Socket
Socket
Sign inDemoInstall

@iiif/vault-helpers

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iiif/vault-helpers - npm Package Compare versions

Comparing version 0.9.11 to 0.10.0

.build/types/compat.d.ts

10

.build/types/annotation-targets/parse-selector.d.ts
import { ParsedSelector, SvgShapeType } from './selector-types';
import { Selector } from '@iiif/presentation-3';
export declare function parseSelector(source: Selector | Selector[], { domParser, svgPreprocessor }?: {
import { ImageApiSelector, Selector } from '@iiif/presentation-3';
export declare function parseSelector(source: Selector | Selector[], { domParser, svgPreprocessor, iiifRenderingHints, }?: {
domParser?: DOMParser;
svgPreprocessor?: (svg: string) => string;
iiifRenderingHints?: ImageApiSelector;
}): ParsedSelector;

@@ -12,1 +13,6 @@ export declare type SelectorElement = {

};
export declare function isImageApiSelector(t: unknown): t is ImageApiSelector;
/**
* Parse rotation "90", "180", "!90"
*/
export declare function parseRotation(input: string): number;

13

.build/types/annotation-targets/selector-types.d.ts

@@ -0,1 +1,2 @@

import { ImageApiSelector } from '@iiif/presentation-3';
export declare type SvgShapeType = 'rect' | 'circle' | 'ellipse' | 'line' | 'polyline' | 'polygon' | 'path';

@@ -15,2 +16,3 @@ export interface SupportedSelector {

};
rotation?: number;
points?: [number, number][];

@@ -38,2 +40,3 @@ svg?: string;

};
rotation?: number;
}

@@ -46,2 +49,3 @@ export interface PointSelector extends SupportedSelector {

};
rotation?: number;
}

@@ -60,2 +64,3 @@ export interface SvgSelector extends SupportedSelector {

};
rotation?: number;
}

@@ -69,2 +74,6 @@ export interface TemporalSelector extends SupportedSelector {

}
export interface RotationSelector extends SupportedSelector {
type: 'RotationSelector';
rotation: number;
}
export interface TemporalBoxSelector extends SupportedSelector {

@@ -79,2 +88,3 @@ type: 'TemporalBoxSelector';

};
rotation?: number;
temporal: {

@@ -85,6 +95,7 @@ startTime: number;

}
export declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector | PointSelector | SvgSelector;
export declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector | PointSelector | SvgSelector | RotationSelector;
export declare type ParsedSelector = {
selector: SupportedSelectors | null;
selectors: SupportedSelectors[];
iiifRenderingHints?: ImageApiSelector;
};

@@ -14,4 +14,10 @@ import { ExternalWebResource } from '@iiif/presentation-3';

