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