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