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