@recogito/text-annotator 3.0.0-rc.52 → 3.0.0-rc.54

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.
@@ -1,3 +1,3 @@
1
- (function(O,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(O=typeof globalThis<"u"?globalThis:O||self,G(O.RecogitoJS={}))})(this,function(O){"use strict";const G="not-annotatable",Q=`.${G}`,tt=t=>{var n;return!!(t instanceof HTMLElement?t.closest(Q):(n=t.parentElement)==null?void 0:n.closest(Q))},jt=t=>{const e=t.commonAncestorContainer;return!tt(e)},Ft=t=>t.addEventListener("click",e=>{!e.target.closest(Q)&&!e.target.closest("a")&&e.preventDefault()}),yt=t=>({...t,type:t.type,x:t.x,y:t.y,clientX:t.clientX,clientY:t.clientY,offsetX:t.offsetX,offsetY:t.offsetY,screenX:t.screenX,screenY:t.screenY,isPrimary:t.isPrimary,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,button:t.button,buttons:t.buttons,currentTarget:t.currentTarget,target:t.target,defaultPrevented:t.defaultPrevented,detail:t.detail,eventPhase:t.eventPhase,pointerId:t.pointerId,pointerType:t.pointerType,timeStamp:t.timeStamp}),it=t=>({...t,type:t.type,key:t.key,code:t.code,location:t.location,repeat:t.repeat,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,currentTarget:t.currentTarget,target:t.target,defaultPrevented:t.defaultPrevented,detail:t.detail,timeStamp:t.timeStamp}),zt=/mac/i.test(navigator.userAgentData?navigator.userAgentData.platform:navigator.platform),Wt=t=>{!t.hasAttribute("tabindex")&&t.tabIndex<0&&t.setAttribute("tabindex","-1"),t.classList.add("no-focus-outline")},bt=(t,e=10)=>{let n;return(...o)=>{clearTimeout(n),n=setTimeout(()=>t.apply(void 0,o),e)}},qe=function*(t){const e=document.createNodeIterator(t.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(G)&&!o.parentElement.closest(Q)&&t.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=e.nextNode();)n instanceof HTMLElement&&(yield n)},qt=t=>{if(!jt(t))return[];const e=[];let n=null;for(const o of qe(t)){let i;n?(i=document.createRange(),i.setStartAfter(n),i.setEndBefore(o)):(i=t.cloneRange(),i.setEndBefore(o)),i.collapsed||e.push(i),n=o}if(n){const o=t.cloneRange();o.setStartAfter(n),o.collapsed||e.push(o)}return e.length>0?e:[t]},wt=t=>{const e=t.cloneContents();return e.querySelectorAll(Q).forEach(n=>n.remove()),e},Gt=(t,e,n=10,o)=>{const i=o?t.startContainer.parentElement.closest(o):e,s=document.createRange();s.setStart(i,0),s.setEnd(t.startContainer,t.startOffset);const a=wt(s).textContent,r=document.createRange();r.setStart(t.endContainer,t.endOffset),i===document.body?r.setEnd(i,i.childNodes.length):r.setEndAfter(i);const l=wt(r).textContent;return{prefix:a.substring(a.length-n),suffix:l.substring(0,n)}},j=t=>t.every(e=>e.range instanceof Range&&!e.range.collapsed),Qt=/^\s*$/,Jt=t=>Qt.test(t.toString()),Ge=(t,e)=>{const n=s=>Math.round(s*10)/10,o={top:n(t.top),bottom:n(t.bottom),left:n(t.left),right:n(t.right)},i={top:n(e.top),bottom:n(e.bottom),left:n(e.left),right:n(e.right)};if(Math.abs(o.top-i.top)<.5&&Math.abs(o.bottom-i.bottom)<.5){if(Math.abs(o.left-i.right)<.5||Math.abs(o.right-i.left)<.5)return"inline-adjacent";if(o.left>=i.left&&o.right<=i.right)return"inline-is-contained";if(o.left<=i.left&&o.right>=i.right)return"inline-contains"}else if(o.top<=i.top&&o.bottom>=i.bottom){if(o.left<=i.left&&o.right>=i.right)return"block-contains"}else if(o.top>=i.top&&o.bottom<=i.bottom&&o.left>=i.left&&o.right<=i.right)return"block-is-contained"},Qe=(t,e)=>{const n=Math.min(t.left,e.left),o=Math.max(t.right,e.right),i=Math.min(t.top,e.top),s=Math.max(t.bottom,e.bottom);return new DOMRect(n,i,o-n,s-i)},Zt=t=>t.reduce((e,n)=>{if(n.width===0||n.height===0)return e;let o=[...e],i=!1;for(const s of e){const a=Ge(n,s);if(a==="inline-adjacent"){o=o.map(r=>r===s?Qe(n,s):r),i=!0;break}else if(a==="inline-contains"){o=o.map(r=>r===s?n:r),i=!0;break}else if(a==="inline-is-contained"){i=!0;break}else if(a==="block-contains"||a==="block-is-contained"){n.width<s.width&&(o=o.map(r=>r===s?n:r)),i=!0;break}}return i?o:[...o,n]},[]),te=(t,e,n)=>{const o=document.createRange(),i=n?t.startContainer.parentElement.closest(n):e;o.setStart(i,0),o.setEnd(t.startContainer,t.startOffset);const s=wt(o).textContent,a=t.toString(),r=s.length||0,l=r+a.length;return n?{quote:a,start:r,end:l,range:t,offsetReference:i}:{quote:a,start:r,end:l,range:t}},Lt=(t,e)=>{var h,u;const{start:n,end:o}=t,i=t.offsetReference||e,s=document.createNodeIterator(e,NodeFilter.SHOW_TEXT,g=>{var p;return(p=g.parentElement)!=null&&p.closest(Q)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT});let a=0;const r=document.createRange();let l=s.nextNode();l===null&&console.error("Could not revive annotation target. Content missing.");let f=!i;for(;l!==null;){if(f||(f=i==null?void 0:i.contains(l)),f){const g=((h=l.textContent)==null?void 0:h.length)||0;if(a+g>n){r.setStart(l,n-a);break}a+=g}l=s.nextNode()}for(;l!==null;){const g=((u=l.textContent)==null?void 0:u.length)||0;if(a+g>=o){r.setEnd(l,o-a);break}a+=g,l=s.nextNode()}return{...t,range:r}},st=(t,e)=>j(t.selector)?t:{...t,selector:t.selector.map(n=>n.range instanceof Range&&!n.range.collapsed?n:Lt(n,e))},At=(t,e)=>j(t.target.selector)?t:{...t,target:st(t.target,e)},ee=(t,e)=>{const n=t.cloneRange();return e.contains(n.startContainer)||n.setStart(e,0),e.contains(n.endContainer)||n.setEnd(e,e.childNodes.length),n},ne=t=>{if(t===null)return document.scrollingElement;const{overflowY:e}=window.getComputedStyle(t);return e!=="visible"&&e!=="hidden"&&t.scrollHeight>t.clientHeight?t:ne(t.parentElement)},oe=(t,e)=>n=>{const o=typeof n=="string"?n:n.id,i=a=>{const r=s.getBoundingClientRect(),l=s.clientHeight,f=s.clientWidth,h=a.selector[0].range.getBoundingClientRect(),{width:u,height:g}=e.getAnnotationBounds(o),p=h.top-r.top,b=h.left-r.left,w=s.parentElement?s.scrollTop:0,y=s.parentElement?s.scrollLeft:0,d=p+w-(l-g)/2,c=b+y-(f-u)/2;s.scroll({top:d,left:c,behavior:"smooth"})},s=ne(t);if(s){const a=e.getAnnotation(o),{range:r}=a.target.selector[0];if(r&&!r.collapsed)return i(a.target),!0;{const l=st(a.target,t),{range:f}=l.selector[0];if(f&&!f.collapsed)return i(l),!0}}return!1},z={fill:"rgb(0, 128, 255)",fillOpacity:.18},rt={fill:"rgb(0, 128, 255)",fillOpacity:.45},ie=(t,e,n,o,i)=>{var a,r;const s=n?typeof n=="function"?n(t.annotation,t.state,i)||((a=t.state)!=null&&a.selected?rt:z):n:(r=t.state)!=null&&r.selected?rt:z;return o&&o.paint(t,e)||s},Je=t=>{const{top:e,left:n}=t.getBoundingClientRect(),{innerWidth:o,innerHeight:i}=window,s=-n,a=-e,r=o-n,l=i-e;return{top:e,left:n,minX:s,minY:a,maxX:r,maxY:l}},Ze=t=>{let e=new Set;return o=>{const i=o.map(s=>s.id);(e.size!==i.length||i.some(s=>!e.has(s)))&&t.set(i),e=new Set(i)}},Tt=(t,e,n,o)=>{const{store:i,selection:s,hover:a}=e;let r,l,f;const h=Ze(n),u=M=>{const{x:L,y:m}=t.getBoundingClientRect(),E=i.getAt(M.clientX-L,M.clientY-m,!1,l);E?a.current!==E.id&&(t.classList.add("hovered"),a.set(E.id)):a.current&&(t.classList.remove("hovered"),a.set(null))};t.addEventListener("pointermove",u);const g=(M=!1)=>{f&&f.clear();const L=Je(t),{minX:m,minY:E,maxX:v,maxY:C}=L,B=l?i.getIntersecting(m,E,v,C).filter(({annotation:Y})=>l(Y)):i.getIntersecting(m,E,v,C),k=s.selected.map(({id:Y})=>Y),U=B.map(({annotation:Y,rects:mt})=>{const Z=k.includes(Y.id),vo=Y.id===a.current;return{annotation:Y,rects:mt,state:{selected:Z,hover:vo}}});o.redraw(U,L,r,f,M),setTimeout(()=>h(B.map(({annotation:Y})=>Y)),1)},p=M=>{f=M,g()},b=M=>{r=M,g()},w=M=>{l=M,g(!1)},y=()=>g();i.observe(y);const d=s.subscribe(()=>g()),c=()=>g(!0);document.addEventListener("scroll",c,{capture:!0,passive:!0});const A=bt(()=>{i.recalculatePositions(),f&&f.reset(),g()});window.addEventListener("resize",A);const S=new ResizeObserver(A);S.observe(t);const T={attributes:!0,childList:!0,subtree:!0},x=new MutationObserver(M=>{M.every(m=>m.target===t||t.contains(m.target))||g(!0)});return x.observe(document.body,T),{destroy:()=>{t.removeEventListener("pointermove",u),o.destroy(),i.unobserve(y),d(),document.removeEventListener("scroll",c),window.removeEventListener("resize",A),S.disconnect(),x.disconnect()},redraw:g,setStyle:b,setFilter:w,setPainter:p,setVisible:o.setVisible}},tn=()=>{const t=document.createElement("canvas");return t.width=window.innerWidth,t.height=window.innerHeight,t.className="r6o-canvas-highlight-layer bg",t},en=(t,e)=>{t.width=window.innerWidth,t.height=window.innerHeight},nn=t=>{t.classList.add("r6o-annotatable");const e=tn(),n=e.getContext("2d");document.body.appendChild(e);const o=(r,l,f,h)=>requestAnimationFrame(()=>{const{width:u,height:g}=e;n.clearRect(-.5,-.5,u+1,g+1),h&&h.clear();const{top:p,left:b}=l;[...r].sort((y,d)=>{const{annotation:{target:{created:c}}}=y,{annotation:{target:{created:A}}}=d;return c.getTime()-A.getTime()}).forEach(y=>{var S;const d=f?typeof f=="function"?f(y.annotation,y.state):f:(S=y.state)!=null&&S.selected?rt:z,c=h&&h.paint(y,l)||d,A=y.rects.map(({x:T,y:x,width:R,height:M})=>({x:T+b,y:x+p,width:R,height:M}));if(n.fillStyle=c.fill,n.globalAlpha=c.fillOpacity||1,A.forEach(({x:T,y:x,width:R,height:M})=>n.fillRect(T,x,R,M)),c.underlineColor){n.globalAlpha=1,n.strokeStyle=c.underlineColor,n.lineWidth=c.underlineThickness??1;const T=c.underlineOffset??0;A.forEach(({x,y:R,width:M,height:L})=>{n.beginPath(),n.moveTo(x,R+L+T),n.lineTo(x+M,R+L+T),n.stroke()})}})}),i=bt(()=>{en(e)});return window.addEventListener("resize",i),{destroy:()=>{e.remove(),window.removeEventListener("resize",i)},setVisible:r=>{console.log("setVisible not implemented on Canvas renderer")},redraw:o}},se=(t,e,n)=>Tt(t,e,n,nn(t));var on={grad:.9,turn:360,rad:360/(2*Math.PI)},W=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},V=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=Math.pow(10,e)),Math.round(n*t)/n+0},P=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=1),t>n?n:t>e?t:e},re=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},ae=function(t){return{r:P(t.r,0,255),g:P(t.g,0,255),b:P(t.b,0,255),a:P(t.a)}},Ot=function(t){return{r:V(t.r),g:V(t.g),b:V(t.b),a:V(t.a,3)}},sn=/^#([0-9a-f]{3,8})$/i,vt=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},ce=function(t){var e=t.r,n=t.g,o=t.b,i=t.a,s=Math.max(e,n,o),a=s-Math.min(e,n,o),r=a?s===e?(n-o)/a:s===n?2+(o-e)/a:4+(e-n)/a:0;return{h:60*(r<0?r+6:r),s:s?a/s*100:0,v:s/255*100,a:i}},le=function(t){var e=t.h,n=t.s,o=t.v,i=t.a;e=e/360*6,n/=100,o/=100;var s=Math.floor(e),a=o*(1-n),r=o*(1-(e-s)*n),l=o*(1-(1-e+s)*n),f=s%6;return{r:255*[o,r,a,a,l,o][f],g:255*[l,o,o,r,a,a][f],b:255*[a,a,l,o,o,r][f],a:i}},de=function(t){return{h:re(t.h),s:P(t.s,0,100),l:P(t.l,0,100),a:P(t.a)}},ue=function(t){return{h:V(t.h),s:V(t.s),l:V(t.l),a:V(t.a,3)}},fe=function(t){return le((n=(e=t).s,{h:e.h,s:(n*=((o=e.l)<50?o:100-o)/100)>0?2*n/(o+n)*100:0,v:o+n,a:e.a}));var e,n,o},at=function(t){return{h:(e=ce(t)).h,s:(i=(200-(n=e.s))*(o=e.v)/100)>0&&i<200?n*o/100/(i<=100?i:200-i)*100:0,l:i/2,a:e.a};var e,n,o,i},rn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,an=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,cn=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ln=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,he={string:[[function(t){var e=sn.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?V(parseInt(t[3]+t[3],16)/255,2):1}:t.length===6||t.length===8?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:t.length===8?V(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=cn.exec(t)||ln.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:ae({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=rn.exec(t)||an.exec(t);if(!e)return null;var n,o,i=de({h:(n=e[1],o=e[2],o===void 0&&(o="deg"),Number(n)*(on[o]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return fe(i)},"hsl"]],object:[[function(t){var e=t.r,n=t.g,o=t.b,i=t.a,s=i===void 0?1:i;return W(e)&&W(n)&&W(o)?ae({r:Number(e),g:Number(n),b:Number(o),a:Number(s)}):null},"rgb"],[function(t){var e=t.h,n=t.s,o=t.l,i=t.a,s=i===void 0?1:i;if(!W(e)||!W(n)||!W(o))return null;var a=de({h:Number(e),s:Number(n),l:Number(o),a:Number(s)});return fe(a)},"hsl"],[function(t){var e=t.h,n=t.s,o=t.v,i=t.a,s=i===void 0?1:i;if(!W(e)||!W(n)||!W(o))return null;var a=function(r){return{h:re(r.h),s:P(r.s,0,100),v:P(r.v,0,100),a:P(r.a)}}({h:Number(e),s:Number(n),v:Number(o),a:Number(s)});return le(a)},"hsv"]]},ge=function(t,e){for(var n=0;n<e.length;n++){var o=e[n][0](t);if(o)return[o,e[n][1]]}return[null,void 0]},dn=function(t){return typeof t=="string"?ge(t.trim(),he.string):typeof t=="object"&&t!==null?ge(t,he.object):[null,void 0]},Rt=function(t,e){var n=at(t);return{h:n.h,s:P(n.s+100*e,0,100),l:n.l,a:n.a}},Mt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},pe=function(t,e){var n=at(t);return{h:n.h,s:n.s,l:P(n.l+100*e,0,100),a:n.a}},me=function(){function t(e){this.parsed=dn(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return this.parsed!==null},t.prototype.brightness=function(){return V(Mt(this.rgba),2)},t.prototype.isDark=function(){return Mt(this.rgba)<.5},t.prototype.isLight=function(){return Mt(this.rgba)>=.5},t.prototype.toHex=function(){return e=Ot(this.rgba),n=e.r,o=e.g,i=e.b,a=(s=e.a)<1?vt(V(255*s)):"","#"+vt(n)+vt(o)+vt(i)+a;var e,n,o,i,s,a},t.prototype.toRgb=function(){return Ot(this.rgba)},t.prototype.toRgbString=function(){return e=Ot(this.rgba),n=e.r,o=e.g,i=e.b,(s=e.a)<1?"rgba("+n+", "+o+", "+i+", "+s+")":"rgb("+n+", "+o+", "+i+")";var e,n,o,i,s},t.prototype.toHsl=function(){return ue(at(this.rgba))},t.prototype.toHslString=function(){return e=ue(at(this.rgba)),n=e.h,o=e.s,i=e.l,(s=e.a)<1?"hsla("+n+", "+o+"%, "+i+"%, "+s+")":"hsl("+n+", "+o+"%, "+i+"%)";var e,n,o,i,s},t.prototype.toHsv=function(){return e=ce(this.rgba),{h:V(e.h),s:V(e.s),v:V(e.v),a:V(e.a,3)};var e},t.prototype.invert=function(){return H({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},t.prototype.saturate=function(e){return e===void 0&&(e=.1),H(Rt(this.rgba,e))},t.prototype.desaturate=function(e){return e===void 0&&(e=.1),H(Rt(this.rgba,-e))},t.prototype.grayscale=function(){return H(Rt(this.rgba,-1))},t.prototype.lighten=function(e){return e===void 0&&(e=.1),H(pe(this.rgba,e))},t.prototype.darken=function(e){return e===void 0&&(e=.1),H(pe(this.rgba,-e))},t.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},t.prototype.alpha=function(e){return typeof e=="number"?H({r:(n=this.rgba).r,g:n.g,b:n.b,a:e}):V(this.rgba.a,3);var n},t.prototype.hue=function(e){var n=at(this.rgba);return typeof e=="number"?H({h:e,s:n.s,l:n.l,a:n.a}):V(n.h)},t.prototype.isEqual=function(e){return this.toHex()===H(e).toHex()},t}(),H=function(t){return t instanceof me?t:new me(t)};const un=t=>[`background-color:${H((t==null?void 0:t.fill)||z.fill).alpha((t==null?void 0:t.fillOpacity)===void 0?z.fillOpacity:t.fillOpacity).toHex()}`,t!=null&&t.underlineThickness?"text-decoration:underline":void 0,t!=null&&t.underlineColor?`text-decoration-color:${t.underlineColor}`:void 0,t!=null&&t.underlineOffset?`text-underline-offset:${t.underlineOffset}px`:void 0,t!=null&&t.underlineThickness?`text-decoration-thickness:${t.underlineThickness}px`:void 0].filter(Boolean).join(";"),ye=()=>{const t=document.createElement("style");document.getElementsByTagName("head")[0].appendChild(t);let e=new Set;return{destroy:()=>{CSS.highlights.clear(),t.remove()},setVisible:s=>{console.log("setVisible not implemented on CSS Custom Highlights renderer")},redraw:(s,a,r,l)=>{l&&l.clear();const f=new Set(s.map(u=>u.annotation.id));Array.from(e).filter(u=>!f.has(u));const h=s.map(u=>{var b;const g=r?typeof r=="function"?r(u.annotation,u.state):r:(b=u.state)!=null&&b.selected?rt:z,p=l&&l.paint(u,a)||g;return`::highlight(_${u.annotation.id}) { ${un(p)} }`});t.innerHTML=h.join(`
2
- `),CSS.highlights.clear(),s.forEach(({annotation:u})=>{const g=u.target.selector.map(b=>b.range),p=new Highlight(...g);CSS.highlights.set(`_${u.id}`,p)}),e=f}}},be=(t,e,n)=>Tt(t,e,n,ye());var we=Object.prototype.hasOwnProperty;function Bt(t,e){var n,o;if(t===e)return!0;if(t&&e&&(n=t.constructor)===e.constructor){if(n===Date)return t.getTime()===e.getTime();if(n===RegExp)return t.toString()===e.toString();if(n===Array){if((o=t.length)===e.length)for(;o--&&Bt(t[o],e[o]););return o===-1}if(!n||typeof t=="object"){o=0;for(n in t)if(we.call(t,n)&&++o&&!we.call(e,n)||!(n in e)||!Bt(t[n],e[n]))return!1;return Object.keys(e).length===o}}return t!==t&&e!==e}const fn=(t,e)=>{const n=(s,a)=>s.x<=a.x+a.width&&s.x+s.width>=a.x&&s.y<=a.y+a.height&&s.y+s.height>=a.y,o=s=>s.rects.reduce((a,r)=>a+r.width,0),i=e.filter(({rects:s})=>s.some(a=>n(t,a)));return i.sort((s,a)=>o(a)-o(s)),i.findIndex(s=>s.rects.includes(t))},hn=t=>{t.classList.add("r6o-annotatable");const e=document.createElement("div");e.className="r6o-span-highlight-layer",t.insertBefore(e,t.firstChild);let n=[];return{destroy:()=>{e.remove()},redraw:(a,r,l,f,h)=>{const g=!(Bt(n,a)&&h);if(!f&&!g)return;g&&(e.innerHTML=""),[...a].sort((b,w)=>{const{annotation:{target:{created:y}}}=b,{annotation:{target:{created:d}}}=w;return y&&d?y.getTime()-d.getTime():0}).forEach(b=>{b.rects.map(w=>{const y=fn(w,a),d=ie(b,r,l,f,y);if(g){const c=document.createElement("span");c.className="r6o-annotation",c.dataset.annotation=b.annotation.id,c.style.left=`${w.x}px`,c.style.top=`${w.y}px`,c.style.width=`${w.width}px`,c.style.height=`${w.height}px`,c.style.backgroundColor=H((d==null?void 0:d.fill)||z.fill).alpha((d==null?void 0:d.fillOpacity)===void 0?z.fillOpacity:d.fillOpacity).toHex(),d.underlineStyle&&(c.style.borderStyle=d.underlineStyle),d.underlineColor&&(c.style.borderColor=d.underlineColor),d.underlineThickness&&(c.style.borderBottomWidth=`${d.underlineThickness}px`),d.underlineOffset&&(c.style.paddingBottom=`${d.underlineOffset}px`),e.appendChild(c)}})}),n=a},setVisible:a=>{a?e.classList.remove("hidden"):e.classList.add("hidden")}}},Ae=(t,e,n)=>Tt(t,e,n,hn(t)),K=[];for(let t=0;t<256;++t)K.push((t+256).toString(16).slice(1));function gn(t,e=0){return(K[t[e+0]]+K[t[e+1]]+K[t[e+2]]+K[t[e+3]]+"-"+K[t[e+4]]+K[t[e+5]]+"-"+K[t[e+6]]+K[t[e+7]]+"-"+K[t[e+8]]+K[t[e+9]]+"-"+K[t[e+10]]+K[t[e+11]]+K[t[e+12]]+K[t[e+13]]+K[t[e+14]]+K[t[e+15]]).toLowerCase()}let kt;const pn=new Uint8Array(16);function mn(){if(!kt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");kt=crypto.getRandomValues.bind(crypto)}return kt(pn)}const ve={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ee(t,e,n){if(ve.randomUUID&&!e&&!t)return ve.randomUUID();t=t||{};const o=t.random||(t.rng||mn)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,gn(o)}var Se=Object.prototype.hasOwnProperty;function J(t,e){var n,o;if(t===e)return!0;if(t&&e&&(n=t.constructor)===e.constructor){if(n===Date)return t.getTime()===e.getTime();if(n===RegExp)return t.toString()===e.toString();if(n===Array){if((o=t.length)===e.length)for(;o--&&J(t[o],e[o]););return o===-1}if(!n||typeof t=="object"){o=0;for(n in t)if(Se.call(t,n)&&++o&&!Se.call(e,n)||!(n in e)||!J(t[n],e[n]))return!1;return Object.keys(e).length===o}}return t!==t&&e!==e}function It(){}function yn(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}const et=[];function _t(t,e=It){let n;const o=new Set;function i(r){if(yn(t,r)&&(t=r,n)){const l=!et.length;for(const f of o)f[1](),et.push(f,t);if(l){for(let f=0;f<et.length;f+=2)et[f][0](et[f+1]);et.length=0}}}function s(r){i(r(t))}function a(r,l=It){const f=[r,l];return o.add(f),o.size===1&&(n=e(i,s)||It),r(t),()=>{o.delete(f),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:a}}const bn=t=>{const{subscribe:e,set:n}=_t();let o;return e(i=>o=i),t.observe(({changes:i})=>{if(o){(i.deleted||[]).some(a=>a.id===o)&&n(void 0);const s=(i.updated||[]).find(({oldValue:a})=>a.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:e,set:n}};var xe=(t=>(t.EDIT="EDIT",t.SELECT="SELECT",t.NONE="NONE",t))(xe||{});const Et={selected:[]},wn=(t,e,n)=>{const{subscribe:o,set:i}=_t(Et);let s=e,a=Et;o(b=>a=b);const r=()=>{J(a,Et)||i(Et)},l=()=>{var b;return((b=a.selected)==null?void 0:b.length)===0},f=b=>{if(l())return!1;const w=typeof b=="string"?b:b.id;return a.selected.some(y=>y.id===w)},h=(b,w)=>{let y;if(Array.isArray(b)){if(y=b.map(c=>t.getAnnotation(c)).filter(Boolean),y.length<b.length){console.warn("Invalid selection: "+b.filter(c=>!y.some(A=>A.id===c)));return}}else{const c=t.getAnnotation(b);if(!c){console.warn("Invalid selection: "+b);return}y=[c]}const d=y.reduce((c,A)=>{const S=Ce(A,s);return S==="EDIT"?[...c,{id:A.id,editable:!0}]:S==="SELECT"?[...c,{id:A.id}]:c},[]);i({selected:d,event:w})},u=(b,w)=>{const y=Array.isArray(b)?b:[b],d=y.map(c=>t.getAnnotation(c)).filter(c=>!!c);i({selected:d.map(c=>{const A=w===void 0?Ce(c,s)==="EDIT":w;return{id:c.id,editable:A}})}),d.length!==y.length&&console.warn("Invalid selection",b)},g=b=>{if(l())return!1;const{selected:w}=a;w.some(({id:y})=>b.includes(y))&&i({selected:w.filter(({id:y})=>!b.includes(y))})},p=b=>s=b;return t.observe(({changes:b})=>g((b.deleted||[]).map(w=>w.id))),{get event(){return a?a.event:null},get selected(){return a?[...a.selected]:null},get userSelectAction(){return s},clear:r,isEmpty:l,isSelected:f,setSelected:u,setUserSelectAction:p,subscribe:o,userSelect:h}},Ce=(t,e,n)=>typeof e=="function"?e(t):e||"EDIT",D=[];for(let t=0;t<256;++t)D.push((t+256).toString(16).slice(1));function An(t,e=0){return(D[t[e+0]]+D[t[e+1]]+D[t[e+2]]+D[t[e+3]]+"-"+D[t[e+4]]+D[t[e+5]]+"-"+D[t[e+6]]+D[t[e+7]]+"-"+D[t[e+8]]+D[t[e+9]]+"-"+D[t[e+10]]+D[t[e+11]]+D[t[e+12]]+D[t[e+13]]+D[t[e+14]]+D[t[e+15]]).toLowerCase()}let Nt;const vn=new Uint8Array(16);function En(){if(!Nt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Nt=crypto.getRandomValues.bind(crypto)}return Nt(vn)}const Sn=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Le={randomUUID:Sn};function Te(t,e,n){if(Le.randomUUID&&!e&&!t)return Le.randomUUID();t=t||{};const o=t.random||(t.rng||En)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,An(o)}const Ut=t=>{const e=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{...t,bodies:(t.bodies||[]).map(e),target:e(t.target)}},xn=(t,e,n,o)=>({id:Te(),annotation:typeof t=="string"?t:t.id,created:n||new Date,creator:o,...e}),Cn=(t,e)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Ln=(t,e)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Tn=(t,e)=>e.bodies.map(n=>{const o=t.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!J(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),On=(t,e)=>!J(t.target,e.target),Oe=(t,e)=>{const n=Cn(t,e),o=Ln(t,e),i=Tn(t,e);return{oldValue:t,newValue:e,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:On(t,e)?{oldTarget:t.target,newTarget:e.target}:void 0}};var I=(t=>(t.LOCAL="LOCAL",t.REMOTE="REMOTE",t.SILENT="SILENT",t))(I||{});const Rn=(t,e)=>{var n,o;const{changes:i,origin:s}=e;if(!(t.options.origin?t.options.origin===s:s!=="SILENT"))return!1;if(t.options.ignore){const{ignore:a}=t.options,r=l=>l&&l.length>0;if(!(r(i.created)||r(i.deleted))){const l=(n=i.updated)==null?void 0:n.some(h=>r(h.bodiesCreated)||r(h.bodiesDeleted)||r(h.bodiesUpdated)),f=(o=i.updated)==null?void 0:o.some(h=>h.targetUpdated);if(a==="BODY_ONLY"&&l&&!f||a==="TARGET_ONLY"&&f&&!l)return!1}}if(t.options.annotations){const a=new Set([...(i.created||[]).map(r=>r.id),...(i.deleted||[]).map(r=>r.id),...(i.updated||[]).map(({oldValue:r})=>r.id)]);return!!(Array.isArray(t.options.annotations)?t.options.annotations:[t.options.annotations]).find(r=>a.has(r))}else return!0},Mn=(t,e)=>{const n=new Set((t.created||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({newValue:u})=>u.id)),i=new Set((e.created||[]).map(u=>u.id)),s=new Set((e.deleted||[]).map(u=>u.id)),a=new Set((e.updated||[]).map(({oldValue:u})=>u.id)),r=new Set((e.updated||[]).filter(({oldValue:u})=>n.has(u.id)||o.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(t.created||[]).filter(u=>!s.has(u.id)).map(u=>a.has(u.id)?e.updated.find(({oldValue:g})=>g.id===u.id).newValue:u),...e.created||[]],f=[...(t.deleted||[]).filter(u=>!i.has(u.id)),...(e.deleted||[]).filter(u=>!n.has(u.id))],h=[...(t.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:g,newValue:p}=u;if(a.has(p.id)){const b=e.updated.find(w=>w.oldValue.id===p.id).newValue;return Oe(g,b)}else return u}),...(e.updated||[]).filter(({oldValue:u})=>!r.has(u.id))];return{created:l,deleted:f,updated:h}},Vt=t=>{const e=t.id===void 0?Te():t.id;return{...t,id:e,bodies:t.bodies===void 0?[]:t.bodies.map(n=>({...n,annotation:e})),target:{...t.target,annotation:e}}},Bn=t=>t.id!==void 0,kn=()=>{const t=new Map,e=new Map,n=[],o=(m,E={})=>{n.push({onChange:m,options:E})},i=m=>{const E=n.findIndex(v=>v.onChange==m);E>-1&&n.splice(E,1)},s=(m,E)=>{const v={origin:m,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...t.values()]};n.forEach(C=>{Rn(C,v)&&C.onChange(v)})},a=(m,E=I.LOCAL)=>{if(m.id&&t.get(m.id))throw Error(`Cannot add annotation ${m.id} - exists already`);{const v=Vt(m);t.set(v.id,v),v.bodies.forEach(C=>e.set(C.id,v.id)),s(E,{created:[v]})}},r=(m,E)=>{const v=Vt(typeof m=="string"?E:m),C=typeof m=="string"?m:m.id,B=C&&t.get(C);if(B){const k=Oe(B,v);return C===v.id?t.set(C,v):(t.delete(C),t.set(v.id,v)),B.bodies.forEach(U=>e.delete(U.id)),v.bodies.forEach(U=>e.set(U.id,v.id)),k}else console.warn(`Cannot update annotation ${C} - does not exist`)},l=(m,E=I.LOCAL,v=I.LOCAL)=>{const C=Bn(E)?v:E,B=r(m,E);B&&s(C,{updated:[B]})},f=(m,E=I.LOCAL)=>{const v=m.reduce((C,B)=>{const k=r(B);return k?[...C,k]:C},[]);v.length>0&&s(E,{updated:v})},h=(m,E=I.LOCAL)=>{const v=t.get(m.annotation);if(v){const C={...v,bodies:[...v.bodies,m]};t.set(v.id,C),e.set(m.id,C.id),s(E,{updated:[{oldValue:v,newValue:C,bodiesCreated:[m]}]})}else console.warn(`Attempt to add body to missing annotation: ${m.annotation}`)},u=()=>[...t.values()],g=(m=I.LOCAL)=>{const E=[...t.values()];t.clear(),e.clear(),s(m,{deleted:E})},p=(m,E=!0,v=I.LOCAL)=>{const C=m.map(Vt);if(E){const B=[...t.values()];t.clear(),e.clear(),C.forEach(k=>{t.set(k.id,k),k.bodies.forEach(U=>e.set(U.id,k.id))}),s(v,{created:C,deleted:B})}else{const B=m.reduce((k,U)=>{const Y=U.id&&t.get(U.id);return Y?[...k,Y]:k},[]);if(B.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${B.map(k=>k.id).join(", ")}`);C.forEach(k=>{t.set(k.id,k),k.bodies.forEach(U=>e.set(U.id,k.id))}),s(v,{created:C})}},b=m=>{const E=typeof m=="string"?m:m.id,v=t.get(E);if(v)return t.delete(E),v.bodies.forEach(C=>e.delete(C.id)),v;console.warn(`Attempt to delete missing annotation: ${E}`)},w=(m,E=I.LOCAL)=>{const v=b(m);v&&s(E,{deleted:[v]})},y=(m,E=I.LOCAL)=>{const v=m.reduce((C,B)=>{const k=b(B);return k?[...C,k]:C},[]);v.length>0&&s(E,{deleted:v})},d=m=>{const E=t.get(m.annotation);if(E){const v=E.bodies.find(C=>C.id===m.id);if(v){e.delete(v.id);const C={...E,bodies:E.bodies.filter(B=>B.id!==m.id)};return t.set(E.id,C),{oldValue:E,newValue:C,bodiesDeleted:[v]}}else console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${m.annotation}`)},c=(m,E=I.LOCAL)=>{const v=d(m);v&&s(E,{updated:[v]})},A=(m,E=I.LOCAL)=>{const v=m.map(C=>d(C)).filter(Boolean);v.length>0&&s(E,{updated:v})},S=m=>{const E=t.get(m);return E?{...E}:void 0},T=m=>{const E=e.get(m);if(E){const v=S(E).bodies.find(C=>C.id===m);if(v)return v;console.error(`Store integrity error: body ${m} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${m}`)},x=(m,E)=>{if(m.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const v=t.get(m.annotation);if(v){const C=v.bodies.find(k=>k.id===m.id),B={...v,bodies:v.bodies.map(k=>k.id===C.id?E:k)};return t.set(v.id,B),C.id!==E.id&&(e.delete(C.id),e.set(E.id,B.id)),{oldValue:v,newValue:B,bodiesUpdated:[{oldBody:C,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${m.annotation}`)},R=(m,E,v=I.LOCAL)=>{const C=x(m,E);C&&s(v,{updated:[C]})},M=(m,E=I.LOCAL)=>{const v=m.map(C=>x({id:C.id,annotation:C.annotation},C)).filter(Boolean);s(E,{updated:v})},L=m=>{const E=t.get(m.annotation);if(E){const v={...E,target:{...E.target,...m}};return t.set(E.id,v),{oldValue:E,newValue:v,targetUpdated:{oldTarget:E.target,newTarget:m}}}else console.warn(`Attempt to update target on missing annotation: ${m.annotation}`)};return{addAnnotation:a,addBody:h,all:u,bulkAddAnnotation:p,bulkDeleteAnnotation:y,bulkDeleteBodies:A,bulkUpdateAnnotation:f,bulkUpdateBodies:M,bulkUpdateTargets:(m,E=I.LOCAL)=>{const v=m.map(C=>L(C)).filter(Boolean);v.length>0&&s(E,{updated:v})},clear:g,deleteAnnotation:w,deleteBody:c,getAnnotation:S,getBody:T,observe:o,unobserve:i,updateAnnotation:l,updateBody:R,updateTarget:(m,E=I.LOCAL)=>{const v=L(m);v&&s(E,{updated:[v]})}}};let In=()=>({emit(t,...e){for(let n=this.events[t]||[],o=0,i=n.length;o<i;o++)n[o](...e)},events:{},on(t,e){var n;return((n=this.events)[t]||(n[t]=[])).push(e),()=>{var o;this.events[t]=(o=this.events[t])==null?void 0:o.filter(i=>e!==i)}}});const _n=250,Nn=t=>{const e=In(),n=[];let o=-1,i=!1,s=0;const a=p=>{if(!i){const{changes:b}=p,w=performance.now();if(w-s>_n)n.splice(o+1),n.push(b),o=n.length-1;else{const y=n.length-1;n[y]=Mn(n[y],b)}s=w}i=!1};t.observe(a,{origin:I.LOCAL});const r=p=>p&&p.length>0&&t.bulkDeleteAnnotation(p),l=p=>p&&p.length>0&&t.bulkAddAnnotation(p,!1),f=p=>p&&p.length>0&&t.bulkUpdateAnnotation(p.map(({oldValue:b})=>b)),h=p=>p&&p.length>0&&t.bulkUpdateAnnotation(p.map(({newValue:b})=>b)),u=p=>p&&p.length>0&&t.bulkAddAnnotation(p,!1),g=p=>p&&p.length>0&&t.bulkDeleteAnnotation(p);return{canRedo:()=>n.length-1>o,canUndo:()=>o>-1,destroy:()=>t.unobserve(a),on:(p,b)=>e.on(p,b),redo:()=>{if(n.length-1>o){i=!0;const{created:p,updated:b,deleted:w}=n[o+1];l(p),h(b),g(w),e.emit("redo",n[o+1]),o+=1}},undo:()=>{if(o>-1){i=!0;const{created:p,updated:b,deleted:w}=n[o];r(p),f(b),u(w),e.emit("undo",n[o]),o-=1}}}},Un=()=>{const{subscribe:t,set:e}=_t([]);return{subscribe:t,set:e}},Vn=(t,e,n,o)=>{const{hover:i,selection:s,store:a,viewport:r}=t,l=new Map;let f=[],h;const u=(w,y)=>{l.has(w)?l.get(w).push(y):l.set(w,[y])},g=(w,y)=>{const d=l.get(w);if(d){const c=d.indexOf(y);c!==-1&&d.splice(c,1)}},p=(w,y,d)=>{l.has(w)&&setTimeout(()=>{l.get(w).forEach(c=>{if(n){const A=Array.isArray(y)?y.map(T=>n.serialize(T)):n.serialize(y),S=d?d instanceof PointerEvent?d:n.serialize(d):void 0;c(A,S)}else c(y,d)})},1)};s.subscribe(({selected:w})=>{if(!(f.length===0&&w.length===0)){if(f.length===0&&w.length>0)f=w.map(({id:y})=>a.getAnnotation(y));else if(f.length>0&&w.length===0)f.forEach(y=>{const d=a.getAnnotation(y.id);d&&!J(d,y)&&p("updateAnnotation",d,y)}),f=[];else{const y=new Set(f.map(c=>c.id)),d=new Set(w.map(({id:c})=>c));f.filter(c=>!d.has(c.id)).forEach(c=>{const A=a.getAnnotation(c.id);A&&!J(A,c)&&p("updateAnnotation",A,c)}),f=[...f.filter(c=>d.has(c.id)),...w.filter(({id:c})=>!y.has(c)).map(({id:c})=>a.getAnnotation(c))]}p("selectionChanged",f)}}),i.subscribe(w=>{!h&&w?p("mouseEnterAnnotation",a.getAnnotation(w)):h&&!w?p("mouseLeaveAnnotation",a.getAnnotation(h)):h&&w&&(p("mouseLeaveAnnotation",a.getAnnotation(h)),p("mouseEnterAnnotation",a.getAnnotation(w))),h=w}),r==null||r.subscribe(w=>p("viewportIntersect",w.map(y=>a.getAnnotation(y)))),a.observe(w=>{const{created:y,deleted:d}=w.changes;(y||[]).forEach(c=>p("createAnnotation",c)),(d||[]).forEach(c=>p("deleteAnnotation",c)),(w.changes.updated||[]).filter(c=>[...c.bodiesCreated||[],...c.bodiesDeleted||[],...c.bodiesUpdated||[]].length>0).forEach(({oldValue:c,newValue:A})=>{const S=f.find(T=>T.id===c.id)||c;f=f.map(T=>T.id===c.id?A:T),p("updateAnnotation",A,S)})},{origin:I.LOCAL}),a.observe(w=>{if(f){const y=new Set(f.map(c=>c.id)),d=(w.changes.updated||[]).filter(({newValue:c})=>y.has(c.id)).map(({newValue:c})=>c);d.length>0&&(f=f.map(c=>d.find(S=>S.id===c.id)||c))}},{origin:I.REMOTE});const b=w=>y=>{const{updated:d}=y;w?(d||[]).forEach(c=>p("updateAnnotation",c.oldValue,c.newValue)):(d||[]).forEach(c=>p("updateAnnotation",c.newValue,c.oldValue))};return e.on("undo",b(!0)),e.on("redo",b(!1)),{on:u,off:g,emit:p}},Yn=t=>e=>e.reduce((n,o)=>{const{parsed:i,error:s}=t.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Kn=(t,e,n)=>{const{store:o,selection:i}=t,s=d=>{if(n){const{parsed:c,error:A}=n.parse(d);c?o.addAnnotation(c,I.REMOTE):console.error(A)}else o.addAnnotation(Ut(d),I.REMOTE)},a=()=>i.clear(),r=()=>o.clear(),l=d=>{const c=o.getAnnotation(d);return n&&c?n.serialize(c):c},f=()=>n?o.all().map(n.serialize):o.all(),h=()=>{var d;const c=(((d=i.selected)==null?void 0:d.map(A=>A.id))||[]).map(A=>o.getAnnotation(A)).filter(Boolean);return n?c.map(n.serialize):c},u=(d,c=!0)=>fetch(d).then(A=>A.json()).then(A=>(p(A,c),A)),g=d=>{if(typeof d=="string"){const c=o.getAnnotation(d);if(o.deleteAnnotation(d),c)return n?n.serialize(c):c}else{const c=n?n.parse(d).parsed:d;if(c)return o.deleteAnnotation(c),d}},p=(d,c=!0)=>{if(n){const A=n.parseAll||Yn(n),{parsed:S,failed:T}=A(d);T.length>0&&console.warn(`Discarded ${T.length} invalid annotations`,T),o.bulkAddAnnotation(S,c,I.REMOTE)}else o.bulkAddAnnotation(d.map(Ut),c,I.REMOTE)},b=(d,c)=>{d?i.setSelected(d,c):i.clear()},w=d=>{i.clear(),i.setUserSelectAction(d)},y=d=>{if(n){const c=n.parse(d).parsed,A=n.serialize(o.getAnnotation(c.id));return o.updateAnnotation(c),A}else{const c=o.getAnnotation(d.id);return o.updateAnnotation(Ut(d)),c}};return{addAnnotation:s,cancelSelected:a,canRedo:e.canRedo,canUndo:e.canUndo,clearAnnotations:r,getAnnotationById:l,getAnnotations:f,getSelected:h,loadAnnotations:u,redo:e.redo,removeAnnotation:g,setAnnotations:p,setSelected:b,setUserSelectAction:w,undo:e.undo,updateAnnotation:y}},Dn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Xn=t=>crypto.getRandomValues(new Uint8Array(t)),Pn=(t,e,n)=>{let o=(2<<Math.log2(t.length-1))-1,i=-~(1.6*o*e/t.length);return(s=e)=>{let a="";for(;;){let r=n(i),l=i;for(;l--;)if(a+=t[r[l]&o]||"",a.length===s)return a}}},$n=(t,e=21)=>Pn(t,e,Xn),Hn=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=Dn[n[t]&63];return e};const jn=()=>({isGuest:!0,id:$n("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Fn=t=>{const e=JSON.stringify(t);let n=0;for(let o=0,i=e.length;o<i;o++){let s=e.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Re=t=>t?typeof t=="object"?{...t}:t:void 0,zn=(t,e)=>(Array.isArray(t)?t:[t]).map(n=>{const{id:o,type:i,purpose:s,value:a,created:r,modified:l,creator:f,...h}=n;return{id:o||`temp-${Fn(n)}`,annotation:e,type:i,purpose:s,value:a,creator:Re(f),created:r?new Date(r):void 0,updated:l?new Date(l):void 0,...h}}),Wn=t=>t.map(e=>{var n;const{annotation:o,created:i,updated:s,...a}=e,r={...a,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=r.id)!=null&&n.startsWith("temp-")&&delete r.id,r});Hn();const qn=(t,e)=>({parse:n=>Me(n),serialize:n=>Be(n,t,e)}),Gn=t=>t.quote!==void 0&&t.start!==void 0&&t.end!==void 0,Qn=t=>{const{id:e,creator:n,created:o,modified:i,target:s}=t,a=Array.isArray(s)?s:[s];if(a.length===0)return{error:Error(`No targets found for annotation: ${t.id}`)};const r={creator:Re(n),created:o?new Date(o):void 0,updated:i?new Date(i):void 0,annotation:e,selector:[],styleClass:"styleClass"in a[0]?a[0].styleClass:void 0};for(const l of a){const h=(Array.isArray(l.selector)?l.selector:[l.selector]).reduce((u,g)=>{switch(g.type){case"TextQuoteSelector":u.quote=g.exact;break;case"TextPositionSelector":u.start=g.start,u.end=g.end;break}return u},{});if(Gn(h))r.selector.push({...h,id:l.id,scope:l.scope});else{const u=[h.start?void 0:"TextPositionSelector",h.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`)}}}return{parsed:r}},Me=t=>{const e=t.id||Ee(),{creator:n,created:o,modified:i,body:s,...a}=t,r=zn(s,e),l=Qn(t);return"error"in l?{error:l.error}:{parsed:{...a,id:e,bodies:r,target:l.parsed}}},Be=(t,e,n)=>{const{bodies:o,target:i,...s}=t,{selector:a,creator:r,created:l,updated:f,...h}=i,u=a.map(g=>{const{id:p,quote:b,start:w,end:y,range:d}=g,{prefix:c,suffix:A}=Gt(d,n),S=[{type:"TextQuoteSelector",exact:b,prefix:c,suffix:A},{type:"TextPositionSelector",start:w,end:y}];return{...h,id:p,scope:"scope"in g?g.scope:void 0,source:e,selector:S}});return{...s,"@context":"http://www.w3.org/ns/anno.jsonld",id:t.id,type:"Annotation",body:Wn(t.bodies),creator:r,created:l==null?void 0:l.toISOString(),modified:f==null?void 0:f.toISOString(),target:u}};function ke(t,e,n=0,o=t.length-1,i=Jn){for(;o>n;){if(o-n>600){const l=o-n+1,f=e-n+1,h=Math.log(l),u=.5*Math.exp(2*h/3),g=.5*Math.sqrt(h*u*(l-u)/l)*(f-l/2<0?-1:1),p=Math.max(n,Math.floor(e-f*u/l+g)),b=Math.min(o,Math.floor(e+(l-f)*u/l+g));ke(t,e,p,b,i)}const s=t[e];let a=n,r=o;for(ct(t,n,e),i(t[o],s)>0&&ct(t,n,o);a<r;){for(ct(t,a,r),a++,r--;i(t[a],s)<0;)a++;for(;i(t[r],s)>0;)r--}i(t[n],s)===0?ct(t,n,r):(r++,ct(t,r,o)),r<=e&&(n=r+1),e<=r&&(o=r-1)}}function ct(t,e,n){const o=t[e];t[e]=t[n],t[n]=o}function Jn(t,e){return t<e?-1:t>e?1:0}class Zn{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let n=this.data;const o=[];if(!xt(e,n))return o;const i=this.toBBox,s=[];for(;n;){for(let a=0;a<n.children.length;a++){const r=n.children[a],l=n.leaf?i(r):r;xt(e,l)&&(n.leaf?o.push(r):Kt(e,l)?this._all(r,o):s.push(r))}n=s.pop()}return o}collides(e){let n=this.data;if(!xt(e,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],a=n.leaf?this.toBBox(s):s;if(xt(e,a)){if(n.leaf||Kt(e,a))return!0;o.push(s)}}n=o.pop()}return!1}load(e){if(!(e&&e.length))return this;if(e.length<this._minEntries){for(let o=0;o<e.length;o++)this.insert(e[o]);return this}let n=this._build(e.slice(),0,e.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(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=ot([]),this}remove(e,n){if(!e)return this;let o=this.data;const i=this.toBBox(e),s=[],a=[];let r,l,f;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],r=a.pop(),f=!0),o.leaf){const h=to(e,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!f&&!o.leaf&&Kt(o,i)?(s.push(o),a.push(r),r=0,l=o,o=o.children[0]):l?(r++,o=l.children[r],f=!1):o=null}return this}toBBox(e){return e}compareMinX(e,n){return e.minX-n.minX}compareMinY(e,n){return e.minY-n.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,n){const o=[];for(;e;)e.leaf?n.push(...e.children):o.push(...e.children),e=o.pop();return n}_build(e,n,o,i){const s=o-n+1;let a=this._maxEntries,r;if(s<=a)return r=ot(e.slice(n,o+1)),nt(r,this.toBBox),r;i||(i=Math.ceil(Math.log(s)/Math.log(a)),a=Math.ceil(s/Math.pow(a,i-1))),r=ot([]),r.leaf=!1,r.height=i;const l=Math.ceil(s/a),f=l*Math.ceil(Math.sqrt(a));Ie(e,n,o,f,this.compareMinX);for(let h=n;h<=o;h+=f){const u=Math.min(h+f-1,o);Ie(e,h,u,l,this.compareMinY);for(let g=h;g<=u;g+=l){const p=Math.min(g+l-1,u);r.children.push(this._build(e,g,p,i-1))}}return nt(r,this.toBBox),r}_chooseSubtree(e,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,a=1/0,r;for(let l=0;l<n.children.length;l++){const f=n.children[l],h=Yt(f),u=oo(e,f)-h;u<a?(a=u,s=h<s?h:s,r=f):u===a&&h<s&&(s=h,r=f)}n=r||n.children[0]}return n}_insert(e,n,o){const i=o?e:this.toBBox(e),s=[],a=this._chooseSubtree(i,this.data,n,s);for(a.children.push(e),dt(a,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(e,n){const o=e[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const a=this._chooseSplitIndex(o,s,i),r=ot(o.children.splice(a,o.children.length-a));r.height=o.height,r.leaf=o.leaf,nt(o,this.toBBox),nt(r,this.toBBox),n?e[n-1].children.push(r):this._splitRoot(o,r)}_splitRoot(e,n){this.data=ot([e,n]),this.data.height=e.height+1,this.data.leaf=!1,nt(this.data,this.toBBox)}_chooseSplitIndex(e,n,o){let i,s=1/0,a=1/0;for(let r=n;r<=o-n;r++){const l=lt(e,0,r,this.toBBox),f=lt(e,r,o,this.toBBox),h=io(l,f),u=Yt(l)+Yt(f);h<s?(s=h,i=r,a=u<a?u:a):h===s&&u<a&&(a=u,i=r)}return i||o-n}_chooseSplitAxis(e,n,o){const i=e.leaf?this.compareMinX:eo,s=e.leaf?this.compareMinY:no,a=this._allDistMargin(e,n,o,i),r=this._allDistMargin(e,n,o,s);a<r&&e.children.sort(i)}_allDistMargin(e,n,o,i){e.children.sort(i);const s=this.toBBox,a=lt(e,0,n,s),r=lt(e,o-n,o,s);let l=St(a)+St(r);for(let f=n;f<o-n;f++){const h=e.children[f];dt(a,e.leaf?s(h):h),l+=St(a)}for(let f=o-n-1;f>=n;f--){const h=e.children[f];dt(r,e.leaf?s(h):h),l+=St(r)}return l}_adjustParentBBoxes(e,n,o){for(let i=o;i>=0;i--)dt(n[i],e)}_condense(e){for(let n=e.length-1,o;n>=0;n--)e[n].children.length===0?n>0?(o=e[n-1].children,o.splice(o.indexOf(e[n]),1)):this.clear():nt(e[n],this.toBBox)}}function to(t,e,n){if(!n)return e.indexOf(t);for(let o=0;o<e.length;o++)if(n(t,e[o]))return o;return-1}function nt(t,e){lt(t,0,t.children.length,e,t)}function lt(t,e,n,o,i){i||(i=ot(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=e;s<n;s++){const a=t.children[s];dt(i,t.leaf?o(a):a)}return i}function dt(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function eo(t,e){return t.minX-e.minX}function no(t,e){return t.minY-e.minY}function Yt(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function St(t){return t.maxX-t.minX+(t.maxY-t.minY)}function oo(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function io(t,e){const n=Math.max(t.minX,e.minX),o=Math.max(t.minY,e.minY),i=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function Kt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function xt(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function ot(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Ie(t,e,n,o,i){const s=[e,n];for(;s.length;){if(n=s.pop(),e=s.pop(),n-e<=o)continue;const a=e+Math.ceil((n-e)/o/2)*o;ke(t,a,e,n,i),s.push(e,a,a,n)}}const so=(t,e)=>{const n=new Zn,o=new Map,i=(d,c)=>{const A=d.selector.flatMap(T=>{const x=j([T])?T.range:Lt(T,e).range;return Array.from(x.getClientRects())}),S=Zt(A).map(({left:T,top:x,right:R,bottom:M})=>new DOMRect(T-c.left,x-c.top,R-T,M-x));return S.map(T=>{const{x,y:R,width:M,height:L}=T;return{minX:x,minY:R,maxX:x+M,maxY:R+L,annotation:{id:d.annotation,rects:S}}})},s=()=>[...o.values()],a=()=>{n.clear(),o.clear()},r=d=>{const c=i(d,e.getBoundingClientRect());c.forEach(A=>n.insert(A)),o.set(d.annotation,c)},l=d=>{const c=o.get(d.annotation);c&&(c.forEach(A=>n.remove(A)),o.delete(d.annotation))},f=d=>{l(d),r(d)},h=(d,c=!0)=>{c&&a();const A=e.getBoundingClientRect(),S=d.map(x=>({target:x,rects:i(x,A)}));S.forEach(({target:x,rects:R})=>o.set(x.annotation,R));const T=S.flatMap(({rects:x})=>x);n.load(T)},u=(d,c,A=!1)=>{const S=n.search({minX:d,minY:c,maxX:d,maxY:c}),T=x=>x.annotation.rects.reduce((R,M)=>R+M.width*M.height,0);return S.length>0?(S.sort((x,R)=>T(x)-T(R)),A?S.map(x=>x.annotation.id):[S[0].annotation.id]):[]},g=d=>{const c=p(d);if(c.length===0)return;let A=c[0].left,S=c[0].top,T=c[0].right,x=c[0].bottom;for(let R=1;R<c.length;R++){const M=c[R];A=Math.min(A,M.left),S=Math.min(S,M.top),T=Math.max(T,M.right),x=Math.max(x,M.bottom)}return new DOMRect(A,S,T-A,x-S)},p=d=>{const c=o.get(d);return c?c[0].annotation.rects:[]};return{all:s,clear:a,getAt:u,getAnnotationBounds:g,getAnnotationRects:p,getIntersecting:(d,c,A,S)=>{const T=n.search({minX:d,minY:c,maxX:A,maxY:S}),x=new Set(T.map(R=>R.annotation.id));return Array.from(x).map(R=>({annotation:t.getAnnotation(R),rects:p(R)})).filter(R=>!!R.annotation)},insert:r,recalculate:()=>h(t.all().map(d=>d.target),!0),remove:l,set:h,size:()=>n.all().length,update:f}},_e=(t,e)=>{const n=kn(),o=so(n,t),i=wn(n);i.setUserSelectAction(e);const s=bn(n),a=Un(),r=(y,d=I.LOCAL)=>{const c=At(y,t),A=j(c.target.selector);return A&&n.addAnnotation(c,d),A},l=(y,d=!0,c=I.LOCAL)=>{const A=y.map(T=>At(T,t)),S=A.filter(T=>!j(T.target.selector));return n.bulkAddAnnotation(A,d,c),S},f=(y,d=I.LOCAL)=>{const c=y.map(S=>At(S,t)),A=c.filter(S=>!j(S.target.selector));return c.forEach(S=>{n.getAnnotation(S.id)?n.updateAnnotation(S,d):n.addAnnotation(S,d)}),A},h=(y,d=I.LOCAL)=>{const c=st(y,t);n.updateTarget(c,d)},u=(y,d=I.LOCAL)=>{const c=y.map(A=>st(A,t));n.bulkUpdateTargets(c,d)};function g(y,d,c,A){const S=c||!!A,T=o.getAt(y,d,S).map(R=>n.getAnnotation(R)),x=A?T.filter(A):T;if(x.length!==0)return c?x:x[0]}const p=(y,d,c,A=5)=>{const S=o.getAnnotationRects(y);if(S.length!==0){if(d&&c){const T=S.find(({top:x,right:R,bottom:M,left:L})=>d>=L-A&&d<=R+A&&c>=x-A&&c<=M+A);if(T)return T}return o.getAnnotationBounds(y)}},b=y=>o.getAnnotationRects(y),w=()=>o.recalculate();return n.observe(({changes:y})=>{const d=(y.deleted||[]).filter(S=>j(S.target.selector)),c=(y.created||[]).filter(S=>j(S.target.selector)),A=(y.updated||[]).filter(S=>j(S.newValue.target.selector));(d==null?void 0:d.length)>0&&d.forEach(S=>o.remove(S.target)),c.length>0&&o.set(c.map(S=>S.target),!1),(A==null?void 0:A.length)>0&&A.forEach(({newValue:S})=>o.update(S.target))}),{store:{...n,addAnnotation:r,bulkAddAnnotation:l,bulkUpdateTargets:u,bulkUpsertAnnotations:f,getAnnotationBounds:p,getAnnotationRects:b,getAt:g,getIntersecting:o.getIntersecting,recalculatePositions:w,updateTarget:h},selection:i,hover:s,viewport:a}},ro=()=>{const t=document.createElement("canvas");t.width=2*window.innerWidth,t.height=2*window.innerHeight,t.className="r6o-presence-layer";const e=t.getContext("2d");return e.scale(2,2),e.translate(.5,.5),t},Ne=(t,e={})=>{const n=ro(),o=n.getContext("2d");document.body.appendChild(n);const i=new Map,s=h=>Array.from(i.entries()).filter(([u,g])=>g.presenceKey===h.presenceKey).map(([u,g])=>u);return t.on("selectionChange",(h,u)=>{s(h).forEach(p=>i.delete(p)),u&&u.forEach(p=>i.set(p,h))}),{clear:()=>{const{width:h,height:u}=n;o.clearRect(-.5,-.5,h+1,u+1)},destroy:()=>{n.remove()},paint:(h,u,g)=>{e.font&&(o.font=e.font);const p=i.get(h.annotation.id);if(p){const{height:b}=h.rects[0],w=h.rects[0].x+u.left,y=h.rects[0].y+u.top;o.fillStyle=p.appearance.color,o.fillRect(w-2,y-2.5,2,b+5);const d=o.measureText(p.appearance.label),c=d.width+6,A=d.actualBoundingBoxAscent+d.actualBoundingBoxDescent+8,S=d.fontBoundingBoxAscent?8:6.5;return o.fillRect(w-2,y-2.5-A,c,A),o.fillStyle="#fff",o.fillText(p.appearance.label,w+1,y-S),{fill:p.appearance.color,fillOpacity:g?.45:.18}}},reset:()=>{n.width=2*window.innerWidth,n.height=2*window.innerHeight;const h=n.getContext("2d");h.scale(2,2),h.translate(.5,.5)}}},Dt=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function Xt(t,e,n,o){t.addEventListener?t.addEventListener(e,n,o):t.attachEvent&&t.attachEvent("on".concat(e),n)}function ut(t,e,n,o){t.removeEventListener?t.removeEventListener(e,n,o):t.detachEvent&&t.detachEvent("on".concat(e),n)}function Ue(t,e){const n=e.slice(0,e.length-1);for(let o=0;o<n.length;o++)n[o]=t[n[o].toLowerCase()];return n}function Ve(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function ao(t,e){const n=t.length>=e.length?t:e,o=t.length>=e.length?e:t;let i=!0;for(let s=0;s<n.length;s++)o.indexOf(n[s])===-1&&(i=!1);return i}const ft={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,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,"-":Dt?173:189,"=":Dt?61:187,";":Dt?59:186,"'":222,"[":219,"]":221,"\\":220},F={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Pt={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},N={};for(let t=1;t<20;t++)ft["f".concat(t)]=111+t;let _=[],ht=null,Ye="all";const q=new Map,gt=t=>ft[t.toLowerCase()]||F[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),co=t=>Object.keys(ft).find(e=>ft[e]===t),lo=t=>Object.keys(F).find(e=>F[e]===t);function Ke(t){Ye=t||"all"}function pt(){return Ye||"all"}function uo(){return _.slice(0)}function fo(){return _.map(t=>co(t)||lo(t)||String.fromCharCode(t))}function ho(){const t=[];return Object.keys(N).forEach(e=>{N[e].forEach(n=>{let{key:o,scope:i,mods:s,shortcut:a}=n;t.push({scope:i,shortcut:a,mods:s,keys:o.split("+").map(r=>gt(r))})})}),t}function go(t){const e=t.target||t.srcElement,{tagName:n}=e;let o=!0;const i=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(e.type);return(e.isContentEditable||(i||n==="TEXTAREA"||n==="SELECT")&&!e.readOnly)&&(o=!1),o}function po(t){return typeof t=="string"&&(t=gt(t)),_.indexOf(t)!==-1}function mo(t,e){let n,o;t||(t=pt());for(const i in N)if(Object.prototype.hasOwnProperty.call(N,i))for(n=N[i],o=0;o<n.length;)n[o].scope===t?n.splice(o,1).forEach(a=>{let{element:r}=a;return $t(r)}):o++;pt()===t&&Ke(e||"all")}function yo(t){let e=t.keyCode||t.which||t.charCode;const n=_.indexOf(e);if(n>=0&&_.splice(n,1),t.key&&t.key.toLowerCase()==="meta"&&_.splice(0,_.length),(e===93||e===224)&&(e=91),e in X){X[e]=!1;for(const o in F)F[o]===e&&($[o]=!1)}}function De(t){if(typeof t>"u")Object.keys(N).forEach(i=>{Array.isArray(N[i])&&N[i].forEach(s=>Ct(s)),delete N[i]}),$t(null);else if(Array.isArray(t))t.forEach(i=>{i.key&&Ct(i)});else if(typeof t=="object")t.key&&Ct(t);else if(typeof t=="string"){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];let[i,s]=n;typeof i=="function"&&(s=i,i=""),Ct({key:t,scope:i,method:s,splitKey:"+"})}}const Ct=t=>{let{key:e,scope:n,method:o,splitKey:i="+"}=t;Ve(e).forEach(a=>{const r=a.split(i),l=r.length,f=r[l-1],h=f==="*"?"*":gt(f);if(!N[h])return;n||(n=pt());const u=l>1?Ue(F,r):[],g=[];N[h]=N[h].filter(p=>{const w=(o?p.method===o:!0)&&p.scope===n&&ao(p.mods,u);return w&&g.push(p.element),!w}),g.forEach(p=>$t(p))})};function Xe(t,e,n,o){if(e.element!==o)return;let i;if(e.scope===n||e.scope==="all"){i=e.mods.length>0;for(const s in X)Object.prototype.hasOwnProperty.call(X,s)&&(!X[s]&&e.mods.indexOf(+s)>-1||X[s]&&e.mods.indexOf(+s)===-1)&&(i=!1);(e.mods.length===0&&!X[16]&&!X[18]&&!X[17]&&!X[91]||i||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(_),e.method(t,e)===!1&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0)))}}function Pe(t,e){const n=N["*"];let o=t.keyCode||t.which||t.charCode;if(!$.filter.call(this,t))return;if((o===93||o===224)&&(o=91),_.indexOf(o)===-1&&o!==229&&_.push(o),["ctrlKey","altKey","shiftKey","metaKey"].forEach(r=>{const l=Pt[r];t[r]&&_.indexOf(l)===-1?_.push(l):!t[r]&&_.indexOf(l)>-1?_.splice(_.indexOf(l),1):r==="metaKey"&&t[r]&&_.length===3&&(t.ctrlKey||t.shiftKey||t.altKey||(_=_.slice(_.indexOf(l))))}),o in X){X[o]=!0;for(const r in F)F[r]===o&&($[r]=!0);if(!n)return}for(const r in X)Object.prototype.hasOwnProperty.call(X,r)&&(X[r]=t[Pt[r]]);t.getModifierState&&!(t.altKey&&!t.ctrlKey)&&t.getModifierState("AltGraph")&&(_.indexOf(17)===-1&&_.push(17),_.indexOf(18)===-1&&_.push(18),X[17]=!0,X[18]=!0);const i=pt();if(n)for(let r=0;r<n.length;r++)n[r].scope===i&&(t.type==="keydown"&&n[r].keydown||t.type==="keyup"&&n[r].keyup)&&Xe(t,n[r],i,e);if(!(o in N))return;const s=N[o],a=s.length;for(let r=0;r<a;r++)if((t.type==="keydown"&&s[r].keydown||t.type==="keyup"&&s[r].keyup)&&s[r].key){const l=s[r],{splitKey:f}=l,h=l.key.split(f),u=[];for(let g=0;g<h.length;g++)u.push(gt(h[g]));u.sort().join("")===_.sort().join("")&&Xe(t,l,i,e)}}function $(t,e,n){_=[];const o=Ve(t);let i=[],s="all",a=document,r=0,l=!1,f=!0,h="+",u=!1,g=!1;for(n===void 0&&typeof e=="function"&&(n=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(s=e.scope),e.element&&(a=e.element),e.keyup&&(l=e.keyup),e.keydown!==void 0&&(f=e.keydown),e.capture!==void 0&&(u=e.capture),typeof e.splitKey=="string"&&(h=e.splitKey),e.single===!0&&(g=!0)),typeof e=="string"&&(s=e),g&&De(t,s);r<o.length;r++)t=o[r].split(h),i=[],t.length>1&&(i=Ue(F,t)),t=t[t.length-1],t=t==="*"?"*":gt(t),t in N||(N[t]=[]),N[t].push({keyup:l,keydown:f,scope:s,mods:i,shortcut:o[r],method:n,key:o[r],splitKey:h,element:a});if(typeof a<"u"&&window){if(!q.has(a)){const p=function(){let w=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return Pe(w,a)},b=function(){let w=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;Pe(w,a),yo(w)};q.set(a,{keydownListener:p,keyupListenr:b,capture:u}),Xt(a,"keydown",p,u),Xt(a,"keyup",b,u)}if(!ht){const p=()=>{_=[]};ht={listener:p,capture:u},Xt(window,"focus",p,u)}}}function bo(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(N).forEach(n=>{N[n].filter(i=>i.scope===e&&i.shortcut===t).forEach(i=>{i&&i.method&&i.method()})})}function $t(t){const e=Object.values(N).flat();if(e.findIndex(o=>{let{element:i}=o;return i===t})<0){const{keydownListener:o,keyupListenr:i,capture:s}=q.get(t)||{};o&&i&&(ut(t,"keyup",i,s),ut(t,"keydown",o,s),q.delete(t))}if((e.length<=0||q.size<=0)&&(Object.keys(q).forEach(i=>{const{keydownListener:s,keyupListenr:a,capture:r}=q.get(i)||{};s&&a&&(ut(i,"keyup",a,r),ut(i,"keydown",s,r),q.delete(i))}),q.clear(),Object.keys(N).forEach(i=>delete N[i]),ht)){const{listener:i,capture:s}=ht;ut(window,"focus",i,s),ht=null}}const Ht={getPressedKeyString:fo,setScope:Ke,getScope:pt,deleteScope:mo,getPressedKeyCodes:uo,getAllKeyCodes:ho,isPressed:po,filter:go,trigger:bo,unbind:De,keyMap:ft,modifier:F,modifierMap:Pt};for(const t in Ht)Object.prototype.hasOwnProperty.call(Ht,t)&&($[t]=Ht[t]);if(typeof window<"u"){const t=window.hotkeys;$.noConflict=e=>(e&&window.hotkeys===$&&(window.hotkeys=t),$),window.hotkeys=$}const $e=300,He=["up","down","left","right"],je=zt?"⌘+a":"ctrl+a",wo=[...He.map(t=>`shift+${t}`),je],Fe=(t,e,n)=>{let o;const{annotatingEnabled:i,offsetReferenceSelector:s,selectionMode:a}=n,r=L=>o=L;let l;const f=L=>l=L,{store:h,selection:u}=e;let g,p,b;const w=L=>{p!==!1&&(g=tt(L.target)?void 0:{annotation:Ee(),selector:[],creator:o,created:new Date})},y=bt(L=>{const m=document.getSelection();if(tt(m.anchorNode)){g=void 0;return}const E=L.timeStamp-((b==null?void 0:b.timeStamp)||L.timeStamp);if((b==null?void 0:b.type)==="pointerdown"&&(E<1e3&&!g||m.isCollapsed&&E<$e)&&w(b||L),!g)return;if(m.isCollapsed){h.getAnnotation(g.annotation)&&(u.clear(),h.deleteAnnotation(g.annotation));return}const v=m.getRangeAt(0),C=ee(v,t);if(Jt(C))return;const B=qt(C.cloneRange());(B.length!==g.selector.length||B.some((U,Y)=>{var mt;return U.toString()!==((mt=g.selector[Y])==null?void 0:mt.quote)}))&&(g={...g,selector:B.map(U=>te(U,t,s)),updated:new Date},h.getAnnotation(g.annotation)?h.updateTarget(g,I.LOCAL):u.clear())}),d=L=>{tt(L.target)||(b=yt(L),p=b.button===0)},c=L=>{if(tt(L.target)||!p)return;const m=()=>{const{x:v,y:C}=t.getBoundingClientRect(),B=L.target instanceof Node&&t.contains(L.target)&&h.getAt(L.clientX-v,L.clientY-C,a==="all",l);if(B){const{selected:k}=u,U=new Set(k.map(Z=>Z.id)),Y=Array.isArray(B)?B.map(Z=>Z.id):[B.id];(U.size!==Y.length||!Y.every(Z=>U.has(Z)))&&u.userSelect(Y,L)}else u.clear()},E=L.timeStamp-b.timeStamp;setTimeout(()=>{const v=document.getSelection();v!=null&&v.isCollapsed&&E<$e?(g=void 0,m()):g&&g.selector.length>0&&(u.clear(),R(),u.userSelect(g.annotation,yt(L)))})},A=L=>{const m=document.getSelection();m!=null&&m.isCollapsed||((!g||g.selector.length===0)&&y(L),R(),u.userSelect(g.annotation,yt(L)))},S=L=>{L.key==="Shift"&&g&&(document.getSelection().isCollapsed||(u.clear(),R(),u.userSelect(g.annotation,it(L))))},T=L=>{const m=()=>setTimeout(()=>{(g==null?void 0:g.selector.length)>0&&(u.clear(),h.addAnnotation({id:g.annotation,bodies:[],target:g}),u.userSelect(g.annotation,it(L))),document.removeEventListener("selectionchange",m)},100);document.addEventListener("selectionchange",m),w(L)};$(wo.join(","),{element:t,keydown:!0,keyup:!1},L=>{L.repeat||(b=it(L))}),$(je,{keydown:!0,keyup:!1},L=>{b=it(L),T(L)});const x=L=>{L.repeat||L.target!==t&&L.target!==document.body||(g=void 0,u.clear())};$(He.join(","),{keydown:!0,keyup:!1},x);const R=()=>{const L=h.getAnnotation(g.annotation);if(!L){h.addAnnotation({id:g.annotation,bodies:[],target:g});return}const{target:{updated:m}}=L,{updated:E}=g;(!m||!E||m<E)&&h.updateTarget(g)};return t.addEventListener("pointerdown",d),document.addEventListener("pointerup",c),document.addEventListener("contextmenu",A),i&&(t.addEventListener("keyup",S),t.addEventListener("selectstart",w),document.addEventListener("selectionchange",y)),{destroy:()=>{t.removeEventListener("pointerdown",d),document.removeEventListener("pointerup",c),document.removeEventListener("contextmenu",A),t.removeEventListener("keyup",S),t.removeEventListener("selectstart",w),document.removeEventListener("selectionchange",y),$.unbind()},setFilter:f,setUser:r}},ze=(t,e)=>({...t,annotatingEnabled:t.annotatingEnabled??e.annotatingEnabled,user:t.user||e.user}),We="SPANS",Ao=(t,e={})=>{Ft(t),Wt(t);const n=ze(e,{annotatingEnabled:!0,user:jn()}),o=_e(t,n.userSelectAction),{selection:i,viewport:s}=o,a=o.store,r=Nn(a),l=Vn(o,r,n.adapter);let f=n.user;const h=n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":We:n.renderer||We,u=h==="SPANS"?Ae(t,o,s):h==="CSS_HIGHLIGHTS"?be(t,o,s):h==="CANVAS"?se(t,o,s):void 0;if(!u)throw`Unknown renderer implementation: ${h}`;console.debug(`Using ${h} renderer`),n.style&&u.setStyle(n.style);const g=Fe(t,o,n);return g.setUser(f),{...Kn(o,r,n.adapter),destroy:()=>{u.destroy(),g.destroy(),r.destroy()},element:t,getUser:()=>f,setFilter:x=>{u.setFilter(x),g.setFilter(x)},setStyle:x=>u.setStyle(x),setUser:x=>{f=x,g.setUser(x)},setSelected:x=>{x?i.setSelected(x):i.clear()},setPresenceProvider:x=>{x&&(u.setPainter(Ne(x,n.presence)),x.on("selectionChange",()=>u.redraw()))},setVisible:x=>u.setVisible(x),on:l.on,off:l.off,scrollIntoView:oe(t,a),state:o}};O.DEFAULT_SELECTED_STYLE=rt,O.DEFAULT_STYLE=z,O.NOT_ANNOTATABLE_CLASS=G,O.NOT_ANNOTATABLE_SELECTOR=Q,O.Origin=I,O.SelectionHandler=Fe,O.UserSelectAction=xe,O.W3CTextFormat=qn,O.cancelSingleClickEvents=Ft,O.cloneKeyboardEvent=it,O.clonePointerEvent=yt,O.createBody=xn,O.createCanvasRenderer=se,O.createHighlightsRenderer=be,O.createPresencePainter=Ne,O.createRenderer=ye,O.createSpansRenderer=Ae,O.createTextAnnotator=Ao,O.createTextAnnotatorState=_e,O.debounce=bt,O.fillDefaults=ze,O.getQuoteContext=Gt,O.getRangeAnnotatableContents=wt,O.isMac=zt,O.isNotAnnotatable=tt,O.isRangeAnnotatable=jt,O.isRevived=j,O.isWhitespaceOrEmpty=Jt,O.mergeClientRects=Zt,O.paint=ie,O.parseW3CTextAnnotation=Me,O.programmaticallyFocusable=Wt,O.rangeToSelector=te,O.reviveAnnotation=At,O.reviveSelector=Lt,O.reviveTarget=st,O.scrollIntoView=oe,O.serializeW3CTextAnnotation=Be,O.splitAnnotatableRanges=qt,O.trimRangeToContainer=ee,O.whitespaceOrEmptyRegex=Qt,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
1
+ (function(O,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(O=typeof globalThis<"u"?globalThis:O||self,G(O.RecogitoJS={}))})(this,function(O){"use strict";const G="not-annotatable",Q=`.${G}`,tt=t=>{var n;return!!(t instanceof HTMLElement?t.closest(Q):(n=t.parentElement)==null?void 0:n.closest(Q))},jt=t=>{const e=t.commonAncestorContainer;return!tt(e)},Ft=t=>t.addEventListener("click",e=>{!e.target.closest(Q)&&!e.target.closest("a")&&e.preventDefault()}),yt=t=>({...t,type:t.type,x:t.x,y:t.y,clientX:t.clientX,clientY:t.clientY,offsetX:t.offsetX,offsetY:t.offsetY,screenX:t.screenX,screenY:t.screenY,isPrimary:t.isPrimary,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,button:t.button,buttons:t.buttons,currentTarget:t.currentTarget,target:t.target,defaultPrevented:t.defaultPrevented,detail:t.detail,eventPhase:t.eventPhase,pointerId:t.pointerId,pointerType:t.pointerType,timeStamp:t.timeStamp}),it=t=>({...t,type:t.type,key:t.key,code:t.code,location:t.location,repeat:t.repeat,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,currentTarget:t.currentTarget,target:t.target,defaultPrevented:t.defaultPrevented,detail:t.detail,timeStamp:t.timeStamp}),zt=/mac/i.test(navigator.userAgentData?navigator.userAgentData.platform:navigator.platform),Wt=t=>{!t.hasAttribute("tabindex")&&t.tabIndex<0&&t.setAttribute("tabindex","-1"),t.classList.add("no-focus-outline")},bt=(t,e=10)=>{let n;return(...o)=>{clearTimeout(n),n=setTimeout(()=>t.apply(void 0,o),e)}},qe=function*(t){const e=document.createNodeIterator(t.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(G)&&!o.parentElement.closest(Q)&&t.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=e.nextNode();)n instanceof HTMLElement&&(yield n)},qt=t=>{if(!jt(t))return[];const e=[];let n=null;for(const o of qe(t)){let i;n?(i=document.createRange(),i.setStartAfter(n),i.setEndBefore(o)):(i=t.cloneRange(),i.setEndBefore(o)),i.collapsed||e.push(i),n=o}if(n){const o=t.cloneRange();o.setStartAfter(n),o.collapsed||e.push(o)}return e.length>0?e:[t]},wt=t=>{const e=t.cloneContents();return e.querySelectorAll(Q).forEach(n=>n.remove()),e},Gt=(t,e,n=10,o)=>{const i=o?t.startContainer.parentElement.closest(o):e,s=document.createRange();s.setStart(i,0),s.setEnd(t.startContainer,t.startOffset);const a=wt(s).textContent,r=document.createRange();r.setStart(t.endContainer,t.endOffset),i===document.body?r.setEnd(i,i.childNodes.length):r.setEndAfter(i);const d=wt(r).textContent;return{prefix:a.substring(a.length-n),suffix:d.substring(0,n)}},j=t=>t.every(e=>e.range instanceof Range&&!e.range.collapsed),Qt=/^\s*$/,Jt=t=>Qt.test(t.toString()),Ge=(t,e)=>{const n=s=>Math.round(s*10)/10,o={top:n(t.top),bottom:n(t.bottom),left:n(t.left),right:n(t.right)},i={top:n(e.top),bottom:n(e.bottom),left:n(e.left),right:n(e.right)};if(Math.abs(o.top-i.top)<.5&&Math.abs(o.bottom-i.bottom)<.5){if(Math.abs(o.left-i.right)<.5||Math.abs(o.right-i.left)<.5)return"inline-adjacent";if(o.left>=i.left&&o.right<=i.right)return"inline-is-contained";if(o.left<=i.left&&o.right>=i.right)return"inline-contains"}else if(o.top<=i.top&&o.bottom>=i.bottom){if(o.left<=i.left&&o.right>=i.right)return"block-contains"}else if(o.top>=i.top&&o.bottom<=i.bottom&&o.left>=i.left&&o.right<=i.right)return"block-is-contained"},Qe=(t,e)=>{const n=Math.min(t.left,e.left),o=Math.max(t.right,e.right),i=Math.min(t.top,e.top),s=Math.max(t.bottom,e.bottom);return new DOMRect(n,i,o-n,s-i)},Zt=t=>t.reduce((e,n)=>{if(n.width===0||n.height===0)return e;let o=[...e],i=!1;for(const s of e){const a=Ge(n,s);if(a==="inline-adjacent"){o=o.map(r=>r===s?Qe(n,s):r),i=!0;break}else if(a==="inline-contains"){o=o.map(r=>r===s?n:r),i=!0;break}else if(a==="inline-is-contained"){i=!0;break}else if(a==="block-contains"||a==="block-is-contained"){n.width<s.width&&(o=o.map(r=>r===s?n:r)),i=!0;break}}return i?o:[...o,n]},[]),Je=t=>({length:t.length,item:e=>t[e],[Symbol.iterator]:function*(){for(let e=0;e<this.length;e++)yield this.item(e)}}),te=(t,e,n)=>{const o=document.createRange(),i=n?t.startContainer.parentElement.closest(n):e;o.setStart(i,0),o.setEnd(t.startContainer,t.startOffset);const s=wt(o).textContent,a=t.toString(),r=s.length||0,d=r+a.length;return n?{quote:a,start:r,end:d,range:t,offsetReference:i}:{quote:a,start:r,end:d,range:t}},Tt=(t,e)=>{var h,u;const{start:n,end:o}=t,i=t.offsetReference||e,s=document.createNodeIterator(e,NodeFilter.SHOW_TEXT,g=>{var E;return(E=g.parentElement)!=null&&E.closest(Q)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT});let a=0;const r=document.createRange();let d=s.nextNode();d===null&&console.error("Could not revive annotation target. Content missing.");let f=!i;for(;d!==null;){if(f||(f=i==null?void 0:i.contains(d)),f){const g=((h=d.textContent)==null?void 0:h.length)||0;if(a+g>n){r.setStart(d,n-a);break}a+=g}d=s.nextNode()}for(;d!==null;){const g=((u=d.textContent)==null?void 0:u.length)||0;if(a+g>=o){r.setEnd(d,o-a);break}a+=g,d=s.nextNode()}return{...t,range:r}},st=(t,e)=>j(t.selector)?t:{...t,selector:t.selector.map(n=>n.range instanceof Range&&!n.range.collapsed?n:Tt(n,e))},At=(t,e)=>j(t.target.selector)?t:{...t,target:st(t.target,e)},ee=(t,e)=>{const n=t.cloneRange();return e.contains(n.startContainer)||n.setStart(e,0),e.contains(n.endContainer)||n.setEnd(e,e.childNodes.length),n},ne=t=>{if(t===null)return document.scrollingElement;const{overflowY:e}=window.getComputedStyle(t);return e!=="visible"&&e!=="hidden"&&t.scrollHeight>t.clientHeight?t:ne(t.parentElement)},oe=(t,e)=>n=>{const o=typeof n=="string"?n:n.id,i=a=>{const r=s.getBoundingClientRect(),d=s.clientHeight,f=s.clientWidth,h=a.selector[0].range.getBoundingClientRect(),{width:u,height:g}=e.getAnnotationBounds(o),E=h.top-r.top,p=h.left-r.left,y=s.parentElement?s.scrollTop:0,v=s.parentElement?s.scrollLeft:0,l=E+y-(d-g)/2,c=p+v-(f-u)/2;s.scroll({top:l,left:c,behavior:"smooth"})},s=ne(t);if(s){const a=e.getAnnotation(o),{range:r}=a.target.selector[0];if(r&&!r.collapsed)return i(a.target),!0;{const d=st(a.target,t),{range:f}=d.selector[0];if(f&&!f.collapsed)return i(d),!0}}return!1},z={fill:"rgb(0, 128, 255)",fillOpacity:.18},rt={fill:"rgb(0, 128, 255)",fillOpacity:.45},ie=(t,e,n,o,i)=>{var a,r;const s=n?typeof n=="function"?n(t.annotation,t.state,i)||((a=t.state)!=null&&a.selected?rt:z):n:(r=t.state)!=null&&r.selected?rt:z;return o&&o.paint(t,e)||s},Ze=t=>{const{top:e,left:n}=t.getBoundingClientRect(),{innerWidth:o,innerHeight:i}=window,s=-n,a=-e,r=o-n,d=i-e;return{top:e,left:n,minX:s,minY:a,maxX:r,maxY:d}},tn=t=>{let e=new Set;return o=>{const i=o.map(s=>s.id);(e.size!==i.length||i.some(s=>!e.has(s)))&&t.set(i),e=new Set(i)}},Ot=(t,e,n,o)=>{const{store:i,selection:s,hover:a}=e;let r,d,f;const h=tn(n),u=B=>{const{x:T,y:m}=t.getBoundingClientRect(),A=i.getAt(B.clientX-T,B.clientY-m,!1,d);A?a.current!==A.id&&(t.classList.add("hovered"),a.set(A.id)):a.current&&(t.classList.remove("hovered"),a.set(null))};t.addEventListener("pointermove",u);const g=(B=!1)=>{f&&f.clear();const T=Ze(t),{minX:m,minY:A,maxX:w,maxY:L}=T,M=d?i.getIntersecting(m,A,w,L).filter(({annotation:V})=>d(V)):i.getIntersecting(m,A,w,L),k=s.selected.map(({id:V})=>V),U=M.map(({annotation:V,rects:mt})=>{const Z=k.includes(V.id),Eo=V.id===a.current;return{annotation:V,rects:mt,state:{selected:Z,hover:Eo}}});o.redraw(U,T,r,f,B),setTimeout(()=>h(M.map(({annotation:V})=>V)),1)},E=B=>{f=B,g()},p=B=>{r=B,g()},y=B=>{d=B,g(!1)},v=()=>g();i.observe(v);const l=s.subscribe(()=>g()),c=()=>g(!0);document.addEventListener("scroll",c,{capture:!0,passive:!0});const b=bt(()=>{i.recalculatePositions(),f&&f.reset(),g()});window.addEventListener("resize",b);const x=new ResizeObserver(b);x.observe(t);const S={attributes:!0,childList:!0,subtree:!0},C=new MutationObserver(B=>{B.every(m=>m.target===t||t.contains(m.target))||g(!0)});return C.observe(document.body,S),{destroy:()=>{t.removeEventListener("pointermove",u),o.destroy(),i.unobserve(v),l(),document.removeEventListener("scroll",c),window.removeEventListener("resize",b),x.disconnect(),C.disconnect()},redraw:g,setStyle:p,setFilter:y,setPainter:E,setVisible:o.setVisible}},en=()=>{const t=document.createElement("canvas");return t.width=window.innerWidth,t.height=window.innerHeight,t.className="r6o-canvas-highlight-layer bg",t},nn=(t,e)=>{t.width=window.innerWidth,t.height=window.innerHeight},on=t=>{t.classList.add("r6o-annotatable");const e=en(),n=e.getContext("2d");document.body.appendChild(e);const o=(r,d,f,h)=>requestAnimationFrame(()=>{const{width:u,height:g}=e;n.clearRect(-.5,-.5,u+1,g+1),h&&h.clear();const{top:E,left:p}=d;[...r].sort((v,l)=>{const{annotation:{target:{created:c}}}=v,{annotation:{target:{created:b}}}=l;return c.getTime()-b.getTime()}).forEach(v=>{var x;const l=f?typeof f=="function"?f(v.annotation,v.state):f:(x=v.state)!=null&&x.selected?rt:z,c=h&&h.paint(v,d)||l,b=v.rects.map(({x:S,y:C,width:R,height:B})=>({x:S+p,y:C+E,width:R,height:B}));if(n.fillStyle=c.fill,n.globalAlpha=c.fillOpacity||1,b.forEach(({x:S,y:C,width:R,height:B})=>n.fillRect(S,C,R,B)),c.underlineColor){n.globalAlpha=1,n.strokeStyle=c.underlineColor,n.lineWidth=c.underlineThickness??1;const S=c.underlineOffset??0;b.forEach(({x:C,y:R,width:B,height:T})=>{n.beginPath(),n.moveTo(C,R+T+S),n.lineTo(C+B,R+T+S),n.stroke()})}})}),i=bt(()=>{nn(e)});return window.addEventListener("resize",i),{destroy:()=>{e.remove(),window.removeEventListener("resize",i)},setVisible:r=>{console.log("setVisible not implemented on Canvas renderer")},redraw:o}},se=(t,e,n)=>Ot(t,e,n,on(t));var sn={grad:.9,turn:360,rad:360/(2*Math.PI)},W=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},D=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=Math.pow(10,e)),Math.round(n*t)/n+0},P=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=1),t>n?n:t>e?t:e},re=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},ae=function(t){return{r:P(t.r,0,255),g:P(t.g,0,255),b:P(t.b,0,255),a:P(t.a)}},Rt=function(t){return{r:D(t.r),g:D(t.g),b:D(t.b),a:D(t.a,3)}},rn=/^#([0-9a-f]{3,8})$/i,vt=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},ce=function(t){var e=t.r,n=t.g,o=t.b,i=t.a,s=Math.max(e,n,o),a=s-Math.min(e,n,o),r=a?s===e?(n-o)/a:s===n?2+(o-e)/a:4+(e-n)/a:0;return{h:60*(r<0?r+6:r),s:s?a/s*100:0,v:s/255*100,a:i}},le=function(t){var e=t.h,n=t.s,o=t.v,i=t.a;e=e/360*6,n/=100,o/=100;var s=Math.floor(e),a=o*(1-n),r=o*(1-(e-s)*n),d=o*(1-(1-e+s)*n),f=s%6;return{r:255*[o,r,a,a,d,o][f],g:255*[d,o,o,r,a,a][f],b:255*[a,a,d,o,o,r][f],a:i}},de=function(t){return{h:re(t.h),s:P(t.s,0,100),l:P(t.l,0,100),a:P(t.a)}},ue=function(t){return{h:D(t.h),s:D(t.s),l:D(t.l),a:D(t.a,3)}},fe=function(t){return le((n=(e=t).s,{h:e.h,s:(n*=((o=e.l)<50?o:100-o)/100)>0?2*n/(o+n)*100:0,v:o+n,a:e.a}));var e,n,o},at=function(t){return{h:(e=ce(t)).h,s:(i=(200-(n=e.s))*(o=e.v)/100)>0&&i<200?n*o/100/(i<=100?i:200-i)*100:0,l:i/2,a:e.a};var e,n,o,i},an=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,cn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ln=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,dn=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,he={string:[[function(t){var e=rn.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?D(parseInt(t[3]+t[3],16)/255,2):1}:t.length===6||t.length===8?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:t.length===8?D(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=ln.exec(t)||dn.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:ae({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=an.exec(t)||cn.exec(t);if(!e)return null;var n,o,i=de({h:(n=e[1],o=e[2],o===void 0&&(o="deg"),Number(n)*(sn[o]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return fe(i)},"hsl"]],object:[[function(t){var e=t.r,n=t.g,o=t.b,i=t.a,s=i===void 0?1:i;return W(e)&&W(n)&&W(o)?ae({r:Number(e),g:Number(n),b:Number(o),a:Number(s)}):null},"rgb"],[function(t){var e=t.h,n=t.s,o=t.l,i=t.a,s=i===void 0?1:i;if(!W(e)||!W(n)||!W(o))return null;var a=de({h:Number(e),s:Number(n),l:Number(o),a:Number(s)});return fe(a)},"hsl"],[function(t){var e=t.h,n=t.s,o=t.v,i=t.a,s=i===void 0?1:i;if(!W(e)||!W(n)||!W(o))return null;var a=function(r){return{h:re(r.h),s:P(r.s,0,100),v:P(r.v,0,100),a:P(r.a)}}({h:Number(e),s:Number(n),v:Number(o),a:Number(s)});return le(a)},"hsv"]]},ge=function(t,e){for(var n=0;n<e.length;n++){var o=e[n][0](t);if(o)return[o,e[n][1]]}return[null,void 0]},un=function(t){return typeof t=="string"?ge(t.trim(),he.string):typeof t=="object"&&t!==null?ge(t,he.object):[null,void 0]},Bt=function(t,e){var n=at(t);return{h:n.h,s:P(n.s+100*e,0,100),l:n.l,a:n.a}},Mt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},pe=function(t,e){var n=at(t);return{h:n.h,s:n.s,l:P(n.l+100*e,0,100),a:n.a}},me=function(){function t(e){this.parsed=un(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return this.parsed!==null},t.prototype.brightness=function(){return D(Mt(this.rgba),2)},t.prototype.isDark=function(){return Mt(this.rgba)<.5},t.prototype.isLight=function(){return Mt(this.rgba)>=.5},t.prototype.toHex=function(){return e=Rt(this.rgba),n=e.r,o=e.g,i=e.b,a=(s=e.a)<1?vt(D(255*s)):"","#"+vt(n)+vt(o)+vt(i)+a;var e,n,o,i,s,a},t.prototype.toRgb=function(){return Rt(this.rgba)},t.prototype.toRgbString=function(){return e=Rt(this.rgba),n=e.r,o=e.g,i=e.b,(s=e.a)<1?"rgba("+n+", "+o+", "+i+", "+s+")":"rgb("+n+", "+o+", "+i+")";var e,n,o,i,s},t.prototype.toHsl=function(){return ue(at(this.rgba))},t.prototype.toHslString=function(){return e=ue(at(this.rgba)),n=e.h,o=e.s,i=e.l,(s=e.a)<1?"hsla("+n+", "+o+"%, "+i+"%, "+s+")":"hsl("+n+", "+o+"%, "+i+"%)";var e,n,o,i,s},t.prototype.toHsv=function(){return e=ce(this.rgba),{h:D(e.h),s:D(e.s),v:D(e.v),a:D(e.a,3)};var e},t.prototype.invert=function(){return $({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},t.prototype.saturate=function(e){return e===void 0&&(e=.1),$(Bt(this.rgba,e))},t.prototype.desaturate=function(e){return e===void 0&&(e=.1),$(Bt(this.rgba,-e))},t.prototype.grayscale=function(){return $(Bt(this.rgba,-1))},t.prototype.lighten=function(e){return e===void 0&&(e=.1),$(pe(this.rgba,e))},t.prototype.darken=function(e){return e===void 0&&(e=.1),$(pe(this.rgba,-e))},t.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},t.prototype.alpha=function(e){return typeof e=="number"?$({r:(n=this.rgba).r,g:n.g,b:n.b,a:e}):D(this.rgba.a,3);var n},t.prototype.hue=function(e){var n=at(this.rgba);return typeof e=="number"?$({h:e,s:n.s,l:n.l,a:n.a}):D(n.h)},t.prototype.isEqual=function(e){return this.toHex()===$(e).toHex()},t}(),$=function(t){return t instanceof me?t:new me(t)};const fn=t=>[`background-color:${$((t==null?void 0:t.fill)||z.fill).alpha((t==null?void 0:t.fillOpacity)===void 0?z.fillOpacity:t.fillOpacity).toHex()}`,t!=null&&t.underlineThickness?"text-decoration:underline":void 0,t!=null&&t.underlineColor?`text-decoration-color:${t.underlineColor}`:void 0,t!=null&&t.underlineOffset?`text-underline-offset:${t.underlineOffset}px`:void 0,t!=null&&t.underlineThickness?`text-decoration-thickness:${t.underlineThickness}px`:void 0].filter(Boolean).join(";"),ye=()=>{const t=document.createElement("style");document.getElementsByTagName("head")[0].appendChild(t);let e=new Set;return{destroy:()=>{CSS.highlights.clear(),t.remove()},setVisible:s=>{console.log("setVisible not implemented on CSS Custom Highlights renderer")},redraw:(s,a,r,d)=>{d&&d.clear();const f=new Set(s.map(u=>u.annotation.id));Array.from(e).filter(u=>!f.has(u));const h=s.map(u=>{var p;const g=r?typeof r=="function"?r(u.annotation,u.state):r:(p=u.state)!=null&&p.selected?rt:z,E=d&&d.paint(u,a)||g;return`::highlight(_${u.annotation.id}) { ${fn(E)} }`});t.innerHTML=h.join(`
2
+ `),CSS.highlights.clear(),s.forEach(({annotation:u})=>{const g=u.target.selector.map(p=>p.range),E=new Highlight(...g);CSS.highlights.set(`_${u.id}`,E)}),e=f}}},be=(t,e,n)=>Ot(t,e,n,ye());var we=Object.prototype.hasOwnProperty;function kt(t,e){var n,o;if(t===e)return!0;if(t&&e&&(n=t.constructor)===e.constructor){if(n===Date)return t.getTime()===e.getTime();if(n===RegExp)return t.toString()===e.toString();if(n===Array){if((o=t.length)===e.length)for(;o--&&kt(t[o],e[o]););return o===-1}if(!n||typeof t=="object"){o=0;for(n in t)if(we.call(t,n)&&++o&&!we.call(e,n)||!(n in e)||!kt(t[n],e[n]))return!1;return Object.keys(e).length===o}}return t!==t&&e!==e}const hn=(t,e)=>{const n=(s,a)=>s.x<=a.x+a.width&&s.x+s.width>=a.x&&s.y<=a.y+a.height&&s.y+s.height>=a.y,o=s=>s.rects.reduce((a,r)=>a+r.width,0),i=e.filter(({rects:s})=>s.some(a=>n(t,a)));return i.sort((s,a)=>o(a)-o(s)),i.findIndex(s=>s.rects.includes(t))},gn=t=>{t.classList.add("r6o-annotatable");const e=document.createElement("div");e.className="r6o-span-highlight-layer",t.insertBefore(e,t.firstChild);let n=[];return{destroy:()=>{e.remove()},redraw:(a,r,d,f,h)=>{const g=!(kt(n,a)&&h);if(!f&&!g)return;g&&(e.innerHTML=""),[...a].sort((p,y)=>{const{annotation:{target:{created:v}}}=p,{annotation:{target:{created:l}}}=y;return v&&l?v.getTime()-l.getTime():0}).forEach(p=>{p.rects.map(y=>{const v=hn(y,a),l=ie(p,r,d,f,v);if(g){const c=document.createElement("span");c.className="r6o-annotation",c.dataset.annotation=p.annotation.id,c.style.left=`${y.x}px`,c.style.top=`${y.y}px`,c.style.width=`${y.width}px`,c.style.height=`${y.height}px`,c.style.backgroundColor=$((l==null?void 0:l.fill)||z.fill).alpha((l==null?void 0:l.fillOpacity)===void 0?z.fillOpacity:l.fillOpacity).toHex(),l.underlineStyle&&(c.style.borderStyle=l.underlineStyle),l.underlineColor&&(c.style.borderColor=l.underlineColor),l.underlineThickness&&(c.style.borderBottomWidth=`${l.underlineThickness}px`),l.underlineOffset&&(c.style.paddingBottom=`${l.underlineOffset}px`),e.appendChild(c)}})}),n=a},setVisible:a=>{a?e.classList.remove("hidden"):e.classList.add("hidden")}}},Ae=(t,e,n)=>Ot(t,e,n,gn(t)),Y=[];for(let t=0;t<256;++t)Y.push((t+256).toString(16).slice(1));function pn(t,e=0){return(Y[t[e+0]]+Y[t[e+1]]+Y[t[e+2]]+Y[t[e+3]]+"-"+Y[t[e+4]]+Y[t[e+5]]+"-"+Y[t[e+6]]+Y[t[e+7]]+"-"+Y[t[e+8]]+Y[t[e+9]]+"-"+Y[t[e+10]]+Y[t[e+11]]+Y[t[e+12]]+Y[t[e+13]]+Y[t[e+14]]+Y[t[e+15]]).toLowerCase()}let It;const mn=new Uint8Array(16);function yn(){if(!It){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");It=crypto.getRandomValues.bind(crypto)}return It(mn)}const ve={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ee(t,e,n){if(ve.randomUUID&&!e&&!t)return ve.randomUUID();t=t||{};const o=t.random||(t.rng||yn)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,pn(o)}var Se=Object.prototype.hasOwnProperty;function J(t,e){var n,o;if(t===e)return!0;if(t&&e&&(n=t.constructor)===e.constructor){if(n===Date)return t.getTime()===e.getTime();if(n===RegExp)return t.toString()===e.toString();if(n===Array){if((o=t.length)===e.length)for(;o--&&J(t[o],e[o]););return o===-1}if(!n||typeof t=="object"){o=0;for(n in t)if(Se.call(t,n)&&++o&&!Se.call(e,n)||!(n in e)||!J(t[n],e[n]))return!1;return Object.keys(e).length===o}}return t!==t&&e!==e}function _t(){}function bn(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}const et=[];function Nt(t,e=_t){let n;const o=new Set;function i(r){if(bn(t,r)&&(t=r,n)){const d=!et.length;for(const f of o)f[1](),et.push(f,t);if(d){for(let f=0;f<et.length;f+=2)et[f][0](et[f+1]);et.length=0}}}function s(r){i(r(t))}function a(r,d=_t){const f=[r,d];return o.add(f),o.size===1&&(n=e(i,s)||_t),r(t),()=>{o.delete(f),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:a}}const wn=t=>{const{subscribe:e,set:n}=Nt();let o;return e(i=>o=i),t.observe(({changes:i})=>{if(o){(i.deleted||[]).some(a=>a.id===o)&&n(void 0);const s=(i.updated||[]).find(({oldValue:a})=>a.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:e,set:n}};var xe=(t=>(t.EDIT="EDIT",t.SELECT="SELECT",t.NONE="NONE",t))(xe||{});const Et={selected:[]},An=(t,e,n)=>{const{subscribe:o,set:i}=Nt(Et);let s=e,a=Et;o(p=>a=p);const r=()=>{J(a,Et)||i(Et)},d=()=>{var p;return((p=a.selected)==null?void 0:p.length)===0},f=p=>{if(d())return!1;const y=typeof p=="string"?p:p.id;return a.selected.some(v=>v.id===y)},h=(p,y)=>{let v;if(Array.isArray(p)){if(v=p.map(c=>t.getAnnotation(c)).filter(Boolean),v.length<p.length){console.warn("Invalid selection: "+p.filter(c=>!v.some(b=>b.id===c)));return}}else{const c=t.getAnnotation(p);if(!c){console.warn("Invalid selection: "+p);return}v=[c]}const l=v.reduce((c,b)=>{const x=Ce(b,s);return x==="EDIT"?[...c,{id:b.id,editable:!0}]:x==="SELECT"?[...c,{id:b.id}]:c},[]);i({selected:l,event:y})},u=(p,y)=>{const v=Array.isArray(p)?p:[p],l=v.map(c=>t.getAnnotation(c)).filter(c=>!!c);i({selected:l.map(c=>{const b=y===void 0?Ce(c,s)==="EDIT":y;return{id:c.id,editable:b}})}),l.length!==v.length&&console.warn("Invalid selection",p)},g=p=>{if(d())return!1;const{selected:y}=a;y.some(({id:v})=>p.includes(v))&&i({selected:y.filter(({id:v})=>!p.includes(v))})},E=p=>s=p;return t.observe(({changes:p})=>g((p.deleted||[]).map(y=>y.id))),{get event(){return a?a.event:null},get selected(){return a?[...a.selected]:null},get userSelectAction(){return s},clear:r,isEmpty:d,isSelected:f,setSelected:u,setUserSelectAction:E,subscribe:o,userSelect:h}},Ce=(t,e,n)=>typeof e=="function"?e(t):e||"EDIT",K=[];for(let t=0;t<256;++t)K.push((t+256).toString(16).slice(1));function vn(t,e=0){return(K[t[e+0]]+K[t[e+1]]+K[t[e+2]]+K[t[e+3]]+"-"+K[t[e+4]]+K[t[e+5]]+"-"+K[t[e+6]]+K[t[e+7]]+"-"+K[t[e+8]]+K[t[e+9]]+"-"+K[t[e+10]]+K[t[e+11]]+K[t[e+12]]+K[t[e+13]]+K[t[e+14]]+K[t[e+15]]).toLowerCase()}let Ut;const En=new Uint8Array(16);function Sn(){if(!Ut){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ut=crypto.getRandomValues.bind(crypto)}return Ut(En)}const xn=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Le={randomUUID:xn};function Te(t,e,n){if(Le.randomUUID&&!e&&!t)return Le.randomUUID();t=t||{};const o=t.random||(t.rng||Sn)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,vn(o)}const Dt=t=>{const e=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{...t,bodies:(t.bodies||[]).map(e),target:e(t.target)}},Cn=(t,e,n,o)=>({id:Te(),annotation:typeof t=="string"?t:t.id,created:n||new Date,creator:o,...e}),Ln=(t,e)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Tn=(t,e)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},On=(t,e)=>e.bodies.map(n=>{const o=t.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!J(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Rn=(t,e)=>!J(t.target,e.target),Oe=(t,e)=>{const n=Ln(t,e),o=Tn(t,e),i=On(t,e);return{oldValue:t,newValue:e,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Rn(t,e)?{oldTarget:t.target,newTarget:e.target}:void 0}};var I=(t=>(t.LOCAL="LOCAL",t.REMOTE="REMOTE",t.SILENT="SILENT",t))(I||{});const Bn=(t,e)=>{var n,o;const{changes:i,origin:s}=e;if(!(t.options.origin?t.options.origin===s:s!=="SILENT"))return!1;if(t.options.ignore){const{ignore:a}=t.options,r=d=>d&&d.length>0;if(!(r(i.created)||r(i.deleted))){const d=(n=i.updated)==null?void 0:n.some(h=>r(h.bodiesCreated)||r(h.bodiesDeleted)||r(h.bodiesUpdated)),f=(o=i.updated)==null?void 0:o.some(h=>h.targetUpdated);if(a==="BODY_ONLY"&&d&&!f||a==="TARGET_ONLY"&&f&&!d)return!1}}if(t.options.annotations){const a=new Set([...(i.created||[]).map(r=>r.id),...(i.deleted||[]).map(r=>r.id),...(i.updated||[]).map(({oldValue:r})=>r.id)]);return!!(Array.isArray(t.options.annotations)?t.options.annotations:[t.options.annotations]).find(r=>a.has(r))}else return!0},Mn=(t,e)=>{const n=new Set((t.created||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({newValue:u})=>u.id)),i=new Set((e.created||[]).map(u=>u.id)),s=new Set((e.deleted||[]).map(u=>u.id)),a=new Set((e.updated||[]).map(({oldValue:u})=>u.id)),r=new Set((e.updated||[]).filter(({oldValue:u})=>n.has(u.id)||o.has(u.id)).map(({oldValue:u})=>u.id)),d=[...(t.created||[]).filter(u=>!s.has(u.id)).map(u=>a.has(u.id)?e.updated.find(({oldValue:g})=>g.id===u.id).newValue:u),...e.created||[]],f=[...(t.deleted||[]).filter(u=>!i.has(u.id)),...(e.deleted||[]).filter(u=>!n.has(u.id))],h=[...(t.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:g,newValue:E}=u;if(a.has(E.id)){const p=e.updated.find(y=>y.oldValue.id===E.id).newValue;return Oe(g,p)}else return u}),...(e.updated||[]).filter(({oldValue:u})=>!r.has(u.id))];return{created:d,deleted:f,updated:h}},Vt=t=>{const e=t.id===void 0?Te():t.id;return{...t,id:e,bodies:t.bodies===void 0?[]:t.bodies.map(n=>({...n,annotation:e})),target:{...t.target,annotation:e}}},kn=t=>t.id!==void 0,In=()=>{const t=new Map,e=new Map,n=[],o=(m,A={})=>{n.push({onChange:m,options:A})},i=m=>{const A=n.findIndex(w=>w.onChange==m);A>-1&&n.splice(A,1)},s=(m,A)=>{const w={origin:m,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...t.values()]};n.forEach(L=>{Bn(L,w)&&L.onChange(w)})},a=(m,A=I.LOCAL)=>{if(m.id&&t.get(m.id))throw Error(`Cannot add annotation ${m.id} - exists already`);{const w=Vt(m);t.set(w.id,w),w.bodies.forEach(L=>e.set(L.id,w.id)),s(A,{created:[w]})}},r=(m,A)=>{const w=Vt(typeof m=="string"?A:m),L=typeof m=="string"?m:m.id,M=L&&t.get(L);if(M){const k=Oe(M,w);return L===w.id?t.set(L,w):(t.delete(L),t.set(w.id,w)),M.bodies.forEach(U=>e.delete(U.id)),w.bodies.forEach(U=>e.set(U.id,w.id)),k}else console.warn(`Cannot update annotation ${L} - does not exist`)},d=(m,A=I.LOCAL,w=I.LOCAL)=>{const L=kn(A)?w:A,M=r(m,A);M&&s(L,{updated:[M]})},f=(m,A=I.LOCAL)=>{const w=m.reduce((L,M)=>{const k=r(M);return k?[...L,k]:L},[]);w.length>0&&s(A,{updated:w})},h=(m,A=I.LOCAL)=>{const w=t.get(m.annotation);if(w){const L={...w,bodies:[...w.bodies,m]};t.set(w.id,L),e.set(m.id,L.id),s(A,{updated:[{oldValue:w,newValue:L,bodiesCreated:[m]}]})}else console.warn(`Attempt to add body to missing annotation: ${m.annotation}`)},u=()=>[...t.values()],g=(m=I.LOCAL)=>{const A=[...t.values()];t.clear(),e.clear(),s(m,{deleted:A})},E=(m,A=!0,w=I.LOCAL)=>{const L=m.map(Vt);if(A){const M=[...t.values()];t.clear(),e.clear(),L.forEach(k=>{t.set(k.id,k),k.bodies.forEach(U=>e.set(U.id,k.id))}),s(w,{created:L,deleted:M})}else{const M=m.reduce((k,U)=>{const V=U.id&&t.get(U.id);return V?[...k,V]:k},[]);if(M.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${M.map(k=>k.id).join(", ")}`);L.forEach(k=>{t.set(k.id,k),k.bodies.forEach(U=>e.set(U.id,k.id))}),s(w,{created:L})}},p=m=>{const A=typeof m=="string"?m:m.id,w=t.get(A);if(w)return t.delete(A),w.bodies.forEach(L=>e.delete(L.id)),w;console.warn(`Attempt to delete missing annotation: ${A}`)},y=(m,A=I.LOCAL)=>{const w=p(m);w&&s(A,{deleted:[w]})},v=(m,A=I.LOCAL)=>{const w=m.reduce((L,M)=>{const k=p(M);return k?[...L,k]:L},[]);w.length>0&&s(A,{deleted:w})},l=m=>{const A=t.get(m.annotation);if(A){const w=A.bodies.find(L=>L.id===m.id);if(w){e.delete(w.id);const L={...A,bodies:A.bodies.filter(M=>M.id!==m.id)};return t.set(A.id,L),{oldValue:A,newValue:L,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${m.annotation}`)},c=(m,A=I.LOCAL)=>{const w=l(m);w&&s(A,{updated:[w]})},b=(m,A=I.LOCAL)=>{const w=m.map(L=>l(L)).filter(Boolean);w.length>0&&s(A,{updated:w})},x=m=>{const A=t.get(m);return A?{...A}:void 0},S=m=>{const A=e.get(m);if(A){const w=x(A).bodies.find(L=>L.id===m);if(w)return w;console.error(`Store integrity error: body ${m} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${m}`)},C=(m,A)=>{if(m.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=t.get(m.annotation);if(w){const L=w.bodies.find(k=>k.id===m.id),M={...w,bodies:w.bodies.map(k=>k.id===L.id?A:k)};return t.set(w.id,M),L.id!==A.id&&(e.delete(L.id),e.set(A.id,M.id)),{oldValue:w,newValue:M,bodiesUpdated:[{oldBody:L,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${m.annotation}`)},R=(m,A,w=I.LOCAL)=>{const L=C(m,A);L&&s(w,{updated:[L]})},B=(m,A=I.LOCAL)=>{const w=m.map(L=>C({id:L.id,annotation:L.annotation},L)).filter(Boolean);s(A,{updated:w})},T=m=>{const A=t.get(m.annotation);if(A){const w={...A,target:{...A.target,...m}};return t.set(A.id,w),{oldValue:A,newValue:w,targetUpdated:{oldTarget:A.target,newTarget:m}}}else console.warn(`Attempt to update target on missing annotation: ${m.annotation}`)};return{addAnnotation:a,addBody:h,all:u,bulkAddAnnotation:E,bulkDeleteAnnotation:v,bulkDeleteBodies:b,bulkUpdateAnnotation:f,bulkUpdateBodies:B,bulkUpdateTargets:(m,A=I.LOCAL)=>{const w=m.map(L=>T(L)).filter(Boolean);w.length>0&&s(A,{updated:w})},clear:g,deleteAnnotation:y,deleteBody:c,getAnnotation:x,getBody:S,observe:o,unobserve:i,updateAnnotation:d,updateBody:R,updateTarget:(m,A=I.LOCAL)=>{const w=T(m);w&&s(A,{updated:[w]})}}};let _n=()=>({emit(t,...e){for(let n=this.events[t]||[],o=0,i=n.length;o<i;o++)n[o](...e)},events:{},on(t,e){var n;return((n=this.events)[t]||(n[t]=[])).push(e),()=>{var o;this.events[t]=(o=this.events[t])==null?void 0:o.filter(i=>e!==i)}}});const Nn=250,Un=(t,e)=>{const n=_n(),o=[];let i=-1,s=!1,a=0;const r=p=>{if(!s){const{changes:y}=p,v=performance.now();if(v-a>Nn)o.splice(i+1),o.push(y),i=o.length-1;else{const l=o.length-1;o[l]=Mn(o[l],y)}a=v}s=!1};t.observe(r,{origin:I.LOCAL});const d=p=>p&&p.length>0&&t.bulkDeleteAnnotation(p),f=p=>p&&p.length>0&&t.bulkAddAnnotation(p,!1),h=p=>p&&p.length>0&&t.bulkUpdateAnnotation(p.map(({oldValue:y})=>y)),u=p=>p&&p.length>0&&t.bulkUpdateAnnotation(p.map(({newValue:y})=>y)),g=p=>p&&p.length>0&&t.bulkAddAnnotation(p,!1),E=p=>p&&p.length>0&&t.bulkDeleteAnnotation(p);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>t.unobserve(r),getHistory:()=>({changes:[...o],pointer:i}),on:(p,y)=>n.on(p,y),redo:()=>{if(o.length-1>i){s=!0;const{created:p,updated:y,deleted:v}=o[i+1];f(p),u(y),E(v),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:p,updated:y,deleted:v}=o[i];d(p),h(y),g(v),n.emit("undo",o[i]),i-=1}}}},Dn=()=>{const{subscribe:t,set:e}=Nt([]);return{subscribe:t,set:e}},Vn=(t,e,n,o)=>{const{hover:i,selection:s,store:a,viewport:r}=t,d=new Map;let f=[],h;const u=(y,v)=>{d.has(y)?d.get(y).push(v):d.set(y,[v])},g=(y,v)=>{const l=d.get(y);if(l){const c=l.indexOf(v);c!==-1&&l.splice(c,1)}},E=(y,v,l)=>{d.has(y)&&setTimeout(()=>{d.get(y).forEach(c=>{if(n){const b=Array.isArray(v)?v.map(S=>n.serialize(S)):n.serialize(v),x=l?l instanceof PointerEvent?l:n.serialize(l):void 0;c(b,x)}else c(v,l)})},1)};s.subscribe(({selected:y})=>{if(!(f.length===0&&y.length===0)){if(f.length===0&&y.length>0)f=y.map(({id:v})=>a.getAnnotation(v));else if(f.length>0&&y.length===0)f.forEach(v=>{const l=a.getAnnotation(v.id);l&&!J(l,v)&&E("updateAnnotation",l,v)}),f=[];else{const v=new Set(f.map(c=>c.id)),l=new Set(y.map(({id:c})=>c));f.filter(c=>!l.has(c.id)).forEach(c=>{const b=a.getAnnotation(c.id);b&&!J(b,c)&&E("updateAnnotation",b,c)}),f=[...f.filter(c=>l.has(c.id)),...y.filter(({id:c})=>!v.has(c)).map(({id:c})=>a.getAnnotation(c))]}E("selectionChanged",f)}}),i.subscribe(y=>{!h&&y?E("mouseEnterAnnotation",a.getAnnotation(y)):h&&!y?E("mouseLeaveAnnotation",a.getAnnotation(h)):h&&y&&(E("mouseLeaveAnnotation",a.getAnnotation(h)),E("mouseEnterAnnotation",a.getAnnotation(y))),h=y}),r==null||r.subscribe(y=>E("viewportIntersect",y.map(v=>a.getAnnotation(v)))),a.observe(y=>{const{created:v,deleted:l}=y.changes;(v||[]).forEach(c=>E("createAnnotation",c)),(l||[]).forEach(c=>E("deleteAnnotation",c)),(y.changes.updated||[]).filter(c=>[...c.bodiesCreated||[],...c.bodiesDeleted||[],...c.bodiesUpdated||[]].length>0).forEach(({oldValue:c,newValue:b})=>{const x=f.find(S=>S.id===c.id)||c;f=f.map(S=>S.id===c.id?b:S),E("updateAnnotation",b,x)})},{origin:I.LOCAL}),a.observe(y=>{if(f){const v=new Set(f.map(c=>c.id)),l=(y.changes.updated||[]).filter(({newValue:c})=>v.has(c.id)).map(({newValue:c})=>c);l.length>0&&(f=f.map(c=>l.find(x=>x.id===c.id)||c))}},{origin:I.REMOTE});const p=y=>v=>{const{updated:l}=v;y?(l||[]).forEach(c=>E("updateAnnotation",c.oldValue,c.newValue)):(l||[]).forEach(c=>E("updateAnnotation",c.newValue,c.oldValue))};return e.on("undo",p(!0)),e.on("redo",p(!1)),{on:u,off:g,emit:E}},Yn=t=>e=>e.reduce((n,o)=>{const{parsed:i,error:s}=t.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Kn=(t,e,n)=>{const{store:o,selection:i}=t,s=l=>{if(n){const{parsed:c,error:b}=n.parse(l);c?o.addAnnotation(c,I.REMOTE):console.error(b)}else o.addAnnotation(Dt(l),I.REMOTE)},a=()=>i.clear(),r=()=>o.clear(),d=l=>{const c=o.getAnnotation(l);return n&&c?n.serialize(c):c},f=()=>n?o.all().map(n.serialize):o.all(),h=()=>{var l;const c=(((l=i.selected)==null?void 0:l.map(b=>b.id))||[]).map(b=>o.getAnnotation(b)).filter(Boolean);return n?c.map(n.serialize):c},u=(l,c=!0)=>fetch(l).then(b=>b.json()).then(b=>(E(b,c),b)),g=l=>{if(typeof l=="string"){const c=o.getAnnotation(l);if(o.deleteAnnotation(l),c)return n?n.serialize(c):c}else{const c=n?n.parse(l).parsed:l;if(c)return o.deleteAnnotation(c),l}},E=(l,c=!0)=>{if(n){const b=n.parseAll||Yn(n),{parsed:x,failed:S}=b(l);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),o.bulkAddAnnotation(x,c,I.REMOTE)}else o.bulkAddAnnotation(l.map(Dt),c,I.REMOTE)},p=(l,c)=>{l?i.setSelected(l,c):i.clear()},y=l=>{i.clear(),i.setUserSelectAction(l)},v=l=>{if(n){const c=n.parse(l).parsed,b=n.serialize(o.getAnnotation(c.id));return o.updateAnnotation(c),b}else{const c=o.getAnnotation(l.id);return o.updateAnnotation(Dt(l)),c}};return{addAnnotation:s,cancelSelected:a,canRedo:e.canRedo,canUndo:e.canUndo,clearAnnotations:r,getAnnotationById:d,getAnnotations:f,getHistory:e.getHistory,getSelected:h,loadAnnotations:u,redo:e.redo,removeAnnotation:g,setAnnotations:E,setSelected:p,setUserSelectAction:y,undo:e.undo,updateAnnotation:v}},Xn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Pn=t=>crypto.getRandomValues(new Uint8Array(t)),Hn=(t,e,n)=>{let o=(2<<Math.log2(t.length-1))-1,i=-~(1.6*o*e/t.length);return(s=e)=>{let a="";for(;;){let r=n(i),d=i|0;for(;d--;)if(a+=t[r[d]&o]||"",a.length>=s)return a}}},$n=(t,e=21)=>Hn(t,e|0,Pn),jn=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=Xn[n[t]&63];return e};const Fn=()=>({isGuest:!0,id:$n("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),zn=t=>{const e=JSON.stringify(t);let n=0;for(let o=0,i=e.length;o<i;o++){let s=e.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Re=t=>t?typeof t=="object"?{...t}:t:void 0,Wn=(t,e)=>(Array.isArray(t)?t:[t]).map(n=>{const{id:o,type:i,purpose:s,value:a,created:r,modified:d,creator:f,...h}=n;return{id:o||`temp-${zn(n)}`,annotation:e,type:i,purpose:s,value:a,creator:Re(f),created:r?new Date(r):void 0,updated:d?new Date(d):void 0,...h}}),qn=t=>t.map(e=>{var n;const{annotation:o,created:i,updated:s,...a}=e,r={...a,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=r.id)!=null&&n.startsWith("temp-")&&delete r.id,r});jn();const Gn=(t,e)=>({parse:n=>Be(n),serialize:n=>Me(n,t,e)}),Qn=t=>t.quote!==void 0&&t.start!==void 0&&t.end!==void 0,Jn=t=>{const{id:e,creator:n,created:o,modified:i,target:s}=t,a=Array.isArray(s)?s:[s];if(a.length===0)return{error:Error(`No targets found for annotation: ${t.id}`)};const r={creator:Re(n),created:o?new Date(o):void 0,updated:i?new Date(i):void 0,annotation:e,selector:[],styleClass:"styleClass"in a[0]?a[0].styleClass:void 0};for(const d of a){const h=(Array.isArray(d.selector)?d.selector:[d.selector]).reduce((u,g)=>{switch(g.type){case"TextQuoteSelector":u.quote=g.exact;break;case"TextPositionSelector":u.start=g.start,u.end=g.end;break}return u},{});if(Qn(h))r.selector.push({...h,id:d.id,scope:d.scope});else{const u=[h.start?void 0:"TextPositionSelector",h.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`)}}}return{parsed:r}},Be=t=>{const e=t.id||Ee(),{creator:n,created:o,modified:i,body:s,...a}=t,r=Wn(s,e),d=Jn(t);return"error"in d?{error:d.error}:{parsed:{...a,id:e,bodies:r,target:d.parsed}}},Me=(t,e,n)=>{const{bodies:o,target:i,...s}=t,{selector:a,creator:r,created:d,updated:f,...h}=i,u=a.map(g=>{const{id:E,quote:p,start:y,end:v,range:l}=g,{prefix:c,suffix:b}=Gt(l,n),x=[{type:"TextQuoteSelector",exact:p,prefix:c,suffix:b},{type:"TextPositionSelector",start:y,end:v}];return{...h,id:E,scope:"scope"in g?g.scope:void 0,source:e,selector:x}});return{...s,"@context":"http://www.w3.org/ns/anno.jsonld",id:t.id,type:"Annotation",body:qn(t.bodies),creator:r,created:d==null?void 0:d.toISOString(),modified:f==null?void 0:f.toISOString(),target:u}};function ke(t,e,n=0,o=t.length-1,i=Zn){for(;o>n;){if(o-n>600){const d=o-n+1,f=e-n+1,h=Math.log(d),u=.5*Math.exp(2*h/3),g=.5*Math.sqrt(h*u*(d-u)/d)*(f-d/2<0?-1:1),E=Math.max(n,Math.floor(e-f*u/d+g)),p=Math.min(o,Math.floor(e+(d-f)*u/d+g));ke(t,e,E,p,i)}const s=t[e];let a=n,r=o;for(ct(t,n,e),i(t[o],s)>0&&ct(t,n,o);a<r;){for(ct(t,a,r),a++,r--;i(t[a],s)<0;)a++;for(;i(t[r],s)>0;)r--}i(t[n],s)===0?ct(t,n,r):(r++,ct(t,r,o)),r<=e&&(n=r+1),e<=r&&(o=r-1)}}function ct(t,e,n){const o=t[e];t[e]=t[n],t[n]=o}function Zn(t,e){return t<e?-1:t>e?1:0}class to{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let n=this.data;const o=[];if(!xt(e,n))return o;const i=this.toBBox,s=[];for(;n;){for(let a=0;a<n.children.length;a++){const r=n.children[a],d=n.leaf?i(r):r;xt(e,d)&&(n.leaf?o.push(r):Kt(e,d)?this._all(r,o):s.push(r))}n=s.pop()}return o}collides(e){let n=this.data;if(!xt(e,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],a=n.leaf?this.toBBox(s):s;if(xt(e,a)){if(n.leaf||Kt(e,a))return!0;o.push(s)}}n=o.pop()}return!1}load(e){if(!(e&&e.length))return this;if(e.length<this._minEntries){for(let o=0;o<e.length;o++)this.insert(e[o]);return this}let n=this._build(e.slice(),0,e.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(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=ot([]),this}remove(e,n){if(!e)return this;let o=this.data;const i=this.toBBox(e),s=[],a=[];let r,d,f;for(;o||s.length;){if(o||(o=s.pop(),d=s[s.length-1],r=a.pop(),f=!0),o.leaf){const h=eo(e,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!f&&!o.leaf&&Kt(o,i)?(s.push(o),a.push(r),r=0,d=o,o=o.children[0]):d?(r++,o=d.children[r],f=!1):o=null}return this}toBBox(e){return e}compareMinX(e,n){return e.minX-n.minX}compareMinY(e,n){return e.minY-n.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,n){const o=[];for(;e;)e.leaf?n.push(...e.children):o.push(...e.children),e=o.pop();return n}_build(e,n,o,i){const s=o-n+1;let a=this._maxEntries,r;if(s<=a)return r=ot(e.slice(n,o+1)),nt(r,this.toBBox),r;i||(i=Math.ceil(Math.log(s)/Math.log(a)),a=Math.ceil(s/Math.pow(a,i-1))),r=ot([]),r.leaf=!1,r.height=i;const d=Math.ceil(s/a),f=d*Math.ceil(Math.sqrt(a));Ie(e,n,o,f,this.compareMinX);for(let h=n;h<=o;h+=f){const u=Math.min(h+f-1,o);Ie(e,h,u,d,this.compareMinY);for(let g=h;g<=u;g+=d){const E=Math.min(g+d-1,u);r.children.push(this._build(e,g,E,i-1))}}return nt(r,this.toBBox),r}_chooseSubtree(e,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,a=1/0,r;for(let d=0;d<n.children.length;d++){const f=n.children[d],h=Yt(f),u=io(e,f)-h;u<a?(a=u,s=h<s?h:s,r=f):u===a&&h<s&&(s=h,r=f)}n=r||n.children[0]}return n}_insert(e,n,o){const i=o?e:this.toBBox(e),s=[],a=this._chooseSubtree(i,this.data,n,s);for(a.children.push(e),dt(a,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(e,n){const o=e[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const a=this._chooseSplitIndex(o,s,i),r=ot(o.children.splice(a,o.children.length-a));r.height=o.height,r.leaf=o.leaf,nt(o,this.toBBox),nt(r,this.toBBox),n?e[n-1].children.push(r):this._splitRoot(o,r)}_splitRoot(e,n){this.data=ot([e,n]),this.data.height=e.height+1,this.data.leaf=!1,nt(this.data,this.toBBox)}_chooseSplitIndex(e,n,o){let i,s=1/0,a=1/0;for(let r=n;r<=o-n;r++){const d=lt(e,0,r,this.toBBox),f=lt(e,r,o,this.toBBox),h=so(d,f),u=Yt(d)+Yt(f);h<s?(s=h,i=r,a=u<a?u:a):h===s&&u<a&&(a=u,i=r)}return i||o-n}_chooseSplitAxis(e,n,o){const i=e.leaf?this.compareMinX:no,s=e.leaf?this.compareMinY:oo,a=this._allDistMargin(e,n,o,i),r=this._allDistMargin(e,n,o,s);a<r&&e.children.sort(i)}_allDistMargin(e,n,o,i){e.children.sort(i);const s=this.toBBox,a=lt(e,0,n,s),r=lt(e,o-n,o,s);let d=St(a)+St(r);for(let f=n;f<o-n;f++){const h=e.children[f];dt(a,e.leaf?s(h):h),d+=St(a)}for(let f=o-n-1;f>=n;f--){const h=e.children[f];dt(r,e.leaf?s(h):h),d+=St(r)}return d}_adjustParentBBoxes(e,n,o){for(let i=o;i>=0;i--)dt(n[i],e)}_condense(e){for(let n=e.length-1,o;n>=0;n--)e[n].children.length===0?n>0?(o=e[n-1].children,o.splice(o.indexOf(e[n]),1)):this.clear():nt(e[n],this.toBBox)}}function eo(t,e,n){if(!n)return e.indexOf(t);for(let o=0;o<e.length;o++)if(n(t,e[o]))return o;return-1}function nt(t,e){lt(t,0,t.children.length,e,t)}function lt(t,e,n,o,i){i||(i=ot(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=e;s<n;s++){const a=t.children[s];dt(i,t.leaf?o(a):a)}return i}function dt(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function no(t,e){return t.minX-e.minX}function oo(t,e){return t.minY-e.minY}function Yt(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function St(t){return t.maxX-t.minX+(t.maxY-t.minY)}function io(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function so(t,e){const n=Math.max(t.minX,e.minX),o=Math.max(t.minY,e.minY),i=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function Kt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function xt(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function ot(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Ie(t,e,n,o,i){const s=[e,n];for(;s.length;){if(n=s.pop(),e=s.pop(),n-e<=o)continue;const a=e+Math.ceil((n-e)/o/2)*o;ke(t,a,e,n,i),s.push(e,a,a,n)}}const ro=(t,e)=>{const n=new to,o=new Map,i=(l,c)=>{const b=l.selector.flatMap(S=>{const C=j([S])?S.range:Tt(S,e).range;return Array.from(C.getClientRects())}),x=Zt(b).map(({left:S,top:C,right:R,bottom:B})=>new DOMRect(S-c.left,C-c.top,R-S,B-C));return x.map(S=>{const{x:C,y:R,width:B,height:T}=S;return{minX:C,minY:R,maxX:C+B,maxY:R+T,annotation:{id:l.annotation,rects:x}}})},s=()=>[...o.values()],a=()=>{n.clear(),o.clear()},r=l=>{const c=i(l,e.getBoundingClientRect());c.length!==0&&(c.forEach(b=>n.insert(b)),o.set(l.annotation,c))},d=l=>{const c=o.get(l.annotation);c&&(c.forEach(b=>n.remove(b)),o.delete(l.annotation))},f=l=>{d(l),r(l)},h=(l,c=!0)=>{c&&a();const b=e.getBoundingClientRect(),x=l.map(C=>({target:C,rects:i(C,b)}));x.forEach(({target:C,rects:R})=>{R.length>0&&o.set(C.annotation,R)});const S=x.flatMap(({rects:C})=>C);n.load(S)},u=(l,c,b=!1)=>{const x=n.search({minX:l,minY:c,maxX:l,maxY:c}),S=C=>C.annotation.rects.reduce((R,B)=>R+B.width*B.height,0);return x.length>0?(x.sort((C,R)=>S(C)-S(R)),b?x.map(C=>C.annotation.id):[x[0].annotation.id]):[]},g=l=>{const c=E(l);if(c.length===0)return;let b=c[0].left,x=c[0].top,S=c[0].right,C=c[0].bottom;for(let R=1;R<c.length;R++){const B=c[R];b=Math.min(b,B.left),x=Math.min(x,B.top),S=Math.max(S,B.right),C=Math.max(C,B.bottom)}return new DOMRect(b,x,S-b,C-x)},E=l=>{const c=o.get(l);return c?c[0].annotation.rects:[]};return{all:s,clear:a,getAt:u,getAnnotationBounds:g,getAnnotationRects:E,getIntersecting:(l,c,b,x)=>{const S=n.search({minX:l,minY:c,maxX:b,maxY:x}),C=new Set(S.map(R=>R.annotation.id));return Array.from(C).map(R=>({annotation:t.getAnnotation(R),rects:E(R)})).filter(R=>!!R.annotation)},insert:r,recalculate:()=>h(t.all().map(l=>l.target),!0),remove:d,set:h,size:()=>n.all().length,update:f}},_e=(t,e)=>{const n=In(),o=ro(n,t),i=An(n);i.setUserSelectAction(e);const s=wn(n),a=Dn(),r=(l,c=I.LOCAL)=>{const b=At(l,t),x=j(b.target.selector);return x&&n.addAnnotation(b,c),x},d=(l,c=!0,b=I.LOCAL)=>{const x=l.map(C=>At(C,t)),S=x.filter(C=>!j(C.target.selector));return n.bulkAddAnnotation(x,c,b),S},f=(l,c=I.LOCAL)=>{const b=l.map(S=>At(S,t)),x=b.filter(S=>!j(S.target.selector));return b.forEach(S=>{n.getAnnotation(S.id)?n.updateAnnotation(S,c):n.addAnnotation(S,c)}),x},h=(l,c=I.LOCAL)=>{const b=st(l,t);n.updateTarget(b,c)},u=(l,c=I.LOCAL)=>{const b=l.map(x=>st(x,t));n.bulkUpdateTargets(b,c)};function g(l,c,b,x){const S=b||!!x,C=o.getAt(l,c,S).map(B=>n.getAnnotation(B)),R=x?C.filter(x):C;if(R.length!==0)return b?R:R[0]}const E=l=>{if(o.getAnnotationRects(l).length!==0)return o.getAnnotationBounds(l)},p=(l,c,b,x)=>o.getIntersecting(l,c,b,x),y=l=>o.getAnnotationRects(l),v=()=>o.recalculate();return n.observe(({changes:l})=>{const c=(l.deleted||[]).filter(S=>j(S.target.selector)),b=(l.created||[]).filter(S=>j(S.target.selector)),x=(l.updated||[]).filter(S=>j(S.newValue.target.selector));(c==null?void 0:c.length)>0&&c.forEach(S=>o.remove(S.target)),b.length>0&&o.set(b.map(S=>S.target),!1),(x==null?void 0:x.length)>0&&x.forEach(({newValue:S})=>o.update(S.target))}),{store:{...n,addAnnotation:r,bulkAddAnnotation:d,bulkUpdateTargets:u,bulkUpsertAnnotations:f,getAnnotationBounds:E,getAnnotationRects:y,getIntersecting:p,getAt:g,recalculatePositions:v,updateTarget:h},selection:i,hover:s,viewport:a}},ao=()=>{const t=document.createElement("canvas");t.width=2*window.innerWidth,t.height=2*window.innerHeight,t.className="r6o-presence-layer";const e=t.getContext("2d");return e.scale(2,2),e.translate(.5,.5),t},Ne=(t,e={})=>{const n=ao(),o=n.getContext("2d");document.body.appendChild(n);const i=new Map,s=h=>Array.from(i.entries()).filter(([u,g])=>g.presenceKey===h.presenceKey).map(([u,g])=>u);return t.on("selectionChange",(h,u)=>{s(h).forEach(E=>i.delete(E)),u&&u.forEach(E=>i.set(E,h))}),{clear:()=>{const{width:h,height:u}=n;o.clearRect(-.5,-.5,h+1,u+1)},destroy:()=>{n.remove()},paint:(h,u,g)=>{e.font&&(o.font=e.font);const E=i.get(h.annotation.id);if(E){const{height:p}=h.rects[0],y=h.rects[0].x+u.left,v=h.rects[0].y+u.top;o.fillStyle=E.appearance.color,o.fillRect(y-2,v-2.5,2,p+5);const l=o.measureText(E.appearance.label),c=l.width+6,b=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent+8,x=l.fontBoundingBoxAscent?8:6.5;return o.fillRect(y-2,v-2.5-b,c,b),o.fillStyle="#fff",o.fillText(E.appearance.label,y+1,v-x),{fill:E.appearance.color,fillOpacity:g?.45:.18}}},reset:()=>{n.width=2*window.innerWidth,n.height=2*window.innerHeight;const h=n.getContext("2d");h.scale(2,2),h.translate(.5,.5)}}},Xt=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function Pt(t,e,n,o){t.addEventListener?t.addEventListener(e,n,o):t.attachEvent&&t.attachEvent("on".concat(e),n)}function ut(t,e,n,o){t.removeEventListener?t.removeEventListener(e,n,o):t.detachEvent&&t.detachEvent("on".concat(e),n)}function Ue(t,e){const n=e.slice(0,e.length-1);for(let o=0;o<n.length;o++)n[o]=t[n[o].toLowerCase()];return n}function De(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function co(t,e){const n=t.length>=e.length?t:e,o=t.length>=e.length?e:t;let i=!0;for(let s=0;s<n.length;s++)o.indexOf(n[s])===-1&&(i=!1);return i}const ft={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,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,"-":Xt?173:189,"=":Xt?61:187,";":Xt?59:186,"'":222,"[":219,"]":221,"\\":220},F={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Ct={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},N={};for(let t=1;t<20;t++)ft["f".concat(t)]=111+t;let _=[],ht=null,Ve="all";const q=new Map,gt=t=>ft[t.toLowerCase()]||F[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),lo=t=>Object.keys(ft).find(e=>ft[e]===t),uo=t=>Object.keys(F).find(e=>F[e]===t);function Ye(t){Ve=t||"all"}function pt(){return Ve||"all"}function fo(){return _.slice(0)}function ho(){return _.map(t=>lo(t)||uo(t)||String.fromCharCode(t))}function go(){const t=[];return Object.keys(N).forEach(e=>{N[e].forEach(n=>{let{key:o,scope:i,mods:s,shortcut:a}=n;t.push({scope:i,shortcut:a,mods:s,keys:o.split("+").map(r=>gt(r))})})}),t}function po(t){const e=t.target||t.srcElement,{tagName:n}=e;let o=!0;const i=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(e.type);return(e.isContentEditable||(i||n==="TEXTAREA"||n==="SELECT")&&!e.readOnly)&&(o=!1),o}function mo(t){return typeof t=="string"&&(t=gt(t)),_.indexOf(t)!==-1}function yo(t,e){let n,o;t||(t=pt());for(const i in N)if(Object.prototype.hasOwnProperty.call(N,i))for(n=N[i],o=0;o<n.length;)n[o].scope===t?n.splice(o,1).forEach(a=>{let{element:r}=a;return Ht(r)}):o++;pt()===t&&Ye(e||"all")}function bo(t){let e=t.keyCode||t.which||t.charCode;const n=_.indexOf(e);if(n>=0&&_.splice(n,1),t.key&&t.key.toLowerCase()==="meta"&&_.splice(0,_.length),(e===93||e===224)&&(e=91),e in X){X[e]=!1;for(const o in F)F[o]===e&&(H[o]=!1)}}function Ke(t){if(typeof t>"u")Object.keys(N).forEach(i=>{Array.isArray(N[i])&&N[i].forEach(s=>Lt(s)),delete N[i]}),Ht(null);else if(Array.isArray(t))t.forEach(i=>{i.key&&Lt(i)});else if(typeof t=="object")t.key&&Lt(t);else if(typeof t=="string"){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];let[i,s]=n;typeof i=="function"&&(s=i,i=""),Lt({key:t,scope:i,method:s,splitKey:"+"})}}const Lt=t=>{let{key:e,scope:n,method:o,splitKey:i="+"}=t;De(e).forEach(a=>{const r=a.split(i),d=r.length,f=r[d-1],h=f==="*"?"*":gt(f);if(!N[h])return;n||(n=pt());const u=d>1?Ue(F,r):[],g=[];N[h]=N[h].filter(E=>{const y=(o?E.method===o:!0)&&E.scope===n&&co(E.mods,u);return y&&g.push(E.element),!y}),g.forEach(E=>Ht(E))})};function Xe(t,e,n,o){if(e.element!==o)return;let i;if(e.scope===n||e.scope==="all"){i=e.mods.length>0;for(const s in X)Object.prototype.hasOwnProperty.call(X,s)&&(!X[s]&&e.mods.indexOf(+s)>-1||X[s]&&e.mods.indexOf(+s)===-1)&&(i=!1);(e.mods.length===0&&!X[16]&&!X[18]&&!X[17]&&!X[91]||i||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(_),e.method(t,e)===!1&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0)))}}function Pe(t,e){const n=N["*"];let o=t.keyCode||t.which||t.charCode;if(!H.filter.call(this,t))return;if((o===93||o===224)&&(o=91),_.indexOf(o)===-1&&o!==229&&_.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(r=>{const d=Ct[r];t[r]&&_.indexOf(d)===-1?_.push(d):!t[r]&&_.indexOf(d)>-1?_.splice(_.indexOf(d),1):r==="metaKey"&&t[r]&&(_=_.filter(f=>f in Ct||f===o))}),o in X){X[o]=!0;for(const r in F)F[r]===o&&(H[r]=!0);if(!n)return}for(const r in X)Object.prototype.hasOwnProperty.call(X,r)&&(X[r]=t[Ct[r]]);t.getModifierState&&!(t.altKey&&!t.ctrlKey)&&t.getModifierState("AltGraph")&&(_.indexOf(17)===-1&&_.push(17),_.indexOf(18)===-1&&_.push(18),X[17]=!0,X[18]=!0);const i=pt();if(n)for(let r=0;r<n.length;r++)n[r].scope===i&&(t.type==="keydown"&&n[r].keydown||t.type==="keyup"&&n[r].keyup)&&Xe(t,n[r],i,e);if(!(o in N))return;const s=N[o],a=s.length;for(let r=0;r<a;r++)if((t.type==="keydown"&&s[r].keydown||t.type==="keyup"&&s[r].keyup)&&s[r].key){const d=s[r],{splitKey:f}=d,h=d.key.split(f),u=[];for(let g=0;g<h.length;g++)u.push(gt(h[g]));u.sort().join("")===_.sort().join("")&&Xe(t,d,i,e)}}function H(t,e,n){_=[];const o=De(t);let i=[],s="all",a=document,r=0,d=!1,f=!0,h="+",u=!1,g=!1;for(n===void 0&&typeof e=="function"&&(n=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(s=e.scope),e.element&&(a=e.element),e.keyup&&(d=e.keyup),e.keydown!==void 0&&(f=e.keydown),e.capture!==void 0&&(u=e.capture),typeof e.splitKey=="string"&&(h=e.splitKey),e.single===!0&&(g=!0)),typeof e=="string"&&(s=e),g&&Ke(t,s);r<o.length;r++)t=o[r].split(h),i=[],t.length>1&&(i=Ue(F,t)),t=t[t.length-1],t=t==="*"?"*":gt(t),t in N||(N[t]=[]),N[t].push({keyup:d,keydown:f,scope:s,mods:i,shortcut:o[r],method:n,key:o[r],splitKey:h,element:a});if(typeof a<"u"&&window){if(!q.has(a)){const E=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return Pe(y,a)},p=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;Pe(y,a),bo(y)};q.set(a,{keydownListener:E,keyupListenr:p,capture:u}),Pt(a,"keydown",E,u),Pt(a,"keyup",p,u)}if(!ht){const E=()=>{_=[]};ht={listener:E,capture:u},Pt(window,"focus",E,u)}}}function wo(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(N).forEach(n=>{N[n].filter(i=>i.scope===e&&i.shortcut===t).forEach(i=>{i&&i.method&&i.method()})})}function Ht(t){const e=Object.values(N).flat();if(e.findIndex(o=>{let{element:i}=o;return i===t})<0){const{keydownListener:o,keyupListenr:i,capture:s}=q.get(t)||{};o&&i&&(ut(t,"keyup",i,s),ut(t,"keydown",o,s),q.delete(t))}if((e.length<=0||q.size<=0)&&(Object.keys(q).forEach(i=>{const{keydownListener:s,keyupListenr:a,capture:r}=q.get(i)||{};s&&a&&(ut(i,"keyup",a,r),ut(i,"keydown",s,r),q.delete(i))}),q.clear(),Object.keys(N).forEach(i=>delete N[i]),ht)){const{listener:i,capture:s}=ht;ut(window,"focus",i,s),ht=null}}const $t={getPressedKeyString:ho,setScope:Ye,getScope:pt,deleteScope:yo,getPressedKeyCodes:fo,getAllKeyCodes:go,isPressed:mo,filter:po,trigger:wo,unbind:Ke,keyMap:ft,modifier:F,modifierMap:Ct};for(const t in $t)Object.prototype.hasOwnProperty.call($t,t)&&(H[t]=$t[t]);if(typeof window<"u"){const t=window.hotkeys;H.noConflict=e=>(e&&window.hotkeys===H&&(window.hotkeys=t),H),window.hotkeys=H}const He=300,$e=["up","down","left","right"],je=zt?"⌘+a":"ctrl+a",Ao=[...$e.map(t=>`shift+${t}`),je],Fe=(t,e,n)=>{let o;const{annotatingEnabled:i,offsetReferenceSelector:s,selectionMode:a}=n,r=T=>o=T;let d;const f=T=>d=T,{store:h,selection:u}=e;let g,E,p;const y=T=>{E!==!1&&(g=tt(T.target)?void 0:{annotation:Ee(),selector:[],creator:o,created:new Date})},v=bt(T=>{const m=document.getSelection();if(!(m!=null&&m.anchorNode))return;if(tt(m.anchorNode)){g=void 0;return}const A=T.timeStamp-((p==null?void 0:p.timeStamp)||T.timeStamp);if((p==null?void 0:p.type)==="pointerdown"&&(A<1e3&&!g||m.isCollapsed&&A<He)&&y(p||T),!g)return;if(m.isCollapsed){h.getAnnotation(g.annotation)&&(u.clear(),h.deleteAnnotation(g.annotation));return}const w=m.getRangeAt(0),L=ee(w,t);if(Jt(L))return;const M=qt(L.cloneRange());(M.length!==g.selector.length||M.some((U,V)=>{var mt;return U.toString()!==((mt=g.selector[V])==null?void 0:mt.quote)}))&&(g={...g,selector:M.map(U=>te(U,t,s)),updated:new Date},h.getAnnotation(g.annotation)?h.updateTarget(g,I.LOCAL):u.clear())}),l=T=>{tt(T.target)||(p=yt(T),E=p.button===0)},c=T=>{if(tt(T.target)||!E)return;const m=()=>{const{x:w,y:L}=t.getBoundingClientRect(),M=T.target instanceof Node&&t.contains(T.target)&&h.getAt(T.clientX-w,T.clientY-L,a==="all",d);if(M){const{selected:k}=u,U=new Set(k.map(Z=>Z.id)),V=Array.isArray(M)?M.map(Z=>Z.id):[M.id];(U.size!==V.length||!V.every(Z=>U.has(Z)))&&u.userSelect(V,T)}else u.clear()},A=T.timeStamp-p.timeStamp;setTimeout(()=>{const w=document.getSelection();w!=null&&w.isCollapsed&&A<He?(g=void 0,m()):g&&g.selector.length>0&&(R(),u.userSelect(g.annotation,yt(T)))})},b=T=>{const m=document.getSelection();m!=null&&m.isCollapsed||((!g||g.selector.length===0)&&v(T),R(),u.userSelect(g.annotation,yt(T)))},x=T=>{T.key==="Shift"&&g&&(document.getSelection().isCollapsed||(R(),u.userSelect(g.annotation,it(T))))},S=T=>{const m=()=>setTimeout(()=>{(g==null?void 0:g.selector.length)>0&&(u.clear(),h.addAnnotation({id:g.annotation,bodies:[],target:g}),u.userSelect(g.annotation,it(T))),document.removeEventListener("selectionchange",m)},100);document.addEventListener("selectionchange",m),y(T)};H(Ao.join(","),{element:t,keydown:!0,keyup:!1},T=>{T.repeat||(p=it(T))}),H(je,{keydown:!0,keyup:!1},T=>{p=it(T),S(T)});const C=T=>{T.repeat||T.target!==t&&T.target!==document.body||(g=void 0,u.clear())};H($e.join(","),{keydown:!0,keyup:!1},C);const R=()=>{const T=h.getAnnotation(g.annotation);if(!T){h.addAnnotation({id:g.annotation,bodies:[],target:g});return}const{target:{updated:m}}=T,{updated:A}=g;(!m||!A||m<A)&&h.updateTarget(g)};return t.addEventListener("pointerdown",l),document.addEventListener("pointerup",c),document.addEventListener("contextmenu",b),i&&(t.addEventListener("keyup",x),t.addEventListener("selectstart",y),document.addEventListener("selectionchange",v)),{destroy:()=>{t.removeEventListener("pointerdown",l),document.removeEventListener("pointerup",c),document.removeEventListener("contextmenu",b),t.removeEventListener("keyup",x),t.removeEventListener("selectstart",y),document.removeEventListener("selectionchange",v),H.unbind()},setFilter:f,setUser:r}},ze=(t,e)=>({...t,annotatingEnabled:t.annotatingEnabled??e.annotatingEnabled,user:t.user||e.user}),We="SPANS",vo=(t,e={})=>{Ft(t),Wt(t);const n=ze(e,{annotatingEnabled:!0,user:Fn()}),o=_e(t,n.userSelectAction),{selection:i,viewport:s}=o,a=o.store,r=Un(a),d=Vn(o,r,n.adapter);let f=n.user;const h=n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":We:n.renderer||We,u=h==="SPANS"?Ae(t,o,s):h==="CSS_HIGHLIGHTS"?be(t,o,s):h==="CANVAS"?se(t,o,s):void 0;if(!u)throw`Unknown renderer implementation: ${h}`;console.debug(`Using ${h} renderer`),n.style&&u.setStyle(n.style);const g=Fe(t,o,n);return g.setUser(f),{...Kn(o,r,n.adapter),destroy:()=>{u.destroy(),g.destroy(),r.destroy()},element:t,getUser:()=>f,setFilter:C=>{u.setFilter(C),g.setFilter(C)},setStyle:C=>u.setStyle(C),setUser:C=>{f=C,g.setUser(C)},setSelected:C=>{C?i.setSelected(C):i.clear()},setPresenceProvider:C=>{C&&(u.setPainter(Ne(C,n.presence)),C.on("selectionChange",()=>u.redraw()))},setVisible:C=>u.setVisible(C),on:d.on,off:d.off,scrollIntoView:oe(t,a),state:o}};O.DEFAULT_SELECTED_STYLE=rt,O.DEFAULT_STYLE=z,O.NOT_ANNOTATABLE_CLASS=G,O.NOT_ANNOTATABLE_SELECTOR=Q,O.Origin=I,O.SelectionHandler=Fe,O.UserSelectAction=xe,O.W3CTextFormat=Gn,O.cancelSingleClickEvents=Ft,O.cloneKeyboardEvent=it,O.clonePointerEvent=yt,O.createBody=Cn,O.createCanvasRenderer=se,O.createHighlightsRenderer=be,O.createPresencePainter=Ne,O.createRenderer=ye,O.createSpansRenderer=Ae,O.createTextAnnotator=vo,O.createTextAnnotatorState=_e,O.debounce=bt,O.fillDefaults=ze,O.getQuoteContext=Gt,O.getRangeAnnotatableContents=wt,O.isMac=zt,O.isNotAnnotatable=tt,O.isRangeAnnotatable=jt,O.isRevived=j,O.isWhitespaceOrEmpty=Jt,O.mergeClientRects=Zt,O.paint=ie,O.parseW3CTextAnnotation=Be,O.programmaticallyFocusable=Wt,O.rangeToSelector=te,O.reviveAnnotation=At,O.reviveSelector=Tt,O.reviveTarget=st,O.scrollIntoView=oe,O.serializeW3CTextAnnotation=Me,O.splitAnnotatableRanges=qt,O.toDomRectList=Je,O.trimRangeToContainer=ee,O.whitespaceOrEmptyRegex=Qt,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
3
3
  //# sourceMappingURL=text-annotator.umd.js.map