@soomo/text-annotator 3.1.0-staging.20 → 3.1.0-staging.21

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