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