cozy-iiif 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,32 +1,32 @@
1
- import { g as p, a as L, b } from "./resource-DS2brz47.js";
2
- import { c as Ot } from "./resource-DS2brz47.js";
3
- var re = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", ie = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", O = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", se = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ne = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", U = "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", D = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", ce = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", le = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", E = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", pe = "http://iiif.io/api/image/1/level0.json", ve = "http://iiif.io/api/image/1/profiles/level0.json", he = "http://iiif.io/api/image/1/level1.json", ue = "http://iiif.io/api/image/1/profiles/level1.json", N = "http://iiif.io/api/image/1/level2.json", q = "http://iiif.io/api/image/1/profiles/level2.json", fe = "http://iiif.io/api/image/2/level0.json", me = "http://iiif.io/api/image/2/profiles/level0.json", ge = "http://iiif.io/api/image/2/level1.json", de = "http://iiif.io/api/image/2/profiles/level1.json", _ = "http://iiif.io/api/image/2/level2.json", V = "http://iiif.io/api/image/2/profiles/level2.json", ye = "level0", Ae = "level1", F = "level2", Ce = "http://iiif.io/api/image/2/level0", be = "http://iiif.io/api/image/2/level1", W = "http://iiif.io/api/image/2/level2", Re = [W, O, U, D, E, N, q, _, V, F], Le = [Ce, be, W, re, ie, O, se, ne, U, ae, oe, D, ce, le, E, pe, ve, he, ue, N, q, fe, me, ge, de, _, V, ye, Ae, F], we = Le;
4
- function v(t) {
1
+ import { g as u, a as M, b as w } from "./resource-DS2brz47.js";
2
+ import { c as rr } from "./resource-DS2brz47.js";
3
+ var he = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", fe = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", B = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", ge = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", de = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", J = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", me = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", ye = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", z = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ae = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", be = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", G = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", Ce = "http://iiif.io/api/image/1/level0.json", Re = "http://iiif.io/api/image/1/profiles/level0.json", Le = "http://iiif.io/api/image/1/level1.json", we = "http://iiif.io/api/image/1/profiles/level1.json", K = "http://iiif.io/api/image/1/level2.json", Q = "http://iiif.io/api/image/1/profiles/level2.json", Ie = "http://iiif.io/api/image/2/level0.json", Se = "http://iiif.io/api/image/2/profiles/level0.json", xe = "http://iiif.io/api/image/2/level1.json", Te = "http://iiif.io/api/image/2/profiles/level1.json", X = "http://iiif.io/api/image/2/level2.json", Y = "http://iiif.io/api/image/2/profiles/level2.json", $e = "level0", Me = "level1", Z = "level2", je = "http://iiif.io/api/image/2/level0", ke = "http://iiif.io/api/image/2/level1", ee = "http://iiif.io/api/image/2/level2", Oe = [ee, B, J, z, G, K, Q, X, Y, Z], Pe = [je, ke, ee, he, fe, B, ge, de, J, me, ye, z, Ae, be, G, Ce, Re, Le, we, K, Q, Ie, Se, xe, Te, X, Y, $e, Me, Z], Ue = Pe;
4
+ function h(t) {
5
5
  for (let e in t) (typeof t[e] > "u" || t[e] === null) && delete t[e];
6
6
  return t;
7
7
  }
8
- function g(t) {
8
+ function R(t) {
9
9
  return Array.isArray(t) ? t : t ? [t] : [];
10
10
  }
11
- var Ie = Object.defineProperty, Se = (t, e, r) => e in t ? Ie(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, f = (t, e, r) => (Se(t, typeof e != "symbol" ? e + "" : e, r), r), x = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
12
- function Te(t) {
11
+ var De = Object.defineProperty, Ee = (t, e, r) => e in t ? De(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, A = (t, e, r) => (Ee(t, typeof e != "symbol" ? e + "" : e, r), r), E = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
12
+ function Ve(t) {
13
13
  if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
14
14
  if (Array.isArray(t)) throw new Error("Array is not a valid entity");
15
15
  if (typeof t != "object") throw new Error(`${typeof t} is not a valid entity`);
16
16
  if (typeof t["@type"] == "string") {
17
- let e = x.indexOf(t["@type"]);
18
- if (e !== -1) return x[e];
17
+ let e = E.indexOf(t["@type"]);
18
+ if (e !== -1) return E[e];
19
19
  }
20
20
  if (t.profile) return "Service";
21
21
  if (t.format || t["@type"]) return "ContentResource";
22
22
  throw new Error("Resource type is not known");
23
23
  }
24
- var xe = class B {
24
+ var Ne = class te {
25
25
  constructor(e, r = {}) {
26
- f(this, "traversals"), f(this, "options"), this.traversals = { collection: [], manifest: [], canvas: [], annotationList: [], sequence: [], annotation: [], contentResource: [], choice: [], range: [], service: [], layer: [], ...e }, this.options = { convertPropsToArray: !0, mergeMemberProperties: !0, allowUndefinedReturn: !1, ...r };
26
+ A(this, "traversals"), A(this, "options"), this.traversals = { collection: [], manifest: [], canvas: [], annotationList: [], sequence: [], annotation: [], contentResource: [], choice: [], range: [], service: [], layer: [], ...e }, this.options = { convertPropsToArray: !0, mergeMemberProperties: !0, allowUndefinedReturn: !1, ...r };
27
27
  }
28
28
  static all(e) {
29
- return new B({ collection: [e], manifest: [e], canvas: [e], annotationList: [e], sequence: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], layer: [e] });
29
+ return new te({ collection: [e], manifest: [e], canvas: [e], annotationList: [e], sequence: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], layer: [e] });
30
30
  }
31
31
  traverseCollection(e) {
32
32
  return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))), this.traversals.collection);
@@ -99,7 +99,7 @@ var xe = class B {
99
99
  }
100
100
  traverseUnknown(e) {
101
101
  if (!e["@type"] || typeof e == "string") return e;
102
- switch (Te(e)) {
102
+ switch (Ve(e)) {
103
103
  case "sc:Collection":
104
104
  return this.traverseCollection(e);
105
105
  case "sc:Manifest":
@@ -126,17 +126,17 @@ var xe = class B {
126
126
  return e.profile ? this.traverseService(e) : e;
127
127
  }
128
128
  traverseImageResource(e) {
129
- let r = Array.isArray(e), i = Array.isArray(e) ? e : [e], s = [];
130
- for (let n of i) typeof n == "string" ? s.push(this.traverseContentResource({ "@id": n, "@type": "dctypes:Image" })) : s.push(this.traverseContentResource(n));
131
- return !r && !this.options.convertPropsToArray ? s[0] : s;
129
+ let r = Array.isArray(e), i = Array.isArray(e) ? e : [e], n = [];
130
+ for (let s of i) typeof s == "string" ? n.push(this.traverseContentResource({ "@id": s, "@type": "dctypes:Image" })) : n.push(this.traverseContentResource(s));
131
+ return !r && !this.options.convertPropsToArray ? n[0] : n;
132
132
  }
133
133
  traverseDescriptive(e) {
134
134
  return e.thumbnail && (e.thumbnail = this.traverseImageResource(e.thumbnail)), e.logo && (e.logo = this.traverseImageResource(e.logo)), e;
135
135
  }
136
136
  traverseOneOrMoreServices(e) {
137
- let r = Array.isArray(e), i = Array.isArray(e) ? e : [e], s = [];
138
- for (let n of i) s.push(this.traverseService(n));
139
- return !r && !this.options.convertPropsToArray ? s[0] : s;
137
+ let r = Array.isArray(e), i = Array.isArray(e) ? e : [e], n = [];
138
+ for (let s of i) n.push(this.traverseService(s));
139
+ return !r && !this.options.convertPropsToArray ? n[0] : n;
140
140
  }
141
141
  traverseLinking(e) {
142
142
  return e.related && (e.related = this.traverseOneOrManyType(e.related, this.traversals.contentResource)), e.rendering && (e.rendering = this.traverseOneOrManyType(e.rendering, this.traversals.contentResource)), e.service && (e.service = this.traverseOneOrMoreServices(e.service)), e.seeAlso && (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;
@@ -147,13 +147,13 @@ var xe = class B {
147
147
  return e.map((i) => this.traverseType(i, r));
148
148
  }
149
149
  traverseType(e, r) {
150
- return r.reduce((i, s) => {
151
- let n = s(i);
152
- return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
150
+ return r.reduce((i, n) => {
151
+ let s = n(i);
152
+ return typeof s > "u" && !this.options.allowUndefinedReturn ? i : s;
153
153
  }, e);
154
154
  }
155
- }, $e = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", je = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Me = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", ke = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", Pe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", Oe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ue = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", De = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", Ee = "http://iiif.io/api/image/1/level1.json", Ne = "http://iiif.io/api/image/1/profiles/level1.json", qe = "http://iiif.io/api/image/1/level2.json", _e = "http://iiif.io/api/image/1/profiles/level2.json", Ve = "http://iiif.io/api/image/2/level1.json", Fe = "http://iiif.io/api/image/2/profiles/level1.json", We = "http://iiif.io/api/image/2/level2.json", Be = "http://iiif.io/api/image/2/profiles/level2.json", He = "level1", Je = "level2", Ge = "http://iiif.io/api/image/2/level1", ze = "http://iiif.io/api/image/2/level2", Ke = [Ge, ze, $e, je, Me, ke, Pe, Oe, Ue, De, Ee, Ne, qe, _e, Ve, Fe, We, Be, He, Je], w = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
156
- function Qe(t) {
155
+ }, _e = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", qe = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Fe = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", We = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", He = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", Be = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Je = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", ze = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", Ge = "http://iiif.io/api/image/1/level1.json", Ke = "http://iiif.io/api/image/1/profiles/level1.json", Qe = "http://iiif.io/api/image/1/level2.json", Xe = "http://iiif.io/api/image/1/profiles/level2.json", Ye = "http://iiif.io/api/image/2/level1.json", Ze = "http://iiif.io/api/image/2/profiles/level1.json", et = "http://iiif.io/api/image/2/level2.json", tt = "http://iiif.io/api/image/2/profiles/level2.json", rt = "level1", it = "level2", nt = "http://iiif.io/api/image/2/level1", st = "http://iiif.io/api/image/2/level2", at = [nt, st, _e, qe, Fe, We, He, Be, Je, ze, Ge, Ke, Qe, Xe, Ye, Ze, et, tt, rt, it], j = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
156
+ function ot(t) {
157
157
  if (typeof t == "string") return [t];
158
158
  if (!t) return [];
159
159
  let e = Array.isArray(t) ? t : [t], r = [];
@@ -166,31 +166,31 @@ function Qe(t) {
166
166
  }
167
167
  return r;
168
168
  }
169
- function d(t, e = "none") {
169
+ function L(t, e = "none") {
170
170
  if (!t) return { none: [""] };
171
- let r = Qe(t), i = {};
172
- for (let s of r) {
173
- if (typeof s == "string") {
174
- i[e] = i[e] ? i[e] : [], i[e].push(s || "");
171
+ let r = ot(t), i = {};
172
+ for (let n of r) {
173
+ if (typeof n == "string") {
174
+ i[e] = i[e] ? i[e] : [], i[e].push(n || "");
175
175
  continue;
176
176
  }
177
- if (!s["@language"]) {
178
- i[e] = i[e] ? i[e] : [], i[e].push(s["@value"] || "");
177
+ if (!n["@language"]) {
178
+ i[e] = i[e] ? i[e] : [], i[e].push(n["@value"] || "");
179
179
  continue;
180
180
  }
181
- let n = s["@language"];
182
- i[n] = i[n] ? i[n] : [], i[n].push(s["@value"] || "");
181
+ let s = n["@language"];
182
+ i[s] = i[s] ? i[s] : [], i[s].push(n["@value"] || "");
183
183
  }
184
184
  return Object.keys(i).length === 0 ? { none: [""] } : i;
185
185
  }
186
- function H(t) {
187
- if (Array.isArray(t)) return H(t.find((e) => typeof e == "string"));
188
- if (Re.indexOf(t) !== -1) return "level2";
189
- if (Ke.indexOf(t) !== -1) return "level1";
190
- if (we.indexOf(t) !== -1) return "level0";
186
+ function re(t) {
187
+ if (Array.isArray(t)) return re(t.find((e) => typeof e == "string"));
188
+ if (Oe.indexOf(t) !== -1) return "level2";
189
+ if (at.indexOf(t) !== -1) return "level1";
190
+ if (Ue.indexOf(t) !== -1) return "level0";
191
191
  if (typeof t == "string") return t;
192
192
  }
193
- function Xe(t) {
193
+ function ct(t) {
194
194
  let e = Array.isArray(t) ? t : [t];
195
195
  for (let r of e) switch (r) {
196
196
  case "http://iiif.io/api/image/2/context.json":
@@ -203,7 +203,7 @@ function Xe(t) {
203
203
  return "ImageApiSelector";
204
204
  }
205
205
  }
206
- function Ye(t) {
206
+ function lt(t) {
207
207
  switch (t) {
208
208
  case "http://iiif.io/api/image/2/level0.json":
209
209
  case "http://iiif.io/api/image/2/level1.json":
@@ -232,20 +232,20 @@ function Ye(t) {
232
232
  return "AutoCompleteService1";
233
233
  }
234
234
  }
235
- function $(t) {
235
+ function V(t) {
236
236
  for (let e of ["sc", "oa", "dcterms", "dctypes", "iiif"]) if (t.startsWith(`${e}:`)) return t.slice(e.length + 1);
237
237
  return t;
238
238
  }
239
- var Ze = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
240
- function S(t) {
241
- let e = t["@id"] || t.id, r = t["@type"] || t.type, i = t.profile || void 0, s = t["@context"] || void 0;
239
+ var pt = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
240
+ function O(t) {
241
+ let e = t["@id"] || t.id, r = t["@type"] || t.type, i = t.profile || void 0, n = t["@context"] || void 0;
242
242
  if (i) {
243
- let n = Ye(i);
244
- if (n) return n;
243
+ let s = lt(i);
244
+ if (s) return s;
245
245
  }
246
- if (s) {
247
- let n = Xe(s);
248
- if (n) return n;
246
+ if (n) {
247
+ let s = ct(n);
248
+ if (s) return s;
249
249
  }
250
250
  if (r) {
251
251
  if (Array.isArray(r)) {
@@ -253,8 +253,8 @@ function S(t) {
253
253
  if (r.indexOf("cnt:ContentAsText") !== -1) return "TextualBody";
254
254
  r = r[0];
255
255
  }
256
- for (let n of ["sc", "oa", "dcterms", "dctypes", "iiif"]) if (r.startsWith(`${n}:`)) {
257
- r = r.slice(n.length + 1);
256
+ for (let s of ["sc", "oa", "dcterms", "dctypes", "iiif"]) if (r.startsWith(`${s}:`)) {
257
+ r = r.slice(s.length + 1);
258
258
  break;
259
259
  }
260
260
  switch (r) {
@@ -266,7 +266,7 @@ function S(t) {
266
266
  return "TextualBody";
267
267
  }
268
268
  }
269
- if (r && Ze.indexOf(r) !== -1) return r;
269
+ if (r && pt.indexOf(r) !== -1) return r;
270
270
  if (t.format) {
271
271
  if (t.format.startsWith("image/")) return "Image";
272
272
  if (t.format.startsWith("text/") || t.format === "application/pdf") return "Text";
@@ -274,53 +274,53 @@ function S(t) {
274
274
  }
275
275
  return e && (e.endsWith(".jpg") || e.endsWith(".png") || e.endsWith(".jpeg")) ? "Image" : r || "unknown";
276
276
  }
277
- var et = /http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;
278
- function tt(t) {
279
- let e = t.match(et);
277
+ var vt = /http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;
278
+ function ut(t) {
279
+ let e = t.match(vt);
280
280
  return e ? e[0] : t;
281
281
  }
282
- function rt(t, e = "Rights/License", r = "none") {
283
- let i = null, s = [], n = Array.isArray(t) ? t : [t];
284
- for (let a of n) {
285
- let o = a ? tt(a) : void 0;
282
+ function ht(t, e = "Rights/License", r = "none") {
283
+ let i = null, n = [], s = Array.isArray(t) ? t : [t];
284
+ for (let a of s) {
285
+ let o = a ? ut(a) : void 0;
286
286
  if (o && (o.indexOf("creativecommons.org") !== -1 || o.indexOf("rightsstatements.org") !== -1)) {
287
287
  o.startsWith("https://") ? i = `http://${o.slice(8)}` : i = o;
288
288
  continue;
289
289
  }
290
- o && s.push({ label: { [r]: [e] }, value: { [r]: [o] } });
290
+ o && n.push({ label: { [r]: [e] }, value: { [r]: [o] } });
291
291
  }
292
- return [i, s];
292
+ return [i, n];
293
293
  }
294
- var it = ["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"];
295
- function st(t) {
294
+ var ft = ["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"];
295
+ function gt(t) {
296
296
  if (t) {
297
297
  let e = Array.isArray(t) ? t : [t], r = [];
298
- for (let i of e) i === "http://iiif.io/api/presentation/2/context.json" && r.push("http://iiif.io/api/presentation/3/context.json"), it.indexOf(i) === -1 && r.push(i);
298
+ for (let i of e) i === "http://iiif.io/api/presentation/2/context.json" && r.push("http://iiif.io/api/presentation/3/context.json"), ft.indexOf(i) === -1 && r.push(i);
299
299
  if (e.length) return r.length === 1 ? r[0] : r;
300
300
  }
301
301
  }
302
- function nt(t) {
303
- return t ? t.map((e) => ({ label: d(e.label), value: d(e.value) })) : [];
302
+ function dt(t) {
303
+ return t ? t.map((e) => ({ label: L(e.label), value: L(e.value) })) : [];
304
304
  }
305
- var j = 0;
306
- function J(t, e) {
305
+ var N = 0;
306
+ function ie(t, e) {
307
307
  let r = encodeURI(t.id || t["@id"] || "").trim();
308
- return r && e ? `${r}/${e}` : r || (j++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${j}`);
308
+ return r && e ? `${r}/${e}` : r || (N++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${N}`);
309
309
  }
310
- function h(t) {
310
+ function d(t) {
311
311
  let e = [...t.behavior || []];
312
312
  t.viewingHint && e.push(t.viewingHint);
313
313
  let r;
314
- return Array.isArray(t.motivation) ? r = t.motivation.map($) : t.motivation && (r = $(t.motivation)), { "@context": t["@context"] ? st(t["@context"]) : void 0, id: (t["@id"] || J(t)).trim(), type: S(t), behavior: e.length ? e : void 0, height: t.height ? t.height : void 0, width: t.width ? t.width : void 0, motivation: r, viewingDirection: t.viewingDirection, profile: t.profile, format: t.format ? t.format : void 0, duration: void 0, timeMode: void 0 };
314
+ return Array.isArray(t.motivation) ? r = t.motivation.map(V) : t.motivation && (r = V(t.motivation)), { "@context": t["@context"] ? gt(t["@context"]) : void 0, id: (t["@id"] || ie(t)).trim(), type: O(t), behavior: e.length ? e : void 0, height: t.height ? t.height : void 0, width: t.width ? t.width : void 0, motivation: r, viewingDirection: t.viewingDirection, profile: t.profile, format: t.format ? t.format : void 0, duration: void 0, timeMode: void 0 };
315
315
  }
316
- function u(t) {
317
- let [e, r] = rt(t.license), i = [...t.metadata ? nt(t.metadata) : [], ...r];
318
- return { rights: e, metadata: i.length ? i : void 0, label: t.label ? d(t.label) : void 0, requiredStatement: t.attribution ? { label: d(w.attributionLabel), value: d(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? d(t.description) : void 0, thumbnail: at(t.thumbnail) };
316
+ function m(t) {
317
+ let [e, r] = ht(t.license), i = [...t.metadata ? dt(t.metadata) : [], ...r];
318
+ return { rights: e, metadata: i.length ? i : void 0, label: t.label ? L(t.label) : void 0, requiredStatement: t.attribution ? { label: L(j.attributionLabel), value: L(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? L(t.description) : void 0, thumbnail: mt(t.thumbnail) };
319
319
  }
320
- function at(t) {
320
+ function mt(t) {
321
321
  return t && (Array.isArray(t) ? t : [t]).map((e) => typeof e == "string" ? { id: e, type: "Image" } : (e.type === "unknown" && (e.type = "Image"), e));
322
322
  }
323
- function ot(t) {
323
+ function yt(t) {
324
324
  if (!t.within) return;
325
325
  let e = Array.isArray(t.within) ? t.within : [t.within], r = [];
326
326
  for (let i of e) if (typeof i == "string") {
@@ -329,46 +329,46 @@ function ot(t) {
329
329
  r.push({ id: i, type: "Collection" });
330
330
  break;
331
331
  }
332
- } else i["@id"] && r.push({ id: i["@id"], type: S(i) });
332
+ } else i["@id"] && r.push({ id: i["@id"], type: O(i) });
333
333
  return r.length ? r : void 0;
334
334
  }
335
- function m(t) {
335
+ function b(t) {
336
336
  let e = t.related ? Array.isArray(t.related) ? t.related : [t.related] : [], r = t.contentLayer;
337
- return { provider: t.logo || e.length ? [{ id: w.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: d(w.providerName) }] : void 0, partOf: ot(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? g(t.service) : void 0, supplementary: r ? [r] : void 0 };
337
+ return { provider: t.logo || e.length ? [{ id: j.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: L(j.providerName) }] : void 0, partOf: yt(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? R(t.service) : void 0, supplementary: r ? [r] : void 0 };
338
338
  }
339
- function ct(t) {
339
+ function At(t) {
340
340
  return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
341
341
  }
342
- function lt(t) {
343
- return v({ ...h(t), ...u(t), ...m(t), items: t.members });
342
+ function bt(t) {
343
+ return h({ ...d(t), ...m(t), ...b(t), items: t.members });
344
344
  }
345
- function pt(t) {
345
+ function Ct(t) {
346
346
  let e = [], r = [], i;
347
- for (let n of t.sequences || []) n.canvases.length && e.push(...n.canvases), n.behavior && r.push(...n.behavior), n.startCanvas && (i = n.startCanvas);
348
- let s = h(t);
349
- return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), v({ ...s, ...u(t), ...m(t), start: i, items: e, structures: vt(t.structures) });
347
+ for (let s of t.sequences || []) s.canvases.length && e.push(...s.canvases), s.behavior && r.push(...s.behavior), s.startCanvas && (i = s.startCanvas);
348
+ let n = d(t);
349
+ return r.length && (n.behavior ? n.behavior.push(...r) : n.behavior = r), h({ ...n, ...m(t), ...b(t), start: i, items: e, structures: Rt(t.structures) });
350
350
  }
351
- function vt(t) {
351
+ function Rt(t) {
352
352
  if (!t) return t;
353
353
  let e = /* @__PURE__ */ new Map();
354
354
  for (let i of t) e.set(i.id, i);
355
355
  let r = [];
356
356
  for (let i of t) if (i.items) {
357
- let s = i.items.map((n) => typeof n == "string" ? (r.push(n), e.get(n) || n) : n && n.id ? (r.push(n.id), e.get(n.id) || n) : n);
358
- i.items = s;
357
+ let n = i.items.map((s) => typeof s == "string" ? (r.push(s), e.get(s) || s) : s && s.id ? (r.push(s.id), e.get(s.id) || s) : s);
358
+ i.items = n;
359
359
  }
360
360
  return t.filter((i) => r.indexOf(i.id) === -1);
361
361
  }
362
- function ht(t) {
363
- return v({ ...h(t), ...u(t), ...m(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: J(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
362
+ function Lt(t) {
363
+ return h({ ...d(t), ...m(t), ...b(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: ie(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
364
364
  }
365
- function ut(t) {
366
- return v({ ...h(t), ...u(t), ...m(t), items: t.resources && t.resources.length ? t.resources : void 0 });
365
+ function wt(t) {
366
+ return h({ ...d(t), ...m(t), ...b(t), items: t.resources && t.resources.length ? t.resources : void 0 });
367
367
  }
368
- function ft(t) {
368
+ function It(t) {
369
369
  return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
370
370
  }
371
- function mt(t) {
371
+ function St(t) {
372
372
  function e(r) {
373
373
  if (Array.isArray(r)) {
374
374
  if (r.length > 1) return { type: "List", items: r.map(e) };
@@ -381,51 +381,51 @@ function mt(t) {
381
381
  else if (r.full["@type"] === "dctypes:Image") i = { id: r.full["@id"], type: "Image" };
382
382
  else if (r.full["@type"] === "sc:Canvas") i = { id: r.full["@id"], type: "Canvas" };
383
383
  else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);
384
- return { type: "SpecificResource", source: i, selector: I(r.selector) };
384
+ return { type: "SpecificResource", source: i, selector: k(r.selector) };
385
385
  } else return encodeURI(r["@id"]).trim();
386
386
  }
387
- return v({ ...h(t), ...u(t), ...m(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(M) : M(t.resource) });
387
+ return h({ ...d(t), ...m(t), ...b(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(_) : _(t.resource) });
388
388
  }
389
- function M(t) {
390
- return t.type === "Choice" ? t : G(t);
389
+ function _(t) {
390
+ return t.type === "Choice" ? t : ne(t);
391
391
  }
392
- function G(t) {
392
+ function ne(t) {
393
393
  let e = t;
394
- return v({ ...h(e), ...u(e), ...m(e), ...ct(e) });
394
+ return h({ ...d(e), ...m(e), ...b(e), ...At(e) });
395
395
  }
396
- function gt(t) {
396
+ function xt(t) {
397
397
  let e = [];
398
- return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), v({ ...h(t), ...u(t), items: e });
398
+ return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), h({ ...d(t), ...m(t), items: e });
399
399
  }
400
- function dt(t) {
401
- return v({ ...h(t), ...u(t), ...m(t), items: t.members });
400
+ function Tt(t) {
401
+ return h({ ...d(t), ...m(t), ...b(t), items: t.members });
402
402
  }
403
- function yt(t) {
404
- let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, a = {};
405
- return e && (a["@id"] = e), a["@type"] = S(t), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), s && (a.profile = H(s)), v({ ...a, ...n });
403
+ function $t(t) {
404
+ let { "@id": e, "@type": r, "@context": i, profile: n, ...s } = t, a = {};
405
+ return e && (a["@id"] = e), a["@type"] = O(t), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), n && (a.profile = re(n)), h({ ...a, ...s });
406
406
  }
407
- function At(t) {
408
- return v({ ...h(t), ...u(t), ...m(t) });
407
+ function Mt(t) {
408
+ return h({ ...d(t), ...m(t), ...b(t) });
409
409
  }
410
- var Ct = new xe({ collection: [lt], manifest: [pt], canvas: [ht], annotationList: [ut], sequence: [ft], annotation: [mt], contentResource: [G], choice: [gt], range: [dt], service: [yt], layer: [At] });
411
- function z(t) {
412
- return t && t["@context"] && (t["@context"] === "http://iiif.io/api/presentation/2/context.json" || t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json") !== -1 || t["@context"] === "http://www.shared-canvas.org/ns/context.json") || t["@context"] === "http://iiif.io/api/image/2/context.json" ? Ct.traverseUnknown(t) : t;
410
+ var jt = new Ne({ collection: [bt], manifest: [Ct], canvas: [Lt], annotationList: [wt], sequence: [It], annotation: [St], contentResource: [ne], choice: [xt], range: [Tt], service: [$t], layer: [Mt] });
411
+ function se(t) {
412
+ return t && t["@context"] && (t["@context"] === "http://iiif.io/api/presentation/2/context.json" || t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json") !== -1 || t["@context"] === "http://www.shared-canvas.org/ns/context.json") || t["@context"] === "http://iiif.io/api/image/2/context.json" ? jt.traverseUnknown(t) : t;
413
413
  }
414
- function I(t) {
414
+ function k(t) {
415
415
  if ((Array.isArray(t["@type"]) && t["@type"].includes("oa:SvgSelector") || t["@type"] == "oa:SvgSelector") && ("chars" in t || "value" in t)) return { type: "SvgSelector", value: "chars" in t ? t.chars : t.value };
416
416
  if (t["@type"] === "oa:FragmentSelector") return { type: "FragmentSelector", value: t.value };
417
- if (t["@type"] === "oa:Choice") return [I(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(I)];
417
+ if (t["@type"] === "oa:Choice") return [k(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(k)];
418
418
  if (t["@type"] == "iiif:ImageApiSelector") return { type: "ImageApiSelector", region: "region" in t ? t.region : void 0, rotation: "rotation" in t ? t.rotation : void 0 };
419
419
  throw new Error(`Unsupported selector type: ${t["@type"]}`);
420
420
  }
421
- function R(t) {
421
+ function T(t) {
422
422
  return typeof t == "string" ? !1 : t && !t.type && "source" in t ? (t.type = "SpecificResource", !0) : !!t && t.type === "SpecificResource";
423
423
  }
424
- function C(...t) {
424
+ function I(...t) {
425
425
  return (e) => t.reduce((r, i) => i(r), e);
426
426
  }
427
- var k = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
428
- function bt(t, e) {
427
+ var q = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
428
+ function kt(t, e) {
429
429
  if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
430
430
  if (Array.isArray(t)) throw new Error("Array is not a valid entity");
431
431
  if (typeof t != "object") {
@@ -433,24 +433,24 @@ function bt(t, e) {
433
433
  throw new Error(`${typeof t} is not a valid entity`);
434
434
  }
435
435
  if (typeof t.type == "string") {
436
- let r = k.indexOf(t.type);
437
- if (r !== -1) return k[r];
436
+ let r = q.indexOf(t.type);
437
+ if (r !== -1) return q[r];
438
438
  }
439
439
  if (t.profile) return "Service";
440
440
  throw new Error("Resource type is not known");
441
441
  }
442
- var T = class K {
442
+ var P = class ae {
443
443
  constructor(e, r = {}) {
444
- f(this, "traversals"), f(this, "options"), f(this, "_traverseManifest", C(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), f(this, "_traverseCanvas", C(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), f(this, "_traverseAnnotationPage", C(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), f(this, "_traverseRange", C(this.traverseRangeRanges.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this))), this.traversals = { collection: [], manifest: [], canvas: [], annotationCollection: [], annotationPage: [], annotation: [], contentResource: [], choice: [], range: [], service: [], agent: [], specificResource: [], geoJson: [], ...e }, this.options = { allowUndefinedReturn: !1, ...r };
444
+ A(this, "traversals"), A(this, "options"), A(this, "_traverseManifest", I(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), A(this, "_traverseCanvas", I(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), A(this, "_traverseAnnotationPage", I(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), A(this, "_traverseRange", I(this.traverseRangeRanges.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this))), this.traversals = { collection: [], manifest: [], canvas: [], annotationCollection: [], annotationPage: [], annotation: [], contentResource: [], choice: [], range: [], service: [], agent: [], specificResource: [], geoJson: [], ...e }, this.options = { allowUndefinedReturn: !1, ...r };
445
445
  }
446
446
  static all(e) {
447
- return new K({ collection: [e], manifest: [e], canvas: [e], annotationCollection: [e], annotationPage: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], geoJson: [e], specificResource: [e], agent: [e] });
447
+ return new ae({ collection: [e], manifest: [e], canvas: [e], annotationCollection: [e], annotationPage: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], geoJson: [e], specificResource: [e], agent: [e] });
448
448
  }
449
449
  traverseDescriptive(e) {
450
- return e.thumbnail && (e.thumbnail = g(e.thumbnail).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.provider && (e.provider = e.provider.map((r) => this.traverseAgent(r, e))), e;
450
+ return e.thumbnail && (e.thumbnail = R(e.thumbnail).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.provider && (e.provider = e.provider.map((r) => this.traverseAgent(r, e))), e;
451
451
  }
452
452
  traverseLinking(e) {
453
- return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service = g(e.service).map((r) => this.traverseService(r))), e.services && (e.services = g(e.services).map((r) => this.traverseService(r, e))), e.logo && (e.logo = e.logo.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.homepage && (e.homepage = g(e.homepage).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.partOf && (e.partOf = e.partOf.map((r) => typeof r == "string" || !r.type ? this.traverseType(r, { parent: e }, this.traversals.contentResource) : r.type === "Canvas" ? this.traverseType(r, { parent: e }, this.traversals.canvas) : r.type === "AnnotationCollection" ? this.traverseType(r, { parent: e }, this.traversals.annotationCollection) : r.type === "Collection" ? this.traverseType(r, { parent: e }, this.traversals.collection) : this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.start && (R(e.start) ? e.start = this.traverseSpecificResource(e.start, "Canvas", e) : e.start = this.traverseType(e.start, { parent: e }, this.traversals.canvas)), e.rendering && (e.rendering = e.rendering.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.supplementary && (e.supplementary = e.supplementary.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e;
453
+ return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service = R(e.service).map((r) => this.traverseService(r))), e.services && (e.services = R(e.services).map((r) => this.traverseService(r, e))), e.logo && (e.logo = e.logo.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.homepage && (e.homepage = R(e.homepage).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.partOf && (e.partOf = e.partOf.map((r) => typeof r == "string" || !r.type ? this.traverseType(r, { parent: e }, this.traversals.contentResource) : r.type === "Canvas" ? this.traverseType(r, { parent: e }, this.traversals.canvas) : r.type === "AnnotationCollection" ? this.traverseType(r, { parent: e }, this.traversals.annotationCollection) : r.type === "Collection" ? this.traverseType(r, { parent: e }, this.traversals.collection) : this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.start && (T(e.start) ? e.start = this.traverseSpecificResource(e.start, "Canvas", e) : e.start = this.traverseType(e.start, { parent: e }, this.traversals.canvas)), e.rendering && (e.rendering = e.rendering.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.supplementary && (e.supplementary = e.supplementary.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e;
454
454
  }
455
455
  traverseCollectionItems(e) {
456
456
  return e.items && e.items.map((r) => r.type === "Collection" ? this.traverseCollection(r) : this.traverseManifest(r)), e;
@@ -498,17 +498,17 @@ var T = class K {
498
498
  return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))), { parent: r }, this.traversals.annotation);
499
499
  }
500
500
  traverseContentResourceLinking(e) {
501
- return typeof e == "string" || !e || e && e.service && (e.service = g(e.service || []).map((r) => this.traverseService(r, e))), e;
501
+ return typeof e == "string" || !e || e && e.service && (e.service = R(e.service || []).map((r) => this.traverseService(r, e))), e;
502
502
  }
503
503
  traverseContentResource(e, r) {
504
- return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))), R(e) ? this.traverseSpecificResource(e, "ContentResource") : this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)), { parent: r }, this.traversals.contentResource);
504
+ return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))), T(e) ? this.traverseSpecificResource(e, "ContentResource") : this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)), { parent: r }, this.traversals.contentResource);
505
505
  }
506
506
  traverseSpecificResource(e, r, i) {
507
- let s = e.source;
508
- return typeof e.source == "string" && (s = { id: e.source, type: r || "unknown" }), this.traverseType({ ...e, source: r === "Canvas" || s.type === "Canvas" ? this.traverseType(s, { parent: i }, this.traversals.canvas) : r === "ContentResource" ? this.traverseContentResource(s, { parent: i }) : this.traverseUnknown(s, { parent: i, typeHint: r }) }, { parent: i }, this.traversals.specificResource);
507
+ let n = e.source;
508
+ return typeof e.source == "string" && (n = { id: e.source, type: r || "unknown" }), this.traverseType({ ...e, source: r === "Canvas" || n.type === "Canvas" ? this.traverseType(n, { parent: i }, this.traversals.canvas) : r === "ContentResource" ? this.traverseContentResource(n, { parent: i }) : this.traverseUnknown(n, { parent: i, typeHint: r }) }, { parent: i }, this.traversals.specificResource);
509
509
  }
510
510
  traverseRangeRanges(e) {
511
- return e.items && (e.items = e.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, e) : R(r) ? this.traverseSpecificResource(r, "Canvas", e) : r.type === "Manifest" ? this.traverseManifest(r, e) : this.traverseRange(r, e))), e;
511
+ return e.items && (e.items = e.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, e) : T(r) ? this.traverseSpecificResource(r, "Canvas", e) : r.type === "Manifest" ? this.traverseManifest(r, e) : this.traverseRange(r, e))), e;
512
512
  }
513
513
  traverseRange(e, r) {
514
514
  return this.traverseType(this._traverseRange(e), { parent: r }, this.traversals.range);
@@ -517,18 +517,18 @@ var T = class K {
517
517
  return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)), { parent: r }, this.traversals.agent);
518
518
  }
519
519
  traverseType(e, r, i) {
520
- return i.reduce((s, n) => {
521
- let a = n(s, r);
522
- return typeof a > "u" && !this.options.allowUndefinedReturn ? s : a;
520
+ return i.reduce((n, s) => {
521
+ let a = s(n, r);
522
+ return typeof a > "u" && !this.options.allowUndefinedReturn ? n : a;
523
523
  }, e);
524
524
  }
525
525
  traverseService(e, r) {
526
526
  let i = Object.assign({}, e);
527
- return i && i.service && (i.service = g(i.service).map((s) => this.traverseService(s))), this.traverseType(i, { parent: r }, this.traversals.service);
527
+ return i && i.service && (i.service = R(i.service).map((n) => this.traverseService(n))), this.traverseType(i, { parent: r }, this.traversals.service);
528
528
  }
529
529
  traverseUnknown(e, { parent: r, typeHint: i } = {}) {
530
- let s = bt(e, i);
531
- switch (s) {
530
+ let n = kt(e, i);
531
+ switch (n) {
532
532
  case "Collection":
533
533
  return this.traverseCollection(e, r);
534
534
  case "Manifest":
@@ -548,20 +548,20 @@ var T = class K {
548
548
  case "Agent":
549
549
  return this.traverseAgent(e, r);
550
550
  default:
551
- throw new Error(`Unknown or unsupported resource type of ${s}`);
551
+ throw new Error(`Unknown or unsupported resource type of ${n}`);
552
552
  }
553
553
  }
554
554
  };
555
- const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), X = (t) => {
556
- const e = p(t, "type"), r = p(t, "context");
555
+ const oe = (t) => u(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ce = (t) => {
556
+ const e = u(t, "type"), r = u(t, "context");
557
557
  if (e === "ImageService2" || r != null && r.includes("image/2")) {
558
- const i = t, s = ["level0", "level1", "level2"];
559
- return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((o) => s.findIndex((c) => o.toString().includes(c))).filter((o) => o > -1).sort((o, c) => c - o)[0] };
558
+ const i = t, n = ["level0", "level1", "level2"];
559
+ return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((o) => n.findIndex((c) => o.toString().includes(c))).filter((o) => o > -1).sort((o, c) => c - o)[0] };
560
560
  } else if (e || r)
561
561
  return { majorVersion: 3, profileLevel: parseInt(t.profile) };
562
- }, P = (t, e, r) => {
563
- const i = p(t, "id"), s = t.profile || "";
564
- if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
562
+ }, F = (t, e, r) => {
563
+ const i = u(t, "id"), n = t.profile || "";
564
+ if (typeof n == "string" && (n.includes("level0") || n.includes("level:0"))) {
565
565
  if ("sizes" in t && Array.isArray(t.sizes)) {
566
566
  const a = t.sizes.sort((o, c) => c.width * c.height - o.width * o.height).filter((o) => o.width * o.height >= e * r)[0];
567
567
  if (a)
@@ -570,49 +570,49 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
570
570
  return `${i}/full/full/0/default.jpg`;
571
571
  }
572
572
  return `${i}/full/!${e},${r}/0/default.jpg`;
573
- }, Rt = (t, e, r) => {
574
- const i = p(t, "id"), s = t.profile || "";
575
- if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) return;
576
- const { x: a, y: o, w: c, h: l } = e, y = c / l, A = y < 1, Z = Math.ceil(A ? r / y : r), ee = Math.ceil(A ? r : r / y), te = `${Math.round(a)},${Math.round(o)},${Math.round(c)},${Math.round(l)}`;
577
- return `${i}/${te}/!${ee},${Z}/0/default.jpg`;
578
- }, Lt = (t) => (e, r = 400) => {
573
+ }, Ot = (t, e, r) => {
574
+ const i = u(t, "id"), n = t.profile || "";
575
+ if (typeof n == "string" && (n.includes("level0") || n.includes("level:0"))) return;
576
+ const { x: a, y: o, w: c, h: v } = e, f = c / v, C = f < 1, S = Math.ceil(C ? r / f : r), l = Math.ceil(C ? r : r / f), y = `${Math.round(a)},${Math.round(o)},${Math.round(c)},${Math.round(v)}`;
577
+ return `${i}/${y}/!${l},${S}/0/default.jpg`;
578
+ }, Pt = (t) => (e, r = 400) => {
579
579
  if (t.type === "dynamic")
580
- return Rt(t.service, e, r);
580
+ return Ot(t.service, e, r);
581
581
  console.error("Level 0 or static image canvas: unspported");
582
- }, wt = (t, e = []) => (r = 400) => {
583
- const { width: i, height: s } = t;
584
- if (!i || !s) return;
585
- const n = i / s, a = n < 1, o = Math.ceil(a ? r / n : r), c = Math.ceil(a ? r : r / n);
582
+ }, Ut = (t, e = []) => (r = 400) => {
583
+ const { width: i, height: n } = t;
584
+ if (!i || !n) return;
585
+ const s = i / n, a = s < 1, o = Math.ceil(a ? r / s : r), c = Math.ceil(a ? r : r / s);
586
586
  if (t.thumbnail && t.thumbnail.length > 0) {
587
- const l = t.thumbnail[0];
588
- if ("service" in l && Array.isArray(l.service)) {
589
- const y = l.service.find((A) => Q(A));
590
- if (y)
591
- return P(y, c, o);
587
+ const v = t.thumbnail[0];
588
+ if ("service" in v && Array.isArray(v.service)) {
589
+ const f = v.service.find((C) => oe(C));
590
+ if (f)
591
+ return F(f, c, o);
592
592
  }
593
- if ("id" in l) return l.id;
593
+ if ("id" in v) return v.id;
594
594
  }
595
- for (const l of e) {
596
- if (l.type === "dynamic" || l.type === "level0")
597
- return P(l.service, c, o);
598
- if (l.type === "static")
599
- return l.url;
595
+ for (const v of e) {
596
+ if (v.type === "dynamic" || v.type === "level0")
597
+ return F(v.service, c, o);
598
+ if (v.type === "static")
599
+ return v.url;
600
600
  }
601
- }, Y = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, It = (t) => {
602
- const { format: e, height: r, width: i } = t, s = p(t, "id"), n = (t.service || []).find(Q), a = n ? X(n) : void 0;
601
+ }, le = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, Dt = (t) => {
602
+ const { format: e, height: r, width: i } = t, n = u(t, "id"), s = (t.service || []).find(oe), a = s ? ce(s) : void 0;
603
603
  if (a) {
604
604
  const o = {
605
605
  source: t,
606
606
  type: a.profileLevel === 0 ? "level0" : "dynamic",
607
- service: n,
607
+ service: s,
608
608
  width: i,
609
609
  height: r,
610
610
  majorVersion: a.majorVersion,
611
- serviceUrl: Y(p(n, "id"))
611
+ serviceUrl: le(u(s, "id"))
612
612
  };
613
613
  return a.profileLevel === 0 ? o : {
614
614
  ...o,
615
- getRegionURL: Lt(o)
615
+ getRegionURL: Pt(o)
616
616
  };
617
617
  } else
618
618
  return {
@@ -620,158 +620,300 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
620
620
  type: "static",
621
621
  width: i,
622
622
  height: r,
623
- url: s,
623
+ url: n,
624
624
  format: e
625
625
  };
626
- }, St = (t) => {
626
+ }, Et = (t) => {
627
627
  const e = [];
628
- return new T({
628
+ return new P({
629
629
  annotation: [(i) => {
630
630
  if (i.motivation === "painting" || !i.motivation) {
631
- const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((a) => a.type === "Image");
632
- e.push(...n.map((a) => It(a)));
631
+ const s = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((a) => a.type === "Image");
632
+ e.push(...s.map((a) => Dt(a)));
633
633
  }
634
634
  }]
635
635
  }).traverseCanvas(t), e;
636
- }, Mt = {
637
- parseURL: async (t) => {
638
- try {
639
- new URL(t);
640
- } catch {
641
- return {
642
- type: "error",
643
- code: "INVALID_URL",
644
- message: "The provided input is not a valid URL"
645
- };
646
- }
647
- let e;
648
- try {
649
- if (e = await fetch(t), !e.ok)
650
- return {
651
- type: "error",
652
- code: "INVALID_HTTP_RESPONSE",
653
- message: `Server responded: HTTP ${e.status} ${e.statusText ? `(${e.statusText})` : ""}`
654
- };
655
- } catch (i) {
656
- return {
657
- type: "error",
658
- code: "FETCH_ERROR",
659
- message: i instanceof Error ? i.message : "Failed to fetch resource"
660
- };
661
- }
662
- const r = e.headers.get("content-type");
663
- if (r != null && r.startsWith("image/"))
664
- return {
665
- type: "plain-image",
666
- url: t
667
- };
668
- if (r != null && r.includes("text/html"))
669
- return {
670
- type: "webpage",
671
- url: t
672
- };
673
- try {
674
- const i = await e.json(), s = Array.isArray(i["@context"]) ? i["@context"].find((a) => a.includes("iiif.io/api/")) : i["@context"];
675
- if (!s)
676
- return {
677
- type: "error",
678
- code: "INVALID_MANIFEST",
679
- message: "Missing @context"
680
- };
681
- if (!p(i, "id"))
682
- return {
683
- type: "error",
684
- code: "INVALID_MANIFEST",
685
- message: "Missing id property"
686
- };
687
- if (s.includes("presentation/2") || s.includes("presentation/3")) {
688
- const a = s.includes("presentation/2") ? 2 : 3;
689
- return p(i, "type").includes("Collection") ? {
690
- type: "collection",
691
- url: t,
692
- resource: Tt(i, a)
693
- } : {
694
- type: "manifest",
695
- url: t,
696
- resource: xt(i, a)
697
- };
698
- }
699
- if (s.includes("image/2") || s.includes("image/3")) {
700
- const a = $t(i);
701
- return a ? {
702
- type: "iiif-image",
703
- url: t,
704
- resource: a
705
- } : {
706
- type: "error",
707
- code: "INVALID_MANIFEST",
708
- message: "Invalid image service definition"
709
- };
710
- }
711
- return {
712
- type: "error",
713
- code: "INVALID_MANIFEST",
714
- message: "JSON resource is not a recognized IIIF format"
715
- };
716
- } catch {
636
+ }, Vt = (t) => () => {
637
+ const e = (i, n, s = 0) => {
638
+ const a = {
639
+ id: i.id,
640
+ type: "range",
641
+ getLabel: i.getLabel,
642
+ children: [],
643
+ parent: n,
644
+ level: s
645
+ };
646
+ return i.items && i.items.length > 0 && i.items.forEach((o) => {
647
+ if (o.source.type === "Range") {
648
+ const c = e(o, a, s + 1);
649
+ a.children.push(c);
650
+ } else
651
+ a.children.push({
652
+ id: o.id,
653
+ type: "canvas",
654
+ getLabel: o.getLabel,
655
+ children: [],
656
+ parent: a,
657
+ level: s + 1
658
+ });
659
+ }), a;
660
+ };
661
+ return t.filter((i) => {
662
+ var n;
663
+ return (n = i.source.behavior) == null ? void 0 : n.includes("top");
664
+ }).map((i) => e(i, void 0));
665
+ }, p = [];
666
+ for (let t = 0; t < 256; ++t)
667
+ p.push((t + 256).toString(16).slice(1));
668
+ function Nt(t, e = 0) {
669
+ return (p[t[e + 0]] + p[t[e + 1]] + p[t[e + 2]] + p[t[e + 3]] + "-" + p[t[e + 4]] + p[t[e + 5]] + "-" + p[t[e + 6]] + p[t[e + 7]] + "-" + p[t[e + 8]] + p[t[e + 9]] + "-" + p[t[e + 10]] + p[t[e + 11]] + p[t[e + 12]] + p[t[e + 13]] + p[t[e + 14]] + p[t[e + 15]]).toLowerCase();
670
+ }
671
+ let $;
672
+ const _t = new Uint8Array(16);
673
+ function qt() {
674
+ if (!$) {
675
+ if (typeof crypto > "u" || !crypto.getRandomValues)
676
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
677
+ $ = crypto.getRandomValues.bind(crypto);
678
+ }
679
+ return $(_t);
680
+ }
681
+ const Ft = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), W = { randomUUID: Ft };
682
+ function Wt(t, e, r) {
683
+ var n;
684
+ if (W.randomUUID && !t)
685
+ return W.randomUUID();
686
+ t = t || {};
687
+ const i = t.random ?? ((n = t.rng) == null ? void 0 : n.call(t)) ?? qt();
688
+ if (i.length < 16)
689
+ throw new Error("Random bytes length must be >= 16");
690
+ return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, Nt(i);
691
+ }
692
+ const H = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), Ht = (t, e) => {
693
+ if (e) {
694
+ const r = t.annotations;
695
+ if (r.length > 0) {
696
+ const i = new RegExp(`${H(t.id)}/${H(e)}/page/p(\\d+)$`), n = r.reduce((s, a) => {
697
+ const o = a.id.match(i);
698
+ if (o && o[1]) {
699
+ const c = parseInt(o[1]);
700
+ return Math.max(s, c);
701
+ } else
702
+ return s;
703
+ }, 1);
704
+ return `${t.id}/${e}/annotations/page/p${n}`;
705
+ } else
706
+ return `${t.id}/${e}/annotations/page/p1`;
707
+ } else
708
+ return `${t.id}/annotations/page/${Wt()}`;
709
+ }, pe = (t, e, r) => {
710
+ const i = {
711
+ id: Ht(t, r),
712
+ type: "AnnotationPage",
713
+ items: e
714
+ };
715
+ return {
716
+ source: {
717
+ ...t.source,
718
+ annotations: [...t.annotations, i]
719
+ },
720
+ id: t.id,
721
+ width: t.width,
722
+ height: t.height,
723
+ images: [...t.images],
724
+ annotations: [...t.annotations, i],
725
+ getLabel: t.getLabel,
726
+ getMetadata: t.getMetadata,
727
+ getThumbnailURL: t.getThumbnailURL
728
+ };
729
+ }, Bt = (t, e, r) => {
730
+ const i = (a) => {
731
+ const o = a.target;
732
+ if (o)
733
+ return typeof o == "string" ? o.substring(0, o.indexOf("#")) : o.source;
734
+ }, n = e.reduce((a, o) => {
735
+ const c = i(o);
736
+ return c && (a[c] || (a[c] = []), a[c].push(o)), a;
737
+ }, {}), s = t.canvases.map((a) => {
738
+ const o = n[a.id] || [];
739
+ return o.length > 0 ? pe(a, o, r) : a;
740
+ });
741
+ return {
742
+ source: {
743
+ ...t.source,
744
+ items: s.map((a) => a.source)
745
+ },
746
+ id: t.id,
747
+ majorVersion: t.majorVersion,
748
+ canvases: s,
749
+ structure: t.structure,
750
+ getLabel: t.getLabel,
751
+ getMetadata: t.getMetadata,
752
+ getTableOfContents: t.getTableOfContents
753
+ };
754
+ }, Jt = (t, e, r) => t.source.type === "Canvas" ? pe(t, e, r) : Bt(t, e, r), zt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
755
+ __proto__: null,
756
+ importAnnotations: Jt
757
+ }, Symbol.toStringTag, { value: "Module" })), Gt = async (t) => {
758
+ try {
759
+ new URL(t);
760
+ } catch {
761
+ return {
762
+ type: "error",
763
+ code: "INVALID_URL",
764
+ message: "The provided input is not a valid URL"
765
+ };
766
+ }
767
+ let e;
768
+ try {
769
+ if (e = await fetch(t), !e.ok)
717
770
  return {
718
771
  type: "error",
719
- code: "UNSUPPORTED_FORMAT",
720
- message: "Could not parse resource"
772
+ code: "INVALID_HTTP_RESPONSE",
773
+ message: `Server responded: HTTP ${e.status} ${e.statusText ? `(${e.statusText})` : ""}`
721
774
  };
722
- }
775
+ } catch (i) {
776
+ return {
777
+ type: "error",
778
+ code: "FETCH_ERROR",
779
+ message: i instanceof Error ? i.message : "Failed to fetch resource"
780
+ };
723
781
  }
724
- }, Tt = (t, e) => {
725
- const r = (n) => {
782
+ const r = e.headers.get("content-type");
783
+ if (r != null && r.startsWith("image/"))
784
+ return {
785
+ type: "plain-image",
786
+ url: t
787
+ };
788
+ if (r != null && r.includes("text/html"))
789
+ return {
790
+ type: "webpage",
791
+ url: t
792
+ };
793
+ try {
794
+ const i = await e.json();
795
+ return ve(i, t);
796
+ } catch {
797
+ return {
798
+ type: "error",
799
+ code: "UNSUPPORTED_FORMAT",
800
+ message: "Could not parse resource"
801
+ };
802
+ }
803
+ }, ve = (t, e) => {
804
+ const r = Array.isArray(t["@context"]) ? t["@context"].find((n) => n.includes("iiif.io/api/")) : t["@context"];
805
+ if (!r)
806
+ return {
807
+ type: "error",
808
+ code: "INVALID_MANIFEST",
809
+ message: "Missing @context"
810
+ };
811
+ const i = u(t, "id");
812
+ if (!i)
813
+ return {
814
+ type: "error",
815
+ code: "INVALID_MANIFEST",
816
+ message: "Missing id property"
817
+ };
818
+ if (r.includes("presentation/2") || r.includes("presentation/3")) {
819
+ const n = r.includes("presentation/2") ? 2 : 3;
820
+ return u(t, "type").includes("Collection") ? {
821
+ type: "collection",
822
+ url: e || i,
823
+ resource: Kt(t, n)
824
+ } : {
825
+ type: "manifest",
826
+ url: e || i,
827
+ resource: Qt(t, n)
828
+ };
829
+ }
830
+ if (r.includes("image/2") || r.includes("image/3")) {
831
+ const n = Xt(t);
832
+ return n ? {
833
+ type: "iiif-image",
834
+ url: e || i,
835
+ resource: n
836
+ } : {
837
+ type: "error",
838
+ code: "INVALID_MANIFEST",
839
+ message: "Invalid image service definition"
840
+ };
841
+ }
842
+ return {
843
+ type: "error",
844
+ code: "INVALID_MANIFEST",
845
+ message: "JSON resource is not a recognized IIIF format"
846
+ };
847
+ }, Kt = (t, e) => {
848
+ const r = (s) => {
726
849
  const a = [];
727
- return new T({
850
+ return new P({
728
851
  manifest: [(c) => a.push(c)]
729
- }).traverseCollection(n), a.map((c) => ({
852
+ }).traverseCollection(s), a.map((c) => ({
730
853
  id: c.id,
731
854
  type: c.type,
732
- getLabel: b(c),
855
+ getLabel: w(c),
733
856
  source: c
734
857
  }));
735
- }, i = e === 2 ? z(t) : t, s = r(i);
858
+ }, i = e === 2 ? se(t) : t, n = r(i);
736
859
  return {
737
860
  source: i,
738
861
  id: i.id,
739
862
  majorVersion: e,
740
- items: s,
741
- getLabel: b(i),
742
- getMetadata: L(i)
863
+ items: n,
864
+ getLabel: w(i),
865
+ getMetadata: M(i)
743
866
  };
744
- }, xt = (t, e) => {
745
- const r = (n) => {
746
- const a = [];
747
- return new T({
748
- canvas: [(c) => {
749
- c.items && a.push(c);
867
+ }, Qt = (t, e) => {
868
+ const r = (a) => {
869
+ const o = [], c = [];
870
+ new P({
871
+ canvas: [(l) => {
872
+ l.items && o.push(l);
873
+ }],
874
+ range: [(l) => {
875
+ l.type === "Range" && c.push(l);
750
876
  }]
751
- }).traverseManifest(n), a.map((c) => {
752
- const l = St(c);
877
+ }).traverseManifest(a);
878
+ const f = o.map((l) => {
879
+ const y = Et(l);
753
880
  return {
754
- source: c,
755
- id: c.id,
756
- width: c.width,
757
- height: c.height,
758
- images: l,
759
- getLabel: b(c),
760
- getMetadata: L(c),
761
- getThumbnailURL: wt(c, l)
881
+ source: l,
882
+ id: l.id,
883
+ width: l.width,
884
+ height: l.height,
885
+ images: y,
886
+ annotations: l.annotations || [],
887
+ getLabel: w(l),
888
+ getMetadata: M(l),
889
+ getThumbnailURL: Ut(l, y)
762
890
  };
763
- });
764
- }, i = e === 2 ? z(t) : t, s = r(i);
891
+ }), C = (l) => {
892
+ const y = l.items || [], U = y.filter((g) => g.type === "Canvas").map((g) => f.find((x) => x.id === g.id)).filter(Boolean), D = y.filter((g) => g.type === "Range").map((g) => C(g)), ue = [...U, ...D];
893
+ return {
894
+ source: l,
895
+ id: l.id,
896
+ // Maintain original order
897
+ items: y.map((g) => ue.find((x) => x.id === g.id)),
898
+ canvases: U,
899
+ ranges: D,
900
+ getLabel: w(l)
901
+ };
902
+ }, S = c.map((l) => C(l));
903
+ return { canvases: f, ranges: S };
904
+ }, i = e === 2 ? se(t) : t, { canvases: n, ranges: s } = r(i);
765
905
  return {
766
906
  source: i,
767
907
  id: i.id,
768
908
  majorVersion: e,
769
- canvases: s,
770
- getLabel: b(i),
771
- getMetadata: L(i)
909
+ canvases: n,
910
+ structure: s,
911
+ getLabel: w(i),
912
+ getMetadata: M(i),
913
+ getTableOfContents: Vt(s)
772
914
  };
773
- }, $t = (t) => {
774
- const { width: e, height: r } = t, i = X(t);
915
+ }, Xt = (t) => {
916
+ const { width: e, height: r } = t, i = ce(t);
775
917
  if (i)
776
918
  return {
777
919
  type: i.profileLevel === 0 ? "level0" : "dynamic",
@@ -779,21 +921,22 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
779
921
  width: e,
780
922
  height: r,
781
923
  majorVersion: i.majorVersion,
782
- serviceUrl: Y(p(t, "id"))
924
+ serviceUrl: le(u(t, "id"))
783
925
  };
784
- };
926
+ }, Zt = { parse: ve, parseURL: Gt, Helpers: zt };
785
927
  export {
786
- Mt as Cozy,
787
- P as getImageURLFromService,
788
- St as getImages,
789
- b as getLabel,
790
- L as getMetadata,
791
- p as getPropertyValue,
792
- Lt as getRegionURL,
793
- Rt as getRegionURLFromService,
794
- Ot as getStringValue,
795
- wt as getThumbnailURL,
796
- Q as isImageService,
797
- Y as normalizeServiceUrl,
798
- X as parseImageService
928
+ Zt as Cozy,
929
+ F as getImageURLFromService,
930
+ Et as getImages,
931
+ w as getLabel,
932
+ M as getMetadata,
933
+ u as getPropertyValue,
934
+ Pt as getRegionURL,
935
+ Ot as getRegionURLFromService,
936
+ rr as getStringValue,
937
+ Vt as getTableOfContents,
938
+ Ut as getThumbnailURL,
939
+ oe as isImageService,
940
+ le as normalizeServiceUrl,
941
+ ce as parseImageService
799
942
  };