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