@annotorious/annotorious 3.0.11 → 3.0.13

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