@soomo/text-annotator 3.1.0-staging.0 → 3.1.0-staging.2

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