@soomo/text-annotator 3.0.0-staging.52 → 3.0.0-staging.53

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