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.8 to 0.9.10

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

2

.build/types/annotation-targets/expand-target.d.ts

@@ -5,2 +5,4 @@ import { W3CAnnotationTarget } from '@iiif/presentation-3';

typeMap?: Record<string, string>;
domParser?: DOMParser;
svgPreprocessor?: (svg: string) => string;
}): SupportedTarget;

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

import { ParsedSelector } from './selector-types';
import { ParsedSelector, SvgShapeType } from './selector-types';
import { Selector } from '@iiif/presentation-3';
export declare function parseSelector(source: Selector | Selector[]): ParsedSelector;
export declare function parseSelector(source: Selector | Selector[], { domParser, svgPreprocessor }?: {
domParser?: DOMParser;
svgPreprocessor?: (svg: string) => string;
}): ParsedSelector;
export declare type SelectorElement = {
element: SVGElement;
points: [number, number][];
shapeType: SvgShapeType;
};

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

export declare type SvgShapeType = 'rect' | 'circle' | 'ellipse' | 'line' | 'polyline' | 'polygon' | 'path';
export interface SupportedSelector {

@@ -14,3 +15,15 @@ type: string;

};
points?: [number, number][];
svg?: string;
svgShape?: SvgShapeType;
style?: SelectorStyle;
}
export interface SelectorStyle {
fill?: string;
fillOpacity?: number;
stroke?: string;
strokeOpacity?: number;
strokeWidth?: string;
strokeDasharray?: string;
}
export interface BoxSelector extends SupportedSelector {

@@ -33,2 +46,15 @@ type: 'BoxSelector';

}
export interface SvgSelector extends SupportedSelector {
type: 'SvgSelector';
svg: string;
svgShape?: SvgShapeType;
points?: [number, number][];
spatial?: {
unit: 'pixel';
x: number;
y: number;
width: number;
height: number;
};
}
export interface TemporalSelector extends SupportedSelector {

@@ -55,3 +81,3 @@ type: 'TemporalSelector';

}
export declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector | PointSelector;
export declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector | PointSelector | SvgSelector;
export declare type ParsedSelector = {

@@ -58,0 +84,0 @@ selector: SupportedSelectors | null;

@@ -8,1 +8,2 @@ export * from './events';

export * from './painting-annotations';
export * from './objects';

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

"use strict";var f=Object.defineProperty,y=Object.defineProperties;var a=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;var i=(e,t,r)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,l=(e,t)=>{for(var r in t||(t={}))S.call(t,r)&&i(e,r,t[r]);if(p)for(var r of p(t))m.call(t,r)&&i(e,r,t[r]);return e},n=(e,t)=>y(e,a(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,O=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function o(e){if(Array.isArray(e))return e.reduce((t,r)=>{const{selector:s,selectors:u}=o(r);return s&&(t.selector||(t.selector=s),t.selectors.push(...u)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,r]=e.split("#");return r?o({type:"FragmentSelector",value:r}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=d.exec(e.value);if(t){const s={type:"BoxSelector",spatial:{unit:t[2]==="percent:"||t[2]==="pct:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:s,selectors:[s]}}const r=e.value.match(O);if(r){const s={type:"TemporalSelector",temporal:{startTime:r[4]?parseFloat(r[4]):0,endTime:r[7]?parseFloat(r[7]):void 0}};return{selector:s,selectors:[s]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}function c(e,t={}){if(Array.isArray(e))return c(e[0]);if(typeof e=="string"){const[r,s]=e.split("#");return s?c({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:s}}):{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 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:r,selectors:s}=e.selector?o(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:s}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,s]=e.id.split("#");return s?c({type:"SpecificResource",source:n(l({},e),{id:r}),selector:{type:"FragmentSelector",value:s}}):{type:"SpecificResource",source:n(l({},e),{id:r}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}exports.expandTarget=c;exports.parseSelector=o;
"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.
*
* All code in this module is based on JavaScript code by Raph Levien, published on his blog at
* https://raphlinus.github.io/.
* I merely changed the structure a bit, removed some unneeded parts and added some comments and type hints.
*
* Flattening of quadratic Bézier curves:
* - Article: https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html
* - Code: https://github.com/raphlinus/raphlinus.github.io/blob/master/_posts/2019-12-23-flatten-quadbez.md?plain=1#L73-L212
*
* Flattening of cubic Bézier curves: https://levien.com/tmp/flatten.html
*
* Note that the code in this module has a different license than the rest of the package,
* due to the inclusion of Apache-licensed third party code.
*
* @license
* Copyright 2022 Johannes Baiter <johannes.baiter@gmail.com>
* Copyright 2019, 2022 Raph Levien <raph.levien@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* 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;
//# sourceMappingURL=annotation-targets.js.map

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

"use strict";var xe=Object.defineProperty,ve=Object.defineProperties;var we=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var B=(e,t,i)=>t in e?xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,C=(e,t)=>{for(var i in t||(t={}))be.call(t,i)&&B(e,i,t[i]);if(z)for(var i of z(t))Se.call(t,i)&&B(e,i,t[i]);return e},k=(e,t)=>ve(e,we(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function Oe(e){return{addEventListener(t,i,r,o){if(!!t)return e.setMetaValue([t.id,"eventManager",i],n=>{const s=n||[];for(const a of s)if(a.callback===r)return s;return[...s,{callback:r,scope:o}]}),r},removeEventListener(t,i,r){!t||e.setMetaValue([t.id,"eventManager",i],o=>(o||[]).filter(n=>n.callback!==r))},getListenersAsProps(t,i){const r=typeof t=="string"?{id:t}:t;if(!r||!r.id)return{};const o=e.getResourceMeta(r.id,"eventManager"),n={};if(o&&r)for(const s of Object.keys(o))n[s]=a=>{const f=e.get(r);for(const{callback:l,scope:c}of o[s]||[])(!c||i&&c.indexOf(i)!==-1)&&l(a,f)};return n}}}function Ae(e){return{applyStyles(t,i,r){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",i],r)},getAppliedStyles(t){const i=typeof t=="string"?t:t.id;return e.getResourceMeta(i,"styles")}}}function x(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}const Fe="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Q="http://library.stanford.edu/iiif/image-api/compliance.html#level1",q="http://library.stanford.edu/iiif/image-api/compliance.html#level2",je="http://library.stanford.edu/iiif/image-api/conformance.html#level0",N="http://library.stanford.edu/iiif/image-api/conformance.html#level1",U="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ce="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",_="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",J="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ke="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",V="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",D="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Re="http://iiif.io/api/image/1/level0.json",Ie="http://iiif.io/api/image/1/profiles/level0.json",Z="http://iiif.io/api/image/1/level1.json",G="http://iiif.io/api/image/1/profiles/level1.json",K="http://iiif.io/api/image/1/level2.json",X="http://iiif.io/api/image/1/profiles/level2.json",Pe="http://iiif.io/api/image/2/level0.json",We="http://iiif.io/api/image/2/profiles/level0.json",Y="http://iiif.io/api/image/2/level1.json",ee="http://iiif.io/api/image/2/profiles/level1.json",te="http://iiif.io/api/image/2/level2.json",ie="http://iiif.io/api/image/2/profiles/level2.json",ze="level0",re="level1",ne="level2",Be="http://iiif.io/api/image/2/level0",oe="http://iiif.io/api/image/2/level1",se="http://iiif.io/api/image/2/level2",ae=[se,q,U,J,D,K,X,te,ie,ne],le=[...ae,oe,Q,N,_,V,Z,G,Y,ee,re],Me=[Be,oe,se,Fe,Q,q,je,N,U,Ce,_,J,ke,V,D,Re,Ie,Z,G,K,X,Pe,We,Y,ee,te,ie,ze,re,ne],Ee={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},He={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},Te={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function $e(e){return ae.indexOf(e)!==-1?Te:le.indexOf(e)!==-1?He:Ee}function Le(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of t)if(typeof r=="string"&&(r=$e(r)),!!r){if(r.formats)for(const o of r.formats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(r.qualities)for(const o of r.qualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(r.supports)for(const o of r.supports)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const o of r.extraFormats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(r.extraQualities)for(const o of r.extraQualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(r.extraFeatures)for(const o of r.extraFeatures)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(e.extraFormats)for(const r of e.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(e.extraFeatures)for(const r of e.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(e.extraQualities)for(const r of e.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function Qe(e){try{if(e==="full")return{full:!0};if(e==="square")return{square:!0};const t=e.startsWith("pct:"),i=e.substr(t?4:0).split(",").map(r=>parseFloat(r));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function qe(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 i=e.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(t.width=parseInt(i[0],10)),i[1]!==""&&(t.height=parseInt(i[1],10))),t}function Ne(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 Ue(e,t=""){const i=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${e}`);const r=i[2],o=i[3];let n=i[4];if(n[0]==="/"&&(n=n.substr(1)),t.length>0){if(t[0]==="/"&&(t=t.substr(1)),t!==n.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${t})`);n=n.substr(t.length)}return{scheme:r,server:o,path:n,prefix:t}}function _e(e,t=""){const{path:i,scheme:r,server:o,prefix:n}=Ue(e,t),s=i.split("/").reverse(),[a,f,l,c,...p]=s,d=p.reverse().filter(Boolean).join("/");if(s.length===1||a==="")return{type:"base",scheme:r,server:o,prefix:n,identifier:d};if(a==="info.json"){const[,...g]=s;return{type:"info",scheme:r,server:o,prefix:n,identifier:g.reverse().filter(Boolean).join("/")}}const h=a.split(".");return{type:"image",scheme:r,server:o,prefix:n,identifier:d,originalPath:i,region:Qe(c),size:qe(l),rotation:Ne(f),quality:h[0],format:h[1]}}function Je(e){const t=_e(x(e.id));if(t.type!=="info")throw new Error("Invalid service URL");const i=Le(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.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 Ve(e,t,i){const r=i.length,o=[];for(let n=0;n<r;n++){const s=i[n].width;o.push(e/s)}return o}function De(e,t,i){const r=i.length,o=[];for(let n=0;n<r;n++){const s=i[n];o.push({width:Math.floor(e/s),height:Math.floor(t/s)})}return o}function u(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function W(e){if(!e||!e.profile||!u(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"&&Me.indexOf(i)!==-1)return!0;return!1}function Ze(e){if(!W(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"){if(le.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 Ge(e){if(!Ze(e))return[];const t=[],i=Array.isArray(e.profile)?e.profile:[e.profile],r=i.length;for(let o=0;o<r;o++){const n=i[o];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return[{id:u(e),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let n=0;n<o;n++){const s=e.tiles[n];(s.height||s.width)&&t.push({id:u(e),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width})}}return t}function M(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=e.match(t);if(i){const r=i[1],o=parseInt(i[4],10),n=parseInt(i[5],10),s=i[7];if((r==="max"||r==="full")&&o&&n&&s)return{type:"fixed",id:e,height:n,width:o}}return{type:"unknown",id:e}}function Ke(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function I(e){if(typeof e=="string")return M(e);const t=Ke(e);if(t!=="Image"&&t!=="sc:Image")return null;const i=e,r=u(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:M(r):null}function Xe(e){return W(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:u(e),type:"fixed-service",height:t.height,width:t.width})):[]}function E(e){const t=[],i=e.length;for(let r=0;r<i;r++){const o=Xe(e[r]);o.length&&t.push(...o);const n=Ge(e[r]);n.length&&t.push(...n)}return t}function ce(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],i=t.length,r=[];for(let o=0;o<i;o++)W(t[o])&&r.push(t[o]);return r}function Ye(e,t=!0,i){const r=[],o=I(e);if(o===null)return r;const n=e;if(r.push(o),t&&n.width&&n.height){const s=[],a=ce(n);for(const f of a){const l={id:u(f),width:n.width,height:n.height};if(i.canLoadSync(l)){const c=i.loadServiceSync(l);c&&(c.height||(c.height=n.height),c.width||(c.width=n.width),s.push(...E([c])))}}if(s.length)return r.push(...s),r}return n.service&&r.push(...E(n.service)),r}function et({x:e=0,y:t=0,w:i,h:r,full:o,square:n,percent:s}){if(o)return"full";if(n)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const a=`${e},${t},${i},${r}`;return s?`pct:${a}`:a}function tt({max:e,percentScale:t,upscaled:i,confined:r,width:o,height:n,serialiseAsFull:s}){const a=[];return i&&a.push("^"),e?(a.push(s?"full":"max"),a.join("")):(r&&a.push("!"),t&&a.push(`pct:${t}`),o&&a.push(`${o}`),a.push(","),n&&a.push(`${n}`),a.join(""))}function it(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}var rt=Object.defineProperty,nt=Object.defineProperties,ot=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertySymbols,st=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,T=(e,t,i)=>t in e?rt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,b=(e,t)=>{for(var i in t||(t={}))st.call(t,i)&&T(e,i,t[i]);if(H)for(var i of H(t))at.call(t,i)&&T(e,i,t[i]);return e},S=(e,t)=>nt(e,ot(t));function lt(e,t){const i=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,r=`${e.scheme}://${e.server}/${i?`${i}/`:""}${e.identifier}`;if(e.type==="base")return r;if(e.type==="info")return`${r}/info.json`;let{region:o,size:n,rotation:s,format:a,quality:f}=e;if(t){const l=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],c=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,p=l.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=S(b({},n),{max:!0})),c&&(n.max&&!n.serialiseAsFull&&(n=S(b({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=S(b({},n),{height:void 0}))),p&&(n.max&&n.serialiseAsFull&&(n=S(b({},n),{serialiseAsFull:!1})),n.width&&!n.height&&t.width&&t.height)){const d=t.height/t.width;n=S(b({},n),{height:Math.ceil(n.width*d)})}}return[r,et(o),tt(n),it(s),`${f}.${a}`].filter(Boolean).join("/")}function R(e,t,i){const r=Je({id:x(u(e)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=t,r.size.height=i,{id:lt(r),type:"fixed",width:t,height:i||e.height/(e.width||1)*t,unsafe:e.width>t}}function v(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function ct(e,t,i){const r=e.width?e.width:e.maxWidth;return i.height<=e.maxHeight&&i.width<=e.maxWidth&&i.height>=e.minHeight&&i.width>=e.minWidth&&(!t||Math.abs(i.width-r)<Math.abs(t.width-r))}function ft(e,t){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},e),o=[],n=[];let s=null;const a=(l,c)=>{if(ct(r,c,l)){if(r.preferFixedSize&&l.unsafe){n.push(l);return}r.returnAllOptions&&c&&n.push(c),s=l}else r.returnAllOptions&&n.push(l)},f=t.length;for(let l=0;l<f;l++){const c=t[l](),p=c.length;for(let d=0;d<p;d++){const h=c[d];if(h.type==="unknown"&&r.atAnyCost&&o.push(h),h.type==="fixed"&&(h.unsafe?o.push(h):a(h,s)),h.type==="fixed-service")if(r.unsafeImageService){const g=R(h,r.width,r.height);a(g,s)}else{const g=R(h,h.width,h.height);a(g,s)}if(h.type==="variable"&&h.maxWidth){const g=R({id:h.id,type:"fixed-service",width:h.maxWidth,height:h.maxWidth},h.maxWidth);a(g,s)}}if(s&&!r.returnAllOptions){if(s.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:s||o[0],fallback:o.slice(1),log:i}:r.returnAllOptions?{best:r.atAnyCost?s||n[0]||o[0]:s||n[0],fallback:[...n,...o],log:i}:{best:s||n[0]||null,fallback:s?n:n.slice(1),log:i}}var ht=Object.defineProperty,ut=Object.defineProperties,pt=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,dt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,L=(e,t,i)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,mt=(e,t)=>{for(var i in t||(t={}))dt.call(t,i)&&L(e,i,t[i]);if($)for(var i of $(t))gt.call(t,i)&&L(e,i,t[i]);return e},yt=(e,t)=>ut(e,pt(t));function xt(e,t,i){const r=e>t?e:t,o=i.length,n=[];for(let s=0;s<o;s++){const a=i[s];let f=a.scaleFactors[0],l=r/f;const c=[f];for(;l>=a.width;)f=f*2,c.push(f),l=l/2;n.push(yt(mt({},a),{scaleFactors:c}))}return n}function vt(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const i=e.length;let r=!0;for(let n=0;n<i;n++){const s=e[n],a=t[n];if(s.width!==a.width||s.height!==a.height){r=!1;break}}if(r)return!0;let o=0;for(let n=0;n<i;n++)for(let s=0;s<i;s++)if(e[n].width===t[s].width&&e[n].height===t[s].height){o++;break}return o===i}var y=(e,t,i)=>new Promise((r,o)=>{var n=f=>{try{a(i.next(f))}catch(l){o(l)}},s=f=>{try{a(i.throw(f))}catch(l){o(l)}},a=f=>f.done?r(f.value):Promise.resolve(f.value).then(n,s);a((i=i.apply(e,t)).next())});class fe{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,i,r=!0){const o=v(u(t)),n=x(u(t)),s=this.knownImageServers[o];return this.imageServices[n]=Object.assign(t,{real:!0}),!s&&t.tiles?(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:r,sampledId:u(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:i&&t.height?i.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:Ve(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0):this.verify(t)}preLoad(t,i=!0){this.knownImageServers[t.root]=t,i&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,i=!1,r=!1){const o=t==null?void 0:t.source,n=v(u(t)),s=this.knownImageServers[n];if(!s||!s.result||!r&&(s.malformed||s.verifications<this.config.verificationsRequired))return null;const a=x(u(t));return this.imageServices[a]||(this.imageServices[a]={"@context":s.result.context,"@id":u(t),id:u(t),protocol:"http://iiif.io/api/image",tiles:(o==null?void 0:o.tiles)||xt(t.width,t.height,s.result.sampledTiles),sizes:(o==null?void 0:o.sizes)||De(Math.round(t.width/s.result.resourceServiceRatio),Math.round(t.height/s.result.resourceServiceRatio),s.result.sizeRatios),profile:(o==null?void 0:o.profile)||s.result.sampledProfile,height:(o==null?void 0:o.height)||t.height,width:(o==null?void 0:o.width)||t.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(t,i){return y(this,arguments,function*(r,o,n=!0,s=[]){const a=yield this.getImageCandidates(r,n);return ft(o,[()=>s,()=>a])})}getImageCandidates(t,i=!0){return y(this,null,function*(){const r=t;if(i&&r.height&&r.width){const o=ce(r);for(const n of o){const s={id:u(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(s)}}return Ye(t,i,this)})}verify(t){return y(this,null,function*(){const i=this.predict(t,!1,!0),r=yield this.fetchService(u(t));if(!i)return!1;const o=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&vt(i.sizes||[],r.sizes||[]);if(o){const n=v(u(t));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0)}return o})}canLoadSync(t){const i=typeof t=="string"?t:u(t),r=x(i);if(this.imageServices[r])return!0;const o=this.knownImageServers[v(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return y(this,null,function*(){return this.knownImageServers[v(u(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,i=!1){return y(this,null,function*(){const r=x(t);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 o=yield this.fetch(r).then(n=>n.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[r]=Object.assign(o,{real:!0}),this.imageServices[r]})}fetch(t,i){return y(this,null,function*(){return fetch(t,i)})}loadService(t,i=!1){return y(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(s=>setTimeout(s,500));else{n=!1;break}}const r=this.knownImageServers[v(u(t))];if(r&&!r.malformed&&!i){yield r.result;const n=this.loadServiceSync(t);if(n)return n}this.fetchingCount++;const o=yield this.fetchService(u(t),i);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const i=x(u(t));return this.imageServices[i]?this.imageServices[i]:this.predict(t)}}new fe;function wt(e,t={}){const i=t.imageServiceLoader||new fe;async function r(o,n,s,a=[],f){if(typeof o=="string")return{best:I(o),fallback:[],log:[]};const l=e.get(o);if(typeof l=="string")return{best:I(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const c=l.body,p=e.get(c[0]);return f&&!p.width&&(p.width=f.width,p.height=f.height),await i.getThumbnailFromResource(p,n,s,a)}case"Canvas":{const c=l;if(c.thumbnail&&c.thumbnail.length){const p=e.get(c.thumbnail[0]),d=await i.getImageCandidates(p,s);d&&d.length&&a.push(...d)}return r(c.items[0],n,s,a,{width:c.width,height:c.height})}case"AnnotationPage":return r(l.items[0],n,s,a,f);case"Choice":return r(l.items[0],n,s,a,f);case"Collection":{const p=l.items[0];return r(p,n,s,a,f)}case"Manifest":{const p=l.items[0];return r(p,n,s,a,f)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return f&&!l.width&&(l.width=f.width,l.height=f.height),i.getThumbnailFromResource(l,n,s,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 he(e,t,i=[],r=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const o=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(o&&t.indexOf(o)!==-1)return o;for(const n of i)if(t.indexOf(n)!==-1)return n;if(!r){const s=t.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(e);if(s!==-1)return t[s];for(const a of i){const f=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,l=f?t.indexOf(f):-1;if(l!==-1)return t[l]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function ue(e,t,i={}){const{strictFallback:r=!1,defaultText:o="",separator:n=`
`,fallbackLanguages:s=[],closest:a}=i,f=Object.keys(e||{}),l=a?t:he(t,f,s,r);if(!e)return o;if(typeof e=="string")return e;const c=l?e[l]:void 0;return c?typeof c=="string"?c:c.join(n):""}function bt(e,t={}){return ue(e,typeof navigator!="undefined"?navigator.language:void 0,t)}const St=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Ot=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function j(e){if(Array.isArray(e))return e.reduce((t,i)=>{const{selector:r,selectors:o}=j(i);return r&&(t.selector||(t.selector=r),t.selectors.push(...o)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,i]=e.split("#");return i?j({type:"FragmentSelector",value:i}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=St.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"||t[2]==="pct:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const i=e.value.match(Ot);if(i){const r={type:"TemporalSelector",temporal:{startTime:i[4]?parseFloat(i[4]):0,endTime:i[7]?parseFloat(i[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}function m(e,t={}){if(Array.isArray(e))return m(e[0]);if(typeof e=="string"){const[i,r]=e.split("#");return r?m({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return m(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:i,selectors:r}=e.selector?j(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:i,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[i,r]=e.id.split("#");return r?m({type:"SpecificResource",source:k(C({},e),{id:i}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:k(C({},e),{id:i}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function P(e,t=!1){if(typeof e=="string"){if(e.startsWith("{"))try{const i=JSON.parse(e);return P(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(e)){for(const i of e){const[r,o]=P(i);if(!r&&o)return[r,o]}return[!0]}return e.type==="Annotation"?[!0]:t&&e.type==="Canvas"&&!e.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function At(e){return de(typeof e=="string"?e:JSON.stringify(e))}function pe(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(i=>i.json())}return pe(ge(e),t)}function de(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 i=Ft(e).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function Ft(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 jt(e){if(!e)throw new Error("Content state is empty");Array.isArray(e)||(e=[e]);let t="vault://virtual-annotation/"+new Date().getTime();const i=[];for(const r of e){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(t=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=m(n);i.push(s)}else{const n=m(r.target);i.push(n)}continue}const o=m(r);i.push(o)}return{id:t,type:"Annotation",motivation:["contentState",...e.motivation||[]],target:i,extensions:{}}}function me(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Ct(e){function t(o){const n=o?typeof o=="string"?e.get(o):o:null;if(!n)return[];const s=e.get(n.items),a=[];for(const f of s)a.push(...e.get(f.items));return a}function i(o,n=[]){const s=Array.isArray(o)?o:t(o),a=[];let f=null;const l=[];for(const c of s){if(c.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const p=e.get(c.body);for(const d of p){const[h,{selector:g}]=me(d),O=(h.type||"unknown").toLowerCase();if(O==="choice"){const A=e.get(h.items),F=n.length?n.map(w=>A.find(ye=>ye.id===w)).filter(Boolean):[A[0]];F.length===0&&F.push(A[0]),f={type:"single-choice",items:A.map(w=>({id:w.id,label:w.label,selected:F.indexOf(w)!==-1})),label:d.label},p.push(...F);continue}a.indexOf(O)===-1&&a.push(O),l.push({type:O,resource:h,target:c.target,selector:g})}}return{types:a,items:l,choice:f}}function r(o){const{choice:n}=i(o);return n}return{getAllPaintingAnnotations:t,getPaintables:i,extractChoices:r}}exports.buildLocaleString=ue;exports.createEventsHelper=Oe;exports.createPaintingAnnotationsHelper=Ct;exports.createStylesHelper=Ae;exports.createThumbnailHelper=wt;exports.decodeContentState=ge;exports.encodeContentState=de;exports.expandTarget=m;exports.getClosestLanguage=he;exports.getValue=bt;exports.normaliseContentState=jt;exports.parseContentState=pe;exports.parseSelector=j;exports.parseSpecificResource=me;exports.serialiseContentState=At;exports.validateContentState=P;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function Jt(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 Yt(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 I(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const Zt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ht="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ut="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Kt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",pt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",dt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",yt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",gt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ee="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",mt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",xt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ie="http://iiif.io/api/image/1/level0.json",re="http://iiif.io/api/image/1/profiles/level0.json",vt="http://iiif.io/api/image/1/level1.json",bt="http://iiif.io/api/image/1/profiles/level1.json",wt="http://iiif.io/api/image/1/level2.json",St="http://iiif.io/api/image/1/profiles/level2.json",ne="http://iiif.io/api/image/2/level0.json",se="http://iiif.io/api/image/2/profiles/level0.json",At="http://iiif.io/api/image/2/level1.json",Ot="http://iiif.io/api/image/2/profiles/level1.json",kt="http://iiif.io/api/image/2/level2.json",Mt="http://iiif.io/api/image/2/profiles/level2.json",oe="level0",Ft="level1",Ct="level2",ae="http://iiif.io/api/image/2/level0",jt="http://iiif.io/api/image/2/level1",Tt="http://iiif.io/api/image/2/level2",Rt=[Tt,ut,dt,gt,xt,wt,St,kt,Mt,Ct],zt=[...Rt,jt,ht,pt,yt,mt,vt,bt,At,Ot,Ft],ce=[ae,jt,Tt,Zt,ht,ut,Kt,pt,dt,te,yt,gt,ee,mt,xt,ie,re,vt,bt,wt,St,ne,se,At,Ot,kt,Mt,oe,Ft,Ct],le={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},fe={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 ue(t){return Rt.indexOf(t)!==-1?he:zt.indexOf(t)!==-1?fe:le}function pe(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=ue(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 de(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 ge(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 me(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}=me(t,e),o=i.split("/").reverse(),[a,c,l,f,...d]=o,y=d.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:r,server:s,prefix:n,identifier:y};if(a==="info.json"){const[,...h]=o;return{type:"info",scheme:r,server:s,prefix:n,identifier:h.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:r,server:s,prefix:n,identifier:y,originalPath:i,region:de(f),size:ye(l),rotation:ge(c),quality:p[0],format:p[1]}}function ve(t){const e=xe(I(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const i=pe(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 be(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 we(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 J(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"&&ce.indexOf(i)!==-1)return!0;return!1}function Se(t){if(!J(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(zt.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 Ae(t){if(!Se(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 it(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 Oe(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function X(t){if(typeof t=="string")return it(t);const e=Oe(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}:it(r):null}function ke(t){return J(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:A(t),type:"fixed-service",height:e.height,width:e.width})):[]}function rt(t){const e=[],i=t.length;for(let r=0;r<i;r++){const s=ke(t[r]);s.length&&e.push(...s);const n=Ae(t[r]);n.length&&e.push(...n)}return e}function It(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,r=[];for(let s=0;s<i;s++)J(e[s])&&r.push(e[s]);return r}function Me(t,e=!0,i){const r=[],s=X(t);if(s===null)return r;const n=t;if(r.push(s),e&&n.width&&n.height){const o=[],a=It(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(...rt([f])))}}if(o.length)return r.push(...o),r}return n.service&&r.push(...rt(n.service)),r}function Fe({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 Ce({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 Te=Object.defineProperty,Re=Object.defineProperties,ze=Object.getOwnPropertyDescriptors,nt=Object.getOwnPropertySymbols,Ie=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable,st=(t,e,i)=>e in t?Te(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,H=(t,e)=>{for(var i in e||(e={}))Ie.call(e,i)&&st(t,i,e[i]);if(nt)for(var i of nt(e))Pe.call(e,i)&&st(t,i,e[i]);return t},L=(t,e)=>Re(t,ze(e));function We(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,d=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}))),d&&(n.max&&n.serialiseAsFull&&(n=L(H({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const y=e.height/e.width;n=L(H({},n),{height:Math.ceil(n.width*y)})}}return[r,Fe(s),Ce(n),je(o),`${c}.${a}`].filter(Boolean).join("/")}function V(t,e,i){const r=ve({id:I(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:We(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 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 qe(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](),d=f.length;for(let y=0;y<d;y++){const p=f[y];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 h=V(p,r.width,r.height);a(h,o)}else{const h=V(p,p.width,p.height);a(h,o)}if(p.type==="variable"&&p.maxWidth){const h=V({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);a(h,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,He=Object.defineProperties,Le=Object.getOwnPropertyDescriptors,ot=Object.getOwnPropertySymbols,Qe=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,at=(t,e,i)=>e in t?$e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ee=(t,e)=>{for(var i in e||(e={}))Qe.call(e,i)&&at(t,i,e[i]);if(ot)for(var i of ot(e))_e.call(e,i)&&at(t,i,e[i]);return t},Ne=(t,e)=>He(t,Le(e));function Ve(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(Ne(Ee({},a),{scaleFactors:f}))}return n}function Ue(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 ct(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=W(A(e)),n=I(A(e)),o=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),!o&&e.tiles&&!ct(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:be(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)||ct(e.source))return null;const a=I(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)||Ve(e.width,e.height,o.result.sampledTiles),sizes:(s==null?void 0:s.sizes)||we(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 qe(s,[()=>o,()=>a])})}getImageCandidates(e,i=!0){return z(this,null,function*(){const r=e;if(i&&r.height&&r.width){const s=It(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 Me(e,i,this)})}verify(e){return z(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"]&&Ue(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=I(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 z(this,null,function*(){return this.knownImageServers[W(A(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return z(this,null,function*(){const r=I(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[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=I(A(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new Pt;function De(t,e={}){const i=e.imageServiceLoader||new Pt;async function r(s,n,o,a=[],c){if(typeof s=="string")return{best:X(s),fallback:[],log:[]};const l=t.get(s);if(typeof l=="string")return{best:X(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,d=t.get(f[0]);return c&&!d.width&&(d.width=c.width,d.height=c.height),await i.getThumbnailFromResource(d,n,o,a)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const d=t.get(f.thumbnail[0]),y=await i.getImageCandidates(d,o);y&&y.length&&a.push(...y)}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 d=l.items[0];return r(d,n,o,a,c)}case"Manifest":{const d=l.items[0];return r(d,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 Bt(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 Xe(t,e={}){return Bt(t,typeof navigator!="undefined"?navigator.language:void 0,e)}var Ge=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,U=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,d=n*c+s*l;return{x:f+o,y:d+a}},Je=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}]},lt=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)},Ye=function(e,i,r,s,n,o,a,c,l,f,d,y){var p=Math.pow(n,2),h=Math.pow(o,2),b=Math.pow(d,2),m=Math.pow(y,2),x=p*h-p*m-h*b;x<0&&(x=0),x/=p*m+h*b,x=Math.sqrt(x)*(a===c?-1:1);var u=x*n/o*y,g=x*-o/n*d,v=f*u-l*g+(e+r)/2,w=l*u+f*g+(i+s)/2,S=(d-u)/n,k=(y-g)/o,M=(-d-u)/n,F=(-y-g)/o,R=lt(1,0,S,k),C=lt(S,k,M,F);return c===0&&C>0&&(C-=Q),c===1&&C<0&&(C+=Q),[v,w,R,C]},Ze=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,d=f===void 0?0:f,y=e.sweepFlag,p=y===void 0?0:y,h=[];if(o===0||a===0)return[];var b=Math.sin(l*Q/360),m=Math.cos(l*Q/360),x=m*(i-s)/2+b*(r-n)/2,u=-b*(i-s)/2+m*(r-n)/2;if(x===0&&u===0)return[];o=Math.abs(o),a=Math.abs(a);var g=Math.pow(x,2)/Math.pow(o,2)+Math.pow(u,2)/Math.pow(a,2);g>1&&(o*=Math.sqrt(g),a*=Math.sqrt(g));var v=Ye(i,r,s,n,o,a,d,p,b,m,x,u),w=Ge(v,4),S=w[0],k=w[1],M=w[2],F=w[3],R=Math.abs(F)/(Q/4);Math.abs(1-R)<1e-7&&(R=1);var C=Math.max(Math.ceil(R),1);F/=C;for(var Z=0;Z<C;Z++)h.push(Je(M,F)),M+=F;return h.map(function(N){var K=U(N[0],o,a,m,b,S,k),Nt=K.x,Vt=K.y,tt=U(N[1],o,a,m,b,S,k),Ut=tt.x,Dt=tt.y,et=U(N[2],o,a,m,b,S,k),Xt=et.x,Gt=et.y;return{x1:Nt,y1:Vt,x2:Ut,y2:Dt,x:Xt,y:Gt}})},Ke=ei,D={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ti=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ei(t){var e=[];return t.replace(ti,function(i,r,s){var n=r.toLowerCase();for(s=ri(s),n=="m"&&s.length>2&&(e.push([r].concat(s.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(s.length==D[n])return s.unshift(r),e.push(s);if(s.length<D[n])throw new Error("malformed path data");e.push([r].concat(s.splice(0,D[n])))}}),e}var ii=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ri(t){var e=t.match(ii);return e?e.map(Number):[]}var ni=si;function si(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 oi(t){const e=Ke(t),i=ni(e);let r,s=0,n=0,o=0,a=0,c,l,f=0,d=0;const y=[];for(let p=0;p<i.length;p++){let h=i[p];const b=h[0];switch(b){case"M":s=h[1],n=h[2];break;case"H":h=["L",h[1],n];break;case"V":h=["L",s,h[1]];break;case"S":{let m=f,x=d;(r==="C"||r=="S")&&(m+=m-o,x+=x-a),h=["C",m,x,h[1],h[2],h[3],h[4]]}break;case"T":r==="Q"||r=="T"?(c=f*2-c,l=d*2-l):(c=f,l=d),h=["Q",c,l,h[1],h[2]];break;case"Q":c=h[1],l=h[2];break;case"A":{const m=Ze({px:f,py:d,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!m.length)continue;for(const[x,u]of m.entries())h=["C",u.x1,u.y1,u.x2,u.y2,u.x,u.y],x<m.length-1&&y.push(h);h=h}break;case"Z":h=["L",s,n];break}r=b,f=h[h.length-2],d=h[h.length-1],["C","Q","A"].indexOf(b)>-1?(o=h[h.length-4],a=h[h.length-3]):(o=f,a=d),y.push(h)}return y}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
*
* All code in this module is based on JavaScript code by Raph Levien, published on his blog at
* https://raphlinus.github.io/.
* I merely changed the structure a bit, removed some unneeded parts and added some comments and type hints.
*
* Flattening of quadratic Bézier curves:
* - Article: https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html
* - Code: https://github.com/raphlinus/raphlinus.github.io/blob/master/_posts/2019-12-23-flatten-quadbez.md?plain=1#L73-L212
*
* Flattening of cubic Bézier curves: https://levien.com/tmp/flatten.html
*
* Note that the code in this module has a different license than the rest of the package,
* due to the inclusion of Apache-licensed third party code.
*
* @license
* Copyright 2022 Johannes Baiter <johannes.baiter@gmail.com>
* Copyright 2019, 2022 Raph Levien <raph.levien@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function ai(t,e,i,r=1){return new qt(t,e,i).subdivide(r)}function ci(t,e,i,r,s=1){return new Y(new Float64Array([t.x,t.y,e.x,e.y,i.x,i.y,r.x,r.y])).subdivide(s)}function li(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 q(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,d=(n-e)*c-(o-i)*a,y=l/d,p=f/d,h=Math.abs(d)/(Math.hypot(a,c)*Math.abs(p-y));return{x0:e,x2:n,scale:h,cross:d}}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=q(r),c=q(s),l=[0];for(let f=1;f<o;f++){const y=(q(r+(s-r)*f/o)-a)/(c-a);l.push(y)}return l.push(1),l.map(f=>this.eval(f))}}class Y{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 Y(r)}subdivide(e){const i=.1*e,r=e-i,s=Math.sqrt(r),n=li(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(n/(432*i*i),1/6)),a=[];let c=0;for(let h=0;h<o;h++){const b=h/o,m=(h+1)/o,x=this.subsegment(b,m).midpoint_quadbez(),u=x.mapToBasic(),g=_(u.x0),v=_(u.x2),w=Math.sqrt(u.scale);let S=Math.abs(v-g)*w;if(Math.sign(u.x0)!=Math.sign(u.x2)){const k=s/w,M=s*Math.abs(v-g)/_(k);S=Math.max(S,M)}a.push({quad:x,a0:g,a2:v,val:S}),c+=S}const l=.5*c/s,f=Math.ceil(l),d=[{x:this.c[0],y:this.c[1]}];let y=0,p=0;for(let h=1;h<f;h++){const b=c*h/f;for(;y+a[p].val<b;)y+=a[p].val,p++;const m=a[p].a0,x=a[p].a2,u=q(m),g=q(x),v=m+(x-m)*(b-y)/a[p].val,S=(q(v)-u)/(g-u);d.push(a[p].quad.eval(S))}return d.push({x:this.c[6],y:this.c[7]}),d}}const fi=/&?(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]+)?))?/,ft=/^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=fi.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 d=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!d)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const y=$t(d);y&&(n=y.points,l=y.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=di(y.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 ui(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,d,y,p,h,b,m,x;for(const u of Array.from(t.children))switch(u==null?void 0:u.tagName.toLowerCase()){case"g":{const g=$t(u);if(g)return g}continue;case"path":{const g=u.getAttribute("d");if(!g)continue;const v=oi(g);return{element:u,points:pi(v),shapeType:ui(v)}}case"circle":{const g=parseFloat((e=u.getAttribute("cx"))!=null?e:"0"),v=parseFloat((i=u.getAttribute("cy"))!=null?i:"0"),w=parseFloat((r=u.getAttribute("r"))!=null?r:"0");if(!w)continue;const S=[];for(let k=0;k<=360;k+=12){const M=k*Math.PI/180;S.push([g+w*Math.cos(M),v+w*Math.sin(M)])}return{element:u,points:S,shapeType:"circle"}}case"ellipse":{const g=parseFloat((s=u.getAttribute("cx"))!=null?s:"0"),v=parseFloat((n=u.getAttribute("cy"))!=null?n:"0"),w=parseFloat((o=u.getAttribute("rx"))!=null?o:"0"),S=parseFloat((a=u.getAttribute("ry"))!=null?a:"0");if(!w&&!S)continue;const k=[];for(let M=0;M<=360;M+=12){const F=Math.tan(M/360*Math.PI),R=w*(1-F**2)/(1+F**2),C=S*2*F/(1+F**2);k.push([g+R,v+C])}return{element:u,points:k,shapeType:"ellipse"}}case"line":{const g=parseFloat((c=u.getAttribute("x0"))!=null?c:"0"),v=parseFloat((l=u.getAttribute("y0"))!=null?l:"0"),w=parseFloat((f=u.getAttribute("x1"))!=null?f:"0"),S=parseFloat((d=u.getAttribute("y1"))!=null?d:"0");if(g===w&&v===S)continue;return{element:u,points:[[g,v],[w,S]],shapeType:"polyline"}}case"polygon":case"polyline":{const g=(p=(y=u.getAttribute("points"))==null?void 0:y.split(" ").map(w=>w.split(",").map(parseFloat)))!=null?p:[];if(!g.length)continue;let v="polyline";return u.tagName.toLowerCase()==="polygon"&&(g.push(g[0]),v="polygon"),{element:u,points:g,shapeType:v}}case"rect":{const g=parseFloat((h=u.getAttribute("x"))!=null?h:"0"),v=parseFloat((b=u.getAttribute("y"))!=null?b:"0"),w=parseFloat((m=u.getAttribute("width"))!=null?m:"0"),S=parseFloat((x=u.getAttribute("height"))!=null?x:"0");if(!w||!S)continue;return{element:u,points:[[g,v],[g+w,v],[g+w,v+S],[g,v+S],[g,v]],shapeType:"rect"}}default:continue}return null}function pi(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(...ci({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(...ai({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 di(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=ft.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=ft.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 T(t,e={}){if(Array.isArray(t))return T(t[0]);if(typeof t=="string"){const[i,r]=t.split("#");return r?T({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 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: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?T({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 G(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const i=JSON.parse(t);return G(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const i of t){const[r,s]=G(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 Lt(typeof t=="string"?t:JSON.stringify(t))}function Ht(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 Ht(Qt(t),e)}function Lt(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 Qt(t){const i=gi(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function gi(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 mi(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=T(n);i.push(o)}else{const n=T(r.target);i.push(n)}continue}const s=T(r);i.push(s)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:i,extensions:{}}}function _t(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 d=t.get(f.body);for(const y of d){const[p,{selector:h}]=_t(y),b=(p.type||"unknown").toLowerCase();if(b==="choice"){const m=t.get(p.items),x=n.length?n.map(u=>m.find(g=>g.id===u)).filter(Boolean):[m[0]];x.length===0&&x.push(m[0]),c={type:"single-choice",items:m.map(u=>({id:u.id,label:u.label,selected:x.indexOf(u)!==-1})),label:y.label},d.push(...x);continue}a.indexOf(b)===-1&&a.push(b),l.push({type:b,resource:p,target:f.target,selector:h})}}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 O(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&&j(i.get(e[P][t]),i)},set(r){e[P][t]!==r&&(this[P][t]=r)}})}const P=Symbol.for("_refs_"),B=Symbol.for("_reactive_"),$=Symbol.for("_defined_");function vi(t,e=!1){const i={id:null,[$]:[],[P]:{},[B]:null,is(r){return typeof r=="string"?this.id===r:r.id?r.id===this.id:!1},reactive(){if(!this[B])return this[B]=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[B]&&(this[B](),this[B]=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 O("items",i,t),O("annotations",i,t),O("structures",i,t),O("seeAlso",i,t),O("service",i,t),O("services",i,t),O("rendering",i,t),O("partOf",i,t),O("start",i,t),O("supplementary",i,t),O("homepage",i,t),O("thumbnail",i,t),O("placeholderCanvas",i,t),O("accompanyingCanvas",i,t),O("provider",i,t),O("body",i,t),O("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 j(t,e,i=!1){if(Array.isArray(t))return t.map(o=>j(o,e,i));if(!t||!t.type||!t.id)return t;const r=vi(e,i),s=Object.create(r),n=Object.assign(s,t);return i&&n.reactive(),n}function bi(t){return{get(e,i=!1){return j(t.get(e),t,i)},async load(e,i){return j(await t.load(e,i),t)},async loadManifest(e,i){return j(await t.loadManifest(e,i),t)},async loadCollection(e,i){return j(await t.loadCollection(e,i),t)},wrapObject(e){return j(t.get(e,{skipSelfReturn:!1}),t)},isWrapped(e){return!!e[$]}}}exports.buildLocaleString=Bt;exports.createEventsHelper=Jt;exports.createObjectsHelper=bi;exports.createPaintingAnnotationsHelper=xi;exports.createStylesHelper=Yt;exports.createThumbnailHelper=De;exports.decodeContentState=Qt;exports.encodeContentState=Lt;exports.expandTarget=T;exports.getClosestLanguage=Wt;exports.getValue=Xe;exports.normaliseContentState=mi;exports.parseContentState=Ht;exports.parseSelector=E;exports.parseSpecificResource=_t;exports.serialiseContentState=yi;exports.unwrapObject=Et;exports.validateContentState=G;exports.wrapObject=j;
//# sourceMappingURL=index.js.map

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

"use strict";var h=Object.defineProperty,C=Object.defineProperties;var v=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var u=(e,t,r)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,c=(e,t)=>{for(var r in t||(t={}))b.call(t,r)&&u(e,r,t[r]);if(f)for(var r of f(t))O.call(t,r)&&u(e,r,t[r]);return e},l=(e,t)=>C(e,v(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,w=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function p(e){if(Array.isArray(e))return e.reduce((t,r)=>{const{selector:n,selectors:s}=p(r);return n&&(t.selector||(t.selector=n),t.selectors.push(...s)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,r]=e.split("#");return r?p({type:"FragmentSelector",value:r}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=g.exec(e.value);if(t){const n={type:"BoxSelector",spatial:{unit:t[2]==="percent:"||t[2]==="pct:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:n,selectors:[n]}}const r=e.value.match(w);if(r){const n={type:"TemporalSelector",temporal:{startTime:r[4]?parseFloat(r[4]):0,endTime:r[7]?parseFloat(r[7]):void 0}};return{selector:n,selectors:[n]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}function o(e,t={}){if(Array.isArray(e))return o(e[0]);if(typeof e=="string"){const[r,n]=e.split("#");return n?o({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{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 o(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:n}=e.selector?p(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,n]=e.id.split("#");return n?o({type:"SpecificResource",source:l(c({},e),{id:r}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:l(c({},e),{id:r}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function a(e,t=!1){if(typeof e=="string"){if(e.startsWith("{"))try{const r=JSON.parse(e);return a(r)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(e)){for(const r of e){const[n,s]=a(r);if(!n&&s)return[n,s]}return[!0]}return e.type==="Annotation"?[!0]:t&&e.type==="Canvas"&&!e.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function A(e){return d(typeof e=="string"?e:JSON.stringify(e))}function y(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 y(S(e),t)}function d(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 S(e){const r=R(e).replace(/-/g,"+").replace(/_/g,"/"),n=typeof atob=="undefined"?Buffer.from(r,"base64").toString("utf-8"):atob(r);return decodeURIComponent(n).trim()}function R(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 T(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 n of e){if(typeof n=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(n.type==="Annotation"){if(t=n.id,Array.isArray(n.motivation))for(const i of n.motivation);if(Array.isArray(n.target))for(const i of n.target){const m=o(i);r.push(m)}else{const i=o(n.target);r.push(i)}continue}const s=o(n);r.push(s)}return{id:t,type:"Annotation",motivation:["contentState",...e.motivation||[]],target:r,extensions:{}}}exports.decodeContentState=S;exports.encodeContentState=d;exports.normaliseContentState=T;exports.parseContentState=y;exports.serialiseContentState=A;exports.validateContentState=a;
"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.
*
* All code in this module is based on JavaScript code by Raph Levien, published on his blog at
* https://raphlinus.github.io/.
* I merely changed the structure a bit, removed some unneeded parts and added some comments and type hints.
*
* Flattening of quadratic Bézier curves:
* - Article: https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html
* - Code: https://github.com/raphlinus/raphlinus.github.io/blob/master/_posts/2019-12-23-flatten-quadbez.md?plain=1#L73-L212
*
* Flattening of cubic Bézier curves: https://levien.com/tmp/flatten.html
*
* Note that the code in this module has a different license than the rest of the package,
* due to the inclusion of Apache-licensed third party code.
*
* @license
* Copyright 2022 Johannes Baiter <johannes.baiter@gmail.com>
* Copyright 2019, 2022 Raph Levien <raph.levien@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* 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;
//# sourceMappingURL=content-state.js.map

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

(function(h,g){typeof exports=="object"&&typeof module!="undefined"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(h=typeof globalThis!="undefined"?globalThis:h||self,g(h.VaultHelpers={}))})(this,function(h){"use strict";var At=Object.defineProperty,Ft=Object.defineProperties;var jt=Object.getOwnPropertyDescriptors;var ve=Object.getOwnPropertySymbols;var Ct=Object.prototype.hasOwnProperty,kt=Object.prototype.propertyIsEnumerable;var xe=(h,g,y)=>g in h?At(h,g,{enumerable:!0,configurable:!0,writable:!0,value:y}):h[g]=y,B=(h,g)=>{for(var y in g||(g={}))Ct.call(g,y)&&xe(h,y,g[y]);if(ve)for(var y of ve(g))kt.call(g,y)&&xe(h,y,g[y]);return h},T=(h,g)=>Ft(h,jt(g));function g(e){return{addEventListener(t,i,r,o){if(!!t)return e.setMetaValue([t.id,"eventManager",i],n=>{const s=n||[];for(const a of s)if(a.callback===r)return s;return[...s,{callback:r,scope:o}]}),r},removeEventListener(t,i,r){!t||e.setMetaValue([t.id,"eventManager",i],o=>(o||[]).filter(n=>n.callback!==r))},getListenersAsProps(t,i){const r=typeof t=="string"?{id:t}:t;if(!r||!r.id)return{};const o=e.getResourceMeta(r.id,"eventManager"),n={};if(o&&r)for(const s of Object.keys(o))n[s]=a=>{const f=e.get(r);for(const{callback:l,scope:c}of o[s]||[])(!c||i&&c.indexOf(i)!==-1)&&l(a,f)};return n}}}function y(e){return{applyStyles(t,i,r){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",i],r)},getAppliedStyles(t){const i=typeof t=="string"?t:t.id;return e.getResourceMeta(i,"styles")}}}function w(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}const we="http://library.stanford.edu/iiif/image-api/compliance.html#level0",H="http://library.stanford.edu/iiif/image-api/compliance.html#level1",M="http://library.stanford.edu/iiif/image-api/compliance.html#level2",be="http://library.stanford.edu/iiif/image-api/conformance.html#level0",E="http://library.stanford.edu/iiif/image-api/conformance.html#level1",$="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Se="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",L="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Q="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Oe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",q="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",N="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ae="http://iiif.io/api/image/1/level0.json",Fe="http://iiif.io/api/image/1/profiles/level0.json",U="http://iiif.io/api/image/1/level1.json",_="http://iiif.io/api/image/1/profiles/level1.json",V="http://iiif.io/api/image/1/level2.json",J="http://iiif.io/api/image/1/profiles/level2.json",je="http://iiif.io/api/image/2/level0.json",Ce="http://iiif.io/api/image/2/profiles/level0.json",D="http://iiif.io/api/image/2/level1.json",Z="http://iiif.io/api/image/2/profiles/level1.json",G="http://iiif.io/api/image/2/level2.json",K="http://iiif.io/api/image/2/profiles/level2.json",ke="level0",X="level1",Y="level2",Re="http://iiif.io/api/image/2/level0",ee="http://iiif.io/api/image/2/level1",te="http://iiif.io/api/image/2/level2",ie=[te,M,$,Q,N,V,J,G,K,Y],re=[...ie,ee,H,E,L,q,U,_,D,Z,X],Ie=[Re,ee,te,we,H,M,be,E,$,Se,L,Q,Oe,q,N,Ae,Fe,U,_,V,J,je,Ce,D,Z,G,K,ke,X,Y],Pe={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},We={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},ze={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function Be(e){return ie.indexOf(e)!==-1?ze:re.indexOf(e)!==-1?We:Pe}function Te(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of t)if(typeof r=="string"&&(r=Be(r)),!!r){if(r.formats)for(const o of r.formats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(r.qualities)for(const o of r.qualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(r.supports)for(const o of r.supports)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const o of r.extraFormats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(r.extraQualities)for(const o of r.extraQualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(r.extraFeatures)for(const o of r.extraFeatures)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(e.extraFormats)for(const r of e.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(e.extraFeatures)for(const r of e.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(e.extraQualities)for(const r of e.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function He(e){try{if(e==="full")return{full:!0};if(e==="square")return{square:!0};const t=e.startsWith("pct:"),i=e.substr(t?4:0).split(",").map(r=>parseFloat(r));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function Me(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 i=e.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(t.width=parseInt(i[0],10)),i[1]!==""&&(t.height=parseInt(i[1],10))),t}function Ee(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 $e(e,t=""){const i=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${e}`);const r=i[2],o=i[3];let n=i[4];if(n[0]==="/"&&(n=n.substr(1)),t.length>0){if(t[0]==="/"&&(t=t.substr(1)),t!==n.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${t})`);n=n.substr(t.length)}return{scheme:r,server:o,path:n,prefix:t}}function Le(e,t=""){const{path:i,scheme:r,server:o,prefix:n}=$e(e,t),s=i.split("/").reverse(),[a,f,l,c,...d]=s,m=d.reverse().filter(Boolean).join("/");if(s.length===1||a==="")return{type:"base",scheme:r,server:o,prefix:n,identifier:m};if(a==="info.json"){const[,...v]=s;return{type:"info",scheme:r,server:o,prefix:n,identifier:v.reverse().filter(Boolean).join("/")}}const u=a.split(".");return{type:"image",scheme:r,server:o,prefix:n,identifier:m,originalPath:i,region:He(c),size:Me(l),rotation:Ee(f),quality:u[0],format:u[1]}}function Qe(e){const t=Le(w(e.id));if(t.type!=="info")throw new Error("Invalid service URL");const i=Te(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.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 qe(e,t,i){const r=i.length,o=[];for(let n=0;n<r;n++){const s=i[n].width;o.push(e/s)}return o}function Ne(e,t,i){const r=i.length,o=[];for(let n=0;n<r;n++){const s=i[n];o.push({width:Math.floor(e/s),height:Math.floor(t/s)})}return o}function p(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function I(e){if(!e||!e.profile||!p(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"&&Ie.indexOf(i)!==-1)return!0;return!1}function Ue(e){if(!I(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"){if(re.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 _e(e){if(!Ue(e))return[];const t=[],i=Array.isArray(e.profile)?e.profile:[e.profile],r=i.length;for(let o=0;o<r;o++){const n=i[o];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return[{id:p(e),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let n=0;n<o;n++){const s=e.tiles[n];(s.height||s.width)&&t.push({id:p(e),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width})}}return t}function ne(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=e.match(t);if(i){const r=i[1],o=parseInt(i[4],10),n=parseInt(i[5],10),s=i[7];if((r==="max"||r==="full")&&o&&n&&s)return{type:"fixed",id:e,height:n,width:o}}return{type:"unknown",id:e}}function Ve(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function P(e){if(typeof e=="string")return ne(e);const t=Ve(e);if(t!=="Image"&&t!=="sc:Image")return null;const i=e,r=p(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:ne(r):null}function Je(e){return I(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:p(e),type:"fixed-service",height:t.height,width:t.width})):[]}function oe(e){const t=[],i=e.length;for(let r=0;r<i;r++){const o=Je(e[r]);o.length&&t.push(...o);const n=_e(e[r]);n.length&&t.push(...n)}return t}function se(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],i=t.length,r=[];for(let o=0;o<i;o++)I(t[o])&&r.push(t[o]);return r}function De(e,t=!0,i){const r=[],o=P(e);if(o===null)return r;const n=e;if(r.push(o),t&&n.width&&n.height){const s=[],a=se(n);for(const f of a){const l={id:p(f),width:n.width,height:n.height};if(i.canLoadSync(l)){const c=i.loadServiceSync(l);c&&(c.height||(c.height=n.height),c.width||(c.width=n.width),s.push(...oe([c])))}}if(s.length)return r.push(...s),r}return n.service&&r.push(...oe(n.service)),r}function Ze({x:e=0,y:t=0,w:i,h:r,full:o,square:n,percent:s}){if(o)return"full";if(n)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const a=`${e},${t},${i},${r}`;return s?`pct:${a}`:a}function Ge({max:e,percentScale:t,upscaled:i,confined:r,width:o,height:n,serialiseAsFull:s}){const a=[];return i&&a.push("^"),e?(a.push(s?"full":"max"),a.join("")):(r&&a.push("!"),t&&a.push(`pct:${t}`),o&&a.push(`${o}`),a.push(","),n&&a.push(`${n}`),a.join(""))}function Ke(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}var Xe=Object.defineProperty,Ye=Object.defineProperties,et=Object.getOwnPropertyDescriptors,ae=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,le=(e,t,i)=>t in e?Xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,O=(e,t)=>{for(var i in t||(t={}))tt.call(t,i)&&le(e,i,t[i]);if(ae)for(var i of ae(t))it.call(t,i)&&le(e,i,t[i]);return e},A=(e,t)=>Ye(e,et(t));function rt(e,t){const i=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,r=`${e.scheme}://${e.server}/${i?`${i}/`:""}${e.identifier}`;if(e.type==="base")return r;if(e.type==="info")return`${r}/info.json`;let{region:o,size:n,rotation:s,format:a,quality:f}=e;if(t){const l=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],c=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,d=l.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=A(O({},n),{max:!0})),c&&(n.max&&!n.serialiseAsFull&&(n=A(O({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=A(O({},n),{height:void 0}))),d&&(n.max&&n.serialiseAsFull&&(n=A(O({},n),{serialiseAsFull:!1})),n.width&&!n.height&&t.width&&t.height)){const m=t.height/t.width;n=A(O({},n),{height:Math.ceil(n.width*m)})}}return[r,Ze(o),Ge(n),Ke(s),`${f}.${a}`].filter(Boolean).join("/")}function W(e,t,i){const r=Qe({id:w(p(e)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=t,r.size.height=i,{id:rt(r),type:"fixed",width:t,height:i||e.height/(e.width||1)*t,unsafe:e.width>t}}function S(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function nt(e,t,i){const r=e.width?e.width:e.maxWidth;return i.height<=e.maxHeight&&i.width<=e.maxWidth&&i.height>=e.minHeight&&i.width>=e.minWidth&&(!t||Math.abs(i.width-r)<Math.abs(t.width-r))}function ot(e,t){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},e),o=[],n=[];let s=null;const a=(l,c)=>{if(nt(r,c,l)){if(r.preferFixedSize&&l.unsafe){n.push(l);return}r.returnAllOptions&&c&&n.push(c),s=l}else r.returnAllOptions&&n.push(l)},f=t.length;for(let l=0;l<f;l++){const c=t[l](),d=c.length;for(let m=0;m<d;m++){const u=c[m];if(u.type==="unknown"&&r.atAnyCost&&o.push(u),u.type==="fixed"&&(u.unsafe?o.push(u):a(u,s)),u.type==="fixed-service")if(r.unsafeImageService){const v=W(u,r.width,r.height);a(v,s)}else{const v=W(u,u.width,u.height);a(v,s)}if(u.type==="variable"&&u.maxWidth){const v=W({id:u.id,type:"fixed-service",width:u.maxWidth,height:u.maxWidth},u.maxWidth);a(v,s)}}if(s&&!r.returnAllOptions){if(s.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:s||o[0],fallback:o.slice(1),log:i}:r.returnAllOptions?{best:r.atAnyCost?s||n[0]||o[0]:s||n[0],fallback:[...n,...o],log:i}:{best:s||n[0]||null,fallback:s?n:n.slice(1),log:i}}var st=Object.defineProperty,at=Object.defineProperties,lt=Object.getOwnPropertyDescriptors,ce=Object.getOwnPropertySymbols,ct=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,fe=(e,t,i)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ht=(e,t)=>{for(var i in t||(t={}))ct.call(t,i)&&fe(e,i,t[i]);if(ce)for(var i of ce(t))ft.call(t,i)&&fe(e,i,t[i]);return e},ut=(e,t)=>at(e,lt(t));function pt(e,t,i){const r=e>t?e:t,o=i.length,n=[];for(let s=0;s<o;s++){const a=i[s];let f=a.scaleFactors[0],l=r/f;const c=[f];for(;l>=a.width;)f=f*2,c.push(f),l=l/2;n.push(ut(ht({},a),{scaleFactors:c}))}return n}function dt(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const i=e.length;let r=!0;for(let n=0;n<i;n++){const s=e[n],a=t[n];if(s.width!==a.width||s.height!==a.height){r=!1;break}}if(r)return!0;let o=0;for(let n=0;n<i;n++)for(let s=0;s<i;s++)if(e[n].width===t[s].width&&e[n].height===t[s].height){o++;break}return o===i}var b=(e,t,i)=>new Promise((r,o)=>{var n=f=>{try{a(i.next(f))}catch(l){o(l)}},s=f=>{try{a(i.throw(f))}catch(l){o(l)}},a=f=>f.done?r(f.value):Promise.resolve(f.value).then(n,s);a((i=i.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,i,r=!0){const o=S(p(t)),n=w(p(t)),s=this.knownImageServers[o];return this.imageServices[n]=Object.assign(t,{real:!0}),!s&&t.tiles?(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:r,sampledId:p(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:i&&t.height?i.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:qe(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0):this.verify(t)}preLoad(t,i=!0){this.knownImageServers[t.root]=t,i&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,i=!1,r=!1){const o=t==null?void 0:t.source,n=S(p(t)),s=this.knownImageServers[n];if(!s||!s.result||!r&&(s.malformed||s.verifications<this.config.verificationsRequired))return null;const a=w(p(t));return this.imageServices[a]||(this.imageServices[a]={"@context":s.result.context,"@id":p(t),id:p(t),protocol:"http://iiif.io/api/image",tiles:(o==null?void 0:o.tiles)||pt(t.width,t.height,s.result.sampledTiles),sizes:(o==null?void 0:o.sizes)||Ne(Math.round(t.width/s.result.resourceServiceRatio),Math.round(t.height/s.result.resourceServiceRatio),s.result.sizeRatios),profile:(o==null?void 0:o.profile)||s.result.sampledProfile,height:(o==null?void 0:o.height)||t.height,width:(o==null?void 0:o.width)||t.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(t,i){return b(this,arguments,function*(r,o,n=!0,s=[]){const a=yield this.getImageCandidates(r,n);return ot(o,[()=>s,()=>a])})}getImageCandidates(t,i=!0){return b(this,null,function*(){const r=t;if(i&&r.height&&r.width){const o=se(r);for(const n of o){const s={id:p(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(s)}}return De(t,i,this)})}verify(t){return b(this,null,function*(){const i=this.predict(t,!1,!0),r=yield this.fetchService(p(t));if(!i)return!1;const o=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&dt(i.sizes||[],r.sizes||[]);if(o){const n=S(p(t));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0)}return o})}canLoadSync(t){const i=typeof t=="string"?t:p(t),r=w(i);if(this.imageServices[r])return!0;const o=this.knownImageServers[S(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return b(this,null,function*(){return this.knownImageServers[S(p(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,i=!1){return b(this,null,function*(){const r=w(t);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 o=yield this.fetch(r).then(n=>n.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[r]=Object.assign(o,{real:!0}),this.imageServices[r]})}fetch(t,i){return b(this,null,function*(){return fetch(t,i)})}loadService(t,i=!1){return b(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(s=>setTimeout(s,500));else{n=!1;break}}const r=this.knownImageServers[S(p(t))];if(r&&!r.malformed&&!i){yield r.result;const n=this.loadServiceSync(t);if(n)return n}this.fetchingCount++;const o=yield this.fetchService(p(t),i);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const i=w(p(t));return this.imageServices[i]?this.imageServices[i]:this.predict(t)}}new he;function gt(e,t={}){const i=t.imageServiceLoader||new he;async function r(o,n,s,a=[],f){if(typeof o=="string")return{best:P(o),fallback:[],log:[]};const l=e.get(o);if(typeof l=="string")return{best:P(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const c=l.body,d=e.get(c[0]);return f&&!d.width&&(d.width=f.width,d.height=f.height),await i.getThumbnailFromResource(d,n,s,a)}case"Canvas":{const c=l;if(c.thumbnail&&c.thumbnail.length){const d=e.get(c.thumbnail[0]),m=await i.getImageCandidates(d,s);m&&m.length&&a.push(...m)}return r(c.items[0],n,s,a,{width:c.width,height:c.height})}case"AnnotationPage":return r(l.items[0],n,s,a,f);case"Choice":return r(l.items[0],n,s,a,f);case"Collection":{const d=l.items[0];return r(d,n,s,a,f)}case"Manifest":{const d=l.items[0];return r(d,n,s,a,f)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return f&&!l.width&&(l.width=f.width,l.height=f.height),i.getThumbnailFromResource(l,n,s,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 ue(e,t,i=[],r=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const o=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(o&&t.indexOf(o)!==-1)return o;for(const n of i)if(t.indexOf(n)!==-1)return n;if(!r){const s=t.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(e);if(s!==-1)return t[s];for(const a of i){const f=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,l=f?t.indexOf(f):-1;if(l!==-1)return t[l]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function pe(e,t,i={}){const{strictFallback:r=!1,defaultText:o="",separator:n=`
`,fallbackLanguages:s=[],closest:a}=i,f=Object.keys(e||{}),l=a?t:ue(t,f,s,r);if(!e)return o;if(typeof e=="string")return e;const c=l?e[l]:void 0;return c?typeof c=="string"?c:c.join(n):""}function mt(e,t={}){return pe(e,typeof navigator!="undefined"?navigator.language:void 0,t)}const yt=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,vt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function j(e){if(Array.isArray(e))return e.reduce((t,i)=>{const{selector:r,selectors:o}=j(i);return r&&(t.selector||(t.selector=r),t.selectors.push(...o)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,i]=e.split("#");return i?j({type:"FragmentSelector",value:i}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=yt.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"||t[2]==="pct:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const i=e.value.match(vt);if(i){const r={type:"TemporalSelector",temporal:{startTime:i[4]?parseFloat(i[4]):0,endTime:i[7]?parseFloat(i[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}function x(e,t={}){if(Array.isArray(e))return x(e[0]);if(typeof e=="string"){const[i,r]=e.split("#");return r?x({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return x(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:i,selectors:r}=e.selector?j(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:i,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[i,r]=e.id.split("#");return r?x({type:"SpecificResource",source:T(B({},e),{id:i}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:T(B({},e),{id:i}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function z(e,t=!1){if(typeof e=="string"){if(e.startsWith("{"))try{const i=JSON.parse(e);return z(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(e)){for(const i of e){const[r,o]=z(i);if(!r&&o)return[r,o]}return[!0]}return e.type==="Annotation"?[!0]:t&&e.type==="Canvas"&&!e.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function xt(e){return ge(typeof e=="string"?e:JSON.stringify(e))}function de(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(i=>i.json())}return de(me(e),t)}function ge(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 me(e){const i=wt(e).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function wt(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 bt(e){if(!e)throw new Error("Content state is empty");Array.isArray(e)||(e=[e]);let t="vault://virtual-annotation/"+new Date().getTime();const i=[];for(const r of e){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(t=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=x(n);i.push(s)}else{const n=x(r.target);i.push(n)}continue}const o=x(r);i.push(o)}return{id:t,type:"Annotation",motivation:["contentState",...e.motivation||[]],target:i,extensions:{}}}function ye(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function St(e){function t(o){const n=o?typeof o=="string"?e.get(o):o:null;if(!n)return[];const s=e.get(n.items),a=[];for(const f of s)a.push(...e.get(f.items));return a}function i(o,n=[]){const s=Array.isArray(o)?o:t(o),a=[];let f=null;const l=[];for(const c of s){if(c.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const d=e.get(c.body);for(const m of d){const[u,{selector:v}]=ye(m),C=(u.type||"unknown").toLowerCase();if(C==="choice"){const k=e.get(u.items),R=n.length?n.map(F=>k.find(Ot=>Ot.id===F)).filter(Boolean):[k[0]];R.length===0&&R.push(k[0]),f={type:"single-choice",items:k.map(F=>({id:F.id,label:F.label,selected:R.indexOf(F)!==-1})),label:m.label},d.push(...R);continue}a.indexOf(C)===-1&&a.push(C),l.push({type:C,resource:u,target:c.target,selector:v})}}return{types:a,items:l,choice:f}}function r(o){const{choice:n}=i(o);return n}return{getAllPaintingAnnotations:t,getPaintables:i,extractChoices:r}}h.buildLocaleString=pe,h.createEventsHelper=g,h.createPaintingAnnotationsHelper=St,h.createStylesHelper=y,h.createThumbnailHelper=gt,h.decodeContentState=me,h.encodeContentState=ge,h.expandTarget=x,h.getClosestLanguage=ue,h.getValue=mt,h.normaliseContentState=bt,h.parseContentState=de,h.parseSelector=j,h.parseSpecificResource=ye,h.serialiseContentState=xt,h.validateContentState=z,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
(function(A,L){typeof exports=="object"&&typeof module!="undefined"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(A=typeof globalThis!="undefined"?globalThis:A||self,L(A.VaultHelpers={}))})(this,function(A){"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 Ut(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 Dt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",tt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",et="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Xt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",it="http://library.stanford.edu/iiif/image-api/conformance.html#level1",rt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Gt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",nt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",st="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Jt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",ot="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",at="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Yt="http://iiif.io/api/image/1/level0.json",Zt="http://iiif.io/api/image/1/profiles/level0.json",ct="http://iiif.io/api/image/1/level1.json",lt="http://iiif.io/api/image/1/profiles/level1.json",ft="http://iiif.io/api/image/1/level2.json",ht="http://iiif.io/api/image/1/profiles/level2.json",Kt="http://iiif.io/api/image/2/level0.json",te="http://iiif.io/api/image/2/profiles/level0.json",ut="http://iiif.io/api/image/2/level1.json",pt="http://iiif.io/api/image/2/profiles/level1.json",dt="http://iiif.io/api/image/2/level2.json",yt="http://iiif.io/api/image/2/profiles/level2.json",ee="level0",gt="level1",mt="level2",ie="http://iiif.io/api/image/2/level0",vt="http://iiif.io/api/image/2/level1",xt="http://iiif.io/api/image/2/level2",bt=[xt,et,rt,st,at,ft,ht,dt,yt,mt],wt=[...bt,vt,tt,it,nt,ot,ct,lt,ut,pt,gt],re=[ie,vt,xt,Dt,tt,et,Xt,it,rt,Gt,nt,st,Jt,ot,at,Yt,Zt,ct,lt,ft,ht,Kt,te,ut,pt,dt,yt,ee,gt,mt],ne={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},se={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},oe={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function ae(t){return bt.indexOf(t)!==-1?oe:wt.indexOf(t)!==-1?se:ne}function ce(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=ae(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 le(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 fe(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 he(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 ue(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 pe(t,e=""){const{path:i,scheme:r,server:s,prefix:n}=ue(t,e),o=i.split("/").reverse(),[a,c,l,f,...d]=o,y=d.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:r,server:s,prefix:n,identifier:y};if(a==="info.json"){const[,...h]=o;return{type:"info",scheme:r,server:s,prefix:n,identifier:h.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:r,server:s,prefix:n,identifier:y,originalPath:i,region:le(f),size:fe(l),rotation:he(c),quality:p[0],format:p[1]}}function de(t){const e=pe(z(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const i=ce(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 ye(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 ge(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 O(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function U(t){if(!t||!t.profile||!O(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"&&re.indexOf(i)!==-1)return!0;return!1}function me(t){if(!U(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(wt.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 ve(t){if(!me(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:O(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:O(t),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width})}}return e}function St(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 xe(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function D(t){if(typeof t=="string")return St(t);const e=xe(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,r=O(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:St(r):null}function be(t){return U(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:O(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=be(t[r]);s.length&&e.push(...s);const n=ve(t[r]);n.length&&e.push(...n)}return e}function Ot(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,r=[];for(let s=0;s<i;s++)U(e[s])&&r.push(e[s]);return r}function we(t,e=!0,i){const r=[],s=D(t);if(s===null)return r;const n=t;if(r.push(s),e&&n.width&&n.height){const o=[],a=Ot(n);for(const c of a){const l={id:O(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 Se({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 Ae({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 Oe(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var ke=Object.defineProperty,Me=Object.defineProperties,Fe=Object.getOwnPropertyDescriptors,kt=Object.getOwnPropertySymbols,Ce=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable,Mt=(t,e,i)=>e in t?ke(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Q=(t,e)=>{for(var i in e||(e={}))Ce.call(e,i)&&Mt(t,i,e[i]);if(kt)for(var i of kt(e))je.call(e,i)&&Mt(t,i,e[i]);return t},_=(t,e)=>Me(t,Fe(e));function Te(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,d=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}))),d&&(n.max&&n.serialiseAsFull&&(n=_(Q({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const y=e.height/e.width;n=_(Q({},n),{height:Math.ceil(n.width*y)})}}return[r,Se(s),Ae(n),Oe(o),`${c}.${a}`].filter(Boolean).join("/")}function X(t,e,i){const r=de({id:z(O(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:Te(r),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function B(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Re(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 ze(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(Re(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](),d=f.length;for(let y=0;y<d;y++){const p=f[y];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 h=X(p,r.width,r.height);a(h,o)}else{const h=X(p,p.width,p.height);a(h,o)}if(p.type==="variable"&&p.maxWidth){const h=X({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);a(h,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 Ie=Object.defineProperty,Pe=Object.defineProperties,We=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,Ct=(t,e,i)=>e in t?Ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,$e=(t,e)=>{for(var i in e||(e={}))Be.call(e,i)&&Ct(t,i,e[i]);if(Ft)for(var i of Ft(e))qe.call(e,i)&&Ct(t,i,e[i]);return t},He=(t,e)=>Pe(t,We(e));function Le(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(He($e({},a),{scaleFactors:f}))}return n}function Qe(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 jt(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 I=(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 Tt{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=B(O(e)),n=z(O(e)),o=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),!o&&e.tiles&&!jt(e)?(this.knownImageServers[s]={verifications:0,malformed:!1,root:s,preLoaded:r,sampledId:O(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:ye(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=B(O(e)),o=this.knownImageServers[n];if(!o||!o.result||!r&&(o.malformed||o.verifications<this.config.verificationsRequired)||jt(e.source))return null;const a=z(O(e));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":O(e),id:O(e),protocol:"http://iiif.io/api/image",tiles:(s==null?void 0:s.tiles)||Le(e.width,e.height,o.result.sampledTiles),sizes:(s==null?void 0:s.sizes)||ge(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 I(this,arguments,function*(r,s,n=!0,o=[]){const a=yield this.getImageCandidates(r,n);return ze(s,[()=>o,()=>a])})}getImageCandidates(e,i=!0){return I(this,null,function*(){const r=e;if(i&&r.height&&r.width){const s=Ot(r);for(const n of s){const o={id:O(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(o)}}return we(e,i,this)})}verify(e){return I(this,null,function*(){const i=this.predict(e,!1,!0),r=yield this.fetchService(O(e));if(!i)return!1;const s=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&Qe(i.sizes||[],r.sizes||[]);if(s){const n=B(O(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:O(e),r=z(i);if(this.imageServices[r])return!0;const s=this.knownImageServers[B(i)];return s&&!s.malformed&&s.verifications>=this.config.verificationsRequired}markAsMalformed(e){return I(this,null,function*(){return this.knownImageServers[B(O(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return I(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 I(this,null,function*(){return fetch(e,i)})}loadService(e,i=!1){return I(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[B(O(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(O(e),i);return this.fetchingCount--,s.real&&this.sample(s,e),s})}loadServiceSync(e){const i=z(O(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new Tt;function _e(t,e={}){const i=e.imageServiceLoader||new Tt;async function r(s,n,o,a=[],c){if(typeof s=="string")return{best:D(s),fallback:[],log:[]};const l=t.get(s);if(typeof l=="string")return{best:D(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,d=t.get(f[0]);return c&&!d.width&&(d.width=c.width,d.height=c.height),await i.getThumbnailFromResource(d,n,o,a)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const d=t.get(f.thumbnail[0]),y=await i.getImageCandidates(d,o);y&&y.length&&a.push(...y)}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 d=l.items[0];return r(d,n,o,a,c)}case"Manifest":{const d=l.items[0];return r(d,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 Rt(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 zt(t,e,i={}){const{strictFallback:r=!1,defaultText:s="",separator:n=`
`,fallbackLanguages:o=[],closest:a}=i,c=Object.keys(t||{}),l=a?e:Rt(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 Ee(t,e={}){return zt(t,typeof navigator!="undefined"?navigator.language:void 0,e)}var Ne=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")}}(),E=Math.PI*2,G=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,d=n*c+s*l;return{x:f+o,y:d+a}},Ve=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}]},It=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)},Ue=function(e,i,r,s,n,o,a,c,l,f,d,y){var p=Math.pow(n,2),h=Math.pow(o,2),b=Math.pow(d,2),m=Math.pow(y,2),v=p*h-p*m-h*b;v<0&&(v=0),v/=p*m+h*b,v=Math.sqrt(v)*(a===c?-1:1);var u=v*n/o*y,g=v*-o/n*d,x=f*u-l*g+(e+r)/2,w=l*u+f*g+(i+s)/2,S=(d-u)/n,M=(y-g)/o,F=(-d-u)/n,C=(-y-g)/o,W=It(1,0,S,M),j=It(S,M,F,C);return c===0&&j>0&&(j-=E),c===1&&j<0&&(j+=E),[x,w,W,j]},De=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,d=f===void 0?0:f,y=e.sweepFlag,p=y===void 0?0:y,h=[];if(o===0||a===0)return[];var b=Math.sin(l*E/360),m=Math.cos(l*E/360),v=m*(i-s)/2+b*(r-n)/2,u=-b*(i-s)/2+m*(r-n)/2;if(v===0&&u===0)return[];o=Math.abs(o),a=Math.abs(a);var g=Math.pow(v,2)/Math.pow(o,2)+Math.pow(u,2)/Math.pow(a,2);g>1&&(o*=Math.sqrt(g),a*=Math.sqrt(g));var x=Ue(i,r,s,n,o,a,d,p,b,m,v,u),w=Ne(x,4),S=w[0],M=w[1],F=w[2],C=w[3],W=Math.abs(C)/(E/4);Math.abs(1-W)<1e-7&&(W=1);var j=Math.max(Math.ceil(W),1);C/=j;for(var _t=0;_t<j;_t++)h.push(Ve(F,C)),F+=C;return h.map(function(K){var Et=G(K[0],o,a,m,b,S,M),gi=Et.x,mi=Et.y,Nt=G(K[1],o,a,m,b,S,M),vi=Nt.x,xi=Nt.y,Vt=G(K[2],o,a,m,b,S,M),bi=Vt.x,wi=Vt.y;return{x1:gi,y1:mi,x2:vi,y2:xi,x:bi,y:wi}})},Xe=Je,J={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},Ge=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function Je(t){var e=[];return t.replace(Ge,function(i,r,s){var n=r.toLowerCase();for(s=Ze(s),n=="m"&&s.length>2&&(e.push([r].concat(s.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(s.length==J[n])return s.unshift(r),e.push(s);if(s.length<J[n])throw new Error("malformed path data");e.push([r].concat(s.splice(0,J[n])))}}),e}var Ye=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Ze(t){var e=t.match(Ye);return e?e.map(Number):[]}var Ke=ti;function ti(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 ei(t){const e=Xe(t),i=Ke(e);let r,s=0,n=0,o=0,a=0,c,l,f=0,d=0;const y=[];for(let p=0;p<i.length;p++){let h=i[p];const b=h[0];switch(b){case"M":s=h[1],n=h[2];break;case"H":h=["L",h[1],n];break;case"V":h=["L",s,h[1]];break;case"S":{let m=f,v=d;(r==="C"||r=="S")&&(m+=m-o,v+=v-a),h=["C",m,v,h[1],h[2],h[3],h[4]]}break;case"T":r==="Q"||r=="T"?(c=f*2-c,l=d*2-l):(c=f,l=d),h=["Q",c,l,h[1],h[2]];break;case"Q":c=h[1],l=h[2];break;case"A":{const m=De({px:f,py:d,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!m.length)continue;for(const[v,u]of m.entries())h=["C",u.x1,u.y1,u.x2,u.y2,u.x,u.y],v<m.length-1&&y.push(h);h=h}break;case"Z":h=["L",s,n];break}r=b,f=h[h.length-2],d=h[h.length-1],["C","Q","A"].indexOf(b)>-1?(o=h[h.length-4],a=h[h.length-3]):(o=f,a=d),y.push(h)}return y}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
*
* All code in this module is based on JavaScript code by Raph Levien, published on his blog at
* https://raphlinus.github.io/.
* I merely changed the structure a bit, removed some unneeded parts and added some comments and type hints.
*
* Flattening of quadratic Bézier curves:
* - Article: https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html
* - Code: https://github.com/raphlinus/raphlinus.github.io/blob/master/_posts/2019-12-23-flatten-quadbez.md?plain=1#L73-L212
*
* Flattening of cubic Bézier curves: https://levien.com/tmp/flatten.html
*
* Note that the code in this module has a different license than the rest of the package,
* due to the inclusion of Apache-licensed third party code.
*
* @license
* Copyright 2022 Johannes Baiter <johannes.baiter@gmail.com>
* Copyright 2019, 2022 Raph Levien <raph.levien@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function ii(t,e,i,r=1){return new Pt(t,e,i).subdivide(r)}function ri(t,e,i,r,s=1){return new Y(new Float64Array([t.x,t.y,e.x,e.y,i.x,i.y,r.x,r.y])).subdivide(s)}function ni(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 q(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Pt{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,d=(n-e)*c-(o-i)*a,y=l/d,p=f/d,h=Math.abs(d)/(Math.hypot(a,c)*Math.abs(p-y));return{x0:e,x2:n,scale:h,cross:d}}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=q(r),c=q(s),l=[0];for(let f=1;f<o;f++){const y=(q(r+(s-r)*f/o)-a)/(c-a);l.push(y)}return l.push(1),l.map(f=>this.eval(f))}}class Y{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 Pt({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 Y(r)}subdivide(e){const i=.1*e,r=e-i,s=Math.sqrt(r),n=ni(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(n/(432*i*i),1/6)),a=[];let c=0;for(let h=0;h<o;h++){const b=h/o,m=(h+1)/o,v=this.subsegment(b,m).midpoint_quadbez(),u=v.mapToBasic(),g=N(u.x0),x=N(u.x2),w=Math.sqrt(u.scale);let S=Math.abs(x-g)*w;if(Math.sign(u.x0)!=Math.sign(u.x2)){const M=s/w,F=s*Math.abs(x-g)/N(M);S=Math.max(S,F)}a.push({quad:v,a0:g,a2:x,val:S}),c+=S}const l=.5*c/s,f=Math.ceil(l),d=[{x:this.c[0],y:this.c[1]}];let y=0,p=0;for(let h=1;h<f;h++){const b=c*h/f;for(;y+a[p].val<b;)y+=a[p].val,p++;const m=a[p].a0,v=a[p].a2,u=q(m),g=q(v),x=m+(v-m)*(b-y)/a[p].val,S=(q(x)-u)/(g-u);d.push(a[p].quad.eval(S))}return d.push({x:this.c[6],y:this.c[7]}),d}}const si=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,oi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,Wt=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function V(t,{domParser:e,svgPreprocessor:i}={}){var r,s;if(Array.isArray(t))return t.reduce((n,o)=>{const{selector:a,selectors:c}=V(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?V({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=si.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(oi);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 d=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!d)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const y=Bt(d);y&&(n=y.points,l=y.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=li(y.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 ai(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 Bt(t){var e,i,r,s,n,o,a,c,l,f,d,y,p,h,b,m,v;for(const u of Array.from(t.children))switch(u==null?void 0:u.tagName.toLowerCase()){case"g":{const g=Bt(u);if(g)return g}continue;case"path":{const g=u.getAttribute("d");if(!g)continue;const x=ei(g);return{element:u,points:ci(x),shapeType:ai(x)}}case"circle":{const g=parseFloat((e=u.getAttribute("cx"))!=null?e:"0"),x=parseFloat((i=u.getAttribute("cy"))!=null?i:"0"),w=parseFloat((r=u.getAttribute("r"))!=null?r:"0");if(!w)continue;const S=[];for(let M=0;M<=360;M+=12){const F=M*Math.PI/180;S.push([g+w*Math.cos(F),x+w*Math.sin(F)])}return{element:u,points:S,shapeType:"circle"}}case"ellipse":{const g=parseFloat((s=u.getAttribute("cx"))!=null?s:"0"),x=parseFloat((n=u.getAttribute("cy"))!=null?n:"0"),w=parseFloat((o=u.getAttribute("rx"))!=null?o:"0"),S=parseFloat((a=u.getAttribute("ry"))!=null?a:"0");if(!w&&!S)continue;const M=[];for(let F=0;F<=360;F+=12){const C=Math.tan(F/360*Math.PI),W=w*(1-C**2)/(1+C**2),j=S*2*C/(1+C**2);M.push([g+W,x+j])}return{element:u,points:M,shapeType:"ellipse"}}case"line":{const g=parseFloat((c=u.getAttribute("x0"))!=null?c:"0"),x=parseFloat((l=u.getAttribute("y0"))!=null?l:"0"),w=parseFloat((f=u.getAttribute("x1"))!=null?f:"0"),S=parseFloat((d=u.getAttribute("y1"))!=null?d:"0");if(g===w&&x===S)continue;return{element:u,points:[[g,x],[w,S]],shapeType:"polyline"}}case"polygon":case"polyline":{const g=(p=(y=u.getAttribute("points"))==null?void 0:y.split(" ").map(w=>w.split(",").map(parseFloat)))!=null?p:[];if(!g.length)continue;let x="polyline";return u.tagName.toLowerCase()==="polygon"&&(g.push(g[0]),x="polygon"),{element:u,points:g,shapeType:x}}case"rect":{const g=parseFloat((h=u.getAttribute("x"))!=null?h:"0"),x=parseFloat((b=u.getAttribute("y"))!=null?b:"0"),w=parseFloat((m=u.getAttribute("width"))!=null?m:"0"),S=parseFloat((v=u.getAttribute("height"))!=null?v:"0");if(!w||!S)continue;return{element:u,points:[[g,x],[g+w,x],[g+w,x+S],[g,x+S],[g,x]],shapeType:"rect"}}default:continue}return null}function ci(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(...ri({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(...ii({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 li(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=Wt.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=Wt.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 T(t,e={}){if(Array.isArray(t))return T(t[0]);if(typeof t=="string"){const[i,r]=t.split("#");return r?T({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 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:i,selectors:r}=t.selector?V(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?T({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 Z(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const i=JSON.parse(t);return Z(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const i of t){const[r,s]=Z(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 fi(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(Ht(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 Ht(t){const i=hi(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function hi(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 ui(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=T(n);i.push(o)}else{const n=T(r.target);i.push(n)}continue}const s=T(r);i.push(s)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:i,extensions:{}}}function Lt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function pi(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 d=t.get(f.body);for(const y of d){const[p,{selector:h}]=Lt(y),b=(p.type||"unknown").toLowerCase();if(b==="choice"){const m=t.get(p.items),v=n.length?n.map(u=>m.find(g=>g.id===u)).filter(Boolean):[m[0]];v.length===0&&v.push(m[0]),c={type:"single-choice",items:m.map(u=>({id:u.id,label:u.label,selected:v.indexOf(u)!==-1})),label:y.label},d.push(...v);continue}a.indexOf(b)===-1&&a.push(b),l.push({type:b,resource:p,target:f.target,selector:h})}}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 k(t,e,i){e[H]=e[H]||[],e[H].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_"),$=Symbol.for("_reactive_"),H=Symbol.for("_defined_");function di(t,e=!1){const i={id:null,[H]:[],[P]:{},[$]:null,is(r){return typeof r=="string"?this.id===r:r.id?r.id===this.id:!1},reactive(){if(!this[$])return this[$]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const r=this.unwrap();for(const s of Object.keys(r||{}))this[H].includes(s)?this[P][s]=r[s]:this[s]=r[s]}},unreactive(){this[$]&&(this[$](),this[$]=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 k("items",i,t),k("annotations",i,t),k("structures",i,t),k("seeAlso",i,t),k("service",i,t),k("services",i,t),k("rendering",i,t),k("partOf",i,t),k("start",i,t),k("supplementary",i,t),k("homepage",i,t),k("thumbnail",i,t),k("placeholderCanvas",i,t),k("accompanyingCanvas",i,t),k("provider",i,t),k("body",i,t),k("logo",i,t),i}function Qt(t){return Array.isArray(t)?t.map(e=>Qt(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=di(e,i),s=Object.create(r),n=Object.assign(s,t);return i&&n.reactive(),n}function yi(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[H]}}}A.buildLocaleString=zt,A.createEventsHelper=L,A.createObjectsHelper=yi,A.createPaintingAnnotationsHelper=pi,A.createStylesHelper=Ut,A.createThumbnailHelper=_e,A.decodeContentState=Ht,A.encodeContentState=$t,A.expandTarget=T,A.getClosestLanguage=Rt,A.getValue=Ee,A.normaliseContentState=ui,A.parseContentState=qt,A.parseSelector=V,A.parseSpecificResource=Lt,A.serialiseContentState=fi,A.unwrapObject=Qt,A.validateContentState=Z,A.wrapObject=R,Object.defineProperties(A,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
//# sourceMappingURL=index.umd.js.map

6

dist/react-i18next/cjs/react-i18next.js

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

"use strict";var G=Object.defineProperty,Q=Object.defineProperties;var X=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var U=(e,t,n)=>t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))F.call(t,n)&&U(e,n,t[n]);if(x)for(var n of x(t))T.call(t,n)&&U(e,n,t[n]);return e},S=(e,t)=>Q(e,X(t));var I=(e,t)=>{var n={};for(var r in e)F.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&x)for(var r of x(e))t.indexOf(r)<0&&T.call(e,r)&&(n[r]=e[r]);return n};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var c=require("react");function Z(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var m=Z(c);function ee(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function te(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function z(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function ne(e,t,n){return t&&z(e.prototype,t),n&&z(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var re=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,ae={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"'},ie=function(t){return ae[t]},ue=function(t){return t.replace(re,ie)},oe={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:ue},se,fe=c.createContext();function ce(){return oe}var le=function(){function e(){te(this,e),this.usedNamespaces={}}return ne(e,[{key:"addUsedNamespaces",value:function(n){var r=this;n.forEach(function(i){r.usedNamespaces[i]||(r.usedNamespaces[i]=!0)})}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}]),e}();function de(){return se}function ge(){if(console&&console.warn){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];typeof n[0]=="string"&&(n[0]="react-i18next:: ".concat(n[0])),(e=console).warn.apply(e,n)}}var M={};function j(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];typeof t[0]=="string"&&M[t[0]]||(typeof t[0]=="string"&&(M[t[0]]=new Date),ge.apply(void 0,t))}function B(e,t,n){e.loadNamespaces(t,function(){if(e.isInitialized)n();else{var r=function i(){setTimeout(function(){e.off("initialized",i)},0),n()};e.on("initialized",r)}})}function pe(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=t.languages[0],i=t.options?t.options.fallbackLng:!1,o=t.languages[t.languages.length-1];if(r.toLowerCase()==="cimode")return!0;var a=function(s,f){var d=t.services.backendConnector.state["".concat(s,"|").concat(f)];return d===-1||d===2};return n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!a(t.isLanguageChangingTo,e)?!1:!!(t.hasResourceBundle(r,e)||!t.services.backendConnector.backend||t.options.resources&&!t.options.partialBundledLanguages||a(r,e)&&(!i||a(o,e)))}function ve(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t.languages||!t.languages.length)return j("i18n.languages were undefined or empty",t.languages),!0;var r=t.options.ignoreJSONStructure!==void 0;return r?t.hasLoadedNamespace(e,{precheck:function(o,a){if(n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&o.services.backendConnector.backend&&o.isLanguageChangingTo&&!a(o.isLanguageChangingTo,e))return!1}}):pe(e,t,n)}function me(e){if(Array.isArray(e))return e}function ye(e,t){var n=e==null?null:typeof Symbol!="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],i=!0,o=!1,a,u;try{for(n=n.call(e);!(i=(a=n.next()).done)&&(r.push(a.value),!(t&&r.length===t));i=!0);}catch(s){o=!0,u=s}finally{try{!i&&n.return!=null&&n.return()}finally{if(o)throw u}}return r}}function H(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function be(e,t){if(!!e){if(typeof e=="string")return H(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return H(e,t)}}function he(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Oe(e,t){return me(e)||ye(e,t)||be(e,t)||he()}function q(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function P(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?q(Object(n),!0).forEach(function(r){ee(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):q(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}var Se=function(t,n){var r=c.useRef();return c.useEffect(function(){r.current=n?r.current:t},[t,n]),r.current};function C(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.i18n,r=c.useContext(fe)||{},i=r.i18n,o=r.defaultNS,a=n||i||de();if(a&&!a.reportNamespaces&&(a.reportNamespaces=new le),!a){j("You will need to pass in an i18next instance by using initReactI18next");var u=function(p){return Array.isArray(p)?p[p.length-1]:p},s=[u,{},!1];return s.t=u,s.i18n={},s.ready=!1,s}a.options.react&&a.options.react.wait!==void 0&&j("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var f=P(P(P({},ce()),a.options.react),t),d=f.useSuspense,Y=f.keyPrefix,l=e||o||a.options&&a.options.defaultNS;l=typeof l=="string"?[l]:l||["translation"],a.reportNamespaces.addUsedNamespaces&&a.reportNamespaces.addUsedNamespaces(l);var y=(a.isInitialized||a.initializedStoreOnce)&&l.every(function(g){return ve(g,a,f)});function h(){return a.getFixedT(null,f.nsMode==="fallback"?l:l[0],Y)}var $=c.useState(h),_=Oe($,2),k=_[0],w=_[1],L=l.join(),A=Se(L),b=c.useRef(!0);c.useEffect(function(){var g=f.bindI18n,p=f.bindI18nStore;b.current=!0,!y&&!d&&B(a,l,function(){b.current&&w(h)}),y&&A&&A!==L&&b.current&&w(h);function N(){b.current&&w(h)}return g&&a&&a.on(g,N),p&&a&&a.store.on(p,N),function(){b.current=!1,g&&a&&g.split(" ").forEach(function(E){return a.off(E,N)}),p&&a&&p.split(" ").forEach(function(E){return a.store.off(E,N)})}},[a,L]);var R=c.useRef(!0);c.useEffect(function(){b.current&&!R.current&&w(h),R.current=!1},[a]);var O=[k,a,y];if(O.t=k,O.i18n=a,O.ready=y,y||!y&&!d)return O;throw new Promise(function(g){B(a,l,function(){g()})})}function D(i){var o=i,{as:e,language:t,children:n}=o,r=I(o,["as","language","children"]);const{i18n:a}=C(),u=c.useMemo(()=>a.dir?a.dir(t):"ltr",[t]);return c.useMemo(()=>a.services?a.services.languageUtils.getLanguagePartFromCode(a.language)===a.services.languageUtils.getLanguagePartFromCode(t):!1,[a.language,t])?e?m.default.createElement(e,v({},r),n):m.default.createElement("span",v({},r),n):e?m.default.createElement(e,S(v({},r),{lang:t,dir:u}),n):m.default.createElement("span",S(v({},r),{lang:t,dir:u}),n)}function W(e,t,n=[],r=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const i=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(i&&t.indexOf(i)!==-1)return i;for(const o of n)if(t.indexOf(o)!==-1)return o;if(!r){const a=t.map(u=>u.indexOf("-")!==-1?u.slice(0,u.indexOf("-")):null).indexOf(e);if(a!==-1)return t[a];for(const u of n){const s=u.indexOf("-")!==-1?u.slice(0,u.indexOf("-")):null,f=s?t.indexOf(s):-1;if(f!==-1)return t[f]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function J(e,t,n={}){const{strictFallback:r=!1,defaultText:i="",separator:o=`
`,fallbackLanguages:a=[],closest:u}=n,s=Object.keys(e||{}),f=u?t:W(t,s,a,r);if(!e)return i;if(typeof e=="string")return e;const d=f?e[f]:void 0;return d?typeof d=="string"?d:d.join(o):""}function K(e,t=[]){const{i18n:n}=C(),r=n&&n.languages?n.languages:[],i=n&&n.language?n.language:"en";return c.useMemo(()=>{const o=e();return W(i,o,r)},[r,i,...t])}function V(e,t){const n=K(()=>Object.keys(e||{}),[e]);return[c.useMemo(()=>J(e,n,{defaultText:t,closest:!0}),[n,t,e]),n]}const we=o=>{var a=o,{as:e,defaultText:t,enableDangerouslySetInnerHTML:n,children:r}=a,i=I(a,["as","defaultText","enableDangerouslySetInnerHTML","children"]);const[u,s]=V(r,t);return s?m.default.createElement(D,S(v({},i),{as:e,language:s,title:n?void 0:u,dangerouslySetInnerHTML:n?{__html:u}:void 0}),n?void 0:u):e?m.default.createElement(e,v({},i),u):m.default.createElement("span",S(v({},i),{title:n?void 0:u,dangerouslySetInnerHTML:n?{__html:u}:void 0}),n?void 0:u)};function Ne(){const{i18n:e}=C(),t=e&&e.languages?e.languages:[],n=e&&e.language?e.language:"en";return function(i,o){return J(i,n,{fallbackLanguages:t,defaultText:o})}}exports.LanguageString=D;exports.LocaleString=we;exports.useClosestLanguage=K;exports.useCreateLocaleString=Ne;exports.useLocaleString=V;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var f=require("react");function D(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var v=D(f);function W(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function J(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function k(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function K(e,t,n){return t&&k(e.prototype,t),n&&k(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var V=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,Y={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"\xA9","&#169;":"\xA9","&reg;":"\xAE","&#174;":"\xAE","&hellip;":"\u2026","&#8230;":"\u2026","&#x2F;":"/","&#47;":"/"},$=function(t){return Y[t]},G=function(t){return t.replace(V,$)},Q={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:G},X,Z=f.createContext();function ee(){return Q}var te=function(){function e(){J(this,e),this.usedNamespaces={}}return K(e,[{key:"addUsedNamespaces",value:function(n){var r=this;n.forEach(function(i){r.usedNamespaces[i]||(r.usedNamespaces[i]=!0)})}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}]),e}();function ne(){return X}function re(){if(console&&console.warn){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];typeof n[0]=="string"&&(n[0]="react-i18next:: ".concat(n[0])),(e=console).warn.apply(e,n)}}var A={};function L(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];typeof t[0]=="string"&&A[t[0]]||(typeof t[0]=="string"&&(A[t[0]]=new Date),re.apply(void 0,t))}function F(e,t,n){e.loadNamespaces(t,function(){if(e.isInitialized)n();else{var r=function i(){setTimeout(function(){e.off("initialized",i)},0),n()};e.on("initialized",r)}})}function ae(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=t.languages[0],i=t.options?t.options.fallbackLng:!1,u=t.languages[t.languages.length-1];if(r.toLowerCase()==="cimode")return!0;var a=function(c,s){var d=t.services.backendConnector.state["".concat(c,"|").concat(s)];return d===-1||d===2};return n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!a(t.isLanguageChangingTo,e)?!1:!!(t.hasResourceBundle(r,e)||!t.services.backendConnector.backend||t.options.resources&&!t.options.partialBundledLanguages||a(r,e)&&(!i||a(u,e)))}function ie(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t.languages||!t.languages.length)return L("i18n.languages were undefined or empty",t.languages),!0;var r=t.options.ignoreJSONStructure!==void 0;return r?t.hasLoadedNamespace(e,{precheck:function(u,a){if(n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&u.services.backendConnector.backend&&u.isLanguageChangingTo&&!a(u.isLanguageChangingTo,e))return!1}}):ae(e,t,n)}function ue(e){if(Array.isArray(e))return e}function oe(e,t){var n=e==null?null:typeof Symbol!="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],i=!0,u=!1,a,o;try{for(n=n.call(e);!(i=(a=n.next()).done)&&(r.push(a.value),!(t&&r.length===t));i=!0);}catch(c){u=!0,o=c}finally{try{!i&&n.return!=null&&n.return()}finally{if(u)throw o}}return r}}function R(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function se(e,t){if(!!e){if(typeof e=="string")return R(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return R(e,t)}}function fe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ce(e,t){return ue(e)||oe(e,t)||se(e,t)||fe()}function U(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function x(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?U(Object(n),!0).forEach(function(r){W(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):U(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}var le=function(t,n){var r=f.useRef();return f.useEffect(function(){r.current=n?r.current:t},[t,n]),r.current};function E(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.i18n,r=f.useContext(Z)||{},i=r.i18n,u=r.defaultNS,a=n||i||ne();if(a&&!a.reportNamespaces&&(a.reportNamespaces=new te),!a){L("You will need to pass in an i18next instance by using initReactI18next");var o=function(p){return Array.isArray(p)?p[p.length-1]:p},c=[o,{},!1];return c.t=o,c.i18n={},c.ready=!1,c}a.options.react&&a.options.react.wait!==void 0&&L("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var s=x(x(x({},ee()),a.options.react),t),d=s.useSuspense,I=s.keyPrefix,l=e||u||a.options&&a.options.defaultNS;l=typeof l=="string"?[l]:l||["translation"],a.reportNamespaces.addUsedNamespaces&&a.reportNamespaces.addUsedNamespaces(l);var m=(a.isInitialized||a.initializedStoreOnce)&&l.every(function(g){return ie(g,a,s)});function b(){return a.getFixedT(null,s.nsMode==="fallback"?l:l[0],I)}var q=f.useState(b),P=ce(q,2),j=P[0],O=P[1],w=l.join(),C=le(w),y=f.useRef(!0);f.useEffect(function(){var g=s.bindI18n,p=s.bindI18nStore;y.current=!0,!m&&!d&&F(a,l,function(){y.current&&O(b)}),m&&C&&C!==w&&y.current&&O(b);function S(){y.current&&O(b)}return g&&a&&a.on(g,S),p&&a&&a.store.on(p,S),function(){y.current=!1,g&&a&&g.split(" ").forEach(function(N){return a.off(N,S)}),p&&a&&p.split(" ").forEach(function(N){return a.store.off(N,S)})}},[a,w]);var _=f.useRef(!0);f.useEffect(function(){y.current&&!_.current&&O(b),_.current=!1},[a,I]);var h=[j,a,m];if(h.t=j,h.i18n=a,h.ready=m,m||!m&&!d)return h;throw new Promise(function(g){F(a,l,function(){g()})})}function T({as:e,language:t,children:n,...r}){const{i18n:i}=E(),u=f.useMemo(()=>i.dir?i.dir(t):"ltr",[t]);return f.useMemo(()=>i.services?i.services.languageUtils.getLanguagePartFromCode(i.language)===i.services.languageUtils.getLanguagePartFromCode(t):!1,[i.language,t])?e?v.default.createElement(e,{...r},n):v.default.createElement("span",{...r},n):e?v.default.createElement(e,{...r,lang:t,dir:u},n):v.default.createElement("span",{...r,lang:t,dir:u},n)}function z(e,t,n=[],r=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const i=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(i&&t.indexOf(i)!==-1)return i;for(const u of n)if(t.indexOf(u)!==-1)return u;if(!r){const a=t.map(o=>o.indexOf("-")!==-1?o.slice(0,o.indexOf("-")):null).indexOf(e);if(a!==-1)return t[a];for(const o of n){const c=o.indexOf("-")!==-1?o.slice(0,o.indexOf("-")):null,s=c?t.indexOf(c):-1;if(s!==-1)return t[s]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function M(e,t,n={}){const{strictFallback:r=!1,defaultText:i="",separator:u=`
`,fallbackLanguages:a=[],closest:o}=n,c=Object.keys(e||{}),s=o?t:z(t,c,a,r);if(!e)return i;if(typeof e=="string")return e;const d=s?e[s]:void 0;return d?typeof d=="string"?d:d.join(u):""}function B(e,t=[]){const{i18n:n}=E(),r=n&&n.languages?n.languages:[],i=n&&n.language?n.language:"en";return f.useMemo(()=>{const u=e();return z(i,u,r)},[r,i,...t])}function H(e,t){const n=B(()=>Object.keys(e||{}),[e]);return[f.useMemo(()=>M(e,n,{defaultText:t,closest:!0}),[n,t,e]),n]}const de=({as:e,defaultText:t,enableDangerouslySetInnerHTML:n,children:r,...i})=>{const[u,a]=H(r,t);return a?v.default.createElement(T,{...i,as:e,language:a,title:n?void 0:u,dangerouslySetInnerHTML:n?{__html:u}:void 0},n?void 0:u):e?v.default.createElement(e,{...i},u):v.default.createElement("span",{...i,title:n?void 0:u,dangerouslySetInnerHTML:n?{__html:u}:void 0},n?void 0:u)};function ge(){const{i18n:e}=E(),t=e&&e.languages?e.languages:[],n=e&&e.language?e.language:"en";return function(i,u){return M(i,n,{fallbackLanguages:t,defaultText:u})}}exports.LanguageString=T;exports.LocaleString=de;exports.useClosestLanguage=B;exports.useCreateLocaleString=ge;exports.useLocaleString=H;
//# sourceMappingURL=react-i18next.js.map
{
"name": "@iiif/vault-helpers",
"version": "0.9.8",
"version": "0.9.10",
"license": "MIT",

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

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

@@ -81,2 +85,5 @@ },

".build/types/painting-annotations.d.ts"
],
"objects": [
".build/types/objects.d.ts"
]

@@ -96,3 +103,6 @@ }

"optionalDependencies": {
"react-i18next": "^11.18.0"
"react-i18next": "^11.18.0",
"svg-arc-to-cubic-bezier": "^3.2.0",
"parse-svg-path": "^0.1.0",
"abs-svg-path": "^0.1.0"
},

@@ -107,3 +117,5 @@ "peerDependencies": {

"@iiif/parser": "^1.0.10",
"@types/jsdom": "^20.0.0",
"@types/react": "^17.0.38",
"@types/svg-arc-to-cubic-bezier": "^3.2.0",
"@typescript-eslint/eslint-plugin": "^5.9.1",

@@ -117,2 +129,3 @@ "@typescript-eslint/parser": "^5.9.1",

"happy-dom": "^6.0.3",
"jsdom": "^20.0.0",
"prettier": "^2.5.1",

@@ -119,0 +132,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

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