@soomo/text-annotator 3.0.0-staging.49 → 3.0.0-staging.50

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