UNPKG

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.

386 lines (385 loc) 16.4 kB
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, u as d, ut as f } from "./getters-B4oepJRC.js"; import { Bt as p, It as m, Qt as h, en as g, fn as _, p as v, t as y, tn as b } from "./canvases-CeUwRIFA.js"; import { useEffect as x, useMemo as S, useRef as C } from "react"; //#region node_modules/lodash/_overRest.js var w = /* @__PURE__ */ f(((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; })), T = /* @__PURE__ */ f(((e, t) => { var i = r(), a = w(), o = n(); function s(e, t) { return o(a(e, t, i), e + ""); } t.exports = s; })), E = /* @__PURE__ */ f(((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; })), D = /* @__PURE__ */ f(((e, n) => { var r = t(), a = i(), o = h(); n.exports = r && 1 / o(new r([, -0]))[1] == 1 / 0 ? function(e) { return new r(e); } : a; })), O = /* @__PURE__ */ f(((e, t) => { var n = b(), r = a(), i = E(), o = g(), s = D(), c = h(), 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; })), k = /* @__PURE__ */ f(((t, n) => { var r = s(), i = e(); function a(e) { return i(e) && r(e); } n.exports = a; })), A = /* @__PURE__ */ f(((e, t) => { var n = b(), r = a(), i = E(), o = _(), s = c(), l = g(), 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; })), j = u([y, m], (e, t) => e ? t(e).imageResources : []), M = u([(e) => l(e).layers, (e, { windowId: t }) => t], (e, t) => e && e[t] || d), N = u([M, (e, { canvasId: t }) => t], (e, t) => e[t]), P = u([j, N], (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), F = u([v, M], (e, t) => e.reduce((e, n) => (e[n] = t[n], e), {})), I = "text/plain", ee = "us-ascii", L = "%(?:3A|2F|3F|23|5B|5D|40|21|24|26|27|28|29|2A|2B|2C|3B|3D)", R = "__normalize_url_encoded_reserved__", z = /__normalize_url_encoded_reserved__(\d+)__/g, B = new RegExp(L, "i"), V = new RegExp(L, "gi"), H = (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), U = /* @__PURE__ */ new Set([ "https:", "http:", "file:" ]), W = (e) => { if (typeof e != "string") return; let t = e.trim().toLowerCase().replace(/:$/, ""); return t === "" ? void 0 : `${t}:`; }, G = (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) && !U.has(t)) return t; } catch {} }, K = (e) => { try { return decodeURIComponent(e.replaceAll("+", "%20")); } catch { return new URLSearchParams(`${e}=`).keys().next().value; } }, q = (e) => { let t = /* @__PURE__ */ new Set(); if (!e) return t; for (let n of e.slice(1).split("&")) n && !n.includes("=") && t.add(K(n)); return t; }, J = (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(z)) 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 `${R}${i}__`; }, Y = (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(); }, X = (e, t) => t ? e.replace(t, (e, t) => String.fromCodePoint(Number.parseInt(t, 16))) : e, Z = (e, t, n) => { let r = t === "always", i = t === "never", a = r || i ? void 0 : q(n), o = (e) => e.replaceAll("+", "%20"), s = (e) => r ? `${e}=` : i || a.has(K(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("&")}`; }, Q = (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 === ee) ? "" : `${t}${n ? `=${n}` : ""}`; }).filter(Boolean)]; s && l.push("base64"), (l.length > 0 || c && c !== I) && 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 Q(e, t); let n = Array.isArray(t.customProtocols) ? t.customProtocols : [], r = new Set(n.map((e) => W(e)).filter(Boolean)), i = G(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 && H(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 && B.test(s)) { let e = J(s); o.search = s.replaceAll(V, (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()]) H(X(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()]) H(X(e, c), t.keepQueryParameters) || u.delete(e); else l && (o.search = ""); t.sortQueryParameters && (o.search = Y(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 = Z(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 te = 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) => $(p(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 ne(e, t, n, r) { var i = this, a = C(null), o = C(0), s = C(0), c = C(null), l = C([]), u = C(), d = C(), f = C(e), p = C(!0), m = C(), h = C(); 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, w = "maxWait" in n, T = "debounceOnServer" in n && !!n.debounceOnServer, E = w ? Math.max(+n.maxWait || 0, t) : null, D = S(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); }, x = function(e) { if (!p.current) return !1; var n = e - a.current; return !a.current || n >= t || n < 0 || w && e - o.current >= E; }, S = function(t) { return c.current = null, y && l.current ? e(t) : (l.current = u.current = null, d.current); }, C = function e() { var r = Date.now(); if (v && s.current === o.current && D(), x(r)) return S(r); if (p.current) { var i = t - (r - a.current); n(e, w ? Math.min(i, E - (r - o.current)) : i); } }, D = function() { r && r({}); }, O = function() { if (g || T) { var r, s = Date.now(), f = x(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(C, t), v ? e(a.current) : d.current; if (w) return n(C, t), e(a.current); } return c.current || n(C, 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 ? S(Date.now()) : d.current; }, O; }, [ v, w, t, E, y, b, _, g, T, r ]); return h.current = D, x(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]), D; } //#endregion export { N as a, P as c, O as d, T as f, j as i, A as l, te as n, F as o, w as p, $ as r, M as s, ne as t, k as u }; //# sourceMappingURL=index.module-DGZAy1M6.js.map