@annotorious/annotorious 3.0.0-rc.29 → 3.0.0-rc.30

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