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.

319 lines (318 loc) • 10.4 kB
import { G as e, lt as t, mt as n, st as r, ut as i, v as a } from "./getters-H0mV17lW.js"; import { V as o, ft as s, ht as c } from "./canvases-CWytFm4k.js"; import { t as l } from "./FailedImageContext-BVU9xFk0.js"; import { t as u } from "./createSvgIcon-Cwt8YPfm.js"; import * as d from "react"; import { createContext as f, useContext as p, useEffect as m, useMemo as h, useState as g } from "react"; import { jsx as _, jsxs as v } from "react/jsx-runtime"; import { styled as y } from "@mui/material/styles"; //#region node_modules/react-intersection-observer/dist/index.mjs var b = /* @__PURE__ */ n(r(), 1), x = Object.defineProperty, S = (e, t, n) => t in e ? x(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, C = (e, t, n) => S(e, typeof t == "symbol" ? t : t + "", n), w = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new WeakMap(), E = 0, D; function O(e) { return e ? T.has(e) ? T.get(e) : (E += 1, T.set(e, E.toString()), T.get(e)) : "0"; } function k(e) { return Object.keys(e).sort().filter((t) => e[t] !== void 0).map((t) => `${t}_${t === "root" ? O(e.root) : e[t]}`).toString(); } function A(e) { let t = k(e), n = w.get(t); if (!n) { let r = /* @__PURE__ */ new Map(), i, a = new IntersectionObserver((t) => { t.forEach((t) => { let n = t.isIntersecting && i.some((e) => t.intersectionRatio >= e); e.trackVisibility && t.isVisible === void 0 && (t.isVisible = n), [...r.get(t.target) ?? []].forEach((e) => { e(n, t); }); }); }, e); i = a.thresholds || (Array.isArray(e.threshold) ? e.threshold : [e.threshold || 0]), n = { id: t, observer: a, elements: r }, w.set(t, n); } return n; } function j(e, t, n = {}, r = D) { if (window.IntersectionObserver === void 0 && r !== void 0) { let i = e.getBoundingClientRect(); return t(r, { isIntersecting: r, target: e, intersectionRatio: typeof n.threshold == "number" ? n.threshold : 0, time: 0, boundingClientRect: i, intersectionRect: i, rootBounds: i }), () => {}; } let { id: i, observer: a, elements: o } = A(n), s = o.get(e) || []; return o.has(e) || o.set(e, s), s.push(t), a.observe(e), function() { s.splice(s.indexOf(t), 1), s.length === 0 && (o.delete(e), a.unobserve(e)), o.size === 0 && (a.disconnect(), w.delete(i)); }; } function M(e) { return typeof e.children != "function"; } var N = class extends d.Component { constructor(e) { super(e), C(this, "node", null), C(this, "_unobserveCb", null), C(this, "lastInView"), C(this, "handleNode", (e) => { this.node && (this.unobserve(), !e && !this.props.triggerOnce && !this.props.skip && (this.setState({ inView: !!this.props.initialInView, entry: void 0 }), this.lastInView = this.props.initialInView)), this.node = e || null, this.observeNode(); }), C(this, "handleChange", (e, t) => { let n = this.lastInView; this.lastInView = e, !(n === void 0 && !e) && (e && this.props.triggerOnce && this.unobserve(), M(this.props) || this.setState({ inView: e, entry: t }), this.props.onChange && this.props.onChange(e, t)); }), this.state = { inView: !!e.initialInView, entry: void 0 }, this.lastInView = e.initialInView; } componentDidMount() { this.unobserve(), this.observeNode(); } componentDidUpdate(e) { (e.rootMargin !== this.props.rootMargin || e.scrollMargin !== this.props.scrollMargin || e.root !== this.props.root || e.threshold !== this.props.threshold || e.skip !== this.props.skip || e.trackVisibility !== this.props.trackVisibility || e.delay !== this.props.delay) && (this.unobserve(), this.observeNode()); } componentWillUnmount() { this.unobserve(); } observeNode() { if (!this.node || this.props.skip) return; let { threshold: e, root: t, rootMargin: n, scrollMargin: r, trackVisibility: i, delay: a, fallbackInView: o } = this.props; this.lastInView === void 0 && (this.lastInView = this.props.initialInView), this._unobserveCb = j(this.node, this.handleChange, { threshold: e, root: t, rootMargin: n, scrollMargin: r, trackVisibility: i, delay: a }, o); } unobserve() { this._unobserveCb &&= (this._unobserveCb(), null); } render() { let { children: e } = this.props; if (typeof e == "function") { let { inView: t, entry: n } = this.state; return e({ inView: t, entry: n, ref: this.handleNode }); } let { as: t, triggerOnce: n, threshold: r, root: i, rootMargin: a, scrollMargin: o, onChange: s, skip: c, trackVisibility: l, delay: u, initialInView: f, fallbackInView: p, ...m } = this.props; return d.createElement(t || "div", { ref: this.handleNode, ...m }, e); } }; function P({ threshold: e, delay: t, trackVisibility: n, rootMargin: r, scrollMargin: i, root: a, triggerOnce: o, skip: s, initialInView: c, fallbackInView: l, onChange: u } = {}) { let [f, p] = d.useState(null), m = d.useRef(u), h = d.useRef(c), [g, _] = d.useState({ inView: !!c, entry: void 0 }); m.current = u, d.useEffect(() => { if (h.current === void 0 && (h.current = c), s || !f) return; let u; return u = j(f, (e, t) => { let n = h.current; h.current = e, !(n === void 0 && !e) && (_({ inView: e, entry: t }), m.current && m.current(e, t), t.isIntersecting && o && u && (u(), u = void 0)); }, { root: a, rootMargin: r, scrollMargin: i, threshold: e, trackVisibility: n, delay: t }, l), () => { u && u(); }; }, [ Array.isArray(e) ? e.toString() : e, f, a, r, i, o, s, n, l, t ]); let v = g.entry?.target, y = d.useRef(void 0); !f && v && !o && !s && y.current !== v && (y.current = v, _({ inView: !!c, entry: void 0 }), h.current = c); let b = [ p, g.inView, g.entry ]; return b.ref = b[0], b.inView = b[1], b.entry = b[2], b; } ("useInsertionEffect" in d ? d.useInsertionEffect : void 0) ?? d.useLayoutEffect ?? d.useEffect; //#endregion //#region src/contexts/LocaleContext.js var F = f(); //#endregion //#region src/components/IIIFResourceLabel.jsx function I({ fallback: e, resource: t }) { let n = p(F), r = i((e) => o(e, {})); if (!t) return e; let a = t.getLabel(); return a ? a.getValue(n || r || "") ?? (e || t.id) : e; } I.propTypes = { fallback: b.default.string, resource: b.default.object.isRequired }; //#endregion //#region src/hooks/useThumbnailService.js function L(e, t) { return i((n) => s(n, e, t), [e, t]); } //#endregion //#region src/components/IIIFThumbnail.jsx var R = y("div", { name: "IIIFThumbnail", slot: "root" })({}), z = y("span", { name: "IIIFThumbnail", slot: "label" })(({ theme: e }) => ({ ...e.typography.caption })), B = y("img", { name: "IIIFThumbnail", slot: "image" })(() => ({ height: "auto", width: "auto" })), V = ({ border: e = !1, placeholder: t, style: n = {}, thumbnail: r = null, resource: i, maxHeight: a = null, maxWidth: o = null, ...s }) => { let { ref: c, inView: u } = P(), [d, f] = g(!1), [v, y] = g(!1), b = L(a, o), { notifyFailure: x, fallbackImage: S } = p(l); m(() => { d || !u || f(!0); }, [u, d]); let C = h(() => { if (r) return r; let e = b.get(i); if (e && e.url) return e; }, [ i, r, b ]), w = h(() => { let e = (e) => v && S ? { ...n, height: e.height ?? e.maxHeight, width: e.width ?? e.maxWidth, objectFit: "contain" } : { ...e, ...n }, t = { height: void 0, maxHeight: void 0, maxWidth: void 0, width: void 0 }; if (!C) return t.height = a, t.width = o, e(t); let { height: r, width: i } = C; if (r && i) { if (a && r > a || o && i > o) { let e = i / r; a && o ? o / a < e ? (t.height = Math.round(o / e), t.width = o) : (t.height = a, t.width = Math.round(a * e)) : a ? (t.height = a, t.maxWidth = Math.round(a * e)) : o && (t.width = o, t.maxHeight = Math.round(o / e)); } else t.width = i, t.height = r; } else r && !i ? t.height = a : !r && i ? t.width = o : (t.width = o, t.height = a); return e(t); }, [ C, o, a, n, v, S ]), { url: T = t } = d && (r || C) || {}, E = v ? S || t : T; return /* @__PURE__ */ _(B, { ownerState: { border: e }, ref: c, alt: v ? "Thumbnail image unavailable" : "", role: v ? void 0 : "presentation", src: E, style: w, onError: () => { y(!0), E && x(E); }, ...s }); }; V.propTypes = { border: b.default.bool, maxHeight: b.default.number, maxWidth: b.default.number, placeholder: b.default.string.isRequired, resource: b.default.object.isRequired, style: b.default.object, thumbnail: b.default.shape({ height: b.default.number, url: b.default.string.isRequired, width: b.default.number }) }; var H = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mMMDQmtBwADgwF/Op8FmAAAAABJRU5ErkJggg=="; function U({ border: e = !1, children: t = null, imagePlaceholder: n = H, label: r = void 0, labelled: i = !1, maxHeight: a = null, maxWidth: o = null, resource: s, style: c = {}, thumbnail: l = null }) { let u = arguments[0]; return /* @__PURE__ */ v(R, { ownerState: u, children: [ /* @__PURE__ */ _(V, { placeholder: n, thumbnail: l, resource: s, maxHeight: a, maxWidth: o, style: c, border: e }), i && /* @__PURE__ */ _(z, { ownerState: u, children: r || /* @__PURE__ */ _(I, { resource: s }) }), t ] }); } U.propTypes = { border: b.default.bool, children: b.default.node, imagePlaceholder: b.default.string, label: b.default.string, labelled: b.default.bool, maxHeight: b.default.number, maxWidth: b.default.number, resource: b.default.object.isRequired, style: b.default.object, thumbnail: b.default.shape({ height: b.default.number, url: b.default.string.isRequired, width: b.default.number }), variant: b.default.oneOf(["inside", "outside"]) }; var W = e(t((e) => ({ thumbnailsConfig: c(e).thumbnails })), a("IIIFThumbnail"))(U), G = u(/*#__PURE__*/ _("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14" }), "SearchSharp"), K = u(/*#__PURE__*/ _("path", { d: "M21.99 2H2v16h16l4 4zM18 14H6v-2h12zm0-3H6V9h12zm0-3H6V6h12z" }), "CommentSharp"); //#endregion export { I as a, U as i, G as n, F as o, W as r, N as s, K as t }; //# sourceMappingURL=CommentSharp-DglfFOa-.js.map