@annotorious/openseadragon 3.6.4 → 3.6.6

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,4 +1,4 @@
1
- (function(Yt,ce){typeof exports=="object"&&typeof module<"u"?ce(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],ce):(Yt=typeof globalThis<"u"?globalThis:Yt||self,ce(Yt.AnnotoriousOSD={},Yt.OpenSeadragon))})(this,function(Yt,ce){"use strict";var oC=Object.defineProperty;var aC=(Yt,ce,qr)=>ce in Yt?oC(Yt,ce,{enumerable:!0,configurable:!0,writable:!0,value:qr}):Yt[ce]=qr;var Oh=(Yt,ce,qr)=>aC(Yt,typeof ce!="symbol"?ce+"":ce,qr);var qr=Object.prototype.hasOwnProperty;function Kr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Kr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(qr.call(r,e)&&++i&&!qr.call(t,e)||!(e in t)||!Kr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var Go=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(Go||{});const ue=[];for(let r=0;r<256;++r)ue.push((r+256).toString(16).slice(1));function Zm(r,t=0){return(ue[r[t+0]]+ue[r[t+1]]+ue[r[t+2]]+ue[r[t+3]]+"-"+ue[r[t+4]]+ue[r[t+5]]+"-"+ue[r[t+6]]+ue[r[t+7]]+"-"+ue[r[t+8]]+ue[r[t+9]]+"-"+ue[r[t+10]]+ue[r[t+11]]+ue[r[t+12]]+ue[r[t+13]]+ue[r[t+14]]+ue[r[t+15]]).toLowerCase()}let $o;const Jm=new Uint8Array(16);function Qm(){if(!$o){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");$o=crypto.getRandomValues.bind(crypto)}return $o(Jm)}const tg=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),$h={randomUUID:tg};function eg(r,t,e){var i;if($h.randomUUID&&!r)return $h.randomUUID();r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Qm();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Zm(n)}const Ho=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},rg=(r,t,e,i)=>({id:eg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),ig=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},ng=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},sg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Kr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),og=(r,t)=>!Kr(r.target,t.target),ag=(r,t)=>{const e=ig(r,t),i=ng(r,t),n=sg(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:n.length>0?n:void 0,targetUpdated:og(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Pr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Pr||{});const lg=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),n=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>e.has(u.id)||i.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(r.created||[]).filter(u=>!s.has(u.id)).map(u=>o.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],h=[...(r.deleted||[]).filter(u=>!n.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:p}=u;if(o.has(p.id)){const f=t.updated.find(m=>m.oldValue.id===p.id).newValue;return ag(d,f)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let hg=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,n=e.length;i<n;i++)e[i](...t)},events:{},on(r,t){var e;return((e=this.events)[r]||(e[r]=[])).push(t),()=>{var i;this.events[r]=(i=this.events[r])==null?void 0:i.filter(n=>t!==n)}}});const cg=250,ug=(r,t)=>{const e=hg(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=f=>{if(!s){const{changes:m}=f,_=performance.now();if(_-o>cg)i.splice(n+1),i.push(m),n=i.length-1;else{const v=i.length-1;i[v]=lg(i[v],m)}o=_}s=!1};r.observe(a,{origin:Pr.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f),h=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),c=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({oldValue:m})=>m)),u=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(f,m)=>e.on(f,m),redo:()=>{if(i.length-1>n){s=!0;const{created:f,updated:m,deleted:_}=i[n+1];h(f),u(m),p(_),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:f,updated:m,deleted:_}=i[n];l(f),c(m),d(_),e.emit("undo",i[n]),n-=1}}}},dg=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(v,y)=>{l.has(v)?l.get(v).push(y):l.set(v,[y])},p=(v,y)=>{const g=l.get(v);if(g){const b=g.indexOf(y);b!==-1&&g.splice(b,1)}},f=(v,y,g)=>{l.has(v)&&setTimeout(()=>{l.get(v).forEach(b=>{if(e){const C=Array.isArray(y)?y.map(A=>e.serialize(A)):e.serialize(y),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(C,R)}else b(y,g)})},1)},m=()=>{const{selected:v}=s,y=(v||[]).map(({id:g})=>o.getAnnotation(g));y.forEach(g=>{const b=h.find(C=>C.id===g.id);(!b||!Kr(b,g))&&f("updateAnnotation",g,b)}),h=h.map(g=>y.find(({id:C})=>C===g.id)||g)};s.subscribe(({selected:v})=>{if(!(h.length===0&&v.length===0)){if(h.length===0&&v.length>0)h=v.map(({id:y})=>o.getAnnotation(y));else if(h.length>0&&v.length===0)h.forEach(y=>{const g=o.getAnnotation(y.id);g&&!Kr(g,y)&&f("updateAnnotation",g,y)}),h=[];else{const y=new Set(h.map(b=>b.id)),g=new Set(v.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const C=o.getAnnotation(b.id);C&&!Kr(C,b)&&f("updateAnnotation",C,b)}),h=[...h.filter(b=>g.has(b.id)),...v.filter(({id:b})=>!y.has(b)).map(({id:b})=>o.getAnnotation(b))]}f("selectionChanged",h)}}),n.subscribe(v=>{!c&&v?f("mouseEnterAnnotation",o.getAnnotation(v)):c&&!v?f("mouseLeaveAnnotation",o.getAnnotation(c)):c&&v&&(f("mouseLeaveAnnotation",o.getAnnotation(c)),f("mouseEnterAnnotation",o.getAnnotation(v))),c=v}),a==null||a.subscribe(v=>f("viewportIntersect",v.map(y=>o.getAnnotation(y)))),o.observe(v=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:y,deleted:g}=v.changes;(y||[]).forEach(b=>f("createAnnotation",b)),(g||[]).forEach(b=>f("deleteAnnotation",b)),(v.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:C})=>{const R=h.find(A=>A.id===b.id)||b;h=h.map(A=>A.id===b.id?C:A),f("updateAnnotation",C,R)})},{origin:Pr.LOCAL}),o.observe(v=>{if(h){const y=new Set(h.map(b=>b.id)),g=(v.changes.updated||[]).filter(({newValue:b})=>y.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(R=>R.id===b.id)||b))}},{origin:Pr.REMOTE});const _=v=>y=>{const{updated:g}=y;v?(g||[]).forEach(b=>f("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>f("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:p,emit:f}},fg=r=>t=>t.reduce((e,i)=>{const{parsed:n,error:s}=r.parse(i);return s?{parsed:e.parsed,failed:[...e.failed,i]}:n?{parsed:[...e.parsed,n],failed:e.failed}:{...e}},{parsed:[],failed:[]}),pg=(r,t,e)=>{const{store:i,selection:n}=r,s=v=>{if(e){const{parsed:y,error:g}=e.parse(v);y?i.addAnnotation(y,Pr.REMOTE):console.error(g)}else i.addAnnotation(Ho(v),Pr.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=v=>{const y=i.getAnnotation(v);return e&&y?e.serialize(y):y},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var v;const y=(((v=n.selected)==null?void 0:v.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?y.map(e.serialize):y},u=(v,y=!0)=>fetch(v).then(g=>g.json()).then(g=>(p(g,y),g)),d=v=>{if(typeof v=="string"){const y=i.getAnnotation(v);if(i.deleteAnnotation(v),y)return e?e.serialize(y):y}else{const y=e?e.parse(v).parsed:v;if(y)return i.deleteAnnotation(y),v}},p=(v,y=!0)=>{if(e){const g=e.parseAll||fg(e),{parsed:b,failed:C}=g(v);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),i.bulkAddAnnotations(b,y,Pr.REMOTE)}else i.bulkAddAnnotations(v.map(Ho),y,Pr.REMOTE)},f=(v,y)=>{v?n.setSelected(v,y):n.clear()},m=v=>{n.clear(),n.setUserSelectAction(v)},_=v=>{if(e){const y=e.parse(v).parsed,g=e.serialize(i.getAnnotation(y.id));return i.updateAnnotation(y),g}else{const y=i.getAnnotation(v.id);return i.updateAnnotation(Ho(v)),y}};return{addAnnotation:s,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:f,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},mg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let gg=r=>crypto.getRandomValues(new Uint8Array(r)),yg=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,n=-~(1.6*i*t/r.length);return(s=t)=>{let o="";for(;;){let a=e(n),l=n|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=s)return o}}},_g=(r,t=21)=>yg(r,t|0,gg),vg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=mg[e[r]&63];return t};const bg=()=>({isGuest:!0,id:_g("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),xg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],wg=()=>{const r=[...xg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};vg();var Eg=Object.defineProperty,Tg=(r,t,e)=>t in r?Eg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Hh=(r,t,e)=>Tg(r,typeof t!="symbol"?t+"":t,e);function It(){}function Xo(r,t){for(const e in t)r[e]=t[e];return r}function Xh(r){return r()}function Vh(){return Object.create(null)}function Me(r){r.forEach(Xh)}function Gt(r){return typeof r=="function"}function qt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Ag(r){return Object.keys(r).length===0}function zh(r,...t){if(r==null){for(const i of t)i(void 0);return It}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Vo(r,t,e){r.$$.on_destroy.push(zh(t,e))}function Sg(r,t,e,i){if(r){const n=jh(r,t,e,i);return r[0](n)}}function jh(r,t,e,i){return r[1]&&i?Xo(e.ctx.slice(),r[1](i(t))):e.ctx}function Cg(r,t,e,i){if(r[2]&&i){const n=r[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const s=[],o=Math.max(t.dirty.length,n.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|n[a];return s}return t.dirty|n}return t.dirty}function Ig(r,t,e,i,n,s){if(n){const o=jh(t,e,i,s);r.p(o,n)}}function Pg(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function Wh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function ns(r){return r??""}function bt(r,t){r.appendChild(t)}function rt(r,t,e){r.insertBefore(t,e||null)}function tt(r){r.parentNode&&r.parentNode.removeChild(r)}function Zr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function W(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Yh(r){return document.createTextNode(r)}function we(){return Yh(" ")}function De(){return Yh("")}function Ct(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function x(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function Rg(r){return Array.from(r.childNodes)}function Ze(r,t,e){r.classList.toggle(t,!!e)}function Mg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let gn;function yn(r){gn=r}function qh(){if(!gn)throw new Error("Function called outside component initialization");return gn}function Jr(r){qh().$$.on_mount.push(r)}function Rr(){const r=qh();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=Mg(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function de(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Ei=[],ss=[];let Ti=[];const Kh=[],Zh=Promise.resolve();let zo=!1;function Jh(){zo||(zo=!0,Zh.then(tc))}function Qh(){return Jh(),Zh}function jo(r){Ti.push(r)}const Wo=new Set;let Ai=0;function tc(){if(Ai!==0)return;const r=gn;do{try{for(;Ai<Ei.length;){const t=Ei[Ai];Ai++,yn(t),Dg(t.$$)}}catch(t){throw Ei.length=0,Ai=0,t}for(yn(null),Ei.length=0,Ai=0;ss.length;)ss.pop()();for(let t=0;t<Ti.length;t+=1){const e=Ti[t];Wo.has(e)||(Wo.add(e),e())}Ti.length=0}while(Ei.length);for(;Kh.length;)Kh.pop()();zo=!1,Wo.clear(),yn(r)}function Dg(r){if(r.fragment!==null){r.update(),Me(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(jo)}}function Og(r){const t=[],e=[];Ti.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ti=t}const os=new Set;let Qr;function Ee(){Qr={r:0,c:[],p:Qr}}function Te(){Qr.r||Me(Qr.c),Qr=Qr.p}function at(r,t){r&&r.i&&(os.delete(r),r.i(t))}function pt(r,t,e,i){if(r&&r.o){if(os.has(r))return;os.add(r),Qr.c.push(()=>{os.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Ie(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function ee(r){r&&r.c()}function Jt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),jo(()=>{const s=r.$$.on_mount.map(Xh).filter(Gt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Me(s),r.$$.on_mount=[]}),n.forEach(jo)}function Qt(r,t){const e=r.$$;e.fragment!==null&&(Og(e.after_update),Me(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Lg(r,t){r.$$.dirty[0]===-1&&(Ei.push(r),Jh(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function fe(r,t,e,i,n,s,o=null,a=[-1]){const l=gn;yn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:It,not_equal:n,bound:Vh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Vh(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let c=!1;if(h.ctx=e?e(r,t.props||{},(u,d,...p)=>{const f=p.length?p[0]:d;return h.ctx&&n(h.ctx[u],h.ctx[u]=f)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](f),c&&Lg(r,u)),d}):[],h.update(),c=!0,Me(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=Rg(t.target);h.fragment&&h.fragment.l(u),u.forEach(tt)}else h.fragment&&h.fragment.c();t.intro&&at(r.$$.fragment),Jt(r,t.target,t.anchor),tc()}yn(l)}class pe{constructor(){Hh(this,"$$"),Hh(this,"$$set")}$destroy(){Qt(this,1),this.$destroy=It}$on(t,e){if(!Gt(e))return It;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!Ag(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Bg="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Bg);var mt=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(mt||{}),Ng={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,c=a.y-l.y;return h*h+c*c}function e(a,l,h){var c=l.x,u=l.y,d=h.x-c,p=h.y-u;if(d!==0||p!==0){var f=((a.x-c)*d+(a.y-u)*p)/(d*d+p*p);f>1?(c=h.x,u=h.y):f>0&&(c+=d*f,u+=p*f)}return d=a.x-c,p=a.y-u,d*d+p*p}function i(a,l){for(var h=a[0],c=[h],u,d=1,p=a.length;d<p;d++)u=a[d],t(u,h)>l&&(c.push(u),h=u);return h!==u&&c.push(u),c}function n(a,l,h,c,u){for(var d=c,p,f=l+1;f<h;f++){var m=e(a[f],a[l],a[h]);m>d&&(p=f,d=m)}d>c&&(p-l>1&&n(a,l,p,c,u),u.push(a[p]),h-p>1&&n(a,p,h,c,u))}function s(a,l){var h=a.length-1,c=[a[0]];return n(a,0,h,l,c),c.push(a[h]),c}function o(a,l,h){if(a.length<=2)return a;var c=l!==void 0?l*l:1;return a=h?a:i(a,c),a=s(a,c),a}r.exports=o,r.exports.default=o})()})(Ng);const Yo={},Si=(r,t)=>Yo[r]=t,qo=r=>Yo[r.type].area(r),Fg=(r,t,e,i)=>Yo[r.type].intersects(r,t,e,i),Ae=r=>{let t=1/0,e=1/0,i=-1/0,n=-1/0;return r.forEach(([s,o])=>{t=Math.min(t,s),e=Math.min(e,o),i=Math.max(i,s),n=Math.max(n,o)}),{minX:t,minY:e,maxX:i,maxY:n}},as=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},ls=(r,t,e)=>{let i=!1;for(let n=0,s=r.length-1;n<r.length;s=n++){const o=r[n][0],a=r[n][1],l=r[s][0],h=r[s][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},kg=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},hs=(r,t)=>{const e=Math.abs(t[0]-r[0]),i=Math.abs(t[1]-r[1]);return Math.sqrt(Math.pow(e,2)+Math.pow(i,2))},Ug={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:n,rx:s,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),c=t-i,u=e-n,d=l*c+h*u,p=h*c-l*u;return d*d/(s*s)+p*p/(o*o)<=1}};Si(mt.ELLIPSE,Ug);const Gg={area:r=>0,intersects:(r,t,e,i=2)=>{const[[n,s],[o,a]]=r.geometry.points,l=Math.abs((a-s)*t-(o-n)*e+o*s-a*n),h=hs([n,s],[o,a]);return l/h<=i}};Si(mt.LINE,Gg);const $g={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=as(n.points),a=s.reduce((l,h)=>l+as(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const n of i){const[s,...o]=n.rings;if(ls(s.points,t,e)){let a=!1;for(const l of o)if(ls(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Ko=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ae(t)},$e=r=>r.rings.map(t=>kg(t.points)).join(" "),Hg=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Si(mt.MULTIPOLYGON,$g);const Xg={area:r=>{const t=r.geometry.points;return as(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return ls(i,t,e)}};Si(mt.POLYGON,Xg);const Vg={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Zo(t.points,t.closed);return as(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Zo(n.points,n.closed);return ls(s,t,e)}else return zg(n,[t,e],i)}},Zo=(r,t=!1)=>{const e=[];for(let i=0;i<r.length;i++){const n=r[i],s=r[(i+1)%r.length];if(e.push(n.point),(i<r.length-1||t)&&(n.outHandle||s.inHandle)){const o=ec(n.point,n.outHandle||n.point,s.inHandle||s.point,s.point,10);e.push(...o.slice(1))}}return e},ec=(r,t,e,i,n=10)=>{const s=[];for(let o=0;o<=n;o++){const a=o/n,l=Math.pow(1-a,3)*r[0]+3*Math.pow(1-a,2)*a*t[0]+3*(1-a)*Math.pow(a,2)*e[0]+Math.pow(a,3)*i[0],h=Math.pow(1-a,3)*r[1]+3*Math.pow(1-a,2)*a*t[1]+3*(1-a)*Math.pow(a,2)*e[1]+Math.pow(a,3)*i[1];s.push([l,h])}return s},zg=(r,t,e)=>{for(let i=0;i<r.points.length-1;i++){const n=r.points[i],s=r.points[i+1];if(n.outHandle||s.inHandle){const o=ec(n.point,n.outHandle||n.point,s.inHandle||s.point,s.point,20);for(let a=0;a<o.length-1;a++)if(rc(t,o[a],o[a+1])<=e)return!0}else if(rc(t,n.point,s.point)<=e)return!0}return!1},rc=(r,t,e)=>{const[i,n]=r,[s,o]=t,[a,l]=e,h=a-s,c=l-o,u=Math.sqrt(h*h+c*c);if(u===0)return Math.sqrt((i-s)*(i-s)+(n-o)*(n-o));const d=((i-s)*h+(n-o)*c)/(u*u);return d<=0?Math.sqrt((i-s)*(i-s)+(n-o)*(n-o)):d>=1?Math.sqrt((i-a)*(i-a)+(n-l)*(n-l)):Math.abs((l-o)*i-(a-s)*n+a*o-l*s)/u},Jo=r=>{if(!r.points||r.points.length===0)return"";const t=[],e=r.points[0];t.push(`M ${e.point[0]} ${e.point[1]}`);for(let i=1;i<r.points.length;i++){const n=r.points[i],s=r.points[i-1];if(n.type==="CURVE"||s.type==="CURVE"){const o=s.type==="CURVE"&&s.outHandle||s.point,a=n.type==="CURVE"&&n.inHandle||n.point,l=n.point;t.push(`C ${o[0]} ${o[1]} ${a[0]} ${a[1]} ${l[0]} ${l[1]}`)}else t.push(`L ${n.point[0]} ${n.point[1]}`)}if(r.closed){const i=r.points[r.points.length-1],n=r.points[0];if(i.outHandle||n.inHandle){const s=i.outHandle||i.point,o=n.inHandle||n.point,a=n.point;t.push(`C ${s[0]} ${s[1]} ${o[0]} ${o[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Si(mt.POLYLINE,Vg);const jg={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};Si(mt.RECTANGLE,jg);const Be=r=>cs(r.target),cs=r=>{var t,e;return(r==null?void 0:r.annotation)!==void 0&&((e=(t=r==null?void 0:r.selector)==null?void 0:t.geometry)==null?void 0:e.bounds)!==void 0},Wg=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,n=[...e.matchAll(i)][0],[s,o,a,l,h,c,u]=n;if(o!=="xywh")throw new Error("Unsupported MediaFragment: "+e);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,p,f,m]=[l,h,c,u].map(parseFloat);return{type:mt.RECTANGLE,geometry:{x:d,y:p,w:f,h:m,bounds:{minX:d,minY:t?p-m:p,maxX:d+f,maxY:t?p:p+m}}}},Yg=r=>{const{x:t,y:e,w:i,h:n}=r;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${e},${i},${n}`}},ic="http://www.w3.org/2000/svg",nc=r=>{const t=i=>{Array.from(i.attributes).forEach(n=>{n.name.startsWith("on")&&i.removeAttribute(n.name)})},e=r.getElementsByTagName("script");return Array.from(e).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(r.querySelectorAll("*")).forEach(t),r},qg=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${ic}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},us=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(ic),i=t.lookupNamespaceURI(null);return e||i?nc(t).firstChild:nc(qg(t)).firstChild},Kg=r=>{const t=sc(r),e=[];let i=[],n=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":i.length>0&&(e.push({points:i}),i=[]),n=[s.args[0],s.args[1]],i.push([...n]);break;case"L":n=[s.args[0],s.args[1]],i.push([...n]);break;case"H":n=[s.args[0],n[1]],i.push([...n]);break;case"V":n=[n[0],s.args[0]],i.push([...n]);break;case"C":n=[s.args[4],s.args[5]],i.push([...n]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(i.length>2&&e.push({points:i}),e.length>0){const s=Ae(e[0].points);return{rings:e,bounds:s}}},Zg=r=>{const{point:t,inHandle:e,outHandle:i}=r;if(!e||!i)return!1;const n=e[0]-t[0],s=e[1]-t[1],o=i[0]-t[0],a=i[1]-t[1],l=n*a-s*o;return Math.abs(l)<.01},Jg=r=>{const t=sc(r);let e=[],i=[0,0],n=!1;for(let o=0;o<t.length;o++){const a=t[o];switch(a.type.toUpperCase()){case"M":i=[a.args[0],a.args[1]],e.push({type:"CORNER",point:[...i]});break;case"L":i=[a.args[0],a.args[1]],e.push({type:"CORNER",point:[...i]});break;case"C":const l=[a.args[0],a.args[1]],h=[a.args[2],a.args[3]],c=[a.args[4],a.args[5]];if(e.length>0){const d=e[e.length-1];(l[0]!==d.point[0]||l[1]!==d.point[1])&&(d.type="CURVE",d.outHandle=l)}const u={type:h[0]!==c[0]||h[1]!==c[1]?"CURVE":"CORNER",point:c};u.type==="CURVE"&&(u.inHandle=h),e.push(u),i=c;break;case"Z":n=!0;break;default:console.warn(`Unsupported SVG path command: ${a.type}`);break}}e=e.map(o=>Zg(o)?{...o,locked:!0}:o);const s=Ae(Zo(e,n));return{points:e,closed:n,bounds:s}},sc=r=>{const t=[],e=r.replace(/,/g," ").trim(),i=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let n;for(;(n=i.exec(e))!==null;){const[,s,o]=n,a=o.trim()===""?[]:o.trim().split(/\s+/).map(Number).filter(l=>!isNaN(l));t.push({type:s,args:a})}return t},Qg=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],n=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:mt.POLYGON,geometry:{points:n,bounds:Ae(n)}}},ty=r=>{const t=us(r),e=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),n=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),o={minX:e-n,minY:i-s,maxX:e+n,maxY:i+s};return{type:mt.ELLIPSE,geometry:{cx:e,cy:i,rx:n,ry:s,bounds:o}}},ey=r=>{const t=us(r),e=parseFloat(t.getAttribute("x1")),i=parseFloat(t.getAttribute("x2")),n=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),o={minX:Math.min(e,i),minY:Math.min(n,s),maxX:Math.max(e,i),maxY:Math.max(n,s)};return{type:mt.LINE,geometry:{points:[[e,n],[i,s]],bounds:o}}},ry=r=>{const t=us(r),e=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],i=e==null?void 0:e.getAttribute("d");if(!i)throw new Error("Could not parse SVG path");const n=Jg(i);if(!n)throw new Error("Could not parse SVG path");return{type:mt.POLYLINE,geometry:n}},iy=r=>{const t=us(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>Kg(s)).filter(Boolean),i=e.reduce((s,o)=>[...s,...o.rings[0].points],[]),n=Ae(i);return e.length===1&&e[0].rings.length===1?{type:mt.POLYGON,geometry:{points:i,bounds:n}}:{type:mt.MULTIPOLYGON,geometry:{polygons:e,bounds:n}}},ny=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return Qg(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return ry(t);if(t.includes("<path "))return iy(t);if(t.includes("<ellipse "))return ty(t);if(t.includes("<line "))return ey(t);throw"Unsupported SVG shape: "+t},sy=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${$e(t)}" />`).join("")}</g>`,oy=r=>{let t;switch(r.type){case mt.POLYGON:{const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(n=>n.join(",")).join(" ")}" /></svg>`;break}case mt.ELLIPSE:{const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`;break}case mt.MULTIPOLYGON:{const e=r.geometry;t=`<svg>${sy(e)}</svg>`;break}case mt.LINE:{const e=r.geometry,[[i,n],[s,o]]=e.points;t=`<svg><line x1="${i}" y1="${n}" x2="${s}" y2="${o}" /></svg>`;break}case mt.POLYLINE:t=`<svg><path d="${Jo(r.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},me=[];for(let r=0;r<256;++r)me.push((r+256).toString(16).slice(1));function ay(r,t=0){return(me[r[t+0]]+me[r[t+1]]+me[r[t+2]]+me[r[t+3]]+"-"+me[r[t+4]]+me[r[t+5]]+"-"+me[r[t+6]]+me[r[t+7]]+"-"+me[r[t+8]]+me[r[t+9]]+"-"+me[r[t+10]]+me[r[t+11]]+me[r[t+12]]+me[r[t+13]]+me[r[t+14]]+me[r[t+15]]).toLowerCase()}let Qo;const ly=new Uint8Array(16);function hy(){if(!Qo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qo=crypto.getRandomValues.bind(crypto)}return Qo(ly)}const cy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),oc={randomUUID:cy};function ac(r,t,e){var i;if(oc.randomUUID&&!r)return oc.randomUUID();r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??hy();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,ay(n)}var lc=Object.prototype.hasOwnProperty;function Mr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Mr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(lc.call(r,e)&&++i&&!lc.call(t,e)||!(e in t)||!Mr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}function ta(){}function uy(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const Ci=[];function ea(r,t=ta){let e;const i=new Set;function n(a){if(uy(r,a)&&(r=a,e)){const l=!Ci.length;for(const h of i)h[1](),Ci.push(h,r);if(l){for(let h=0;h<Ci.length;h+=2)Ci[h][0](Ci[h+1]);Ci.length=0}}}function s(a){n(a(r))}function o(a,l=ta){const h=[a,l];return i.add(h),i.size===1&&(e=t(n,s)||ta),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:n,update:s,subscribe:o}}const dy=r=>{const{subscribe:t,set:e}=ea();let i;return t(n=>i=n),r.observe(({changes:n})=>{if(i){(n.deleted||[]).some(o=>o.id===i)&&e(void 0);const s=(n.updated||[]).find(({oldValue:o})=>o.id===i);s&&e(s.newValue.id)}}),{get current(){return i},subscribe:t,set:e}};var hc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(hc||{});const ds={selected:[]},fy=(r,t,e)=>{const{subscribe:i,set:n}=ea(ds);let s=t,o=ds;i(m=>o=m);const a=()=>{Mr(o,ds)||n(ds)},l=()=>{var m;return((m=o.selected)==null?void 0:m.length)===0},h=m=>{if(l())return!1;const _=typeof m=="string"?m:m.id;return o.selected.some(v=>v.id===_)},c=(m,_)=>{let v;if(Array.isArray(m)){if(v=m.map(g=>r.getAnnotation(g)).filter(Boolean),v.length<m.length){console.warn("Invalid selection: "+m.filter(g=>!v.some(b=>b.id===g)));return}}else{const g=r.getAnnotation(m);if(!g){console.warn("Invalid selection: "+m);return}v=[g]}const y=v.reduce((g,b)=>{const C=f(b);return C==="EDIT"?[...g,{id:b.id,editable:!0}]:C==="SELECT"?[...g,{id:b.id}]:g},[]);n({selected:y,event:_})},u=(m,_)=>{const v=Array.isArray(m)?m:[m],y=v.map(g=>r.getAnnotation(g)).filter(g=>!!g);n({selected:y.map(g=>{const b=_===void 0?f(g)==="EDIT":_;return{id:g.id,editable:b}})}),y.length!==v.length&&console.warn("Invalid selection",m)},d=m=>{if(l())return!1;const{selected:_}=o;_.some(({id:v})=>m.includes(v))&&n({selected:_.filter(({id:v})=>!m.includes(v))})},p=m=>{s=m,u(o.selected.map(({id:_})=>_))},f=m=>py(m,s,e);return r.observe(({changes:m})=>d((m.deleted||[]).map(_=>_.id))),{get event(){return o?o.event:null},get selected(){return o?[...o.selected]:null},get userSelectAction(){return s},clear:a,evalSelectAction:f,isEmpty:l,isSelected:h,setSelected:u,setUserSelectAction:p,subscribe:i,userSelect:c}},py=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},ge=[];for(let r=0;r<256;++r)ge.push((r+256).toString(16).slice(1));function my(r,t=0){return(ge[r[t+0]]+ge[r[t+1]]+ge[r[t+2]]+ge[r[t+3]]+"-"+ge[r[t+4]]+ge[r[t+5]]+"-"+ge[r[t+6]]+ge[r[t+7]]+"-"+ge[r[t+8]]+ge[r[t+9]]+"-"+ge[r[t+10]]+ge[r[t+11]]+ge[r[t+12]]+ge[r[t+13]]+ge[r[t+14]]+ge[r[t+15]]).toLowerCase()}let ra;const gy=new Uint8Array(16);function yy(){if(!ra){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ra=crypto.getRandomValues.bind(crypto)}return ra(gy)}const _y=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),cc={randomUUID:_y};function vy(r,t,e){var i;if(cc.randomUUID&&!r)return cc.randomUUID();r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??yy();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,my(n)}const ia=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},by=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},xy=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},wy=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Mr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Ey=(r,t)=>!Mr(r.target,t.target),uc=(r,t)=>{const e=by(r,t),i=xy(r,t),n=wy(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:n.length>0?n:void 0,targetUpdated:Ey(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Nt=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Nt||{});const Ty=(r,t)=>{var e,i;const{changes:n,origin:s}=t;if(!(r.options.origin?r.options.origin===s:s!=="SILENT"))return!1;if(r.options.ignore){const{ignore:o}=r.options,a=l=>l&&l.length>0;if(!(a(n.created)||a(n.deleted))){const l=(e=n.updated)==null?void 0:e.some(c=>a(c.bodiesCreated)||a(c.bodiesDeleted)||a(c.bodiesUpdated)),h=(i=n.updated)==null?void 0:i.some(c=>c.targetUpdated);if(o==="BODY_ONLY"&&l&&!h||o==="TARGET_ONLY"&&h&&!l)return!1}}if(r.options.annotations){const o=new Set([...(n.created||[]).map(a=>a.id),...(n.deleted||[]).map(a=>a.id),...(n.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(r.options.annotations)?r.options.annotations:[r.options.annotations]).find(a=>o.has(a))}else return!0},Ay=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),n=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>e.has(u.id)||i.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(r.created||[]).filter(u=>!s.has(u.id)).map(u=>o.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],h=[...(r.deleted||[]).filter(u=>!n.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:p}=u;if(o.has(p.id)){const f=t.updated.find(m=>m.oldValue.id===p.id).newValue;return uc(d,f)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},fs=r=>{const t=r.id===void 0?vy():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Sy=r=>r.id!==void 0,Cy=()=>{const r=new Map,t=new Map,e=[],i=(I,T={})=>{e.push({onChange:I,options:T})},n=I=>{const T=e.findIndex(E=>E.onChange==I);T>-1&&e.splice(T,1)},s=(I,T)=>{const E={origin:I,changes:{created:T.created||[],updated:T.updated||[],deleted:T.deleted||[]},state:[...r.values()]};e.forEach(S=>{Ty(S,E)&&S.onChange(E)})},o=(I,T=Nt.LOCAL)=>{if(I.id&&r.get(I.id))throw Error(`Cannot add annotation ${I.id} - exists already`);{const E=fs(I);r.set(E.id,E),E.bodies.forEach(S=>t.set(S.id,E.id)),s(T,{created:[E]})}},a=(I,T)=>{const E=fs(typeof I=="string"?T:I),S=typeof I=="string"?I:I.id,B=S&&r.get(S);if(B){const D=uc(B,E);return S===E.id?r.set(S,E):(r.delete(S),r.set(E.id,E)),B.bodies.forEach(N=>t.delete(N.id)),E.bodies.forEach(N=>t.set(N.id,E.id)),D}else console.warn(`Cannot update annotation ${S} - does not exist`)},l=(I,T=Nt.LOCAL,E=Nt.LOCAL)=>{const S=Sy(T)?E:T,B=a(I,T);B&&s(S,{updated:[B]})},h=(I,T=Nt.LOCAL)=>{r.get(I.id)?l(I,T):o(I,T)},c=(I,T=Nt.LOCAL)=>{const E=I.reduce((S,B)=>{const D=a(B);return D?[...S,D]:S},[]);E.length>0&&s(T,{updated:E})},u=(I,T=Nt.LOCAL)=>{const E=I.map(fs),{toAdd:S,toUpdate:B}=E.reduce((N,H)=>r.get(H.id)?{...N,toUpdate:[...N.toUpdate,H]}:{...N,toAdd:[...N.toAdd,H]},{toAdd:[],toUpdate:[]}),D=B.map(N=>a(N,T)).filter(Boolean);S.forEach(N=>{r.set(N.id,N),N.bodies.forEach(H=>t.set(H.id,N.id))}),s(T,{created:S,updated:D})},d=(I,T=Nt.LOCAL)=>{const E=r.get(I.annotation);if(E){const S={...E,bodies:[...E.bodies,I]};r.set(E.id,S),t.set(I.id,S.id),s(T,{updated:[{oldValue:E,newValue:S,bodiesCreated:[I]}]})}else console.warn(`Attempt to add body to missing annotation: ${I.annotation}`)},p=()=>[...r.values()],f=(I=Nt.LOCAL)=>{const T=[...r.values()];r.clear(),t.clear(),s(I,{deleted:T})},m=(I,T=!0,E=Nt.LOCAL)=>{const S=I.map(fs);if(T){const B=[...r.values()];r.clear(),t.clear(),S.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:S,deleted:B})}else{const B=I.reduce((D,N)=>{const H=N.id&&r.get(N.id);return H?[...D,H]:D},[]);if(B.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${B.map(D=>D.id).join(", ")}`);S.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:S})}},_=I=>{const T=typeof I=="string"?I:I.id,E=r.get(T);if(E)return r.delete(T),E.bodies.forEach(S=>t.delete(S.id)),E;console.warn(`Attempt to delete missing annotation: ${T}`)},v=(I,T=Nt.LOCAL)=>{const E=_(I);E&&s(T,{deleted:[E]})},y=(I,T=Nt.LOCAL)=>{const E=I.reduce((S,B)=>{const D=_(B);return D?[...S,D]:S},[]);E.length>0&&s(T,{deleted:E})},g=I=>{const T=r.get(I.annotation);if(T){const E=T.bodies.find(S=>S.id===I.id);if(E){t.delete(E.id);const S={...T,bodies:T.bodies.filter(B=>B.id!==I.id)};return r.set(T.id,S),{oldValue:T,newValue:S,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${I.id} from annotation ${I.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${I.annotation}`)},b=(I,T=Nt.LOCAL)=>{const E=g(I);E&&s(T,{updated:[E]})},C=(I,T=Nt.LOCAL)=>{const E=I.map(S=>g(S)).filter(Boolean);E.length>0&&s(T,{updated:E})},R=I=>{const T=r.get(I);return T?{...T}:void 0},A=I=>{const T=t.get(I);if(T){const E=R(T).bodies.find(S=>S.id===I);if(E)return E;console.error(`Store integrity error: body ${I} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${I}`)},P=(I,T)=>{if(I.annotation!==T.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=r.get(I.annotation);if(E){const S=E.bodies.find(D=>D.id===I.id),B={...E,bodies:E.bodies.map(D=>D.id===S.id?T:D)};return r.set(E.id,B),S.id!==T.id&&(t.delete(S.id),t.set(T.id,B.id)),{oldValue:E,newValue:B,bodiesUpdated:[{oldBody:S,newBody:T}]}}else console.warn(`Attempt to add body to missing annotation ${I.annotation}`)},M=(I,T,E=Nt.LOCAL)=>{const S=P(I,T);S&&s(E,{updated:[S]})},k=(I,T=Nt.LOCAL)=>{const E=I.map(S=>P({id:S.id,annotation:S.annotation},S)).filter(Boolean);s(T,{updated:E})},U=I=>{const T=r.get(I.annotation);if(T){const E={...T,target:{...T.target,...I}};return r.set(T.id,E),{oldValue:T,newValue:E,targetUpdated:{oldTarget:T.target,newTarget:I}}}else console.warn(`Attempt to update target on missing annotation: ${I.annotation}`)};return{addAnnotation:o,addBody:d,all:p,bulkAddAnnotations:m,bulkDeleteAnnotations:y,bulkDeleteBodies:C,bulkUpdateAnnotations:c,bulkUpdateBodies:k,bulkUpdateTargets:(I,T=Nt.LOCAL)=>{const E=I.map(S=>U(S)).filter(Boolean);E.length>0&&s(T,{updated:E})},bulkUpsertAnnotations:u,clear:f,deleteAnnotation:v,deleteBody:b,getAnnotation:R,getBody:A,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(I,T=Nt.LOCAL)=>{const E=U(I);E&&s(T,{updated:[E]})},upsertAnnotation:h}},Iy=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let Py=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,n=e.length;i<n;i++)e[i](...t)},events:{},on(r,t){var e;return((e=this.events)[r]||(e[r]=[])).push(t),()=>{var i;this.events[r]=(i=this.events[r])==null?void 0:i.filter(n=>t!==n)}}});const Ry=250,My=(r,t)=>{const e=Py(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=f=>{if(!s){const{changes:m}=f,_=performance.now();if(_-o>Ry)i.splice(n+1),i.push(m),n=i.length-1;else{const v=i.length-1;i[v]=Ay(i[v],m)}o=_}s=!1};r.observe(a,{origin:Nt.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f),h=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),c=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({oldValue:m})=>m)),u=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(f,m)=>e.on(f,m),redo:()=>{if(i.length-1>n){s=!0;const{created:f,updated:m,deleted:_}=i[n+1];h(f),u(m),p(_),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:f,updated:m,deleted:_}=i[n];l(f),c(m),d(_),e.emit("undo",i[n]),n-=1}}}},Dy=()=>{const{subscribe:r,set:t}=ea([]);return{subscribe:r,set:t}},Oy=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(v,y)=>{l.has(v)?l.get(v).push(y):l.set(v,[y])},p=(v,y)=>{const g=l.get(v);if(g){const b=g.indexOf(y);b!==-1&&g.splice(b,1)}},f=(v,y,g)=>{l.has(v)&&setTimeout(()=>{l.get(v).forEach(b=>{if(e){const C=Array.isArray(y)?y.map(A=>e.serialize(A)):e.serialize(y),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(C,R)}else b(y,g)})},1)},m=()=>{const{selected:v}=s,y=(v||[]).map(({id:g})=>o.getAnnotation(g));y.forEach(g=>{const b=h.find(C=>C.id===g.id);(!b||!Mr(b,g))&&f("updateAnnotation",g,b)}),h=h.map(g=>y.find(({id:b})=>b===g.id)||g)};s.subscribe(({selected:v})=>{if(!(h.length===0&&v.length===0)){if(h.length===0&&v.length>0)h=v.map(({id:y})=>o.getAnnotation(y));else if(h.length>0&&v.length===0)h.forEach(y=>{const g=o.getAnnotation(y.id);g&&!Mr(g,y)&&f("updateAnnotation",g,y)}),h=[];else{const y=new Set(h.map(b=>b.id)),g=new Set(v.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const C=o.getAnnotation(b.id);C&&!Mr(C,b)&&f("updateAnnotation",C,b)}),h=[...h.filter(b=>g.has(b.id)),...v.filter(({id:b})=>!y.has(b)).map(({id:b})=>o.getAnnotation(b))]}f("selectionChanged",h)}}),n.subscribe(v=>{!c&&v?f("mouseEnterAnnotation",o.getAnnotation(v)):c&&!v?f("mouseLeaveAnnotation",o.getAnnotation(c)):c&&v&&(f("mouseLeaveAnnotation",o.getAnnotation(c)),f("mouseEnterAnnotation",o.getAnnotation(v))),c=v}),a==null||a.subscribe(v=>f("viewportIntersect",v.map(y=>o.getAnnotation(y)))),o.observe(v=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:y,deleted:g}=v.changes;(y||[]).forEach(b=>f("createAnnotation",b)),(g||[]).forEach(b=>f("deleteAnnotation",b)),(v.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:C})=>{const R=h.find(A=>A.id===b.id)||b;h=h.map(A=>A.id===b.id?C:A),f("updateAnnotation",C,R)})},{origin:Nt.LOCAL}),o.observe(v=>{if(h){const y=new Set(h.map(b=>b.id)),g=(v.changes.updated||[]).filter(({newValue:b})=>y.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(C=>C.id===b.id)||b))}},{origin:Nt.REMOTE});const _=v=>y=>{const{updated:g}=y;v?(g||[]).forEach(b=>f("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>f("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:p,emit:f}},Ly=r=>t=>t.reduce((e,i)=>{const{parsed:n,error:s}=r.parse(i);return s?{parsed:e.parsed,failed:[...e.failed,i]}:n?{parsed:[...e.parsed,n],failed:e.failed}:{...e}},{parsed:[],failed:[]}),By=(r,t,e)=>{const{store:i,selection:n}=r,s=v=>{if(e){const{parsed:y,error:g}=e.parse(v);y?i.addAnnotation(y,Nt.REMOTE):console.error(g)}else i.addAnnotation(ia(v),Nt.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=v=>{const y=i.getAnnotation(v);return e&&y?e.serialize(y):y},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var v;const y=(((v=n.selected)==null?void 0:v.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?y.map(e.serialize):y},u=(v,y=!0)=>fetch(v).then(g=>g.json()).then(g=>(p(g,y),g)),d=v=>{if(typeof v=="string"){const y=i.getAnnotation(v);if(i.deleteAnnotation(v),y)return e?e.serialize(y):y}else{const y=e?e.parse(v).parsed:v;if(y)return i.deleteAnnotation(y),v}},p=(v,y=!0)=>{if(e){const g=e.parseAll||Ly(e),{parsed:b,failed:C}=g(v);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),i.bulkAddAnnotations(b,y,Nt.REMOTE)}else i.bulkAddAnnotations(v.map(ia),y,Nt.REMOTE)},f=(v,y)=>{v?n.setSelected(v,y):n.clear()},m=v=>{n.clear(),n.setUserSelectAction(v)},_=v=>{if(e){const y=e.parse(v).parsed,g=e.serialize(i.getAnnotation(y.id));return i.updateAnnotation(y),g}else{const y=i.getAnnotation(v.id);return i.updateAnnotation(ia(v)),y}};return{addAnnotation:s,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:f,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},Ny=(r,t,e)=>typeof t=="function"?t(r,e):t,Fy=(r,t)=>typeof r!="function"&&typeof t!="function"?{...r||{},...t||{}}:(e,i)=>{const n=typeof r=="function"?r(e,i):r,s=typeof t=="function"?t(e,i):t;return{...n||{},...s||{}}},ky="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Uy=r=>crypto.getRandomValues(new Uint8Array(r)),Gy=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,n=-~(1.6*i*t/r.length);return(s=t)=>{let o="";for(;;){let a=e(n),l=n|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=s)return o}}},$y=(r,t=21)=>Gy(r,t|0,Uy),Hy=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=ky[e[r]&63];return t};const Xy=()=>({isGuest:!0,id:$y("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Vy=r=>{const t=JSON.stringify(r);let e=0;for(let i=0,n=t.length;i<n;i++){let s=t.charCodeAt(i);e=(e<<5)-e+s,e|=0}return`${e}`},dc=r=>r?typeof r=="object"?{...r}:r:void 0,zy=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:n,purpose:s,value:o,created:a,modified:l,creator:h,...c}=e;return{id:i||`temp-${Vy(e)}`,annotation:t,type:n,purpose:s,value:o,creator:dc(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),jy=r=>r.map(t=>{var e;const{annotation:i,created:n,updated:s,...o}=t,a={...o,created:n==null?void 0:n.toISOString(),modified:s==null?void 0:s.toISOString()};return(e=a.id)!=null&&e.startsWith("temp-")&&delete a.id,a});Hy();const Wy=(r,t={strict:!0,invertY:!1})=>({parse:e=>Yy(e,t),serialize:e=>qy(e,r,t)}),Yy=(r,t={strict:!0,invertY:!1})=>{const e=r.id||ac(),{creator:i,created:n,modified:s,body:o,...a}=r,l=zy(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,c=typeof h=="string"?h:Array.isArray(h.selector)?h.selector[0]:h.selector,u=typeof c=="string"||(c==null?void 0:c.type)==="FragmentSelector"?Wg(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?ny(c):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return u||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:n?new Date(n):void 0,creator:dc(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},qy=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:n,created:s,updated:o,updatedBy:a,...l}=r.target;let h;try{h=i.type==mt.RECTANGLE?Yg(i.geometry):oy(i)}catch(u){if(e.strict)throw u;h=i}const c={...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:r.id,type:"Annotation",body:jy(r.bodies),created:s==null?void 0:s.toISOString(),creator:n,modified:o==null?void 0:o.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:h}};return delete c.bodies,"annotation"in c.target&&delete c.target.annotation,c},Ii=[];function Ky(r,t=It){let e;const i=new Set;function n(a){if(qt(r,a)&&(r=a,e)){const l=!Ii.length;for(const h of i)h[1](),Ii.push(h,r);if(l){for(let h=0;h<Ii.length;h+=2)Ii[h][0](Ii[h+1]);Ii.length=0}}}function s(a){n(a(r))}function o(a,l=It){const h=[a,l];return i.add(h),i.size===1&&(e=t(n,s)||It),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:n,update:s,subscribe:o}}const Zy=(r,t)=>{const{naturalWidth:e,naturalHeight:i}=r;if(!e&&!i){const{width:n,height:s}=r;t.setAttribute("viewBox",`0 0 ${n} ${s}`),r.addEventListener("load",o=>{const a=o.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${e} ${i}`)},Jy=(r,t)=>{Zy(r,t);const{subscribe:e,set:i}=Ky(1);let n;return window.ResizeObserver&&(n=new ResizeObserver(()=>{const s=t.getBoundingClientRect(),{width:o,height:a}=t.viewBox.baseVal,l=Math.max(s.width/o,s.height/a);i(l)}),n.observe(t.parentElement)),{destroy:()=>{n&&n.disconnect()},subscribe:e}},ti=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:n,stroke:s,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${n||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},ps=(r,t=0)=>{const{minX:e,minY:i,maxX:n,maxY:s}=r;return{x:e-t,y:i-t,w:n-e+2*t,h:s-i+2*t}},pr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Qy=r=>({}),fc=r=>({grab:r[0]});function t0(r){let t,e,i,n;const s=r[8].default,o=Sg(s,r,r[7],fc);return{c(){t=W("g"),o&&o.c(),x(t,"class","a9s-annotation selected")},m(a,l){rt(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Ct(t,"pointerup",r[2]),Ct(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Ig(o,s,a,a[7],e?Cg(s,a[7],l,Qy):Pg(a[7]),fc)},i(a){e||(at(o,a),e=!0)},o(a){pt(o,a),e=!1},d(a){a&&tt(t),o&&o.d(a),i=!1,Me(n)}}}function e0(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Rr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const p=_=>v=>{if(c=_,h){const{left:y,top:g}=h.getBoundingClientRect(),b=v.clientX-y,C=v.clientY-g;u=l.elementToImage(b,C)}else{const{offsetX:y,offsetY:g}=v;u=l.elementToImage(y,g)}d=o,v.target.setPointerCapture(v.pointerId),s("grab",v)},f=_=>{if(c){const[v,y]=l.elementToImage(_.offsetX,_.offsetY),g=[v-u[0],y-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=_=>{_.target.releasePointerCapture(_.pointerId),c=void 0,d=o,s("release",_)};return r.$$set=_=>{"shape"in _&&e(3,o=_.shape),"editor"in _&&e(4,a=_.editor),"transform"in _&&e(5,l=_.transform),"svgEl"in _&&e(6,h=_.svgEl),"$$scope"in _&&e(7,n=_.$$scope)},[p,f,m,o,a,l,h,n,i]}class na extends pe{constructor(t){super(),fe(this,t,e0,t0,qt,{shape:3,editor:4,transform:5,svgEl:6})}}function r0(r){let t,e,i,n,s,o,a,l,h=r[3]&&pc(r);return{c(){t=W("g"),e=W("circle"),h&&h.c(),n=W("circle"),x(e,"class","a9s-handle-buffer"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=r[5]+6/r[2]),x(e,"role","button"),x(e,"tabindex","0"),x(n,"class",s=`a9s-handle-dot${r[3]?" selected":""}`),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",r[5]),x(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){rt(c,t,u),bt(t,e),h&&h.m(t,null),bt(t,n),a||(l=[Ct(e,"dblclick",r[11]),Ct(e,"pointerenter",r[12]),Ct(e,"pointerleave",r[13]),Ct(e,"pointerdown",r[14]),Ct(e,"pointerdown",r[6]),Ct(e,"pointerup",r[15]),Ct(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&x(e,"cx",c[0]),u&2&&x(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&x(e,"r",i),c[3]?h?h.p(c,u):(h=pc(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=`a9s-handle-dot${c[3]?" selected":""}`)&&x(n,"class",s),u&1&&x(n,"cx",c[0]),u&2&&x(n,"cy",c[1]),u&32&&x(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&x(t,"class",o)},d(c){c&&tt(t),h&&h.d(),a=!1,Me(l)}}}function i0(r){let t,e,i,n,s,o,a,l,h;return{c(){t=W("g"),e=W("circle"),n=W("circle"),o=W("circle"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=r[5]*10),x(e,"class","a9s-touch-halo"),Ze(e,"touched",r[4]),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",s=r[5]+10/r[2]),x(n,"class","a9s-handle-buffer"),x(o,"class","a9s-handle-dot"),x(o,"cx",r[0]),x(o,"cy",r[1]),x(o,"r",a=r[5]+2/r[2]),x(t,"class","a9s-touch-handle")},m(c,u){rt(c,t,u),bt(t,e),bt(t,n),bt(t,o),l||(h=[Ct(n,"pointerdown",r[9]),Ct(n,"pointerup",r[10]),Ct(n,"pointerdown",r[6]),Ct(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&x(e,"cx",c[0]),u&2&&x(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&x(e,"r",i),u&16&&Ze(e,"touched",c[4]),u&1&&x(n,"cx",c[0]),u&2&&x(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&x(n,"r",s),u&1&&x(o,"cx",c[0]),u&2&&x(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&x(o,"r",a)},d(c){c&&tt(t),l=!1,Me(h)}}}function pc(r){let t,e;return{c(){t=W("circle"),x(t,"class","a9s-handle-selected"),x(t,"cx",r[0]),x(t,"cy",r[1]),x(t,"r",e=r[5]+8/r[2])},m(i,n){rt(i,t,n)},p(i,n){n&1&&x(t,"cx",i[0]),n&2&&x(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&x(t,"r",e)},d(i){i&&tt(t)}}}function n0(r){let t;function e(n,s){return pr?i0:r0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),rt(n,t,s)},p(n,[s]){i.p(n,s)},i:It,o:It,d(n){n&&tt(t),i.d(n)}}}function s0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=y=>{y.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(y){de.call(this,r,y)}function d(y){de.call(this,r,y)}function p(y){de.call(this,r,y)}function f(y){de.call(this,r,y)}function m(y){de.call(this,r,y)}function _(y){de.call(this,r,y)}function v(y){de.call(this,r,y)}return r.$$set=y=>{e(8,t=Xo(Xo({},t),Wh(y))),"x"in y&&e(0,n=y.x),"y"in y&&e(1,s=y.y),"scale"in y&&e(2,o=y.scale),"selected"in y&&e(3,a=y.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Wh(t),[n,s,o,a,l,i,h,c,t,u,d,p,f,m,_,v]}class Pi extends pe{constructor(t){super(),fe(this,t,s0,n0,qt,{x:0,y:1,scale:2,selected:3})}}function o0(r){let t,e,i,n,s,o,a;return{c(){t=W("g"),e=W("circle"),n=W("circle"),s=W("circle"),x(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=1.75*r[2]),x(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",r[2]),x(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),x(s,"cx",r[0]),x(s,"cy",r[1]),x(s,"r",r[2]),x(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){rt(l,t,h),bt(t,e),bt(t,n),bt(t,s),o||(a=[Ct(e,"pointerdown",r[5]),Ct(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&x(e,"cx",l[0]),h&2&&x(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&x(e,"r",i),h&1&&x(n,"cx",l[0]),h&2&&x(n,"cy",l[1]),h&4&&x(n,"r",l[2]),h&1&&x(s,"cx",l[0]),h&2&&x(s,"cy",l[1]),h&4&&x(s,"r",l[2])},d(l){l&&tt(t),o=!1,Me(a)}}}function a0(r){let t;return{c(){t=W("circle"),x(t,"cx",r[0]),x(t,"cy",r[1]),x(t,"r",r[2])},m(e,i){rt(e,t,i)},p(e,i){i&1&&x(t,"cx",e[0]),i&2&&x(t,"cy",e[1]),i&4&&x(t,"r",e[2])},d(e){e&&tt(t)}}}function l0(r){let t;function e(n,s){return pr?a0:o0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),rt(n,t,s)},p(n,[s]){i.p(n,s)},i:It,o:It,d(n){n&&tt(t),i.d(n)}}}function h0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){de.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,n=h.x),"y"in h&&e(1,s=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[n,s,i,a,o,l]}class mc extends pe{constructor(t){super(),fe(this,t,h0,l0,qt,{x:0,y:1,scale:4})}}function sa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function gc(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function oa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function aa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function yc(r){let t,e,i,n;return{c(){t=W("circle"),x(t,"cx",e=r[28][0]),x(t,"cy",i=r[28][1]),x(t,"r",n=_n/r[3]),x(t,"class","svelte-1h2slbm")},m(s,o){rt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&x(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&x(t,"cy",i),o[0]&8&&n!==(n=_n/s[3])&&x(t,"r",n)},d(s){s&&tt(t)}}}function _c(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=W("mask"),e=W("rect"),a=W("circle"),x(e,"x",i=r[9].x),x(e,"y",n=r[9].y),x(e,"width",s=r[9].w),x(e,"height",o=r[9].h),x(e,"class","svelte-1h2slbm"),x(a,"cx",l=r[28][0]),x(a,"cy",h=r[28][1]),x(a,"r",c=_n/r[3]),x(a,"class","svelte-1h2slbm"),x(t,"id",`${r[19]}-inner`),x(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){rt(u,t,d),bt(t,e),bt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&x(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&x(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&x(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&x(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&x(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&x(a,"cy",h),d[0]&8&&c!==(c=_n/u[3])&&x(a,"r",c)},d(u){u&&tt(t)}}}function vc(r){let t,e;return t=new Pi({props:{class:"a9s-corner-handle",x:r[28][0],y:r[28][1],scale:r[3],selected:r[8].includes(r[30])}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[15]),t.$on("pointerdown",function(){Gt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function bc(r){let t,e;return t=new mc({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Gt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function c0(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y,g,b,C,R=r[6]!==void 0&&!r[7]&&yc(aa(r)),A=r[6]!==void 0&&!r[7]&&_c(oa(r)),P=Ie(r[5].points),M=[];for(let I=0;I<P.length;I+=1)M[I]=vc(gc(r,P,I));const k=I=>pt(M[I],1,1,()=>{M[I]=null});let U=r[6]!==void 0&&!r[7]&&bc(sa(r));return{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("polygon"),R&&R.c(),A&&A.c(),c=we(),u=W("polygon"),p=we(),f=W("polygon"),_=we();for(let I=0;I<M.length;I+=1)M[I].c();v=we(),U&&U.c(),y=De(),x(i,"x",n=r[9].x),x(i,"y",s=r[9].y),x(i,"width",o=r[9].w),x(i,"height",a=r[9].h),x(i,"class","svelte-1h2slbm"),x(l,"points",h=r[5].points.map(xc).join(" ")),x(l,"class","svelte-1h2slbm"),x(e,"id",`${r[19]}-outer`),x(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),x(u,"class","a9s-outer"),x(u,"mask",`url(#${r[19]}-outer)`),x(u,"points",d=r[5].points.map(wc).join(" ")),x(f,"class","a9s-inner a9s-shape-handle"),x(f,"mask",`url(#${r[19]}-inner)`),x(f,"style",r[1]),x(f,"points",m=r[5].points.map(Ec).join(" "))},m(I,T){rt(I,t,T),bt(t,e),bt(e,i),bt(e,l),R&&R.m(e,null),A&&A.m(t,null),rt(I,c,T),rt(I,u,T),rt(I,p,T),rt(I,f,T),rt(I,_,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(I,T);rt(I,v,T),U&&U.m(I,T),rt(I,y,T),g=!0,b||(C=[Ct(u,"pointerup",r[14]),Ct(u,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Ct(f,"pointermove",r[13]),Ct(f,"pointerup",r[14]),Ct(f,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(I,T){if(r=I,(!g||T[0]&512&&n!==(n=r[9].x))&&x(i,"x",n),(!g||T[0]&512&&s!==(s=r[9].y))&&x(i,"y",s),(!g||T[0]&512&&o!==(o=r[9].w))&&x(i,"width",o),(!g||T[0]&512&&a!==(a=r[9].h))&&x(i,"height",a),(!g||T[0]&32&&h!==(h=r[5].points.map(xc).join(" ")))&&x(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(aa(r),T):(R=yc(aa(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?A?A.p(oa(r),T):(A=_c(oa(r)),A.c(),A.m(t,null)):A&&(A.d(1),A=null),(!g||T[0]&32&&d!==(d=r[5].points.map(wc).join(" ")))&&x(u,"points",d),(!g||T[0]&2)&&x(f,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Ec).join(" ")))&&x(f,"points",m),T[0]&134322472){P=Ie(r[5].points);let E;for(E=0;E<P.length;E+=1){const S=gc(r,P,E);M[E]?(M[E].p(S,T),at(M[E],1)):(M[E]=vc(S),M[E].c(),at(M[E],1),M[E].m(v.parentNode,v))}for(Ee(),E=P.length;E<M.length;E+=1)k(E);Te()}r[6]!==void 0&&!r[7]?U?(U.p(sa(r),T),T[0]&192&&at(U,1)):(U=bc(sa(r)),U.c(),at(U,1),U.m(y.parentNode,y)):U&&(Ee(),pt(U,1,1,()=>{U=null}),Te())},i(I){if(!g){for(let T=0;T<P.length;T+=1)at(M[T]);at(U),g=!0}},o(I){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)pt(M[T]);pt(U),g=!1},d(I){I&&(tt(t),tt(c),tt(u),tt(p),tt(f),tt(_),tt(v),tt(y)),R&&R.d(),A&&A.d(),Zr(M,I),U&&U.d(I),b=!1,Me(C)}}}function u0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[c0,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}const d0=250,f0=1e3,p0=12,_n=4.5,xc=r=>r.join(","),wc=r=>r.join(","),Ec=r=>r.join(",");function m0(r,t,e){let i,n,s;const o=Rr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const _=()=>e(7,p=!0),v=()=>e(7,p=!1),y=E=>{if(m.length>0||!n.some(L=>L.visible)){e(6,d=void 0);return}const[S,B]=h.elementToImage(E.offsetX,E.offsetY),D=L=>Math.pow(L[0]-S,2)+Math.pow(L[1]-B,2),N=i.points.reduce((L,$)=>D($)<D(L)?$:L),H=n.filter(L=>L.visible).reduce((L,$)=>D($.point)<D(L.point)?$:L),O=Math.pow(f0/c,2);D(N)<O||D(H.point)<O?e(6,d=n.indexOf(H)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},C=E=>{e(7,p=!0),E.preventDefault(),E.stopPropagation(),f=performance.now()},R=E=>S=>{if(!f||pr||performance.now()-f>d0)return;const B=m.includes(E);S.metaKey||S.ctrlKey||S.shiftKey?B?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):B&&m.length>1?e(8,m=[E]):B?e(8,m=[]):e(8,m=[E]),g()},A=(E,S,B)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,L],$)=>m.includes($)?[O+B[0],L+B[1]]:[O,L]):S==="SHAPE"?D=N.points.map(([O,L])=>[O+B[0],L+B[1]]):D=N.points.map(([O,L],$)=>S===`HANDLE-${$}`?[O+B[0],L+B[1]]:[O,L]);const H=Ae(D);return{...E,geometry:{points:D,bounds:H}}},P=E=>async S=>{S.stopPropagation();const B=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=Ae(B);o("change",{...a,geometry:{points:B,bounds:D}}),await Qh();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:S.clientX,clientY:S.clientY,pointerId:S.pointerId,pointerType:S.pointerType,isPrimary:S.isPrimary,buttons:S.buttons});N.firstChild.dispatchEvent(H)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((B,D)=>!m.includes(D)),S=Ae(E);o("change",{...a,geometry:{points:E,bounds:S}}),e(8,m=[])};Jr(()=>{if(pr)return;const E=S=>{(S.key==="Delete"||S.key==="Backspace")&&(S.preventDefault(),M())};return u.addEventListener("pointermove",y),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",y),u.removeEventListener("keydown",E)}});const k=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){de.call(this,r,E)}function I(E){de.call(this,r,E)}function T(E){de.call(this,r,E)}return r.$$set=E=>{"shape"in E&&e(0,a=E.shape),"computedStyle"in E&&e(1,l=E.computedStyle),"transform"in E&&e(2,h=E.transform),"viewportScale"in E&&e(3,c=E.viewportScale),"svgEl"in E&&e(4,u=E.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=pr?[]:i.points.map((E,S)=>{const B=S===i.points.length-1?i.points[0]:i.points[S+1],D=(E[0]+B[0])/2,N=(E[1]+B[1])/2,H=Math.sqrt(Math.pow(B[0]-D,2)+Math.pow(B[1]-N,2))>p0/c;return{point:[D,N],visible:H}})),r.$$.dirty[0]&40&&e(9,s=ps(i.bounds,_n/c))},[a,l,h,c,u,i,d,p,m,s,n,_,v,y,b,C,R,A,P,k,U,I,T]}class g0 extends pe{constructor(t){super(),fe(this,t,m0,u0,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function y0(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y,g,b,C,R,A,P,M,k,U,I,T,E,S,B,D,N,H,O,L,$,F,X,V,dt,yt,z,wt,it,ft,_t,Pt,Dt,he,Vt,Q,Ge,Jn;return it=new Pi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),it.$on("pointerdown",function(){Gt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),_t=new Pi({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),_t.$on("pointerdown",function(){Gt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Pi({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Dt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new Pi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("rect"),p=we(),f=W("rect"),g=we(),b=W("rect"),M=we(),k=W("rect"),E=we(),S=W("rect"),H=we(),O=W("rect"),X=we(),V=W("rect"),wt=we(),ee(it.$$.fragment),ft=we(),ee(_t.$$.fragment),Pt=we(),ee(Dt.$$.fragment),he=we(),ee(Vt.$$.fragment),x(i,"class","rect-mask-bg svelte-1njczvj"),x(i,"x",n=r[6].x),x(i,"y",s=r[6].y),x(i,"width",o=r[6].w),x(i,"height",a=r[6].h),x(l,"class","rect-mask-fg svelte-1njczvj"),x(l,"x",h=r[5].x),x(l,"y",c=r[5].y),x(l,"width",u=r[5].w),x(l,"height",d=r[5].h),x(e,"id",r[8]),x(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),x(f,"class","a9s-outer"),x(f,"mask",`url(#${r[8]})`),x(f,"x",m=r[5].x),x(f,"y",_=r[5].y),x(f,"width",v=r[5].w),x(f,"height",y=r[5].h),x(b,"class","a9s-inner a9s-shape-handle"),x(b,"style",r[1]),x(b,"x",C=r[5].x),x(b,"y",R=r[5].y),x(b,"width",A=r[5].w),x(b,"height",P=r[5].h),x(k,"class","a9s-edge-handle a9s-edge-handle-top"),x(k,"x",U=r[5].x),x(k,"y",I=r[5].y),x(k,"height",1),x(k,"width",T=r[5].w),x(S,"class","a9s-edge-handle a9s-edge-handle-right"),x(S,"x",B=r[5].x+r[5].w),x(S,"y",D=r[5].y),x(S,"height",N=r[5].h),x(S,"width",1),x(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),x(O,"x",L=r[5].x),x(O,"y",$=r[5].y+r[5].h),x(O,"height",1),x(O,"width",F=r[5].w),x(V,"class","a9s-edge-handle a9s-edge-handle-left"),x(V,"x",dt=r[5].x),x(V,"y",yt=r[5].y),x(V,"height",z=r[5].h),x(V,"width",1)},m(Y,G){rt(Y,t,G),bt(t,e),bt(e,i),bt(e,l),rt(Y,p,G),rt(Y,f,G),rt(Y,g,G),rt(Y,b,G),rt(Y,M,G),rt(Y,k,G),rt(Y,E,G),rt(Y,S,G),rt(Y,H,G),rt(Y,O,G),rt(Y,X,G),rt(Y,V,G),rt(Y,wt,G),Jt(it,Y,G),rt(Y,ft,G),Jt(_t,Y,G),rt(Y,Pt,G),Jt(Dt,Y,G),rt(Y,he,G),Jt(Vt,Y,G),Q=!0,Ge||(Jn=[Ct(f,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Ct(b,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Ct(k,"pointerdown",function(){Gt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Ct(S,"pointerdown",function(){Gt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Ct(O,"pointerdown",function(){Gt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Ct(V,"pointerdown",function(){Gt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],Ge=!0)},p(Y,G){r=Y,(!Q||G&64&&n!==(n=r[6].x))&&x(i,"x",n),(!Q||G&64&&s!==(s=r[6].y))&&x(i,"y",s),(!Q||G&64&&o!==(o=r[6].w))&&x(i,"width",o),(!Q||G&64&&a!==(a=r[6].h))&&x(i,"height",a),(!Q||G&32&&h!==(h=r[5].x))&&x(l,"x",h),(!Q||G&32&&c!==(c=r[5].y))&&x(l,"y",c),(!Q||G&32&&u!==(u=r[5].w))&&x(l,"width",u),(!Q||G&32&&d!==(d=r[5].h))&&x(l,"height",d),(!Q||G&32&&m!==(m=r[5].x))&&x(f,"x",m),(!Q||G&32&&_!==(_=r[5].y))&&x(f,"y",_),(!Q||G&32&&v!==(v=r[5].w))&&x(f,"width",v),(!Q||G&32&&y!==(y=r[5].h))&&x(f,"height",y),(!Q||G&2)&&x(b,"style",r[1]),(!Q||G&32&&C!==(C=r[5].x))&&x(b,"x",C),(!Q||G&32&&R!==(R=r[5].y))&&x(b,"y",R),(!Q||G&32&&A!==(A=r[5].w))&&x(b,"width",A),(!Q||G&32&&P!==(P=r[5].h))&&x(b,"height",P),(!Q||G&32&&U!==(U=r[5].x))&&x(k,"x",U),(!Q||G&32&&I!==(I=r[5].y))&&x(k,"y",I),(!Q||G&32&&T!==(T=r[5].w))&&x(k,"width",T),(!Q||G&32&&B!==(B=r[5].x+r[5].w))&&x(S,"x",B),(!Q||G&32&&D!==(D=r[5].y))&&x(S,"y",D),(!Q||G&32&&N!==(N=r[5].h))&&x(S,"height",N),(!Q||G&32&&L!==(L=r[5].x))&&x(O,"x",L),(!Q||G&32&&$!==($=r[5].y+r[5].h))&&x(O,"y",$),(!Q||G&32&&F!==(F=r[5].w))&&x(O,"width",F),(!Q||G&32&&dt!==(dt=r[5].x))&&x(V,"x",dt),(!Q||G&32&&yt!==(yt=r[5].y))&&x(V,"y",yt),(!Q||G&32&&z!==(z=r[5].h))&&x(V,"height",z);const Ar={};G&32&&(Ar.x=r[5].x),G&32&&(Ar.y=r[5].y),G&8&&(Ar.scale=r[3]),it.$set(Ar);const Sr={};G&32&&(Sr.x=r[5].x+r[5].w),G&32&&(Sr.y=r[5].y),G&8&&(Sr.scale=r[3]),_t.$set(Sr);const Cr={};G&32&&(Cr.x=r[5].x+r[5].w),G&32&&(Cr.y=r[5].y+r[5].h),G&8&&(Cr.scale=r[3]),Dt.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x),G&32&&(Ir.y=r[5].y+r[5].h),G&8&&(Ir.scale=r[3]),Vt.$set(Ir)},i(Y){Q||(at(it.$$.fragment,Y),at(_t.$$.fragment,Y),at(Dt.$$.fragment,Y),at(Vt.$$.fragment,Y),Q=!0)},o(Y){pt(it.$$.fragment,Y),pt(_t.$$.fragment,Y),pt(Dt.$$.fragment,Y),pt(Vt.$$.fragment,Y),Q=!1},d(Y){Y&&(tt(t),tt(p),tt(f),tt(g),tt(b),tt(M),tt(k),tt(E),tt(S),tt(H),tt(O),tt(X),tt(V),tt(wt),tt(ft),tt(Pt),tt(he)),Qt(it,Y),Qt(_t,Y),Qt(Dt,Y),Qt(Vt,Y),Ge=!1,Me(Jn)}}}function _0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[y0,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:r}}}),t.$on("grab",r[9]),t.$on("change",r[10]),t.$on("release",r[11]),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function v0(r,t,e){let i,n,{shape:s}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const c=(m,_,v)=>{const y=m.geometry.bounds;let[g,b]=[y.minX,y.minY],[C,R]=[y.maxX,y.maxY];const[A,P]=v;if(_==="SHAPE")g+=A,C+=A,b+=P,R+=P;else{switch(_){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=P;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=P;break}}switch(_){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=A;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{C+=A;break}}}const M=Math.min(g,C),k=Math.min(b,R),U=Math.abs(C-g),I=Math.abs(R-b);return{...m,geometry:{x:M,y:k,w:U,h:I,bounds:{minX:M,minY:k,maxX:M+U,maxY:k+I}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){de.call(this,r,m)}function p(m){de.call(this,r,m)}function f(m){de.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,s=m.shape),"computedStyle"in m&&e(1,o=m.computedStyle),"transform"in m&&e(2,a=m.transform),"viewportScale"in m&&e(3,l=m.viewportScale),"svgEl"in m&&e(4,h=m.svgEl)},r.$$.update=()=>{r.$$.dirty&1&&e(5,i=s.geometry),r.$$.dirty&40&&e(6,n=ps(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,p,f]}class b0 extends pe{constructor(t){super(),fe(this,t,v0,_0,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Tc=Object.prototype.hasOwnProperty;function la(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&la(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Tc.call(r,e)&&++i&&!Tc.call(t,e)||!(e in t)||!la(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const x0=12,w0=(r,t)=>r.polygons.reduce((e,i,n)=>{const s=i.rings.reduce((o,a,l)=>{const h=a.points.map((c,u)=>{const d=u===a.points.length-1?a.points[0]:a.points[u+1],p=(c[0]+d[0])/2,f=(c[1]+d[1])/2,m=Math.sqrt(Math.pow(d[0]-p,2)+Math.pow(d[1]-f,2))>x0/t;return{point:[p,f],visible:m,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function ha(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ac(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Sc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Cc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function ca(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function ua(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ic(r){let t,e,i,n;return{c(){t=W("circle"),x(t,"cx",e=r[29][0]),x(t,"cy",i=r[29][1]),x(t,"r",n=vn/r[3]),x(t,"class","svelte-1vxo6dc")},m(s,o){rt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&x(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&x(t,"cy",i),o[0]&8&&n!==(n=vn/s[3])&&x(t,"r",n)},d(s){s&&tt(t)}}}function Pc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=W("mask"),e=W("rect"),a=W("circle"),x(e,"x",i=r[9].x),x(e,"y",n=r[9].y),x(e,"width",s=r[9].w),x(e,"height",o=r[9].h),x(e,"class","svelte-1vxo6dc"),x(a,"cx",l=r[29][0]),x(a,"cy",h=r[29][1]),x(a,"r",c=vn/r[3]),x(a,"class","svelte-1vxo6dc"),x(t,"id",`${r[18]}-${r[32]}-inner`),x(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){rt(u,t,d),bt(t,e),bt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&x(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&x(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&x(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&x(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&x(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&x(a,"cy",h),d[0]&8&&c!==(c=vn/u[3])&&x(a,"r",c)},d(u){u&&tt(t)}}}function Rc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Pi({props:{class:"a9s-corner-handle",x:r[29][0],y:r[29][1],scale:r[3],selected:r[8].some(i)}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[14]),t.$on("pointerdown",function(){Gt(r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`))&&r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`).apply(this,arguments)}),t.$on("pointerup",r[15](r[32],r[35],r[37])),{c(){ee(t.$$.fragment)},m(n,s){Jt(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(at(t.$$.fragment,n),e=!0)},o(n){pt(t.$$.fragment,n),e=!1},d(n){Qt(t,n)}}}function Mc(r){let t,e,i=Ie(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Rc(Cc(r,i,o));const s=o=>pt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=De()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);rt(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Ie(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Cc(o,i,l);n[l]?(n[l].p(h,a),at(n[l],1)):(n[l]=Rc(h),n[l].c(),at(n[l],1),n[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<n.length;l+=1)s(l);Te()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)at(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)pt(n[a]);e=!1},d(o){o&&tt(t),Zr(n,o)}}}function Dc(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y=r[6]!==void 0&&!r[7]&&Ic(ua(r)),g=r[6]!==void 0&&!r[7]&&Pc(ca(r)),b=Ie(r[30].rings),C=[];for(let A=0;A<b.length;A+=1)C[A]=Mc(Sc(r,b,A));const R=A=>pt(C[A],1,1,()=>{C[A]=null});return{c(){t=W("g"),e=W("defs"),i=W("mask"),n=W("rect"),h=W("path"),y&&y.c(),g&&g.c(),u=W("path"),p=W("path");for(let A=0;A<C.length;A+=1)C[A].c();x(n,"x",s=r[9].x),x(n,"y",o=r[9].y),x(n,"width",a=r[9].w),x(n,"height",l=r[9].h),x(n,"class","svelte-1vxo6dc"),x(h,"d",c=$e(r[30])),x(h,"class","svelte-1vxo6dc"),x(i,"id",`${r[18]}-${r[32]}-outer`),x(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),x(u,"class","a9s-outer"),x(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),x(u,"fill-rule","evenodd"),x(u,"d",d=$e(r[30])),x(p,"class","a9s-inner"),x(p,"mask",`url(#${r[18]}-${r[32]}-inner)`),x(p,"style",r[1]),x(p,"fill-rule","evenodd"),x(p,"d",f=$e(r[30]))},m(A,P){rt(A,t,P),bt(t,e),bt(e,i),bt(i,n),bt(i,h),y&&y.m(i,null),g&&g.m(e,null),bt(t,u),bt(t,p);for(let M=0;M<C.length;M+=1)C[M]&&C[M].m(t,null);m=!0,_||(v=[Ct(u,"pointerup",r[13]),Ct(u,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Ct(p,"pointerup",r[13]),Ct(p,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],_=!0)},p(A,P){if(r=A,(!m||P[0]&512&&s!==(s=r[9].x))&&x(n,"x",s),(!m||P[0]&512&&o!==(o=r[9].y))&&x(n,"y",o),(!m||P[0]&512&&a!==(a=r[9].w))&&x(n,"width",a),(!m||P[0]&512&&l!==(l=r[9].h))&&x(n,"height",l),(!m||P[0]&32&&c!==(c=$e(r[30])))&&x(h,"d",c),r[6]!==void 0&&!r[7]?y?y.p(ua(r),P):(y=Ic(ua(r)),y.c(),y.m(i,null)):y&&(y.d(1),y=null),r[6]!==void 0&&!r[7]?g?g.p(ca(r),P):(g=Pc(ca(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||P[0]&32&&d!==(d=$e(r[30])))&&x(u,"d",d),(!m||P[0]&2)&&x(p,"style",r[1]),(!m||P[0]&32&&f!==(f=$e(r[30])))&&x(p,"d",f),P[0]&268491048){b=Ie(r[30].rings);let M;for(M=0;M<b.length;M+=1){const k=Sc(r,b,M);C[M]?(C[M].p(k,P),at(C[M],1)):(C[M]=Mc(k),C[M].c(),at(C[M],1),C[M].m(t,null))}for(Ee(),M=b.length;M<C.length;M+=1)R(M);Te()}},i(A){if(!m){for(let P=0;P<b.length;P+=1)at(C[P]);m=!0}},o(A){C=C.filter(Boolean);for(let P=0;P<C.length;P+=1)pt(C[P]);m=!1},d(A){A&&tt(t),y&&y.d(),g&&g.d(),Zr(C,A),_=!1,Me(v)}}}function Oc(r){let t,e;return t=new mc({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Gt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function E0(r){let t,e,i,n=Ie(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Dc(Ac(r,n,l));const o=l=>pt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&Oc(ha(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=we(),a&&a.c(),e=De()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);rt(l,t,h),a&&a.m(l,h),rt(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=Ie(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=Ac(l,n,c);s[c]?(s[c].p(u,h),at(s[c],1)):(s[c]=Dc(u),s[c].c(),at(s[c],1),s[c].m(t.parentNode,t))}for(Ee(),c=n.length;c<s.length;c+=1)o(c);Te()}l[6]!==void 0&&!l[7]?a?(a.p(ha(l),h),h[0]&192&&at(a,1)):(a=Oc(ha(l)),a.c(),at(a,1),a.m(e.parentNode,e)):a&&(Ee(),pt(a,1,1,()=>{a=null}),Te())},i(l){if(!i){for(let h=0;h<n.length;h+=1)at(s[h]);at(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)pt(s[h]);pt(a),i=!1},d(l){l&&(tt(t),tt(e)),Zr(s,l),a&&a.d(l)}}}function T0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[E0,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}const A0=250,S0=1e3,vn=4.5;function C0(r,t,e){let i,n,s;const o=Rr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const _=()=>e(7,p=!0),v=()=>e(7,p=!1),y=S=>{if(m.length>0||!n.some($=>$.visible)){e(6,d=void 0);return}const[B,D]=h.elementToImage(S.offsetX,S.offsetY),N=$=>Math.pow($[0]-B,2)+Math.pow($[1]-D,2),H=Hg(i).reduce(($,F)=>N(F)<N($)?F:$),O=n.filter($=>$.visible).reduce(($,F)=>N(F.point)<N($.point)?F:$),L=Math.pow(S0/c,2);N(H)<L||N(O.point)<L?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},C=S=>{e(7,p=!0),S.preventDefault(),S.stopPropagation(),f=performance.now()},R=(S,B,D)=>N=>{if(!f||pr||performance.now()-f>A0)return;const H=L=>L.polygon===S&&L.ring===B&&L.point===D,O=m.some(H);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(L=>!H(L))):e(8,m=[...m,{polygon:S,ring:B,point:D}]):O&&m.length>1?e(8,m=[{polygon:S,ring:B,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:S,ring:B,point:D}]),g()},A=(S,B,D)=>{g();const N=S.geometry.polygons;let H;if(B==="SHAPE")H=N.map(O=>{const L=O.rings.map((F,X)=>({points:F.points.map((V,dt)=>[V[0]+D[0],V[1]+D[1]])})),$=Ae(L[0].points);return{rings:L,bounds:$}});else{const[O,L,$,F]=B.split("-").map(X=>parseInt(X));H=N.map((X,V)=>{if(V===L){const dt=X.rings.map((z,wt)=>wt===$?{points:z.points.map((it,ft)=>ft===F?[it[0]+D[0],it[1]+D[1]]:it)}:z),yt=Ae(dt[0].points);return{rings:dt,bounds:yt}}else return X})}return{...S,geometry:{polygons:H,bounds:Ko(H)}}},P=S=>async B=>{B.stopPropagation();const D=n[S],N=i.polygons.map((O,L)=>{if(L===D.elementIdx){const $=O.rings.map((X,V)=>V===D.ringIdx?{points:[...X.points.slice(0,D.pointIdx+1),D.point,...X.points.slice(D.pointIdx+1)]}:X),F=Ae($[0].points);return{rings:$,bounds:F}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Ko(N)}}),await Qh();const H=[...document.querySelectorAll(".a9s-handle")][S+1];if(H!=null&&H.firstChild){const O=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:B.clientX,clientY:B.clientY,pointerId:B.pointerId,pointerType:B.pointerType,isPrimary:B.isPrimary,buttons:B.buttons});H.firstChild.dispatchEvent(O)}},M=()=>{const S=i.polygons.map((B,D)=>{if(m.some(N=>N.polygon===D)){const N=B.rings.map((O,L)=>{const $=m.filter(F=>F.polygon===D&&F.ring===L);return $.length&&O.points.length-$.length>=3?{points:O.points.filter((F,X)=>!$.some(V=>V.point===X))}:O}),H=Ae(N[0].points);return{rings:N,bounds:H}}else return B});!la(i.polygons,S)&&(o("change",{...a,geometry:{polygons:S,bounds:Ko(S)}}),e(8,m=[]))};Jr(()=>{if(pr)return;const S=B=>{(B.key==="Delete"||B.key==="Backspace")&&(B.preventDefault(),M())};return u.addEventListener("pointermove",y),u.addEventListener("keydown",S),()=>{u.removeEventListener("pointermove",y),u.removeEventListener("keydown",S)}});const k=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(S,B,D,{polygon:N,ring:H,point:O})=>N===S&&H===B&&O===D;function I(S){de.call(this,r,S)}function T(S){de.call(this,r,S)}function E(S){de.call(this,r,S)}return r.$$set=S=>{"shape"in S&&e(0,a=S.shape),"computedStyle"in S&&e(1,l=S.computedStyle),"transform"in S&&e(2,h=S.transform),"viewportScale"in S&&e(3,c=S.viewportScale),"svgEl"in S&&e(4,u=S.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=pr?[]:w0(i,c)),r.$$.dirty[0]&40&&e(9,s=ps(i.bounds,vn/c))},[a,l,h,c,u,i,d,p,m,s,n,_,v,b,C,R,A,P,k,U,I,T,E]}class I0 extends pe{constructor(t){super(),fe(this,t,C0,T0,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Lc=new Map([[mt.RECTANGLE,b0],[mt.POLYGON,g0],[mt.MULTIPOLYGON,I0]]),da=r=>Lc.get(r.type),Bc=(r,t)=>Lc.set(r,t);function P0(r,t,e){let i;const n=Rr();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return Jr(()=>(e(6,u=new o({target:l,props:{shape:s.target.selector,computedStyle:i,transform:h,viewportScale:c,svgEl:l.closest("svg")}})),u.$on("change",d=>{u.$$set({shape:d.detail}),n("change",d.detail)}),u.$on("grab",d=>n("grab",d.detail)),u.$on("release",d=>n("release",d.detail)),()=>{u.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,s=d.annotation),"editor"in d&&e(1,o=d.editor),"style"in d&&e(2,a=d.style),"target"in d&&e(3,l=d.target),"transform"in d&&e(4,h=d.transform),"viewportScale"in d&&e(5,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=ti(s,a)),r.$$.dirty&65&&s&&(u==null||u.$set({shape:s.target.selector})),r.$$.dirty&80&&u&&u.$set({transform:h}),r.$$.dirty&96&&u&&u.$set({viewportScale:c}),r.$$.dirty&192&&u&&i&&u.$set({computedStyle:i})},[s,o,a,l,h,c,u,i]}class R0 extends pe{constructor(t){super(),fe(this,t,P0,null,qt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function M0(r,t,e){const i=Rr();let{drawingMode:n}=t,{target:s}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return Jr(()=>{const c=s.closest("svg"),u=[],d=(p,f,m)=>{c==null||c.addEventListener(p,f,m),u.push(()=>c==null?void 0:c.removeEventListener(p,f,m))};return e(5,h=new o({target:s,props:{addEventListener:d,drawingMode:n,transform:a,viewportScale:l}})),h.$on("create",p=>i("create",p.detail)),()=>{u.forEach(p=>p()),h.$destroy()}}),r.$$set=c=>{"drawingMode"in c&&e(0,n=c.drawingMode),"target"in c&&e(1,s=c.target),"tool"in c&&e(2,o=c.tool),"transform"in c&&e(3,a=c.transform),"viewportScale"in c&&e(4,l=c.viewportScale)},r.$$.update=()=>{r.$$.dirty&40&&h&&h.$set({transform:a}),r.$$.dirty&48&&h&&h.$set({viewportScale:l})},[n,s,o,a,l,h]}class D0 extends pe{constructor(t){super(),fe(this,t,M0,null,qt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Nc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("rect"),h=W("rect"),c=W("rect"),x(i,"class","rect-mask-bg svelte-1a76qe7"),x(i,"x",n=r[1]-r[5]),x(i,"y",s=r[2]-r[5]),x(i,"width",o=r[3]+2*r[5]),x(i,"height",a=r[4]+2*r[5]),x(l,"class","rect-mask-fg svelte-1a76qe7"),x(l,"x",r[1]),x(l,"y",r[2]),x(l,"width",r[3]),x(l,"height",r[4]),x(e,"id",r[6]),x(e,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),x(h,"class","a9s-outer"),x(h,"mask",`url(#${r[6]})`),x(h,"x",r[1]),x(h,"y",r[2]),x(h,"width",r[3]),x(h,"height",r[4]),x(c,"class","a9s-inner"),x(c,"x",r[1]),x(c,"y",r[2]),x(c,"width",r[3]),x(c,"height",r[4])},m(u,d){rt(u,t,d),bt(t,e),bt(e,i),bt(e,l),rt(u,h,d),rt(u,c,d)},p(u,d){d&34&&n!==(n=u[1]-u[5])&&x(i,"x",n),d&36&&s!==(s=u[2]-u[5])&&x(i,"y",s),d&40&&o!==(o=u[3]+2*u[5])&&x(i,"width",o),d&48&&a!==(a=u[4]+2*u[5])&&x(i,"height",a),d&2&&x(l,"x",u[1]),d&4&&x(l,"y",u[2]),d&8&&x(l,"width",u[3]),d&16&&x(l,"height",u[4]),d&2&&x(h,"x",u[1]),d&4&&x(h,"y",u[2]),d&8&&x(h,"width",u[3]),d&16&&x(h,"height",u[4]),d&2&&x(c,"x",u[1]),d&4&&x(c,"y",u[2]),d&8&&x(c,"width",u[3]),d&16&&x(c,"height",u[4])},d(u){u&&(tt(t),tt(h),tt(c))}}}function O0(r){let t,e=r[0]&&Nc(r);return{c(){t=W("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){rt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[0]?e?e.p(i,n):(e=Nc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:It,o:It,d(i){i&&tt(t),e&&e.d()}}}function L0(r,t,e){let i;const n=Rr();let{addEventListener:s}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c,u,d,p,f,m;const _=C=>{const R=C;h=performance.now(),o==="drag"&&(e(0,c=a.elementToImage(R.offsetX,R.offsetY)),u=c,e(1,d=c[0]),e(2,p=c[1]),e(3,f=1),e(4,m=1))},v=C=>{const R=C;c&&(u=a.elementToImage(R.offsetX,R.offsetY),e(1,d=Math.min(u[0],c[0])),e(2,p=Math.min(u[1],c[1])),e(3,f=Math.abs(u[0]-c[0])),e(4,m=Math.abs(u[1]-c[1])))},y=C=>{const R=C,A=performance.now()-h;if(o==="click"){if(A>300)return;c?g():(e(0,c=a.elementToImage(R.offsetX,R.offsetY)),u=c,e(1,d=c[0]),e(2,p=c[1]),e(3,f=1),e(4,m=1))}else c&&(A>300||f*m>100?(R.stopPropagation(),g()):(e(0,c=void 0),u=void 0))},g=()=>{if(f*m>15){const C={type:mt.RECTANGLE,geometry:{bounds:{minX:d,minY:p,maxX:d+f,maxY:p+m},x:d,y:p,w:f,h:m}};n("create",C)}e(0,c=void 0),u=void 0};Jr(()=>{s("pointerdown",_),s("pointermove",v),s("pointerup",y,!0)});const b=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=C=>{"addEventListener"in C&&e(7,s=C.addEventListener),"drawingMode"in C&&e(8,o=C.drawingMode),"transform"in C&&e(9,a=C.transform),"viewportScale"in C&&e(10,l=C.viewportScale)},r.$$.update=()=>{r.$$.dirty&1024&&e(5,i=2/l)},[c,d,p,f,m,i,b,s,o,a,l]}class B0 extends pe{constructor(t){super(),fe(this,t,L0,O0,qt,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function fa(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function Fc(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m=r[1]&&kc(r);return{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("polygon"),c=W("polygon"),d=W("polygon"),m&&m.c(),f=De(),x(i,"x",n=r[3].x),x(i,"y",s=r[3].y),x(i,"width",o=r[3].w),x(i,"height",a=r[3].h),x(i,"class","svelte-18wrg3t"),x(l,"points",h=r[19]),x(l,"class","svelte-18wrg3t"),x(e,"id",r[5]),x(e,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),x(c,"class","a9s-outer"),x(c,"mask",`url(#${r[5]})`),x(c,"points",u=r[19]),x(d,"class","a9s-inner"),x(d,"points",p=r[19])},m(_,v){rt(_,t,v),bt(t,e),bt(e,i),bt(e,l),rt(_,c,v),rt(_,d,v),m&&m.m(_,v),rt(_,f,v)},p(_,v){v&8&&n!==(n=_[3].x)&&x(i,"x",n),v&8&&s!==(s=_[3].y)&&x(i,"y",s),v&8&&o!==(o=_[3].w)&&x(i,"width",o),v&8&&a!==(a=_[3].h)&&x(i,"height",a),v&4&&h!==(h=_[19])&&x(l,"points",h),v&4&&u!==(u=_[19])&&x(c,"points",u),v&4&&p!==(p=_[19])&&x(d,"points",p),_[1]?m?m.p(_,v):(m=kc(_),m.c(),m.m(f.parentNode,f)):m&&(m.d(1),m=null)},d(_){_&&(tt(t),tt(c),tt(d),tt(f)),m&&m.d(_)}}}function kc(r){let t,e,i;return{c(){t=W("circle"),x(t,"class","a9s-handle svelte-18wrg3t"),x(t,"cx",e=r[0][0][0]),x(t,"cy",i=r[0][0][1]),x(t,"r",r[4])},m(n,s){rt(n,t,s)},p(n,s){s&1&&e!==(e=n[0][0][0])&&x(t,"cx",e),s&1&&i!==(i=n[0][0][1])&&x(t,"cy",i),s&16&&x(t,"r",n[4])},d(n){n&&tt(t)}}}function N0(r){let t,e=r[3]&&Fc(fa(r));return{c(){t=W("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){rt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[3]?e?e.p(fa(i),n):(e=Fc(fa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:It,o:It,d(i){i&&tt(t),e&&e.d()}}}const F0=20,k0=1500;function U0(r,t,e){let i,n,s;const o=Rr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:c=1}=t,u,d=[],p,f,m=!1;const _=R=>{const A=R,{timeStamp:P,offsetX:M,offsetY:k}=A;if(u={timeStamp:P,offsetX:M,offsetY:k},l==="drag"&&d.length===0){const U=h.elementToImage(A.offsetX,A.offsetY);d.push(U),e(10,p=U)}},v=R=>{const A=R;if(f&&clearTimeout(f),d.length>0){if(e(10,p=h.elementToImage(A.offsetX,A.offsetY)),d.length>2){const P=hs(p,d[0])*c;e(1,m=P<F0)}A.pointerType==="touch"&&(f=setTimeout(()=>{g()},k0))}},y=R=>{const A=R;if(f&&clearTimeout(f),l==="click"){const P=A.timeStamp-u.timeStamp,M=hs([u.offsetX,u.offsetY],[A.offsetX,A.offsetY]);if(P>300||M>15)return;if(m)b();else if(d.length===0){const k=h.elementToImage(A.offsetX,A.offsetY);d.push(k),e(10,p=k)}else d.push(p)}else{if(d.length===1&&hs(d[0],p)<=4){e(0,d=[]),e(10,p=void 0);return}A.stopImmediatePropagation(),m?b():d.push(p)}},g=()=>{if(!p)return;const R=d.slice(0,-1);if(R.length<3)return;const A={type:mt.POLYGON,geometry:{bounds:Ae(d),points:R}};qo(A)>4&&(e(0,d=[]),e(10,p=void 0),o("create",A))},b=()=>{const R={type:mt.POLYGON,geometry:{bounds:Ae(d),points:[...d]}};e(0,d=[]),e(10,p=void 0),o("create",R)};Jr(()=>{a("pointerdown",_,!0),a("pointermove",v),a("pointerup",y,!0),a("dblclick",g,!0)});const C=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=R=>{"addEventListener"in R&&e(6,a=R.addEventListener),"drawingMode"in R&&e(7,l=R.drawingMode),"transform"in R&&e(8,h=R.transform),"viewportScale"in R&&e(9,c=R.viewportScale)},r.$$.update=()=>{r.$$.dirty&512&&e(4,i=4/c),r.$$.dirty&1027&&e(2,n=p?m?d:[...d,p]:[]),r.$$.dirty&516&&e(3,s=n.length>0?ps(Ae(n),2/c):void 0)},[d,m,n,s,i,C,a,l,h,c,p]}class G0 extends pe{constructor(t){super(),fe(this,t,U0,N0,qt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const pa=new Map([["rectangle",{tool:B0}],["polygon",{tool:G0}]]),ms=()=>[...pa.keys()],gs=r=>pa.get(r),Uc=(r,t,e={})=>pa.set(r,{tool:t,opts:e});function $0(r){let t,e,i,n,s;return{c(){t=W("g"),e=W("ellipse"),n=W("ellipse"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"cx",r[2]),x(e,"cy",r[3]),x(e,"rx",r[4]),x(e,"ry",r[5]),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"cx",r[2]),x(n,"cy",r[3]),x(n,"rx",r[4]),x(n,"ry",r[5]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:It,o:It,d(o){o&&tt(t)}}}function H0(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:c}=s;return r.$$set=u=>{"annotation"in u&&e(0,n=u.annotation),"geom"in u&&e(6,s=u.geom),"style"in u&&e(7,o=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=ti(n,o))},[n,i,a,l,h,c,s,o]}class X0 extends pe{constructor(t){super(),fe(this,t,H0,$0,qt,{annotation:0,geom:6,style:7})}}function V0(r){let t,e,i,n,s;return{c(){t=W("g"),e=W("line"),n=W("line"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"x1",r[2]),x(e,"y1",r[3]),x(e,"x2",r[4]),x(e,"y2",r[5]),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"x1",r[2]),x(n,"y1",r[3]),x(n,"x2",r[4]),x(n,"y2",r[5]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:It,o:It,d(o){o&&tt(t)}}}function z0(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{points:a}=s,[[l,h],[c,u]]=a;return r.$$set=d=>{"annotation"in d&&e(0,n=d.annotation),"geom"in d&&e(6,s=d.geom),"style"in d&&e(7,o=d.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=ti(n,o))},[n,i,l,h,c,u,s,o]}class j0 extends pe{constructor(t){super(),fe(this,t,z0,V0,qt,{annotation:0,geom:6,style:7})}}function Gc(r,t,e){const i=r.slice();return i[5]=t[e],i}function $c(r){let t,e,i;return{c(){t=W("path"),i=W("path"),x(t,"class","a9s-outer"),x(t,"style",e=r[1]?"display:none;":void 0),x(t,"fill-rule","evenodd"),x(t,"d",$e(r[5])),x(i,"class","a9s-inner"),x(i,"style",r[1]),x(i,"fill-rule","evenodd"),x(i,"d",$e(r[5]))},m(n,s){rt(n,t,s),rt(n,i,s)},p(n,s){s&2&&e!==(e=n[1]?"display:none;":void 0)&&x(t,"style",e),s&2&&x(i,"style",n[1])},d(n){n&&(tt(t),tt(i))}}}function W0(r){let t,e,i=Ie(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=$c(Gc(r,i,s));return{c(){t=W("g");for(let s=0;s<n.length;s+=1)n[s].c();x(t,"class","a9s-annotation"),x(t,"data-id",e=r[0].id)},m(s,o){rt(s,t,o);for(let a=0;a<n.length;a+=1)n[a]&&n[a].m(t,null)},p(s,[o]){if(o&6){i=Ie(s[2]);let a;for(a=0;a<i.length;a+=1){const l=Gc(s,i,a);n[a]?n[a].p(l,o):(n[a]=$c(l),n[a].c(),n[a].m(t,null))}for(;a<n.length;a+=1)n[a].d(1);n.length=i.length}o&1&&e!==(e=s[0].id)&&x(t,"data-id",e)},i:It,o:It,d(s){s&&tt(t),Zr(n,s)}}}function Y0(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{polygons:a}=s;return r.$$set=l=>{"annotation"in l&&e(0,n=l.annotation),"geom"in l&&e(3,s=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=ti(n,o))},[n,i,a,s,o]}class q0 extends pe{constructor(t){super(),fe(this,t,Y0,W0,qt,{annotation:0,geom:3,style:4})}}function K0(r){let t,e,i,n,s;return{c(){t=W("g"),e=W("polygon"),n=W("polygon"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"points",r[2].map(Z0).join(" ")),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"points",r[2].map(J0).join(" ")),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:It,o:It,d(o){o&&tt(t)}}}const Z0=r=>r.join(","),J0=r=>r.join(",");function Q0(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{points:a}=s;return r.$$set=l=>{"annotation"in l&&e(0,n=l.annotation),"geom"in l&&e(3,s=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=ti(n,o))},[n,i,a,s,o]}class t_ extends pe{constructor(t){super(),fe(this,t,Q0,K0,qt,{annotation:0,geom:3,style:4})}}function e_(r){let t,e,i,n,s,o,a;return{c(){t=W("g"),e=W("path"),s=W("path"),x(e,"class",i=ns(`a9s-outer ${r[1]}`)+" svelte-1w0132l"),x(e,"style",n=r[3]?"display:none;":void 0),x(e,"d",r[2]),x(s,"class",o=ns(`a9s-inner ${r[1]}`)+" svelte-1w0132l"),x(s,"style",r[3]),x(s,"d",r[2]),x(t,"class","a9s-annotation"),x(t,"data-id",a=r[0].id)},m(l,h){rt(l,t,h),bt(t,e),bt(t,s)},p(l,[h]){h&2&&i!==(i=ns(`a9s-outer ${l[1]}`)+" svelte-1w0132l")&&x(e,"class",i),h&8&&n!==(n=l[3]?"display:none;":void 0)&&x(e,"style",n),h&4&&x(e,"d",l[2]),h&2&&o!==(o=ns(`a9s-inner ${l[1]}`)+" svelte-1w0132l")&&x(s,"class",o),h&8&&x(s,"style",l[3]),h&4&&x(s,"d",l[2]),h&1&&a!==(a=l[0].id)&&x(t,"data-id",a)},i:It,o:It,d(l){l&&tt(t)}}}function r_(r,t,e){let i,n,s,{annotation:o}=t,{geom:a}=t,{style:l}=t;return r.$$set=h=>{"annotation"in h&&e(0,o=h.annotation),"geom"in h&&e(4,a=h.geom),"style"in h&&e(5,l=h.style)},r.$$.update=()=>{r.$$.dirty&33&&e(3,i=ti(o,l)),r.$$.dirty&16&&e(2,n=Jo(a)),r.$$.dirty&16&&e(1,s=a.closed?"closed":"open")},[o,s,n,i,a,l]}class i_ extends pe{constructor(t){super(),fe(this,t,r_,e_,qt,{annotation:0,geom:4,style:5})}}function n_(r){let t,e,i,n,s;return{c(){t=W("g"),e=W("rect"),n=W("rect"),x(e,"class","a9s-outer"),x(e,"style",i=r[5]?"display:none;":void 0),x(e,"x",r[4]),x(e,"y",r[3]),x(e,"width",r[2]),x(e,"height",r[1]),x(n,"class","a9s-inner"),x(n,"style",r[5]),x(n,"x",r[4]),x(n,"y",r[3]),x(n,"width",r[2]),x(n,"height",r[1]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&x(e,"style",i),a&16&&x(e,"x",o[4]),a&8&&x(e,"y",o[3]),a&4&&x(e,"width",o[2]),a&2&&x(e,"height",o[1]),a&32&&x(n,"style",o[5]),a&16&&x(n,"x",o[4]),a&8&&x(n,"y",o[3]),a&4&&x(n,"width",o[2]),a&2&&x(n,"height",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:It,o:It,d(o){o&&tt(t)}}}function s_(r,t,e){let i,n,s,o,a,{annotation:l}=t,{geom:h}=t,{style:c}=t;return r.$$set=u=>{"annotation"in u&&e(0,l=u.annotation),"geom"in u&&e(6,h=u.geom),"style"in u&&e(7,c=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=ti(l,c)),r.$$.dirty&64&&e(4,{x:n,y:s,w:o,h:a}=h,n,(e(3,s),e(6,h)),(e(2,o),e(6,h)),(e(1,a),e(6,h)))},[l,a,o,s,n,i,h,c]}class o_ extends pe{constructor(t){super(),fe(this,t,s_,n_,qt,{annotation:0,geom:6,style:7})}}const a_=r=>({elementToImage:(t,e)=>{const i=r.getBoundingClientRect(),n=r.createSVGPoint();n.x=t+i.x,n.y=e+i.y;const{x:s,y:o}=n.matrixTransform(r.getScreenCTM().inverse());return[s,o]}}),l_=250,h_=(r,t)=>{const e=Rr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<l_){const{x:s,y:o}=Hc(n,r),a=t.getAt(s,o,void 0,2);a?e("click",{originalEvent:n,annotation:a}):e("click",{originalEvent:n})}}}},Hc=(r,t)=>{const e=t.createSVGPoint(),i=t.getBoundingClientRect(),n=r.clientX-i.x,s=r.clientY-i.y,{left:o,top:a}=t.getBoundingClientRect();return e.x=n+o,e.y=s+a,e.matrixTransform(t.getScreenCTM().inverse())};function Xc(r,t,e){const i=r.slice();return i[39]=t[e],i}function Vc(r,t,e){const i=r.slice();return i[42]=t[e],i}function ma(r){const t=r.slice(),e=t[42].target.selector;return t[45]=e,t}function zc(r){let t=r[42],e,i,n=jc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&131072&&qt(t,t=s[42])?(Ee(),pt(n,1,1,It),Te(),n=jc(s),n.c(),at(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(at(n),i=!0)},o(s){pt(n),i=!1},d(s){s&&tt(e),n.d(s)}}}function c_(r){let t,e;return t=new j0({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function u_(r){let t,e;return t=new i_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function d_(r){let t,e;return t=new q0({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function f_(r){let t,e;return t=new t_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function p_(r){let t,e;return t=new o_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function m_(r){var t;let e,i;return e=new X0({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){ee(e.$$.fragment)},m(n,s){Jt(e,n,s),i=!0},p(n,s){var o;const a={};s[0]&131072&&(a.annotation=n[42]),s[0]&131072&&(a.geom=(o=n[45])==null?void 0:o.geometry),s[0]&2&&(a.style=n[1]),e.$set(a)},i(n){i||(at(e.$$.fragment,n),i=!0)},o(n){pt(e.$$.fragment,n),i=!1},d(n){Qt(e,n)}}}function jc(r){let t,e,i,n;const s=[m_,p_,f_,d_,u_,c_],o=[];function a(l,h){var c,u,d,p,f,m;return((c=l[45])==null?void 0:c.type)===mt.ELLIPSE?0:((u=l[45])==null?void 0:u.type)===mt.RECTANGLE?1:((d=l[45])==null?void 0:d.type)===mt.POLYGON?2:((p=l[45])==null?void 0:p.type)===mt.MULTIPOLYGON?3:((f=l[45])==null?void 0:f.type)===mt.POLYLINE?4:((m=l[45])==null?void 0:m.type)===mt.LINE?5:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=De()},m(l,h){~t&&o[t].m(l,h),rt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),pt(o[c],1,1,()=>{o[c]=null}),Te()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),at(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(at(e),n=!0)},o(l){pt(e),n=!1},d(l){l&&tt(i),~t&&o[t].d(l)}}}function Wc(r){let t=Be(r[42])&&!r[10](r[42]),e,i,n=t&&zc(ma(r));return{c(){n&&n.c(),e=De()},m(s,o){n&&n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&132096&&(t=Be(s[42])&&!s[10](s[42])),t?n?(n.p(ma(s),o),o[0]&132096&&at(n,1)):(n=zc(ma(s)),n.c(),at(n,1),n.m(e.parentNode,e)):n&&(Ee(),pt(n,1,1,()=>{n=null}),Te())},i(s){i||(at(n),i=!0)},o(s){pt(n),i=!1},d(s){s&&tt(e),n&&n.d(s)}}}function Yc(r){let t,e,i,n;const s=[y_,g_],o=[];function a(l,h){return l[6]?0:l[15]&&l[0]?1:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=De()},m(l,h){~t&&o[t].m(l,h),rt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),pt(o[c],1,1,()=>{o[c]=null}),Te()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),at(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(at(e),n=!0)},o(l){pt(e),n=!1},d(l){l&&tt(i),~t&&o[t].d(l)}}}function g_(r){let t=`${r[2]}-${r[7]}`,e,i,n=qc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&132&&qt(t,t=`${s[2]}-${s[7]}`)?(Ee(),pt(n,1,1,It),Te(),n=qc(s),n.c(),at(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(at(n),i=!0)},o(s){pt(n),i=!1},d(s){s&&tt(e),n.d(s)}}}function y_(r){let t,e,i=Ie(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=Zc(Xc(r,i,o));const s=o=>pt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=De()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);rt(o,t,a),e=!0},p(o,a){if(a[0]&8659266){i=Ie(o[6]);let l;for(l=0;l<i.length;l+=1){const h=Xc(o,i,l);n[l]?(n[l].p(h,a),at(n[l],1)):(n[l]=Zc(h),n[l].c(),at(n[l],1),n[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<n.length;l+=1)s(l);Te()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)at(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)pt(n[a]);e=!1},d(o){o&&tt(t),Zr(n,o)}}}function qc(r){let t,e;return t=new D0({props:{target:r[8],tool:r[15],drawingMode:r[14],transform:r[13],viewportScale:r[18]}}),t.$on("create",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&256&&(s.target=i[8]),n[0]&32768&&(s.tool=i[15]),n[0]&16384&&(s.drawingMode=i[14]),n[0]&8192&&(s.transform=i[13]),n[0]&262144&&(s.viewportScale=i[18]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function Kc(r){let t,e;return t=new R0({props:{target:r[8],editor:r[39].editor,annotation:r[39].annotation,style:r[1],transform:r[13],viewportScale:r[18]}}),t.$on("change",function(){Gt(r[23](r[39].annotation))&&r[23](r[39].annotation).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&256&&(s.target=r[8]),n[0]&64&&(s.editor=r[39].editor),n[0]&64&&(s.annotation=r[39].annotation),n[0]&2&&(s.style=r[1]),n[0]&8192&&(s.transform=r[13]),n[0]&262144&&(s.viewportScale=r[18]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function Zc(r){let t=r[39].annotation.id,e,i,n=Kc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&64&&qt(t,t=s[39].annotation.id)?(Ee(),pt(n,1,1,It),Te(),n=Kc(s),n.c(),at(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(at(n),i=!0)},o(s){pt(n),i=!1},d(s){s&&tt(e),n.d(s)}}}function __(r){let t,e,i,n,s,o,a=Ie(r[17].filter(r[34])),l=[];for(let u=0;u<a.length;u+=1)l[u]=Wc(Vc(r,a,u));const h=u=>pt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&Yc(r);return{c(){t=W("svg"),e=W("g");for(let u=0;u<l.length;u+=1)l[u].c();i=W("g"),c&&c.c(),x(i,"class","drawing"),x(t,"role","application"),x(t,"tabindex",0),x(t,"class","a9s-annotationlayer"),Ze(t,"drawing",r[15]),Ze(t,"editing",r[5]),Ze(t,"hidden",!r[3]),Ze(t,"hover",r[16])},m(u,d){rt(u,t,d),bt(t,e);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(e,null);bt(t,i),c&&c.m(i,null),r[35](i),r[36](t),n=!0,s||(o=[Ct(t,"pointerup",function(){Gt(r[11])&&r[11].apply(this,arguments)}),Ct(t,"pointerdown",function(){Gt(r[12])&&r[12].apply(this,arguments)}),Ct(t,"pointermove",r[24])],s=!0)},p(u,d){if(r=u,d[0]&132098){a=Ie(r[17].filter(r[34]));let p;for(p=0;p<a.length;p+=1){const f=Vc(r,a,p);l[p]?(l[p].p(f,d),at(l[p],1)):(l[p]=Wc(f),l[p].c(),at(l[p],1),l[p].m(e,null))}for(Ee(),p=a.length;p<l.length;p+=1)h(p);Te()}r[8]?c?(c.p(r,d),d[0]&256&&at(c,1)):(c=Yc(r),c.c(),at(c,1),c.m(i,null)):c&&(Ee(),pt(c,1,1,()=>{c=null}),Te()),(!n||d[0]&32768)&&Ze(t,"drawing",r[15]),(!n||d[0]&32)&&Ze(t,"editing",r[5]),(!n||d[0]&8)&&Ze(t,"hidden",!r[3]),(!n||d[0]&65536)&&Ze(t,"hover",r[16])},i(u){if(!n){for(let d=0;d<a.length;d+=1)at(l[d]);at(c),n=!0}},o(u){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)pt(l[d]);pt(c),n=!1},d(u){u&&tt(t),Zr(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,Me(o)}}}function v_(r,t,e){let i,n,s,o,a,l,h,c,u,d,p,f,m=It,_=()=>(m(),m=zh(S,z=>e(18,f=z)),S);r.$$.on_destroy.push(()=>m());let{drawingEnabled:v}=t,{image:y}=t,{preferredDrawingMode:g}=t,{state:b}=t,{style:C=void 0}=t,{toolName:R=ms()[0]}=t,{user:A}=t,{visible:P=!0}=t,M=0;const k=()=>e(7,M+=1),U=()=>R,I=()=>v;let T,E,S;Jr(()=>_(e(9,S=Jy(y,E))));const{hover:B,selection:D,store:N}=b;Vo(r,B,z=>e(16,u=z)),Vo(r,D,z=>e(33,d=z)),Vo(r,N,z=>e(17,p=z));let H,O;const L=z=>{H&&N.unobserve(H);const wt=z.filter(({editable:it})=>it).map(({id:it})=>it);wt.length>0?(e(5,O=wt.map(it=>N.getAnnotation(it)).filter(it=>it&&Be(it))),H=it=>{const{updated:ft}=it.changes;e(5,O=ft==null?void 0:ft.map(_t=>_t.newValue))},N.observe(H,{annotations:wt})):e(5,O=void 0)},$=z=>{const wt=ac(),it={id:wt,bodies:[],target:{annotation:wt,selector:z.detail,creator:A,created:new Date}};N.addAnnotation(it),D.setSelected(it.id)},F=z=>wt=>{var it;const{target:ft}=z,_t=10*60*1e3,Pt=((it=ft.creator)==null?void 0:it.id)!==A.id||!ft.created||new Date().getTime()-ft.created.getTime()>_t;N.updateTarget({...ft,selector:wt.detail,created:Pt?ft.created:new Date,updated:Pt?new Date:void 0,updatedBy:Pt?A:void 0})},X=z=>{const{x:wt,y:it}=Hc(z,E),ft=N.getAt(wt,it,void 0,2);ft?u!==ft.id&&B.set(ft.id):B.set(void 0)},V=z=>Be(z);function dt(z){ss[z?"unshift":"push"](()=>{T=z,e(8,T)})}function yt(z){ss[z?"unshift":"push"](()=>{E=z,e(4,E)})}return r.$$set=z=>{"drawingEnabled"in z&&e(0,v=z.drawingEnabled),"image"in z&&e(25,y=z.image),"preferredDrawingMode"in z&&e(26,g=z.preferredDrawingMode),"state"in z&&e(27,b=z.state),"style"in z&&e(1,C=z.style),"toolName"in z&&e(2,R=z.toolName),"user"in z&&e(28,A=z.user),"visible"in z&&e(3,P=z.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(15,{tool:i,opts:n}=gs(R)||{tool:void 0,opts:void 0},i,(e(32,n),e(2,R))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(14,s=(n==null?void 0:n.drawingMode)||g),r.$$.dirty[0]&16&&e(13,o=a_(E)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=h_(E,N),a,(e(11,l),e(4,E))),r.$$.dirty[1]&4&&L(d.selected),r.$$.dirty[0]&32&&e(6,h=O?O.map(z=>({annotation:z,editor:da(z.target.selector)})).filter(z=>z.editor):void 0),r.$$.dirty[0]&64&&e(10,c=z=>h&&h.some(wt=>wt.annotation.id===z.id))},[v,C,R,P,E,O,h,M,T,S,c,l,a,o,s,i,u,p,f,B,D,N,$,F,X,y,g,b,A,k,U,I,n,d,V,dt,yt]}class b_ extends pe{constructor(t){super(),fe(this,t,v_,__,qt,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function Jc(r,t,e=0,i=r.length-1,n=x_){for(;i>e;){if(i-e>600){const l=i-e+1,h=t-e+1,c=Math.log(l),u=.5*Math.exp(2*c/3),d=.5*Math.sqrt(c*u*(l-u)/l)*(h-l/2<0?-1:1),p=Math.max(e,Math.floor(t-h*u/l+d)),f=Math.min(i,Math.floor(t+(l-h)*u/l+d));Jc(r,t,p,f,n)}const s=r[t];let o=e,a=i;for(bn(r,e,t),n(r[i],s)>0&&bn(r,e,i);o<a;){for(bn(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?bn(r,e,a):(a++,bn(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function bn(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function x_(r,t){return r<t?-1:r>t?1:0}class w_{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 e=this.data;const i=[];if(!_s(t,e))return i;const n=this.toBBox,s=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?n(a):a;_s(t,l)&&(e.leaf?i.push(a):ya(t,l)?this._all(a,i):s.push(a))}e=s.pop()}return i}collides(t){let e=this.data;if(!_s(t,e))return!1;const i=[];for(;e;){for(let n=0;n<e.children.length;n++){const s=e.children[n],o=e.leaf?this.toBBox(s):s;if(_s(t,o)){if(e.leaf||ya(t,o))return!0;i.push(s)}}e=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const i=this.data;this.data=e,e=i}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Mi([]),this}remove(t,e){if(!t)return this;let i=this.data;const n=this.toBBox(t),s=[],o=[];let a,l,h;for(;i||s.length;){if(i||(i=s.pop(),l=s[s.length-1],a=o.pop(),h=!0),i.leaf){const c=E_(t,i.children,e);if(c!==-1)return i.children.splice(c,1),s.push(i),this._condense(s),this}!h&&!i.leaf&&ya(i,n)?(s.push(i),o.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],h=!1):i=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,n){const s=i-e+1;let o=this._maxEntries,a;if(s<=o)return a=Mi(t.slice(e,i+1)),Ri(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=Mi([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));Qc(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);Qc(t,c,u,l,this.compareMinY);for(let d=c;d<=u;d+=l){const p=Math.min(d+l-1,u);a.children.push(this._build(t,d,p,n-1))}}return Ri(a,this.toBBox),a}_chooseSubtree(t,e,i,n){for(;n.push(e),!(e.leaf||n.length-1===i);){let s=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],c=ga(h),u=S_(t,h)-c;u<o?(o=u,s=c<s?c:s,a=h):u===o&&c<s&&(s=c,a=h)}e=a||e.children[0]}return e}_insert(t,e,i){const n=i?t:this.toBBox(t),s=[],o=this._chooseSubtree(n,this.data,e,s);for(o.children.push(t),wn(o,n);e>=0&&s[e].children.length>this._maxEntries;)this._split(s,e),e--;this._adjustParentBBoxes(n,s,e)}_split(t,e){const i=t[e],n=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,n);const o=this._chooseSplitIndex(i,s,n),a=Mi(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Ri(i,this.toBBox),Ri(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Mi([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Ri(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let n,s=1/0,o=1/0;for(let a=e;a<=i-e;a++){const l=xn(t,0,a,this.toBBox),h=xn(t,a,i,this.toBBox),c=C_(l,h),u=ga(l)+ga(h);c<s?(s=c,n=a,o=u<o?u:o):c===s&&u<o&&(o=u,n=a)}return n||i-e}_chooseSplitAxis(t,e,i){const n=t.leaf?this.compareMinX:T_,s=t.leaf?this.compareMinY:A_,o=this._allDistMargin(t,e,i,n),a=this._allDistMargin(t,e,i,s);o<a&&t.children.sort(n)}_allDistMargin(t,e,i,n){t.children.sort(n);const s=this.toBBox,o=xn(t,0,e,s),a=xn(t,i-e,i,s);let l=ys(o)+ys(a);for(let h=e;h<i-e;h++){const c=t.children[h];wn(o,t.leaf?s(c):c),l+=ys(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];wn(a,t.leaf?s(c):c),l+=ys(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)wn(e[n],t)}_condense(t){for(let e=t.length-1,i;e>=0;e--)t[e].children.length===0?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():Ri(t[e],this.toBBox)}}function E_(r,t,e){if(!e)return t.indexOf(r);for(let i=0;i<t.length;i++)if(e(r,t[i]))return i;return-1}function Ri(r,t){xn(r,0,r.children.length,t,r)}function xn(r,t,e,i,n){n||(n=Mi(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(let s=t;s<e;s++){const o=r.children[s];wn(n,r.leaf?i(o):o)}return n}function wn(r,t){return r.minX=Math.min(r.minX,t.minX),r.minY=Math.min(r.minY,t.minY),r.maxX=Math.max(r.maxX,t.maxX),r.maxY=Math.max(r.maxY,t.maxY),r}function T_(r,t){return r.minX-t.minX}function A_(r,t){return r.minY-t.minY}function ga(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function ys(r){return r.maxX-r.minX+(r.maxY-r.minY)}function S_(r,t){return(Math.max(t.maxX,r.maxX)-Math.min(t.minX,r.minX))*(Math.max(t.maxY,r.maxY)-Math.min(t.minY,r.minY))}function C_(r,t){const e=Math.max(r.minX,t.minX),i=Math.max(r.minY,t.minY),n=Math.min(r.maxX,t.maxX),s=Math.min(r.maxY,t.maxY);return Math.max(0,n-e)*Math.max(0,s-i)}function ya(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function _s(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Mi(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Qc(r,t,e,i,n){const s=[t,e];for(;s.length;){if(e=s.pop(),t=s.pop(),e-t<=i)continue;const o=t+Math.ceil((e-t)/i/2)*i;Jc(r,o,t,e,n),s.push(t,o,o,e)}}const I_=()=>{const r=new w_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!cs(o))return;const{minX:a,minY:l,maxX:h,maxY:c}=o.selector.geometry.bounds,u={minX:a,minY:l,maxX:h,maxY:c,target:o};r.insert(u),t.set(o.annotation,u)},s=o=>{if(!cs(o))return;const a=t.get(o.annotation);a&&r.remove(a),t.delete(o.annotation)};return{all:e,clear:i,getAt:(o,a,l,h=0)=>{const c=r.search({minX:o-h,minY:a-h,maxX:o+h,maxY:a+h}).map(u=>u.target).filter(u=>u.selector.type===mt.RECTANGLE||Fg(u.selector,o,a,h));return c.length>0?(c.sort((u,d)=>qo(u.selector)-qo(d.selector)),c):[]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(c=>c.target),insert:n,remove:s,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,c)=>{if(cs(c)){const{minX:u,minY:d,maxX:p,maxY:f}=c.selector.geometry.bounds;return[...h,{minX:u,minY:d,maxX:p,maxY:f,target:c}]}else return h},[]);l.forEach(h=>t.set(h.target.annotation,h)),r.load(l)},size:()=>r.all().length,update:(o,a)=>{s(o),n(a)}}},tu=r=>{const t=Cy(),e=I_(),i=fy(t,r.userSelectAction,r.adapter),n=dy(t),s=Dy();return t.observe(({changes:o})=>{e.set((o.created||[]).map(a=>a.target),!1),(o.deleted||[]).forEach(a=>e.remove(a.target)),(o.updated||[]).forEach(({oldValue:a,newValue:l})=>e.update(a.target,l.target))}),{store:{...t,getAt:(o,a,l,h)=>{const c=e.getAt(o,a,l,h);if(l)return c.map(u=>t.getAnnotation(u.annotation)).filter(Boolean).filter(l)[0];{const u=c[0];return u?t.getAnnotation(u.annotation):void 0}},getIntersecting:(o,a,l,h)=>e.getIntersecting(o,a,l,h).map(c=>t.getAnnotation(c.annotation)).filter(Boolean)},selection:i,hover:n,viewport:s}},P_=r=>{const t=tu(r);return{...t,store:Iy(t.store)}},R_=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const n=r;t=document.createElement("canvas"),t.width=n.width,t.height=n.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(n,0,0,n.width,n.height)}let i=0;for(let n=1;n<10;n++)for(let s=1;s<10;s++){const o=Math.round(s*t.width/10),a=Math.round(n*t.height/10),l=e.getImageData(o,a,1,1).data,h=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=h}return i/81},eu=r=>{const t=R_(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},ru=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?eu(r):e),iu=(r,t)=>({...r,drawingEnabled:r.drawingEnabled===void 0?t.drawingEnabled:r.drawingEnabled,drawingMode:r.drawingMode||t.drawingMode,userSelectAction:r.userSelectAction||t.userSelectAction,theme:r.theme||t.theme}),nu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,su=(r,t)=>{const e=t||document,i=o=>{const a=o;a.key==="z"&&a.ctrlKey?r.undo():a.key==="y"&&a.ctrlKey&&r.redo()},n=o=>{const a=o;a.key==="z"&&a.metaKey&&(a.shiftKey?r.redo():r.undo())},s=()=>{nu?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return nu?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},M_=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=iu(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:hc.EDIT,theme:"light"}),n=P_(i),{selection:s,store:o}=n,a=My(o,i.initialHistory),l=Oy(n,a,i.adapter,i.autoSave),h=document.createElement("DIV");h.style.position="relative",h.style.display="inline-block",e.style.display="block",e.parentNode.insertBefore(h,e),h.appendChild(e);const c=su(a);let u=Xy();ru(e,h,i.theme);const d=new b_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",I=>{const{originalEvent:T,annotation:E}=I.detail;E?s.userSelect(E.id,T):s.isEmpty()||s.clear()});const p=By(n,a,i.adapter),f=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},_=()=>d.getDrawingTool(),v=()=>u,y=()=>d.isDrawingEnabled(),g=(I,T,E)=>Uc(I,T,E),b=(I,T)=>Bc(I,T),C=I=>{if(!gs(I))throw`No drawing tool named ${I}`;d.$set({toolName:I})},R=I=>d.$set({drawingEnabled:I}),A=I=>{console.warn("Filter not implemented yet")},P=I=>d.$set({style:I}),M=I=>ru(e,h,I),k=I=>{u=I,d.$set({user:I})},U=I=>d.$set({visible:I});return{...p,cancelDrawing:f,destroy:m,getDrawingTool:_,getUser:v,isDrawingEnabled:y,listDrawingTools:ms,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:b,setDrawingEnabled:R,setDrawingTool:C,setFilter:A,setStyle:P,setTheme:M,setUser:k,setVisible:U,element:h,state:n}};function Ft(){}function _a(r,t){for(const e in t)r[e]=t[e];return r}function ou(r){return r()}function au(){return Object.create(null)}function Ne(r){r.forEach(ou)}function Kt(r){return typeof r=="function"}function Ut(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function D_(r){return Object.keys(r).length===0}function O_(r,...t){if(r==null){for(const i of t)i(void 0);return Ft}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function vs(r,t,e){r.$$.on_destroy.push(O_(t,e))}function lu(r,t,e,i){if(r){const n=hu(r,t,e,i);return r[0](n)}}function hu(r,t,e,i){return r[1]&&i?_a(e.ctx.slice(),r[1](i(t))):e.ctx}function cu(r,t,e,i){if(r[2]&&i){const n=r[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const s=[],o=Math.max(t.dirty.length,n.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|n[a];return s}return t.dirty|n}return t.dirty}function uu(r,t,e,i,n,s){if(n){const o=hu(t,e,i,s);r.p(o,n)}}function du(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function fu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}const va=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function At(r,t){r.appendChild(t)}function st(r,t,e){r.insertBefore(t,e||null)}function nt(r){r.parentNode&&r.parentNode.removeChild(r)}function Dr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function et(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function ba(r){return document.createTextNode(r)}function Se(){return ba(" ")}function Pe(){return ba("")}function Rt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function w(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function L_(r){return Array.from(r.childNodes)}function B_(r,t){t=""+t,r.data!==t&&(r.data=t)}function Or(r,t,e){r.classList.toggle(t,!!e)}function N_(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let En;function Tn(r){En=r}function xa(){if(!En)throw new Error("Function called outside component initialization");return En}function ei(r){xa().$$.on_mount.push(r)}function F_(r){xa().$$.on_destroy.push(r)}function Di(){const r=xa();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=N_(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function ye(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Oi=[],bs=[];let Li=[];const pu=[],mu=Promise.resolve();let wa=!1;function gu(){wa||(wa=!0,mu.then(_u))}function yu(){return gu(),mu}function Ea(r){Li.push(r)}const Ta=new Set;let Bi=0;function _u(){if(Bi!==0)return;const r=En;do{try{for(;Bi<Oi.length;){const t=Oi[Bi];Bi++,Tn(t),k_(t.$$)}}catch(t){throw Oi.length=0,Bi=0,t}for(Tn(null),Oi.length=0,Bi=0;bs.length;)bs.pop()();for(let t=0;t<Li.length;t+=1){const e=Li[t];Ta.has(e)||(Ta.add(e),e())}Li.length=0}while(Oi.length);for(;pu.length;)pu.pop()();wa=!1,Ta.clear(),Tn(r)}function k_(r){if(r.fragment!==null){r.update(),Ne(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Ea)}}function U_(r){const t=[],e=[];Li.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Li=t}const xs=new Set;let ri;function ne(){ri={r:0,c:[],p:ri}}function se(){ri.r||Ne(ri.c),ri=ri.p}function q(r,t){r&&r.i&&(xs.delete(r),r.i(t))}function ot(r,t,e,i){if(r&&r.o){if(xs.has(r))return;xs.add(r),ri.c.push(()=>{xs.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function xe(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Bt(r){r&&r.c()}function Ot(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Ea(()=>{const s=r.$$.on_mount.map(ou).filter(Kt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Ne(s),r.$$.on_mount=[]}),n.forEach(Ea)}function Lt(r,t){const e=r.$$;e.fragment!==null&&(U_(e.after_update),Ne(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function G_(r,t){r.$$.dirty[0]===-1&&(Oi.push(r),gu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function zt(r,t,e,i,n,s,o=null,a=[-1]){const l=En;Tn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Ft,not_equal:n,bound:au(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:au(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let c=!1;if(h.ctx=e?e(r,t.props||{},(u,d,...p)=>{const f=p.length?p[0]:d;return h.ctx&&n(h.ctx[u],h.ctx[u]=f)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](f),c&&G_(r,u)),d}):[],h.update(),c=!0,Ne(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=L_(t.target);h.fragment&&h.fragment.l(u),u.forEach(nt)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Ot(r,t.target,t.anchor),_u()}Tn(l)}class jt{constructor(){Oh(this,"$$");Oh(this,"$$set")}$destroy(){Lt(this,1),this.$destroy=Ft}$on(t,e){if(!Kt(e))return Ft;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!D_(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $_="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($_);var Je=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(Je||{}),An=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Aa(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function H_(r){if(r.__esModule)return r;var t=r.default;if(typeof t=="function"){var e=function i(){return this instanceof i?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(r).forEach(function(i){var n=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return r[i]}})}),e}var vu={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,c=a.y-l.y;return h*h+c*c}function e(a,l,h){var c=l.x,u=l.y,d=h.x-c,p=h.y-u;if(d!==0||p!==0){var f=((a.x-c)*d+(a.y-u)*p)/(d*d+p*p);f>1?(c=h.x,u=h.y):f>0&&(c+=d*f,u+=p*f)}return d=a.x-c,p=a.y-u,d*d+p*p}function i(a,l){for(var h=a[0],c=[h],u,d=1,p=a.length;d<p;d++)u=a[d],t(u,h)>l&&(c.push(u),h=u);return h!==u&&c.push(u),c}function n(a,l,h,c,u){for(var d=c,p,f=l+1;f<h;f++){var m=e(a[f],a[l],a[h]);m>d&&(p=f,d=m)}d>c&&(p-l>1&&n(a,l,p,c,u),u.push(a[p]),h-p>1&&n(a,p,h,c,u))}function s(a,l){var h=a.length-1,c=[a[0]];return n(a,0,h,l,c),c.push(a[h]),c}function o(a,l,h){if(a.length<=2)return a;var c=l!==void 0?l*l:1;return a=h?a:i(a,c),a=s(a,c),a}r.exports=o,r.exports.default=o})()})(vu);var X_=vu.exports;const V_=Aa(X_),Ni=(r,t)=>t,Qe=r=>{let t=1/0,e=1/0,i=-1/0,n=-1/0;return r.forEach(([s,o])=>{t=Math.min(t,s),e=Math.min(e,o),i=Math.max(i,s),n=Math.max(n,o)}),{minX:t,minY:e,maxX:i,maxY:n}},ws=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},Es=(r,t,e)=>{let i=!1;for(let n=0,s=r.length-1;n<r.length;s=n++){const o=r[n][0],a=r[n][1],l=r[s][0],h=r[s][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},z_=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},bu=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return V_(e,t,!0).map(i=>[i.x,i.y])},j_=(r,t)=>{const e=Math.abs(t[0]-r[0]),i=Math.abs(t[1]-r[1]);return Math.sqrt(Math.pow(e,2)+Math.pow(i,2))},W_={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:n,rx:s,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),c=t-i,u=e-n,d=l*c+h*u,p=h*c-l*u;return d*d/(s*s)+p*p/(o*o)<=1}};Ni(Je.ELLIPSE,W_);const Y_={area:r=>0,intersects:(r,t,e,i=2)=>{const[[n,s],[o,a]]=r.geometry.points,l=Math.abs((a-s)*t-(o-n)*e+o*s-a*n),h=j_([n,s],[o,a]);return l/h<=i}};Ni(Je.LINE,Y_);const q_={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=ws(n.points),a=s.reduce((l,h)=>l+ws(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const n of i){const[s,...o]=n.rings;if(Es(s.points,t,e)){let a=!1;for(const l of o)if(Es(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Ts=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Qe(t)},Fi=r=>r.rings.map(e=>z_(e.points)).join(" "),K_=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),Z_=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=bu(a.points,t);return{...a,points:l}}),o=Qe(s[0].points);return{...n,rings:s,bounds:o}}),i=Ts(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Ni(Je.MULTIPOLYGON,q_);const J_={area:r=>{const t=r.geometry.points;return ws(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Es(i,t,e)}},Q_=(r,t=1)=>{const e=bu(r.geometry.points,t),i=Qe(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Ni(Je.POLYGON,J_);const tv={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=xu(t.points,t.closed);return ws(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=xu(n.points,n.closed);return Es(s,t,e)}else return ev(n,[t,e],i)}},xu=(r,t=!1)=>{const e=[];for(let i=0;i<r.length;i++){const n=r[i],s=r[(i+1)%r.length];if(e.push(n.point),(i<r.length-1||t)&&(n.outHandle||s.inHandle)){const a=wu(n.point,n.outHandle||n.point,s.inHandle||s.point,s.point,10);e.push(...a.slice(1))}}return e},wu=(r,t,e,i,n=10)=>{const s=[];for(let o=0;o<=n;o++){const a=o/n,l=Math.pow(1-a,3)*r[0]+3*Math.pow(1-a,2)*a*t[0]+3*(1-a)*Math.pow(a,2)*e[0]+Math.pow(a,3)*i[0],h=Math.pow(1-a,3)*r[1]+3*Math.pow(1-a,2)*a*t[1]+3*(1-a)*Math.pow(a,2)*e[1]+Math.pow(a,3)*i[1];s.push([l,h])}return s},ev=(r,t,e)=>{for(let i=0;i<r.points.length-1;i++){const n=r.points[i],s=r.points[i+1];if(n.outHandle||s.inHandle){const a=wu(n.point,n.outHandle||n.point,s.inHandle||s.point,s.point,20);for(let l=0;l<a.length-1;l++)if(Eu(t,a[l],a[l+1])<=e)return!0}else if(Eu(t,n.point,s.point)<=e)return!0}return!1},Eu=(r,t,e)=>{const[i,n]=r,[s,o]=t,[a,l]=e,h=a-s,c=l-o,u=Math.sqrt(h*h+c*c);if(u===0)return Math.sqrt((i-s)*(i-s)+(n-o)*(n-o));const d=((i-s)*h+(n-o)*c)/(u*u);return d<=0?Math.sqrt((i-s)*(i-s)+(n-o)*(n-o)):d>=1?Math.sqrt((i-a)*(i-a)+(n-l)*(n-l)):Math.abs((l-o)*i-(a-s)*n+a*o-l*s)/u};Ni(Je.POLYLINE,tv);const rv={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};Ni(Je.RECTANGLE,rv);const _e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function iv(r,t=0){return(_e[r[t+0]]+_e[r[t+1]]+_e[r[t+2]]+_e[r[t+3]]+"-"+_e[r[t+4]]+_e[r[t+5]]+"-"+_e[r[t+6]]+_e[r[t+7]]+"-"+_e[r[t+8]]+_e[r[t+9]]+"-"+_e[r[t+10]]+_e[r[t+11]]+_e[r[t+12]]+_e[r[t+13]]+_e[r[t+14]]+_e[r[t+15]]).toLowerCase()}let Sa;const nv=new Uint8Array(16);function sv(){if(!Sa){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Sa=crypto.getRandomValues.bind(crypto)}return Sa(nv)}const Tu={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ov(r,t,e){var n;if(Tu.randomUUID&&!r)return Tu.randomUUID();r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??sv();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,iv(i)}const av=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:n,stroke:s,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${n||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},Ca=(r,t=0)=>{const{minX:e,minY:i,maxX:n,maxY:s}=r;return{x:e-t,y:i-t,w:n-e+2*t,h:s-i+2*t}},Lr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,lv=r=>({}),Au=r=>({grab:r[0]});function hv(r){let t,e,i,n;const s=r[8].default,o=lu(s,r,r[7],Au);return{c(){t=et("g"),o&&o.c(),w(t,"class","a9s-annotation selected")},m(a,l){st(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Rt(t,"pointerup",r[2]),Rt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&uu(o,s,a,a[7],e?cu(s,a[7],l,lv):du(a[7]),Au)},i(a){e||(q(o,a),e=!0)},o(a){ot(o,a),e=!1},d(a){a&&nt(t),o&&o.d(a),i=!1,Ne(n)}}}function cv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Di();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const p=_=>v=>{if(c=_,h){const{left:g,top:b}=h.getBoundingClientRect(),C=v.clientX-g,R=v.clientY-b;u=l.elementToImage(C,R)}else{const{offsetX:g,offsetY:b}=v;u=l.elementToImage(g,b)}d=o,v.target.setPointerCapture(v.pointerId),s("grab",v)},f=_=>{if(c){const[v,y]=l.elementToImage(_.offsetX,_.offsetY),g=[v-u[0],y-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=_=>{_.target.releasePointerCapture(_.pointerId),c=void 0,d=o,s("release",_)};return r.$$set=_=>{"shape"in _&&e(3,o=_.shape),"editor"in _&&e(4,a=_.editor),"transform"in _&&e(5,l=_.transform),"svgEl"in _&&e(6,h=_.svgEl),"$$scope"in _&&e(7,n=_.$$scope)},[p,f,m,o,a,l,h,n,i]}class Ia extends jt{constructor(t){super(),zt(this,t,cv,hv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function uv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Su(r);return{c(){t=et("g"),e=et("circle"),h&&h.c(),n=et("circle"),w(e,"class","a9s-handle-buffer"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]+6/r[2]),w(e,"role","button"),w(e,"tabindex","0"),w(n,"class",s=`a9s-handle-dot${r[3]?" selected":""}`),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",r[5]),w(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){st(c,t,u),At(t,e),h&&h.m(t,null),At(t,n),a||(l=[Rt(e,"dblclick",r[11]),Rt(e,"pointerenter",r[12]),Rt(e,"pointerleave",r[13]),Rt(e,"pointerdown",r[14]),Rt(e,"pointerdown",r[6]),Rt(e,"pointerup",r[15]),Rt(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&w(e,"cx",c[0]),u&2&&w(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&w(e,"r",i),c[3]?h?h.p(c,u):(h=Su(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=`a9s-handle-dot${c[3]?" selected":""}`)&&w(n,"class",s),u&1&&w(n,"cx",c[0]),u&2&&w(n,"cy",c[1]),u&32&&w(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&w(t,"class",o)},d(c){c&&nt(t),h&&h.d(),a=!1,Ne(l)}}}function dv(r){let t,e,i,n,s,o,a,l,h;return{c(){t=et("g"),e=et("circle"),n=et("circle"),o=et("circle"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]*10),w(e,"class","a9s-touch-halo"),Or(e,"touched",r[4]),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",s=r[5]+10/r[2]),w(n,"class","a9s-handle-buffer"),w(o,"class","a9s-handle-dot"),w(o,"cx",r[0]),w(o,"cy",r[1]),w(o,"r",a=r[5]+2/r[2]),w(t,"class","a9s-touch-handle")},m(c,u){st(c,t,u),At(t,e),At(t,n),At(t,o),l||(h=[Rt(n,"pointerdown",r[9]),Rt(n,"pointerup",r[10]),Rt(n,"pointerdown",r[6]),Rt(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&w(e,"cx",c[0]),u&2&&w(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&w(e,"r",i),u&16&&Or(e,"touched",c[4]),u&1&&w(n,"cx",c[0]),u&2&&w(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&w(n,"r",s),u&1&&w(o,"cx",c[0]),u&2&&w(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&w(o,"r",a)},d(c){c&&nt(t),l=!1,Ne(h)}}}function Su(r){let t,e;return{c(){t=et("circle"),w(t,"class","a9s-handle-selected"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",e=r[5]+8/r[2])},m(i,n){st(i,t,n)},p(i,n){n&1&&w(t,"cx",i[0]),n&2&&w(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&w(t,"r",e)},d(i){i&&nt(t)}}}function fv(r){let t;function e(s,o){return Lr?dv:uv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),st(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&nt(t),n.d(s)}}}function pv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=y=>{y.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(y){ye.call(this,r,y)}function d(y){ye.call(this,r,y)}function p(y){ye.call(this,r,y)}function f(y){ye.call(this,r,y)}function m(y){ye.call(this,r,y)}function _(y){ye.call(this,r,y)}function v(y){ye.call(this,r,y)}return r.$$set=y=>{e(8,t=_a(_a({},t),fu(y))),"x"in y&&e(0,n=y.x),"y"in y&&e(1,s=y.y),"scale"in y&&e(2,o=y.scale),"selected"in y&&e(3,a=y.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=fu(t),[n,s,o,a,l,i,h,c,t,u,d,p,f,m,_,v]}class ki extends jt{constructor(t){super(),zt(this,t,pv,fv,Ut,{x:0,y:1,scale:2,selected:3})}}function mv(r){let t,e,i,n,s,o,a;return{c(){t=et("g"),e=et("circle"),n=et("circle"),s=et("circle"),w(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=1.75*r[2]),w(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",r[2]),w(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),w(s,"cx",r[0]),w(s,"cy",r[1]),w(s,"r",r[2]),w(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){st(l,t,h),At(t,e),At(t,n),At(t,s),o||(a=[Rt(e,"pointerdown",r[5]),Rt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&w(e,"cx",l[0]),h&2&&w(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&w(e,"r",i),h&1&&w(n,"cx",l[0]),h&2&&w(n,"cy",l[1]),h&4&&w(n,"r",l[2]),h&1&&w(s,"cx",l[0]),h&2&&w(s,"cy",l[1]),h&4&&w(s,"r",l[2])},d(l){l&&nt(t),o=!1,Ne(a)}}}function gv(r){let t;return{c(){t=et("circle"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",r[2])},m(e,i){st(e,t,i)},p(e,i){i&1&&w(t,"cx",e[0]),i&2&&w(t,"cy",e[1]),i&4&&w(t,"r",e[2])},d(e){e&&nt(t)}}}function yv(r){let t;function e(s,o){return Lr?gv:mv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),st(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&nt(t),n.d(s)}}}function _v(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){ye.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,n=h.x),"y"in h&&e(1,s=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[n,s,i,a,o,l]}class Cu extends jt{constructor(t){super(),zt(this,t,_v,yv,Ut,{x:0,y:1,scale:4})}}function Pa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Iu(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Ra(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ma(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Pu(r){let t,e,i,n;return{c(){t=et("circle"),w(t,"cx",e=r[28][0]),w(t,"cy",i=r[28][1]),w(t,"r",n=Sn/r[3]),w(t,"class","svelte-1h2slbm")},m(s,o){st(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&w(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&w(t,"cy",i),o[0]&8&&n!==(n=Sn/s[3])&&w(t,"r",n)},d(s){s&&nt(t)}}}function Ru(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=et("mask"),e=et("rect"),a=et("circle"),w(e,"x",i=r[9].x),w(e,"y",n=r[9].y),w(e,"width",s=r[9].w),w(e,"height",o=r[9].h),w(e,"class","svelte-1h2slbm"),w(a,"cx",l=r[28][0]),w(a,"cy",h=r[28][1]),w(a,"r",c=Sn/r[3]),w(a,"class","svelte-1h2slbm"),w(t,"id",`${r[19]}-inner`),w(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){st(u,t,d),At(t,e),At(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&w(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&w(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&w(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&w(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&w(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&w(a,"cy",h),d[0]&8&&c!==(c=Sn/u[3])&&w(a,"r",c)},d(u){u&&nt(t)}}}function Mu(r){let t,e;return t=new ki({props:{class:"a9s-corner-handle",x:r[28][0],y:r[28][1],scale:r[3],selected:r[8].includes(r[30])}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[15]),t.$on("pointerdown",function(){Kt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}function Du(r){let t,e;return t=new Cu({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Kt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}function vv(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y,g,b,C,R=r[6]!==void 0&&!r[7]&&Pu(Ma(r)),A=r[6]!==void 0&&!r[7]&&Ru(Ra(r)),P=xe(r[5].points),M=[];for(let I=0;I<P.length;I+=1)M[I]=Mu(Iu(r,P,I));const k=I=>ot(M[I],1,1,()=>{M[I]=null});let U=r[6]!==void 0&&!r[7]&&Du(Pa(r));return{c(){t=et("defs"),e=et("mask"),i=et("rect"),l=et("polygon"),R&&R.c(),A&&A.c(),c=Se(),u=et("polygon"),p=Se(),f=et("polygon"),_=Se();for(let I=0;I<M.length;I+=1)M[I].c();v=Se(),U&&U.c(),y=Pe(),w(i,"x",n=r[9].x),w(i,"y",s=r[9].y),w(i,"width",o=r[9].w),w(i,"height",a=r[9].h),w(i,"class","svelte-1h2slbm"),w(l,"points",h=r[5].points.map(Ou).join(" ")),w(l,"class","svelte-1h2slbm"),w(e,"id",`${r[19]}-outer`),w(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),w(u,"class","a9s-outer"),w(u,"mask",`url(#${r[19]}-outer)`),w(u,"points",d=r[5].points.map(Lu).join(" ")),w(f,"class","a9s-inner a9s-shape-handle"),w(f,"mask",`url(#${r[19]}-inner)`),w(f,"style",r[1]),w(f,"points",m=r[5].points.map(Bu).join(" "))},m(I,T){st(I,t,T),At(t,e),At(e,i),At(e,l),R&&R.m(e,null),A&&A.m(t,null),st(I,c,T),st(I,u,T),st(I,p,T),st(I,f,T),st(I,_,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(I,T);st(I,v,T),U&&U.m(I,T),st(I,y,T),g=!0,b||(C=[Rt(u,"pointerup",r[14]),Rt(u,"pointerdown",function(){Kt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Rt(f,"pointermove",r[13]),Rt(f,"pointerup",r[14]),Rt(f,"pointerdown",function(){Kt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(I,T){if(r=I,(!g||T[0]&512&&n!==(n=r[9].x))&&w(i,"x",n),(!g||T[0]&512&&s!==(s=r[9].y))&&w(i,"y",s),(!g||T[0]&512&&o!==(o=r[9].w))&&w(i,"width",o),(!g||T[0]&512&&a!==(a=r[9].h))&&w(i,"height",a),(!g||T[0]&32&&h!==(h=r[5].points.map(Ou).join(" ")))&&w(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Ma(r),T):(R=Pu(Ma(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?A?A.p(Ra(r),T):(A=Ru(Ra(r)),A.c(),A.m(t,null)):A&&(A.d(1),A=null),(!g||T[0]&32&&d!==(d=r[5].points.map(Lu).join(" ")))&&w(u,"points",d),(!g||T[0]&2)&&w(f,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Bu).join(" ")))&&w(f,"points",m),T[0]&134322472){P=xe(r[5].points);let E;for(E=0;E<P.length;E+=1){const S=Iu(r,P,E);M[E]?(M[E].p(S,T),q(M[E],1)):(M[E]=Mu(S),M[E].c(),q(M[E],1),M[E].m(v.parentNode,v))}for(ne(),E=P.length;E<M.length;E+=1)k(E);se()}r[6]!==void 0&&!r[7]?U?(U.p(Pa(r),T),T[0]&192&&q(U,1)):(U=Du(Pa(r)),U.c(),q(U,1),U.m(y.parentNode,y)):U&&(ne(),ot(U,1,1,()=>{U=null}),se())},i(I){if(!g){for(let T=0;T<P.length;T+=1)q(M[T]);q(U),g=!0}},o(I){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)ot(M[T]);ot(U),g=!1},d(I){I&&(nt(t),nt(c),nt(u),nt(p),nt(f),nt(_),nt(v),nt(y)),R&&R.d(),A&&A.d(),Dr(M,I),U&&U.d(I),b=!1,Ne(C)}}}function bv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[vv,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}const xv=250,wv=1e3,Ev=12,Sn=4.5,Ou=r=>r.join(","),Lu=r=>r.join(","),Bu=r=>r.join(",");function Tv(r,t,e){let i,n,s;const o=Di();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const _=()=>e(7,p=!0),v=()=>e(7,p=!1),y=E=>{if(m.length>0||!n.some($=>$.visible)){e(6,d=void 0);return}const[S,B]=h.elementToImage(E.offsetX,E.offsetY),D=$=>Math.pow($[0]-S,2)+Math.pow($[1]-B,2),N=i.points.reduce(($,F)=>D(F)<D($)?F:$),H=n.filter($=>$.visible).reduce(($,F)=>D(F.point)<D($.point)?F:$),O=Math.pow(wv/c,2);D(N)<O||D(H.point)<O?e(6,d=n.indexOf(H)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},C=E=>{e(7,p=!0),E.preventDefault(),E.stopPropagation(),f=performance.now()},R=E=>S=>{if(!f||Lr||performance.now()-f>xv)return;const B=m.includes(E);S.metaKey||S.ctrlKey||S.shiftKey?B?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):B&&m.length>1?e(8,m=[E]):B?e(8,m=[]):e(8,m=[E]),g()},A=(E,S,B)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,L],$)=>m.includes($)?[O+B[0],L+B[1]]:[O,L]):S==="SHAPE"?D=N.points.map(([O,L])=>[O+B[0],L+B[1]]):D=N.points.map(([O,L],$)=>S===`HANDLE-${$}`?[O+B[0],L+B[1]]:[O,L]);const H=Qe(D);return{...E,geometry:{points:D,bounds:H}}},P=E=>async S=>{S.stopPropagation();const B=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=Qe(B);o("change",{...a,geometry:{points:B,bounds:D}}),await yu();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:S.clientX,clientY:S.clientY,pointerId:S.pointerId,pointerType:S.pointerType,isPrimary:S.isPrimary,buttons:S.buttons});N.firstChild.dispatchEvent(H)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((B,D)=>!m.includes(D)),S=Qe(E);o("change",{...a,geometry:{points:E,bounds:S}}),e(8,m=[])};ei(()=>{if(Lr)return;const E=S=>{(S.key==="Delete"||S.key==="Backspace")&&(S.preventDefault(),M())};return u.addEventListener("pointermove",y),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",y),u.removeEventListener("keydown",E)}});const k=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){ye.call(this,r,E)}function I(E){ye.call(this,r,E)}function T(E){ye.call(this,r,E)}return r.$$set=E=>{"shape"in E&&e(0,a=E.shape),"computedStyle"in E&&e(1,l=E.computedStyle),"transform"in E&&e(2,h=E.transform),"viewportScale"in E&&e(3,c=E.viewportScale),"svgEl"in E&&e(4,u=E.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Lr?[]:i.points.map((E,S)=>{const B=S===i.points.length-1?i.points[0]:i.points[S+1],D=(E[0]+B[0])/2,N=(E[1]+B[1])/2,O=Math.sqrt(Math.pow(B[0]-D,2)+Math.pow(B[1]-N,2))>Ev/c;return{point:[D,N],visible:O}})),r.$$.dirty[0]&40&&e(9,s=Ca(i.bounds,Sn/c))},[a,l,h,c,u,i,d,p,m,s,n,_,v,y,b,C,R,A,P,k,U,I,T]}class Av extends jt{constructor(t){super(),zt(this,t,Tv,bv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Sv(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y,g,b,C,R,A,P,M,k,U,I,T,E,S,B,D,N,H,O,L,$,F,X,V,dt,yt,z,wt,it,ft,_t,Pt,Dt,he,Vt,Q,Ge,Jn;return it=new ki({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),it.$on("pointerdown",function(){Kt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),_t=new ki({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),_t.$on("pointerdown",function(){Kt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new ki({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Dt.$on("pointerdown",function(){Kt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new ki({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Kt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=et("defs"),e=et("mask"),i=et("rect"),l=et("rect"),p=Se(),f=et("rect"),g=Se(),b=et("rect"),M=Se(),k=et("rect"),E=Se(),S=et("rect"),H=Se(),O=et("rect"),X=Se(),V=et("rect"),wt=Se(),Bt(it.$$.fragment),ft=Se(),Bt(_t.$$.fragment),Pt=Se(),Bt(Dt.$$.fragment),he=Se(),Bt(Vt.$$.fragment),w(i,"class","rect-mask-bg svelte-1njczvj"),w(i,"x",n=r[6].x),w(i,"y",s=r[6].y),w(i,"width",o=r[6].w),w(i,"height",a=r[6].h),w(l,"class","rect-mask-fg svelte-1njczvj"),w(l,"x",h=r[5].x),w(l,"y",c=r[5].y),w(l,"width",u=r[5].w),w(l,"height",d=r[5].h),w(e,"id",r[8]),w(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),w(f,"class","a9s-outer"),w(f,"mask",`url(#${r[8]})`),w(f,"x",m=r[5].x),w(f,"y",_=r[5].y),w(f,"width",v=r[5].w),w(f,"height",y=r[5].h),w(b,"class","a9s-inner a9s-shape-handle"),w(b,"style",r[1]),w(b,"x",C=r[5].x),w(b,"y",R=r[5].y),w(b,"width",A=r[5].w),w(b,"height",P=r[5].h),w(k,"class","a9s-edge-handle a9s-edge-handle-top"),w(k,"x",U=r[5].x),w(k,"y",I=r[5].y),w(k,"height",1),w(k,"width",T=r[5].w),w(S,"class","a9s-edge-handle a9s-edge-handle-right"),w(S,"x",B=r[5].x+r[5].w),w(S,"y",D=r[5].y),w(S,"height",N=r[5].h),w(S,"width",1),w(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),w(O,"x",L=r[5].x),w(O,"y",$=r[5].y+r[5].h),w(O,"height",1),w(O,"width",F=r[5].w),w(V,"class","a9s-edge-handle a9s-edge-handle-left"),w(V,"x",dt=r[5].x),w(V,"y",yt=r[5].y),w(V,"height",z=r[5].h),w(V,"width",1)},m(Y,G){st(Y,t,G),At(t,e),At(e,i),At(e,l),st(Y,p,G),st(Y,f,G),st(Y,g,G),st(Y,b,G),st(Y,M,G),st(Y,k,G),st(Y,E,G),st(Y,S,G),st(Y,H,G),st(Y,O,G),st(Y,X,G),st(Y,V,G),st(Y,wt,G),Ot(it,Y,G),st(Y,ft,G),Ot(_t,Y,G),st(Y,Pt,G),Ot(Dt,Y,G),st(Y,he,G),Ot(Vt,Y,G),Q=!0,Ge||(Jn=[Rt(f,"pointerdown",function(){Kt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Rt(b,"pointerdown",function(){Kt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Rt(k,"pointerdown",function(){Kt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Rt(S,"pointerdown",function(){Kt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Rt(O,"pointerdown",function(){Kt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Rt(V,"pointerdown",function(){Kt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],Ge=!0)},p(Y,G){r=Y,(!Q||G&64&&n!==(n=r[6].x))&&w(i,"x",n),(!Q||G&64&&s!==(s=r[6].y))&&w(i,"y",s),(!Q||G&64&&o!==(o=r[6].w))&&w(i,"width",o),(!Q||G&64&&a!==(a=r[6].h))&&w(i,"height",a),(!Q||G&32&&h!==(h=r[5].x))&&w(l,"x",h),(!Q||G&32&&c!==(c=r[5].y))&&w(l,"y",c),(!Q||G&32&&u!==(u=r[5].w))&&w(l,"width",u),(!Q||G&32&&d!==(d=r[5].h))&&w(l,"height",d),(!Q||G&32&&m!==(m=r[5].x))&&w(f,"x",m),(!Q||G&32&&_!==(_=r[5].y))&&w(f,"y",_),(!Q||G&32&&v!==(v=r[5].w))&&w(f,"width",v),(!Q||G&32&&y!==(y=r[5].h))&&w(f,"height",y),(!Q||G&2)&&w(b,"style",r[1]),(!Q||G&32&&C!==(C=r[5].x))&&w(b,"x",C),(!Q||G&32&&R!==(R=r[5].y))&&w(b,"y",R),(!Q||G&32&&A!==(A=r[5].w))&&w(b,"width",A),(!Q||G&32&&P!==(P=r[5].h))&&w(b,"height",P),(!Q||G&32&&U!==(U=r[5].x))&&w(k,"x",U),(!Q||G&32&&I!==(I=r[5].y))&&w(k,"y",I),(!Q||G&32&&T!==(T=r[5].w))&&w(k,"width",T),(!Q||G&32&&B!==(B=r[5].x+r[5].w))&&w(S,"x",B),(!Q||G&32&&D!==(D=r[5].y))&&w(S,"y",D),(!Q||G&32&&N!==(N=r[5].h))&&w(S,"height",N),(!Q||G&32&&L!==(L=r[5].x))&&w(O,"x",L),(!Q||G&32&&$!==($=r[5].y+r[5].h))&&w(O,"y",$),(!Q||G&32&&F!==(F=r[5].w))&&w(O,"width",F),(!Q||G&32&&dt!==(dt=r[5].x))&&w(V,"x",dt),(!Q||G&32&&yt!==(yt=r[5].y))&&w(V,"y",yt),(!Q||G&32&&z!==(z=r[5].h))&&w(V,"height",z);const Ar={};G&32&&(Ar.x=r[5].x),G&32&&(Ar.y=r[5].y),G&8&&(Ar.scale=r[3]),it.$set(Ar);const Sr={};G&32&&(Sr.x=r[5].x+r[5].w),G&32&&(Sr.y=r[5].y),G&8&&(Sr.scale=r[3]),_t.$set(Sr);const Cr={};G&32&&(Cr.x=r[5].x+r[5].w),G&32&&(Cr.y=r[5].y+r[5].h),G&8&&(Cr.scale=r[3]),Dt.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x),G&32&&(Ir.y=r[5].y+r[5].h),G&8&&(Ir.scale=r[3]),Vt.$set(Ir)},i(Y){Q||(q(it.$$.fragment,Y),q(_t.$$.fragment,Y),q(Dt.$$.fragment,Y),q(Vt.$$.fragment,Y),Q=!0)},o(Y){ot(it.$$.fragment,Y),ot(_t.$$.fragment,Y),ot(Dt.$$.fragment,Y),ot(Vt.$$.fragment,Y),Q=!1},d(Y){Y&&(nt(t),nt(p),nt(f),nt(g),nt(b),nt(M),nt(k),nt(E),nt(S),nt(H),nt(O),nt(X),nt(V),nt(wt),nt(ft),nt(Pt),nt(he)),Lt(it,Y),Lt(_t,Y),Lt(Dt,Y),Lt(Vt,Y),Ge=!1,Ne(Jn)}}}function Cv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[Sv,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:r}}}),t.$on("grab",r[9]),t.$on("change",r[10]),t.$on("release",r[11]),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}function Iv(r,t,e){let i,n,{shape:s}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const c=(m,_,v)=>{const y=m.geometry.bounds;let[g,b]=[y.minX,y.minY],[C,R]=[y.maxX,y.maxY];const[A,P]=v;if(_==="SHAPE")g+=A,C+=A,b+=P,R+=P;else{switch(_){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=P;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=P;break}}switch(_){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=A;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{C+=A;break}}}const M=Math.min(g,C),k=Math.min(b,R),U=Math.abs(C-g),I=Math.abs(R-b);return{...m,geometry:{x:M,y:k,w:U,h:I,bounds:{minX:M,minY:k,maxX:M+U,maxY:k+I}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){ye.call(this,r,m)}function p(m){ye.call(this,r,m)}function f(m){ye.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,s=m.shape),"computedStyle"in m&&e(1,o=m.computedStyle),"transform"in m&&e(2,a=m.transform),"viewportScale"in m&&e(3,l=m.viewportScale),"svgEl"in m&&e(4,h=m.svgEl)},r.$$.update=()=>{r.$$.dirty&1&&e(5,i=s.geometry),r.$$.dirty&40&&e(6,n=Ca(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,p,f]}class Pv extends jt{constructor(t){super(),zt(this,t,Iv,Cv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Nu=Object.prototype.hasOwnProperty;function Da(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Da(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Nu.call(r,e)&&++i&&!Nu.call(t,e)||!(e in t)||!Da(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const Rv=12,Mv=(r,t)=>r.polygons.reduce((e,i,n)=>{const s=i.rings.reduce((o,a,l)=>{const h=a.points.map((c,u)=>{const d=u===a.points.length-1?a.points[0]:a.points[u+1],p=(c[0]+d[0])/2,f=(c[1]+d[1])/2,_=Math.sqrt(Math.pow(d[0]-p,2)+Math.pow(d[1]-f,2))>Rv/t;return{point:[p,f],visible:_,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function Oa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Fu(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function ku(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Uu(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function La(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ba(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Gu(r){let t,e,i,n;return{c(){t=et("circle"),w(t,"cx",e=r[29][0]),w(t,"cy",i=r[29][1]),w(t,"r",n=Cn/r[3]),w(t,"class","svelte-1vxo6dc")},m(s,o){st(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&w(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&w(t,"cy",i),o[0]&8&&n!==(n=Cn/s[3])&&w(t,"r",n)},d(s){s&&nt(t)}}}function $u(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=et("mask"),e=et("rect"),a=et("circle"),w(e,"x",i=r[9].x),w(e,"y",n=r[9].y),w(e,"width",s=r[9].w),w(e,"height",o=r[9].h),w(e,"class","svelte-1vxo6dc"),w(a,"cx",l=r[29][0]),w(a,"cy",h=r[29][1]),w(a,"r",c=Cn/r[3]),w(a,"class","svelte-1vxo6dc"),w(t,"id",`${r[18]}-${r[32]}-inner`),w(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){st(u,t,d),At(t,e),At(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&w(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&w(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&w(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&w(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&w(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&w(a,"cy",h),d[0]&8&&c!==(c=Cn/u[3])&&w(a,"r",c)},d(u){u&&nt(t)}}}function Hu(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new ki({props:{class:"a9s-corner-handle",x:r[29][0],y:r[29][1],scale:r[3],selected:r[8].some(i)}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[14]),t.$on("pointerdown",function(){Kt(r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`))&&r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`).apply(this,arguments)}),t.$on("pointerup",r[15](r[32],r[35],r[37])),{c(){Bt(t.$$.fragment)},m(n,s){Ot(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(q(t.$$.fragment,n),e=!0)},o(n){ot(t.$$.fragment,n),e=!1},d(n){Lt(t,n)}}}function Xu(r){let t,e,i=xe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Hu(Uu(r,i,o));const s=o=>ot(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Pe()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);st(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=xe(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Uu(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=Hu(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(ne(),l=i.length;l<n.length;l+=1)s(l);se()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)q(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)ot(n[a]);e=!1},d(o){o&&nt(t),Dr(n,o)}}}function Vu(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y=r[6]!==void 0&&!r[7]&&Gu(Ba(r)),g=r[6]!==void 0&&!r[7]&&$u(La(r)),b=xe(r[30].rings),C=[];for(let A=0;A<b.length;A+=1)C[A]=Xu(ku(r,b,A));const R=A=>ot(C[A],1,1,()=>{C[A]=null});return{c(){t=et("g"),e=et("defs"),i=et("mask"),n=et("rect"),h=et("path"),y&&y.c(),g&&g.c(),u=et("path"),p=et("path");for(let A=0;A<C.length;A+=1)C[A].c();w(n,"x",s=r[9].x),w(n,"y",o=r[9].y),w(n,"width",a=r[9].w),w(n,"height",l=r[9].h),w(n,"class","svelte-1vxo6dc"),w(h,"d",c=Fi(r[30])),w(h,"class","svelte-1vxo6dc"),w(i,"id",`${r[18]}-${r[32]}-outer`),w(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),w(u,"class","a9s-outer"),w(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),w(u,"fill-rule","evenodd"),w(u,"d",d=Fi(r[30])),w(p,"class","a9s-inner"),w(p,"mask",`url(#${r[18]}-${r[32]}-inner)`),w(p,"style",r[1]),w(p,"fill-rule","evenodd"),w(p,"d",f=Fi(r[30]))},m(A,P){st(A,t,P),At(t,e),At(e,i),At(i,n),At(i,h),y&&y.m(i,null),g&&g.m(e,null),At(t,u),At(t,p);for(let M=0;M<C.length;M+=1)C[M]&&C[M].m(t,null);m=!0,_||(v=[Rt(u,"pointerup",r[13]),Rt(u,"pointerdown",function(){Kt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Rt(p,"pointerup",r[13]),Rt(p,"pointerdown",function(){Kt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],_=!0)},p(A,P){if(r=A,(!m||P[0]&512&&s!==(s=r[9].x))&&w(n,"x",s),(!m||P[0]&512&&o!==(o=r[9].y))&&w(n,"y",o),(!m||P[0]&512&&a!==(a=r[9].w))&&w(n,"width",a),(!m||P[0]&512&&l!==(l=r[9].h))&&w(n,"height",l),(!m||P[0]&32&&c!==(c=Fi(r[30])))&&w(h,"d",c),r[6]!==void 0&&!r[7]?y?y.p(Ba(r),P):(y=Gu(Ba(r)),y.c(),y.m(i,null)):y&&(y.d(1),y=null),r[6]!==void 0&&!r[7]?g?g.p(La(r),P):(g=$u(La(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||P[0]&32&&d!==(d=Fi(r[30])))&&w(u,"d",d),(!m||P[0]&2)&&w(p,"style",r[1]),(!m||P[0]&32&&f!==(f=Fi(r[30])))&&w(p,"d",f),P[0]&268491048){b=xe(r[30].rings);let M;for(M=0;M<b.length;M+=1){const k=ku(r,b,M);C[M]?(C[M].p(k,P),q(C[M],1)):(C[M]=Xu(k),C[M].c(),q(C[M],1),C[M].m(t,null))}for(ne(),M=b.length;M<C.length;M+=1)R(M);se()}},i(A){if(!m){for(let P=0;P<b.length;P+=1)q(C[P]);m=!0}},o(A){C=C.filter(Boolean);for(let P=0;P<C.length;P+=1)ot(C[P]);m=!1},d(A){A&&nt(t),y&&y.d(),g&&g.d(),Dr(C,A),_=!1,Ne(v)}}}function zu(r){let t,e;return t=new Cu({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Kt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}function Dv(r){let t,e,i,n=xe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Vu(Fu(r,n,l));const o=l=>ot(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&zu(Oa(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Se(),a&&a.c(),e=Pe()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);st(l,t,h),a&&a.m(l,h),st(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=xe(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=Fu(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=Vu(u),s[c].c(),q(s[c],1),s[c].m(t.parentNode,t))}for(ne(),c=n.length;c<s.length;c+=1)o(c);se()}l[6]!==void 0&&!l[7]?a?(a.p(Oa(l),h),h[0]&192&&q(a,1)):(a=zu(Oa(l)),a.c(),q(a,1),a.m(e.parentNode,e)):a&&(ne(),ot(a,1,1,()=>{a=null}),se())},i(l){if(!i){for(let h=0;h<n.length;h+=1)q(s[h]);q(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)ot(s[h]);ot(a),i=!1},d(l){l&&(nt(t),nt(e)),Dr(s,l),a&&a.d(l)}}}function Ov(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[Dv,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}const Lv=250,Bv=1e3,Cn=4.5;function Nv(r,t,e){let i,n,s;const o=Di();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const _=()=>e(7,p=!0),v=()=>e(7,p=!1),y=S=>{if(m.length>0||!n.some(F=>F.visible)){e(6,d=void 0);return}const[B,D]=h.elementToImage(S.offsetX,S.offsetY),N=F=>Math.pow(F[0]-B,2)+Math.pow(F[1]-D,2),H=K_(i).reduce((F,X)=>N(X)<N(F)?X:F),O=n.filter(F=>F.visible).reduce((F,X)=>N(X.point)<N(F.point)?X:F),L=Math.pow(Bv/c,2);N(H)<L||N(O.point)<L?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},C=S=>{e(7,p=!0),S.preventDefault(),S.stopPropagation(),f=performance.now()},R=(S,B,D)=>N=>{if(!f||Lr||performance.now()-f>Lv)return;const H=L=>L.polygon===S&&L.ring===B&&L.point===D,O=m.some(H);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(L=>!H(L))):e(8,m=[...m,{polygon:S,ring:B,point:D}]):O&&m.length>1?e(8,m=[{polygon:S,ring:B,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:S,ring:B,point:D}]),g()},A=(S,B,D)=>{g();const N=S.geometry.polygons;let H;if(B==="SHAPE")H=N.map(O=>{const L=O.rings.map((F,X)=>({points:F.points.map((dt,yt)=>[dt[0]+D[0],dt[1]+D[1]])})),$=Qe(L[0].points);return{rings:L,bounds:$}});else{const[O,L,$,F]=B.split("-").map(X=>parseInt(X));H=N.map((X,V)=>{if(V===L){const dt=X.rings.map((z,wt)=>wt===$?{points:z.points.map((ft,_t)=>_t===F?[ft[0]+D[0],ft[1]+D[1]]:ft)}:z),yt=Qe(dt[0].points);return{rings:dt,bounds:yt}}else return X})}return{...S,geometry:{polygons:H,bounds:Ts(H)}}},P=S=>async B=>{B.stopPropagation();const D=n[S],N=i.polygons.map((O,L)=>{if(L===D.elementIdx){const $=O.rings.map((X,V)=>V===D.ringIdx?{points:[...X.points.slice(0,D.pointIdx+1),D.point,...X.points.slice(D.pointIdx+1)]}:X),F=Qe($[0].points);return{rings:$,bounds:F}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Ts(N)}}),await yu();const H=[...document.querySelectorAll(".a9s-handle")][S+1];if(H!=null&&H.firstChild){const O=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:B.clientX,clientY:B.clientY,pointerId:B.pointerId,pointerType:B.pointerType,isPrimary:B.isPrimary,buttons:B.buttons});H.firstChild.dispatchEvent(O)}},M=()=>{const S=i.polygons.map((D,N)=>{if(m.some(O=>O.polygon===N)){const O=D.rings.map(($,F)=>{const X=m.filter(V=>V.polygon===N&&V.ring===F);return X.length&&$.points.length-X.length>=3?{points:$.points.filter((dt,yt)=>!X.some(z=>z.point===yt))}:$}),L=Qe(O[0].points);return{rings:O,bounds:L}}else return D});!Da(i.polygons,S)&&(o("change",{...a,geometry:{polygons:S,bounds:Ts(S)}}),e(8,m=[]))};ei(()=>{if(Lr)return;const S=B=>{(B.key==="Delete"||B.key==="Backspace")&&(B.preventDefault(),M())};return u.addEventListener("pointermove",y),u.addEventListener("keydown",S),()=>{u.removeEventListener("pointermove",y),u.removeEventListener("keydown",S)}});const k=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(S,B,D,{polygon:N,ring:H,point:O})=>N===S&&H===B&&O===D;function I(S){ye.call(this,r,S)}function T(S){ye.call(this,r,S)}function E(S){ye.call(this,r,S)}return r.$$set=S=>{"shape"in S&&e(0,a=S.shape),"computedStyle"in S&&e(1,l=S.computedStyle),"transform"in S&&e(2,h=S.transform),"viewportScale"in S&&e(3,c=S.viewportScale),"svgEl"in S&&e(4,u=S.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Lr?[]:Mv(i,c)),r.$$.dirty[0]&40&&e(9,s=Ca(i.bounds,Cn/c))},[a,l,h,c,u,i,d,p,m,s,n,_,v,b,C,R,A,P,k,U,I,T,E]}class Fv extends jt{constructor(t){super(),zt(this,t,Nv,Ov,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}Je.RECTANGLE,Je.POLYGON,Je.MULTIPOLYGON;function kv(r,t,e){let i;const n=Di();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return ei(()=>(e(6,u=new o({target:l,props:{shape:s.target.selector,computedStyle:i,transform:h,viewportScale:c,svgEl:l.closest("svg")}})),u.$on("change",d=>{u.$$set({shape:d.detail}),n("change",d.detail)}),u.$on("grab",d=>n("grab",d.detail)),u.$on("release",d=>n("release",d.detail)),()=>{u.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,s=d.annotation),"editor"in d&&e(1,o=d.editor),"style"in d&&e(2,a=d.style),"target"in d&&e(3,l=d.target),"transform"in d&&e(4,h=d.transform),"viewportScale"in d&&e(5,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=av(s,a)),r.$$.dirty&65&&s&&(u==null||u.$set({shape:s.target.selector})),r.$$.dirty&80&&u&&u.$set({transform:h}),r.$$.dirty&96&&u&&u.$set({viewportScale:c}),r.$$.dirty&192&&u&&i&&u.$set({computedStyle:i})},[s,o,a,l,h,c,u,i]}class Uv extends jt{constructor(t){super(),zt(this,t,kv,null,Ut,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1;var ii=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(ii||{}),ju=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(ju||{}),Na=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Na||{}),gt=(r=>(r[r.NORMAL=0]="NORMAL",r[r.ADD=1]="ADD",r[r.MULTIPLY=2]="MULTIPLY",r[r.SCREEN=3]="SCREEN",r[r.OVERLAY=4]="OVERLAY",r[r.DARKEN=5]="DARKEN",r[r.LIGHTEN=6]="LIGHTEN",r[r.COLOR_DODGE=7]="COLOR_DODGE",r[r.COLOR_BURN=8]="COLOR_BURN",r[r.HARD_LIGHT=9]="HARD_LIGHT",r[r.SOFT_LIGHT=10]="SOFT_LIGHT",r[r.DIFFERENCE=11]="DIFFERENCE",r[r.EXCLUSION=12]="EXCLUSION",r[r.HUE=13]="HUE",r[r.SATURATION=14]="SATURATION",r[r.COLOR=15]="COLOR",r[r.LUMINOSITY=16]="LUMINOSITY",r[r.NORMAL_NPM=17]="NORMAL_NPM",r[r.ADD_NPM=18]="ADD_NPM",r[r.SCREEN_NPM=19]="SCREEN_NPM",r[r.NONE=20]="NONE",r[r.SRC_OVER=0]="SRC_OVER",r[r.SRC_IN=21]="SRC_IN",r[r.SRC_OUT=22]="SRC_OUT",r[r.SRC_ATOP=23]="SRC_ATOP",r[r.DST_OVER=24]="DST_OVER",r[r.DST_IN=25]="DST_IN",r[r.DST_OUT=26]="DST_OUT",r[r.DST_ATOP=27]="DST_ATOP",r[r.ERASE=26]="ERASE",r[r.SUBTRACT=28]="SUBTRACT",r[r.XOR=29]="XOR",r))(gt||{}),tr=(r=>(r[r.POINTS=0]="POINTS",r[r.LINES=1]="LINES",r[r.LINE_LOOP=2]="LINE_LOOP",r[r.LINE_STRIP=3]="LINE_STRIP",r[r.TRIANGLES=4]="TRIANGLES",r[r.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",r[r.TRIANGLE_FAN=6]="TRIANGLE_FAN",r))(tr||{}),j=(r=>(r[r.RGBA=6408]="RGBA",r[r.RGB=6407]="RGB",r[r.RG=33319]="RG",r[r.RED=6403]="RED",r[r.RGBA_INTEGER=36249]="RGBA_INTEGER",r[r.RGB_INTEGER=36248]="RGB_INTEGER",r[r.RG_INTEGER=33320]="RG_INTEGER",r[r.RED_INTEGER=36244]="RED_INTEGER",r[r.ALPHA=6406]="ALPHA",r[r.LUMINANCE=6409]="LUMINANCE",r[r.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",r[r.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",r[r.DEPTH_STENCIL=34041]="DEPTH_STENCIL",r))(j||{}),Ui=(r=>(r[r.TEXTURE_2D=3553]="TEXTURE_2D",r[r.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",r[r.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",r[r.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",r[r.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",r[r.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",r[r.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",r))(Ui||{}),ut=(r=>(r[r.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",r[r.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",r[r.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",r[r.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",r[r.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",r[r.UNSIGNED_INT=5125]="UNSIGNED_INT",r[r.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",r[r.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",r[r.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",r[r.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",r[r.BYTE=5120]="BYTE",r[r.SHORT=5122]="SHORT",r[r.INT=5124]="INT",r[r.FLOAT=5126]="FLOAT",r[r.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",r[r.HALF_FLOAT=36193]="HALF_FLOAT",r))(ut||{}),Z=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(Z||{}),mr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(mr||{}),Br=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Br||{}),er=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(er||{}),Re=(r=>(r[r.NPM=0]="NPM",r[r.UNPACK=1]="UNPACK",r[r.PMA=2]="PMA",r[r.NO_PREMULTIPLIED_ALPHA=0]="NO_PREMULTIPLIED_ALPHA",r[r.PREMULTIPLY_ON_UPLOAD=1]="PREMULTIPLY_ON_UPLOAD",r[r.PREMULTIPLIED_ALPHA=2]="PREMULTIPLIED_ALPHA",r))(Re||{}),rr=(r=>(r[r.NO=0]="NO",r[r.YES=1]="YES",r[r.AUTO=2]="AUTO",r[r.BLEND=0]="BLEND",r[r.CLEAR=1]="CLEAR",r[r.BLIT=2]="BLIT",r))(rr||{}),Fa=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(Fa||{}),Fe=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(Fe||{}),re=(r=>(r[r.NONE=0]="NONE",r[r.SCISSOR=1]="SCISSOR",r[r.STENCIL=2]="STENCIL",r[r.SPRITE=3]="SPRITE",r[r.COLOR=4]="COLOR",r))(re||{}),te=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(te||{}),ir=(r=>(r[r.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",r[r.ARRAY_BUFFER=34962]="ARRAY_BUFFER",r[r.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",r))(ir||{});const J={ADAPTER:{createCanvas:(r,t)=>{const e=document.createElement("canvas");return e.width=r,e.height=t,e},getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(r,t)=>fetch(r,t),parseXML:r=>new DOMParser().parseFromString(r,"text/xml")},RESOLUTION:1,CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1};var ka=/iPhone/i,Wu=/iPod/i,Yu=/iPad/i,qu=/\biOS-universal(?:.+)Mac\b/i,Ua=/\bAndroid(?:.+)Mobile\b/i,Ku=/Android/i,Gi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,As=/Silk/i,gr=/Windows Phone/i,Zu=/\bWindows(?:.+)ARM\b/i,Ju=/BlackBerry/i,Qu=/BB10/i,td=/Opera Mini/i,ed=/\b(CriOS|Chrome)(?:.+)Mobile/i,rd=/Mobile(?:.+)Firefox\b/i,id=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function Gv(r){return function(t){return t.test(r)}}function nd(r){var t={userAgent:"",platform:"",maxTouchPoints:0};!r&&typeof navigator<"u"?t={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof r=="string"?t.userAgent=r:r&&r.userAgent&&(t={userAgent:r.userAgent,platform:r.platform,maxTouchPoints:r.maxTouchPoints||0});var e=t.userAgent,i=e.split("[FBAN");typeof i[1]<"u"&&(e=i[0]),i=e.split("Twitter"),typeof i[1]<"u"&&(e=i[0]);var n=Gv(e),s={apple:{phone:n(ka)&&!n(gr),ipod:n(Wu),tablet:!n(ka)&&(n(Yu)||id(t))&&!n(gr),universal:n(qu),device:(n(ka)||n(Wu)||n(Yu)||n(qu)||id(t))&&!n(gr)},amazon:{phone:n(Gi),tablet:!n(Gi)&&n(As),device:n(Gi)||n(As)},android:{phone:!n(gr)&&n(Gi)||!n(gr)&&n(Ua),tablet:!n(gr)&&!n(Gi)&&!n(Ua)&&(n(As)||n(Ku)),device:!n(gr)&&(n(Gi)||n(As)||n(Ua)||n(Ku))||n(/\bokhttp\b/i)},windows:{phone:n(gr),tablet:n(Zu),device:n(gr)||n(Zu)},other:{blackberry:n(Ju),blackberry10:n(Qu),opera:n(td),firefox:n(rd),chrome:n(ed),device:n(Ju)||n(Qu)||n(td)||n(rd)||n(ed)},any:!1,phone:!1,tablet:!1};return s.any=s.apple.device||s.android.device||s.windows.device||s.other.device,s.phone=s.apple.phone||s.android.phone||s.windows.phone,s.tablet=s.apple.tablet||s.android.tablet||s.windows.tablet,s}const $v=nd.default??nd,yr=$v(globalThis.navigator);J.RETINA_PREFIX=/@([0-9\.]+)x/,J.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var sd={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function n(l,h,c){this.fn=l,this.context=h,this.once=c||!1}function s(l,h,c,u,d){if(typeof c!="function")throw new TypeError("The listener must be a function");var p=new n(c,u||l,d),f=e?e+h:h;return l._events[f]?l._events[f].fn?l._events[f]=[l._events[f],p]:l._events[f].push(p):(l._events[f]=p,l._eventsCount++),l}function o(l,h){--l._eventsCount===0?l._events=new i:delete l._events[h]}function a(){this._events=new i,this._eventsCount=0}a.prototype.eventNames=function(){var h=[],c,u;if(this._eventsCount===0)return h;for(u in c=this._events)t.call(c,u)&&h.push(e?u.slice(1):u);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(c)):h},a.prototype.listeners=function(h){var c=e?e+h:h,u=this._events[c];if(!u)return[];if(u.fn)return[u.fn];for(var d=0,p=u.length,f=new Array(p);d<p;d++)f[d]=u[d].fn;return f},a.prototype.listenerCount=function(h){var c=e?e+h:h,u=this._events[c];return u?u.fn?1:u.length:0},a.prototype.emit=function(h,c,u,d,p,f){var m=e?e+h:h;if(!this._events[m])return!1;var _=this._events[m],v=arguments.length,y,g;if(_.fn){switch(_.once&&this.removeListener(h,_.fn,void 0,!0),v){case 1:return _.fn.call(_.context),!0;case 2:return _.fn.call(_.context,c),!0;case 3:return _.fn.call(_.context,c,u),!0;case 4:return _.fn.call(_.context,c,u,d),!0;case 5:return _.fn.call(_.context,c,u,d,p),!0;case 6:return _.fn.call(_.context,c,u,d,p,f),!0}for(g=1,y=new Array(v-1);g<v;g++)y[g-1]=arguments[g];_.fn.apply(_.context,y)}else{var b=_.length,C;for(g=0;g<b;g++)switch(_[g].once&&this.removeListener(h,_[g].fn,void 0,!0),v){case 1:_[g].fn.call(_[g].context);break;case 2:_[g].fn.call(_[g].context,c);break;case 3:_[g].fn.call(_[g].context,c,u);break;case 4:_[g].fn.call(_[g].context,c,u,d);break;default:if(!y)for(C=1,y=new Array(v-1);C<v;C++)y[C-1]=arguments[C];_[g].fn.apply(_[g].context,y)}}return!0},a.prototype.on=function(h,c,u){return s(this,h,c,u,!1)},a.prototype.once=function(h,c,u){return s(this,h,c,u,!0)},a.prototype.removeListener=function(h,c,u,d){var p=e?e+h:h;if(!this._events[p])return this;if(!c)return o(this,p),this;var f=this._events[p];if(f.fn)f.fn===c&&(!d||f.once)&&(!u||f.context===u)&&o(this,p);else{for(var m=0,_=[],v=f.length;m<v;m++)(f[m].fn!==c||d&&!f[m].once||u&&f[m].context!==u)&&_.push(f[m]);_.length?this._events[p]=_.length===1?_[0]:_:o(this,p)}return this},a.prototype.removeAllListeners=function(h){var c;return h?(c=e?e+h:h,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,r.exports=a})(sd);var Hv=sd.exports;const In=Aa(Hv);var Ga={exports:{}};Ga.exports=Ss,Ga.exports.default=Ss;function Ss(r,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:r.length,s=od(r,0,n,e,!0),o=[];if(!s||s.next===s.prev)return o;var a,l,h,c,u,d,p;if(i&&(s=Wv(r,t,s,e)),r.length>80*e){a=h=r[0],l=c=r[1];for(var f=e;f<n;f+=e)u=r[f],d=r[f+1],u<a&&(a=u),d<l&&(l=d),u>h&&(h=u),d>c&&(c=d);p=Math.max(h-a,c-l),p=p!==0?32767/p:0}return Pn(s,o,e,a,l,p,0),o}function od(r,t,e,i,n){var s,o;if(n===Xa(r,t,e,i)>0)for(s=t;s<e;s+=i)o=hd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=hd(s,r[s],r[s+1],o);return o&&Cs(o,o.next)&&(Mn(o),o=o.next),o}function ni(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(Cs(e,e.next)||$t(e.prev,e,e.next)===0)){if(Mn(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Pn(r,t,e,i,n,s,o){if(r){!o&&s&&Jv(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?Vv(r,i,n,s):Xv(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Mn(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=zv(ni(r),t,e),Pn(r,t,e,i,n,s,2)):o===2&&jv(r,t,e,i,n,s):Pn(ni(r),t,e,i,n,s,1);break}}}}function Xv(r){var t=r.prev,e=r,i=r.next;if($t(t,e,i)>=0)return!1;for(var n=t.x,s=e.x,o=i.x,a=t.y,l=e.y,h=i.y,c=n<s?n<o?n:o:s<o?s:o,u=a<l?a<h?a:h:l<h?l:h,d=n>s?n>o?n:o:s>o?s:o,p=a>l?a>h?a:h:l>h?l:h,f=i.next;f!==t;){if(f.x>=c&&f.x<=d&&f.y>=u&&f.y<=p&&$i(n,a,s,l,o,h,f.x,f.y)&&$t(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Vv(r,t,e,i){var n=r.prev,s=r,o=r.next;if($t(n,s,o)>=0)return!1;for(var a=n.x,l=s.x,h=o.x,c=n.y,u=s.y,d=o.y,p=a<l?a<h?a:h:l<h?l:h,f=c<u?c<d?c:d:u<d?u:d,m=a>l?a>h?a:h:l>h?l:h,_=c>u?c>d?c:d:u>d?u:d,v=$a(p,f,t,e,i),y=$a(m,_,t,e,i),g=r.prevZ,b=r.nextZ;g&&g.z>=v&&b&&b.z<=y;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=_&&g!==n&&g!==o&&$i(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0||(g=g.prevZ,b.x>=p&&b.x<=m&&b.y>=f&&b.y<=_&&b!==n&&b!==o&&$i(a,c,l,u,h,d,b.x,b.y)&&$t(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;g&&g.z>=v;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=_&&g!==n&&g!==o&&$i(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;b&&b.z<=y;){if(b.x>=p&&b.x<=m&&b.y>=f&&b.y<=_&&b!==n&&b!==o&&$i(a,c,l,u,h,d,b.x,b.y)&&$t(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function zv(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!Cs(n,s)&&ad(n,i,i.next,s)&&Rn(n,s)&&Rn(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),Mn(i),Mn(i.next),i=r=s),i=i.next}while(i!==r);return ni(i)}function jv(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&e1(o,a)){var l=ld(o,a);o=ni(o,o.next),l=ni(l,l.next),Pn(o,t,e,i,n,s,0),Pn(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function Wv(r,t,e,i){var n=[],s,o,a,l,h;for(s=0,o=t.length;s<o;s++)a=t[s]*i,l=s<o-1?t[s+1]*i:r.length,h=od(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(t1(h));for(n.sort(Yv),s=0;s<n.length;s++)e=qv(n[s],e);return e}function Yv(r,t){return r.x-t.x}function qv(r,t){var e=Kv(r,t);if(!e)return t;var i=ld(e,r);return ni(i,i.next),ni(e,e.next)}function Kv(r,t){var e=t,i=r.x,n=r.y,s=-1/0,o;do{if(n<=e.y&&n>=e.next.y&&e.next.y!==e.y){var a=e.x+(n-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(a<=i&&a>s&&(s=a,o=e.x<e.next.x?e:e.next,a===i))return o}e=e.next}while(e!==t);if(!o)return null;var l=o,h=o.x,c=o.y,u=1/0,d;e=o;do i>=e.x&&e.x>=h&&i!==e.x&&$i(n<c?i:s,n,h,c,n<c?s:i,n,e.x,e.y)&&(d=Math.abs(n-e.y)/(i-e.x),Rn(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&Zv(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function Zv(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function Jv(r,t,e,i){var n=r;do n.z===0&&(n.z=$a(n.x,n.y,t,e,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==r);n.prevZ.nextZ=null,n.prevZ=null,Qv(n)}function Qv(r){var t,e,i,n,s,o,a,l,h=1;do{for(e=r,r=null,s=null,o=0;e;){for(o++,i=e,a=0,t=0;t<h&&(a++,i=i.nextZ,!!i);t++);for(l=h;a>0||l>0&&i;)a!==0&&(l===0||!i||e.z<=i.z)?(n=e,e=e.nextZ,a--):(n=i,i=i.nextZ,l--),s?s.nextZ=n:r=n,n.prevZ=s,s=n;e=i}s.nextZ=null,h*=2}while(o>1);return r}function $a(r,t,e,i,n){return r=(r-e)*n|0,t=(t-i)*n|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1}function t1(r){var t=r,e=r;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==r);return e}function $i(r,t,e,i,n,s,o,a){return(n-o)*(t-a)>=(r-o)*(s-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(s-a)>=(n-o)*(i-a)}function e1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!r1(r,t)&&(Rn(r,t)&&Rn(t,r)&&i1(r,t)&&($t(r.prev,r,t.prev)||$t(r,t.prev,t))||Cs(r,t)&&$t(r.prev,r,r.next)>0&&$t(t.prev,t,t.next)>0)}function $t(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function Cs(r,t){return r.x===t.x&&r.y===t.y}function ad(r,t,e,i){var n=Ps($t(r,t,e)),s=Ps($t(r,t,i)),o=Ps($t(e,i,r)),a=Ps($t(e,i,t));return!!(n!==s&&o!==a||n===0&&Is(r,e,t)||s===0&&Is(r,i,t)||o===0&&Is(e,r,i)||a===0&&Is(e,t,i))}function Is(r,t,e){return t.x<=Math.max(r.x,e.x)&&t.x>=Math.min(r.x,e.x)&&t.y<=Math.max(r.y,e.y)&&t.y>=Math.min(r.y,e.y)}function Ps(r){return r>0?1:r<0?-1:0}function r1(r,t){var e=r;do{if(e.i!==r.i&&e.next.i!==r.i&&e.i!==t.i&&e.next.i!==t.i&&ad(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Rn(r,t){return $t(r.prev,r,r.next)<0?$t(r,t,r.next)>=0&&$t(r,r.prev,t)>=0:$t(r,t,r.prev)<0||$t(r,r.next,t)<0}function i1(r,t){var e=r,i=!1,n=(r.x+t.x)/2,s=(r.y+t.y)/2;do e.y>s!=e.next.y>s&&e.next.y!==e.y&&n<(e.next.x-e.x)*(s-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function ld(r,t){var e=new Ha(r.i,r.x,r.y),i=new Ha(t.i,t.x,t.y),n=r.next,s=t.prev;return r.next=t,t.prev=r,e.next=n,n.prev=e,i.next=e,e.prev=i,s.next=i,i.prev=s,i}function hd(r,t,e,i){var n=new Ha(r,t,e);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function Mn(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function Ha(r,t,e){this.i=r,this.x=t,this.y=e,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}Ss.deviation=function(r,t,e,i){var n=t&&t.length,s=n?t[0]*e:r.length,o=Math.abs(Xa(r,0,s,e));if(n)for(var a=0,l=t.length;a<l;a++){var h=t[a]*e,c=a<l-1?t[a+1]*e:r.length;o-=Math.abs(Xa(r,h,c,e))}var u=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,p=i[a+1]*e,f=i[a+2]*e;u+=Math.abs((r[d]-r[f])*(r[p+1]-r[d+1])-(r[d]-r[p])*(r[f+1]-r[d+1]))}return o===0&&u===0?0:Math.abs((u-o)/o)};function Xa(r,t,e,i){for(var n=0,s=t,o=e-i;s<e;s+=i)n+=(r[o]-r[s])*(r[s+1]+r[o+1]),o=s;return n}Ss.flatten=function(r){for(var t=r[0][0].length,e={vertices:[],holes:[],dimensions:t},i=0,n=0;n<r.length;n++){for(var s=0;s<r[n].length;s++)for(var o=0;o<t;o++)e.vertices.push(r[n][s][o]);n>0&&(i+=r[n-1].length,e.holes.push(i))}return e};var n1=Ga.exports;const s1=Aa(n1);var Rs={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Rs.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,n=r&&!r.nodeType&&r,s=typeof An=="object"&&An;(s.global===s||s.window===s||s.self===s)&&(e=s);var o,a=2147483647,l=36,h=1,c=26,u=38,d=700,p=72,f=128,m="-",_=/^xn--/,v=/[^\x20-\x7E]/,y=/[\x2E\u3002\uFF0E\uFF61]/g,g={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},b=l-h,C=Math.floor,R=String.fromCharCode,A;function P(O){throw new RangeError(g[O])}function M(O,L){for(var $=O.length,F=[];$--;)F[$]=L(O[$]);return F}function k(O,L){var $=O.split("@"),F="";$.length>1&&(F=$[0]+"@",O=$[1]),O=O.replace(y,".");var X=O.split("."),V=M(X,L).join(".");return F+V}function U(O){for(var L=[],$=0,F=O.length,X,V;$<F;)X=O.charCodeAt($++),X>=55296&&X<=56319&&$<F?(V=O.charCodeAt($++),(V&64512)==56320?L.push(((X&1023)<<10)+(V&1023)+65536):(L.push(X),$--)):L.push(X);return L}function I(O){return M(O,function(L){var $="";return L>65535&&(L-=65536,$+=R(L>>>10&1023|55296),L=56320|L&1023),$+=R(L),$}).join("")}function T(O){return O-48<10?O-22:O-65<26?O-65:O-97<26?O-97:l}function E(O,L){return O+22+75*(O<26)-((L!=0)<<5)}function S(O,L,$){var F=0;for(O=$?C(O/d):O>>1,O+=C(O/L);O>b*c>>1;F+=l)O=C(O/b);return C(F+(b+1)*O/(O+u))}function B(O){var L=[],$=O.length,F,X=0,V=f,dt=p,yt,z,wt,it,ft,_t,Pt,Dt,he;for(yt=O.lastIndexOf(m),yt<0&&(yt=0),z=0;z<yt;++z)O.charCodeAt(z)>=128&&P("not-basic"),L.push(O.charCodeAt(z));for(wt=yt>0?yt+1:0;wt<$;){for(it=X,ft=1,_t=l;wt>=$&&P("invalid-input"),Pt=T(O.charCodeAt(wt++)),(Pt>=l||Pt>C((a-X)/ft))&&P("overflow"),X+=Pt*ft,Dt=_t<=dt?h:_t>=dt+c?c:_t-dt,!(Pt<Dt);_t+=l)he=l-Dt,ft>C(a/he)&&P("overflow"),ft*=he;F=L.length+1,dt=S(X-it,F,it==0),C(X/F)>a-V&&P("overflow"),V+=C(X/F),X%=F,L.splice(X++,0,V)}return I(L)}function D(O){var L,$,F,X,V,dt,yt,z,wt,it,ft,_t=[],Pt,Dt,he,Vt;for(O=U(O),Pt=O.length,L=f,$=0,V=p,dt=0;dt<Pt;++dt)ft=O[dt],ft<128&&_t.push(R(ft));for(F=X=_t.length,X&&_t.push(m);F<Pt;){for(yt=a,dt=0;dt<Pt;++dt)ft=O[dt],ft>=L&&ft<yt&&(yt=ft);for(Dt=F+1,yt-L>C((a-$)/Dt)&&P("overflow"),$+=(yt-L)*Dt,L=yt,dt=0;dt<Pt;++dt)if(ft=O[dt],ft<L&&++$>a&&P("overflow"),ft==L){for(z=$,wt=l;it=wt<=V?h:wt>=V+c?c:wt-V,!(z<it);wt+=l)Vt=z-it,he=l-it,_t.push(R(E(it+Vt%he,0))),z=C(Vt/he);_t.push(R(E(z,0))),V=S($,Dt,F==X),$=0,++F}++$,++L}return _t.join("")}function N(O){return k(O,function(L){return _.test(L)?B(L.slice(4).toLowerCase()):L})}function H(O){return k(O,function(L){return v.test(L)?"xn--"+D(L):L})}if(o={version:"1.4.1",ucs2:{decode:U,encode:I},decode:B,encode:D,toASCII:H,toUnicode:N},i&&n)if(r.exports==i)n.exports=o;else for(A in o)o.hasOwnProperty(A)&&(i[A]=o[A]);else e.punycode=o})(An)}(Rs,Rs.exports);var o1=Rs.exports,Hi=TypeError;const a1=H_(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Va=typeof Map=="function"&&Map.prototype,za=Object.getOwnPropertyDescriptor&&Va?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ms=Va&&za&&typeof za.get=="function"?za.get:null,cd=Va&&Map.prototype.forEach,ja=typeof Set=="function"&&Set.prototype,Wa=Object.getOwnPropertyDescriptor&&ja?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Ds=ja&&Wa&&typeof Wa.get=="function"?Wa.get:null,ud=ja&&Set.prototype.forEach,l1=typeof WeakMap=="function"&&WeakMap.prototype,Dn=l1?WeakMap.prototype.has:null,h1=typeof WeakSet=="function"&&WeakSet.prototype,On=h1?WeakSet.prototype.has:null,c1=typeof WeakRef=="function"&&WeakRef.prototype,dd=c1?WeakRef.prototype.deref:null,u1=Boolean.prototype.valueOf,d1=Object.prototype.toString,f1=Function.prototype.toString,p1=String.prototype.match,Ya=String.prototype.slice,Nr=String.prototype.replace,m1=String.prototype.toUpperCase,fd=String.prototype.toLowerCase,pd=RegExp.prototype.test,md=Array.prototype.concat,nr=Array.prototype.join,g1=Array.prototype.slice,gd=Math.floor,qa=typeof BigInt=="function"?BigInt.prototype.valueOf:null,Ka=Object.getOwnPropertySymbols,Za=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Xi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Ln=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xi||!0)?Symbol.toStringTag:null,yd=Object.prototype.propertyIsEnumerable,_d=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function vd(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||pd.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-gd(-r):gd(r);if(i!==r){var n=String(i),s=Ya.call(t,n.length+1);return Nr.call(n,e,"$&_")+"."+Nr.call(Nr.call(s,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Nr.call(t,e,"$&_")}var Ja=a1,bd=Ja.custom,xd=Ad(bd)?bd:null,wd={__proto__:null,double:'"',single:"'"},y1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Os=function r(t,e,i,n){var s=e||{};if(_r(s,"quoteStyle")&&!_r(wd,s.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(_r(s,"maxStringLength")&&(typeof s.maxStringLength=="number"?s.maxStringLength<0&&s.maxStringLength!==1/0:s.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=_r(s,"customInspect")?s.customInspect:!0;if(typeof o!="boolean"&&o!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(_r(s,"indent")&&s.indent!==null&&s.indent!==" "&&!(parseInt(s.indent,10)===s.indent&&s.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(_r(s,"numericSeparator")&&typeof s.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=s.numericSeparator;if(typeof t>"u")return"undefined";if(t===null)return"null";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="string")return Cd(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?vd(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?vd(t,h):h}var c=typeof s.depth>"u"?5:s.depth;if(typeof i>"u"&&(i=0),i>=c&&c>0&&typeof t=="object")return Qa(t)?"[Array]":"[Object]";var u=B1(s,i);if(typeof n>"u")n=[];else if(Sd(n,t)>=0)return"[Circular]";function d(T,E,S){if(E&&(n=g1.call(n),n.push(E)),S){var B={depth:s.depth};return _r(s,"quoteStyle")&&(B.quoteStyle=s.quoteStyle),r(T,B,i+1,n)}return r(T,s,i+1,n)}if(typeof t=="function"&&!Td(t)){var p=S1(t),f=Ls(t,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+nr.call(f,", ")+" }":"")}if(Ad(t)){var m=Xi?Nr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Za.call(t);return typeof t=="object"&&!Xi?Bn(m):m}if(D1(t)){for(var _="<"+fd.call(String(t.nodeName)),v=t.attributes||[],y=0;y<v.length;y++)_+=" "+v[y].name+"="+Ed(_1(v[y].value),"double",s);return _+=">",t.childNodes&&t.childNodes.length&&(_+="..."),_+="</"+fd.call(String(t.nodeName))+">",_}if(Qa(t)){if(t.length===0)return"[]";var g=Ls(t,d);return u&&!L1(g)?"["+el(g,u)+"]":"[ "+nr.call(g,", ")+" ]"}if(b1(t)){var b=Ls(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!yd.call(t,"cause")?"{ ["+String(t)+"] "+nr.call(md.call("[cause]: "+d(t.cause),b),", ")+" }":b.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+nr.call(b,", ")+" }"}if(typeof t=="object"&&o){if(xd&&typeof t[xd]=="function"&&Ja)return Ja(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(C1(t)){var C=[];return cd&&cd.call(t,function(T,E){C.push(d(E,t,!0)+" => "+d(T,t))}),Id("Map",Ms.call(t),C,u)}if(R1(t)){var R=[];return ud&&ud.call(t,function(T){R.push(d(T,t))}),Id("Set",Ds.call(t),R,u)}if(I1(t))return tl("WeakMap");if(M1(t))return tl("WeakSet");if(P1(t))return tl("WeakRef");if(w1(t))return Bn(d(Number(t)));if(T1(t))return Bn(d(qa.call(t)));if(E1(t))return Bn(u1.call(t));if(x1(t))return Bn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof An<"u"&&t===An)return"{ [object globalThis] }";if(!v1(t)&&!Td(t)){var A=Ls(t,d),P=_d?_d(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",k=!P&&Ln&&Object(t)===t&&Ln in t?Ya.call(Fr(t),8,-1):M?"Object":"",U=P||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",I=U+(k||M?"["+nr.call(md.call([],k||[],M||[]),": ")+"] ":"");return A.length===0?I+"{}":u?I+"{"+el(A,u)+"}":I+"{ "+nr.call(A,", ")+" }"}return String(t)};function Ed(r,t,e){var i=e.quoteStyle||t,n=wd[i];return n+r+n}function _1(r){return Nr.call(String(r),/"/g,"&quot;")}function si(r){return!Ln||!(typeof r=="object"&&(Ln in r||typeof r[Ln]<"u"))}function Qa(r){return Fr(r)==="[object Array]"&&si(r)}function v1(r){return Fr(r)==="[object Date]"&&si(r)}function Td(r){return Fr(r)==="[object RegExp]"&&si(r)}function b1(r){return Fr(r)==="[object Error]"&&si(r)}function x1(r){return Fr(r)==="[object String]"&&si(r)}function w1(r){return Fr(r)==="[object Number]"&&si(r)}function E1(r){return Fr(r)==="[object Boolean]"&&si(r)}function Ad(r){if(Xi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!Za)return!1;try{return Za.call(r),!0}catch{}return!1}function T1(r){if(!r||typeof r!="object"||!qa)return!1;try{return qa.call(r),!0}catch{}return!1}var A1=Object.prototype.hasOwnProperty||function(r){return r in this};function _r(r,t){return A1.call(r,t)}function Fr(r){return d1.call(r)}function S1(r){if(r.name)return r.name;var t=p1.call(f1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Sd(r,t){if(r.indexOf)return r.indexOf(t);for(var e=0,i=r.length;e<i;e++)if(r[e]===t)return e;return-1}function C1(r){if(!Ms||!r||typeof r!="object")return!1;try{Ms.call(r);try{Ds.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function I1(r){if(!Dn||!r||typeof r!="object")return!1;try{Dn.call(r,Dn);try{On.call(r,On)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function P1(r){if(!dd||!r||typeof r!="object")return!1;try{return dd.call(r),!0}catch{}return!1}function R1(r){if(!Ds||!r||typeof r!="object")return!1;try{Ds.call(r);try{Ms.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function M1(r){if(!On||!r||typeof r!="object")return!1;try{On.call(r,On);try{Dn.call(r,Dn)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function D1(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Cd(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Cd(Ya.call(r,0,t.maxStringLength),t)+i}var n=y1[t.quoteStyle||"single"];n.lastIndex=0;var s=Nr.call(Nr.call(r,n,"\\$1"),/[\x00-\x1f]/g,O1);return Ed(s,"single",t)}function O1(r){var t=r.charCodeAt(0),e={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return e?"\\"+e:"\\x"+(t<16?"0":"")+m1.call(t.toString(16))}function Bn(r){return"Object("+r+")"}function tl(r){return r+" { ? }"}function Id(r,t,e,i){var n=i?el(e,i):nr.call(e,", ");return r+" ("+t+") {"+n+"}"}function L1(r){for(var t=0;t<r.length;t++)if(Sd(r[t],`
1
+ (function(Yt,ce){typeof exports=="object"&&typeof module<"u"?ce(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],ce):(Yt=typeof globalThis<"u"?globalThis:Yt||self,ce(Yt.AnnotoriousOSD={},Yt.OpenSeadragon))})(this,function(Yt,ce){"use strict";var oC=Object.defineProperty;var aC=(Yt,ce,qr)=>ce in Yt?oC(Yt,ce,{enumerable:!0,configurable:!0,writable:!0,value:qr}):Yt[ce]=qr;var Oh=(Yt,ce,qr)=>aC(Yt,typeof ce!="symbol"?ce+"":ce,qr);var qr=Object.prototype.hasOwnProperty;function Kr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Kr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(qr.call(r,e)&&++i&&!qr.call(t,e)||!(e in t)||!Kr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var Go=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(Go||{});const ue=[];for(let r=0;r<256;++r)ue.push((r+256).toString(16).slice(1));function Zm(r,t=0){return(ue[r[t+0]]+ue[r[t+1]]+ue[r[t+2]]+ue[r[t+3]]+"-"+ue[r[t+4]]+ue[r[t+5]]+"-"+ue[r[t+6]]+ue[r[t+7]]+"-"+ue[r[t+8]]+ue[r[t+9]]+"-"+ue[r[t+10]]+ue[r[t+11]]+ue[r[t+12]]+ue[r[t+13]]+ue[r[t+14]]+ue[r[t+15]]).toLowerCase()}let $o;const Jm=new Uint8Array(16);function Qm(){if(!$o){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");$o=crypto.getRandomValues.bind(crypto)}return $o(Jm)}const tg=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),$h={randomUUID:tg};function eg(r,t,e){var i;if($h.randomUUID&&!r)return $h.randomUUID();r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Qm();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Zm(n)}const Ho=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},rg=(r,t,e,i)=>({id:eg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),ig=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},ng=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},sg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Kr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),og=(r,t)=>!Kr(r.target,t.target),ag=(r,t)=>{const e=ig(r,t),i=ng(r,t),n=sg(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:n.length>0?n:void 0,targetUpdated:og(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Pr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Pr||{});const lg=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),n=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>e.has(u.id)||i.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(r.created||[]).filter(u=>!s.has(u.id)).map(u=>o.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],h=[...(r.deleted||[]).filter(u=>!n.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:p}=u;if(o.has(p.id)){const f=t.updated.find(m=>m.oldValue.id===p.id).newValue;return ag(d,f)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let hg=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,n=e.length;i<n;i++)e[i](...t)},events:{},on(r,t){var e;return((e=this.events)[r]||(e[r]=[])).push(t),()=>{var i;this.events[r]=(i=this.events[r])==null?void 0:i.filter(n=>t!==n)}}});const cg=250,ug=(r,t)=>{const e=hg(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=f=>{if(!s){const{changes:m}=f,_=performance.now();if(_-o>cg)i.splice(n+1),i.push(m),n=i.length-1;else{const v=i.length-1;i[v]=lg(i[v],m)}o=_}s=!1};r.observe(a,{origin:Pr.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f),h=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),c=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({oldValue:m})=>m)),u=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(f,m)=>e.on(f,m),redo:()=>{if(i.length-1>n){s=!0;const{created:f,updated:m,deleted:_}=i[n+1];h(f),u(m),p(_),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:f,updated:m,deleted:_}=i[n];l(f),c(m),d(_),e.emit("undo",i[n]),n-=1}}}},dg=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(v,y)=>{l.has(v)?l.get(v).push(y):l.set(v,[y])},p=(v,y)=>{const g=l.get(v);if(g){const b=g.indexOf(y);b!==-1&&g.splice(b,1)}},f=(v,y,g)=>{l.has(v)&&setTimeout(()=>{l.get(v).forEach(b=>{if(e){const C=Array.isArray(y)?y.map(A=>e.serialize(A)):e.serialize(y),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(C,R)}else b(y,g)})},1)},m=()=>{const{selected:v}=s,y=(v||[]).map(({id:g})=>o.getAnnotation(g));y.forEach(g=>{const b=h.find(C=>C.id===g.id);(!b||!Kr(b,g))&&f("updateAnnotation",g,b)}),h=h.map(g=>y.find(({id:C})=>C===g.id)||g)};s.subscribe(({selected:v})=>{if(!(h.length===0&&v.length===0)){if(h.length===0&&v.length>0)h=v.map(({id:y})=>o.getAnnotation(y));else if(h.length>0&&v.length===0)h.forEach(y=>{const g=o.getAnnotation(y.id);g&&!Kr(g,y)&&f("updateAnnotation",g,y)}),h=[];else{const y=new Set(h.map(b=>b.id)),g=new Set(v.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const C=o.getAnnotation(b.id);C&&!Kr(C,b)&&f("updateAnnotation",C,b)}),h=[...h.filter(b=>g.has(b.id)),...v.filter(({id:b})=>!y.has(b)).map(({id:b})=>o.getAnnotation(b))]}f("selectionChanged",h)}}),n.subscribe(v=>{!c&&v?f("mouseEnterAnnotation",o.getAnnotation(v)):c&&!v?f("mouseLeaveAnnotation",o.getAnnotation(c)):c&&v&&(f("mouseLeaveAnnotation",o.getAnnotation(c)),f("mouseEnterAnnotation",o.getAnnotation(v))),c=v}),a==null||a.subscribe(v=>f("viewportIntersect",v.map(y=>o.getAnnotation(y)))),o.observe(v=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:y,deleted:g}=v.changes;(y||[]).forEach(b=>f("createAnnotation",b)),(g||[]).forEach(b=>f("deleteAnnotation",b)),(v.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:C})=>{const R=h.find(A=>A.id===b.id)||b;h=h.map(A=>A.id===b.id?C:A),f("updateAnnotation",C,R)})},{origin:Pr.LOCAL}),o.observe(v=>{if(h){const y=new Set(h.map(b=>b.id)),g=(v.changes.updated||[]).filter(({newValue:b})=>y.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(R=>R.id===b.id)||b))}},{origin:Pr.REMOTE});const _=v=>y=>{const{updated:g}=y;v?(g||[]).forEach(b=>f("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>f("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:p,emit:f}},fg=r=>t=>t.reduce((e,i)=>{const{parsed:n,error:s}=r.parse(i);return s?{parsed:e.parsed,failed:[...e.failed,i]}:n?{parsed:[...e.parsed,n],failed:e.failed}:{...e}},{parsed:[],failed:[]}),pg=(r,t,e)=>{const{store:i,selection:n}=r,s=v=>{if(e){const{parsed:y,error:g}=e.parse(v);y?i.addAnnotation(y,Pr.REMOTE):console.error(g)}else i.addAnnotation(Ho(v),Pr.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=v=>{const y=i.getAnnotation(v);return e&&y?e.serialize(y):y},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var v;const y=(((v=n.selected)==null?void 0:v.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?y.map(e.serialize):y},u=(v,y=!0)=>fetch(v).then(g=>g.json()).then(g=>(p(g,y),g)),d=v=>{if(typeof v=="string"){const y=i.getAnnotation(v);if(i.deleteAnnotation(v),y)return e?e.serialize(y):y}else{const y=e?e.parse(v).parsed:v;if(y)return i.deleteAnnotation(y),v}},p=(v,y=!0)=>{if(e){const g=e.parseAll||fg(e),{parsed:b,failed:C}=g(v);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),i.bulkAddAnnotations(b,y,Pr.REMOTE)}else i.bulkAddAnnotations(v.map(Ho),y,Pr.REMOTE)},f=(v,y)=>{v?n.setSelected(v,y):n.clear()},m=v=>{n.clear(),n.setUserSelectAction(v)},_=v=>{if(e){const y=e.parse(v).parsed,g=e.serialize(i.getAnnotation(y.id));return i.updateAnnotation(y),g}else{const y=i.getAnnotation(v.id);return i.updateAnnotation(Ho(v)),y}};return{addAnnotation:s,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:f,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},mg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let gg=r=>crypto.getRandomValues(new Uint8Array(r)),yg=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,n=-~(1.6*i*t/r.length);return(s=t)=>{let o="";for(;;){let a=e(n),l=n|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=s)return o}}},_g=(r,t=21)=>yg(r,t|0,gg),vg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=mg[e[r]&63];return t};const bg=()=>({isGuest:!0,id:_g("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),xg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],wg=()=>{const r=[...xg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};vg();var Eg=Object.defineProperty,Tg=(r,t,e)=>t in r?Eg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Hh=(r,t,e)=>Tg(r,typeof t!="symbol"?t+"":t,e);function It(){}function Xo(r,t){for(const e in t)r[e]=t[e];return r}function Xh(r){return r()}function Vh(){return Object.create(null)}function Me(r){r.forEach(Xh)}function Gt(r){return typeof r=="function"}function qt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Ag(r){return Object.keys(r).length===0}function zh(r,...t){if(r==null){for(const i of t)i(void 0);return It}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Vo(r,t,e){r.$$.on_destroy.push(zh(t,e))}function Sg(r,t,e,i){if(r){const n=jh(r,t,e,i);return r[0](n)}}function jh(r,t,e,i){return r[1]&&i?Xo(e.ctx.slice(),r[1](i(t))):e.ctx}function Cg(r,t,e,i){if(r[2]&&i){const n=r[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const s=[],o=Math.max(t.dirty.length,n.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|n[a];return s}return t.dirty|n}return t.dirty}function Ig(r,t,e,i,n,s){if(n){const o=jh(t,e,i,s);r.p(o,n)}}function Pg(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function Wh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function ns(r){return r??""}function bt(r,t){r.appendChild(t)}function rt(r,t,e){r.insertBefore(t,e||null)}function tt(r){r.parentNode&&r.parentNode.removeChild(r)}function Zr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function W(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Yh(r){return document.createTextNode(r)}function we(){return Yh(" ")}function De(){return Yh("")}function Ct(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function x(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function Rg(r){return Array.from(r.childNodes)}function Ze(r,t,e){r.classList.toggle(t,!!e)}function Mg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let gn;function yn(r){gn=r}function qh(){if(!gn)throw new Error("Function called outside component initialization");return gn}function Jr(r){qh().$$.on_mount.push(r)}function Rr(){const r=qh();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=Mg(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function de(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Ei=[],ss=[];let Ti=[];const Kh=[],Zh=Promise.resolve();let zo=!1;function Jh(){zo||(zo=!0,Zh.then(tc))}function Qh(){return Jh(),Zh}function jo(r){Ti.push(r)}const Wo=new Set;let Ai=0;function tc(){if(Ai!==0)return;const r=gn;do{try{for(;Ai<Ei.length;){const t=Ei[Ai];Ai++,yn(t),Dg(t.$$)}}catch(t){throw Ei.length=0,Ai=0,t}for(yn(null),Ei.length=0,Ai=0;ss.length;)ss.pop()();for(let t=0;t<Ti.length;t+=1){const e=Ti[t];Wo.has(e)||(Wo.add(e),e())}Ti.length=0}while(Ei.length);for(;Kh.length;)Kh.pop()();zo=!1,Wo.clear(),yn(r)}function Dg(r){if(r.fragment!==null){r.update(),Me(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(jo)}}function Og(r){const t=[],e=[];Ti.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ti=t}const os=new Set;let Qr;function Ee(){Qr={r:0,c:[],p:Qr}}function Te(){Qr.r||Me(Qr.c),Qr=Qr.p}function at(r,t){r&&r.i&&(os.delete(r),r.i(t))}function pt(r,t,e,i){if(r&&r.o){if(os.has(r))return;os.add(r),Qr.c.push(()=>{os.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Ie(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function ee(r){r&&r.c()}function Jt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),jo(()=>{const s=r.$$.on_mount.map(Xh).filter(Gt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Me(s),r.$$.on_mount=[]}),n.forEach(jo)}function Qt(r,t){const e=r.$$;e.fragment!==null&&(Og(e.after_update),Me(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Lg(r,t){r.$$.dirty[0]===-1&&(Ei.push(r),Jh(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function fe(r,t,e,i,n,s,o=null,a=[-1]){const l=gn;yn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:It,not_equal:n,bound:Vh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Vh(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let c=!1;if(h.ctx=e?e(r,t.props||{},(u,d,...p)=>{const f=p.length?p[0]:d;return h.ctx&&n(h.ctx[u],h.ctx[u]=f)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](f),c&&Lg(r,u)),d}):[],h.update(),c=!0,Me(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=Rg(t.target);h.fragment&&h.fragment.l(u),u.forEach(tt)}else h.fragment&&h.fragment.c();t.intro&&at(r.$$.fragment),Jt(r,t.target,t.anchor),tc()}yn(l)}class pe{constructor(){Hh(this,"$$"),Hh(this,"$$set")}$destroy(){Qt(this,1),this.$destroy=It}$on(t,e){if(!Gt(e))return It;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!Ag(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Bg="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Bg);var mt=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(mt||{}),Ng={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,c=a.y-l.y;return h*h+c*c}function e(a,l,h){var c=l.x,u=l.y,d=h.x-c,p=h.y-u;if(d!==0||p!==0){var f=((a.x-c)*d+(a.y-u)*p)/(d*d+p*p);f>1?(c=h.x,u=h.y):f>0&&(c+=d*f,u+=p*f)}return d=a.x-c,p=a.y-u,d*d+p*p}function i(a,l){for(var h=a[0],c=[h],u,d=1,p=a.length;d<p;d++)u=a[d],t(u,h)>l&&(c.push(u),h=u);return h!==u&&c.push(u),c}function n(a,l,h,c,u){for(var d=c,p,f=l+1;f<h;f++){var m=e(a[f],a[l],a[h]);m>d&&(p=f,d=m)}d>c&&(p-l>1&&n(a,l,p,c,u),u.push(a[p]),h-p>1&&n(a,p,h,c,u))}function s(a,l){var h=a.length-1,c=[a[0]];return n(a,0,h,l,c),c.push(a[h]),c}function o(a,l,h){if(a.length<=2)return a;var c=l!==void 0?l*l:1;return a=h?a:i(a,c),a=s(a,c),a}r.exports=o,r.exports.default=o})()})(Ng);const Yo={},Si=(r,t)=>Yo[r]=t,qo=r=>Yo[r.type].area(r),Fg=(r,t,e,i)=>Yo[r.type].intersects(r,t,e,i),Ae=r=>{let t=1/0,e=1/0,i=-1/0,n=-1/0;return r.forEach(([s,o])=>{t=Math.min(t,s),e=Math.min(e,o),i=Math.max(i,s),n=Math.max(n,o)}),{minX:t,minY:e,maxX:i,maxY:n}},as=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},ls=(r,t,e)=>{let i=!1;for(let n=0,s=r.length-1;n<r.length;s=n++){const o=r[n][0],a=r[n][1],l=r[s][0],h=r[s][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},kg=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},hs=(r,t)=>{const e=Math.abs(t[0]-r[0]),i=Math.abs(t[1]-r[1]);return Math.sqrt(Math.pow(e,2)+Math.pow(i,2))},Ug={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:n,rx:s,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),c=t-i,u=e-n,d=l*c+h*u,p=h*c-l*u;return d*d/(s*s)+p*p/(o*o)<=1}};Si(mt.ELLIPSE,Ug);const Gg={area:r=>0,intersects:(r,t,e,i=2)=>{const[[n,s],[o,a]]=r.geometry.points,l=Math.abs((a-s)*t-(o-n)*e+o*s-a*n),h=hs([n,s],[o,a]);return l/h<=i}};Si(mt.LINE,Gg);const $g={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=as(n.points),a=s.reduce((l,h)=>l+as(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const n of i){const[s,...o]=n.rings;if(ls(s.points,t,e)){let a=!1;for(const l of o)if(ls(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Ko=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ae(t)},$e=r=>r.rings.map(t=>kg(t.points)).join(" "),Hg=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Si(mt.MULTIPOLYGON,$g);const Xg={area:r=>{const t=r.geometry.points;return as(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return ls(i,t,e)}};Si(mt.POLYGON,Xg);const Vg={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Zo(t.points,t.closed);return as(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Zo(n.points,n.closed);return ls(s,t,e)}else return zg(n,[t,e],i)}},Zo=(r,t=!1)=>{const e=[];for(let i=0;i<r.length;i++){const n=r[i],s=r[(i+1)%r.length];if(e.push(n.point),(i<r.length-1||t)&&(n.type==="CURVE"||s.type=="CURVE")){const o=ec(n.point,n.outHandle||n.point,s.inHandle||s.point,s.point,10);e.push(...o.slice(1))}}return e},ec=(r,t,e,i,n=10)=>{const s=[];for(let o=0;o<=n;o++){const a=o/n,l=Math.pow(1-a,3)*r[0]+3*Math.pow(1-a,2)*a*t[0]+3*(1-a)*Math.pow(a,2)*e[0]+Math.pow(a,3)*i[0],h=Math.pow(1-a,3)*r[1]+3*Math.pow(1-a,2)*a*t[1]+3*(1-a)*Math.pow(a,2)*e[1]+Math.pow(a,3)*i[1];s.push([l,h])}return s},zg=(r,t,e)=>{for(let i=0;i<r.points.length-1;i++){const n=r.points[i],s=r.points[i+1];if(n.outHandle||s.inHandle){const o=ec(n.point,n.outHandle||n.point,s.inHandle||s.point,s.point,20);for(let a=0;a<o.length-1;a++)if(rc(t,o[a],o[a+1])<=e)return!0}else if(rc(t,n.point,s.point)<=e)return!0}return!1},rc=(r,t,e)=>{const[i,n]=r,[s,o]=t,[a,l]=e,h=a-s,c=l-o,u=Math.sqrt(h*h+c*c);if(u===0)return Math.sqrt((i-s)*(i-s)+(n-o)*(n-o));const d=((i-s)*h+(n-o)*c)/(u*u);return d<=0?Math.sqrt((i-s)*(i-s)+(n-o)*(n-o)):d>=1?Math.sqrt((i-a)*(i-a)+(n-l)*(n-l)):Math.abs((l-o)*i-(a-s)*n+a*o-l*s)/u},Jo=r=>{if(!r.points||r.points.length===0)return"";const t=[],e=r.points[0];t.push(`M ${e.point[0]} ${e.point[1]}`);for(let i=1;i<r.points.length;i++){const n=r.points[i],s=r.points[i-1];if(n.type==="CURVE"||s.type==="CURVE"){const o=s.type==="CURVE"&&s.outHandle||s.point,a=n.type==="CURVE"&&n.inHandle||n.point,l=n.point;t.push(`C ${o[0]} ${o[1]} ${a[0]} ${a[1]} ${l[0]} ${l[1]}`)}else t.push(`L ${n.point[0]} ${n.point[1]}`)}if(r.closed){const i=r.points[r.points.length-1],n=r.points[0];if(i.outHandle||n.inHandle){const s=i.outHandle||i.point,o=n.inHandle||n.point,a=n.point;t.push(`C ${s[0]} ${s[1]} ${o[0]} ${o[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Si(mt.POLYLINE,Vg);const jg={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};Si(mt.RECTANGLE,jg);const Be=r=>cs(r.target),cs=r=>{var t,e;return(r==null?void 0:r.annotation)!==void 0&&((e=(t=r==null?void 0:r.selector)==null?void 0:t.geometry)==null?void 0:e.bounds)!==void 0},Wg=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,n=[...e.matchAll(i)][0],[s,o,a,l,h,c,u]=n;if(o!=="xywh")throw new Error("Unsupported MediaFragment: "+e);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,p,f,m]=[l,h,c,u].map(parseFloat);return{type:mt.RECTANGLE,geometry:{x:d,y:p,w:f,h:m,bounds:{minX:d,minY:t?p-m:p,maxX:d+f,maxY:t?p:p+m}}}},Yg=r=>{const{x:t,y:e,w:i,h:n}=r;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${e},${i},${n}`}},ic="http://www.w3.org/2000/svg",nc=r=>{const t=i=>{Array.from(i.attributes).forEach(n=>{n.name.startsWith("on")&&i.removeAttribute(n.name)})},e=r.getElementsByTagName("script");return Array.from(e).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(r.querySelectorAll("*")).forEach(t),r},qg=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${ic}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},us=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(ic),i=t.lookupNamespaceURI(null);return e||i?nc(t).firstChild:nc(qg(t)).firstChild},Kg=r=>{const t=sc(r),e=[];let i=[],n=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":i.length>0&&(e.push({points:i}),i=[]),n=[s.args[0],s.args[1]],i.push([...n]);break;case"L":n=[s.args[0],s.args[1]],i.push([...n]);break;case"H":n=[s.args[0],n[1]],i.push([...n]);break;case"V":n=[n[0],s.args[0]],i.push([...n]);break;case"C":n=[s.args[4],s.args[5]],i.push([...n]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(i.length>2&&e.push({points:i}),e.length>0){const s=Ae(e[0].points);return{rings:e,bounds:s}}},Zg=r=>{const{point:t,inHandle:e,outHandle:i}=r;if(!e||!i)return!1;const n=e[0]-t[0],s=e[1]-t[1],o=i[0]-t[0],a=i[1]-t[1],l=n*a-s*o;return Math.abs(l)<.01},Jg=r=>{const t=sc(r);let e=[],i=[0,0],n=!1;for(let o=0;o<t.length;o++){const a=t[o];switch(a.type.toUpperCase()){case"M":i=[a.args[0],a.args[1]],e.push({type:"CORNER",point:[...i]});break;case"L":i=[a.args[0],a.args[1]],e.push({type:"CORNER",point:[...i]});break;case"C":const l=[a.args[0],a.args[1]],h=[a.args[2],a.args[3]],c=[a.args[4],a.args[5]];if(e.length>0){const d=e[e.length-1];(l[0]!==d.point[0]||l[1]!==d.point[1])&&(d.type="CURVE",d.outHandle=l)}const u={type:h[0]!==c[0]||h[1]!==c[1]?"CURVE":"CORNER",point:c};u.type==="CURVE"&&(u.inHandle=h),e.push(u),i=c;break;case"Z":n=!0;break;default:console.warn(`Unsupported SVG path command: ${a.type}`);break}}e=e.map(o=>Zg(o)?{...o,locked:!0}:o);const s=Ae(Zo(e,n));return{points:e,closed:n,bounds:s}},sc=r=>{const t=[],e=r.replace(/,/g," ").trim(),i=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let n;for(;(n=i.exec(e))!==null;){const[,s,o]=n,a=o.trim()===""?[]:o.trim().split(/\s+/).map(Number).filter(l=>!isNaN(l));t.push({type:s,args:a})}return t},Qg=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],n=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:mt.POLYGON,geometry:{points:n,bounds:Ae(n)}}},ty=r=>{const t=us(r),e=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),n=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),o={minX:e-n,minY:i-s,maxX:e+n,maxY:i+s};return{type:mt.ELLIPSE,geometry:{cx:e,cy:i,rx:n,ry:s,bounds:o}}},ey=r=>{const t=us(r),e=parseFloat(t.getAttribute("x1")),i=parseFloat(t.getAttribute("x2")),n=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),o={minX:Math.min(e,i),minY:Math.min(n,s),maxX:Math.max(e,i),maxY:Math.max(n,s)};return{type:mt.LINE,geometry:{points:[[e,n],[i,s]],bounds:o}}},ry=r=>{const t=us(r),e=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],i=e==null?void 0:e.getAttribute("d");if(!i)throw new Error("Could not parse SVG path");const n=Jg(i);if(!n)throw new Error("Could not parse SVG path");return{type:mt.POLYLINE,geometry:n}},iy=r=>{const t=us(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>Kg(s)).filter(Boolean),i=e.reduce((s,o)=>[...s,...o.rings[0].points],[]),n=Ae(i);return e.length===1&&e[0].rings.length===1?{type:mt.POLYGON,geometry:{points:i,bounds:n}}:{type:mt.MULTIPOLYGON,geometry:{polygons:e,bounds:n}}},ny=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return Qg(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return ry(t);if(t.includes("<path "))return iy(t);if(t.includes("<ellipse "))return ty(t);if(t.includes("<line "))return ey(t);throw"Unsupported SVG shape: "+t},sy=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${$e(t)}" />`).join("")}</g>`,oy=r=>{let t;switch(r.type){case mt.POLYGON:{const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(n=>n.join(",")).join(" ")}" /></svg>`;break}case mt.ELLIPSE:{const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`;break}case mt.MULTIPOLYGON:{const e=r.geometry;t=`<svg>${sy(e)}</svg>`;break}case mt.LINE:{const e=r.geometry,[[i,n],[s,o]]=e.points;t=`<svg><line x1="${i}" y1="${n}" x2="${s}" y2="${o}" /></svg>`;break}case mt.POLYLINE:t=`<svg><path d="${Jo(r.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},me=[];for(let r=0;r<256;++r)me.push((r+256).toString(16).slice(1));function ay(r,t=0){return(me[r[t+0]]+me[r[t+1]]+me[r[t+2]]+me[r[t+3]]+"-"+me[r[t+4]]+me[r[t+5]]+"-"+me[r[t+6]]+me[r[t+7]]+"-"+me[r[t+8]]+me[r[t+9]]+"-"+me[r[t+10]]+me[r[t+11]]+me[r[t+12]]+me[r[t+13]]+me[r[t+14]]+me[r[t+15]]).toLowerCase()}let Qo;const ly=new Uint8Array(16);function hy(){if(!Qo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qo=crypto.getRandomValues.bind(crypto)}return Qo(ly)}const cy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),oc={randomUUID:cy};function ac(r,t,e){var i;if(oc.randomUUID&&!r)return oc.randomUUID();r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??hy();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,ay(n)}var lc=Object.prototype.hasOwnProperty;function Mr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Mr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(lc.call(r,e)&&++i&&!lc.call(t,e)||!(e in t)||!Mr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}function ta(){}function uy(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const Ci=[];function ea(r,t=ta){let e;const i=new Set;function n(a){if(uy(r,a)&&(r=a,e)){const l=!Ci.length;for(const h of i)h[1](),Ci.push(h,r);if(l){for(let h=0;h<Ci.length;h+=2)Ci[h][0](Ci[h+1]);Ci.length=0}}}function s(a){n(a(r))}function o(a,l=ta){const h=[a,l];return i.add(h),i.size===1&&(e=t(n,s)||ta),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:n,update:s,subscribe:o}}const dy=r=>{const{subscribe:t,set:e}=ea();let i;return t(n=>i=n),r.observe(({changes:n})=>{if(i){(n.deleted||[]).some(o=>o.id===i)&&e(void 0);const s=(n.updated||[]).find(({oldValue:o})=>o.id===i);s&&e(s.newValue.id)}}),{get current(){return i},subscribe:t,set:e}};var hc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(hc||{});const ds={selected:[]},fy=(r,t,e)=>{const{subscribe:i,set:n}=ea(ds);let s=t,o=ds;i(m=>o=m);const a=()=>{Mr(o,ds)||n(ds)},l=()=>{var m;return((m=o.selected)==null?void 0:m.length)===0},h=m=>{if(l())return!1;const _=typeof m=="string"?m:m.id;return o.selected.some(v=>v.id===_)},c=(m,_)=>{let v;if(Array.isArray(m)){if(v=m.map(g=>r.getAnnotation(g)).filter(Boolean),v.length<m.length){console.warn("Invalid selection: "+m.filter(g=>!v.some(b=>b.id===g)));return}}else{const g=r.getAnnotation(m);if(!g){console.warn("Invalid selection: "+m);return}v=[g]}const y=v.reduce((g,b)=>{const C=f(b);return C==="EDIT"?[...g,{id:b.id,editable:!0}]:C==="SELECT"?[...g,{id:b.id}]:g},[]);n({selected:y,event:_})},u=(m,_)=>{const v=Array.isArray(m)?m:[m],y=v.map(g=>r.getAnnotation(g)).filter(g=>!!g);n({selected:y.map(g=>{const b=_===void 0?f(g)==="EDIT":_;return{id:g.id,editable:b}})}),y.length!==v.length&&console.warn("Invalid selection",m)},d=m=>{if(l())return!1;const{selected:_}=o;_.some(({id:v})=>m.includes(v))&&n({selected:_.filter(({id:v})=>!m.includes(v))})},p=m=>{s=m,u(o.selected.map(({id:_})=>_))},f=m=>py(m,s,e);return r.observe(({changes:m})=>d((m.deleted||[]).map(_=>_.id))),{get event(){return o?o.event:null},get selected(){return o?[...o.selected]:null},get userSelectAction(){return s},clear:a,evalSelectAction:f,isEmpty:l,isSelected:h,setSelected:u,setUserSelectAction:p,subscribe:i,userSelect:c}},py=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},ge=[];for(let r=0;r<256;++r)ge.push((r+256).toString(16).slice(1));function my(r,t=0){return(ge[r[t+0]]+ge[r[t+1]]+ge[r[t+2]]+ge[r[t+3]]+"-"+ge[r[t+4]]+ge[r[t+5]]+"-"+ge[r[t+6]]+ge[r[t+7]]+"-"+ge[r[t+8]]+ge[r[t+9]]+"-"+ge[r[t+10]]+ge[r[t+11]]+ge[r[t+12]]+ge[r[t+13]]+ge[r[t+14]]+ge[r[t+15]]).toLowerCase()}let ra;const gy=new Uint8Array(16);function yy(){if(!ra){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ra=crypto.getRandomValues.bind(crypto)}return ra(gy)}const _y=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),cc={randomUUID:_y};function vy(r,t,e){var i;if(cc.randomUUID&&!r)return cc.randomUUID();r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??yy();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,my(n)}const ia=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},by=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},xy=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},wy=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Mr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Ey=(r,t)=>!Mr(r.target,t.target),uc=(r,t)=>{const e=by(r,t),i=xy(r,t),n=wy(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:n.length>0?n:void 0,targetUpdated:Ey(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Nt=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Nt||{});const Ty=(r,t)=>{var e,i;const{changes:n,origin:s}=t;if(!(r.options.origin?r.options.origin===s:s!=="SILENT"))return!1;if(r.options.ignore){const{ignore:o}=r.options,a=l=>l&&l.length>0;if(!(a(n.created)||a(n.deleted))){const l=(e=n.updated)==null?void 0:e.some(c=>a(c.bodiesCreated)||a(c.bodiesDeleted)||a(c.bodiesUpdated)),h=(i=n.updated)==null?void 0:i.some(c=>c.targetUpdated);if(o==="BODY_ONLY"&&l&&!h||o==="TARGET_ONLY"&&h&&!l)return!1}}if(r.options.annotations){const o=new Set([...(n.created||[]).map(a=>a.id),...(n.deleted||[]).map(a=>a.id),...(n.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(r.options.annotations)?r.options.annotations:[r.options.annotations]).find(a=>o.has(a))}else return!0},Ay=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),n=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>e.has(u.id)||i.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(r.created||[]).filter(u=>!s.has(u.id)).map(u=>o.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],h=[...(r.deleted||[]).filter(u=>!n.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:p}=u;if(o.has(p.id)){const f=t.updated.find(m=>m.oldValue.id===p.id).newValue;return uc(d,f)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},fs=r=>{const t=r.id===void 0?vy():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Sy=r=>r.id!==void 0,Cy=()=>{const r=new Map,t=new Map,e=[],i=(I,T={})=>{e.push({onChange:I,options:T})},n=I=>{const T=e.findIndex(E=>E.onChange==I);T>-1&&e.splice(T,1)},s=(I,T)=>{const E={origin:I,changes:{created:T.created||[],updated:T.updated||[],deleted:T.deleted||[]},state:[...r.values()]};e.forEach(S=>{Ty(S,E)&&S.onChange(E)})},o=(I,T=Nt.LOCAL)=>{if(I.id&&r.get(I.id))throw Error(`Cannot add annotation ${I.id} - exists already`);{const E=fs(I);r.set(E.id,E),E.bodies.forEach(S=>t.set(S.id,E.id)),s(T,{created:[E]})}},a=(I,T)=>{const E=fs(typeof I=="string"?T:I),S=typeof I=="string"?I:I.id,B=S&&r.get(S);if(B){const D=uc(B,E);return S===E.id?r.set(S,E):(r.delete(S),r.set(E.id,E)),B.bodies.forEach(N=>t.delete(N.id)),E.bodies.forEach(N=>t.set(N.id,E.id)),D}else console.warn(`Cannot update annotation ${S} - does not exist`)},l=(I,T=Nt.LOCAL,E=Nt.LOCAL)=>{const S=Sy(T)?E:T,B=a(I,T);B&&s(S,{updated:[B]})},h=(I,T=Nt.LOCAL)=>{r.get(I.id)?l(I,T):o(I,T)},c=(I,T=Nt.LOCAL)=>{const E=I.reduce((S,B)=>{const D=a(B);return D?[...S,D]:S},[]);E.length>0&&s(T,{updated:E})},u=(I,T=Nt.LOCAL)=>{const E=I.map(fs),{toAdd:S,toUpdate:B}=E.reduce((N,H)=>r.get(H.id)?{...N,toUpdate:[...N.toUpdate,H]}:{...N,toAdd:[...N.toAdd,H]},{toAdd:[],toUpdate:[]}),D=B.map(N=>a(N,T)).filter(Boolean);S.forEach(N=>{r.set(N.id,N),N.bodies.forEach(H=>t.set(H.id,N.id))}),s(T,{created:S,updated:D})},d=(I,T=Nt.LOCAL)=>{const E=r.get(I.annotation);if(E){const S={...E,bodies:[...E.bodies,I]};r.set(E.id,S),t.set(I.id,S.id),s(T,{updated:[{oldValue:E,newValue:S,bodiesCreated:[I]}]})}else console.warn(`Attempt to add body to missing annotation: ${I.annotation}`)},p=()=>[...r.values()],f=(I=Nt.LOCAL)=>{const T=[...r.values()];r.clear(),t.clear(),s(I,{deleted:T})},m=(I,T=!0,E=Nt.LOCAL)=>{const S=I.map(fs);if(T){const B=[...r.values()];r.clear(),t.clear(),S.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:S,deleted:B})}else{const B=I.reduce((D,N)=>{const H=N.id&&r.get(N.id);return H?[...D,H]:D},[]);if(B.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${B.map(D=>D.id).join(", ")}`);S.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:S})}},_=I=>{const T=typeof I=="string"?I:I.id,E=r.get(T);if(E)return r.delete(T),E.bodies.forEach(S=>t.delete(S.id)),E;console.warn(`Attempt to delete missing annotation: ${T}`)},v=(I,T=Nt.LOCAL)=>{const E=_(I);E&&s(T,{deleted:[E]})},y=(I,T=Nt.LOCAL)=>{const E=I.reduce((S,B)=>{const D=_(B);return D?[...S,D]:S},[]);E.length>0&&s(T,{deleted:E})},g=I=>{const T=r.get(I.annotation);if(T){const E=T.bodies.find(S=>S.id===I.id);if(E){t.delete(E.id);const S={...T,bodies:T.bodies.filter(B=>B.id!==I.id)};return r.set(T.id,S),{oldValue:T,newValue:S,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${I.id} from annotation ${I.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${I.annotation}`)},b=(I,T=Nt.LOCAL)=>{const E=g(I);E&&s(T,{updated:[E]})},C=(I,T=Nt.LOCAL)=>{const E=I.map(S=>g(S)).filter(Boolean);E.length>0&&s(T,{updated:E})},R=I=>{const T=r.get(I);return T?{...T}:void 0},A=I=>{const T=t.get(I);if(T){const E=R(T).bodies.find(S=>S.id===I);if(E)return E;console.error(`Store integrity error: body ${I} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${I}`)},P=(I,T)=>{if(I.annotation!==T.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=r.get(I.annotation);if(E){const S=E.bodies.find(D=>D.id===I.id),B={...E,bodies:E.bodies.map(D=>D.id===S.id?T:D)};return r.set(E.id,B),S.id!==T.id&&(t.delete(S.id),t.set(T.id,B.id)),{oldValue:E,newValue:B,bodiesUpdated:[{oldBody:S,newBody:T}]}}else console.warn(`Attempt to add body to missing annotation ${I.annotation}`)},M=(I,T,E=Nt.LOCAL)=>{const S=P(I,T);S&&s(E,{updated:[S]})},k=(I,T=Nt.LOCAL)=>{const E=I.map(S=>P({id:S.id,annotation:S.annotation},S)).filter(Boolean);s(T,{updated:E})},U=I=>{const T=r.get(I.annotation);if(T){const E={...T,target:{...T.target,...I}};return r.set(T.id,E),{oldValue:T,newValue:E,targetUpdated:{oldTarget:T.target,newTarget:I}}}else console.warn(`Attempt to update target on missing annotation: ${I.annotation}`)};return{addAnnotation:o,addBody:d,all:p,bulkAddAnnotations:m,bulkDeleteAnnotations:y,bulkDeleteBodies:C,bulkUpdateAnnotations:c,bulkUpdateBodies:k,bulkUpdateTargets:(I,T=Nt.LOCAL)=>{const E=I.map(S=>U(S)).filter(Boolean);E.length>0&&s(T,{updated:E})},bulkUpsertAnnotations:u,clear:f,deleteAnnotation:v,deleteBody:b,getAnnotation:R,getBody:A,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(I,T=Nt.LOCAL)=>{const E=U(I);E&&s(T,{updated:[E]})},upsertAnnotation:h}},Iy=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let Py=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,n=e.length;i<n;i++)e[i](...t)},events:{},on(r,t){var e;return((e=this.events)[r]||(e[r]=[])).push(t),()=>{var i;this.events[r]=(i=this.events[r])==null?void 0:i.filter(n=>t!==n)}}});const Ry=250,My=(r,t)=>{const e=Py(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=f=>{if(!s){const{changes:m}=f,_=performance.now();if(_-o>Ry)i.splice(n+1),i.push(m),n=i.length-1;else{const v=i.length-1;i[v]=Ay(i[v],m)}o=_}s=!1};r.observe(a,{origin:Nt.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f),h=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),c=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({oldValue:m})=>m)),u=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(f,m)=>e.on(f,m),redo:()=>{if(i.length-1>n){s=!0;const{created:f,updated:m,deleted:_}=i[n+1];h(f),u(m),p(_),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:f,updated:m,deleted:_}=i[n];l(f),c(m),d(_),e.emit("undo",i[n]),n-=1}}}},Dy=()=>{const{subscribe:r,set:t}=ea([]);return{subscribe:r,set:t}},Oy=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(v,y)=>{l.has(v)?l.get(v).push(y):l.set(v,[y])},p=(v,y)=>{const g=l.get(v);if(g){const b=g.indexOf(y);b!==-1&&g.splice(b,1)}},f=(v,y,g)=>{l.has(v)&&setTimeout(()=>{l.get(v).forEach(b=>{if(e){const C=Array.isArray(y)?y.map(A=>e.serialize(A)):e.serialize(y),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(C,R)}else b(y,g)})},1)},m=()=>{const{selected:v}=s,y=(v||[]).map(({id:g})=>o.getAnnotation(g));y.forEach(g=>{const b=h.find(C=>C.id===g.id);(!b||!Mr(b,g))&&f("updateAnnotation",g,b)}),h=h.map(g=>y.find(({id:b})=>b===g.id)||g)};s.subscribe(({selected:v})=>{if(!(h.length===0&&v.length===0)){if(h.length===0&&v.length>0)h=v.map(({id:y})=>o.getAnnotation(y));else if(h.length>0&&v.length===0)h.forEach(y=>{const g=o.getAnnotation(y.id);g&&!Mr(g,y)&&f("updateAnnotation",g,y)}),h=[];else{const y=new Set(h.map(b=>b.id)),g=new Set(v.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const C=o.getAnnotation(b.id);C&&!Mr(C,b)&&f("updateAnnotation",C,b)}),h=[...h.filter(b=>g.has(b.id)),...v.filter(({id:b})=>!y.has(b)).map(({id:b})=>o.getAnnotation(b))]}f("selectionChanged",h)}}),n.subscribe(v=>{!c&&v?f("mouseEnterAnnotation",o.getAnnotation(v)):c&&!v?f("mouseLeaveAnnotation",o.getAnnotation(c)):c&&v&&(f("mouseLeaveAnnotation",o.getAnnotation(c)),f("mouseEnterAnnotation",o.getAnnotation(v))),c=v}),a==null||a.subscribe(v=>f("viewportIntersect",v.map(y=>o.getAnnotation(y)))),o.observe(v=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:y,deleted:g}=v.changes;(y||[]).forEach(b=>f("createAnnotation",b)),(g||[]).forEach(b=>f("deleteAnnotation",b)),(v.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:C})=>{const R=h.find(A=>A.id===b.id)||b;h=h.map(A=>A.id===b.id?C:A),f("updateAnnotation",C,R)})},{origin:Nt.LOCAL}),o.observe(v=>{if(h){const y=new Set(h.map(b=>b.id)),g=(v.changes.updated||[]).filter(({newValue:b})=>y.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(C=>C.id===b.id)||b))}},{origin:Nt.REMOTE});const _=v=>y=>{const{updated:g}=y;v?(g||[]).forEach(b=>f("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>f("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:p,emit:f}},Ly=r=>t=>t.reduce((e,i)=>{const{parsed:n,error:s}=r.parse(i);return s?{parsed:e.parsed,failed:[...e.failed,i]}:n?{parsed:[...e.parsed,n],failed:e.failed}:{...e}},{parsed:[],failed:[]}),By=(r,t,e)=>{const{store:i,selection:n}=r,s=v=>{if(e){const{parsed:y,error:g}=e.parse(v);y?i.addAnnotation(y,Nt.REMOTE):console.error(g)}else i.addAnnotation(ia(v),Nt.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=v=>{const y=i.getAnnotation(v);return e&&y?e.serialize(y):y},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var v;const y=(((v=n.selected)==null?void 0:v.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?y.map(e.serialize):y},u=(v,y=!0)=>fetch(v).then(g=>g.json()).then(g=>(p(g,y),g)),d=v=>{if(typeof v=="string"){const y=i.getAnnotation(v);if(i.deleteAnnotation(v),y)return e?e.serialize(y):y}else{const y=e?e.parse(v).parsed:v;if(y)return i.deleteAnnotation(y),v}},p=(v,y=!0)=>{if(e){const g=e.parseAll||Ly(e),{parsed:b,failed:C}=g(v);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),i.bulkAddAnnotations(b,y,Nt.REMOTE)}else i.bulkAddAnnotations(v.map(ia),y,Nt.REMOTE)},f=(v,y)=>{v?n.setSelected(v,y):n.clear()},m=v=>{n.clear(),n.setUserSelectAction(v)},_=v=>{if(e){const y=e.parse(v).parsed,g=e.serialize(i.getAnnotation(y.id));return i.updateAnnotation(y),g}else{const y=i.getAnnotation(v.id);return i.updateAnnotation(ia(v)),y}};return{addAnnotation:s,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:f,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},Ny=(r,t,e)=>typeof t=="function"?t(r,e):t,Fy=(r,t)=>typeof r!="function"&&typeof t!="function"?{...r||{},...t||{}}:(e,i)=>{const n=typeof r=="function"?r(e,i):r,s=typeof t=="function"?t(e,i):t;return{...n||{},...s||{}}},ky="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Uy=r=>crypto.getRandomValues(new Uint8Array(r)),Gy=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,n=-~(1.6*i*t/r.length);return(s=t)=>{let o="";for(;;){let a=e(n),l=n|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=s)return o}}},$y=(r,t=21)=>Gy(r,t|0,Uy),Hy=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=ky[e[r]&63];return t};const Xy=()=>({isGuest:!0,id:$y("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Vy=r=>{const t=JSON.stringify(r);let e=0;for(let i=0,n=t.length;i<n;i++){let s=t.charCodeAt(i);e=(e<<5)-e+s,e|=0}return`${e}`},dc=r=>r?typeof r=="object"?{...r}:r:void 0,zy=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:n,purpose:s,value:o,created:a,modified:l,creator:h,...c}=e;return{id:i||`temp-${Vy(e)}`,annotation:t,type:n,purpose:s,value:o,creator:dc(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),jy=r=>r.map(t=>{var e;const{annotation:i,created:n,updated:s,...o}=t,a={...o,created:n==null?void 0:n.toISOString(),modified:s==null?void 0:s.toISOString()};return(e=a.id)!=null&&e.startsWith("temp-")&&delete a.id,a});Hy();const Wy=(r,t={strict:!0,invertY:!1})=>({parse:e=>Yy(e,t),serialize:e=>qy(e,r,t)}),Yy=(r,t={strict:!0,invertY:!1})=>{const e=r.id||ac(),{creator:i,created:n,modified:s,body:o,...a}=r,l=zy(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,c=typeof h=="string"?h:Array.isArray(h.selector)?h.selector[0]:h.selector,u=typeof c=="string"||(c==null?void 0:c.type)==="FragmentSelector"?Wg(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?ny(c):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return u||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:n?new Date(n):void 0,creator:dc(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},qy=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:n,created:s,updated:o,updatedBy:a,...l}=r.target;let h;try{h=i.type==mt.RECTANGLE?Yg(i.geometry):oy(i)}catch(u){if(e.strict)throw u;h=i}const c={...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:r.id,type:"Annotation",body:jy(r.bodies),created:s==null?void 0:s.toISOString(),creator:n,modified:o==null?void 0:o.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:h}};return delete c.bodies,"annotation"in c.target&&delete c.target.annotation,c},Ii=[];function Ky(r,t=It){let e;const i=new Set;function n(a){if(qt(r,a)&&(r=a,e)){const l=!Ii.length;for(const h of i)h[1](),Ii.push(h,r);if(l){for(let h=0;h<Ii.length;h+=2)Ii[h][0](Ii[h+1]);Ii.length=0}}}function s(a){n(a(r))}function o(a,l=It){const h=[a,l];return i.add(h),i.size===1&&(e=t(n,s)||It),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:n,update:s,subscribe:o}}const Zy=(r,t)=>{const{naturalWidth:e,naturalHeight:i}=r;if(!e&&!i){const{width:n,height:s}=r;t.setAttribute("viewBox",`0 0 ${n} ${s}`),r.addEventListener("load",o=>{const a=o.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${e} ${i}`)},Jy=(r,t)=>{Zy(r,t);const{subscribe:e,set:i}=Ky(1);let n;return window.ResizeObserver&&(n=new ResizeObserver(()=>{const s=t.getBoundingClientRect(),{width:o,height:a}=t.viewBox.baseVal,l=Math.max(s.width/o,s.height/a);i(l)}),n.observe(t.parentElement)),{destroy:()=>{n&&n.disconnect()},subscribe:e}},ti=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:n,stroke:s,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${n||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},ps=(r,t=0)=>{const{minX:e,minY:i,maxX:n,maxY:s}=r;return{x:e-t,y:i-t,w:n-e+2*t,h:s-i+2*t}},pr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Qy=r=>({}),fc=r=>({grab:r[0]});function t0(r){let t,e,i,n;const s=r[8].default,o=Sg(s,r,r[7],fc);return{c(){t=W("g"),o&&o.c(),x(t,"class","a9s-annotation selected")},m(a,l){rt(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Ct(t,"pointerup",r[2]),Ct(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Ig(o,s,a,a[7],e?Cg(s,a[7],l,Qy):Pg(a[7]),fc)},i(a){e||(at(o,a),e=!0)},o(a){pt(o,a),e=!1},d(a){a&&tt(t),o&&o.d(a),i=!1,Me(n)}}}function e0(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Rr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const p=_=>v=>{if(c=_,h){const{left:y,top:g}=h.getBoundingClientRect(),b=v.clientX-y,C=v.clientY-g;u=l.elementToImage(b,C)}else{const{offsetX:y,offsetY:g}=v;u=l.elementToImage(y,g)}d=o,v.target.setPointerCapture(v.pointerId),s("grab",v)},f=_=>{if(c){const[v,y]=l.elementToImage(_.offsetX,_.offsetY),g=[v-u[0],y-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=_=>{_.target.releasePointerCapture(_.pointerId),c=void 0,d=o,s("release",_)};return r.$$set=_=>{"shape"in _&&e(3,o=_.shape),"editor"in _&&e(4,a=_.editor),"transform"in _&&e(5,l=_.transform),"svgEl"in _&&e(6,h=_.svgEl),"$$scope"in _&&e(7,n=_.$$scope)},[p,f,m,o,a,l,h,n,i]}class na extends pe{constructor(t){super(),fe(this,t,e0,t0,qt,{shape:3,editor:4,transform:5,svgEl:6})}}function r0(r){let t,e,i,n,s,o,a,l,h=r[3]&&pc(r);return{c(){t=W("g"),e=W("circle"),h&&h.c(),n=W("circle"),x(e,"class","a9s-handle-buffer"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=r[5]+6/r[2]),x(e,"role","button"),x(e,"tabindex","0"),x(n,"class",s=`a9s-handle-dot${r[3]?" selected":""}`),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",r[5]),x(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){rt(c,t,u),bt(t,e),h&&h.m(t,null),bt(t,n),a||(l=[Ct(e,"dblclick",r[11]),Ct(e,"pointerenter",r[12]),Ct(e,"pointerleave",r[13]),Ct(e,"pointerdown",r[14]),Ct(e,"pointerdown",r[6]),Ct(e,"pointerup",r[15]),Ct(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&x(e,"cx",c[0]),u&2&&x(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&x(e,"r",i),c[3]?h?h.p(c,u):(h=pc(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=`a9s-handle-dot${c[3]?" selected":""}`)&&x(n,"class",s),u&1&&x(n,"cx",c[0]),u&2&&x(n,"cy",c[1]),u&32&&x(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&x(t,"class",o)},d(c){c&&tt(t),h&&h.d(),a=!1,Me(l)}}}function i0(r){let t,e,i,n,s,o,a,l,h;return{c(){t=W("g"),e=W("circle"),n=W("circle"),o=W("circle"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=r[5]*10),x(e,"class","a9s-touch-halo"),Ze(e,"touched",r[4]),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",s=r[5]+10/r[2]),x(n,"class","a9s-handle-buffer"),x(o,"class","a9s-handle-dot"),x(o,"cx",r[0]),x(o,"cy",r[1]),x(o,"r",a=r[5]+2/r[2]),x(t,"class","a9s-touch-handle")},m(c,u){rt(c,t,u),bt(t,e),bt(t,n),bt(t,o),l||(h=[Ct(n,"pointerdown",r[9]),Ct(n,"pointerup",r[10]),Ct(n,"pointerdown",r[6]),Ct(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&x(e,"cx",c[0]),u&2&&x(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&x(e,"r",i),u&16&&Ze(e,"touched",c[4]),u&1&&x(n,"cx",c[0]),u&2&&x(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&x(n,"r",s),u&1&&x(o,"cx",c[0]),u&2&&x(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&x(o,"r",a)},d(c){c&&tt(t),l=!1,Me(h)}}}function pc(r){let t,e;return{c(){t=W("circle"),x(t,"class","a9s-handle-selected"),x(t,"cx",r[0]),x(t,"cy",r[1]),x(t,"r",e=r[5]+8/r[2])},m(i,n){rt(i,t,n)},p(i,n){n&1&&x(t,"cx",i[0]),n&2&&x(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&x(t,"r",e)},d(i){i&&tt(t)}}}function n0(r){let t;function e(n,s){return pr?i0:r0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),rt(n,t,s)},p(n,[s]){i.p(n,s)},i:It,o:It,d(n){n&&tt(t),i.d(n)}}}function s0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=y=>{y.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(y){de.call(this,r,y)}function d(y){de.call(this,r,y)}function p(y){de.call(this,r,y)}function f(y){de.call(this,r,y)}function m(y){de.call(this,r,y)}function _(y){de.call(this,r,y)}function v(y){de.call(this,r,y)}return r.$$set=y=>{e(8,t=Xo(Xo({},t),Wh(y))),"x"in y&&e(0,n=y.x),"y"in y&&e(1,s=y.y),"scale"in y&&e(2,o=y.scale),"selected"in y&&e(3,a=y.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Wh(t),[n,s,o,a,l,i,h,c,t,u,d,p,f,m,_,v]}class Pi extends pe{constructor(t){super(),fe(this,t,s0,n0,qt,{x:0,y:1,scale:2,selected:3})}}function o0(r){let t,e,i,n,s,o,a;return{c(){t=W("g"),e=W("circle"),n=W("circle"),s=W("circle"),x(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=1.75*r[2]),x(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",r[2]),x(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),x(s,"cx",r[0]),x(s,"cy",r[1]),x(s,"r",r[2]),x(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){rt(l,t,h),bt(t,e),bt(t,n),bt(t,s),o||(a=[Ct(e,"pointerdown",r[5]),Ct(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&x(e,"cx",l[0]),h&2&&x(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&x(e,"r",i),h&1&&x(n,"cx",l[0]),h&2&&x(n,"cy",l[1]),h&4&&x(n,"r",l[2]),h&1&&x(s,"cx",l[0]),h&2&&x(s,"cy",l[1]),h&4&&x(s,"r",l[2])},d(l){l&&tt(t),o=!1,Me(a)}}}function a0(r){let t;return{c(){t=W("circle"),x(t,"cx",r[0]),x(t,"cy",r[1]),x(t,"r",r[2])},m(e,i){rt(e,t,i)},p(e,i){i&1&&x(t,"cx",e[0]),i&2&&x(t,"cy",e[1]),i&4&&x(t,"r",e[2])},d(e){e&&tt(t)}}}function l0(r){let t;function e(n,s){return pr?a0:o0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),rt(n,t,s)},p(n,[s]){i.p(n,s)},i:It,o:It,d(n){n&&tt(t),i.d(n)}}}function h0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){de.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,n=h.x),"y"in h&&e(1,s=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[n,s,i,a,o,l]}class mc extends pe{constructor(t){super(),fe(this,t,h0,l0,qt,{x:0,y:1,scale:4})}}function sa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function gc(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function oa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function aa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function yc(r){let t,e,i,n;return{c(){t=W("circle"),x(t,"cx",e=r[28][0]),x(t,"cy",i=r[28][1]),x(t,"r",n=_n/r[3]),x(t,"class","svelte-1h2slbm")},m(s,o){rt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&x(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&x(t,"cy",i),o[0]&8&&n!==(n=_n/s[3])&&x(t,"r",n)},d(s){s&&tt(t)}}}function _c(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=W("mask"),e=W("rect"),a=W("circle"),x(e,"x",i=r[9].x),x(e,"y",n=r[9].y),x(e,"width",s=r[9].w),x(e,"height",o=r[9].h),x(e,"class","svelte-1h2slbm"),x(a,"cx",l=r[28][0]),x(a,"cy",h=r[28][1]),x(a,"r",c=_n/r[3]),x(a,"class","svelte-1h2slbm"),x(t,"id",`${r[19]}-inner`),x(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){rt(u,t,d),bt(t,e),bt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&x(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&x(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&x(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&x(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&x(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&x(a,"cy",h),d[0]&8&&c!==(c=_n/u[3])&&x(a,"r",c)},d(u){u&&tt(t)}}}function vc(r){let t,e;return t=new Pi({props:{class:"a9s-corner-handle",x:r[28][0],y:r[28][1],scale:r[3],selected:r[8].includes(r[30])}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[15]),t.$on("pointerdown",function(){Gt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function bc(r){let t,e;return t=new mc({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Gt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function c0(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y,g,b,C,R=r[6]!==void 0&&!r[7]&&yc(aa(r)),A=r[6]!==void 0&&!r[7]&&_c(oa(r)),P=Ie(r[5].points),M=[];for(let I=0;I<P.length;I+=1)M[I]=vc(gc(r,P,I));const k=I=>pt(M[I],1,1,()=>{M[I]=null});let U=r[6]!==void 0&&!r[7]&&bc(sa(r));return{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("polygon"),R&&R.c(),A&&A.c(),c=we(),u=W("polygon"),p=we(),f=W("polygon"),_=we();for(let I=0;I<M.length;I+=1)M[I].c();v=we(),U&&U.c(),y=De(),x(i,"x",n=r[9].x),x(i,"y",s=r[9].y),x(i,"width",o=r[9].w),x(i,"height",a=r[9].h),x(i,"class","svelte-1h2slbm"),x(l,"points",h=r[5].points.map(xc).join(" ")),x(l,"class","svelte-1h2slbm"),x(e,"id",`${r[19]}-outer`),x(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),x(u,"class","a9s-outer"),x(u,"mask",`url(#${r[19]}-outer)`),x(u,"points",d=r[5].points.map(wc).join(" ")),x(f,"class","a9s-inner a9s-shape-handle"),x(f,"mask",`url(#${r[19]}-inner)`),x(f,"style",r[1]),x(f,"points",m=r[5].points.map(Ec).join(" "))},m(I,T){rt(I,t,T),bt(t,e),bt(e,i),bt(e,l),R&&R.m(e,null),A&&A.m(t,null),rt(I,c,T),rt(I,u,T),rt(I,p,T),rt(I,f,T),rt(I,_,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(I,T);rt(I,v,T),U&&U.m(I,T),rt(I,y,T),g=!0,b||(C=[Ct(u,"pointerup",r[14]),Ct(u,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Ct(f,"pointermove",r[13]),Ct(f,"pointerup",r[14]),Ct(f,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(I,T){if(r=I,(!g||T[0]&512&&n!==(n=r[9].x))&&x(i,"x",n),(!g||T[0]&512&&s!==(s=r[9].y))&&x(i,"y",s),(!g||T[0]&512&&o!==(o=r[9].w))&&x(i,"width",o),(!g||T[0]&512&&a!==(a=r[9].h))&&x(i,"height",a),(!g||T[0]&32&&h!==(h=r[5].points.map(xc).join(" ")))&&x(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(aa(r),T):(R=yc(aa(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?A?A.p(oa(r),T):(A=_c(oa(r)),A.c(),A.m(t,null)):A&&(A.d(1),A=null),(!g||T[0]&32&&d!==(d=r[5].points.map(wc).join(" ")))&&x(u,"points",d),(!g||T[0]&2)&&x(f,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Ec).join(" ")))&&x(f,"points",m),T[0]&134322472){P=Ie(r[5].points);let E;for(E=0;E<P.length;E+=1){const S=gc(r,P,E);M[E]?(M[E].p(S,T),at(M[E],1)):(M[E]=vc(S),M[E].c(),at(M[E],1),M[E].m(v.parentNode,v))}for(Ee(),E=P.length;E<M.length;E+=1)k(E);Te()}r[6]!==void 0&&!r[7]?U?(U.p(sa(r),T),T[0]&192&&at(U,1)):(U=bc(sa(r)),U.c(),at(U,1),U.m(y.parentNode,y)):U&&(Ee(),pt(U,1,1,()=>{U=null}),Te())},i(I){if(!g){for(let T=0;T<P.length;T+=1)at(M[T]);at(U),g=!0}},o(I){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)pt(M[T]);pt(U),g=!1},d(I){I&&(tt(t),tt(c),tt(u),tt(p),tt(f),tt(_),tt(v),tt(y)),R&&R.d(),A&&A.d(),Zr(M,I),U&&U.d(I),b=!1,Me(C)}}}function u0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[c0,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}const d0=250,f0=1e3,p0=12,_n=4.5,xc=r=>r.join(","),wc=r=>r.join(","),Ec=r=>r.join(",");function m0(r,t,e){let i,n,s;const o=Rr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const _=()=>e(7,p=!0),v=()=>e(7,p=!1),y=E=>{if(m.length>0||!n.some(L=>L.visible)){e(6,d=void 0);return}const[S,B]=h.elementToImage(E.offsetX,E.offsetY),D=L=>Math.pow(L[0]-S,2)+Math.pow(L[1]-B,2),N=i.points.reduce((L,$)=>D($)<D(L)?$:L),H=n.filter(L=>L.visible).reduce((L,$)=>D($.point)<D(L.point)?$:L),O=Math.pow(f0/c,2);D(N)<O||D(H.point)<O?e(6,d=n.indexOf(H)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},C=E=>{e(7,p=!0),E.preventDefault(),E.stopPropagation(),f=performance.now()},R=E=>S=>{if(!f||pr||performance.now()-f>d0)return;const B=m.includes(E);S.metaKey||S.ctrlKey||S.shiftKey?B?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):B&&m.length>1?e(8,m=[E]):B?e(8,m=[]):e(8,m=[E]),g()},A=(E,S,B)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,L],$)=>m.includes($)?[O+B[0],L+B[1]]:[O,L]):S==="SHAPE"?D=N.points.map(([O,L])=>[O+B[0],L+B[1]]):D=N.points.map(([O,L],$)=>S===`HANDLE-${$}`?[O+B[0],L+B[1]]:[O,L]);const H=Ae(D);return{...E,geometry:{points:D,bounds:H}}},P=E=>async S=>{S.stopPropagation();const B=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=Ae(B);o("change",{...a,geometry:{points:B,bounds:D}}),await Qh();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:S.clientX,clientY:S.clientY,pointerId:S.pointerId,pointerType:S.pointerType,isPrimary:S.isPrimary,buttons:S.buttons});N.firstChild.dispatchEvent(H)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((B,D)=>!m.includes(D)),S=Ae(E);o("change",{...a,geometry:{points:E,bounds:S}}),e(8,m=[])};Jr(()=>{if(pr)return;const E=S=>{(S.key==="Delete"||S.key==="Backspace")&&(S.preventDefault(),M())};return u.addEventListener("pointermove",y),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",y),u.removeEventListener("keydown",E)}});const k=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){de.call(this,r,E)}function I(E){de.call(this,r,E)}function T(E){de.call(this,r,E)}return r.$$set=E=>{"shape"in E&&e(0,a=E.shape),"computedStyle"in E&&e(1,l=E.computedStyle),"transform"in E&&e(2,h=E.transform),"viewportScale"in E&&e(3,c=E.viewportScale),"svgEl"in E&&e(4,u=E.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=pr?[]:i.points.map((E,S)=>{const B=S===i.points.length-1?i.points[0]:i.points[S+1],D=(E[0]+B[0])/2,N=(E[1]+B[1])/2,H=Math.sqrt(Math.pow(B[0]-D,2)+Math.pow(B[1]-N,2))>p0/c;return{point:[D,N],visible:H}})),r.$$.dirty[0]&40&&e(9,s=ps(i.bounds,_n/c))},[a,l,h,c,u,i,d,p,m,s,n,_,v,y,b,C,R,A,P,k,U,I,T]}class g0 extends pe{constructor(t){super(),fe(this,t,m0,u0,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function y0(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y,g,b,C,R,A,P,M,k,U,I,T,E,S,B,D,N,H,O,L,$,F,X,V,dt,yt,z,wt,it,ft,_t,Pt,Dt,he,Vt,Q,Ge,Jn;return it=new Pi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),it.$on("pointerdown",function(){Gt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),_t=new Pi({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),_t.$on("pointerdown",function(){Gt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Pi({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Dt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new Pi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("rect"),p=we(),f=W("rect"),g=we(),b=W("rect"),M=we(),k=W("rect"),E=we(),S=W("rect"),H=we(),O=W("rect"),X=we(),V=W("rect"),wt=we(),ee(it.$$.fragment),ft=we(),ee(_t.$$.fragment),Pt=we(),ee(Dt.$$.fragment),he=we(),ee(Vt.$$.fragment),x(i,"class","rect-mask-bg svelte-1njczvj"),x(i,"x",n=r[6].x),x(i,"y",s=r[6].y),x(i,"width",o=r[6].w),x(i,"height",a=r[6].h),x(l,"class","rect-mask-fg svelte-1njczvj"),x(l,"x",h=r[5].x),x(l,"y",c=r[5].y),x(l,"width",u=r[5].w),x(l,"height",d=r[5].h),x(e,"id",r[8]),x(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),x(f,"class","a9s-outer"),x(f,"mask",`url(#${r[8]})`),x(f,"x",m=r[5].x),x(f,"y",_=r[5].y),x(f,"width",v=r[5].w),x(f,"height",y=r[5].h),x(b,"class","a9s-inner a9s-shape-handle"),x(b,"style",r[1]),x(b,"x",C=r[5].x),x(b,"y",R=r[5].y),x(b,"width",A=r[5].w),x(b,"height",P=r[5].h),x(k,"class","a9s-edge-handle a9s-edge-handle-top"),x(k,"x",U=r[5].x),x(k,"y",I=r[5].y),x(k,"height",1),x(k,"width",T=r[5].w),x(S,"class","a9s-edge-handle a9s-edge-handle-right"),x(S,"x",B=r[5].x+r[5].w),x(S,"y",D=r[5].y),x(S,"height",N=r[5].h),x(S,"width",1),x(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),x(O,"x",L=r[5].x),x(O,"y",$=r[5].y+r[5].h),x(O,"height",1),x(O,"width",F=r[5].w),x(V,"class","a9s-edge-handle a9s-edge-handle-left"),x(V,"x",dt=r[5].x),x(V,"y",yt=r[5].y),x(V,"height",z=r[5].h),x(V,"width",1)},m(Y,G){rt(Y,t,G),bt(t,e),bt(e,i),bt(e,l),rt(Y,p,G),rt(Y,f,G),rt(Y,g,G),rt(Y,b,G),rt(Y,M,G),rt(Y,k,G),rt(Y,E,G),rt(Y,S,G),rt(Y,H,G),rt(Y,O,G),rt(Y,X,G),rt(Y,V,G),rt(Y,wt,G),Jt(it,Y,G),rt(Y,ft,G),Jt(_t,Y,G),rt(Y,Pt,G),Jt(Dt,Y,G),rt(Y,he,G),Jt(Vt,Y,G),Q=!0,Ge||(Jn=[Ct(f,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Ct(b,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Ct(k,"pointerdown",function(){Gt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Ct(S,"pointerdown",function(){Gt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Ct(O,"pointerdown",function(){Gt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Ct(V,"pointerdown",function(){Gt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],Ge=!0)},p(Y,G){r=Y,(!Q||G&64&&n!==(n=r[6].x))&&x(i,"x",n),(!Q||G&64&&s!==(s=r[6].y))&&x(i,"y",s),(!Q||G&64&&o!==(o=r[6].w))&&x(i,"width",o),(!Q||G&64&&a!==(a=r[6].h))&&x(i,"height",a),(!Q||G&32&&h!==(h=r[5].x))&&x(l,"x",h),(!Q||G&32&&c!==(c=r[5].y))&&x(l,"y",c),(!Q||G&32&&u!==(u=r[5].w))&&x(l,"width",u),(!Q||G&32&&d!==(d=r[5].h))&&x(l,"height",d),(!Q||G&32&&m!==(m=r[5].x))&&x(f,"x",m),(!Q||G&32&&_!==(_=r[5].y))&&x(f,"y",_),(!Q||G&32&&v!==(v=r[5].w))&&x(f,"width",v),(!Q||G&32&&y!==(y=r[5].h))&&x(f,"height",y),(!Q||G&2)&&x(b,"style",r[1]),(!Q||G&32&&C!==(C=r[5].x))&&x(b,"x",C),(!Q||G&32&&R!==(R=r[5].y))&&x(b,"y",R),(!Q||G&32&&A!==(A=r[5].w))&&x(b,"width",A),(!Q||G&32&&P!==(P=r[5].h))&&x(b,"height",P),(!Q||G&32&&U!==(U=r[5].x))&&x(k,"x",U),(!Q||G&32&&I!==(I=r[5].y))&&x(k,"y",I),(!Q||G&32&&T!==(T=r[5].w))&&x(k,"width",T),(!Q||G&32&&B!==(B=r[5].x+r[5].w))&&x(S,"x",B),(!Q||G&32&&D!==(D=r[5].y))&&x(S,"y",D),(!Q||G&32&&N!==(N=r[5].h))&&x(S,"height",N),(!Q||G&32&&L!==(L=r[5].x))&&x(O,"x",L),(!Q||G&32&&$!==($=r[5].y+r[5].h))&&x(O,"y",$),(!Q||G&32&&F!==(F=r[5].w))&&x(O,"width",F),(!Q||G&32&&dt!==(dt=r[5].x))&&x(V,"x",dt),(!Q||G&32&&yt!==(yt=r[5].y))&&x(V,"y",yt),(!Q||G&32&&z!==(z=r[5].h))&&x(V,"height",z);const Ar={};G&32&&(Ar.x=r[5].x),G&32&&(Ar.y=r[5].y),G&8&&(Ar.scale=r[3]),it.$set(Ar);const Sr={};G&32&&(Sr.x=r[5].x+r[5].w),G&32&&(Sr.y=r[5].y),G&8&&(Sr.scale=r[3]),_t.$set(Sr);const Cr={};G&32&&(Cr.x=r[5].x+r[5].w),G&32&&(Cr.y=r[5].y+r[5].h),G&8&&(Cr.scale=r[3]),Dt.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x),G&32&&(Ir.y=r[5].y+r[5].h),G&8&&(Ir.scale=r[3]),Vt.$set(Ir)},i(Y){Q||(at(it.$$.fragment,Y),at(_t.$$.fragment,Y),at(Dt.$$.fragment,Y),at(Vt.$$.fragment,Y),Q=!0)},o(Y){pt(it.$$.fragment,Y),pt(_t.$$.fragment,Y),pt(Dt.$$.fragment,Y),pt(Vt.$$.fragment,Y),Q=!1},d(Y){Y&&(tt(t),tt(p),tt(f),tt(g),tt(b),tt(M),tt(k),tt(E),tt(S),tt(H),tt(O),tt(X),tt(V),tt(wt),tt(ft),tt(Pt),tt(he)),Qt(it,Y),Qt(_t,Y),Qt(Dt,Y),Qt(Vt,Y),Ge=!1,Me(Jn)}}}function _0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[y0,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:r}}}),t.$on("grab",r[9]),t.$on("change",r[10]),t.$on("release",r[11]),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function v0(r,t,e){let i,n,{shape:s}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const c=(m,_,v)=>{const y=m.geometry.bounds;let[g,b]=[y.minX,y.minY],[C,R]=[y.maxX,y.maxY];const[A,P]=v;if(_==="SHAPE")g+=A,C+=A,b+=P,R+=P;else{switch(_){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=P;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=P;break}}switch(_){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=A;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{C+=A;break}}}const M=Math.min(g,C),k=Math.min(b,R),U=Math.abs(C-g),I=Math.abs(R-b);return{...m,geometry:{x:M,y:k,w:U,h:I,bounds:{minX:M,minY:k,maxX:M+U,maxY:k+I}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){de.call(this,r,m)}function p(m){de.call(this,r,m)}function f(m){de.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,s=m.shape),"computedStyle"in m&&e(1,o=m.computedStyle),"transform"in m&&e(2,a=m.transform),"viewportScale"in m&&e(3,l=m.viewportScale),"svgEl"in m&&e(4,h=m.svgEl)},r.$$.update=()=>{r.$$.dirty&1&&e(5,i=s.geometry),r.$$.dirty&40&&e(6,n=ps(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,p,f]}class b0 extends pe{constructor(t){super(),fe(this,t,v0,_0,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Tc=Object.prototype.hasOwnProperty;function la(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&la(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Tc.call(r,e)&&++i&&!Tc.call(t,e)||!(e in t)||!la(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const x0=12,w0=(r,t)=>r.polygons.reduce((e,i,n)=>{const s=i.rings.reduce((o,a,l)=>{const h=a.points.map((c,u)=>{const d=u===a.points.length-1?a.points[0]:a.points[u+1],p=(c[0]+d[0])/2,f=(c[1]+d[1])/2,m=Math.sqrt(Math.pow(d[0]-p,2)+Math.pow(d[1]-f,2))>x0/t;return{point:[p,f],visible:m,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function ha(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ac(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Sc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Cc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function ca(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function ua(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ic(r){let t,e,i,n;return{c(){t=W("circle"),x(t,"cx",e=r[29][0]),x(t,"cy",i=r[29][1]),x(t,"r",n=vn/r[3]),x(t,"class","svelte-1vxo6dc")},m(s,o){rt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&x(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&x(t,"cy",i),o[0]&8&&n!==(n=vn/s[3])&&x(t,"r",n)},d(s){s&&tt(t)}}}function Pc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=W("mask"),e=W("rect"),a=W("circle"),x(e,"x",i=r[9].x),x(e,"y",n=r[9].y),x(e,"width",s=r[9].w),x(e,"height",o=r[9].h),x(e,"class","svelte-1vxo6dc"),x(a,"cx",l=r[29][0]),x(a,"cy",h=r[29][1]),x(a,"r",c=vn/r[3]),x(a,"class","svelte-1vxo6dc"),x(t,"id",`${r[18]}-${r[32]}-inner`),x(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){rt(u,t,d),bt(t,e),bt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&x(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&x(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&x(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&x(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&x(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&x(a,"cy",h),d[0]&8&&c!==(c=vn/u[3])&&x(a,"r",c)},d(u){u&&tt(t)}}}function Rc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Pi({props:{class:"a9s-corner-handle",x:r[29][0],y:r[29][1],scale:r[3],selected:r[8].some(i)}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[14]),t.$on("pointerdown",function(){Gt(r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`))&&r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`).apply(this,arguments)}),t.$on("pointerup",r[15](r[32],r[35],r[37])),{c(){ee(t.$$.fragment)},m(n,s){Jt(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(at(t.$$.fragment,n),e=!0)},o(n){pt(t.$$.fragment,n),e=!1},d(n){Qt(t,n)}}}function Mc(r){let t,e,i=Ie(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Rc(Cc(r,i,o));const s=o=>pt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=De()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);rt(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Ie(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Cc(o,i,l);n[l]?(n[l].p(h,a),at(n[l],1)):(n[l]=Rc(h),n[l].c(),at(n[l],1),n[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<n.length;l+=1)s(l);Te()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)at(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)pt(n[a]);e=!1},d(o){o&&tt(t),Zr(n,o)}}}function Dc(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y=r[6]!==void 0&&!r[7]&&Ic(ua(r)),g=r[6]!==void 0&&!r[7]&&Pc(ca(r)),b=Ie(r[30].rings),C=[];for(let A=0;A<b.length;A+=1)C[A]=Mc(Sc(r,b,A));const R=A=>pt(C[A],1,1,()=>{C[A]=null});return{c(){t=W("g"),e=W("defs"),i=W("mask"),n=W("rect"),h=W("path"),y&&y.c(),g&&g.c(),u=W("path"),p=W("path");for(let A=0;A<C.length;A+=1)C[A].c();x(n,"x",s=r[9].x),x(n,"y",o=r[9].y),x(n,"width",a=r[9].w),x(n,"height",l=r[9].h),x(n,"class","svelte-1vxo6dc"),x(h,"d",c=$e(r[30])),x(h,"class","svelte-1vxo6dc"),x(i,"id",`${r[18]}-${r[32]}-outer`),x(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),x(u,"class","a9s-outer"),x(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),x(u,"fill-rule","evenodd"),x(u,"d",d=$e(r[30])),x(p,"class","a9s-inner"),x(p,"mask",`url(#${r[18]}-${r[32]}-inner)`),x(p,"style",r[1]),x(p,"fill-rule","evenodd"),x(p,"d",f=$e(r[30]))},m(A,P){rt(A,t,P),bt(t,e),bt(e,i),bt(i,n),bt(i,h),y&&y.m(i,null),g&&g.m(e,null),bt(t,u),bt(t,p);for(let M=0;M<C.length;M+=1)C[M]&&C[M].m(t,null);m=!0,_||(v=[Ct(u,"pointerup",r[13]),Ct(u,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Ct(p,"pointerup",r[13]),Ct(p,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],_=!0)},p(A,P){if(r=A,(!m||P[0]&512&&s!==(s=r[9].x))&&x(n,"x",s),(!m||P[0]&512&&o!==(o=r[9].y))&&x(n,"y",o),(!m||P[0]&512&&a!==(a=r[9].w))&&x(n,"width",a),(!m||P[0]&512&&l!==(l=r[9].h))&&x(n,"height",l),(!m||P[0]&32&&c!==(c=$e(r[30])))&&x(h,"d",c),r[6]!==void 0&&!r[7]?y?y.p(ua(r),P):(y=Ic(ua(r)),y.c(),y.m(i,null)):y&&(y.d(1),y=null),r[6]!==void 0&&!r[7]?g?g.p(ca(r),P):(g=Pc(ca(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||P[0]&32&&d!==(d=$e(r[30])))&&x(u,"d",d),(!m||P[0]&2)&&x(p,"style",r[1]),(!m||P[0]&32&&f!==(f=$e(r[30])))&&x(p,"d",f),P[0]&268491048){b=Ie(r[30].rings);let M;for(M=0;M<b.length;M+=1){const k=Sc(r,b,M);C[M]?(C[M].p(k,P),at(C[M],1)):(C[M]=Mc(k),C[M].c(),at(C[M],1),C[M].m(t,null))}for(Ee(),M=b.length;M<C.length;M+=1)R(M);Te()}},i(A){if(!m){for(let P=0;P<b.length;P+=1)at(C[P]);m=!0}},o(A){C=C.filter(Boolean);for(let P=0;P<C.length;P+=1)pt(C[P]);m=!1},d(A){A&&tt(t),y&&y.d(),g&&g.d(),Zr(C,A),_=!1,Me(v)}}}function Oc(r){let t,e;return t=new mc({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Gt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function E0(r){let t,e,i,n=Ie(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Dc(Ac(r,n,l));const o=l=>pt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&Oc(ha(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=we(),a&&a.c(),e=De()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);rt(l,t,h),a&&a.m(l,h),rt(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=Ie(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=Ac(l,n,c);s[c]?(s[c].p(u,h),at(s[c],1)):(s[c]=Dc(u),s[c].c(),at(s[c],1),s[c].m(t.parentNode,t))}for(Ee(),c=n.length;c<s.length;c+=1)o(c);Te()}l[6]!==void 0&&!l[7]?a?(a.p(ha(l),h),h[0]&192&&at(a,1)):(a=Oc(ha(l)),a.c(),at(a,1),a.m(e.parentNode,e)):a&&(Ee(),pt(a,1,1,()=>{a=null}),Te())},i(l){if(!i){for(let h=0;h<n.length;h+=1)at(s[h]);at(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)pt(s[h]);pt(a),i=!1},d(l){l&&(tt(t),tt(e)),Zr(s,l),a&&a.d(l)}}}function T0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[E0,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}const A0=250,S0=1e3,vn=4.5;function C0(r,t,e){let i,n,s;const o=Rr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const _=()=>e(7,p=!0),v=()=>e(7,p=!1),y=S=>{if(m.length>0||!n.some($=>$.visible)){e(6,d=void 0);return}const[B,D]=h.elementToImage(S.offsetX,S.offsetY),N=$=>Math.pow($[0]-B,2)+Math.pow($[1]-D,2),H=Hg(i).reduce(($,F)=>N(F)<N($)?F:$),O=n.filter($=>$.visible).reduce(($,F)=>N(F.point)<N($.point)?F:$),L=Math.pow(S0/c,2);N(H)<L||N(O.point)<L?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},C=S=>{e(7,p=!0),S.preventDefault(),S.stopPropagation(),f=performance.now()},R=(S,B,D)=>N=>{if(!f||pr||performance.now()-f>A0)return;const H=L=>L.polygon===S&&L.ring===B&&L.point===D,O=m.some(H);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(L=>!H(L))):e(8,m=[...m,{polygon:S,ring:B,point:D}]):O&&m.length>1?e(8,m=[{polygon:S,ring:B,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:S,ring:B,point:D}]),g()},A=(S,B,D)=>{g();const N=S.geometry.polygons;let H;if(B==="SHAPE")H=N.map(O=>{const L=O.rings.map((F,X)=>({points:F.points.map((V,dt)=>[V[0]+D[0],V[1]+D[1]])})),$=Ae(L[0].points);return{rings:L,bounds:$}});else{const[O,L,$,F]=B.split("-").map(X=>parseInt(X));H=N.map((X,V)=>{if(V===L){const dt=X.rings.map((z,wt)=>wt===$?{points:z.points.map((it,ft)=>ft===F?[it[0]+D[0],it[1]+D[1]]:it)}:z),yt=Ae(dt[0].points);return{rings:dt,bounds:yt}}else return X})}return{...S,geometry:{polygons:H,bounds:Ko(H)}}},P=S=>async B=>{B.stopPropagation();const D=n[S],N=i.polygons.map((O,L)=>{if(L===D.elementIdx){const $=O.rings.map((X,V)=>V===D.ringIdx?{points:[...X.points.slice(0,D.pointIdx+1),D.point,...X.points.slice(D.pointIdx+1)]}:X),F=Ae($[0].points);return{rings:$,bounds:F}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Ko(N)}}),await Qh();const H=[...document.querySelectorAll(".a9s-handle")][S+1];if(H!=null&&H.firstChild){const O=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:B.clientX,clientY:B.clientY,pointerId:B.pointerId,pointerType:B.pointerType,isPrimary:B.isPrimary,buttons:B.buttons});H.firstChild.dispatchEvent(O)}},M=()=>{const S=i.polygons.map((B,D)=>{if(m.some(N=>N.polygon===D)){const N=B.rings.map((O,L)=>{const $=m.filter(F=>F.polygon===D&&F.ring===L);return $.length&&O.points.length-$.length>=3?{points:O.points.filter((F,X)=>!$.some(V=>V.point===X))}:O}),H=Ae(N[0].points);return{rings:N,bounds:H}}else return B});!la(i.polygons,S)&&(o("change",{...a,geometry:{polygons:S,bounds:Ko(S)}}),e(8,m=[]))};Jr(()=>{if(pr)return;const S=B=>{(B.key==="Delete"||B.key==="Backspace")&&(B.preventDefault(),M())};return u.addEventListener("pointermove",y),u.addEventListener("keydown",S),()=>{u.removeEventListener("pointermove",y),u.removeEventListener("keydown",S)}});const k=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(S,B,D,{polygon:N,ring:H,point:O})=>N===S&&H===B&&O===D;function I(S){de.call(this,r,S)}function T(S){de.call(this,r,S)}function E(S){de.call(this,r,S)}return r.$$set=S=>{"shape"in S&&e(0,a=S.shape),"computedStyle"in S&&e(1,l=S.computedStyle),"transform"in S&&e(2,h=S.transform),"viewportScale"in S&&e(3,c=S.viewportScale),"svgEl"in S&&e(4,u=S.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=pr?[]:w0(i,c)),r.$$.dirty[0]&40&&e(9,s=ps(i.bounds,vn/c))},[a,l,h,c,u,i,d,p,m,s,n,_,v,b,C,R,A,P,k,U,I,T,E]}class I0 extends pe{constructor(t){super(),fe(this,t,C0,T0,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Lc=new Map([[mt.RECTANGLE,b0],[mt.POLYGON,g0],[mt.MULTIPOLYGON,I0]]),da=r=>Lc.get(r.type),Bc=(r,t)=>Lc.set(r,t);function P0(r,t,e){let i;const n=Rr();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return Jr(()=>(e(6,u=new o({target:l,props:{shape:s.target.selector,computedStyle:i,transform:h,viewportScale:c,svgEl:l.closest("svg")}})),u.$on("change",d=>{u.$$set({shape:d.detail}),n("change",d.detail)}),u.$on("grab",d=>n("grab",d.detail)),u.$on("release",d=>n("release",d.detail)),()=>{u.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,s=d.annotation),"editor"in d&&e(1,o=d.editor),"style"in d&&e(2,a=d.style),"target"in d&&e(3,l=d.target),"transform"in d&&e(4,h=d.transform),"viewportScale"in d&&e(5,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=ti(s,a)),r.$$.dirty&65&&s&&(u==null||u.$set({shape:s.target.selector})),r.$$.dirty&80&&u&&u.$set({transform:h}),r.$$.dirty&96&&u&&u.$set({viewportScale:c}),r.$$.dirty&192&&u&&i&&u.$set({computedStyle:i})},[s,o,a,l,h,c,u,i]}class R0 extends pe{constructor(t){super(),fe(this,t,P0,null,qt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function M0(r,t,e){const i=Rr();let{drawingMode:n}=t,{target:s}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return Jr(()=>{const c=s.closest("svg"),u=[],d=(p,f,m)=>{c==null||c.addEventListener(p,f,m),u.push(()=>c==null?void 0:c.removeEventListener(p,f,m))};return e(5,h=new o({target:s,props:{addEventListener:d,drawingMode:n,transform:a,viewportScale:l}})),h.$on("create",p=>i("create",p.detail)),()=>{u.forEach(p=>p()),h.$destroy()}}),r.$$set=c=>{"drawingMode"in c&&e(0,n=c.drawingMode),"target"in c&&e(1,s=c.target),"tool"in c&&e(2,o=c.tool),"transform"in c&&e(3,a=c.transform),"viewportScale"in c&&e(4,l=c.viewportScale)},r.$$.update=()=>{r.$$.dirty&40&&h&&h.$set({transform:a}),r.$$.dirty&48&&h&&h.$set({viewportScale:l})},[n,s,o,a,l,h]}class D0 extends pe{constructor(t){super(),fe(this,t,M0,null,qt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Nc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("rect"),h=W("rect"),c=W("rect"),x(i,"class","rect-mask-bg svelte-1a76qe7"),x(i,"x",n=r[1]-r[5]),x(i,"y",s=r[2]-r[5]),x(i,"width",o=r[3]+2*r[5]),x(i,"height",a=r[4]+2*r[5]),x(l,"class","rect-mask-fg svelte-1a76qe7"),x(l,"x",r[1]),x(l,"y",r[2]),x(l,"width",r[3]),x(l,"height",r[4]),x(e,"id",r[6]),x(e,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),x(h,"class","a9s-outer"),x(h,"mask",`url(#${r[6]})`),x(h,"x",r[1]),x(h,"y",r[2]),x(h,"width",r[3]),x(h,"height",r[4]),x(c,"class","a9s-inner"),x(c,"x",r[1]),x(c,"y",r[2]),x(c,"width",r[3]),x(c,"height",r[4])},m(u,d){rt(u,t,d),bt(t,e),bt(e,i),bt(e,l),rt(u,h,d),rt(u,c,d)},p(u,d){d&34&&n!==(n=u[1]-u[5])&&x(i,"x",n),d&36&&s!==(s=u[2]-u[5])&&x(i,"y",s),d&40&&o!==(o=u[3]+2*u[5])&&x(i,"width",o),d&48&&a!==(a=u[4]+2*u[5])&&x(i,"height",a),d&2&&x(l,"x",u[1]),d&4&&x(l,"y",u[2]),d&8&&x(l,"width",u[3]),d&16&&x(l,"height",u[4]),d&2&&x(h,"x",u[1]),d&4&&x(h,"y",u[2]),d&8&&x(h,"width",u[3]),d&16&&x(h,"height",u[4]),d&2&&x(c,"x",u[1]),d&4&&x(c,"y",u[2]),d&8&&x(c,"width",u[3]),d&16&&x(c,"height",u[4])},d(u){u&&(tt(t),tt(h),tt(c))}}}function O0(r){let t,e=r[0]&&Nc(r);return{c(){t=W("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){rt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[0]?e?e.p(i,n):(e=Nc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:It,o:It,d(i){i&&tt(t),e&&e.d()}}}function L0(r,t,e){let i;const n=Rr();let{addEventListener:s}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c,u,d,p,f,m;const _=C=>{const R=C;h=performance.now(),o==="drag"&&(e(0,c=a.elementToImage(R.offsetX,R.offsetY)),u=c,e(1,d=c[0]),e(2,p=c[1]),e(3,f=1),e(4,m=1))},v=C=>{const R=C;c&&(u=a.elementToImage(R.offsetX,R.offsetY),e(1,d=Math.min(u[0],c[0])),e(2,p=Math.min(u[1],c[1])),e(3,f=Math.abs(u[0]-c[0])),e(4,m=Math.abs(u[1]-c[1])))},y=C=>{const R=C,A=performance.now()-h;if(o==="click"){if(A>300)return;c?g():(e(0,c=a.elementToImage(R.offsetX,R.offsetY)),u=c,e(1,d=c[0]),e(2,p=c[1]),e(3,f=1),e(4,m=1))}else c&&(A>300||f*m>100?(R.stopPropagation(),g()):(e(0,c=void 0),u=void 0))},g=()=>{if(f*m>15){const C={type:mt.RECTANGLE,geometry:{bounds:{minX:d,minY:p,maxX:d+f,maxY:p+m},x:d,y:p,w:f,h:m}};n("create",C)}e(0,c=void 0),u=void 0};Jr(()=>{s("pointerdown",_),s("pointermove",v),s("pointerup",y,!0)});const b=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=C=>{"addEventListener"in C&&e(7,s=C.addEventListener),"drawingMode"in C&&e(8,o=C.drawingMode),"transform"in C&&e(9,a=C.transform),"viewportScale"in C&&e(10,l=C.viewportScale)},r.$$.update=()=>{r.$$.dirty&1024&&e(5,i=2/l)},[c,d,p,f,m,i,b,s,o,a,l]}class B0 extends pe{constructor(t){super(),fe(this,t,L0,O0,qt,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function fa(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function Fc(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m=r[1]&&kc(r);return{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("polygon"),c=W("polygon"),d=W("polygon"),m&&m.c(),f=De(),x(i,"x",n=r[3].x),x(i,"y",s=r[3].y),x(i,"width",o=r[3].w),x(i,"height",a=r[3].h),x(i,"class","svelte-18wrg3t"),x(l,"points",h=r[19]),x(l,"class","svelte-18wrg3t"),x(e,"id",r[5]),x(e,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),x(c,"class","a9s-outer"),x(c,"mask",`url(#${r[5]})`),x(c,"points",u=r[19]),x(d,"class","a9s-inner"),x(d,"points",p=r[19])},m(_,v){rt(_,t,v),bt(t,e),bt(e,i),bt(e,l),rt(_,c,v),rt(_,d,v),m&&m.m(_,v),rt(_,f,v)},p(_,v){v&8&&n!==(n=_[3].x)&&x(i,"x",n),v&8&&s!==(s=_[3].y)&&x(i,"y",s),v&8&&o!==(o=_[3].w)&&x(i,"width",o),v&8&&a!==(a=_[3].h)&&x(i,"height",a),v&4&&h!==(h=_[19])&&x(l,"points",h),v&4&&u!==(u=_[19])&&x(c,"points",u),v&4&&p!==(p=_[19])&&x(d,"points",p),_[1]?m?m.p(_,v):(m=kc(_),m.c(),m.m(f.parentNode,f)):m&&(m.d(1),m=null)},d(_){_&&(tt(t),tt(c),tt(d),tt(f)),m&&m.d(_)}}}function kc(r){let t,e,i;return{c(){t=W("circle"),x(t,"class","a9s-handle svelte-18wrg3t"),x(t,"cx",e=r[0][0][0]),x(t,"cy",i=r[0][0][1]),x(t,"r",r[4])},m(n,s){rt(n,t,s)},p(n,s){s&1&&e!==(e=n[0][0][0])&&x(t,"cx",e),s&1&&i!==(i=n[0][0][1])&&x(t,"cy",i),s&16&&x(t,"r",n[4])},d(n){n&&tt(t)}}}function N0(r){let t,e=r[3]&&Fc(fa(r));return{c(){t=W("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){rt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[3]?e?e.p(fa(i),n):(e=Fc(fa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:It,o:It,d(i){i&&tt(t),e&&e.d()}}}const F0=20,k0=1500;function U0(r,t,e){let i,n,s;const o=Rr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:c=1}=t,u,d=[],p,f,m=!1;const _=R=>{const A=R,{timeStamp:P,offsetX:M,offsetY:k}=A;if(u={timeStamp:P,offsetX:M,offsetY:k},l==="drag"&&d.length===0){const U=h.elementToImage(A.offsetX,A.offsetY);d.push(U),e(10,p=U)}},v=R=>{const A=R;if(f&&clearTimeout(f),d.length>0){if(e(10,p=h.elementToImage(A.offsetX,A.offsetY)),d.length>2){const P=hs(p,d[0])*c;e(1,m=P<F0)}A.pointerType==="touch"&&(f=setTimeout(()=>{g()},k0))}},y=R=>{const A=R;if(f&&clearTimeout(f),l==="click"){const P=A.timeStamp-u.timeStamp,M=hs([u.offsetX,u.offsetY],[A.offsetX,A.offsetY]);if(P>300||M>15)return;if(m)b();else if(d.length===0){const k=h.elementToImage(A.offsetX,A.offsetY);d.push(k),e(10,p=k)}else d.push(p)}else{if(d.length===1&&hs(d[0],p)<=4){e(0,d=[]),e(10,p=void 0);return}A.stopImmediatePropagation(),m?b():d.push(p)}},g=()=>{if(!p)return;const R=d.slice(0,-1);if(R.length<3)return;const A={type:mt.POLYGON,geometry:{bounds:Ae(d),points:R}};qo(A)>4&&(e(0,d=[]),e(10,p=void 0),o("create",A))},b=()=>{const R={type:mt.POLYGON,geometry:{bounds:Ae(d),points:[...d]}};e(0,d=[]),e(10,p=void 0),o("create",R)};Jr(()=>{a("pointerdown",_,!0),a("pointermove",v),a("pointerup",y,!0),a("dblclick",g,!0)});const C=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=R=>{"addEventListener"in R&&e(6,a=R.addEventListener),"drawingMode"in R&&e(7,l=R.drawingMode),"transform"in R&&e(8,h=R.transform),"viewportScale"in R&&e(9,c=R.viewportScale)},r.$$.update=()=>{r.$$.dirty&512&&e(4,i=4/c),r.$$.dirty&1027&&e(2,n=p?m?d:[...d,p]:[]),r.$$.dirty&516&&e(3,s=n.length>0?ps(Ae(n),2/c):void 0)},[d,m,n,s,i,C,a,l,h,c,p]}class G0 extends pe{constructor(t){super(),fe(this,t,U0,N0,qt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const pa=new Map([["rectangle",{tool:B0}],["polygon",{tool:G0}]]),ms=()=>[...pa.keys()],gs=r=>pa.get(r),Uc=(r,t,e={})=>pa.set(r,{tool:t,opts:e});function $0(r){let t,e,i,n,s;return{c(){t=W("g"),e=W("ellipse"),n=W("ellipse"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"cx",r[2]),x(e,"cy",r[3]),x(e,"rx",r[4]),x(e,"ry",r[5]),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"cx",r[2]),x(n,"cy",r[3]),x(n,"rx",r[4]),x(n,"ry",r[5]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:It,o:It,d(o){o&&tt(t)}}}function H0(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:c}=s;return r.$$set=u=>{"annotation"in u&&e(0,n=u.annotation),"geom"in u&&e(6,s=u.geom),"style"in u&&e(7,o=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=ti(n,o))},[n,i,a,l,h,c,s,o]}class X0 extends pe{constructor(t){super(),fe(this,t,H0,$0,qt,{annotation:0,geom:6,style:7})}}function V0(r){let t,e,i,n,s;return{c(){t=W("g"),e=W("line"),n=W("line"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"x1",r[2]),x(e,"y1",r[3]),x(e,"x2",r[4]),x(e,"y2",r[5]),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"x1",r[2]),x(n,"y1",r[3]),x(n,"x2",r[4]),x(n,"y2",r[5]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:It,o:It,d(o){o&&tt(t)}}}function z0(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{points:a}=s,[[l,h],[c,u]]=a;return r.$$set=d=>{"annotation"in d&&e(0,n=d.annotation),"geom"in d&&e(6,s=d.geom),"style"in d&&e(7,o=d.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=ti(n,o))},[n,i,l,h,c,u,s,o]}class j0 extends pe{constructor(t){super(),fe(this,t,z0,V0,qt,{annotation:0,geom:6,style:7})}}function Gc(r,t,e){const i=r.slice();return i[5]=t[e],i}function $c(r){let t,e,i;return{c(){t=W("path"),i=W("path"),x(t,"class","a9s-outer"),x(t,"style",e=r[1]?"display:none;":void 0),x(t,"fill-rule","evenodd"),x(t,"d",$e(r[5])),x(i,"class","a9s-inner"),x(i,"style",r[1]),x(i,"fill-rule","evenodd"),x(i,"d",$e(r[5]))},m(n,s){rt(n,t,s),rt(n,i,s)},p(n,s){s&2&&e!==(e=n[1]?"display:none;":void 0)&&x(t,"style",e),s&2&&x(i,"style",n[1])},d(n){n&&(tt(t),tt(i))}}}function W0(r){let t,e,i=Ie(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=$c(Gc(r,i,s));return{c(){t=W("g");for(let s=0;s<n.length;s+=1)n[s].c();x(t,"class","a9s-annotation"),x(t,"data-id",e=r[0].id)},m(s,o){rt(s,t,o);for(let a=0;a<n.length;a+=1)n[a]&&n[a].m(t,null)},p(s,[o]){if(o&6){i=Ie(s[2]);let a;for(a=0;a<i.length;a+=1){const l=Gc(s,i,a);n[a]?n[a].p(l,o):(n[a]=$c(l),n[a].c(),n[a].m(t,null))}for(;a<n.length;a+=1)n[a].d(1);n.length=i.length}o&1&&e!==(e=s[0].id)&&x(t,"data-id",e)},i:It,o:It,d(s){s&&tt(t),Zr(n,s)}}}function Y0(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{polygons:a}=s;return r.$$set=l=>{"annotation"in l&&e(0,n=l.annotation),"geom"in l&&e(3,s=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=ti(n,o))},[n,i,a,s,o]}class q0 extends pe{constructor(t){super(),fe(this,t,Y0,W0,qt,{annotation:0,geom:3,style:4})}}function K0(r){let t,e,i,n,s;return{c(){t=W("g"),e=W("polygon"),n=W("polygon"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"points",r[2].map(Z0).join(" ")),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"points",r[2].map(J0).join(" ")),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:It,o:It,d(o){o&&tt(t)}}}const Z0=r=>r.join(","),J0=r=>r.join(",");function Q0(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{points:a}=s;return r.$$set=l=>{"annotation"in l&&e(0,n=l.annotation),"geom"in l&&e(3,s=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=ti(n,o))},[n,i,a,s,o]}class t_ extends pe{constructor(t){super(),fe(this,t,Q0,K0,qt,{annotation:0,geom:3,style:4})}}function e_(r){let t,e,i,n,s,o,a;return{c(){t=W("g"),e=W("path"),s=W("path"),x(e,"class",i=ns(`a9s-outer ${r[1]}`)+" svelte-1w0132l"),x(e,"style",n=r[3]?"display:none;":void 0),x(e,"d",r[2]),x(s,"class",o=ns(`a9s-inner ${r[1]}`)+" svelte-1w0132l"),x(s,"style",r[3]),x(s,"d",r[2]),x(t,"class","a9s-annotation"),x(t,"data-id",a=r[0].id)},m(l,h){rt(l,t,h),bt(t,e),bt(t,s)},p(l,[h]){h&2&&i!==(i=ns(`a9s-outer ${l[1]}`)+" svelte-1w0132l")&&x(e,"class",i),h&8&&n!==(n=l[3]?"display:none;":void 0)&&x(e,"style",n),h&4&&x(e,"d",l[2]),h&2&&o!==(o=ns(`a9s-inner ${l[1]}`)+" svelte-1w0132l")&&x(s,"class",o),h&8&&x(s,"style",l[3]),h&4&&x(s,"d",l[2]),h&1&&a!==(a=l[0].id)&&x(t,"data-id",a)},i:It,o:It,d(l){l&&tt(t)}}}function r_(r,t,e){let i,n,s,{annotation:o}=t,{geom:a}=t,{style:l}=t;return r.$$set=h=>{"annotation"in h&&e(0,o=h.annotation),"geom"in h&&e(4,a=h.geom),"style"in h&&e(5,l=h.style)},r.$$.update=()=>{r.$$.dirty&33&&e(3,i=ti(o,l)),r.$$.dirty&16&&e(2,n=Jo(a)),r.$$.dirty&16&&e(1,s=a.closed?"closed":"open")},[o,s,n,i,a,l]}class i_ extends pe{constructor(t){super(),fe(this,t,r_,e_,qt,{annotation:0,geom:4,style:5})}}function n_(r){let t,e,i,n,s;return{c(){t=W("g"),e=W("rect"),n=W("rect"),x(e,"class","a9s-outer"),x(e,"style",i=r[5]?"display:none;":void 0),x(e,"x",r[4]),x(e,"y",r[3]),x(e,"width",r[2]),x(e,"height",r[1]),x(n,"class","a9s-inner"),x(n,"style",r[5]),x(n,"x",r[4]),x(n,"y",r[3]),x(n,"width",r[2]),x(n,"height",r[1]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&x(e,"style",i),a&16&&x(e,"x",o[4]),a&8&&x(e,"y",o[3]),a&4&&x(e,"width",o[2]),a&2&&x(e,"height",o[1]),a&32&&x(n,"style",o[5]),a&16&&x(n,"x",o[4]),a&8&&x(n,"y",o[3]),a&4&&x(n,"width",o[2]),a&2&&x(n,"height",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:It,o:It,d(o){o&&tt(t)}}}function s_(r,t,e){let i,n,s,o,a,{annotation:l}=t,{geom:h}=t,{style:c}=t;return r.$$set=u=>{"annotation"in u&&e(0,l=u.annotation),"geom"in u&&e(6,h=u.geom),"style"in u&&e(7,c=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=ti(l,c)),r.$$.dirty&64&&e(4,{x:n,y:s,w:o,h:a}=h,n,(e(3,s),e(6,h)),(e(2,o),e(6,h)),(e(1,a),e(6,h)))},[l,a,o,s,n,i,h,c]}class o_ extends pe{constructor(t){super(),fe(this,t,s_,n_,qt,{annotation:0,geom:6,style:7})}}const a_=r=>({elementToImage:(t,e)=>{const i=r.getBoundingClientRect(),n=r.createSVGPoint();n.x=t+i.x,n.y=e+i.y;const{x:s,y:o}=n.matrixTransform(r.getScreenCTM().inverse());return[s,o]}}),l_=250,h_=(r,t)=>{const e=Rr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<l_){const{x:s,y:o}=Hc(n,r),a=t.getAt(s,o,void 0,2);a?e("click",{originalEvent:n,annotation:a}):e("click",{originalEvent:n})}}}},Hc=(r,t)=>{const e=t.createSVGPoint(),i=t.getBoundingClientRect(),n=r.clientX-i.x,s=r.clientY-i.y,{left:o,top:a}=t.getBoundingClientRect();return e.x=n+o,e.y=s+a,e.matrixTransform(t.getScreenCTM().inverse())};function Xc(r,t,e){const i=r.slice();return i[39]=t[e],i}function Vc(r,t,e){const i=r.slice();return i[42]=t[e],i}function ma(r){const t=r.slice(),e=t[42].target.selector;return t[45]=e,t}function zc(r){let t=r[42],e,i,n=jc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&131072&&qt(t,t=s[42])?(Ee(),pt(n,1,1,It),Te(),n=jc(s),n.c(),at(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(at(n),i=!0)},o(s){pt(n),i=!1},d(s){s&&tt(e),n.d(s)}}}function c_(r){let t,e;return t=new j0({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function u_(r){let t,e;return t=new i_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function d_(r){let t,e;return t=new q0({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function f_(r){let t,e;return t=new t_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function p_(r){let t,e;return t=new o_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function m_(r){var t;let e,i;return e=new X0({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){ee(e.$$.fragment)},m(n,s){Jt(e,n,s),i=!0},p(n,s){var o;const a={};s[0]&131072&&(a.annotation=n[42]),s[0]&131072&&(a.geom=(o=n[45])==null?void 0:o.geometry),s[0]&2&&(a.style=n[1]),e.$set(a)},i(n){i||(at(e.$$.fragment,n),i=!0)},o(n){pt(e.$$.fragment,n),i=!1},d(n){Qt(e,n)}}}function jc(r){let t,e,i,n;const s=[m_,p_,f_,d_,u_,c_],o=[];function a(l,h){var c,u,d,p,f,m;return((c=l[45])==null?void 0:c.type)===mt.ELLIPSE?0:((u=l[45])==null?void 0:u.type)===mt.RECTANGLE?1:((d=l[45])==null?void 0:d.type)===mt.POLYGON?2:((p=l[45])==null?void 0:p.type)===mt.MULTIPOLYGON?3:((f=l[45])==null?void 0:f.type)===mt.POLYLINE?4:((m=l[45])==null?void 0:m.type)===mt.LINE?5:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=De()},m(l,h){~t&&o[t].m(l,h),rt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),pt(o[c],1,1,()=>{o[c]=null}),Te()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),at(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(at(e),n=!0)},o(l){pt(e),n=!1},d(l){l&&tt(i),~t&&o[t].d(l)}}}function Wc(r){let t=Be(r[42])&&!r[10](r[42]),e,i,n=t&&zc(ma(r));return{c(){n&&n.c(),e=De()},m(s,o){n&&n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&132096&&(t=Be(s[42])&&!s[10](s[42])),t?n?(n.p(ma(s),o),o[0]&132096&&at(n,1)):(n=zc(ma(s)),n.c(),at(n,1),n.m(e.parentNode,e)):n&&(Ee(),pt(n,1,1,()=>{n=null}),Te())},i(s){i||(at(n),i=!0)},o(s){pt(n),i=!1},d(s){s&&tt(e),n&&n.d(s)}}}function Yc(r){let t,e,i,n;const s=[y_,g_],o=[];function a(l,h){return l[6]?0:l[15]&&l[0]?1:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=De()},m(l,h){~t&&o[t].m(l,h),rt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),pt(o[c],1,1,()=>{o[c]=null}),Te()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),at(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(at(e),n=!0)},o(l){pt(e),n=!1},d(l){l&&tt(i),~t&&o[t].d(l)}}}function g_(r){let t=`${r[2]}-${r[7]}`,e,i,n=qc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&132&&qt(t,t=`${s[2]}-${s[7]}`)?(Ee(),pt(n,1,1,It),Te(),n=qc(s),n.c(),at(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(at(n),i=!0)},o(s){pt(n),i=!1},d(s){s&&tt(e),n.d(s)}}}function y_(r){let t,e,i=Ie(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=Zc(Xc(r,i,o));const s=o=>pt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=De()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);rt(o,t,a),e=!0},p(o,a){if(a[0]&8659266){i=Ie(o[6]);let l;for(l=0;l<i.length;l+=1){const h=Xc(o,i,l);n[l]?(n[l].p(h,a),at(n[l],1)):(n[l]=Zc(h),n[l].c(),at(n[l],1),n[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<n.length;l+=1)s(l);Te()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)at(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)pt(n[a]);e=!1},d(o){o&&tt(t),Zr(n,o)}}}function qc(r){let t,e;return t=new D0({props:{target:r[8],tool:r[15],drawingMode:r[14],transform:r[13],viewportScale:r[18]}}),t.$on("create",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&256&&(s.target=i[8]),n[0]&32768&&(s.tool=i[15]),n[0]&16384&&(s.drawingMode=i[14]),n[0]&8192&&(s.transform=i[13]),n[0]&262144&&(s.viewportScale=i[18]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function Kc(r){let t,e;return t=new R0({props:{target:r[8],editor:r[39].editor,annotation:r[39].annotation,style:r[1],transform:r[13],viewportScale:r[18]}}),t.$on("change",function(){Gt(r[23](r[39].annotation))&&r[23](r[39].annotation).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&256&&(s.target=r[8]),n[0]&64&&(s.editor=r[39].editor),n[0]&64&&(s.annotation=r[39].annotation),n[0]&2&&(s.style=r[1]),n[0]&8192&&(s.transform=r[13]),n[0]&262144&&(s.viewportScale=r[18]),t.$set(s)},i(i){e||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){Qt(t,i)}}}function Zc(r){let t=r[39].annotation.id,e,i,n=Kc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&64&&qt(t,t=s[39].annotation.id)?(Ee(),pt(n,1,1,It),Te(),n=Kc(s),n.c(),at(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(at(n),i=!0)},o(s){pt(n),i=!1},d(s){s&&tt(e),n.d(s)}}}function __(r){let t,e,i,n,s,o,a=Ie(r[17].filter(r[34])),l=[];for(let u=0;u<a.length;u+=1)l[u]=Wc(Vc(r,a,u));const h=u=>pt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&Yc(r);return{c(){t=W("svg"),e=W("g");for(let u=0;u<l.length;u+=1)l[u].c();i=W("g"),c&&c.c(),x(i,"class","drawing"),x(t,"role","application"),x(t,"tabindex",0),x(t,"class","a9s-annotationlayer"),Ze(t,"drawing",r[15]),Ze(t,"editing",r[5]),Ze(t,"hidden",!r[3]),Ze(t,"hover",r[16])},m(u,d){rt(u,t,d),bt(t,e);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(e,null);bt(t,i),c&&c.m(i,null),r[35](i),r[36](t),n=!0,s||(o=[Ct(t,"pointerup",function(){Gt(r[11])&&r[11].apply(this,arguments)}),Ct(t,"pointerdown",function(){Gt(r[12])&&r[12].apply(this,arguments)}),Ct(t,"pointermove",r[24])],s=!0)},p(u,d){if(r=u,d[0]&132098){a=Ie(r[17].filter(r[34]));let p;for(p=0;p<a.length;p+=1){const f=Vc(r,a,p);l[p]?(l[p].p(f,d),at(l[p],1)):(l[p]=Wc(f),l[p].c(),at(l[p],1),l[p].m(e,null))}for(Ee(),p=a.length;p<l.length;p+=1)h(p);Te()}r[8]?c?(c.p(r,d),d[0]&256&&at(c,1)):(c=Yc(r),c.c(),at(c,1),c.m(i,null)):c&&(Ee(),pt(c,1,1,()=>{c=null}),Te()),(!n||d[0]&32768)&&Ze(t,"drawing",r[15]),(!n||d[0]&32)&&Ze(t,"editing",r[5]),(!n||d[0]&8)&&Ze(t,"hidden",!r[3]),(!n||d[0]&65536)&&Ze(t,"hover",r[16])},i(u){if(!n){for(let d=0;d<a.length;d+=1)at(l[d]);at(c),n=!0}},o(u){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)pt(l[d]);pt(c),n=!1},d(u){u&&tt(t),Zr(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,Me(o)}}}function v_(r,t,e){let i,n,s,o,a,l,h,c,u,d,p,f,m=It,_=()=>(m(),m=zh(S,z=>e(18,f=z)),S);r.$$.on_destroy.push(()=>m());let{drawingEnabled:v}=t,{image:y}=t,{preferredDrawingMode:g}=t,{state:b}=t,{style:C=void 0}=t,{toolName:R=ms()[0]}=t,{user:A}=t,{visible:P=!0}=t,M=0;const k=()=>e(7,M+=1),U=()=>R,I=()=>v;let T,E,S;Jr(()=>_(e(9,S=Jy(y,E))));const{hover:B,selection:D,store:N}=b;Vo(r,B,z=>e(16,u=z)),Vo(r,D,z=>e(33,d=z)),Vo(r,N,z=>e(17,p=z));let H,O;const L=z=>{H&&N.unobserve(H);const wt=z.filter(({editable:it})=>it).map(({id:it})=>it);wt.length>0?(e(5,O=wt.map(it=>N.getAnnotation(it)).filter(it=>it&&Be(it))),H=it=>{const{updated:ft}=it.changes;e(5,O=ft==null?void 0:ft.map(_t=>_t.newValue))},N.observe(H,{annotations:wt})):e(5,O=void 0)},$=z=>{const wt=ac(),it={id:wt,bodies:[],target:{annotation:wt,selector:z.detail,creator:A,created:new Date}};N.addAnnotation(it),D.setSelected(it.id)},F=z=>wt=>{var it;const{target:ft}=z,_t=10*60*1e3,Pt=((it=ft.creator)==null?void 0:it.id)!==A.id||!ft.created||new Date().getTime()-ft.created.getTime()>_t;N.updateTarget({...ft,selector:wt.detail,created:Pt?ft.created:new Date,updated:Pt?new Date:void 0,updatedBy:Pt?A:void 0})},X=z=>{const{x:wt,y:it}=Hc(z,E),ft=N.getAt(wt,it,void 0,2);ft?u!==ft.id&&B.set(ft.id):B.set(void 0)},V=z=>Be(z);function dt(z){ss[z?"unshift":"push"](()=>{T=z,e(8,T)})}function yt(z){ss[z?"unshift":"push"](()=>{E=z,e(4,E)})}return r.$$set=z=>{"drawingEnabled"in z&&e(0,v=z.drawingEnabled),"image"in z&&e(25,y=z.image),"preferredDrawingMode"in z&&e(26,g=z.preferredDrawingMode),"state"in z&&e(27,b=z.state),"style"in z&&e(1,C=z.style),"toolName"in z&&e(2,R=z.toolName),"user"in z&&e(28,A=z.user),"visible"in z&&e(3,P=z.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(15,{tool:i,opts:n}=gs(R)||{tool:void 0,opts:void 0},i,(e(32,n),e(2,R))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(14,s=(n==null?void 0:n.drawingMode)||g),r.$$.dirty[0]&16&&e(13,o=a_(E)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=h_(E,N),a,(e(11,l),e(4,E))),r.$$.dirty[1]&4&&L(d.selected),r.$$.dirty[0]&32&&e(6,h=O?O.map(z=>({annotation:z,editor:da(z.target.selector)})).filter(z=>z.editor):void 0),r.$$.dirty[0]&64&&e(10,c=z=>h&&h.some(wt=>wt.annotation.id===z.id))},[v,C,R,P,E,O,h,M,T,S,c,l,a,o,s,i,u,p,f,B,D,N,$,F,X,y,g,b,A,k,U,I,n,d,V,dt,yt]}class b_ extends pe{constructor(t){super(),fe(this,t,v_,__,qt,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function Jc(r,t,e=0,i=r.length-1,n=x_){for(;i>e;){if(i-e>600){const l=i-e+1,h=t-e+1,c=Math.log(l),u=.5*Math.exp(2*c/3),d=.5*Math.sqrt(c*u*(l-u)/l)*(h-l/2<0?-1:1),p=Math.max(e,Math.floor(t-h*u/l+d)),f=Math.min(i,Math.floor(t+(l-h)*u/l+d));Jc(r,t,p,f,n)}const s=r[t];let o=e,a=i;for(bn(r,e,t),n(r[i],s)>0&&bn(r,e,i);o<a;){for(bn(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?bn(r,e,a):(a++,bn(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function bn(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function x_(r,t){return r<t?-1:r>t?1:0}class w_{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 e=this.data;const i=[];if(!_s(t,e))return i;const n=this.toBBox,s=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?n(a):a;_s(t,l)&&(e.leaf?i.push(a):ya(t,l)?this._all(a,i):s.push(a))}e=s.pop()}return i}collides(t){let e=this.data;if(!_s(t,e))return!1;const i=[];for(;e;){for(let n=0;n<e.children.length;n++){const s=e.children[n],o=e.leaf?this.toBBox(s):s;if(_s(t,o)){if(e.leaf||ya(t,o))return!0;i.push(s)}}e=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const i=this.data;this.data=e,e=i}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Mi([]),this}remove(t,e){if(!t)return this;let i=this.data;const n=this.toBBox(t),s=[],o=[];let a,l,h;for(;i||s.length;){if(i||(i=s.pop(),l=s[s.length-1],a=o.pop(),h=!0),i.leaf){const c=E_(t,i.children,e);if(c!==-1)return i.children.splice(c,1),s.push(i),this._condense(s),this}!h&&!i.leaf&&ya(i,n)?(s.push(i),o.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],h=!1):i=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,n){const s=i-e+1;let o=this._maxEntries,a;if(s<=o)return a=Mi(t.slice(e,i+1)),Ri(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=Mi([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));Qc(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);Qc(t,c,u,l,this.compareMinY);for(let d=c;d<=u;d+=l){const p=Math.min(d+l-1,u);a.children.push(this._build(t,d,p,n-1))}}return Ri(a,this.toBBox),a}_chooseSubtree(t,e,i,n){for(;n.push(e),!(e.leaf||n.length-1===i);){let s=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],c=ga(h),u=S_(t,h)-c;u<o?(o=u,s=c<s?c:s,a=h):u===o&&c<s&&(s=c,a=h)}e=a||e.children[0]}return e}_insert(t,e,i){const n=i?t:this.toBBox(t),s=[],o=this._chooseSubtree(n,this.data,e,s);for(o.children.push(t),wn(o,n);e>=0&&s[e].children.length>this._maxEntries;)this._split(s,e),e--;this._adjustParentBBoxes(n,s,e)}_split(t,e){const i=t[e],n=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,n);const o=this._chooseSplitIndex(i,s,n),a=Mi(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Ri(i,this.toBBox),Ri(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Mi([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Ri(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let n,s=1/0,o=1/0;for(let a=e;a<=i-e;a++){const l=xn(t,0,a,this.toBBox),h=xn(t,a,i,this.toBBox),c=C_(l,h),u=ga(l)+ga(h);c<s?(s=c,n=a,o=u<o?u:o):c===s&&u<o&&(o=u,n=a)}return n||i-e}_chooseSplitAxis(t,e,i){const n=t.leaf?this.compareMinX:T_,s=t.leaf?this.compareMinY:A_,o=this._allDistMargin(t,e,i,n),a=this._allDistMargin(t,e,i,s);o<a&&t.children.sort(n)}_allDistMargin(t,e,i,n){t.children.sort(n);const s=this.toBBox,o=xn(t,0,e,s),a=xn(t,i-e,i,s);let l=ys(o)+ys(a);for(let h=e;h<i-e;h++){const c=t.children[h];wn(o,t.leaf?s(c):c),l+=ys(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];wn(a,t.leaf?s(c):c),l+=ys(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)wn(e[n],t)}_condense(t){for(let e=t.length-1,i;e>=0;e--)t[e].children.length===0?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():Ri(t[e],this.toBBox)}}function E_(r,t,e){if(!e)return t.indexOf(r);for(let i=0;i<t.length;i++)if(e(r,t[i]))return i;return-1}function Ri(r,t){xn(r,0,r.children.length,t,r)}function xn(r,t,e,i,n){n||(n=Mi(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(let s=t;s<e;s++){const o=r.children[s];wn(n,r.leaf?i(o):o)}return n}function wn(r,t){return r.minX=Math.min(r.minX,t.minX),r.minY=Math.min(r.minY,t.minY),r.maxX=Math.max(r.maxX,t.maxX),r.maxY=Math.max(r.maxY,t.maxY),r}function T_(r,t){return r.minX-t.minX}function A_(r,t){return r.minY-t.minY}function ga(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function ys(r){return r.maxX-r.minX+(r.maxY-r.minY)}function S_(r,t){return(Math.max(t.maxX,r.maxX)-Math.min(t.minX,r.minX))*(Math.max(t.maxY,r.maxY)-Math.min(t.minY,r.minY))}function C_(r,t){const e=Math.max(r.minX,t.minX),i=Math.max(r.minY,t.minY),n=Math.min(r.maxX,t.maxX),s=Math.min(r.maxY,t.maxY);return Math.max(0,n-e)*Math.max(0,s-i)}function ya(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function _s(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Mi(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Qc(r,t,e,i,n){const s=[t,e];for(;s.length;){if(e=s.pop(),t=s.pop(),e-t<=i)continue;const o=t+Math.ceil((e-t)/i/2)*i;Jc(r,o,t,e,n),s.push(t,o,o,e)}}const I_=()=>{const r=new w_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!cs(o))return;const{minX:a,minY:l,maxX:h,maxY:c}=o.selector.geometry.bounds,u={minX:a,minY:l,maxX:h,maxY:c,target:o};r.insert(u),t.set(o.annotation,u)},s=o=>{if(!cs(o))return;const a=t.get(o.annotation);a&&r.remove(a),t.delete(o.annotation)};return{all:e,clear:i,getAt:(o,a,l=0)=>{const h=r.search({minX:o-l,minY:a-l,maxX:o+l,maxY:a+l}).map(c=>c.target).filter(c=>c.selector.type===mt.RECTANGLE||Fg(c.selector,o,a,l));return h.length>0?(h.sort((c,u)=>qo(c.selector)-qo(u.selector)),h):[]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(c=>c.target),insert:n,remove:s,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,c)=>{if(cs(c)){const{minX:u,minY:d,maxX:p,maxY:f}=c.selector.geometry.bounds;return[...h,{minX:u,minY:d,maxX:p,maxY:f,target:c}]}else return h},[]);l.forEach(h=>t.set(h.target.annotation,h)),r.load(l)},size:()=>r.all().length,update:(o,a)=>{s(o),n(a)}}},tu=r=>{const t=Cy(),e=I_(),i=fy(t,r.userSelectAction,r.adapter),n=dy(t),s=Dy();return t.observe(({changes:o})=>{e.set((o.created||[]).map(a=>a.target),!1),(o.deleted||[]).forEach(a=>e.remove(a.target)),(o.updated||[]).forEach(({oldValue:a,newValue:l})=>e.update(a.target,l.target))}),{store:{...t,getAt:(o,a,l,h)=>{const c=e.getAt(o,a,h);if(l)return c.map(u=>t.getAnnotation(u.annotation)).filter(Boolean).filter(l)[0];{const u=c[0];return u?t.getAnnotation(u.annotation):void 0}},getIntersecting:(o,a,l,h)=>e.getIntersecting(o,a,l,h).map(c=>t.getAnnotation(c.annotation)).filter(Boolean)},selection:i,hover:n,viewport:s}},P_=r=>{const t=tu(r);return{...t,store:Iy(t.store)}},R_=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const n=r;t=document.createElement("canvas"),t.width=n.width,t.height=n.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(n,0,0,n.width,n.height)}let i=0;for(let n=1;n<10;n++)for(let s=1;s<10;s++){const o=Math.round(s*t.width/10),a=Math.round(n*t.height/10),l=e.getImageData(o,a,1,1).data,h=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=h}return i/81},eu=r=>{const t=R_(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},ru=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?eu(r):e),iu=(r,t)=>({...r,drawingEnabled:r.drawingEnabled===void 0?t.drawingEnabled:r.drawingEnabled,drawingMode:r.drawingMode||t.drawingMode,userSelectAction:r.userSelectAction||t.userSelectAction,theme:r.theme||t.theme}),nu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,su=(r,t)=>{const e=t||document,i=o=>{const a=o;a.key==="z"&&a.ctrlKey?r.undo():a.key==="y"&&a.ctrlKey&&r.redo()},n=o=>{const a=o;a.key==="z"&&a.metaKey&&(a.shiftKey?r.redo():r.undo())},s=()=>{nu?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return nu?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},M_=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=iu(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:hc.EDIT,theme:"light"}),n=P_(i),{selection:s,store:o}=n,a=My(o,i.initialHistory),l=Oy(n,a,i.adapter,i.autoSave),h=document.createElement("DIV");h.style.position="relative",h.style.display="inline-block",e.style.display="block",e.parentNode.insertBefore(h,e),h.appendChild(e);const c=su(a);let u=Xy();ru(e,h,i.theme);const d=new b_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",I=>{const{originalEvent:T,annotation:E}=I.detail;E?s.userSelect(E.id,T):s.isEmpty()||s.clear()});const p=By(n,a,i.adapter),f=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},_=()=>d.getDrawingTool(),v=()=>u,y=()=>d.isDrawingEnabled(),g=(I,T,E)=>Uc(I,T,E),b=(I,T)=>Bc(I,T),C=I=>{if(!gs(I))throw`No drawing tool named ${I}`;d.$set({toolName:I})},R=I=>d.$set({drawingEnabled:I}),A=I=>{console.warn("Filter not implemented yet")},P=I=>d.$set({style:I}),M=I=>ru(e,h,I),k=I=>{u=I,d.$set({user:I})},U=I=>d.$set({visible:I});return{...p,cancelDrawing:f,destroy:m,getDrawingTool:_,getUser:v,isDrawingEnabled:y,listDrawingTools:ms,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:b,setDrawingEnabled:R,setDrawingTool:C,setFilter:A,setStyle:P,setTheme:M,setUser:k,setVisible:U,element:h,state:n}};function Ft(){}function _a(r,t){for(const e in t)r[e]=t[e];return r}function ou(r){return r()}function au(){return Object.create(null)}function Ne(r){r.forEach(ou)}function Kt(r){return typeof r=="function"}function Ut(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function D_(r){return Object.keys(r).length===0}function O_(r,...t){if(r==null){for(const i of t)i(void 0);return Ft}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function vs(r,t,e){r.$$.on_destroy.push(O_(t,e))}function lu(r,t,e,i){if(r){const n=hu(r,t,e,i);return r[0](n)}}function hu(r,t,e,i){return r[1]&&i?_a(e.ctx.slice(),r[1](i(t))):e.ctx}function cu(r,t,e,i){if(r[2]&&i){const n=r[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const s=[],o=Math.max(t.dirty.length,n.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|n[a];return s}return t.dirty|n}return t.dirty}function uu(r,t,e,i,n,s){if(n){const o=hu(t,e,i,s);r.p(o,n)}}function du(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function fu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}const va=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function At(r,t){r.appendChild(t)}function st(r,t,e){r.insertBefore(t,e||null)}function nt(r){r.parentNode&&r.parentNode.removeChild(r)}function Dr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function et(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function ba(r){return document.createTextNode(r)}function Se(){return ba(" ")}function Pe(){return ba("")}function Rt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function w(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function L_(r){return Array.from(r.childNodes)}function B_(r,t){t=""+t,r.data!==t&&(r.data=t)}function Or(r,t,e){r.classList.toggle(t,!!e)}function N_(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let En;function Tn(r){En=r}function xa(){if(!En)throw new Error("Function called outside component initialization");return En}function ei(r){xa().$$.on_mount.push(r)}function F_(r){xa().$$.on_destroy.push(r)}function Di(){const r=xa();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=N_(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function ye(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Oi=[],bs=[];let Li=[];const pu=[],mu=Promise.resolve();let wa=!1;function gu(){wa||(wa=!0,mu.then(_u))}function yu(){return gu(),mu}function Ea(r){Li.push(r)}const Ta=new Set;let Bi=0;function _u(){if(Bi!==0)return;const r=En;do{try{for(;Bi<Oi.length;){const t=Oi[Bi];Bi++,Tn(t),k_(t.$$)}}catch(t){throw Oi.length=0,Bi=0,t}for(Tn(null),Oi.length=0,Bi=0;bs.length;)bs.pop()();for(let t=0;t<Li.length;t+=1){const e=Li[t];Ta.has(e)||(Ta.add(e),e())}Li.length=0}while(Oi.length);for(;pu.length;)pu.pop()();wa=!1,Ta.clear(),Tn(r)}function k_(r){if(r.fragment!==null){r.update(),Ne(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Ea)}}function U_(r){const t=[],e=[];Li.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Li=t}const xs=new Set;let ri;function ne(){ri={r:0,c:[],p:ri}}function se(){ri.r||Ne(ri.c),ri=ri.p}function q(r,t){r&&r.i&&(xs.delete(r),r.i(t))}function ot(r,t,e,i){if(r&&r.o){if(xs.has(r))return;xs.add(r),ri.c.push(()=>{xs.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function xe(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Bt(r){r&&r.c()}function Ot(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Ea(()=>{const s=r.$$.on_mount.map(ou).filter(Kt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Ne(s),r.$$.on_mount=[]}),n.forEach(Ea)}function Lt(r,t){const e=r.$$;e.fragment!==null&&(U_(e.after_update),Ne(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function G_(r,t){r.$$.dirty[0]===-1&&(Oi.push(r),gu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function zt(r,t,e,i,n,s,o=null,a=[-1]){const l=En;Tn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Ft,not_equal:n,bound:au(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:au(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let c=!1;if(h.ctx=e?e(r,t.props||{},(u,d,...p)=>{const f=p.length?p[0]:d;return h.ctx&&n(h.ctx[u],h.ctx[u]=f)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](f),c&&G_(r,u)),d}):[],h.update(),c=!0,Ne(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=L_(t.target);h.fragment&&h.fragment.l(u),u.forEach(nt)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Ot(r,t.target,t.anchor),_u()}Tn(l)}class jt{constructor(){Oh(this,"$$");Oh(this,"$$set")}$destroy(){Lt(this,1),this.$destroy=Ft}$on(t,e){if(!Kt(e))return Ft;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!D_(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $_="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($_);var Je=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(Je||{}),An=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Aa(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function H_(r){if(r.__esModule)return r;var t=r.default;if(typeof t=="function"){var e=function i(){return this instanceof i?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(r).forEach(function(i){var n=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return r[i]}})}),e}var vu={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,c=a.y-l.y;return h*h+c*c}function e(a,l,h){var c=l.x,u=l.y,d=h.x-c,p=h.y-u;if(d!==0||p!==0){var f=((a.x-c)*d+(a.y-u)*p)/(d*d+p*p);f>1?(c=h.x,u=h.y):f>0&&(c+=d*f,u+=p*f)}return d=a.x-c,p=a.y-u,d*d+p*p}function i(a,l){for(var h=a[0],c=[h],u,d=1,p=a.length;d<p;d++)u=a[d],t(u,h)>l&&(c.push(u),h=u);return h!==u&&c.push(u),c}function n(a,l,h,c,u){for(var d=c,p,f=l+1;f<h;f++){var m=e(a[f],a[l],a[h]);m>d&&(p=f,d=m)}d>c&&(p-l>1&&n(a,l,p,c,u),u.push(a[p]),h-p>1&&n(a,p,h,c,u))}function s(a,l){var h=a.length-1,c=[a[0]];return n(a,0,h,l,c),c.push(a[h]),c}function o(a,l,h){if(a.length<=2)return a;var c=l!==void 0?l*l:1;return a=h?a:i(a,c),a=s(a,c),a}r.exports=o,r.exports.default=o})()})(vu);var X_=vu.exports;const V_=Aa(X_),Ni=(r,t)=>t,Qe=r=>{let t=1/0,e=1/0,i=-1/0,n=-1/0;return r.forEach(([s,o])=>{t=Math.min(t,s),e=Math.min(e,o),i=Math.max(i,s),n=Math.max(n,o)}),{minX:t,minY:e,maxX:i,maxY:n}},ws=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},Es=(r,t,e)=>{let i=!1;for(let n=0,s=r.length-1;n<r.length;s=n++){const o=r[n][0],a=r[n][1],l=r[s][0],h=r[s][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},z_=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},bu=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return V_(e,t,!0).map(i=>[i.x,i.y])},j_=(r,t)=>{const e=Math.abs(t[0]-r[0]),i=Math.abs(t[1]-r[1]);return Math.sqrt(Math.pow(e,2)+Math.pow(i,2))},W_={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:n,rx:s,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),c=t-i,u=e-n,d=l*c+h*u,p=h*c-l*u;return d*d/(s*s)+p*p/(o*o)<=1}};Ni(Je.ELLIPSE,W_);const Y_={area:r=>0,intersects:(r,t,e,i=2)=>{const[[n,s],[o,a]]=r.geometry.points,l=Math.abs((a-s)*t-(o-n)*e+o*s-a*n),h=j_([n,s],[o,a]);return l/h<=i}};Ni(Je.LINE,Y_);const q_={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=ws(n.points),a=s.reduce((l,h)=>l+ws(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const n of i){const[s,...o]=n.rings;if(Es(s.points,t,e)){let a=!1;for(const l of o)if(Es(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Ts=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Qe(t)},Fi=r=>r.rings.map(e=>z_(e.points)).join(" "),K_=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),Z_=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=bu(a.points,t);return{...a,points:l}}),o=Qe(s[0].points);return{...n,rings:s,bounds:o}}),i=Ts(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Ni(Je.MULTIPOLYGON,q_);const J_={area:r=>{const t=r.geometry.points;return ws(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Es(i,t,e)}},Q_=(r,t=1)=>{const e=bu(r.geometry.points,t),i=Qe(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Ni(Je.POLYGON,J_);const tv={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=xu(t.points,t.closed);return ws(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=xu(n.points,n.closed);return Es(s,t,e)}else return ev(n,[t,e],i)}},xu=(r,t=!1)=>{const e=[];for(let i=0;i<r.length;i++){const n=r[i],s=r[(i+1)%r.length];if(e.push(n.point),(i<r.length-1||t)&&(n.type==="CURVE"||s.type=="CURVE")){const a=wu(n.point,n.outHandle||n.point,s.inHandle||s.point,s.point,10);e.push(...a.slice(1))}}return e},wu=(r,t,e,i,n=10)=>{const s=[];for(let o=0;o<=n;o++){const a=o/n,l=Math.pow(1-a,3)*r[0]+3*Math.pow(1-a,2)*a*t[0]+3*(1-a)*Math.pow(a,2)*e[0]+Math.pow(a,3)*i[0],h=Math.pow(1-a,3)*r[1]+3*Math.pow(1-a,2)*a*t[1]+3*(1-a)*Math.pow(a,2)*e[1]+Math.pow(a,3)*i[1];s.push([l,h])}return s},ev=(r,t,e)=>{for(let i=0;i<r.points.length-1;i++){const n=r.points[i],s=r.points[i+1];if(n.outHandle||s.inHandle){const a=wu(n.point,n.outHandle||n.point,s.inHandle||s.point,s.point,20);for(let l=0;l<a.length-1;l++)if(Eu(t,a[l],a[l+1])<=e)return!0}else if(Eu(t,n.point,s.point)<=e)return!0}return!1},Eu=(r,t,e)=>{const[i,n]=r,[s,o]=t,[a,l]=e,h=a-s,c=l-o,u=Math.sqrt(h*h+c*c);if(u===0)return Math.sqrt((i-s)*(i-s)+(n-o)*(n-o));const d=((i-s)*h+(n-o)*c)/(u*u);return d<=0?Math.sqrt((i-s)*(i-s)+(n-o)*(n-o)):d>=1?Math.sqrt((i-a)*(i-a)+(n-l)*(n-l)):Math.abs((l-o)*i-(a-s)*n+a*o-l*s)/u};Ni(Je.POLYLINE,tv);const rv={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};Ni(Je.RECTANGLE,rv);const _e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function iv(r,t=0){return(_e[r[t+0]]+_e[r[t+1]]+_e[r[t+2]]+_e[r[t+3]]+"-"+_e[r[t+4]]+_e[r[t+5]]+"-"+_e[r[t+6]]+_e[r[t+7]]+"-"+_e[r[t+8]]+_e[r[t+9]]+"-"+_e[r[t+10]]+_e[r[t+11]]+_e[r[t+12]]+_e[r[t+13]]+_e[r[t+14]]+_e[r[t+15]]).toLowerCase()}let Sa;const nv=new Uint8Array(16);function sv(){if(!Sa){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Sa=crypto.getRandomValues.bind(crypto)}return Sa(nv)}const Tu={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ov(r,t,e){var n;if(Tu.randomUUID&&!r)return Tu.randomUUID();r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??sv();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,iv(i)}const av=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:n,stroke:s,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${n||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},Ca=(r,t=0)=>{const{minX:e,minY:i,maxX:n,maxY:s}=r;return{x:e-t,y:i-t,w:n-e+2*t,h:s-i+2*t}},Lr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,lv=r=>({}),Au=r=>({grab:r[0]});function hv(r){let t,e,i,n;const s=r[8].default,o=lu(s,r,r[7],Au);return{c(){t=et("g"),o&&o.c(),w(t,"class","a9s-annotation selected")},m(a,l){st(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Rt(t,"pointerup",r[2]),Rt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&uu(o,s,a,a[7],e?cu(s,a[7],l,lv):du(a[7]),Au)},i(a){e||(q(o,a),e=!0)},o(a){ot(o,a),e=!1},d(a){a&&nt(t),o&&o.d(a),i=!1,Ne(n)}}}function cv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Di();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const p=_=>v=>{if(c=_,h){const{left:g,top:b}=h.getBoundingClientRect(),C=v.clientX-g,R=v.clientY-b;u=l.elementToImage(C,R)}else{const{offsetX:g,offsetY:b}=v;u=l.elementToImage(g,b)}d=o,v.target.setPointerCapture(v.pointerId),s("grab",v)},f=_=>{if(c){const[v,y]=l.elementToImage(_.offsetX,_.offsetY),g=[v-u[0],y-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=_=>{_.target.releasePointerCapture(_.pointerId),c=void 0,d=o,s("release",_)};return r.$$set=_=>{"shape"in _&&e(3,o=_.shape),"editor"in _&&e(4,a=_.editor),"transform"in _&&e(5,l=_.transform),"svgEl"in _&&e(6,h=_.svgEl),"$$scope"in _&&e(7,n=_.$$scope)},[p,f,m,o,a,l,h,n,i]}class Ia extends jt{constructor(t){super(),zt(this,t,cv,hv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function uv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Su(r);return{c(){t=et("g"),e=et("circle"),h&&h.c(),n=et("circle"),w(e,"class","a9s-handle-buffer"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]+6/r[2]),w(e,"role","button"),w(e,"tabindex","0"),w(n,"class",s=`a9s-handle-dot${r[3]?" selected":""}`),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",r[5]),w(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){st(c,t,u),At(t,e),h&&h.m(t,null),At(t,n),a||(l=[Rt(e,"dblclick",r[11]),Rt(e,"pointerenter",r[12]),Rt(e,"pointerleave",r[13]),Rt(e,"pointerdown",r[14]),Rt(e,"pointerdown",r[6]),Rt(e,"pointerup",r[15]),Rt(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&w(e,"cx",c[0]),u&2&&w(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&w(e,"r",i),c[3]?h?h.p(c,u):(h=Su(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=`a9s-handle-dot${c[3]?" selected":""}`)&&w(n,"class",s),u&1&&w(n,"cx",c[0]),u&2&&w(n,"cy",c[1]),u&32&&w(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&w(t,"class",o)},d(c){c&&nt(t),h&&h.d(),a=!1,Ne(l)}}}function dv(r){let t,e,i,n,s,o,a,l,h;return{c(){t=et("g"),e=et("circle"),n=et("circle"),o=et("circle"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]*10),w(e,"class","a9s-touch-halo"),Or(e,"touched",r[4]),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",s=r[5]+10/r[2]),w(n,"class","a9s-handle-buffer"),w(o,"class","a9s-handle-dot"),w(o,"cx",r[0]),w(o,"cy",r[1]),w(o,"r",a=r[5]+2/r[2]),w(t,"class","a9s-touch-handle")},m(c,u){st(c,t,u),At(t,e),At(t,n),At(t,o),l||(h=[Rt(n,"pointerdown",r[9]),Rt(n,"pointerup",r[10]),Rt(n,"pointerdown",r[6]),Rt(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&w(e,"cx",c[0]),u&2&&w(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&w(e,"r",i),u&16&&Or(e,"touched",c[4]),u&1&&w(n,"cx",c[0]),u&2&&w(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&w(n,"r",s),u&1&&w(o,"cx",c[0]),u&2&&w(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&w(o,"r",a)},d(c){c&&nt(t),l=!1,Ne(h)}}}function Su(r){let t,e;return{c(){t=et("circle"),w(t,"class","a9s-handle-selected"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",e=r[5]+8/r[2])},m(i,n){st(i,t,n)},p(i,n){n&1&&w(t,"cx",i[0]),n&2&&w(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&w(t,"r",e)},d(i){i&&nt(t)}}}function fv(r){let t;function e(s,o){return Lr?dv:uv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),st(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&nt(t),n.d(s)}}}function pv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=y=>{y.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(y){ye.call(this,r,y)}function d(y){ye.call(this,r,y)}function p(y){ye.call(this,r,y)}function f(y){ye.call(this,r,y)}function m(y){ye.call(this,r,y)}function _(y){ye.call(this,r,y)}function v(y){ye.call(this,r,y)}return r.$$set=y=>{e(8,t=_a(_a({},t),fu(y))),"x"in y&&e(0,n=y.x),"y"in y&&e(1,s=y.y),"scale"in y&&e(2,o=y.scale),"selected"in y&&e(3,a=y.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=fu(t),[n,s,o,a,l,i,h,c,t,u,d,p,f,m,_,v]}class ki extends jt{constructor(t){super(),zt(this,t,pv,fv,Ut,{x:0,y:1,scale:2,selected:3})}}function mv(r){let t,e,i,n,s,o,a;return{c(){t=et("g"),e=et("circle"),n=et("circle"),s=et("circle"),w(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=1.75*r[2]),w(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",r[2]),w(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),w(s,"cx",r[0]),w(s,"cy",r[1]),w(s,"r",r[2]),w(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){st(l,t,h),At(t,e),At(t,n),At(t,s),o||(a=[Rt(e,"pointerdown",r[5]),Rt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&w(e,"cx",l[0]),h&2&&w(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&w(e,"r",i),h&1&&w(n,"cx",l[0]),h&2&&w(n,"cy",l[1]),h&4&&w(n,"r",l[2]),h&1&&w(s,"cx",l[0]),h&2&&w(s,"cy",l[1]),h&4&&w(s,"r",l[2])},d(l){l&&nt(t),o=!1,Ne(a)}}}function gv(r){let t;return{c(){t=et("circle"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",r[2])},m(e,i){st(e,t,i)},p(e,i){i&1&&w(t,"cx",e[0]),i&2&&w(t,"cy",e[1]),i&4&&w(t,"r",e[2])},d(e){e&&nt(t)}}}function yv(r){let t;function e(s,o){return Lr?gv:mv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),st(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&nt(t),n.d(s)}}}function _v(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){ye.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,n=h.x),"y"in h&&e(1,s=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[n,s,i,a,o,l]}class Cu extends jt{constructor(t){super(),zt(this,t,_v,yv,Ut,{x:0,y:1,scale:4})}}function Pa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Iu(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Ra(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ma(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Pu(r){let t,e,i,n;return{c(){t=et("circle"),w(t,"cx",e=r[28][0]),w(t,"cy",i=r[28][1]),w(t,"r",n=Sn/r[3]),w(t,"class","svelte-1h2slbm")},m(s,o){st(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&w(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&w(t,"cy",i),o[0]&8&&n!==(n=Sn/s[3])&&w(t,"r",n)},d(s){s&&nt(t)}}}function Ru(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=et("mask"),e=et("rect"),a=et("circle"),w(e,"x",i=r[9].x),w(e,"y",n=r[9].y),w(e,"width",s=r[9].w),w(e,"height",o=r[9].h),w(e,"class","svelte-1h2slbm"),w(a,"cx",l=r[28][0]),w(a,"cy",h=r[28][1]),w(a,"r",c=Sn/r[3]),w(a,"class","svelte-1h2slbm"),w(t,"id",`${r[19]}-inner`),w(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){st(u,t,d),At(t,e),At(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&w(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&w(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&w(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&w(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&w(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&w(a,"cy",h),d[0]&8&&c!==(c=Sn/u[3])&&w(a,"r",c)},d(u){u&&nt(t)}}}function Mu(r){let t,e;return t=new ki({props:{class:"a9s-corner-handle",x:r[28][0],y:r[28][1],scale:r[3],selected:r[8].includes(r[30])}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[15]),t.$on("pointerdown",function(){Kt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}function Du(r){let t,e;return t=new Cu({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Kt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}function vv(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y,g,b,C,R=r[6]!==void 0&&!r[7]&&Pu(Ma(r)),A=r[6]!==void 0&&!r[7]&&Ru(Ra(r)),P=xe(r[5].points),M=[];for(let I=0;I<P.length;I+=1)M[I]=Mu(Iu(r,P,I));const k=I=>ot(M[I],1,1,()=>{M[I]=null});let U=r[6]!==void 0&&!r[7]&&Du(Pa(r));return{c(){t=et("defs"),e=et("mask"),i=et("rect"),l=et("polygon"),R&&R.c(),A&&A.c(),c=Se(),u=et("polygon"),p=Se(),f=et("polygon"),_=Se();for(let I=0;I<M.length;I+=1)M[I].c();v=Se(),U&&U.c(),y=Pe(),w(i,"x",n=r[9].x),w(i,"y",s=r[9].y),w(i,"width",o=r[9].w),w(i,"height",a=r[9].h),w(i,"class","svelte-1h2slbm"),w(l,"points",h=r[5].points.map(Ou).join(" ")),w(l,"class","svelte-1h2slbm"),w(e,"id",`${r[19]}-outer`),w(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),w(u,"class","a9s-outer"),w(u,"mask",`url(#${r[19]}-outer)`),w(u,"points",d=r[5].points.map(Lu).join(" ")),w(f,"class","a9s-inner a9s-shape-handle"),w(f,"mask",`url(#${r[19]}-inner)`),w(f,"style",r[1]),w(f,"points",m=r[5].points.map(Bu).join(" "))},m(I,T){st(I,t,T),At(t,e),At(e,i),At(e,l),R&&R.m(e,null),A&&A.m(t,null),st(I,c,T),st(I,u,T),st(I,p,T),st(I,f,T),st(I,_,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(I,T);st(I,v,T),U&&U.m(I,T),st(I,y,T),g=!0,b||(C=[Rt(u,"pointerup",r[14]),Rt(u,"pointerdown",function(){Kt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Rt(f,"pointermove",r[13]),Rt(f,"pointerup",r[14]),Rt(f,"pointerdown",function(){Kt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(I,T){if(r=I,(!g||T[0]&512&&n!==(n=r[9].x))&&w(i,"x",n),(!g||T[0]&512&&s!==(s=r[9].y))&&w(i,"y",s),(!g||T[0]&512&&o!==(o=r[9].w))&&w(i,"width",o),(!g||T[0]&512&&a!==(a=r[9].h))&&w(i,"height",a),(!g||T[0]&32&&h!==(h=r[5].points.map(Ou).join(" ")))&&w(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Ma(r),T):(R=Pu(Ma(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?A?A.p(Ra(r),T):(A=Ru(Ra(r)),A.c(),A.m(t,null)):A&&(A.d(1),A=null),(!g||T[0]&32&&d!==(d=r[5].points.map(Lu).join(" ")))&&w(u,"points",d),(!g||T[0]&2)&&w(f,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Bu).join(" ")))&&w(f,"points",m),T[0]&134322472){P=xe(r[5].points);let E;for(E=0;E<P.length;E+=1){const S=Iu(r,P,E);M[E]?(M[E].p(S,T),q(M[E],1)):(M[E]=Mu(S),M[E].c(),q(M[E],1),M[E].m(v.parentNode,v))}for(ne(),E=P.length;E<M.length;E+=1)k(E);se()}r[6]!==void 0&&!r[7]?U?(U.p(Pa(r),T),T[0]&192&&q(U,1)):(U=Du(Pa(r)),U.c(),q(U,1),U.m(y.parentNode,y)):U&&(ne(),ot(U,1,1,()=>{U=null}),se())},i(I){if(!g){for(let T=0;T<P.length;T+=1)q(M[T]);q(U),g=!0}},o(I){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)ot(M[T]);ot(U),g=!1},d(I){I&&(nt(t),nt(c),nt(u),nt(p),nt(f),nt(_),nt(v),nt(y)),R&&R.d(),A&&A.d(),Dr(M,I),U&&U.d(I),b=!1,Ne(C)}}}function bv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[vv,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}const xv=250,wv=1e3,Ev=12,Sn=4.5,Ou=r=>r.join(","),Lu=r=>r.join(","),Bu=r=>r.join(",");function Tv(r,t,e){let i,n,s;const o=Di();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const _=()=>e(7,p=!0),v=()=>e(7,p=!1),y=E=>{if(m.length>0||!n.some($=>$.visible)){e(6,d=void 0);return}const[S,B]=h.elementToImage(E.offsetX,E.offsetY),D=$=>Math.pow($[0]-S,2)+Math.pow($[1]-B,2),N=i.points.reduce(($,F)=>D(F)<D($)?F:$),H=n.filter($=>$.visible).reduce(($,F)=>D(F.point)<D($.point)?F:$),O=Math.pow(wv/c,2);D(N)<O||D(H.point)<O?e(6,d=n.indexOf(H)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},C=E=>{e(7,p=!0),E.preventDefault(),E.stopPropagation(),f=performance.now()},R=E=>S=>{if(!f||Lr||performance.now()-f>xv)return;const B=m.includes(E);S.metaKey||S.ctrlKey||S.shiftKey?B?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):B&&m.length>1?e(8,m=[E]):B?e(8,m=[]):e(8,m=[E]),g()},A=(E,S,B)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,L],$)=>m.includes($)?[O+B[0],L+B[1]]:[O,L]):S==="SHAPE"?D=N.points.map(([O,L])=>[O+B[0],L+B[1]]):D=N.points.map(([O,L],$)=>S===`HANDLE-${$}`?[O+B[0],L+B[1]]:[O,L]);const H=Qe(D);return{...E,geometry:{points:D,bounds:H}}},P=E=>async S=>{S.stopPropagation();const B=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=Qe(B);o("change",{...a,geometry:{points:B,bounds:D}}),await yu();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:S.clientX,clientY:S.clientY,pointerId:S.pointerId,pointerType:S.pointerType,isPrimary:S.isPrimary,buttons:S.buttons});N.firstChild.dispatchEvent(H)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((B,D)=>!m.includes(D)),S=Qe(E);o("change",{...a,geometry:{points:E,bounds:S}}),e(8,m=[])};ei(()=>{if(Lr)return;const E=S=>{(S.key==="Delete"||S.key==="Backspace")&&(S.preventDefault(),M())};return u.addEventListener("pointermove",y),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",y),u.removeEventListener("keydown",E)}});const k=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){ye.call(this,r,E)}function I(E){ye.call(this,r,E)}function T(E){ye.call(this,r,E)}return r.$$set=E=>{"shape"in E&&e(0,a=E.shape),"computedStyle"in E&&e(1,l=E.computedStyle),"transform"in E&&e(2,h=E.transform),"viewportScale"in E&&e(3,c=E.viewportScale),"svgEl"in E&&e(4,u=E.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Lr?[]:i.points.map((E,S)=>{const B=S===i.points.length-1?i.points[0]:i.points[S+1],D=(E[0]+B[0])/2,N=(E[1]+B[1])/2,O=Math.sqrt(Math.pow(B[0]-D,2)+Math.pow(B[1]-N,2))>Ev/c;return{point:[D,N],visible:O}})),r.$$.dirty[0]&40&&e(9,s=Ca(i.bounds,Sn/c))},[a,l,h,c,u,i,d,p,m,s,n,_,v,y,b,C,R,A,P,k,U,I,T]}class Av extends jt{constructor(t){super(),zt(this,t,Tv,bv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Sv(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y,g,b,C,R,A,P,M,k,U,I,T,E,S,B,D,N,H,O,L,$,F,X,V,dt,yt,z,wt,it,ft,_t,Pt,Dt,he,Vt,Q,Ge,Jn;return it=new ki({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),it.$on("pointerdown",function(){Kt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),_t=new ki({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),_t.$on("pointerdown",function(){Kt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new ki({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Dt.$on("pointerdown",function(){Kt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new ki({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Kt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=et("defs"),e=et("mask"),i=et("rect"),l=et("rect"),p=Se(),f=et("rect"),g=Se(),b=et("rect"),M=Se(),k=et("rect"),E=Se(),S=et("rect"),H=Se(),O=et("rect"),X=Se(),V=et("rect"),wt=Se(),Bt(it.$$.fragment),ft=Se(),Bt(_t.$$.fragment),Pt=Se(),Bt(Dt.$$.fragment),he=Se(),Bt(Vt.$$.fragment),w(i,"class","rect-mask-bg svelte-1njczvj"),w(i,"x",n=r[6].x),w(i,"y",s=r[6].y),w(i,"width",o=r[6].w),w(i,"height",a=r[6].h),w(l,"class","rect-mask-fg svelte-1njczvj"),w(l,"x",h=r[5].x),w(l,"y",c=r[5].y),w(l,"width",u=r[5].w),w(l,"height",d=r[5].h),w(e,"id",r[8]),w(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),w(f,"class","a9s-outer"),w(f,"mask",`url(#${r[8]})`),w(f,"x",m=r[5].x),w(f,"y",_=r[5].y),w(f,"width",v=r[5].w),w(f,"height",y=r[5].h),w(b,"class","a9s-inner a9s-shape-handle"),w(b,"style",r[1]),w(b,"x",C=r[5].x),w(b,"y",R=r[5].y),w(b,"width",A=r[5].w),w(b,"height",P=r[5].h),w(k,"class","a9s-edge-handle a9s-edge-handle-top"),w(k,"x",U=r[5].x),w(k,"y",I=r[5].y),w(k,"height",1),w(k,"width",T=r[5].w),w(S,"class","a9s-edge-handle a9s-edge-handle-right"),w(S,"x",B=r[5].x+r[5].w),w(S,"y",D=r[5].y),w(S,"height",N=r[5].h),w(S,"width",1),w(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),w(O,"x",L=r[5].x),w(O,"y",$=r[5].y+r[5].h),w(O,"height",1),w(O,"width",F=r[5].w),w(V,"class","a9s-edge-handle a9s-edge-handle-left"),w(V,"x",dt=r[5].x),w(V,"y",yt=r[5].y),w(V,"height",z=r[5].h),w(V,"width",1)},m(Y,G){st(Y,t,G),At(t,e),At(e,i),At(e,l),st(Y,p,G),st(Y,f,G),st(Y,g,G),st(Y,b,G),st(Y,M,G),st(Y,k,G),st(Y,E,G),st(Y,S,G),st(Y,H,G),st(Y,O,G),st(Y,X,G),st(Y,V,G),st(Y,wt,G),Ot(it,Y,G),st(Y,ft,G),Ot(_t,Y,G),st(Y,Pt,G),Ot(Dt,Y,G),st(Y,he,G),Ot(Vt,Y,G),Q=!0,Ge||(Jn=[Rt(f,"pointerdown",function(){Kt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Rt(b,"pointerdown",function(){Kt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Rt(k,"pointerdown",function(){Kt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Rt(S,"pointerdown",function(){Kt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Rt(O,"pointerdown",function(){Kt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Rt(V,"pointerdown",function(){Kt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],Ge=!0)},p(Y,G){r=Y,(!Q||G&64&&n!==(n=r[6].x))&&w(i,"x",n),(!Q||G&64&&s!==(s=r[6].y))&&w(i,"y",s),(!Q||G&64&&o!==(o=r[6].w))&&w(i,"width",o),(!Q||G&64&&a!==(a=r[6].h))&&w(i,"height",a),(!Q||G&32&&h!==(h=r[5].x))&&w(l,"x",h),(!Q||G&32&&c!==(c=r[5].y))&&w(l,"y",c),(!Q||G&32&&u!==(u=r[5].w))&&w(l,"width",u),(!Q||G&32&&d!==(d=r[5].h))&&w(l,"height",d),(!Q||G&32&&m!==(m=r[5].x))&&w(f,"x",m),(!Q||G&32&&_!==(_=r[5].y))&&w(f,"y",_),(!Q||G&32&&v!==(v=r[5].w))&&w(f,"width",v),(!Q||G&32&&y!==(y=r[5].h))&&w(f,"height",y),(!Q||G&2)&&w(b,"style",r[1]),(!Q||G&32&&C!==(C=r[5].x))&&w(b,"x",C),(!Q||G&32&&R!==(R=r[5].y))&&w(b,"y",R),(!Q||G&32&&A!==(A=r[5].w))&&w(b,"width",A),(!Q||G&32&&P!==(P=r[5].h))&&w(b,"height",P),(!Q||G&32&&U!==(U=r[5].x))&&w(k,"x",U),(!Q||G&32&&I!==(I=r[5].y))&&w(k,"y",I),(!Q||G&32&&T!==(T=r[5].w))&&w(k,"width",T),(!Q||G&32&&B!==(B=r[5].x+r[5].w))&&w(S,"x",B),(!Q||G&32&&D!==(D=r[5].y))&&w(S,"y",D),(!Q||G&32&&N!==(N=r[5].h))&&w(S,"height",N),(!Q||G&32&&L!==(L=r[5].x))&&w(O,"x",L),(!Q||G&32&&$!==($=r[5].y+r[5].h))&&w(O,"y",$),(!Q||G&32&&F!==(F=r[5].w))&&w(O,"width",F),(!Q||G&32&&dt!==(dt=r[5].x))&&w(V,"x",dt),(!Q||G&32&&yt!==(yt=r[5].y))&&w(V,"y",yt),(!Q||G&32&&z!==(z=r[5].h))&&w(V,"height",z);const Ar={};G&32&&(Ar.x=r[5].x),G&32&&(Ar.y=r[5].y),G&8&&(Ar.scale=r[3]),it.$set(Ar);const Sr={};G&32&&(Sr.x=r[5].x+r[5].w),G&32&&(Sr.y=r[5].y),G&8&&(Sr.scale=r[3]),_t.$set(Sr);const Cr={};G&32&&(Cr.x=r[5].x+r[5].w),G&32&&(Cr.y=r[5].y+r[5].h),G&8&&(Cr.scale=r[3]),Dt.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x),G&32&&(Ir.y=r[5].y+r[5].h),G&8&&(Ir.scale=r[3]),Vt.$set(Ir)},i(Y){Q||(q(it.$$.fragment,Y),q(_t.$$.fragment,Y),q(Dt.$$.fragment,Y),q(Vt.$$.fragment,Y),Q=!0)},o(Y){ot(it.$$.fragment,Y),ot(_t.$$.fragment,Y),ot(Dt.$$.fragment,Y),ot(Vt.$$.fragment,Y),Q=!1},d(Y){Y&&(nt(t),nt(p),nt(f),nt(g),nt(b),nt(M),nt(k),nt(E),nt(S),nt(H),nt(O),nt(X),nt(V),nt(wt),nt(ft),nt(Pt),nt(he)),Lt(it,Y),Lt(_t,Y),Lt(Dt,Y),Lt(Vt,Y),Ge=!1,Ne(Jn)}}}function Cv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[Sv,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:r}}}),t.$on("grab",r[9]),t.$on("change",r[10]),t.$on("release",r[11]),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}function Iv(r,t,e){let i,n,{shape:s}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const c=(m,_,v)=>{const y=m.geometry.bounds;let[g,b]=[y.minX,y.minY],[C,R]=[y.maxX,y.maxY];const[A,P]=v;if(_==="SHAPE")g+=A,C+=A,b+=P,R+=P;else{switch(_){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=P;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=P;break}}switch(_){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=A;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{C+=A;break}}}const M=Math.min(g,C),k=Math.min(b,R),U=Math.abs(C-g),I=Math.abs(R-b);return{...m,geometry:{x:M,y:k,w:U,h:I,bounds:{minX:M,minY:k,maxX:M+U,maxY:k+I}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){ye.call(this,r,m)}function p(m){ye.call(this,r,m)}function f(m){ye.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,s=m.shape),"computedStyle"in m&&e(1,o=m.computedStyle),"transform"in m&&e(2,a=m.transform),"viewportScale"in m&&e(3,l=m.viewportScale),"svgEl"in m&&e(4,h=m.svgEl)},r.$$.update=()=>{r.$$.dirty&1&&e(5,i=s.geometry),r.$$.dirty&40&&e(6,n=Ca(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,p,f]}class Pv extends jt{constructor(t){super(),zt(this,t,Iv,Cv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Nu=Object.prototype.hasOwnProperty;function Da(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Da(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Nu.call(r,e)&&++i&&!Nu.call(t,e)||!(e in t)||!Da(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const Rv=12,Mv=(r,t)=>r.polygons.reduce((e,i,n)=>{const s=i.rings.reduce((o,a,l)=>{const h=a.points.map((c,u)=>{const d=u===a.points.length-1?a.points[0]:a.points[u+1],p=(c[0]+d[0])/2,f=(c[1]+d[1])/2,_=Math.sqrt(Math.pow(d[0]-p,2)+Math.pow(d[1]-f,2))>Rv/t;return{point:[p,f],visible:_,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function Oa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Fu(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function ku(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Uu(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function La(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ba(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Gu(r){let t,e,i,n;return{c(){t=et("circle"),w(t,"cx",e=r[29][0]),w(t,"cy",i=r[29][1]),w(t,"r",n=Cn/r[3]),w(t,"class","svelte-1vxo6dc")},m(s,o){st(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&w(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&w(t,"cy",i),o[0]&8&&n!==(n=Cn/s[3])&&w(t,"r",n)},d(s){s&&nt(t)}}}function $u(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=et("mask"),e=et("rect"),a=et("circle"),w(e,"x",i=r[9].x),w(e,"y",n=r[9].y),w(e,"width",s=r[9].w),w(e,"height",o=r[9].h),w(e,"class","svelte-1vxo6dc"),w(a,"cx",l=r[29][0]),w(a,"cy",h=r[29][1]),w(a,"r",c=Cn/r[3]),w(a,"class","svelte-1vxo6dc"),w(t,"id",`${r[18]}-${r[32]}-inner`),w(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){st(u,t,d),At(t,e),At(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&w(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&w(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&w(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&w(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&w(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&w(a,"cy",h),d[0]&8&&c!==(c=Cn/u[3])&&w(a,"r",c)},d(u){u&&nt(t)}}}function Hu(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new ki({props:{class:"a9s-corner-handle",x:r[29][0],y:r[29][1],scale:r[3],selected:r[8].some(i)}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[14]),t.$on("pointerdown",function(){Kt(r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`))&&r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`).apply(this,arguments)}),t.$on("pointerup",r[15](r[32],r[35],r[37])),{c(){Bt(t.$$.fragment)},m(n,s){Ot(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(q(t.$$.fragment,n),e=!0)},o(n){ot(t.$$.fragment,n),e=!1},d(n){Lt(t,n)}}}function Xu(r){let t,e,i=xe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Hu(Uu(r,i,o));const s=o=>ot(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Pe()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);st(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=xe(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Uu(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=Hu(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(ne(),l=i.length;l<n.length;l+=1)s(l);se()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)q(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)ot(n[a]);e=!1},d(o){o&&nt(t),Dr(n,o)}}}function Vu(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y=r[6]!==void 0&&!r[7]&&Gu(Ba(r)),g=r[6]!==void 0&&!r[7]&&$u(La(r)),b=xe(r[30].rings),C=[];for(let A=0;A<b.length;A+=1)C[A]=Xu(ku(r,b,A));const R=A=>ot(C[A],1,1,()=>{C[A]=null});return{c(){t=et("g"),e=et("defs"),i=et("mask"),n=et("rect"),h=et("path"),y&&y.c(),g&&g.c(),u=et("path"),p=et("path");for(let A=0;A<C.length;A+=1)C[A].c();w(n,"x",s=r[9].x),w(n,"y",o=r[9].y),w(n,"width",a=r[9].w),w(n,"height",l=r[9].h),w(n,"class","svelte-1vxo6dc"),w(h,"d",c=Fi(r[30])),w(h,"class","svelte-1vxo6dc"),w(i,"id",`${r[18]}-${r[32]}-outer`),w(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),w(u,"class","a9s-outer"),w(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),w(u,"fill-rule","evenodd"),w(u,"d",d=Fi(r[30])),w(p,"class","a9s-inner"),w(p,"mask",`url(#${r[18]}-${r[32]}-inner)`),w(p,"style",r[1]),w(p,"fill-rule","evenodd"),w(p,"d",f=Fi(r[30]))},m(A,P){st(A,t,P),At(t,e),At(e,i),At(i,n),At(i,h),y&&y.m(i,null),g&&g.m(e,null),At(t,u),At(t,p);for(let M=0;M<C.length;M+=1)C[M]&&C[M].m(t,null);m=!0,_||(v=[Rt(u,"pointerup",r[13]),Rt(u,"pointerdown",function(){Kt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Rt(p,"pointerup",r[13]),Rt(p,"pointerdown",function(){Kt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],_=!0)},p(A,P){if(r=A,(!m||P[0]&512&&s!==(s=r[9].x))&&w(n,"x",s),(!m||P[0]&512&&o!==(o=r[9].y))&&w(n,"y",o),(!m||P[0]&512&&a!==(a=r[9].w))&&w(n,"width",a),(!m||P[0]&512&&l!==(l=r[9].h))&&w(n,"height",l),(!m||P[0]&32&&c!==(c=Fi(r[30])))&&w(h,"d",c),r[6]!==void 0&&!r[7]?y?y.p(Ba(r),P):(y=Gu(Ba(r)),y.c(),y.m(i,null)):y&&(y.d(1),y=null),r[6]!==void 0&&!r[7]?g?g.p(La(r),P):(g=$u(La(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||P[0]&32&&d!==(d=Fi(r[30])))&&w(u,"d",d),(!m||P[0]&2)&&w(p,"style",r[1]),(!m||P[0]&32&&f!==(f=Fi(r[30])))&&w(p,"d",f),P[0]&268491048){b=xe(r[30].rings);let M;for(M=0;M<b.length;M+=1){const k=ku(r,b,M);C[M]?(C[M].p(k,P),q(C[M],1)):(C[M]=Xu(k),C[M].c(),q(C[M],1),C[M].m(t,null))}for(ne(),M=b.length;M<C.length;M+=1)R(M);se()}},i(A){if(!m){for(let P=0;P<b.length;P+=1)q(C[P]);m=!0}},o(A){C=C.filter(Boolean);for(let P=0;P<C.length;P+=1)ot(C[P]);m=!1},d(A){A&&nt(t),y&&y.d(),g&&g.d(),Dr(C,A),_=!1,Ne(v)}}}function zu(r){let t,e;return t=new Cu({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Kt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}function Dv(r){let t,e,i,n=xe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Vu(Fu(r,n,l));const o=l=>ot(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&zu(Oa(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Se(),a&&a.c(),e=Pe()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);st(l,t,h),a&&a.m(l,h),st(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=xe(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=Fu(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=Vu(u),s[c].c(),q(s[c],1),s[c].m(t.parentNode,t))}for(ne(),c=n.length;c<s.length;c+=1)o(c);se()}l[6]!==void 0&&!l[7]?a?(a.p(Oa(l),h),h[0]&192&&q(a,1)):(a=zu(Oa(l)),a.c(),q(a,1),a.m(e.parentNode,e)):a&&(ne(),ot(a,1,1,()=>{a=null}),se())},i(l){if(!i){for(let h=0;h<n.length;h+=1)q(s[h]);q(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)ot(s[h]);ot(a),i=!1},d(l){l&&(nt(t),nt(e)),Dr(s,l),a&&a.d(l)}}}function Ov(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[Dv,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){Bt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){ot(t.$$.fragment,i),e=!1},d(i){Lt(t,i)}}}const Lv=250,Bv=1e3,Cn=4.5;function Nv(r,t,e){let i,n,s;const o=Di();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const _=()=>e(7,p=!0),v=()=>e(7,p=!1),y=S=>{if(m.length>0||!n.some(F=>F.visible)){e(6,d=void 0);return}const[B,D]=h.elementToImage(S.offsetX,S.offsetY),N=F=>Math.pow(F[0]-B,2)+Math.pow(F[1]-D,2),H=K_(i).reduce((F,X)=>N(X)<N(F)?X:F),O=n.filter(F=>F.visible).reduce((F,X)=>N(X.point)<N(F.point)?X:F),L=Math.pow(Bv/c,2);N(H)<L||N(O.point)<L?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},C=S=>{e(7,p=!0),S.preventDefault(),S.stopPropagation(),f=performance.now()},R=(S,B,D)=>N=>{if(!f||Lr||performance.now()-f>Lv)return;const H=L=>L.polygon===S&&L.ring===B&&L.point===D,O=m.some(H);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(L=>!H(L))):e(8,m=[...m,{polygon:S,ring:B,point:D}]):O&&m.length>1?e(8,m=[{polygon:S,ring:B,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:S,ring:B,point:D}]),g()},A=(S,B,D)=>{g();const N=S.geometry.polygons;let H;if(B==="SHAPE")H=N.map(O=>{const L=O.rings.map((F,X)=>({points:F.points.map((dt,yt)=>[dt[0]+D[0],dt[1]+D[1]])})),$=Qe(L[0].points);return{rings:L,bounds:$}});else{const[O,L,$,F]=B.split("-").map(X=>parseInt(X));H=N.map((X,V)=>{if(V===L){const dt=X.rings.map((z,wt)=>wt===$?{points:z.points.map((ft,_t)=>_t===F?[ft[0]+D[0],ft[1]+D[1]]:ft)}:z),yt=Qe(dt[0].points);return{rings:dt,bounds:yt}}else return X})}return{...S,geometry:{polygons:H,bounds:Ts(H)}}},P=S=>async B=>{B.stopPropagation();const D=n[S],N=i.polygons.map((O,L)=>{if(L===D.elementIdx){const $=O.rings.map((X,V)=>V===D.ringIdx?{points:[...X.points.slice(0,D.pointIdx+1),D.point,...X.points.slice(D.pointIdx+1)]}:X),F=Qe($[0].points);return{rings:$,bounds:F}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Ts(N)}}),await yu();const H=[...document.querySelectorAll(".a9s-handle")][S+1];if(H!=null&&H.firstChild){const O=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:B.clientX,clientY:B.clientY,pointerId:B.pointerId,pointerType:B.pointerType,isPrimary:B.isPrimary,buttons:B.buttons});H.firstChild.dispatchEvent(O)}},M=()=>{const S=i.polygons.map((D,N)=>{if(m.some(O=>O.polygon===N)){const O=D.rings.map(($,F)=>{const X=m.filter(V=>V.polygon===N&&V.ring===F);return X.length&&$.points.length-X.length>=3?{points:$.points.filter((dt,yt)=>!X.some(z=>z.point===yt))}:$}),L=Qe(O[0].points);return{rings:O,bounds:L}}else return D});!Da(i.polygons,S)&&(o("change",{...a,geometry:{polygons:S,bounds:Ts(S)}}),e(8,m=[]))};ei(()=>{if(Lr)return;const S=B=>{(B.key==="Delete"||B.key==="Backspace")&&(B.preventDefault(),M())};return u.addEventListener("pointermove",y),u.addEventListener("keydown",S),()=>{u.removeEventListener("pointermove",y),u.removeEventListener("keydown",S)}});const k=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(S,B,D,{polygon:N,ring:H,point:O})=>N===S&&H===B&&O===D;function I(S){ye.call(this,r,S)}function T(S){ye.call(this,r,S)}function E(S){ye.call(this,r,S)}return r.$$set=S=>{"shape"in S&&e(0,a=S.shape),"computedStyle"in S&&e(1,l=S.computedStyle),"transform"in S&&e(2,h=S.transform),"viewportScale"in S&&e(3,c=S.viewportScale),"svgEl"in S&&e(4,u=S.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Lr?[]:Mv(i,c)),r.$$.dirty[0]&40&&e(9,s=Ca(i.bounds,Cn/c))},[a,l,h,c,u,i,d,p,m,s,n,_,v,b,C,R,A,P,k,U,I,T,E]}class Fv extends jt{constructor(t){super(),zt(this,t,Nv,Ov,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}Je.RECTANGLE,Je.POLYGON,Je.MULTIPOLYGON;function kv(r,t,e){let i;const n=Di();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return ei(()=>(e(6,u=new o({target:l,props:{shape:s.target.selector,computedStyle:i,transform:h,viewportScale:c,svgEl:l.closest("svg")}})),u.$on("change",d=>{u.$$set({shape:d.detail}),n("change",d.detail)}),u.$on("grab",d=>n("grab",d.detail)),u.$on("release",d=>n("release",d.detail)),()=>{u.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,s=d.annotation),"editor"in d&&e(1,o=d.editor),"style"in d&&e(2,a=d.style),"target"in d&&e(3,l=d.target),"transform"in d&&e(4,h=d.transform),"viewportScale"in d&&e(5,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=av(s,a)),r.$$.dirty&65&&s&&(u==null||u.$set({shape:s.target.selector})),r.$$.dirty&80&&u&&u.$set({transform:h}),r.$$.dirty&96&&u&&u.$set({viewportScale:c}),r.$$.dirty&192&&u&&i&&u.$set({computedStyle:i})},[s,o,a,l,h,c,u,i]}class Uv extends jt{constructor(t){super(),zt(this,t,kv,null,Ut,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1;var ii=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(ii||{}),ju=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(ju||{}),Na=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Na||{}),gt=(r=>(r[r.NORMAL=0]="NORMAL",r[r.ADD=1]="ADD",r[r.MULTIPLY=2]="MULTIPLY",r[r.SCREEN=3]="SCREEN",r[r.OVERLAY=4]="OVERLAY",r[r.DARKEN=5]="DARKEN",r[r.LIGHTEN=6]="LIGHTEN",r[r.COLOR_DODGE=7]="COLOR_DODGE",r[r.COLOR_BURN=8]="COLOR_BURN",r[r.HARD_LIGHT=9]="HARD_LIGHT",r[r.SOFT_LIGHT=10]="SOFT_LIGHT",r[r.DIFFERENCE=11]="DIFFERENCE",r[r.EXCLUSION=12]="EXCLUSION",r[r.HUE=13]="HUE",r[r.SATURATION=14]="SATURATION",r[r.COLOR=15]="COLOR",r[r.LUMINOSITY=16]="LUMINOSITY",r[r.NORMAL_NPM=17]="NORMAL_NPM",r[r.ADD_NPM=18]="ADD_NPM",r[r.SCREEN_NPM=19]="SCREEN_NPM",r[r.NONE=20]="NONE",r[r.SRC_OVER=0]="SRC_OVER",r[r.SRC_IN=21]="SRC_IN",r[r.SRC_OUT=22]="SRC_OUT",r[r.SRC_ATOP=23]="SRC_ATOP",r[r.DST_OVER=24]="DST_OVER",r[r.DST_IN=25]="DST_IN",r[r.DST_OUT=26]="DST_OUT",r[r.DST_ATOP=27]="DST_ATOP",r[r.ERASE=26]="ERASE",r[r.SUBTRACT=28]="SUBTRACT",r[r.XOR=29]="XOR",r))(gt||{}),tr=(r=>(r[r.POINTS=0]="POINTS",r[r.LINES=1]="LINES",r[r.LINE_LOOP=2]="LINE_LOOP",r[r.LINE_STRIP=3]="LINE_STRIP",r[r.TRIANGLES=4]="TRIANGLES",r[r.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",r[r.TRIANGLE_FAN=6]="TRIANGLE_FAN",r))(tr||{}),j=(r=>(r[r.RGBA=6408]="RGBA",r[r.RGB=6407]="RGB",r[r.RG=33319]="RG",r[r.RED=6403]="RED",r[r.RGBA_INTEGER=36249]="RGBA_INTEGER",r[r.RGB_INTEGER=36248]="RGB_INTEGER",r[r.RG_INTEGER=33320]="RG_INTEGER",r[r.RED_INTEGER=36244]="RED_INTEGER",r[r.ALPHA=6406]="ALPHA",r[r.LUMINANCE=6409]="LUMINANCE",r[r.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",r[r.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",r[r.DEPTH_STENCIL=34041]="DEPTH_STENCIL",r))(j||{}),Ui=(r=>(r[r.TEXTURE_2D=3553]="TEXTURE_2D",r[r.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",r[r.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",r[r.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",r[r.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",r[r.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",r[r.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",r))(Ui||{}),ut=(r=>(r[r.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",r[r.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",r[r.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",r[r.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",r[r.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",r[r.UNSIGNED_INT=5125]="UNSIGNED_INT",r[r.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",r[r.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",r[r.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",r[r.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",r[r.BYTE=5120]="BYTE",r[r.SHORT=5122]="SHORT",r[r.INT=5124]="INT",r[r.FLOAT=5126]="FLOAT",r[r.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",r[r.HALF_FLOAT=36193]="HALF_FLOAT",r))(ut||{}),Z=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(Z||{}),mr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(mr||{}),Br=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Br||{}),er=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(er||{}),Re=(r=>(r[r.NPM=0]="NPM",r[r.UNPACK=1]="UNPACK",r[r.PMA=2]="PMA",r[r.NO_PREMULTIPLIED_ALPHA=0]="NO_PREMULTIPLIED_ALPHA",r[r.PREMULTIPLY_ON_UPLOAD=1]="PREMULTIPLY_ON_UPLOAD",r[r.PREMULTIPLIED_ALPHA=2]="PREMULTIPLIED_ALPHA",r))(Re||{}),rr=(r=>(r[r.NO=0]="NO",r[r.YES=1]="YES",r[r.AUTO=2]="AUTO",r[r.BLEND=0]="BLEND",r[r.CLEAR=1]="CLEAR",r[r.BLIT=2]="BLIT",r))(rr||{}),Fa=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(Fa||{}),Fe=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(Fe||{}),re=(r=>(r[r.NONE=0]="NONE",r[r.SCISSOR=1]="SCISSOR",r[r.STENCIL=2]="STENCIL",r[r.SPRITE=3]="SPRITE",r[r.COLOR=4]="COLOR",r))(re||{}),te=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(te||{}),ir=(r=>(r[r.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",r[r.ARRAY_BUFFER=34962]="ARRAY_BUFFER",r[r.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",r))(ir||{});const J={ADAPTER:{createCanvas:(r,t)=>{const e=document.createElement("canvas");return e.width=r,e.height=t,e},getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(r,t)=>fetch(r,t),parseXML:r=>new DOMParser().parseFromString(r,"text/xml")},RESOLUTION:1,CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1};var ka=/iPhone/i,Wu=/iPod/i,Yu=/iPad/i,qu=/\biOS-universal(?:.+)Mac\b/i,Ua=/\bAndroid(?:.+)Mobile\b/i,Ku=/Android/i,Gi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,As=/Silk/i,gr=/Windows Phone/i,Zu=/\bWindows(?:.+)ARM\b/i,Ju=/BlackBerry/i,Qu=/BB10/i,td=/Opera Mini/i,ed=/\b(CriOS|Chrome)(?:.+)Mobile/i,rd=/Mobile(?:.+)Firefox\b/i,id=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function Gv(r){return function(t){return t.test(r)}}function nd(r){var t={userAgent:"",platform:"",maxTouchPoints:0};!r&&typeof navigator<"u"?t={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof r=="string"?t.userAgent=r:r&&r.userAgent&&(t={userAgent:r.userAgent,platform:r.platform,maxTouchPoints:r.maxTouchPoints||0});var e=t.userAgent,i=e.split("[FBAN");typeof i[1]<"u"&&(e=i[0]),i=e.split("Twitter"),typeof i[1]<"u"&&(e=i[0]);var n=Gv(e),s={apple:{phone:n(ka)&&!n(gr),ipod:n(Wu),tablet:!n(ka)&&(n(Yu)||id(t))&&!n(gr),universal:n(qu),device:(n(ka)||n(Wu)||n(Yu)||n(qu)||id(t))&&!n(gr)},amazon:{phone:n(Gi),tablet:!n(Gi)&&n(As),device:n(Gi)||n(As)},android:{phone:!n(gr)&&n(Gi)||!n(gr)&&n(Ua),tablet:!n(gr)&&!n(Gi)&&!n(Ua)&&(n(As)||n(Ku)),device:!n(gr)&&(n(Gi)||n(As)||n(Ua)||n(Ku))||n(/\bokhttp\b/i)},windows:{phone:n(gr),tablet:n(Zu),device:n(gr)||n(Zu)},other:{blackberry:n(Ju),blackberry10:n(Qu),opera:n(td),firefox:n(rd),chrome:n(ed),device:n(Ju)||n(Qu)||n(td)||n(rd)||n(ed)},any:!1,phone:!1,tablet:!1};return s.any=s.apple.device||s.android.device||s.windows.device||s.other.device,s.phone=s.apple.phone||s.android.phone||s.windows.phone,s.tablet=s.apple.tablet||s.android.tablet||s.windows.tablet,s}const $v=nd.default??nd,yr=$v(globalThis.navigator);J.RETINA_PREFIX=/@([0-9\.]+)x/,J.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var sd={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function n(l,h,c){this.fn=l,this.context=h,this.once=c||!1}function s(l,h,c,u,d){if(typeof c!="function")throw new TypeError("The listener must be a function");var p=new n(c,u||l,d),f=e?e+h:h;return l._events[f]?l._events[f].fn?l._events[f]=[l._events[f],p]:l._events[f].push(p):(l._events[f]=p,l._eventsCount++),l}function o(l,h){--l._eventsCount===0?l._events=new i:delete l._events[h]}function a(){this._events=new i,this._eventsCount=0}a.prototype.eventNames=function(){var h=[],c,u;if(this._eventsCount===0)return h;for(u in c=this._events)t.call(c,u)&&h.push(e?u.slice(1):u);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(c)):h},a.prototype.listeners=function(h){var c=e?e+h:h,u=this._events[c];if(!u)return[];if(u.fn)return[u.fn];for(var d=0,p=u.length,f=new Array(p);d<p;d++)f[d]=u[d].fn;return f},a.prototype.listenerCount=function(h){var c=e?e+h:h,u=this._events[c];return u?u.fn?1:u.length:0},a.prototype.emit=function(h,c,u,d,p,f){var m=e?e+h:h;if(!this._events[m])return!1;var _=this._events[m],v=arguments.length,y,g;if(_.fn){switch(_.once&&this.removeListener(h,_.fn,void 0,!0),v){case 1:return _.fn.call(_.context),!0;case 2:return _.fn.call(_.context,c),!0;case 3:return _.fn.call(_.context,c,u),!0;case 4:return _.fn.call(_.context,c,u,d),!0;case 5:return _.fn.call(_.context,c,u,d,p),!0;case 6:return _.fn.call(_.context,c,u,d,p,f),!0}for(g=1,y=new Array(v-1);g<v;g++)y[g-1]=arguments[g];_.fn.apply(_.context,y)}else{var b=_.length,C;for(g=0;g<b;g++)switch(_[g].once&&this.removeListener(h,_[g].fn,void 0,!0),v){case 1:_[g].fn.call(_[g].context);break;case 2:_[g].fn.call(_[g].context,c);break;case 3:_[g].fn.call(_[g].context,c,u);break;case 4:_[g].fn.call(_[g].context,c,u,d);break;default:if(!y)for(C=1,y=new Array(v-1);C<v;C++)y[C-1]=arguments[C];_[g].fn.apply(_[g].context,y)}}return!0},a.prototype.on=function(h,c,u){return s(this,h,c,u,!1)},a.prototype.once=function(h,c,u){return s(this,h,c,u,!0)},a.prototype.removeListener=function(h,c,u,d){var p=e?e+h:h;if(!this._events[p])return this;if(!c)return o(this,p),this;var f=this._events[p];if(f.fn)f.fn===c&&(!d||f.once)&&(!u||f.context===u)&&o(this,p);else{for(var m=0,_=[],v=f.length;m<v;m++)(f[m].fn!==c||d&&!f[m].once||u&&f[m].context!==u)&&_.push(f[m]);_.length?this._events[p]=_.length===1?_[0]:_:o(this,p)}return this},a.prototype.removeAllListeners=function(h){var c;return h?(c=e?e+h:h,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,r.exports=a})(sd);var Hv=sd.exports;const In=Aa(Hv);var Ga={exports:{}};Ga.exports=Ss,Ga.exports.default=Ss;function Ss(r,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:r.length,s=od(r,0,n,e,!0),o=[];if(!s||s.next===s.prev)return o;var a,l,h,c,u,d,p;if(i&&(s=Wv(r,t,s,e)),r.length>80*e){a=h=r[0],l=c=r[1];for(var f=e;f<n;f+=e)u=r[f],d=r[f+1],u<a&&(a=u),d<l&&(l=d),u>h&&(h=u),d>c&&(c=d);p=Math.max(h-a,c-l),p=p!==0?32767/p:0}return Pn(s,o,e,a,l,p,0),o}function od(r,t,e,i,n){var s,o;if(n===Xa(r,t,e,i)>0)for(s=t;s<e;s+=i)o=hd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=hd(s,r[s],r[s+1],o);return o&&Cs(o,o.next)&&(Mn(o),o=o.next),o}function ni(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(Cs(e,e.next)||$t(e.prev,e,e.next)===0)){if(Mn(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Pn(r,t,e,i,n,s,o){if(r){!o&&s&&Jv(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?Vv(r,i,n,s):Xv(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Mn(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=zv(ni(r),t,e),Pn(r,t,e,i,n,s,2)):o===2&&jv(r,t,e,i,n,s):Pn(ni(r),t,e,i,n,s,1);break}}}}function Xv(r){var t=r.prev,e=r,i=r.next;if($t(t,e,i)>=0)return!1;for(var n=t.x,s=e.x,o=i.x,a=t.y,l=e.y,h=i.y,c=n<s?n<o?n:o:s<o?s:o,u=a<l?a<h?a:h:l<h?l:h,d=n>s?n>o?n:o:s>o?s:o,p=a>l?a>h?a:h:l>h?l:h,f=i.next;f!==t;){if(f.x>=c&&f.x<=d&&f.y>=u&&f.y<=p&&$i(n,a,s,l,o,h,f.x,f.y)&&$t(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Vv(r,t,e,i){var n=r.prev,s=r,o=r.next;if($t(n,s,o)>=0)return!1;for(var a=n.x,l=s.x,h=o.x,c=n.y,u=s.y,d=o.y,p=a<l?a<h?a:h:l<h?l:h,f=c<u?c<d?c:d:u<d?u:d,m=a>l?a>h?a:h:l>h?l:h,_=c>u?c>d?c:d:u>d?u:d,v=$a(p,f,t,e,i),y=$a(m,_,t,e,i),g=r.prevZ,b=r.nextZ;g&&g.z>=v&&b&&b.z<=y;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=_&&g!==n&&g!==o&&$i(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0||(g=g.prevZ,b.x>=p&&b.x<=m&&b.y>=f&&b.y<=_&&b!==n&&b!==o&&$i(a,c,l,u,h,d,b.x,b.y)&&$t(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;g&&g.z>=v;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=_&&g!==n&&g!==o&&$i(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;b&&b.z<=y;){if(b.x>=p&&b.x<=m&&b.y>=f&&b.y<=_&&b!==n&&b!==o&&$i(a,c,l,u,h,d,b.x,b.y)&&$t(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function zv(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!Cs(n,s)&&ad(n,i,i.next,s)&&Rn(n,s)&&Rn(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),Mn(i),Mn(i.next),i=r=s),i=i.next}while(i!==r);return ni(i)}function jv(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&e1(o,a)){var l=ld(o,a);o=ni(o,o.next),l=ni(l,l.next),Pn(o,t,e,i,n,s,0),Pn(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function Wv(r,t,e,i){var n=[],s,o,a,l,h;for(s=0,o=t.length;s<o;s++)a=t[s]*i,l=s<o-1?t[s+1]*i:r.length,h=od(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(t1(h));for(n.sort(Yv),s=0;s<n.length;s++)e=qv(n[s],e);return e}function Yv(r,t){return r.x-t.x}function qv(r,t){var e=Kv(r,t);if(!e)return t;var i=ld(e,r);return ni(i,i.next),ni(e,e.next)}function Kv(r,t){var e=t,i=r.x,n=r.y,s=-1/0,o;do{if(n<=e.y&&n>=e.next.y&&e.next.y!==e.y){var a=e.x+(n-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(a<=i&&a>s&&(s=a,o=e.x<e.next.x?e:e.next,a===i))return o}e=e.next}while(e!==t);if(!o)return null;var l=o,h=o.x,c=o.y,u=1/0,d;e=o;do i>=e.x&&e.x>=h&&i!==e.x&&$i(n<c?i:s,n,h,c,n<c?s:i,n,e.x,e.y)&&(d=Math.abs(n-e.y)/(i-e.x),Rn(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&Zv(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function Zv(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function Jv(r,t,e,i){var n=r;do n.z===0&&(n.z=$a(n.x,n.y,t,e,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==r);n.prevZ.nextZ=null,n.prevZ=null,Qv(n)}function Qv(r){var t,e,i,n,s,o,a,l,h=1;do{for(e=r,r=null,s=null,o=0;e;){for(o++,i=e,a=0,t=0;t<h&&(a++,i=i.nextZ,!!i);t++);for(l=h;a>0||l>0&&i;)a!==0&&(l===0||!i||e.z<=i.z)?(n=e,e=e.nextZ,a--):(n=i,i=i.nextZ,l--),s?s.nextZ=n:r=n,n.prevZ=s,s=n;e=i}s.nextZ=null,h*=2}while(o>1);return r}function $a(r,t,e,i,n){return r=(r-e)*n|0,t=(t-i)*n|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1}function t1(r){var t=r,e=r;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==r);return e}function $i(r,t,e,i,n,s,o,a){return(n-o)*(t-a)>=(r-o)*(s-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(s-a)>=(n-o)*(i-a)}function e1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!r1(r,t)&&(Rn(r,t)&&Rn(t,r)&&i1(r,t)&&($t(r.prev,r,t.prev)||$t(r,t.prev,t))||Cs(r,t)&&$t(r.prev,r,r.next)>0&&$t(t.prev,t,t.next)>0)}function $t(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function Cs(r,t){return r.x===t.x&&r.y===t.y}function ad(r,t,e,i){var n=Ps($t(r,t,e)),s=Ps($t(r,t,i)),o=Ps($t(e,i,r)),a=Ps($t(e,i,t));return!!(n!==s&&o!==a||n===0&&Is(r,e,t)||s===0&&Is(r,i,t)||o===0&&Is(e,r,i)||a===0&&Is(e,t,i))}function Is(r,t,e){return t.x<=Math.max(r.x,e.x)&&t.x>=Math.min(r.x,e.x)&&t.y<=Math.max(r.y,e.y)&&t.y>=Math.min(r.y,e.y)}function Ps(r){return r>0?1:r<0?-1:0}function r1(r,t){var e=r;do{if(e.i!==r.i&&e.next.i!==r.i&&e.i!==t.i&&e.next.i!==t.i&&ad(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Rn(r,t){return $t(r.prev,r,r.next)<0?$t(r,t,r.next)>=0&&$t(r,r.prev,t)>=0:$t(r,t,r.prev)<0||$t(r,r.next,t)<0}function i1(r,t){var e=r,i=!1,n=(r.x+t.x)/2,s=(r.y+t.y)/2;do e.y>s!=e.next.y>s&&e.next.y!==e.y&&n<(e.next.x-e.x)*(s-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function ld(r,t){var e=new Ha(r.i,r.x,r.y),i=new Ha(t.i,t.x,t.y),n=r.next,s=t.prev;return r.next=t,t.prev=r,e.next=n,n.prev=e,i.next=e,e.prev=i,s.next=i,i.prev=s,i}function hd(r,t,e,i){var n=new Ha(r,t,e);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function Mn(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function Ha(r,t,e){this.i=r,this.x=t,this.y=e,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}Ss.deviation=function(r,t,e,i){var n=t&&t.length,s=n?t[0]*e:r.length,o=Math.abs(Xa(r,0,s,e));if(n)for(var a=0,l=t.length;a<l;a++){var h=t[a]*e,c=a<l-1?t[a+1]*e:r.length;o-=Math.abs(Xa(r,h,c,e))}var u=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,p=i[a+1]*e,f=i[a+2]*e;u+=Math.abs((r[d]-r[f])*(r[p+1]-r[d+1])-(r[d]-r[p])*(r[f+1]-r[d+1]))}return o===0&&u===0?0:Math.abs((u-o)/o)};function Xa(r,t,e,i){for(var n=0,s=t,o=e-i;s<e;s+=i)n+=(r[o]-r[s])*(r[s+1]+r[o+1]),o=s;return n}Ss.flatten=function(r){for(var t=r[0][0].length,e={vertices:[],holes:[],dimensions:t},i=0,n=0;n<r.length;n++){for(var s=0;s<r[n].length;s++)for(var o=0;o<t;o++)e.vertices.push(r[n][s][o]);n>0&&(i+=r[n-1].length,e.holes.push(i))}return e};var n1=Ga.exports;const s1=Aa(n1);var Rs={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Rs.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,n=r&&!r.nodeType&&r,s=typeof An=="object"&&An;(s.global===s||s.window===s||s.self===s)&&(e=s);var o,a=2147483647,l=36,h=1,c=26,u=38,d=700,p=72,f=128,m="-",_=/^xn--/,v=/[^\x20-\x7E]/,y=/[\x2E\u3002\uFF0E\uFF61]/g,g={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},b=l-h,C=Math.floor,R=String.fromCharCode,A;function P(O){throw new RangeError(g[O])}function M(O,L){for(var $=O.length,F=[];$--;)F[$]=L(O[$]);return F}function k(O,L){var $=O.split("@"),F="";$.length>1&&(F=$[0]+"@",O=$[1]),O=O.replace(y,".");var X=O.split("."),V=M(X,L).join(".");return F+V}function U(O){for(var L=[],$=0,F=O.length,X,V;$<F;)X=O.charCodeAt($++),X>=55296&&X<=56319&&$<F?(V=O.charCodeAt($++),(V&64512)==56320?L.push(((X&1023)<<10)+(V&1023)+65536):(L.push(X),$--)):L.push(X);return L}function I(O){return M(O,function(L){var $="";return L>65535&&(L-=65536,$+=R(L>>>10&1023|55296),L=56320|L&1023),$+=R(L),$}).join("")}function T(O){return O-48<10?O-22:O-65<26?O-65:O-97<26?O-97:l}function E(O,L){return O+22+75*(O<26)-((L!=0)<<5)}function S(O,L,$){var F=0;for(O=$?C(O/d):O>>1,O+=C(O/L);O>b*c>>1;F+=l)O=C(O/b);return C(F+(b+1)*O/(O+u))}function B(O){var L=[],$=O.length,F,X=0,V=f,dt=p,yt,z,wt,it,ft,_t,Pt,Dt,he;for(yt=O.lastIndexOf(m),yt<0&&(yt=0),z=0;z<yt;++z)O.charCodeAt(z)>=128&&P("not-basic"),L.push(O.charCodeAt(z));for(wt=yt>0?yt+1:0;wt<$;){for(it=X,ft=1,_t=l;wt>=$&&P("invalid-input"),Pt=T(O.charCodeAt(wt++)),(Pt>=l||Pt>C((a-X)/ft))&&P("overflow"),X+=Pt*ft,Dt=_t<=dt?h:_t>=dt+c?c:_t-dt,!(Pt<Dt);_t+=l)he=l-Dt,ft>C(a/he)&&P("overflow"),ft*=he;F=L.length+1,dt=S(X-it,F,it==0),C(X/F)>a-V&&P("overflow"),V+=C(X/F),X%=F,L.splice(X++,0,V)}return I(L)}function D(O){var L,$,F,X,V,dt,yt,z,wt,it,ft,_t=[],Pt,Dt,he,Vt;for(O=U(O),Pt=O.length,L=f,$=0,V=p,dt=0;dt<Pt;++dt)ft=O[dt],ft<128&&_t.push(R(ft));for(F=X=_t.length,X&&_t.push(m);F<Pt;){for(yt=a,dt=0;dt<Pt;++dt)ft=O[dt],ft>=L&&ft<yt&&(yt=ft);for(Dt=F+1,yt-L>C((a-$)/Dt)&&P("overflow"),$+=(yt-L)*Dt,L=yt,dt=0;dt<Pt;++dt)if(ft=O[dt],ft<L&&++$>a&&P("overflow"),ft==L){for(z=$,wt=l;it=wt<=V?h:wt>=V+c?c:wt-V,!(z<it);wt+=l)Vt=z-it,he=l-it,_t.push(R(E(it+Vt%he,0))),z=C(Vt/he);_t.push(R(E(z,0))),V=S($,Dt,F==X),$=0,++F}++$,++L}return _t.join("")}function N(O){return k(O,function(L){return _.test(L)?B(L.slice(4).toLowerCase()):L})}function H(O){return k(O,function(L){return v.test(L)?"xn--"+D(L):L})}if(o={version:"1.4.1",ucs2:{decode:U,encode:I},decode:B,encode:D,toASCII:H,toUnicode:N},i&&n)if(r.exports==i)n.exports=o;else for(A in o)o.hasOwnProperty(A)&&(i[A]=o[A]);else e.punycode=o})(An)}(Rs,Rs.exports);var o1=Rs.exports,Hi=TypeError;const a1=H_(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Va=typeof Map=="function"&&Map.prototype,za=Object.getOwnPropertyDescriptor&&Va?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ms=Va&&za&&typeof za.get=="function"?za.get:null,cd=Va&&Map.prototype.forEach,ja=typeof Set=="function"&&Set.prototype,Wa=Object.getOwnPropertyDescriptor&&ja?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Ds=ja&&Wa&&typeof Wa.get=="function"?Wa.get:null,ud=ja&&Set.prototype.forEach,l1=typeof WeakMap=="function"&&WeakMap.prototype,Dn=l1?WeakMap.prototype.has:null,h1=typeof WeakSet=="function"&&WeakSet.prototype,On=h1?WeakSet.prototype.has:null,c1=typeof WeakRef=="function"&&WeakRef.prototype,dd=c1?WeakRef.prototype.deref:null,u1=Boolean.prototype.valueOf,d1=Object.prototype.toString,f1=Function.prototype.toString,p1=String.prototype.match,Ya=String.prototype.slice,Nr=String.prototype.replace,m1=String.prototype.toUpperCase,fd=String.prototype.toLowerCase,pd=RegExp.prototype.test,md=Array.prototype.concat,nr=Array.prototype.join,g1=Array.prototype.slice,gd=Math.floor,qa=typeof BigInt=="function"?BigInt.prototype.valueOf:null,Ka=Object.getOwnPropertySymbols,Za=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Xi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Ln=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xi||!0)?Symbol.toStringTag:null,yd=Object.prototype.propertyIsEnumerable,_d=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function vd(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||pd.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-gd(-r):gd(r);if(i!==r){var n=String(i),s=Ya.call(t,n.length+1);return Nr.call(n,e,"$&_")+"."+Nr.call(Nr.call(s,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Nr.call(t,e,"$&_")}var Ja=a1,bd=Ja.custom,xd=Ad(bd)?bd:null,wd={__proto__:null,double:'"',single:"'"},y1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Os=function r(t,e,i,n){var s=e||{};if(_r(s,"quoteStyle")&&!_r(wd,s.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(_r(s,"maxStringLength")&&(typeof s.maxStringLength=="number"?s.maxStringLength<0&&s.maxStringLength!==1/0:s.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=_r(s,"customInspect")?s.customInspect:!0;if(typeof o!="boolean"&&o!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(_r(s,"indent")&&s.indent!==null&&s.indent!==" "&&!(parseInt(s.indent,10)===s.indent&&s.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(_r(s,"numericSeparator")&&typeof s.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=s.numericSeparator;if(typeof t>"u")return"undefined";if(t===null)return"null";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="string")return Cd(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?vd(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?vd(t,h):h}var c=typeof s.depth>"u"?5:s.depth;if(typeof i>"u"&&(i=0),i>=c&&c>0&&typeof t=="object")return Qa(t)?"[Array]":"[Object]";var u=B1(s,i);if(typeof n>"u")n=[];else if(Sd(n,t)>=0)return"[Circular]";function d(T,E,S){if(E&&(n=g1.call(n),n.push(E)),S){var B={depth:s.depth};return _r(s,"quoteStyle")&&(B.quoteStyle=s.quoteStyle),r(T,B,i+1,n)}return r(T,s,i+1,n)}if(typeof t=="function"&&!Td(t)){var p=S1(t),f=Ls(t,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+nr.call(f,", ")+" }":"")}if(Ad(t)){var m=Xi?Nr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Za.call(t);return typeof t=="object"&&!Xi?Bn(m):m}if(D1(t)){for(var _="<"+fd.call(String(t.nodeName)),v=t.attributes||[],y=0;y<v.length;y++)_+=" "+v[y].name+"="+Ed(_1(v[y].value),"double",s);return _+=">",t.childNodes&&t.childNodes.length&&(_+="..."),_+="</"+fd.call(String(t.nodeName))+">",_}if(Qa(t)){if(t.length===0)return"[]";var g=Ls(t,d);return u&&!L1(g)?"["+el(g,u)+"]":"[ "+nr.call(g,", ")+" ]"}if(b1(t)){var b=Ls(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!yd.call(t,"cause")?"{ ["+String(t)+"] "+nr.call(md.call("[cause]: "+d(t.cause),b),", ")+" }":b.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+nr.call(b,", ")+" }"}if(typeof t=="object"&&o){if(xd&&typeof t[xd]=="function"&&Ja)return Ja(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(C1(t)){var C=[];return cd&&cd.call(t,function(T,E){C.push(d(E,t,!0)+" => "+d(T,t))}),Id("Map",Ms.call(t),C,u)}if(R1(t)){var R=[];return ud&&ud.call(t,function(T){R.push(d(T,t))}),Id("Set",Ds.call(t),R,u)}if(I1(t))return tl("WeakMap");if(M1(t))return tl("WeakSet");if(P1(t))return tl("WeakRef");if(w1(t))return Bn(d(Number(t)));if(T1(t))return Bn(d(qa.call(t)));if(E1(t))return Bn(u1.call(t));if(x1(t))return Bn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof An<"u"&&t===An)return"{ [object globalThis] }";if(!v1(t)&&!Td(t)){var A=Ls(t,d),P=_d?_d(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",k=!P&&Ln&&Object(t)===t&&Ln in t?Ya.call(Fr(t),8,-1):M?"Object":"",U=P||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",I=U+(k||M?"["+nr.call(md.call([],k||[],M||[]),": ")+"] ":"");return A.length===0?I+"{}":u?I+"{"+el(A,u)+"}":I+"{ "+nr.call(A,", ")+" }"}return String(t)};function Ed(r,t,e){var i=e.quoteStyle||t,n=wd[i];return n+r+n}function _1(r){return Nr.call(String(r),/"/g,"&quot;")}function si(r){return!Ln||!(typeof r=="object"&&(Ln in r||typeof r[Ln]<"u"))}function Qa(r){return Fr(r)==="[object Array]"&&si(r)}function v1(r){return Fr(r)==="[object Date]"&&si(r)}function Td(r){return Fr(r)==="[object RegExp]"&&si(r)}function b1(r){return Fr(r)==="[object Error]"&&si(r)}function x1(r){return Fr(r)==="[object String]"&&si(r)}function w1(r){return Fr(r)==="[object Number]"&&si(r)}function E1(r){return Fr(r)==="[object Boolean]"&&si(r)}function Ad(r){if(Xi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!Za)return!1;try{return Za.call(r),!0}catch{}return!1}function T1(r){if(!r||typeof r!="object"||!qa)return!1;try{return qa.call(r),!0}catch{}return!1}var A1=Object.prototype.hasOwnProperty||function(r){return r in this};function _r(r,t){return A1.call(r,t)}function Fr(r){return d1.call(r)}function S1(r){if(r.name)return r.name;var t=p1.call(f1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Sd(r,t){if(r.indexOf)return r.indexOf(t);for(var e=0,i=r.length;e<i;e++)if(r[e]===t)return e;return-1}function C1(r){if(!Ms||!r||typeof r!="object")return!1;try{Ms.call(r);try{Ds.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function I1(r){if(!Dn||!r||typeof r!="object")return!1;try{Dn.call(r,Dn);try{On.call(r,On)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function P1(r){if(!dd||!r||typeof r!="object")return!1;try{return dd.call(r),!0}catch{}return!1}function R1(r){if(!Ds||!r||typeof r!="object")return!1;try{Ds.call(r);try{Ms.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function M1(r){if(!On||!r||typeof r!="object")return!1;try{On.call(r,On);try{Dn.call(r,Dn)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function D1(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Cd(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Cd(Ya.call(r,0,t.maxStringLength),t)+i}var n=y1[t.quoteStyle||"single"];n.lastIndex=0;var s=Nr.call(Nr.call(r,n,"\\$1"),/[\x00-\x1f]/g,O1);return Ed(s,"single",t)}function O1(r){var t=r.charCodeAt(0),e={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return e?"\\"+e:"\\x"+(t<16?"0":"")+m1.call(t.toString(16))}function Bn(r){return"Object("+r+")"}function tl(r){return r+" { ? }"}function Id(r,t,e,i){var n=i?el(e,i):nr.call(e,", ");return r+" ("+t+") {"+n+"}"}function L1(r){for(var t=0;t<r.length;t++)if(Sd(r[t],`
2
2
  `)>=0)return!1;return!0}function B1(r,t){var e;if(r.indent===" ")e=" ";else if(typeof r.indent=="number"&&r.indent>0)e=nr.call(Array(r.indent+1)," ");else return null;return{base:e,prev:nr.call(Array(t+1),e)}}function el(r,t){if(r.length===0)return"";var e=`
3
3
  `+t.prev+t.base;return e+nr.call(r,","+e)+`
4
4
  `+t.prev}function Ls(r,t){var e=Qa(r),i=[];if(e){i.length=r.length;for(var n=0;n<r.length;n++)i[n]=_r(r,n)?t(r[n],r):""}var s=typeof Ka=="function"?Ka(r):[],o;if(Xi){o={};for(var a=0;a<s.length;a++)o["$"+s[a]]=s[a]}for(var l in r)_r(r,l)&&(e&&String(Number(l))===l&&l<r.length||Xi&&o["$"+l]instanceof Symbol||(pd.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof Ka=="function")for(var h=0;h<s.length;h++)yd.call(r,s[h])&&i.push("["+t(s[h])+"]: "+t(r[s[h]],r));return i}var N1=Os,F1=Hi,Bs=function(r,t,e){for(var i=r,n;(n=i.next)!=null;i=n)if(n.key===t)return i.next=n.next,e||(n.next=r.next,r.next=n),n},k1=function(r,t){if(r){var e=Bs(r,t);return e&&e.value}},U1=function(r,t,e){var i=Bs(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},G1=function(r,t){return r?!!Bs(r,t):!1},$1=function(r,t){if(r)return Bs(r,t,!0)},H1=function(){var t,e={assert:function(i){if(!e.has(i))throw new F1("Side channel does not contain "+N1(i))},delete:function(i){var n=t&&t.next,s=$1(t,i);return s&&n&&n===s&&(t=void 0),!!s},get:function(i){return k1(t,i)},has:function(i){return G1(t,i)},set:function(i,n){t||(t={next:void 0}),U1(t,i,n)}};return e},Pd=Object,X1=Error,V1=EvalError,z1=RangeError,j1=ReferenceError,W1=SyntaxError,Y1=URIError,q1=Math.abs,K1=Math.floor,Z1=Math.max,J1=Math.min,Q1=Math.pow,tb=Math.round,eb=Number.isNaN||function(t){return t!==t},rb=eb,ib=function(t){return rb(t)||t===0?t:t<0?-1:1},nb=Object.getOwnPropertyDescriptor,Ns=nb;if(Ns)try{Ns([],"length")}catch{Ns=null}var Rd=Ns,Fs=Object.defineProperty||!1;if(Fs)try{Fs({},"a",{value:1})}catch{Fs=!1}var sb=Fs,rl,Md;function ob(){return Md||(Md=1,rl=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var t={},e=Symbol("test"),i=Object(e);if(typeof e=="string"||Object.prototype.toString.call(e)!=="[object Symbol]"||Object.prototype.toString.call(i)!=="[object Symbol]")return!1;var n=42;t[e]=n;for(var s in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var o=Object.getOwnPropertySymbols(t);if(o.length!==1||o[0]!==e||!Object.prototype.propertyIsEnumerable.call(t,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var a=Object.getOwnPropertyDescriptor(t,e);if(a.value!==n||a.enumerable!==!0)return!1}return!0}),rl}var il,Dd;function ab(){if(Dd)return il;Dd=1;var r=typeof Symbol<"u"&&Symbol,t=ob();return il=function(){return typeof r!="function"||typeof Symbol!="function"||typeof r("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},il}var nl,Od;function Ld(){return Od||(Od=1,nl=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),nl}var sl,Bd;function Nd(){if(Bd)return sl;Bd=1;var r=Pd;return sl=r.getPrototypeOf||null,sl}var lb="Function.prototype.bind called on incompatible ",hb=Object.prototype.toString,cb=Math.max,ub="[object Function]",Fd=function(t,e){for(var i=[],n=0;n<t.length;n+=1)i[n]=t[n];for(var s=0;s<e.length;s+=1)i[s+t.length]=e[s];return i},db=function(t,e){for(var i=[],n=e,s=0;n<t.length;n+=1,s+=1)i[s]=t[n];return i},fb=function(r,t){for(var e="",i=0;i<r.length;i+=1)e+=r[i],i+1<r.length&&(e+=t);return e},pb=function(t){var e=this;if(typeof e!="function"||hb.apply(e)!==ub)throw new TypeError(lb+e);for(var i=db(arguments,1),n,s=function(){if(this instanceof n){var c=e.apply(this,Fd(i,arguments));return Object(c)===c?c:this}return e.apply(t,Fd(i,arguments))},o=cb(0,e.length-i.length),a=[],l=0;l<o;l++)a[l]="$"+l;if(n=Function("binder","return function ("+fb(a,",")+"){ return binder.apply(this,arguments); }")(s),e.prototype){var h=function(){};h.prototype=e.prototype,n.prototype=new h,h.prototype=null}return n},mb=pb,ks=Function.prototype.bind||mb,ol=Function.prototype.call,al,kd;function Ud(){return kd||(kd=1,al=Function.prototype.apply),al}var gb=typeof Reflect<"u"&&Reflect&&Reflect.apply,yb=ks,_b=Ud(),vb=ol,bb=gb,xb=bb||yb.call(vb,_b),wb=ks,Eb=Hi,Tb=ol,Ab=xb,Gd=function(t){if(t.length<1||typeof t[0]!="function")throw new Eb("a function is required");return Ab(wb,Tb,t)},ll,$d;function Sb(){if($d)return ll;$d=1;var r=Gd,t=Rd,e;try{e=[].__proto__===Array.prototype}catch(o){if(!o||typeof o!="object"||!("code"in o)||o.code!=="ERR_PROTO_ACCESS")throw o}var i=!!e&&t&&t(Object.prototype,"__proto__"),n=Object,s=n.getPrototypeOf;return ll=i&&typeof i.get=="function"?r([i.get]):typeof s=="function"?function(a){return s(a==null?a:n(a))}:!1,ll}var hl,Hd;function Cb(){if(Hd)return hl;Hd=1;var r=Ld(),t=Nd(),e=Sb();return hl=r?function(n){return r(n)}:t?function(n){if(!n||typeof n!="object"&&typeof n!="function")throw new TypeError("getProto: not an object");return t(n)}:e?function(n){return e(n)}:null,hl}var cl,Xd;function Ib(){if(Xd)return cl;Xd=1;var r=Function.prototype.call,t=Object.prototype.hasOwnProperty,e=ks;return cl=e.call(r,t),cl}var Et,Pb=Pd,Rb=X1,Mb=V1,Db=z1,Ob=j1,Vi=W1,zi=Hi,Lb=Y1,Bb=q1,Nb=K1,Fb=Z1,kb=J1,Ub=Q1,Gb=tb,$b=ib,Vd=Function,ul=function(r){try{return Vd('"use strict"; return ('+r+").constructor;")()}catch{}},Nn=Rd,Hb=sb,dl=function(){throw new zi},Xb=Nn?function(){try{return arguments.callee,dl}catch{try{return Nn(arguments,"callee").get}catch{return dl}}}():dl,ji=ab()(),oe=Cb(),Vb=Nd(),zb=Ld(),zd=Ud(),Fn=ol,Wi={},jb=typeof Uint8Array>"u"||!oe?Et:oe(Uint8Array),oi={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?Et:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?Et:ArrayBuffer,"%ArrayIteratorPrototype%":ji&&oe?oe([][Symbol.iterator]()):Et,"%AsyncFromSyncIteratorPrototype%":Et,"%AsyncFunction%":Wi,"%AsyncGenerator%":Wi,"%AsyncGeneratorFunction%":Wi,"%AsyncIteratorPrototype%":Wi,"%Atomics%":typeof Atomics>"u"?Et:Atomics,"%BigInt%":typeof BigInt>"u"?Et:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?Et:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?Et:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?Et:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Rb,"%eval%":eval,"%EvalError%":Mb,"%Float16Array%":typeof Float16Array>"u"?Et:Float16Array,"%Float32Array%":typeof Float32Array>"u"?Et:Float32Array,"%Float64Array%":typeof Float64Array>"u"?Et:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?Et:FinalizationRegistry,"%Function%":Vd,"%GeneratorFunction%":Wi,"%Int8Array%":typeof Int8Array>"u"?Et:Int8Array,"%Int16Array%":typeof Int16Array>"u"?Et:Int16Array,"%Int32Array%":typeof Int32Array>"u"?Et:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":ji&&oe?oe(oe([][Symbol.iterator]())):Et,"%JSON%":typeof JSON=="object"?JSON:Et,"%Map%":typeof Map>"u"?Et:Map,"%MapIteratorPrototype%":typeof Map>"u"||!ji||!oe?Et:oe(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Pb,"%Object.getOwnPropertyDescriptor%":Nn,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?Et:Promise,"%Proxy%":typeof Proxy>"u"?Et:Proxy,"%RangeError%":Db,"%ReferenceError%":Ob,"%Reflect%":typeof Reflect>"u"?Et:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?Et:Set,"%SetIteratorPrototype%":typeof Set>"u"||!ji||!oe?Et:oe(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?Et:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":ji&&oe?oe(""[Symbol.iterator]()):Et,"%Symbol%":ji?Symbol:Et,"%SyntaxError%":Vi,"%ThrowTypeError%":Xb,"%TypedArray%":jb,"%TypeError%":zi,"%Uint8Array%":typeof Uint8Array>"u"?Et:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?Et:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?Et:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?Et:Uint32Array,"%URIError%":Lb,"%WeakMap%":typeof WeakMap>"u"?Et:WeakMap,"%WeakRef%":typeof WeakRef>"u"?Et:WeakRef,"%WeakSet%":typeof WeakSet>"u"?Et:WeakSet,"%Function.prototype.call%":Fn,"%Function.prototype.apply%":zd,"%Object.defineProperty%":Hb,"%Object.getPrototypeOf%":Vb,"%Math.abs%":Bb,"%Math.floor%":Nb,"%Math.max%":Fb,"%Math.min%":kb,"%Math.pow%":Ub,"%Math.round%":Gb,"%Math.sign%":$b,"%Reflect.getPrototypeOf%":zb};if(oe)try{null.error}catch(r){var Wb=oe(oe(r));oi["%Error.prototype%"]=Wb}var Yb=function r(t){var e;if(t==="%AsyncFunction%")e=ul("async function () {}");else if(t==="%GeneratorFunction%")e=ul("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=ul("async function* () {}");else if(t==="%AsyncGenerator%"){var i=r("%AsyncGeneratorFunction%");i&&(e=i.prototype)}else if(t==="%AsyncIteratorPrototype%"){var n=r("%AsyncGenerator%");n&&oe&&(e=oe(n.prototype))}return oi[t]=e,e},jd={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},kn=ks,Us=Ib(),qb=kn.call(Fn,Array.prototype.concat),Kb=kn.call(zd,Array.prototype.splice),Wd=kn.call(Fn,String.prototype.replace),Gs=kn.call(Fn,String.prototype.slice),Zb=kn.call(Fn,RegExp.prototype.exec),Jb=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,Qb=/\\(\\)?/g,tx=function(t){var e=Gs(t,0,1),i=Gs(t,-1);if(e==="%"&&i!=="%")throw new Vi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new Vi("invalid intrinsic syntax, expected opening `%`");var n=[];return Wd(t,Jb,function(s,o,a,l){n[n.length]=a?Wd(l,Qb,"$1"):o||s}),n},ex=function(t,e){var i=t,n;if(Us(jd,i)&&(n=jd[i],i="%"+n[0]+"%"),Us(oi,i)){var s=oi[i];if(s===Wi&&(s=Yb(i)),typeof s>"u"&&!e)throw new zi("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:s}}throw new Vi("intrinsic "+t+" does not exist!")},fl=function(t,e){if(typeof t!="string"||t.length===0)throw new zi("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new zi('"allowMissing" argument must be a boolean');if(Zb(/^%?[^%]*%?$/,t)===null)throw new Vi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=tx(t),n=i.length>0?i[0]:"",s=ex("%"+n+"%",e),o=s.name,a=s.value,l=!1,h=s.alias;h&&(n=h[0],Kb(i,qb([0,1],h)));for(var c=1,u=!0;c<i.length;c+=1){var d=i[c],p=Gs(d,0,1),f=Gs(d,-1);if((p==='"'||p==="'"||p==="`"||f==='"'||f==="'"||f==="`")&&p!==f)throw new Vi("property names with quotes must have matching quotes");if((d==="constructor"||!u)&&(l=!0),n+="."+d,o="%"+n+"%",Us(oi,o))a=oi[o];else if(a!=null){if(!(d in a)){if(!e)throw new zi("base intrinsic for "+t+" exists, but the property is not available.");return}if(Nn&&c+1>=i.length){var m=Nn(a,d);u=!!m,u&&"get"in m&&!("originalValue"in m.get)?a=m.get:a=a[d]}else u=Us(a,d),a=a[d];u&&!l&&(oi[o]=a)}}return a},Yd=fl,qd=Gd,rx=qd([Yd("%String.prototype.indexOf%")]),Kd=function(t,e){var i=Yd(t,!!e);return typeof i=="function"&&rx(t,".prototype.")>-1?qd([i]):i},ix=fl,Un=Kd,nx=Os,sx=Hi,Zd=ix("%Map%",!0),ox=Un("Map.prototype.get",!0),ax=Un("Map.prototype.set",!0),lx=Un("Map.prototype.has",!0),hx=Un("Map.prototype.delete",!0),cx=Un("Map.prototype.size",!0),Jd=!!Zd&&function(){var t,e={assert:function(i){if(!e.has(i))throw new sx("Side channel does not contain "+nx(i))},delete:function(i){if(t){var n=hx(t,i);return cx(t)===0&&(t=void 0),n}return!1},get:function(i){if(t)return ox(t,i)},has:function(i){return t?lx(t,i):!1},set:function(i,n){t||(t=new Zd),ax(t,i,n)}};return e},ux=fl,$s=Kd,dx=Os,Hs=Jd,fx=Hi,Yi=ux("%WeakMap%",!0),px=$s("WeakMap.prototype.get",!0),mx=$s("WeakMap.prototype.set",!0),gx=$s("WeakMap.prototype.has",!0),yx=$s("WeakMap.prototype.delete",!0),_x=Yi?function(){var t,e,i={assert:function(n){if(!i.has(n))throw new fx("Side channel does not contain "+dx(n))},delete:function(n){if(Yi&&n&&(typeof n=="object"||typeof n=="function")){if(t)return yx(t,n)}else if(Hs&&e)return e.delete(n);return!1},get:function(n){return Yi&&n&&(typeof n=="object"||typeof n=="function")&&t?px(t,n):e&&e.get(n)},has:function(n){return Yi&&n&&(typeof n=="object"||typeof n=="function")&&t?gx(t,n):!!e&&e.has(n)},set:function(n,s){Yi&&n&&(typeof n=="object"||typeof n=="function")?(t||(t=new Yi),mx(t,n,s)):Hs&&(e||(e=Hs()),e.set(n,s))}};return i}:Hs,vx=Hi,bx=Os,xx=H1,wx=Jd,Ex=_x,Tx=Ex||wx||xx,Ax=function(){var t,e={assert:function(i){if(!e.has(i))throw new vx("Side channel does not contain "+bx(i))},delete:function(i){return!!t&&t.delete(i)},get:function(i){return t&&t.get(i)},has:function(i){return!!t&&t.has(i)},set:function(i,n){t||(t=Tx()),t.set(i,n)}};return e},Sx=String.prototype.replace,Cx=/%20/g,pl={RFC1738:"RFC1738",RFC3986:"RFC3986"},ml={default:pl.RFC3986,formatters:{RFC1738:function(r){return Sx.call(r,Cx,"+")},RFC3986:function(r){return String(r)}},RFC1738:pl.RFC1738,RFC3986:pl.RFC3986},Ix=ml,gl=Object.prototype.hasOwnProperty,ai=Array.isArray,sr=function(){for(var r=[],t=0;t<256;++t)r.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return r}(),Px=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(ai(i)){for(var n=[],s=0;s<i.length;++s)typeof i[s]<"u"&&n.push(i[s]);e.obj[e.prop]=n}}},Qd=function(t,e){for(var i=e&&e.plainObjects?{__proto__:null}:{},n=0;n<t.length;++n)typeof t[n]<"u"&&(i[n]=t[n]);return i},Rx=function r(t,e,i){if(!e)return t;if(typeof e!="object"&&typeof e!="function"){if(ai(t))t.push(e);else if(t&&typeof t=="object")(i&&(i.plainObjects||i.allowPrototypes)||!gl.call(Object.prototype,e))&&(t[e]=!0);else return[t,e];return t}if(!t||typeof t!="object")return[t].concat(e);var n=t;return ai(t)&&!ai(e)&&(n=Qd(t,i)),ai(t)&&ai(e)?(e.forEach(function(s,o){if(gl.call(t,o)){var a=t[o];a&&typeof a=="object"&&s&&typeof s=="object"?t[o]=r(a,s,i):t.push(s)}else t[o]=s}),t):Object.keys(e).reduce(function(s,o){var a=e[o];return gl.call(s,o)?s[o]=r(s[o],a,i):s[o]=a,s},n)},Mx=function(t,e){return Object.keys(e).reduce(function(i,n){return i[n]=e[n],i},t)},Dx=function(r,t,e){var i=r.replace(/\+/g," ");if(e==="iso-8859-1")return i.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(i)}catch{return i}},yl=1024,Ox=function(t,e,i,n,s){if(t.length===0)return t;var o=t;if(typeof t=="symbol"?o=Symbol.prototype.toString.call(t):typeof t!="string"&&(o=String(t)),i==="iso-8859-1")return escape(o).replace(/%u[0-9a-f]{4}/gi,function(p){return"%26%23"+parseInt(p.slice(2),16)+"%3B"});for(var a="",l=0;l<o.length;l+=yl){for(var h=o.length>=yl?o.slice(l,l+yl):o,c=[],u=0;u<h.length;++u){var d=h.charCodeAt(u);if(d===45||d===46||d===95||d===126||d>=48&&d<=57||d>=65&&d<=90||d>=97&&d<=122||s===Ix.RFC1738&&(d===40||d===41)){c[c.length]=h.charAt(u);continue}if(d<128){c[c.length]=sr[d];continue}if(d<2048){c[c.length]=sr[192|d>>6]+sr[128|d&63];continue}if(d<55296||d>=57344){c[c.length]=sr[224|d>>12]+sr[128|d>>6&63]+sr[128|d&63];continue}u+=1,d=65536+((d&1023)<<10|h.charCodeAt(u)&1023),c[c.length]=sr[240|d>>18]+sr[128|d>>12&63]+sr[128|d>>6&63]+sr[128|d&63]}a+=c.join("")}return a},Lx=function(t){for(var e=[{obj:{o:t},prop:"o"}],i=[],n=0;n<e.length;++n)for(var s=e[n],o=s.obj[s.prop],a=Object.keys(o),l=0;l<a.length;++l){var h=a[l],c=o[h];typeof c=="object"&&c!==null&&i.indexOf(c)===-1&&(e.push({obj:o,prop:h}),i.push(c))}return Px(e),t},Bx=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},Nx=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},Fx=function(t,e){return[].concat(t,e)},kx=function(t,e){if(ai(t)){for(var i=[],n=0;n<t.length;n+=1)i.push(e(t[n]));return i}return e(t)},tf={arrayToObject:Qd,assign:Mx,combine:Fx,compact:Lx,decode:Dx,encode:Ox,isBuffer:Nx,isRegExp:Bx,maybeMap:kx,merge:Rx},ef=Ax,Xs=tf,Gn=ml,Ux=Object.prototype.hasOwnProperty,rf={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},or=Array.isArray,Gx=Array.prototype.push,nf=function(r,t){Gx.apply(r,or(t)?t:[t])},$x=Date.prototype.toISOString,sf=Gn.default,ie={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Xs.encode,encodeValuesOnly:!1,filter:void 0,format:sf,formatter:Gn.formatters[sf],indices:!1,serializeDate:function(t){return $x.call(t)},skipNulls:!1,strictNullHandling:!1},Hx=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},_l={},Xx=function r(t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,_,v,y){for(var g=t,b=y,C=0,R=!1;(b=b.get(_l))!==void 0&&!R;){var A=b.get(t);if(C+=1,typeof A<"u"){if(A===C)throw new RangeError("Cyclic object value");R=!0}typeof b.get(_l)>"u"&&(C=0)}if(typeof c=="function"?g=c(e,g):g instanceof Date?g=p(g):i==="comma"&&or(g)&&(g=Xs.maybeMap(g,function(O){return O instanceof Date?p(O):O})),g===null){if(o)return h&&!_?h(e,ie.encoder,v,"key",f):e;g=""}if(Hx(g)||Xs.isBuffer(g)){if(h){var P=_?e:h(e,ie.encoder,v,"key",f);return[m(P)+"="+m(h(g,ie.encoder,v,"value",f))]}return[m(e)+"="+m(String(g))]}var M=[];if(typeof g>"u")return M;var k;if(i==="comma"&&or(g))_&&h&&(g=Xs.maybeMap(g,h)),k=[{value:g.length>0?g.join(",")||null:void 0}];else if(or(c))k=c;else{var U=Object.keys(g);k=u?U.sort(u):U}var I=l?String(e).replace(/\./g,"%2E"):String(e),T=n&&or(g)&&g.length===1?I+"[]":I;if(s&&or(g)&&g.length===0)return T+"[]";for(var E=0;E<k.length;++E){var S=k[E],B=typeof S=="object"&&S&&typeof S.value<"u"?S.value:g[S];if(!(a&&B===null)){var D=d&&l?String(S).replace(/\./g,"%2E"):String(S),N=or(g)?typeof i=="function"?i(T,D):T:T+(d?"."+D:"["+D+"]");y.set(t,C);var H=ef();H.set(_l,y),nf(M,r(B,N,i,n,s,o,a,l,i==="comma"&&_&&or(g)?null:h,c,u,d,p,f,m,_,v,H))}}return M},Vx=function(t){if(!t)return ie;if(typeof t.allowEmptyArrays<"u"&&typeof t.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof t.encodeDotInKeys<"u"&&typeof t.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(t.encoder!==null&&typeof t.encoder<"u"&&typeof t.encoder!="function")throw new TypeError("Encoder has to be a function.");var e=t.charset||ie.charset;if(typeof t.charset<"u"&&t.charset!=="utf-8"&&t.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var i=Gn.default;if(typeof t.format<"u"){if(!Ux.call(Gn.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var n=Gn.formatters[i],s=ie.filter;(typeof t.filter=="function"||or(t.filter))&&(s=t.filter);var o;if(t.arrayFormat in rf?o=t.arrayFormat:"indices"in t?o=t.indices?"indices":"repeat":o=ie.arrayFormat,"commaRoundTrip"in t&&typeof t.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var a=typeof t.allowDots>"u"?t.encodeDotInKeys===!0?!0:ie.allowDots:!!t.allowDots;return{addQueryPrefix:typeof t.addQueryPrefix=="boolean"?t.addQueryPrefix:ie.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:ie.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:ie.charsetSentinel,commaRoundTrip:!!t.commaRoundTrip,delimiter:typeof t.delimiter>"u"?ie.delimiter:t.delimiter,encode:typeof t.encode=="boolean"?t.encode:ie.encode,encodeDotInKeys:typeof t.encodeDotInKeys=="boolean"?t.encodeDotInKeys:ie.encodeDotInKeys,encoder:typeof t.encoder=="function"?t.encoder:ie.encoder,encodeValuesOnly:typeof t.encodeValuesOnly=="boolean"?t.encodeValuesOnly:ie.encodeValuesOnly,filter:s,format:i,formatter:n,serializeDate:typeof t.serializeDate=="function"?t.serializeDate:ie.serializeDate,skipNulls:typeof t.skipNulls=="boolean"?t.skipNulls:ie.skipNulls,sort:typeof t.sort=="function"?t.sort:null,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:ie.strictNullHandling}},zx=function(r,t){var e=r,i=Vx(t),n,s;typeof i.filter=="function"?(s=i.filter,e=s("",e)):or(i.filter)&&(s=i.filter,n=s);var o=[];if(typeof e!="object"||e===null)return"";var a=rf[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var h=ef(),c=0;c<n.length;++c){var u=n[c],d=e[u];i.skipNulls&&d===null||nf(o,Xx(d,u,a,l,i.allowEmptyArrays,i.strictNullHandling,i.skipNulls,i.encodeDotInKeys,i.encode?i.encoder:null,i.filter,i.sort,i.allowDots,i.serializeDate,i.format,i.formatter,i.encodeValuesOnly,i.charset,h))}var p=o.join(i.delimiter),f=i.addQueryPrefix===!0?"?":"";return i.charsetSentinel&&(i.charset==="iso-8859-1"?f+="utf8=%26%2310003%3B&":f+="utf8=%E2%9C%93&"),p.length>0?f+p:""},li=tf,vl=Object.prototype.hasOwnProperty,of=Array.isArray,Wt={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:li.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1,throwOnLimitExceeded:!1},jx=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},af=function(r,t,e){if(r&&typeof r=="string"&&t.comma&&r.indexOf(",")>-1)return r.split(",");if(t.throwOnLimitExceeded&&e>=t.arrayLimit)throw new RangeError("Array limit exceeded. Only "+t.arrayLimit+" element"+(t.arrayLimit===1?"":"s")+" allowed in an array.");return r},Wx="utf8=%26%2310003%3B",Yx="utf8=%E2%9C%93",qx=function(t,e){var i={__proto__:null},n=e.ignoreQueryPrefix?t.replace(/^\?/,""):t;n=n.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var s=e.parameterLimit===1/0?void 0:e.parameterLimit,o=n.split(e.delimiter,e.throwOnLimitExceeded?s+1:s);if(e.throwOnLimitExceeded&&o.length>s)throw new RangeError("Parameter limit exceeded. Only "+s+" parameter"+(s===1?"":"s")+" allowed.");var a=-1,l,h=e.charset;if(e.charsetSentinel)for(l=0;l<o.length;++l)o[l].indexOf("utf8=")===0&&(o[l]===Yx?h="utf-8":o[l]===Wx&&(h="iso-8859-1"),a=l,l=o.length);for(l=0;l<o.length;++l)if(l!==a){var c=o[l],u=c.indexOf("]="),d=u===-1?c.indexOf("="):u+1,p,f;d===-1?(p=e.decoder(c,Wt.decoder,h,"key"),f=e.strictNullHandling?null:""):(p=e.decoder(c.slice(0,d),Wt.decoder,h,"key"),f=li.maybeMap(af(c.slice(d+1),e,of(i[p])?i[p].length:0),function(_){return e.decoder(_,Wt.decoder,h,"value")})),f&&e.interpretNumericEntities&&h==="iso-8859-1"&&(f=jx(String(f))),c.indexOf("[]=")>-1&&(f=of(f)?[f]:f);var m=vl.call(i,p);m&&e.duplicates==="combine"?i[p]=li.combine(i[p],f):(!m||e.duplicates==="last")&&(i[p]=f)}return i},Kx=function(r,t,e,i){var n=0;if(r.length>0&&r[r.length-1]==="[]"){var s=r.slice(0,-1).join("");n=Array.isArray(t)&&t[s]?t[s].length:0}for(var o=i?t:af(t,e,n),a=r.length-1;a>=0;--a){var l,h=r[a];if(h==="[]"&&e.parseArrays)l=e.allowEmptyArrays&&(o===""||e.strictNullHandling&&o===null)?[]:li.combine([],o);else{l=e.plainObjects?{__proto__:null}:{};var c=h.charAt(0)==="["&&h.charAt(h.length-1)==="]"?h.slice(1,-1):h,u=e.decodeDotInKeys?c.replace(/%2E/g,"."):c,d=parseInt(u,10);!e.parseArrays&&u===""?l={0:o}:!isNaN(d)&&h!==u&&String(d)===u&&d>=0&&e.parseArrays&&d<=e.arrayLimit?(l=[],l[d]=o):u!=="__proto__"&&(l[u]=o)}o=l}return o},Zx=function(t,e,i,n){if(t){var s=i.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,l=i.depth>0&&o.exec(s),h=l?s.slice(0,l.index):s,c=[];if(h){if(!i.plainObjects&&vl.call(Object.prototype,h)&&!i.allowPrototypes)return;c.push(h)}for(var u=0;i.depth>0&&(l=a.exec(s))!==null&&u<i.depth;){if(u+=1,!i.plainObjects&&vl.call(Object.prototype,l[1].slice(1,-1))&&!i.allowPrototypes)return;c.push(l[1])}if(l){if(i.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+i.depth+" and strictDepth is true");c.push("["+s.slice(l.index)+"]")}return Kx(c,e,i,n)}},Jx=function(t){if(!t)return Wt;if(typeof t.allowEmptyArrays<"u"&&typeof t.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof t.decodeDotInKeys<"u"&&typeof t.decodeDotInKeys!="boolean")throw new TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(t.decoder!==null&&typeof t.decoder<"u"&&typeof t.decoder!="function")throw new TypeError("Decoder has to be a function.");if(typeof t.charset<"u"&&t.charset!=="utf-8"&&t.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");if(typeof t.throwOnLimitExceeded<"u"&&typeof t.throwOnLimitExceeded!="boolean")throw new TypeError("`throwOnLimitExceeded` option must be a boolean");var e=typeof t.charset>"u"?Wt.charset:t.charset,i=typeof t.duplicates>"u"?Wt.duplicates:t.duplicates;if(i!=="combine"&&i!=="first"&&i!=="last")throw new TypeError("The duplicates option must be either combine, first, or last");var n=typeof t.allowDots>"u"?t.decodeDotInKeys===!0?!0:Wt.allowDots:!!t.allowDots;return{allowDots:n,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:Wt.allowEmptyArrays,allowPrototypes:typeof t.allowPrototypes=="boolean"?t.allowPrototypes:Wt.allowPrototypes,allowSparse:typeof t.allowSparse=="boolean"?t.allowSparse:Wt.allowSparse,arrayLimit:typeof t.arrayLimit=="number"?t.arrayLimit:Wt.arrayLimit,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:Wt.charsetSentinel,comma:typeof t.comma=="boolean"?t.comma:Wt.comma,decodeDotInKeys:typeof t.decodeDotInKeys=="boolean"?t.decodeDotInKeys:Wt.decodeDotInKeys,decoder:typeof t.decoder=="function"?t.decoder:Wt.decoder,delimiter:typeof t.delimiter=="string"||li.isRegExp(t.delimiter)?t.delimiter:Wt.delimiter,depth:typeof t.depth=="number"||t.depth===!1?+t.depth:Wt.depth,duplicates:i,ignoreQueryPrefix:t.ignoreQueryPrefix===!0,interpretNumericEntities:typeof t.interpretNumericEntities=="boolean"?t.interpretNumericEntities:Wt.interpretNumericEntities,parameterLimit:typeof t.parameterLimit=="number"?t.parameterLimit:Wt.parameterLimit,parseArrays:t.parseArrays!==!1,plainObjects:typeof t.plainObjects=="boolean"?t.plainObjects:Wt.plainObjects,strictDepth:typeof t.strictDepth=="boolean"?!!t.strictDepth:Wt.strictDepth,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:Wt.strictNullHandling,throwOnLimitExceeded:typeof t.throwOnLimitExceeded=="boolean"?t.throwOnLimitExceeded:!1}},Qx=function(r,t){var e=Jx(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?{__proto__:null}:{};for(var i=typeof r=="string"?qx(r,e):r,n=e.plainObjects?{__proto__:null}:{},s=Object.keys(i),o=0;o<s.length;++o){var a=s[o],l=Zx(a,i[a],e,typeof r=="string");n=li.merge(n,l,e)}return e.allowSparse===!0?n:li.compact(n)},tw=zx,ew=Qx,rw=ml,iw={formats:rw,parse:ew,stringify:tw},nw=o1;function vr(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var sw=/^([a-z0-9.+-]+:)/i,ow=/:[0-9]*$/,aw=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,lw=["<",">",'"',"`"," ","\r",`