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