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.
321 lines (320 loc) • 10.6 kB
JavaScript
import { a as e, d as t, f as n, ft as r, h as i, m as a, rt as o, u as s, ut as c } from "./getters-DPoFra9X.js";
import { G as l, Ut as u, Vt as d, in as f, mt as p, p as m, s as h, t as g, tn as _ } from "./canvases-xKdr7cbX.js";
import { t as v } from "./action-types-DjIbTE-A.js";
import { createContext as ee } from "react";
//#region node_modules/lodash/_baseFilter.js
var y = /* @__PURE__ */ c(((e, t) => {
var n = _();
function r(e, t) {
var r = [];
return n(e, function(e, n, i) {
t(e, n, i) && r.push(e);
}), r;
}
t.exports = r;
})), b = /* @__PURE__ */ c(((e, t) => {
var n = f(), r = y(), i = u(), a = o();
function s(e, t) {
return (a(e) ? n : r)(e, i(t, 3));
}
t.exports = s;
})), te = /* @__PURE__ */ c(((e, t) => {
function n(e) {
for (var t = -1, n = e == null ? 0 : e.length, r = 0, i = []; ++t < n;) {
var a = e[t];
a && (i[r++] = a);
}
return i;
}
t.exports = n;
})), x = /* @__PURE__ */ r(b(), 1), S = /* @__PURE__ */ r(te(), 1), C = class {
constructor(e = {}) {
this.resource = e;
}
isOnlyTag() {
return this.motivations.length === 1 && this.motivations[0] === "oa:tagging";
}
get id() {
return this._id = this._id || this.resource["@id"] || this.resources[0] && this.resources[0]["@id"] || i(), this._id;
}
get targetId() {
let e = this.on[0];
switch (typeof e) {
case "string": return e.replace(/#?xywh=(.*)$/, "");
case "object": return e.full.replace(/#?xywh=(.*)$/, "");
default: return null;
}
}
get motivations() {
return (0, S.default)(Array(this.resource.motivation)).flat();
}
get resources() {
return (0, S.default)(Array(this.resource.resource)).flat();
}
get on() {
return (0, S.default)(Array(this.resource.on)).flat();
}
get tags() {
return this.isOnlyTag() ? this.resources.map((e) => e.chars) : this.resources.filter((e) => e["@type"] === "oa:Tag").map((e) => e.chars);
}
get chars() {
return this.resources.filter((e) => e["@type"] !== "oa:Tag").map((e) => e.chars).join(" ");
}
get selector() {
let e = this.on[0];
switch (typeof e) {
case "string": return e;
case "object": return e.selector["@type"] === "oa:Choice" ? e.selector.default : e.selector;
default: return null;
}
}
get svgSelector() {
let e = this.on[0];
switch (typeof e) {
case "string": return null;
case "object": return e.selector && e.selector.item && e.selector.item["@type"] === "oa:SvgSelector" ? e.selector.item : null;
default: return null;
}
}
get fragmentSelector() {
let { selector: e } = this, t;
switch (typeof e) {
case "string":
t = e.match(/xywh=(.*)$/);
break;
case "object":
t = e.value.match(/xywh=(.*)$/);
break;
default: return null;
}
return t && t[1].split(",").map((e) => parseInt(e, 10));
}
}, w = class {
constructor(e, t) {
this.json = e, this.target = t;
}
get id() {
return this.json["@id"];
}
present() {
return this.resources && this.resources.length > 0;
}
get resources() {
return this._resources = this._resources || (!this.json || !this.json.resources ? [] : [this.json.resources].flat().map((e) => new C(e))), this._resources;
}
}, T = class {
constructor(e = {}) {
this.resource = e;
}
isOnlyTag() {
return this.motivations.length === 1 && this.motivations[0] === "tagging";
}
get id() {
return this._id = this._id || this.resource.id || i(), this._id;
}
get targetId() {
let e = this.target[0];
switch (typeof e) {
case "string": return e.replace(/#?xywh=(.*)$/, "");
case "object": return e.source && e.source.id || e.source || e.id;
default: return null;
}
}
bodyValue(e) {
return typeof e == "string" ? e : e.value;
}
get motivations() {
return (0, S.default)(Array(this.resource.motivation)).flat();
}
get body() {
return (0, S.default)(Array(this.resource.body)).flat();
}
get resources() {
return this.body;
}
get tags() {
return this.isOnlyTag() ? this.body.map((e) => this.bodyValue(e)) : this.body.filter((e) => e.purpose === "tagging").map((e) => this.bodyValue(e));
}
get target() {
return (0, S.default)(Array(this.resource.target)).flat();
}
get chars() {
return this.isOnlyTag() ? null : this.body.filter((e) => e.purpose !== "tagging").map((e) => this.bodyValue(e)).join(" ");
}
get selector() {
let e = this.target[0];
switch (typeof e) {
case "string": return e;
case "object": return (0, S.default)(Array(e.selector)).flat();
default: return null;
}
}
get svgSelector() {
let { selector: e } = this;
switch (typeof e) {
case "string": return null;
case "object": return e.find((e) => e.type && e.type === "SvgSelector");
default: return null;
}
}
get fragmentSelector() {
let { selector: e } = this, t, n;
switch (typeof e) {
case "string":
t = e.match(/xywh=(.*)$/);
break;
case "object":
n = e.find((e) => e.type && e.type === "FragmentSelector"), t = n && n.value.match(/xywh=(.*)$/);
break;
default: return null;
}
return t && t[1].split(",").map((e) => parseInt(e, 10));
}
}, E = class {
constructor(e, t) {
this.json = e, this.target = t;
}
get id() {
return this.json.id;
}
present() {
return this.items && this.items.length > 0;
}
get items() {
return this._items = this._items || (!this.json || !this.json.items ? [] : [this.json.items].flat().map((e) => new T(e))), this._items;
}
get resources() {
return this.items;
}
}, D = class {
static determineAnnotation(e, t) {
return e ? e.type === "AnnotationPage" ? new E(e, t) : new w(e, t) : null;
}
}, O = (e) => n(e).annotations, k = a([p, (e, { motivations: t }) => t], (e, t) => t || e.annotations.filteredMotivations), ne = a([g, O], (e, t) => !t || !e || !t[e.id] ? [] : Object.values(t[e.id]).flat()), A = a([ne], (e) => (0, x.default)(Object.values(e).map((e) => e && D.determineAnnotation(e.json)), (e) => e && e.present())), j = a([(e, { canvasId: t, ...n }) => t ? [t] : m(e, n), O], (e, t) => !t || e.length === 0 ? [] : e.flatMap((e) => t[e] && Object.values(t[e]))), M = a([j], (e) => (0, x.default)(Object.values(e).map((e) => e && D.determineAnnotation(e.json)), (e) => e && e.present())), N = a([A, k], (e, t) => {
let n = e.flatMap((e) => e.resources);
return !t || t.length === 0 ? n : n.filter((e) => e.motivations.some((e) => t.includes(e)));
}), P = a([N], (e) => e.map((e) => ({
content: e.chars,
id: e.id,
tags: e.tags,
targetId: e.targetId
}))), F = a([M, k], (e, t) => {
let n = e.flatMap((e) => e.resources);
return !t || t.length === 0 ? n : n.filter((e) => e.motivations.some((e) => t.includes(e)));
}), I = a([e], ({ selectedAnnotationId: e }) => e), L = a([M, I], (e, t) => e.map((e) => ({
id: e["@id"] || e.id,
resources: e.resources.filter((e) => t === e.id)
})).filter((e) => e.resources.length > 0)), R = d(), z = a([(e, { windowId: t }) => t, (e) => n(e).searches], (e, n) => !e || !n ? t : n[e]), B = a([z, (e, { companionWindowId: t }) => t], (e, t) => {
if (!(!e || !t)) return e[t];
}), V = a([B], (e) => e ? Object.values(e.data) : s), H = a([B], (e) => e && e.query), U = a([V], (e) => e.some((e) => e.isFetching)), W = a([B], (e) => {
if (!(!e || !e.data)) return Object.values(e.data).find((e) => !e.isFetching && e.json && e.json.within)?.json?.within?.total;
}), re = a([B], (e) => {
if (!e || !e.data) return;
let t = Object.values(e.data).find((t) => !t.isFetching && t.json && t.json.next && !e.data[t.json.next]);
return t && t.json && t.json.next;
}), G = a([V], (e) => e.flatMap((e) => !e || !e.json || e.isFetching || !e.json.hits ? s : e.json.hits)), K = a([V], (e) => e && J(e)), q = a([
G,
h,
K
], (e, t, n) => {
if (!t || t.length === 0 || !e || e.length === 0) return s;
let r = t.map((e) => e.id);
return [].concat(e).sort((e, t) => {
let i = n.resources.find((t) => t.id === e.annotations[0]), a = n.resources.find((e) => e.id === t.annotations[0]);
return r.indexOf(i.targetId) - r.indexOf(a.targetId);
});
}), J = (e) => {
let t = e.map((e) => {
if (!e || !e.json || e.isFetching || !e.json.resources) return;
let t = new w(e.json);
return {
id: t.id,
resources: t.resources
};
}).filter(Boolean);
return {
id: (t.find((e) => e.id) || {}).id,
resources: t.flatMap((e) => e.resources)
};
};
function Y(e, t) {
if (!e || !e.resources || e.length === 0 || !t || t.length === 0) return s;
let n = t.map((e) => e.id);
return [].concat(e.resources).sort((e, t) => n.indexOf(e.targetId) - n.indexOf(t.targetId));
}
var X = a([K, h], (e, t) => Y(e, t)), Z = a([z], (e) => e ? Object.values(e).map((e) => Object.values(e.data)).map((e) => J(e)).filter((e) => e.resources.length > 0) : s), ie = a([e, B], (e, t) => t && t.selectedContentSearchAnnotationIds || []), Q = a([K, (e, { annotationUri: t }) => t], (e, t) => e.resources.find((e) => e.id === t)), ae = a([Q, l], (e, t) => e && e.resource && e.resource.label ? R.PropertyValue.parse(e.resource.label).getValues(t) : s), oe = a([Z, (e, { annotationId: t }) => t], (e, t) => e.flatMap((e) => e.resources).find((e) => e.id === t)), se = a([oe, (e, { windowId: t }) => (n) => g(e, {
canvasId: n,
windowId: t
})], (e, t) => {
let n = e && e.targetId;
return n && t(n);
});
//#endregion
//#region src/state/actions/annotation.js
function $(e, t) {
return {
canvasId: t,
type: v.REQUEST_CANVAS_ANNOTATIONS,
windowId: e
};
}
function ce(e, t) {
return {
annotationId: t,
targetId: e,
type: v.REQUEST_ANNOTATION
};
}
function le(e, t, n) {
return {
annotationId: t,
annotationJson: n,
targetId: e,
type: v.RECEIVE_ANNOTATION
};
}
function ue(e, t, n) {
return {
annotationId: t,
error: n,
targetId: e,
type: v.RECEIVE_ANNOTATION_FAILURE
};
}
function de(e, t) {
return {
annotationId: t,
type: v.SELECT_ANNOTATION,
windowId: e
};
}
function fe(e, t) {
return {
annotationId: t,
type: v.DESELECT_ANNOTATION,
windowId: e
};
}
function pe(e) {
return {
type: v.TOGGLE_ANNOTATION_DISPLAY,
windowId: e
};
}
function me(e, t) {
return {
annotationIds: t,
type: v.HOVER_ANNOTATION,
windowId: e
};
}
//#endregion
//#region src/contexts/FailedImageContext.js
var he = ee({
fallbackImage: "",
hasFailed: !1,
notifyFailure: () => {}
});
//#endregion
export { L as A, Y as C, O as D, P as E, C as F, E as M, T as N, M as O, w as P, q as S, N as T, U as _, ue as a, ie as b, de as c, re as d, Q as f, z as g, Z as h, le as i, D as j, I as k, pe as l, K as m, fe as n, ce as o, ae as p, me as r, $ as s, he as t, se as u, W as v, F as w, X as x, H as y };
//# sourceMappingURL=FailedImageContext-BPhlsq3Z.js.map