@recogito/text-annotator 4.0.0-beta → 4.0.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +12 -409
- package/dist/model/core/text-annotation.d.ts +1 -1
- package/dist/model/w3c/w3c-text-annotation.d.ts +1 -1
- package/dist/model/w3c/w3c-text-format-adapter.d.ts +3 -3
- package/dist/rendering/base-renderer.d.ts +5 -5
- package/dist/rendering/highlight-style.d.ts +3 -3
- package/dist/rendering/highlight.d.ts +3 -3
- package/dist/rendering/index.d.ts +1 -0
- package/dist/rendering/renderer-css-highlight/css-highlight-renderer.d.ts +1 -1
- package/dist/rendering/renderer-spans/spans-renderer.d.ts +2 -1
- package/dist/rendering/viewport.d.ts +2 -2
- package/dist/selection-handler.d.ts +5 -5
- package/dist/state/spatial-tree.d.ts +4 -4
- package/dist/state/text-annotation-store.d.ts +4 -4
- package/dist/state/text-annotator-state.d.ts +5 -4
- package/dist/text-annotator-options.d.ts +3 -3
- package/dist/text-annotator.css +1 -1
- package/dist/text-annotator.d.ts +6 -5
- package/dist/text-annotator.es.js +470 -469
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -2
- package/dist/text-annotator.umd.js.map +1 -1
- package/dist/utils/annotation/range-to-selector.d.ts +1 -1
- package/dist/utils/annotation/revive-annotation.d.ts +1 -1
- package/dist/utils/annotation/scroll-into-view.d.ts +2 -2
- package/dist/utils/highlight/compute-z-index.d.ts +2 -2
- package/package.json +9 -10
- package/dist/src/index.d.ts +0 -12
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(I,Be){typeof exports=="object"&&typeof module<"u"?Be(exports):typeof define=="function"&&define.amd?define(["exports"],Be):(I=typeof globalThis<"u"?globalThis:I||self,Be(I.RecogitoJS={}))})(this,(function(I){"use strict";let Be=()=>({emit(e,...t){for(let n=this.events[e]||[],i=0,o=n.length;i<o;i++)n[i](...t)},events:{},on(e,t){return(this.events[e]||=[]).push(t),()=>{this.events[e]=this.events[e]?.filter(n=>t!==n)}}});var En=Object.prototype.hasOwnProperty;function ke(e,t){var n,i;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((i=e.length)===t.length)for(;i--&&ke(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(En.call(e,n)&&++i&&!En.call(t,n)||!(n in t)||!ke(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}let Xi=Symbol("clean"),le=[],Se=0;const gt=4;let Ut=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},lc:0,listen(i){return n.lc=t.push(i),()=>{for(let r=Se+gt;r<le.length;)le[r]===i?le.splice(r,gt):r+=gt;let o=t.indexOf(i);~o&&(t.splice(o,1),--n.lc||n.off())}},notify(i,o){let r=!le.length;for(let s of t)le.push(s,n.value,i,o);if(r){for(Se=0;Se<le.length;Se+=gt)le[Se](le[Se+1],le[Se+2],le[Se+3]);le.length=0}},off(){},set(i){let o=n.value;o!==i&&(n.value=i,n.notify(o))},subscribe(i){let o=n.listen(i);return i(n.value),o},value:e};return process.env.NODE_ENV!=="production"&&(n[Xi]=()=>{t=[],n.lc=0,n.off()}),n};const Fi=e=>{const t=Ut(null);return e.observe(({changes:n})=>{const i=t.get();if(i){(n.deleted||[]).some(r=>r.id===i)&&t.set(null);const o=(n.updated||[]).find(({oldValue:r})=>r.id===i);o&&t.set(o.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var Dt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Dt||{});const Ht={selected:[]},Yi=(e,t,n)=>{const i=Ut(Ht);let o=t;const r=()=>{ke(i.get(),Ht)||i.set(Ht)},s=()=>{var g;return((g=i.get().selected)==null?void 0:g.length)===0},a=g=>{if(s())return!1;const p=typeof g=="string"?g:g.id;return i.get().selected.some(E=>E.id===p)},l=(g,p)=>{let E;if(Array.isArray(g)){if(E=g.map(b=>e.getAnnotation(b)).filter(Boolean),E.length<g.length){console.warn("Invalid selection: "+g.filter(b=>!E.some(d=>d.id===b)));return}}else{const b=e.getAnnotation(g);if(!b){console.warn("Invalid selection: "+g);return}E=[b]}const T=E.reduce((b,d)=>{const R=S(d);return R==="EDIT"?[...b,{id:d.id,editable:!0}]:R==="SELECT"?[...b,{id:d.id}]:b},[]);i.set({selected:T,event:p})},c=(g,p)=>{const E=Array.isArray(g)?g:[g],T=E.map(b=>e.getAnnotation(b)).filter(b=>!!b);i.set({selected:T.map(b=>{const d=p===void 0?S(b)==="EDIT":p;return{id:b.id,editable:d}})}),T.length!==E.length&&console.warn("Invalid selection",g)},u=g=>{if(s())return!1;const{selected:p}=i.get();p.some(({id:E})=>g.includes(E))&&i.set({selected:p.filter(({id:E})=>!g.includes(E))})},f=g=>{o=g,c(i.get().selected.map(({id:p})=>p))},S=g=>Ki(g,o,n);return e.observe(({changes:g})=>u((g.deleted||[]).map(p=>p.id))),{get event(){const g=i.get();return g?g.event:null},get selected(){const g=i.get();return g?[...g.selected]:null},get userSelectAction(){return o},clear:r,evalSelectAction:S,isEmpty:s,isSelected:a,setSelected:c,setUserSelectAction:f,subscribe:i.subscribe.bind(i),userSelect:l}},Ki=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},J=[];for(let e=0;e<256;++e)J.push((e+256).toString(16).slice(1));function Wi(e,t=0){return(J[e[t+0]]+J[e[t+1]]+J[e[t+2]]+J[e[t+3]]+"-"+J[e[t+4]]+J[e[t+5]]+"-"+J[e[t+6]]+J[e[t+7]]+"-"+J[e[t+8]]+J[e[t+9]]+"-"+J[e[t+10]]+J[e[t+11]]+J[e[t+12]]+J[e[t+13]]+J[e[t+14]]+J[e[t+15]]).toLowerCase()}let Pt;const ji=new Uint8Array(16);function $i(){if(!Pt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Pt=crypto.getRandomValues.bind(crypto)}return Pt(ji)}const zi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),An={randomUUID:zi};function qi(e,t,n){var i;e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??$i();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Wi(o)}function Sn(e,t,n){return An.randomUUID&&!e?An.randomUUID():qi(e)}const Vt=e=>{const t=n=>{const i={...n};return n.created&&typeof n.created=="string"&&(i.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(i.updated=new Date(n.updated)),i};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Gi=(e,t,n,i)=>({id:Sn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),Ji=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},Qi=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},Zi=(e,t)=>t.bodies.map(n=>{const i=e.bodies.find(o=>o.id===n.id);return{newBody:n,oldBody:i&&!ke(i,n)?i:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:i})=>({oldBody:n,newBody:i})),eo=(e,t)=>!ke(e.target,t.target),On=(e,t)=>{const n=Ji(e,t),i=Qi(e,t),o=Zi(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:o.length>0?o:void 0,targetUpdated:eo(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var V=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(V||{});const to=(e,t)=>{var n,i;const{changes:o,origin:r}=t;if(!(e.options.origin?e.options.origin===r:r!=="SILENT"))return!1;if(e.options.ignore){const{ignore:s}=e.options,a=l=>l&&l.length>0;if(!(a(o.created)||a(o.deleted))){const l=(n=o.updated)==null?void 0:n.some(u=>a(u.bodiesCreated)||a(u.bodiesDeleted)||a(u.bodiesUpdated)),c=(i=o.updated)==null?void 0:i.some(u=>u.targetUpdated);if(s==="BODY_ONLY"&&l&&!c||s==="TARGET_ONLY"&&c&&!l)return!1}}if(e.options.annotations){const s=new Set([...(o.created||[]).map(a=>a.id),...(o.deleted||[]).map(a=>a.id),...(o.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>s.has(a))}else return!0},no=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),i=new Set((e.updated||[]).map(({newValue:f})=>f.id)),o=new Set((t.created||[]).map(f=>f.id)),r=new Set((t.deleted||[]).map(f=>f.id)),s=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),a=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||i.has(f.id)).map(({oldValue:f})=>f.id)),l=[...(e.created||[]).filter(f=>!r.has(f.id)).map(f=>s.has(f.id)?t.updated.find(({oldValue:S})=>S.id===f.id).newValue:f),...t.created||[]],c=[...(e.deleted||[]).filter(f=>!o.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],u=[...(e.updated||[]).filter(({newValue:f})=>!r.has(f.id)).map(f=>{const{oldValue:S,newValue:g}=f;if(s.has(g.id)){const p=t.updated.find(E=>E.oldValue.id===g.id).newValue;return On(S,p)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!a.has(f.id))];return{created:l,deleted:c,updated:u}},mt=e=>{const t=e.id===void 0?Sn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},io=e=>e.id!==void 0,oo=()=>{const e=new Map,t=new Map,n=[],i=(A,O={})=>{n.push({onChange:A,options:O})},o=A=>{const O=n.findIndex(C=>C.onChange==A);O>-1&&n.splice(O,1)},r=(A,O)=>{const C={origin:A,changes:{created:O.created||[],updated:O.updated||[],deleted:O.deleted||[]},state:[...e.values()]};n.forEach(N=>{to(N,C)&&N.onChange(C)})},s=(A,O=V.LOCAL)=>{if(A.id&&e.get(A.id))throw Error(`Cannot add annotation ${A.id} - exists already`);{const C=mt(A);e.set(C.id,C),C.bodies.forEach(N=>t.set(N.id,C.id)),r(O,{created:[C]})}},a=(A,O)=>{const C=mt(typeof A=="string"?O:A),N=typeof A=="string"?A:A.id,F=N&&e.get(N);if(F){const X=On(F,C);return N===C.id?e.set(N,C):(e.delete(N),e.set(C.id,C)),F.bodies.forEach(k=>t.delete(k.id)),C.bodies.forEach(k=>t.set(k.id,C.id)),X}else console.warn(`Cannot update annotation ${N} - does not exist`)},l=(A,O=V.LOCAL,C=V.LOCAL)=>{const N=io(O)?C:O,F=a(A,O);F&&r(N,{updated:[F]})},c=(A,O=V.LOCAL)=>{e.get(A.id)?l(A,O):s(A,O)},u=(A,O=V.LOCAL)=>{const C=A.reduce((N,F)=>{const X=a(F);return X?[...N,X]:N},[]);C.length>0&&r(O,{updated:C})},f=(A,O=V.LOCAL)=>{const C=A.map(mt),{toAdd:N,toUpdate:F}=C.reduce((k,M)=>e.get(M.id)?{...k,toUpdate:[...k.toUpdate,M]}:{...k,toAdd:[...k.toAdd,M]},{toAdd:[],toUpdate:[]}),X=F.map(k=>a(k,O)).filter(Boolean);N.forEach(k=>{e.set(k.id,k),k.bodies.forEach(M=>t.set(M.id,k.id))}),r(O,{created:N,updated:X})},S=(A,O=V.LOCAL)=>{const C=e.get(A.annotation);if(C){const N={...C,bodies:[...C.bodies,A]};e.set(C.id,N),t.set(A.id,N.id),r(O,{updated:[{oldValue:C,newValue:N,bodiesCreated:[A]}]})}else console.warn(`Attempt to add body to missing annotation: ${A.annotation}`)},g=()=>[...e.values()],p=(A=V.LOCAL)=>{const O=[...e.values()];e.clear(),t.clear(),r(A,{deleted:O})},E=(A,O=!0,C=V.LOCAL)=>{const N=A.map(mt);if(O){const F=[...e.values()];e.clear(),t.clear(),N.forEach(X=>{e.set(X.id,X),X.bodies.forEach(k=>t.set(k.id,X.id))}),r(C,{created:N,deleted:F})}else{const F=A.reduce((X,k)=>{const M=k.id&&e.get(k.id);return M?[...X,M]:X},[]);if(F.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${F.map(X=>X.id).join(", ")}`);N.forEach(X=>{e.set(X.id,X),X.bodies.forEach(k=>t.set(k.id,X.id))}),r(C,{created:N})}},T=A=>{const O=typeof A=="string"?A:A.id,C=e.get(O);if(C)return e.delete(O),C.bodies.forEach(N=>t.delete(N.id)),C;console.warn(`Attempt to delete missing annotation: ${O}`)},b=(A,O=V.LOCAL)=>{const C=T(A);C&&r(O,{deleted:[C]})},d=(A,O=V.LOCAL)=>{const C=A.reduce((N,F)=>{const X=T(F);return X?[...N,X]:N},[]);C.length>0&&r(O,{deleted:C})},R=A=>{const O=e.get(A.annotation);if(O){const C=O.bodies.find(N=>N.id===A.id);if(C){t.delete(C.id);const N={...O,bodies:O.bodies.filter(F=>F.id!==A.id)};return e.set(O.id,N),{oldValue:O,newValue:N,bodiesDeleted:[C]}}else console.warn(`Attempt to delete missing body ${A.id} from annotation ${A.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${A.annotation}`)},U=(A,O=V.LOCAL)=>{const C=R(A);C&&r(O,{updated:[C]})},x=(A,O=V.LOCAL)=>{const C=A.map(N=>R(N)).filter(Boolean);C.length>0&&r(O,{updated:C})},L=A=>{const O=e.get(A);return O?{...O}:void 0},H=A=>{const O=t.get(A);if(O){const C=L(O).bodies.find(N=>N.id===A);if(C)return C;console.error(`Store integrity error: body ${A} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${A}`)},P=(A,O)=>{if(A.annotation!==O.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const C=e.get(A.annotation);if(C){const N=C.bodies.find(X=>X.id===A.id),F={...C,bodies:C.bodies.map(X=>X.id===N.id?O:X)};return e.set(C.id,F),N.id!==O.id&&(t.delete(N.id),t.set(O.id,F.id)),{oldValue:C,newValue:F,bodiesUpdated:[{oldBody:N,newBody:O}]}}else console.warn(`Attempt to add body to missing annotation ${A.annotation}`)},K=(A,O,C=V.LOCAL)=>{const N=P(A,O);N&&r(C,{updated:[N]})},_=(A,O=V.LOCAL)=>{const C=A.map(N=>P({id:N.id,annotation:N.annotation},N)).filter(Boolean);r(O,{updated:C})},D=A=>{const O=e.get(A.annotation);if(O){const C={...O,target:{...O.target,...A}};return e.set(O.id,C),{oldValue:O,newValue:C,targetUpdated:{oldTarget:O.target,newTarget:A}}}else console.warn(`Attempt to update target on missing annotation: ${A.annotation}`)};return{addAnnotation:s,addBody:S,all:g,bulkAddAnnotations:E,bulkDeleteAnnotations:d,bulkDeleteBodies:x,bulkUpdateAnnotations:u,bulkUpdateBodies:_,bulkUpdateTargets:(A,O=V.LOCAL)=>{const C=A.map(N=>D(N)).filter(Boolean);C.length>0&&r(O,{updated:C})},bulkUpsertAnnotations:f,clear:p,deleteAnnotation:b,deleteBody:U,getAnnotation:L,getBody:H,observe:i,unobserve:o,updateAnnotation:l,updateBody:K,updateTarget:(A,O=V.LOCAL)=>{const C=D(A);C&&r(O,{updated:[C]})},upsertAnnotation:c}};let ro=()=>({emit(e,...t){for(let n=this.events[e]||[],i=0,o=n.length;i<o;i++)n[i](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var i;this.events[e]=(i=this.events[e])==null?void 0:i.filter(o=>t!==o)}}});const so=250,ao=(e,t)=>{const n=ro(),i=[];let o=-1,r=!1,s=0;const a=p=>{if(!r){const{changes:E}=p,T=performance.now();if(T-s>so)i.splice(o+1),i.push(E),o=i.length-1;else{const b=i.length-1;i[b]=no(i[b],E)}s=T}r=!1};e.observe(a,{origin:V.LOCAL});const l=p=>p&&p.length>0&&e.bulkDeleteAnnotations(p),c=p=>p&&p.length>0&&e.bulkAddAnnotations(p,!1),u=p=>p&&p.length>0&&e.bulkUpdateAnnotations(p.map(({oldValue:E})=>E)),f=p=>p&&p.length>0&&e.bulkUpdateAnnotations(p.map(({newValue:E})=>E)),S=p=>p&&p.length>0&&e.bulkAddAnnotations(p,!1),g=p=>p&&p.length>0&&e.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...i],pointer:o}),on:(p,E)=>n.on(p,E),redo:()=>{if(i.length-1>o){r=!0;const{created:p,updated:E,deleted:T}=i[o+1];c(p),f(E),g(T),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){r=!0;const{created:p,updated:E,deleted:T}=i[o];l(p),u(E),S(T),n.emit("undo",i[o]),o-=1}}}},lo=()=>{const e=Ut([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},co=(e,t,n,i)=>{const{hover:o,selection:r,store:s,viewport:a}=e,l=new Map;let c=[],u;const f=(E,T)=>{l.has(E)?l.get(E).push(T):l.set(E,[T])},S=(E,T)=>{const b=l.get(E);if(b){const d=b.indexOf(T);d!==-1&&b.splice(d,1)}},g=(E,T,b)=>{l.has(E)&&setTimeout(()=>{l.get(E).forEach(d=>{if(n){const R=Array.isArray(T)?T.map(x=>n.serialize(x)):n.serialize(T),U=b?b instanceof PointerEvent?b:n.serialize(b):void 0;d(R,U)}else d(T,b)})},1)};r.subscribe(({selected:E})=>{if(!(c.length===0&&E.length===0)){if(c.length===0&&E.length>0)c=E.map(({id:T})=>s.getAnnotation(T));else if(c.length>0&&E.length===0)c.forEach(T=>{const b=s.getAnnotation(T.id);b&&!ke(b,T)&&g("updateAnnotation",b,T)}),c=[];else{const T=new Set(c.map(d=>d.id)),b=new Set(E.map(({id:d})=>d));c.filter(d=>!b.has(d.id)).forEach(d=>{const R=s.getAnnotation(d.id);R&&!ke(R,d)&&g("updateAnnotation",R,d)}),c=[...c.filter(d=>b.has(d.id)),...E.filter(({id:d})=>!T.has(d)).map(({id:d})=>s.getAnnotation(d))]}g("selectionChanged",c)}}),o.subscribe(E=>{!u&&E?g("mouseEnterAnnotation",s.getAnnotation(E)):u&&!E?g("mouseLeaveAnnotation",s.getAnnotation(u)):u&&E&&(g("mouseLeaveAnnotation",s.getAnnotation(u)),g("mouseEnterAnnotation",s.getAnnotation(E))),u=E}),a?.subscribe(E=>g("viewportIntersect",E.map(T=>s.getAnnotation(T)))),s.observe(E=>{const{created:T,deleted:b}=E.changes;(T||[]).forEach(d=>g("createAnnotation",d)),(b||[]).forEach(d=>g("deleteAnnotation",d)),(E.changes.updated||[]).filter(d=>[...d.bodiesCreated||[],...d.bodiesDeleted||[],...d.bodiesUpdated||[]].length>0).forEach(({oldValue:d,newValue:R})=>{const U=c.find(x=>x.id===d.id)||d;c=c.map(x=>x.id===d.id?R:x),g("updateAnnotation",R,U)})},{origin:V.LOCAL}),s.observe(E=>{if(c){const T=new Set(c.map(d=>d.id)),b=(E.changes.updated||[]).filter(({newValue:d})=>T.has(d.id)).map(({newValue:d})=>d);b.length>0&&(c=c.map(d=>b.find(U=>U.id===d.id)||d))}},{origin:V.REMOTE});const p=E=>T=>{const{updated:b}=T;E?(b||[]).forEach(d=>g("updateAnnotation",d.oldValue,d.newValue)):(b||[]).forEach(d=>g("updateAnnotation",d.newValue,d.oldValue))};return t.on("undo",p(!0)),t.on("redo",p(!1)),{on:f,off:S,emit:g}},uo=e=>t=>t.reduce((n,i)=>{const{parsed:o,error:r}=e.parse(i);return r?{parsed:n.parsed,failed:[...n.failed,i]}:o?{parsed:[...n.parsed,o],failed:n.failed}:{...n}},{parsed:[],failed:[]}),fo=(e,t,n)=>{const{store:i,selection:o}=e,r=b=>{if(n){const{parsed:d,error:R}=n.parse(b);d?i.addAnnotation(d,V.REMOTE):console.error(R)}else i.addAnnotation(Vt(b),V.REMOTE)},s=()=>o.clear(),a=()=>i.clear(),l=b=>{const d=i.getAnnotation(b);return n&&d?n.serialize(d):d},c=()=>n?i.all().map(n.serialize):i.all(),u=()=>{var b;const d=(((b=o.selected)==null?void 0:b.map(R=>R.id))||[]).map(R=>i.getAnnotation(R)).filter(Boolean);return n?d.map(n.serialize):d},f=(b,d=!0)=>fetch(b).then(R=>R.json()).then(R=>(g(R,d),R)),S=b=>{if(typeof b=="string"){const d=i.getAnnotation(b);if(i.deleteAnnotation(b),d)return n?n.serialize(d):d}else{const d=n?n.parse(b).parsed:b;if(d)return i.deleteAnnotation(d),b}},g=(b,d=!0)=>{if(n){const R=n.parseAll||uo(n),{parsed:U,failed:x}=R(b);x.length>0&&console.warn(`Discarded ${x.length} invalid annotations`,x),i.bulkAddAnnotations(U,d,V.REMOTE)}else i.bulkAddAnnotations(b.map(Vt),d,V.REMOTE)},p=(b,d)=>{b?o.setSelected(b,d):o.clear()},E=b=>{o.setUserSelectAction(b)},T=b=>{if(n){const d=n.parse(b).parsed,R=n.serialize(i.getAnnotation(d.id));return i.updateAnnotation(d),R}else{const d=i.getAnnotation(b.id);return i.updateAnnotation(Vt(b)),d}};return{addAnnotation:r,cancelSelected:s,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:c,getHistory:t.getHistory,getSelected:u,loadAnnotations:f,redo:t.redo,removeAnnotation:S,setAnnotations:g,setSelected:p,setUserSelectAction:E,undo:t.undo,updateAnnotation:T}},ho="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let po=e=>crypto.getRandomValues(new Uint8Array(e)),go=(e,t,n)=>{let i=(2<<Math.log2(e.length-1))-1,o=-~(1.6*i*t/e.length);return(r=t)=>{let s="";for(;;){let a=n(o),l=o|0;for(;l--;)if(s+=e[a[l]&i]||"",s.length>=r)return s}}},mo=(e,t=21)=>go(e,t|0,po),bo=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=ho[n[e]&63];return t};const wo=()=>({isGuest:!0,id:mo("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),yo=e=>{const t=JSON.stringify(e);let n=0;for(let i=0,o=t.length;i<o;i++){let r=t.charCodeAt(i);n=(n<<5)-n+r,n|=0}return`${n}`},Cn=e=>e?typeof e=="object"?{...e}:e:void 0,vo=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:i,type:o,purpose:r,value:s,created:a,modified:l,creator:c,...u}=n;return{id:i||`temp-${yo(n)}`,annotation:t,type:o,purpose:r,value:s,creator:Cn(c),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...u}}),Eo=e=>e.map(t=>{var n;const{annotation:i,created:o,updated:r,...s}=t,a={...s,created:o?.toISOString(),modified:r?.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a});bo();var Ao="2.0.6",So=500,xn="user-agent",_e="",Tn="?",$={FUNCTION:"function",OBJECT:"object",STRING:"string",UNDEFINED:"undefined"},ne="browser",be="cpu",ue="device",ce="engine",oe="os",Ue="result",w="name",h="type",y="vendor",v="version",te="architecture",We="major",m="model",je="console",B="mobile",Y="tablet",z="smarttv",fe="wearable",bt="xr",$e="embedded",De="inapp",Xt="brands",Le="formFactors",Ft="fullVersionList",He="platform",Yt="platformVersion",wt="bitness",Oe="sec-ch-ua",Oo=Oe+"-full-version-list",Co=Oe+"-arch",xo=Oe+"-"+wt,To=Oe+"-form-factors",Ro=Oe+"-"+B,ko=Oe+"-"+m,Rn=Oe+"-"+He,Lo=Rn+"-version",kn=[Xt,Ft,B,m,He,Yt,te,Le,wt],yt="Amazon",Pe="Apple",Ln="ASUS",Nn="BlackBerry",Ne="Google",In="Huawei",Kt="Lenovo",Mn="Honor",vt="LG",Wt="Microsoft",jt="Motorola",$t="Nvidia",Bn="OnePlus",zt="OPPO",ze="Samsung",_n="Sharp",qe="Sony",qt="Xiaomi",Gt="Zebra",Un="Chrome",Dn="Chromium",Ce="Chromecast",Et="Edge",Ge="Firefox",Je="Opera",Jt="Facebook",Hn="Sogou",Ve="Mobile ",Qe=" Browser",Qt="Windows",No=typeof window!==$.UNDEFINED,ie=No&&window.navigator?window.navigator:void 0,xe=ie&&ie.userAgentData?ie.userAgentData:void 0,Io=function(e,t){var n={},i=t;if(!St(t)){i={};for(var o in t)for(var r in t[o])i[r]=t[o][r].concat(i[r]?i[r]:[])}for(var s in e)n[s]=i[s]&&i[s].length%2===0?i[s].concat(e[s]):e[s];return n},At=function(e){for(var t={},n=0;n<e.length;n++)t[e[n].toUpperCase()]=e[n];return t},Zt=function(e,t){if(typeof e===$.OBJECT&&e.length>0){for(var n in e)if(Te(t)==Te(e[n]))return!0;return!1}return Ze(e)?Te(t)==Te(e):!1},St=function(e,t){for(var n in e)return/^(browser|cpu|device|engine|os)$/.test(n)||(t?St(e[n]):!1)},Ze=function(e){return typeof e===$.STRING},en=function(e){if(e){for(var t=[],n=Xe(/\\?\"/g,e).split(","),i=0;i<n.length;i++)if(n[i].indexOf(";")>-1){var o=Ot(n[i]).split(";v=");t[i]={brand:o[0],version:o[1]}}else t[i]=Ot(n[i]);return t}},Te=function(e){return Ze(e)?e.toLowerCase():e},tn=function(e){return Ze(e)?Xe(/[^\d\.]/g,e).split(".")[0]:void 0},we=function(e){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];typeof n==$.OBJECT&&n.length==2?this[n[0]]=n[1]:this[n]=void 0}return this},Xe=function(e,t){return Ze(t)?t.replace(e,_e):t},et=function(e){return Xe(/\\?\"/g,e)},Ot=function(e,t){return e=Xe(/^\s\s*/,String(e)),typeof t===$.UNDEFINED?e:e.substring(0,t)},nn=function(e,t){if(!(!e||!t))for(var n=0,i,o,r,s,a,l;n<t.length&&!a;){var c=t[n],u=t[n+1];for(i=o=0;i<c.length&&!a&&c[i];)if(a=c[i++].exec(e),a)for(r=0;r<u.length;r++)l=a[++o],s=u[r],typeof s===$.OBJECT&&s.length>0?s.length===2?typeof s[1]==$.FUNCTION?this[s[0]]=s[1].call(this,l):this[s[0]]=s[1]:s.length>=3&&(typeof s[1]===$.FUNCTION&&!(s[1].exec&&s[1].test)?s.length>3?this[s[0]]=l?s[1].apply(this,s.slice(2)):void 0:this[s[0]]=l?s[1].call(this,l,s[2]):void 0:s.length==3?this[s[0]]=l?l.replace(s[1],s[2]):void 0:s.length==4?this[s[0]]=l?s[3].call(this,l.replace(s[1],s[2])):void 0:s.length>4&&(this[s[0]]=l?s[3].apply(this,[l.replace(s[1],s[2])].concat(s.slice(4))):void 0)):this[s]=l||void 0;n+=2}},he=function(e,t){for(var n in t)if(typeof t[n]===$.OBJECT&&t[n].length>0){for(var i=0;i<t[n].length;i++)if(Zt(t[n][i],e))return n===Tn?void 0:n}else if(Zt(t[n],e))return n===Tn?void 0:n;return t.hasOwnProperty("*")?t["*"]:e},Pn={ME:"4.90","NT 3.51":"3.51","NT 4.0":"4.0",2e3:["5.0","5.01"],XP:["5.1","5.2"],Vista:"6.0",7:"6.1",8:"6.2","8.1":"6.3",10:["6.4","10.0"],NT:""},Vn={embedded:"Automotive",mobile:"Mobile",tablet:["Tablet","EInk"],smarttv:"TV",wearable:"Watch",xr:["VR","XR"],"?":["Desktop","Unknown"],"*":void 0},Mo={Chrome:"Google Chrome",Edge:"Microsoft Edge","Edge WebView2":"Microsoft Edge WebView2","Chrome WebView":"Android WebView","Chrome Headless":"HeadlessChrome","Huawei Browser":"HuaweiBrowser","MIUI Browser":"Miui Browser","Opera Mobi":"OperaMobile",Yandex:"YaBrowser"},Xn={browser:[[/\b(?:crmo|crios)\/([\w\.]+)/i],[v,[w,Ve+"Chrome"]],[/webview.+edge\/([\w\.]+)/i],[v,[w,Et+" WebView"]],[/edg(?:e|ios|a)?\/([\w\.]+)/i],[v,[w,"Edge"]],[/(opera mini)\/([-\w\.]+)/i,/(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i,/(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i],[w,v],[/opios[\/ ]+([\w\.]+)/i],[v,[w,Je+" Mini"]],[/\bop(?:rg)?x\/([\w\.]+)/i],[v,[w,Je+" GX"]],[/\bopr\/([\w\.]+)/i],[v,[w,Je]],[/\bb[ai]*d(?:uhd|[ub]*[aekoprswx]{5,6})[\/ ]?([\w\.]+)/i],[v,[w,"Baidu"]],[/\b(?:mxbrowser|mxios|myie2)\/?([-\w\.]*)\b/i],[v,[w,"Maxthon"]],[/(kindle)\/([\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer|sleipnir)[\/ ]?([\w\.]*)/i,/(avant|iemobile|slim(?:browser|boat|jet))[\/ ]?([\d\.]*)/i,/(?:ms|\()(ie) ([\w\.]+)/i,/(flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|qupzilla|falkon|rekonq|puffin|brave|whale(?!.+naver)|qqbrowserlite|duckduckgo|klar|helio|(?=comodo_)?dragon|otter|dooble|(?:lg |qute)browser|palemoon)\/([-\w\.]+)/i,/(heytap|ovi|115|surf|qwant)browser\/([\d\.]+)/i,/(qwant)(?:ios|mobile)\/([\d\.]+)/i,/(ecosia|weibo)(?:__| \w+@)([\d\.]+)/i],[w,v],[/quark(?:pc)?\/([-\w\.]+)/i],[v,[w,"Quark"]],[/\bddg\/([\w\.]+)/i],[v,[w,"DuckDuckGo"]],[/(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i],[v,[w,"UCBrowser"]],[/microm.+\bqbcore\/([\w\.]+)/i,/\bqbcore\/([\w\.]+).+microm/i,/micromessenger\/([\w\.]+)/i],[v,[w,"WeChat"]],[/konqueror\/([\w\.]+)/i],[v,[w,"Konqueror"]],[/trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i],[v,[w,"IE"]],[/ya(?:search)?browser\/([\w\.]+)/i],[v,[w,"Yandex"]],[/slbrowser\/([\w\.]+)/i],[v,[w,"Smart "+Kt+Qe]],[/(avast|avg)\/([\w\.]+)/i],[[w,/(.+)/,"$1 Secure"+Qe],v],[/\bfocus\/([\w\.]+)/i],[v,[w,Ge+" Focus"]],[/\bopt\/([\w\.]+)/i],[v,[w,Je+" Touch"]],[/coc_coc\w+\/([\w\.]+)/i],[v,[w,"Coc Coc"]],[/dolfin\/([\w\.]+)/i],[v,[w,"Dolphin"]],[/coast\/([\w\.]+)/i],[v,[w,Je+" Coast"]],[/miuibrowser\/([\w\.]+)/i],[v,[w,"MIUI"+Qe]],[/fxios\/([\w\.-]+)/i],[v,[w,Ve+Ge]],[/\bqihoobrowser\/?([\w\.]*)/i],[v,[w,"360"]],[/\b(qq)\/([\w\.]+)/i],[[w,/(.+)/,"$1Browser"],v],[/(oculus|sailfish|huawei|vivo|pico)browser\/([\w\.]+)/i],[[w,/(.+)/,"$1"+Qe],v],[/samsungbrowser\/([\w\.]+)/i],[v,[w,ze+" Internet"]],[/metasr[\/ ]?([\d\.]+)/i],[v,[w,Hn+" Explorer"]],[/(sogou)mo\w+\/([\d\.]+)/i],[[w,Hn+" Mobile"],v],[/(electron)\/([\w\.]+) safari/i,/(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i,/m?(qqbrowser|2345(?=browser|chrome|explorer))\w*[\/ ]?v?([\w\.]+)/i],[w,v],[/(lbbrowser|rekonq)/i],[w],[/ome\/([\w\.]+) \w* ?(iron) saf/i,/ome\/([\w\.]+).+qihu (360)[es]e/i],[v,w],[/((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i],[[w,Jt],v,[h,De]],[/(kakao(?:talk|story))[\/ ]([\w\.]+)/i,/(naver)\(.*?(\d+\.[\w\.]+).*\)/i,/(daum)apps[\/ ]([\w\.]+)/i,/safari (line)\/([\w\.]+)/i,/\b(line)\/([\w\.]+)\/iab/i,/(alipay)client\/([\w\.]+)/i,/(twitter)(?:and| f.+e\/([\w\.]+))/i,/(bing)(?:web|sapphire)\/([\w\.]+)/i,/(instagram|snapchat|klarna)[\/ ]([-\w\.]+)/i],[w,v,[h,De]],[/\bgsa\/([\w\.]+) .*safari\//i],[v,[w,"GSA"],[h,De]],[/musical_ly(?:.+app_?version\/|_)([\w\.]+)/i],[v,[w,"TikTok"],[h,De]],[/\[(linkedin)app\]/i],[w,[h,De]],[/(zalo(?:app)?)[\/\sa-z]*([\w\.-]+)/i],[[w,/(.+)/,"Zalo"],v,[h,De]],[/(chromium)[\/ ]([-\w\.]+)/i],[w,v],[/headlesschrome(?:\/([\w\.]+)| )/i],[v,[w,Un+" Headless"]],[/wv\).+chrome\/([\w\.]+).+edgw\//i],[v,[w,Et+" WebView2"]],[/ wv\).+(chrome)\/([\w\.]+)/i],[[w,Un+" WebView"],v],[/droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i],[v,[w,"Android"+Qe]],[/chrome\/([\w\.]+) mobile/i],[v,[w,Ve+"Chrome"]],[/(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i],[w,v],[/version\/([\w\.\,]+) .*mobile(?:\/\w+ | ?)safari/i],[v,[w,Ve+"Safari"]],[/iphone .*mobile(?:\/\w+ | ?)safari/i],[[w,Ve+"Safari"]],[/version\/([\w\.\,]+) .*(safari)/i],[v,w],[/webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i],[w,[v,"1"]],[/(webkit|khtml)\/([\w\.]+)/i],[w,v],[/(?:mobile|tablet);.*(firefox)\/([\w\.-]+)/i],[[w,Ve+Ge],v],[/(navigator|netscape\d?)\/([-\w\.]+)/i],[[w,"Netscape"],v],[/(wolvic|librewolf)\/([\w\.]+)/i],[w,v],[/mobile vr; rv:([\w\.]+)\).+firefox/i],[v,[w,Ge+" Reality"]],[/ekiohf.+(flow)\/([\w\.]+)/i,/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo browser|minimo|conkeror)[\/ ]?([\w\.\+]+)/i,/(seamonkey|k-meleon|icecat|iceape|firebird|phoenix|basilisk|waterfox)\/([-\w\.]+)$/i,/(firefox)\/([\w\.]+)/i,/(mozilla)\/([\w\.]+(?= .+rv\:.+gecko\/\d+)|[0-4][\w\.]+(?!.+compatible))/i,/(amaya|dillo|doris|icab|ladybird|lynx|mosaic|netsurf|obigo|polaris|w3m|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,/\b(links) \(([\w\.]+)/i],[w,[v,/_/g,"."]],[/(cobalt)\/([\w\.]+)/i],[w,[v,/[^\d\.]+./,_e]]],cpu:[[/\b((amd|x|x86[-_]?|wow|win)64)\b/i],[[te,"amd64"]],[/(ia32(?=;))/i,/\b((i[346]|x)86)(pc)?\b/i],[[te,"ia32"]],[/\b(aarch64|arm(v?[89]e?l?|_?64))\b/i],[[te,"arm64"]],[/\b(arm(v[67])?ht?n?[fl]p?)\b/i],[[te,"armhf"]],[/( (ce|mobile); ppc;|\/[\w\.]+arm\b)/i],[[te,"arm"]],[/ sun4\w[;\)]/i],[[te,"sparc"]],[/\b(avr32|ia64(?=;)|68k(?=\))|\barm(?=v([1-7]|[5-7]1)l?|;|eabi)|(irix|mips|sparc)(64)?\b|pa-risc)/i,/((ppc|powerpc)(64)?)( mac|;|\))/i,/(?:osf1|[freopnt]{3,4}bsd) (alpha)/i],[[te,/ower/,_e,Te]],[/mc680.0/i],[[te,"68k"]],[/winnt.+\[axp/i],[[te,"alpha"]]],device:[[/\b(sch-i[89]0\d|shw-m380s|sm-[ptx]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i],[m,[y,ze],[h,Y]],[/\b((?:s[cgp]h|gt|sm)-(?![lr])\w+|sc[g-]?[\d]+a?|galaxy nexus)/i,/samsung[- ]((?!sm-[lr]|browser)[-\w]+)/i,/sec-(sgh\w+)/i],[m,[y,ze],[h,B]],[/(?:\/|\()(ip(?:hone|od)[\w, ]*)[\/\);]/i],[m,[y,Pe],[h,B]],[/\b(?:ios|apple\w+)\/.+[\(\/](ipad)/i,/\b(ipad)[\d,]*[;\] ].+(mac |i(pad)?)os/i],[m,[y,Pe],[h,Y]],[/(macintosh);/i],[m,[y,Pe]],[/\b(sh-?[altvz]?\d\d[a-ekm]?)/i],[m,[y,_n],[h,B]],[/\b((?:brt|eln|hey2?|gdi|jdn)-a?[lnw]09|(?:ag[rm]3?|jdn2|kob2)-a?[lw]0[09]hn)(?: bui|\)|;)/i],[m,[y,Mn],[h,Y]],[/honor([-\w ]+)[;\)]/i],[m,[y,Mn],[h,B]],[/\b((?:ag[rs][2356]?k?|bah[234]?|bg[2o]|bt[kv]|cmr|cpn|db[ry]2?|jdn2|got|kob2?k?|mon|pce|scm|sht?|[tw]gr|vrd)-[ad]?[lw][0125][09]b?|605hw|bg2-u03|(?:gem|fdr|m2|ple|t1)-[7a]0[1-4][lu]|t1-a2[13][lw]|mediapad[\w\. ]*(?= bui|\)))\b(?!.+d\/s)/i],[m,[y,In],[h,Y]],[/(?:huawei) ?([-\w ]+)[;\)]/i,/\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][\dc][adnt]?)\b(?!.+d\/s)/i],[m,[y,In],[h,B]],[/oid[^\)]+; (2[\dbc]{4}(182|283|rp\w{2})[cgl]|m2105k81a?c)(?: bui|\))/i,/\b(?:xiao)?((?:red)?mi[-_ ]?pad[\w- ]*)(?: bui|\))/i],[[m,/_/g," "],[y,qt],[h,Y]],[/\b(poco[\w ]+|m2\d{3}j\d\d[a-z]{2})(?: bui|\))/i,/\b; (\w+) build\/hm\1/i,/\b(hm[-_ ]?note?[_ ]?(?:\d\w)?) bui/i,/\b(redmi[\-_ ]?(?:note|k)?[\w_ ]+)(?: bui|\))/i,/oid[^\)]+; (m?[12][0-389][01]\w{3,6}[c-y])( bui|; wv|\))/i,/\b(mi[-_ ]?(?:a\d|one|one[_ ]plus|note|max|cc)?[_ ]?(?:\d{0,2}\w?)[_ ]?(?:plus|se|lite|pro)?( 5g|lte)?)(?: bui|\))/i,/ ([\w ]+) miui\/v?\d/i],[[m,/_/g," "],[y,qt],[h,B]],[/droid.+; (cph2[3-6]\d[13579]|((gm|hd)19|(ac|be|in|kb)20|(d[en]|eb|le|mt)21|ne22)[0-2]\d|p[g-k]\w[1m]10)\b/i,/(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i],[m,[y,Bn],[h,B]],[/; (\w+) bui.+ oppo/i,/\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i],[m,[y,zt],[h,B]],[/\b(opd2(\d{3}a?))(?: bui|\))/i],[m,[y,he,{OnePlus:["203","304","403","404","413","415"],"*":zt}],[h,Y]],[/(vivo (5r?|6|8l?|go|one|s|x[il]?[2-4]?)[\w\+ ]*)(?: bui|\))/i],[m,[y,"BLU"],[h,B]],[/; vivo (\w+)(?: bui|\))/i,/\b(v[12]\d{3}\w?[at])(?: bui|;)/i],[m,[y,"Vivo"],[h,B]],[/\b(rmx[1-3]\d{3})(?: bui|;|\))/i],[m,[y,"Realme"],[h,B]],[/(ideatab[-\w ]+|602lv|d-42a|a101lv|a2109a|a3500-hv|s[56]000|pb-6505[my]|tb-?x?\d{3,4}(?:f[cu]|xu|[av])|yt\d?-[jx]?\d+[lfmx])( bui|;|\)|\/)/i,/lenovo ?(b[68]0[08]0-?[hf]?|tab(?:[\w- ]+?)|tb[\w-]{6,7})( bui|;|\)|\/)/i],[m,[y,Kt],[h,Y]],[/lenovo[-_ ]?([-\w ]+?)(?: bui|\)|\/)/i],[m,[y,Kt],[h,B]],[/\b(milestone|droid(?:[2-4x]| (?:bionic|x2|pro|razr))?:?( 4g)?)\b[\w ]+build\//i,/\bmot(?:orola)?[- ]([\w\s]+)(\)| bui)/i,/((?:moto(?! 360)[-\w\(\) ]+|xt\d{3,4}[cgkosw\+]?[-\d]*|nexus 6)(?= bui|\)))/i],[m,[y,jt],[h,B]],[/\b(mz60\d|xoom[2 ]{0,2}) build\//i],[m,[y,jt],[h,Y]],[/((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i],[m,[y,vt],[h,Y]],[/(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,/\blg[-e;\/ ]+(?!.*(?:browser|netcast|android tv|watch|webos))(\w+)/i,/\blg-?([\d\w]+) bui/i],[m,[y,vt],[h,B]],[/(nokia) (t[12][01])/i],[y,m,[h,Y]],[/(?:maemo|nokia).*(n900|lumia \d+|rm-\d+)/i,/nokia[-_ ]?(([-\w\. ]*?))( bui|\)|;|\/)/i],[[m,/_/g," "],[h,B],[y,"Nokia"]],[/(pixel (c|tablet))\b/i],[m,[y,Ne],[h,Y]],[/droid.+;(?: google)? (g(01[13]a|020[aem]|025[jn]|1b60|1f8f|2ybb|4s1m|576d|5nz6|8hhn|8vou|a02099|c15s|d1yq|e2ae|ec77|gh2x|kv4x|p4bc|pj41|r83y|tt9q|ur25|wvk6)|pixel[\d ]*a?( pro)?( xl)?( fold)?( \(5g\))?)( bui|\))/i],[m,[y,Ne],[h,B]],[/(google) (pixelbook( go)?)/i],[y,m],[/droid.+; (a?\d[0-2]{2}so|[c-g]\d{4}|so[-gl]\w+|xq-\w\w\d\d)(?= bui|\).+chrome\/(?![1-6]{0,1}\d\.))/i],[m,[y,qe],[h,B]],[/sony tablet [ps]/i,/\b(?:sony)?sgp\w+(?: bui|\))/i],[[m,"Xperia Tablet"],[y,qe],[h,Y]],[/(alexa)webm/i,/(kf[a-z]{2}wi|aeo(?!bc)\w\w)( bui|\))/i,/(kf[a-z]+)( bui|\)).+silk\//i],[m,[y,yt],[h,Y]],[/((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i],[[m,/(.+)/g,"Fire Phone $1"],[y,yt],[h,B]],[/(playbook);[-\w\),; ]+(rim)/i],[m,y,[h,Y]],[/\b((?:bb[a-f]|st[hv])100-\d)/i,/(?:blackberry|\(bb10;) (\w+)/i],[m,[y,Nn],[h,B]],[/(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i],[m,[y,Ln],[h,Y]],[/ (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i],[m,[y,Ln],[h,B]],[/(nexus 9)/i],[m,[y,"HTC"],[h,Y]],[/(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i,/(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,/(alcatel|geeksphone|nexian|panasonic(?!(?:;|\.))|sony(?!-bra))[-_ ]?([-\w]*)/i],[y,[m,/_/g," "],[h,B]],[/tcl (xess p17aa)/i,/droid [\w\.]+; ((?:8[14]9[16]|9(?:0(?:48|60|8[01])|1(?:3[27]|66)|2(?:6[69]|9[56])|466))[gqswx])(_\w(\w|\w\w))?(\)| bui)/i],[m,[y,"TCL"],[h,Y]],[/droid [\w\.]+; (418(?:7d|8v)|5087z|5102l|61(?:02[dh]|25[adfh]|27[ai]|56[dh]|59k|65[ah])|a509dl|t(?:43(?:0w|1[adepqu])|50(?:6d|7[adju])|6(?:09dl|10k|12b|71[efho]|76[hjk])|7(?:66[ahju]|67[hw]|7[045][bh]|71[hk]|73o|76[ho]|79w|81[hks]?|82h|90[bhsy]|99b)|810[hs]))(_\w(\w|\w\w))?(\)| bui)/i],[m,[y,"TCL"],[h,B]],[/(itel) ((\w+))/i],[[y,Te],m,[h,he,{tablet:["p10001l","w7001"],"*":"mobile"}]],[/droid.+; ([ab][1-7]-?[0178a]\d\d?)/i],[m,[y,"Acer"],[h,Y]],[/droid.+; (m[1-5] note) bui/i,/\bmz-([-\w]{2,})/i],[m,[y,"Meizu"],[h,B]],[/; ((?:power )?armor(?:[\w ]{0,8}))(?: bui|\))/i],[m,[y,"Ulefone"],[h,B]],[/; (energy ?\w+)(?: bui|\))/i,/; energizer ([\w ]+)(?: bui|\))/i],[m,[y,"Energizer"],[h,B]],[/; cat (b35);/i,/; (b15q?|s22 flip|s48c|s62 pro)(?: bui|\))/i],[m,[y,"Cat"],[h,B]],[/((?:new )?andromax[\w- ]+)(?: bui|\))/i],[m,[y,"Smartfren"],[h,B]],[/droid.+; (a(in)?(0(15|59|6[35])|142)p?)/i],[m,[y,"Nothing"],[h,B]],[/; (x67 5g|tikeasy \w+|ac[1789]\d\w+)( b|\))/i,/archos ?(5|gamepad2?|([\w ]*[t1789]|hello) ?\d+[\w ]*)( b|\))/i],[m,[y,"Archos"],[h,Y]],[/archos ([\w ]+)( b|\))/i,/; (ac[3-6]\d\w{2,8})( b|\))/i],[m,[y,"Archos"],[h,B]],[/; (n159v)/i],[m,[y,"HMD"],[h,B]],[/(imo) (tab \w+)/i,/(infinix|tecno) (x1101b?|p904|dp(7c|8d|10a)( pro)?|p70[1-3]a?|p904|t1101)/i],[y,m,[h,Y]],[/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus(?! zenw)|dell|jolla|meizu|motorola|polytron|tecno|micromax|advan)[-_ ]?([-\w]*)/i,/; (blu|hmd|imo|infinix|lava|oneplus|tcl|wiko)[_ ]([\w\+ ]+?)(?: bui|\)|; r)/i,/(hp) ([\w ]+\w)/i,/(microsoft); (lumia[\w ]+)/i,/(oppo) ?([\w ]+) bui/i,/(hisense) ([ehv][\w ]+)\)/i,/droid[^;]+; (philips)[_ ]([sv-x][\d]{3,4}[xz]?)/i],[y,m,[h,B]],[/(kobo)\s(ereader|touch)/i,/(hp).+(touchpad(?!.+tablet)|tablet)/i,/(kindle)\/([\w\.]+)/i],[y,m,[h,Y]],[/(surface duo)/i],[m,[y,Wt],[h,Y]],[/droid [\d\.]+; (fp\du?)(?: b|\))/i],[m,[y,"Fairphone"],[h,B]],[/((?:tegranote|shield t(?!.+d tv))[\w- ]*?)(?: b|\))/i],[m,[y,$t],[h,Y]],[/(sprint) (\w+)/i],[y,m,[h,B]],[/(kin\.[onetw]{3})/i],[[m,/\./g," "],[y,Wt],[h,B]],[/droid.+; ([c6]+|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i],[m,[y,Gt],[h,Y]],[/droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i],[m,[y,Gt],[h,B]],[/(philips)[\w ]+tv/i,/smart-tv.+(samsung)/i],[y,[h,z]],[/hbbtv.+maple;(\d+)/i],[[m,/^/,"SmartTV"],[y,ze],[h,z]],[/(vizio)(?: |.+model\/)(\w+-\w+)/i,/tcast.+(lg)e?. ([-\w]+)/i],[y,m,[h,z]],[/(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i],[[y,vt],[h,z]],[/(apple) ?tv/i],[y,[m,Pe+" TV"],[h,z]],[/crkey.*devicetype\/chromecast/i],[[m,Ce+" Third Generation"],[y,Ne],[h,z]],[/crkey.*devicetype\/([^/]*)/i],[[m,/^/,"Chromecast "],[y,Ne],[h,z]],[/fuchsia.*crkey/i],[[m,Ce+" Nest Hub"],[y,Ne],[h,z]],[/crkey/i],[[m,Ce],[y,Ne],[h,z]],[/(portaltv)/i],[m,[y,Jt],[h,z]],[/droid.+aft(\w+)( bui|\))/i],[m,[y,yt],[h,z]],[/(shield \w+ tv)/i],[m,[y,$t],[h,z]],[/\(dtv[\);].+(aquos)/i,/(aquos-tv[\w ]+)\)/i],[m,[y,_n],[h,z]],[/(bravia[\w ]+)( bui|\))/i],[m,[y,qe],[h,z]],[/(mi(tv|box)-?\w+) bui/i],[m,[y,qt],[h,z]],[/Hbbtv.*(technisat) (.*);/i],[y,m,[h,z]],[/\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i,/hbbtv\/\d+\.\d+\.\d+ +\([\w\+ ]*; *([\w\d][^;]*);([^;]*)/i],[[y,/.+\/(\w+)/,"$1",he,{LG:"lge"}],[m,Ot],[h,z]],[/(playstation \w+)/i],[m,[y,qe],[h,je]],[/\b(xbox(?: one)?(?!; xbox))[\); ]/i],[m,[y,Wt],[h,je]],[/(ouya)/i,/(nintendo) (\w+)/i,/(retroid) (pocket ([^\)]+))/i],[y,m,[h,je]],[/droid.+; (shield)( bui|\))/i],[m,[y,$t],[h,je]],[/\b(sm-[lr]\d\d[0156][fnuw]?s?|gear live)\b/i],[m,[y,ze],[h,fe]],[/((pebble))app/i,/(asus|google|lg|oppo) ((pixel |zen)?watch[\w ]*)( bui|\))/i],[y,m,[h,fe]],[/(ow(?:19|20)?we?[1-3]{1,3})/i],[m,[y,zt],[h,fe]],[/(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i],[m,[y,Pe],[h,fe]],[/(opwwe\d{3})/i],[m,[y,Bn],[h,fe]],[/(moto 360)/i],[m,[y,jt],[h,fe]],[/(smartwatch 3)/i],[m,[y,qe],[h,fe]],[/(g watch r)/i],[m,[y,vt],[h,fe]],[/droid.+; (wt63?0{2,3})\)/i],[m,[y,Gt],[h,fe]],[/droid.+; (glass) \d/i],[m,[y,Ne],[h,bt]],[/(pico) ([\w ]+) os\d/i],[y,m,[h,bt]],[/(quest( \d| pro)?s?).+vr/i],[m,[y,Jt],[h,bt]],[/mobile vr; rv.+firefox/i],[[h,bt]],[/(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i],[y,[h,$e]],[/(aeobc)\b/i],[m,[y,yt],[h,$e]],[/(homepod).+mac os/i],[m,[y,Pe],[h,$e]],[/windows iot/i],[[h,$e]],[/droid.+; ([\w- ]+) (4k|android|smart|google)[- ]?tv/i],[m,[h,z]],[/\b((4k|android|smart|opera)[- ]?tv|tv; rv:|large screen[\w ]+safari)\b/i],[[h,z]],[/droid .+?; ([^;]+?)(?: bui|; wv\)|\) applew|; hmsc).+?(mobile|vr|\d) safari/i],[m,[h,he,{mobile:"Mobile",xr:"VR","*":Y}]],[/\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i],[[h,Y]],[/(phone|mobile(?:[;\/]| [ \w\/\.]*safari)|pda(?=.+windows ce))/i],[[h,B]],[/droid .+?; ([\w\. -]+)( bui|\))/i],[m,[y,"Generic"]]],engine:[[/windows.+ edge\/([\w\.]+)/i],[v,[w,Et+"HTML"]],[/(arkweb)\/([\w\.]+)/i],[w,v],[/webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i],[v,[w,"Blink"]],[/(presto)\/([\w\.]+)/i,/(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna|servo)\/([\w\.]+)/i,/ekioh(flow)\/([\w\.]+)/i,/(khtml|tasman|links)[\/ ]\(?([\w\.]+)/i,/(icab)[\/ ]([23]\.[\d\.]+)/i,/\b(libweb)/i],[w,v],[/ladybird\//i],[[w,"LibWeb"]],[/rv\:([\w\.]{1,9})\b.+(gecko)/i],[v,w]],os:[[/(windows nt) (6\.[23]); arm/i],[[w,/N/,"R"],[v,he,Pn]],[/(windows (?:phone|mobile|iot))(?: os)?[\/ ]?([\d\.]*( se)?)/i,/(windows)[\/ ](1[01]|2000|3\.1|7|8(\.1)?|9[58]|me|server 20\d\d( r2)?|vista|xp)/i],[w,v],[/windows nt ?([\d\.\)]*)(?!.+xbox)/i,/\bwin(?=3| ?9|n)(?:nt| 9x )?([\d\.;]*)/i],[[v,/(;|\))/g,"",he,Pn],[w,Qt]],[/(windows ce)\/?([\d\.]*)/i],[w,v],[/[adehimnop]{4,7}\b(?:.*os ([\w]+) like mac|; opera)/i,/(?:ios;fbsv|ios(?=.+ip(?:ad|hone))|ip(?:ad|hone)(?: |.+i(?:pad)?)os)[\/ ]([\w\.]+)/i,/cfnetwork\/.+darwin/i],[[v,/_/g,"."],[w,"iOS"]],[/(mac os x) ?([\w\. ]*)/i,/(macintosh|mac_powerpc\b)(?!.+(haiku|morphos))/i],[[w,"macOS"],[v,/_/g,"."]],[/android ([\d\.]+).*crkey/i],[v,[w,Ce+" Android"]],[/fuchsia.*crkey\/([\d\.]+)/i],[v,[w,Ce+" Fuchsia"]],[/crkey\/([\d\.]+).*devicetype\/smartspeaker/i],[v,[w,Ce+" SmartSpeaker"]],[/linux.*crkey\/([\d\.]+)/i],[v,[w,Ce+" Linux"]],[/crkey\/([\d\.]+)/i],[v,[w,Ce]],[/droid ([\w\.]+)\b.+(android[- ]x86)/i],[v,w],[/(ubuntu) ([\w\.]+) like android/i],[[w,/(.+)/,"$1 Touch"],v],[/(harmonyos)[\/ ]?([\d\.]*)/i,/(android|bada|blackberry|kaios|maemo|meego|openharmony|qnx|rim tablet os|sailfish|series40|symbian|tizen)\w*[-\/\.; ]?([\d\.]*)/i],[w,v],[/\(bb(10);/i],[v,[w,Nn]],[/(?:symbian ?os|symbos|s60(?=;)|series ?60)[-\/ ]?([\w\.]*)/i],[v,[w,"Symbian"]],[/mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i],[v,[w,Ge+" OS"]],[/\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i,/webos(?:[ \/]?|\.tv-20(?=2[2-9]))(\d[\d\.]*)/i],[v,[w,"webOS"]],[/web0s;.+?(?:chr[o0]me|safari)\/(\d+)/i],[[v,he,{25:"120",24:"108",23:"94",22:"87",6:"79",5:"68",4:"53",3:"38",2:"538",1:"537","*":"TV"}],[w,"webOS"]],[/watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i],[v,[w,"watchOS"]],[/(cros) [\w]+(?:\)| ([\w\.]+)\b)/i],[[w,"Chrome OS"],v],[/panasonic;(viera)/i,/(netrange)mmh/i,/(nettv)\/(\d+\.[\w\.]+)/i,/(nintendo|playstation) (\w+)/i,/(xbox); +xbox ([^\);]+)/i,/(pico) .+os([\w\.]+)/i,/\b(joli|palm)\b ?(?:os)?\/?([\w\.]*)/i,/linux.+(mint)[\/\(\) ]?([\w\.]*)/i,/(mageia|vectorlinux|fuchsia|arcaos|arch(?= ?linux))[;l ]([\d\.]*)/i,/([kxln]?ubuntu|debian|suse|opensuse|gentoo|slackware|fedora|mandriva|centos|pclinuxos|red ?hat|zenwalk|linpus|raspbian|plan 9|minix|risc os|contiki|deepin|manjaro|elementary os|sabayon|linspire|knoppix)(?: gnu[\/ ]linux)?(?: enterprise)?(?:[- ]linux)?(?:-gnu)?[-\/ ]?(?!chrom|package)([-\w\.]*)/i,/((?:open)?solaris)[-\/ ]?([\w\.]*)/i,/\b(aix)[; ]([1-9\.]{0,4})/i,/(hurd|linux|morphos)(?: (?:arm|x86|ppc)\w*| ?)([\w\.]*)/i,/(gnu) ?([\w\.]*)/i,/\b([-frentopcghs]{0,5}bsd|dragonfly)[\/ ]?(?!amd|[ix346]{1,2}86)([\w\.]*)/i,/(haiku) ?(r\d)?/i],[w,v],[/(sunos) ?([\d\.]*)/i],[[w,"Solaris"],v],[/\b(beos|os\/2|amigaos|openvms|hp-ux|serenityos)/i,/(unix) ?([\w\.]*)/i],[w,v]]},Ct=(function(){var e={init:{},isIgnore:{},isIgnoreRgx:{},toString:{}};return we.call(e.init,[[ne,[w,v,We,h]],[be,[te]],[ue,[h,m,y]],[ce,[w,v]],[oe,[w,v]]]),we.call(e.isIgnore,[[ne,[v,We]],[ce,[v]],[oe,[v]]]),we.call(e.isIgnoreRgx,[[ne,/ ?browser$/i],[oe,/ ?os$/i]]),we.call(e.toString,[[ne,[w,v]],[be,[te]],[ue,[y,m]],[ce,[w,v]],[oe,[w,v]]]),e})(),Bo=function(e,t){var n=Ct.init[t],i=Ct.isIgnore[t]||0,o=Ct.isIgnoreRgx[t]||0,r=Ct.toString[t]||0;function s(){we.call(this,n)}return s.prototype.getItem=function(){return e},s.prototype.withClientHints=function(){return xe?xe.getHighEntropyValues(kn).then(function(a){return e.setCH(new Fn(a,!1)).parseCH().get()}):e.parseCH().get()},s.prototype.withFeatureCheck=function(){return e.detectFeature().get()},t!=Ue&&(s.prototype.is=function(a){var l=!1;for(var c in this)if(this.hasOwnProperty(c)&&!Zt(i,c)&&Te(o?Xe(o,this[c]):this[c])==Te(o?Xe(o,a):a)){if(l=!0,a!=$.UNDEFINED)break}else if(a==$.UNDEFINED&&l){l=!l;break}return l},s.prototype.toString=function(){var a=_e;for(var l in r)typeof this[r[l]]!==$.UNDEFINED&&(a+=(a?" ":_e)+this[r[l]]);return a||$.UNDEFINED}),xe||(s.prototype.then=function(a){var l=this,c=function(){for(var f in l)l.hasOwnProperty(f)&&(this[f]=l[f])};c.prototype={is:s.prototype.is,toString:s.prototype.toString};var u=new c;return a(u),u}),new s};function Fn(e,t){if(e=e||{},we.call(this,kn),t)we.call(this,[[Xt,en(e[Oe])],[Ft,en(e[Oo])],[B,/\?1/.test(e[Ro])],[m,et(e[ko])],[He,et(e[Rn])],[Yt,et(e[Lo])],[te,et(e[Co])],[Le,en(e[To])],[wt,et(e[xo])]]);else for(var n in e)this.hasOwnProperty(n)&&typeof e[n]!==$.UNDEFINED&&(this[n]=e[n])}function Yn(e,t,n,i){return this.get=function(o){return o?this.data.hasOwnProperty(o)?this.data[o]:void 0:this.data},this.set=function(o,r){return this.data[o]=r,this},this.setCH=function(o){return this.uaCH=o,this},this.detectFeature=function(){if(ie&&ie.userAgent==this.ua)switch(this.itemType){case ne:ie.brave&&typeof ie.brave.isBrave==$.FUNCTION&&this.set(w,"Brave");break;case ue:!this.get(h)&&xe&&xe[B]&&this.set(h,B),this.get(m)=="Macintosh"&&ie&&typeof ie.standalone!==$.UNDEFINED&&ie.maxTouchPoints&&ie.maxTouchPoints>2&&this.set(m,"iPad").set(h,Y);break;case oe:!this.get(w)&&xe&&xe[He]&&this.set(w,xe[He]);break;case Ue:var o=this.data,r=function(s){return o[s].getItem().detectFeature().get()};this.set(ne,r(ne)).set(be,r(be)).set(ue,r(ue)).set(ce,r(ce)).set(oe,r(oe))}return this},this.parseUA=function(){switch(this.itemType!=Ue&&nn.call(this.data,this.ua,this.rgxMap),this.itemType){case ne:this.set(We,tn(this.get(v)));break;case oe:if(this.get(w)=="iOS"&&this.get(v)=="18.6"){var o=/\) Version\/([\d\.]+)/.exec(this.ua);o&&parseInt(o[1].substring(0,2),10)>=26&&this.set(v,o[1])}break}return this},this.parseCH=function(){var o=this.uaCH,r=this.rgxMap;switch(this.itemType){case ne:case ce:var s=o[Ft]||o[Xt],a;if(s)for(var l=0;l<s.length;l++){var c=s[l].brand||s[l],u=s[l].version;this.itemType==ne&&!/not.a.brand/i.test(c)&&(!a||/Chrom/.test(a)&&c!=Dn||a==Et&&/WebView2/.test(c))&&(c=he(c,Mo),a=this.get(w),a&&!/Chrom/.test(a)&&/Chrom/.test(c)||this.set(w,c).set(v,u).set(We,tn(u)),a=c),this.itemType==ce&&c==Dn&&this.set(v,u)}break;case be:var f=o[te];f&&(f&&o[wt]=="64"&&(f+="64"),nn.call(this.data,f+";",r));break;case ue:if(o[B]&&this.set(h,B),o[m]&&(this.set(m,o[m]),!this.get(h)||!this.get(y))){var S={};nn.call(S,"droid 9; "+o[m]+")",r),!this.get(h)&&S.type&&this.set(h,S.type),!this.get(y)&&S.vendor&&this.set(y,S.vendor)}if(o[Le]){var g;if(typeof o[Le]!="string")for(var p=0;!g&&p<o[Le].length;)g=he(o[Le][p++],Vn);else g=he(o[Le],Vn);this.set(h,g)}break;case oe:var E=o[He];if(E){var T=o[Yt];E==Qt&&(T=parseInt(tn(T),10)>=13?"11":"10"),this.set(w,E).set(v,T)}this.get(w)==Qt&&o[m]=="Xbox"&&this.set(w,"Xbox").set(v,void 0);break;case Ue:var b=this.data,d=function(R){return b[R].getItem().setCH(o).parseCH().get()};this.set(ne,d(ne)).set(be,d(be)).set(ue,d(ue)).set(ce,d(ce)).set(oe,d(oe))}return this},we.call(this,[["itemType",e],["ua",t],["uaCH",i],["rgxMap",n],["data",Bo(this,e)]]),this}function ye(e,t,n){if(typeof e===$.OBJECT?(St(e,!0)?(typeof t===$.OBJECT&&(n=t),t=e):(n=e,t=void 0),e=void 0):typeof e===$.STRING&&!St(t,!0)&&(n=t,t=void 0),n)if(typeof n.append===$.FUNCTION){var i={};n.forEach(function(u,f){i[String(f).toLowerCase()]=u}),n=i}else{var o={};for(var r in n)n.hasOwnProperty(r)&&(o[String(r).toLowerCase()]=n[r]);n=o}if(!(this instanceof ye))return new ye(e,t,n).getResult();var s=typeof e===$.STRING?e:n&&n[xn]?n[xn]:ie&&ie.userAgent?ie.userAgent:_e,a=new Fn(n,!0),l=t?Io(Xn,t):Xn,c=function(u){return u==Ue?function(){return new Yn(u,s,l,a).set("ua",s).set(ne,this.getBrowser()).set(be,this.getCPU()).set(ue,this.getDevice()).set(ce,this.getEngine()).set(oe,this.getOS()).get()}:function(){return new Yn(u,s,l[u],a).parseUA().get()}};return we.call(this,[["getBrowser",c(ne)],["getCPU",c(be)],["getDevice",c(ue)],["getEngine",c(ce)],["getOS",c(oe)],["getResult",c(Ue)],["getUA",function(){return s}],["setUA",function(u){return Ze(u)&&(s=Ot(u,So)),this}]]).setUA(s),this}ye.VERSION=Ao,ye.BROWSER=At([w,v,We,h]),ye.CPU=At([te]),ye.DEVICE=At([m,y,h,je,B,z,Y,fe,$e]),ye.ENGINE=ye.OS=At([w,v]);const _o=Object.freeze({AIX:"AIX",AMIGA_OS:"Amiga OS",ANDROID:"Android",ANDROID_X86:"Android-x86",ARCAOS:"ArcaOS",ARCH:"Arch",BADA:"Bada",BEOS:"BeOS",BLACKBERRY:"BlackBerry",CENTOS:"CentOS",CHROME_OS:"Chrome OS",CHROMECAST:"Chromecast",CHROMECAST_ANDROID:"Chromecast Android",CHROMECAST_FUCHSIA:"Chromecast Fuchsia",CHROMECAST_LINUX:"Chromecast Linux",CHROMECAST_SMARTSPEAKER:"Chromecast SmartSpeaker",CONTIKI:"Contiki",DEBIAN:"Debian",DEEPIN:"Deepin",DRAGONFLY:"DragonFly",ELEMENTARY_OS:"elementary OS",FEDORA:"Fedora",FIREFOX_OS:"Firefox OS",FREEBSD:"FreeBSD",FUCHSIA:"Fuchsia",GENTOO:"Gentoo",GHOSTBSD:"GhostBSD",GNU:"GNU",HAIKU:"Haiku",HARMONYOS:"HarmonyOS",HP_UX:"HP-UX",HURD:"Hurd",IOS:"iOS",JOLI:"Joli",KAIOS:"KaiOS",KNOPPIX:"Knoppix",KUBUNTU:"Kubuntu",LINPUS:"Linpus",LINSPIRE:"Linspire",LINUX:"Linux",MACOS:"macOS",MAEMO:"Maemo",MAGEIA:"Mageia",MANDRIVA:"Mandriva",MANJARO:"Manjaro",MEEGO:"MeeGo",MINIX:"Minix",MINT:"Mint",MORPH_OS:"Morph OS",NETBSD:"NetBSD",NETRANGE:"NetRange",NETTV:"NetTV",NINTENDO:"Nintendo",OPENHARMONY:"OpenHarmony",OPENBSD:"OpenBSD",OPENVMS:"OpenVMS",OS2:"OS/2",PALM:"Palm",PC_BSD:"PC-BSD",PCLINUXOS:"PCLinuxOS",PICO:"Pico",PLAN9:"Plan9",PLAYSTATION:"PlayStation",QNX:"QNX",RASPBIAN:"Raspbian",REDHAT:"RedHat",RIM_TABLET_OS:"RIM Tablet OS",RISC_OS:"RISC OS",SABAYON:"Sabayon",SAILFISH:"Sailfish",SERENITYOS:"SerenityOS",SERIES40:"Series40",SLACKWARE:"Slackware",SOLARIS:"Solaris",SUSE:"SUSE",SYMBIAN:"Symbian",TIZEN:"Tizen",UBUNTU:"Ubuntu",UBUNTU_TOUCH:"Ubuntu Touch",UNIX:"Unix",VECTORLINUX:"VectorLinux",WATCHOS:"watchOS",WEBOS:"WebOS",WINDOWS:"Windows",WINDOWS_CE:"Windows CE",WINDOWS_IOT:"Windows IoT",WINDOWS_MOBILE:"Windows Mobile",WINDOWS_PHONE:"Windows Phone",WINDOWS_RT:"Windows RT",XBOX:"Xbox",XUBUNTU:"Xubuntu",ZENWALK:"Zenwalk"}),on=ye().os.is(_o.MACOS),rn="not-annotatable",Ie=`.${rn}`,tt=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(Ie):t.parentElement?.closest(Ie)):!0,Kn=(e,t)=>{const n=t.commonAncestorContainer;return!tt(e,n)},sn=/^\s*$/,Wn=e=>sn.test(e.toString()),Uo=e=>sn.test(e.textContent||""),jn=e=>{if(e.length===0)return[];if(e.length===1)return[e[0]];e.sort((o,r)=>{const s=o.compareBoundaryPoints(Range.START_TO_START,r);return s!==0?s:o.compareBoundaryPoints(Range.END_TO_END,r)});const[t,...n]=e,i=n.reduce((o,r)=>o.current.compareBoundaryPoints(Range.START_TO_END,r)>=0?(o.current.compareBoundaryPoints(Range.END_TO_END,r)<0&&o.current.setEnd(r.endContainer,r.endOffset),o):(o.merged.push(o.current),o.current=r.cloneRange(),o),{merged:[],current:t.cloneRange()});return[...i.merged,i.current]},$n=e=>{!e.hasAttribute("tabindex")&&e.tabIndex<0&&e.setAttribute("tabindex","-1"),e.classList.add("no-focus-outline")},Do=function*(e){const t=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,i=>i instanceof HTMLElement&&i.classList.contains(rn)&&!i.parentElement.closest(Ie)&&e.intersectsNode(i)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},zn=(e,t)=>{if(!Kn(e,t))return[];const n=[];let i=null;for(const o of Do(t)){let r;i?(r=document.createRange(),r.setStartAfter(i),r.setEndBefore(o)):(r=t.cloneRange(),r.setEndBefore(o)),r.collapsed||n.push(r),i=o}if(i){const o=t.cloneRange();o.setStartAfter(i),o.collapsed||n.push(o)}return n.length>0?n:[t]},xt=e=>{const t=e.cloneContents();return t.querySelectorAll(Ie).forEach(n=>n.remove()),t},qn=(e,t)=>{const n=e.cloneRange();return t.contains(n.startContainer)||n.setStart(t,0),t.contains(n.endContainer)||n.setEnd(t,t.childNodes.length),n},Gn=e=>e.addEventListener("click",t=>{!t.target.closest(Ie)&&!t.target.closest("a")&&t.preventDefault()}),Tt=e=>({...e,type:e.type,x:e.x,y:e.y,clientX:e.clientX,clientY:e.clientY,offsetX:e.offsetX,offsetY:e.offsetY,screenX:e.screenX,screenY:e.screenY,isPrimary:e.isPrimary,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,button:e.button,buttons:e.buttons,currentTarget:e.currentTarget,target:e.target,defaultPrevented:e.defaultPrevented,detail:e.detail,eventPhase:e.eventPhase,pointerId:e.pointerId,pointerType:e.pointerType,timeStamp:e.timeStamp}),nt=e=>({...e,type:e.type,key:e.key,code:e.code,location:e.location,repeat:e.repeat,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,currentTarget:e.currentTarget,target:e.target,defaultPrevented:e.defaultPrevented,detail:e.detail,timeStamp:e.timeStamp}),Rt=(e,t=10)=>{let n;return((...i)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,i),t)})},an=(e,t,n,i)=>{const{store:o,selection:r,hover:s}=n,a=Be();let l;const c=new Map;let u;const f=di(i),S=_=>{const{x:D,y:A}=t.getBoundingClientRect(),O=o.getAt(_.clientX-D,_.clientY-A,!1,u);O&&n.selection.evalSelectAction(O)!==Dt.NONE?s.current!==O.id&&(t.classList.add("hovered"),s.set(O.id)):s.current&&(t.classList.remove("hovered"),s.set(null))};t.addEventListener("pointermove",S);const g=Rt((_=!1)=>requestAnimationFrame(()=>{const D=ci(t),{minX:A,minY:O,maxX:C,maxY:N}=D,F=u?o.getIntersecting(A,O,C,N).filter(({annotation:M})=>u(M)):o.getIntersecting(A,O,C,N),X=r.selected.map(({id:M})=>M),k=F.map(({annotation:M,rects:ee})=>{const Me=X.includes(M.id),ge=M.id===s.current;return{annotation:M,rects:ee,state:{selected:Me,hovered:ge}}});e.redraw(k,D,l,c,_),setTimeout(()=>{f(F.map(({annotation:M})=>M)),a.emit("onRedraw")},1)}),10),p=(_,D)=>{D?_?c.set(D,_):c.delete(D):l=_,g(!0)},E=_=>{u=_,g(!1)},T=(_,D)=>a.on(_,D),b=()=>{g()};o.observe(b);const d=r.subscribe(()=>{g()}),R=s.subscribe(()=>{g()}),U=()=>{g(!0)};document.addEventListener("scroll",U,{capture:!0,passive:!0});const x=Rt(()=>{o.recalculatePositions(),g()},10);window.addEventListener("resize",x);const L=new ResizeObserver(x);L.observe(t);const H={attributes:!0,childList:!0,subtree:!0},P=new MutationObserver(Rt(_=>{_.every(A=>A.target===t||t.contains(A.target))||g(!0)},150));return P.observe(document.body,H),{destroy:()=>{t.removeEventListener("pointermove",S),e.destroy(),o.unobserve(b),d(),R(),document.removeEventListener("scroll",U),window.removeEventListener("resize",x),L.disconnect(),P.disconnect()},on:T,redraw:g,setStyle:p,setFilter:E,setVisible:e.setVisible.bind(e)}};var Ho={grad:.9,turn:360,rad:360/(2*Math.PI)},ve=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},q=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=Math.pow(10,t)),Math.round(n*e)/n+0},re=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},Jn=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},Qn=function(e){return{r:re(e.r,0,255),g:re(e.g,0,255),b:re(e.b,0,255),a:re(e.a)}},ln=function(e){return{r:q(e.r),g:q(e.g),b:q(e.b),a:q(e.a,3)}},Po=/^#([0-9a-f]{3,8})$/i,kt=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},Zn=function(e){var t=e.r,n=e.g,i=e.b,o=e.a,r=Math.max(t,n,i),s=r-Math.min(t,n,i),a=s?r===t?(n-i)/s:r===n?2+(i-t)/s:4+(t-n)/s:0;return{h:60*(a<0?a+6:a),s:r?s/r*100:0,v:r/255*100,a:o}},ei=function(e){var t=e.h,n=e.s,i=e.v,o=e.a;t=t/360*6,n/=100,i/=100;var r=Math.floor(t),s=i*(1-n),a=i*(1-(t-r)*n),l=i*(1-(1-t+r)*n),c=r%6;return{r:255*[i,a,s,s,l,i][c],g:255*[l,i,i,a,s,s][c],b:255*[s,s,l,i,i,a][c],a:o}},ti=function(e){return{h:Jn(e.h),s:re(e.s,0,100),l:re(e.l,0,100),a:re(e.a)}},ni=function(e){return{h:q(e.h),s:q(e.s),l:q(e.l),a:q(e.a,3)}},ii=function(e){return ei((n=(t=e).s,{h:t.h,s:(n*=((i=t.l)<50?i:100-i)/100)>0?2*n/(i+n)*100:0,v:i+n,a:t.a}));var t,n,i},it=function(e){return{h:(t=Zn(e)).h,s:(o=(200-(n=t.s))*(i=t.v)/100)>0&&o<200?n*i/100/(o<=100?o:200-o)*100:0,l:o/2,a:t.a};var t,n,i,o},Vo=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Xo=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Fo=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Yo=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,oi={string:[[function(e){var t=Po.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?q(parseInt(e[3]+e[3],16)/255,2):1}:e.length===6||e.length===8?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:e.length===8?q(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=Fo.exec(e)||Yo.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Qn({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=Vo.exec(e)||Xo.exec(e);if(!t)return null;var n,i,o=ti({h:(n=t[1],i=t[2],i===void 0&&(i="deg"),Number(n)*(Ho[i]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return ii(o)},"hsl"]],object:[[function(e){var t=e.r,n=e.g,i=e.b,o=e.a,r=o===void 0?1:o;return ve(t)&&ve(n)&&ve(i)?Qn({r:Number(t),g:Number(n),b:Number(i),a:Number(r)}):null},"rgb"],[function(e){var t=e.h,n=e.s,i=e.l,o=e.a,r=o===void 0?1:o;if(!ve(t)||!ve(n)||!ve(i))return null;var s=ti({h:Number(t),s:Number(n),l:Number(i),a:Number(r)});return ii(s)},"hsl"],[function(e){var t=e.h,n=e.s,i=e.v,o=e.a,r=o===void 0?1:o;if(!ve(t)||!ve(n)||!ve(i))return null;var s=(function(a){return{h:Jn(a.h),s:re(a.s,0,100),v:re(a.v,0,100),a:re(a.a)}})({h:Number(t),s:Number(n),v:Number(i),a:Number(r)});return ei(s)},"hsv"]]},ri=function(e,t){for(var n=0;n<t.length;n++){var i=t[n][0](e);if(i)return[i,t[n][1]]}return[null,void 0]},Ko=function(e){return typeof e=="string"?ri(e.trim(),oi.string):typeof e=="object"&&e!==null?ri(e,oi.object):[null,void 0]},cn=function(e,t){var n=it(e);return{h:n.h,s:re(n.s+100*t,0,100),l:n.l,a:n.a}},dn=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},si=function(e,t){var n=it(e);return{h:n.h,s:n.s,l:re(n.l+100*t,0,100),a:n.a}},ai=(function(){function e(t){this.parsed=Ko(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return q(dn(this.rgba),2)},e.prototype.isDark=function(){return dn(this.rgba)<.5},e.prototype.isLight=function(){return dn(this.rgba)>=.5},e.prototype.toHex=function(){return t=ln(this.rgba),n=t.r,i=t.g,o=t.b,s=(r=t.a)<1?kt(q(255*r)):"","#"+kt(n)+kt(i)+kt(o)+s;var t,n,i,o,r,s},e.prototype.toRgb=function(){return ln(this.rgba)},e.prototype.toRgbString=function(){return t=ln(this.rgba),n=t.r,i=t.g,o=t.b,(r=t.a)<1?"rgba("+n+", "+i+", "+o+", "+r+")":"rgb("+n+", "+i+", "+o+")";var t,n,i,o,r},e.prototype.toHsl=function(){return ni(it(this.rgba))},e.prototype.toHslString=function(){return t=ni(it(this.rgba)),n=t.h,i=t.s,o=t.l,(r=t.a)<1?"hsla("+n+", "+i+"%, "+o+"%, "+r+")":"hsl("+n+", "+i+"%, "+o+"%)";var t,n,i,o,r},e.prototype.toHsv=function(){return t=Zn(this.rgba),{h:q(t.h),s:q(t.s),v:q(t.v),a:q(t.a,3)};var t},e.prototype.invert=function(){return se({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},e.prototype.saturate=function(t){return t===void 0&&(t=.1),se(cn(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),se(cn(this.rgba,-t))},e.prototype.grayscale=function(){return se(cn(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),se(si(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),se(si(this.rgba,-t))},e.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},e.prototype.alpha=function(t){return typeof t=="number"?se({r:(n=this.rgba).r,g:n.g,b:n.b,a:t}):q(this.rgba.a,3);var n},e.prototype.hue=function(t){var n=it(this.rgba);return typeof t=="number"?se({h:t,s:n.s,l:n.l,a:n.a}):q(n.h)},e.prototype.isEqual=function(t){return this.toHex()===se(t).toHex()},e})(),se=function(e){return e instanceof ai?e:new ai(e)};const Ee={fill:"rgb(0, 128, 255)",fillOpacity:.18},Lt={fill:"rgb(0, 128, 255)",fillOpacity:.45},li=e=>e?.fillOpacity!==void 0?se(e?.fill||Ee.fill).alpha(e.fillOpacity).toHex():e?.fill?e.fill:se(Ee.fill).alpha(Ee.fillOpacity).toHex(),un=(e,t,n)=>t?typeof t=="function"?t(e.annotation,e.state,n)||(e.state?.selected?Lt:Ee):t:e.state?.selected?Lt:Ee,ci=e=>{const{top:t,left:n}=e.getBoundingClientRect(),{innerWidth:i,innerHeight:o}=window,r=-n,s=-t,a=i-n,l=o-t;return{top:t,left:n,minX:r,minY:s,maxX:a,maxY:l}},di=e=>{let t=new Set;return i=>{const o=i.map(r=>r.id);(t.size!==o.length||o.some(r=>!t.has(r)))&&e.set(o),t=new Set(o)}},Q=[];for(let e=0;e<256;++e)Q.push((e+256).toString(16).slice(1));function Wo(e,t=0){return(Q[e[t+0]]+Q[e[t+1]]+Q[e[t+2]]+Q[e[t+3]]+"-"+Q[e[t+4]]+Q[e[t+5]]+"-"+Q[e[t+6]]+Q[e[t+7]]+"-"+Q[e[t+8]]+Q[e[t+9]]+"-"+Q[e[t+10]]+Q[e[t+11]]+Q[e[t+12]]+Q[e[t+13]]+Q[e[t+14]]+Q[e[t+15]]).toLowerCase()}let fn;const jo=new Uint8Array(16);function $o(){if(!fn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");fn=crypto.getRandomValues.bind(crypto)}return fn(jo)}const ui={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function zo(e,t,n){e=e||{};const i=e.random??e.rng?.()??$o();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Wo(i)}function fi(e,t,n){return ui.randomUUID&&!e?ui.randomUUID():zo(e)}const hi=(e,t,n=10,i)=>{const o=i?e.startContainer.parentElement.closest(i):t,r=document.createRange();r.setStart(o,0),r.setEnd(e.startContainer,e.startOffset);const s=xt(r).textContent,a=document.createRange();a.setStart(e.endContainer,e.endOffset),o===document.body?a.setEnd(o,o.childNodes.length):a.setEndAfter(o);const l=xt(a).textContent;return{prefix:s.substring(s.length-n),suffix:l.substring(0,n)}},pi=(e,t,n)=>{const i=document.createRange(),o=n?e.startContainer.parentElement.closest(n):t;i.setStart(o,0),i.setEnd(e.startContainer,e.startOffset);const r=xt(i).textContent,s=e.toString(),a=r.length||0,l=a+s.length;return n?{quote:s,start:a,end:l,range:e,offsetReference:o}:{quote:s,start:a,end:l,range:e}},pe=e=>e.every(t=>t.range instanceof Range&&!t.range.collapsed),hn=(e,t)=>{const{start:n,end:i}=e,o=e.offsetReference||t,r=document.createNodeIterator(t,NodeFilter.SHOW_TEXT,u=>u.parentElement?.closest(Ie)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT);let s=0;const a=document.createRange();let l=r.nextNode();l===null&&console.error("Could not revive annotation target. Content missing.");let c=!o;for(;l!==null;){if(c||=typeof o?.contains=="function"?o.contains(l):!1,c){const u=l.textContent?.length||0;if(s+u>n){a.setStart(l,n-s);break}s+=u}l=r.nextNode()}for(;l!==null;){const u=l.textContent?.length||0;if(s+u>=i){a.setEnd(l,i-s);break}s+=u,l=r.nextNode()}return{...e,range:a}},ot=(e,t)=>pe(e.selector)?e:{...e,selector:e.selector.map(n=>n.range instanceof Range&&!n.range.collapsed?n:hn(n,t))},Nt=(e,t)=>pe(e.target.selector)?e:{...e,target:ot(e.target,t)},gi=e=>{if(!e)return document.scrollingElement;const{overflowY:t}=window.getComputedStyle(e);return t!=="visible"&&t!=="hidden"&&e.scrollHeight>e.clientHeight?e:gi(e.parentElement)},mi=(e,t,n)=>{const i=n.getBoundingClientRect(),o=n.clientHeight,r=n.clientWidth,s=t.selector[0].range.getBoundingClientRect(),{width:a,height:l}=e.getAnnotationBounds(t.annotation),c=s.top-i.top,u=s.left-i.left,f=n.parentElement?n.scrollTop:0,S=n.parentElement?n.scrollLeft:0,g=c+f-(o-l)/2,p=u+S-(r-a)/2;n.scroll({top:g,left:p,behavior:"smooth"})},bi=(e,t)=>(n,i)=>{const o=typeof n=="string"?n:n.id,r=i?typeof i=="string"?document.getElementById(i):i:gi(e);if(!r)return console.warn(`The scroll parent is missing for the annotation: ${o}`,{container:e}),!1;const s=t.getAnnotation(o);if(!s)return console.warn(`The annotation is missing in the store: ${o}`),!1;const{range:a}=s.target.selector[0];if(a&&!a.collapsed)return mi(t,s.target,r),!0;const l=ot(s.target,e),{range:c}=l.selector[0];return c&&!c.collapsed?(mi(t,l,r),!0):!1},qo=(e,t)=>({parse:n=>wi(n),serialize:n=>yi(n,e,t)}),Go=e=>e.quote!==void 0&&e.start!==void 0&&e.end!==void 0,Jo=e=>{const{id:t,creator:n,created:i,modified:o,target:r}=e,s=Array.isArray(r)?r:[r];if(s.length===0)return{error:Error(`No targets found for annotation: ${e.id}`)};const a={creator:Cn(n),created:i?new Date(i):void 0,updated:o?new Date(o):void 0,annotation:t,selector:[],styleClass:"styleClass"in s[0]?s[0].styleClass:void 0};for(const l of s){const u=(Array.isArray(l.selector)?l.selector:[l.selector]).reduce((f,S)=>{switch(S.type){case"TextQuoteSelector":f.quote=S.exact;break;case"TextPositionSelector":f.start=S.start,f.end=S.end;break}return f},{});if(Go(u))a.selector.push({...u,id:l.id,scope:l.scope});else{const f=[u.start?void 0:"TextPositionSelector",u.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${f.join(" and ")} for annotation: ${e.id}`)}}}return{parsed:a}},wi=e=>{const t=e.id||fi(),{creator:n,created:i,modified:o,body:r,...s}=e,a=vo(r,t),l=Jo(e);return"error"in l?{error:l.error}:{parsed:{...s,id:t,bodies:a,target:l.parsed}}},yi=(e,t,n)=>{const{bodies:i,target:o,...r}=e,{selector:s,creator:a,created:l,updated:c,...u}=o,f=s.map(S=>{const{id:g,quote:p,start:E,end:T,range:b}=S,d={type:"TextQuoteSelector",exact:p};if(n){const{prefix:U,suffix:x}=hi(b,n);d.prefix=U,d.suffix=x}const R={type:"TextPositionSelector",start:E,end:T};return{...u,id:g,scope:"scope"in S?S.scope:void 0,source:t,selector:[d,R]}});return{...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Eo(e.bodies),creator:a,created:l?.toISOString(),modified:c?.toISOString(),target:f}};function vi(e,t,n=0,i=e.length-1,o=Qo){for(;i>n;){if(i-n>600){const l=i-n+1,c=t-n+1,u=Math.log(l),f=.5*Math.exp(2*u/3),S=.5*Math.sqrt(u*f*(l-f)/l)*(c-l/2<0?-1:1),g=Math.max(n,Math.floor(t-c*f/l+S)),p=Math.min(i,Math.floor(t+(l-c)*f/l+S));vi(e,t,g,p,o)}const r=e[t];let s=n,a=i;for(rt(e,n,t),o(e[i],r)>0&&rt(e,n,i);s<a;){for(rt(e,s,a),s++,a--;o(e[s],r)<0;)s++;for(;o(e[a],r)>0;)a--}o(e[n],r)===0?rt(e,n,a):(a++,rt(e,a,i)),a<=t&&(n=a+1),t<=a&&(i=a-1)}}function rt(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function Qo(e,t){return e<t?-1:e>t?1:0}class Zo{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const i=[];if(!Mt(t,n))return i;const o=this.toBBox,r=[];for(;n;){for(let s=0;s<n.children.length;s++){const a=n.children[s],l=n.leaf?o(a):a;Mt(t,l)&&(n.leaf?i.push(a):gn(t,l)?this._all(a,i):r.push(a))}n=r.pop()}return i}collides(t){let n=this.data;if(!Mt(t,n))return!1;const i=[];for(;n;){for(let o=0;o<n.children.length;o++){const r=n.children[o],s=n.leaf?this.toBBox(r):r;if(Mt(t,s)){if(n.leaf||gn(t,s))return!0;i.push(r)}}n=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const i=this.data;this.data=n,n=i}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Ye([]),this}remove(t,n){if(!t)return this;let i=this.data;const o=this.toBBox(t),r=[],s=[];let a,l,c;for(;i||r.length;){if(i||(i=r.pop(),l=r[r.length-1],a=s.pop(),c=!0),i.leaf){const u=er(t,i.children,n);if(u!==-1)return i.children.splice(u,1),r.push(i),this._condense(r),this}!c&&!i.leaf&&gn(i,o)?(r.push(i),s.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],c=!1):i=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const i=[];for(;t;)t.leaf?n.push(...t.children):i.push(...t.children),t=i.pop();return n}_build(t,n,i,o){const r=i-n+1;let s=this._maxEntries,a;if(r<=s)return a=Ye(t.slice(n,i+1)),Fe(a,this.toBBox),a;o||(o=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,o-1))),a=Ye([]),a.leaf=!1,a.height=o;const l=Math.ceil(r/s),c=l*Math.ceil(Math.sqrt(s));Ei(t,n,i,c,this.compareMinX);for(let u=n;u<=i;u+=c){const f=Math.min(u+c-1,i);Ei(t,u,f,l,this.compareMinY);for(let S=u;S<=f;S+=l){const g=Math.min(S+l-1,f);a.children.push(this._build(t,S,g,o-1))}}return Fe(a,this.toBBox),a}_chooseSubtree(t,n,i,o){for(;o.push(n),!(n.leaf||o.length-1===i);){let r=1/0,s=1/0,a;for(let l=0;l<n.children.length;l++){const c=n.children[l],u=pn(c),f=ir(t,c)-u;f<s?(s=f,r=u<r?u:r,a=c):f===s&&u<r&&(r=u,a=c)}n=a||n.children[0]}return n}_insert(t,n,i){const o=i?t:this.toBBox(t),r=[],s=this._chooseSubtree(o,this.data,n,r);for(s.children.push(t),at(s,o);n>=0&&r[n].children.length>this._maxEntries;)this._split(r,n),n--;this._adjustParentBBoxes(o,r,n)}_split(t,n){const i=t[n],o=i.children.length,r=this._minEntries;this._chooseSplitAxis(i,r,o);const s=this._chooseSplitIndex(i,r,o),a=Ye(i.children.splice(s,i.children.length-s));a.height=i.height,a.leaf=i.leaf,Fe(i,this.toBBox),Fe(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,n){this.data=Ye([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Fe(this.data,this.toBBox)}_chooseSplitIndex(t,n,i){let o,r=1/0,s=1/0;for(let a=n;a<=i-n;a++){const l=st(t,0,a,this.toBBox),c=st(t,a,i,this.toBBox),u=or(l,c),f=pn(l)+pn(c);u<r?(r=u,o=a,s=f<s?f:s):u===r&&f<s&&(s=f,o=a)}return o||i-n}_chooseSplitAxis(t,n,i){const o=t.leaf?this.compareMinX:tr,r=t.leaf?this.compareMinY:nr,s=this._allDistMargin(t,n,i,o),a=this._allDistMargin(t,n,i,r);s<a&&t.children.sort(o)}_allDistMargin(t,n,i,o){t.children.sort(o);const r=this.toBBox,s=st(t,0,n,r),a=st(t,i-n,i,r);let l=It(s)+It(a);for(let c=n;c<i-n;c++){const u=t.children[c];at(s,t.leaf?r(u):u),l+=It(s)}for(let c=i-n-1;c>=n;c--){const u=t.children[c];at(a,t.leaf?r(u):u),l+=It(a)}return l}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)at(n[o],t)}_condense(t){for(let n=t.length-1,i;n>=0;n--)t[n].children.length===0?n>0?(i=t[n-1].children,i.splice(i.indexOf(t[n]),1)):this.clear():Fe(t[n],this.toBBox)}}function er(e,t,n){if(!n)return t.indexOf(e);for(let i=0;i<t.length;i++)if(n(e,t[i]))return i;return-1}function Fe(e,t){st(e,0,e.children.length,t,e)}function st(e,t,n,i,o){o||(o=Ye(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let r=t;r<n;r++){const s=e.children[r];at(o,e.leaf?i(s):s)}return o}function at(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function tr(e,t){return e.minX-t.minX}function nr(e,t){return e.minY-t.minY}function pn(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function It(e){return e.maxX-e.minX+(e.maxY-e.minY)}function ir(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function or(e,t){const n=Math.max(e.minX,t.minX),i=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),r=Math.min(e.maxY,t.maxY);return Math.max(0,o-n)*Math.max(0,r-i)}function gn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Mt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ye(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Ei(e,t,n,i,o){const r=[t,n];for(;r.length;){if(n=r.pop(),t=r.pop(),n-t<=i)continue;const s=t+Math.ceil((n-t)/i/2)*i;vi(e,s,t,n,o),r.push(t,s,s,n)}}const Ai=(e,t)=>{const n=(r,s)=>r.x<=s.x+s.width&&r.x+r.width>=s.x&&r.y<=s.y+s.height&&r.y+r.height>=s.y,i=r=>r.rects.reduce((s,a)=>s+a.width,0),o=t.filter(({rects:r})=>r.some(s=>n(e,s)));return o.sort((r,s)=>i(s)-i(r)),o.findIndex(r=>r.rects.includes(e))},Si=e=>{const t=[],n=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_TEXT);let i;for(;i=n.nextNode();)e.intersectsNode(i)&&t.push(i);if(t.length<2)return Array.from(e.getClientRects());{const o=t[0],r=t[t.length-1],s=document.createRange();if(s.selectNode(o),e.startContainer.nodeType===Node.TEXT_NODE)s.setStart(o,e.startOffset);else{const c=e.startContainer.childNodes[e.startOffset];c?s.setStartBefore(c):s.setStartAfter(e.startContainer)}const a=document.createRange();if(a.selectNode(r),e.endContainer.nodeType===Node.TEXT_NODE)a.setEnd(r,e.endOffset);else{const c=e.endContainer.childNodes[e.endOffset];c?a.setEndBefore(c):a.setEndAfter(e.endContainer)}const l=c=>{const u=document.createRange();return u.selectNode(c),Array.from(u.getClientRects())};return[...Array.from(s.getClientRects()),...t.slice(1,-1).flatMap(l),...Array.from(a.getClientRects())]}},rr=(e,t,n,i)=>{const o=a=>Math.round(a*10)/10,r={top:o(e.top),bottom:o(e.bottom),left:o(e.left),right:o(e.right)},s={top:o(t.top),bottom:o(t.bottom),left:o(t.left),right:o(t.right)};if(Math.abs(r.top-s.top)<i&&Math.abs(r.bottom-s.bottom)<i){if(Math.abs(r.left-s.right)<n||Math.abs(r.right-s.left)<n)return"inline-adjacent";if(r.left>=s.left&&r.right<=s.right)return"inline-is-contained";if(r.left<=s.left&&r.right>=s.right)return"inline-contains"}else if(r.top<=s.top&&r.bottom>=s.bottom){if(r.left<=s.left&&r.right>=s.right)return"block-contains"}else if(r.top>=s.top&&r.bottom<=s.bottom&&r.left>=s.left&&r.right<=s.right)return"block-is-contained"},sr=(e,t)=>{const n=Math.min(e.left,t.left),i=Math.max(e.right,t.right),o=Math.min(e.top,t.top),r=Math.max(e.bottom,t.bottom);return new DOMRect(n,o,i-n,r-o)},Oi=(e,t=.5,n=.5)=>e.reduce((i,o)=>{if(o.width===0||o.height===0)return i;let r=[...i],s=!1;for(const a of i){const l=rr(o,a,t,n);if(l==="inline-adjacent"){r=r.map(c=>c===a?sr(o,a):c),s=!0;break}else if(l==="inline-contains"){r=r.map(c=>c===a?o:c),s=!0;break}else if(l==="inline-is-contained"){s=!0;break}else if(l==="block-contains"||l==="block-is-contained"){o.width<a.width&&(r=r.map(c=>c===a?o:c)),o.width===a.width&&o.height<a.width&&(r=r.map(c=>c===a?o:c)),s=!0;break}}return s?r:[...r,o]},[]),ar=e=>({length:e.length,item:t=>e[t],[Symbol.iterator]:function*(){for(let t=0;t<this.length;t++)yield this.item(t)}}),Ci=(e,t)=>{const{left:n,top:i,right:o,bottom:r}=e;return new DOMRect(n-t.left,i-t.top,o-n,r-i)},lr=(e,t)=>{const{left:n,top:i,right:o,bottom:r}=e;return new DOMRect(n+t.left,i+t.top,o-n,r-i)},cr=(e,t,n,i)=>{const o=new Zo,r=new Map,s=Be(),a=(x,L)=>{const H=x.selector.flatMap(K=>{const _=pe([K])?K.range:hn(K,t).range;return Si(_)}),P=Oi(H,n,i).map(K=>Ci(K,L));return P.map(K=>{const{x:_,y:D,width:A,height:O}=K;return{minX:_,minY:D,maxX:_+A,maxY:D+O,annotation:{id:x.annotation,rects:P}}})},l=()=>[...r.values()],c=()=>{o.clear(),r.clear()},u=x=>{const L=a(x,t.getBoundingClientRect());L.length!==0&&(L.forEach(H=>o.insert(H)),r.set(x.annotation,L))},f=x=>{const L=r.get(x.annotation);L&&(L.forEach(H=>o.remove(H)),r.delete(x.annotation))},S=x=>{f(x),u(x)},g=(x,L=!0)=>{L&&c();const H=t.getBoundingClientRect(),P=x.map(_=>({target:_,rects:a(_,H)}));P.forEach(({target:_,rects:D})=>{D.length>0&&r.set(_.annotation,D)});const K=P.flatMap(({rects:_})=>_);o.load(K)},p=(x,L,H=!1)=>{const P=o.search({minX:x,minY:L,maxX:x,maxY:L}),K=_=>_.annotation.rects.reduce((D,A)=>D+A.width*A.height,0);return P.length>0?(P.sort((_,D)=>K(_)-K(D)),H?P.map(_=>_.annotation.id):[P[0].annotation.id]):[]},E=x=>{const L=T(x);if(L.length===0)return;let H=L[0].left,P=L[0].top,K=L[0].right,_=L[0].bottom;for(let D=1;D<L.length;D++){const A=L[D];H=Math.min(H,A.left),P=Math.min(P,A.top),K=Math.max(K,A.right),_=Math.max(_,A.bottom)}return new DOMRect(H,P,K-H,_-P)},T=x=>{const L=r.get(x);return L?L[0].annotation.rects:[]};return{all:l,clear:c,getAt:p,getAnnotationBounds:E,getAnnotationRects:T,getIntersecting:(x,L,H,P)=>{const K=o.search({minX:x,minY:L,maxX:H,maxY:P}),_=new Set(K.map(D=>D.annotation.id));return Array.from(_).map(D=>({annotation:e.getAnnotation(D),rects:T(D)})).filter(D=>!!D.annotation)},insert:u,recalculate:()=>{g(e.all().map(x=>x.target),!0),s.emit("recalculate")},remove:f,set:g,size:()=>o.all().length,update:S,on:(x,L)=>s.on(x,L)}},xi=(e,t)=>{const n=oo(),i=cr(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance),o=Yi(n,t.userSelectAction,t.adapter),r=Fi(n),s=lo(),a=(d,R=V.LOCAL)=>{const U=Nt(d,e),x=pe(U.target.selector);return x&&n.addAnnotation(U,R),x},l=(d,R=!0,U=V.LOCAL)=>{const x=d.map(H=>Nt(H,e)),L=x.filter(H=>!pe(H.target.selector));return n.bulkAddAnnotations(x,R,U),L},c=(d,R=V.LOCAL)=>{const U=d.map(L=>Nt(L,e)),x=U.filter(L=>!pe(L.target.selector));return U.forEach(L=>{n.getAnnotation(L.id)?n.updateAnnotation(L,R):n.addAnnotation(L,R)}),x},u=(d,R=V.LOCAL)=>{const U=ot(d,e);n.updateTarget(U,R)},f=(d,R=V.LOCAL)=>{const U=d.map(x=>ot(x,e));n.bulkUpdateTargets(U,R)};function S(d,R,U,x){const L=U||!!x,H=i.getAt(d,R,L).map(K=>n.getAnnotation(K)),P=x?H.filter(x):H;if(P.length!==0)return U?P:P[0]}const g=d=>i.getAnnotationRects(d).length>0?i.getAnnotationBounds(d):void 0,p=(d,R,U,x)=>i.getIntersecting(d,R,U,x),E=d=>i.getAnnotationRects(d),T=()=>i.recalculate(),b=d=>i.on("recalculate",d);return n.observe(({changes:d})=>{const R=(d.deleted||[]).filter(L=>pe(L.target.selector)),U=(d.created||[]).filter(L=>pe(L.target.selector)),x=(d.updated||[]).filter(L=>pe(L.newValue.target.selector));R?.length>0&&R.forEach(L=>i.remove(L.target)),U.length>0&&i.set(U.map(L=>L.target),!1),x?.length>0&&x.forEach(({newValue:L})=>i.update(L.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotations:l,bulkUpdateTargets:f,bulkUpsertAnnotations:c,getAnnotationBounds:g,getAnnotationRects:E,getIntersecting:p,getAt:S,recalculatePositions:T,onRecalculatePositions:b,updateTarget:u},selection:o,hover:r,viewport:s}};function dr(e,t=100,n={}){if(typeof e!="function")throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");if(typeof n=="boolean")throw new TypeError("The `options` parameter must be an object, not a boolean. Use `{immediate: true}` instead.");const{immediate:i}=n;let o,r,s,a,l;function c(){const S=o,g=r;return o=void 0,r=void 0,l=e.apply(S,g),l}function u(){const S=Date.now()-a;S<t&&S>=0?s=setTimeout(u,t-S):(s=void 0,i||(l=c()))}const f=function(...S){if(o&&this!==o&&Object.getPrototypeOf(this)===Object.getPrototypeOf(o))throw new Error("Debounced method called with different contexts of the same prototype.");o=this,r=S,a=Date.now();const g=i&&!s;if(s||(s=setTimeout(u,t)),g)return l=c(),l};return Object.defineProperty(f,"isPending",{get(){return s!==void 0}}),f.clear=()=>{s&&(clearTimeout(s),s=void 0,o=void 0,r=void 0)},f.flush=()=>{s&&f.trigger()},f.trigger=()=>{l=c(),f.clear()},f}const mn=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function bn(e,t,n,i){e.addEventListener?e.addEventListener(t,n,i):e.attachEvent&&e.attachEvent("on".concat(t),n)}function lt(e,t,n,i){e.removeEventListener?e.removeEventListener(t,n,i):e.detachEvent&&e.detachEvent("on".concat(t),n)}function Ti(e,t){const n=t.slice(0,t.length-1);for(let i=0;i<n.length;i++)n[i]=e[n[i].toLowerCase()];return n}function Ri(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function ur(e,t){const n=e.length>=t.length?e:t,i=e.length>=t.length?t:e;let o=!0;for(let r=0;r<n.length;r++)i.indexOf(n[r])===-1&&(o=!1);return o}const ct={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,arrowup:38,arrowdown:40,arrowleft:37,arrowright:39,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":mn?173:189,"=":mn?61:187,";":mn?59:186,"'":222,"{":219,"}":221,"[":219,"]":221,"\\":220},de={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,meta:91,command:91},dt={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Z={16:!1,18:!1,17:!1,91:!1},j={};for(let e=1;e<20;e++)ct["f".concat(e)]=111+e;let W=[],ut=null,ki="all";const Ae=new Map,Ke=e=>ct[e.toLowerCase()]||de[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),fr=e=>Object.keys(ct).find(t=>ct[t]===e),hr=e=>Object.keys(de).find(t=>de[t]===e);function Li(e){ki=e||"all"}function ft(){return ki||"all"}function pr(){return W.slice(0)}function gr(){return W.map(e=>fr(e)||hr(e)||String.fromCharCode(e))}function mr(){const e=[];return Object.keys(j).forEach(t=>{j[t].forEach(n=>{let{key:i,scope:o,mods:r,shortcut:s}=n;e.push({scope:o,shortcut:s,mods:r,keys:i.split("+").map(a=>Ke(a))})})}),e}function br(e){const t=e.target||e.srcElement,{tagName:n}=t;let i=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(i=!1),i}function wr(e){return typeof e=="string"&&(e=Ke(e)),W.indexOf(e)!==-1}function yr(e,t){let n,i;e||(e=ft());for(const o in j)if(Object.prototype.hasOwnProperty.call(j,o))for(n=j[o],i=0;i<n.length;)n[i].scope===e?n.splice(i,1).forEach(s=>{let{element:a}=s;return wn(a)}):i++;ft()===e&&Li(t||"all")}function vr(e){let t=e.keyCode||e.which||e.charCode;e.key&&e.key.toLowerCase()==="capslock"&&(t=Ke(e.key));const n=W.indexOf(t);if(n>=0&&W.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&W.splice(0,W.length),(t===93||t===224)&&(t=91),t in Z){Z[t]=!1;for(const i in de)de[i]===t&&(ae[i]=!1)}}function Ni(e){if(typeof e>"u")Object.keys(j).forEach(o=>{Array.isArray(j[o])&&j[o].forEach(r=>Bt(r)),delete j[o]}),wn(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&Bt(o)});else if(typeof e=="object")e.key&&Bt(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];let[o,r]=n;typeof o=="function"&&(r=o,o=""),Bt({key:e,scope:o,method:r,splitKey:"+"})}}const Bt=e=>{let{key:t,scope:n,method:i,splitKey:o="+"}=e;Ri(t).forEach(s=>{const a=s.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Ke(c);if(!j[u])return;n||(n=ft());const f=l>1?Ti(de,a):[],S=[];j[u]=j[u].filter(g=>{const E=(i?g.method===i:!0)&&g.scope===n&&ur(g.mods,f);return E&&S.push(g.element),!E}),S.forEach(g=>wn(g))})};function Ii(e,t,n,i){if(t.element!==i)return;let o;if(t.scope===n||t.scope==="all"){o=t.mods.length>0;for(const r in Z)Object.prototype.hasOwnProperty.call(Z,r)&&(!Z[r]&&t.mods.indexOf(+r)>-1||Z[r]&&t.mods.indexOf(+r)===-1)&&(o=!1);(t.mods.length===0&&!Z[16]&&!Z[18]&&!Z[17]&&!Z[91]||o||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(W),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function Mi(e,t){const n=j["*"];let i=e.keyCode||e.which||e.charCode;if(e.key&&e.key.toLowerCase()==="capslock"||!ae.filter.call(this,e))return;if((i===93||i===224)&&(i=91),W.indexOf(i)===-1&&i!==229&&W.push(i),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=dt[a];e[a]&&W.indexOf(l)===-1?W.push(l):!e[a]&&W.indexOf(l)>-1?W.splice(W.indexOf(l),1):a==="metaKey"&&e[a]&&(W=W.filter(c=>c in dt||c===i))}),i in Z){Z[i]=!0;for(const a in de)if(Object.prototype.hasOwnProperty.call(de,a)){const l=dt[de[a]];ae[a]=e[l]}if(!n)return}for(const a in Z)Object.prototype.hasOwnProperty.call(Z,a)&&(Z[a]=e[dt[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(W.indexOf(17)===-1&&W.push(17),W.indexOf(18)===-1&&W.push(18),Z[17]=!0,Z[18]=!0);const o=ft();if(n)for(let a=0;a<n.length;a++)n[a].scope===o&&(e.type==="keydown"&&n[a].keydown||e.type==="keyup"&&n[a].keyup)&&Ii(e,n[a],o,t);if(!(i in j))return;const r=j[i],s=r.length;for(let a=0;a<s;a++)if((e.type==="keydown"&&r[a].keydown||e.type==="keyup"&&r[a].keyup)&&r[a].key){const l=r[a],{splitKey:c}=l,u=l.key.split(c),f=[];for(let S=0;S<u.length;S++)f.push(Ke(u[S]));f.sort().join("")===W.sort().join("")&&Ii(e,l,o,t)}}function ae(e,t,n){W=[];const i=Ri(e);let o=[],r="all",s=document,a=0,l=!1,c=!0,u="+",f=!1,S=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(r=t.scope),t.element&&(s=t.element),t.keyup&&(l=t.keyup),t.keydown!==void 0&&(c=t.keydown),t.capture!==void 0&&(f=t.capture),typeof t.splitKey=="string"&&(u=t.splitKey),t.single===!0&&(S=!0)),typeof t=="string"&&(r=t),S&&Ni(e,r);a<i.length;a++)e=i[a].split(u),o=[],e.length>1&&(o=Ti(de,e)),e=e[e.length-1],e=e==="*"?"*":Ke(e),e in j||(j[e]=[]),j[e].push({keyup:l,keydown:c,scope:r,mods:o,shortcut:i[a],method:n,key:i[a],splitKey:u,element:s});if(typeof s<"u"&&window){if(!Ae.has(s)){const g=function(){let E=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return Mi(E,s)},p=function(){let E=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;Mi(E,s),vr(E)};Ae.set(s,{keydownListener:g,keyupListenr:p,capture:f}),bn(s,"keydown",g,f),bn(s,"keyup",p,f)}if(!ut){const g=()=>{W=[]};ut={listener:g,capture:f},bn(window,"focus",g,f)}}}function Er(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(j).forEach(n=>{j[n].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function wn(e){const t=Object.values(j).flat();if(t.findIndex(i=>{let{element:o}=i;return o===e})<0){const{keydownListener:i,keyupListenr:o,capture:r}=Ae.get(e)||{};i&&o&&(lt(e,"keyup",o,r),lt(e,"keydown",i,r),Ae.delete(e))}if((t.length<=0||Ae.size<=0)&&(Object.keys(Ae).forEach(o=>{const{keydownListener:r,keyupListenr:s,capture:a}=Ae.get(o)||{};r&&s&&(lt(o,"keyup",s,a),lt(o,"keydown",r,a),Ae.delete(o))}),Ae.clear(),Object.keys(j).forEach(o=>delete j[o]),ut)){const{listener:o,capture:r}=ut;lt(window,"focus",o,r),ut=null}}const yn={getPressedKeyString:gr,setScope:Li,getScope:ft,deleteScope:yr,getPressedKeyCodes:pr,getAllKeyCodes:mr,isPressed:wr,filter:br,trigger:Er,unbind:Ni,keyMap:ct,modifier:de,modifierMap:dt};for(const e in yn)Object.prototype.hasOwnProperty.call(yn,e)&&(ae[e]=yn[e]);if(typeof window<"u"){const e=window.hotkeys;ae.noConflict=t=>(t&&window.hotkeys===ae&&(window.hotkeys=e),ae),window.hotkeys=ae}async function Ar(e,t,n=(()=>!1)){do{if(await e(),await n())break;const i=t;await new Promise((o=>setTimeout(o,Math.max(0,i))))}while(!await n())}const Bi=300,_i=["up","down","left","right"],Ui=on?"⌘+a":"ctrl+a",Sr=[..._i.map(e=>`shift+${e}`),Ui],Di=(e,t,n,i)=>{const{store:o,selection:r}=t;let s;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:c,dismissOnNotAnnotatable:u="NEVER"}=i;let f,S=a,g="CREATE_NEW",p,E,T,b;const d=k=>{S=k,P.clear(),k||(E=void 0,p=void 0,T=void 0,b=void 0)},R=k=>g=k||"CREATE_NEW",U=k=>f=k,x=k=>s=k,L=k=>{if(g==="ADD_TO_CURRENT")return!0;if(i.allowModifierSelect){const M=k;return on?M.metaKey:M.ctrlKey}else return!1},H=()=>{if(!S||T===!1)return;const{selected:k}=r;if((L(b)||g==="REPLACE_CURRENT")&&k.length===1&&k[0].editable){const ee=o.getAnnotation(k[0].id);if(ee?.target){E=ee.target,p={annotation:ee.id,selector:[],created:E.created,creator:E.creator,updated:new Date,updatedBy:s};return}}E=void 0,p={annotation:fi(),selector:[],created:new Date,creator:s}},P=dr(k=>{if(!S)return;const M=document.getSelection();if(!M?.anchorNode)return;const ee=Array.from(Array(M.rangeCount).keys()).map(G=>M.getRangeAt(G));if(!ee.some(G=>G.intersectsNode(e))){p=void 0;return}const Me=k.timeStamp-(b?.timeStamp||k.timeStamp);if(b?.type==="pointerdown"&&(Me<1e3&&!p||M.isCollapsed&&Me<Bi)&&H(),p||H(),M.isCollapsed){o.getAnnotation(p.annotation)&&!(L(b)||g==="REPLACE_CURRENT")&&(r.clear(),o.deleteAnnotation(p.annotation));return}const ge=ee.map(G=>qn(G,e));if(ge.every(G=>Wn(G)))return;const me=ge.flatMap(G=>zn(e,G.cloneRange()));if(!(me.length>0&&!p||me.length!==p.selector.length||me.some((G,ht)=>G.toString()!==p.selector[ht]?.quote)))return;const _t=L(b)&&E?jn([...E.selector.map(G=>G.range),...me]):me;p={...p,selector:_t.map(G=>pi(G,e,l)),updated:new Date},!(L(b)||g==="REPLACE_CURRENT")&&(o.getAnnotation(p.annotation)?o.updateTarget(p,V.LOCAL):r.clear())},10),K=k=>{b=Tt(k),T=b.button===0},_=async k=>{if(!T)return;const M=Tt(k),ee=()=>{const{x:ge,y:me}=e.getBoundingClientRect();if(tt(e,M.target)){(typeof u=="function"?u(M,e):u==="ALWAYS")&&r.clear();return}const Re=M.target instanceof Node&&e.contains(M.target)&&o.getAt(M.clientX-ge,M.clientY-me,c==="all",f);if(Re){const{selected:_t}=r,G=new Set(_t.map(pt=>pt.id)),ht=Array.isArray(Re)?Re.map(pt=>pt.id):[Re.id];(G.size!==ht.length||!ht.every(pt=>G.has(pt)))&&(n.emit("clickAnnotation",Re),r.userSelect(ht,M))}else r.clear()};if(M.timeStamp-b.timeStamp<Bi){await D();const ge=document.getSelection(),me=tt(e,b.target),Re=tt(e,M.target);if(ge?.isCollapsed||me&&Re){p=void 0,ee();return}}p&&p.selector.length>0&&(F(),r.userSelect(p.annotation,M))},D=async()=>{const k=document.getSelection();let M=!1,ee=k?.isCollapsed;const Me=()=>ee||M,ge=1;return setTimeout(()=>M=!0,50),Ar(()=>ee=k?.isCollapsed,ge,Me)},A=k=>{document.getSelection()?.isCollapsed||((!p||p.selector.length===0)&&P(k),p&&(F(),r.userSelect(p.annotation,Tt(k))))},O=k=>{S&&k.key==="Shift"&&p&&(document.getSelection().isCollapsed||(F(),r.userSelect(p.annotation,nt(k))))},C=k=>{const M=()=>setTimeout(()=>{p?.selector.length>0&&(r.clear(),o.addAnnotation({id:p.annotation,bodies:[],target:p}),r.userSelect(p.annotation,nt(k))),document.removeEventListener("selectionchange",M)},100);document.addEventListener("selectionchange",M),H()};ae(Sr.join(","),{element:e,keydown:!0,keyup:!1},k=>{k.repeat||(b=nt(k))}),ae(Ui,{keydown:!0,keyup:!1},k=>{b=nt(k),C(k)});const N=k=>{k.repeat||k.target!==e&&k.target!==document.body||(p=void 0,r.clear())};ae(_i.join(","),{keydown:!0,keyup:!1},N);const F=()=>{const k=o.getAnnotation(p.annotation);if(!k)o.addAnnotation({id:p.annotation,bodies:[],target:p});else{const{target:{updated:M}}=k,{updated:ee}=p;(!M||!ee||M<ee)&&o.updateTarget(p)}};return document.addEventListener("pointerdown",K),document.addEventListener("pointerup",_),document.addEventListener("contextmenu",A),e.addEventListener("keyup",O),e.addEventListener("selectstart",H),document.addEventListener("selectionchange",P),{destroy:()=>{p=void 0,E=void 0,T=void 0,b=void 0,P.clear(),document.removeEventListener("pointerdown",K),document.removeEventListener("pointerup",_),document.removeEventListener("contextmenu",A),e.removeEventListener("keyup",O),e.removeEventListener("selectstart",H),document.removeEventListener("selectionchange",P),ae.unbind()},setFilter:U,setUser:x,setAnnotatingEnabled:d,setAnnotatingMode:R}};var Hi=Object.prototype.hasOwnProperty;function vn(e,t){var n,i;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((i=e.length)===t.length)for(;i--&&vn(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(Hi.call(e,n)&&++i&&!Hi.call(t,n)||!(n in t)||!vn(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}const Or=e=>{e.classList.add("r6o-annotatable");const t=document.createElement("div");t.className="r6o-span-highlight-layer",e.insertBefore(t,e.firstChild);let n=[];return{destroy:()=>{t.remove()},redraw:(s,a,l,c,u)=>{if(!(!vn(n,s)||u))return;t.innerHTML="",[...s].sort((p,E)=>{const{annotation:{target:{created:T}}}=p,{annotation:{target:{created:b}}}=E;return T&&b?T.getTime()-b.getTime():0}).forEach(p=>{const E=c.get(p.annotation.id)||l;p.rects.map(T=>{const b=Ai(T,s),d=un(p,E,b),R=document.createElement("span");R.className="r6o-annotation",R.dataset.annotation=p.annotation.id,R.style.left=`${T.x}px`,R.style.top=`${T.y}px`,R.style.width=`${T.width}px`,R.style.height=`${T.height}px`,R.style.backgroundColor=li(d),d.underlineStyle&&(R.style.borderStyle=d.underlineStyle),d.underlineColor&&(R.style.borderColor=d.underlineColor),d.underlineThickness&&(R.style.borderBottomWidth=`${d.underlineThickness}px`),d.underlineOffset&&(R.style.paddingBottom=`${d.underlineOffset}px`),t.appendChild(R)})}),n=s},setVisible:s=>{s?t.classList.remove("hidden"):t.classList.add("hidden")}}},Cr=(e,t,n)=>an(Or(e),e,t,n),xr=e=>[`background-color:${se(e?.fill||Ee.fill).alpha(e?.fillOpacity===void 0?Ee.fillOpacity:e.fillOpacity).toHex()}`,e?.underlineThickness?"text-decoration:underline":void 0,e?.underlineColor?`text-decoration-color:${e.underlineColor}`:void 0,e?.underlineOffset?`text-underline-offset:${e.underlineOffset}px`:void 0,e?.underlineThickness?`text-decoration-thickness:${e.underlineThickness}px`:void 0].filter(Boolean).join(";"),Tr=()=>{const e=document.createElement("style");document.getElementsByTagName("head")[0].appendChild(e);let t=new Set;return{destroy:()=>{CSS.highlights.clear(),e.remove()},setVisible:r=>{console.log("setVisible not implemented on CSS Custom Highlights renderer")},redraw:(r,s,a,l,c)=>{const u=new Set(r.map(S=>S.annotation.id));Array.from(t).filter(S=>!u.has(S));const f=r.map(S=>{a?typeof a=="function"&&a(S.annotation,S.state):S.state?.selected;const g=un(S,a);return`::highlight(_${S.annotation.id}) { ${xr(g)} }`});e.innerHTML=f.join(`
|
|
2
|
-
`),CSS.highlights.clear(),
|
|
1
|
+
(function(L,K){typeof exports=="object"&&typeof module<"u"?K(exports):typeof define=="function"&&define.amd?define(["exports"],K):(L=typeof globalThis<"u"?globalThis:L||self,K(L.RecogitoJS={}))})(this,(function(L){"use strict";const K=[];for(let e=0;e<256;++e)K.push((e+256).toString(16).slice(1));function an(e,t=0){return(K[e[t+0]]+K[e[t+1]]+K[e[t+2]]+K[e[t+3]]+"-"+K[e[t+4]]+K[e[t+5]]+"-"+K[e[t+6]]+K[e[t+7]]+"-"+K[e[t+8]]+K[e[t+9]]+"-"+K[e[t+10]]+K[e[t+11]]+K[e[t+12]]+K[e[t+13]]+K[e[t+14]]+K[e[t+15]]).toLowerCase()}const ln=new Uint8Array(16);function cn(){return crypto.getRandomValues(ln)}function it(e,t,n){return crypto.randomUUID?crypto.randomUUID():dn(e)}function dn(e,t,n){e=e||{};const o=e.random??e.rng?.()??cn();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,an(o)}const De=typeof navigator<"u"&&navigator.platform.startsWith("Mac"),Ye="not-annotatable",se=`.${Ye}`,re=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(se):t.parentElement?.closest(se)):!0,Ve=(e,t)=>{const n=t.commonAncestorContainer;return!re(e,n)},Ke=/^\s*$/,st=e=>Ke.test(e.toString()),un=e=>Ke.test(e.textContent||""),rt=e=>{if(e.length===0)return[];if(e.length===1)return[e[0]];e.sort((i,s)=>{const r=i.compareBoundaryPoints(Range.START_TO_START,s);return r!==0?r:i.compareBoundaryPoints(Range.END_TO_END,s)});const[t,...n]=e,o=n.reduce((i,s)=>i.current.compareBoundaryPoints(Range.START_TO_END,s)>=0?(i.current.compareBoundaryPoints(Range.END_TO_END,s)<0&&i.current.setEnd(s.endContainer,s.endOffset),i):(i.merged.push(i.current),i.current=s.cloneRange(),i),{merged:[],current:t.cloneRange()});return[...o.merged,o.current]},at=e=>{(!e.hasAttribute("tabindex")||e.tabIndex<-1)&&e.setAttribute("tabindex","-1"),e.classList.add("no-focus-outline")},fn=function*(e){const t=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(Ye)&&!o.parentElement.closest(se)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},lt=(e,t)=>{if(!Ve(e,t))return[];const n=[];let o=null;for(const i of fn(t)){let s;o?(s=document.createRange(),s.setStartAfter(o),s.setEndBefore(i)):(s=t.cloneRange(),s.setEndBefore(i)),s.collapsed||n.push(s),o=i}if(o){const i=t.cloneRange();i.setStartAfter(o),i.collapsed||n.push(i)}return n.length>0?n:[t]},Te=e=>{const t=e.cloneContents();return t.querySelectorAll(se).forEach(n=>n.remove()),t},ct=(e,t)=>{const n=e.cloneRange();return t.contains(n.startContainer)||n.setStart(t,0),t.contains(n.endContainer)||n.setEnd(t,t.childNodes.length),n},dt=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ut=(e,t,n=10,o)=>{const i=o?e.startContainer.parentElement.closest(o):t,s=document.createRange();s.setStart(i,0),s.setEnd(e.startContainer,e.startOffset);const r=Te(s).textContent,a=document.createRange();a.setStart(e.endContainer,e.endOffset),i===document.body?a.setEnd(i,i.childNodes.length):a.setEndAfter(i);const l=Te(a).textContent,c=[...dt.segment(r)],h=[...dt.segment(l)];return{prefix:c.slice(-n).map(f=>f.segment).join(""),suffix:h.slice(0,n).map(f=>f.segment).join("")}},ft=(e,t,n)=>{const o=document.createRange(),i=n?e.startContainer.parentElement.closest(n):t;o.setStart(i,0),o.setEnd(e.startContainer,e.startOffset);const s=Te(o).textContent,r=e.toString(),a=s.length||0,l=a+r.length;return n?{quote:r,start:a,end:l,range:e,offsetReference:i}:{quote:r,start:a,end:l,range:e}},Q=e=>e.every(t=>t.range instanceof Range&&!t.range.collapsed),Xe=(e,t)=>{const{start:n,end:o}=e,i=e.offsetReference||t,s=document.createNodeIterator(t,NodeFilter.SHOW_TEXT,h=>h.parentElement?.closest(se)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT);let r=0;const a=document.createRange();let l=s.nextNode();l===null&&console.error("Could not revive annotation target. Content missing.");let c=!i;for(;l!==null;){if(c||=typeof i?.contains=="function"?i.contains(l):!1,c){const h=l.textContent?.length||0;if(r+h>n){a.setStart(l,n-r);break}r+=h}l=s.nextNode()}for(;l!==null;){const h=l.textContent?.length||0;if(r+h>=o){a.setEnd(l,o-r);break}r+=h,l=s.nextNode()}return{...e,range:a}},fe=(e,t)=>Q(e.selector)?e:{...e,selector:e.selector.map(n=>n.range instanceof Range&&!n.range.collapsed?n:Xe(n,t))},xe=(e,t)=>Q(e.target.selector)?e:{...e,target:fe(e.target,t)},ht=e=>{if(!e)return document.scrollingElement;const{overflowY:t}=window.getComputedStyle(e);return t!=="visible"&&t!=="hidden"&&e.scrollHeight>e.clientHeight?e:ht(e.parentElement)},gt=(e,t,n)=>{const o=n.getBoundingClientRect(),i=n.clientHeight,s=n.clientWidth,r=t.selector[0].range.getBoundingClientRect(),{width:a,height:l}=e.getAnnotationBounds(t.annotation),c=r.top-o.top,h=r.left-o.left,f=n.parentElement?n.scrollTop:0,A=n.parentElement?n.scrollLeft:0,g=c+f-(i-l)/2,u=h+A-(s-a)/2;n.scroll({top:g,left:u,behavior:"smooth"})},pt=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,s=o?typeof o=="string"?document.getElementById(o):o:ht(e);if(!s)return console.warn(`The scroll parent is missing for the annotation: ${i}`,{container:e}),!1;const r=t.getAnnotation(i);if(!r)return console.warn(`The annotation is missing in the store: ${i}`),!1;const{range:a}=r.target.selector[0];if(a&&!a.collapsed)return gt(t,r.target,s),!0;const l=fe(r.target,e),{range:c}=l.selector[0];return c&&!c.collapsed?(gt(t,l,s),!0):!1};var mt=Object.prototype.hasOwnProperty;function ae(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&ae(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(mt.call(e,n)&&++o&&!mt.call(t,n)||!(n in t)||!ae(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const hn=Symbol("clean");let q=[],oe=0;const Le=4,gn=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),Pe=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(o){return n.lc=t.push(o),()=>{for(let s=oe+Le;s<q.length;)q[s]===o?q.splice(s,Le):s+=Le;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){gn.epoch++;let s=!q.length;for(let r of t)q.push(r,n.value,o,i);if(s){for(oe=0;oe<q.length;oe+=Le)q[oe](q[oe+1],q[oe+2],q[oe+3]);q.length=0}},off(){},set(o){let i=n.value;i!==o&&(n.value=o,n.notify(i))},subscribe(o){let i=n.listen(o);return o(n.value),i},value:e};return process.env.NODE_ENV!=="production"&&(n[hn]=()=>{t=[],n.lc=0,n.off()}),n},pn=e=>{const t=Pe(null);return e.observe(({changes:n})=>{const o=t.get();if(o){(n.deleted||[]).some(s=>s.id===o)&&t.set(null);const i=(n.updated||[]).find(({oldValue:s})=>s.id===o);i&&t.set(i.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var $e=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))($e||{});const He={selected:[]},mn=(e,t,n)=>{const o=Pe(He);let i=t;const s=()=>{ae(o.get(),He)||o.set(He)},r=()=>{var g;return((g=o.get().selected)==null?void 0:g.length)===0},a=g=>{if(r())return!1;const u=typeof g=="string"?g:g.id;return o.get().selected.some(y=>y.id===u)},l=(g,u)=>{let y;if(Array.isArray(g)){if(y=g.map(p=>e.getAnnotation(p)).filter(Boolean),y.length<g.length){console.warn("Invalid selection: "+g.filter(p=>!y.some(d=>d.id===p)));return}}else{const p=e.getAnnotation(g);if(!p){console.warn("Invalid selection: "+g);return}y=[p]}const C=y.reduce((p,d)=>{const S=A(d);return S==="EDIT"?[...p,{id:d.id,editable:!0}]:S==="SELECT"?[...p,{id:d.id}]:p},[]);o.set({selected:C,event:u})},c=(g,u)=>{const y=Array.isArray(g)?g:[g],C=y.map(p=>e.getAnnotation(p)).filter(p=>!!p);o.set({selected:C.map(p=>{const d=u===void 0?A(p)==="EDIT":u;return{id:p.id,editable:d}})}),C.length!==y.length&&console.warn("Invalid selection",g)},h=g=>{if(r())return!1;const{selected:u}=o.get();u.some(({id:y})=>g.includes(y))&&o.set({selected:u.filter(({id:y})=>!g.includes(y))})},f=g=>{i=g,c(o.get().selected.map(({id:u})=>u))},A=g=>yn(g,i,n);return e.observe(({changes:g})=>h((g.deleted||[]).map(u=>u.id))),{get event(){const g=o.get();return g?g.event:null},get selected(){const g=o.get();return g?[...g.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:A,isEmpty:r,isSelected:a,setSelected:c,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:l}},yn=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},$=[];for(let e=0;e<256;++e)$.push((e+256).toString(16).slice(1));function bn(e,t=0){return($[e[t+0]]+$[e[t+1]]+$[e[t+2]]+$[e[t+3]]+"-"+$[e[t+4]]+$[e[t+5]]+"-"+$[e[t+6]]+$[e[t+7]]+"-"+$[e[t+8]]+$[e[t+9]]+"-"+$[e[t+10]]+$[e[t+11]]+$[e[t+12]]+$[e[t+13]]+$[e[t+14]]+$[e[t+15]]).toLowerCase()}const An=new Uint8Array(16);function wn(){return crypto.getRandomValues(An)}function yt(e,t,n){return crypto.randomUUID?crypto.randomUUID():En(e)}function En(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??wn();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,bn(i)}const je=e=>{const t=n=>{const o={...n};return n.created&&typeof n.created=="string"&&(o.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(o.updated=new Date(n.updated)),o};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},vn=(e,t,n,o)=>({id:yt(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Sn=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Cn=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Tn=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!ae(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),xn=(e,t)=>!ae(e.target,t.target),bt=(e,t)=>{const n=Sn(e,t),o=Cn(e,t),i=Tn(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:xn(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var _=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(_||{});const Ln=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>l&&l.length>0;if(!(a(i.created)||a(i.deleted))){const l=(n=i.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),c=(o=i.updated)==null?void 0:o.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!c||r==="TARGET_ONLY"&&c&&!l)return!1}}if(e.options.annotations){const r=new Set([...(i.created||[]).map(a=>a.id),...(i.deleted||[]).map(a=>a.id),...(i.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},On=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),a=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),l=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:A})=>A.id===f.id).newValue:f),...t.created||[]],c=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],h=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:A,newValue:g}=f;if(r.has(g.id)){const u=t.updated.find(y=>y.oldValue.id===g.id).newValue;return bt(A,u)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!a.has(f.id))];return{created:l,deleted:c,updated:h}},Oe=e=>{const t=e.id===void 0?yt():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},Rn=e=>e.id!==void 0,Mn=()=>{const e=new Map,t=new Map,n=[],o=(m,b={})=>{n.push({onChange:m,options:b})},i=m=>{const b=n.findIndex(w=>w.onChange==m);b>-1&&n.splice(b,1)},s=(m,b)=>{const w={origin:m,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(x=>{Ln(x,w)&&x.onChange(w)})},r=(m,b=_.LOCAL)=>{if(m.id&&e.get(m.id))throw Error(`Cannot add annotation ${m.id} - exists already`);{const w=Oe(m);e.set(w.id,w),w.bodies.forEach(x=>t.set(x.id,w.id)),s(b,{created:[w]})}},a=(m,b)=>{const w=Oe(typeof m=="string"?b:m),x=typeof m=="string"?m:m.id,U=x&&e.get(x);if(U){const I=bt(U,w);return x===w.id?e.set(x,w):(e.delete(x),e.set(w.id,w)),U.bodies.forEach(v=>t.delete(v.id)),w.bodies.forEach(v=>t.set(v.id,w.id)),I}else console.warn(`Cannot update annotation ${x} - does not exist`)},l=(m,b=_.LOCAL,w=_.LOCAL)=>{const x=Rn(b)?w:b,U=a(m,b);U&&s(x,{updated:[U]})},c=(m,b=_.LOCAL)=>{e.get(m.id)?l(m,b):r(m,b)},h=(m,b=_.LOCAL)=>{const w=m.reduce((x,U)=>{const I=a(U);return I?[...x,I]:x},[]);w.length>0&&s(b,{updated:w})},f=(m,b=_.LOCAL)=>{const w=m.map(Oe),{toAdd:x,toUpdate:U}=w.reduce((v,O)=>e.get(O.id)?{...v,toUpdate:[...v.toUpdate,O]}:{...v,toAdd:[...v.toAdd,O]},{toAdd:[],toUpdate:[]}),I=U.map(v=>a(v,b)).filter(Boolean);x.forEach(v=>{e.set(v.id,v),v.bodies.forEach(O=>t.set(O.id,v.id))}),s(b,{created:x,updated:I})},A=(m,b=_.LOCAL)=>{const w=e.get(m.annotation);if(w){const x={...w,bodies:[...w.bodies,m]};e.set(w.id,x),t.set(m.id,x.id),s(b,{updated:[{oldValue:w,newValue:x,bodiesCreated:[m]}]})}else console.warn(`Attempt to add body to missing annotation: ${m.annotation}`)},g=()=>[...e.values()],u=(m=_.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(m,{deleted:b})},y=(m,b=!0,w=_.LOCAL)=>{const x=m.map(Oe);if(b){const U=[...e.values()];e.clear(),t.clear(),x.forEach(I=>{e.set(I.id,I),I.bodies.forEach(v=>t.set(v.id,I.id))}),s(w,{created:x,deleted:U})}else{const U=m.reduce((I,v)=>{const O=v.id&&e.get(v.id);return O?[...I,O]:I},[]);if(U.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${U.map(I=>I.id).join(", ")}`);x.forEach(I=>{e.set(I.id,I),I.bodies.forEach(v=>t.set(v.id,I.id))}),s(w,{created:x})}},C=m=>{const b=typeof m=="string"?m:m.id,w=e.get(b);if(w)return e.delete(b),w.bodies.forEach(x=>t.delete(x.id)),w;console.warn(`Attempt to delete missing annotation: ${b}`)},p=(m,b=_.LOCAL)=>{const w=C(m);w&&s(b,{deleted:[w]})},d=(m,b=_.LOCAL)=>{const w=m.reduce((x,U)=>{const I=C(U);return I?[...x,I]:x},[]);w.length>0&&s(b,{deleted:w})},S=m=>{const b=e.get(m.annotation);if(b){const w=b.bodies.find(x=>x.id===m.id);if(w){t.delete(w.id);const x={...b,bodies:b.bodies.filter(U=>U.id!==m.id)};return e.set(b.id,x),{oldValue:b,newValue:x,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${m.annotation}`)},M=(m,b=_.LOCAL)=>{const w=S(m);w&&s(b,{updated:[w]})},E=(m,b=_.LOCAL)=>{const w=m.map(x=>S(x)).filter(Boolean);w.length>0&&s(b,{updated:w})},T=m=>{const b=e.get(m);return b?{...b}:void 0},N=m=>{const b=t.get(m);if(b){const w=T(b).bodies.find(x=>x.id===m);if(w)return w;console.error(`Store integrity error: body ${m} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${m}`)},k=(m,b)=>{if(m.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=e.get(m.annotation);if(w){const x=w.bodies.find(I=>I.id===m.id),U={...w,bodies:w.bodies.map(I=>I.id===x.id?b:I)};return e.set(w.id,U),x.id!==b.id&&(t.delete(x.id),t.set(b.id,U.id)),{oldValue:w,newValue:U,bodiesUpdated:[{oldBody:x,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${m.annotation}`)},D=(m,b,w=_.LOCAL)=>{const x=k(m,b);x&&s(w,{updated:[x]})},R=(m,b=_.LOCAL)=>{const w=m.map(x=>k({id:x.id,annotation:x.annotation},x)).filter(Boolean);s(b,{updated:w})},B=m=>{const b=e.get(m.annotation);if(b){const w={...b,target:{...b.target,...m}};return e.set(b.id,w),{oldValue:b,newValue:w,targetUpdated:{oldTarget:b.target,newTarget:m}}}else console.warn(`Attempt to update target on missing annotation: ${m.annotation}`)};return{addAnnotation:r,addBody:A,all:g,bulkAddAnnotations:y,bulkDeleteAnnotations:d,bulkDeleteBodies:E,bulkUpdateAnnotations:h,bulkUpdateBodies:R,bulkUpdateTargets:(m,b=_.LOCAL)=>{const w=m.map(x=>B(x)).filter(Boolean);w.length>0&&s(b,{updated:w})},bulkUpsertAnnotations:f,clear:u,deleteAnnotation:p,deleteBody:M,getAnnotation:T,getBody:N,observe:o,unobserve:i,updateAnnotation:l,updateBody:D,updateTarget:(m,b=_.LOCAL)=>{const w=B(m);w&&s(b,{updated:[w]})},upsertAnnotation:c}};let Bn=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const Nn=250,kn=(e,t)=>{const n=Bn(),o=[];let i=-1,s=!1,r=0;const a=u=>{if(!s){const{changes:y}=u,C=performance.now();if(C-r>Nn)o.splice(i+1),o.push(y),i=o.length-1;else{const p=o.length-1;o[p]=On(o[p],y)}r=C}s=!1};e.observe(a,{origin:_.LOCAL});const l=u=>u&&u.length>0&&e.bulkDeleteAnnotations(u),c=u=>u&&u.length>0&&e.bulkAddAnnotations(u,!1),h=u=>u&&u.length>0&&e.bulkUpdateAnnotations(u.map(({oldValue:y})=>y)),f=u=>u&&u.length>0&&e.bulkUpdateAnnotations(u.map(({newValue:y})=>y)),A=u=>u&&u.length>0&&e.bulkAddAnnotations(u,!1),g=u=>u&&u.length>0&&e.bulkDeleteAnnotations(u);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...o],pointer:i}),on:(u,y)=>n.on(u,y),redo:()=>{if(o.length-1>i){s=!0;const{created:u,updated:y,deleted:C}=o[i+1];c(u),f(y),g(C),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:u,updated:y,deleted:C}=o[i];l(u),h(y),A(C),n.emit("undo",o[i]),i-=1}}}},_n=()=>{const e=Pe([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},In=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:a}=e,l=new Map;let c=[],h;const f=(y,C)=>{l.has(y)?l.get(y).push(C):l.set(y,[C])},A=(y,C)=>{const p=l.get(y);if(p){const d=p.indexOf(C);d!==-1&&p.splice(d,1)}},g=(y,C,p)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(d=>{if(n){const S=Array.isArray(C)?C.map(E=>n.serialize(E)):n.serialize(C),M=p?p instanceof PointerEvent?p:n.serialize(p):void 0;d(S,M)}else d(C,p)})},1)};s.subscribe(({selected:y})=>{if(!(c.length===0&&y.length===0)){if(c.length===0&&y.length>0)c=y.map(({id:C})=>r.getAnnotation(C));else if(c.length>0&&y.length===0)c.forEach(C=>{const p=r.getAnnotation(C.id);p&&!ae(p,C)&&g("updateAnnotation",p,C)}),c=[];else{const C=new Set(c.map(d=>d.id)),p=new Set(y.map(({id:d})=>d));c.filter(d=>!p.has(d.id)).forEach(d=>{const S=r.getAnnotation(d.id);S&&!ae(S,d)&&g("updateAnnotation",S,d)}),c=[...c.filter(d=>p.has(d.id)),...y.filter(({id:d})=>!C.has(d)).map(({id:d})=>r.getAnnotation(d))]}g("selectionChanged",c)}}),i.subscribe(y=>{!h&&y?g("mouseEnterAnnotation",r.getAnnotation(y)):h&&!y?g("mouseLeaveAnnotation",r.getAnnotation(h)):h&&y&&(g("mouseLeaveAnnotation",r.getAnnotation(h)),g("mouseEnterAnnotation",r.getAnnotation(y))),h=y}),a?.subscribe(y=>g("viewportIntersect",y.map(C=>r.getAnnotation(C)))),r.observe(y=>{const{created:C,deleted:p}=y.changes;(C||[]).forEach(d=>g("createAnnotation",d)),(p||[]).forEach(d=>g("deleteAnnotation",d)),(y.changes.updated||[]).filter(d=>[...d.bodiesCreated||[],...d.bodiesDeleted||[],...d.bodiesUpdated||[]].length>0).forEach(({oldValue:d,newValue:S})=>{const M=c.find(E=>E.id===d.id)||d;c=c.map(E=>E.id===d.id?S:E),g("updateAnnotation",S,M)})},{origin:_.LOCAL}),r.observe(y=>{if(c){const C=new Set(c.map(d=>d.id)),p=(y.changes.updated||[]).filter(({newValue:d})=>C.has(d.id)).map(({newValue:d})=>d);p.length>0&&(c=c.map(d=>p.find(M=>M.id===d.id)||d))}},{origin:_.REMOTE});const u=y=>C=>{const{updated:p}=C;y?(p||[]).forEach(d=>g("updateAnnotation",d.oldValue,d.newValue)):(p||[]).forEach(d=>g("updateAnnotation",d.newValue,d.oldValue))};return t.on("undo",u(!0)),t.on("redo",u(!1)),{on:f,off:A,emit:g}},Un=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Dn=(e,t,n)=>{const{store:o,selection:i}=e,s=p=>{if(n){const{parsed:d,error:S}=n.parse(p);d?o.addAnnotation(d,_.REMOTE):console.error(S)}else o.addAnnotation(je(p),_.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=p=>{const d=o.getAnnotation(p);return n&&d?n.serialize(d):d},c=()=>n?o.all().map(n.serialize):o.all(),h=()=>{var p;const d=(((p=i.selected)==null?void 0:p.map(S=>S.id))||[]).map(S=>o.getAnnotation(S)).filter(Boolean);return n?d.map(n.serialize):d},f=(p,d=!0)=>fetch(p).then(S=>S.json()).then(S=>(g(S,d),S)),A=p=>{if(typeof p=="string"){const d=o.getAnnotation(p);if(o.deleteAnnotation(p),d)return n?n.serialize(d):d}else{const d=n?n.parse(p).parsed:p;if(d)return o.deleteAnnotation(d),p}},g=(p,d=!0)=>{if(n){const S=n.parseAll||Un(n),{parsed:M,failed:E}=S(p);E.length>0&&console.warn(`Discarded ${E.length} invalid annotations`,E),o.bulkAddAnnotations(M,d,_.REMOTE)}else o.bulkAddAnnotations(p.map(je),d,_.REMOTE)},u=(p,d)=>{p?i.setSelected(p,d):i.clear()},y=p=>{i.setUserSelectAction(p)},C=p=>{if(n){const d=n.parse(p).parsed,S=n.serialize(o.getAnnotation(d.id));return o.updateAnnotation(d),S}else{const d=o.getAnnotation(p.id);return o.updateAnnotation(je(p)),d}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:c,getHistory:t.getHistory,getSelected:h,loadAnnotations:f,redo:t.redo,removeAnnotation:A,setAnnotations:g,setSelected:u,setUserSelectAction:y,undo:t.undo,updateAnnotation:C}};let Yn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",Vn=e=>crypto.getRandomValues(new Uint8Array(e)),Kn=(e,t,n)=>{let o=256-256%e.length;if(o===256){let s=e.length-1;return(r=t)=>{if(!r)return"";let a="";for(;;){let l=n(r),c=r;for(;c--;)if(a+=e[l[c]&s],a.length>=r)return a}}}let i=Math.ceil(1.6*256*t/o);return(s=t)=>{if(!s)return"";let r="";for(;;){let a=n(i),l=i;for(;l--;)if(a[l]<o&&(r+=e[a[l]%e.length],r.length>=s))return r}}},Xn=(e,t=21)=>Kn(e,t|0,Vn),Pn=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Yn[n[e]&63];return t};const $n=()=>({isGuest:!0,id:Xn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Hn=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},At=e=>e?typeof e=="object"?{...e}:e:void 0,jn=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,modified:l,creator:c,...h}=n;return{id:o||`temp-${Hn(n)}`,annotation:t,type:i,purpose:s,value:r,creator:At(c),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...h}}),Fn=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,a={...r,created:i?.toISOString(),modified:s?.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a});Pn();const zn=(e,t)=>({parse:n=>wt(n),serialize:n=>Et(n,e,t)}),Wn=e=>e.quote!==void 0&&e.start!==void 0&&e.end!==void 0,qn=e=>{const{id:t,creator:n,created:o,modified:i,target:s}=e,r=Array.isArray(s)?s:[s];if(r.length===0)return{error:Error(`No targets found for annotation: ${e.id}`)};const a={creator:At(n),created:o?new Date(o):void 0,updated:i?new Date(i):void 0,annotation:t,selector:[],styleClass:"styleClass"in r[0]?r[0].styleClass:void 0};for(const l of r){const h=(Array.isArray(l.selector)?l.selector:[l.selector]).reduce((f,A)=>{switch(A.type){case"TextQuoteSelector":f.quote=A.exact;break;case"TextPositionSelector":f.start=A.start,f.end=A.end;break}return f},{});if(Wn(h))a.selector.push({...h,id:l.id,scope:l.scope});else{const f=[h.start?void 0:"TextPositionSelector",h.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${f.join(" and ")} for annotation: ${e.id}`)}}}return{parsed:a}},wt=e=>{const t=e.id||it(),{creator:n,created:o,modified:i,body:s,...r}=e,a=jn(s,t),l=qn(e);return"error"in l?{error:l.error}:{parsed:{...r,id:t,bodies:a,target:l.parsed}}},Et=(e,t,n)=>{const{bodies:o,target:i,...s}=e,{selector:r,creator:a,created:l,updated:c,...h}=i,f=r.map(A=>{const{id:g,quote:u,start:y,end:C,range:p}=A,d={type:"TextQuoteSelector",exact:u};if(n){const{prefix:M,suffix:E}=ut(p,n);d.prefix=M,d.suffix=E}const S={type:"TextPositionSelector",start:y,end:C};return{...h,id:g,scope:"scope"in A?A.scope:void 0,source:t,selector:[d,S]}});return{...s,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Fn(e.bodies),creator:a,created:l?.toISOString(),modified:c?.toISOString(),target:f}};let vt=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){return(this.events[e]||=[]).push(t),()=>{this.events[e]=this.events[e]?.filter(n=>t!==n)}}});const St=e=>e.addEventListener("click",t=>{!t.target.closest(se)&&!t.target.closest("a")&&t.preventDefault()}),Re=e=>({...e,type:e.type,x:e.x,y:e.y,clientX:e.clientX,clientY:e.clientY,offsetX:e.offsetX,offsetY:e.offsetY,screenX:e.screenX,screenY:e.screenY,isPrimary:e.isPrimary,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,button:e.button,buttons:e.buttons,currentTarget:e.currentTarget,target:e.target,defaultPrevented:e.defaultPrevented,detail:e.detail,eventPhase:e.eventPhase,pointerId:e.pointerId,pointerType:e.pointerType,timeStamp:e.timeStamp}),he=e=>({...e,type:e.type,key:e.key,code:e.code,location:e.location,repeat:e.repeat,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,currentTarget:e.currentTarget,target:e.target,defaultPrevented:e.defaultPrevented,detail:e.detail,timeStamp:e.timeStamp}),Me=(e,t=10)=>{let n;return((...o)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,o),t)})},Fe=(e,t,n,o)=>{const{store:i,selection:s,hover:r}=n,a=vt();let l;const c=new Map;let h;const f=$t(o),A=R=>{const{x:B,y:m}=t.getBoundingClientRect(),b=i.getAt(R.clientX-B,R.clientY-m,!1,h);b&&n.selection.evalSelectAction(b)!==$e.NONE?r.current!==b.id&&(t.classList.add("hovered"),r.set(b.id)):r.current&&(t.classList.remove("hovered"),r.set(null))};t.addEventListener("pointermove",A);const g=Me((R=!1)=>requestAnimationFrame(()=>{const B=Pt(t),{minX:m,minY:b,maxX:w,maxY:x}=B,U=h?i.getIntersecting(m,b,w,x).filter(({annotation:O})=>h(O)):i.getIntersecting(m,b,w,x),I=s.selected.map(({id:O})=>O),v=U.map(({annotation:O,rects:j})=>{const le=I.includes(O.id),J=O.id===r.current;return{annotation:O,rects:j,state:{selected:le,hovered:J}}});e.redraw(v,B,l,c,R),setTimeout(()=>{f(U.map(({annotation:O})=>O)),a.emit("onRedraw")},1)}),10),u=(R,B)=>{B?R?c.set(B,R):c.delete(B):l=R,g(!0)},y=R=>{h=R,g(!1)},C=(R,B)=>a.on(R,B),p=()=>{g()};i.observe(p);const d=s.subscribe(()=>{g()}),S=r.subscribe(()=>{g()}),M=()=>{g(!0)};document.addEventListener("scroll",M,{capture:!0,passive:!0});const E=Me(()=>{i.recalculatePositions(),g()},10);window.addEventListener("resize",E);const T=new ResizeObserver(E);T.observe(t);const N={attributes:!0,childList:!0,subtree:!0},k=new MutationObserver(Me(R=>{R.every(m=>m.target===t||t.contains(m.target))||g(!0)},150));return k.observe(document.body,N),{destroy:()=>{t.removeEventListener("pointermove",A),e.destroy(),i.unobserve(p),d(),S(),document.removeEventListener("scroll",M),window.removeEventListener("resize",E),T.disconnect(),k.disconnect()},on:C,redraw:g,setStyle:u,setFilter:y,setVisible:e.setVisible.bind(e)}};var Gn={grad:.9,turn:360,rad:360/(2*Math.PI)},ee=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},X=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=Math.pow(10,t)),Math.round(n*e)/n+0},F=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},Ct=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},Tt=function(e){return{r:F(e.r,0,255),g:F(e.g,0,255),b:F(e.b,0,255),a:F(e.a)}},ze=function(e){return{r:X(e.r),g:X(e.g),b:X(e.b),a:X(e.a,3)}},Qn=/^#([0-9a-f]{3,8})$/i,Be=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},xt=function(e){var t=e.r,n=e.g,o=e.b,i=e.a,s=Math.max(t,n,o),r=s-Math.min(t,n,o),a=r?s===t?(n-o)/r:s===n?2+(o-t)/r:4+(t-n)/r:0;return{h:60*(a<0?a+6:a),s:s?r/s*100:0,v:s/255*100,a:i}},Lt=function(e){var t=e.h,n=e.s,o=e.v,i=e.a;t=t/360*6,n/=100,o/=100;var s=Math.floor(t),r=o*(1-n),a=o*(1-(t-s)*n),l=o*(1-(1-t+s)*n),c=s%6;return{r:255*[o,a,r,r,l,o][c],g:255*[l,o,o,a,r,r][c],b:255*[r,r,l,o,o,a][c],a:i}},Ot=function(e){return{h:Ct(e.h),s:F(e.s,0,100),l:F(e.l,0,100),a:F(e.a)}},Rt=function(e){return{h:X(e.h),s:X(e.s),l:X(e.l),a:X(e.a,3)}},Mt=function(e){return Lt((n=(t=e).s,{h:t.h,s:(n*=((o=t.l)<50?o:100-o)/100)>0?2*n/(o+n)*100:0,v:o+n,a:t.a}));var t,n,o},ge=function(e){return{h:(t=xt(e)).h,s:(i=(200-(n=t.s))*(o=t.v)/100)>0&&i<200?n*o/100/(i<=100?i:200-i)*100:0,l:i/2,a:t.a};var t,n,o,i},Jn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Zn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,eo=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,to=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Bt={string:[[function(e){var t=Qn.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?X(parseInt(e[3]+e[3],16)/255,2):1}:e.length===6||e.length===8?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:e.length===8?X(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=eo.exec(e)||to.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Tt({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=Jn.exec(e)||Zn.exec(e);if(!t)return null;var n,o,i=Ot({h:(n=t[1],o=t[2],o===void 0&&(o="deg"),Number(n)*(Gn[o]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return Mt(i)},"hsl"]],object:[[function(e){var t=e.r,n=e.g,o=e.b,i=e.a,s=i===void 0?1:i;return ee(t)&&ee(n)&&ee(o)?Tt({r:Number(t),g:Number(n),b:Number(o),a:Number(s)}):null},"rgb"],[function(e){var t=e.h,n=e.s,o=e.l,i=e.a,s=i===void 0?1:i;if(!ee(t)||!ee(n)||!ee(o))return null;var r=Ot({h:Number(t),s:Number(n),l:Number(o),a:Number(s)});return Mt(r)},"hsl"],[function(e){var t=e.h,n=e.s,o=e.v,i=e.a,s=i===void 0?1:i;if(!ee(t)||!ee(n)||!ee(o))return null;var r=(function(a){return{h:Ct(a.h),s:F(a.s,0,100),v:F(a.v,0,100),a:F(a.a)}})({h:Number(t),s:Number(n),v:Number(o),a:Number(s)});return Lt(r)},"hsv"]]},Nt=function(e,t){for(var n=0;n<t.length;n++){var o=t[n][0](e);if(o)return[o,t[n][1]]}return[null,void 0]},no=function(e){return typeof e=="string"?Nt(e.trim(),Bt.string):typeof e=="object"&&e!==null?Nt(e,Bt.object):[null,void 0]},We=function(e,t){var n=ge(e);return{h:n.h,s:F(n.s+100*t,0,100),l:n.l,a:n.a}},qe=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},kt=function(e,t){var n=ge(e);return{h:n.h,s:n.s,l:F(n.l+100*t,0,100),a:n.a}},_t=(function(){function e(t){this.parsed=no(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return X(qe(this.rgba),2)},e.prototype.isDark=function(){return qe(this.rgba)<.5},e.prototype.isLight=function(){return qe(this.rgba)>=.5},e.prototype.toHex=function(){return t=ze(this.rgba),n=t.r,o=t.g,i=t.b,r=(s=t.a)<1?Be(X(255*s)):"","#"+Be(n)+Be(o)+Be(i)+r;var t,n,o,i,s,r},e.prototype.toRgb=function(){return ze(this.rgba)},e.prototype.toRgbString=function(){return t=ze(this.rgba),n=t.r,o=t.g,i=t.b,(s=t.a)<1?"rgba("+n+", "+o+", "+i+", "+s+")":"rgb("+n+", "+o+", "+i+")";var t,n,o,i,s},e.prototype.toHsl=function(){return Rt(ge(this.rgba))},e.prototype.toHslString=function(){return t=Rt(ge(this.rgba)),n=t.h,o=t.s,i=t.l,(s=t.a)<1?"hsla("+n+", "+o+"%, "+i+"%, "+s+")":"hsl("+n+", "+o+"%, "+i+"%)";var t,n,o,i,s},e.prototype.toHsv=function(){return t=xt(this.rgba),{h:X(t.h),s:X(t.s),v:X(t.v),a:X(t.a,3)};var t},e.prototype.invert=function(){return z({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},e.prototype.saturate=function(t){return t===void 0&&(t=.1),z(We(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),z(We(this.rgba,-t))},e.prototype.grayscale=function(){return z(We(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),z(kt(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),z(kt(this.rgba,-t))},e.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},e.prototype.alpha=function(t){return typeof t=="number"?z({r:(n=this.rgba).r,g:n.g,b:n.b,a:t}):X(this.rgba.a,3);var n},e.prototype.hue=function(t){var n=ge(this.rgba);return typeof t=="number"?z({h:t,s:n.s,l:n.l,a:n.a}):X(n.h)},e.prototype.isEqual=function(t){return this.toHex()===z(t).toHex()},e})(),z=function(e){return e instanceof _t?e:new _t(e)};const te={fill:"rgb(0, 128, 255)",fillOpacity:.18},Ne={fill:"rgb(0, 128, 255)",fillOpacity:.45},It=e=>e?.fillOpacity!==void 0?z(e?.fill||te.fill).alpha(e.fillOpacity).toHex():e?.fill?e.fill:z(te.fill).alpha(te.fillOpacity).toHex(),Ge=(e,t,n)=>t?typeof t=="function"?t(e.annotation,e.state,n)||(e.state?.selected?Ne:te):t:e.state?.selected?Ne:te;var Ut=Object.prototype.hasOwnProperty;function Qe(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&Qe(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Ut.call(e,n)&&++o&&!Ut.call(t,n)||!(n in t)||!Qe(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Dt=(e,t)=>{const n=(s,r)=>s.x<=r.x+r.width&&s.x+s.width>=r.x&&s.y<=r.y+r.height&&s.y+s.height>=r.y,o=s=>s.rects.reduce((r,a)=>r+a.width,0),i=t.filter(({rects:s})=>s.some(r=>n(e,r)));return i.sort((s,r)=>o(r)-o(s)),i.findIndex(s=>s.rects.includes(e))},Yt=e=>{const t=[],n=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_TEXT);let o;for(;o=n.nextNode();)e.intersectsNode(o)&&t.push(o);if(t.length<2)return Array.from(e.getClientRects());{const i=t[0],s=t[t.length-1],r=document.createRange();if(r.selectNode(i),e.startContainer.nodeType===Node.TEXT_NODE)r.setStart(i,e.startOffset);else{const c=e.startContainer.childNodes[e.startOffset];c?r.setStartBefore(c):r.setStartAfter(e.startContainer)}const a=document.createRange();if(a.selectNode(s),e.endContainer.nodeType===Node.TEXT_NODE)a.setEnd(s,e.endOffset);else{const c=e.endContainer.childNodes[e.endOffset];c?a.setEndBefore(c):a.setEndAfter(e.endContainer)}const l=c=>{const h=document.createRange();return h.selectNode(c),Array.from(h.getClientRects())};return[...Array.from(r.getClientRects()),...t.slice(1,-1).flatMap(l),...Array.from(a.getClientRects())]}},oo=(e,t,n,o)=>{const i=a=>Math.round(a*10)/10,s={top:i(e.top),bottom:i(e.bottom),left:i(e.left),right:i(e.right)},r={top:i(t.top),bottom:i(t.bottom),left:i(t.left),right:i(t.right)};if(Math.abs(s.top-r.top)<o&&Math.abs(s.bottom-r.bottom)<o){if(Math.abs(s.left-r.right)<n||Math.abs(s.right-r.left)<n)return"inline-adjacent";if(s.left>=r.left&&s.right<=r.right)return"inline-is-contained";if(s.left<=r.left&&s.right>=r.right)return"inline-contains"}else if(s.top<=r.top&&s.bottom>=r.bottom){if(s.left<=r.left&&s.right>=r.right)return"block-contains"}else if(s.top>=r.top&&s.bottom<=r.bottom&&s.left>=r.left&&s.right<=r.right)return"block-is-contained"},io=(e,t)=>{const n=Math.min(e.left,t.left),o=Math.max(e.right,t.right),i=Math.min(e.top,t.top),s=Math.max(e.bottom,t.bottom);return new DOMRect(n,i,o-n,s-i)},Vt=(e,t=.5,n=.5)=>e.reduce((o,i)=>{if(i.width===0||i.height===0)return o;let s=[...o],r=!1;for(const a of o){const l=oo(i,a,t,n);if(l==="inline-adjacent"){s=s.map(c=>c===a?io(i,a):c),r=!0;break}else if(l==="inline-contains"){s=s.map(c=>c===a?i:c),r=!0;break}else if(l==="inline-is-contained"){r=!0;break}else if(l==="block-contains"||l==="block-is-contained"){i.width<a.width&&(s=s.map(c=>c===a?i:c)),i.width===a.width&&i.height<a.width&&(s=s.map(c=>c===a?i:c)),r=!0;break}}return r?s:[...s,i]},[]),so=e=>({length:e.length,item:t=>e[t],[Symbol.iterator]:function*(){for(let t=0;t<this.length;t++)yield this.item(t)}}),Kt=(e,t)=>{const{left:n,top:o,right:i,bottom:s}=e;return new DOMRect(n-t.left,o-t.top,i-n,s-o)},ro=(e,t)=>{const{left:n,top:o,right:i,bottom:s}=e;return new DOMRect(n+t.left,o+t.top,i-n,s-o)},ao=e=>{e.classList.add("r6o-annotatable");const t=document.createElement("div");t.className="r6o-span-highlight-layer",e.appendChild(t);let n=[];return{destroy:()=>{t.remove()},redraw:(r,a,l,c,h)=>{if(!(!Qe(n,r)||h))return;t.innerHTML="",[...r].sort((u,y)=>{const{annotation:{target:{created:C}}}=u,{annotation:{target:{created:p}}}=y;return C&&p?C.getTime()-p.getTime():0}).forEach(u=>{const y=c.get(u.annotation.id)||l;u.rects.map(C=>{const p=Dt(C,r),d=Ge(u,y,p),S=document.createElement("span");S.className="r6o-annotation",S.dataset.annotation=u.annotation.id,S.style.left=`${C.x}px`,S.style.top=`${C.y}px`,S.style.width=`${C.width}px`,S.style.height=`${C.height}px`,S.style.backgroundColor=It(d),d.underlineStyle&&(S.style.borderStyle=d.underlineStyle),d.underlineColor&&(S.style.borderColor=d.underlineColor),d.underlineThickness&&(S.style.borderBottomWidth=`${d.underlineThickness}px`),d.underlineOffset&&(S.style.paddingBottom=`${d.underlineOffset}px`),t.appendChild(S)})}),n=r},setVisible:r=>{r?t.classList.remove("hidden"):t.classList.add("hidden")}}},Xt=(e,t,n)=>Fe(ao(e),e,t,n),Pt=e=>{const{top:t,left:n}=e.getBoundingClientRect(),{innerWidth:o,innerHeight:i}=window,s=-n,r=-t,a=o-n,l=i-t;return{top:t,left:n,minX:s,minY:r,maxX:a,maxY:l}},$t=e=>{let t=new Set;return o=>{const i=o.map(s=>s.id);(t.size!==i.length||i.some(s=>!t.has(s)))&&e.set(i),t=new Set(i)}};function Ht(e,t,n=0,o=e.length-1,i=lo){for(;o>n;){if(o-n>600){const l=o-n+1,c=t-n+1,h=Math.log(l),f=.5*Math.exp(2*h/3),A=.5*Math.sqrt(h*f*(l-f)/l)*(c-l/2<0?-1:1),g=Math.max(n,Math.floor(t-c*f/l+A)),u=Math.min(o,Math.floor(t+(l-c)*f/l+A));Ht(e,t,g,u,i)}const s=e[t];let r=n,a=o;for(pe(e,n,t),i(e[o],s)>0&&pe(e,n,o);r<a;){for(pe(e,r,a),r++,a--;i(e[r],s)<0;)r++;for(;i(e[a],s)>0;)a--}i(e[n],s)===0?pe(e,n,a):(a++,pe(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function pe(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function lo(e,t){return e<t?-1:e>t?1:0}class co{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!_e(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const a=n.children[r],l=n.leaf?i(a):a;_e(t,l)&&(n.leaf?o.push(a):Ze(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!_e(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(_e(t,r)){if(n.leaf||Ze(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=de([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let a,l,c;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],a=r.pop(),c=!0),o.leaf){const h=uo(t,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!c&&!o.leaf&&Ze(o,i)?(s.push(o),r.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],c=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,a;if(s<=r)return a=de(t.slice(n,o+1)),ce(a,this.toBBox),a;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),a=de([]),a.leaf=!1,a.height=i;const l=Math.ceil(s/r),c=l*Math.ceil(Math.sqrt(r));jt(t,n,o,c,this.compareMinX);for(let h=n;h<=o;h+=c){const f=Math.min(h+c-1,o);jt(t,h,f,l,this.compareMinY);for(let A=h;A<=f;A+=l){const g=Math.min(A+l-1,f);a.children.push(this._build(t,A,g,i-1))}}return ce(a,this.toBBox),a}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,a;for(let l=0;l<n.children.length;l++){const c=n.children[l],h=Je(c),f=go(t,c)-h;f<r?(r=f,s=h<s?h:s,a=c):f===r&&h<s&&(s=h,a=c)}n=a||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),ye(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),a=de(o.children.splice(r,o.children.length-r));a.height=o.height,a.leaf=o.leaf,ce(o,this.toBBox),ce(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(o,a)}_splitRoot(t,n){this.data=de([t,n]),this.data.height=t.height+1,this.data.leaf=!1,ce(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let a=n;a<=o-n;a++){const l=me(t,0,a,this.toBBox),c=me(t,a,o,this.toBBox),h=po(l,c),f=Je(l)+Je(c);h<s?(s=h,i=a,r=f<r?f:r):h===s&&f<r&&(r=f,i=a)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:fo,s=t.leaf?this.compareMinY:ho,r=this._allDistMargin(t,n,o,i),a=this._allDistMargin(t,n,o,s);r<a&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=me(t,0,n,s),a=me(t,o-n,o,s);let l=ke(r)+ke(a);for(let c=n;c<o-n;c++){const h=t.children[c];ye(r,t.leaf?s(h):h),l+=ke(r)}for(let c=o-n-1;c>=n;c--){const h=t.children[c];ye(a,t.leaf?s(h):h),l+=ke(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)ye(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():ce(t[n],this.toBBox)}}function uo(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function ce(e,t){me(e,0,e.children.length,t,e)}function me(e,t,n,o,i){i||(i=de(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];ye(i,e.leaf?o(r):r)}return i}function ye(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function fo(e,t){return e.minX-t.minX}function ho(e,t){return e.minY-t.minY}function Je(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ke(e){return e.maxX-e.minX+(e.maxY-e.minY)}function go(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function po(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function Ze(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function _e(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function de(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function jt(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;Ht(e,r,t,n,i),s.push(t,r,r,n)}}const mo=(e,t,n,o)=>{const i=new co,s=new Map,r=vt(),a=(E,T)=>{const N=E.selector.flatMap(D=>{const R=Q([D])?D.range:Xe(D,t).range;return Yt(R)}),k=Vt(N,n,o).map(D=>Kt(D,T));return k.map(D=>{const{x:R,y:B,width:m,height:b}=D;return{minX:R,minY:B,maxX:R+m,maxY:B+b,annotation:{id:E.annotation,rects:k}}})},l=()=>[...s.values()],c=()=>{i.clear(),s.clear()},h=E=>{const T=a(E,t.getBoundingClientRect());T.length!==0&&(T.forEach(N=>i.insert(N)),s.set(E.annotation,T))},f=E=>{const T=s.get(E.annotation);T&&(T.forEach(N=>i.remove(N)),s.delete(E.annotation))},A=E=>{f(E),h(E)},g=(E,T=!0)=>{T&&c();const N=t.getBoundingClientRect(),k=E.map(R=>({target:R,rects:a(R,N)}));k.forEach(({target:R,rects:B})=>{B.length>0&&s.set(R.annotation,B)});const D=k.flatMap(({rects:R})=>R);i.load(D)},u=(E,T,N=!1)=>{const k=i.search({minX:E,minY:T,maxX:E,maxY:T}),D=R=>R.annotation.rects.reduce((B,m)=>B+m.width*m.height,0);return k.length>0?(k.sort((R,B)=>D(R)-D(B)),N?k.map(R=>R.annotation.id):[k[0].annotation.id]):[]},y=E=>{const T=C(E);if(T.length===0)return;let N=T[0].left,k=T[0].top,D=T[0].right,R=T[0].bottom;for(let B=1;B<T.length;B++){const m=T[B];N=Math.min(N,m.left),k=Math.min(k,m.top),D=Math.max(D,m.right),R=Math.max(R,m.bottom)}return new DOMRect(N,k,D-N,R-k)},C=E=>{const T=s.get(E);return T?T[0].annotation.rects:[]};return{all:l,clear:c,getAt:u,getAnnotationBounds:y,getAnnotationRects:C,getIntersecting:(E,T,N,k)=>{const D=i.search({minX:E,minY:T,maxX:N,maxY:k}),R=new Set(D.map(B=>B.annotation.id));return Array.from(R).map(B=>({annotation:e.getAnnotation(B),rects:C(B)})).filter(B=>!!B.annotation)},insert:h,recalculate:()=>{g(e.all().map(E=>E.target),!0),r.emit("recalculate")},remove:f,set:g,size:()=>i.all().length,update:A,on:(E,T)=>r.on(E,T)}},Ft=(e,t)=>{const n=Mn(),o=mo(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance),i=mn(n,t.userSelectAction,t.adapter),s=pn(n),r=_n(),a=(d,S=_.LOCAL)=>{const M=xe(d,e),E=Q(M.target.selector);return E&&n.addAnnotation(M,S),E},l=(d,S=!0,M=_.LOCAL)=>{const E=d.map(N=>xe(N,e)),T=E.filter(N=>!Q(N.target.selector));return n.bulkAddAnnotations(E,S,M),T},c=(d,S=_.LOCAL)=>{const M=d.map(T=>xe(T,e)),E=M.filter(T=>!Q(T.target.selector));return M.forEach(T=>{n.getAnnotation(T.id)?n.updateAnnotation(T,S):n.addAnnotation(T,S)}),E},h=(d,S=_.LOCAL)=>{const M=fe(d,e);n.updateTarget(M,S)},f=(d,S=_.LOCAL)=>{const M=d.map(E=>fe(E,e));n.bulkUpdateTargets(M,S)};function A(d,S,M,E){const T=M||!!E,N=o.getAt(d,S,T).map(D=>n.getAnnotation(D)),k=E?N.filter(E):N;if(k.length!==0)return M?k:k[0]}const g=d=>o.getAnnotationRects(d).length>0?o.getAnnotationBounds(d):void 0,u=(d,S,M,E)=>o.getIntersecting(d,S,M,E),y=d=>o.getAnnotationRects(d),C=()=>o.recalculate(),p=d=>o.on("recalculate",d);return n.observe(({changes:d})=>{const S=(d.deleted||[]).filter(T=>Q(T.target.selector)),M=(d.created||[]).filter(T=>Q(T.target.selector)),E=(d.updated||[]).filter(T=>Q(T.newValue.target.selector));S?.length>0&&S.forEach(T=>o.remove(T.target)),M.length>0&&o.set(M.map(T=>T.target),!1),E?.length>0&&E.forEach(({newValue:T})=>o.update(T.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotations:l,bulkUpdateTargets:f,bulkUpsertAnnotations:c,getAnnotationBounds:g,getAnnotationRects:y,getIntersecting:u,getAt:A,recalculatePositions:C,onRecalculatePositions:p,updateTarget:h},selection:i,hover:s,viewport:r}};function yo(e,t=100,n={}){if(typeof e!="function")throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");if(typeof n=="boolean")throw new TypeError("The `options` parameter must be an object, not a boolean. Use `{immediate: true}` instead.");const{immediate:o}=n;let i,s,r,a,l;function c(){const A=i,g=s;return i=void 0,s=void 0,l=e.apply(A,g),l}function h(){const A=Date.now()-a;A<t&&A>=0?r=setTimeout(h,t-A):(r=void 0,o||(l=c()))}const f=function(...A){if(i&&this!==i&&Object.getPrototypeOf(this)===Object.getPrototypeOf(i))throw new Error("Debounced method called with different contexts of the same prototype.");i=this,s=A,a=Date.now();const g=o&&!r;if(r||(r=setTimeout(h,t)),g)return l=c(),l};return Object.defineProperty(f,"isPending",{get(){return r!==void 0}}),f.clear=()=>{r&&(clearTimeout(r),r=void 0,i=void 0,s=void 0)},f.flush=()=>{r&&f.trigger()},f.trigger=()=>{l=c(),f.clear()},f}const et=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function tt(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),n)}function be(e,t,n,o){e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent("on".concat(t),n)}function zt(e,t){const n=t.slice(0,t.length-1);for(let o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}function Wt(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function bo(e,t){const n=e.length>=t.length?e:t,o=e.length>=t.length?t:e;let i=!0;for(let s=0;s<n.length;s++)o.indexOf(n[s])===-1&&(i=!1);return i}const Ae={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,arrowup:38,arrowdown:40,arrowleft:37,arrowright:39,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":et?173:189,"=":et?61:187,";":et?59:186,"'":222,"{":219,"}":221,"[":219,"]":221,"\\":220},G={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,meta:91,command:91},we={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},H={16:!1,18:!1,17:!1,91:!1},V={};for(let e=1;e<20;e++)Ae["f".concat(e)]=111+e;let Y=[],Ee=null,qt="all";const ne=new Map,ue=e=>Ae[e.toLowerCase()]||G[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),Ao=e=>Object.keys(Ae).find(t=>Ae[t]===e),wo=e=>Object.keys(G).find(t=>G[t]===e);function Gt(e){qt=e||"all"}function ve(){return qt||"all"}function Eo(){return Y.slice(0)}function vo(){return Y.map(e=>Ao(e)||wo(e)||String.fromCharCode(e))}function So(){const e=[];return Object.keys(V).forEach(t=>{V[t].forEach(n=>{let{key:o,scope:i,mods:s,shortcut:r}=n;e.push({scope:i,shortcut:r,mods:s,keys:o.split("+").map(a=>ue(a))})})}),e}function Co(e){const t=e.target||e.srcElement,{tagName:n}=t;let o=!0;const i=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(i||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(o=!1),o}function To(e){return typeof e=="string"&&(e=ue(e)),Y.indexOf(e)!==-1}function xo(e,t){let n,o;e||(e=ve());for(const i in V)if(Object.prototype.hasOwnProperty.call(V,i))for(n=V[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(r=>{let{element:a}=r;return nt(a)}):o++;ve()===e&&Gt(t||"all")}function Lo(e){let t=e.keyCode||e.which||e.charCode;e.key&&e.key.toLowerCase()==="capslock"&&(t=ue(e.key));const n=Y.indexOf(t);if(n>=0&&Y.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&Y.splice(0,Y.length),(t===93||t===224)&&(t=91),t in H){H[t]=!1;for(const o in G)G[o]===t&&(W[o]=!1)}}function Qt(e){if(typeof e>"u")Object.keys(V).forEach(i=>{Array.isArray(V[i])&&V[i].forEach(s=>Ie(s)),delete V[i]}),nt(null);else if(Array.isArray(e))e.forEach(i=>{i.key&&Ie(i)});else if(typeof e=="object")e.key&&Ie(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];let[i,s]=n;typeof i=="function"&&(s=i,i=""),Ie({key:e,scope:i,method:s,splitKey:"+"})}}const Ie=e=>{let{key:t,scope:n,method:o,splitKey:i="+"}=e;Wt(t).forEach(r=>{const a=r.split(i),l=a.length,c=a[l-1],h=c==="*"?"*":ue(c);if(!V[h])return;n||(n=ve());const f=l>1?zt(G,a):[],A=[];V[h]=V[h].filter(g=>{const y=(o?g.method===o:!0)&&g.scope===n&&bo(g.mods,f);return y&&A.push(g.element),!y}),A.forEach(g=>nt(g))})};function Jt(e,t,n,o){if(t.element!==o)return;let i;if(t.scope===n||t.scope==="all"){i=t.mods.length>0;for(const s in H)Object.prototype.hasOwnProperty.call(H,s)&&(!H[s]&&t.mods.indexOf(+s)>-1||H[s]&&t.mods.indexOf(+s)===-1)&&(i=!1);(t.mods.length===0&&!H[16]&&!H[18]&&!H[17]&&!H[91]||i||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(Y),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function Zt(e,t){const n=V["*"];let o=e.keyCode||e.which||e.charCode;if(e.key&&e.key.toLowerCase()==="capslock"||!W.filter.call(this,e))return;if((o===93||o===224)&&(o=91),Y.indexOf(o)===-1&&o!==229&&Y.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=we[a];e[a]&&Y.indexOf(l)===-1?Y.push(l):!e[a]&&Y.indexOf(l)>-1?Y.splice(Y.indexOf(l),1):a==="metaKey"&&e[a]&&(Y=Y.filter(c=>c in we||c===o))}),o in H){H[o]=!0;for(const a in G)if(Object.prototype.hasOwnProperty.call(G,a)){const l=we[G[a]];W[a]=e[l]}if(!n)return}for(const a in H)Object.prototype.hasOwnProperty.call(H,a)&&(H[a]=e[we[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(Y.indexOf(17)===-1&&Y.push(17),Y.indexOf(18)===-1&&Y.push(18),H[17]=!0,H[18]=!0);const i=ve();if(n)for(let a=0;a<n.length;a++)n[a].scope===i&&(e.type==="keydown"&&n[a].keydown||e.type==="keyup"&&n[a].keyup)&&Jt(e,n[a],i,t);if(!(o in V))return;const s=V[o],r=s.length;for(let a=0;a<r;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,h=l.key.split(c),f=[];for(let A=0;A<h.length;A++)f.push(ue(h[A]));f.sort().join("")===Y.sort().join("")&&Jt(e,l,i,t)}}function W(e,t,n){Y=[];const o=Wt(e);let i=[],s="all",r=document,a=0,l=!1,c=!0,h="+",f=!1,A=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(s=t.scope),t.element&&(r=t.element),t.keyup&&(l=t.keyup),t.keydown!==void 0&&(c=t.keydown),t.capture!==void 0&&(f=t.capture),typeof t.splitKey=="string"&&(h=t.splitKey),t.single===!0&&(A=!0)),typeof t=="string"&&(s=t),A&&Qt(e,s);a<o.length;a++)e=o[a].split(h),i=[],e.length>1&&(i=zt(G,e)),e=e[e.length-1],e=e==="*"?"*":ue(e),e in V||(V[e]=[]),V[e].push({keyup:l,keydown:c,scope:s,mods:i,shortcut:o[a],method:n,key:o[a],splitKey:h,element:r});if(typeof r<"u"&&window){if(!ne.has(r)){const g=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return Zt(y,r)},u=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;Zt(y,r),Lo(y)};ne.set(r,{keydownListener:g,keyupListenr:u,capture:f}),tt(r,"keydown",g,f),tt(r,"keyup",u,f)}if(!Ee){const g=()=>{Y=[]};Ee={listener:g,capture:f},tt(window,"focus",g,f)}}}function Oo(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(V).forEach(n=>{V[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method()})})}function nt(e){const t=Object.values(V).flat();if(t.findIndex(o=>{let{element:i}=o;return i===e})<0){const{keydownListener:o,keyupListenr:i,capture:s}=ne.get(e)||{};o&&i&&(be(e,"keyup",i,s),be(e,"keydown",o,s),ne.delete(e))}if((t.length<=0||ne.size<=0)&&(Object.keys(ne).forEach(i=>{const{keydownListener:s,keyupListenr:r,capture:a}=ne.get(i)||{};s&&r&&(be(i,"keyup",r,a),be(i,"keydown",s,a),ne.delete(i))}),ne.clear(),Object.keys(V).forEach(i=>delete V[i]),Ee)){const{listener:i,capture:s}=Ee;be(window,"focus",i,s),Ee=null}}const ot={getPressedKeyString:vo,setScope:Gt,getScope:ve,deleteScope:xo,getPressedKeyCodes:Eo,getAllKeyCodes:So,isPressed:To,filter:Co,trigger:Oo,unbind:Qt,keyMap:Ae,modifier:G,modifierMap:we};for(const e in ot)Object.prototype.hasOwnProperty.call(ot,e)&&(W[e]=ot[e]);if(typeof window<"u"){const e=window.hotkeys;W.noConflict=t=>(t&&window.hotkeys===W&&(window.hotkeys=e),W),window.hotkeys=W}async function Ro(e,t,n=(()=>!1)){do{if(await e(),await n())break;const o=t;await new Promise((i=>setTimeout(i,Math.max(0,o))))}while(!await n())}const en=300,tn=["up","down","left","right"],nn=De?"⌘+a":"ctrl+a",Mo=[...tn.map(e=>`shift+${e}`),nn],on=(e,t,n,o)=>{const{store:i,selection:s}=t;let r;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:c,dismissOnNotAnnotatable:h="NEVER"}=o;let f,A=a,g="CREATE_NEW",u,y,C,p;const d=v=>{A=v,k.clear(),v||(y=void 0,u=void 0,C=void 0,p=void 0)},S=v=>g=v||"CREATE_NEW",M=v=>f=v,E=v=>r=v,T=v=>{if(g==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const O=v;return De?O.metaKey:O.ctrlKey}else return!1},N=()=>{if(!A||C===!1)return;const{selected:v}=s;if((T(p)||g==="REPLACE_CURRENT")&&v.length===1&&v[0].editable){const j=i.getAnnotation(v[0].id);if(j?.target){y=j.target,u={annotation:j.id,selector:[],created:y.created,creator:y.creator,updated:new Date,updatedBy:r};return}}y=void 0,u={annotation:it(),selector:[],created:new Date,creator:r}},k=yo(v=>{if(!A)return;const O=document.getSelection();if(!O?.anchorNode)return;const j=Array.from(Array(O.rangeCount).keys()).map(P=>O.getRangeAt(P));if(j.every(P=>!Ve(e,P))){u=void 0;return}const le=v.timeStamp-(p?.timeStamp||v.timeStamp);if(p?.type==="pointerdown"&&(le<1e3&&!u||O.isCollapsed&&le<en)&&N(),!u&&(N(),!u))return;if(O.isCollapsed){i.getAnnotation(u.annotation)&&!(T(p)||g==="REPLACE_CURRENT")&&(s.clear(),i.deleteAnnotation(u.annotation));return}const J=j.map(P=>ct(P,e));if(J.every(P=>st(P)))return;const Z=J.flatMap(P=>lt(e,P.cloneRange()));if(!(Z.length>0&&!u||Z.length!==u.selector.length||Z.some((P,Se)=>P.toString()!==u.selector[Se]?.quote)))return;const Ue=T(p)&&y?rt([...y.selector.map(P=>P.range),...Z]):Z;u={...u,selector:Ue.map(P=>ft(P,e,l)),updated:new Date},!(T(p)||g==="REPLACE_CURRENT")&&(i.getAnnotation(u.annotation)?i.updateTarget(u,_.LOCAL):s.clear())},10),D=v=>{p=Re(v),C=p.button===0},R=async v=>{if(!C)return;const O=Re(v),j=()=>{const{x:J,y:Z}=e.getBoundingClientRect();if(re(e,O.target)){(typeof h=="function"?h(O,e):h==="ALWAYS")&&s.clear();return}const ie=O.target instanceof Node&&e.contains(O.target)&&i.getAt(O.clientX-J,O.clientY-Z,c==="all",f);if(ie){const{selected:Ue}=s,P=new Set(Ue.map(Ce=>Ce.id)),Se=Array.isArray(ie)?ie.map(Ce=>Ce.id):[ie.id];(P.size!==Se.length||!Se.every(Ce=>P.has(Ce)))&&(n.emit("clickAnnotation",ie),s.userSelect(Se,O))}else s.clear()};if(O.timeStamp-p.timeStamp<en){await B();const J=document.getSelection(),Z=re(e,p.target),ie=re(e,O.target);if(J?.isCollapsed||Z&&ie){u=void 0,j();return}}u&&u.selector.length>0&&(U(),s.userSelect(u.annotation,O))},B=async()=>{const v=document.getSelection();let O=!1,j=v?.isCollapsed;const le=()=>j||O,J=1;return setTimeout(()=>O=!0,50),Ro(()=>j=v?.isCollapsed,J,le)},m=v=>{document.getSelection()?.isCollapsed||((!u||u.selector.length===0)&&k(v),u&&(U(),s.userSelect(u.annotation,Re(v))))},b=v=>{A&&(v.repeat||v.target instanceof Node&&re(e,v.target)&&v.target!==document.body||v.key==="Shift"&&u&&(document.getSelection().isCollapsed||(U(),s.userSelect(u.annotation,he(v)))))},w=v=>{const O=()=>setTimeout(()=>{u?.selector.length>0&&(s.clear(),i.addAnnotation({id:u.annotation,bodies:[],target:u}),s.userSelect(u.annotation,he(v))),document.removeEventListener("selectionchange",O)},100);document.addEventListener("selectionchange",O),N()};W(Mo.join(","),{element:e,keydown:!0,keyup:!1},v=>{v.repeat||(p=he(v))}),W(nn,{keydown:!0,keyup:!1},v=>{p=he(v),w(v)});const x=v=>{v.repeat||v.target instanceof Node&&re(e,v.target)&&v.target!==document.body||(u=void 0,s.clear())};W(tn.join(","),{keydown:!0,keyup:!1},x);const U=()=>{const v=i.getAnnotation(u.annotation);if(!v)i.addAnnotation({id:u.annotation,bodies:[],target:u});else{const{target:{updated:O}}=v,{updated:j}=u;(!O||!j||O<j)&&i.updateTarget(u)}};return document.addEventListener("pointerdown",D),document.addEventListener("pointerup",R),document.addEventListener("contextmenu",m),document.addEventListener("keyup",b),e.addEventListener("selectstart",N),document.addEventListener("selectionchange",k),{destroy:()=>{u=void 0,y=void 0,C=void 0,p=void 0,k.clear(),document.removeEventListener("pointerdown",D),document.removeEventListener("pointerup",R),document.removeEventListener("contextmenu",m),document.removeEventListener("keyup",b),e.removeEventListener("selectstart",N),document.removeEventListener("selectionchange",k),W.unbind()},setFilter:M,setUser:E,setAnnotatingEnabled:d,setAnnotatingMode:S}},Bo=e=>[`background-color:${z(e?.fill||te.fill).alpha(e?.fillOpacity===void 0?te.fillOpacity:e.fillOpacity).toHex()}`,e?.underlineThickness?"text-decoration:underline":void 0,e?.underlineColor?`text-decoration-color:${e.underlineColor}`:void 0,e?.underlineOffset?`text-underline-offset:${e.underlineOffset}px`:void 0,e?.underlineThickness?`text-decoration-thickness:${e.underlineThickness}px`:void 0].filter(Boolean).join(";"),No=()=>{const e=document.createElement("style");document.getElementsByTagName("head")[0].appendChild(e);let t=new Set;return{destroy:()=>{CSS.highlights.clear(),e.remove()},setVisible:s=>{console.log("setVisible not implemented on CSS Custom Highlights renderer")},redraw:(s,r,a,l,c)=>{const h=new Set(s.map(A=>A.annotation.id));Array.from(t).filter(A=>!h.has(A));const f=s.map(A=>{a?typeof a=="function"&&a(A.annotation,A.state):A.state?.selected;const g=Ge(A,a);return`::highlight(_${A.annotation.id}) { ${Bo(g)} }`});e.innerHTML=f.join(`
|
|
2
|
+
`),CSS.highlights.clear(),s.forEach(({annotation:A})=>{const g=A.target.selector.map(y=>y.range),u=new Highlight(...g);CSS.highlights.set(`_${A.id}`,u)}),t=h}}},ko=(e,t,n)=>Fe(No(),e,t,n),sn=(e,t)=>({...e,annotatingEnabled:e.annotatingEnabled??t.annotatingEnabled,user:e.user||t.user}),rn="SPANS",_o=(e,t={})=>{St(e),at(e);const n=sn(t,{annotatingEnabled:!0,user:$n()}),o=Ft(e,n),{selection:i,viewport:s}=o,r=o.store,a=kn(r),l=In(o,a,n.adapter);let c=n.user;const h=typeof n.renderer!="function"?n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":rn:n.renderer||rn:null,f=h===null?n.renderer(e,o,s):h==="SPANS"?Xt(e,o,s):h==="CSS_HIGHLIGHTS"?ko(e,o,s):void 0;if(!f)throw`Unknown renderer implementation: ${n.renderer}`;console.debug(h?`Using ${h} renderer`:"Using custom renderer implementation"),n.style&&f.setStyle(n.style);const A=on(e,o,l,n);A.setUser(c);const g=Dn(o,a,n.adapter),u=()=>c,y=E=>{A.setAnnotatingEnabled(E===void 0?!0:E)},C=E=>{A.setAnnotatingMode(E)},p=E=>{f.setFilter(E),A.setFilter(E)},d=E=>{c=E,A.setUser(E)},S=E=>{E?i.setSelected(E):i.clear()};return{...g,destroy:()=>{f.destroy(),A.destroy(),a.destroy()},element:e,getUser:u,renderer:f,setAnnotatingEnabled:y,setAnnotatingMode:C,setFilter:p,setStyle:f.setStyle.bind(f),setUser:d,setSelected:S,setVisible:f.setVisible.bind(f),on:l.on,off:l.off,scrollIntoView:pt(e,r),state:o}};L.DEFAULT_SELECTED_STYLE=Ne,L.DEFAULT_STYLE=te,L.NOT_ANNOTATABLE_CLASS=Ye,L.NOT_ANNOTATABLE_SELECTOR=se,L.Origin=_,L.UserSelectAction=$e,L.W3CTextFormat=zn,L.cancelSingleClickEvents=St,L.cloneKeyboardEvent=he,L.clonePointerEvent=Re,L.computeStyle=Ge,L.computeZIndex=Dt,L.createBody=vn,L.createRenderer=Fe,L.createSelectionHandler=on,L.createSpansRenderer=Xt,L.createTextAnnotator=_o,L.createTextAnnotatorState=Ft,L.debounce=Me,L.fillDefaults=sn,L.getBackgroundColor=It,L.getHighlightClientRects=Yt,L.getQuoteContext=ut,L.getRangeAnnotatableContents=Te,L.getViewportBounds=Pt,L.isMac=De,L.isNodeWhitespaceOrEmpty=un,L.isNotAnnotatable=re,L.isRangeAnnotatable=Ve,L.isRangeWhitespaceOrEmpty=st,L.isRevived=Q,L.mergeClientRects=Vt,L.mergeRanges=rt,L.parseW3CTextAnnotation=wt,L.programmaticallyFocusable=at,L.rangeToSelector=ft,L.reviveAnnotation=xe,L.reviveSelector=Xe,L.reviveTarget=fe,L.scrollIntoView=pt,L.serializeW3CTextAnnotation=Et,L.splitAnnotatableRanges=lt,L.toDomRectList=so,L.toParentBounds=Kt,L.toViewportBounds=ro,L.trackViewport=$t,L.trimRangeToContainer=ct,L.whitespaceOrEmptyRegex=Ke,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
|
|
3
3
|
//# sourceMappingURL=text-annotator.umd.js.map
|