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