cozy-iiif 0.2.3 → 0.2.5
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 +200 -197
- package/dist/level-0/index.js +39 -39
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/core/canvas.ts +0 -1
- package/src/core/image-service.ts +1 -2
- package/src/core/manifest.ts +6 -2
- package/src/level-0/throttled-loader.ts +0 -1
- package/src/types.ts +2 -0
package/dist/index.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
import { g as
|
1
|
+
import { g as m, a as j, b as S } from "./resource-DS2brz47.js";
|
2
2
|
import { c as Ft } from "./resource-DS2brz47.js";
|
3
|
-
var ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", le = "http://library.stanford.edu/iiif/image-api/compliance.html#level1",
|
4
|
-
function
|
3
|
+
var ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", le = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", F = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", pe = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", W = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", he = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", B = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", me = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", H = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", ge = "http://iiif.io/api/image/1/level0.json", de = "http://iiif.io/api/image/1/profiles/level0.json", ye = "http://iiif.io/api/image/1/level1.json", Ae = "http://iiif.io/api/image/1/profiles/level1.json", J = "http://iiif.io/api/image/1/level2.json", G = "http://iiif.io/api/image/1/profiles/level2.json", Ce = "http://iiif.io/api/image/2/level0.json", be = "http://iiif.io/api/image/2/profiles/level0.json", Re = "http://iiif.io/api/image/2/level1.json", Le = "http://iiif.io/api/image/2/profiles/level1.json", z = "http://iiif.io/api/image/2/level2.json", K = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", Q = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", X = "http://iiif.io/api/image/2/level2", xe = [X, F, W, B, H, J, G, z, K, Q], $e = [Se, Te, X, ce, le, F, pe, ve, W, he, ue, B, fe, me, H, ge, de, ye, Ae, J, G, Ce, be, Re, Le, z, K, we, Ie, Q], Me = $e;
|
4
|
+
function g(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
|
8
|
+
function w(t) {
|
9
9
|
return Array.isArray(t) ? t : t ? [t] : [];
|
10
10
|
}
|
11
|
-
var je = Object.defineProperty, ke = (t, e, r) => e in t ? je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r,
|
11
|
+
var je = Object.defineProperty, ke = (t, e, r) => e in t ? je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, b = (t, e, r) => (ke(t, typeof e != "symbol" ? e + "" : e, r), r), D = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
|
12
12
|
function Pe(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");
|
@@ -21,12 +21,12 @@ function Pe(t) {
|
|
21
21
|
if (t.format || t["@type"]) return "ContentResource";
|
22
22
|
throw new Error("Resource type is not known");
|
23
23
|
}
|
24
|
-
var Oe = class
|
24
|
+
var Oe = class Y {
|
25
25
|
constructor(e, r = {}) {
|
26
|
-
|
26
|
+
b(this, "traversals"), b(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
|
29
|
+
return new Y({ 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);
|
@@ -152,7 +152,7 @@ var Oe = class X {
|
|
152
152
|
return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
|
153
153
|
}, e);
|
154
154
|
}
|
155
|
-
},
|
155
|
+
}, Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", De = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Ne = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", qe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", _e = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ve = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", Fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", We = "http://iiif.io/api/image/1/level1.json", Be = "http://iiif.io/api/image/1/profiles/level1.json", He = "http://iiif.io/api/image/1/level2.json", Je = "http://iiif.io/api/image/1/profiles/level2.json", Ge = "http://iiif.io/api/image/2/level1.json", ze = "http://iiif.io/api/image/2/profiles/level1.json", Ke = "http://iiif.io/api/image/2/level2.json", Qe = "http://iiif.io/api/image/2/profiles/level2.json", Xe = "level1", Ye = "level2", Ze = "http://iiif.io/api/image/2/level1", et = "http://iiif.io/api/image/2/level2", tt = [Ze, et, Ue, De, Ne, Ee, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe, Ye], k = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
|
156
156
|
function rt(t) {
|
157
157
|
if (typeof t == "string") return [t];
|
158
158
|
if (!t) return [];
|
@@ -166,7 +166,7 @@ function rt(t) {
|
|
166
166
|
}
|
167
167
|
return r;
|
168
168
|
}
|
169
|
-
function
|
169
|
+
function I(t, e = "none") {
|
170
170
|
if (!t) return { none: [""] };
|
171
171
|
let r = rt(t), i = {};
|
172
172
|
for (let s of r) {
|
@@ -183,8 +183,8 @@ function L(t, e = "none") {
|
|
183
183
|
}
|
184
184
|
return Object.keys(i).length === 0 ? { none: [""] } : i;
|
185
185
|
}
|
186
|
-
function
|
187
|
-
if (Array.isArray(t)) return
|
186
|
+
function Z(t) {
|
187
|
+
if (Array.isArray(t)) return Z(t.find((e) => typeof e == "string"));
|
188
188
|
if (xe.indexOf(t) !== -1) return "level2";
|
189
189
|
if (tt.indexOf(t) !== -1) return "level1";
|
190
190
|
if (Me.indexOf(t) !== -1) return "level0";
|
@@ -232,12 +232,12 @@ function st(t) {
|
|
232
232
|
return "AutoCompleteService1";
|
233
233
|
}
|
234
234
|
}
|
235
|
-
function
|
235
|
+
function N(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
239
|
var nt = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
|
240
|
-
function
|
240
|
+
function O(t) {
|
241
241
|
let e = t["@id"] || t.id, r = t["@type"] || t.type, i = t.profile || void 0, s = t["@context"] || void 0;
|
242
242
|
if (i) {
|
243
243
|
let n = st(i);
|
@@ -281,13 +281,13 @@ function ot(t) {
|
|
281
281
|
}
|
282
282
|
function ct(t, e = "Rights/License", r = "none") {
|
283
283
|
let i = null, s = [], n = Array.isArray(t) ? t : [t];
|
284
|
-
for (let
|
285
|
-
let
|
286
|
-
if (
|
287
|
-
|
284
|
+
for (let o of n) {
|
285
|
+
let c = o ? ot(o) : void 0;
|
286
|
+
if (c && (c.indexOf("creativecommons.org") !== -1 || c.indexOf("rightsstatements.org") !== -1)) {
|
287
|
+
c.startsWith("https://") ? i = `http://${c.slice(8)}` : i = c;
|
288
288
|
continue;
|
289
289
|
}
|
290
|
-
|
290
|
+
c && s.push({ label: { [r]: [e] }, value: { [r]: [c] } });
|
291
291
|
}
|
292
292
|
return [i, s];
|
293
293
|
}
|
@@ -300,22 +300,22 @@ function pt(t) {
|
|
300
300
|
}
|
301
301
|
}
|
302
302
|
function vt(t) {
|
303
|
-
return t ? t.map((e) => ({ label:
|
303
|
+
return t ? t.map((e) => ({ label: I(e.label), value: I(e.value) })) : [];
|
304
304
|
}
|
305
305
|
var E = 0;
|
306
|
-
function
|
306
|
+
function ee(t, e) {
|
307
307
|
let r = encodeURI(t.id || t["@id"] || "").trim();
|
308
308
|
return r && e ? `${r}/${e}` : r || (E++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${E}`);
|
309
309
|
}
|
310
|
-
function
|
310
|
+
function A(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(
|
314
|
+
return Array.isArray(t.motivation) ? r = t.motivation.map(N) : t.motivation && (r = N(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || ee(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
|
316
|
+
function C(t) {
|
317
317
|
let [e, r] = ct(t.license), i = [...t.metadata ? vt(t.metadata) : [], ...r];
|
318
|
-
return { rights: e, metadata: i.length ? i : void 0, label: t.label ?
|
318
|
+
return { rights: e, metadata: i.length ? i : void 0, label: t.label ? I(t.label) : void 0, requiredStatement: t.attribution ? { label: I(k.attributionLabel), value: I(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? I(t.description) : void 0, thumbnail: ht(t.thumbnail) };
|
319
319
|
}
|
320
320
|
function ht(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));
|
@@ -329,24 +329,24 @@ function ut(t) {
|
|
329
329
|
r.push({ id: i, type: "Collection" });
|
330
330
|
break;
|
331
331
|
}
|
332
|
-
} else i["@id"] && r.push({ id: i["@id"], type:
|
332
|
+
} else i["@id"] && r.push({ id: i["@id"], type: O(i) });
|
333
333
|
return r.length ? r : void 0;
|
334
334
|
}
|
335
|
-
function
|
335
|
+
function R(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:
|
337
|
+
return { provider: t.logo || e.length ? [{ id: k.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: I(k.providerName) }] : void 0, partOf: ut(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? w(t.service) : void 0, supplementary: r ? [r] : void 0 };
|
338
338
|
}
|
339
339
|
function ft(t) {
|
340
340
|
return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
|
341
341
|
}
|
342
342
|
function mt(t) {
|
343
|
-
return
|
343
|
+
return g({ ...A(t), ...C(t), ...R(t), items: t.members });
|
344
344
|
}
|
345
345
|
function gt(t) {
|
346
|
-
let e = [], r = [], i
|
347
|
-
for (let
|
348
|
-
let
|
349
|
-
return r.length && (
|
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 = A(t);
|
349
|
+
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), g({ ...s, ...C(t), ...R(t), start: i, items: e, structures: dt(t.structures) });
|
350
350
|
}
|
351
351
|
function dt(t) {
|
352
352
|
if (!t) return t;
|
@@ -360,13 +360,13 @@ function dt(t) {
|
|
360
360
|
return t.filter((i) => r.indexOf(i.id) === -1);
|
361
361
|
}
|
362
362
|
function yt(t) {
|
363
|
-
return
|
363
|
+
return g({ ...A(t), ...C(t), ...R(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: ee(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
|
364
364
|
}
|
365
365
|
function At(t) {
|
366
|
-
return
|
366
|
+
return g({ ...A(t), ...C(t), ...R(t), items: t.resources && t.resources.length ? t.resources : void 0 });
|
367
367
|
}
|
368
368
|
function Ct(t) {
|
369
|
-
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [],
|
369
|
+
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
|
370
370
|
}
|
371
371
|
function bt(t) {
|
372
372
|
function e(r) {
|
@@ -381,50 +381,50 @@ function bt(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:
|
384
|
+
return { type: "SpecificResource", source: i, selector: P(r.selector) };
|
385
385
|
} else return encodeURI(r["@id"]).trim();
|
386
386
|
}
|
387
|
-
return
|
387
|
+
return g({ ...A(t), ...C(t), ...R(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(q) : q(t.resource) });
|
388
388
|
}
|
389
|
-
function
|
390
|
-
return t.type === "Choice" ? t :
|
389
|
+
function q(t) {
|
390
|
+
return t.type === "Choice" ? t : te(t);
|
391
391
|
}
|
392
|
-
function
|
392
|
+
function te(t) {
|
393
393
|
let e = t;
|
394
|
-
return
|
394
|
+
return g({ ...A(e), ...C(e), ...R(e), ...ft(e) });
|
395
395
|
}
|
396
396
|
function Rt(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),
|
398
|
+
return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), g({ ...A(t), ...C(t), items: e });
|
399
399
|
}
|
400
400
|
function Lt(t) {
|
401
|
-
return
|
401
|
+
return g({ ...A(t), ...C(t), ...R(t), items: t.members });
|
402
402
|
}
|
403
403
|
function wt(t) {
|
404
|
-
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t,
|
405
|
-
return e && (
|
404
|
+
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, o = {};
|
405
|
+
return e && (o["@id"] = e), o["@type"] = O(t), o["@type"] === "unknown" && (i && i.length && (o["@context"] = i), o["@type"] = "Service"), s && (o.profile = Z(s)), g({ ...o, ...n });
|
406
406
|
}
|
407
407
|
function It(t) {
|
408
|
-
return
|
408
|
+
return g({ ...A(t), ...C(t), ...R(t) });
|
409
409
|
}
|
410
|
-
var St = new Oe({ collection: [mt], manifest: [gt], canvas: [yt], annotationList: [At], sequence: [Ct], annotation: [bt], contentResource: [
|
411
|
-
function
|
410
|
+
var St = new Oe({ collection: [mt], manifest: [gt], canvas: [yt], annotationList: [At], sequence: [Ct], annotation: [bt], contentResource: [te], choice: [Rt], range: [Lt], service: [wt], layer: [It] });
|
411
|
+
function re(t) {
|
412
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" ? St.traverseUnknown(t) : t;
|
413
413
|
}
|
414
|
-
function
|
414
|
+
function P(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 [
|
417
|
+
if (t["@type"] === "oa:Choice") return [P(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(P)];
|
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
|
421
|
+
function M(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
424
|
function T(...t) {
|
425
425
|
return (e) => t.reduce((r, i) => i(r), e);
|
426
426
|
}
|
427
|
-
var
|
427
|
+
var _ = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
|
428
428
|
function Tt(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");
|
@@ -433,24 +433,24 @@ function Tt(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 =
|
437
|
-
if (r !== -1) return
|
436
|
+
let r = _.indexOf(t.type);
|
437
|
+
if (r !== -1) return _[r];
|
438
438
|
}
|
439
439
|
if (t.profile) return "Service";
|
440
440
|
throw new Error("Resource type is not known");
|
441
441
|
}
|
442
|
-
var
|
442
|
+
var U = class ie {
|
443
443
|
constructor(e, r = {}) {
|
444
|
-
|
444
|
+
b(this, "traversals"), b(this, "options"), b(this, "_traverseManifest", T(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), b(this, "_traverseCanvas", T(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), b(this, "_traverseAnnotationPage", T(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), b(this, "_traverseRange", T(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
|
447
|
+
return new ie({ 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 =
|
450
|
+
return e.thumbnail && (e.thumbnail = w(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 =
|
453
|
+
return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service = w(e.service).map((r) => this.traverseService(r))), e.services && (e.services = w(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 = w(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 && (M(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 O = class re {
|
|
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 =
|
501
|
+
return typeof e == "string" || !e || e && e.service && (e.service = w(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))),
|
504
|
+
return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))), M(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
507
|
let s = e.source;
|
508
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);
|
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) :
|
511
|
+
return e.items && (e.items = e.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, e) : M(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);
|
@@ -518,13 +518,13 @@ var O = class re {
|
|
518
518
|
}
|
519
519
|
traverseType(e, r, i) {
|
520
520
|
return i.reduce((s, n) => {
|
521
|
-
let
|
522
|
-
return typeof
|
521
|
+
let o = n(s, r);
|
522
|
+
return typeof o > "u" && !this.options.allowUndefinedReturn ? s : o;
|
523
523
|
}, e);
|
524
524
|
}
|
525
525
|
traverseService(e, r) {
|
526
526
|
let i = Object.assign({}, e);
|
527
|
-
return i && i.service && (i.service =
|
527
|
+
return i && i.service && (i.service = w(i.service).map((s) => this.traverseService(s))), this.traverseType(i, { parent: r }, this.traversals.service);
|
528
528
|
}
|
529
529
|
traverseUnknown(e, { parent: r, typeHint: i } = {}) {
|
530
530
|
let s = Tt(e, i);
|
@@ -552,67 +552,67 @@ var O = class re {
|
|
552
552
|
}
|
553
553
|
}
|
554
554
|
};
|
555
|
-
const
|
556
|
-
const e =
|
555
|
+
const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ne = (t) => {
|
556
|
+
const e = m(t, "type"), r = m(t, "context");
|
557
557
|
if (e === "ImageService2" || r != null && r.includes("image/2")) {
|
558
558
|
const i = t, s = ["level0", "level1", "level2"];
|
559
|
-
return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((
|
559
|
+
return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((c) => s.findIndex((a) => c.toString().includes(a))).filter((c) => c > -1).sort((c, a) => a - c)[0] };
|
560
560
|
} else if (e || r)
|
561
561
|
return { majorVersion: 3, profileLevel: parseInt(t.profile) };
|
562
|
-
},
|
563
|
-
const i =
|
562
|
+
}, V = (t, e, r) => {
|
563
|
+
const i = m(t, "id"), s = t.profile || "";
|
564
564
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
|
565
565
|
if ("sizes" in t && Array.isArray(t.sizes)) {
|
566
|
-
const
|
567
|
-
if (
|
568
|
-
return `${i}/full/${
|
566
|
+
const o = t.sizes.sort((c, a) => a.width * a.height - c.width * c.height).filter((c) => c.width * c.height >= e * r)[0];
|
567
|
+
if (o)
|
568
|
+
return `${i}/full/${o.width},${o.height}/0/default.jpg`;
|
569
569
|
}
|
570
570
|
return `${i}/full/full/0/default.jpg`;
|
571
571
|
}
|
572
572
|
return `${i}/full/!${e},${r}/0/default.jpg`;
|
573
573
|
}, xt = (t, e, r) => {
|
574
|
-
const i =
|
574
|
+
const i = m(t, "id"), s = t.profile || "";
|
575
575
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) return;
|
576
|
-
const { x:
|
577
|
-
return `${i}/${
|
576
|
+
const { x: o, y: c, w: a, h: l } = e, u = a / l, v = u < 1, d = Math.ceil(v ? r / u : r), p = Math.ceil(v ? r : r / u), f = `${Math.round(o)},${Math.round(c)},${Math.round(a)},${Math.round(l)}`;
|
577
|
+
return `${i}/${f}/!${p},${d}/0/default.jpg`;
|
578
578
|
}, $t = (t) => (e, r = 400) => {
|
579
579
|
if (t.type === "dynamic")
|
580
580
|
return xt(t.service, e, r);
|
581
|
-
console.error("Level 0 or static image canvas:
|
581
|
+
console.error("Level 0 or static image canvas: unsupported");
|
582
582
|
}, Mt = (t, e = []) => (r = 400) => {
|
583
583
|
const { width: i, height: s } = t;
|
584
584
|
if (!i || !s) return;
|
585
|
-
const n = i / s,
|
585
|
+
const n = i / s, o = n < 1, c = Math.ceil(o ? r / n : r), a = Math.ceil(o ? r : r / n);
|
586
586
|
if (t.thumbnail && t.thumbnail.length > 0) {
|
587
|
-
const
|
588
|
-
if ("service" in
|
589
|
-
const
|
590
|
-
if (
|
591
|
-
return
|
587
|
+
const l = t.thumbnail[0];
|
588
|
+
if ("service" in l && Array.isArray(l.service)) {
|
589
|
+
const u = l.service.find((v) => se(v));
|
590
|
+
if (u)
|
591
|
+
return V(u, a, c);
|
592
592
|
}
|
593
|
-
if ("id" in
|
594
|
-
}
|
595
|
-
for (const
|
596
|
-
if (
|
597
|
-
return
|
598
|
-
if (
|
599
|
-
return
|
600
|
-
}
|
601
|
-
},
|
602
|
-
const { format: e, height: r, width: i } = t, s =
|
603
|
-
if (
|
604
|
-
const
|
593
|
+
if ("id" in l) return l.id;
|
594
|
+
}
|
595
|
+
for (const l of e) {
|
596
|
+
if (l.type === "dynamic" || l.type === "level0")
|
597
|
+
return V(l.service, a, c);
|
598
|
+
if (l.type === "static")
|
599
|
+
return l.url;
|
600
|
+
}
|
601
|
+
}, ae = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, jt = (t) => {
|
602
|
+
const { format: e, height: r, width: i } = t, s = m(t, "id"), n = (t.service || []).find(se), o = n ? ne(n) : void 0;
|
603
|
+
if (o) {
|
604
|
+
const c = {
|
605
605
|
source: t,
|
606
|
-
type:
|
606
|
+
type: o.profileLevel === 0 ? "level0" : "dynamic",
|
607
607
|
service: n,
|
608
608
|
width: i,
|
609
609
|
height: r,
|
610
|
-
majorVersion:
|
611
|
-
serviceUrl:
|
610
|
+
majorVersion: o.majorVersion,
|
611
|
+
serviceUrl: ae(m(n, "id"))
|
612
612
|
};
|
613
|
-
return
|
614
|
-
...
|
615
|
-
getRegionURL: $t(
|
613
|
+
return o.profileLevel === 0 ? c : {
|
614
|
+
...c,
|
615
|
+
getRegionURL: $t(c)
|
616
616
|
};
|
617
617
|
} else
|
618
618
|
return {
|
@@ -625,58 +625,61 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
625
625
|
};
|
626
626
|
}, kt = (t) => {
|
627
627
|
const e = [];
|
628
|
-
return new
|
628
|
+
return new U({
|
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((
|
632
|
-
e.push(...n.map((
|
631
|
+
const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((o) => o.type === "Image");
|
632
|
+
e.push(...n.map((o) => jt(o)));
|
633
633
|
}
|
634
634
|
}]
|
635
635
|
}).traverseCanvas(t), e;
|
636
636
|
}, Pt = (t) => () => {
|
637
|
-
const e = /* @__PURE__ */ new Map(), r = (
|
638
|
-
const
|
639
|
-
id:
|
637
|
+
const e = /* @__PURE__ */ new Map(), r = (a, l, u = 0) => {
|
638
|
+
const v = {
|
639
|
+
id: a.id,
|
640
640
|
type: "range",
|
641
|
-
source:
|
641
|
+
source: a,
|
642
642
|
children: [],
|
643
643
|
navItems: [],
|
644
644
|
navSections: [],
|
645
|
-
parent:
|
646
|
-
level:
|
647
|
-
getLabel:
|
645
|
+
parent: l,
|
646
|
+
level: u,
|
647
|
+
getLabel: a.getLabel
|
648
648
|
};
|
649
|
-
|
650
|
-
if (
|
651
|
-
const
|
652
|
-
|
649
|
+
a.items && a.items.length > 0 && a.items.forEach((h) => {
|
650
|
+
if (h.source.type === "Range") {
|
651
|
+
const x = r(h, v, u + 1);
|
652
|
+
v.children.push(x);
|
653
653
|
} else {
|
654
|
-
const
|
655
|
-
id:
|
654
|
+
const L = {
|
655
|
+
id: h.id,
|
656
656
|
type: "canvas",
|
657
|
-
source:
|
657
|
+
source: h,
|
658
658
|
children: [],
|
659
659
|
navItems: [],
|
660
660
|
navSections: [],
|
661
|
-
parent:
|
662
|
-
level:
|
663
|
-
getLabel:
|
661
|
+
parent: v,
|
662
|
+
level: u + 1,
|
663
|
+
getLabel: h.getLabel
|
664
664
|
};
|
665
|
-
|
665
|
+
v.children.push(L), e.set(L.id, L);
|
666
666
|
}
|
667
667
|
});
|
668
|
-
const
|
669
|
-
return
|
668
|
+
const d = v.children.map((h) => h.type === "canvas" ? h.source : h.children.length === 1 && h.children[0].type === "canvas" ? h.children[0].source : h.source), p = d.filter((h) => h.source.type === "Canvas"), f = d.filter((h) => h.source.type === "Range");
|
669
|
+
return v.navItems.push(...p), v.navSections.push(...f), e.set(v.id, v), v;
|
670
670
|
};
|
671
|
-
return { root: t.filter((
|
672
|
-
var
|
673
|
-
return (
|
674
|
-
}).map((
|
675
|
-
const
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
671
|
+
return { root: t.filter((a) => {
|
672
|
+
var l;
|
673
|
+
return (l = a.source.behavior) == null ? void 0 : l.includes("top");
|
674
|
+
}).map((a) => r(a, void 0)), enumerateNodes: (a) => {
|
675
|
+
const l = Array.from(e.values());
|
676
|
+
return a ? l.filter((u) => u.type === a) : l;
|
677
|
+
}, getBreadcrumbs: (a) => {
|
678
|
+
const l = e.get(a);
|
679
|
+
if (!l) return [];
|
680
|
+
const u = (v, d = []) => v.parent ? u(v.parent, [v, ...d]) : [v, ...d];
|
681
|
+
return u(l);
|
682
|
+
}, getNode: (a) => e.get(a) };
|
680
683
|
}, Ot = async (t) => {
|
681
684
|
try {
|
682
685
|
new URL(t);
|
@@ -715,7 +718,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
715
718
|
};
|
716
719
|
try {
|
717
720
|
const i = await e.json();
|
718
|
-
return
|
721
|
+
return oe(i, t);
|
719
722
|
} catch {
|
720
723
|
return {
|
721
724
|
type: "error",
|
@@ -723,7 +726,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
723
726
|
message: "Could not parse resource"
|
724
727
|
};
|
725
728
|
}
|
726
|
-
},
|
729
|
+
}, oe = (t, e) => {
|
727
730
|
const r = Array.isArray(t["@context"]) ? t["@context"].find((s) => s.includes("iiif.io/api/")) : t["@context"];
|
728
731
|
if (!r)
|
729
732
|
return {
|
@@ -731,7 +734,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
731
734
|
code: "INVALID_MANIFEST",
|
732
735
|
message: "Missing @context"
|
733
736
|
};
|
734
|
-
const i =
|
737
|
+
const i = m(t, "id");
|
735
738
|
if (!i)
|
736
739
|
return {
|
737
740
|
type: "error",
|
@@ -740,18 +743,18 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
740
743
|
};
|
741
744
|
if (r.includes("presentation/2") || r.includes("presentation/3")) {
|
742
745
|
const s = r.includes("presentation/2") ? 2 : 3;
|
743
|
-
return
|
746
|
+
return m(t, "type").includes("Collection") ? {
|
744
747
|
type: "collection",
|
745
748
|
url: e || i,
|
746
|
-
resource:
|
749
|
+
resource: Ut(t, s)
|
747
750
|
} : {
|
748
751
|
type: "manifest",
|
749
752
|
url: e || i,
|
750
|
-
resource:
|
753
|
+
resource: Dt(t, s)
|
751
754
|
};
|
752
755
|
}
|
753
756
|
if (r.includes("image/2") || r.includes("image/3")) {
|
754
|
-
const s =
|
757
|
+
const s = Nt(t);
|
755
758
|
return s ? {
|
756
759
|
type: "iiif-image",
|
757
760
|
url: e || i,
|
@@ -767,76 +770,76 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
767
770
|
code: "INVALID_MANIFEST",
|
768
771
|
message: "JSON resource is not a recognized IIIF format"
|
769
772
|
};
|
770
|
-
},
|
773
|
+
}, Ut = (t, e) => {
|
771
774
|
const r = (n) => {
|
772
|
-
const
|
773
|
-
return new
|
774
|
-
manifest: [(
|
775
|
-
}).traverseCollection(n),
|
776
|
-
id:
|
777
|
-
type:
|
778
|
-
getLabel:
|
779
|
-
source:
|
775
|
+
const o = [];
|
776
|
+
return new U({
|
777
|
+
manifest: [(a) => o.push(a)]
|
778
|
+
}).traverseCollection(n), o.map((a) => ({
|
779
|
+
id: a.id,
|
780
|
+
type: a.type,
|
781
|
+
getLabel: S(a),
|
782
|
+
source: a
|
780
783
|
}));
|
781
|
-
}, i = e === 2 ?
|
784
|
+
}, i = e === 2 ? re(t) : t, s = r(i);
|
782
785
|
return {
|
783
786
|
source: i,
|
784
787
|
id: i.id,
|
785
788
|
majorVersion: e,
|
786
789
|
items: s,
|
787
|
-
getLabel:
|
788
|
-
getMetadata:
|
790
|
+
getLabel: S(i),
|
791
|
+
getMetadata: j(i)
|
789
792
|
};
|
790
|
-
},
|
791
|
-
const r = (
|
792
|
-
const
|
793
|
-
new
|
794
|
-
canvas: [(
|
795
|
-
|
793
|
+
}, Dt = (t, e) => {
|
794
|
+
const r = (o) => {
|
795
|
+
const c = [], a = [];
|
796
|
+
new U({
|
797
|
+
canvas: [(p) => {
|
798
|
+
p.items && c.push(p);
|
796
799
|
}],
|
797
|
-
range: [(
|
798
|
-
|
800
|
+
range: [(p) => {
|
801
|
+
p.type === "Range" && a.push(p);
|
799
802
|
}]
|
800
|
-
}).traverseManifest(
|
801
|
-
const
|
802
|
-
const
|
803
|
+
}).traverseManifest(o);
|
804
|
+
const u = c.map((p) => {
|
805
|
+
const f = kt(p);
|
803
806
|
return {
|
804
|
-
source:
|
805
|
-
id:
|
806
|
-
width:
|
807
|
-
height:
|
808
|
-
images:
|
809
|
-
annotations:
|
810
|
-
getLabel:
|
811
|
-
getMetadata:
|
812
|
-
getThumbnailURL: Mt(
|
807
|
+
source: p,
|
808
|
+
id: p.id,
|
809
|
+
width: p.width,
|
810
|
+
height: p.height,
|
811
|
+
images: f,
|
812
|
+
annotations: p.annotations || [],
|
813
|
+
getLabel: S(p),
|
814
|
+
getMetadata: j(p),
|
815
|
+
getThumbnailURL: Mt(p, f)
|
813
816
|
};
|
814
|
-
}),
|
815
|
-
const
|
817
|
+
}), v = (p) => {
|
818
|
+
const f = p.items || [], h = f.filter((y) => y.type === "Canvas").map((y) => u.find(($) => $.id === y.id)).filter(Boolean), L = f.filter((y) => y.type === "Range").map((y) => v(y)), x = [...h, ...L];
|
816
819
|
return {
|
817
|
-
source:
|
818
|
-
id:
|
820
|
+
source: p,
|
821
|
+
id: p.id,
|
819
822
|
// Maintain original order
|
820
|
-
items:
|
821
|
-
canvases:
|
822
|
-
ranges:
|
823
|
-
getLabel:
|
823
|
+
items: f.map((y) => x.find(($) => $.id === y.id)),
|
824
|
+
canvases: h,
|
825
|
+
ranges: L,
|
826
|
+
getLabel: S(p)
|
824
827
|
};
|
825
|
-
},
|
826
|
-
return { canvases:
|
827
|
-
}, i = e === 2 ?
|
828
|
+
}, d = a.map((p) => v(p));
|
829
|
+
return { canvases: u, ranges: d };
|
830
|
+
}, i = e === 2 ? re(t) : t, { canvases: s, ranges: n } = r(i);
|
828
831
|
return {
|
829
832
|
source: i,
|
830
833
|
id: i.id,
|
831
834
|
majorVersion: e,
|
832
835
|
canvases: s,
|
833
836
|
structure: n,
|
834
|
-
getLabel:
|
835
|
-
getMetadata:
|
837
|
+
getLabel: S(i),
|
838
|
+
getMetadata: j(i),
|
836
839
|
getTableOfContents: Pt(n)
|
837
840
|
};
|
838
|
-
},
|
839
|
-
const { width: e, height: r } = t, i =
|
841
|
+
}, Nt = (t) => {
|
842
|
+
const { width: e, height: r } = t, i = ne(t);
|
840
843
|
if (i)
|
841
844
|
return {
|
842
845
|
type: i.profileLevel === 0 ? "level0" : "dynamic",
|
@@ -844,22 +847,22 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
844
847
|
width: e,
|
845
848
|
height: r,
|
846
849
|
majorVersion: i.majorVersion,
|
847
|
-
serviceUrl:
|
850
|
+
serviceUrl: ae(m(t, "id"))
|
848
851
|
};
|
849
|
-
}, qt = { parse:
|
852
|
+
}, qt = { parse: oe, parseURL: Ot };
|
850
853
|
export {
|
851
854
|
qt as Cozy,
|
852
|
-
|
855
|
+
V as getImageURLFromService,
|
853
856
|
kt as getImages,
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
+
S as getLabel,
|
858
|
+
j as getMetadata,
|
859
|
+
m as getPropertyValue,
|
857
860
|
$t as getRegionURL,
|
858
861
|
xt as getRegionURLFromService,
|
859
862
|
Ft as getStringValue,
|
860
863
|
Pt as getTableOfContents,
|
861
864
|
Mt as getThumbnailURL,
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
+
se as isImageService,
|
866
|
+
ae as normalizeServiceUrl,
|
867
|
+
ne as parseImageService
|
865
868
|
};
|
package/dist/level-0/index.js
CHANGED
@@ -2,12 +2,12 @@ import { g as $ } from "../resource-DS2brz47.js";
|
|
2
2
|
const F = (t) => ({ id: $(t, "id"), ...t }), T = (t) => fetch(t.serviceUrl).then((e) => e.json()).then(F), P = new FinalizationRegistry(({ signal: t, aborted: e }) => {
|
3
3
|
t == null || t.removeEventListener("abort", e);
|
4
4
|
});
|
5
|
-
function M({ limit: t, interval: e, strict: c, signal: i, onDelay:
|
5
|
+
function M({ limit: t, interval: e, strict: c, signal: i, onDelay: r }) {
|
6
6
|
if (!Number.isFinite(t))
|
7
7
|
throw new TypeError("Expected `limit` to be a finite number");
|
8
8
|
if (!Number.isFinite(e))
|
9
9
|
throw new TypeError("Expected `interval` to be a finite number");
|
10
|
-
const
|
10
|
+
const n = /* @__PURE__ */ new Map();
|
11
11
|
let o = 0, a = 0;
|
12
12
|
function l() {
|
13
13
|
const h = Date.now();
|
@@ -29,18 +29,18 @@ function M({ limit: t, interval: e, strict: c, signal: i, onDelay: n }) {
|
|
29
29
|
let f;
|
30
30
|
return new Promise((v, C) => {
|
31
31
|
const y = () => {
|
32
|
-
v(h.apply(this, u)),
|
32
|
+
v(h.apply(this, u)), n.delete(f);
|
33
33
|
}, p = g();
|
34
|
-
p > 0 ? (f = setTimeout(y, p),
|
34
|
+
p > 0 ? (f = setTimeout(y, p), n.set(f, C), r == null || r(...u)) : y();
|
35
35
|
});
|
36
36
|
}, m = () => {
|
37
|
-
for (const u of
|
38
|
-
clearTimeout(u),
|
39
|
-
|
37
|
+
for (const u of n.keys())
|
38
|
+
clearTimeout(u), n.get(u)(i.reason);
|
39
|
+
n.clear(), s.splice(0, s.length);
|
40
40
|
};
|
41
41
|
return P.register(w, { signal: i, aborted: m }), i == null || i.throwIfAborted(), i == null || i.addEventListener("abort", m, { once: !0 }), w.isEnabled = !0, Object.defineProperty(w, "queueSize", {
|
42
42
|
get() {
|
43
|
-
return
|
43
|
+
return n.size;
|
44
44
|
}
|
45
45
|
}), w;
|
46
46
|
};
|
@@ -53,14 +53,14 @@ const H = () => {
|
|
53
53
|
return {
|
54
54
|
getInstance: () => e,
|
55
55
|
getConfig: () => ({ ...t }),
|
56
|
-
setConfig: (
|
57
|
-
t = { ...t, ...
|
56
|
+
setConfig: (n) => {
|
57
|
+
t = { ...t, ...n }, e = M(t);
|
58
58
|
}
|
59
59
|
};
|
60
60
|
}, x = H(), W = (t) => {
|
61
61
|
if (!t) return;
|
62
62
|
const e = x.getConfig();
|
63
|
-
(t.limit && t.limit !== e.limit || t.interval && t.interval !== e.interval) &&
|
63
|
+
(t.limit && t.limit !== e.limit || t.interval && t.interval !== e.interval) && x.setConfig({ ...e, ...t });
|
64
64
|
}, E = (t) => {
|
65
65
|
if (t) {
|
66
66
|
const i = {
|
@@ -69,20 +69,20 @@ const H = () => {
|
|
69
69
|
};
|
70
70
|
W(i);
|
71
71
|
}
|
72
|
-
return { loadImage: x.getInstance()((i) => new Promise((
|
72
|
+
return { loadImage: x.getInstance()((i) => new Promise((r, n) => {
|
73
73
|
const o = new Image();
|
74
|
-
o.crossOrigin = "anonymous", o.onload = () =>
|
74
|
+
o.crossOrigin = "anonymous", o.onload = () => r(o), o.onerror = n, o.src = i;
|
75
75
|
})) };
|
76
76
|
}, j = (t, e) => {
|
77
|
-
const { x: c, y: i, w:
|
78
|
-
return `${t.id}/${c * o},${i * a},${
|
77
|
+
const { x: c, y: i, w: r, h: n } = e, o = t.tiles[0].width, a = t.tiles[0].height || t.tiles[0].width;
|
78
|
+
return `${t.id}/${c * o},${i * a},${r},${n}/${o},/0/default.jpg`;
|
79
79
|
}, R = (t, e) => {
|
80
|
-
const c = t.tiles[0].width, i = t.tiles[0].height || t.tiles[0].width,
|
80
|
+
const c = t.tiles[0].width, i = t.tiles[0].height || t.tiles[0].width, r = t.width, n = t.height, o = Math.floor(e.x / c), a = Math.floor(e.y / i), l = Math.ceil((e.x + e.w) / c), s = Math.ceil((e.y + e.h) / i), d = [];
|
81
81
|
for (let g = a; g < s; g++)
|
82
82
|
for (let h = o; h < l; h++) {
|
83
|
-
if (h * c >=
|
83
|
+
if (h * c >= r || g * i >= n)
|
84
84
|
continue;
|
85
|
-
const w = Math.min(c,
|
85
|
+
const w = Math.min(c, r - h * c), m = Math.min(i, n - g * i);
|
86
86
|
d.push({
|
87
87
|
x: h,
|
88
88
|
y: g,
|
@@ -93,15 +93,15 @@ const H = () => {
|
|
93
93
|
}
|
94
94
|
return d;
|
95
95
|
}, L = async (t, e) => {
|
96
|
-
const c = await T(t), i = R(c, e),
|
97
|
-
if (!
|
96
|
+
const c = await T(t), i = R(c, e), r = document.createElement("canvas"), n = r.getContext("2d");
|
97
|
+
if (!n)
|
98
98
|
throw new Error("Error initializing canvas context");
|
99
99
|
const o = c.tiles[0].width, a = c.tiles[0].height || c.tiles[0].width, l = (Math.ceil(e.w / o) + 1) * o, s = (Math.ceil(e.h / a) + 1) * a;
|
100
|
-
|
100
|
+
r.width = l, r.height = s;
|
101
101
|
const d = E({ callsPerSecond: 20 });
|
102
102
|
await Promise.all(i.map(async (w) => {
|
103
103
|
const m = await d.loadImage(w.url), u = w.x * o - e.x, f = w.y * a - e.y;
|
104
|
-
|
104
|
+
n.drawImage(m, u, f);
|
105
105
|
}));
|
106
106
|
const g = document.createElement("canvas");
|
107
107
|
g.width = e.w, g.height = e.h;
|
@@ -109,7 +109,7 @@ const H = () => {
|
|
109
109
|
if (!h)
|
110
110
|
throw new Error("Error initializing canvas context");
|
111
111
|
return h.drawImage(
|
112
|
-
|
112
|
+
r,
|
113
113
|
0,
|
114
114
|
0,
|
115
115
|
e.w,
|
@@ -131,43 +131,43 @@ const H = () => {
|
|
131
131
|
const c = t.tiles[0].scaleFactors.sort((o, a) => a - o);
|
132
132
|
if (!e)
|
133
133
|
return c[0];
|
134
|
-
const i = e.width ? t.width / e.width : 1 / 0,
|
134
|
+
const i = e.width ? t.width / e.width : 1 / 0, r = e.height ? t.height / e.height : 1 / 0, n = Math.min(i, r);
|
135
135
|
for (const o of c)
|
136
|
-
if (o <=
|
136
|
+
if (o <= n)
|
137
137
|
return o;
|
138
138
|
return c[c.length - 1];
|
139
139
|
}, b = (t, e) => {
|
140
140
|
const c = I(t, e);
|
141
|
-
let i = Math.ceil(t.width / c),
|
141
|
+
let i = Math.ceil(t.width / c), r = Math.ceil(t.height / c);
|
142
142
|
if (e) {
|
143
|
-
const
|
144
|
-
e.width && i < e.width && (i = e.width,
|
143
|
+
const n = t.width / t.height;
|
144
|
+
e.width && i < e.width && (i = e.width, r = Math.ceil(i / n)), e.height && r < e.height && (r = e.height, i = Math.ceil(r * n));
|
145
145
|
}
|
146
|
-
return { width: i, height:
|
146
|
+
return { width: i, height: r };
|
147
147
|
}, k = (t, e) => {
|
148
|
-
const c = I(t, e), i = t.tiles[0].width,
|
148
|
+
const c = I(t, e), i = t.tiles[0].width, r = t.tiles[0].height || t.tiles[0].width, n = Math.ceil(t.width / (i * c)), o = Math.ceil(t.height / (r * c)), a = [];
|
149
149
|
for (let l = 0; l < o; l++)
|
150
|
-
for (let s = 0; s <
|
150
|
+
for (let s = 0; s < n; s++) {
|
151
151
|
const d = Math.min(
|
152
152
|
i,
|
153
153
|
(t.width - s * i * c) / c
|
154
154
|
), g = Math.min(
|
155
|
-
|
156
|
-
(t.height - l *
|
155
|
+
r,
|
156
|
+
(t.height - l * r * c) / c
|
157
157
|
);
|
158
158
|
d <= 0 || g <= 0 || a.push({
|
159
|
-
url: `${t.id}/${s * i * c},${l *
|
159
|
+
url: `${t.id}/${s * i * c},${l * r * c},${d * c},${g * c}/${Math.ceil(d)},/0/default.jpg`,
|
160
160
|
width: Math.ceil(d),
|
161
161
|
height: Math.ceil(g),
|
162
162
|
x: s * i,
|
163
|
-
y: l *
|
163
|
+
y: l * r
|
164
164
|
});
|
165
165
|
}
|
166
166
|
return a;
|
167
167
|
}, O = async (t, e) => {
|
168
|
-
const c = await T(t), i = k(c, e),
|
169
|
-
|
170
|
-
const o =
|
168
|
+
const c = await T(t), i = k(c, e), r = b(c, e), n = document.createElement("canvas");
|
169
|
+
n.width = r.width, n.height = r.height;
|
170
|
+
const o = n.getContext("2d");
|
171
171
|
if (!o)
|
172
172
|
throw new Error("Error creating canvas context");
|
173
173
|
const a = E();
|
@@ -175,7 +175,7 @@ const H = () => {
|
|
175
175
|
const s = await a.loadImage(l.url);
|
176
176
|
o.drawImage(s, l.x, l.y);
|
177
177
|
})), new Promise((l, s) => {
|
178
|
-
|
178
|
+
n.toBlob((d) => {
|
179
179
|
d ? l(d) : s(new Error("Failed to create blob"));
|
180
180
|
}, "image/jpeg", 0.85);
|
181
181
|
});
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "cozy-iiif",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.5",
|
4
4
|
"description": "A developer-friendly collection of abstractions and utilities built on top of @iiif/presentation-3 and @iiif/parser",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "Rainer Simon",
|
@@ -33,7 +33,7 @@
|
|
33
33
|
"vitest": "^3.1.4"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@iiif/parser": "
|
36
|
+
"@iiif/parser": "2.1.7",
|
37
37
|
"@iiif/presentation-3": "^2.2.3",
|
38
38
|
"p-throttle": "^7.0.0",
|
39
39
|
"uuid": "^11.1.0"
|
package/src/core/canvas.ts
CHANGED
@@ -37,7 +37,6 @@ export const getThumbnailURL = (canvas: Canvas, images: CozyImageResource[] = []
|
|
37
37
|
if (image.type === 'dynamic' || image.type === 'level0') {
|
38
38
|
return getImageURLFromService(image.service, w, h);
|
39
39
|
} else if (image.type === 'static') {
|
40
|
-
// console.warn('Static image canvas');
|
41
40
|
return image.url;
|
42
41
|
}
|
43
42
|
}
|
@@ -100,7 +100,6 @@ export const getRegionURL = (
|
|
100
100
|
if (image.type === 'dynamic') {
|
101
101
|
return getRegionURLFromService(image.service, bounds, minSize);
|
102
102
|
} else {
|
103
|
-
|
104
|
-
console.error('Level 0 or static image canvas: unspported');
|
103
|
+
console.error('Level 0 or static image canvas: unsupported');
|
105
104
|
}
|
106
105
|
}
|
package/src/core/manifest.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import type { CozyCanvas, CozyRange, CozyTOC, CozyTOCNode } from '../types';
|
2
2
|
|
3
3
|
export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
|
4
|
-
|
5
4
|
const index = new Map<string, CozyTOCNode>();
|
6
5
|
|
7
6
|
const buildTree = (range: CozyRange, parent: CozyTOCNode | undefined, level: number = 0): CozyTOCNode => {
|
@@ -90,5 +89,10 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
|
|
90
89
|
return addParent(thisNode);
|
91
90
|
}
|
92
91
|
|
93
|
-
|
92
|
+
const enumerateNodes = (type?: 'range' | 'canvas'): CozyTOCNode[] => {
|
93
|
+
const all = Array.from(index.values());
|
94
|
+
return type ? all.filter(n => n.type === type) : all;
|
95
|
+
}
|
96
|
+
|
97
|
+
return { root, enumerateNodes, getBreadcrumbs, getNode };
|
94
98
|
}
|
@@ -53,7 +53,6 @@ const updateThrottleConfig = (opts?: Partial<ThrottleConfig>) => {
|
|
53
53
|
(opts.limit && opts.limit !== current.limit) ||
|
54
54
|
(opts.interval && opts.interval !== current.interval)
|
55
55
|
) {
|
56
|
-
console.log('updating throttle config!');
|
57
56
|
throttleManager.setConfig({ ...current, ...opts });
|
58
57
|
}
|
59
58
|
}
|
package/src/types.ts
CHANGED