@soomo/text-annotator 4.2.0-staging.0 → 4.3.0-staging.0

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.
@@ -1,3 +1,3 @@
1
- (function(x,he){typeof exports=="object"&&typeof module<"u"?he(exports):typeof define=="function"&&define.amd?define(["exports"],he):(x=typeof globalThis<"u"?globalThis:x||self,he(x.RecogitoJS={}))})(this,(function(x){"use strict";const he=e=>e.target.selector.every(J),Ve=e=>e.selector.every(J);function J(e){return Array.isArray(e)?e.every(t=>"range"in t&&t.range instanceof Range&&!t.range.collapsed):"range"in e&&e.range instanceof Range&&!e.range.collapsed}const $=[];for(let e=0;e<256;++e)$.push((e+256).toString(16).slice(1));function hn(e,t=0){return($[e[t+0]]+$[e[t+1]]+$[e[t+2]]+$[e[t+3]]+"-"+$[e[t+4]]+$[e[t+5]]+"-"+$[e[t+6]]+$[e[t+7]]+"-"+$[e[t+8]]+$[e[t+9]]+"-"+$[e[t+10]]+$[e[t+11]]+$[e[t+12]]+$[e[t+13]]+$[e[t+14]]+$[e[t+15]]).toLowerCase()}const gn=new Uint8Array(16);function pn(){return crypto.getRandomValues(gn)}function lt(e,t,n){return crypto.randomUUID?crypto.randomUUID():mn(e)}function mn(e,t,n){e=e||{};const o=e.random??e.rng?.()??pn();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,hn(o)}const Pe=typeof navigator<"u"&&navigator.platform.startsWith("Mac"),Xe="not-annotatable",ae=`.${Xe}`,ge=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(ae):t.parentElement?.closest(ae)):!0,$e=(e,t)=>{const n=t.commonAncestorContainer;return!ge(e,n)},He=/^\s*$/,ct=e=>He.test(e.toString()),yn=e=>He.test(e.textContent||""),dt=e=>{if(e.length===0)return[];if(e.length===1)return[e[0]];e.sort((i,s)=>{const r=i.compareBoundaryPoints(Range.START_TO_START,s);return r!==0?r:i.compareBoundaryPoints(Range.END_TO_END,s)});const[t,...n]=e,o=n.reduce((i,s)=>i.current.compareBoundaryPoints(Range.START_TO_END,s)>=0?(i.current.compareBoundaryPoints(Range.END_TO_END,s)<0&&i.current.setEnd(s.endContainer,s.endOffset),i):(i.merged.push(i.current),i.current=s.cloneRange(),i),{merged:[],current:t.cloneRange()});return[...o.merged,o.current]},ut=e=>{(!e.hasAttribute("tabindex")||e.tabIndex<-1)&&e.setAttribute("tabindex","-1"),e.classList.add("no-focus-outline")},bn=function*(e){const t=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(Xe)&&!o.parentElement?.closest(ae)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},ft=(e,t)=>{if(!$e(e,t))return[];const n=[];let o=null;for(const i of bn(t)){let s;o?(s=document.createRange(),s.setStartAfter(o),s.setEndBefore(i)):(s=t.cloneRange(),s.setEndBefore(i)),s.collapsed||n.push(s),o=i}if(o){const i=t.cloneRange();i.setStartAfter(o),i.collapsed||n.push(i)}return n.length>0?n:[t]},Re=e=>{const t=e.cloneContents();return t.querySelectorAll(ae).forEach(n=>n.remove()),t},ht=(e,t)=>{const n=e.cloneRange();return t.contains(n.startContainer)||n.setStart(t,0),t.contains(n.endContainer)||n.setEnd(t,t.childNodes.length),n},gt=new Intl.Segmenter(void 0,{granularity:"grapheme"}),pt=(e,t,n=10,o)=>{const i=o?e.startContainer.parentElement.closest(o):t,s=document.createRange();s.setStart(i,0),s.setEnd(e.startContainer,e.startOffset);const r=Re(s).textContent,a=document.createRange();a.setStart(e.endContainer,e.endOffset),i===document.body?a.setEnd(i,i.childNodes.length):a.setEndAfter(i);const l=Re(a).textContent,d=[...gt.segment(r)],h=[...gt.segment(l)];return{prefix:d.slice(-n).map(f=>f.segment).join(""),suffix:h.slice(0,n).map(f=>f.segment).join("")}},mt=(e,t,n)=>{const o=document.createRange(),i=n?e.startContainer.parentElement.closest(n):t;o.setStart(i,0),o.setEnd(e.startContainer,e.startOffset);const s=Re(o).textContent,r=e.toString(),a=s.length||0,l=a+r.length;return n?{quote:r,start:a,end:l,range:e,offsetReference:i}:{quote:r,start:a,end:l,range:e}},je=(e,t)=>{const{start:n,end:o}=e,i=e.offsetReference||t,s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,h=>h.parentElement?.closest(ae)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT);let r=0;const a=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||=typeof i?.contains=="function"?i.contains(l):!1,d){const h=l.textContent?.length||0;if(r+h>n){a.setStart(l,n-r);break}r+=h}l=s.nextNode()}for(;l!==null;){const h=l.textContent?.length||0;if(r+h>=o){a.setEnd(l,o-r);break}r+=h,l=s.nextNode()}return{...e,range:a}},pe=(e,t,n=(o,i)=>je(o,i))=>Ve(e)?e:{...e,selector:e.selector.map(o=>J(o)?o:n(o,t))},Oe=(e,t,n)=>Ve(e.target)?e:{...e,target:pe(e.target,t,n)},yt=e=>{if(!e)return document.scrollingElement;const{overflowY:t}=window.getComputedStyle(e);return t!=="visible"&&t!=="hidden"&&e.scrollHeight>e.clientHeight?e:yt(e.parentElement)},bt=(e,t,n)=>{const o=n.getBoundingClientRect(),i=n.clientHeight,s=n.clientWidth,r=t.selector[0].range.getBoundingClientRect(),{width:a,height:l}=e.getAnnotationBounds(t.annotation),d=r.top-o.top,h=r.left-o.left,f=n.parentElement?n.scrollTop:0,b=n.parentElement?n.scrollLeft:0,m=d+f-(i-l)/2,c=h+b-(s-a)/2;n.scroll({top:m,left:c,behavior:"smooth"})},At=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,s=o?typeof o=="string"?document.getElementById(o):o:yt(e);if(!s)return console.warn(`The scroll parent is missing for the annotation: ${i}`,{container:e}),!1;const r=t.getAnnotation(i);if(!r)return console.warn(`The annotation is missing in the store: ${i}`),!1;const{range:a}=r.target.selector[0];if(a&&!a.collapsed)return bt(t,r.target,s),!0;const l=pe(r.target,e),{range:d}=l.selector[0];return d&&!d.collapsed?(bt(t,l,s),!0):!1};var wt=Object.prototype.hasOwnProperty;function le(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&le(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(wt.call(e,n)&&++o&&!wt.call(t,n)||!(n in t)||!le(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const An=Symbol("clean");let Q=[],oe=0;const ke=4,wn=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),Fe=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(o){return n.lc=t.push(o),()=>{for(let s=oe+ke;s<Q.length;)Q[s]===o?Q.splice(s,ke):s+=ke;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){wn.epoch++;let s=!Q.length;for(let r of t)Q.push(r,n.value,o,i);if(s){for(oe=0;oe<Q.length;oe+=ke)Q[oe](Q[oe+1],Q[oe+2],Q[oe+3]);Q.length=0}},off(){},set(o){let i=n.value;i!==o&&(n.value=o,n.notify(i))},subscribe(o){let i=n.listen(o);return o(n.value),i},value:e};return process.env.NODE_ENV!=="production"&&(n[An]=()=>{t=[],n.lc=0,n.off()}),n},En=e=>{const t=Fe(null);return e.observe(({changes:n})=>{const o=t.get();if(o){(n.deleted||[]).some(s=>s.id===o)&&t.set(null);const i=(n.updated||[]).find(({oldValue:s})=>s.id===o);i&&t.set(i.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var We=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(We||{});const ze={selected:[]},vn=(e,t,n)=>{const o=Fe(ze);let i=t;const s=()=>{le(o.get(),ze)||o.set(ze)},r=()=>{var m;return((m=o.get().selected)==null?void 0:m.length)===0},a=m=>{if(r())return!1;const c=typeof m=="string"?m:m.id;return o.get().selected.some(y=>y.id===c)},l=(m,c)=>{let y;if(Array.isArray(m)){if(y=m.map(g=>e.getAnnotation(g)).filter(Boolean),y.length<m.length){console.warn("Invalid selection: "+m.filter(g=>!y.some(u=>u.id===g)));return}}else{const g=e.getAnnotation(m);if(!g){console.warn("Invalid selection: "+m);return}y=[g]}const E=y.reduce((g,u)=>{const v=b(u);return v==="EDIT"?[...g,{id:u.id,editable:!0}]:v==="SELECT"?[...g,{id:u.id}]:g},[]);o.set({selected:E,event:c})},d=(m,c)=>{const y=Array.isArray(m)?m:[m],E=y.map(g=>e.getAnnotation(g)).filter(g=>!!g);o.set({selected:E.map(g=>{const u=c===void 0?b(g)==="EDIT":c;return{id:g.id,editable:u}})}),E.length!==y.length&&console.warn("Invalid selection",m)},h=m=>{if(r())return!1;const{selected:c}=o.get();c.some(({id:y})=>m.includes(y))&&o.set({selected:c.filter(({id:y})=>!m.includes(y))})},f=m=>{i=m,d(o.get().selected.map(({id:c})=>c))},b=m=>Sn(m,i,n);return e.observe(({changes:m})=>h((m.deleted||[]).map(c=>c.id))),{get event(){const m=o.get();return m?m.event:null},get selected(){const m=o.get();return m?[...m.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:b,isEmpty:r,isSelected:a,setSelected:d,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:l}},Sn=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},H=[];for(let e=0;e<256;++e)H.push((e+256).toString(16).slice(1));function Cn(e,t=0){return(H[e[t+0]]+H[e[t+1]]+H[e[t+2]]+H[e[t+3]]+"-"+H[e[t+4]]+H[e[t+5]]+"-"+H[e[t+6]]+H[e[t+7]]+"-"+H[e[t+8]]+H[e[t+9]]+"-"+H[e[t+10]]+H[e[t+11]]+H[e[t+12]]+H[e[t+13]]+H[e[t+14]]+H[e[t+15]]).toLowerCase()}const Tn=new Uint8Array(16);function xn(){return crypto.getRandomValues(Tn)}function Et(e,t,n){return crypto.randomUUID?crypto.randomUUID():Ln(e)}function Ln(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??xn();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,Cn(i)}const qe=e=>{const t=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{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Rn=(e,t,n,o)=>({id:Et(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),On=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},kn=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Mn=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!le(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Bn=(e,t)=>!le(e.target,t.target),vt=(e,t)=>{const n=On(e,t),o=kn(e,t),i=Mn(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Bn(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var _=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(_||{});const Nn=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>l&&l.length>0;if(!(a(i.created)||a(i.deleted))){const l=(n=i.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),d=(o=i.updated)==null?void 0:o.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!d||r==="TARGET_ONLY"&&d&&!l)return!1}}if(e.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(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},_n=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),a=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),l=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:b})=>b.id===f.id).newValue:f),...t.created||[]],d=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],h=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:b,newValue:m}=f;if(r.has(m.id)){const c=t.updated.find(y=>y.oldValue.id===m.id).newValue;return vt(b,c)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!a.has(f.id))];return{created:l,deleted:d,updated:h}},Me=e=>{const t=e.id===void 0?Et():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},In=e=>e.id!==void 0,Un=()=>{const e=new Map,t=new Map,n=[],o=(p,A={})=>{n.push({onChange:p,options:A})},i=p=>{const A=n.findIndex(w=>w.onChange==p);A>-1&&n.splice(A,1)},s=(p,A)=>{const w={origin:p,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...e.values()]};n.forEach(T=>{Nn(T,w)&&T.onChange(w)})},r=(p,A=_.LOCAL)=>{if(p.id&&e.get(p.id))throw Error(`Cannot add annotation ${p.id} - exists already`);{const w=Me(p);e.set(w.id,w),w.bodies.forEach(T=>t.set(T.id,w.id)),s(A,{created:[w]})}},a=(p,A)=>{const w=Me(typeof p=="string"?A:p),T=typeof p=="string"?p:p.id,U=T&&e.get(T);if(U){const N=vt(U,w);return T===w.id?e.set(T,w):(e.delete(T),e.set(w.id,w)),U.bodies.forEach(D=>t.delete(D.id)),w.bodies.forEach(D=>t.set(D.id,w.id)),N}else console.warn(`Cannot update annotation ${T} - does not exist`)},l=(p,A=_.LOCAL,w=_.LOCAL)=>{const T=In(A)?w:A,U=a(p,A);U&&s(T,{updated:[U]})},d=(p,A=_.LOCAL)=>{e.get(p.id)?l(p,A):r(p,A)},h=(p,A=_.LOCAL)=>{const w=p.reduce((T,U)=>{const N=a(U);return N?[...T,N]:T},[]);w.length>0&&s(A,{updated:w})},f=(p,A=_.LOCAL)=>{const w=p.map(Me),{toAdd:T,toUpdate:U}=w.reduce((D,S)=>e.get(S.id)?{...D,toUpdate:[...D.toUpdate,S]}:{...D,toAdd:[...D.toAdd,S]},{toAdd:[],toUpdate:[]}),N=U.map(D=>a(D,A)).filter(Boolean);T.forEach(D=>{e.set(D.id,D),D.bodies.forEach(S=>t.set(S.id,D.id))}),s(A,{created:T,updated:N})},b=(p,A=_.LOCAL)=>{const w=e.get(p.annotation);if(w){const T={...w,bodies:[...w.bodies,p]};e.set(w.id,T),t.set(p.id,T.id),s(A,{updated:[{oldValue:w,newValue:T,bodiesCreated:[p]}]})}else console.warn(`Attempt to add body to missing annotation: ${p.annotation}`)},m=()=>[...e.values()],c=(p=_.LOCAL)=>{const A=[...e.values()];e.clear(),t.clear(),s(p,{deleted:A})},y=(p,A=!0,w=_.LOCAL)=>{const T=p.map(Me);if(A){const U=[...e.values()];e.clear(),t.clear(),T.forEach(N=>{e.set(N.id,N),N.bodies.forEach(D=>t.set(D.id,N.id))}),s(w,{created:T,deleted:U})}else{const U=p.reduce((N,D)=>{const S=D.id&&e.get(D.id);return S?[...N,S]:N},[]);if(U.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${U.map(N=>N.id).join(", ")}`);T.forEach(N=>{e.set(N.id,N),N.bodies.forEach(D=>t.set(D.id,N.id))}),s(w,{created:T})}},E=p=>{const A=typeof p=="string"?p:p.id,w=e.get(A);if(w)return e.delete(A),w.bodies.forEach(T=>t.delete(T.id)),w;console.warn(`Attempt to delete missing annotation: ${A}`)},g=(p,A=_.LOCAL)=>{const w=E(p);w&&s(A,{deleted:[w]})},u=(p,A=_.LOCAL)=>{const w=p.reduce((T,U)=>{const N=E(U);return N?[...T,N]:T},[]);w.length>0&&s(A,{deleted:w})},v=p=>{const A=e.get(p.annotation);if(A){const w=A.bodies.find(T=>T.id===p.id);if(w){t.delete(w.id);const T={...A,bodies:A.bodies.filter(U=>U.id!==p.id)};return e.set(A.id,T),{oldValue:A,newValue:T,bodiesDeleted:[w]}}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}`)},k=(p,A=_.LOCAL)=>{const w=v(p);w&&s(A,{updated:[w]})},L=(p,A=_.LOCAL)=>{const w=p.map(T=>v(T)).filter(Boolean);w.length>0&&s(A,{updated:w})},C=p=>{const A=e.get(p);return A?{...A}:void 0},R=p=>{const A=t.get(p);if(A){const w=C(A).bodies.find(T=>T.id===p);if(w)return w;console.error(`Store integrity error: body ${p} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${p}`)},I=(p,A)=>{if(p.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=e.get(p.annotation);if(w){const T=w.bodies.find(N=>N.id===p.id),U={...w,bodies:w.bodies.map(N=>N.id===T.id?A:N)};return e.set(w.id,U),T.id!==A.id&&(t.delete(T.id),t.set(A.id,U.id)),{oldValue:w,newValue:U,bodiesUpdated:[{oldBody:T,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${p.annotation}`)},Y=(p,A,w=_.LOCAL)=>{const T=I(p,A);T&&s(w,{updated:[T]})},M=(p,A=_.LOCAL)=>{const w=p.map(T=>I({id:T.id,annotation:T.annotation},T)).filter(Boolean);s(A,{updated:w})},O=p=>{const A=e.get(p.annotation);if(A){const w={...A,target:{...A.target,...p}};return e.set(A.id,w),{oldValue:A,newValue:w,targetUpdated:{oldTarget:A.target,newTarget:p}}}else console.warn(`Attempt to update target on missing annotation: ${p.annotation}`)};return{addAnnotation:r,addBody:b,all:m,bulkAddAnnotations:y,bulkDeleteAnnotations:u,bulkDeleteBodies:L,bulkUpdateAnnotations:h,bulkUpdateBodies:M,bulkUpdateTargets:(p,A=_.LOCAL)=>{const w=p.map(T=>O(T)).filter(Boolean);w.length>0&&s(A,{updated:w})},bulkUpsertAnnotations:f,clear:c,deleteAnnotation:g,deleteBody:k,getAnnotation:C,getBody:R,observe:o,unobserve:i,updateAnnotation:l,updateBody:Y,updateTarget:(p,A=_.LOCAL)=>{const w=O(p);w&&s(A,{updated:[w]})},upsertAnnotation:d}};let Dn=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const Kn=250,Yn=(e,t)=>{const n=Dn(),o=[];let i=-1,s=!1,r=0;const a=c=>{if(!s){const{changes:y}=c,E=performance.now();if(E-r>Kn)o.splice(i+1),o.push(y),i=o.length-1;else{const g=o.length-1;o[g]=_n(o[g],y)}r=E}s=!1};e.observe(a,{origin:_.LOCAL});const l=c=>c&&c.length>0&&e.bulkDeleteAnnotations(c),d=c=>c&&c.length>0&&e.bulkAddAnnotations(c,!1),h=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({oldValue:y})=>y)),f=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({newValue:y})=>y)),b=c=>c&&c.length>0&&e.bulkAddAnnotations(c,!1),m=c=>c&&c.length>0&&e.bulkDeleteAnnotations(c);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...o],pointer:i}),on:(c,y)=>n.on(c,y),redo:()=>{if(o.length-1>i){s=!0;const{created:c,updated:y,deleted:E}=o[i+1];d(c),f(y),m(E),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:c,updated:y,deleted:E}=o[i];l(c),h(y),b(E),n.emit("undo",o[i]),i-=1}}}},Vn=()=>{const e=Fe([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Pn=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:a}=e,l=new Map;let d=[],h;const f=(y,E)=>{l.has(y)?l.get(y).push(E):l.set(y,[E])},b=(y,E)=>{const g=l.get(y);if(g){const u=g.indexOf(E);u!==-1&&g.splice(u,1)}},m=(y,E,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(u=>{if(n){const v=Array.isArray(E)?E.map(L=>n.serialize(L)):n.serialize(E),k=g?g instanceof PointerEvent?g:n.serialize(g):void 0;u(v,k)}else u(E,g)})},1)};s.subscribe(({selected:y})=>{if(!(d.length===0&&y.length===0)){if(d.length===0&&y.length>0)d=y.map(({id:E})=>r.getAnnotation(E));else if(d.length>0&&y.length===0)d.forEach(E=>{const g=r.getAnnotation(E.id);g&&!le(g,E)&&m("updateAnnotation",g,E)}),d=[];else{const E=new Set(d.map(u=>u.id)),g=new Set(y.map(({id:u})=>u));d.filter(u=>!g.has(u.id)).forEach(u=>{const v=r.getAnnotation(u.id);v&&!le(v,u)&&m("updateAnnotation",v,u)}),d=[...d.filter(u=>g.has(u.id)),...y.filter(({id:u})=>!E.has(u)).map(({id:u})=>r.getAnnotation(u))]}m("selectionChanged",d)}}),i.subscribe(y=>{!h&&y?m("mouseEnterAnnotation",r.getAnnotation(y)):h&&!y?m("mouseLeaveAnnotation",r.getAnnotation(h)):h&&y&&(m("mouseLeaveAnnotation",r.getAnnotation(h)),m("mouseEnterAnnotation",r.getAnnotation(y))),h=y}),a?.subscribe(y=>m("viewportIntersect",y.map(E=>r.getAnnotation(E)))),r.observe(y=>{const{created:E,deleted:g}=y.changes;(E||[]).forEach(u=>m("createAnnotation",u)),(g||[]).forEach(u=>m("deleteAnnotation",u)),(y.changes.updated||[]).filter(u=>[...u.bodiesCreated||[],...u.bodiesDeleted||[],...u.bodiesUpdated||[]].length>0).forEach(({oldValue:u,newValue:v})=>{const k=d.find(L=>L.id===u.id)||u;d=d.map(L=>L.id===u.id?v:L),m("updateAnnotation",v,k)})},{origin:_.LOCAL}),r.observe(y=>{if(d){const E=new Set(d.map(u=>u.id)),g=(y.changes.updated||[]).filter(({newValue:u})=>E.has(u.id)).map(({newValue:u})=>u);g.length>0&&(d=d.map(u=>g.find(k=>k.id===u.id)||u))}},{origin:_.REMOTE});const c=y=>E=>{const{updated:g}=E;y?(g||[]).forEach(u=>m("updateAnnotation",u.oldValue,u.newValue)):(g||[]).forEach(u=>m("updateAnnotation",u.newValue,u.oldValue))};return t.on("undo",c(!0)),t.on("redo",c(!1)),{on:f,off:b,emit:m}},Xn=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),$n=(e,t,n)=>{const{store:o,selection:i}=e,s=g=>{if(n){const{parsed:u,error:v}=n.parse(g);u?o.addAnnotation(u,_.REMOTE):console.error(v)}else o.addAnnotation(qe(g),_.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=g=>{const u=o.getAnnotation(g);return n&&u?n.serialize(u):u},d=()=>n?o.all().map(n.serialize):o.all(),h=()=>{var g;const u=(((g=i.selected)==null?void 0:g.map(v=>v.id))||[]).map(v=>o.getAnnotation(v)).filter(Boolean);return n?u.map(n.serialize):u},f=(g,u=!0)=>fetch(g).then(v=>v.json()).then(v=>(m(v,u),v)),b=g=>{if(typeof g=="string"){const u=o.getAnnotation(g);if(o.deleteAnnotation(g),u)return n?n.serialize(u):u}else{const u=n?n.parse(g).parsed:g;if(u)return o.deleteAnnotation(u),g}},m=(g,u=!0)=>{if(n){const v=n.parseAll||Xn(n),{parsed:k,failed:L}=v(g);L.length>0&&console.warn(`Discarded ${L.length} invalid annotations`,L),o.bulkAddAnnotations(k,u,_.REMOTE)}else o.bulkAddAnnotations(g.map(qe),u,_.REMOTE)},c=(g,u)=>{g?i.setSelected(g,u):i.clear()},y=g=>{i.setUserSelectAction(g)},E=g=>{if(n){const u=n.parse(g).parsed,v=n.serialize(o.getAnnotation(u.id));return o.updateAnnotation(u),v}else{const u=o.getAnnotation(g.id);return o.updateAnnotation(qe(g)),u}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:d,getHistory:t.getHistory,getSelected:h,loadAnnotations:f,redo:t.redo,removeAnnotation:b,setAnnotations:m,setSelected:c,setUserSelectAction:y,undo:t.undo,updateAnnotation:E}};let Hn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",jn=e=>crypto.getRandomValues(new Uint8Array(e)),Fn=(e,t,n)=>{let o=256-256%e.length;if(o===256){let s=e.length-1;return(r=t)=>{if(!r)return"";let a="";for(;;){let l=n(r),d=r;for(;d--;)if(a+=e[l[d]&s],a.length>=r)return a}}}let i=Math.ceil(1.6*256*t/o);return(s=t)=>{if(!s)return"";let r="";for(;;){let a=n(i),l=i;for(;l--;)if(a[l]<o&&(r+=e[a[l]%e.length],r.length>=s))return r}}},Wn=(e,t=21)=>Fn(e,t|0,jn),zn=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Hn[n[e]&63];return t};const qn=()=>({isGuest:!0,id:Wn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Gn=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},St=e=>e?typeof e=="object"?{...e}:e:void 0,Qn=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,modified:l,creator:d,...h}=n;return{id:o||`temp-${Gn(n)}`,annotation:t,type:i,purpose:s,value:r,creator:St(d),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...h}}),Jn=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,a={...r,created:i?.toISOString(),modified:s?.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a});zn();const Zn=(e,t)=>({parse:n=>Ct(n),serialize:n=>Tt(n,e,t)}),eo=e=>e.quote!==void 0&&e.start!==void 0&&e.end!==void 0,to=e=>{const{id:t,creator:n,created:o,modified:i,target:s}=e,r=Array.isArray(s)?s:[s];if(r.length===0)return{error:Error(`No targets found for annotation: ${e.id}`)};const a={creator:St(n),created:o?new Date(o):void 0,updated:i?new Date(i):void 0,annotation:t,selector:[],styleClass:"styleClass"in r[0]?r[0].styleClass:void 0};for(const l of r){const h=(Array.isArray(l.selector)?l.selector:[l.selector]).reduce((f,b)=>{switch(b.type){case"TextQuoteSelector":f.quote=b.exact;break;case"TextPositionSelector":f.start=b.start,f.end=b.end;break}return f},{});if(a.outdated||="outdated"in l?l.outdated:void 0,a.migrationPending||="migrationPending"in l?l.migrationPending:void 0,eo(h))a.selector.push({...h,id:l.id,scope:l.scope});else{const f=[h.start?void 0:"TextPositionSelector",h.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${f.join(" and ")} for annotation: ${e.id}`)}}}return{parsed:a}},Ct=e=>{const t=e.id||lt(),{creator:n,created:o,modified:i,body:s,...r}=e,a=Qn(s,t),l=to(e);return"error"in l?{error:l.error}:{parsed:{...r,id:t,bodies:a,target:l.parsed}}},Tt=(e,t,n)=>{const{bodies:o,target:i,...s}=e,{selector:r,creator:a,created:l,updated:d,...h}=i,f=r.map(b=>{const{id:m,quote:c}=b,y={type:"TextQuoteSelector",exact:c};if(n&&"range"in b){const{prefix:v,suffix:k}=pt(b.range,n);y.prefix=v,y.suffix=k}if(!("start"in b))throw new Error("W3C serialization requires TextSelector with start/end");const{start:E,end:g}=b,u={type:"TextPositionSelector",start:E,end:g};return{...h,id:m,scope:"scope"in b?b.scope:void 0,source:t,selector:[y,u]}});return{...s,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Jn(e.bodies),creator:a,created:l?.toISOString(),modified:d?.toISOString(),target:f}};let xt=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){return(this.events[e]||=[]).push(t),()=>{this.events[e]=this.events[e]?.filter(n=>t!==n)}}});const Lt=e=>e.addEventListener("click",t=>{!t.target.closest(ae)&&!t.target.closest("a")&&t.preventDefault()}),Be=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}),me=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}),Ne=(e,t=10)=>{let n;return((...o)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,o),t)})},Ge=(e,t,n,o)=>{const{store:i,selection:s,hover:r}=n,a=xt();let l;const d=new Map;let h;const f=Wt(o),b=M=>{const{x:O,y:p}=t.getBoundingClientRect(),A=i.getAt(M.clientX-O,M.clientY-p,!1,h);A&&n.selection.evalSelectAction(A)!==We.NONE?r.current!==A.id&&(t.classList.add("hovered"),r.set(A.id)):r.current&&(t.classList.remove("hovered"),r.set(null))};t.addEventListener("pointermove",b);const m=Ne((M=!1)=>requestAnimationFrame(()=>{const O=Ft(t),{minX:p,minY:A,maxX:w,maxY:T}=O,U=h?i.getIntersecting(p,A,w,T).filter(({annotation:S})=>h?.(S)):i.getIntersecting(p,A,w,T),N=s.selected.map(({id:S})=>S),D=U.map(({annotation:S,rects:B})=>{const F=N.includes(S.id),ie=S.id===r.current;return{annotation:S,rects:B,state:{selected:F,hovered:ie}}});e.redraw(D,O,l,d,M),setTimeout(()=>{f(U.map(({annotation:S})=>S)),a.emit("onRedraw")},1)}),10),c=(M,O)=>{O?M?d.set(O,M):d.delete(O):l=M,m(!0)},y=M=>{h=M,m(!1)},E=(M,O)=>a.on(M,O),g=()=>{m()};i.observe(g);const u=s.subscribe(()=>{m()}),v=r.subscribe(()=>{m()}),k=()=>{m(!0)};document.addEventListener("scroll",k,{capture:!0,passive:!0});const L=Ne(()=>{i.recalculatePositions(),m()},10);window.addEventListener("resize",L);const C=new ResizeObserver(L);C.observe(t);const R={attributes:!0,childList:!0,subtree:!0},I=new MutationObserver(Ne(M=>{M.every(p=>p.target===t||t.contains(p.target))||m(!0)},150));return I.observe(document.body,R),{destroy:()=>{t.removeEventListener("pointermove",b),e.destroy(),i.unobserve(g),u(),v(),document.removeEventListener("scroll",k),window.removeEventListener("resize",L),C.disconnect(),I.disconnect()},on:E,redraw:m,setStyle:c,setFilter:y,setVisible:e.setVisible.bind(e)}};var no={grad:.9,turn:360,rad:360/(2*Math.PI)},ee=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},X=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=Math.pow(10,t)),Math.round(n*e)/n+0},W=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},Rt=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},Ot=function(e){return{r:W(e.r,0,255),g:W(e.g,0,255),b:W(e.b,0,255),a:W(e.a)}},Qe=function(e){return{r:X(e.r),g:X(e.g),b:X(e.b),a:X(e.a,3)}},oo=/^#([0-9a-f]{3,8})$/i,_e=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},kt=function(e){var t=e.r,n=e.g,o=e.b,i=e.a,s=Math.max(t,n,o),r=s-Math.min(t,n,o),a=r?s===t?(n-o)/r:s===n?2+(o-t)/r:4+(t-n)/r:0;return{h:60*(a<0?a+6:a),s:s?r/s*100:0,v:s/255*100,a:i}},Mt=function(e){var t=e.h,n=e.s,o=e.v,i=e.a;t=t/360*6,n/=100,o/=100;var s=Math.floor(t),r=o*(1-n),a=o*(1-(t-s)*n),l=o*(1-(1-t+s)*n),d=s%6;return{r:255*[o,a,r,r,l,o][d],g:255*[l,o,o,a,r,r][d],b:255*[r,r,l,o,o,a][d],a:i}},Bt=function(e){return{h:Rt(e.h),s:W(e.s,0,100),l:W(e.l,0,100),a:W(e.a)}},Nt=function(e){return{h:X(e.h),s:X(e.s),l:X(e.l),a:X(e.a,3)}},_t=function(e){return Mt((n=(t=e).s,{h:t.h,s:(n*=((o=t.l)<50?o:100-o)/100)>0?2*n/(o+n)*100:0,v:o+n,a:t.a}));var t,n,o},ye=function(e){return{h:(t=kt(e)).h,s:(i=(200-(n=t.s))*(o=t.v)/100)>0&&i<200?n*o/100/(i<=100?i:200-i)*100:0,l:i/2,a:t.a};var t,n,o,i},io=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,so=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ro=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ao=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,It={string:[[function(e){var t=oo.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?X(parseInt(e[3]+e[3],16)/255,2):1}:e.length===6||e.length===8?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:e.length===8?X(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=ro.exec(e)||ao.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Ot({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=io.exec(e)||so.exec(e);if(!t)return null;var n,o,i=Bt({h:(n=t[1],o=t[2],o===void 0&&(o="deg"),Number(n)*(no[o]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return _t(i)},"hsl"]],object:[[function(e){var t=e.r,n=e.g,o=e.b,i=e.a,s=i===void 0?1:i;return ee(t)&&ee(n)&&ee(o)?Ot({r:Number(t),g:Number(n),b:Number(o),a:Number(s)}):null},"rgb"],[function(e){var t=e.h,n=e.s,o=e.l,i=e.a,s=i===void 0?1:i;if(!ee(t)||!ee(n)||!ee(o))return null;var r=Bt({h:Number(t),s:Number(n),l:Number(o),a:Number(s)});return _t(r)},"hsl"],[function(e){var t=e.h,n=e.s,o=e.v,i=e.a,s=i===void 0?1:i;if(!ee(t)||!ee(n)||!ee(o))return null;var r=(function(a){return{h:Rt(a.h),s:W(a.s,0,100),v:W(a.v,0,100),a:W(a.a)}})({h:Number(t),s:Number(n),v:Number(o),a:Number(s)});return Mt(r)},"hsv"]]},Ut=function(e,t){for(var n=0;n<t.length;n++){var o=t[n][0](e);if(o)return[o,t[n][1]]}return[null,void 0]},lo=function(e){return typeof e=="string"?Ut(e.trim(),It.string):typeof e=="object"&&e!==null?Ut(e,It.object):[null,void 0]},Je=function(e,t){var n=ye(e);return{h:n.h,s:W(n.s+100*t,0,100),l:n.l,a:n.a}},Ze=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},Dt=function(e,t){var n=ye(e);return{h:n.h,s:n.s,l:W(n.l+100*t,0,100),a:n.a}},Kt=(function(){function e(t){this.parsed=lo(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return X(Ze(this.rgba),2)},e.prototype.isDark=function(){return Ze(this.rgba)<.5},e.prototype.isLight=function(){return Ze(this.rgba)>=.5},e.prototype.toHex=function(){return t=Qe(this.rgba),n=t.r,o=t.g,i=t.b,r=(s=t.a)<1?_e(X(255*s)):"","#"+_e(n)+_e(o)+_e(i)+r;var t,n,o,i,s,r},e.prototype.toRgb=function(){return Qe(this.rgba)},e.prototype.toRgbString=function(){return t=Qe(this.rgba),n=t.r,o=t.g,i=t.b,(s=t.a)<1?"rgba("+n+", "+o+", "+i+", "+s+")":"rgb("+n+", "+o+", "+i+")";var t,n,o,i,s},e.prototype.toHsl=function(){return Nt(ye(this.rgba))},e.prototype.toHslString=function(){return t=Nt(ye(this.rgba)),n=t.h,o=t.s,i=t.l,(s=t.a)<1?"hsla("+n+", "+o+"%, "+i+"%, "+s+")":"hsl("+n+", "+o+"%, "+i+"%)";var t,n,o,i,s},e.prototype.toHsv=function(){return t=kt(this.rgba),{h:X(t.h),s:X(t.s),v:X(t.v),a:X(t.a,3)};var t},e.prototype.invert=function(){return z({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},e.prototype.saturate=function(t){return t===void 0&&(t=.1),z(Je(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),z(Je(this.rgba,-t))},e.prototype.grayscale=function(){return z(Je(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),z(Dt(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),z(Dt(this.rgba,-t))},e.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},e.prototype.alpha=function(t){return typeof t=="number"?z({r:(n=this.rgba).r,g:n.g,b:n.b,a:t}):X(this.rgba.a,3);var n},e.prototype.hue=function(t){var n=ye(this.rgba);return typeof t=="number"?z({h:t,s:n.s,l:n.l,a:n.a}):X(n.h)},e.prototype.isEqual=function(t){return this.toHex()===z(t).toHex()},e})(),z=function(e){return e instanceof Kt?e:new Kt(e)};const te={fill:"rgb(0, 128, 255)",fillOpacity:.18},Ie={fill:"rgb(0, 128, 255)",fillOpacity:.45},Yt=e=>e?.fillOpacity!==void 0?z(e?.fill||te.fill).alpha(e.fillOpacity).toHex():e?.fill?e.fill:z(te.fill).alpha(te.fillOpacity).toHex(),et=(e,t,n)=>t?typeof t=="function"?t(e.annotation,e.state,n)||(e.state?.selected?Ie:te):t:e.state?.selected?Ie:te;var Vt=Object.prototype.hasOwnProperty;function tt(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&tt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Vt.call(e,n)&&++o&&!Vt.call(t,n)||!(n in t)||!tt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Pt=(e,t)=>{const n=(s,r)=>s.x<=r.x+r.width&&s.x+s.width>=r.x&&s.y<=r.y+r.height&&s.y+s.height>=r.y,o=s=>s.rects.reduce((r,a)=>r+a.width,0),i=t.filter(({rects:s})=>s.some(r=>n(e,r)));return i.sort((s,r)=>o(r)-o(s)),i.findIndex(s=>s.rects.includes(e))},Xt=e=>{const t=[],n=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_TEXT);e.startContainer.nodeType===Node.TEXT_NODE&&(n.currentNode=e.startContainer,e.intersectsNode(e.startContainer)&&t.push(e.startContainer));let o=t.length>0,i;for(;i=n.nextNode();)if(e.intersectsNode(i))o=!0,t.push(i);else if(o)break;if(t.length<2)return Array.from(e.getClientRects());{const s=t[0],r=t[t.length-1],a=document.createRange();if(a.selectNode(s),e.startContainer.nodeType===Node.TEXT_NODE)a.setStart(s,e.startOffset);else{const h=e.startContainer.childNodes[e.startOffset];h?a.setStartBefore(h):a.setStartAfter(e.startContainer)}const l=document.createRange();if(l.selectNode(r),e.endContainer.nodeType===Node.TEXT_NODE)l.setEnd(r,e.endOffset);else{const h=e.endContainer.childNodes[e.endOffset];h?l.setEndBefore(h):l.setEndAfter(e.endContainer)}const d=h=>{const f=document.createRange();return f.selectNode(h),Array.from(f.getClientRects())};return[...Array.from(a.getClientRects()),...t.slice(1,-1).flatMap(d),...Array.from(l.getClientRects())]}},co=(e,t,n,o)=>{const i=a=>Math.round(a*10)/10,s={top:i(e.top),bottom:i(e.bottom),left:i(e.left),right:i(e.right)},r={top:i(t.top),bottom:i(t.bottom),left:i(t.left),right:i(t.right)};if(Math.abs(s.top-r.top)<o&&Math.abs(s.bottom-r.bottom)<o){if(Math.abs(s.left-r.right)<n||Math.abs(s.right-r.left)<n)return"inline-adjacent";if(s.left>=r.left&&s.right<=r.right)return"inline-is-contained";if(s.left<=r.left&&s.right>=r.right)return"inline-contains"}else if(s.top<=r.top&&s.bottom>=r.bottom){if(s.left<=r.left&&s.right>=r.right)return"block-contains"}else if(s.top>=r.top&&s.bottom<=r.bottom&&s.left>=r.left&&s.right<=r.right)return"block-is-contained"},uo=(e,t)=>{const n=Math.min(e.left,t.left),o=Math.max(e.right,t.right),i=Math.min(e.top,t.top),s=Math.max(e.bottom,t.bottom);return new DOMRect(n,i,o-n,s-i)},$t=(e,t=.5,n=.5)=>e.reduce((o,i)=>{if(i.width===0||i.height===0)return o;let s=[...o],r=!1;for(const a of o){const l=co(i,a,t,n);if(l==="inline-adjacent"){s=s.map(d=>d===a?uo(i,a):d),r=!0;break}else if(l==="inline-contains"){s=s.map(d=>d===a?i:d),r=!0;break}else if(l==="inline-is-contained"){r=!0;break}else if(l==="block-contains"||l==="block-is-contained"){i.width<a.width&&(s=s.map(d=>d===a?i:d)),i.width===a.width&&i.height<a.width&&(s=s.map(d=>d===a?i:d)),r=!0;break}}return r?s:[...s,i]},[]),fo=e=>({length:e.length,item:t=>e[t],[Symbol.iterator]:function*(){for(let t=0;t<this.length;t++)yield this.item(t)}}),Ht=(e,t)=>{const{left:n,top:o,right:i,bottom:s}=e;return new DOMRect(n-t.left,o-t.top,i-n,s-o)},ho=(e,t)=>{const{left:n,top:o,right:i,bottom:s}=e;return new DOMRect(n+t.left,o+t.top,i-n,s-o)},go=e=>{e.classList.add("r6o-annotatable");const t=document.createElement("div");t.className="r6o-span-highlight-layer",e.appendChild(t);let n=[];return{destroy:()=>{t.remove()},redraw:(r,a,l,d,h)=>{if(!(!tt(n,r)||h))return;t.innerHTML="",[...r].sort((c,y)=>{const{annotation:{target:{created:E}}}=c,{annotation:{target:{created:g}}}=y;return E&&g?E.getTime()-g.getTime():0}).forEach(c=>{const y=d?.get(c.annotation.id)||l;c.rects.map(E=>{const g=Pt(E,r),u=et(c,y,g),v=document.createElement("span");v.className="r6o-annotation",v.dataset.annotation=c.annotation.id,v.style.left=`${E.x}px`,v.style.top=`${E.y}px`,v.style.width=`${E.width}px`,v.style.height=`${E.height}px`,v.style.backgroundColor=Yt(u),u.underlineStyle&&(v.style.borderStyle=u.underlineStyle),u.underlineColor&&(v.style.borderColor=u.underlineColor),u.underlineThickness&&(v.style.borderBottomWidth=`${u.underlineThickness}px`),u.underlineOffset&&(v.style.paddingBottom=`${u.underlineOffset}px`),t.appendChild(v)})}),n=r},setVisible:r=>{r?t.classList.remove("hidden"):t.classList.add("hidden")}}},jt=(e,t,n)=>Ge(go(e),e,t,n),Ft=e=>{const{top:t,left:n}=e.getBoundingClientRect(),{innerWidth:o,innerHeight:i}=window,s=-n,r=-t,a=o-n,l=i-t;return{top:t,left:n,minX:s,minY:r,maxX:a,maxY:l}},Wt=e=>{let t=new Set;return o=>{const i=o.map(s=>s.id);(t.size!==i.length||i.some(s=>!t.has(s)))&&e.set(i),t=new Set(i)}};function zt(e,t,n=0,o=e.length-1,i=po){for(;o>n;){if(o-n>600){const l=o-n+1,d=t-n+1,h=Math.log(l),f=.5*Math.exp(2*h/3),b=.5*Math.sqrt(h*f*(l-f)/l)*(d-l/2<0?-1:1),m=Math.max(n,Math.floor(t-d*f/l+b)),c=Math.min(o,Math.floor(t+(l-d)*f/l+b));zt(e,t,m,c,i)}const s=e[t];let r=n,a=o;for(be(e,n,t),i(e[o],s)>0&&be(e,n,o);r<a;){for(be(e,r,a),r++,a--;i(e[r],s)<0;)r++;for(;i(e[a],s)>0;)a--}i(e[n],s)===0?be(e,n,a):(a++,be(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function be(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function po(e,t){return e<t?-1:e>t?1:0}class mo{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!De(t,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;De(t,l)&&(n.leaf?o.push(a):ot(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!De(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(De(t,r)){if(n.leaf||ot(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=de([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),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 h=yo(t,o.children,n);if(h!==-1)return o.children.splice(h,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(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,a;if(s<=r)return a=de(t.slice(n,o+1)),ce(a,this.toBBox),a;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),a=de([]),a.leaf=!1,a.height=i;const l=Math.ceil(s/r),d=l*Math.ceil(Math.sqrt(r));qt(t,n,o,d,this.compareMinX);for(let h=n;h<=o;h+=d){const f=Math.min(h+d-1,o);qt(t,h,f,l,this.compareMinY);for(let b=h;b<=f;b+=l){const m=Math.min(b+l-1,f);a.children.push(this._build(t,b,m,i-1))}}return ce(a,this.toBBox),a}_chooseSubtree(t,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],h=nt(d),f=wo(t,d)-h;f<r?(r=f,s=h<s?h:s,a=d):f===r&&h<s&&(s=h,a=d)}n=a||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),we(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),a=de(o.children.splice(r,o.children.length-r));a.height=o.height,a.leaf=o.leaf,ce(o,this.toBBox),ce(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(o,a)}_splitRoot(t,n){this.data=de([t,n]),this.data.height=t.height+1,this.data.leaf=!1,ce(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let a=n;a<=o-n;a++){const l=Ae(t,0,a,this.toBBox),d=Ae(t,a,o,this.toBBox),h=Eo(l,d),f=nt(l)+nt(d);h<s?(s=h,i=a,r=f<r?f:r):h===s&&f<r&&(r=f,i=a)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:bo,s=t.leaf?this.compareMinY:Ao,r=this._allDistMargin(t,n,o,i),a=this._allDistMargin(t,n,o,s);r<a&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=Ae(t,0,n,s),a=Ae(t,o-n,o,s);let l=Ue(r)+Ue(a);for(let d=n;d<o-n;d++){const h=t.children[d];we(r,t.leaf?s(h):h),l+=Ue(r)}for(let d=o-n-1;d>=n;d--){const h=t.children[d];we(a,t.leaf?s(h):h),l+=Ue(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)we(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():ce(t[n],this.toBBox)}}function yo(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function ce(e,t){Ae(e,0,e.children.length,t,e)}function Ae(e,t,n,o,i){i||(i=de(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];we(i,e.leaf?o(r):r)}return i}function we(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function bo(e,t){return e.minX-t.minX}function Ao(e,t){return e.minY-t.minY}function nt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ue(e){return e.maxX-e.minX+(e.maxY-e.minY)}function wo(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Eo(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function ot(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function De(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function de(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function qt(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;zt(e,r,t,n,i),s.push(t,r,r,n)}}const vo=(e,t,n,o,i)=>{const s=new mo,r=new Map,a=xt(),l=(C,R)=>{const I=C.selector.flatMap(M=>{const O=(i?i(M,t):je(M,t))?.range;return Xt(O)}),Y=$t(I,n,o).map(M=>Ht(M,R));return Y.map(M=>{const{x:O,y:p,width:A,height:w}=M;return{minX:O,minY:p,maxX:O+A,maxY:p+w,annotation:{id:C.annotation,rects:Y}}})},d=()=>[...r.values()],h=()=>{s.clear(),r.clear()},f=C=>{const R=l(C,t.getBoundingClientRect());R.length!==0&&(R.forEach(I=>s.insert(I)),r.set(C.annotation,R))},b=C=>{const R=r.get(C.annotation);R&&(R.forEach(I=>s.remove(I)),r.delete(C.annotation))},m=C=>{b(C),f(C)},c=(C,R=!0)=>{R&&h();const I=t.getBoundingClientRect(),Y=C.map(O=>({target:O,rects:l(O,I)}));Y.forEach(({target:O,rects:p})=>{p.length>0&&r.set(O.annotation,p)});const M=Y.flatMap(({rects:O})=>O);s.load(M)},y=(C,R,I=!1)=>{const Y=s.search({minX:C,minY:R,maxX:C,maxY:R}),M=O=>O.annotation.rects.reduce((p,A)=>p+A.width*A.height,0);return Y.length>0?(Y.sort((O,p)=>M(O)-M(p)),I?Y.map(O=>O.annotation.id):[Y[0].annotation.id]):[]},E=C=>{const R=g(C);if(R.length===0)return;let I=R[0].left,Y=R[0].top,M=R[0].right,O=R[0].bottom;for(let p=1;p<R.length;p++){const A=R[p];I=Math.min(I,A.left),Y=Math.min(Y,A.top),M=Math.max(M,A.right),O=Math.max(O,A.bottom)}return new DOMRect(I,Y,M-I,O-Y)},g=C=>{const R=r.get(C);return R?R[0].annotation.rects:[]};return{all:d,clear:h,getAt:y,getAnnotationBounds:E,getAnnotationRects:g,getIntersecting:(C,R,I,Y)=>{const M=s.search({minX:C,minY:R,maxX:I,maxY:Y}),O=new Set(M.map(p=>p.annotation.id));return Array.from(O).map(p=>({annotation:e.getAnnotation(p),rects:g(p)})).filter(p=>!!p.annotation)},insert:f,recalculate:()=>{c(e.all().map(C=>C.target),!0),a.emit("recalculate")},remove:b,set:c,size:()=>s.all().length,update:m,on:(C,R)=>a.on(C,R)}},Gt=(e,t)=>{const n=Un(),o=vo(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance,t.selectorReviveFn),i=vn(n,t.userSelectAction,t.adapter),s=En(n),r=Vn(),a=(u,v=_.LOCAL)=>{const k=Oe(u,e,t.selectorReviveFn),L=J(k.target.selector);return L&&n.addAnnotation(k,v),L},l=(u,v=!0,k=_.LOCAL)=>{const L=u.map(R=>Oe(R,e)),C=L.filter(R=>!J(R.target.selector));return n.bulkAddAnnotations(L,v,k),C},d=(u,v=_.LOCAL)=>{const k=u.map(C=>Oe(C,e)),L=k.filter(C=>!J(C.target.selector));return k.forEach(C=>{n.getAnnotation(C.id)?n.updateAnnotation(C,v):n.addAnnotation(C,v)}),L},h=(u,v=_.LOCAL)=>{const k=pe(u,e);n.updateTarget(k,v)},f=(u,v=_.LOCAL)=>{const k=u.map(L=>pe(L,e));n.bulkUpdateTargets(k,v)};function b(u,v,k,L){const C=k||!!L,R=o.getAt(u,v,C).map(Y=>n.getAnnotation(Y)).filter(Boolean),I=L?R.filter(L):R;if(I.length!==0)return k?I:I[0]}const m=u=>o.getAnnotationRects(u).length>0?o.getAnnotationBounds(u):void 0,c=(u,v,k,L)=>o.getIntersecting(u,v,k,L),y=u=>o.getAnnotationRects(u),E=()=>o.recalculate(),g=u=>o.on("recalculate",u);return n.observe(({changes:u})=>{const v=(u.deleted||[]).filter(C=>J(C.target.selector)),k=(u.created||[]).filter(C=>J(C.target.selector)),L=(u.updated||[]).filter(C=>J(C.newValue.target.selector));v?.length>0&&v.forEach(C=>o.remove(C.target)),k.length>0&&o.set(k.map(C=>C.target),!1),L?.length>0&&L.forEach(({newValue:C})=>o.update(C.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotations:l,bulkUpdateTargets:f,bulkUpsertAnnotations:d,getAnnotationBounds:m,getAnnotationRects:y,getIntersecting:c,getAt:b,recalculatePositions:E,onRecalculatePositions:g,updateTarget:h},selection:i,hover:s,viewport:r}};function So(e,t=100,n={}){if(typeof e!="function")throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");if(typeof n=="boolean")throw new TypeError("The `options` parameter must be an object, not a boolean. Use `{immediate: true}` instead.");const{immediate:o}=n;let i,s,r,a,l;function d(){const b=i,m=s;return i=void 0,s=void 0,l=e.apply(b,m),l}function h(){const b=Date.now()-a;b<t&&b>=0?r=setTimeout(h,t-b):(r=void 0,o||(l=d()))}const f=function(...b){if(i&&this!==i&&Object.getPrototypeOf(this)===Object.getPrototypeOf(i))throw new Error("Debounced method called with different contexts of the same prototype.");i=this,s=b,a=Date.now();const m=o&&!r;if(r||(r=setTimeout(h,t)),m)return l=d(),l};return Object.defineProperty(f,"isPending",{get(){return r!==void 0}}),f.clear=()=>{r&&(clearTimeout(r),r=void 0,i=void 0,s=void 0)},f.flush=()=>{r&&f.trigger()},f.trigger=()=>{l=d(),f.clear()},f}const it=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function st(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent(`on${t}`,n)}function Ee(e,t,n,o){e&&(e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent(`on${t}`,n))}function Qt(e,t){const n=t.slice(0,t.length-1),o=[];for(let i=0;i<n.length;i++)o.push(e[n[i].toLowerCase()]);return o}function Jt(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function Co(e,t){const n=e.length>=t.length?e:t,o=e.length>=t.length?t:e;let i=!0;for(let s=0;s<n.length;s++)o.indexOf(n[s])===-1&&(i=!1);return i}function Zt(e){let t=e.keyCode||e.which||e.charCode;return e.key&&/^[a-z]$/i.test(e.key)?e.key.toUpperCase().charCodeAt(0):(e.code&&/^Key[A-Z]$/.test(e.code)&&(t=e.code.charCodeAt(3)),t)}const ve={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,arrowup:38,arrowdown:40,arrowleft:37,arrowright:39,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,"-":it?173:189,"=":it?61:187,";":it?59:186,"'":222,"{":219,"}":221,"[":219,"]":221,"\\":220},q={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,meta:91,command:91},Se={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},P={16:!1,18:!1,17:!1,91:!1},V={};for(let e=1;e<20;e++)ve[`f${e}`]=111+e;let K=[],Ce=null,ue=null,en="all";const ne=new Map,fe=e=>ve[e.toLowerCase()]||q[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),To=e=>Object.keys(ve).find(t=>ve[t]===e),xo=e=>Object.keys(q).find(t=>q[t]===e),tn=e=>{en=e||"all"},Te=()=>en||"all",Lo=()=>K.slice(0),Ro=()=>K.map(e=>To(e)||xo(e)||String.fromCharCode(e)),Oo=()=>{const e=[];return Object.keys(V).forEach(t=>{V[t].forEach(({key:n,scope:o,mods:i,shortcut:s})=>{e.push({scope:o,shortcut:s,mods:i,keys:n.split("+").map(r=>fe(r))})})}),e},nn=e=>{const t=e.target||e.srcElement,{tagName:n}=t;let o=!0;const i=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(i||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(o=!1),o},ko=e=>(typeof e=="string"&&(e=fe(e)),K.indexOf(e)!==-1),Mo=(e,t)=>{let n,o;e||(e=Te());for(const i in V)if(Object.prototype.hasOwnProperty.call(V,i))for(n=V[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(({element:r})=>rt(r)):o++;Te()===e&&tn(t||"all")};function Bo(e){let t=Zt(e);e.key&&e.key.toLowerCase()==="capslock"&&(t=fe(e.key));const n=K.indexOf(t);if(n>=0&&K.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&K.splice(0,K.length),(t===93||t===224)&&(t=91),t in P){P[t]=!1;for(const o in q)q[o]===t&&(G[o]=!1)}}const on=(e,...t)=>{if(typeof e>"u")Object.keys(V).forEach(n=>{Array.isArray(V[n])&&V[n].forEach(o=>Ke(o)),delete V[n]}),rt(null);else if(Array.isArray(e))e.forEach(n=>{n.key&&Ke(n)});else if(typeof e=="object")e.key&&Ke(e);else if(typeof e=="string"){let[n,o]=t;typeof n=="function"&&(o=n,n=""),Ke({key:e,scope:n,method:o,splitKey:"+"})}},Ke=({key:e,scope:t,method:n,splitKey:o="+"})=>{Jt(e).forEach(s=>{const r=s.split(o),a=r.length,l=r[a-1],d=l==="*"?"*":fe(l);if(!V[d])return;t||(t=Te());const h=a>1?Qt(q,r):[],f=[];V[d]=V[d].filter(b=>{const c=(n?b.method===n:!0)&&b.scope===t&&Co(b.mods,h);return c&&f.push(b.element),!c}),f.forEach(b=>rt(b))})};function sn(e,t,n,o){if(t.element!==o)return;let i;if(t.scope===n||t.scope==="all"){i=t.mods.length>0;for(const s in P)Object.prototype.hasOwnProperty.call(P,s)&&(!P[s]&&t.mods.indexOf(+s)>-1||P[s]&&t.mods.indexOf(+s)===-1)&&(i=!1);(t.mods.length===0&&!P[16]&&!P[18]&&!P[17]&&!P[91]||i||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(K),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function rn(e,t){const n=V["*"];let o=Zt(e);if(e.key&&e.key.toLowerCase()==="capslock"||!(G.filter||nn).call(this,e))return;if((o===93||o===224)&&(o=91),K.indexOf(o)===-1&&o!==229&&K.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(l=>{const d=Se[l];e[l]&&K.indexOf(d)===-1?K.push(d):!e[l]&&K.indexOf(d)>-1?K.splice(K.indexOf(d),1):l==="metaKey"&&e[l]&&(K=K.filter(h=>h in Se||h===o))}),o in P){P[o]=!0;for(const l in q)if(Object.prototype.hasOwnProperty.call(q,l)){const d=Se[q[l]];G[l]=e[d]}if(!n)return}for(const l in P)Object.prototype.hasOwnProperty.call(P,l)&&(P[l]=e[Se[l]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(K.indexOf(17)===-1&&K.push(17),K.indexOf(18)===-1&&K.push(18),P[17]=!0,P[18]=!0);const s=Te();if(n)for(let l=0;l<n.length;l++)n[l].scope===s&&(e.type==="keydown"&&n[l].keydown||e.type==="keyup"&&n[l].keyup)&&sn(e,n[l],s,t);if(!(o in V))return;const r=V[o],a=r.length;for(let l=0;l<a;l++)if((e.type==="keydown"&&r[l].keydown||e.type==="keyup"&&r[l].keyup)&&r[l].key){const d=r[l],{splitKey:h}=d,f=d.key.split(h),b=[];for(let m=0;m<f.length;m++)b.push(fe(f[m]));b.sort().join("")===K.sort().join("")&&sn(e,d,s,t)}}const G=function e(t,n,o){K=[];const i=Jt(t);let s=[],r="all",a=document,l=0,d=!1,h=!0,f="+",b=!1,m=!1;if(o===void 0&&typeof n=="function"&&(o=n),Object.prototype.toString.call(n)==="[object Object]"){const c=n;c.scope&&(r=c.scope),c.element&&(a=c.element),c.keyup&&(d=c.keyup),c.keydown!==void 0&&(h=c.keydown),c.capture!==void 0&&(b=c.capture),typeof c.splitKey=="string"&&(f=c.splitKey),c.single===!0&&(m=!0)}for(typeof n=="string"&&(r=n),m&&on(t,r);l<i.length;l++){const c=i[l].split(f);s=[],c.length>1&&(s=Qt(q,c));let y=c[c.length-1];y=y==="*"?"*":fe(y),y in V||(V[y]=[]),V[y].push({keyup:d,keydown:h,scope:r,mods:s,shortcut:i[l],method:o,key:i[l],splitKey:f,element:a})}if(typeof a<"u"&&typeof window<"u"){if(!ne.has(a)){const c=(E=window.event)=>rn(E,a),y=(E=window.event)=>{rn(E,a),Bo(E)};ne.set(a,{keydownListener:c,keyupListenr:y,capture:b}),st(a,"keydown",c,b),st(a,"keyup",y,b)}if(!Ce){const c=()=>{K=[]};Ce={listener:c,capture:b},st(window,"focus",c,b)}if(!ue&&typeof document<"u"){const c=()=>{K=[];for(const g in P)P[g]=!1;for(const g in q)e[g]=!1},y=c,E=c;document.addEventListener("fullscreenchange",y),document.addEventListener("webkitfullscreenchange",E),ue={fullscreen:y,webkit:E}}}};function No(e,t="all"){Object.keys(V).forEach(n=>{V[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method({},i)})})}function rt(e){const t=Object.values(V).flat();if(t.findIndex(({element:o})=>o===e)<0&&e){const{keydownListener:o,keyupListenr:i,capture:s}=ne.get(e)||{};o&&i&&(Ee(e,"keyup",i,s),Ee(e,"keydown",o,s),ne.delete(e))}if(t.length<=0||ne.size<=0){if(Array.from(ne.keys()).forEach(i=>{const{keydownListener:s,keyupListenr:r,capture:a}=ne.get(i)||{};s&&r&&(Ee(i,"keyup",r,a),Ee(i,"keydown",s,a),ne.delete(i))}),ne.clear(),Object.keys(V).forEach(i=>delete V[i]),Ce){const{listener:i,capture:s}=Ce;Ee(window,"focus",i,s),Ce=null}ue&&typeof document<"u"&&(document.removeEventListener("fullscreenchange",ue.fullscreen),document.removeEventListener("webkitfullscreenchange",ue.webkit),ue=null)}}const at={getPressedKeyString:Ro,setScope:tn,getScope:Te,deleteScope:Mo,getPressedKeyCodes:Lo,getAllKeyCodes:Oo,isPressed:ko,filter:nn,trigger:No,unbind:on,keyMap:ve,modifier:q,modifierMap:Se};for(const e in at){const t=e;Object.prototype.hasOwnProperty.call(at,t)&&(G[t]=at[t])}if(typeof window<"u"){const e=window.hotkeys;G.noConflict=t=>(t&&window.hotkeys===G&&(window.hotkeys=e),G),window.hotkeys=G}async function _o(e,t,n=(()=>!1)){do{if(await e(),await n())break;const o=t;await new Promise((i=>setTimeout(i,Math.max(0,o))))}while(!await n())}const an=300,ln=["up","down","left","right"],cn=Pe?"⌘+a":"ctrl+a",Io=[...ln.map(e=>`shift+${e}`),cn],dn=(e,t,n,o)=>{const{store:i,selection:s}=t;let r;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:d,dismissOnNotAnnotatable:h="NEVER"}=o;let f,b=a,m="CREATE_NEW",c,y,E,g;const u=S=>{b=S,I.clear(),S||(y=void 0,c=void 0,E=void 0,g=void 0)},v=S=>m=S||"CREATE_NEW",k=S=>f=S,L=S=>r=S,C=S=>{if(m==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const B=S;return Pe?B.metaKey:B.ctrlKey}else return!1},R=()=>{if(!b||E===!1)return;const{selected:S}=s;if((C(g)||m==="REPLACE_CURRENT")&&S.length===1&&S[0].editable){const F=i.getAnnotation(S[0].id);if(F?.target){y=F.target,c={annotation:F.id,selector:[],created:y.created,creator:y.creator,updated:new Date,updatedBy:r};return}}y=void 0,c={annotation:lt(),selector:[],created:new Date,creator:r}},I=So(S=>{if(!b)return;const B=document.getSelection();if(!B?.anchorNode)return;const ie=N().map(j=>ht(j,e));if(ie.every(j=>!$e(e,j))){c=void 0;return}const se=S.timeStamp-(g?.timeStamp||S.timeStamp);if(g?.type==="pointerdown"&&(se<1e3&&!c||B.isCollapsed&&se<an)&&R(),!c&&(R(),!c))return;if(B.isCollapsed){i.getAnnotation(c.annotation)&&!(C(g)||m==="REPLACE_CURRENT")&&(s.clear(),i.deleteAnnotation(c.annotation));return}if(ie.every(j=>ct(j)))return;const Z=ie.flatMap(j=>ft(e,j.cloneRange()));if(!(Z.length>0&&!c||Z.length!==c.selector.length||Z.some((j,xe)=>j.toString()!==c?.selector[xe]?.quote)))return;const Ye=C(g)&&y?dt([...y.selector.map(j=>j.range),...Z]):Z;c={...c,selector:Ye.map(j=>mt(j,e,l)),updated:new Date},!(C(g)||m==="REPLACE_CURRENT")&&(i.getAnnotation(c.annotation)?i.updateTarget(c,_.LOCAL):s.clear())},10),Y=S=>{g=Be(S),E=g.button===0},M=async S=>{if(!E)return;const B=Be(S),F=()=>{const{x:se,y:Z}=e.getBoundingClientRect();if(ge(e,B.target)){(typeof h=="function"?h(B,e):h==="ALWAYS")&&s.clear();return}const re=B.target instanceof Node&&e.contains(B.target)&&i.getAt(B.clientX-se,B.clientY-Z,d==="all",f);if(re){const{selected:Ye}=s,j=new Set(Ye.map(Le=>Le.id)),xe=Array.isArray(re)?re.map(Le=>Le.id):[re.id];(j.size!==xe.length||!xe.every(Le=>j.has(Le)))&&(n.emit("clickAnnotation",re),s.userSelect(xe,B))}else s.clear()};if(B.timeStamp-(g?.timeStamp||0)<an){await O();const se=document.getSelection(),Z=ge(e,g?.target),re=ge(e,B.target);if(se?.isCollapsed||Z&&re){c=void 0,F();return}}c&&c.selector.length>0&&(D(),s.userSelect(c.annotation,B))},O=async()=>{const S=document.getSelection();let B=!1,F=S?.isCollapsed;const ie=()=>F||B,se=1;return setTimeout(()=>B=!0,50),_o(()=>F=S?.isCollapsed,se,ie)},p=S=>{document.getSelection()?.isCollapsed||((!c||c.selector.length===0)&&I(S),c&&(D(),s.userSelect(c.annotation,Be(S))))},A=S=>{if(b&&!S.repeat&&N().length!==0&&S.key==="Shift"&&c){const B=document.getSelection();B&&!B.isCollapsed&&(D(),s.userSelect(c.annotation,me(S)))}},w=S=>{const B=()=>setTimeout(()=>{c&&(c.selector.length>0&&(s.clear(),i.addAnnotation({id:c.annotation,bodies:[],target:c}),s.userSelect(c.annotation,me(S))),document.removeEventListener("selectionchange",B))},100);document.addEventListener("selectionchange",B),R()};G(Io.join(","),{element:e,keydown:!0,keyup:!1},S=>{S.repeat||(g=me(S))}),G(cn,{keydown:!0,keyup:!1},S=>{g=me(S),w(S)});const T=S=>{S.repeat||N().length!==0&&(c=void 0,s.clear())};G(ln.join(","),{keydown:!0,keyup:!1},T),document.addEventListener("pointerdown",Y),document.addEventListener("pointerup",M),document.addEventListener("contextmenu",p),document.addEventListener("keyup",A),e.addEventListener("selectstart",R),document.addEventListener("selectionchange",I);const U=()=>{c=void 0,y=void 0,E=void 0,g=void 0,I.clear(),document.removeEventListener("pointerdown",Y),document.removeEventListener("pointerup",M),document.removeEventListener("contextmenu",p),document.removeEventListener("keyup",A),e.removeEventListener("selectstart",R),document.removeEventListener("selectionchange",I),G.unbind()},N=()=>{const S=document.getSelection();return S?Array.from(Array(S.rangeCount).keys()).map(B=>S.getRangeAt(B)).filter(B=>B.intersectsNode(e)):[]},D=()=>{if(!c)return;const S=i.getAnnotation(c.annotation);if(!S)i.addAnnotation({id:c.annotation,bodies:[],target:c});else{const{target:{updated:B}}=S,{updated:F}=c;(!B||!F||B<F)&&i.updateTarget(c)}};return{destroy:U,setFilter:k,setUser:L,setAnnotatingEnabled:u,setAnnotatingMode:v}},Uo=e=>[`background-color:${z(e?.fill||te.fill).alpha(e?.fillOpacity===void 0?te.fillOpacity:e.fillOpacity).toHex()}`,e?.underlineThickness?"text-decoration:underline":void 0,e?.underlineColor?`text-decoration-color:${e.underlineColor}`:void 0,e?.underlineOffset?`text-underline-offset:${e.underlineOffset}px`:void 0,e?.underlineThickness?`text-decoration-thickness:${e.underlineThickness}px`:void 0].filter(Boolean).join(";"),Do=()=>{const e=document.createElement("style");document.getElementsByTagName("head")[0].appendChild(e);let t=new Set;return{destroy:()=>{CSS.highlights.clear(),e.remove()},setVisible:s=>{console.log("setVisible not implemented on CSS Custom Highlights renderer")},redraw:(s,r,a,l,d)=>{const h=new Set(s.map(b=>b.annotation.id));Array.from(t).filter(b=>!h.has(b));const f=s.map(b=>{a?typeof a=="function"&&a(b.annotation,b.state):b.state?.selected;const m=et(b,a);return`::highlight(_${b.annotation.id}) { ${Uo(m)} }`});e.innerHTML=f.join(`
2
- `),CSS.highlights.clear(),s.forEach(({annotation:b})=>{const m=b.target.selector.map(y=>y.range),c=new Highlight(...m);CSS.highlights.set(`_${b.id}`,c)}),t=h}}},Ko=(e,t,n)=>Ge(Do(),e,t,n),un=(e,t)=>({...e,annotatingEnabled:e.annotatingEnabled??t.annotatingEnabled,user:e.user||t.user}),fn="SPANS",Yo=(e,t={})=>{Lt(e),ut(e);const n=un(t,{annotatingEnabled:!0,user:qn()}),o=Gt(e,n),{selection:i,viewport:s}=o,r=o.store,a=Yn(r),l=Pn(o,a,n.adapter);let d=n.user;const h=typeof n.renderer!="function"?n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":fn:n.renderer||fn:null,f=h===null?n.renderer(e,o,s):h==="SPANS"?jt(e,o,s):h==="CSS_HIGHLIGHTS"?Ko(e,o,s):void 0;if(!f)throw`Unknown renderer implementation: ${n.renderer}`;console.debug(h?`Using ${h} renderer`:"Using custom renderer implementation"),n.style&&f.setStyle(n.style);const b=dn(e,o,l,n);b.setUser(d);const m=$n(o,a,n.adapter),c=()=>d,y=L=>{b.setAnnotatingEnabled(L===void 0?!0:L)},E=L=>{b.setAnnotatingMode(L)},g=L=>{f.setFilter(L),b.setFilter(L)},u=L=>{d=L,b.setUser(L)},v=L=>{L?i.setSelected(L):i.clear()};return{...m,destroy:()=>{f.destroy(),b.destroy(),a.destroy()},element:e,getUser:c,renderer:f,setAnnotatingEnabled:y,setAnnotatingMode:E,setFilter:g,setStyle:f.setStyle.bind(f),setUser:u,setSelected:v,setVisible:f.setVisible.bind(f),on:l.on,off:l.off,scrollIntoView:At(e,r),state:o}};x.DEFAULT_SELECTED_STYLE=Ie,x.DEFAULT_STYLE=te,x.NOT_ANNOTATABLE_CLASS=Xe,x.NOT_ANNOTATABLE_SELECTOR=ae,x.Origin=_,x.UserSelectAction=We,x.W3CTextFormat=Zn,x.cancelSingleClickEvents=Lt,x.cloneKeyboardEvent=me,x.clonePointerEvent=Be,x.computeStyle=et,x.computeZIndex=Pt,x.createBody=Rn,x.createRenderer=Ge,x.createSelectionHandler=dn,x.createSpansRenderer=jt,x.createTextAnnotator=Yo,x.createTextAnnotatorState=Gt,x.debounce=Ne,x.fillDefaults=un,x.getBackgroundColor=Yt,x.getHighlightClientRects=Xt,x.getQuoteContext=pt,x.getRangeAnnotatableContents=Re,x.getViewportBounds=Ft,x.isMac=Pe,x.isNodeWhitespaceOrEmpty=yn,x.isNotAnnotatable=ge,x.isRangeAnnotatable=$e,x.isRangeWhitespaceOrEmpty=ct,x.isRevived=J,x.isRevivedAnnotation=he,x.isRevivedTarget=Ve,x.mergeClientRects=$t,x.mergeRanges=dt,x.parseW3CTextAnnotation=Ct,x.programmaticallyFocusable=ut,x.rangeToSelector=mt,x.reviveAnnotation=Oe,x.reviveTarget=pe,x.reviveTextSelector=je,x.scrollIntoView=At,x.serializeW3CTextAnnotation=Tt,x.splitAnnotatableRanges=ft,x.toDomRectList=fo,x.toParentBounds=Ht,x.toViewportBounds=ho,x.trackViewport=Wt,x.trimRangeToContainer=ht,x.whitespaceOrEmptyRegex=He,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(L,he){typeof exports=="object"&&typeof module<"u"?he(exports):typeof define=="function"&&define.amd?define(["exports"],he):(L=typeof globalThis<"u"?globalThis:L||self,he(L.RecogitoJS={}))})(this,(function(L){"use strict";const he=e=>e.target.selector.every(Z),fn=e=>e.selector.every(Z);function Z(e){return Array.isArray(e)?e.every(t=>"range"in t&&t.range instanceof Range&&!t.range.collapsed):"range"in e&&e.range instanceof Range&&!e.range.collapsed}const $=[];for(let e=0;e<256;++e)$.push((e+256).toString(16).slice(1));function hn(e,t=0){return($[e[t+0]]+$[e[t+1]]+$[e[t+2]]+$[e[t+3]]+"-"+$[e[t+4]]+$[e[t+5]]+"-"+$[e[t+6]]+$[e[t+7]]+"-"+$[e[t+8]]+$[e[t+9]]+"-"+$[e[t+10]]+$[e[t+11]]+$[e[t+12]]+$[e[t+13]]+$[e[t+14]]+$[e[t+15]]).toLowerCase()}const gn=new Uint8Array(16);function pn(){return crypto.getRandomValues(gn)}function at(e,t,n){return crypto.randomUUID?crypto.randomUUID():mn(e)}function mn(e,t,n){e=e||{};const o=e.random??e.rng?.()??pn();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,hn(o)}const Ye=typeof navigator<"u"&&navigator.platform.startsWith("Mac"),Ke="not-annotatable",ae=`.${Ke}`,ge=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(ae):t.parentElement?.closest(ae)):!0,Pe=(e,t)=>{const n=t.commonAncestorContainer;return!ge(e,n)},Ve=/^\s*$/,lt=e=>Ve.test(e.toString()),yn=e=>Ve.test(e.textContent||""),ct=e=>{if(e.length===0)return[];if(e.length===1)return[e[0]];e.sort((i,r)=>{const s=i.compareBoundaryPoints(Range.START_TO_START,r);return s!==0?s:i.compareBoundaryPoints(Range.END_TO_END,r)});const[t,...n]=e,o=n.reduce((i,r)=>i.current.compareBoundaryPoints(Range.START_TO_END,r)>=0?(i.current.compareBoundaryPoints(Range.END_TO_END,r)<0&&i.current.setEnd(r.endContainer,r.endOffset),i):(i.merged.push(i.current),i.current=r.cloneRange(),i),{merged:[],current:t.cloneRange()});return[...o.merged,o.current]},dt=e=>{(!e.hasAttribute("tabindex")||e.tabIndex<-1)&&e.setAttribute("tabindex","-1"),e.classList.add("no-focus-outline")},bn=function*(e){const t=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(Ke)&&!o.parentElement?.closest(ae)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},ut=(e,t)=>{if(!Pe(e,t))return[];const n=[];let o=null;for(const i of bn(t)){let r;o?(r=document.createRange(),r.setStartAfter(o),r.setEndBefore(i)):(r=t.cloneRange(),r.setEndBefore(i)),r.collapsed||n.push(r),o=i}if(o){const i=t.cloneRange();i.setStartAfter(o),i.collapsed||n.push(i)}return n.length>0?n:[t]},Re=e=>{const t=e.cloneContents();return t.querySelectorAll(ae).forEach(n=>n.remove()),t},ft=(e,t)=>{const n=e.cloneRange();return t.contains(n.startContainer)||n.setStart(t,0),t.contains(n.endContainer)||n.setEnd(t,t.childNodes.length),n},ht=new Intl.Segmenter(void 0,{granularity:"grapheme"}),gt=(e,t,n=10,o)=>{const i=o?e.startContainer.parentElement.closest(o):t,r=document.createRange();r.setStart(i,0),r.setEnd(e.startContainer,e.startOffset);const s=Re(r).textContent,a=document.createRange();a.setStart(e.endContainer,e.endOffset),i===document.body?a.setEnd(i,i.childNodes.length):a.setEndAfter(i);const l=Re(a).textContent,d=[...ht.segment(s)],u=[...ht.segment(l)];return{prefix:d.slice(-n).map(f=>f.segment).join(""),suffix:u.slice(0,n).map(f=>f.segment).join("")}},pt=(e,t,n)=>{const o=document.createRange(),i=n?e.startContainer.parentElement.closest(n):t;o.setStart(i,0),o.setEnd(e.startContainer,e.startOffset);const r=Re(o).textContent,s=e.toString(),a=r.length||0,l=a+s.length;return n?{quote:s,start:a,end:l,range:e,offsetReference:i}:{quote:s,start:a,end:l,range:e}},Xe=(e,t)=>{if(Z(e))return e;const{start:n,end:o}=e,i=e.offsetReference||t,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,u=>u.parentElement?.closest(ae)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT);let s=0;const a=document.createRange();let l=r.nextNode();l===null&&console.error("Could not revive annotation target. Content missing.");let d=!i;for(;l!==null;){if(d||=typeof i?.contains=="function"?i.contains(l):!1,d){const u=l.textContent?.length||0;if(s+u>n){a.setStart(l,n-s);break}s+=u}l=r.nextNode()}for(;l!==null;){const u=l.textContent?.length||0;if(s+u>=o){a.setEnd(l,o-s);break}s+=u,l=r.nextNode()}return{...e,range:a}},pe=(e,t,n=(o,i)=>Xe(o,i))=>({...e,selector:e.selector.map(o=>n(o,t))}),$e=(e,t,n)=>({...e,target:pe(e.target,t,n)}),mt=e=>{if(!e)return document.scrollingElement;const{overflowY:t}=window.getComputedStyle(e);return t!=="visible"&&t!=="hidden"&&e.scrollHeight>e.clientHeight?e:mt(e.parentElement)},yt=(e,t,n)=>{const o=n.getBoundingClientRect(),i=n.clientHeight,r=n.clientWidth,s=t.selector[0].range.getBoundingClientRect(),{width:a,height:l}=e.getAnnotationBounds(t.annotation),d=s.top-o.top,u=s.left-o.left,f=n.parentElement?n.scrollTop:0,y=n.parentElement?n.scrollLeft:0,p=d+f-(i-l)/2,c=u+y-(r-a)/2;n.scroll({top:p,left:c,behavior:"smooth"})},bt=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,r=o?typeof o=="string"?document.getElementById(o):o:mt(e);if(!r)return console.warn(`The scroll parent is missing for the annotation: ${i}`,{container:e}),!1;const s=t.getAnnotation(i);if(!s)return console.warn(`The annotation is missing in the store: ${i}`),!1;const{range:a}=s.target.selector[0];if(a&&!a.collapsed)return yt(t,s.target,r),!0;const l=pe(s.target,e),{range:d}=l.selector[0];return d&&!d.collapsed?(yt(t,l,r),!0):!1};var At=Object.prototype.hasOwnProperty;function le(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&le(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(At.call(e,n)&&++o&&!At.call(t,n)||!(n in t)||!le(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const An=Symbol("clean");let Q=[],ie=0;const Oe=4,wn=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),He=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(o){return n.lc=t.push(o),()=>{for(let r=ie+Oe;r<Q.length;)Q[r]===o?Q.splice(r,Oe):r+=Oe;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){wn.epoch++;let r=!Q.length;for(let s of t)Q.push(s,n.value,o,i);if(r){for(ie=0;ie<Q.length;ie+=Oe)Q[ie](Q[ie+1],Q[ie+2],Q[ie+3]);Q.length=0}},off(){},set(o){let i=n.value;i!==o&&(n.value=o,n.notify(i))},subscribe(o){let i=n.listen(o);return o(n.value),i},value:e};return process.env.NODE_ENV!=="production"&&(n[An]=()=>{t=[],n.lc=0,n.off()}),n},En=e=>{const t=He(null);return e.observe(({changes:n})=>{const o=t.get();if(o){(n.deleted||[]).some(r=>r.id===o)&&t.set(null);const i=(n.updated||[]).find(({oldValue:r})=>r.id===o);i&&t.set(i.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var je=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(je||{});const Fe={selected:[]},vn=(e,t,n)=>{const o=He(Fe);let i=t;const r=()=>{le(o.get(),Fe)||o.set(Fe)},s=()=>{var p;return((p=o.get().selected)==null?void 0:p.length)===0},a=p=>{if(s())return!1;const c=typeof p=="string"?p:p.id;return o.get().selected.some(m=>m.id===c)},l=(p,c)=>{let m;if(Array.isArray(p)){if(m=p.map(h=>e.getAnnotation(h)).filter(Boolean),m.length<p.length){console.warn("Invalid selection: "+p.filter(h=>!m.some(g=>g.id===h)));return}}else{const h=e.getAnnotation(p);if(!h){console.warn("Invalid selection: "+p);return}m=[h]}const v=m.reduce((h,g)=>{const x=y(g);return x==="EDIT"?[...h,{id:g.id,editable:!0}]:x==="SELECT"?[...h,{id:g.id}]:h},[]);o.set({selected:v,event:c})},d=(p,c)=>{const m=Array.isArray(p)?p:[p],v=m.map(h=>e.getAnnotation(h)).filter(h=>!!h);o.set({selected:v.map(h=>{const g=c===void 0?y(h)==="EDIT":c;return{id:h.id,editable:g}})}),v.length!==m.length&&console.warn("Invalid selection",p)},u=p=>{if(s())return!1;const{selected:c}=o.get();c.some(({id:m})=>p.includes(m))&&o.set({selected:c.filter(({id:m})=>!p.includes(m))})},f=p=>{i=p,d(o.get().selected.map(({id:c})=>c))},y=p=>Sn(p,i,n);return e.observe(({changes:p})=>u((p.deleted||[]).map(c=>c.id))),{get event(){const p=o.get();return p?p.event:null},get selected(){const p=o.get();return p?[...p.selected]:null},get userSelectAction(){return i},clear:r,evalSelectAction:y,isEmpty:s,isSelected:a,setSelected:d,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:l}},Sn=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},H=[];for(let e=0;e<256;++e)H.push((e+256).toString(16).slice(1));function Cn(e,t=0){return(H[e[t+0]]+H[e[t+1]]+H[e[t+2]]+H[e[t+3]]+"-"+H[e[t+4]]+H[e[t+5]]+"-"+H[e[t+6]]+H[e[t+7]]+"-"+H[e[t+8]]+H[e[t+9]]+"-"+H[e[t+10]]+H[e[t+11]]+H[e[t+12]]+H[e[t+13]]+H[e[t+14]]+H[e[t+15]]).toLowerCase()}const Tn=new Uint8Array(16);function xn(){return crypto.getRandomValues(Tn)}function wt(e,t,n){return crypto.randomUUID?crypto.randomUUID():Ln(e)}function Ln(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??xn();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,Cn(i)}const We=e=>{const t=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{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Rn=(e,t,n,o)=>({id:wt(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),On=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},kn=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Mn=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!le(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Nn=(e,t)=>!le(e.target,t.target),Et=(e,t)=>{const n=On(e,t),o=kn(e,t),i=Mn(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Nn(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var _=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(_||{});const Bn=(e,t)=>{var n,o;const{changes:i,origin:r}=t;if(!(e.options.origin?e.options.origin===r:r!=="SILENT"))return!1;if(e.options.ignore){const{ignore:s}=e.options,a=l=>l&&l.length>0;if(!(a(i.created)||a(i.deleted))){const l=(n=i.updated)==null?void 0:n.some(u=>a(u.bodiesCreated)||a(u.bodiesDeleted)||a(u.bodiesUpdated)),d=(o=i.updated)==null?void 0:o.some(u=>u.targetUpdated);if(s==="BODY_ONLY"&&l&&!d||s==="TARGET_ONLY"&&d&&!l)return!1}}if(e.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(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>s.has(a))}else return!0},_n=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),r=new Set((t.deleted||[]).map(f=>f.id)),s=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),a=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),l=[...(e.created||[]).filter(f=>!r.has(f.id)).map(f=>s.has(f.id)?t.updated.find(({oldValue:y})=>y.id===f.id).newValue:f),...t.created||[]],d=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],u=[...(e.updated||[]).filter(({newValue:f})=>!r.has(f.id)).map(f=>{const{oldValue:y,newValue:p}=f;if(s.has(p.id)){const c=t.updated.find(m=>m.oldValue.id===p.id).newValue;return Et(y,c)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!a.has(f.id))];return{created:l,deleted:d,updated:u}},ze=e=>{const t=e.id===void 0?wt():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},In=e=>e.id!==void 0,Dn=()=>{const e=new Map,t=new Map,n=[],o=(b,A={})=>{n.push({onChange:b,options:A})},i=b=>{const A=n.findIndex(w=>w.onChange==b);A>-1&&n.splice(A,1)},r=(b,A)=>{const w={origin:b,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...e.values()]};n.forEach(T=>{Bn(T,w)&&T.onChange(w)})},s=b=>{e.set(b.id,b),b.bodies.forEach(A=>t.set(A.id,b.id))},a=(b,A=_.LOCAL)=>{if(b.id&&e.get(b.id))throw Error(`Cannot add annotation ${b.id} - exists already`);{const w=ze(b);s(w),r(A,{created:[w]})}},l=(b,A)=>{const w=ze(typeof b=="string"?A:b),T=typeof b=="string"?b:b.id,E=T&&e.get(T);if(E){const O=Et(E,w);return T===w.id?e.set(T,w):(e.delete(T),e.set(w.id,w)),E.bodies.forEach(P=>t.delete(P.id)),w.bodies.forEach(P=>t.set(P.id,w.id)),O}else console.warn(`Cannot update annotation ${T} - does not exist`)},d=(b,A=_.LOCAL,w=_.LOCAL)=>{const T=In(A)?w:A,E=l(b,A);E&&r(T,{updated:[E]})},u=(b,A=_.LOCAL)=>{e.get(b.id)?d(b,A):a(b,A)},f=(b,A=_.LOCAL)=>{const w=b.reduce((T,E)=>{const O=l(E);return O?[...T,O]:T},[]);w.length>0&&r(A,{updated:w})},y=b=>b.map(ze).reduce((A,w)=>e.get(w.id)?{...A,toUpdate:[...A.toUpdate,w]}:{...A,toAdd:[...A.toAdd,w]},{toAdd:[],toUpdate:[]}),p=(b,A=_.LOCAL)=>{const{toAdd:w,toUpdate:T}=y(b),E=T.map(O=>l(O,A)).filter(Boolean);w.forEach(s),r(A,{created:w,updated:E})},c=(b,A=_.LOCAL)=>{const w=e.get(b.annotation);if(w){const T={...w,bodies:[...w.bodies,b]};e.set(w.id,T),t.set(b.id,T.id),r(A,{updated:[{oldValue:w,newValue:T,bodiesCreated:[b]}]})}else console.warn(`Attempt to add body to missing annotation: ${b.annotation}`)},m=()=>[...e.values()],v=(b=_.LOCAL)=>{const A=[...e.values()];e.clear(),t.clear(),r(b,{deleted:A})},h=(b,A=_.LOCAL)=>{const{toAdd:w,toUpdate:T}=y(b),E=new Set([...w,...T].map(j=>j.id)),O=[...e.keys()].filter(j=>!E.has(j)).map(j=>x(j)).filter(Boolean),P=T.map(j=>l(j)).filter(Boolean);w.forEach(s),r(A,{created:w,updated:P,deleted:O})},g=(b,A=!0,w=_.LOCAL)=>{A?h(b,w):p(b,w)},x=b=>{const A=typeof b=="string"?b:b.id,w=e.get(A);if(w)return e.delete(A),w.bodies.forEach(T=>t.delete(T.id)),w;console.warn(`Attempt to delete missing annotation: ${A}`)},k=(b,A=_.LOCAL)=>{const w=x(b);w&&r(A,{deleted:[w]})},R=(b,A=_.LOCAL)=>{const w=b.reduce((T,E)=>{const O=x(E);return O?[...T,O]:T},[]);w.length>0&&r(A,{deleted:w})},S=b=>{const A=e.get(b.annotation);if(A){const w=A.bodies.find(T=>T.id===b.id);if(w){t.delete(w.id);const T={...A,bodies:A.bodies.filter(E=>E.id!==b.id)};return e.set(A.id,T),{oldValue:A,newValue:T,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${b.annotation}`)},C=(b,A=_.LOCAL)=>{const w=S(b);w&&r(A,{updated:[w]})},N=(b,A=_.LOCAL)=>{const w=b.map(T=>S(T)).filter(Boolean);w.length>0&&r(A,{updated:w})},D=b=>{const A=e.get(b);return A?{...A}:void 0},B=b=>{const A=t.get(b);if(A){const w=D(A).bodies.find(T=>T.id===b);if(w)return w;console.error(`Store integrity error: body ${b} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${b}`)},M=(b,A)=>{if(b.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=e.get(b.annotation);if(w){const T=w.bodies.find(O=>O.id===b.id),E={...w,bodies:w.bodies.map(O=>O.id===T.id?A:O)};return e.set(w.id,E),T.id!==A.id&&(t.delete(T.id),t.set(A.id,E.id)),{oldValue:w,newValue:E,bodiesUpdated:[{oldBody:T,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${b.annotation}`)},I=(b,A,w=_.LOCAL)=>{const T=M(b,A);T&&r(w,{updated:[T]})},K=(b,A=_.LOCAL)=>{const w=b.map(T=>M({id:T.id,annotation:T.annotation},T)).filter(Boolean);r(A,{updated:w})},oe=b=>{const A=e.get(b.annotation);if(A){const w={...A,target:{...A.target,...b}};return e.set(A.id,w),{oldValue:A,newValue:w,targetUpdated:{oldTarget:A.target,newTarget:b}}}else console.warn(`Attempt to update target on missing annotation: ${b.annotation}`)};return{addAnnotation:a,addBody:c,all:m,bulkAddAnnotations:g,bulkDeleteAnnotations:R,bulkDeleteBodies:N,bulkUpdateAnnotations:f,bulkUpdateBodies:K,bulkUpdateTargets:(b,A=_.LOCAL)=>{const w=b.map(T=>oe(T)).filter(Boolean);w.length>0&&r(A,{updated:w})},bulkUpsertAnnotations:p,clear:v,deleteAnnotation:k,deleteBody:C,getAnnotation:D,getBody:B,observe:o,syncAnnotations:h,unobserve:i,updateAnnotation:d,updateBody:I,updateTarget:(b,A=_.LOCAL)=>{const w=oe(b);w&&r(A,{updated:[w]})},upsertAnnotation:u}};let Un=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const Yn=250,Kn=(e,t)=>{const n=Un(),o=[];let i=-1,r=!1,s=0;const a=c=>{if(!r){const{changes:m}=c,v=performance.now();if(v-s>Yn)o.splice(i+1),o.push(m),i=o.length-1;else{const h=o.length-1;o[h]=_n(o[h],m)}s=v}r=!1};e.observe(a,{origin:_.LOCAL});const l=c=>c&&c.length>0&&e.bulkDeleteAnnotations(c),d=c=>c&&c.length>0&&e.bulkUpsertAnnotations(c),u=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({oldValue:m})=>m)),f=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({newValue:m})=>m)),y=c=>c&&c.length>0&&e.bulkUpsertAnnotations(c),p=c=>c&&c.length>0&&e.bulkDeleteAnnotations(c);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...o],pointer:i}),on:(c,m)=>n.on(c,m),redo:()=>{if(o.length-1>i){r=!0;const{created:c,updated:m,deleted:v}=o[i+1];d(c),f(m),p(v),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){r=!0;const{created:c,updated:m,deleted:v}=o[i];l(c),u(m),y(v),n.emit("undo",o[i]),i-=1}}}},Pn=()=>{const e=He([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Vn=(e,t,n,o)=>{const{hover:i,selection:r,store:s,viewport:a}=e,l=new Map;let d=[],u;const f=(m,v)=>{l.has(m)?l.get(m).push(v):l.set(m,[v])},y=(m,v)=>{const h=l.get(m);if(h){const g=h.indexOf(v);g!==-1&&h.splice(g,1)}},p=(m,v,h)=>{l.has(m)&&setTimeout(()=>{l.get(m).forEach(g=>{if(n){const x=Array.isArray(v)?v.map(R=>n.serialize(R)):n.serialize(v),k=h?h instanceof PointerEvent?h:n.serialize(h):void 0;g(x,k)}else g(v,h)})},1)};r.subscribe(({selected:m})=>{if(!(d.length===0&&m.length===0)){if(d.length===0&&m.length>0)d=m.map(({id:v})=>s.getAnnotation(v));else if(d.length>0&&m.length===0)d.forEach(v=>{const h=s.getAnnotation(v.id);h&&!le(h,v)&&p("updateAnnotation",h,v)}),d=[];else{const v=new Set(d.map(g=>g.id)),h=new Set(m.map(({id:g})=>g));d.filter(g=>!h.has(g.id)).forEach(g=>{const x=s.getAnnotation(g.id);x&&!le(x,g)&&p("updateAnnotation",x,g)}),d=[...d.filter(g=>h.has(g.id)),...m.filter(({id:g})=>!v.has(g)).map(({id:g})=>s.getAnnotation(g))]}p("selectionChanged",d)}}),i.subscribe(m=>{!u&&m?p("mouseEnterAnnotation",s.getAnnotation(m)):u&&!m?p("mouseLeaveAnnotation",s.getAnnotation(u)):u&&m&&(p("mouseLeaveAnnotation",s.getAnnotation(u)),p("mouseEnterAnnotation",s.getAnnotation(m))),u=m}),a?.subscribe(m=>p("viewportIntersect",m.map(v=>s.getAnnotation(v)))),s.observe(m=>{const{created:v,deleted:h}=m.changes;(v||[]).forEach(g=>p("createAnnotation",g)),(h||[]).forEach(g=>p("deleteAnnotation",g)),(m.changes.updated||[]).filter(g=>[...g.bodiesCreated||[],...g.bodiesDeleted||[],...g.bodiesUpdated||[]].length>0).forEach(({oldValue:g,newValue:x})=>{const k=d.find(R=>R.id===g.id)||g;d=d.map(R=>R.id===g.id?x:R),p("updateAnnotation",x,k)})},{origin:_.LOCAL}),s.observe(m=>{if(d){const v=new Set(d.map(g=>g.id)),h=(m.changes.updated||[]).filter(({newValue:g})=>v.has(g.id)).map(({newValue:g})=>g);h.length>0&&(d=d.map(g=>h.find(k=>k.id===g.id)||g))}},{origin:_.REMOTE});const c=m=>v=>{const{updated:h}=v;m?(h||[]).forEach(g=>p("updateAnnotation",g.oldValue,g.newValue)):(h||[]).forEach(g=>p("updateAnnotation",g.newValue,g.oldValue))};return t.on("undo",c(!0)),t.on("redo",c(!1)),{on:f,off:y,emit:p}},Xn=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:r}=e.parse(o);return r?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),$n=(e,t,n)=>{const{store:o,selection:i}=e,r=h=>{if(n){const{parsed:g,error:x}=n.parse(h);g?o.addAnnotation(g,_.REMOTE):console.error(x)}else o.addAnnotation(We(h),_.REMOTE)},s=()=>i.clear(),a=()=>o.clear(),l=h=>{const g=o.getAnnotation(h);return n&&g?n.serialize(g):g},d=()=>n?o.all().map(n.serialize):o.all(),u=()=>{var h;const g=(((h=i.selected)==null?void 0:h.map(x=>x.id))||[]).map(x=>o.getAnnotation(x)).filter(Boolean);return n?g.map(n.serialize):g},f=(h,g=!0)=>fetch(h).then(x=>x.json()).then(x=>(p(x,g),x)),y=h=>{if(typeof h=="string"){const g=o.getAnnotation(h);if(o.deleteAnnotation(h),g)return n?n.serialize(g):g}else{const g=n?n.parse(h).parsed:h;if(g)return o.deleteAnnotation(g),h}},p=(h,g=!0)=>{const x=g?o.syncAnnotations:o.bulkUpsertAnnotations;if(n){const k=n.parseAll||Xn(n),{parsed:R,failed:S}=k(h);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),x(R,_.REMOTE)}else x(h.map(We),_.REMOTE)},c=(h,g)=>{h?i.setSelected(h,g):i.clear()},m=h=>{i.setUserSelectAction(h)},v=h=>{if(n){const g=n.parse(h).parsed,x=n.serialize(o.getAnnotation(g.id));return o.updateAnnotation(g),x}else{const g=o.getAnnotation(h.id);return o.updateAnnotation(We(h)),g}};return{addAnnotation:r,cancelSelected:s,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:d,getHistory:t.getHistory,getSelected:u,loadAnnotations:f,redo:t.redo,removeAnnotation:y,setAnnotations:p,setSelected:c,setUserSelectAction:m,undo:t.undo,updateAnnotation:v}};let Hn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",jn=e=>crypto.getRandomValues(new Uint8Array(e)),Fn=(e,t,n)=>{let o=256-256%e.length;if(o===256){let r=e.length-1;return(s=t)=>{if(!s)return"";let a="";for(;;){let l=n(s),d=s;for(;d--;)if(a+=e[l[d]&r],a.length>=s)return a}}}let i=Math.ceil(1.6*256*t/o);return(r=t)=>{if(!r)return"";let s="";for(;;){let a=n(i),l=i;for(;l--;)if(a[l]<o&&(s+=e[a[l]%e.length],s.length>=r))return s}}},Wn=(e,t=21)=>Fn(e,t|0,jn),zn=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Hn[n[e]&63];return t};const qn=()=>({isGuest:!0,id:Wn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Gn=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let r=t.charCodeAt(o);n=(n<<5)-n+r,n|=0}return`${n}`},vt=e=>e?typeof e=="object"?{...e}:e:void 0,Qn=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:r,value:s,created:a,modified:l,creator:d,...u}=n;return{id:o||`temp-${Gn(n)}`,annotation:t,type:i,purpose:r,value:s,creator:vt(d),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...u}}),Jn=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:r,...s}=t,a={...s,created:i?.toISOString(),modified:r?.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a});globalThis.ANNOTORIOUS_PRESENCE_KEY||(globalThis.ANNOTORIOUS_PRESENCE_KEY=zn());const Zn=(e,t)=>({parse:n=>St(n),serialize:n=>Ct(n,e,t)}),eo=e=>e.quote!==void 0&&e.start!==void 0&&e.end!==void 0,to=e=>{const{id:t,creator:n,created:o,modified:i,target:r}=e,s=Array.isArray(r)?r:[r];if(s.length===0)return{error:Error(`No targets found for annotation: ${e.id}`)};const a={creator:vt(n),created:o?new Date(o):void 0,updated:i?new Date(i):void 0,annotation:t,selector:[],styleClass:"styleClass"in s[0]?s[0].styleClass:void 0};for(const l of s){const u=(Array.isArray(l.selector)?l.selector:[l.selector]).reduce((f,y)=>{switch(y.type){case"TextQuoteSelector":f.quote=y.exact;break;case"TextPositionSelector":f.start=y.start,f.end=y.end;break}return f},{});if(a.outdated||="outdated"in l?l.outdated:void 0,a.migrationPending||="migrationPending"in l?l.migrationPending:void 0,eo(u))a.selector.push({...u,id:l.id,scope:l.scope});else{const f=[u.start?void 0:"TextPositionSelector",u.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${f.join(" and ")} for annotation: ${e.id}`)}}}return{parsed:a}},St=e=>{const t=e.id||at(),{creator:n,created:o,modified:i,body:r,...s}=e,a=Qn(r,t),l=to(e);return"error"in l?{error:l.error}:{parsed:{...s,id:t,bodies:a,target:l.parsed}}},Ct=(e,t,n)=>{const{bodies:o,target:i,...r}=e,{selector:s,creator:a,created:l,updated:d,...u}=i,f=s.map(y=>{const{id:p,quote:c}=y,m={type:"TextQuoteSelector",exact:c};if(n&&"range"in y){const{prefix:x,suffix:k}=gt(y.range,n);m.prefix=x,m.suffix=k}if(!("start"in y))throw new Error("W3C serialization requires TextSelector with start/end");const{start:v,end:h}=y,g={type:"TextPositionSelector",start:v,end:h};return{...u,id:p,scope:"scope"in y?y.scope:void 0,source:t,selector:[m,g]}});return{...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Jn(e.bodies),creator:a,created:l?.toISOString(),modified:d?.toISOString(),target:f}};let Tt=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){return(this.events[e]||=[]).push(t),()=>{this.events[e]=this.events[e]?.filter(n=>t!==n)}}});const xt=e=>e.addEventListener("click",t=>{!t.target.closest(ae)&&!t.target.closest("a")&&t.preventDefault()}),ke=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}),me=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}),Me=(e,t=10)=>{let n;return((...o)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,o),t)})},qe=(e,t,n,o)=>{const{store:i,selection:r,hover:s}=n,a=Tt();let l;const d=new Map;let u;const f=Ft(o),y=B=>{const{x:M,y:I}=t.getBoundingClientRect(),K=i.getAt(B.clientX-M,B.clientY-I,!1,u);K&&n.selection.evalSelectAction(K)!==je.NONE?s.current!==K.id&&(t.classList.add("hovered"),s.set(K.id)):s.current&&(t.classList.remove("hovered"),s.set(null))};t.addEventListener("pointermove",y);const p=Me((B=!1)=>requestAnimationFrame(()=>{const M=jt(t),{minX:I,minY:K,maxX:oe,maxY:b}=M,A=u?i.getIntersecting(I,K,oe,b).filter(({annotation:E})=>u?.(E)):i.getIntersecting(I,K,oe,b),w=r.selected.map(({id:E})=>E),T=A.map(({annotation:E,rects:O})=>{const P=w.includes(E.id),j=E.id===s.current;return{annotation:E,rects:O,state:{selected:P,hovered:j}}});e.redraw(T,M,l,d,B),setTimeout(()=>{f(A.map(({annotation:E})=>E)),a.emit("onRedraw")},1)}),10),c=(B,M)=>{M?B?d.set(M,B):d.delete(M):l=B,p(!0)},m=B=>{u=B,p(!1)},v=(B,M)=>a.on(B,M),h=()=>{p()};i.observe(h);const g=r.subscribe(()=>{p()}),x=s.subscribe(()=>{p()}),k=()=>{p(!0)};document.addEventListener("scroll",k,{capture:!0,passive:!0});const R=Me(()=>{i.recalculatePositions(),p()},10);window.addEventListener("resize",R);const S=new ResizeObserver(R);S.observe(t);const C={attributes:!0,childList:!0,subtree:!0},N=new MutationObserver(Me(B=>{B.every(I=>I.target===t||t.contains(I.target))||p(!0)},150));return N.observe(document.body,C),{destroy:()=>{t.removeEventListener("pointermove",y),e.destroy(),i.unobserve(h),g(),x(),document.removeEventListener("scroll",k),window.removeEventListener("resize",R),S.disconnect(),N.disconnect()},on:v,redraw:p,setStyle:c,setFilter:m,setVisible:e.setVisible.bind(e)}};var no={grad:.9,turn:360,rad:360/(2*Math.PI)},ee=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},X=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=Math.pow(10,t)),Math.round(n*e)/n+0},W=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},Lt=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},Rt=function(e){return{r:W(e.r,0,255),g:W(e.g,0,255),b:W(e.b,0,255),a:W(e.a)}},Ge=function(e){return{r:X(e.r),g:X(e.g),b:X(e.b),a:X(e.a,3)}},oo=/^#([0-9a-f]{3,8})$/i,Ne=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},Ot=function(e){var t=e.r,n=e.g,o=e.b,i=e.a,r=Math.max(t,n,o),s=r-Math.min(t,n,o),a=s?r===t?(n-o)/s:r===n?2+(o-t)/s:4+(t-n)/s:0;return{h:60*(a<0?a+6:a),s:r?s/r*100:0,v:r/255*100,a:i}},kt=function(e){var t=e.h,n=e.s,o=e.v,i=e.a;t=t/360*6,n/=100,o/=100;var r=Math.floor(t),s=o*(1-n),a=o*(1-(t-r)*n),l=o*(1-(1-t+r)*n),d=r%6;return{r:255*[o,a,s,s,l,o][d],g:255*[l,o,o,a,s,s][d],b:255*[s,s,l,o,o,a][d],a:i}},Mt=function(e){return{h:Lt(e.h),s:W(e.s,0,100),l:W(e.l,0,100),a:W(e.a)}},Nt=function(e){return{h:X(e.h),s:X(e.s),l:X(e.l),a:X(e.a,3)}},Bt=function(e){return kt((n=(t=e).s,{h:t.h,s:(n*=((o=t.l)<50?o:100-o)/100)>0?2*n/(o+n)*100:0,v:o+n,a:t.a}));var t,n,o},ye=function(e){return{h:(t=Ot(e)).h,s:(i=(200-(n=t.s))*(o=t.v)/100)>0&&i<200?n*o/100/(i<=100?i:200-i)*100:0,l:i/2,a:t.a};var t,n,o,i},io=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ro=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,so=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ao=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,_t={string:[[function(e){var t=oo.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?X(parseInt(e[3]+e[3],16)/255,2):1}:e.length===6||e.length===8?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:e.length===8?X(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=so.exec(e)||ao.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Rt({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=io.exec(e)||ro.exec(e);if(!t)return null;var n,o,i=Mt({h:(n=t[1],o=t[2],o===void 0&&(o="deg"),Number(n)*(no[o]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return Bt(i)},"hsl"]],object:[[function(e){var t=e.r,n=e.g,o=e.b,i=e.a,r=i===void 0?1:i;return ee(t)&&ee(n)&&ee(o)?Rt({r:Number(t),g:Number(n),b:Number(o),a:Number(r)}):null},"rgb"],[function(e){var t=e.h,n=e.s,o=e.l,i=e.a,r=i===void 0?1:i;if(!ee(t)||!ee(n)||!ee(o))return null;var s=Mt({h:Number(t),s:Number(n),l:Number(o),a:Number(r)});return Bt(s)},"hsl"],[function(e){var t=e.h,n=e.s,o=e.v,i=e.a,r=i===void 0?1:i;if(!ee(t)||!ee(n)||!ee(o))return null;var s=(function(a){return{h:Lt(a.h),s:W(a.s,0,100),v:W(a.v,0,100),a:W(a.a)}})({h:Number(t),s:Number(n),v:Number(o),a:Number(r)});return kt(s)},"hsv"]]},It=function(e,t){for(var n=0;n<t.length;n++){var o=t[n][0](e);if(o)return[o,t[n][1]]}return[null,void 0]},lo=function(e){return typeof e=="string"?It(e.trim(),_t.string):typeof e=="object"&&e!==null?It(e,_t.object):[null,void 0]},Qe=function(e,t){var n=ye(e);return{h:n.h,s:W(n.s+100*t,0,100),l:n.l,a:n.a}},Je=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},Dt=function(e,t){var n=ye(e);return{h:n.h,s:n.s,l:W(n.l+100*t,0,100),a:n.a}},Ut=(function(){function e(t){this.parsed=lo(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return X(Je(this.rgba),2)},e.prototype.isDark=function(){return Je(this.rgba)<.5},e.prototype.isLight=function(){return Je(this.rgba)>=.5},e.prototype.toHex=function(){return t=Ge(this.rgba),n=t.r,o=t.g,i=t.b,s=(r=t.a)<1?Ne(X(255*r)):"","#"+Ne(n)+Ne(o)+Ne(i)+s;var t,n,o,i,r,s},e.prototype.toRgb=function(){return Ge(this.rgba)},e.prototype.toRgbString=function(){return t=Ge(this.rgba),n=t.r,o=t.g,i=t.b,(r=t.a)<1?"rgba("+n+", "+o+", "+i+", "+r+")":"rgb("+n+", "+o+", "+i+")";var t,n,o,i,r},e.prototype.toHsl=function(){return Nt(ye(this.rgba))},e.prototype.toHslString=function(){return t=Nt(ye(this.rgba)),n=t.h,o=t.s,i=t.l,(r=t.a)<1?"hsla("+n+", "+o+"%, "+i+"%, "+r+")":"hsl("+n+", "+o+"%, "+i+"%)";var t,n,o,i,r},e.prototype.toHsv=function(){return t=Ot(this.rgba),{h:X(t.h),s:X(t.s),v:X(t.v),a:X(t.a,3)};var t},e.prototype.invert=function(){return z({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},e.prototype.saturate=function(t){return t===void 0&&(t=.1),z(Qe(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),z(Qe(this.rgba,-t))},e.prototype.grayscale=function(){return z(Qe(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),z(Dt(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),z(Dt(this.rgba,-t))},e.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},e.prototype.alpha=function(t){return typeof t=="number"?z({r:(n=this.rgba).r,g:n.g,b:n.b,a:t}):X(this.rgba.a,3);var n},e.prototype.hue=function(t){var n=ye(this.rgba);return typeof t=="number"?z({h:t,s:n.s,l:n.l,a:n.a}):X(n.h)},e.prototype.isEqual=function(t){return this.toHex()===z(t).toHex()},e})(),z=function(e){return e instanceof Ut?e:new Ut(e)};const te={fill:"rgb(0, 128, 255)",fillOpacity:.18},Be={fill:"rgb(0, 128, 255)",fillOpacity:.45},Yt=e=>e?.fillOpacity!==void 0?z(e?.fill||te.fill).alpha(e.fillOpacity).toHex():e?.fill?e.fill:z(te.fill).alpha(te.fillOpacity).toHex(),Ze=(e,t,n)=>t?typeof t=="function"?t(e.annotation,e.state,n)||(e.state?.selected?Be:te):t:e.state?.selected?Be:te;var Kt=Object.prototype.hasOwnProperty;function et(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&et(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Kt.call(e,n)&&++o&&!Kt.call(t,n)||!(n in t)||!et(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Pt=(e,t)=>{const n=(r,s)=>r.x<=s.x+s.width&&r.x+r.width>=s.x&&r.y<=s.y+s.height&&r.y+r.height>=s.y,o=r=>r.rects.reduce((s,a)=>s+a.width,0),i=t.filter(({rects:r})=>r.some(s=>n(e,s)));return i.sort((r,s)=>o(s)-o(r)),i.findIndex(r=>r.rects.includes(e))},Vt=e=>{const t=[],n=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_TEXT);e.startContainer.nodeType===Node.TEXT_NODE&&(n.currentNode=e.startContainer,e.intersectsNode(e.startContainer)&&t.push(e.startContainer));let o=t.length>0,i;for(;i=n.nextNode();)if(e.intersectsNode(i))o=!0,t.push(i);else if(o)break;if(t.length<2)return Array.from(e.getClientRects());{const r=t[0],s=t[t.length-1],a=document.createRange();if(a.selectNode(r),e.startContainer.nodeType===Node.TEXT_NODE)a.setStart(r,e.startOffset);else{const u=e.startContainer.childNodes[e.startOffset];u?a.setStartBefore(u):a.setStartAfter(e.startContainer)}const l=document.createRange();if(l.selectNode(s),e.endContainer.nodeType===Node.TEXT_NODE)l.setEnd(s,e.endOffset);else{const u=e.endContainer.childNodes[e.endOffset];u?l.setEndBefore(u):l.setEndAfter(e.endContainer)}const d=u=>{const f=document.createRange();return f.selectNode(u),Array.from(f.getClientRects())};return[...Array.from(a.getClientRects()),...t.slice(1,-1).flatMap(d),...Array.from(l.getClientRects())]}},co=(e,t,n,o)=>{const i=a=>Math.round(a*10)/10,r={top:i(e.top),bottom:i(e.bottom),left:i(e.left),right:i(e.right)},s={top:i(t.top),bottom:i(t.bottom),left:i(t.left),right:i(t.right)};if(Math.abs(r.top-s.top)<o&&Math.abs(r.bottom-s.bottom)<o){if(Math.abs(r.left-s.right)<n||Math.abs(r.right-s.left)<n)return"inline-adjacent";if(r.left>=s.left&&r.right<=s.right)return"inline-is-contained";if(r.left<=s.left&&r.right>=s.right)return"inline-contains"}else if(r.top<=s.top&&r.bottom>=s.bottom){if(r.left<=s.left&&r.right>=s.right)return"block-contains"}else if(r.top>=s.top&&r.bottom<=s.bottom&&r.left>=s.left&&r.right<=s.right)return"block-is-contained"},uo=(e,t)=>{const n=Math.min(e.left,t.left),o=Math.max(e.right,t.right),i=Math.min(e.top,t.top),r=Math.max(e.bottom,t.bottom);return new DOMRect(n,i,o-n,r-i)},Xt=(e,t=.5,n=.5)=>e.reduce((o,i)=>{if(i.width===0||i.height===0)return o;let r=[...o],s=!1;for(const a of o){const l=co(i,a,t,n);if(l==="inline-adjacent"){r=r.map(d=>d===a?uo(i,a):d),s=!0;break}else if(l==="inline-contains"){r=r.map(d=>d===a?i:d),s=!0;break}else if(l==="inline-is-contained"){s=!0;break}else if(l==="block-contains"||l==="block-is-contained"){i.width<a.width&&(r=r.map(d=>d===a?i:d)),i.width===a.width&&i.height<a.width&&(r=r.map(d=>d===a?i:d)),s=!0;break}}return s?r:[...r,i]},[]),fo=e=>({length:e.length,item:t=>e[t],[Symbol.iterator]:function*(){for(let t=0;t<this.length;t++)yield this.item(t)}}),$t=(e,t)=>{const{left:n,top:o,right:i,bottom:r}=e;return new DOMRect(n-t.left,o-t.top,i-n,r-o)},ho=(e,t)=>{const{left:n,top:o,right:i,bottom:r}=e;return new DOMRect(n+t.left,o+t.top,i-n,r-o)},go=e=>{e.classList.add("r6o-annotatable");const t=document.createElement("div");t.className="r6o-span-highlight-layer",e.appendChild(t);let n=[];return{destroy:()=>{t.remove()},redraw:(s,a,l,d,u)=>{if(!(!et(n,s)||u))return;t.innerHTML="",[...s].sort((c,m)=>{const{annotation:{target:{created:v}}}=c,{annotation:{target:{created:h}}}=m;return v&&h?v.getTime()-h.getTime():0}).forEach(c=>{const m=d?.get(c.annotation.id)||l;c.rects.map(v=>{const h=Pt(v,s),g=Ze(c,m,h),x=document.createElement("span");x.className="r6o-annotation",x.dataset.annotation=c.annotation.id,x.style.left=`${v.x}px`,x.style.top=`${v.y}px`,x.style.width=`${v.width}px`,x.style.height=`${v.height}px`,x.style.backgroundColor=Yt(g),g.underlineStyle&&(x.style.borderStyle=g.underlineStyle),g.underlineColor&&(x.style.borderColor=g.underlineColor),g.underlineThickness&&(x.style.borderBottomWidth=`${g.underlineThickness}px`),g.underlineOffset&&(x.style.paddingBottom=`${g.underlineOffset}px`),t.appendChild(x)})}),n=s},setVisible:s=>{s?t.classList.remove("hidden"):t.classList.add("hidden")}}},Ht=(e,t,n)=>qe(go(e),e,t,n),jt=e=>{const{top:t,left:n}=e.getBoundingClientRect(),{innerWidth:o,innerHeight:i}=window,r=-n,s=-t,a=o-n,l=i-t;return{top:t,left:n,minX:r,minY:s,maxX:a,maxY:l}},Ft=e=>{let t=new Set;return o=>{const i=o.map(r=>r.id);(t.size!==i.length||i.some(r=>!t.has(r)))&&e.set(i),t=new Set(i)}};function Wt(e,t,n=0,o=e.length-1,i=po){for(;o>n;){if(o-n>600){const l=o-n+1,d=t-n+1,u=Math.log(l),f=.5*Math.exp(2*u/3),y=.5*Math.sqrt(u*f*(l-f)/l)*(d-l/2<0?-1:1),p=Math.max(n,Math.floor(t-d*f/l+y)),c=Math.min(o,Math.floor(t+(l-d)*f/l+y));Wt(e,t,p,c,i)}const r=e[t];let s=n,a=o;for(be(e,n,t),i(e[o],r)>0&&be(e,n,o);s<a;){for(be(e,s,a),s++,a--;i(e[s],r)<0;)s++;for(;i(e[a],r)>0;)a--}i(e[n],r)===0?be(e,n,a):(a++,be(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function be(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function po(e,t){return e<t?-1:e>t?1:0}class mo{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!Ie(t,n))return o;const i=this.toBBox,r=[];for(;n;){for(let s=0;s<n.children.length;s++){const a=n.children[s],l=n.leaf?i(a):a;Ie(t,l)&&(n.leaf?o.push(a):nt(t,l)?this._all(a,o):r.push(a))}n=r.pop()}return o}collides(t){let n=this.data;if(!Ie(t,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(Ie(t,s)){if(n.leaf||nt(t,s))return!0;o.push(r)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=de([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),r=[],s=[];let a,l,d;for(;o||r.length;){if(o||(o=r.pop(),l=r[r.length-1],a=s.pop(),d=!0),o.leaf){const u=yo(t,o.children,n);if(u!==-1)return o.children.splice(u,1),r.push(o),this._condense(r),this}!d&&!o.leaf&&nt(o,i)?(r.push(o),s.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],d=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const r=o-n+1;let s=this._maxEntries,a;if(r<=s)return a=de(t.slice(n,o+1)),ce(a,this.toBBox),a;i||(i=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,i-1))),a=de([]),a.leaf=!1,a.height=i;const l=Math.ceil(r/s),d=l*Math.ceil(Math.sqrt(s));zt(t,n,o,d,this.compareMinX);for(let u=n;u<=o;u+=d){const f=Math.min(u+d-1,o);zt(t,u,f,l,this.compareMinY);for(let y=u;y<=f;y+=l){const p=Math.min(y+l-1,f);a.children.push(this._build(t,y,p,i-1))}}return ce(a,this.toBBox),a}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let r=1/0,s=1/0,a;for(let l=0;l<n.children.length;l++){const d=n.children[l],u=tt(d),f=wo(t,d)-u;f<s?(s=f,r=u<r?u:r,a=d):f===s&&u<r&&(r=u,a=d)}n=a||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),r=[],s=this._chooseSubtree(i,this.data,n,r);for(s.children.push(t),we(s,i);n>=0&&r[n].children.length>this._maxEntries;)this._split(r,n),n--;this._adjustParentBBoxes(i,r,n)}_split(t,n){const o=t[n],i=o.children.length,r=this._minEntries;this._chooseSplitAxis(o,r,i);const s=this._chooseSplitIndex(o,r,i),a=de(o.children.splice(s,o.children.length-s));a.height=o.height,a.leaf=o.leaf,ce(o,this.toBBox),ce(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(o,a)}_splitRoot(t,n){this.data=de([t,n]),this.data.height=t.height+1,this.data.leaf=!1,ce(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,r=1/0,s=1/0;for(let a=n;a<=o-n;a++){const l=Ae(t,0,a,this.toBBox),d=Ae(t,a,o,this.toBBox),u=Eo(l,d),f=tt(l)+tt(d);u<r?(r=u,i=a,s=f<s?f:s):u===r&&f<s&&(s=f,i=a)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:bo,r=t.leaf?this.compareMinY:Ao,s=this._allDistMargin(t,n,o,i),a=this._allDistMargin(t,n,o,r);s<a&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const r=this.toBBox,s=Ae(t,0,n,r),a=Ae(t,o-n,o,r);let l=_e(s)+_e(a);for(let d=n;d<o-n;d++){const u=t.children[d];we(s,t.leaf?r(u):u),l+=_e(s)}for(let d=o-n-1;d>=n;d--){const u=t.children[d];we(a,t.leaf?r(u):u),l+=_e(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)we(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():ce(t[n],this.toBBox)}}function yo(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function ce(e,t){Ae(e,0,e.children.length,t,e)}function Ae(e,t,n,o,i){i||(i=de(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let r=t;r<n;r++){const s=e.children[r];we(i,e.leaf?o(s):s)}return i}function we(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function bo(e,t){return e.minX-t.minX}function Ao(e,t){return e.minY-t.minY}function tt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function _e(e){return e.maxX-e.minX+(e.maxY-e.minY)}function wo(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Eo(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),r=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,r-o)}function nt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Ie(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function de(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function zt(e,t,n,o,i){const r=[t,n];for(;r.length;){if(n=r.pop(),t=r.pop(),n-t<=o)continue;const s=t+Math.ceil((n-t)/o/2)*o;Wt(e,s,t,n,i),r.push(t,s,s,n)}}const vo=(e,t,n,o,i)=>{const r=new mo,s=new Map,a=Tt(),l=(S,C)=>{const N=S.selector.flatMap(B=>{const M=(i?i(B,t):Xe(B,t))?.range;return Vt(M)}),D=Xt(N,n,o).map(B=>$t(B,C));return D.map(B=>{const{x:M,y:I,width:K,height:oe}=B;return{minX:M,minY:I,maxX:M+K,maxY:I+oe,annotation:{id:S.annotation,rects:D}}})},d=()=>[...s.values()],u=()=>{r.clear(),s.clear()},f=S=>{const C=l(S,t.getBoundingClientRect());C.length!==0&&(C.forEach(N=>r.insert(N)),s.set(S.annotation,C))},y=S=>{const C=s.get(S.annotation);C&&(C.forEach(N=>r.remove(N)),s.delete(S.annotation))},p=S=>{y(S),f(S)},c=(S,C=!0)=>{C&&u();const N=t.getBoundingClientRect(),D=S.map(M=>({target:M,rects:l(M,N)}));D.forEach(({target:M,rects:I})=>{I.length>0&&s.set(M.annotation,I)});const B=D.flatMap(({rects:M})=>M);r.load(B)},m=(S,C,N=!1)=>{const D=r.search({minX:S,minY:C,maxX:S,maxY:C}),B=M=>M.annotation.rects.reduce((I,K)=>I+K.width*K.height,0);return D.length>0?(D.sort((M,I)=>B(M)-B(I)),N?D.map(M=>M.annotation.id):[D[0].annotation.id]):[]},v=S=>{const C=h(S);if(C.length===0)return;let N=C[0].left,D=C[0].top,B=C[0].right,M=C[0].bottom;for(let I=1;I<C.length;I++){const K=C[I];N=Math.min(N,K.left),D=Math.min(D,K.top),B=Math.max(B,K.right),M=Math.max(M,K.bottom)}return new DOMRect(N,D,B-N,M-D)},h=S=>{const C=s.get(S);return C?C[0].annotation.rects:[]};return{all:d,clear:u,getAt:m,getAnnotationBounds:v,getAnnotationRects:h,getIntersecting:(S,C,N,D)=>{const B=r.search({minX:S,minY:C,maxX:N,maxY:D}),M=new Set(B.map(I=>I.annotation.id));return Array.from(M).map(I=>({annotation:e.getAnnotation(I),rects:h(I)})).filter(I=>!!I.annotation)},insert:f,recalculate:()=>{c(e.all().map(S=>S.target),!0),a.emit("recalculate")},remove:y,set:c,size:()=>r.all().length,update:p,on:(S,C)=>a.on(S,C)}},qt=(e,t)=>{const n=Dn(),o=vo(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance,t.selectorReviveFn),i=vn(n,t.userSelectAction,t.adapter),r=En(n),s=Pn(),a=(k,R=_.LOCAL)=>{const S=$e(k,e,t.selectorReviveFn),C=Z(S.target.selector);return C&&n.addAnnotation(S,R),C},l=k=>{const R=k.map(C=>$e(C,e,t.selectorReviveFn)),S=R.filter(C=>!Z(C.target.selector));return{revived:R,couldNotRevive:S}},d=(k,R=_.LOCAL)=>{const{revived:S,couldNotRevive:C}=l(k);return n.syncAnnotations(S,R),C},u=(k,R=_.LOCAL)=>{const{revived:S,couldNotRevive:C}=l(k);return n.bulkUpsertAnnotations(S,R),C},f=(k,R=!0,S=_.LOCAL)=>R?d(k,S):u(k,S),y=(k,R=_.LOCAL)=>{const S=pe(k,e);n.updateTarget(S,R)},p=(k,R=_.LOCAL)=>{const S=k.map(C=>pe(C,e));n.bulkUpdateTargets(S,R)};function c(k,R,S,C){const N=S||!!C,D=o.getAt(k,R,N).map(M=>n.getAnnotation(M)).filter(Boolean),B=C?D.filter(C):D;if(B.length!==0)return S?B:B[0]}const m=k=>o.getAnnotationRects(k).length>0?o.getAnnotationBounds(k):void 0,v=(k,R,S,C)=>o.getIntersecting(k,R,S,C),h=k=>o.getAnnotationRects(k),g=()=>o.recalculate(),x=k=>o.on("recalculate",k);return n.observe(({changes:k})=>{const R=(k.deleted||[]).filter(N=>Z(N.target.selector)),S=(k.created||[]).filter(N=>Z(N.target.selector)),C=(k.updated||[]).filter(N=>Z(N.newValue.target.selector));R?.length>0&&R.forEach(N=>o.remove(N.target)),S.length>0&&o.set(S.map(N=>N.target),!1),C?.length>0&&C.forEach(({newValue:N})=>o.update(N.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotations:f,bulkUpdateTargets:p,bulkUpsertAnnotations:u,getAnnotationBounds:m,getAnnotationRects:h,getIntersecting:v,getAt:c,recalculatePositions:g,onRecalculatePositions:x,syncAnnotations:d,updateTarget:y},selection:i,hover:r,viewport:s}};function So(e,t=100,n={}){if(typeof e!="function")throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");if(typeof n=="boolean")throw new TypeError("The `options` parameter must be an object, not a boolean. Use `{immediate: true}` instead.");const{immediate:o}=n;let i,r,s,a,l;function d(){const y=i,p=r;return i=void 0,r=void 0,l=e.apply(y,p),l}function u(){const y=Date.now()-a;y<t&&y>=0?s=setTimeout(u,t-y):(s=void 0,o||(l=d()))}const f=function(...y){if(i&&this!==i&&Object.getPrototypeOf(this)===Object.getPrototypeOf(i))throw new Error("Debounced method called with different contexts of the same prototype.");i=this,r=y,a=Date.now();const p=o&&!s;if(s||(s=setTimeout(u,t)),p)return l=d(),l};return Object.defineProperty(f,"isPending",{get(){return s!==void 0}}),f.clear=()=>{s&&(clearTimeout(s),s=void 0,i=void 0,r=void 0)},f.flush=()=>{s&&f.trigger()},f.trigger=()=>{l=d(),f.clear()},f}const ot=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function it(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent(`on${t}`,n)}function Ee(e,t,n,o){e&&(e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent(`on${t}`,n))}function Gt(e,t){const n=t.slice(0,t.length-1),o=[];for(let i=0;i<n.length;i++)o.push(e[n[i].toLowerCase()]);return o}function Qt(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function Co(e,t){const n=e.length>=t.length?e:t,o=e.length>=t.length?t:e;let i=!0;for(let r=0;r<n.length;r++)o.indexOf(n[r])===-1&&(i=!1);return i}function Jt(e){let t=e.keyCode||e.which||e.charCode;return e.key&&/^[a-z]$/i.test(e.key)?e.key.toUpperCase().charCodeAt(0):(e.code&&/^Key[A-Z]$/.test(e.code)&&(t=e.code.charCodeAt(3)),t)}const ve={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,arrowup:38,arrowdown:40,arrowleft:37,arrowright:39,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,"-":ot?173:189,"=":ot?61:187,";":ot?59:186,"'":222,"{":219,"}":221,"[":219,"]":221,"\\":220},q={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,meta:91,command:91},Se={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},V={16:!1,18:!1,17:!1,91:!1},Y={};for(let e=1;e<20;e++)ve[`f${e}`]=111+e;let U=[],Ce=null,ue=null,Zt="all";const ne=new Map,fe=e=>ve[e.toLowerCase()]||q[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),To=e=>Object.keys(ve).find(t=>ve[t]===e),xo=e=>Object.keys(q).find(t=>q[t]===e),en=e=>{Zt=e||"all"},Te=()=>Zt||"all",Lo=()=>U.slice(0),Ro=()=>U.map(e=>To(e)||xo(e)||String.fromCharCode(e)),Oo=()=>{const e=[];return Object.keys(Y).forEach(t=>{Y[t].forEach(({key:n,scope:o,mods:i,shortcut:r})=>{e.push({scope:o,shortcut:r,mods:i,keys:n.split("+").map(s=>fe(s))})})}),e},tn=e=>{const t=e.target||e.srcElement,{tagName:n}=t;let o=!0;const i=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(i||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(o=!1),o},ko=e=>(typeof e=="string"&&(e=fe(e)),U.indexOf(e)!==-1),Mo=(e,t)=>{let n,o;e||(e=Te());for(const i in Y)if(Object.prototype.hasOwnProperty.call(Y,i))for(n=Y[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(({element:s})=>rt(s)):o++;Te()===e&&en(t||"all")};function No(e){let t=Jt(e);e.key&&e.key.toLowerCase()==="capslock"&&(t=fe(e.key));const n=U.indexOf(t);if(n>=0&&U.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&U.splice(0,U.length),(t===93||t===224)&&(t=91),t in V){V[t]=!1;for(const o in q)q[o]===t&&(G[o]=!1)}}const nn=(e,...t)=>{if(typeof e>"u")Object.keys(Y).forEach(n=>{Array.isArray(Y[n])&&Y[n].forEach(o=>De(o)),delete Y[n]}),rt(null);else if(Array.isArray(e))e.forEach(n=>{n.key&&De(n)});else if(typeof e=="object")e.key&&De(e);else if(typeof e=="string"){let[n,o]=t;typeof n=="function"&&(o=n,n=""),De({key:e,scope:n,method:o,splitKey:"+"})}},De=({key:e,scope:t,method:n,splitKey:o="+"})=>{Qt(e).forEach(r=>{const s=r.split(o),a=s.length,l=s[a-1],d=l==="*"?"*":fe(l);if(!Y[d])return;t||(t=Te());const u=a>1?Gt(q,s):[],f=[];Y[d]=Y[d].filter(y=>{const c=(n?y.method===n:!0)&&y.scope===t&&Co(y.mods,u);return c&&f.push(y.element),!c}),f.forEach(y=>rt(y))})};function on(e,t,n,o){if(t.element!==o)return;let i;if(t.scope===n||t.scope==="all"){i=t.mods.length>0;for(const r in V)Object.prototype.hasOwnProperty.call(V,r)&&(!V[r]&&t.mods.indexOf(+r)>-1||V[r]&&t.mods.indexOf(+r)===-1)&&(i=!1);(t.mods.length===0&&!V[16]&&!V[18]&&!V[17]&&!V[91]||i||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(U),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function rn(e,t){const n=Y["*"];let o=Jt(e);if(e.key&&e.key.toLowerCase()==="capslock"||!(G.filter||tn).call(this,e))return;if((o===93||o===224)&&(o=91),U.indexOf(o)===-1&&o!==229&&U.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(l=>{const d=Se[l];e[l]&&U.indexOf(d)===-1?U.push(d):!e[l]&&U.indexOf(d)>-1?U.splice(U.indexOf(d),1):l==="metaKey"&&e[l]&&(U=U.filter(u=>u in Se||u===o))}),o in V){V[o]=!0;for(const l in q)if(Object.prototype.hasOwnProperty.call(q,l)){const d=Se[q[l]];G[l]=e[d]}if(!n)return}for(const l in V)Object.prototype.hasOwnProperty.call(V,l)&&(V[l]=e[Se[l]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(U.indexOf(17)===-1&&U.push(17),U.indexOf(18)===-1&&U.push(18),V[17]=!0,V[18]=!0);const r=Te();if(n)for(let l=0;l<n.length;l++)n[l].scope===r&&(e.type==="keydown"&&n[l].keydown||e.type==="keyup"&&n[l].keyup)&&on(e,n[l],r,t);if(!(o in Y))return;const s=Y[o],a=s.length;for(let l=0;l<a;l++)if((e.type==="keydown"&&s[l].keydown||e.type==="keyup"&&s[l].keyup)&&s[l].key){const d=s[l],{splitKey:u}=d,f=d.key.split(u),y=[];for(let p=0;p<f.length;p++)y.push(fe(f[p]));y.sort().join("")===U.sort().join("")&&on(e,d,r,t)}}const G=function e(t,n,o){U=[];const i=Qt(t);let r=[],s="all",a=document,l=0,d=!1,u=!0,f="+",y=!1,p=!1;if(o===void 0&&typeof n=="function"&&(o=n),Object.prototype.toString.call(n)==="[object Object]"){const c=n;c.scope&&(s=c.scope),c.element&&(a=c.element),c.keyup&&(d=c.keyup),c.keydown!==void 0&&(u=c.keydown),c.capture!==void 0&&(y=c.capture),typeof c.splitKey=="string"&&(f=c.splitKey),c.single===!0&&(p=!0)}for(typeof n=="string"&&(s=n),p&&nn(t,s);l<i.length;l++){const c=i[l].split(f);r=[],c.length>1&&(r=Gt(q,c));let m=c[c.length-1];m=m==="*"?"*":fe(m),m in Y||(Y[m]=[]),Y[m].push({keyup:d,keydown:u,scope:s,mods:r,shortcut:i[l],method:o,key:i[l],splitKey:f,element:a})}if(typeof a<"u"&&typeof window<"u"){if(!ne.has(a)){const c=(v=window.event)=>rn(v,a),m=(v=window.event)=>{rn(v,a),No(v)};ne.set(a,{keydownListener:c,keyupListenr:m,capture:y}),it(a,"keydown",c,y),it(a,"keyup",m,y)}if(!Ce){const c=()=>{U=[]};Ce={listener:c,capture:y},it(window,"focus",c,y)}if(!ue&&typeof document<"u"){const c=()=>{U=[];for(const h in V)V[h]=!1;for(const h in q)e[h]=!1},m=c,v=c;document.addEventListener("fullscreenchange",m),document.addEventListener("webkitfullscreenchange",v),ue={fullscreen:m,webkit:v}}}};function Bo(e,t="all"){Object.keys(Y).forEach(n=>{Y[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method({},i)})})}function rt(e){const t=Object.values(Y).flat();if(t.findIndex(({element:o})=>o===e)<0&&e){const{keydownListener:o,keyupListenr:i,capture:r}=ne.get(e)||{};o&&i&&(Ee(e,"keyup",i,r),Ee(e,"keydown",o,r),ne.delete(e))}if(t.length<=0||ne.size<=0){if(Array.from(ne.keys()).forEach(i=>{const{keydownListener:r,keyupListenr:s,capture:a}=ne.get(i)||{};r&&s&&(Ee(i,"keyup",s,a),Ee(i,"keydown",r,a),ne.delete(i))}),ne.clear(),Object.keys(Y).forEach(i=>delete Y[i]),Ce){const{listener:i,capture:r}=Ce;Ee(window,"focus",i,r),Ce=null}ue&&typeof document<"u"&&(document.removeEventListener("fullscreenchange",ue.fullscreen),document.removeEventListener("webkitfullscreenchange",ue.webkit),ue=null)}}const st={getPressedKeyString:Ro,setScope:en,getScope:Te,deleteScope:Mo,getPressedKeyCodes:Lo,getAllKeyCodes:Oo,isPressed:ko,filter:tn,trigger:Bo,unbind:nn,keyMap:ve,modifier:q,modifierMap:Se};for(const e in st){const t=e;Object.prototype.hasOwnProperty.call(st,t)&&(G[t]=st[t])}if(typeof window<"u"){const e=window.hotkeys;G.noConflict=t=>(t&&window.hotkeys===G&&(window.hotkeys=e),G),window.hotkeys=G}async function _o(e,t,n=(()=>!1)){do{if(await e(),await n())break;const o=t;await new Promise((i=>setTimeout(i,Math.max(0,o))))}while(!await n())}const sn=300,an=["up","down","left","right"],ln=Ye?"⌘+a":"ctrl+a",Io=[...an.map(e=>`shift+${e}`),ln],cn=(e,t,n,o)=>{const{store:i,selection:r}=t;let s;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:d,dismissOnNotAnnotatable:u="NEVER"}=o;let f,y=a,p="CREATE_NEW",c,m,v,h;const g=E=>{y=E,N.clear(),E||(m=void 0,c=void 0,v=void 0,h=void 0)},x=E=>p=E||"CREATE_NEW",k=E=>f=E,R=E=>s=E,S=E=>{if(p==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const O=E;return Ye?O.metaKey:O.ctrlKey}else return!1},C=()=>{if(!y||v===!1)return;const{selected:E}=r;if((S(h)||p==="REPLACE_CURRENT")&&E.length===1&&E[0].editable){const P=i.getAnnotation(E[0].id);if(P?.target){m=P.target,c={annotation:P.id,selector:[],created:m.created,creator:m.creator,updated:new Date,updatedBy:s};return}}m=void 0,c={annotation:at(),selector:[],created:new Date,creator:s}},N=So(E=>{if(!y)return;const O=document.getSelection();if(!O?.anchorNode)return;const j=w().map(F=>ft(F,e));if(j.every(F=>!Pe(e,F))){c=void 0;return}const re=E.timeStamp-(h?.timeStamp||E.timeStamp);if(h?.type==="pointerdown"&&(re<1e3&&!c||O.isCollapsed&&re<sn)&&C(),!c&&(C(),!c))return;if(O.isCollapsed){i.getAnnotation(c.annotation)&&!(S(h)||p==="REPLACE_CURRENT")&&(r.clear(),i.deleteAnnotation(c.annotation));return}if(j.every(F=>lt(F)))return;const J=j.flatMap(F=>ut(e,F.cloneRange()));if(!(J.length>0&&!c||J.length!==c.selector.length||J.some((F,xe)=>F.toString()!==c?.selector[xe]?.quote)))return;const Ue=S(h)&&m?ct([...m.selector.map(F=>F.range),...J]):J;c={...c,selector:Ue.map(F=>pt(F,e,l)),updated:new Date},!(S(h)||p==="REPLACE_CURRENT")&&(i.getAnnotation(c.annotation)?i.updateTarget(c,_.LOCAL):r.clear())},10),D=E=>{h=ke(E),v=h.button===0},B=async E=>{if(!v)return;const O=ke(E),P=()=>{const{x:re,y:J}=e.getBoundingClientRect();if(ge(e,O.target)){(typeof u=="function"?u(O,e):u==="ALWAYS")&&r.clear();return}const se=O.target instanceof Node&&e.contains(O.target)&&i.getAt(O.clientX-re,O.clientY-J,d==="all",f);if(se){const{selected:Ue}=r,F=new Set(Ue.map(Le=>Le.id)),xe=Array.isArray(se)?se.map(Le=>Le.id):[se.id];(F.size!==xe.length||!xe.every(Le=>F.has(Le)))&&(n.emit("clickAnnotation",se),r.userSelect(xe,O))}else r.clear()};if(O.timeStamp-(h?.timeStamp||0)<sn){await M();const re=document.getSelection(),J=ge(e,h?.target),se=ge(e,O.target);if(re?.isCollapsed||J&&se){c=void 0,P();return}}c&&c.selector.length>0&&(T(),r.userSelect(c.annotation,O))},M=async()=>{const E=document.getSelection();let O=!1,P=E?.isCollapsed;const j=()=>P||O,re=1;return setTimeout(()=>O=!0,50),_o(()=>P=E?.isCollapsed,re,j)},I=E=>{document.getSelection()?.isCollapsed||((!c||c.selector.length===0)&&N(E),c&&(T(),r.userSelect(c.annotation,ke(E))))},K=E=>{if(y&&!E.repeat&&w().length!==0&&E.key==="Shift"&&c){const O=document.getSelection();O&&!O.isCollapsed&&(T(),r.userSelect(c.annotation,me(E)))}},oe=E=>{const O=()=>setTimeout(()=>{c&&(c.selector.length>0&&(r.clear(),i.addAnnotation({id:c.annotation,bodies:[],target:c}),r.userSelect(c.annotation,me(E))),document.removeEventListener("selectionchange",O))},100);document.addEventListener("selectionchange",O),C()};G(Io.join(","),{element:e,keydown:!0,keyup:!1},E=>{E.repeat||(h=me(E))}),G(ln,{keydown:!0,keyup:!1},E=>{h=me(E),oe(E)});const b=E=>{E.repeat||w().length!==0&&(c=void 0,r.clear())};G(an.join(","),{keydown:!0,keyup:!1},b),document.addEventListener("pointerdown",D),document.addEventListener("pointerup",B),document.addEventListener("contextmenu",I),document.addEventListener("keyup",K),e.addEventListener("selectstart",C),document.addEventListener("selectionchange",N);const A=()=>{c=void 0,m=void 0,v=void 0,h=void 0,N.clear(),document.removeEventListener("pointerdown",D),document.removeEventListener("pointerup",B),document.removeEventListener("contextmenu",I),document.removeEventListener("keyup",K),e.removeEventListener("selectstart",C),document.removeEventListener("selectionchange",N),G.unbind()},w=()=>{const E=document.getSelection();return E?Array.from(Array(E.rangeCount).keys()).map(O=>E.getRangeAt(O)).filter(O=>O.intersectsNode(e)):[]},T=()=>{if(!c)return;const E=i.getAnnotation(c.annotation);if(!E)i.addAnnotation({id:c.annotation,bodies:[],target:c});else{const{target:{updated:O}}=E,{updated:P}=c;(!O||!P||O<P)&&i.updateTarget(c)}};return{destroy:A,setFilter:k,setUser:R,setAnnotatingEnabled:g,setAnnotatingMode:x}},Do=e=>[`background-color:${z(e?.fill||te.fill).alpha(e?.fillOpacity===void 0?te.fillOpacity:e.fillOpacity).toHex()}`,e?.underlineThickness?"text-decoration:underline":void 0,e?.underlineColor?`text-decoration-color:${e.underlineColor}`:void 0,e?.underlineOffset?`text-underline-offset:${e.underlineOffset}px`:void 0,e?.underlineThickness?`text-decoration-thickness:${e.underlineThickness}px`:void 0].filter(Boolean).join(";"),Uo=()=>{const e=document.createElement("style");document.getElementsByTagName("head")[0].appendChild(e);let t=new Set;return{destroy:()=>{CSS.highlights.clear(),e.remove()},setVisible:r=>{console.log("setVisible not implemented on CSS Custom Highlights renderer")},redraw:(r,s,a,l,d)=>{const u=new Set(r.map(y=>y.annotation.id));Array.from(t).filter(y=>!u.has(y));const f=r.map(y=>{a?typeof a=="function"&&a(y.annotation,y.state):y.state?.selected;const p=Ze(y,a);return`::highlight(_${y.annotation.id}) { ${Do(p)} }`});e.innerHTML=f.join(`
2
+ `),CSS.highlights.clear(),r.forEach(({annotation:y})=>{const p=y.target.selector.map(m=>m.range),c=new Highlight(...p);CSS.highlights.set(`_${y.id}`,c)}),t=u}}},Yo=(e,t,n)=>qe(Uo(),e,t,n),dn=(e,t)=>({...e,annotatingEnabled:e.annotatingEnabled??t.annotatingEnabled,user:e.user||t.user}),un="SPANS",Ko=(e,t={})=>{xt(e),dt(e);const n=dn(t,{annotatingEnabled:!0,user:qn()}),o=qt(e,n),{selection:i,viewport:r}=o,s=o.store,a=Kn(s),l=Vn(o,a,n.adapter);let d=n.user;const u=typeof n.renderer!="function"?n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":un:n.renderer||un:null,f=u===null?n.renderer(e,o,r):u==="SPANS"?Ht(e,o,r):u==="CSS_HIGHLIGHTS"?Yo(e,o,r):void 0;if(!f)throw`Unknown renderer implementation: ${n.renderer}`;console.debug(u?`Using ${u} renderer`:"Using custom renderer implementation"),n.style&&f.setStyle(n.style);const y=cn(e,o,l,n);y.setUser(d);const p=$n(o,a,n.adapter),c=()=>d,m=R=>{y.setAnnotatingEnabled(R===void 0?!0:R)},v=R=>{y.setAnnotatingMode(R)},h=R=>{f.setFilter(R),y.setFilter(R)},g=R=>{d=R,y.setUser(R)},x=R=>{R?i.setSelected(R):i.clear()};return{...p,destroy:()=>{f.destroy(),y.destroy(),a.destroy()},element:e,getUser:c,renderer:f,setAnnotatingEnabled:m,setAnnotatingMode:v,setFilter:h,setStyle:f.setStyle.bind(f),setUser:g,setSelected:x,setVisible:f.setVisible.bind(f),on:l.on,off:l.off,scrollIntoView:bt(e,s),state:o}};L.DEFAULT_SELECTED_STYLE=Be,L.DEFAULT_STYLE=te,L.NOT_ANNOTATABLE_CLASS=Ke,L.NOT_ANNOTATABLE_SELECTOR=ae,L.Origin=_,L.UserSelectAction=je,L.W3CTextFormat=Zn,L.cancelSingleClickEvents=xt,L.cloneKeyboardEvent=me,L.clonePointerEvent=ke,L.computeStyle=Ze,L.computeZIndex=Pt,L.createBody=Rn,L.createRenderer=qe,L.createSelectionHandler=cn,L.createSpansRenderer=Ht,L.createTextAnnotator=Ko,L.createTextAnnotatorState=qt,L.debounce=Me,L.fillDefaults=dn,L.getBackgroundColor=Yt,L.getHighlightClientRects=Vt,L.getQuoteContext=gt,L.getRangeAnnotatableContents=Re,L.getViewportBounds=jt,L.isMac=Ye,L.isNodeWhitespaceOrEmpty=yn,L.isNotAnnotatable=ge,L.isRangeAnnotatable=Pe,L.isRangeWhitespaceOrEmpty=lt,L.isRevived=Z,L.isRevivedAnnotation=he,L.isRevivedTarget=fn,L.mergeClientRects=Xt,L.mergeRanges=ct,L.parseW3CTextAnnotation=St,L.programmaticallyFocusable=dt,L.rangeToSelector=pt,L.reviveAnnotation=$e,L.reviveTarget=pe,L.reviveTextSelector=Xe,L.scrollIntoView=bt,L.serializeW3CTextAnnotation=Ct,L.splitAnnotatableRanges=ut,L.toDomRectList=fo,L.toParentBounds=$t,L.toViewportBounds=ho,L.trackViewport=Ft,L.trimRangeToContainer=ft,L.whitespaceOrEmptyRegex=Ve,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
3
3
  //# sourceMappingURL=text-annotator.umd.js.map