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