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