@recogito/text-annotator 4.2.2 → 4.2.4
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/state/spatial-tree.d.ts +5 -5
- package/dist/state/text-annotation-store.d.ts +5 -1
- package/dist/state/text-annotator-state.d.ts +1 -1
- package/dist/text-annotator-options.d.ts +1 -1
- package/dist/text-annotator.es.js +673 -666
- 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/revive-annotation.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(x,he){typeof exports=="object"&&typeof module<"u"?he(exports):typeof define=="function"&&define.amd?define(["exports"],he):(x=typeof globalThis<"u"?globalThis:x||self,he(x.RecogitoJS={}))})(this,(function(x){"use strict";const he=e=>e.target.selector.every(J),fn=e=>e.selector.every(J);function J(e){return Array.isArray(e)?e.every(t=>"range"in t&&t.range instanceof Range&&!t.range.collapsed):"range"in e&&e.range instanceof Range&&!e.range.collapsed}const $=[];for(let e=0;e<256;++e)$.push((e+256).toString(16).slice(1));function hn(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 gn=new Uint8Array(16);function pn(){return crypto.getRandomValues(gn)}function at(e,t,n){return crypto.randomUUID?crypto.randomUUID():mn(e)}function mn(e,t,n){e=e||{};const o=e.random??e.rng?.()??pn();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,hn(o)}const Ve=typeof navigator<"u"&&navigator.platform.startsWith("Mac"),Xe="not-annotatable",ae=`.${Xe}`,ge=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(ae):t.parentElement?.closest(ae)):!0,Pe=(e,t)=>{const n=t.commonAncestorContainer;return!ge(e,n)},$e=/^\s*$/,lt=e=>$e.test(e.toString()),yn=e=>$e.test(e.textContent||""),ct=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]},dt=e=>{(!e.hasAttribute("tabindex")||e.tabIndex<-1)&&e.setAttribute("tabindex","-1"),e.classList.add("no-focus-outline")},bn=function*(e){const t=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(Xe)&&!o.parentElement?.closest(ae)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},ut=(e,t)=>{if(!Pe(e,t))return[];const n=[];let o=null;for(const i of bn(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]},Re=e=>{const t=e.cloneContents();return t.querySelectorAll(ae).forEach(n=>n.remove()),t},ft=(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},ht=new Intl.Segmenter(void 0,{granularity:"grapheme"}),gt=(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=Re(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=Re(a).textContent,d=[...ht.segment(r)],h=[...ht.segment(l)];return{prefix:d.slice(-n).map(f=>f.segment).join(""),suffix:h.slice(0,n).map(f=>f.segment).join("")}},pt=(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=Re(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}},He=(e,t)=>{if(J(e))return e;const{start:n,end:o}=e,i=e.offsetReference||t,s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,h=>h.parentElement?.closest(ae)?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 d=!i;for(;l!==null;){if(d||=typeof i?.contains=="function"?i.contains(l):!1,d){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}},pe=(e,t,n=(o,i)=>He(o,i))=>({...e,selector:e.selector.map(o=>n(o,t))}),Oe=(e,t,n)=>({...e,target:pe(e.target,t,n)}),mt=e=>{if(!e)return document.scrollingElement;const{overflowY:t}=window.getComputedStyle(e);return t!=="visible"&&t!=="hidden"&&e.scrollHeight>e.clientHeight?e:mt(e.parentElement)},yt=(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),d=r.top-o.top,h=r.left-o.left,f=n.parentElement?n.scrollTop:0,b=n.parentElement?n.scrollLeft:0,m=d+f-(i-l)/2,c=h+b-(s-a)/2;n.scroll({top:m,left:c,behavior:"smooth"})},bt=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,s=o?typeof o=="string"?document.getElementById(o):o:mt(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 yt(t,r.target,s),!0;const l=pe(r.target,e),{range:d}=l.selector[0];return d&&!d.collapsed?(yt(t,l,s),!0):!1};var At=Object.prototype.hasOwnProperty;function le(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--&&le(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(At.call(e,n)&&++o&&!At.call(t,n)||!(n in t)||!le(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const An=Symbol("clean");let Q=[],oe=0;const ke=4,wn=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),je=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+ke;s<Q.length;)Q[s]===o?Q.splice(s,ke):s+=ke;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){wn.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+=ke)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[An]=()=>{t=[],n.lc=0,n.off()}),n},En=e=>{const t=je(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 Fe=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Fe||{});const ze={selected:[]},vn=(e,t,n)=>{const o=je(ze);let i=t;const s=()=>{le(o.get(),ze)||o.set(ze)},r=()=>{var m;return((m=o.get().selected)==null?void 0:m.length)===0},a=m=>{if(r())return!1;const c=typeof m=="string"?m:m.id;return o.get().selected.some(y=>y.id===c)},l=(m,c)=>{let y;if(Array.isArray(m)){if(y=m.map(g=>e.getAnnotation(g)).filter(Boolean),y.length<m.length){console.warn("Invalid selection: "+m.filter(g=>!y.some(u=>u.id===g)));return}}else{const g=e.getAnnotation(m);if(!g){console.warn("Invalid selection: "+m);return}y=[g]}const E=y.reduce((g,u)=>{const v=b(u);return v==="EDIT"?[...g,{id:u.id,editable:!0}]:v==="SELECT"?[...g,{id:u.id}]:g},[]);o.set({selected:E,event:c})},d=(m,c)=>{const y=Array.isArray(m)?m:[m],E=y.map(g=>e.getAnnotation(g)).filter(g=>!!g);o.set({selected:E.map(g=>{const u=c===void 0?b(g)==="EDIT":c;return{id:g.id,editable:u}})}),E.length!==y.length&&console.warn("Invalid selection",m)},h=m=>{if(r())return!1;const{selected:c}=o.get();c.some(({id:y})=>m.includes(y))&&o.set({selected:c.filter(({id:y})=>!m.includes(y))})},f=m=>{i=m,d(o.get().selected.map(({id:c})=>c))},b=m=>Sn(m,i,n);return e.observe(({changes:m})=>h((m.deleted||[]).map(c=>c.id))),{get event(){const m=o.get();return m?m.event:null},get selected(){const m=o.get();return m?[...m.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:b,isEmpty:r,isSelected:a,setSelected:d,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:l}},Sn=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},H=[];for(let e=0;e<256;++e)H.push((e+256).toString(16).slice(1));function Cn(e,t=0){return(H[e[t+0]]+H[e[t+1]]+H[e[t+2]]+H[e[t+3]]+"-"+H[e[t+4]]+H[e[t+5]]+"-"+H[e[t+6]]+H[e[t+7]]+"-"+H[e[t+8]]+H[e[t+9]]+"-"+H[e[t+10]]+H[e[t+11]]+H[e[t+12]]+H[e[t+13]]+H[e[t+14]]+H[e[t+15]]).toLowerCase()}const Tn=new Uint8Array(16);function xn(){return crypto.getRandomValues(Tn)}function wt(e,t,n){return crypto.randomUUID?crypto.randomUUID():Ln(e)}function Ln(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??xn();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,Cn(i)}const We=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)}},Rn=(e,t,n,o)=>({id:wt(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),On=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},kn=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Nn=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!le(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Mn=(e,t)=>!le(e.target,t.target),Et=(e,t)=>{const n=On(e,t),o=kn(e,t),i=Nn(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:Mn(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var B=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(B||{});const _n=(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)),d=(o=i.updated)==null?void 0:o.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!d||r==="TARGET_ONLY"&&d&&!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},Bn=(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:b})=>b.id===f.id).newValue:f),...t.created||[]],d=[...(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:b,newValue:m}=f;if(r.has(m.id)){const c=t.updated.find(y=>y.oldValue.id===m.id).newValue;return Et(b,c)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!a.has(f.id))];return{created:l,deleted:d,updated:h}},Ne=e=>{const t=e.id===void 0?wt():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},In=e=>e.id!==void 0,Dn=()=>{const e=new Map,t=new Map,n=[],o=(p,A={})=>{n.push({onChange:p,options:A})},i=p=>{const A=n.findIndex(w=>w.onChange==p);A>-1&&n.splice(A,1)},s=(p,A)=>{const w={origin:p,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...e.values()]};n.forEach(T=>{_n(T,w)&&T.onChange(w)})},r=(p,A=B.LOCAL)=>{if(p.id&&e.get(p.id))throw Error(`Cannot add annotation ${p.id} - exists already`);{const w=Ne(p);e.set(w.id,w),w.bodies.forEach(T=>t.set(T.id,w.id)),s(A,{created:[w]})}},a=(p,A)=>{const w=Ne(typeof p=="string"?A:p),T=typeof p=="string"?p:p.id,D=T&&e.get(T);if(D){const _=Et(D,w);return T===w.id?e.set(T,w):(e.delete(T),e.set(w.id,w)),D.bodies.forEach(Y=>t.delete(Y.id)),w.bodies.forEach(Y=>t.set(Y.id,w.id)),_}else console.warn(`Cannot update annotation ${T} - does not exist`)},l=(p,A=B.LOCAL,w=B.LOCAL)=>{const T=In(A)?w:A,D=a(p,A);D&&s(T,{updated:[D]})},d=(p,A=B.LOCAL)=>{e.get(p.id)?l(p,A):r(p,A)},h=(p,A=B.LOCAL)=>{const w=p.reduce((T,D)=>{const _=a(D);return _?[...T,_]:T},[]);w.length>0&&s(A,{updated:w})},f=(p,A=B.LOCAL)=>{const w=p.map(Ne),{toAdd:T,toUpdate:D}=w.reduce((Y,S)=>e.get(S.id)?{...Y,toUpdate:[...Y.toUpdate,S]}:{...Y,toAdd:[...Y.toAdd,S]},{toAdd:[],toUpdate:[]}),_=D.map(Y=>a(Y,A)).filter(Boolean);T.forEach(Y=>{e.set(Y.id,Y),Y.bodies.forEach(S=>t.set(S.id,Y.id))}),s(A,{created:T,updated:_})},b=(p,A=B.LOCAL)=>{const w=e.get(p.annotation);if(w){const T={...w,bodies:[...w.bodies,p]};e.set(w.id,T),t.set(p.id,T.id),s(A,{updated:[{oldValue:w,newValue:T,bodiesCreated:[p]}]})}else console.warn(`Attempt to add body to missing annotation: ${p.annotation}`)},m=()=>[...e.values()],c=(p=B.LOCAL)=>{const A=[...e.values()];e.clear(),t.clear(),s(p,{deleted:A})},y=(p,A=!0,w=B.LOCAL)=>{const T=p.map(Ne);if(A){const D=[...e.values()];e.clear(),t.clear(),T.forEach(_=>{e.set(_.id,_),_.bodies.forEach(Y=>t.set(Y.id,_.id))}),s(w,{created:T,deleted:D})}else{const D=p.reduce((_,Y)=>{const S=Y.id&&e.get(Y.id);return S?[..._,S]:_},[]);if(D.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${D.map(_=>_.id).join(", ")}`);T.forEach(_=>{e.set(_.id,_),_.bodies.forEach(Y=>t.set(Y.id,_.id))}),s(w,{created:T})}},E=p=>{const A=typeof p=="string"?p:p.id,w=e.get(A);if(w)return e.delete(A),w.bodies.forEach(T=>t.delete(T.id)),w;console.warn(`Attempt to delete missing annotation: ${A}`)},g=(p,A=B.LOCAL)=>{const w=E(p);w&&s(A,{deleted:[w]})},u=(p,A=B.LOCAL)=>{const w=p.reduce((T,D)=>{const _=E(D);return _?[...T,_]:T},[]);w.length>0&&s(A,{deleted:w})},v=p=>{const A=e.get(p.annotation);if(A){const w=A.bodies.find(T=>T.id===p.id);if(w){t.delete(w.id);const T={...A,bodies:A.bodies.filter(D=>D.id!==p.id)};return e.set(A.id,T),{oldValue:A,newValue:T,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${p.id} from annotation ${p.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${p.annotation}`)},k=(p,A=B.LOCAL)=>{const w=v(p);w&&s(A,{updated:[w]})},L=(p,A=B.LOCAL)=>{const w=p.map(T=>v(T)).filter(Boolean);w.length>0&&s(A,{updated:w})},C=p=>{const A=e.get(p);return A?{...A}:void 0},R=p=>{const A=t.get(p);if(A){const w=C(A).bodies.find(T=>T.id===p);if(w)return w;console.error(`Store integrity error: body ${p} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${p}`)},I=(p,A)=>{if(p.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=e.get(p.annotation);if(w){const T=w.bodies.find(_=>_.id===p.id),D={...w,bodies:w.bodies.map(_=>_.id===T.id?A:_)};return e.set(w.id,D),T.id!==A.id&&(t.delete(T.id),t.set(A.id,D.id)),{oldValue:w,newValue:D,bodiesUpdated:[{oldBody:T,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${p.annotation}`)},U=(p,A,w=B.LOCAL)=>{const T=I(p,A);T&&s(w,{updated:[T]})},N=(p,A=B.LOCAL)=>{const w=p.map(T=>I({id:T.id,annotation:T.annotation},T)).filter(Boolean);s(A,{updated:w})},O=p=>{const A=e.get(p.annotation);if(A){const w={...A,target:{...A.target,...p}};return e.set(A.id,w),{oldValue:A,newValue:w,targetUpdated:{oldTarget:A.target,newTarget:p}}}else console.warn(`Attempt to update target on missing annotation: ${p.annotation}`)};return{addAnnotation:r,addBody:b,all:m,bulkAddAnnotations:y,bulkDeleteAnnotations:u,bulkDeleteBodies:L,bulkUpdateAnnotations:h,bulkUpdateBodies:N,bulkUpdateTargets:(p,A=B.LOCAL)=>{const w=p.map(T=>O(T)).filter(Boolean);w.length>0&&s(A,{updated:w})},bulkUpsertAnnotations:f,clear:c,deleteAnnotation:g,deleteBody:k,getAnnotation:C,getBody:R,observe:o,unobserve:i,updateAnnotation:l,updateBody:U,updateTarget:(p,A=B.LOCAL)=>{const w=O(p);w&&s(A,{updated:[w]})},upsertAnnotation:d}};let Yn=()=>({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 Kn=250,Un=(e,t)=>{const n=Yn(),o=[];let i=-1,s=!1,r=0;const a=c=>{if(!s){const{changes:y}=c,E=performance.now();if(E-r>Kn)o.splice(i+1),o.push(y),i=o.length-1;else{const g=o.length-1;o[g]=Bn(o[g],y)}r=E}s=!1};e.observe(a,{origin:B.LOCAL});const l=c=>c&&c.length>0&&e.bulkDeleteAnnotations(c),d=c=>c&&c.length>0&&e.bulkAddAnnotations(c,!1),h=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({oldValue:y})=>y)),f=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({newValue:y})=>y)),b=c=>c&&c.length>0&&e.bulkAddAnnotations(c,!1),m=c=>c&&c.length>0&&e.bulkDeleteAnnotations(c);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...o],pointer:i}),on:(c,y)=>n.on(c,y),redo:()=>{if(o.length-1>i){s=!0;const{created:c,updated:y,deleted:E}=o[i+1];d(c),f(y),m(E),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:c,updated:y,deleted:E}=o[i];l(c),h(y),b(E),n.emit("undo",o[i]),i-=1}}}},Vn=()=>{const e=je([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Xn=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:a}=e,l=new Map;let d=[],h;const f=(y,E)=>{l.has(y)?l.get(y).push(E):l.set(y,[E])},b=(y,E)=>{const g=l.get(y);if(g){const u=g.indexOf(E);u!==-1&&g.splice(u,1)}},m=(y,E,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(u=>{if(n){const v=Array.isArray(E)?E.map(L=>n.serialize(L)):n.serialize(E),k=g?g instanceof PointerEvent?g:n.serialize(g):void 0;u(v,k)}else u(E,g)})},1)};s.subscribe(({selected:y})=>{if(!(d.length===0&&y.length===0)){if(d.length===0&&y.length>0)d=y.map(({id:E})=>r.getAnnotation(E));else if(d.length>0&&y.length===0)d.forEach(E=>{const g=r.getAnnotation(E.id);g&&!le(g,E)&&m("updateAnnotation",g,E)}),d=[];else{const E=new Set(d.map(u=>u.id)),g=new Set(y.map(({id:u})=>u));d.filter(u=>!g.has(u.id)).forEach(u=>{const v=r.getAnnotation(u.id);v&&!le(v,u)&&m("updateAnnotation",v,u)}),d=[...d.filter(u=>g.has(u.id)),...y.filter(({id:u})=>!E.has(u)).map(({id:u})=>r.getAnnotation(u))]}m("selectionChanged",d)}}),i.subscribe(y=>{!h&&y?m("mouseEnterAnnotation",r.getAnnotation(y)):h&&!y?m("mouseLeaveAnnotation",r.getAnnotation(h)):h&&y&&(m("mouseLeaveAnnotation",r.getAnnotation(h)),m("mouseEnterAnnotation",r.getAnnotation(y))),h=y}),a?.subscribe(y=>m("viewportIntersect",y.map(E=>r.getAnnotation(E)))),r.observe(y=>{const{created:E,deleted:g}=y.changes;(E||[]).forEach(u=>m("createAnnotation",u)),(g||[]).forEach(u=>m("deleteAnnotation",u)),(y.changes.updated||[]).filter(u=>[...u.bodiesCreated||[],...u.bodiesDeleted||[],...u.bodiesUpdated||[]].length>0).forEach(({oldValue:u,newValue:v})=>{const k=d.find(L=>L.id===u.id)||u;d=d.map(L=>L.id===u.id?v:L),m("updateAnnotation",v,k)})},{origin:B.LOCAL}),r.observe(y=>{if(d){const E=new Set(d.map(u=>u.id)),g=(y.changes.updated||[]).filter(({newValue:u})=>E.has(u.id)).map(({newValue:u})=>u);g.length>0&&(d=d.map(u=>g.find(k=>k.id===u.id)||u))}},{origin:B.REMOTE});const c=y=>E=>{const{updated:g}=E;y?(g||[]).forEach(u=>m("updateAnnotation",u.oldValue,u.newValue)):(g||[]).forEach(u=>m("updateAnnotation",u.newValue,u.oldValue))};return t.on("undo",c(!0)),t.on("redo",c(!1)),{on:f,off:b,emit:m}},Pn=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:[]}),$n=(e,t,n)=>{const{store:o,selection:i}=e,s=g=>{if(n){const{parsed:u,error:v}=n.parse(g);u?o.addAnnotation(u,B.REMOTE):console.error(v)}else o.addAnnotation(We(g),B.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=g=>{const u=o.getAnnotation(g);return n&&u?n.serialize(u):u},d=()=>n?o.all().map(n.serialize):o.all(),h=()=>{var g;const u=(((g=i.selected)==null?void 0:g.map(v=>v.id))||[]).map(v=>o.getAnnotation(v)).filter(Boolean);return n?u.map(n.serialize):u},f=(g,u=!0)=>fetch(g).then(v=>v.json()).then(v=>(m(v,u),v)),b=g=>{if(typeof g=="string"){const u=o.getAnnotation(g);if(o.deleteAnnotation(g),u)return n?n.serialize(u):u}else{const u=n?n.parse(g).parsed:g;if(u)return o.deleteAnnotation(u),g}},m=(g,u=!0)=>{if(n){const v=n.parseAll||Pn(n),{parsed:k,failed:L}=v(g);L.length>0&&console.warn(`Discarded ${L.length} invalid annotations`,L),o.bulkAddAnnotations(k,u,B.REMOTE)}else o.bulkAddAnnotations(g.map(We),u,B.REMOTE)},c=(g,u)=>{g?i.setSelected(g,u):i.clear()},y=g=>{i.setUserSelectAction(g)},E=g=>{if(n){const u=n.parse(g).parsed,v=n.serialize(o.getAnnotation(u.id));return o.updateAnnotation(u),v}else{const u=o.getAnnotation(g.id);return o.updateAnnotation(We(g)),u}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:d,getHistory:t.getHistory,getSelected:h,loadAnnotations:f,redo:t.redo,removeAnnotation:b,setAnnotations:m,setSelected:c,setUserSelectAction:y,undo:t.undo,updateAnnotation:E}};let Hn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",jn=e=>crypto.getRandomValues(new Uint8Array(e)),Fn=(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),d=r;for(;d--;)if(a+=e[l[d]&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}}},zn=(e,t=21)=>Fn(e,t|0,jn),Wn=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Hn[n[e]&63];return t};const qn=()=>({isGuest:!0,id:zn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Gn=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}`},vt=e=>e?typeof e=="object"?{...e}:e:void 0,Qn=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,modified:l,creator:d,...h}=n;return{id:o||`temp-${Gn(n)}`,annotation:t,type:i,purpose:s,value:r,creator:vt(d),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...h}}),Jn=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});globalThis.ANNOTORIOUS_PRESENCE_KEY||(globalThis.ANNOTORIOUS_PRESENCE_KEY=Wn());const Zn=(e,t)=>({parse:n=>St(n),serialize:n=>Ct(n,e,t)}),eo=e=>e.quote!==void 0&&e.start!==void 0&&e.end!==void 0,to=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:vt(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,b)=>{switch(b.type){case"TextQuoteSelector":f.quote=b.exact;break;case"TextPositionSelector":f.start=b.start,f.end=b.end;break}return f},{});if(eo(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}},St=e=>{const t=e.id||at(),{creator:n,created:o,modified:i,body:s,...r}=e,a=Qn(s,t),l=to(e);return"error"in l?{error:l.error}:{parsed:{...r,id:t,bodies:a,target:l.parsed}}},Ct=(e,t,n)=>{const{bodies:o,target:i,...s}=e,{selector:r,creator:a,created:l,updated:d,...h}=i,f=r.map(b=>{const{id:m,quote:c}=b,y={type:"TextQuoteSelector",exact:c};if(n&&"range"in b){const{prefix:v,suffix:k}=gt(b.range,n);y.prefix=v,y.suffix=k}if(!("start"in b))throw new Error("W3C serialization requires TextSelector with start/end");const{start:E,end:g}=b,u={type:"TextPositionSelector",start:E,end:g};return{...h,id:m,scope:"scope"in b?b.scope:void 0,source:t,selector:[y,u]}});return{...s,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Jn(e.bodies),creator:a,created:l?.toISOString(),modified:d?.toISOString(),target:f}};let Tt=()=>({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 xt=e=>e.addEventListener("click",t=>{!t.target.closest(ae)&&!t.target.closest("a")&&t.preventDefault()}),Me=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}),me=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}),_e=(e,t=10)=>{let n;return((...o)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,o),t)})},qe=(e,t,n,o)=>{const{store:i,selection:s,hover:r}=n,a=Tt();let l;const d=new Map;let h;const f=Ft(o),b=N=>{const{x:O,y:p}=t.getBoundingClientRect(),A=i.getAt(N.clientX-O,N.clientY-p,!1,h);A&&n.selection.evalSelectAction(A)!==Fe.NONE?r.current!==A.id&&(t.classList.add("hovered"),r.set(A.id)):r.current&&(t.classList.remove("hovered"),r.set(null))};t.addEventListener("pointermove",b);const m=_e((N=!1)=>requestAnimationFrame(()=>{const O=jt(t),{minX:p,minY:A,maxX:w,maxY:T}=O,D=h?i.getIntersecting(p,A,w,T).filter(({annotation:S})=>h?.(S)):i.getIntersecting(p,A,w,T),_=s.selected.map(({id:S})=>S),Y=D.map(({annotation:S,rects:M})=>{const F=_.includes(S.id),ie=S.id===r.current;return{annotation:S,rects:M,state:{selected:F,hovered:ie}}});e.redraw(Y,O,l,d,N),setTimeout(()=>{f(D.map(({annotation:S})=>S)),a.emit("onRedraw")},1)}),10),c=(N,O)=>{O?N?d.set(O,N):d.delete(O):l=N,m(!0)},y=N=>{h=N,m(!1)},E=(N,O)=>a.on(N,O),g=()=>{m()};i.observe(g);const u=s.subscribe(()=>{m()}),v=r.subscribe(()=>{m()}),k=()=>{m(!0)};document.addEventListener("scroll",k,{capture:!0,passive:!0});const L=_e(()=>{i.recalculatePositions(),m()},10);window.addEventListener("resize",L);const C=new ResizeObserver(L);C.observe(t);const R={attributes:!0,childList:!0,subtree:!0},I=new MutationObserver(_e(N=>{N.every(p=>p.target===t||t.contains(p.target))||m(!0)},150));return I.observe(document.body,R),{destroy:()=>{t.removeEventListener("pointermove",b),e.destroy(),i.unobserve(g),u(),v(),document.removeEventListener("scroll",k),window.removeEventListener("resize",L),C.disconnect(),I.disconnect()},on:E,redraw:m,setStyle:c,setFilter:y,setVisible:e.setVisible.bind(e)}};var no={grad:.9,turn:360,rad:360/(2*Math.PI)},ee=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},P=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=Math.pow(10,t)),Math.round(n*e)/n+0},z=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},Lt=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},Rt=function(e){return{r:z(e.r,0,255),g:z(e.g,0,255),b:z(e.b,0,255),a:z(e.a)}},Ge=function(e){return{r:P(e.r),g:P(e.g),b:P(e.b),a:P(e.a,3)}},oo=/^#([0-9a-f]{3,8})$/i,Be=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},Ot=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}},kt=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),d=s%6;return{r:255*[o,a,r,r,l,o][d],g:255*[l,o,o,a,r,r][d],b:255*[r,r,l,o,o,a][d],a:i}},Nt=function(e){return{h:Lt(e.h),s:z(e.s,0,100),l:z(e.l,0,100),a:z(e.a)}},Mt=function(e){return{h:P(e.h),s:P(e.s),l:P(e.l),a:P(e.a,3)}},_t=function(e){return kt((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},ye=function(e){return{h:(t=Ot(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},io=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,so=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ro=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ao=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Bt={string:[[function(e){var t=oo.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?P(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?P(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=ro.exec(e)||ao.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Rt({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=io.exec(e)||so.exec(e);if(!t)return null;var n,o,i=Nt({h:(n=t[1],o=t[2],o===void 0&&(o="deg"),Number(n)*(no[o]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return _t(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)?Rt({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=Nt({h:Number(t),s:Number(n),l:Number(o),a:Number(s)});return _t(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:Lt(a.h),s:z(a.s,0,100),v:z(a.v,0,100),a:z(a.a)}})({h:Number(t),s:Number(n),v:Number(o),a:Number(s)});return kt(r)},"hsv"]]},It=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]},lo=function(e){return typeof e=="string"?It(e.trim(),Bt.string):typeof e=="object"&&e!==null?It(e,Bt.object):[null,void 0]},Qe=function(e,t){var n=ye(e);return{h:n.h,s:z(n.s+100*t,0,100),l:n.l,a:n.a}},Je=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},Dt=function(e,t){var n=ye(e);return{h:n.h,s:n.s,l:z(n.l+100*t,0,100),a:n.a}},Yt=(function(){function e(t){this.parsed=lo(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 P(Je(this.rgba),2)},e.prototype.isDark=function(){return Je(this.rgba)<.5},e.prototype.isLight=function(){return Je(this.rgba)>=.5},e.prototype.toHex=function(){return t=Ge(this.rgba),n=t.r,o=t.g,i=t.b,r=(s=t.a)<1?Be(P(255*s)):"","#"+Be(n)+Be(o)+Be(i)+r;var t,n,o,i,s,r},e.prototype.toRgb=function(){return Ge(this.rgba)},e.prototype.toRgbString=function(){return t=Ge(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 Mt(ye(this.rgba))},e.prototype.toHslString=function(){return t=Mt(ye(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=Ot(this.rgba),{h:P(t.h),s:P(t.s),v:P(t.v),a:P(t.a,3)};var t},e.prototype.invert=function(){return W({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),W(Qe(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),W(Qe(this.rgba,-t))},e.prototype.grayscale=function(){return W(Qe(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),W(Dt(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),W(Dt(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"?W({r:(n=this.rgba).r,g:n.g,b:n.b,a:t}):P(this.rgba.a,3);var n},e.prototype.hue=function(t){var n=ye(this.rgba);return typeof t=="number"?W({h:t,s:n.s,l:n.l,a:n.a}):P(n.h)},e.prototype.isEqual=function(t){return this.toHex()===W(t).toHex()},e})(),W=function(e){return e instanceof Yt?e:new Yt(e)};const te={fill:"rgb(0, 128, 255)",fillOpacity:.18},Ie={fill:"rgb(0, 128, 255)",fillOpacity:.45},Kt=e=>e?.fillOpacity!==void 0?W(e?.fill||te.fill).alpha(e.fillOpacity).toHex():e?.fill?e.fill:W(te.fill).alpha(te.fillOpacity).toHex(),Ze=(e,t,n)=>t?typeof t=="function"?t(e.annotation,e.state,n)||(e.state?.selected?Ie:te):t:e.state?.selected?Ie:te;var Ut=Object.prototype.hasOwnProperty;function et(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--&&et(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)||!et(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Vt=(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))},Xt=e=>{const t=[],n=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_TEXT);e.startContainer.nodeType===Node.TEXT_NODE&&(n.currentNode=e.startContainer,e.intersectsNode(e.startContainer)&&t.push(e.startContainer));let o=t.length>0,i;for(;i=n.nextNode();)if(e.intersectsNode(i))o=!0,t.push(i);else if(o)break;if(t.length<2)return Array.from(e.getClientRects());{const s=t[0],r=t[t.length-1],a=document.createRange();if(a.selectNode(s),e.startContainer.nodeType===Node.TEXT_NODE)a.setStart(s,e.startOffset);else{const h=e.startContainer.childNodes[e.startOffset];h?a.setStartBefore(h):a.setStartAfter(e.startContainer)}const l=document.createRange();if(l.selectNode(r),e.endContainer.nodeType===Node.TEXT_NODE)l.setEnd(r,e.endOffset);else{const h=e.endContainer.childNodes[e.endOffset];h?l.setEndBefore(h):l.setEndAfter(e.endContainer)}const d=h=>{const f=document.createRange();return f.selectNode(h),Array.from(f.getClientRects())};return[...Array.from(a.getClientRects()),...t.slice(1,-1).flatMap(d),...Array.from(l.getClientRects())]}},co=(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"},uo=(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)},Pt=(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=co(i,a,t,n);if(l==="inline-adjacent"){s=s.map(d=>d===a?uo(i,a):d),r=!0;break}else if(l==="inline-contains"){s=s.map(d=>d===a?i:d),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(d=>d===a?i:d)),i.width===a.width&&i.height<a.width&&(s=s.map(d=>d===a?i:d)),r=!0;break}}return r?s:[...s,i]},[]),fo=e=>({length:e.length,item:t=>e[t],[Symbol.iterator]:function*(){for(let t=0;t<this.length;t++)yield this.item(t)}}),$t=(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)},ho=(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)},go=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,d,h)=>{if(!(!et(n,r)||h))return;t.innerHTML="",[...r].sort((c,y)=>{const{annotation:{target:{created:E}}}=c,{annotation:{target:{created:g}}}=y;return E&&g?E.getTime()-g.getTime():0}).forEach(c=>{const y=d?.get(c.annotation.id)||l;c.rects.map(E=>{const g=Vt(E,r),u=Ze(c,y,g),v=document.createElement("span");v.className="r6o-annotation",v.dataset.annotation=c.annotation.id,v.style.left=`${E.x}px`,v.style.top=`${E.y}px`,v.style.width=`${E.width}px`,v.style.height=`${E.height}px`,v.style.backgroundColor=Kt(u),u.underlineStyle&&(v.style.borderStyle=u.underlineStyle),u.underlineColor&&(v.style.borderColor=u.underlineColor),u.underlineThickness&&(v.style.borderBottomWidth=`${u.underlineThickness}px`),u.underlineOffset&&(v.style.paddingBottom=`${u.underlineOffset}px`),t.appendChild(v)})}),n=r},setVisible:r=>{r?t.classList.remove("hidden"):t.classList.add("hidden")}}},Ht=(e,t,n)=>qe(go(e),e,t,n),jt=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}},Ft=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 zt(e,t,n=0,o=e.length-1,i=po){for(;o>n;){if(o-n>600){const l=o-n+1,d=t-n+1,h=Math.log(l),f=.5*Math.exp(2*h/3),b=.5*Math.sqrt(h*f*(l-f)/l)*(d-l/2<0?-1:1),m=Math.max(n,Math.floor(t-d*f/l+b)),c=Math.min(o,Math.floor(t+(l-d)*f/l+b));zt(e,t,m,c,i)}const s=e[t];let r=n,a=o;for(be(e,n,t),i(e[o],s)>0&&be(e,n,o);r<a;){for(be(e,r,a),r++,a--;i(e[r],s)<0;)r++;for(;i(e[a],s)>0;)a--}i(e[n],s)===0?be(e,n,a):(a++,be(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function be(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function po(e,t){return e<t?-1:e>t?1:0}class mo{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(!Ye(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;Ye(t,l)&&(n.leaf?o.push(a):nt(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!Ye(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(Ye(t,r)){if(n.leaf||nt(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,d;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],a=r.pop(),d=!0),o.leaf){const h=yo(t,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!d&&!o.leaf&&nt(o,i)?(s.push(o),r.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],d=!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),d=l*Math.ceil(Math.sqrt(r));Wt(t,n,o,d,this.compareMinX);for(let h=n;h<=o;h+=d){const f=Math.min(h+d-1,o);Wt(t,h,f,l,this.compareMinY);for(let b=h;b<=f;b+=l){const m=Math.min(b+l-1,f);a.children.push(this._build(t,b,m,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 d=n.children[l],h=tt(d),f=wo(t,d)-h;f<r?(r=f,s=h<s?h:s,a=d):f===r&&h<s&&(s=h,a=d)}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),we(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=Ae(t,0,a,this.toBBox),d=Ae(t,a,o,this.toBBox),h=Eo(l,d),f=tt(l)+tt(d);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:bo,s=t.leaf?this.compareMinY:Ao,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=Ae(t,0,n,s),a=Ae(t,o-n,o,s);let l=De(r)+De(a);for(let d=n;d<o-n;d++){const h=t.children[d];we(r,t.leaf?s(h):h),l+=De(r)}for(let d=o-n-1;d>=n;d--){const h=t.children[d];we(a,t.leaf?s(h):h),l+=De(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)we(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 yo(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){Ae(e,0,e.children.length,t,e)}function Ae(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];we(i,e.leaf?o(r):r)}return i}function we(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 bo(e,t){return e.minX-t.minX}function Ao(e,t){return e.minY-t.minY}function tt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function De(e){return e.maxX-e.minX+(e.maxY-e.minY)}function wo(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 Eo(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 nt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Ye(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 Wt(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;zt(e,r,t,n,i),s.push(t,r,r,n)}}const vo=(e,t,n,o,i)=>{const s=new mo,r=new Map,a=Tt(),l=(C,R)=>{const I=C.selector.flatMap(N=>{const O=(i?i(N,t):He(N,t))?.range;return Xt(O)}),U=Pt(I,n,o).map(N=>$t(N,R));return U.map(N=>{const{x:O,y:p,width:A,height:w}=N;return{minX:O,minY:p,maxX:O+A,maxY:p+w,annotation:{id:C.annotation,rects:U}}})},d=()=>[...r.values()],h=()=>{s.clear(),r.clear()},f=C=>{const R=l(C,t.getBoundingClientRect());R.length!==0&&(R.forEach(I=>s.insert(I)),r.set(C.annotation,R))},b=C=>{const R=r.get(C.annotation);R&&(R.forEach(I=>s.remove(I)),r.delete(C.annotation))},m=C=>{b(C),f(C)},c=(C,R=!0)=>{R&&h();const I=t.getBoundingClientRect(),U=C.map(O=>({target:O,rects:l(O,I)}));U.forEach(({target:O,rects:p})=>{p.length>0&&r.set(O.annotation,p)});const N=U.flatMap(({rects:O})=>O);s.load(N)},y=(C,R,I=!1)=>{const U=s.search({minX:C,minY:R,maxX:C,maxY:R}),N=O=>O.annotation.rects.reduce((p,A)=>p+A.width*A.height,0);return U.length>0?(U.sort((O,p)=>N(O)-N(p)),I?U.map(O=>O.annotation.id):[U[0].annotation.id]):[]},E=C=>{const R=g(C);if(R.length===0)return;let I=R[0].left,U=R[0].top,N=R[0].right,O=R[0].bottom;for(let p=1;p<R.length;p++){const A=R[p];I=Math.min(I,A.left),U=Math.min(U,A.top),N=Math.max(N,A.right),O=Math.max(O,A.bottom)}return new DOMRect(I,U,N-I,O-U)},g=C=>{const R=r.get(C);return R?R[0].annotation.rects:[]};return{all:d,clear:h,getAt:y,getAnnotationBounds:E,getAnnotationRects:g,getIntersecting:(C,R,I,U)=>{const N=s.search({minX:C,minY:R,maxX:I,maxY:U}),O=new Set(N.map(p=>p.annotation.id));return Array.from(O).map(p=>({annotation:e.getAnnotation(p),rects:g(p)})).filter(p=>!!p.annotation)},insert:f,recalculate:()=>{c(e.all().map(C=>C.target),!0),a.emit("recalculate")},remove:b,set:c,size:()=>s.all().length,update:m,on:(C,R)=>a.on(C,R)}},qt=(e,t)=>{const n=Dn(),o=vo(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance,t.selectorReviveFn),i=vn(n,t.userSelectAction,t.adapter),s=En(n),r=Vn(),a=(u,v=B.LOCAL)=>{const k=Oe(u,e,t.selectorReviveFn),L=J(k.target.selector);return L&&n.addAnnotation(k,v),L},l=(u,v=!0,k=B.LOCAL)=>{const L=u.map(R=>Oe(R,e,t.selectorReviveFn)),C=L.filter(R=>!J(R.target.selector));return n.bulkAddAnnotations(L,v,k),C},d=(u,v=B.LOCAL)=>{const k=u.map(C=>Oe(C,e,t.selectorReviveFn)),L=k.filter(C=>!J(C.target.selector));return k.forEach(C=>{n.getAnnotation(C.id)?n.updateAnnotation(C,v):n.addAnnotation(C,v)}),L},h=(u,v=B.LOCAL)=>{const k=pe(u,e);n.updateTarget(k,v)},f=(u,v=B.LOCAL)=>{const k=u.map(L=>pe(L,e));n.bulkUpdateTargets(k,v)};function b(u,v,k,L){const C=k||!!L,R=o.getAt(u,v,C).map(U=>n.getAnnotation(U)).filter(Boolean),I=L?R.filter(L):R;if(I.length!==0)return k?I:I[0]}const m=u=>o.getAnnotationRects(u).length>0?o.getAnnotationBounds(u):void 0,c=(u,v,k,L)=>o.getIntersecting(u,v,k,L),y=u=>o.getAnnotationRects(u),E=()=>o.recalculate(),g=u=>o.on("recalculate",u);return n.observe(({changes:u})=>{const v=(u.deleted||[]).filter(C=>J(C.target.selector)),k=(u.created||[]).filter(C=>J(C.target.selector)),L=(u.updated||[]).filter(C=>J(C.newValue.target.selector));v?.length>0&&v.forEach(C=>o.remove(C.target)),k.length>0&&o.set(k.map(C=>C.target),!1),L?.length>0&&L.forEach(({newValue:C})=>o.update(C.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotations:l,bulkUpdateTargets:f,bulkUpsertAnnotations:d,getAnnotationBounds:m,getAnnotationRects:y,getIntersecting:c,getAt:b,recalculatePositions:E,onRecalculatePositions:g,updateTarget:h},selection:i,hover:s,viewport:r}};function So(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 d(){const b=i,m=s;return i=void 0,s=void 0,l=e.apply(b,m),l}function h(){const b=Date.now()-a;b<t&&b>=0?r=setTimeout(h,t-b):(r=void 0,o||(l=d()))}const f=function(...b){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=b,a=Date.now();const m=o&&!r;if(r||(r=setTimeout(h,t)),m)return l=d(),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=d(),f.clear()},f}const ot=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function it(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent(`on${t}`,n)}function Ee(e,t,n,o){e&&(e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent(`on${t}`,n))}function Gt(e,t){const n=t.slice(0,t.length-1),o=[];for(let i=0;i<n.length;i++)o.push(e[n[i].toLowerCase()]);return o}function Qt(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 Co(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}function Jt(e){let t=e.keyCode||e.which||e.charCode;return e.key&&/^[a-z]$/i.test(e.key)?e.key.toUpperCase().charCodeAt(0):(e.code&&/^Key[A-Z]$/.test(e.code)&&(t=e.code.charCodeAt(3)),t)}const ve={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,"-":ot?173:189,"=":ot?61:187,";":ot?59:186,"'":222,"{":219,"}":221,"[":219,"]":221,"\\":220},q={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,meta:91,command:91},Se={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},X={16:!1,18:!1,17:!1,91:!1},V={};for(let e=1;e<20;e++)ve[`f${e}`]=111+e;let K=[],Ce=null,ue=null,Zt="all";const ne=new Map,fe=e=>ve[e.toLowerCase()]||q[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),To=e=>Object.keys(ve).find(t=>ve[t]===e),xo=e=>Object.keys(q).find(t=>q[t]===e),en=e=>{Zt=e||"all"},Te=()=>Zt||"all",Lo=()=>K.slice(0),Ro=()=>K.map(e=>To(e)||xo(e)||String.fromCharCode(e)),Oo=()=>{const e=[];return Object.keys(V).forEach(t=>{V[t].forEach(({key:n,scope:o,mods:i,shortcut:s})=>{e.push({scope:o,shortcut:s,mods:i,keys:n.split("+").map(r=>fe(r))})})}),e},tn=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},ko=e=>(typeof e=="string"&&(e=fe(e)),K.indexOf(e)!==-1),No=(e,t)=>{let n,o;e||(e=Te());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(({element:r})=>st(r)):o++;Te()===e&&en(t||"all")};function Mo(e){let t=Jt(e);e.key&&e.key.toLowerCase()==="capslock"&&(t=fe(e.key));const n=K.indexOf(t);if(n>=0&&K.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&K.splice(0,K.length),(t===93||t===224)&&(t=91),t in X){X[t]=!1;for(const o in q)q[o]===t&&(G[o]=!1)}}const nn=(e,...t)=>{if(typeof e>"u")Object.keys(V).forEach(n=>{Array.isArray(V[n])&&V[n].forEach(o=>Ke(o)),delete V[n]}),st(null);else if(Array.isArray(e))e.forEach(n=>{n.key&&Ke(n)});else if(typeof e=="object")e.key&&Ke(e);else if(typeof e=="string"){let[n,o]=t;typeof n=="function"&&(o=n,n=""),Ke({key:e,scope:n,method:o,splitKey:"+"})}},Ke=({key:e,scope:t,method:n,splitKey:o="+"})=>{Qt(e).forEach(s=>{const r=s.split(o),a=r.length,l=r[a-1],d=l==="*"?"*":fe(l);if(!V[d])return;t||(t=Te());const h=a>1?Gt(q,r):[],f=[];V[d]=V[d].filter(b=>{const c=(n?b.method===n:!0)&&b.scope===t&&Co(b.mods,h);return c&&f.push(b.element),!c}),f.forEach(b=>st(b))})};function on(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 X)Object.prototype.hasOwnProperty.call(X,s)&&(!X[s]&&t.mods.indexOf(+s)>-1||X[s]&&t.mods.indexOf(+s)===-1)&&(i=!1);(t.mods.length===0&&!X[16]&&!X[18]&&!X[17]&&!X[91]||i||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(K),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function sn(e,t){const n=V["*"];let o=Jt(e);if(e.key&&e.key.toLowerCase()==="capslock"||!(G.filter||tn).call(this,e))return;if((o===93||o===224)&&(o=91),K.indexOf(o)===-1&&o!==229&&K.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(l=>{const d=Se[l];e[l]&&K.indexOf(d)===-1?K.push(d):!e[l]&&K.indexOf(d)>-1?K.splice(K.indexOf(d),1):l==="metaKey"&&e[l]&&(K=K.filter(h=>h in Se||h===o))}),o in X){X[o]=!0;for(const l in q)if(Object.prototype.hasOwnProperty.call(q,l)){const d=Se[q[l]];G[l]=e[d]}if(!n)return}for(const l in X)Object.prototype.hasOwnProperty.call(X,l)&&(X[l]=e[Se[l]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(K.indexOf(17)===-1&&K.push(17),K.indexOf(18)===-1&&K.push(18),X[17]=!0,X[18]=!0);const s=Te();if(n)for(let l=0;l<n.length;l++)n[l].scope===s&&(e.type==="keydown"&&n[l].keydown||e.type==="keyup"&&n[l].keyup)&&on(e,n[l],s,t);if(!(o in V))return;const r=V[o],a=r.length;for(let l=0;l<a;l++)if((e.type==="keydown"&&r[l].keydown||e.type==="keyup"&&r[l].keyup)&&r[l].key){const d=r[l],{splitKey:h}=d,f=d.key.split(h),b=[];for(let m=0;m<f.length;m++)b.push(fe(f[m]));b.sort().join("")===K.sort().join("")&&on(e,d,s,t)}}const G=function e(t,n,o){K=[];const i=Qt(t);let s=[],r="all",a=document,l=0,d=!1,h=!0,f="+",b=!1,m=!1;if(o===void 0&&typeof n=="function"&&(o=n),Object.prototype.toString.call(n)==="[object Object]"){const c=n;c.scope&&(r=c.scope),c.element&&(a=c.element),c.keyup&&(d=c.keyup),c.keydown!==void 0&&(h=c.keydown),c.capture!==void 0&&(b=c.capture),typeof c.splitKey=="string"&&(f=c.splitKey),c.single===!0&&(m=!0)}for(typeof n=="string"&&(r=n),m&&nn(t,r);l<i.length;l++){const c=i[l].split(f);s=[],c.length>1&&(s=Gt(q,c));let y=c[c.length-1];y=y==="*"?"*":fe(y),y in V||(V[y]=[]),V[y].push({keyup:d,keydown:h,scope:r,mods:s,shortcut:i[l],method:o,key:i[l],splitKey:f,element:a})}if(typeof a<"u"&&typeof window<"u"){if(!ne.has(a)){const c=(E=window.event)=>sn(E,a),y=(E=window.event)=>{sn(E,a),Mo(E)};ne.set(a,{keydownListener:c,keyupListenr:y,capture:b}),it(a,"keydown",c,b),it(a,"keyup",y,b)}if(!Ce){const c=()=>{K=[]};Ce={listener:c,capture:b},it(window,"focus",c,b)}if(!ue&&typeof document<"u"){const c=()=>{K=[];for(const g in X)X[g]=!1;for(const g in q)e[g]=!1},y=c,E=c;document.addEventListener("fullscreenchange",y),document.addEventListener("webkitfullscreenchange",E),ue={fullscreen:y,webkit:E}}}};function _o(e,t="all"){Object.keys(V).forEach(n=>{V[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method({},i)})})}function st(e){const t=Object.values(V).flat();if(t.findIndex(({element:o})=>o===e)<0&&e){const{keydownListener:o,keyupListenr:i,capture:s}=ne.get(e)||{};o&&i&&(Ee(e,"keyup",i,s),Ee(e,"keydown",o,s),ne.delete(e))}if(t.length<=0||ne.size<=0){if(Array.from(ne.keys()).forEach(i=>{const{keydownListener:s,keyupListenr:r,capture:a}=ne.get(i)||{};s&&r&&(Ee(i,"keyup",r,a),Ee(i,"keydown",s,a),ne.delete(i))}),ne.clear(),Object.keys(V).forEach(i=>delete V[i]),Ce){const{listener:i,capture:s}=Ce;Ee(window,"focus",i,s),Ce=null}ue&&typeof document<"u"&&(document.removeEventListener("fullscreenchange",ue.fullscreen),document.removeEventListener("webkitfullscreenchange",ue.webkit),ue=null)}}const rt={getPressedKeyString:Ro,setScope:en,getScope:Te,deleteScope:No,getPressedKeyCodes:Lo,getAllKeyCodes:Oo,isPressed:ko,filter:tn,trigger:_o,unbind:nn,keyMap:ve,modifier:q,modifierMap:Se};for(const e in rt){const t=e;Object.prototype.hasOwnProperty.call(rt,t)&&(G[t]=rt[t])}if(typeof window<"u"){const e=window.hotkeys;G.noConflict=t=>(t&&window.hotkeys===G&&(window.hotkeys=e),G),window.hotkeys=G}async function Bo(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 rn=300,an=["up","down","left","right"],ln=Ve?"⌘+a":"ctrl+a",Io=[...an.map(e=>`shift+${e}`),ln],cn=(e,t,n,o)=>{const{store:i,selection:s}=t;let r;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:d,dismissOnNotAnnotatable:h="NEVER"}=o;let f,b=a,m="CREATE_NEW",c,y,E,g;const u=S=>{b=S,I.clear(),S||(y=void 0,c=void 0,E=void 0,g=void 0)},v=S=>m=S||"CREATE_NEW",k=S=>f=S,L=S=>r=S,C=S=>{if(m==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const M=S;return Ve?M.metaKey:M.ctrlKey}else return!1},R=()=>{if(!b||E===!1)return;const{selected:S}=s;if((C(g)||m==="REPLACE_CURRENT")&&S.length===1&&S[0].editable){const F=i.getAnnotation(S[0].id);if(F?.target){y=F.target,c={annotation:F.id,selector:[],created:y.created,creator:y.creator,updated:new Date,updatedBy:r};return}}y=void 0,c={annotation:at(),selector:[],created:new Date,creator:r}},I=So(S=>{if(!b)return;const M=document.getSelection();if(!M?.anchorNode)return;const ie=_().map(j=>ft(j,e));if(ie.every(j=>!Pe(e,j))){c=void 0;return}const se=S.timeStamp-(g?.timeStamp||S.timeStamp);if(g?.type==="pointerdown"&&(se<1e3&&!c||M.isCollapsed&&se<rn)&&R(),!c&&(R(),!c))return;if(M.isCollapsed){i.getAnnotation(c.annotation)&&!(C(g)||m==="REPLACE_CURRENT")&&(s.clear(),i.deleteAnnotation(c.annotation));return}if(ie.every(j=>lt(j)))return;const Z=ie.flatMap(j=>ut(e,j.cloneRange()));if(!(Z.length>0&&!c||Z.length!==c.selector.length||Z.some((j,xe)=>j.toString()!==c?.selector[xe]?.quote)))return;const Ue=C(g)&&y?ct([...y.selector.map(j=>j.range),...Z]):Z;c={...c,selector:Ue.map(j=>pt(j,e,l)),updated:new Date},!(C(g)||m==="REPLACE_CURRENT")&&(i.getAnnotation(c.annotation)?i.updateTarget(c,B.LOCAL):s.clear())},10),U=S=>{g=Me(S),E=g.button===0},N=async S=>{if(!E)return;const M=Me(S),F=()=>{const{x:se,y:Z}=e.getBoundingClientRect();if(ge(e,M.target)){(typeof h=="function"?h(M,e):h==="ALWAYS")&&s.clear();return}const re=M.target instanceof Node&&e.contains(M.target)&&i.getAt(M.clientX-se,M.clientY-Z,d==="all",f);if(re){const{selected:Ue}=s,j=new Set(Ue.map(Le=>Le.id)),xe=Array.isArray(re)?re.map(Le=>Le.id):[re.id];(j.size!==xe.length||!xe.every(Le=>j.has(Le)))&&(n.emit("clickAnnotation",re),s.userSelect(xe,M))}else s.clear()};if(M.timeStamp-(g?.timeStamp||0)<rn){await O();const se=document.getSelection(),Z=ge(e,g?.target),re=ge(e,M.target);if(se?.isCollapsed||Z&&re){c=void 0,F();return}}c&&c.selector.length>0&&(Y(),s.userSelect(c.annotation,M))},O=async()=>{const S=document.getSelection();let M=!1,F=S?.isCollapsed;const ie=()=>F||M,se=1;return setTimeout(()=>M=!0,50),Bo(()=>F=S?.isCollapsed,se,ie)},p=S=>{document.getSelection()?.isCollapsed||((!c||c.selector.length===0)&&I(S),c&&(Y(),s.userSelect(c.annotation,Me(S))))},A=S=>{if(b&&!S.repeat&&_().length!==0&&S.key==="Shift"&&c){const M=document.getSelection();M&&!M.isCollapsed&&(Y(),s.userSelect(c.annotation,me(S)))}},w=S=>{const M=()=>setTimeout(()=>{c&&(c.selector.length>0&&(s.clear(),i.addAnnotation({id:c.annotation,bodies:[],target:c}),s.userSelect(c.annotation,me(S))),document.removeEventListener("selectionchange",M))},100);document.addEventListener("selectionchange",M),R()};G(Io.join(","),{element:e,keydown:!0,keyup:!1},S=>{S.repeat||(g=me(S))}),G(ln,{keydown:!0,keyup:!1},S=>{g=me(S),w(S)});const T=S=>{S.repeat||_().length!==0&&(c=void 0,s.clear())};G(an.join(","),{keydown:!0,keyup:!1},T),document.addEventListener("pointerdown",U),document.addEventListener("pointerup",N),document.addEventListener("contextmenu",p),document.addEventListener("keyup",A),e.addEventListener("selectstart",R),document.addEventListener("selectionchange",I);const D=()=>{c=void 0,y=void 0,E=void 0,g=void 0,I.clear(),document.removeEventListener("pointerdown",U),document.removeEventListener("pointerup",N),document.removeEventListener("contextmenu",p),document.removeEventListener("keyup",A),e.removeEventListener("selectstart",R),document.removeEventListener("selectionchange",I),G.unbind()},_=()=>{const S=document.getSelection();return S?Array.from(Array(S.rangeCount).keys()).map(M=>S.getRangeAt(M)).filter(M=>M.intersectsNode(e)):[]},Y=()=>{if(!c)return;const S=i.getAnnotation(c.annotation);if(!S)i.addAnnotation({id:c.annotation,bodies:[],target:c});else{const{target:{updated:M}}=S,{updated:F}=c;(!M||!F||M<F)&&i.updateTarget(c)}};return{destroy:D,setFilter:k,setUser:L,setAnnotatingEnabled:u,setAnnotatingMode:v}},Do=e=>[`background-color:${W(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(";"),Yo=()=>{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,d)=>{const h=new Set(s.map(b=>b.annotation.id));Array.from(t).filter(b=>!h.has(b));const f=s.map(b=>{a?typeof a=="function"&&a(b.annotation,b.state):b.state?.selected;const m=Ze(b,a);return`::highlight(_${b.annotation.id}) { ${Do(m)} }`});e.innerHTML=f.join(`
|
|
2
|
-
`),CSS.highlights.clear(),s.forEach(({annotation:
|
|
1
|
+
(function(L,he){typeof exports=="object"&&typeof module<"u"?he(exports):typeof define=="function"&&define.amd?define(["exports"],he):(L=typeof globalThis<"u"?globalThis:L||self,he(L.RecogitoJS={}))})(this,(function(L){"use strict";const he=e=>e.target.selector.every(Z),fn=e=>e.selector.every(Z);function Z(e){return Array.isArray(e)?e.every(t=>"range"in t&&t.range instanceof Range&&!t.range.collapsed):"range"in e&&e.range instanceof Range&&!e.range.collapsed}const P=[];for(let e=0;e<256;++e)P.push((e+256).toString(16).slice(1));function hn(e,t=0){return(P[e[t+0]]+P[e[t+1]]+P[e[t+2]]+P[e[t+3]]+"-"+P[e[t+4]]+P[e[t+5]]+"-"+P[e[t+6]]+P[e[t+7]]+"-"+P[e[t+8]]+P[e[t+9]]+"-"+P[e[t+10]]+P[e[t+11]]+P[e[t+12]]+P[e[t+13]]+P[e[t+14]]+P[e[t+15]]).toLowerCase()}const gn=new Uint8Array(16);function pn(){return crypto.getRandomValues(gn)}function rt(e,t,n){return crypto.randomUUID?crypto.randomUUID():mn(e)}function mn(e,t,n){e=e||{};const o=e.random??e.rng?.()??pn();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,hn(o)}const Ke=typeof navigator<"u"&&navigator.platform.startsWith("Mac"),Ve="not-annotatable",re=`.${Ve}`,ge=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(re):t.parentElement?.closest(re)):!0,Xe=(e,t)=>{const n=t.commonAncestorContainer;return!ge(e,n)},Pe=/^\s*$/,at=e=>Pe.test(e.toString()),yn=e=>Pe.test(e.textContent||""),lt=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]},ct=e=>{(!e.hasAttribute("tabindex")||e.tabIndex<-1)&&e.setAttribute("tabindex","-1"),e.classList.add("no-focus-outline")},bn=function*(e){const t=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(Ve)&&!o.parentElement?.closest(re)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},dt=(e,t)=>{if(!Xe(e,t))return[];const n=[];let o=null;for(const i of bn(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]},Oe=e=>{const t=e.cloneContents();return t.querySelectorAll(re).forEach(n=>n.remove()),t},ut=(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},ft=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ht=(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=Oe(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=Oe(a).textContent,d=[...ft.segment(r)],f=[...ft.segment(l)];return{prefix:d.slice(-n).map(u=>u.segment).join(""),suffix:f.slice(0,n).map(u=>u.segment).join("")}},gt=(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=Oe(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}},pt=(e,t)=>{if(Z(e))return e;const{start:n,end:o}=e,i=e.offsetReference||t,s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,f=>f.parentElement?.closest(re)?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 d=!i;for(;l!==null;){if(d||=typeof i?.contains=="function"?i.contains(l):!1,d){const f=l.textContent?.length||0;if(r+f>n){a.setStart(l,n-r);break}r+=f}l=s.nextNode()}for(;l!==null;){const f=l.textContent?.length||0;if(r+f>=o){a.setEnd(l,o-r);break}r+=f,l=s.nextNode()}return{...e,range:a}},pe=(e,t,n=(o,i)=>pt(o,i))=>({...e,selector:e.selector.flatMap(o=>n(o,t))}),me=(e,t,n)=>({...e,target:pe(e.target,t,n)}),mt=e=>{if(!e)return document.scrollingElement;const{overflowY:t}=window.getComputedStyle(e);return t!=="visible"&&t!=="hidden"&&e.scrollHeight>e.clientHeight?e:mt(e.parentElement)},yt=(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),d=r.top-o.top,f=r.left-o.left,u=n.parentElement?n.scrollTop:0,y=n.parentElement?n.scrollLeft:0,g=d+u-(i-l)/2,c=f+y-(s-a)/2;n.scroll({top:g,left:c,behavior:"smooth"})},bt=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,s=o?typeof o=="string"?document.getElementById(o):o:mt(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 yt(t,r.target,s),!0;const l=pe(r.target,e),{range:d}=l.selector[0];return d&&!d.collapsed?(yt(t,l,s),!0):!1};var At=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(At.call(e,n)&&++o&&!At.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 An=Symbol("clean");let Q=[],oe=0;const ke=4,wn=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),$e=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+ke;s<Q.length;)Q[s]===o?Q.splice(s,ke):s+=ke;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){wn.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+=ke)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[An]=()=>{t=[],n.lc=0,n.off()}),n},En=e=>{const t=$e(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 He=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(He||{});const je={selected:[]},vn=(e,t,n)=>{const o=$e(je);let i=t;const s=()=>{ae(o.get(),je)||o.set(je)},r=()=>{var g;return((g=o.get().selected)==null?void 0:g.length)===0},a=g=>{if(r())return!1;const c=typeof g=="string"?g:g.id;return o.get().selected.some(m=>m.id===c)},l=(g,c)=>{let m;if(Array.isArray(g)){if(m=g.map(h=>e.getAnnotation(h)).filter(Boolean),m.length<g.length){console.warn("Invalid selection: "+g.filter(h=>!m.some(p=>p.id===h)));return}}else{const h=e.getAnnotation(g);if(!h){console.warn("Invalid selection: "+g);return}m=[h]}const S=m.reduce((h,p)=>{const x=y(p);return x==="EDIT"?[...h,{id:p.id,editable:!0}]:x==="SELECT"?[...h,{id:p.id}]:h},[]);o.set({selected:S,event:c})},d=(g,c)=>{const m=Array.isArray(g)?g:[g],S=m.map(h=>e.getAnnotation(h)).filter(h=>!!h);o.set({selected:S.map(h=>{const p=c===void 0?y(h)==="EDIT":c;return{id:h.id,editable:p}})}),S.length!==m.length&&console.warn("Invalid selection",g)},f=g=>{if(r())return!1;const{selected:c}=o.get();c.some(({id:m})=>g.includes(m))&&o.set({selected:c.filter(({id:m})=>!g.includes(m))})},u=g=>{i=g,d(o.get().selected.map(({id:c})=>c))},y=g=>Sn(g,i,n);return e.observe(({changes:g})=>f((g.deleted||[]).map(c=>c.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:y,isEmpty:r,isSelected:a,setSelected:d,setUserSelectAction:u,subscribe:o.subscribe.bind(o),userSelect:l}},Sn=(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 Cn(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 Tn=new Uint8Array(16);function xn(){return crypto.getRandomValues(Tn)}function wt(e,t,n){return crypto.randomUUID?crypto.randomUUID():Ln(e)}function Ln(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??xn();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,Cn(i)}const Fe=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)}},Rn=(e,t,n,o)=>({id:wt(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),On=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},kn=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Mn=(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})),Nn=(e,t)=>!ae(e.target,t.target),Et=(e,t)=>{const n=On(e,t),o=kn(e,t),i=Mn(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:Nn(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var _=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(_||{});const Bn=(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(f=>a(f.bodiesCreated)||a(f.bodiesDeleted)||a(f.bodiesUpdated)),d=(o=i.updated)==null?void 0:o.some(f=>f.targetUpdated);if(r==="BODY_ONLY"&&l&&!d||r==="TARGET_ONLY"&&d&&!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},_n=(e,t)=>{const n=new Set((e.created||[]).map(u=>u.id)),o=new Set((e.updated||[]).map(({newValue:u})=>u.id)),i=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),r=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>n.has(u.id)||o.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(e.created||[]).filter(u=>!s.has(u.id)).map(u=>r.has(u.id)?t.updated.find(({oldValue:y})=>y.id===u.id).newValue:u),...t.created||[]],d=[...(e.deleted||[]).filter(u=>!i.has(u.id)),...(t.deleted||[]).filter(u=>!n.has(u.id))],f=[...(e.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:y,newValue:g}=u;if(r.has(g.id)){const c=t.updated.find(m=>m.oldValue.id===g.id).newValue;return Et(y,c)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:d,updated:f}},We=e=>{const t=e.id===void 0?wt():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},In=e=>e.id!==void 0,Dn=()=>{const e=new Map,t=new Map,n=[],o=(b,w={})=>{n.push({onChange:b,options:w})},i=b=>{const w=n.findIndex(E=>E.onChange==b);w>-1&&n.splice(w,1)},s=(b,w)=>{const E={origin:b,changes:{created:w.created||[],updated:w.updated||[],deleted:w.deleted||[]},state:[...e.values()]};n.forEach(T=>{Bn(T,E)&&T.onChange(E)})},r=b=>{e.set(b.id,b),b.bodies.forEach(w=>t.set(w.id,b.id))},a=(b,w=_.LOCAL)=>{if(b.id&&e.get(b.id))throw Error(`Cannot add annotation ${b.id} - exists already`);{const E=We(b);r(E),s(w,{created:[E]})}},l=(b,w)=>{const E=We(typeof b=="string"?w:b),T=typeof b=="string"?b:b.id,v=T&&e.get(T);if(v){const O=Et(v,E);return T===E.id?e.set(T,E):(e.delete(T),e.set(E.id,E)),v.bodies.forEach(K=>t.delete(K.id)),E.bodies.forEach(K=>t.set(K.id,E.id)),O}else console.warn(`Cannot update annotation ${T} - does not exist`)},d=(b,w=_.LOCAL,E=_.LOCAL)=>{const T=In(w)?E:w,v=l(b,w);v&&s(T,{updated:[v]})},f=(b,w=_.LOCAL)=>{e.get(b.id)?d(b,w):a(b,w)},u=(b,w=_.LOCAL)=>{const E=b.reduce((T,v)=>{const O=l(v);return O?[...T,O]:T},[]);E.length>0&&s(w,{updated:E})},y=b=>b.map(We).reduce((w,E)=>e.get(E.id)?{...w,toUpdate:[...w.toUpdate,E]}:{...w,toAdd:[...w.toAdd,E]},{toAdd:[],toUpdate:[]}),g=(b,w=_.LOCAL)=>{const{toAdd:E,toUpdate:T}=y(b),v=T.map(O=>l(O,w)).filter(Boolean);E.forEach(r),s(w,{created:E,updated:v})},c=(b,w=_.LOCAL)=>{const E=e.get(b.annotation);if(E){const T={...E,bodies:[...E.bodies,b]};e.set(E.id,T),t.set(b.id,T.id),s(w,{updated:[{oldValue:E,newValue:T,bodiesCreated:[b]}]})}else console.warn(`Attempt to add body to missing annotation: ${b.annotation}`)},m=()=>[...e.values()],S=(b=_.LOCAL)=>{const w=[...e.values()];e.clear(),t.clear(),s(b,{deleted:w})},h=(b,w=_.LOCAL)=>{const{toAdd:E,toUpdate:T}=y(b),v=new Set([...E,...T].map(H=>H.id)),O=[...e.keys()].filter(H=>!v.has(H)).map(H=>x(H)).filter(Boolean),K=T.map(H=>l(H)).filter(Boolean);E.forEach(r),s(w,{created:E,updated:K,deleted:O})},p=(b,w=!0,E=_.LOCAL)=>{w?h(b,E):g(b,E)},x=b=>{const w=typeof b=="string"?b:b.id,E=e.get(w);if(E)return e.delete(w),E.bodies.forEach(T=>t.delete(T.id)),E;console.warn(`Attempt to delete missing annotation: ${w}`)},Y=(b,w=_.LOCAL)=>{const E=x(b);E&&s(w,{deleted:[E]})},A=(b,w=_.LOCAL)=>{const E=b.reduce((T,v)=>{const O=x(v);return O?[...T,O]:T},[]);E.length>0&&s(w,{deleted:E})},C=b=>{const w=e.get(b.annotation);if(w){const E=w.bodies.find(T=>T.id===b.id);if(E){t.delete(E.id);const T={...w,bodies:w.bodies.filter(v=>v.id!==b.id)};return e.set(w.id,T),{oldValue:w,newValue:T,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${b.annotation}`)},k=(b,w=_.LOCAL)=>{const E=C(b);E&&s(w,{updated:[E]})},R=(b,w=_.LOCAL)=>{const E=b.map(T=>C(T)).filter(Boolean);E.length>0&&s(w,{updated:E})},B=b=>{const w=e.get(b);return w?{...w}:void 0},M=b=>{const w=t.get(b);if(w){const E=B(w).bodies.find(T=>T.id===b);if(E)return E;console.error(`Store integrity error: body ${b} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${b}`)},N=(b,w)=>{if(b.annotation!==w.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=e.get(b.annotation);if(E){const T=E.bodies.find(O=>O.id===b.id),v={...E,bodies:E.bodies.map(O=>O.id===T.id?w:O)};return e.set(E.id,v),T.id!==w.id&&(t.delete(T.id),t.set(w.id,v.id)),{oldValue:E,newValue:v,bodiesUpdated:[{oldBody:T,newBody:w}]}}else console.warn(`Attempt to add body to missing annotation ${b.annotation}`)},D=(b,w,E=_.LOCAL)=>{const T=N(b,w);T&&s(E,{updated:[T]})},F=(b,w=_.LOCAL)=>{const E=b.map(T=>N({id:T.id,annotation:T.annotation},T)).filter(Boolean);s(w,{updated:E})},le=b=>{const w=e.get(b.annotation);if(w){const E={...w,target:{...w.target,...b}};return e.set(w.id,E),{oldValue:w,newValue:E,targetUpdated:{oldTarget:w.target,newTarget:b}}}else console.warn(`Attempt to update target on missing annotation: ${b.annotation}`)};return{addAnnotation:a,addBody:c,all:m,bulkAddAnnotations:p,bulkDeleteAnnotations:A,bulkDeleteBodies:R,bulkUpdateAnnotations:u,bulkUpdateBodies:F,bulkUpdateTargets:(b,w=_.LOCAL)=>{const E=b.map(T=>le(T)).filter(Boolean);E.length>0&&s(w,{updated:E})},bulkUpsertAnnotations:g,clear:S,deleteAnnotation:Y,deleteBody:k,getAnnotation:B,getBody:M,observe:o,syncAnnotations:h,unobserve:i,updateAnnotation:d,updateBody:D,updateTarget:(b,w=_.LOCAL)=>{const E=le(b);E&&s(w,{updated:[E]})},upsertAnnotation:f}};let Un=()=>({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 Yn=250,Kn=(e,t)=>{const n=Un(),o=[];let i=-1,s=!1,r=0;const a=c=>{if(!s){const{changes:m}=c,S=performance.now();if(S-r>Yn)o.splice(i+1),o.push(m),i=o.length-1;else{const h=o.length-1;o[h]=_n(o[h],m)}r=S}s=!1};e.observe(a,{origin:_.LOCAL});const l=c=>c&&c.length>0&&e.bulkDeleteAnnotations(c),d=c=>c&&c.length>0&&e.bulkUpsertAnnotations(c),f=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({oldValue:m})=>m)),u=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({newValue:m})=>m)),y=c=>c&&c.length>0&&e.bulkUpsertAnnotations(c),g=c=>c&&c.length>0&&e.bulkDeleteAnnotations(c);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...o],pointer:i}),on:(c,m)=>n.on(c,m),redo:()=>{if(o.length-1>i){s=!0;const{created:c,updated:m,deleted:S}=o[i+1];d(c),u(m),g(S),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:c,updated:m,deleted:S}=o[i];l(c),f(m),y(S),n.emit("undo",o[i]),i-=1}}}},Vn=()=>{const e=$e([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Xn=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:a}=e,l=new Map;let d=[],f;const u=(m,S)=>{l.has(m)?l.get(m).push(S):l.set(m,[S])},y=(m,S)=>{const h=l.get(m);if(h){const p=h.indexOf(S);p!==-1&&h.splice(p,1)}},g=(m,S,h)=>{l.has(m)&&setTimeout(()=>{l.get(m).forEach(p=>{if(n){const x=Array.isArray(S)?S.map(A=>n.serialize(A)):n.serialize(S),Y=h?h instanceof PointerEvent?h:n.serialize(h):void 0;p(x,Y)}else p(S,h)})},1)};s.subscribe(({selected:m})=>{if(!(d.length===0&&m.length===0)){if(d.length===0&&m.length>0)d=m.map(({id:S})=>r.getAnnotation(S));else if(d.length>0&&m.length===0)d.forEach(S=>{const h=r.getAnnotation(S.id);h&&!ae(h,S)&&g("updateAnnotation",h,S)}),d=[];else{const S=new Set(d.map(p=>p.id)),h=new Set(m.map(({id:p})=>p));d.filter(p=>!h.has(p.id)).forEach(p=>{const x=r.getAnnotation(p.id);x&&!ae(x,p)&&g("updateAnnotation",x,p)}),d=[...d.filter(p=>h.has(p.id)),...m.filter(({id:p})=>!S.has(p)).map(({id:p})=>r.getAnnotation(p))]}g("selectionChanged",d)}}),i.subscribe(m=>{!f&&m?g("mouseEnterAnnotation",r.getAnnotation(m)):f&&!m?g("mouseLeaveAnnotation",r.getAnnotation(f)):f&&m&&(g("mouseLeaveAnnotation",r.getAnnotation(f)),g("mouseEnterAnnotation",r.getAnnotation(m))),f=m}),a?.subscribe(m=>g("viewportIntersect",m.map(S=>r.getAnnotation(S)))),r.observe(m=>{const{created:S,deleted:h}=m.changes;(S||[]).forEach(p=>g("createAnnotation",p)),(h||[]).forEach(p=>g("deleteAnnotation",p)),(m.changes.updated||[]).filter(p=>[...p.bodiesCreated||[],...p.bodiesDeleted||[],...p.bodiesUpdated||[]].length>0).forEach(({oldValue:p,newValue:x})=>{const Y=d.find(A=>A.id===p.id)||p;d=d.map(A=>A.id===p.id?x:A),g("updateAnnotation",x,Y)})},{origin:_.LOCAL}),r.observe(m=>{if(d){const S=new Set(d.map(p=>p.id)),h=(m.changes.updated||[]).filter(({newValue:p})=>S.has(p.id)).map(({newValue:p})=>p);h.length>0&&(d=d.map(p=>h.find(Y=>Y.id===p.id)||p))}},{origin:_.REMOTE});const c=m=>S=>{const{updated:h}=S;m?(h||[]).forEach(p=>g("updateAnnotation",p.oldValue,p.newValue)):(h||[]).forEach(p=>g("updateAnnotation",p.newValue,p.oldValue))};return t.on("undo",c(!0)),t.on("redo",c(!1)),{on:u,off:y,emit:g}},Pn=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:[]}),$n=(e,t,n)=>{const{store:o,selection:i}=e,s=h=>{if(n){const{parsed:p,error:x}=n.parse(h);p?o.addAnnotation(p,_.REMOTE):console.error(x)}else o.addAnnotation(Fe(h),_.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=h=>{const p=o.getAnnotation(h);return n&&p?n.serialize(p):p},d=()=>n?o.all().map(n.serialize):o.all(),f=()=>{var h;const p=(((h=i.selected)==null?void 0:h.map(x=>x.id))||[]).map(x=>o.getAnnotation(x)).filter(Boolean);return n?p.map(n.serialize):p},u=(h,p=!0)=>fetch(h).then(x=>x.json()).then(x=>(g(x,p),x)),y=h=>{if(typeof h=="string"){const p=o.getAnnotation(h);if(o.deleteAnnotation(h),p)return n?n.serialize(p):p}else{const p=n?n.parse(h).parsed:h;if(p)return o.deleteAnnotation(p),h}},g=(h,p=!0)=>{const x=p?o.syncAnnotations:o.bulkUpsertAnnotations;if(n){const Y=n.parseAll||Pn(n),{parsed:A,failed:C}=Y(h);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),x(A,_.REMOTE)}else x(h.map(Fe),_.REMOTE)},c=(h,p)=>{h?i.setSelected(h,p):i.clear()},m=h=>{i.setUserSelectAction(h)},S=h=>{if(n){const p=n.parse(h).parsed,x=n.serialize(o.getAnnotation(p.id));return o.updateAnnotation(p),x}else{const p=o.getAnnotation(h.id);return o.updateAnnotation(Fe(h)),p}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:d,getHistory:t.getHistory,getSelected:f,loadAnnotations:u,redo:t.redo,removeAnnotation:y,setAnnotations:g,setSelected:c,setUserSelectAction:m,undo:t.undo,updateAnnotation:S}};let Hn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",jn=e=>crypto.getRandomValues(new Uint8Array(e)),Fn=(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),d=r;for(;d--;)if(a+=e[l[d]&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}}},Wn=(e,t=21)=>Fn(e,t|0,jn),zn=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Hn[n[e]&63];return t};const qn=()=>({isGuest:!0,id:Wn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Gn=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}`},vt=e=>e?typeof e=="object"?{...e}:e:void 0,Qn=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,modified:l,creator:d,...f}=n;return{id:o||`temp-${Gn(n)}`,annotation:t,type:i,purpose:s,value:r,creator:vt(d),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...f}}),Jn=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});globalThis.ANNOTORIOUS_PRESENCE_KEY||(globalThis.ANNOTORIOUS_PRESENCE_KEY=zn());const Zn=(e,t)=>({parse:n=>St(n),serialize:n=>Ct(n,e,t)}),eo=e=>e.quote!==void 0&&e.start!==void 0&&e.end!==void 0,to=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:vt(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 f=(Array.isArray(l.selector)?l.selector:[l.selector]).reduce((u,y)=>{switch(y.type){case"TextQuoteSelector":u.quote=y.exact;break;case"TextPositionSelector":u.start=y.start,u.end=y.end;break}return u},{});if(eo(f))a.selector.push({...f,id:l.id,scope:l.scope});else{const u=[f.start?void 0:"TextPositionSelector",f.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${u.join(" and ")} for annotation: ${e.id}`)}}}return{parsed:a}},St=e=>{const t=e.id||rt(),{creator:n,created:o,modified:i,body:s,...r}=e,a=Qn(s,t),l=to(e);return"error"in l?{error:l.error}:{parsed:{...r,id:t,bodies:a,target:l.parsed}}},Ct=(e,t,n)=>{const{bodies:o,target:i,...s}=e,{selector:r,creator:a,created:l,updated:d,...f}=i,u=r.map(y=>{const{id:g,quote:c}=y,m={type:"TextQuoteSelector",exact:c};if(n&&"range"in y){const{prefix:x,suffix:Y}=ht(y.range,n);m.prefix=x,m.suffix=Y}if(!("start"in y))throw new Error("W3C serialization requires TextSelector with start/end");const{start:S,end:h}=y,p={type:"TextPositionSelector",start:S,end:h};return{...f,id:g,scope:"scope"in y?y.scope:void 0,source:t,selector:[m,p]}});return{...s,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Jn(e.bodies),creator:a,created:l?.toISOString(),modified:d?.toISOString(),target:u}};let Tt=()=>({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 xt=e=>e.addEventListener("click",t=>{!t.target.closest(re)&&!t.target.closest("a")&&t.preventDefault()}),Me=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}),ye=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}),Ne=(e,t=10)=>{let n;return((...o)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,o),t)})},ze=(e,t,n,o)=>{const{store:i,selection:s,hover:r}=n,a=Tt();let l;const d=new Map;let f;const u=Ft(o),y=M=>{const{x:N,y:D}=t.getBoundingClientRect(),F=i.getAt(M.clientX-N,M.clientY-D,!1,f);F&&n.selection.evalSelectAction(F)!==He.NONE?r.current!==F.id&&(t.classList.add("hovered"),r.set(F.id)):r.current&&(t.classList.remove("hovered"),r.set(null))};t.addEventListener("pointermove",y);const g=Ne((M=!1)=>requestAnimationFrame(()=>{const N=jt(t),{minX:D,minY:F,maxX:le,maxY:b}=N,w=f?i.getIntersecting(D,F,le,b).filter(({annotation:v})=>f?.(v)):i.getIntersecting(D,F,le,b),E=s.selected.map(({id:v})=>v),T=w.map(({annotation:v,rects:O})=>{const K=E.includes(v.id),H=v.id===r.current;return{annotation:v,rects:O,state:{selected:K,hovered:H}}});e.redraw(T,N,l,d,M),setTimeout(()=>{u(w.map(({annotation:v})=>v)),a.emit("onRedraw")},1)}),10),c=(M,N)=>{N?M?d.set(N,M):d.delete(N):l=M,g(!0)},m=M=>{f=M,g(!1)},S=(M,N)=>a.on(M,N),h=()=>{g()};i.observe(h);const p=s.subscribe(()=>{g()}),x=r.subscribe(()=>{g()}),Y=()=>{g(!0)};document.addEventListener("scroll",Y,{capture:!0,passive:!0});const A=Ne(()=>{i.recalculatePositions(),g()},10);window.addEventListener("resize",A);const C=new ResizeObserver(A);C.observe(t);const k={attributes:!0,childList:!0,subtree:!0},R=new MutationObserver(Ne(M=>{M.every(D=>D.target===t||t.contains(D.target))||g(!0)},150));return R.observe(document.body,k),{destroy:()=>{t.removeEventListener("pointermove",y),e.destroy(),i.unobserve(h),p(),x(),document.removeEventListener("scroll",Y),window.removeEventListener("resize",A),C.disconnect(),R.disconnect()},on:S,redraw:g,setStyle:c,setFilter:m,setVisible:e.setVisible.bind(e)}};var no={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},W=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},Lt=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},Rt=function(e){return{r:W(e.r,0,255),g:W(e.g,0,255),b:W(e.b,0,255),a:W(e.a)}},qe=function(e){return{r:X(e.r),g:X(e.g),b:X(e.b),a:X(e.a,3)}},oo=/^#([0-9a-f]{3,8})$/i,Be=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},Ot=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}},kt=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),d=s%6;return{r:255*[o,a,r,r,l,o][d],g:255*[l,o,o,a,r,r][d],b:255*[r,r,l,o,o,a][d],a:i}},Mt=function(e){return{h:Lt(e.h),s:W(e.s,0,100),l:W(e.l,0,100),a:W(e.a)}},Nt=function(e){return{h:X(e.h),s:X(e.s),l:X(e.l),a:X(e.a,3)}},Bt=function(e){return kt((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},be=function(e){return{h:(t=Ot(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},io=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,so=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ro=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ao=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,_t={string:[[function(e){var t=oo.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=ro.exec(e)||ao.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Rt({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=io.exec(e)||so.exec(e);if(!t)return null;var n,o,i=Mt({h:(n=t[1],o=t[2],o===void 0&&(o="deg"),Number(n)*(no[o]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return Bt(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)?Rt({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=Mt({h:Number(t),s:Number(n),l:Number(o),a:Number(s)});return Bt(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:Lt(a.h),s:W(a.s,0,100),v:W(a.v,0,100),a:W(a.a)}})({h:Number(t),s:Number(n),v:Number(o),a:Number(s)});return kt(r)},"hsv"]]},It=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]},lo=function(e){return typeof e=="string"?It(e.trim(),_t.string):typeof e=="object"&&e!==null?It(e,_t.object):[null,void 0]},Ge=function(e,t){var n=be(e);return{h:n.h,s:W(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},Dt=function(e,t){var n=be(e);return{h:n.h,s:n.s,l:W(n.l+100*t,0,100),a:n.a}},Ut=(function(){function e(t){this.parsed=lo(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=qe(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 qe(this.rgba)},e.prototype.toRgbString=function(){return t=qe(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 Nt(be(this.rgba))},e.prototype.toHslString=function(){return t=Nt(be(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=Ot(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(Ge(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),z(Ge(this.rgba,-t))},e.prototype.grayscale=function(){return z(Ge(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),z(Dt(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),z(Dt(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=be(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 Ut?e:new Ut(e)};const te={fill:"rgb(0, 128, 255)",fillOpacity:.18},_e={fill:"rgb(0, 128, 255)",fillOpacity:.45},Yt=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(),Je=(e,t,n)=>t?typeof t=="function"?t(e.annotation,e.state,n)||(e.state?.selected?_e:te):t:e.state?.selected?_e:te;var Kt=Object.prototype.hasOwnProperty;function Ze(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--&&Ze(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Kt.call(e,n)&&++o&&!Kt.call(t,n)||!(n in t)||!Ze(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Vt=(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))},Xt=e=>{const t=[],n=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_TEXT);e.startContainer.nodeType===Node.TEXT_NODE&&(n.currentNode=e.startContainer,e.intersectsNode(e.startContainer)&&t.push(e.startContainer));let o=t.length>0,i;for(;i=n.nextNode();)if(e.intersectsNode(i))o=!0,t.push(i);else if(o)break;if(t.length<2)return Array.from(e.getClientRects());{const s=t[0],r=t[t.length-1],a=document.createRange();if(a.selectNode(s),e.startContainer.nodeType===Node.TEXT_NODE)a.setStart(s,e.startOffset);else{const f=e.startContainer.childNodes[e.startOffset];f?a.setStartBefore(f):a.setStartAfter(e.startContainer)}const l=document.createRange();if(l.selectNode(r),e.endContainer.nodeType===Node.TEXT_NODE)l.setEnd(r,e.endOffset);else{const f=e.endContainer.childNodes[e.endOffset];f?l.setEndBefore(f):l.setEndAfter(e.endContainer)}const d=f=>{const u=document.createRange();return u.selectNode(f),Array.from(u.getClientRects())};return[...Array.from(a.getClientRects()),...t.slice(1,-1).flatMap(d),...Array.from(l.getClientRects())]}},co=(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"},uo=(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)},Pt=(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=co(i,a,t,n);if(l==="inline-adjacent"){s=s.map(d=>d===a?uo(i,a):d),r=!0;break}else if(l==="inline-contains"){s=s.map(d=>d===a?i:d),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(d=>d===a?i:d)),i.width===a.width&&i.height<a.width&&(s=s.map(d=>d===a?i:d)),r=!0;break}}return r?s:[...s,i]},[]),fo=e=>({length:e.length,item:t=>e[t],[Symbol.iterator]:function*(){for(let t=0;t<this.length;t++)yield this.item(t)}}),$t=(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)},ho=(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)},go=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,d,f)=>{if(!(!Ze(n,r)||f))return;t.innerHTML="",[...r].sort((c,m)=>{const{annotation:{target:{created:S}}}=c,{annotation:{target:{created:h}}}=m;return S&&h?S.getTime()-h.getTime():0}).forEach(c=>{const m=d?.get(c.annotation.id)||l;c.rects.map(S=>{const h=Vt(S,r),p=Je(c,m,h),x=document.createElement("span");x.className="r6o-annotation",x.dataset.annotation=c.annotation.id,x.style.left=`${S.x}px`,x.style.top=`${S.y}px`,x.style.width=`${S.width}px`,x.style.height=`${S.height}px`,x.style.backgroundColor=Yt(p),p.underlineStyle&&(x.style.borderStyle=p.underlineStyle),p.underlineColor&&(x.style.borderColor=p.underlineColor),p.underlineThickness&&(x.style.borderBottomWidth=`${p.underlineThickness}px`),p.underlineOffset&&(x.style.paddingBottom=`${p.underlineOffset}px`),t.appendChild(x)})}),n=r},setVisible:r=>{r?t.classList.remove("hidden"):t.classList.add("hidden")}}},Ht=(e,t,n)=>ze(go(e),e,t,n),jt=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}},Ft=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 Wt(e,t,n=0,o=e.length-1,i=po){for(;o>n;){if(o-n>600){const l=o-n+1,d=t-n+1,f=Math.log(l),u=.5*Math.exp(2*f/3),y=.5*Math.sqrt(f*u*(l-u)/l)*(d-l/2<0?-1:1),g=Math.max(n,Math.floor(t-d*u/l+y)),c=Math.min(o,Math.floor(t+(l-d)*u/l+y));Wt(e,t,g,c,i)}const s=e[t];let r=n,a=o;for(Ae(e,n,t),i(e[o],s)>0&&Ae(e,n,o);r<a;){for(Ae(e,r,a),r++,a--;i(e[r],s)<0;)r++;for(;i(e[a],s)>0;)a--}i(e[n],s)===0?Ae(e,n,a):(a++,Ae(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function Ae(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function po(e,t){return e<t?-1:e>t?1:0}class mo{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(!De(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;De(t,l)&&(n.leaf?o.push(a):tt(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!De(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(De(t,r)){if(n.leaf||tt(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,d;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],a=r.pop(),d=!0),o.leaf){const f=yo(t,o.children,n);if(f!==-1)return o.children.splice(f,1),s.push(o),this._condense(s),this}!d&&!o.leaf&&tt(o,i)?(s.push(o),r.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],d=!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),d=l*Math.ceil(Math.sqrt(r));zt(t,n,o,d,this.compareMinX);for(let f=n;f<=o;f+=d){const u=Math.min(f+d-1,o);zt(t,f,u,l,this.compareMinY);for(let y=f;y<=u;y+=l){const g=Math.min(y+l-1,u);a.children.push(this._build(t,y,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 d=n.children[l],f=et(d),u=wo(t,d)-f;u<r?(r=u,s=f<s?f:s,a=d):u===r&&f<s&&(s=f,a=d)}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),Ee(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=we(t,0,a,this.toBBox),d=we(t,a,o,this.toBBox),f=Eo(l,d),u=et(l)+et(d);f<s?(s=f,i=a,r=u<r?u:r):f===s&&u<r&&(r=u,i=a)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:bo,s=t.leaf?this.compareMinY:Ao,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=we(t,0,n,s),a=we(t,o-n,o,s);let l=Ie(r)+Ie(a);for(let d=n;d<o-n;d++){const f=t.children[d];Ee(r,t.leaf?s(f):f),l+=Ie(r)}for(let d=o-n-1;d>=n;d--){const f=t.children[d];Ee(a,t.leaf?s(f):f),l+=Ie(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)Ee(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 yo(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){we(e,0,e.children.length,t,e)}function we(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];Ee(i,e.leaf?o(r):r)}return i}function Ee(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 bo(e,t){return e.minX-t.minX}function Ao(e,t){return e.minY-t.minY}function et(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ie(e){return e.maxX-e.minX+(e.maxY-e.minY)}function wo(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 Eo(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 tt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function De(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 zt(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;Wt(e,r,t,n,i),s.push(t,r,r,n)}}const vo=(e,t,n,o)=>{const i=new mo,s=new Map,r=Tt(),a=(A,C)=>{const k=A.selector.flatMap(B=>Xt(B.range)),R=Pt(k,n,o).map(B=>$t(B,C));return R.map(B=>{const{x:M,y:N,width:D,height:F}=B;return{minX:M,minY:N,maxX:M+D,maxY:N+F,annotation:{id:A.annotation,rects:R}}})},l=()=>[...s.values()],d=()=>{i.clear(),s.clear()},f=A=>{const C=a(A,t.getBoundingClientRect());C.length!==0&&(C.forEach(k=>i.insert(k)),s.set(A.annotation,C))},u=A=>{const C=s.get(A.annotation);C&&(C.forEach(k=>i.remove(k)),s.delete(A.annotation))},y=A=>{u(A),f(A)},g=(A,C=!0)=>{C&&d();const k=t.getBoundingClientRect(),R=A.map(M=>({target:M,rects:a(M,k)}));R.forEach(({target:M,rects:N})=>{N.length>0&&s.set(M.annotation,N)});const B=R.flatMap(({rects:M})=>M);i.load(B)},c=(A,C,k=!1)=>{const R=i.search({minX:A,minY:C,maxX:A,maxY:C}),B=M=>M.annotation.rects.reduce((N,D)=>N+D.width*D.height,0);return R.length>0?(R.sort((M,N)=>B(M)-B(N)),k?R.map(M=>M.annotation.id):[R[0].annotation.id]):[]},m=A=>{const C=S(A);if(C.length===0)return;let k=C[0].left,R=C[0].top,B=C[0].right,M=C[0].bottom;for(let N=1;N<C.length;N++){const D=C[N];k=Math.min(k,D.left),R=Math.min(R,D.top),B=Math.max(B,D.right),M=Math.max(M,D.bottom)}return new DOMRect(k,R,B-k,M-R)},S=A=>{const C=s.get(A);return C?C[0].annotation.rects:[]};return{all:l,clear:d,getAt:c,getAnnotationBounds:m,getAnnotationRects:S,getIntersecting:(A,C,k,R)=>{const B=i.search({minX:A,minY:C,maxX:k,maxY:R}),M=new Set(B.map(N=>N.annotation.id));return Array.from(M).map(N=>({annotation:e.getAnnotation(N),rects:S(N)})).filter(N=>!!N.annotation)},insert:f,recalculate:()=>{g(e.all().map(A=>A.target),!0),r.emit("recalculate")},remove:u,set:g,size:()=>i.all().length,update:y,on:(A,C)=>r.on(A,C)}},qt=(e,t)=>{const n=Dn(),o=vo(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance),i=vn(n,t.userSelectAction,t.adapter),s=En(n),r=Vn(),a=A=>{const C=A.map(R=>me(R,e,t.selectorReviveFn)),k=C.filter(R=>!Z(R.target.selector));return{revived:C,couldNotRevive:k}},l=(A,C=_.LOCAL)=>{const k=me(A,e,t.selectorReviveFn),R=Z(k.target.selector);return R&&n.addAnnotation(k,C),R},d=(A,C=_.LOCAL)=>{const{revived:k,couldNotRevive:R}=a(A);return n.syncAnnotations(k,C),R},f=(A,C=!0,k=_.LOCAL)=>C?d(A,k):y(A,k),u=(A,C,k)=>{if(typeof A=="string"){const R=me(C,e,t.selectorReviveFn);n.updateAnnotation(A,R,k)}else{const R=me(A,e,t.selectorReviveFn);n.updateAnnotation(R,C)}},y=(A,C=_.LOCAL)=>{const{revived:k,couldNotRevive:R}=a(A);return n.bulkUpsertAnnotations(k,C),R},g=(A,C=_.LOCAL)=>{const k=pe(A,e,t.selectorReviveFn);n.updateTarget(k,C)},c=(A,C=_.LOCAL)=>{const k=A.map(R=>pe(R,e,t.selectorReviveFn));n.bulkUpdateTargets(k,C)};function m(A,C,k,R){const B=k||!!R,M=o.getAt(A,C,B).map(D=>n.getAnnotation(D)).filter(Boolean),N=R?M.filter(R):M;if(N.length!==0)return k?N:N[0]}const S=A=>o.getAnnotationRects(A).length>0?o.getAnnotationBounds(A):void 0,h=(A,C,k,R)=>o.getIntersecting(A,C,k,R),p=A=>o.getAnnotationRects(A),x=()=>o.recalculate(),Y=A=>o.on("recalculate",A);return n.observe(({changes:A})=>{const C=(A.deleted||[]).filter(B=>Z(B.target.selector)),k=(A.created||[]).filter(B=>Z(B.target.selector)),R=(A.updated||[]).filter(B=>Z(B.newValue.target.selector));C?.length>0&&C.forEach(B=>o.remove(B.target)),k.length>0&&o.set(k.map(B=>B.target),!1),R?.length>0&&R.forEach(({newValue:B})=>o.update(B.target))}),{store:{...n,addAnnotation:l,bulkAddAnnotations:f,bulkUpdateTargets:c,bulkUpsertAnnotations:y,getAnnotationBounds:S,getAnnotationRects:p,getIntersecting:h,getAt:m,recalculatePositions:x,onRecalculatePositions:Y,syncAnnotations:d,updateAnnotation:u,updateTarget:g},selection:i,hover:s,viewport:r}};function So(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 d(){const y=i,g=s;return i=void 0,s=void 0,l=e.apply(y,g),l}function f(){const y=Date.now()-a;y<t&&y>=0?r=setTimeout(f,t-y):(r=void 0,o||(l=d()))}const u=function(...y){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=y,a=Date.now();const g=o&&!r;if(r||(r=setTimeout(f,t)),g)return l=d(),l};return Object.defineProperty(u,"isPending",{get(){return r!==void 0}}),u.clear=()=>{r&&(clearTimeout(r),r=void 0,i=void 0,s=void 0)},u.flush=()=>{r&&u.trigger()},u.trigger=()=>{l=d(),u.clear()},u}const nt=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function ot(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent(`on${t}`,n)}function ve(e,t,n,o){e&&(e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent(`on${t}`,n))}function Gt(e,t){const n=t.slice(0,t.length-1),o=[];for(let i=0;i<n.length;i++)o.push(e[n[i].toLowerCase()]);return o}function Qt(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 Co(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}function Jt(e){let t=e.keyCode||e.which||e.charCode;return e.key&&/^[a-z]$/i.test(e.key)?e.key.toUpperCase().charCodeAt(0):(e.code&&/^Key[A-Z]$/.test(e.code)&&(t=e.code.charCodeAt(3)),t)}const Se={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,"-":nt?173:189,"=":nt?61:187,";":nt?59:186,"'":222,"{":219,"}":221,"[":219,"]":221,"\\":220},q={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,meta:91,command:91},Ce={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},V={16:!1,18:!1,17:!1,91:!1},U={};for(let e=1;e<20;e++)Se[`f${e}`]=111+e;let I=[],Te=null,ue=null,Zt="all";const ne=new Map,fe=e=>Se[e.toLowerCase()]||q[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),To=e=>Object.keys(Se).find(t=>Se[t]===e),xo=e=>Object.keys(q).find(t=>q[t]===e),en=e=>{Zt=e||"all"},xe=()=>Zt||"all",Lo=()=>I.slice(0),Ro=()=>I.map(e=>To(e)||xo(e)||String.fromCharCode(e)),Oo=()=>{const e=[];return Object.keys(U).forEach(t=>{U[t].forEach(({key:n,scope:o,mods:i,shortcut:s})=>{e.push({scope:o,shortcut:s,mods:i,keys:n.split("+").map(r=>fe(r))})})}),e},tn=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},ko=e=>(typeof e=="string"&&(e=fe(e)),I.indexOf(e)!==-1),Mo=(e,t)=>{let n,o;e||(e=xe());for(const i in U)if(Object.prototype.hasOwnProperty.call(U,i))for(n=U[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(({element:r})=>it(r)):o++;xe()===e&&en(t||"all")};function No(e){let t=Jt(e);e.key&&e.key.toLowerCase()==="capslock"&&(t=fe(e.key));const n=I.indexOf(t);if(n>=0&&I.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&I.splice(0,I.length),(t===93||t===224)&&(t=91),t in V){V[t]=!1;for(const o in q)q[o]===t&&(G[o]=!1)}}const nn=(e,...t)=>{if(typeof e>"u")Object.keys(U).forEach(n=>{Array.isArray(U[n])&&U[n].forEach(o=>Ue(o)),delete U[n]}),it(null);else if(Array.isArray(e))e.forEach(n=>{n.key&&Ue(n)});else if(typeof e=="object")e.key&&Ue(e);else if(typeof e=="string"){let[n,o]=t;typeof n=="function"&&(o=n,n=""),Ue({key:e,scope:n,method:o,splitKey:"+"})}},Ue=({key:e,scope:t,method:n,splitKey:o="+"})=>{Qt(e).forEach(s=>{const r=s.split(o),a=r.length,l=r[a-1],d=l==="*"?"*":fe(l);if(!U[d])return;t||(t=xe());const f=a>1?Gt(q,r):[],u=[];U[d]=U[d].filter(y=>{const c=(n?y.method===n:!0)&&y.scope===t&&Co(y.mods,f);return c&&u.push(y.element),!c}),u.forEach(y=>it(y))})};function on(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 V)Object.prototype.hasOwnProperty.call(V,s)&&(!V[s]&&t.mods.indexOf(+s)>-1||V[s]&&t.mods.indexOf(+s)===-1)&&(i=!1);(t.mods.length===0&&!V[16]&&!V[18]&&!V[17]&&!V[91]||i||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(I),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function sn(e,t){const n=U["*"];let o=Jt(e);if(e.key&&e.key.toLowerCase()==="capslock"||!(G.filter||tn).call(this,e))return;if((o===93||o===224)&&(o=91),I.indexOf(o)===-1&&o!==229&&I.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(l=>{const d=Ce[l];e[l]&&I.indexOf(d)===-1?I.push(d):!e[l]&&I.indexOf(d)>-1?I.splice(I.indexOf(d),1):l==="metaKey"&&e[l]&&(I=I.filter(f=>f in Ce||f===o))}),o in V){V[o]=!0;for(const l in q)if(Object.prototype.hasOwnProperty.call(q,l)){const d=Ce[q[l]];G[l]=e[d]}if(!n)return}for(const l in V)Object.prototype.hasOwnProperty.call(V,l)&&(V[l]=e[Ce[l]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(I.indexOf(17)===-1&&I.push(17),I.indexOf(18)===-1&&I.push(18),V[17]=!0,V[18]=!0);const s=xe();if(n)for(let l=0;l<n.length;l++)n[l].scope===s&&(e.type==="keydown"&&n[l].keydown||e.type==="keyup"&&n[l].keyup)&&on(e,n[l],s,t);if(!(o in U))return;const r=U[o],a=r.length;for(let l=0;l<a;l++)if((e.type==="keydown"&&r[l].keydown||e.type==="keyup"&&r[l].keyup)&&r[l].key){const d=r[l],{splitKey:f}=d,u=d.key.split(f),y=[];for(let g=0;g<u.length;g++)y.push(fe(u[g]));y.sort().join("")===I.sort().join("")&&on(e,d,s,t)}}const G=function e(t,n,o){I=[];const i=Qt(t);let s=[],r="all",a=document,l=0,d=!1,f=!0,u="+",y=!1,g=!1;if(o===void 0&&typeof n=="function"&&(o=n),Object.prototype.toString.call(n)==="[object Object]"){const c=n;c.scope&&(r=c.scope),c.element&&(a=c.element),c.keyup&&(d=c.keyup),c.keydown!==void 0&&(f=c.keydown),c.capture!==void 0&&(y=c.capture),typeof c.splitKey=="string"&&(u=c.splitKey),c.single===!0&&(g=!0)}for(typeof n=="string"&&(r=n),g&&nn(t,r);l<i.length;l++){const c=i[l].split(u);s=[],c.length>1&&(s=Gt(q,c));let m=c[c.length-1];m=m==="*"?"*":fe(m),m in U||(U[m]=[]),U[m].push({keyup:d,keydown:f,scope:r,mods:s,shortcut:i[l],method:o,key:i[l],splitKey:u,element:a})}if(typeof a<"u"&&typeof window<"u"){if(!ne.has(a)){const c=(S=window.event)=>sn(S,a),m=(S=window.event)=>{sn(S,a),No(S)};ne.set(a,{keydownListener:c,keyupListenr:m,capture:y}),ot(a,"keydown",c,y),ot(a,"keyup",m,y)}if(!Te){const c=()=>{I=[]};Te={listener:c,capture:y},ot(window,"focus",c,y)}if(!ue&&typeof document<"u"){const c=()=>{I=[];for(const h in V)V[h]=!1;for(const h in q)e[h]=!1},m=c,S=c;document.addEventListener("fullscreenchange",m),document.addEventListener("webkitfullscreenchange",S),ue={fullscreen:m,webkit:S}}}};function Bo(e,t="all"){Object.keys(U).forEach(n=>{U[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method({},i)})})}function it(e){const t=Object.values(U).flat();if(t.findIndex(({element:o})=>o===e)<0&&e){const{keydownListener:o,keyupListenr:i,capture:s}=ne.get(e)||{};o&&i&&(ve(e,"keyup",i,s),ve(e,"keydown",o,s),ne.delete(e))}if(t.length<=0||ne.size<=0){if(Array.from(ne.keys()).forEach(i=>{const{keydownListener:s,keyupListenr:r,capture:a}=ne.get(i)||{};s&&r&&(ve(i,"keyup",r,a),ve(i,"keydown",s,a),ne.delete(i))}),ne.clear(),Object.keys(U).forEach(i=>delete U[i]),Te){const{listener:i,capture:s}=Te;ve(window,"focus",i,s),Te=null}ue&&typeof document<"u"&&(document.removeEventListener("fullscreenchange",ue.fullscreen),document.removeEventListener("webkitfullscreenchange",ue.webkit),ue=null)}}const st={getPressedKeyString:Ro,setScope:en,getScope:xe,deleteScope:Mo,getPressedKeyCodes:Lo,getAllKeyCodes:Oo,isPressed:ko,filter:tn,trigger:Bo,unbind:nn,keyMap:Se,modifier:q,modifierMap:Ce};for(const e in st){const t=e;Object.prototype.hasOwnProperty.call(st,t)&&(G[t]=st[t])}if(typeof window<"u"){const e=window.hotkeys;G.noConflict=t=>(t&&window.hotkeys===G&&(window.hotkeys=e),G),window.hotkeys=G}async function _o(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 rn=300,an=["up","down","left","right"],ln=Ke?"⌘+a":"ctrl+a",Io=[...an.map(e=>`shift+${e}`),ln],cn=(e,t,n,o)=>{const{store:i,selection:s}=t;let r;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:d,dismissOnNotAnnotatable:f="NEVER"}=o;let u,y=a,g="CREATE_NEW",c,m,S,h;const p=v=>{y=v,R.clear(),v||(m=void 0,c=void 0,S=void 0,h=void 0)},x=v=>g=v||"CREATE_NEW",Y=v=>u=v,A=v=>r=v,C=v=>{if(g==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const O=v;return Ke?O.metaKey:O.ctrlKey}else return!1},k=()=>{if(!y||S===!1)return;const{selected:v}=s;if((C(h)||g==="REPLACE_CURRENT")&&v.length===1&&v[0].editable){const K=i.getAnnotation(v[0].id);if(K?.target){m=K.target,c={annotation:K.id,selector:[],created:m.created,creator:m.creator,updated:new Date,updatedBy:r};return}}m=void 0,c={annotation:rt(),selector:[],created:new Date,creator:r}},R=So(v=>{if(!y)return;const O=document.getSelection();if(!O?.anchorNode)return;const H=E().map(j=>ut(j,e));if(H.every(j=>!Xe(e,j))){c=void 0;return}const ie=v.timeStamp-(h?.timeStamp||v.timeStamp);if(h?.type==="pointerdown"&&(ie<1e3&&!c||O.isCollapsed&&ie<rn)&&k(),!c&&(k(),!c))return;if(O.isCollapsed){i.getAnnotation(c.annotation)&&!(C(h)||g==="REPLACE_CURRENT")&&(s.clear(),i.deleteAnnotation(c.annotation));return}if(H.every(j=>at(j)))return;const J=H.flatMap(j=>dt(e,j.cloneRange()));if(!(J.length>0&&!c||J.length!==c.selector.length||J.some((j,Le)=>j.toString()!==c?.selector[Le]?.quote)))return;const Ye=C(h)&&m?lt([...m.selector.map(j=>j.range),...J]):J;c={...c,selector:Ye.map(j=>gt(j,e,l)),updated:new Date},!(C(h)||g==="REPLACE_CURRENT")&&(i.getAnnotation(c.annotation)?i.updateTarget(c,_.LOCAL):s.clear())},10),B=v=>{h=Me(v),S=h.button===0},M=async v=>{if(!S)return;const O=Me(v),K=()=>{const{x:ie,y:J}=e.getBoundingClientRect();if(ge(e,O.target)){(typeof f=="function"?f(O,e):f==="ALWAYS")&&s.clear();return}const se=O.target instanceof Node&&e.contains(O.target)&&i.getAt(O.clientX-ie,O.clientY-J,d==="all",u);if(se){const{selected:Ye}=s,j=new Set(Ye.map(Re=>Re.id)),Le=Array.isArray(se)?se.map(Re=>Re.id):[se.id];(j.size!==Le.length||!Le.every(Re=>j.has(Re)))&&(n.emit("clickAnnotation",se),s.userSelect(Le,O))}else s.clear()};if(O.timeStamp-(h?.timeStamp||0)<rn){await N();const ie=document.getSelection(),J=ge(e,h?.target),se=ge(e,O.target);if(ie?.isCollapsed||J&&se){c=void 0,K();return}}c&&c.selector.length>0&&(T(),s.userSelect(c.annotation,O))},N=async()=>{const v=document.getSelection();let O=!1,K=v?.isCollapsed;const H=()=>K||O,ie=1;return setTimeout(()=>O=!0,50),_o(()=>K=v?.isCollapsed,ie,H)},D=v=>{document.getSelection()?.isCollapsed||((!c||c.selector.length===0)&&R(v),c&&(T(),s.userSelect(c.annotation,Me(v))))},F=v=>{if(y&&!v.repeat&&E().length!==0&&v.key==="Shift"&&c){const O=document.getSelection();O&&!O.isCollapsed&&(T(),s.userSelect(c.annotation,ye(v)))}},le=v=>{const O=()=>setTimeout(()=>{c&&(c.selector.length>0&&(s.clear(),i.addAnnotation({id:c.annotation,bodies:[],target:c}),s.userSelect(c.annotation,ye(v))),document.removeEventListener("selectionchange",O))},100);document.addEventListener("selectionchange",O),k()};G(Io.join(","),{element:e,keydown:!0,keyup:!1},v=>{v.repeat||(h=ye(v))}),G(ln,{keydown:!0,keyup:!1},v=>{h=ye(v),le(v)});const b=v=>{v.repeat||E().length!==0&&(c=void 0,s.clear())};G(an.join(","),{keydown:!0,keyup:!1},b),document.addEventListener("pointerdown",B),document.addEventListener("pointerup",M),document.addEventListener("contextmenu",D),document.addEventListener("keyup",F),e.addEventListener("selectstart",k),document.addEventListener("selectionchange",R);const w=()=>{c=void 0,m=void 0,S=void 0,h=void 0,R.clear(),document.removeEventListener("pointerdown",B),document.removeEventListener("pointerup",M),document.removeEventListener("contextmenu",D),document.removeEventListener("keyup",F),e.removeEventListener("selectstart",k),document.removeEventListener("selectionchange",R),G.unbind()},E=()=>{const v=document.getSelection();return v?Array.from(Array(v.rangeCount).keys()).map(O=>v.getRangeAt(O)).filter(O=>O.intersectsNode(e)):[]},T=()=>{if(!c)return;const v=i.getAnnotation(c.annotation);if(!v)i.addAnnotation({id:c.annotation,bodies:[],target:c});else{const{target:{updated:O}}=v,{updated:K}=c;(!O||!K||O<K)&&i.updateTarget(c)}};return{destroy:w,setFilter:Y,setUser:A,setAnnotatingEnabled:p,setAnnotatingMode:x}},Do=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(";"),Uo=()=>{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,d)=>{const f=new Set(s.map(y=>y.annotation.id));Array.from(t).filter(y=>!f.has(y));const u=s.map(y=>{a?typeof a=="function"&&a(y.annotation,y.state):y.state?.selected;const g=Je(y,a);return`::highlight(_${y.annotation.id}) { ${Do(g)} }`});e.innerHTML=u.join(`
|
|
2
|
+
`),CSS.highlights.clear(),s.forEach(({annotation:y})=>{const g=y.target.selector.map(m=>m.range),c=new Highlight(...g);CSS.highlights.set(`_${y.id}`,c)}),t=f}}},Yo=(e,t,n)=>ze(Uo(),e,t,n),dn=(e,t)=>({...e,annotatingEnabled:e.annotatingEnabled??t.annotatingEnabled,user:e.user||t.user}),un="SPANS",Ko=(e,t={})=>{xt(e),ct(e);const n=dn(t,{annotatingEnabled:!0,user:qn()}),o=qt(e,n),{selection:i,viewport:s}=o,r=o.store,a=Kn(r),l=Xn(o,a,n.adapter);let d=n.user;const f=typeof n.renderer!="function"?n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":un:n.renderer||un:null,u=f===null?n.renderer(e,o,s):f==="SPANS"?Ht(e,o,s):f==="CSS_HIGHLIGHTS"?Yo(e,o,s):void 0;if(!u)throw`Unknown renderer implementation: ${n.renderer}`;console.debug(f?`Using ${f} renderer`:"Using custom renderer implementation"),n.style&&u.setStyle(n.style);const y=cn(e,o,l,n);y.setUser(d);const g=$n(o,a,n.adapter),c=()=>d,m=A=>{y.setAnnotatingEnabled(A===void 0?!0:A)},S=A=>{y.setAnnotatingMode(A)},h=A=>{u.setFilter(A),y.setFilter(A)},p=A=>{d=A,y.setUser(A)},x=A=>{A?i.setSelected(A):i.clear()};return{...g,destroy:()=>{u.destroy(),y.destroy(),a.destroy()},element:e,getUser:c,renderer:u,setAnnotatingEnabled:m,setAnnotatingMode:S,setFilter:h,setStyle:u.setStyle.bind(u),setUser:p,setSelected:x,setVisible:u.setVisible.bind(u),on:l.on,off:l.off,scrollIntoView:bt(e,r),state:o}};L.DEFAULT_SELECTED_STYLE=_e,L.DEFAULT_STYLE=te,L.NOT_ANNOTATABLE_CLASS=Ve,L.NOT_ANNOTATABLE_SELECTOR=re,L.Origin=_,L.UserSelectAction=He,L.W3CTextFormat=Zn,L.cancelSingleClickEvents=xt,L.cloneKeyboardEvent=ye,L.clonePointerEvent=Me,L.computeStyle=Je,L.computeZIndex=Vt,L.createBody=Rn,L.createRenderer=ze,L.createSelectionHandler=cn,L.createSpansRenderer=Ht,L.createTextAnnotator=Ko,L.createTextAnnotatorState=qt,L.debounce=Ne,L.fillDefaults=dn,L.getBackgroundColor=Yt,L.getHighlightClientRects=Xt,L.getQuoteContext=ht,L.getRangeAnnotatableContents=Oe,L.getViewportBounds=jt,L.isMac=Ke,L.isNodeWhitespaceOrEmpty=yn,L.isNotAnnotatable=ge,L.isRangeAnnotatable=Xe,L.isRangeWhitespaceOrEmpty=at,L.isRevived=Z,L.isRevivedAnnotation=he,L.isRevivedTarget=fn,L.mergeClientRects=Pt,L.mergeRanges=lt,L.parseW3CTextAnnotation=St,L.programmaticallyFocusable=ct,L.rangeToSelector=gt,L.reviveAnnotation=me,L.reviveTarget=pe,L.reviveTextSelector=pt,L.scrollIntoView=bt,L.serializeW3CTextAnnotation=Ct,L.splitAnnotatableRanges=dt,L.toDomRectList=fo,L.toParentBounds=$t,L.toViewportBounds=ho,L.trackViewport=Ft,L.trimRangeToContainer=ut,L.whitespaceOrEmptyRegex=Pe,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
|
|
3
3
|
//# sourceMappingURL=text-annotator.umd.js.map
|