@annotorious/openseadragon 3.7.20 → 3.7.22

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 yC=Object.defineProperty;var _C=(qt,se,Qr)=>se in qt?yC(qt,se,{enumerable:!0,configurable:!0,writable:!0,value:Qr}):qt[se]=Qr;var jh=(qt,se,Qr)=>_C(qt,typeof se!="symbol"?se+"":se,Qr);var Qr=Object.prototype.hasOwnProperty;function Jr(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--&&Jr(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)||!Jr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var zo=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(zo||{});const fe=[];for(let r=0;r<256;++r)fe.push((r+256).toString(16).slice(1));function cg(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 Yo;const ug=new Uint8Array(16);function dg(){if(!Yo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Yo=crypto.getRandomValues.bind(crypto)}return Yo(ug)}const fg=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Jh={randomUUID:fg};function pg(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??dg();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,cg(n)}function mg(r,t,e){return Jh.randomUUID&&!r?Jh.randomUUID():pg(r)}const qo=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)}},gg=(r,t,e,i)=>({id:mg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),yg=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},_g=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},vg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Jr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),bg=(r,t)=>!Jr(r.target,t.target),xg=(r,t)=>{const e=yg(r,t),i=_g(r,t),n=vg(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:bg(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Mr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Mr||{});const wg=(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:f}=u;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return xg(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let Eg=()=>({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 Tg=250,Ag=(r,t)=>{const e=Eg(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:m}=p,y=performance.now();if(y-o>Tg)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=wg(i[_],m)}o=y}s=!1};r.observe(a,{origin:Mr.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),c=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:m})=>m)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:m})=>m)),d=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),f=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(p,m)=>e.on(p,m),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:m,deleted:y}=i[n+1];h(p),u(m),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:m,deleted:y}=i[n];l(p),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},Sg=(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])},f=(_,v)=>{const g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},p=(_,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||!Jr(b,g))&&p("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&&!Jr(g,v)&&p("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&&!Jr(S,b)&&p("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}p("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?p("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>p("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=>p("createAnnotation",b)),(g||[]).forEach(b=>p("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),p("updateAnnotation",S,R)})},{origin:Mr.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:Mr.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>p("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>p("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},Cg=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:[]}),Ig=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Mr.REMOTE):console.error(g)}else i.addAnnotation(qo(_),Mr.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=>(f(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),_}},f=(_,v=!0)=>{if(e){const g=e.parseAll||Cg(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Mr.REMOTE)}else i.bulkAddAnnotations(_.map(qo),v,Mr.REMOTE)},p=(_,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(qo(_)),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:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:y}},Pg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Rg=r=>crypto.getRandomValues(new Uint8Array(r)),Mg=(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}}},Dg=(r,t=21)=>Mg(r,t|0,Rg),Bg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Pg[e[r]&63];return t};const Og=()=>({isGuest:!0,id:Dg("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Lg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Ng=()=>{const r=[...Lg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};Bg();var Fg=Object.defineProperty,kg=(r,t,e)=>t in r?Fg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,tc=(r,t,e)=>kg(r,typeof t!="symbol"?t+"":t,e);function Rt(){}function Ko(r,t){for(const e in t)r[e]=t[e];return r}function ec(r){return r()}function rc(){return Object.create(null)}function Me(r){r.forEach(ec)}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 Ug(r){return Object.keys(r).length===0}function ic(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 Zo(r,t,e){r.$$.on_destroy.push(ic(t,e))}function Gg(r,t,e,i){if(r){const n=nc(r,t,e,i);return r[0](n)}}function nc(r,t,e,i){return r[1]&&i?Ko(e.ctx.slice(),r[1](i(t))):e.ctx}function $g(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 Hg(r,t,e,i,n,s){if(n){const o=nc(t,e,i,s);r.p(o,n)}}function Xg(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 sc(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Ci(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 ti(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function z(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function oc(r){return document.createTextNode(r)}function we(){return oc(" ")}function De(){return oc("")}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 Vg(r){return Array.from(r.childNodes)}function Je(r,t,e){r.classList.toggle(t,!!e)}function jg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let bn;function xn(r){bn=r}function ac(){if(!bn)throw new Error("Function called outside component initialization");return bn}function ei(r){ac().$$.on_mount.push(r)}function Dr(){const r=ac();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=jg(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 Ii=[],us=[];let Pi=[];const lc=[],hc=Promise.resolve();let Qo=!1;function cc(){Qo||(Qo=!0,hc.then(dc))}function uc(){return cc(),hc}function Jo(r){Pi.push(r)}const ta=new Set;let Ri=0;function dc(){if(Ri!==0)return;const r=bn;do{try{for(;Ri<Ii.length;){const t=Ii[Ri];Ri++,xn(t),Wg(t.$$)}}catch(t){throw Ii.length=0,Ri=0,t}for(xn(null),Ii.length=0,Ri=0;us.length;)us.pop()();for(let t=0;t<Pi.length;t+=1){const e=Pi[t];ta.has(e)||(ta.add(e),e())}Pi.length=0}while(Ii.length);for(;lc.length;)lc.pop()();Qo=!1,ta.clear(),xn(r)}function Wg(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 zg(r){const t=[],e=[];Pi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Pi=t}const ds=new Set;let ri;function Ee(){ri={r:0,c:[],p:ri}}function Te(){ri.r||Me(ri.c),ri=ri.p}function lt(r,t){r&&r.i&&(ds.delete(r),r.i(t))}function yt(r,t,e,i){if(r&&r.o){if(ds.has(r))return;ds.add(r),ri.c.push(()=>{ds.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 Jt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Jo(()=>{const s=r.$$.on_mount.map(ec).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&&(zg(e.after_update),Me(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Yg(r,t){r.$$.dirty[0]===-1&&(Ii.push(r),cc(),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=bn;xn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Rt,not_equal:n,bound:rc(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:rc(),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,...f)=>{const p=f.length?f[0]:d;return h.ctx&&n(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&Yg(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=Vg(t.target);h.fragment&&h.fragment.l(u),u.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&lt(r.$$.fragment),Jt(r,t.target,t.anchor),dc()}xn(l)}class me{constructor(){tc(this,"$$"),tc(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&&!Ug(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const qg="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(qg);var _t=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(_t||{}),Kg={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,f=h.y-u;if(d!==0||f!==0){var p=((a.x-c)*d+(a.y-u)*f)/(d*d+f*f);p>1?(c=h.x,u=h.y):p>0&&(c+=d*p,u+=f*p)}return d=a.x-c,f=a.y-u,d*d+f*f}function i(a,l){for(var h=a[0],c=[h],u,d=1,f=a.length;d<f;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,f,p=l+1;p<h;p++){var m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}d>c&&(f-l>1&&n(a,l,f,c,u),u.push(a[f]),h-f>1&&n(a,f,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})()})(Kg);const ea={},Mi=(r,t)=>ea[r]=t,ra=r=>ea[r.type].area(r),Zg=(r,t,e,i)=>ea[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}},fs=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)},ps=(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},Qg=(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},ms=(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,f=h*c-l*u;return d*d/(s*s)+f*f/(o*o)<=1}};Mi(_t.ELLIPSE,Jg);const ty={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=ms([n,s],[o,a]);return l/h<=i}};Mi(_t.LINE,ty);const ey={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=fs(n.points),a=s.reduce((l,h)=>l+fs(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(ps(s.points,t,e)){let a=!1;for(const l of o)if(ps(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},ia=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ae(t)},He=r=>r.rings.map(t=>Qg(t.points)).join(" "),ry=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Mi(_t.MULTIPOLYGON,ey);const iy={area:r=>{const t=r.geometry.points;return fs(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return ps(i,t,e)}};Mi(_t.POLYGON,iy);const ny={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=na(t.points,t.closed);return fs(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=na(n.points,n.closed);return ps(s,t,e)}else return sy(n,[t,e],i)}},na=(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=fc(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},fc=(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},sy=(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=fc(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(pc(t,o[a],o[a+1])<=e)return!0}else if(pc(t,n.point,s.point)<=e)return!0}return!1},pc=(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},sa=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(" ")};Mi(_t.POLYLINE,ny);const oy={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};Mi(_t.RECTANGLE,oy);const Le=r=>gs(r.target),gs=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},ay=r=>(r==null?void 0:r.type)==="FragmentSelector"?!0:typeof r=="string"?r.indexOf("#")<0?!1:/^#xywh(?:=(?:pixel:|percent:)?)\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?$/i.test(r):!1,ly=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,n=[...e.matchAll(i)][0];if(!n)throw new Error("Not a MediaFragment: "+e);const[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,f,p,m]=[l,h,c,u].map(parseFloat);return{type:_t.RECTANGLE,geometry:{x:d,y:f,w:p,h:m,bounds:{minX:d,minY:t?f-m:f,maxX:d+p,maxY:t?f:f+m}}}},hy=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}`}},mc="http://www.w3.org/2000/svg",gc=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},cy=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${mc}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},ys=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(mc),i=t.lookupNamespaceURI(null);return e||i?gc(t).firstChild:gc(cy(t)).firstChild},uy=r=>{const t=yc(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}}},dy=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},fy=r=>{const t=yc(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=>dy(o)?{...o,locked:!0}:o);const s=Ae(na(e,n));return{points:e,closed:n,bounds:s}},yc=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},py=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)}}},my=r=>{const t=ys(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}}},gy=r=>{const t=ys(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}}},yy=r=>{const t=ys(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=fy(i);if(!n)throw new Error("Could not parse SVG path");return{type:_t.POLYLINE,geometry:n}},_y=r=>{const t=ys(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>uy(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}}},vy=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return py(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return yy(t);if(t.includes("<path "))return _y(t);if(t.includes("<ellipse "))return my(t);if(t.includes("<line "))return gy(t);throw"Unsupported SVG shape: "+t},by=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${He(t)}" />`).join("")}</g>`,xy=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>${by(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="${sa(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 wy(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 oa;const Ey=new Uint8Array(16);function Ty(){if(!oa){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");oa=crypto.getRandomValues.bind(crypto)}return oa(Ey)}const Ay=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_c={randomUUID:Ay};function Sy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Ty();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,wy(n)}function vc(r,t,e){return _c.randomUUID&&!r?_c.randomUUID():Sy(r)}var bc=Object.prototype.hasOwnProperty;function Br(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--&&Br(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(bc.call(r,e)&&++i&&!bc.call(t,e)||!(e in t)||!Br(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}let Xe=[],Or=0;const _s=4,aa=r=>{let t=[],e={get(){return e.lc||e.listen(()=>{})(),e.value},lc:0,listen(i){return e.lc=t.push(i),()=>{for(let s=Or+_s;s<Xe.length;)Xe[s]===i?Xe.splice(s,_s):s+=_s;let n=t.indexOf(i);~n&&(t.splice(n,1),--e.lc||e.off())}},notify(i,n){let s=!Xe.length;for(let o of t)Xe.push(o,e.value,i,n);if(s){for(Or=0;Or<Xe.length;Or+=_s)Xe[Or](Xe[Or+1],Xe[Or+2],Xe[Or+3]);Xe.length=0}},off(){},set(i){let n=e.value;n!==i&&(e.value=i,e.notify(n))},subscribe(i){let n=e.listen(i);return i(e.value),n},value:r};return e},Cy=r=>{const t=aa(null);return r.observe(({changes:e})=>{const i=t.get();if(i){(e.deleted||[]).some(s=>s.id===i)&&t.set(null);const n=(e.updated||[]).find(({oldValue:s})=>s.id===i);n&&t.set(n.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var xc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(xc||{});const la={selected:[]},Iy=(r,t,e)=>{const i=aa(la);let n=t;const s=()=>{Br(i.get(),la)||i.set(la)},o=()=>{var f;return((f=i.get().selected)==null?void 0:f.length)===0},a=f=>{if(o())return!1;const p=typeof f=="string"?f:f.id;return i.get().selected.some(m=>m.id===p)},l=(f,p)=>{let m;if(Array.isArray(f)){if(m=f.map(_=>r.getAnnotation(_)).filter(Boolean),m.length<f.length){console.warn("Invalid selection: "+f.filter(_=>!m.some(v=>v.id===_)));return}}else{const _=r.getAnnotation(f);if(!_){console.warn("Invalid selection: "+f);return}m=[_]}const y=m.reduce((_,v)=>{const g=d(v);return g==="EDIT"?[..._,{id:v.id,editable:!0}]:g==="SELECT"?[..._,{id:v.id}]:_},[]);i.set({selected:y,event:p})},h=(f,p)=>{const m=Array.isArray(f)?f:[f],y=m.map(_=>r.getAnnotation(_)).filter(_=>!!_);i.set({selected:y.map(_=>{const v=p===void 0?d(_)==="EDIT":p;return{id:_.id,editable:v}})}),y.length!==m.length&&console.warn("Invalid selection",f)},c=f=>{if(o())return!1;const{selected:p}=i.get();p.some(({id:m})=>f.includes(m))&&i.set({selected:p.filter(({id:m})=>!f.includes(m))})},u=f=>{n=f,h(i.get().selected.map(({id:p})=>p))},d=f=>Py(f,n,e);return r.observe(({changes:f})=>c((f.deleted||[]).map(p=>p.id))),{get event(){const f=i.get();return f?f.event:null},get selected(){const f=i.get();return f?[...f.selected]:null},get userSelectAction(){return n},clear:s,evalSelectAction:d,isEmpty:o,isSelected:a,setSelected:h,setUserSelectAction:u,subscribe:i.subscribe.bind(i),userSelect:l}},Py=(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 Ry(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 ha;const My=new Uint8Array(16);function Dy(){if(!ha){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ha=crypto.getRandomValues.bind(crypto)}return ha(My)}const By=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),wc={randomUUID:By};function Oy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Dy();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,Ry(n)}function Ly(r,t,e){return wc.randomUUID&&!r?wc.randomUUID():Oy(r)}const ca=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)}},Ny=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Fy=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},ky=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Br(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Uy=(r,t)=>!Br(r.target,t.target),Ec=(r,t)=>{const e=Ny(r,t),i=Fy(r,t),n=ky(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:Uy(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 Gy=(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},$y=(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:f}=u;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return Ec(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},vs=r=>{const t=r.id===void 0?Ly():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Hy=r=>r.id!==void 0,Xy=()=>{const r=new Map,t=new Map,e=[],i=(P,E={})=>{e.push({onChange:P,options:E})},n=P=>{const E=e.findIndex(T=>T.onChange==P);E>-1&&e.splice(E,1)},s=(P,E)=>{const T={origin:P,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...r.values()]};e.forEach(A=>{Gy(A,T)&&A.onChange(T)})},o=(P,E=Nt.LOCAL)=>{if(P.id&&r.get(P.id))throw Error(`Cannot add annotation ${P.id} - exists already`);{const T=vs(P);r.set(T.id,T),T.bodies.forEach(A=>t.set(A.id,T.id)),s(E,{created:[T]})}},a=(P,E)=>{const T=vs(typeof P=="string"?E:P),A=typeof P=="string"?P:P.id,O=A&&r.get(A);if(O){const D=Ec(O,T);return A===T.id?r.set(A,T):(r.delete(A),r.set(T.id,T)),O.bodies.forEach(L=>t.delete(L.id)),T.bodies.forEach(L=>t.set(L.id,T.id)),D}else console.warn(`Cannot update annotation ${A} - does not exist`)},l=(P,E=Nt.LOCAL,T=Nt.LOCAL)=>{const A=Hy(E)?T:E,O=a(P,E);O&&s(A,{updated:[O]})},h=(P,E=Nt.LOCAL)=>{r.get(P.id)?l(P,E):o(P,E)},c=(P,E=Nt.LOCAL)=>{const T=P.reduce((A,O)=>{const D=a(O);return D?[...A,D]:A},[]);T.length>0&&s(E,{updated:T})},u=(P,E=Nt.LOCAL)=>{const T=P.map(vs),{toAdd:A,toUpdate:O}=T.reduce((L,$)=>r.get($.id)?{...L,toUpdate:[...L.toUpdate,$]}:{...L,toAdd:[...L.toAdd,$]},{toAdd:[],toUpdate:[]}),D=O.map(L=>a(L,E)).filter(Boolean);A.forEach(L=>{r.set(L.id,L),L.bodies.forEach($=>t.set($.id,L.id))}),s(E,{created:A,updated:D})},d=(P,E=Nt.LOCAL)=>{const T=r.get(P.annotation);if(T){const A={...T,bodies:[...T.bodies,P]};r.set(T.id,A),t.set(P.id,A.id),s(E,{updated:[{oldValue:T,newValue:A,bodiesCreated:[P]}]})}else console.warn(`Attempt to add body to missing annotation: ${P.annotation}`)},f=()=>[...r.values()],p=(P=Nt.LOCAL)=>{const E=[...r.values()];r.clear(),t.clear(),s(P,{deleted:E})},m=(P,E=!0,T=Nt.LOCAL)=>{const A=P.map(vs);if(E){const O=[...r.values()];r.clear(),t.clear(),A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(L=>t.set(L.id,D.id))}),s(T,{created:A,deleted:O})}else{const O=P.reduce((D,L)=>{const $=L.id&&r.get(L.id);return $?[...D,$]:D},[]);if(O.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${O.map(D=>D.id).join(", ")}`);A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(L=>t.set(L.id,D.id))}),s(T,{created:A})}},y=P=>{const E=typeof P=="string"?P:P.id,T=r.get(E);if(T)return r.delete(E),T.bodies.forEach(A=>t.delete(A.id)),T;console.warn(`Attempt to delete missing annotation: ${E}`)},_=(P,E=Nt.LOCAL)=>{const T=y(P);T&&s(E,{deleted:[T]})},v=(P,E=Nt.LOCAL)=>{const T=P.reduce((A,O)=>{const D=y(O);return D?[...A,D]:A},[]);T.length>0&&s(E,{deleted:T})},g=P=>{const E=r.get(P.annotation);if(E){const T=E.bodies.find(A=>A.id===P.id);if(T){t.delete(T.id);const A={...E,bodies:E.bodies.filter(O=>O.id!==P.id)};return r.set(E.id,A),{oldValue:E,newValue:A,bodiesDeleted:[T]}}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,E=Nt.LOCAL)=>{const T=g(P);T&&s(E,{updated:[T]})},S=(P,E=Nt.LOCAL)=>{const T=P.map(A=>g(A)).filter(Boolean);T.length>0&&s(E,{updated:T})},R=P=>{const E=r.get(P);return E?{...E}:void 0},C=P=>{const E=t.get(P);if(E){const T=R(E).bodies.find(A=>A.id===P);if(T)return T;console.error(`Store integrity error: body ${P} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${P}`)},I=(P,E)=>{if(P.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const T=r.get(P.annotation);if(T){const A=T.bodies.find(D=>D.id===P.id),O={...T,bodies:T.bodies.map(D=>D.id===A.id?E:D)};return r.set(T.id,O),A.id!==E.id&&(t.delete(A.id),t.set(E.id,O.id)),{oldValue:T,newValue:O,bodiesUpdated:[{oldBody:A,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${P.annotation}`)},M=(P,E,T=Nt.LOCAL)=>{const A=I(P,E);A&&s(T,{updated:[A]})},F=(P,E=Nt.LOCAL)=>{const T=P.map(A=>I({id:A.id,annotation:A.annotation},A)).filter(Boolean);s(E,{updated:T})},U=P=>{const E=r.get(P.annotation);if(E){const T={...E,target:{...E.target,...P}};return r.set(E.id,T),{oldValue:E,newValue:T,targetUpdated:{oldTarget:E.target,newTarget:P}}}else console.warn(`Attempt to update target on missing annotation: ${P.annotation}`)};return{addAnnotation:o,addBody:d,all:f,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:S,bulkUpdateAnnotations:c,bulkUpdateBodies:F,bulkUpdateTargets:(P,E=Nt.LOCAL)=>{const T=P.map(A=>U(A)).filter(Boolean);T.length>0&&s(E,{updated:T})},bulkUpsertAnnotations:u,clear:p,deleteAnnotation:_,deleteBody:b,getAnnotation:R,getBody:C,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(P,E=Nt.LOCAL)=>{const T=U(P);T&&s(E,{updated:[T]})},upsertAnnotation:h}};let Vy=()=>({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 jy=250,Wy=(r,t)=>{const e=Vy(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:m}=p,y=performance.now();if(y-o>jy)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=$y(i[_],m)}o=y}s=!1};r.observe(a,{origin:Nt.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),c=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:m})=>m)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:m})=>m)),d=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),f=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(p,m)=>e.on(p,m),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:m,deleted:y}=i[n+1];h(p),u(m),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:m,deleted:y}=i[n];l(p),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},zy=()=>{const r=aa([]);return{subscribe:r.subscribe.bind(r),set:r.set.bind(r)}},Yy=(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])},f=(_,v)=>{const g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},p=(_,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||!Br(b,g))&&p("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&&!Br(g,v)&&p("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&&!Br(S,b)&&p("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}p("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?p("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>p("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=>p("createAnnotation",b)),(g||[]).forEach(b=>p("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),p("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=>p("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>p("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},qy=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:[]}),Ky=(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(ca(_),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=>(f(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),_}},f=(_,v=!0)=>{if(e){const g=e.parseAll||qy(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(ca),v,Nt.REMOTE)},p=(_,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(ca(_)),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:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:y}},Zy=(r,t,e)=>typeof t=="function"?t(r,e):t,Qy=(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||{}}},Jy="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let t0=r=>crypto.getRandomValues(new Uint8Array(r)),e0=(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}}},r0=(r,t=21)=>e0(r,t|0,t0),i0=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Jy[e[r]&63];return t};const n0=()=>({isGuest:!0,id:r0("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),s0=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}`},Tc=r=>r?typeof r=="object"?{...r}:r:void 0,o0=(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-${s0(e)}`,annotation:t,type:n,purpose:s,value:o,creator:Tc(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),a0=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});i0();const l0=(r,t={strict:!0,invertY:!1})=>({parse:e=>h0(e,t),serialize:e=>c0(e,r,t)}),h0=(r,t={strict:!0,invertY:!1})=>{const e=r.id||vc(),{creator:i,created:n,modified:s,body:o,...a}=r,l=o0(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=ay(c)?ly(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?vy(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:Tc(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},c0=(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?hy(i.geometry):xy(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:a0(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,typeof c.target!="string"&&"annotation"in c.target&&delete c.target.annotation,c},Di=[];function u0(r,t=Rt){let e;const i=new Set;function n(a){if(Kt(r,a)&&(r=a,e)){const l=!Di.length;for(const h of i)h[1](),Di.push(h,r);if(l){for(let h=0;h<Di.length;h+=2)Di[h][0](Di[h+1]);Di.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 d0=(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}`)},f0=(r,t)=>{d0(r,t);const{subscribe:e,set:i}=u0(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}},ii=(r,t,e)=>{const i=typeof t=="function"?t(r,e):t;if(i){const{fill:n,fillOpacity:s,stroke:o,strokeWidth:a,strokeOpacity:l}=i;let h="";return n&&(h+=`fill:${n};`),s||s===0?h+=`fill-opacity:${s};`:n&&(h+="fill-opacity:0.25;"),o&&(h+=`stroke:${o};`,h+=`stroke-width:${a||"1"};`,h+=`stroke-opacity:${l||"1"};`),h}},bs=(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,p0=r=>({}),Ac=r=>({grab:r[0]});function m0(r){let t,e,i,n;const s=r[8].default,o=Gg(s,r,r[7],Ac);return{c(){t=z("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)&&Hg(o,s,a,a[7],e?$g(s,a[7],l,p0):Xg(a[7]),Ac)},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 g0(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Dr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const f=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",_)},p=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)},[f,p,m,o,a,l,h,n,i]}class ua extends me{constructor(t){super(),pe(this,t,g0,m0,Kt,{shape:3,editor:4,transform:5,svgEl:6})}}function y0(r){let t,e,i,n,s,o,a,l,h=r[3]&&Sc(r);return{c(){t=z("g"),e=z("circle"),h&&h.c(),n=z("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=Ci(`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=Sc(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Ci(`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 _0(r){let t,e,i,n,s,o,a,l,h;return{c(){t=z("g"),e=z("circle"),n=z("circle"),o=z("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 Sc(r){let t,e;return{c(){t=z("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 v0(r){let t;function e(n,s){return Ne?_0:y0}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 b0(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 f(g){oe.call(this,r,g)}function p(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=Ko(Ko({},t),sc(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=sc(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,m,y,_,v]}class Bi extends me{constructor(t){super(),pe(this,t,b0,v0,Kt,{x:0,y:1,scale:2,selected:3})}}function x0(r){let t,e,i,n,s,o,a;return{c(){t=z("g"),e=z("circle"),n=z("circle"),s=z("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 w0(r){let t;return{c(){t=z("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 E0(r){let t;function e(n,s){return Ne?w0:x0}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 T0(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 Cc extends me{constructor(t){super(),pe(this,t,T0,E0,Kt,{x:0,y:1,scale:4})}}function da(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ic(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function fa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function pa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Pc(r){let t,e,i,n;return{c(){t=z("circle"),x(t,"cx",e=r[28][0]),x(t,"cy",i=r[28][1]),x(t,"r",n=wn/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=wn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function Rc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("mask"),e=z("rect"),a=z("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=wn/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=wn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Mc(r){let t,e;return t=new Bi({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){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function Dc(r){let t,e;return t=new Cc({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){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function A0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&Pc(pa(r)),C=r[6]!==void 0&&!r[7]&&Rc(fa(r)),I=Ie(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Mc(Ic(r,I,P));const F=P=>yt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Dc(da(r));return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("polygon"),R&&R.c(),C&&C.c(),c=we(),u=z("polygon"),f=we(),p=z("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(Bc).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(Oc).join(" ")),x(p,"class","a9s-inner a9s-shape-handle"),x(p,"mask",`url(#${r[19]}-inner)`),x(p,"style",r[1]),x(p,"points",m=r[5].points.map(Lc).join(" "))},m(P,E){nt(P,t,E),xt(t,e),xt(e,i),xt(e,l),R&&R.m(e,null),C&&C.m(t,null),nt(P,c,E),nt(P,u,E),nt(P,f,E),nt(P,p,E),nt(P,y,E);for(let T=0;T<M.length;T+=1)M[T]&&M[T].m(P,E);nt(P,_,E),U&&U.m(P,E),nt(P,v,E),g=!0,b||(S=[St(u,"pointerup",r[14]),St(u,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),St(p,"pointermove",r[13]),St(p,"pointerup",r[14]),St(p,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,E){if(r=P,(!g||E[0]&512&&n!==(n=r[9].x))&&x(i,"x",n),(!g||E[0]&512&&s!==(s=r[9].y))&&x(i,"y",s),(!g||E[0]&512&&o!==(o=r[9].w))&&x(i,"width",o),(!g||E[0]&512&&a!==(a=r[9].h))&&x(i,"height",a),(!g||E[0]&32&&h!==(h=r[5].points.map(Bc).join(" ")))&&x(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(pa(r),E):(R=Pc(pa(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(fa(r),E):(C=Rc(fa(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||E[0]&32&&d!==(d=r[5].points.map(Oc).join(" ")))&&x(u,"points",d),(!g||E[0]&2)&&x(p,"style",r[1]),(!g||E[0]&32&&m!==(m=r[5].points.map(Lc).join(" ")))&&x(p,"points",m),E[0]&134322472){I=Ie(r[5].points);let T;for(T=0;T<I.length;T+=1){const A=Ic(r,I,T);M[T]?(M[T].p(A,E),lt(M[T],1)):(M[T]=Mc(A),M[T].c(),lt(M[T],1),M[T].m(_.parentNode,_))}for(Ee(),T=I.length;T<M.length;T+=1)F(T);Te()}r[6]!==void 0&&!r[7]?U?(U.p(da(r),E),E[0]&192&&lt(U,1)):(U=Dc(da(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 E=0;E<I.length;E+=1)lt(M[E]);lt(U),g=!0}},o(P){M=M.filter(Boolean);for(let E=0;E<M.length;E+=1)yt(M[E]);yt(U),g=!1},d(P){P&&(rt(t),rt(c),rt(u),rt(f),rt(p),rt(y),rt(_),rt(v)),R&&R.d(),C&&C.d(),ti(M,P),U&&U.d(P),b=!1,Me(S)}}}function S0(r){let t,e;return t=new ua({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[A0,({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){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const C0=250,I0=1e3,P0=12,wn=4.5,Bc=r=>r.join(","),Oc=r=>r.join(","),Lc=r=>r.join(",");function R0(r,t,e){let i,n,s;const o=Dr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=T=>{if(m.length>0||!n.some(N=>N.visible)){e(6,d=void 0);return}const[A,O]=h.elementToImage(T.offsetX,T.offsetY),D=N=>Math.pow(N[0]-A,2)+Math.pow(N[1]-O,2),L=i.points.reduce((N,k)=>D(k)<D(N)?k:N),$=n.filter(N=>N.visible).reduce((N,k)=>D(k.point)<D(N.point)?k:N),B=Math.pow(I0/c,2);D(L)<B||D($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=T=>{e(7,f=!0),T.preventDefault(),T.stopPropagation(),p=performance.now()},R=T=>A=>{if(!p||Ne||performance.now()-p>C0)return;const O=m.includes(T);A.metaKey||A.ctrlKey||A.shiftKey?O?e(8,m=m.filter(D=>D!==T)):e(8,m=[...m,T]):O&&m.length>1?e(8,m=[T]):O?e(8,m=[]):e(8,m=[T]),g()},C=(T,A,O)=>{g();let D;const L=T.geometry;m.length>1?D=L.points.map(([B,N],k)=>m.includes(k)?[B+O[0],N+O[1]]:[B,N]):A==="SHAPE"?D=L.points.map(([B,N])=>[B+O[0],N+O[1]]):D=L.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+O[0],N+O[1]]:[B,N]);const $=Ae(D);return{...T,geometry:{points:D,bounds:$}}},I=T=>async A=>{A.stopPropagation();const O=[...i.points.slice(0,T+1),n[T].point,...i.points.slice(T+1)],D=Ae(O);o("change",{...a,geometry:{points:O,bounds:D}}),await uc();const L=[...document.querySelectorAll(".a9s-handle")][T+1];if(L!=null&&L.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});L.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const T=i.points.filter((O,D)=>!m.includes(D)),A=Ae(T);o("change",{...a,geometry:{points:T,bounds:A}}),e(8,m=[])};ei(()=>{if(Ne)return;const T=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",T),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",T)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(T){oe.call(this,r,T)}function P(T){oe.call(this,r,T)}function E(T){oe.call(this,r,T)}return r.$$set=T=>{"shape"in T&&e(0,a=T.shape),"computedStyle"in T&&e(1,l=T.computedStyle),"transform"in T&&e(2,h=T.transform),"viewportScale"in T&&e(3,c=T.viewportScale),"svgEl"in T&&e(4,u=T.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Ne?[]:i.points.map((T,A)=>{const O=A===i.points.length-1?i.points[0]:i.points[A+1],D=(T[0]+O[0])/2,L=(T[1]+O[1])/2,$=Math.sqrt(Math.pow(O[0]-D,2)+Math.pow(O[1]-L,2))>P0/c;return{point:[D,L],visible:$}})),r.$$.dirty[0]&40&&e(9,s=bs(i.bounds,wn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,v,b,S,R,C,I,F,U,P,E]}class M0 extends me{constructor(t){super(),pe(this,t,R0,S0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function D0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R,C,I,M,F,U,P,E,T,A,O,D,L,$,B,N,k,X,j,K,V,ut,H,mt,Q,dt,gt,Et,Dt,Yt,jt,et,$e,ss;return Q=new Bi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),Q.$on("pointerdown",function(){Gt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Bi({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 Bi({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)}),jt=new Bi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),jt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("rect"),f=we(),p=z("rect"),g=we(),b=z("rect"),M=we(),F=z("rect"),T=we(),A=z("rect"),$=we(),B=z("rect"),j=we(),K=z("rect"),mt=we(),re(Q.$$.fragment),dt=we(),re(gt.$$.fragment),Et=we(),re(Dt.$$.fragment),Yt=we(),re(jt.$$.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(p,"class","a9s-outer"),x(p,"mask",`url(#${r[8]})`),x(p,"x",m=r[5].x),x(p,"y",y=r[5].y),x(p,"width",_=r[5].w),x(p,"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",E=r[5].w),x(A,"class","a9s-edge-handle a9s-edge-handle-right"),x(A,"x",O=r[5].x+r[5].w),x(A,"y",D=r[5].y),x(A,"height",L=r[5].h),x(A,"width",1),x(B,"class","a9s-edge-handle a9s-edge-handle-bottom"),x(B,"x",N=r[5].x),x(B,"y",k=r[5].y+r[5].h),x(B,"height",1),x(B,"width",X=r[5].w),x(K,"class","a9s-edge-handle a9s-edge-handle-left"),x(K,"x",V=r[5].x),x(K,"y",ut=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,f,G),nt(Y,p,G),nt(Y,g,G),nt(Y,b,G),nt(Y,M,G),nt(Y,F,G),nt(Y,T,G),nt(Y,A,G),nt(Y,$,G),nt(Y,B,G),nt(Y,j,G),nt(Y,K,G),nt(Y,mt,G),Jt(Q,Y,G),nt(Y,dt,G),Jt(gt,Y,G),nt(Y,Et,G),Jt(Dt,Y,G),nt(Y,Yt,G),Jt(jt,Y,G),et=!0,$e||(ss=[St(p,"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(B,"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(p,"x",m),(!et||G&32&&y!==(y=r[5].y))&&x(p,"y",y),(!et||G&32&&_!==(_=r[5].w))&&x(p,"width",_),(!et||G&32&&v!==(v=r[5].h))&&x(p,"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&&E!==(E=r[5].w))&&x(F,"width",E),(!et||G&32&&O!==(O=r[5].x+r[5].w))&&x(A,"x",O),(!et||G&32&&D!==(D=r[5].y))&&x(A,"y",D),(!et||G&32&&L!==(L=r[5].h))&&x(A,"height",L),(!et||G&32&&N!==(N=r[5].x))&&x(B,"x",N),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&x(B,"y",k),(!et||G&32&&X!==(X=r[5].w))&&x(B,"width",X),(!et||G&32&&V!==(V=r[5].x))&&x(K,"x",V),(!et||G&32&&ut!==(ut=r[5].y))&&x(K,"y",ut),(!et||G&32&&H!==(H=r[5].h))&&x(K,"height",H);const Cr={};G&32&&(Cr.x=r[5].x),G&32&&(Cr.y=r[5].y),G&8&&(Cr.scale=r[3]),Q.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x+r[5].w),G&32&&(Ir.y=r[5].y),G&8&&(Ir.scale=r[3]),gt.$set(Ir);const Pr={};G&32&&(Pr.x=r[5].x+r[5].w),G&32&&(Pr.y=r[5].y+r[5].h),G&8&&(Pr.scale=r[3]),Dt.$set(Pr);const Rr={};G&32&&(Rr.x=r[5].x),G&32&&(Rr.y=r[5].y+r[5].h),G&8&&(Rr.scale=r[3]),jt.$set(Rr)},i(Y){et||(lt(Q.$$.fragment,Y),lt(gt.$$.fragment,Y),lt(Dt.$$.fragment,Y),lt(jt.$$.fragment,Y),et=!0)},o(Y){yt(Q.$$.fragment,Y),yt(gt.$$.fragment,Y),yt(Dt.$$.fragment,Y),yt(jt.$$.fragment,Y),et=!1},d(Y){Y&&(rt(t),rt(f),rt(p),rt(g),rt(b),rt(M),rt(F),rt(T),rt(A),rt($),rt(B),rt(j),rt(K),rt(mt),rt(dt),rt(Et),rt(Yt)),te(Q,Y),te(gt,Y),te(Dt,Y),te(jt,Y),$e=!1,Me(ss)}}}function B0(r){let t,e;return t=new ua({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[D0,({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){Jt(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function O0(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 f(m){oe.call(this,r,m)}function p(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=bs(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,f,p]}class L0 extends me{constructor(t){super(),pe(this,t,O0,B0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Nc=Object.prototype.hasOwnProperty;function ma(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--&&ma(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Nc.call(r,e)&&++i&&!Nc.call(t,e)||!(e in t)||!ma(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const N0=12,F0=(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],f=(c[0]+d[0])/2,p=(c[1]+d[1])/2,m=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>N0/t;return{point:[f,p],visible:m,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function ga(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Fc(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function kc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Uc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function ya(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function _a(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Gc(r){let t,e,i,n;return{c(){t=z("circle"),x(t,"cx",e=r[29][0]),x(t,"cy",i=r[29][1]),x(t,"r",n=En/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=En/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function $c(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("mask"),e=z("rect"),a=z("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=En/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=En/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Hc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Bi({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){Jt(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(lt(t.$$.fragment,n),e=!0)},o(n){yt(t.$$.fragment,n),e=!1},d(n){te(t,n)}}}function Xc(r){let t,e,i=Ie(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Hc(Uc(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=Uc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=Hc(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),ti(n,o)}}}function Vc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v=r[6]!==void 0&&!r[7]&&Gc(_a(r)),g=r[6]!==void 0&&!r[7]&&$c(ya(r)),b=Ie(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Xc(kc(r,b,C));const R=C=>yt(S[C],1,1,()=>{S[C]=null});return{c(){t=z("g"),e=z("defs"),i=z("mask"),n=z("rect"),h=z("path"),v&&v.c(),g&&g.c(),u=z("path"),f=z("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(f,"class","a9s-inner"),x(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),x(f,"style",r[1]),x(f,"fill-rule","evenodd"),x(f,"d",p=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,f);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(f,"pointerup",r[13]),St(f,"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(_a(r),I):(v=Gc(_a(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(ya(r),I):(g=$c(ya(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(f,"style",r[1]),(!m||I[0]&32&&p!==(p=He(r[30])))&&x(f,"d",p),I[0]&268491048){b=Ie(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=kc(r,b,M);S[M]?(S[M].p(F,I),lt(S[M],1)):(S[M]=Xc(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(),ti(S,C),y=!1,Me(_)}}}function jc(r){let t,e;return t=new Cc({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){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function k0(r){let t,e,i,n=Ie(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Vc(Fc(r,n,l));const o=l=>yt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&jc(ga(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=Fc(l,n,c);s[c]?(s[c].p(u,h),lt(s[c],1)):(s[c]=Vc(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(ga(l),h),h[0]&192&&lt(a,1)):(a=jc(ga(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)),ti(s,l),a&&a.d(l)}}}function U0(r){let t,e;return t=new ua({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[k0,({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){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const G0=250,$0=1e3,En=4.5;function H0(r,t,e){let i,n,s;const o=Dr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[O,D]=h.elementToImage(A.offsetX,A.offsetY),L=k=>Math.pow(k[0]-O,2)+Math.pow(k[1]-D,2),$=ry(i).reduce((k,X)=>L(X)<L(k)?X:k),B=n.filter(k=>k.visible).reduce((k,X)=>L(X.point)<L(k.point)?X:k),N=Math.pow($0/c,2);L($)<N||L(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,O,D)=>L=>{if(!p||Ne||performance.now()-p>G0)return;const $=N=>N.polygon===A&&N.ring===O&&N.point===D,B=m.some($);L.metaKey||L.ctrlKey||L.shiftKey?B?e(8,m=m.filter(N=>!$(N))):e(8,m=[...m,{polygon:A,ring:O,point:D}]):B&&m.length>1?e(8,m=[{polygon:A,ring:O,point:D}]):B?e(8,m=[]):e(8,m=[{polygon:A,ring:O,point:D}]),g()},C=(A,O,D)=>{g();const L=A.geometry.polygons;let $;if(O==="SHAPE")$=L.map(B=>{const N=B.rings.map((X,j)=>({points:X.points.map((K,V)=>[K[0]+D[0],K[1]+D[1]])})),k=Ae(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,X]=O.split("-").map(j=>parseInt(j));$=L.map((j,K)=>{if(K===N){const V=j.rings.map((H,mt)=>mt===k?{points:H.points.map((Q,dt)=>dt===X?[Q[0]+D[0],Q[1]+D[1]]:Q)}:H),ut=Ae(V[0].points);return{rings:V,bounds:ut}}else return j})}return{...A,geometry:{polygons:$,bounds:ia($)}}},I=A=>async O=>{O.stopPropagation();const D=n[A],L=i.polygons.map((B,N)=>{if(N===D.elementIdx){const k=B.rings.map((j,K)=>K===D.ringIdx?{points:[...j.points.slice(0,D.pointIdx+1),D.point,...j.points.slice(D.pointIdx+1)]}:j),X=Ae(k[0].points);return{rings:k,bounds:X}}else return B});o("change",{...a,geometry:{polygons:L,bounds:ia(L)}}),await uc();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:O.clientX,clientY:O.clientY,pointerId:O.pointerId,pointerType:O.pointerType,isPrimary:O.isPrimary,buttons:O.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((O,D)=>{if(m.some(L=>L.polygon===D)){const L=O.rings.map((B,N)=>{const k=m.filter(X=>X.polygon===D&&X.ring===N);return k.length&&B.points.length-k.length>=3?{points:B.points.filter((X,j)=>!k.some(K=>K.point===j))}:B}),$=Ae(L[0].points);return{rings:L,bounds:$}}else return O});!ma(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:ia(A)}}),e(8,m=[]))};ei(()=>{if(Ne)return;const A=O=>{(O.key==="Delete"||O.key==="Backspace")&&(O.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,O,D,{polygon:L,ring:$,point:B})=>L===A&&$===O&&B===D;function P(A){oe.call(this,r,A)}function E(A){oe.call(this,r,A)}function T(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?[]:F0(i,c)),r.$$.dirty[0]&40&&e(9,s=bs(i.bounds,En/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,b,S,R,C,I,F,U,P,E,T]}class X0 extends me{constructor(t){super(),pe(this,t,H0,U0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Wc=new Map([[_t.RECTANGLE,L0],[_t.POLYGON,M0],[_t.MULTIPOLYGON,X0]]),va=r=>Wc.get(r.type),zc=(r,t)=>Wc.set(r,t);function V0(r,t,e){let i;const n=Dr();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=ii(s,a,{selected:!0,hovered:!0})),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 j0 extends me{constructor(t){super(),pe(this,t,V0,null,Kt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function W0(r,t,e){const i=Dr();let{drawingMode:n}=t,{target:s}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return ei(()=>{const c=s.closest("svg"),u=[],d=(f,p,m)=>{c==null||c.addEventListener(f,p,m),u.push(()=>c==null?void 0:c.removeEventListener(f,p,m))};return e(5,h=new o({target:s,props:{addEventListener:d,drawingMode:n,transform:a,viewportScale:l}})),h.$on("create",f=>i("create",f.detail)),()=>{u.forEach(f=>f()),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 z0 extends me{constructor(t){super(),pe(this,t,W0,null,Kt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Yc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("rect"),h=z("rect"),c=z("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 Y0(r){let t,e=r[0]&&Yc(r);return{c(){t=z("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=Yc(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 q0(r,t,e){let i;const n=Dr();let{addEventListener:s}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c,u,d,f,p,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,f=c[1]),e(3,p=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,f=Math.min(u[1],c[1])),e(3,p=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,f=c[1]),e(3,p=1),e(4,m=1))}else c&&(C>300||p*m>100?(R.stopPropagation(),g()):(e(0,c=void 0),u=void 0))},g=()=>{if(p*m>15){const S={type:_t.RECTANGLE,geometry:{bounds:{minX:d,minY:f,maxX:d+p,maxY:f+m},x:d,y:f,w:p,h:m}};n("create",S)}e(0,c=void 0),u=void 0};ei(()=>{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,f,p,m,i,b,s,o,a,l]}class K0 extends me{constructor(t){super(),pe(this,t,q0,Y0,Kt,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function ba(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function qc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m=r[1]&&Kc(r);return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("polygon"),c=z("polygon"),d=z("polygon"),m&&m.c(),p=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",f=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,p,_)},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&&f!==(f=y[19])&&x(d,"points",f),y[1]?m?m.p(y,_):(m=Kc(y),m.c(),m.m(p.parentNode,p)):m&&(m.d(1),m=null)},d(y){y&&(rt(t),rt(c),rt(d),rt(p)),m&&m.d(y)}}}function Kc(r){let t,e,i;return{c(){t=z("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]&&qc(ba(r));return{c(){t=z("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(ba(i),n):(e=qc(ba(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 Q0=20,J0=1500;function t_(r,t,e){let i,n,s;const o=Dr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:c=1}=t,u,d=[],f,p,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,f=U)}},_=R=>{const C=R;if(p&&clearTimeout(p),d.length>0){if(e(10,f=h.elementToImage(C.offsetX,C.offsetY)),d.length>2){const I=ms(f,d[0])*c;e(1,m=I<Q0)}C.pointerType==="touch"&&(p=setTimeout(()=>{g()},J0))}},v=R=>{const C=R;if(p&&clearTimeout(p),l==="click"){const I=C.timeStamp-u.timeStamp,M=ms([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,f=F)}else f&&d.push(f)}else{if(!f)return;if(d.length===1&&ms(d[0],f)<=4){e(0,d=[]),e(10,f=void 0);return}C.stopImmediatePropagation(),m?b():d.push(f)}},g=()=>{if(!f)return;const R=d.slice(0,-1);if(R.length<3)return;const C={type:_t.POLYGON,geometry:{bounds:Ae(d),points:R}};ra(C)>4&&(e(0,d=[]),e(10,f=void 0),o("create",C))},b=()=>{const R={type:_t.POLYGON,geometry:{bounds:Ae(d),points:[...d]}};e(0,d=[]),e(10,f=void 0),o("create",R)};ei(()=>{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=f?m?d:[...d,f]:[]),r.$$.dirty&516&&e(3,s=n.length>0?bs(Ae(n),2/c):void 0)},[d,m,n,s,i,S,a,l,h,c,f]}class e_ extends me{constructor(t){super(),pe(this,t,t_,Z0,Kt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const xa=new Map([["rectangle",{tool:K0}],["polygon",{tool:e_}]]),xs=()=>[...xa.keys()],ws=r=>xa.get(r),Zc=(r,t,e={})=>xa.set(r,{tool:t,opts:e});function r_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("ellipse"),n=z("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 i_(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=ii(n,o))},[n,i,a,l,h,c,s,o]}class n_ extends me{constructor(t){super(),pe(this,t,i_,r_,Kt,{annotation:0,geom:6,style:7})}}function s_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("line"),n=z("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 o_(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=ii(n,o))},[n,i,l,h,c,u,s,o]}class a_ extends me{constructor(t){super(),pe(this,t,o_,s_,Kt,{annotation:0,geom:6,style:7})}}function Qc(r,t,e){const i=r.slice();return i[5]=t[e],i}function Jc(r){let t,e,i;return{c(){t=z("path"),i=z("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 l_(r){let t,e,i=Ie(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=Jc(Qc(r,i,s));return{c(){t=z("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=Qc(s,i,a);n[a]?n[a].p(l,o):(n[a]=Jc(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),ti(n,s)}}}function h_(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=ii(n,o))},[n,i,a,s,o]}class c_ extends me{constructor(t){super(),pe(this,t,h_,l_,Kt,{annotation:0,geom:3,style:4})}}function u_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("polygon"),n=z("polygon"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"points",r[2].map(d_).join(" ")),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"points",r[2].map(f_).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 d_=r=>r.join(","),f_=r=>r.join(",");function p_(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=ii(n,o))},[n,i,a,s,o]}class m_ extends me{constructor(t){super(),pe(this,t,p_,u_,Kt,{annotation:0,geom:3,style:4})}}function g_(r){let t,e,i,n,s,o,a;return{c(){t=z("g"),e=z("path"),s=z("path"),x(e,"class",i=Ci(`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=Ci(`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=Ci(`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=Ci(`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 y_(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=ii(o,l)),r.$$.dirty&16&&e(2,n=sa(a)),r.$$.dirty&16&&e(1,s=a.closed?"closed":"open")},[o,s,n,i,a,l]}class __ extends me{constructor(t){super(),pe(this,t,y_,g_,Kt,{annotation:0,geom:4,style:5})}}function v_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("rect"),n=z("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 b_(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=ii(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 x_ extends me{constructor(t){super(),pe(this,t,b_,v_,Kt,{annotation:0,geom:6,style:7})}}const w_=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]}}),E_=250,T_=(r,t)=>{const e=Dr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<E_){const{x:s,y:o}=tu(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})}}}},tu=(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 eu(r,t,e){const i=r.slice();return i[39]=t[e],i}function ru(r,t,e){const i=r.slice();return i[42]=t[e],i}function wa(r){const t=r.slice(),e=t[42].target.selector;return t[45]=e,t}function iu(r){let t=r[42],e,i,n=nu(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=nu(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 A_(r){let t,e;return t=new a_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function S_(r){let t,e;return t=new __({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function C_(r){let t,e;return t=new c_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function I_(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){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function P_(r){let t,e;return t=new x_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function R_(r){var t;let e,i;return e=new n_({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){re(e.$$.fragment)},m(n,s){Jt(e,n,s),i=!0},p(n,s){var o;const a={};s[0]&131072&&(a.annotation=n[42]),s[0]&131072&&(a.geom=(o=n[45])==null?void 0:o.geometry),s[0]&2&&(a.style=n[1]),e.$set(a)},i(n){i||(lt(e.$$.fragment,n),i=!0)},o(n){yt(e.$$.fragment,n),i=!1},d(n){te(e,n)}}}function nu(r){let t,e,i,n;const s=[R_,P_,I_,C_,S_,A_],o=[];function a(l,h){var c,u,d,f,p,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:((f=l[45])==null?void 0:f.type)===_t.MULTIPOLYGON?3:((p=l[45])==null?void 0:p.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 su(r){let t=Le(r[42])&&!r[10](r[42]),e,i,n=t&&iu(wa(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(wa(s),o),o[0]&132096&&lt(n,1)):(n=iu(wa(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 ou(r){let t,e,i,n;const s=[D_,M_],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 M_(r){let t=`${r[2]}-${r[7]}`,e,i,n=au(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=au(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 D_(r){let t,e,i=Ie(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=hu(eu(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=eu(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=hu(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),ti(n,o)}}}function au(r){let t,e;return t=new z0({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){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&256&&(s.target=i[8]),n[0]&32768&&(s.tool=i[15]),n[0]&16384&&(s.drawingMode=i[14]),n[0]&8192&&(s.transform=i[13]),n[0]&262144&&(s.viewportScale=i[18]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function lu(r){let t,e;return t=new j0({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){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&256&&(s.target=r[8]),n[0]&64&&(s.editor=r[39].editor),n[0]&64&&(s.annotation=r[39].annotation),n[0]&2&&(s.style=r[1]),n[0]&8192&&(s.transform=r[13]),n[0]&262144&&(s.viewportScale=r[18]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function hu(r){let t=r[39].annotation.id,e,i,n=lu(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=lu(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 B_(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]=su(ru(r,a,u));const h=u=>yt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&ou(r);return{c(){t=z("svg"),e=z("g");for(let u=0;u<l.length;u+=1)l[u].c();i=z("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 f=0;f<l.length;f+=1)l[f]&&l[f].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 f;for(f=0;f<a.length;f+=1){const p=ru(r,a,f);l[f]?(l[f].p(p,d),lt(l[f],1)):(l[f]=su(p),l[f].c(),lt(l[f],1),l[f].m(e,null))}for(Ee(),f=a.length;f<l.length;f+=1)h(f);Te()}r[8]?c?(c.p(r,d),d[0]&256&&lt(c,1)):(c=ou(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),ti(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,Me(o)}}}function O_(r,t,e){let i,n,s,o,a,l,h,c,u,d,f,p,m=Rt,y=()=>(m(),m=ic(A,H=>e(18,p=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=xs()[0]}=t,{user:C}=t,{visible:I=!0}=t,M=0;const F=()=>e(7,M+=1),U=()=>R,P=()=>_;let E,T,A;ei(()=>y(e(9,A=f0(v,T))));const{hover:O,selection:D,store:L}=b;Zo(r,O,H=>e(16,u=H)),Zo(r,D,H=>e(33,d=H)),Zo(r,L,H=>e(17,f=H));let $,B;const N=H=>{$&&L.unobserve($);const mt=H.filter(({editable:Q})=>Q).map(({id:Q})=>Q);mt.length>0?(e(5,B=mt.map(Q=>L.getAnnotation(Q)).filter(Q=>Q&&Le(Q))),$=Q=>{const{updated:dt}=Q.changes;e(5,B=dt==null?void 0:dt.map(gt=>gt.newValue))},L.observe($,{annotations:mt})):e(5,B=void 0)},k=H=>{const mt=vc(),Q={id:mt,bodies:[],target:{annotation:mt,selector:H.detail,creator:C,created:new Date}};L.addAnnotation(Q),D.setSelected(Q.id)},X=H=>mt=>{var Q;const{target:dt}=H,gt=10*60*1e3,Et=((Q=dt.creator)==null?void 0:Q.id)!==C.id||!dt.created||new Date().getTime()-dt.created.getTime()>gt;L.updateTarget({...dt,selector:mt.detail,created:Et?dt.created:new Date,updated:Et?new Date:void 0,updatedBy:Et?C:void 0})},j=H=>{const{x:mt,y:Q}=tu(H,T),dt=L.getAt(mt,Q,void 0,2);dt?u!==dt.id&&O.set(dt.id):O.set(void 0)},K=H=>Le(H);function V(H){us[H?"unshift":"push"](()=>{E=H,e(8,E)})}function ut(H){us[H?"unshift":"push"](()=>{T=H,e(4,T)})}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}=ws(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=w_(T)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=T_(T,L),a,(e(11,l),e(4,T))),r.$$.dirty[1]&4&&N(d.selected),r.$$.dirty[0]&32&&e(6,h=B?B.map(H=>({annotation:H,editor:va(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,T,B,h,M,E,A,c,l,a,o,s,i,u,f,p,O,D,L,k,X,j,v,g,b,C,F,U,P,n,d,K,V,ut]}class L_ extends me{constructor(t){super(),pe(this,t,O_,B_,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 cu(r,t,e=0,i=r.length-1,n=N_){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),f=Math.max(e,Math.floor(t-h*u/l+d)),p=Math.min(i,Math.floor(t+(l-h)*u/l+d));cu(r,t,f,p,n)}const s=r[t];let o=e,a=i;for(Tn(r,e,t),n(r[i],s)>0&&Tn(r,e,i);o<a;){for(Tn(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?Tn(r,e,a):(a++,Tn(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function Tn(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function N_(r,t){return r<t?-1:r>t?1:0}class F_{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(!Ts(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;Ts(t,l)&&(e.leaf?i.push(a):Ta(t,l)?this._all(a,i):s.push(a))}e=s.pop()}return i}collides(t){let e=this.data;if(!Ts(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(Ts(t,o)){if(e.leaf||Ta(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=Li([]),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=k_(t,i.children,e);if(c!==-1)return i.children.splice(c,1),s.push(i),this._condense(s),this}!h&&!i.leaf&&Ta(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=Li(t.slice(e,i+1)),Oi(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=Li([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));uu(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);uu(t,c,u,l,this.compareMinY);for(let d=c;d<=u;d+=l){const f=Math.min(d+l-1,u);a.children.push(this._build(t,d,f,n-1))}}return Oi(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=Ea(h),u=$_(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),Sn(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=Li(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Oi(i,this.toBBox),Oi(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Li([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Oi(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=An(t,0,a,this.toBBox),h=An(t,a,i,this.toBBox),c=H_(l,h),u=Ea(l)+Ea(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:U_,s=t.leaf?this.compareMinY:G_,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=An(t,0,e,s),a=An(t,i-e,i,s);let l=Es(o)+Es(a);for(let h=e;h<i-e;h++){const c=t.children[h];Sn(o,t.leaf?s(c):c),l+=Es(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];Sn(a,t.leaf?s(c):c),l+=Es(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)Sn(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():Oi(t[e],this.toBBox)}}function k_(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 Oi(r,t){An(r,0,r.children.length,t,r)}function An(r,t,e,i,n){n||(n=Li(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];Sn(n,r.leaf?i(o):o)}return n}function Sn(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 U_(r,t){return r.minX-t.minX}function G_(r,t){return r.minY-t.minY}function Ea(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Es(r){return r.maxX-r.minX+(r.maxY-r.minY)}function $_(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 H_(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 Ta(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function Ts(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Li(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function uu(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;cu(r,o,t,e,n),s.push(t,o,o,e)}}const X_=()=>{const r=new F_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!gs(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(!gs(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||Zg(c.selector,o,a,l));return h.length>0?(h.sort((c,u)=>ra(c.selector)-ra(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(gs(c)){const{minX:u,minY:d,maxX:f,maxY:p}=c.selector.geometry.bounds;return[...h,{minX:u,minY:d,maxX:f,maxY:p,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)}}},V_=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}}),du=r=>{const t=Xy(),e=X_(),i=Iy(t,r.userSelectAction,r.adapter),n=Cy(t),s=zy();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}},j_=r=>{const t=du(r);return{...t,store:V_(t.store)}},W_=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},fu=r=>{const t=W_(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},pu=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?fu(r):e),mu=(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}),gu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,yu=(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=()=>{gu?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return gu?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},z_=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=mu(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:xc.EDIT,theme:"light"}),n=j_(i),{selection:s,store:o}=n,a=Wy(o,i.initialHistory),l=Yy(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=yu(a);let u=n0();pu(e,h,i.theme);const d=new L_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",E=>{const{originalEvent:T,annotation:A}=E.detail;A?s.userSelect(A.id,T):s.isEmpty()||s.clear()});const f=Ky(n,a,i.adapter),p=()=>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=(E,T,A)=>Zc(E,T,A),b=(E,T)=>zc(E,T),S=E=>{if(!ws(E))throw`No drawing tool named ${E}`;d.$set({toolName:E})},R=E=>d.$set({drawingEnabled:E}),C=E=>d.$set({preferredDrawingMode:E}),I=E=>{console.warn("Filter not implemented yet")},M=E=>d.$set({style:E}),F=E=>pu(e,h,E),U=E=>{u=E,d.$set({user:E})},P=E=>d.$set({visible:E});return{...f,cancelDrawing:p,destroy:m,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:xs,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:b,setDrawingEnabled:R,setDrawingMode:C,setDrawingTool:S,setFilter:I,setStyle:M,setTheme:F,setUser:U,setVisible:P,element:h,state:n}};function Ft(){}function Aa(r,t){for(const e in t)r[e]=t[e];return r}function _u(r){return r()}function vu(){return Object.create(null)}function Fe(r){r.forEach(_u)}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 Y_(r){return Object.keys(r).length===0}function q_(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 Cn(r,t,e){r.$$.on_destroy.push(q_(t,e))}function bu(r,t,e,i){if(r){const n=xu(r,t,e,i);return r[0](n)}}function xu(r,t,e,i){return r[1]&&i?Aa(e.ctx.slice(),r[1](i(t))):e.ctx}function wu(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 Eu(r,t,e,i,n,s){if(n){const o=xu(t,e,i,s);r.p(o,n)}}function Tu(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 Au(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Su(r){return r??""}const Sa=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 Lr(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 Ca(r){return document.createTextNode(r)}function Se(){return Ca(" ")}function Pe(){return Ca("")}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 K_(r){return Array.from(r.childNodes)}function Z_(r,t){t=""+t,r.data!==t&&(r.data=t)}function Nr(r,t,e){r.classList.toggle(t,!!e)}function Q_(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let In;function Pn(r){In=r}function Ia(){if(!In)throw new Error("Function called outside component initialization");return In}function ni(r){Ia().$$.on_mount.push(r)}function J_(r){Ia().$$.on_destroy.push(r)}function Ni(){const r=Ia();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=Q_(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 Fi=[],As=[];let ki=[];const Cu=[],Iu=Promise.resolve();let Pa=!1;function Pu(){Pa||(Pa=!0,Iu.then(Mu))}function Ru(){return Pu(),Iu}function Ra(r){ki.push(r)}const Ma=new Set;let Ui=0;function Mu(){if(Ui!==0)return;const r=In;do{try{for(;Ui<Fi.length;){const t=Fi[Ui];Ui++,Pn(t),tv(t.$$)}}catch(t){throw Fi.length=0,Ui=0,t}for(Pn(null),Fi.length=0,Ui=0;As.length;)As.pop()();for(let t=0;t<ki.length;t+=1){const e=ki[t];Ma.has(e)||(Ma.add(e),e())}ki.length=0}while(Fi.length);for(;Cu.length;)Cu.pop()();Pa=!1,Ma.clear(),Pn(r)}function tv(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(Ra)}}function ev(r){const t=[],e=[];ki.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),ki=t}const Ss=new Set;let si;function le(){si={r:0,c:[],p:si}}function he(){si.r||Fe(si.c),si=si.p}function q(r,t){r&&r.i&&(Ss.delete(r),r.i(t))}function at(r,t,e,i){if(r&&r.o){if(Ss.has(r))return;Ss.add(r),si.c.push(()=>{Ss.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),Ra(()=>{const s=r.$$.on_mount.map(_u).filter(Zt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Fe(s),r.$$.on_mount=[]}),n.forEach(Ra)}function Ot(r,t){const e=r.$$;e.fragment!==null&&(ev(e.after_update),Fe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function rv(r,t){r.$$.dirty[0]===-1&&(Fi.push(r),Pu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Wt(r,t,e,i,n,s,o=null,a=[-1]){const l=In;Pn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Ft,not_equal:n,bound:vu(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:vu(),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,...f)=>{const p=f.length?f[0]:d;return h.ctx&&n(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&rv(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=K_(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),Mu()}Pn(l)}class zt{constructor(){jh(this,"$$");jh(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&&!Y_(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const iv="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(iv);var tr=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(tr||{}),Rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Da(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function nv(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 Du={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,f=h.y-u;if(d!==0||f!==0){var p=((a.x-c)*d+(a.y-u)*f)/(d*d+f*f);p>1?(c=h.x,u=h.y):p>0&&(c+=d*p,u+=f*p)}return d=a.x-c,f=a.y-u,d*d+f*f}function i(a,l){for(var h=a[0],c=[h],u,d=1,f=a.length;d<f;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,f,p=l+1;p<h;p++){var m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}d>c&&(f-l>1&&n(a,l,f,c,u),u.push(a[f]),h-f>1&&n(a,f,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})()})(Du);var sv=Du.exports;const ov=Da(sv),Gi=(r,t)=>t,er=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}},Cs=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)},Is=(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},av=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},Bu=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return ov(e,t,!0).map(i=>[i.x,i.y])},lv=(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))},hv={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,f=h*c-l*u;return d*d/(s*s)+f*f/(o*o)<=1}};Gi(tr.ELLIPSE,hv);const cv={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=lv([n,s],[o,a]);return l/h<=i}};Gi(tr.LINE,cv);const uv={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=Cs(n.points),a=s.reduce((l,h)=>l+Cs(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(Is(s.points,t,e)){let a=!1;for(const l of o)if(Is(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Ps=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return er(t)},$i=r=>r.rings.map(e=>av(e.points)).join(" "),dv=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),fv=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=Bu(a.points,t);return{...a,points:l}}),o=er(s[0].points);return{...n,rings:s,bounds:o}}),i=Ps(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Gi(tr.MULTIPOLYGON,uv);const pv={area:r=>{const t=r.geometry.points;return Cs(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Is(i,t,e)}},mv=(r,t=1)=>{const e=Bu(r.geometry.points,t),i=er(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Gi(tr.POLYGON,pv);const gv={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Ou(t.points,t.closed);return Cs(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Ou(n.points,n.closed);return Is(s,t,e)}else return yv(n,[t,e],i)}},Ou=(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=Lu(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},Lu=(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},yv=(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=Lu(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(Nu(t,a[l],a[l+1])<=e)return!0}else if(Nu(t,n.point,s.point)<=e)return!0}return!1},Nu=(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};Gi(tr.POLYLINE,gv);const _v={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};Gi(tr.RECTANGLE,_v);const _e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function vv(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 Ba;const bv=new Uint8Array(16);function xv(){if(!Ba){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ba=crypto.getRandomValues.bind(crypto)}return Ba(bv)}const Fu={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function wv(r,t,e){var n;r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??xv();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,vv(i)}function Ev(r,t,e){return Fu.randomUUID&&!r?Fu.randomUUID():wv(r)}const Tv=(r,t,e)=>{const i=typeof t=="function"?t(r,e):t;if(i){const{fill:n,fillOpacity:s,stroke:o,strokeWidth:a,strokeOpacity:l}=i;let h="";return n&&(h+=`fill:${n};`),s||s===0?h+=`fill-opacity:${s};`:n&&(h+="fill-opacity:0.25;"),o&&(h+=`stroke:${o};`,h+=`stroke-width:${a||"1"};`,h+=`stroke-opacity:${l||"1"};`),h}},Oa=(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}},Fr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Av=r=>({}),ku=r=>({grab:r[0]});function Sv(r){let t,e,i,n;const s=r[8].default,o=bu(s,r,r[7],ku);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)&&Eu(o,s,a,a[7],e?wu(s,a[7],l,Av):Tu(a[7]),ku)},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 Cv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Ni();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const f=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",_)},p=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)},[f,p,m,o,a,l,h,n,i]}class La extends zt{constructor(t){super(),Wt(this,t,Cv,Sv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function Iv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Uu(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=Su(`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=Uu(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Su(`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 Pv(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"),Nr(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&&Nr(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 Uu(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 Rv(r){let t;function e(s,o){return Fr?Pv:Iv}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 Mv(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 f(g){ae.call(this,r,g)}function p(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=Aa(Aa({},t),Au(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=Au(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,m,y,_,v]}class Hi extends zt{constructor(t){super(),Wt(this,t,Mv,Rv,Ut,{x:0,y:1,scale:2,selected:3})}}function Dv(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 Bv(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 Ov(r){let t;function e(s,o){return Fr?Bv:Dv}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 Lv(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 Gu extends zt{constructor(t){super(),Wt(this,t,Lv,Ov,Ut,{x:0,y:1,scale:4})}}function Na(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function $u(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Fa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function ka(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Hu(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=Mn/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=Mn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function Xu(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=Mn/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=Mn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function Vu(r){let t,e;return t=new Hi({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 ju(r){let t,e;return t=new Gu({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 Nv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&Hu(ka(r)),C=r[6]!==void 0&&!r[7]&&Xu(Fa(r)),I=xe(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Vu($u(r,I,P));const F=P=>at(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&ju(Na(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"),f=Se(),p=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(Wu).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(zu).join(" ")),w(p,"class","a9s-inner a9s-shape-handle"),w(p,"mask",`url(#${r[19]}-inner)`),w(p,"style",r[1]),w(p,"points",m=r[5].points.map(Yu).join(" "))},m(P,E){ot(P,t,E),Ct(t,e),Ct(e,i),Ct(e,l),R&&R.m(e,null),C&&C.m(t,null),ot(P,c,E),ot(P,u,E),ot(P,f,E),ot(P,p,E),ot(P,y,E);for(let T=0;T<M.length;T+=1)M[T]&&M[T].m(P,E);ot(P,_,E),U&&U.m(P,E),ot(P,v,E),g=!0,b||(S=[Pt(u,"pointerup",r[14]),Pt(u,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(p,"pointermove",r[13]),Pt(p,"pointerup",r[14]),Pt(p,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,E){if(r=P,(!g||E[0]&512&&n!==(n=r[9].x))&&w(i,"x",n),(!g||E[0]&512&&s!==(s=r[9].y))&&w(i,"y",s),(!g||E[0]&512&&o!==(o=r[9].w))&&w(i,"width",o),(!g||E[0]&512&&a!==(a=r[9].h))&&w(i,"height",a),(!g||E[0]&32&&h!==(h=r[5].points.map(Wu).join(" ")))&&w(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(ka(r),E):(R=Hu(ka(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(Fa(r),E):(C=Xu(Fa(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||E[0]&32&&d!==(d=r[5].points.map(zu).join(" ")))&&w(u,"points",d),(!g||E[0]&2)&&w(p,"style",r[1]),(!g||E[0]&32&&m!==(m=r[5].points.map(Yu).join(" ")))&&w(p,"points",m),E[0]&134322472){I=xe(r[5].points);let T;for(T=0;T<I.length;T+=1){const A=$u(r,I,T);M[T]?(M[T].p(A,E),q(M[T],1)):(M[T]=Vu(A),M[T].c(),q(M[T],1),M[T].m(_.parentNode,_))}for(le(),T=I.length;T<M.length;T+=1)F(T);he()}r[6]!==void 0&&!r[7]?U?(U.p(Na(r),E),E[0]&192&&q(U,1)):(U=ju(Na(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 E=0;E<I.length;E+=1)q(M[E]);q(U),g=!0}},o(P){M=M.filter(Boolean);for(let E=0;E<M.length;E+=1)at(M[E]);at(U),g=!1},d(P){P&&(st(t),st(c),st(u),st(f),st(p),st(y),st(_),st(v)),R&&R.d(),C&&C.d(),Lr(M,P),U&&U.d(P),b=!1,Fe(S)}}}function Fv(r){let t,e;return t=new La({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[Nv,({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 kv=250,Uv=1e3,Gv=12,Mn=4.5,Wu=r=>r.join(","),zu=r=>r.join(","),Yu=r=>r.join(",");function $v(r,t,e){let i,n,s;const o=Ni();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=T=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[A,O]=h.elementToImage(T.offsetX,T.offsetY),D=k=>Math.pow(k[0]-A,2)+Math.pow(k[1]-O,2),L=i.points.reduce((k,X)=>D(X)<D(k)?X:k),$=n.filter(k=>k.visible).reduce((k,X)=>D(X.point)<D(k.point)?X:k),B=Math.pow(Uv/c,2);D(L)<B||D($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=T=>{e(7,f=!0),T.preventDefault(),T.stopPropagation(),p=performance.now()},R=T=>A=>{if(!p||Fr||performance.now()-p>kv)return;const O=m.includes(T);A.metaKey||A.ctrlKey||A.shiftKey?O?e(8,m=m.filter(D=>D!==T)):e(8,m=[...m,T]):O&&m.length>1?e(8,m=[T]):O?e(8,m=[]):e(8,m=[T]),g()},C=(T,A,O)=>{g();let D;const L=T.geometry;m.length>1?D=L.points.map(([B,N],k)=>m.includes(k)?[B+O[0],N+O[1]]:[B,N]):A==="SHAPE"?D=L.points.map(([B,N])=>[B+O[0],N+O[1]]):D=L.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+O[0],N+O[1]]:[B,N]);const $=er(D);return{...T,geometry:{points:D,bounds:$}}},I=T=>async A=>{A.stopPropagation();const O=[...i.points.slice(0,T+1),n[T].point,...i.points.slice(T+1)],D=er(O);o("change",{...a,geometry:{points:O,bounds:D}}),await Ru();const L=[...document.querySelectorAll(".a9s-handle")][T+1];if(L!=null&&L.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});L.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const T=i.points.filter((O,D)=>!m.includes(D)),A=er(T);o("change",{...a,geometry:{points:T,bounds:A}}),e(8,m=[])};ni(()=>{if(Fr)return;const T=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",T),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",T)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(T){ae.call(this,r,T)}function P(T){ae.call(this,r,T)}function E(T){ae.call(this,r,T)}return r.$$set=T=>{"shape"in T&&e(0,a=T.shape),"computedStyle"in T&&e(1,l=T.computedStyle),"transform"in T&&e(2,h=T.transform),"viewportScale"in T&&e(3,c=T.viewportScale),"svgEl"in T&&e(4,u=T.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Fr?[]:i.points.map((T,A)=>{const O=A===i.points.length-1?i.points[0]:i.points[A+1],D=(T[0]+O[0])/2,L=(T[1]+O[1])/2,B=Math.sqrt(Math.pow(O[0]-D,2)+Math.pow(O[1]-L,2))>Gv/c;return{point:[D,L],visible:B}})),r.$$.dirty[0]&40&&e(9,s=Oa(i.bounds,Mn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,v,b,S,R,C,I,F,U,P,E]}class Hv extends zt{constructor(t){super(),Wt(this,t,$v,Fv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Xv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R,C,I,M,F,U,P,E,T,A,O,D,L,$,B,N,k,X,j,K,V,ut,H,mt,Q,dt,gt,Et,Dt,Yt,jt,et,$e,ss;return Q=new Hi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),Q.$on("pointerdown",function(){Zt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Hi({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 Hi({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)}),jt=new Hi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),jt.$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"),f=Se(),p=it("rect"),g=Se(),b=it("rect"),M=Se(),F=it("rect"),T=Se(),A=it("rect"),$=Se(),B=it("rect"),j=Se(),K=it("rect"),mt=Se(),Lt(Q.$$.fragment),dt=Se(),Lt(gt.$$.fragment),Et=Se(),Lt(Dt.$$.fragment),Yt=Se(),Lt(jt.$$.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(p,"class","a9s-outer"),w(p,"mask",`url(#${r[8]})`),w(p,"x",m=r[5].x),w(p,"y",y=r[5].y),w(p,"width",_=r[5].w),w(p,"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",E=r[5].w),w(A,"class","a9s-edge-handle a9s-edge-handle-right"),w(A,"x",O=r[5].x+r[5].w),w(A,"y",D=r[5].y),w(A,"height",L=r[5].h),w(A,"width",1),w(B,"class","a9s-edge-handle a9s-edge-handle-bottom"),w(B,"x",N=r[5].x),w(B,"y",k=r[5].y+r[5].h),w(B,"height",1),w(B,"width",X=r[5].w),w(K,"class","a9s-edge-handle a9s-edge-handle-left"),w(K,"x",V=r[5].x),w(K,"y",ut=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,f,G),ot(Y,p,G),ot(Y,g,G),ot(Y,b,G),ot(Y,M,G),ot(Y,F,G),ot(Y,T,G),ot(Y,A,G),ot(Y,$,G),ot(Y,B,G),ot(Y,j,G),ot(Y,K,G),ot(Y,mt,G),Bt(Q,Y,G),ot(Y,dt,G),Bt(gt,Y,G),ot(Y,Et,G),Bt(Dt,Y,G),ot(Y,Yt,G),Bt(jt,Y,G),et=!0,$e||(ss=[Pt(p,"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(B,"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(p,"x",m),(!et||G&32&&y!==(y=r[5].y))&&w(p,"y",y),(!et||G&32&&_!==(_=r[5].w))&&w(p,"width",_),(!et||G&32&&v!==(v=r[5].h))&&w(p,"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&&E!==(E=r[5].w))&&w(F,"width",E),(!et||G&32&&O!==(O=r[5].x+r[5].w))&&w(A,"x",O),(!et||G&32&&D!==(D=r[5].y))&&w(A,"y",D),(!et||G&32&&L!==(L=r[5].h))&&w(A,"height",L),(!et||G&32&&N!==(N=r[5].x))&&w(B,"x",N),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&w(B,"y",k),(!et||G&32&&X!==(X=r[5].w))&&w(B,"width",X),(!et||G&32&&V!==(V=r[5].x))&&w(K,"x",V),(!et||G&32&&ut!==(ut=r[5].y))&&w(K,"y",ut),(!et||G&32&&H!==(H=r[5].h))&&w(K,"height",H);const Cr={};G&32&&(Cr.x=r[5].x),G&32&&(Cr.y=r[5].y),G&8&&(Cr.scale=r[3]),Q.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x+r[5].w),G&32&&(Ir.y=r[5].y),G&8&&(Ir.scale=r[3]),gt.$set(Ir);const Pr={};G&32&&(Pr.x=r[5].x+r[5].w),G&32&&(Pr.y=r[5].y+r[5].h),G&8&&(Pr.scale=r[3]),Dt.$set(Pr);const Rr={};G&32&&(Rr.x=r[5].x),G&32&&(Rr.y=r[5].y+r[5].h),G&8&&(Rr.scale=r[3]),jt.$set(Rr)},i(Y){et||(q(Q.$$.fragment,Y),q(gt.$$.fragment,Y),q(Dt.$$.fragment,Y),q(jt.$$.fragment,Y),et=!0)},o(Y){at(Q.$$.fragment,Y),at(gt.$$.fragment,Y),at(Dt.$$.fragment,Y),at(jt.$$.fragment,Y),et=!1},d(Y){Y&&(st(t),st(f),st(p),st(g),st(b),st(M),st(F),st(T),st(A),st($),st(B),st(j),st(K),st(mt),st(dt),st(Et),st(Yt)),Ot(Q,Y),Ot(gt,Y),Ot(Dt,Y),Ot(jt,Y),$e=!1,Fe(ss)}}}function Vv(r){let t,e;return t=new La({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[Xv,({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 jv(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 f(m){ae.call(this,r,m)}function p(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=Oa(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,f,p]}class Wv extends zt{constructor(t){super(),Wt(this,t,jv,Vv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var qu=Object.prototype.hasOwnProperty;function Ua(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--&&Ua(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(qu.call(r,e)&&++i&&!qu.call(t,e)||!(e in t)||!Ua(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const zv=12,Yv=(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],f=(c[0]+d[0])/2,p=(c[1]+d[1])/2,y=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>zv/t;return{point:[f,p],visible:y,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function Ga(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ku(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Zu(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Qu(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function $a(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ha(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ju(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=Dn/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=Dn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function td(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=Dn/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=Dn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function ed(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Hi({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 rd(r){let t,e,i=xe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=ed(Qu(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=Qu(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=ed(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),Lr(n,o)}}}function id(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v=r[6]!==void 0&&!r[7]&&Ju(Ha(r)),g=r[6]!==void 0&&!r[7]&&td($a(r)),b=xe(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=rd(Zu(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"),f=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=$i(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=$i(r[30])),w(f,"class","a9s-inner"),w(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),w(f,"style",r[1]),w(f,"fill-rule","evenodd"),w(f,"d",p=$i(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,f);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(f,"pointerup",r[13]),Pt(f,"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=$i(r[30])))&&w(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(Ha(r),I):(v=Ju(Ha(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p($a(r),I):(g=td($a(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=$i(r[30])))&&w(u,"d",d),(!m||I[0]&2)&&w(f,"style",r[1]),(!m||I[0]&32&&p!==(p=$i(r[30])))&&w(f,"d",p),I[0]&268491048){b=xe(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Zu(r,b,M);S[M]?(S[M].p(F,I),q(S[M],1)):(S[M]=rd(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(),Lr(S,C),y=!1,Fe(_)}}}function nd(r){let t,e;return t=new Gu({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 qv(r){let t,e,i,n=xe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=id(Ku(r,n,l));const o=l=>at(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&nd(Ga(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=Ku(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=id(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(Ga(l),h),h[0]&192&&q(a,1)):(a=nd(Ga(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)),Lr(s,l),a&&a.d(l)}}}function Kv(r){let t,e;return t=new La({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[qv,({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 Zv=250,Qv=1e3,Dn=4.5;function Jv(r,t,e){let i,n,s;const o=Ni();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(m.length>0||!n.some(X=>X.visible)){e(6,d=void 0);return}const[O,D]=h.elementToImage(A.offsetX,A.offsetY),L=X=>Math.pow(X[0]-O,2)+Math.pow(X[1]-D,2),$=dv(i).reduce((X,j)=>L(j)<L(X)?j:X),B=n.filter(X=>X.visible).reduce((X,j)=>L(j.point)<L(X.point)?j:X),N=Math.pow(Qv/c,2);L($)<N||L(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,O,D)=>L=>{if(!p||Fr||performance.now()-p>Zv)return;const $=N=>N.polygon===A&&N.ring===O&&N.point===D,B=m.some($);L.metaKey||L.ctrlKey||L.shiftKey?B?e(8,m=m.filter(N=>!$(N))):e(8,m=[...m,{polygon:A,ring:O,point:D}]):B&&m.length>1?e(8,m=[{polygon:A,ring:O,point:D}]):B?e(8,m=[]):e(8,m=[{polygon:A,ring:O,point:D}]),g()},C=(A,O,D)=>{g();const L=A.geometry.polygons;let $;if(O==="SHAPE")$=L.map(B=>{const N=B.rings.map((X,j)=>({points:X.points.map((V,ut)=>[V[0]+D[0],V[1]+D[1]])})),k=er(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,X]=O.split("-").map(j=>parseInt(j));$=L.map((j,K)=>{if(K===N){const V=j.rings.map((H,mt)=>mt===k?{points:H.points.map((dt,gt)=>gt===X?[dt[0]+D[0],dt[1]+D[1]]:dt)}:H),ut=er(V[0].points);return{rings:V,bounds:ut}}else return j})}return{...A,geometry:{polygons:$,bounds:Ps($)}}},I=A=>async O=>{O.stopPropagation();const D=n[A],L=i.polygons.map((B,N)=>{if(N===D.elementIdx){const k=B.rings.map((j,K)=>K===D.ringIdx?{points:[...j.points.slice(0,D.pointIdx+1),D.point,...j.points.slice(D.pointIdx+1)]}:j),X=er(k[0].points);return{rings:k,bounds:X}}else return B});o("change",{...a,geometry:{polygons:L,bounds:Ps(L)}}),await Ru();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:O.clientX,clientY:O.clientY,pointerId:O.pointerId,pointerType:O.pointerType,isPrimary:O.isPrimary,buttons:O.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((D,L)=>{if(m.some(B=>B.polygon===L)){const B=D.rings.map((k,X)=>{const j=m.filter(K=>K.polygon===L&&K.ring===X);return j.length&&k.points.length-j.length>=3?{points:k.points.filter((V,ut)=>!j.some(H=>H.point===ut))}:k}),N=er(B[0].points);return{rings:B,bounds:N}}else return D});!Ua(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:Ps(A)}}),e(8,m=[]))};ni(()=>{if(Fr)return;const A=O=>{(O.key==="Delete"||O.key==="Backspace")&&(O.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,O,D,{polygon:L,ring:$,point:B})=>L===A&&$===O&&B===D;function P(A){ae.call(this,r,A)}function E(A){ae.call(this,r,A)}function T(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=Fr?[]:Yv(i,c)),r.$$.dirty[0]&40&&e(9,s=Oa(i.bounds,Dn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,b,S,R,C,I,F,U,P,E,T]}class t1 extends zt{constructor(t){super(),Wt(this,t,Jv,Kv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}tr.RECTANGLE,tr.POLYGON,tr.MULTIPOLYGON;function e1(r,t,e){let i;const n=Ni();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return ni(()=>(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=Tv(s,a,{selected:!0,hovered:!0})),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 r1 extends zt{constructor(t){super(),Wt(this,t,e1,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 oi=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(oi||{}),sd=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(sd||{}),Xa=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Xa||{}),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||{}),rr=(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))(rr||{}),W=(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))(W||{}),Xi=(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))(Xi||{}),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||{}),J=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(J||{}),yr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(yr||{}),kr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(kr||{}),ir=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(ir||{}),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||{}),nr=(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))(nr||{}),Va=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(Va||{}),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||{}),sr=(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))(sr||{});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 ja=/iPhone/i,od=/iPod/i,ad=/iPad/i,ld=/\biOS-universal(?:.+)Mac\b/i,Wa=/\bAndroid(?:.+)Mobile\b/i,hd=/Android/i,Vi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Rs=/Silk/i,_r=/Windows Phone/i,cd=/\bWindows(?:.+)ARM\b/i,ud=/BlackBerry/i,dd=/BB10/i,fd=/Opera Mini/i,pd=/\b(CriOS|Chrome)(?:.+)Mobile/i,md=/Mobile(?:.+)Firefox\b/i,gd=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function i1(r){return function(t){return t.test(r)}}function yd(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=i1(e),s={apple:{phone:n(ja)&&!n(_r),ipod:n(od),tablet:!n(ja)&&(n(ad)||gd(t))&&!n(_r),universal:n(ld),device:(n(ja)||n(od)||n(ad)||n(ld)||gd(t))&&!n(_r)},amazon:{phone:n(Vi),tablet:!n(Vi)&&n(Rs),device:n(Vi)||n(Rs)},android:{phone:!n(_r)&&n(Vi)||!n(_r)&&n(Wa),tablet:!n(_r)&&!n(Vi)&&!n(Wa)&&(n(Rs)||n(hd)),device:!n(_r)&&(n(Vi)||n(Rs)||n(Wa)||n(hd))||n(/\bokhttp\b/i)},windows:{phone:n(_r),tablet:n(cd),device:n(_r)||n(cd)},other:{blackberry:n(ud),blackberry10:n(dd),opera:n(fd),firefox:n(md),chrome:n(pd),device:n(ud)||n(dd)||n(fd)||n(md)||n(pd)},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 n1=yd.default??yd,vr=n1(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var _d={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 f=new n(c,u||l,d),p=e?e+h:h;return l._events[p]?l._events[p].fn?l._events[p]=[l._events[p],f]:l._events[p].push(f):(l._events[p]=f,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,f=u.length,p=new Array(f);d<f;d++)p[d]=u[d].fn;return p},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,f,p){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,f),!0;case 6:return y.fn.call(y.context,c,u,d,f,p),!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 f=e?e+h:h;if(!this._events[f])return this;if(!c)return o(this,f),this;var p=this._events[f];if(p.fn)p.fn===c&&(!d||p.once)&&(!u||p.context===u)&&o(this,f);else{for(var m=0,y=[],_=p.length;m<_;m++)(p[m].fn!==c||d&&!p[m].once||u&&p[m].context!==u)&&y.push(p[m]);y.length?this._events[f]=y.length===1?y[0]:y:o(this,f)}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})(_d);var s1=_d.exports;const Bn=Da(s1);var za={exports:{}};za.exports=Ms,za.exports.default=Ms;function Ms(r,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:r.length,s=vd(r,0,n,e,!0),o=[];if(!s||s.next===s.prev)return o;var a,l,h,c,u,d,f;if(i&&(s=c1(r,t,s,e)),r.length>80*e){a=h=r[0],l=c=r[1];for(var p=e;p<n;p+=e)u=r[p],d=r[p+1],u<a&&(a=u),d<l&&(l=d),u>h&&(h=u),d>c&&(c=d);f=Math.max(h-a,c-l),f=f!==0?32767/f:0}return On(s,o,e,a,l,f,0),o}function vd(r,t,e,i,n){var s,o;if(n===Ka(r,t,e,i)>0)for(s=t;s<e;s+=i)o=wd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=wd(s,r[s],r[s+1],o);return o&&Ds(o,o.next)&&(Nn(o),o=o.next),o}function ai(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(Ds(e,e.next)||$t(e.prev,e,e.next)===0)){if(Nn(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function On(r,t,e,i,n,s,o){if(r){!o&&s&&m1(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?a1(r,i,n,s):o1(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Nn(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=l1(ai(r),t,e),On(r,t,e,i,n,s,2)):o===2&&h1(r,t,e,i,n,s):On(ai(r),t,e,i,n,s,1);break}}}}function o1(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,f=a>l?a>h?a:h:l>h?l:h,p=i.next;p!==t;){if(p.x>=c&&p.x<=d&&p.y>=u&&p.y<=f&&ji(n,a,s,l,o,h,p.x,p.y)&&$t(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function a1(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,f=a<l?a<h?a:h:l<h?l:h,p=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,_=Ya(f,p,t,e,i),v=Ya(m,y,t,e,i),g=r.prevZ,b=r.nextZ;g&&g.z>=_&&b&&b.z<=v;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=y&&g!==n&&g!==o&&ji(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0||(g=g.prevZ,b.x>=f&&b.x<=m&&b.y>=p&&b.y<=y&&b!==n&&b!==o&&ji(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>=f&&g.x<=m&&g.y>=p&&g.y<=y&&g!==n&&g!==o&&ji(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>=f&&b.x<=m&&b.y>=p&&b.y<=y&&b!==n&&b!==o&&ji(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 l1(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!Ds(n,s)&&bd(n,i,i.next,s)&&Ln(n,s)&&Ln(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),Nn(i),Nn(i.next),i=r=s),i=i.next}while(i!==r);return ai(i)}function h1(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&_1(o,a)){var l=xd(o,a);o=ai(o,o.next),l=ai(l,l.next),On(o,t,e,i,n,s,0),On(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function c1(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=vd(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(y1(h));for(n.sort(u1),s=0;s<n.length;s++)e=d1(n[s],e);return e}function u1(r,t){return r.x-t.x}function d1(r,t){var e=f1(r,t);if(!e)return t;var i=xd(e,r);return ai(i,i.next),ai(e,e.next)}function f1(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&&ji(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),Ln(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&p1(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function p1(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function m1(r,t,e,i){var n=r;do n.z===0&&(n.z=Ya(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,g1(n)}function g1(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 Ya(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 y1(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 ji(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 _1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!v1(r,t)&&(Ln(r,t)&&Ln(t,r)&&b1(r,t)&&($t(r.prev,r,t.prev)||$t(r,t.prev,t))||Ds(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 Ds(r,t){return r.x===t.x&&r.y===t.y}function bd(r,t,e,i){var n=Os($t(r,t,e)),s=Os($t(r,t,i)),o=Os($t(e,i,r)),a=Os($t(e,i,t));return!!(n!==s&&o!==a||n===0&&Bs(r,e,t)||s===0&&Bs(r,i,t)||o===0&&Bs(e,r,i)||a===0&&Bs(e,t,i))}function Bs(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 Os(r){return r>0?1:r<0?-1:0}function v1(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&&bd(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Ln(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 b1(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 xd(r,t){var e=new qa(r.i,r.x,r.y),i=new qa(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 wd(r,t,e,i){var n=new qa(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 Nn(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 qa(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}Ms.deviation=function(r,t,e,i){var n=t&&t.length,s=n?t[0]*e:r.length,o=Math.abs(Ka(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(Ka(r,h,c,e))}var u=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,f=i[a+1]*e,p=i[a+2]*e;u+=Math.abs((r[d]-r[p])*(r[f+1]-r[d+1])-(r[d]-r[f])*(r[p+1]-r[d+1]))}return o===0&&u===0?0:Math.abs((u-o)/o)};function Ka(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}Ms.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 x1=za.exports;const w1=Da(x1);var Ls={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Ls.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,n=r&&!r.nodeType&&r,s=typeof Rn=="object"&&Rn;(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,f=72,p=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(B){throw new RangeError(g[B])}function M(B,N){for(var k=B.length,X=[];k--;)X[k]=N(B[k]);return X}function F(B,N){var k=B.split("@"),X="";k.length>1&&(X=k[0]+"@",B=k[1]),B=B.replace(v,".");var j=B.split("."),K=M(j,N).join(".");return X+K}function U(B){for(var N=[],k=0,X=B.length,j,K;k<X;)j=B.charCodeAt(k++),j>=55296&&j<=56319&&k<X?(K=B.charCodeAt(k++),(K&64512)==56320?N.push(((j&1023)<<10)+(K&1023)+65536):(N.push(j),k--)):N.push(j);return N}function P(B){return M(B,function(N){var k="";return N>65535&&(N-=65536,k+=R(N>>>10&1023|55296),N=56320|N&1023),k+=R(N),k}).join("")}function E(B){return B-48<10?B-22:B-65<26?B-65:B-97<26?B-97:l}function T(B,N){return B+22+75*(B<26)-((N!=0)<<5)}function A(B,N,k){var X=0;for(B=k?S(B/d):B>>1,B+=S(B/N);B>b*c>>1;X+=l)B=S(B/b);return S(X+(b+1)*B/(B+u))}function O(B){var N=[],k=B.length,X,j=0,K=p,V=f,ut,H,mt,Q,dt,gt,Et,Dt,Yt;for(ut=B.lastIndexOf(m),ut<0&&(ut=0),H=0;H<ut;++H)B.charCodeAt(H)>=128&&I("not-basic"),N.push(B.charCodeAt(H));for(mt=ut>0?ut+1:0;mt<k;){for(Q=j,dt=1,gt=l;mt>=k&&I("invalid-input"),Et=E(B.charCodeAt(mt++)),(Et>=l||Et>S((a-j)/dt))&&I("overflow"),j+=Et*dt,Dt=gt<=V?h:gt>=V+c?c:gt-V,!(Et<Dt);gt+=l)Yt=l-Dt,dt>S(a/Yt)&&I("overflow"),dt*=Yt;X=N.length+1,V=A(j-Q,X,Q==0),S(j/X)>a-K&&I("overflow"),K+=S(j/X),j%=X,N.splice(j++,0,K)}return P(N)}function D(B){var N,k,X,j,K,V,ut,H,mt,Q,dt,gt=[],Et,Dt,Yt,jt;for(B=U(B),Et=B.length,N=p,k=0,K=f,V=0;V<Et;++V)dt=B[V],dt<128&&gt.push(R(dt));for(X=j=gt.length,j&&gt.push(m);X<Et;){for(ut=a,V=0;V<Et;++V)dt=B[V],dt>=N&&dt<ut&&(ut=dt);for(Dt=X+1,ut-N>S((a-k)/Dt)&&I("overflow"),k+=(ut-N)*Dt,N=ut,V=0;V<Et;++V)if(dt=B[V],dt<N&&++k>a&&I("overflow"),dt==N){for(H=k,mt=l;Q=mt<=K?h:mt>=K+c?c:mt-K,!(H<Q);mt+=l)jt=H-Q,Yt=l-Q,gt.push(R(T(Q+jt%Yt,0))),H=S(jt/Yt);gt.push(R(T(H,0))),K=A(k,Dt,X==j),k=0,++X}++k,++N}return gt.join("")}function L(B){return F(B,function(N){return y.test(N)?O(N.slice(4).toLowerCase()):N})}function $(B){return F(B,function(N){return _.test(N)?"xn--"+D(N):N})}if(o={version:"1.4.1",ucs2:{decode:U,encode:P},decode:O,encode:D,toASCII:$,toUnicode:L},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})(Rn)}(Ls,Ls.exports);var E1=Ls.exports,Wi=TypeError;const T1=nv(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Za=typeof Map=="function"&&Map.prototype,Qa=Object.getOwnPropertyDescriptor&&Za?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ns=Za&&Qa&&typeof Qa.get=="function"?Qa.get:null,Ed=Za&&Map.prototype.forEach,Ja=typeof Set=="function"&&Set.prototype,tl=Object.getOwnPropertyDescriptor&&Ja?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Fs=Ja&&tl&&typeof tl.get=="function"?tl.get:null,Td=Ja&&Set.prototype.forEach,A1=typeof WeakMap=="function"&&WeakMap.prototype,Fn=A1?WeakMap.prototype.has:null,S1=typeof WeakSet=="function"&&WeakSet.prototype,kn=S1?WeakSet.prototype.has:null,C1=typeof WeakRef=="function"&&WeakRef.prototype,Ad=C1?WeakRef.prototype.deref:null,I1=Boolean.prototype.valueOf,P1=Object.prototype.toString,R1=Function.prototype.toString,M1=String.prototype.match,el=String.prototype.slice,Ur=String.prototype.replace,D1=String.prototype.toUpperCase,Sd=String.prototype.toLowerCase,Cd=RegExp.prototype.test,Id=Array.prototype.concat,or=Array.prototype.join,B1=Array.prototype.slice,Pd=Math.floor,rl=typeof BigInt=="function"?BigInt.prototype.valueOf:null,il=Object.getOwnPropertySymbols,nl=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,zi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Un=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===zi||!0)?Symbol.toStringTag:null,Rd=Object.prototype.propertyIsEnumerable,Md=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Dd(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Cd.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Pd(-r):Pd(r);if(i!==r){var n=String(i),s=el.call(t,n.length+1);return Ur.call(n,e,"$&_")+"."+Ur.call(Ur.call(s,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Ur.call(t,e,"$&_")}var sl=T1,Bd=sl.custom,Od=kd(Bd)?Bd:null,Ld={__proto__:null,double:'"',single:"'"},O1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},ks=function r(t,e,i,n){var s=e||{};if(br(s,"quoteStyle")&&!br(Ld,s.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(br(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=br(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(br(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(br(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 Gd(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Dd(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Dd(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 ol(t)?"[Array]":"[Object]";var u=Q1(s,i);if(typeof n>"u")n=[];else if(Ud(n,t)>=0)return"[Circular]";function d(E,T,A){if(T&&(n=B1.call(n),n.push(T)),A){var O={depth:s.depth};return br(s,"quoteStyle")&&(O.quoteStyle=s.quoteStyle),r(E,O,i+1,n)}return r(E,s,i+1,n)}if(typeof t=="function"&&!Fd(t)){var f=X1(t),p=Us(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+or.call(p,", ")+" }":"")}if(kd(t)){var m=zi?Ur.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):nl.call(t);return typeof t=="object"&&!zi?Gn(m):m}if(q1(t)){for(var y="<"+Sd.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Nd(L1(_[v].value),"double",s);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+Sd.call(String(t.nodeName))+">",y}if(ol(t)){if(t.length===0)return"[]";var g=Us(t,d);return u&&!Z1(g)?"["+ll(g,u)+"]":"[ "+or.call(g,", ")+" ]"}if(F1(t)){var b=Us(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!Rd.call(t,"cause")?"{ ["+String(t)+"] "+or.call(Id.call("[cause]: "+d(t.cause),b),", ")+" }":b.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+or.call(b,", ")+" }"}if(typeof t=="object"&&o){if(Od&&typeof t[Od]=="function"&&sl)return sl(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(V1(t)){var S=[];return Ed&&Ed.call(t,function(E,T){S.push(d(T,t,!0)+" => "+d(E,t))}),$d("Map",Ns.call(t),S,u)}if(z1(t)){var R=[];return Td&&Td.call(t,function(E){R.push(d(E,t))}),$d("Set",Fs.call(t),R,u)}if(j1(t))return al("WeakMap");if(Y1(t))return al("WeakSet");if(W1(t))return al("WeakRef");if(U1(t))return Gn(d(Number(t)));if($1(t))return Gn(d(rl.call(t)));if(G1(t))return Gn(I1.call(t));if(k1(t))return Gn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Rn<"u"&&t===Rn)return"{ [object globalThis] }";if(!N1(t)&&!Fd(t)){var C=Us(t,d),I=Md?Md(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",F=!I&&Un&&Object(t)===t&&Un in t?el.call(Gr(t),8,-1):M?"Object":"",U=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",P=U+(F||M?"["+or.call(Id.call([],F||[],M||[]),": ")+"] ":"");return C.length===0?P+"{}":u?P+"{"+ll(C,u)+"}":P+"{ "+or.call(C,", ")+" }"}return String(t)};function Nd(r,t,e){var i=e.quoteStyle||t,n=Ld[i];return n+r+n}function L1(r){return Ur.call(String(r),/"/g,"&quot;")}function li(r){return!Un||!(typeof r=="object"&&(Un in r||typeof r[Un]<"u"))}function ol(r){return Gr(r)==="[object Array]"&&li(r)}function N1(r){return Gr(r)==="[object Date]"&&li(r)}function Fd(r){return Gr(r)==="[object RegExp]"&&li(r)}function F1(r){return Gr(r)==="[object Error]"&&li(r)}function k1(r){return Gr(r)==="[object String]"&&li(r)}function U1(r){return Gr(r)==="[object Number]"&&li(r)}function G1(r){return Gr(r)==="[object Boolean]"&&li(r)}function kd(r){if(zi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!nl)return!1;try{return nl.call(r),!0}catch{}return!1}function $1(r){if(!r||typeof r!="object"||!rl)return!1;try{return rl.call(r),!0}catch{}return!1}var H1=Object.prototype.hasOwnProperty||function(r){return r in this};function br(r,t){return H1.call(r,t)}function Gr(r){return P1.call(r)}function X1(r){if(r.name)return r.name;var t=M1.call(R1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Ud(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 V1(r){if(!Ns||!r||typeof r!="object")return!1;try{Ns.call(r);try{Fs.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function j1(r){if(!Fn||!r||typeof r!="object")return!1;try{Fn.call(r,Fn);try{kn.call(r,kn)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function W1(r){if(!Ad||!r||typeof r!="object")return!1;try{return Ad.call(r),!0}catch{}return!1}function z1(r){if(!Fs||!r||typeof r!="object")return!1;try{Fs.call(r);try{Ns.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function Y1(r){if(!kn||!r||typeof r!="object")return!1;try{kn.call(r,kn);try{Fn.call(r,Fn)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function q1(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Gd(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Gd(el.call(r,0,t.maxStringLength),t)+i}var n=O1[t.quoteStyle||"single"];n.lastIndex=0;var s=Ur.call(Ur.call(r,n,"\\$1"),/[\x00-\x1f]/g,K1);return Nd(s,"single",t)}function K1(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":"")+D1.call(t.toString(16))}function Gn(r){return"Object("+r+")"}function al(r){return r+" { ? }"}function $d(r,t,e,i){var n=i?ll(e,i):or.call(e,", ");return r+" ("+t+") {"+n+"}"}function Z1(r){for(var t=0;t<r.length;t++)if(Ud(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 yC=Object.defineProperty;var _C=(qt,se,Qr)=>se in qt?yC(qt,se,{enumerable:!0,configurable:!0,writable:!0,value:Qr}):qt[se]=Qr;var jh=(qt,se,Qr)=>_C(qt,typeof se!="symbol"?se+"":se,Qr);var Qr=Object.prototype.hasOwnProperty;function Jr(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--&&Jr(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)||!Jr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var zo=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(zo||{});const fe=[];for(let r=0;r<256;++r)fe.push((r+256).toString(16).slice(1));function cg(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 Yo;const ug=new Uint8Array(16);function dg(){if(!Yo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Yo=crypto.getRandomValues.bind(crypto)}return Yo(ug)}const fg=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Jh={randomUUID:fg};function pg(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??dg();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,cg(n)}function mg(r,t,e){return Jh.randomUUID&&!r?Jh.randomUUID():pg(r)}const qo=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)}},gg=(r,t,e,i)=>({id:mg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),yg=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},_g=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},vg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Jr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),bg=(r,t)=>!Jr(r.target,t.target),xg=(r,t)=>{const e=yg(r,t),i=_g(r,t),n=vg(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:bg(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Mr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Mr||{});const wg=(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:f}=u;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return xg(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let Eg=()=>({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 Tg=250,Ag=(r,t)=>{const e=Eg(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:m}=p,y=performance.now();if(y-o>Tg)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=wg(i[_],m)}o=y}s=!1};r.observe(a,{origin:Mr.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),c=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:m})=>m)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:m})=>m)),d=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),f=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(p,m)=>e.on(p,m),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:m,deleted:y}=i[n+1];h(p),u(m),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:m,deleted:y}=i[n];l(p),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},Sg=(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])},f=(_,v)=>{const g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},p=(_,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||!Jr(b,g))&&p("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&&!Jr(g,v)&&p("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&&!Jr(S,b)&&p("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}p("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?p("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>p("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=>p("createAnnotation",b)),(g||[]).forEach(b=>p("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),p("updateAnnotation",S,R)})},{origin:Mr.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:Mr.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>p("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>p("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},Cg=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:[]}),Ig=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Mr.REMOTE):console.error(g)}else i.addAnnotation(qo(_),Mr.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=>(f(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),_}},f=(_,v=!0)=>{if(e){const g=e.parseAll||Cg(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Mr.REMOTE)}else i.bulkAddAnnotations(_.map(qo),v,Mr.REMOTE)},p=(_,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(qo(_)),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:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:y}},Pg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Rg=r=>crypto.getRandomValues(new Uint8Array(r)),Mg=(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}}},Dg=(r,t=21)=>Mg(r,t|0,Rg),Bg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Pg[e[r]&63];return t};const Og=()=>({isGuest:!0,id:Dg("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Lg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Ng=()=>{const r=[...Lg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};Bg();var Fg=Object.defineProperty,kg=(r,t,e)=>t in r?Fg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,tc=(r,t,e)=>kg(r,typeof t!="symbol"?t+"":t,e);function Rt(){}function Ko(r,t){for(const e in t)r[e]=t[e];return r}function ec(r){return r()}function rc(){return Object.create(null)}function Me(r){r.forEach(ec)}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 Ug(r){return Object.keys(r).length===0}function ic(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 Zo(r,t,e){r.$$.on_destroy.push(ic(t,e))}function Gg(r,t,e,i){if(r){const n=nc(r,t,e,i);return r[0](n)}}function nc(r,t,e,i){return r[1]&&i?Ko(e.ctx.slice(),r[1](i(t))):e.ctx}function $g(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 Hg(r,t,e,i,n,s){if(n){const o=nc(t,e,i,s);r.p(o,n)}}function Xg(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 sc(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Ci(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 ti(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function z(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function oc(r){return document.createTextNode(r)}function we(){return oc(" ")}function De(){return oc("")}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 Vg(r){return Array.from(r.childNodes)}function Je(r,t,e){r.classList.toggle(t,!!e)}function jg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let bn;function xn(r){bn=r}function ac(){if(!bn)throw new Error("Function called outside component initialization");return bn}function ei(r){ac().$$.on_mount.push(r)}function Dr(){const r=ac();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=jg(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 Ii=[],us=[];let Pi=[];const lc=[],hc=Promise.resolve();let Qo=!1;function cc(){Qo||(Qo=!0,hc.then(dc))}function uc(){return cc(),hc}function Jo(r){Pi.push(r)}const ta=new Set;let Ri=0;function dc(){if(Ri!==0)return;const r=bn;do{try{for(;Ri<Ii.length;){const t=Ii[Ri];Ri++,xn(t),Wg(t.$$)}}catch(t){throw Ii.length=0,Ri=0,t}for(xn(null),Ii.length=0,Ri=0;us.length;)us.pop()();for(let t=0;t<Pi.length;t+=1){const e=Pi[t];ta.has(e)||(ta.add(e),e())}Pi.length=0}while(Ii.length);for(;lc.length;)lc.pop()();Qo=!1,ta.clear(),xn(r)}function Wg(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 zg(r){const t=[],e=[];Pi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Pi=t}const ds=new Set;let ri;function Ee(){ri={r:0,c:[],p:ri}}function Te(){ri.r||Me(ri.c),ri=ri.p}function lt(r,t){r&&r.i&&(ds.delete(r),r.i(t))}function yt(r,t,e,i){if(r&&r.o){if(ds.has(r))return;ds.add(r),ri.c.push(()=>{ds.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 Jt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Jo(()=>{const s=r.$$.on_mount.map(ec).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&&(zg(e.after_update),Me(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Yg(r,t){r.$$.dirty[0]===-1&&(Ii.push(r),cc(),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=bn;xn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Rt,not_equal:n,bound:rc(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:rc(),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,...f)=>{const p=f.length?f[0]:d;return h.ctx&&n(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&Yg(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=Vg(t.target);h.fragment&&h.fragment.l(u),u.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&lt(r.$$.fragment),Jt(r,t.target,t.anchor),dc()}xn(l)}class me{constructor(){tc(this,"$$"),tc(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&&!Ug(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const qg="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(qg);var _t=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(_t||{}),Kg={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,f=h.y-u;if(d!==0||f!==0){var p=((a.x-c)*d+(a.y-u)*f)/(d*d+f*f);p>1?(c=h.x,u=h.y):p>0&&(c+=d*p,u+=f*p)}return d=a.x-c,f=a.y-u,d*d+f*f}function i(a,l){for(var h=a[0],c=[h],u,d=1,f=a.length;d<f;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,f,p=l+1;p<h;p++){var m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}d>c&&(f-l>1&&n(a,l,f,c,u),u.push(a[f]),h-f>1&&n(a,f,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})()})(Kg);const ea={},Mi=(r,t)=>ea[r]=t,ra=r=>ea[r.type].area(r),Zg=(r,t,e,i)=>ea[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}},fs=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)},ps=(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},Qg=(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},ms=(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,f=h*c-l*u;return d*d/(s*s)+f*f/(o*o)<=1}};Mi(_t.ELLIPSE,Jg);const ty={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=ms([n,s],[o,a]);return l/h<=i}};Mi(_t.LINE,ty);const ey={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=fs(n.points),a=s.reduce((l,h)=>l+fs(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(ps(s.points,t,e)){let a=!1;for(const l of o)if(ps(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},ia=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ae(t)},He=r=>r.rings.map(t=>Qg(t.points)).join(" "),ry=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Mi(_t.MULTIPOLYGON,ey);const iy={area:r=>{const t=r.geometry.points;return fs(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return ps(i,t,e)}};Mi(_t.POLYGON,iy);const ny={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=na(t.points,t.closed);return fs(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=na(n.points,n.closed);return ps(s,t,e)}else return sy(n,[t,e],i)}},na=(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=fc(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},fc=(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},sy=(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=fc(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(pc(t,o[a],o[a+1])<=e)return!0}else if(pc(t,n.point,s.point)<=e)return!0}return!1},pc=(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},sa=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(" ")};Mi(_t.POLYLINE,ny);const oy={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};Mi(_t.RECTANGLE,oy);const Le=r=>gs(r.target),gs=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},ay=r=>(r==null?void 0:r.type)==="FragmentSelector"?!0:typeof r=="string"?r.indexOf("#")<0?!1:/#xywh(?:=(?:pixel:|percent:)?)(.+?),(.+?),(.+?),(.+)$/i.test(r):!1,ly=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/(xywh)=(?:(pixel|percent):)?:?(.+?),(.+?),(.+?),(.+)*/g,n=[...e.matchAll(i)][0];if(!n)throw new Error("Not a MediaFragment: "+e);const[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,f,p,m]=[l,h,c,u].map(parseFloat);return{type:_t.RECTANGLE,geometry:{x:d,y:f,w:p,h:m,bounds:{minX:d,minY:t?f-m:f,maxX:d+p,maxY:t?f:f+m}}}},hy=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}`}},mc="http://www.w3.org/2000/svg",gc=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},cy=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${mc}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},ys=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(mc),i=t.lookupNamespaceURI(null);return e||i?gc(t).firstChild:gc(cy(t)).firstChild},uy=r=>{const t=yc(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}}},dy=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},fy=r=>{const t=yc(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=>dy(o)?{...o,locked:!0}:o);const s=Ae(na(e,n));return{points:e,closed:n,bounds:s}},yc=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},py=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)}}},my=r=>{const t=ys(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}}},gy=r=>{const t=ys(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}}},yy=r=>{const t=ys(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=fy(i);if(!n)throw new Error("Could not parse SVG path");return{type:_t.POLYLINE,geometry:n}},_y=r=>{const t=ys(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>uy(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}}},vy=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return py(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return yy(t);if(t.includes("<path "))return _y(t);if(t.includes("<ellipse "))return my(t);if(t.includes("<line "))return gy(t);throw"Unsupported SVG shape: "+t},by=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${He(t)}" />`).join("")}</g>`,xy=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>${by(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="${sa(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 wy(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 oa;const Ey=new Uint8Array(16);function Ty(){if(!oa){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");oa=crypto.getRandomValues.bind(crypto)}return oa(Ey)}const Ay=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_c={randomUUID:Ay};function Sy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Ty();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,wy(n)}function vc(r,t,e){return _c.randomUUID&&!r?_c.randomUUID():Sy(r)}var bc=Object.prototype.hasOwnProperty;function Br(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--&&Br(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(bc.call(r,e)&&++i&&!bc.call(t,e)||!(e in t)||!Br(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}let Xe=[],Or=0;const _s=4,aa=r=>{let t=[],e={get(){return e.lc||e.listen(()=>{})(),e.value},lc:0,listen(i){return e.lc=t.push(i),()=>{for(let s=Or+_s;s<Xe.length;)Xe[s]===i?Xe.splice(s,_s):s+=_s;let n=t.indexOf(i);~n&&(t.splice(n,1),--e.lc||e.off())}},notify(i,n){let s=!Xe.length;for(let o of t)Xe.push(o,e.value,i,n);if(s){for(Or=0;Or<Xe.length;Or+=_s)Xe[Or](Xe[Or+1],Xe[Or+2],Xe[Or+3]);Xe.length=0}},off(){},set(i){let n=e.value;n!==i&&(e.value=i,e.notify(n))},subscribe(i){let n=e.listen(i);return i(e.value),n},value:r};return e},Cy=r=>{const t=aa(null);return r.observe(({changes:e})=>{const i=t.get();if(i){(e.deleted||[]).some(s=>s.id===i)&&t.set(null);const n=(e.updated||[]).find(({oldValue:s})=>s.id===i);n&&t.set(n.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var xc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(xc||{});const la={selected:[]},Iy=(r,t,e)=>{const i=aa(la);let n=t;const s=()=>{Br(i.get(),la)||i.set(la)},o=()=>{var f;return((f=i.get().selected)==null?void 0:f.length)===0},a=f=>{if(o())return!1;const p=typeof f=="string"?f:f.id;return i.get().selected.some(m=>m.id===p)},l=(f,p)=>{let m;if(Array.isArray(f)){if(m=f.map(_=>r.getAnnotation(_)).filter(Boolean),m.length<f.length){console.warn("Invalid selection: "+f.filter(_=>!m.some(v=>v.id===_)));return}}else{const _=r.getAnnotation(f);if(!_){console.warn("Invalid selection: "+f);return}m=[_]}const y=m.reduce((_,v)=>{const g=d(v);return g==="EDIT"?[..._,{id:v.id,editable:!0}]:g==="SELECT"?[..._,{id:v.id}]:_},[]);i.set({selected:y,event:p})},h=(f,p)=>{const m=Array.isArray(f)?f:[f],y=m.map(_=>r.getAnnotation(_)).filter(_=>!!_);i.set({selected:y.map(_=>{const v=p===void 0?d(_)==="EDIT":p;return{id:_.id,editable:v}})}),y.length!==m.length&&console.warn("Invalid selection",f)},c=f=>{if(o())return!1;const{selected:p}=i.get();p.some(({id:m})=>f.includes(m))&&i.set({selected:p.filter(({id:m})=>!f.includes(m))})},u=f=>{n=f,h(i.get().selected.map(({id:p})=>p))},d=f=>Py(f,n,e);return r.observe(({changes:f})=>c((f.deleted||[]).map(p=>p.id))),{get event(){const f=i.get();return f?f.event:null},get selected(){const f=i.get();return f?[...f.selected]:null},get userSelectAction(){return n},clear:s,evalSelectAction:d,isEmpty:o,isSelected:a,setSelected:h,setUserSelectAction:u,subscribe:i.subscribe.bind(i),userSelect:l}},Py=(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 Ry(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 ha;const My=new Uint8Array(16);function Dy(){if(!ha){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ha=crypto.getRandomValues.bind(crypto)}return ha(My)}const By=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),wc={randomUUID:By};function Oy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Dy();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,Ry(n)}function Ly(r,t,e){return wc.randomUUID&&!r?wc.randomUUID():Oy(r)}const ca=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)}},Ny=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Fy=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},ky=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Br(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Uy=(r,t)=>!Br(r.target,t.target),Ec=(r,t)=>{const e=Ny(r,t),i=Fy(r,t),n=ky(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:Uy(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 Gy=(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},$y=(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:f}=u;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return Ec(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},vs=r=>{const t=r.id===void 0?Ly():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Hy=r=>r.id!==void 0,Xy=()=>{const r=new Map,t=new Map,e=[],i=(P,E={})=>{e.push({onChange:P,options:E})},n=P=>{const E=e.findIndex(T=>T.onChange==P);E>-1&&e.splice(E,1)},s=(P,E)=>{const T={origin:P,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...r.values()]};e.forEach(A=>{Gy(A,T)&&A.onChange(T)})},o=(P,E=Nt.LOCAL)=>{if(P.id&&r.get(P.id))throw Error(`Cannot add annotation ${P.id} - exists already`);{const T=vs(P);r.set(T.id,T),T.bodies.forEach(A=>t.set(A.id,T.id)),s(E,{created:[T]})}},a=(P,E)=>{const T=vs(typeof P=="string"?E:P),A=typeof P=="string"?P:P.id,O=A&&r.get(A);if(O){const D=Ec(O,T);return A===T.id?r.set(A,T):(r.delete(A),r.set(T.id,T)),O.bodies.forEach(L=>t.delete(L.id)),T.bodies.forEach(L=>t.set(L.id,T.id)),D}else console.warn(`Cannot update annotation ${A} - does not exist`)},l=(P,E=Nt.LOCAL,T=Nt.LOCAL)=>{const A=Hy(E)?T:E,O=a(P,E);O&&s(A,{updated:[O]})},h=(P,E=Nt.LOCAL)=>{r.get(P.id)?l(P,E):o(P,E)},c=(P,E=Nt.LOCAL)=>{const T=P.reduce((A,O)=>{const D=a(O);return D?[...A,D]:A},[]);T.length>0&&s(E,{updated:T})},u=(P,E=Nt.LOCAL)=>{const T=P.map(vs),{toAdd:A,toUpdate:O}=T.reduce((L,$)=>r.get($.id)?{...L,toUpdate:[...L.toUpdate,$]}:{...L,toAdd:[...L.toAdd,$]},{toAdd:[],toUpdate:[]}),D=O.map(L=>a(L,E)).filter(Boolean);A.forEach(L=>{r.set(L.id,L),L.bodies.forEach($=>t.set($.id,L.id))}),s(E,{created:A,updated:D})},d=(P,E=Nt.LOCAL)=>{const T=r.get(P.annotation);if(T){const A={...T,bodies:[...T.bodies,P]};r.set(T.id,A),t.set(P.id,A.id),s(E,{updated:[{oldValue:T,newValue:A,bodiesCreated:[P]}]})}else console.warn(`Attempt to add body to missing annotation: ${P.annotation}`)},f=()=>[...r.values()],p=(P=Nt.LOCAL)=>{const E=[...r.values()];r.clear(),t.clear(),s(P,{deleted:E})},m=(P,E=!0,T=Nt.LOCAL)=>{const A=P.map(vs);if(E){const O=[...r.values()];r.clear(),t.clear(),A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(L=>t.set(L.id,D.id))}),s(T,{created:A,deleted:O})}else{const O=P.reduce((D,L)=>{const $=L.id&&r.get(L.id);return $?[...D,$]:D},[]);if(O.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${O.map(D=>D.id).join(", ")}`);A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(L=>t.set(L.id,D.id))}),s(T,{created:A})}},y=P=>{const E=typeof P=="string"?P:P.id,T=r.get(E);if(T)return r.delete(E),T.bodies.forEach(A=>t.delete(A.id)),T;console.warn(`Attempt to delete missing annotation: ${E}`)},_=(P,E=Nt.LOCAL)=>{const T=y(P);T&&s(E,{deleted:[T]})},v=(P,E=Nt.LOCAL)=>{const T=P.reduce((A,O)=>{const D=y(O);return D?[...A,D]:A},[]);T.length>0&&s(E,{deleted:T})},g=P=>{const E=r.get(P.annotation);if(E){const T=E.bodies.find(A=>A.id===P.id);if(T){t.delete(T.id);const A={...E,bodies:E.bodies.filter(O=>O.id!==P.id)};return r.set(E.id,A),{oldValue:E,newValue:A,bodiesDeleted:[T]}}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,E=Nt.LOCAL)=>{const T=g(P);T&&s(E,{updated:[T]})},S=(P,E=Nt.LOCAL)=>{const T=P.map(A=>g(A)).filter(Boolean);T.length>0&&s(E,{updated:T})},R=P=>{const E=r.get(P);return E?{...E}:void 0},C=P=>{const E=t.get(P);if(E){const T=R(E).bodies.find(A=>A.id===P);if(T)return T;console.error(`Store integrity error: body ${P} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${P}`)},I=(P,E)=>{if(P.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const T=r.get(P.annotation);if(T){const A=T.bodies.find(D=>D.id===P.id),O={...T,bodies:T.bodies.map(D=>D.id===A.id?E:D)};return r.set(T.id,O),A.id!==E.id&&(t.delete(A.id),t.set(E.id,O.id)),{oldValue:T,newValue:O,bodiesUpdated:[{oldBody:A,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${P.annotation}`)},M=(P,E,T=Nt.LOCAL)=>{const A=I(P,E);A&&s(T,{updated:[A]})},F=(P,E=Nt.LOCAL)=>{const T=P.map(A=>I({id:A.id,annotation:A.annotation},A)).filter(Boolean);s(E,{updated:T})},U=P=>{const E=r.get(P.annotation);if(E){const T={...E,target:{...E.target,...P}};return r.set(E.id,T),{oldValue:E,newValue:T,targetUpdated:{oldTarget:E.target,newTarget:P}}}else console.warn(`Attempt to update target on missing annotation: ${P.annotation}`)};return{addAnnotation:o,addBody:d,all:f,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:S,bulkUpdateAnnotations:c,bulkUpdateBodies:F,bulkUpdateTargets:(P,E=Nt.LOCAL)=>{const T=P.map(A=>U(A)).filter(Boolean);T.length>0&&s(E,{updated:T})},bulkUpsertAnnotations:u,clear:p,deleteAnnotation:_,deleteBody:b,getAnnotation:R,getBody:C,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(P,E=Nt.LOCAL)=>{const T=U(P);T&&s(E,{updated:[T]})},upsertAnnotation:h}};let Vy=()=>({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 jy=250,Wy=(r,t)=>{const e=Vy(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:m}=p,y=performance.now();if(y-o>jy)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=$y(i[_],m)}o=y}s=!1};r.observe(a,{origin:Nt.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),c=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:m})=>m)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:m})=>m)),d=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),f=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(p,m)=>e.on(p,m),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:m,deleted:y}=i[n+1];h(p),u(m),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:m,deleted:y}=i[n];l(p),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},zy=()=>{const r=aa([]);return{subscribe:r.subscribe.bind(r),set:r.set.bind(r)}},Yy=(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])},f=(_,v)=>{const g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},p=(_,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||!Br(b,g))&&p("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&&!Br(g,v)&&p("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&&!Br(S,b)&&p("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}p("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?p("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>p("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=>p("createAnnotation",b)),(g||[]).forEach(b=>p("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),p("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=>p("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>p("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},qy=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:[]}),Ky=(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(ca(_),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=>(f(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),_}},f=(_,v=!0)=>{if(e){const g=e.parseAll||qy(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(ca),v,Nt.REMOTE)},p=(_,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(ca(_)),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:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:y}},Zy=(r,t,e)=>typeof t=="function"?t(r,e):t,Qy=(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||{}}},Jy="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let t0=r=>crypto.getRandomValues(new Uint8Array(r)),e0=(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}}},r0=(r,t=21)=>e0(r,t|0,t0),i0=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Jy[e[r]&63];return t};const n0=()=>({isGuest:!0,id:r0("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),s0=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}`},Tc=r=>r?typeof r=="object"?{...r}:r:void 0,o0=(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-${s0(e)}`,annotation:t,type:n,purpose:s,value:o,creator:Tc(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),a0=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});i0();const l0=(r,t={strict:!0,invertY:!1})=>({parse:e=>h0(e,t),serialize:e=>c0(e,r,t)}),h0=(r,t={strict:!0,invertY:!1})=>{const e=r.id||vc(),{creator:i,created:n,modified:s,body:o,...a}=r,l=o0(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=ay(c)?ly(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?vy(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:Tc(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},c0=(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?hy(i.geometry):xy(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:a0(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,typeof c.target!="string"&&"annotation"in c.target&&delete c.target.annotation,c},Di=[];function u0(r,t=Rt){let e;const i=new Set;function n(a){if(Kt(r,a)&&(r=a,e)){const l=!Di.length;for(const h of i)h[1](),Di.push(h,r);if(l){for(let h=0;h<Di.length;h+=2)Di[h][0](Di[h+1]);Di.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 d0=(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}`)},f0=(r,t)=>{d0(r,t);const{subscribe:e,set:i}=u0(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}},ii=(r,t,e)=>{const i=typeof t=="function"?t(r,e):t;if(i){const{fill:n,fillOpacity:s,stroke:o,strokeWidth:a,strokeOpacity:l}=i;let h="";return n&&(h+=`fill:${n};`),s||s===0?h+=`fill-opacity:${s};`:n&&(h+="fill-opacity:0.25;"),o&&(h+=`stroke:${o};`,h+=`stroke-width:${a||"1"};`,h+=`stroke-opacity:${l||"1"};`),h}},bs=(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,p0=r=>({}),Ac=r=>({grab:r[0]});function m0(r){let t,e,i,n;const s=r[8].default,o=Gg(s,r,r[7],Ac);return{c(){t=z("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)&&Hg(o,s,a,a[7],e?$g(s,a[7],l,p0):Xg(a[7]),Ac)},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 g0(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Dr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const f=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",_)},p=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)},[f,p,m,o,a,l,h,n,i]}class ua extends me{constructor(t){super(),pe(this,t,g0,m0,Kt,{shape:3,editor:4,transform:5,svgEl:6})}}function y0(r){let t,e,i,n,s,o,a,l,h=r[3]&&Sc(r);return{c(){t=z("g"),e=z("circle"),h&&h.c(),n=z("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=Ci(`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=Sc(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Ci(`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 _0(r){let t,e,i,n,s,o,a,l,h;return{c(){t=z("g"),e=z("circle"),n=z("circle"),o=z("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 Sc(r){let t,e;return{c(){t=z("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 v0(r){let t;function e(n,s){return Ne?_0:y0}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 b0(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 f(g){oe.call(this,r,g)}function p(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=Ko(Ko({},t),sc(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=sc(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,m,y,_,v]}class Bi extends me{constructor(t){super(),pe(this,t,b0,v0,Kt,{x:0,y:1,scale:2,selected:3})}}function x0(r){let t,e,i,n,s,o,a;return{c(){t=z("g"),e=z("circle"),n=z("circle"),s=z("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 w0(r){let t;return{c(){t=z("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 E0(r){let t;function e(n,s){return Ne?w0:x0}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 T0(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 Cc extends me{constructor(t){super(),pe(this,t,T0,E0,Kt,{x:0,y:1,scale:4})}}function da(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ic(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function fa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function pa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Pc(r){let t,e,i,n;return{c(){t=z("circle"),x(t,"cx",e=r[28][0]),x(t,"cy",i=r[28][1]),x(t,"r",n=wn/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=wn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function Rc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("mask"),e=z("rect"),a=z("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=wn/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=wn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Mc(r){let t,e;return t=new Bi({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){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function Dc(r){let t,e;return t=new Cc({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){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function A0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&Pc(pa(r)),C=r[6]!==void 0&&!r[7]&&Rc(fa(r)),I=Ie(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Mc(Ic(r,I,P));const F=P=>yt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Dc(da(r));return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("polygon"),R&&R.c(),C&&C.c(),c=we(),u=z("polygon"),f=we(),p=z("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(Bc).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(Oc).join(" ")),x(p,"class","a9s-inner a9s-shape-handle"),x(p,"mask",`url(#${r[19]}-inner)`),x(p,"style",r[1]),x(p,"points",m=r[5].points.map(Lc).join(" "))},m(P,E){nt(P,t,E),xt(t,e),xt(e,i),xt(e,l),R&&R.m(e,null),C&&C.m(t,null),nt(P,c,E),nt(P,u,E),nt(P,f,E),nt(P,p,E),nt(P,y,E);for(let T=0;T<M.length;T+=1)M[T]&&M[T].m(P,E);nt(P,_,E),U&&U.m(P,E),nt(P,v,E),g=!0,b||(S=[St(u,"pointerup",r[14]),St(u,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),St(p,"pointermove",r[13]),St(p,"pointerup",r[14]),St(p,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,E){if(r=P,(!g||E[0]&512&&n!==(n=r[9].x))&&x(i,"x",n),(!g||E[0]&512&&s!==(s=r[9].y))&&x(i,"y",s),(!g||E[0]&512&&o!==(o=r[9].w))&&x(i,"width",o),(!g||E[0]&512&&a!==(a=r[9].h))&&x(i,"height",a),(!g||E[0]&32&&h!==(h=r[5].points.map(Bc).join(" ")))&&x(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(pa(r),E):(R=Pc(pa(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(fa(r),E):(C=Rc(fa(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||E[0]&32&&d!==(d=r[5].points.map(Oc).join(" ")))&&x(u,"points",d),(!g||E[0]&2)&&x(p,"style",r[1]),(!g||E[0]&32&&m!==(m=r[5].points.map(Lc).join(" ")))&&x(p,"points",m),E[0]&134322472){I=Ie(r[5].points);let T;for(T=0;T<I.length;T+=1){const A=Ic(r,I,T);M[T]?(M[T].p(A,E),lt(M[T],1)):(M[T]=Mc(A),M[T].c(),lt(M[T],1),M[T].m(_.parentNode,_))}for(Ee(),T=I.length;T<M.length;T+=1)F(T);Te()}r[6]!==void 0&&!r[7]?U?(U.p(da(r),E),E[0]&192&&lt(U,1)):(U=Dc(da(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 E=0;E<I.length;E+=1)lt(M[E]);lt(U),g=!0}},o(P){M=M.filter(Boolean);for(let E=0;E<M.length;E+=1)yt(M[E]);yt(U),g=!1},d(P){P&&(rt(t),rt(c),rt(u),rt(f),rt(p),rt(y),rt(_),rt(v)),R&&R.d(),C&&C.d(),ti(M,P),U&&U.d(P),b=!1,Me(S)}}}function S0(r){let t,e;return t=new ua({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[A0,({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){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const C0=250,I0=1e3,P0=12,wn=4.5,Bc=r=>r.join(","),Oc=r=>r.join(","),Lc=r=>r.join(",");function R0(r,t,e){let i,n,s;const o=Dr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=T=>{if(m.length>0||!n.some(N=>N.visible)){e(6,d=void 0);return}const[A,O]=h.elementToImage(T.offsetX,T.offsetY),D=N=>Math.pow(N[0]-A,2)+Math.pow(N[1]-O,2),L=i.points.reduce((N,k)=>D(k)<D(N)?k:N),$=n.filter(N=>N.visible).reduce((N,k)=>D(k.point)<D(N.point)?k:N),B=Math.pow(I0/c,2);D(L)<B||D($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=T=>{e(7,f=!0),T.preventDefault(),T.stopPropagation(),p=performance.now()},R=T=>A=>{if(!p||Ne||performance.now()-p>C0)return;const O=m.includes(T);A.metaKey||A.ctrlKey||A.shiftKey?O?e(8,m=m.filter(D=>D!==T)):e(8,m=[...m,T]):O&&m.length>1?e(8,m=[T]):O?e(8,m=[]):e(8,m=[T]),g()},C=(T,A,O)=>{g();let D;const L=T.geometry;m.length>1?D=L.points.map(([B,N],k)=>m.includes(k)?[B+O[0],N+O[1]]:[B,N]):A==="SHAPE"?D=L.points.map(([B,N])=>[B+O[0],N+O[1]]):D=L.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+O[0],N+O[1]]:[B,N]);const $=Ae(D);return{...T,geometry:{points:D,bounds:$}}},I=T=>async A=>{A.stopPropagation();const O=[...i.points.slice(0,T+1),n[T].point,...i.points.slice(T+1)],D=Ae(O);o("change",{...a,geometry:{points:O,bounds:D}}),await uc();const L=[...document.querySelectorAll(".a9s-handle")][T+1];if(L!=null&&L.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});L.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const T=i.points.filter((O,D)=>!m.includes(D)),A=Ae(T);o("change",{...a,geometry:{points:T,bounds:A}}),e(8,m=[])};ei(()=>{if(Ne)return;const T=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",T),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",T)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(T){oe.call(this,r,T)}function P(T){oe.call(this,r,T)}function E(T){oe.call(this,r,T)}return r.$$set=T=>{"shape"in T&&e(0,a=T.shape),"computedStyle"in T&&e(1,l=T.computedStyle),"transform"in T&&e(2,h=T.transform),"viewportScale"in T&&e(3,c=T.viewportScale),"svgEl"in T&&e(4,u=T.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Ne?[]:i.points.map((T,A)=>{const O=A===i.points.length-1?i.points[0]:i.points[A+1],D=(T[0]+O[0])/2,L=(T[1]+O[1])/2,$=Math.sqrt(Math.pow(O[0]-D,2)+Math.pow(O[1]-L,2))>P0/c;return{point:[D,L],visible:$}})),r.$$.dirty[0]&40&&e(9,s=bs(i.bounds,wn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,v,b,S,R,C,I,F,U,P,E]}class M0 extends me{constructor(t){super(),pe(this,t,R0,S0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function D0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R,C,I,M,F,U,P,E,T,A,O,D,L,$,B,N,k,X,j,K,V,ut,H,mt,Q,dt,gt,Et,Dt,Yt,jt,et,$e,ss;return Q=new Bi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),Q.$on("pointerdown",function(){Gt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Bi({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 Bi({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)}),jt=new Bi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),jt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("rect"),f=we(),p=z("rect"),g=we(),b=z("rect"),M=we(),F=z("rect"),T=we(),A=z("rect"),$=we(),B=z("rect"),j=we(),K=z("rect"),mt=we(),re(Q.$$.fragment),dt=we(),re(gt.$$.fragment),Et=we(),re(Dt.$$.fragment),Yt=we(),re(jt.$$.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(p,"class","a9s-outer"),x(p,"mask",`url(#${r[8]})`),x(p,"x",m=r[5].x),x(p,"y",y=r[5].y),x(p,"width",_=r[5].w),x(p,"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",E=r[5].w),x(A,"class","a9s-edge-handle a9s-edge-handle-right"),x(A,"x",O=r[5].x+r[5].w),x(A,"y",D=r[5].y),x(A,"height",L=r[5].h),x(A,"width",1),x(B,"class","a9s-edge-handle a9s-edge-handle-bottom"),x(B,"x",N=r[5].x),x(B,"y",k=r[5].y+r[5].h),x(B,"height",1),x(B,"width",X=r[5].w),x(K,"class","a9s-edge-handle a9s-edge-handle-left"),x(K,"x",V=r[5].x),x(K,"y",ut=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,f,G),nt(Y,p,G),nt(Y,g,G),nt(Y,b,G),nt(Y,M,G),nt(Y,F,G),nt(Y,T,G),nt(Y,A,G),nt(Y,$,G),nt(Y,B,G),nt(Y,j,G),nt(Y,K,G),nt(Y,mt,G),Jt(Q,Y,G),nt(Y,dt,G),Jt(gt,Y,G),nt(Y,Et,G),Jt(Dt,Y,G),nt(Y,Yt,G),Jt(jt,Y,G),et=!0,$e||(ss=[St(p,"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(B,"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(p,"x",m),(!et||G&32&&y!==(y=r[5].y))&&x(p,"y",y),(!et||G&32&&_!==(_=r[5].w))&&x(p,"width",_),(!et||G&32&&v!==(v=r[5].h))&&x(p,"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&&E!==(E=r[5].w))&&x(F,"width",E),(!et||G&32&&O!==(O=r[5].x+r[5].w))&&x(A,"x",O),(!et||G&32&&D!==(D=r[5].y))&&x(A,"y",D),(!et||G&32&&L!==(L=r[5].h))&&x(A,"height",L),(!et||G&32&&N!==(N=r[5].x))&&x(B,"x",N),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&x(B,"y",k),(!et||G&32&&X!==(X=r[5].w))&&x(B,"width",X),(!et||G&32&&V!==(V=r[5].x))&&x(K,"x",V),(!et||G&32&&ut!==(ut=r[5].y))&&x(K,"y",ut),(!et||G&32&&H!==(H=r[5].h))&&x(K,"height",H);const Cr={};G&32&&(Cr.x=r[5].x),G&32&&(Cr.y=r[5].y),G&8&&(Cr.scale=r[3]),Q.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x+r[5].w),G&32&&(Ir.y=r[5].y),G&8&&(Ir.scale=r[3]),gt.$set(Ir);const Pr={};G&32&&(Pr.x=r[5].x+r[5].w),G&32&&(Pr.y=r[5].y+r[5].h),G&8&&(Pr.scale=r[3]),Dt.$set(Pr);const Rr={};G&32&&(Rr.x=r[5].x),G&32&&(Rr.y=r[5].y+r[5].h),G&8&&(Rr.scale=r[3]),jt.$set(Rr)},i(Y){et||(lt(Q.$$.fragment,Y),lt(gt.$$.fragment,Y),lt(Dt.$$.fragment,Y),lt(jt.$$.fragment,Y),et=!0)},o(Y){yt(Q.$$.fragment,Y),yt(gt.$$.fragment,Y),yt(Dt.$$.fragment,Y),yt(jt.$$.fragment,Y),et=!1},d(Y){Y&&(rt(t),rt(f),rt(p),rt(g),rt(b),rt(M),rt(F),rt(T),rt(A),rt($),rt(B),rt(j),rt(K),rt(mt),rt(dt),rt(Et),rt(Yt)),te(Q,Y),te(gt,Y),te(Dt,Y),te(jt,Y),$e=!1,Me(ss)}}}function B0(r){let t,e;return t=new ua({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[D0,({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){Jt(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function O0(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 f(m){oe.call(this,r,m)}function p(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=bs(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,f,p]}class L0 extends me{constructor(t){super(),pe(this,t,O0,B0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Nc=Object.prototype.hasOwnProperty;function ma(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--&&ma(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Nc.call(r,e)&&++i&&!Nc.call(t,e)||!(e in t)||!ma(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const N0=12,F0=(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],f=(c[0]+d[0])/2,p=(c[1]+d[1])/2,m=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>N0/t;return{point:[f,p],visible:m,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function ga(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Fc(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function kc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Uc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function ya(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function _a(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Gc(r){let t,e,i,n;return{c(){t=z("circle"),x(t,"cx",e=r[29][0]),x(t,"cy",i=r[29][1]),x(t,"r",n=En/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=En/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function $c(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("mask"),e=z("rect"),a=z("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=En/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=En/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Hc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Bi({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){Jt(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(lt(t.$$.fragment,n),e=!0)},o(n){yt(t.$$.fragment,n),e=!1},d(n){te(t,n)}}}function Xc(r){let t,e,i=Ie(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Hc(Uc(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=Uc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=Hc(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),ti(n,o)}}}function Vc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v=r[6]!==void 0&&!r[7]&&Gc(_a(r)),g=r[6]!==void 0&&!r[7]&&$c(ya(r)),b=Ie(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Xc(kc(r,b,C));const R=C=>yt(S[C],1,1,()=>{S[C]=null});return{c(){t=z("g"),e=z("defs"),i=z("mask"),n=z("rect"),h=z("path"),v&&v.c(),g&&g.c(),u=z("path"),f=z("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(f,"class","a9s-inner"),x(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),x(f,"style",r[1]),x(f,"fill-rule","evenodd"),x(f,"d",p=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,f);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(f,"pointerup",r[13]),St(f,"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(_a(r),I):(v=Gc(_a(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(ya(r),I):(g=$c(ya(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(f,"style",r[1]),(!m||I[0]&32&&p!==(p=He(r[30])))&&x(f,"d",p),I[0]&268491048){b=Ie(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=kc(r,b,M);S[M]?(S[M].p(F,I),lt(S[M],1)):(S[M]=Xc(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(),ti(S,C),y=!1,Me(_)}}}function jc(r){let t,e;return t=new Cc({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){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function k0(r){let t,e,i,n=Ie(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Vc(Fc(r,n,l));const o=l=>yt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&jc(ga(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=Fc(l,n,c);s[c]?(s[c].p(u,h),lt(s[c],1)):(s[c]=Vc(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(ga(l),h),h[0]&192&&lt(a,1)):(a=jc(ga(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)),ti(s,l),a&&a.d(l)}}}function U0(r){let t,e;return t=new ua({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[k0,({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){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const G0=250,$0=1e3,En=4.5;function H0(r,t,e){let i,n,s;const o=Dr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[O,D]=h.elementToImage(A.offsetX,A.offsetY),L=k=>Math.pow(k[0]-O,2)+Math.pow(k[1]-D,2),$=ry(i).reduce((k,X)=>L(X)<L(k)?X:k),B=n.filter(k=>k.visible).reduce((k,X)=>L(X.point)<L(k.point)?X:k),N=Math.pow($0/c,2);L($)<N||L(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,O,D)=>L=>{if(!p||Ne||performance.now()-p>G0)return;const $=N=>N.polygon===A&&N.ring===O&&N.point===D,B=m.some($);L.metaKey||L.ctrlKey||L.shiftKey?B?e(8,m=m.filter(N=>!$(N))):e(8,m=[...m,{polygon:A,ring:O,point:D}]):B&&m.length>1?e(8,m=[{polygon:A,ring:O,point:D}]):B?e(8,m=[]):e(8,m=[{polygon:A,ring:O,point:D}]),g()},C=(A,O,D)=>{g();const L=A.geometry.polygons;let $;if(O==="SHAPE")$=L.map(B=>{const N=B.rings.map((X,j)=>({points:X.points.map((K,V)=>[K[0]+D[0],K[1]+D[1]])})),k=Ae(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,X]=O.split("-").map(j=>parseInt(j));$=L.map((j,K)=>{if(K===N){const V=j.rings.map((H,mt)=>mt===k?{points:H.points.map((Q,dt)=>dt===X?[Q[0]+D[0],Q[1]+D[1]]:Q)}:H),ut=Ae(V[0].points);return{rings:V,bounds:ut}}else return j})}return{...A,geometry:{polygons:$,bounds:ia($)}}},I=A=>async O=>{O.stopPropagation();const D=n[A],L=i.polygons.map((B,N)=>{if(N===D.elementIdx){const k=B.rings.map((j,K)=>K===D.ringIdx?{points:[...j.points.slice(0,D.pointIdx+1),D.point,...j.points.slice(D.pointIdx+1)]}:j),X=Ae(k[0].points);return{rings:k,bounds:X}}else return B});o("change",{...a,geometry:{polygons:L,bounds:ia(L)}}),await uc();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:O.clientX,clientY:O.clientY,pointerId:O.pointerId,pointerType:O.pointerType,isPrimary:O.isPrimary,buttons:O.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((O,D)=>{if(m.some(L=>L.polygon===D)){const L=O.rings.map((B,N)=>{const k=m.filter(X=>X.polygon===D&&X.ring===N);return k.length&&B.points.length-k.length>=3?{points:B.points.filter((X,j)=>!k.some(K=>K.point===j))}:B}),$=Ae(L[0].points);return{rings:L,bounds:$}}else return O});!ma(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:ia(A)}}),e(8,m=[]))};ei(()=>{if(Ne)return;const A=O=>{(O.key==="Delete"||O.key==="Backspace")&&(O.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,O,D,{polygon:L,ring:$,point:B})=>L===A&&$===O&&B===D;function P(A){oe.call(this,r,A)}function E(A){oe.call(this,r,A)}function T(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?[]:F0(i,c)),r.$$.dirty[0]&40&&e(9,s=bs(i.bounds,En/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,b,S,R,C,I,F,U,P,E,T]}class X0 extends me{constructor(t){super(),pe(this,t,H0,U0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Wc=new Map([[_t.RECTANGLE,L0],[_t.POLYGON,M0],[_t.MULTIPOLYGON,X0]]),va=r=>Wc.get(r.type),zc=(r,t)=>Wc.set(r,t);function V0(r,t,e){let i;const n=Dr();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=ii(s,a,{selected:!0,hovered:!0})),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 j0 extends me{constructor(t){super(),pe(this,t,V0,null,Kt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function W0(r,t,e){const i=Dr();let{drawingMode:n}=t,{target:s}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return ei(()=>{const c=s.closest("svg"),u=[],d=(f,p,m)=>{c==null||c.addEventListener(f,p,m),u.push(()=>c==null?void 0:c.removeEventListener(f,p,m))};return e(5,h=new o({target:s,props:{addEventListener:d,drawingMode:n,transform:a,viewportScale:l}})),h.$on("create",f=>i("create",f.detail)),()=>{u.forEach(f=>f()),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 z0 extends me{constructor(t){super(),pe(this,t,W0,null,Kt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Yc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("rect"),h=z("rect"),c=z("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 Y0(r){let t,e=r[0]&&Yc(r);return{c(){t=z("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=Yc(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 q0(r,t,e){let i;const n=Dr();let{addEventListener:s}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c,u,d,f,p,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,f=c[1]),e(3,p=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,f=Math.min(u[1],c[1])),e(3,p=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,f=c[1]),e(3,p=1),e(4,m=1))}else c&&(C>300||p*m>100?(R.stopPropagation(),g()):(e(0,c=void 0),u=void 0))},g=()=>{if(p*m>15){const S={type:_t.RECTANGLE,geometry:{bounds:{minX:d,minY:f,maxX:d+p,maxY:f+m},x:d,y:f,w:p,h:m}};n("create",S)}e(0,c=void 0),u=void 0};ei(()=>{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,f,p,m,i,b,s,o,a,l]}class K0 extends me{constructor(t){super(),pe(this,t,q0,Y0,Kt,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function ba(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function qc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m=r[1]&&Kc(r);return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("polygon"),c=z("polygon"),d=z("polygon"),m&&m.c(),p=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",f=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,p,_)},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&&f!==(f=y[19])&&x(d,"points",f),y[1]?m?m.p(y,_):(m=Kc(y),m.c(),m.m(p.parentNode,p)):m&&(m.d(1),m=null)},d(y){y&&(rt(t),rt(c),rt(d),rt(p)),m&&m.d(y)}}}function Kc(r){let t,e,i;return{c(){t=z("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]&&qc(ba(r));return{c(){t=z("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(ba(i),n):(e=qc(ba(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 Q0=20,J0=1500;function t_(r,t,e){let i,n,s;const o=Dr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:c=1}=t,u,d=[],f,p,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,f=U)}},_=R=>{const C=R;if(p&&clearTimeout(p),d.length>0){if(e(10,f=h.elementToImage(C.offsetX,C.offsetY)),d.length>2){const I=ms(f,d[0])*c;e(1,m=I<Q0)}C.pointerType==="touch"&&(p=setTimeout(()=>{g()},J0))}},v=R=>{const C=R;if(p&&clearTimeout(p),l==="click"){const I=C.timeStamp-u.timeStamp,M=ms([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,f=F)}else f&&d.push(f)}else{if(!f)return;if(d.length===1&&ms(d[0],f)<=4){e(0,d=[]),e(10,f=void 0);return}C.stopImmediatePropagation(),m?b():d.push(f)}},g=()=>{if(!f)return;const R=d.slice(0,-1);if(R.length<3)return;const C={type:_t.POLYGON,geometry:{bounds:Ae(d),points:R}};ra(C)>4&&(e(0,d=[]),e(10,f=void 0),o("create",C))},b=()=>{const R={type:_t.POLYGON,geometry:{bounds:Ae(d),points:[...d]}};e(0,d=[]),e(10,f=void 0),o("create",R)};ei(()=>{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=f?m?d:[...d,f]:[]),r.$$.dirty&516&&e(3,s=n.length>0?bs(Ae(n),2/c):void 0)},[d,m,n,s,i,S,a,l,h,c,f]}class e_ extends me{constructor(t){super(),pe(this,t,t_,Z0,Kt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const xa=new Map([["rectangle",{tool:K0}],["polygon",{tool:e_}]]),xs=()=>[...xa.keys()],ws=r=>xa.get(r),Zc=(r,t,e={})=>xa.set(r,{tool:t,opts:e});function r_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("ellipse"),n=z("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 i_(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=ii(n,o))},[n,i,a,l,h,c,s,o]}class n_ extends me{constructor(t){super(),pe(this,t,i_,r_,Kt,{annotation:0,geom:6,style:7})}}function s_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("line"),n=z("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 o_(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=ii(n,o))},[n,i,l,h,c,u,s,o]}class a_ extends me{constructor(t){super(),pe(this,t,o_,s_,Kt,{annotation:0,geom:6,style:7})}}function Qc(r,t,e){const i=r.slice();return i[5]=t[e],i}function Jc(r){let t,e,i;return{c(){t=z("path"),i=z("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 l_(r){let t,e,i=Ie(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=Jc(Qc(r,i,s));return{c(){t=z("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=Qc(s,i,a);n[a]?n[a].p(l,o):(n[a]=Jc(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),ti(n,s)}}}function h_(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=ii(n,o))},[n,i,a,s,o]}class c_ extends me{constructor(t){super(),pe(this,t,h_,l_,Kt,{annotation:0,geom:3,style:4})}}function u_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("polygon"),n=z("polygon"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"points",r[2].map(d_).join(" ")),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"points",r[2].map(f_).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 d_=r=>r.join(","),f_=r=>r.join(",");function p_(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=ii(n,o))},[n,i,a,s,o]}class m_ extends me{constructor(t){super(),pe(this,t,p_,u_,Kt,{annotation:0,geom:3,style:4})}}function g_(r){let t,e,i,n,s,o,a;return{c(){t=z("g"),e=z("path"),s=z("path"),x(e,"class",i=Ci(`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=Ci(`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=Ci(`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=Ci(`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 y_(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=ii(o,l)),r.$$.dirty&16&&e(2,n=sa(a)),r.$$.dirty&16&&e(1,s=a.closed?"closed":"open")},[o,s,n,i,a,l]}class __ extends me{constructor(t){super(),pe(this,t,y_,g_,Kt,{annotation:0,geom:4,style:5})}}function v_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("rect"),n=z("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 b_(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=ii(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 x_ extends me{constructor(t){super(),pe(this,t,b_,v_,Kt,{annotation:0,geom:6,style:7})}}const w_=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]}}),E_=250,T_=(r,t)=>{const e=Dr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<E_){const{x:s,y:o}=tu(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})}}}},tu=(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 eu(r,t,e){const i=r.slice();return i[39]=t[e],i}function ru(r,t,e){const i=r.slice();return i[42]=t[e],i}function wa(r){const t=r.slice(),e=t[42].target.selector;return t[45]=e,t}function iu(r){let t=r[42],e,i,n=nu(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=nu(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 A_(r){let t,e;return t=new a_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function S_(r){let t,e;return t=new __({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function C_(r){let t,e;return t=new c_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function I_(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){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function P_(r){let t,e;return t=new x_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function R_(r){var t;let e,i;return e=new n_({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){re(e.$$.fragment)},m(n,s){Jt(e,n,s),i=!0},p(n,s){var o;const a={};s[0]&131072&&(a.annotation=n[42]),s[0]&131072&&(a.geom=(o=n[45])==null?void 0:o.geometry),s[0]&2&&(a.style=n[1]),e.$set(a)},i(n){i||(lt(e.$$.fragment,n),i=!0)},o(n){yt(e.$$.fragment,n),i=!1},d(n){te(e,n)}}}function nu(r){let t,e,i,n;const s=[R_,P_,I_,C_,S_,A_],o=[];function a(l,h){var c,u,d,f,p,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:((f=l[45])==null?void 0:f.type)===_t.MULTIPOLYGON?3:((p=l[45])==null?void 0:p.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 su(r){let t=Le(r[42])&&!r[10](r[42]),e,i,n=t&&iu(wa(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(wa(s),o),o[0]&132096&&lt(n,1)):(n=iu(wa(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 ou(r){let t,e,i,n;const s=[D_,M_],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 M_(r){let t=`${r[2]}-${r[7]}`,e,i,n=au(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=au(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 D_(r){let t,e,i=Ie(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=hu(eu(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=eu(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=hu(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),ti(n,o)}}}function au(r){let t,e;return t=new z0({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){Jt(t,i,n),e=!0},p(i,n){const s={};n[0]&256&&(s.target=i[8]),n[0]&32768&&(s.tool=i[15]),n[0]&16384&&(s.drawingMode=i[14]),n[0]&8192&&(s.transform=i[13]),n[0]&262144&&(s.viewportScale=i[18]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function lu(r){let t,e;return t=new j0({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){Jt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&256&&(s.target=r[8]),n[0]&64&&(s.editor=r[39].editor),n[0]&64&&(s.annotation=r[39].annotation),n[0]&2&&(s.style=r[1]),n[0]&8192&&(s.transform=r[13]),n[0]&262144&&(s.viewportScale=r[18]),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function hu(r){let t=r[39].annotation.id,e,i,n=lu(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=lu(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 B_(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]=su(ru(r,a,u));const h=u=>yt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&ou(r);return{c(){t=z("svg"),e=z("g");for(let u=0;u<l.length;u+=1)l[u].c();i=z("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 f=0;f<l.length;f+=1)l[f]&&l[f].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 f;for(f=0;f<a.length;f+=1){const p=ru(r,a,f);l[f]?(l[f].p(p,d),lt(l[f],1)):(l[f]=su(p),l[f].c(),lt(l[f],1),l[f].m(e,null))}for(Ee(),f=a.length;f<l.length;f+=1)h(f);Te()}r[8]?c?(c.p(r,d),d[0]&256&&lt(c,1)):(c=ou(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),ti(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,Me(o)}}}function O_(r,t,e){let i,n,s,o,a,l,h,c,u,d,f,p,m=Rt,y=()=>(m(),m=ic(A,H=>e(18,p=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=xs()[0]}=t,{user:C}=t,{visible:I=!0}=t,M=0;const F=()=>e(7,M+=1),U=()=>R,P=()=>_;let E,T,A;ei(()=>y(e(9,A=f0(v,T))));const{hover:O,selection:D,store:L}=b;Zo(r,O,H=>e(16,u=H)),Zo(r,D,H=>e(33,d=H)),Zo(r,L,H=>e(17,f=H));let $,B;const N=H=>{$&&L.unobserve($);const mt=H.filter(({editable:Q})=>Q).map(({id:Q})=>Q);mt.length>0?(e(5,B=mt.map(Q=>L.getAnnotation(Q)).filter(Q=>Q&&Le(Q))),$=Q=>{const{updated:dt}=Q.changes;e(5,B=dt==null?void 0:dt.map(gt=>gt.newValue))},L.observe($,{annotations:mt})):e(5,B=void 0)},k=H=>{const mt=vc(),Q={id:mt,bodies:[],target:{annotation:mt,selector:H.detail,creator:C,created:new Date}};L.addAnnotation(Q),D.setSelected(Q.id)},X=H=>mt=>{var Q;const{target:dt}=H,gt=10*60*1e3,Et=((Q=dt.creator)==null?void 0:Q.id)!==C.id||!dt.created||new Date().getTime()-dt.created.getTime()>gt;L.updateTarget({...dt,selector:mt.detail,created:Et?dt.created:new Date,updated:Et?new Date:void 0,updatedBy:Et?C:void 0})},j=H=>{const{x:mt,y:Q}=tu(H,T),dt=L.getAt(mt,Q,void 0,2);dt?u!==dt.id&&O.set(dt.id):O.set(void 0)},K=H=>Le(H);function V(H){us[H?"unshift":"push"](()=>{E=H,e(8,E)})}function ut(H){us[H?"unshift":"push"](()=>{T=H,e(4,T)})}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}=ws(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=w_(T)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=T_(T,L),a,(e(11,l),e(4,T))),r.$$.dirty[1]&4&&N(d.selected),r.$$.dirty[0]&32&&e(6,h=B?B.map(H=>({annotation:H,editor:va(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,T,B,h,M,E,A,c,l,a,o,s,i,u,f,p,O,D,L,k,X,j,v,g,b,C,F,U,P,n,d,K,V,ut]}class L_ extends me{constructor(t){super(),pe(this,t,O_,B_,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 cu(r,t,e=0,i=r.length-1,n=N_){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),f=Math.max(e,Math.floor(t-h*u/l+d)),p=Math.min(i,Math.floor(t+(l-h)*u/l+d));cu(r,t,f,p,n)}const s=r[t];let o=e,a=i;for(Tn(r,e,t),n(r[i],s)>0&&Tn(r,e,i);o<a;){for(Tn(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?Tn(r,e,a):(a++,Tn(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function Tn(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function N_(r,t){return r<t?-1:r>t?1:0}class F_{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(!Ts(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;Ts(t,l)&&(e.leaf?i.push(a):Ta(t,l)?this._all(a,i):s.push(a))}e=s.pop()}return i}collides(t){let e=this.data;if(!Ts(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(Ts(t,o)){if(e.leaf||Ta(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=Li([]),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=k_(t,i.children,e);if(c!==-1)return i.children.splice(c,1),s.push(i),this._condense(s),this}!h&&!i.leaf&&Ta(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=Li(t.slice(e,i+1)),Oi(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=Li([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));uu(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);uu(t,c,u,l,this.compareMinY);for(let d=c;d<=u;d+=l){const f=Math.min(d+l-1,u);a.children.push(this._build(t,d,f,n-1))}}return Oi(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=Ea(h),u=$_(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),Sn(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=Li(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Oi(i,this.toBBox),Oi(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Li([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Oi(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=An(t,0,a,this.toBBox),h=An(t,a,i,this.toBBox),c=H_(l,h),u=Ea(l)+Ea(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:U_,s=t.leaf?this.compareMinY:G_,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=An(t,0,e,s),a=An(t,i-e,i,s);let l=Es(o)+Es(a);for(let h=e;h<i-e;h++){const c=t.children[h];Sn(o,t.leaf?s(c):c),l+=Es(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];Sn(a,t.leaf?s(c):c),l+=Es(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)Sn(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():Oi(t[e],this.toBBox)}}function k_(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 Oi(r,t){An(r,0,r.children.length,t,r)}function An(r,t,e,i,n){n||(n=Li(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];Sn(n,r.leaf?i(o):o)}return n}function Sn(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 U_(r,t){return r.minX-t.minX}function G_(r,t){return r.minY-t.minY}function Ea(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Es(r){return r.maxX-r.minX+(r.maxY-r.minY)}function $_(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 H_(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 Ta(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function Ts(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Li(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function uu(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;cu(r,o,t,e,n),s.push(t,o,o,e)}}const X_=()=>{const r=new F_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!gs(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(!gs(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||Zg(c.selector,o,a,l));return h.length>0?(h.sort((c,u)=>ra(c.selector)-ra(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(gs(c)){const{minX:u,minY:d,maxX:f,maxY:p}=c.selector.geometry.bounds;return[...h,{minX:u,minY:d,maxX:f,maxY:p,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)}}},V_=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}}),du=r=>{const t=Xy(),e=X_(),i=Iy(t,r.userSelectAction,r.adapter),n=Cy(t),s=zy();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}},j_=r=>{const t=du(r);return{...t,store:V_(t.store)}},W_=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},fu=r=>{const t=W_(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},pu=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?fu(r):e),mu=(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}),gu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,yu=(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=()=>{gu?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return gu?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},z_=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=mu(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:xc.EDIT,theme:"light"}),n=j_(i),{selection:s,store:o}=n,a=Wy(o,i.initialHistory),l=Yy(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=yu(a);let u=n0();pu(e,h,i.theme);const d=new L_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",E=>{const{originalEvent:T,annotation:A}=E.detail;A?s.userSelect(A.id,T):s.isEmpty()||s.clear()});const f=Ky(n,a,i.adapter),p=()=>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=(E,T,A)=>Zc(E,T,A),b=(E,T)=>zc(E,T),S=E=>{if(!ws(E))throw`No drawing tool named ${E}`;d.$set({toolName:E})},R=E=>d.$set({drawingEnabled:E}),C=E=>d.$set({preferredDrawingMode:E}),I=E=>{console.warn("Filter not implemented yet")},M=E=>d.$set({style:E}),F=E=>pu(e,h,E),U=E=>{u=E,d.$set({user:E})},P=E=>d.$set({visible:E});return{...f,cancelDrawing:p,destroy:m,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:xs,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:b,setDrawingEnabled:R,setDrawingMode:C,setDrawingTool:S,setFilter:I,setStyle:M,setTheme:F,setUser:U,setVisible:P,element:h,state:n}};function Ft(){}function Aa(r,t){for(const e in t)r[e]=t[e];return r}function _u(r){return r()}function vu(){return Object.create(null)}function Fe(r){r.forEach(_u)}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 Y_(r){return Object.keys(r).length===0}function q_(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 Cn(r,t,e){r.$$.on_destroy.push(q_(t,e))}function bu(r,t,e,i){if(r){const n=xu(r,t,e,i);return r[0](n)}}function xu(r,t,e,i){return r[1]&&i?Aa(e.ctx.slice(),r[1](i(t))):e.ctx}function wu(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 Eu(r,t,e,i,n,s){if(n){const o=xu(t,e,i,s);r.p(o,n)}}function Tu(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 Au(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Su(r){return r??""}const Sa=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 Lr(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 Ca(r){return document.createTextNode(r)}function Se(){return Ca(" ")}function Pe(){return Ca("")}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 K_(r){return Array.from(r.childNodes)}function Z_(r,t){t=""+t,r.data!==t&&(r.data=t)}function Nr(r,t,e){r.classList.toggle(t,!!e)}function Q_(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let In;function Pn(r){In=r}function Ia(){if(!In)throw new Error("Function called outside component initialization");return In}function ni(r){Ia().$$.on_mount.push(r)}function J_(r){Ia().$$.on_destroy.push(r)}function Ni(){const r=Ia();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=Q_(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 Fi=[],As=[];let ki=[];const Cu=[],Iu=Promise.resolve();let Pa=!1;function Pu(){Pa||(Pa=!0,Iu.then(Mu))}function Ru(){return Pu(),Iu}function Ra(r){ki.push(r)}const Ma=new Set;let Ui=0;function Mu(){if(Ui!==0)return;const r=In;do{try{for(;Ui<Fi.length;){const t=Fi[Ui];Ui++,Pn(t),tv(t.$$)}}catch(t){throw Fi.length=0,Ui=0,t}for(Pn(null),Fi.length=0,Ui=0;As.length;)As.pop()();for(let t=0;t<ki.length;t+=1){const e=ki[t];Ma.has(e)||(Ma.add(e),e())}ki.length=0}while(Fi.length);for(;Cu.length;)Cu.pop()();Pa=!1,Ma.clear(),Pn(r)}function tv(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(Ra)}}function ev(r){const t=[],e=[];ki.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),ki=t}const Ss=new Set;let si;function le(){si={r:0,c:[],p:si}}function he(){si.r||Fe(si.c),si=si.p}function q(r,t){r&&r.i&&(Ss.delete(r),r.i(t))}function at(r,t,e,i){if(r&&r.o){if(Ss.has(r))return;Ss.add(r),si.c.push(()=>{Ss.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),Ra(()=>{const s=r.$$.on_mount.map(_u).filter(Zt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Fe(s),r.$$.on_mount=[]}),n.forEach(Ra)}function Ot(r,t){const e=r.$$;e.fragment!==null&&(ev(e.after_update),Fe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function rv(r,t){r.$$.dirty[0]===-1&&(Fi.push(r),Pu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Wt(r,t,e,i,n,s,o=null,a=[-1]){const l=In;Pn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Ft,not_equal:n,bound:vu(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:vu(),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,...f)=>{const p=f.length?f[0]:d;return h.ctx&&n(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&rv(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=K_(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),Mu()}Pn(l)}class zt{constructor(){jh(this,"$$");jh(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&&!Y_(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const iv="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(iv);var tr=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(tr||{}),Rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Da(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function nv(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 Du={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,f=h.y-u;if(d!==0||f!==0){var p=((a.x-c)*d+(a.y-u)*f)/(d*d+f*f);p>1?(c=h.x,u=h.y):p>0&&(c+=d*p,u+=f*p)}return d=a.x-c,f=a.y-u,d*d+f*f}function i(a,l){for(var h=a[0],c=[h],u,d=1,f=a.length;d<f;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,f,p=l+1;p<h;p++){var m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}d>c&&(f-l>1&&n(a,l,f,c,u),u.push(a[f]),h-f>1&&n(a,f,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})()})(Du);var sv=Du.exports;const ov=Da(sv),Gi=(r,t)=>t,er=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}},Cs=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)},Is=(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},av=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},Bu=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return ov(e,t,!0).map(i=>[i.x,i.y])},lv=(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))},hv={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,f=h*c-l*u;return d*d/(s*s)+f*f/(o*o)<=1}};Gi(tr.ELLIPSE,hv);const cv={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=lv([n,s],[o,a]);return l/h<=i}};Gi(tr.LINE,cv);const uv={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=Cs(n.points),a=s.reduce((l,h)=>l+Cs(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(Is(s.points,t,e)){let a=!1;for(const l of o)if(Is(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Ps=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return er(t)},$i=r=>r.rings.map(e=>av(e.points)).join(" "),dv=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),fv=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=Bu(a.points,t);return{...a,points:l}}),o=er(s[0].points);return{...n,rings:s,bounds:o}}),i=Ps(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Gi(tr.MULTIPOLYGON,uv);const pv={area:r=>{const t=r.geometry.points;return Cs(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Is(i,t,e)}},mv=(r,t=1)=>{const e=Bu(r.geometry.points,t),i=er(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Gi(tr.POLYGON,pv);const gv={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Ou(t.points,t.closed);return Cs(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Ou(n.points,n.closed);return Is(s,t,e)}else return yv(n,[t,e],i)}},Ou=(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=Lu(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},Lu=(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},yv=(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=Lu(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(Nu(t,a[l],a[l+1])<=e)return!0}else if(Nu(t,n.point,s.point)<=e)return!0}return!1},Nu=(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};Gi(tr.POLYLINE,gv);const _v={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};Gi(tr.RECTANGLE,_v);const _e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function vv(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 Ba;const bv=new Uint8Array(16);function xv(){if(!Ba){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ba=crypto.getRandomValues.bind(crypto)}return Ba(bv)}const Fu={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function wv(r,t,e){var n;r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??xv();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,vv(i)}function Ev(r,t,e){return Fu.randomUUID&&!r?Fu.randomUUID():wv(r)}const Tv=(r,t,e)=>{const i=typeof t=="function"?t(r,e):t;if(i){const{fill:n,fillOpacity:s,stroke:o,strokeWidth:a,strokeOpacity:l}=i;let h="";return n&&(h+=`fill:${n};`),s||s===0?h+=`fill-opacity:${s};`:n&&(h+="fill-opacity:0.25;"),o&&(h+=`stroke:${o};`,h+=`stroke-width:${a||"1"};`,h+=`stroke-opacity:${l||"1"};`),h}},Oa=(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}},Fr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Av=r=>({}),ku=r=>({grab:r[0]});function Sv(r){let t,e,i,n;const s=r[8].default,o=bu(s,r,r[7],ku);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)&&Eu(o,s,a,a[7],e?wu(s,a[7],l,Av):Tu(a[7]),ku)},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 Cv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Ni();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const f=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",_)},p=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)},[f,p,m,o,a,l,h,n,i]}class La extends zt{constructor(t){super(),Wt(this,t,Cv,Sv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function Iv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Uu(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=Su(`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=Uu(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Su(`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 Pv(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"),Nr(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&&Nr(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 Uu(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 Rv(r){let t;function e(s,o){return Fr?Pv:Iv}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 Mv(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 f(g){ae.call(this,r,g)}function p(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=Aa(Aa({},t),Au(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=Au(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,m,y,_,v]}class Hi extends zt{constructor(t){super(),Wt(this,t,Mv,Rv,Ut,{x:0,y:1,scale:2,selected:3})}}function Dv(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 Bv(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 Ov(r){let t;function e(s,o){return Fr?Bv:Dv}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 Lv(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 Gu extends zt{constructor(t){super(),Wt(this,t,Lv,Ov,Ut,{x:0,y:1,scale:4})}}function Na(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function $u(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Fa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function ka(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Hu(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=Mn/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=Mn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function Xu(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=Mn/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=Mn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function Vu(r){let t,e;return t=new Hi({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 ju(r){let t,e;return t=new Gu({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 Nv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&Hu(ka(r)),C=r[6]!==void 0&&!r[7]&&Xu(Fa(r)),I=xe(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Vu($u(r,I,P));const F=P=>at(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&ju(Na(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"),f=Se(),p=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(Wu).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(zu).join(" ")),w(p,"class","a9s-inner a9s-shape-handle"),w(p,"mask",`url(#${r[19]}-inner)`),w(p,"style",r[1]),w(p,"points",m=r[5].points.map(Yu).join(" "))},m(P,E){ot(P,t,E),Ct(t,e),Ct(e,i),Ct(e,l),R&&R.m(e,null),C&&C.m(t,null),ot(P,c,E),ot(P,u,E),ot(P,f,E),ot(P,p,E),ot(P,y,E);for(let T=0;T<M.length;T+=1)M[T]&&M[T].m(P,E);ot(P,_,E),U&&U.m(P,E),ot(P,v,E),g=!0,b||(S=[Pt(u,"pointerup",r[14]),Pt(u,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(p,"pointermove",r[13]),Pt(p,"pointerup",r[14]),Pt(p,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,E){if(r=P,(!g||E[0]&512&&n!==(n=r[9].x))&&w(i,"x",n),(!g||E[0]&512&&s!==(s=r[9].y))&&w(i,"y",s),(!g||E[0]&512&&o!==(o=r[9].w))&&w(i,"width",o),(!g||E[0]&512&&a!==(a=r[9].h))&&w(i,"height",a),(!g||E[0]&32&&h!==(h=r[5].points.map(Wu).join(" ")))&&w(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(ka(r),E):(R=Hu(ka(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(Fa(r),E):(C=Xu(Fa(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||E[0]&32&&d!==(d=r[5].points.map(zu).join(" ")))&&w(u,"points",d),(!g||E[0]&2)&&w(p,"style",r[1]),(!g||E[0]&32&&m!==(m=r[5].points.map(Yu).join(" ")))&&w(p,"points",m),E[0]&134322472){I=xe(r[5].points);let T;for(T=0;T<I.length;T+=1){const A=$u(r,I,T);M[T]?(M[T].p(A,E),q(M[T],1)):(M[T]=Vu(A),M[T].c(),q(M[T],1),M[T].m(_.parentNode,_))}for(le(),T=I.length;T<M.length;T+=1)F(T);he()}r[6]!==void 0&&!r[7]?U?(U.p(Na(r),E),E[0]&192&&q(U,1)):(U=ju(Na(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 E=0;E<I.length;E+=1)q(M[E]);q(U),g=!0}},o(P){M=M.filter(Boolean);for(let E=0;E<M.length;E+=1)at(M[E]);at(U),g=!1},d(P){P&&(st(t),st(c),st(u),st(f),st(p),st(y),st(_),st(v)),R&&R.d(),C&&C.d(),Lr(M,P),U&&U.d(P),b=!1,Fe(S)}}}function Fv(r){let t,e;return t=new La({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[Nv,({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 kv=250,Uv=1e3,Gv=12,Mn=4.5,Wu=r=>r.join(","),zu=r=>r.join(","),Yu=r=>r.join(",");function $v(r,t,e){let i,n,s;const o=Ni();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=T=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[A,O]=h.elementToImage(T.offsetX,T.offsetY),D=k=>Math.pow(k[0]-A,2)+Math.pow(k[1]-O,2),L=i.points.reduce((k,X)=>D(X)<D(k)?X:k),$=n.filter(k=>k.visible).reduce((k,X)=>D(X.point)<D(k.point)?X:k),B=Math.pow(Uv/c,2);D(L)<B||D($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=T=>{e(7,f=!0),T.preventDefault(),T.stopPropagation(),p=performance.now()},R=T=>A=>{if(!p||Fr||performance.now()-p>kv)return;const O=m.includes(T);A.metaKey||A.ctrlKey||A.shiftKey?O?e(8,m=m.filter(D=>D!==T)):e(8,m=[...m,T]):O&&m.length>1?e(8,m=[T]):O?e(8,m=[]):e(8,m=[T]),g()},C=(T,A,O)=>{g();let D;const L=T.geometry;m.length>1?D=L.points.map(([B,N],k)=>m.includes(k)?[B+O[0],N+O[1]]:[B,N]):A==="SHAPE"?D=L.points.map(([B,N])=>[B+O[0],N+O[1]]):D=L.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+O[0],N+O[1]]:[B,N]);const $=er(D);return{...T,geometry:{points:D,bounds:$}}},I=T=>async A=>{A.stopPropagation();const O=[...i.points.slice(0,T+1),n[T].point,...i.points.slice(T+1)],D=er(O);o("change",{...a,geometry:{points:O,bounds:D}}),await Ru();const L=[...document.querySelectorAll(".a9s-handle")][T+1];if(L!=null&&L.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});L.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const T=i.points.filter((O,D)=>!m.includes(D)),A=er(T);o("change",{...a,geometry:{points:T,bounds:A}}),e(8,m=[])};ni(()=>{if(Fr)return;const T=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",T),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",T)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(T){ae.call(this,r,T)}function P(T){ae.call(this,r,T)}function E(T){ae.call(this,r,T)}return r.$$set=T=>{"shape"in T&&e(0,a=T.shape),"computedStyle"in T&&e(1,l=T.computedStyle),"transform"in T&&e(2,h=T.transform),"viewportScale"in T&&e(3,c=T.viewportScale),"svgEl"in T&&e(4,u=T.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Fr?[]:i.points.map((T,A)=>{const O=A===i.points.length-1?i.points[0]:i.points[A+1],D=(T[0]+O[0])/2,L=(T[1]+O[1])/2,B=Math.sqrt(Math.pow(O[0]-D,2)+Math.pow(O[1]-L,2))>Gv/c;return{point:[D,L],visible:B}})),r.$$.dirty[0]&40&&e(9,s=Oa(i.bounds,Mn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,v,b,S,R,C,I,F,U,P,E]}class Hv extends zt{constructor(t){super(),Wt(this,t,$v,Fv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Xv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R,C,I,M,F,U,P,E,T,A,O,D,L,$,B,N,k,X,j,K,V,ut,H,mt,Q,dt,gt,Et,Dt,Yt,jt,et,$e,ss;return Q=new Hi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),Q.$on("pointerdown",function(){Zt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Hi({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 Hi({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)}),jt=new Hi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),jt.$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"),f=Se(),p=it("rect"),g=Se(),b=it("rect"),M=Se(),F=it("rect"),T=Se(),A=it("rect"),$=Se(),B=it("rect"),j=Se(),K=it("rect"),mt=Se(),Lt(Q.$$.fragment),dt=Se(),Lt(gt.$$.fragment),Et=Se(),Lt(Dt.$$.fragment),Yt=Se(),Lt(jt.$$.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(p,"class","a9s-outer"),w(p,"mask",`url(#${r[8]})`),w(p,"x",m=r[5].x),w(p,"y",y=r[5].y),w(p,"width",_=r[5].w),w(p,"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",E=r[5].w),w(A,"class","a9s-edge-handle a9s-edge-handle-right"),w(A,"x",O=r[5].x+r[5].w),w(A,"y",D=r[5].y),w(A,"height",L=r[5].h),w(A,"width",1),w(B,"class","a9s-edge-handle a9s-edge-handle-bottom"),w(B,"x",N=r[5].x),w(B,"y",k=r[5].y+r[5].h),w(B,"height",1),w(B,"width",X=r[5].w),w(K,"class","a9s-edge-handle a9s-edge-handle-left"),w(K,"x",V=r[5].x),w(K,"y",ut=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,f,G),ot(Y,p,G),ot(Y,g,G),ot(Y,b,G),ot(Y,M,G),ot(Y,F,G),ot(Y,T,G),ot(Y,A,G),ot(Y,$,G),ot(Y,B,G),ot(Y,j,G),ot(Y,K,G),ot(Y,mt,G),Bt(Q,Y,G),ot(Y,dt,G),Bt(gt,Y,G),ot(Y,Et,G),Bt(Dt,Y,G),ot(Y,Yt,G),Bt(jt,Y,G),et=!0,$e||(ss=[Pt(p,"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(B,"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(p,"x",m),(!et||G&32&&y!==(y=r[5].y))&&w(p,"y",y),(!et||G&32&&_!==(_=r[5].w))&&w(p,"width",_),(!et||G&32&&v!==(v=r[5].h))&&w(p,"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&&E!==(E=r[5].w))&&w(F,"width",E),(!et||G&32&&O!==(O=r[5].x+r[5].w))&&w(A,"x",O),(!et||G&32&&D!==(D=r[5].y))&&w(A,"y",D),(!et||G&32&&L!==(L=r[5].h))&&w(A,"height",L),(!et||G&32&&N!==(N=r[5].x))&&w(B,"x",N),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&w(B,"y",k),(!et||G&32&&X!==(X=r[5].w))&&w(B,"width",X),(!et||G&32&&V!==(V=r[5].x))&&w(K,"x",V),(!et||G&32&&ut!==(ut=r[5].y))&&w(K,"y",ut),(!et||G&32&&H!==(H=r[5].h))&&w(K,"height",H);const Cr={};G&32&&(Cr.x=r[5].x),G&32&&(Cr.y=r[5].y),G&8&&(Cr.scale=r[3]),Q.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x+r[5].w),G&32&&(Ir.y=r[5].y),G&8&&(Ir.scale=r[3]),gt.$set(Ir);const Pr={};G&32&&(Pr.x=r[5].x+r[5].w),G&32&&(Pr.y=r[5].y+r[5].h),G&8&&(Pr.scale=r[3]),Dt.$set(Pr);const Rr={};G&32&&(Rr.x=r[5].x),G&32&&(Rr.y=r[5].y+r[5].h),G&8&&(Rr.scale=r[3]),jt.$set(Rr)},i(Y){et||(q(Q.$$.fragment,Y),q(gt.$$.fragment,Y),q(Dt.$$.fragment,Y),q(jt.$$.fragment,Y),et=!0)},o(Y){at(Q.$$.fragment,Y),at(gt.$$.fragment,Y),at(Dt.$$.fragment,Y),at(jt.$$.fragment,Y),et=!1},d(Y){Y&&(st(t),st(f),st(p),st(g),st(b),st(M),st(F),st(T),st(A),st($),st(B),st(j),st(K),st(mt),st(dt),st(Et),st(Yt)),Ot(Q,Y),Ot(gt,Y),Ot(Dt,Y),Ot(jt,Y),$e=!1,Fe(ss)}}}function Vv(r){let t,e;return t=new La({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[Xv,({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 jv(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 f(m){ae.call(this,r,m)}function p(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=Oa(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,f,p]}class Wv extends zt{constructor(t){super(),Wt(this,t,jv,Vv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var qu=Object.prototype.hasOwnProperty;function Ua(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--&&Ua(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(qu.call(r,e)&&++i&&!qu.call(t,e)||!(e in t)||!Ua(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const zv=12,Yv=(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],f=(c[0]+d[0])/2,p=(c[1]+d[1])/2,y=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>zv/t;return{point:[f,p],visible:y,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function Ga(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ku(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Zu(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Qu(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function $a(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ha(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ju(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=Dn/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=Dn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function td(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=Dn/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=Dn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function ed(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Hi({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 rd(r){let t,e,i=xe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=ed(Qu(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=Qu(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=ed(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),Lr(n,o)}}}function id(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v=r[6]!==void 0&&!r[7]&&Ju(Ha(r)),g=r[6]!==void 0&&!r[7]&&td($a(r)),b=xe(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=rd(Zu(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"),f=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=$i(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=$i(r[30])),w(f,"class","a9s-inner"),w(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),w(f,"style",r[1]),w(f,"fill-rule","evenodd"),w(f,"d",p=$i(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,f);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(f,"pointerup",r[13]),Pt(f,"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=$i(r[30])))&&w(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(Ha(r),I):(v=Ju(Ha(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p($a(r),I):(g=td($a(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=$i(r[30])))&&w(u,"d",d),(!m||I[0]&2)&&w(f,"style",r[1]),(!m||I[0]&32&&p!==(p=$i(r[30])))&&w(f,"d",p),I[0]&268491048){b=xe(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Zu(r,b,M);S[M]?(S[M].p(F,I),q(S[M],1)):(S[M]=rd(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(),Lr(S,C),y=!1,Fe(_)}}}function nd(r){let t,e;return t=new Gu({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 qv(r){let t,e,i,n=xe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=id(Ku(r,n,l));const o=l=>at(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&nd(Ga(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=Ku(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=id(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(Ga(l),h),h[0]&192&&q(a,1)):(a=nd(Ga(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)),Lr(s,l),a&&a.d(l)}}}function Kv(r){let t,e;return t=new La({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[qv,({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 Zv=250,Qv=1e3,Dn=4.5;function Jv(r,t,e){let i,n,s;const o=Ni();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(m.length>0||!n.some(X=>X.visible)){e(6,d=void 0);return}const[O,D]=h.elementToImage(A.offsetX,A.offsetY),L=X=>Math.pow(X[0]-O,2)+Math.pow(X[1]-D,2),$=dv(i).reduce((X,j)=>L(j)<L(X)?j:X),B=n.filter(X=>X.visible).reduce((X,j)=>L(j.point)<L(X.point)?j:X),N=Math.pow(Qv/c,2);L($)<N||L(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,O,D)=>L=>{if(!p||Fr||performance.now()-p>Zv)return;const $=N=>N.polygon===A&&N.ring===O&&N.point===D,B=m.some($);L.metaKey||L.ctrlKey||L.shiftKey?B?e(8,m=m.filter(N=>!$(N))):e(8,m=[...m,{polygon:A,ring:O,point:D}]):B&&m.length>1?e(8,m=[{polygon:A,ring:O,point:D}]):B?e(8,m=[]):e(8,m=[{polygon:A,ring:O,point:D}]),g()},C=(A,O,D)=>{g();const L=A.geometry.polygons;let $;if(O==="SHAPE")$=L.map(B=>{const N=B.rings.map((X,j)=>({points:X.points.map((V,ut)=>[V[0]+D[0],V[1]+D[1]])})),k=er(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,X]=O.split("-").map(j=>parseInt(j));$=L.map((j,K)=>{if(K===N){const V=j.rings.map((H,mt)=>mt===k?{points:H.points.map((dt,gt)=>gt===X?[dt[0]+D[0],dt[1]+D[1]]:dt)}:H),ut=er(V[0].points);return{rings:V,bounds:ut}}else return j})}return{...A,geometry:{polygons:$,bounds:Ps($)}}},I=A=>async O=>{O.stopPropagation();const D=n[A],L=i.polygons.map((B,N)=>{if(N===D.elementIdx){const k=B.rings.map((j,K)=>K===D.ringIdx?{points:[...j.points.slice(0,D.pointIdx+1),D.point,...j.points.slice(D.pointIdx+1)]}:j),X=er(k[0].points);return{rings:k,bounds:X}}else return B});o("change",{...a,geometry:{polygons:L,bounds:Ps(L)}}),await Ru();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:O.clientX,clientY:O.clientY,pointerId:O.pointerId,pointerType:O.pointerType,isPrimary:O.isPrimary,buttons:O.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((D,L)=>{if(m.some(B=>B.polygon===L)){const B=D.rings.map((k,X)=>{const j=m.filter(K=>K.polygon===L&&K.ring===X);return j.length&&k.points.length-j.length>=3?{points:k.points.filter((V,ut)=>!j.some(H=>H.point===ut))}:k}),N=er(B[0].points);return{rings:B,bounds:N}}else return D});!Ua(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:Ps(A)}}),e(8,m=[]))};ni(()=>{if(Fr)return;const A=O=>{(O.key==="Delete"||O.key==="Backspace")&&(O.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,O,D,{polygon:L,ring:$,point:B})=>L===A&&$===O&&B===D;function P(A){ae.call(this,r,A)}function E(A){ae.call(this,r,A)}function T(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=Fr?[]:Yv(i,c)),r.$$.dirty[0]&40&&e(9,s=Oa(i.bounds,Dn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,b,S,R,C,I,F,U,P,E,T]}class t1 extends zt{constructor(t){super(),Wt(this,t,Jv,Kv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}tr.RECTANGLE,tr.POLYGON,tr.MULTIPOLYGON;function e1(r,t,e){let i;const n=Ni();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return ni(()=>(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=Tv(s,a,{selected:!0,hovered:!0})),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 r1 extends zt{constructor(t){super(),Wt(this,t,e1,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 oi=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(oi||{}),sd=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(sd||{}),Xa=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Xa||{}),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||{}),rr=(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))(rr||{}),W=(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))(W||{}),Xi=(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))(Xi||{}),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||{}),J=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(J||{}),yr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(yr||{}),kr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(kr||{}),ir=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(ir||{}),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||{}),nr=(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))(nr||{}),Va=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(Va||{}),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||{}),sr=(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))(sr||{});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 ja=/iPhone/i,od=/iPod/i,ad=/iPad/i,ld=/\biOS-universal(?:.+)Mac\b/i,Wa=/\bAndroid(?:.+)Mobile\b/i,hd=/Android/i,Vi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Rs=/Silk/i,_r=/Windows Phone/i,cd=/\bWindows(?:.+)ARM\b/i,ud=/BlackBerry/i,dd=/BB10/i,fd=/Opera Mini/i,pd=/\b(CriOS|Chrome)(?:.+)Mobile/i,md=/Mobile(?:.+)Firefox\b/i,gd=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function i1(r){return function(t){return t.test(r)}}function yd(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=i1(e),s={apple:{phone:n(ja)&&!n(_r),ipod:n(od),tablet:!n(ja)&&(n(ad)||gd(t))&&!n(_r),universal:n(ld),device:(n(ja)||n(od)||n(ad)||n(ld)||gd(t))&&!n(_r)},amazon:{phone:n(Vi),tablet:!n(Vi)&&n(Rs),device:n(Vi)||n(Rs)},android:{phone:!n(_r)&&n(Vi)||!n(_r)&&n(Wa),tablet:!n(_r)&&!n(Vi)&&!n(Wa)&&(n(Rs)||n(hd)),device:!n(_r)&&(n(Vi)||n(Rs)||n(Wa)||n(hd))||n(/\bokhttp\b/i)},windows:{phone:n(_r),tablet:n(cd),device:n(_r)||n(cd)},other:{blackberry:n(ud),blackberry10:n(dd),opera:n(fd),firefox:n(md),chrome:n(pd),device:n(ud)||n(dd)||n(fd)||n(md)||n(pd)},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 n1=yd.default??yd,vr=n1(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var _d={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 f=new n(c,u||l,d),p=e?e+h:h;return l._events[p]?l._events[p].fn?l._events[p]=[l._events[p],f]:l._events[p].push(f):(l._events[p]=f,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,f=u.length,p=new Array(f);d<f;d++)p[d]=u[d].fn;return p},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,f,p){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,f),!0;case 6:return y.fn.call(y.context,c,u,d,f,p),!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 f=e?e+h:h;if(!this._events[f])return this;if(!c)return o(this,f),this;var p=this._events[f];if(p.fn)p.fn===c&&(!d||p.once)&&(!u||p.context===u)&&o(this,f);else{for(var m=0,y=[],_=p.length;m<_;m++)(p[m].fn!==c||d&&!p[m].once||u&&p[m].context!==u)&&y.push(p[m]);y.length?this._events[f]=y.length===1?y[0]:y:o(this,f)}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})(_d);var s1=_d.exports;const Bn=Da(s1);var za={exports:{}};za.exports=Ms,za.exports.default=Ms;function Ms(r,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:r.length,s=vd(r,0,n,e,!0),o=[];if(!s||s.next===s.prev)return o;var a,l,h,c,u,d,f;if(i&&(s=c1(r,t,s,e)),r.length>80*e){a=h=r[0],l=c=r[1];for(var p=e;p<n;p+=e)u=r[p],d=r[p+1],u<a&&(a=u),d<l&&(l=d),u>h&&(h=u),d>c&&(c=d);f=Math.max(h-a,c-l),f=f!==0?32767/f:0}return On(s,o,e,a,l,f,0),o}function vd(r,t,e,i,n){var s,o;if(n===Ka(r,t,e,i)>0)for(s=t;s<e;s+=i)o=wd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=wd(s,r[s],r[s+1],o);return o&&Ds(o,o.next)&&(Nn(o),o=o.next),o}function ai(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(Ds(e,e.next)||$t(e.prev,e,e.next)===0)){if(Nn(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function On(r,t,e,i,n,s,o){if(r){!o&&s&&m1(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?a1(r,i,n,s):o1(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Nn(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=l1(ai(r),t,e),On(r,t,e,i,n,s,2)):o===2&&h1(r,t,e,i,n,s):On(ai(r),t,e,i,n,s,1);break}}}}function o1(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,f=a>l?a>h?a:h:l>h?l:h,p=i.next;p!==t;){if(p.x>=c&&p.x<=d&&p.y>=u&&p.y<=f&&ji(n,a,s,l,o,h,p.x,p.y)&&$t(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function a1(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,f=a<l?a<h?a:h:l<h?l:h,p=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,_=Ya(f,p,t,e,i),v=Ya(m,y,t,e,i),g=r.prevZ,b=r.nextZ;g&&g.z>=_&&b&&b.z<=v;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=y&&g!==n&&g!==o&&ji(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0||(g=g.prevZ,b.x>=f&&b.x<=m&&b.y>=p&&b.y<=y&&b!==n&&b!==o&&ji(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>=f&&g.x<=m&&g.y>=p&&g.y<=y&&g!==n&&g!==o&&ji(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>=f&&b.x<=m&&b.y>=p&&b.y<=y&&b!==n&&b!==o&&ji(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 l1(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!Ds(n,s)&&bd(n,i,i.next,s)&&Ln(n,s)&&Ln(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),Nn(i),Nn(i.next),i=r=s),i=i.next}while(i!==r);return ai(i)}function h1(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&_1(o,a)){var l=xd(o,a);o=ai(o,o.next),l=ai(l,l.next),On(o,t,e,i,n,s,0),On(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function c1(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=vd(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(y1(h));for(n.sort(u1),s=0;s<n.length;s++)e=d1(n[s],e);return e}function u1(r,t){return r.x-t.x}function d1(r,t){var e=f1(r,t);if(!e)return t;var i=xd(e,r);return ai(i,i.next),ai(e,e.next)}function f1(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&&ji(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),Ln(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&p1(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function p1(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function m1(r,t,e,i){var n=r;do n.z===0&&(n.z=Ya(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,g1(n)}function g1(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 Ya(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 y1(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 ji(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 _1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!v1(r,t)&&(Ln(r,t)&&Ln(t,r)&&b1(r,t)&&($t(r.prev,r,t.prev)||$t(r,t.prev,t))||Ds(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 Ds(r,t){return r.x===t.x&&r.y===t.y}function bd(r,t,e,i){var n=Os($t(r,t,e)),s=Os($t(r,t,i)),o=Os($t(e,i,r)),a=Os($t(e,i,t));return!!(n!==s&&o!==a||n===0&&Bs(r,e,t)||s===0&&Bs(r,i,t)||o===0&&Bs(e,r,i)||a===0&&Bs(e,t,i))}function Bs(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 Os(r){return r>0?1:r<0?-1:0}function v1(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&&bd(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Ln(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 b1(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 xd(r,t){var e=new qa(r.i,r.x,r.y),i=new qa(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 wd(r,t,e,i){var n=new qa(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 Nn(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 qa(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}Ms.deviation=function(r,t,e,i){var n=t&&t.length,s=n?t[0]*e:r.length,o=Math.abs(Ka(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(Ka(r,h,c,e))}var u=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,f=i[a+1]*e,p=i[a+2]*e;u+=Math.abs((r[d]-r[p])*(r[f+1]-r[d+1])-(r[d]-r[f])*(r[p+1]-r[d+1]))}return o===0&&u===0?0:Math.abs((u-o)/o)};function Ka(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}Ms.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 x1=za.exports;const w1=Da(x1);var Ls={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Ls.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,n=r&&!r.nodeType&&r,s=typeof Rn=="object"&&Rn;(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,f=72,p=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(B){throw new RangeError(g[B])}function M(B,N){for(var k=B.length,X=[];k--;)X[k]=N(B[k]);return X}function F(B,N){var k=B.split("@"),X="";k.length>1&&(X=k[0]+"@",B=k[1]),B=B.replace(v,".");var j=B.split("."),K=M(j,N).join(".");return X+K}function U(B){for(var N=[],k=0,X=B.length,j,K;k<X;)j=B.charCodeAt(k++),j>=55296&&j<=56319&&k<X?(K=B.charCodeAt(k++),(K&64512)==56320?N.push(((j&1023)<<10)+(K&1023)+65536):(N.push(j),k--)):N.push(j);return N}function P(B){return M(B,function(N){var k="";return N>65535&&(N-=65536,k+=R(N>>>10&1023|55296),N=56320|N&1023),k+=R(N),k}).join("")}function E(B){return B-48<10?B-22:B-65<26?B-65:B-97<26?B-97:l}function T(B,N){return B+22+75*(B<26)-((N!=0)<<5)}function A(B,N,k){var X=0;for(B=k?S(B/d):B>>1,B+=S(B/N);B>b*c>>1;X+=l)B=S(B/b);return S(X+(b+1)*B/(B+u))}function O(B){var N=[],k=B.length,X,j=0,K=p,V=f,ut,H,mt,Q,dt,gt,Et,Dt,Yt;for(ut=B.lastIndexOf(m),ut<0&&(ut=0),H=0;H<ut;++H)B.charCodeAt(H)>=128&&I("not-basic"),N.push(B.charCodeAt(H));for(mt=ut>0?ut+1:0;mt<k;){for(Q=j,dt=1,gt=l;mt>=k&&I("invalid-input"),Et=E(B.charCodeAt(mt++)),(Et>=l||Et>S((a-j)/dt))&&I("overflow"),j+=Et*dt,Dt=gt<=V?h:gt>=V+c?c:gt-V,!(Et<Dt);gt+=l)Yt=l-Dt,dt>S(a/Yt)&&I("overflow"),dt*=Yt;X=N.length+1,V=A(j-Q,X,Q==0),S(j/X)>a-K&&I("overflow"),K+=S(j/X),j%=X,N.splice(j++,0,K)}return P(N)}function D(B){var N,k,X,j,K,V,ut,H,mt,Q,dt,gt=[],Et,Dt,Yt,jt;for(B=U(B),Et=B.length,N=p,k=0,K=f,V=0;V<Et;++V)dt=B[V],dt<128&&gt.push(R(dt));for(X=j=gt.length,j&&gt.push(m);X<Et;){for(ut=a,V=0;V<Et;++V)dt=B[V],dt>=N&&dt<ut&&(ut=dt);for(Dt=X+1,ut-N>S((a-k)/Dt)&&I("overflow"),k+=(ut-N)*Dt,N=ut,V=0;V<Et;++V)if(dt=B[V],dt<N&&++k>a&&I("overflow"),dt==N){for(H=k,mt=l;Q=mt<=K?h:mt>=K+c?c:mt-K,!(H<Q);mt+=l)jt=H-Q,Yt=l-Q,gt.push(R(T(Q+jt%Yt,0))),H=S(jt/Yt);gt.push(R(T(H,0))),K=A(k,Dt,X==j),k=0,++X}++k,++N}return gt.join("")}function L(B){return F(B,function(N){return y.test(N)?O(N.slice(4).toLowerCase()):N})}function $(B){return F(B,function(N){return _.test(N)?"xn--"+D(N):N})}if(o={version:"1.4.1",ucs2:{decode:U,encode:P},decode:O,encode:D,toASCII:$,toUnicode:L},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})(Rn)}(Ls,Ls.exports);var E1=Ls.exports,Wi=TypeError;const T1=nv(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Za=typeof Map=="function"&&Map.prototype,Qa=Object.getOwnPropertyDescriptor&&Za?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ns=Za&&Qa&&typeof Qa.get=="function"?Qa.get:null,Ed=Za&&Map.prototype.forEach,Ja=typeof Set=="function"&&Set.prototype,tl=Object.getOwnPropertyDescriptor&&Ja?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Fs=Ja&&tl&&typeof tl.get=="function"?tl.get:null,Td=Ja&&Set.prototype.forEach,A1=typeof WeakMap=="function"&&WeakMap.prototype,Fn=A1?WeakMap.prototype.has:null,S1=typeof WeakSet=="function"&&WeakSet.prototype,kn=S1?WeakSet.prototype.has:null,C1=typeof WeakRef=="function"&&WeakRef.prototype,Ad=C1?WeakRef.prototype.deref:null,I1=Boolean.prototype.valueOf,P1=Object.prototype.toString,R1=Function.prototype.toString,M1=String.prototype.match,el=String.prototype.slice,Ur=String.prototype.replace,D1=String.prototype.toUpperCase,Sd=String.prototype.toLowerCase,Cd=RegExp.prototype.test,Id=Array.prototype.concat,or=Array.prototype.join,B1=Array.prototype.slice,Pd=Math.floor,rl=typeof BigInt=="function"?BigInt.prototype.valueOf:null,il=Object.getOwnPropertySymbols,nl=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,zi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Un=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===zi||!0)?Symbol.toStringTag:null,Rd=Object.prototype.propertyIsEnumerable,Md=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Dd(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Cd.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Pd(-r):Pd(r);if(i!==r){var n=String(i),s=el.call(t,n.length+1);return Ur.call(n,e,"$&_")+"."+Ur.call(Ur.call(s,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Ur.call(t,e,"$&_")}var sl=T1,Bd=sl.custom,Od=kd(Bd)?Bd:null,Ld={__proto__:null,double:'"',single:"'"},O1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},ks=function r(t,e,i,n){var s=e||{};if(br(s,"quoteStyle")&&!br(Ld,s.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(br(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=br(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(br(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(br(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 Gd(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Dd(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Dd(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 ol(t)?"[Array]":"[Object]";var u=Q1(s,i);if(typeof n>"u")n=[];else if(Ud(n,t)>=0)return"[Circular]";function d(E,T,A){if(T&&(n=B1.call(n),n.push(T)),A){var O={depth:s.depth};return br(s,"quoteStyle")&&(O.quoteStyle=s.quoteStyle),r(E,O,i+1,n)}return r(E,s,i+1,n)}if(typeof t=="function"&&!Fd(t)){var f=X1(t),p=Us(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+or.call(p,", ")+" }":"")}if(kd(t)){var m=zi?Ur.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):nl.call(t);return typeof t=="object"&&!zi?Gn(m):m}if(q1(t)){for(var y="<"+Sd.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Nd(L1(_[v].value),"double",s);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+Sd.call(String(t.nodeName))+">",y}if(ol(t)){if(t.length===0)return"[]";var g=Us(t,d);return u&&!Z1(g)?"["+ll(g,u)+"]":"[ "+or.call(g,", ")+" ]"}if(F1(t)){var b=Us(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!Rd.call(t,"cause")?"{ ["+String(t)+"] "+or.call(Id.call("[cause]: "+d(t.cause),b),", ")+" }":b.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+or.call(b,", ")+" }"}if(typeof t=="object"&&o){if(Od&&typeof t[Od]=="function"&&sl)return sl(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(V1(t)){var S=[];return Ed&&Ed.call(t,function(E,T){S.push(d(T,t,!0)+" => "+d(E,t))}),$d("Map",Ns.call(t),S,u)}if(z1(t)){var R=[];return Td&&Td.call(t,function(E){R.push(d(E,t))}),$d("Set",Fs.call(t),R,u)}if(j1(t))return al("WeakMap");if(Y1(t))return al("WeakSet");if(W1(t))return al("WeakRef");if(U1(t))return Gn(d(Number(t)));if($1(t))return Gn(d(rl.call(t)));if(G1(t))return Gn(I1.call(t));if(k1(t))return Gn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Rn<"u"&&t===Rn)return"{ [object globalThis] }";if(!N1(t)&&!Fd(t)){var C=Us(t,d),I=Md?Md(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",F=!I&&Un&&Object(t)===t&&Un in t?el.call(Gr(t),8,-1):M?"Object":"",U=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",P=U+(F||M?"["+or.call(Id.call([],F||[],M||[]),": ")+"] ":"");return C.length===0?P+"{}":u?P+"{"+ll(C,u)+"}":P+"{ "+or.call(C,", ")+" }"}return String(t)};function Nd(r,t,e){var i=e.quoteStyle||t,n=Ld[i];return n+r+n}function L1(r){return Ur.call(String(r),/"/g,"&quot;")}function li(r){return!Un||!(typeof r=="object"&&(Un in r||typeof r[Un]<"u"))}function ol(r){return Gr(r)==="[object Array]"&&li(r)}function N1(r){return Gr(r)==="[object Date]"&&li(r)}function Fd(r){return Gr(r)==="[object RegExp]"&&li(r)}function F1(r){return Gr(r)==="[object Error]"&&li(r)}function k1(r){return Gr(r)==="[object String]"&&li(r)}function U1(r){return Gr(r)==="[object Number]"&&li(r)}function G1(r){return Gr(r)==="[object Boolean]"&&li(r)}function kd(r){if(zi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!nl)return!1;try{return nl.call(r),!0}catch{}return!1}function $1(r){if(!r||typeof r!="object"||!rl)return!1;try{return rl.call(r),!0}catch{}return!1}var H1=Object.prototype.hasOwnProperty||function(r){return r in this};function br(r,t){return H1.call(r,t)}function Gr(r){return P1.call(r)}function X1(r){if(r.name)return r.name;var t=M1.call(R1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Ud(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 V1(r){if(!Ns||!r||typeof r!="object")return!1;try{Ns.call(r);try{Fs.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function j1(r){if(!Fn||!r||typeof r!="object")return!1;try{Fn.call(r,Fn);try{kn.call(r,kn)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function W1(r){if(!Ad||!r||typeof r!="object")return!1;try{return Ad.call(r),!0}catch{}return!1}function z1(r){if(!Fs||!r||typeof r!="object")return!1;try{Fs.call(r);try{Ns.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function Y1(r){if(!kn||!r||typeof r!="object")return!1;try{kn.call(r,kn);try{Fn.call(r,Fn)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function q1(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Gd(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Gd(el.call(r,0,t.maxStringLength),t)+i}var n=O1[t.quoteStyle||"single"];n.lastIndex=0;var s=Ur.call(Ur.call(r,n,"\\$1"),/[\x00-\x1f]/g,K1);return Nd(s,"single",t)}function K1(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":"")+D1.call(t.toString(16))}function Gn(r){return"Object("+r+")"}function al(r){return r+" { ? }"}function $d(r,t,e,i){var n=i?ll(e,i):or.call(e,", ");return r+" ("+t+") {"+n+"}"}function Z1(r){for(var t=0;t<r.length;t++)if(Ud(r[t],`
2
2
  `)>=0)return!1;return!0}function Q1(r,t){var e;if(r.indent===" ")e=" ";else if(typeof r.indent=="number"&&r.indent>0)e=or.call(Array(r.indent+1)," ");else return null;return{base:e,prev:or.call(Array(t+1),e)}}function ll(r,t){if(r.length===0)return"";var e=`
3
3
  `+t.prev+t.base;return e+or.call(r,","+e)+`
4
4
  `+t.prev}function Us(r,t){var e=ol(r),i=[];if(e){i.length=r.length;for(var n=0;n<r.length;n++)i[n]=br(r,n)?t(r[n],r):""}var s=typeof il=="function"?il(r):[],o;if(zi){o={};for(var a=0;a<s.length;a++)o["$"+s[a]]=s[a]}for(var l in r)br(r,l)&&(e&&String(Number(l))===l&&l<r.length||zi&&o["$"+l]instanceof Symbol||(Cd.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof il=="function")for(var h=0;h<s.length;h++)Rd.call(r,s[h])&&i.push("["+t(s[h])+"]: "+t(r[s[h]],r));return i}var J1=ks,tb=Wi,Gs=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},eb=function(r,t){if(r){var e=Gs(r,t);return e&&e.value}},rb=function(r,t,e){var i=Gs(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},ib=function(r,t){return r?!!Gs(r,t):!1},nb=function(r,t){if(r)return Gs(r,t,!0)},sb=function(){var t,e={assert:function(i){if(!e.has(i))throw new tb("Side channel does not contain "+J1(i))},delete:function(i){var n=t&&t.next,s=nb(t,i);return s&&n&&n===s&&(t=void 0),!!s},get:function(i){return eb(t,i)},has:function(i){return ib(t,i)},set:function(i,n){t||(t={next:void 0}),rb(t,i,n)}};return e},Hd=Object,ob=Error,ab=EvalError,lb=RangeError,hb=ReferenceError,cb=SyntaxError,ub=URIError,db=Math.abs,fb=Math.floor,pb=Math.max,mb=Math.min,gb=Math.pow,yb=Math.round,_b=Number.isNaN||function(t){return t!==t},vb=_b,bb=function(t){return vb(t)||t===0?t:t<0?-1:1},xb=Object.getOwnPropertyDescriptor,$s=xb;if($s)try{$s([],"length")}catch{$s=null}var Xd=$s,Hs=Object.defineProperty||!1;if(Hs)try{Hs({},"a",{value:1})}catch{Hs=!1}var wb=Hs,hl,Vd;function Eb(){return Vd||(Vd=1,hl=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}),hl}var cl,jd;function Tb(){if(jd)return cl;jd=1;var r=typeof Symbol<"u"&&Symbol,t=Eb();return cl=function(){return typeof r!="function"||typeof Symbol!="function"||typeof r("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},cl}var ul,Wd;function zd(){return Wd||(Wd=1,ul=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),ul}var dl,Yd;function qd(){if(Yd)return dl;Yd=1;var r=Hd;return dl=r.getPrototypeOf||null,dl}var fl,Kd;function Ab(){if(Kd)return fl;Kd=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 fl=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))},f=e(0,h.length-c.length),p=[],m=0;m<f;m++)p[m]="$"+m;if(u=Function("binder","return function ("+o(p,",")+"){ return binder.apply(this,arguments); }")(d),h.prototype){var y=function(){};y.prototype=h.prototype,u.prototype=new y,y.prototype=null}return u},fl}var pl,Zd;function Xs(){if(Zd)return pl;Zd=1;var r=Ab();return pl=Function.prototype.bind||r,pl}var ml,Qd;function gl(){return Qd||(Qd=1,ml=Function.prototype.call),ml}var yl,Jd;function tf(){return Jd||(Jd=1,yl=Function.prototype.apply),yl}var Sb=typeof Reflect<"u"&&Reflect&&Reflect.apply,Cb=Xs(),Ib=tf(),Pb=gl(),Rb=Sb,Mb=Rb||Cb.call(Pb,Ib),Db=Xs(),Bb=Wi,Ob=gl(),Lb=Mb,ef=function(t){if(t.length<1||typeof t[0]!="function")throw new Bb("a function is required");return Lb(Db,Ob,t)},_l,rf;function Nb(){if(rf)return _l;rf=1;var r=ef,t=Xd,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 _l=i&&typeof i.get=="function"?r([i.get]):typeof s=="function"?function(a){return s(a==null?a:n(a))}:!1,_l}var vl,nf;function Fb(){if(nf)return vl;nf=1;var r=zd(),t=qd(),e=Nb();return vl=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,vl}var bl,sf;function kb(){if(sf)return bl;sf=1;var r=Function.prototype.call,t=Object.prototype.hasOwnProperty,e=Xs();return bl=e.call(r,t),bl}var Tt,Ub=Hd,Gb=ob,$b=ab,Hb=lb,Xb=hb,Yi=cb,qi=Wi,Vb=ub,jb=db,Wb=fb,zb=pb,Yb=mb,qb=gb,Kb=yb,Zb=bb,of=Function,xl=function(r){try{return of('"use strict"; return ('+r+").constructor;")()}catch{}},$n=Xd,Qb=wb,wl=function(){throw new qi},Jb=$n?function(){try{return arguments.callee,wl}catch{try{return $n(arguments,"callee").get}catch{return wl}}}():wl,Ki=Tb()(),ce=Fb(),tx=qd(),ex=zd(),af=tf(),Hn=gl(),Zi={},rx=typeof Uint8Array>"u"||!ce?Tt:ce(Uint8Array),hi={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?Tt:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?Tt:ArrayBuffer,"%ArrayIteratorPrototype%":Ki&&ce?ce([][Symbol.iterator]()):Tt,"%AsyncFromSyncIteratorPrototype%":Tt,"%AsyncFunction%":Zi,"%AsyncGenerator%":Zi,"%AsyncGeneratorFunction%":Zi,"%AsyncIteratorPrototype%":Zi,"%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%":Gb,"%eval%":eval,"%EvalError%":$b,"%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%":of,"%GeneratorFunction%":Zi,"%Int8Array%":typeof Int8Array>"u"?Tt:Int8Array,"%Int16Array%":typeof Int16Array>"u"?Tt:Int16Array,"%Int32Array%":typeof Int32Array>"u"?Tt:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Ki&&ce?ce(ce([][Symbol.iterator]())):Tt,"%JSON%":typeof JSON=="object"?JSON:Tt,"%Map%":typeof Map>"u"?Tt:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Ki||!ce?Tt:ce(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Ub,"%Object.getOwnPropertyDescriptor%":$n,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?Tt:Promise,"%Proxy%":typeof Proxy>"u"?Tt:Proxy,"%RangeError%":Hb,"%ReferenceError%":Xb,"%Reflect%":typeof Reflect>"u"?Tt:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?Tt:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Ki||!ce?Tt:ce(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?Tt:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Ki&&ce?ce(""[Symbol.iterator]()):Tt,"%Symbol%":Ki?Symbol:Tt,"%SyntaxError%":Yi,"%ThrowTypeError%":Jb,"%TypedArray%":rx,"%TypeError%":qi,"%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%":Vb,"%WeakMap%":typeof WeakMap>"u"?Tt:WeakMap,"%WeakRef%":typeof WeakRef>"u"?Tt:WeakRef,"%WeakSet%":typeof WeakSet>"u"?Tt:WeakSet,"%Function.prototype.call%":Hn,"%Function.prototype.apply%":af,"%Object.defineProperty%":Qb,"%Object.getPrototypeOf%":tx,"%Math.abs%":jb,"%Math.floor%":Wb,"%Math.max%":zb,"%Math.min%":Yb,"%Math.pow%":qb,"%Math.round%":Kb,"%Math.sign%":Zb,"%Reflect.getPrototypeOf%":ex};if(ce)try{null.error}catch(r){var ix=ce(ce(r));hi["%Error.prototype%"]=ix}var nx=function r(t){var e;if(t==="%AsyncFunction%")e=xl("async function () {}");else if(t==="%GeneratorFunction%")e=xl("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=xl("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 hi[t]=e,e},lf={__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"]},Xn=Xs(),Vs=kb(),sx=Xn.call(Hn,Array.prototype.concat),ox=Xn.call(af,Array.prototype.splice),hf=Xn.call(Hn,String.prototype.replace),js=Xn.call(Hn,String.prototype.slice),ax=Xn.call(Hn,RegExp.prototype.exec),lx=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,hx=/\\(\\)?/g,cx=function(t){var e=js(t,0,1),i=js(t,-1);if(e==="%"&&i!=="%")throw new Yi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new Yi("invalid intrinsic syntax, expected opening `%`");var n=[];return hf(t,lx,function(s,o,a,l){n[n.length]=a?hf(l,hx,"$1"):o||s}),n},ux=function(t,e){var i=t,n;if(Vs(lf,i)&&(n=lf[i],i="%"+n[0]+"%"),Vs(hi,i)){var s=hi[i];if(s===Zi&&(s=nx(i)),typeof s>"u"&&!e)throw new qi("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:s}}throw new Yi("intrinsic "+t+" does not exist!")},El=function(t,e){if(typeof t!="string"||t.length===0)throw new qi("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new qi('"allowMissing" argument must be a boolean');if(ax(/^%?[^%]*%?$/,t)===null)throw new Yi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=cx(t),n=i.length>0?i[0]:"",s=ux("%"+n+"%",e),o=s.name,a=s.value,l=!1,h=s.alias;h&&(n=h[0],ox(i,sx([0,1],h)));for(var c=1,u=!0;c<i.length;c+=1){var d=i[c],f=js(d,0,1),p=js(d,-1);if((f==='"'||f==="'"||f==="`"||p==='"'||p==="'"||p==="`")&&f!==p)throw new Yi("property names with quotes must have matching quotes");if((d==="constructor"||!u)&&(l=!0),n+="."+d,o="%"+n+"%",Vs(hi,o))a=hi[o];else if(a!=null){if(!(d in a)){if(!e)throw new qi("base intrinsic for "+t+" exists, but the property is not available.");return}if($n&&c+1>=i.length){var m=$n(a,d);u=!!m,u&&"get"in m&&!("originalValue"in m.get)?a=m.get:a=a[d]}else u=Vs(a,d),a=a[d];u&&!l&&(hi[o]=a)}}return a},cf=El,uf=ef,dx=uf([cf("%String.prototype.indexOf%")]),df=function(t,e){var i=cf(t,!!e);return typeof i=="function"&&dx(t,".prototype.")>-1?uf([i]):i},fx=El,Vn=df,px=ks,mx=Wi,ff=fx("%Map%",!0),gx=Vn("Map.prototype.get",!0),yx=Vn("Map.prototype.set",!0),_x=Vn("Map.prototype.has",!0),vx=Vn("Map.prototype.delete",!0),bx=Vn("Map.prototype.size",!0),pf=!!ff&&function(){var t,e={assert:function(i){if(!e.has(i))throw new mx("Side channel does not contain "+px(i))},delete:function(i){if(t){var n=vx(t,i);return bx(t)===0&&(t=void 0),n}return!1},get:function(i){if(t)return gx(t,i)},has:function(i){return t?_x(t,i):!1},set:function(i,n){t||(t=new ff),yx(t,i,n)}};return e},xx=El,Ws=df,wx=ks,zs=pf,Ex=Wi,Qi=xx("%WeakMap%",!0),Tx=Ws("WeakMap.prototype.get",!0),Ax=Ws("WeakMap.prototype.set",!0),Sx=Ws("WeakMap.prototype.has",!0),Cx=Ws("WeakMap.prototype.delete",!0),Ix=Qi?function(){var t,e,i={assert:function(n){if(!i.has(n))throw new Ex("Side channel does not contain "+wx(n))},delete:function(n){if(Qi&&n&&(typeof n=="object"||typeof n=="function")){if(t)return Cx(t,n)}else if(zs&&e)return e.delete(n);return!1},get:function(n){return Qi&&n&&(typeof n=="object"||typeof n=="function")&&t?Tx(t,n):e&&e.get(n)},has:function(n){return Qi&&n&&(typeof n=="object"||typeof n=="function")&&t?Sx(t,n):!!e&&e.has(n)},set:function(n,s){Qi&&n&&(typeof n=="object"||typeof n=="function")?(t||(t=new Qi),Ax(t,n,s)):zs&&(e||(e=zs()),e.set(n,s))}};return i}:zs,Px=Wi,Rx=ks,Mx=sb,Dx=pf,Bx=Ix,Ox=Bx||Dx||Mx,mf=function(){var t,e={assert:function(i){if(!e.has(i))throw new Px("Side channel does not contain "+Rx(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=Ox()),t.set(i,n)}};return e},Lx=String.prototype.replace,Nx=/%20/g,Tl={RFC1738:"RFC1738",RFC3986:"RFC3986"},Al={default:Tl.RFC3986,formatters:{RFC1738:function(r){return Lx.call(r,Nx,"+")},RFC3986:function(r){return String(r)}},RFC1738:Tl.RFC1738,RFC3986:Tl.RFC3986},Fx=Al,kx=mf,Sl=Object.prototype.hasOwnProperty,ci=Array.isArray,Ys=kx(),Ji=function(t,e){return Ys.set(t,e),t},ui=function(t){return Ys.has(t)},jn=function(t){return Ys.get(t)},Cl=function(t,e){Ys.set(t,e)},ar=function(){for(var r=[],t=0;t<256;++t)r[r.length]="%"+((t<16?"0":"")+t.toString(16)).toUpperCase();return r}(),Ux=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(ci(i)){for(var n=[],s=0;s<i.length;++s)typeof i[s]<"u"&&(n[n.length]=i[s]);e.obj[e.prop]=n}}},Wn=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},Gx=function r(t,e,i){if(!e)return t;if(typeof e!="object"&&typeof e!="function"){if(ci(t)){var n=t.length;if(i&&typeof i.arrayLimit=="number"&&n>i.arrayLimit)return Ji(Wn(t.concat(e),i),n);t[n]=e}else if(t&&typeof t=="object")if(ui(t)){var s=jn(t)+1;t[s]=e,Cl(t,s)}else{if(i&&i.strictMerge)return[t,e];(i&&(i.plainObjects||i.allowPrototypes)||!Sl.call(Object.prototype,e))&&(t[e]=!0)}else return[t,e];return t}if(!t||typeof t!="object"){if(ui(e)){for(var o=Object.keys(e),a=i&&i.plainObjects?{__proto__:null,0:t}:{0:t},l=0;l<o.length;l++){var h=parseInt(o[l],10);a[h+1]=e[o[l]]}return Ji(a,jn(e)+1)}var c=[t].concat(e);return i&&typeof i.arrayLimit=="number"&&c.length>i.arrayLimit?Ji(Wn(c,i),c.length-1):c}var u=t;return ci(t)&&!ci(e)&&(u=Wn(t,i)),ci(t)&&ci(e)?(e.forEach(function(d,f){if(Sl.call(t,f)){var p=t[f];p&&typeof p=="object"&&d&&typeof d=="object"?t[f]=r(p,d,i):t[t.length]=d}else t[f]=d}),t):Object.keys(e).reduce(function(d,f){var p=e[f];if(Sl.call(d,f)?d[f]=r(d[f],p,i):d[f]=p,ui(e)&&!ui(d)&&Ji(d,jn(e)),ui(d)){var m=parseInt(f,10);String(m)===f&&m>=0&&m>jn(d)&&Cl(d,m)}return d},u)},$x=function(t,e){return Object.keys(e).reduce(function(i,n){return i[n]=e[n],i},t)},Hx=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}},Il=1024,Xx=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(f){return"%26%23"+parseInt(f.slice(2),16)+"%3B"});for(var a="",l=0;l<o.length;l+=Il){for(var h=o.length>=Il?o.slice(l,l+Il):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===Fx.RFC1738&&(d===40||d===41)){c[c.length]=h.charAt(u);continue}if(d<128){c[c.length]=ar[d];continue}if(d<2048){c[c.length]=ar[192|d>>6]+ar[128|d&63];continue}if(d<55296||d>=57344){c[c.length]=ar[224|d>>12]+ar[128|d>>6&63]+ar[128|d&63];continue}u+=1,d=65536+((d&1023)<<10|h.charCodeAt(u)&1023),c[c.length]=ar[240|d>>18]+ar[128|d>>12&63]+ar[128|d>>6&63]+ar[128|d&63]}a+=c.join("")}return a},Vx=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[e.length]={obj:o,prop:h},i[i.length]=c)}return Ux(e),t},jx=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},Wx=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},zx=function(t,e,i,n){if(ui(t)){var s=jn(t)+1;return t[s]=e,Cl(t,s),t}var o=[].concat(t,e);return o.length>i?Ji(Wn(o,{plainObjects:n}),o.length-1):o},Yx=function(t,e){if(ci(t)){for(var i=[],n=0;n<t.length;n+=1)i[i.length]=e(t[n]);return i}return e(t)},gf={arrayToObject:Wn,assign:$x,combine:zx,compact:Vx,decode:Hx,encode:Xx,isBuffer:Wx,isOverflow:ui,isRegExp:jx,markOverflow:Ji,maybeMap:Yx,merge:Gx},yf=mf,qs=gf,zn=Al,qx=Object.prototype.hasOwnProperty,_f={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},lr=Array.isArray,Kx=Array.prototype.push,vf=function(r,t){Kx.apply(r,lr(t)?t:[t])},Zx=Date.prototype.toISOString,bf=zn.default,ne={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:qs.encode,encodeValuesOnly:!1,filter:void 0,format:bf,formatter:zn.formatters[bf],indices:!1,serializeDate:function(t){return Zx.call(t)},skipNulls:!1,strictNullHandling:!1},Qx=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},Pl={},Jx=function r(t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v){for(var g=t,b=v,S=0,R=!1;(b=b.get(Pl))!==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(Pl)>"u"&&(S=0)}if(typeof c=="function"?g=c(e,g):g instanceof Date?g=f(g):i==="comma"&&lr(g)&&(g=qs.maybeMap(g,function(B){return B instanceof Date?f(B):B})),g===null){if(o)return h&&!y?h(e,ne.encoder,_,"key",p):e;g=""}if(Qx(g)||qs.isBuffer(g)){if(h){var I=y?e:h(e,ne.encoder,_,"key",p);return[m(I)+"="+m(h(g,ne.encoder,_,"value",p))]}return[m(e)+"="+m(String(g))]}var M=[];if(typeof g>"u")return M;var F;if(i==="comma"&&lr(g))y&&h&&(g=qs.maybeMap(g,h)),F=[{value:g.length>0?g.join(",")||null:void 0}];else if(lr(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),E=n&&lr(g)&&g.length===1?P+"[]":P;if(s&&lr(g)&&g.length===0)return E+"[]";for(var T=0;T<F.length;++T){var A=F[T],O=typeof A=="object"&&A&&typeof A.value<"u"?A.value:g[A];if(!(a&&O===null)){var D=d&&l?String(A).replace(/\./g,"%2E"):String(A),L=lr(g)?typeof i=="function"?i(E,D):E:E+(d?"."+D:"["+D+"]");v.set(t,S);var $=yf();$.set(Pl,v),vf(M,r(O,L,i,n,s,o,a,l,i==="comma"&&y&&lr(g)?null:h,c,u,d,f,p,m,y,_,$))}}return M},tw=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=zn.default;if(typeof t.format<"u"){if(!qx.call(zn.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var n=zn.formatters[i],s=ne.filter;(typeof t.filter=="function"||lr(t.filter))&&(s=t.filter);var o;if(t.arrayFormat in _f?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}},ew=function(r,t){var e=r,i=tw(t),n,s;typeof i.filter=="function"?(s=i.filter,e=s("",e)):lr(i.filter)&&(s=i.filter,n=s);var o=[];if(typeof e!="object"||e===null)return"";var a=_f[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var h=yf(),c=0;c<n.length;++c){var u=n[c],d=e[u];i.skipNulls&&d===null||vf(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 f=o.join(i.delimiter),p=i.addQueryPrefix===!0?"?":"";return i.charsetSentinel&&(i.charset==="iso-8859-1"?p+="utf8=%26%2310003%3B&":p+="utf8=%E2%9C%93&"),f.length>0?p+f:""},hr=gf,Ks=Object.prototype.hasOwnProperty,Rl=Array.isArray,Ht={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:hr.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictMerge:!0,strictNullHandling:!1,throwOnLimitExceeded:!1},rw=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},xf=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},iw="utf8=%26%2310003%3B",nw="utf8=%E2%9C%93",sw=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]===nw?h="utf-8":o[l]===iw&&(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,f,p;if(d===-1?(f=e.decoder(c,Ht.decoder,h,"key"),p=e.strictNullHandling?null:""):(f=e.decoder(c.slice(0,d),Ht.decoder,h,"key"),f!==null&&(p=hr.maybeMap(xf(c.slice(d+1),e,Rl(i[f])?i[f].length:0),function(y){return e.decoder(y,Ht.decoder,h,"value")}))),p&&e.interpretNumericEntities&&h==="iso-8859-1"&&(p=rw(String(p))),c.indexOf("[]=")>-1&&(p=Rl(p)?[p]:p),e.comma&&Rl(p)&&p.length>e.arrayLimit){if(e.throwOnLimitExceeded)throw new RangeError("Array limit exceeded. Only "+e.arrayLimit+" element"+(e.arrayLimit===1?"":"s")+" allowed in an array.");p=hr.combine([],p,e.arrayLimit,e.plainObjects)}if(f!==null){var m=Ks.call(i,f);m&&(e.duplicates==="combine"||c.indexOf("[]=")>-1)?i[f]=hr.combine(i[f],p,e.arrayLimit,e.plainObjects):(!m||e.duplicates==="last")&&(i[f]=p)}}return i},ow=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:xf(t,e,n),a=r.length-1;a>=0;--a){var l,h=r[a];if(h==="[]"&&e.parseArrays)hr.isOverflow(o)?l=o:l=e.allowEmptyArrays&&(o===""||e.strictNullHandling&&o===null)?[]:hr.combine([],o,e.arrayLimit,e.plainObjects);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),f=!isNaN(d)&&h!==u&&String(d)===u&&d>=0&&e.parseArrays;if(!e.parseArrays&&u==="")l={0:o};else if(f&&d<e.arrayLimit)l=[],l[d]=o;else{if(f&&e.throwOnLimitExceeded)throw new RangeError("Array limit exceeded. Only "+e.arrayLimit+" element"+(e.arrayLimit===1?"":"s")+" allowed in an array.");f?(l[d]=o,hr.markOverflow(l,d)):u!=="__proto__"&&(l[u]=o)}}o=l}return o},aw=function(t,e){var i=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t;if(e.depth<=0)return!e.plainObjects&&Ks.call(Object.prototype,i)&&!e.allowPrototypes?void 0:[i];var n=/(\[[^[\]]*])/,s=/(\[[^[\]]*])/g,o=n.exec(i),a=o?i.slice(0,o.index):i,l=[];if(a){if(!e.plainObjects&&Ks.call(Object.prototype,a)&&!e.allowPrototypes)return;l[l.length]=a}for(var h=0;(o=s.exec(i))!==null&&h<e.depth;){h+=1;var c=o[1].slice(1,-1);if(!e.plainObjects&&Ks.call(Object.prototype,c)&&!e.allowPrototypes)return;l[l.length]=o[1]}if(o){if(e.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+e.depth+" and strictDepth is true");l[l.length]="["+i.slice(o.index)+"]"}return l},lw=function(t,e,i,n){if(t){var s=aw(t,i);if(s)return ow(s,e,i,n)}},hw=function(t){if(!t)return Ht;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"?Ht.charset:t.charset,i=typeof t.duplicates>"u"?Ht.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:Ht.allowDots:!!t.allowDots;return{allowDots:n,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:Ht.allowEmptyArrays,allowPrototypes:typeof t.allowPrototypes=="boolean"?t.allowPrototypes:Ht.allowPrototypes,allowSparse:typeof t.allowSparse=="boolean"?t.allowSparse:Ht.allowSparse,arrayLimit:typeof t.arrayLimit=="number"?t.arrayLimit:Ht.arrayLimit,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:Ht.charsetSentinel,comma:typeof t.comma=="boolean"?t.comma:Ht.comma,decodeDotInKeys:typeof t.decodeDotInKeys=="boolean"?t.decodeDotInKeys:Ht.decodeDotInKeys,decoder:typeof t.decoder=="function"?t.decoder:Ht.decoder,delimiter:typeof t.delimiter=="string"||hr.isRegExp(t.delimiter)?t.delimiter:Ht.delimiter,depth:typeof t.depth=="number"||t.depth===!1?+t.depth:Ht.depth,duplicates:i,ignoreQueryPrefix:t.ignoreQueryPrefix===!0,interpretNumericEntities:typeof t.interpretNumericEntities=="boolean"?t.interpretNumericEntities:Ht.interpretNumericEntities,parameterLimit:typeof t.parameterLimit=="number"?t.parameterLimit:Ht.parameterLimit,parseArrays:t.parseArrays!==!1,plainObjects:typeof t.plainObjects=="boolean"?t.plainObjects:Ht.plainObjects,strictDepth:typeof t.strictDepth=="boolean"?!!t.strictDepth:Ht.strictDepth,strictMerge:typeof t.strictMerge=="boolean"?!!t.strictMerge:Ht.strictMerge,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:Ht.strictNullHandling,throwOnLimitExceeded:typeof t.throwOnLimitExceeded=="boolean"?t.throwOnLimitExceeded:!1}},cw=function(r,t){var e=hw(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?{__proto__:null}:{};for(var i=typeof r=="string"?sw(r,e):r,n=e.plainObjects?{__proto__:null}:{},s=Object.keys(i),o=0;o<s.length;++o){var a=s[o],l=lw(a,i[a],e,typeof r=="string");n=hr.merge(n,l,e)}return e.allowSparse===!0?n:hr.compact(n)},uw=ew,dw=cw,fw=Al,pw={formats:fw,parse:dw,stringify:uw},mw=E1;function xr(){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 gw=/^([a-z0-9.+-]+:)/i,yw=/:[0-9]*$/,_w=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,vw=["<",">",'"',"`"," ","\r",`