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