@recogito/text-annotator 3.0.0-rc.19 → 3.0.0-rc.3

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.
Files changed (49) hide show
  1. package/dist/src/SelectionHandler.d.ts +4 -4
  2. package/dist/src/TextAnnotator.d.ts +4 -7
  3. package/dist/src/TextAnnotatorOptions.d.ts +4 -8
  4. package/dist/src/api/scrollIntoView.d.ts +2 -3
  5. package/dist/src/highlight/HighlightPainter.d.ts +19 -11
  6. package/dist/src/highlight/highlightLayer.d.ts +10 -0
  7. package/dist/src/highlight/index.d.ts +2 -3
  8. package/dist/src/highlight/trackViewport.d.ts +3 -0
  9. package/dist/src/index.d.ts +3 -4
  10. package/dist/src/model/{core/TextAnnotation.d.ts → TextAnnotation.d.ts} +2 -4
  11. package/dist/src/model/index.d.ts +1 -2
  12. package/dist/src/presence/PresencePainter.d.ts +4 -5
  13. package/dist/src/state/TextAnnotationStore.d.ts +6 -7
  14. package/dist/src/state/TextAnnotatorState.d.ts +6 -6
  15. package/dist/src/state/index.d.ts +1 -0
  16. package/dist/src/state/reviveTarget.d.ts +9 -0
  17. package/dist/src/state/spatialTree.d.ts +6 -9
  18. package/dist/src/utils/index.d.ts +0 -9
  19. package/dist/text-annotator.css +1 -1
  20. package/dist/text-annotator.es.js +945 -1480
  21. package/dist/text-annotator.es.js.map +1 -1
  22. package/dist/text-annotator.umd.js +1 -2
  23. package/dist/text-annotator.umd.js.map +1 -1
  24. package/package.json +11 -17
  25. package/dist/src/highlight/Highlight.d.ts +0 -6
  26. package/dist/src/highlight/HighlightStyle.d.ts +0 -12
  27. package/dist/src/highlight/baseRenderer.d.ts +0 -21
  28. package/dist/src/highlight/canvas/canvasRenderer.d.ts +0 -4
  29. package/dist/src/highlight/canvas/index.d.ts +0 -1
  30. package/dist/src/highlight/highlights/highlightsRenderer.d.ts +0 -6
  31. package/dist/src/highlight/highlights/index.d.ts +0 -1
  32. package/dist/src/highlight/span/index.d.ts +0 -1
  33. package/dist/src/highlight/span/spansRenderer.d.ts +0 -4
  34. package/dist/src/highlight/viewport.d.ts +0 -13
  35. package/dist/src/model/core/index.d.ts +0 -1
  36. package/dist/src/model/w3c/W3CTextAnnotation.d.ts +0 -34
  37. package/dist/src/model/w3c/W3CTextFormatAdapter.d.ts +0 -13
  38. package/dist/src/model/w3c/index.d.ts +0 -2
  39. package/dist/src/utils/debounce.d.ts +0 -1
  40. package/dist/src/utils/getAnnotatableFragment.d.ts +0 -5
  41. package/dist/src/utils/getQuoteContext.d.ts +0 -4
  42. package/dist/src/utils/isRevived.d.ts +0 -3
  43. package/dist/src/utils/rangeToSelector.d.ts +0 -3
  44. package/dist/src/utils/reviveAnnotation.d.ts +0 -3
  45. package/dist/src/utils/reviveSelector.d.ts +0 -12
  46. package/dist/src/utils/reviveTarget.d.ts +0 -3
  47. package/dist/src/utils/splitAnnotatableRanges.d.ts +0 -6
  48. package/dist/test/model/w3c/W3CTextFormatAdapter.test.d.ts +0 -1
  49. package/dist/test/model/w3c/fixtures.d.ts +0 -4