purpose?: string;
imageServiceHints?: {
size?: string;
rotation?: string;
quality?: string;
format?: string;
};
selector: SupportedSelectors | null;
selectors: SupportedSelectors[];
};
import type { Reference } from '@iiif/presentation-3';
import type { Vault } from '@iiif/vault';
export declare function createEventsHelper(vault: Vault): {
import { CompatVault } from './compat';
export declare function createEventsHelper(vault?: CompatVault): {
addEventListener<T>(resource: Reference<any>, event: string, listener: (e: any, resource: T) => void, scope?: string[]): ((e: any, resource: T) => void) | undefined;

@@ -5,0 +5,0 @@ removeEventListener<T_1>(resource: Reference<any>, event: string, listener: (e: any, resource: T_1) => void): void;

@@ -1,5 +0,5 @@

import { Vault } from '@iiif/vault';
import { AnnotationNormalized, CanvasNormalized } from '@iiif/presentation-3';
import { Paintables } from './types';
export declare function createPaintingAnnotationsHelper(vault: Vault): {
import { CompatVault } from '../compat';
export declare function createPaintingAnnotationsHelper(vault?: CompatVault): {
getAllPaintingAnnotations: (canvasOrId: string | CanvasNormalized | undefined | null) => AnnotationNormalized[];

@@ -6,0 +6,0 @@ getPaintables: (paintingAnnotationsOrCanvas: string | CanvasNormalized | AnnotationNormalized[], enabledChoices?: string[]) => Paintables;

@@ -1,4 +0,4 @@

import { Vault } from '@iiif/vault';
import { ManifestNormalized, RangeNormalized, Reference } from '@iiif/presentation-3';
export declare function createRangeHelper(vault: Vault): {
import { CompatVault } from './compat';
export declare function createRangeHelper(vault?: CompatVault): {
findFirstCanvasFromRange: (range: RangeNormalized) => Reference<"Canvas"> | null;

@@ -9,5 +9,5 @@ findAllCanvasesInRange: (range: RangeNormalized) => Reference<"Canvas">[];

};
export declare function findFirstCanvasFromRange(vault: Vault, range: RangeNormalized): null | Reference<'Canvas'>;
export declare function findAllCanvasesInRange(vault: Vault, range: RangeNormalized): Array<Reference<'Canvas'>>;
export declare function findManifestSelectedRange(vault: Vault, manifest: ManifestNormalized, canvasId: string): null | RangeNormalized;
export declare function findSelectedRange(vault: Vault, range: RangeNormalized, canvasId: string): null | RangeNormalized;
export declare function findFirstCanvasFromRange(vault: CompatVault, range: RangeNormalized): null | Reference<'Canvas'>;
export declare function findAllCanvasesInRange(vault: CompatVault, range: RangeNormalized): Array<Reference<'Canvas'>>;
export declare function findManifestSelectedRange(vault: CompatVault, manifest: ManifestNormalized, canvasId: string): null | RangeNormalized;
export declare function findSelectedRange(vault: CompatVault, range: RangeNormalized, canvasId: string): null | RangeNormalized;
import { ManifestNormalized, RangeNormalized, Reference } from '@iiif/presentation-3';
import { Vault } from '@iiif/vault';
export declare function createSequenceHelper(vault: Vault): {
import { CompatVault } from './compat';
export declare function createSequenceHelper(vault?: CompatVault): {
getVisibleCanvasesFromCanvasId: (manifestOrRange: ManifestNormalized | RangeNormalized, canvasId: string | null, preventPaged?: boolean) => Reference<"Canvas">[];

@@ -41,6 +41,6 @@ getManifestSequence: (manifestOrRange: ManifestNormalized | RangeNormalized, options?: {

*/
export declare function getVisibleCanvasesFromCanvasId(vault: Vault, manifestOrRange: ManifestNormalized | RangeNormalized, canvasId: string | null, preventPaged?: boolean): Reference<'Canvas'>[];
export declare function getManifestSequence(vault: Vault, manifestOrRange: ManifestNormalized | RangeNormalized, { disablePaging, skipNonPaged }?: {
export declare function getVisibleCanvasesFromCanvasId(vault: CompatVault | undefined, manifestOrRange: ManifestNormalized | RangeNormalized, canvasId: string | null, preventPaged?: boolean): Reference<'Canvas'>[];
export declare function getManifestSequence(vault: CompatVault | undefined, manifestOrRange: ManifestNormalized | RangeNormalized, { disablePaging, skipNonPaged }?: {
disablePaging?: boolean;
skipNonPaged?: boolean;
}): [Reference<'Canvas'>[], number[][]];

@@ -1,2 +0,2 @@

import type { Vault } from '@iiif/vault';
import { CompatVault } from './compat';
export declare type StyleDefinition = Record<string, any>;

@@ -7,2 +7,2 @@ export declare type StyledHelper<S extends StyleDefinition> = {

};
export declare function createStylesHelper<S extends StyleDefinition>(vault: Vault): StyledHelper<S>;
export declare function createStylesHelper<S extends StyleDefinition>(vault?: CompatVault): StyledHelper<S>;
import { AnnotationNormalized, AnnotationPageNormalized, CanvasNormalized, CollectionItemSchemas, CollectionNormalized, ContentResource, ManifestNormalized, Reference } from '@iiif/presentation-3';
import { Vault } from '@iiif/vault';
import { FixedSizeImage, FixedSizeImageService, ImageCandidate, ImageCandidateRequest, ImageServiceLoader, UnknownSizeImage, VariableSizeImage } from '@atlas-viewer/iiif-image-api';
export declare function createThumbnailHelper(vault: Vault, dependencies?: {
import { CompatVault } from './compat';
export declare function createThumbnailHelper(vault?: CompatVault, dependencies?: {
imageServiceLoader?: ImageServiceLoader;
}): {
getBestThumbnailAtSize: (input: string | Reference<CollectionItemSchemas> | Reference<'Collection'> | Reference<'Manifest'> | Reference<'Canvas'> | Reference<'Annotation'> | Reference<'AnnotationPage'> | Reference<'ContentResource'> | CollectionNormalized | ManifestNormalized | CanvasNormalized | AnnotationNormalized | AnnotationPageNormalized | ContentResource, request: ImageCandidateRequest, dereference?: boolean, candidates?: Array<ImageCandidate>, dimensions?: {
getBestThumbnailAtSize: (input: string | Reference<CollectionItemSchemas> | Reference<'Collection'> | Reference<'Manifest'> | Reference<'Canvas'> | Reference<'Annotation'> | Reference<'AnnotationPage'> | Reference<'ContentResource'> | CollectionNormalized | ManifestNormalized | CanvasNormalized | AnnotationNormalized | AnnotationPageNormalized | ContentResource | undefined, request: ImageCandidateRequest, dereference?: boolean, candidates?: Array<ImageCandidate>, dimensions?: {
width: number;

@@ -9,0 +9,0 @@ height: number;

@@ -1,2 +0,2 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var J=function(){function e(t,a){var r=[],i=!0,s=!1,n=void 0;try{for(var o=t[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(r.push(u.value),!(a&&r.length===a));i=!0);}catch(h){s=!0,n=h}finally{try{!i&&o.return&&o.return()}finally{if(s)throw n}}return r}return function(t,a){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,a);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),C=Math.PI*2,_=function(t,a,r,i,s,n,o){var u=t.x,h=t.y;u*=a,h*=r;var y=i*u-s*h,f=s*u+i*h;return{x:y+n,y:f+o}},K=function(t,a){var r=a===1.5707963267948966?.551915024494:a===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(a/4),i=Math.cos(t),s=Math.sin(t),n=Math.cos(t+a),o=Math.sin(t+a);return[{x:i-s*r,y:s+i*r},{x:n+o*r,y:o-n*r},{x:n,y:o}]},D=function(t,a,r,i){var s=t*i-a*r<0?-1:1,n=t*r+a*i;return n>1&&(n=1),n<-1&&(n=-1),s*Math.acos(n)},E=function(t,a,r,i,s,n,o,u,h,y,f,d){var v=Math.pow(s,2),c=Math.pow(n,2),w=Math.pow(f,2),b=Math.pow(d,2),M=v*c-v*b-c*w;M<0&&(M=0),M/=v*b+c*w,M=Math.sqrt(M)*(o===u?-1:1);var l=M*s/n*d,p=M*-n/s*f,x=y*l-h*p+(t+r)/2,m=h*l+y*p+(a+i)/2,A=(f-l)/s,g=(d-p)/n,k=(-f-l)/s,S=(-d-p)/n,T=D(1,0,A,g),F=D(A,g,k,S);return u===0&&F>0&&(F-=C),u===1&&F<0&&(F+=C),[x,m,T,F]},tt=function(t){var a=t.px,r=t.py,i=t.cx,s=t.cy,n=t.rx,o=t.ry,u=t.xAxisRotation,h=u===void 0?0:u,y=t.largeArcFlag,f=y===void 0?0:y,d=t.sweepFlag,v=d===void 0?0:d,c=[];if(n===0||o===0)return[];var w=Math.sin(h*C/360),b=Math.cos(h*C/360),M=b*(a-i)/2+w*(r-s)/2,l=-w*(a-i)/2+b*(r-s)/2;if(M===0&&l===0)return[];n=Math.abs(n),o=Math.abs(o);var p=Math.pow(M,2)/Math.pow(n,2)+Math.pow(l,2)/Math.pow(o,2);p>1&&(n*=Math.sqrt(p),o*=Math.sqrt(p));var x=E(a,r,i,s,n,o,f,v,w,b,M,l),m=J(x,4),A=m[0],g=m[1],k=m[2],S=m[3],T=Math.abs(S)/(C/4);Math.abs(1-T)<1e-7&&(T=1);var F=Math.max(Math.ceil(T),1);S/=F;for(var Q=0;Q<F;Q++)c.push(K(k,S)),k+=S;return c.map(function(R){var V=_(R[0],n,o,b,w,A,g),G=V.x,W=V.y,I=_(R[1],n,o,b,w,A,g),Y=I.x,H=I.y,X=_(R[2],n,o,b,w,A,g),Z=X.x,P=X.y;return{x1:G,y1:W,x2:Y,y2:H,x:Z,y:P}})},et=st,B={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},rt=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function st(e){var t=[];return e.replace(rt,function(a,r,i){var s=r.toLowerCase();for(i=nt(i),s=="m"&&i.length>2&&(t.push([r].concat(i.splice(0,2))),s="l",r=r=="m"?"l":"L");;){if(i.length==B[s])return i.unshift(r),t.push(i);if(i.length<B[s])throw new Error("malformed path data");t.push([r].concat(i.splice(0,B[s])))}}),t}var at=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function nt(e){var t=e.match(at);return t?t.map(Number):[]}var it=ot;function ot(e){var t=0,a=0,r=0,i=0;return e.map(function(s){s=s.slice();var n=s[0],o=n.toUpperCase();if(n!=o)switch(s[0]=o,n){case"a":s[6]+=r,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=r;break;default:for(var u=1;u<s.length;)s[u++]+=r,s[u++]+=i}switch(o){case"Z":r=t,i=a;break;case"H":r=s[1];break;case"V":i=s[1];break;case"M":r=t=s[1],i=a=s[2];break;default:r=s[s.length-2],i=s[s.length-1]}return s})}function ct(e){const t=et(e),a=it(t);let r,i=0,s=0,n=0,o=0,u,h,y=0,f=0;const d=[];for(let v=0;v<a.length;v++){let c=a[v];const w=c[0];switch(w){case"M":i=c[1],s=c[2];break;case"H":c=["L",c[1],s];break;case"V":c=["L",i,c[1]];break;case"S":{let b=y,M=f;(r==="C"||r=="S")&&(b+=b-n,M+=M-o),c=["C",b,M,c[1],c[2],c[3],c[4]]}break;case"T":r==="Q"||r=="T"?(u=y*2-u,h=f*2-h):(u=y,h=f),c=["Q",u,h,c[1],c[2]];break;case"Q":u=c[1],h=c[2];break;case"A":{const b=tt({px:y,py:f,cx:c[6],cy:c[7],rx:c[1],ry:c[2],xAxisRotation:c[3],largeArcFlag:c[4],sweepFlag:c[5]});if(!b.length)continue;for(const[M,l]of b.entries())c=["C",l.x1,l.y1,l.x2,l.y2,l.x,l.y],M<b.length-1&&d.push(c);c=c}break;case"Z":c=["L",i,s];break}r=w,y=c[c.length-2],f=c[c.length-1],["C","Q","A"].indexOf(w)>-1?(n=c[c.length-4],o=c[c.length-3]):(n=y,o=f),d.push(c)}return d}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var tt=function(){function e(t,a){var r=[],o=!0,n=!1,s=void 0;try{for(var i=t[Symbol.iterator](),u;!(o=(u=i.next()).done)&&(r.push(u.value),!(a&&r.length===a));o=!0);}catch(h){n=!0,s=h}finally{try{!o&&i.return&&i.return()}finally{if(n)throw s}}return r}return function(t,a){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,a);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),L=Math.PI*2,I=function(t,a,r,o,n,s,i){var u=t.x,h=t.y;u*=a,h*=r;var y=o*u-n*h,f=n*u+o*h;return{x:y+s,y:f+i}},et=function(t,a){var r=a===1.5707963267948966?.551915024494:a===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(a/4),o=Math.cos(t),n=Math.sin(t),s=Math.cos(t+a),i=Math.sin(t+a);return[{x:o-n*r,y:n+o*r},{x:s+i*r,y:i-s*r},{x:s,y:i}]},D=function(t,a,r,o){var n=t*o-a*r<0?-1:1,s=t*r+a*o;return s>1&&(s=1),s<-1&&(s=-1),n*Math.acos(s)},rt=function(t,a,r,o,n,s,i,u,h,y,f,M){var x=Math.pow(n,2),c=Math.pow(s,2),g=Math.pow(f,2),b=Math.pow(M,2),d=x*c-x*b-c*g;d<0&&(d=0),d/=x*b+c*g,d=Math.sqrt(d)*(i===u?-1:1);var l=d*n/s*M,p=d*-s/n*f,v=y*l-h*p+(t+r)/2,m=h*l+y*p+(a+o)/2,A=(f-l)/n,w=(M-p)/s,S=(-f-l)/n,k=(-M-p)/s,O=D(1,0,A,w),T=D(A,w,S,k);return u===0&&T>0&&(T-=L),u===1&&T<0&&(T+=L),[v,m,O,T]},at=function(t){var a=t.px,r=t.py,o=t.cx,n=t.cy,s=t.rx,i=t.ry,u=t.xAxisRotation,h=u===void 0?0:u,y=t.largeArcFlag,f=y===void 0?0:y,M=t.sweepFlag,x=M===void 0?0:M,c=[];if(s===0||i===0)return[];var g=Math.sin(h*L/360),b=Math.cos(h*L/360),d=b*(a-o)/2+g*(r-n)/2,l=-g*(a-o)/2+b*(r-n)/2;if(d===0&&l===0)return[];s=Math.abs(s),i=Math.abs(i);var p=Math.pow(d,2)/Math.pow(s,2)+Math.pow(l,2)/Math.pow(i,2);p>1&&(s*=Math.sqrt(p),i*=Math.sqrt(p));var v=rt(a,r,o,n,s,i,f,x,g,b,d,l),m=tt(v,4),A=m[0],w=m[1],S=m[2],k=m[3],O=Math.abs(k)/(L/4);Math.abs(1-O)<1e-7&&(O=1);var T=Math.max(Math.ceil(O),1);k/=T;for(var Q=0;Q<T;Q++)c.push(et(S,k)),S+=k;return c.map(function(_){var V=I(_[0],s,i,b,g,A,w),Z=V.x,J=V.y,X=I(_[1],s,i,b,g,A,w),K=X.x,H=X.y,j=I(_[2],s,i,b,g,A,w),P=j.x,E=j.y;return{x1:Z,y1:J,x2:K,y2:H,x:P,y:E}})},st=ot,B={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},nt=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ot(e){var t=[];return e.replace(nt,function(a,r,o){var n=r.toLowerCase();for(o=ct(o),n=="m"&&o.length>2&&(t.push([r].concat(o.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(o.length==B[n])return o.unshift(r),t.push(o);if(o.length<B[n])throw new Error("malformed path data");t.push([r].concat(o.splice(0,B[n])))}}),t}var it=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ct(e){var t=e.match(it);return t?t.map(Number):[]}var lt=ut;function ut(e){var t=0,a=0,r=0,o=0;return e.map(function(n){n=n.slice();var s=n[0],i=s.toUpperCase();if(s!=i)switch(n[0]=i,s){case"a":n[6]+=r,n[7]+=o;break;case"v":n[1]+=o;break;case"h":n[1]+=r;break;default:for(var u=1;u<n.length;)n[u++]+=r,n[u++]+=o}switch(i){case"Z":r=t,o=a;break;case"H":r=n[1];break;case"V":o=n[1];break;case"M":r=t=n[1],o=a=n[2];break;default:r=n[n.length-2],o=n[n.length-1]}return n})}function pt(e){const t=st(e),a=lt(t);let r,o=0,n=0,s=0,i=0,u,h,y=0,f=0;const M=[];for(let x=0;x<a.length;x++){let c=a[x];const g=c[0];switch(g){case"M":o=c[1],n=c[2];break;case"H":c=["L",c[1],n];break;case"V":c=["L",o,c[1]];break;case"S":{let b=y,d=f;(r==="C"||r=="S")&&(b+=b-s,d+=d-i),c=["C",b,d,c[1],c[2],c[3],c[4]]}break;case"T":r==="Q"||r=="T"?(u=y*2-u,h=f*2-h):(u=y,h=f),c=["Q",u,h,c[1],c[2]];break;case"Q":u=c[1],h=c[2];break;case"A":{const b=at({px:y,py:f,cx:c[6],cy:c[7],rx:c[1],ry:c[2],xAxisRotation:c[3],largeArcFlag:c[4],sweepFlag:c[5]});if(!b.length)continue;for(const[d,l]of b.entries())c=["C",l.x1,l.y1,l.x2,l.y2,l.x,l.y],d<b.length-1&&M.push(c);c=c}break;case"Z":c=["L",o,n];break}r=g,y=c[c.length-2],f=c[c.length-1],["C","Q","A"].indexOf(g)>-1?(s=c[c.length-4],i=c[c.length-3]):(s=y,i=f),M.push(c)}return M}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
*

@@ -31,3 +31,3 @@ * All code in this module is based on JavaScript code by Raph Levien, published on his blog at

* limitations under the License.
*/function lt(e,t,a,r=1){return new U(e,t,a).subdivide(r)}function ut(e,t,a,r,i=1){return new $(new Float64Array([e.x,e.y,t.x,t.y,a.x,a.y,r.x,r.y])).subdivide(i)}function pt(e){return e.x*e.x+e.y*e.y}function L(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function O(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class U{constructor(t,a,r){this.start=t,this.control=a,this.end=r}eval(t){const a=1-t;return{x:this.start.x*a*a+2*this.control.x*a*t+this.end.x*t*t,y:this.start.y*a*a+2*this.control.y*a*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:a}=this.start,{x:r,y:i}=this.control,{x:s,y:n}=this.end,o=2*r-t-s,u=2*i-a-n,h=(r-t)*o+(i-a)*u,y=(s-r)*o+(n-i)*u,f=(s-t)*u-(n-a)*o,d=h/f,v=y/f,c=Math.abs(f)/(Math.hypot(o,u)*Math.abs(v-d));return{x0:t,x2:s,scale:c,cross:f}}subdivide(t){const a=this.mapToBasic(),r=L(a.x0),i=L(a.x2),s=.5*Math.abs(i-r)*Math.sqrt(a.scale/t),n=Math.ceil(s),o=O(r),u=O(i),h=[0];for(let y=1;y<n;y++){const d=(O(r+(i-r)*y/n)-o)/(u-o);h.push(d)}return h.push(1),h.map(y=>this.eval(y))}}class ${constructor(t){this.c=t}weightsum(t,a,r,i){const s=t*this.c[0]+a*this.c[2]+r*this.c[4]+i*this.c[6],n=t*this.c[1]+a*this.c[3]+r*this.c[5]+i*this.c[7];return{x:s,y:n}}eval(t){const a=1-t,r=a*a*a,i=3*a*a*t,s=3*a*t*t,n=t*t*t;return this.weightsum(r,i,s,n)}deriv(t){const a=1-t,r=-3*a*a,i=3*t*t,s=-6*t*a-r,n=6*t*a-i;return this.weightsum(r,s,n,i)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new U({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,a){const r=new Float64Array(8),i=this.eval(t),s=this.eval(a);r[0]=i.x,r[1]=i.y;const n=(a-t)/3,o=this.deriv(t);r[2]=i.x+n*o.x,r[3]=i.y+n*o.y;const u=this.deriv(a);return r[4]=s.x-n*u.x,r[5]=s.y-n*u.y,r[6]=s.x,r[7]=s.y,new $(r)}subdivide(t){const a=.1*t,r=t-a,i=Math.sqrt(r),s=pt(this.weightsum(1,-3,3,-1)),n=Math.ceil(Math.pow(s/(432*a*a),1/6)),o=[];let u=0;for(let c=0;c<n;c++){const w=c/n,b=(c+1)/n,M=this.subsegment(w,b).midpoint_quadbez(),l=M.mapToBasic(),p=L(l.x0),x=L(l.x2),m=Math.sqrt(l.scale);let A=Math.abs(x-p)*m;if(Math.sign(l.x0)!=Math.sign(l.x2)){const g=i/m,k=i*Math.abs(x-p)/L(g);A=Math.max(A,k)}o.push({quad:M,a0:p,a2:x,val:A}),u+=A}const h=.5*u/i,y=Math.ceil(h),f=[{x:this.c[0],y:this.c[1]}];let d=0,v=0;for(let c=1;c<y;c++){const w=u*c/y;for(;d+o[v].val<w;)d+=o[v].val,v++;const b=o[v].a0,M=o[v].a2,l=O(b),p=O(M),x=b+(M-b)*(w-d)/o[v].val,A=(O(x)-l)/(p-l);f.push(o[v].quad.eval(A))}return f.push({x:this.c[6],y:this.c[7]}),f}}const ht=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,yt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,N=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function z(e,{domParser:t,svgPreprocessor:a}={}){var r,i;if(Array.isArray(e))return e.reduce((s,n)=>{const{selector:o,selectors:u}=z(n);return o&&(s.selector||(s.selector=o),s.selectors.push(...u)),s},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[s,n]=e.split("#");return n?z({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const s={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:s,selectors:[s]}}if(e.type==="FragmentSelector"){const s=ht.exec(e.value);if(s){const o={type:"BoxSelector",spatial:{unit:s[2]==="percent:"||s[2]==="pct:"?"percent":"pixel",x:parseFloat(s[3]),y:parseFloat(s[4]),width:parseFloat(s[5]),height:parseFloat(s[6])}};return{selector:o,selectors:[o]}}const n=e.value.match(yt);if(n){const o={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:o,selectors:[o]}}return{selector:null,selectors:[]}}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window!="undefined"?t=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let s=[],n,o,u=(r=a==null?void 0:a(e.value))!=null?r:e.value,h;if(t){const f=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!f)return console.warn(`Illegal SVG selector: ${e.value}`),{selector:null,selectors:[]};const d=j(f);d&&(s=d.points,h=d.shapeType,n=[Math.min(...s.map(v=>v[0])),Math.min(...s.map(v=>v[1])),Math.max(...s.map(v=>v[0])),Math.max(...s.map(v=>v[1]))],{style:o,svg:u}=(i=xt(d.element))!=null?i:{svg:u})}const y={type:"SvgSelector",svg:u,svgShape:h,style:o,points:s.length?s:void 0,spatial:n?{unit:"pixel",x:n[0],y:n[1],width:n[2]-n[0],height:n[3]-n[1]}:void 0};return{selector:y,selectors:[y]}}return{selector:null,selectors:[]}}function ft(e){const t=e.map(r=>r[0]).reduce((r,i)=>(r[i]+=1,r),{C:0,Q:0,L:0,M:0}),a=new Set(e.map(r=>r[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(a.size===1||a.size===2&&a.has("M"))){if(t.L===4)return"rect";const r=e.slice(-1)[0];return e[0][0]==="M"&&r[0]==="L"&&r[1]==e[0][1]&&r[2]===e[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function j(e){var t,a,r,i,s,n,o,u,h,y,f,d,v,c,w,b,M;for(const l of Array.from(e.children))switch(l==null?void 0:l.tagName.toLowerCase()){case"g":{const p=j(l);if(p)return p}continue;case"path":{const p=l.getAttribute("d");if(!p)continue;const x=ct(p);return{element:l,points:vt(x),shapeType:ft(x)}}case"circle":{const p=parseFloat((t=l.getAttribute("cx"))!=null?t:"0"),x=parseFloat((a=l.getAttribute("cy"))!=null?a:"0"),m=parseFloat((r=l.getAttribute("r"))!=null?r:"0");if(!m)continue;const A=[];for(let g=0;g<=360;g+=12){const k=g*Math.PI/180;A.push([p+m*Math.cos(k),x+m*Math.sin(k)])}return{element:l,points:A,shapeType:"circle"}}case"ellipse":{const p=parseFloat((i=l.getAttribute("cx"))!=null?i:"0"),x=parseFloat((s=l.getAttribute("cy"))!=null?s:"0"),m=parseFloat((n=l.getAttribute("rx"))!=null?n:"0"),A=parseFloat((o=l.getAttribute("ry"))!=null?o:"0");if(!m&&!A)continue;const g=[];for(let k=0;k<=360;k+=12){const S=Math.tan(k/360*Math.PI),T=m*(1-S**2)/(1+S**2),F=A*2*S/(1+S**2);g.push([p+T,x+F])}return{element:l,points:g,shapeType:"ellipse"}}case"line":{const p=parseFloat((u=l.getAttribute("x0"))!=null?u:"0"),x=parseFloat((h=l.getAttribute("y0"))!=null?h:"0"),m=parseFloat((y=l.getAttribute("x1"))!=null?y:"0"),A=parseFloat((f=l.getAttribute("y1"))!=null?f:"0");if(p===m&&x===A)continue;return{element:l,points:[[p,x],[m,A]],shapeType:"polyline"}}case"polygon":case"polyline":{const p=(v=(d=l.getAttribute("points"))==null?void 0:d.split(" ").map(m=>m.split(",").map(parseFloat)))!=null?v:[];if(!p.length)continue;let x="polyline";return l.tagName.toLowerCase()==="polygon"&&(p.push(p[0]),x="polygon"),{element:l,points:p,shapeType:x}}case"rect":{const p=parseFloat((c=l.getAttribute("x"))!=null?c:"0"),x=parseFloat((w=l.getAttribute("y"))!=null?w:"0"),m=parseFloat((b=l.getAttribute("width"))!=null?b:"0"),A=parseFloat((M=l.getAttribute("height"))!=null?M:"0");if(!m||!A)continue;return{element:l,points:[[p,x],[p+m,x],[p+m,x+A],[p,x+A],[p,x]],shapeType:"rect"}}default:continue}return null}function vt(e){var a;const t=[];for(let r=0;r<e.length;r++){const i=(a=t[t.length-1])!=null?a:[0,0],s=e[r];switch(s[0]){case"M":case"L":t.push([s[1],s[2]]);continue;case"C":t.push(...ut({x:i[0],y:i[1]},{x:s[1],y:s[2]},{x:s[3],y:s[4]},{x:s[5],y:s[6]}).map(n=>[n.x,n.y]).slice(1));continue;case"Q":t.push(...lt({x:i[0],y:i[1]},{x:s[1],y:s[2]},{x:s[3],y:s[4]}).map(n=>[n.x,n.y]).slice(1));continue}}return t}function xt(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const r=N.exec(t.fill);r&&(t.fillOpacity=parseFloat(r[4]),t.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const r=N.exec(t.stroke);r&&(t.strokeOpacity=parseFloat(r[4]),t.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let a=e;for(;a.tagName.toLowerCase()!=="svg";)if(a=a.parentElement,a===null)throw new Error("Could not find root SVG element");return{svg:a.outerHTML,style:Object.keys(t).length>0?t:void 0}}function q(e,t={}){if(Array.isArray(e))return q(e[0]);if(typeof e=="string"){const[a,r]=e.split("#");return r?q({type:"SpecificResource",source:{id:a,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:a,type:t.typeMap&&t.typeMap[a]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return q(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:a,selectors:r}=e.selector?z(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:a,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[a,r]=e.id.split("#");return r?q({type:"SpecificResource",source:{...e,id:a},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...e,id:a},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}exports.expandTarget=q;exports.parseSelector=z;
*/function ht(e,t,a,r=1){return new U(e,t,a).subdivide(r)}function yt(e,t,a,r,o=1){return new $(new Float64Array([e.x,e.y,t.x,t.y,a.x,a.y,r.x,r.y])).subdivide(o)}function ft(e){return e.x*e.x+e.y*e.y}function z(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function q(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class U{constructor(t,a,r){this.start=t,this.control=a,this.end=r}eval(t){const a=1-t;return{x:this.start.x*a*a+2*this.control.x*a*t+this.end.x*t*t,y:this.start.y*a*a+2*this.control.y*a*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:a}=this.start,{x:r,y:o}=this.control,{x:n,y:s}=this.end,i=2*r-t-n,u=2*o-a-s,h=(r-t)*i+(o-a)*u,y=(n-r)*i+(s-o)*u,f=(n-t)*u-(s-a)*i,M=h/f,x=y/f,c=Math.abs(f)/(Math.hypot(i,u)*Math.abs(x-M));return{x0:t,x2:n,scale:c,cross:f}}subdivide(t){const a=this.mapToBasic(),r=z(a.x0),o=z(a.x2),n=.5*Math.abs(o-r)*Math.sqrt(a.scale/t),s=Math.ceil(n),i=q(r),u=q(o),h=[0];for(let y=1;y<s;y++){const M=(q(r+(o-r)*y/s)-i)/(u-i);h.push(M)}return h.push(1),h.map(y=>this.eval(y))}}class ${constructor(t){this.c=t}weightsum(t,a,r,o){const n=t*this.c[0]+a*this.c[2]+r*this.c[4]+o*this.c[6],s=t*this.c[1]+a*this.c[3]+r*this.c[5]+o*this.c[7];return{x:n,y:s}}eval(t){const a=1-t,r=a*a*a,o=3*a*a*t,n=3*a*t*t,s=t*t*t;return this.weightsum(r,o,n,s)}deriv(t){const a=1-t,r=-3*a*a,o=3*t*t,n=-6*t*a-r,s=6*t*a-o;return this.weightsum(r,n,s,o)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new U({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,a){const r=new Float64Array(8),o=this.eval(t),n=this.eval(a);r[0]=o.x,r[1]=o.y;const s=(a-t)/3,i=this.deriv(t);r[2]=o.x+s*i.x,r[3]=o.y+s*i.y;const u=this.deriv(a);return r[4]=n.x-s*u.x,r[5]=n.y-s*u.y,r[6]=n.x,r[7]=n.y,new $(r)}subdivide(t){const a=.1*t,r=t-a,o=Math.sqrt(r),n=ft(this.weightsum(1,-3,3,-1)),s=Math.ceil(Math.pow(n/(432*a*a),1/6)),i=[];let u=0;for(let c=0;c<s;c++){const g=c/s,b=(c+1)/s,d=this.subsegment(g,b).midpoint_quadbez(),l=d.mapToBasic(),p=z(l.x0),v=z(l.x2),m=Math.sqrt(l.scale);let A=Math.abs(v-p)*m;if(Math.sign(l.x0)!=Math.sign(l.x2)){const w=o/m,S=o*Math.abs(v-p)/z(w);A=Math.max(A,S)}i.push({quad:d,a0:p,a2:v,val:A}),u+=A}const h=.5*u/o,y=Math.ceil(h),f=[{x:this.c[0],y:this.c[1]}];let M=0,x=0;for(let c=1;c<y;c++){const g=u*c/y;for(;M+i[x].val<g;)M+=i[x].val,x++;const b=i[x].a0,d=i[x].a2,l=q(b),p=q(d),v=b+(d-b)*(g-M)/i[x].val,A=(q(v)-l)/(p-l);f.push(i[x].quad.eval(A))}return f.push({x:this.c[6],y:this.c[7]}),f}}const vt=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,xt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,N=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function R(e,{domParser:t,svgPreprocessor:a,iiifRenderingHints:r}={}){var o,n;if(Array.isArray(e))return F(e.reduce((s,i)=>{const{selector:u,selectors:h,iiifRenderingHints:y}=R(i,{domParser:t,svgPreprocessor:a,iiifRenderingHints:r});return u&&(s.selector||(s.selector=u),s.selectors.push(...h)),y&&(s.iiifRenderingHints=s.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(s.iiifRenderingHints,y)),s},{selector:null,selectors:[],iiifRenderingHints:r}));if(!e)return F({selector:null,selectors:[],iiifRenderingHints:r});if(typeof e=="string"){const[s,i]=e.split("#");return i?R({type:"FragmentSelector",value:i},{svgPreprocessor:a,iiifRenderingHints:r,domParser:t}):F({selector:null,selectors:[],iiifRenderingHints:r})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const s={type:"TemporalSelector",temporal:{startTime:e.t}};return F({selector:s,selectors:[s],iiifRenderingHints:r})}if(W(e)){const s=[];if(e.region){const i=R({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:a,iiifRenderingHints:r});s.push(...i.selectors)}return F({selector:s[0],selectors:s,iiifRenderingHints:r?{...r,...e}:e})}if(e.type==="FragmentSelector"){const s=vt.exec(e.value);if(s){const u={type:"BoxSelector",spatial:{unit:s[2]==="percent:"||s[2]==="pct:"?"percent":"pixel",x:parseFloat(s[3]),y:parseFloat(s[4]),width:parseFloat(s[5]),height:parseFloat(s[6])}};return F({selector:u,selectors:[u],iiifRenderingHints:r})}const i=e.value.match(xt);if(i){const u={type:"TemporalSelector",temporal:{startTime:i[4]?parseFloat(i[4]):0,endTime:i[7]?parseFloat(i[7]):void 0}};return F({selector:u,selectors:[u],iiifRenderingHints:r})}return F({selector:null,selectors:[],iiifRenderingHints:r})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window!="undefined"?t=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let s=[],i,u,h=(o=a==null?void 0:a(e.value))!=null?o:e.value,y;if(t){const M=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!M)return console.warn(`Illegal SVG selector: ${e.value}`),F({selector:null,selectors:[],iiifRenderingHints:r});const x=G(M);x&&(s=x.points,y=x.shapeType,i=[Math.min(...s.map(c=>c[0])),Math.min(...s.map(c=>c[1])),Math.max(...s.map(c=>c[0])),Math.max(...s.map(c=>c[1]))],{style:u,svg:h}=(n=mt(x.element))!=null?n:{svg:h})}const f={type:"SvgSelector",svg:h,svgShape:y,style:u,points:s.length?s:void 0,spatial:i?{unit:"pixel",x:i[0],y:i[1],width:i[2]-i[0],height:i[3]-i[1]}:void 0};return F({selector:f,selectors:[f],iiifRenderingHints:r})}return F({selector:null,selectors:[],iiifRenderingHints:r})}function bt(e){const t=e.map(r=>r[0]).reduce((r,o)=>(r[o]+=1,r),{C:0,Q:0,L:0,M:0}),a=new Set(e.map(r=>r[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(a.size===1||a.size===2&&a.has("M"))){if(t.L===4)return"rect";const r=e.slice(-1)[0];return e[0][0]==="M"&&r[0]==="L"&&r[1]==e[0][1]&&r[2]===e[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function G(e){var t,a,r,o,n,s,i,u,h,y,f,M,x,c,g,b,d;for(const l of Array.from(e.children))switch(l==null?void 0:l.tagName.toLowerCase()){case"g":{const p=G(l);if(p)return p}continue;case"path":{const p=l.getAttribute("d");if(!p)continue;const v=pt(p);return{element:l,points:dt(v),shapeType:bt(v)}}case"circle":{const p=parseFloat((t=l.getAttribute("cx"))!=null?t:"0"),v=parseFloat((a=l.getAttribute("cy"))!=null?a:"0"),m=parseFloat((r=l.getAttribute("r"))!=null?r:"0");if(!m)continue;const A=[];for(let w=0;w<=360;w+=12){const S=w*Math.PI/180;A.push([p+m*Math.cos(S),v+m*Math.sin(S)])}return{element:l,points:A,shapeType:"circle"}}case"ellipse":{const p=parseFloat((o=l.getAttribute("cx"))!=null?o:"0"),v=parseFloat((n=l.getAttribute("cy"))!=null?n:"0"),m=parseFloat((s=l.getAttribute("rx"))!=null?s:"0"),A=parseFloat((i=l.getAttribute("ry"))!=null?i:"0");if(!m&&!A)continue;const w=[];for(let S=0;S<=360;S+=12){const k=Math.tan(S/360*Math.PI),O=m*(1-k**2)/(1+k**2),T=A*2*k/(1+k**2);w.push([p+O,v+T])}return{element:l,points:w,shapeType:"ellipse"}}case"line":{const p=parseFloat((u=l.getAttribute("x0"))!=null?u:"0"),v=parseFloat((h=l.getAttribute("y0"))!=null?h:"0"),m=parseFloat((y=l.getAttribute("x1"))!=null?y:"0"),A=parseFloat((f=l.getAttribute("y1"))!=null?f:"0");if(p===m&&v===A)continue;return{element:l,points:[[p,v],[m,A]],shapeType:"polyline"}}case"polygon":case"polyline":{const p=(x=(M=l.getAttribute("points"))==null?void 0:M.split(" ").map(m=>m.split(",").map(parseFloat)))!=null?x:[];if(!p.length)continue;let v="polyline";return l.tagName.toLowerCase()==="polygon"&&(p.push(p[0]),v="polygon"),{element:l,points:p,shapeType:v}}case"rect":{const p=parseFloat((c=l.getAttribute("x"))!=null?c:"0"),v=parseFloat((g=l.getAttribute("y"))!=null?g:"0"),m=parseFloat((b=l.getAttribute("width"))!=null?b:"0"),A=parseFloat((d=l.getAttribute("height"))!=null?d:"0");if(!m||!A)continue;return{element:l,points:[[p,v],[p+m,v],[p+m,v+A],[p,v+A],[p,v]],shapeType:"rect"}}default:continue}return null}function dt(e){var a;const t=[];for(let r=0;r<e.length;r++){const o=(a=t[t.length-1])!=null?a:[0,0],n=e[r];switch(n[0]){case"M":case"L":t.push([n[1],n[2]]);continue;case"C":t.push(...yt({x:o[0],y:o[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":t.push(...ht({x:o[0],y:o[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return t}function mt(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const r=N.exec(t.fill);r&&(t.fillOpacity=parseFloat(r[4]),t.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const r=N.exec(t.stroke);r&&(t.strokeOpacity=parseFloat(r[4]),t.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let a=e;for(;a.tagName.toLowerCase()!=="svg";)if(a=a.parentElement,a===null)throw new Error("Could not find root SVG element");return{svg:a.outerHTML,style:Object.keys(t).length>0?t:void 0}}function W(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function F(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const a=Y(t.rotation);if(a)if(e.selectors.length)for(const r of e.selectors)r.rotation=a;else e.selectors.push({type:"RotationSelector",rotation:a})}}else delete e.iiifRenderingHints;return e}function Y(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function C(e,t={}){if(Array.isArray(e))return C(e[0]);if(typeof e=="string"){const[a,r]=e.split("#");return r?C({type:"SpecificResource",source:{id:a,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:a,type:t.typeMap&&t.typeMap[a]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return C(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:a,selectors:r}=e.selector?R(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:a,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[a,r]=e.id.split("#");return r?C({type:"SpecificResource",source:{...e,id:a},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...e,id:a},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}exports.expandTarget=C;exports.isImageApiSelector=W;exports.parseRotation=Y;exports.parseSelector=R;
//# sourceMappingURL=annotation-targets.js.map

@@ -1,3 +0,3 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function ie(t){return{addEventListener(e,i,r,s){if(!!e)return t.setMetaValue([e.id,"eventManager",i],n=>{const o=n||[];for(const a of o)if(a.callback===r)return o;return[...o,{callback:r,scope:s}]}),r},removeEventListener(e,i,r){!e||t.setMetaValue([e.id,"eventManager",i],s=>(s||[]).filter(n=>n.callback!==r))},getListenersAsProps(e,i){const r=typeof e=="string"?{id:e}:e;if(!r||!r.id)return{};const s=t.getResourceMeta(r.id,"eventManager"),n={};if(s&&r)for(const o of Object.keys(s))n[o]=a=>{const c=t.get(r);for(const{callback:l,scope:f}of s[o]||[])(!f||i&&f.indexOf(i)!==-1)&&l(a,c)};return n}}}function re(t){return{applyStyles(e,i,r){const s=typeof e=="string"?e:e.id;return t.setMetaValue([s,"styles",i],r)},getAppliedStyles(e){const i=typeof e=="string"?e:e.id;return t.getResourceMeta(i,"styles")}}}function z(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const ne="http://library.stanford.edu/iiif/image-api/compliance.html#level0",gt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",yt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",se="http://library.stanford.edu/iiif/image-api/conformance.html#level0",mt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",vt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",oe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",xt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",bt="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",wt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",St="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ce="http://iiif.io/api/image/1/level0.json",le="http://iiif.io/api/image/1/profiles/level0.json",At="http://iiif.io/api/image/1/level1.json",Ft="http://iiif.io/api/image/1/profiles/level1.json",Mt="http://iiif.io/api/image/1/level2.json",Ot="http://iiif.io/api/image/1/profiles/level2.json",fe="http://iiif.io/api/image/2/level0.json",ue="http://iiif.io/api/image/2/profiles/level0.json",Ct="http://iiif.io/api/image/2/level1.json",kt="http://iiif.io/api/image/2/profiles/level1.json",Rt="http://iiif.io/api/image/2/level2.json",jt="http://iiif.io/api/image/2/profiles/level2.json",he="level0",It="level1",Tt="level2",pe="http://iiif.io/api/image/2/level0",zt="http://iiif.io/api/image/2/level1",Pt="http://iiif.io/api/image/2/level2",Wt=[Pt,yt,vt,bt,St,Mt,Ot,Rt,jt,Tt],qt=[...Wt,zt,gt,mt,xt,wt,At,Ft,Ct,kt,It],de=[pe,zt,Pt,ne,gt,yt,se,mt,vt,oe,xt,bt,ae,wt,St,ce,le,At,Ft,Mt,Ot,fe,ue,Ct,kt,Rt,jt,he,It,Tt],ge={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},ye={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},me={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function ve(t){return Wt.indexOf(t)!==-1?me:qt.indexOf(t)!==-1?ye:ge}function xe(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=ve(r)),!!r){if(r.formats)for(const s of r.formats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.qualities)for(const s of r.qualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.supports)for(const s of r.supports)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const s of r.extraFormats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.extraQualities)for(const s of r.extraQualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.extraFeatures)for(const s of r.extraFeatures)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(t.extraFormats)for(const r of t.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(t.extraFeatures)for(const r of t.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(t.extraQualities)for(const r of t.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function be(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),i=t.substr(e?4:0).split(",").map(r=>parseFloat(r));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function we(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const i=t.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(e.width=parseInt(i[0],10)),i[1]!==""&&(e.height=parseInt(i[1],10))),e}function Se(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function Ae(t,e=""){const i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);const r=i[2],s=i[3];let n=i[4];if(n[0]==="/"&&(n=n.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==n.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${e})`);n=n.substr(e.length)}return{scheme:r,server:s,path:n,prefix:e}}function Fe(t,e=""){const{path:i,scheme:r,server:s,prefix:n}=Ae(t,e),o=i.split("/").reverse(),[a,c,l,f,...h]=o,g=h.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:r,server:s,prefix:n,identifier:g};if(a==="info.json"){const[,...u]=o;return{type:"info",scheme:r,server:s,prefix:n,identifier:u.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:r,server:s,prefix:n,identifier:g,originalPath:i,region:be(f),size:we(l),rotation:Se(c),quality:p[0],format:p[1]}}function Me(t){const e=Fe(z(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const i=xe(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Oe(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n].width;s.push(t/o)}return s}function Ce(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n];s.push({width:Math.floor(t/o),height:Math.floor(e/o)})}return s}function A(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Z(t){if(!t||!t.profile||!A(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"&&de.indexOf(i)!==-1)return!0;return!1}function ke(t){if(!Z(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(qt.indexOf(i)!==-1)return!0}else{const r=[...i.supports||[],...i.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return!0}return!1}function Re(t){if(!ke(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],r=i.length;for(let s=0;s<r;s++){const n=i[s];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return[{id:A(t),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(t.tiles){const s=t.tiles.length;for(let n=0;n<s;n++){const o=t.tiles[n];(o.height||o.width)&&e.push({id:A(t),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width})}}return e}function ot(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=t.match(e);if(i){const r=i[1],s=parseInt(i[4],10),n=parseInt(i[5],10),o=i[7];if((r==="max"||r==="full")&&s&&n&&o)return{type:"fixed",id:t,height:n,width:s}}return{type:"unknown",id:t}}function je(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function J(t){if(typeof t=="string")return ot(t);const e=je(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,r=A(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:ot(r):null}function Ie(t){return Z(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:A(t),type:"fixed-service",height:e.height,width:e.width})):[]}function at(t){const e=[],i=t.length;for(let r=0;r<i;r++){const s=Ie(t[r]);s.length&&e.push(...s);const n=Re(t[r]);n.length&&e.push(...n)}return e}function Bt(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,r=[];for(let s=0;s<i;s++)Z(e[s])&&r.push(e[s]);return r}function Te(t,e=!0,i){const r=[],s=J(t);if(s===null)return r;const n=t;if(r.push(s),e&&n.width&&n.height){const o=[],a=Bt(n);for(const c of a){const l={id:A(c),width:n.width,height:n.height};if(i.canLoadSync(l)){const f=i.loadServiceSync(l);f&&(f.height||(f.height=n.height),f.width||(f.width=n.width),o.push(...at([f])))}}if(o.length)return r.push(...o),r}return n.service&&r.push(...at(n.service)),r}function ze({x:t=0,y:e=0,w:i,h:r,full:s,square:n,percent:o}){if(s)return"full";if(n)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const a=`${t},${e},${i},${r}`;return o?`pct:${a}`:a}function Pe({max:t,percentScale:e,upscaled:i,confined:r,width:s,height:n,serialiseAsFull:o}){const a=[];return i&&a.push("^"),t?(a.push(o?"full":"max"),a.join("")):(r&&a.push("!"),e&&a.push(`pct:${e}`),s&&a.push(`${s}`),a.push(","),n&&a.push(`${n}`),a.join(""))}function We(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var qe=Object.defineProperty,Be=Object.defineProperties,$e=Object.getOwnPropertyDescriptors,ct=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable,lt=(t,e,i)=>e in t?qe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,H=(t,e)=>{for(var i in e||(e={}))He.call(e,i)&&lt(t,i,e[i]);if(ct)for(var i of ct(e))Le.call(e,i)&&lt(t,i,e[i]);return t},L=(t,e)=>Be(t,$e(e));function Qe(t,e){const i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,r=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if(t.type==="base")return r;if(t.type==="info")return`${r}/info.json`;let{region:s,size:n,rotation:o,format:a,quality:c}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,h=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((n.width===e.width&&!n.height||n.height===e.height&&!n.width||n.width===e.width&&n.height===e.height)&&(n=L(H({},n),{max:!0})),f&&(n.max&&!n.serialiseAsFull&&(n=L(H({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=L(H({},n),{height:void 0}))),h&&(n.max&&n.serialiseAsFull&&(n=L(H({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const g=e.height/e.width;n=L(H({},n),{height:Math.ceil(n.width*g)})}}return[r,ze(s),Pe(n),We(o),`${c}.${a}`].filter(Boolean).join("/")}function D(t,e,i){const r=Me({id:z(A(t)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=e,r.size.height=i,{id:Qe(r),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function W(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function _e(t,e,i){const r=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-r)<Math.abs(e.width-r))}function Ne(t,e){const i=[],r=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),s=[],n=[];let o=null;const a=(l,f)=>{if(_e(r,f,l)){if(r.preferFixedSize&&l.unsafe){n.push(l);return}r.returnAllOptions&&f&&n.push(f),o=l}else r.returnAllOptions&&n.push(l)},c=e.length;for(let l=0;l<c;l++){const f=e[l](),h=f.length;for(let g=0;g<h;g++){const p=f[g];if(p.type==="unknown"&&r.atAnyCost&&s.push(p),p.type==="fixed"&&(p.unsafe?s.push(p):a(p,o)),p.type==="fixed-service")if(r.unsafeImageService){const u=D(p,r.width,r.height);a(u,o)}else{const u=D(p,p.width,p.height);a(u,o)}if(p.type==="variable"&&p.maxWidth){const u=D({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);a(u,o)}}if(o&&!r.returnAllOptions){if(o.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:o||s[0],fallback:s.slice(1),log:i}:r.returnAllOptions?{best:r.atAnyCost?o||n[0]||s[0]:o||n[0],fallback:[...n,...s],log:i}:{best:o||n[0]||null,fallback:o?n:n.slice(1),log:i}}var Ve=Object.defineProperty,Ee=Object.defineProperties,Ue=Object.getOwnPropertyDescriptors,ft=Object.getOwnPropertySymbols,De=Object.prototype.hasOwnProperty,Xe=Object.prototype.propertyIsEnumerable,ut=(t,e,i)=>e in t?Ve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ge=(t,e)=>{for(var i in e||(e={}))De.call(e,i)&&ut(t,i,e[i]);if(ft)for(var i of ft(e))Xe.call(e,i)&&ut(t,i,e[i]);return t},Je=(t,e)=>Ee(t,Ue(e));function Ye(t,e,i){const r=t>e?t:e,s=i.length,n=[];for(let o=0;o<s;o++){const a=i[o];let c=a.scaleFactors[0],l=r/c;const f=[c];for(;l>=a.width;)c=c*2,f.push(c),l=l/2;n.push(Je(Ge({},a),{scaleFactors:f}))}return n}function Ze(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const i=t.length;let r=!0;for(let n=0;n<i;n++){const o=t[n],a=e[n];if(o.width!==a.width||o.height!==a.height){r=!1;break}}if(r)return!0;let s=0;for(let n=0;n<i;n++)for(let o=0;o<i;o++)if(t[n].width===e[o].width&&t[n].height===e[o].height){s++;break}return s===i}function ht(t){if(t&&t.profile){const e=t.profile;if(e){const i=Array.isArray(e)?e:[e];return i.includes("level0")||i.includes("http://iiif.io/api/image/2/level0.json")||i.includes("http://iiif.io/api/image/1/level0.json")||i.includes("http://iiif.io/api/image/1/profiles/level0.json")}}return!1}var T=(t,e,i)=>new Promise((r,s)=>{var n=c=>{try{a(i.next(c))}catch(l){s(l)}},o=c=>{try{a(i.throw(c))}catch(l){s(l)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(n,o);a((i=i.apply(t,e)).next())});class $t{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,i,r=!0){const s=W(A(e)),n=z(A(e)),o=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),!o&&e.tiles&&!ht(e)?(this.knownImageServers[s]={verifications:0,malformed:!1,root:s,preLoaded:r,sampledId:A(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:i&&e.height?i.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Oe(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0):this.verify(e)}preLoad(e,i=!0){this.knownImageServers[e.root]=e,i&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,i=!1,r=!1){const s=e==null?void 0:e.source,n=W(A(e)),o=this.knownImageServers[n];if(!o||!o.result||!r&&(o.malformed||o.verifications<this.config.verificationsRequired)||ht(e.source))return null;const a=z(A(e));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":A(e),id:A(e),protocol:"http://iiif.io/api/image",tiles:(s==null?void 0:s.tiles)||Ye(e.width,e.height,o.result.sampledTiles),sizes:(s==null?void 0:s.sizes)||Ce(Math.round(e.width/o.result.resourceServiceRatio),Math.round(e.height/o.result.resourceServiceRatio),o.result.sizeRatios),profile:(s==null?void 0:s.profile)||o.result.sampledProfile,height:(s==null?void 0:s.height)||e.height,width:(s==null?void 0:s.width)||e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,i){return T(this,arguments,function*(r,s,n=!0,o=[]){const a=yield this.getImageCandidates(r,n);return Ne(s,[()=>o,()=>a])})}getImageCandidates(e,i=!0){return T(this,null,function*(){const r=e;if(i&&r.height&&r.width){const s=Bt(r);for(const n of s){const o={id:A(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(o)}}return Te(e,i,this)})}verify(e){return T(this,null,function*(){const i=this.predict(e,!1,!0),r=yield this.fetchService(A(e));if(!i)return!1;const s=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&Ze(i.sizes||[],r.sizes||[]);if(s){const n=W(A(e));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0)}return s})}canLoadSync(e){const i=typeof e=="string"?e:A(e),r=z(i);if(this.imageServices[r])return!0;const s=this.knownImageServers[W(i)];return s&&!s.malformed&&s.verifications>=this.config.verificationsRequired}markAsMalformed(e){return T(this,null,function*(){return this.knownImageServers[W(A(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return T(this,null,function*(){const r=z(e);if(this.imageServices[r]&&(!i||this.imageServices[r].real))return this.imageServices[r];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const s=yield this.fetch(r).then(n=>n.json());return!s.id&&s["@id"]&&(s.id=s["@id"]),s.id!==e&&(s.id=e,s["@id"]&&(s["@id"]=e)),this.imageServices[r]=Object.assign(s,{real:!0}),this.imageServices[r]})}fetch(e,i){return T(this,null,function*(){return fetch(e,i)})}loadService(e,i=!1){return T(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(o=>setTimeout(o,500));else{n=!1;break}}const r=this.knownImageServers[W(A(e))];if(r&&!r.malformed&&!i){yield r.result;const n=this.loadServiceSync(e);if(n)return n}this.fetchingCount++;const s=yield this.fetchService(A(e),i);return this.fetchingCount--,s.real&&this.sample(s,e),s})}loadServiceSync(e){const i=z(A(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new $t;function Ke(t,e={}){const i=e.imageServiceLoader||new $t;async function r(s,n,o,a=[],c){if(typeof s=="string")return{best:J(s),fallback:[],log:[]};const l=t.get(s);if(typeof l=="string")return{best:J(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,h=t.get(f[0]);return c&&!h.width&&(h.width=c.width,h.height=c.height),await i.getThumbnailFromResource(h,n,o,a)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const h=t.get(f.thumbnail[0]),g=await i.getImageCandidates(h,o);g&&g.length&&a.push(...g)}return r(f.items[0],n,o,a,{width:f.width,height:f.height})}case"AnnotationPage":return r(l.items[0],n,o,a,c);case"Choice":return r(l.items[0],n,o,a,c);case"Collection":{const h=l.items[0];return r(h,n,o,a,c)}case"Manifest":{const h=l.items[0];return r(h,n,o,a,c)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return c&&!l.width&&(l.width=c.width,l.height=c.height),i.getThumbnailFromResource(l,n,o,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function Ht(t,e,i=[],r=!1){if(!t||!e||e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const s=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(s&&e.indexOf(s)!==-1)return s;for(const n of i)if(e.indexOf(n)!==-1)return n;if(!r){const o=e.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(t);if(o!==-1)return e[o];for(const a of i){const c=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,l=c?e.indexOf(c):-1;if(l!==-1)return e[l]}}return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}function Lt(t,e,i={}){const{strictFallback:r=!1,defaultText:s="",separator:n=`
`,fallbackLanguages:o=[],closest:a}=i,c=Object.keys(t||{}),l=a?e:Ht(e,c,o,r);if(!t)return s;if(typeof t=="string")return t;const f=l?t[l]:void 0;return f?typeof f=="string"?f:f.join(n):""}function ti(t,e={}){return Lt(t,typeof navigator!="undefined"?navigator.language:void 0,e)}var ei=function(){function t(e,i){var r=[],s=!0,n=!1,o=void 0;try{for(var a=e[Symbol.iterator](),c;!(s=(c=a.next()).done)&&(r.push(c.value),!(i&&r.length===i));s=!0);}catch(l){n=!0,o=l}finally{try{!s&&a.return&&a.return()}finally{if(n)throw o}}return r}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Q=Math.PI*2,X=function(e,i,r,s,n,o,a){var c=e.x,l=e.y;c*=i,l*=r;var f=s*c-n*l,h=n*c+s*l;return{x:f+o,y:h+a}},ii=function(e,i){var r=i===1.5707963267948966?.551915024494:i===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(i/4),s=Math.cos(e),n=Math.sin(e),o=Math.cos(e+i),a=Math.sin(e+i);return[{x:s-n*r,y:n+s*r},{x:o+a*r,y:a-o*r},{x:o,y:a}]},pt=function(e,i,r,s){var n=e*s-i*r<0?-1:1,o=e*r+i*s;return o>1&&(o=1),o<-1&&(o=-1),n*Math.acos(o)},ri=function(e,i,r,s,n,o,a,c,l,f,h,g){var p=Math.pow(n,2),u=Math.pow(o,2),m=Math.pow(h,2),v=Math.pow(g,2),x=p*u-p*v-u*m;x<0&&(x=0),x/=p*v+u*m,x=Math.sqrt(x)*(a===c?-1:1);var d=x*n/o*g,y=x*-o/n*h,b=f*d-l*y+(e+r)/2,w=l*d+f*y+(i+s)/2,S=(h-d)/n,M=(g-y)/o,O=(-h-d)/n,C=(-g-y)/o,I=pt(1,0,S,M),k=pt(S,M,O,C);return c===0&&k>0&&(k-=Q),c===1&&k<0&&(k+=Q),[b,w,I,k]},ni=function(e){var i=e.px,r=e.py,s=e.cx,n=e.cy,o=e.rx,a=e.ry,c=e.xAxisRotation,l=c===void 0?0:c,f=e.largeArcFlag,h=f===void 0?0:f,g=e.sweepFlag,p=g===void 0?0:g,u=[];if(o===0||a===0)return[];var m=Math.sin(l*Q/360),v=Math.cos(l*Q/360),x=v*(i-s)/2+m*(r-n)/2,d=-m*(i-s)/2+v*(r-n)/2;if(x===0&&d===0)return[];o=Math.abs(o),a=Math.abs(a);var y=Math.pow(x,2)/Math.pow(o,2)+Math.pow(d,2)/Math.pow(a,2);y>1&&(o*=Math.sqrt(y),a*=Math.sqrt(y));var b=ri(i,r,s,n,o,a,h,p,m,v,x,d),w=ei(b,4),S=w[0],M=w[1],O=w[2],C=w[3],I=Math.abs(C)/(Q/4);Math.abs(1-I)<1e-7&&(I=1);var k=Math.max(Math.ceil(I),1);C/=k;for(var it=0;it<k;it++)u.push(ii(O,C)),O+=C;return u.map(function(U){var rt=X(U[0],o,a,v,m,S,M),Jt=rt.x,Yt=rt.y,nt=X(U[1],o,a,v,m,S,M),Zt=nt.x,Kt=nt.y,st=X(U[2],o,a,v,m,S,M),te=st.x,ee=st.y;return{x1:Jt,y1:Yt,x2:Zt,y2:Kt,x:te,y:ee}})},si=ai,G={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},oi=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ai(t){var e=[];return t.replace(oi,function(i,r,s){var n=r.toLowerCase();for(s=li(s),n=="m"&&s.length>2&&(e.push([r].concat(s.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(s.length==G[n])return s.unshift(r),e.push(s);if(s.length<G[n])throw new Error("malformed path data");e.push([r].concat(s.splice(0,G[n])))}}),e}var ci=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function li(t){var e=t.match(ci);return e?e.map(Number):[]}var fi=ui;function ui(t){var e=0,i=0,r=0,s=0;return t.map(function(n){n=n.slice();var o=n[0],a=o.toUpperCase();if(o!=a)switch(n[0]=a,o){case"a":n[6]+=r,n[7]+=s;break;case"v":n[1]+=s;break;case"h":n[1]+=r;break;default:for(var c=1;c<n.length;)n[c++]+=r,n[c++]+=s}switch(a){case"Z":r=e,s=i;break;case"H":r=n[1];break;case"V":s=n[1];break;case"M":r=e=n[1],s=i=n[2];break;default:r=n[n.length-2],s=n[n.length-1]}return n})}function hi(t){const e=si(t),i=fi(e);let r,s=0,n=0,o=0,a=0,c,l,f=0,h=0;const g=[];for(let p=0;p<i.length;p++){let u=i[p];const m=u[0];switch(m){case"M":s=u[1],n=u[2];break;case"H":u=["L",u[1],n];break;case"V":u=["L",s,u[1]];break;case"S":{let v=f,x=h;(r==="C"||r=="S")&&(v+=v-o,x+=x-a),u=["C",v,x,u[1],u[2],u[3],u[4]]}break;case"T":r==="Q"||r=="T"?(c=f*2-c,l=h*2-l):(c=f,l=h),u=["Q",c,l,u[1],u[2]];break;case"Q":c=u[1],l=u[2];break;case"A":{const v=ni({px:f,py:h,cx:u[6],cy:u[7],rx:u[1],ry:u[2],xAxisRotation:u[3],largeArcFlag:u[4],sweepFlag:u[5]});if(!v.length)continue;for(const[x,d]of v.entries())u=["C",d.x1,d.y1,d.x2,d.y2,d.x,d.y],x<v.length-1&&g.push(u);u=u}break;case"Z":u=["L",s,n];break}r=m,f=u[u.length-2],h=u[u.length-1],["C","Q","A"].indexOf(m)>-1?(o=u[u.length-4],a=u[u.length-3]):(o=f,a=h),g.push(u)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const U={},I={get(e){return e},setMetaValue([e,t,r],i){const n=I.getResourceMeta(e,t),s=n?n[r]:void 0,o=typeof i=="function"?i(s):i;U[e]={...U[e]||{},[t]:{...(U[e]||{})[t]||{},[r]:o}}},getResourceMeta:(e,t)=>{const r=U[e];if(!!r)return t?r[t]:r}};function ft(e=I){return{addEventListener(t,r,i,n){if(!!t)return e.setMetaValue([t.id,"eventManager",r],s=>{const o=s||[];for(const a of o)if(a.callback===i)return o;return[...o,{callback:i,scope:n}]}),i},removeEventListener(t,r,i){!t||e.setMetaValue([t.id,"eventManager",r],n=>(n||[]).filter(s=>s.callback!==i))},getListenersAsProps(t,r){const i=typeof t=="string"?{id:t}:t;if(!i||!i.id)return{};const n=e.getResourceMeta(i.id,"eventManager"),s={};if(n&&i)for(const o of Object.keys(n))s[o]=a=>{const c=e.get(i);for(const{callback:u,scope:f}of n[o]||[])(!f||r&&f.indexOf(r)!==-1)&&u(a,c)};return s}}}function ut(e=I){return{applyStyles(t,r,i){const n=typeof t=="string"?t:t.id;return e.setMetaValue([n,"styles",r],i)},getAppliedStyles(t){const r=typeof t=="string"?t:t.id;return e.getResourceMeta(r,"styles")}}}function P(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}const ht="http://library.stanford.edu/iiif/image-api/compliance.html#level0",be="http://library.stanford.edu/iiif/image-api/compliance.html#level1",we="http://library.stanford.edu/iiif/image-api/compliance.html#level2",pt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/conformance.html#level2",dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Fe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Me="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",gt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Oe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",yt="http://iiif.io/api/image/1/level0.json",mt="http://iiif.io/api/image/1/profiles/level0.json",ke="http://iiif.io/api/image/1/level1.json",Re="http://iiif.io/api/image/1/profiles/level1.json",Ie="http://iiif.io/api/image/1/level2.json",je="http://iiif.io/api/image/1/profiles/level2.json",vt="http://iiif.io/api/image/2/level0.json",xt="http://iiif.io/api/image/2/profiles/level0.json",Te="http://iiif.io/api/image/2/level1.json",ze="http://iiif.io/api/image/2/profiles/level1.json",$e="http://iiif.io/api/image/2/level2.json",We="http://iiif.io/api/image/2/profiles/level2.json",bt="level0",Be="level1",Pe="level2",wt="http://iiif.io/api/image/2/level0",qe="http://iiif.io/api/image/2/level1",He="http://iiif.io/api/image/2/level2",Le=[He,we,Ae,Me,Oe,Ie,je,$e,We,Pe],_e=[...Le,qe,be,Se,Fe,Ce,ke,Re,Te,ze,Be],St=[wt,qe,He,ht,be,we,pt,Se,Ae,dt,Fe,Me,gt,Ce,Oe,yt,mt,ke,Re,Ie,je,vt,xt,Te,ze,$e,We,bt,Be,Pe],At={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},Ft={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},Mt={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function Ct(e){return Le.indexOf(e)!==-1?Mt:_e.indexOf(e)!==-1?Ft:At}function Ot(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],r={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let i of t)if(typeof i=="string"&&(i=Ct(i)),!!i){if(i.formats)for(const n of i.formats)r.extraFormats.indexOf(n)===-1&&r.extraFormats.push(n);if(i.qualities)for(const n of i.qualities)r.extraQualities.indexOf(n)===-1&&r.extraQualities.push(n);if(i.supports)for(const n of i.supports)r.extraFeatures.indexOf(n)===-1&&r.extraFeatures.push(n);if(i.maxHeight&&(r.maxHeight=i.maxHeight),i.maxWidth&&(r.maxWidth=i.maxWidth),i.maxArea&&(r.maxArea=i.maxArea),i.extraFormats)for(const n of i.extraFormats)r.extraFormats.indexOf(n)===-1&&r.extraFormats.push(n);if(i.extraQualities)for(const n of i.extraQualities)r.extraQualities.indexOf(n)===-1&&r.extraQualities.push(n);if(i.extraFeatures)for(const n of i.extraFeatures)r.extraFeatures.indexOf(n)===-1&&r.extraFeatures.push(n);i.maxHeight&&(r.maxHeight=i.maxHeight),i.maxWidth&&(r.maxWidth=i.maxWidth),i.maxArea&&(r.maxArea=i.maxArea)}if(e.extraFormats)for(const i of e.extraFormats)r.extraFormats.indexOf(i)===-1&&r.extraFormats.push(i);if(e.extraFeatures)for(const i of e.extraFeatures)r.extraFeatures.indexOf(i)===-1&&r.extraFeatures.push(i);if(e.extraQualities)for(const i of e.extraQualities)r.extraQualities.indexOf(i)===-1&&r.extraQualities.push(i);return r}function kt(e){try{if(e==="full")return{full:!0};if(e==="square")return{square:!0};const t=e.startsWith("pct:"),r=e.substr(t?4:0).split(",").map(i=>parseFloat(i));return{x:r[0],y:r[1],w:r[2],h:r[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function Rt(e){const t={upscaled:!1,max:!1,confined:!1};if(e[0]==="^"&&(t.upscaled=!0,e=e.slice(1)),e==="max"||e==="full")return t.max=!0,t.serialiseAsFull=e==="full",t;if(e[0]==="!"&&(t.confined=!0,e=e.slice(1)),e[0]==="p")return t.percentScale=parseFloat(e.slice(4)),t;const r=e.split(",").map(i=>i.trim());return r.length&&(r[0]!==""&&(t.width=parseInt(r[0],10)),r[1]!==""?(t.height=parseInt(r[1],10),t.version=2):t.version=3),t}function It(e){const t={angle:0};if(e[0]==="!"&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw new Error(`Invalid rotation ${e}`);return t}function jt(e,t=""){const r=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!r)throw new Error(`Invalid or unknown input ${e}`);const i=r[2],n=r[3];let s=r[4];if(s[0]==="/"&&(s=s.substr(1)),t.length>0){if(t[0]==="/"&&(t=t.substr(1)),t!==s.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${s}, prefix: ${t})`);s=s.substr(t.length)}return{scheme:i,server:n,path:s,prefix:t}}function Tt(e,t=""){const{path:r,scheme:i,server:n,prefix:s}=jt(e,t),o=r.split("/").reverse(),[a,c,u,f,...p]=o,h=p.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:i,server:n,prefix:s,identifier:h};if(a==="info.json"){const[,...l]=o;return{type:"info",scheme:i,server:n,prefix:s,identifier:l.reverse().filter(Boolean).join("/")}}const g=a.split(".");return{type:"image",scheme:i,server:n,prefix:s,identifier:h,originalPath:r,region:kt(f),size:Rt(u),rotation:It(c),quality:g[0],format:g[1]}}function zt(e){const t=Tt(P(e.id));if(t.type!=="info")throw new Error("Invalid service URL");const r=Ot(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.scheme,type:"image",quality:r.extraQualities.indexOf("default")===-1?r.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function $t(e,t,r){const i=r.length,n=[];for(let s=0;s<i;s++){const o=r[s].width;n.push(e/o)}return n}function Wt(e,t,r){const i=r.length,n=[];for(let s=0;s<i;s++){const o=r[s];n.push({width:Math.floor(e/o),height:Math.floor(t/o)})}return n}function A(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function J(e){if(!e||!e.profile||!A(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const r of t)if(typeof r=="string"&&St.indexOf(r)!==-1)return!0;return!1}function Bt(e){if(!J(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const r of t)if(typeof r=="string"){if(_e.indexOf(r)!==-1)return!0}else{const i=[...r.supports||[],...r.extraFeatures||[]];if(i.indexOf("regionByPx")!==-1&&(i.indexOf("sizeByW")!==-1||i.indexOf("sizeByWh")!==-1))return!0}return!1}function D(e,t){if(t&&t.profile){const r=t.profile;if(r){const i=Array.isArray(r)?r:[r];return i.includes(`level${e}`)||i.includes(`http://iiif.io/api/image/2/level${e}.json`)||i.includes(`http://iiif.io/api/image/1/level${e}.json`)||i.includes(`http://iiif.io/api/image/1/profiles/level${e}.json`)}}return!1}function te(e){return J(e)?D(0,e)?0:D(1,e)?1:D(2,e)?2:null:null}function Qe(e){return(e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[]).indexOf("http://iiif.io/api/image/3/context.json")!==-1}function Pt(e){if(!Bt(e))return[];const t=[],r=Array.isArray(e.profile)?e.profile:[e.profile],i=r.length;for(let n=0;n<i;n++){const s=r[n];if(typeof s!="string"&&(s.maxHeight||s.maxWidth))return[{id:A(e),type:"variable",minWidth:0,minHeight:0,maxHeight:s.maxHeight||s.maxWidth,maxWidth:s.maxWidth||s.maxHeight,level:te(e),version:e["@context"]==="http://iiif.io/api/image/3/context.json"?3:2}]}if(e.tiles){const n=e.tiles.length;for(let s=0;s<n;s++){const o=e.tiles[s];(o.height||o.width)&&t.push({id:A(e),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width,level:te(e),version:Qe(e)?3:2})}}return t}function ue(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=e.match(t);if(r){const i=r[1],n=parseInt(r[4],10),s=parseInt(r[5],10),o=r[7];if((i==="max"||i==="full")&&n&&s&&o)return{type:"fixed",id:e,height:s,width:n}}return{type:"unknown",id:e}}function qt(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function ie(e){if(typeof e=="string")return ue(e);const t=qt(e);if(t!=="Image"&&t!=="sc:Image")return null;const r=e,i=A(r);return i?i&&r.width&&r.height?{id:i,type:"fixed",width:r.width,height:r.height,unsafe:!0}:ue(i):null}function Ht(e){return J(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:A(e),type:"fixed-service",height:t.height,width:t.width,level:te(e),version:Qe(e)?3:2})):[]}function he(e){const t=[],r=e.length;for(let i=0;i<r;i++){const n=Ht(e[i]);n.length&&t.push(...n);const s=Pt(e[i]);s.length&&t.push(...s)}return t}function Ve(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],r=t.length,i=[];for(let n=0;n<r;n++)J(t[n])&&i.push(t[n]);return i}function Lt(e,t=!0,r){const i=[],n=ie(e);if(n===null)return i;const s=e;if(i.push(n),t&&s.width&&s.height){const o=[],a=Ve(s);for(const c of a){const u={id:A(c),width:s.width,height:s.height};if(r.canLoadSync(u)){const f=r.loadServiceSync(u);f&&(f.height||(f.height=s.height),f.width||(f.width=s.width),o.push(...he([f])))}}if(o.length)return i.push(...o),i}return s.service&&i.push(...he(s.service)),i}function _t({x:e=0,y:t=0,w:r,h:i,full:n,square:s,percent:o}){if(n)return"full";if(s)return"square";if(typeof r>"u"||typeof i>"u")throw new Error("RegionParameter: invalid region");const a=`${e},${t},${r},${i}`;return o?`pct:${a}`:a}function Qt({max:e,percentScale:t,upscaled:r,confined:i,width:n,height:s,serialiseAsFull:o,version:a}){const c=[];return r&&c.push("^"),e?(c.push(o?"full":"max"),c.join("")):(i&&c.push("!"),t&&c.push(`pct:${t}`),n&&c.push(`${n}`),c.push(","),s&&a===3&&c.push(`${s}`),c.join(""))}function Vt(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}var Nt=Object.defineProperty,Et=Object.defineProperties,Ut=Object.getOwnPropertyDescriptors,pe=Object.getOwnPropertySymbols,Dt=Object.prototype.hasOwnProperty,Jt=Object.prototype.propertyIsEnumerable,de=(e,t,r)=>t in e?Nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,$=(e,t)=>{for(var r in t||(t={}))Dt.call(t,r)&&de(e,r,t[r]);if(pe)for(var r of pe(t))Jt.call(t,r)&&de(e,r,t[r]);return e},W=(e,t)=>Et(e,Ut(t));function Xt(e,t){const r=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,i=`${e.scheme}://${e.server}/${r?`${r}/`:""}${e.identifier}`;if(e.type==="base")return i;if(e.type==="info")return`${i}/info.json`;let{size:n}=e;const{region:s,rotation:o,format:a,quality:c}=e;if(t){const u=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],f=u.indexOf("http://iiif.io/api/image/2/context.json")!==-1,p=u.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((n.width===t.width&&!n.height||n.height===t.height&&!n.width||n.width===t.width&&n.height===t.height)&&(n=W($({},n),{max:!0})),f&&(n.max&&!n.serialiseAsFull&&(n=W($({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=W($({},n),{height:void 0})),n=W($({},n),{version:2})),p){if(n.max&&n.serialiseAsFull&&(n=W($({},n),{serialiseAsFull:!1})),n.width&&!n.height&&t.width&&t.height){const h=t.height/t.width;n=W($({},n),{height:Math.ceil(n.width*h)})}n=W($({},n),{version:3})}}return[i,_t(s),Qt(n),Vt(o),`${c}.${a}`].filter(Boolean).join("/")}function Z(e,t,r){const i=zt({"@context":e.version===3?"http://iiif.io/api/image/3/context.json":"http://iiif.io/api/image/2/context.json",id:P(A(e)),profile:e.level===null||typeof e.level>"u"?"level0":`level${e.level}}`,type:e.version===3?"ImageService3":"ImageService2"});if(i.type!=="image")throw new Error("Invalid service");return i.size.max=!1,i.size.width=t,i.size.height=r,{id:Xt(i),type:"fixed",width:t,height:r||e.height/(e.width||1)*t,unsafe:e.width>t}}function H(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Gt(e,t,r){const i=e.width?e.width:e.maxWidth;return r.height<=e.maxHeight&&r.width<=e.maxWidth&&r.height>=e.minHeight&&r.width>=e.minWidth&&(!t||Math.abs(r.width-i)<Math.abs(t.width-i))}function Yt(e,t){const r=[],i=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),n=(f,p=0)=>i.explain?r.push(new Array(p).fill(0).map(h=>" ").join("")+f().trim()):void 0,s=[],o=[];let a=null;n(()=>`Using configuration: ${JSON.stringify(i,null,2)}`);const c=(f,p)=>{if(n(()=>"Swapping choice",3),Gt(i,p,f)){if(i.preferFixedSize&&f.unsafe){n(()=>`We found an image that was marked as unsafe, but it was the best size. (${f.id})`,4),o.push(f);return}i.returnAllOptions&&p&&o.push(p),n(()=>`We found a new image that was the best size. (${f.id})`,4),a=f}else i.returnAllOptions&&o.push(f)};n(()=>`The input shows we have ${t.length} list(s) of candidates to choose from.`);const u=t.length;for(let f=0;f<u;f++){const p=t[f]();n(()=>`Candidate group ${f}: ${JSON.stringify(p,null,2)}`,1);const h=p.length;n(()=>`Checking candidate list number ${f} and found ${h} potential ways of creating image(s)`,1);for(let g=0;g<h;g++){const l=p[g];if(n(()=>`-> Checking candidate ${g}`,1),l.type==="unknown"&&i.atAnyCost&&(n(()=>`We've found an unknown image type, adding this to the "last resort" list`,2),s.push(l)),l.type==="fixed"&&(l.unsafe?(n(()=>`We've found an unsafe fixed image type, adding this to the "last resort" list`,2),s.push(l)):(n(()=>"We've found a fixed size image, checking if it matches the request",2),c(l,a))),l.type==="fixed-service")if(i.unsafeImageService){n(()=>"Checking for an image from the tile source, without calculating the right height and width (unsafeImageService)",2);const m=Z(l,i.width,i.height);c(m,a)}else{n(()=>"Checking for an image from the tile source 3",2);const m=Z(l,l.width,l.height);c(m,a)}if(l.type==="variable"&&l.maxWidth){const m=Z({id:l.id,type:"fixed-service",width:l.maxWidth,height:l.maxWidth,level:l.level,version:l.version},l.maxWidth);c(m,a)}}if(a&&!i.returnAllOptions){if(a.unsafe||i.allowUnsafe)continue;n(()=>`We found a match in choice list number ${f}, no searching any more`);break}}return i.atAnyCost&&o.length===0?(n(()=>a?`We found an image! ${a.id} of type ${a.type}`:'We found no images, but "atAnyCost" is set, so returning that'),{best:a||s[0],fallback:s.slice(1),log:r}):i.returnAllOptions?(n(()=>"Returning all options that we have found"),{best:i.atAnyCost?a||o[0]||s[0]:a||o[0],fallback:[...o,...s],log:r}):(n(()=>"Returning the best image that we found, and a fallback"),{best:a||o[0]||null,fallback:a?o:o.slice(1),log:r})}var Zt=Object.defineProperty,Kt=Object.defineProperties,ei=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertySymbols,ti=Object.prototype.hasOwnProperty,ii=Object.prototype.propertyIsEnumerable,ye=(e,t,r)=>t in e?Zt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ri=(e,t)=>{for(var r in t||(t={}))ti.call(t,r)&&ye(e,r,t[r]);if(ge)for(var r of ge(t))ii.call(t,r)&&ye(e,r,t[r]);return e},ni=(e,t)=>Kt(e,ei(t));function si(e,t,r){const i=e>t?e:t,n=r.length,s=[];for(let o=0;o<n;o++){const a=r[o];let c=a.scaleFactors[0],u=i/c;const f=[c];for(;u>=a.width;)c=c*2,f.push(c),u=u/2;s.push(ni(ri({},a),{scaleFactors:f}))}return s}function oi(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const r=e.length;let i=!0;for(let s=0;s<r;s++){const o=e[s],a=t[s];if(o.width!==a.width||o.height!==a.height){i=!1;break}}if(i)return!0;let n=0;for(let s=0;s<r;s++)for(let o=0;o<r;o++)if(e[s].width===t[o].width&&e[s].height===t[o].height){n++;break}return n===r}function me(e){return D(0,e)}var B=(e,t,r)=>new Promise((i,n)=>{var s=c=>{try{a(r.next(c))}catch(u){n(u)}},o=c=>{try{a(r.throw(c))}catch(u){n(u)}},a=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,o);a((r=r.apply(e,t)).next())});class Ne{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,r,i=!0){const n=H(A(t)),s=P(A(t)),o=this.knownImageServers[n];return this.imageServices[s]=Object.assign(t,{real:!0}),!o&&t.tiles&&!me(t)?(this.knownImageServers[n]={verifications:0,malformed:!1,root:n,preLoaded:i,sampledId:A(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:r&&t.height?r.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:$t(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0):this.verify(t)}preLoad(t,r=!0){this.knownImageServers[t.root]=t,r&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,r=!1,i=!1){const n=t==null?void 0:t.source,s=H(A(t)),o=this.knownImageServers[s];if(!o||!o.result||!((n==null?void 0:n.height)||t.height)||!((n==null?void 0:n.width)||t.width)||!i&&(o.malformed||o.verifications<this.config.verificationsRequired)||me(t.source))return null;const a=P(A(t));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":A(t),id:A(t),protocol:"http://iiif.io/api/image",tiles:(n==null?void 0:n.tiles)||si(t.width,t.height,o.result.sampledTiles),sizes:(n==null?void 0:n.sizes)||Wt(Math.round(t.width/o.result.resourceServiceRatio),Math.round(t.height/o.result.resourceServiceRatio),o.result.sizeRatios),profile:(n==null?void 0:n.profile)||o.result.sampledProfile,height:(n==null?void 0:n.height)||t.height,width:(n==null?void 0:n.width)||t.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(t,r){return B(this,arguments,function*(i,n,s=!0,o=[]){const a=i?yield this.getImageCandidates(i,s):[];return Yt(n,[()=>o,()=>a])})}getImageCandidates(t,r=!0){return B(this,null,function*(){const i=t;if(r&&i.height&&i.width){const n=Ve(i);for(const s of n){const o={id:A(s),width:s.width?s.width:i.width,height:s.height?s.height:i.height,source:s};yield this.loadService(o)}}return Lt(t,r,this)})}verify(t){return B(this,null,function*(){const r=this.predict(t,!1,!0),i=yield this.fetchService(A(t));if(!r)return!1;const n=r.height===i.height&&r.width===i.width&&r["@context"]===i["@context"]&&oi(r.sizes||[],i.sizes||[]);if(n){const s=H(A(t));this.knownImageServers[s].verifications+=1,this.knownImageServers[s].verifications>=this.config.verificationsRequired&&(this.knownImageServers[s].verified=!0)}return n})}canLoadSync(t){const r=typeof t=="string"?t:A(t),i=P(r);if(this.imageServices[i])return!0;const n=this.knownImageServers[H(r)];return n&&!n.malformed&&n.verifications>=this.config.verificationsRequired}markAsMalformed(t){return B(this,null,function*(){return this.knownImageServers[H(A(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,r=!1){return B(this,null,function*(){const i=P(t);if(this.imageServices[i]&&(!r||this.imageServices[i].real))return this.imageServices[i];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const n=yield this.fetch(i).then(s=>s.json());return!n.id&&n["@id"]&&(n.id=n["@id"]),n.id!==t&&(n.id=t,n["@id"]&&(n["@id"]=t)),this.imageServices[i]=Object.assign(n,{real:!0}),this.imageServices[i]})}fetch(t,r){return B(this,null,function*(){return fetch(t,r)})}loadService(t,r=!1){return B(this,null,function*(){if(!this.config.disableThrottling){let s=!0;for(;s;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(o=>setTimeout(o,500));else{s=!1;break}}const i=this.knownImageServers[H(A(t))];if(i&&!i.malformed&&!r){yield i.result;const s=this.loadServiceSync(t);if(s)return s}this.fetchingCount++;const n=yield this.fetchService(A(t),r);return this.fetchingCount--,n.real&&this.sample(n,t),n})}loadServiceSync(t){const r=P(A(t));return this.imageServices[r]?this.imageServices[r]:this.predict(t)}}new Ne;function ai(e=I,t={}){const r=t.imageServiceLoader||new Ne;async function i(n,s,o,a=[],c){const u=()=>r.getThumbnailFromResource(void 0,s,o,a);if(!n)return await r.getThumbnailFromResource(void 0,s,o,a);if(typeof n=="string"){const h=ie(n);return h&&a.push(h),await r.getThumbnailFromResource(void 0,s,o,a)}const f=e.get(n,{skipSelfReturn:!1});if(typeof f=="string")return{best:ie(f),fallback:[],log:[]};if(!f)return await u();switch(await(async h=>{if(h&&h.thumbnail&&h.thumbnail.length){const g=e.get(h.thumbnail[0]),l=await r.getImageCandidates(g,o);l&&l.length&&a.push(...l)}})(f),f.type){case"Annotation":{const h=Array.isArray(f.body)?f.body:[f.body],g=e.get(h[0]);return c&&!g.width&&(g.width=c.width,g.height=c.height),await r.getThumbnailFromResource(g,s,o,a)}case"Canvas":{const h=f;return i(h.items[0],s,o,a,{width:h.width,height:h.height})}case"AnnotationPage":return i(f.items[0],s,o,a,c);case"Choice":{const h=f;return!h.items||h.items[0]?await u():i(h.items[0],s,o,a,c)}case"Collection":{const g=f.items[0];return g?i(g,s,o,a,c):await u()}case"Manifest":{const g=f.items[0];return g?i(g,s,o,a,c):await u()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return c&&!f.width&&(f.width=c.width,f.height=c.height),r.getThumbnailFromResource(f,s,o,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return await u()}return await u()}return{getBestThumbnailAtSize:i}}function Ee(e,t,r=[],i=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const n=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(n&&t.indexOf(n)!==-1)return n;for(const s of r)if(t.indexOf(s)!==-1)return s;if(!i){const o=t.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(e);if(o!==-1)return t[o];for(const a of r){const c=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,u=c?t.indexOf(c):-1;if(u!==-1)return t[u]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function Ue(e,t,r={}){const{strictFallback:i=!1,defaultText:n="",separator:s=`
`,fallbackLanguages:o=[],closest:a}=r,c=Object.keys(e||{}),u=a?t:Ee(t,c,o,i);if(!e)return n;if(typeof e=="string")return e;const f=u?e[u]:void 0;return f?typeof f=="string"?f:f.join(s):""}function ci(e,t={}){return Ue(e,typeof navigator!="undefined"?navigator.language:void 0,t)}var li=function(){function e(t,r){var i=[],n=!0,s=!1,o=void 0;try{for(var a=t[Symbol.iterator](),c;!(n=(c=a.next()).done)&&(i.push(c.value),!(r&&i.length===r));n=!0);}catch(u){s=!0,o=u}finally{try{!n&&a.return&&a.return()}finally{if(s)throw o}}return i}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),V=Math.PI*2,K=function(t,r,i,n,s,o,a){var c=t.x,u=t.y;c*=r,u*=i;var f=n*c-s*u,p=s*c+n*u;return{x:f+o,y:p+a}},fi=function(t,r){var i=r===1.5707963267948966?.551915024494:r===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(r/4),n=Math.cos(t),s=Math.sin(t),o=Math.cos(t+r),a=Math.sin(t+r);return[{x:n-s*i,y:s+n*i},{x:o+a*i,y:a-o*i},{x:o,y:a}]},ve=function(t,r,i,n){var s=t*n-r*i<0?-1:1,o=t*i+r*n;return o>1&&(o=1),o<-1&&(o=-1),s*Math.acos(o)},ui=function(t,r,i,n,s,o,a,c,u,f,p,h){var g=Math.pow(s,2),l=Math.pow(o,2),m=Math.pow(p,2),v=Math.pow(h,2),x=g*l-g*v-l*m;x<0&&(x=0),x/=g*v+l*m,x=Math.sqrt(x)*(a===c?-1:1);var d=x*s/o*h,y=x*-o/s*p,b=f*d-u*y+(t+i)/2,w=u*d+f*y+(r+n)/2,S=(p-d)/s,M=(h-y)/o,C=(-p-d)/s,O=(-h-y)/o,z=ve(1,0,S,M),R=ve(S,M,C,O);return c===0&&R>0&&(R-=V),c===1&&R<0&&(R+=V),[b,w,z,R]},hi=function(t){var r=t.px,i=t.py,n=t.cx,s=t.cy,o=t.rx,a=t.ry,c=t.xAxisRotation,u=c===void 0?0:c,f=t.largeArcFlag,p=f===void 0?0:f,h=t.sweepFlag,g=h===void 0?0:h,l=[];if(o===0||a===0)return[];var m=Math.sin(u*V/360),v=Math.cos(u*V/360),x=v*(r-n)/2+m*(i-s)/2,d=-m*(r-n)/2+v*(i-s)/2;if(x===0&&d===0)return[];o=Math.abs(o),a=Math.abs(a);var y=Math.pow(x,2)/Math.pow(o,2)+Math.pow(d,2)/Math.pow(a,2);y>1&&(o*=Math.sqrt(y),a*=Math.sqrt(y));var b=ui(r,i,n,s,o,a,p,g,m,v,x,d),w=li(b,4),S=w[0],M=w[1],C=w[2],O=w[3],z=Math.abs(O)/(V/4);Math.abs(1-z)<1e-7&&(z=1);var R=Math.max(Math.ceil(z),1);O/=R;for(var ae=0;ae<R;ae++)l.push(fi(C,O)),C+=O;return l.map(function(Y){var ce=K(Y[0],o,a,v,m,S,M),nt=ce.x,st=ce.y,le=K(Y[1],o,a,v,m,S,M),ot=le.x,at=le.y,fe=K(Y[2],o,a,v,m,S,M),ct=fe.x,lt=fe.y;return{x1:nt,y1:st,x2:ot,y2:at,x:ct,y:lt}})},pi=gi,ee={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},di=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function gi(e){var t=[];return e.replace(di,function(r,i,n){var s=i.toLowerCase();for(n=mi(n),s=="m"&&n.length>2&&(t.push([i].concat(n.splice(0,2))),s="l",i=i=="m"?"l":"L");;){if(n.length==ee[s])return n.unshift(i),t.push(n);if(n.length<ee[s])throw new Error("malformed path data");t.push([i].concat(n.splice(0,ee[s])))}}),t}var yi=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function mi(e){var t=e.match(yi);return t?t.map(Number):[]}var vi=xi;function xi(e){var t=0,r=0,i=0,n=0;return e.map(function(s){s=s.slice();var o=s[0],a=o.toUpperCase();if(o!=a)switch(s[0]=a,o){case"a":s[6]+=i,s[7]+=n;break;case"v":s[1]+=n;break;case"h":s[1]+=i;break;default:for(var c=1;c<s.length;)s[c++]+=i,s[c++]+=n}switch(a){case"Z":i=t,n=r;break;case"H":i=s[1];break;case"V":n=s[1];break;case"M":i=t=s[1],n=r=s[2];break;default:i=s[s.length-2],n=s[s.length-1]}return s})}function bi(e){const t=pi(e),r=vi(t);let i,n=0,s=0,o=0,a=0,c,u,f=0,p=0;const h=[];for(let g=0;g<r.length;g++){let l=r[g];const m=l[0];switch(m){case"M":n=l[1],s=l[2];break;case"H":l=["L",l[1],s];break;case"V":l=["L",n,l[1]];break;case"S":{let v=f,x=p;(i==="C"||i=="S")&&(v+=v-o,x+=x-a),l=["C",v,x,l[1],l[2],l[3],l[4]]}break;case"T":i==="Q"||i=="T"?(c=f*2-c,u=p*2-u):(c=f,u=p),l=["Q",c,u,l[1],l[2]];break;case"Q":c=l[1],u=l[2];break;case"A":{const v=hi({px:f,py:p,cx:l[6],cy:l[7],rx:l[1],ry:l[2],xAxisRotation:l[3],largeArcFlag:l[4],sweepFlag:l[5]});if(!v.length)continue;for(const[x,d]of v.entries())l=["C",d.x1,d.y1,d.x2,d.y2,d.x,d.y],x<v.length-1&&h.push(l);l=l}break;case"Z":l=["L",n,s];break}i=m,f=l[l.length-2],p=l[l.length-1],["C","Q","A"].indexOf(m)>-1?(o=l[l.length-4],a=l[l.length-3]):(o=f,a=p),h.push(l)}return h}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
*

@@ -32,3 +32,3 @@ * All code in this module is based on JavaScript code by Raph Levien, published on his blog at

* limitations under the License.
*/function pi(t,e,i,r=1){return new Qt(t,e,i).subdivide(r)}function di(t,e,i,r,s=1){return new K(new Float64Array([t.x,t.y,e.x,e.y,i.x,i.y,r.x,r.y])).subdivide(s)}function gi(t){return t.x*t.x+t.y*t.y}function _(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function B(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Qt{constructor(e,i,r){this.start=e,this.control=i,this.end=r}eval(e){const i=1-e;return{x:this.start.x*i*i+2*this.control.x*i*e+this.end.x*e*e,y:this.start.y*i*i+2*this.control.y*i*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:i}=this.start,{x:r,y:s}=this.control,{x:n,y:o}=this.end,a=2*r-e-n,c=2*s-i-o,l=(r-e)*a+(s-i)*c,f=(n-r)*a+(o-s)*c,h=(n-e)*c-(o-i)*a,g=l/h,p=f/h,u=Math.abs(h)/(Math.hypot(a,c)*Math.abs(p-g));return{x0:e,x2:n,scale:u,cross:h}}subdivide(e){const i=this.mapToBasic(),r=_(i.x0),s=_(i.x2),n=.5*Math.abs(s-r)*Math.sqrt(i.scale/e),o=Math.ceil(n),a=B(r),c=B(s),l=[0];for(let f=1;f<o;f++){const g=(B(r+(s-r)*f/o)-a)/(c-a);l.push(g)}return l.push(1),l.map(f=>this.eval(f))}}class K{constructor(e){this.c=e}weightsum(e,i,r,s){const n=e*this.c[0]+i*this.c[2]+r*this.c[4]+s*this.c[6],o=e*this.c[1]+i*this.c[3]+r*this.c[5]+s*this.c[7];return{x:n,y:o}}eval(e){const i=1-e,r=i*i*i,s=3*i*i*e,n=3*i*e*e,o=e*e*e;return this.weightsum(r,s,n,o)}deriv(e){const i=1-e,r=-3*i*i,s=3*e*e,n=-6*e*i-r,o=6*e*i-s;return this.weightsum(r,n,o,s)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Qt({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,i){const r=new Float64Array(8),s=this.eval(e),n=this.eval(i);r[0]=s.x,r[1]=s.y;const o=(i-e)/3,a=this.deriv(e);r[2]=s.x+o*a.x,r[3]=s.y+o*a.y;const c=this.deriv(i);return r[4]=n.x-o*c.x,r[5]=n.y-o*c.y,r[6]=n.x,r[7]=n.y,new K(r)}subdivide(e){const i=.1*e,r=e-i,s=Math.sqrt(r),n=gi(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(n/(432*i*i),1/6)),a=[];let c=0;for(let u=0;u<o;u++){const m=u/o,v=(u+1)/o,x=this.subsegment(m,v).midpoint_quadbez(),d=x.mapToBasic(),y=_(d.x0),b=_(d.x2),w=Math.sqrt(d.scale);let S=Math.abs(b-y)*w;if(Math.sign(d.x0)!=Math.sign(d.x2)){const M=s/w,O=s*Math.abs(b-y)/_(M);S=Math.max(S,O)}a.push({quad:x,a0:y,a2:b,val:S}),c+=S}const l=.5*c/s,f=Math.ceil(l),h=[{x:this.c[0],y:this.c[1]}];let g=0,p=0;for(let u=1;u<f;u++){const m=c*u/f;for(;g+a[p].val<m;)g+=a[p].val,p++;const v=a[p].a0,x=a[p].a2,d=B(v),y=B(x),b=v+(x-v)*(m-g)/a[p].val,S=(B(b)-d)/(y-d);h.push(a[p].quad.eval(S))}return h.push({x:this.c[6],y:this.c[7]}),h}}const yi=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,mi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,dt=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function N(t,{domParser:e,svgPreprocessor:i}={}){var r,s;if(Array.isArray(t))return t.reduce((n,o)=>{const{selector:a,selectors:c}=N(o);return a&&(n.selector||(n.selector=a),n.selectors.push(...c)),n},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[n,o]=t.split("#");return o?N({type:"FragmentSelector",value:o}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:n,selectors:[n]}}if(t.type==="FragmentSelector"){const n=yi.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return{selector:a,selectors:[a]}}const o=t.value.match(mi);if(o){const a={type:"TemporalSelector",temporal:{startTime:o[4]?parseFloat(o[4]):0,endTime:o[7]?parseFloat(o[7]):void 0}};return{selector:a,selectors:[a]}}return{selector:null,selectors:[]}}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window!="undefined"?e=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let n=[],o,a,c=(r=i==null?void 0:i(t.value))!=null?r:t.value,l;if(e){const h=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!h)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const g=_t(h);g&&(n=g.points,l=g.shapeType,o=[Math.min(...n.map(p=>p[0])),Math.min(...n.map(p=>p[1])),Math.max(...n.map(p=>p[0])),Math.max(...n.map(p=>p[1]))],{style:a,svg:c}=(s=bi(g.element))!=null?s:{svg:c})}const f={type:"SvgSelector",svg:c,svgShape:l,style:a,points:n.length?n:void 0,spatial:o?{unit:"pixel",x:o[0],y:o[1],width:o[2]-o[0],height:o[3]-o[1]}:void 0};return{selector:f,selectors:[f]}}return{selector:null,selectors:[]}}function vi(t){const e=t.map(r=>r[0]).reduce((r,s)=>(r[s]+=1,r),{C:0,Q:0,L:0,M:0}),i=new Set(t.map(r=>r[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(i.size===1||i.size===2&&i.has("M"))){if(e.L===4)return"rect";const r=t.slice(-1)[0];return t[0][0]==="M"&&r[0]==="L"&&r[1]==t[0][1]&&r[2]===t[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function _t(t){var e,i,r,s,n,o,a,c,l,f,h,g,p,u,m,v,x;for(const d of Array.from(t.children))switch(d==null?void 0:d.tagName.toLowerCase()){case"g":{const y=_t(d);if(y)return y}continue;case"path":{const y=d.getAttribute("d");if(!y)continue;const b=hi(y);return{element:d,points:xi(b),shapeType:vi(b)}}case"circle":{const y=parseFloat((e=d.getAttribute("cx"))!=null?e:"0"),b=parseFloat((i=d.getAttribute("cy"))!=null?i:"0"),w=parseFloat((r=d.getAttribute("r"))!=null?r:"0");if(!w)continue;const S=[];for(let M=0;M<=360;M+=12){const O=M*Math.PI/180;S.push([y+w*Math.cos(O),b+w*Math.sin(O)])}return{element:d,points:S,shapeType:"circle"}}case"ellipse":{const y=parseFloat((s=d.getAttribute("cx"))!=null?s:"0"),b=parseFloat((n=d.getAttribute("cy"))!=null?n:"0"),w=parseFloat((o=d.getAttribute("rx"))!=null?o:"0"),S=parseFloat((a=d.getAttribute("ry"))!=null?a:"0");if(!w&&!S)continue;const M=[];for(let O=0;O<=360;O+=12){const C=Math.tan(O/360*Math.PI),I=w*(1-C**2)/(1+C**2),k=S*2*C/(1+C**2);M.push([y+I,b+k])}return{element:d,points:M,shapeType:"ellipse"}}case"line":{const y=parseFloat((c=d.getAttribute("x0"))!=null?c:"0"),b=parseFloat((l=d.getAttribute("y0"))!=null?l:"0"),w=parseFloat((f=d.getAttribute("x1"))!=null?f:"0"),S=parseFloat((h=d.getAttribute("y1"))!=null?h:"0");if(y===w&&b===S)continue;return{element:d,points:[[y,b],[w,S]],shapeType:"polyline"}}case"polygon":case"polyline":{const y=(p=(g=d.getAttribute("points"))==null?void 0:g.split(" ").map(w=>w.split(",").map(parseFloat)))!=null?p:[];if(!y.length)continue;let b="polyline";return d.tagName.toLowerCase()==="polygon"&&(y.push(y[0]),b="polygon"),{element:d,points:y,shapeType:b}}case"rect":{const y=parseFloat((u=d.getAttribute("x"))!=null?u:"0"),b=parseFloat((m=d.getAttribute("y"))!=null?m:"0"),w=parseFloat((v=d.getAttribute("width"))!=null?v:"0"),S=parseFloat((x=d.getAttribute("height"))!=null?x:"0");if(!w||!S)continue;return{element:d,points:[[y,b],[y+w,b],[y+w,b+S],[y,b+S],[y,b]],shapeType:"rect"}}default:continue}return null}function xi(t){var i;const e=[];for(let r=0;r<t.length;r++){const s=(i=e[e.length-1])!=null?i:[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...di({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(o=>[o.x,o.y]).slice(1));continue;case"Q":e.push(...pi({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(o=>[o.x,o.y]).slice(1));continue}}return e}function bi(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const r=dt.exec(e.fill);r&&(e.fillOpacity=parseFloat(r[4]),e.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const r=dt.exec(e.stroke);r&&(e.strokeOpacity=parseFloat(r[4]),e.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let i=t;for(;i.tagName.toLowerCase()!=="svg";)if(i=i.parentElement,i===null)throw new Error("Could not find root SVG element");return{svg:i.outerHTML,style:Object.keys(e).length>0?e:void 0}}function j(t,e={}){if(Array.isArray(t))return j(t[0]);if(typeof t=="string"){const[i,r]=t.split("#");return r?j({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:i,type:e.typeMap&&e.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return j(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:i,selectors:r}=t.selector?N(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:i,selectors:r}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[i,r]=t.id.split("#");return r?j({type:"SpecificResource",source:{...t,id:i},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...t,id:i},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Y(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const i=JSON.parse(t);return Y(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const i of t){const[r,s]=Y(i);if(!r&&s)return[r,s]}return[!0]}return t.type==="Annotation"?[!0]:e&&t.type==="Canvas"&&!t.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function wi(t){return Vt(typeof t=="string"?t:JSON.stringify(t))}function Nt(t,e){if(t=t.trim(),t[0]==="{")return e?Promise.resolve(JSON.parse(t)):JSON.parse(t);if(t.startsWith("http")){if(!e)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(t).then(i=>i.json())}return Nt(Et(t),e)}function Vt(t){const e=encodeURIComponent(t);return(typeof btoa=="undefined"?Buffer.from(e,"utf-8").toString("base64"):btoa(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Et(t){const i=Si(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function Si(t){const e=t.length%4;if(e===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return t+(e?"====".slice(0,4-e):"")}function Ai(t){if(!t)throw new Error("Content state is empty");Array.isArray(t)||(t=[t]);let e="vault://virtual-annotation/"+new Date().getTime();const i=[];for(const r of t){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(e=r.id,Array.isArray(r.motivation))for(const n of r.motivation);if(Array.isArray(r.target))for(const n of r.target){const o=j(n);i.push(o)}else{const n=j(r.target);i.push(n)}continue}const s=j(r);i.push(s)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:i,extensions:{}}}function Ut(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function Fi(t){function e(s){const n=s?typeof s=="string"?t.get(s):s:null;if(!n)return[];const o=t.get(n.items),a=[];for(const c of o)a.push(...t.get(c.items));return a}function i(s,n=[]){const o=Array.isArray(s)?s:e(s),a=[];let c=null;const l=[];for(const f of o){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const h=t.get(f.body);for(const g of h){const[p,{selector:u}]=Ut(g),m=(p.type||"unknown").toLowerCase();if(m==="choice"){const v=t.get(p.items),x=n.length?n.map(d=>v.find(y=>y.id===d)).filter(Boolean):[v[0]];x.length===0&&x.push(v[0]),c={type:"single-choice",items:v.map(d=>({id:d.id,label:d.label,selected:x.indexOf(d)!==-1})),label:g.label},h.push(...x);continue}a.indexOf(m)===-1&&a.push(m),l.push({type:m,resource:p,target:f.target,selector:u})}}return{types:a,items:l,choice:c}}function r(s){const{choice:n}=i(s);return n}return{getAllPaintingAnnotations:e,getPaintables:i,extractChoices:r}}function F(t,e,i){e[$]=e[$]||[],e[$].push(t),Object.defineProperty(e,t,{get(){if(typeof e[P][t]=="undefined")return;const r=e[P][t];return r&&R(i.get(e[P][t]),i)},set(r){e[P][t]!==r&&(this[P][t]=r)}})}const P=Symbol.for("_refs_"),q=Symbol.for("_reactive_"),$=Symbol.for("_defined_");function Mi(t,e=!1){const i={id:null,[$]:[],[P]:{},[q]:null,is(r){return typeof r=="string"?this.id===r:r.id?r.id===this.id:!1},reactive(){if(!this[q])return this[q]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const r=this.unwrap();for(const s of Object.keys(r||{}))this[$].includes(s)?this[P][s]=r[s]:this[s]=r[s]}},unreactive(){this[q]&&(this[q](),this[q]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");return t.get(this.id)},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},toJSON(){const r=this;return{...r,items:r.items,annotations:r.annotations,structures:r.structures,seeAlso:r.seeAlso,service:r.service,services:r.services,rendering:r.rendering,partOf:r.partOf,start:r.start,supplementary:r.supplementary,homepage:r.homepage,thumbnail:r.thumbnail,placeholderCanvas:r.placeholderCanvas,accompanyingCanvas:r.accompanyingCanvas,provider:r.provider}},subscribe(r,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,r,s)}};return F("items",i,t),F("annotations",i,t),F("structures",i,t),F("seeAlso",i,t),F("service",i,t),F("services",i,t),F("rendering",i,t),F("partOf",i,t),F("start",i,t),F("supplementary",i,t),F("homepage",i,t),F("thumbnail",i,t),F("placeholderCanvas",i,t),F("accompanyingCanvas",i,t),F("provider",i,t),F("body",i,t),F("logo",i,t),i}function Dt(t){return Array.isArray(t)?t.map(e=>Dt(e)):!t||!t.type?t:{id:t.id,type:t.type}}function R(t,e,i=!1){if(Array.isArray(t))return t.map(o=>R(o,e,i));if(!t||!t.type||!t.id)return t;const r=Mi(e,i),s=Object.create(r),n=Object.assign(s,t);return i&&n.reactive(),n}function Oi(t){return{get(e,i=!1){return R(t.get(e),t,i)},async load(e,i){return R(await t.load(e,i),t)},async loadManifest(e,i){return R(await t.loadManifest(e,i),t)},async loadCollection(e,i){return R(await t.loadCollection(e,i),t)},wrapObject(e){return R(t.get(e,{skipSelfReturn:!1}),t)},isWrapped(e){return!!e[$]}}}function Ci(t){return{findFirstCanvasFromRange:e=>tt(t,e),findAllCanvasesInRange:e=>V(t,e),findManifestSelectedRange:(e,i)=>Xt(t,e,i),findSelectedRange:(e,i)=>E(t,e,i)}}function tt(t,e){for(const i of e.items){if(i.type==="Canvas")return i;if(i.type==="Range"){const r=tt(t,t.get(i));if(r)return r}}return null}function V(t,e){const i=[];for(const r of e.items)if(r.type==="Canvas"&&(r.id.indexOf("#")!==-1?i.push({id:r.id.split("#")[0],type:"Canvas"}):i.push(r)),r.type==="Range"&&i.push(...V(t,t.get(r))),r.type==="SpecificResource"){const s=typeof r.source=="string"?r.source:r.source.id;i.push({id:s,type:"Canvas"})}return i}function Xt(t,e,i){for(const r of e.structures){const s=E(t,t.get(r),i);if(s)return s}return null}function E(t,e,i){var r;for(const s of e.items){const n=(r=s.id)==null?void 0:r.split("#")[0];if(s.type==="SpecificResource"&&s.source===i||s.type==="Canvas"&&i===n)return e;if(s.type==="Range"){const o=E(t,t.get(s),i);if(o)return o}}return null}function ki(t){return{getVisibleCanvasesFromCanvasId:(e,i,r=!1)=>Gt(t,e,i,r),getManifestSequence:(e,i={})=>et(t,e,i)}}function Gt(t,e,i,r=!1){const s=e.behavior,n=i?t.get(i):null;if(!n)return[];const o=n.behavior,a=r?!1:s.includes("paged"),c=a?!1:s.includes("continuous"),l=a||c?!1:s.includes("individuals"),f=o.includes("facing-pages"),h=o.includes("non-paged");if(f||h||l||r)return[{id:n.id,type:"Canvas"}];const[g,p]=et(t,e);if(c)return g;const u=g.findIndex(m=>m.id===i);if(u===-1)return[];for(const m of p)if(m.includes(u))return m.map(v=>g[v]);return[{id:n.id,type:"Canvas"}]}function et(t,e,{disablePaging:i,skipNonPaged:r}={}){const s=e.behavior,n=s.includes("paged"),o=n?!1:s.includes("continuous"),a=n||o?!1:s.includes("individuals"),c=e.type==="Manifest"?e.items:V(t,e);if(o)return[c,[c.map((u,m)=>m)]];if(a||!n||i)return[c,c.map((u,m)=>[m])];const l=[];let f=[];const h=()=>{f.length&&(l.push([...f]),f=[])};let g=0,p=!1;for(let u=0;u<c.length;u++){const m=t.get(c[u]);if(m.behavior.includes("non-paged")){u===g&&g++,r||(h(),l.push([u]),h());continue}if(u===g||m.behavior.includes("facing-pages")){f.length&&(p=!0),h(),l.push([u]),h();continue}if(f.push(u),p){h(),p=!1;continue}f.length>1&&h()}return f.length&&h(),[c,l]}exports.buildLocaleString=Lt;exports.createEventsHelper=ie;exports.createObjectsHelper=Oi;exports.createPaintingAnnotationsHelper=Fi;exports.createRangeHelper=Ci;exports.createSequenceHelper=ki;exports.createStylesHelper=re;exports.createThumbnailHelper=Ke;exports.decodeContentState=Et;exports.encodeContentState=Vt;exports.expandTarget=j;exports.findAllCanvasesInRange=V;exports.findFirstCanvasFromRange=tt;exports.findManifestSelectedRange=Xt;exports.findSelectedRange=E;exports.getClosestLanguage=Ht;exports.getManifestSequence=et;exports.getValue=ti;exports.getVisibleCanvasesFromCanvasId=Gt;exports.normaliseContentState=Ai;exports.parseContentState=Nt;exports.parseSelector=N;exports.parseSpecificResource=Ut;exports.serialiseContentState=wi;exports.unwrapObject=Dt;exports.validateContentState=Y;exports.wrapObject=R;
*/function wi(e,t,r,i=1){return new De(e,t,r).subdivide(i)}function Si(e,t,r,i,n=1){return new ne(new Float64Array([e.x,e.y,t.x,t.y,r.x,r.y,i.x,i.y])).subdivide(n)}function Ai(e){return e.x*e.x+e.y*e.y}function N(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function _(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class De{constructor(t,r,i){this.start=t,this.control=r,this.end=i}eval(t){const r=1-t;return{x:this.start.x*r*r+2*this.control.x*r*t+this.end.x*t*t,y:this.start.y*r*r+2*this.control.y*r*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:r}=this.start,{x:i,y:n}=this.control,{x:s,y:o}=this.end,a=2*i-t-s,c=2*n-r-o,u=(i-t)*a+(n-r)*c,f=(s-i)*a+(o-n)*c,p=(s-t)*c-(o-r)*a,h=u/p,g=f/p,l=Math.abs(p)/(Math.hypot(a,c)*Math.abs(g-h));return{x0:t,x2:s,scale:l,cross:p}}subdivide(t){const r=this.mapToBasic(),i=N(r.x0),n=N(r.x2),s=.5*Math.abs(n-i)*Math.sqrt(r.scale/t),o=Math.ceil(s),a=_(i),c=_(n),u=[0];for(let f=1;f<o;f++){const h=(_(i+(n-i)*f/o)-a)/(c-a);u.push(h)}return u.push(1),u.map(f=>this.eval(f))}}class ne{constructor(t){this.c=t}weightsum(t,r,i,n){const s=t*this.c[0]+r*this.c[2]+i*this.c[4]+n*this.c[6],o=t*this.c[1]+r*this.c[3]+i*this.c[5]+n*this.c[7];return{x:s,y:o}}eval(t){const r=1-t,i=r*r*r,n=3*r*r*t,s=3*r*t*t,o=t*t*t;return this.weightsum(i,n,s,o)}deriv(t){const r=1-t,i=-3*r*r,n=3*t*t,s=-6*t*r-i,o=6*t*r-n;return this.weightsum(i,s,o,n)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new De({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,r){const i=new Float64Array(8),n=this.eval(t),s=this.eval(r);i[0]=n.x,i[1]=n.y;const o=(r-t)/3,a=this.deriv(t);i[2]=n.x+o*a.x,i[3]=n.y+o*a.y;const c=this.deriv(r);return i[4]=s.x-o*c.x,i[5]=s.y-o*c.y,i[6]=s.x,i[7]=s.y,new ne(i)}subdivide(t){const r=.1*t,i=t-r,n=Math.sqrt(i),s=Ai(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(s/(432*r*r),1/6)),a=[];let c=0;for(let l=0;l<o;l++){const m=l/o,v=(l+1)/o,x=this.subsegment(m,v).midpoint_quadbez(),d=x.mapToBasic(),y=N(d.x0),b=N(d.x2),w=Math.sqrt(d.scale);let S=Math.abs(b-y)*w;if(Math.sign(d.x0)!=Math.sign(d.x2)){const M=n/w,C=n*Math.abs(b-y)/N(M);S=Math.max(S,C)}a.push({quad:x,a0:y,a2:b,val:S}),c+=S}const u=.5*c/n,f=Math.ceil(u),p=[{x:this.c[0],y:this.c[1]}];let h=0,g=0;for(let l=1;l<f;l++){const m=c*l/f;for(;h+a[g].val<m;)h+=a[g].val,g++;const v=a[g].a0,x=a[g].a2,d=_(v),y=_(x),b=v+(x-v)*(m-h)/a[g].val,S=(_(b)-d)/(y-d);p.push(a[g].quad.eval(S))}return p.push({x:this.c[6],y:this.c[7]}),p}}const Fi=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Mi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,xe=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function E(e,{domParser:t,svgPreprocessor:r,iiifRenderingHints:i}={}){var n,s;if(Array.isArray(e))return k(e.reduce((o,a)=>{const{selector:c,selectors:u,iiifRenderingHints:f}=E(a,{domParser:t,svgPreprocessor:r,iiifRenderingHints:i});return c&&(o.selector||(o.selector=c),o.selectors.push(...u)),f&&(o.iiifRenderingHints=o.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(o.iiifRenderingHints,f)),o},{selector:null,selectors:[],iiifRenderingHints:i}));if(!e)return k({selector:null,selectors:[],iiifRenderingHints:i});if(typeof e=="string"){const[o,a]=e.split("#");return a?E({type:"FragmentSelector",value:a},{svgPreprocessor:r,iiifRenderingHints:i,domParser:t}):k({selector:null,selectors:[],iiifRenderingHints:i})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const o={type:"TemporalSelector",temporal:{startTime:e.t}};return k({selector:o,selectors:[o],iiifRenderingHints:i})}if(Xe(e)){const o=[];if(e.region){const a=E({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:r,iiifRenderingHints:i});o.push(...a.selectors)}return k({selector:o[0],selectors:o,iiifRenderingHints:i?{...i,...e}:e})}if(e.type==="FragmentSelector"){const o=Fi.exec(e.value);if(o){const c={type:"BoxSelector",spatial:{unit:o[2]==="percent:"||o[2]==="pct:"?"percent":"pixel",x:parseFloat(o[3]),y:parseFloat(o[4]),width:parseFloat(o[5]),height:parseFloat(o[6])}};return k({selector:c,selectors:[c],iiifRenderingHints:i})}const a=e.value.match(Mi);if(a){const c={type:"TemporalSelector",temporal:{startTime:a[4]?parseFloat(a[4]):0,endTime:a[7]?parseFloat(a[7]):void 0}};return k({selector:c,selectors:[c],iiifRenderingHints:i})}return k({selector:null,selectors:[],iiifRenderingHints:i})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window!="undefined"?t=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let o=[],a,c,u=(n=r==null?void 0:r(e.value))!=null?n:e.value,f;if(t){const h=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!h)return console.warn(`Illegal SVG selector: ${e.value}`),k({selector:null,selectors:[],iiifRenderingHints:i});const g=Je(h);g&&(o=g.points,f=g.shapeType,a=[Math.min(...o.map(l=>l[0])),Math.min(...o.map(l=>l[1])),Math.max(...o.map(l=>l[0])),Math.max(...o.map(l=>l[1]))],{style:c,svg:u}=(s=ki(g.element))!=null?s:{svg:u})}const p={type:"SvgSelector",svg:u,svgShape:f,style:c,points:o.length?o:void 0,spatial:a?{unit:"pixel",x:a[0],y:a[1],width:a[2]-a[0],height:a[3]-a[1]}:void 0};return k({selector:p,selectors:[p],iiifRenderingHints:i})}return k({selector:null,selectors:[],iiifRenderingHints:i})}function Ci(e){const t=e.map(i=>i[0]).reduce((i,n)=>(i[n]+=1,i),{C:0,Q:0,L:0,M:0}),r=new Set(e.map(i=>i[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(t.L===4)return"rect";const i=e.slice(-1)[0];return e[0][0]==="M"&&i[0]==="L"&&i[1]==e[0][1]&&i[2]===e[0][2]||i[1]===0&&i[2]===0?"polygon":"polyline"}return"path"}function Je(e){var t,r,i,n,s,o,a,c,u,f,p,h,g,l,m,v,x;for(const d of Array.from(e.children))switch(d==null?void 0:d.tagName.toLowerCase()){case"g":{const y=Je(d);if(y)return y}continue;case"path":{const y=d.getAttribute("d");if(!y)continue;const b=bi(y);return{element:d,points:Oi(b),shapeType:Ci(b)}}case"circle":{const y=parseFloat((t=d.getAttribute("cx"))!=null?t:"0"),b=parseFloat((r=d.getAttribute("cy"))!=null?r:"0"),w=parseFloat((i=d.getAttribute("r"))!=null?i:"0");if(!w)continue;const S=[];for(let M=0;M<=360;M+=12){const C=M*Math.PI/180;S.push([y+w*Math.cos(C),b+w*Math.sin(C)])}return{element:d,points:S,shapeType:"circle"}}case"ellipse":{const y=parseFloat((n=d.getAttribute("cx"))!=null?n:"0"),b=parseFloat((s=d.getAttribute("cy"))!=null?s:"0"),w=parseFloat((o=d.getAttribute("rx"))!=null?o:"0"),S=parseFloat((a=d.getAttribute("ry"))!=null?a:"0");if(!w&&!S)continue;const M=[];for(let C=0;C<=360;C+=12){const O=Math.tan(C/360*Math.PI),z=w*(1-O**2)/(1+O**2),R=S*2*O/(1+O**2);M.push([y+z,b+R])}return{element:d,points:M,shapeType:"ellipse"}}case"line":{const y=parseFloat((c=d.getAttribute("x0"))!=null?c:"0"),b=parseFloat((u=d.getAttribute("y0"))!=null?u:"0"),w=parseFloat((f=d.getAttribute("x1"))!=null?f:"0"),S=parseFloat((p=d.getAttribute("y1"))!=null?p:"0");if(y===w&&b===S)continue;return{element:d,points:[[y,b],[w,S]],shapeType:"polyline"}}case"polygon":case"polyline":{const y=(g=(h=d.getAttribute("points"))==null?void 0:h.split(" ").map(w=>w.split(",").map(parseFloat)))!=null?g:[];if(!y.length)continue;let b="polyline";return d.tagName.toLowerCase()==="polygon"&&(y.push(y[0]),b="polygon"),{element:d,points:y,shapeType:b}}case"rect":{const y=parseFloat((l=d.getAttribute("x"))!=null?l:"0"),b=parseFloat((m=d.getAttribute("y"))!=null?m:"0"),w=parseFloat((v=d.getAttribute("width"))!=null?v:"0"),S=parseFloat((x=d.getAttribute("height"))!=null?x:"0");if(!w||!S)continue;return{element:d,points:[[y,b],[y+w,b],[y+w,b+S],[y,b+S],[y,b]],shapeType:"rect"}}default:continue}return null}function Oi(e){var r;const t=[];for(let i=0;i<e.length;i++){const n=(r=t[t.length-1])!=null?r:[0,0],s=e[i];switch(s[0]){case"M":case"L":t.push([s[1],s[2]]);continue;case"C":t.push(...Si({x:n[0],y:n[1]},{x:s[1],y:s[2]},{x:s[3],y:s[4]},{x:s[5],y:s[6]}).map(o=>[o.x,o.y]).slice(1));continue;case"Q":t.push(...wi({x:n[0],y:n[1]},{x:s[1],y:s[2]},{x:s[3],y:s[4]}).map(o=>[o.x,o.y]).slice(1));continue}}return t}function ki(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const i=xe.exec(t.fill);i&&(t.fillOpacity=parseFloat(i[4]),t.fill=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const i=xe.exec(t.stroke);i&&(t.strokeOpacity=parseFloat(i[4]),t.stroke=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let r=e;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(t).length>0?t:void 0}}function Xe(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function k(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const r=Ge(t.rotation);if(r)if(e.selectors.length)for(const i of e.selectors)i.rotation=r;else e.selectors.push({type:"RotationSelector",rotation:r})}}else delete e.iiifRenderingHints;return e}function Ge(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function T(e,t={}){if(Array.isArray(e))return T(e[0]);if(typeof e=="string"){const[r,i]=e.split("#");return i?T({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{id:r,type:t.typeMap&&t.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return T(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:r,selectors:i}=e.selector?E(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:i}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,i]=e.id.split("#");return i?T({type:"SpecificResource",source:{...e,id:r},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{...e,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function re(e,t=!1){if(typeof e=="string"){if(e.startsWith("{"))try{const r=JSON.parse(e);return re(r)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(e)){for(const r of e){const[i,n]=re(r);if(!i&&n)return[i,n]}return[!0]}return e.type==="Annotation"?[!0]:t&&e.type==="Canvas"&&!e.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function Ri(e){return Ze(typeof e=="string"?e:JSON.stringify(e))}function Ye(e,t){if(e=e.trim(),e[0]==="{")return t?Promise.resolve(JSON.parse(e)):JSON.parse(e);if(e.startsWith("http")){if(!t)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(e).then(r=>r.json())}return Ye(Ke(e),t)}function Ze(e){const t=encodeURIComponent(e);return(typeof btoa=="undefined"?Buffer.from(t,"utf-8").toString("base64"):btoa(t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Ke(e){const r=Ii(e).replace(/-/g,"+").replace(/_/g,"/"),i=typeof atob=="undefined"?Buffer.from(r,"base64").toString("utf-8"):atob(r);return decodeURIComponent(i).trim()}function Ii(e){const t=e.length%4;if(t===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return e+(t?"====".slice(0,4-t):"")}function ji(e){if(!e)throw new Error("Content state is empty");Array.isArray(e)||(e=[e]);let t="vault://virtual-annotation/"+new Date().getTime();const r=[];for(const i of e){if(typeof i=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(i.type==="Annotation"){if(t=i.id,Array.isArray(i.motivation))for(const s of i.motivation);if(Array.isArray(i.target))for(const s of i.target){const o=T(s);r.push(o)}else{const s=T(i.target);r.push(s)}continue}const n=T(i);r.push(n)}return{id:t,type:"Annotation",motivation:["contentState",...e.motivation||[]],target:r,extensions:{}}}function et(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Ti(e=I){function t(n){const s=n?typeof n=="string"?e.get(n):n:null;if(!s)return[];const o=e.get(s.items),a=[];for(const c of o)a.push(...e.get(c.items));return a}function r(n,s=[]){const o=Array.isArray(n)?n:t(n),a=[];let c=null;const u=[];for(const f of o){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const p=e.get(f.body),h=Array.isArray(p)?p:[p];for(const g of h){const[l,{selector:m}]=et(g),v=(l.type||"unknown").toLowerCase();if(v==="choice"){const x=e.get(l.items),d=s.length?s.map(y=>x.find(b=>b.id===y)).filter(Boolean):[x[0]];d.length===0&&d.push(x[0]),c={type:"single-choice",items:x.map(y=>({id:y.id,label:y.label,selected:d.indexOf(y)!==-1})),label:g.label},h.push(...d);continue}a.indexOf(v)===-1&&a.push(v),u.push({type:v,resource:l,target:f.target,selector:m})}}return{types:a,items:u,choice:c}}function i(n){const{choice:s}=r(n);return s}return{getAllPaintingAnnotations:t,getPaintables:r,extractChoices:i}}function F(e,t,r){t[Q]=t[Q]||[],t[Q].push(e),Object.defineProperty(t,e,{get(){if(typeof t[q][e]=="undefined")return;const i=t[q][e];return i&&j(r.get(t[q][e]),r)},set(i){t[q][e]!==i&&(this[q][e]=i)}})}const q=Symbol.for("_refs_"),L=Symbol.for("_reactive_"),Q=Symbol.for("_defined_");function zi(e,t=!1){const r={id:null,[Q]:[],[q]:{},[L]:null,is(i){return typeof i=="string"?this.id===i:i.id?i.id===this.id:!1},reactive(){if(!this[L])return this[L]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const i=this.unwrap();for(const n of Object.keys(i||{}))this[Q].includes(n)?this[q][n]=i[n]:this[n]=i[n]}},unreactive(){this[L]&&(this[L](),this[L]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");return e.get(this.id)},toPresentation3(){return e.toPresentation3(this.unwrap())},toPresentation2(){return e.toPresentation2(this.unwrap())},toJSON(){const i=this;return{...i,items:i.items,annotations:i.annotations,structures:i.structures,seeAlso:i.seeAlso,service:i.service,services:i.services,rendering:i.rendering,partOf:i.partOf,start:i.start,supplementary:i.supplementary,homepage:i.homepage,thumbnail:i.thumbnail,placeholderCanvas:i.placeholderCanvas,accompanyingCanvas:i.accompanyingCanvas,provider:i.provider}},subscribe(i,n=!0){return e.subscribe(()=>this.id?e.get(this.id):null,i,n)}};return F("items",r,e),F("annotations",r,e),F("structures",r,e),F("seeAlso",r,e),F("service",r,e),F("services",r,e),F("rendering",r,e),F("partOf",r,e),F("start",r,e),F("supplementary",r,e),F("homepage",r,e),F("thumbnail",r,e),F("placeholderCanvas",r,e),F("accompanyingCanvas",r,e),F("provider",r,e),F("body",r,e),F("logo",r,e),r}function tt(e){return Array.isArray(e)?e.map(t=>tt(t)):!e||!e.type?e:{id:e.id,type:e.type}}function j(e,t,r=!1){if(Array.isArray(e))return e.map(o=>j(o,t,r));if(!e||!e.type||!e.id)return e;const i=zi(t,r),n=Object.create(i),s=Object.assign(n,e);return r&&s.reactive(),s}function $i(e){return{get(t,r=!1){return j(e.get(t),e,r)},async load(t,r){return j(await e.load(t,r),e)},async loadManifest(t,r){return j(await e.loadManifest(t,r),e)},async loadCollection(t,r){return j(await e.loadCollection(t,r),e)},wrapObject(t){return j(e.get(t,{skipSelfReturn:!1}),e)},isWrapped(t){return!!t[Q]}}}function Wi(e=I){return{findFirstCanvasFromRange:t=>se(e,t),findAllCanvasesInRange:t=>X(e,t),findManifestSelectedRange:(t,r)=>it(e,t,r),findSelectedRange:(t,r)=>G(e,t,r)}}function se(e,t){for(const r of t.items){if(r.type==="Canvas")return r;if(r.type==="Range"){const i=se(e,e.get(r));if(i)return i}}return null}function X(e,t){const r=[];for(const i of t.items)if(i.type==="Canvas"&&(i.id.indexOf("#")!==-1?r.push({id:i.id.split("#")[0],type:"Canvas"}):r.push(i)),i.type==="Range"&&r.push(...X(e,e.get(i))),i.type==="SpecificResource"){const n=typeof i.source=="string"?i.source:i.source.id;r.push({id:n,type:"Canvas"})}return r}function it(e,t,r){for(const i of t.structures){const n=G(e,e.get(i),r);if(n)return n}return null}function G(e,t,r){var i;for(const n of t.items){const s=(i=n.id)==null?void 0:i.split("#")[0];if(n.type==="SpecificResource"&&n.source===r||n.type==="Canvas"&&r===s)return t;if(n.type==="Range"){const o=G(e,e.get(n),r);if(o)return o}}return null}function Bi(e=I){return{getVisibleCanvasesFromCanvasId:(t,r,i=!1)=>rt(e,t,r,i),getManifestSequence:(t,r={})=>oe(e,t,r)}}function rt(e=I,t,r,i=!1){const n=t.behavior||[],s=r?e.get(r):null;if(!s)return[];const o=s.behavior||[],a=i?!1:n.includes("paged"),c=a?!1:n.includes("continuous"),u=a||c?!1:n.includes("individuals"),f=o.includes("facing-pages"),p=o.includes("non-paged");if(f||p||u||i)return[{id:s.id,type:"Canvas"}];const[h,g]=oe(e,t);if(c)return h;const l=h.findIndex(m=>m.id===r);if(l===-1)return[];for(const m of g)if(m.includes(l))return m.map(v=>h[v]);return[{id:s.id,type:"Canvas"}]}function oe(e=I,t,{disablePaging:r,skipNonPaged:i}={}){const n=t.behavior||[],s=n.includes("paged"),o=s?!1:n.includes("continuous"),a=s||o?!1:n.includes("individuals"),c=t.type==="Manifest"?t.items:X(e,t);if(o)return[c,[c.map((l,m)=>m)]];if(a||!s||r)return[c,c.map((l,m)=>[m])];const u=[];let f=[];const p=()=>{f.length&&(u.push([...f]),f=[])};let h=0,g=!1;for(let l=0;l<c.length;l++){const v=e.get(c[l]).behavior||[];if(v.includes("non-paged")){l===h&&h++,i||(p(),u.push([l]),p());continue}if(l===h||v.includes("facing-pages")){f.length&&(g=!0),p(),u.push([l]),p();continue}if(f.push(l),g){p(),g=!1;continue}f.length>1&&p()}return f.length&&p(),[c,u]}exports.buildLocaleString=Ue;exports.createEventsHelper=ft;exports.createObjectsHelper=$i;exports.createPaintingAnnotationsHelper=Ti;exports.createRangeHelper=Wi;exports.createSequenceHelper=Bi;exports.createStylesHelper=ut;exports.createThumbnailHelper=ai;exports.decodeContentState=Ke;exports.encodeContentState=Ze;exports.expandTarget=T;exports.findAllCanvasesInRange=X;exports.findFirstCanvasFromRange=se;exports.findManifestSelectedRange=it;exports.findSelectedRange=G;exports.getClosestLanguage=Ee;exports.getManifestSequence=oe;exports.getValue=ci;exports.getVisibleCanvasesFromCanvasId=rt;exports.isImageApiSelector=Xe;exports.normaliseContentState=ji;exports.parseContentState=Ye;exports.parseRotation=Ge;exports.parseSelector=E;exports.parseSpecificResource=et;exports.serialiseContentState=Ri;exports.unwrapObject=tt;exports.validateContentState=re;exports.wrapObject=j;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var et=function(){function t(e,a){var r=[],o=!0,n=!1,s=void 0;try{for(var i=e[Symbol.iterator](),u;!(o=(u=i.next()).done)&&(r.push(u.value),!(a&&r.length===a));o=!0);}catch(f){n=!0,s=f}finally{try{!o&&i.return&&i.return()}finally{if(n)throw s}}return r}return function(e,a){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,a);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),q=Math.PI*2,z=function(e,a,r,o,n,s,i){var u=e.x,f=e.y;u*=a,f*=r;var h=o*u-n*f,y=n*u+o*f;return{x:h+s,y:y+i}},rt=function(e,a){var r=a===1.5707963267948966?.551915024494:a===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(a/4),o=Math.cos(e),n=Math.sin(e),s=Math.cos(e+a),i=Math.sin(e+a);return[{x:o-n*r,y:n+o*r},{x:s+i*r,y:i-s*r},{x:s,y:i}]},V=function(e,a,r,o){var n=e*o-a*r<0?-1:1,s=e*r+a*o;return s>1&&(s=1),s<-1&&(s=-1),n*Math.acos(s)},at=function(e,a,r,o,n,s,i,u,f,h,y,x){var d=Math.pow(n,2),c=Math.pow(s,2),w=Math.pow(y,2),b=Math.pow(x,2),g=d*c-d*b-c*w;g<0&&(g=0),g/=d*b+c*w,g=Math.sqrt(g)*(i===u?-1:1);var l=g*n/s*x,p=g*-s/n*y,v=h*l-f*p+(e+r)/2,m=f*l+h*p+(a+o)/2,A=(y-l)/n,M=(x-p)/s,S=(-y-l)/n,k=(-x-p)/s,F=V(1,0,A,M),C=V(A,M,S,k);return u===0&&C>0&&(C-=q),u===1&&C<0&&(C+=q),[v,m,F,C]},nt=function(e){var a=e.px,r=e.py,o=e.cx,n=e.cy,s=e.rx,i=e.ry,u=e.xAxisRotation,f=u===void 0?0:u,h=e.largeArcFlag,y=h===void 0?0:h,x=e.sweepFlag,d=x===void 0?0:x,c=[];if(s===0||i===0)return[];var w=Math.sin(f*q/360),b=Math.cos(f*q/360),g=b*(a-o)/2+w*(r-n)/2,l=-w*(a-o)/2+b*(r-n)/2;if(g===0&&l===0)return[];s=Math.abs(s),i=Math.abs(i);var p=Math.pow(g,2)/Math.pow(s,2)+Math.pow(l,2)/Math.pow(i,2);p>1&&(s*=Math.sqrt(p),i*=Math.sqrt(p));var v=at(a,r,o,n,s,i,y,d,w,b,g,l),m=et(v,4),A=m[0],M=m[1],S=m[2],k=m[3],F=Math.abs(k)/(q/4);Math.abs(1-F)<1e-7&&(F=1);var C=Math.max(Math.ceil(F),1);k/=C;for(var $=0;$<C;$++)c.push(rt(S,k)),S+=k;return c.map(function(R){var Q=z(R[0],s,i,b,w,A,M),H=Q.x,P=Q.y,D=z(R[1],s,i,b,w,A,M),Z=D.x,K=D.y,U=z(R[2],s,i,b,w,A,M),E=U.x,tt=U.y;return{x1:H,y1:P,x2:Z,y2:K,x:E,y:tt}})},st=it,_={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ot=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function it(t){var e=[];return t.replace(ot,function(a,r,o){var n=r.toLowerCase();for(o=lt(o),n=="m"&&o.length>2&&(e.push([r].concat(o.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(o.length==_[n])return o.unshift(r),e.push(o);if(o.length<_[n])throw new Error("malformed path data");e.push([r].concat(o.splice(0,_[n])))}}),e}var ct=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function lt(t){var e=t.match(ct);return e?e.map(Number):[]}var ut=pt;function pt(t){var e=0,a=0,r=0,o=0;return t.map(function(n){n=n.slice();var s=n[0],i=s.toUpperCase();if(s!=i)switch(n[0]=i,s){case"a":n[6]+=r,n[7]+=o;break;case"v":n[1]+=o;break;case"h":n[1]+=r;break;default:for(var u=1;u<n.length;)n[u++]+=r,n[u++]+=o}switch(i){case"Z":r=e,o=a;break;case"H":r=n[1];break;case"V":o=n[1];break;case"M":r=e=n[1],o=a=n[2];break;default:r=n[n.length-2],o=n[n.length-1]}return n})}function ft(t){const e=st(t),a=ut(e);let r,o=0,n=0,s=0,i=0,u,f,h=0,y=0;const x=[];for(let d=0;d<a.length;d++){let c=a[d];const w=c[0];switch(w){case"M":o=c[1],n=c[2];break;case"H":c=["L",c[1],n];break;case"V":c=["L",o,c[1]];break;case"S":{let b=h,g=y;(r==="C"||r=="S")&&(b+=b-s,g+=g-i),c=["C",b,g,c[1],c[2],c[3],c[4]]}break;case"T":r==="Q"||r=="T"?(u=h*2-u,f=y*2-f):(u=h,f=y),c=["Q",u,f,c[1],c[2]];break;case"Q":u=c[1],f=c[2];break;case"A":{const b=nt({px:h,py:y,cx:c[6],cy:c[7],rx:c[1],ry:c[2],xAxisRotation:c[3],largeArcFlag:c[4],sweepFlag:c[5]});if(!b.length)continue;for(const[g,l]of b.entries())c=["C",l.x1,l.y1,l.x2,l.y2,l.x,l.y],g<b.length-1&&x.push(c);c=c}break;case"Z":c=["L",o,n];break}r=w,h=c[c.length-2],y=c[c.length-1],["C","Q","A"].indexOf(w)>-1?(s=c[c.length-4],i=c[c.length-3]):(s=h,i=y),x.push(c)}return x}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var rt=function(){function t(e,n){var r=[],o=!0,s=!1,a=void 0;try{for(var i=e[Symbol.iterator](),u;!(o=(u=i.next()).done)&&(r.push(u.value),!(n&&r.length===n));o=!0);}catch(f){s=!0,a=f}finally{try{!o&&i.return&&i.return()}finally{if(s)throw a}}return r}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),L=Math.PI*2,_=function(e,n,r,o,s,a,i){var u=e.x,f=e.y;u*=n,f*=r;var h=o*u-s*f,y=s*u+o*f;return{x:h+a,y:y+i}},nt=function(e,n){var r=n===1.5707963267948966?.551915024494:n===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(n/4),o=Math.cos(e),s=Math.sin(e),a=Math.cos(e+n),i=Math.sin(e+n);return[{x:o-s*r,y:s+o*r},{x:a+i*r,y:i-a*r},{x:a,y:i}]},j=function(e,n,r,o){var s=e*o-n*r<0?-1:1,a=e*r+n*o;return a>1&&(a=1),a<-1&&(a=-1),s*Math.acos(a)},at=function(e,n,r,o,s,a,i,u,f,h,y,A){var d=Math.pow(s,2),c=Math.pow(a,2),w=Math.pow(y,2),x=Math.pow(A,2),b=d*c-d*x-c*w;b<0&&(b=0),b/=d*x+c*w,b=Math.sqrt(b)*(i===u?-1:1);var l=b*s/a*A,p=b*-a/s*y,v=h*l-f*p+(e+r)/2,g=f*l+h*p+(n+o)/2,m=(y-l)/s,M=(A-p)/a,S=(-y-l)/s,k=(-A-p)/a,T=j(1,0,m,M),F=j(m,M,S,k);return u===0&&F>0&&(F-=L),u===1&&F<0&&(F+=L),[v,g,T,F]},st=function(e){var n=e.px,r=e.py,o=e.cx,s=e.cy,a=e.rx,i=e.ry,u=e.xAxisRotation,f=u===void 0?0:u,h=e.largeArcFlag,y=h===void 0?0:h,A=e.sweepFlag,d=A===void 0?0:A,c=[];if(a===0||i===0)return[];var w=Math.sin(f*L/360),x=Math.cos(f*L/360),b=x*(n-o)/2+w*(r-s)/2,l=-w*(n-o)/2+x*(r-s)/2;if(b===0&&l===0)return[];a=Math.abs(a),i=Math.abs(i);var p=Math.pow(b,2)/Math.pow(a,2)+Math.pow(l,2)/Math.pow(i,2);p>1&&(a*=Math.sqrt(p),i*=Math.sqrt(p));var v=at(n,r,o,s,a,i,y,d,w,x,b,l),g=rt(v,4),m=g[0],M=g[1],S=g[2],k=g[3],T=Math.abs(k)/(L/4);Math.abs(1-T)<1e-7&&(T=1);var F=Math.max(Math.ceil(T),1);k/=F;for(var Q=0;Q<F;Q++)c.push(nt(S,k)),S+=k;return c.map(function(R){var D=_(R[0],a,i,x,w,m,M),K=D.x,H=D.y,U=_(R[1],a,i,x,w,m,M),P=U.x,E=U.y,V=_(R[2],a,i,x,w,m,M),tt=V.x,et=V.y;return{x1:K,y1:H,x2:P,y2:E,x:tt,y:et}})},ot=ct,B={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},it=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ct(t){var e=[];return t.replace(it,function(n,r,o){var s=r.toLowerCase();for(o=ut(o),s=="m"&&o.length>2&&(e.push([r].concat(o.splice(0,2))),s="l",r=r=="m"?"l":"L");;){if(o.length==B[s])return o.unshift(r),e.push(o);if(o.length<B[s])throw new Error("malformed path data");e.push([r].concat(o.splice(0,B[s])))}}),e}var lt=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ut(t){var e=t.match(lt);return e?e.map(Number):[]}var pt=ft;function ft(t){var e=0,n=0,r=0,o=0;return t.map(function(s){s=s.slice();var a=s[0],i=a.toUpperCase();if(a!=i)switch(s[0]=i,a){case"a":s[6]+=r,s[7]+=o;break;case"v":s[1]+=o;break;case"h":s[1]+=r;break;default:for(var u=1;u<s.length;)s[u++]+=r,s[u++]+=o}switch(i){case"Z":r=e,o=n;break;case"H":r=s[1];break;case"V":o=s[1];break;case"M":r=e=s[1],o=n=s[2];break;default:r=s[s.length-2],o=s[s.length-1]}return s})}function ht(t){const e=ot(t),n=pt(e);let r,o=0,s=0,a=0,i=0,u,f,h=0,y=0;const A=[];for(let d=0;d<n.length;d++){let c=n[d];const w=c[0];switch(w){case"M":o=c[1],s=c[2];break;case"H":c=["L",c[1],s];break;case"V":c=["L",o,c[1]];break;case"S":{let x=h,b=y;(r==="C"||r=="S")&&(x+=x-a,b+=b-i),c=["C",x,b,c[1],c[2],c[3],c[4]]}break;case"T":r==="Q"||r=="T"?(u=h*2-u,f=y*2-f):(u=h,f=y),c=["Q",u,f,c[1],c[2]];break;case"Q":u=c[1],f=c[2];break;case"A":{const x=st({px:h,py:y,cx:c[6],cy:c[7],rx:c[1],ry:c[2],xAxisRotation:c[3],largeArcFlag:c[4],sweepFlag:c[5]});if(!x.length)continue;for(const[b,l]of x.entries())c=["C",l.x1,l.y1,l.x2,l.y2,l.x,l.y],b<x.length-1&&A.push(c);c=c}break;case"Z":c=["L",o,s];break}r=w,h=c[c.length-2],y=c[c.length-1],["C","Q","A"].indexOf(w)>-1?(a=c[c.length-4],i=c[c.length-3]):(a=h,i=y),A.push(c)}return A}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
*

@@ -31,3 +31,3 @@ * All code in this module is based on JavaScript code by Raph Levien, published on his blog at

* limitations under the License.
*/function ht(t,e,a,r=1){return new j(t,e,a).subdivide(r)}function yt(t,e,a,r,o=1){return new N(new Float64Array([t.x,t.y,e.x,e.y,a.x,a.y,r.x,r.y])).subdivide(o)}function dt(t){return t.x*t.x+t.y*t.y}function L(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function O(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class j{constructor(e,a,r){this.start=e,this.control=a,this.end=r}eval(e){const a=1-e;return{x:this.start.x*a*a+2*this.control.x*a*e+this.end.x*e*e,y:this.start.y*a*a+2*this.control.y*a*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:a}=this.start,{x:r,y:o}=this.control,{x:n,y:s}=this.end,i=2*r-e-n,u=2*o-a-s,f=(r-e)*i+(o-a)*u,h=(n-r)*i+(s-o)*u,y=(n-e)*u-(s-a)*i,x=f/y,d=h/y,c=Math.abs(y)/(Math.hypot(i,u)*Math.abs(d-x));return{x0:e,x2:n,scale:c,cross:y}}subdivide(e){const a=this.mapToBasic(),r=L(a.x0),o=L(a.x2),n=.5*Math.abs(o-r)*Math.sqrt(a.scale/e),s=Math.ceil(n),i=O(r),u=O(o),f=[0];for(let h=1;h<s;h++){const x=(O(r+(o-r)*h/s)-i)/(u-i);f.push(x)}return f.push(1),f.map(h=>this.eval(h))}}class N{constructor(e){this.c=e}weightsum(e,a,r,o){const n=e*this.c[0]+a*this.c[2]+r*this.c[4]+o*this.c[6],s=e*this.c[1]+a*this.c[3]+r*this.c[5]+o*this.c[7];return{x:n,y:s}}eval(e){const a=1-e,r=a*a*a,o=3*a*a*e,n=3*a*e*e,s=e*e*e;return this.weightsum(r,o,n,s)}deriv(e){const a=1-e,r=-3*a*a,o=3*e*e,n=-6*e*a-r,s=6*e*a-o;return this.weightsum(r,n,s,o)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new j({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,a){const r=new Float64Array(8),o=this.eval(e),n=this.eval(a);r[0]=o.x,r[1]=o.y;const s=(a-e)/3,i=this.deriv(e);r[2]=o.x+s*i.x,r[3]=o.y+s*i.y;const u=this.deriv(a);return r[4]=n.x-s*u.x,r[5]=n.y-s*u.y,r[6]=n.x,r[7]=n.y,new N(r)}subdivide(e){const a=.1*e,r=e-a,o=Math.sqrt(r),n=dt(this.weightsum(1,-3,3,-1)),s=Math.ceil(Math.pow(n/(432*a*a),1/6)),i=[];let u=0;for(let c=0;c<s;c++){const w=c/s,b=(c+1)/s,g=this.subsegment(w,b).midpoint_quadbez(),l=g.mapToBasic(),p=L(l.x0),v=L(l.x2),m=Math.sqrt(l.scale);let A=Math.abs(v-p)*m;if(Math.sign(l.x0)!=Math.sign(l.x2)){const M=o/m,S=o*Math.abs(v-p)/L(M);A=Math.max(A,S)}i.push({quad:g,a0:p,a2:v,val:A}),u+=A}const f=.5*u/o,h=Math.ceil(f),y=[{x:this.c[0],y:this.c[1]}];let x=0,d=0;for(let c=1;c<h;c++){const w=u*c/h;for(;x+i[d].val<w;)x+=i[d].val,d++;const b=i[d].a0,g=i[d].a2,l=O(b),p=O(g),v=b+(g-b)*(w-x)/i[d].val,A=(O(v)-l)/(p-l);y.push(i[d].quad.eval(A))}return y.push({x:this.c[6],y:this.c[7]}),y}}const vt=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,xt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,X=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function B(t,{domParser:e,svgPreprocessor:a}={}){var r,o;if(Array.isArray(t))return t.reduce((n,s)=>{const{selector:i,selectors:u}=B(s);return i&&(n.selector||(n.selector=i),n.selectors.push(...u)),n},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[n,s]=t.split("#");return s?B({type:"FragmentSelector",value:s}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:n,selectors:[n]}}if(t.type==="FragmentSelector"){const n=vt.exec(t.value);if(n){const i={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return{selector:i,selectors:[i]}}const s=t.value.match(xt);if(s){const i={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return{selector:i,selectors:[i]}}return{selector:null,selectors:[]}}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window!="undefined"?e=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let n=[],s,i,u=(r=a==null?void 0:a(t.value))!=null?r:t.value,f;if(e){const y=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!y)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const x=W(y);x&&(n=x.points,f=x.shapeType,s=[Math.min(...n.map(d=>d[0])),Math.min(...n.map(d=>d[1])),Math.max(...n.map(d=>d[0])),Math.max(...n.map(d=>d[1]))],{style:i,svg:u}=(o=mt(x.element))!=null?o:{svg:u})}const h={type:"SvgSelector",svg:u,svgShape:f,style:i,points:n.length?n:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return{selector:h,selectors:[h]}}return{selector:null,selectors:[]}}function bt(t){const e=t.map(r=>r[0]).reduce((r,o)=>(r[o]+=1,r),{C:0,Q:0,L:0,M:0}),a=new Set(t.map(r=>r[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(a.size===1||a.size===2&&a.has("M"))){if(e.L===4)return"rect";const r=t.slice(-1)[0];return t[0][0]==="M"&&r[0]==="L"&&r[1]==t[0][1]&&r[2]===t[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function W(t){var e,a,r,o,n,s,i,u,f,h,y,x,d,c,w,b,g;for(const l of Array.from(t.children))switch(l==null?void 0:l.tagName.toLowerCase()){case"g":{const p=W(l);if(p)return p}continue;case"path":{const p=l.getAttribute("d");if(!p)continue;const v=ft(p);return{element:l,points:gt(v),shapeType:bt(v)}}case"circle":{const p=parseFloat((e=l.getAttribute("cx"))!=null?e:"0"),v=parseFloat((a=l.getAttribute("cy"))!=null?a:"0"),m=parseFloat((r=l.getAttribute("r"))!=null?r:"0");if(!m)continue;const A=[];for(let M=0;M<=360;M+=12){const S=M*Math.PI/180;A.push([p+m*Math.cos(S),v+m*Math.sin(S)])}return{element:l,points:A,shapeType:"circle"}}case"ellipse":{const p=parseFloat((o=l.getAttribute("cx"))!=null?o:"0"),v=parseFloat((n=l.getAttribute("cy"))!=null?n:"0"),m=parseFloat((s=l.getAttribute("rx"))!=null?s:"0"),A=parseFloat((i=l.getAttribute("ry"))!=null?i:"0");if(!m&&!A)continue;const M=[];for(let S=0;S<=360;S+=12){const k=Math.tan(S/360*Math.PI),F=m*(1-k**2)/(1+k**2),C=A*2*k/(1+k**2);M.push([p+F,v+C])}return{element:l,points:M,shapeType:"ellipse"}}case"line":{const p=parseFloat((u=l.getAttribute("x0"))!=null?u:"0"),v=parseFloat((f=l.getAttribute("y0"))!=null?f:"0"),m=parseFloat((h=l.getAttribute("x1"))!=null?h:"0"),A=parseFloat((y=l.getAttribute("y1"))!=null?y:"0");if(p===m&&v===A)continue;return{element:l,points:[[p,v],[m,A]],shapeType:"polyline"}}case"polygon":case"polyline":{const p=(d=(x=l.getAttribute("points"))==null?void 0:x.split(" ").map(m=>m.split(",").map(parseFloat)))!=null?d:[];if(!p.length)continue;let v="polyline";return l.tagName.toLowerCase()==="polygon"&&(p.push(p[0]),v="polygon"),{element:l,points:p,shapeType:v}}case"rect":{const p=parseFloat((c=l.getAttribute("x"))!=null?c:"0"),v=parseFloat((w=l.getAttribute("y"))!=null?w:"0"),m=parseFloat((b=l.getAttribute("width"))!=null?b:"0"),A=parseFloat((g=l.getAttribute("height"))!=null?g:"0");if(!m||!A)continue;return{element:l,points:[[p,v],[p+m,v],[p+m,v+A],[p,v+A],[p,v]],shapeType:"rect"}}default:continue}return null}function gt(t){var a;const e=[];for(let r=0;r<t.length;r++){const o=(a=e[e.length-1])!=null?a:[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...yt({x:o[0],y:o[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...ht({x:o[0],y:o[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function mt(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const r=X.exec(e.fill);r&&(e.fillOpacity=parseFloat(r[4]),e.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const r=X.exec(e.stroke);r&&(e.strokeOpacity=parseFloat(r[4]),e.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let a=t;for(;a.tagName.toLowerCase()!=="svg";)if(a=a.parentElement,a===null)throw new Error("Could not find root SVG element");return{svg:a.outerHTML,style:Object.keys(e).length>0?e:void 0}}function T(t,e={}){if(Array.isArray(t))return T(t[0]);if(typeof t=="string"){const[a,r]=t.split("#");return r?T({type:"SpecificResource",source:{id:a,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:a,type:e.typeMap&&e.typeMap[a]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return T(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:a,selectors:r}=t.selector?B(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:a,selectors:r}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[a,r]=t.id.split("#");return r?T({type:"SpecificResource",source:{...t,id:a},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...t,id:a},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function I(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const a=JSON.parse(t);return I(a)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const a of t){const[r,o]=I(a);if(!r&&o)return[r,o]}return[!0]}return t.type==="Annotation"?[!0]:e&&t.type==="Canvas"&&!t.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function At(t){return J(typeof t=="string"?t:JSON.stringify(t))}function G(t,e){if(t=t.trim(),t[0]==="{")return e?Promise.resolve(JSON.parse(t)):JSON.parse(t);if(t.startsWith("http")){if(!e)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(t).then(a=>a.json())}return G(Y(t),e)}function J(t){const e=encodeURIComponent(t);return(typeof btoa=="undefined"?Buffer.from(e,"utf-8").toString("base64"):btoa(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Y(t){const a=wt(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(a,"base64").toString("utf-8"):atob(a);return decodeURIComponent(r).trim()}function wt(t){const e=t.length%4;if(e===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return t+(e?"====".slice(0,4-e):"")}function Mt(t){if(!t)throw new Error("Content state is empty");Array.isArray(t)||(t=[t]);let e="vault://virtual-annotation/"+new Date().getTime();const a=[];for(const r of t){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(e=r.id,Array.isArray(r.motivation))for(const n of r.motivation);if(Array.isArray(r.target))for(const n of r.target){const s=T(n);a.push(s)}else{const n=T(r.target);a.push(n)}continue}const o=T(r);a.push(o)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:a,extensions:{}}}exports.decodeContentState=Y;exports.encodeContentState=J;exports.normaliseContentState=Mt;exports.parseContentState=G;exports.serialiseContentState=At;exports.validateContentState=I;
*/function yt(t,e,n,r=1){return new X(t,e,n).subdivide(r)}function vt(t,e,n,r,o=1){return new $(new Float64Array([t.x,t.y,e.x,e.y,n.x,n.y,r.x,r.y])).subdivide(o)}function dt(t){return t.x*t.x+t.y*t.y}function I(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function q(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class X{constructor(e,n,r){this.start=e,this.control=n,this.end=r}eval(e){const n=1-e;return{x:this.start.x*n*n+2*this.control.x*n*e+this.end.x*e*e,y:this.start.y*n*n+2*this.control.y*n*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:n}=this.start,{x:r,y:o}=this.control,{x:s,y:a}=this.end,i=2*r-e-s,u=2*o-n-a,f=(r-e)*i+(o-n)*u,h=(s-r)*i+(a-o)*u,y=(s-e)*u-(a-n)*i,A=f/y,d=h/y,c=Math.abs(y)/(Math.hypot(i,u)*Math.abs(d-A));return{x0:e,x2:s,scale:c,cross:y}}subdivide(e){const n=this.mapToBasic(),r=I(n.x0),o=I(n.x2),s=.5*Math.abs(o-r)*Math.sqrt(n.scale/e),a=Math.ceil(s),i=q(r),u=q(o),f=[0];for(let h=1;h<a;h++){const A=(q(r+(o-r)*h/a)-i)/(u-i);f.push(A)}return f.push(1),f.map(h=>this.eval(h))}}class ${constructor(e){this.c=e}weightsum(e,n,r,o){const s=e*this.c[0]+n*this.c[2]+r*this.c[4]+o*this.c[6],a=e*this.c[1]+n*this.c[3]+r*this.c[5]+o*this.c[7];return{x:s,y:a}}eval(e){const n=1-e,r=n*n*n,o=3*n*n*e,s=3*n*e*e,a=e*e*e;return this.weightsum(r,o,s,a)}deriv(e){const n=1-e,r=-3*n*n,o=3*e*e,s=-6*e*n-r,a=6*e*n-o;return this.weightsum(r,s,a,o)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new X({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,n){const r=new Float64Array(8),o=this.eval(e),s=this.eval(n);r[0]=o.x,r[1]=o.y;const a=(n-e)/3,i=this.deriv(e);r[2]=o.x+a*i.x,r[3]=o.y+a*i.y;const u=this.deriv(n);return r[4]=s.x-a*u.x,r[5]=s.y-a*u.y,r[6]=s.x,r[7]=s.y,new $(r)}subdivide(e){const n=.1*e,r=e-n,o=Math.sqrt(r),s=dt(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*n*n),1/6)),i=[];let u=0;for(let c=0;c<a;c++){const w=c/a,x=(c+1)/a,b=this.subsegment(w,x).midpoint_quadbez(),l=b.mapToBasic(),p=I(l.x0),v=I(l.x2),g=Math.sqrt(l.scale);let m=Math.abs(v-p)*g;if(Math.sign(l.x0)!=Math.sign(l.x2)){const M=o/g,S=o*Math.abs(v-p)/I(M);m=Math.max(m,S)}i.push({quad:b,a0:p,a2:v,val:m}),u+=m}const f=.5*u/o,h=Math.ceil(f),y=[{x:this.c[0],y:this.c[1]}];let A=0,d=0;for(let c=1;c<h;c++){const w=u*c/h;for(;A+i[d].val<w;)A+=i[d].val,d++;const x=i[d].a0,b=i[d].a2,l=q(x),p=q(b),v=x+(b-x)*(w-A)/i[d].val,m=(q(v)-l)/(p-l);y.push(i[d].quad.eval(m))}return y.push({x:this.c[6],y:this.c[7]}),y}}const xt=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,bt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,W=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function z(t,{domParser:e,svgPreprocessor:n,iiifRenderingHints:r}={}){var o,s;if(Array.isArray(t))return C(t.reduce((a,i)=>{const{selector:u,selectors:f,iiifRenderingHints:h}=z(i,{domParser:e,svgPreprocessor:n,iiifRenderingHints:r});return u&&(a.selector||(a.selector=u),a.selectors.push(...f)),h&&(a.iiifRenderingHints=a.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(a.iiifRenderingHints,h)),a},{selector:null,selectors:[],iiifRenderingHints:r}));if(!t)return C({selector:null,selectors:[],iiifRenderingHints:r});if(typeof t=="string"){const[a,i]=t.split("#");return i?z({type:"FragmentSelector",value:i},{svgPreprocessor:n,iiifRenderingHints:r,domParser:e}):C({selector:null,selectors:[],iiifRenderingHints:r})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const a={type:"TemporalSelector",temporal:{startTime:t.t}};return C({selector:a,selectors:[a],iiifRenderingHints:r})}if(wt(t)){const a=[];if(t.region){const i=z({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:n,iiifRenderingHints:r});a.push(...i.selectors)}return C({selector:a[0],selectors:a,iiifRenderingHints:r?{...r,...t}:t})}if(t.type==="FragmentSelector"){const a=xt.exec(t.value);if(a){const u={type:"BoxSelector",spatial:{unit:a[2]==="percent:"||a[2]==="pct:"?"percent":"pixel",x:parseFloat(a[3]),y:parseFloat(a[4]),width:parseFloat(a[5]),height:parseFloat(a[6])}};return C({selector:u,selectors:[u],iiifRenderingHints:r})}const i=t.value.match(bt);if(i){const u={type:"TemporalSelector",temporal:{startTime:i[4]?parseFloat(i[4]):0,endTime:i[7]?parseFloat(i[7]):void 0}};return C({selector:u,selectors:[u],iiifRenderingHints:r})}return C({selector:null,selectors:[],iiifRenderingHints:r})}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window!="undefined"?e=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let a=[],i,u,f=(o=n==null?void 0:n(t.value))!=null?o:t.value,h;if(e){const A=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!A)return console.warn(`Illegal SVG selector: ${t.value}`),C({selector:null,selectors:[],iiifRenderingHints:r});const d=G(A);d&&(a=d.points,h=d.shapeType,i=[Math.min(...a.map(c=>c[0])),Math.min(...a.map(c=>c[1])),Math.max(...a.map(c=>c[0])),Math.max(...a.map(c=>c[1]))],{style:u,svg:f}=(s=At(d.element))!=null?s:{svg:f})}const y={type:"SvgSelector",svg:f,svgShape:h,style:u,points:a.length?a:void 0,spatial:i?{unit:"pixel",x:i[0],y:i[1],width:i[2]-i[0],height:i[3]-i[1]}:void 0};return C({selector:y,selectors:[y],iiifRenderingHints:r})}return C({selector:null,selectors:[],iiifRenderingHints:r})}function gt(t){const e=t.map(r=>r[0]).reduce((r,o)=>(r[o]+=1,r),{C:0,Q:0,L:0,M:0}),n=new Set(t.map(r=>r[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(n.size===1||n.size===2&&n.has("M"))){if(e.L===4)return"rect";const r=t.slice(-1)[0];return t[0][0]==="M"&&r[0]==="L"&&r[1]==t[0][1]&&r[2]===t[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function G(t){var e,n,r,o,s,a,i,u,f,h,y,A,d,c,w,x,b;for(const l of Array.from(t.children))switch(l==null?void 0:l.tagName.toLowerCase()){case"g":{const p=G(l);if(p)return p}continue;case"path":{const p=l.getAttribute("d");if(!p)continue;const v=ht(p);return{element:l,points:mt(v),shapeType:gt(v)}}case"circle":{const p=parseFloat((e=l.getAttribute("cx"))!=null?e:"0"),v=parseFloat((n=l.getAttribute("cy"))!=null?n:"0"),g=parseFloat((r=l.getAttribute("r"))!=null?r:"0");if(!g)continue;const m=[];for(let M=0;M<=360;M+=12){const S=M*Math.PI/180;m.push([p+g*Math.cos(S),v+g*Math.sin(S)])}return{element:l,points:m,shapeType:"circle"}}case"ellipse":{const p=parseFloat((o=l.getAttribute("cx"))!=null?o:"0"),v=parseFloat((s=l.getAttribute("cy"))!=null?s:"0"),g=parseFloat((a=l.getAttribute("rx"))!=null?a:"0"),m=parseFloat((i=l.getAttribute("ry"))!=null?i:"0");if(!g&&!m)continue;const M=[];for(let S=0;S<=360;S+=12){const k=Math.tan(S/360*Math.PI),T=g*(1-k**2)/(1+k**2),F=m*2*k/(1+k**2);M.push([p+T,v+F])}return{element:l,points:M,shapeType:"ellipse"}}case"line":{const p=parseFloat((u=l.getAttribute("x0"))!=null?u:"0"),v=parseFloat((f=l.getAttribute("y0"))!=null?f:"0"),g=parseFloat((h=l.getAttribute("x1"))!=null?h:"0"),m=parseFloat((y=l.getAttribute("y1"))!=null?y:"0");if(p===g&&v===m)continue;return{element:l,points:[[p,v],[g,m]],shapeType:"polyline"}}case"polygon":case"polyline":{const p=(d=(A=l.getAttribute("points"))==null?void 0:A.split(" ").map(g=>g.split(",").map(parseFloat)))!=null?d:[];if(!p.length)continue;let v="polyline";return l.tagName.toLowerCase()==="polygon"&&(p.push(p[0]),v="polygon"),{element:l,points:p,shapeType:v}}case"rect":{const p=parseFloat((c=l.getAttribute("x"))!=null?c:"0"),v=parseFloat((w=l.getAttribute("y"))!=null?w:"0"),g=parseFloat((x=l.getAttribute("width"))!=null?x:"0"),m=parseFloat((b=l.getAttribute("height"))!=null?b:"0");if(!g||!m)continue;return{element:l,points:[[p,v],[p+g,v],[p+g,v+m],[p,v+m],[p,v]],shapeType:"rect"}}default:continue}return null}function mt(t){var n;const e=[];for(let r=0;r<t.length;r++){const o=(n=e[e.length-1])!=null?n:[0,0],s=t[r];switch(s[0]){case"M":case"L":e.push([s[1],s[2]]);continue;case"C":e.push(...vt({x:o[0],y:o[1]},{x:s[1],y:s[2]},{x:s[3],y:s[4]},{x:s[5],y:s[6]}).map(a=>[a.x,a.y]).slice(1));continue;case"Q":e.push(...yt({x:o[0],y:o[1]},{x:s[1],y:s[2]},{x:s[3],y:s[4]}).map(a=>[a.x,a.y]).slice(1));continue}}return e}function At(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const r=W.exec(e.fill);r&&(e.fillOpacity=parseFloat(r[4]),e.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const r=W.exec(e.stroke);r&&(e.strokeOpacity=parseFloat(r[4]),e.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let n=t;for(;n.tagName.toLowerCase()!=="svg";)if(n=n.parentElement,n===null)throw new Error("Could not find root SVG element");return{svg:n.outerHTML,style:Object.keys(e).length>0?e:void 0}}function wt(t){return!!t&&t.type==="iiif:ImageApiSelector"&&t.type==="iiif:ImageApiSelector"}function C(t){if(t.iiifRenderingHints){const e=t.iiifRenderingHints;if(e.rotation){const n=Mt(e.rotation);if(n)if(t.selectors.length)for(const r of t.selectors)r.rotation=n;else t.selectors.push({type:"RotationSelector",rotation:n})}}else delete t.iiifRenderingHints;return t}function Mt(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function O(t,e={}){if(Array.isArray(t))return O(t[0]);if(typeof t=="string"){const[n,r]=t.split("#");return r?O({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:e.typeMap&&e.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return O(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=t.selector?z(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:n,selectors:r}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[n,r]=t.id.split("#");return r?O({type:"SpecificResource",source:{...t,id:n},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...t,id:n},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function N(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const n=JSON.parse(t);return N(n)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const n of t){const[r,o]=N(n);if(!r&&o)return[r,o]}return[!0]}return t.type==="Annotation"?[!0]:e&&t.type==="Canvas"&&!t.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function St(t){return Y(typeof t=="string"?t:JSON.stringify(t))}function J(t,e){if(t=t.trim(),t[0]==="{")return e?Promise.resolve(JSON.parse(t)):JSON.parse(t);if(t.startsWith("http")){if(!e)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(t).then(n=>n.json())}return J(Z(t),e)}function Y(t){const e=encodeURIComponent(t);return(typeof btoa=="undefined"?Buffer.from(e,"utf-8").toString("base64"):btoa(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Z(t){const n=kt(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(n,"base64").toString("utf-8"):atob(n);return decodeURIComponent(r).trim()}function kt(t){const e=t.length%4;if(e===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return t+(e?"====".slice(0,4-e):"")}function Ct(t){if(!t)throw new Error("Content state is empty");Array.isArray(t)||(t=[t]);let e="vault://virtual-annotation/"+new Date().getTime();const n=[];for(const r of t){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(e=r.id,Array.isArray(r.motivation))for(const s of r.motivation);if(Array.isArray(r.target))for(const s of r.target){const a=O(s);n.push(a)}else{const s=O(r.target);n.push(s)}continue}const o=O(r);n.push(o)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:n,extensions:{}}}exports.decodeContentState=Z;exports.encodeContentState=Y;exports.normaliseContentState=Ct;exports.parseContentState=J;exports.serialiseContentState=St;exports.validateContentState=N;
//# sourceMappingURL=content-state.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function u(a){return{addEventListener(t,n,e,r){if(!!t)return a.setMetaValue([t.id,"eventManager",n],o=>{const s=o||[];for(const c of s)if(c.callback===e)return s;return[...s,{callback:e,scope:r}]}),e},removeEventListener(t,n,e){!t||a.setMetaValue([t.id,"eventManager",n],r=>(r||[]).filter(o=>o.callback!==e))},getListenersAsProps(t,n){const e=typeof t=="string"?{id:t}:t;if(!e||!e.id)return{};const r=a.getResourceMeta(e.id,"eventManager"),o={};if(r&&e)for(const s of Object.keys(r))o[s]=c=>{const f=a.get(e);for(const{callback:l,scope:i}of r[s]||[])(!i||n&&i.indexOf(n)!==-1)&&l(c,f)};return o}}}exports.createEventsHelper=u;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a={},f={get(n){return n},setMetaValue([n,e,r],t){const o=f.getResourceMeta(n,e),s=o?o[r]:void 0,c=typeof t=="function"?t(s):t;a[n]={...a[n]||{},[e]:{...(a[n]||{})[e]||{},[r]:c}}},getResourceMeta:(n,e)=>{const r=a[n];if(!!r)return e?r[e]:r}};function M(n=f){return{addEventListener(e,r,t,o){if(!!e)return n.setMetaValue([e.id,"eventManager",r],s=>{const c=s||[];for(const u of c)if(u.callback===t)return c;return[...c,{callback:t,scope:o}]}),t},removeEventListener(e,r,t){!e||n.setMetaValue([e.id,"eventManager",r],o=>(o||[]).filter(s=>s.callback!==t))},getListenersAsProps(e,r){const t=typeof e=="string"?{id:e}:e;if(!t||!t.id)return{};const o=n.getResourceMeta(t.id,"eventManager"),s={};if(o&&t)for(const c of Object.keys(o))s[c]=u=>{const l=n.get(t);for(const{callback:g,scope:i}of o[c]||[])(!i||r&&i.indexOf(r)!==-1)&&g(u,l)};return s}}}exports.createEventsHelper=M;
//# sourceMappingURL=events.js.map

@@ -1,3 +0,3 @@

(function(x,L){typeof exports=="object"&&typeof module!="undefined"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(x=typeof globalThis!="undefined"?globalThis:x||self,L(x.VaultHelpers={}))})(this,function(x){"use strict";function L(t){return{addEventListener(e,i,r,s){if(!!e)return t.setMetaValue([e.id,"eventManager",i],n=>{const o=n||[];for(const a of o)if(a.callback===r)return o;return[...o,{callback:r,scope:s}]}),r},removeEventListener(e,i,r){!e||t.setMetaValue([e.id,"eventManager",i],s=>(s||[]).filter(n=>n.callback!==r))},getListenersAsProps(e,i){const r=typeof e=="string"?{id:e}:e;if(!r||!r.id)return{};const s=t.getResourceMeta(r.id,"eventManager"),n={};if(s&&r)for(const o of Object.keys(s))n[o]=a=>{const c=t.get(r);for(const{callback:l,scope:f}of s[o]||[])(!f||i&&f.indexOf(i)!==-1)&&l(a,c)};return n}}}function Zt(t){return{applyStyles(e,i,r){const s=typeof e=="string"?e:e.id;return t.setMetaValue([s,"styles",i],r)},getAppliedStyles(e){const i=typeof e=="string"?e:e.id;return t.getResourceMeta(i,"styles")}}}function T(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const Kt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",nt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",st="http://library.stanford.edu/iiif/image-api/compliance.html#level2",te="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ot="http://library.stanford.edu/iiif/image-api/conformance.html#level1",at="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ee="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",ct="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",lt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ie="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",ft="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ut="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",re="http://iiif.io/api/image/1/level0.json",ne="http://iiif.io/api/image/1/profiles/level0.json",ht="http://iiif.io/api/image/1/level1.json",pt="http://iiif.io/api/image/1/profiles/level1.json",dt="http://iiif.io/api/image/1/level2.json",gt="http://iiif.io/api/image/1/profiles/level2.json",se="http://iiif.io/api/image/2/level0.json",oe="http://iiif.io/api/image/2/profiles/level0.json",yt="http://iiif.io/api/image/2/level1.json",mt="http://iiif.io/api/image/2/profiles/level1.json",vt="http://iiif.io/api/image/2/level2.json",xt="http://iiif.io/api/image/2/profiles/level2.json",ae="level0",bt="level1",wt="level2",ce="http://iiif.io/api/image/2/level0",St="http://iiif.io/api/image/2/level1",At="http://iiif.io/api/image/2/level2",Ft=[At,st,at,lt,ut,dt,gt,vt,xt,wt],Mt=[...Ft,St,nt,ot,ct,ft,ht,pt,yt,mt,bt],le=[ce,St,At,Kt,nt,st,te,ot,at,ee,ct,lt,ie,ft,ut,re,ne,ht,pt,dt,gt,se,oe,yt,mt,vt,xt,ae,bt,wt],fe={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},ue={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},he={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function pe(t){return Ft.indexOf(t)!==-1?he:Mt.indexOf(t)!==-1?ue:fe}function de(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=pe(r)),!!r){if(r.formats)for(const s of r.formats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.qualities)for(const s of r.qualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.supports)for(const s of r.supports)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const s of r.extraFormats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.extraQualities)for(const s of r.extraQualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.extraFeatures)for(const s of r.extraFeatures)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(t.extraFormats)for(const r of t.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(t.extraFeatures)for(const r of t.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(t.extraQualities)for(const r of t.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function ge(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),i=t.substr(e?4:0).split(",").map(r=>parseFloat(r));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function ye(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const i=t.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(e.width=parseInt(i[0],10)),i[1]!==""&&(e.height=parseInt(i[1],10))),e}function me(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function ve(t,e=""){const i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);const r=i[2],s=i[3];let n=i[4];if(n[0]==="/"&&(n=n.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==n.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${e})`);n=n.substr(e.length)}return{scheme:r,server:s,path:n,prefix:e}}function xe(t,e=""){const{path:i,scheme:r,server:s,prefix:n}=ve(t,e),o=i.split("/").reverse(),[a,c,l,f,...h]=o,g=h.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:r,server:s,prefix:n,identifier:g};if(a==="info.json"){const[,...u]=o;return{type:"info",scheme:r,server:s,prefix:n,identifier:u.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:r,server:s,prefix:n,identifier:g,originalPath:i,region:ge(f),size:ye(l),rotation:me(c),quality:p[0],format:p[1]}}function be(t){const e=xe(T(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const i=de(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function we(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n].width;s.push(t/o)}return s}function Se(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n];s.push({width:Math.floor(t/o),height:Math.floor(e/o)})}return s}function F(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function X(t){if(!t||!t.profile||!F(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"&&le.indexOf(i)!==-1)return!0;return!1}function Ae(t){if(!X(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(Mt.indexOf(i)!==-1)return!0}else{const r=[...i.supports||[],...i.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return!0}return!1}function Fe(t){if(!Ae(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],r=i.length;for(let s=0;s<r;s++){const n=i[s];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return[{id:F(t),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(t.tiles){const s=t.tiles.length;for(let n=0;n<s;n++){const o=t.tiles[n];(o.height||o.width)&&e.push({id:F(t),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width})}}return e}function Ot(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=t.match(e);if(i){const r=i[1],s=parseInt(i[4],10),n=parseInt(i[5],10),o=i[7];if((r==="max"||r==="full")&&s&&n&&o)return{type:"fixed",id:t,height:n,width:s}}return{type:"unknown",id:t}}function Me(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function G(t){if(typeof t=="string")return Ot(t);const e=Me(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,r=F(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:Ot(r):null}function Oe(t){return X(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:F(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Ct(t){const e=[],i=t.length;for(let r=0;r<i;r++){const s=Oe(t[r]);s.length&&e.push(...s);const n=Fe(t[r]);n.length&&e.push(...n)}return e}function kt(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,r=[];for(let s=0;s<i;s++)X(e[s])&&r.push(e[s]);return r}function Ce(t,e=!0,i){const r=[],s=G(t);if(s===null)return r;const n=t;if(r.push(s),e&&n.width&&n.height){const o=[],a=kt(n);for(const c of a){const l={id:F(c),width:n.width,height:n.height};if(i.canLoadSync(l)){const f=i.loadServiceSync(l);f&&(f.height||(f.height=n.height),f.width||(f.width=n.width),o.push(...Ct([f])))}}if(o.length)return r.push(...o),r}return n.service&&r.push(...Ct(n.service)),r}function ke({x:t=0,y:e=0,w:i,h:r,full:s,square:n,percent:o}){if(s)return"full";if(n)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const a=`${t},${e},${i},${r}`;return o?`pct:${a}`:a}function Re({max:t,percentScale:e,upscaled:i,confined:r,width:s,height:n,serialiseAsFull:o}){const a=[];return i&&a.push("^"),t?(a.push(o?"full":"max"),a.join("")):(r&&a.push("!"),e&&a.push(`pct:${e}`),s&&a.push(`${s}`),a.push(","),n&&a.push(`${n}`),a.join(""))}function je(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Ie=Object.defineProperty,Te=Object.defineProperties,ze=Object.getOwnPropertyDescriptors,Rt=Object.getOwnPropertySymbols,Pe=Object.prototype.hasOwnProperty,We=Object.prototype.propertyIsEnumerable,jt=(t,e,i)=>e in t?Ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Q=(t,e)=>{for(var i in e||(e={}))Pe.call(e,i)&&jt(t,i,e[i]);if(Rt)for(var i of Rt(e))We.call(e,i)&&jt(t,i,e[i]);return t},_=(t,e)=>Te(t,ze(e));function qe(t,e){const i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,r=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if(t.type==="base")return r;if(t.type==="info")return`${r}/info.json`;let{region:s,size:n,rotation:o,format:a,quality:c}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,h=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((n.width===e.width&&!n.height||n.height===e.height&&!n.width||n.width===e.width&&n.height===e.height)&&(n=_(Q({},n),{max:!0})),f&&(n.max&&!n.serialiseAsFull&&(n=_(Q({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=_(Q({},n),{height:void 0}))),h&&(n.max&&n.serialiseAsFull&&(n=_(Q({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const g=e.height/e.width;n=_(Q({},n),{height:Math.ceil(n.width*g)})}}return[r,ke(s),Re(n),je(o),`${c}.${a}`].filter(Boolean).join("/")}function J(t,e,i){const r=be({id:T(F(t)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=e,r.size.height=i,{id:qe(r),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function q(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Be(t,e,i){const r=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-r)<Math.abs(e.width-r))}function He(t,e){const i=[],r=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),s=[],n=[];let o=null;const a=(l,f)=>{if(Be(r,f,l)){if(r.preferFixedSize&&l.unsafe){n.push(l);return}r.returnAllOptions&&f&&n.push(f),o=l}else r.returnAllOptions&&n.push(l)},c=e.length;for(let l=0;l<c;l++){const f=e[l](),h=f.length;for(let g=0;g<h;g++){const p=f[g];if(p.type==="unknown"&&r.atAnyCost&&s.push(p),p.type==="fixed"&&(p.unsafe?s.push(p):a(p,o)),p.type==="fixed-service")if(r.unsafeImageService){const u=J(p,r.width,r.height);a(u,o)}else{const u=J(p,p.width,p.height);a(u,o)}if(p.type==="variable"&&p.maxWidth){const u=J({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);a(u,o)}}if(o&&!r.returnAllOptions){if(o.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:o||s[0],fallback:s.slice(1),log:i}:r.returnAllOptions?{best:r.atAnyCost?o||n[0]||s[0]:o||n[0],fallback:[...n,...s],log:i}:{best:o||n[0]||null,fallback:o?n:n.slice(1),log:i}}var $e=Object.defineProperty,Le=Object.defineProperties,Qe=Object.getOwnPropertyDescriptors,It=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,Tt=(t,e,i)=>e in t?$e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ne=(t,e)=>{for(var i in e||(e={}))_e.call(e,i)&&Tt(t,i,e[i]);if(It)for(var i of It(e))Ve.call(e,i)&&Tt(t,i,e[i]);return t},Ee=(t,e)=>Le(t,Qe(e));function Ue(t,e,i){const r=t>e?t:e,s=i.length,n=[];for(let o=0;o<s;o++){const a=i[o];let c=a.scaleFactors[0],l=r/c;const f=[c];for(;l>=a.width;)c=c*2,f.push(c),l=l/2;n.push(Ee(Ne({},a),{scaleFactors:f}))}return n}function De(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const i=t.length;let r=!0;for(let n=0;n<i;n++){const o=t[n],a=e[n];if(o.width!==a.width||o.height!==a.height){r=!1;break}}if(r)return!0;let s=0;for(let n=0;n<i;n++)for(let o=0;o<i;o++)if(t[n].width===e[o].width&&t[n].height===e[o].height){s++;break}return s===i}function zt(t){if(t&&t.profile){const e=t.profile;if(e){const i=Array.isArray(e)?e:[e];return i.includes("level0")||i.includes("http://iiif.io/api/image/2/level0.json")||i.includes("http://iiif.io/api/image/1/level0.json")||i.includes("http://iiif.io/api/image/1/profiles/level0.json")}}return!1}var z=(t,e,i)=>new Promise((r,s)=>{var n=c=>{try{a(i.next(c))}catch(l){s(l)}},o=c=>{try{a(i.throw(c))}catch(l){s(l)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(n,o);a((i=i.apply(t,e)).next())});class Pt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,i,r=!0){const s=q(F(e)),n=T(F(e)),o=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),!o&&e.tiles&&!zt(e)?(this.knownImageServers[s]={verifications:0,malformed:!1,root:s,preLoaded:r,sampledId:F(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:i&&e.height?i.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:we(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0):this.verify(e)}preLoad(e,i=!0){this.knownImageServers[e.root]=e,i&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,i=!1,r=!1){const s=e==null?void 0:e.source,n=q(F(e)),o=this.knownImageServers[n];if(!o||!o.result||!r&&(o.malformed||o.verifications<this.config.verificationsRequired)||zt(e.source))return null;const a=T(F(e));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":F(e),id:F(e),protocol:"http://iiif.io/api/image",tiles:(s==null?void 0:s.tiles)||Ue(e.width,e.height,o.result.sampledTiles),sizes:(s==null?void 0:s.sizes)||Se(Math.round(e.width/o.result.resourceServiceRatio),Math.round(e.height/o.result.resourceServiceRatio),o.result.sizeRatios),profile:(s==null?void 0:s.profile)||o.result.sampledProfile,height:(s==null?void 0:s.height)||e.height,width:(s==null?void 0:s.width)||e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,i){return z(this,arguments,function*(r,s,n=!0,o=[]){const a=yield this.getImageCandidates(r,n);return He(s,[()=>o,()=>a])})}getImageCandidates(e,i=!0){return z(this,null,function*(){const r=e;if(i&&r.height&&r.width){const s=kt(r);for(const n of s){const o={id:F(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(o)}}return Ce(e,i,this)})}verify(e){return z(this,null,function*(){const i=this.predict(e,!1,!0),r=yield this.fetchService(F(e));if(!i)return!1;const s=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&De(i.sizes||[],r.sizes||[]);if(s){const n=q(F(e));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0)}return s})}canLoadSync(e){const i=typeof e=="string"?e:F(e),r=T(i);if(this.imageServices[r])return!0;const s=this.knownImageServers[q(i)];return s&&!s.malformed&&s.verifications>=this.config.verificationsRequired}markAsMalformed(e){return z(this,null,function*(){return this.knownImageServers[q(F(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return z(this,null,function*(){const r=T(e);if(this.imageServices[r]&&(!i||this.imageServices[r].real))return this.imageServices[r];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const s=yield this.fetch(r).then(n=>n.json());return!s.id&&s["@id"]&&(s.id=s["@id"]),s.id!==e&&(s.id=e,s["@id"]&&(s["@id"]=e)),this.imageServices[r]=Object.assign(s,{real:!0}),this.imageServices[r]})}fetch(e,i){return z(this,null,function*(){return fetch(e,i)})}loadService(e,i=!1){return z(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(o=>setTimeout(o,500));else{n=!1;break}}const r=this.knownImageServers[q(F(e))];if(r&&!r.malformed&&!i){yield r.result;const n=this.loadServiceSync(e);if(n)return n}this.fetchingCount++;const s=yield this.fetchService(F(e),i);return this.fetchingCount--,s.real&&this.sample(s,e),s})}loadServiceSync(e){const i=T(F(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new Pt;function Xe(t,e={}){const i=e.imageServiceLoader||new Pt;async function r(s,n,o,a=[],c){if(typeof s=="string")return{best:G(s),fallback:[],log:[]};const l=t.get(s);if(typeof l=="string")return{best:G(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,h=t.get(f[0]);return c&&!h.width&&(h.width=c.width,h.height=c.height),await i.getThumbnailFromResource(h,n,o,a)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const h=t.get(f.thumbnail[0]),g=await i.getImageCandidates(h,o);g&&g.length&&a.push(...g)}return r(f.items[0],n,o,a,{width:f.width,height:f.height})}case"AnnotationPage":return r(l.items[0],n,o,a,c);case"Choice":return r(l.items[0],n,o,a,c);case"Collection":{const h=l.items[0];return r(h,n,o,a,c)}case"Manifest":{const h=l.items[0];return r(h,n,o,a,c)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return c&&!l.width&&(l.width=c.width,l.height=c.height),i.getThumbnailFromResource(l,n,o,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function Wt(t,e,i=[],r=!1){if(!t||!e||e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const s=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(s&&e.indexOf(s)!==-1)return s;for(const n of i)if(e.indexOf(n)!==-1)return n;if(!r){const o=e.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(t);if(o!==-1)return e[o];for(const a of i){const c=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,l=c?e.indexOf(c):-1;if(l!==-1)return e[l]}}return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}function qt(t,e,i={}){const{strictFallback:r=!1,defaultText:s="",separator:n=`
`,fallbackLanguages:o=[],closest:a}=i,c=Object.keys(t||{}),l=a?e:Wt(e,c,o,r);if(!t)return s;if(typeof t=="string")return t;const f=l?t[l]:void 0;return f?typeof f=="string"?f:f.join(n):""}function Ge(t,e={}){return qt(t,typeof navigator!="undefined"?navigator.language:void 0,e)}var Je=function(){function t(e,i){var r=[],s=!0,n=!1,o=void 0;try{for(var a=e[Symbol.iterator](),c;!(s=(c=a.next()).done)&&(r.push(c.value),!(i&&r.length===i));s=!0);}catch(l){n=!0,o=l}finally{try{!s&&a.return&&a.return()}finally{if(n)throw o}}return r}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),V=Math.PI*2,Y=function(e,i,r,s,n,o,a){var c=e.x,l=e.y;c*=i,l*=r;var f=s*c-n*l,h=n*c+s*l;return{x:f+o,y:h+a}},Ye=function(e,i){var r=i===1.5707963267948966?.551915024494:i===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(i/4),s=Math.cos(e),n=Math.sin(e),o=Math.cos(e+i),a=Math.sin(e+i);return[{x:s-n*r,y:n+s*r},{x:o+a*r,y:a-o*r},{x:o,y:a}]},Bt=function(e,i,r,s){var n=e*s-i*r<0?-1:1,o=e*r+i*s;return o>1&&(o=1),o<-1&&(o=-1),n*Math.acos(o)},Ze=function(e,i,r,s,n,o,a,c,l,f,h,g){var p=Math.pow(n,2),u=Math.pow(o,2),m=Math.pow(h,2),v=Math.pow(g,2),b=p*u-p*v-u*m;b<0&&(b=0),b/=p*v+u*m,b=Math.sqrt(b)*(a===c?-1:1);var d=b*n/o*g,y=b*-o/n*h,w=f*d-l*y+(e+r)/2,S=l*d+f*y+(i+s)/2,A=(h-d)/n,O=(g-y)/o,C=(-h-d)/n,k=(-g-y)/o,W=Bt(1,0,A,O),R=Bt(A,O,C,k);return c===0&&R>0&&(R-=V),c===1&&R<0&&(R+=V),[w,S,W,R]},Ke=function(e){var i=e.px,r=e.py,s=e.cx,n=e.cy,o=e.rx,a=e.ry,c=e.xAxisRotation,l=c===void 0?0:c,f=e.largeArcFlag,h=f===void 0?0:f,g=e.sweepFlag,p=g===void 0?0:g,u=[];if(o===0||a===0)return[];var m=Math.sin(l*V/360),v=Math.cos(l*V/360),b=v*(i-s)/2+m*(r-n)/2,d=-m*(i-s)/2+v*(r-n)/2;if(b===0&&d===0)return[];o=Math.abs(o),a=Math.abs(a);var y=Math.pow(b,2)/Math.pow(o,2)+Math.pow(d,2)/Math.pow(a,2);y>1&&(o*=Math.sqrt(y),a*=Math.sqrt(y));var w=Ze(i,r,s,n,o,a,h,p,m,v,b,d),S=Je(w,4),A=S[0],O=S[1],C=S[2],k=S[3],W=Math.abs(k)/(V/4);Math.abs(1-W)<1e-7&&(W=1);var R=Math.max(Math.ceil(W),1);k/=R;for(var Xt=0;Xt<R;Xt++)u.push(Ye(C,k)),C+=k;return u.map(function(rt){var Gt=Y(rt[0],o,a,v,m,A,O),Fi=Gt.x,Mi=Gt.y,Jt=Y(rt[1],o,a,v,m,A,O),Oi=Jt.x,Ci=Jt.y,Yt=Y(rt[2],o,a,v,m,A,O),ki=Yt.x,Ri=Yt.y;return{x1:Fi,y1:Mi,x2:Oi,y2:Ci,x:ki,y:Ri}})},ti=ii,Z={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ei=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ii(t){var e=[];return t.replace(ei,function(i,r,s){var n=r.toLowerCase();for(s=ni(s),n=="m"&&s.length>2&&(e.push([r].concat(s.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(s.length==Z[n])return s.unshift(r),e.push(s);if(s.length<Z[n])throw new Error("malformed path data");e.push([r].concat(s.splice(0,Z[n])))}}),e}var ri=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ni(t){var e=t.match(ri);return e?e.map(Number):[]}var si=oi;function oi(t){var e=0,i=0,r=0,s=0;return t.map(function(n){n=n.slice();var o=n[0],a=o.toUpperCase();if(o!=a)switch(n[0]=a,o){case"a":n[6]+=r,n[7]+=s;break;case"v":n[1]+=s;break;case"h":n[1]+=r;break;default:for(var c=1;c<n.length;)n[c++]+=r,n[c++]+=s}switch(a){case"Z":r=e,s=i;break;case"H":r=n[1];break;case"V":s=n[1];break;case"M":r=e=n[1],s=i=n[2];break;default:r=n[n.length-2],s=n[n.length-1]}return n})}function ai(t){const e=ti(t),i=si(e);let r,s=0,n=0,o=0,a=0,c,l,f=0,h=0;const g=[];for(let p=0;p<i.length;p++){let u=i[p];const m=u[0];switch(m){case"M":s=u[1],n=u[2];break;case"H":u=["L",u[1],n];break;case"V":u=["L",s,u[1]];break;case"S":{let v=f,b=h;(r==="C"||r=="S")&&(v+=v-o,b+=b-a),u=["C",v,b,u[1],u[2],u[3],u[4]]}break;case"T":r==="Q"||r=="T"?(c=f*2-c,l=h*2-l):(c=f,l=h),u=["Q",c,l,u[1],u[2]];break;case"Q":c=u[1],l=u[2];break;case"A":{const v=Ke({px:f,py:h,cx:u[6],cy:u[7],rx:u[1],ry:u[2],xAxisRotation:u[3],largeArcFlag:u[4],sweepFlag:u[5]});if(!v.length)continue;for(const[b,d]of v.entries())u=["C",d.x1,d.y1,d.x2,d.y2,d.x,d.y],b<v.length-1&&g.push(u);u=u}break;case"Z":u=["L",s,n];break}r=m,f=u[u.length-2],h=u[u.length-1],["C","Q","A"].indexOf(m)>-1?(o=u[u.length-4],a=u[u.length-3]):(o=f,a=h),g.push(u)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
(function(x,T){typeof exports=="object"&&typeof module!="undefined"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(x=typeof globalThis!="undefined"?globalThis:x||self,T(x.VaultHelpers={}))})(this,function(x){"use strict";const T={},I={get(e){return e},setMetaValue([e,t,n],i){const r=I.getResourceMeta(e,t),s=r?r[n]:void 0,o=typeof i=="function"?i(s):i;T[e]={...T[e]||{},[t]:{...(T[e]||{})[t]||{},[n]:o}}},getResourceMeta:(e,t)=>{const n=T[e];if(!!n)return t?n[t]:n}};function st(e=I){return{addEventListener(t,n,i,r){if(!!t)return e.setMetaValue([t.id,"eventManager",n],s=>{const o=s||[];for(const a of o)if(a.callback===i)return o;return[...o,{callback:i,scope:r}]}),i},removeEventListener(t,n,i){!t||e.setMetaValue([t.id,"eventManager",n],r=>(r||[]).filter(s=>s.callback!==i))},getListenersAsProps(t,n){const i=typeof t=="string"?{id:t}:t;if(!i||!i.id)return{};const r=e.getResourceMeta(i.id,"eventManager"),s={};if(r&&i)for(const o of Object.keys(r))s[o]=a=>{const c=e.get(i);for(const{callback:u,scope:f}of r[o]||[])(!f||n&&f.indexOf(n)!==-1)&&u(a,c)};return s}}}function ot(e=I){return{applyStyles(t,n,i){const r=typeof t=="string"?t:t.id;return e.setMetaValue([r,"styles",n],i)},getAppliedStyles(t){const n=typeof t=="string"?t:t.id;return e.getResourceMeta(n,"styles")}}}function W(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}const at="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ce="http://library.stanford.edu/iiif/image-api/compliance.html#level1",le="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ct="http://library.stanford.edu/iiif/image-api/conformance.html#level0",fe="http://library.stanford.edu/iiif/image-api/conformance.html#level1",ue="http://library.stanford.edu/iiif/image-api/conformance.html#level2",lt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",he="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",pe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ft="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",de="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ge="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ut="http://iiif.io/api/image/1/level0.json",ht="http://iiif.io/api/image/1/profiles/level0.json",ye="http://iiif.io/api/image/1/level1.json",me="http://iiif.io/api/image/1/profiles/level1.json",ve="http://iiif.io/api/image/1/level2.json",xe="http://iiif.io/api/image/1/profiles/level2.json",pt="http://iiif.io/api/image/2/level0.json",dt="http://iiif.io/api/image/2/profiles/level0.json",be="http://iiif.io/api/image/2/level1.json",we="http://iiif.io/api/image/2/profiles/level1.json",Se="http://iiif.io/api/image/2/level2.json",Ae="http://iiif.io/api/image/2/profiles/level2.json",gt="level0",Fe="level1",Me="level2",yt="http://iiif.io/api/image/2/level0",Ce="http://iiif.io/api/image/2/level1",Oe="http://iiif.io/api/image/2/level2",ke=[Oe,le,ue,pe,ge,ve,xe,Se,Ae,Me],Re=[...ke,Ce,ce,fe,he,de,ye,me,be,we,Fe],mt=[yt,Ce,Oe,at,ce,le,ct,fe,ue,lt,he,pe,ft,de,ge,ut,ht,ye,me,ve,xe,pt,dt,be,we,Se,Ae,gt,Fe,Me],vt={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},xt={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},bt={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function wt(e){return ke.indexOf(e)!==-1?bt:Re.indexOf(e)!==-1?xt:vt}function St(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],n={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let i of t)if(typeof i=="string"&&(i=wt(i)),!!i){if(i.formats)for(const r of i.formats)n.extraFormats.indexOf(r)===-1&&n.extraFormats.push(r);if(i.qualities)for(const r of i.qualities)n.extraQualities.indexOf(r)===-1&&n.extraQualities.push(r);if(i.supports)for(const r of i.supports)n.extraFeatures.indexOf(r)===-1&&n.extraFeatures.push(r);if(i.maxHeight&&(n.maxHeight=i.maxHeight),i.maxWidth&&(n.maxWidth=i.maxWidth),i.maxArea&&(n.maxArea=i.maxArea),i.extraFormats)for(const r of i.extraFormats)n.extraFormats.indexOf(r)===-1&&n.extraFormats.push(r);if(i.extraQualities)for(const r of i.extraQualities)n.extraQualities.indexOf(r)===-1&&n.extraQualities.push(r);if(i.extraFeatures)for(const r of i.extraFeatures)n.extraFeatures.indexOf(r)===-1&&n.extraFeatures.push(r);i.maxHeight&&(n.maxHeight=i.maxHeight),i.maxWidth&&(n.maxWidth=i.maxWidth),i.maxArea&&(n.maxArea=i.maxArea)}if(e.extraFormats)for(const i of e.extraFormats)n.extraFormats.indexOf(i)===-1&&n.extraFormats.push(i);if(e.extraFeatures)for(const i of e.extraFeatures)n.extraFeatures.indexOf(i)===-1&&n.extraFeatures.push(i);if(e.extraQualities)for(const i of e.extraQualities)n.extraQualities.indexOf(i)===-1&&n.extraQualities.push(i);return n}function At(e){try{if(e==="full")return{full:!0};if(e==="square")return{square:!0};const t=e.startsWith("pct:"),n=e.substr(t?4:0).split(",").map(i=>parseFloat(i));return{x:n[0],y:n[1],w:n[2],h:n[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function Ft(e){const t={upscaled:!1,max:!1,confined:!1};if(e[0]==="^"&&(t.upscaled=!0,e=e.slice(1)),e==="max"||e==="full")return t.max=!0,t.serialiseAsFull=e==="full",t;if(e[0]==="!"&&(t.confined=!0,e=e.slice(1)),e[0]==="p")return t.percentScale=parseFloat(e.slice(4)),t;const n=e.split(",").map(i=>i.trim());return n.length&&(n[0]!==""&&(t.width=parseInt(n[0],10)),n[1]!==""?(t.height=parseInt(n[1],10),t.version=2):t.version=3),t}function Mt(e){const t={angle:0};if(e[0]==="!"&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw new Error(`Invalid rotation ${e}`);return t}function Ct(e,t=""){const n=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!n)throw new Error(`Invalid or unknown input ${e}`);const i=n[2],r=n[3];let s=n[4];if(s[0]==="/"&&(s=s.substr(1)),t.length>0){if(t[0]==="/"&&(t=t.substr(1)),t!==s.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${s}, prefix: ${t})`);s=s.substr(t.length)}return{scheme:i,server:r,path:s,prefix:t}}function Ot(e,t=""){const{path:n,scheme:i,server:r,prefix:s}=Ct(e,t),o=n.split("/").reverse(),[a,c,u,f,...p]=o,h=p.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:i,server:r,prefix:s,identifier:h};if(a==="info.json"){const[,...l]=o;return{type:"info",scheme:i,server:r,prefix:s,identifier:l.reverse().filter(Boolean).join("/")}}const g=a.split(".");return{type:"image",scheme:i,server:r,prefix:s,identifier:h,originalPath:n,region:At(f),size:Ft(u),rotation:Mt(c),quality:g[0],format:g[1]}}function kt(e){const t=Ot(W(e.id));if(t.type!=="info")throw new Error("Invalid service URL");const n=St(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.scheme,type:"image",quality:n.extraQualities.indexOf("default")===-1?n.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Rt(e,t,n){const i=n.length,r=[];for(let s=0;s<i;s++){const o=n[s].width;r.push(e/o)}return r}function jt(e,t,n){const i=n.length,r=[];for(let s=0;s<i;s++){const o=n[s];r.push({width:Math.floor(e/o),height:Math.floor(t/o)})}return r}function F(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function J(e){if(!e||!e.profile||!F(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"&&mt.indexOf(n)!==-1)return!0;return!1}function It(e){if(!J(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"){if(Re.indexOf(n)!==-1)return!0}else{const i=[...n.supports||[],...n.extraFeatures||[]];if(i.indexOf("regionByPx")!==-1&&(i.indexOf("sizeByW")!==-1||i.indexOf("sizeByWh")!==-1))return!0}return!1}function X(e,t){if(t&&t.profile){const n=t.profile;if(n){const i=Array.isArray(n)?n:[n];return i.includes(`level${e}`)||i.includes(`http://iiif.io/api/image/2/level${e}.json`)||i.includes(`http://iiif.io/api/image/1/level${e}.json`)||i.includes(`http://iiif.io/api/image/1/profiles/level${e}.json`)}}return!1}function Z(e){return J(e)?X(0,e)?0:X(1,e)?1:X(2,e)?2:null:null}function je(e){return(e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[]).indexOf("http://iiif.io/api/image/3/context.json")!==-1}function Tt(e){if(!It(e))return[];const t=[],n=Array.isArray(e.profile)?e.profile:[e.profile],i=n.length;for(let r=0;r<i;r++){const s=n[r];if(typeof s!="string"&&(s.maxHeight||s.maxWidth))return[{id:F(e),type:"variable",minWidth:0,minHeight:0,maxHeight:s.maxHeight||s.maxWidth,maxWidth:s.maxWidth||s.maxHeight,level:Z(e),version:e["@context"]==="http://iiif.io/api/image/3/context.json"?3:2}]}if(e.tiles){const r=e.tiles.length;for(let s=0;s<r;s++){const o=e.tiles[s];(o.height||o.width)&&t.push({id:F(e),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width,level:Z(e),version:je(e)?3:2})}}return t}function Ie(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,n=e.match(t);if(n){const i=n[1],r=parseInt(n[4],10),s=parseInt(n[5],10),o=n[7];if((i==="max"||i==="full")&&r&&s&&o)return{type:"fixed",id:e,height:s,width:r}}return{type:"unknown",id:e}}function zt(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function K(e){if(typeof e=="string")return Ie(e);const t=zt(e);if(t!=="Image"&&t!=="sc:Image")return null;const n=e,i=F(n);return i?i&&n.width&&n.height?{id:i,type:"fixed",width:n.width,height:n.height,unsafe:!0}:Ie(i):null}function $t(e){return J(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:F(e),type:"fixed-service",height:t.height,width:t.width,level:Z(e),version:je(e)?3:2})):[]}function Te(e){const t=[],n=e.length;for(let i=0;i<n;i++){const r=$t(e[i]);r.length&&t.push(...r);const s=Tt(e[i]);s.length&&t.push(...s)}return t}function ze(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],n=t.length,i=[];for(let r=0;r<n;r++)J(t[r])&&i.push(t[r]);return i}function Wt(e,t=!0,n){const i=[],r=K(e);if(r===null)return i;const s=e;if(i.push(r),t&&s.width&&s.height){const o=[],a=ze(s);for(const c of a){const u={id:F(c),width:s.width,height:s.height};if(n.canLoadSync(u)){const f=n.loadServiceSync(u);f&&(f.height||(f.height=s.height),f.width||(f.width=s.width),o.push(...Te([f])))}}if(o.length)return i.push(...o),i}return s.service&&i.push(...Te(s.service)),i}function Bt({x:e=0,y:t=0,w:n,h:i,full:r,square:s,percent:o}){if(r)return"full";if(s)return"square";if(typeof n>"u"||typeof i>"u")throw new Error("RegionParameter: invalid region");const a=`${e},${t},${n},${i}`;return o?`pct:${a}`:a}function Pt({max:e,percentScale:t,upscaled:n,confined:i,width:r,height:s,serialiseAsFull:o,version:a}){const c=[];return n&&c.push("^"),e?(c.push(o?"full":"max"),c.join("")):(i&&c.push("!"),t&&c.push(`pct:${t}`),r&&c.push(`${r}`),c.push(","),s&&a===3&&c.push(`${s}`),c.join(""))}function qt(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}var Ht=Object.defineProperty,Lt=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,$e=Object.getOwnPropertySymbols,Qt=Object.prototype.hasOwnProperty,Vt=Object.prototype.propertyIsEnumerable,We=(e,t,n)=>t in e?Ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,B=(e,t)=>{for(var n in t||(t={}))Qt.call(t,n)&&We(e,n,t[n]);if($e)for(var n of $e(t))Vt.call(t,n)&&We(e,n,t[n]);return e},P=(e,t)=>Lt(e,_t(t));function Nt(e,t){const n=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,i=`${e.scheme}://${e.server}/${n?`${n}/`:""}${e.identifier}`;if(e.type==="base")return i;if(e.type==="info")return`${i}/info.json`;let{size:r}=e;const{region:s,rotation:o,format:a,quality:c}=e;if(t){const u=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],f=u.indexOf("http://iiif.io/api/image/2/context.json")!==-1,p=u.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((r.width===t.width&&!r.height||r.height===t.height&&!r.width||r.width===t.width&&r.height===t.height)&&(r=P(B({},r),{max:!0})),f&&(r.max&&!r.serialiseAsFull&&(r=P(B({},r),{serialiseAsFull:!0})),!r.max&&r.width&&r.height&&(r=P(B({},r),{height:void 0})),r=P(B({},r),{version:2})),p){if(r.max&&r.serialiseAsFull&&(r=P(B({},r),{serialiseAsFull:!1})),r.width&&!r.height&&t.width&&t.height){const h=t.height/t.width;r=P(B({},r),{height:Math.ceil(r.width*h)})}r=P(B({},r),{version:3})}}return[i,Bt(s),Pt(r),qt(o),`${c}.${a}`].filter(Boolean).join("/")}function ee(e,t,n){const i=kt({"@context":e.version===3?"http://iiif.io/api/image/3/context.json":"http://iiif.io/api/image/2/context.json",id:W(F(e)),profile:e.level===null||typeof e.level>"u"?"level0":`level${e.level}}`,type:e.version===3?"ImageService3":"ImageService2"});if(i.type!=="image")throw new Error("Invalid service");return i.size.max=!1,i.size.width=t,i.size.height=n,{id:Nt(i),type:"fixed",width:t,height:n||e.height/(e.width||1)*t,unsafe:e.width>t}}function _(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Et(e,t,n){const i=e.width?e.width:e.maxWidth;return n.height<=e.maxHeight&&n.width<=e.maxWidth&&n.height>=e.minHeight&&n.width>=e.minWidth&&(!t||Math.abs(n.width-i)<Math.abs(t.width-i))}function Ut(e,t){const n=[],i=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),r=(f,p=0)=>i.explain?n.push(new Array(p).fill(0).map(h=>" ").join("")+f().trim()):void 0,s=[],o=[];let a=null;r(()=>`Using configuration: ${JSON.stringify(i,null,2)}`);const c=(f,p)=>{if(r(()=>"Swapping choice",3),Et(i,p,f)){if(i.preferFixedSize&&f.unsafe){r(()=>`We found an image that was marked as unsafe, but it was the best size. (${f.id})`,4),o.push(f);return}i.returnAllOptions&&p&&o.push(p),r(()=>`We found a new image that was the best size. (${f.id})`,4),a=f}else i.returnAllOptions&&o.push(f)};r(()=>`The input shows we have ${t.length} list(s) of candidates to choose from.`);const u=t.length;for(let f=0;f<u;f++){const p=t[f]();r(()=>`Candidate group ${f}: ${JSON.stringify(p,null,2)}`,1);const h=p.length;r(()=>`Checking candidate list number ${f} and found ${h} potential ways of creating image(s)`,1);for(let g=0;g<h;g++){const l=p[g];if(r(()=>`-> Checking candidate ${g}`,1),l.type==="unknown"&&i.atAnyCost&&(r(()=>`We've found an unknown image type, adding this to the "last resort" list`,2),s.push(l)),l.type==="fixed"&&(l.unsafe?(r(()=>`We've found an unsafe fixed image type, adding this to the "last resort" list`,2),s.push(l)):(r(()=>"We've found a fixed size image, checking if it matches the request",2),c(l,a))),l.type==="fixed-service")if(i.unsafeImageService){r(()=>"Checking for an image from the tile source, without calculating the right height and width (unsafeImageService)",2);const m=ee(l,i.width,i.height);c(m,a)}else{r(()=>"Checking for an image from the tile source 3",2);const m=ee(l,l.width,l.height);c(m,a)}if(l.type==="variable"&&l.maxWidth){const m=ee({id:l.id,type:"fixed-service",width:l.maxWidth,height:l.maxWidth,level:l.level,version:l.version},l.maxWidth);c(m,a)}}if(a&&!i.returnAllOptions){if(a.unsafe||i.allowUnsafe)continue;r(()=>`We found a match in choice list number ${f}, no searching any more`);break}}return i.atAnyCost&&o.length===0?(r(()=>a?`We found an image! ${a.id} of type ${a.type}`:'We found no images, but "atAnyCost" is set, so returning that'),{best:a||s[0],fallback:s.slice(1),log:n}):i.returnAllOptions?(r(()=>"Returning all options that we have found"),{best:i.atAnyCost?a||o[0]||s[0]:a||o[0],fallback:[...o,...s],log:n}):(r(()=>"Returning the best image that we found, and a fallback"),{best:a||o[0]||null,fallback:a?o:o.slice(1),log:n})}var Dt=Object.defineProperty,Jt=Object.defineProperties,Xt=Object.getOwnPropertyDescriptors,Be=Object.getOwnPropertySymbols,Gt=Object.prototype.hasOwnProperty,Yt=Object.prototype.propertyIsEnumerable,Pe=(e,t,n)=>t in e?Dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Zt=(e,t)=>{for(var n in t||(t={}))Gt.call(t,n)&&Pe(e,n,t[n]);if(Be)for(var n of Be(t))Yt.call(t,n)&&Pe(e,n,t[n]);return e},Kt=(e,t)=>Jt(e,Xt(t));function ei(e,t,n){const i=e>t?e:t,r=n.length,s=[];for(let o=0;o<r;o++){const a=n[o];let c=a.scaleFactors[0],u=i/c;const f=[c];for(;u>=a.width;)c=c*2,f.push(c),u=u/2;s.push(Kt(Zt({},a),{scaleFactors:f}))}return s}function ti(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const n=e.length;let i=!0;for(let s=0;s<n;s++){const o=e[s],a=t[s];if(o.width!==a.width||o.height!==a.height){i=!1;break}}if(i)return!0;let r=0;for(let s=0;s<n;s++)for(let o=0;o<n;o++)if(e[s].width===t[o].width&&e[s].height===t[o].height){r++;break}return r===n}function qe(e){return X(0,e)}var q=(e,t,n)=>new Promise((i,r)=>{var s=c=>{try{a(n.next(c))}catch(u){r(u)}},o=c=>{try{a(n.throw(c))}catch(u){r(u)}},a=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,o);a((n=n.apply(e,t)).next())});class He{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,n,i=!0){const r=_(F(t)),s=W(F(t)),o=this.knownImageServers[r];return this.imageServices[s]=Object.assign(t,{real:!0}),!o&&t.tiles&&!qe(t)?(this.knownImageServers[r]={verifications:0,malformed:!1,root:r,preLoaded:i,sampledId:F(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:n&&t.height?n.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:Rt(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0):this.verify(t)}preLoad(t,n=!0){this.knownImageServers[t.root]=t,n&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,n=!1,i=!1){const r=t==null?void 0:t.source,s=_(F(t)),o=this.knownImageServers[s];if(!o||!o.result||!((r==null?void 0:r.height)||t.height)||!((r==null?void 0:r.width)||t.width)||!i&&(o.malformed||o.verifications<this.config.verificationsRequired)||qe(t.source))return null;const a=W(F(t));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":F(t),id:F(t),protocol:"http://iiif.io/api/image",tiles:(r==null?void 0:r.tiles)||ei(t.width,t.height,o.result.sampledTiles),sizes:(r==null?void 0:r.sizes)||jt(Math.round(t.width/o.result.resourceServiceRatio),Math.round(t.height/o.result.resourceServiceRatio),o.result.sizeRatios),profile:(r==null?void 0:r.profile)||o.result.sampledProfile,height:(r==null?void 0:r.height)||t.height,width:(r==null?void 0:r.width)||t.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(t,n){return q(this,arguments,function*(i,r,s=!0,o=[]){const a=i?yield this.getImageCandidates(i,s):[];return Ut(r,[()=>o,()=>a])})}getImageCandidates(t,n=!0){return q(this,null,function*(){const i=t;if(n&&i.height&&i.width){const r=ze(i);for(const s of r){const o={id:F(s),width:s.width?s.width:i.width,height:s.height?s.height:i.height,source:s};yield this.loadService(o)}}return Wt(t,n,this)})}verify(t){return q(this,null,function*(){const n=this.predict(t,!1,!0),i=yield this.fetchService(F(t));if(!n)return!1;const r=n.height===i.height&&n.width===i.width&&n["@context"]===i["@context"]&&ti(n.sizes||[],i.sizes||[]);if(r){const s=_(F(t));this.knownImageServers[s].verifications+=1,this.knownImageServers[s].verifications>=this.config.verificationsRequired&&(this.knownImageServers[s].verified=!0)}return r})}canLoadSync(t){const n=typeof t=="string"?t:F(t),i=W(n);if(this.imageServices[i])return!0;const r=this.knownImageServers[_(n)];return r&&!r.malformed&&r.verifications>=this.config.verificationsRequired}markAsMalformed(t){return q(this,null,function*(){return this.knownImageServers[_(F(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,n=!1){return q(this,null,function*(){const i=W(t);if(this.imageServices[i]&&(!n||this.imageServices[i].real))return this.imageServices[i];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const r=yield this.fetch(i).then(s=>s.json());return!r.id&&r["@id"]&&(r.id=r["@id"]),r.id!==t&&(r.id=t,r["@id"]&&(r["@id"]=t)),this.imageServices[i]=Object.assign(r,{real:!0}),this.imageServices[i]})}fetch(t,n){return q(this,null,function*(){return fetch(t,n)})}loadService(t,n=!1){return q(this,null,function*(){if(!this.config.disableThrottling){let s=!0;for(;s;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(o=>setTimeout(o,500));else{s=!1;break}}const i=this.knownImageServers[_(F(t))];if(i&&!i.malformed&&!n){yield i.result;const s=this.loadServiceSync(t);if(s)return s}this.fetchingCount++;const r=yield this.fetchService(F(t),n);return this.fetchingCount--,r.real&&this.sample(r,t),r})}loadServiceSync(t){const n=W(F(t));return this.imageServices[n]?this.imageServices[n]:this.predict(t)}}new He;function ii(e=I,t={}){const n=t.imageServiceLoader||new He;async function i(r,s,o,a=[],c){const u=()=>n.getThumbnailFromResource(void 0,s,o,a);if(!r)return await n.getThumbnailFromResource(void 0,s,o,a);if(typeof r=="string"){const h=K(r);return h&&a.push(h),await n.getThumbnailFromResource(void 0,s,o,a)}const f=e.get(r,{skipSelfReturn:!1});if(typeof f=="string")return{best:K(f),fallback:[],log:[]};if(!f)return await u();switch(await(async h=>{if(h&&h.thumbnail&&h.thumbnail.length){const g=e.get(h.thumbnail[0]),l=await n.getImageCandidates(g,o);l&&l.length&&a.push(...l)}})(f),f.type){case"Annotation":{const h=Array.isArray(f.body)?f.body:[f.body],g=e.get(h[0]);return c&&!g.width&&(g.width=c.width,g.height=c.height),await n.getThumbnailFromResource(g,s,o,a)}case"Canvas":{const h=f;return i(h.items[0],s,o,a,{width:h.width,height:h.height})}case"AnnotationPage":return i(f.items[0],s,o,a,c);case"Choice":{const h=f;return!h.items||h.items[0]?await u():i(h.items[0],s,o,a,c)}case"Collection":{const g=f.items[0];return g?i(g,s,o,a,c):await u()}case"Manifest":{const g=f.items[0];return g?i(g,s,o,a,c):await u()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return c&&!f.width&&(f.width=c.width,f.height=c.height),n.getThumbnailFromResource(f,s,o,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return await u()}return await u()}return{getBestThumbnailAtSize:i}}function Le(e,t,n=[],i=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const r=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(r&&t.indexOf(r)!==-1)return r;for(const s of n)if(t.indexOf(s)!==-1)return s;if(!i){const o=t.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(e);if(o!==-1)return t[o];for(const a of n){const c=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,u=c?t.indexOf(c):-1;if(u!==-1)return t[u]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function _e(e,t,n={}){const{strictFallback:i=!1,defaultText:r="",separator:s=`
`,fallbackLanguages:o=[],closest:a}=n,c=Object.keys(e||{}),u=a?t:Le(t,c,o,i);if(!e)return r;if(typeof e=="string")return e;const f=u?e[u]:void 0;return f?typeof f=="string"?f:f.join(s):""}function ni(e,t={}){return _e(e,typeof navigator!="undefined"?navigator.language:void 0,t)}var ri=function(){function e(t,n){var i=[],r=!0,s=!1,o=void 0;try{for(var a=t[Symbol.iterator](),c;!(r=(c=a.next()).done)&&(i.push(c.value),!(n&&i.length===n));r=!0);}catch(u){s=!0,o=u}finally{try{!r&&a.return&&a.return()}finally{if(s)throw o}}return i}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),E=Math.PI*2,te=function(t,n,i,r,s,o,a){var c=t.x,u=t.y;c*=n,u*=i;var f=r*c-s*u,p=s*c+r*u;return{x:f+o,y:p+a}},si=function(t,n){var i=n===1.5707963267948966?.551915024494:n===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(n/4),r=Math.cos(t),s=Math.sin(t),o=Math.cos(t+n),a=Math.sin(t+n);return[{x:r-s*i,y:s+r*i},{x:o+a*i,y:a-o*i},{x:o,y:a}]},Qe=function(t,n,i,r){var s=t*r-n*i<0?-1:1,o=t*i+n*r;return o>1&&(o=1),o<-1&&(o=-1),s*Math.acos(o)},oi=function(t,n,i,r,s,o,a,c,u,f,p,h){var g=Math.pow(s,2),l=Math.pow(o,2),m=Math.pow(p,2),v=Math.pow(h,2),b=g*l-g*v-l*m;b<0&&(b=0),b/=g*v+l*m,b=Math.sqrt(b)*(a===c?-1:1);var d=b*s/o*h,y=b*-o/s*p,w=f*d-u*y+(t+i)/2,S=u*d+f*y+(n+r)/2,A=(p-d)/s,C=(h-y)/o,O=(-p-d)/s,R=(-h-y)/o,L=Qe(1,0,A,C),j=Qe(A,C,O,R);return c===0&&j>0&&(j-=E),c===1&&j<0&&(j+=E),[w,S,L,j]},ai=function(t){var n=t.px,i=t.py,r=t.cx,s=t.cy,o=t.rx,a=t.ry,c=t.xAxisRotation,u=c===void 0?0:c,f=t.largeArcFlag,p=f===void 0?0:f,h=t.sweepFlag,g=h===void 0?0:h,l=[];if(o===0||a===0)return[];var m=Math.sin(u*E/360),v=Math.cos(u*E/360),b=v*(n-r)/2+m*(i-s)/2,d=-m*(n-r)/2+v*(i-s)/2;if(b===0&&d===0)return[];o=Math.abs(o),a=Math.abs(a);var y=Math.pow(b,2)/Math.pow(o,2)+Math.pow(d,2)/Math.pow(a,2);y>1&&(o*=Math.sqrt(y),a*=Math.sqrt(y));var w=oi(n,i,r,s,o,a,p,g,m,v,b,d),S=ri(w,4),A=S[0],C=S[1],O=S[2],R=S[3],L=Math.abs(R)/(E/4);Math.abs(1-L)<1e-7&&(L=1);var j=Math.max(Math.ceil(L),1);R/=j;for(var tt=0;tt<j;tt++)l.push(si(O,R)),O+=R;return l.map(function(ae){var it=te(ae[0],o,a,v,m,A,C),Ti=it.x,zi=it.y,nt=te(ae[1],o,a,v,m,A,C),$i=nt.x,Wi=nt.y,rt=te(ae[2],o,a,v,m,A,C),Bi=rt.x,Pi=rt.y;return{x1:Ti,y1:zi,x2:$i,y2:Wi,x:Bi,y:Pi}})},ci=fi,ie={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},li=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function fi(e){var t=[];return e.replace(li,function(n,i,r){var s=i.toLowerCase();for(r=hi(r),s=="m"&&r.length>2&&(t.push([i].concat(r.splice(0,2))),s="l",i=i=="m"?"l":"L");;){if(r.length==ie[s])return r.unshift(i),t.push(r);if(r.length<ie[s])throw new Error("malformed path data");t.push([i].concat(r.splice(0,ie[s])))}}),t}var ui=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function hi(e){var t=e.match(ui);return t?t.map(Number):[]}var pi=di;function di(e){var t=0,n=0,i=0,r=0;return e.map(function(s){s=s.slice();var o=s[0],a=o.toUpperCase();if(o!=a)switch(s[0]=a,o){case"a":s[6]+=i,s[7]+=r;break;case"v":s[1]+=r;break;case"h":s[1]+=i;break;default:for(var c=1;c<s.length;)s[c++]+=i,s[c++]+=r}switch(a){case"Z":i=t,r=n;break;case"H":i=s[1];break;case"V":r=s[1];break;case"M":i=t=s[1],r=n=s[2];break;default:i=s[s.length-2],r=s[s.length-1]}return s})}function gi(e){const t=ci(e),n=pi(t);let i,r=0,s=0,o=0,a=0,c,u,f=0,p=0;const h=[];for(let g=0;g<n.length;g++){let l=n[g];const m=l[0];switch(m){case"M":r=l[1],s=l[2];break;case"H":l=["L",l[1],s];break;case"V":l=["L",r,l[1]];break;case"S":{let v=f,b=p;(i==="C"||i=="S")&&(v+=v-o,b+=b-a),l=["C",v,b,l[1],l[2],l[3],l[4]]}break;case"T":i==="Q"||i=="T"?(c=f*2-c,u=p*2-u):(c=f,u=p),l=["Q",c,u,l[1],l[2]];break;case"Q":c=l[1],u=l[2];break;case"A":{const v=ai({px:f,py:p,cx:l[6],cy:l[7],rx:l[1],ry:l[2],xAxisRotation:l[3],largeArcFlag:l[4],sweepFlag:l[5]});if(!v.length)continue;for(const[b,d]of v.entries())l=["C",d.x1,d.y1,d.x2,d.y2,d.x,d.y],b<v.length-1&&h.push(l);l=l}break;case"Z":l=["L",r,s];break}i=m,f=l[l.length-2],p=l[l.length-1],["C","Q","A"].indexOf(m)>-1?(o=l[l.length-4],a=l[l.length-3]):(o=f,a=p),h.push(l)}return h}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
*

@@ -32,3 +32,3 @@ * All code in this module is based on JavaScript code by Raph Levien, published on his blog at

* limitations under the License.
*/function ci(t,e,i,r=1){return new Ht(t,e,i).subdivide(r)}function li(t,e,i,r,s=1){return new K(new Float64Array([t.x,t.y,e.x,e.y,i.x,i.y,r.x,r.y])).subdivide(s)}function fi(t){return t.x*t.x+t.y*t.y}function N(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function B(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Ht{constructor(e,i,r){this.start=e,this.control=i,this.end=r}eval(e){const i=1-e;return{x:this.start.x*i*i+2*this.control.x*i*e+this.end.x*e*e,y:this.start.y*i*i+2*this.control.y*i*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:i}=this.start,{x:r,y:s}=this.control,{x:n,y:o}=this.end,a=2*r-e-n,c=2*s-i-o,l=(r-e)*a+(s-i)*c,f=(n-r)*a+(o-s)*c,h=(n-e)*c-(o-i)*a,g=l/h,p=f/h,u=Math.abs(h)/(Math.hypot(a,c)*Math.abs(p-g));return{x0:e,x2:n,scale:u,cross:h}}subdivide(e){const i=this.mapToBasic(),r=N(i.x0),s=N(i.x2),n=.5*Math.abs(s-r)*Math.sqrt(i.scale/e),o=Math.ceil(n),a=B(r),c=B(s),l=[0];for(let f=1;f<o;f++){const g=(B(r+(s-r)*f/o)-a)/(c-a);l.push(g)}return l.push(1),l.map(f=>this.eval(f))}}class K{constructor(e){this.c=e}weightsum(e,i,r,s){const n=e*this.c[0]+i*this.c[2]+r*this.c[4]+s*this.c[6],o=e*this.c[1]+i*this.c[3]+r*this.c[5]+s*this.c[7];return{x:n,y:o}}eval(e){const i=1-e,r=i*i*i,s=3*i*i*e,n=3*i*e*e,o=e*e*e;return this.weightsum(r,s,n,o)}deriv(e){const i=1-e,r=-3*i*i,s=3*e*e,n=-6*e*i-r,o=6*e*i-s;return this.weightsum(r,n,o,s)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Ht({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,i){const r=new Float64Array(8),s=this.eval(e),n=this.eval(i);r[0]=s.x,r[1]=s.y;const o=(i-e)/3,a=this.deriv(e);r[2]=s.x+o*a.x,r[3]=s.y+o*a.y;const c=this.deriv(i);return r[4]=n.x-o*c.x,r[5]=n.y-o*c.y,r[6]=n.x,r[7]=n.y,new K(r)}subdivide(e){const i=.1*e,r=e-i,s=Math.sqrt(r),n=fi(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(n/(432*i*i),1/6)),a=[];let c=0;for(let u=0;u<o;u++){const m=u/o,v=(u+1)/o,b=this.subsegment(m,v).midpoint_quadbez(),d=b.mapToBasic(),y=N(d.x0),w=N(d.x2),S=Math.sqrt(d.scale);let A=Math.abs(w-y)*S;if(Math.sign(d.x0)!=Math.sign(d.x2)){const O=s/S,C=s*Math.abs(w-y)/N(O);A=Math.max(A,C)}a.push({quad:b,a0:y,a2:w,val:A}),c+=A}const l=.5*c/s,f=Math.ceil(l),h=[{x:this.c[0],y:this.c[1]}];let g=0,p=0;for(let u=1;u<f;u++){const m=c*u/f;for(;g+a[p].val<m;)g+=a[p].val,p++;const v=a[p].a0,b=a[p].a2,d=B(v),y=B(b),w=v+(b-v)*(m-g)/a[p].val,A=(B(w)-d)/(y-d);h.push(a[p].quad.eval(A))}return h.push({x:this.c[6],y:this.c[7]}),h}}const ui=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,hi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,$t=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function E(t,{domParser:e,svgPreprocessor:i}={}){var r,s;if(Array.isArray(t))return t.reduce((n,o)=>{const{selector:a,selectors:c}=E(o);return a&&(n.selector||(n.selector=a),n.selectors.push(...c)),n},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[n,o]=t.split("#");return o?E({type:"FragmentSelector",value:o}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:n,selectors:[n]}}if(t.type==="FragmentSelector"){const n=ui.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return{selector:a,selectors:[a]}}const o=t.value.match(hi);if(o){const a={type:"TemporalSelector",temporal:{startTime:o[4]?parseFloat(o[4]):0,endTime:o[7]?parseFloat(o[7]):void 0}};return{selector:a,selectors:[a]}}return{selector:null,selectors:[]}}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window!="undefined"?e=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let n=[],o,a,c=(r=i==null?void 0:i(t.value))!=null?r:t.value,l;if(e){const h=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!h)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const g=Lt(h);g&&(n=g.points,l=g.shapeType,o=[Math.min(...n.map(p=>p[0])),Math.min(...n.map(p=>p[1])),Math.max(...n.map(p=>p[0])),Math.max(...n.map(p=>p[1]))],{style:a,svg:c}=(s=gi(g.element))!=null?s:{svg:c})}const f={type:"SvgSelector",svg:c,svgShape:l,style:a,points:n.length?n:void 0,spatial:o?{unit:"pixel",x:o[0],y:o[1],width:o[2]-o[0],height:o[3]-o[1]}:void 0};return{selector:f,selectors:[f]}}return{selector:null,selectors:[]}}function pi(t){const e=t.map(r=>r[0]).reduce((r,s)=>(r[s]+=1,r),{C:0,Q:0,L:0,M:0}),i=new Set(t.map(r=>r[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(i.size===1||i.size===2&&i.has("M"))){if(e.L===4)return"rect";const r=t.slice(-1)[0];return t[0][0]==="M"&&r[0]==="L"&&r[1]==t[0][1]&&r[2]===t[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function Lt(t){var e,i,r,s,n,o,a,c,l,f,h,g,p,u,m,v,b;for(const d of Array.from(t.children))switch(d==null?void 0:d.tagName.toLowerCase()){case"g":{const y=Lt(d);if(y)return y}continue;case"path":{const y=d.getAttribute("d");if(!y)continue;const w=ai(y);return{element:d,points:di(w),shapeType:pi(w)}}case"circle":{const y=parseFloat((e=d.getAttribute("cx"))!=null?e:"0"),w=parseFloat((i=d.getAttribute("cy"))!=null?i:"0"),S=parseFloat((r=d.getAttribute("r"))!=null?r:"0");if(!S)continue;const A=[];for(let O=0;O<=360;O+=12){const C=O*Math.PI/180;A.push([y+S*Math.cos(C),w+S*Math.sin(C)])}return{element:d,points:A,shapeType:"circle"}}case"ellipse":{const y=parseFloat((s=d.getAttribute("cx"))!=null?s:"0"),w=parseFloat((n=d.getAttribute("cy"))!=null?n:"0"),S=parseFloat((o=d.getAttribute("rx"))!=null?o:"0"),A=parseFloat((a=d.getAttribute("ry"))!=null?a:"0");if(!S&&!A)continue;const O=[];for(let C=0;C<=360;C+=12){const k=Math.tan(C/360*Math.PI),W=S*(1-k**2)/(1+k**2),R=A*2*k/(1+k**2);O.push([y+W,w+R])}return{element:d,points:O,shapeType:"ellipse"}}case"line":{const y=parseFloat((c=d.getAttribute("x0"))!=null?c:"0"),w=parseFloat((l=d.getAttribute("y0"))!=null?l:"0"),S=parseFloat((f=d.getAttribute("x1"))!=null?f:"0"),A=parseFloat((h=d.getAttribute("y1"))!=null?h:"0");if(y===S&&w===A)continue;return{element:d,points:[[y,w],[S,A]],shapeType:"polyline"}}case"polygon":case"polyline":{const y=(p=(g=d.getAttribute("points"))==null?void 0:g.split(" ").map(S=>S.split(",").map(parseFloat)))!=null?p:[];if(!y.length)continue;let w="polyline";return d.tagName.toLowerCase()==="polygon"&&(y.push(y[0]),w="polygon"),{element:d,points:y,shapeType:w}}case"rect":{const y=parseFloat((u=d.getAttribute("x"))!=null?u:"0"),w=parseFloat((m=d.getAttribute("y"))!=null?m:"0"),S=parseFloat((v=d.getAttribute("width"))!=null?v:"0"),A=parseFloat((b=d.getAttribute("height"))!=null?b:"0");if(!S||!A)continue;return{element:d,points:[[y,w],[y+S,w],[y+S,w+A],[y,w+A],[y,w]],shapeType:"rect"}}default:continue}return null}function di(t){var i;const e=[];for(let r=0;r<t.length;r++){const s=(i=e[e.length-1])!=null?i:[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...li({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(o=>[o.x,o.y]).slice(1));continue;case"Q":e.push(...ci({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(o=>[o.x,o.y]).slice(1));continue}}return e}function gi(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const r=$t.exec(e.fill);r&&(e.fillOpacity=parseFloat(r[4]),e.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const r=$t.exec(e.stroke);r&&(e.strokeOpacity=parseFloat(r[4]),e.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let i=t;for(;i.tagName.toLowerCase()!=="svg";)if(i=i.parentElement,i===null)throw new Error("Could not find root SVG element");return{svg:i.outerHTML,style:Object.keys(e).length>0?e:void 0}}function j(t,e={}){if(Array.isArray(t))return j(t[0]);if(typeof t=="string"){const[i,r]=t.split("#");return r?j({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:i,type:e.typeMap&&e.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return j(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:i,selectors:r}=t.selector?E(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:i,selectors:r}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[i,r]=t.id.split("#");return r?j({type:"SpecificResource",source:{...t,id:i},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...t,id:i},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function tt(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const i=JSON.parse(t);return tt(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const i of t){const[r,s]=tt(i);if(!r&&s)return[r,s]}return[!0]}return t.type==="Annotation"?[!0]:e&&t.type==="Canvas"&&!t.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function yi(t){return _t(typeof t=="string"?t:JSON.stringify(t))}function Qt(t,e){if(t=t.trim(),t[0]==="{")return e?Promise.resolve(JSON.parse(t)):JSON.parse(t);if(t.startsWith("http")){if(!e)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(t).then(i=>i.json())}return Qt(Vt(t),e)}function _t(t){const e=encodeURIComponent(t);return(typeof btoa=="undefined"?Buffer.from(e,"utf-8").toString("base64"):btoa(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Vt(t){const i=mi(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function mi(t){const e=t.length%4;if(e===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return t+(e?"====".slice(0,4-e):"")}function vi(t){if(!t)throw new Error("Content state is empty");Array.isArray(t)||(t=[t]);let e="vault://virtual-annotation/"+new Date().getTime();const i=[];for(const r of t){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(e=r.id,Array.isArray(r.motivation))for(const n of r.motivation);if(Array.isArray(r.target))for(const n of r.target){const o=j(n);i.push(o)}else{const n=j(r.target);i.push(n)}continue}const s=j(r);i.push(s)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:i,extensions:{}}}function Nt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function xi(t){function e(s){const n=s?typeof s=="string"?t.get(s):s:null;if(!n)return[];const o=t.get(n.items),a=[];for(const c of o)a.push(...t.get(c.items));return a}function i(s,n=[]){const o=Array.isArray(s)?s:e(s),a=[];let c=null;const l=[];for(const f of o){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const h=t.get(f.body);for(const g of h){const[p,{selector:u}]=Nt(g),m=(p.type||"unknown").toLowerCase();if(m==="choice"){const v=t.get(p.items),b=n.length?n.map(d=>v.find(y=>y.id===d)).filter(Boolean):[v[0]];b.length===0&&b.push(v[0]),c={type:"single-choice",items:v.map(d=>({id:d.id,label:d.label,selected:b.indexOf(d)!==-1})),label:g.label},h.push(...b);continue}a.indexOf(m)===-1&&a.push(m),l.push({type:m,resource:p,target:f.target,selector:u})}}return{types:a,items:l,choice:c}}function r(s){const{choice:n}=i(s);return n}return{getAllPaintingAnnotations:e,getPaintables:i,extractChoices:r}}function M(t,e,i){e[$]=e[$]||[],e[$].push(t),Object.defineProperty(e,t,{get(){if(typeof e[P][t]=="undefined")return;const r=e[P][t];return r&&I(i.get(e[P][t]),i)},set(r){e[P][t]!==r&&(this[P][t]=r)}})}const P=Symbol.for("_refs_"),H=Symbol.for("_reactive_"),$=Symbol.for("_defined_");function bi(t,e=!1){const i={id:null,[$]:[],[P]:{},[H]:null,is(r){return typeof r=="string"?this.id===r:r.id?r.id===this.id:!1},reactive(){if(!this[H])return this[H]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const r=this.unwrap();for(const s of Object.keys(r||{}))this[$].includes(s)?this[P][s]=r[s]:this[s]=r[s]}},unreactive(){this[H]&&(this[H](),this[H]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");return t.get(this.id)},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},toJSON(){const r=this;return{...r,items:r.items,annotations:r.annotations,structures:r.structures,seeAlso:r.seeAlso,service:r.service,services:r.services,rendering:r.rendering,partOf:r.partOf,start:r.start,supplementary:r.supplementary,homepage:r.homepage,thumbnail:r.thumbnail,placeholderCanvas:r.placeholderCanvas,accompanyingCanvas:r.accompanyingCanvas,provider:r.provider}},subscribe(r,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,r,s)}};return M("items",i,t),M("annotations",i,t),M("structures",i,t),M("seeAlso",i,t),M("service",i,t),M("services",i,t),M("rendering",i,t),M("partOf",i,t),M("start",i,t),M("supplementary",i,t),M("homepage",i,t),M("thumbnail",i,t),M("placeholderCanvas",i,t),M("accompanyingCanvas",i,t),M("provider",i,t),M("body",i,t),M("logo",i,t),i}function Et(t){return Array.isArray(t)?t.map(e=>Et(e)):!t||!t.type?t:{id:t.id,type:t.type}}function I(t,e,i=!1){if(Array.isArray(t))return t.map(o=>I(o,e,i));if(!t||!t.type||!t.id)return t;const r=bi(e,i),s=Object.create(r),n=Object.assign(s,t);return i&&n.reactive(),n}function wi(t){return{get(e,i=!1){return I(t.get(e),t,i)},async load(e,i){return I(await t.load(e,i),t)},async loadManifest(e,i){return I(await t.loadManifest(e,i),t)},async loadCollection(e,i){return I(await t.loadCollection(e,i),t)},wrapObject(e){return I(t.get(e,{skipSelfReturn:!1}),t)},isWrapped(e){return!!e[$]}}}function Si(t){return{findFirstCanvasFromRange:e=>et(t,e),findAllCanvasesInRange:e=>U(t,e),findManifestSelectedRange:(e,i)=>Ut(t,e,i),findSelectedRange:(e,i)=>D(t,e,i)}}function et(t,e){for(const i of e.items){if(i.type==="Canvas")return i;if(i.type==="Range"){const r=et(t,t.get(i));if(r)return r}}return null}function U(t,e){const i=[];for(const r of e.items)if(r.type==="Canvas"&&(r.id.indexOf("#")!==-1?i.push({id:r.id.split("#")[0],type:"Canvas"}):i.push(r)),r.type==="Range"&&i.push(...U(t,t.get(r))),r.type==="SpecificResource"){const s=typeof r.source=="string"?r.source:r.source.id;i.push({id:s,type:"Canvas"})}return i}function Ut(t,e,i){for(const r of e.structures){const s=D(t,t.get(r),i);if(s)return s}return null}function D(t,e,i){var r;for(const s of e.items){const n=(r=s.id)==null?void 0:r.split("#")[0];if(s.type==="SpecificResource"&&s.source===i||s.type==="Canvas"&&i===n)return e;if(s.type==="Range"){const o=D(t,t.get(s),i);if(o)return o}}return null}function Ai(t){return{getVisibleCanvasesFromCanvasId:(e,i,r=!1)=>Dt(t,e,i,r),getManifestSequence:(e,i={})=>it(t,e,i)}}function Dt(t,e,i,r=!1){const s=e.behavior,n=i?t.get(i):null;if(!n)return[];const o=n.behavior,a=r?!1:s.includes("paged"),c=a?!1:s.includes("continuous"),l=a||c?!1:s.includes("individuals"),f=o.includes("facing-pages"),h=o.includes("non-paged");if(f||h||l||r)return[{id:n.id,type:"Canvas"}];const[g,p]=it(t,e);if(c)return g;const u=g.findIndex(m=>m.id===i);if(u===-1)return[];for(const m of p)if(m.includes(u))return m.map(v=>g[v]);return[{id:n.id,type:"Canvas"}]}function it(t,e,{disablePaging:i,skipNonPaged:r}={}){const s=e.behavior,n=s.includes("paged"),o=n?!1:s.includes("continuous"),a=n||o?!1:s.includes("individuals"),c=e.type==="Manifest"?e.items:U(t,e);if(o)return[c,[c.map((u,m)=>m)]];if(a||!n||i)return[c,c.map((u,m)=>[m])];const l=[];let f=[];const h=()=>{f.length&&(l.push([...f]),f=[])};let g=0,p=!1;for(let u=0;u<c.length;u++){const m=t.get(c[u]);if(m.behavior.includes("non-paged")){u===g&&g++,r||(h(),l.push([u]),h());continue}if(u===g||m.behavior.includes("facing-pages")){f.length&&(p=!0),h(),l.push([u]),h();continue}if(f.push(u),p){h(),p=!1;continue}f.length>1&&h()}return f.length&&h(),[c,l]}x.buildLocaleString=qt,x.createEventsHelper=L,x.createObjectsHelper=wi,x.createPaintingAnnotationsHelper=xi,x.createRangeHelper=Si,x.createSequenceHelper=Ai,x.createStylesHelper=Zt,x.createThumbnailHelper=Xe,x.decodeContentState=Vt,x.encodeContentState=_t,x.expandTarget=j,x.findAllCanvasesInRange=U,x.findFirstCanvasFromRange=et,x.findManifestSelectedRange=Ut,x.findSelectedRange=D,x.getClosestLanguage=Wt,x.getManifestSequence=it,x.getValue=Ge,x.getVisibleCanvasesFromCanvasId=Dt,x.normaliseContentState=vi,x.parseContentState=Qt,x.parseSelector=E,x.parseSpecificResource=Nt,x.serialiseContentState=yi,x.unwrapObject=Et,x.validateContentState=tt,x.wrapObject=I,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
*/function yi(e,t,n,i=1){return new Ve(e,t,n).subdivide(i)}function mi(e,t,n,i,r=1){return new ne(new Float64Array([e.x,e.y,t.x,t.y,n.x,n.y,i.x,i.y])).subdivide(r)}function vi(e){return e.x*e.x+e.y*e.y}function U(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function Q(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class Ve{constructor(t,n,i){this.start=t,this.control=n,this.end=i}eval(t){const n=1-t;return{x:this.start.x*n*n+2*this.control.x*n*t+this.end.x*t*t,y:this.start.y*n*n+2*this.control.y*n*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:n}=this.start,{x:i,y:r}=this.control,{x:s,y:o}=this.end,a=2*i-t-s,c=2*r-n-o,u=(i-t)*a+(r-n)*c,f=(s-i)*a+(o-r)*c,p=(s-t)*c-(o-n)*a,h=u/p,g=f/p,l=Math.abs(p)/(Math.hypot(a,c)*Math.abs(g-h));return{x0:t,x2:s,scale:l,cross:p}}subdivide(t){const n=this.mapToBasic(),i=U(n.x0),r=U(n.x2),s=.5*Math.abs(r-i)*Math.sqrt(n.scale/t),o=Math.ceil(s),a=Q(i),c=Q(r),u=[0];for(let f=1;f<o;f++){const h=(Q(i+(r-i)*f/o)-a)/(c-a);u.push(h)}return u.push(1),u.map(f=>this.eval(f))}}class ne{constructor(t){this.c=t}weightsum(t,n,i,r){const s=t*this.c[0]+n*this.c[2]+i*this.c[4]+r*this.c[6],o=t*this.c[1]+n*this.c[3]+i*this.c[5]+r*this.c[7];return{x:s,y:o}}eval(t){const n=1-t,i=n*n*n,r=3*n*n*t,s=3*n*t*t,o=t*t*t;return this.weightsum(i,r,s,o)}deriv(t){const n=1-t,i=-3*n*n,r=3*t*t,s=-6*t*n-i,o=6*t*n-r;return this.weightsum(i,s,o,r)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new Ve({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,n){const i=new Float64Array(8),r=this.eval(t),s=this.eval(n);i[0]=r.x,i[1]=r.y;const o=(n-t)/3,a=this.deriv(t);i[2]=r.x+o*a.x,i[3]=r.y+o*a.y;const c=this.deriv(n);return i[4]=s.x-o*c.x,i[5]=s.y-o*c.y,i[6]=s.x,i[7]=s.y,new ne(i)}subdivide(t){const n=.1*t,i=t-n,r=Math.sqrt(i),s=vi(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(s/(432*n*n),1/6)),a=[];let c=0;for(let l=0;l<o;l++){const m=l/o,v=(l+1)/o,b=this.subsegment(m,v).midpoint_quadbez(),d=b.mapToBasic(),y=U(d.x0),w=U(d.x2),S=Math.sqrt(d.scale);let A=Math.abs(w-y)*S;if(Math.sign(d.x0)!=Math.sign(d.x2)){const C=r/S,O=r*Math.abs(w-y)/U(C);A=Math.max(A,O)}a.push({quad:b,a0:y,a2:w,val:A}),c+=A}const u=.5*c/r,f=Math.ceil(u),p=[{x:this.c[0],y:this.c[1]}];let h=0,g=0;for(let l=1;l<f;l++){const m=c*l/f;for(;h+a[g].val<m;)h+=a[g].val,g++;const v=a[g].a0,b=a[g].a2,d=Q(v),y=Q(b),w=v+(b-v)*(m-h)/a[g].val,A=(Q(w)-d)/(y-d);p.push(a[g].quad.eval(A))}return p.push({x:this.c[6],y:this.c[7]}),p}}const xi=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,bi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,Ne=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function D(e,{domParser:t,svgPreprocessor:n,iiifRenderingHints:i}={}){var r,s;if(Array.isArray(e))return k(e.reduce((o,a)=>{const{selector:c,selectors:u,iiifRenderingHints:f}=D(a,{domParser:t,svgPreprocessor:n,iiifRenderingHints:i});return c&&(o.selector||(o.selector=c),o.selectors.push(...u)),f&&(o.iiifRenderingHints=o.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(o.iiifRenderingHints,f)),o},{selector:null,selectors:[],iiifRenderingHints:i}));if(!e)return k({selector:null,selectors:[],iiifRenderingHints:i});if(typeof e=="string"){const[o,a]=e.split("#");return a?D({type:"FragmentSelector",value:a},{svgPreprocessor:n,iiifRenderingHints:i,domParser:t}):k({selector:null,selectors:[],iiifRenderingHints:i})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const o={type:"TemporalSelector",temporal:{startTime:e.t}};return k({selector:o,selectors:[o],iiifRenderingHints:i})}if(Ue(e)){const o=[];if(e.region){const a=D({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:n,iiifRenderingHints:i});o.push(...a.selectors)}return k({selector:o[0],selectors:o,iiifRenderingHints:i?{...i,...e}:e})}if(e.type==="FragmentSelector"){const o=xi.exec(e.value);if(o){const c={type:"BoxSelector",spatial:{unit:o[2]==="percent:"||o[2]==="pct:"?"percent":"pixel",x:parseFloat(o[3]),y:parseFloat(o[4]),width:parseFloat(o[5]),height:parseFloat(o[6])}};return k({selector:c,selectors:[c],iiifRenderingHints:i})}const a=e.value.match(bi);if(a){const c={type:"TemporalSelector",temporal:{startTime:a[4]?parseFloat(a[4]):0,endTime:a[7]?parseFloat(a[7]):void 0}};return k({selector:c,selectors:[c],iiifRenderingHints:i})}return k({selector:null,selectors:[],iiifRenderingHints:i})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window!="undefined"?t=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let o=[],a,c,u=(r=n==null?void 0:n(e.value))!=null?r:e.value,f;if(t){const h=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!h)return console.warn(`Illegal SVG selector: ${e.value}`),k({selector:null,selectors:[],iiifRenderingHints:i});const g=Ee(h);g&&(o=g.points,f=g.shapeType,a=[Math.min(...o.map(l=>l[0])),Math.min(...o.map(l=>l[1])),Math.max(...o.map(l=>l[0])),Math.max(...o.map(l=>l[1]))],{style:c,svg:u}=(s=Ai(g.element))!=null?s:{svg:u})}const p={type:"SvgSelector",svg:u,svgShape:f,style:c,points:o.length?o:void 0,spatial:a?{unit:"pixel",x:a[0],y:a[1],width:a[2]-a[0],height:a[3]-a[1]}:void 0};return k({selector:p,selectors:[p],iiifRenderingHints:i})}return k({selector:null,selectors:[],iiifRenderingHints:i})}function wi(e){const t=e.map(i=>i[0]).reduce((i,r)=>(i[r]+=1,i),{C:0,Q:0,L:0,M:0}),n=new Set(e.map(i=>i[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(n.size===1||n.size===2&&n.has("M"))){if(t.L===4)return"rect";const i=e.slice(-1)[0];return e[0][0]==="M"&&i[0]==="L"&&i[1]==e[0][1]&&i[2]===e[0][2]||i[1]===0&&i[2]===0?"polygon":"polyline"}return"path"}function Ee(e){var t,n,i,r,s,o,a,c,u,f,p,h,g,l,m,v,b;for(const d of Array.from(e.children))switch(d==null?void 0:d.tagName.toLowerCase()){case"g":{const y=Ee(d);if(y)return y}continue;case"path":{const y=d.getAttribute("d");if(!y)continue;const w=gi(y);return{element:d,points:Si(w),shapeType:wi(w)}}case"circle":{const y=parseFloat((t=d.getAttribute("cx"))!=null?t:"0"),w=parseFloat((n=d.getAttribute("cy"))!=null?n:"0"),S=parseFloat((i=d.getAttribute("r"))!=null?i:"0");if(!S)continue;const A=[];for(let C=0;C<=360;C+=12){const O=C*Math.PI/180;A.push([y+S*Math.cos(O),w+S*Math.sin(O)])}return{element:d,points:A,shapeType:"circle"}}case"ellipse":{const y=parseFloat((r=d.getAttribute("cx"))!=null?r:"0"),w=parseFloat((s=d.getAttribute("cy"))!=null?s:"0"),S=parseFloat((o=d.getAttribute("rx"))!=null?o:"0"),A=parseFloat((a=d.getAttribute("ry"))!=null?a:"0");if(!S&&!A)continue;const C=[];for(let O=0;O<=360;O+=12){const R=Math.tan(O/360*Math.PI),L=S*(1-R**2)/(1+R**2),j=A*2*R/(1+R**2);C.push([y+L,w+j])}return{element:d,points:C,shapeType:"ellipse"}}case"line":{const y=parseFloat((c=d.getAttribute("x0"))!=null?c:"0"),w=parseFloat((u=d.getAttribute("y0"))!=null?u:"0"),S=parseFloat((f=d.getAttribute("x1"))!=null?f:"0"),A=parseFloat((p=d.getAttribute("y1"))!=null?p:"0");if(y===S&&w===A)continue;return{element:d,points:[[y,w],[S,A]],shapeType:"polyline"}}case"polygon":case"polyline":{const y=(g=(h=d.getAttribute("points"))==null?void 0:h.split(" ").map(S=>S.split(",").map(parseFloat)))!=null?g:[];if(!y.length)continue;let w="polyline";return d.tagName.toLowerCase()==="polygon"&&(y.push(y[0]),w="polygon"),{element:d,points:y,shapeType:w}}case"rect":{const y=parseFloat((l=d.getAttribute("x"))!=null?l:"0"),w=parseFloat((m=d.getAttribute("y"))!=null?m:"0"),S=parseFloat((v=d.getAttribute("width"))!=null?v:"0"),A=parseFloat((b=d.getAttribute("height"))!=null?b:"0");if(!S||!A)continue;return{element:d,points:[[y,w],[y+S,w],[y+S,w+A],[y,w+A],[y,w]],shapeType:"rect"}}default:continue}return null}function Si(e){var n;const t=[];for(let i=0;i<e.length;i++){const r=(n=t[t.length-1])!=null?n:[0,0],s=e[i];switch(s[0]){case"M":case"L":t.push([s[1],s[2]]);continue;case"C":t.push(...mi({x:r[0],y:r[1]},{x:s[1],y:s[2]},{x:s[3],y:s[4]},{x:s[5],y:s[6]}).map(o=>[o.x,o.y]).slice(1));continue;case"Q":t.push(...yi({x:r[0],y:r[1]},{x:s[1],y:s[2]},{x:s[3],y:s[4]}).map(o=>[o.x,o.y]).slice(1));continue}}return t}function Ai(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const i=Ne.exec(t.fill);i&&(t.fillOpacity=parseFloat(i[4]),t.fill=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const i=Ne.exec(t.stroke);i&&(t.strokeOpacity=parseFloat(i[4]),t.stroke=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let n=e;for(;n.tagName.toLowerCase()!=="svg";)if(n=n.parentElement,n===null)throw new Error("Could not find root SVG element");return{svg:n.outerHTML,style:Object.keys(t).length>0?t:void 0}}function Ue(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function k(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const n=De(t.rotation);if(n)if(e.selectors.length)for(const i of e.selectors)i.rotation=n;else e.selectors.push({type:"RotationSelector",rotation:n})}}else delete e.iiifRenderingHints;return e}function De(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function z(e,t={}){if(Array.isArray(e))return z(e[0]);if(typeof e=="string"){const[n,i]=e.split("#");return i?z({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return z(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:i}=e.selector?D(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:i}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,i]=e.id.split("#");return i?z({type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{...e,id:n},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function re(e,t=!1){if(typeof e=="string"){if(e.startsWith("{"))try{const n=JSON.parse(e);return re(n)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(e)){for(const n of e){const[i,r]=re(n);if(!i&&r)return[i,r]}return[!0]}return e.type==="Annotation"?[!0]:t&&e.type==="Canvas"&&!e.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function Fi(e){return Xe(typeof e=="string"?e:JSON.stringify(e))}function Je(e,t){if(e=e.trim(),e[0]==="{")return t?Promise.resolve(JSON.parse(e)):JSON.parse(e);if(e.startsWith("http")){if(!t)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(e).then(n=>n.json())}return Je(Ge(e),t)}function Xe(e){const t=encodeURIComponent(e);return(typeof btoa=="undefined"?Buffer.from(t,"utf-8").toString("base64"):btoa(t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Ge(e){const n=Mi(e).replace(/-/g,"+").replace(/_/g,"/"),i=typeof atob=="undefined"?Buffer.from(n,"base64").toString("utf-8"):atob(n);return decodeURIComponent(i).trim()}function Mi(e){const t=e.length%4;if(t===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return e+(t?"====".slice(0,4-t):"")}function Ci(e){if(!e)throw new Error("Content state is empty");Array.isArray(e)||(e=[e]);let t="vault://virtual-annotation/"+new Date().getTime();const n=[];for(const i of e){if(typeof i=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(i.type==="Annotation"){if(t=i.id,Array.isArray(i.motivation))for(const s of i.motivation);if(Array.isArray(i.target))for(const s of i.target){const o=z(s);n.push(o)}else{const s=z(i.target);n.push(s)}continue}const r=z(i);n.push(r)}return{id:t,type:"Annotation",motivation:["contentState",...e.motivation||[]],target:n,extensions:{}}}function Ye(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Oi(e=I){function t(r){const s=r?typeof r=="string"?e.get(r):r:null;if(!s)return[];const o=e.get(s.items),a=[];for(const c of o)a.push(...e.get(c.items));return a}function n(r,s=[]){const o=Array.isArray(r)?r:t(r),a=[];let c=null;const u=[];for(const f of o){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const p=e.get(f.body),h=Array.isArray(p)?p:[p];for(const g of h){const[l,{selector:m}]=Ye(g),v=(l.type||"unknown").toLowerCase();if(v==="choice"){const b=e.get(l.items),d=s.length?s.map(y=>b.find(w=>w.id===y)).filter(Boolean):[b[0]];d.length===0&&d.push(b[0]),c={type:"single-choice",items:b.map(y=>({id:y.id,label:y.label,selected:d.indexOf(y)!==-1})),label:g.label},h.push(...d);continue}a.indexOf(v)===-1&&a.push(v),u.push({type:v,resource:l,target:f.target,selector:m})}}return{types:a,items:u,choice:c}}function i(r){const{choice:s}=n(r);return s}return{getAllPaintingAnnotations:t,getPaintables:n,extractChoices:i}}function M(e,t,n){t[N]=t[N]||[],t[N].push(e),Object.defineProperty(t,e,{get(){if(typeof t[H][e]=="undefined")return;const i=t[H][e];return i&&$(n.get(t[H][e]),n)},set(i){t[H][e]!==i&&(this[H][e]=i)}})}const H=Symbol.for("_refs_"),V=Symbol.for("_reactive_"),N=Symbol.for("_defined_");function ki(e,t=!1){const n={id:null,[N]:[],[H]:{},[V]:null,is(i){return typeof i=="string"?this.id===i:i.id?i.id===this.id:!1},reactive(){if(!this[V])return this[V]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const i=this.unwrap();for(const r of Object.keys(i||{}))this[N].includes(r)?this[H][r]=i[r]:this[r]=i[r]}},unreactive(){this[V]&&(this[V](),this[V]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");return e.get(this.id)},toPresentation3(){return e.toPresentation3(this.unwrap())},toPresentation2(){return e.toPresentation2(this.unwrap())},toJSON(){const i=this;return{...i,items:i.items,annotations:i.annotations,structures:i.structures,seeAlso:i.seeAlso,service:i.service,services:i.services,rendering:i.rendering,partOf:i.partOf,start:i.start,supplementary:i.supplementary,homepage:i.homepage,thumbnail:i.thumbnail,placeholderCanvas:i.placeholderCanvas,accompanyingCanvas:i.accompanyingCanvas,provider:i.provider}},subscribe(i,r=!0){return e.subscribe(()=>this.id?e.get(this.id):null,i,r)}};return M("items",n,e),M("annotations",n,e),M("structures",n,e),M("seeAlso",n,e),M("service",n,e),M("services",n,e),M("rendering",n,e),M("partOf",n,e),M("start",n,e),M("supplementary",n,e),M("homepage",n,e),M("thumbnail",n,e),M("placeholderCanvas",n,e),M("accompanyingCanvas",n,e),M("provider",n,e),M("body",n,e),M("logo",n,e),n}function Ze(e){return Array.isArray(e)?e.map(t=>Ze(t)):!e||!e.type?e:{id:e.id,type:e.type}}function $(e,t,n=!1){if(Array.isArray(e))return e.map(o=>$(o,t,n));if(!e||!e.type||!e.id)return e;const i=ki(t,n),r=Object.create(i),s=Object.assign(r,e);return n&&s.reactive(),s}function Ri(e){return{get(t,n=!1){return $(e.get(t),e,n)},async load(t,n){return $(await e.load(t,n),e)},async loadManifest(t,n){return $(await e.loadManifest(t,n),e)},async loadCollection(t,n){return $(await e.loadCollection(t,n),e)},wrapObject(t){return $(e.get(t,{skipSelfReturn:!1}),e)},isWrapped(t){return!!t[N]}}}function ji(e=I){return{findFirstCanvasFromRange:t=>se(e,t),findAllCanvasesInRange:t=>G(e,t),findManifestSelectedRange:(t,n)=>Ke(e,t,n),findSelectedRange:(t,n)=>Y(e,t,n)}}function se(e,t){for(const n of t.items){if(n.type==="Canvas")return n;if(n.type==="Range"){const i=se(e,e.get(n));if(i)return i}}return null}function G(e,t){const n=[];for(const i of t.items)if(i.type==="Canvas"&&(i.id.indexOf("#")!==-1?n.push({id:i.id.split("#")[0],type:"Canvas"}):n.push(i)),i.type==="Range"&&n.push(...G(e,e.get(i))),i.type==="SpecificResource"){const r=typeof i.source=="string"?i.source:i.source.id;n.push({id:r,type:"Canvas"})}return n}function Ke(e,t,n){for(const i of t.structures){const r=Y(e,e.get(i),n);if(r)return r}return null}function Y(e,t,n){var i;for(const r of t.items){const s=(i=r.id)==null?void 0:i.split("#")[0];if(r.type==="SpecificResource"&&r.source===n||r.type==="Canvas"&&n===s)return t;if(r.type==="Range"){const o=Y(e,e.get(r),n);if(o)return o}}return null}function Ii(e=I){return{getVisibleCanvasesFromCanvasId:(t,n,i=!1)=>et(e,t,n,i),getManifestSequence:(t,n={})=>oe(e,t,n)}}function et(e=I,t,n,i=!1){const r=t.behavior||[],s=n?e.get(n):null;if(!s)return[];const o=s.behavior||[],a=i?!1:r.includes("paged"),c=a?!1:r.includes("continuous"),u=a||c?!1:r.includes("individuals"),f=o.includes("facing-pages"),p=o.includes("non-paged");if(f||p||u||i)return[{id:s.id,type:"Canvas"}];const[h,g]=oe(e,t);if(c)return h;const l=h.findIndex(m=>m.id===n);if(l===-1)return[];for(const m of g)if(m.includes(l))return m.map(v=>h[v]);return[{id:s.id,type:"Canvas"}]}function oe(e=I,t,{disablePaging:n,skipNonPaged:i}={}){const r=t.behavior||[],s=r.includes("paged"),o=s?!1:r.includes("continuous"),a=s||o?!1:r.includes("individuals"),c=t.type==="Manifest"?t.items:G(e,t);if(o)return[c,[c.map((l,m)=>m)]];if(a||!s||n)return[c,c.map((l,m)=>[m])];const u=[];let f=[];const p=()=>{f.length&&(u.push([...f]),f=[])};let h=0,g=!1;for(let l=0;l<c.length;l++){const v=e.get(c[l]).behavior||[];if(v.includes("non-paged")){l===h&&h++,i||(p(),u.push([l]),p());continue}if(l===h||v.includes("facing-pages")){f.length&&(g=!0),p(),u.push([l]),p();continue}if(f.push(l),g){p(),g=!1;continue}f.length>1&&p()}return f.length&&p(),[c,u]}x.buildLocaleString=_e,x.createEventsHelper=st,x.createObjectsHelper=Ri,x.createPaintingAnnotationsHelper=Oi,x.createRangeHelper=ji,x.createSequenceHelper=Ii,x.createStylesHelper=ot,x.createThumbnailHelper=ii,x.decodeContentState=Ge,x.encodeContentState=Xe,x.expandTarget=z,x.findAllCanvasesInRange=G,x.findFirstCanvasFromRange=se,x.findManifestSelectedRange=Ke,x.findSelectedRange=Y,x.getClosestLanguage=Le,x.getManifestSequence=oe,x.getValue=ni,x.getVisibleCanvasesFromCanvasId=et,x.isImageApiSelector=Ue,x.normaliseContentState=Ci,x.parseContentState=Je,x.parseRotation=De,x.parseSelector=D,x.parseSpecificResource=Ye,x.serialiseContentState=Fi,x.unwrapObject=Ze,x.validateContentState=re,x.wrapObject=$,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
//# sourceMappingURL=index.umd.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function b(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function w(e){function p(t){const n=t?typeof t=="string"?e.get(t):t:null;if(!n)return[];const a=e.get(n.items),o=[];for(const s of a)o.push(...e.get(s.items));return o}function g(t,n=[]){const a=Array.isArray(t)?t:p(t),o=[];let s=null;const d=[];for(const f of a){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const h=e.get(f.body);for(const y of h){const[u,{selector:A}]=b(y),c=(u.type||"unknown").toLowerCase();if(c==="choice"){const r=e.get(u.items),l=n.length?n.map(i=>r.find(P=>P.id===i)).filter(Boolean):[r[0]];l.length===0&&l.push(r[0]),s={type:"single-choice",items:r.map(i=>({id:i.id,label:i.label,selected:l.indexOf(i)!==-1})),label:y.label},h.push(...l);continue}o.indexOf(c)===-1&&o.push(c),d.push({type:c,resource:u,target:f.target,selector:A})}}return{types:o,items:d,choice:s}}function m(t){const{choice:n}=g(t);return n}return{getAllPaintingAnnotations:p,getPaintables:g,extractChoices:m}}exports.createPaintingAnnotationsHelper=w;exports.parseSpecificResource=b;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function w(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const g={},P={get(e){return e},setMetaValue([e,n,o],c){const t=P.getResourceMeta(e,n),s=t?t[o]:void 0,r=typeof c=="function"?c(s):c;g[e]={...g[e]||{},[n]:{...(g[e]||{})[n]||{},[o]:r}}},getResourceMeta:(e,n)=>{const o=g[e];if(!!o)return n?o[n]:o}};function R(e=P){function n(t){const s=t?typeof t=="string"?e.get(t):t:null;if(!s)return[];const r=e.get(s.items),i=[];for(const l of r)i.push(...e.get(l.items));return i}function o(t,s=[]){const r=Array.isArray(t)?t:n(t),i=[];let l=null;const A=[];for(const d of r){if(d.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const y=e.get(d.body),b=Array.isArray(y)?y:[y];for(const m of b){const[h,{selector:M}]=w(m),u=(h.type||"unknown").toLowerCase();if(u==="choice"){const f=e.get(h.items),p=s.length?s.map(a=>f.find(S=>S.id===a)).filter(Boolean):[f[0]];p.length===0&&p.push(f[0]),l={type:"single-choice",items:f.map(a=>({id:a.id,label:a.label,selected:p.indexOf(a)!==-1})),label:m.label},b.push(...p);continue}i.indexOf(u)===-1&&i.push(u),A.push({type:u,resource:h,target:d.target,selector:M})}}return{types:i,items:A,choice:l}}function c(t){const{choice:s}=o(t);return s}return{getAllPaintingAnnotations:n,getPaintables:o,extractChoices:c}}exports.createPaintingAnnotationsHelper=R;exports.parseSpecificResource=w;
//# sourceMappingURL=painting-annotations.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function d(i){return{findFirstCanvasFromRange:t=>f(i,t),findAllCanvasesInRange:t=>o(i,t),findManifestSelectedRange:(t,e)=>c(i,t,e),findSelectedRange:(t,e)=>s(i,t,e)}}function f(i,t){for(const e of t.items){if(e.type==="Canvas")return e;if(e.type==="Range"){const n=f(i,i.get(e));if(n)return n}}return null}function o(i,t){const e=[];for(const n of t.items)if(n.type==="Canvas"&&(n.id.indexOf("#")!==-1?e.push({id:n.id.split("#")[0],type:"Canvas"}):e.push(n)),n.type==="Range"&&e.push(...o(i,i.get(n))),n.type==="SpecificResource"){const r=typeof n.source=="string"?n.source:n.source.id;e.push({id:r,type:"Canvas"})}return e}function c(i,t,e){for(const n of t.structures){const r=s(i,i.get(n),e);if(r)return r}return null}function s(i,t,e){var n;for(const r of t.items){const u=(n=r.id)==null?void 0:n.split("#")[0];if(r.type==="SpecificResource"&&r.source===e||r.type==="Canvas"&&e===u)return t;if(r.type==="Range"){const a=s(i,i.get(r),e);if(a)return a}}return null}exports.createRangeHelper=d;exports.findAllCanvasesInRange=o;exports.findFirstCanvasFromRange=f;exports.findManifestSelectedRange=c;exports.findSelectedRange=s;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o={},d={get(n){return n},setMetaValue([n,t,e],r){const s=d.getResourceMeta(n,t),c=s?s[e]:void 0,i=typeof r=="function"?r(c):r;o[n]={...o[n]||{},[t]:{...(o[n]||{})[t]||{},[e]:i}}},getResourceMeta:(n,t)=>{const e=o[n];if(!!e)return t?e[t]:e}};function l(n=d){return{findFirstCanvasFromRange:t=>u(n,t),findAllCanvasesInRange:t=>a(n,t),findManifestSelectedRange:(t,e)=>g(n,t,e),findSelectedRange:(t,e)=>f(n,t,e)}}function u(n,t){for(const e of t.items){if(e.type==="Canvas")return e;if(e.type==="Range"){const r=u(n,n.get(e));if(r)return r}}return null}function a(n,t){const e=[];for(const r of t.items)if(r.type==="Canvas"&&(r.id.indexOf("#")!==-1?e.push({id:r.id.split("#")[0],type:"Canvas"}):e.push(r)),r.type==="Range"&&e.push(...a(n,n.get(r))),r.type==="SpecificResource"){const s=typeof r.source=="string"?r.source:r.source.id;e.push({id:s,type:"Canvas"})}return e}function g(n,t,e){for(const r of t.structures){const s=f(n,n.get(r),e);if(s)return s}return null}function f(n,t,e){var r;for(const s of t.items){const c=(r=s.id)==null?void 0:r.split("#")[0];if(s.type==="SpecificResource"&&s.source===e||s.type==="Canvas"&&e===c)return t;if(s.type==="Range"){const i=f(n,n.get(s),e);if(i)return i}}return null}exports.createRangeHelper=l;exports.findAllCanvasesInRange=a;exports.findFirstCanvasFromRange=u;exports.findManifestSelectedRange=g;exports.findSelectedRange=f;
//# sourceMappingURL=ranges.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function C(t,s){const n=[];for(const e of s.items)if(e.type==="Canvas"&&(e.id.indexOf("#")!==-1?n.push({id:e.id.split("#")[0],type:"Canvas"}):n.push(e)),e.type==="Range"&&n.push(...C(t,t.get(e))),e.type==="SpecificResource"){const u=typeof e.source=="string"?e.source:e.source.id;n.push({id:u,type:"Canvas"})}return n}function m(t){return{getVisibleCanvasesFromCanvasId:(s,n,e=!1)=>b(t,s,n,e),getManifestSequence:(s,n={})=>h(t,s,n)}}function b(t,s,n,e=!1){const u=s.behavior,f=n?t.get(n):null;if(!f)return[];const g=f.behavior,v=e?!1:u.includes("paged"),a=v?!1:u.includes("continuous"),l=v||a?!1:u.includes("individuals"),c=g.includes("facing-pages"),r=g.includes("non-paged");if(c||r||l||e)return[{id:f.id,type:"Canvas"}];const[d,p]=h(t,s);if(a)return d;const i=d.findIndex(o=>o.id===n);if(i===-1)return[];for(const o of p)if(o.includes(i))return o.map(y=>d[y]);return[{id:f.id,type:"Canvas"}]}function h(t,s,{disablePaging:n,skipNonPaged:e}={}){const u=s.behavior,f=u.includes("paged"),g=f?!1:u.includes("continuous"),v=f||g?!1:u.includes("individuals"),a=s.type==="Manifest"?s.items:C(t,s);if(g)return[a,[a.map((i,o)=>o)]];if(v||!f||n)return[a,a.map((i,o)=>[o])];const l=[];let c=[];const r=()=>{c.length&&(l.push([...c]),c=[])};let d=0,p=!1;for(let i=0;i<a.length;i++){const o=t.get(a[i]);if(o.behavior.includes("non-paged")){i===d&&d++,e||(r(),l.push([i]),r());continue}if(i===d||o.behavior.includes("facing-pages")){c.length&&(p=!0),r(),l.push([i]),r();continue}if(c.push(i),p){r(),p=!1;continue}c.length>1&&r()}return c.length&&r(),[a,l]}exports.createSequenceHelper=m;exports.getManifestSequence=h;exports.getVisibleCanvasesFromCanvasId=b;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const C={},b={get(s){return s},setMetaValue([s,t,e],n){const o=b.getResourceMeta(s,t),a=o?o[e]:void 0,l=typeof n=="function"?n(a):n;C[s]={...C[s]||{},[t]:{...(C[s]||{})[t]||{},[e]:l}}},getResourceMeta:(s,t)=>{const e=C[s];if(!!e)return t?e[t]:e}};function M(s,t){const e=[];for(const n of t.items)if(n.type==="Canvas"&&(n.id.indexOf("#")!==-1?e.push({id:n.id.split("#")[0],type:"Canvas"}):e.push(n)),n.type==="Range"&&e.push(...M(s,s.get(n))),n.type==="SpecificResource"){const o=typeof n.source=="string"?n.source:n.source.id;e.push({id:o,type:"Canvas"})}return e}function y(s=b){return{getVisibleCanvasesFromCanvasId:(t,e,n=!1)=>m(s,t,e,n),getManifestSequence:(t,e={})=>I(s,t,e)}}function m(s=b,t,e,n=!1){const o=t.behavior||[],a=e?s.get(e):null;if(!a)return[];const l=a.behavior||[],v=n?!1:o.includes("paged"),u=v?!1:o.includes("continuous"),g=v||u?!1:o.includes("individuals"),c=l.includes("facing-pages"),r=l.includes("non-paged");if(c||r||g||n)return[{id:a.id,type:"Canvas"}];const[d,p]=I(s,t);if(u)return d;const i=d.findIndex(f=>f.id===e);if(i===-1)return[];for(const f of p)if(f.includes(i))return f.map(h=>d[h]);return[{id:a.id,type:"Canvas"}]}function I(s=b,t,{disablePaging:e,skipNonPaged:n}={}){const o=t.behavior||[],a=o.includes("paged"),l=a?!1:o.includes("continuous"),v=a||l?!1:o.includes("individuals"),u=t.type==="Manifest"?t.items:M(s,t);if(l)return[u,[u.map((i,f)=>f)]];if(v||!a||e)return[u,u.map((i,f)=>[f])];const g=[];let c=[];const r=()=>{c.length&&(g.push([...c]),c=[])};let d=0,p=!1;for(let i=0;i<u.length;i++){const h=s.get(u[i]).behavior||[];if(h.includes("non-paged")){i===d&&d++,n||(r(),g.push([i]),r());continue}if(i===d||h.includes("facing-pages")){c.length&&(p=!0),r(),g.push([i]),r();continue}if(c.push(i),p){r(),p=!1;continue}c.length>1&&r()}return c.length&&r(),[u,g]}exports.createSequenceHelper=y;exports.getManifestSequence=I;exports.getVisibleCanvasesFromCanvasId=m;
//# sourceMappingURL=sequences.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function n(l){return{applyStyles(e,t,s){const i=typeof e=="string"?e:e.id;return l.setMetaValue([i,"styles",t],s)},getAppliedStyles(e){const t=typeof e=="string"?e:e.id;return l.getResourceMeta(t,"styles")}}}exports.createStylesHelper=n;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r={},l={get(t){return t},setMetaValue([t,e,n],s){const o=l.getResourceMeta(t,e),u=o?o[n]:void 0,a=typeof s=="function"?s(u):s;r[t]={...r[t]||{},[e]:{...(r[t]||{})[e]||{},[n]:a}}},getResourceMeta:(t,e)=>{const n=r[t];if(!!n)return e?n[e]:n}};function c(t=l){return{applyStyles(e,n,s){const o=typeof e=="string"?e:e.id;return t.setMetaValue([o,"styles",n],s)},getAppliedStyles(e){const n=typeof e=="string"?e:e.id;return t.getResourceMeta(n,"styles")}}}exports.createStylesHelper=c;
//# sourceMappingURL=styles.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var u=require("@atlas-viewer/iiif-image-api");function b(s,m={}){const r=m.imageServiceLoader||new u.ImageServiceLoader;async function l(g,n,o,c=[],a){if(typeof g=="string")return{best:u.getFixedSizeFromImage(g),fallback:[],log:[]};const t=s.get(g);if(typeof t=="string")return{best:u.getFixedSizeFromImage(t),fallback:[],log:[]};switch(t.type){case"Annotation":{const e=t.body,i=s.get(e[0]);return a&&!i.width&&(i.width=a.width,i.height=a.height),await r.getThumbnailFromResource(i,n,o,c)}case"Canvas":{const e=t;if(e.thumbnail&&e.thumbnail.length){const i=s.get(e.thumbnail[0]),h=await r.getImageCandidates(i,o);h&&h.length&&c.push(...h)}return l(e.items[0],n,o,c,{width:e.width,height:e.height})}case"AnnotationPage":return l(t.items[0],n,o,c,a);case"Choice":return l(t.items[0],n,o,c,a);case"Collection":{const i=t.items[0];return l(i,n,o,c,a)}case"Manifest":{const i=t.items[0];return l(i,n,o,c,a)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return a&&!t.width&&(t.width=a.width,t.height=a.height),r.getThumbnailFromResource(t,n,o,c);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:l}}exports.createThumbnailHelper=b;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var b=require("@atlas-viewer/iiif-image-api");const m={},w={get(o){return o},setMetaValue([o,l,e],s){const h=w.getResourceMeta(o,l),n=h?h[e]:void 0,i=typeof s=="function"?s(n):s;m[o]={...m[o]||{},[l]:{...(m[o]||{})[l]||{},[e]:i}}},getResourceMeta:(o,l)=>{const e=m[o];if(!!e)return l?e[l]:e}};function p(o=w,l={}){const e=l.imageServiceLoader||new b.ImageServiceLoader;async function s(h,n,i,r=[],u){const g=()=>e.getThumbnailFromResource(void 0,n,i,r);if(!h)return await e.getThumbnailFromResource(void 0,n,i,r);if(typeof h=="string"){const t=b.getFixedSizeFromImage(h);return t&&r.push(t),await e.getThumbnailFromResource(void 0,n,i,r)}const a=o.get(h,{skipSelfReturn:!1});if(typeof a=="string")return{best:b.getFixedSizeFromImage(a),fallback:[],log:[]};if(!a)return await g();switch(await(async t=>{if(t&&t.thumbnail&&t.thumbnail.length){const c=o.get(t.thumbnail[0]),f=await e.getImageCandidates(c,i);f&&f.length&&r.push(...f)}})(a),a.type){case"Annotation":{const t=Array.isArray(a.body)?a.body:[a.body],c=o.get(t[0]);return u&&!c.width&&(c.width=u.width,c.height=u.height),await e.getThumbnailFromResource(c,n,i,r)}case"Canvas":{const t=a;return s(t.items[0],n,i,r,{width:t.width,height:t.height})}case"AnnotationPage":return s(a.items[0],n,i,r,u);case"Choice":{const t=a;return!t.items||t.items[0]?await g():s(t.items[0],n,i,r,u)}case"Collection":{const c=a.items[0];return c?s(c,n,i,r,u):await g()}case"Manifest":{const c=a.items[0];return c?s(c,n,i,r,u):await g()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return u&&!a.width&&(a.width=u.width,a.height=u.height),e.getThumbnailFromResource(a,n,i,r);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return await g()}return await g()}return{getBestThumbnailAtSize:s}}exports.createThumbnailHelper=p;
//# sourceMappingURL=thumbnail.js.map
{
"name": "@iiif/vault-helpers",
"version": "0.9.11",
"version": "0.10.0",
"license": "MIT",

@@ -47,2 +47,6 @@ "main": "dist/cjs/index.js",

},
"./fetch": {
"require": "./dist/fetch/cjs/fetch.js",
"import": "./dist/fetch/esm/fetch.mjs"
},
"./painting-annotations": {

@@ -100,2 +104,5 @@ "require": "./dist/painting-annotations/cjs/painting-annotations.js",

],
"fetch": [
".build/types/fetch.d.ts"
],
"sequences": [

@@ -123,7 +130,7 @@ ".build/types/sequences.d.ts"

"peerDependencies": {
"@atlas-viewer/iiif-image-api": "2.x",
"@atlas-viewer/iiif-image-api": "^2.1.1",
"@iiif/vault": "0.9.x"
},
"devDependencies": {
"@atlas-viewer/iiif-image-api": "^2.0.5",
"@atlas-viewer/iiif-image-api": "^2.1.1",
"@iiif/vault": "^0.9.19",

@@ -143,2 +150,3 @@ "@iiif/parser": "^1.0.10",

"jsdom": "^20.0.0",
"node-fetch": "3.3.0",
"prettier": "^2.5.1",

@@ -145,0 +153,0 @@ "react": "17.0.2",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc