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