@annotorious/annotorious 3.0.0-rc.1 → 3.0.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- (function(S,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(S=typeof globalThis<"u"?globalThis:S||self,G(S.Annotorious={}))})(this,function(S){"use strict";function G(){}function On(e,t){for(const n in t)e[n]=t[n];return e}function dt(e){return e()}function ht(){return Object.create(null)}function re(e){e.forEach(dt)}function V(e){return typeof e=="function"}function Z(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Bn(e){return Object.keys(e).length===0}function mt(e,...t){if(e==null)return G;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function gt(e,t,n){e.$$.on_destroy.push(mt(t,n))}function In(e,t,n,o){if(e){const i=pt(e,t,n,o);return e[0](i)}}function pt(e,t,n,o){return e[1]&&o?On(n.ctx.slice(),e[1](o(t))):n.ctx}function Cn(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let l=0;l<r;l+=1)s[l]=t.dirty[l]|i[l];return s}return t.dirty|i}return t.dirty}function Pn(e,t,n,o,i,s){if(i){const r=pt(t,n,o,s);e.p(r,i)}}function kn(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function fe(e,t){e.appendChild(t)}function B(e,t,n){e.insertBefore(t,n||null)}function O(e){e.parentNode&&e.parentNode.removeChild(e)}function We(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function D(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function _t(e){return document.createTextNode(e)}function te(){return _t(" ")}function le(){return _t("")}function W(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function u(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Rn(e){return Array.from(e.childNodes)}function yt(e,t,n){e.classList[n?"add":"remove"](t)}function Yn(e,t,{bubbles:n=!1,cancelable:o=!1}={}){const i=document.createEvent("CustomEvent");return i.initCustomEvent(e,n,o,t),i}let Le;function Oe(e){Le=e}function wt(){if(!Le)throw new Error("Function called outside component initialization");return Le}function Be(e){wt().$$.on_mount.push(e)}function ye(){const e=wt();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Yn(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function we(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const be=[],Ee=[];let Ae=[];const bt=[],Dn=Promise.resolve();let qe=!1;function Xn(){qe||(qe=!0,Dn.then(Et))}function Je(e){Ae.push(e)}const Qe=new Set;let Te=0;function Et(){if(Te!==0)return;const e=Le;do{try{for(;Te<be.length;){const t=be[Te];Te++,Oe(t),Un(t.$$)}}catch(t){throw be.length=0,Te=0,t}for(Oe(null),be.length=0,Te=0;Ee.length;)Ee.pop()();for(let t=0;t<Ae.length;t+=1){const n=Ae[t];Qe.has(n)||(Qe.add(n),n())}Ae.length=0}while(be.length);for(;bt.length;)bt.pop()();qe=!1,Qe.clear(),Oe(e)}function Un(e){if(e.fragment!==null){e.update(),re(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Je)}}function Nn(e){const t=[],n=[];Ae.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),Ae=t}const Ye=new Set;let me;function ae(){me={r:0,c:[],p:me}}function ce(){me.r||re(me.c),me=me.p}function U(e,t){e&&e.i&&(Ye.delete(e),e.i(t))}function N(e,t,n,o){if(e&&e.o){if(Ye.has(e))return;Ye.add(e),me.c.push(()=>{Ye.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ge(e){e&&e.c()}function ue(e,t,n,o){const{fragment:i,after_update:s}=e.$$;i&&i.m(t,n),o||Je(()=>{const r=e.$$.on_mount.map(dt).filter(V);e.$$.on_destroy?e.$$.on_destroy.push(...r):re(r),e.$$.on_mount=[]}),s.forEach(Je)}function de(e,t){const n=e.$$;n.fragment!==null&&(Nn(n.after_update),re(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Gn(e,t){e.$$.dirty[0]===-1&&(be.push(e),Xn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function ne(e,t,n,o,i,s,r,l=[-1]){const a=Le;Oe(e);const d=e.$$={fragment:null,ctx:[],props:s,update:G,not_equal:i,bound:ht(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:ht(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(d.root);let h=!1;if(d.ctx=n?n(e,t.props||{},(c,f,...m)=>{const g=m.length?m[0]:f;return d.ctx&&i(d.ctx[c],d.ctx[c]=g)&&(!d.skip_bound&&d.bound[c]&&d.bound[c](g),h&&Gn(e,c)),f}):[],d.update(),h=!0,re(d.before_update),d.fragment=o?o(d.ctx):!1,t.target){if(t.hydrate){const c=Rn(t.target);d.fragment&&d.fragment.l(c),c.forEach(O)}else d.fragment&&d.fragment.c();t.intro&&U(e.$$.fragment),ue(e,t.target,t.anchor,t.customElement),Et()}Oe(a)}class oe{$destroy(){de(this,1),this.$destroy=G}$on(t,n){if(!V(n))return G;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!Bn(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}var H=(e=>(e.ELLIPSE="ELLIPSE",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(H||{});const Ze={},De=(e,t)=>Ze[e]=t,Ke=e=>Ze[e.type].area(e),At=(e,t,n)=>Ze[e.type].intersects(e,t,n),Ie=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},Fn={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,l=0,a=Math.cos(l),d=Math.sin(l),h=t-o,c=n-i,f=a*h+d*c,m=d*h-a*c;return f*f/(s*s)+m*m/(r*r)<=1}};De(H.ELLIPSE,Fn);const Hn={area:e=>{const{points:t}=e.geometry;let n=0,o=t.length-1;for(let i=0;i<t.length;i++)n+=(t[o][0]+t[i][0])*(t[o][1]-t[i][1]),o=i;return Math.abs(.5*n)},intersects:(e,t,n)=>{const{points:o}=e.geometry;let i=!1;for(let s=0,r=o.length-1;s<o.length;r=s++){const l=o[s][0],a=o[s][1],d=o[r][0],h=o[r][1];a>n!=h>n&&t<(d-l)*(n-a)/(h-a)+l&&(i=!i)}return i}};De(H.POLYGON,Hn);const Tt={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};De(H.RECTANGLE,Tt);const St=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[s,r,l,a,d,h,c]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[f,m,g,p]=[a,d,h,c].map(parseFloat);return{type:H.RECTANGLE,geometry:{x:f,y:m,w:g,h:p,bounds:{minX:f,minY:t?m-p:m,maxX:f+g,maxY:t?m:m+p}}}},Mt=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},vt="http://www.w3.org/2000/svg",Lt=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},zn=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${vt}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},jn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(vt),i=n.lookupNamespaceURI(null);return o||i?Lt(n).firstChild:Lt(zn(n)).firstChild},Vn=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[];if(!o)return;const i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:H.POLYGON,geometry:{points:i,bounds:Ie(i)}}},Wn=e=>{const t=jn(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:H.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},Ot=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Vn(t);if(t.includes("<ellipse "))return Wn(t)},Bt=e=>{let t;if(e.type===H.POLYGON){const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`}else if(e.type===H.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`};let Xe;const qn=new Uint8Array(16);function Jn(){if(!Xe&&(Xe=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Xe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Xe(qn)}const q=[];for(let e=0;e<256;++e)q.push((e+256).toString(16).slice(1));function Qn(e,t=0){return q[e[t+0]]+q[e[t+1]]+q[e[t+2]]+q[e[t+3]]+"-"+q[e[t+4]]+q[e[t+5]]+"-"+q[e[t+6]]+q[e[t+7]]+"-"+q[e[t+8]]+q[e[t+9]]+"-"+q[e[t+10]]+q[e[t+11]]+q[e[t+12]]+q[e[t+13]]+q[e[t+14]]+q[e[t+15]]}const It={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function xe(e,t,n){if(It.randomUUID&&!t&&!e)return It.randomUUID();e=e||{};const o=e.random||(e.rng||Jn)();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 Qn(o)}var Ct=Object.prototype.hasOwnProperty;function pe(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--&&pe(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Ct.call(e,n)&&++o&&!Ct.call(t,n)||!(n in t)||!pe(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Se=[];function Ue(e,t=G){let n;const o=new Set;function i(l){if(Z(e,l)&&(e=l,n)){const a=!Se.length;for(const d of o)d[1](),Se.push(d,e);if(a){for(let d=0;d<Se.length;d+=2)Se[d][0](Se[d+1]);Se.length=0}}}function s(l){i(l(e))}function r(l,a=G){const d=[l,a];return o.add(d),o.size===1&&(n=t(i)||G),l(e),()=>{o.delete(d),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Zn=e=>{const{subscribe:t,set:n}=Ue(null);let o=null;return t(i=>o=i),e.observe(({changes:i})=>{if(o){i.deleted.some(l=>l.id===o)&&n(null);const r=i.updated.find(({oldValue:l})=>l.id===o);r&&n(r.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Pt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Pt||{});const $e={selected:[]},Kn=(e,t="EDIT")=>{const{subscribe:n,set:o}=Ue($e);let i=$e;n(c=>i=c);const s=()=>o($e),r=()=>{var c;return((c=i.selected)==null?void 0:c.length)===0},l=c=>{if(i.selected.length===0)return!1;const f=typeof c=="string"?c:c.id;return i.selected.some(m=>m.id===f)},a=(c,f)=>{const m=e.getAnnotation(c);if(m){const g=xn(m,t);o(g==="EDIT"?{selected:[{id:c,editable:!0}],pointerEvent:f}:g==="SELECT"?{selected:[{id:c}],pointerEvent:f}:{selected:[],pointerEvent:f})}else console.warn("Invalid selection: "+c)},d=(c,f=!0)=>{const m=Array.isArray(c)?c:[c],g=m.map(p=>e.getAnnotation(p)).filter(p=>p);o({selected:g.map(({id:p})=>({id:p,editable:f}))}),g.length!==m.length&&console.warn("Invalid selection",c)},h=c=>{if(i.selected.length===0)return!1;const{selected:f}=i;f.filter(({id:g})=>c.includes(g)).length>0&&o({selected:f.filter(({id:g})=>!c.includes(g))})};return e.observe(({changes:c})=>h(c.deleted.map(f=>f.id))),{clear:s,clickSelect:a,get selected(){return i?[...i.selected]:null},get pointerEvent(){return i?i.pointerEvent:null},isEmpty:r,isSelected:l,setSelected:d,subscribe:n}},xn=(e,t)=>typeof t=="function"?t(e)||"EDIT":t||"EDIT",$n=e=>{const{creator:t,updatedBy:n}=e.target,o=e.bodies.reduce((i,s)=>[...i,s.creator,s.updatedBy],[]);return[t,n,...o].filter(i=>i)},eo=(e,t,n,o)=>({id:xe(),annotation:e.id,created:n||new Date,creator:o,...t}),to=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},no=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},oo=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!pe(o,n)?o:void 0}}).filter(({oldBody:n})=>n),io=(e,t)=>!pe(e.target,t.target),kt=(e,t)=>({oldValue:e,newValue:t,bodiesCreated:to(e,t),bodiesDeleted:no(e,t),bodiesUpdated:oo(e,t),targetUpdated:io(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0});var z=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e))(z||{});const so=(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:l}=e.options,a=h=>(h==null?void 0:h.length)>0;if(!(a(n.created)||a(n.deleted))){const h=(s=n.updated)==null?void 0:s.some(f=>a(f.bodiesCreated)||a(f.bodiesDeleted)||a(f.bodiesUpdated)),c=(r=n.updated)==null?void 0:r.some(f=>f.targetUpdated);if(l==="BODY_ONLY"&&h&&!c||l==="TARGET_ONLY"&&c&&!h)return!1}}if(e.options.annotations){const l=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=>l.has(d))}else return!0},ro=e=>e.id!==void 0,lo=()=>{const e=new Map,t=new Map,n=[],o=(_,w={})=>n.push({onChange:_,options:w}),i=_=>{const w=n.findIndex(A=>A.onChange==_);w>-1&&n.splice(w,1)},s=(_,w)=>{const A={origin:_,changes:{created:w.created||[],updated:w.updated||[],deleted:w.deleted||[]},state:[...e.values()]};n.forEach(M=>{so(M,A)&&M.onChange(A)})},r=(_,w=z.LOCAL)=>{if(e.get(_.id))throw Error(`Cannot add annotation ${_.id} - exists already`);e.set(_.id,_),_.bodies.forEach(M=>t.set(M.id,_.id)),s(w,{created:[_]})},l=(_,w=z.LOCAL,A=z.LOCAL)=>{const M=ro(w)?A:w,I=typeof _=="string"?w:_,R=typeof _=="string"?_:_.id,K=e.get(R);if(K){const he=kt(K,I);R===I.id?e.set(R,I):(e.delete(R),e.set(I.id,I)),K.bodies.forEach(ie=>t.delete(ie.id)),I.bodies.forEach(ie=>t.set(ie.id,I.id)),s(M,{updated:[he]})}else throw Error(`Cannot update annotation ${R} - does not exist`)},a=(_,w=z.LOCAL)=>{const A=e.get(_.annotation);if(A){const M={...A,bodies:[...A.bodies,_]};e.set(A.id,M),t.set(_.id,M.id),s(w,{updated:[{oldValue:A,newValue:M,bodiesCreated:[_]}]})}else console.warn(`Attempt to add body to missing annotation: ${_.annotation}`)},d=()=>[...e.values()],h=(_=z.LOCAL)=>{const w=[...e.values()];e.clear(),t.clear(),s(_,{deleted:w})},c=(_,w=!0,A=z.LOCAL)=>{if(w){const M=[...e.values()];e.clear(),t.clear(),_.forEach(I=>{e.set(I.id,I),I.bodies.forEach(R=>t.set(R.id,I.id))}),s(A,{created:_,deleted:M})}else{const M=_.reduce((I,R)=>{const K=e.get(R.id);return K?[...I,K]:I},[]);if(M.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${M.map(I=>I.id).join(", ")}`);_.forEach(I=>{e.set(I.id,I),I.bodies.forEach(R=>t.set(R.id,I.id))}),s(A,{created:_})}},f=_=>{const w=typeof _=="string"?_:_.id,A=e.get(w);if(A)return e.delete(w),A.bodies.forEach(M=>t.delete(M.id)),A;console.warn(`Attempt to delete missing annotation: ${w}`)},m=(_,w=z.LOCAL)=>{const A=f(_);A&&s(w,{deleted:[A]})},g=(_,w=z.LOCAL)=>{const A=_.reduce((M,I)=>{const R=f(I);return R?[...M,R]:M},[]);A.length>0&&s(w,{deleted:A})},p=(_,w=z.LOCAL)=>{const A=e.get(_.annotation);if(A){const M=A.bodies.find(I=>I.id===_.id);if(M){t.delete(M.id);const I={...A,bodies:A.bodies.filter(K=>K.id!==_.id)};e.set(A.id,I),s(w,{updated:[{oldValue:A,newValue:I,bodiesDeleted:[M]}]})}else console.warn(`Attempt to delete missing body ${_.id} from annotation ${_.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${_.annotation}`)},y=_=>{const w=e.get(_);return w?{...w}:void 0},L=_=>{const w=t.get(_);if(w){const M=y(w).bodies.find(I=>I.id===_);if(M)return M;console.error(`Store integrity error: body ${_} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${_}`)},E=(_,w)=>{if(_.annotation!==w.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const A=e.get(_.annotation);if(A){const M=A.bodies.find(R=>R.id===_.id),I={...A,bodies:A.bodies.map(R=>R.id===M.id?w:R)};return e.set(A.id,I),M.id!==w.id&&(t.delete(M.id),t.set(w.id,I.id)),{oldValue:A,newValue:I,bodiesUpdated:[{oldBody:M,newBody:w}]}}else console.warn(`Attempt to add body to missing annotation ${_.annotation}`)},C=(_,w,A=z.LOCAL)=>{const M=E(_,w);s(A,{updated:[M]})},b=(_,w=z.LOCAL)=>{const A=_.map(M=>E({id:M.id,annotation:M.annotation},M));s(w,{updated:A})},Y=_=>{const w=e.get(_.annotation);if(w){const A={...w,target:{...w.target,..._}};return e.set(w.id,A),{oldValue:w,newValue:A,targetUpdated:{oldTarget:w.target,newTarget:_}}}else console.warn(`Attempt to update target on missing annotation: ${_.annotation}`)};return{addAnnotation:r,addBody:a,all:d,bulkAddAnnotation:c,bulkDeleteAnnotation:g,bulkUpdateBodies:b,bulkUpdateTargets:(_,w=z.LOCAL)=>{const A=_.map(Y).filter(M=>M);A.length>0&&s(w,{updated:A})},clear:h,deleteAnnotation:m,deleteBody:p,getAnnotation:y,getBody:L,observe:o,unobserve:i,updateAnnotation:l,updateBody:C,updateTarget:(_,w=z.LOCAL)=>{const A=Y(_);A&&s(w,{updated:[A]})}}},ao=e=>({...e,subscribe:n=>{const o=i=>n(i.state);return e.observe(o),n(e.all()),()=>e.unobserve(o)}}),co=()=>{const{subscribe:e,set:t}=Ue([]);return{subscribe:e,set:t}},fo=(e,t,n,o,i,s)=>{const r=new Map;let l=[],a,d;const h=(g,p)=>{r.has(g)?r.get(g).push(p):r.set(g,[p])},c=(g,p)=>{const y=r.get(g);y&&y.indexOf(p)>0&&y.splice(y.indexOf(p),1)},f=(g,p,y)=>{r.has(g)&&setTimeout(()=>{r.get(g).forEach(L=>{if(i){const E=Array.isArray(p)?p.map(b=>i.serialize(b)):i.serialize(p),C=y?y instanceof PointerEvent?y:i.serialize(y):void 0;L(E,C)}else L(p,y)})},1)},m=()=>{const{selected:g}=t,p=g.map(({id:y})=>e.getAnnotation(y));p.forEach(y=>{const L=l.find(E=>E.id===y.id);(!L||!pe(L,y))&&f("updateAnnotation",y,L)}),l=l.map(y=>{const L=p.find(({id:E})=>E===y.id);return L||y})};return t.subscribe(({selected:g})=>{if(!(l.length===0&&g.length===0)){if(l.length===0&&g.length>0)l=g.map(({id:p})=>e.getAnnotation(p));else if(l.length>0&&g.length===0)l.forEach(p=>{const y=e.getAnnotation(p.id);y&&!pe(y,p)&&f("updateAnnotation",y,p)}),l=[];else{const p=new Set(l.map(E=>E.id)),y=new Set(g.map(({id:E})=>E));l.filter(E=>!y.has(E.id)).forEach(E=>{const C=e.getAnnotation(E.id);C&&!pe(C,E)&&f("updateAnnotation",C,E)}),l=[...l.filter(E=>y.has(E.id)),...g.filter(({id:E})=>!p.has(E)).map(({id:E})=>e.getAnnotation(E))]}f("selectionChanged",l)}}),n.subscribe(g=>{!a&&g?f("mouseEnterAnnotation",e.getAnnotation(g)):a&&!g?f("mouseLeaveAnnotation",e.getAnnotation(a)):a&&g&&(f("mouseLeaveAnnotation",e.getAnnotation(a)),f("mouseEnterAnnotation",e.getAnnotation(g))),a=g}),o==null||o.subscribe(g=>f("viewportIntersect",g.map(e.getAnnotation))),e.observe(g=>{s&&(d&&clearTimeout(d),d=setTimeout(m,1e3));const{created:p,deleted:y}=g.changes;p.forEach(E=>f("createAnnotation",E)),y.forEach(E=>f("deleteAnnotation",E)),g.changes.updated.filter(E=>[...E.bodiesCreated||[],...E.bodiesDeleted||[],...E.bodiesUpdated||[]].length>0).forEach(({oldValue:E,newValue:C})=>{const b=l.find(Y=>Y.id===E.id)||E;l=l.map(Y=>Y.id===E.id?C:Y),f("updateAnnotation",C,b)})},{origin:z.LOCAL}),e.observe(g=>{if(l){const p=new Set(l.map(L=>L.id)),y=g.changes.updated.filter(({newValue:L})=>p.has(L.id)).map(({newValue:L})=>L);y.length>0&&(l=l.map(L=>{const E=y.find(C=>C.id===L.id);return E||L}))}},{origin:z.REMOTE}),{on:h,off:c,emit:f}},uo=e=>t=>t.map(n=>e.serialize(n)),Rt=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:[]}),Yt=(e,t)=>{const n=h=>{if(t){const{parsed:c,error:f}=t.parse(h);c?e.addAnnotation(c,z.REMOTE):console.error(f)}else e.addAnnotation(h,z.REMOTE)},o=()=>e.clear(),i=h=>{const c=e.getAnnotation(h);return t&&c?t.serialize(c):c},s=()=>t?e.all().map(t.serialize):e.all(),r=h=>fetch(h).then(c=>c.json()).then(c=>(a(c),c)),l=h=>{if(typeof h=="string"){const c=e.getAnnotation(h);return e.deleteAnnotation(h),t?t.serialize(c):c}else{const c=t?t.parse(h).parsed:h;return e.deleteAnnotation(c),h}},a=h=>{if(t){const{parsed:c,failed:f}=Rt(t)(h);f.length>0&&console.warn(`Discarded ${f.length} invalid annotations`,f),e.bulkAddAnnotation(c,!0,z.REMOTE)}else e.bulkAddAnnotation(h,!0,z.REMOTE)};return{addAnnotation:n,clearAnnotations:o,getAnnotationById:i,getAnnotations:s,loadAnnotations:r,removeAnnotation:l,setAnnotations:a,updateAnnotation:h=>{if(t){const c=t.parse(h).parsed,f=t.serialize(e.getAnnotation(c.id));return e.updateAnnotation(c),f}else{const c=e.getAnnotation(h.id);return e.updateAnnotation(h),c}}}};let ho=e=>crypto.getRandomValues(new Uint8Array(e)),mo=(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 l=n(i),a=i;for(;a--;)if(r+=e[l[a]&o]||"",r.length===s)return r}}},go=(e,t=21)=>mo(e,t,ho),po=(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 Dt=()=>({isGuest:!0,id:go("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),_o=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}`},Xt=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:l,creator:a,...d}=n;return{id:o||`temp-${_o(n)}`,annotation:t,type:i,purpose:s,value:r,created:l,creator:a?typeof a=="object"?{...a}:a:void 0,...d}}),Ut=e=>e.map(t=>{var o;const n={...t};return delete n.annotation,(o=n.id)!=null&&o.startsWith("temp-")&&delete n.id,n}),yo=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Nt=()=>{const e=[...yo];return{assignRandomColor:()=>{const o=Math.floor(Math.random()*e.length),i=e[o];return e.splice(o,1),i},releaseColor:o=>e.push(o)}},Gt=()=>{const e=Nt();return{addUser:(o,i)=>{const s=e.assignRandomColor();return{label:i.name||i.id,avatar:i.avatar,color:s}},removeUser:o=>e.releaseColor(o.appearance.color)}};let wo=()=>({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 bo=(e,t)=>e.every(n=>e.includes(n))&&t.every(n=>e.includes(n)),Eo=po(),Ao=(e=Gt())=>{const t=wo(),n=new Map,o=new Map,i=(c,f)=>{if(n.has(c)){console.warn("Attempt to add user that is already present",c,f);return}const m=e.addUser(c,f);n.set(c,{...f,presenceKey:c,appearance:m})},s=c=>{const f=n.get(c);if(!f){console.warn("Attempt to remove user that is not present",c);return}e.removeUser(f),n.delete(c)},r=c=>{const f=new Set(c.map(p=>p.presenceKey)),m=c.filter(({presenceKey:p})=>!n.has(p)),g=Array.from(n.values()).filter(p=>!f.has(p.presenceKey));m.forEach(({presenceKey:p,user:y})=>i(p,y)),g.forEach(p=>{const{presenceKey:y}=p;o.has(y)&&t.emit("selectionChange",p,null),s(y)}),(m.length>0||g.length>0)&&t.emit("presence",d())},l=(c,f)=>{const m=n.get(c);if(!m){console.warn("Activity notification from user that is not present");return}const g=o.get(c);(!g||!bo(g,f))&&(o.set(c,f),t.emit("selectionChange",m,f))},a=(c,f)=>{const m=n.get(c);if(!m){console.warn("Selection change for user that is not present",c);return}f?o.set(c,f):o.delete(c),t.emit("selectionChange",m,f)},d=()=>[...Array.from(n.values())];return{getPresentUsers:d,notifyActivity:l,on:(c,f)=>t.on(c,f),syncUsers:r,updateSelection:a}},To=(e,t=!1)=>({parse:i=>Ft(i,t),serialize:i=>Ht(i,e)}),Ft=(e,t=!1)=>{const n=e.id||xe(),o=Xt(e.body,n),i=Array.isArray(e.target)?e.target[0]:e.target,s=Array.isArray(i.selector)?i.selector[0]:i.selector,r=s.type==="FragmentSelector"?St(s,t):s.type==="SvgSelector"?Ot(s):void 0;return r?{parsed:{...e,id:n,bodies:o,target:{annotation:n,selector:r}}}:{error:Error(`Unknown selector type: ${r.type}`)}},Ht=(e,t)=>{const n=e.target.selector,o=n.type==H.RECTANGLE?Mt(n.geometry):Bt(n);return{...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Ut(e.bodies),target:{source:t,selector:o}}};function zt(e,t,n){const o=e.slice();return o[11]=t[n],o[13]=n,o}function jt(e){let t,n,o,i,s;return{c(){t=D("rect"),u(t,"class","a9s-corner-handle"),u(t,"x",n=e[11][0]-e[3]/2),u(t,"y",o=e[11][1]-e[3]/2),u(t,"height",e[3]),u(t,"width",e[3])},m(r,l){B(r,t,l),i||(s=W(t,"pointerdown",function(){V(e[10](v(e[13])))&&e[10](v(e[13])).apply(this,arguments)}),i=!0)},p(r,l){e=r,l&24&&n!==(n=e[11][0]-e[3]/2)&&u(t,"x",n),l&24&&o!==(o=e[11][1]-e[3]/2)&&u(t,"y",o),l&8&&u(t,"height",e[3]),l&8&&u(t,"width",e[3])},d(r){r&&O(t),i=!1,s()}}}function So(e){let t,n,o,i,s,r,l,a,d,h,c=e[4].points,f=[];for(let m=0;m<c.length;m+=1)f[m]=jt(zt(e,c,m));return{c(){t=D("polygon"),i=te(),s=D("polygon"),l=te();for(let m=0;m<f.length;m+=1)f[m].c();a=le(),u(t,"class","a9s-outer"),u(t,"style",n=e[1]?"display:none;":void 0),u(t,"points",o=e[4].points.map(Vt).join(" ")),u(s,"class","a9s-inner a9s-shape-handle"),u(s,"style",e[1]),u(s,"points",r=e[4].points.map(Wt).join(" "))},m(m,g){B(m,t,g),B(m,i,g),B(m,s,g),B(m,l,g);for(let p=0;p<f.length;p+=1)f[p]&&f[p].m(m,g);B(m,a,g),d||(h=[W(t,"pointerdown",function(){V(e[10](v.SHAPE))&&e[10](v.SHAPE).apply(this,arguments)}),W(s,"pointerdown",function(){V(e[10](v.SHAPE))&&e[10](v.SHAPE).apply(this,arguments)})],d=!0)},p(m,g){if(e=m,g&2&&n!==(n=e[1]?"display:none;":void 0)&&u(t,"style",n),g&16&&o!==(o=e[4].points.map(Vt).join(" "))&&u(t,"points",o),g&2&&u(s,"style",e[1]),g&16&&r!==(r=e[4].points.map(Wt).join(" "))&&u(s,"points",r),g&1048){c=e[4].points;let p;for(p=0;p<c.length;p+=1){const y=zt(e,c,p);f[p]?f[p].p(y,g):(f[p]=jt(y),f[p].c(),f[p].m(a.parentNode,a))}for(;p<f.length;p+=1)f[p].d(1);f.length=c.length}},d(m){m&&O(t),m&&O(i),m&&O(s),m&&O(l),We(f,m),m&&O(a),d=!1,re(h)}}}function Mo(e){let t,n;return t=new tt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[So,({grab:o})=>({10:o}),({grab:o})=>o?1024:0]},$$scope:{ctx:e}}}),t.$on("change",e[7]),t.$on("grab",e[8]),t.$on("release",e[9]),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&17434&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}const Vt=e=>e.join(","),Wt=e=>e.join(",");function vo(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:l}=t,{viewportScale:a=1}=t;const d=(m,g,p)=>{let y;g===v.SHAPE?y=m.geometry.points.map(([E,C])=>[E+p[0],C+p[1]]):y=m.geometry.points.map(([E,C],b)=>g===v(b)?[E+p[0],C+p[1]]:[E,C]);const L=Ie(y);return{...m,geometry:{points:y,bounds:L}}};function h(m){we.call(this,e,m)}function c(m){we.call(this,e,m)}function f(m){we.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,s=m.shape),"computedStyle"in m&&n(1,r=m.computedStyle),"transform"in m&&n(2,l=m.transform),"viewportScale"in m&&n(6,a=m.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/a)},[s,r,l,i,o,d,a,h,c,f]}class qt extends oe{constructor(t){super(),ne(this,t,vo,Mo,Z,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}function Lo(e){let t,n,o,i,s,r,l,a,d,h,c,f,m,g,p,y,L,E,C,b,Y,F,X,_,w,A,M,I,R,K,he,ie,Re,x,P,Q,j,J,se,_e,ct,$,He,ze,ft,ee,je,Ve,ut,Ln;return{c(){t=D("rect"),l=te(),a=D("rect"),m=te(),g=D("rect"),E=te(),C=D("rect"),X=te(),_=D("rect"),I=te(),R=D("rect"),Re=te(),x=D("rect"),j=te(),J=D("rect"),ct=te(),$=D("rect"),ft=te(),ee=D("rect"),u(t,"class","a9s-outer"),u(t,"style",n=e[1]?"display:none;":void 0),u(t,"x",o=e[4].x),u(t,"y",i=e[4].y),u(t,"width",s=e[4].w),u(t,"height",r=e[4].h),u(a,"class","a9s-inner a9s-shape-handle"),u(a,"style",e[1]),u(a,"x",d=e[4].x),u(a,"y",h=e[4].y),u(a,"width",c=e[4].w),u(a,"height",f=e[4].h),u(g,"class","a9s-edge-handle a9s-edge-handle-top"),u(g,"x",p=e[4].x),u(g,"y",y=e[4].y),u(g,"height",1),u(g,"width",L=e[4].w),u(C,"class","a9s-edge-handle a9s-edge-handle-right"),u(C,"x",b=e[4].x+e[4].w),u(C,"y",Y=e[4].y),u(C,"height",F=e[4].h),u(C,"width",1),u(_,"class","a9s-edge-handle a9s-edge-handle-bottom"),u(_,"x",w=e[4].x),u(_,"y",A=e[4].y+e[4].h),u(_,"height",1),u(_,"width",M=e[4].w),u(R,"class","a9s-edge-handle a9s-edge-handle-left"),u(R,"x",K=e[4].x),u(R,"y",he=e[4].y),u(R,"height",ie=e[4].h),u(R,"width",1),u(x,"class","a9s-corner-handle a9s-corner-handle-topleft"),u(x,"x",P=e[4].x-e[3]/2),u(x,"y",Q=e[4].y-e[3]/2),u(x,"height",e[3]),u(x,"width",e[3]),u(J,"class","a9s-corner-handle a9s-corner-handle-topright"),u(J,"x",se=e[4].x+e[4].w-e[3]/2),u(J,"y",_e=e[4].y-e[3]/2),u(J,"height",e[3]),u(J,"width",e[3]),u($,"class","a9s-corner-handle a9s-corner-handle-bottomright"),u($,"x",He=e[4].x+e[4].w-e[3]/2),u($,"y",ze=e[4].y+e[4].h-e[3]/2),u($,"height",e[3]),u($,"width",e[3]),u(ee,"class","a9s-corner-handle a9s-corner-handle-bottomleft"),u(ee,"x",je=e[4].x-e[3]/2),u(ee,"y",Ve=e[4].y+e[4].h-e[3]/2),u(ee,"height",e[3]),u(ee,"width",e[3])},m(k,T){B(k,t,T),B(k,l,T),B(k,a,T),B(k,m,T),B(k,g,T),B(k,E,T),B(k,C,T),B(k,X,T),B(k,_,T),B(k,I,T),B(k,R,T),B(k,Re,T),B(k,x,T),B(k,j,T),B(k,J,T),B(k,ct,T),B(k,$,T),B(k,ft,T),B(k,ee,T),ut||(Ln=[W(t,"pointerdown",function(){V(e[10](v.SHAPE))&&e[10](v.SHAPE).apply(this,arguments)}),W(a,"pointerdown",function(){V(e[10](v.SHAPE))&&e[10](v.SHAPE).apply(this,arguments)}),W(g,"pointerdown",function(){V(e[10](v.TOP))&&e[10](v.TOP).apply(this,arguments)}),W(C,"pointerdown",function(){V(e[10](v.RIGHT))&&e[10](v.RIGHT).apply(this,arguments)}),W(_,"pointerdown",function(){V(e[10](v.BOTTOM))&&e[10](v.BOTTOM).apply(this,arguments)}),W(R,"pointerdown",function(){V(e[10](v.LEFT))&&e[10](v.LEFT).apply(this,arguments)}),W(x,"pointerdown",function(){V(e[10](v.TOP_LEFT))&&e[10](v.TOP_LEFT).apply(this,arguments)}),W(J,"pointerdown",function(){V(e[10](v.TOP_RIGHT))&&e[10](v.TOP_RIGHT).apply(this,arguments)}),W($,"pointerdown",function(){V(e[10](v.BOTTOM_RIGHT))&&e[10](v.BOTTOM_RIGHT).apply(this,arguments)}),W(ee,"pointerdown",function(){V(e[10](v.BOTTOM_LEFT))&&e[10](v.BOTTOM_LEFT).apply(this,arguments)})],ut=!0)},p(k,T){e=k,T&2&&n!==(n=e[1]?"display:none;":void 0)&&u(t,"style",n),T&16&&o!==(o=e[4].x)&&u(t,"x",o),T&16&&i!==(i=e[4].y)&&u(t,"y",i),T&16&&s!==(s=e[4].w)&&u(t,"width",s),T&16&&r!==(r=e[4].h)&&u(t,"height",r),T&2&&u(a,"style",e[1]),T&16&&d!==(d=e[4].x)&&u(a,"x",d),T&16&&h!==(h=e[4].y)&&u(a,"y",h),T&16&&c!==(c=e[4].w)&&u(a,"width",c),T&16&&f!==(f=e[4].h)&&u(a,"height",f),T&16&&p!==(p=e[4].x)&&u(g,"x",p),T&16&&y!==(y=e[4].y)&&u(g,"y",y),T&16&&L!==(L=e[4].w)&&u(g,"width",L),T&16&&b!==(b=e[4].x+e[4].w)&&u(C,"x",b),T&16&&Y!==(Y=e[4].y)&&u(C,"y",Y),T&16&&F!==(F=e[4].h)&&u(C,"height",F),T&16&&w!==(w=e[4].x)&&u(_,"x",w),T&16&&A!==(A=e[4].y+e[4].h)&&u(_,"y",A),T&16&&M!==(M=e[4].w)&&u(_,"width",M),T&16&&K!==(K=e[4].x)&&u(R,"x",K),T&16&&he!==(he=e[4].y)&&u(R,"y",he),T&16&&ie!==(ie=e[4].h)&&u(R,"height",ie),T&24&&P!==(P=e[4].x-e[3]/2)&&u(x,"x",P),T&24&&Q!==(Q=e[4].y-e[3]/2)&&u(x,"y",Q),T&8&&u(x,"height",e[3]),T&8&&u(x,"width",e[3]),T&24&&se!==(se=e[4].x+e[4].w-e[3]/2)&&u(J,"x",se),T&24&&_e!==(_e=e[4].y-e[3]/2)&&u(J,"y",_e),T&8&&u(J,"height",e[3]),T&8&&u(J,"width",e[3]),T&24&&He!==(He=e[4].x+e[4].w-e[3]/2)&&u($,"x",He),T&24&&ze!==(ze=e[4].y+e[4].h-e[3]/2)&&u($,"y",ze),T&8&&u($,"height",e[3]),T&8&&u($,"width",e[3]),T&24&&je!==(je=e[4].x-e[3]/2)&&u(ee,"x",je),T&24&&Ve!==(Ve=e[4].y+e[4].h-e[3]/2)&&u(ee,"y",Ve),T&8&&u(ee,"height",e[3]),T&8&&u(ee,"width",e[3])},d(k){k&&O(t),k&&O(l),k&&O(a),k&&O(m),k&&O(g),k&&O(E),k&&O(C),k&&O(X),k&&O(_),k&&O(I),k&&O(R),k&&O(Re),k&&O(x),k&&O(j),k&&O(J),k&&O(ct),k&&O($),k&&O(ft),k&&O(ee),ut=!1,re(Ln)}}}function Oo(e){let t,n;return t=new tt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Lo,({grab:o})=>({10:o}),({grab:o})=>o?1024:0]},$$scope:{ctx:e}}}),t.$on("grab",e[7]),t.$on("change",e[8]),t.$on("release",e[9]),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&3098&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function Bo(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:l}=t,{viewportScale:a=1}=t;const d=(m,g,p)=>{const y=m.geometry.bounds;let[L,E]=[y.minX,y.minY],[C,b]=[y.maxX,y.maxY];const[Y,F]=p;if(g===v.SHAPE)L+=Y,C+=Y,E+=F,b+=F;else{switch(g){case v.TOP:case v.TOP_LEFT:case v.TOP_RIGHT:{E+=F;break}case v.BOTTOM:case v.BOTTOM_LEFT:case v.BOTTOM_RIGHT:{b+=F;break}}switch(g){case v.LEFT:case v.TOP_LEFT:case v.BOTTOM_LEFT:{L+=Y;break}case v.RIGHT:case v.TOP_RIGHT:case v.BOTTOM_RIGHT:{C+=Y;break}}}const X=Math.min(L,C),_=Math.min(E,b),w=Math.abs(C-L),A=Math.abs(b-E);return{...m,geometry:{x:X,y:_,w,h:A,bounds:{minX:X,minY:_,maxX:X+w,maxY:_+A}}}};function h(m){we.call(this,e,m)}function c(m){we.call(this,e,m)}function f(m){we.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,s=m.shape),"computedStyle"in m&&n(1,r=m.computedStyle),"transform"in m&&n(2,l=m.transform),"viewportScale"in m&&n(6,a=m.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/a)},[s,r,l,i,o,d,a,h,c,f]}class Jt extends oe{constructor(t){super(),ne(this,t,Bo,Oo,Z,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}const Qt=new Map([[H.RECTANGLE,Jt],[H.POLYGON,qt]]),et=e=>Qt.get(e.type),Zt=(e,t)=>Qt.set(e,t),v=e=>`HANDLE-${e}`;v.SHAPE="SHAPE",v.TOP="TOP",v.RIGHT="RIGHT",v.BOTTOM="BOTTOM",v.LEFT="LEFT",v.TOP_LEFT="TOP_LEFT",v.TOP_RIGHT="TOP_RIGHT",v.BOTTOM_RIGHT="BOTTOM_RIGHT",v.BOTTOM_LEFT="BOTTOM_LEFT";const Io=e=>({}),Kt=e=>({grab:e[0]});function Co(e){let t,n,o,i;const s=e[7].default,r=In(s,e,e[6],Kt);return{c(){t=D("g"),r&&r.c(),u(t,"class","a9s-annotation selected")},m(l,a){B(l,t,a),r&&r.m(t,null),n=!0,o||(i=[W(t,"pointerup",e[2]),W(t,"pointermove",e[1])],o=!0)},p(l,[a]){r&&r.p&&(!n||a&64)&&Pn(r,s,l,l[6],n?Cn(s,l[6],a,Io):kn(l[6]),Kt)},i(l){n||(U(r,l),n=!0)},o(l){N(r,l),n=!1},d(l){l&&O(t),r&&r.d(l),o=!1,re(i)}}}function Po(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=ye();let{shape:r}=t,{editor:l}=t,{transform:a}=t,d=null,h,c=null;const f=p=>y=>{d=p,h=a.elementToImage(y.offsetX,y.offsetY),c=r,y.target.setPointerCapture(y.pointerId),s("grab")},m=p=>{if(d){const[y,L]=a.elementToImage(p.offsetX,p.offsetY),E=[y-h[0],L-h[1]];n(3,r=l(c,d,E)),s("change",r)}},g=p=>{p.target.releasePointerCapture(p.pointerId),d=null,c=r,s("release")};return e.$$set=p=>{"shape"in p&&n(3,r=p.shape),"editor"in p&&n(4,l=p.editor),"transform"in p&&n(5,a=p.transform),"$$scope"in p&&n(6,i=p.$$scope)},[f,m,g,r,l,a,i,o]}class tt extends oe{constructor(t){super(),ne(this,t,Po,Co,Z,{shape:3,editor:4,transform:5})}}const Ne=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i}=n;let s="";return o&&(s+=`fill:${o};stroke:${o};`),s+=`fill-opacity:${i||"0.25"};`,s}};function ko(e,t,n){let o;const i=ye();let{annotation:s}=t,{editor:r}=t,{style:l=void 0}=t,{target:a}=t,{transform:d}=t,{viewportScale:h}=t,c;return Be(()=>(n(6,c=new r({target:a,props:{shape:s.target.selector,computedStyle:o,transform:d,viewportScale:h}})),c.$on("change",f=>{c.$$set({shape:f.detail}),i("change",f.detail)}),c.$on("grab",f=>i("grab",f.detail)),c.$on("release",f=>i("release",f.detail)),()=>{c.$destroy()})),e.$$set=f=>{"annotation"in f&&n(0,s=f.annotation),"editor"in f&&n(1,r=f.editor),"style"in f&&n(2,l=f.style),"target"in f&&n(3,a=f.target),"transform"in f&&n(4,d=f.transform),"viewportScale"in f&&n(5,h=f.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&(o=Ne(s,l)),e.$$.dirty&80&&c&&c.$set({transform:d}),e.$$.dirty&96&&c&&c.$set({viewportScale:h})},[s,r,l,a,d,h,c]}class xt extends oe{constructor(t){super(),ne(this,t,ko,null,Z,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Ro(e,t,n){const o=ye();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,d;return Be(()=>{const h=s.closest("svg"),c=[],f=(m,g,p)=>{h.addEventListener(m,g,p),c.push(()=>h.removeEventListener(m,g,p))};return n(5,d=new r({target:s,props:{addEventListener:f,drawingMode:i,transform:l,viewportScale:a}})),d.$on("create",m=>o("create",m.detail)),()=>{c.forEach(m=>m()),d.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,i=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,l=h.transform),"viewportScale"in h&&n(4,a=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&d&&d.$set({transform:l}),e.$$.dirty&48&&d&&d.$set({viewportScale:a})},[i,s,r,l,a,d]}class $t extends oe{constructor(t){super(),ne(this,t,Ro,null,Z,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function en(e){let t,n;return{c(){t=D("rect"),n=D("rect"),u(t,"class","a9s-outer"),u(t,"x",e[2]),u(t,"y",e[3]),u(t,"width",e[4]),u(t,"height",e[5]),u(n,"class","a9s-inner"),u(n,"x",e[2]),u(n,"y",e[3]),u(n,"width",e[4]),u(n,"height",e[5])},m(o,i){B(o,t,i),B(o,n,i)},p(o,i){i&4&&u(t,"x",o[2]),i&8&&u(t,"y",o[3]),i&16&&u(t,"width",o[4]),i&32&&u(t,"height",o[5]),i&4&&u(n,"x",o[2]),i&8&&u(n,"y",o[3]),i&16&&u(n,"width",o[4]),i&32&&u(n,"height",o[5])},d(o){o&&O(t),o&&O(n)}}}function Yo(e){let t,n=e[1]&&en(e);return{c(){t=D("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null),e[9](t)},p(o,[i]){o[1]?n?n.p(o,i):(n=en(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:G,o:G,d(o){o&&O(t),n&&n.d(),e[9](null)}}}function Do(e,t,n){const o=ye();let{addEventListener:i}=t,{drawingMode:s}=t,{transform:r}=t,l,a,d,h,c,f,m,g;const p=b=>{a=performance.now(),s==="drag"&&(n(1,d=r.elementToImage(b.offsetX,b.offsetY)),h=d,n(2,c=d[0]),n(3,f=d[1]),n(4,m=1),n(5,g=1))},y=b=>{d&&(h=r.elementToImage(b.offsetX,b.offsetY),n(2,c=Math.min(h[0],d[0])),n(3,f=Math.min(h[1],d[1])),n(4,m=Math.abs(h[0]-d[0])),n(5,g=Math.abs(h[1]-d[1])))},L=b=>{const Y=performance.now()-a;if(s==="click"){if(Y>300)return;b.stopPropagation(),d?E():(n(1,d=r.elementToImage(b.offsetX,b.offsetY)),h=d,n(2,c=d[0]),n(3,f=d[1]),n(4,m=1),n(5,g=1))}else d&&(Y>300||m*g>100?(b.stopPropagation(),E()):(n(1,d=null),h=null))},E=()=>{if(m*g>15){const b={type:H.RECTANGLE,geometry:{bounds:{minX:c,minY:f,maxX:c+m,maxY:f+g},x:c,y:f,w:m,h:g}};o("create",b)}n(1,d=null),h=null};Be(()=>{i("pointerdown",p),i("pointermove",y),i("pointerup",L,!0)});function C(b){Ee[b?"unshift":"push"](()=>{l=b,n(0,l)})}return e.$$set=b=>{"addEventListener"in b&&n(6,i=b.addEventListener),"drawingMode"in b&&n(7,s=b.drawingMode),"transform"in b&&n(8,r=b.transform)},[l,d,c,f,m,g,i,s,r,C]}class tn extends oe{constructor(t){super(),ne(this,t,Do,Yo,Z,{addEventListener:6,drawingMode:7,transform:8})}}const nt=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},Xo=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},nn=(e,t)=>{Xo(e,t);const{subscribe:n,set:o}=Ue(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,d=Math.max(r.width/l,r.height/a);o(d)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},Uo="ontouchstart"in window||navigator.maxTouchPoints>0;function ot(e){const t=e.slice(),n=(t[3]?t[1]:[...t[1],t[2]]).map(o=>o.join(",")).join(" ");return t[17]=n,t}function on(e){let t,n,o,i,s,r=e[3]&&sn(e);return{c(){t=D("polygon"),o=D("polygon"),r&&r.c(),s=le(),u(t,"class","a9s-outer"),u(t,"points",n=e[17]),u(o,"class","a9s-inner"),u(o,"points",i=e[17])},m(l,a){B(l,t,a),B(l,o,a),r&&r.m(l,a),B(l,s,a)},p(l,a){a&14&&n!==(n=l[17])&&u(t,"points",n),a&14&&i!==(i=l[17])&&u(o,"points",i),l[3]?r?r.p(l,a):(r=sn(l),r.c(),r.m(s.parentNode,s)):r&&(r.d(1),r=null)},d(l){l&&O(t),l&&O(o),r&&r.d(l),l&&O(s)}}}function sn(e){let t,n,o;return{c(){t=D("rect"),u(t,"class","a9s-corner-handle"),u(t,"x",n=e[1][0][0]-e[4]/2),u(t,"y",o=e[1][0][1]-e[4]/2),u(t,"height",e[4]),u(t,"width",e[4])},m(i,s){B(i,t,s)},p(i,s){s&18&&n!==(n=i[1][0][0]-i[4]/2)&&u(t,"x",n),s&18&&o!==(o=i[1][0][1]-i[4]/2)&&u(t,"y",o),s&16&&u(t,"height",i[4]),s&16&&u(t,"width",i[4])},d(i){i&&O(t)}}}function No(e){let t,n=e[2]&&on(ot(e));return{c(){t=D("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null),e[9](t)},p(o,[i]){o[2]?n?n.p(ot(o),i):(n=on(ot(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:G,o:G,d(o){o&&O(t),n&&n.d(),e[9](null)}}}const Go=20;function Fo(e,t,n){let o;const i=ye();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,d,h,c=[],f=null,m=!1;const g=b=>{if(h=performance.now(),r==="drag"&&c.length===0){const Y=l.elementToImage(b.offsetX,b.offsetY);c.push(Y),n(2,f=Y)}},p=b=>{if(c.length>0&&(n(2,f=l.elementToImage(b.offsetX,b.offsetY)),c.length>2)){const Y=nt(f,c[0])*a;n(3,m=Y<Go)}},y=b=>{const Y=performance.now()-h;if(r==="click"){if(Y>300)return;if(b.stopPropagation(),m)E();else if(c.length===0){const F=l.elementToImage(b.offsetX,b.offsetY);c.push(F),n(2,f=F)}else c.push(f)}else{if(c.length===1&&nt(c[0],f)<=4){n(1,c=[]),n(2,f=null);return}b.stopImmediatePropagation(),m?E():c.push(f)}},L=()=>{console.log("dblclick");const b=[...c,f],Y={type:H.POLYGON,geometry:{bounds:Ie(b),points:b}};n(1,c=[]),n(2,f=null),i("create",Y)},E=()=>{const b={type:H.POLYGON,geometry:{bounds:Ie(c),points:[...c]}};n(1,c=[]),n(2,f=null),i("create",b)};Be(()=>{s("pointerdown",g,!0),s("pointermove",p),s("pointerup",y,!0),s("dblclick",L,!0)});function C(b){Ee[b?"unshift":"push"](()=>{d=b,n(0,d)})}return e.$$set=b=>{"addEventListener"in b&&n(5,s=b.addEventListener),"drawingMode"in b&&n(6,r=b.drawingMode),"transform"in b&&n(7,l=b.transform),"viewportScale"in b&&n(8,a=b.viewportScale)},e.$$.update=()=>{e.$$.dirty&256&&n(4,o=10/a)},[d,c,f,m,o,s,r,l,a,C]}class Ho extends oe{constructor(t){super(),ne(this,t,Fo,No,Z,{addEventListener:5,drawingMode:6,transform:7,viewportScale:8})}}const it=new Map([["rectangle",{tool:tn}],["polygon",{tool:Ho}]]),rn=()=>[...it.keys()],st=e=>it.get(e),ln=(e,t,n)=>it.set(e,{tool:t,opts:n});function zo(e){let t,n,o,i,s;return{c(){t=D("g"),n=D("ellipse"),i=D("ellipse"),u(n,"class","a9s-outer"),u(n,"style",o=e[1]?"display:none;":void 0),u(n,"cx",e[2]),u(n,"cy",e[3]),u(n,"rx",e[4]),u(n,"ry",e[5]),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"cx",e[2]),u(i,"cy",e[3]),u(i,"rx",e[4]),u(i,"ry",e[5]),u(t,"data-id",s=e[0].id)},m(r,l){B(r,t,l),fe(t,n),fe(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&u(n,"style",o),l&2&&u(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:G,o:G,d(r){r&&O(t)}}}function jo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{cx:l,cy:a,rx:d,ry:h}=s;return e.$$set=c=>{"annotation"in c&&n(0,i=c.annotation),"geom"in c&&n(6,s=c.geom),"style"in c&&n(7,r=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ne(i,r))},[i,o,l,a,d,h,s,r]}class Vo extends oe{constructor(t){super(),ne(this,t,jo,zo,Z,{annotation:0,geom:6,style:7})}}function Wo(e){let t,n,o,i,s;return{c(){t=D("g"),n=D("polygon"),i=D("polygon"),u(n,"class","a9s-outer"),u(n,"style",o=e[1]?"display:none;":void 0),u(n,"points",e[2].map(qo).join(" ")),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"points",e[2].map(Jo).join(" ")),u(t,"data-id",s=e[0].id)},m(r,l){B(r,t,l),fe(t,n),fe(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&u(n,"style",o),l&2&&u(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:G,o:G,d(r){r&&O(t)}}}const qo=e=>e.join(","),Jo=e=>e.join(",");function Qo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ne(i,r))},[i,o,l,s,r]}class Zo extends oe{constructor(t){super(),ne(this,t,Qo,Wo,Z,{annotation:0,geom:3,style:4})}}function Ko(e){let t,n,o,i,s;return{c(){t=D("g"),n=D("rect"),i=D("rect"),u(n,"class","a9s-outer"),u(n,"style",o=e[1]?"display:none;":void 0),u(n,"x",e[2]),u(n,"y",e[3]),u(n,"width",e[4]),u(n,"height",e[5]),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"x",e[2]),u(i,"y",e[3]),u(i,"width",e[4]),u(i,"height",e[5]),u(t,"data-id",s=e[0].id)},m(r,l){B(r,t,l),fe(t,n),fe(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&u(n,"style",o),l&2&&u(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:G,o:G,d(r){r&&O(t)}}}function xo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{x:l,y:a,w:d,h}=s;return e.$$set=c=>{"annotation"in c&&n(0,i=c.annotation),"geom"in c&&n(6,s=c.geom),"style"in c&&n(7,r=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ne(i,r))},[i,o,l,a,d,h,s,r]}class $o extends oe{constructor(t){super(),ne(this,t,xo,Ko,Z,{annotation:0,geom:6,style:7})}}const ei={elementToImage:(e,t)=>[e,t]},an=e=>({elementToImage:(t,n)=>{const o=e.createSVGPoint();o.x=t,o.y=n;const{x:i,y:s}=o.matrixTransform(e.getCTM().inverse());return[i,s]}}),ti=250,cn=(e,t)=>{const n=ye();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<ti){const{x:a,y:d}=ni(r,e),h=t.getAt(a,d);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},ni=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=i+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function fn(e,t,n){const o=e.slice();return o[28]=t[n],o}function un(e,t,n){const o=e.slice();return o[31]=t[n],o}function rt(e){const t=e.slice(),n=t[31].target.selector;return t[34]=n,t}function dn(e){let t=e[31].id,n,o,i=hn(e);return{c(){i.c(),n=le()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4096&&Z(t,t=s[31].id)?(ae(),N(i,1,1,G),ce(),i=hn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){N(i),o=!1},d(s){s&&O(n),i.d(s)}}}function oi(e){let t,n;return t=new Zo({props:{annotation:e[31],geom:e[34].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){const s={};i[0]&4096&&(s.annotation=o[31]),i[0]&4096&&(s.geom=o[34].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function ii(e){let t,n;return t=new $o({props:{annotation:e[31],geom:e[34].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){const s={};i[0]&4096&&(s.annotation=o[31]),i[0]&4096&&(s.geom=o[34].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function si(e){let t,n;return t=new Vo({props:{annotation:e[31],geom:e[34].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){const s={};i[0]&4096&&(s.annotation=o[31]),i[0]&4096&&(s.geom=o[34].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function hn(e){let t,n,o,i;const s=[si,ii,oi],r=[];function l(a,d){return a[34].type===H.ELLIPSE?0:a[34].type===H.RECTANGLE?1:a[34].type===H.POLYGON?2:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=le()},m(a,d){~t&&r[t].m(a,d),B(a,o,d),i=!0},p(a,d){let h=t;t=l(a),t===h?~t&&r[t].p(a,d):(n&&(ae(),N(r[h],1,1,()=>{r[h]=null}),ce()),~t?(n=r[t],n?n.p(a,d):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){N(n),i=!1},d(a){~t&&r[t].d(a),a&&O(o)}}}function mn(e){let t=!e[7](e[31]),n,o,i=t&&dn(rt(e));return{c(){i&&i.c(),n=le()},m(s,r){i&&i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4224&&(t=!s[7](s[31])),t?i?(i.p(rt(s),r),r[0]&4224&&U(i,1)):(i=dn(rt(s)),i.c(),U(i,1),i.m(n.parentNode,n)):i&&(ae(),N(i,1,1,()=>{i=null}),ce())},i(s){o||(U(i),o=!0)},o(s){N(i),o=!1},d(s){i&&i.d(s),s&&O(n)}}}function gn(e){let t,n,o,i;const s=[li,ri],r=[];function l(a,d){return a[6]?0:a[2]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=le()},m(a,d){~t&&r[t].m(a,d),B(a,o,d),i=!0},p(a,d){let h=t;t=l(a),t===h?~t&&r[t].p(a,d):(n&&(ae(),N(r[h],1,1,()=>{r[h]=null}),ce()),~t?(n=r[t],n?n.p(a,d):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){N(n),i=!1},d(a){~t&&r[t].d(a),a&&O(o)}}}function ri(e){let t=e[2],n,o,i=pn(e);return{c(){i.c(),n=le()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4&&Z(t,t=s[2])?(ae(),N(i,1,1,G),ce(),i=pn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){N(i),o=!1},d(s){s&&O(n),i.d(s)}}}function li(e){let t,n,o=e[6],i=[];for(let r=0;r<o.length;r+=1)i[r]=yn(fn(e,o,r));const s=r=>N(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=le()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);B(r,t,l),n=!0},p(r,l){if(l[0]&140370){o=r[6];let a;for(a=0;a<o.length;a+=1){const d=fn(r,o,a);i[a]?(i[a].p(d,l),U(i[a],1)):(i[a]=yn(d),i[a].c(),U(i[a],1),i[a].m(t.parentNode,t))}for(ae(),a=o.length;a<i.length;a+=1)s(a);ce()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)U(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)N(i[l]);n=!1},d(r){We(i,r),r&&O(t)}}}function pn(e){let t,n;return t=new $t({props:{target:e[4],tool:e[2],drawingMode:e[11],transform:e[10],viewportScale:e[13]}}),t.$on("create",e[16]),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){const s={};i[0]&16&&(s.target=o[4]),i[0]&4&&(s.tool=o[2]),i[0]&2048&&(s.drawingMode=o[11]),i[0]&1024&&(s.transform=o[10]),i[0]&8192&&(s.viewportScale=o[13]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function _n(e){let t,n;return t=new xt({props:{target:e[4],editor:et(e[28].target.selector),annotation:e[28],style:e[1],transform:e[10],viewportScale:e[13]}}),t.$on("change",function(){V(e[17](e[28]))&&e[17](e[28]).apply(this,arguments)}),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&16&&(s.target=e[4]),i[0]&64&&(s.editor=et(e[28].target.selector)),i[0]&64&&(s.annotation=e[28]),i[0]&2&&(s.style=e[1]),i[0]&1024&&(s.transform=e[10]),i[0]&8192&&(s.viewportScale=e[13]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function yn(e){let t=e[28].id,n,o,i=_n(e);return{c(){i.c(),n=le()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&64&&Z(t,t=s[28].id)?(ae(),N(i,1,1,G),ce(),i=_n(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){N(i),o=!1},d(s){s&&O(n),i.d(s)}}}function ai(e){let t,n,o,i,s,r,l=e[12],a=[];for(let c=0;c<l.length;c+=1)a[c]=mn(un(e,l,c));const d=c=>N(a[c],1,1,()=>{a[c]=null});let h=e[4]&&gn(e);return{c(){t=D("svg"),n=D("g");for(let c=0;c<a.length;c+=1)a[c].c();o=D("g"),h&&h.c(),u(o,"class","drawing"),u(t,"class","a9s-annotationlayer"),yt(t,"drawing",e[2])},m(c,f){B(c,t,f),fe(t,n);for(let m=0;m<a.length;m+=1)a[m]&&a[m].m(n,null);fe(t,o),h&&h.m(o,null),e[24](o),e[25](t),i=!0,s||(r=[W(t,"pointerup",function(){V(e[8])&&e[8].apply(this,arguments)}),W(t,"pointerdown",function(){V(e[9])&&e[9].apply(this,arguments)})],s=!0)},p(c,f){if(e=c,f[0]&4226){l=e[12];let m;for(m=0;m<l.length;m+=1){const g=un(e,l,m);a[m]?(a[m].p(g,f),U(a[m],1)):(a[m]=mn(g),a[m].c(),U(a[m],1),a[m].m(n,null))}for(ae(),m=l.length;m<a.length;m+=1)d(m);ce()}e[4]?h?(h.p(e,f),f[0]&16&&U(h,1)):(h=gn(e),h.c(),U(h,1),h.m(o,null)):h&&(ae(),N(h,1,1,()=>{h=null}),ce()),(!i||f[0]&4)&&yt(t,"drawing",e[2])},i(c){if(!i){for(let f=0;f<l.length;f+=1)U(a[f]);U(h),i=!0}},o(c){a=a.filter(Boolean);for(let f=0;f<a.length;f+=1)N(a[f]);N(h),i=!1},d(c){c&&O(t),We(a,c),h&&h.d(),e[24](null),e[25](null),s=!1,re(r)}}}function ci(e,t,n){let o,i,s,r,l,a,d,h,c=G,f=()=>(c(),c=mt(w,P=>n(13,h=P)),w);e.$$.on_destroy.push(()=>c());let{drawingEnabled:m}=t,{image:g}=t,{preferredDrawingMode:p}=t,{state:y}=t,{style:L=void 0}=t,{tool:E,opts:C}=st("rectangle"),{tool:b=E,opts:Y=C}=t,{user:F}=t,X,_,w;Be(()=>f(n(5,w=nn(g,_))));const{selection:A,store:M}=y;gt(e,A,P=>n(23,a=P)),gt(e,M,P=>n(12,d=P));let I=null,R=null;const K=P=>{M.unobserve(I);const Q=P.filter(({editable:j})=>j).map(({id:j})=>j);Q.length>0?(n(6,R=Q.map(j=>M.getAnnotation(j))),I=j=>{const{updated:J}=j.changes;n(6,R=J.map(se=>se.newValue))},M.observe(I,{annotations:Q})):n(6,R=null)},he=P=>{const Q=xe(),j={id:Q,bodies:[],target:{annotation:Q,selector:P.detail,creator:F,created:new Date}};M.addAnnotation(j),A.setSelected(j.id)},ie=P=>Q=>{var _e;const{target:j}=P,J=10*60*1e3,se=((_e=j.creator)==null?void 0:_e.id)!==F.id||!j.created||new Date().getTime()-j.created.getTime()>J;M.updateTarget({...j,selector:Q.detail,created:se?j.created:new Date,updated:se?new Date:null,updatedBy:se?F:null})};function Re(P){Ee[P?"unshift":"push"](()=>{X=P,n(4,X)})}function x(P){Ee[P?"unshift":"push"](()=>{_=P,n(3,_)})}return e.$$set=P=>{"drawingEnabled"in P&&n(0,m=P.drawingEnabled),"image"in P&&n(18,g=P.image),"preferredDrawingMode"in P&&n(19,p=P.preferredDrawingMode),"state"in P&&n(20,y=P.state),"style"in P&&n(1,L=P.style),"tool"in P&&n(2,b=P.tool),"opts"in P&&n(21,Y=P.opts),"user"in P&&n(22,F=P.user)},e.$$.update=()=>{e.$$.dirty[0]&2621440&&n(11,o=(Y==null?void 0:Y.drawingMode)||p),e.$$.dirty[0]&8&&n(10,i=an(_)),e.$$.dirty[0]&8&&n(9,{onPointerDown:s,onPointerUp:r}=cn(_,M),s,(n(8,r),n(3,_))),e.$$.dirty[0]&8388608&&n(7,l=P=>a.selected.find(Q=>Q.id===P.id&&Q.editable)),e.$$.dirty[0]&8388608&&K(a.selected)},[m,L,b,_,X,w,R,l,r,s,i,o,d,h,A,M,he,ie,g,p,y,Y,F,a,Re,x]}class wn extends oe{constructor(t){super(),ne(this,t,ci,ai,Z,{drawingEnabled:0,image:18,preferredDrawingMode:19,state:20,style:1,tool:2,opts:21,user:22},null,[-1,-1])}}function fi(e,t,n,o,i){bn(e,t,n||0,o||e.length-1,i||ui)}function bn(e,t,n,o,i){for(;o>n;){if(o-n>600){var s=o-n+1,r=t-n+1,l=Math.log(s),a=.5*Math.exp(2*l/3),d=.5*Math.sqrt(l*a*(s-a)/s)*(r-s/2<0?-1:1),h=Math.max(n,Math.floor(t-r*a/s+d)),c=Math.min(o,Math.floor(t+(s-r)*a/s+d));bn(e,t,h,c,i)}var f=e[t],m=n,g=o;for(Ce(e,n,t),i(e[o],f)>0&&Ce(e,n,o);m<g;){for(Ce(e,m,g),m++,g--;i(e[m],f)<0;)m++;for(;i(e[g],f)>0;)g--}i(e[n],f)===0?Ce(e,n,g):(g++,Ce(e,g,o)),g<=t&&(n=g+1),t<=g&&(o=g-1)}}function Ce(e,t,n){var o=e[t];e[t]=e[n],e[n]=o}function ui(e,t){return e<t?-1:e>t?1:0}class di{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(!Fe(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?i(l):l;Fe(t,a)&&(n.leaf?o.push(l):at(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!Fe(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(Fe(t,r)){if(n.leaf||at(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=ve([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let l,a,d;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],l=r.pop(),d=!0),o.leaf){const h=hi(t,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!d&&!o.leaf&&at(o,i)?(s.push(o),r.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],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,l;if(s<=r)return l=ve(t.slice(n,o+1)),Me(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=ve([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),d=a*Math.ceil(Math.sqrt(r));En(t,n,o,d,this.compareMinX);for(let h=n;h<=o;h+=d){const c=Math.min(h+d-1,o);En(t,h,c,a,this.compareMinY);for(let f=h;f<=c;f+=a){const m=Math.min(f+a-1,c);l.children.push(this._build(t,f,m,i-1))}}return Me(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const d=n.children[a],h=lt(d),c=pi(t,d)-h;c<r?(r=c,s=h<s?h:s,l=d):c===r&&h<s&&(s=h,l=d)}n=l||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),ke(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),l=ve(o.children.splice(r,o.children.length-r));l.height=o.height,l.leaf=o.leaf,Me(o,this.toBBox),Me(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=ve([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Me(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let l=n;l<=o-n;l++){const a=Pe(t,0,l,this.toBBox),d=Pe(t,l,o,this.toBBox),h=_i(a,d),c=lt(a)+lt(d);h<s?(s=h,i=l,r=c<r?c:r):h===s&&c<r&&(r=c,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:mi,s=t.leaf?this.compareMinY:gi,r=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,s);r<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=Pe(t,0,n,s),l=Pe(t,o-n,o,s);let a=Ge(r)+Ge(l);for(let d=n;d<o-n;d++){const h=t.children[d];ke(r,t.leaf?s(h):h),a+=Ge(r)}for(let d=o-n-1;d>=n;d--){const h=t.children[d];ke(l,t.leaf?s(h):h),a+=Ge(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)ke(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():Me(t[n],this.toBBox)}}function hi(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 Me(e,t){Pe(e,0,e.children.length,t,e)}function Pe(e,t,n,o,i){i||(i=ve(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];ke(i,e.leaf?o(r):r)}return i}function ke(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 mi(e,t){return e.minX-t.minX}function gi(e,t){return e.minY-t.minY}function lt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ge(e){return e.maxX-e.minX+(e.maxY-e.minY)}function pi(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 _i(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 at(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Fe(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function ve(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function En(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;fi(e,r,t,n,i),s.push(t,r,r,n)}}const yi=()=>{const e=new di,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=c=>{const{minX:f,minY:m,maxX:g,maxY:p}=c.selector.geometry.bounds,y={minX:f,minY:m,maxX:g,maxY:p,target:c};e.insert(y),t.set(c.annotation,y)},s=c=>{const f=t.get(c.annotation);e.remove(f),t.delete(c.annotation)};return{all:n,clear:o,getAt:(c,f)=>{const g=e.search({minX:c,minY:f,maxX:c,maxY:f}).map(p=>p.target).filter(p=>p.selector.type===H.RECTANGLE||At(p.selector,c,f));if(g.length>0)return g.sort((p,y)=>Ke(p.selector)-Ke(y.selector)),g[0]},getIntersecting:(c,f,m,g)=>e.search({minX:c,minY:f,maxX:c+m,maxY:f+g}).map(p=>p.target),insert:i,remove:s,set:(c,f=!0)=>{f&&o();const m=c.map(g=>{const{minX:p,minY:y,maxX:L,maxY:E}=g.selector.geometry.bounds;return{minX:p,minY:y,maxX:L,maxY:E,target:g}});m.forEach(g=>t.set(g.target.annotation,g)),e.load(m)},size:()=>e.all().length,update:(c,f)=>{s(c),i(f)}}},An=e=>{const t=lo(),n=yi(),o=Kn(t,e.pointerSelectAction),i=Zn(t),s=co();return t.observe(({changes:a})=>{n.set(a.created.map(d=>d.target),!1),a.deleted.forEach(d=>n.remove(d.target)),a.updated.forEach(({oldValue:d,newValue:h})=>n.update(d.target,h.target))}),{store:{...t,getAt:(a,d)=>{const h=n.getAt(a,d);return h?t.getAnnotation(h.annotation):void 0},getIntersecting:(a,d,h,c)=>n.getIntersecting(a,d,h,c).map(f=>t.getAnnotation(f.annotation))},selection:o,hover:i,viewport:s}},Tn=e=>{const t=An(e);return{...t,store:ao(t.store)}},Sn=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(r,l,1,1).data,d=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=d}return o/81},Mn=(e,t)=>{const n=Sn(e),o=n>.6?"dark":"light";console.log(`[Annotorious] Image brightness: ${n.toFixed(1)}. Setting ${o} theme.`),t.setAttribute("data-theme",o)},vn=e=>({...e,drawingEnabled:e.drawingEnabled===void 0?!0:e.drawingEnabled,drawingMode:e.drawingMode||"drag",pointerSelectAction:e.pointerSelectAction||Pt.EDIT}),Ei="",Ai="",Ti="",wi=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=vn(t),i=Tn(o),{hover:s,selection:r,store:l}=i,a=fo(l,r,s,void 0,o.adapter,o.autoSave);let d=Dt(),h=o.style;const c=document.createElement("DIV");c.style.position="relative",c.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(c,n),c.appendChild(n),Mn(n,c);const f=new wn({target:c,props:{drawingEnabled:o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:h,user:d}});f.$on("click",X=>{const{originalEvent:_,annotation:w}=X.detail;w?r.clickSelect(w.id,_):r.isEmpty()||r.clear()});const m=Yt(l,o.adapter),g=X=>{h=X,f.$set({style:h})},p=()=>{f.$destroy(),c.parentNode.insertBefore(n,c),c.parentNode.removeChild(c)},y=()=>d,L=(X,_,w)=>ln(X,_,w),E=(X,_)=>Zt(X,_),C=X=>{const{tool:_,opts:w}=st(X);f.$set({tool:_,opts:w})},b=X=>f.$set({drawingEnabled:X}),Y=X=>{X?r.setSelected(X):r.clear()},F=X=>{d=X,f.$set({user:X})};return{...m,get style(){return h},set style(X){g(X)},destroy:p,getUser:y,listDrawingTools:rn,on:a.on,off:a.off,registerDrawingTool:L,registerShapeEditor:E,setDrawingEnabled:b,setDrawingTool:C,setSelected:Y,setUser:F,state:i}};S.Editor=tt,S.EditorMount=xt,S.Handle=v,S.IdentityTransform=ei,S.PRESENCE_KEY=Eo,S.PolygonEditor=qt,S.RectangleEditor=Jt,S.RectangleUtil=Tt,S.RubberbandRectangle=tn,S.SVGAnnotationLayer=wn,S.ShapeType=H,S.ToolMount=$t,S.W3CImageFormat=To,S.addEventListeners=cn,S.boundsFromPoints=Ie,S.computeArea=Ke,S.createAnonymousGuest=Dt,S.createBaseAnnotator=Yt,S.createBody=eo,S.createDefaultAppearenceProvider=Gt,S.createImageAnnotator=wi,S.createImageAnnotatorState=An,S.createPresenceState=Ao,S.createSVGTransform=an,S.createSvelteImageAnnotatorState=Tn,S.defaultColorProvider=Nt,S.diffAnnotations=kt,S.distance=nt,S.enableResponsive=nn,S.fillDefaults=vn,S.getContributors=$n,S.getEditor=et,S.getTool=st,S.intersects=At,S.isTouch=Uo,S.listDrawingTools=rn,S.parseAll=Rt,S.parseFragmentSelector=St,S.parseSVGSelector=Ot,S.parseW3CBodies=Xt,S.parseW3CImageAnnotation=Ft,S.registerEditor=Zt,S.registerShapeUtil=De,S.registerTool=ln,S.sampleBrightness=Sn,S.serializeAll=uo,S.serializeFragmentSelector=Mt,S.serializeSVGSelector=Bt,S.serializeW3CBodies=Ut,S.serializeW3CImageAnnotation=Ht,S.setTheme=Mn,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
1
+ (function(k,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(k=typeof globalThis<"u"?globalThis:k||self,G(k.Annotorious={}))})(this,function(k){"use strict";function G(){}function vn(e,t){for(const n in t)e[n]=t[n];return e}function gt(e){return e()}function pt(){return Object.create(null)}function oe(e){e.forEach(gt)}function W(e){return typeof e=="function"}function Z(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Ln(e){return Object.keys(e).length===0}function yt(e,...t){if(e==null)return G;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function _t(e,t,n){e.$$.on_destroy.push(yt(t,n))}function On(e,t,n,o){if(e){const i=wt(e,t,n,o);return e[0](i)}}function wt(e,t,n,o){return e[1]&&o?vn(n.ctx.slice(),e[1](o(t))):n.ctx}function In(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let a=0;a<r;a+=1)s[a]=t.dirty[a]|i[a];return s}return t.dirty|i}return t.dirty}function kn(e,t,n,o,i,s){if(i){const r=wt(t,n,o,s);e.p(r,i)}}function Bn(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function le(e,t){e.appendChild(t)}function B(e,t,n){e.insertBefore(t,n||null)}function I(e){e.parentNode&&e.parentNode.removeChild(e)}function Je(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function X(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function bt(e){return document.createTextNode(e)}function ee(){return bt(" ")}function ie(){return bt("")}function q(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function f(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Pn(e){return Array.from(e.childNodes)}function Et(e,t,n){e.classList[n?"add":"remove"](t)}function Yn(e,t,{bubbles:n=!1,cancelable:o=!1}={}){const i=document.createEvent("CustomEvent");return i.initCustomEvent(e,n,o,t),i}let ve;function Le(e){ve=e}function At(){if(!ve)throw new Error("Function called outside component initialization");return ve}function Oe(e){At().$$.on_mount.push(e)}function ge(){const e=At();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Yn(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function pe(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const ye=[],Re=[];let _e=[];const Tt=[],Rn=Promise.resolve();let Ze=!1;function Dn(){Ze||(Ze=!0,Rn.then(St))}function Qe(e){_e.push(e)}const xe=new Set;let we=0;function St(){if(we!==0)return;const e=ve;do{try{for(;we<ye.length;){const t=ye[we];we++,Le(t),Cn(t.$$)}}catch(t){throw ye.length=0,we=0,t}for(Le(null),ye.length=0,we=0;Re.length;)Re.pop()();for(let t=0;t<_e.length;t+=1){const n=_e[t];xe.has(n)||(xe.add(n),n())}_e.length=0}while(ye.length);for(;Tt.length;)Tt.pop()();Ze=!1,xe.clear(),Le(e)}function Cn(e){if(e.fragment!==null){e.update(),oe(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Qe)}}function Xn(e){const t=[],n=[];_e.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),_e=t}const De=new Set;let ue;function se(){ue={r:0,c:[],p:ue}}function re(){ue.r||oe(ue.c),ue=ue.p}function U(e,t){e&&e.i&&(De.delete(e),e.i(t))}function V(e,t,n,o){if(e&&e.o){if(De.has(e))return;De.add(e),ue.c.push(()=>{De.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function fe(e){e&&e.c()}function ae(e,t,n,o){const{fragment:i,after_update:s}=e.$$;i&&i.m(t,n),o||Qe(()=>{const r=e.$$.on_mount.map(gt).filter(W);e.$$.on_destroy?e.$$.on_destroy.push(...r):oe(r),e.$$.on_mount=[]}),s.forEach(Qe)}function ce(e,t){const n=e.$$;n.fragment!==null&&(Xn(n.after_update),oe(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Un(e,t){e.$$.dirty[0]===-1&&(ye.push(e),Dn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function te(e,t,n,o,i,s,r,a=[-1]){const l=ve;Le(e);const c=e.$$={fragment:null,ctx:[],props:s,update:G,not_equal:i,bound:pt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:pt(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};r&&r(c.root);let h=!1;if(c.ctx=n?n(e,t.props||{},(u,m,...d)=>{const g=d.length?d[0]:m;return c.ctx&&i(c.ctx[u],c.ctx[u]=g)&&(!c.skip_bound&&c.bound[u]&&c.bound[u](g),h&&Un(e,u)),m}):[],c.update(),h=!0,oe(c.before_update),c.fragment=o?o(c.ctx):!1,t.target){if(t.hydrate){const u=Pn(t.target);c.fragment&&c.fragment.l(u),u.forEach(I)}else c.fragment&&c.fragment.c();t.intro&&U(e.$$.fragment),ae(e,t.target,t.anchor,t.customElement),St()}Le(l)}class ne{$destroy(){ce(this,1),this.$destroy=G}$on(t,n){if(!W(n))return G;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!Ln(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}var z=(e=>(e.ELLIPSE="ELLIPSE",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(z||{});const $e={},Ce=(e,t)=>$e[e]=t,Xe=e=>$e[e.type].area(e),Mt=(e,t,n)=>$e[e.type].intersects(e,t,n),Ie=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},Nn={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,a=0,l=Math.cos(a),c=Math.sin(a),h=t-o,u=n-i,m=l*h+c*u,d=c*h-l*u;return m*m/(s*s)+d*d/(r*r)<=1}};Ce(z.ELLIPSE,Nn);const Vn={area:e=>{const{points:t}=e.geometry;let n=0,o=t.length-1;for(let i=0;i<t.length;i++)n+=(t[o][0]+t[i][0])*(t[o][1]-t[i][1]),o=i;return Math.abs(.5*n)},intersects:(e,t,n)=>{const{points:o}=e.geometry;let i=!1;for(let s=0,r=o.length-1;s<o.length;r=s++){const a=o[s][0],l=o[s][1],c=o[r][0],h=o[r][1];l>n!=h>n&&t<(c-a)*(n-l)/(h-l)+a&&(i=!i)}return i}};Ce(z.POLYGON,Vn);const vt={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};Ce(z.RECTANGLE,vt);const Lt=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[s,r,a,l,c,h,u]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[m,d,g,_]=[l,c,h,u].map(parseFloat);return{type:z.RECTANGLE,geometry:{x:m,y:d,w:g,h:_,bounds:{minX:m,minY:t?d-_:d,maxX:m+g,maxY:t?d:d+_}}}},Ot=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},It="http://www.w3.org/2000/svg",kt=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},Gn=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${It}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},Fn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(It),i=n.lookupNamespaceURI(null);return o||i?kt(n).firstChild:kt(Gn(n)).firstChild},Hn=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[];if(!o)return;const i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:z.POLYGON,geometry:{points:i,bounds:Ie(i)}}},zn=e=>{const t=Fn(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:z.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},Bt=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Hn(t);if(t.includes("<ellipse "))return zn(t)},Pt=e=>{let t;if(e.type===z.POLYGON){const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`}else if(e.type===z.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`};let Ue;const jn=new Uint8Array(16);function Wn(){if(!Ue&&(Ue=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ue))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ue(jn)}const K=[];for(let e=0;e<256;++e)K.push((e+256).toString(16).slice(1));function qn(e,t=0){return K[e[t+0]]+K[e[t+1]]+K[e[t+2]]+K[e[t+3]]+"-"+K[e[t+4]]+K[e[t+5]]+"-"+K[e[t+6]]+K[e[t+7]]+"-"+K[e[t+8]]+K[e[t+9]]+"-"+K[e[t+10]]+K[e[t+11]]+K[e[t+12]]+K[e[t+13]]+K[e[t+14]]+K[e[t+15]]}const Yt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Rt(e,t,n){if(Yt.randomUUID&&!t&&!e)return Yt.randomUUID();e=e||{};const o=e.random||(e.rng||Wn)();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 qn(o)}var Dt=Object.prototype.hasOwnProperty;function de(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--&&de(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Dt.call(e,n)&&++o&&!Dt.call(t,n)||!(n in t)||!de(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function et(){}function Kn(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const be=[];function tt(e,t=et){let n;const o=new Set;function i(a){if(Kn(e,a)&&(e=a,n)){const l=!be.length;for(const c of o)c[1](),be.push(c,e);if(l){for(let c=0;c<be.length;c+=2)be[c][0](be[c+1]);be.length=0}}}function s(a){i(a(e))}function r(a,l=et){const c=[a,l];return o.add(c),o.size===1&&(n=t(i)||et),a(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Jn=e=>{const{subscribe:t,set:n}=tt(null);let o=null;return t(i=>o=i),e.observe(({changes:i})=>{if(o){i.deleted.some(r=>r.id===o)&&n(null);const s=i.updated.find(({oldValue:r})=>r.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Ct=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Ct||{});const nt={selected:[]},Zn=(e,t="EDIT")=>{const{subscribe:n,set:o}=tt(nt);let i=nt;n(u=>i=u);const s=()=>o(nt),r=()=>{var u;return((u=i.selected)==null?void 0:u.length)===0},a=u=>{if(i.selected.length===0)return!1;const m=typeof u=="string"?u:u.id;return i.selected.some(d=>d.id===m)},l=(u,m)=>{const d=e.getAnnotation(u);if(d){const g=Qn(d,t);o(g==="EDIT"?{selected:[{id:u,editable:!0}],pointerEvent:m}:g==="SELECT"?{selected:[{id:u}],pointerEvent:m}:{selected:[],pointerEvent:m})}else console.warn("Invalid selection: "+u)},c=(u,m=!0)=>{const d=Array.isArray(u)?u:[u],g=d.map(_=>e.getAnnotation(_)).filter(_=>_);o({selected:g.map(({id:_})=>({id:_,editable:m}))}),g.length!==d.length&&console.warn("Invalid selection",u)},h=u=>{if(i.selected.length===0)return!1;const{selected:m}=i;m.filter(({id:d})=>u.includes(d)).length>0&&o({selected:m.filter(({id:d})=>!u.includes(d))})};return e.observe(({changes:u})=>h(u.deleted.map(m=>m.id))),{clear:s,clickSelect:l,get selected(){return i?[...i.selected]:null},get pointerEvent(){return i?i.pointerEvent:null},isEmpty:r,isSelected:a,setSelected:c,subscribe:n}},Qn=(e,t)=>typeof t=="function"?t(e)||"EDIT":t||"EDIT",xn=[];for(let e=0;e<256;++e)xn.push((e+256).toString(16).slice(1));typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const $n=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},eo=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},to=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!de(o,n)?o:void 0}}).filter(({oldBody:n})=>n),no=(e,t)=>!de(e.target,t.target),Xt=(e,t)=>{const n=$n(e,t),o=eo(e,t),i=to(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:no(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var F=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e))(F||{});const oo=(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:r}=e.options,a=l=>(l==null?void 0:l.length)>0;if(!(a(i.created)||a(i.deleted))){const l=(n=i.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),c=(o=i.updated)==null?void 0:o.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!c||r==="TARGET_ONLY"&&c&&!l)return!1}}if(e.options.annotations){const r=new Set([...i.created.map(a=>a.id),...i.deleted.map(a=>a.id),...i.updated.map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},io=(e,t)=>{const n=new Set((e.created||[]).map(u=>u.id)),o=new Set((e.updated||[]).map(({newValue:u})=>u.id)),i=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),r=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>n.has(u.id)||o.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(e.created||[]).filter(u=>!s.has(u.id)).map(u=>r.has(u.id)?t.updated.find(({oldValue:m})=>m.id===u.id).newValue:u),...t.created||[]],c=[...(e.deleted||[]).filter(u=>!i.has(u.id)),...(t.deleted||[]).filter(u=>!n.has(u.id))],h=[...(e.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:m,newValue:d}=u;if(r.has(d.id)){const g=t.updated.find(_=>_.oldValue.id===d.id).newValue;return Xt(m,g)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:c,updated:h}},so=e=>e.id!==void 0,ro=()=>{const e=new Map,t=new Map,n=[],o=(p,E={})=>n.push({onChange:p,options:E}),i=p=>{const E=n.findIndex(b=>b.onChange==p);E>-1&&n.splice(E,1)},s=(p,E)=>{const b={origin:p,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...e.values()]};n.forEach(v=>{oo(v,b)&&v.onChange(b)})},r=(p,E=F.LOCAL)=>{if(e.get(p.id))throw Error(`Cannot add annotation ${p.id} - exists already`);e.set(p.id,p),p.bodies.forEach(b=>t.set(b.id,p.id)),s(E,{created:[p]})},a=(p,E)=>{const b=typeof p=="string"?E:p,v=typeof p=="string"?p:p.id,P=e.get(v);if(P){const C=Xt(P,b);return v===b.id?e.set(v,b):(e.delete(v),e.set(b.id,b)),P.bodies.forEach(Q=>t.delete(Q.id)),b.bodies.forEach(Q=>t.set(Q.id,b.id)),C}else console.warn(`Cannot update annotation ${v} - does not exist`)},l=(p,E=F.LOCAL,b=F.LOCAL)=>{const v=so(E)?b:E,P=a(p,E);P&&s(v,{updated:[P]})},c=(p,E=F.LOCAL)=>{const b=p.reduce((v,P)=>{const C=a(P);return C?[...v,C]:v},[]);b.length>0&&s(E,{updated:b})},h=(p,E=F.LOCAL)=>{const b=e.get(p.annotation);if(b){const v={...b,bodies:[...b.bodies,p]};e.set(b.id,v),t.set(p.id,v.id),s(E,{updated:[{oldValue:b,newValue:v,bodiesCreated:[p]}]})}else console.warn(`Attempt to add body to missing annotation: ${p.annotation}`)},u=()=>[...e.values()],m=(p=F.LOCAL)=>{const E=[...e.values()];e.clear(),t.clear(),s(p,{deleted:E})},d=(p,E=!0,b=F.LOCAL)=>{if(E){const v=[...e.values()];e.clear(),t.clear(),p.forEach(P=>{e.set(P.id,P),P.bodies.forEach(C=>t.set(C.id,P.id))}),s(b,{created:p,deleted:v})}else{const v=p.reduce((P,C)=>{const Q=e.get(C.id);return Q?[...P,Q]:P},[]);if(v.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${v.map(P=>P.id).join(", ")}`);p.forEach(P=>{e.set(P.id,P),P.bodies.forEach(C=>t.set(C.id,P.id))}),s(b,{created:p})}},g=p=>{const E=typeof p=="string"?p:p.id,b=e.get(E);if(b)return e.delete(E),b.bodies.forEach(v=>t.delete(v.id)),b;console.warn(`Attempt to delete missing annotation: ${E}`)},_=(p,E=F.LOCAL)=>{const b=g(p);b&&s(E,{deleted:[b]})},A=(p,E=F.LOCAL)=>{const b=p.reduce((v,P)=>{const C=g(P);return C?[...v,C]:v},[]);b.length>0&&s(E,{deleted:b})},w=(p,E=F.LOCAL)=>{const b=e.get(p.annotation);if(b){const v=b.bodies.find(P=>P.id===p.id);if(v){t.delete(v.id);const P={...b,bodies:b.bodies.filter(C=>C.id!==p.id)};e.set(b.id,P),s(E,{updated:[{oldValue:b,newValue:P,bodiesDeleted:[v]}]})}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}`)},y=p=>{const E=e.get(p);return E?{...E}:void 0},T=p=>{const E=t.get(p);if(E){const b=y(E).bodies.find(v=>v.id===p);if(b)return b;console.error(`Store integrity error: body ${p} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${p}`)},S=(p,E)=>{if(p.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const b=e.get(p.annotation);if(b){const v=b.bodies.find(C=>C.id===p.id),P={...b,bodies:b.bodies.map(C=>C.id===v.id?E:C)};return e.set(b.id,P),v.id!==E.id&&(t.delete(v.id),t.set(E.id,P.id)),{oldValue:b,newValue:P,bodiesUpdated:[{oldBody:v,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${p.annotation}`)},Y=(p,E,b=F.LOCAL)=>{const v=S(p,E);s(b,{updated:[v]})},D=(p,E=F.LOCAL)=>{const b=p.map(v=>S({id:v.id,annotation:v.annotation},v));s(E,{updated:b})},N=p=>{const E=e.get(p.annotation);if(E){const b={...E,target:{...E.target,...p}};return e.set(E.id,b),{oldValue:E,newValue:b,targetUpdated:{oldTarget:E.target,newTarget:p}}}else console.warn(`Attempt to update target on missing annotation: ${p.annotation}`)};return{addAnnotation:r,addBody:h,all:u,bulkAddAnnotation:d,bulkDeleteAnnotation:A,bulkUpdateAnnotation:c,bulkUpdateBodies:D,bulkUpdateTargets:(p,E=F.LOCAL)=>{const b=p.map(N).filter(v=>v);b.length>0&&s(E,{updated:b})},clear:m,deleteAnnotation:_,deleteBody:w,getAnnotation:y,getBody:T,observe:o,unobserve:i,updateAnnotation:l,updateBody:Y,updateTarget:(p,E=F.LOCAL)=>{const b=N(p);b&&s(E,{updated:[b]})}}},lo=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let ao=()=>({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 co=250,uo=e=>{const t=ao(),n=[];let o=-1,i=!1,s=0;const r=d=>{if(!i){const{changes:g}=d,_=performance.now();if(_-s>co)n.splice(o+1),n.push(g),o=n.length-1;else{const A=n.length-1;n[A]=io(n[A],g)}s=_}i=!1};e.observe(r,{origin:F.LOCAL});const a=d=>(d==null?void 0:d.length)>0&&e.bulkDeleteAnnotation(d),l=d=>(d==null?void 0:d.length)>0&&e.bulkAddAnnotation(d,!1),c=d=>(d==null?void 0:d.length)>0&&e.bulkUpdateAnnotation(d.map(({oldValue:g})=>g)),h=d=>(d==null?void 0:d.length)>0&&e.bulkUpdateAnnotation(d.map(({newValue:g})=>g)),u=d=>(d==null?void 0:d.length)>0&&e.bulkAddAnnotation(d,!1),m=d=>(d==null?void 0:d.length)>0&&e.bulkDeleteAnnotation(d);return{canRedo:()=>n.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(r),on:(d,g)=>t.on(d,g),redo:()=>{if(n.length-1>o){i=!0;const{created:d,updated:g,deleted:_}=n[o+1];l(d),h(g),m(_),t.emit("redo",n[o+1]),o+=1}},undo:()=>{if(o>-1){i=!0;const{created:d,updated:g,deleted:_}=n[o];a(d),c(g),u(_),t.emit("undo",n[o]),o-=1}}}},fo=()=>{const{subscribe:e,set:t}=tt([]);return{subscribe:e,set:t}},ho=(e,t,n,o)=>{const{store:i,selection:s,hover:r,viewport:a}=e,l=new Map;let c=[],h,u;const m=(w,y)=>{l.has(w)?l.get(w).push(y):l.set(w,[y])},d=(w,y)=>{const T=l.get(w);T&&T.indexOf(y)>0&&T.splice(T.indexOf(y),1)},g=(w,y,T)=>{l.has(w)&&setTimeout(()=>{l.get(w).forEach(S=>{if(n){const Y=Array.isArray(y)?y.map(N=>n.serialize(N)):n.serialize(y),D=T?T instanceof PointerEvent?T:n.serialize(T):void 0;S(Y,D)}else S(y,T)})},1)},_=()=>{const{selected:w}=s,y=w.map(({id:T})=>i.getAnnotation(T));y.forEach(T=>{const S=c.find(Y=>Y.id===T.id);(!S||!de(S,T))&&g("updateAnnotation",T,S)}),c=c.map(T=>y.find(({id:Y})=>Y===T.id)||T)};s.subscribe(({selected:w})=>{if(!(c.length===0&&w.length===0)){if(c.length===0&&w.length>0)c=w.map(({id:y})=>i.getAnnotation(y));else if(c.length>0&&w.length===0)c.forEach(y=>{const T=i.getAnnotation(y.id);T&&!de(T,y)&&g("updateAnnotation",T,y)}),c=[];else{const y=new Set(c.map(S=>S.id)),T=new Set(w.map(({id:S})=>S));c.filter(S=>!T.has(S.id)).forEach(S=>{const Y=i.getAnnotation(S.id);Y&&!de(Y,S)&&g("updateAnnotation",Y,S)}),c=[...c.filter(S=>T.has(S.id)),...w.filter(({id:S})=>!y.has(S)).map(({id:S})=>i.getAnnotation(S))]}g("selectionChanged",c)}}),r.subscribe(w=>{!h&&w?g("mouseEnterAnnotation",i.getAnnotation(w)):h&&!w?g("mouseLeaveAnnotation",i.getAnnotation(h)):h&&w&&(g("mouseLeaveAnnotation",i.getAnnotation(h)),g("mouseEnterAnnotation",i.getAnnotation(w))),h=w}),a==null||a.subscribe(w=>g("viewportIntersect",w.map(i.getAnnotation))),i.observe(w=>{o&&(u&&clearTimeout(u),u=setTimeout(_,1e3));const{created:y,deleted:T}=w.changes;y.forEach(S=>g("createAnnotation",S)),T.forEach(S=>g("deleteAnnotation",S)),w.changes.updated.filter(S=>[...S.bodiesCreated||[],...S.bodiesDeleted||[],...S.bodiesUpdated||[]].length>0).forEach(({oldValue:S,newValue:Y})=>{const D=c.find(N=>N.id===S.id)||S;c=c.map(N=>N.id===S.id?Y:N),g("updateAnnotation",Y,D)})},{origin:F.LOCAL}),i.observe(w=>{if(c){const y=new Set(c.map(S=>S.id)),T=w.changes.updated.filter(({newValue:S})=>y.has(S.id)).map(({newValue:S})=>S);T.length>0&&(c=c.map(S=>T.find(D=>D.id===S.id)||S))}},{origin:F.REMOTE});const A=w=>y=>{const{created:T,deleted:S,updated:Y}=y;T.forEach(D=>g("createAnnotation",D)),S.forEach(D=>g("deleteAnnotation",D)),w?Y.forEach(D=>g("updateAnnotation",D.oldValue,D.newValue)):Y.forEach(D=>g("updateAnnotation",D.newValue,D.oldValue))};return t.on("undo",A(!0)),t.on("redo",A(!1)),{on:m,off:d,emit:g}},mo=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:[]}),go=(e,t,n)=>{const{store:o,selection:i}=e,s=A=>{if(n){const{parsed:w,error:y}=n.parse(A);w?o.addAnnotation(w,F.REMOTE):console.error(y)}else o.addAnnotation(A,F.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=A=>{const w=o.getAnnotation(A);return n&&w?n.serialize(w):w},c=()=>n?o.all().map(n.serialize):o.all(),h=()=>{var A;const w=(((A=i.selected)==null?void 0:A.map(y=>y.id))||[]).map(y=>o.getAnnotation(y));return n?w.map(n.serialize):w},u=A=>fetch(A).then(w=>w.json()).then(w=>(d(w),w)),m=A=>{if(typeof A=="string"){const w=o.getAnnotation(A);return o.deleteAnnotation(A),n?n.serialize(w):w}else{const w=n?n.parse(A).parsed:A;return o.deleteAnnotation(w),A}},d=A=>{if(n){const{parsed:w,failed:y}=mo(n)(A);y.length>0&&console.warn(`Discarded ${y.length} invalid annotations`,y),o.bulkAddAnnotation(w,!0,F.REMOTE)}else o.bulkAddAnnotation(A,!0,F.REMOTE)},g=A=>{A?i.setSelected(A):i.clear()},_=A=>{if(n){const w=n.parse(A).parsed,y=n.serialize(o.getAnnotation(w.id));return o.updateAnnotation(w),y}else{const w=o.getAnnotation(A.id);return o.updateAnnotation(A),w}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:c,getSelected:h,loadAnnotations:u,redo:t.redo,removeAnnotation:m,setAnnotations:d,setSelected:g,undo:t.undo,updateAnnotation:_}};let po=e=>crypto.getRandomValues(new Uint8Array(e)),yo=(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 a=n(i),l=i;for(;l--;)if(r+=e[a[l]&o]||"",r.length===s)return r}}},_o=(e,t=21)=>yo(e,t,po),wo=(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 bo=()=>({isGuest:!0,id:_o("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Eo=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}`},Ao=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,creator:l,...c}=n;return{id:o||`temp-${Eo(n)}`,annotation:t,type:i,purpose:s,value:r,created:a,creator:l?typeof l=="object"?{...l}:l:void 0,...c}}),To=e=>e.map(t=>{var n;const o={...t};return delete o.annotation,(n=o.id)!=null&&n.startsWith("temp-")&&delete o.id,o});wo();const So=(e,t=!1)=>({parse:i=>Ut(i,t),serialize:i=>Nt(i,e)}),Ut=(e,t=!1)=>{const n=e.id||Rt(),{body:o,...i}=e,s=Ao(o,n),r=Array.isArray(e.target)?e.target[0]:e.target,a=Array.isArray(r.selector)?r.selector[0]:r.selector,l=a.type==="FragmentSelector"?Lt(a,t):a.type==="SvgSelector"?Bt(a):void 0;return l?{parsed:{...i,id:n,bodies:s,target:{...i.target,annotation:n,selector:l}}}:{error:Error(`Unknown selector type: ${a.type}`)}},Nt=(e,t)=>{const n=e.target.selector,o=n.type==z.RECTANGLE?Ot(n.geometry):Pt(n);return{...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:To(e.bodies),target:{source:t,selector:o}}};function Vt(e,t,n){const o=e.slice();return o[11]=t[n],o[13]=n,o}function Gt(e){let t,n,o,i,s;return{c(){t=X("rect"),f(t,"class","a9s-corner-handle"),f(t,"x",n=e[11][0]-e[3]/2),f(t,"y",o=e[11][1]-e[3]/2),f(t,"height",e[3]),f(t,"width",e[3])},m(r,a){B(r,t,a),i||(s=q(t,"pointerdown",function(){W(e[10](L(e[13])))&&e[10](L(e[13])).apply(this,arguments)}),i=!0)},p(r,a){e=r,a&24&&n!==(n=e[11][0]-e[3]/2)&&f(t,"x",n),a&24&&o!==(o=e[11][1]-e[3]/2)&&f(t,"y",o),a&8&&f(t,"height",e[3]),a&8&&f(t,"width",e[3])},d(r){r&&I(t),i=!1,s()}}}function Mo(e){let t,n,o,i,s,r,a,l,c,h,u=e[4].points,m=[];for(let d=0;d<u.length;d+=1)m[d]=Gt(Vt(e,u,d));return{c(){t=X("polygon"),i=ee(),s=X("polygon"),a=ee();for(let d=0;d<m.length;d+=1)m[d].c();l=ie(),f(t,"class","a9s-outer"),f(t,"style",n=e[1]?"display:none;":void 0),f(t,"points",o=e[4].points.map(Ft).join(" ")),f(s,"class","a9s-inner a9s-shape-handle"),f(s,"style",e[1]),f(s,"points",r=e[4].points.map(Ht).join(" "))},m(d,g){B(d,t,g),B(d,i,g),B(d,s,g),B(d,a,g);for(let _=0;_<m.length;_+=1)m[_]&&m[_].m(d,g);B(d,l,g),c||(h=[q(t,"pointerdown",function(){W(e[10](L.SHAPE))&&e[10](L.SHAPE).apply(this,arguments)}),q(s,"pointerdown",function(){W(e[10](L.SHAPE))&&e[10](L.SHAPE).apply(this,arguments)})],c=!0)},p(d,g){if(e=d,g&2&&n!==(n=e[1]?"display:none;":void 0)&&f(t,"style",n),g&16&&o!==(o=e[4].points.map(Ft).join(" "))&&f(t,"points",o),g&2&&f(s,"style",e[1]),g&16&&r!==(r=e[4].points.map(Ht).join(" "))&&f(s,"points",r),g&1048){u=e[4].points;let _;for(_=0;_<u.length;_+=1){const A=Vt(e,u,_);m[_]?m[_].p(A,g):(m[_]=Gt(A),m[_].c(),m[_].m(l.parentNode,l))}for(;_<m.length;_+=1)m[_].d(1);m.length=u.length}},d(d){d&&I(t),d&&I(i),d&&I(s),d&&I(a),Je(m,d),d&&I(l),c=!1,oe(h)}}}function vo(e){let t,n;return t=new it({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Mo,({grab:o})=>({10:o}),({grab:o})=>o?1024:0]},$$scope:{ctx:e}}}),t.$on("change",e[7]),t.$on("grab",e[8]),t.$on("release",e[9]),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&17434&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}const Ft=e=>e.join(","),Ht=e=>e.join(",");function Lo(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:a}=t,{viewportScale:l=1}=t;const c=(d,g,_)=>{let A;g===L.SHAPE?A=d.geometry.points.map(([y,T])=>[y+_[0],T+_[1]]):A=d.geometry.points.map(([y,T],S)=>g===L(S)?[y+_[0],T+_[1]]:[y,T]);const w=Ie(A);return{...d,geometry:{points:A,bounds:w}}};function h(d){pe.call(this,e,d)}function u(d){pe.call(this,e,d)}function m(d){pe.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,s=d.shape),"computedStyle"in d&&n(1,r=d.computedStyle),"transform"in d&&n(2,a=d.transform),"viewportScale"in d&&n(6,l=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/l)},[s,r,a,i,o,c,l,h,u,m]}class zt extends ne{constructor(t){super(),te(this,t,Lo,vo,Z,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}function Oo(e){let t,n,o,i,s,r,a,l,c,h,u,m,d,g,_,A,w,y,T,S,Y,D,N,p,E,b,v,P,C,Q,Se,Me,Ye,O,J,H,he,j,me,ze,dt,x,je,We,ht,$,qe,Ke,mt,Mn;return{c(){t=X("rect"),a=ee(),l=X("rect"),d=ee(),g=X("rect"),y=ee(),T=X("rect"),N=ee(),p=X("rect"),P=ee(),C=X("rect"),Ye=ee(),O=X("rect"),he=ee(),j=X("rect"),dt=ee(),x=X("rect"),ht=ee(),$=X("rect"),f(t,"class","a9s-outer"),f(t,"style",n=e[1]?"display:none;":void 0),f(t,"x",o=e[4].x),f(t,"y",i=e[4].y),f(t,"width",s=e[4].w),f(t,"height",r=e[4].h),f(l,"class","a9s-inner a9s-shape-handle"),f(l,"style",e[1]),f(l,"x",c=e[4].x),f(l,"y",h=e[4].y),f(l,"width",u=e[4].w),f(l,"height",m=e[4].h),f(g,"class","a9s-edge-handle a9s-edge-handle-top"),f(g,"x",_=e[4].x),f(g,"y",A=e[4].y),f(g,"height",1),f(g,"width",w=e[4].w),f(T,"class","a9s-edge-handle a9s-edge-handle-right"),f(T,"x",S=e[4].x+e[4].w),f(T,"y",Y=e[4].y),f(T,"height",D=e[4].h),f(T,"width",1),f(p,"class","a9s-edge-handle a9s-edge-handle-bottom"),f(p,"x",E=e[4].x),f(p,"y",b=e[4].y+e[4].h),f(p,"height",1),f(p,"width",v=e[4].w),f(C,"class","a9s-edge-handle a9s-edge-handle-left"),f(C,"x",Q=e[4].x),f(C,"y",Se=e[4].y),f(C,"height",Me=e[4].h),f(C,"width",1),f(O,"class","a9s-corner-handle a9s-corner-handle-topleft"),f(O,"x",J=e[4].x-e[3]/2),f(O,"y",H=e[4].y-e[3]/2),f(O,"height",e[3]),f(O,"width",e[3]),f(j,"class","a9s-corner-handle a9s-corner-handle-topright"),f(j,"x",me=e[4].x+e[4].w-e[3]/2),f(j,"y",ze=e[4].y-e[3]/2),f(j,"height",e[3]),f(j,"width",e[3]),f(x,"class","a9s-corner-handle a9s-corner-handle-bottomright"),f(x,"x",je=e[4].x+e[4].w-e[3]/2),f(x,"y",We=e[4].y+e[4].h-e[3]/2),f(x,"height",e[3]),f(x,"width",e[3]),f($,"class","a9s-corner-handle a9s-corner-handle-bottomleft"),f($,"x",qe=e[4].x-e[3]/2),f($,"y",Ke=e[4].y+e[4].h-e[3]/2),f($,"height",e[3]),f($,"width",e[3])},m(R,M){B(R,t,M),B(R,a,M),B(R,l,M),B(R,d,M),B(R,g,M),B(R,y,M),B(R,T,M),B(R,N,M),B(R,p,M),B(R,P,M),B(R,C,M),B(R,Ye,M),B(R,O,M),B(R,he,M),B(R,j,M),B(R,dt,M),B(R,x,M),B(R,ht,M),B(R,$,M),mt||(Mn=[q(t,"pointerdown",function(){W(e[10](L.SHAPE))&&e[10](L.SHAPE).apply(this,arguments)}),q(l,"pointerdown",function(){W(e[10](L.SHAPE))&&e[10](L.SHAPE).apply(this,arguments)}),q(g,"pointerdown",function(){W(e[10](L.TOP))&&e[10](L.TOP).apply(this,arguments)}),q(T,"pointerdown",function(){W(e[10](L.RIGHT))&&e[10](L.RIGHT).apply(this,arguments)}),q(p,"pointerdown",function(){W(e[10](L.BOTTOM))&&e[10](L.BOTTOM).apply(this,arguments)}),q(C,"pointerdown",function(){W(e[10](L.LEFT))&&e[10](L.LEFT).apply(this,arguments)}),q(O,"pointerdown",function(){W(e[10](L.TOP_LEFT))&&e[10](L.TOP_LEFT).apply(this,arguments)}),q(j,"pointerdown",function(){W(e[10](L.TOP_RIGHT))&&e[10](L.TOP_RIGHT).apply(this,arguments)}),q(x,"pointerdown",function(){W(e[10](L.BOTTOM_RIGHT))&&e[10](L.BOTTOM_RIGHT).apply(this,arguments)}),q($,"pointerdown",function(){W(e[10](L.BOTTOM_LEFT))&&e[10](L.BOTTOM_LEFT).apply(this,arguments)})],mt=!0)},p(R,M){e=R,M&2&&n!==(n=e[1]?"display:none;":void 0)&&f(t,"style",n),M&16&&o!==(o=e[4].x)&&f(t,"x",o),M&16&&i!==(i=e[4].y)&&f(t,"y",i),M&16&&s!==(s=e[4].w)&&f(t,"width",s),M&16&&r!==(r=e[4].h)&&f(t,"height",r),M&2&&f(l,"style",e[1]),M&16&&c!==(c=e[4].x)&&f(l,"x",c),M&16&&h!==(h=e[4].y)&&f(l,"y",h),M&16&&u!==(u=e[4].w)&&f(l,"width",u),M&16&&m!==(m=e[4].h)&&f(l,"height",m),M&16&&_!==(_=e[4].x)&&f(g,"x",_),M&16&&A!==(A=e[4].y)&&f(g,"y",A),M&16&&w!==(w=e[4].w)&&f(g,"width",w),M&16&&S!==(S=e[4].x+e[4].w)&&f(T,"x",S),M&16&&Y!==(Y=e[4].y)&&f(T,"y",Y),M&16&&D!==(D=e[4].h)&&f(T,"height",D),M&16&&E!==(E=e[4].x)&&f(p,"x",E),M&16&&b!==(b=e[4].y+e[4].h)&&f(p,"y",b),M&16&&v!==(v=e[4].w)&&f(p,"width",v),M&16&&Q!==(Q=e[4].x)&&f(C,"x",Q),M&16&&Se!==(Se=e[4].y)&&f(C,"y",Se),M&16&&Me!==(Me=e[4].h)&&f(C,"height",Me),M&24&&J!==(J=e[4].x-e[3]/2)&&f(O,"x",J),M&24&&H!==(H=e[4].y-e[3]/2)&&f(O,"y",H),M&8&&f(O,"height",e[3]),M&8&&f(O,"width",e[3]),M&24&&me!==(me=e[4].x+e[4].w-e[3]/2)&&f(j,"x",me),M&24&&ze!==(ze=e[4].y-e[3]/2)&&f(j,"y",ze),M&8&&f(j,"height",e[3]),M&8&&f(j,"width",e[3]),M&24&&je!==(je=e[4].x+e[4].w-e[3]/2)&&f(x,"x",je),M&24&&We!==(We=e[4].y+e[4].h-e[3]/2)&&f(x,"y",We),M&8&&f(x,"height",e[3]),M&8&&f(x,"width",e[3]),M&24&&qe!==(qe=e[4].x-e[3]/2)&&f($,"x",qe),M&24&&Ke!==(Ke=e[4].y+e[4].h-e[3]/2)&&f($,"y",Ke),M&8&&f($,"height",e[3]),M&8&&f($,"width",e[3])},d(R){R&&I(t),R&&I(a),R&&I(l),R&&I(d),R&&I(g),R&&I(y),R&&I(T),R&&I(N),R&&I(p),R&&I(P),R&&I(C),R&&I(Ye),R&&I(O),R&&I(he),R&&I(j),R&&I(dt),R&&I(x),R&&I(ht),R&&I($),mt=!1,oe(Mn)}}}function Io(e){let t,n;return t=new it({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Oo,({grab:o})=>({10:o}),({grab:o})=>o?1024:0]},$$scope:{ctx:e}}}),t.$on("grab",e[7]),t.$on("change",e[8]),t.$on("release",e[9]),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&3098&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function ko(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:a}=t,{viewportScale:l=1}=t;const c=(d,g,_)=>{const A=d.geometry.bounds;let[w,y]=[A.minX,A.minY],[T,S]=[A.maxX,A.maxY];const[Y,D]=_;if(g===L.SHAPE)w+=Y,T+=Y,y+=D,S+=D;else{switch(g){case L.TOP:case L.TOP_LEFT:case L.TOP_RIGHT:{y+=D;break}case L.BOTTOM:case L.BOTTOM_LEFT:case L.BOTTOM_RIGHT:{S+=D;break}}switch(g){case L.LEFT:case L.TOP_LEFT:case L.BOTTOM_LEFT:{w+=Y;break}case L.RIGHT:case L.TOP_RIGHT:case L.BOTTOM_RIGHT:{T+=Y;break}}}const N=Math.min(w,T),p=Math.min(y,S),E=Math.abs(T-w),b=Math.abs(S-y);return{...d,geometry:{x:N,y:p,w:E,h:b,bounds:{minX:N,minY:p,maxX:N+E,maxY:p+b}}}};function h(d){pe.call(this,e,d)}function u(d){pe.call(this,e,d)}function m(d){pe.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,s=d.shape),"computedStyle"in d&&n(1,r=d.computedStyle),"transform"in d&&n(2,a=d.transform),"viewportScale"in d&&n(6,l=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/l)},[s,r,a,i,o,c,l,h,u,m]}class jt extends ne{constructor(t){super(),te(this,t,ko,Io,Z,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}const Wt=new Map([[z.RECTANGLE,jt],[z.POLYGON,zt]]),ot=e=>Wt.get(e.type),qt=(e,t)=>Wt.set(e,t),L=e=>`HANDLE-${e}`;L.SHAPE="SHAPE",L.TOP="TOP",L.RIGHT="RIGHT",L.BOTTOM="BOTTOM",L.LEFT="LEFT",L.TOP_LEFT="TOP_LEFT",L.TOP_RIGHT="TOP_RIGHT",L.BOTTOM_RIGHT="BOTTOM_RIGHT",L.BOTTOM_LEFT="BOTTOM_LEFT";const Bo=e=>({}),Kt=e=>({grab:e[0]});function Po(e){let t,n,o,i;const s=e[7].default,r=On(s,e,e[6],Kt);return{c(){t=X("g"),r&&r.c(),f(t,"class","a9s-annotation selected")},m(a,l){B(a,t,l),r&&r.m(t,null),n=!0,o||(i=[q(t,"pointerup",e[2]),q(t,"pointermove",e[1])],o=!0)},p(a,[l]){r&&r.p&&(!n||l&64)&&kn(r,s,a,a[6],n?In(s,a[6],l,Bo):Bn(a[6]),Kt)},i(a){n||(U(r,a),n=!0)},o(a){V(r,a),n=!1},d(a){a&&I(t),r&&r.d(a),o=!1,oe(i)}}}function Yo(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=ge();let{shape:r}=t,{editor:a}=t,{transform:l}=t,c=null,h,u=null;const m=_=>A=>{c=_,h=l.elementToImage(A.offsetX,A.offsetY),u=r,A.target.setPointerCapture(A.pointerId),s("grab")},d=_=>{if(c){const[A,w]=l.elementToImage(_.offsetX,_.offsetY),y=[A-h[0],w-h[1]];n(3,r=a(u,c,y)),s("change",r)}},g=_=>{_.target.releasePointerCapture(_.pointerId),c=null,u=r,s("release")};return e.$$set=_=>{"shape"in _&&n(3,r=_.shape),"editor"in _&&n(4,a=_.editor),"transform"in _&&n(5,l=_.transform),"$$scope"in _&&n(6,i=_.$$scope)},[m,d,g,r,a,l,i,o]}class it extends ne{constructor(t){super(),te(this,t,Yo,Po,Z,{shape:3,editor:4,transform:5})}}const Ne=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i}=n;let s="";return o&&(s+=`fill:${o};stroke:${o};`),s+=`fill-opacity:${i||"0.25"};`,s}};function Ro(e,t,n){let o;const i=ge();let{annotation:s}=t,{editor:r}=t,{style:a=void 0}=t,{target:l}=t,{transform:c}=t,{viewportScale:h}=t,u;return Oe(()=>(n(6,u=new r({target:l,props:{shape:s.target.selector,computedStyle:o,transform:c,viewportScale:h}})),u.$on("change",m=>{u.$$set({shape:m.detail}),i("change",m.detail)}),u.$on("grab",m=>i("grab",m.detail)),u.$on("release",m=>i("release",m.detail)),()=>{u.$destroy()})),e.$$set=m=>{"annotation"in m&&n(0,s=m.annotation),"editor"in m&&n(1,r=m.editor),"style"in m&&n(2,a=m.style),"target"in m&&n(3,l=m.target),"transform"in m&&n(4,c=m.transform),"viewportScale"in m&&n(5,h=m.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&(o=Ne(s,a)),e.$$.dirty&65&&s&&(u==null||u.$set({shape:s.target.selector})),e.$$.dirty&80&&u&&u.$set({transform:c}),e.$$.dirty&96&&u&&u.$set({viewportScale:h})},[s,r,a,l,c,h,u]}class Jt extends ne{constructor(t){super(),te(this,t,Ro,null,Z,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Do(e,t,n){const o=ge();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:a}=t,{viewportScale:l}=t,c;return Oe(()=>{const h=s.closest("svg"),u=[],m=(d,g,_)=>{h.addEventListener(d,g,_),u.push(()=>h.removeEventListener(d,g,_))};return n(5,c=new r({target:s,props:{addEventListener:m,drawingMode:i,transform:a,viewportScale:l}})),c.$on("create",d=>o("create",d.detail)),()=>{u.forEach(d=>d()),c.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,i=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,a=h.transform),"viewportScale"in h&&n(4,l=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&c&&c.$set({transform:a}),e.$$.dirty&48&&c&&c.$set({viewportScale:l})},[i,s,r,a,l,c]}class Zt extends ne{constructor(t){super(),te(this,t,Do,null,Z,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Qt(e){let t,n;return{c(){t=X("rect"),n=X("rect"),f(t,"class","a9s-outer"),f(t,"x",e[1]),f(t,"y",e[2]),f(t,"width",e[3]),f(t,"height",e[4]),f(n,"class","a9s-inner"),f(n,"x",e[1]),f(n,"y",e[2]),f(n,"width",e[3]),f(n,"height",e[4])},m(o,i){B(o,t,i),B(o,n,i)},p(o,i){i&2&&f(t,"x",o[1]),i&4&&f(t,"y",o[2]),i&8&&f(t,"width",o[3]),i&16&&f(t,"height",o[4]),i&2&&f(n,"x",o[1]),i&4&&f(n,"y",o[2]),i&8&&f(n,"width",o[3]),i&16&&f(n,"height",o[4])},d(o){o&&I(t),o&&I(n)}}}function Co(e){let t,n=e[0]&&Qt(e);return{c(){t=X("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=Qt(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:G,o:G,d(o){o&&I(t),n&&n.d()}}}function Xo(e,t,n){const o=ge();let{addEventListener:i}=t,{drawingMode:s}=t,{transform:r}=t,a,l,c,h,u,m,d;const g=y=>{a=performance.now(),s==="drag"&&(n(0,l=r.elementToImage(y.offsetX,y.offsetY)),c=l,n(1,h=l[0]),n(2,u=l[1]),n(3,m=1),n(4,d=1))},_=y=>{l&&(c=r.elementToImage(y.offsetX,y.offsetY),n(1,h=Math.min(c[0],l[0])),n(2,u=Math.min(c[1],l[1])),n(3,m=Math.abs(c[0]-l[0])),n(4,d=Math.abs(c[1]-l[1])))},A=y=>{const T=performance.now()-a;if(s==="click"){if(T>300)return;y.stopPropagation(),l?w():(n(0,l=r.elementToImage(y.offsetX,y.offsetY)),c=l,n(1,h=l[0]),n(2,u=l[1]),n(3,m=1),n(4,d=1))}else l&&(T>300||m*d>100?(y.stopPropagation(),w()):(n(0,l=null),c=null))},w=()=>{if(m*d>15){const y={type:z.RECTANGLE,geometry:{bounds:{minX:h,minY:u,maxX:h+m,maxY:u+d},x:h,y:u,w:m,h:d}};o("create",y)}n(0,l=null),c=null};return Oe(()=>{i("pointerdown",g),i("pointermove",_),i("pointerup",A,!0)}),e.$$set=y=>{"addEventListener"in y&&n(5,i=y.addEventListener),"drawingMode"in y&&n(6,s=y.drawingMode),"transform"in y&&n(7,r=y.transform)},[l,h,u,m,d,i,s,r]}class xt extends ne{constructor(t){super(),te(this,t,Xo,Co,Z,{addEventListener:5,drawingMode:6,transform:7})}}const Ve=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},Ee=[];function Uo(e,t=G){let n;const o=new Set;function i(a){if(Z(e,a)&&(e=a,n)){const l=!Ee.length;for(const c of o)c[1](),Ee.push(c,e);if(l){for(let c=0;c<Ee.length;c+=2)Ee[c][0](Ee[c+1]);Ee.length=0}}}function s(a){i(a(e))}function r(a,l=G){const c=[a,l];return o.add(c),o.size===1&&(n=t(i)||G),a(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const No=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const a=r.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},$t=(e,t)=>{No(e,t);const{subscribe:n,set:o}=Uo(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,c=Math.max(r.width/a,r.height/l);o(c)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},Vo="ontouchstart"in window||navigator.maxTouchPoints>0;function st(e){const t=e.slice(),n=(t[2]?t[0]:[...t[0],t[1]]).map(o=>o.join(",")).join(" ");return t[15]=n,t}function en(e){let t,n,o,i,s,r=e[2]&&tn(e);return{c(){t=X("polygon"),o=X("polygon"),r&&r.c(),s=ie(),f(t,"class","a9s-outer"),f(t,"points",n=e[15]),f(o,"class","a9s-inner"),f(o,"points",i=e[15])},m(a,l){B(a,t,l),B(a,o,l),r&&r.m(a,l),B(a,s,l)},p(a,l){l&7&&n!==(n=a[15])&&f(t,"points",n),l&7&&i!==(i=a[15])&&f(o,"points",i),a[2]?r?r.p(a,l):(r=tn(a),r.c(),r.m(s.parentNode,s)):r&&(r.d(1),r=null)},d(a){a&&I(t),a&&I(o),r&&r.d(a),a&&I(s)}}}function tn(e){let t,n,o;return{c(){t=X("rect"),f(t,"class","a9s-corner-handle"),f(t,"x",n=e[0][0][0]-e[3]/2),f(t,"y",o=e[0][0][1]-e[3]/2),f(t,"height",e[3]),f(t,"width",e[3])},m(i,s){B(i,t,s)},p(i,s){s&9&&n!==(n=i[0][0][0]-i[3]/2)&&f(t,"x",n),s&9&&o!==(o=i[0][0][1]-i[3]/2)&&f(t,"y",o),s&8&&f(t,"height",i[3]),s&8&&f(t,"width",i[3])},d(i){i&&I(t)}}}function Go(e){let t,n=e[1]&&en(st(e));return{c(){t=X("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null)},p(o,[i]){o[1]?n?n.p(st(o),i):(n=en(st(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:G,o:G,d(o){o&&I(t),n&&n.d()}}}const Fo=20;function Ho(e,t,n){let o;const i=ge();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:a}=t,{viewportScale:l=1}=t,c,h=[],u=null,m=!1;const d=y=>{const{timeStamp:T,offsetX:S,offsetY:Y}=y;if(c={timeStamp:T,offsetX:S,offsetY:Y},r==="drag"&&h.length===0){const D=a.elementToImage(y.offsetX,y.offsetY);h.push(D),n(1,u=D)}},g=y=>{if(h.length>0&&(n(1,u=a.elementToImage(y.offsetX,y.offsetY)),h.length>2)){const T=Ve(u,h[0])*l;n(2,m=T<Fo)}},_=y=>{if(r==="click"){const T=y.timeStamp-c.timeStamp,S=Ve([c.offsetX,c.offsetY],[y.offsetX,y.offsetY]);if(T>300||S>15)return;if(m)w();else if(h.length===0){const Y=a.elementToImage(y.offsetX,y.offsetY);h.push(Y),n(1,u=Y)}else h.push(u)}else{if(h.length===1&&Ve(h[0],u)<=4){n(0,h=[]),n(1,u=null);return}y.stopImmediatePropagation(),m?w():h.push(u)}},A=()=>{const y=[...h,u],T={type:z.POLYGON,geometry:{bounds:Ie(y),points:y}};Xe(T)>4&&(n(0,h=[]),n(1,u=null),i("create",T))},w=()=>{const y={type:z.POLYGON,geometry:{bounds:Ie(h),points:[...h]}};n(0,h=[]),n(1,u=null),i("create",y)};return Oe(()=>{s("pointerdown",d,!0),s("pointermove",g),s("pointerup",_,!0),s("dblclick",A,!0)}),e.$$set=y=>{"addEventListener"in y&&n(4,s=y.addEventListener),"drawingMode"in y&&n(5,r=y.drawingMode),"transform"in y&&n(6,a=y.transform),"viewportScale"in y&&n(7,l=y.viewportScale)},e.$$.update=()=>{e.$$.dirty&128&&n(3,o=10/l)},[h,u,m,o,s,r,a,l]}class zo extends ne{constructor(t){super(),te(this,t,Ho,Go,Z,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const rt=new Map([["rectangle",{tool:xt}],["polygon",{tool:zo}]]),Ge=()=>[...rt.keys()],lt=e=>rt.get(e),nn=(e,t,n)=>rt.set(e,{tool:t,opts:n});function jo(e){let t,n,o,i,s;return{c(){t=X("g"),n=X("ellipse"),i=X("ellipse"),f(n,"class","a9s-outer"),f(n,"style",o=e[1]?"display:none;":void 0),f(n,"cx",e[2]),f(n,"cy",e[3]),f(n,"rx",e[4]),f(n,"ry",e[5]),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"cx",e[2]),f(i,"cy",e[3]),f(i,"rx",e[4]),f(i,"ry",e[5]),f(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&f(n,"style",o),a&2&&f(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:G,o:G,d(r){r&&I(t)}}}function Wo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{cx:a,cy:l,rx:c,ry:h}=s;return e.$$set=u=>{"annotation"in u&&n(0,i=u.annotation),"geom"in u&&n(6,s=u.geom),"style"in u&&n(7,r=u.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ne(i,r))},[i,o,a,l,c,h,s,r]}class qo extends ne{constructor(t){super(),te(this,t,Wo,jo,Z,{annotation:0,geom:6,style:7})}}function Ko(e){let t,n,o,i,s;return{c(){t=X("g"),n=X("polygon"),i=X("polygon"),f(n,"class","a9s-outer"),f(n,"style",o=e[1]?"display:none;":void 0),f(n,"points",e[2].map(Jo).join(" ")),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"points",e[2].map(Zo).join(" ")),f(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&f(n,"style",o),a&2&&f(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:G,o:G,d(r){r&&I(t)}}}const Jo=e=>e.join(","),Zo=e=>e.join(",");function Qo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{points:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,i=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ne(i,r))},[i,o,a,s,r]}class xo extends ne{constructor(t){super(),te(this,t,Qo,Ko,Z,{annotation:0,geom:3,style:4})}}function $o(e){let t,n,o,i,s;return{c(){t=X("g"),n=X("rect"),i=X("rect"),f(n,"class","a9s-outer"),f(n,"style",o=e[5]?"display:none;":void 0),f(n,"x",e[4]),f(n,"y",e[3]),f(n,"width",e[2]),f(n,"height",e[1]),f(i,"class","a9s-inner"),f(i,"style",e[5]),f(i,"x",e[4]),f(i,"y",e[3]),f(i,"width",e[2]),f(i,"height",e[1]),f(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&32&&o!==(o=r[5]?"display:none;":void 0)&&f(n,"style",o),a&16&&f(n,"x",r[4]),a&8&&f(n,"y",r[3]),a&4&&f(n,"width",r[2]),a&2&&f(n,"height",r[1]),a&32&&f(i,"style",r[5]),a&16&&f(i,"x",r[4]),a&8&&f(i,"y",r[3]),a&4&&f(i,"width",r[2]),a&2&&f(i,"height",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:G,o:G,d(r){r&&I(t)}}}function ei(e,t,n){let o,i,s,r,a,{annotation:l}=t,{geom:c}=t,{style:h=void 0}=t;return e.$$set=u=>{"annotation"in u&&n(0,l=u.annotation),"geom"in u&&n(6,c=u.geom),"style"in u&&n(7,h=u.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=Ne(l,h)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:a}=c,i,(n(3,s),n(6,c)),(n(2,r),n(6,c)),(n(1,a),n(6,c)))},[l,a,r,s,i,o,c,h]}class ti extends ne{constructor(t){super(),te(this,t,ei,$o,Z,{annotation:0,geom:6,style:7})}}const ni={elementToImage:(e,t)=>[e,t]},on=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),oi=250,sn=(e,t)=>{const n=ge();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<oi){const{x:l,y:c}=ii(r,e),h=t.getAt(l,c);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},ii=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:a}=t.getBoundingClientRect();return n.x=i+r,n.y=s+a,n.matrixTransform(t.getScreenCTM().inverse())};function rn(e,t,n){const o=e.slice();return o[29]=t[n],o}function ln(e,t,n){const o=e.slice();return o[32]=t[n],o}function at(e){const t=e.slice(),n=t[32].target.selector;return t[35]=n,t}function an(e){let t=e[32].id,n,o,i=cn(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&8192&&Z(t,t=s[32].id)?(se(),V(i,1,1,G),re(),i=cn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){V(i),o=!1},d(s){s&&I(n),i.d(s)}}}function si(e){let t,n;return t=new xo({props:{annotation:e[32],geom:e[35].geometry,style:e[1]}}),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i[0]&8192&&(s.annotation=o[32]),i[0]&8192&&(s.geom=o[35].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function ri(e){let t,n;return t=new ti({props:{annotation:e[32],geom:e[35].geometry,style:e[1]}}),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i[0]&8192&&(s.annotation=o[32]),i[0]&8192&&(s.geom=o[35].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function li(e){let t,n;return t=new qo({props:{annotation:e[32],geom:e[35].geometry,style:e[1]}}),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i[0]&8192&&(s.annotation=o[32]),i[0]&8192&&(s.geom=o[35].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function cn(e){let t,n,o,i;const s=[li,ri,si],r=[];function a(l,c){return l[35].type===z.ELLIPSE?0:l[35].type===z.RECTANGLE?1:l[35].type===z.POLYGON?2:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ie()},m(l,c){~t&&r[t].m(l,c),B(l,o,c),i=!0},p(l,c){let h=t;t=a(l),t===h?~t&&r[t].p(l,c):(n&&(se(),V(r[h],1,1,()=>{r[h]=null}),re()),~t?(n=r[t],n?n.p(l,c):(n=r[t]=s[t](l),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(l){i||(U(n),i=!0)},o(l){V(n),i=!1},d(l){~t&&r[t].d(l),l&&I(o)}}}function un(e){let t=!e[7](e[32]),n,o,i=t&&an(at(e));return{c(){i&&i.c(),n=ie()},m(s,r){i&&i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&8320&&(t=!s[7](s[32])),t?i?(i.p(at(s),r),r[0]&8320&&U(i,1)):(i=an(at(s)),i.c(),U(i,1),i.m(n.parentNode,n)):i&&(se(),V(i,1,1,()=>{i=null}),re())},i(s){o||(U(i),o=!0)},o(s){V(i),o=!1},d(s){i&&i.d(s),s&&I(n)}}}function fn(e){let t,n,o,i;const s=[ci,ai],r=[];function a(l,c){return l[6]?0:l[12]&&l[0]?1:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ie()},m(l,c){~t&&r[t].m(l,c),B(l,o,c),i=!0},p(l,c){let h=t;t=a(l),t===h?~t&&r[t].p(l,c):(n&&(se(),V(r[h],1,1,()=>{r[h]=null}),re()),~t?(n=r[t],n?n.p(l,c):(n=r[t]=s[t](l),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(l){i||(U(n),i=!0)},o(l){V(n),i=!1},d(l){~t&&r[t].d(l),l&&I(o)}}}function ai(e){let t=e[2],n,o,i=dn(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4&&Z(t,t=s[2])?(se(),V(i,1,1,G),re(),i=dn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){V(i),o=!1},d(s){s&&I(n),i.d(s)}}}function ci(e){let t,n,o=e[6],i=[];for(let r=0;r<o.length;r+=1)i[r]=mn(rn(e,o,r));const s=r=>V(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ie()},m(r,a){for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(r,a);B(r,t,a),n=!0},p(r,a){if(a[0]&279634){o=r[6];let l;for(l=0;l<o.length;l+=1){const c=rn(r,o,l);i[l]?(i[l].p(c,a),U(i[l],1)):(i[l]=mn(c),i[l].c(),U(i[l],1),i[l].m(t.parentNode,t))}for(se(),l=o.length;l<i.length;l+=1)s(l);re()}},i(r){if(!n){for(let a=0;a<o.length;a+=1)U(i[a]);n=!0}},o(r){i=i.filter(Boolean);for(let a=0;a<i.length;a+=1)V(i[a]);n=!1},d(r){Je(i,r),r&&I(t)}}}function dn(e){let t,n;return t=new Zt({props:{target:e[4],tool:e[12],drawingMode:e[11],transform:e[10],viewportScale:e[14]}}),t.$on("create",e[17]),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i[0]&16&&(s.target=o[4]),i[0]&4096&&(s.tool=o[12]),i[0]&2048&&(s.drawingMode=o[11]),i[0]&1024&&(s.transform=o[10]),i[0]&16384&&(s.viewportScale=o[14]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function hn(e){let t,n;return t=new Jt({props:{target:e[4],editor:ot(e[29].target.selector),annotation:e[29],style:e[1],transform:e[10],viewportScale:e[14]}}),t.$on("change",function(){W(e[18](e[29]))&&e[18](e[29]).apply(this,arguments)}),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&16&&(s.target=e[4]),i[0]&64&&(s.editor=ot(e[29].target.selector)),i[0]&64&&(s.annotation=e[29]),i[0]&2&&(s.style=e[1]),i[0]&1024&&(s.transform=e[10]),i[0]&16384&&(s.viewportScale=e[14]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function mn(e){let t=e[29].id,n,o,i=hn(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&64&&Z(t,t=s[29].id)?(se(),V(i,1,1,G),re(),i=hn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){V(i),o=!1},d(s){s&&I(n),i.d(s)}}}function ui(e){let t,n,o,i,s,r,a=e[13],l=[];for(let u=0;u<a.length;u+=1)l[u]=un(ln(e,a,u));const c=u=>V(l[u],1,1,()=>{l[u]=null});let h=e[4]&&fn(e);return{c(){t=X("svg"),n=X("g");for(let u=0;u<l.length;u+=1)l[u].c();o=X("g"),h&&h.c(),f(o,"class","drawing"),f(t,"class","a9s-annotationlayer"),Et(t,"drawing",e[12])},m(u,m){B(u,t,m),le(t,n);for(let d=0;d<l.length;d+=1)l[d]&&l[d].m(n,null);le(t,o),h&&h.m(o,null),e[25](o),e[26](t),i=!0,s||(r=[q(t,"pointerup",function(){W(e[8])&&e[8].apply(this,arguments)}),q(t,"pointerdown",function(){W(e[9])&&e[9].apply(this,arguments)})],s=!0)},p(u,m){if(e=u,m[0]&8322){a=e[13];let d;for(d=0;d<a.length;d+=1){const g=ln(e,a,d);l[d]?(l[d].p(g,m),U(l[d],1)):(l[d]=un(g),l[d].c(),U(l[d],1),l[d].m(n,null))}for(se(),d=a.length;d<l.length;d+=1)c(d);re()}e[4]?h?(h.p(e,m),m[0]&16&&U(h,1)):(h=fn(e),h.c(),U(h,1),h.m(o,null)):h&&(se(),V(h,1,1,()=>{h=null}),re()),(!i||m[0]&4096)&&Et(t,"drawing",e[12])},i(u){if(!i){for(let m=0;m<a.length;m+=1)U(l[m]);U(h),i=!0}},o(u){l=l.filter(Boolean);for(let m=0;m<l.length;m+=1)V(l[m]);V(h),i=!1},d(u){u&&I(t),Je(l,u),h&&h.d(),e[25](null),e[26](null),s=!1,oe(r)}}}function fi(e,t,n){let o,i,s,r,a,l,c,h,u,m,d=G,g=()=>(d(),d=yt(p,O=>n(14,m=O)),p);e.$$.on_destroy.push(()=>d());let{drawingEnabled:_}=t,{image:A}=t,{preferredDrawingMode:w}=t,{state:y}=t,{style:T=void 0}=t,{toolName:S=Ge().length>0?Ge()[0]:void 0}=t,{user:Y}=t,D,N,p;Oe(()=>g(n(5,p=$t(A,N))));const{selection:E,store:b}=y;_t(e,E,O=>n(24,h=O)),_t(e,b,O=>n(13,u=O));let v=null,P=null;const C=O=>{b.unobserve(v);const J=O.filter(({editable:H})=>H).map(({id:H})=>H);J.length>0?(n(6,P=J.map(H=>b.getAnnotation(H))),v=H=>{const{updated:he}=H.changes;n(6,P=he.map(j=>j.newValue))},b.observe(v,{annotations:J})):n(6,P=null)},Q=O=>{const J=Rt(),H={id:J,bodies:[],target:{annotation:J,selector:O.detail,creator:Y,created:new Date}};b.addAnnotation(H),E.setSelected(H.id)},Se=O=>J=>{var me;const{target:H}=O,he=10*60*1e3,j=((me=H.creator)==null?void 0:me.id)!==Y.id||!H.created||new Date().getTime()-H.created.getTime()>he;b.updateTarget({...H,selector:J.detail,created:j?H.created:new Date,updated:j?new Date:null,updatedBy:j?Y:null})};function Me(O){Re[O?"unshift":"push"](()=>{D=O,n(4,D)})}function Ye(O){Re[O?"unshift":"push"](()=>{N=O,n(3,N)})}return e.$$set=O=>{"drawingEnabled"in O&&n(0,_=O.drawingEnabled),"image"in O&&n(19,A=O.image),"preferredDrawingMode"in O&&n(20,w=O.preferredDrawingMode),"state"in O&&n(21,y=O.state),"style"in O&&n(1,T=O.style),"toolName"in O&&n(2,S=O.toolName),"user"in O&&n(22,Y=O.user)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(12,{tool:o,opts:i}=lt(S),o,(n(23,i),n(2,S))),e.$$.dirty[0]&9437184&&n(11,s=(i==null?void 0:i.drawingMode)||w),e.$$.dirty[0]&8&&n(10,r=on(N)),e.$$.dirty[0]&8&&n(9,{onPointerDown:a,onPointerUp:l}=sn(N,b),a,(n(8,l),n(3,N))),e.$$.dirty[0]&16777216&&n(7,c=O=>h.selected.find(J=>J.id===O.id&&J.editable)),e.$$.dirty[0]&16777216&&C(h.selected)},[_,T,S,N,D,p,P,c,l,a,r,s,o,u,m,E,b,Q,Se,A,w,y,Y,i,h,Me,Ye]}class gn extends ne{constructor(t){super(),te(this,t,fi,ui,Z,{drawingEnabled:0,image:19,preferredDrawingMode:20,state:21,style:1,toolName:2,user:22},null,[-1,-1])}}function di(e,t,n,o,i){pn(e,t,n||0,o||e.length-1,i||hi)}function pn(e,t,n,o,i){for(;o>n;){if(o-n>600){var s=o-n+1,r=t-n+1,a=Math.log(s),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(s-l)/s)*(r-s/2<0?-1:1),h=Math.max(n,Math.floor(t-r*l/s+c)),u=Math.min(o,Math.floor(t+(s-r)*l/s+c));pn(e,t,h,u,i)}var m=e[t],d=n,g=o;for(ke(e,n,t),i(e[o],m)>0&&ke(e,n,o);d<g;){for(ke(e,d,g),d++,g--;i(e[d],m)<0;)d++;for(;i(e[g],m)>0;)g--}i(e[n],m)===0?ke(e,n,g):(g++,ke(e,g,o)),g<=t&&(n=g+1),t<=g&&(o=g-1)}}function ke(e,t,n){var o=e[t];e[t]=e[n],e[n]=o}function hi(e,t){return e<t?-1:e>t?1:0}class mi{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(!He(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const a=n.children[r],l=n.leaf?i(a):a;He(t,l)&&(n.leaf?o.push(a):ut(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!He(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(He(t,r)){if(n.leaf||ut(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=Te([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let a,l,c;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],a=r.pop(),c=!0),o.leaf){const h=gi(t,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!c&&!o.leaf&&ut(o,i)?(s.push(o),r.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],c=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,a;if(s<=r)return a=Te(t.slice(n,o+1)),Ae(a,this.toBBox),a;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),a=Te([]),a.leaf=!1,a.height=i;const l=Math.ceil(s/r),c=l*Math.ceil(Math.sqrt(r));yn(t,n,o,c,this.compareMinX);for(let h=n;h<=o;h+=c){const u=Math.min(h+c-1,o);yn(t,h,u,l,this.compareMinY);for(let m=h;m<=u;m+=l){const d=Math.min(m+l-1,u);a.children.push(this._build(t,m,d,i-1))}}return Ae(a,this.toBBox),a}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,a;for(let l=0;l<n.children.length;l++){const c=n.children[l],h=ct(c),u=_i(t,c)-h;u<r?(r=u,s=h<s?h:s,a=c):u===r&&h<s&&(s=h,a=c)}n=a||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),Pe(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),a=Te(o.children.splice(r,o.children.length-r));a.height=o.height,a.leaf=o.leaf,Ae(o,this.toBBox),Ae(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(o,a)}_splitRoot(t,n){this.data=Te([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Ae(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let a=n;a<=o-n;a++){const l=Be(t,0,a,this.toBBox),c=Be(t,a,o,this.toBBox),h=wi(l,c),u=ct(l)+ct(c);h<s?(s=h,i=a,r=u<r?u:r):h===s&&u<r&&(r=u,i=a)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:pi,s=t.leaf?this.compareMinY:yi,r=this._allDistMargin(t,n,o,i),a=this._allDistMargin(t,n,o,s);r<a&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=Be(t,0,n,s),a=Be(t,o-n,o,s);let l=Fe(r)+Fe(a);for(let c=n;c<o-n;c++){const h=t.children[c];Pe(r,t.leaf?s(h):h),l+=Fe(r)}for(let c=o-n-1;c>=n;c--){const h=t.children[c];Pe(a,t.leaf?s(h):h),l+=Fe(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)Pe(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():Ae(t[n],this.toBBox)}}function gi(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 Ae(e,t){Be(e,0,e.children.length,t,e)}function Be(e,t,n,o,i){i||(i=Te(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];Pe(i,e.leaf?o(r):r)}return i}function Pe(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 pi(e,t){return e.minX-t.minX}function yi(e,t){return e.minY-t.minY}function ct(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Fe(e){return e.maxX-e.minX+(e.maxY-e.minY)}function _i(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 wi(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 ut(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function He(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Te(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function yn(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;di(e,r,t,n,i),s.push(t,r,r,n)}}const bi=()=>{const e=new mi,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=u=>{const{minX:m,minY:d,maxX:g,maxY:_}=u.selector.geometry.bounds,A={minX:m,minY:d,maxX:g,maxY:_,target:u};e.insert(A),t.set(u.annotation,A)},s=u=>{const m=t.get(u.annotation);e.remove(m),t.delete(u.annotation)};return{all:n,clear:o,getAt:(u,m)=>{const g=e.search({minX:u,minY:m,maxX:u,maxY:m}).map(_=>_.target).filter(_=>_.selector.type===z.RECTANGLE||Mt(_.selector,u,m));if(g.length>0)return g.sort((_,A)=>Xe(_.selector)-Xe(A.selector)),g[0]},getIntersecting:(u,m,d,g)=>e.search({minX:u,minY:m,maxX:u+d,maxY:m+g}).map(_=>_.target),insert:i,remove:s,set:(u,m=!0)=>{m&&o();const d=u.map(g=>{const{minX:_,minY:A,maxX:w,maxY:y}=g.selector.geometry.bounds;return{minX:_,minY:A,maxX:w,maxY:y,target:g}});d.forEach(g=>t.set(g.target.annotation,g)),e.load(d)},size:()=>e.all().length,update:(u,m)=>{s(u),i(m)}}},_n=e=>{const t=ro(),n=bi(),o=Zn(t,e.pointerSelectAction),i=Jn(t),s=fo();return t.observe(({changes:l})=>{n.set(l.created.map(c=>c.target),!1),l.deleted.forEach(c=>n.remove(c.target)),l.updated.forEach(({oldValue:c,newValue:h})=>n.update(c.target,h.target))}),{store:{...t,getAt:(l,c)=>{const h=n.getAt(l,c);return h?t.getAnnotation(h.annotation):void 0},getIntersecting:(l,c,h,u)=>n.getIntersecting(l,c,h,u).map(m=>t.getAnnotation(m.annotation))},selection:o,hover:i,viewport:s}},wn=e=>{const t=_n(e);return{...t,store:lo(t.store)}},bn=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),a=Math.round(i*t.height/10),l=n.getImageData(r,a,1,1).data,c=(.299*l[0]+.587*l[1]+.114*l[2])/255;o+=c}return o/81},En=e=>{const t=bn(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},ft=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?En(e):n),An=e=>({...e,drawingEnabled:e.drawingEnabled===void 0?!0:e.drawingEnabled,drawingMode:e.drawingMode||"drag",pointerSelectAction:e.pointerSelectAction||Ct.EDIT,theme:e.theme||"light"}),Tn=navigator.userAgent.indexOf("Mac OS X")!==-1,Sn=(e,t)=>{const n=t||document,o=r=>{r.key==="Z"&&r.ctrlKey?e.undo():r.key==="Y"&&r.ctrlKey&&e.redo()},i=r=>{r.key==="z"&&r.metaKey&&(r.shiftKey?e.redo():e.undo())},s=()=>{Tn?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return Tn?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Ti="",Si="",Mi="",Ei=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=An(t),i=wn(o),{selection:s,store:r}=i,a=uo(r),l=ho(i,a,o.adapter,o.autoSave),c=document.createElement("DIV");c.style.position="relative",c.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(c,n),c.appendChild(n);const h=Sn(a);let u=bo();ft(n,c,o.theme);const m=new gn({target:c,props:{drawingEnabled:o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:u}});m.$on("click",p=>{const{originalEvent:E,annotation:b}=p.detail;b?s.clickSelect(b.id,E):s.isEmpty()||s.clear()});const d=go(i,a,o.adapter),g=()=>{m.$destroy(),c.parentNode.insertBefore(n,c),c.parentNode.removeChild(c),h.destroy(),a.destroy()},_=()=>u,A=(p,E,b)=>nn(p,E,b),w=(p,E)=>qt(p,E),y=p=>{if(!lt(p))throw`No drawing tool named ${p}`;m.$set({toolName:p})},T=p=>m.$set({drawingEnabled:p}),S=p=>{console.warn("Filter not implemented yet")},Y=p=>m.$set({style:p}),D=p=>ft(n,c,p),N=p=>{u=p,m.$set({user:p})};return{...d,destroy:g,getUser:_,listDrawingTools:Ge,on:l.on,off:l.off,registerDrawingTool:A,registerShapeEditor:w,setDrawingEnabled:T,setDrawingTool:y,setFilter:S,setStyle:Y,setTheme:D,setUser:N,state:i}};k.Editor=it,k.EditorMount=Jt,k.Handle=L,k.IdentityTransform=ni,k.PolygonEditor=zt,k.RectangleEditor=jt,k.RectangleUtil=vt,k.RubberbandRectangle=xt,k.SVGAnnotationLayer=gn,k.ShapeType=z,k.ToolMount=Zt,k.W3CImageFormat=So,k.addEventListeners=sn,k.boundsFromPoints=Ie,k.computeArea=Xe,k.createImageAnnotator=Ei,k.createImageAnnotatorState=_n,k.createSVGTransform=on,k.createSvelteImageAnnotatorState=wn,k.detectTheme=En,k.distance=Ve,k.enableResponsive=$t,k.fillDefaults=An,k.getEditor=ot,k.getTool=lt,k.initKeyboardCommands=Sn,k.intersects=Mt,k.isTouch=Vo,k.listDrawingTools=Ge,k.parseFragmentSelector=Lt,k.parseSVGSelector=Bt,k.parseW3CImageAnnotation=Ut,k.registerEditor=qt,k.registerShapeUtil=Ce,k.registerTool=nn,k.sampleBrightness=bn,k.serializeFragmentSelector=Ot,k.serializeSVGSelector=Pt,k.serializeW3CImageAnnotation=Nt,k.setTheme=ft,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=annotorious.js.map