@recogito/text-annotator 3.0.0-rc.11 → 3.0.0-rc.12

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