@recogito/text-annotator 3.4.10 → 4.0.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -7
- package/dist/model/core/index.d.ts +1 -1
- package/dist/model/w3c/index.d.ts +2 -2
- package/dist/model/w3c/{W3CTextFormatAdapter.d.ts → w3c-text-format-adapter.d.ts} +2 -2
- package/dist/rendering/base-renderer.d.ts +31 -0
- package/dist/{highlight/HighlightStyle.d.ts → rendering/highlight-style.d.ts} +4 -1
- package/dist/{highlight/Highlight.d.ts → rendering/highlight.d.ts} +2 -1
- package/dist/rendering/index.d.ts +5 -0
- package/dist/rendering/renderer-css-highlight/css-highlight-renderer.d.ts +6 -0
- package/dist/rendering/renderer-css-highlight/index.d.ts +1 -0
- package/dist/rendering/renderer-inline-markup/index.d.ts +0 -0
- package/dist/rendering/renderer-spans/index.d.ts +1 -0
- package/dist/rendering/renderer-spans/spans-renderer.d.ts +3 -0
- package/dist/{SelectionHandler.d.ts → selection-handler.d.ts} +2 -2
- package/dist/state/index.d.ts +2 -2
- package/dist/state/{spatialTree.d.ts → spatial-tree.d.ts} +1 -1
- package/dist/state/{TextAnnotationStore.d.ts → text-annotation-store.d.ts} +1 -1
- package/dist/state/{TextAnnotatorState.d.ts → text-annotator-state.d.ts} +2 -2
- package/dist/{TextAnnotatorOptions.d.ts → text-annotator-options.d.ts} +2 -4
- package/dist/text-annotator.css +1 -1
- package/dist/{TextAnnotator.d.ts → text-annotator.d.ts} +6 -6
- package/dist/text-annotator.es.js +757 -841
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -2
- package/dist/text-annotator.umd.js.map +1 -1
- package/dist/utils/annotation/index.d.ts +4 -0
- package/dist/utils/{rangeToSelector.d.ts → annotation/range-to-selector.d.ts} +1 -1
- package/dist/utils/{reviveSelector.d.ts → annotation/revive-annotation.d.ts} +4 -1
- package/dist/{api/scrollIntoView.d.ts → utils/annotation/scroll-into-view.d.ts} +2 -2
- package/dist/utils/dom/index.d.ts +7 -0
- package/dist/utils/events/index.d.ts +3 -0
- package/dist/utils/highlight/compute-z-index.d.ts +3 -0
- package/dist/utils/highlight/index.d.ts +4 -0
- package/package.json +1 -1
- package/dist/api/index.d.ts +0 -1
- package/dist/highlight/HighlightPainter.d.ts +0 -11
- package/dist/highlight/Renderer.d.ts +0 -22
- package/dist/highlight/canvas/canvasRenderer.d.ts +0 -5
- package/dist/highlight/canvas/index.d.ts +0 -1
- package/dist/highlight/highlights/highlightsRenderer.d.ts +0 -6
- package/dist/highlight/highlights/index.d.ts +0 -1
- package/dist/highlight/index.d.ts +0 -8
- package/dist/highlight/span/color.d.ts +0 -2
- package/dist/highlight/span/index.d.ts +0 -2
- package/dist/highlight/span/spansRenderer.d.ts +0 -3
- package/dist/presence/PresencePainter.d.ts +0 -5
- package/dist/presence/PresencePainterOptions.d.ts +0 -3
- package/dist/presence/index.d.ts +0 -2
- package/dist/utils/index.d.ts +0 -19
- package/dist/utils/isRevived.d.ts +0 -2
- package/dist/utils/reviveAnnotation.d.ts +0 -2
- package/dist/utils/reviveTarget.d.ts +0 -2
- /package/dist/model/core/{TextAnnotation.d.ts → text-annotation.d.ts} +0 -0
- /package/dist/model/w3c/{W3CTextAnnotation.d.ts → w3c-text-annotation.d.ts} +0 -0
- /package/dist/{highlight → rendering}/viewport.d.ts +0 -0
- /package/dist/utils/{getQuoteContext.d.ts → annotation/get-quote-context.d.ts} +0 -0
- /package/dist/utils/{device.d.ts → dom/device.d.ts} +0 -0
- /package/dist/utils/{isNotAnnotatable.d.ts → dom/is-not-annotatable.d.ts} +0 -0
- /package/dist/utils/{isWhitespaceOrEmpty.d.ts → dom/is-whitespace-or-empty.d.ts} +0 -0
- /package/dist/utils/{mergeRanges.d.ts → dom/merge-ranges.d.ts} +0 -0
- /package/dist/utils/{programmaticallyFocusable.d.ts → dom/programmatically-focusable.d.ts} +0 -0
- /package/dist/utils/{splitAnnotatableRanges.d.ts → dom/split-annotatable-ranges.d.ts} +0 -0
- /package/dist/utils/{trimRangeToContainer.d.ts → dom/trim-range-to-container.d.ts} +0 -0
- /package/dist/utils/{cancelSingleClickEvents.d.ts → events/cancel-single-click-events.d.ts} +0 -0
- /package/dist/utils/{cloneEvents.d.ts → events/clone-events.d.ts} +0 -0
- /package/dist/utils/{debounce.d.ts → events/debounce.d.ts} +0 -0
- /package/dist/utils/{getHighlightClientRects.d.ts → highlight/get-highlight-client-rects.d.ts} +0 -0
- /package/dist/utils/{mergeClientRects.d.ts → highlight/merge-client-rects.d.ts} +0 -0
- /package/dist/utils/{rectsToBounds.d.ts → highlight/rects-to-bounds.d.ts} +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(L,se){typeof exports=="object"&&typeof module<"u"?se(exports):typeof define=="function"&&define.amd?define(["exports"],se):(L=typeof globalThis<"u"?globalThis:L||self,se(L.RecogitoJS={}))})(this,(function(L){"use strict";const se="not-annotatable",re=`.${se}`,ae=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(re):t.parentElement?.closest(re)):!0,Ye=(e,t)=>{const n=t.commonAncestorContainer;return!ae(e,n)},ot=e=>e.addEventListener("click",t=>{!t.target.closest(re)&&!t.target.closest("a")&&t.preventDefault()}),Le=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}),he=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}),Re=(e,t=10)=>{let n;return((...o)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,o),t)})},Pe=typeof navigator<"u"&&navigator.platform.startsWith("Mac"),it=e=>{(!e.hasAttribute("tabindex")||e.tabIndex<-1)&&e.setAttribute("tabindex","-1"),e.classList.add("no-focus-outline")},st=e=>{const t=[],n=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_TEXT);let o;for(;o=n.nextNode();)e.intersectsNode(o)&&t.push(o);if(t.length<2)return Array.from(e.getClientRects());{const i=t[0],s=t[t.length-1],r=document.createRange();if(r.selectNode(i),e.startContainer.nodeType===Node.TEXT_NODE)r.setStart(i,e.startOffset);else{const c=e.startContainer.childNodes[e.startOffset];c?r.setStartBefore(c):r.setStartAfter(e.startContainer)}const a=document.createRange();if(a.selectNode(s),e.endContainer.nodeType===Node.TEXT_NODE)a.setEnd(s,e.endOffset);else{const c=e.endContainer.childNodes[e.endOffset];c?a.setEndBefore(c):a.setEndAfter(e.endContainer)}const l=c=>{const f=document.createRange();return f.selectNode(c),Array.from(f.getClientRects())};return[...Array.from(r.getClientRects()),...t.slice(1,-1).flatMap(l),...Array.from(a.getClientRects())]}},dn=function*(e){const t=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(se)&&!o.parentElement.closest(re)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},rt=(e,t)=>{if(!Ye(e,t))return[];const n=[];let o=null;for(const i of dn(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},at=new Intl.Segmenter(void 0,{granularity:"grapheme"}),lt=(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,c=[...at.segment(r)],f=[...at.segment(l)];return{prefix:c.slice(-n).map(u=>u.segment).join(""),suffix:f.slice(0,n).map(u=>u.segment).join("")}},Q=e=>e.every(t=>t.range instanceof Range&&!t.range.collapsed),Ke=/^\s*$/,ct=e=>Ke.test(e.toString()),un=e=>Ke.test(e.textContent||""),fn=(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"},hn=(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)},dt=(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=fn(i,a,t,n);if(l==="inline-adjacent"){s=s.map(c=>c===a?hn(i,a):c),r=!0;break}else if(l==="inline-contains"){s=s.map(c=>c===a?i:c),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(c=>c===a?i:c)),i.width===a.width&&i.height<a.width&&(s=s.map(c=>c===a?i:c)),r=!0;break}}return r?s:[...s,i]},[]),gn=e=>({length:e.length,item:t=>e[t],[Symbol.iterator]:function*(){for(let t=0;t<this.length;t++)yield this.item(t)}}),ut=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]},ft=(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}},ht=(e,t)=>{const{left:n,top:o,right:i,bottom:s}=e;return new DOMRect(n-t.left,o-t.top,i-n,s-o)},pn=(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)},Xe=(e,t)=>{const{start:n,end:o}=e,i=e.offsetReference||t,s=document.createNodeIterator(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 c=!i;for(;l!==null;){if(c||=typeof i?.contains=="function"?i.contains(l):!1,c){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}},ge=(e,t)=>Q(e.selector)?e:{...e,selector:e.selector.map(n=>n.range instanceof Range&&!n.range.collapsed?n:Xe(n,t))},Be=(e,t)=>Q(e.target.selector)?e:{...e,target:ge(e.target,t)},gt=(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},pt=e=>{if(!e)return document.scrollingElement;const{overflowY:t}=window.getComputedStyle(e);return t!=="visible"&&t!=="hidden"&&e.scrollHeight>e.clientHeight?e:pt(e.parentElement)},mt=(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),c=r.top-o.top,f=r.left-o.left,u=n.parentElement?n.scrollTop:0,b=n.parentElement?n.scrollLeft:0,p=c+u-(i-l)/2,g=f+b-(s-a)/2;n.scroll({top:p,left:g,behavior:"smooth"})},yt=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,s=o?typeof o=="string"?document.getElementById(o):o:pt(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 mt(t,r.target,s),!0;const l=ge(r.target,e),{range:c}=l.selector[0];return c&&!c.collapsed?(mt(t,l,s),!0):!1};function bt(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 c(){const b=i,p=s;return i=void 0,s=void 0,l=e.apply(b,p),l}function f(){const b=Date.now()-a;b<t&&b>=0?r=setTimeout(f,t-b):(r=void 0,o||(l=c()))}const u=function(...b){if(i&&this!==i&&Object.getPrototypeOf(this)===Object.getPrototypeOf(i))throw new Error("Debounced method called with different contexts of the same prototype.");i=this,s=b,a=Date.now();const p=o&&!r;if(r||(r=setTimeout(f,t)),p)return l=c(),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=c(),u.clear()},u}const J={fill:"rgb(0, 128, 255)",fillOpacity:.18},pe={fill:"rgb(0, 128, 255)",fillOpacity:.45};var wt=Object.prototype.hasOwnProperty;function le(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&le(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(wt.call(e,n)&&++o&&!wt.call(t,n)||!(n in t)||!le(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const mn=Symbol("clean");let q=[],ne=0;const Me=4,yn=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),He=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(o){return n.lc=t.push(o),()=>{for(let s=ne+Me;s<q.length;)q[s]===o?q.splice(s,Me):s+=Me;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){yn.epoch++;let s=!q.length;for(let r of t)q.push(r,n.value,o,i);if(s){for(ne=0;ne<q.length;ne+=Me)q[ne](q[ne+1],q[ne+2],q[ne+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[mn]=()=>{t=[],n.lc=0,n.off()}),n},bn=e=>{const t=He(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 $e=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))($e||{});const je={selected:[]},wn=(e,t,n)=>{const o=He(je);let i=t;const s=()=>{le(o.get(),je)||o.set(je)},r=()=>{var p;return((p=o.get().selected)==null?void 0:p.length)===0},a=p=>{if(r())return!1;const g=typeof p=="string"?p:p.id;return o.get().selected.some(m=>m.id===g)},l=(p,g)=>{let m;if(Array.isArray(p)){if(m=p.map(h=>e.getAnnotation(h)).filter(Boolean),m.length<p.length){console.warn("Invalid selection: "+p.filter(h=>!m.some(d=>d.id===h)));return}}else{const h=e.getAnnotation(p);if(!h){console.warn("Invalid selection: "+p);return}m=[h]}const S=m.reduce((h,d)=>{const x=b(d);return x==="EDIT"?[...h,{id:d.id,editable:!0}]:x==="SELECT"?[...h,{id:d.id}]:h},[]);o.set({selected:S,event:g})},c=(p,g)=>{const m=Array.isArray(p)?p:[p],S=m.map(h=>e.getAnnotation(h)).filter(h=>!!h);o.set({selected:S.map(h=>{const d=g===void 0?b(h)==="EDIT":g;return{id:h.id,editable:d}})}),S.length!==m.length&&console.warn("Invalid selection",p)},f=p=>{if(r())return!1;const{selected:g}=o.get();g.some(({id:m})=>p.includes(m))&&o.set({selected:g.filter(({id:m})=>!p.includes(m))})},u=p=>{i=p,c(o.get().selected.map(({id:g})=>g))},b=p=>An(p,i,n);return e.observe(({changes:p})=>f((p.deleted||[]).map(g=>g.id))),{get event(){const p=o.get();return p?p.event:null},get selected(){const p=o.get();return p?[...p.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:b,isEmpty:r,isSelected:a,setSelected:c,setUserSelectAction:u,subscribe:o.subscribe.bind(o),userSelect:l}},An=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},X=[];for(let e=0;e<256;++e)X.push((e+256).toString(16).slice(1));function En(e,t=0){return(X[e[t+0]]+X[e[t+1]]+X[e[t+2]]+X[e[t+3]]+"-"+X[e[t+4]]+X[e[t+5]]+"-"+X[e[t+6]]+X[e[t+7]]+"-"+X[e[t+8]]+X[e[t+9]]+"-"+X[e[t+10]]+X[e[t+11]]+X[e[t+12]]+X[e[t+13]]+X[e[t+14]]+X[e[t+15]]).toLowerCase()}const vn=new Uint8Array(16);function Sn(){return crypto.getRandomValues(vn)}function At(e,t,n){return crypto.randomUUID?crypto.randomUUID():Cn(e)}function Cn(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Sn();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,En(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)}},xn=(e,t,n,o)=>({id:At(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Tn=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Ln=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Rn=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!le(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),On=(e,t)=>!le(e.target,t.target),Et=(e,t)=>{const n=Tn(e,t),o=Ln(e,t),i=Rn(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:On(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var I=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(I||{});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)),c=(o=i.updated)==null?void 0:o.some(f=>f.targetUpdated);if(r==="BODY_ONLY"&&l&&!c||r==="TARGET_ONLY"&&c&&!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},Mn=(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:b})=>b.id===u.id).newValue:u),...t.created||[]],c=[...(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:b,newValue:p}=u;if(r.has(p.id)){const g=t.updated.find(m=>m.oldValue.id===p.id).newValue;return Et(b,g)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:c,updated:f}},Ne=e=>{const t=e.id===void 0?At():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},Nn=e=>e.id!==void 0,kn=()=>{const e=new Map,t=new Map,n=[],o=(y,A={})=>{n.push({onChange:y,options:A})},i=y=>{const A=n.findIndex(v=>v.onChange==y);A>-1&&n.splice(A,1)},s=(y,A)=>{const v={origin:y,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...e.values()]};n.forEach(T=>{Bn(T,v)&&T.onChange(v)})},r=(y,A=I.LOCAL)=>{if(y.id&&e.get(y.id))throw Error(`Cannot add annotation ${y.id} - exists already`);{const v=Ne(y);e.set(v.id,v),v.bodies.forEach(T=>t.set(T.id,v.id)),s(A,{created:[v]})}},a=(y,A)=>{const v=Ne(typeof y=="string"?A:y),T=typeof y=="string"?y:y.id,D=T&&e.get(T);if(D){const U=Et(D,v);return T===v.id?e.set(T,v):(e.delete(T),e.set(v.id,v)),D.bodies.forEach(E=>t.delete(E.id)),v.bodies.forEach(E=>t.set(E.id,v.id)),U}else console.warn(`Cannot update annotation ${T} - does not exist`)},l=(y,A=I.LOCAL,v=I.LOCAL)=>{const T=Nn(A)?v:A,D=a(y,A);D&&s(T,{updated:[D]})},c=(y,A=I.LOCAL)=>{e.get(y.id)?l(y,A):r(y,A)},f=(y,A=I.LOCAL)=>{const v=y.reduce((T,D)=>{const U=a(D);return U?[...T,U]:T},[]);v.length>0&&s(A,{updated:v})},u=(y,A=I.LOCAL)=>{const v=y.map(Ne),{toAdd:T,toUpdate:D}=v.reduce((E,O)=>e.get(O.id)?{...E,toUpdate:[...E.toUpdate,O]}:{...E,toAdd:[...E.toAdd,O]},{toAdd:[],toUpdate:[]}),U=D.map(E=>a(E,A)).filter(Boolean);T.forEach(E=>{e.set(E.id,E),E.bodies.forEach(O=>t.set(O.id,E.id))}),s(A,{created:T,updated:U})},b=(y,A=I.LOCAL)=>{const v=e.get(y.annotation);if(v){const T={...v,bodies:[...v.bodies,y]};e.set(v.id,T),t.set(y.id,T.id),s(A,{updated:[{oldValue:v,newValue:T,bodiesCreated:[y]}]})}else console.warn(`Attempt to add body to missing annotation: ${y.annotation}`)},p=()=>[...e.values()],g=(y=I.LOCAL)=>{const A=[...e.values()];e.clear(),t.clear(),s(y,{deleted:A})},m=(y,A=!0,v=I.LOCAL)=>{const T=y.map(Ne);if(A){const D=[...e.values()];e.clear(),t.clear(),T.forEach(U=>{e.set(U.id,U),U.bodies.forEach(E=>t.set(E.id,U.id))}),s(v,{created:T,deleted:D})}else{const D=y.reduce((U,E)=>{const O=E.id&&e.get(E.id);return O?[...U,O]:U},[]);if(D.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${D.map(U=>U.id).join(", ")}`);T.forEach(U=>{e.set(U.id,U),U.bodies.forEach(E=>t.set(E.id,U.id))}),s(v,{created:T})}},S=y=>{const A=typeof y=="string"?y:y.id,v=e.get(A);if(v)return e.delete(A),v.bodies.forEach(T=>t.delete(T.id)),v;console.warn(`Attempt to delete missing annotation: ${A}`)},h=(y,A=I.LOCAL)=>{const v=S(y);v&&s(A,{deleted:[v]})},d=(y,A=I.LOCAL)=>{const v=y.reduce((T,D)=>{const U=S(D);return U?[...T,U]:T},[]);v.length>0&&s(A,{deleted:v})},x=y=>{const A=e.get(y.annotation);if(A){const v=A.bodies.find(T=>T.id===y.id);if(v){t.delete(v.id);const T={...A,bodies:A.bodies.filter(D=>D.id!==y.id)};return e.set(A.id,T),{oldValue:A,newValue:T,bodiesDeleted:[v]}}else console.warn(`Attempt to delete missing body ${y.id} from annotation ${y.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${y.annotation}`)},R=(y,A=I.LOCAL)=>{const v=x(y);v&&s(A,{updated:[v]})},C=(y,A=I.LOCAL)=>{const v=y.map(T=>x(T)).filter(Boolean);v.length>0&&s(A,{updated:v})},w=y=>{const A=e.get(y);return A?{...A}:void 0},B=y=>{const A=t.get(y);if(A){const v=w(A).bodies.find(T=>T.id===y);if(v)return v;console.error(`Store integrity error: body ${y} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${y}`)},N=(y,A)=>{if(y.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const v=e.get(y.annotation);if(v){const T=v.bodies.find(U=>U.id===y.id),D={...v,bodies:v.bodies.map(U=>U.id===T.id?A:U)};return e.set(v.id,D),T.id!==A.id&&(t.delete(T.id),t.set(A.id,D.id)),{oldValue:v,newValue:D,bodiesUpdated:[{oldBody:T,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${y.annotation}`)},M=(y,A,v=I.LOCAL)=>{const T=N(y,A);T&&s(v,{updated:[T]})},k=(y,A=I.LOCAL)=>{const v=y.map(T=>N({id:T.id,annotation:T.annotation},T)).filter(Boolean);s(A,{updated:v})},_=y=>{const A=e.get(y.annotation);if(A){const v={...A,target:{...A.target,...y}};return e.set(A.id,v),{oldValue:A,newValue:v,targetUpdated:{oldTarget:A.target,newTarget:y}}}else console.warn(`Attempt to update target on missing annotation: ${y.annotation}`)};return{addAnnotation:r,addBody:b,all:p,bulkAddAnnotations:m,bulkDeleteAnnotations:d,bulkDeleteBodies:C,bulkUpdateAnnotations:f,bulkUpdateBodies:k,bulkUpdateTargets:(y,A=I.LOCAL)=>{const v=y.map(T=>_(T)).filter(Boolean);v.length>0&&s(A,{updated:v})},bulkUpsertAnnotations:u,clear:g,deleteAnnotation:h,deleteBody:R,getAnnotation:w,getBody:B,observe:o,unobserve:i,updateAnnotation:l,updateBody:M,updateTarget:(y,A=I.LOCAL)=>{const v=_(y);v&&s(A,{updated:[v]})},upsertAnnotation:c}};let _n=()=>({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 In=250,Un=(e,t)=>{const n=_n(),o=[];let i=-1,s=!1,r=0;const a=g=>{if(!s){const{changes:m}=g,S=performance.now();if(S-r>In)o.splice(i+1),o.push(m),i=o.length-1;else{const h=o.length-1;o[h]=Mn(o[h],m)}r=S}s=!1};e.observe(a,{origin:I.LOCAL});const l=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g),c=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),f=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({oldValue:m})=>m)),u=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({newValue:m})=>m)),b=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),p=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...o],pointer:i}),on:(g,m)=>n.on(g,m),redo:()=>{if(o.length-1>i){s=!0;const{created:g,updated:m,deleted:S}=o[i+1];c(g),u(m),p(S),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:g,updated:m,deleted:S}=o[i];l(g),f(m),b(S),n.emit("undo",o[i]),i-=1}}}},Dn=()=>{const e=He([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Vn=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:a}=e,l=new Map;let c=[],f;const u=(m,S)=>{l.has(m)?l.get(m).push(S):l.set(m,[S])},b=(m,S)=>{const h=l.get(m);if(h){const d=h.indexOf(S);d!==-1&&h.splice(d,1)}},p=(m,S,h)=>{l.has(m)&&setTimeout(()=>{l.get(m).forEach(d=>{if(n){const x=Array.isArray(S)?S.map(C=>n.serialize(C)):n.serialize(S),R=h?h instanceof PointerEvent?h:n.serialize(h):void 0;d(x,R)}else d(S,h)})},1)};s.subscribe(({selected:m})=>{if(!(c.length===0&&m.length===0)){if(c.length===0&&m.length>0)c=m.map(({id:S})=>r.getAnnotation(S));else if(c.length>0&&m.length===0)c.forEach(S=>{const h=r.getAnnotation(S.id);h&&!le(h,S)&&p("updateAnnotation",h,S)}),c=[];else{const S=new Set(c.map(d=>d.id)),h=new Set(m.map(({id:d})=>d));c.filter(d=>!h.has(d.id)).forEach(d=>{const x=r.getAnnotation(d.id);x&&!le(x,d)&&p("updateAnnotation",x,d)}),c=[...c.filter(d=>h.has(d.id)),...m.filter(({id:d})=>!S.has(d)).map(({id:d})=>r.getAnnotation(d))]}p("selectionChanged",c)}}),i.subscribe(m=>{!f&&m?p("mouseEnterAnnotation",r.getAnnotation(m)):f&&!m?p("mouseLeaveAnnotation",r.getAnnotation(f)):f&&m&&(p("mouseLeaveAnnotation",r.getAnnotation(f)),p("mouseEnterAnnotation",r.getAnnotation(m))),f=m}),a?.subscribe(m=>p("viewportIntersect",m.map(S=>r.getAnnotation(S)))),r.observe(m=>{const{created:S,deleted:h}=m.changes;(S||[]).forEach(d=>p("createAnnotation",d)),(h||[]).forEach(d=>p("deleteAnnotation",d)),(m.changes.updated||[]).filter(d=>[...d.bodiesCreated||[],...d.bodiesDeleted||[],...d.bodiesUpdated||[]].length>0).forEach(({oldValue:d,newValue:x})=>{const R=c.find(C=>C.id===d.id)||d;c=c.map(C=>C.id===d.id?x:C),p("updateAnnotation",x,R)})},{origin:I.LOCAL}),r.observe(m=>{if(c){const S=new Set(c.map(d=>d.id)),h=(m.changes.updated||[]).filter(({newValue:d})=>S.has(d.id)).map(({newValue:d})=>d);h.length>0&&(c=c.map(d=>h.find(R=>R.id===d.id)||d))}},{origin:I.REMOTE});const g=m=>S=>{const{updated:h}=S;m?(h||[]).forEach(d=>p("updateAnnotation",d.oldValue,d.newValue)):(h||[]).forEach(d=>p("updateAnnotation",d.newValue,d.oldValue))};return t.on("undo",g(!0)),t.on("redo",g(!1)),{on:u,off:b,emit:p}},Yn=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:[]}),Pn=(e,t,n)=>{const{store:o,selection:i}=e,s=h=>{if(n){const{parsed:d,error:x}=n.parse(h);d?o.addAnnotation(d,I.REMOTE):console.error(x)}else o.addAnnotation(Fe(h),I.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=h=>{const d=o.getAnnotation(h);return n&&d?n.serialize(d):d},c=()=>n?o.all().map(n.serialize):o.all(),f=()=>{var h;const d=(((h=i.selected)==null?void 0:h.map(x=>x.id))||[]).map(x=>o.getAnnotation(x)).filter(Boolean);return n?d.map(n.serialize):d},u=(h,d=!0)=>fetch(h).then(x=>x.json()).then(x=>(p(x,d),x)),b=h=>{if(typeof h=="string"){const d=o.getAnnotation(h);if(o.deleteAnnotation(h),d)return n?n.serialize(d):d}else{const d=n?n.parse(h).parsed:h;if(d)return o.deleteAnnotation(d),h}},p=(h,d=!0)=>{if(n){const x=n.parseAll||Yn(n),{parsed:R,failed:C}=x(h);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),o.bulkAddAnnotations(R,d,I.REMOTE)}else o.bulkAddAnnotations(h.map(Fe),d,I.REMOTE)},g=(h,d)=>{h?i.setSelected(h,d):i.clear()},m=h=>{i.setUserSelectAction(h)},S=h=>{if(n){const d=n.parse(h).parsed,x=n.serialize(o.getAnnotation(d.id));return o.updateAnnotation(d),x}else{const d=o.getAnnotation(h.id);return o.updateAnnotation(Fe(h)),d}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:c,getHistory:t.getHistory,getSelected:f,loadAnnotations:u,redo:t.redo,removeAnnotation:b,setAnnotations:p,setSelected:g,setUserSelectAction:m,undo:t.undo,updateAnnotation:S}};let Kn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",Xn=e=>crypto.getRandomValues(new Uint8Array(e)),Hn=(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),c=r;for(;c--;)if(a+=e[l[c]&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}}},$n=(e,t=21)=>Hn(e,t|0,Xn),jn=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Kn[n[e]&63];return t};const Fn=()=>({isGuest:!0,id:$n("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Wn=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,zn=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,modified:l,creator:c,...f}=n;return{id:o||`temp-${Wn(n)}`,annotation:t,type:i,purpose:s,value:r,creator:vt(c),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...f}}),qn=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});jn();const St=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}},Ct=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)}},ke=(e,t,n,o)=>{const{store:i,selection:s,hover:r}=t;let a,l,c;const f=Ct(n),u=M=>{const{x:k,y:_}=e.getBoundingClientRect(),y=i.getAt(M.clientX-k,M.clientY-_,!1,l);y&&t.selection.evalSelectAction(y)!==$e.NONE?r.current!==y.id&&(e.classList.add("hovered"),r.set(y.id)):r.current&&(e.classList.remove("hovered"),r.set(null))};e.addEventListener("pointermove",u);const b=Re((M=!1)=>requestAnimationFrame(()=>{c&&c.clear();const k=St(e),{minX:_,minY:y,maxX:A,maxY:v}=k,T=l?i.getIntersecting(_,y,A,v).filter(({annotation:E})=>l(E)):i.getIntersecting(_,y,A,v),D=s.selected.map(({id:E})=>E),U=T.map(({annotation:E,rects:O})=>{const j=D.includes(E.id),ce=E.id===r.current;return{annotation:E,rects:O,state:{selected:j,hovered:ce}}});o.redraw(U,k,a,c,M),setTimeout(()=>f(T.map(({annotation:E})=>E)),1)}),10),p=M=>{c=M,b()},g=M=>{a=M,b()},m=M=>{l=M,b(!1)},S=()=>b();i.observe(S);const h=s.subscribe(()=>b()),d=r.subscribe(()=>b()),x=()=>b(!0);document.addEventListener("scroll",x,{capture:!0,passive:!0});const R=Re(()=>{i.recalculatePositions(),c?.reset(),b()},10);window.addEventListener("resize",R);const C=new ResizeObserver(R);C.observe(e);const w={attributes:!0,childList:!0,subtree:!0},B=new MutationObserver(Re(M=>{M.every(_=>_.target===e||e.contains(_.target))||b(!0)},150));return B.observe(document.body,w),{destroy:()=>{e.removeEventListener("pointermove",u),o.destroy(),i.unobserve(S),h(),d(),document.removeEventListener("scroll",x),window.removeEventListener("resize",R),C.disconnect(),B.disconnect()},redraw:b,setStyle:g,setFilter:m,setPainter:p,setVisible:o.setVisible}},Gn=()=>{const e=document.createElement("canvas");return e.width=window.innerWidth,e.height=window.innerHeight,e.className="r6o-canvas-highlight-layer bg",e},Qn=(e,t)=>{e.width=window.innerWidth,e.height=window.innerHeight},Jn=e=>{console.warn('WARNING! Canvas renderer is deprecated and will be removed in the next major release. Please use the default "SPANS" renderer instead.'),e.classList.add("r6o-annotatable");const t=Gn(),n=t.getContext("2d");document.body.appendChild(t);const o=(a,l,c,f)=>requestAnimationFrame(()=>{const{width:u,height:b}=t;n.clearRect(-.5,-.5,u+1,b+1),f&&f.clear();const{top:p,left:g}=l;[...a].sort((S,h)=>{const{annotation:{target:{created:d}}}=S,{annotation:{target:{created:x}}}=h;return d.getTime()-x.getTime()}).forEach(S=>{const h=c?typeof c=="function"?c(S.annotation,S.state):c:S.state?.selected?pe:J,d=f&&f.paint(S,l)||h,x=S.rects.map(({x:R,y:C,width:w,height:B})=>({x:R+g,y:C+p,width:w,height:B}));if(n.fillStyle=d.fill,n.globalAlpha=d.fillOpacity||1,x.forEach(({x:R,y:C,width:w,height:B})=>n.fillRect(R,C,w,B)),d.underlineColor){n.globalAlpha=1,n.strokeStyle=d.underlineColor,n.lineWidth=d.underlineThickness??1;const R=d.underlineOffset??0;x.forEach(({x:C,y:w,width:B,height:N})=>{n.beginPath(),n.moveTo(C,w+N+R),n.lineTo(C+B,w+N+R),n.stroke()})}})}),i=bt(()=>Qn(t),10);return window.addEventListener("resize",i),{destroy:()=>{t.remove(),i.clear(),window.removeEventListener("resize",i)},setVisible:a=>{console.log("setVisible not implemented on Canvas renderer")},redraw:o}},xt=(e,t,n)=>ke(e,t,n,Jn(e));var Zn={grad:.9,turn:360,rad:360/(2*Math.PI)},ee=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},P=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=Math.pow(10,t)),Math.round(n*e)/n+0},F=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},Tt=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},Lt=function(e){return{r:F(e.r,0,255),g:F(e.g,0,255),b:F(e.b,0,255),a:F(e.a)}},We=function(e){return{r:P(e.r),g:P(e.g),b:P(e.b),a:P(e.a,3)}},eo=/^#([0-9a-f]{3,8})$/i,_e=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},Rt=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}},Ot=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),c=s%6;return{r:255*[o,a,r,r,l,o][c],g:255*[l,o,o,a,r,r][c],b:255*[r,r,l,o,o,a][c],a:i}},Bt=function(e){return{h:Tt(e.h),s:F(e.s,0,100),l:F(e.l,0,100),a:F(e.a)}},Mt=function(e){return{h:P(e.h),s:P(e.s),l:P(e.l),a:P(e.a,3)}},Nt=function(e){return Ot((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},me=function(e){return{h:(t=Rt(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},to=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,no=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,oo=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,io=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,kt={string:[[function(e){var t=eo.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?P(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?P(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=oo.exec(e)||io.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Lt({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=to.exec(e)||no.exec(e);if(!t)return null;var n,o,i=Bt({h:(n=t[1],o=t[2],o===void 0&&(o="deg"),Number(n)*(Zn[o]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return Nt(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)?Lt({r:Number(t),g:Number(n),b:Number(o),a:Number(s)}):null},"rgb"],[function(e){var t=e.h,n=e.s,o=e.l,i=e.a,s=i===void 0?1:i;if(!ee(t)||!ee(n)||!ee(o))return null;var r=Bt({h:Number(t),s:Number(n),l:Number(o),a:Number(s)});return Nt(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:Tt(a.h),s:F(a.s,0,100),v:F(a.v,0,100),a:F(a.a)}})({h:Number(t),s:Number(n),v:Number(o),a:Number(s)});return Ot(r)},"hsv"]]},_t=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]},so=function(e){return typeof e=="string"?_t(e.trim(),kt.string):typeof e=="object"&&e!==null?_t(e,kt.object):[null,void 0]},ze=function(e,t){var n=me(e);return{h:n.h,s:F(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},It=function(e,t){var n=me(e);return{h:n.h,s:n.s,l:F(n.l+100*t,0,100),a:n.a}},Ut=(function(){function e(t){this.parsed=so(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 P(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=We(this.rgba),n=t.r,o=t.g,i=t.b,r=(s=t.a)<1?_e(P(255*s)):"","#"+_e(n)+_e(o)+_e(i)+r;var t,n,o,i,s,r},e.prototype.toRgb=function(){return We(this.rgba)},e.prototype.toRgbString=function(){return t=We(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 Mt(me(this.rgba))},e.prototype.toHslString=function(){return t=Mt(me(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=Rt(this.rgba),{h:P(t.h),s:P(t.s),v:P(t.v),a:P(t.a,3)};var t},e.prototype.invert=function(){return W({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),W(ze(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),W(ze(this.rgba,-t))},e.prototype.grayscale=function(){return W(ze(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),W(It(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),W(It(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"?W({r:(n=this.rgba).r,g:n.g,b:n.b,a:t}):P(this.rgba.a,3);var n},e.prototype.hue=function(t){var n=me(this.rgba);return typeof t=="number"?W({h:t,s:n.s,l:n.l,a:n.a}):P(n.h)},e.prototype.isEqual=function(t){return this.toHex()===W(t).toHex()},e})(),W=function(e){return e instanceof Ut?e:new Ut(e)};const ro=e=>[`background-color:${W(e?.fill||J.fill).alpha(e?.fillOpacity===void 0?J.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(";"),Dt=()=>{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)=>{l&&l.clear();const c=new Set(s.map(u=>u.annotation.id));Array.from(t).filter(u=>!c.has(u));const f=s.map(u=>{const b=a?typeof a=="function"?a(u.annotation,u.state):a:u.state?.selected?pe:J,p=l&&l.paint(u,r)||b;return`::highlight(_${u.annotation.id}) { ${ro(p)} }`});e.innerHTML=f.join(`
|
|
2
|
-
`),CSS.highlights.clear(),s.forEach(({annotation:u})=>{const b=u.target.selector.map(g=>g.range),p=new Highlight(...b);CSS.highlights.set(`_${u.id}`,p)}),t=c}}},Vt=(e,t,n)=>ke(e,t,n,Dt()),Yt=e=>e?.fillOpacity!==void 0?W(e?.fill||J.fill).alpha(e.fillOpacity).toHex():e?.fill?e.fill:W(J.fill).alpha(J.fillOpacity).toHex();var Pt=Object.prototype.hasOwnProperty;function Ge(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--&&Ge(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Pt.call(e,n)&&++o&&!Pt.call(t,n)||!(n in t)||!Ge(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Kt=(e,t,n,o,i)=>{const s=n?typeof n=="function"?n(e.annotation,e.state,i)||(e.state?.selected?pe:J):n:e.state?.selected?pe:J;return o&&o.paint(e,t)||s},ao=(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))},lo=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,c,f)=>{const b=!(Ge(n,r)&&f);if(!c&&!b)return;b&&(t.innerHTML=""),[...r].sort((g,m)=>{const{annotation:{target:{created:S}}}=g,{annotation:{target:{created:h}}}=m;return S&&h?S.getTime()-h.getTime():0}).forEach(g=>{g.rects.map(m=>{const S=ao(m,r),h=Kt(g,a,l,c,S);if(b){const d=document.createElement("span");d.className="r6o-annotation",d.dataset.annotation=g.annotation.id,d.style.left=`${m.x}px`,d.style.top=`${m.y}px`,d.style.width=`${m.width}px`,d.style.height=`${m.height}px`,d.style.backgroundColor=Yt(h),h.underlineStyle&&(d.style.borderStyle=h.underlineStyle),h.underlineColor&&(d.style.borderColor=h.underlineColor),h.underlineThickness&&(d.style.borderBottomWidth=`${h.underlineThickness}px`),h.underlineOffset&&(d.style.paddingBottom=`${h.underlineOffset}px`),t.appendChild(d)}})}),n=r},setVisible:r=>{r?t.classList.remove("hidden"):t.classList.add("hidden")}}},Xt=(e,t,n)=>ke(e,t,n,lo(e)),H=[];for(let e=0;e<256;++e)H.push((e+256).toString(16).slice(1));function co(e,t=0){return(H[e[t+0]]+H[e[t+1]]+H[e[t+2]]+H[e[t+3]]+"-"+H[e[t+4]]+H[e[t+5]]+"-"+H[e[t+6]]+H[e[t+7]]+"-"+H[e[t+8]]+H[e[t+9]]+"-"+H[e[t+10]]+H[e[t+11]]+H[e[t+12]]+H[e[t+13]]+H[e[t+14]]+H[e[t+15]]).toLowerCase()}const uo=new Uint8Array(16);function fo(){return crypto.getRandomValues(uo)}function Ht(e,t,n){return crypto.randomUUID?crypto.randomUUID():ho(e)}function ho(e,t,n){e=e||{};const o=e.random??e.rng?.()??fo();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,co(o)}const go=(e,t)=>({parse:n=>$t(n),serialize:n=>jt(n,e,t)}),po=e=>e.quote!==void 0&&e.start!==void 0&&e.end!==void 0,mo=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,b)=>{switch(b.type){case"TextQuoteSelector":u.quote=b.exact;break;case"TextPositionSelector":u.start=b.start,u.end=b.end;break}return u},{});if(po(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}},$t=e=>{const t=e.id||Ht(),{creator:n,created:o,modified:i,body:s,...r}=e,a=zn(s,t),l=mo(e);return"error"in l?{error:l.error}:{parsed:{...r,id:t,bodies:a,target:l.parsed}}},jt=(e,t,n)=>{const{bodies:o,target:i,...s}=e,{selector:r,creator:a,created:l,updated:c,...f}=i,u=r.map(b=>{const{id:p,quote:g,start:m,end:S,range:h}=b,d={type:"TextQuoteSelector",exact:g};if(n){const{prefix:R,suffix:C}=lt(h,n);d.prefix=R,d.suffix=C}const x={type:"TextPositionSelector",start:m,end:S};return{...f,id:p,scope:"scope"in b?b.scope:void 0,source:t,selector:[d,x]}});return{...s,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:qn(e.bodies),creator:a,created:l?.toISOString(),modified:c?.toISOString(),target:u}},yo=()=>{const e=document.createElement("canvas");e.width=2*window.innerWidth,e.height=2*window.innerHeight,e.className="r6o-presence-layer";const t=e.getContext("2d");return t.scale(2,2),t.translate(.5,.5),e},Ft=(e,t={})=>{const n=yo(),o=n.getContext("2d");document.body.appendChild(n);const i=new Map,s=f=>Array.from(i.entries()).filter(([u,b])=>b.presenceKey===f.presenceKey).map(([u,b])=>u);return e.on("selectionChange",(f,u)=>{s(f).forEach(p=>i.delete(p)),u&&u.forEach(p=>i.set(p,f))}),{clear:()=>{const{width:f,height:u}=n;o.clearRect(-.5,-.5,f+1,u+1)},destroy:()=>{n.remove()},paint:(f,u,b)=>{t.font&&(o.font=t.font);const p=i.get(f.annotation.id);if(p){const{height:g}=f.rects[0],m=f.rects[0].x+u.left,S=f.rects[0].y+u.top;o.fillStyle=p.appearance.color,o.fillRect(m-2,S-2.5,2,g+5);const h=o.measureText(p.appearance.label),d=h.width+6,x=h.actualBoundingBoxAscent+h.actualBoundingBoxDescent+8,R=h.fontBoundingBoxAscent?8:6.5;return o.fillRect(m-2,S-2.5-x,d,x),o.fillStyle="#fff",o.fillText(p.appearance.label,m+1,S-R),{fill:p.appearance.color,fillOpacity:b?.45:.18}}},reset:()=>{n.width=2*window.innerWidth,n.height=2*window.innerHeight;const f=n.getContext("2d");f.scale(2,2),f.translate(.5,.5)}}};function Wt(e,t,n=0,o=e.length-1,i=bo){for(;o>n;){if(o-n>600){const l=o-n+1,c=t-n+1,f=Math.log(l),u=.5*Math.exp(2*f/3),b=.5*Math.sqrt(f*u*(l-u)/l)*(c-l/2<0?-1:1),p=Math.max(n,Math.floor(t-c*u/l+b)),g=Math.min(o,Math.floor(t+(l-c)*u/l+b));Wt(e,t,p,g,i)}const s=e[t];let r=n,a=o;for(ye(e,n,t),i(e[o],s)>0&&ye(e,n,o);r<a;){for(ye(e,r,a),r++,a--;i(e[r],s)<0;)r++;for(;i(e[a],s)>0;)a--}i(e[n],s)===0?ye(e,n,a):(a++,ye(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function ye(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function bo(e,t){return e<t?-1:e>t?1:0}class wo{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(!Ue(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;Ue(t,l)&&(n.leaf?o.push(a):Je(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!Ue(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(Ue(t,r)){if(n.leaf||Je(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=ue([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let a,l,c;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],a=r.pop(),c=!0),o.leaf){const f=Ao(t,o.children,n);if(f!==-1)return o.children.splice(f,1),s.push(o),this._condense(s),this}!c&&!o.leaf&&Je(o,i)?(s.push(o),r.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],c=!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=ue(t.slice(n,o+1)),de(a,this.toBBox),a;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),a=ue([]),a.leaf=!1,a.height=i;const l=Math.ceil(s/r),c=l*Math.ceil(Math.sqrt(r));zt(t,n,o,c,this.compareMinX);for(let f=n;f<=o;f+=c){const u=Math.min(f+c-1,o);zt(t,f,u,l,this.compareMinY);for(let b=f;b<=u;b+=l){const p=Math.min(b+l-1,u);a.children.push(this._build(t,b,p,i-1))}}return de(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 c=n.children[l],f=Qe(c),u=So(t,c)-f;u<r?(r=u,s=f<s?f:s,a=c):u===r&&f<s&&(s=f,a=c)}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=ue(o.children.splice(r,o.children.length-r));a.height=o.height,a.leaf=o.leaf,de(o,this.toBBox),de(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(o,a)}_splitRoot(t,n){this.data=ue([t,n]),this.data.height=t.height+1,this.data.leaf=!1,de(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=be(t,0,a,this.toBBox),c=be(t,a,o,this.toBBox),f=Co(l,c),u=Qe(l)+Qe(c);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:Eo,s=t.leaf?this.compareMinY:vo,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=be(t,0,n,s),a=be(t,o-n,o,s);let l=Ie(r)+Ie(a);for(let c=n;c<o-n;c++){const f=t.children[c];we(r,t.leaf?s(f):f),l+=Ie(r)}for(let c=o-n-1;c>=n;c--){const f=t.children[c];we(a,t.leaf?s(f):f),l+=Ie(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():de(t[n],this.toBBox)}}function Ao(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 de(e,t){be(e,0,e.children.length,t,e)}function be(e,t,n,o,i){i||(i=ue(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 Eo(e,t){return e.minX-t.minX}function vo(e,t){return e.minY-t.minY}function Qe(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ie(e){return e.maxX-e.minX+(e.maxY-e.minY)}function So(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 Co(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 Je(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Ue(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function ue(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)}}let xo=()=>({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 To=(e,t,n,o)=>{const i=new wo,s=new Map,r=xo(),a=(C,w)=>{const B=C.selector.flatMap(M=>{const k=Q([M])?M.range:Xe(M,t).range;return st(k)}),N=dt(B,n,o).map(M=>ht(M,w));return N.map(M=>{const{x:k,y:_,width:y,height:A}=M;return{minX:k,minY:_,maxX:k+y,maxY:_+A,annotation:{id:C.annotation,rects:N}}})},l=()=>[...s.values()],c=()=>{i.clear(),s.clear()},f=C=>{const w=a(C,t.getBoundingClientRect());w.length!==0&&(w.forEach(B=>i.insert(B)),s.set(C.annotation,w))},u=C=>{const w=s.get(C.annotation);w&&(w.forEach(B=>i.remove(B)),s.delete(C.annotation))},b=C=>{u(C),f(C)},p=(C,w=!0)=>{w&&c();const B=t.getBoundingClientRect(),N=C.map(k=>({target:k,rects:a(k,B)}));N.forEach(({target:k,rects:_})=>{_.length>0&&s.set(k.annotation,_)});const M=N.flatMap(({rects:k})=>k);i.load(M)},g=(C,w,B=!1)=>{const N=i.search({minX:C,minY:w,maxX:C,maxY:w}),M=k=>k.annotation.rects.reduce((_,y)=>_+y.width*y.height,0);return N.length>0?(N.sort((k,_)=>M(k)-M(_)),B?N.map(k=>k.annotation.id):[N[0].annotation.id]):[]},m=C=>{const w=S(C);if(w.length===0)return;let B=w[0].left,N=w[0].top,M=w[0].right,k=w[0].bottom;for(let _=1;_<w.length;_++){const y=w[_];B=Math.min(B,y.left),N=Math.min(N,y.top),M=Math.max(M,y.right),k=Math.max(k,y.bottom)}return new DOMRect(B,N,M-B,k-N)},S=C=>{const w=s.get(C);return w?w[0].annotation.rects:[]};return{all:l,clear:c,getAt:g,getAnnotationBounds:m,getAnnotationRects:S,getIntersecting:(C,w,B,N)=>{const M=i.search({minX:C,minY:w,maxX:B,maxY:N}),k=new Set(M.map(_=>_.annotation.id));return Array.from(k).map(_=>({annotation:e.getAnnotation(_),rects:S(_)})).filter(_=>!!_.annotation)},insert:f,recalculate:()=>{p(e.all().map(C=>C.target),!0),r.emit("recalculate")},remove:u,set:p,size:()=>i.all().length,update:b,on:(C,w)=>r.on(C,w)}},qt=(e,t)=>{const n=kn(),o=To(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance),i=wn(n,t.userSelectAction,t.adapter),s=bn(n),r=Dn(),a=(d,x=I.LOCAL)=>{const R=Be(d,e),C=Q(R.target.selector);return C&&n.addAnnotation(R,x),C},l=(d,x=!0,R=I.LOCAL)=>{const C=d.map(B=>Be(B,e)),w=C.filter(B=>!Q(B.target.selector));return n.bulkAddAnnotations(C,x,R),w},c=(d,x=I.LOCAL)=>{const R=d.map(w=>Be(w,e)),C=R.filter(w=>!Q(w.target.selector));return R.forEach(w=>{n.getAnnotation(w.id)?n.updateAnnotation(w,x):n.addAnnotation(w,x)}),C},f=(d,x=I.LOCAL)=>{const R=ge(d,e);n.updateTarget(R,x)},u=(d,x=I.LOCAL)=>{const R=d.map(C=>ge(C,e));n.bulkUpdateTargets(R,x)};function b(d,x,R,C){const w=R||!!C,B=o.getAt(d,x,w).map(M=>n.getAnnotation(M)),N=C?B.filter(C):B;if(N.length!==0)return R?N:N[0]}const p=d=>o.getAnnotationRects(d).length>0?o.getAnnotationBounds(d):void 0,g=(d,x,R,C)=>o.getIntersecting(d,x,R,C),m=d=>o.getAnnotationRects(d),S=()=>o.recalculate(),h=d=>o.on("recalculate",d);return n.observe(({changes:d})=>{const x=(d.deleted||[]).filter(w=>Q(w.target.selector)),R=(d.created||[]).filter(w=>Q(w.target.selector)),C=(d.updated||[]).filter(w=>Q(w.newValue.target.selector));x?.length>0&&x.forEach(w=>o.remove(w.target)),R.length>0&&o.set(R.map(w=>w.target),!1),C?.length>0&&C.forEach(({newValue:w})=>o.update(w.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotations:l,bulkUpdateTargets:u,bulkUpsertAnnotations:c,getAnnotationBounds:p,getAnnotationRects:m,getIntersecting:g,getAt:b,recalculatePositions:S,onRecalculatePositions:h,updateTarget:f},selection:i,hover:s,viewport:r}},Ze=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function et(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),n)}function Ae(e,t,n,o){e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent("on".concat(t),n)}function Gt(e,t){const n=t.slice(0,t.length-1);for(let o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}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 Lo(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}const Ee={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,"-":Ze?173:189,"=":Ze?61:187,";":Ze?59:186,"'":222,"{":219,"}":221,"[":219,"]":221,"\\":220},G={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,meta:91,command:91},ve={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},$={16:!1,18:!1,17:!1,91:!1},Y={};for(let e=1;e<20;e++)Ee["f".concat(e)]=111+e;let V=[],Se=null,Jt="all";const te=new Map,fe=e=>Ee[e.toLowerCase()]||G[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),Ro=e=>Object.keys(Ee).find(t=>Ee[t]===e),Oo=e=>Object.keys(G).find(t=>G[t]===e);function Zt(e){Jt=e||"all"}function Ce(){return Jt||"all"}function Bo(){return V.slice(0)}function Mo(){return V.map(e=>Ro(e)||Oo(e)||String.fromCharCode(e))}function No(){const e=[];return Object.keys(Y).forEach(t=>{Y[t].forEach(n=>{let{key:o,scope:i,mods:s,shortcut:r}=n;e.push({scope:i,shortcut:r,mods:s,keys:o.split("+").map(a=>fe(a))})})}),e}function ko(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}function _o(e){return typeof e=="string"&&(e=fe(e)),V.indexOf(e)!==-1}function Io(e,t){let n,o;e||(e=Ce());for(const i in Y)if(Object.prototype.hasOwnProperty.call(Y,i))for(n=Y[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(r=>{let{element:a}=r;return tt(a)}):o++;Ce()===e&&Zt(t||"all")}function Uo(e){let t=e.keyCode||e.which||e.charCode;e.key&&e.key.toLowerCase()==="capslock"&&(t=fe(e.key));const n=V.indexOf(t);if(n>=0&&V.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&V.splice(0,V.length),(t===93||t===224)&&(t=91),t in $){$[t]=!1;for(const o in G)G[o]===t&&(z[o]=!1)}}function en(e){if(typeof e>"u")Object.keys(Y).forEach(i=>{Array.isArray(Y[i])&&Y[i].forEach(s=>De(s)),delete Y[i]}),tt(null);else if(Array.isArray(e))e.forEach(i=>{i.key&&De(i)});else if(typeof e=="object")e.key&&De(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];let[i,s]=n;typeof i=="function"&&(s=i,i=""),De({key:e,scope:i,method:s,splitKey:"+"})}}const De=e=>{let{key:t,scope:n,method:o,splitKey:i="+"}=e;Qt(t).forEach(r=>{const a=r.split(i),l=a.length,c=a[l-1],f=c==="*"?"*":fe(c);if(!Y[f])return;n||(n=Ce());const u=l>1?Gt(G,a):[],b=[];Y[f]=Y[f].filter(p=>{const m=(o?p.method===o:!0)&&p.scope===n&&Lo(p.mods,u);return m&&b.push(p.element),!m}),b.forEach(p=>tt(p))})};function tn(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 $)Object.prototype.hasOwnProperty.call($,s)&&(!$[s]&&t.mods.indexOf(+s)>-1||$[s]&&t.mods.indexOf(+s)===-1)&&(i=!1);(t.mods.length===0&&!$[16]&&!$[18]&&!$[17]&&!$[91]||i||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(V),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function nn(e,t){const n=Y["*"];let o=e.keyCode||e.which||e.charCode;if(e.key&&e.key.toLowerCase()==="capslock"||!z.filter.call(this,e))return;if((o===93||o===224)&&(o=91),V.indexOf(o)===-1&&o!==229&&V.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=ve[a];e[a]&&V.indexOf(l)===-1?V.push(l):!e[a]&&V.indexOf(l)>-1?V.splice(V.indexOf(l),1):a==="metaKey"&&e[a]&&(V=V.filter(c=>c in ve||c===o))}),o in $){$[o]=!0;for(const a in G)if(Object.prototype.hasOwnProperty.call(G,a)){const l=ve[G[a]];z[a]=e[l]}if(!n)return}for(const a in $)Object.prototype.hasOwnProperty.call($,a)&&($[a]=e[ve[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(V.indexOf(17)===-1&&V.push(17),V.indexOf(18)===-1&&V.push(18),$[17]=!0,$[18]=!0);const i=Ce();if(n)for(let a=0;a<n.length;a++)n[a].scope===i&&(e.type==="keydown"&&n[a].keydown||e.type==="keyup"&&n[a].keyup)&&tn(e,n[a],i,t);if(!(o in Y))return;const s=Y[o],r=s.length;for(let a=0;a<r;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,f=l.key.split(c),u=[];for(let b=0;b<f.length;b++)u.push(fe(f[b]));u.sort().join("")===V.sort().join("")&&tn(e,l,i,t)}}function z(e,t,n){V=[];const o=Qt(e);let i=[],s="all",r=document,a=0,l=!1,c=!0,f="+",u=!1,b=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(s=t.scope),t.element&&(r=t.element),t.keyup&&(l=t.keyup),t.keydown!==void 0&&(c=t.keydown),t.capture!==void 0&&(u=t.capture),typeof t.splitKey=="string"&&(f=t.splitKey),t.single===!0&&(b=!0)),typeof t=="string"&&(s=t),b&&en(e,s);a<o.length;a++)e=o[a].split(f),i=[],e.length>1&&(i=Gt(G,e)),e=e[e.length-1],e=e==="*"?"*":fe(e),e in Y||(Y[e]=[]),Y[e].push({keyup:l,keydown:c,scope:s,mods:i,shortcut:o[a],method:n,key:o[a],splitKey:f,element:r});if(typeof r<"u"&&window){if(!te.has(r)){const p=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return nn(m,r)},g=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;nn(m,r),Uo(m)};te.set(r,{keydownListener:p,keyupListenr:g,capture:u}),et(r,"keydown",p,u),et(r,"keyup",g,u)}if(!Se){const p=()=>{V=[]};Se={listener:p,capture:u},et(window,"focus",p,u)}}}function Do(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(Y).forEach(n=>{Y[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method()})})}function tt(e){const t=Object.values(Y).flat();if(t.findIndex(o=>{let{element:i}=o;return i===e})<0){const{keydownListener:o,keyupListenr:i,capture:s}=te.get(e)||{};o&&i&&(Ae(e,"keyup",i,s),Ae(e,"keydown",o,s),te.delete(e))}if((t.length<=0||te.size<=0)&&(Object.keys(te).forEach(i=>{const{keydownListener:s,keyupListenr:r,capture:a}=te.get(i)||{};s&&r&&(Ae(i,"keyup",r,a),Ae(i,"keydown",s,a),te.delete(i))}),te.clear(),Object.keys(Y).forEach(i=>delete Y[i]),Se)){const{listener:i,capture:s}=Se;Ae(window,"focus",i,s),Se=null}}const nt={getPressedKeyString:Mo,setScope:Zt,getScope:Ce,deleteScope:Io,getPressedKeyCodes:Bo,getAllKeyCodes:No,isPressed:_o,filter:ko,trigger:Do,unbind:en,keyMap:Ee,modifier:G,modifierMap:ve};for(const e in nt)Object.prototype.hasOwnProperty.call(nt,e)&&(z[e]=nt[e]);if(typeof window<"u"){const e=window.hotkeys;z.noConflict=t=>(t&&window.hotkeys===z&&(window.hotkeys=e),z),window.hotkeys=z}async function Vo(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 on=300,sn=["up","down","left","right"],rn=Pe?"⌘+a":"ctrl+a",Yo=[...sn.map(e=>`shift+${e}`),rn],an=(e,t,n,o)=>{const{store:i,selection:s}=t;let r;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:c,dismissOnNotAnnotatable:f="NEVER"}=o;let u,b=a,p="CREATE_NEW",g,m,S,h;const d=E=>{b=E,N.clear(),E||(m=void 0,g=void 0,S=void 0,h=void 0)},x=E=>p=E||"CREATE_NEW",R=E=>u=E,C=E=>r=E,w=E=>{if(p==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const O=E;return Pe?O.metaKey:O.ctrlKey}else return!1},B=()=>{if(!b||S===!1)return;const{selected:E}=s;if((w(h)||p==="REPLACE_CURRENT")&&E.length===1&&E[0].editable){const j=i.getAnnotation(E[0].id);if(j?.target){m=j.target,g={annotation:j.id,selector:[],created:m.created,creator:m.creator,updated:new Date,updatedBy:r};return}}m=void 0,g={annotation:Ht(),selector:[],created:new Date,creator:r}},N=bt(E=>{if(!b)return;const O=document.getSelection();if(!O?.anchorNode)return;const j=Array.from(Array(O.rangeCount).keys()).map(K=>O.getRangeAt(K));if(j.every(K=>!Ye(e,K))){g=void 0;return}const ce=E.timeStamp-(h?.timeStamp||E.timeStamp);if(h?.type==="pointerdown"&&(ce<1e3&&!g||O.isCollapsed&&ce<on)&&B(),!g&&(B(),!g))return;if(O.isCollapsed){i.getAnnotation(g.annotation)&&!(w(h)||p==="REPLACE_CURRENT")&&(s.clear(),i.deleteAnnotation(g.annotation));return}const oe=j.map(K=>gt(K,e));if(oe.every(K=>ct(K)))return;const Z=oe.flatMap(K=>rt(e,K.cloneRange()));if(!(Z.length>0&&!g||Z.length!==g.selector.length||Z.some((K,xe)=>K.toString()!==g.selector[xe]?.quote)))return;const Ve=w(h)&&m?ut([...m.selector.map(K=>K.range),...Z]):Z;g={...g,selector:Ve.map(K=>ft(K,e,l)),updated:new Date},!(w(h)||p==="REPLACE_CURRENT")&&(i.getAnnotation(g.annotation)?i.updateTarget(g,I.LOCAL):s.clear())},10),M=E=>{h=Le(E),S=h.button===0},k=async E=>{if(!S)return;const O=Le(E),j=()=>{const{x:oe,y:Z}=e.getBoundingClientRect();if(ae(e,O.target)){(typeof f=="function"?f(O,e):f==="ALWAYS")&&s.clear();return}const ie=O.target instanceof Node&&e.contains(O.target)&&i.getAt(O.clientX-oe,O.clientY-Z,c==="all",u);if(ie){const{selected:Ve}=s,K=new Set(Ve.map(Te=>Te.id)),xe=Array.isArray(ie)?ie.map(Te=>Te.id):[ie.id];(K.size!==xe.length||!xe.every(Te=>K.has(Te)))&&(n.emit("clickAnnotation",ie),s.userSelect(xe,O))}else s.clear()};if(O.timeStamp-h.timeStamp<on){await _();const oe=document.getSelection(),Z=ae(e,h.target),ie=ae(e,O.target);if(oe?.isCollapsed||Z&&ie){g=void 0,j();return}}g&&g.selector.length>0&&(D(),s.userSelect(g.annotation,O))},_=async()=>{const E=document.getSelection();let O=!1,j=E?.isCollapsed;const ce=()=>j||O,oe=1;return setTimeout(()=>O=!0,50),Vo(()=>j=E?.isCollapsed,oe,ce)},y=E=>{document.getSelection()?.isCollapsed||((!g||g.selector.length===0)&&N(E),g&&(D(),s.userSelect(g.annotation,Le(E))))},A=E=>{b&&(E.repeat||E.target instanceof Node&&ae(e,E.target)&&E.target!==document.body||E.key==="Shift"&&g&&(document.getSelection().isCollapsed||(D(),s.userSelect(g.annotation,he(E)))))},v=E=>{const O=()=>setTimeout(()=>{g?.selector.length>0&&(s.clear(),i.addAnnotation({id:g.annotation,bodies:[],target:g}),s.userSelect(g.annotation,he(E))),document.removeEventListener("selectionchange",O)},100);document.addEventListener("selectionchange",O),B()};z(Yo.join(","),{element:e,keydown:!0,keyup:!1},E=>{E.repeat||(h=he(E))}),z(rn,{keydown:!0,keyup:!1},E=>{h=he(E),v(E)});const T=E=>{E.repeat||E.target instanceof Node&&ae(e,E.target)&&E.target!==document.body||(g=void 0,s.clear())};z(sn.join(","),{keydown:!0,keyup:!1},T);const D=()=>{const E=i.getAnnotation(g.annotation);if(!E)i.addAnnotation({id:g.annotation,bodies:[],target:g});else{const{target:{updated:O}}=E,{updated:j}=g;(!O||!j||O<j)&&i.updateTarget(g)}};return document.addEventListener("pointerdown",M),document.addEventListener("pointerup",k),document.addEventListener("contextmenu",y),document.addEventListener("keyup",A),e.addEventListener("selectstart",B),document.addEventListener("selectionchange",N),{destroy:()=>{g=void 0,m=void 0,S=void 0,h=void 0,N.clear(),document.removeEventListener("pointerdown",M),document.removeEventListener("pointerup",k),document.removeEventListener("contextmenu",y),document.removeEventListener("keyup",A),e.removeEventListener("selectstart",B),document.removeEventListener("selectionchange",N),z.unbind()},setFilter:R,setUser:C,setAnnotatingEnabled:d,setAnnotatingMode:x}},ln=(e,t)=>({...e,annotatingEnabled:e.annotatingEnabled??t.annotatingEnabled,user:e.user||t.user}),cn="SPANS",Po=(e,t={})=>{ot(e),it(e);const n=ln(t,{annotatingEnabled:!0,user:Fn()}),o=qt(e,n),{selection:i,viewport:s}=o,r=o.store,a=Un(r),l=Vn(o,a,n.adapter);let c=n.user;const f=typeof n.renderer!="function"?n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":cn:n.renderer||cn:null,u=f===null?n.renderer(e,o,s):f==="SPANS"?Xt(e,o,s):f==="CSS_HIGHLIGHTS"?Vt(e,o,s):f==="CANVAS"?xt(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 b=an(e,o,l,n);b.setUser(c);const p=Pn(o,a,n.adapter),g=()=>c,m=w=>{b.setAnnotatingEnabled(w===void 0?!0:w)},S=w=>{b.setAnnotatingMode(w)},h=w=>{u.setFilter(w),b.setFilter(w)},d=w=>{c=w,b.setUser(w)},x=w=>{w&&(u.setPainter(Ft(w,n.presence)),w.on("selectionChange",()=>u.redraw()))},R=w=>{w?i.setSelected(w):i.clear()};return{...p,destroy:()=>{u.destroy(),b.destroy(),a.destroy()},element:e,getUser:g,setAnnotatingEnabled:m,setAnnotatingMode:S,setFilter:h,setStyle:u.setStyle.bind(u),redraw:u.redraw.bind(u),setUser:d,setSelected:R,setPresenceProvider:x,setVisible:u.setVisible.bind(u),on:l.on,off:l.off,scrollIntoView:yt(e,r),state:o}};L.DEFAULT_SELECTED_STYLE=pe,L.DEFAULT_STYLE=J,L.NOT_ANNOTATABLE_CLASS=se,L.NOT_ANNOTATABLE_SELECTOR=re,L.Origin=I,L.UserSelectAction=$e,L.W3CTextFormat=go,L.cancelSingleClickEvents=ot,L.cloneKeyboardEvent=he,L.clonePointerEvent=Le,L.createBaseRenderer=ke,L.createBody=xn,L.createCanvasRenderer=xt,L.createHighlightsRenderer=Vt,L.createPresencePainter=Ft,L.createRenderer=Dt,L.createSelectionHandler=an,L.createSpansRenderer=Xt,L.createTextAnnotator=Po,L.createTextAnnotatorState=qt,L.debounce=Re,L.fillDefaults=ln,L.getBackgroundColor=Yt,L.getHighlightClientRects=st,L.getQuoteContext=lt,L.getRangeAnnotatableContents=Oe,L.getViewportBounds=St,L.isMac=Pe,L.isNodeWhitespaceOrEmpty=un,L.isNotAnnotatable=ae,L.isRangeAnnotatable=Ye,L.isRangeWhitespaceOrEmpty=ct,L.isRevived=Q,L.mergeClientRects=dt,L.mergeRanges=ut,L.paint=Kt,L.parseW3CTextAnnotation=$t,L.programmaticallyFocusable=it,L.rangeToSelector=ft,L.reviveAnnotation=Be,L.reviveSelector=Xe,L.reviveTarget=ge,L.scrollIntoView=yt,L.serializeW3CTextAnnotation=jt,L.splitAnnotatableRanges=rt,L.toDomRectList=gn,L.toParentBounds=ht,L.toViewportBounds=pn,L.trackViewport=Ct,L.trimRangeToContainer=gt,L.whitespaceOrEmptyRegex=Ke,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(L,K){typeof exports=="object"&&typeof module<"u"?K(exports):typeof define=="function"&&define.amd?define(["exports"],K):(L=typeof globalThis<"u"?globalThis:L||self,K(L.RecogitoJS={}))})(this,(function(L){"use strict";const K=[];for(let e=0;e<256;++e)K.push((e+256).toString(16).slice(1));function an(e,t=0){return(K[e[t+0]]+K[e[t+1]]+K[e[t+2]]+K[e[t+3]]+"-"+K[e[t+4]]+K[e[t+5]]+"-"+K[e[t+6]]+K[e[t+7]]+"-"+K[e[t+8]]+K[e[t+9]]+"-"+K[e[t+10]]+K[e[t+11]]+K[e[t+12]]+K[e[t+13]]+K[e[t+14]]+K[e[t+15]]).toLowerCase()}const ln=new Uint8Array(16);function cn(){return crypto.getRandomValues(ln)}function it(e,t,n){return crypto.randomUUID?crypto.randomUUID():dn(e)}function dn(e,t,n){e=e||{};const o=e.random??e.rng?.()??cn();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,an(o)}const De=typeof navigator<"u"&&navigator.platform.startsWith("Mac"),Ye="not-annotatable",se=`.${Ye}`,re=(e,t)=>e.contains(t)?!!(t instanceof HTMLElement?t.closest(se):t.parentElement?.closest(se)):!0,Ve=(e,t)=>{const n=t.commonAncestorContainer;return!re(e,n)},Ke=/^\s*$/,st=e=>Ke.test(e.toString()),un=e=>Ke.test(e.textContent||""),rt=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]},at=e=>{(!e.hasAttribute("tabindex")||e.tabIndex<-1)&&e.setAttribute("tabindex","-1"),e.classList.add("no-focus-outline")},fn=function*(e){const t=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT,o=>o instanceof HTMLElement&&o.classList.contains(Ye)&&!o.parentElement.closest(se)&&e.intersectsNode(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);let n;for(;n=t.nextNode();)n instanceof HTMLElement&&(yield n)},lt=(e,t)=>{if(!Ve(e,t))return[];const n=[];let o=null;for(const i of fn(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]},Te=e=>{const t=e.cloneContents();return t.querySelectorAll(se).forEach(n=>n.remove()),t},ct=(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},dt=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ut=(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=Te(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=Te(a).textContent,c=[...dt.segment(r)],h=[...dt.segment(l)];return{prefix:c.slice(-n).map(f=>f.segment).join(""),suffix:h.slice(0,n).map(f=>f.segment).join("")}},ft=(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=Te(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}},Q=e=>e.every(t=>t.range instanceof Range&&!t.range.collapsed),Xe=(e,t)=>{const{start:n,end:o}=e,i=e.offsetReference||t,s=document.createNodeIterator(t,NodeFilter.SHOW_TEXT,h=>h.parentElement?.closest(se)?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 c=!i;for(;l!==null;){if(c||=typeof i?.contains=="function"?i.contains(l):!1,c){const h=l.textContent?.length||0;if(r+h>n){a.setStart(l,n-r);break}r+=h}l=s.nextNode()}for(;l!==null;){const h=l.textContent?.length||0;if(r+h>=o){a.setEnd(l,o-r);break}r+=h,l=s.nextNode()}return{...e,range:a}},fe=(e,t)=>Q(e.selector)?e:{...e,selector:e.selector.map(n=>n.range instanceof Range&&!n.range.collapsed?n:Xe(n,t))},xe=(e,t)=>Q(e.target.selector)?e:{...e,target:fe(e.target,t)},ht=e=>{if(!e)return document.scrollingElement;const{overflowY:t}=window.getComputedStyle(e);return t!=="visible"&&t!=="hidden"&&e.scrollHeight>e.clientHeight?e:ht(e.parentElement)},gt=(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),c=r.top-o.top,h=r.left-o.left,f=n.parentElement?n.scrollTop:0,A=n.parentElement?n.scrollLeft:0,g=c+f-(i-l)/2,u=h+A-(s-a)/2;n.scroll({top:g,left:u,behavior:"smooth"})},pt=(e,t)=>(n,o)=>{const i=typeof n=="string"?n:n.id,s=o?typeof o=="string"?document.getElementById(o):o:ht(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 gt(t,r.target,s),!0;const l=fe(r.target,e),{range:c}=l.selector[0];return c&&!c.collapsed?(gt(t,l,s),!0):!1};var mt=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(mt.call(e,n)&&++o&&!mt.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 hn=Symbol("clean");let q=[],oe=0;const Le=4,gn=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),Pe=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+Le;s<q.length;)q[s]===o?q.splice(s,Le):s+=Le;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){gn.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+=Le)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[hn]=()=>{t=[],n.lc=0,n.off()}),n},pn=e=>{const t=Pe(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 $e=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))($e||{});const He={selected:[]},mn=(e,t,n)=>{const o=Pe(He);let i=t;const s=()=>{ae(o.get(),He)||o.set(He)},r=()=>{var g;return((g=o.get().selected)==null?void 0:g.length)===0},a=g=>{if(r())return!1;const u=typeof g=="string"?g:g.id;return o.get().selected.some(y=>y.id===u)},l=(g,u)=>{let y;if(Array.isArray(g)){if(y=g.map(p=>e.getAnnotation(p)).filter(Boolean),y.length<g.length){console.warn("Invalid selection: "+g.filter(p=>!y.some(d=>d.id===p)));return}}else{const p=e.getAnnotation(g);if(!p){console.warn("Invalid selection: "+g);return}y=[p]}const C=y.reduce((p,d)=>{const S=A(d);return S==="EDIT"?[...p,{id:d.id,editable:!0}]:S==="SELECT"?[...p,{id:d.id}]:p},[]);o.set({selected:C,event:u})},c=(g,u)=>{const y=Array.isArray(g)?g:[g],C=y.map(p=>e.getAnnotation(p)).filter(p=>!!p);o.set({selected:C.map(p=>{const d=u===void 0?A(p)==="EDIT":u;return{id:p.id,editable:d}})}),C.length!==y.length&&console.warn("Invalid selection",g)},h=g=>{if(r())return!1;const{selected:u}=o.get();u.some(({id:y})=>g.includes(y))&&o.set({selected:u.filter(({id:y})=>!g.includes(y))})},f=g=>{i=g,c(o.get().selected.map(({id:u})=>u))},A=g=>yn(g,i,n);return e.observe(({changes:g})=>h((g.deleted||[]).map(u=>u.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:A,isEmpty:r,isSelected:a,setSelected:c,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:l}},yn=(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 bn(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 An=new Uint8Array(16);function wn(){return crypto.getRandomValues(An)}function yt(e,t,n){return crypto.randomUUID?crypto.randomUUID():En(e)}function En(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??wn();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,bn(i)}const je=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)}},vn=(e,t,n,o)=>({id:yt(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Sn=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Cn=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Tn=(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})),xn=(e,t)=>!ae(e.target,t.target),bt=(e,t)=>{const n=Sn(e,t),o=Cn(e,t),i=Tn(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:xn(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var _=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(_||{});const Ln=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>l&&l.length>0;if(!(a(i.created)||a(i.deleted))){const l=(n=i.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),c=(o=i.updated)==null?void 0:o.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!c||r==="TARGET_ONLY"&&c&&!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},On=(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:A})=>A.id===f.id).newValue:f),...t.created||[]],c=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],h=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:A,newValue:g}=f;if(r.has(g.id)){const u=t.updated.find(y=>y.oldValue.id===g.id).newValue;return bt(A,u)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!a.has(f.id))];return{created:l,deleted:c,updated:h}},Oe=e=>{const t=e.id===void 0?yt():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},Rn=e=>e.id!==void 0,Mn=()=>{const e=new Map,t=new Map,n=[],o=(m,b={})=>{n.push({onChange:m,options:b})},i=m=>{const b=n.findIndex(w=>w.onChange==m);b>-1&&n.splice(b,1)},s=(m,b)=>{const w={origin:m,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(x=>{Ln(x,w)&&x.onChange(w)})},r=(m,b=_.LOCAL)=>{if(m.id&&e.get(m.id))throw Error(`Cannot add annotation ${m.id} - exists already`);{const w=Oe(m);e.set(w.id,w),w.bodies.forEach(x=>t.set(x.id,w.id)),s(b,{created:[w]})}},a=(m,b)=>{const w=Oe(typeof m=="string"?b:m),x=typeof m=="string"?m:m.id,U=x&&e.get(x);if(U){const I=bt(U,w);return x===w.id?e.set(x,w):(e.delete(x),e.set(w.id,w)),U.bodies.forEach(v=>t.delete(v.id)),w.bodies.forEach(v=>t.set(v.id,w.id)),I}else console.warn(`Cannot update annotation ${x} - does not exist`)},l=(m,b=_.LOCAL,w=_.LOCAL)=>{const x=Rn(b)?w:b,U=a(m,b);U&&s(x,{updated:[U]})},c=(m,b=_.LOCAL)=>{e.get(m.id)?l(m,b):r(m,b)},h=(m,b=_.LOCAL)=>{const w=m.reduce((x,U)=>{const I=a(U);return I?[...x,I]:x},[]);w.length>0&&s(b,{updated:w})},f=(m,b=_.LOCAL)=>{const w=m.map(Oe),{toAdd:x,toUpdate:U}=w.reduce((v,O)=>e.get(O.id)?{...v,toUpdate:[...v.toUpdate,O]}:{...v,toAdd:[...v.toAdd,O]},{toAdd:[],toUpdate:[]}),I=U.map(v=>a(v,b)).filter(Boolean);x.forEach(v=>{e.set(v.id,v),v.bodies.forEach(O=>t.set(O.id,v.id))}),s(b,{created:x,updated:I})},A=(m,b=_.LOCAL)=>{const w=e.get(m.annotation);if(w){const x={...w,bodies:[...w.bodies,m]};e.set(w.id,x),t.set(m.id,x.id),s(b,{updated:[{oldValue:w,newValue:x,bodiesCreated:[m]}]})}else console.warn(`Attempt to add body to missing annotation: ${m.annotation}`)},g=()=>[...e.values()],u=(m=_.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(m,{deleted:b})},y=(m,b=!0,w=_.LOCAL)=>{const x=m.map(Oe);if(b){const U=[...e.values()];e.clear(),t.clear(),x.forEach(I=>{e.set(I.id,I),I.bodies.forEach(v=>t.set(v.id,I.id))}),s(w,{created:x,deleted:U})}else{const U=m.reduce((I,v)=>{const O=v.id&&e.get(v.id);return O?[...I,O]:I},[]);if(U.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${U.map(I=>I.id).join(", ")}`);x.forEach(I=>{e.set(I.id,I),I.bodies.forEach(v=>t.set(v.id,I.id))}),s(w,{created:x})}},C=m=>{const b=typeof m=="string"?m:m.id,w=e.get(b);if(w)return e.delete(b),w.bodies.forEach(x=>t.delete(x.id)),w;console.warn(`Attempt to delete missing annotation: ${b}`)},p=(m,b=_.LOCAL)=>{const w=C(m);w&&s(b,{deleted:[w]})},d=(m,b=_.LOCAL)=>{const w=m.reduce((x,U)=>{const I=C(U);return I?[...x,I]:x},[]);w.length>0&&s(b,{deleted:w})},S=m=>{const b=e.get(m.annotation);if(b){const w=b.bodies.find(x=>x.id===m.id);if(w){t.delete(w.id);const x={...b,bodies:b.bodies.filter(U=>U.id!==m.id)};return e.set(b.id,x),{oldValue:b,newValue:x,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${m.annotation}`)},M=(m,b=_.LOCAL)=>{const w=S(m);w&&s(b,{updated:[w]})},E=(m,b=_.LOCAL)=>{const w=m.map(x=>S(x)).filter(Boolean);w.length>0&&s(b,{updated:w})},T=m=>{const b=e.get(m);return b?{...b}:void 0},N=m=>{const b=t.get(m);if(b){const w=T(b).bodies.find(x=>x.id===m);if(w)return w;console.error(`Store integrity error: body ${m} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${m}`)},k=(m,b)=>{if(m.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=e.get(m.annotation);if(w){const x=w.bodies.find(I=>I.id===m.id),U={...w,bodies:w.bodies.map(I=>I.id===x.id?b:I)};return e.set(w.id,U),x.id!==b.id&&(t.delete(x.id),t.set(b.id,U.id)),{oldValue:w,newValue:U,bodiesUpdated:[{oldBody:x,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${m.annotation}`)},D=(m,b,w=_.LOCAL)=>{const x=k(m,b);x&&s(w,{updated:[x]})},R=(m,b=_.LOCAL)=>{const w=m.map(x=>k({id:x.id,annotation:x.annotation},x)).filter(Boolean);s(b,{updated:w})},B=m=>{const b=e.get(m.annotation);if(b){const w={...b,target:{...b.target,...m}};return e.set(b.id,w),{oldValue:b,newValue:w,targetUpdated:{oldTarget:b.target,newTarget:m}}}else console.warn(`Attempt to update target on missing annotation: ${m.annotation}`)};return{addAnnotation:r,addBody:A,all:g,bulkAddAnnotations:y,bulkDeleteAnnotations:d,bulkDeleteBodies:E,bulkUpdateAnnotations:h,bulkUpdateBodies:R,bulkUpdateTargets:(m,b=_.LOCAL)=>{const w=m.map(x=>B(x)).filter(Boolean);w.length>0&&s(b,{updated:w})},bulkUpsertAnnotations:f,clear:u,deleteAnnotation:p,deleteBody:M,getAnnotation:T,getBody:N,observe:o,unobserve:i,updateAnnotation:l,updateBody:D,updateTarget:(m,b=_.LOCAL)=>{const w=B(m);w&&s(b,{updated:[w]})},upsertAnnotation:c}};let Bn=()=>({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 Nn=250,kn=(e,t)=>{const n=Bn(),o=[];let i=-1,s=!1,r=0;const a=u=>{if(!s){const{changes:y}=u,C=performance.now();if(C-r>Nn)o.splice(i+1),o.push(y),i=o.length-1;else{const p=o.length-1;o[p]=On(o[p],y)}r=C}s=!1};e.observe(a,{origin:_.LOCAL});const l=u=>u&&u.length>0&&e.bulkDeleteAnnotations(u),c=u=>u&&u.length>0&&e.bulkAddAnnotations(u,!1),h=u=>u&&u.length>0&&e.bulkUpdateAnnotations(u.map(({oldValue:y})=>y)),f=u=>u&&u.length>0&&e.bulkUpdateAnnotations(u.map(({newValue:y})=>y)),A=u=>u&&u.length>0&&e.bulkAddAnnotations(u,!1),g=u=>u&&u.length>0&&e.bulkDeleteAnnotations(u);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...o],pointer:i}),on:(u,y)=>n.on(u,y),redo:()=>{if(o.length-1>i){s=!0;const{created:u,updated:y,deleted:C}=o[i+1];c(u),f(y),g(C),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:u,updated:y,deleted:C}=o[i];l(u),h(y),A(C),n.emit("undo",o[i]),i-=1}}}},_n=()=>{const e=Pe([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},In=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:a}=e,l=new Map;let c=[],h;const f=(y,C)=>{l.has(y)?l.get(y).push(C):l.set(y,[C])},A=(y,C)=>{const p=l.get(y);if(p){const d=p.indexOf(C);d!==-1&&p.splice(d,1)}},g=(y,C,p)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(d=>{if(n){const S=Array.isArray(C)?C.map(E=>n.serialize(E)):n.serialize(C),M=p?p instanceof PointerEvent?p:n.serialize(p):void 0;d(S,M)}else d(C,p)})},1)};s.subscribe(({selected:y})=>{if(!(c.length===0&&y.length===0)){if(c.length===0&&y.length>0)c=y.map(({id:C})=>r.getAnnotation(C));else if(c.length>0&&y.length===0)c.forEach(C=>{const p=r.getAnnotation(C.id);p&&!ae(p,C)&&g("updateAnnotation",p,C)}),c=[];else{const C=new Set(c.map(d=>d.id)),p=new Set(y.map(({id:d})=>d));c.filter(d=>!p.has(d.id)).forEach(d=>{const S=r.getAnnotation(d.id);S&&!ae(S,d)&&g("updateAnnotation",S,d)}),c=[...c.filter(d=>p.has(d.id)),...y.filter(({id:d})=>!C.has(d)).map(({id:d})=>r.getAnnotation(d))]}g("selectionChanged",c)}}),i.subscribe(y=>{!h&&y?g("mouseEnterAnnotation",r.getAnnotation(y)):h&&!y?g("mouseLeaveAnnotation",r.getAnnotation(h)):h&&y&&(g("mouseLeaveAnnotation",r.getAnnotation(h)),g("mouseEnterAnnotation",r.getAnnotation(y))),h=y}),a?.subscribe(y=>g("viewportIntersect",y.map(C=>r.getAnnotation(C)))),r.observe(y=>{const{created:C,deleted:p}=y.changes;(C||[]).forEach(d=>g("createAnnotation",d)),(p||[]).forEach(d=>g("deleteAnnotation",d)),(y.changes.updated||[]).filter(d=>[...d.bodiesCreated||[],...d.bodiesDeleted||[],...d.bodiesUpdated||[]].length>0).forEach(({oldValue:d,newValue:S})=>{const M=c.find(E=>E.id===d.id)||d;c=c.map(E=>E.id===d.id?S:E),g("updateAnnotation",S,M)})},{origin:_.LOCAL}),r.observe(y=>{if(c){const C=new Set(c.map(d=>d.id)),p=(y.changes.updated||[]).filter(({newValue:d})=>C.has(d.id)).map(({newValue:d})=>d);p.length>0&&(c=c.map(d=>p.find(M=>M.id===d.id)||d))}},{origin:_.REMOTE});const u=y=>C=>{const{updated:p}=C;y?(p||[]).forEach(d=>g("updateAnnotation",d.oldValue,d.newValue)):(p||[]).forEach(d=>g("updateAnnotation",d.newValue,d.oldValue))};return t.on("undo",u(!0)),t.on("redo",u(!1)),{on:f,off:A,emit:g}},Un=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:[]}),Dn=(e,t,n)=>{const{store:o,selection:i}=e,s=p=>{if(n){const{parsed:d,error:S}=n.parse(p);d?o.addAnnotation(d,_.REMOTE):console.error(S)}else o.addAnnotation(je(p),_.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=p=>{const d=o.getAnnotation(p);return n&&d?n.serialize(d):d},c=()=>n?o.all().map(n.serialize):o.all(),h=()=>{var p;const d=(((p=i.selected)==null?void 0:p.map(S=>S.id))||[]).map(S=>o.getAnnotation(S)).filter(Boolean);return n?d.map(n.serialize):d},f=(p,d=!0)=>fetch(p).then(S=>S.json()).then(S=>(g(S,d),S)),A=p=>{if(typeof p=="string"){const d=o.getAnnotation(p);if(o.deleteAnnotation(p),d)return n?n.serialize(d):d}else{const d=n?n.parse(p).parsed:p;if(d)return o.deleteAnnotation(d),p}},g=(p,d=!0)=>{if(n){const S=n.parseAll||Un(n),{parsed:M,failed:E}=S(p);E.length>0&&console.warn(`Discarded ${E.length} invalid annotations`,E),o.bulkAddAnnotations(M,d,_.REMOTE)}else o.bulkAddAnnotations(p.map(je),d,_.REMOTE)},u=(p,d)=>{p?i.setSelected(p,d):i.clear()},y=p=>{i.setUserSelectAction(p)},C=p=>{if(n){const d=n.parse(p).parsed,S=n.serialize(o.getAnnotation(d.id));return o.updateAnnotation(d),S}else{const d=o.getAnnotation(p.id);return o.updateAnnotation(je(p)),d}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:c,getHistory:t.getHistory,getSelected:h,loadAnnotations:f,redo:t.redo,removeAnnotation:A,setAnnotations:g,setSelected:u,setUserSelectAction:y,undo:t.undo,updateAnnotation:C}};let Yn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",Vn=e=>crypto.getRandomValues(new Uint8Array(e)),Kn=(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),c=r;for(;c--;)if(a+=e[l[c]&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}}},Xn=(e,t=21)=>Kn(e,t|0,Vn),Pn=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Yn[n[e]&63];return t};const $n=()=>({isGuest:!0,id:Xn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Hn=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}`},At=e=>e?typeof e=="object"?{...e}:e:void 0,jn=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,modified:l,creator:c,...h}=n;return{id:o||`temp-${Hn(n)}`,annotation:t,type:i,purpose:s,value:r,creator:At(c),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...h}}),Fn=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});Pn();const zn=(e,t)=>({parse:n=>wt(n),serialize:n=>Et(n,e,t)}),Wn=e=>e.quote!==void 0&&e.start!==void 0&&e.end!==void 0,qn=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:At(n),created:o?new Date(o):void 0,updated:i?new Date(i):void 0,annotation:t,selector:[],styleClass:"styleClass"in r[0]?r[0].styleClass:void 0};for(const l of r){const h=(Array.isArray(l.selector)?l.selector:[l.selector]).reduce((f,A)=>{switch(A.type){case"TextQuoteSelector":f.quote=A.exact;break;case"TextPositionSelector":f.start=A.start,f.end=A.end;break}return f},{});if(Wn(h))a.selector.push({...h,id:l.id,scope:l.scope});else{const f=[h.start?void 0:"TextPositionSelector",h.quote?void 0:"TextQuoteSelector"].filter(Boolean);return{error:Error(`Missing selector types: ${f.join(" and ")} for annotation: ${e.id}`)}}}return{parsed:a}},wt=e=>{const t=e.id||it(),{creator:n,created:o,modified:i,body:s,...r}=e,a=jn(s,t),l=qn(e);return"error"in l?{error:l.error}:{parsed:{...r,id:t,bodies:a,target:l.parsed}}},Et=(e,t,n)=>{const{bodies:o,target:i,...s}=e,{selector:r,creator:a,created:l,updated:c,...h}=i,f=r.map(A=>{const{id:g,quote:u,start:y,end:C,range:p}=A,d={type:"TextQuoteSelector",exact:u};if(n){const{prefix:M,suffix:E}=ut(p,n);d.prefix=M,d.suffix=E}const S={type:"TextPositionSelector",start:y,end:C};return{...h,id:g,scope:"scope"in A?A.scope:void 0,source:t,selector:[d,S]}});return{...s,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Fn(e.bodies),creator:a,created:l?.toISOString(),modified:c?.toISOString(),target:f}};let vt=()=>({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 St=e=>e.addEventListener("click",t=>{!t.target.closest(se)&&!t.target.closest("a")&&t.preventDefault()}),Re=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}),he=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)})},Fe=(e,t,n,o)=>{const{store:i,selection:s,hover:r}=n,a=vt();let l;const c=new Map;let h;const f=$t(o),A=R=>{const{x:B,y:m}=t.getBoundingClientRect(),b=i.getAt(R.clientX-B,R.clientY-m,!1,h);b&&n.selection.evalSelectAction(b)!==$e.NONE?r.current!==b.id&&(t.classList.add("hovered"),r.set(b.id)):r.current&&(t.classList.remove("hovered"),r.set(null))};t.addEventListener("pointermove",A);const g=Me((R=!1)=>requestAnimationFrame(()=>{const B=Pt(t),{minX:m,minY:b,maxX:w,maxY:x}=B,U=h?i.getIntersecting(m,b,w,x).filter(({annotation:O})=>h(O)):i.getIntersecting(m,b,w,x),I=s.selected.map(({id:O})=>O),v=U.map(({annotation:O,rects:j})=>{const le=I.includes(O.id),J=O.id===r.current;return{annotation:O,rects:j,state:{selected:le,hovered:J}}});e.redraw(v,B,l,c,R),setTimeout(()=>{f(U.map(({annotation:O})=>O)),a.emit("onRedraw")},1)}),10),u=(R,B)=>{B?R?c.set(B,R):c.delete(B):l=R,g(!0)},y=R=>{h=R,g(!1)},C=(R,B)=>a.on(R,B),p=()=>{g()};i.observe(p);const d=s.subscribe(()=>{g()}),S=r.subscribe(()=>{g()}),M=()=>{g(!0)};document.addEventListener("scroll",M,{capture:!0,passive:!0});const E=Me(()=>{i.recalculatePositions(),g()},10);window.addEventListener("resize",E);const T=new ResizeObserver(E);T.observe(t);const N={attributes:!0,childList:!0,subtree:!0},k=new MutationObserver(Me(R=>{R.every(m=>m.target===t||t.contains(m.target))||g(!0)},150));return k.observe(document.body,N),{destroy:()=>{t.removeEventListener("pointermove",A),e.destroy(),i.unobserve(p),d(),S(),document.removeEventListener("scroll",M),window.removeEventListener("resize",E),T.disconnect(),k.disconnect()},on:C,redraw:g,setStyle:u,setFilter:y,setVisible:e.setVisible.bind(e)}};var Gn={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},F=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},Ct=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},Tt=function(e){return{r:F(e.r,0,255),g:F(e.g,0,255),b:F(e.b,0,255),a:F(e.a)}},ze=function(e){return{r:X(e.r),g:X(e.g),b:X(e.b),a:X(e.a,3)}},Qn=/^#([0-9a-f]{3,8})$/i,Be=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},xt=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}},Lt=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),c=s%6;return{r:255*[o,a,r,r,l,o][c],g:255*[l,o,o,a,r,r][c],b:255*[r,r,l,o,o,a][c],a:i}},Ot=function(e){return{h:Ct(e.h),s:F(e.s,0,100),l:F(e.l,0,100),a:F(e.a)}},Rt=function(e){return{h:X(e.h),s:X(e.s),l:X(e.l),a:X(e.a,3)}},Mt=function(e){return Lt((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},ge=function(e){return{h:(t=xt(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},Jn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Zn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,eo=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,to=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Bt={string:[[function(e){var t=Qn.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=eo.exec(e)||to.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Tt({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=Jn.exec(e)||Zn.exec(e);if(!t)return null;var n,o,i=Ot({h:(n=t[1],o=t[2],o===void 0&&(o="deg"),Number(n)*(Gn[o]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return Mt(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)?Tt({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=Ot({h:Number(t),s:Number(n),l:Number(o),a:Number(s)});return Mt(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:Ct(a.h),s:F(a.s,0,100),v:F(a.v,0,100),a:F(a.a)}})({h:Number(t),s:Number(n),v:Number(o),a:Number(s)});return Lt(r)},"hsv"]]},Nt=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]},no=function(e){return typeof e=="string"?Nt(e.trim(),Bt.string):typeof e=="object"&&e!==null?Nt(e,Bt.object):[null,void 0]},We=function(e,t){var n=ge(e);return{h:n.h,s:F(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},kt=function(e,t){var n=ge(e);return{h:n.h,s:n.s,l:F(n.l+100*t,0,100),a:n.a}},_t=(function(){function e(t){this.parsed=no(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=ze(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 ze(this.rgba)},e.prototype.toRgbString=function(){return t=ze(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 Rt(ge(this.rgba))},e.prototype.toHslString=function(){return t=Rt(ge(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=xt(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(We(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),z(We(this.rgba,-t))},e.prototype.grayscale=function(){return z(We(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),z(kt(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),z(kt(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=ge(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 _t?e:new _t(e)};const te={fill:"rgb(0, 128, 255)",fillOpacity:.18},Ne={fill:"rgb(0, 128, 255)",fillOpacity:.45},It=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(),Ge=(e,t,n)=>t?typeof t=="function"?t(e.annotation,e.state,n)||(e.state?.selected?Ne:te):t:e.state?.selected?Ne:te;var Ut=Object.prototype.hasOwnProperty;function Qe(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--&&Qe(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Ut.call(e,n)&&++o&&!Ut.call(t,n)||!(n in t)||!Qe(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Dt=(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))},Yt=e=>{const t=[],n=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_TEXT);let o;for(;o=n.nextNode();)e.intersectsNode(o)&&t.push(o);if(t.length<2)return Array.from(e.getClientRects());{const i=t[0],s=t[t.length-1],r=document.createRange();if(r.selectNode(i),e.startContainer.nodeType===Node.TEXT_NODE)r.setStart(i,e.startOffset);else{const c=e.startContainer.childNodes[e.startOffset];c?r.setStartBefore(c):r.setStartAfter(e.startContainer)}const a=document.createRange();if(a.selectNode(s),e.endContainer.nodeType===Node.TEXT_NODE)a.setEnd(s,e.endOffset);else{const c=e.endContainer.childNodes[e.endOffset];c?a.setEndBefore(c):a.setEndAfter(e.endContainer)}const l=c=>{const h=document.createRange();return h.selectNode(c),Array.from(h.getClientRects())};return[...Array.from(r.getClientRects()),...t.slice(1,-1).flatMap(l),...Array.from(a.getClientRects())]}},oo=(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"},io=(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)},Vt=(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=oo(i,a,t,n);if(l==="inline-adjacent"){s=s.map(c=>c===a?io(i,a):c),r=!0;break}else if(l==="inline-contains"){s=s.map(c=>c===a?i:c),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(c=>c===a?i:c)),i.width===a.width&&i.height<a.width&&(s=s.map(c=>c===a?i:c)),r=!0;break}}return r?s:[...s,i]},[]),so=e=>({length:e.length,item:t=>e[t],[Symbol.iterator]:function*(){for(let t=0;t<this.length;t++)yield this.item(t)}}),Kt=(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)},ro=(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)},ao=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,c,h)=>{if(!(!Qe(n,r)||h))return;t.innerHTML="",[...r].sort((u,y)=>{const{annotation:{target:{created:C}}}=u,{annotation:{target:{created:p}}}=y;return C&&p?C.getTime()-p.getTime():0}).forEach(u=>{const y=c.get(u.annotation.id)||l;u.rects.map(C=>{const p=Dt(C,r),d=Ge(u,y,p),S=document.createElement("span");S.className="r6o-annotation",S.dataset.annotation=u.annotation.id,S.style.left=`${C.x}px`,S.style.top=`${C.y}px`,S.style.width=`${C.width}px`,S.style.height=`${C.height}px`,S.style.backgroundColor=It(d),d.underlineStyle&&(S.style.borderStyle=d.underlineStyle),d.underlineColor&&(S.style.borderColor=d.underlineColor),d.underlineThickness&&(S.style.borderBottomWidth=`${d.underlineThickness}px`),d.underlineOffset&&(S.style.paddingBottom=`${d.underlineOffset}px`),t.appendChild(S)})}),n=r},setVisible:r=>{r?t.classList.remove("hidden"):t.classList.add("hidden")}}},Xt=(e,t,n)=>Fe(ao(e),e,t,n),Pt=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}},$t=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 Ht(e,t,n=0,o=e.length-1,i=lo){for(;o>n;){if(o-n>600){const l=o-n+1,c=t-n+1,h=Math.log(l),f=.5*Math.exp(2*h/3),A=.5*Math.sqrt(h*f*(l-f)/l)*(c-l/2<0?-1:1),g=Math.max(n,Math.floor(t-c*f/l+A)),u=Math.min(o,Math.floor(t+(l-c)*f/l+A));Ht(e,t,g,u,i)}const s=e[t];let r=n,a=o;for(pe(e,n,t),i(e[o],s)>0&&pe(e,n,o);r<a;){for(pe(e,r,a),r++,a--;i(e[r],s)<0;)r++;for(;i(e[a],s)>0;)a--}i(e[n],s)===0?pe(e,n,a):(a++,pe(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function pe(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function lo(e,t){return e<t?-1:e>t?1:0}class co{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(!_e(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;_e(t,l)&&(n.leaf?o.push(a):Ze(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!_e(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(_e(t,r)){if(n.leaf||Ze(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,c;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],a=r.pop(),c=!0),o.leaf){const h=uo(t,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!c&&!o.leaf&&Ze(o,i)?(s.push(o),r.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],c=!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),c=l*Math.ceil(Math.sqrt(r));jt(t,n,o,c,this.compareMinX);for(let h=n;h<=o;h+=c){const f=Math.min(h+c-1,o);jt(t,h,f,l,this.compareMinY);for(let A=h;A<=f;A+=l){const g=Math.min(A+l-1,f);a.children.push(this._build(t,A,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 c=n.children[l],h=Je(c),f=go(t,c)-h;f<r?(r=f,s=h<s?h:s,a=c):f===r&&h<s&&(s=h,a=c)}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),ye(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=me(t,0,a,this.toBBox),c=me(t,a,o,this.toBBox),h=po(l,c),f=Je(l)+Je(c);h<s?(s=h,i=a,r=f<r?f:r):h===s&&f<r&&(r=f,i=a)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:fo,s=t.leaf?this.compareMinY:ho,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=me(t,0,n,s),a=me(t,o-n,o,s);let l=ke(r)+ke(a);for(let c=n;c<o-n;c++){const h=t.children[c];ye(r,t.leaf?s(h):h),l+=ke(r)}for(let c=o-n-1;c>=n;c--){const h=t.children[c];ye(a,t.leaf?s(h):h),l+=ke(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)ye(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 uo(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){me(e,0,e.children.length,t,e)}function me(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];ye(i,e.leaf?o(r):r)}return i}function ye(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 fo(e,t){return e.minX-t.minX}function ho(e,t){return e.minY-t.minY}function Je(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ke(e){return e.maxX-e.minX+(e.maxY-e.minY)}function go(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 po(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 Ze(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function _e(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 jt(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;Ht(e,r,t,n,i),s.push(t,r,r,n)}}const mo=(e,t,n,o)=>{const i=new co,s=new Map,r=vt(),a=(E,T)=>{const N=E.selector.flatMap(D=>{const R=Q([D])?D.range:Xe(D,t).range;return Yt(R)}),k=Vt(N,n,o).map(D=>Kt(D,T));return k.map(D=>{const{x:R,y:B,width:m,height:b}=D;return{minX:R,minY:B,maxX:R+m,maxY:B+b,annotation:{id:E.annotation,rects:k}}})},l=()=>[...s.values()],c=()=>{i.clear(),s.clear()},h=E=>{const T=a(E,t.getBoundingClientRect());T.length!==0&&(T.forEach(N=>i.insert(N)),s.set(E.annotation,T))},f=E=>{const T=s.get(E.annotation);T&&(T.forEach(N=>i.remove(N)),s.delete(E.annotation))},A=E=>{f(E),h(E)},g=(E,T=!0)=>{T&&c();const N=t.getBoundingClientRect(),k=E.map(R=>({target:R,rects:a(R,N)}));k.forEach(({target:R,rects:B})=>{B.length>0&&s.set(R.annotation,B)});const D=k.flatMap(({rects:R})=>R);i.load(D)},u=(E,T,N=!1)=>{const k=i.search({minX:E,minY:T,maxX:E,maxY:T}),D=R=>R.annotation.rects.reduce((B,m)=>B+m.width*m.height,0);return k.length>0?(k.sort((R,B)=>D(R)-D(B)),N?k.map(R=>R.annotation.id):[k[0].annotation.id]):[]},y=E=>{const T=C(E);if(T.length===0)return;let N=T[0].left,k=T[0].top,D=T[0].right,R=T[0].bottom;for(let B=1;B<T.length;B++){const m=T[B];N=Math.min(N,m.left),k=Math.min(k,m.top),D=Math.max(D,m.right),R=Math.max(R,m.bottom)}return new DOMRect(N,k,D-N,R-k)},C=E=>{const T=s.get(E);return T?T[0].annotation.rects:[]};return{all:l,clear:c,getAt:u,getAnnotationBounds:y,getAnnotationRects:C,getIntersecting:(E,T,N,k)=>{const D=i.search({minX:E,minY:T,maxX:N,maxY:k}),R=new Set(D.map(B=>B.annotation.id));return Array.from(R).map(B=>({annotation:e.getAnnotation(B),rects:C(B)})).filter(B=>!!B.annotation)},insert:h,recalculate:()=>{g(e.all().map(E=>E.target),!0),r.emit("recalculate")},remove:f,set:g,size:()=>i.all().length,update:A,on:(E,T)=>r.on(E,T)}},Ft=(e,t)=>{const n=Mn(),o=mo(n,e,t.mergeHighlights?.horizontalTolerance,t.mergeHighlights?.verticalTolerance),i=mn(n,t.userSelectAction,t.adapter),s=pn(n),r=_n(),a=(d,S=_.LOCAL)=>{const M=xe(d,e),E=Q(M.target.selector);return E&&n.addAnnotation(M,S),E},l=(d,S=!0,M=_.LOCAL)=>{const E=d.map(N=>xe(N,e)),T=E.filter(N=>!Q(N.target.selector));return n.bulkAddAnnotations(E,S,M),T},c=(d,S=_.LOCAL)=>{const M=d.map(T=>xe(T,e)),E=M.filter(T=>!Q(T.target.selector));return M.forEach(T=>{n.getAnnotation(T.id)?n.updateAnnotation(T,S):n.addAnnotation(T,S)}),E},h=(d,S=_.LOCAL)=>{const M=fe(d,e);n.updateTarget(M,S)},f=(d,S=_.LOCAL)=>{const M=d.map(E=>fe(E,e));n.bulkUpdateTargets(M,S)};function A(d,S,M,E){const T=M||!!E,N=o.getAt(d,S,T).map(D=>n.getAnnotation(D)),k=E?N.filter(E):N;if(k.length!==0)return M?k:k[0]}const g=d=>o.getAnnotationRects(d).length>0?o.getAnnotationBounds(d):void 0,u=(d,S,M,E)=>o.getIntersecting(d,S,M,E),y=d=>o.getAnnotationRects(d),C=()=>o.recalculate(),p=d=>o.on("recalculate",d);return n.observe(({changes:d})=>{const S=(d.deleted||[]).filter(T=>Q(T.target.selector)),M=(d.created||[]).filter(T=>Q(T.target.selector)),E=(d.updated||[]).filter(T=>Q(T.newValue.target.selector));S?.length>0&&S.forEach(T=>o.remove(T.target)),M.length>0&&o.set(M.map(T=>T.target),!1),E?.length>0&&E.forEach(({newValue:T})=>o.update(T.target))}),{store:{...n,addAnnotation:a,bulkAddAnnotations:l,bulkUpdateTargets:f,bulkUpsertAnnotations:c,getAnnotationBounds:g,getAnnotationRects:y,getIntersecting:u,getAt:A,recalculatePositions:C,onRecalculatePositions:p,updateTarget:h},selection:i,hover:s,viewport:r}};function yo(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 c(){const A=i,g=s;return i=void 0,s=void 0,l=e.apply(A,g),l}function h(){const A=Date.now()-a;A<t&&A>=0?r=setTimeout(h,t-A):(r=void 0,o||(l=c()))}const f=function(...A){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=A,a=Date.now();const g=o&&!r;if(r||(r=setTimeout(h,t)),g)return l=c(),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=c(),f.clear()},f}const et=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function tt(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),n)}function be(e,t,n,o){e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent("on".concat(t),n)}function zt(e,t){const n=t.slice(0,t.length-1);for(let o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}function Wt(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 bo(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}const Ae={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,"-":et?173:189,"=":et?61:187,";":et?59:186,"'":222,"{":219,"}":221,"[":219,"]":221,"\\":220},G={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,meta:91,command:91},we={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},H={16:!1,18:!1,17:!1,91:!1},V={};for(let e=1;e<20;e++)Ae["f".concat(e)]=111+e;let Y=[],Ee=null,qt="all";const ne=new Map,ue=e=>Ae[e.toLowerCase()]||G[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),Ao=e=>Object.keys(Ae).find(t=>Ae[t]===e),wo=e=>Object.keys(G).find(t=>G[t]===e);function Gt(e){qt=e||"all"}function ve(){return qt||"all"}function Eo(){return Y.slice(0)}function vo(){return Y.map(e=>Ao(e)||wo(e)||String.fromCharCode(e))}function So(){const e=[];return Object.keys(V).forEach(t=>{V[t].forEach(n=>{let{key:o,scope:i,mods:s,shortcut:r}=n;e.push({scope:i,shortcut:r,mods:s,keys:o.split("+").map(a=>ue(a))})})}),e}function Co(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}function To(e){return typeof e=="string"&&(e=ue(e)),Y.indexOf(e)!==-1}function xo(e,t){let n,o;e||(e=ve());for(const i in V)if(Object.prototype.hasOwnProperty.call(V,i))for(n=V[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(r=>{let{element:a}=r;return nt(a)}):o++;ve()===e&&Gt(t||"all")}function Lo(e){let t=e.keyCode||e.which||e.charCode;e.key&&e.key.toLowerCase()==="capslock"&&(t=ue(e.key));const n=Y.indexOf(t);if(n>=0&&Y.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&Y.splice(0,Y.length),(t===93||t===224)&&(t=91),t in H){H[t]=!1;for(const o in G)G[o]===t&&(W[o]=!1)}}function Qt(e){if(typeof e>"u")Object.keys(V).forEach(i=>{Array.isArray(V[i])&&V[i].forEach(s=>Ie(s)),delete V[i]}),nt(null);else if(Array.isArray(e))e.forEach(i=>{i.key&&Ie(i)});else if(typeof e=="object")e.key&&Ie(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];let[i,s]=n;typeof i=="function"&&(s=i,i=""),Ie({key:e,scope:i,method:s,splitKey:"+"})}}const Ie=e=>{let{key:t,scope:n,method:o,splitKey:i="+"}=e;Wt(t).forEach(r=>{const a=r.split(i),l=a.length,c=a[l-1],h=c==="*"?"*":ue(c);if(!V[h])return;n||(n=ve());const f=l>1?zt(G,a):[],A=[];V[h]=V[h].filter(g=>{const y=(o?g.method===o:!0)&&g.scope===n&&bo(g.mods,f);return y&&A.push(g.element),!y}),A.forEach(g=>nt(g))})};function Jt(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 H)Object.prototype.hasOwnProperty.call(H,s)&&(!H[s]&&t.mods.indexOf(+s)>-1||H[s]&&t.mods.indexOf(+s)===-1)&&(i=!1);(t.mods.length===0&&!H[16]&&!H[18]&&!H[17]&&!H[91]||i||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(Y),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function Zt(e,t){const n=V["*"];let o=e.keyCode||e.which||e.charCode;if(e.key&&e.key.toLowerCase()==="capslock"||!W.filter.call(this,e))return;if((o===93||o===224)&&(o=91),Y.indexOf(o)===-1&&o!==229&&Y.push(o),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=we[a];e[a]&&Y.indexOf(l)===-1?Y.push(l):!e[a]&&Y.indexOf(l)>-1?Y.splice(Y.indexOf(l),1):a==="metaKey"&&e[a]&&(Y=Y.filter(c=>c in we||c===o))}),o in H){H[o]=!0;for(const a in G)if(Object.prototype.hasOwnProperty.call(G,a)){const l=we[G[a]];W[a]=e[l]}if(!n)return}for(const a in H)Object.prototype.hasOwnProperty.call(H,a)&&(H[a]=e[we[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(Y.indexOf(17)===-1&&Y.push(17),Y.indexOf(18)===-1&&Y.push(18),H[17]=!0,H[18]=!0);const i=ve();if(n)for(let a=0;a<n.length;a++)n[a].scope===i&&(e.type==="keydown"&&n[a].keydown||e.type==="keyup"&&n[a].keyup)&&Jt(e,n[a],i,t);if(!(o in V))return;const s=V[o],r=s.length;for(let a=0;a<r;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,h=l.key.split(c),f=[];for(let A=0;A<h.length;A++)f.push(ue(h[A]));f.sort().join("")===Y.sort().join("")&&Jt(e,l,i,t)}}function W(e,t,n){Y=[];const o=Wt(e);let i=[],s="all",r=document,a=0,l=!1,c=!0,h="+",f=!1,A=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(s=t.scope),t.element&&(r=t.element),t.keyup&&(l=t.keyup),t.keydown!==void 0&&(c=t.keydown),t.capture!==void 0&&(f=t.capture),typeof t.splitKey=="string"&&(h=t.splitKey),t.single===!0&&(A=!0)),typeof t=="string"&&(s=t),A&&Qt(e,s);a<o.length;a++)e=o[a].split(h),i=[],e.length>1&&(i=zt(G,e)),e=e[e.length-1],e=e==="*"?"*":ue(e),e in V||(V[e]=[]),V[e].push({keyup:l,keydown:c,scope:s,mods:i,shortcut:o[a],method:n,key:o[a],splitKey:h,element:r});if(typeof r<"u"&&window){if(!ne.has(r)){const g=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return Zt(y,r)},u=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;Zt(y,r),Lo(y)};ne.set(r,{keydownListener:g,keyupListenr:u,capture:f}),tt(r,"keydown",g,f),tt(r,"keyup",u,f)}if(!Ee){const g=()=>{Y=[]};Ee={listener:g,capture:f},tt(window,"focus",g,f)}}}function Oo(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(V).forEach(n=>{V[n].filter(i=>i.scope===t&&i.shortcut===e).forEach(i=>{i&&i.method&&i.method()})})}function nt(e){const t=Object.values(V).flat();if(t.findIndex(o=>{let{element:i}=o;return i===e})<0){const{keydownListener:o,keyupListenr:i,capture:s}=ne.get(e)||{};o&&i&&(be(e,"keyup",i,s),be(e,"keydown",o,s),ne.delete(e))}if((t.length<=0||ne.size<=0)&&(Object.keys(ne).forEach(i=>{const{keydownListener:s,keyupListenr:r,capture:a}=ne.get(i)||{};s&&r&&(be(i,"keyup",r,a),be(i,"keydown",s,a),ne.delete(i))}),ne.clear(),Object.keys(V).forEach(i=>delete V[i]),Ee)){const{listener:i,capture:s}=Ee;be(window,"focus",i,s),Ee=null}}const ot={getPressedKeyString:vo,setScope:Gt,getScope:ve,deleteScope:xo,getPressedKeyCodes:Eo,getAllKeyCodes:So,isPressed:To,filter:Co,trigger:Oo,unbind:Qt,keyMap:Ae,modifier:G,modifierMap:we};for(const e in ot)Object.prototype.hasOwnProperty.call(ot,e)&&(W[e]=ot[e]);if(typeof window<"u"){const e=window.hotkeys;W.noConflict=t=>(t&&window.hotkeys===W&&(window.hotkeys=e),W),window.hotkeys=W}async function Ro(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 en=300,tn=["up","down","left","right"],nn=De?"⌘+a":"ctrl+a",Mo=[...tn.map(e=>`shift+${e}`),nn],on=(e,t,n,o)=>{const{store:i,selection:s}=t;let r;const{annotatingEnabled:a,offsetReferenceSelector:l,selectionMode:c,dismissOnNotAnnotatable:h="NEVER"}=o;let f,A=a,g="CREATE_NEW",u,y,C,p;const d=v=>{A=v,k.clear(),v||(y=void 0,u=void 0,C=void 0,p=void 0)},S=v=>g=v||"CREATE_NEW",M=v=>f=v,E=v=>r=v,T=v=>{if(g==="ADD_TO_CURRENT")return!0;if(o.allowModifierSelect){const O=v;return De?O.metaKey:O.ctrlKey}else return!1},N=()=>{if(!A||C===!1)return;const{selected:v}=s;if((T(p)||g==="REPLACE_CURRENT")&&v.length===1&&v[0].editable){const j=i.getAnnotation(v[0].id);if(j?.target){y=j.target,u={annotation:j.id,selector:[],created:y.created,creator:y.creator,updated:new Date,updatedBy:r};return}}y=void 0,u={annotation:it(),selector:[],created:new Date,creator:r}},k=yo(v=>{if(!A)return;const O=document.getSelection();if(!O?.anchorNode)return;const j=Array.from(Array(O.rangeCount).keys()).map(P=>O.getRangeAt(P));if(j.every(P=>!Ve(e,P))){u=void 0;return}const le=v.timeStamp-(p?.timeStamp||v.timeStamp);if(p?.type==="pointerdown"&&(le<1e3&&!u||O.isCollapsed&&le<en)&&N(),!u&&(N(),!u))return;if(O.isCollapsed){i.getAnnotation(u.annotation)&&!(T(p)||g==="REPLACE_CURRENT")&&(s.clear(),i.deleteAnnotation(u.annotation));return}const J=j.map(P=>ct(P,e));if(J.every(P=>st(P)))return;const Z=J.flatMap(P=>lt(e,P.cloneRange()));if(!(Z.length>0&&!u||Z.length!==u.selector.length||Z.some((P,Se)=>P.toString()!==u.selector[Se]?.quote)))return;const Ue=T(p)&&y?rt([...y.selector.map(P=>P.range),...Z]):Z;u={...u,selector:Ue.map(P=>ft(P,e,l)),updated:new Date},!(T(p)||g==="REPLACE_CURRENT")&&(i.getAnnotation(u.annotation)?i.updateTarget(u,_.LOCAL):s.clear())},10),D=v=>{p=Re(v),C=p.button===0},R=async v=>{if(!C)return;const O=Re(v),j=()=>{const{x:J,y:Z}=e.getBoundingClientRect();if(re(e,O.target)){(typeof h=="function"?h(O,e):h==="ALWAYS")&&s.clear();return}const ie=O.target instanceof Node&&e.contains(O.target)&&i.getAt(O.clientX-J,O.clientY-Z,c==="all",f);if(ie){const{selected:Ue}=s,P=new Set(Ue.map(Ce=>Ce.id)),Se=Array.isArray(ie)?ie.map(Ce=>Ce.id):[ie.id];(P.size!==Se.length||!Se.every(Ce=>P.has(Ce)))&&(n.emit("clickAnnotation",ie),s.userSelect(Se,O))}else s.clear()};if(O.timeStamp-p.timeStamp<en){await B();const J=document.getSelection(),Z=re(e,p.target),ie=re(e,O.target);if(J?.isCollapsed||Z&&ie){u=void 0,j();return}}u&&u.selector.length>0&&(U(),s.userSelect(u.annotation,O))},B=async()=>{const v=document.getSelection();let O=!1,j=v?.isCollapsed;const le=()=>j||O,J=1;return setTimeout(()=>O=!0,50),Ro(()=>j=v?.isCollapsed,J,le)},m=v=>{document.getSelection()?.isCollapsed||((!u||u.selector.length===0)&&k(v),u&&(U(),s.userSelect(u.annotation,Re(v))))},b=v=>{A&&(v.repeat||v.target instanceof Node&&re(e,v.target)&&v.target!==document.body||v.key==="Shift"&&u&&(document.getSelection().isCollapsed||(U(),s.userSelect(u.annotation,he(v)))))},w=v=>{const O=()=>setTimeout(()=>{u?.selector.length>0&&(s.clear(),i.addAnnotation({id:u.annotation,bodies:[],target:u}),s.userSelect(u.annotation,he(v))),document.removeEventListener("selectionchange",O)},100);document.addEventListener("selectionchange",O),N()};W(Mo.join(","),{element:e,keydown:!0,keyup:!1},v=>{v.repeat||(p=he(v))}),W(nn,{keydown:!0,keyup:!1},v=>{p=he(v),w(v)});const x=v=>{v.repeat||v.target instanceof Node&&re(e,v.target)&&v.target!==document.body||(u=void 0,s.clear())};W(tn.join(","),{keydown:!0,keyup:!1},x);const U=()=>{const v=i.getAnnotation(u.annotation);if(!v)i.addAnnotation({id:u.annotation,bodies:[],target:u});else{const{target:{updated:O}}=v,{updated:j}=u;(!O||!j||O<j)&&i.updateTarget(u)}};return document.addEventListener("pointerdown",D),document.addEventListener("pointerup",R),document.addEventListener("contextmenu",m),document.addEventListener("keyup",b),e.addEventListener("selectstart",N),document.addEventListener("selectionchange",k),{destroy:()=>{u=void 0,y=void 0,C=void 0,p=void 0,k.clear(),document.removeEventListener("pointerdown",D),document.removeEventListener("pointerup",R),document.removeEventListener("contextmenu",m),document.removeEventListener("keyup",b),e.removeEventListener("selectstart",N),document.removeEventListener("selectionchange",k),W.unbind()},setFilter:M,setUser:E,setAnnotatingEnabled:d,setAnnotatingMode:S}},Bo=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(";"),No=()=>{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,c)=>{const h=new Set(s.map(A=>A.annotation.id));Array.from(t).filter(A=>!h.has(A));const f=s.map(A=>{a?typeof a=="function"&&a(A.annotation,A.state):A.state?.selected;const g=Ge(A,a);return`::highlight(_${A.annotation.id}) { ${Bo(g)} }`});e.innerHTML=f.join(`
|
|
2
|
+
`),CSS.highlights.clear(),s.forEach(({annotation:A})=>{const g=A.target.selector.map(y=>y.range),u=new Highlight(...g);CSS.highlights.set(`_${A.id}`,u)}),t=h}}},ko=(e,t,n)=>Fe(No(),e,t,n),sn=(e,t)=>({...e,annotatingEnabled:e.annotatingEnabled??t.annotatingEnabled,user:e.user||t.user}),rn="SPANS",_o=(e,t={})=>{St(e),at(e);const n=sn(t,{annotatingEnabled:!0,user:$n()}),o=Ft(e,n),{selection:i,viewport:s}=o,r=o.store,a=kn(r),l=In(o,a,n.adapter);let c=n.user;const h=typeof n.renderer!="function"?n.renderer==="CSS_HIGHLIGHTS"?CSS.highlights?"CSS_HIGHLIGHTS":rn:n.renderer||rn:null,f=h===null?n.renderer(e,o,s):h==="SPANS"?Xt(e,o,s):h==="CSS_HIGHLIGHTS"?ko(e,o,s):void 0;if(!f)throw`Unknown renderer implementation: ${n.renderer}`;console.debug(h?`Using ${h} renderer`:"Using custom renderer implementation"),n.style&&f.setStyle(n.style);const A=on(e,o,l,n);A.setUser(c);const g=Dn(o,a,n.adapter),u=()=>c,y=E=>{A.setAnnotatingEnabled(E===void 0?!0:E)},C=E=>{A.setAnnotatingMode(E)},p=E=>{f.setFilter(E),A.setFilter(E)},d=E=>{c=E,A.setUser(E)},S=E=>{E?i.setSelected(E):i.clear()};return{...g,destroy:()=>{f.destroy(),A.destroy(),a.destroy()},element:e,getUser:u,renderer:f,setAnnotatingEnabled:y,setAnnotatingMode:C,setFilter:p,setStyle:f.setStyle.bind(f),setUser:d,setSelected:S,setVisible:f.setVisible.bind(f),on:l.on,off:l.off,scrollIntoView:pt(e,r),state:o}};L.DEFAULT_SELECTED_STYLE=Ne,L.DEFAULT_STYLE=te,L.NOT_ANNOTATABLE_CLASS=Ye,L.NOT_ANNOTATABLE_SELECTOR=se,L.Origin=_,L.UserSelectAction=$e,L.W3CTextFormat=zn,L.cancelSingleClickEvents=St,L.cloneKeyboardEvent=he,L.clonePointerEvent=Re,L.computeStyle=Ge,L.computeZIndex=Dt,L.createBody=vn,L.createRenderer=Fe,L.createSelectionHandler=on,L.createSpansRenderer=Xt,L.createTextAnnotator=_o,L.createTextAnnotatorState=Ft,L.debounce=Me,L.fillDefaults=sn,L.getBackgroundColor=It,L.getHighlightClientRects=Yt,L.getQuoteContext=ut,L.getRangeAnnotatableContents=Te,L.getViewportBounds=Pt,L.isMac=De,L.isNodeWhitespaceOrEmpty=un,L.isNotAnnotatable=re,L.isRangeAnnotatable=Ve,L.isRangeWhitespaceOrEmpty=st,L.isRevived=Q,L.mergeClientRects=Vt,L.mergeRanges=rt,L.parseW3CTextAnnotation=wt,L.programmaticallyFocusable=at,L.rangeToSelector=ft,L.reviveAnnotation=xe,L.reviveSelector=Xe,L.reviveTarget=fe,L.scrollIntoView=pt,L.serializeW3CTextAnnotation=Et,L.splitAnnotatableRanges=lt,L.toDomRectList=so,L.toParentBounds=Kt,L.toViewportBounds=ro,L.trackViewport=$t,L.trimRangeToContainer=ct,L.whitespaceOrEmptyRegex=Ke,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
|
|
3
3
|
//# sourceMappingURL=text-annotator.umd.js.map
|