cozy-iiif
Version:
A developer-friendly collection of abstractions and utilities built on top of @iiif/presentation-3 and @iiif/parser
957 lines (956 loc) • 29.8 kB
JavaScript
import { _ as e, a as t, b as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as ee, v as _, y as te } from "./core-BHFaVC33.js";
//#region node_modules/@iiif/parser/dist/profiles-DU_UcLCg.js
var ne = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", re = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", v = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", y = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ie = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", b = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", ae = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", oe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", x = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", se = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", ce = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", S = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", C = "http://iiif.io/api/image/1/level0.json", w = "http://iiif.io/api/image/1/profiles/level0.json", le = "http://iiif.io/api/image/1/level1.json", ue = "http://iiif.io/api/image/1/profiles/level1.json", T = "http://iiif.io/api/image/1/level2.json", E = "http://iiif.io/api/image/1/profiles/level2.json", de = "http://iiif.io/api/image/2/level0.json", fe = "http://iiif.io/api/image/2/profiles/level0.json", pe = "http://iiif.io/api/image/2/level1.json", me = "http://iiif.io/api/image/2/profiles/level1.json", D = "http://iiif.io/api/image/2/level2.json", O = "http://iiif.io/api/image/2/profiles/level2.json", he = "level0", ge = "level1", k = "level2", _e = "http://iiif.io/api/image/2/level0", A = "http://iiif.io/api/image/2/level1", j = "http://iiif.io/api/image/2/level2", M = [
j,
v,
b,
x,
S,
T,
E,
D,
O,
k
];
[...M];
var N = [
_e,
A,
j,
ne,
re,
v,
y,
ie,
b,
ae,
oe,
x,
se,
ce,
S,
C,
w,
le,
ue,
T,
E,
de,
fe,
pe,
me,
D,
O,
he,
ge,
k
], P = [
"sc:Collection",
"sc:Manifest",
"sc:Canvas",
"sc:AnnotationList",
"oa:Annotation",
"sc:Range",
"sc:Layer",
"sc:Sequence",
"oa:Choice",
"Service",
"ContentResource"
];
function F(e) {
if (e == null) throw Error("Null or undefined is not a valid entity.");
if (Array.isArray(e)) throw Error("Array is not a valid entity");
if (typeof e != "object") throw Error(`${typeof e} is not a valid entity`);
if (typeof e["@type"] == "string") {
let t = P.indexOf(e["@type"]);
if (t !== -1) return P[t];
}
if (e.profile) return "Service";
if (e.format || e["@type"]) return "ContentResource";
throw Error("Resource type is not known");
}
var I = class e {
constructor(e, t = {}) {
n(this, "traversals", void 0), n(this, "options", void 0), this.traversals = {
collection: [],
manifest: [],
canvas: [],
annotationList: [],
sequence: [],
annotation: [],
contentResource: [],
choice: [],
range: [],
service: [],
layer: [],
...e
}, this.options = {
convertPropsToArray: !0,
mergeMemberProperties: !0,
allowUndefinedReturn: !1,
...t
};
}
static all(t) {
return new e({
collection: [t],
manifest: [t],
canvas: [t],
annotationList: [t],
sequence: [t],
annotation: [t],
contentResource: [t],
choice: [t],
range: [t],
service: [t],
layer: [t]
});
}
traverseCollection(e) {
return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))), this.traversals.collection);
}
traverseCollectionItems(e) {
if (this.options.mergeMemberProperties) {
let t = [
...(e.manifests || []).map((e) => typeof e == "string" ? {
"@id": e,
"@type": "sc:Manifest"
} : (e["@type"] ||= "sc:Manifest", e)),
...(e.collections || []).map((e) => typeof e == "string" ? {
"@id": e,
"@type": "sc:Collection"
} : e),
...e.members || []
], n = [], r = t.filter((e) => n.includes(e["@id"]) ? !1 : (n.push(e["@id"]), !0));
delete e.collections, delete e.manifests, e.members = r;
}
return e.manifests &&= e.manifests.map((e) => {
let t = e;
return typeof e == "string" && (t = {
"@id": e,
"@type": "sc:Manifest"
}), t["@type"] ||= "sc:Manifest", this.traverseManifest(t);
}), e.collections &&= e.collections.map((e) => this.traverseCollection(typeof e == "string" ? {
"@id": e,
"@type": "sc:Collection"
} : e)), e.members &&= e.members.map((e) => typeof e == "string" ? e : e["@type"] === "sc:Collection" ? this.traverseCollection(e) : e["@type"] === "sc:Manifest" ? this.traverseManifest(e) : this.traverseUnknown(e)), e;
}
traverseManifest(e) {
return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))), this.traversals.manifest);
}
traverseManifestItems(e) {
return e.sequences &&= e.sequences.map((e) => this.traverseSequence(e)), e.structures &&= e.structures.map((e) => this.traverseRange(e)), e;
}
traverseSequence(e) {
return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))), this.traversals.sequence);
}
traverseSequenceItems(e) {
return e.canvases &&= e.canvases.map((e) => this.traverseCanvas(e)), e;
}
traverseCanvas(e) {
return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))), this.traversals.canvas);
}
traverseCanvasItems(e) {
return e.images &&= e.images.map((e) => (e.on && e["@type"] !== "oa:Annotation" && e["@type"] !== "Annotation" && (e["@type"] = "oa:Annotation"), this.traverseAnnotation(e))), e.otherContent &&= e.otherContent.map((e) => this.traverseAnnotationList(e)), e;
}
traverseRange(e) {
return e["@type"] !== "sc:Range" && (e["@type"] = "sc:Range"), this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))), this.traversals.range);
}
traverseRangeItems(e) {
if (this.options.mergeMemberProperties) {
let t = [
...(e.ranges || []).map((e) => typeof e == "string" ? {
"@id": e,
"@type": "sc:Range"
} : e),
...(e.canvases || []).map((e) => typeof e == "string" ? {
"@id": e,
"@type": "sc:Canvas"
} : e),
...e.members || []
];
delete e.ranges, delete e.canvases, e.members = t.length ? t.map((e) => this.traverseUnknown(e)) : void 0;
}
return e;
}
traverseAnnotationList(e) {
let t = typeof e == "string" ? {
"@id": e,
"@type": "sc:AnnotationList"
} : e;
return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)), this.traversals.annotationList);
}
traverseAnnotationListItems(e) {
return e.resources &&= e.resources.map((e) => this.traverseAnnotation(e)), e;
}
traverseAnnotation(e) {
return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))), this.traversals.annotation);
}
traverseAnnotationItems(e) {
return e.resource && (Array.isArray(e.resource) ? e.resource = e.resource.map((e) => this.traverseContentResource(e)) : e.resource = this.traverseContentResource(e.resource)), e.on, e;
}
traverseLayer(e) {
return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)), this.traversals.layer);
}
traverseLayerItems(e) {
return e.otherContent &&= e.otherContent.map((e) => this.traverseAnnotationList(e)), e;
}
traverseChoice(e) {
return this.traverseType(this.traverseChoiceItems(e), this.traversals.choice);
}
traverseChoiceItems(e) {
return e.default && e.default !== "rdf:nil" && (e.default = this.traverseContentResource(e.default)), e.item && e.item !== "rdf:nil" && (e.item = e.item.map((e) => this.traverseContentResource(e))), e;
}
traverseService(e) {
return this.traverseType(this.traverseLinking(e), this.traversals.service);
}
traverseContentResource(e) {
return e["@type"] === "oa:Choice" ? this.traverseChoice(e) : this.traverseType(this.traverseDescriptive(this.traverseLinking(e)), this.traversals.contentResource);
}
traverseUnknown(e) {
if (!e["@type"] || typeof e == "string") return e;
switch (F(e)) {
case "sc:Collection": return this.traverseCollection(e);
case "sc:Manifest": return this.traverseManifest(e);
case "sc:Canvas": return this.traverseCanvas(e);
case "sc:Sequence": return this.traverseSequence(e);
case "sc:Range": return this.traverseRange(e);
case "oa:Annotation": return this.traverseAnnotation(e);
case "sc:AnnotationList": return this.traverseAnnotationList(e);
case "sc:Layer": return this.traverseLayer(e);
case "Service": return this.traverseService(e);
case "oa:Choice": return this.traverseChoice(e);
case "ContentResource": return this.traverseContentResource(e);
}
return e.profile ? this.traverseService(e) : e;
}
traverseImageResource(e) {
let t = Array.isArray(e), n = Array.isArray(e) ? e : [e], r = [];
for (let e of n) typeof e == "string" ? r.push(this.traverseContentResource({
"@id": e,
"@type": "dctypes:Image"
})) : r.push(this.traverseContentResource(e));
return !t && !this.options.convertPropsToArray ? r[0] : r;
}
traverseDescriptive(e) {
return e.thumbnail &&= this.traverseImageResource(e.thumbnail), e.logo &&= this.traverseImageResource(e.logo), e;
}
traverseOneOrMoreServices(e) {
let t = Array.isArray(e), n = Array.isArray(e) ? e : [e], r = [];
for (let e of n) r.push(this.traverseService(e));
return !t && !this.options.convertPropsToArray ? r[0] : r;
}
traverseLinking(e) {
return e.related &&= this.traverseOneOrManyType(e.related, this.traversals.contentResource), e.rendering &&= this.traverseOneOrManyType(e.rendering, this.traversals.contentResource), e.service &&= this.traverseOneOrMoreServices(e.service), e.seeAlso &&= this.traverseOneOrManyType(e.seeAlso, this.traversals.contentResource), e.within && (typeof e.within == "string" || (e.within = this.traverseOneOrManyType(e.within, this.traversals.contentResource))), e.startCanvas && (typeof e.startCanvas == "string" ? e.startCanvas = this.traverseType({
"@id": e.startCanvas,
"@type": "sc:Canvas"
}, this.traversals.canvas) : e.startCanvas && this.traverseType(e.startCanvas, this.traversals.canvas)), e.contentLayer && (typeof e.contentLayer == "string" ? e.contentLayer = this.traverseLayer({
"@id": e.contentLayer,
"@type": "sc:Layer"
}) : e.contentLayer = this.traverseLayer(e.contentLayer)), e;
}
traverseOneOrManyType(e, t) {
if (!Array.isArray(e)) if (this.options.convertPropsToArray) e = [e];
else return this.traverseType(e, t);
return e.map((e) => this.traverseType(e, t));
}
traverseType(e, t) {
return t.reduce((e, t) => {
let n = t(e);
return n === void 0 && !this.options.allowUndefinedReturn ? e : n;
}, e);
}
}, ve = [
"http://iiif.io/api/image/2/level1",
"http://iiif.io/api/image/2/level2",
"http://library.stanford.edu/iiif/image-api/compliance.html#level1",
"http://library.stanford.edu/iiif/image-api/compliance.html#level2",
"http://library.stanford.edu/iiif/image-api/conformance.html#level1",
"http://library.stanford.edu/iiif/image-api/conformance.html#level2",
"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",
"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",
"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",
"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",
"http://iiif.io/api/image/1/level1.json",
"http://iiif.io/api/image/1/profiles/level1.json",
"http://iiif.io/api/image/1/level2.json",
"http://iiif.io/api/image/1/profiles/level2.json",
"http://iiif.io/api/image/2/level1.json",
"http://iiif.io/api/image/2/profiles/level1.json",
"http://iiif.io/api/image/2/level2.json",
"http://iiif.io/api/image/2/profiles/level2.json",
"level1",
"level2"
], L = {
attributionLabel: "Attribution",
lang: "none",
providerId: "http://example.org/provider",
providerName: ""
};
function ye(e) {
if (typeof e == "string") return [e];
if (!e) return [];
let t = Array.isArray(e) ? e : [e], n = [];
for (let e of t) {
if (typeof e == "string") {
n.push(e);
continue;
}
n.push({
"@language": e["@language"] || e.language,
"@value": e["@value"] || e.value
});
}
return n;
}
function R(e, t = "none") {
if (!e) return { none: [""] };
let n = ye(e), r = {};
for (let e of n) {
if (typeof e == "string") {
r[t] = r[t] ? r[t] : [], r[t].push(e || "");
continue;
}
if (!e["@language"]) {
r[t] = r[t] ? r[t] : [], r[t].push(e["@value"] || "");
continue;
}
let n = e["@language"];
r[n] = r[n] ? r[n] : [], r[n].push(e["@value"] || "");
}
return Object.keys(r).length === 0 ? { none: [""] } : r;
}
function z(e) {
if (Array.isArray(e)) return z(e.find((e) => typeof e == "string"));
if (M.indexOf(e) !== -1) return "level2";
if (ve.indexOf(e) !== -1) return "level1";
if (N.indexOf(e) !== -1) return "level0";
if (typeof e == "string") return e;
}
function be(e) {
let t = Array.isArray(e) ? e : [e];
for (let e of t) switch (e) {
case "http://iiif.io/api/image/2/context.json":
case "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2": return "ImageService2";
case "http://iiif.io/api/image/1/context.json":
case "http://library.stanford.edu/iiif/image-api/1.1/context.json": return "ImageService1";
case "http://iiif.io/api/annex/openannotation/context.json": return "ImageApiSelector";
}
}
function xe(e) {
switch (e) {
case "http://iiif.io/api/image/2/level0.json":
case "http://iiif.io/api/image/2/level1.json":
case "http://iiif.io/api/image/2/level2.json": return "ImageService2";
case "http://iiif.io/api/auth/1/kiosk":
case "http://iiif.io/api/auth/1/login":
case "http://iiif.io/api/auth/1/clickthrough":
case "http://iiif.io/api/auth/1/external":
case "http://iiif.io/api/auth/0/kiosk":
case "http://iiif.io/api/auth/0/login":
case "http://iiif.io/api/auth/0/clickthrough":
case "http://iiif.io/api/auth/0/external": return "AuthCookieService1";
case "http://iiif.io/api/auth/1/token":
case "http://iiif.io/api/auth/0/token": return "AuthTokenService1";
case "http://iiif.io/api/auth/1/logout":
case "http://iiif.io/api/auth/0/logout": return "AuthLogoutService1";
case "http://iiif.io/api/search/1/search":
case "http://iiif.io/api/search/0/search": return "SearchService1";
case "http://iiif.io/api/search/1/autocomplete":
case "http://iiif.io/api/search/0/autocomplete": return "AutoCompleteService1";
}
}
function B(e) {
for (let t of [
"sc",
"oa",
"dcterms",
"dctypes",
"iiif"
]) if (e.startsWith(`${t}:`)) return e.slice(t.length + 1);
return e;
}
var Se = [
"Collection",
"Manifest",
"Annotation",
"AnnotationPage",
"Range",
"Service"
];
function V(e) {
let t = e["@id"] || e.id, n = e["@type"] || e.type, r = e.profile || void 0, i = e["@context"] || void 0;
if (r) {
let e = xe(r);
if (e) return e;
}
if (i) {
let e = be(i);
if (e) return e;
}
if (n) {
if (Array.isArray(n)) {
if (n.indexOf("oa:CssStylesheet") !== -1) return "CssStylesheet";
if (n.indexOf("cnt:ContentAsText") !== -1) return "TextualBody";
n = n[0];
}
for (let e of [
"sc",
"oa",
"dcterms",
"dctypes",
"iiif"
]) if (n.startsWith(`${e}:`)) {
n = n.slice(e.length + 1);
break;
}
switch (n) {
case "Layer": return "AnnotationCollection";
case "AnnotationList": return "AnnotationPage";
case "cnt:ContentAsText": return "TextualBody";
}
}
if (n && Se.indexOf(n) !== -1) return n;
if (e.format) {
if (e.format.startsWith("image/")) return "Image";
if (e.format.startsWith("text/") || e.format === "application/pdf") return "Text";
if (e.format.startsWith("application/")) return "Dataset";
}
return t && (t.endsWith(".jpg") || t.endsWith(".png") || t.endsWith(".jpeg")) ? "Image" : n || "unknown";
}
var Ce = /^|["'\\>]http(s)?:\/\/(creativecommons.org|rightsstatements.org)\/[^"'\\<\n]+/gm;
function we(e) {
let t = e.match(Ce);
return t ? t[0] : e;
}
function H(e, t = "Rights/License", n = "none") {
let r = null, i = [], a = Array.isArray(e) ? e : [e];
for (let e of a) {
let a = e ? we(e) : void 0;
if (a && (a.indexOf("creativecommons.org") !== -1 || a.indexOf("rightsstatements.org") !== -1)) {
r = a.startsWith("https://") ? `http://${a.slice(8)}` : a;
continue;
}
a && i.push({
label: { [n]: [t] },
value: { [n]: [a] }
});
}
return [r, i];
}
var Te = [
"http://iiif.io/api/presentation/2/context.json",
"http://iiif.io/api/image/2/context.json",
"http://iiif.io/api/image/1/context.json",
"http://library.stanford.edu/iiif/image-api/1.1/context.json",
"http://iiif.io/api/search/1/context.json",
"http://iiif.io/api/search/0/context.json",
"http://iiif.io/api/auth/1/context.json",
"http://iiif.io/api/auth/0/context.json",
"http://iiif.io/api/annex/openannotation/context.json"
];
function Ee(e) {
if (e) {
let t = Array.isArray(e) ? e : [e], n = [];
for (let e of t) e === "http://iiif.io/api/presentation/2/context.json" && n.push("http://iiif.io/api/presentation/3/context.json"), Te.indexOf(e) === -1 && n.push(e);
if (t.length) return n.length === 1 ? n[0] : n;
}
}
function De(e) {
return e ? e.map((e) => ({
label: R(e.label),
value: R(e.value)
})) : [];
}
var U = 0;
function W(e, t) {
let n = encodeURI(e.id || e["@id"] || "").trim();
return n && t ? `${n}/${t}` : n || (U++, `http://example.org/${e["@type"]}${t ? `/${t}` : ""}/${U}`);
}
function G(e) {
let t = [...e.behavior || []];
e.viewingHint && t.push(e.viewingHint);
let n;
return Array.isArray(e.motivation) ? n = e.motivation.map(B) : e.motivation && (n = B(e.motivation)), {
"@context": e["@context"] ? Ee(e["@context"]) : void 0,
id: (e["@id"] || W(e)).trim(),
type: V(e),
behavior: t.length ? t : void 0,
height: e.height ? e.height : void 0,
width: e.width ? e.width : void 0,
motivation: n,
viewingDirection: e.viewingDirection,
profile: e.profile,
format: e.format ? e.format : void 0,
duration: void 0,
timeMode: void 0
};
}
function K(e) {
let [t, n] = H(e.license), r = [...e.metadata ? De(e.metadata) : [], ...n];
return {
rights: t,
metadata: r.length ? r : void 0,
label: e.label ? R(e.label) : void 0,
requiredStatement: e.attribution ? {
label: R(L.attributionLabel),
value: R(e.attribution)
} : void 0,
navDate: e.navDate,
summary: e.description ? R(e.description) : void 0,
thumbnail: Oe(e.thumbnail)
};
}
function Oe(e) {
return e && (Array.isArray(e) ? e : [e]).map((e) => typeof e == "string" ? {
id: e,
type: "Image"
} : (e.type === "unknown" && (e.type = "Image"), e));
}
function ke(e) {
if (!e.within) return;
let t = Array.isArray(e.within) ? e.within : [e.within], n = [];
for (let r of t) if (typeof r == "string") {
if (r) switch (e["@type"]) {
case "sc:Manifest":
n.push({
id: r,
type: "Collection"
});
break;
}
} else r["@id"] && n.push({
id: r["@id"],
type: V(r)
});
return n.length ? n : void 0;
}
function q(e) {
let t = e.related ? Array.isArray(e.related) ? e.related : [e.related] : [], n = e.contentLayer;
return {
provider: e.logo || t.length ? [{
id: L.providerId,
type: "Agent",
homepage: t.length ? [t[0]] : void 0,
logo: e.logo ? Array.isArray(e.logo) ? e.logo : [e.logo] : void 0,
label: R(L.providerName)
}] : void 0,
partOf: ke(e),
rendering: e.rendering,
seeAlso: e.seeAlso,
start: e.startCanvas,
service: e.service ? te(e.service) : void 0,
supplementary: n ? [n] : void 0
};
}
function Ae(e) {
return {
chars: e.chars,
format: e.format ? e.format : void 0,
language: e.language
};
}
function J(e, t) {
return e ? typeof e == "string" ? {
id: e,
type: t
} : typeof e?.["@id"] == "string" ? {
id: e["@id"],
type: t
} : typeof e.id == "string" ? {
id: e.id,
type: t
} : null : null;
}
function je(e) {
let t = {};
if (e.first) {
let n = J(e.first, "Collection");
n && (t.first = n);
}
if ((e.total || e.total === 0) && (t.total = e.total), e.prev) {
let n = J(e.prev, "Collection");
n && (t.prev = n);
}
if (e.next) {
let n = J(e.next, "Collection");
n && (t.next = n);
}
return t;
}
function Me(e) {
let t = [];
for (let n of e) {
let e = { ...n };
e.items && e.items.length === 0 && delete e.items, t.push(e);
}
return t;
}
function Ne(e) {
return _({
...G(e),
...K(e),
...q(e),
...je(e),
items: Me(e.members)
});
}
function Pe(e) {
let t = [], n = [], r, i;
for (let a of e.sequences || []) a.canvases.length && t.push(...a.canvases), a.behavior && n.push(...a.behavior), a.viewingDirection && (i = a.viewingDirection), a.startCanvas && (r = a.startCanvas);
let a = G(e);
return n.length && (a.behavior ? a.behavior.push(...n) : a.behavior = n), _({
...a,
...K(e),
...q(e),
viewingDirection: i,
start: r,
items: t,
structures: Fe(e.structures)
});
}
function Fe(e) {
if (!e) return e;
let t = /* @__PURE__ */ new Map();
for (let n of e) t.set(n.id, n);
let n = [];
for (let r of e) r.items &&= r.items.map((e) => typeof e == "string" ? (n.push(e), t.get(e) || e) : e && e.id ? (n.push(e.id), t.get(e.id) || e) : e);
return e.filter((e) => n.indexOf(e.id) === -1);
}
function Ie(e) {
return _({
...G(e),
...K(e),
...q(e),
annotations: e.otherContent && e.otherContent.length ? e.otherContent : void 0,
items: e.images && e.images.length ? [{
id: W(e, "annotation-page"),
type: "AnnotationPage",
items: e.images
}] : void 0
});
}
function Le(e) {
return _({
...G(e),
...K(e),
...q(e),
items: e.resources && e.resources.length ? e.resources : void 0
});
}
function Re(e) {
return !e.canvases || e.canvases.length === 0 ? {
canvases: [],
behavior: []
} : {
canvases: e.canvases,
behavior: e.viewingHint ? [e.viewingHint] : [],
viewingDirection: e.viewingDirection,
startCanvas: e.startCanvas
};
}
function ze(e) {
function t(e) {
if (Array.isArray(e)) {
if (e.length > 1) return {
type: "List",
items: e.map(t)
};
e = e[0];
}
if (typeof e == "string") return encodeURI(e).trim();
if ("@type" in e) {
let t;
if (typeof e.full == "string") t = e.full;
else if (e.full["@type"] === "dctypes:Image") t = {
id: e.full["@id"],
type: "Image"
};
else if (e.full["@type"] === "sc:Canvas") t = {
id: e.full["@id"],
type: "Canvas"
};
else throw Error(`Unsupported source type on annotation: ${e.full["@type"]}`);
return {
type: "SpecificResource",
source: t,
selector: Q(e.selector)
};
} else return encodeURI(e["@id"]).trim();
}
return _({
...G(e),
...K(e),
...q(e),
target: t(e.on),
body: Array.isArray(e.resource) ? e.resource.map(Y) : Y(e.resource)
});
}
function Y(e) {
return e.type === "Choice" ? e : X(e);
}
function X(e) {
let t = e;
return _({
...G(t),
...K(t),
...q(t),
...Ae(t)
});
}
function Be(e) {
let t = [];
return e.default && e.default !== "rdf:nil" && t.push(e.default), e.item && e.item !== "rdf:nil" && t.push(...e.item), _({
...G(e),
...K(e),
items: t
});
}
function Ve(e) {
return _({
...G(e),
...K(e),
...q(e),
items: e.members
});
}
function He(e) {
let { "@id": t, "@type": n, "@context": r, profile: i, ...a } = e, o = {};
return t && (o["@id"] = t), o["@type"] = V(e), o["@type"] === "unknown" && (r && r.length && (o["@context"] = r), o["@type"] = "Service"), i && (o.profile = z(i)), _({
...o,
...a
});
}
function Ue(e) {
return _({
...G(e),
...K(e),
...q(e)
});
}
var We = new I({
collection: [Ne],
manifest: [Pe],
canvas: [Ie],
annotationList: [Le],
sequence: [Re],
annotation: [ze],
contentResource: [X],
choice: [Be],
range: [Ve],
service: [He],
layer: [Ue]
});
function Z(e) {
return e && e["@context"] && (e["@context"] === "http://iiif.io/api/presentation/2/context.json" || Array.isArray(e["@context"]) && e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json") !== -1 || e["@context"] === "http://www.shared-canvas.org/ns/context.json") || e["@context"] === "http://iiif.io/api/image/2/context.json" || e["@id"] && e["@type"] === "sc:Collection" || e["@id"] && e["@type"] === "sc:Manifest" ? (e["@context"] ||= "http://iiif.io/api/presentation/2/context.json", We.traverseUnknown(e)) : e;
}
function Q(e) {
if ((Array.isArray(e["@type"]) && e["@type"].includes("oa:SvgSelector") || e["@type"] == "oa:SvgSelector") && ("chars" in e || "value" in e)) return {
type: "SvgSelector",
value: "chars" in e ? e.chars : e.value
};
if (e["@type"] === "oa:FragmentSelector") return {
type: "FragmentSelector",
value: e.value
};
if (e["@type"] === "oa:Choice") return [Q(e.default), ...(Array.isArray(e.item) ? e.item : [e.item]).map(Q)];
if (e["@type"] == "iiif:ImageApiSelector") return {
type: "ImageApiSelector",
region: "region" in e ? e.region : void 0,
rotation: "rotation" in e ? e.rotation : void 0
};
throw Error(`Unsupported selector type: ${e["@type"]}`);
}
//#endregion
//#region src/Cozy.ts
var Ge = async (e) => {
try {
new URL(e);
} catch {
return {
type: "error",
code: "INVALID_URL",
message: "The provided input is not a valid URL"
};
}
let t;
try {
if (t = await fetch(e), !t.ok) return {
type: "error",
code: "INVALID_HTTP_RESPONSE",
message: `Server responded: HTTP ${t.status} ${t.statusText ? `(${t.statusText})` : ""}`
};
} catch (e) {
return {
type: "error",
code: "FETCH_ERROR",
message: e instanceof Error ? e.message : "Failed to fetch resource"
};
}
let n = t.headers.get("content-type");
if (n?.startsWith("image/")) return {
type: "plain-image",
url: e
};
if (n?.includes("text/html")) return {
type: "webpage",
url: e
};
try {
return $(await t.json(), e);
} catch {
return {
type: "error",
code: "UNSUPPORTED_FORMAT",
message: "Could not parse resource"
};
}
}, $ = (e, t) => {
let n = Array.isArray(e["@context"]) ? e["@context"].find((e) => e.includes("iiif.io/api/presentation") || e.includes("iiif.io/api/image") || e.includes("shared-canvas")) : e["@context"];
if (!n) return {
type: "error",
code: "INVALID_MANIFEST",
message: "Missing @context"
};
let r = s(e, "id");
if (!r) return {
type: "error",
code: "INVALID_MANIFEST",
message: "Missing id property"
};
if (n.includes("presentation/2") || n.includes("presentation/3") || n.includes("shared-canvas")) {
let i = n.includes("presentation/3") ? 3 : 2;
return s(e, "type").includes("Collection") ? {
type: "collection",
url: t || r,
resource: Ke(e, i)
} : {
type: "manifest",
url: t || r,
resource: qe(e, i)
};
}
if (n.includes("image/2") || n.includes("image/3")) {
let n = Je(e);
return n ? {
type: "iiif-image",
url: t || r,
resource: n
} : {
type: "error",
code: "INVALID_MANIFEST",
message: "Invalid image service definition"
};
}
return {
type: "error",
code: "INVALID_MANIFEST",
message: "JSON resource is not a recognized IIIF format"
};
}, Ke = (t, n) => {
let r = (n) => {
let r = [];
return new e({
collection: [(e) => e.id !== s(t, "id") && r.push(e)],
manifest: [(e) => r.push(e)]
}).traverseCollection(n), r.map((e) => ({
id: e.id,
type: e.type,
getLabel: p(e),
source: e
}));
}, i = n === 2 ? Z(t) : t, a = r(i);
return {
type: "Collection",
source: i,
id: i.id,
majorVersion: n,
items: a,
getLabel: p(i),
getMetadata: u(i)
};
}, qe = (t, n) => {
let r = (t) => {
let n = [], r = [];
new e({
canvas: [(e) => {
e.items && n.push(e);
}],
range: [(e) => {
e.type === "Range" && r.push(e);
}]
}).traverseManifest(t);
let i = n.map((e) => {
let t = d(e);
return {
source: e,
id: e.id,
width: e.width,
height: e.height,
images: t,
annotations: e.annotations || [],
getImageURL: t.length > 0 ? t[0].getImageURL : () => void 0,
getLabel: p(e),
getMetadata: u(e),
getThumbnailURL: m(e, t)
};
}), a = (e) => {
let t = e.items || [], n = t.filter((e) => e.type === "Canvas").map((e) => i.find((t) => t.id === e.id)).filter(Boolean), r = t.filter((e) => e.type === "Range").map((e) => a(e)), o = [...n, ...r];
return {
source: e,
id: e.id,
items: t.map((e) => o.find((t) => t.id === e.id)),
canvases: n,
ranges: r,
getLabel: p(e)
};
};
return {
canvases: i,
ranges: r.map((e) => a(e))
};
}, i = n === 2 ? Z(t) : t, { canvases: a, ranges: o } = r(i);
return {
source: i,
id: i.id,
majorVersion: n,
canvases: a,
structure: o,
getLabel: p(i),
getMetadata: u(i),
getTableOfContents: g(o)
};
}, Je = (e) => {
let { width: t, height: n, format: r } = e, o = s(e, "id"), u = a(e);
if (u) {
let r = i(s(e, "id")), a = {
source: e,
type: u.profileLevel === 0 ? "level0" : "dynamic",
service: e,
width: t,
height: n,
majorVersion: u.majorVersion,
serviceUrl: r,
getImageURL: c(t, n, e),
getPixelSize: f(r)
};
return u.profileLevel === 0 ? a : {
...a,
getRegionURL: h(a)
};
} else return {
source: e,
type: "static",
width: t,
height: n,
url: o,
format: r,
getImageURL: () => o,
getPixelSize: l(o)
};
}, Ye = {
parse: $,
parseURL: Ge
};
//#endregion
export { Ye as Cozy, c as getImageURL, t as getImageURLFromService, d as getImages, p as getLabel, u as getMetadata, f as getPixelSizeFromServiceUrl, s as getPropertyValue, h as getRegionURL, r as getRegionURLFromService, l as getStaticImagePixelSize, o as getStringValue, g as getTableOfContents, m as getThumbnailURL, ee as isImageService, i as normalizeServiceUrl, a as parseImageService };