@recogito/text-annotator 4.2.3 → 4.2.5

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(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 P=[];for(let e=0;e<256;++e)P.push((e+256).toString(16).slice(1));function hn(e,t=0){return(P[e[t+0]]+P[e[t+1]]+P[e[t+2]]+P[e[t+3]]+"-"+P[e[t+4]]+P[e[t+5]]+"-"+P[e[t+6]]+P[e[t+7]]+"-"+P[e[t+8]]+P[e[t+9]]+"-"+P[e[t+10]]+P[e[t+11]]+P[e[t+12]]+P[e[t+13]]+P[e[t+14]]+P[e[t+15]]).toLowerCase()}const gn=new Uint8Array(16);function pn(){return crypto.getRandomValues(gn)}function rt(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",re=`.${Ke}`,ge=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(re):t.parentElement?.closest(re)):!0,Ve=(e,t)=>{const n=t.commonAncestorContainer;return!ge(e,n)},Xe=/^\s*$/,at=e=>Xe.test(e.toString()),yn=e=>Xe.test(e.textContent||""),lt=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]},ct=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(re)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},dt=(e,t)=>{if(!Ve(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(re).forEach(n=>n.remove()),t},ut=(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},ft=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ht=(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=[...ft.segment(r)],u=[...ft.segment(l)];return{prefix:d.slice(-n).map(f=>f.segment).join(""),suffix:u.slice(0,n).map(f=>f.segment).join("")}},gt=(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}},pt=(e,t)=>{if(Z(e))return e;const{start:n,end:o}=e,i=e.offsetReference||t,s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,u=>u.parentElement?.closest(re)?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 u=l.textContent?.length||0;if(r+u>n){a.setStart(l,n-r);break}r+=u}l=s.nextNode()}for(;l!==null;){const u=l.textContent?.length||0;if(r+u>=o){a.setEnd(l,o-r);break}r+=u,l=s.nextNode()}return{...e,range:a}},pe=(e,t,n=(o,i)=>pt(o,i))=>({...e,selector:e.selector.flatMap(o=>n(o,t))}),Pe=(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,s=n.clientWidth,r=t.selector[0].range.getBoundingClientRect(),{width:a,height:l}=e.getAnnotationBounds(t.annotation),d=r.top-o.top,u=r.left-o.left,f=n.parentElement?n.scrollTop:0,y=n.parentElement?n.scrollLeft:0,g=d+f-(i-l)/2,c=u+y-(s-a)/2;n.scroll({top:g,left:c,behavior:"smooth"})},bt=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,s=o?typeof o=="string"?document.getElementById(o):o:mt(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 yt(t,r.target,s),!0;const l=pe(r.target,e),{range:d}=l.selector[0];return d&&!d.collapsed?(yt(t,l,s),!0):!1};var At=Object.prototype.hasOwnProperty;function ae(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--&&ae(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)||!ae(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 Oe=4,wn=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),$e=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+Oe;s<Q.length;)Q[s]===o?Q.splice(s,Oe):s+=Oe;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+=Oe)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=$e(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 He=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(He||{});const je={selected:[]},vn=(e,t,n)=>{const o=$e(je);let i=t;const s=()=>{ae(o.get(),je)||o.set(je)},r=()=>{var g;return((g=o.get().selected)==null?void 0:g.length)===0},a=g=>{if(r())return!1;const c=typeof g=="string"?g:g.id;return o.get().selected.some(m=>m.id===c)},l=(g,c)=>{let m;if(Array.isArray(g)){if(m=g.map(h=>e.getAnnotation(h)).filter(Boolean),m.length<g.length){console.warn("Invalid selection: "+g.filter(h=>!m.some(p=>p.id===h)));return}}else{const h=e.getAnnotation(g);if(!h){console.warn("Invalid selection: "+g);return}m=[h]}const S=m.reduce((h,p)=>{const x=y(p);return x==="EDIT"?[...h,{id:p.id,editable:!0}]:x==="SELECT"?[...h,{id:p.id}]:h},[]);o.set({selected:S,event:c})},d=(g,c)=>{const m=Array.isArray(g)?g:[g],S=m.map(h=>e.getAnnotation(h)).filter(h=>!!h);o.set({selected:S.map(h=>{const p=c===void 0?y(h)==="EDIT":c;return{id:h.id,editable:p}})}),S.length!==m.length&&console.warn("Invalid selection",g)},u=g=>{if(r())return!1;const{selected:c}=o.get();c.some(({id:m})=>g.includes(m))&&o.set({selected:c.filter(({id:m})=>!g.includes(m))})},f=g=>{i=g,d(o.get().selected.map(({id:c})=>c))},y=g=>Sn(g,i,n);return e.observe(({changes:g})=>u((g.deleted||[]).map(c=>c.id))),{get event(){const g=o.get();return g?g.event:null},get selected(){const g=o.get();return g?[...g.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:y,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"},$=[];for(let e=0;e<256;++e)$.push((e+256).toString(16).slice(1));function Cn(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 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 Fe=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&&!ae(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Nn=(e,t)=>!ae(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: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(u=>a(u.bodiesCreated)||a(u.bodiesDeleted)||a(u.bodiesUpdated)),d=(o=i.updated)==null?void 0:o.some(u=>u.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: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})=>!s.has(f.id)).map(f=>{const{oldValue:y,newValue:g}=f;if(r.has(g.id)){const c=t.updated.find(m=>m.oldValue.id===g.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}},We=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)},s=(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)})},r=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=We(b);r(w),s(A,{created:[w]})}},l=(b,A)=>{const w=We(typeof b=="string"?A:b),T=typeof b=="string"?b:b.id,v=T&&e.get(T);if(v){const R=Et(v,w);return T===w.id?e.set(T,w):(e.delete(T),e.set(w.id,w)),v.bodies.forEach(K=>t.delete(K.id)),w.bodies.forEach(K=>t.set(K.id,w.id)),R}else console.warn(`Cannot update annotation ${T} - does not exist`)},d=(b,A=_.LOCAL,w=_.LOCAL)=>{const T=In(A)?w:A,v=l(b,A);v&&s(T,{updated:[v]})},u=(b,A=_.LOCAL)=>{e.get(b.id)?d(b,A):a(b,A)},f=(b,A=_.LOCAL)=>{const w=b.reduce((T,v)=>{const R=l(v);return R?[...T,R]:T},[]);w.length>0&&s(A,{updated:w})},y=b=>b.map(We).reduce((A,w)=>e.get(w.id)?{...A,toUpdate:[...A.toUpdate,w]}:{...A,toAdd:[...A.toAdd,w]},{toAdd:[],toUpdate:[]}),g=(b,A=_.LOCAL)=>{const{toAdd:w,toUpdate:T}=y(b),v=T.map(R=>l(R,A)).filter(Boolean);w.forEach(r),s(A,{created:w,updated:v})},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),s(A,{updated:[{oldValue:w,newValue:T,bodiesCreated:[b]}]})}else console.warn(`Attempt to add body to missing annotation: ${b.annotation}`)},m=()=>[...e.values()],S=(b=_.LOCAL)=>{const A=[...e.values()];e.clear(),t.clear(),s(b,{deleted:A})},h=(b,A=_.LOCAL)=>{const{toAdd:w,toUpdate:T}=y(b),v=new Set([...w,...T].map(H=>H.id)),R=[...e.keys()].filter(H=>!v.has(H)).map(H=>x(H)).filter(Boolean),K=T.map(H=>l(H)).filter(Boolean);w.forEach(r),s(A,{created:w,updated:K,deleted:R})},p=(b,A=!0,w=_.LOCAL)=>{A?h(b,w):g(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&&s(A,{deleted:[w]})},E=(b,A=_.LOCAL)=>{const w=b.reduce((T,v)=>{const R=x(v);return R?[...T,R]:T},[]);w.length>0&&s(A,{deleted:w})},C=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(v=>v.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}`)},O=(b,A=_.LOCAL)=>{const w=C(b);w&&s(A,{updated:[w]})},N=(b,A=_.LOCAL)=>{const w=b.map(T=>C(T)).filter(Boolean);w.length>0&&s(A,{updated:w})},I=b=>{const A=e.get(b);return A?{...A}:void 0},M=b=>{const A=t.get(b);if(A){const w=I(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}`)},B=(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(R=>R.id===b.id),v={...w,bodies:w.bodies.map(R=>R.id===T.id?A:R)};return e.set(w.id,v),T.id!==A.id&&(t.delete(T.id),t.set(A.id,v.id)),{oldValue:w,newValue:v,bodiesUpdated:[{oldBody:T,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${b.annotation}`)},Y=(b,A,w=_.LOCAL)=>{const T=B(b,A);T&&s(w,{updated:[T]})},F=(b,A=_.LOCAL)=>{const w=b.map(T=>B({id:T.id,annotation:T.annotation},T)).filter(Boolean);s(A,{updated:w})},le=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:p,bulkDeleteAnnotations:E,bulkDeleteBodies:N,bulkUpdateAnnotations:f,bulkUpdateBodies:F,bulkUpdateTargets:(b,A=_.LOCAL)=>{const w=b.map(T=>le(T)).filter(Boolean);w.length>0&&s(A,{updated:w})},bulkUpsertAnnotations:g,clear:S,deleteAnnotation:k,deleteBody:O,getAnnotation:I,getBody:M,observe:o,syncAnnotations:h,unobserve:i,updateAnnotation:d,updateBody:Y,updateTarget:(b,A=_.LOCAL)=>{const w=le(b);w&&s(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,s=!1,r=0;const a=c=>{if(!s){const{changes:m}=c,S=performance.now();if(S-r>Yn)o.splice(i+1),o.push(m),i=o.length-1;else{const h=o.length-1;o[h]=_n(o[h],m)}r=S}s=!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),g=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){s=!0;const{created:c,updated:m,deleted:S}=o[i+1];d(c),f(m),g(S),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:c,updated:m,deleted:S}=o[i];l(c),u(m),y(S),n.emit("undo",o[i]),i-=1}}}},Vn=()=>{const e=$e([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Xn=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:a}=e,l=new Map;let d=[],u;const f=(m,S)=>{l.has(m)?l.get(m).push(S):l.set(m,[S])},y=(m,S)=>{const h=l.get(m);if(h){const p=h.indexOf(S);p!==-1&&h.splice(p,1)}},g=(m,S,h)=>{l.has(m)&&setTimeout(()=>{l.get(m).forEach(p=>{if(n){const x=Array.isArray(S)?S.map(E=>n.serialize(E)):n.serialize(S),k=h?h instanceof PointerEvent?h:n.serialize(h):void 0;p(x,k)}else p(S,h)})},1)};s.subscribe(({selected:m})=>{if(!(d.length===0&&m.length===0)){if(d.length===0&&m.length>0)d=m.map(({id:S})=>r.getAnnotation(S));else if(d.length>0&&m.length===0)d.forEach(S=>{const h=r.getAnnotation(S.id);h&&!ae(h,S)&&g("updateAnnotation",h,S)}),d=[];else{const S=new Set(d.map(p=>p.id)),h=new Set(m.map(({id:p})=>p));d.filter(p=>!h.has(p.id)).forEach(p=>{const x=r.getAnnotation(p.id);x&&!ae(x,p)&&g("updateAnnotation",x,p)}),d=[...d.filter(p=>h.has(p.id)),...m.filter(({id:p})=>!S.has(p)).map(({id:p})=>r.getAnnotation(p))]}g("selectionChanged",d)}}),i.subscribe(m=>{!u&&m?g("mouseEnterAnnotation",r.getAnnotation(m)):u&&!m?g("mouseLeaveAnnotation",r.getAnnotation(u)):u&&m&&(g("mouseLeaveAnnotation",r.getAnnotation(u)),g("mouseEnterAnnotation",r.getAnnotation(m))),u=m}),a?.subscribe(m=>g("viewportIntersect",m.map(S=>r.getAnnotation(S)))),r.observe(m=>{const{created:S,deleted:h}=m.changes;(S||[]).forEach(p=>g("createAnnotation",p)),(h||[]).forEach(p=>g("deleteAnnotation",p)),(m.changes.updated||[]).filter(p=>[...p.bodiesCreated||[],...p.bodiesDeleted||[],...p.bodiesUpdated||[]].length>0).forEach(({oldValue:p,newValue:x})=>{const k=d.find(E=>E.id===p.id)||p;d=d.map(E=>E.id===p.id?x:E),g("updateAnnotation",x,k)})},{origin:_.LOCAL}),r.observe(m=>{if(d){const S=new Set(d.map(p=>p.id)),h=(m.changes.updated||[]).filter(({newValue:p})=>S.has(p.id)).map(({newValue:p})=>p);h.length>0&&(d=d.map(p=>h.find(k=>k.id===p.id)||p))}},{origin:_.REMOTE});const c=m=>S=>{const{updated:h}=S;m?(h||[]).forEach(p=>g("updateAnnotation",p.oldValue,p.newValue)):(h||[]).forEach(p=>g("updateAnnotation",p.newValue,p.oldValue))};return t.on("undo",c(!0)),t.on("redo",c(!1)),{on:f,off:y,emit:g}},Pn=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=h=>{if(n){const{parsed:p,error:x}=n.parse(h);p?o.addAnnotation(p,_.REMOTE):console.error(x)}else o.addAnnotation(Fe(h),_.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=h=>{const p=o.getAnnotation(h);return n&&p?n.serialize(p):p},d=()=>n?o.all().map(n.serialize):o.all(),u=()=>{var h;const p=(((h=i.selected)==null?void 0:h.map(x=>x.id))||[]).map(x=>o.getAnnotation(x)).filter(Boolean);return n?p.map(n.serialize):p},f=(h,p=!0)=>fetch(h).then(x=>x.json()).then(x=>(g(x,p),x)),y=h=>{if(typeof h=="string"){const p=o.getAnnotation(h);if(o.deleteAnnotation(h),p)return n?n.serialize(p):p}else{const p=n?n.parse(h).parsed:h;if(p)return o.deleteAnnotation(p),h}},g=(h,p=!0)=>{const x=p?o.syncAnnotations:o.bulkUpsertAnnotations;if(n){const k=n.parseAll||Pn(n),{parsed:E,failed:C}=k(h);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),x(E,_.REMOTE)}else x(h.map(Fe),_.REMOTE)},c=(h,p)=>{h?i.setSelected(h,p):i.clear()},m=h=>{i.setUserSelectAction(h)},S=h=>{if(n){const p=n.parse(h).parsed,x=n.serialize(o.getAnnotation(p.id));return o.updateAnnotation(p),x}else{const p=o.getAnnotation(h.id);return o.updateAnnotation(Fe(h)),p}};return{addAnnotation:s,cancelSelected:r,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:g,setSelected:c,setUserSelectAction:m,undo:t.undo,updateAnnotation:S}};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}`},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:s,value:r,created:a,modified:l,creator:d,...u}=n;return{id:o||`temp-${Gn(n)}`,annotation:t,type:i,purpose:s,value:r,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:s,...r}=t,a={...r,created:i?.toISOString(),modified:s?.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: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:vt(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 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(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||rt(),{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}}},Ct=(e,t,n)=>{const{bodies:o,target:i,...s}=e,{selector:r,creator:a,created:l,updated:d,...u}=i,f=r.map(y=>{const{id:g,quote:c}=y,m={type:"TextQuoteSelector",exact:c};if(n&&"range"in y){const{prefix:x,suffix:k}=ht(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:S,end:h}=y,p={type:"TextPositionSelector",start:S,end:h};return{...u,id:g,scope:"scope"in y?y.scope:void 0,source:t,selector:[m,p]}});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 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(re)&&!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)})},ze=(e,t,n,o)=>{const{store:i,selection:s,hover:r}=n,a=Tt();let l;const d=new Map;let u;const f=Ft(o),y=M=>{const{x:B,y:Y}=t.getBoundingClientRect(),F=i.getAt(M.clientX-B,M.clientY-Y,!1,u);F&&n.selection.evalSelectAction(F)!==He.NONE?r.current!==F.id&&(t.classList.add("hovered"),r.set(F.id)):r.current&&(t.classList.remove("hovered"),r.set(null))};t.addEventListener("pointermove",y);const g=Me((M=!1)=>requestAnimationFrame(()=>{const B=jt(t),{minX:Y,minY:F,maxX:le,maxY:b}=B,A=u?i.getIntersecting(Y,F,le,b).filter(({annotation:v})=>u?.(v)):i.getIntersecting(Y,F,le,b),w=s.selected.map(({id:v})=>v),T=A.map(({annotation:v,rects:R})=>{const K=w.includes(v.id),H=v.id===r.current;return{annotation:v,rects:R,state:{selected:K,hovered:H}}});e.redraw(T,B,l,d,M),setTimeout(()=>{f(A.map(({annotation:v})=>v)),a.emit("onRedraw")},1)}),10),c=(M,B)=>{B?M?d.set(B,M):d.delete(B):l=M,g(!0)},m=M=>{u=M,g(!1)},S=(M,B)=>a.on(M,B),h=()=>{g()};i.observe(h);const p=s.subscribe(()=>{g()}),x=r.subscribe(()=>{g()}),k=()=>{g(!0)};document.addEventListener("scroll",k,{capture:!0,passive:!0});const E=Me(()=>{i.recalculatePositions(),g()},10);window.addEventListener("resize",E);const C=new ResizeObserver(E);C.observe(t);const O={attributes:!0,childList:!0,subtree:!0},N=new MutationObserver(Me(M=>{M.every(Y=>Y.target===t||t.contains(Y.target))||g(!0)},150));return N.observe(document.body,O),{destroy:()=>{t.removeEventListener("pointermove",y),e.destroy(),i.unobserve(h),p(),x(),document.removeEventListener("scroll",k),window.removeEventListener("resize",E),C.disconnect(),N.disconnect()},on:S,redraw:g,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)}},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,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,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}},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 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}},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,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,_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=ro.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)||so.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,s=i===void 0?1:i;return ee(t)&&ee(n)&&ee(o)?Rt({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=Mt({h:Number(t),s:Number(n),l:Number(o),a:Number(s)});return Bt(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: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(s)});return kt(r)},"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]},Ge=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}},Qe=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(Qe(this.rgba),2)},e.prototype.isDark=function(){return Qe(this.rgba)<.5},e.prototype.isLight=function(){return Qe(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?Ne(X(255*s)):"","#"+Ne(n)+Ne(o)+Ne(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=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(Ge(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),z(Ge(this.rgba,-t))},e.prototype.grayscale=function(){return z(Ge(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(),Je=(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 Ze(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--&&Ze(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)||!Ze(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Vt=(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 u=e.startContainer.childNodes[e.startOffset];u?a.setStartBefore(u):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 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,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)},Pt=(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)}}),$t=(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,u)=>{if(!(!Ze(n,r)||u))return;t.innerHTML="",[...r].sort((c,m)=>{const{annotation:{target:{created:S}}}=c,{annotation:{target:{created:h}}}=m;return S&&h?S.getTime()-h.getTime():0}).forEach(c=>{const m=d?.get(c.annotation.id)||l;c.rects.map(S=>{const h=Vt(S,r),p=Je(c,m,h),x=document.createElement("span");x.className="r6o-annotation",x.dataset.annotation=c.annotation.id,x.style.left=`${S.x}px`,x.style.top=`${S.y}px`,x.style.width=`${S.width}px`,x.style.height=`${S.height}px`,x.style.backgroundColor=Yt(p),p.underlineStyle&&(x.style.borderStyle=p.underlineStyle),p.underlineColor&&(x.style.borderColor=p.underlineColor),p.underlineThickness&&(x.style.borderBottomWidth=`${p.underlineThickness}px`),p.underlineOffset&&(x.style.paddingBottom=`${p.underlineOffset}px`),t.appendChild(x)})}),n=r},setVisible:r=>{r?t.classList.remove("hidden"):t.classList.add("hidden")}}},Ht=(e,t,n)=>ze(go(e),e,t,n),jt=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}},Ft=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 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),g=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,g,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(!Ie(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;Ie(t,l)&&(n.leaf?o.push(a):tt(t,l)?this._all(a,o):s.push(a))}n=s.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 s=n.children[i],r=n.leaf?this.toBBox(s):s;if(Ie(t,r)){if(n.leaf||tt(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=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 u=yo(t,o.children,n);if(u!==-1)return o.children.splice(u,1),s.push(o),this._condense(s),this}!d&&!o.leaf&&tt(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));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 g=Math.min(y+l-1,f);a.children.push(this._build(t,y,g,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],u=et(d),f=wo(t,d)-u;f<r?(r=f,s=u<s?u:s,a=d):f===r&&u<s&&(s=u,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),u=Eo(l,d),f=et(l)+et(d);u<s?(s=u,i=a,r=f<r?f:r):u===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=_e(r)+_e(a);for(let d=n;d<o-n;d++){const u=t.children[d];we(r,t.leaf?s(u):u),l+=_e(r)}for(let d=o-n-1;d>=n;d--){const u=t.children[d];we(a,t.leaf?s(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 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 et(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),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function tt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function 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 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;Wt(e,r,t,n,i),s.push(t,r,r,n)}}const vo=(e,t,n,o)=>{const i=new mo,s=new Map,r=Tt(),a=(E,C)=>{const O=E.selector.flatMap(I=>Xt(I.range)),N=Pt(O,n,o).map(I=>$t(I,C));return N.map(I=>{const{x:M,y:B,width:Y,height:F}=I;return{minX:M,minY:B,maxX:M+Y,maxY:B+F,annotation:{id:E.annotation,rects:N}}})},l=()=>[...s.values()],d=()=>{i.clear(),s.clear()},u=E=>{const C=a(E,t.getBoundingClientRect());C.length!==0&&(C.forEach(O=>i.insert(O)),s.set(E.annotation,C))},f=E=>{const C=s.get(E.annotation);C&&(C.forEach(O=>i.remove(O)),s.delete(E.annotation))},y=E=>{f(E),u(E)},g=(E,C=!0)=>{C&&d();const O=t.getBoundingClientRect(),N=E.map(M=>({target:M,rects:a(M,O)}));N.forEach(({target:M,rects:B})=>{B.length>0&&s.set(M.annotation,B)});const I=N.flatMap(({rects:M})=>M);i.load(I)},c=(E,C,O=!1)=>{const N=i.search({minX:E,minY:C,maxX:E,maxY:C}),I=M=>M.annotation.rects.reduce((B,Y)=>B+Y.width*Y.height,0);return N.length>0?(N.sort((M,B)=>I(M)-I(B)),O?N.map(M=>M.annotation.id):[N[0].annotation.id]):[]},m=E=>{const C=S(E);if(C.length===0)return;let O=C[0].left,N=C[0].top,I=C[0].right,M=C[0].bottom;for(let B=1;B<C.length;B++){const Y=C[B];O=Math.min(O,Y.left),N=Math.min(N,Y.top),I=Math.max(I,Y.right),M=Math.max(M,Y.bottom)}return new DOMRect(O,N,I-O,M-N)},S=E=>{const C=s.get(E);return C?C[0].annotation.rects:[]};return{all:l,clear:d,getAt:c,getAnnotationBounds:m,getAnnotationRects:S,getIntersecting:(E,C,O,N)=>{const I=i.search({minX:E,minY:C,maxX:O,maxY:N}),M=new Set(I.map(B=>B.annotation.id));return Array.from(M).map(B=>({annotation:e.getAnnotation(B),rects:S(B)})).filter(B=>!!B.annotation)},insert:u,recalculate:()=>{g(e.all().map(E=>E.target),!0),r.emit("recalculate")},remove:f,set:g,size:()=>i.all().length,update:y,on:(E,C)=>r.on(E,C)}},qt=(e,t)=>{const n=Dn(),o=vo(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance),i=vn(n,t.userSelectAction,t.adapter),s=En(n),r=Vn(),a=(k,E=_.LOCAL)=>{const C=Pe(k,e,t.selectorReviveFn),O=Z(C.target.selector);return O&&n.addAnnotation(C,E),O},l=k=>{const E=k.map(O=>Pe(O,e,t.selectorReviveFn)),C=E.filter(O=>!Z(O.target.selector));return{revived:E,couldNotRevive:C}},d=(k,E=_.LOCAL)=>{const{revived:C,couldNotRevive:O}=l(k);return n.syncAnnotations(C,E),O},u=(k,E=_.LOCAL)=>{const{revived:C,couldNotRevive:O}=l(k);return n.bulkUpsertAnnotations(C,E),O},f=(k,E=!0,C=_.LOCAL)=>E?d(k,C):u(k,C),y=(k,E=_.LOCAL)=>{const C=pe(k,e);n.updateTarget(C,E)},g=(k,E=_.LOCAL)=>{const C=k.map(O=>pe(O,e));n.bulkUpdateTargets(C,E)};function c(k,E,C,O){const N=C||!!O,I=o.getAt(k,E,N).map(B=>n.getAnnotation(B)).filter(Boolean),M=O?I.filter(O):I;if(M.length!==0)return C?M:M[0]}const m=k=>o.getAnnotationRects(k).length>0?o.getAnnotationBounds(k):void 0,S=(k,E,C,O)=>o.getIntersecting(k,E,C,O),h=k=>o.getAnnotationRects(k),p=()=>o.recalculate(),x=k=>o.on("recalculate",k);return n.observe(({changes:k})=>{const E=(k.deleted||[]).filter(N=>Z(N.target.selector)),C=(k.created||[]).filter(N=>Z(N.target.selector)),O=(k.updated||[]).filter(N=>Z(N.newValue.target.selector));E?.length>0&&E.forEach(N=>o.remove(N.target)),C.length>0&&o.set(C.map(N=>N.target),!1),O?.length>0&&O.forEach(({newValue:N})=>o.update(N.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotations:f,bulkUpdateTargets:g,bulkUpsertAnnotations:u,getAnnotationBounds:m,getAnnotationRects:h,getIntersecting:S,getAt:c,recalculatePositions:p,onRecalculatePositions:x,syncAnnotations:d,updateTarget:y},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 y=i,g=s;return i=void 0,s=void 0,l=e.apply(y,g),l}function u(){const y=Date.now()-a;y<t&&y>=0?r=setTimeout(u,t-y):(r=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,s=y,a=Date.now();const g=o&&!r;if(r||(r=setTimeout(u,t)),g)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 nt=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function ot(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 s=0;s<n.length;s++)o.indexOf(n[s])===-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,"-":nt?173:189,"=":nt?61:187,";":nt?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},U={};for(let e=1;e<20;e++)ve[`f${e}`]=111+e;let D=[],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=()=>D.slice(0),Ro=()=>D.map(e=>To(e)||xo(e)||String.fromCharCode(e)),Oo=()=>{const e=[];return Object.keys(U).forEach(t=>{U[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},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)),D.indexOf(e)!==-1),Mo=(e,t)=>{let n,o;e||(e=Te());for(const i in U)if(Object.prototype.hasOwnProperty.call(U,i))for(n=U[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(({element:r})=>it(r)):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=D.indexOf(t);if(n>=0&&D.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&D.splice(0,D.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(U).forEach(n=>{Array.isArray(U[n])&&U[n].forEach(o=>De(o)),delete U[n]}),it(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(s=>{const r=s.split(o),a=r.length,l=r[a-1],d=l==="*"?"*":fe(l);if(!U[d])return;t||(t=Te());const u=a>1?Gt(q,r):[],f=[];U[d]=U[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=>it(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 s in V)Object.prototype.hasOwnProperty.call(V,s)&&(!V[s]&&t.mods.indexOf(+s)>-1||V[s]&&t.mods.indexOf(+s)===-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(D),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function sn(e,t){const n=U["*"];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),D.indexOf(o)===-1&&o!==229&&D.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(l=>{const d=Se[l];e[l]&&D.indexOf(d)===-1?D.push(d):!e[l]&&D.indexOf(d)>-1?D.splice(D.indexOf(d),1):l==="metaKey"&&e[l]&&(D=D.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")&&(D.indexOf(17)===-1&&D.push(17),D.indexOf(18)===-1&&D.push(18),V[17]=!0,V[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)&&on(e,n[l],s,t);if(!(o in U))return;const r=U[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:u}=d,f=d.key.split(u),y=[];for(let g=0;g<f.length;g++)y.push(fe(f[g]));y.sort().join("")===D.sort().join("")&&on(e,d,s,t)}}const G=function e(t,n,o){D=[];const i=Qt(t);let s=[],r="all",a=document,l=0,d=!1,u=!0,f="+",y=!1,g=!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&&(u=c.keydown),c.capture!==void 0&&(y=c.capture),typeof c.splitKey=="string"&&(f=c.splitKey),c.single===!0&&(g=!0)}for(typeof n=="string"&&(r=n),g&&nn(t,r);l<i.length;l++){const c=i[l].split(f);s=[],c.length>1&&(s=Gt(q,c));let m=c[c.length-1];m=m==="*"?"*":fe(m),m in U||(U[m]=[]),U[m].push({keyup:d,keydown:u,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=(S=window.event)=>sn(S,a),m=(S=window.event)=>{sn(S,a),No(S)};ne.set(a,{keydownListener:c,keyupListenr:m,capture:y}),ot(a,"keydown",c,y),ot(a,"keyup",m,y)}if(!Ce){const c=()=>{D=[]};Ce={listener:c,capture:y},ot(window,"focus",c,y)}if(!ue&&typeof document<"u"){const c=()=>{D=[];for(const h in V)V[h]=!1;for(const h in q)e[h]=!1},m=c,S=c;document.addEventListener("fullscreenchange",m),document.addEventListener("webkitfullscreenchange",S),ue={fullscreen:m,webkit:S}}}};function Bo(e,t="all"){Object.keys(U).forEach(n=>{U[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method({},i)})})}function it(e){const t=Object.values(U).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(U).forEach(i=>delete U[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 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 rn=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:s}=t;let r;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:d,dismissOnNotAnnotatable:u="NEVER"}=o;let f,y=a,g="CREATE_NEW",c,m,S,h;const p=v=>{y=v,N.clear(),v||(m=void 0,c=void 0,S=void 0,h=void 0)},x=v=>g=v||"CREATE_NEW",k=v=>f=v,E=v=>r=v,C=v=>{if(g==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const R=v;return Ye?R.metaKey:R.ctrlKey}else return!1},O=()=>{if(!y||S===!1)return;const{selected:v}=s;if((C(h)||g==="REPLACE_CURRENT")&&v.length===1&&v[0].editable){const K=i.getAnnotation(v[0].id);if(K?.target){m=K.target,c={annotation:K.id,selector:[],created:m.created,creator:m.creator,updated:new Date,updatedBy:r};return}}m=void 0,c={annotation:rt(),selector:[],created:new Date,creator:r}},N=So(v=>{if(!y)return;const R=document.getSelection();if(!R?.anchorNode)return;const H=w().map(j=>ut(j,e));if(H.every(j=>!Ve(e,j))){c=void 0;return}const ie=v.timeStamp-(h?.timeStamp||v.timeStamp);if(h?.type==="pointerdown"&&(ie<1e3&&!c||R.isCollapsed&&ie<rn)&&O(),!c&&(O(),!c))return;if(R.isCollapsed){i.getAnnotation(c.annotation)&&!(C(h)||g==="REPLACE_CURRENT")&&(s.clear(),i.deleteAnnotation(c.annotation));return}if(H.every(j=>at(j)))return;const J=H.flatMap(j=>dt(e,j.cloneRange()));if(!(J.length>0&&!c||J.length!==c.selector.length||J.some((j,xe)=>j.toString()!==c?.selector[xe]?.quote)))return;const Ue=C(h)&&m?lt([...m.selector.map(j=>j.range),...J]):J;c={...c,selector:Ue.map(j=>gt(j,e,l)),updated:new Date},!(C(h)||g==="REPLACE_CURRENT")&&(i.getAnnotation(c.annotation)?i.updateTarget(c,_.LOCAL):s.clear())},10),I=v=>{h=ke(v),S=h.button===0},M=async v=>{if(!S)return;const R=ke(v),K=()=>{const{x:ie,y:J}=e.getBoundingClientRect();if(ge(e,R.target)){(typeof u=="function"?u(R,e):u==="ALWAYS")&&s.clear();return}const se=R.target instanceof Node&&e.contains(R.target)&&i.getAt(R.clientX-ie,R.clientY-J,d==="all",f);if(se){const{selected:Ue}=s,j=new Set(Ue.map(Le=>Le.id)),xe=Array.isArray(se)?se.map(Le=>Le.id):[se.id];(j.size!==xe.length||!xe.every(Le=>j.has(Le)))&&(n.emit("clickAnnotation",se),s.userSelect(xe,R))}else s.clear()};if(R.timeStamp-(h?.timeStamp||0)<rn){await B();const ie=document.getSelection(),J=ge(e,h?.target),se=ge(e,R.target);if(ie?.isCollapsed||J&&se){c=void 0,K();return}}c&&c.selector.length>0&&(T(),s.userSelect(c.annotation,R))},B=async()=>{const v=document.getSelection();let R=!1,K=v?.isCollapsed;const H=()=>K||R,ie=1;return setTimeout(()=>R=!0,50),_o(()=>K=v?.isCollapsed,ie,H)},Y=v=>{document.getSelection()?.isCollapsed||((!c||c.selector.length===0)&&N(v),c&&(T(),s.userSelect(c.annotation,ke(v))))},F=v=>{if(y&&!v.repeat&&w().length!==0&&v.key==="Shift"&&c){const R=document.getSelection();R&&!R.isCollapsed&&(T(),s.userSelect(c.annotation,me(v)))}},le=v=>{const R=()=>setTimeout(()=>{c&&(c.selector.length>0&&(s.clear(),i.addAnnotation({id:c.annotation,bodies:[],target:c}),s.userSelect(c.annotation,me(v))),document.removeEventListener("selectionchange",R))},100);document.addEventListener("selectionchange",R),O()};G(Io.join(","),{element:e,keydown:!0,keyup:!1},v=>{v.repeat||(h=me(v))}),G(ln,{keydown:!0,keyup:!1},v=>{h=me(v),le(v)});const b=v=>{v.repeat||w().length!==0&&(c=void 0,s.clear())};G(an.join(","),{keydown:!0,keyup:!1},b),document.addEventListener("pointerdown",I),document.addEventListener("pointerup",M),document.addEventListener("contextmenu",Y),document.addEventListener("keyup",F),e.addEventListener("selectstart",O),document.addEventListener("selectionchange",N);const A=()=>{c=void 0,m=void 0,S=void 0,h=void 0,N.clear(),document.removeEventListener("pointerdown",I),document.removeEventListener("pointerup",M),document.removeEventListener("contextmenu",Y),document.removeEventListener("keyup",F),e.removeEventListener("selectstart",O),document.removeEventListener("selectionchange",N),G.unbind()},w=()=>{const v=document.getSelection();return v?Array.from(Array(v.rangeCount).keys()).map(R=>v.getRangeAt(R)).filter(R=>R.intersectsNode(e)):[]},T=()=>{if(!c)return;const v=i.getAnnotation(c.annotation);if(!v)i.addAnnotation({id:c.annotation,bodies:[],target:c});else{const{target:{updated:R}}=v,{updated:K}=c;(!R||!K||R<K)&&i.updateTarget(c)}};return{destroy:A,setFilter:k,setUser:E,setAnnotatingEnabled:p,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:s=>{console.log("setVisible not implemented on CSS Custom Highlights renderer")},redraw:(s,r,a,l,d)=>{const u=new Set(s.map(y=>y.annotation.id));Array.from(t).filter(y=>!u.has(y));const f=s.map(y=>{a?typeof a=="function"&&a(y.annotation,y.state):y.state?.selected;const g=Je(y,a);return`::highlight(_${y.annotation.id}) { ${Do(g)} }`});e.innerHTML=f.join(`
2
- `),CSS.highlights.clear(),s.forEach(({annotation:y})=>{const g=y.target.selector.map(m=>m.range),c=new Highlight(...g);CSS.highlights.set(`_${y.id}`,c)}),t=u}}},Yo=(e,t,n)=>ze(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),ct(e);const n=dn(t,{annotatingEnabled:!0,user:qn()}),o=qt(e,n),{selection:i,viewport:s}=o,r=o.store,a=Kn(r),l=Xn(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,s):u==="SPANS"?Ht(e,o,s):u==="CSS_HIGHLIGHTS"?Yo(e,o,s):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 g=$n(o,a,n.adapter),c=()=>d,m=E=>{y.setAnnotatingEnabled(E===void 0?!0:E)},S=E=>{y.setAnnotatingMode(E)},h=E=>{f.setFilter(E),y.setFilter(E)},p=E=>{d=E,y.setUser(E)},x=E=>{E?i.setSelected(E):i.clear()};return{...g,destroy:()=>{f.destroy(),y.destroy(),a.destroy()},element:e,getUser:c,renderer:f,setAnnotatingEnabled:m,setAnnotatingMode:S,setFilter:h,setStyle:f.setStyle.bind(f),setUser:p,setSelected:x,setVisible:f.setVisible.bind(f),on:l.on,off:l.off,scrollIntoView:bt(e,r),state:o}};L.DEFAULT_SELECTED_STYLE=Be,L.DEFAULT_STYLE=te,L.NOT_ANNOTATABLE_CLASS=Ke,L.NOT_ANNOTATABLE_SELECTOR=re,L.Origin=_,L.UserSelectAction=He,L.W3CTextFormat=Zn,L.cancelSingleClickEvents=xt,L.cloneKeyboardEvent=me,L.clonePointerEvent=ke,L.computeStyle=Je,L.computeZIndex=Vt,L.createBody=Rn,L.createRenderer=ze,L.createSelectionHandler=cn,L.createSpansRenderer=Ht,L.createTextAnnotator=Ko,L.createTextAnnotatorState=qt,L.debounce=Me,L.fillDefaults=dn,L.getBackgroundColor=Yt,L.getHighlightClientRects=Xt,L.getQuoteContext=ht,L.getRangeAnnotatableContents=Re,L.getViewportBounds=jt,L.isMac=Ye,L.isNodeWhitespaceOrEmpty=yn,L.isNotAnnotatable=ge,L.isRangeAnnotatable=Ve,L.isRangeWhitespaceOrEmpty=at,L.isRevived=Z,L.isRevivedAnnotation=he,L.isRevivedTarget=fn,L.mergeClientRects=Pt,L.mergeRanges=lt,L.parseW3CTextAnnotation=St,L.programmaticallyFocusable=ct,L.rangeToSelector=gt,L.reviveAnnotation=Pe,L.reviveTarget=pe,L.reviveTextSelector=pt,L.scrollIntoView=bt,L.serializeW3CTextAnnotation=Ct,L.splitAnnotatableRanges=dt,L.toDomRectList=fo,L.toParentBounds=$t,L.toViewportBounds=ho,L.trackViewport=Ft,L.trimRangeToContainer=ut,L.whitespaceOrEmptyRegex=Xe,Object.defineProperty(L,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 P=[];for(let e=0;e<256;++e)P.push((e+256).toString(16).slice(1));function hn(e,t=0){return(P[e[t+0]]+P[e[t+1]]+P[e[t+2]]+P[e[t+3]]+"-"+P[e[t+4]]+P[e[t+5]]+"-"+P[e[t+6]]+P[e[t+7]]+"-"+P[e[t+8]]+P[e[t+9]]+"-"+P[e[t+10]]+P[e[t+11]]+P[e[t+12]]+P[e[t+13]]+P[e[t+14]]+P[e[t+15]]).toLowerCase()}const gn=new Uint8Array(16);function pn(){return crypto.getRandomValues(gn)}function rt(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 Ke=typeof navigator<"u"&&navigator.platform.startsWith("Mac"),Ve="not-annotatable",re=`.${Ve}`,ge=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(re):t.parentElement?.closest(re)):!0,Xe=(e,t)=>{const n=t.commonAncestorContainer;return!ge(e,n)},Pe=/^\s*$/,at=e=>Pe.test(e.toString()),yn=e=>Pe.test(e.textContent||""),lt=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]},ct=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(Ve)&&!o.parentElement?.closest(re)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},dt=(e,t)=>{if(!Xe(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]},Oe=e=>{const t=e.cloneContents();return t.querySelectorAll(re).forEach(n=>n.remove()),t},ut=(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},ft=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ht=(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=Oe(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=Oe(a).textContent,d=[...ft.segment(r)],f=[...ft.segment(l)];return{prefix:d.slice(-n).map(u=>u.segment).join(""),suffix:f.slice(0,n).map(u=>u.segment).join("")}},gt=(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=Oe(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}},pt=(e,t)=>{if(Z(e))return e;const{start:n,end:o}=e,i=e.offsetReference||t,s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,f=>f.parentElement?.closest(re)?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 f=l.textContent?.length||0;if(r+f>n){a.setStart(l,n-r);break}r+=f}l=s.nextNode()}for(;l!==null;){const f=l.textContent?.length||0;if(r+f>=o){a.setEnd(l,o-r);break}r+=f,l=s.nextNode()}return{...e,range:a}},pe=(e,t,n=(o,i)=>pt(o,i))=>({...e,selector:e.selector.flatMap(o=>n(o,t))}),me=(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,s=n.clientWidth,r=t.selector[0].range.getBoundingClientRect(),{width:a,height:l}=e.getAnnotationBounds(t.annotation),d=r.top-o.top,f=r.left-o.left,u=n.parentElement?n.scrollTop:0,y=n.parentElement?n.scrollLeft:0,g=d+u-(i-l)/2,c=f+y-(s-a)/2;n.scroll({top:g,left:c,behavior:"smooth"})},bt=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,s=o?typeof o=="string"?document.getElementById(o):o:mt(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 yt(t,r.target,s),!0;const l=pe(r.target,e),{range:d}=l.selector[0];return d&&!d.collapsed?(yt(t,l,s),!0):!1};var At=Object.prototype.hasOwnProperty;function ae(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--&&ae(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)||!ae(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}),$e=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=$e(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 He=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(He||{});const je={selected:[]},vn=(e,t,n)=>{const o=$e(je);let i=t;const s=()=>{ae(o.get(),je)||o.set(je)},r=()=>{var g;return((g=o.get().selected)==null?void 0:g.length)===0},a=g=>{if(r())return!1;const c=typeof g=="string"?g:g.id;return o.get().selected.some(m=>m.id===c)},l=(g,c)=>{let m;if(Array.isArray(g)){if(m=g.map(h=>e.getAnnotation(h)).filter(Boolean),m.length<g.length){console.warn("Invalid selection: "+g.filter(h=>!m.some(p=>p.id===h)));return}}else{const h=e.getAnnotation(g);if(!h){console.warn("Invalid selection: "+g);return}m=[h]}const S=m.reduce((h,p)=>{const x=y(p);return x==="EDIT"?[...h,{id:p.id,editable:!0}]:x==="SELECT"?[...h,{id:p.id}]:h},[]);o.set({selected:S,event:c})},d=(g,c)=>{const m=Array.isArray(g)?g:[g],S=m.map(h=>e.getAnnotation(h)).filter(h=>!!h);o.set({selected:S.map(h=>{const p=c===void 0?y(h)==="EDIT":c;return{id:h.id,editable:p}})}),S.length!==m.length&&console.warn("Invalid selection",g)},f=g=>{if(r())return!1;const{selected:c}=o.get();c.some(({id:m})=>g.includes(m))&&o.set({selected:c.filter(({id:m})=>!g.includes(m))})},u=g=>{i=g,d(o.get().selected.map(({id:c})=>c))},y=g=>Sn(g,i,n);return e.observe(({changes:g})=>f((g.deleted||[]).map(c=>c.id))),{get event(){const g=o.get();return g?g.event:null},get selected(){const g=o.get();return g?[...g.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:y,isEmpty:r,isSelected:a,setSelected:d,setUserSelectAction:u,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"},$=[];for(let e=0;e<256;++e)$.push((e+256).toString(16).slice(1));function Cn(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 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 Fe=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&&!ae(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Nn=(e,t)=>!ae(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: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(f=>a(f.bodiesCreated)||a(f.bodiesDeleted)||a(f.bodiesUpdated)),d=(o=i.updated)==null?void 0:o.some(f=>f.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(u=>u.id)),o=new Set((e.updated||[]).map(({newValue:u})=>u.id)),i=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),r=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>n.has(u.id)||o.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(e.created||[]).filter(u=>!s.has(u.id)).map(u=>r.has(u.id)?t.updated.find(({oldValue:y})=>y.id===u.id).newValue:u),...t.created||[]],d=[...(e.deleted||[]).filter(u=>!i.has(u.id)),...(t.deleted||[]).filter(u=>!n.has(u.id))],f=[...(e.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:y,newValue:g}=u;if(r.has(g.id)){const c=t.updated.find(m=>m.oldValue.id===g.id).newValue;return Et(y,c)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:d,updated:f}},We=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,w={})=>{n.push({onChange:b,options:w})},i=b=>{const w=n.findIndex(E=>E.onChange==b);w>-1&&n.splice(w,1)},s=(b,w)=>{const E={origin:b,changes:{created:w.created||[],updated:w.updated||[],deleted:w.deleted||[]},state:[...e.values()]};n.forEach(T=>{Bn(T,E)&&T.onChange(E)})},r=b=>{e.set(b.id,b),b.bodies.forEach(w=>t.set(w.id,b.id))},a=(b,w=_.LOCAL)=>{if(b.id&&e.get(b.id))throw Error(`Cannot add annotation ${b.id} - exists already`);{const E=We(b);r(E),s(w,{created:[E]})}},l=(b,w)=>{const E=We(typeof b=="string"?w:b),T=typeof b=="string"?b:b.id,v=T&&e.get(T);if(v){const O=Et(v,E);return T===E.id?e.set(T,E):(e.delete(T),e.set(E.id,E)),v.bodies.forEach(K=>t.delete(K.id)),E.bodies.forEach(K=>t.set(K.id,E.id)),O}else console.warn(`Cannot update annotation ${T} - does not exist`)},d=(b,w=_.LOCAL,E=_.LOCAL)=>{const T=In(w)?E:w,v=l(b,w);v&&s(T,{updated:[v]})},f=(b,w=_.LOCAL)=>{e.get(b.id)?d(b,w):a(b,w)},u=(b,w=_.LOCAL)=>{const E=b.reduce((T,v)=>{const O=l(v);return O?[...T,O]:T},[]);E.length>0&&s(w,{updated:E})},y=b=>b.map(We).reduce((w,E)=>e.get(E.id)?{...w,toUpdate:[...w.toUpdate,E]}:{...w,toAdd:[...w.toAdd,E]},{toAdd:[],toUpdate:[]}),g=(b,w=_.LOCAL)=>{const{toAdd:E,toUpdate:T}=y(b),v=T.map(O=>l(O,w)).filter(Boolean);E.forEach(r),s(w,{created:E,updated:v})},c=(b,w=_.LOCAL)=>{const E=e.get(b.annotation);if(E){const T={...E,bodies:[...E.bodies,b]};e.set(E.id,T),t.set(b.id,T.id),s(w,{updated:[{oldValue:E,newValue:T,bodiesCreated:[b]}]})}else console.warn(`Attempt to add body to missing annotation: ${b.annotation}`)},m=()=>[...e.values()],S=(b=_.LOCAL)=>{const w=[...e.values()];e.clear(),t.clear(),s(b,{deleted:w})},h=(b,w=_.LOCAL)=>{const{toAdd:E,toUpdate:T}=y(b),v=new Set([...E,...T].map(H=>H.id)),O=[...e.keys()].filter(H=>!v.has(H)).map(H=>x(H)).filter(Boolean),K=T.map(H=>l(H)).filter(Boolean);E.forEach(r),s(w,{created:E,updated:K,deleted:O})},p=(b,w=!0,E=_.LOCAL)=>{w?h(b,E):g(b,E)},x=b=>{const w=typeof b=="string"?b:b.id,E=e.get(w);if(E)return e.delete(w),E.bodies.forEach(T=>t.delete(T.id)),E;console.warn(`Attempt to delete missing annotation: ${w}`)},Y=(b,w=_.LOCAL)=>{const E=x(b);E&&s(w,{deleted:[E]})},A=(b,w=_.LOCAL)=>{const E=b.reduce((T,v)=>{const O=x(v);return O?[...T,O]:T},[]);E.length>0&&s(w,{deleted:E})},C=b=>{const w=e.get(b.annotation);if(w){const E=w.bodies.find(T=>T.id===b.id);if(E){t.delete(E.id);const T={...w,bodies:w.bodies.filter(v=>v.id!==b.id)};return e.set(w.id,T),{oldValue:w,newValue:T,bodiesDeleted:[E]}}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}`)},k=(b,w=_.LOCAL)=>{const E=C(b);E&&s(w,{updated:[E]})},R=(b,w=_.LOCAL)=>{const E=b.map(T=>C(T)).filter(Boolean);E.length>0&&s(w,{updated:E})},B=b=>{const w=e.get(b);return w?{...w}:void 0},M=b=>{const w=t.get(b);if(w){const E=B(w).bodies.find(T=>T.id===b);if(E)return E;console.error(`Store integrity error: body ${b} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${b}`)},N=(b,w)=>{if(b.annotation!==w.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=e.get(b.annotation);if(E){const T=E.bodies.find(O=>O.id===b.id),v={...E,bodies:E.bodies.map(O=>O.id===T.id?w:O)};return e.set(E.id,v),T.id!==w.id&&(t.delete(T.id),t.set(w.id,v.id)),{oldValue:E,newValue:v,bodiesUpdated:[{oldBody:T,newBody:w}]}}else console.warn(`Attempt to add body to missing annotation ${b.annotation}`)},D=(b,w,E=_.LOCAL)=>{const T=N(b,w);T&&s(E,{updated:[T]})},F=(b,w=_.LOCAL)=>{const E=b.map(T=>N({id:T.id,annotation:T.annotation},T)).filter(Boolean);s(w,{updated:E})},le=b=>{const w=e.get(b.annotation);if(w){const E={...w,target:{...w.target,...b}};return e.set(w.id,E),{oldValue:w,newValue:E,targetUpdated:{oldTarget:w.target,newTarget:b}}}else console.warn(`Attempt to update target on missing annotation: ${b.annotation}`)};return{addAnnotation:a,addBody:c,all:m,bulkAddAnnotations:p,bulkDeleteAnnotations:A,bulkDeleteBodies:R,bulkUpdateAnnotations:u,bulkUpdateBodies:F,bulkUpdateTargets:(b,w=_.LOCAL)=>{const E=b.map(T=>le(T)).filter(Boolean);E.length>0&&s(w,{updated:E})},bulkUpsertAnnotations:g,clear:S,deleteAnnotation:Y,deleteBody:k,getAnnotation:B,getBody:M,observe:o,syncAnnotations:h,unobserve:i,updateAnnotation:d,updateBody:D,updateTarget:(b,w=_.LOCAL)=>{const E=le(b);E&&s(w,{updated:[E]})},upsertAnnotation:f}};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,s=!1,r=0;const a=c=>{if(!s){const{changes:m}=c,S=performance.now();if(S-r>Yn)o.splice(i+1),o.push(m),i=o.length-1;else{const h=o.length-1;o[h]=_n(o[h],m)}r=S}s=!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),f=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({oldValue:m})=>m)),u=c=>c&&c.length>0&&e.bulkUpdateAnnotations(c.map(({newValue:m})=>m)),y=c=>c&&c.length>0&&e.bulkUpsertAnnotations(c),g=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){s=!0;const{created:c,updated:m,deleted:S}=o[i+1];d(c),u(m),g(S),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:c,updated:m,deleted:S}=o[i];l(c),f(m),y(S),n.emit("undo",o[i]),i-=1}}}},Vn=()=>{const e=$e([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Xn=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:a}=e,l=new Map;let d=[],f;const u=(m,S)=>{l.has(m)?l.get(m).push(S):l.set(m,[S])},y=(m,S)=>{const h=l.get(m);if(h){const p=h.indexOf(S);p!==-1&&h.splice(p,1)}},g=(m,S,h)=>{l.has(m)&&setTimeout(()=>{l.get(m).forEach(p=>{if(n){const x=Array.isArray(S)?S.map(A=>n.serialize(A)):n.serialize(S),Y=h?h instanceof PointerEvent?h:n.serialize(h):void 0;p(x,Y)}else p(S,h)})},1)};s.subscribe(({selected:m})=>{if(!(d.length===0&&m.length===0)){if(d.length===0&&m.length>0)d=m.map(({id:S})=>r.getAnnotation(S));else if(d.length>0&&m.length===0)d.forEach(S=>{const h=r.getAnnotation(S.id);h&&!ae(h,S)&&g("updateAnnotation",h,S)}),d=[];else{const S=new Set(d.map(p=>p.id)),h=new Set(m.map(({id:p})=>p));d.filter(p=>!h.has(p.id)).forEach(p=>{const x=r.getAnnotation(p.id);x&&!ae(x,p)&&g("updateAnnotation",x,p)}),d=[...d.filter(p=>h.has(p.id)),...m.filter(({id:p})=>!S.has(p)).map(({id:p})=>r.getAnnotation(p))]}g("selectionChanged",d)}}),i.subscribe(m=>{!f&&m?g("mouseEnterAnnotation",r.getAnnotation(m)):f&&!m?g("mouseLeaveAnnotation",r.getAnnotation(f)):f&&m&&(g("mouseLeaveAnnotation",r.getAnnotation(f)),g("mouseEnterAnnotation",r.getAnnotation(m))),f=m}),a?.subscribe(m=>g("viewportIntersect",m.map(S=>r.getAnnotation(S)))),r.observe(m=>{const{created:S,deleted:h}=m.changes;(S||[]).forEach(p=>g("createAnnotation",p)),(h||[]).forEach(p=>g("deleteAnnotation",p)),(m.changes.updated||[]).filter(p=>[...p.bodiesCreated||[],...p.bodiesDeleted||[],...p.bodiesUpdated||[]].length>0).forEach(({oldValue:p,newValue:x})=>{const Y=d.find(A=>A.id===p.id)||p;d=d.map(A=>A.id===p.id?x:A),g("updateAnnotation",x,Y)})},{origin:_.LOCAL}),r.observe(m=>{if(d){const S=new Set(d.map(p=>p.id)),h=(m.changes.updated||[]).filter(({newValue:p})=>S.has(p.id)).map(({newValue:p})=>p);h.length>0&&(d=d.map(p=>h.find(Y=>Y.id===p.id)||p))}},{origin:_.REMOTE});const c=m=>S=>{const{updated:h}=S;m?(h||[]).forEach(p=>g("updateAnnotation",p.oldValue,p.newValue)):(h||[]).forEach(p=>g("updateAnnotation",p.newValue,p.oldValue))};return t.on("undo",c(!0)),t.on("redo",c(!1)),{on:u,off:y,emit:g}},Pn=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=h=>{if(n){const{parsed:p,error:x}=n.parse(h);p?o.addAnnotation(p,_.REMOTE):console.error(x)}else o.addAnnotation(Fe(h),_.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=h=>{const p=o.getAnnotation(h);return n&&p?n.serialize(p):p},d=()=>n?o.all().map(n.serialize):o.all(),f=()=>{var h;const p=(((h=i.selected)==null?void 0:h.map(x=>x.id))||[]).map(x=>o.getAnnotation(x)).filter(Boolean);return n?p.map(n.serialize):p},u=(h,p=!0)=>fetch(h).then(x=>x.json()).then(x=>(g(x,p),x)),y=h=>{if(typeof h=="string"){const p=o.getAnnotation(h);if(o.deleteAnnotation(h),p)return n?n.serialize(p):p}else{const p=n?n.parse(h).parsed:h;if(p)return o.deleteAnnotation(p),h}},g=(h,p=!0)=>{const x=p?o.syncAnnotations:o.bulkUpsertAnnotations;if(n){const Y=n.parseAll||Pn(n),{parsed:A,failed:C}=Y(h);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),x(A,_.REMOTE)}else x(h.map(Fe),_.REMOTE)},c=(h,p)=>{h?i.setSelected(h,p):i.clear()},m=h=>{i.setUserSelectAction(h)},S=h=>{if(n){const p=n.parse(h).parsed,x=n.serialize(o.getAnnotation(p.id));return o.updateAnnotation(p),x}else{const p=o.getAnnotation(h.id);return o.updateAnnotation(Fe(h)),p}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:d,getHistory:t.getHistory,getSelected:f,loadAnnotations:u,redo:t.redo,removeAnnotation:y,setAnnotations:g,setSelected:c,setUserSelectAction:m,undo:t.undo,updateAnnotation:S}};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}`},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:s,value:r,created:a,modified:l,creator:d,...f}=n;return{id:o||`temp-${Gn(n)}`,annotation:t,type:i,purpose:s,value:r,creator:vt(d),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...f}}),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});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: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:vt(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 f=(Array.isArray(l.selector)?l.selector:[l.selector]).reduce((u,y)=>{switch(y.type){case"TextQuoteSelector":u.quote=y.exact;break;case"TextPositionSelector":u.start=y.start,u.end=y.end;break}return u},{});if(eo(f))a.selector.push({...f,id:l.id,scope:l.scope});else{const u=[f.start?void 0:"TextPositionSelector",f.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${u.join(" and ")} for annotation: ${e.id}`)}}}return{parsed:a}},St=e=>{const t=e.id||rt(),{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}}},Ct=(e,t,n)=>{const{bodies:o,target:i,...s}=e,{selector:r,creator:a,created:l,updated:d,...f}=i,u=r.map(y=>{const{id:g,quote:c}=y,m={type:"TextQuoteSelector",exact:c};if(n&&"range"in y){const{prefix:x,suffix:Y}=ht(y.range,n);m.prefix=x,m.suffix=Y}if(!("start"in y))throw new Error("W3C serialization requires TextSelector with start/end");const{start:S,end:h}=y,p={type:"TextPositionSelector",start:S,end:h};return{...f,id:g,scope:"scope"in y?y.scope:void 0,source:t,selector:[m,p]}});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:u}};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(re)&&!t.target.closest("a")&&t.preventDefault()}),Me=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}),ye=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)})},ze=(e,t,n,o)=>{const{store:i,selection:s,hover:r}=n,a=Tt();let l;const d=new Map;let f;const u=Ft(o),y=M=>{const{x:N,y:D}=t.getBoundingClientRect(),F=i.getAt(M.clientX-N,M.clientY-D,!1,f);F&&n.selection.evalSelectAction(F)!==He.NONE?r.current!==F.id&&(t.classList.add("hovered"),r.set(F.id)):r.current&&(t.classList.remove("hovered"),r.set(null))};t.addEventListener("pointermove",y);const g=Ne((M=!1)=>requestAnimationFrame(()=>{const N=jt(t),{minX:D,minY:F,maxX:le,maxY:b}=N,w=f?i.getIntersecting(D,F,le,b).filter(({annotation:v})=>f?.(v)):i.getIntersecting(D,F,le,b),E=s.selected.map(({id:v})=>v),T=w.map(({annotation:v,rects:O})=>{const K=E.includes(v.id),H=v.id===r.current;return{annotation:v,rects:O,state:{selected:K,hovered:H}}});e.redraw(T,N,l,d,M),setTimeout(()=>{u(w.map(({annotation:v})=>v)),a.emit("onRedraw")},1)}),10),c=(M,N)=>{N?M?d.set(N,M):d.delete(N):l=M,g(!0)},m=M=>{f=M,g(!1)},S=(M,N)=>a.on(M,N),h=()=>{g()};i.observe(h);const p=s.subscribe(()=>{g()}),x=r.subscribe(()=>{g()}),Y=()=>{g(!0)};document.addEventListener("scroll",Y,{capture:!0,passive:!0});const A=Ne(()=>{i.recalculatePositions(),g()},10);window.addEventListener("resize",A);const C=new ResizeObserver(A);C.observe(t);const k={attributes:!0,childList:!0,subtree:!0},R=new MutationObserver(Ne(M=>{M.every(D=>D.target===t||t.contains(D.target))||g(!0)},150));return R.observe(document.body,k),{destroy:()=>{t.removeEventListener("pointermove",y),e.destroy(),i.unobserve(h),p(),x(),document.removeEventListener("scroll",Y),window.removeEventListener("resize",A),C.disconnect(),R.disconnect()},on:S,redraw:g,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)}},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,Be=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,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}},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 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}},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},be=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,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,_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=ro.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)||so.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,s=i===void 0?1:i;return ee(t)&&ee(n)&&ee(o)?Rt({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=Mt({h:Number(t),s:Number(n),l:Number(o),a:Number(s)});return Bt(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: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(s)});return kt(r)},"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]},Ge=function(e,t){var n=be(e);return{h:n.h,s:W(n.s+100*t,0,100),l:n.l,a:n.a}},Qe=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},Dt=function(e,t){var n=be(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(Qe(this.rgba),2)},e.prototype.isDark=function(){return Qe(this.rgba)<.5},e.prototype.isLight=function(){return Qe(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?Be(X(255*s)):"","#"+Be(n)+Be(o)+Be(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(be(this.rgba))},e.prototype.toHslString=function(){return t=Nt(be(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=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(Ge(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),z(Ge(this.rgba,-t))},e.prototype.grayscale=function(){return z(Ge(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=be(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},_e={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(),Je=(e,t,n)=>t?typeof t=="function"?t(e.annotation,e.state,n)||(e.state?.selected?_e:te):t:e.state?.selected?_e:te;var Kt=Object.prototype.hasOwnProperty;function Ze(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--&&Ze(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)||!Ze(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Vt=(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 f=e.startContainer.childNodes[e.startOffset];f?a.setStartBefore(f):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 f=e.endContainer.childNodes[e.endOffset];f?l.setEndBefore(f):l.setEndAfter(e.endContainer)}const d=f=>{const u=document.createRange();return u.selectNode(f),Array.from(u.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)},Pt=(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)}}),$t=(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,f)=>{if(!(!Ze(n,r)||f))return;t.innerHTML="",[...r].sort((c,m)=>{const{annotation:{target:{created:S}}}=c,{annotation:{target:{created:h}}}=m;return S&&h?S.getTime()-h.getTime():0}).forEach(c=>{const m=d?.get(c.annotation.id)||l;c.rects.map(S=>{const h=Vt(S,r),p=Je(c,m,h),x=document.createElement("span");x.className="r6o-annotation",x.dataset.annotation=c.annotation.id,x.style.left=`${S.x}px`,x.style.top=`${S.y}px`,x.style.width=`${S.width}px`,x.style.height=`${S.height}px`,x.style.backgroundColor=Yt(p),p.underlineStyle&&(x.style.borderStyle=p.underlineStyle),p.underlineColor&&(x.style.borderColor=p.underlineColor),p.underlineThickness&&(x.style.borderBottomWidth=`${p.underlineThickness}px`),p.underlineOffset&&(x.style.paddingBottom=`${p.underlineOffset}px`),t.appendChild(x)})}),n=r},setVisible:r=>{r?t.classList.remove("hidden"):t.classList.add("hidden")}}},Ht=(e,t,n)=>ze(go(e),e,t,n),jt=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}},Ft=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 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,f=Math.log(l),u=.5*Math.exp(2*f/3),y=.5*Math.sqrt(f*u*(l-u)/l)*(d-l/2<0?-1:1),g=Math.max(n,Math.floor(t-d*u/l+y)),c=Math.min(o,Math.floor(t+(l-d)*u/l+y));Wt(e,t,g,c,i)}const s=e[t];let r=n,a=o;for(Ae(e,n,t),i(e[o],s)>0&&Ae(e,n,o);r<a;){for(Ae(e,r,a),r++,a--;i(e[r],s)<0;)r++;for(;i(e[a],s)>0;)a--}i(e[n],s)===0?Ae(e,n,a):(a++,Ae(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function Ae(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):tt(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||tt(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=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 f=yo(t,o.children,n);if(f!==-1)return o.children.splice(f,1),s.push(o),this._condense(s),this}!d&&!o.leaf&&tt(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));zt(t,n,o,d,this.compareMinX);for(let f=n;f<=o;f+=d){const u=Math.min(f+d-1,o);zt(t,f,u,l,this.compareMinY);for(let y=f;y<=u;y+=l){const g=Math.min(y+l-1,u);a.children.push(this._build(t,y,g,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],f=et(d),u=wo(t,d)-f;u<r?(r=u,s=f<s?f:s,a=d):u===r&&f<s&&(s=f,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),Ee(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=we(t,0,a,this.toBBox),d=we(t,a,o,this.toBBox),f=Eo(l,d),u=et(l)+et(d);f<s?(s=f,i=a,r=u<r?u:r):f===s&&u<r&&(r=u,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=we(t,0,n,s),a=we(t,o-n,o,s);let l=Ie(r)+Ie(a);for(let d=n;d<o-n;d++){const f=t.children[d];Ee(r,t.leaf?s(f):f),l+=Ie(r)}for(let d=o-n-1;d>=n;d--){const f=t.children[d];Ee(a,t.leaf?s(f):f),l+=Ie(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)Ee(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){we(e,0,e.children.length,t,e)}function we(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];Ee(i,e.leaf?o(r):r)}return i}function Ee(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 et(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ie(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 tt(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 zt(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;Wt(e,r,t,n,i),s.push(t,r,r,n)}}const vo=(e,t,n,o)=>{const i=new mo,s=new Map,r=Tt(),a=(A,C)=>{const k=A.selector.flatMap(B=>Xt(B.range)),R=Pt(k,n,o).map(B=>$t(B,C));return R.map(B=>{const{x:M,y:N,width:D,height:F}=B;return{minX:M,minY:N,maxX:M+D,maxY:N+F,annotation:{id:A.annotation,rects:R}}})},l=()=>[...s.values()],d=()=>{i.clear(),s.clear()},f=A=>{const C=a(A,t.getBoundingClientRect());C.length!==0&&(C.forEach(k=>i.insert(k)),s.set(A.annotation,C))},u=A=>{const C=s.get(A.annotation);C&&(C.forEach(k=>i.remove(k)),s.delete(A.annotation))},y=A=>{u(A),f(A)},g=(A,C=!0)=>{C&&d();const k=t.getBoundingClientRect(),R=A.map(M=>({target:M,rects:a(M,k)}));R.forEach(({target:M,rects:N})=>{N.length>0&&s.set(M.annotation,N)});const B=R.flatMap(({rects:M})=>M);i.load(B)},c=(A,C,k=!1)=>{const R=i.search({minX:A,minY:C,maxX:A,maxY:C}),B=M=>M.annotation.rects.reduce((N,D)=>N+D.width*D.height,0);return R.length>0?(R.sort((M,N)=>B(M)-B(N)),k?R.map(M=>M.annotation.id):[R[0].annotation.id]):[]},m=A=>{const C=S(A);if(C.length===0)return;let k=C[0].left,R=C[0].top,B=C[0].right,M=C[0].bottom;for(let N=1;N<C.length;N++){const D=C[N];k=Math.min(k,D.left),R=Math.min(R,D.top),B=Math.max(B,D.right),M=Math.max(M,D.bottom)}return new DOMRect(k,R,B-k,M-R)},S=A=>{const C=s.get(A);return C?C[0].annotation.rects:[]};return{all:l,clear:d,getAt:c,getAnnotationBounds:m,getAnnotationRects:S,getIntersecting:(A,C,k,R)=>{const B=i.search({minX:A,minY:C,maxX:k,maxY:R}),M=new Set(B.map(N=>N.annotation.id));return Array.from(M).map(N=>({annotation:e.getAnnotation(N),rects:S(N)})).filter(N=>!!N.annotation)},insert:f,recalculate:()=>{g(e.all().map(A=>A.target),!0),r.emit("recalculate")},remove:u,set:g,size:()=>i.all().length,update:y,on:(A,C)=>r.on(A,C)}},qt=(e,t)=>{const n=Dn(),o=vo(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance),i=vn(n,t.userSelectAction,t.adapter),s=En(n),r=Vn(),a=A=>{const C=A.map(R=>me(R,e,t.selectorReviveFn)),k=C.filter(R=>!Z(R.target.selector));return{revived:C,couldNotRevive:k}},l=(A,C=_.LOCAL)=>{const k=me(A,e,t.selectorReviveFn),R=Z(k.target.selector);return R&&n.addAnnotation(k,C),R},d=(A,C=_.LOCAL)=>{const{revived:k,couldNotRevive:R}=a(A);return n.syncAnnotations(k,C),R},f=(A,C=!0,k=_.LOCAL)=>C?d(A,k):y(A,k),u=(A,C,k)=>{if(typeof A=="string"){const R=me(C,e,t.selectorReviveFn);n.updateAnnotation(A,R,k)}else{const R=me(A,e,t.selectorReviveFn);n.updateAnnotation(R,C)}},y=(A,C=_.LOCAL)=>{const{revived:k,couldNotRevive:R}=a(A);return n.bulkUpsertAnnotations(k,C),R},g=(A,C=_.LOCAL)=>{const k=pe(A,e,t.selectorReviveFn);n.updateTarget(k,C)},c=(A,C=_.LOCAL)=>{const k=A.map(R=>pe(R,e,t.selectorReviveFn));n.bulkUpdateTargets(k,C)};function m(A,C,k,R){const B=k||!!R,M=o.getAt(A,C,B).map(D=>n.getAnnotation(D)).filter(Boolean),N=R?M.filter(R):M;if(N.length!==0)return k?N:N[0]}const S=A=>o.getAnnotationRects(A).length>0?o.getAnnotationBounds(A):void 0,h=(A,C,k,R)=>o.getIntersecting(A,C,k,R),p=A=>o.getAnnotationRects(A),x=()=>o.recalculate(),Y=A=>o.on("recalculate",A);return n.observe(({changes:A})=>{const C=(A.deleted||[]).filter(B=>Z(B.target.selector)),k=(A.created||[]).filter(B=>Z(B.target.selector)),R=(A.updated||[]).filter(B=>Z(B.newValue.target.selector));C?.length>0&&C.forEach(B=>o.remove(B.target)),k.length>0&&o.set(k.map(B=>B.target),!1),R?.length>0&&R.forEach(({newValue:B})=>o.update(B.target))}),{store:{...n,addAnnotation:l,bulkAddAnnotations:f,bulkUpdateTargets:c,bulkUpsertAnnotations:y,getAnnotationBounds:S,getAnnotationRects:p,getIntersecting:h,getAt:m,recalculatePositions:x,onRecalculatePositions:Y,syncAnnotations:d,updateAnnotation:u,updateTarget:g},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 y=i,g=s;return i=void 0,s=void 0,l=e.apply(y,g),l}function f(){const y=Date.now()-a;y<t&&y>=0?r=setTimeout(f,t-y):(r=void 0,o||(l=d()))}const u=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,s=y,a=Date.now();const g=o&&!r;if(r||(r=setTimeout(f,t)),g)return l=d(),l};return Object.defineProperty(u,"isPending",{get(){return r!==void 0}}),u.clear=()=>{r&&(clearTimeout(r),r=void 0,i=void 0,s=void 0)},u.flush=()=>{r&&u.trigger()},u.trigger=()=>{l=d(),u.clear()},u}const nt=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function ot(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent(`on${t}`,n)}function ve(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 s=0;s<n.length;s++)o.indexOf(n[s])===-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 Se={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,"-":nt?173:189,"=":nt?61:187,";":nt?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},Ce={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},U={};for(let e=1;e<20;e++)Se[`f${e}`]=111+e;let I=[],Te=null,ue=null,Zt="all";const ne=new Map,fe=e=>Se[e.toLowerCase()]||q[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),To=e=>Object.keys(Se).find(t=>Se[t]===e),xo=e=>Object.keys(q).find(t=>q[t]===e),en=e=>{Zt=e||"all"},xe=()=>Zt||"all",Lo=()=>I.slice(0),Ro=()=>I.map(e=>To(e)||xo(e)||String.fromCharCode(e)),Oo=()=>{const e=[];return Object.keys(U).forEach(t=>{U[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},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)),I.indexOf(e)!==-1),Mo=(e,t)=>{let n,o;e||(e=xe());for(const i in U)if(Object.prototype.hasOwnProperty.call(U,i))for(n=U[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(({element:r})=>it(r)):o++;xe()===e&&en(t||"all")};function No(e){let t=Jt(e);e.key&&e.key.toLowerCase()==="capslock"&&(t=fe(e.key));const n=I.indexOf(t);if(n>=0&&I.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&I.splice(0,I.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(U).forEach(n=>{Array.isArray(U[n])&&U[n].forEach(o=>Ue(o)),delete U[n]}),it(null);else if(Array.isArray(e))e.forEach(n=>{n.key&&Ue(n)});else if(typeof e=="object")e.key&&Ue(e);else if(typeof e=="string"){let[n,o]=t;typeof n=="function"&&(o=n,n=""),Ue({key:e,scope:n,method:o,splitKey:"+"})}},Ue=({key:e,scope:t,method:n,splitKey:o="+"})=>{Qt(e).forEach(s=>{const r=s.split(o),a=r.length,l=r[a-1],d=l==="*"?"*":fe(l);if(!U[d])return;t||(t=xe());const f=a>1?Gt(q,r):[],u=[];U[d]=U[d].filter(y=>{const c=(n?y.method===n:!0)&&y.scope===t&&Co(y.mods,f);return c&&u.push(y.element),!c}),u.forEach(y=>it(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 s in V)Object.prototype.hasOwnProperty.call(V,s)&&(!V[s]&&t.mods.indexOf(+s)>-1||V[s]&&t.mods.indexOf(+s)===-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(I),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function sn(e,t){const n=U["*"];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),I.indexOf(o)===-1&&o!==229&&I.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(l=>{const d=Ce[l];e[l]&&I.indexOf(d)===-1?I.push(d):!e[l]&&I.indexOf(d)>-1?I.splice(I.indexOf(d),1):l==="metaKey"&&e[l]&&(I=I.filter(f=>f in Ce||f===o))}),o in V){V[o]=!0;for(const l in q)if(Object.prototype.hasOwnProperty.call(q,l)){const d=Ce[q[l]];G[l]=e[d]}if(!n)return}for(const l in V)Object.prototype.hasOwnProperty.call(V,l)&&(V[l]=e[Ce[l]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(I.indexOf(17)===-1&&I.push(17),I.indexOf(18)===-1&&I.push(18),V[17]=!0,V[18]=!0);const s=xe();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)&&on(e,n[l],s,t);if(!(o in U))return;const r=U[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:f}=d,u=d.key.split(f),y=[];for(let g=0;g<u.length;g++)y.push(fe(u[g]));y.sort().join("")===I.sort().join("")&&on(e,d,s,t)}}const G=function e(t,n,o){I=[];const i=Qt(t);let s=[],r="all",a=document,l=0,d=!1,f=!0,u="+",y=!1,g=!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&&(f=c.keydown),c.capture!==void 0&&(y=c.capture),typeof c.splitKey=="string"&&(u=c.splitKey),c.single===!0&&(g=!0)}for(typeof n=="string"&&(r=n),g&&nn(t,r);l<i.length;l++){const c=i[l].split(u);s=[],c.length>1&&(s=Gt(q,c));let m=c[c.length-1];m=m==="*"?"*":fe(m),m in U||(U[m]=[]),U[m].push({keyup:d,keydown:f,scope:r,mods:s,shortcut:i[l],method:o,key:i[l],splitKey:u,element:a})}if(typeof a<"u"&&typeof window<"u"){if(!ne.has(a)){const c=(S=window.event)=>sn(S,a),m=(S=window.event)=>{sn(S,a),No(S)};ne.set(a,{keydownListener:c,keyupListenr:m,capture:y}),ot(a,"keydown",c,y),ot(a,"keyup",m,y)}if(!Te){const c=()=>{I=[]};Te={listener:c,capture:y},ot(window,"focus",c,y)}if(!ue&&typeof document<"u"){const c=()=>{I=[];for(const h in V)V[h]=!1;for(const h in q)e[h]=!1},m=c,S=c;document.addEventListener("fullscreenchange",m),document.addEventListener("webkitfullscreenchange",S),ue={fullscreen:m,webkit:S}}}};function Bo(e,t="all"){Object.keys(U).forEach(n=>{U[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method({},i)})})}function it(e){const t=Object.values(U).flat();if(t.findIndex(({element:o})=>o===e)<0&&e){const{keydownListener:o,keyupListenr:i,capture:s}=ne.get(e)||{};o&&i&&(ve(e,"keyup",i,s),ve(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&&(ve(i,"keyup",r,a),ve(i,"keydown",s,a),ne.delete(i))}),ne.clear(),Object.keys(U).forEach(i=>delete U[i]),Te){const{listener:i,capture:s}=Te;ve(window,"focus",i,s),Te=null}ue&&typeof document<"u"&&(document.removeEventListener("fullscreenchange",ue.fullscreen),document.removeEventListener("webkitfullscreenchange",ue.webkit),ue=null)}}const st={getPressedKeyString:Ro,setScope:en,getScope:xe,deleteScope:Mo,getPressedKeyCodes:Lo,getAllKeyCodes:Oo,isPressed:ko,filter:tn,trigger:Bo,unbind:nn,keyMap:Se,modifier:q,modifierMap:Ce};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 rn=300,an=["up","down","left","right"],ln=Ke?"⌘+a":"ctrl+a",Io=[...an.map(e=>`shift+${e}`),ln],cn=(e,t,n,o)=>{const{store:i,selection:s}=t;let r;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:d,dismissOnNotAnnotatable:f="NEVER"}=o;let u,y=a,g="CREATE_NEW",c,m,S,h;const p=v=>{y=v,R.clear(),v||(m=void 0,c=void 0,S=void 0,h=void 0)},x=v=>g=v||"CREATE_NEW",Y=v=>u=v,A=v=>r=v,C=v=>{if(g==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const O=v;return Ke?O.metaKey:O.ctrlKey}else return!1},k=()=>{if(!y||S===!1)return;const{selected:v}=s;if((C(h)||g==="REPLACE_CURRENT")&&v.length===1&&v[0].editable){const K=i.getAnnotation(v[0].id);if(K?.target){m=K.target,c={annotation:K.id,selector:[],created:m.created,creator:m.creator,updated:new Date,updatedBy:r};return}}m=void 0,c={annotation:rt(),selector:[],created:new Date,creator:r}},R=So(v=>{if(!y)return;const O=document.getSelection();if(!O?.anchorNode)return;const H=E().map(j=>ut(j,e));if(H.every(j=>!Xe(e,j))){c=void 0;return}const ie=v.timeStamp-(h?.timeStamp||v.timeStamp);if(h?.type==="pointerdown"&&(ie<1e3&&!c||O.isCollapsed&&ie<rn)&&k(),!c&&(k(),!c))return;if(O.isCollapsed){i.getAnnotation(c.annotation)&&!(C(h)||g==="REPLACE_CURRENT")&&(s.clear(),i.deleteAnnotation(c.annotation));return}if(H.every(j=>at(j)))return;const J=H.flatMap(j=>dt(e,j.cloneRange()));if(!(J.length>0&&!c||J.length!==c.selector.length||J.some((j,Le)=>j.toString()!==c?.selector[Le]?.quote)))return;const Ye=C(h)&&m?lt([...m.selector.map(j=>j.range),...J]):J;c={...c,selector:Ye.map(j=>gt(j,e,l)),updated:new Date},!(C(h)||g==="REPLACE_CURRENT")&&(i.getAnnotation(c.annotation)?i.updateTarget(c,_.LOCAL):s.clear())},10),B=v=>{h=Me(v),S=h.button===0},M=async v=>{if(!S)return;const O=Me(v),K=()=>{const{x:ie,y:J}=e.getBoundingClientRect();if(ge(e,O.target)){(typeof f=="function"?f(O,e):f==="ALWAYS")&&s.clear();return}const se=O.target instanceof Node&&e.contains(O.target)&&i.getAt(O.clientX-ie,O.clientY-J,d==="all",u);if(se){const{selected:Ye}=s,j=new Set(Ye.map(Re=>Re.id)),Le=Array.isArray(se)?se.map(Re=>Re.id):[se.id];(j.size!==Le.length||!Le.every(Re=>j.has(Re)))&&(n.emit("clickAnnotation",se),s.userSelect(Le,O))}else s.clear()};if(O.timeStamp-(h?.timeStamp||0)<rn){await N();const ie=document.getSelection(),J=ge(e,h?.target),se=ge(e,O.target);if(ie?.isCollapsed||J&&se){c=void 0,K();return}}c&&c.selector.length>0&&(T(),s.userSelect(c.annotation,O))},N=async()=>{const v=document.getSelection();let O=!1,K=v?.isCollapsed;const H=()=>K||O,ie=1;return setTimeout(()=>O=!0,50),_o(()=>K=v?.isCollapsed,ie,H)},D=v=>{document.getSelection()?.isCollapsed||((!c||c.selector.length===0)&&R(v),c&&(T(),s.userSelect(c.annotation,Me(v))))},F=v=>{if(y&&!v.repeat&&E().length!==0&&v.key==="Shift"&&c){const O=document.getSelection();O&&!O.isCollapsed&&(T(),s.userSelect(c.annotation,ye(v)))}},le=v=>{const O=()=>setTimeout(()=>{c&&(c.selector.length>0&&(s.clear(),i.addAnnotation({id:c.annotation,bodies:[],target:c}),s.userSelect(c.annotation,ye(v))),document.removeEventListener("selectionchange",O))},100);document.addEventListener("selectionchange",O),k()};G(Io.join(","),{element:e,keydown:!0,keyup:!1},v=>{v.repeat||(h=ye(v))}),G(ln,{keydown:!0,keyup:!1},v=>{h=ye(v),le(v)});const b=v=>{v.repeat||E().length!==0&&(c=void 0,s.clear())};G(an.join(","),{keydown:!0,keyup:!1},b),document.addEventListener("pointerdown",B),document.addEventListener("pointerup",M),document.addEventListener("contextmenu",D),document.addEventListener("keyup",F),e.addEventListener("selectstart",k),document.addEventListener("selectionchange",R);const w=()=>{c=void 0,m=void 0,S=void 0,h=void 0,R.clear(),document.removeEventListener("pointerdown",B),document.removeEventListener("pointerup",M),document.removeEventListener("contextmenu",D),document.removeEventListener("keyup",F),e.removeEventListener("selectstart",k),document.removeEventListener("selectionchange",R),G.unbind()},E=()=>{const v=document.getSelection();return v?Array.from(Array(v.rangeCount).keys()).map(O=>v.getRangeAt(O)).filter(O=>O.intersectsNode(e)):[]},T=()=>{if(!c)return;const v=i.getAnnotation(c.annotation);if(!v)i.addAnnotation({id:c.annotation,bodies:[],target:c});else{const{target:{updated:O}}=v,{updated:K}=c;(!O||!K||O<K)&&i.updateTarget(c)}};return{destroy:w,setFilter:Y,setUser:A,setAnnotatingEnabled:p,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:s=>{console.log("setVisible not implemented on CSS Custom Highlights renderer")},redraw:(s,r,a,l,d)=>{const f=new Set(s.map(y=>y.annotation.id));Array.from(t).filter(y=>!f.has(y));const u=s.map(y=>{a?typeof a=="function"&&a(y.annotation,y.state):y.state?.selected;const g=Je(y,a);return`::highlight(_${y.annotation.id}) { ${Do(g)} }`});e.innerHTML=u.join(`
2
+ `),CSS.highlights.clear(),s.forEach(({annotation:y})=>{const g=y.target.selector.map(m=>m.range),c=new Highlight(...g);CSS.highlights.set(`_${y.id}`,c)}),t=f}}},Yo=(e,t,n)=>ze(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),ct(e);const n=dn(t,{annotatingEnabled:!0,user:qn()}),o=qt(e,n),{selection:i,viewport:s}=o,r=o.store,a=Kn(r),l=Xn(o,a,n.adapter);let d=n.user;const f=typeof n.renderer!="function"?n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":un:n.renderer||un:null,u=f===null?n.renderer(e,o,s):f==="SPANS"?Ht(e,o,s):f==="CSS_HIGHLIGHTS"?Yo(e,o,s):void 0;if(!u)throw`Unknown renderer implementation: ${n.renderer}`;console.debug(f?`Using ${f} renderer`:"Using custom renderer implementation"),n.style&&u.setStyle(n.style);const y=cn(e,o,l,n);y.setUser(d);const g=$n(o,a,n.adapter),c=()=>d,m=A=>{y.setAnnotatingEnabled(A===void 0?!0:A)},S=A=>{y.setAnnotatingMode(A)},h=A=>{u.setFilter(A),y.setFilter(A)},p=A=>{d=A,y.setUser(A)},x=A=>{A?i.setSelected(A):i.clear()};return{...g,destroy:()=>{u.destroy(),y.destroy(),a.destroy()},element:e,getUser:c,renderer:u,setAnnotatingEnabled:m,setAnnotatingMode:S,setFilter:h,setStyle:u.setStyle.bind(u),setUser:p,setSelected:x,setVisible:u.setVisible.bind(u),on:l.on,off:l.off,scrollIntoView:bt(e,r),state:o}};L.DEFAULT_SELECTED_STYLE=_e,L.DEFAULT_STYLE=te,L.NOT_ANNOTATABLE_CLASS=Ve,L.NOT_ANNOTATABLE_SELECTOR=re,L.Origin=_,L.UserSelectAction=He,L.W3CTextFormat=Zn,L.cancelSingleClickEvents=xt,L.cloneKeyboardEvent=ye,L.clonePointerEvent=Me,L.computeStyle=Je,L.computeZIndex=Vt,L.createBody=Rn,L.createRenderer=ze,L.createSelectionHandler=cn,L.createSpansRenderer=Ht,L.createTextAnnotator=Ko,L.createTextAnnotatorState=qt,L.debounce=Ne,L.fillDefaults=dn,L.getBackgroundColor=Yt,L.getHighlightClientRects=Xt,L.getQuoteContext=ht,L.getRangeAnnotatableContents=Oe,L.getViewportBounds=jt,L.isMac=Ke,L.isNodeWhitespaceOrEmpty=yn,L.isNotAnnotatable=ge,L.isRangeAnnotatable=Xe,L.isRangeWhitespaceOrEmpty=at,L.isRevived=Z,L.isRevivedAnnotation=he,L.isRevivedTarget=fn,L.mergeClientRects=Pt,L.mergeRanges=lt,L.parseW3CTextAnnotation=St,L.programmaticallyFocusable=ct,L.rangeToSelector=gt,L.reviveAnnotation=me,L.reviveTarget=pe,L.reviveTextSelector=pt,L.scrollIntoView=bt,L.serializeW3CTextAnnotation=Ct,L.splitAnnotatableRanges=dt,L.toDomRectList=fo,L.toParentBounds=$t,L.toViewportBounds=ho,L.trackViewport=Ft,L.trimRangeToContainer=ut,L.whitespaceOrEmptyRegex=Pe,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
3
3
  //# sourceMappingURL=text-annotator.umd.js.map