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