@annotorious/openseadragon 3.7.6 → 3.7.7

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(qt,se){typeof exports=="object"&&typeof module<"u"?se(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],se):(qt=typeof globalThis<"u"?globalThis:qt||self,se(qt.AnnotoriousOSD={},qt.OpenSeadragon))})(this,function(qt,se){"use strict";var hC=Object.defineProperty;var cC=(qt,se,qr)=>se in qt?hC(qt,se,{enumerable:!0,configurable:!0,writable:!0,value:qr}):qt[se]=qr;var Nh=(qt,se,qr)=>cC(qt,typeof se!="symbol"?se+"":se,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 fe=[];for(let r=0;r<256;++r)fe.push((r+256).toString(16).slice(1));function ig(r,t=0){return(fe[r[t+0]]+fe[r[t+1]]+fe[r[t+2]]+fe[r[t+3]]+"-"+fe[r[t+4]]+fe[r[t+5]]+"-"+fe[r[t+6]]+fe[r[t+7]]+"-"+fe[r[t+8]]+fe[r[t+9]]+"-"+fe[r[t+10]]+fe[r[t+11]]+fe[r[t+12]]+fe[r[t+13]]+fe[r[t+14]]+fe[r[t+15]]).toLowerCase()}let $o;const ng=new Uint8Array(16);function sg(){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(ng)}const og=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Vh={randomUUID:og};function ag(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??sg();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,ig(n)}function lg(r,t,e){return Vh.randomUUID&&!r?Vh.randomUUID():ag(r)}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)}},hg=(r,t,e,i)=>({id:lg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),cg=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},ug=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},dg=(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})),fg=(r,t)=>!Kr(r.target,t.target),pg=(r,t)=>{const e=cg(r,t),i=ug(r,t),n=dg(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:fg(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 mg=(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 pg(d,f)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let gg=()=>({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 yg=250,_g=(r,t)=>{const e=gg(),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,y=performance.now();if(y-o>yg)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=mg(i[_],m)}o=y}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:y}=i[n+1];h(f),u(m),p(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:f,updated:m,deleted:y}=i[n];l(f),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},vg=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},p=(_,v)=>{const g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},f=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(S,R)}else b(v,g)})},1)},m=()=>{const{selected:_}=s,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const b=h.find(S=>S.id===g.id);(!b||!Kr(b,g))&&f("updateAnnotation",g,b)}),h=h.map(g=>v.find(({id:S})=>S===g.id)||g)};s.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Kr(g,v)&&f("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(b=>b.id)),g=new Set(_.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const S=o.getAnnotation(b.id);S&&!Kr(S,b)&&f("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}f("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?f("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?f("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(f("mouseLeaveAnnotation",o.getAnnotation(c)),f("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>f("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(b=>f("createAnnotation",b)),(g||[]).forEach(b=>f("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:S})=>{const R=h.find(C=>C.id===b.id)||b;h=h.map(C=>C.id===b.id?S:C),f("updateAnnotation",S,R)})},{origin:Pr.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(b=>b.id)),g=(_.changes.updated||[]).filter(({newValue:b})=>v.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 y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>f("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>f("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:p,emit:f}},bg=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:[]}),xg=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Pr.REMOTE):console.error(g)}else i.addAnnotation(Ho(_),Pr.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var _;const v=(((_=n.selected)==null?void 0:_.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(p(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},p=(_,v=!0)=>{if(e){const g=e.parseAll||bg(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Pr.REMOTE)}else i.bulkAddAnnotations(_.map(Ho),v,Pr.REMOTE)},f=(_,v)=>{_?n.setSelected(_,v):n.clear()},m=_=>{n.clear(),n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(Ho(_)),v}};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:y}},wg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Eg=r=>crypto.getRandomValues(new Uint8Array(r)),Tg=(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}}},Ag=(r,t=21)=>Tg(r,t|0,Eg),Sg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=wg[e[r]&63];return t};const Cg=()=>({isGuest:!0,id:Ag("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Ig=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Pg=()=>{const r=[...Ig];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};Sg();var Rg=Object.defineProperty,Mg=(r,t,e)=>t in r?Rg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,zh=(r,t,e)=>Mg(r,typeof t!="symbol"?t+"":t,e);function Rt(){}function Xo(r,t){for(const e in t)r[e]=t[e];return r}function jh(r){return r()}function Wh(){return Object.create(null)}function Me(r){r.forEach(jh)}function Gt(r){return typeof r=="function"}function Kt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Dg(r){return Object.keys(r).length===0}function Yh(r,...t){if(r==null){for(const i of t)i(void 0);return Rt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Vo(r,t,e){r.$$.on_destroy.push(Yh(t,e))}function Bg(r,t,e,i){if(r){const n=qh(r,t,e,i);return r[0](n)}}function qh(r,t,e,i){return r[1]&&i?Xo(e.ctx.slice(),r[1](i(t))):e.ctx}function Og(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 Lg(r,t,e,i,n,s){if(n){const o=qh(t,e,i,s);r.p(o,n)}}function Ng(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 Kh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Ei(r){return r??""}function xt(r,t){r.appendChild(t)}function nt(r,t,e){r.insertBefore(t,e||null)}function rt(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 Zh(r){return document.createTextNode(r)}function we(){return Zh(" ")}function De(){return Zh("")}function St(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 Fg(r){return Array.from(r.childNodes)}function Je(r,t,e){r.classList.toggle(t,!!e)}function kg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let yn;function _n(r){yn=r}function Jh(){if(!yn)throw new Error("Function called outside component initialization");return yn}function Jr(r){Jh().$$.on_mount.push(r)}function Rr(){const r=Jh();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=kg(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function oe(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Ti=[],os=[];let Ai=[];const Qh=[],tc=Promise.resolve();let zo=!1;function ec(){zo||(zo=!0,tc.then(ic))}function rc(){return ec(),tc}function jo(r){Ai.push(r)}const Wo=new Set;let Si=0;function ic(){if(Si!==0)return;const r=yn;do{try{for(;Si<Ti.length;){const t=Ti[Si];Si++,_n(t),Ug(t.$$)}}catch(t){throw Ti.length=0,Si=0,t}for(_n(null),Ti.length=0,Si=0;os.length;)os.pop()();for(let t=0;t<Ai.length;t+=1){const e=Ai[t];Wo.has(e)||(Wo.add(e),e())}Ai.length=0}while(Ti.length);for(;Qh.length;)Qh.pop()();zo=!1,Wo.clear(),_n(r)}function Ug(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 Gg(r){const t=[],e=[];Ai.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ai=t}const as=new Set;let Qr;function Ee(){Qr={r:0,c:[],p:Qr}}function Te(){Qr.r||Me(Qr.c),Qr=Qr.p}function lt(r,t){r&&r.i&&(as.delete(r),r.i(t))}function yt(r,t,e,i){if(r&&r.o){if(as.has(r))return;as.add(r),Qr.c.push(()=>{as.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 re(r){r&&r.c()}function Qt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),jo(()=>{const s=r.$$.on_mount.map(jh).filter(Gt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Me(s),r.$$.on_mount=[]}),n.forEach(jo)}function te(r,t){const e=r.$$;e.fragment!==null&&(Gg(e.after_update),Me(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&&(Ti.push(r),ec(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function pe(r,t,e,i,n,s,o=null,a=[-1]){const l=yn;_n(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Rt,not_equal:n,bound:Wh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Wh(),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,Me(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=Fg(t.target);h.fragment&&h.fragment.l(u),u.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&lt(r.$$.fragment),Qt(r,t.target,t.anchor),ic()}_n(l)}class me{constructor(){zh(this,"$$"),zh(this,"$$set")}$destroy(){te(this,1),this.$destroy=Rt}$on(t,e){if(!Gt(e))return Rt;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&&!Dg(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Hg="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Hg);var _t=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(_t||{}),Xg={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})()})(Xg);const Yo={},Ci=(r,t)=>Yo[r]=t,qo=r=>Yo[r.type].area(r),Vg=(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}},ls=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)},hs=(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},zg=(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},cs=(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))},jg={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}};Ci(_t.ELLIPSE,jg);const Wg={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=cs([n,s],[o,a]);return l/h<=i}};Ci(_t.LINE,Wg);const Yg={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=ls(n.points),a=s.reduce((l,h)=>l+ls(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(hs(s.points,t,e)){let a=!1;for(const l of o)if(hs(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)},He=r=>r.rings.map(t=>zg(t.points)).join(" "),qg=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Ci(_t.MULTIPOLYGON,Yg);const Kg={area:r=>{const t=r.geometry.points;return ls(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return hs(i,t,e)}};Ci(_t.POLYGON,Kg);const Zg={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Zo(t.points,t.closed);return ls(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Zo(n.points,n.closed);return hs(s,t,e)}else return Jg(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=nc(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);e.push(...o.slice(1))}}return e},nc=(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},Jg=(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.type==="CURVE"||s.type==="CURVE"){const o=nc(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let a=0;a<o.length-1;a++)if(sc(t,o[a],o[a+1])<=e)return!0}else if(sc(t,n.point,s.point)<=e)return!0}return!1},sc=(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.type==="CURVE"||n.type==="CURVE"){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(" ")};Ci(_t.POLYLINE,Zg);const Qg={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};Ci(_t.RECTANGLE,Qg);const Le=r=>us(r.target),us=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},ty=(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:_t.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}}}},ey=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}`}},oc="http://www.w3.org/2000/svg",ac=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},ry=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${oc}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},ds=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(oc),i=t.lookupNamespaceURI(null);return e||i?ac(t).firstChild:ac(ry(t)).firstChild},iy=r=>{const t=lc(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}}},ny=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},sy=r=>{const t=lc(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=>ny(o)?{...o,locked:!0}:o);const s=Ae(Zo(e,n));return{points:e,closed:n,bounds:s}},lc=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},oy=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],n=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:_t.POLYGON,geometry:{points:n,bounds:Ae(n)}}},ay=r=>{const t=ds(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:_t.ELLIPSE,geometry:{cx:e,cy:i,rx:n,ry:s,bounds:o}}},ly=r=>{const t=ds(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:_t.LINE,geometry:{points:[[e,n],[i,s]],bounds:o}}},hy=r=>{const t=ds(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=sy(i);if(!n)throw new Error("Could not parse SVG path");return{type:_t.POLYLINE,geometry:n}},cy=r=>{const t=ds(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>iy(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:_t.POLYGON,geometry:{points:i,bounds:n}}:{type:_t.MULTIPOLYGON,geometry:{polygons:e,bounds:n}}},uy=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return oy(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return hy(t);if(t.includes("<path "))return cy(t);if(t.includes("<ellipse "))return ay(t);if(t.includes("<line "))return ly(t);throw"Unsupported SVG shape: "+t},dy=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${He(t)}" />`).join("")}</g>`,fy=r=>{let t;switch(r.type){case _t.POLYGON:{const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(n=>n.join(",")).join(" ")}" /></svg>`;break}case _t.ELLIPSE:{const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`;break}case _t.MULTIPOLYGON:{const e=r.geometry;t=`<svg>${dy(e)}</svg>`;break}case _t.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 _t.POLYLINE:t=`<svg><path d="${Jo(r.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},ge=[];for(let r=0;r<256;++r)ge.push((r+256).toString(16).slice(1));function py(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 Qo;const my=new Uint8Array(16);function gy(){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(my)}const yy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),hc={randomUUID:yy};function _y(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??gy();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,py(n)}function cc(r,t,e){return hc.randomUUID&&!r?hc.randomUUID():_y(r)}var uc=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(uc.call(r,e)&&++i&&!uc.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 vy(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const Ii=[];function ea(r,t=ta){let e;const i=new Set;function n(a){if(vy(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=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 by=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 dc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(dc||{});const fs={selected:[]},xy=(r,t,e)=>{const{subscribe:i,set:n}=ea(fs);let s=t,o=fs;i(m=>o=m);const a=()=>{Mr(o,fs)||n(fs)},l=()=>{var m;return((m=o.selected)==null?void 0:m.length)===0},h=m=>{if(l())return!1;const y=typeof m=="string"?m:m.id;return o.selected.some(_=>_.id===y)},c=(m,y)=>{let _;if(Array.isArray(m)){if(_=m.map(g=>r.getAnnotation(g)).filter(Boolean),_.length<m.length){console.warn("Invalid selection: "+m.filter(g=>!_.some(b=>b.id===g)));return}}else{const g=r.getAnnotation(m);if(!g){console.warn("Invalid selection: "+m);return}_=[g]}const v=_.reduce((g,b)=>{const S=f(b);return S==="EDIT"?[...g,{id:b.id,editable:!0}]:S==="SELECT"?[...g,{id:b.id}]:g},[]);n({selected:v,event:y})},u=(m,y)=>{const _=Array.isArray(m)?m:[m],v=_.map(g=>r.getAnnotation(g)).filter(g=>!!g);n({selected:v.map(g=>{const b=y===void 0?f(g)==="EDIT":y;return{id:g.id,editable:b}})}),v.length!==_.length&&console.warn("Invalid selection",m)},d=m=>{if(l())return!1;const{selected:y}=o;y.some(({id:_})=>m.includes(_))&&n({selected:y.filter(({id:_})=>!m.includes(_))})},p=m=>{s=m,u(o.selected.map(({id:y})=>y))},f=m=>wy(m,s,e);return r.observe(({changes:m})=>d((m.deleted||[]).map(y=>y.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}},wy=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},ye=[];for(let r=0;r<256;++r)ye.push((r+256).toString(16).slice(1));function Ey(r,t=0){return(ye[r[t+0]]+ye[r[t+1]]+ye[r[t+2]]+ye[r[t+3]]+"-"+ye[r[t+4]]+ye[r[t+5]]+"-"+ye[r[t+6]]+ye[r[t+7]]+"-"+ye[r[t+8]]+ye[r[t+9]]+"-"+ye[r[t+10]]+ye[r[t+11]]+ye[r[t+12]]+ye[r[t+13]]+ye[r[t+14]]+ye[r[t+15]]).toLowerCase()}let ra;const Ty=new Uint8Array(16);function Ay(){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(Ty)}const Sy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),fc={randomUUID:Sy};function Cy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Ay();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,Ey(n)}function Iy(r,t,e){return fc.randomUUID&&!r?fc.randomUUID():Cy(r)}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)}},Py=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Ry=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},My=(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})),Dy=(r,t)=>!Mr(r.target,t.target),pc=(r,t)=>{const e=Py(r,t),i=Ry(r,t),n=My(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:Dy(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 By=(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},Oy=(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 pc(d,f)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},ps=r=>{const t=r.id===void 0?Iy():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Ly=r=>r.id!==void 0,Ny=()=>{const r=new Map,t=new Map,e=[],i=(P,T={})=>{e.push({onChange:P,options:T})},n=P=>{const T=e.findIndex(E=>E.onChange==P);T>-1&&e.splice(T,1)},s=(P,T)=>{const E={origin:P,changes:{created:T.created||[],updated:T.updated||[],deleted:T.deleted||[]},state:[...r.values()]};e.forEach(A=>{By(A,E)&&A.onChange(E)})},o=(P,T=Nt.LOCAL)=>{if(P.id&&r.get(P.id))throw Error(`Cannot add annotation ${P.id} - exists already`);{const E=ps(P);r.set(E.id,E),E.bodies.forEach(A=>t.set(A.id,E.id)),s(T,{created:[E]})}},a=(P,T)=>{const E=ps(typeof P=="string"?T:P),A=typeof P=="string"?P:P.id,L=A&&r.get(A);if(L){const D=pc(L,E);return A===E.id?r.set(A,E):(r.delete(A),r.set(E.id,E)),L.bodies.forEach(N=>t.delete(N.id)),E.bodies.forEach(N=>t.set(N.id,E.id)),D}else console.warn(`Cannot update annotation ${A} - does not exist`)},l=(P,T=Nt.LOCAL,E=Nt.LOCAL)=>{const A=Ly(T)?E:T,L=a(P,T);L&&s(A,{updated:[L]})},h=(P,T=Nt.LOCAL)=>{r.get(P.id)?l(P,T):o(P,T)},c=(P,T=Nt.LOCAL)=>{const E=P.reduce((A,L)=>{const D=a(L);return D?[...A,D]:A},[]);E.length>0&&s(T,{updated:E})},u=(P,T=Nt.LOCAL)=>{const E=P.map(ps),{toAdd:A,toUpdate:L}=E.reduce((N,$)=>r.get($.id)?{...N,toUpdate:[...N.toUpdate,$]}:{...N,toAdd:[...N.toAdd,$]},{toAdd:[],toUpdate:[]}),D=L.map(N=>a(N,T)).filter(Boolean);A.forEach(N=>{r.set(N.id,N),N.bodies.forEach($=>t.set($.id,N.id))}),s(T,{created:A,updated:D})},d=(P,T=Nt.LOCAL)=>{const E=r.get(P.annotation);if(E){const A={...E,bodies:[...E.bodies,P]};r.set(E.id,A),t.set(P.id,A.id),s(T,{updated:[{oldValue:E,newValue:A,bodiesCreated:[P]}]})}else console.warn(`Attempt to add body to missing annotation: ${P.annotation}`)},p=()=>[...r.values()],f=(P=Nt.LOCAL)=>{const T=[...r.values()];r.clear(),t.clear(),s(P,{deleted:T})},m=(P,T=!0,E=Nt.LOCAL)=>{const A=P.map(ps);if(T){const L=[...r.values()];r.clear(),t.clear(),A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:A,deleted:L})}else{const L=P.reduce((D,N)=>{const $=N.id&&r.get(N.id);return $?[...D,$]:D},[]);if(L.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${L.map(D=>D.id).join(", ")}`);A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:A})}},y=P=>{const T=typeof P=="string"?P:P.id,E=r.get(T);if(E)return r.delete(T),E.bodies.forEach(A=>t.delete(A.id)),E;console.warn(`Attempt to delete missing annotation: ${T}`)},_=(P,T=Nt.LOCAL)=>{const E=y(P);E&&s(T,{deleted:[E]})},v=(P,T=Nt.LOCAL)=>{const E=P.reduce((A,L)=>{const D=y(L);return D?[...A,D]:A},[]);E.length>0&&s(T,{deleted:E})},g=P=>{const T=r.get(P.annotation);if(T){const E=T.bodies.find(A=>A.id===P.id);if(E){t.delete(E.id);const A={...T,bodies:T.bodies.filter(L=>L.id!==P.id)};return r.set(T.id,A),{oldValue:T,newValue:A,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${P.id} from annotation ${P.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${P.annotation}`)},b=(P,T=Nt.LOCAL)=>{const E=g(P);E&&s(T,{updated:[E]})},S=(P,T=Nt.LOCAL)=>{const E=P.map(A=>g(A)).filter(Boolean);E.length>0&&s(T,{updated:E})},R=P=>{const T=r.get(P);return T?{...T}:void 0},C=P=>{const T=t.get(P);if(T){const E=R(T).bodies.find(A=>A.id===P);if(E)return E;console.error(`Store integrity error: body ${P} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${P}`)},I=(P,T)=>{if(P.annotation!==T.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=r.get(P.annotation);if(E){const A=E.bodies.find(D=>D.id===P.id),L={...E,bodies:E.bodies.map(D=>D.id===A.id?T:D)};return r.set(E.id,L),A.id!==T.id&&(t.delete(A.id),t.set(T.id,L.id)),{oldValue:E,newValue:L,bodiesUpdated:[{oldBody:A,newBody:T}]}}else console.warn(`Attempt to add body to missing annotation ${P.annotation}`)},M=(P,T,E=Nt.LOCAL)=>{const A=I(P,T);A&&s(E,{updated:[A]})},F=(P,T=Nt.LOCAL)=>{const E=P.map(A=>I({id:A.id,annotation:A.annotation},A)).filter(Boolean);s(T,{updated:E})},U=P=>{const T=r.get(P.annotation);if(T){const E={...T,target:{...T.target,...P}};return r.set(T.id,E),{oldValue:T,newValue:E,targetUpdated:{oldTarget:T.target,newTarget:P}}}else console.warn(`Attempt to update target on missing annotation: ${P.annotation}`)};return{addAnnotation:o,addBody:d,all:p,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:S,bulkUpdateAnnotations:c,bulkUpdateBodies:F,bulkUpdateTargets:(P,T=Nt.LOCAL)=>{const E=P.map(A=>U(A)).filter(Boolean);E.length>0&&s(T,{updated:E})},bulkUpsertAnnotations:u,clear:f,deleteAnnotation:_,deleteBody:b,getAnnotation:R,getBody:C,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(P,T=Nt.LOCAL)=>{const E=U(P);E&&s(T,{updated:[E]})},upsertAnnotation:h}},Fy=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let ky=()=>({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 Uy=250,Gy=(r,t)=>{const e=ky(),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,y=performance.now();if(y-o>Uy)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=Oy(i[_],m)}o=y}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:y}=i[n+1];h(f),u(m),p(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:f,updated:m,deleted:y}=i[n];l(f),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},$y=()=>{const{subscribe:r,set:t}=ea([]);return{subscribe:r,set:t}},Hy=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},p=(_,v)=>{const g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},f=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(S,R)}else b(v,g)})},1)},m=()=>{const{selected:_}=s,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const b=h.find(S=>S.id===g.id);(!b||!Mr(b,g))&&f("updateAnnotation",g,b)}),h=h.map(g=>v.find(({id:b})=>b===g.id)||g)};s.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Mr(g,v)&&f("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(b=>b.id)),g=new Set(_.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const S=o.getAnnotation(b.id);S&&!Mr(S,b)&&f("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}f("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?f("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?f("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(f("mouseLeaveAnnotation",o.getAnnotation(c)),f("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>f("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(b=>f("createAnnotation",b)),(g||[]).forEach(b=>f("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:S})=>{const R=h.find(C=>C.id===b.id)||b;h=h.map(C=>C.id===b.id?S:C),f("updateAnnotation",S,R)})},{origin:Nt.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(b=>b.id)),g=(_.changes.updated||[]).filter(({newValue:b})=>v.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(S=>S.id===b.id)||b))}},{origin:Nt.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>f("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>f("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:p,emit:f}},Xy=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:[]}),Vy=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Nt.REMOTE):console.error(g)}else i.addAnnotation(ia(_),Nt.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var _;const v=(((_=n.selected)==null?void 0:_.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(p(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},p=(_,v=!0)=>{if(e){const g=e.parseAll||Xy(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Nt.REMOTE)}else i.bulkAddAnnotations(_.map(ia),v,Nt.REMOTE)},f=(_,v)=>{_?n.setSelected(_,v):n.clear()},m=_=>{n.clear(),n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(ia(_)),v}};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:y}},zy=(r,t,e)=>typeof t=="function"?t(r,e):t,jy=(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||{}}},Wy="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Yy=r=>crypto.getRandomValues(new Uint8Array(r)),qy=(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}}},Ky=(r,t=21)=>qy(r,t|0,Yy),Zy=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Wy[e[r]&63];return t};const Jy=()=>({isGuest:!0,id:Ky("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Qy=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}`},mc=r=>r?typeof r=="object"?{...r}:r:void 0,t0=(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-${Qy(e)}`,annotation:t,type:n,purpose:s,value:o,creator:mc(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),e0=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});Zy();const r0=(r,t={strict:!0,invertY:!1})=>({parse:e=>i0(e,t),serialize:e=>n0(e,r,t)}),i0=(r,t={strict:!0,invertY:!1})=>{const e=r.id||cc(),{creator:i,created:n,modified:s,body:o,...a}=r,l=t0(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"?ty(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?uy(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:mc(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},n0=(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==_t.RECTANGLE?ey(i.geometry):fy(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:e0(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},Pi=[];function s0(r,t=Rt){let e;const i=new Set;function n(a){if(Kt(r,a)&&(r=a,e)){const l=!Pi.length;for(const h of i)h[1](),Pi.push(h,r);if(l){for(let h=0;h<Pi.length;h+=2)Pi[h][0](Pi[h+1]);Pi.length=0}}}function s(a){n(a(r))}function o(a,l=Rt){const h=[a,l];return i.add(h),i.size===1&&(e=t(n,s)||Rt),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:n,update:s,subscribe:o}}const o0=(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}`)},a0=(r,t)=>{o0(r,t);const{subscribe:e,set:i}=s0(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};`),n||n===0?l+=`fill-opacity:${n};`:i&&(l+="fill-opacity:0.25;"),s&&(l+=`stroke:${s};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},ms=(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}},Ne=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,l0=r=>({}),gc=r=>({grab:r[0]});function h0(r){let t,e,i,n;const s=r[8].default,o=Bg(s,r,r[7],gc);return{c(){t=W("g"),o&&o.c(),x(t,"class","a9s-annotation selected")},m(a,l){nt(a,t,l),o&&o.m(t,null),e=!0,i||(n=[St(t,"pointerup",r[2]),St(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Lg(o,s,a,a[7],e?Og(s,a[7],l,l0):Ng(a[7]),gc)},i(a){e||(lt(o,a),e=!0)},o(a){yt(o,a),e=!1},d(a){a&&rt(t),o&&o.d(a),i=!1,Me(n)}}}function c0(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=y=>_=>{if(c=y,h){const{left:v,top:g}=h.getBoundingClientRect(),b=_.clientX-v,S=_.clientY-g;u=l.elementToImage(b,S)}else{const{offsetX:v,offsetY:g}=_;u=l.elementToImage(v,g)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},f=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),g=[_-u[0],v-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,d=o,s("release",y)};return r.$$set=y=>{"shape"in y&&e(3,o=y.shape),"editor"in y&&e(4,a=y.editor),"transform"in y&&e(5,l=y.transform),"svgEl"in y&&e(6,h=y.svgEl),"$$scope"in y&&e(7,n=y.$$scope)},[p,f,m,o,a,l,h,n,i]}class na extends me{constructor(t){super(),pe(this,t,c0,h0,Kt,{shape:3,editor:4,transform:5,svgEl:6})}}function u0(r){let t,e,i,n,s,o,a,l,h=r[3]&&yc(r);return{c(){t=W("g"),e=W("circle"),h&&h.c(),n=W("circle"),x(e,"class","a9s-handle-buffer svelte-qtyc7s"),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=Ei(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),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){nt(c,t,u),xt(t,e),h&&h.m(t,null),xt(t,n),a||(l=[St(e,"dblclick",r[12]),St(e,"pointerenter",r[13]),St(e,"pointerleave",r[14]),St(e,"pointerdown",r[15]),St(e,"pointerdown",r[6]),St(e,"pointerup",r[16]),St(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=yc(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Ei(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&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&&rt(t),h&&h.d(),a=!1,Me(l)}}}function d0(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"),Je(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 svelte-qtyc7s"),x(n,"role","button"),x(n,"tabindex","0"),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){nt(c,t,u),xt(t,e),xt(t,n),xt(t,o),l||(h=[St(n,"dblclick",r[9]),St(n,"pointerdown",r[10]),St(n,"pointerdown",r[6]),St(n,"pointerup",r[11]),St(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&&Je(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&&rt(t),l=!1,Me(h)}}}function yc(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){nt(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&&rt(t)}}}function f0(r){let t;function e(n,s){return Ne?d0:u0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),nt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&rt(t),i.d(n)}}}function p0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=g=>{g.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(g){oe.call(this,r,g)}function d(g){oe.call(this,r,g)}function p(g){oe.call(this,r,g)}function f(g){oe.call(this,r,g)}function m(g){oe.call(this,r,g)}function y(g){oe.call(this,r,g)}function _(g){oe.call(this,r,g)}function v(g){oe.call(this,r,g)}return r.$$set=g=>{e(8,t=Xo(Xo({},t),Kh(g))),"x"in g&&e(0,n=g.x),"y"in g&&e(1,s=g.y),"scale"in g&&e(2,o=g.scale),"selected"in g&&e(3,a=g.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Kh(t),[n,s,o,a,l,i,h,c,t,u,d,p,f,m,y,_,v]}class Ri extends me{constructor(t){super(),pe(this,t,p0,f0,Kt,{x:0,y:1,scale:2,selected:3})}}function m0(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){nt(l,t,h),xt(t,e),xt(t,n),xt(t,s),o||(a=[St(e,"pointerdown",r[5]),St(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&&rt(t),o=!1,Me(a)}}}function g0(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){nt(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&&rt(t)}}}function y0(r){let t;function e(n,s){return Ne?g0:m0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),nt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&rt(t),i.d(n)}}}function _0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){oe.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 _c extends me{constructor(t){super(),pe(this,t,_0,y0,Kt,{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 vc(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 bc(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=vn/r[3]),x(t,"class","svelte-1h2slbm")},m(s,o){nt(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=vn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function xc(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=vn/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){nt(u,t,d),xt(t,e),xt(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=vn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function wc(r){let t,e;return t=new Ri({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function Ec(r){let t,e;return t=new _c({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function v0(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&bc(aa(r)),C=r[6]!==void 0&&!r[7]&&xc(oa(r)),I=Ie(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=wc(vc(r,I,P));const F=P=>yt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Ec(sa(r));return{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("polygon"),R&&R.c(),C&&C.c(),c=we(),u=W("polygon"),p=we(),f=W("polygon"),y=we();for(let P=0;P<M.length;P+=1)M[P].c();_=we(),U&&U.c(),v=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(Tc).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(Ac).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(Sc).join(" "))},m(P,T){nt(P,t,T),xt(t,e),xt(e,i),xt(e,l),R&&R.m(e,null),C&&C.m(t,null),nt(P,c,T),nt(P,u,T),nt(P,p,T),nt(P,f,T),nt(P,y,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(P,T);nt(P,_,T),U&&U.m(P,T),nt(P,v,T),g=!0,b||(S=[St(u,"pointerup",r[14]),St(u,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),St(f,"pointermove",r[13]),St(f,"pointerup",r[14]),St(f,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,T){if(r=P,(!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(Tc).join(" ")))&&x(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(aa(r),T):(R=bc(aa(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(oa(r),T):(C=xc(oa(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||T[0]&32&&d!==(d=r[5].points.map(Ac).join(" ")))&&x(u,"points",d),(!g||T[0]&2)&&x(f,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Sc).join(" ")))&&x(f,"points",m),T[0]&134322472){I=Ie(r[5].points);let E;for(E=0;E<I.length;E+=1){const A=vc(r,I,E);M[E]?(M[E].p(A,T),lt(M[E],1)):(M[E]=wc(A),M[E].c(),lt(M[E],1),M[E].m(_.parentNode,_))}for(Ee(),E=I.length;E<M.length;E+=1)F(E);Te()}r[6]!==void 0&&!r[7]?U?(U.p(sa(r),T),T[0]&192&&lt(U,1)):(U=Ec(sa(r)),U.c(),lt(U,1),U.m(v.parentNode,v)):U&&(Ee(),yt(U,1,1,()=>{U=null}),Te())},i(P){if(!g){for(let T=0;T<I.length;T+=1)lt(M[T]);lt(U),g=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)yt(M[T]);yt(U),g=!1},d(P){P&&(rt(t),rt(c),rt(u),rt(p),rt(f),rt(y),rt(_),rt(v)),R&&R.d(),C&&C.d(),Zr(M,P),U&&U.d(P),b=!1,Me(S)}}}function b0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[v0,({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const x0=250,w0=1e3,E0=12,vn=4.5,Tc=r=>r.join(","),Ac=r=>r.join(","),Sc=r=>r.join(",");function T0(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 y=()=>e(7,p=!0),_=()=>e(7,p=!1),v=E=>{if(m.length>0||!n.some(B=>B.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(E.offsetX,E.offsetY),D=B=>Math.pow(B[0]-A,2)+Math.pow(B[1]-L,2),N=i.points.reduce((B,k)=>D(k)<D(B)?k:B),$=n.filter(B=>B.visible).reduce((B,k)=>D(k.point)<D(B.point)?k:B),O=Math.pow(w0/c,2);D(N)<O||D($.point)<O?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=E=>{e(7,p=!0),E.preventDefault(),E.stopPropagation(),f=performance.now()},R=E=>A=>{if(!f||Ne||performance.now()-f>x0)return;const L=m.includes(E);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):L&&m.length>1?e(8,m=[E]):L?e(8,m=[]):e(8,m=[E]),g()},C=(E,A,L)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,B],k)=>m.includes(k)?[O+L[0],B+L[1]]:[O,B]):A==="SHAPE"?D=N.points.map(([O,B])=>[O+L[0],B+L[1]]):D=N.points.map(([O,B],k)=>A===`HANDLE-${k}`?[O+L[0],B+L[1]]:[O,B]);const $=Ae(D);return{...E,geometry:{points:D,bounds:$}}},I=E=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=Ae(L);o("change",{...a,geometry:{points:L,bounds:D}}),await rc();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.firstChild){const $=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:A.clientX,clientY:A.clientY,pointerId:A.pointerId,pointerType:A.pointerType,isPrimary:A.isPrimary,buttons:A.buttons});N.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((L,D)=>!m.includes(D)),A=Ae(E);o("change",{...a,geometry:{points:E,bounds:A}}),e(8,m=[])};Jr(()=>{if(Ne)return;const E=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",E)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){oe.call(this,r,E)}function P(E){oe.call(this,r,E)}function T(E){oe.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=Ne?[]:i.points.map((E,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],D=(E[0]+L[0])/2,N=(E[1]+L[1])/2,$=Math.sqrt(Math.pow(L[0]-D,2)+Math.pow(L[1]-N,2))>E0/c;return{point:[D,N],visible:$}})),r.$$.dirty[0]&40&&e(9,s=ms(i.bounds,vn/c))},[a,l,h,c,u,i,d,p,m,s,n,y,_,v,b,S,R,C,I,F,U,P,T]}class A0 extends me{constructor(t){super(),pe(this,t,T0,b0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function S0(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v,g,b,S,R,C,I,M,F,U,P,T,E,A,L,D,N,$,O,B,k,V,z,K,X,ft,H,mt,J,ut,gt,Et,Dt,Yt,Vt,et,$e,ts;return J=new Ri({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),J.$on("pointerdown",function(){Gt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Ri({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),gt.$on("pointerdown",function(){Gt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Ri({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 Ri({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(),F=W("rect"),E=we(),A=W("rect"),$=we(),O=W("rect"),z=we(),K=W("rect"),mt=we(),re(J.$$.fragment),ut=we(),re(gt.$$.fragment),Et=we(),re(Dt.$$.fragment),Yt=we(),re(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",y=r[5].y),x(f,"width",_=r[5].w),x(f,"height",v=r[5].h),x(b,"class","a9s-inner a9s-shape-handle"),x(b,"style",r[1]),x(b,"x",S=r[5].x),x(b,"y",R=r[5].y),x(b,"width",C=r[5].w),x(b,"height",I=r[5].h),x(F,"class","a9s-edge-handle a9s-edge-handle-top"),x(F,"x",U=r[5].x),x(F,"y",P=r[5].y),x(F,"height",1),x(F,"width",T=r[5].w),x(A,"class","a9s-edge-handle a9s-edge-handle-right"),x(A,"x",L=r[5].x+r[5].w),x(A,"y",D=r[5].y),x(A,"height",N=r[5].h),x(A,"width",1),x(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),x(O,"x",B=r[5].x),x(O,"y",k=r[5].y+r[5].h),x(O,"height",1),x(O,"width",V=r[5].w),x(K,"class","a9s-edge-handle a9s-edge-handle-left"),x(K,"x",X=r[5].x),x(K,"y",ft=r[5].y),x(K,"height",H=r[5].h),x(K,"width",1)},m(Y,G){nt(Y,t,G),xt(t,e),xt(e,i),xt(e,l),nt(Y,p,G),nt(Y,f,G),nt(Y,g,G),nt(Y,b,G),nt(Y,M,G),nt(Y,F,G),nt(Y,E,G),nt(Y,A,G),nt(Y,$,G),nt(Y,O,G),nt(Y,z,G),nt(Y,K,G),nt(Y,mt,G),Qt(J,Y,G),nt(Y,ut,G),Qt(gt,Y,G),nt(Y,Et,G),Qt(Dt,Y,G),nt(Y,Yt,G),Qt(Vt,Y,G),et=!0,$e||(ts=[St(f,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),St(b,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),St(F,"pointerdown",function(){Gt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),St(A,"pointerdown",function(){Gt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),St(O,"pointerdown",function(){Gt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),St(K,"pointerdown",function(){Gt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],$e=!0)},p(Y,G){r=Y,(!et||G&64&&n!==(n=r[6].x))&&x(i,"x",n),(!et||G&64&&s!==(s=r[6].y))&&x(i,"y",s),(!et||G&64&&o!==(o=r[6].w))&&x(i,"width",o),(!et||G&64&&a!==(a=r[6].h))&&x(i,"height",a),(!et||G&32&&h!==(h=r[5].x))&&x(l,"x",h),(!et||G&32&&c!==(c=r[5].y))&&x(l,"y",c),(!et||G&32&&u!==(u=r[5].w))&&x(l,"width",u),(!et||G&32&&d!==(d=r[5].h))&&x(l,"height",d),(!et||G&32&&m!==(m=r[5].x))&&x(f,"x",m),(!et||G&32&&y!==(y=r[5].y))&&x(f,"y",y),(!et||G&32&&_!==(_=r[5].w))&&x(f,"width",_),(!et||G&32&&v!==(v=r[5].h))&&x(f,"height",v),(!et||G&2)&&x(b,"style",r[1]),(!et||G&32&&S!==(S=r[5].x))&&x(b,"x",S),(!et||G&32&&R!==(R=r[5].y))&&x(b,"y",R),(!et||G&32&&C!==(C=r[5].w))&&x(b,"width",C),(!et||G&32&&I!==(I=r[5].h))&&x(b,"height",I),(!et||G&32&&U!==(U=r[5].x))&&x(F,"x",U),(!et||G&32&&P!==(P=r[5].y))&&x(F,"y",P),(!et||G&32&&T!==(T=r[5].w))&&x(F,"width",T),(!et||G&32&&L!==(L=r[5].x+r[5].w))&&x(A,"x",L),(!et||G&32&&D!==(D=r[5].y))&&x(A,"y",D),(!et||G&32&&N!==(N=r[5].h))&&x(A,"height",N),(!et||G&32&&B!==(B=r[5].x))&&x(O,"x",B),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&x(O,"y",k),(!et||G&32&&V!==(V=r[5].w))&&x(O,"width",V),(!et||G&32&&X!==(X=r[5].x))&&x(K,"x",X),(!et||G&32&&ft!==(ft=r[5].y))&&x(K,"y",ft),(!et||G&32&&H!==(H=r[5].h))&&x(K,"height",H);const Ar={};G&32&&(Ar.x=r[5].x),G&32&&(Ar.y=r[5].y),G&8&&(Ar.scale=r[3]),J.$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]),gt.$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){et||(lt(J.$$.fragment,Y),lt(gt.$$.fragment,Y),lt(Dt.$$.fragment,Y),lt(Vt.$$.fragment,Y),et=!0)},o(Y){yt(J.$$.fragment,Y),yt(gt.$$.fragment,Y),yt(Dt.$$.fragment,Y),yt(Vt.$$.fragment,Y),et=!1},d(Y){Y&&(rt(t),rt(p),rt(f),rt(g),rt(b),rt(M),rt(F),rt(E),rt(A),rt($),rt(O),rt(z),rt(K),rt(mt),rt(ut),rt(Et),rt(Yt)),te(J,Y),te(gt,Y),te(Dt,Y),te(Vt,Y),$e=!1,Me(ts)}}}function C0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[S0,({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function I0(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,y,_)=>{const v=m.geometry.bounds;let[g,b]=[v.minX,v.minY],[S,R]=[v.maxX,v.maxY];const[C,I]=_;if(y==="SHAPE")g+=C,S+=C,b+=I,R+=I;else{switch(y){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=I;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=I;break}}switch(y){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const M=Math.min(g,S),F=Math.min(b,R),U=Math.abs(S-g),P=Math.abs(R-b);return{...m,geometry:{x:M,y:F,w:U,h:P,bounds:{minX:M,minY:F,maxX:M+U,maxY:F+P}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){oe.call(this,r,m)}function p(m){oe.call(this,r,m)}function f(m){oe.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=ms(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,p,f]}class P0 extends me{constructor(t){super(),pe(this,t,I0,C0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Cc=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(Cc.call(r,e)&&++i&&!Cc.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 R0=12,M0=(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))>R0/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 Ic(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Pc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Rc(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 Mc(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=bn/r[3]),x(t,"class","svelte-1vxo6dc")},m(s,o){nt(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=bn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function Dc(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=bn/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){nt(u,t,d),xt(t,e),xt(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=bn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Bc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Ri({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(){re(t.$$.fragment)},m(n,s){Qt(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||(lt(t.$$.fragment,n),e=!0)},o(n){yt(t.$$.fragment,n),e=!1},d(n){te(t,n)}}}function Oc(r){let t,e,i=Ie(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Bc(Rc(r,i,o));const s=o=>yt(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);nt(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=Rc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=Bc(h),n[l].c(),lt(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)lt(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)yt(n[a]);e=!1},d(o){o&&rt(t),Zr(n,o)}}}function Lc(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v=r[6]!==void 0&&!r[7]&&Mc(ua(r)),g=r[6]!==void 0&&!r[7]&&Dc(ca(r)),b=Ie(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Oc(Pc(r,b,C));const R=C=>yt(S[C],1,1,()=>{S[C]=null});return{c(){t=W("g"),e=W("defs"),i=W("mask"),n=W("rect"),h=W("path"),v&&v.c(),g&&g.c(),u=W("path"),p=W("path");for(let C=0;C<S.length;C+=1)S[C].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=He(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=He(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=He(r[30]))},m(C,I){nt(C,t,I),xt(t,e),xt(e,i),xt(i,n),xt(i,h),v&&v.m(i,null),g&&g.m(e,null),xt(t,u),xt(t,p);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);m=!0,y||(_=[St(u,"pointerup",r[13]),St(u,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),St(p,"pointerup",r[13]),St(p,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!m||I[0]&512&&s!==(s=r[9].x))&&x(n,"x",s),(!m||I[0]&512&&o!==(o=r[9].y))&&x(n,"y",o),(!m||I[0]&512&&a!==(a=r[9].w))&&x(n,"width",a),(!m||I[0]&512&&l!==(l=r[9].h))&&x(n,"height",l),(!m||I[0]&32&&c!==(c=He(r[30])))&&x(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(ua(r),I):(v=Mc(ua(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(ca(r),I):(g=Dc(ca(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=He(r[30])))&&x(u,"d",d),(!m||I[0]&2)&&x(p,"style",r[1]),(!m||I[0]&32&&f!==(f=He(r[30])))&&x(p,"d",f),I[0]&268491048){b=Ie(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Pc(r,b,M);S[M]?(S[M].p(F,I),lt(S[M],1)):(S[M]=Oc(F),S[M].c(),lt(S[M],1),S[M].m(t,null))}for(Ee(),M=b.length;M<S.length;M+=1)R(M);Te()}},i(C){if(!m){for(let I=0;I<b.length;I+=1)lt(S[I]);m=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)yt(S[I]);m=!1},d(C){C&&rt(t),v&&v.d(),g&&g.d(),Zr(S,C),y=!1,Me(_)}}}function Nc(r){let t,e;return t=new _c({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function D0(r){let t,e,i,n=Ie(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Lc(Ic(r,n,l));const o=l=>yt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&Nc(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);nt(l,t,h),a&&a.m(l,h),nt(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=Ic(l,n,c);s[c]?(s[c].p(u,h),lt(s[c],1)):(s[c]=Lc(u),s[c].c(),lt(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&&lt(a,1)):(a=Nc(ha(l)),a.c(),lt(a,1),a.m(e.parentNode,e)):a&&(Ee(),yt(a,1,1,()=>{a=null}),Te())},i(l){if(!i){for(let h=0;h<n.length;h+=1)lt(s[h]);lt(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)yt(s[h]);yt(a),i=!1},d(l){l&&(rt(t),rt(e)),Zr(s,l),a&&a.d(l)}}}function B0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[D0,({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const O0=250,L0=1e3,bn=4.5;function N0(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 y=()=>e(7,p=!0),_=()=>e(7,p=!1),v=A=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[L,D]=h.elementToImage(A.offsetX,A.offsetY),N=k=>Math.pow(k[0]-L,2)+Math.pow(k[1]-D,2),$=qg(i).reduce((k,V)=>N(V)<N(k)?V:k),O=n.filter(k=>k.visible).reduce((k,V)=>N(V.point)<N(k.point)?V:k),B=Math.pow(L0/c,2);N($)<B||N(O.point)<B?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,p=!0),A.preventDefault(),A.stopPropagation(),f=performance.now()},R=(A,L,D)=>N=>{if(!f||Ne||performance.now()-f>O0)return;const $=B=>B.polygon===A&&B.ring===L&&B.point===D,O=m.some($);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(B=>!$(B))):e(8,m=[...m,{polygon:A,ring:L,point:D}]):O&&m.length>1?e(8,m=[{polygon:A,ring:L,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:A,ring:L,point:D}]),g()},C=(A,L,D)=>{g();const N=A.geometry.polygons;let $;if(L==="SHAPE")$=N.map(O=>{const B=O.rings.map((V,z)=>({points:V.points.map((K,X)=>[K[0]+D[0],K[1]+D[1]])})),k=Ae(B[0].points);return{rings:B,bounds:k}});else{const[O,B,k,V]=L.split("-").map(z=>parseInt(z));$=N.map((z,K)=>{if(K===B){const X=z.rings.map((H,mt)=>mt===k?{points:H.points.map((J,ut)=>ut===V?[J[0]+D[0],J[1]+D[1]]:J)}:H),ft=Ae(X[0].points);return{rings:X,bounds:ft}}else return z})}return{...A,geometry:{polygons:$,bounds:Ko($)}}},I=A=>async L=>{L.stopPropagation();const D=n[A],N=i.polygons.map((O,B)=>{if(B===D.elementIdx){const k=O.rings.map((z,K)=>K===D.ringIdx?{points:[...z.points.slice(0,D.pointIdx+1),D.point,...z.points.slice(D.pointIdx+1)]}:z),V=Ae(k[0].points);return{rings:k,bounds:V}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Ko(N)}}),await rc();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const O=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});$.firstChild.dispatchEvent(O)}},M=()=>{const A=i.polygons.map((L,D)=>{if(m.some(N=>N.polygon===D)){const N=L.rings.map((O,B)=>{const k=m.filter(V=>V.polygon===D&&V.ring===B);return k.length&&O.points.length-k.length>=3?{points:O.points.filter((V,z)=>!k.some(K=>K.point===z))}:O}),$=Ae(N[0].points);return{rings:N,bounds:$}}else return L});!la(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:Ko(A)}}),e(8,m=[]))};Jr(()=>{if(Ne)return;const A=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",A),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",A)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(A,L,D,{polygon:N,ring:$,point:O})=>N===A&&$===L&&O===D;function P(A){oe.call(this,r,A)}function T(A){oe.call(this,r,A)}function E(A){oe.call(this,r,A)}return r.$$set=A=>{"shape"in A&&e(0,a=A.shape),"computedStyle"in A&&e(1,l=A.computedStyle),"transform"in A&&e(2,h=A.transform),"viewportScale"in A&&e(3,c=A.viewportScale),"svgEl"in A&&e(4,u=A.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Ne?[]:M0(i,c)),r.$$.dirty[0]&40&&e(9,s=ms(i.bounds,bn/c))},[a,l,h,c,u,i,d,p,m,s,n,y,_,b,S,R,C,I,F,U,P,T,E]}class F0 extends me{constructor(t){super(),pe(this,t,N0,B0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Fc=new Map([[_t.RECTANGLE,P0],[_t.POLYGON,A0],[_t.MULTIPOLYGON,F0]]),da=r=>Fc.get(r.type),kc=(r,t)=>Fc.set(r,t);function k0(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 U0 extends me{constructor(t){super(),pe(this,t,k0,null,Kt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function G0(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 $0 extends me{constructor(t){super(),pe(this,t,G0,null,Kt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Uc(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){nt(u,t,d),xt(t,e),xt(e,i),xt(e,l),nt(u,h,d),nt(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&&(rt(t),rt(h),rt(c))}}}function H0(r){let t,e=r[0]&&Uc(r);return{c(){t=W("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){nt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[0]?e?e.p(i,n):(e=Uc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&rt(t),e&&e.d()}}}function X0(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 y=S=>{const R=S;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))},_=S=>{const R=S;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])))},v=S=>{const R=S,C=performance.now()-h;if(o==="click"){if(C>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&&(C>300||f*m>100?(R.stopPropagation(),g()):(e(0,c=void 0),u=void 0))},g=()=>{if(f*m>15){const S={type:_t.RECTANGLE,geometry:{bounds:{minX:d,minY:p,maxX:d+f,maxY:p+m},x:d,y:p,w:f,h:m}};n("create",S)}e(0,c=void 0),u=void 0};Jr(()=>{s("pointerdown",y),s("pointermove",_),s("pointerup",v,!0)});const b=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=S=>{"addEventListener"in S&&e(7,s=S.addEventListener),"drawingMode"in S&&e(8,o=S.drawingMode),"transform"in S&&e(9,a=S.transform),"viewportScale"in S&&e(10,l=S.viewportScale)},r.$$.update=()=>{r.$$.dirty&1024&&e(5,i=2/l)},[c,d,p,f,m,i,b,s,o,a,l]}class V0 extends me{constructor(t){super(),pe(this,t,X0,H0,Kt,{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 Gc(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m=r[1]&&$c(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(y,_){nt(y,t,_),xt(t,e),xt(e,i),xt(e,l),nt(y,c,_),nt(y,d,_),m&&m.m(y,_),nt(y,f,_)},p(y,_){_&8&&n!==(n=y[3].x)&&x(i,"x",n),_&8&&s!==(s=y[3].y)&&x(i,"y",s),_&8&&o!==(o=y[3].w)&&x(i,"width",o),_&8&&a!==(a=y[3].h)&&x(i,"height",a),_&4&&h!==(h=y[19])&&x(l,"points",h),_&4&&u!==(u=y[19])&&x(c,"points",u),_&4&&p!==(p=y[19])&&x(d,"points",p),y[1]?m?m.p(y,_):(m=$c(y),m.c(),m.m(f.parentNode,f)):m&&(m.d(1),m=null)},d(y){y&&(rt(t),rt(c),rt(d),rt(f)),m&&m.d(y)}}}function $c(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){nt(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&&rt(t)}}}function z0(r){let t,e=r[3]&&Gc(fa(r));return{c(){t=W("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){nt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[3]?e?e.p(fa(i),n):(e=Gc(fa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&rt(t),e&&e.d()}}}const j0=20,W0=1500;function Y0(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 y=R=>{const C=R,{timeStamp:I,offsetX:M,offsetY:F}=C;if(u={timeStamp:I,offsetX:M,offsetY:F},l==="drag"&&d.length===0){const U=h.elementToImage(C.offsetX,C.offsetY);d.push(U),e(10,p=U)}},_=R=>{const C=R;if(f&&clearTimeout(f),d.length>0){if(e(10,p=h.elementToImage(C.offsetX,C.offsetY)),d.length>2){const I=cs(p,d[0])*c;e(1,m=I<j0)}C.pointerType==="touch"&&(f=setTimeout(()=>{g()},W0))}},v=R=>{const C=R;if(f&&clearTimeout(f),l==="click"){const I=C.timeStamp-u.timeStamp,M=cs([u.offsetX,u.offsetY],[C.offsetX,C.offsetY]);if(I>300||M>15)return;if(m)b();else if(d.length===0){const F=h.elementToImage(C.offsetX,C.offsetY);d.push(F),e(10,p=F)}else d.push(p)}else{if(d.length===1&&cs(d[0],p)<=4){e(0,d=[]),e(10,p=void 0);return}C.stopImmediatePropagation(),m?b():d.push(p)}},g=()=>{if(!p)return;const R=d.slice(0,-1);if(R.length<3)return;const C={type:_t.POLYGON,geometry:{bounds:Ae(d),points:R}};qo(C)>4&&(e(0,d=[]),e(10,p=void 0),o("create",C))},b=()=>{const R={type:_t.POLYGON,geometry:{bounds:Ae(d),points:[...d]}};e(0,d=[]),e(10,p=void 0),o("create",R)};Jr(()=>{a("pointerdown",y,!0),a("pointermove",_),a("pointerup",v,!0),a("dblclick",g,!0)});const S=`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?ms(Ae(n),2/c):void 0)},[d,m,n,s,i,S,a,l,h,c,p]}class q0 extends me{constructor(t){super(),pe(this,t,Y0,z0,Kt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const pa=new Map([["rectangle",{tool:V0}],["polygon",{tool:q0}]]),gs=()=>[...pa.keys()],ys=r=>pa.get(r),Hc=(r,t,e={})=>pa.set(r,{tool:t,opts:e});function K0(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){nt(o,t,a),xt(t,e),xt(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:Rt,o:Rt,d(o){o&&rt(t)}}}function Z0(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 J0 extends me{constructor(t){super(),pe(this,t,Z0,K0,Kt,{annotation:0,geom:6,style:7})}}function Q0(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){nt(o,t,a),xt(t,e),xt(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:Rt,o:Rt,d(o){o&&rt(t)}}}function t_(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 e_ extends me{constructor(t){super(),pe(this,t,t_,Q0,Kt,{annotation:0,geom:6,style:7})}}function Xc(r,t,e){const i=r.slice();return i[5]=t[e],i}function Vc(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",He(r[5])),x(i,"class","a9s-inner"),x(i,"style",r[1]),x(i,"fill-rule","evenodd"),x(i,"d",He(r[5]))},m(n,s){nt(n,t,s),nt(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&&(rt(t),rt(i))}}}function r_(r){let t,e,i=Ie(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=Vc(Xc(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){nt(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=Xc(s,i,a);n[a]?n[a].p(l,o):(n[a]=Vc(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:Rt,o:Rt,d(s){s&&rt(t),Zr(n,s)}}}function i_(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 n_ extends me{constructor(t){super(),pe(this,t,i_,r_,Kt,{annotation:0,geom:3,style:4})}}function s_(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(o_).join(" ")),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"points",r[2].map(a_).join(" ")),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(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:Rt,o:Rt,d(o){o&&rt(t)}}}const o_=r=>r.join(","),a_=r=>r.join(",");function l_(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 h_ extends me{constructor(t){super(),pe(this,t,l_,s_,Kt,{annotation:0,geom:3,style:4})}}function c_(r){let t,e,i,n,s,o,a;return{c(){t=W("g"),e=W("path"),s=W("path"),x(e,"class",i=Ei(`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=Ei(`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){nt(l,t,h),xt(t,e),xt(t,s)},p(l,[h]){h&2&&i!==(i=Ei(`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=Ei(`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:Rt,o:Rt,d(l){l&&rt(t)}}}function u_(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 d_ extends me{constructor(t){super(),pe(this,t,u_,c_,Kt,{annotation:0,geom:4,style:5})}}function f_(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){nt(o,t,a),xt(t,e),xt(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:Rt,o:Rt,d(o){o&&rt(t)}}}function p_(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 m_ extends me{constructor(t){super(),pe(this,t,p_,f_,Kt,{annotation:0,geom:6,style:7})}}const g_=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]}}),y_=250,__=(r,t)=>{const e=Rr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<y_){const{x:s,y:o}=zc(n,r),a=Ne?10:2,l=t.getAt(s,o,void 0,a);l?e("click",{originalEvent:n,annotation:l}):e("click",{originalEvent:n})}}}},zc=(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 jc(r,t,e){const i=r.slice();return i[39]=t[e],i}function Wc(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 Yc(r){let t=r[42],e,i,n=qc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&131072&&Kt(t,t=s[42])?(Ee(),yt(n,1,1,Rt),Te(),n=qc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function v_(r){let t,e;return t=new e_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function b_(r){let t,e;return t=new d_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function x_(r){let t,e;return t=new n_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function w_(r){let t,e;return t=new h_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function E_(r){let t,e;return t=new m_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function T_(r){var t;let e,i;return e=new J0({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){re(e.$$.fragment)},m(n,s){Qt(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||(lt(e.$$.fragment,n),i=!0)},o(n){yt(e.$$.fragment,n),i=!1},d(n){te(e,n)}}}function qc(r){let t,e,i,n;const s=[T_,E_,w_,x_,b_,v_],o=[];function a(l,h){var c,u,d,p,f,m;return((c=l[45])==null?void 0:c.type)===_t.ELLIPSE?0:((u=l[45])==null?void 0:u.type)===_t.RECTANGLE?1:((d=l[45])==null?void 0:d.type)===_t.POLYGON?2:((p=l[45])==null?void 0:p.type)===_t.MULTIPOLYGON?3:((f=l[45])==null?void 0:f.type)===_t.POLYLINE?4:((m=l[45])==null?void 0:m.type)===_t.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),nt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),yt(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()),lt(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(lt(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function Kc(r){let t=Le(r[42])&&!r[10](r[42]),e,i,n=t&&Yc(ma(r));return{c(){n&&n.c(),e=De()},m(s,o){n&&n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&132096&&(t=Le(s[42])&&!s[10](s[42])),t?n?(n.p(ma(s),o),o[0]&132096&&lt(n,1)):(n=Yc(ma(s)),n.c(),lt(n,1),n.m(e.parentNode,e)):n&&(Ee(),yt(n,1,1,()=>{n=null}),Te())},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n&&n.d(s)}}}function Zc(r){let t,e,i,n;const s=[S_,A_],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),nt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),yt(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()),lt(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(lt(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function A_(r){let t=`${r[2]}-${r[7]}`,e,i,n=Jc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&132&&Kt(t,t=`${s[2]}-${s[7]}`)?(Ee(),yt(n,1,1,Rt),Te(),n=Jc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function S_(r){let t,e,i=Ie(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=tu(jc(r,i,o));const s=o=>yt(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);nt(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=jc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=tu(h),n[l].c(),lt(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)lt(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)yt(n[a]);e=!1},d(o){o&&rt(t),Zr(n,o)}}}function Jc(r){let t,e;return t=new $0({props:{target:r[8],tool:r[15],drawingMode:r[14],transform:r[13],viewportScale:r[18]}}),t.$on("create",r[22]),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function Qc(r){let t,e;return t=new U0({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function tu(r){let t=r[39].annotation.id,e,i,n=Qc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&64&&Kt(t,t=s[39].annotation.id)?(Ee(),yt(n,1,1,Rt),Te(),n=Qc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function C_(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]=Kc(Wc(r,a,u));const h=u=>yt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&Zc(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"),Je(t,"drawing",r[15]),Je(t,"editing",r[5]),Je(t,"hidden",!r[3]),Je(t,"hover",r[16])},m(u,d){nt(u,t,d),xt(t,e);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(e,null);xt(t,i),c&&c.m(i,null),r[35](i),r[36](t),n=!0,s||(o=[St(t,"pointerup",function(){Gt(r[11])&&r[11].apply(this,arguments)}),St(t,"pointerdown",function(){Gt(r[12])&&r[12].apply(this,arguments)}),St(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=Wc(r,a,p);l[p]?(l[p].p(f,d),lt(l[p],1)):(l[p]=Kc(f),l[p].c(),lt(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&&lt(c,1)):(c=Zc(r),c.c(),lt(c,1),c.m(i,null)):c&&(Ee(),yt(c,1,1,()=>{c=null}),Te()),(!n||d[0]&32768)&&Je(t,"drawing",r[15]),(!n||d[0]&32)&&Je(t,"editing",r[5]),(!n||d[0]&8)&&Je(t,"hidden",!r[3]),(!n||d[0]&65536)&&Je(t,"hover",r[16])},i(u){if(!n){for(let d=0;d<a.length;d+=1)lt(l[d]);lt(c),n=!0}},o(u){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)yt(l[d]);yt(c),n=!1},d(u){u&&rt(t),Zr(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,Me(o)}}}function I_(r,t,e){let i,n,s,o,a,l,h,c,u,d,p,f,m=Rt,y=()=>(m(),m=Yh(A,H=>e(18,f=H)),A);r.$$.on_destroy.push(()=>m());let{drawingEnabled:_}=t,{image:v}=t,{preferredDrawingMode:g}=t,{state:b}=t,{style:S=void 0}=t,{toolName:R=gs()[0]}=t,{user:C}=t,{visible:I=!0}=t,M=0;const F=()=>e(7,M+=1),U=()=>R,P=()=>_;let T,E,A;Jr(()=>y(e(9,A=a0(v,E))));const{hover:L,selection:D,store:N}=b;Vo(r,L,H=>e(16,u=H)),Vo(r,D,H=>e(33,d=H)),Vo(r,N,H=>e(17,p=H));let $,O;const B=H=>{$&&N.unobserve($);const mt=H.filter(({editable:J})=>J).map(({id:J})=>J);mt.length>0?(e(5,O=mt.map(J=>N.getAnnotation(J)).filter(J=>J&&Le(J))),$=J=>{const{updated:ut}=J.changes;e(5,O=ut==null?void 0:ut.map(gt=>gt.newValue))},N.observe($,{annotations:mt})):e(5,O=void 0)},k=H=>{const mt=cc(),J={id:mt,bodies:[],target:{annotation:mt,selector:H.detail,creator:C,created:new Date}};N.addAnnotation(J),D.setSelected(J.id)},V=H=>mt=>{var J;const{target:ut}=H,gt=10*60*1e3,Et=((J=ut.creator)==null?void 0:J.id)!==C.id||!ut.created||new Date().getTime()-ut.created.getTime()>gt;N.updateTarget({...ut,selector:mt.detail,created:Et?ut.created:new Date,updated:Et?new Date:void 0,updatedBy:Et?C:void 0})},z=H=>{const{x:mt,y:J}=zc(H,E),ut=N.getAt(mt,J,void 0,2);ut?u!==ut.id&&L.set(ut.id):L.set(void 0)},K=H=>Le(H);function X(H){os[H?"unshift":"push"](()=>{T=H,e(8,T)})}function ft(H){os[H?"unshift":"push"](()=>{E=H,e(4,E)})}return r.$$set=H=>{"drawingEnabled"in H&&e(0,_=H.drawingEnabled),"image"in H&&e(25,v=H.image),"preferredDrawingMode"in H&&e(26,g=H.preferredDrawingMode),"state"in H&&e(27,b=H.state),"style"in H&&e(1,S=H.style),"toolName"in H&&e(2,R=H.toolName),"user"in H&&e(28,C=H.user),"visible"in H&&e(3,I=H.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(15,{tool:i,opts:n}=ys(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=g_(E)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=__(E,N),a,(e(11,l),e(4,E))),r.$$.dirty[1]&4&&B(d.selected),r.$$.dirty[0]&32&&e(6,h=O?O.map(H=>({annotation:H,editor:da(H.target.selector)})).filter(H=>H.editor):void 0),r.$$.dirty[0]&64&&e(10,c=H=>h&&h.some(mt=>mt.annotation.id===H.id))},[_,S,R,I,E,O,h,M,T,A,c,l,a,o,s,i,u,p,f,L,D,N,k,V,z,v,g,b,C,F,U,P,n,d,K,X,ft]}class P_ extends me{constructor(t){super(),pe(this,t,I_,C_,Kt,{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 eu(r,t,e=0,i=r.length-1,n=R_){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));eu(r,t,p,f,n)}const s=r[t];let o=e,a=i;for(xn(r,e,t),n(r[i],s)>0&&xn(r,e,i);o<a;){for(xn(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?xn(r,e,a):(a++,xn(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function xn(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function R_(r,t){return r<t?-1:r>t?1:0}class M_{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(!vs(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;vs(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(!vs(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(vs(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=Di([]),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=D_(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=Di(t.slice(e,i+1)),Mi(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=Di([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));ru(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);ru(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 Mi(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=L_(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),En(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=Di(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Mi(i,this.toBBox),Mi(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Di([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Mi(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=wn(t,0,a,this.toBBox),h=wn(t,a,i,this.toBBox),c=N_(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:B_,s=t.leaf?this.compareMinY:O_,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=wn(t,0,e,s),a=wn(t,i-e,i,s);let l=_s(o)+_s(a);for(let h=e;h<i-e;h++){const c=t.children[h];En(o,t.leaf?s(c):c),l+=_s(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];En(a,t.leaf?s(c):c),l+=_s(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)En(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():Mi(t[e],this.toBBox)}}function D_(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 Mi(r,t){wn(r,0,r.children.length,t,r)}function wn(r,t,e,i,n){n||(n=Di(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];En(n,r.leaf?i(o):o)}return n}function En(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 B_(r,t){return r.minX-t.minX}function O_(r,t){return r.minY-t.minY}function ga(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function _s(r){return r.maxX-r.minX+(r.maxY-r.minY)}function L_(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 N_(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 vs(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Di(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ru(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;eu(r,o,t,e,n),s.push(t,o,o,e)}}const F_=()=>{const r=new M_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!us(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(!us(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===_t.RECTANGLE||Vg(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(us(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)}}},iu=r=>{const t=Ny(),e=F_(),i=xy(t,r.userSelectAction,r.adapter),n=by(t),s=$y();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}},k_=r=>{const t=iu(r);return{...t,store:Fy(t.store)}},U_=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},nu=r=>{const t=U_(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},su=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?nu(r):e),ou=(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}),au=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,lu=(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=()=>{au?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return au?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},G_=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=ou(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:dc.EDIT,theme:"light"}),n=k_(i),{selection:s,store:o}=n,a=Gy(o,i.initialHistory),l=Hy(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=lu(a);let u=Jy();su(e,h,i.theme);const d=new P_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",P=>{const{originalEvent:T,annotation:E}=P.detail;E?s.userSelect(E.id,T):s.isEmpty()||s.clear()});const p=Vy(n,a,i.adapter),f=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},y=()=>d.getDrawingTool(),_=()=>u,v=()=>d.isDrawingEnabled(),g=(P,T,E)=>Hc(P,T,E),b=(P,T)=>kc(P,T),S=P=>{if(!ys(P))throw`No drawing tool named ${P}`;d.$set({toolName:P})},R=P=>d.$set({drawingEnabled:P}),C=P=>{console.warn("Filter not implemented yet")},I=P=>d.$set({style:P}),M=P=>su(e,h,P),F=P=>{u=P,d.$set({user:P})},U=P=>d.$set({visible:P});return{...p,cancelDrawing:f,destroy:m,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:gs,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:b,setDrawingEnabled:R,setDrawingTool:S,setFilter:C,setStyle:I,setTheme:M,setUser:F,setVisible:U,element:h,state:n}};function Ft(){}function _a(r,t){for(const e in t)r[e]=t[e];return r}function hu(r){return r()}function cu(){return Object.create(null)}function Fe(r){r.forEach(hu)}function Zt(r){return typeof r=="function"}function Ut(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function $_(r){return Object.keys(r).length===0}function H_(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 Tn(r,t,e){r.$$.on_destroy.push(H_(t,e))}function uu(r,t,e,i){if(r){const n=du(r,t,e,i);return r[0](n)}}function du(r,t,e,i){return r[1]&&i?_a(e.ctx.slice(),r[1](i(t))):e.ctx}function fu(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 pu(r,t,e,i,n,s){if(n){const o=du(t,e,i,s);r.p(o,n)}}function mu(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 gu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function yu(r){return r??""}const va=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Ct(r,t){r.appendChild(t)}function ot(r,t,e){r.insertBefore(t,e||null)}function st(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 it(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 Pt(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 X_(r){return Array.from(r.childNodes)}function V_(r,t){t=""+t,r.data!==t&&(r.data=t)}function Br(r,t,e){r.classList.toggle(t,!!e)}function z_(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let An;function Sn(r){An=r}function xa(){if(!An)throw new Error("Function called outside component initialization");return An}function ei(r){xa().$$.on_mount.push(r)}function j_(r){xa().$$.on_destroy.push(r)}function Bi(){const r=xa();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=z_(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function ae(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Oi=[],bs=[];let Li=[];const _u=[],vu=Promise.resolve();let wa=!1;function bu(){wa||(wa=!0,vu.then(wu))}function xu(){return bu(),vu}function Ea(r){Li.push(r)}const Ta=new Set;let Ni=0;function wu(){if(Ni!==0)return;const r=An;do{try{for(;Ni<Oi.length;){const t=Oi[Ni];Ni++,Sn(t),W_(t.$$)}}catch(t){throw Oi.length=0,Ni=0,t}for(Sn(null),Oi.length=0,Ni=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(;_u.length;)_u.pop()();wa=!1,Ta.clear(),Sn(r)}function W_(r){if(r.fragment!==null){r.update(),Fe(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Ea)}}function Y_(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 le(){ri={r:0,c:[],p:ri}}function he(){ri.r||Fe(ri.c),ri=ri.p}function q(r,t){r&&r.i&&(xs.delete(r),r.i(t))}function at(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 Lt(r){r&&r.c()}function Bt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Ea(()=>{const s=r.$$.on_mount.map(hu).filter(Zt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Fe(s),r.$$.on_mount=[]}),n.forEach(Ea)}function Ot(r,t){const e=r.$$;e.fragment!==null&&(Y_(e.after_update),Fe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function q_(r,t){r.$$.dirty[0]===-1&&(Oi.push(r),bu(),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=An;Sn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Ft,not_equal:n,bound:cu(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:cu(),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&&q_(r,u)),d}):[],h.update(),c=!0,Fe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=X_(t.target);h.fragment&&h.fragment.l(u),u.forEach(st)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Bt(r,t.target,t.anchor),wu()}Sn(l)}class jt{constructor(){Nh(this,"$$");Nh(this,"$$set")}$destroy(){Ot(this,1),this.$destroy=Ft}$on(t,e){if(!Zt(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&&!$_(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const K_="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(K_);var Qe=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(Qe||{}),Cn=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 Z_(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 Eu={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})()})(Eu);var J_=Eu.exports;const Q_=Aa(J_),Fi=(r,t)=>t,tr=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},tv=(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},Tu=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return Q_(e,t,!0).map(i=>[i.x,i.y])},ev=(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))},rv={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}};Fi(Qe.ELLIPSE,rv);const iv={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=ev([n,s],[o,a]);return l/h<=i}};Fi(Qe.LINE,iv);const nv={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 tr(t)},ki=r=>r.rings.map(e=>tv(e.points)).join(" "),sv=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),ov=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=Tu(a.points,t);return{...a,points:l}}),o=tr(s[0].points);return{...n,rings:s,bounds:o}}),i=Ts(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Fi(Qe.MULTIPOLYGON,nv);const av={area:r=>{const t=r.geometry.points;return ws(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Es(i,t,e)}},lv=(r,t=1)=>{const e=Tu(r.geometry.points,t),i=tr(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Fi(Qe.POLYGON,av);const hv={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Au(t.points,t.closed);return ws(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Au(n.points,n.closed);return Es(s,t,e)}else return cv(n,[t,e],i)}},Au=(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=Su(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);e.push(...a.slice(1))}}return e},Su=(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},cv=(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.type==="CURVE"||s.type==="CURVE"){const a=Su(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let l=0;l<a.length-1;l++)if(Cu(t,a[l],a[l+1])<=e)return!0}else if(Cu(t,n.point,s.point)<=e)return!0}return!1},Cu=(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};Fi(Qe.POLYLINE,hv);const uv={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};Fi(Qe.RECTANGLE,uv);const _e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function dv(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 fv=new Uint8Array(16);function pv(){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(fv)}const Iu={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function mv(r,t,e){var n;r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??pv();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,dv(i)}function gv(r,t,e){return Iu.randomUUID&&!r?Iu.randomUUID():mv(r)}const yv=(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};`),n||n===0?l+=`fill-opacity:${n};`:i&&(l+="fill-opacity: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}},Or=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,_v=r=>({}),Pu=r=>({grab:r[0]});function vv(r){let t,e,i,n;const s=r[8].default,o=uu(s,r,r[7],Pu);return{c(){t=it("g"),o&&o.c(),w(t,"class","a9s-annotation selected")},m(a,l){ot(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Pt(t,"pointerup",r[2]),Pt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&pu(o,s,a,a[7],e?fu(s,a[7],l,_v):mu(a[7]),Pu)},i(a){e||(q(o,a),e=!0)},o(a){at(o,a),e=!1},d(a){a&&st(t),o&&o.d(a),i=!1,Fe(n)}}}function bv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Bi();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const p=y=>_=>{if(c=y,h){const{left:g,top:b}=h.getBoundingClientRect(),S=_.clientX-g,R=_.clientY-b;u=l.elementToImage(S,R)}else{const{offsetX:g,offsetY:b}=_;u=l.elementToImage(g,b)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},f=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),g=[_-u[0],v-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,d=o,s("release",y)};return r.$$set=y=>{"shape"in y&&e(3,o=y.shape),"editor"in y&&e(4,a=y.editor),"transform"in y&&e(5,l=y.transform),"svgEl"in y&&e(6,h=y.svgEl),"$$scope"in y&&e(7,n=y.$$scope)},[p,f,m,o,a,l,h,n,i]}class Ia extends jt{constructor(t){super(),zt(this,t,bv,vv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function xv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Ru(r);return{c(){t=it("g"),e=it("circle"),h&&h.c(),n=it("circle"),w(e,"class","a9s-handle-buffer svelte-qtyc7s"),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=yu(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),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){ot(c,t,u),Ct(t,e),h&&h.m(t,null),Ct(t,n),a||(l=[Pt(e,"dblclick",r[12]),Pt(e,"pointerenter",r[13]),Pt(e,"pointerleave",r[14]),Pt(e,"pointerdown",r[15]),Pt(e,"pointerdown",r[6]),Pt(e,"pointerup",r[16]),Pt(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=Ru(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=yu(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&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&&st(t),h&&h.d(),a=!1,Fe(l)}}}function wv(r){let t,e,i,n,s,o,a,l,h;return{c(){t=it("g"),e=it("circle"),n=it("circle"),o=it("circle"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]*10),w(e,"class","a9s-touch-halo"),Br(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 svelte-qtyc7s"),w(n,"role","button"),w(n,"tabindex","0"),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){ot(c,t,u),Ct(t,e),Ct(t,n),Ct(t,o),l||(h=[Pt(n,"dblclick",r[9]),Pt(n,"pointerdown",r[10]),Pt(n,"pointerdown",r[6]),Pt(n,"pointerup",r[11]),Pt(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&&Br(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&&st(t),l=!1,Fe(h)}}}function Ru(r){let t,e;return{c(){t=it("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){ot(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&&st(t)}}}function Ev(r){let t;function e(s,o){return Or?wv:xv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&st(t),n.d(s)}}}function Tv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=g=>{g.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(g){ae.call(this,r,g)}function d(g){ae.call(this,r,g)}function p(g){ae.call(this,r,g)}function f(g){ae.call(this,r,g)}function m(g){ae.call(this,r,g)}function y(g){ae.call(this,r,g)}function _(g){ae.call(this,r,g)}function v(g){ae.call(this,r,g)}return r.$$set=g=>{e(8,t=_a(_a({},t),gu(g))),"x"in g&&e(0,n=g.x),"y"in g&&e(1,s=g.y),"scale"in g&&e(2,o=g.scale),"selected"in g&&e(3,a=g.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=gu(t),[n,s,o,a,l,i,h,c,t,u,d,p,f,m,y,_,v]}class Ui extends jt{constructor(t){super(),zt(this,t,Tv,Ev,Ut,{x:0,y:1,scale:2,selected:3})}}function Av(r){let t,e,i,n,s,o,a;return{c(){t=it("g"),e=it("circle"),n=it("circle"),s=it("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){ot(l,t,h),Ct(t,e),Ct(t,n),Ct(t,s),o||(a=[Pt(e,"pointerdown",r[5]),Pt(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&&st(t),o=!1,Fe(a)}}}function Sv(r){let t;return{c(){t=it("circle"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",r[2])},m(e,i){ot(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&&st(t)}}}function Cv(r){let t;function e(s,o){return Or?Sv:Av}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&st(t),n.d(s)}}}function Iv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){ae.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 Mu extends jt{constructor(t){super(),zt(this,t,Iv,Cv,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 Du(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 Bu(r){let t,e,i,n;return{c(){t=it("circle"),w(t,"cx",e=r[28][0]),w(t,"cy",i=r[28][1]),w(t,"r",n=In/r[3]),w(t,"class","svelte-1h2slbm")},m(s,o){ot(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=In/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function Ou(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=it("mask"),e=it("rect"),a=it("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=In/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){ot(u,t,d),Ct(t,e),Ct(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=In/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function Lu(r){let t,e;return t=new Ui({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(){Zt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Nu(r){let t,e;return t=new Mu({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Zt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Pv(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&Bu(Ma(r)),C=r[6]!==void 0&&!r[7]&&Ou(Ra(r)),I=xe(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Lu(Du(r,I,P));const F=P=>at(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Nu(Pa(r));return{c(){t=it("defs"),e=it("mask"),i=it("rect"),l=it("polygon"),R&&R.c(),C&&C.c(),c=Se(),u=it("polygon"),p=Se(),f=it("polygon"),y=Se();for(let P=0;P<M.length;P+=1)M[P].c();_=Se(),U&&U.c(),v=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(Fu).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(ku).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(Uu).join(" "))},m(P,T){ot(P,t,T),Ct(t,e),Ct(e,i),Ct(e,l),R&&R.m(e,null),C&&C.m(t,null),ot(P,c,T),ot(P,u,T),ot(P,p,T),ot(P,f,T),ot(P,y,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(P,T);ot(P,_,T),U&&U.m(P,T),ot(P,v,T),g=!0,b||(S=[Pt(u,"pointerup",r[14]),Pt(u,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(f,"pointermove",r[13]),Pt(f,"pointerup",r[14]),Pt(f,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,T){if(r=P,(!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(Fu).join(" ")))&&w(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Ma(r),T):(R=Bu(Ma(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(Ra(r),T):(C=Ou(Ra(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||T[0]&32&&d!==(d=r[5].points.map(ku).join(" ")))&&w(u,"points",d),(!g||T[0]&2)&&w(f,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Uu).join(" ")))&&w(f,"points",m),T[0]&134322472){I=xe(r[5].points);let E;for(E=0;E<I.length;E+=1){const A=Du(r,I,E);M[E]?(M[E].p(A,T),q(M[E],1)):(M[E]=Lu(A),M[E].c(),q(M[E],1),M[E].m(_.parentNode,_))}for(le(),E=I.length;E<M.length;E+=1)F(E);he()}r[6]!==void 0&&!r[7]?U?(U.p(Pa(r),T),T[0]&192&&q(U,1)):(U=Nu(Pa(r)),U.c(),q(U,1),U.m(v.parentNode,v)):U&&(le(),at(U,1,1,()=>{U=null}),he())},i(P){if(!g){for(let T=0;T<I.length;T+=1)q(M[T]);q(U),g=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)at(M[T]);at(U),g=!1},d(P){P&&(st(t),st(c),st(u),st(p),st(f),st(y),st(_),st(v)),R&&R.d(),C&&C.d(),Dr(M,P),U&&U.d(P),b=!1,Fe(S)}}}function Rv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[Pv,({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(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}const Mv=250,Dv=1e3,Bv=12,In=4.5,Fu=r=>r.join(","),ku=r=>r.join(","),Uu=r=>r.join(",");function Ov(r,t,e){let i,n,s;const o=Bi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const y=()=>e(7,p=!0),_=()=>e(7,p=!1),v=E=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(E.offsetX,E.offsetY),D=k=>Math.pow(k[0]-A,2)+Math.pow(k[1]-L,2),N=i.points.reduce((k,V)=>D(V)<D(k)?V:k),$=n.filter(k=>k.visible).reduce((k,V)=>D(V.point)<D(k.point)?V:k),O=Math.pow(Dv/c,2);D(N)<O||D($.point)<O?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=E=>{e(7,p=!0),E.preventDefault(),E.stopPropagation(),f=performance.now()},R=E=>A=>{if(!f||Or||performance.now()-f>Mv)return;const L=m.includes(E);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):L&&m.length>1?e(8,m=[E]):L?e(8,m=[]):e(8,m=[E]),g()},C=(E,A,L)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,B],k)=>m.includes(k)?[O+L[0],B+L[1]]:[O,B]):A==="SHAPE"?D=N.points.map(([O,B])=>[O+L[0],B+L[1]]):D=N.points.map(([O,B],k)=>A===`HANDLE-${k}`?[O+L[0],B+L[1]]:[O,B]);const $=tr(D);return{...E,geometry:{points:D,bounds:$}}},I=E=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=tr(L);o("change",{...a,geometry:{points:L,bounds:D}}),await xu();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.firstChild){const $=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:A.clientX,clientY:A.clientY,pointerId:A.pointerId,pointerType:A.pointerType,isPrimary:A.isPrimary,buttons:A.buttons});N.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((L,D)=>!m.includes(D)),A=tr(E);o("change",{...a,geometry:{points:E,bounds:A}}),e(8,m=[])};ei(()=>{if(Or)return;const E=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",E)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){ae.call(this,r,E)}function P(E){ae.call(this,r,E)}function T(E){ae.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=Or?[]:i.points.map((E,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],D=(E[0]+L[0])/2,N=(E[1]+L[1])/2,O=Math.sqrt(Math.pow(L[0]-D,2)+Math.pow(L[1]-N,2))>Bv/c;return{point:[D,N],visible:O}})),r.$$.dirty[0]&40&&e(9,s=Ca(i.bounds,In/c))},[a,l,h,c,u,i,d,p,m,s,n,y,_,v,b,S,R,C,I,F,U,P,T]}class Lv extends jt{constructor(t){super(),zt(this,t,Ov,Rv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Nv(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v,g,b,S,R,C,I,M,F,U,P,T,E,A,L,D,N,$,O,B,k,V,z,K,X,ft,H,mt,J,ut,gt,Et,Dt,Yt,Vt,et,$e,ts;return J=new Ui({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),J.$on("pointerdown",function(){Zt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Ui({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),gt.$on("pointerdown",function(){Zt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Ui({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(){Zt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new Ui({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Zt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=it("defs"),e=it("mask"),i=it("rect"),l=it("rect"),p=Se(),f=it("rect"),g=Se(),b=it("rect"),M=Se(),F=it("rect"),E=Se(),A=it("rect"),$=Se(),O=it("rect"),z=Se(),K=it("rect"),mt=Se(),Lt(J.$$.fragment),ut=Se(),Lt(gt.$$.fragment),Et=Se(),Lt(Dt.$$.fragment),Yt=Se(),Lt(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",y=r[5].y),w(f,"width",_=r[5].w),w(f,"height",v=r[5].h),w(b,"class","a9s-inner a9s-shape-handle"),w(b,"style",r[1]),w(b,"x",S=r[5].x),w(b,"y",R=r[5].y),w(b,"width",C=r[5].w),w(b,"height",I=r[5].h),w(F,"class","a9s-edge-handle a9s-edge-handle-top"),w(F,"x",U=r[5].x),w(F,"y",P=r[5].y),w(F,"height",1),w(F,"width",T=r[5].w),w(A,"class","a9s-edge-handle a9s-edge-handle-right"),w(A,"x",L=r[5].x+r[5].w),w(A,"y",D=r[5].y),w(A,"height",N=r[5].h),w(A,"width",1),w(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),w(O,"x",B=r[5].x),w(O,"y",k=r[5].y+r[5].h),w(O,"height",1),w(O,"width",V=r[5].w),w(K,"class","a9s-edge-handle a9s-edge-handle-left"),w(K,"x",X=r[5].x),w(K,"y",ft=r[5].y),w(K,"height",H=r[5].h),w(K,"width",1)},m(Y,G){ot(Y,t,G),Ct(t,e),Ct(e,i),Ct(e,l),ot(Y,p,G),ot(Y,f,G),ot(Y,g,G),ot(Y,b,G),ot(Y,M,G),ot(Y,F,G),ot(Y,E,G),ot(Y,A,G),ot(Y,$,G),ot(Y,O,G),ot(Y,z,G),ot(Y,K,G),ot(Y,mt,G),Bt(J,Y,G),ot(Y,ut,G),Bt(gt,Y,G),ot(Y,Et,G),Bt(Dt,Y,G),ot(Y,Yt,G),Bt(Vt,Y,G),et=!0,$e||(ts=[Pt(f,"pointerdown",function(){Zt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(b,"pointerdown",function(){Zt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(F,"pointerdown",function(){Zt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Pt(A,"pointerdown",function(){Zt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Pt(O,"pointerdown",function(){Zt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Pt(K,"pointerdown",function(){Zt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],$e=!0)},p(Y,G){r=Y,(!et||G&64&&n!==(n=r[6].x))&&w(i,"x",n),(!et||G&64&&s!==(s=r[6].y))&&w(i,"y",s),(!et||G&64&&o!==(o=r[6].w))&&w(i,"width",o),(!et||G&64&&a!==(a=r[6].h))&&w(i,"height",a),(!et||G&32&&h!==(h=r[5].x))&&w(l,"x",h),(!et||G&32&&c!==(c=r[5].y))&&w(l,"y",c),(!et||G&32&&u!==(u=r[5].w))&&w(l,"width",u),(!et||G&32&&d!==(d=r[5].h))&&w(l,"height",d),(!et||G&32&&m!==(m=r[5].x))&&w(f,"x",m),(!et||G&32&&y!==(y=r[5].y))&&w(f,"y",y),(!et||G&32&&_!==(_=r[5].w))&&w(f,"width",_),(!et||G&32&&v!==(v=r[5].h))&&w(f,"height",v),(!et||G&2)&&w(b,"style",r[1]),(!et||G&32&&S!==(S=r[5].x))&&w(b,"x",S),(!et||G&32&&R!==(R=r[5].y))&&w(b,"y",R),(!et||G&32&&C!==(C=r[5].w))&&w(b,"width",C),(!et||G&32&&I!==(I=r[5].h))&&w(b,"height",I),(!et||G&32&&U!==(U=r[5].x))&&w(F,"x",U),(!et||G&32&&P!==(P=r[5].y))&&w(F,"y",P),(!et||G&32&&T!==(T=r[5].w))&&w(F,"width",T),(!et||G&32&&L!==(L=r[5].x+r[5].w))&&w(A,"x",L),(!et||G&32&&D!==(D=r[5].y))&&w(A,"y",D),(!et||G&32&&N!==(N=r[5].h))&&w(A,"height",N),(!et||G&32&&B!==(B=r[5].x))&&w(O,"x",B),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&w(O,"y",k),(!et||G&32&&V!==(V=r[5].w))&&w(O,"width",V),(!et||G&32&&X!==(X=r[5].x))&&w(K,"x",X),(!et||G&32&&ft!==(ft=r[5].y))&&w(K,"y",ft),(!et||G&32&&H!==(H=r[5].h))&&w(K,"height",H);const Ar={};G&32&&(Ar.x=r[5].x),G&32&&(Ar.y=r[5].y),G&8&&(Ar.scale=r[3]),J.$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]),gt.$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){et||(q(J.$$.fragment,Y),q(gt.$$.fragment,Y),q(Dt.$$.fragment,Y),q(Vt.$$.fragment,Y),et=!0)},o(Y){at(J.$$.fragment,Y),at(gt.$$.fragment,Y),at(Dt.$$.fragment,Y),at(Vt.$$.fragment,Y),et=!1},d(Y){Y&&(st(t),st(p),st(f),st(g),st(b),st(M),st(F),st(E),st(A),st($),st(O),st(z),st(K),st(mt),st(ut),st(Et),st(Yt)),Ot(J,Y),Ot(gt,Y),Ot(Dt,Y),Ot(Vt,Y),$e=!1,Fe(ts)}}}function Fv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[Nv,({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(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function kv(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,y,_)=>{const v=m.geometry.bounds;let[g,b]=[v.minX,v.minY],[S,R]=[v.maxX,v.maxY];const[C,I]=_;if(y==="SHAPE")g+=C,S+=C,b+=I,R+=I;else{switch(y){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=I;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=I;break}}switch(y){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const M=Math.min(g,S),F=Math.min(b,R),U=Math.abs(S-g),P=Math.abs(R-b);return{...m,geometry:{x:M,y:F,w:U,h:P,bounds:{minX:M,minY:F,maxX:M+U,maxY:F+P}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){ae.call(this,r,m)}function p(m){ae.call(this,r,m)}function f(m){ae.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 Uv extends jt{constructor(t){super(),zt(this,t,kv,Fv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Gu=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(Gu.call(r,e)&&++i&&!Gu.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 Gv=12,$v=(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,y=Math.sqrt(Math.pow(d[0]-p,2)+Math.pow(d[1]-f,2))>Gv/t;return{point:[p,f],visible:y,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function Ba(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function $u(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Hu(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Xu(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function Oa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function La(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Vu(r){let t,e,i,n;return{c(){t=it("circle"),w(t,"cx",e=r[29][0]),w(t,"cy",i=r[29][1]),w(t,"r",n=Pn/r[3]),w(t,"class","svelte-1vxo6dc")},m(s,o){ot(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=Pn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function zu(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=it("mask"),e=it("rect"),a=it("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=Pn/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){ot(u,t,d),Ct(t,e),Ct(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=Pn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function ju(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Ui({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(){Zt(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(){Lt(t.$$.fragment)},m(n,s){Bt(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){at(t.$$.fragment,n),e=!1},d(n){Ot(t,n)}}}function Wu(r){let t,e,i=xe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=ju(Xu(r,i,o));const s=o=>at(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);ot(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=Xu(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=ju(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(le(),l=i.length;l<n.length;l+=1)s(l);he()}},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)at(n[a]);e=!1},d(o){o&&st(t),Dr(n,o)}}}function Yu(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v=r[6]!==void 0&&!r[7]&&Vu(La(r)),g=r[6]!==void 0&&!r[7]&&zu(Oa(r)),b=xe(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Wu(Hu(r,b,C));const R=C=>at(S[C],1,1,()=>{S[C]=null});return{c(){t=it("g"),e=it("defs"),i=it("mask"),n=it("rect"),h=it("path"),v&&v.c(),g&&g.c(),u=it("path"),p=it("path");for(let C=0;C<S.length;C+=1)S[C].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=ki(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=ki(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=ki(r[30]))},m(C,I){ot(C,t,I),Ct(t,e),Ct(e,i),Ct(i,n),Ct(i,h),v&&v.m(i,null),g&&g.m(e,null),Ct(t,u),Ct(t,p);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);m=!0,y||(_=[Pt(u,"pointerup",r[13]),Pt(u,"pointerdown",function(){Zt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Pt(p,"pointerup",r[13]),Pt(p,"pointerdown",function(){Zt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!m||I[0]&512&&s!==(s=r[9].x))&&w(n,"x",s),(!m||I[0]&512&&o!==(o=r[9].y))&&w(n,"y",o),(!m||I[0]&512&&a!==(a=r[9].w))&&w(n,"width",a),(!m||I[0]&512&&l!==(l=r[9].h))&&w(n,"height",l),(!m||I[0]&32&&c!==(c=ki(r[30])))&&w(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(La(r),I):(v=Vu(La(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(Oa(r),I):(g=zu(Oa(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=ki(r[30])))&&w(u,"d",d),(!m||I[0]&2)&&w(p,"style",r[1]),(!m||I[0]&32&&f!==(f=ki(r[30])))&&w(p,"d",f),I[0]&268491048){b=xe(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Hu(r,b,M);S[M]?(S[M].p(F,I),q(S[M],1)):(S[M]=Wu(F),S[M].c(),q(S[M],1),S[M].m(t,null))}for(le(),M=b.length;M<S.length;M+=1)R(M);he()}},i(C){if(!m){for(let I=0;I<b.length;I+=1)q(S[I]);m=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)at(S[I]);m=!1},d(C){C&&st(t),v&&v.d(),g&&g.d(),Dr(S,C),y=!1,Fe(_)}}}function qu(r){let t,e;return t=new Mu({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Zt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Hv(r){let t,e,i,n=xe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Yu($u(r,n,l));const o=l=>at(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&qu(Ba(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);ot(l,t,h),a&&a.m(l,h),ot(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=$u(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=Yu(u),s[c].c(),q(s[c],1),s[c].m(t.parentNode,t))}for(le(),c=n.length;c<s.length;c+=1)o(c);he()}l[6]!==void 0&&!l[7]?a?(a.p(Ba(l),h),h[0]&192&&q(a,1)):(a=qu(Ba(l)),a.c(),q(a,1),a.m(e.parentNode,e)):a&&(le(),at(a,1,1,()=>{a=null}),he())},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)at(s[h]);at(a),i=!1},d(l){l&&(st(t),st(e)),Dr(s,l),a&&a.d(l)}}}function Xv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[Hv,({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(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}const Vv=250,zv=1e3,Pn=4.5;function jv(r,t,e){let i,n,s;const o=Bi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const y=()=>e(7,p=!0),_=()=>e(7,p=!1),v=A=>{if(m.length>0||!n.some(V=>V.visible)){e(6,d=void 0);return}const[L,D]=h.elementToImage(A.offsetX,A.offsetY),N=V=>Math.pow(V[0]-L,2)+Math.pow(V[1]-D,2),$=sv(i).reduce((V,z)=>N(z)<N(V)?z:V),O=n.filter(V=>V.visible).reduce((V,z)=>N(z.point)<N(V.point)?z:V),B=Math.pow(zv/c,2);N($)<B||N(O.point)<B?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,p=!0),A.preventDefault(),A.stopPropagation(),f=performance.now()},R=(A,L,D)=>N=>{if(!f||Or||performance.now()-f>Vv)return;const $=B=>B.polygon===A&&B.ring===L&&B.point===D,O=m.some($);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(B=>!$(B))):e(8,m=[...m,{polygon:A,ring:L,point:D}]):O&&m.length>1?e(8,m=[{polygon:A,ring:L,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:A,ring:L,point:D}]),g()},C=(A,L,D)=>{g();const N=A.geometry.polygons;let $;if(L==="SHAPE")$=N.map(O=>{const B=O.rings.map((V,z)=>({points:V.points.map((X,ft)=>[X[0]+D[0],X[1]+D[1]])})),k=tr(B[0].points);return{rings:B,bounds:k}});else{const[O,B,k,V]=L.split("-").map(z=>parseInt(z));$=N.map((z,K)=>{if(K===B){const X=z.rings.map((H,mt)=>mt===k?{points:H.points.map((ut,gt)=>gt===V?[ut[0]+D[0],ut[1]+D[1]]:ut)}:H),ft=tr(X[0].points);return{rings:X,bounds:ft}}else return z})}return{...A,geometry:{polygons:$,bounds:Ts($)}}},I=A=>async L=>{L.stopPropagation();const D=n[A],N=i.polygons.map((O,B)=>{if(B===D.elementIdx){const k=O.rings.map((z,K)=>K===D.ringIdx?{points:[...z.points.slice(0,D.pointIdx+1),D.point,...z.points.slice(D.pointIdx+1)]}:z),V=tr(k[0].points);return{rings:k,bounds:V}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Ts(N)}}),await xu();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const O=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});$.firstChild.dispatchEvent(O)}},M=()=>{const A=i.polygons.map((D,N)=>{if(m.some(O=>O.polygon===N)){const O=D.rings.map((k,V)=>{const z=m.filter(K=>K.polygon===N&&K.ring===V);return z.length&&k.points.length-z.length>=3?{points:k.points.filter((X,ft)=>!z.some(H=>H.point===ft))}:k}),B=tr(O[0].points);return{rings:O,bounds:B}}else return D});!Da(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:Ts(A)}}),e(8,m=[]))};ei(()=>{if(Or)return;const A=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",A),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",A)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(A,L,D,{polygon:N,ring:$,point:O})=>N===A&&$===L&&O===D;function P(A){ae.call(this,r,A)}function T(A){ae.call(this,r,A)}function E(A){ae.call(this,r,A)}return r.$$set=A=>{"shape"in A&&e(0,a=A.shape),"computedStyle"in A&&e(1,l=A.computedStyle),"transform"in A&&e(2,h=A.transform),"viewportScale"in A&&e(3,c=A.viewportScale),"svgEl"in A&&e(4,u=A.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Or?[]:$v(i,c)),r.$$.dirty[0]&40&&e(9,s=Ca(i.bounds,Pn/c))},[a,l,h,c,u,i,d,p,m,s,n,y,_,b,S,R,C,I,F,U,P,T,E]}class Wv extends jt{constructor(t){super(),zt(this,t,jv,Xv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}Qe.RECTANGLE,Qe.POLYGON,Qe.MULTIPOLYGON;function Yv(r,t,e){let i;const n=Bi();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=yv(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 qv extends jt{constructor(t){super(),zt(this,t,Yv,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||{}),Ku=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(Ku||{}),Na=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Na||{}),vt=(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))(vt||{}),er=(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))(er||{}),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||{}),Gi=(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))(Gi||{}),pt=(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))(pt||{}),Q=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(Q||{}),mr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(mr||{}),Lr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Lr||{}),rr=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(rr||{}),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||{}),ir=(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))(ir||{}),Fa=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(Fa||{}),ke=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(ke||{}),ie=(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))(ie||{}),ee=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(ee||{}),nr=(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))(nr||{});const tt={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,Zu=/iPod/i,Ju=/iPad/i,Qu=/\biOS-universal(?:.+)Mac\b/i,Ua=/\bAndroid(?:.+)Mobile\b/i,td=/Android/i,$i=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,As=/Silk/i,gr=/Windows Phone/i,ed=/\bWindows(?:.+)ARM\b/i,rd=/BlackBerry/i,id=/BB10/i,nd=/Opera Mini/i,sd=/\b(CriOS|Chrome)(?:.+)Mobile/i,od=/Mobile(?:.+)Firefox\b/i,ad=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function Kv(r){return function(t){return t.test(r)}}function ld(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=Kv(e),s={apple:{phone:n(ka)&&!n(gr),ipod:n(Zu),tablet:!n(ka)&&(n(Ju)||ad(t))&&!n(gr),universal:n(Qu),device:(n(ka)||n(Zu)||n(Ju)||n(Qu)||ad(t))&&!n(gr)},amazon:{phone:n($i),tablet:!n($i)&&n(As),device:n($i)||n(As)},android:{phone:!n(gr)&&n($i)||!n(gr)&&n(Ua),tablet:!n(gr)&&!n($i)&&!n(Ua)&&(n(As)||n(td)),device:!n(gr)&&(n($i)||n(As)||n(Ua)||n(td))||n(/\bokhttp\b/i)},windows:{phone:n(gr),tablet:n(ed),device:n(gr)||n(ed)},other:{blackberry:n(rd),blackberry10:n(id),opera:n(nd),firefox:n(od),chrome:n(sd),device:n(rd)||n(id)||n(nd)||n(od)||n(sd)},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 Zv=ld.default??ld,yr=Zv(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var hd={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 y=this._events[m],_=arguments.length,v,g;if(y.fn){switch(y.once&&this.removeListener(h,y.fn,void 0,!0),_){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,c),!0;case 3:return y.fn.call(y.context,c,u),!0;case 4:return y.fn.call(y.context,c,u,d),!0;case 5:return y.fn.call(y.context,c,u,d,p),!0;case 6:return y.fn.call(y.context,c,u,d,p,f),!0}for(g=1,v=new Array(_-1);g<_;g++)v[g-1]=arguments[g];y.fn.apply(y.context,v)}else{var b=y.length,S;for(g=0;g<b;g++)switch(y[g].once&&this.removeListener(h,y[g].fn,void 0,!0),_){case 1:y[g].fn.call(y[g].context);break;case 2:y[g].fn.call(y[g].context,c);break;case 3:y[g].fn.call(y[g].context,c,u);break;case 4:y[g].fn.call(y[g].context,c,u,d);break;default:if(!v)for(S=1,v=new Array(_-1);S<_;S++)v[S-1]=arguments[S];y[g].fn.apply(y[g].context,v)}}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,y=[],_=f.length;m<_;m++)(f[m].fn!==c||d&&!f[m].once||u&&f[m].context!==u)&&y.push(f[m]);y.length?this._events[p]=y.length===1?y[0]:y: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})(hd);var Jv=hd.exports;const Rn=Aa(Jv);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=cd(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=i1(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 Mn(s,o,e,a,l,p,0),o}function cd(r,t,e,i,n){var s,o;if(n===Xa(r,t,e,i)>0)for(s=t;s<e;s+=i)o=fd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=fd(s,r[s],r[s+1],o);return o&&Cs(o,o.next)&&(Bn(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(Bn(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Mn(r,t,e,i,n,s,o){if(r){!o&&s&&l1(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?t1(r,i,n,s):Qv(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Bn(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=e1(ni(r),t,e),Mn(r,t,e,i,n,s,2)):o===2&&r1(r,t,e,i,n,s):Mn(ni(r),t,e,i,n,s,1);break}}}}function Qv(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&&Hi(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 t1(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,y=c>u?c>d?c:d:u>d?u:d,_=$a(p,f,t,e,i),v=$a(m,y,t,e,i),g=r.prevZ,b=r.nextZ;g&&g.z>=_&&b&&b.z<=v;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=y&&g!==n&&g!==o&&Hi(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<=y&&b!==n&&b!==o&&Hi(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>=_;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=y&&g!==n&&g!==o&&Hi(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<=v;){if(b.x>=p&&b.x<=m&&b.y>=f&&b.y<=y&&b!==n&&b!==o&&Hi(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 e1(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!Cs(n,s)&&ud(n,i,i.next,s)&&Dn(n,s)&&Dn(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),Bn(i),Bn(i.next),i=r=s),i=i.next}while(i!==r);return ni(i)}function r1(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&u1(o,a)){var l=dd(o,a);o=ni(o,o.next),l=ni(l,l.next),Mn(o,t,e,i,n,s,0),Mn(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function i1(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=cd(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(c1(h));for(n.sort(n1),s=0;s<n.length;s++)e=s1(n[s],e);return e}function n1(r,t){return r.x-t.x}function s1(r,t){var e=o1(r,t);if(!e)return t;var i=dd(e,r);return ni(i,i.next),ni(e,e.next)}function o1(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&&Hi(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),Dn(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&a1(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function a1(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function l1(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,h1(n)}function h1(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 c1(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 Hi(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 u1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!d1(r,t)&&(Dn(r,t)&&Dn(t,r)&&f1(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 ud(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 d1(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&&ud(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Dn(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 f1(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 dd(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 fd(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 Bn(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 p1=Ga.exports;const m1=Aa(p1);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 Cn=="object"&&Cn;(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="-",y=/^xn--/,_=/[^\x20-\x7E]/,v=/[\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,S=Math.floor,R=String.fromCharCode,C;function I(O){throw new RangeError(g[O])}function M(O,B){for(var k=O.length,V=[];k--;)V[k]=B(O[k]);return V}function F(O,B){var k=O.split("@"),V="";k.length>1&&(V=k[0]+"@",O=k[1]),O=O.replace(v,".");var z=O.split("."),K=M(z,B).join(".");return V+K}function U(O){for(var B=[],k=0,V=O.length,z,K;k<V;)z=O.charCodeAt(k++),z>=55296&&z<=56319&&k<V?(K=O.charCodeAt(k++),(K&64512)==56320?B.push(((z&1023)<<10)+(K&1023)+65536):(B.push(z),k--)):B.push(z);return B}function P(O){return M(O,function(B){var k="";return B>65535&&(B-=65536,k+=R(B>>>10&1023|55296),B=56320|B&1023),k+=R(B),k}).join("")}function T(O){return O-48<10?O-22:O-65<26?O-65:O-97<26?O-97:l}function E(O,B){return O+22+75*(O<26)-((B!=0)<<5)}function A(O,B,k){var V=0;for(O=k?S(O/d):O>>1,O+=S(O/B);O>b*c>>1;V+=l)O=S(O/b);return S(V+(b+1)*O/(O+u))}function L(O){var B=[],k=O.length,V,z=0,K=f,X=p,ft,H,mt,J,ut,gt,Et,Dt,Yt;for(ft=O.lastIndexOf(m),ft<0&&(ft=0),H=0;H<ft;++H)O.charCodeAt(H)>=128&&I("not-basic"),B.push(O.charCodeAt(H));for(mt=ft>0?ft+1:0;mt<k;){for(J=z,ut=1,gt=l;mt>=k&&I("invalid-input"),Et=T(O.charCodeAt(mt++)),(Et>=l||Et>S((a-z)/ut))&&I("overflow"),z+=Et*ut,Dt=gt<=X?h:gt>=X+c?c:gt-X,!(Et<Dt);gt+=l)Yt=l-Dt,ut>S(a/Yt)&&I("overflow"),ut*=Yt;V=B.length+1,X=A(z-J,V,J==0),S(z/V)>a-K&&I("overflow"),K+=S(z/V),z%=V,B.splice(z++,0,K)}return P(B)}function D(O){var B,k,V,z,K,X,ft,H,mt,J,ut,gt=[],Et,Dt,Yt,Vt;for(O=U(O),Et=O.length,B=f,k=0,K=p,X=0;X<Et;++X)ut=O[X],ut<128&&gt.push(R(ut));for(V=z=gt.length,z&&gt.push(m);V<Et;){for(ft=a,X=0;X<Et;++X)ut=O[X],ut>=B&&ut<ft&&(ft=ut);for(Dt=V+1,ft-B>S((a-k)/Dt)&&I("overflow"),k+=(ft-B)*Dt,B=ft,X=0;X<Et;++X)if(ut=O[X],ut<B&&++k>a&&I("overflow"),ut==B){for(H=k,mt=l;J=mt<=K?h:mt>=K+c?c:mt-K,!(H<J);mt+=l)Vt=H-J,Yt=l-J,gt.push(R(E(J+Vt%Yt,0))),H=S(Vt/Yt);gt.push(R(E(H,0))),K=A(k,Dt,V==z),k=0,++V}++k,++B}return gt.join("")}function N(O){return F(O,function(B){return y.test(B)?L(B.slice(4).toLowerCase()):B})}function $(O){return F(O,function(B){return _.test(B)?"xn--"+D(B):B})}if(o={version:"1.4.1",ucs2:{decode:U,encode:P},decode:L,encode:D,toASCII:$,toUnicode:N},i&&n)if(r.exports==i)n.exports=o;else for(C in o)o.hasOwnProperty(C)&&(i[C]=o[C]);else e.punycode=o})(Cn)}(Rs,Rs.exports);var g1=Rs.exports,Xi=TypeError;const y1=Z_(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,pd=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,md=ja&&Set.prototype.forEach,_1=typeof WeakMap=="function"&&WeakMap.prototype,On=_1?WeakMap.prototype.has:null,v1=typeof WeakSet=="function"&&WeakSet.prototype,Ln=v1?WeakSet.prototype.has:null,b1=typeof WeakRef=="function"&&WeakRef.prototype,gd=b1?WeakRef.prototype.deref:null,x1=Boolean.prototype.valueOf,w1=Object.prototype.toString,E1=Function.prototype.toString,T1=String.prototype.match,Ya=String.prototype.slice,Nr=String.prototype.replace,A1=String.prototype.toUpperCase,yd=String.prototype.toLowerCase,_d=RegExp.prototype.test,vd=Array.prototype.concat,sr=Array.prototype.join,S1=Array.prototype.slice,bd=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,Vi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Nn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Vi||!0)?Symbol.toStringTag:null,xd=Object.prototype.propertyIsEnumerable,wd=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Ed(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||_d.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-bd(-r):bd(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=y1,Td=Ja.custom,Ad=Pd(Td)?Td:null,Sd={__proto__:null,double:'"',single:"'"},C1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Bs=function r(t,e,i,n){var s=e||{};if(_r(s,"quoteStyle")&&!_r(Sd,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 Md(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Ed(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Ed(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=z1(s,i);if(typeof n>"u")n=[];else if(Rd(n,t)>=0)return"[Circular]";function d(T,E,A){if(E&&(n=S1.call(n),n.push(E)),A){var L={depth:s.depth};return _r(s,"quoteStyle")&&(L.quoteStyle=s.quoteStyle),r(T,L,i+1,n)}return r(T,s,i+1,n)}if(typeof t=="function"&&!Id(t)){var p=N1(t),f=Os(t,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+sr.call(f,", ")+" }":"")}if(Pd(t)){var m=Vi?Nr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Za.call(t);return typeof t=="object"&&!Vi?Fn(m):m}if(H1(t)){for(var y="<"+yd.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Cd(I1(_[v].value),"double",s);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+yd.call(String(t.nodeName))+">",y}if(Qa(t)){if(t.length===0)return"[]";var g=Os(t,d);return u&&!V1(g)?"["+el(g,u)+"]":"[ "+sr.call(g,", ")+" ]"}if(R1(t)){var b=Os(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!xd.call(t,"cause")?"{ ["+String(t)+"] "+sr.call(vd.call("[cause]: "+d(t.cause),b),", ")+" }":b.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+sr.call(b,", ")+" }"}if(typeof t=="object"&&o){if(Ad&&typeof t[Ad]=="function"&&Ja)return Ja(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(F1(t)){var S=[];return pd&&pd.call(t,function(T,E){S.push(d(E,t,!0)+" => "+d(T,t))}),Dd("Map",Ms.call(t),S,u)}if(G1(t)){var R=[];return md&&md.call(t,function(T){R.push(d(T,t))}),Dd("Set",Ds.call(t),R,u)}if(k1(t))return tl("WeakMap");if($1(t))return tl("WeakSet");if(U1(t))return tl("WeakRef");if(D1(t))return Fn(d(Number(t)));if(O1(t))return Fn(d(qa.call(t)));if(B1(t))return Fn(x1.call(t));if(M1(t))return Fn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Cn<"u"&&t===Cn)return"{ [object globalThis] }";if(!P1(t)&&!Id(t)){var C=Os(t,d),I=wd?wd(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",F=!I&&Nn&&Object(t)===t&&Nn in t?Ya.call(Fr(t),8,-1):M?"Object":"",U=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",P=U+(F||M?"["+sr.call(vd.call([],F||[],M||[]),": ")+"] ":"");return C.length===0?P+"{}":u?P+"{"+el(C,u)+"}":P+"{ "+sr.call(C,", ")+" }"}return String(t)};function Cd(r,t,e){var i=e.quoteStyle||t,n=Sd[i];return n+r+n}function I1(r){return Nr.call(String(r),/"/g,"&quot;")}function si(r){return!Nn||!(typeof r=="object"&&(Nn in r||typeof r[Nn]<"u"))}function Qa(r){return Fr(r)==="[object Array]"&&si(r)}function P1(r){return Fr(r)==="[object Date]"&&si(r)}function Id(r){return Fr(r)==="[object RegExp]"&&si(r)}function R1(r){return Fr(r)==="[object Error]"&&si(r)}function M1(r){return Fr(r)==="[object String]"&&si(r)}function D1(r){return Fr(r)==="[object Number]"&&si(r)}function B1(r){return Fr(r)==="[object Boolean]"&&si(r)}function Pd(r){if(Vi)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 O1(r){if(!r||typeof r!="object"||!qa)return!1;try{return qa.call(r),!0}catch{}return!1}var L1=Object.prototype.hasOwnProperty||function(r){return r in this};function _r(r,t){return L1.call(r,t)}function Fr(r){return w1.call(r)}function N1(r){if(r.name)return r.name;var t=T1.call(E1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Rd(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 F1(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 k1(r){if(!On||!r||typeof r!="object")return!1;try{On.call(r,On);try{Ln.call(r,Ln)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function U1(r){if(!gd||!r||typeof r!="object")return!1;try{return gd.call(r),!0}catch{}return!1}function G1(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 $1(r){if(!Ln||!r||typeof r!="object")return!1;try{Ln.call(r,Ln);try{On.call(r,On)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function H1(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Md(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Md(Ya.call(r,0,t.maxStringLength),t)+i}var n=C1[t.quoteStyle||"single"];n.lastIndex=0;var s=Nr.call(Nr.call(r,n,"\\$1"),/[\x00-\x1f]/g,X1);return Cd(s,"single",t)}function X1(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":"")+A1.call(t.toString(16))}function Fn(r){return"Object("+r+")"}function tl(r){return r+" { ? }"}function Dd(r,t,e,i){var n=i?el(e,i):sr.call(e,", ");return r+" ("+t+") {"+n+"}"}function V1(r){for(var t=0;t<r.length;t++)if(Rd(r[t],`
1
+ (function(qt,se){typeof exports=="object"&&typeof module<"u"?se(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],se):(qt=typeof globalThis<"u"?globalThis:qt||self,se(qt.AnnotoriousOSD={},qt.OpenSeadragon))})(this,function(qt,se){"use strict";var hC=Object.defineProperty;var cC=(qt,se,qr)=>se in qt?hC(qt,se,{enumerable:!0,configurable:!0,writable:!0,value:qr}):qt[se]=qr;var Nh=(qt,se,qr)=>cC(qt,typeof se!="symbol"?se+"":se,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 fe=[];for(let r=0;r<256;++r)fe.push((r+256).toString(16).slice(1));function ig(r,t=0){return(fe[r[t+0]]+fe[r[t+1]]+fe[r[t+2]]+fe[r[t+3]]+"-"+fe[r[t+4]]+fe[r[t+5]]+"-"+fe[r[t+6]]+fe[r[t+7]]+"-"+fe[r[t+8]]+fe[r[t+9]]+"-"+fe[r[t+10]]+fe[r[t+11]]+fe[r[t+12]]+fe[r[t+13]]+fe[r[t+14]]+fe[r[t+15]]).toLowerCase()}let $o;const ng=new Uint8Array(16);function sg(){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(ng)}const og=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Vh={randomUUID:og};function ag(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??sg();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,ig(n)}function lg(r,t,e){return Vh.randomUUID&&!r?Vh.randomUUID():ag(r)}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)}},hg=(r,t,e,i)=>({id:lg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),cg=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},ug=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},dg=(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})),fg=(r,t)=>!Kr(r.target,t.target),pg=(r,t)=>{const e=cg(r,t),i=ug(r,t),n=dg(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:fg(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 mg=(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 pg(d,f)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let gg=()=>({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 yg=250,_g=(r,t)=>{const e=gg(),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,y=performance.now();if(y-o>yg)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=mg(i[_],m)}o=y}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:y}=i[n+1];h(f),u(m),p(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:f,updated:m,deleted:y}=i[n];l(f),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},vg=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},p=(_,v)=>{const g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},f=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(S,R)}else b(v,g)})},1)},m=()=>{const{selected:_}=s,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const b=h.find(S=>S.id===g.id);(!b||!Kr(b,g))&&f("updateAnnotation",g,b)}),h=h.map(g=>v.find(({id:S})=>S===g.id)||g)};s.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Kr(g,v)&&f("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(b=>b.id)),g=new Set(_.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const S=o.getAnnotation(b.id);S&&!Kr(S,b)&&f("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}f("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?f("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?f("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(f("mouseLeaveAnnotation",o.getAnnotation(c)),f("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>f("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(b=>f("createAnnotation",b)),(g||[]).forEach(b=>f("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:S})=>{const R=h.find(C=>C.id===b.id)||b;h=h.map(C=>C.id===b.id?S:C),f("updateAnnotation",S,R)})},{origin:Pr.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(b=>b.id)),g=(_.changes.updated||[]).filter(({newValue:b})=>v.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 y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>f("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>f("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:p,emit:f}},bg=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:[]}),xg=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Pr.REMOTE):console.error(g)}else i.addAnnotation(Ho(_),Pr.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var _;const v=(((_=n.selected)==null?void 0:_.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(p(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},p=(_,v=!0)=>{if(e){const g=e.parseAll||bg(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Pr.REMOTE)}else i.bulkAddAnnotations(_.map(Ho),v,Pr.REMOTE)},f=(_,v)=>{_?n.setSelected(_,v):n.clear()},m=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(Ho(_)),v}};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:y}},wg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Eg=r=>crypto.getRandomValues(new Uint8Array(r)),Tg=(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}}},Ag=(r,t=21)=>Tg(r,t|0,Eg),Sg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=wg[e[r]&63];return t};const Cg=()=>({isGuest:!0,id:Ag("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Ig=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Pg=()=>{const r=[...Ig];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};Sg();var Rg=Object.defineProperty,Mg=(r,t,e)=>t in r?Rg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,zh=(r,t,e)=>Mg(r,typeof t!="symbol"?t+"":t,e);function Rt(){}function Xo(r,t){for(const e in t)r[e]=t[e];return r}function jh(r){return r()}function Wh(){return Object.create(null)}function Me(r){r.forEach(jh)}function Gt(r){return typeof r=="function"}function Kt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Dg(r){return Object.keys(r).length===0}function Yh(r,...t){if(r==null){for(const i of t)i(void 0);return Rt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Vo(r,t,e){r.$$.on_destroy.push(Yh(t,e))}function Bg(r,t,e,i){if(r){const n=qh(r,t,e,i);return r[0](n)}}function qh(r,t,e,i){return r[1]&&i?Xo(e.ctx.slice(),r[1](i(t))):e.ctx}function Og(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 Lg(r,t,e,i,n,s){if(n){const o=qh(t,e,i,s);r.p(o,n)}}function Ng(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 Kh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Ei(r){return r??""}function xt(r,t){r.appendChild(t)}function nt(r,t,e){r.insertBefore(t,e||null)}function rt(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 Zh(r){return document.createTextNode(r)}function we(){return Zh(" ")}function De(){return Zh("")}function St(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 Fg(r){return Array.from(r.childNodes)}function Je(r,t,e){r.classList.toggle(t,!!e)}function kg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let yn;function _n(r){yn=r}function Jh(){if(!yn)throw new Error("Function called outside component initialization");return yn}function Jr(r){Jh().$$.on_mount.push(r)}function Rr(){const r=Jh();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=kg(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function oe(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Ti=[],os=[];let Ai=[];const Qh=[],tc=Promise.resolve();let zo=!1;function ec(){zo||(zo=!0,tc.then(ic))}function rc(){return ec(),tc}function jo(r){Ai.push(r)}const Wo=new Set;let Si=0;function ic(){if(Si!==0)return;const r=yn;do{try{for(;Si<Ti.length;){const t=Ti[Si];Si++,_n(t),Ug(t.$$)}}catch(t){throw Ti.length=0,Si=0,t}for(_n(null),Ti.length=0,Si=0;os.length;)os.pop()();for(let t=0;t<Ai.length;t+=1){const e=Ai[t];Wo.has(e)||(Wo.add(e),e())}Ai.length=0}while(Ti.length);for(;Qh.length;)Qh.pop()();zo=!1,Wo.clear(),_n(r)}function Ug(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 Gg(r){const t=[],e=[];Ai.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ai=t}const as=new Set;let Qr;function Ee(){Qr={r:0,c:[],p:Qr}}function Te(){Qr.r||Me(Qr.c),Qr=Qr.p}function lt(r,t){r&&r.i&&(as.delete(r),r.i(t))}function yt(r,t,e,i){if(r&&r.o){if(as.has(r))return;as.add(r),Qr.c.push(()=>{as.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 re(r){r&&r.c()}function Qt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),jo(()=>{const s=r.$$.on_mount.map(jh).filter(Gt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Me(s),r.$$.on_mount=[]}),n.forEach(jo)}function te(r,t){const e=r.$$;e.fragment!==null&&(Gg(e.after_update),Me(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&&(Ti.push(r),ec(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function pe(r,t,e,i,n,s,o=null,a=[-1]){const l=yn;_n(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Rt,not_equal:n,bound:Wh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Wh(),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,Me(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=Fg(t.target);h.fragment&&h.fragment.l(u),u.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&lt(r.$$.fragment),Qt(r,t.target,t.anchor),ic()}_n(l)}class me{constructor(){zh(this,"$$"),zh(this,"$$set")}$destroy(){te(this,1),this.$destroy=Rt}$on(t,e){if(!Gt(e))return Rt;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&&!Dg(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Hg="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Hg);var _t=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(_t||{}),Xg={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})()})(Xg);const Yo={},Ci=(r,t)=>Yo[r]=t,qo=r=>Yo[r.type].area(r),Vg=(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}},ls=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)},hs=(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},zg=(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},cs=(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))},jg={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}};Ci(_t.ELLIPSE,jg);const Wg={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=cs([n,s],[o,a]);return l/h<=i}};Ci(_t.LINE,Wg);const Yg={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=ls(n.points),a=s.reduce((l,h)=>l+ls(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(hs(s.points,t,e)){let a=!1;for(const l of o)if(hs(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)},He=r=>r.rings.map(t=>zg(t.points)).join(" "),qg=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Ci(_t.MULTIPOLYGON,Yg);const Kg={area:r=>{const t=r.geometry.points;return ls(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return hs(i,t,e)}};Ci(_t.POLYGON,Kg);const Zg={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Zo(t.points,t.closed);return ls(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Zo(n.points,n.closed);return hs(s,t,e)}else return Jg(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=nc(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);e.push(...o.slice(1))}}return e},nc=(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},Jg=(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.type==="CURVE"||s.type==="CURVE"){const o=nc(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let a=0;a<o.length-1;a++)if(sc(t,o[a],o[a+1])<=e)return!0}else if(sc(t,n.point,s.point)<=e)return!0}return!1},sc=(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.type==="CURVE"||n.type==="CURVE"){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(" ")};Ci(_t.POLYLINE,Zg);const Qg={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};Ci(_t.RECTANGLE,Qg);const Le=r=>us(r.target),us=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},ty=(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:_t.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}}}},ey=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}`}},oc="http://www.w3.org/2000/svg",ac=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},ry=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${oc}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},ds=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(oc),i=t.lookupNamespaceURI(null);return e||i?ac(t).firstChild:ac(ry(t)).firstChild},iy=r=>{const t=lc(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}}},ny=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},sy=r=>{const t=lc(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=>ny(o)?{...o,locked:!0}:o);const s=Ae(Zo(e,n));return{points:e,closed:n,bounds:s}},lc=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},oy=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],n=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:_t.POLYGON,geometry:{points:n,bounds:Ae(n)}}},ay=r=>{const t=ds(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:_t.ELLIPSE,geometry:{cx:e,cy:i,rx:n,ry:s,bounds:o}}},ly=r=>{const t=ds(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:_t.LINE,geometry:{points:[[e,n],[i,s]],bounds:o}}},hy=r=>{const t=ds(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=sy(i);if(!n)throw new Error("Could not parse SVG path");return{type:_t.POLYLINE,geometry:n}},cy=r=>{const t=ds(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>iy(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:_t.POLYGON,geometry:{points:i,bounds:n}}:{type:_t.MULTIPOLYGON,geometry:{polygons:e,bounds:n}}},uy=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return oy(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return hy(t);if(t.includes("<path "))return cy(t);if(t.includes("<ellipse "))return ay(t);if(t.includes("<line "))return ly(t);throw"Unsupported SVG shape: "+t},dy=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${He(t)}" />`).join("")}</g>`,fy=r=>{let t;switch(r.type){case _t.POLYGON:{const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(n=>n.join(",")).join(" ")}" /></svg>`;break}case _t.ELLIPSE:{const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`;break}case _t.MULTIPOLYGON:{const e=r.geometry;t=`<svg>${dy(e)}</svg>`;break}case _t.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 _t.POLYLINE:t=`<svg><path d="${Jo(r.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},ge=[];for(let r=0;r<256;++r)ge.push((r+256).toString(16).slice(1));function py(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 Qo;const my=new Uint8Array(16);function gy(){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(my)}const yy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),hc={randomUUID:yy};function _y(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??gy();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,py(n)}function cc(r,t,e){return hc.randomUUID&&!r?hc.randomUUID():_y(r)}var uc=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(uc.call(r,e)&&++i&&!uc.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 vy(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const Ii=[];function ea(r,t=ta){let e;const i=new Set;function n(a){if(vy(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=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 by=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 dc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(dc||{});const fs={selected:[]},xy=(r,t,e)=>{const{subscribe:i,set:n}=ea(fs);let s=t,o=fs;i(m=>o=m);const a=()=>{Mr(o,fs)||n(fs)},l=()=>{var m;return((m=o.selected)==null?void 0:m.length)===0},h=m=>{if(l())return!1;const y=typeof m=="string"?m:m.id;return o.selected.some(_=>_.id===y)},c=(m,y)=>{let _;if(Array.isArray(m)){if(_=m.map(g=>r.getAnnotation(g)).filter(Boolean),_.length<m.length){console.warn("Invalid selection: "+m.filter(g=>!_.some(b=>b.id===g)));return}}else{const g=r.getAnnotation(m);if(!g){console.warn("Invalid selection: "+m);return}_=[g]}const v=_.reduce((g,b)=>{const S=f(b);return S==="EDIT"?[...g,{id:b.id,editable:!0}]:S==="SELECT"?[...g,{id:b.id}]:g},[]);n({selected:v,event:y})},u=(m,y)=>{const _=Array.isArray(m)?m:[m],v=_.map(g=>r.getAnnotation(g)).filter(g=>!!g);n({selected:v.map(g=>{const b=y===void 0?f(g)==="EDIT":y;return{id:g.id,editable:b}})}),v.length!==_.length&&console.warn("Invalid selection",m)},d=m=>{if(l())return!1;const{selected:y}=o;y.some(({id:_})=>m.includes(_))&&n({selected:y.filter(({id:_})=>!m.includes(_))})},p=m=>{s=m,u(o.selected.map(({id:y})=>y))},f=m=>wy(m,s,e);return r.observe(({changes:m})=>d((m.deleted||[]).map(y=>y.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}},wy=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},ye=[];for(let r=0;r<256;++r)ye.push((r+256).toString(16).slice(1));function Ey(r,t=0){return(ye[r[t+0]]+ye[r[t+1]]+ye[r[t+2]]+ye[r[t+3]]+"-"+ye[r[t+4]]+ye[r[t+5]]+"-"+ye[r[t+6]]+ye[r[t+7]]+"-"+ye[r[t+8]]+ye[r[t+9]]+"-"+ye[r[t+10]]+ye[r[t+11]]+ye[r[t+12]]+ye[r[t+13]]+ye[r[t+14]]+ye[r[t+15]]).toLowerCase()}let ra;const Ty=new Uint8Array(16);function Ay(){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(Ty)}const Sy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),fc={randomUUID:Sy};function Cy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Ay();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,Ey(n)}function Iy(r,t,e){return fc.randomUUID&&!r?fc.randomUUID():Cy(r)}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)}},Py=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Ry=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},My=(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})),Dy=(r,t)=>!Mr(r.target,t.target),pc=(r,t)=>{const e=Py(r,t),i=Ry(r,t),n=My(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:Dy(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 By=(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},Oy=(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 pc(d,f)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},ps=r=>{const t=r.id===void 0?Iy():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Ly=r=>r.id!==void 0,Ny=()=>{const r=new Map,t=new Map,e=[],i=(P,T={})=>{e.push({onChange:P,options:T})},n=P=>{const T=e.findIndex(E=>E.onChange==P);T>-1&&e.splice(T,1)},s=(P,T)=>{const E={origin:P,changes:{created:T.created||[],updated:T.updated||[],deleted:T.deleted||[]},state:[...r.values()]};e.forEach(A=>{By(A,E)&&A.onChange(E)})},o=(P,T=Nt.LOCAL)=>{if(P.id&&r.get(P.id))throw Error(`Cannot add annotation ${P.id} - exists already`);{const E=ps(P);r.set(E.id,E),E.bodies.forEach(A=>t.set(A.id,E.id)),s(T,{created:[E]})}},a=(P,T)=>{const E=ps(typeof P=="string"?T:P),A=typeof P=="string"?P:P.id,L=A&&r.get(A);if(L){const D=pc(L,E);return A===E.id?r.set(A,E):(r.delete(A),r.set(E.id,E)),L.bodies.forEach(N=>t.delete(N.id)),E.bodies.forEach(N=>t.set(N.id,E.id)),D}else console.warn(`Cannot update annotation ${A} - does not exist`)},l=(P,T=Nt.LOCAL,E=Nt.LOCAL)=>{const A=Ly(T)?E:T,L=a(P,T);L&&s(A,{updated:[L]})},h=(P,T=Nt.LOCAL)=>{r.get(P.id)?l(P,T):o(P,T)},c=(P,T=Nt.LOCAL)=>{const E=P.reduce((A,L)=>{const D=a(L);return D?[...A,D]:A},[]);E.length>0&&s(T,{updated:E})},u=(P,T=Nt.LOCAL)=>{const E=P.map(ps),{toAdd:A,toUpdate:L}=E.reduce((N,$)=>r.get($.id)?{...N,toUpdate:[...N.toUpdate,$]}:{...N,toAdd:[...N.toAdd,$]},{toAdd:[],toUpdate:[]}),D=L.map(N=>a(N,T)).filter(Boolean);A.forEach(N=>{r.set(N.id,N),N.bodies.forEach($=>t.set($.id,N.id))}),s(T,{created:A,updated:D})},d=(P,T=Nt.LOCAL)=>{const E=r.get(P.annotation);if(E){const A={...E,bodies:[...E.bodies,P]};r.set(E.id,A),t.set(P.id,A.id),s(T,{updated:[{oldValue:E,newValue:A,bodiesCreated:[P]}]})}else console.warn(`Attempt to add body to missing annotation: ${P.annotation}`)},p=()=>[...r.values()],f=(P=Nt.LOCAL)=>{const T=[...r.values()];r.clear(),t.clear(),s(P,{deleted:T})},m=(P,T=!0,E=Nt.LOCAL)=>{const A=P.map(ps);if(T){const L=[...r.values()];r.clear(),t.clear(),A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:A,deleted:L})}else{const L=P.reduce((D,N)=>{const $=N.id&&r.get(N.id);return $?[...D,$]:D},[]);if(L.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${L.map(D=>D.id).join(", ")}`);A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:A})}},y=P=>{const T=typeof P=="string"?P:P.id,E=r.get(T);if(E)return r.delete(T),E.bodies.forEach(A=>t.delete(A.id)),E;console.warn(`Attempt to delete missing annotation: ${T}`)},_=(P,T=Nt.LOCAL)=>{const E=y(P);E&&s(T,{deleted:[E]})},v=(P,T=Nt.LOCAL)=>{const E=P.reduce((A,L)=>{const D=y(L);return D?[...A,D]:A},[]);E.length>0&&s(T,{deleted:E})},g=P=>{const T=r.get(P.annotation);if(T){const E=T.bodies.find(A=>A.id===P.id);if(E){t.delete(E.id);const A={...T,bodies:T.bodies.filter(L=>L.id!==P.id)};return r.set(T.id,A),{oldValue:T,newValue:A,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${P.id} from annotation ${P.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${P.annotation}`)},b=(P,T=Nt.LOCAL)=>{const E=g(P);E&&s(T,{updated:[E]})},S=(P,T=Nt.LOCAL)=>{const E=P.map(A=>g(A)).filter(Boolean);E.length>0&&s(T,{updated:E})},R=P=>{const T=r.get(P);return T?{...T}:void 0},C=P=>{const T=t.get(P);if(T){const E=R(T).bodies.find(A=>A.id===P);if(E)return E;console.error(`Store integrity error: body ${P} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${P}`)},I=(P,T)=>{if(P.annotation!==T.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=r.get(P.annotation);if(E){const A=E.bodies.find(D=>D.id===P.id),L={...E,bodies:E.bodies.map(D=>D.id===A.id?T:D)};return r.set(E.id,L),A.id!==T.id&&(t.delete(A.id),t.set(T.id,L.id)),{oldValue:E,newValue:L,bodiesUpdated:[{oldBody:A,newBody:T}]}}else console.warn(`Attempt to add body to missing annotation ${P.annotation}`)},M=(P,T,E=Nt.LOCAL)=>{const A=I(P,T);A&&s(E,{updated:[A]})},F=(P,T=Nt.LOCAL)=>{const E=P.map(A=>I({id:A.id,annotation:A.annotation},A)).filter(Boolean);s(T,{updated:E})},U=P=>{const T=r.get(P.annotation);if(T){const E={...T,target:{...T.target,...P}};return r.set(T.id,E),{oldValue:T,newValue:E,targetUpdated:{oldTarget:T.target,newTarget:P}}}else console.warn(`Attempt to update target on missing annotation: ${P.annotation}`)};return{addAnnotation:o,addBody:d,all:p,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:S,bulkUpdateAnnotations:c,bulkUpdateBodies:F,bulkUpdateTargets:(P,T=Nt.LOCAL)=>{const E=P.map(A=>U(A)).filter(Boolean);E.length>0&&s(T,{updated:E})},bulkUpsertAnnotations:u,clear:f,deleteAnnotation:_,deleteBody:b,getAnnotation:R,getBody:C,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(P,T=Nt.LOCAL)=>{const E=U(P);E&&s(T,{updated:[E]})},upsertAnnotation:h}},Fy=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let ky=()=>({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 Uy=250,Gy=(r,t)=>{const e=ky(),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,y=performance.now();if(y-o>Uy)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=Oy(i[_],m)}o=y}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:y}=i[n+1];h(f),u(m),p(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:f,updated:m,deleted:y}=i[n];l(f),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},$y=()=>{const{subscribe:r,set:t}=ea([]);return{subscribe:r,set:t}},Hy=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},p=(_,v)=>{const g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},f=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(S,R)}else b(v,g)})},1)},m=()=>{const{selected:_}=s,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const b=h.find(S=>S.id===g.id);(!b||!Mr(b,g))&&f("updateAnnotation",g,b)}),h=h.map(g=>v.find(({id:b})=>b===g.id)||g)};s.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Mr(g,v)&&f("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(b=>b.id)),g=new Set(_.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const S=o.getAnnotation(b.id);S&&!Mr(S,b)&&f("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}f("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?f("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?f("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(f("mouseLeaveAnnotation",o.getAnnotation(c)),f("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>f("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(b=>f("createAnnotation",b)),(g||[]).forEach(b=>f("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:S})=>{const R=h.find(C=>C.id===b.id)||b;h=h.map(C=>C.id===b.id?S:C),f("updateAnnotation",S,R)})},{origin:Nt.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(b=>b.id)),g=(_.changes.updated||[]).filter(({newValue:b})=>v.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(S=>S.id===b.id)||b))}},{origin:Nt.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>f("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>f("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:p,emit:f}},Xy=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:[]}),Vy=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Nt.REMOTE):console.error(g)}else i.addAnnotation(ia(_),Nt.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var _;const v=(((_=n.selected)==null?void 0:_.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(p(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},p=(_,v=!0)=>{if(e){const g=e.parseAll||Xy(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Nt.REMOTE)}else i.bulkAddAnnotations(_.map(ia),v,Nt.REMOTE)},f=(_,v)=>{_?n.setSelected(_,v):n.clear()},m=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(ia(_)),v}};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:y}},zy=(r,t,e)=>typeof t=="function"?t(r,e):t,jy=(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||{}}},Wy="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Yy=r=>crypto.getRandomValues(new Uint8Array(r)),qy=(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}}},Ky=(r,t=21)=>qy(r,t|0,Yy),Zy=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Wy[e[r]&63];return t};const Jy=()=>({isGuest:!0,id:Ky("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Qy=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}`},mc=r=>r?typeof r=="object"?{...r}:r:void 0,t0=(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-${Qy(e)}`,annotation:t,type:n,purpose:s,value:o,creator:mc(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),e0=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});Zy();const r0=(r,t={strict:!0,invertY:!1})=>({parse:e=>i0(e,t),serialize:e=>n0(e,r,t)}),i0=(r,t={strict:!0,invertY:!1})=>{const e=r.id||cc(),{creator:i,created:n,modified:s,body:o,...a}=r,l=t0(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"?ty(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?uy(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:mc(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},n0=(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==_t.RECTANGLE?ey(i.geometry):fy(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:e0(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},Pi=[];function s0(r,t=Rt){let e;const i=new Set;function n(a){if(Kt(r,a)&&(r=a,e)){const l=!Pi.length;for(const h of i)h[1](),Pi.push(h,r);if(l){for(let h=0;h<Pi.length;h+=2)Pi[h][0](Pi[h+1]);Pi.length=0}}}function s(a){n(a(r))}function o(a,l=Rt){const h=[a,l];return i.add(h),i.size===1&&(e=t(n,s)||Rt),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:n,update:s,subscribe:o}}const o0=(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}`)},a0=(r,t)=>{o0(r,t);const{subscribe:e,set:i}=s0(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};`),n||n===0?l+=`fill-opacity:${n};`:i&&(l+="fill-opacity:0.25;"),s&&(l+=`stroke:${s};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},ms=(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}},Ne=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,l0=r=>({}),gc=r=>({grab:r[0]});function h0(r){let t,e,i,n;const s=r[8].default,o=Bg(s,r,r[7],gc);return{c(){t=W("g"),o&&o.c(),x(t,"class","a9s-annotation selected")},m(a,l){nt(a,t,l),o&&o.m(t,null),e=!0,i||(n=[St(t,"pointerup",r[2]),St(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Lg(o,s,a,a[7],e?Og(s,a[7],l,l0):Ng(a[7]),gc)},i(a){e||(lt(o,a),e=!0)},o(a){yt(o,a),e=!1},d(a){a&&rt(t),o&&o.d(a),i=!1,Me(n)}}}function c0(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=y=>_=>{if(c=y,h){const{left:v,top:g}=h.getBoundingClientRect(),b=_.clientX-v,S=_.clientY-g;u=l.elementToImage(b,S)}else{const{offsetX:v,offsetY:g}=_;u=l.elementToImage(v,g)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},f=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),g=[_-u[0],v-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,d=o,s("release",y)};return r.$$set=y=>{"shape"in y&&e(3,o=y.shape),"editor"in y&&e(4,a=y.editor),"transform"in y&&e(5,l=y.transform),"svgEl"in y&&e(6,h=y.svgEl),"$$scope"in y&&e(7,n=y.$$scope)},[p,f,m,o,a,l,h,n,i]}class na extends me{constructor(t){super(),pe(this,t,c0,h0,Kt,{shape:3,editor:4,transform:5,svgEl:6})}}function u0(r){let t,e,i,n,s,o,a,l,h=r[3]&&yc(r);return{c(){t=W("g"),e=W("circle"),h&&h.c(),n=W("circle"),x(e,"class","a9s-handle-buffer svelte-qtyc7s"),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=Ei(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),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){nt(c,t,u),xt(t,e),h&&h.m(t,null),xt(t,n),a||(l=[St(e,"dblclick",r[12]),St(e,"pointerenter",r[13]),St(e,"pointerleave",r[14]),St(e,"pointerdown",r[15]),St(e,"pointerdown",r[6]),St(e,"pointerup",r[16]),St(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=yc(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Ei(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&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&&rt(t),h&&h.d(),a=!1,Me(l)}}}function d0(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"),Je(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 svelte-qtyc7s"),x(n,"role","button"),x(n,"tabindex","0"),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){nt(c,t,u),xt(t,e),xt(t,n),xt(t,o),l||(h=[St(n,"dblclick",r[9]),St(n,"pointerdown",r[10]),St(n,"pointerdown",r[6]),St(n,"pointerup",r[11]),St(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&&Je(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&&rt(t),l=!1,Me(h)}}}function yc(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){nt(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&&rt(t)}}}function f0(r){let t;function e(n,s){return Ne?d0:u0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),nt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&rt(t),i.d(n)}}}function p0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=g=>{g.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(g){oe.call(this,r,g)}function d(g){oe.call(this,r,g)}function p(g){oe.call(this,r,g)}function f(g){oe.call(this,r,g)}function m(g){oe.call(this,r,g)}function y(g){oe.call(this,r,g)}function _(g){oe.call(this,r,g)}function v(g){oe.call(this,r,g)}return r.$$set=g=>{e(8,t=Xo(Xo({},t),Kh(g))),"x"in g&&e(0,n=g.x),"y"in g&&e(1,s=g.y),"scale"in g&&e(2,o=g.scale),"selected"in g&&e(3,a=g.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Kh(t),[n,s,o,a,l,i,h,c,t,u,d,p,f,m,y,_,v]}class Ri extends me{constructor(t){super(),pe(this,t,p0,f0,Kt,{x:0,y:1,scale:2,selected:3})}}function m0(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){nt(l,t,h),xt(t,e),xt(t,n),xt(t,s),o||(a=[St(e,"pointerdown",r[5]),St(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&&rt(t),o=!1,Me(a)}}}function g0(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){nt(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&&rt(t)}}}function y0(r){let t;function e(n,s){return Ne?g0:m0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),nt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&rt(t),i.d(n)}}}function _0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){oe.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 _c extends me{constructor(t){super(),pe(this,t,_0,y0,Kt,{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 vc(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 bc(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=vn/r[3]),x(t,"class","svelte-1h2slbm")},m(s,o){nt(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=vn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function xc(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=vn/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){nt(u,t,d),xt(t,e),xt(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=vn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function wc(r){let t,e;return t=new Ri({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function Ec(r){let t,e;return t=new _c({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function v0(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&bc(aa(r)),C=r[6]!==void 0&&!r[7]&&xc(oa(r)),I=Ie(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=wc(vc(r,I,P));const F=P=>yt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Ec(sa(r));return{c(){t=W("defs"),e=W("mask"),i=W("rect"),l=W("polygon"),R&&R.c(),C&&C.c(),c=we(),u=W("polygon"),p=we(),f=W("polygon"),y=we();for(let P=0;P<M.length;P+=1)M[P].c();_=we(),U&&U.c(),v=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(Tc).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(Ac).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(Sc).join(" "))},m(P,T){nt(P,t,T),xt(t,e),xt(e,i),xt(e,l),R&&R.m(e,null),C&&C.m(t,null),nt(P,c,T),nt(P,u,T),nt(P,p,T),nt(P,f,T),nt(P,y,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(P,T);nt(P,_,T),U&&U.m(P,T),nt(P,v,T),g=!0,b||(S=[St(u,"pointerup",r[14]),St(u,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),St(f,"pointermove",r[13]),St(f,"pointerup",r[14]),St(f,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,T){if(r=P,(!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(Tc).join(" ")))&&x(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(aa(r),T):(R=bc(aa(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(oa(r),T):(C=xc(oa(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||T[0]&32&&d!==(d=r[5].points.map(Ac).join(" ")))&&x(u,"points",d),(!g||T[0]&2)&&x(f,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Sc).join(" ")))&&x(f,"points",m),T[0]&134322472){I=Ie(r[5].points);let E;for(E=0;E<I.length;E+=1){const A=vc(r,I,E);M[E]?(M[E].p(A,T),lt(M[E],1)):(M[E]=wc(A),M[E].c(),lt(M[E],1),M[E].m(_.parentNode,_))}for(Ee(),E=I.length;E<M.length;E+=1)F(E);Te()}r[6]!==void 0&&!r[7]?U?(U.p(sa(r),T),T[0]&192&&lt(U,1)):(U=Ec(sa(r)),U.c(),lt(U,1),U.m(v.parentNode,v)):U&&(Ee(),yt(U,1,1,()=>{U=null}),Te())},i(P){if(!g){for(let T=0;T<I.length;T+=1)lt(M[T]);lt(U),g=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)yt(M[T]);yt(U),g=!1},d(P){P&&(rt(t),rt(c),rt(u),rt(p),rt(f),rt(y),rt(_),rt(v)),R&&R.d(),C&&C.d(),Zr(M,P),U&&U.d(P),b=!1,Me(S)}}}function b0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[v0,({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const x0=250,w0=1e3,E0=12,vn=4.5,Tc=r=>r.join(","),Ac=r=>r.join(","),Sc=r=>r.join(",");function T0(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 y=()=>e(7,p=!0),_=()=>e(7,p=!1),v=E=>{if(m.length>0||!n.some(B=>B.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(E.offsetX,E.offsetY),D=B=>Math.pow(B[0]-A,2)+Math.pow(B[1]-L,2),N=i.points.reduce((B,k)=>D(k)<D(B)?k:B),$=n.filter(B=>B.visible).reduce((B,k)=>D(k.point)<D(B.point)?k:B),O=Math.pow(w0/c,2);D(N)<O||D($.point)<O?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=E=>{e(7,p=!0),E.preventDefault(),E.stopPropagation(),f=performance.now()},R=E=>A=>{if(!f||Ne||performance.now()-f>x0)return;const L=m.includes(E);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):L&&m.length>1?e(8,m=[E]):L?e(8,m=[]):e(8,m=[E]),g()},C=(E,A,L)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,B],k)=>m.includes(k)?[O+L[0],B+L[1]]:[O,B]):A==="SHAPE"?D=N.points.map(([O,B])=>[O+L[0],B+L[1]]):D=N.points.map(([O,B],k)=>A===`HANDLE-${k}`?[O+L[0],B+L[1]]:[O,B]);const $=Ae(D);return{...E,geometry:{points:D,bounds:$}}},I=E=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=Ae(L);o("change",{...a,geometry:{points:L,bounds:D}}),await rc();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.firstChild){const $=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:A.clientX,clientY:A.clientY,pointerId:A.pointerId,pointerType:A.pointerType,isPrimary:A.isPrimary,buttons:A.buttons});N.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((L,D)=>!m.includes(D)),A=Ae(E);o("change",{...a,geometry:{points:E,bounds:A}}),e(8,m=[])};Jr(()=>{if(Ne)return;const E=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",E)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){oe.call(this,r,E)}function P(E){oe.call(this,r,E)}function T(E){oe.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=Ne?[]:i.points.map((E,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],D=(E[0]+L[0])/2,N=(E[1]+L[1])/2,$=Math.sqrt(Math.pow(L[0]-D,2)+Math.pow(L[1]-N,2))>E0/c;return{point:[D,N],visible:$}})),r.$$.dirty[0]&40&&e(9,s=ms(i.bounds,vn/c))},[a,l,h,c,u,i,d,p,m,s,n,y,_,v,b,S,R,C,I,F,U,P,T]}class A0 extends me{constructor(t){super(),pe(this,t,T0,b0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function S0(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v,g,b,S,R,C,I,M,F,U,P,T,E,A,L,D,N,$,O,B,k,V,z,K,X,ft,H,mt,J,ut,gt,Et,Dt,Yt,Vt,et,$e,ts;return J=new Ri({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),J.$on("pointerdown",function(){Gt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Ri({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),gt.$on("pointerdown",function(){Gt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Ri({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 Ri({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(),F=W("rect"),E=we(),A=W("rect"),$=we(),O=W("rect"),z=we(),K=W("rect"),mt=we(),re(J.$$.fragment),ut=we(),re(gt.$$.fragment),Et=we(),re(Dt.$$.fragment),Yt=we(),re(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",y=r[5].y),x(f,"width",_=r[5].w),x(f,"height",v=r[5].h),x(b,"class","a9s-inner a9s-shape-handle"),x(b,"style",r[1]),x(b,"x",S=r[5].x),x(b,"y",R=r[5].y),x(b,"width",C=r[5].w),x(b,"height",I=r[5].h),x(F,"class","a9s-edge-handle a9s-edge-handle-top"),x(F,"x",U=r[5].x),x(F,"y",P=r[5].y),x(F,"height",1),x(F,"width",T=r[5].w),x(A,"class","a9s-edge-handle a9s-edge-handle-right"),x(A,"x",L=r[5].x+r[5].w),x(A,"y",D=r[5].y),x(A,"height",N=r[5].h),x(A,"width",1),x(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),x(O,"x",B=r[5].x),x(O,"y",k=r[5].y+r[5].h),x(O,"height",1),x(O,"width",V=r[5].w),x(K,"class","a9s-edge-handle a9s-edge-handle-left"),x(K,"x",X=r[5].x),x(K,"y",ft=r[5].y),x(K,"height",H=r[5].h),x(K,"width",1)},m(Y,G){nt(Y,t,G),xt(t,e),xt(e,i),xt(e,l),nt(Y,p,G),nt(Y,f,G),nt(Y,g,G),nt(Y,b,G),nt(Y,M,G),nt(Y,F,G),nt(Y,E,G),nt(Y,A,G),nt(Y,$,G),nt(Y,O,G),nt(Y,z,G),nt(Y,K,G),nt(Y,mt,G),Qt(J,Y,G),nt(Y,ut,G),Qt(gt,Y,G),nt(Y,Et,G),Qt(Dt,Y,G),nt(Y,Yt,G),Qt(Vt,Y,G),et=!0,$e||(ts=[St(f,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),St(b,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),St(F,"pointerdown",function(){Gt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),St(A,"pointerdown",function(){Gt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),St(O,"pointerdown",function(){Gt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),St(K,"pointerdown",function(){Gt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],$e=!0)},p(Y,G){r=Y,(!et||G&64&&n!==(n=r[6].x))&&x(i,"x",n),(!et||G&64&&s!==(s=r[6].y))&&x(i,"y",s),(!et||G&64&&o!==(o=r[6].w))&&x(i,"width",o),(!et||G&64&&a!==(a=r[6].h))&&x(i,"height",a),(!et||G&32&&h!==(h=r[5].x))&&x(l,"x",h),(!et||G&32&&c!==(c=r[5].y))&&x(l,"y",c),(!et||G&32&&u!==(u=r[5].w))&&x(l,"width",u),(!et||G&32&&d!==(d=r[5].h))&&x(l,"height",d),(!et||G&32&&m!==(m=r[5].x))&&x(f,"x",m),(!et||G&32&&y!==(y=r[5].y))&&x(f,"y",y),(!et||G&32&&_!==(_=r[5].w))&&x(f,"width",_),(!et||G&32&&v!==(v=r[5].h))&&x(f,"height",v),(!et||G&2)&&x(b,"style",r[1]),(!et||G&32&&S!==(S=r[5].x))&&x(b,"x",S),(!et||G&32&&R!==(R=r[5].y))&&x(b,"y",R),(!et||G&32&&C!==(C=r[5].w))&&x(b,"width",C),(!et||G&32&&I!==(I=r[5].h))&&x(b,"height",I),(!et||G&32&&U!==(U=r[5].x))&&x(F,"x",U),(!et||G&32&&P!==(P=r[5].y))&&x(F,"y",P),(!et||G&32&&T!==(T=r[5].w))&&x(F,"width",T),(!et||G&32&&L!==(L=r[5].x+r[5].w))&&x(A,"x",L),(!et||G&32&&D!==(D=r[5].y))&&x(A,"y",D),(!et||G&32&&N!==(N=r[5].h))&&x(A,"height",N),(!et||G&32&&B!==(B=r[5].x))&&x(O,"x",B),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&x(O,"y",k),(!et||G&32&&V!==(V=r[5].w))&&x(O,"width",V),(!et||G&32&&X!==(X=r[5].x))&&x(K,"x",X),(!et||G&32&&ft!==(ft=r[5].y))&&x(K,"y",ft),(!et||G&32&&H!==(H=r[5].h))&&x(K,"height",H);const Ar={};G&32&&(Ar.x=r[5].x),G&32&&(Ar.y=r[5].y),G&8&&(Ar.scale=r[3]),J.$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]),gt.$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){et||(lt(J.$$.fragment,Y),lt(gt.$$.fragment,Y),lt(Dt.$$.fragment,Y),lt(Vt.$$.fragment,Y),et=!0)},o(Y){yt(J.$$.fragment,Y),yt(gt.$$.fragment,Y),yt(Dt.$$.fragment,Y),yt(Vt.$$.fragment,Y),et=!1},d(Y){Y&&(rt(t),rt(p),rt(f),rt(g),rt(b),rt(M),rt(F),rt(E),rt(A),rt($),rt(O),rt(z),rt(K),rt(mt),rt(ut),rt(Et),rt(Yt)),te(J,Y),te(gt,Y),te(Dt,Y),te(Vt,Y),$e=!1,Me(ts)}}}function C0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[S0,({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function I0(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,y,_)=>{const v=m.geometry.bounds;let[g,b]=[v.minX,v.minY],[S,R]=[v.maxX,v.maxY];const[C,I]=_;if(y==="SHAPE")g+=C,S+=C,b+=I,R+=I;else{switch(y){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=I;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=I;break}}switch(y){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const M=Math.min(g,S),F=Math.min(b,R),U=Math.abs(S-g),P=Math.abs(R-b);return{...m,geometry:{x:M,y:F,w:U,h:P,bounds:{minX:M,minY:F,maxX:M+U,maxY:F+P}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){oe.call(this,r,m)}function p(m){oe.call(this,r,m)}function f(m){oe.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=ms(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,p,f]}class P0 extends me{constructor(t){super(),pe(this,t,I0,C0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Cc=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(Cc.call(r,e)&&++i&&!Cc.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 R0=12,M0=(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))>R0/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 Ic(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Pc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Rc(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 Mc(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=bn/r[3]),x(t,"class","svelte-1vxo6dc")},m(s,o){nt(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=bn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function Dc(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=bn/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){nt(u,t,d),xt(t,e),xt(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=bn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Bc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Ri({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(){re(t.$$.fragment)},m(n,s){Qt(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||(lt(t.$$.fragment,n),e=!0)},o(n){yt(t.$$.fragment,n),e=!1},d(n){te(t,n)}}}function Oc(r){let t,e,i=Ie(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Bc(Rc(r,i,o));const s=o=>yt(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);nt(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=Rc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=Bc(h),n[l].c(),lt(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)lt(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)yt(n[a]);e=!1},d(o){o&&rt(t),Zr(n,o)}}}function Lc(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v=r[6]!==void 0&&!r[7]&&Mc(ua(r)),g=r[6]!==void 0&&!r[7]&&Dc(ca(r)),b=Ie(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Oc(Pc(r,b,C));const R=C=>yt(S[C],1,1,()=>{S[C]=null});return{c(){t=W("g"),e=W("defs"),i=W("mask"),n=W("rect"),h=W("path"),v&&v.c(),g&&g.c(),u=W("path"),p=W("path");for(let C=0;C<S.length;C+=1)S[C].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=He(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=He(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=He(r[30]))},m(C,I){nt(C,t,I),xt(t,e),xt(e,i),xt(i,n),xt(i,h),v&&v.m(i,null),g&&g.m(e,null),xt(t,u),xt(t,p);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);m=!0,y||(_=[St(u,"pointerup",r[13]),St(u,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),St(p,"pointerup",r[13]),St(p,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!m||I[0]&512&&s!==(s=r[9].x))&&x(n,"x",s),(!m||I[0]&512&&o!==(o=r[9].y))&&x(n,"y",o),(!m||I[0]&512&&a!==(a=r[9].w))&&x(n,"width",a),(!m||I[0]&512&&l!==(l=r[9].h))&&x(n,"height",l),(!m||I[0]&32&&c!==(c=He(r[30])))&&x(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(ua(r),I):(v=Mc(ua(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(ca(r),I):(g=Dc(ca(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=He(r[30])))&&x(u,"d",d),(!m||I[0]&2)&&x(p,"style",r[1]),(!m||I[0]&32&&f!==(f=He(r[30])))&&x(p,"d",f),I[0]&268491048){b=Ie(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Pc(r,b,M);S[M]?(S[M].p(F,I),lt(S[M],1)):(S[M]=Oc(F),S[M].c(),lt(S[M],1),S[M].m(t,null))}for(Ee(),M=b.length;M<S.length;M+=1)R(M);Te()}},i(C){if(!m){for(let I=0;I<b.length;I+=1)lt(S[I]);m=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)yt(S[I]);m=!1},d(C){C&&rt(t),v&&v.d(),g&&g.d(),Zr(S,C),y=!1,Me(_)}}}function Nc(r){let t,e;return t=new _c({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function D0(r){let t,e,i,n=Ie(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Lc(Ic(r,n,l));const o=l=>yt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&Nc(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);nt(l,t,h),a&&a.m(l,h),nt(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=Ic(l,n,c);s[c]?(s[c].p(u,h),lt(s[c],1)):(s[c]=Lc(u),s[c].c(),lt(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&&lt(a,1)):(a=Nc(ha(l)),a.c(),lt(a,1),a.m(e.parentNode,e)):a&&(Ee(),yt(a,1,1,()=>{a=null}),Te())},i(l){if(!i){for(let h=0;h<n.length;h+=1)lt(s[h]);lt(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)yt(s[h]);yt(a),i=!1},d(l){l&&(rt(t),rt(e)),Zr(s,l),a&&a.d(l)}}}function B0(r){let t,e;return t=new na({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[D0,({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const O0=250,L0=1e3,bn=4.5;function N0(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 y=()=>e(7,p=!0),_=()=>e(7,p=!1),v=A=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[L,D]=h.elementToImage(A.offsetX,A.offsetY),N=k=>Math.pow(k[0]-L,2)+Math.pow(k[1]-D,2),$=qg(i).reduce((k,V)=>N(V)<N(k)?V:k),O=n.filter(k=>k.visible).reduce((k,V)=>N(V.point)<N(k.point)?V:k),B=Math.pow(L0/c,2);N($)<B||N(O.point)<B?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,p=!0),A.preventDefault(),A.stopPropagation(),f=performance.now()},R=(A,L,D)=>N=>{if(!f||Ne||performance.now()-f>O0)return;const $=B=>B.polygon===A&&B.ring===L&&B.point===D,O=m.some($);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(B=>!$(B))):e(8,m=[...m,{polygon:A,ring:L,point:D}]):O&&m.length>1?e(8,m=[{polygon:A,ring:L,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:A,ring:L,point:D}]),g()},C=(A,L,D)=>{g();const N=A.geometry.polygons;let $;if(L==="SHAPE")$=N.map(O=>{const B=O.rings.map((V,z)=>({points:V.points.map((K,X)=>[K[0]+D[0],K[1]+D[1]])})),k=Ae(B[0].points);return{rings:B,bounds:k}});else{const[O,B,k,V]=L.split("-").map(z=>parseInt(z));$=N.map((z,K)=>{if(K===B){const X=z.rings.map((H,mt)=>mt===k?{points:H.points.map((J,ut)=>ut===V?[J[0]+D[0],J[1]+D[1]]:J)}:H),ft=Ae(X[0].points);return{rings:X,bounds:ft}}else return z})}return{...A,geometry:{polygons:$,bounds:Ko($)}}},I=A=>async L=>{L.stopPropagation();const D=n[A],N=i.polygons.map((O,B)=>{if(B===D.elementIdx){const k=O.rings.map((z,K)=>K===D.ringIdx?{points:[...z.points.slice(0,D.pointIdx+1),D.point,...z.points.slice(D.pointIdx+1)]}:z),V=Ae(k[0].points);return{rings:k,bounds:V}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Ko(N)}}),await rc();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const O=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});$.firstChild.dispatchEvent(O)}},M=()=>{const A=i.polygons.map((L,D)=>{if(m.some(N=>N.polygon===D)){const N=L.rings.map((O,B)=>{const k=m.filter(V=>V.polygon===D&&V.ring===B);return k.length&&O.points.length-k.length>=3?{points:O.points.filter((V,z)=>!k.some(K=>K.point===z))}:O}),$=Ae(N[0].points);return{rings:N,bounds:$}}else return L});!la(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:Ko(A)}}),e(8,m=[]))};Jr(()=>{if(Ne)return;const A=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",A),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",A)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(A,L,D,{polygon:N,ring:$,point:O})=>N===A&&$===L&&O===D;function P(A){oe.call(this,r,A)}function T(A){oe.call(this,r,A)}function E(A){oe.call(this,r,A)}return r.$$set=A=>{"shape"in A&&e(0,a=A.shape),"computedStyle"in A&&e(1,l=A.computedStyle),"transform"in A&&e(2,h=A.transform),"viewportScale"in A&&e(3,c=A.viewportScale),"svgEl"in A&&e(4,u=A.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Ne?[]:M0(i,c)),r.$$.dirty[0]&40&&e(9,s=ms(i.bounds,bn/c))},[a,l,h,c,u,i,d,p,m,s,n,y,_,b,S,R,C,I,F,U,P,T,E]}class F0 extends me{constructor(t){super(),pe(this,t,N0,B0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Fc=new Map([[_t.RECTANGLE,P0],[_t.POLYGON,A0],[_t.MULTIPOLYGON,F0]]),da=r=>Fc.get(r.type),kc=(r,t)=>Fc.set(r,t);function k0(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 U0 extends me{constructor(t){super(),pe(this,t,k0,null,Kt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function G0(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 $0 extends me{constructor(t){super(),pe(this,t,G0,null,Kt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Uc(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){nt(u,t,d),xt(t,e),xt(e,i),xt(e,l),nt(u,h,d),nt(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&&(rt(t),rt(h),rt(c))}}}function H0(r){let t,e=r[0]&&Uc(r);return{c(){t=W("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){nt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[0]?e?e.p(i,n):(e=Uc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&rt(t),e&&e.d()}}}function X0(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 y=S=>{const R=S;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))},_=S=>{const R=S;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])))},v=S=>{const R=S,C=performance.now()-h;if(o==="click"){if(C>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&&(C>300||f*m>100?(R.stopPropagation(),g()):(e(0,c=void 0),u=void 0))},g=()=>{if(f*m>15){const S={type:_t.RECTANGLE,geometry:{bounds:{minX:d,minY:p,maxX:d+f,maxY:p+m},x:d,y:p,w:f,h:m}};n("create",S)}e(0,c=void 0),u=void 0};Jr(()=>{s("pointerdown",y),s("pointermove",_),s("pointerup",v,!0)});const b=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=S=>{"addEventListener"in S&&e(7,s=S.addEventListener),"drawingMode"in S&&e(8,o=S.drawingMode),"transform"in S&&e(9,a=S.transform),"viewportScale"in S&&e(10,l=S.viewportScale)},r.$$.update=()=>{r.$$.dirty&1024&&e(5,i=2/l)},[c,d,p,f,m,i,b,s,o,a,l]}class V0 extends me{constructor(t){super(),pe(this,t,X0,H0,Kt,{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 Gc(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m=r[1]&&$c(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(y,_){nt(y,t,_),xt(t,e),xt(e,i),xt(e,l),nt(y,c,_),nt(y,d,_),m&&m.m(y,_),nt(y,f,_)},p(y,_){_&8&&n!==(n=y[3].x)&&x(i,"x",n),_&8&&s!==(s=y[3].y)&&x(i,"y",s),_&8&&o!==(o=y[3].w)&&x(i,"width",o),_&8&&a!==(a=y[3].h)&&x(i,"height",a),_&4&&h!==(h=y[19])&&x(l,"points",h),_&4&&u!==(u=y[19])&&x(c,"points",u),_&4&&p!==(p=y[19])&&x(d,"points",p),y[1]?m?m.p(y,_):(m=$c(y),m.c(),m.m(f.parentNode,f)):m&&(m.d(1),m=null)},d(y){y&&(rt(t),rt(c),rt(d),rt(f)),m&&m.d(y)}}}function $c(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){nt(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&&rt(t)}}}function z0(r){let t,e=r[3]&&Gc(fa(r));return{c(){t=W("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){nt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[3]?e?e.p(fa(i),n):(e=Gc(fa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&rt(t),e&&e.d()}}}const j0=20,W0=1500;function Y0(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 y=R=>{const C=R,{timeStamp:I,offsetX:M,offsetY:F}=C;if(u={timeStamp:I,offsetX:M,offsetY:F},l==="drag"&&d.length===0){const U=h.elementToImage(C.offsetX,C.offsetY);d.push(U),e(10,p=U)}},_=R=>{const C=R;if(f&&clearTimeout(f),d.length>0){if(e(10,p=h.elementToImage(C.offsetX,C.offsetY)),d.length>2){const I=cs(p,d[0])*c;e(1,m=I<j0)}C.pointerType==="touch"&&(f=setTimeout(()=>{g()},W0))}},v=R=>{if(!p)return;const C=R;if(f&&clearTimeout(f),l==="click"){const I=C.timeStamp-u.timeStamp,M=cs([u.offsetX,u.offsetY],[C.offsetX,C.offsetY]);if(I>300||M>15)return;if(m)b();else if(d.length===0){const F=h.elementToImage(C.offsetX,C.offsetY);d.push(F),e(10,p=F)}else d.push(p)}else{if(d.length===1&&cs(d[0],p)<=4){e(0,d=[]),e(10,p=void 0);return}C.stopImmediatePropagation(),m?b():d.push(p)}},g=()=>{if(!p)return;const R=d.slice(0,-1);if(R.length<3)return;const C={type:_t.POLYGON,geometry:{bounds:Ae(d),points:R}};qo(C)>4&&(e(0,d=[]),e(10,p=void 0),o("create",C))},b=()=>{const R={type:_t.POLYGON,geometry:{bounds:Ae(d),points:[...d]}};e(0,d=[]),e(10,p=void 0),o("create",R)};Jr(()=>{a("pointerdown",y,!0),a("pointermove",_),a("pointerup",v,!0),a("dblclick",g,!0)});const S=`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?ms(Ae(n),2/c):void 0)},[d,m,n,s,i,S,a,l,h,c,p]}class q0 extends me{constructor(t){super(),pe(this,t,Y0,z0,Kt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const pa=new Map([["rectangle",{tool:V0}],["polygon",{tool:q0}]]),gs=()=>[...pa.keys()],ys=r=>pa.get(r),Hc=(r,t,e={})=>pa.set(r,{tool:t,opts:e});function K0(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){nt(o,t,a),xt(t,e),xt(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:Rt,o:Rt,d(o){o&&rt(t)}}}function Z0(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 J0 extends me{constructor(t){super(),pe(this,t,Z0,K0,Kt,{annotation:0,geom:6,style:7})}}function Q0(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){nt(o,t,a),xt(t,e),xt(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:Rt,o:Rt,d(o){o&&rt(t)}}}function t_(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 e_ extends me{constructor(t){super(),pe(this,t,t_,Q0,Kt,{annotation:0,geom:6,style:7})}}function Xc(r,t,e){const i=r.slice();return i[5]=t[e],i}function Vc(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",He(r[5])),x(i,"class","a9s-inner"),x(i,"style",r[1]),x(i,"fill-rule","evenodd"),x(i,"d",He(r[5]))},m(n,s){nt(n,t,s),nt(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&&(rt(t),rt(i))}}}function r_(r){let t,e,i=Ie(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=Vc(Xc(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){nt(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=Xc(s,i,a);n[a]?n[a].p(l,o):(n[a]=Vc(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:Rt,o:Rt,d(s){s&&rt(t),Zr(n,s)}}}function i_(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 n_ extends me{constructor(t){super(),pe(this,t,i_,r_,Kt,{annotation:0,geom:3,style:4})}}function s_(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(o_).join(" ")),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"points",r[2].map(a_).join(" ")),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(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:Rt,o:Rt,d(o){o&&rt(t)}}}const o_=r=>r.join(","),a_=r=>r.join(",");function l_(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 h_ extends me{constructor(t){super(),pe(this,t,l_,s_,Kt,{annotation:0,geom:3,style:4})}}function c_(r){let t,e,i,n,s,o,a;return{c(){t=W("g"),e=W("path"),s=W("path"),x(e,"class",i=Ei(`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=Ei(`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){nt(l,t,h),xt(t,e),xt(t,s)},p(l,[h]){h&2&&i!==(i=Ei(`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=Ei(`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:Rt,o:Rt,d(l){l&&rt(t)}}}function u_(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 d_ extends me{constructor(t){super(),pe(this,t,u_,c_,Kt,{annotation:0,geom:4,style:5})}}function f_(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){nt(o,t,a),xt(t,e),xt(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:Rt,o:Rt,d(o){o&&rt(t)}}}function p_(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 m_ extends me{constructor(t){super(),pe(this,t,p_,f_,Kt,{annotation:0,geom:6,style:7})}}const g_=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]}}),y_=250,__=(r,t)=>{const e=Rr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<y_){const{x:s,y:o}=zc(n,r),a=Ne?10:2,l=t.getAt(s,o,void 0,a);l?e("click",{originalEvent:n,annotation:l}):e("click",{originalEvent:n})}}}},zc=(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 jc(r,t,e){const i=r.slice();return i[39]=t[e],i}function Wc(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 Yc(r){let t=r[42],e,i,n=qc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&131072&&Kt(t,t=s[42])?(Ee(),yt(n,1,1,Rt),Te(),n=qc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function v_(r){let t,e;return t=new e_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function b_(r){let t,e;return t=new d_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function x_(r){let t,e;return t=new n_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function w_(r){let t,e;return t=new h_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function E_(r){let t,e;return t=new m_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function T_(r){var t;let e,i;return e=new J0({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){re(e.$$.fragment)},m(n,s){Qt(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||(lt(e.$$.fragment,n),i=!0)},o(n){yt(e.$$.fragment,n),i=!1},d(n){te(e,n)}}}function qc(r){let t,e,i,n;const s=[T_,E_,w_,x_,b_,v_],o=[];function a(l,h){var c,u,d,p,f,m;return((c=l[45])==null?void 0:c.type)===_t.ELLIPSE?0:((u=l[45])==null?void 0:u.type)===_t.RECTANGLE?1:((d=l[45])==null?void 0:d.type)===_t.POLYGON?2:((p=l[45])==null?void 0:p.type)===_t.MULTIPOLYGON?3:((f=l[45])==null?void 0:f.type)===_t.POLYLINE?4:((m=l[45])==null?void 0:m.type)===_t.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),nt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),yt(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()),lt(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(lt(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function Kc(r){let t=Le(r[42])&&!r[10](r[42]),e,i,n=t&&Yc(ma(r));return{c(){n&&n.c(),e=De()},m(s,o){n&&n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&132096&&(t=Le(s[42])&&!s[10](s[42])),t?n?(n.p(ma(s),o),o[0]&132096&&lt(n,1)):(n=Yc(ma(s)),n.c(),lt(n,1),n.m(e.parentNode,e)):n&&(Ee(),yt(n,1,1,()=>{n=null}),Te())},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n&&n.d(s)}}}function Zc(r){let t,e,i,n;const s=[S_,A_],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),nt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),yt(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()),lt(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(lt(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function A_(r){let t=`${r[2]}-${r[7]}`,e,i,n=Jc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&132&&Kt(t,t=`${s[2]}-${s[7]}`)?(Ee(),yt(n,1,1,Rt),Te(),n=Jc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function S_(r){let t,e,i=Ie(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=tu(jc(r,i,o));const s=o=>yt(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);nt(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=jc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=tu(h),n[l].c(),lt(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)lt(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)yt(n[a]);e=!1},d(o){o&&rt(t),Zr(n,o)}}}function Jc(r){let t,e;return t=new $0({props:{target:r[8],tool:r[15],drawingMode:r[14],transform:r[13],viewportScale:r[18]}}),t.$on("create",r[22]),{c(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function Qc(r){let t,e;return t=new U0({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(){re(t.$$.fragment)},m(i,n){Qt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function tu(r){let t=r[39].annotation.id,e,i,n=Qc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&64&&Kt(t,t=s[39].annotation.id)?(Ee(),yt(n,1,1,Rt),Te(),n=Qc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function C_(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]=Kc(Wc(r,a,u));const h=u=>yt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&Zc(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"),Je(t,"drawing",r[15]),Je(t,"editing",r[5]),Je(t,"hidden",!r[3]),Je(t,"hover",r[16])},m(u,d){nt(u,t,d),xt(t,e);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(e,null);xt(t,i),c&&c.m(i,null),r[35](i),r[36](t),n=!0,s||(o=[St(t,"pointerup",function(){Gt(r[11])&&r[11].apply(this,arguments)}),St(t,"pointerdown",function(){Gt(r[12])&&r[12].apply(this,arguments)}),St(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=Wc(r,a,p);l[p]?(l[p].p(f,d),lt(l[p],1)):(l[p]=Kc(f),l[p].c(),lt(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&&lt(c,1)):(c=Zc(r),c.c(),lt(c,1),c.m(i,null)):c&&(Ee(),yt(c,1,1,()=>{c=null}),Te()),(!n||d[0]&32768)&&Je(t,"drawing",r[15]),(!n||d[0]&32)&&Je(t,"editing",r[5]),(!n||d[0]&8)&&Je(t,"hidden",!r[3]),(!n||d[0]&65536)&&Je(t,"hover",r[16])},i(u){if(!n){for(let d=0;d<a.length;d+=1)lt(l[d]);lt(c),n=!0}},o(u){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)yt(l[d]);yt(c),n=!1},d(u){u&&rt(t),Zr(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,Me(o)}}}function I_(r,t,e){let i,n,s,o,a,l,h,c,u,d,p,f,m=Rt,y=()=>(m(),m=Yh(A,H=>e(18,f=H)),A);r.$$.on_destroy.push(()=>m());let{drawingEnabled:_}=t,{image:v}=t,{preferredDrawingMode:g}=t,{state:b}=t,{style:S=void 0}=t,{toolName:R=gs()[0]}=t,{user:C}=t,{visible:I=!0}=t,M=0;const F=()=>e(7,M+=1),U=()=>R,P=()=>_;let T,E,A;Jr(()=>y(e(9,A=a0(v,E))));const{hover:L,selection:D,store:N}=b;Vo(r,L,H=>e(16,u=H)),Vo(r,D,H=>e(33,d=H)),Vo(r,N,H=>e(17,p=H));let $,O;const B=H=>{$&&N.unobserve($);const mt=H.filter(({editable:J})=>J).map(({id:J})=>J);mt.length>0?(e(5,O=mt.map(J=>N.getAnnotation(J)).filter(J=>J&&Le(J))),$=J=>{const{updated:ut}=J.changes;e(5,O=ut==null?void 0:ut.map(gt=>gt.newValue))},N.observe($,{annotations:mt})):e(5,O=void 0)},k=H=>{const mt=cc(),J={id:mt,bodies:[],target:{annotation:mt,selector:H.detail,creator:C,created:new Date}};N.addAnnotation(J),D.setSelected(J.id)},V=H=>mt=>{var J;const{target:ut}=H,gt=10*60*1e3,Et=((J=ut.creator)==null?void 0:J.id)!==C.id||!ut.created||new Date().getTime()-ut.created.getTime()>gt;N.updateTarget({...ut,selector:mt.detail,created:Et?ut.created:new Date,updated:Et?new Date:void 0,updatedBy:Et?C:void 0})},z=H=>{const{x:mt,y:J}=zc(H,E),ut=N.getAt(mt,J,void 0,2);ut?u!==ut.id&&L.set(ut.id):L.set(void 0)},K=H=>Le(H);function X(H){os[H?"unshift":"push"](()=>{T=H,e(8,T)})}function ft(H){os[H?"unshift":"push"](()=>{E=H,e(4,E)})}return r.$$set=H=>{"drawingEnabled"in H&&e(0,_=H.drawingEnabled),"image"in H&&e(25,v=H.image),"preferredDrawingMode"in H&&e(26,g=H.preferredDrawingMode),"state"in H&&e(27,b=H.state),"style"in H&&e(1,S=H.style),"toolName"in H&&e(2,R=H.toolName),"user"in H&&e(28,C=H.user),"visible"in H&&e(3,I=H.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(15,{tool:i,opts:n}=ys(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=g_(E)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=__(E,N),a,(e(11,l),e(4,E))),r.$$.dirty[1]&4&&B(d.selected),r.$$.dirty[0]&32&&e(6,h=O?O.map(H=>({annotation:H,editor:da(H.target.selector)})).filter(H=>H.editor):void 0),r.$$.dirty[0]&64&&e(10,c=H=>h&&h.some(mt=>mt.annotation.id===H.id))},[_,S,R,I,E,O,h,M,T,A,c,l,a,o,s,i,u,p,f,L,D,N,k,V,z,v,g,b,C,F,U,P,n,d,K,X,ft]}class P_ extends me{constructor(t){super(),pe(this,t,I_,C_,Kt,{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 eu(r,t,e=0,i=r.length-1,n=R_){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));eu(r,t,p,f,n)}const s=r[t];let o=e,a=i;for(xn(r,e,t),n(r[i],s)>0&&xn(r,e,i);o<a;){for(xn(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?xn(r,e,a):(a++,xn(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function xn(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function R_(r,t){return r<t?-1:r>t?1:0}class M_{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(!vs(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;vs(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(!vs(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(vs(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=Di([]),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=D_(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=Di(t.slice(e,i+1)),Mi(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=Di([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));ru(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);ru(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 Mi(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=L_(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),En(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=Di(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Mi(i,this.toBBox),Mi(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Di([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Mi(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=wn(t,0,a,this.toBBox),h=wn(t,a,i,this.toBBox),c=N_(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:B_,s=t.leaf?this.compareMinY:O_,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=wn(t,0,e,s),a=wn(t,i-e,i,s);let l=_s(o)+_s(a);for(let h=e;h<i-e;h++){const c=t.children[h];En(o,t.leaf?s(c):c),l+=_s(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];En(a,t.leaf?s(c):c),l+=_s(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)En(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():Mi(t[e],this.toBBox)}}function D_(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 Mi(r,t){wn(r,0,r.children.length,t,r)}function wn(r,t,e,i,n){n||(n=Di(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];En(n,r.leaf?i(o):o)}return n}function En(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 B_(r,t){return r.minX-t.minX}function O_(r,t){return r.minY-t.minY}function ga(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function _s(r){return r.maxX-r.minX+(r.maxY-r.minY)}function L_(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 N_(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 vs(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Di(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ru(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;eu(r,o,t,e,n),s.push(t,o,o,e)}}const F_=()=>{const r=new M_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!us(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(!us(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===_t.RECTANGLE||Vg(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(us(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)}}},iu=r=>{const t=Ny(),e=F_(),i=xy(t,r.userSelectAction,r.adapter),n=by(t),s=$y();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}},k_=r=>{const t=iu(r);return{...t,store:Fy(t.store)}},U_=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},nu=r=>{const t=U_(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},su=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?nu(r):e),ou=(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}),au=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,lu=(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=()=>{au?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return au?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},G_=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=ou(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:dc.EDIT,theme:"light"}),n=k_(i),{selection:s,store:o}=n,a=Gy(o,i.initialHistory),l=Hy(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=lu(a);let u=Jy();su(e,h,i.theme);const d=new P_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",P=>{const{originalEvent:T,annotation:E}=P.detail;E?s.userSelect(E.id,T):s.isEmpty()||s.clear()});const p=Vy(n,a,i.adapter),f=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},y=()=>d.getDrawingTool(),_=()=>u,v=()=>d.isDrawingEnabled(),g=(P,T,E)=>Hc(P,T,E),b=(P,T)=>kc(P,T),S=P=>{if(!ys(P))throw`No drawing tool named ${P}`;d.$set({toolName:P})},R=P=>d.$set({drawingEnabled:P}),C=P=>{console.warn("Filter not implemented yet")},I=P=>d.$set({style:P}),M=P=>su(e,h,P),F=P=>{u=P,d.$set({user:P})},U=P=>d.$set({visible:P});return{...p,cancelDrawing:f,destroy:m,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:gs,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:b,setDrawingEnabled:R,setDrawingTool:S,setFilter:C,setStyle:I,setTheme:M,setUser:F,setVisible:U,element:h,state:n}};function Ft(){}function _a(r,t){for(const e in t)r[e]=t[e];return r}function hu(r){return r()}function cu(){return Object.create(null)}function Fe(r){r.forEach(hu)}function Zt(r){return typeof r=="function"}function Ut(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function $_(r){return Object.keys(r).length===0}function H_(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 Tn(r,t,e){r.$$.on_destroy.push(H_(t,e))}function uu(r,t,e,i){if(r){const n=du(r,t,e,i);return r[0](n)}}function du(r,t,e,i){return r[1]&&i?_a(e.ctx.slice(),r[1](i(t))):e.ctx}function fu(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 pu(r,t,e,i,n,s){if(n){const o=du(t,e,i,s);r.p(o,n)}}function mu(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 gu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function yu(r){return r??""}const va=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Ct(r,t){r.appendChild(t)}function ot(r,t,e){r.insertBefore(t,e||null)}function st(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 it(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 Pt(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 X_(r){return Array.from(r.childNodes)}function V_(r,t){t=""+t,r.data!==t&&(r.data=t)}function Br(r,t,e){r.classList.toggle(t,!!e)}function z_(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let An;function Sn(r){An=r}function xa(){if(!An)throw new Error("Function called outside component initialization");return An}function ei(r){xa().$$.on_mount.push(r)}function j_(r){xa().$$.on_destroy.push(r)}function Bi(){const r=xa();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=z_(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function ae(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Oi=[],bs=[];let Li=[];const _u=[],vu=Promise.resolve();let wa=!1;function bu(){wa||(wa=!0,vu.then(wu))}function xu(){return bu(),vu}function Ea(r){Li.push(r)}const Ta=new Set;let Ni=0;function wu(){if(Ni!==0)return;const r=An;do{try{for(;Ni<Oi.length;){const t=Oi[Ni];Ni++,Sn(t),W_(t.$$)}}catch(t){throw Oi.length=0,Ni=0,t}for(Sn(null),Oi.length=0,Ni=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(;_u.length;)_u.pop()();wa=!1,Ta.clear(),Sn(r)}function W_(r){if(r.fragment!==null){r.update(),Fe(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Ea)}}function Y_(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 le(){ri={r:0,c:[],p:ri}}function he(){ri.r||Fe(ri.c),ri=ri.p}function q(r,t){r&&r.i&&(xs.delete(r),r.i(t))}function at(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 Lt(r){r&&r.c()}function Bt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Ea(()=>{const s=r.$$.on_mount.map(hu).filter(Zt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Fe(s),r.$$.on_mount=[]}),n.forEach(Ea)}function Ot(r,t){const e=r.$$;e.fragment!==null&&(Y_(e.after_update),Fe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function q_(r,t){r.$$.dirty[0]===-1&&(Oi.push(r),bu(),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=An;Sn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Ft,not_equal:n,bound:cu(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:cu(),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&&q_(r,u)),d}):[],h.update(),c=!0,Fe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=X_(t.target);h.fragment&&h.fragment.l(u),u.forEach(st)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Bt(r,t.target,t.anchor),wu()}Sn(l)}class jt{constructor(){Nh(this,"$$");Nh(this,"$$set")}$destroy(){Ot(this,1),this.$destroy=Ft}$on(t,e){if(!Zt(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&&!$_(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const K_="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(K_);var Qe=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(Qe||{}),Cn=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 Z_(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 Eu={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})()})(Eu);var J_=Eu.exports;const Q_=Aa(J_),Fi=(r,t)=>t,tr=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},tv=(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},Tu=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return Q_(e,t,!0).map(i=>[i.x,i.y])},ev=(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))},rv={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}};Fi(Qe.ELLIPSE,rv);const iv={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=ev([n,s],[o,a]);return l/h<=i}};Fi(Qe.LINE,iv);const nv={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 tr(t)},ki=r=>r.rings.map(e=>tv(e.points)).join(" "),sv=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),ov=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=Tu(a.points,t);return{...a,points:l}}),o=tr(s[0].points);return{...n,rings:s,bounds:o}}),i=Ts(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Fi(Qe.MULTIPOLYGON,nv);const av={area:r=>{const t=r.geometry.points;return ws(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Es(i,t,e)}},lv=(r,t=1)=>{const e=Tu(r.geometry.points,t),i=tr(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Fi(Qe.POLYGON,av);const hv={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Au(t.points,t.closed);return ws(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Au(n.points,n.closed);return Es(s,t,e)}else return cv(n,[t,e],i)}},Au=(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=Su(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);e.push(...a.slice(1))}}return e},Su=(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},cv=(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.type==="CURVE"||s.type==="CURVE"){const a=Su(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let l=0;l<a.length-1;l++)if(Cu(t,a[l],a[l+1])<=e)return!0}else if(Cu(t,n.point,s.point)<=e)return!0}return!1},Cu=(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};Fi(Qe.POLYLINE,hv);const uv={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};Fi(Qe.RECTANGLE,uv);const _e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function dv(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 fv=new Uint8Array(16);function pv(){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(fv)}const Iu={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function mv(r,t,e){var n;r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??pv();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,dv(i)}function gv(r,t,e){return Iu.randomUUID&&!r?Iu.randomUUID():mv(r)}const yv=(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};`),n||n===0?l+=`fill-opacity:${n};`:i&&(l+="fill-opacity: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}},Or=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,_v=r=>({}),Pu=r=>({grab:r[0]});function vv(r){let t,e,i,n;const s=r[8].default,o=uu(s,r,r[7],Pu);return{c(){t=it("g"),o&&o.c(),w(t,"class","a9s-annotation selected")},m(a,l){ot(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Pt(t,"pointerup",r[2]),Pt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&pu(o,s,a,a[7],e?fu(s,a[7],l,_v):mu(a[7]),Pu)},i(a){e||(q(o,a),e=!0)},o(a){at(o,a),e=!1},d(a){a&&st(t),o&&o.d(a),i=!1,Fe(n)}}}function bv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Bi();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const p=y=>_=>{if(c=y,h){const{left:g,top:b}=h.getBoundingClientRect(),S=_.clientX-g,R=_.clientY-b;u=l.elementToImage(S,R)}else{const{offsetX:g,offsetY:b}=_;u=l.elementToImage(g,b)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},f=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),g=[_-u[0],v-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,d=o,s("release",y)};return r.$$set=y=>{"shape"in y&&e(3,o=y.shape),"editor"in y&&e(4,a=y.editor),"transform"in y&&e(5,l=y.transform),"svgEl"in y&&e(6,h=y.svgEl),"$$scope"in y&&e(7,n=y.$$scope)},[p,f,m,o,a,l,h,n,i]}class Ia extends jt{constructor(t){super(),zt(this,t,bv,vv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function xv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Ru(r);return{c(){t=it("g"),e=it("circle"),h&&h.c(),n=it("circle"),w(e,"class","a9s-handle-buffer svelte-qtyc7s"),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=yu(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),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){ot(c,t,u),Ct(t,e),h&&h.m(t,null),Ct(t,n),a||(l=[Pt(e,"dblclick",r[12]),Pt(e,"pointerenter",r[13]),Pt(e,"pointerleave",r[14]),Pt(e,"pointerdown",r[15]),Pt(e,"pointerdown",r[6]),Pt(e,"pointerup",r[16]),Pt(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=Ru(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=yu(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&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&&st(t),h&&h.d(),a=!1,Fe(l)}}}function wv(r){let t,e,i,n,s,o,a,l,h;return{c(){t=it("g"),e=it("circle"),n=it("circle"),o=it("circle"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]*10),w(e,"class","a9s-touch-halo"),Br(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 svelte-qtyc7s"),w(n,"role","button"),w(n,"tabindex","0"),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){ot(c,t,u),Ct(t,e),Ct(t,n),Ct(t,o),l||(h=[Pt(n,"dblclick",r[9]),Pt(n,"pointerdown",r[10]),Pt(n,"pointerdown",r[6]),Pt(n,"pointerup",r[11]),Pt(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&&Br(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&&st(t),l=!1,Fe(h)}}}function Ru(r){let t,e;return{c(){t=it("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){ot(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&&st(t)}}}function Ev(r){let t;function e(s,o){return Or?wv:xv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&st(t),n.d(s)}}}function Tv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=g=>{g.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(g){ae.call(this,r,g)}function d(g){ae.call(this,r,g)}function p(g){ae.call(this,r,g)}function f(g){ae.call(this,r,g)}function m(g){ae.call(this,r,g)}function y(g){ae.call(this,r,g)}function _(g){ae.call(this,r,g)}function v(g){ae.call(this,r,g)}return r.$$set=g=>{e(8,t=_a(_a({},t),gu(g))),"x"in g&&e(0,n=g.x),"y"in g&&e(1,s=g.y),"scale"in g&&e(2,o=g.scale),"selected"in g&&e(3,a=g.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=gu(t),[n,s,o,a,l,i,h,c,t,u,d,p,f,m,y,_,v]}class Ui extends jt{constructor(t){super(),zt(this,t,Tv,Ev,Ut,{x:0,y:1,scale:2,selected:3})}}function Av(r){let t,e,i,n,s,o,a;return{c(){t=it("g"),e=it("circle"),n=it("circle"),s=it("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){ot(l,t,h),Ct(t,e),Ct(t,n),Ct(t,s),o||(a=[Pt(e,"pointerdown",r[5]),Pt(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&&st(t),o=!1,Fe(a)}}}function Sv(r){let t;return{c(){t=it("circle"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",r[2])},m(e,i){ot(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&&st(t)}}}function Cv(r){let t;function e(s,o){return Or?Sv:Av}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&st(t),n.d(s)}}}function Iv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){ae.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 Mu extends jt{constructor(t){super(),zt(this,t,Iv,Cv,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 Du(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 Bu(r){let t,e,i,n;return{c(){t=it("circle"),w(t,"cx",e=r[28][0]),w(t,"cy",i=r[28][1]),w(t,"r",n=In/r[3]),w(t,"class","svelte-1h2slbm")},m(s,o){ot(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=In/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function Ou(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=it("mask"),e=it("rect"),a=it("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=In/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){ot(u,t,d),Ct(t,e),Ct(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=In/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function Lu(r){let t,e;return t=new Ui({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(){Zt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Nu(r){let t,e;return t=new Mu({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Zt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Pv(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&Bu(Ma(r)),C=r[6]!==void 0&&!r[7]&&Ou(Ra(r)),I=xe(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Lu(Du(r,I,P));const F=P=>at(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Nu(Pa(r));return{c(){t=it("defs"),e=it("mask"),i=it("rect"),l=it("polygon"),R&&R.c(),C&&C.c(),c=Se(),u=it("polygon"),p=Se(),f=it("polygon"),y=Se();for(let P=0;P<M.length;P+=1)M[P].c();_=Se(),U&&U.c(),v=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(Fu).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(ku).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(Uu).join(" "))},m(P,T){ot(P,t,T),Ct(t,e),Ct(e,i),Ct(e,l),R&&R.m(e,null),C&&C.m(t,null),ot(P,c,T),ot(P,u,T),ot(P,p,T),ot(P,f,T),ot(P,y,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(P,T);ot(P,_,T),U&&U.m(P,T),ot(P,v,T),g=!0,b||(S=[Pt(u,"pointerup",r[14]),Pt(u,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(f,"pointermove",r[13]),Pt(f,"pointerup",r[14]),Pt(f,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,T){if(r=P,(!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(Fu).join(" ")))&&w(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Ma(r),T):(R=Bu(Ma(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(Ra(r),T):(C=Ou(Ra(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||T[0]&32&&d!==(d=r[5].points.map(ku).join(" ")))&&w(u,"points",d),(!g||T[0]&2)&&w(f,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Uu).join(" ")))&&w(f,"points",m),T[0]&134322472){I=xe(r[5].points);let E;for(E=0;E<I.length;E+=1){const A=Du(r,I,E);M[E]?(M[E].p(A,T),q(M[E],1)):(M[E]=Lu(A),M[E].c(),q(M[E],1),M[E].m(_.parentNode,_))}for(le(),E=I.length;E<M.length;E+=1)F(E);he()}r[6]!==void 0&&!r[7]?U?(U.p(Pa(r),T),T[0]&192&&q(U,1)):(U=Nu(Pa(r)),U.c(),q(U,1),U.m(v.parentNode,v)):U&&(le(),at(U,1,1,()=>{U=null}),he())},i(P){if(!g){for(let T=0;T<I.length;T+=1)q(M[T]);q(U),g=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)at(M[T]);at(U),g=!1},d(P){P&&(st(t),st(c),st(u),st(p),st(f),st(y),st(_),st(v)),R&&R.d(),C&&C.d(),Dr(M,P),U&&U.d(P),b=!1,Fe(S)}}}function Rv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[Pv,({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(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}const Mv=250,Dv=1e3,Bv=12,In=4.5,Fu=r=>r.join(","),ku=r=>r.join(","),Uu=r=>r.join(",");function Ov(r,t,e){let i,n,s;const o=Bi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const y=()=>e(7,p=!0),_=()=>e(7,p=!1),v=E=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(E.offsetX,E.offsetY),D=k=>Math.pow(k[0]-A,2)+Math.pow(k[1]-L,2),N=i.points.reduce((k,V)=>D(V)<D(k)?V:k),$=n.filter(k=>k.visible).reduce((k,V)=>D(V.point)<D(k.point)?V:k),O=Math.pow(Dv/c,2);D(N)<O||D($.point)<O?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=E=>{e(7,p=!0),E.preventDefault(),E.stopPropagation(),f=performance.now()},R=E=>A=>{if(!f||Or||performance.now()-f>Mv)return;const L=m.includes(E);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):L&&m.length>1?e(8,m=[E]):L?e(8,m=[]):e(8,m=[E]),g()},C=(E,A,L)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,B],k)=>m.includes(k)?[O+L[0],B+L[1]]:[O,B]):A==="SHAPE"?D=N.points.map(([O,B])=>[O+L[0],B+L[1]]):D=N.points.map(([O,B],k)=>A===`HANDLE-${k}`?[O+L[0],B+L[1]]:[O,B]);const $=tr(D);return{...E,geometry:{points:D,bounds:$}}},I=E=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=tr(L);o("change",{...a,geometry:{points:L,bounds:D}}),await xu();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.firstChild){const $=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:A.clientX,clientY:A.clientY,pointerId:A.pointerId,pointerType:A.pointerType,isPrimary:A.isPrimary,buttons:A.buttons});N.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((L,D)=>!m.includes(D)),A=tr(E);o("change",{...a,geometry:{points:E,bounds:A}}),e(8,m=[])};ei(()=>{if(Or)return;const E=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",E)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){ae.call(this,r,E)}function P(E){ae.call(this,r,E)}function T(E){ae.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=Or?[]:i.points.map((E,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],D=(E[0]+L[0])/2,N=(E[1]+L[1])/2,O=Math.sqrt(Math.pow(L[0]-D,2)+Math.pow(L[1]-N,2))>Bv/c;return{point:[D,N],visible:O}})),r.$$.dirty[0]&40&&e(9,s=Ca(i.bounds,In/c))},[a,l,h,c,u,i,d,p,m,s,n,y,_,v,b,S,R,C,I,F,U,P,T]}class Lv extends jt{constructor(t){super(),zt(this,t,Ov,Rv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Nv(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v,g,b,S,R,C,I,M,F,U,P,T,E,A,L,D,N,$,O,B,k,V,z,K,X,ft,H,mt,J,ut,gt,Et,Dt,Yt,Vt,et,$e,ts;return J=new Ui({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),J.$on("pointerdown",function(){Zt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Ui({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),gt.$on("pointerdown",function(){Zt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Ui({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(){Zt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new Ui({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Zt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=it("defs"),e=it("mask"),i=it("rect"),l=it("rect"),p=Se(),f=it("rect"),g=Se(),b=it("rect"),M=Se(),F=it("rect"),E=Se(),A=it("rect"),$=Se(),O=it("rect"),z=Se(),K=it("rect"),mt=Se(),Lt(J.$$.fragment),ut=Se(),Lt(gt.$$.fragment),Et=Se(),Lt(Dt.$$.fragment),Yt=Se(),Lt(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",y=r[5].y),w(f,"width",_=r[5].w),w(f,"height",v=r[5].h),w(b,"class","a9s-inner a9s-shape-handle"),w(b,"style",r[1]),w(b,"x",S=r[5].x),w(b,"y",R=r[5].y),w(b,"width",C=r[5].w),w(b,"height",I=r[5].h),w(F,"class","a9s-edge-handle a9s-edge-handle-top"),w(F,"x",U=r[5].x),w(F,"y",P=r[5].y),w(F,"height",1),w(F,"width",T=r[5].w),w(A,"class","a9s-edge-handle a9s-edge-handle-right"),w(A,"x",L=r[5].x+r[5].w),w(A,"y",D=r[5].y),w(A,"height",N=r[5].h),w(A,"width",1),w(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),w(O,"x",B=r[5].x),w(O,"y",k=r[5].y+r[5].h),w(O,"height",1),w(O,"width",V=r[5].w),w(K,"class","a9s-edge-handle a9s-edge-handle-left"),w(K,"x",X=r[5].x),w(K,"y",ft=r[5].y),w(K,"height",H=r[5].h),w(K,"width",1)},m(Y,G){ot(Y,t,G),Ct(t,e),Ct(e,i),Ct(e,l),ot(Y,p,G),ot(Y,f,G),ot(Y,g,G),ot(Y,b,G),ot(Y,M,G),ot(Y,F,G),ot(Y,E,G),ot(Y,A,G),ot(Y,$,G),ot(Y,O,G),ot(Y,z,G),ot(Y,K,G),ot(Y,mt,G),Bt(J,Y,G),ot(Y,ut,G),Bt(gt,Y,G),ot(Y,Et,G),Bt(Dt,Y,G),ot(Y,Yt,G),Bt(Vt,Y,G),et=!0,$e||(ts=[Pt(f,"pointerdown",function(){Zt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(b,"pointerdown",function(){Zt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(F,"pointerdown",function(){Zt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Pt(A,"pointerdown",function(){Zt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Pt(O,"pointerdown",function(){Zt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Pt(K,"pointerdown",function(){Zt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],$e=!0)},p(Y,G){r=Y,(!et||G&64&&n!==(n=r[6].x))&&w(i,"x",n),(!et||G&64&&s!==(s=r[6].y))&&w(i,"y",s),(!et||G&64&&o!==(o=r[6].w))&&w(i,"width",o),(!et||G&64&&a!==(a=r[6].h))&&w(i,"height",a),(!et||G&32&&h!==(h=r[5].x))&&w(l,"x",h),(!et||G&32&&c!==(c=r[5].y))&&w(l,"y",c),(!et||G&32&&u!==(u=r[5].w))&&w(l,"width",u),(!et||G&32&&d!==(d=r[5].h))&&w(l,"height",d),(!et||G&32&&m!==(m=r[5].x))&&w(f,"x",m),(!et||G&32&&y!==(y=r[5].y))&&w(f,"y",y),(!et||G&32&&_!==(_=r[5].w))&&w(f,"width",_),(!et||G&32&&v!==(v=r[5].h))&&w(f,"height",v),(!et||G&2)&&w(b,"style",r[1]),(!et||G&32&&S!==(S=r[5].x))&&w(b,"x",S),(!et||G&32&&R!==(R=r[5].y))&&w(b,"y",R),(!et||G&32&&C!==(C=r[5].w))&&w(b,"width",C),(!et||G&32&&I!==(I=r[5].h))&&w(b,"height",I),(!et||G&32&&U!==(U=r[5].x))&&w(F,"x",U),(!et||G&32&&P!==(P=r[5].y))&&w(F,"y",P),(!et||G&32&&T!==(T=r[5].w))&&w(F,"width",T),(!et||G&32&&L!==(L=r[5].x+r[5].w))&&w(A,"x",L),(!et||G&32&&D!==(D=r[5].y))&&w(A,"y",D),(!et||G&32&&N!==(N=r[5].h))&&w(A,"height",N),(!et||G&32&&B!==(B=r[5].x))&&w(O,"x",B),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&w(O,"y",k),(!et||G&32&&V!==(V=r[5].w))&&w(O,"width",V),(!et||G&32&&X!==(X=r[5].x))&&w(K,"x",X),(!et||G&32&&ft!==(ft=r[5].y))&&w(K,"y",ft),(!et||G&32&&H!==(H=r[5].h))&&w(K,"height",H);const Ar={};G&32&&(Ar.x=r[5].x),G&32&&(Ar.y=r[5].y),G&8&&(Ar.scale=r[3]),J.$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]),gt.$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){et||(q(J.$$.fragment,Y),q(gt.$$.fragment,Y),q(Dt.$$.fragment,Y),q(Vt.$$.fragment,Y),et=!0)},o(Y){at(J.$$.fragment,Y),at(gt.$$.fragment,Y),at(Dt.$$.fragment,Y),at(Vt.$$.fragment,Y),et=!1},d(Y){Y&&(st(t),st(p),st(f),st(g),st(b),st(M),st(F),st(E),st(A),st($),st(O),st(z),st(K),st(mt),st(ut),st(Et),st(Yt)),Ot(J,Y),Ot(gt,Y),Ot(Dt,Y),Ot(Vt,Y),$e=!1,Fe(ts)}}}function Fv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[Nv,({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(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function kv(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,y,_)=>{const v=m.geometry.bounds;let[g,b]=[v.minX,v.minY],[S,R]=[v.maxX,v.maxY];const[C,I]=_;if(y==="SHAPE")g+=C,S+=C,b+=I,R+=I;else{switch(y){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=I;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=I;break}}switch(y){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const M=Math.min(g,S),F=Math.min(b,R),U=Math.abs(S-g),P=Math.abs(R-b);return{...m,geometry:{x:M,y:F,w:U,h:P,bounds:{minX:M,minY:F,maxX:M+U,maxY:F+P}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){ae.call(this,r,m)}function p(m){ae.call(this,r,m)}function f(m){ae.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 Uv extends jt{constructor(t){super(),zt(this,t,kv,Fv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Gu=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(Gu.call(r,e)&&++i&&!Gu.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 Gv=12,$v=(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,y=Math.sqrt(Math.pow(d[0]-p,2)+Math.pow(d[1]-f,2))>Gv/t;return{point:[p,f],visible:y,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function Ba(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function $u(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Hu(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Xu(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function Oa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function La(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Vu(r){let t,e,i,n;return{c(){t=it("circle"),w(t,"cx",e=r[29][0]),w(t,"cy",i=r[29][1]),w(t,"r",n=Pn/r[3]),w(t,"class","svelte-1vxo6dc")},m(s,o){ot(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=Pn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function zu(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=it("mask"),e=it("rect"),a=it("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=Pn/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){ot(u,t,d),Ct(t,e),Ct(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=Pn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function ju(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Ui({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(){Zt(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(){Lt(t.$$.fragment)},m(n,s){Bt(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){at(t.$$.fragment,n),e=!1},d(n){Ot(t,n)}}}function Wu(r){let t,e,i=xe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=ju(Xu(r,i,o));const s=o=>at(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);ot(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=Xu(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=ju(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(le(),l=i.length;l<n.length;l+=1)s(l);he()}},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)at(n[a]);e=!1},d(o){o&&st(t),Dr(n,o)}}}function Yu(r){let t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v=r[6]!==void 0&&!r[7]&&Vu(La(r)),g=r[6]!==void 0&&!r[7]&&zu(Oa(r)),b=xe(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Wu(Hu(r,b,C));const R=C=>at(S[C],1,1,()=>{S[C]=null});return{c(){t=it("g"),e=it("defs"),i=it("mask"),n=it("rect"),h=it("path"),v&&v.c(),g&&g.c(),u=it("path"),p=it("path");for(let C=0;C<S.length;C+=1)S[C].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=ki(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=ki(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=ki(r[30]))},m(C,I){ot(C,t,I),Ct(t,e),Ct(e,i),Ct(i,n),Ct(i,h),v&&v.m(i,null),g&&g.m(e,null),Ct(t,u),Ct(t,p);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);m=!0,y||(_=[Pt(u,"pointerup",r[13]),Pt(u,"pointerdown",function(){Zt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Pt(p,"pointerup",r[13]),Pt(p,"pointerdown",function(){Zt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!m||I[0]&512&&s!==(s=r[9].x))&&w(n,"x",s),(!m||I[0]&512&&o!==(o=r[9].y))&&w(n,"y",o),(!m||I[0]&512&&a!==(a=r[9].w))&&w(n,"width",a),(!m||I[0]&512&&l!==(l=r[9].h))&&w(n,"height",l),(!m||I[0]&32&&c!==(c=ki(r[30])))&&w(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(La(r),I):(v=Vu(La(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(Oa(r),I):(g=zu(Oa(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=ki(r[30])))&&w(u,"d",d),(!m||I[0]&2)&&w(p,"style",r[1]),(!m||I[0]&32&&f!==(f=ki(r[30])))&&w(p,"d",f),I[0]&268491048){b=xe(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Hu(r,b,M);S[M]?(S[M].p(F,I),q(S[M],1)):(S[M]=Wu(F),S[M].c(),q(S[M],1),S[M].m(t,null))}for(le(),M=b.length;M<S.length;M+=1)R(M);he()}},i(C){if(!m){for(let I=0;I<b.length;I+=1)q(S[I]);m=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)at(S[I]);m=!1},d(C){C&&st(t),v&&v.d(),g&&g.d(),Dr(S,C),y=!1,Fe(_)}}}function qu(r){let t,e;return t=new Mu({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Zt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Hv(r){let t,e,i,n=xe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Yu($u(r,n,l));const o=l=>at(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&qu(Ba(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);ot(l,t,h),a&&a.m(l,h),ot(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=$u(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=Yu(u),s[c].c(),q(s[c],1),s[c].m(t.parentNode,t))}for(le(),c=n.length;c<s.length;c+=1)o(c);he()}l[6]!==void 0&&!l[7]?a?(a.p(Ba(l),h),h[0]&192&&q(a,1)):(a=qu(Ba(l)),a.c(),q(a,1),a.m(e.parentNode,e)):a&&(le(),at(a,1,1,()=>{a=null}),he())},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)at(s[h]);at(a),i=!1},d(l){l&&(st(t),st(e)),Dr(s,l),a&&a.d(l)}}}function Xv(r){let t,e;return t=new Ia({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[Hv,({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(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}const Vv=250,zv=1e3,Pn=4.5;function jv(r,t,e){let i,n,s;const o=Bi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,p=!1,f,m=[];const y=()=>e(7,p=!0),_=()=>e(7,p=!1),v=A=>{if(m.length>0||!n.some(V=>V.visible)){e(6,d=void 0);return}const[L,D]=h.elementToImage(A.offsetX,A.offsetY),N=V=>Math.pow(V[0]-L,2)+Math.pow(V[1]-D,2),$=sv(i).reduce((V,z)=>N(z)<N(V)?z:V),O=n.filter(V=>V.visible).reduce((V,z)=>N(z.point)<N(V.point)?z:V),B=Math.pow(zv/c,2);N($)<B||N(O.point)<B?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,p=!0),A.preventDefault(),A.stopPropagation(),f=performance.now()},R=(A,L,D)=>N=>{if(!f||Or||performance.now()-f>Vv)return;const $=B=>B.polygon===A&&B.ring===L&&B.point===D,O=m.some($);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(B=>!$(B))):e(8,m=[...m,{polygon:A,ring:L,point:D}]):O&&m.length>1?e(8,m=[{polygon:A,ring:L,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:A,ring:L,point:D}]),g()},C=(A,L,D)=>{g();const N=A.geometry.polygons;let $;if(L==="SHAPE")$=N.map(O=>{const B=O.rings.map((V,z)=>({points:V.points.map((X,ft)=>[X[0]+D[0],X[1]+D[1]])})),k=tr(B[0].points);return{rings:B,bounds:k}});else{const[O,B,k,V]=L.split("-").map(z=>parseInt(z));$=N.map((z,K)=>{if(K===B){const X=z.rings.map((H,mt)=>mt===k?{points:H.points.map((ut,gt)=>gt===V?[ut[0]+D[0],ut[1]+D[1]]:ut)}:H),ft=tr(X[0].points);return{rings:X,bounds:ft}}else return z})}return{...A,geometry:{polygons:$,bounds:Ts($)}}},I=A=>async L=>{L.stopPropagation();const D=n[A],N=i.polygons.map((O,B)=>{if(B===D.elementIdx){const k=O.rings.map((z,K)=>K===D.ringIdx?{points:[...z.points.slice(0,D.pointIdx+1),D.point,...z.points.slice(D.pointIdx+1)]}:z),V=tr(k[0].points);return{rings:k,bounds:V}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Ts(N)}}),await xu();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const O=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});$.firstChild.dispatchEvent(O)}},M=()=>{const A=i.polygons.map((D,N)=>{if(m.some(O=>O.polygon===N)){const O=D.rings.map((k,V)=>{const z=m.filter(K=>K.polygon===N&&K.ring===V);return z.length&&k.points.length-z.length>=3?{points:k.points.filter((X,ft)=>!z.some(H=>H.point===ft))}:k}),B=tr(O[0].points);return{rings:O,bounds:B}}else return D});!Da(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:Ts(A)}}),e(8,m=[]))};ei(()=>{if(Or)return;const A=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",A),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",A)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(A,L,D,{polygon:N,ring:$,point:O})=>N===A&&$===L&&O===D;function P(A){ae.call(this,r,A)}function T(A){ae.call(this,r,A)}function E(A){ae.call(this,r,A)}return r.$$set=A=>{"shape"in A&&e(0,a=A.shape),"computedStyle"in A&&e(1,l=A.computedStyle),"transform"in A&&e(2,h=A.transform),"viewportScale"in A&&e(3,c=A.viewportScale),"svgEl"in A&&e(4,u=A.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Or?[]:$v(i,c)),r.$$.dirty[0]&40&&e(9,s=Ca(i.bounds,Pn/c))},[a,l,h,c,u,i,d,p,m,s,n,y,_,b,S,R,C,I,F,U,P,T,E]}class Wv extends jt{constructor(t){super(),zt(this,t,jv,Xv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}Qe.RECTANGLE,Qe.POLYGON,Qe.MULTIPOLYGON;function Yv(r,t,e){let i;const n=Bi();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=yv(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 qv extends jt{constructor(t){super(),zt(this,t,Yv,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||{}),Ku=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(Ku||{}),Na=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Na||{}),vt=(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))(vt||{}),er=(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))(er||{}),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||{}),Gi=(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))(Gi||{}),pt=(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))(pt||{}),Q=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(Q||{}),mr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(mr||{}),Lr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Lr||{}),rr=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(rr||{}),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||{}),ir=(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))(ir||{}),Fa=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(Fa||{}),ke=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(ke||{}),ie=(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))(ie||{}),ee=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(ee||{}),nr=(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))(nr||{});const tt={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,Zu=/iPod/i,Ju=/iPad/i,Qu=/\biOS-universal(?:.+)Mac\b/i,Ua=/\bAndroid(?:.+)Mobile\b/i,td=/Android/i,$i=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,As=/Silk/i,gr=/Windows Phone/i,ed=/\bWindows(?:.+)ARM\b/i,rd=/BlackBerry/i,id=/BB10/i,nd=/Opera Mini/i,sd=/\b(CriOS|Chrome)(?:.+)Mobile/i,od=/Mobile(?:.+)Firefox\b/i,ad=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function Kv(r){return function(t){return t.test(r)}}function ld(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=Kv(e),s={apple:{phone:n(ka)&&!n(gr),ipod:n(Zu),tablet:!n(ka)&&(n(Ju)||ad(t))&&!n(gr),universal:n(Qu),device:(n(ka)||n(Zu)||n(Ju)||n(Qu)||ad(t))&&!n(gr)},amazon:{phone:n($i),tablet:!n($i)&&n(As),device:n($i)||n(As)},android:{phone:!n(gr)&&n($i)||!n(gr)&&n(Ua),tablet:!n(gr)&&!n($i)&&!n(Ua)&&(n(As)||n(td)),device:!n(gr)&&(n($i)||n(As)||n(Ua)||n(td))||n(/\bokhttp\b/i)},windows:{phone:n(gr),tablet:n(ed),device:n(gr)||n(ed)},other:{blackberry:n(rd),blackberry10:n(id),opera:n(nd),firefox:n(od),chrome:n(sd),device:n(rd)||n(id)||n(nd)||n(od)||n(sd)},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 Zv=ld.default??ld,yr=Zv(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var hd={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 y=this._events[m],_=arguments.length,v,g;if(y.fn){switch(y.once&&this.removeListener(h,y.fn,void 0,!0),_){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,c),!0;case 3:return y.fn.call(y.context,c,u),!0;case 4:return y.fn.call(y.context,c,u,d),!0;case 5:return y.fn.call(y.context,c,u,d,p),!0;case 6:return y.fn.call(y.context,c,u,d,p,f),!0}for(g=1,v=new Array(_-1);g<_;g++)v[g-1]=arguments[g];y.fn.apply(y.context,v)}else{var b=y.length,S;for(g=0;g<b;g++)switch(y[g].once&&this.removeListener(h,y[g].fn,void 0,!0),_){case 1:y[g].fn.call(y[g].context);break;case 2:y[g].fn.call(y[g].context,c);break;case 3:y[g].fn.call(y[g].context,c,u);break;case 4:y[g].fn.call(y[g].context,c,u,d);break;default:if(!v)for(S=1,v=new Array(_-1);S<_;S++)v[S-1]=arguments[S];y[g].fn.apply(y[g].context,v)}}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,y=[],_=f.length;m<_;m++)(f[m].fn!==c||d&&!f[m].once||u&&f[m].context!==u)&&y.push(f[m]);y.length?this._events[p]=y.length===1?y[0]:y: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})(hd);var Jv=hd.exports;const Rn=Aa(Jv);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=cd(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=i1(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 Mn(s,o,e,a,l,p,0),o}function cd(r,t,e,i,n){var s,o;if(n===Xa(r,t,e,i)>0)for(s=t;s<e;s+=i)o=fd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=fd(s,r[s],r[s+1],o);return o&&Cs(o,o.next)&&(Bn(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(Bn(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Mn(r,t,e,i,n,s,o){if(r){!o&&s&&l1(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?t1(r,i,n,s):Qv(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Bn(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=e1(ni(r),t,e),Mn(r,t,e,i,n,s,2)):o===2&&r1(r,t,e,i,n,s):Mn(ni(r),t,e,i,n,s,1);break}}}}function Qv(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&&Hi(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 t1(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,y=c>u?c>d?c:d:u>d?u:d,_=$a(p,f,t,e,i),v=$a(m,y,t,e,i),g=r.prevZ,b=r.nextZ;g&&g.z>=_&&b&&b.z<=v;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=y&&g!==n&&g!==o&&Hi(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<=y&&b!==n&&b!==o&&Hi(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>=_;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=y&&g!==n&&g!==o&&Hi(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<=v;){if(b.x>=p&&b.x<=m&&b.y>=f&&b.y<=y&&b!==n&&b!==o&&Hi(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 e1(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!Cs(n,s)&&ud(n,i,i.next,s)&&Dn(n,s)&&Dn(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),Bn(i),Bn(i.next),i=r=s),i=i.next}while(i!==r);return ni(i)}function r1(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&u1(o,a)){var l=dd(o,a);o=ni(o,o.next),l=ni(l,l.next),Mn(o,t,e,i,n,s,0),Mn(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function i1(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=cd(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(c1(h));for(n.sort(n1),s=0;s<n.length;s++)e=s1(n[s],e);return e}function n1(r,t){return r.x-t.x}function s1(r,t){var e=o1(r,t);if(!e)return t;var i=dd(e,r);return ni(i,i.next),ni(e,e.next)}function o1(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&&Hi(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),Dn(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&a1(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function a1(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function l1(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,h1(n)}function h1(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 c1(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 Hi(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 u1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!d1(r,t)&&(Dn(r,t)&&Dn(t,r)&&f1(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 ud(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 d1(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&&ud(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Dn(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 f1(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 dd(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 fd(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 Bn(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 p1=Ga.exports;const m1=Aa(p1);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 Cn=="object"&&Cn;(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="-",y=/^xn--/,_=/[^\x20-\x7E]/,v=/[\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,S=Math.floor,R=String.fromCharCode,C;function I(O){throw new RangeError(g[O])}function M(O,B){for(var k=O.length,V=[];k--;)V[k]=B(O[k]);return V}function F(O,B){var k=O.split("@"),V="";k.length>1&&(V=k[0]+"@",O=k[1]),O=O.replace(v,".");var z=O.split("."),K=M(z,B).join(".");return V+K}function U(O){for(var B=[],k=0,V=O.length,z,K;k<V;)z=O.charCodeAt(k++),z>=55296&&z<=56319&&k<V?(K=O.charCodeAt(k++),(K&64512)==56320?B.push(((z&1023)<<10)+(K&1023)+65536):(B.push(z),k--)):B.push(z);return B}function P(O){return M(O,function(B){var k="";return B>65535&&(B-=65536,k+=R(B>>>10&1023|55296),B=56320|B&1023),k+=R(B),k}).join("")}function T(O){return O-48<10?O-22:O-65<26?O-65:O-97<26?O-97:l}function E(O,B){return O+22+75*(O<26)-((B!=0)<<5)}function A(O,B,k){var V=0;for(O=k?S(O/d):O>>1,O+=S(O/B);O>b*c>>1;V+=l)O=S(O/b);return S(V+(b+1)*O/(O+u))}function L(O){var B=[],k=O.length,V,z=0,K=f,X=p,ft,H,mt,J,ut,gt,Et,Dt,Yt;for(ft=O.lastIndexOf(m),ft<0&&(ft=0),H=0;H<ft;++H)O.charCodeAt(H)>=128&&I("not-basic"),B.push(O.charCodeAt(H));for(mt=ft>0?ft+1:0;mt<k;){for(J=z,ut=1,gt=l;mt>=k&&I("invalid-input"),Et=T(O.charCodeAt(mt++)),(Et>=l||Et>S((a-z)/ut))&&I("overflow"),z+=Et*ut,Dt=gt<=X?h:gt>=X+c?c:gt-X,!(Et<Dt);gt+=l)Yt=l-Dt,ut>S(a/Yt)&&I("overflow"),ut*=Yt;V=B.length+1,X=A(z-J,V,J==0),S(z/V)>a-K&&I("overflow"),K+=S(z/V),z%=V,B.splice(z++,0,K)}return P(B)}function D(O){var B,k,V,z,K,X,ft,H,mt,J,ut,gt=[],Et,Dt,Yt,Vt;for(O=U(O),Et=O.length,B=f,k=0,K=p,X=0;X<Et;++X)ut=O[X],ut<128&&gt.push(R(ut));for(V=z=gt.length,z&&gt.push(m);V<Et;){for(ft=a,X=0;X<Et;++X)ut=O[X],ut>=B&&ut<ft&&(ft=ut);for(Dt=V+1,ft-B>S((a-k)/Dt)&&I("overflow"),k+=(ft-B)*Dt,B=ft,X=0;X<Et;++X)if(ut=O[X],ut<B&&++k>a&&I("overflow"),ut==B){for(H=k,mt=l;J=mt<=K?h:mt>=K+c?c:mt-K,!(H<J);mt+=l)Vt=H-J,Yt=l-J,gt.push(R(E(J+Vt%Yt,0))),H=S(Vt/Yt);gt.push(R(E(H,0))),K=A(k,Dt,V==z),k=0,++V}++k,++B}return gt.join("")}function N(O){return F(O,function(B){return y.test(B)?L(B.slice(4).toLowerCase()):B})}function $(O){return F(O,function(B){return _.test(B)?"xn--"+D(B):B})}if(o={version:"1.4.1",ucs2:{decode:U,encode:P},decode:L,encode:D,toASCII:$,toUnicode:N},i&&n)if(r.exports==i)n.exports=o;else for(C in o)o.hasOwnProperty(C)&&(i[C]=o[C]);else e.punycode=o})(Cn)}(Rs,Rs.exports);var g1=Rs.exports,Xi=TypeError;const y1=Z_(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,pd=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,md=ja&&Set.prototype.forEach,_1=typeof WeakMap=="function"&&WeakMap.prototype,On=_1?WeakMap.prototype.has:null,v1=typeof WeakSet=="function"&&WeakSet.prototype,Ln=v1?WeakSet.prototype.has:null,b1=typeof WeakRef=="function"&&WeakRef.prototype,gd=b1?WeakRef.prototype.deref:null,x1=Boolean.prototype.valueOf,w1=Object.prototype.toString,E1=Function.prototype.toString,T1=String.prototype.match,Ya=String.prototype.slice,Nr=String.prototype.replace,A1=String.prototype.toUpperCase,yd=String.prototype.toLowerCase,_d=RegExp.prototype.test,vd=Array.prototype.concat,sr=Array.prototype.join,S1=Array.prototype.slice,bd=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,Vi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Nn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Vi||!0)?Symbol.toStringTag:null,xd=Object.prototype.propertyIsEnumerable,wd=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Ed(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||_d.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-bd(-r):bd(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=y1,Td=Ja.custom,Ad=Pd(Td)?Td:null,Sd={__proto__:null,double:'"',single:"'"},C1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Bs=function r(t,e,i,n){var s=e||{};if(_r(s,"quoteStyle")&&!_r(Sd,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 Md(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Ed(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Ed(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=z1(s,i);if(typeof n>"u")n=[];else if(Rd(n,t)>=0)return"[Circular]";function d(T,E,A){if(E&&(n=S1.call(n),n.push(E)),A){var L={depth:s.depth};return _r(s,"quoteStyle")&&(L.quoteStyle=s.quoteStyle),r(T,L,i+1,n)}return r(T,s,i+1,n)}if(typeof t=="function"&&!Id(t)){var p=N1(t),f=Os(t,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+sr.call(f,", ")+" }":"")}if(Pd(t)){var m=Vi?Nr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Za.call(t);return typeof t=="object"&&!Vi?Fn(m):m}if(H1(t)){for(var y="<"+yd.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Cd(I1(_[v].value),"double",s);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+yd.call(String(t.nodeName))+">",y}if(Qa(t)){if(t.length===0)return"[]";var g=Os(t,d);return u&&!V1(g)?"["+el(g,u)+"]":"[ "+sr.call(g,", ")+" ]"}if(R1(t)){var b=Os(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!xd.call(t,"cause")?"{ ["+String(t)+"] "+sr.call(vd.call("[cause]: "+d(t.cause),b),", ")+" }":b.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+sr.call(b,", ")+" }"}if(typeof t=="object"&&o){if(Ad&&typeof t[Ad]=="function"&&Ja)return Ja(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(F1(t)){var S=[];return pd&&pd.call(t,function(T,E){S.push(d(E,t,!0)+" => "+d(T,t))}),Dd("Map",Ms.call(t),S,u)}if(G1(t)){var R=[];return md&&md.call(t,function(T){R.push(d(T,t))}),Dd("Set",Ds.call(t),R,u)}if(k1(t))return tl("WeakMap");if($1(t))return tl("WeakSet");if(U1(t))return tl("WeakRef");if(D1(t))return Fn(d(Number(t)));if(O1(t))return Fn(d(qa.call(t)));if(B1(t))return Fn(x1.call(t));if(M1(t))return Fn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Cn<"u"&&t===Cn)return"{ [object globalThis] }";if(!P1(t)&&!Id(t)){var C=Os(t,d),I=wd?wd(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",F=!I&&Nn&&Object(t)===t&&Nn in t?Ya.call(Fr(t),8,-1):M?"Object":"",U=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",P=U+(F||M?"["+sr.call(vd.call([],F||[],M||[]),": ")+"] ":"");return C.length===0?P+"{}":u?P+"{"+el(C,u)+"}":P+"{ "+sr.call(C,", ")+" }"}return String(t)};function Cd(r,t,e){var i=e.quoteStyle||t,n=Sd[i];return n+r+n}function I1(r){return Nr.call(String(r),/"/g,"&quot;")}function si(r){return!Nn||!(typeof r=="object"&&(Nn in r||typeof r[Nn]<"u"))}function Qa(r){return Fr(r)==="[object Array]"&&si(r)}function P1(r){return Fr(r)==="[object Date]"&&si(r)}function Id(r){return Fr(r)==="[object RegExp]"&&si(r)}function R1(r){return Fr(r)==="[object Error]"&&si(r)}function M1(r){return Fr(r)==="[object String]"&&si(r)}function D1(r){return Fr(r)==="[object Number]"&&si(r)}function B1(r){return Fr(r)==="[object Boolean]"&&si(r)}function Pd(r){if(Vi)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 O1(r){if(!r||typeof r!="object"||!qa)return!1;try{return qa.call(r),!0}catch{}return!1}var L1=Object.prototype.hasOwnProperty||function(r){return r in this};function _r(r,t){return L1.call(r,t)}function Fr(r){return w1.call(r)}function N1(r){if(r.name)return r.name;var t=T1.call(E1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Rd(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 F1(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 k1(r){if(!On||!r||typeof r!="object")return!1;try{On.call(r,On);try{Ln.call(r,Ln)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function U1(r){if(!gd||!r||typeof r!="object")return!1;try{return gd.call(r),!0}catch{}return!1}function G1(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 $1(r){if(!Ln||!r||typeof r!="object")return!1;try{Ln.call(r,Ln);try{On.call(r,On)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function H1(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Md(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Md(Ya.call(r,0,t.maxStringLength),t)+i}var n=C1[t.quoteStyle||"single"];n.lastIndex=0;var s=Nr.call(Nr.call(r,n,"\\$1"),/[\x00-\x1f]/g,X1);return Cd(s,"single",t)}function X1(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":"")+A1.call(t.toString(16))}function Fn(r){return"Object("+r+")"}function tl(r){return r+" { ? }"}function Dd(r,t,e,i){var n=i?el(e,i):sr.call(e,", ");return r+" ("+t+") {"+n+"}"}function V1(r){for(var t=0;t<r.length;t++)if(Rd(r[t],`
2
2
  `)>=0)return!1;return!0}function z1(r,t){var e;if(r.indent===" ")e=" ";else if(typeof r.indent=="number"&&r.indent>0)e=sr.call(Array(r.indent+1)," ");else return null;return{base:e,prev:sr.call(Array(t+1),e)}}function el(r,t){if(r.length===0)return"";var e=`
3
3
  `+t.prev+t.base;return e+sr.call(r,","+e)+`
4
4
  `+t.prev}function Os(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(Vi){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||Vi&&o["$"+l]instanceof Symbol||(_d.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++)xd.call(r,s[h])&&i.push("["+t(s[h])+"]: "+t(r[s[h]],r));return i}var j1=Bs,W1=Xi,Ls=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},Y1=function(r,t){if(r){var e=Ls(r,t);return e&&e.value}},q1=function(r,t,e){var i=Ls(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},K1=function(r,t){return r?!!Ls(r,t):!1},Z1=function(r,t){if(r)return Ls(r,t,!0)},J1=function(){var t,e={assert:function(i){if(!e.has(i))throw new W1("Side channel does not contain "+j1(i))},delete:function(i){var n=t&&t.next,s=Z1(t,i);return s&&n&&n===s&&(t=void 0),!!s},get:function(i){return Y1(t,i)},has:function(i){return K1(t,i)},set:function(i,n){t||(t={next:void 0}),q1(t,i,n)}};return e},Bd=Object,Q1=Error,tb=EvalError,eb=RangeError,rb=ReferenceError,ib=SyntaxError,nb=URIError,sb=Math.abs,ob=Math.floor,ab=Math.max,lb=Math.min,hb=Math.pow,cb=Math.round,ub=Number.isNaN||function(t){return t!==t},db=ub,fb=function(t){return db(t)||t===0?t:t<0?-1:1},pb=Object.getOwnPropertyDescriptor,Ns=pb;if(Ns)try{Ns([],"length")}catch{Ns=null}var Od=Ns,Fs=Object.defineProperty||!1;if(Fs)try{Fs({},"a",{value:1})}catch{Fs=!1}var mb=Fs,rl,Ld;function gb(){return Ld||(Ld=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,Nd;function yb(){if(Nd)return il;Nd=1;var r=typeof Symbol<"u"&&Symbol,t=gb();return il=function(){return typeof r!="function"||typeof Symbol!="function"||typeof r("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},il}var nl,Fd;function kd(){return Fd||(Fd=1,nl=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),nl}var sl,Ud;function Gd(){if(Ud)return sl;Ud=1;var r=Bd;return sl=r.getPrototypeOf||null,sl}var ol,$d;function _b(){if($d)return ol;$d=1;var r="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,e=Math.max,i="[object Function]",n=function(l,h){for(var c=[],u=0;u<l.length;u+=1)c[u]=l[u];for(var d=0;d<h.length;d+=1)c[d+l.length]=h[d];return c},s=function(l,h){for(var c=[],u=h,d=0;u<l.length;u+=1,d+=1)c[d]=l[u];return c},o=function(a,l){for(var h="",c=0;c<a.length;c+=1)h+=a[c],c+1<a.length&&(h+=l);return h};return ol=function(l){var h=this;if(typeof h!="function"||t.apply(h)!==i)throw new TypeError(r+h);for(var c=s(arguments,1),u,d=function(){if(this instanceof u){var _=h.apply(this,n(c,arguments));return Object(_)===_?_:this}return h.apply(l,n(c,arguments))},p=e(0,h.length-c.length),f=[],m=0;m<p;m++)f[m]="$"+m;if(u=Function("binder","return function ("+o(f,",")+"){ return binder.apply(this,arguments); }")(d),h.prototype){var y=function(){};y.prototype=h.prototype,u.prototype=new y,y.prototype=null}return u},ol}var al,Hd;function ks(){if(Hd)return al;Hd=1;var r=_b();return al=Function.prototype.bind||r,al}var ll,Xd;function hl(){return Xd||(Xd=1,ll=Function.prototype.call),ll}var cl,Vd;function zd(){return Vd||(Vd=1,cl=Function.prototype.apply),cl}var vb=typeof Reflect<"u"&&Reflect&&Reflect.apply,bb=ks(),xb=zd(),wb=hl(),Eb=vb,Tb=Eb||bb.call(wb,xb),Ab=ks(),Sb=Xi,Cb=hl(),Ib=Tb,jd=function(t){if(t.length<1||typeof t[0]!="function")throw new Sb("a function is required");return Ib(Ab,Cb,t)},ul,Wd;function Pb(){if(Wd)return ul;Wd=1;var r=jd,t=Od,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 ul=i&&typeof i.get=="function"?r([i.get]):typeof s=="function"?function(a){return s(a==null?a:n(a))}:!1,ul}var dl,Yd;function Rb(){if(Yd)return dl;Yd=1;var r=kd(),t=Gd(),e=Pb();return dl=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,dl}var fl,qd;function Mb(){if(qd)return fl;qd=1;var r=Function.prototype.call,t=Object.prototype.hasOwnProperty,e=ks();return fl=e.call(r,t),fl}var Tt,Db=Bd,Bb=Q1,Ob=tb,Lb=eb,Nb=rb,zi=ib,ji=Xi,Fb=nb,kb=sb,Ub=ob,Gb=ab,$b=lb,Hb=hb,Xb=cb,Vb=fb,Kd=Function,pl=function(r){try{return Kd('"use strict"; return ('+r+").constructor;")()}catch{}},kn=Od,zb=mb,ml=function(){throw new ji},jb=kn?function(){try{return arguments.callee,ml}catch{try{return kn(arguments,"callee").get}catch{return ml}}}():ml,Wi=yb()(),ce=Rb(),Wb=Gd(),Yb=kd(),Zd=zd(),Un=hl(),Yi={},qb=typeof Uint8Array>"u"||!ce?Tt:ce(Uint8Array),oi={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?Tt:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?Tt:ArrayBuffer,"%ArrayIteratorPrototype%":Wi&&ce?ce([][Symbol.iterator]()):Tt,"%AsyncFromSyncIteratorPrototype%":Tt,"%AsyncFunction%":Yi,"%AsyncGenerator%":Yi,"%AsyncGeneratorFunction%":Yi,"%AsyncIteratorPrototype%":Yi,"%Atomics%":typeof Atomics>"u"?Tt:Atomics,"%BigInt%":typeof BigInt>"u"?Tt:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?Tt:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?Tt:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?Tt:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Bb,"%eval%":eval,"%EvalError%":Ob,"%Float16Array%":typeof Float16Array>"u"?Tt:Float16Array,"%Float32Array%":typeof Float32Array>"u"?Tt:Float32Array,"%Float64Array%":typeof Float64Array>"u"?Tt:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?Tt:FinalizationRegistry,"%Function%":Kd,"%GeneratorFunction%":Yi,"%Int8Array%":typeof Int8Array>"u"?Tt:Int8Array,"%Int16Array%":typeof Int16Array>"u"?Tt:Int16Array,"%Int32Array%":typeof Int32Array>"u"?Tt:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Wi&&ce?ce(ce([][Symbol.iterator]())):Tt,"%JSON%":typeof JSON=="object"?JSON:Tt,"%Map%":typeof Map>"u"?Tt:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Wi||!ce?Tt:ce(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Db,"%Object.getOwnPropertyDescriptor%":kn,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?Tt:Promise,"%Proxy%":typeof Proxy>"u"?Tt:Proxy,"%RangeError%":Lb,"%ReferenceError%":Nb,"%Reflect%":typeof Reflect>"u"?Tt:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?Tt:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Wi||!ce?Tt:ce(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?Tt:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Wi&&ce?ce(""[Symbol.iterator]()):Tt,"%Symbol%":Wi?Symbol:Tt,"%SyntaxError%":zi,"%ThrowTypeError%":jb,"%TypedArray%":qb,"%TypeError%":ji,"%Uint8Array%":typeof Uint8Array>"u"?Tt:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?Tt:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?Tt:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?Tt:Uint32Array,"%URIError%":Fb,"%WeakMap%":typeof WeakMap>"u"?Tt:WeakMap,"%WeakRef%":typeof WeakRef>"u"?Tt:WeakRef,"%WeakSet%":typeof WeakSet>"u"?Tt:WeakSet,"%Function.prototype.call%":Un,"%Function.prototype.apply%":Zd,"%Object.defineProperty%":zb,"%Object.getPrototypeOf%":Wb,"%Math.abs%":kb,"%Math.floor%":Ub,"%Math.max%":Gb,"%Math.min%":$b,"%Math.pow%":Hb,"%Math.round%":Xb,"%Math.sign%":Vb,"%Reflect.getPrototypeOf%":Yb};if(ce)try{null.error}catch(r){var Kb=ce(ce(r));oi["%Error.prototype%"]=Kb}var Zb=function r(t){var e;if(t==="%AsyncFunction%")e=pl("async function () {}");else if(t==="%GeneratorFunction%")e=pl("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=pl("async function* () {}");else if(t==="%AsyncGenerator%"){var i=r("%AsyncGeneratorFunction%");i&&(e=i.prototype)}else if(t==="%AsyncIteratorPrototype%"){var n=r("%AsyncGenerator%");n&&ce&&(e=ce(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"]},Gn=ks(),Us=Mb(),Jb=Gn.call(Un,Array.prototype.concat),Qb=Gn.call(Zd,Array.prototype.splice),Qd=Gn.call(Un,String.prototype.replace),Gs=Gn.call(Un,String.prototype.slice),tx=Gn.call(Un,RegExp.prototype.exec),ex=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,rx=/\\(\\)?/g,ix=function(t){var e=Gs(t,0,1),i=Gs(t,-1);if(e==="%"&&i!=="%")throw new zi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new zi("invalid intrinsic syntax, expected opening `%`");var n=[];return Qd(t,ex,function(s,o,a,l){n[n.length]=a?Qd(l,rx,"$1"):o||s}),n},nx=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===Yi&&(s=Zb(i)),typeof s>"u"&&!e)throw new ji("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:s}}throw new zi("intrinsic "+t+" does not exist!")},gl=function(t,e){if(typeof t!="string"||t.length===0)throw new ji("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new ji('"allowMissing" argument must be a boolean');if(tx(/^%?[^%]*%?$/,t)===null)throw new zi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=ix(t),n=i.length>0?i[0]:"",s=nx("%"+n+"%",e),o=s.name,a=s.value,l=!1,h=s.alias;h&&(n=h[0],Qb(i,Jb([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 zi("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 ji("base intrinsic for "+t+" exists, but the property is not available.");return}if(kn&&c+1>=i.length){var m=kn(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},tf=gl,ef=jd,sx=ef([tf("%String.prototype.indexOf%")]),rf=function(t,e){var i=tf(t,!!e);return typeof i=="function"&&sx(t,".prototype.")>-1?ef([i]):i},ox=gl,$n=rf,ax=Bs,lx=Xi,nf=ox("%Map%",!0),hx=$n("Map.prototype.get",!0),cx=$n("Map.prototype.set",!0),ux=$n("Map.prototype.has",!0),dx=$n("Map.prototype.delete",!0),fx=$n("Map.prototype.size",!0),sf=!!nf&&function(){var t,e={assert:function(i){if(!e.has(i))throw new lx("Side channel does not contain "+ax(i))},delete:function(i){if(t){var n=dx(t,i);return fx(t)===0&&(t=void 0),n}return!1},get:function(i){if(t)return hx(t,i)},has:function(i){return t?ux(t,i):!1},set:function(i,n){t||(t=new nf),cx(t,i,n)}};return e},px=gl,$s=rf,mx=Bs,Hs=sf,gx=Xi,qi=px("%WeakMap%",!0),yx=$s("WeakMap.prototype.get",!0),_x=$s("WeakMap.prototype.set",!0),vx=$s("WeakMap.prototype.has",!0),bx=$s("WeakMap.prototype.delete",!0),xx=qi?function(){var t,e,i={assert:function(n){if(!i.has(n))throw new gx("Side channel does not contain "+mx(n))},delete:function(n){if(qi&&n&&(typeof n=="object"||typeof n=="function")){if(t)return bx(t,n)}else if(Hs&&e)return e.delete(n);return!1},get:function(n){return qi&&n&&(typeof n=="object"||typeof n=="function")&&t?yx(t,n):e&&e.get(n)},has:function(n){return qi&&n&&(typeof n=="object"||typeof n=="function")&&t?vx(t,n):!!e&&e.has(n)},set:function(n,s){qi&&n&&(typeof n=="object"||typeof n=="function")?(t||(t=new qi),_x(t,n,s)):Hs&&(e||(e=Hs()),e.set(n,s))}};return i}:Hs,wx=Xi,Ex=Bs,Tx=J1,Ax=sf,Sx=xx,Cx=Sx||Ax||Tx,Ix=function(){var t,e={assert:function(i){if(!e.has(i))throw new wx("Side channel does not contain "+Ex(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=Cx()),t.set(i,n)}};return e},Px=String.prototype.replace,Rx=/%20/g,yl={RFC1738:"RFC1738",RFC3986:"RFC3986"},_l={default:yl.RFC3986,formatters:{RFC1738:function(r){return Px.call(r,Rx,"+")},RFC3986:function(r){return String(r)}},RFC1738:yl.RFC1738,RFC3986:yl.RFC3986},Mx=_l,vl=Object.prototype.hasOwnProperty,ai=Array.isArray,or=function(){for(var r=[],t=0;t<256;++t)r.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return r}(),Dx=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}}},of=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},Bx=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)||!vl.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=of(t,i)),ai(t)&&ai(e)?(e.forEach(function(s,o){if(vl.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 vl.call(s,o)?s[o]=r(s[o],a,i):s[o]=a,s},n)},Ox=function(t,e){return Object.keys(e).reduce(function(i,n){return i[n]=e[n],i},t)},Lx=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}},bl=1024,Nx=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+=bl){for(var h=o.length>=bl?o.slice(l,l+bl):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===Mx.RFC1738&&(d===40||d===41)){c[c.length]=h.charAt(u);continue}if(d<128){c[c.length]=or[d];continue}if(d<2048){c[c.length]=or[192|d>>6]+or[128|d&63];continue}if(d<55296||d>=57344){c[c.length]=or[224|d>>12]+or[128|d>>6&63]+or[128|d&63];continue}u+=1,d=65536+((d&1023)<<10|h.charCodeAt(u)&1023),c[c.length]=or[240|d>>18]+or[128|d>>12&63]+or[128|d>>6&63]+or[128|d&63]}a+=c.join("")}return a},Fx=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 Dx(e),t},kx=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},Ux=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},Gx=function(t,e){return[].concat(t,e)},$x=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)},af={arrayToObject:of,assign:Ox,combine:Gx,compact:Fx,decode:Lx,encode:Nx,isBuffer:Ux,isRegExp:kx,maybeMap:$x,merge:Bx},lf=Ix,Xs=af,Hn=_l,Hx=Object.prototype.hasOwnProperty,hf={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},ar=Array.isArray,Xx=Array.prototype.push,cf=function(r,t){Xx.apply(r,ar(t)?t:[t])},Vx=Date.prototype.toISOString,uf=Hn.default,ne={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:uf,formatter:Hn.formatters[uf],indices:!1,serializeDate:function(t){return Vx.call(t)},skipNulls:!1,strictNullHandling:!1},zx=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},xl={},jx=function r(t,e,i,n,s,o,a,l,h,c,u,d,p,f,m,y,_,v){for(var g=t,b=v,S=0,R=!1;(b=b.get(xl))!==void 0&&!R;){var C=b.get(t);if(S+=1,typeof C<"u"){if(C===S)throw new RangeError("Cyclic object value");R=!0}typeof b.get(xl)>"u"&&(S=0)}if(typeof c=="function"?g=c(e,g):g instanceof Date?g=p(g):i==="comma"&&ar(g)&&(g=Xs.maybeMap(g,function(O){return O instanceof Date?p(O):O})),g===null){if(o)return h&&!y?h(e,ne.encoder,_,"key",f):e;g=""}if(zx(g)||Xs.isBuffer(g)){if(h){var I=y?e:h(e,ne.encoder,_,"key",f);return[m(I)+"="+m(h(g,ne.encoder,_,"value",f))]}return[m(e)+"="+m(String(g))]}var M=[];if(typeof g>"u")return M;var F;if(i==="comma"&&ar(g))y&&h&&(g=Xs.maybeMap(g,h)),F=[{value:g.length>0?g.join(",")||null:void 0}];else if(ar(c))F=c;else{var U=Object.keys(g);F=u?U.sort(u):U}var P=l?String(e).replace(/\./g,"%2E"):String(e),T=n&&ar(g)&&g.length===1?P+"[]":P;if(s&&ar(g)&&g.length===0)return T+"[]";for(var E=0;E<F.length;++E){var A=F[E],L=typeof A=="object"&&A&&typeof A.value<"u"?A.value:g[A];if(!(a&&L===null)){var D=d&&l?String(A).replace(/\./g,"%2E"):String(A),N=ar(g)?typeof i=="function"?i(T,D):T:T+(d?"."+D:"["+D+"]");v.set(t,S);var $=lf();$.set(xl,v),cf(M,r(L,N,i,n,s,o,a,l,i==="comma"&&y&&ar(g)?null:h,c,u,d,p,f,m,y,_,$))}}return M},Wx=function(t){if(!t)return ne;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||ne.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=Hn.default;if(typeof t.format<"u"){if(!Hx.call(Hn.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var n=Hn.formatters[i],s=ne.filter;(typeof t.filter=="function"||ar(t.filter))&&(s=t.filter);var o;if(t.arrayFormat in hf?o=t.arrayFormat:"indices"in t?o=t.indices?"indices":"repeat":o=ne.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:ne.allowDots:!!t.allowDots;return{addQueryPrefix:typeof t.addQueryPrefix=="boolean"?t.addQueryPrefix:ne.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:ne.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:ne.charsetSentinel,commaRoundTrip:!!t.commaRoundTrip,delimiter:typeof t.delimiter>"u"?ne.delimiter:t.delimiter,encode:typeof t.encode=="boolean"?t.encode:ne.encode,encodeDotInKeys:typeof t.encodeDotInKeys=="boolean"?t.encodeDotInKeys:ne.encodeDotInKeys,encoder:typeof t.encoder=="function"?t.encoder:ne.encoder,encodeValuesOnly:typeof t.encodeValuesOnly=="boolean"?t.encodeValuesOnly:ne.encodeValuesOnly,filter:s,format:i,formatter:n,serializeDate:typeof t.serializeDate=="function"?t.serializeDate:ne.serializeDate,skipNulls:typeof t.skipNulls=="boolean"?t.skipNulls:ne.skipNulls,sort:typeof t.sort=="function"?t.sort:null,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:ne.strictNullHandling}},Yx=function(r,t){var e=r,i=Wx(t),n,s;typeof i.filter=="function"?(s=i.filter,e=s("",e)):ar(i.filter)&&(s=i.filter,n=s);var o=[];if(typeof e!="object"||e===null)return"";var a=hf[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var h=lf(),c=0;c<n.length;++c){var u=n[c],d=e[u];i.skipNulls&&d===null||cf(o,jx(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=af,wl=Object.prototype.hasOwnProperty,df=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},qx=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},ff=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},Kx="utf8=%26%2310003%3B",Zx="utf8=%E2%9C%93",Jx=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]===Zx?h="utf-8":o[l]===Kx&&(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(ff(c.slice(d+1),e,df(i[p])?i[p].length:0),function(y){return e.decoder(y,Wt.decoder,h,"value")})),f&&e.interpretNumericEntities&&h==="iso-8859-1"&&(f=qx(String(f))),c.indexOf("[]=")>-1&&(f=df(f)?[f]:f);var m=wl.call(i,p);m&&e.duplicates==="combine"?i[p]=li.combine(i[p],f):(!m||e.duplicates==="last")&&(i[p]=f)}return i},Qx=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:ff(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},tw=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&&wl.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&&wl.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 Qx(c,e,i,n)}},ew=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}},rw=function(r,t){var e=ew(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?{__proto__:null}:{};for(var i=typeof r=="string"?Jx(r,e):r,n=e.plainObjects?{__proto__:null}:{},s=Object.keys(i),o=0;o<s.length;++o){var a=s[o],l=tw(a,i[a],e,typeof r=="string");n=li.merge(n,l,e)}return e.allowSparse===!0?n:li.compact(n)},iw=Yx,nw=rw,sw=_l,ow={formats:sw,parse:nw,stringify:iw},aw=g1;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 lw=/^([a-z0-9.+-]+:)/i,hw=/:[0-9]*$/,cw=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,uw=["<",">",'"',"`"," ","\r",`