@@ -1,3 +1,2 @@
1
- (function(N,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(N=typeof globalThis<"u"?globalThis:N||self,D(N.RecogitoJS={}))})(this,function(N){"use strict";const D=(t,e=10)=>{let n;return(...o)=>{clearTimeout(n),n=setTimeout(()=>t.apply(void 0,o),e)}},mt="not-annotatable",H=`.${mt}`,Jt=t=>{var n;const e=t.commonAncestorContainer;return e instanceof HTMLElement?!e.closest(H):!((n=e.parentElement)!=null&&n.closest(H))},Zt=function*(t){const e=document.createNodeIterator(t.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(mt)&&t.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=e.nextNode();)n instanceof HTMLElement&&(yield n)},bt=t=>{if(!Jt(t))return[];const e=[];let n=null;for(const o of Zt(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]},J=t=>{const e=t.cloneContents();return e.querySelectorAll(H).forEach(n=>n.remove()),e},te=t=>{const e=t.cloneContents();return e.querySelectorAll(H).forEach(n=>n.remove()),e},vt=(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()}},yt=(t,e)=>{const n=document.createNodeIterator(e);let o=null;for(let i=0;i<t+1;i++)o=n.nextNode();return o},ee=t=>{const{commonAncestorContainer:e,startContainer:n,startOffset:o,endContainer:i,endOffset:r}=t,s=Array.from(e.childNodes).map(l=>{const m=l.cloneNode(!0);return l.nodeName==="CANVAS"?l:m}),a=vt(n,e),u=vt(i,e),h=()=>{const l=e;l.replaceChildren(...s);const m=yt(a,l),g=yt(u,l);return t.setStart(m,o),t.setEnd(g,r),t},v=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=v(l),g=document.createRange();g.selectNode(i),g.setEnd(i,r);const w=v(g),y=ne(t).reverse().map(c=>{var f;const d=document.createElement("SPAN");return(f=c.parentNode)==null||f.insertBefore(d,c),d.appendChild(c),d});return{unwrap:h,nodes:[m,...y,w]}}},ne=t=>{const{commonAncestorContainer:e,startContainer:n,endContainer:o}=t,i=document.createNodeIterator(e,NodeFilter.SHOW_TEXT);let r=i.nextNode(),s=!1;const a=[];for(;r!=null;)r===o&&(s=!1),s&&a.push(r),r===n&&(s=!0),r=i.nextNode();return a},oe=t=>{const{startContainer:e,endContainer:n}=t;if(e===n)return Array.from(t.getClientRects());{const{unwrap:o,nodes:i}=ee(t),r=i.reduce((s,a)=>[...s,...a.getClientRects()],[]);return o(),r}},wt=(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 s=J(r).textContent,a=document.createRange();a.setStart(t.endContainer,t.endOffset),i===document.body?a.setEnd(i,i.childNodes.length):a.setEndAfter(i);const u=J(a).textContent;return{prefix:s.substring(s.length-n),suffix:u.substring(0,n)}},U=t=>t.every(e=>e.range instanceof Range&&!e.range.collapsed),ie=(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"},re=(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)},At=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 s=ie(n,r);if(s==="inline-adjacent"){o=o.map(a=>a===r?re(n,r):a),i=!0;break}else if(s==="inline-contains"){o=o.map(a=>a===r?n:a),i=!0;break}else if(s==="inline-is-contained"){i=!0;break}else if(s==="block-contains"||s==="block-is-contained"){n.width<r.width&&(o=o.map(a=>a===r?n:a)),i=!0;break}}return i?o:[...o,n]},[]),xt=(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=J(o).textContent,s=t.toString(),a=r.length||0,u=a+s.length;return n?{quote:s,start:a,end:u,range:t,offsetReference:i}:{quote:s,start:a,end:u,range:t}},it=(t,e)=>{var v,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(H)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT});let s=0;const a=document.createRange();let u=r.nextNode();u===null&&console.error("Could not revive annotation target. Content missing.");let h=!i;for(;u!==null;){if(h||(h=i==null?void 0:i.contains(u)),h){const m=((v=u.textContent)==null?void 0:v.length)||0;if(s+m>n){a.setStart(u,n-s);break}s+=m}u=r.nextNode()}for(;u!==null;){const m=((l=u.textContent)==null?void 0:l.length)||0;if(s+m>=o){a.setEnd(u,o-s);break}s+=m,u=r.nextNode()}return{...t,range:a}},j=(t,e)=>U(t.selector)?t:{...t,selector:t.selector.map(n=>n.range instanceof Range&&!n.range.collapsed?n:it(n,e))},Z=(t,e)=>U(t.target.selector)?t:{...t,target:j(t.target,e)},Et=t=>{var i;const{startContainer:e,endContainer:n}=t;if(e.nodeType===Node.TEXT_NODE&&n.nodeType===Node.TEXT_NODE)return t;if(e.nodeType!==Node.TEXT_NODE){const r=e.nextSibling||e.parentNode,s=(r==null?void 0:r.nodeType)===Node.TEXT_NODE?r:Array.from(r.childNodes).filter(a=>a.nodeType===Node.TEXT_NODE).shift();t.setEnd(s,0)}if(n.nodeType!==Node.TEXT_NODE){const r=n.previousSibling||n.parentNode,s=(r==null?void 0:r.nodeType)===Node.TEXT_NODE?r:Array.from(r.childNodes).filter(a=>a.nodeType===Node.TEXT_NODE).pop();t.setEnd(s,((i=s==null?void 0:s.textContent)==null?void 0:i.length)||0)}return t},$={fill:"rgb(0, 128, 255)",fillOpacity:.18},rt={fill:"rgb(0, 128, 255)",fillOpacity:.45},se=t=>{const{top:e,left:n}=t.getBoundingClientRect(),{innerWidth:o,innerHeight:i}=window,r=-n,s=-e,a=o-n,u=i-e;return{top:e,left:n,minX:r,minY:s,maxX:a,maxY:u}},ae=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:s}=e;let a,u,h;const v=ae(n),l=p=>{const{x:S,y:E}=t.getBoundingClientRect(),C=i.getAt(p.clientX-S,p.clientY-E);C&&(!u||u(C))?s.current!==C.id&&(t.classList.add("hovered"),s.set(C.id)):s.current&&(t.classList.remove("hovered"),s.set(null))};t.addEventListener("pointermove",l);const m=(p=!1)=>{h&&h.clear();const S=se(t),{minX:E,minY:C,maxX:L,maxY:O}=S,k=u?i.getIntersecting(E,C,L,O).filter(({annotation:Y})=>u(Y)):i.getIntersecting(E,C,L,O),vn=r.selected.map(({id:Y})=>Y),yn=k.map(({annotation:Y,rects:wn})=>{const An=vn.includes(Y.id),xn=Y.id===s.current;return{annotation:Y,rects:wn,state:{selected:An,hover:xn,custom:{}}}});o.redraw(yn,S,a,h,p),setTimeout(()=>v(k.map(({annotation:Y})=>Y)),1)},g=p=>{h=p,m()},w=p=>{a=p,m()},A=p=>{u=p,m()},y=()=>m();i.observe(y);const c=r.subscribe(()=>m()),d=()=>m();document.addEventListener("scroll",d,{capture:!0,passive:!0});const f=D(()=>{i.recalculatePositions(),h&&h.reset(),m()});window.addEventListener("resize",f);const b=new ResizeObserver(f);b.observe(t);const x={attributes:!0,childList:!0,subtree:!0},R=new MutationObserver(p=>{p.every(E=>E.target===t||t.contains(E.target))||m(!0)});return R.observe(document.body,x),{destroy:()=>{t.removeEventListener("pointermove",l),o.destroy(),i.unobserve(y),c(),document.removeEventListener("scroll",d),window.removeEventListener("resize",f),b.disconnect(),R.disconnect()},redraw:m,setStyle:w,setFilter:A,setPainter:g,setVisible:o.setVisible}},le=()=>{const t=document.createElement("canvas");return t.width=window.innerWidth,t.height=window.innerHeight,t.className="r6o-highlight-layer bg",t},ce=(t,e)=>{if(t.width=e?2*window.innerWidth:window.innerWidth,t.height=e?2*window.innerHeight:window.innerHeight,e){const n=t.getContext("2d");n.scale(2,2),n.translate(.5,.5)}},de=t=>{t.classList.add("r6o-annotatable");const e=le(),n=e.getContext("2d");t.insertBefore(e,t.firstChild);const o=(a,u,h,v)=>requestAnimationFrame(()=>{const{width:l,height:m}=e;n.clearRect(-.5,-.5,l+1,m+1),v&&v.clear();const{top:g,left:w}=u;a.forEach(A=>{var f;const y=h?typeof h=="function"?h(A.annotation,A.state):h:(f=A.state)!=null&&f.selected?rt:$,c=v&&v.paint(A,u)||y,d=A.rects.map(({x:b,y:x,width:R,height:T})=>({x:b+w,y:x+g,width:R,height:T}));n.fillStyle=c.fill,n.globalAlpha=c.fillOpacity||1,d.forEach(({x:b,y:x,width:R,height:T})=>n.fillRect(b,x-2.5,R,T+5)),c.underlineColor&&(n.globalAlpha=1,n.strokeStyle=c.underlineColor,d.forEach(({x:b,y:x,width:R,height:T})=>{n.beginPath(),n.moveTo(b,x+T+4),n.lineTo(b+R,x+T+4),n.stroke()}))})}),i=D(()=>{ce(e)});return window.addEventListener("resize",i),{destroy:()=>{t.removeChild(e),window.removeEventListener("resize",i)},setVisible:a=>{console.log("setVisible not implemented on Canvas renderer")},redraw:o}},St=(t,e,n)=>st(t,e,n,de(t));var ue={grad:.9,turn:360,rad:360/(2*Math.PI)},X=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},M=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},Ct=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},Tt=function(t){return{r:_(t.r,0,255),g:_(t.g,0,255),b:_(t.b,0,255),a:_(t.a)}},at=function(t){return{r:M(t.r),g:M(t.g),b:M(t.b),a:M(t.a,3)}},he=/^#([0-9a-f]{3,8})$/i,tt=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Rt=function(t){var e=t.r,n=t.g,o=t.b,i=t.a,r=Math.max(e,n,o),s=r-Math.min(e,n,o),a=s?r===e?(n-o)/s:r===n?2+(o-e)/s:4+(e-n)/s:0;return{h:60*(a<0?a+6:a),s:r?s/r*100:0,v:r/255*100,a:i}},Lt=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),s=o*(1-n),a=o*(1-(e-r)*n),u=o*(1-(1-e+r)*n),h=r%6;return{r:255*[o,a,s,s,u,o][h],g:255*[u,o,o,a,s,s][h],b:255*[s,s,u,o,o,a][h],a:i}},Nt=function(t){return{h:Ct(t.h),s:_(t.s,0,100),l:_(t.l,0,100),a:_(t.a)}},Bt=function(t){return{h:M(t.h),s:M(t.s),l:M(t.l),a:M(t.a,3)}},Ot=function(t){return Lt((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=Rt(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},fe=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ge=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,pe=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,me=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt={string:[[function(t){var e=he.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?M(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?M(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=pe.exec(t)||me.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:Tt({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=fe.exec(t)||ge.exec(t);if(!e)return null;var n,o,i=Nt({h:(n=e[1],o=e[2],o===void 0&&(o="deg"),Number(n)*(ue[o]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return Ot(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)?Tt({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 s=Nt({h:Number(e),s:Number(n),l:Number(o),a:Number(r)});return Ot(s)},"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 s=function(a){return{h:Ct(a.h),s:_(a.s,0,100),v:_(a.v,0,100),a:_(a.a)}}({h:Number(e),s:Number(n),v:Number(o),a:Number(r)});return Lt(s)},"hsv"]]},It=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]},be=function(t){return typeof t=="string"?It(t.trim(),Mt.string):typeof t=="object"&&t!==null?It(t,Mt.object):[null,void 0]},lt=function(t,e){var n=q(t);return{h:n.h,s:_(n.s+100*e,0,100),l:n.l,a:n.a}},ct=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},_t=function(t,e){var n=q(t);return{h:n.h,s:n.s,l:_(n.l+100*e,0,100),a:n.a}},Vt=function(){function t(e){this.parsed=be(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 M(ct(this.rgba),2)},t.prototype.isDark=function(){return ct(this.rgba)<.5},t.prototype.isLight=function(){return ct(this.rgba)>=.5},t.prototype.toHex=function(){return e=at(this.rgba),n=e.r,o=e.g,i=e.b,s=(r=e.a)<1?tt(M(255*r)):"","#"+tt(n)+tt(o)+tt(i)+s;var e,n,o,i,r,s},t.prototype.toRgb=function(){return at(this.rgba)},t.prototype.toRgbString=function(){return e=at(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 Bt(q(this.rgba))},t.prototype.toHslString=function(){return e=Bt(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=Rt(this.rgba),{h:M(e.h),s:M(e.s),v:M(e.v),a:M(e.a,3)};var e},t.prototype.invert=function(){return V({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),V(lt(this.rgba,e))},t.prototype.desaturate=function(e){return e===void 0&&(e=.1),V(lt(this.rgba,-e))},t.prototype.grayscale=function(){return V(lt(this.rgba,-1))},t.prototype.lighten=function(e){return e===void 0&&(e=.1),V(_t(this.rgba,e))},t.prototype.darken=function(e){return e===void 0&&(e=.1),V(_t(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"?V({r:(n=this.rgba).r,g:n.g,b:n.b,a:e}):M(this.rgba.a,3);var n},t.prototype.hue=function(e){var n=q(this.rgba);return typeof e=="number"?V({h:e,s:n.s,l:n.l,a:n.a}):M(n.h)},t.prototype.isEqual=function(e){return this.toHex()===V(e).toHex()},t}(),V=function(t){return t instanceof Vt?t:new Vt(t)};const ve=t=>[`background-color:${V((t==null?void 0:t.fill)||$.fill).alpha((t==null?void 0:t.fillOpacity)===void 0?$.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(";"),Ut=()=>{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,s,a,u)=>{u&&u.clear();const h=new Set(r.map(l=>l.annotation.id));Array.from(e).filter(l=>!h.has(l));const v=r.map(l=>{var w;const m=a?typeof a=="function"?a(l.annotation,l.state):a:(w=l.state)!=null&&w.selected?rt:$,g=u&&u.paint(l,s)||m;return`::highlight(_${l.annotation.id}) { ${ve(g)} }`});t.innerHTML=v.join(`
2
- `),CSS.highlights.clear(),r.forEach(({annotation:l})=>{const m=l.target.selector.map(w=>w.range),g=new Highlight(...m);CSS.highlights.set(`_${l.id}`,g)}),e=h}}},Xt=(t,e,n)=>st(t,e,n,Ut());var kt=Object.prototype.hasOwnProperty;function dt(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--&&dt(t[o],e[o]););return o===-1}if(!n||typeof t=="object"){o=0;for(n in t)if(kt.call(t,n)&&++o&&!kt.call(e,n)||!(n in e)||!dt(t[n],e[n]))return!1;return Object.keys(e).length===o}}return t!==t&&e!==e}const ye=(t,e,n,o,i)=>{var s;const r=n?typeof n=="function"?n(t.annotation,t.state,i):n:(s=t.state)!=null&&s.selected?rt:$;return o&&o.paint(t,e)||r},we=(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},Ae=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:(s,a,u,h,v)=>{if(dt(n,s)&&!v)return;e.innerHTML="";const m=s.reduce((g,{rects:w})=>[...g,...w],[]);s.forEach(g=>{const w=g.rects.map(A=>{const y=document.createElement("span");y.className="r6o-annotation",y.dataset.annotation=g.annotation.id,y.style.left=`${A.x}px`,y.style.top=`${A.y}px`,y.style.width=`${A.width}px`,y.style.height=`${A.height}px`;const c=we(A,m),d=ye(g,a,u,h,c),f=V((d==null?void 0:d.fill)||$.fill).alpha((d==null?void 0:d.fillOpacity)===void 0?$.fillOpacity:d.fillOpacity).toHex();return y.style.backgroundColor=f,d.underlineStyle&&(y.style.borderStyle=d.underlineStyle),d.underlineColor&&(y.style.borderColor=d.underlineColor),d.underlineThickness&&(y.style.borderBottomWidth=`${d.underlineThickness}px`),d.underlineOffset&&(y.style.paddingBottom=`${d.underlineOffset}px`),e.appendChild(y),y});return{id:g.annotation.id,spans:w}}),n=s},setVisible:s=>{s?e.classList.remove("hidden"):e.classList.add("hidden")}}},Yt=(t,e,n)=>st(t,e,n,Ae(t));let et;const xe=new Uint8Array(16);function Ee(){if(!et&&(et=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!et))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return et(xe)}const I=[];for(let t=0;t<256;++t)I.push((t+256).toString(16).slice(1));function Se(t,e=0){return I[t[e+0]]+I[t[e+1]]+I[t[e+2]]+I[t[e+3]]+"-"+I[t[e+4]]+I[t[e+5]]+"-"+I[t[e+6]]+I[t[e+7]]+"-"+I[t[e+8]]+I[t[e+9]]+"-"+I[t[e+10]]+I[t[e+11]]+I[t[e+12]]+I[t[e+13]]+I[t[e+14]]+I[t[e+15]]}const Dt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ht(t,e,n){if(Dt.randomUUID&&!e&&!t)return Dt.randomUUID();t=t||{};const o=t.random||(t.rng||Ee)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,e){n=n||0;for(let i=0;i<16;++i)e[n+i]=o[i];return e}return Se(o)}var $t=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($t.call(t,n)&&++o&&!$t.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 ut(){}function Ce(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}const z=[];function ht(t,e=ut){let n;const o=new Set;function i(a){if(Ce(t,a)&&(t=a,n)){const u=!z.length;for(const h of o)h[1](),z.push(h,t);if(u){for(let h=0;h<z.length;h+=2)z[h][0](z[h+1]);z.length=0}}}function r(a){i(a(t))}function s(a,u=ut){const h=[a,u];return o.add(h),o.size===1&&(n=e(i,r)||ut),a(t),()=>{o.delete(h),o.size===0&&n&&(n(),n=null)}}return{set:i,update:r,subscribe:s}}const Te=t=>{const{subscribe:e,set:n}=ht();let o;return e(i=>o=i),t.observe(({changes:i})=>{if(o){(i.deleted||[]).some(s=>s.id===o)&&n(void 0);const r=(i.updated||[]).find(({oldValue:s})=>s.id===o);r&&n(r.newValue.id)}}),{get current(){return o},subscribe:e,set:n}},ft={selected:[]},Re=(t,e="EDIT")=>{const{subscribe:n,set:o}=ht(ft);let i=ft;n(l=>i=l);const r=()=>o(ft),s=()=>{var l;return((l=i.selected)==null?void 0:l.length)===0},a=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 w=Le(g,e);o(w==="EDIT"?{selected:[{id:l,editable:!0}],pointerEvent:m}:w==="SELECT"?{selected:[{id:l}],pointerEvent:m}:{selected:[],pointerEvent:m})}else console.warn("Invalid selection: "+l)},h=(l,m=!0)=>{const g=Array.isArray(l)?l:[l],w=g.map(A=>t.getAnnotation(A)).filter(Boolean);o({selected:w.map(({id:A})=>({id:A,editable:m}))}),w.length!==g.length&&console.warn("Invalid selection",l)},v=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})=>v((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:s,isSelected:a,setSelected:h,subscribe:n}},Le=(t,e)=>typeof e=="function"?e(t)||"EDIT":e||"EDIT",Ne=[];for(let t=0;t<256;++t)Ne.push((t+256).toString(16).slice(1));typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Be=(t,e)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Oe=(t,e)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Me=(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})),Ie=(t,e)=>!P(t.target,e.target),Pt=(t,e)=>{const n=Be(t,e),o=Oe(t,e),i=Me(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:Ie(t,e)?{oldTarget:t.target,newTarget:e.target}:void 0}};var B=(t=>(t.LOCAL="LOCAL",t.REMOTE="REMOTE",t))(B||{});const _e=(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:s}=t.options,a=u=>u&&u.length>0;if(!(a(i.created)||a(i.deleted))){const u=(n=i.updated)==null?void 0:n.some(v=>a(v.bodiesCreated)||a(v.bodiesDeleted)||a(v.bodiesUpdated)),h=(o=i.updated)==null?void 0:o.some(v=>v.targetUpdated);if(s==="BODY_ONLY"&&u&&!h||s==="TARGET_ONLY"&&h&&!u)return!1}}if(t.options.annotations){const s=new Set([...(i.created||[]).map(a=>a.id),...(i.deleted||[]).map(a=>a.id),...(i.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(t.options.annotations)?t.options.annotations:[t.options.annotations]).find(a=>s.has(a))}else return!0},Ve=(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)),s=new Set((e.updated||[]).map(({oldValue:l})=>l.id)),a=new Set((e.updated||[]).filter(({oldValue:l})=>n.has(l.id)||o.has(l.id)).map(({oldValue:l})=>l.id)),u=[...(t.created||[]).filter(l=>!r.has(l.id)).map(l=>s.has(l.id)?e.updated.find(({oldValue:m})=>m.id===l.id).newValue:l),...e.created||[]],h=[...(t.deleted||[]).filter(l=>!i.has(l.id)),...(e.deleted||[]).filter(l=>!n.has(l.id))],v=[...(t.updated||[]).filter(({newValue:l})=>!r.has(l.id)).map(l=>{const{oldValue:m,newValue:g}=l;if(s.has(g.id)){const w=e.updated.find(A=>A.oldValue.id===g.id).newValue;return Pt(m,w)}else return l}),...(e.updated||[]).filter(({oldValue:l})=>!a.has(l.id))];return{created:u,deleted:h,updated:v}},Ue=t=>t.id!==void 0,Xe=()=>{const t=new Map,e=new Map,n=[],o=(p,S={})=>n.push({onChange:p,options:S}),i=p=>{const S=n.findIndex(E=>E.onChange==p);S>-1&&n.splice(S,1)},r=(p,S)=>{const E={origin:p,changes:{created:S.created||[],updated:S.updated||[],deleted:S.deleted||[]},state:[...t.values()]};n.forEach(C=>{_e(C,E)&&C.onChange(E)})},s=(p,S=B.LOCAL)=>{if(t.get(p.id))throw Error(`Cannot add annotation ${p.id} - exists already`);t.set(p.id,p),p.bodies.forEach(E=>e.set(E.id,p.id)),r(S,{created:[p]})},a=(p,S)=>{const E=typeof p=="string"?S:p,C=typeof p=="string"?p:p.id,L=t.get(C);if(L){const O=Pt(L,E);return C===E.id?t.set(C,E):(t.delete(C),t.set(E.id,E)),L.bodies.forEach(k=>e.delete(k.id)),E.bodies.forEach(k=>e.set(k.id,E.id)),O}else console.warn(`Cannot update annotation ${C} - does not exist`)},u=(p,S=B.LOCAL,E=B.LOCAL)=>{const C=Ue(S)?E:S,L=a(p,S);L&&r(C,{updated:[L]})},h=(p,S=B.LOCAL)=>{const E=p.reduce((C,L)=>{const O=a(L);return O?[...C,O]:C},[]);E.length>0&&r(S,{updated:E})},v=(p,S=B.LOCAL)=>{const E=t.get(p.annotation);if(E){const C={...E,bodies:[...E.bodies,p]};t.set(E.id,C),e.set(p.id,C.id),r(S,{updated:[{oldValue:E,newValue:C,bodiesCreated:[p]}]})}else console.warn(`Attempt to add body to missing annotation: ${p.annotation}`)},l=()=>[...t.values()],m=(p=B.LOCAL)=>{const S=[...t.values()];t.clear(),e.clear(),r(p,{deleted:S})},g=(p,S=!0,E=B.LOCAL)=>{if(S){const C=[...t.values()];t.clear(),e.clear(),p.forEach(L=>{t.set(L.id,L),L.bodies.forEach(O=>e.set(O.id,L.id))}),r(E,{created:p,deleted:C})}else{const C=p.reduce((L,O)=>{const k=t.get(O.id);return k?[...L,k]:L},[]);if(C.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${C.map(L=>L.id).join(", ")}`);p.forEach(L=>{t.set(L.id,L),L.bodies.forEach(O=>e.set(O.id,L.id))}),r(E,{created:p})}},w=p=>{const S=typeof p=="string"?p:p.id,E=t.get(S);if(E)return t.delete(S),E.bodies.forEach(C=>e.delete(C.id)),E;console.warn(`Attempt to delete missing annotation: ${S}`)},A=(p,S=B.LOCAL)=>{const E=w(p);E&&r(S,{deleted:[E]})},y=(p,S=B.LOCAL)=>{const E=p.reduce((C,L)=>{const O=w(L);return O?[...C,O]:C},[]);E.length>0&&r(S,{deleted:E})},c=(p,S=B.LOCAL)=>{const E=t.get(p.annotation);if(E){const C=E.bodies.find(L=>L.id===p.id);if(C){e.delete(C.id);const L={...E,bodies:E.bodies.filter(O=>O.id!==p.id)};t.set(E.id,L),r(S,{updated:[{oldValue:E,newValue:L,bodiesDeleted:[C]}]})}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}`)},d=p=>{const S=t.get(p);return S?{...S}:void 0},f=p=>{const S=e.get(p);if(S){const E=d(S).bodies.find(C=>C.id===p);if(E)return E;console.error(`Store integrity error: body ${p} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${p}`)},b=(p,S)=>{if(p.annotation!==S.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=t.get(p.annotation);if(E){const C=E.bodies.find(O=>O.id===p.id),L={...E,bodies:E.bodies.map(O=>O.id===C.id?S:O)};return t.set(E.id,L),C.id!==S.id&&(e.delete(C.id),e.set(S.id,L.id)),{oldValue:E,newValue:L,bodiesUpdated:[{oldBody:C,newBody:S}]}}else console.warn(`Attempt to add body to missing annotation ${p.annotation}`)},x=(p,S,E=B.LOCAL)=>{const C=b(p,S);C&&r(E,{updated:[C]})},R=(p,S=B.LOCAL)=>{const E=p.map(C=>b({id:C.id,annotation:C.annotation},C)).filter(Boolean);r(S,{updated:E})},T=p=>{const S=t.get(p.annotation);if(S){const E={...S,target:{...S.target,...p}};return t.set(S.id,E),{oldValue:S,newValue:E,targetUpdated:{oldTarget:S.target,newTarget:p}}}else console.warn(`Attempt to update target on missing annotation: ${p.annotation}`)};return{addAnnotation:s,addBody:v,all:l,bulkAddAnnotation:g,bulkDeleteAnnotation:y,bulkUpdateAnnotation:h,bulkUpdateBodies:R,bulkUpdateTargets:(p,S=B.LOCAL)=>{const E=p.map(C=>T(C)).filter(Boolean);E.length>0&&r(S,{updated:E})},clear:m,deleteAnnotation:A,deleteBody:c,getAnnotation:d,getBody:f,observe:o,unobserve:i,updateAnnotation:u,updateBody:x,updateTarget:(p,S=B.LOCAL)=>{const E=T(p);E&&r(S,{updated:[E]})}}};let ke=()=>({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 Ye=250,De=t=>{const e=ke(),n=[];let o=-1,i=!1,r=0;const s=g=>{if(!i){const{changes:w}=g,A=performance.now();if(A-r>Ye)n.splice(o+1),n.push(w),o=n.length-1;else{const y=n.length-1;n[y]=Ve(n[y],w)}r=A}i=!1};t.observe(s,{origin:B.LOCAL});const a=g=>g&&g.length>0&&t.bulkDeleteAnnotation(g),u=g=>g&&g.length>0&&t.bulkAddAnnotation(g,!1),h=g=>g&&g.length>0&&t.bulkUpdateAnnotation(g.map(({oldValue:w})=>w)),v=g=>g&&g.length>0&&t.bulkUpdateAnnotation(g.map(({newValue:w})=>w)),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(s),on:(g,w)=>e.on(g,w),redo:()=>{if(n.length-1>o){i=!0;const{created:g,updated:w,deleted:A}=n[o+1];u(g),v(w),m(A),e.emit("redo",n[o+1]),o+=1}},undo:()=>{if(o>-1){i=!0;const{created:g,updated:w,deleted:A}=n[o];a(g),h(w),l(A),e.emit("undo",n[o]),o-=1}}}},He=()=>{const{subscribe:t,set:e}=ht([]);return{subscribe:t,set:e}},$e=(t,e,n,o)=>{const{store:i,selection:r,hover:s,viewport:a}=t,u=new Map;let h=[],v,l;const m=(c,d)=>{u.has(c)?u.get(c).push(d):u.set(c,[d])},g=(c,d)=>{const f=u.get(c);f&&f.indexOf(d)>0&&f.splice(f.indexOf(d),1)},w=(c,d,f)=>{u.has(c)&&setTimeout(()=>{u.get(c).forEach(b=>{if(n){const x=Array.isArray(d)?d.map(T=>n.serialize(T)):n.serialize(d),R=f?f instanceof PointerEvent?f:n.serialize(f):void 0;b(x,R)}else b(d,f)})},1)},A=()=>{const{selected:c}=r,d=(c||[]).map(({id:f})=>i.getAnnotation(f));d.forEach(f=>{const b=h.find(x=>x.id===f.id);(!b||!P(b,f))&&w("updateAnnotation",f,b)}),h=h.map(f=>d.find(({id:x})=>x===f.id)||f)};r.subscribe(({selected:c})=>{if(!(h.length===0&&c.length===0)){if(h.length===0&&c.length>0)h=c.map(({id:d})=>i.getAnnotation(d));else if(h.length>0&&c.length===0)h.forEach(d=>{const f=i.getAnnotation(d.id);f&&!P(f,d)&&w("updateAnnotation",f,d)}),h=[];else{const d=new Set(h.map(b=>b.id)),f=new Set(c.map(({id:b})=>b));h.filter(b=>!f.has(b.id)).forEach(b=>{const x=i.getAnnotation(b.id);x&&!P(x,b)&&w("updateAnnotation",x,b)}),h=[...h.filter(b=>f.has(b.id)),...c.filter(({id:b})=>!d.has(b)).map(({id:b})=>i.getAnnotation(b))]}w("selectionChanged",h)}}),s.subscribe(c=>{!v&&c?w("mouseEnterAnnotation",i.getAnnotation(c)):v&&!c?w("mouseLeaveAnnotation",i.getAnnotation(v)):v&&c&&(w("mouseLeaveAnnotation",i.getAnnotation(v)),w("mouseEnterAnnotation",i.getAnnotation(c))),v=c}),a==null||a.subscribe(c=>w("viewportIntersect",c.map(d=>i.getAnnotation(d)))),i.observe(c=>{o&&(l&&clearTimeout(l),l=setTimeout(A,1e3));const{created:d,deleted:f}=c.changes;(d||[]).forEach(b=>w("createAnnotation",b)),(f||[]).forEach(b=>w("deleteAnnotation",b)),(c.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:x})=>{const R=h.find(T=>T.id===b.id)||b;h=h.map(T=>T.id===b.id?x:T),w("updateAnnotation",x,R)})},{origin:B.LOCAL}),i.observe(c=>{if(h){const d=new Set(h.map(b=>b.id)),f=(c.changes.updated||[]).filter(({newValue:b})=>d.has(b.id)).map(({newValue:b})=>b);f.length>0&&(h=h.map(b=>f.find(R=>R.id===b.id)||b))}},{origin:B.REMOTE});const y=c=>d=>{const{updated:f}=d;c?(f||[]).forEach(b=>w("updateAnnotation",b.oldValue,b.newValue)):(f||[]).forEach(b=>w("updateAnnotation",b.newValue,b.oldValue))};return e.on("undo",y(!0)),e.on("redo",y(!1)),{on:m,off:g,emit:w}},Pe=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:[]}),ze=(t,e,n)=>{const{store:o,selection:i}=t,r=y=>{if(n){const{parsed:c,error:d}=n.parse(y);c?o.addAnnotation(c,B.REMOTE):console.error(d)}else o.addAnnotation(y,B.REMOTE)},s=()=>i.clear(),a=()=>o.clear(),u=y=>{const c=o.getAnnotation(y);return n&&c?n.serialize(c):c},h=()=>n?o.all().map(n.serialize):o.all(),v=()=>{var y;const c=(((y=i.selected)==null?void 0:y.map(d=>d.id))||[]).map(d=>o.getAnnotation(d)).filter(Boolean);return n?c.map(n.serialize):c},l=(y,c=!0)=>fetch(y).then(d=>d.json()).then(d=>(g(d,c),d)),m=y=>{if(typeof y=="string"){const c=o.getAnnotation(y);if(o.deleteAnnotation(y),c)return n?n.serialize(c):c}else{const c=n?n.parse(y).parsed:y;if(c)return o.deleteAnnotation(c),y}},g=(y,c=!0)=>{if(n){const{parsed:d,failed:f}=Pe(n)(y);f.length>0&&console.warn(`Discarded ${f.length} invalid annotations`,f),o.bulkAddAnnotation(d,c,B.REMOTE)}else o.bulkAddAnnotation(y,c,B.REMOTE)},w=y=>{y?i.setSelected(y):i.clear()},A=y=>{if(n){const c=n.parse(y).parsed,d=n.serialize(o.getAnnotation(c.id));return o.updateAnnotation(c),d}else{const c=o.getAnnotation(y.id);return o.updateAnnotation(y),c}};return{addAnnotation:r,cancelSelected:s,canRedo:e.canRedo,canUndo:e.canUndo,clearAnnotations:a,getAnnotationById:u,getAnnotations:h,getSelected:v,loadAnnotations:l,redo:e.redo,removeAnnotation:m,setAnnotations:g,setSelected:w,undo:e.undo,updateAnnotation:A}},Fe="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let We=t=>crypto.getRandomValues(new Uint8Array(t)),je=(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 s="";for(;;){let a=n(i),u=i;for(;u--;)if(s+=t[a[u]&o]||"",s.length===r)return s}}},qe=(t,e=21)=>je(t,e,We),Ge=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=Fe[n[t]&63];return e};const Ke=()=>({isGuest:!0,id:qe("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Qe=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}`},zt=t=>t?typeof t=="object"?{...t}:t:void 0,Je=(t,e)=>(Array.isArray(t)?t:[t]).map(n=>{const{id:o,type:i,purpose:r,value:s,created:a,creator:u,...h}=n;return{id:o||`temp-${Qe(n)}`,annotation:e,type:i,purpose:r,value:s,created:a?new Date(a):void 0,creator:zt(u),...h}}),Ze=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()}});Ge();const tn=(t,e)=>({parse:n=>Ft(n),serialize:n=>Wt(n,t,e)}),en=t=>t.quote!==void 0&&t.start!==void 0&&t.end!==void 0,nn=t=>{const{id:e,creator:n,created:o,modified:i,target:r}=t,s=Array.isArray(r)?r:[r],a={creator:zt(n),created:o?new Date(o):void 0,updated:i?new Date(i):void 0,annotation:e,selector:[]};for(const u of s){const v=(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(en(v))a.selector.push({id:u.id,...v});else{const l=[v.start?void 0:"TextPositionSelector",v.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${l.join(" and ")} for annotation: ${t.id}`)}}}return{parsed:a}},Ft=t=>{const e=t.id||Ht(),{creator:n,created:o,modified:i,body:r,...s}=t,a=Je(r,e),u=nn(t);return"error"in u?{error:u.error}:{parsed:{...s,id:e,bodies:a,target:u.parsed}}},Wt=(t,e,n)=>{const{bodies:o,target:i,...r}=t,{selector:s,creator:a,created:u,updated:h,...v}=i,l=s.map(m=>{const{quote:g,start:w,end:A,range:y}=m,{prefix:c,suffix:d}=wt(y,n),f=[{type:"TextQuoteSelector",exact:g,prefix:c,suffix:d},{type:"TextPositionSelector",start:w,end:A}];return{...v,id:m.id,source:e,selector:f}});return{...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:t.id,type:"Annotation",body:Ze(t.bodies),creator:a,created:u==null?void 0:u.toISOString(),modified:h==null?void 0:h.toISOString(),target:l}};function on(t,e,n,o,i){jt(t,e,n||0,o||t.length-1,i||rn)}function jt(t,e,n,o,i){for(;o>n;){if(o-n>600){var r=o-n+1,s=e-n+1,a=Math.log(r),u=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*u*(r-u)/r)*(s-r/2<0?-1:1),v=Math.max(n,Math.floor(e-s*u/r+h)),l=Math.min(o,Math.floor(e+(r-s)*u/r+h));jt(t,e,v,l,i)}var m=t[e],g=n,w=o;for(G(t,n,e),i(t[o],m)>0&&G(t,n,o);g<w;){for(G(t,g,w),g++,w--;i(t[g],m)<0;)g++;for(;i(t[w],m)>0;)w--}i(t[n],m)===0?G(t,n,w):(w++,G(t,w,o)),w<=e&&(n=w+1),e<=w&&(o=w-1)}}function G(t,e,n){var o=t[e];t[e]=t[n],t[n]=o}function rn(t,e){return t<e?-1:t>e?1:0}class sn{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(!ot(e,n))return o;const i=this.toBBox,r=[];for(;n;){for(let s=0;s<n.children.length;s++){const a=n.children[s],u=n.leaf?i(a):a;ot(e,u)&&(n.leaf?o.push(a):pt(e,u)?this._all(a,o):r.push(a))}n=r.pop()}return o}collides(e){let n=this.data;if(!ot(e,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const r=n.children[i],s=n.leaf?this.toBBox(r):r;if(ot(e,s)){if(n.leaf||pt(e,s))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=[],s=[];let a,u,h;for(;o||r.length;){if(o||(o=r.pop(),u=r[r.length-1],a=s.pop(),h=!0),o.leaf){const v=an(e,o.children,n);if(v!==-1)return o.children.splice(v,1),r.push(o),this._condense(r),this}!h&&!o.leaf&&pt(o,i)?(r.push(o),s.push(a),a=0,u=o,o=o.children[0]):u?(a++,o=u.children[a],h=!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 s=this._maxEntries,a;if(r<=s)return a=W(e.slice(n,o+1)),F(a,this.toBBox),a;i||(i=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,i-1))),a=W([]),a.leaf=!1,a.height=i;const u=Math.ceil(r/s),h=u*Math.ceil(Math.sqrt(s));qt(e,n,o,h,this.compareMinX);for(let v=n;v<=o;v+=h){const l=Math.min(v+h-1,o);qt(e,v,l,u,this.compareMinY);for(let m=v;m<=l;m+=u){const g=Math.min(m+u-1,l);a.children.push(this._build(e,m,g,i-1))}}return F(a,this.toBBox),a}_chooseSubtree(e,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let r=1/0,s=1/0,a;for(let u=0;u<n.children.length;u++){const h=n.children[u],v=gt(h),l=dn(e,h)-v;l<s?(s=l,r=v<r?v:r,a=h):l===s&&v<r&&(r=v,a=h)}n=a||n.children[0]}return n}_insert(e,n,o){const i=o?e:this.toBBox(e),r=[],s=this._chooseSubtree(i,this.data,n,r);for(s.children.push(e),Q(s,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 s=this._chooseSplitIndex(o,r,i),a=W(o.children.splice(s,o.children.length-s));a.height=o.height,a.leaf=o.leaf,F(o,this.toBBox),F(a,this.toBBox),n?e[n-1].children.push(a):this._splitRoot(o,a)}_splitRoot(e,n){this.data=W([e,n]),this.data.height=e.height+1,this.data.leaf=!1,F(this.data,this.toBBox)}_chooseSplitIndex(e,n,o){let i,r=1/0,s=1/0;for(let a=n;a<=o-n;a++){const u=K(e,0,a,this.toBBox),h=K(e,a,o,this.toBBox),v=un(u,h),l=gt(u)+gt(h);v<r?(r=v,i=a,s=l<s?l:s):v===r&&l<s&&(s=l,i=a)}return i||o-n}_chooseSplitAxis(e,n,o){const i=e.leaf?this.compareMinX:ln,r=e.leaf?this.compareMinY:cn,s=this._allDistMargin(e,n,o,i),a=this._allDistMargin(e,n,o,r);s<a&&e.children.sort(i)}_allDistMargin(e,n,o,i){e.children.sort(i);const r=this.toBBox,s=K(e,0,n,r),a=K(e,o-n,o,r);let u=nt(s)+nt(a);for(let h=n;h<o-n;h++){const v=e.children[h];Q(s,e.leaf?r(v):v),u+=nt(s)}for(let h=o-n-1;h>=n;h--){const v=e.children[h];Q(a,e.leaf?r(v):v),u+=nt(a)}return u}_adjustParentBBoxes(e,n,o){for(let i=o;i>=0;i--)Q(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():F(e[n],this.toBBox)}}function an(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 F(t,e){K(t,0,t.children.length,e,t)}function K(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 s=t.children[r];Q(i,t.leaf?o(s):s)}return i}function Q(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 ln(t,e){return t.minX-e.minX}function cn(t,e){return t.minY-e.minY}function gt(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function nt(t){return t.maxX-t.minX+(t.maxY-t.minY)}function dn(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 un(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 pt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function ot(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 qt(t,e,n,o,i){const r=[e,n];for(;r.length;){if(n=r.pop(),e=r.pop(),n-e<=o)continue;const s=e+Math.ceil((n-e)/o/2)*o;on(t,s,e,n,i),r.push(e,s,s,n)}}const hn=(t,e)=>{const n=new sn,o=new Map,i=(c,d)=>{const f=c.selector.flatMap(x=>{const T=x.range instanceof Range&&!x.range.collapsed&&x.range.startContainer.nodeType===Node.TEXT_NODE&&x.range.endContainer.nodeType===Node.TEXT_NODE?x.range:it(x,e).range;return Array.from(T.getClientRects())}),b=At(f).map(({left:x,top:R,right:T,bottom:p})=>new DOMRect(x-d.left,R-d.top,T-x,p-R));return b.map(x=>{const{x:R,y:T,width:p,height:S}=x;return{minX:R,minY:T,maxX:R+p,maxY:T+S,annotation:{id:c.annotation,rects:b}}})},r=()=>[...o.values()],s=()=>{n.clear(),o.clear()},a=c=>{const d=i(c,e.getBoundingClientRect());d.forEach(f=>n.insert(f)),o.set(c.annotation,d)},u=c=>{const d=o.get(c.annotation);d&&(d.forEach(f=>n.remove(f)),o.delete(c.annotation))},h=c=>{u(c),a(c)},v=(c,d=!0)=>{d&&s();const f=e.getBoundingClientRect(),b=c.map(R=>({target:R,rects:i(R,f)}));b.forEach(({target:R,rects:T})=>o.set(R.annotation,T));const x=b.reduce((R,{rects:T})=>[...R,...T],[]);n.load(x)},l=(c,d)=>{const f=n.search({minX:c,minY:d,maxX:c,maxY:d}),b=x=>x.annotation.rects.reduce((R,T)=>R+T.width*T.height,0);if(f.length>0)return f.sort((x,R)=>b(x)-b(R)),f[0].annotation.id},m=c=>{const d=g(c);if(d.length===0)return;let f=d[0].left,b=d[0].top,x=d[0].right,R=d[0].bottom;for(let T=1;T<d.length;T++){const p=d[T];f=Math.min(f,p.left),b=Math.min(b,p.top),x=Math.max(x,p.right),R=Math.max(R,p.bottom)}return new DOMRect(f,b,x-f,R-b)},g=c=>{const d=o.get(c);return d?d[0].annotation.rects:[]};return{all:r,clear:s,getAt:l,getAnnotationBounds:m,getAnnotationRects:g,getIntersecting:(c,d,f,b)=>{const x=n.search({minX:c,minY:d,maxX:f,maxY:b}),R=new Set(x.reduce((T,p)=>[...T,p.annotation.id],[]));return Array.from(R).map(T=>({annotation:t.getAnnotation(T),rects:g(T)})).filter(T=>!!T.annotation)},insert:a,recalculate:()=>v(t.all().map(c=>c.target),!0),remove:u,set:v,size:()=>n.all().length,update:h}},Gt=(t,e)=>{const n=Xe(),o=hn(n,t),i=Re(n,e),r=Te(n),s=He(),a=(A,y=B.LOCAL)=>{const c=Z(A,t),d=U(c.target.selector);return d&&n.addAnnotation(c,y),d},u=(A,y=!0,c=B.LOCAL)=>{const d=A.map(b=>Z(b,t)),f=d.filter(b=>!U(b.target.selector));return f.length>0?(console.warn("Could not revive all targets for these annotations:",f),n.bulkAddAnnotation(d,y,c),f):(n.bulkAddAnnotation(d,y,c),[])},h=(A,y=B.LOCAL)=>{const c=A.map(f=>Z(f,t)),d=c.filter(f=>!U(f.target.selector));return d.length>0&&console.warn("Could not revive all targets for these annotations:",d),c.forEach(f=>{n.getAnnotation(f.id)?n.updateAnnotation(f,y):n.addAnnotation(f,y)}),d},v=(A,y=B.LOCAL)=>{const c=j(A,t);n.updateTarget(c,y)},l=(A,y=B.LOCAL)=>{const c=A.map(d=>j(d,t));n.bulkUpdateTargets(c,y)},m=(A,y)=>{const c=o.getAt(A,y);return c?n.getAnnotation(c):void 0},g=(A,y,c,d=5)=>{const f=o.getAnnotationRects(A);if(f.length!==0){if(y&&c){const b=f.find(({top:x,right:R,bottom:T,left:p})=>y>=p-d&&y<=R+d&&c>=x-d&&c<=T+d);if(b)return b}return o.getAnnotationBounds(A)}},w=()=>o.recalculate();return n.observe(({changes:A})=>{const y=(A.created||[]).filter(f=>U(f.target.selector)),c=(A.deleted||[]).filter(f=>U(f.target.selector)),d=(A.updated||[]).filter(f=>U(f.newValue.target.selector));y.length>0&&o.set(y.map(f=>f.target),!1),(c==null?void 0:c.length)>0&&c.forEach(f=>o.remove(f.target)),(d==null?void 0:d.length)>0&&d.forEach(({newValue:f})=>o.update(f.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotation:u,bulkUpdateTargets:l,bulkUpsertAnnotations:h,getAnnotationBounds:g,getAt:m,getIntersecting:o.getIntersecting,recalculatePositions:w,updateTarget:v},selection:i,hover:r,viewport:s}},fn=()=>{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},gn=(t,e,n={})=>{const o=fn(),i=o.getContext("2d");t.appendChild(o);const r=new Map,s=l=>Array.from(r.entries()).filter(([m,g])=>g.presenceKey===l.presenceKey).map(([m,g])=>m);return e.on("selectionChange",(l,m)=>{s(l).forEach(w=>r.delete(w)),m&&m.forEach(w=>r.set(w,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 w=r.get(l.annotation.id);if(w){const{height:A}=l.rects[0],y=l.rects[0].x+m.left,c=l.rects[0].y+m.top;i.fillStyle=w.appearance.color,i.fillRect(y-2,c-2.5,2,A+5);const d=i.measureText(w.appearance.label),f=d.width+6,b=d.actualBoundingBoxAscent+d.actualBoundingBoxDescent+8,x=d.fontBoundingBoxAscent?8:6.5;return i.fillRect(y-2,c-2.5-b,f,b),i.fillStyle="#fff",i.fillText(w.appearance.label,y+1,c-x),{fill:w.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)}}},Kt=t=>{if(t===null)return document.scrollingElement;const{overflowY:e}=window.getComputedStyle(t);return e!=="visible"&&e!=="hidden"&&t.scrollHeight>t.clientHeight?t:Kt(t.parentElement)},pn=(t,e)=>n=>{const o=r=>{const s=i.getBoundingClientRect(),a=i.clientHeight,u=i.clientWidth,h=r.selector[0].range.getBoundingClientRect(),{width:v,height:l}=e.getAnnotationBounds(n.id),m=h.top-s.top,g=h.left-s.left,w=i.parentElement?i.scrollTop:0,A=i.parentElement?i.scrollLeft:0,y=m+w-(a-l)/2,c=g+A-(u-v)/2;i.scroll({top:y,left:c,behavior:"smooth"})},i=Kt(t);if(i){const r=e.getAnnotation(n.id),{range:s}=r.target.selector[0];if(s&&!s.collapsed)return o(r.target),!0;{const a=j(r.target,t),{range:u}=a.selector[0];if(u&&!u.collapsed)return o(a),!0}}return!1},mn=(t,e,n)=>{const{store:o,selection:i}=e;let r,s;const a=A=>r=A;let u=!1,h;const v=A=>{var c;if(!u)return;!((c=A.target.parentElement)!=null&&c.closest(H))?s={annotation:Ht(),selector:[],creator:r,created:new Date}:s=void 0};t.addEventListener("selectstart",v);const l=D(A=>{const y=document.getSelection();if(A.timeStamp-((h==null?void 0:h.timeStamp)||A.timeStamp)<1e3&&!s&&v(h),y.isCollapsed||!u||!s)return;const c=y.getRangeAt(0),d=Et(c.cloneRange()),f=bt(d);(f.length!==s.selector.length||f.some((x,R)=>{var T;return x.toString()!==((T=s.selector[R])==null?void 0:T.quote)}))&&(s={...s,selector:f.map(x=>xt(x,t,n))},o.getAnnotation(s.annotation)?o.updateTarget(s,B.LOCAL):(o.addAnnotation({id:s.annotation,bodies:[],target:s}),i.clickSelect(s.annotation,h)))});document.addEventListener("selectionchange",l);const m=A=>{const{target:y,timeStamp:c,offsetX:d,offsetY:f,type:b}=A;h={...A,target:y,timeStamp:c,offsetX:d,offsetY:f,type:b},u=A.button===0};t.addEventListener("pointerdown",m);const g=A=>{var f;if(!!((f=A.target.parentElement)!=null&&f.closest(H))||!u)return;const c=()=>{const{x:b,y:x}=t.getBoundingClientRect(),R=o.getAt(A.clientX-b,A.clientY-x);if(R){const{selected:T}=i;(T.length!==1||T[0].id!==R.id)&&i.clickSelect(R.id,A)}else i.isEmpty()||i.clear()},d=A.timeStamp-h.timeStamp;document.getSelection().isCollapsed&&d<300?(s=void 0,c()):s&&i.clickSelect(s.annotation,A)};return document.addEventListener("pointerup",g),{destroy:()=>{t.removeEventListener("selectstart",v),document.removeEventListener("selectionchange",l),t.removeEventListener("pointerdown",m),document.removeEventListener("pointerup",g)},setUser:a}},Qt="SPANS",bn=(t,e={})=>{t.addEventListener("click",x=>!x.target.closest("a")&&x.preventDefault());const n=Gt(t,e.pointerAction),{selection:o,viewport:i}=n,r=n.store,s=De(r),a=$e(n,s,e.adapter);let u=Ke();const h=e.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":Qt:e.renderer||Qt,v=h==="SPANS"?Yt(t,n,i):h==="CSS_HIGHLIGHTS"?Xt(t,n,i):h==="CANVAS"?St(t,n,i):void 0;if(!v)throw`Unknown renderer implementation: ${h}`;console.log(`Using ${h} renderer`),e.style&&v.setStyle(e.style);const l=mn(t,n,e.offsetReferenceSelector);return l.setUser(u),{...ze(n,s,e.adapter),destroy:()=>{v.destroy(),l.destroy(),s.destroy()},element:t,getUser:()=>u,setFilter:x=>v.setFilter(x),setStyle:x=>v.setStyle(x),setUser:x=>{u=x,l.setUser(x)},setSelected:x=>{x?o.setSelected(x):o.clear()},setPresenceProvider:x=>{x&&(v.setPainter(gn(t,x,e.presence)),x.on("selectionChange",()=>v.redraw(!0)))},setVisible:x=>v.setVisible(x),on:a.on,off:a.off,scrollIntoView:pn(t,r),state:n}};N.NOT_ANNOTATABLE_SELECTOR=H,N.Origin=B,N.W3CTextFormat=tn,N.createCanvasRenderer=St,N.createHighlightsRenderer=Xt,N.createRenderer=Ut,N.createSpansRenderer=Yt,N.createTextAnnotator=bn,N.createTextAnnotatorState=Gt,N.debounce=D,N.getAnnotatableFragment=te,N.getClientRectsPonyfill=oe,N.getQuoteContext=wt,N.getRangeAnnotatableContents=J,N.isRevived=U,N.mergeClientRects=At,N.parseW3CTextAnnotation=Ft,N.rangeToSelector=xt,N.reviveAnnotation=Z,N.reviveSelector=it,N.reviveTarget=j,N.serializeW3CTextAnnotation=Wt,N.splitAnnotatableRanges=bt,N.trimRange=Et,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
1
+ (function(X,z){typeof exports=="object"&&typeof module<"u"?z(exports):typeof define=="function"&&define.amd?define(["exports"],z):(X=typeof globalThis<"u"?globalThis:X||self,z(X.RecogitoJS={}))})(this,function(X){"use strict";const z={fill:"rgb(0, 128, 255",fillOpacity:.18},gt={fill:"rgb(0, 128, 255)",fillOpacity:.45},G={paint:(e,t,n,o,i,s)=>{const r=s?typeof s=="function"?s(e,i):s:i?gt:z;n.fillStyle=r.fill,n.globalAlpha=r.fillOpacity||1,t.forEach(({x:c,y:u,width:d,height:m})=>n.fillRect(c,u-2.5,d,m+5))}},pt=e=>{let t=new Set;return o=>{const i=o.map(s=>s.id);(t.size!==i.length||i.some(s=>!t.has(s)))&&e.set(i),t=new Set(i)}},Ae="",mt=(e,t=10)=>{let n;return(...o)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,o),t)}},et=(e,t)=>{const n=document.createElement("canvas");if(n.width=t?2*window.innerWidth:window.innerWidth,n.height=t?2*window.innerHeight:window.innerHeight,n.className=e,t){const o=n.getContext("2d");o.scale(2,2),o.translate(.5,.5)}return n},nt=(e,t)=>{if(e.width=t?2*window.innerWidth:window.innerWidth,e.height=t?2*window.innerHeight:window.innerHeight,t){const n=e.getContext("2d");n.scale(2,2),n.translate(.5,.5)}},ot=(e,t,n)=>{const{store:o,selection:i,hover:s}=t;let r,c,u=G;const d=pt(n);e.classList.add("r6o-annotatable");const m=et("r6o-highlight-layer bg"),f=et("r6o-highlight-layer fg",!0),x=m.getContext("2d"),C=f.getContext("2d");e.insertBefore(m,e.firstChild),e.appendChild(f),e.addEventListener("pointermove",g=>{const{x:E,y:R}=e.getBoundingClientRect(),M=o.getAt(g.clientX-E,g.clientY-R);M&&(!c||c(M))?s.current!==M.id&&(e.classList.add("hovered"),s.set(M.id)):s.current&&(e.classList.remove("hovered"),s.set(null))});const v=()=>{const{top:g,left:E}=e.getBoundingClientRect(),{innerWidth:R,innerHeight:M}=window,U=-E,p=-g,w=R-E,y=M-g;return{top:g,left:E,minX:U,minY:p,maxX:w,maxY:y}},B=()=>h();document.addEventListener("scroll",B,{capture:!0,passive:!0});const b=mt(()=>{nt(m),nt(f,!0),o.recalculatePositions(),h()});window.addEventListener("resize",b),new ResizeObserver(b).observe(e);const h=()=>requestAnimationFrame(()=>{const{top:g,left:E,minX:R,minY:M,maxX:U,maxY:p}=v(),w=c?o.getIntersectingRects(R,M,U,p).filter(({annotation:O})=>c(O)):o.getIntersectingRects(R,M,U,p),{width:y,height:T}=f,S=new Set(i.selected.map(({id:O})=>O));C.clearRect(-.5,-.5,y+1,T+1),x.clearRect(-.5,-.5,y+1,T+1),w.forEach(({annotation:O,rects:Y})=>{const he=Y.map(({x:fe,y:ge,width:pe,height:me})=>({x:fe+E,y:ge+g,width:pe,height:me})),ue=S.has(O.id);u.paint(O,he,x,C,ue,r)}),setTimeout(()=>d(w.map(({annotation:O})=>O)),1)});return o.observe(()=>h()),i.subscribe(()=>h()),{redraw:h,setDrawingStyle:g=>{r=g,h()},setFilter:g=>{c=g,h()},setPainter:g=>u=g}},_=(e,t)=>{const{start:n,end:o}=e.selector,i=e.selector.offsetReference?e.selector.offsetReference:t;if(!i)return e;const s=document.createNodeIterator(t,NodeFilter.SHOW_TEXT);let r=0,c=document.createRange(),u=s.nextNode();u===null&&console.error("Could not revive annotation target. Content missing.");let d=!i;for(;u!==null;){const m=u.textContent.length;if(!d&&i&&(d=i.contains(u)),d){if(r+m>n){c.setStart(u,n-r);break}r+=m}u=s.nextNode()}for(;u!==null;){const m=u.textContent.length;if(r+m>o){c.setEnd(u,o-r);break}r+=m,u=s.nextNode()}return{...e,selector:{...e.selector,range:c}}};var it=Object.prototype.hasOwnProperty;function D(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&D(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(it.call(e,n)&&++o&&!it.call(t,n)||!(n in t)||!D(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function J(){}function At(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const N=[];function K(e,t=J){let n;const o=new Set;function i(c){if(At(e,c)&&(e=c,n)){const u=!N.length;for(const d of o)d[1](),N.push(d,e);if(u){for(let d=0;d<N.length;d+=2)N[d][0](N[d+1]);N.length=0}}}function s(c){i(c(e))}function r(c,u=J){const d=[c,u];return o.add(d),o.size===1&&(n=t(i,s)||J),c(e),()=>{o.delete(d),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const xt=e=>{const{subscribe:t,set:n}=K(null);let o=null;return t(i=>o=i),e.observe(({changes:i})=>{if(o){i.deleted.some(c=>c.id===o)&&n(null);const r=i.updated.find(({oldValue:c})=>c.id===o);r&&n(r.newValue.id)}}),{get current(){return o},subscribe:t,set:n}},Q={selected:[]},wt=(e,t="EDIT")=>{const{subscribe:n,set:o}=K(Q);let i=Q;n(f=>i=f);const s=()=>o(Q),r=()=>{var f;return((f=i.selected)==null?void 0:f.length)===0},c=f=>{if(i.selected.length===0)return!1;const x=typeof f=="string"?f:f.id;return i.selected.some(C=>C.id===x)},u=(f,x)=>{const C=e.getAnnotation(f);if(C){const v=yt(C,t);o(v==="EDIT"?{selected:[{id:f,editable:!0}],pointerEvent:x}:v==="SELECT"?{selected:[{id:f}],pointerEvent:x}:{selected:[],pointerEvent:x})}else console.warn("Invalid selection: "+f)},d=(f,x=!0)=>{const C=Array.isArray(f)?f:[f],v=C.map(B=>e.getAnnotation(B)).filter(B=>B);o({selected:v.map(({id:B})=>({id:B,editable:x}))}),v.length!==C.length&&console.warn("Invalid selection",f)},m=f=>{if(i.selected.length===0)return!1;const{selected:x}=i;x.filter(({id:v})=>f.includes(v)).length>0&&o({selected:x.filter(({id:v})=>!f.includes(v))})};return e.observe(({changes:f})=>m(f.deleted.map(x=>x.id))),{clear:s,clickSelect:u,get selected(){return i?[...i.selected]:null},get pointerEvent(){return i?i.pointerEvent:null},isEmpty:r,isSelected:c,setSelected:d,subscribe:n}},yt=(e,t)=>typeof t=="function"?t(e)||"EDIT":t||"EDIT";let F;const bt=new Uint8Array(16);function Et(){if(!F&&(F=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!F))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return F(bt)}const I=[];for(let e=0;e<256;++e)I.push((e+256).toString(16).slice(1));function vt(e,t=0){return I[e[t+0]]+I[e[t+1]]+I[e[t+2]]+I[e[t+3]]+"-"+I[e[t+4]]+I[e[t+5]]+"-"+I[e[t+6]]+I[e[t+7]]+"-"+I[e[t+8]]+I[e[t+9]]+"-"+I[e[t+10]]+I[e[t+11]]+I[e[t+12]]+I[e[t+13]]+I[e[t+14]]+I[e[t+15]]}const st={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Tt(e,t,n){if(st.randomUUID&&!t&&!e)return st.randomUUID();e=e||{};const o=e.random||(e.rng||Et)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,t){n=n||0;for(let i=0;i<16;++i)t[n+i]=o[i];return t}return vt(o)}const Ct=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},St=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Bt=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!D(o,n)?o:void 0}}).filter(({oldBody:n})=>n),Rt=(e,t)=>!D(e.target,t.target),rt=(e,t)=>{const n=Ct(e,t),o=St(e,t),i=Bt(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Rt(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var L=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e))(L||{});const Lt=(e,t)=>{var s,r;const{changes:n,origin:o}=t;if(!(!e.options.origin||e.options.origin===o))return!1;if(e.options.ignore){const{ignore:c}=e.options,u=m=>(m==null?void 0:m.length)>0;if(!(u(n.created)||u(n.deleted))){const m=(s=n.updated)==null?void 0:s.some(x=>u(x.bodiesCreated)||u(x.bodiesDeleted)||u(x.bodiesUpdated)),f=(r=n.updated)==null?void 0:r.some(x=>x.targetUpdated);if(c==="BODY_ONLY"&&m&&!f||c==="TARGET_ONLY"&&f&&!m)return!1}}if(e.options.annotations){const c=new Set([...n.created.map(d=>d.id),...n.deleted.map(d=>d.id),...n.updated.map(({oldValue:d})=>d.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(d=>c.has(d))}else return!0},Mt=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),c=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),u=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:x})=>x.id===f.id).newValue:f),...t.created||[]],d=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],m=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:x,newValue:C}=f;if(r.has(C.id)){const v=t.updated.find(B=>B.oldValue.id===C.id).newValue;return rt(x,v)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!c.has(f.id))];return{created:u,deleted:d,updated:m}},Ot=e=>e.id!==void 0,Xt=()=>{const e=new Map,t=new Map,n=[],o=(p,w={})=>n.push({onChange:p,options:w}),i=p=>{const w=n.findIndex(y=>y.onChange==p);w>-1&&n.splice(w,1)},s=(p,w)=>{const y={origin:p,changes:{created:w.created||[],updated:w.updated||[],deleted:w.deleted||[]},state:[...e.values()]};n.forEach(T=>{Lt(T,y)&&T.onChange(y)})},r=(p,w=L.LOCAL)=>{if(e.get(p.id))throw Error(`Cannot add annotation ${p.id} - exists already`);e.set(p.id,p),p.bodies.forEach(T=>t.set(T.id,p.id)),s(w,{created:[p]})},c=(p,w)=>{const y=typeof p=="string"?w:p,T=typeof p=="string"?p:p.id,S=e.get(T);if(S){const O=rt(S,y);return T===y.id?e.set(T,y):(e.delete(T),e.set(y.id,y)),S.bodies.forEach(Y=>t.delete(Y.id)),y.bodies.forEach(Y=>t.set(Y.id,y.id)),O}else console.warn(`Cannot update annotation ${T} - does not exist`)},u=(p,w=L.LOCAL,y=L.LOCAL)=>{const T=Ot(w)?y:w,S=c(p,w);S&&s(T,{updated:[S]})},d=(p,w=L.LOCAL)=>{const y=p.reduce((T,S)=>{const O=c(S);return O?[...T,O]:T},[]);y.length>0&&s(w,{updated:y})},m=(p,w=L.LOCAL)=>{const y=e.get(p.annotation);if(y){const T={...y,bodies:[...y.bodies,p]};e.set(y.id,T),t.set(p.id,T.id),s(w,{updated:[{oldValue:y,newValue:T,bodiesCreated:[p]}]})}else console.warn(`Attempt to add body to missing annotation: ${p.annotation}`)},f=()=>[...e.values()],x=(p=L.LOCAL)=>{const w=[...e.values()];e.clear(),t.clear(),s(p,{deleted:w})},C=(p,w=!0,y=L.LOCAL)=>{if(w){const T=[...e.values()];e.clear(),t.clear(),p.forEach(S=>{e.set(S.id,S),S.bodies.forEach(O=>t.set(O.id,S.id))}),s(y,{created:p,deleted:T})}else{const T=p.reduce((S,O)=>{const Y=e.get(O.id);return Y?[...S,Y]:S},[]);if(T.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${T.map(S=>S.id).join(", ")}`);p.forEach(S=>{e.set(S.id,S),S.bodies.forEach(O=>t.set(O.id,S.id))}),s(y,{created:p})}},v=p=>{const w=typeof p=="string"?p:p.id,y=e.get(w);if(y)return e.delete(w),y.bodies.forEach(T=>t.delete(T.id)),y;console.warn(`Attempt to delete missing annotation: ${w}`)},B=(p,w=L.LOCAL)=>{const y=v(p);y&&s(w,{deleted:[y]})},b=(p,w=L.LOCAL)=>{const y=p.reduce((T,S)=>{const O=v(S);return O?[...T,O]:T},[]);y.length>0&&s(w,{deleted:y})},l=(p,w=L.LOCAL)=>{const y=e.get(p.annotation);if(y){const T=y.bodies.find(S=>S.id===p.id);if(T){t.delete(T.id);const S={...y,bodies:y.bodies.filter(Y=>Y.id!==p.id)};e.set(y.id,S),s(w,{updated:[{oldValue:y,newValue:S,bodiesDeleted:[T]}]})}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}`)},h=p=>{const w=e.get(p);return w?{...w}:void 0},a=p=>{const w=t.get(p);if(w){const T=h(w).bodies.find(S=>S.id===p);if(T)return T;console.error(`Store integrity error: body ${p} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${p}`)},A=(p,w)=>{if(p.annotation!==w.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const y=e.get(p.annotation);if(y){const T=y.bodies.find(O=>O.id===p.id),S={...y,bodies:y.bodies.map(O=>O.id===T.id?w:O)};return e.set(y.id,S),T.id!==w.id&&(t.delete(T.id),t.set(w.id,S.id)),{oldValue:y,newValue:S,bodiesUpdated:[{oldBody:T,newBody:w}]}}else console.warn(`Attempt to add body to missing annotation ${p.annotation}`)},g=(p,w,y=L.LOCAL)=>{const T=A(p,w);s(y,{updated:[T]})},E=(p,w=L.LOCAL)=>{const y=p.map(T=>A({id:T.id,annotation:T.annotation},T));s(w,{updated:y})},R=p=>{const w=e.get(p.annotation);if(w){const y={...w,target:{...w.target,...p}};return e.set(w.id,y),{oldValue:w,newValue:y,targetUpdated:{oldTarget:w.target,newTarget:p}}}else console.warn(`Attempt to update target on missing annotation: ${p.annotation}`)};return{addAnnotation:r,addBody:m,all:f,bulkAddAnnotation:C,bulkDeleteAnnotation:b,bulkUpdateAnnotation:d,bulkUpdateBodies:E,bulkUpdateTargets:(p,w=L.LOCAL)=>{const y=p.map(R).filter(T=>T);y.length>0&&s(w,{updated:y})},clear:x,deleteAnnotation:B,deleteBody:l,getAnnotation:h,getBody:a,observe:o,unobserve:i,updateAnnotation:u,updateBody:g,updateTarget:(p,w=L.LOCAL)=>{const y=R(p);y&&s(w,{updated:[y]})}}};let It=()=>({emit(e,...t){let n=this.events[e]||[];for(let o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return(n=this.events[e])!=null&&n.push(t)||(this.events[e]=[t]),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const Ut=250,Yt=e=>{const t=It(),n=[];let o=-1,i=!1,s=0;const r=a=>{if(!i){const{changes:A}=a,g=performance.now();if(g-s>Ut)n.splice(o+1),n.push(A),o=n.length-1;else{const E=n.length-1;n[E]=Mt(n[E],A)}s=g}i=!1};e.observe(r,{origin:L.LOCAL});const c=a=>(a==null?void 0:a.length)>0&&e.bulkDeleteAnnotation(a),u=a=>(a==null?void 0:a.length)>0&&e.bulkAddAnnotation(a,!1),d=a=>(a==null?void 0:a.length)>0&&e.bulkUpdateAnnotation(a.map(({oldValue:A})=>A)),m=a=>(a==null?void 0:a.length)>0&&e.bulkUpdateAnnotation(a.map(({newValue:A})=>A)),f=a=>(a==null?void 0:a.length)>0&&e.bulkAddAnnotation(a,!1),x=a=>(a==null?void 0:a.length)>0&&e.bulkDeleteAnnotation(a);return{canRedo:()=>n.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(r),on:(a,A)=>t.on(a,A),redo:()=>{if(n.length-1>o){i=!0;const{created:a,updated:A,deleted:g}=n[o+1];u(a),m(A),x(g),t.emit("redo",n[o+1]),o+=1}},undo:()=>{if(o>-1){i=!0;const{created:a,updated:A,deleted:g}=n[o];c(a),d(A),f(g),t.emit("undo",n[o]),o-=1}}}},Dt=()=>{const{subscribe:e,set:t}=K([]);return{subscribe:e,set:t}},_t=(e,t,n,o)=>{const{store:i,selection:s,hover:r,viewport:c}=e,u=new Map;let d=[],m,f;const x=(l,h)=>{u.has(l)?u.get(l).push(h):u.set(l,[h])},C=(l,h)=>{const a=u.get(l);a&&a.indexOf(h)>0&&a.splice(a.indexOf(h),1)},v=(l,h,a)=>{u.has(l)&&setTimeout(()=>{u.get(l).forEach(A=>{if(n){const g=Array.isArray(h)?h.map(R=>n.serialize(R)):n.serialize(h),E=a?a instanceof PointerEvent?a:n.serialize(a):void 0;A(g,E)}else A(h,a)})},1)},B=()=>{const{selected:l}=s,h=l.map(({id:a})=>i.getAnnotation(a));h.forEach(a=>{const A=d.find(g=>g.id===a.id);(!A||!D(A,a))&&v("updateAnnotation",a,A)}),d=d.map(a=>{const A=h.find(({id:g})=>g===a.id);return A||a})};s.subscribe(({selected:l})=>{if(!(d.length===0&&l.length===0)){if(d.length===0&&l.length>0)d=l.map(({id:h})=>i.getAnnotation(h));else if(d.length>0&&l.length===0)d.forEach(h=>{const a=i.getAnnotation(h.id);a&&!D(a,h)&&v("updateAnnotation",a,h)}),d=[];else{const h=new Set(d.map(g=>g.id)),a=new Set(l.map(({id:g})=>g));d.filter(g=>!a.has(g.id)).forEach(g=>{const E=i.getAnnotation(g.id);E&&!D(E,g)&&v("updateAnnotation",E,g)}),d=[...d.filter(g=>a.has(g.id)),...l.filter(({id:g})=>!h.has(g)).map(({id:g})=>i.getAnnotation(g))]}v("selectionChanged",d)}}),r.subscribe(l=>{!m&&l?v("mouseEnterAnnotation",i.getAnnotation(l)):m&&!l?v("mouseLeaveAnnotation",i.getAnnotation(m)):m&&l&&(v("mouseLeaveAnnotation",i.getAnnotation(m)),v("mouseEnterAnnotation",i.getAnnotation(l))),m=l}),c==null||c.subscribe(l=>v("viewportIntersect",l.map(i.getAnnotation))),i.observe(l=>{o&&(f&&clearTimeout(f),f=setTimeout(B,1e3));const{created:h,deleted:a}=l.changes;h.forEach(g=>v("createAnnotation",g)),a.forEach(g=>v("deleteAnnotation",g)),l.changes.updated.filter(g=>[...g.bodiesCreated||[],...g.bodiesDeleted||[],...g.bodiesUpdated||[]].length>0).forEach(({oldValue:g,newValue:E})=>{const R=d.find(M=>M.id===g.id)||g;d=d.map(M=>M.id===g.id?E:M),v("updateAnnotation",E,R)})},{origin:L.LOCAL}),i.observe(l=>{if(d){const h=new Set(d.map(A=>A.id)),a=l.changes.updated.filter(({newValue:A})=>h.has(A.id)).map(({newValue:A})=>A);a.length>0&&(d=d.map(A=>{const g=a.find(E=>E.id===A.id);return g||A}))}},{origin:L.REMOTE});const b=l=>h=>{const{created:a,deleted:A,updated:g}=h;a.forEach(E=>v("createAnnotation",E)),A.forEach(E=>v("deleteAnnotation",E)),l?g.forEach(E=>v("updateAnnotation",E.oldValue,E.newValue)):g.forEach(E=>v("updateAnnotation",E.newValue,E.oldValue))};return t.on("undo",b(!0)),t.on("redo",b(!1)),{on:x,off:C,emit:v}},Nt=e=>t=>t.map(n=>e.serialize(n)),at=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:{parsed:[...n.parsed,i],failed:n.failed}},{parsed:[],failed:[]}),ct=(e,t,n)=>{const{store:o,selection:i}=e,s=b=>{if(n){const{parsed:l,error:h}=n.parse(b);l?o.addAnnotation(l,L.REMOTE):console.error(h)}else o.addAnnotation(b,L.REMOTE)},r=()=>i.clear(),c=()=>o.clear(),u=b=>{const l=o.getAnnotation(b);return n&&l?n.serialize(l):l},d=()=>n?o.all().map(n.serialize):o.all(),m=()=>{var h;const l=(((h=i.selected)==null?void 0:h.map(a=>a.id))||[]).map(a=>o.getAnnotation(a));return n?l.map(n.serialize):l},f=b=>fetch(b).then(l=>l.json()).then(l=>(C(l),l)),x=b=>{if(typeof b=="string"){const l=o.getAnnotation(b);return o.deleteAnnotation(b),n?n.serialize(l):l}else{const l=n?n.parse(b).parsed:b;return o.deleteAnnotation(l),b}},C=b=>{if(n){const{parsed:l,failed:h}=at(n)(b);h.length>0&&console.warn(`Discarded ${h.length} invalid annotations`,h),o.bulkAddAnnotation(l,!0,L.REMOTE)}else o.bulkAddAnnotation(b,!0,L.REMOTE)},v=b=>{b?i.setSelected(b):i.clear()},B=b=>{if(n){const l=n.parse(b).parsed,h=n.serialize(o.getAnnotation(l.id));return o.updateAnnotation(l),h}else{const l=o.getAnnotation(b.id);return o.updateAnnotation(b),l}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:c,getAnnotationById:u,getAnnotations:d,getSelected:m,loadAnnotations:f,redo:t.redo,removeAnnotation:x,setAnnotations:C,setSelected:v,undo:t.undo,updateAnnotation:B}};let kt=e=>crypto.getRandomValues(new Uint8Array(e)),Vt=(e,t,n)=>{let o=(2<<Math.log(e.length-1)/Math.LN2)-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let c=n(i),u=i;for(;u--;)if(r+=e[c[u]&o]||"",r.length===s)return r}}},zt=(e,t=21)=>Vt(e,t,kt),Pt=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const lt=()=>({isGuest:!0,id:zt("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Ht=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Wt=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:c,creator:u,...d}=n;return{id:o||`temp-${Ht(n)}`,annotation:t,type:i,purpose:s,value:r,created:c,creator:u?typeof u=="object"?{...u}:u:void 0,...d}}),Ft=e=>e.map(t=>{var o;const n={...t};return delete n.annotation,(o=n.id)!=null&&o.startsWith("temp-")&&delete n.id,n});Pt();function $t(e,t,n,o,i){dt(e,t,n||0,o||e.length-1,i||qt)}function dt(e,t,n,o,i){for(;o>n;){if(o-n>600){var s=o-n+1,r=t-n+1,c=Math.log(s),u=.5*Math.exp(2*c/3),d=.5*Math.sqrt(c*u*(s-u)/s)*(r-s/2<0?-1:1),m=Math.max(n,Math.floor(t-r*u/s+d)),f=Math.min(o,Math.floor(t+(s-r)*u/s+d));dt(e,t,m,f,i)}var x=e[t],C=n,v=o;for(P(e,n,t),i(e[o],x)>0&&P(e,n,o);C<v;){for(P(e,C,v),C++,v--;i(e[C],x)<0;)C++;for(;i(e[v],x)>0;)v--}i(e[n],x)===0?P(e,n,v):(v++,P(e,v,o)),v<=t&&(n=v+1),t<=v&&(o=v-1)}}function P(e,t,n){var o=e[t];e[t]=e[n],e[n]=o}function qt(e,t){return e<t?-1:e>t?1:0}class jt{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!q(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const c=n.children[r],u=n.leaf?i(c):c;q(t,u)&&(n.leaf?o.push(c):tt(t,u)?this._all(c,o):s.push(c))}n=s.pop()}return o}collides(t){let n=this.data;if(!q(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(q(t,r)){if(n.leaf||tt(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.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(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=V([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let c,u,d;for(;o||s.length;){if(o||(o=s.pop(),u=s[s.length-1],c=r.pop(),d=!0),o.leaf){const m=Gt(t,o.children,n);if(m!==-1)return o.children.splice(m,1),s.push(o),this._condense(s),this}!d&&!o.leaf&&tt(o,i)?(s.push(o),r.push(c),c=0,u=o,o=o.children[0]):u?(c++,o=u.children[c],d=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,c;if(s<=r)return c=V(t.slice(n,o+1)),k(c,this.toBBox),c;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),c=V([]),c.leaf=!1,c.height=i;const u=Math.ceil(s/r),d=u*Math.ceil(Math.sqrt(r));ht(t,n,o,d,this.compareMinX);for(let m=n;m<=o;m+=d){const f=Math.min(m+d-1,o);ht(t,m,f,u,this.compareMinY);for(let x=m;x<=f;x+=u){const C=Math.min(x+u-1,f);c.children.push(this._build(t,x,C,i-1))}}return k(c,this.toBBox),c}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,c;for(let u=0;u<n.children.length;u++){const d=n.children[u],m=Z(d),f=Qt(t,d)-m;f<r?(r=f,s=m<s?m:s,c=d):f===r&&m<s&&(s=m,c=d)}n=c||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),W(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),c=V(o.children.splice(r,o.children.length-r));c.height=o.height,c.leaf=o.leaf,k(o,this.toBBox),k(c,this.toBBox),n?t[n-1].children.push(c):this._splitRoot(o,c)}_splitRoot(t,n){this.data=V([t,n]),this.data.height=t.height+1,this.data.leaf=!1,k(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let c=n;c<=o-n;c++){const u=H(t,0,c,this.toBBox),d=H(t,c,o,this.toBBox),m=Zt(u,d),f=Z(u)+Z(d);m<s?(s=m,i=c,r=f<r?f:r):m===s&&f<r&&(r=f,i=c)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Jt,s=t.leaf?this.compareMinY:Kt,r=this._allDistMargin(t,n,o,i),c=this._allDistMargin(t,n,o,s);r<c&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=H(t,0,n,s),c=H(t,o-n,o,s);let u=$(r)+$(c);for(let d=n;d<o-n;d++){const m=t.children[d];W(r,t.leaf?s(m):m),u+=$(r)}for(let d=o-n-1;d>=n;d--){const m=t.children[d];W(c,t.leaf?s(m):m),u+=$(c)}return u}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)W(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():k(t[n],this.toBBox)}}function Gt(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function k(e,t){H(e,0,e.children.length,t,e)}function H(e,t,n,o,i){i||(i=V(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];W(i,e.leaf?o(r):r)}return i}function W(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Jt(e,t){return e.minX-t.minX}function Kt(e,t){return e.minY-t.minY}function Z(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function $(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Qt(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Zt(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function tt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function q(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function V(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ht(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;$t(e,r,t,n,i),s.push(t,r,r,n)}}const te=(e,t)=>{const n=s=>Math.round(s*10)/10,o={top:n(e.top),bottom:n(e.bottom),left:n(e.left),right:n(e.right)},i={top:n(t.top),bottom:n(t.bottom),left:n(t.left),right:n(t.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"},ee=(e,t)=>{const n=Math.min(e.left,t.left),o=Math.max(e.right,t.right),i=Math.min(e.top,t.top),s=Math.max(e.bottom,t.bottom);return new DOMRect(n,i,o-n,s-i)},ne=e=>e.reduce((t,n)=>{if(n.width===0||n.height===0)return t;let o=[...t],i=!1;for(const s of t){const r=te(n,s);if(r==="inline-adjacent"){o=o.map(c=>c===s?ee(n,s):c),i=!0;break}else if(r==="inline-contains"){o=o.map(c=>c===s?n:c),i=!0;break}else if(r==="inline-is-contained"){i=!0;break}else if(r==="block-contains"||r==="block-is-contained"){n.width<s.width&&(o=o.map(c=>c===s?n:c)),i=!0;break}}return i?o:[...o,n]},[]),oe=e=>{const{startContainer:t,endContainer:n}=e;if(t.nodeType===Node.TEXT_NODE&&n.nodeType===Node.TEXT_NODE)return e;if(t.nodeType!==Node.TEXT_NODE){const i=t.nextSibling||t.parentNode,s=i.nodeType===Node.TEXT_NODE?i:Array.from(i.childNodes).filter(r=>r.nodeType===Node.TEXT_NODE).shift();e.setEnd(s,0)}if(n.nodeType!==Node.TEXT_NODE){const i=n.previousSibling||n.parentNode,s=i.nodeType===Node.TEXT_NODE?i:Array.from(i.childNodes).filter(r=>r.nodeType===Node.TEXT_NODE).pop();e.setEnd(s,s.textContent.length)}return e},ie=(e,t)=>{const n=new jt,o=new Map,i=l=>{const h=t.getBoundingClientRect(),A=l.selector.range instanceof Range&&!l.selector.range.collapsed&&l.selector.range.startContainer.nodeType===Node.TEXT_NODE&&l.selector.range.endContainer.nodeType===Node.TEXT_NODE?l:_(l,t),g=Array.from(A.selector.range.getClientRects()),E=ne(g);return E.map(R=>{const{x:M,y:U,width:p,height:w}=R;return{minX:M-h.x,minY:U-h.y,maxX:M-h.x+p,maxY:U-h.y+w,annotation:{id:l.annotation,rects:E}}})},s=()=>[...o.values()],r=()=>{n.clear(),o.clear()},c=l=>{const h=i(l);h.forEach(a=>n.insert(a)),o.set(l.annotation,h)},u=l=>{o.get(l.annotation).forEach(a=>n.remove(a)),o.delete(l.annotation)},d=l=>{u(l),c(l)},m=(l,h=!0)=>{h&&r();const a=l.map(g=>({target:g,rects:i(g)}));a.forEach(({target:g,rects:E})=>o.set(g.annotation,E));const A=a.reduce((g,{rects:E})=>[...g,...E],[]);n.load(A)},f=(l,h)=>{const a=n.search({minX:l,minY:h,maxX:l,maxY:h}),A=g=>g.annotation.rects.reduce((E,R)=>E+R.width*R.height,0);if(a.length>0)return a.sort((g,E)=>A(g)-A(E)),a[0].annotation.id},x=l=>{const h=C(l);if(h.length===0)return;let a=h[0].left,A=h[0].top,g=h[0].right,E=h[0].bottom;for(let R=1;R<h.length;R++){const M=h[R];a=Math.min(a,M.left),A=Math.min(A,M.top),g=Math.max(g,M.right),E=Math.max(E,M.bottom)}return new DOMRect(a,A,g-a,E-A)},C=l=>{const h=o.get(l);return h?h[0].annotation.rects:[]};return{all:s,clear:r,getAt:f,getBoundsForAnnotation:x,getDOMRectsForAnnotation:C,getIntersectingRects:(l,h,a,A)=>n.search({minX:l,minY:h,maxX:a,maxY:A}),insert:c,recalculate:()=>m(e.all().map(l=>l.target),!0),remove:u,set:m,size:()=>n.all().length,update:d}},j=e=>{const{range:t}=e.target.selector;return t instanceof Range&&!t.collapsed},ut=(e,t)=>{const n=Xt(),o=ie(n,e),i=wt(n,t),s=xt(n),r=Dt(),c=(b,l=L.LOCAL)=>{const h=b.target.selector.range instanceof Range?b:{...b,target:_(b.target,e)},{range:a}=h.target.selector,A=a&&!a.collapsed;return A&&n.addAnnotation(h,l),A},u=(b,l=!0,h=L.LOCAL)=>{const a=b.map(g=>j(g)?g:{...g,target:_(g.target,e)});if(a.some(g=>g.target.selector.range.collapsed)){const g=a.filter(E=>E.target.selector.range.collapsed);return console.warn("Could not revive all targets"),console.warn(g),n.bulkAddAnnotation(a,l,h),g}else return n.bulkAddAnnotation(a,l,h),[]},d=(b,l=L.LOCAL)=>{const h=b.selector.range instanceof Range?b:_(b,e);n.updateTarget(h,l)},m=(b,l=L.LOCAL)=>{const h=b.map(a=>a.selector.range instanceof Range?a:_(a,e));n.bulkUpdateTargets(h,l)},f=(b,l)=>{const h=o.getAt(b,l);return h?n.getAnnotation(h):void 0},x=(b,l,h,a)=>{const A=o.getIntersectingRects(b,l,h,a);return Array.from(new Set(A.map(E=>E.annotation.id))).map(E=>n.getAnnotation(E)).filter(E=>E)},C=(b,l,h,a=5)=>{const A=o.getDOMRectsForAnnotation(b);if(A.length>0){if(l&&h){const g=A.find(({top:E,right:R,bottom:M,left:U})=>l>=U-a&&l<=R+a&&h>=E-a&&h<=M+a);if(g)return g}return o.getBoundsForAnnotation(b)}},v=(b,l,h,a)=>{const g=o.getIntersectingRects(b,l,h,a).reduce((E,R)=>((E[R.annotation.id]=E[R.annotation.id]||[]).push(R),E),{});return Object.entries(g).map(([E,R])=>({annotation:n.getAnnotation(E),rects:R.map(({minX:M,minY:U,maxX:p,maxY:w})=>({x:M,y:U,width:p-M,height:w-U}))}))},B=()=>o.recalculate();return n.observe(({changes:b})=>{const l=(b.created||[]).filter(j),h=(b.deleted||[]).filter(j),a=(b.updated||[]).filter(A=>j(A.newValue));l.length>0&&o.set(l.map(A=>A.target),!1),(h==null?void 0:h.length)>0&&h.forEach(A=>o.remove(A.target)),(a==null?void 0:a.length)>0&&a.forEach(({newValue:A})=>o.update(A.target))}),{store:{...n,addAnnotation:c,bulkAddAnnotation:u,bulkUpdateTargets:m,getAnnotationBounds:C,getAt:f,getIntersecting:x,getIntersectingRects:v,recalculatePositions:B,updateTarget:d},selection:i,hover:s,viewport:r}},se=(e,t={})=>{const n=new Map,o=s=>Array.from(n.entries()).filter(([r,c])=>c.presenceKey===s.presenceKey).map(([r,c])=>r);return e.on("selectionChange",(s,r)=>{o(s).forEach(u=>n.delete(u)),r&&r.forEach(u=>n.set(u,s))}),{paint:(s,r,c,u,d,m)=>{t.font&&(u.font=t.font);const f=n.get(s.id);if(f){const{x,y:C,height:v}=r[0];u.fillStyle=f.appearance.color,u.fillRect(x-2,C-2.5,2,v+5);const B=u.measureText(f.appearance.label),b=B.width+6,l=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent+8,h=B.fontBoundingBoxAscent?8:6.5;u.fillRect(x-2,C-2.5-l,b,l),u.fillStyle="#fff",u.fillText(f.appearance.label,x+1,C-h),c.fillStyle=f.appearance.color,c.globalAlpha=d?.45:.18,r.forEach(({x:a,y:A,width:g,height:E})=>c.fillRect(a,A-2.5,g,E+5))}else G.paint(s,r,c,u,d,m)}}},ft=e=>e===null?null:e.scrollHeight>e.clientHeight?e:ft(e.parentElement),re=(e,t)=>n=>{const o=ft(e);if(o){const i=t.getAnnotation(n.id),{range:s}=i.target.selector;if(!s||s.collapsed)return!1;const r=o.getBoundingClientRect(),c=o.clientHeight,u=o.clientWidth,d=i.target.selector.range.getBoundingClientRect(),{width:m,height:f}=t.getAnnotationBounds(n.id),x=d.top-r.top,C=d.left-r.left,v=o.parentElement?o.scrollTop:0,B=o.parentElement?o.scrollLeft:0,b=x+v-(c-f)/2,l=C+B-(u-m)/2;return o.scroll({top:b,left:l,behavior:"smooth"}),!0}},ae=(e,t,n)=>{const o=document.createRange(),i=n?e.startContainer.parentElement.closest(n):t;o.setStart(i,0),o.setEnd(e.startContainer,e.startOffset);const s=e.toString(),r=o.toString().length,c=r+s.length;return n?{quote:s,start:r,end:c,range:e,offsetReference:i}:{quote:s,start:r,end:c,range:e}},ce=(e,t,n)=>{const{store:o,selection:i}=t;let s,r=null;const c=x=>s=x;let u=!1,d;e.addEventListener("selectstart",x=>{if(!u)return;!x.target.parentElement.closest(".not-annotatable")?r={annotation:Tt(),selector:void 0,creator:s,created:new Date}:(r=null,d=void 0)});let m;document.addEventListener("selectionchange",x=>{m&&clearTimeout(m),m=setTimeout(()=>f(),50)});const f=()=>{var C,v;const x=document.getSelection();if(!x.isCollapsed&&u&&r){const B=Array.from(Array(x.rangeCount).keys()).map(h=>x.getRangeAt(h));oe(B[0]).toString()!==((v=(C=r.selector)==null?void 0:C.range)==null?void 0:v.toString())&&(r={...r,selector:ae(B[0],e,n)},o.getAnnotation(r.annotation)?o.updateTarget(r,L.LOCAL):(o.addAnnotation({id:r.annotation,bodies:[],target:r}),i.clickSelect(r.annotation,d)))}};return e.addEventListener("pointerdown",x=>{d=x,u=x.button===0}),document.addEventListener("pointerup",x=>{var v;d=x,!((v=x.target.parentElement)!=null&&v.closest(".not-annotatable")||!u)&&setTimeout(()=>{if(r!=null&&r.selector)o.updateTarget(r,L.LOCAL),i.clickSelect(r.annotation,x),r=null,d=void 0;else{const{x:B,y:b}=e.getBoundingClientRect(),l=o.getAt(x.clientX-B,x.clientY-b);if(l){const{selected:h}=i;(h.length!==1||h[0].id!==l.id)&&(i.clickSelect(l.id,x),d=void 0)}else i.isEmpty()||i.clear()}},50)}),{setUser:c}},we="",le=(e,t={})=>{const n=ut(e,t.pointerAction),{selection:o,viewport:i}=n,s=n.store,r=Yt(s),c=_t(n,r,t.adapter);let u=lt();const d=ot(e,n,i);t.style&&d.setDrawingStyle(t.style);const m=ce(e,n,t.offsetReferenceSelector);return m.setUser(u),{...ct(n,r,t.adapter),destroy:()=>{throw"Not implemented yet"},element:e,getUser:()=>u,setFilter:a=>d.setFilter(a),setStyle:a=>d.setDrawingStyle(a),setUser:a=>{u=a,m.setUser(a)},setSelected:a=>{a?o.setSelected(a):o.clear()},setPresenceProvider:a=>{a&&(d.setPainter(se(a,t.presence)),a.on("selectionChange",()=>d.redraw()))},on:c.on,off:c.off,scrollIntoView:re(e,s),state:n}},de=L;X.Origin=de,X.createAnonymousGuest=lt,X.createBaseAnnotator=ct,X.createHighlightLayer=ot,X.createTextAnnotator=le,X.createTextAnnotatorState=ut,X.defaultPainter=G,X.parseAll=at,X.parseW3CBodies=Wt,X.reviveTarget=_,X.serializeAll=Nt,X.serializeW3CBodies=Ft,Object.defineProperty(X,Symbol.toStringTag,{value:"Module"})});
3
2
  //# sourceMappingURL=text-annotator.umd.js.map