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