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