@annotorious/openseadragon 3.4.6 → 3.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(Zt,ve){typeof exports=="object"&&typeof module<"u"?ve(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],ve):(Zt=typeof globalThis<"u"?globalThis:Zt||self,ve(Zt.AnnotoriousOSD={},Zt.OpenSeadragon))})(this,function(Zt,ve){"use strict";var sI=Object.defineProperty;var nI=(Zt,ve,fi)=>ve in Zt?sI(Zt,ve,{enumerable:!0,configurable:!0,writable:!0,value:fi}):Zt[ve]=fi;var $t=(Zt,ve,fi)=>nI(Zt,typeof ve!="symbol"?ve+"":ve,fi);var fi=Object.prototype.hasOwnProperty;function pi(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--&&pi(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(fi.call(r,e)&&++i&&!fi.call(t,e)||!(e in t)||!pi(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var ea=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(ea||{});const xe=[];for(let r=0;r<256;++r)xe.push((r+256).toString(16).slice(1));function Fg(r,t=0){return(xe[r[t+0]]+xe[r[t+1]]+xe[r[t+2]]+xe[r[t+3]]+"-"+xe[r[t+4]]+xe[r[t+5]]+"-"+xe[r[t+6]]+xe[r[t+7]]+"-"+xe[r[t+8]]+xe[r[t+9]]+"-"+xe[r[t+10]]+xe[r[t+11]]+xe[r[t+12]]+xe[r[t+13]]+xe[r[t+14]]+xe[r[t+15]]).toLowerCase()}let ra;const kg=new Uint8Array(16);function Ug(){if(!ra){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ra=crypto.getRandomValues.bind(crypto)}return ra(kg)}const Gg=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),uu={randomUUID:Gg};function Hg(r,t,e){var i;if(uu.randomUUID&&!r)return uu.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??Ug();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,Fg(s)}const ia=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},$g=(r,t,e,i)=>({id:Hg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),Xg=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Vg=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},zg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!pi(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Yg=(r,t)=>!pi(r.target,t.target),Wg=(r,t)=>{const e=Xg(r,t),i=Vg(r,t),s=zg(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:s.length>0?s:void 0,targetUpdated:Yg(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var $r=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))($r||{});const jg=(r,t)=>{const e=new Set((r.created||[]).map(c=>c.id)),i=new Set((r.updated||[]).map(({newValue:c})=>c.id)),s=new Set((t.created||[]).map(c=>c.id)),n=new Set((t.deleted||[]).map(c=>c.id)),o=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>e.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(r.created||[]).filter(c=>!n.has(c.id)).map(c=>o.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],h=[...(r.deleted||[]).filter(c=>!s.has(c.id)),...(t.deleted||[]).filter(c=>!e.has(c.id))],u=[...(r.updated||[]).filter(({newValue:c})=>!n.has(c.id)).map(c=>{const{oldValue:d,newValue:f}=c;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return Wg(d,p)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}};let qg=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,s=e.length;i<s;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(s=>t!==s)}}});const Kg=250,Zg=(r,t)=>{const e=qg(),i=(t==null?void 0:t.changes)||[];let s=t?t.pointer:-1,n=!1,o=0;const a=p=>{if(!n){const{changes:m}=p,_=performance.now();if(_-o>Kg)i.splice(s+1),i.push(m),s=i.length-1;else{const y=i.length-1;i[y]=jg(i[y],m)}o=_}n=!1};r.observe(a,{origin:$r.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:m})=>m)),c=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>s,canUndo:()=>s>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:s}),on:(p,m)=>e.on(p,m),redo:()=>{if(i.length-1>s){n=!0;const{created:p,updated:m,deleted:_}=i[s+1];h(p),c(m),f(_),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:p,updated:m,deleted:_}=i[s];l(p),u(m),d(_),e.emit("undo",i[s]),s-=1}}}},Qg=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(y,v)=>{l.has(y)?l.get(y).push(v):l.set(y,[v])},f=(y,v)=>{const g=l.get(y);if(g){const x=g.indexOf(v);x!==-1&&g.splice(x,1)}},p=(y,v,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(x=>{if(e){const E=Array.isArray(v)?v.map(S=>e.serialize(S)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;x(E,R)}else x(v,g)})},1)},m=()=>{const{selected:y}=n,v=(y||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const x=h.find(E=>E.id===g.id);(!x||!pi(x,g))&&p("updateAnnotation",g,x)}),h=h.map(g=>v.find(({id:E})=>E===g.id)||g)};n.subscribe(({selected:y})=>{if(!(h.length===0&&y.length===0)){if(h.length===0&&y.length>0)h=y.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&y.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!pi(g,v)&&p("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),g=new Set(y.map(({id:x})=>x));h.filter(x=>!g.has(x.id)).forEach(x=>{const E=o.getAnnotation(x.id);E&&!pi(E,x)&&p("updateAnnotation",E,x)}),h=[...h.filter(x=>g.has(x.id)),...y.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}p("selectionChanged",h)}}),s.subscribe(y=>{!u&&y?p("mouseEnterAnnotation",o.getAnnotation(y)):u&&!y?p("mouseLeaveAnnotation",o.getAnnotation(u)):u&&y&&(p("mouseLeaveAnnotation",o.getAnnotation(u)),p("mouseEnterAnnotation",o.getAnnotation(y))),u=y}),a==null||a.subscribe(y=>p("viewportIntersect",y.map(v=>o.getAnnotation(v)))),o.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:v,deleted:g}=y.changes;(v||[]).forEach(x=>p("createAnnotation",x)),(g||[]).forEach(x=>p("deleteAnnotation",x)),(y.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:E})=>{const R=h.find(S=>S.id===x.id)||x;h=h.map(S=>S.id===x.id?E:S),p("updateAnnotation",E,R)})},{origin:$r.LOCAL}),o.observe(y=>{if(h){const v=new Set(h.map(x=>x.id)),g=(y.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);g.length>0&&(h=h.map(x=>g.find(R=>R.id===x.id)||x))}},{origin:$r.REMOTE});const _=y=>v=>{const{updated:g}=v;y?(g||[]).forEach(x=>p("updateAnnotation",x.oldValue,x.newValue)):(g||[]).forEach(x=>p("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:f,emit:p}},Jg=r=>t=>t.reduce((e,i)=>{const{parsed:s,error:n}=r.parse(i);return n?{parsed:e.parsed,failed:[...e.failed,i]}:s?{parsed:[...e.parsed,s],failed:e.failed}:{...e}},{parsed:[],failed:[]}),ty=(r,t,e)=>{const{store:i,selection:s}=r,n=y=>{if(e){const{parsed:v,error:g}=e.parse(y);v?i.addAnnotation(v,$r.REMOTE):console.error(g)}else i.addAnnotation(ia(y),$r.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=y=>{const v=i.getAnnotation(y);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var y;const v=(((y=s.selected)==null?void 0:y.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},c=(y,v=!0)=>fetch(y).then(g=>g.json()).then(g=>(f(g,v),g)),d=y=>{if(typeof y=="string"){const v=i.getAnnotation(y);if(i.deleteAnnotation(y),v)return e?e.serialize(v):v}else{const v=e?e.parse(y).parsed:y;if(v)return i.deleteAnnotation(v),y}},f=(y,v=!0)=>{if(e){const g=e.parseAll||Jg(e),{parsed:x,failed:E}=g(y);E.length>0&&console.warn(`Discarded ${E.length} invalid annotations`,E),i.bulkAddAnnotations(x,v,$r.REMOTE)}else i.bulkAddAnnotations(y.map(ia),v,$r.REMOTE)},p=(y,v)=>{y?s.setSelected(y,v):s.clear()},m=y=>{s.clear(),s.setUserSelectAction(y)},_=y=>{if(e){const v=e.parse(y).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(y.id);return i.updateAnnotation(ia(y)),v}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:u,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},ey="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ry=r=>crypto.getRandomValues(new Uint8Array(r)),iy=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,s=-~(1.6*i*t/r.length);return(n=t)=>{let o="";for(;;){let a=e(s),l=s|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=n)return o}}},sy=(r,t=21)=>iy(r,t|0,ry),ny=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=ey[e[r]&63];return t};const oy=()=>({isGuest:!0,id:sy("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ay=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],ly=()=>{const r=[...ay];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};ny();var hy=Object.defineProperty,uy=(r,t,e)=>t in r?hy(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Xt=(r,t,e)=>uy(r,typeof t!="symbol"?t+"":t,e);function Dt(){}function sa(r,t){for(const e in t)r[e]=t[e];return r}function cu(r){return r()}function du(){return Object.create(null)}function $e(r){r.forEach(cu)}function Vt(r){return typeof r=="function"}function le(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function cy(r){return Object.keys(r).length===0}function fu(r,...t){if(r==null){for(const i of t)i(void 0);return Dt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function na(r,t,e){r.$$.on_destroy.push(fu(t,e))}function dy(r,t,e,i){if(r){const s=pu(r,t,e,i);return r[0](s)}}function pu(r,t,e,i){return r[1]&&i?sa(e.ctx.slice(),r[1](i(t))):e.ctx}function fy(r,t,e,i){if(r[2]&&i){const s=r[2](i(e));if(t.dirty===void 0)return s;if(typeof s=="object"){const n=[],o=Math.max(t.dirty.length,s.length);for(let a=0;a<o;a+=1)n[a]=t.dirty[a]|s[a];return n}return t.dirty|s}return t.dirty}function py(r,t,e,i,s,n){if(s){const o=pu(t,e,i,n);r.p(o,s)}}function my(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 mu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function wt(r,t){r.appendChild(t)}function it(r,t,e){r.insertBefore(t,e||null)}function rt(r){r.parentNode&&r.parentNode.removeChild(r)}function mi(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 gu(r){return document.createTextNode(r)}function Oe(){return gu(" ")}function Fe(){return gu("")}function Rt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function b(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function gy(r){return Array.from(r.childNodes)}function cr(r,t,e){r.classList.toggle(t,!!e)}function yy(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Ms;function Ps(r){Ms=r}function yu(){if(!Ms)throw new Error("Function called outside component initialization");return Ms}function gi(r){yu().$$.on_mount.push(r)}function Xr(){const r=yu();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=yy(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function Ce(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const $i=[],bn=[];let Xi=[];const _u=[],vu=Promise.resolve();let oa=!1;function xu(){oa||(oa=!0,vu.then(Eu))}function bu(){return xu(),vu}function aa(r){Xi.push(r)}const la=new Set;let Vi=0;function Eu(){if(Vi!==0)return;const r=Ms;do{try{for(;Vi<$i.length;){const t=$i[Vi];Vi++,Ps(t),_y(t.$$)}}catch(t){throw $i.length=0,Vi=0,t}for(Ps(null),$i.length=0,Vi=0;bn.length;)bn.pop()();for(let t=0;t<Xi.length;t+=1){const e=Xi[t];la.has(e)||(la.add(e),e())}Xi.length=0}while($i.length);for(;_u.length;)_u.pop()();oa=!1,la.clear(),Ps(r)}function _y(r){if(r.fragment!==null){r.update(),$e(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(aa)}}function vy(r){const t=[],e=[];Xi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Xi=t}const En=new Set;let yi;function Ie(){yi={r:0,c:[],p:yi}}function Re(){yi.r||$e(yi.c),yi=yi.p}function ot(r,t){r&&r.i&&(En.delete(r),r.i(t))}function gt(r,t,e,i){if(r&&r.o){if(En.has(r))return;En.add(r),yi.c.push(()=>{En.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function ke(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function be(r){r&&r.c()}function ce(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),aa(()=>{const n=r.$$.on_mount.map(cu).filter(Vt);r.$$.on_destroy?r.$$.on_destroy.push(...n):$e(n),r.$$.on_mount=[]}),s.forEach(aa)}function de(r,t){const e=r.$$;e.fragment!==null&&(vy(e.after_update),$e(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function xy(r,t){r.$$.dirty[0]===-1&&($i.push(r),xu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Ne(r,t,e,i,s,n,o=null,a=[-1]){const l=Ms;Ps(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Dt,not_equal:s,bound:du(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:du(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let u=!1;if(h.ctx=e?e(r,t.props||{},(c,d,...f)=>{const p=f.length?f[0]:d;return h.ctx&&s(h.ctx[c],h.ctx[c]=p)&&(!h.skip_bound&&h.bound[c]&&h.bound[c](p),u&&xy(r,c)),d}):[],h.update(),u=!0,$e(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=gy(t.target);h.fragment&&h.fragment.l(c),c.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&ot(r.$$.fragment),ce(r,t.target,t.anchor),Eu()}Ps(l)}class De{constructor(){Xt(this,"$$"),Xt(this,"$$set")}$destroy(){de(this,1),this.$destroy=Dt}$on(t,e){if(!Vt(e))return Dt;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const s=i.indexOf(e);s!==-1&&i.splice(s,1)}}$set(t){this.$$set&&!cy(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const by="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(by);var Tt=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGLON="MULTIPOLYGON",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(Tt||{}),Ey={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,u=a.y-l.y;return h*h+u*u}function e(a,l,h){var u=l.x,c=l.y,d=h.x-u,f=h.y-c;if(d!==0||f!==0){var p=((a.x-u)*d+(a.y-c)*f)/(d*d+f*f);p>1?(u=h.x,c=h.y):p>0&&(u+=d*p,c+=f*p)}return d=a.x-u,f=a.y-c,d*d+f*f}function i(a,l){for(var h=a[0],u=[h],c,d=1,f=a.length;d<f;d++)c=a[d],t(c,h)>l&&(u.push(c),h=c);return h!==c&&u.push(c),u}function s(a,l,h,u,c){for(var d=u,f,p=l+1;p<h;p++){var m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}d>u&&(f-l>1&&s(a,l,f,u,c),c.push(a[f]),h-f>1&&s(a,f,h,u,c))}function n(a,l){var h=a.length-1,u=[a[0]];return s(a,0,h,l,u),u.push(a[h]),u}function o(a,l,h){if(a.length<=2)return a;var u=l!==void 0?l*l:1;return a=h?a:i(a,u),a=n(a,u),a}r.exports=o,r.exports.default=o})()})(Ey);const ha={},wn=(r,t)=>ha[r]=t,ua=r=>ha[r.type].area(r),wy=(r,t,e)=>ha[r.type].intersects(r,t,e),Ue=r=>{let t=1/0,e=1/0,i=-1/0,s=-1/0;return r.forEach(([n,o])=>{t=Math.min(t,n),e=Math.min(e,o),i=Math.max(i,n),s=Math.max(s,o)}),{minX:t,minY:e,maxX:i,maxY:s}},ca=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)},da=(r,t,e)=>{let i=!1;for(let s=0,n=r.length-1;s<r.length;n=s++){const o=r[s][0],a=r[s][1],l=r[n][0],h=r[n][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},Ty=(r,t=!0)=>{let e="M ";return r.forEach(([i,s],n)=>{n===0?e+=`${i},${s}`:e+=` L ${i},${s}`}),t&&(e+=" Z"),e},Ay={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:s,rx:n,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),u=t-i,c=e-s,d=l*u+h*c,f=h*u-l*c;return d*d/(n*n)+f*f/(o*o)<=1}};wn(Tt.ELLIPSE,Ay);const Sy={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[s,...n]=i.rings,o=ca(s.points),a=n.reduce((l,h)=>l+ca(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const s of i){const[n,...o]=s.rings;if(da(n.points,t,e)){let a=!1;for(const l of o)if(da(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},fa=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ue(t)},Ze=r=>r.rings.map(t=>Ty(t.points)).join(" "),Cy=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,s)=>[...i,...s.points],[])],[]);wn(Tt.MULTIPOLYGLON,Sy);const Iy={area:r=>{const t=r.geometry.points;return ca(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return da(i,t,e)}};wn(Tt.POLYGON,Iy);const Ry={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};wn(Tt.RECTANGLE,Ry);const ze=r=>Tn(r.target),Tn=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},My=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,s=[...e.matchAll(i)][0],[n,o,a,l,h,u,c]=s;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,u,c].map(parseFloat);return{type:Tt.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}}}},Py=r=>{const{x:t,y:e,w:i,h:s}=r;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${e},${i},${s}`}},wu="http://www.w3.org/2000/svg",Tu=r=>{const t=i=>{Array.from(i.attributes).forEach(s=>{s.name.startsWith("on")&&i.removeAttribute(s.name)})},e=r.getElementsByTagName("script");return Array.from(e).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(r.querySelectorAll("*")).forEach(t),r},Oy=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${wu}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},Au=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(wu),i=t.lookupNamespaceURI(null);return e||i?Tu(t).firstChild:Tu(Oy(t)).firstChild},ee=" ";function Ny(r){let t="";Array.isArray(r)||(r=[r]);for(let e=0;e<r.length;e++){const i=r[e];if(i.type===G.CLOSE_PATH)t+="z";else if(i.type===G.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===G.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===G.MOVE_TO)t+=(i.relative?"m":"M")+i.x+ee+i.y;else if(i.type===G.LINE_TO)t+=(i.relative?"l":"L")+i.x+ee+i.y;else if(i.type===G.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+ee+i.y1+ee+i.x2+ee+i.y2+ee+i.x+ee+i.y;else if(i.type===G.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+ee+i.y2+ee+i.x+ee+i.y;else if(i.type===G.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+ee+i.y1+ee+i.x+ee+i.y;else if(i.type===G.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+ee+i.y;else if(i.type===G.ARC)t+=(i.relative?"a":"A")+i.rX+ee+i.rY+ee+i.xRot+ee+ +i.lArcFlag+ee+ +i.sweepFlag+ee+i.x+ee+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${e}.`)}return t}function pa([r,t],e){return[r*Math.cos(e)-t*Math.sin(e),r*Math.sin(e)+t*Math.cos(e)]}function Qe(...r){for(let t=0;t<r.length;t++)if(typeof r[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof r[t]} == typeof ${r[t]}`);return!0}const Vr=Math.PI;function ma(r,t,e){r.lArcFlag=r.lArcFlag===0?0:1,r.sweepFlag=r.sweepFlag===0?0:1;let{rX:i,rY:s}=r;const{x:n,y:o}=r;if(Math.abs(i)<1e-10||Math.abs(s)<1e-10){r.rX=0,r.rY=0,r.cX=(t+n)/2,r.cY=(e+o)/2,r.phi1=0,r.phi2=0;return}i=Math.abs(r.rX),s=Math.abs(r.rY);const a=r.xRot/180*Vr,[l,h]=pa([(t-n)/2,(e-o)/2],-a),u=Math.pow(l,2)/Math.pow(i,2)+Math.pow(h,2)/Math.pow(s,2);1<u&&(i*=Math.sqrt(u),s*=Math.sqrt(u)),r.rX=i,r.rY=s;const c=Math.pow(i,2)*Math.pow(h,2)+Math.pow(s,2)*Math.pow(l,2),d=(r.lArcFlag!==r.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(s,2)-c)/c)),f=i*h/s*d,p=-s*l/i*d,m=pa([f,p],a);r.cX=m[0]+(t+n)/2,r.cY=m[1]+(e+o)/2,r.phi1=Math.atan2((h-p)/s,(l-f)/i),r.phi2=Math.atan2((-h-p)/s,(-l-f)/i),r.sweepFlag===0&&r.phi2>r.phi1&&(r.phi2-=2*Vr),r.sweepFlag===1&&r.phi2<r.phi1&&(r.phi2+=2*Vr),r.phi1*=180/Vr,r.phi2*=180/Vr}function Su(r,t,e){Qe(r,t,e);const i=r*r+t*t-e*e;if(0>i)return[];if(i===0)return[[r*e/(r*r+t*t),t*e/(r*r+t*t)]];const s=Math.sqrt(i);return[[(r*e+t*s)/(r*r+t*t),(t*e-r*s)/(r*r+t*t)],[(r*e-t*s)/(r*r+t*t),(t*e+r*s)/(r*r+t*t)]]}const _i=Math.PI/180;function Cu(r,t,e){return(1-e)*r+e*t}function Iu(r,t,e,i){return r+Math.cos(i/180*Vr)*t+Math.sin(i/180*Vr)*e}function Ru(r,t,e,i){const s=t-r,n=e-t,o=i-e,a=3*s+3*o-6*n,l=(n-s)*6,h=3*s;return Math.abs(a)<1e-6?Math.abs(l)<1e-6?[]:[-h/l]:Dy(l/a,h/a,1e-6)}function Mu(r,t,e,i,s){const n=1-s,o=n*n*n,a=3*n*n*s,l=3*n*s*s,h=s*s*s;return r*o+t*a+e*l+i*h}function Dy(r,t,e=1e-6){const i=r*r/4-t;if(i<-e)return[];if(i<=e)return[-r/2];const s=Math.sqrt(i);return[-(r/2)-s,-(r/2)+s]}function Ly(r,t,e){r.cX||ma(r,t,e);const i=r.xRot/180*Vr;if(Math.abs(r.rX)<1e-10||Math.abs(r.rY)<1e-10)return[{relative:r.relative,type:G.CURVE_TO,x1:t+(r.x-t)/3,y1:e+(r.y-e)/3,x2:t+2*(r.x-t)/3,y2:e+2*(r.y-e)/3,x:r.x,y:r.y}];const s=Math.min(r.phi1,r.phi2),n=Math.max(r.phi1,r.phi2),o=n-s,a=Math.ceil(o/90),l=new Array(a);let h=t,u=e;const c=(d,f)=>{const[p,m]=pa([d*r.rX,f*r.rY],i);return[r.cX+p,r.cY+m]};for(let d=0;d<a;d++){const f=Cu(r.phi1,r.phi2,d/a),p=Cu(r.phi1,r.phi2,(d+1)/a),m=p-f,_=4/3*Math.tan(m*_i/4),y=Math.cos(f*_i)-_*Math.sin(f*_i),v=Math.sin(f*_i)+_*Math.cos(f*_i),g=Math.cos(p*_i),x=Math.sin(p*_i),E=g+_*x,R=x-_*g,S=c(y,v),M=c(E,R),P=c(g,x),F={relative:r.relative,type:G.CURVE_TO,x:P[0],y:P[1],x1:S[0],y1:S[1],x2:M[0],y2:M[1]};r.relative&&(F.x1-=h,F.y1-=u,F.x2-=h,F.y2-=u,F.x-=h,F.y-=u),h=P[0],u=P[1],l[d]=F}return l}function ga(r,t,e){const i=t[0]-r[0],s=t[1]-r[1],n=e[0]-r[0],o=e[1]-r[1],a=i*o-s*n;if(!(Math.abs(a)<1e-10))return!1;const l=i*n+s*o,h=i*i+s*s,u=n*n+o*o;return 0<=l&&l<=u&&h<=u}function By(r,t=!0){if(r.length<2)return r;const e=re.INFO((n,o,a)=>({...n,x:n.x??o,y:n.y??a,relative:n.relative??!1})),i=[];let s=[];for(const n of r){const o=e(n);o.type===G.MOVE_TO&&s.length>0&&(t?i.push(...An(s)):i.unshift(...An(s)),s=[]),s.push(o)}return s.length>0&&(t?i.push(...An(s)):i.unshift(...An(s))),i}function An(r){var t;const e=((t=r[r.length-1])==null?void 0:t.type)===G.CLOSE_PATH,i=e?r.length-2:r.length-1,s=[{type:G.MOVE_TO,relative:!1,x:r[i].x,y:r[i].y}];for(let n=i;n>0;n--){const o=r[n],a=r[n-1];if(o.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(o.type){case G.HORIZ_LINE_TO:s.push({type:G.HORIZ_LINE_TO,relative:!1,x:a.x});break;case G.VERT_LINE_TO:s.push({type:G.VERT_LINE_TO,relative:!1,y:a.y});break;case G.LINE_TO:case G.MOVE_TO:s.push({type:G.LINE_TO,relative:!1,x:a.x,y:a.y});break;case G.CURVE_TO:s.push({type:G.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:o.x2,y1:o.y2,x2:o.x1,y2:o.y1});break;case G.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case G.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case G.ARC:throw new Error("Unsupported command: A (arc)");case G.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return e&&s.push({type:G.CLOSE_PATH}),s}function Fy(r=1e13){Qe(r);function t(e){return Math.round(e*r)/r}return function(e){return"x1"in e&&typeof e.x1<"u"&&(e.x1=t(e.x1)),"y1"in e&&typeof e.y1<"u"&&(e.y1=t(e.y1)),"x2"in e&&typeof e.x2<"u"&&(e.x2=t(e.x2)),"y2"in e&&typeof e.y2<"u"&&(e.y2=t(e.y2)),"x"in e&&typeof e.x<"u"&&(e.x=t(e.x)),"y"in e&&typeof e.y<"u"&&(e.y=t(e.y)),"rX"in e&&typeof e.rX<"u"&&(e.rX=t(e.rX)),"rY"in e&&typeof e.rY<"u"&&(e.rY=t(e.rY)),e}}function Pu(){return Je((r,t,e)=>(r.relative&&(typeof r.x1<"u"&&(r.x1+=t),typeof r.y1<"u"&&(r.y1+=e),typeof r.x2<"u"&&(r.x2+=t),typeof r.y2<"u"&&(r.y2+=e),typeof r.x<"u"&&(r.x+=t),typeof r.y<"u"&&(r.y+=e),r.relative=!1),r))}function ky(){return Je((r,t,e)=>(r.relative||(typeof r.x1<"u"&&(r.x1-=t),typeof r.y1<"u"&&(r.y1-=e),typeof r.x2<"u"&&(r.x2-=t),typeof r.y2<"u"&&(r.y2-=e),typeof r.x<"u"&&(r.x-=t),typeof r.y<"u"&&(r.y-=e),r.relative=!0),r))}function Uy(r=!0,t=!0,e=!0,i=!0){return Je((s,n,o,a,l)=>{if(isNaN(a)&&!(s.type&G.MOVE_TO))throw new Error("path must start with moveto");if(t&&s.type&G.HORIZ_LINE_TO&&(s.type=G.LINE_TO,s.y=s.relative?0:o),e&&s.type&G.VERT_LINE_TO&&(s.type=G.LINE_TO,s.x=s.relative?0:n),r&&s.type&G.CLOSE_PATH&&(s.type=G.LINE_TO,s.x=s.relative?a-n:a,s.y=s.relative?l-o:l),s.type&G.ARC&&(s.rX===0||s.rY===0)&&(s.type=G.LINE_TO,delete s.rX,delete s.rY,delete s.xRot,delete s.lArcFlag,delete s.sweepFlag),i&&s.type&G.QUAD_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x,o+s.y]:[s.x,s.y];ga(h,u,c)&&(s.type=G.LINE_TO,delete s.x1,delete s.y1)}if(i&&s.type&G.CURVE_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x2,o+s.y2]:[s.x2,s.y2],d=s.relative?[n+s.x,o+s.y]:[s.x,s.y];ga(h,u,d)&&ga(h,c,d)&&(s.type=G.LINE_TO,delete s.x1,delete s.y1,delete s.x2,delete s.y2)}return s})}function Ou(){let r=NaN,t=NaN,e=NaN,i=NaN;return Je((s,n,o)=>(s.type&G.SMOOTH_CURVE_TO&&(s.type=G.CURVE_TO,r=isNaN(r)?n:r,t=isNaN(t)?o:t,s.x1=s.relative?n-r:2*n-r,s.y1=s.relative?o-t:2*o-t),s.type&G.CURVE_TO?(r=s.relative?n+s.x2:s.x2,t=s.relative?o+s.y2:s.y2):(r=NaN,t=NaN),s.type&G.SMOOTH_QUAD_TO&&(s.type=G.QUAD_TO,e=isNaN(e)?n:e,i=isNaN(i)?o:i,s.x1=s.relative?n-e:2*n-e,s.y1=s.relative?o-i:2*o-i),s.type&G.QUAD_TO?(e=s.relative?n+s.x1:s.x1,i=s.relative?o+s.y1:s.y1):(e=NaN,i=NaN),s))}function Nu(){let r=NaN,t=NaN;return Je((e,i,s)=>{if(e.type&G.SMOOTH_QUAD_TO&&(e.type=G.QUAD_TO,r=isNaN(r)?i:r,t=isNaN(t)?s:t,e.x1=e.relative?i-r:2*i-r,e.y1=e.relative?s-t:2*s-t),e.type&G.QUAD_TO){r=e.relative?i+e.x1:e.x1,t=e.relative?s+e.y1:e.y1;const n=e.x1,o=e.y1;e.type=G.CURVE_TO,e.x1=((e.relative?0:i)+n*2)/3,e.y1=((e.relative?0:s)+o*2)/3,e.x2=(e.x+n*2)/3,e.y2=(e.y+o*2)/3}else r=NaN,t=NaN;return e})}function Je(r){let t=0,e=0,i=NaN,s=NaN;return function(n){if(isNaN(i)&&!(n.type&G.MOVE_TO))throw new Error("path must start with moveto");const o=r(n,t,e,i,s);return n.type&G.CLOSE_PATH&&(t=i,e=s),"x"in n&&typeof n.x<"u"&&(t=n.relative?t+n.x:n.x),"y"in n&&typeof n.y<"u"&&(e=n.relative?e+n.y:n.y),n.type&G.MOVE_TO&&(i=t,s=e),o}}function Gy(r=0){Qe(r);let t=NaN,e=NaN,i=NaN,s=NaN;return Je((n,o,a,l,h)=>{const u=Math.abs;let c=!1,d=0,f=0;if(n.type&G.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:o-t,f=isNaN(e)?0:a-e),n.type&(G.CURVE_TO|G.SMOOTH_CURVE_TO)?(t=n.relative?o+n.x2:n.x2,e=n.relative?a+n.y2:n.y2):(t=NaN,e=NaN),n.type&G.SMOOTH_QUAD_TO?(i=isNaN(i)?o:2*o-i,s=isNaN(s)?a:2*a-s):n.type&G.QUAD_TO?(i=n.relative?o+n.x1:n.x1,s=n.relative?a+n.y1:n.y2):(i=NaN,s=NaN),n.type&G.LINE_COMMANDS||n.type&G.ARC&&(n.rX===0||n.rY===0||!n.lArcFlag)||n.type&G.CURVE_TO||n.type&G.SMOOTH_CURVE_TO||n.type&G.QUAD_TO||n.type&G.SMOOTH_QUAD_TO){const p=typeof n.x>"u"?0:n.relative?n.x:n.x-o,m=typeof n.y>"u"?0:n.relative?n.y:n.y-a;d=isNaN(i)?typeof n.x1>"u"?d:n.relative?n.x:n.x1-o:i-o,f=isNaN(s)?typeof n.y1>"u"?f:n.relative?n.y:n.y1-a:s-a;const _=typeof n.x2>"u"?0:n.relative?n.x:n.x2-o,y=typeof n.y2>"u"?0:n.relative?n.y:n.y2-a;u(p)<=r&&u(m)<=r&&u(d)<=r&&u(f)<=r&&u(_)<=r&&u(y)<=r&&(c=!0)}return n.type&G.CLOSE_PATH&&u(o-l)<=r&&u(a-h)<=r&&(c=!0),c?[]:n})}function zr(r,t,e,i,s,n){return Qe(r,t,e,i,s,n),Je((o,a,l,h)=>{const u=o.x1,c=o.x2,d=o.relative&&!isNaN(h),f=typeof o.x<"u"?o.x:d?0:a,p=typeof o.y<"u"?o.y:d?0:l;o.type&G.HORIZ_LINE_TO&&t!==0&&(o.type=G.LINE_TO,o.y=o.relative?0:l),o.type&G.VERT_LINE_TO&&e!==0&&(o.type=G.LINE_TO,o.x=o.relative?0:a),typeof o.x<"u"&&(o.x=o.x*r+p*e+(d?0:s)),typeof o.y<"u"&&(o.y=f*t+o.y*i+(d?0:n)),typeof o.x1<"u"&&(o.x1=o.x1*r+o.y1*e+(d?0:s)),typeof o.y1<"u"&&(o.y1=u*t+o.y1*i+(d?0:n)),typeof o.x2<"u"&&(o.x2=o.x2*r+o.y2*e+(d?0:s)),typeof o.y2<"u"&&(o.y2=c*t+o.y2*i+(d?0:n));function m(y){return y*y}const _=r*i-t*e;if(typeof o.xRot<"u"&&(r!==1||t!==0||e!==0||i!==1))if(_===0)delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag,o.type=G.LINE_TO;else{const y=o.xRot*Math.PI/180,v=Math.sin(y),g=Math.cos(y),x=1/m(o.rX),E=1/m(o.rY),R=m(g)*x+m(v)*E,S=2*v*g*(x-E),M=m(v)*x+m(g)*E,P=R*i*i-S*t*i+M*t*t,F=S*(r*i+t*e)-2*(R*e*i+M*r*t),U=R*e*e-S*r*e+M*r*r,I=(Math.atan2(F,P-U)+Math.PI)%Math.PI/2,A=Math.sin(I),w=Math.cos(I);o.rX=Math.abs(_)/Math.sqrt(P*m(w)+F*A*w+U*m(A)),o.rY=Math.abs(_)/Math.sqrt(P*m(A)-F*A*w+U*m(w)),o.xRot=I*180/Math.PI}return typeof o.sweepFlag<"u"&&0>_&&(o.sweepFlag=+!o.sweepFlag),o})}function Hy(r,t=0,e=0){Qe(r,t,e);const i=Math.sin(r),s=Math.cos(r);return zr(s,i,-i,s,t-t*s+e*i,e-t*i-e*s)}function $y(r,t=0){return Qe(r,t),zr(1,0,0,1,r,t)}function Xy(r,t=r){return Qe(r,t),zr(r,0,0,t,0,0)}function Vy(r){return Qe(r),zr(1,0,Math.tan(r),1,0,0)}function zy(r){return Qe(r),zr(1,Math.tan(r),0,1,0,0)}function Yy(r=0){return Qe(r),zr(-1,0,0,1,r,0)}function Wy(r=0){return Qe(r),zr(1,0,0,-1,0,r)}function jy(){return Je((r,t,e)=>G.ARC===r.type?Ly(r,r.relative?0:t,r.relative?0:e):r)}function qy(){return Je((r,t,e)=>(r.relative&&(t=0,e=0),G.ARC===r.type&&ma(r,t,e),r))}function Du(){return r=>({...r})}function Ky(){const r=Du(),t=Pu(),e=Nu(),i=Ou(),s=Je((n,o,a)=>{const l=i(e(t(r(n))));function h(c){c>s.maxX&&(s.maxX=c),c<s.minX&&(s.minX=c)}function u(c){c>s.maxY&&(s.maxY=c),c<s.minY&&(s.minY=c)}if(l.type&G.DRAWING_COMMANDS&&(h(o),u(a)),l.type&G.HORIZ_LINE_TO&&h(l.x),l.type&G.VERT_LINE_TO&&u(l.y),l.type&G.LINE_TO&&(h(l.x),u(l.y)),l.type&G.CURVE_TO){h(l.x),u(l.y);const c=Ru(o,l.x1,l.x2,l.x);for(const f of c)0<f&&1>f&&h(Mu(o,l.x1,l.x2,l.x,f));const d=Ru(a,l.y1,l.y2,l.y);for(const f of d)0<f&&1>f&&u(Mu(a,l.y1,l.y2,l.y,f))}if(l.type&G.ARC){h(l.x),u(l.y),ma(l,o,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,f=Math.sin(c)*l.rX,p=-Math.sin(c)*l.rY,m=Math.cos(c)*l.rY,[_,y]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],v=([E,R])=>{const S=Math.atan2(R,E)*180/Math.PI;return S<_?S+360:S},g=Su(p,-d,0).map(v);for(const E of g)E>_&&E<y&&h(Iu(l.cX,d,p,E));const x=Su(m,-f,0).map(v);for(const E of x)E>_&&E<y&&u(Iu(l.cY,f,m,E))}return n});return s.minX=1/0,s.maxX=-1/0,s.minY=1/0,s.maxY=-1/0,s}const re={ROUND:Fy,TO_ABS:Pu,TO_REL:ky,NORMALIZE_HVZ:Uy,NORMALIZE_ST:Ou,QT_TO_C:Nu,INFO:Je,SANITIZE:Gy,MATRIX:zr,ROTATE:Hy,TRANSLATE:$y,SCALE:Xy,SKEW_X:Vy,SKEW_Y:zy,X_AXIS_SYMMETRY:Yy,Y_AXIS_SYMMETRY:Wy,A_TO_C:jy,ANNOTATE_ARCS:qy,CLONE:Du,CALCULATE_BOUNDS:Ky,REVERSE_PATH:By};class Lu{round(t){return this.transform(re.ROUND(t))}toAbs(){return this.transform(re.TO_ABS())}toRel(){return this.transform(re.TO_REL())}normalizeHVZ(t,e,i){return this.transform(re.NORMALIZE_HVZ(t,e,i))}normalizeST(){return this.transform(re.NORMALIZE_ST())}qtToC(){return this.transform(re.QT_TO_C())}aToC(){return this.transform(re.A_TO_C())}sanitize(t){return this.transform(re.SANITIZE(t))}translate(t,e){return this.transform(re.TRANSLATE(t,e))}scale(t,e){return this.transform(re.SCALE(t,e))}rotate(t,e,i){return this.transform(re.ROTATE(t,e,i))}matrix(t,e,i,s,n,o){return this.transform(re.MATRIX(t,e,i,s,n,o))}skewX(t){return this.transform(re.SKEW_X(t))}skewY(t){return this.transform(re.SKEW_Y(t))}xSymmetry(t){return this.transform(re.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(re.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(re.ANNOTATE_ARCS())}}const Zy=r=>r===" "||r===" "||r==="\r"||r===`
|
|
2
|
-
`,Bu=r=>48<=r.charCodeAt(0)&&r.charCodeAt(0)<=57;class Qy extends Lu{constructor(){super(),Xt(this,"curNumber",""),Xt(this,"curCommandType",-1),Xt(this,"curCommandRelative",!1),Xt(this,"canParseCommandOrComma",!0),Xt(this,"curNumberHasExp",!1),Xt(this,"curNumberHasExpDigits",!1),Xt(this,"curNumberHasDecimal",!1),Xt(this,"curArgs",[])}finish(t=[]){if(this.parse(" ",t),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return t}parse(t,e=[]){const i=s=>{e.push(s),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let s=0;s<t.length;s++){const n=t[s],o=this.curCommandType===G.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),a=Bu(n)&&(this.curNumber==="0"&&n==="0"||o);if(Bu(n)&&!a){this.curNumber+=n,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(n==="e"||n==="E"){this.curNumber+=n,this.curNumberHasExp=!0;continue}if((n==="-"||n==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=n;continue}if(n==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!o){this.curNumber+=n,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const l=Number(this.curNumber);if(isNaN(l))throw new SyntaxError(`Invalid number ending at ${s}`);if(this.curCommandType===G.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>l)throw new SyntaxError(`Expected positive number, got "${l}" at index "${s}"`)}else if((this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber!=="0"&&this.curNumber!=="1")throw new SyntaxError(`Expected a flag, got "${this.curNumber}" at index "${s}"`)}this.curArgs.push(l),this.curArgs.length===Jy[this.curCommandType]&&(G.HORIZ_LINE_TO===this.curCommandType?i({type:G.HORIZ_LINE_TO,relative:this.curCommandRelative,x:l}):G.VERT_LINE_TO===this.curCommandType?i({type:G.VERT_LINE_TO,relative:this.curCommandRelative,y:l}):this.curCommandType===G.MOVE_TO||this.curCommandType===G.LINE_TO||this.curCommandType===G.SMOOTH_QUAD_TO?(i({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),G.MOVE_TO===this.curCommandType&&(this.curCommandType=G.LINE_TO)):this.curCommandType===G.CURVE_TO?i({type:G.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===G.SMOOTH_CURVE_TO?i({type:G.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===G.QUAD_TO?i({type:G.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===G.ARC&&i({type:G.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!Zy(n)){if(n===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(n==="+"||n==="-"||n==="."){this.curNumber=n,this.curNumberHasDecimal=n===".";continue}if(a){this.curNumber=n,this.curNumberHasDecimal=!1;continue}if(this.curArgs.length!==0)throw new SyntaxError(`Unterminated command at index ${s}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${n}" at index ${s}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,n==="z"||n==="Z"){e.push({type:G.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(n==="h"||n==="H")this.curCommandType=G.HORIZ_LINE_TO,this.curCommandRelative=n==="h";else if(n==="v"||n==="V")this.curCommandType=G.VERT_LINE_TO,this.curCommandRelative=n==="v";else if(n==="m"||n==="M")this.curCommandType=G.MOVE_TO,this.curCommandRelative=n==="m";else if(n==="l"||n==="L")this.curCommandType=G.LINE_TO,this.curCommandRelative=n==="l";else if(n==="c"||n==="C")this.curCommandType=G.CURVE_TO,this.curCommandRelative=n==="c";else if(n==="s"||n==="S")this.curCommandType=G.SMOOTH_CURVE_TO,this.curCommandRelative=n==="s";else if(n==="q"||n==="Q")this.curCommandType=G.QUAD_TO,this.curCommandRelative=n==="q";else if(n==="t"||n==="T")this.curCommandType=G.SMOOTH_QUAD_TO,this.curCommandRelative=n==="t";else if(n==="a"||n==="A")this.curCommandType=G.ARC,this.curCommandRelative=n==="a";else throw new SyntaxError(`Unexpected character "${n}" at index ${s}.`)}}return e}transform(t){return Object.create(this,{parse:{value(e,i=[]){const s=Object.getPrototypeOf(this).parse.call(this,e);for(const n of s){const o=t(n);Array.isArray(o)?i.push(...o):i.push(o)}return i}}})}}const Gt=class ru extends Lu{constructor(t){super(),Xt(this,"commands"),typeof t=="string"?this.commands=ru.parse(t):this.commands=t}encode(){return ru.encode(this.commands)}getBounds(){const t=re.CALCULATE_BOUNDS();return this.transform(t),t}transform(t){const e=[];for(const i of this.commands){const s=t(i);Array.isArray(s)?e.push(...s):e.push(s)}return this.commands=e,this}reverse(t=!0){return this.commands=re.REVERSE_PATH(this.commands,t),this}static encode(t){return Ny(t)}static parse(t){const e=new Qy,i=[];return e.parse(t,i),e.finish(i),i}};Xt(Gt,"CLOSE_PATH",1),Xt(Gt,"MOVE_TO",2),Xt(Gt,"HORIZ_LINE_TO",4),Xt(Gt,"VERT_LINE_TO",8),Xt(Gt,"LINE_TO",16),Xt(Gt,"CURVE_TO",32),Xt(Gt,"SMOOTH_CURVE_TO",64),Xt(Gt,"QUAD_TO",128),Xt(Gt,"SMOOTH_QUAD_TO",256),Xt(Gt,"ARC",512),Xt(Gt,"LINE_COMMANDS",Gt.LINE_TO|Gt.HORIZ_LINE_TO|Gt.VERT_LINE_TO),Xt(Gt,"DRAWING_COMMANDS",Gt.HORIZ_LINE_TO|Gt.VERT_LINE_TO|Gt.LINE_TO|Gt.CURVE_TO|Gt.SMOOTH_CURVE_TO|Gt.QUAD_TO|Gt.SMOOTH_QUAD_TO|Gt.ARC);let G=Gt;const Jy={[G.MOVE_TO]:2,[G.LINE_TO]:2,[G.HORIZ_LINE_TO]:1,[G.VERT_LINE_TO]:1,[G.CLOSE_PATH]:0,[G.QUAD_TO]:4,[G.SMOOTH_QUAD_TO]:2,[G.CURVE_TO]:6,[G.SMOOTH_CURVE_TO]:4,[G.ARC]:7},t_=r=>{const t=new G(r).toAbs().commands,e=[];let i=[],s=null;for(const n of t)switch(n.type){case G.MOVE_TO:i.length>0&&(e.push({points:i}),i=[]),s=[n.x,n.y],i.push(s);break;case G.LINE_TO:i.push([n.x,n.y]);break;case G.HORIZ_LINE_TO:const o=i[i.length-1][1];i.push([n.x,o]);break;case G.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,n.y]);break;case G.CURVE_TO:case G.SMOOTH_CURVE_TO:case G.QUAD_TO:case G.SMOOTH_QUAD_TO:case G.ARC:i.push([n.x,n.y]);break}if(i.length>2&&e.push({points:i}),e.length>0){const n=Ue(e[0].points);return{rings:e,bounds:n}}},e_=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],s=i.split(" ").map(n=>n.split(",").map(parseFloat));return{type:Tt.POLYGON,geometry:{points:s,bounds:Ue(s)}}},r_=r=>{const t=Au(r),e=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),s=parseFloat(t.getAttribute("rx")),n=parseFloat(t.getAttribute("ry")),o={minX:e-s,minY:i-n,maxX:e+s,maxY:i+n};return{type:Tt.ELLIPSE,geometry:{cx:e,cy:i,rx:s,ry:n,bounds:o}}},i_=r=>{const t=Au(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(n=>n.getAttribute("d")||"").map(n=>t_(n)).filter(Boolean),i=e.reduce((n,o)=>[...n,...o.rings[0].points],[]),s=Ue(i);return e.length===1&&e[0].rings.length===1?{type:Tt.POLYGON,geometry:{points:i,bounds:s}}:{type:Tt.MULTIPOLYGLON,geometry:{polygons:e,bounds:s}}},s_=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return e_(t);if(t.includes("<path "))return i_(t);if(t.includes("<ellipse "))return r_(t);throw"Unsupported SVG shape: "+t},n_=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${Ze(t)}" />`).join("")}</g>`,o_=r=>{let t;if(r.type===Tt.POLYGON){const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(s=>s.join(",")).join(" ")}" /></svg>`}else if(r.type===Tt.ELLIPSE){const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`}else if(r.type===Tt.MULTIPOLYGLON){const e=r.geometry;t=`<svg>${n_(e)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},Ee=[];for(let r=0;r<256;++r)Ee.push((r+256).toString(16).slice(1));function a_(r,t=0){return(Ee[r[t+0]]+Ee[r[t+1]]+Ee[r[t+2]]+Ee[r[t+3]]+"-"+Ee[r[t+4]]+Ee[r[t+5]]+"-"+Ee[r[t+6]]+Ee[r[t+7]]+"-"+Ee[r[t+8]]+Ee[r[t+9]]+"-"+Ee[r[t+10]]+Ee[r[t+11]]+Ee[r[t+12]]+Ee[r[t+13]]+Ee[r[t+14]]+Ee[r[t+15]]).toLowerCase()}let ya;const l_=new Uint8Array(16);function h_(){if(!ya){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ya=crypto.getRandomValues.bind(crypto)}return ya(l_)}const u_=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Fu={randomUUID:u_};function ku(r,t,e){var i;if(Fu.randomUUID&&!r)return Fu.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??h_();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,a_(s)}var Uu=Object.prototype.hasOwnProperty;function Yr(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--&&Yr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Uu.call(r,e)&&++i&&!Uu.call(t,e)||!(e in t)||!Yr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}function _a(){}function c_(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const zi=[];function va(r,t=_a){let e;const i=new Set;function s(a){if(c_(r,a)&&(r=a,e)){const l=!zi.length;for(const h of i)h[1](),zi.push(h,r);if(l){for(let h=0;h<zi.length;h+=2)zi[h][0](zi[h+1]);zi.length=0}}}function n(a){s(a(r))}function o(a,l=_a){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||_a),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const d_=r=>{const{subscribe:t,set:e}=va();let i;return t(s=>i=s),r.observe(({changes:s})=>{if(i){(s.deleted||[]).some(o=>o.id===i)&&e(void 0);const n=(s.updated||[]).find(({oldValue:o})=>o.id===i);n&&e(n.newValue.id)}}),{get current(){return i},subscribe:t,set:e}};var Gu=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(Gu||{});const Sn={selected:[]},f_=(r,t,e)=>{const{subscribe:i,set:s}=va(Sn);let n=t,o=Sn;i(m=>o=m);const a=()=>{Yr(o,Sn)||s(Sn)},l=()=>{var m;return((m=o.selected)==null?void 0:m.length)===0},h=m=>{if(l())return!1;const _=typeof m=="string"?m:m.id;return o.selected.some(y=>y.id===_)},u=(m,_)=>{let y;if(Array.isArray(m)){if(y=m.map(g=>r.getAnnotation(g)).filter(Boolean),y.length<m.length){console.warn("Invalid selection: "+m.filter(g=>!y.some(x=>x.id===g)));return}}else{const g=r.getAnnotation(m);if(!g){console.warn("Invalid selection: "+m);return}y=[g]}const v=y.reduce((g,x)=>{const E=xa(x,n,e);return E==="EDIT"?[...g,{id:x.id,editable:!0}]:E==="SELECT"?[...g,{id:x.id}]:g},[]);s({selected:v,event:_})},c=(m,_)=>{const y=Array.isArray(m)?m:[m],v=y.map(g=>r.getAnnotation(g)).filter(g=>!!g);s({selected:v.map(g=>{const x=_===void 0?xa(g,n,e)==="EDIT":_;return{id:g.id,editable:x}})}),v.length!==y.length&&console.warn("Invalid selection",m)},d=m=>{if(l())return!1;const{selected:_}=o;_.some(({id:y})=>m.includes(y))&&s({selected:_.filter(({id:y})=>!m.includes(y))})},f=m=>{n=m,c(o.selected.map(({id:_})=>_))},p=m=>xa(m,n,e);return r.observe(({changes:m})=>d((m.deleted||[]).map(_=>_.id))),{get event(){return o?o.event:null},get selected(){return o?[...o.selected]:null},get userSelectAction(){return n},clear:a,evalSelectAction:p,isEmpty:l,isSelected:h,setSelected:c,setUserSelectAction:f,subscribe:i,userSelect:u}},xa=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},we=[];for(let r=0;r<256;++r)we.push((r+256).toString(16).slice(1));function p_(r,t=0){return(we[r[t+0]]+we[r[t+1]]+we[r[t+2]]+we[r[t+3]]+"-"+we[r[t+4]]+we[r[t+5]]+"-"+we[r[t+6]]+we[r[t+7]]+"-"+we[r[t+8]]+we[r[t+9]]+"-"+we[r[t+10]]+we[r[t+11]]+we[r[t+12]]+we[r[t+13]]+we[r[t+14]]+we[r[t+15]]).toLowerCase()}let ba;const m_=new Uint8Array(16);function g_(){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(m_)}const y_=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Hu={randomUUID:y_};function __(r,t,e){var i;if(Hu.randomUUID&&!r)return Hu.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??g_();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,p_(s)}const Ea=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)}},v_=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},x_=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},b_=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!Yr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),E_=(r,t)=>!Yr(r.target,t.target),$u=(r,t)=>{const e=v_(r,t),i=x_(r,t),s=b_(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:s.length>0?s:void 0,targetUpdated:E_(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Bt=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Bt||{});const w_=(r,t)=>{var e,i;const{changes:s,origin:n}=t;if(!(r.options.origin?r.options.origin===n:n!=="SILENT"))return!1;if(r.options.ignore){const{ignore:o}=r.options,a=l=>l&&l.length>0;if(!(a(s.created)||a(s.deleted))){const l=(e=s.updated)==null?void 0:e.some(u=>a(u.bodiesCreated)||a(u.bodiesDeleted)||a(u.bodiesUpdated)),h=(i=s.updated)==null?void 0:i.some(u=>u.targetUpdated);if(o==="BODY_ONLY"&&l&&!h||o==="TARGET_ONLY"&&h&&!l)return!1}}if(r.options.annotations){const o=new Set([...(s.created||[]).map(a=>a.id),...(s.deleted||[]).map(a=>a.id),...(s.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},T_=(r,t)=>{const e=new Set((r.created||[]).map(c=>c.id)),i=new Set((r.updated||[]).map(({newValue:c})=>c.id)),s=new Set((t.created||[]).map(c=>c.id)),n=new Set((t.deleted||[]).map(c=>c.id)),o=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>e.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(r.created||[]).filter(c=>!n.has(c.id)).map(c=>o.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],h=[...(r.deleted||[]).filter(c=>!s.has(c.id)),...(t.deleted||[]).filter(c=>!e.has(c.id))],u=[...(r.updated||[]).filter(({newValue:c})=>!n.has(c.id)).map(c=>{const{oldValue:d,newValue:f}=c;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return $u(d,p)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}},Cn=r=>{const t=r.id===void 0?__():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},A_=r=>r.id!==void 0,S_=()=>{const r=new Map,t=new Map,e=[],i=(I,A={})=>{e.push({onChange:I,options:A})},s=I=>{const A=e.findIndex(w=>w.onChange==I);A>-1&&e.splice(A,1)},n=(I,A)=>{const w={origin:I,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...r.values()]};e.forEach(C=>{w_(C,w)&&C.onChange(w)})},o=(I,A=Bt.LOCAL)=>{if(I.id&&r.get(I.id))throw Error(`Cannot add annotation ${I.id} - exists already`);{const w=Cn(I);r.set(w.id,w),w.bodies.forEach(C=>t.set(C.id,w.id)),n(A,{created:[w]})}},a=(I,A)=>{const w=Cn(typeof I=="string"?A:I),C=typeof I=="string"?I:I.id,D=C&&r.get(C);if(D){const N=$u(D,w);return C===w.id?r.set(C,w):(r.delete(C),r.set(w.id,w)),D.bodies.forEach(B=>t.delete(B.id)),w.bodies.forEach(B=>t.set(B.id,w.id)),N}else console.warn(`Cannot update annotation ${C} - does not exist`)},l=(I,A=Bt.LOCAL,w=Bt.LOCAL)=>{const C=A_(A)?w:A,D=a(I,A);D&&n(C,{updated:[D]})},h=(I,A=Bt.LOCAL)=>{r.get(I.id)?l(I,A):o(I,A)},u=(I,A=Bt.LOCAL)=>{const w=I.reduce((C,D)=>{const N=a(D);return N?[...C,N]:C},[]);w.length>0&&n(A,{updated:w})},c=(I,A=Bt.LOCAL)=>{const w=I.map(Cn),{toAdd:C,toUpdate:D}=w.reduce((B,V)=>r.get(V.id)?{...B,toUpdate:[...B.toUpdate,V]}:{...B,toAdd:[...B.toAdd,V]},{toAdd:[],toUpdate:[]}),N=D.map(B=>a(B,A)).filter(Boolean);C.forEach(B=>{r.set(B.id,B),B.bodies.forEach(V=>t.set(V.id,B.id))}),n(A,{created:C,updated:N})},d=(I,A=Bt.LOCAL)=>{const w=r.get(I.annotation);if(w){const C={...w,bodies:[...w.bodies,I]};r.set(w.id,C),t.set(I.id,C.id),n(A,{updated:[{oldValue:w,newValue:C,bodiesCreated:[I]}]})}else console.warn(`Attempt to add body to missing annotation: ${I.annotation}`)},f=()=>[...r.values()],p=(I=Bt.LOCAL)=>{const A=[...r.values()];r.clear(),t.clear(),n(I,{deleted:A})},m=(I,A=!0,w=Bt.LOCAL)=>{const C=I.map(Cn);if(A){const D=[...r.values()];r.clear(),t.clear(),C.forEach(N=>{r.set(N.id,N),N.bodies.forEach(B=>t.set(B.id,N.id))}),n(w,{created:C,deleted:D})}else{const D=I.reduce((N,B)=>{const V=B.id&&r.get(B.id);return V?[...N,V]:N},[]);if(D.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${D.map(N=>N.id).join(", ")}`);C.forEach(N=>{r.set(N.id,N),N.bodies.forEach(B=>t.set(B.id,N.id))}),n(w,{created:C})}},_=I=>{const A=typeof I=="string"?I:I.id,w=r.get(A);if(w)return r.delete(A),w.bodies.forEach(C=>t.delete(C.id)),w;console.warn(`Attempt to delete missing annotation: ${A}`)},y=(I,A=Bt.LOCAL)=>{const w=_(I);w&&n(A,{deleted:[w]})},v=(I,A=Bt.LOCAL)=>{const w=I.reduce((C,D)=>{const N=_(D);return N?[...C,N]:C},[]);w.length>0&&n(A,{deleted:w})},g=I=>{const A=r.get(I.annotation);if(A){const w=A.bodies.find(C=>C.id===I.id);if(w){t.delete(w.id);const C={...A,bodies:A.bodies.filter(D=>D.id!==I.id)};return r.set(A.id,C),{oldValue:A,newValue:C,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${I.id} from annotation ${I.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${I.annotation}`)},x=(I,A=Bt.LOCAL)=>{const w=g(I);w&&n(A,{updated:[w]})},E=(I,A=Bt.LOCAL)=>{const w=I.map(C=>g(C)).filter(Boolean);w.length>0&&n(A,{updated:w})},R=I=>{const A=r.get(I);return A?{...A}:void 0},S=I=>{const A=t.get(I);if(A){const w=R(A).bodies.find(C=>C.id===I);if(w)return w;console.error(`Store integrity error: body ${I} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${I}`)},M=(I,A)=>{if(I.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=r.get(I.annotation);if(w){const C=w.bodies.find(N=>N.id===I.id),D={...w,bodies:w.bodies.map(N=>N.id===C.id?A:N)};return r.set(w.id,D),C.id!==A.id&&(t.delete(C.id),t.set(A.id,D.id)),{oldValue:w,newValue:D,bodiesUpdated:[{oldBody:C,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${I.annotation}`)},P=(I,A,w=Bt.LOCAL)=>{const C=M(I,A);C&&n(w,{updated:[C]})},F=(I,A=Bt.LOCAL)=>{const w=I.map(C=>M({id:C.id,annotation:C.annotation},C)).filter(Boolean);n(A,{updated:w})},U=I=>{const A=r.get(I.annotation);if(A){const w={...A,target:{...A.target,...I}};return r.set(A.id,w),{oldValue:A,newValue:w,targetUpdated:{oldTarget:A.target,newTarget:I}}}else console.warn(`Attempt to update target on missing annotation: ${I.annotation}`)};return{addAnnotation:o,addBody:d,all:f,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:E,bulkUpdateAnnotations:u,bulkUpdateBodies:F,bulkUpdateTargets:(I,A=Bt.LOCAL)=>{const w=I.map(C=>U(C)).filter(Boolean);w.length>0&&n(A,{updated:w})},bulkUpsertAnnotations:c,clear:p,deleteAnnotation:y,deleteBody:x,getAnnotation:R,getBody:S,observe:i,unobserve:s,updateAnnotation:l,updateBody:P,updateTarget:(I,A=Bt.LOCAL)=>{const w=U(I);w&&n(A,{updated:[w]})},upsertAnnotation:h}},C_=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let I_=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,s=e.length;i<s;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(s=>t!==s)}}});const R_=250,M_=(r,t)=>{const e=I_(),i=(t==null?void 0:t.changes)||[];let s=t?t.pointer:-1,n=!1,o=0;const a=p=>{if(!n){const{changes:m}=p,_=performance.now();if(_-o>R_)i.splice(s+1),i.push(m),s=i.length-1;else{const y=i.length-1;i[y]=T_(i[y],m)}o=_}n=!1};r.observe(a,{origin:Bt.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:m})=>m)),c=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>s,canUndo:()=>s>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:s}),on:(p,m)=>e.on(p,m),redo:()=>{if(i.length-1>s){n=!0;const{created:p,updated:m,deleted:_}=i[s+1];h(p),c(m),f(_),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:p,updated:m,deleted:_}=i[s];l(p),u(m),d(_),e.emit("undo",i[s]),s-=1}}}},P_=()=>{const{subscribe:r,set:t}=va([]);return{subscribe:r,set:t}},O_=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(y,v)=>{l.has(y)?l.get(y).push(v):l.set(y,[v])},f=(y,v)=>{const g=l.get(y);if(g){const x=g.indexOf(v);x!==-1&&g.splice(x,1)}},p=(y,v,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(x=>{if(e){const E=Array.isArray(v)?v.map(S=>e.serialize(S)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;x(E,R)}else x(v,g)})},1)},m=()=>{const{selected:y}=n,v=(y||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const x=h.find(E=>E.id===g.id);(!x||!Yr(x,g))&&p("updateAnnotation",g,x)}),h=h.map(g=>v.find(({id:x})=>x===g.id)||g)};n.subscribe(({selected:y})=>{if(!(h.length===0&&y.length===0)){if(h.length===0&&y.length>0)h=y.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&y.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Yr(g,v)&&p("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),g=new Set(y.map(({id:x})=>x));h.filter(x=>!g.has(x.id)).forEach(x=>{const E=o.getAnnotation(x.id);E&&!Yr(E,x)&&p("updateAnnotation",E,x)}),h=[...h.filter(x=>g.has(x.id)),...y.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}p("selectionChanged",h)}}),s.subscribe(y=>{!u&&y?p("mouseEnterAnnotation",o.getAnnotation(y)):u&&!y?p("mouseLeaveAnnotation",o.getAnnotation(u)):u&&y&&(p("mouseLeaveAnnotation",o.getAnnotation(u)),p("mouseEnterAnnotation",o.getAnnotation(y))),u=y}),a==null||a.subscribe(y=>p("viewportIntersect",y.map(v=>o.getAnnotation(v)))),o.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:v,deleted:g}=y.changes;(v||[]).forEach(x=>p("createAnnotation",x)),(g||[]).forEach(x=>p("deleteAnnotation",x)),(y.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:E})=>{const R=h.find(S=>S.id===x.id)||x;h=h.map(S=>S.id===x.id?E:S),p("updateAnnotation",E,R)})},{origin:Bt.LOCAL}),o.observe(y=>{if(h){const v=new Set(h.map(x=>x.id)),g=(y.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);g.length>0&&(h=h.map(x=>g.find(E=>E.id===x.id)||x))}},{origin:Bt.REMOTE});const _=y=>v=>{const{updated:g}=v;y?(g||[]).forEach(x=>p("updateAnnotation",x.oldValue,x.newValue)):(g||[]).forEach(x=>p("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:f,emit:p}},N_=r=>t=>t.reduce((e,i)=>{const{parsed:s,error:n}=r.parse(i);return n?{parsed:e.parsed,failed:[...e.failed,i]}:s?{parsed:[...e.parsed,s],failed:e.failed}:{...e}},{parsed:[],failed:[]}),D_=(r,t,e)=>{const{store:i,selection:s}=r,n=y=>{if(e){const{parsed:v,error:g}=e.parse(y);v?i.addAnnotation(v,Bt.REMOTE):console.error(g)}else i.addAnnotation(Ea(y),Bt.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=y=>{const v=i.getAnnotation(y);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var y;const v=(((y=s.selected)==null?void 0:y.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},c=(y,v=!0)=>fetch(y).then(g=>g.json()).then(g=>(f(g,v),g)),d=y=>{if(typeof y=="string"){const v=i.getAnnotation(y);if(i.deleteAnnotation(y),v)return e?e.serialize(v):v}else{const v=e?e.parse(y).parsed:y;if(v)return i.deleteAnnotation(v),y}},f=(y,v=!0)=>{if(e){const g=e.parseAll||N_(e),{parsed:x,failed:E}=g(y);E.length>0&&console.warn(`Discarded ${E.length} invalid annotations`,E),i.bulkAddAnnotations(x,v,Bt.REMOTE)}else i.bulkAddAnnotations(y.map(Ea),v,Bt.REMOTE)},p=(y,v)=>{y?s.setSelected(y,v):s.clear()},m=y=>{s.clear(),s.setUserSelectAction(y)},_=y=>{if(e){const v=e.parse(y).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(y.id);return i.updateAnnotation(Ea(y)),v}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:u,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},L_=(r,t,e)=>typeof t=="function"?t(r,e):t,B_=(r,t)=>typeof r!="function"&&typeof t!="function"?{...r||{},...t||{}}:(e,i)=>{const s=typeof r=="function"?r(e,i):r,n=typeof t=="function"?t(e,i):t;return{...s||{},...n||{}}},F_="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let k_=r=>crypto.getRandomValues(new Uint8Array(r)),U_=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,s=-~(1.6*i*t/r.length);return(n=t)=>{let o="";for(;;){let a=e(s),l=s|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=n)return o}}},G_=(r,t=21)=>U_(r,t|0,k_),H_=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=F_[e[r]&63];return t};const $_=()=>({isGuest:!0,id:G_("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),X_=r=>{const t=JSON.stringify(r);let e=0;for(let i=0,s=t.length;i<s;i++){let n=t.charCodeAt(i);e=(e<<5)-e+n,e|=0}return`${e}`},Xu=r=>r?typeof r=="object"?{...r}:r:void 0,V_=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:s,purpose:n,value:o,created:a,modified:l,creator:h,...u}=e;return{id:i||`temp-${X_(e)}`,annotation:t,type:s,purpose:n,value:o,creator:Xu(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...u}}),z_=r=>r.map(t=>{var e;const{annotation:i,created:s,updated:n,...o}=t,a={...o,created:s==null?void 0:s.toISOString(),modified:n==null?void 0:n.toISOString()};return(e=a.id)!=null&&e.startsWith("temp-")&&delete a.id,a});H_();const Y_=(r,t={strict:!0,invertY:!1})=>({parse:e=>W_(e,t),serialize:e=>j_(e,r,t)}),W_=(r,t={strict:!0,invertY:!1})=>{const e=r.id||ku(),{creator:i,created:s,modified:n,body:o,...a}=r,l=V_(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,u=typeof h=="string"?h:Array.isArray(h.selector)?h.selector[0]:h.selector,c=typeof u=="string"||(u==null?void 0:u.type)==="FragmentSelector"?My(u,t.invertY):(u==null?void 0:u.type)==="SvgSelector"?s_(u):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return c||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:s?new Date(s):void 0,creator:Xu(i),updated:n?new Date(n):void 0,...typeof d=="string"?{}:d,annotation:e,selector:c||u}}}:{error:Error(`Invalid selector: ${JSON.stringify(u)}`)}},j_=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:s,created:n,updated:o,updatedBy:a,...l}=r.target;let h;try{h=i.type==Tt.RECTANGLE?Py(i.geometry):o_(i)}catch(c){if(e.strict)throw c;h=i}const u={...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:r.id,type:"Annotation",body:z_(r.bodies),created:n==null?void 0:n.toISOString(),creator:s,modified:o==null?void 0:o.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:h}};return delete u.bodies,"annotation"in u.target&&delete u.target.annotation,u},wa=(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))},Yi=[];function q_(r,t=Dt){let e;const i=new Set;function s(a){if(le(r,a)&&(r=a,e)){const l=!Yi.length;for(const h of i)h[1](),Yi.push(h,r);if(l){for(let h=0;h<Yi.length;h+=2)Yi[h][0](Yi[h+1]);Yi.length=0}}}function n(a){s(a(r))}function o(a,l=Dt){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||Dt),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const K_=(r,t)=>{const{naturalWidth:e,naturalHeight:i}=r;if(!e&&!i){const{width:s,height:n}=r;t.setAttribute("viewBox",`0 0 ${s} ${n}`),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}`)},Z_=(r,t)=>{K_(r,t);const{subscribe:e,set:i}=q_(1);let s;return window.ResizeObserver&&(s=new ResizeObserver(()=>{const n=t.getBoundingClientRect(),{width:o,height:a}=t.viewBox.baseVal,l=Math.max(n.width/o,n.height/a);i(l)}),s.observe(t.parentElement)),{destroy:()=>{s&&s.disconnect()},subscribe:e}},Os=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:s,stroke:n,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${s||"0.25"};`),n&&(l+=`stroke:${n};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},In=(r,t=0)=>{const{minX:e,minY:i,maxX:s,maxY:n}=r;return{x:e-t,y:i-t,w:s-e+2*t,h:n-i+2*t}},Cr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Q_=r=>({}),Vu=r=>({grab:r[0]});function J_(r){let t,e,i,s;const n=r[8].default,o=dy(n,r,r[7],Vu);return{c(){t=Z("g"),o&&o.c(),b(t,"class","a9s-annotation selected")},m(a,l){it(a,t,l),o&&o.m(t,null),e=!0,i||(s=[Rt(t,"pointerup",r[2]),Rt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&py(o,n,a,a[7],e?fy(n,a[7],l,Q_):my(a[7]),Vu)},i(a){e||(ot(o,a),e=!0)},o(a){gt(o,a),e=!1},d(a){a&&rt(t),o&&o.d(a),i=!1,$e(s)}}}function t0(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Xr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,u,c,d;const f=_=>y=>{if(u=_,h){const{left:v,top:g}=h.getBoundingClientRect(),x=y.clientX-v,E=y.clientY-g;c=l.elementToImage(x,E)}else{const{offsetX:v,offsetY:g}=y;c=l.elementToImage(v,g)}d=o,y.target.setPointerCapture(y.pointerId),n("grab",y)},p=_=>{if(u){const[y,v]=l.elementToImage(_.offsetX,_.offsetY),g=[y-c[0],v-c[1]];e(3,o=a(d,u,g)),n("change",o)}},m=_=>{_.target.releasePointerCapture(_.pointerId),u=void 0,d=o,n("release",_)};return r.$$set=_=>{"shape"in _&&e(3,o=_.shape),"editor"in _&&e(4,a=_.editor),"transform"in _&&e(5,l=_.transform),"svgEl"in _&&e(6,h=_.svgEl),"$$scope"in _&&e(7,s=_.$$scope)},[f,p,m,o,a,l,h,s,i]}class Ta extends De{constructor(t){super(),Ne(this,t,t0,J_,le,{shape:3,editor:4,transform:5,svgEl:6})}}function e0(r){let t,e,i,s,n,o,a,l,h=r[3]&&zu(r);return{c(){t=Z("g"),e=Z("circle"),h&&h.c(),s=Z("circle"),b(e,"class","a9s-handle-buffer"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=r[5]+6/r[2]),b(s,"class",n=`a9s-handle-dot${r[3]?" selected":""}`),b(s,"cx",r[0]),b(s,"cy",r[1]),b(s,"r",r[5]),b(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(u,c){it(u,t,c),wt(t,e),h&&h.m(t,null),wt(t,s),a||(l=[Rt(e,"pointerenter",r[11]),Rt(e,"pointerleave",r[12]),Rt(e,"pointerdown",r[13]),Rt(e,"pointerdown",r[6]),Rt(e,"pointerup",r[14]),Rt(e,"pointerup",r[7])],a=!0)},p(u,c){c&1&&b(e,"cx",u[0]),c&2&&b(e,"cy",u[1]),c&36&&i!==(i=u[5]+6/u[2])&&b(e,"r",i),u[3]?h?h.p(u,c):(h=zu(u),h.c(),h.m(t,s)):h&&(h.d(1),h=null),c&8&&n!==(n=`a9s-handle-dot${u[3]?" selected":""}`)&&b(s,"class",n),c&1&&b(s,"cx",u[0]),c&2&&b(s,"cy",u[1]),c&32&&b(s,"r",u[5]),c&256&&o!==(o=`a9s-handle ${u[8].class||""}`.trim())&&b(t,"class",o)},d(u){u&&rt(t),h&&h.d(),a=!1,$e(l)}}}function r0(r){let t,e,i,s,n,o,a,l,h;return{c(){t=Z("g"),e=Z("circle"),s=Z("circle"),o=Z("circle"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=r[5]*10),b(e,"class","a9s-touch-halo"),cr(e,"touched",r[4]),b(s,"cx",r[0]),b(s,"cy",r[1]),b(s,"r",n=r[5]+10/r[2]),b(s,"class","a9s-handle-buffer"),b(o,"class","a9s-handle-dot"),b(o,"cx",r[0]),b(o,"cy",r[1]),b(o,"r",a=r[5]+2/r[2]),b(t,"class","a9s-touch-handle")},m(u,c){it(u,t,c),wt(t,e),wt(t,s),wt(t,o),l||(h=[Rt(s,"pointerdown",r[9]),Rt(s,"pointerup",r[10]),Rt(s,"pointerdown",r[6]),Rt(s,"pointerup",r[7])],l=!0)},p(u,c){c&1&&b(e,"cx",u[0]),c&2&&b(e,"cy",u[1]),c&32&&i!==(i=u[5]*10)&&b(e,"r",i),c&16&&cr(e,"touched",u[4]),c&1&&b(s,"cx",u[0]),c&2&&b(s,"cy",u[1]),c&36&&n!==(n=u[5]+10/u[2])&&b(s,"r",n),c&1&&b(o,"cx",u[0]),c&2&&b(o,"cy",u[1]),c&36&&a!==(a=u[5]+2/u[2])&&b(o,"r",a)},d(u){u&&rt(t),l=!1,$e(h)}}}function zu(r){let t,e;return{c(){t=Z("circle"),b(t,"class","a9s-handle-selected"),b(t,"cx",r[0]),b(t,"cy",r[1]),b(t,"r",e=r[5]+8/r[2])},m(i,s){it(i,t,s)},p(i,s){s&1&&b(t,"cx",i[0]),s&2&&b(t,"cy",i[1]),s&36&&e!==(e=i[5]+8/i[2])&&b(t,"r",e)},d(i){i&&rt(t)}}}function i0(r){let t;function e(s,n){return Cr?r0:e0}let i=e()(r);return{c(){i.c(),t=Fe()},m(s,n){i.m(s,n),it(s,t,n)},p(s,[n]){i.p(s,n)},i:Dt,o:Dt,d(s){s&&rt(t),i.d(s)}}}function s0(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=y=>{y.pointerType==="touch"&&e(4,l=!0)},u=()=>e(4,l=!1);function c(y){Ce.call(this,r,y)}function d(y){Ce.call(this,r,y)}function f(y){Ce.call(this,r,y)}function p(y){Ce.call(this,r,y)}function m(y){Ce.call(this,r,y)}function _(y){Ce.call(this,r,y)}return r.$$set=y=>{e(8,t=sa(sa({},t),mu(y))),"x"in y&&e(0,s=y.x),"y"in y&&e(1,n=y.y),"scale"in y&&e(2,o=y.scale),"selected"in y&&e(3,a=y.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=mu(t),[s,n,o,a,l,i,h,u,t,c,d,f,p,m,_]}class Wi extends De{constructor(t){super(),Ne(this,t,s0,i0,le,{x:0,y:1,scale:2,selected:3})}}function n0(r){let t,e,i,s,n,o,a;return{c(){t=Z("g"),e=Z("circle"),s=Z("circle"),n=Z("circle"),b(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=1.75*r[2]),b(s,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),b(s,"cx",r[0]),b(s,"cy",r[1]),b(s,"r",r[2]),b(n,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),b(n,"cx",r[0]),b(n,"cy",r[1]),b(n,"r",r[2]),b(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){it(l,t,h),wt(t,e),wt(t,s),wt(t,n),o||(a=[Rt(e,"pointerdown",r[5]),Rt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&b(e,"cx",l[0]),h&2&&b(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&b(e,"r",i),h&1&&b(s,"cx",l[0]),h&2&&b(s,"cy",l[1]),h&4&&b(s,"r",l[2]),h&1&&b(n,"cx",l[0]),h&2&&b(n,"cy",l[1]),h&4&&b(n,"r",l[2])},d(l){l&&rt(t),o=!1,$e(a)}}}function o0(r){let t;return{c(){t=Z("circle"),b(t,"cx",r[0]),b(t,"cy",r[1]),b(t,"r",r[2])},m(e,i){it(e,t,i)},p(e,i){i&1&&b(t,"cx",e[0]),i&2&&b(t,"cy",e[1]),i&4&&b(t,"r",e[2])},d(e){e&&rt(t)}}}function a0(r){let t;function e(s,n){return Cr?o0:n0}let i=e()(r);return{c(){i.c(),t=Fe()},m(s,n){i.m(s,n),it(s,t,n)},p(s,[n]){i.p(s,n)},i:Dt,o:Dt,d(s){s&&rt(t),i.d(s)}}}function l0(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){Ce.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,s=h.x),"y"in h&&e(1,n=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[s,n,i,a,o,l]}class Yu extends De{constructor(t){super(),Ne(this,t,l0,a0,le,{x:0,y:1,scale:4})}}function Aa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Wu(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Sa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ca(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function ju(r){let t,e,i,s;return{c(){t=Z("circle"),b(t,"cx",e=r[28][0]),b(t,"cy",i=r[28][1]),b(t,"r",s=Ns/r[3]),b(t,"class","svelte-1h2slbm")},m(n,o){it(n,t,o)},p(n,o){o[0]&1088&&e!==(e=n[28][0])&&b(t,"cx",e),o[0]&1088&&i!==(i=n[28][1])&&b(t,"cy",i),o[0]&8&&s!==(s=Ns/n[3])&&b(t,"r",s)},d(n){n&&rt(t)}}}function qu(r){let t,e,i,s,n,o,a,l,h,u;return{c(){t=Z("mask"),e=Z("rect"),a=Z("circle"),b(e,"x",i=r[9].x),b(e,"y",s=r[9].y),b(e,"width",n=r[9].w),b(e,"height",o=r[9].h),b(e,"class","svelte-1h2slbm"),b(a,"cx",l=r[28][0]),b(a,"cy",h=r[28][1]),b(a,"r",u=Ns/r[3]),b(a,"class","svelte-1h2slbm"),b(t,"id",`${r[19]}-inner`),b(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,d){it(c,t,d),wt(t,e),wt(t,a)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&b(e,"x",i),d[0]&512&&s!==(s=c[9].y)&&b(e,"y",s),d[0]&512&&n!==(n=c[9].w)&&b(e,"width",n),d[0]&512&&o!==(o=c[9].h)&&b(e,"height",o),d[0]&1088&&l!==(l=c[28][0])&&b(a,"cx",l),d[0]&1088&&h!==(h=c[28][1])&&b(a,"cy",h),d[0]&8&&u!==(u=Ns/c[3])&&b(a,"r",u)},d(c){c&&rt(t)}}}function Ku(r){let t,e;return t=new Wi({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(){Vt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&32&&(n.x=r[28][0]),s[0]&32&&(n.y=r[28][1]),s[0]&8&&(n.scale=r[3]),s[0]&256&&(n.selected=r[8].includes(r[30])),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function Zu(r){let t,e;return t=new Yu({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Vt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&1088&&(n.x=r[28][0]),s[0]&1088&&(n.y=r[28][1]),s[0]&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function h0(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v,g,x,E,R=r[6]!==void 0&&!r[7]&&ju(Ca(r)),S=r[6]!==void 0&&!r[7]&&qu(Sa(r)),M=ke(r[5].points),P=[];for(let I=0;I<M.length;I+=1)P[I]=Ku(Wu(r,M,I));const F=I=>gt(P[I],1,1,()=>{P[I]=null});let U=r[6]!==void 0&&!r[7]&&Zu(Aa(r));return{c(){t=Z("defs"),e=Z("mask"),i=Z("rect"),l=Z("polygon"),R&&R.c(),S&&S.c(),u=Oe(),c=Z("polygon"),f=Oe(),p=Z("polygon"),_=Oe();for(let I=0;I<P.length;I+=1)P[I].c();y=Oe(),U&&U.c(),v=Fe(),b(i,"x",s=r[9].x),b(i,"y",n=r[9].y),b(i,"width",o=r[9].w),b(i,"height",a=r[9].h),b(i,"class","svelte-1h2slbm"),b(l,"points",h=r[5].points.map(Qu).join(" ")),b(l,"class","svelte-1h2slbm"),b(e,"id",`${r[19]}-outer`),b(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),b(c,"class","a9s-outer"),b(c,"mask",`url(#${r[19]}-outer)`),b(c,"points",d=r[5].points.map(Ju).join(" ")),b(p,"class","a9s-inner a9s-shape-handle"),b(p,"mask",`url(#${r[19]}-inner)`),b(p,"style",r[1]),b(p,"points",m=r[5].points.map(tc).join(" "))},m(I,A){it(I,t,A),wt(t,e),wt(e,i),wt(e,l),R&&R.m(e,null),S&&S.m(t,null),it(I,u,A),it(I,c,A),it(I,f,A),it(I,p,A),it(I,_,A);for(let w=0;w<P.length;w+=1)P[w]&&P[w].m(I,A);it(I,y,A),U&&U.m(I,A),it(I,v,A),g=!0,x||(E=[Rt(c,"pointerup",r[14]),Rt(c,"pointerdown",function(){Vt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Rt(p,"pointermove",r[13]),Rt(p,"pointerup",r[14]),Rt(p,"pointerdown",function(){Vt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],x=!0)},p(I,A){if(r=I,(!g||A[0]&512&&s!==(s=r[9].x))&&b(i,"x",s),(!g||A[0]&512&&n!==(n=r[9].y))&&b(i,"y",n),(!g||A[0]&512&&o!==(o=r[9].w))&&b(i,"width",o),(!g||A[0]&512&&a!==(a=r[9].h))&&b(i,"height",a),(!g||A[0]&32&&h!==(h=r[5].points.map(Qu).join(" ")))&&b(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Ca(r),A):(R=ju(Ca(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?S?S.p(Sa(r),A):(S=qu(Sa(r)),S.c(),S.m(t,null)):S&&(S.d(1),S=null),(!g||A[0]&32&&d!==(d=r[5].points.map(Ju).join(" ")))&&b(c,"points",d),(!g||A[0]&2)&&b(p,"style",r[1]),(!g||A[0]&32&&m!==(m=r[5].points.map(tc).join(" ")))&&b(p,"points",m),A[0]&134322472){M=ke(r[5].points);let w;for(w=0;w<M.length;w+=1){const C=Wu(r,M,w);P[w]?(P[w].p(C,A),ot(P[w],1)):(P[w]=Ku(C),P[w].c(),ot(P[w],1),P[w].m(y.parentNode,y))}for(Ie(),w=M.length;w<P.length;w+=1)F(w);Re()}r[6]!==void 0&&!r[7]?U?(U.p(Aa(r),A),A[0]&192&&ot(U,1)):(U=Zu(Aa(r)),U.c(),ot(U,1),U.m(v.parentNode,v)):U&&(Ie(),gt(U,1,1,()=>{U=null}),Re())},i(I){if(!g){for(let A=0;A<M.length;A+=1)ot(P[A]);ot(U),g=!0}},o(I){P=P.filter(Boolean);for(let A=0;A<P.length;A+=1)gt(P[A]);gt(U),g=!1},d(I){I&&(rt(t),rt(u),rt(c),rt(f),rt(p),rt(_),rt(y),rt(v)),R&&R.d(),S&&S.d(),mi(P,I),U&&U.d(I),x=!1,$e(E)}}}function u0(r){let t,e;return t=new Ta({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[h0,({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(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&1&&(n.shape=i[0]),s[0]&4&&(n.transform=i[2]),s[0]&16&&(n.svgEl=i[4]),s[0]&134219754|s[1]&1&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}const c0=250,d0=1e3,f0=12,Ns=4.5,Qu=r=>r.join(","),Ju=r=>r.join(","),tc=r=>r.join(",");function p0(r,t,e){let i,s,n;const o=Xr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:u=1}=t,{svgEl:c}=t,d,f=!1,p,m=[];const _=()=>e(7,f=!0),y=()=>e(7,f=!1),v=w=>{if(m.length>0||!s.some(O=>O.visible)){e(6,d=void 0);return}const[C,D]=h.elementToImage(w.offsetX,w.offsetY),N=O=>Math.pow(O[0]-C,2)+Math.pow(O[1]-D,2),B=i.points.reduce((O,k)=>N(k)<N(O)?k:O),V=s.filter(O=>O.visible).reduce((O,k)=>N(k.point)<N(O.point)?k:O),L=Math.pow(d0/u,2);N(B)<L||N(V.point)<L?e(6,d=s.indexOf(V)):e(6,d=void 0)},g=()=>{document.activeElement!==c&&c.focus()},x=()=>{e(8,m=[]),g()},E=w=>{e(7,f=!0),w.preventDefault(),w.stopPropagation(),p=performance.now()},R=w=>C=>{if(!p||Cr||performance.now()-p>c0)return;const D=m.includes(w);C.metaKey||C.ctrlKey||C.shiftKey?D?e(8,m=m.filter(N=>N!==w)):e(8,m=[...m,w]):D&&m.length>1?e(8,m=[w]):D?e(8,m=[]):e(8,m=[w]),g()},S=(w,C,D)=>{g();let N;const B=w.geometry;m.length>1?N=B.points.map(([L,O],k)=>m.includes(k)?[L+D[0],O+D[1]]:[L,O]):C==="SHAPE"?N=B.points.map(([L,O])=>[L+D[0],O+D[1]]):N=B.points.map(([L,O],k)=>C===`HANDLE-${k}`?[L+D[0],O+D[1]]:[L,O]);const V=Ue(N);return{...w,geometry:{points:N,bounds:V}}},M=w=>async C=>{C.stopPropagation();const D=[...i.points.slice(0,w+1),s[w].point,...i.points.slice(w+1)],N=Ue(D);o("change",{...a,geometry:{points:D,bounds:N}}),await bu();const B=[...document.querySelectorAll(".a9s-handle")][w+1];if(B!=null&&B.firstChild){const V=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:C.clientX,clientY:C.clientY,pointerId:C.pointerId,pointerType:C.pointerType,isPrimary:C.isPrimary,buttons:C.buttons});B.firstChild.dispatchEvent(V)}},P=()=>{if(i.points.length<4)return;const w=i.points.filter((D,N)=>!m.includes(N)),C=Ue(w);o("change",{...a,geometry:{points:w,bounds:C}}),e(8,m=[])};gi(()=>{if(Cr)return;const w=C=>{(C.key==="Delete"||C.key==="Backspace")&&(C.preventDefault(),P())};return c.addEventListener("pointermove",v),c.addEventListener("keydown",w),()=>{c.removeEventListener("pointermove",v),c.removeEventListener("keydown",w)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(w){Ce.call(this,r,w)}function I(w){Ce.call(this,r,w)}function A(w){Ce.call(this,r,w)}return r.$$set=w=>{"shape"in w&&e(0,a=w.shape),"computedStyle"in w&&e(1,l=w.computedStyle),"transform"in w&&e(2,h=w.transform),"viewportScale"in w&&e(3,u=w.viewportScale),"svgEl"in w&&e(4,c=w.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,s=Cr?[]:i.points.map((w,C)=>{const D=C===i.points.length-1?i.points[0]:i.points[C+1],N=(w[0]+D[0])/2,B=(w[1]+D[1])/2,V=Math.sqrt(Math.pow(D[0]-N,2)+Math.pow(D[1]-B,2))>f0/u;return{point:[N,B],visible:V}})),r.$$.dirty[0]&40&&e(9,n=In(i.bounds,Ns/u))},[a,l,h,u,c,i,d,f,m,n,s,_,y,v,x,E,R,S,M,F,U,I,A]}class m0 extends De{constructor(t){super(),Ne(this,t,p0,u0,le,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function g0(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v,g,x,E,R,S,M,P,F,U,I,A,w,C,D,N,B,V,L,O,k,X,Y,q,pt,_t,W,bt,dt,mt,xt,Mt,Nt,_e,jt,et,Ke,mn;return dt=new Wi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),dt.$on("pointerdown",function(){Vt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),xt=new Wi({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),xt.$on("pointerdown",function(){Vt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Nt=new Wi({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Nt.$on("pointerdown",function(){Vt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),jt=new Wi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),jt.$on("pointerdown",function(){Vt(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=Oe(),p=Z("rect"),g=Oe(),x=Z("rect"),P=Oe(),F=Z("rect"),w=Oe(),C=Z("rect"),V=Oe(),L=Z("rect"),Y=Oe(),q=Z("rect"),bt=Oe(),be(dt.$$.fragment),mt=Oe(),be(xt.$$.fragment),Mt=Oe(),be(Nt.$$.fragment),_e=Oe(),be(jt.$$.fragment),b(i,"class","rect-mask-bg svelte-1njczvj"),b(i,"x",s=r[6].x),b(i,"y",n=r[6].y),b(i,"width",o=r[6].w),b(i,"height",a=r[6].h),b(l,"class","rect-mask-fg svelte-1njczvj"),b(l,"x",h=r[5].x),b(l,"y",u=r[5].y),b(l,"width",c=r[5].w),b(l,"height",d=r[5].h),b(e,"id",r[8]),b(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),b(p,"class","a9s-outer"),b(p,"mask",`url(#${r[8]})`),b(p,"x",m=r[5].x),b(p,"y",_=r[5].y),b(p,"width",y=r[5].w),b(p,"height",v=r[5].h),b(x,"class","a9s-inner a9s-shape-handle"),b(x,"style",r[1]),b(x,"x",E=r[5].x),b(x,"y",R=r[5].y),b(x,"width",S=r[5].w),b(x,"height",M=r[5].h),b(F,"class","a9s-edge-handle a9s-edge-handle-top"),b(F,"x",U=r[5].x),b(F,"y",I=r[5].y),b(F,"height",1),b(F,"width",A=r[5].w),b(C,"class","a9s-edge-handle a9s-edge-handle-right"),b(C,"x",D=r[5].x+r[5].w),b(C,"y",N=r[5].y),b(C,"height",B=r[5].h),b(C,"width",1),b(L,"class","a9s-edge-handle a9s-edge-handle-bottom"),b(L,"x",O=r[5].x),b(L,"y",k=r[5].y+r[5].h),b(L,"height",1),b(L,"width",X=r[5].w),b(q,"class","a9s-edge-handle a9s-edge-handle-left"),b(q,"x",pt=r[5].x),b(q,"y",_t=r[5].y),b(q,"height",W=r[5].h),b(q,"width",1)},m(j,H){it(j,t,H),wt(t,e),wt(e,i),wt(e,l),it(j,f,H),it(j,p,H),it(j,g,H),it(j,x,H),it(j,P,H),it(j,F,H),it(j,w,H),it(j,C,H),it(j,V,H),it(j,L,H),it(j,Y,H),it(j,q,H),it(j,bt,H),ce(dt,j,H),it(j,mt,H),ce(xt,j,H),it(j,Mt,H),ce(Nt,j,H),it(j,_e,H),ce(jt,j,H),et=!0,Ke||(mn=[Rt(p,"pointerdown",function(){Vt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Rt(x,"pointerdown",function(){Vt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Rt(F,"pointerdown",function(){Vt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Rt(C,"pointerdown",function(){Vt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Rt(L,"pointerdown",function(){Vt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Rt(q,"pointerdown",function(){Vt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],Ke=!0)},p(j,H){r=j,(!et||H&64&&s!==(s=r[6].x))&&b(i,"x",s),(!et||H&64&&n!==(n=r[6].y))&&b(i,"y",n),(!et||H&64&&o!==(o=r[6].w))&&b(i,"width",o),(!et||H&64&&a!==(a=r[6].h))&&b(i,"height",a),(!et||H&32&&h!==(h=r[5].x))&&b(l,"x",h),(!et||H&32&&u!==(u=r[5].y))&&b(l,"y",u),(!et||H&32&&c!==(c=r[5].w))&&b(l,"width",c),(!et||H&32&&d!==(d=r[5].h))&&b(l,"height",d),(!et||H&32&&m!==(m=r[5].x))&&b(p,"x",m),(!et||H&32&&_!==(_=r[5].y))&&b(p,"y",_),(!et||H&32&&y!==(y=r[5].w))&&b(p,"width",y),(!et||H&32&&v!==(v=r[5].h))&&b(p,"height",v),(!et||H&2)&&b(x,"style",r[1]),(!et||H&32&&E!==(E=r[5].x))&&b(x,"x",E),(!et||H&32&&R!==(R=r[5].y))&&b(x,"y",R),(!et||H&32&&S!==(S=r[5].w))&&b(x,"width",S),(!et||H&32&&M!==(M=r[5].h))&&b(x,"height",M),(!et||H&32&&U!==(U=r[5].x))&&b(F,"x",U),(!et||H&32&&I!==(I=r[5].y))&&b(F,"y",I),(!et||H&32&&A!==(A=r[5].w))&&b(F,"width",A),(!et||H&32&&D!==(D=r[5].x+r[5].w))&&b(C,"x",D),(!et||H&32&&N!==(N=r[5].y))&&b(C,"y",N),(!et||H&32&&B!==(B=r[5].h))&&b(C,"height",B),(!et||H&32&&O!==(O=r[5].x))&&b(L,"x",O),(!et||H&32&&k!==(k=r[5].y+r[5].h))&&b(L,"y",k),(!et||H&32&&X!==(X=r[5].w))&&b(L,"width",X),(!et||H&32&&pt!==(pt=r[5].x))&&b(q,"x",pt),(!et||H&32&&_t!==(_t=r[5].y))&&b(q,"y",_t),(!et||H&32&&W!==(W=r[5].h))&&b(q,"height",W);const kr={};H&32&&(kr.x=r[5].x),H&32&&(kr.y=r[5].y),H&8&&(kr.scale=r[3]),dt.$set(kr);const Ur={};H&32&&(Ur.x=r[5].x+r[5].w),H&32&&(Ur.y=r[5].y),H&8&&(Ur.scale=r[3]),xt.$set(Ur);const Gr={};H&32&&(Gr.x=r[5].x+r[5].w),H&32&&(Gr.y=r[5].y+r[5].h),H&8&&(Gr.scale=r[3]),Nt.$set(Gr);const Hr={};H&32&&(Hr.x=r[5].x),H&32&&(Hr.y=r[5].y+r[5].h),H&8&&(Hr.scale=r[3]),jt.$set(Hr)},i(j){et||(ot(dt.$$.fragment,j),ot(xt.$$.fragment,j),ot(Nt.$$.fragment,j),ot(jt.$$.fragment,j),et=!0)},o(j){gt(dt.$$.fragment,j),gt(xt.$$.fragment,j),gt(Nt.$$.fragment,j),gt(jt.$$.fragment,j),et=!1},d(j){j&&(rt(t),rt(f),rt(p),rt(g),rt(x),rt(P),rt(F),rt(w),rt(C),rt(V),rt(L),rt(Y),rt(q),rt(bt),rt(mt),rt(Mt),rt(_e)),de(dt,j),de(xt,j),de(Nt,j),de(jt,j),Ke=!1,$e(mn)}}}function y0(r){let t,e;return t=new Ta({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[g0,({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(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&16&&(n.svgEl=i[4]),s&12394&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function _0(r,t,e){let i,s,{shape:n}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const u=(m,_,y)=>{const v=m.geometry.bounds;let[g,x]=[v.minX,v.minY],[E,R]=[v.maxX,v.maxY];const[S,M]=y;if(_==="SHAPE")g+=S,E+=S,x+=M,R+=M;else{switch(_){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{x+=M;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=M;break}}switch(_){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=S;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{E+=S;break}}}const P=Math.min(g,E),F=Math.min(x,R),U=Math.abs(E-g),I=Math.abs(R-x);return{...m,geometry:{x:P,y:F,w:U,h:I,bounds:{minX:P,minY:F,maxX:P+U,maxY:F+I}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){Ce.call(this,r,m)}function f(m){Ce.call(this,r,m)}function p(m){Ce.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,n=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=n.geometry),r.$$.dirty&40&&e(6,s=In(i.bounds,2/l))},[n,o,a,l,h,i,s,u,c,d,f,p]}class v0 extends De{constructor(t){super(),Ne(this,t,_0,y0,le,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var ec=Object.prototype.hasOwnProperty;function Ia(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--&&Ia(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(ec.call(r,e)&&++i&&!ec.call(t,e)||!(e in t)||!Ia(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const x0=12,b0=(r,t)=>r.polygons.reduce((e,i,s)=>{const n=i.rings.reduce((o,a,l)=>{const h=a.points.map((u,c)=>{const d=c===a.points.length-1?a.points[0]:a.points[c+1],f=(u[0]+d[0])/2,p=(u[1]+d[1])/2,m=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>x0/t;return{point:[f,p],visible:m,elementIdx:s,ringIdx:l,pointIdx:c}});return[...o,...h]},[]);return[...e,...n]},[]);function Ra(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function rc(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function ic(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function sc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function Ma(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Pa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function nc(r){let t,e,i,s;return{c(){t=Z("circle"),b(t,"cx",e=r[29][0]),b(t,"cy",i=r[29][1]),b(t,"r",s=Ds/r[3]),b(t,"class","svelte-1vxo6dc")},m(n,o){it(n,t,o)},p(n,o){o[0]&1088&&e!==(e=n[29][0])&&b(t,"cx",e),o[0]&1088&&i!==(i=n[29][1])&&b(t,"cy",i),o[0]&8&&s!==(s=Ds/n[3])&&b(t,"r",s)},d(n){n&&rt(t)}}}function oc(r){let t,e,i,s,n,o,a,l,h,u;return{c(){t=Z("mask"),e=Z("rect"),a=Z("circle"),b(e,"x",i=r[9].x),b(e,"y",s=r[9].y),b(e,"width",n=r[9].w),b(e,"height",o=r[9].h),b(e,"class","svelte-1vxo6dc"),b(a,"cx",l=r[29][0]),b(a,"cy",h=r[29][1]),b(a,"r",u=Ds/r[3]),b(a,"class","svelte-1vxo6dc"),b(t,"id",`${r[18]}-${r[32]}-inner`),b(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(c,d){it(c,t,d),wt(t,e),wt(t,a)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&b(e,"x",i),d[0]&512&&s!==(s=c[9].y)&&b(e,"y",s),d[0]&512&&n!==(n=c[9].w)&&b(e,"width",n),d[0]&512&&o!==(o=c[9].h)&&b(e,"height",o),d[0]&1088&&l!==(l=c[29][0])&&b(a,"cx",l),d[0]&1088&&h!==(h=c[29][1])&&b(a,"cy",h),d[0]&8&&u!==(u=Ds/c[3])&&b(a,"r",u)},d(c){c&&rt(t)}}}function ac(r){let t,e;function i(...s){return r[19](r[32],r[35],r[37],...s)}return t=new Wi({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(){Vt(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(){be(t.$$.fragment)},m(s,n){ce(t,s,n),e=!0},p(s,n){r=s;const o={};n[0]&32&&(o.x=r[29][0]),n[0]&32&&(o.y=r[29][1]),n[0]&8&&(o.scale=r[3]),n[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(s){e||(ot(t.$$.fragment,s),e=!0)},o(s){gt(t.$$.fragment,s),e=!1},d(s){de(t,s)}}}function lc(r){let t,e,i=ke(r[33].points),s=[];for(let o=0;o<i.length;o+=1)s[o]=ac(sc(r,i,o));const n=o=>gt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Fe()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);it(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=ke(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=sc(o,i,l);s[l]?(s[l].p(h,a),ot(s[l],1)):(s[l]=ac(h),s[l].c(),ot(s[l],1),s[l].m(t.parentNode,t))}for(Ie(),l=i.length;l<s.length;l+=1)n(l);Re()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)ot(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)gt(s[a]);e=!1},d(o){o&&rt(t),mi(s,o)}}}function hc(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v=r[6]!==void 0&&!r[7]&&nc(Pa(r)),g=r[6]!==void 0&&!r[7]&&oc(Ma(r)),x=ke(r[30].rings),E=[];for(let S=0;S<x.length;S+=1)E[S]=lc(ic(r,x,S));const R=S=>gt(E[S],1,1,()=>{E[S]=null});return{c(){t=Z("g"),e=Z("defs"),i=Z("mask"),s=Z("rect"),h=Z("path"),v&&v.c(),g&&g.c(),c=Z("path"),f=Z("path");for(let S=0;S<E.length;S+=1)E[S].c();b(s,"x",n=r[9].x),b(s,"y",o=r[9].y),b(s,"width",a=r[9].w),b(s,"height",l=r[9].h),b(s,"class","svelte-1vxo6dc"),b(h,"d",u=Ze(r[30])),b(h,"class","svelte-1vxo6dc"),b(i,"id",`${r[18]}-${r[32]}-outer`),b(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),b(c,"class","a9s-outer"),b(c,"mask",`url(#${r[18]}-${r[32]}-outer)`),b(c,"fill-rule","evenodd"),b(c,"d",d=Ze(r[30])),b(f,"class","a9s-inner"),b(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),b(f,"style",r[1]),b(f,"fill-rule","evenodd"),b(f,"d",p=Ze(r[30]))},m(S,M){it(S,t,M),wt(t,e),wt(e,i),wt(i,s),wt(i,h),v&&v.m(i,null),g&&g.m(e,null),wt(t,c),wt(t,f);for(let P=0;P<E.length;P+=1)E[P]&&E[P].m(t,null);m=!0,_||(y=[Rt(c,"pointerup",r[13]),Rt(c,"pointerdown",function(){Vt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Rt(f,"pointerup",r[13]),Rt(f,"pointerdown",function(){Vt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],_=!0)},p(S,M){if(r=S,(!m||M[0]&512&&n!==(n=r[9].x))&&b(s,"x",n),(!m||M[0]&512&&o!==(o=r[9].y))&&b(s,"y",o),(!m||M[0]&512&&a!==(a=r[9].w))&&b(s,"width",a),(!m||M[0]&512&&l!==(l=r[9].h))&&b(s,"height",l),(!m||M[0]&32&&u!==(u=Ze(r[30])))&&b(h,"d",u),r[6]!==void 0&&!r[7]?v?v.p(Pa(r),M):(v=nc(Pa(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(Ma(r),M):(g=oc(Ma(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||M[0]&32&&d!==(d=Ze(r[30])))&&b(c,"d",d),(!m||M[0]&2)&&b(f,"style",r[1]),(!m||M[0]&32&&p!==(p=Ze(r[30])))&&b(f,"d",p),M[0]&268491048){x=ke(r[30].rings);let P;for(P=0;P<x.length;P+=1){const F=ic(r,x,P);E[P]?(E[P].p(F,M),ot(E[P],1)):(E[P]=lc(F),E[P].c(),ot(E[P],1),E[P].m(t,null))}for(Ie(),P=x.length;P<E.length;P+=1)R(P);Re()}},i(S){if(!m){for(let M=0;M<x.length;M+=1)ot(E[M]);m=!0}},o(S){E=E.filter(Boolean);for(let M=0;M<E.length;M+=1)gt(E[M]);m=!1},d(S){S&&rt(t),v&&v.d(),g&&g.d(),mi(E,S),_=!1,$e(y)}}}function uc(r){let t,e;return t=new Yu({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Vt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&1088&&(n.x=r[29][0]),s[0]&1088&&(n.y=r[29][1]),s[0]&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function E0(r){let t,e,i,s=ke(r[5].polygons),n=[];for(let l=0;l<s.length;l+=1)n[l]=hc(rc(r,s,l));const o=l=>gt(n[l],1,1,()=>{n[l]=null});let a=r[6]!==void 0&&!r[7]&&uc(Ra(r));return{c(){for(let l=0;l<n.length;l+=1)n[l].c();t=Oe(),a&&a.c(),e=Fe()},m(l,h){for(let u=0;u<n.length;u+=1)n[u]&&n[u].m(l,h);it(l,t,h),a&&a.m(l,h),it(l,e,h),i=!0},p(l,h){if(h[0]&268763114){s=ke(l[5].polygons);let u;for(u=0;u<s.length;u+=1){const c=rc(l,s,u);n[u]?(n[u].p(c,h),ot(n[u],1)):(n[u]=hc(c),n[u].c(),ot(n[u],1),n[u].m(t.parentNode,t))}for(Ie(),u=s.length;u<n.length;u+=1)o(u);Re()}l[6]!==void 0&&!l[7]?a?(a.p(Ra(l),h),h[0]&192&&ot(a,1)):(a=uc(Ra(l)),a.c(),ot(a,1),a.m(e.parentNode,e)):a&&(Ie(),gt(a,1,1,()=>{a=null}),Re())},i(l){if(!i){for(let h=0;h<s.length;h+=1)ot(n[h]);ot(a),i=!0}},o(l){n=n.filter(Boolean);for(let h=0;h<n.length;h+=1)gt(n[h]);gt(a),i=!1},d(l){l&&(rt(t),rt(e)),mi(n,l),a&&a.d(l)}}}function w0(r){let t,e;return t=new Ta({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[E0,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&1&&(n.shape=i[0]),s[0]&4&&(n.transform=i[2]),s[0]&16&&(n.svgEl=i[4]),s[0]&268437482|s[1]&128&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}const T0=250,A0=1e3,Ds=4.5;function S0(r,t,e){let i,s,n;const o=Xr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:u=1}=t,{svgEl:c}=t,d,f=!1,p,m=[];const _=()=>e(7,f=!0),y=()=>e(7,f=!1),v=C=>{if(m.length>0||!s.some(k=>k.visible)){e(6,d=void 0);return}const[D,N]=h.elementToImage(C.offsetX,C.offsetY),B=k=>Math.pow(k[0]-D,2)+Math.pow(k[1]-N,2),V=Cy(i).reduce((k,X)=>B(X)<B(k)?X:k),L=s.filter(k=>k.visible).reduce((k,X)=>B(X.point)<B(k.point)?X:k),O=Math.pow(A0/u,2);B(V)<O||B(L.point)<O?e(6,d=s.indexOf(L)):e(6,d=void 0)},g=()=>{document.activeElement!==c&&c.focus()},x=()=>{e(8,m=[]),g()},E=C=>{e(7,f=!0),C.preventDefault(),C.stopPropagation(),p=performance.now()},R=(C,D,N)=>B=>{if(!p||Cr||performance.now()-p>T0)return;const V=O=>O.polygon===C&&O.ring===D&&O.point===N,L=m.some(V);B.metaKey||B.ctrlKey||B.shiftKey?L?e(8,m=m.filter(O=>!V(O))):e(8,m=[...m,{polygon:C,ring:D,point:N}]):L&&m.length>1?e(8,m=[{polygon:C,ring:D,point:N}]):L?e(8,m=[]):e(8,m=[{polygon:C,ring:D,point:N}]),g()},S=(C,D,N)=>{g();const B=C.geometry.polygons;let V;if(D==="SHAPE")V=B.map(L=>{const O=L.rings.map((X,Y)=>({points:X.points.map((q,pt)=>[q[0]+N[0],q[1]+N[1]])})),k=Ue(O[0].points);return{rings:O,bounds:k}});else{const[L,O,k,X]=D.split("-").map(Y=>parseInt(Y));V=B.map((Y,q)=>{if(q===O){const pt=Y.rings.map((W,bt)=>bt===k?{points:W.points.map((dt,mt)=>mt===X?[dt[0]+N[0],dt[1]+N[1]]:dt)}:W),_t=Ue(pt[0].points);return{rings:pt,bounds:_t}}else return Y})}return{...C,geometry:{polygons:V,bounds:fa(V)}}},M=C=>async D=>{D.stopPropagation();const N=s[C],B=i.polygons.map((L,O)=>{if(O===N.elementIdx){const k=L.rings.map((Y,q)=>q===N.ringIdx?{points:[...Y.points.slice(0,N.pointIdx+1),N.point,...Y.points.slice(N.pointIdx+1)]}:Y),X=Ue(k[0].points);return{rings:k,bounds:X}}else return L});o("change",{...a,geometry:{polygons:B,bounds:fa(B)}}),await bu();const V=[...document.querySelectorAll(".a9s-handle")][C+1];if(V!=null&&V.firstChild){const L=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:D.clientX,clientY:D.clientY,pointerId:D.pointerId,pointerType:D.pointerType,isPrimary:D.isPrimary,buttons:D.buttons});V.firstChild.dispatchEvent(L)}},P=()=>{const C=i.polygons.map((D,N)=>{if(m.some(B=>B.polygon===N)){const B=D.rings.map((L,O)=>m.some(k=>k.polygon===N&&k.ring===O)&&L.points.length>3?{points:L.points.filter((k,X)=>!m.some(Y=>Y.polygon===N&&Y.ring===O&&Y.point===X))}:L),V=Ue(B[0].points);return{rings:B,bounds:V}}else return D});!Ia(i.polygons,C)&&(o("change",{...a,geometry:{polygons:C,bounds:fa(C)}}),e(8,m=[]))};gi(()=>{if(Cr)return;const C=D=>{(D.key==="Delete"||D.key==="Backspace")&&(D.preventDefault(),P())};return c.addEventListener("pointermove",v),c.addEventListener("keydown",C),()=>{c.removeEventListener("pointermove",v),c.removeEventListener("keydown",C)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(C,D,N,{polygon:B,ring:V,point:L})=>B===C&&V===D&&L===N;function I(C){Ce.call(this,r,C)}function A(C){Ce.call(this,r,C)}function w(C){Ce.call(this,r,C)}return r.$$set=C=>{"shape"in C&&e(0,a=C.shape),"computedStyle"in C&&e(1,l=C.computedStyle),"transform"in C&&e(2,h=C.transform),"viewportScale"in C&&e(3,u=C.viewportScale),"svgEl"in C&&e(4,c=C.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,s=Cr?[]:b0(i,u)),r.$$.dirty[0]&40&&e(9,n=In(i.bounds,Ds/u))},[a,l,h,u,c,i,d,f,m,n,s,_,y,x,E,R,S,M,F,U,I,A,w]}class C0 extends De{constructor(t){super(),Ne(this,t,S0,w0,le,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const cc=new Map([[Tt.RECTANGLE,v0],[Tt.POLYGON,m0],[Tt.MULTIPOLYGLON,C0]]),dc=r=>cc.get(r.type),fc=(r,t)=>cc.set(r,t);function I0(r,t,e){let i;const s=Xr();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:u}=t,c;return gi(()=>(e(6,c=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:u,svgEl:l.closest("svg")}})),c.$on("change",d=>{c.$$set({shape:d.detail}),s("change",d.detail)}),c.$on("grab",d=>s("grab",d.detail)),c.$on("release",d=>s("release",d.detail)),()=>{c.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,n=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,u=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=Os(n,a)),r.$$.dirty&65&&n&&(c==null||c.$set({shape:n.target.selector})),r.$$.dirty&80&&c&&c.$set({transform:h}),r.$$.dirty&96&&c&&c.$set({viewportScale:u}),r.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[n,o,a,l,h,u,c,i]}class R0 extends De{constructor(t){super(),Ne(this,t,I0,null,le,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function M0(r,t,e){const i=Xr();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return gi(()=>{const u=n.closest("svg"),c=[],d=(f,p,m)=>{u==null||u.addEventListener(f,p,m),c.push(()=>u==null?void 0:u.removeEventListener(f,p,m))};return e(5,h=new o({target:n,props:{addEventListener:d,drawingMode:s,transform:a,viewportScale:l}})),h.$on("create",f=>i("create",f.detail)),()=>{c.forEach(f=>f()),h.$destroy()}}),r.$$set=u=>{"drawingMode"in u&&e(0,s=u.drawingMode),"target"in u&&e(1,n=u.target),"tool"in u&&e(2,o=u.tool),"transform"in u&&e(3,a=u.transform),"viewportScale"in u&&e(4,l=u.viewportScale)},r.$$.update=()=>{r.$$.dirty&40&&h&&h.$set({transform:a}),r.$$.dirty&48&&h&&h.$set({viewportScale:l})},[s,n,o,a,l,h]}class P0 extends De{constructor(t){super(),Ne(this,t,M0,null,le,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function pc(r){let t,e,i,s,n,o,a,l,h,u;return{c(){t=Z("defs"),e=Z("mask"),i=Z("rect"),l=Z("rect"),h=Z("rect"),u=Z("rect"),b(i,"class","rect-mask-bg svelte-1a76qe7"),b(i,"x",s=r[1]-r[5]),b(i,"y",n=r[2]-r[5]),b(i,"width",o=r[3]+2*r[5]),b(i,"height",a=r[4]+2*r[5]),b(l,"class","rect-mask-fg svelte-1a76qe7"),b(l,"x",r[1]),b(l,"y",r[2]),b(l,"width",r[3]),b(l,"height",r[4]),b(e,"id",r[6]),b(e,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),b(h,"class","a9s-outer"),b(h,"mask",`url(#${r[6]})`),b(h,"x",r[1]),b(h,"y",r[2]),b(h,"width",r[3]),b(h,"height",r[4]),b(u,"class","a9s-inner"),b(u,"x",r[1]),b(u,"y",r[2]),b(u,"width",r[3]),b(u,"height",r[4])},m(c,d){it(c,t,d),wt(t,e),wt(e,i),wt(e,l),it(c,h,d),it(c,u,d)},p(c,d){d&34&&s!==(s=c[1]-c[5])&&b(i,"x",s),d&36&&n!==(n=c[2]-c[5])&&b(i,"y",n),d&40&&o!==(o=c[3]+2*c[5])&&b(i,"width",o),d&48&&a!==(a=c[4]+2*c[5])&&b(i,"height",a),d&2&&b(l,"x",c[1]),d&4&&b(l,"y",c[2]),d&8&&b(l,"width",c[3]),d&16&&b(l,"height",c[4]),d&2&&b(h,"x",c[1]),d&4&&b(h,"y",c[2]),d&8&&b(h,"width",c[3]),d&16&&b(h,"height",c[4]),d&2&&b(u,"x",c[1]),d&4&&b(u,"y",c[2]),d&8&&b(u,"width",c[3]),d&16&&b(u,"height",c[4])},d(c){c&&(rt(t),rt(h),rt(u))}}}function O0(r){let t,e=r[0]&&pc(r);return{c(){t=Z("g"),e&&e.c(),b(t,"class","a9s-annotation a9s-rubberband")},m(i,s){it(i,t,s),e&&e.m(t,null)},p(i,[s]){i[0]?e?e.p(i,s):(e=pc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Dt,o:Dt,d(i){i&&rt(t),e&&e.d()}}}function N0(r,t,e){let i;const s=Xr();let{addEventListener:n}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,u,c,d,f,p,m;const _=E=>{const R=E;h=performance.now(),o==="drag"&&(e(0,u=a.elementToImage(R.offsetX,R.offsetY)),c=u,e(1,d=u[0]),e(2,f=u[1]),e(3,p=1),e(4,m=1))},y=E=>{const R=E;u&&(c=a.elementToImage(R.offsetX,R.offsetY),e(1,d=Math.min(c[0],u[0])),e(2,f=Math.min(c[1],u[1])),e(3,p=Math.abs(c[0]-u[0])),e(4,m=Math.abs(c[1]-u[1])))},v=E=>{const R=E,S=performance.now()-h;if(o==="click"){if(S>300)return;u?g():(e(0,u=a.elementToImage(R.offsetX,R.offsetY)),c=u,e(1,d=u[0]),e(2,f=u[1]),e(3,p=1),e(4,m=1))}else u&&(S>300||p*m>100?(R.stopPropagation(),g()):(e(0,u=void 0),c=void 0))},g=()=>{if(p*m>15){const E={type:Tt.RECTANGLE,geometry:{bounds:{minX:d,minY:f,maxX:d+p,maxY:f+m},x:d,y:f,w:p,h:m}};s("create",E)}e(0,u=void 0),c=void 0};gi(()=>{n("pointerdown",_),n("pointermove",y),n("pointerup",v,!0)});const x=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=E=>{"addEventListener"in E&&e(7,n=E.addEventListener),"drawingMode"in E&&e(8,o=E.drawingMode),"transform"in E&&e(9,a=E.transform),"viewportScale"in E&&e(10,l=E.viewportScale)},r.$$.update=()=>{r.$$.dirty&1024&&e(5,i=2/l)},[u,d,f,p,m,i,x,n,o,a,l]}class D0 extends De{constructor(t){super(),Ne(this,t,N0,O0,le,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function Oa(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function mc(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m=r[1]&&gc(r);return{c(){t=Z("defs"),e=Z("mask"),i=Z("rect"),l=Z("polygon"),u=Z("polygon"),d=Z("polygon"),m&&m.c(),p=Fe(),b(i,"x",s=r[3].x),b(i,"y",n=r[3].y),b(i,"width",o=r[3].w),b(i,"height",a=r[3].h),b(i,"class","svelte-18wrg3t"),b(l,"points",h=r[19]),b(l,"class","svelte-18wrg3t"),b(e,"id",r[5]),b(e,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),b(u,"class","a9s-outer"),b(u,"mask",`url(#${r[5]})`),b(u,"points",c=r[19]),b(d,"class","a9s-inner"),b(d,"points",f=r[19])},m(_,y){it(_,t,y),wt(t,e),wt(e,i),wt(e,l),it(_,u,y),it(_,d,y),m&&m.m(_,y),it(_,p,y)},p(_,y){y&8&&s!==(s=_[3].x)&&b(i,"x",s),y&8&&n!==(n=_[3].y)&&b(i,"y",n),y&8&&o!==(o=_[3].w)&&b(i,"width",o),y&8&&a!==(a=_[3].h)&&b(i,"height",a),y&4&&h!==(h=_[19])&&b(l,"points",h),y&4&&c!==(c=_[19])&&b(u,"points",c),y&4&&f!==(f=_[19])&&b(d,"points",f),_[1]?m?m.p(_,y):(m=gc(_),m.c(),m.m(p.parentNode,p)):m&&(m.d(1),m=null)},d(_){_&&(rt(t),rt(u),rt(d),rt(p)),m&&m.d(_)}}}function gc(r){let t,e,i;return{c(){t=Z("circle"),b(t,"class","a9s-handle svelte-18wrg3t"),b(t,"cx",e=r[0][0][0]),b(t,"cy",i=r[0][0][1]),b(t,"r",r[4])},m(s,n){it(s,t,n)},p(s,n){n&1&&e!==(e=s[0][0][0])&&b(t,"cx",e),n&1&&i!==(i=s[0][0][1])&&b(t,"cy",i),n&16&&b(t,"r",s[4])},d(s){s&&rt(t)}}}function L0(r){let t,e=r[3]&&mc(Oa(r));return{c(){t=Z("g"),e&&e.c(),b(t,"class","a9s-annotation a9s-rubberband")},m(i,s){it(i,t,s),e&&e.m(t,null)},p(i,[s]){i[3]?e?e.p(Oa(i),s):(e=mc(Oa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Dt,o:Dt,d(i){i&&rt(t),e&&e.d()}}}const B0=20,F0=1500;function k0(r,t,e){let i,s,n;const o=Xr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:u=1}=t,c,d=[],f,p,m=!1;const _=R=>{const S=R,{timeStamp:M,offsetX:P,offsetY:F}=S;if(c={timeStamp:M,offsetX:P,offsetY:F},l==="drag"&&d.length===0){const U=h.elementToImage(S.offsetX,S.offsetY);d.push(U),e(10,f=U)}},y=R=>{const S=R;if(p&&clearTimeout(p),d.length>0){if(e(10,f=h.elementToImage(S.offsetX,S.offsetY)),d.length>2){const M=wa(f,d[0])*u;e(1,m=M<B0)}S.pointerType==="touch"&&(p=setTimeout(()=>{g()},F0))}},v=R=>{const S=R;if(p&&clearTimeout(p),l==="click"){const M=S.timeStamp-c.timeStamp,P=wa([c.offsetX,c.offsetY],[S.offsetX,S.offsetY]);if(M>300||P>15)return;if(m)x();else if(d.length===0){const F=h.elementToImage(S.offsetX,S.offsetY);d.push(F),e(10,f=F)}else d.push(f)}else{if(d.length===1&&wa(d[0],f)<=4){e(0,d=[]),e(10,f=void 0);return}S.stopImmediatePropagation(),m?x():d.push(f)}},g=()=>{if(!f)return;const R=d.slice(0,-1);if(R.length<3)return;const S={type:Tt.POLYGON,geometry:{bounds:Ue(d),points:R}};ua(S)>4&&(e(0,d=[]),e(10,f=void 0),o("create",S))},x=()=>{const R={type:Tt.POLYGON,geometry:{bounds:Ue(d),points:[...d]}};e(0,d=[]),e(10,f=void 0),o("create",R)};gi(()=>{a("pointerdown",_,!0),a("pointermove",y),a("pointerup",v,!0),a("dblclick",g,!0)});const E=`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,u=R.viewportScale)},r.$$.update=()=>{r.$$.dirty&512&&e(4,i=4/u),r.$$.dirty&1027&&e(2,s=f?m?d:[...d,f]:[]),r.$$.dirty&516&&e(3,n=s.length>0?In(Ue(s),2/u):void 0)},[d,m,s,n,i,E,a,l,h,u,f]}class U0 extends De{constructor(t){super(),Ne(this,t,k0,L0,le,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Na=new Map([["rectangle",{tool:D0}],["polygon",{tool:U0}]]),Rn=()=>[...Na.keys()],Mn=r=>Na.get(r),yc=(r,t,e={})=>Na.set(r,{tool:t,opts:e});function G0(r){let t,e,i,s,n;return{c(){t=Z("g"),e=Z("ellipse"),s=Z("ellipse"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"cx",r[2]),b(e,"cy",r[3]),b(e,"rx",r[4]),b(e,"ry",r[5]),b(s,"class","a9s-inner"),b(s,"style",r[1]),b(s,"cx",r[2]),b(s,"cy",r[3]),b(s,"rx",r[4]),b(s,"ry",r[5]),b(t,"class","a9s-annotation"),b(t,"data-id",n=r[0].id)},m(o,a){it(o,t,a),wt(t,e),wt(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&b(t,"data-id",n)},i:Dt,o:Dt,d(o){o&&rt(t)}}}function H0(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:u}=n;return r.$$set=c=>{"annotation"in c&&e(0,s=c.annotation),"geom"in c&&e(6,n=c.geom),"style"in c&&e(7,o=c.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=Os(s,o))},[s,i,a,l,h,u,n,o]}class $0 extends De{constructor(t){super(),Ne(this,t,H0,G0,le,{annotation:0,geom:6,style:7})}}function _c(r,t,e){const i=r.slice();return i[5]=t[e],i}function vc(r){let t,e,i;return{c(){t=Z("path"),i=Z("path"),b(t,"class","a9s-outer"),b(t,"style",e=r[1]?"display:none;":void 0),b(t,"fill-rule","evenodd"),b(t,"d",Ze(r[5])),b(i,"class","a9s-inner"),b(i,"style",r[1]),b(i,"fill-rule","evenodd"),b(i,"d",Ze(r[5]))},m(s,n){it(s,t,n),it(s,i,n)},p(s,n){n&2&&e!==(e=s[1]?"display:none;":void 0)&&b(t,"style",e),n&2&&b(i,"style",s[1])},d(s){s&&(rt(t),rt(i))}}}function X0(r){let t,e,i=ke(r[2]),s=[];for(let n=0;n<i.length;n+=1)s[n]=vc(_c(r,i,n));return{c(){t=Z("g");for(let n=0;n<s.length;n+=1)s[n].c();b(t,"class","a9s-annotation"),b(t,"data-id",e=r[0].id)},m(n,o){it(n,t,o);for(let a=0;a<s.length;a+=1)s[a]&&s[a].m(t,null)},p(n,[o]){if(o&6){i=ke(n[2]);let a;for(a=0;a<i.length;a+=1){const l=_c(n,i,a);s[a]?s[a].p(l,o):(s[a]=vc(l),s[a].c(),s[a].m(t,null))}for(;a<s.length;a+=1)s[a].d(1);s.length=i.length}o&1&&e!==(e=n[0].id)&&b(t,"data-id",e)},i:Dt,o:Dt,d(n){n&&rt(t),mi(s,n)}}}function V0(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{polygons:a}=n;return r.$$set=l=>{"annotation"in l&&e(0,s=l.annotation),"geom"in l&&e(3,n=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=Os(s,o))},[s,i,a,n,o]}class z0 extends De{constructor(t){super(),Ne(this,t,V0,X0,le,{annotation:0,geom:3,style:4})}}function Y0(r){let t,e,i,s,n;return{c(){t=Z("g"),e=Z("polygon"),s=Z("polygon"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"points",r[2].map(W0).join(" ")),b(s,"class","a9s-inner"),b(s,"style",r[1]),b(s,"points",r[2].map(j0).join(" ")),b(t,"class","a9s-annotation"),b(t,"data-id",n=r[0].id)},m(o,a){it(o,t,a),wt(t,e),wt(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&b(t,"data-id",n)},i:Dt,o:Dt,d(o){o&&rt(t)}}}const W0=r=>r.join(","),j0=r=>r.join(",");function q0(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{points:a}=n;return r.$$set=l=>{"annotation"in l&&e(0,s=l.annotation),"geom"in l&&e(3,n=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=Os(s,o))},[s,i,a,n,o]}class K0 extends De{constructor(t){super(),Ne(this,t,q0,Y0,le,{annotation:0,geom:3,style:4})}}function Z0(r){let t,e,i,s,n;return{c(){t=Z("g"),e=Z("rect"),s=Z("rect"),b(e,"class","a9s-outer"),b(e,"style",i=r[5]?"display:none;":void 0),b(e,"x",r[4]),b(e,"y",r[3]),b(e,"width",r[2]),b(e,"height",r[1]),b(s,"class","a9s-inner"),b(s,"style",r[5]),b(s,"x",r[4]),b(s,"y",r[3]),b(s,"width",r[2]),b(s,"height",r[1]),b(t,"class","a9s-annotation"),b(t,"data-id",n=r[0].id)},m(o,a){it(o,t,a),wt(t,e),wt(t,s)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&b(e,"style",i),a&16&&b(e,"x",o[4]),a&8&&b(e,"y",o[3]),a&4&&b(e,"width",o[2]),a&2&&b(e,"height",o[1]),a&32&&b(s,"style",o[5]),a&16&&b(s,"x",o[4]),a&8&&b(s,"y",o[3]),a&4&&b(s,"width",o[2]),a&2&&b(s,"height",o[1]),a&1&&n!==(n=o[0].id)&&b(t,"data-id",n)},i:Dt,o:Dt,d(o){o&&rt(t)}}}function Q0(r,t,e){let i,s,n,o,a,{annotation:l}=t,{geom:h}=t,{style:u}=t;return r.$$set=c=>{"annotation"in c&&e(0,l=c.annotation),"geom"in c&&e(6,h=c.geom),"style"in c&&e(7,u=c.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=Os(l,u)),r.$$.dirty&64&&e(4,{x:s,y:n,w:o,h:a}=h,s,(e(3,n),e(6,h)),(e(2,o),e(6,h)),(e(1,a),e(6,h)))},[l,a,o,n,s,i,h,u]}class J0 extends De{constructor(t){super(),Ne(this,t,Q0,Z0,le,{annotation:0,geom:6,style:7})}}const tv=r=>({elementToImage:(t,e)=>{const i=r.getBoundingClientRect(),s=r.createSVGPoint();s.x=t+i.x,s.y=e+i.y;const{x:n,y:o}=s.matrixTransform(r.getScreenCTM().inverse());return[n,o]}}),ev=250,rv=(r,t)=>{const e=Xr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<ev){const{x:n,y:o}=xc(s,r),a=t.getAt(n,o);a?e("click",{originalEvent:s,annotation:a}):e("click",{originalEvent:s})}}}},xc=(r,t)=>{const e=t.createSVGPoint(),i=t.getBoundingClientRect(),s=r.clientX-i.x,n=r.clientY-i.y,{left:o,top:a}=t.getBoundingClientRect();return e.x=s+o,e.y=n+a,e.matrixTransform(t.getScreenCTM().inverse())};function bc(r,t,e){const i=r.slice();i[39]=t[e];const s=i[24](i[39].target.selector);return i[40]=s,i}function Ec(r,t,e){const i=r.slice();return i[43]=t[e],i}function Da(r){const t=r.slice(),e=t[43].target.selector;return t[46]=e,t}function wc(r){let t=r[43],e,i,s=Tc(r);return{c(){s.c(),e=Fe()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&65536&&le(t,t=n[43])?(Ie(),gt(s,1,1,Dt),Re(),s=Tc(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){gt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function iv(r){let t,e;return t=new z0({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function sv(r){let t,e;return t=new K0({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function nv(r){let t,e;return t=new J0({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function ov(r){var t;let e,i;return e=new $0({props:{annotation:r[43],geom:(t=r[46])==null?void 0:t.geometry,style:r[1]}}),{c(){be(e.$$.fragment)},m(s,n){ce(e,s,n),i=!0},p(s,n){var o;const a={};n[0]&65536&&(a.annotation=s[43]),n[0]&65536&&(a.geom=(o=s[46])==null?void 0:o.geometry),n[0]&2&&(a.style=s[1]),e.$set(a)},i(s){i||(ot(e.$$.fragment,s),i=!0)},o(s){gt(e.$$.fragment,s),i=!1},d(s){de(e,s)}}}function Tc(r){let t,e,i,s;const n=[ov,nv,sv,iv],o=[];function a(l,h){var u,c,d,f;return((u=l[46])==null?void 0:u.type)===Tt.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===Tt.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===Tt.POLYGON?2:((f=l[46])==null?void 0:f.type)===Tt.MULTIPOLYGLON?3:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=Fe()},m(l,h){~t&&o[t].m(l,h),it(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(Ie(),gt(o[u],1,1,()=>{o[u]=null}),Re()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),ot(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(ot(e),s=!0)},o(l){gt(e),s=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function Ac(r){let t=ze(r[43])&&!r[9](r[43]),e,i,s=t&&wc(Da(r));return{c(){s&&s.c(),e=Fe()},m(n,o){s&&s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&66048&&(t=ze(n[43])&&!n[9](n[43])),t?s?(s.p(Da(n),o),o[0]&66048&&ot(s,1)):(s=wc(Da(n)),s.c(),ot(s,1),s.m(e.parentNode,e)):s&&(Ie(),gt(s,1,1,()=>{s=null}),Re())},i(n){i||(ot(s),i=!0)},o(n){gt(s),i=!1},d(n){n&&rt(e),s&&s.d(n)}}}function Sc(r){let t,e,i,s;const n=[lv,av],o=[];function a(l,h){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=Fe()},m(l,h){~t&&o[t].m(l,h),it(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(Ie(),gt(o[u],1,1,()=>{o[u]=null}),Re()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),ot(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(ot(e),s=!0)},o(l){gt(e),s=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function av(r){let t=`${r[2]}-${r[5]}`,e,i,s=Cc(r);return{c(){s.c(),e=Fe()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&36&&le(t,t=`${n[2]}-${n[5]}`)?(Ie(),gt(s,1,1,Dt),Re(),s=Cc(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){gt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function lv(r){let t,e,i=ke(r[8]),s=[];for(let o=0;o<i.length;o+=1)s[o]=Mc(bc(r,i,o));const n=o=>gt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Fe()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);it(o,t,a),e=!0},p(o,a){if(a[0]&21107010){i=ke(o[8]);let l;for(l=0;l<i.length;l+=1){const h=bc(o,i,l);s[l]?(s[l].p(h,a),ot(s[l],1)):(s[l]=Mc(h),s[l].c(),ot(s[l],1),s[l].m(t.parentNode,t))}for(Ie(),l=i.length;l<s.length;l+=1)n(l);Re()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)ot(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)gt(s[a]);e=!1},d(o){o&&rt(t),mi(s,o)}}}function Cc(r){let t,e;return t=new P0({props:{target:r[6],tool:r[14],drawingMode:r[13],transform:r[12],viewportScale:r[17]}}),t.$on("create",r[21]),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&64&&(n.target=i[6]),s[0]&16384&&(n.tool=i[14]),s[0]&8192&&(n.drawingMode=i[13]),s[0]&4096&&(n.transform=i[12]),s[0]&131072&&(n.viewportScale=i[17]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function Ic(r){let t=r[39].id,e,i,s=Rc(r);return{c(){s.c(),e=Fe()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&256&&le(t,t=n[39].id)?(Ie(),gt(s,1,1,Dt),Re(),s=Rc(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){gt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function Rc(r){let t,e;return t=new R0({props:{target:r[6],editor:r[24](r[39].target.selector),annotation:r[39],style:r[1],transform:r[12],viewportScale:r[17]}}),t.$on("change",function(){Vt(r[22](r[39]))&&r[22](r[39]).apply(this,arguments)}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&64&&(n.target=r[6]),s[0]&256&&(n.editor=r[24](r[39].target.selector)),s[0]&256&&(n.annotation=r[39]),s[0]&2&&(n.style=r[1]),s[0]&4096&&(n.transform=r[12]),s[0]&131072&&(n.viewportScale=r[17]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function Mc(r){let t,e,i=r[40]&&Ic(r);return{c(){i&&i.c(),t=Fe()},m(s,n){i&&i.m(s,n),it(s,t,n),e=!0},p(s,n){s[40]?i?(i.p(s,n),n[0]&256&&ot(i,1)):(i=Ic(s),i.c(),ot(i,1),i.m(t.parentNode,t)):i&&(Ie(),gt(i,1,1,()=>{i=null}),Re())},i(s){e||(ot(i),e=!0)},o(s){gt(i),e=!1},d(s){s&&rt(t),i&&i.d(s)}}}function hv(r){let t,e,i,s,n,o,a=ke(r[16].filter(r[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=Ac(Ec(r,a,c));const h=c=>gt(l[c],1,1,()=>{l[c]=null});let u=r[6]&&Sc(r);return{c(){t=Z("svg"),e=Z("g");for(let c=0;c<l.length;c+=1)l[c].c();i=Z("g"),u&&u.c(),b(i,"class","drawing"),b(t,"role","application"),b(t,"tabindex",0),b(t,"class","a9s-annotationlayer"),cr(t,"drawing",r[14]),cr(t,"editing",r[8]),cr(t,"hidden",!r[3]),cr(t,"hover",r[15])},m(c,d){it(c,t,d),wt(t,e);for(let f=0;f<l.length;f+=1)l[f]&&l[f].m(e,null);wt(t,i),u&&u.m(i,null),r[35](i),r[36](t),s=!0,n||(o=[Rt(t,"pointerup",function(){Vt(r[10])&&r[10].apply(this,arguments)}),Rt(t,"pointerdown",function(){Vt(r[11])&&r[11].apply(this,arguments)}),Rt(t,"pointermove",r[23])],n=!0)},p(c,d){if(r=c,d[0]&66050){a=ke(r[16].filter(r[34]));let f;for(f=0;f<a.length;f+=1){const p=Ec(r,a,f);l[f]?(l[f].p(p,d),ot(l[f],1)):(l[f]=Ac(p),l[f].c(),ot(l[f],1),l[f].m(e,null))}for(Ie(),f=a.length;f<l.length;f+=1)h(f);Re()}r[6]?u?(u.p(r,d),d[0]&64&&ot(u,1)):(u=Sc(r),u.c(),ot(u,1),u.m(i,null)):u&&(Ie(),gt(u,1,1,()=>{u=null}),Re()),(!s||d[0]&16384)&&cr(t,"drawing",r[14]),(!s||d[0]&256)&&cr(t,"editing",r[8]),(!s||d[0]&8)&&cr(t,"hidden",!r[3]),(!s||d[0]&32768)&&cr(t,"hover",r[15])},i(c){if(!s){for(let d=0;d<a.length;d+=1)ot(l[d]);ot(u),s=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)gt(l[d]);gt(u),s=!1},d(c){c&&rt(t),mi(l,c),u&&u.d(),r[35](null),r[36](null),n=!1,$e(o)}}}function uv(r,t,e){let i,s,n,o,a,l,h,u,c,d,f,p=Dt,m=()=>(p(),p=fu(w,W=>e(17,f=W)),w);r.$$.on_destroy.push(()=>p());let{drawingEnabled:_}=t,{image:y}=t,{preferredDrawingMode:v}=t,{state:g}=t,{style:x=void 0}=t,{toolName:E=Rn()[0]}=t,{user:R}=t,{visible:S=!0}=t,M=0;const P=()=>e(5,M+=1),F=()=>E,U=()=>_;let I,A,w;gi(()=>m(e(7,w=Z_(y,A))));const{hover:C,selection:D,store:N}=g;na(r,C,W=>e(15,u=W)),na(r,D,W=>e(33,c=W)),na(r,N,W=>e(16,d=W));let B,V;const L=W=>{B&&N.unobserve(B);const bt=W.filter(({editable:dt})=>dt).map(({id:dt})=>dt);bt.length>0?(e(8,V=bt.map(dt=>N.getAnnotation(dt)).filter(dt=>dt&&ze(dt))),B=dt=>{const{updated:mt}=dt.changes;e(8,V=mt==null?void 0:mt.map(xt=>xt.newValue))},N.observe(B,{annotations:bt})):e(8,V=void 0)},O=W=>{const bt=ku(),dt={id:bt,bodies:[],target:{annotation:bt,selector:W.detail,creator:R,created:new Date}};N.addAnnotation(dt),D.setSelected(dt.id)},k=W=>bt=>{var dt;const{target:mt}=W,xt=10*60*1e3,Mt=((dt=mt.creator)==null?void 0:dt.id)!==R.id||!mt.created||new Date().getTime()-mt.created.getTime()>xt;N.updateTarget({...mt,selector:bt.detail,created:Mt?mt.created:new Date,updated:Mt?new Date:void 0,updatedBy:Mt?R:void 0})},X=W=>{const{x:bt,y:dt}=xc(W,A),mt=N.getAt(bt,dt);mt?u!==mt.id&&C.set(mt.id):C.set(void 0)},Y=W=>dc(W),q=W=>ze(W);function pt(W){bn[W?"unshift":"push"](()=>{I=W,e(6,I)})}function _t(W){bn[W?"unshift":"push"](()=>{A=W,e(4,A)})}return r.$$set=W=>{"drawingEnabled"in W&&e(0,_=W.drawingEnabled),"image"in W&&e(25,y=W.image),"preferredDrawingMode"in W&&e(26,v=W.preferredDrawingMode),"state"in W&&e(27,g=W.state),"style"in W&&e(1,x=W.style),"toolName"in W&&e(2,E=W.toolName),"user"in W&&e(28,R=W.user),"visible"in W&&e(3,S=W.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(14,{tool:i,opts:s}=Mn(E)||{tool:void 0,opts:void 0},i,(e(32,s),e(2,E))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(13,n=(s==null?void 0:s.drawingMode)||v),r.$$.dirty[0]&16&&e(12,o=tv(A)),r.$$.dirty[0]&16&&e(11,{onPointerDown:a,onPointerUp:l}=rv(A,N),a,(e(10,l),e(4,A))),r.$$.dirty[1]&4&&e(9,h=W=>c.selected.find(bt=>bt.id===W.id&&bt.editable)),r.$$.dirty[1]&4&&L(c.selected)},[_,x,E,S,A,M,I,w,V,h,l,a,o,n,i,u,d,f,C,D,N,O,k,X,Y,y,v,g,R,P,F,U,s,c,q,pt,_t]}class cv extends De{constructor(t){super(),Ne(this,t,uv,hv,le,{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 Pc(r,t,e=0,i=r.length-1,s=dv){for(;i>e;){if(i-e>600){const l=i-e+1,h=t-e+1,u=Math.log(l),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(l-c)/l)*(h-l/2<0?-1:1),f=Math.max(e,Math.floor(t-h*c/l+d)),p=Math.min(i,Math.floor(t+(l-h)*c/l+d));Pc(r,t,f,p,s)}const n=r[t];let o=e,a=i;for(Ls(r,e,t),s(r[i],n)>0&&Ls(r,e,i);o<a;){for(Ls(r,o,a),o++,a--;s(r[o],n)<0;)o++;for(;s(r[a],n)>0;)a--}s(r[e],n)===0?Ls(r,e,a):(a++,Ls(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function Ls(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function dv(r,t){return r<t?-1:r>t?1:0}class fv{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(!On(t,e))return i;const s=this.toBBox,n=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?s(a):a;On(t,l)&&(e.leaf?i.push(a):Ba(t,l)?this._all(a,i):n.push(a))}e=n.pop()}return i}collides(t){let e=this.data;if(!On(t,e))return!1;const i=[];for(;e;){for(let s=0;s<e.children.length;s++){const n=e.children[s],o=e.leaf?this.toBBox(n):n;if(On(t,o)){if(e.leaf||Ba(t,o))return!0;i.push(n)}}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=qi([]),this}remove(t,e){if(!t)return this;let i=this.data;const s=this.toBBox(t),n=[],o=[];let a,l,h;for(;i||n.length;){if(i||(i=n.pop(),l=n[n.length-1],a=o.pop(),h=!0),i.leaf){const u=pv(t,i.children,e);if(u!==-1)return i.children.splice(u,1),n.push(i),this._condense(n),this}!h&&!i.leaf&&Ba(i,s)?(n.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,s){const n=i-e+1;let o=this._maxEntries,a;if(n<=o)return a=qi(t.slice(e,i+1)),ji(a,this.toBBox),a;s||(s=Math.ceil(Math.log(n)/Math.log(o)),o=Math.ceil(n/Math.pow(o,s-1))),a=qi([]),a.leaf=!1,a.height=s;const l=Math.ceil(n/o),h=l*Math.ceil(Math.sqrt(o));Oc(t,e,i,h,this.compareMinX);for(let u=e;u<=i;u+=h){const c=Math.min(u+h-1,i);Oc(t,u,c,l,this.compareMinY);for(let d=u;d<=c;d+=l){const f=Math.min(d+l-1,c);a.children.push(this._build(t,d,f,s-1))}}return ji(a,this.toBBox),a}_chooseSubtree(t,e,i,s){for(;s.push(e),!(e.leaf||s.length-1===i);){let n=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],u=La(h),c=yv(t,h)-u;c<o?(o=c,n=u<n?u:n,a=h):c===o&&u<n&&(n=u,a=h)}e=a||e.children[0]}return e}_insert(t,e,i){const s=i?t:this.toBBox(t),n=[],o=this._chooseSubtree(s,this.data,e,n);for(o.children.push(t),Fs(o,s);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(s,n,e)}_split(t,e){const i=t[e],s=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,s);const o=this._chooseSplitIndex(i,n,s),a=qi(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,ji(i,this.toBBox),ji(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=qi([t,e]),this.data.height=t.height+1,this.data.leaf=!1,ji(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let s,n=1/0,o=1/0;for(let a=e;a<=i-e;a++){const l=Bs(t,0,a,this.toBBox),h=Bs(t,a,i,this.toBBox),u=_v(l,h),c=La(l)+La(h);u<n?(n=u,s=a,o=c<o?c:o):u===n&&c<o&&(o=c,s=a)}return s||i-e}_chooseSplitAxis(t,e,i){const s=t.leaf?this.compareMinX:mv,n=t.leaf?this.compareMinY:gv,o=this._allDistMargin(t,e,i,s),a=this._allDistMargin(t,e,i,n);o<a&&t.children.sort(s)}_allDistMargin(t,e,i,s){t.children.sort(s);const n=this.toBBox,o=Bs(t,0,e,n),a=Bs(t,i-e,i,n);let l=Pn(o)+Pn(a);for(let h=e;h<i-e;h++){const u=t.children[h];Fs(o,t.leaf?n(u):u),l+=Pn(o)}for(let h=i-e-1;h>=e;h--){const u=t.children[h];Fs(a,t.leaf?n(u):u),l+=Pn(a)}return l}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)Fs(e[s],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():ji(t[e],this.toBBox)}}function pv(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 ji(r,t){Bs(r,0,r.children.length,t,r)}function Bs(r,t,e,i,s){s||(s=qi(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let n=t;n<e;n++){const o=r.children[n];Fs(s,r.leaf?i(o):o)}return s}function Fs(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 mv(r,t){return r.minX-t.minX}function gv(r,t){return r.minY-t.minY}function La(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Pn(r){return r.maxX-r.minX+(r.maxY-r.minY)}function yv(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 _v(r,t){const e=Math.max(r.minX,t.minX),i=Math.max(r.minY,t.minY),s=Math.min(r.maxX,t.maxX),n=Math.min(r.maxY,t.maxY);return Math.max(0,s-e)*Math.max(0,n-i)}function Ba(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function On(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function qi(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Oc(r,t,e,i,s){const n=[t,e];for(;n.length;){if(e=n.pop(),t=n.pop(),e-t<=i)continue;const o=t+Math.ceil((e-t)/i/2)*i;Pc(r,o,t,e,s),n.push(t,o,o,e)}}const vv=()=>{const r=new fv,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},s=o=>{if(!Tn(o))return;const{minX:a,minY:l,maxX:h,maxY:u}=o.selector.geometry.bounds,c={minX:a,minY:l,maxX:h,maxY:u,target:o};r.insert(c),t.set(o.annotation,c)},n=o=>{if(!Tn(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)=>{const h=r.search({minX:o,minY:a,maxX:o,maxY:a}).map(u=>u.target).filter(u=>u.selector.type===Tt.RECTANGLE||wy(u.selector,o,a));return h.length>0?(h.sort((u,c)=>ua(u.selector)-ua(c.selector)),h):[]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(u=>u.target),insert:s,remove:n,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,u)=>{if(Tn(u)){const{minX:c,minY:d,maxX:f,maxY:p}=u.selector.geometry.bounds;return[...h,{minX:c,minY:d,maxX:f,maxY:p,target:u}]}else return h},[]);l.forEach(h=>t.set(h.target.annotation,h)),r.load(l)},size:()=>r.all().length,update:(o,a)=>{n(o),s(a)}}},Nc=r=>{const t=S_(),e=vv(),i=f_(t,r.userSelectAction,r.adapter),s=d_(t),n=P_();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)=>{const h=e.getAt(o,a,l);if(l)return h.map(u=>t.getAnnotation(u.annotation)).filter(Boolean).filter(l)[0];{const u=h[0];return u?t.getAnnotation(u.annotation):void 0}},getIntersecting:(o,a,l,h)=>e.getIntersecting(o,a,l,h).map(u=>t.getAnnotation(u.annotation))},selection:i,hover:s,viewport:n}},xv=r=>{const t=Nc(r);return{...t,store:C_(t.store)}},bv=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const s=r;t=document.createElement("canvas"),t.width=s.width,t.height=s.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(s,0,0,s.width,s.height)}let i=0;for(let s=1;s<10;s++)for(let n=1;n<10;n++){const o=Math.round(n*t.width/10),a=Math.round(s*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},Dc=r=>{const t=bv(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},Lc=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?Dc(r):e),Bc=(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}),Fc=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,kc=(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()},s=o=>{const a=o;a.key==="z"&&a.metaKey&&(a.shiftKey?r.redo():r.undo())},n=()=>{Fc?e.removeEventListener("keydown",s):e.removeEventListener("keydown",i)};return Fc?e.addEventListener("keydown",s):e.addEventListener("keydown",i),{destroy:n}},Ev=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=Bc(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Gu.EDIT,theme:"light"}),s=xv(i),{selection:n,store:o}=s,a=M_(o,i.initialHistory),l=O_(s,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 u=kc(a);let c=$_();Lc(e,h,i.theme);const d=new cv({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:s,style:i.style,user:c}});d.$on("click",I=>{const{originalEvent:A,annotation:w}=I.detail;w?n.userSelect(w.id,A):n.isEmpty()||n.clear()});const f=D_(s,a,i.adapter),p=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),u.destroy(),a.destroy()},_=()=>d.getDrawingTool(),y=()=>c,v=()=>d.isDrawingEnabled(),g=(I,A,w)=>yc(I,A,w),x=(I,A)=>fc(I,A),E=I=>{if(!Mn(I))throw`No drawing tool named ${I}`;d.$set({toolName:I})},R=I=>d.$set({drawingEnabled:I}),S=I=>{console.warn("Filter not implemented yet")},M=I=>d.$set({style:I}),P=I=>Lc(e,h,I),F=I=>{c=I,d.$set({user:I})},U=I=>d.$set({visible:I});return{...f,cancelDrawing:p,destroy:m,getDrawingTool:_,getUser:y,isDrawingEnabled:v,listDrawingTools:Rn,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:x,setDrawingEnabled:R,setDrawingTool:E,setFilter:S,setStyle:M,setTheme:P,setUser:F,setVisible:U,element:h,state:s}};function Qt(){}function Fa(r,t){for(const e in t)r[e]=t[e];return r}function Uc(r){return r()}function Gc(){return Object.create(null)}function Ye(r){r.forEach(Uc)}function Jt(r){return typeof r=="function"}function qt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function wv(r){return Object.keys(r).length===0}function Tv(r,...t){if(r==null){for(const i of t)i(void 0);return Qt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Nn(r,t,e){r.$$.on_destroy.push(Tv(t,e))}function Hc(r,t,e,i){if(r){const s=$c(r,t,e,i);return r[0](s)}}function $c(r,t,e,i){return r[1]&&i?Fa(e.ctx.slice(),r[1](i(t))):e.ctx}function Xc(r,t,e,i){if(r[2]&&i){const s=r[2](i(e));if(t.dirty===void 0)return s;if(typeof s=="object"){const n=[],o=Math.max(t.dirty.length,s.length);for(let a=0;a<o;a+=1)n[a]=t.dirty[a]|s[a];return n}return t.dirty|s}return t.dirty}function Vc(r,t,e,i,s,n){if(s){const o=$c(t,e,i,n);r.p(o,s)}}function zc(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 Yc(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}const ka=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Ct(r,t){r.appendChild(t)}function at(r,t,e){r.insertBefore(t,e||null)}function nt(r){r.parentNode&&r.parentNode.removeChild(r)}function Wr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function st(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Ua(r){return document.createTextNode(r)}function Le(){return Ua(" ")}function Ge(){return Ua("")}function Pt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function T(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function Av(r){return Array.from(r.childNodes)}function Sv(r,t){t=""+t,r.data!==t&&(r.data=t)}function jr(r,t,e){r.classList.toggle(t,!!e)}function Cv(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let ks;function Us(r){ks=r}function Ga(){if(!ks)throw new Error("Function called outside component initialization");return ks}function vi(r){Ga().$$.on_mount.push(r)}function Iv(r){Ga().$$.on_destroy.push(r)}function Ki(){const r=Ga();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=Cv(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function Me(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Zi=[],Dn=[];let Qi=[];const Wc=[],jc=Promise.resolve();let Ha=!1;function qc(){Ha||(Ha=!0,jc.then(Zc))}function Kc(){return qc(),jc}function $a(r){Qi.push(r)}const Xa=new Set;let Ji=0;function Zc(){if(Ji!==0)return;const r=ks;do{try{for(;Ji<Zi.length;){const t=Zi[Ji];Ji++,Us(t),Rv(t.$$)}}catch(t){throw Zi.length=0,Ji=0,t}for(Us(null),Zi.length=0,Ji=0;Dn.length;)Dn.pop()();for(let t=0;t<Qi.length;t+=1){const e=Qi[t];Xa.has(e)||(Xa.add(e),e())}Qi.length=0}while(Zi.length);for(;Wc.length;)Wc.pop()();Ha=!1,Xa.clear(),Us(r)}function Rv(r){if(r.fragment!==null){r.update(),Ye(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach($a)}}function Mv(r){const t=[],e=[];Qi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Qi=t}const Ln=new Set;let xi;function fe(){xi={r:0,c:[],p:xi}}function pe(){xi.r||Ye(xi.c),xi=xi.p}function K(r,t){r&&r.i&&(Ln.delete(r),r.i(t))}function lt(r,t,e,i){if(r&&r.o){if(Ln.has(r))return;Ln.add(r),xi.c.push(()=>{Ln.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Pe(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Ht(r){r&&r.c()}function Ft(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),$a(()=>{const n=r.$$.on_mount.map(Uc).filter(Jt);r.$$.on_destroy?r.$$.on_destroy.push(...n):Ye(n),r.$$.on_mount=[]}),s.forEach($a)}function kt(r,t){const e=r.$$;e.fragment!==null&&(Mv(e.after_update),Ye(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Pv(r,t){r.$$.dirty[0]===-1&&(Zi.push(r),qc(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ie(r,t,e,i,s,n,o=null,a=[-1]){const l=ks;Us(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Qt,not_equal:s,bound:Gc(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Gc(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let u=!1;if(h.ctx=e?e(r,t.props||{},(c,d,...f)=>{const p=f.length?f[0]:d;return h.ctx&&s(h.ctx[c],h.ctx[c]=p)&&(!h.skip_bound&&h.bound[c]&&h.bound[c](p),u&&Pv(r,c)),d}):[],h.update(),u=!0,Ye(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=Av(t.target);h.fragment&&h.fragment.l(c),c.forEach(nt)}else h.fragment&&h.fragment.c();t.intro&&K(r.$$.fragment),Ft(r,t.target,t.anchor),Zc()}Us(l)}class se{constructor(){$t(this,"$$");$t(this,"$$set")}$destroy(){kt(this,1),this.$destroy=Qt}$on(t,e){if(!Jt(e))return Qt;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const s=i.indexOf(e);s!==-1&&i.splice(s,1)}}$set(t){this.$$set&&!wv(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Ov="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ov);var qr=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGLON="MULTIPOLYGON",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(qr||{}),Gs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Va(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 s=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return r[i]}})}),e}var Qc={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,u=a.y-l.y;return h*h+u*u}function e(a,l,h){var u=l.x,c=l.y,d=h.x-u,f=h.y-c;if(d!==0||f!==0){var p=((a.x-u)*d+(a.y-c)*f)/(d*d+f*f);p>1?(u=h.x,c=h.y):p>0&&(u+=d*p,c+=f*p)}return d=a.x-u,f=a.y-c,d*d+f*f}function i(a,l){for(var h=a[0],u=[h],c,d=1,f=a.length;d<f;d++)c=a[d],t(c,h)>l&&(u.push(c),h=c);return h!==c&&u.push(c),u}function s(a,l,h,u,c){for(var d=u,f,p=l+1;p<h;p++){var m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}d>u&&(f-l>1&&s(a,l,f,u,c),c.push(a[f]),h-f>1&&s(a,f,h,u,c))}function n(a,l){var h=a.length-1,u=[a[0]];return s(a,0,h,l,u),u.push(a[h]),u}function o(a,l,h){if(a.length<=2)return a;var u=l!==void 0?l*l:1;return a=h?a:i(a,u),a=n(a,u),a}r.exports=o,r.exports.default=o})()})(Qc);var Dv=Qc.exports;const Lv=Va(Dv),Bn=(r,t)=>t,dr=r=>{let t=1/0,e=1/0,i=-1/0,s=-1/0;return r.forEach(([n,o])=>{t=Math.min(t,n),e=Math.min(e,o),i=Math.max(i,n),s=Math.max(s,o)}),{minX:t,minY:e,maxX:i,maxY:s}},za=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)},Ya=(r,t,e)=>{let i=!1;for(let s=0,n=r.length-1;s<r.length;n=s++){const o=r[s][0],a=r[s][1],l=r[n][0],h=r[n][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},Bv=(r,t=!0)=>{let e="M ";return r.forEach(([i,s],n)=>{n===0?e+=`${i},${s}`:e+=` L ${i},${s}`}),t&&(e+=" Z"),e},Jc=(r,t=1)=>{const e=r.map(([i,s])=>({x:i,y:s}));return Lv(e,t,!0).map(i=>[i.x,i.y])},Fv={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:s,rx:n,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),u=t-i,c=e-s,d=l*u+h*c,f=h*u-l*c;return d*d/(n*n)+f*f/(o*o)<=1}};Bn(qr.ELLIPSE,Fv);const kv={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[s,...n]=i.rings,o=za(s.points),a=n.reduce((l,h)=>l+za(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const s of i){const[n,...o]=s.rings;if(Ya(n.points,t,e)){let a=!1;for(const l of o)if(Ya(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Fn=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return dr(t)},ts=r=>r.rings.map(e=>Bv(e.points)).join(" "),Uv=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,s)=>[...i,...s.points],[])],[]),Gv=(r,t=1)=>{const e=r.geometry.polygons.map(s=>{const n=s.rings.map(a=>{const l=Jc(a.points,t);return{...a,points:l}}),o=dr(n[0].points);return{...s,rings:n,bounds:o}}),i=Fn(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Bn(qr.MULTIPOLYGLON,kv);const Hv={area:r=>{const t=r.geometry.points;return za(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Ya(i,t,e)}},$v=(r,t=1)=>{const e=Jc(r.geometry.points,t),i=dr(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Bn(qr.POLYGON,Hv);const Xv={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};Bn(qr.RECTANGLE,Xv);const ne=" ";function Vv(r){let t="";Array.isArray(r)||(r=[r]);for(let e=0;e<r.length;e++){const i=r[e];if(i.type===$.CLOSE_PATH)t+="z";else if(i.type===$.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===$.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===$.MOVE_TO)t+=(i.relative?"m":"M")+i.x+ne+i.y;else if(i.type===$.LINE_TO)t+=(i.relative?"l":"L")+i.x+ne+i.y;else if(i.type===$.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+ne+i.y1+ne+i.x2+ne+i.y2+ne+i.x+ne+i.y;else if(i.type===$.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+ne+i.y2+ne+i.x+ne+i.y;else if(i.type===$.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+ne+i.y1+ne+i.x+ne+i.y;else if(i.type===$.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+ne+i.y;else if(i.type===$.ARC)t+=(i.relative?"a":"A")+i.rX+ne+i.rY+ne+i.xRot+ne+ +i.lArcFlag+ne+ +i.sweepFlag+ne+i.x+ne+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${e}.`)}return t}function Wa([r,t],e){return[r*Math.cos(e)-t*Math.sin(e),r*Math.sin(e)+t*Math.cos(e)]}function tr(...r){for(let t=0;t<r.length;t++)if(typeof r[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof r[t]} == typeof ${r[t]}`);return!0}const Kr=Math.PI;function ja(r,t,e){r.lArcFlag=r.lArcFlag===0?0:1,r.sweepFlag=r.sweepFlag===0?0:1;let{rX:i,rY:s}=r;const{x:n,y:o}=r;if(Math.abs(i)<1e-10||Math.abs(s)<1e-10){r.rX=0,r.rY=0,r.cX=(t+n)/2,r.cY=(e+o)/2,r.phi1=0,r.phi2=0;return}i=Math.abs(r.rX),s=Math.abs(r.rY);const a=r.xRot/180*Kr,[l,h]=Wa([(t-n)/2,(e-o)/2],-a),u=Math.pow(l,2)/Math.pow(i,2)+Math.pow(h,2)/Math.pow(s,2);1<u&&(i*=Math.sqrt(u),s*=Math.sqrt(u)),r.rX=i,r.rY=s;const c=Math.pow(i,2)*Math.pow(h,2)+Math.pow(s,2)*Math.pow(l,2),d=(r.lArcFlag!==r.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(s,2)-c)/c)),f=i*h/s*d,p=-s*l/i*d,m=Wa([f,p],a);r.cX=m[0]+(t+n)/2,r.cY=m[1]+(e+o)/2,r.phi1=Math.atan2((h-p)/s,(l-f)/i),r.phi2=Math.atan2((-h-p)/s,(-l-f)/i),r.sweepFlag===0&&r.phi2>r.phi1&&(r.phi2-=2*Kr),r.sweepFlag===1&&r.phi2<r.phi1&&(r.phi2+=2*Kr),r.phi1*=180/Kr,r.phi2*=180/Kr}function td(r,t,e){tr(r,t,e);const i=r*r+t*t-e*e;if(0>i)return[];if(i===0)return[[r*e/(r*r+t*t),t*e/(r*r+t*t)]];const s=Math.sqrt(i);return[[(r*e+t*s)/(r*r+t*t),(t*e-r*s)/(r*r+t*t)],[(r*e-t*s)/(r*r+t*t),(t*e+r*s)/(r*r+t*t)]]}const bi=Math.PI/180;function ed(r,t,e){return(1-e)*r+e*t}function rd(r,t,e,i){return r+Math.cos(i/180*Kr)*t+Math.sin(i/180*Kr)*e}function id(r,t,e,i){const n=t-r,o=e-t,a=i-e,l=3*n+3*a-6*o,h=(o-n)*6,u=3*n;return Math.abs(l)<1e-6?Math.abs(h)<1e-6?[]:[-u/h]:zv(h/l,u/l,1e-6)}function sd(r,t,e,i,s){const n=1-s,o=n*n*n,a=3*n*n*s,l=3*n*s*s,h=s*s*s;return r*o+t*a+e*l+i*h}function zv(r,t,e=1e-6){const i=r*r/4-t;if(i<-e)return[];if(i<=e)return[-r/2];const s=Math.sqrt(i);return[-(r/2)-s,-(r/2)+s]}function Yv(r,t,e){r.cX||ja(r,t,e);const i=r.xRot/180*Kr;if(Math.abs(r.rX)<1e-10||Math.abs(r.rY)<1e-10)return[{relative:r.relative,type:$.CURVE_TO,x1:t+(r.x-t)/3,y1:e+(r.y-e)/3,x2:t+2*(r.x-t)/3,y2:e+2*(r.y-e)/3,x:r.x,y:r.y}];const s=Math.min(r.phi1,r.phi2),n=Math.max(r.phi1,r.phi2),o=n-s,a=Math.ceil(o/90),l=new Array(a);let h=t,u=e;const c=(d,f)=>{const[p,m]=Wa([d*r.rX,f*r.rY],i);return[r.cX+p,r.cY+m]};for(let d=0;d<a;d++){const f=ed(r.phi1,r.phi2,d/a),p=ed(r.phi1,r.phi2,(d+1)/a),m=p-f,_=4/3*Math.tan(m*bi/4),y=Math.cos(f*bi)-_*Math.sin(f*bi),v=Math.sin(f*bi)+_*Math.cos(f*bi),g=Math.cos(p*bi),x=Math.sin(p*bi),E=g+_*x,R=x-_*g,S=c(y,v),M=c(E,R),P=c(g,x),F={relative:r.relative,type:$.CURVE_TO,x:P[0],y:P[1],x1:S[0],y1:S[1],x2:M[0],y2:M[1]};r.relative&&(F.x1-=h,F.y1-=u,F.x2-=h,F.y2-=u,F.x-=h,F.y-=u),h=P[0],u=P[1],l[d]=F}return l}function qa(r,t,e){const i=t[0]-r[0],s=t[1]-r[1],n=e[0]-r[0],o=e[1]-r[1],a=i*o-s*n;if(!(Math.abs(a)<1e-10))return!1;const h=i*n+s*o,u=i*i+s*s,c=n*n+o*o;return 0<=h&&h<=c&&u<=c}function Wv(r,t=!0){if(r.length<2)return r;const e=oe.INFO((n,o,a)=>({...n,x:n.x??o,y:n.y??a,relative:n.relative??!1})),i=[];let s=[];for(const n of r){const o=e(n);o.type===$.MOVE_TO&&s.length>0&&(t?i.push(...kn(s)):i.unshift(...kn(s)),s=[]),s.push(o)}return s.length>0&&(t?i.push(...kn(s)):i.unshift(...kn(s))),i}function kn(r){var s;const t=((s=r[r.length-1])==null?void 0:s.type)===$.CLOSE_PATH,e=t?r.length-2:r.length-1,i=[{type:$.MOVE_TO,relative:!1,x:r[e].x,y:r[e].y}];for(let n=e;n>0;n--){const o=r[n],a=r[n-1];if(o.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(o.type){case $.HORIZ_LINE_TO:i.push({type:$.HORIZ_LINE_TO,relative:!1,x:a.x});break;case $.VERT_LINE_TO:i.push({type:$.VERT_LINE_TO,relative:!1,y:a.y});break;case $.LINE_TO:case $.MOVE_TO:i.push({type:$.LINE_TO,relative:!1,x:a.x,y:a.y});break;case $.CURVE_TO:i.push({type:$.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:o.x2,y1:o.y2,x2:o.x1,y2:o.y1});break;case $.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case $.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case $.ARC:throw new Error("Unsupported command: A (arc)");case $.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:$.CLOSE_PATH}),i}function jv(r=1e13){tr(r);function t(e){return Math.round(e*r)/r}return function(i){return"x1"in i&&typeof i.x1<"u"&&(i.x1=t(i.x1)),"y1"in i&&typeof i.y1<"u"&&(i.y1=t(i.y1)),"x2"in i&&typeof i.x2<"u"&&(i.x2=t(i.x2)),"y2"in i&&typeof i.y2<"u"&&(i.y2=t(i.y2)),"x"in i&&typeof i.x<"u"&&(i.x=t(i.x)),"y"in i&&typeof i.y<"u"&&(i.y=t(i.y)),"rX"in i&&typeof i.rX<"u"&&(i.rX=t(i.rX)),"rY"in i&&typeof i.rY<"u"&&(i.rY=t(i.rY)),i}}function nd(){return er((r,t,e)=>(r.relative&&(typeof r.x1<"u"&&(r.x1+=t),typeof r.y1<"u"&&(r.y1+=e),typeof r.x2<"u"&&(r.x2+=t),typeof r.y2<"u"&&(r.y2+=e),typeof r.x<"u"&&(r.x+=t),typeof r.y<"u"&&(r.y+=e),r.relative=!1),r))}function qv(){return er((r,t,e)=>(r.relative||(typeof r.x1<"u"&&(r.x1-=t),typeof r.y1<"u"&&(r.y1-=e),typeof r.x2<"u"&&(r.x2-=t),typeof r.y2<"u"&&(r.y2-=e),typeof r.x<"u"&&(r.x-=t),typeof r.y<"u"&&(r.y-=e),r.relative=!0),r))}function Kv(r=!0,t=!0,e=!0,i=!0){return er((s,n,o,a,l)=>{if(isNaN(a)&&!(s.type&$.MOVE_TO))throw new Error("path must start with moveto");if(t&&s.type&$.HORIZ_LINE_TO&&(s.type=$.LINE_TO,s.y=s.relative?0:o),e&&s.type&$.VERT_LINE_TO&&(s.type=$.LINE_TO,s.x=s.relative?0:n),r&&s.type&$.CLOSE_PATH&&(s.type=$.LINE_TO,s.x=s.relative?a-n:a,s.y=s.relative?l-o:l),s.type&$.ARC&&(s.rX===0||s.rY===0)&&(s.type=$.LINE_TO,delete s.rX,delete s.rY,delete s.xRot,delete s.lArcFlag,delete s.sweepFlag),i&&s.type&$.QUAD_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x,o+s.y]:[s.x,s.y];qa(h,u,c)&&(s.type=$.LINE_TO,delete s.x1,delete s.y1)}if(i&&s.type&$.CURVE_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x2,o+s.y2]:[s.x2,s.y2],d=s.relative?[n+s.x,o+s.y]:[s.x,s.y];qa(h,u,d)&&qa(h,c,d)&&(s.type=$.LINE_TO,delete s.x1,delete s.y1,delete s.x2,delete s.y2)}return s})}function od(){let r=NaN,t=NaN,e=NaN,i=NaN;return er((s,n,o)=>(s.type&$.SMOOTH_CURVE_TO&&(s.type=$.CURVE_TO,r=isNaN(r)?n:r,t=isNaN(t)?o:t,s.x1=s.relative?n-r:2*n-r,s.y1=s.relative?o-t:2*o-t),s.type&$.CURVE_TO?(r=s.relative?n+s.x2:s.x2,t=s.relative?o+s.y2:s.y2):(r=NaN,t=NaN),s.type&$.SMOOTH_QUAD_TO&&(s.type=$.QUAD_TO,e=isNaN(e)?n:e,i=isNaN(i)?o:i,s.x1=s.relative?n-e:2*n-e,s.y1=s.relative?o-i:2*o-i),s.type&$.QUAD_TO?(e=s.relative?n+s.x1:s.x1,i=s.relative?o+s.y1:s.y1):(e=NaN,i=NaN),s))}function ad(){let r=NaN,t=NaN;return er((e,i,s)=>{if(e.type&$.SMOOTH_QUAD_TO&&(e.type=$.QUAD_TO,r=isNaN(r)?i:r,t=isNaN(t)?s:t,e.x1=e.relative?i-r:2*i-r,e.y1=e.relative?s-t:2*s-t),e.type&$.QUAD_TO){r=e.relative?i+e.x1:e.x1,t=e.relative?s+e.y1:e.y1;const n=e.x1,o=e.y1;e.type=$.CURVE_TO,e.x1=((e.relative?0:i)+n*2)/3,e.y1=((e.relative?0:s)+o*2)/3,e.x2=(e.x+n*2)/3,e.y2=(e.y+o*2)/3}else r=NaN,t=NaN;return e})}function er(r){let t=0,e=0,i=NaN,s=NaN;return function(o){if(isNaN(i)&&!(o.type&$.MOVE_TO))throw new Error("path must start with moveto");const a=r(o,t,e,i,s);return o.type&$.CLOSE_PATH&&(t=i,e=s),"x"in o&&typeof o.x<"u"&&(t=o.relative?t+o.x:o.x),"y"in o&&typeof o.y<"u"&&(e=o.relative?e+o.y:o.y),o.type&$.MOVE_TO&&(i=t,s=e),a}}function Zv(r=0){tr(r);let t=NaN,e=NaN,i=NaN,s=NaN;return er((n,o,a,l,h)=>{const u=Math.abs;let c=!1,d=0,f=0;if(n.type&$.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:o-t,f=isNaN(e)?0:a-e),n.type&($.CURVE_TO|$.SMOOTH_CURVE_TO)?(t=n.relative?o+n.x2:n.x2,e=n.relative?a+n.y2:n.y2):(t=NaN,e=NaN),n.type&$.SMOOTH_QUAD_TO?(i=isNaN(i)?o:2*o-i,s=isNaN(s)?a:2*a-s):n.type&$.QUAD_TO?(i=n.relative?o+n.x1:n.x1,s=n.relative?a+n.y1:n.y2):(i=NaN,s=NaN),n.type&$.LINE_COMMANDS||n.type&$.ARC&&(n.rX===0||n.rY===0||!n.lArcFlag)||n.type&$.CURVE_TO||n.type&$.SMOOTH_CURVE_TO||n.type&$.QUAD_TO||n.type&$.SMOOTH_QUAD_TO){const p=typeof n.x>"u"?0:n.relative?n.x:n.x-o,m=typeof n.y>"u"?0:n.relative?n.y:n.y-a;d=isNaN(i)?typeof n.x1>"u"?d:n.relative?n.x:n.x1-o:i-o,f=isNaN(s)?typeof n.y1>"u"?f:n.relative?n.y:n.y1-a:s-a;const _=typeof n.x2>"u"?0:n.relative?n.x:n.x2-o,y=typeof n.y2>"u"?0:n.relative?n.y:n.y2-a;u(p)<=r&&u(m)<=r&&u(d)<=r&&u(f)<=r&&u(_)<=r&&u(y)<=r&&(c=!0)}return n.type&$.CLOSE_PATH&&u(o-l)<=r&&u(a-h)<=r&&(c=!0),c?[]:n})}function Zr(r,t,e,i,s,n){return tr(r,t,e,i,s,n),er((o,a,l,h)=>{const u=o.x1,c=o.x2,d=o.relative&&!isNaN(h),f=typeof o.x<"u"?o.x:d?0:a,p=typeof o.y<"u"?o.y:d?0:l;o.type&$.HORIZ_LINE_TO&&t!==0&&(o.type=$.LINE_TO,o.y=o.relative?0:l),o.type&$.VERT_LINE_TO&&e!==0&&(o.type=$.LINE_TO,o.x=o.relative?0:a),typeof o.x<"u"&&(o.x=o.x*r+p*e+(d?0:s)),typeof o.y<"u"&&(o.y=f*t+o.y*i+(d?0:n)),typeof o.x1<"u"&&(o.x1=o.x1*r+o.y1*e+(d?0:s)),typeof o.y1<"u"&&(o.y1=u*t+o.y1*i+(d?0:n)),typeof o.x2<"u"&&(o.x2=o.x2*r+o.y2*e+(d?0:s)),typeof o.y2<"u"&&(o.y2=c*t+o.y2*i+(d?0:n));function m(y){return y*y}const _=r*i-t*e;if(typeof o.xRot<"u"&&(r!==1||t!==0||e!==0||i!==1))if(_===0)delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag,o.type=$.LINE_TO;else{const y=o.xRot*Math.PI/180,v=Math.sin(y),g=Math.cos(y),x=1/m(o.rX),E=1/m(o.rY),R=m(g)*x+m(v)*E,S=2*v*g*(x-E),M=m(v)*x+m(g)*E,P=R*i*i-S*t*i+M*t*t,F=S*(r*i+t*e)-2*(R*e*i+M*r*t),U=R*e*e-S*r*e+M*r*r,I=(Math.atan2(F,P-U)+Math.PI)%Math.PI/2,A=Math.sin(I),w=Math.cos(I);o.rX=Math.abs(_)/Math.sqrt(P*m(w)+F*A*w+U*m(A)),o.rY=Math.abs(_)/Math.sqrt(P*m(A)-F*A*w+U*m(w)),o.xRot=I*180/Math.PI}return typeof o.sweepFlag<"u"&&0>_&&(o.sweepFlag=+!o.sweepFlag),o})}function Qv(r,t=0,e=0){tr(r,t,e);const i=Math.sin(r),s=Math.cos(r);return Zr(s,i,-i,s,t-t*s+e*i,e-t*i-e*s)}function Jv(r,t=0){return tr(r,t),Zr(1,0,0,1,r,t)}function t1(r,t=r){return tr(r,t),Zr(r,0,0,t,0,0)}function e1(r){return tr(r),Zr(1,0,Math.tan(r),1,0,0)}function r1(r){return tr(r),Zr(1,Math.tan(r),0,1,0,0)}function i1(r=0){return tr(r),Zr(-1,0,0,1,r,0)}function s1(r=0){return tr(r),Zr(1,0,0,-1,0,r)}function n1(){return er((r,t,e)=>$.ARC===r.type?Yv(r,r.relative?0:t,r.relative?0:e):r)}function o1(){return er((r,t,e)=>(r.relative&&(t=0,e=0),$.ARC===r.type&&ja(r,t,e),r))}function ld(){return r=>({...r})}function a1(){const r=ld(),t=nd(),e=ad(),i=od(),s=er((n,o,a)=>{const l=i(e(t(r(n))));function h(c){c>s.maxX&&(s.maxX=c),c<s.minX&&(s.minX=c)}function u(c){c>s.maxY&&(s.maxY=c),c<s.minY&&(s.minY=c)}if(l.type&$.DRAWING_COMMANDS&&(h(o),u(a)),l.type&$.HORIZ_LINE_TO&&h(l.x),l.type&$.VERT_LINE_TO&&u(l.y),l.type&$.LINE_TO&&(h(l.x),u(l.y)),l.type&$.CURVE_TO){h(l.x),u(l.y);const c=id(o,l.x1,l.x2,l.x);for(const f of c)0<f&&1>f&&h(sd(o,l.x1,l.x2,l.x,f));const d=id(a,l.y1,l.y2,l.y);for(const f of d)0<f&&1>f&&u(sd(a,l.y1,l.y2,l.y,f))}if(l.type&$.ARC){h(l.x),u(l.y),ja(l,o,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,f=Math.sin(c)*l.rX,p=-Math.sin(c)*l.rY,m=Math.cos(c)*l.rY,[_,y]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],v=([E,R])=>{const M=Math.atan2(R,E)*180/Math.PI;return M<_?M+360:M},g=td(p,-d,0).map(v);for(const E of g)E>_&&E<y&&h(rd(l.cX,d,p,E));const x=td(m,-f,0).map(v);for(const E of x)E>_&&E<y&&u(rd(l.cY,f,m,E))}return n});return s.minX=1/0,s.maxX=-1/0,s.minY=1/0,s.maxY=-1/0,s}const oe={ROUND:jv,TO_ABS:nd,TO_REL:qv,NORMALIZE_HVZ:Kv,NORMALIZE_ST:od,QT_TO_C:ad,INFO:er,SANITIZE:Zv,MATRIX:Zr,ROTATE:Qv,TRANSLATE:Jv,SCALE:t1,SKEW_X:e1,SKEW_Y:r1,X_AXIS_SYMMETRY:i1,Y_AXIS_SYMMETRY:s1,A_TO_C:n1,ANNOTATE_ARCS:o1,CLONE:ld,CALCULATE_BOUNDS:a1,REVERSE_PATH:Wv};class hd{round(t){return this.transform(oe.ROUND(t))}toAbs(){return this.transform(oe.TO_ABS())}toRel(){return this.transform(oe.TO_REL())}normalizeHVZ(t,e,i){return this.transform(oe.NORMALIZE_HVZ(t,e,i))}normalizeST(){return this.transform(oe.NORMALIZE_ST())}qtToC(){return this.transform(oe.QT_TO_C())}aToC(){return this.transform(oe.A_TO_C())}sanitize(t){return this.transform(oe.SANITIZE(t))}translate(t,e){return this.transform(oe.TRANSLATE(t,e))}scale(t,e){return this.transform(oe.SCALE(t,e))}rotate(t,e,i){return this.transform(oe.ROTATE(t,e,i))}matrix(t,e,i,s,n,o){return this.transform(oe.MATRIX(t,e,i,s,n,o))}skewX(t){return this.transform(oe.SKEW_X(t))}skewY(t){return this.transform(oe.SKEW_Y(t))}xSymmetry(t){return this.transform(oe.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(oe.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(oe.ANNOTATE_ARCS())}}const l1=r=>r===" "||r===" "||r==="\r"||r===`
|
|
2
|
+
`,Bu=r=>48<=r.charCodeAt(0)&&r.charCodeAt(0)<=57;class Qy extends Lu{constructor(){super(),Xt(this,"curNumber",""),Xt(this,"curCommandType",-1),Xt(this,"curCommandRelative",!1),Xt(this,"canParseCommandOrComma",!0),Xt(this,"curNumberHasExp",!1),Xt(this,"curNumberHasExpDigits",!1),Xt(this,"curNumberHasDecimal",!1),Xt(this,"curArgs",[])}finish(t=[]){if(this.parse(" ",t),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return t}parse(t,e=[]){const i=s=>{e.push(s),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let s=0;s<t.length;s++){const n=t[s],o=this.curCommandType===G.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),a=Bu(n)&&(this.curNumber==="0"&&n==="0"||o);if(Bu(n)&&!a){this.curNumber+=n,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(n==="e"||n==="E"){this.curNumber+=n,this.curNumberHasExp=!0;continue}if((n==="-"||n==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=n;continue}if(n==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!o){this.curNumber+=n,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const l=Number(this.curNumber);if(isNaN(l))throw new SyntaxError(`Invalid number ending at ${s}`);if(this.curCommandType===G.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>l)throw new SyntaxError(`Expected positive number, got "${l}" at index "${s}"`)}else if((this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber!=="0"&&this.curNumber!=="1")throw new SyntaxError(`Expected a flag, got "${this.curNumber}" at index "${s}"`)}this.curArgs.push(l),this.curArgs.length===Jy[this.curCommandType]&&(G.HORIZ_LINE_TO===this.curCommandType?i({type:G.HORIZ_LINE_TO,relative:this.curCommandRelative,x:l}):G.VERT_LINE_TO===this.curCommandType?i({type:G.VERT_LINE_TO,relative:this.curCommandRelative,y:l}):this.curCommandType===G.MOVE_TO||this.curCommandType===G.LINE_TO||this.curCommandType===G.SMOOTH_QUAD_TO?(i({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),G.MOVE_TO===this.curCommandType&&(this.curCommandType=G.LINE_TO)):this.curCommandType===G.CURVE_TO?i({type:G.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===G.SMOOTH_CURVE_TO?i({type:G.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===G.QUAD_TO?i({type:G.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===G.ARC&&i({type:G.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!Zy(n)){if(n===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(n==="+"||n==="-"||n==="."){this.curNumber=n,this.curNumberHasDecimal=n===".";continue}if(a){this.curNumber=n,this.curNumberHasDecimal=!1;continue}if(this.curArgs.length!==0)throw new SyntaxError(`Unterminated command at index ${s}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${n}" at index ${s}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,n==="z"||n==="Z"){e.push({type:G.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(n==="h"||n==="H")this.curCommandType=G.HORIZ_LINE_TO,this.curCommandRelative=n==="h";else if(n==="v"||n==="V")this.curCommandType=G.VERT_LINE_TO,this.curCommandRelative=n==="v";else if(n==="m"||n==="M")this.curCommandType=G.MOVE_TO,this.curCommandRelative=n==="m";else if(n==="l"||n==="L")this.curCommandType=G.LINE_TO,this.curCommandRelative=n==="l";else if(n==="c"||n==="C")this.curCommandType=G.CURVE_TO,this.curCommandRelative=n==="c";else if(n==="s"||n==="S")this.curCommandType=G.SMOOTH_CURVE_TO,this.curCommandRelative=n==="s";else if(n==="q"||n==="Q")this.curCommandType=G.QUAD_TO,this.curCommandRelative=n==="q";else if(n==="t"||n==="T")this.curCommandType=G.SMOOTH_QUAD_TO,this.curCommandRelative=n==="t";else if(n==="a"||n==="A")this.curCommandType=G.ARC,this.curCommandRelative=n==="a";else throw new SyntaxError(`Unexpected character "${n}" at index ${s}.`)}}return e}transform(t){return Object.create(this,{parse:{value(e,i=[]){const s=Object.getPrototypeOf(this).parse.call(this,e);for(const n of s){const o=t(n);Array.isArray(o)?i.push(...o):i.push(o)}return i}}})}}const Gt=class ru extends Lu{constructor(t){super(),Xt(this,"commands"),typeof t=="string"?this.commands=ru.parse(t):this.commands=t}encode(){return ru.encode(this.commands)}getBounds(){const t=re.CALCULATE_BOUNDS();return this.transform(t),t}transform(t){const e=[];for(const i of this.commands){const s=t(i);Array.isArray(s)?e.push(...s):e.push(s)}return this.commands=e,this}reverse(t=!0){return this.commands=re.REVERSE_PATH(this.commands,t),this}static encode(t){return Ny(t)}static parse(t){const e=new Qy,i=[];return e.parse(t,i),e.finish(i),i}};Xt(Gt,"CLOSE_PATH",1),Xt(Gt,"MOVE_TO",2),Xt(Gt,"HORIZ_LINE_TO",4),Xt(Gt,"VERT_LINE_TO",8),Xt(Gt,"LINE_TO",16),Xt(Gt,"CURVE_TO",32),Xt(Gt,"SMOOTH_CURVE_TO",64),Xt(Gt,"QUAD_TO",128),Xt(Gt,"SMOOTH_QUAD_TO",256),Xt(Gt,"ARC",512),Xt(Gt,"LINE_COMMANDS",Gt.LINE_TO|Gt.HORIZ_LINE_TO|Gt.VERT_LINE_TO),Xt(Gt,"DRAWING_COMMANDS",Gt.HORIZ_LINE_TO|Gt.VERT_LINE_TO|Gt.LINE_TO|Gt.CURVE_TO|Gt.SMOOTH_CURVE_TO|Gt.QUAD_TO|Gt.SMOOTH_QUAD_TO|Gt.ARC);let G=Gt;const Jy={[G.MOVE_TO]:2,[G.LINE_TO]:2,[G.HORIZ_LINE_TO]:1,[G.VERT_LINE_TO]:1,[G.CLOSE_PATH]:0,[G.QUAD_TO]:4,[G.SMOOTH_QUAD_TO]:2,[G.CURVE_TO]:6,[G.SMOOTH_CURVE_TO]:4,[G.ARC]:7},t_=r=>{const t=new G(r).toAbs().commands,e=[];let i=[],s=null;for(const n of t)switch(n.type){case G.MOVE_TO:i.length>0&&(e.push({points:i}),i=[]),s=[n.x,n.y],i.push(s);break;case G.LINE_TO:i.push([n.x,n.y]);break;case G.HORIZ_LINE_TO:const o=i[i.length-1][1];i.push([n.x,o]);break;case G.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,n.y]);break;case G.CURVE_TO:case G.SMOOTH_CURVE_TO:case G.QUAD_TO:case G.SMOOTH_QUAD_TO:case G.ARC:i.push([n.x,n.y]);break}if(i.length>2&&e.push({points:i}),e.length>0){const n=Ue(e[0].points);return{rings:e,bounds:n}}},e_=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],s=i.split(" ").map(n=>n.split(",").map(parseFloat));return{type:Tt.POLYGON,geometry:{points:s,bounds:Ue(s)}}},r_=r=>{const t=Au(r),e=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),s=parseFloat(t.getAttribute("rx")),n=parseFloat(t.getAttribute("ry")),o={minX:e-s,minY:i-n,maxX:e+s,maxY:i+n};return{type:Tt.ELLIPSE,geometry:{cx:e,cy:i,rx:s,ry:n,bounds:o}}},i_=r=>{const t=Au(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(n=>n.getAttribute("d")||"").map(n=>t_(n)).filter(Boolean),i=e.reduce((n,o)=>[...n,...o.rings[0].points],[]),s=Ue(i);return e.length===1&&e[0].rings.length===1?{type:Tt.POLYGON,geometry:{points:i,bounds:s}}:{type:Tt.MULTIPOLYGLON,geometry:{polygons:e,bounds:s}}},s_=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return e_(t);if(t.includes("<path "))return i_(t);if(t.includes("<ellipse "))return r_(t);throw"Unsupported SVG shape: "+t},n_=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${Ze(t)}" />`).join("")}</g>`,o_=r=>{let t;if(r.type===Tt.POLYGON){const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(s=>s.join(",")).join(" ")}" /></svg>`}else if(r.type===Tt.ELLIPSE){const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`}else if(r.type===Tt.MULTIPOLYGLON){const e=r.geometry;t=`<svg>${n_(e)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},Ee=[];for(let r=0;r<256;++r)Ee.push((r+256).toString(16).slice(1));function a_(r,t=0){return(Ee[r[t+0]]+Ee[r[t+1]]+Ee[r[t+2]]+Ee[r[t+3]]+"-"+Ee[r[t+4]]+Ee[r[t+5]]+"-"+Ee[r[t+6]]+Ee[r[t+7]]+"-"+Ee[r[t+8]]+Ee[r[t+9]]+"-"+Ee[r[t+10]]+Ee[r[t+11]]+Ee[r[t+12]]+Ee[r[t+13]]+Ee[r[t+14]]+Ee[r[t+15]]).toLowerCase()}let ya;const l_=new Uint8Array(16);function h_(){if(!ya){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ya=crypto.getRandomValues.bind(crypto)}return ya(l_)}const u_=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Fu={randomUUID:u_};function ku(r,t,e){var i;if(Fu.randomUUID&&!r)return Fu.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??h_();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,a_(s)}var Uu=Object.prototype.hasOwnProperty;function Yr(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--&&Yr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Uu.call(r,e)&&++i&&!Uu.call(t,e)||!(e in t)||!Yr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}function _a(){}function c_(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const zi=[];function va(r,t=_a){let e;const i=new Set;function s(a){if(c_(r,a)&&(r=a,e)){const l=!zi.length;for(const h of i)h[1](),zi.push(h,r);if(l){for(let h=0;h<zi.length;h+=2)zi[h][0](zi[h+1]);zi.length=0}}}function n(a){s(a(r))}function o(a,l=_a){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||_a),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const d_=r=>{const{subscribe:t,set:e}=va();let i;return t(s=>i=s),r.observe(({changes:s})=>{if(i){(s.deleted||[]).some(o=>o.id===i)&&e(void 0);const n=(s.updated||[]).find(({oldValue:o})=>o.id===i);n&&e(n.newValue.id)}}),{get current(){return i},subscribe:t,set:e}};var Gu=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(Gu||{});const Sn={selected:[]},f_=(r,t,e)=>{const{subscribe:i,set:s}=va(Sn);let n=t,o=Sn;i(m=>o=m);const a=()=>{Yr(o,Sn)||s(Sn)},l=()=>{var m;return((m=o.selected)==null?void 0:m.length)===0},h=m=>{if(l())return!1;const _=typeof m=="string"?m:m.id;return o.selected.some(y=>y.id===_)},u=(m,_)=>{let y;if(Array.isArray(m)){if(y=m.map(g=>r.getAnnotation(g)).filter(Boolean),y.length<m.length){console.warn("Invalid selection: "+m.filter(g=>!y.some(x=>x.id===g)));return}}else{const g=r.getAnnotation(m);if(!g){console.warn("Invalid selection: "+m);return}y=[g]}const v=y.reduce((g,x)=>{const E=xa(x,n,e);return E==="EDIT"?[...g,{id:x.id,editable:!0}]:E==="SELECT"?[...g,{id:x.id}]:g},[]);s({selected:v,event:_})},c=(m,_)=>{const y=Array.isArray(m)?m:[m],v=y.map(g=>r.getAnnotation(g)).filter(g=>!!g);s({selected:v.map(g=>{const x=_===void 0?xa(g,n,e)==="EDIT":_;return{id:g.id,editable:x}})}),v.length!==y.length&&console.warn("Invalid selection",m)},d=m=>{if(l())return!1;const{selected:_}=o;_.some(({id:y})=>m.includes(y))&&s({selected:_.filter(({id:y})=>!m.includes(y))})},f=m=>{n=m,c(o.selected.map(({id:_})=>_))},p=m=>xa(m,n,e);return r.observe(({changes:m})=>d((m.deleted||[]).map(_=>_.id))),{get event(){return o?o.event:null},get selected(){return o?[...o.selected]:null},get userSelectAction(){return n},clear:a,evalSelectAction:p,isEmpty:l,isSelected:h,setSelected:c,setUserSelectAction:f,subscribe:i,userSelect:u}},xa=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},we=[];for(let r=0;r<256;++r)we.push((r+256).toString(16).slice(1));function p_(r,t=0){return(we[r[t+0]]+we[r[t+1]]+we[r[t+2]]+we[r[t+3]]+"-"+we[r[t+4]]+we[r[t+5]]+"-"+we[r[t+6]]+we[r[t+7]]+"-"+we[r[t+8]]+we[r[t+9]]+"-"+we[r[t+10]]+we[r[t+11]]+we[r[t+12]]+we[r[t+13]]+we[r[t+14]]+we[r[t+15]]).toLowerCase()}let ba;const m_=new Uint8Array(16);function g_(){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(m_)}const y_=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Hu={randomUUID:y_};function __(r,t,e){var i;if(Hu.randomUUID&&!r)return Hu.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??g_();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,p_(s)}const Ea=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)}},v_=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},x_=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},b_=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!Yr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),E_=(r,t)=>!Yr(r.target,t.target),$u=(r,t)=>{const e=v_(r,t),i=x_(r,t),s=b_(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:s.length>0?s:void 0,targetUpdated:E_(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Bt=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Bt||{});const w_=(r,t)=>{var e,i;const{changes:s,origin:n}=t;if(!(r.options.origin?r.options.origin===n:n!=="SILENT"))return!1;if(r.options.ignore){const{ignore:o}=r.options,a=l=>l&&l.length>0;if(!(a(s.created)||a(s.deleted))){const l=(e=s.updated)==null?void 0:e.some(u=>a(u.bodiesCreated)||a(u.bodiesDeleted)||a(u.bodiesUpdated)),h=(i=s.updated)==null?void 0:i.some(u=>u.targetUpdated);if(o==="BODY_ONLY"&&l&&!h||o==="TARGET_ONLY"&&h&&!l)return!1}}if(r.options.annotations){const o=new Set([...(s.created||[]).map(a=>a.id),...(s.deleted||[]).map(a=>a.id),...(s.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},T_=(r,t)=>{const e=new Set((r.created||[]).map(c=>c.id)),i=new Set((r.updated||[]).map(({newValue:c})=>c.id)),s=new Set((t.created||[]).map(c=>c.id)),n=new Set((t.deleted||[]).map(c=>c.id)),o=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>e.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(r.created||[]).filter(c=>!n.has(c.id)).map(c=>o.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],h=[...(r.deleted||[]).filter(c=>!s.has(c.id)),...(t.deleted||[]).filter(c=>!e.has(c.id))],u=[...(r.updated||[]).filter(({newValue:c})=>!n.has(c.id)).map(c=>{const{oldValue:d,newValue:f}=c;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return $u(d,p)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}},Cn=r=>{const t=r.id===void 0?__():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},A_=r=>r.id!==void 0,S_=()=>{const r=new Map,t=new Map,e=[],i=(I,A={})=>{e.push({onChange:I,options:A})},s=I=>{const A=e.findIndex(w=>w.onChange==I);A>-1&&e.splice(A,1)},n=(I,A)=>{const w={origin:I,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...r.values()]};e.forEach(C=>{w_(C,w)&&C.onChange(w)})},o=(I,A=Bt.LOCAL)=>{if(I.id&&r.get(I.id))throw Error(`Cannot add annotation ${I.id} - exists already`);{const w=Cn(I);r.set(w.id,w),w.bodies.forEach(C=>t.set(C.id,w.id)),n(A,{created:[w]})}},a=(I,A)=>{const w=Cn(typeof I=="string"?A:I),C=typeof I=="string"?I:I.id,D=C&&r.get(C);if(D){const N=$u(D,w);return C===w.id?r.set(C,w):(r.delete(C),r.set(w.id,w)),D.bodies.forEach(B=>t.delete(B.id)),w.bodies.forEach(B=>t.set(B.id,w.id)),N}else console.warn(`Cannot update annotation ${C} - does not exist`)},l=(I,A=Bt.LOCAL,w=Bt.LOCAL)=>{const C=A_(A)?w:A,D=a(I,A);D&&n(C,{updated:[D]})},h=(I,A=Bt.LOCAL)=>{r.get(I.id)?l(I,A):o(I,A)},u=(I,A=Bt.LOCAL)=>{const w=I.reduce((C,D)=>{const N=a(D);return N?[...C,N]:C},[]);w.length>0&&n(A,{updated:w})},c=(I,A=Bt.LOCAL)=>{const w=I.map(Cn),{toAdd:C,toUpdate:D}=w.reduce((B,V)=>r.get(V.id)?{...B,toUpdate:[...B.toUpdate,V]}:{...B,toAdd:[...B.toAdd,V]},{toAdd:[],toUpdate:[]}),N=D.map(B=>a(B,A)).filter(Boolean);C.forEach(B=>{r.set(B.id,B),B.bodies.forEach(V=>t.set(V.id,B.id))}),n(A,{created:C,updated:N})},d=(I,A=Bt.LOCAL)=>{const w=r.get(I.annotation);if(w){const C={...w,bodies:[...w.bodies,I]};r.set(w.id,C),t.set(I.id,C.id),n(A,{updated:[{oldValue:w,newValue:C,bodiesCreated:[I]}]})}else console.warn(`Attempt to add body to missing annotation: ${I.annotation}`)},f=()=>[...r.values()],p=(I=Bt.LOCAL)=>{const A=[...r.values()];r.clear(),t.clear(),n(I,{deleted:A})},m=(I,A=!0,w=Bt.LOCAL)=>{const C=I.map(Cn);if(A){const D=[...r.values()];r.clear(),t.clear(),C.forEach(N=>{r.set(N.id,N),N.bodies.forEach(B=>t.set(B.id,N.id))}),n(w,{created:C,deleted:D})}else{const D=I.reduce((N,B)=>{const V=B.id&&r.get(B.id);return V?[...N,V]:N},[]);if(D.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${D.map(N=>N.id).join(", ")}`);C.forEach(N=>{r.set(N.id,N),N.bodies.forEach(B=>t.set(B.id,N.id))}),n(w,{created:C})}},_=I=>{const A=typeof I=="string"?I:I.id,w=r.get(A);if(w)return r.delete(A),w.bodies.forEach(C=>t.delete(C.id)),w;console.warn(`Attempt to delete missing annotation: ${A}`)},y=(I,A=Bt.LOCAL)=>{const w=_(I);w&&n(A,{deleted:[w]})},v=(I,A=Bt.LOCAL)=>{const w=I.reduce((C,D)=>{const N=_(D);return N?[...C,N]:C},[]);w.length>0&&n(A,{deleted:w})},g=I=>{const A=r.get(I.annotation);if(A){const w=A.bodies.find(C=>C.id===I.id);if(w){t.delete(w.id);const C={...A,bodies:A.bodies.filter(D=>D.id!==I.id)};return r.set(A.id,C),{oldValue:A,newValue:C,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${I.id} from annotation ${I.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${I.annotation}`)},x=(I,A=Bt.LOCAL)=>{const w=g(I);w&&n(A,{updated:[w]})},E=(I,A=Bt.LOCAL)=>{const w=I.map(C=>g(C)).filter(Boolean);w.length>0&&n(A,{updated:w})},R=I=>{const A=r.get(I);return A?{...A}:void 0},S=I=>{const A=t.get(I);if(A){const w=R(A).bodies.find(C=>C.id===I);if(w)return w;console.error(`Store integrity error: body ${I} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${I}`)},M=(I,A)=>{if(I.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=r.get(I.annotation);if(w){const C=w.bodies.find(N=>N.id===I.id),D={...w,bodies:w.bodies.map(N=>N.id===C.id?A:N)};return r.set(w.id,D),C.id!==A.id&&(t.delete(C.id),t.set(A.id,D.id)),{oldValue:w,newValue:D,bodiesUpdated:[{oldBody:C,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${I.annotation}`)},P=(I,A,w=Bt.LOCAL)=>{const C=M(I,A);C&&n(w,{updated:[C]})},F=(I,A=Bt.LOCAL)=>{const w=I.map(C=>M({id:C.id,annotation:C.annotation},C)).filter(Boolean);n(A,{updated:w})},U=I=>{const A=r.get(I.annotation);if(A){const w={...A,target:{...A.target,...I}};return r.set(A.id,w),{oldValue:A,newValue:w,targetUpdated:{oldTarget:A.target,newTarget:I}}}else console.warn(`Attempt to update target on missing annotation: ${I.annotation}`)};return{addAnnotation:o,addBody:d,all:f,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:E,bulkUpdateAnnotations:u,bulkUpdateBodies:F,bulkUpdateTargets:(I,A=Bt.LOCAL)=>{const w=I.map(C=>U(C)).filter(Boolean);w.length>0&&n(A,{updated:w})},bulkUpsertAnnotations:c,clear:p,deleteAnnotation:y,deleteBody:x,getAnnotation:R,getBody:S,observe:i,unobserve:s,updateAnnotation:l,updateBody:P,updateTarget:(I,A=Bt.LOCAL)=>{const w=U(I);w&&n(A,{updated:[w]})},upsertAnnotation:h}},C_=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let I_=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,s=e.length;i<s;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(s=>t!==s)}}});const R_=250,M_=(r,t)=>{const e=I_(),i=(t==null?void 0:t.changes)||[];let s=t?t.pointer:-1,n=!1,o=0;const a=p=>{if(!n){const{changes:m}=p,_=performance.now();if(_-o>R_)i.splice(s+1),i.push(m),s=i.length-1;else{const y=i.length-1;i[y]=T_(i[y],m)}o=_}n=!1};r.observe(a,{origin:Bt.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:m})=>m)),c=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>s,canUndo:()=>s>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:s}),on:(p,m)=>e.on(p,m),redo:()=>{if(i.length-1>s){n=!0;const{created:p,updated:m,deleted:_}=i[s+1];h(p),c(m),f(_),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:p,updated:m,deleted:_}=i[s];l(p),u(m),d(_),e.emit("undo",i[s]),s-=1}}}},P_=()=>{const{subscribe:r,set:t}=va([]);return{subscribe:r,set:t}},O_=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(y,v)=>{l.has(y)?l.get(y).push(v):l.set(y,[v])},f=(y,v)=>{const g=l.get(y);if(g){const x=g.indexOf(v);x!==-1&&g.splice(x,1)}},p=(y,v,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(x=>{if(e){const E=Array.isArray(v)?v.map(S=>e.serialize(S)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;x(E,R)}else x(v,g)})},1)},m=()=>{const{selected:y}=n,v=(y||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const x=h.find(E=>E.id===g.id);(!x||!Yr(x,g))&&p("updateAnnotation",g,x)}),h=h.map(g=>v.find(({id:x})=>x===g.id)||g)};n.subscribe(({selected:y})=>{if(!(h.length===0&&y.length===0)){if(h.length===0&&y.length>0)h=y.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&y.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Yr(g,v)&&p("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),g=new Set(y.map(({id:x})=>x));h.filter(x=>!g.has(x.id)).forEach(x=>{const E=o.getAnnotation(x.id);E&&!Yr(E,x)&&p("updateAnnotation",E,x)}),h=[...h.filter(x=>g.has(x.id)),...y.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}p("selectionChanged",h)}}),s.subscribe(y=>{!u&&y?p("mouseEnterAnnotation",o.getAnnotation(y)):u&&!y?p("mouseLeaveAnnotation",o.getAnnotation(u)):u&&y&&(p("mouseLeaveAnnotation",o.getAnnotation(u)),p("mouseEnterAnnotation",o.getAnnotation(y))),u=y}),a==null||a.subscribe(y=>p("viewportIntersect",y.map(v=>o.getAnnotation(v)))),o.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:v,deleted:g}=y.changes;(v||[]).forEach(x=>p("createAnnotation",x)),(g||[]).forEach(x=>p("deleteAnnotation",x)),(y.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:E})=>{const R=h.find(S=>S.id===x.id)||x;h=h.map(S=>S.id===x.id?E:S),p("updateAnnotation",E,R)})},{origin:Bt.LOCAL}),o.observe(y=>{if(h){const v=new Set(h.map(x=>x.id)),g=(y.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);g.length>0&&(h=h.map(x=>g.find(E=>E.id===x.id)||x))}},{origin:Bt.REMOTE});const _=y=>v=>{const{updated:g}=v;y?(g||[]).forEach(x=>p("updateAnnotation",x.oldValue,x.newValue)):(g||[]).forEach(x=>p("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:f,emit:p}},N_=r=>t=>t.reduce((e,i)=>{const{parsed:s,error:n}=r.parse(i);return n?{parsed:e.parsed,failed:[...e.failed,i]}:s?{parsed:[...e.parsed,s],failed:e.failed}:{...e}},{parsed:[],failed:[]}),D_=(r,t,e)=>{const{store:i,selection:s}=r,n=y=>{if(e){const{parsed:v,error:g}=e.parse(y);v?i.addAnnotation(v,Bt.REMOTE):console.error(g)}else i.addAnnotation(Ea(y),Bt.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=y=>{const v=i.getAnnotation(y);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var y;const v=(((y=s.selected)==null?void 0:y.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},c=(y,v=!0)=>fetch(y).then(g=>g.json()).then(g=>(f(g,v),g)),d=y=>{if(typeof y=="string"){const v=i.getAnnotation(y);if(i.deleteAnnotation(y),v)return e?e.serialize(v):v}else{const v=e?e.parse(y).parsed:y;if(v)return i.deleteAnnotation(v),y}},f=(y,v=!0)=>{if(e){const g=e.parseAll||N_(e),{parsed:x,failed:E}=g(y);E.length>0&&console.warn(`Discarded ${E.length} invalid annotations`,E),i.bulkAddAnnotations(x,v,Bt.REMOTE)}else i.bulkAddAnnotations(y.map(Ea),v,Bt.REMOTE)},p=(y,v)=>{y?s.setSelected(y,v):s.clear()},m=y=>{s.clear(),s.setUserSelectAction(y)},_=y=>{if(e){const v=e.parse(y).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(y.id);return i.updateAnnotation(Ea(y)),v}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:u,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},L_=(r,t,e)=>typeof t=="function"?t(r,e):t,B_=(r,t)=>typeof r!="function"&&typeof t!="function"?{...r||{},...t||{}}:(e,i)=>{const s=typeof r=="function"?r(e,i):r,n=typeof t=="function"?t(e,i):t;return{...s||{},...n||{}}},F_="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let k_=r=>crypto.getRandomValues(new Uint8Array(r)),U_=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,s=-~(1.6*i*t/r.length);return(n=t)=>{let o="";for(;;){let a=e(s),l=s|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=n)return o}}},G_=(r,t=21)=>U_(r,t|0,k_),H_=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=F_[e[r]&63];return t};const $_=()=>({isGuest:!0,id:G_("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),X_=r=>{const t=JSON.stringify(r);let e=0;for(let i=0,s=t.length;i<s;i++){let n=t.charCodeAt(i);e=(e<<5)-e+n,e|=0}return`${e}`},Xu=r=>r?typeof r=="object"?{...r}:r:void 0,V_=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:s,purpose:n,value:o,created:a,modified:l,creator:h,...u}=e;return{id:i||`temp-${X_(e)}`,annotation:t,type:s,purpose:n,value:o,creator:Xu(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...u}}),z_=r=>r.map(t=>{var e;const{annotation:i,created:s,updated:n,...o}=t,a={...o,created:s==null?void 0:s.toISOString(),modified:n==null?void 0:n.toISOString()};return(e=a.id)!=null&&e.startsWith("temp-")&&delete a.id,a});H_();const Y_=(r,t={strict:!0,invertY:!1})=>({parse:e=>W_(e,t),serialize:e=>j_(e,r,t)}),W_=(r,t={strict:!0,invertY:!1})=>{const e=r.id||ku(),{creator:i,created:s,modified:n,body:o,...a}=r,l=V_(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,u=typeof h=="string"?h:Array.isArray(h.selector)?h.selector[0]:h.selector,c=typeof u=="string"||(u==null?void 0:u.type)==="FragmentSelector"?My(u,t.invertY):(u==null?void 0:u.type)==="SvgSelector"?s_(u):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return c||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:s?new Date(s):void 0,creator:Xu(i),updated:n?new Date(n):void 0,...typeof d=="string"?{}:d,annotation:e,selector:c||u}}}:{error:Error(`Invalid selector: ${JSON.stringify(u)}`)}},j_=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:s,created:n,updated:o,updatedBy:a,...l}=r.target;let h;try{h=i.type==Tt.RECTANGLE?Py(i.geometry):o_(i)}catch(c){if(e.strict)throw c;h=i}const u={...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:r.id,type:"Annotation",body:z_(r.bodies),created:n==null?void 0:n.toISOString(),creator:s,modified:o==null?void 0:o.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:h}};return delete u.bodies,"annotation"in u.target&&delete u.target.annotation,u},wa=(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))},Yi=[];function q_(r,t=Dt){let e;const i=new Set;function s(a){if(le(r,a)&&(r=a,e)){const l=!Yi.length;for(const h of i)h[1](),Yi.push(h,r);if(l){for(let h=0;h<Yi.length;h+=2)Yi[h][0](Yi[h+1]);Yi.length=0}}}function n(a){s(a(r))}function o(a,l=Dt){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||Dt),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const K_=(r,t)=>{const{naturalWidth:e,naturalHeight:i}=r;if(!e&&!i){const{width:s,height:n}=r;t.setAttribute("viewBox",`0 0 ${s} ${n}`),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}`)},Z_=(r,t)=>{K_(r,t);const{subscribe:e,set:i}=q_(1);let s;return window.ResizeObserver&&(s=new ResizeObserver(()=>{const n=t.getBoundingClientRect(),{width:o,height:a}=t.viewBox.baseVal,l=Math.max(n.width/o,n.height/a);i(l)}),s.observe(t.parentElement)),{destroy:()=>{s&&s.disconnect()},subscribe:e}},Os=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:s,stroke:n,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${s||"0.25"};`),n&&(l+=`stroke:${n};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},In=(r,t=0)=>{const{minX:e,minY:i,maxX:s,maxY:n}=r;return{x:e-t,y:i-t,w:s-e+2*t,h:n-i+2*t}},Cr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Q_=r=>({}),Vu=r=>({grab:r[0]});function J_(r){let t,e,i,s;const n=r[8].default,o=dy(n,r,r[7],Vu);return{c(){t=Z("g"),o&&o.c(),b(t,"class","a9s-annotation selected")},m(a,l){it(a,t,l),o&&o.m(t,null),e=!0,i||(s=[Rt(t,"pointerup",r[2]),Rt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&py(o,n,a,a[7],e?fy(n,a[7],l,Q_):my(a[7]),Vu)},i(a){e||(ot(o,a),e=!0)},o(a){gt(o,a),e=!1},d(a){a&&rt(t),o&&o.d(a),i=!1,$e(s)}}}function t0(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Xr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,u,c,d;const f=_=>y=>{if(u=_,h){const{left:v,top:g}=h.getBoundingClientRect(),x=y.clientX-v,E=y.clientY-g;c=l.elementToImage(x,E)}else{const{offsetX:v,offsetY:g}=y;c=l.elementToImage(v,g)}d=o,y.target.setPointerCapture(y.pointerId),n("grab",y)},p=_=>{if(u){const[y,v]=l.elementToImage(_.offsetX,_.offsetY),g=[y-c[0],v-c[1]];e(3,o=a(d,u,g)),n("change",o)}},m=_=>{_.target.releasePointerCapture(_.pointerId),u=void 0,d=o,n("release",_)};return r.$$set=_=>{"shape"in _&&e(3,o=_.shape),"editor"in _&&e(4,a=_.editor),"transform"in _&&e(5,l=_.transform),"svgEl"in _&&e(6,h=_.svgEl),"$$scope"in _&&e(7,s=_.$$scope)},[f,p,m,o,a,l,h,s,i]}class Ta extends De{constructor(t){super(),Ne(this,t,t0,J_,le,{shape:3,editor:4,transform:5,svgEl:6})}}function e0(r){let t,e,i,s,n,o,a,l,h=r[3]&&zu(r);return{c(){t=Z("g"),e=Z("circle"),h&&h.c(),s=Z("circle"),b(e,"class","a9s-handle-buffer"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=r[5]+6/r[2]),b(s,"class",n=`a9s-handle-dot${r[3]?" selected":""}`),b(s,"cx",r[0]),b(s,"cy",r[1]),b(s,"r",r[5]),b(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(u,c){it(u,t,c),wt(t,e),h&&h.m(t,null),wt(t,s),a||(l=[Rt(e,"pointerenter",r[11]),Rt(e,"pointerleave",r[12]),Rt(e,"pointerdown",r[13]),Rt(e,"pointerdown",r[6]),Rt(e,"pointerup",r[14]),Rt(e,"pointerup",r[7])],a=!0)},p(u,c){c&1&&b(e,"cx",u[0]),c&2&&b(e,"cy",u[1]),c&36&&i!==(i=u[5]+6/u[2])&&b(e,"r",i),u[3]?h?h.p(u,c):(h=zu(u),h.c(),h.m(t,s)):h&&(h.d(1),h=null),c&8&&n!==(n=`a9s-handle-dot${u[3]?" selected":""}`)&&b(s,"class",n),c&1&&b(s,"cx",u[0]),c&2&&b(s,"cy",u[1]),c&32&&b(s,"r",u[5]),c&256&&o!==(o=`a9s-handle ${u[8].class||""}`.trim())&&b(t,"class",o)},d(u){u&&rt(t),h&&h.d(),a=!1,$e(l)}}}function r0(r){let t,e,i,s,n,o,a,l,h;return{c(){t=Z("g"),e=Z("circle"),s=Z("circle"),o=Z("circle"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=r[5]*10),b(e,"class","a9s-touch-halo"),cr(e,"touched",r[4]),b(s,"cx",r[0]),b(s,"cy",r[1]),b(s,"r",n=r[5]+10/r[2]),b(s,"class","a9s-handle-buffer"),b(o,"class","a9s-handle-dot"),b(o,"cx",r[0]),b(o,"cy",r[1]),b(o,"r",a=r[5]+2/r[2]),b(t,"class","a9s-touch-handle")},m(u,c){it(u,t,c),wt(t,e),wt(t,s),wt(t,o),l||(h=[Rt(s,"pointerdown",r[9]),Rt(s,"pointerup",r[10]),Rt(s,"pointerdown",r[6]),Rt(s,"pointerup",r[7])],l=!0)},p(u,c){c&1&&b(e,"cx",u[0]),c&2&&b(e,"cy",u[1]),c&32&&i!==(i=u[5]*10)&&b(e,"r",i),c&16&&cr(e,"touched",u[4]),c&1&&b(s,"cx",u[0]),c&2&&b(s,"cy",u[1]),c&36&&n!==(n=u[5]+10/u[2])&&b(s,"r",n),c&1&&b(o,"cx",u[0]),c&2&&b(o,"cy",u[1]),c&36&&a!==(a=u[5]+2/u[2])&&b(o,"r",a)},d(u){u&&rt(t),l=!1,$e(h)}}}function zu(r){let t,e;return{c(){t=Z("circle"),b(t,"class","a9s-handle-selected"),b(t,"cx",r[0]),b(t,"cy",r[1]),b(t,"r",e=r[5]+8/r[2])},m(i,s){it(i,t,s)},p(i,s){s&1&&b(t,"cx",i[0]),s&2&&b(t,"cy",i[1]),s&36&&e!==(e=i[5]+8/i[2])&&b(t,"r",e)},d(i){i&&rt(t)}}}function i0(r){let t;function e(s,n){return Cr?r0:e0}let i=e()(r);return{c(){i.c(),t=Fe()},m(s,n){i.m(s,n),it(s,t,n)},p(s,[n]){i.p(s,n)},i:Dt,o:Dt,d(s){s&&rt(t),i.d(s)}}}function s0(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=y=>{y.pointerType==="touch"&&e(4,l=!0)},u=()=>e(4,l=!1);function c(y){Ce.call(this,r,y)}function d(y){Ce.call(this,r,y)}function f(y){Ce.call(this,r,y)}function p(y){Ce.call(this,r,y)}function m(y){Ce.call(this,r,y)}function _(y){Ce.call(this,r,y)}return r.$$set=y=>{e(8,t=sa(sa({},t),mu(y))),"x"in y&&e(0,s=y.x),"y"in y&&e(1,n=y.y),"scale"in y&&e(2,o=y.scale),"selected"in y&&e(3,a=y.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=mu(t),[s,n,o,a,l,i,h,u,t,c,d,f,p,m,_]}class Wi extends De{constructor(t){super(),Ne(this,t,s0,i0,le,{x:0,y:1,scale:2,selected:3})}}function n0(r){let t,e,i,s,n,o,a;return{c(){t=Z("g"),e=Z("circle"),s=Z("circle"),n=Z("circle"),b(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=1.75*r[2]),b(s,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),b(s,"cx",r[0]),b(s,"cy",r[1]),b(s,"r",r[2]),b(n,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),b(n,"cx",r[0]),b(n,"cy",r[1]),b(n,"r",r[2]),b(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){it(l,t,h),wt(t,e),wt(t,s),wt(t,n),o||(a=[Rt(e,"pointerdown",r[5]),Rt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&b(e,"cx",l[0]),h&2&&b(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&b(e,"r",i),h&1&&b(s,"cx",l[0]),h&2&&b(s,"cy",l[1]),h&4&&b(s,"r",l[2]),h&1&&b(n,"cx",l[0]),h&2&&b(n,"cy",l[1]),h&4&&b(n,"r",l[2])},d(l){l&&rt(t),o=!1,$e(a)}}}function o0(r){let t;return{c(){t=Z("circle"),b(t,"cx",r[0]),b(t,"cy",r[1]),b(t,"r",r[2])},m(e,i){it(e,t,i)},p(e,i){i&1&&b(t,"cx",e[0]),i&2&&b(t,"cy",e[1]),i&4&&b(t,"r",e[2])},d(e){e&&rt(t)}}}function a0(r){let t;function e(s,n){return Cr?o0:n0}let i=e()(r);return{c(){i.c(),t=Fe()},m(s,n){i.m(s,n),it(s,t,n)},p(s,[n]){i.p(s,n)},i:Dt,o:Dt,d(s){s&&rt(t),i.d(s)}}}function l0(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){Ce.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,s=h.x),"y"in h&&e(1,n=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[s,n,i,a,o,l]}class Yu extends De{constructor(t){super(),Ne(this,t,l0,a0,le,{x:0,y:1,scale:4})}}function Aa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Wu(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Sa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ca(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function ju(r){let t,e,i,s;return{c(){t=Z("circle"),b(t,"cx",e=r[28][0]),b(t,"cy",i=r[28][1]),b(t,"r",s=Ns/r[3]),b(t,"class","svelte-1h2slbm")},m(n,o){it(n,t,o)},p(n,o){o[0]&1088&&e!==(e=n[28][0])&&b(t,"cx",e),o[0]&1088&&i!==(i=n[28][1])&&b(t,"cy",i),o[0]&8&&s!==(s=Ns/n[3])&&b(t,"r",s)},d(n){n&&rt(t)}}}function qu(r){let t,e,i,s,n,o,a,l,h,u;return{c(){t=Z("mask"),e=Z("rect"),a=Z("circle"),b(e,"x",i=r[9].x),b(e,"y",s=r[9].y),b(e,"width",n=r[9].w),b(e,"height",o=r[9].h),b(e,"class","svelte-1h2slbm"),b(a,"cx",l=r[28][0]),b(a,"cy",h=r[28][1]),b(a,"r",u=Ns/r[3]),b(a,"class","svelte-1h2slbm"),b(t,"id",`${r[19]}-inner`),b(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,d){it(c,t,d),wt(t,e),wt(t,a)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&b(e,"x",i),d[0]&512&&s!==(s=c[9].y)&&b(e,"y",s),d[0]&512&&n!==(n=c[9].w)&&b(e,"width",n),d[0]&512&&o!==(o=c[9].h)&&b(e,"height",o),d[0]&1088&&l!==(l=c[28][0])&&b(a,"cx",l),d[0]&1088&&h!==(h=c[28][1])&&b(a,"cy",h),d[0]&8&&u!==(u=Ns/c[3])&&b(a,"r",u)},d(c){c&&rt(t)}}}function Ku(r){let t,e;return t=new Wi({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(){Vt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&32&&(n.x=r[28][0]),s[0]&32&&(n.y=r[28][1]),s[0]&8&&(n.scale=r[3]),s[0]&256&&(n.selected=r[8].includes(r[30])),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function Zu(r){let t,e;return t=new Yu({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Vt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&1088&&(n.x=r[28][0]),s[0]&1088&&(n.y=r[28][1]),s[0]&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function h0(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v,g,x,E,R=r[6]!==void 0&&!r[7]&&ju(Ca(r)),S=r[6]!==void 0&&!r[7]&&qu(Sa(r)),M=ke(r[5].points),P=[];for(let I=0;I<M.length;I+=1)P[I]=Ku(Wu(r,M,I));const F=I=>gt(P[I],1,1,()=>{P[I]=null});let U=r[6]!==void 0&&!r[7]&&Zu(Aa(r));return{c(){t=Z("defs"),e=Z("mask"),i=Z("rect"),l=Z("polygon"),R&&R.c(),S&&S.c(),u=Oe(),c=Z("polygon"),f=Oe(),p=Z("polygon"),_=Oe();for(let I=0;I<P.length;I+=1)P[I].c();y=Oe(),U&&U.c(),v=Fe(),b(i,"x",s=r[9].x),b(i,"y",n=r[9].y),b(i,"width",o=r[9].w),b(i,"height",a=r[9].h),b(i,"class","svelte-1h2slbm"),b(l,"points",h=r[5].points.map(Qu).join(" ")),b(l,"class","svelte-1h2slbm"),b(e,"id",`${r[19]}-outer`),b(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),b(c,"class","a9s-outer"),b(c,"mask",`url(#${r[19]}-outer)`),b(c,"points",d=r[5].points.map(Ju).join(" ")),b(p,"class","a9s-inner a9s-shape-handle"),b(p,"mask",`url(#${r[19]}-inner)`),b(p,"style",r[1]),b(p,"points",m=r[5].points.map(tc).join(" "))},m(I,A){it(I,t,A),wt(t,e),wt(e,i),wt(e,l),R&&R.m(e,null),S&&S.m(t,null),it(I,u,A),it(I,c,A),it(I,f,A),it(I,p,A),it(I,_,A);for(let w=0;w<P.length;w+=1)P[w]&&P[w].m(I,A);it(I,y,A),U&&U.m(I,A),it(I,v,A),g=!0,x||(E=[Rt(c,"pointerup",r[14]),Rt(c,"pointerdown",function(){Vt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Rt(p,"pointermove",r[13]),Rt(p,"pointerup",r[14]),Rt(p,"pointerdown",function(){Vt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],x=!0)},p(I,A){if(r=I,(!g||A[0]&512&&s!==(s=r[9].x))&&b(i,"x",s),(!g||A[0]&512&&n!==(n=r[9].y))&&b(i,"y",n),(!g||A[0]&512&&o!==(o=r[9].w))&&b(i,"width",o),(!g||A[0]&512&&a!==(a=r[9].h))&&b(i,"height",a),(!g||A[0]&32&&h!==(h=r[5].points.map(Qu).join(" ")))&&b(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Ca(r),A):(R=ju(Ca(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?S?S.p(Sa(r),A):(S=qu(Sa(r)),S.c(),S.m(t,null)):S&&(S.d(1),S=null),(!g||A[0]&32&&d!==(d=r[5].points.map(Ju).join(" ")))&&b(c,"points",d),(!g||A[0]&2)&&b(p,"style",r[1]),(!g||A[0]&32&&m!==(m=r[5].points.map(tc).join(" ")))&&b(p,"points",m),A[0]&134322472){M=ke(r[5].points);let w;for(w=0;w<M.length;w+=1){const C=Wu(r,M,w);P[w]?(P[w].p(C,A),ot(P[w],1)):(P[w]=Ku(C),P[w].c(),ot(P[w],1),P[w].m(y.parentNode,y))}for(Ie(),w=M.length;w<P.length;w+=1)F(w);Re()}r[6]!==void 0&&!r[7]?U?(U.p(Aa(r),A),A[0]&192&&ot(U,1)):(U=Zu(Aa(r)),U.c(),ot(U,1),U.m(v.parentNode,v)):U&&(Ie(),gt(U,1,1,()=>{U=null}),Re())},i(I){if(!g){for(let A=0;A<M.length;A+=1)ot(P[A]);ot(U),g=!0}},o(I){P=P.filter(Boolean);for(let A=0;A<P.length;A+=1)gt(P[A]);gt(U),g=!1},d(I){I&&(rt(t),rt(u),rt(c),rt(f),rt(p),rt(_),rt(y),rt(v)),R&&R.d(),S&&S.d(),mi(P,I),U&&U.d(I),x=!1,$e(E)}}}function u0(r){let t,e;return t=new Ta({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[h0,({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(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&1&&(n.shape=i[0]),s[0]&4&&(n.transform=i[2]),s[0]&16&&(n.svgEl=i[4]),s[0]&134219754|s[1]&1&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}const c0=250,d0=1e3,f0=12,Ns=4.5,Qu=r=>r.join(","),Ju=r=>r.join(","),tc=r=>r.join(",");function p0(r,t,e){let i,s,n;const o=Xr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:u=1}=t,{svgEl:c}=t,d,f=!1,p,m=[];const _=()=>e(7,f=!0),y=()=>e(7,f=!1),v=w=>{if(m.length>0||!s.some(O=>O.visible)){e(6,d=void 0);return}const[C,D]=h.elementToImage(w.offsetX,w.offsetY),N=O=>Math.pow(O[0]-C,2)+Math.pow(O[1]-D,2),B=i.points.reduce((O,k)=>N(k)<N(O)?k:O),V=s.filter(O=>O.visible).reduce((O,k)=>N(k.point)<N(O.point)?k:O),L=Math.pow(d0/u,2);N(B)<L||N(V.point)<L?e(6,d=s.indexOf(V)):e(6,d=void 0)},g=()=>{document.activeElement!==c&&c.focus()},x=()=>{e(8,m=[]),g()},E=w=>{e(7,f=!0),w.preventDefault(),w.stopPropagation(),p=performance.now()},R=w=>C=>{if(!p||Cr||performance.now()-p>c0)return;const D=m.includes(w);C.metaKey||C.ctrlKey||C.shiftKey?D?e(8,m=m.filter(N=>N!==w)):e(8,m=[...m,w]):D&&m.length>1?e(8,m=[w]):D?e(8,m=[]):e(8,m=[w]),g()},S=(w,C,D)=>{g();let N;const B=w.geometry;m.length>1?N=B.points.map(([L,O],k)=>m.includes(k)?[L+D[0],O+D[1]]:[L,O]):C==="SHAPE"?N=B.points.map(([L,O])=>[L+D[0],O+D[1]]):N=B.points.map(([L,O],k)=>C===`HANDLE-${k}`?[L+D[0],O+D[1]]:[L,O]);const V=Ue(N);return{...w,geometry:{points:N,bounds:V}}},M=w=>async C=>{C.stopPropagation();const D=[...i.points.slice(0,w+1),s[w].point,...i.points.slice(w+1)],N=Ue(D);o("change",{...a,geometry:{points:D,bounds:N}}),await bu();const B=[...document.querySelectorAll(".a9s-handle")][w+1];if(B!=null&&B.firstChild){const V=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:C.clientX,clientY:C.clientY,pointerId:C.pointerId,pointerType:C.pointerType,isPrimary:C.isPrimary,buttons:C.buttons});B.firstChild.dispatchEvent(V)}},P=()=>{if(i.points.length<4)return;const w=i.points.filter((D,N)=>!m.includes(N)),C=Ue(w);o("change",{...a,geometry:{points:w,bounds:C}}),e(8,m=[])};gi(()=>{if(Cr)return;const w=C=>{(C.key==="Delete"||C.key==="Backspace")&&(C.preventDefault(),P())};return c.addEventListener("pointermove",v),c.addEventListener("keydown",w),()=>{c.removeEventListener("pointermove",v),c.removeEventListener("keydown",w)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(w){Ce.call(this,r,w)}function I(w){Ce.call(this,r,w)}function A(w){Ce.call(this,r,w)}return r.$$set=w=>{"shape"in w&&e(0,a=w.shape),"computedStyle"in w&&e(1,l=w.computedStyle),"transform"in w&&e(2,h=w.transform),"viewportScale"in w&&e(3,u=w.viewportScale),"svgEl"in w&&e(4,c=w.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,s=Cr?[]:i.points.map((w,C)=>{const D=C===i.points.length-1?i.points[0]:i.points[C+1],N=(w[0]+D[0])/2,B=(w[1]+D[1])/2,V=Math.sqrt(Math.pow(D[0]-N,2)+Math.pow(D[1]-B,2))>f0/u;return{point:[N,B],visible:V}})),r.$$.dirty[0]&40&&e(9,n=In(i.bounds,Ns/u))},[a,l,h,u,c,i,d,f,m,n,s,_,y,v,x,E,R,S,M,F,U,I,A]}class m0 extends De{constructor(t){super(),Ne(this,t,p0,u0,le,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function g0(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v,g,x,E,R,S,M,P,F,U,I,A,w,C,D,N,B,V,L,O,k,X,Y,q,pt,_t,W,bt,dt,mt,xt,Mt,Nt,_e,jt,et,Ke,mn;return dt=new Wi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),dt.$on("pointerdown",function(){Vt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),xt=new Wi({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),xt.$on("pointerdown",function(){Vt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Nt=new Wi({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Nt.$on("pointerdown",function(){Vt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),jt=new Wi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),jt.$on("pointerdown",function(){Vt(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=Oe(),p=Z("rect"),g=Oe(),x=Z("rect"),P=Oe(),F=Z("rect"),w=Oe(),C=Z("rect"),V=Oe(),L=Z("rect"),Y=Oe(),q=Z("rect"),bt=Oe(),be(dt.$$.fragment),mt=Oe(),be(xt.$$.fragment),Mt=Oe(),be(Nt.$$.fragment),_e=Oe(),be(jt.$$.fragment),b(i,"class","rect-mask-bg svelte-1njczvj"),b(i,"x",s=r[6].x),b(i,"y",n=r[6].y),b(i,"width",o=r[6].w),b(i,"height",a=r[6].h),b(l,"class","rect-mask-fg svelte-1njczvj"),b(l,"x",h=r[5].x),b(l,"y",u=r[5].y),b(l,"width",c=r[5].w),b(l,"height",d=r[5].h),b(e,"id",r[8]),b(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),b(p,"class","a9s-outer"),b(p,"mask",`url(#${r[8]})`),b(p,"x",m=r[5].x),b(p,"y",_=r[5].y),b(p,"width",y=r[5].w),b(p,"height",v=r[5].h),b(x,"class","a9s-inner a9s-shape-handle"),b(x,"style",r[1]),b(x,"x",E=r[5].x),b(x,"y",R=r[5].y),b(x,"width",S=r[5].w),b(x,"height",M=r[5].h),b(F,"class","a9s-edge-handle a9s-edge-handle-top"),b(F,"x",U=r[5].x),b(F,"y",I=r[5].y),b(F,"height",1),b(F,"width",A=r[5].w),b(C,"class","a9s-edge-handle a9s-edge-handle-right"),b(C,"x",D=r[5].x+r[5].w),b(C,"y",N=r[5].y),b(C,"height",B=r[5].h),b(C,"width",1),b(L,"class","a9s-edge-handle a9s-edge-handle-bottom"),b(L,"x",O=r[5].x),b(L,"y",k=r[5].y+r[5].h),b(L,"height",1),b(L,"width",X=r[5].w),b(q,"class","a9s-edge-handle a9s-edge-handle-left"),b(q,"x",pt=r[5].x),b(q,"y",_t=r[5].y),b(q,"height",W=r[5].h),b(q,"width",1)},m(j,H){it(j,t,H),wt(t,e),wt(e,i),wt(e,l),it(j,f,H),it(j,p,H),it(j,g,H),it(j,x,H),it(j,P,H),it(j,F,H),it(j,w,H),it(j,C,H),it(j,V,H),it(j,L,H),it(j,Y,H),it(j,q,H),it(j,bt,H),ce(dt,j,H),it(j,mt,H),ce(xt,j,H),it(j,Mt,H),ce(Nt,j,H),it(j,_e,H),ce(jt,j,H),et=!0,Ke||(mn=[Rt(p,"pointerdown",function(){Vt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Rt(x,"pointerdown",function(){Vt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Rt(F,"pointerdown",function(){Vt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Rt(C,"pointerdown",function(){Vt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Rt(L,"pointerdown",function(){Vt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Rt(q,"pointerdown",function(){Vt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],Ke=!0)},p(j,H){r=j,(!et||H&64&&s!==(s=r[6].x))&&b(i,"x",s),(!et||H&64&&n!==(n=r[6].y))&&b(i,"y",n),(!et||H&64&&o!==(o=r[6].w))&&b(i,"width",o),(!et||H&64&&a!==(a=r[6].h))&&b(i,"height",a),(!et||H&32&&h!==(h=r[5].x))&&b(l,"x",h),(!et||H&32&&u!==(u=r[5].y))&&b(l,"y",u),(!et||H&32&&c!==(c=r[5].w))&&b(l,"width",c),(!et||H&32&&d!==(d=r[5].h))&&b(l,"height",d),(!et||H&32&&m!==(m=r[5].x))&&b(p,"x",m),(!et||H&32&&_!==(_=r[5].y))&&b(p,"y",_),(!et||H&32&&y!==(y=r[5].w))&&b(p,"width",y),(!et||H&32&&v!==(v=r[5].h))&&b(p,"height",v),(!et||H&2)&&b(x,"style",r[1]),(!et||H&32&&E!==(E=r[5].x))&&b(x,"x",E),(!et||H&32&&R!==(R=r[5].y))&&b(x,"y",R),(!et||H&32&&S!==(S=r[5].w))&&b(x,"width",S),(!et||H&32&&M!==(M=r[5].h))&&b(x,"height",M),(!et||H&32&&U!==(U=r[5].x))&&b(F,"x",U),(!et||H&32&&I!==(I=r[5].y))&&b(F,"y",I),(!et||H&32&&A!==(A=r[5].w))&&b(F,"width",A),(!et||H&32&&D!==(D=r[5].x+r[5].w))&&b(C,"x",D),(!et||H&32&&N!==(N=r[5].y))&&b(C,"y",N),(!et||H&32&&B!==(B=r[5].h))&&b(C,"height",B),(!et||H&32&&O!==(O=r[5].x))&&b(L,"x",O),(!et||H&32&&k!==(k=r[5].y+r[5].h))&&b(L,"y",k),(!et||H&32&&X!==(X=r[5].w))&&b(L,"width",X),(!et||H&32&&pt!==(pt=r[5].x))&&b(q,"x",pt),(!et||H&32&&_t!==(_t=r[5].y))&&b(q,"y",_t),(!et||H&32&&W!==(W=r[5].h))&&b(q,"height",W);const kr={};H&32&&(kr.x=r[5].x),H&32&&(kr.y=r[5].y),H&8&&(kr.scale=r[3]),dt.$set(kr);const Ur={};H&32&&(Ur.x=r[5].x+r[5].w),H&32&&(Ur.y=r[5].y),H&8&&(Ur.scale=r[3]),xt.$set(Ur);const Gr={};H&32&&(Gr.x=r[5].x+r[5].w),H&32&&(Gr.y=r[5].y+r[5].h),H&8&&(Gr.scale=r[3]),Nt.$set(Gr);const Hr={};H&32&&(Hr.x=r[5].x),H&32&&(Hr.y=r[5].y+r[5].h),H&8&&(Hr.scale=r[3]),jt.$set(Hr)},i(j){et||(ot(dt.$$.fragment,j),ot(xt.$$.fragment,j),ot(Nt.$$.fragment,j),ot(jt.$$.fragment,j),et=!0)},o(j){gt(dt.$$.fragment,j),gt(xt.$$.fragment,j),gt(Nt.$$.fragment,j),gt(jt.$$.fragment,j),et=!1},d(j){j&&(rt(t),rt(f),rt(p),rt(g),rt(x),rt(P),rt(F),rt(w),rt(C),rt(V),rt(L),rt(Y),rt(q),rt(bt),rt(mt),rt(Mt),rt(_e)),de(dt,j),de(xt,j),de(Nt,j),de(jt,j),Ke=!1,$e(mn)}}}function y0(r){let t,e;return t=new Ta({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[g0,({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(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&16&&(n.svgEl=i[4]),s&12394&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function _0(r,t,e){let i,s,{shape:n}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const u=(m,_,y)=>{const v=m.geometry.bounds;let[g,x]=[v.minX,v.minY],[E,R]=[v.maxX,v.maxY];const[S,M]=y;if(_==="SHAPE")g+=S,E+=S,x+=M,R+=M;else{switch(_){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{x+=M;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=M;break}}switch(_){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=S;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{E+=S;break}}}const P=Math.min(g,E),F=Math.min(x,R),U=Math.abs(E-g),I=Math.abs(R-x);return{...m,geometry:{x:P,y:F,w:U,h:I,bounds:{minX:P,minY:F,maxX:P+U,maxY:F+I}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){Ce.call(this,r,m)}function f(m){Ce.call(this,r,m)}function p(m){Ce.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,n=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=n.geometry),r.$$.dirty&40&&e(6,s=In(i.bounds,2/l))},[n,o,a,l,h,i,s,u,c,d,f,p]}class v0 extends De{constructor(t){super(),Ne(this,t,_0,y0,le,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var ec=Object.prototype.hasOwnProperty;function Ia(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--&&Ia(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(ec.call(r,e)&&++i&&!ec.call(t,e)||!(e in t)||!Ia(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const x0=12,b0=(r,t)=>r.polygons.reduce((e,i,s)=>{const n=i.rings.reduce((o,a,l)=>{const h=a.points.map((u,c)=>{const d=c===a.points.length-1?a.points[0]:a.points[c+1],f=(u[0]+d[0])/2,p=(u[1]+d[1])/2,m=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>x0/t;return{point:[f,p],visible:m,elementIdx:s,ringIdx:l,pointIdx:c}});return[...o,...h]},[]);return[...e,...n]},[]);function Ra(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function rc(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function ic(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function sc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function Ma(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Pa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function nc(r){let t,e,i,s;return{c(){t=Z("circle"),b(t,"cx",e=r[29][0]),b(t,"cy",i=r[29][1]),b(t,"r",s=Ds/r[3]),b(t,"class","svelte-1vxo6dc")},m(n,o){it(n,t,o)},p(n,o){o[0]&1088&&e!==(e=n[29][0])&&b(t,"cx",e),o[0]&1088&&i!==(i=n[29][1])&&b(t,"cy",i),o[0]&8&&s!==(s=Ds/n[3])&&b(t,"r",s)},d(n){n&&rt(t)}}}function oc(r){let t,e,i,s,n,o,a,l,h,u;return{c(){t=Z("mask"),e=Z("rect"),a=Z("circle"),b(e,"x",i=r[9].x),b(e,"y",s=r[9].y),b(e,"width",n=r[9].w),b(e,"height",o=r[9].h),b(e,"class","svelte-1vxo6dc"),b(a,"cx",l=r[29][0]),b(a,"cy",h=r[29][1]),b(a,"r",u=Ds/r[3]),b(a,"class","svelte-1vxo6dc"),b(t,"id",`${r[18]}-${r[32]}-inner`),b(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(c,d){it(c,t,d),wt(t,e),wt(t,a)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&b(e,"x",i),d[0]&512&&s!==(s=c[9].y)&&b(e,"y",s),d[0]&512&&n!==(n=c[9].w)&&b(e,"width",n),d[0]&512&&o!==(o=c[9].h)&&b(e,"height",o),d[0]&1088&&l!==(l=c[29][0])&&b(a,"cx",l),d[0]&1088&&h!==(h=c[29][1])&&b(a,"cy",h),d[0]&8&&u!==(u=Ds/c[3])&&b(a,"r",u)},d(c){c&&rt(t)}}}function ac(r){let t,e;function i(...s){return r[19](r[32],r[35],r[37],...s)}return t=new Wi({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(){Vt(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(){be(t.$$.fragment)},m(s,n){ce(t,s,n),e=!0},p(s,n){r=s;const o={};n[0]&32&&(o.x=r[29][0]),n[0]&32&&(o.y=r[29][1]),n[0]&8&&(o.scale=r[3]),n[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(s){e||(ot(t.$$.fragment,s),e=!0)},o(s){gt(t.$$.fragment,s),e=!1},d(s){de(t,s)}}}function lc(r){let t,e,i=ke(r[33].points),s=[];for(let o=0;o<i.length;o+=1)s[o]=ac(sc(r,i,o));const n=o=>gt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Fe()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);it(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=ke(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=sc(o,i,l);s[l]?(s[l].p(h,a),ot(s[l],1)):(s[l]=ac(h),s[l].c(),ot(s[l],1),s[l].m(t.parentNode,t))}for(Ie(),l=i.length;l<s.length;l+=1)n(l);Re()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)ot(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)gt(s[a]);e=!1},d(o){o&&rt(t),mi(s,o)}}}function hc(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v=r[6]!==void 0&&!r[7]&&nc(Pa(r)),g=r[6]!==void 0&&!r[7]&&oc(Ma(r)),x=ke(r[30].rings),E=[];for(let S=0;S<x.length;S+=1)E[S]=lc(ic(r,x,S));const R=S=>gt(E[S],1,1,()=>{E[S]=null});return{c(){t=Z("g"),e=Z("defs"),i=Z("mask"),s=Z("rect"),h=Z("path"),v&&v.c(),g&&g.c(),c=Z("path"),f=Z("path");for(let S=0;S<E.length;S+=1)E[S].c();b(s,"x",n=r[9].x),b(s,"y",o=r[9].y),b(s,"width",a=r[9].w),b(s,"height",l=r[9].h),b(s,"class","svelte-1vxo6dc"),b(h,"d",u=Ze(r[30])),b(h,"class","svelte-1vxo6dc"),b(i,"id",`${r[18]}-${r[32]}-outer`),b(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),b(c,"class","a9s-outer"),b(c,"mask",`url(#${r[18]}-${r[32]}-outer)`),b(c,"fill-rule","evenodd"),b(c,"d",d=Ze(r[30])),b(f,"class","a9s-inner"),b(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),b(f,"style",r[1]),b(f,"fill-rule","evenodd"),b(f,"d",p=Ze(r[30]))},m(S,M){it(S,t,M),wt(t,e),wt(e,i),wt(i,s),wt(i,h),v&&v.m(i,null),g&&g.m(e,null),wt(t,c),wt(t,f);for(let P=0;P<E.length;P+=1)E[P]&&E[P].m(t,null);m=!0,_||(y=[Rt(c,"pointerup",r[13]),Rt(c,"pointerdown",function(){Vt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Rt(f,"pointerup",r[13]),Rt(f,"pointerdown",function(){Vt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],_=!0)},p(S,M){if(r=S,(!m||M[0]&512&&n!==(n=r[9].x))&&b(s,"x",n),(!m||M[0]&512&&o!==(o=r[9].y))&&b(s,"y",o),(!m||M[0]&512&&a!==(a=r[9].w))&&b(s,"width",a),(!m||M[0]&512&&l!==(l=r[9].h))&&b(s,"height",l),(!m||M[0]&32&&u!==(u=Ze(r[30])))&&b(h,"d",u),r[6]!==void 0&&!r[7]?v?v.p(Pa(r),M):(v=nc(Pa(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(Ma(r),M):(g=oc(Ma(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||M[0]&32&&d!==(d=Ze(r[30])))&&b(c,"d",d),(!m||M[0]&2)&&b(f,"style",r[1]),(!m||M[0]&32&&p!==(p=Ze(r[30])))&&b(f,"d",p),M[0]&268491048){x=ke(r[30].rings);let P;for(P=0;P<x.length;P+=1){const F=ic(r,x,P);E[P]?(E[P].p(F,M),ot(E[P],1)):(E[P]=lc(F),E[P].c(),ot(E[P],1),E[P].m(t,null))}for(Ie(),P=x.length;P<E.length;P+=1)R(P);Re()}},i(S){if(!m){for(let M=0;M<x.length;M+=1)ot(E[M]);m=!0}},o(S){E=E.filter(Boolean);for(let M=0;M<E.length;M+=1)gt(E[M]);m=!1},d(S){S&&rt(t),v&&v.d(),g&&g.d(),mi(E,S),_=!1,$e(y)}}}function uc(r){let t,e;return t=new Yu({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Vt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&1088&&(n.x=r[29][0]),s[0]&1088&&(n.y=r[29][1]),s[0]&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function E0(r){let t,e,i,s=ke(r[5].polygons),n=[];for(let l=0;l<s.length;l+=1)n[l]=hc(rc(r,s,l));const o=l=>gt(n[l],1,1,()=>{n[l]=null});let a=r[6]!==void 0&&!r[7]&&uc(Ra(r));return{c(){for(let l=0;l<n.length;l+=1)n[l].c();t=Oe(),a&&a.c(),e=Fe()},m(l,h){for(let u=0;u<n.length;u+=1)n[u]&&n[u].m(l,h);it(l,t,h),a&&a.m(l,h),it(l,e,h),i=!0},p(l,h){if(h[0]&268763114){s=ke(l[5].polygons);let u;for(u=0;u<s.length;u+=1){const c=rc(l,s,u);n[u]?(n[u].p(c,h),ot(n[u],1)):(n[u]=hc(c),n[u].c(),ot(n[u],1),n[u].m(t.parentNode,t))}for(Ie(),u=s.length;u<n.length;u+=1)o(u);Re()}l[6]!==void 0&&!l[7]?a?(a.p(Ra(l),h),h[0]&192&&ot(a,1)):(a=uc(Ra(l)),a.c(),ot(a,1),a.m(e.parentNode,e)):a&&(Ie(),gt(a,1,1,()=>{a=null}),Re())},i(l){if(!i){for(let h=0;h<s.length;h+=1)ot(n[h]);ot(a),i=!0}},o(l){n=n.filter(Boolean);for(let h=0;h<n.length;h+=1)gt(n[h]);gt(a),i=!1},d(l){l&&(rt(t),rt(e)),mi(n,l),a&&a.d(l)}}}function w0(r){let t,e;return t=new Ta({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[E0,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&1&&(n.shape=i[0]),s[0]&4&&(n.transform=i[2]),s[0]&16&&(n.svgEl=i[4]),s[0]&268437482|s[1]&128&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}const T0=250,A0=1e3,Ds=4.5;function S0(r,t,e){let i,s,n;const o=Xr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:u=1}=t,{svgEl:c}=t,d,f=!1,p,m=[];const _=()=>e(7,f=!0),y=()=>e(7,f=!1),v=C=>{if(m.length>0||!s.some(k=>k.visible)){e(6,d=void 0);return}const[D,N]=h.elementToImage(C.offsetX,C.offsetY),B=k=>Math.pow(k[0]-D,2)+Math.pow(k[1]-N,2),V=Cy(i).reduce((k,X)=>B(X)<B(k)?X:k),L=s.filter(k=>k.visible).reduce((k,X)=>B(X.point)<B(k.point)?X:k),O=Math.pow(A0/u,2);B(V)<O||B(L.point)<O?e(6,d=s.indexOf(L)):e(6,d=void 0)},g=()=>{document.activeElement!==c&&c.focus()},x=()=>{e(8,m=[]),g()},E=C=>{e(7,f=!0),C.preventDefault(),C.stopPropagation(),p=performance.now()},R=(C,D,N)=>B=>{if(!p||Cr||performance.now()-p>T0)return;const V=O=>O.polygon===C&&O.ring===D&&O.point===N,L=m.some(V);B.metaKey||B.ctrlKey||B.shiftKey?L?e(8,m=m.filter(O=>!V(O))):e(8,m=[...m,{polygon:C,ring:D,point:N}]):L&&m.length>1?e(8,m=[{polygon:C,ring:D,point:N}]):L?e(8,m=[]):e(8,m=[{polygon:C,ring:D,point:N}]),g()},S=(C,D,N)=>{g();const B=C.geometry.polygons;let V;if(D==="SHAPE")V=B.map(L=>{const O=L.rings.map((X,Y)=>({points:X.points.map((q,pt)=>[q[0]+N[0],q[1]+N[1]])})),k=Ue(O[0].points);return{rings:O,bounds:k}});else{const[L,O,k,X]=D.split("-").map(Y=>parseInt(Y));V=B.map((Y,q)=>{if(q===O){const pt=Y.rings.map((W,bt)=>bt===k?{points:W.points.map((dt,mt)=>mt===X?[dt[0]+N[0],dt[1]+N[1]]:dt)}:W),_t=Ue(pt[0].points);return{rings:pt,bounds:_t}}else return Y})}return{...C,geometry:{polygons:V,bounds:fa(V)}}},M=C=>async D=>{D.stopPropagation();const N=s[C],B=i.polygons.map((L,O)=>{if(O===N.elementIdx){const k=L.rings.map((Y,q)=>q===N.ringIdx?{points:[...Y.points.slice(0,N.pointIdx+1),N.point,...Y.points.slice(N.pointIdx+1)]}:Y),X=Ue(k[0].points);return{rings:k,bounds:X}}else return L});o("change",{...a,geometry:{polygons:B,bounds:fa(B)}}),await bu();const V=[...document.querySelectorAll(".a9s-handle")][C+1];if(V!=null&&V.firstChild){const L=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:D.clientX,clientY:D.clientY,pointerId:D.pointerId,pointerType:D.pointerType,isPrimary:D.isPrimary,buttons:D.buttons});V.firstChild.dispatchEvent(L)}},P=()=>{const C=i.polygons.map((D,N)=>{if(m.some(B=>B.polygon===N)){const B=D.rings.map((L,O)=>m.some(k=>k.polygon===N&&k.ring===O)&&L.points.length>3?{points:L.points.filter((k,X)=>!m.some(Y=>Y.polygon===N&&Y.ring===O&&Y.point===X))}:L),V=Ue(B[0].points);return{rings:B,bounds:V}}else return D});!Ia(i.polygons,C)&&(o("change",{...a,geometry:{polygons:C,bounds:fa(C)}}),e(8,m=[]))};gi(()=>{if(Cr)return;const C=D=>{(D.key==="Delete"||D.key==="Backspace")&&(D.preventDefault(),P())};return c.addEventListener("pointermove",v),c.addEventListener("keydown",C),()=>{c.removeEventListener("pointermove",v),c.removeEventListener("keydown",C)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(C,D,N,{polygon:B,ring:V,point:L})=>B===C&&V===D&&L===N;function I(C){Ce.call(this,r,C)}function A(C){Ce.call(this,r,C)}function w(C){Ce.call(this,r,C)}return r.$$set=C=>{"shape"in C&&e(0,a=C.shape),"computedStyle"in C&&e(1,l=C.computedStyle),"transform"in C&&e(2,h=C.transform),"viewportScale"in C&&e(3,u=C.viewportScale),"svgEl"in C&&e(4,c=C.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,s=Cr?[]:b0(i,u)),r.$$.dirty[0]&40&&e(9,n=In(i.bounds,Ds/u))},[a,l,h,u,c,i,d,f,m,n,s,_,y,x,E,R,S,M,F,U,I,A,w]}class C0 extends De{constructor(t){super(),Ne(this,t,S0,w0,le,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const cc=new Map([[Tt.RECTANGLE,v0],[Tt.POLYGON,m0],[Tt.MULTIPOLYGLON,C0]]),dc=r=>cc.get(r.type),fc=(r,t)=>cc.set(r,t);function I0(r,t,e){let i;const s=Xr();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:u}=t,c;return gi(()=>(e(6,c=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:u,svgEl:l.closest("svg")}})),c.$on("change",d=>{c.$$set({shape:d.detail}),s("change",d.detail)}),c.$on("grab",d=>s("grab",d.detail)),c.$on("release",d=>s("release",d.detail)),()=>{c.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,n=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,u=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=Os(n,a)),r.$$.dirty&65&&n&&(c==null||c.$set({shape:n.target.selector})),r.$$.dirty&80&&c&&c.$set({transform:h}),r.$$.dirty&96&&c&&c.$set({viewportScale:u}),r.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[n,o,a,l,h,u,c,i]}class R0 extends De{constructor(t){super(),Ne(this,t,I0,null,le,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function M0(r,t,e){const i=Xr();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return gi(()=>{const u=n.closest("svg"),c=[],d=(f,p,m)=>{u==null||u.addEventListener(f,p,m),c.push(()=>u==null?void 0:u.removeEventListener(f,p,m))};return e(5,h=new o({target:n,props:{addEventListener:d,drawingMode:s,transform:a,viewportScale:l}})),h.$on("create",f=>i("create",f.detail)),()=>{c.forEach(f=>f()),h.$destroy()}}),r.$$set=u=>{"drawingMode"in u&&e(0,s=u.drawingMode),"target"in u&&e(1,n=u.target),"tool"in u&&e(2,o=u.tool),"transform"in u&&e(3,a=u.transform),"viewportScale"in u&&e(4,l=u.viewportScale)},r.$$.update=()=>{r.$$.dirty&40&&h&&h.$set({transform:a}),r.$$.dirty&48&&h&&h.$set({viewportScale:l})},[s,n,o,a,l,h]}class P0 extends De{constructor(t){super(),Ne(this,t,M0,null,le,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function pc(r){let t,e,i,s,n,o,a,l,h,u;return{c(){t=Z("defs"),e=Z("mask"),i=Z("rect"),l=Z("rect"),h=Z("rect"),u=Z("rect"),b(i,"class","rect-mask-bg svelte-1a76qe7"),b(i,"x",s=r[1]-r[5]),b(i,"y",n=r[2]-r[5]),b(i,"width",o=r[3]+2*r[5]),b(i,"height",a=r[4]+2*r[5]),b(l,"class","rect-mask-fg svelte-1a76qe7"),b(l,"x",r[1]),b(l,"y",r[2]),b(l,"width",r[3]),b(l,"height",r[4]),b(e,"id",r[6]),b(e,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),b(h,"class","a9s-outer"),b(h,"mask",`url(#${r[6]})`),b(h,"x",r[1]),b(h,"y",r[2]),b(h,"width",r[3]),b(h,"height",r[4]),b(u,"class","a9s-inner"),b(u,"x",r[1]),b(u,"y",r[2]),b(u,"width",r[3]),b(u,"height",r[4])},m(c,d){it(c,t,d),wt(t,e),wt(e,i),wt(e,l),it(c,h,d),it(c,u,d)},p(c,d){d&34&&s!==(s=c[1]-c[5])&&b(i,"x",s),d&36&&n!==(n=c[2]-c[5])&&b(i,"y",n),d&40&&o!==(o=c[3]+2*c[5])&&b(i,"width",o),d&48&&a!==(a=c[4]+2*c[5])&&b(i,"height",a),d&2&&b(l,"x",c[1]),d&4&&b(l,"y",c[2]),d&8&&b(l,"width",c[3]),d&16&&b(l,"height",c[4]),d&2&&b(h,"x",c[1]),d&4&&b(h,"y",c[2]),d&8&&b(h,"width",c[3]),d&16&&b(h,"height",c[4]),d&2&&b(u,"x",c[1]),d&4&&b(u,"y",c[2]),d&8&&b(u,"width",c[3]),d&16&&b(u,"height",c[4])},d(c){c&&(rt(t),rt(h),rt(u))}}}function O0(r){let t,e=r[0]&&pc(r);return{c(){t=Z("g"),e&&e.c(),b(t,"class","a9s-annotation a9s-rubberband")},m(i,s){it(i,t,s),e&&e.m(t,null)},p(i,[s]){i[0]?e?e.p(i,s):(e=pc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Dt,o:Dt,d(i){i&&rt(t),e&&e.d()}}}function N0(r,t,e){let i;const s=Xr();let{addEventListener:n}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,u,c,d,f,p,m;const _=E=>{const R=E;h=performance.now(),o==="drag"&&(e(0,u=a.elementToImage(R.offsetX,R.offsetY)),c=u,e(1,d=u[0]),e(2,f=u[1]),e(3,p=1),e(4,m=1))},y=E=>{const R=E;u&&(c=a.elementToImage(R.offsetX,R.offsetY),e(1,d=Math.min(c[0],u[0])),e(2,f=Math.min(c[1],u[1])),e(3,p=Math.abs(c[0]-u[0])),e(4,m=Math.abs(c[1]-u[1])))},v=E=>{const R=E,S=performance.now()-h;if(o==="click"){if(S>300)return;u?g():(e(0,u=a.elementToImage(R.offsetX,R.offsetY)),c=u,e(1,d=u[0]),e(2,f=u[1]),e(3,p=1),e(4,m=1))}else u&&(S>300||p*m>100?(R.stopPropagation(),g()):(e(0,u=void 0),c=void 0))},g=()=>{if(p*m>15){const E={type:Tt.RECTANGLE,geometry:{bounds:{minX:d,minY:f,maxX:d+p,maxY:f+m},x:d,y:f,w:p,h:m}};s("create",E)}e(0,u=void 0),c=void 0};gi(()=>{n("pointerdown",_),n("pointermove",y),n("pointerup",v,!0)});const x=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=E=>{"addEventListener"in E&&e(7,n=E.addEventListener),"drawingMode"in E&&e(8,o=E.drawingMode),"transform"in E&&e(9,a=E.transform),"viewportScale"in E&&e(10,l=E.viewportScale)},r.$$.update=()=>{r.$$.dirty&1024&&e(5,i=2/l)},[u,d,f,p,m,i,x,n,o,a,l]}class D0 extends De{constructor(t){super(),Ne(this,t,N0,O0,le,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function Oa(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function mc(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m=r[1]&&gc(r);return{c(){t=Z("defs"),e=Z("mask"),i=Z("rect"),l=Z("polygon"),u=Z("polygon"),d=Z("polygon"),m&&m.c(),p=Fe(),b(i,"x",s=r[3].x),b(i,"y",n=r[3].y),b(i,"width",o=r[3].w),b(i,"height",a=r[3].h),b(i,"class","svelte-18wrg3t"),b(l,"points",h=r[19]),b(l,"class","svelte-18wrg3t"),b(e,"id",r[5]),b(e,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),b(u,"class","a9s-outer"),b(u,"mask",`url(#${r[5]})`),b(u,"points",c=r[19]),b(d,"class","a9s-inner"),b(d,"points",f=r[19])},m(_,y){it(_,t,y),wt(t,e),wt(e,i),wt(e,l),it(_,u,y),it(_,d,y),m&&m.m(_,y),it(_,p,y)},p(_,y){y&8&&s!==(s=_[3].x)&&b(i,"x",s),y&8&&n!==(n=_[3].y)&&b(i,"y",n),y&8&&o!==(o=_[3].w)&&b(i,"width",o),y&8&&a!==(a=_[3].h)&&b(i,"height",a),y&4&&h!==(h=_[19])&&b(l,"points",h),y&4&&c!==(c=_[19])&&b(u,"points",c),y&4&&f!==(f=_[19])&&b(d,"points",f),_[1]?m?m.p(_,y):(m=gc(_),m.c(),m.m(p.parentNode,p)):m&&(m.d(1),m=null)},d(_){_&&(rt(t),rt(u),rt(d),rt(p)),m&&m.d(_)}}}function gc(r){let t,e,i;return{c(){t=Z("circle"),b(t,"class","a9s-handle svelte-18wrg3t"),b(t,"cx",e=r[0][0][0]),b(t,"cy",i=r[0][0][1]),b(t,"r",r[4])},m(s,n){it(s,t,n)},p(s,n){n&1&&e!==(e=s[0][0][0])&&b(t,"cx",e),n&1&&i!==(i=s[0][0][1])&&b(t,"cy",i),n&16&&b(t,"r",s[4])},d(s){s&&rt(t)}}}function L0(r){let t,e=r[3]&&mc(Oa(r));return{c(){t=Z("g"),e&&e.c(),b(t,"class","a9s-annotation a9s-rubberband")},m(i,s){it(i,t,s),e&&e.m(t,null)},p(i,[s]){i[3]?e?e.p(Oa(i),s):(e=mc(Oa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Dt,o:Dt,d(i){i&&rt(t),e&&e.d()}}}const B0=20,F0=1500;function k0(r,t,e){let i,s,n;const o=Xr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:u=1}=t,c,d=[],f,p,m=!1;const _=R=>{const S=R,{timeStamp:M,offsetX:P,offsetY:F}=S;if(c={timeStamp:M,offsetX:P,offsetY:F},l==="drag"&&d.length===0){const U=h.elementToImage(S.offsetX,S.offsetY);d.push(U),e(10,f=U)}},y=R=>{const S=R;if(p&&clearTimeout(p),d.length>0){if(e(10,f=h.elementToImage(S.offsetX,S.offsetY)),d.length>2){const M=wa(f,d[0])*u;e(1,m=M<B0)}S.pointerType==="touch"&&(p=setTimeout(()=>{g()},F0))}},v=R=>{const S=R;if(p&&clearTimeout(p),l==="click"){const M=S.timeStamp-c.timeStamp,P=wa([c.offsetX,c.offsetY],[S.offsetX,S.offsetY]);if(M>300||P>15)return;if(m)x();else if(d.length===0){const F=h.elementToImage(S.offsetX,S.offsetY);d.push(F),e(10,f=F)}else d.push(f)}else{if(d.length===1&&wa(d[0],f)<=4){e(0,d=[]),e(10,f=void 0);return}S.stopImmediatePropagation(),m?x():d.push(f)}},g=()=>{if(!f)return;const R=d.slice(0,-1);if(R.length<3)return;const S={type:Tt.POLYGON,geometry:{bounds:Ue(d),points:R}};ua(S)>4&&(e(0,d=[]),e(10,f=void 0),o("create",S))},x=()=>{const R={type:Tt.POLYGON,geometry:{bounds:Ue(d),points:[...d]}};e(0,d=[]),e(10,f=void 0),o("create",R)};gi(()=>{a("pointerdown",_,!0),a("pointermove",y),a("pointerup",v,!0),a("dblclick",g,!0)});const E=`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,u=R.viewportScale)},r.$$.update=()=>{r.$$.dirty&512&&e(4,i=4/u),r.$$.dirty&1027&&e(2,s=f?m?d:[...d,f]:[]),r.$$.dirty&516&&e(3,n=s.length>0?In(Ue(s),2/u):void 0)},[d,m,s,n,i,E,a,l,h,u,f]}class U0 extends De{constructor(t){super(),Ne(this,t,k0,L0,le,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Na=new Map([["rectangle",{tool:D0}],["polygon",{tool:U0}]]),Rn=()=>[...Na.keys()],Mn=r=>Na.get(r),yc=(r,t,e={})=>Na.set(r,{tool:t,opts:e});function G0(r){let t,e,i,s,n;return{c(){t=Z("g"),e=Z("ellipse"),s=Z("ellipse"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"cx",r[2]),b(e,"cy",r[3]),b(e,"rx",r[4]),b(e,"ry",r[5]),b(s,"class","a9s-inner"),b(s,"style",r[1]),b(s,"cx",r[2]),b(s,"cy",r[3]),b(s,"rx",r[4]),b(s,"ry",r[5]),b(t,"class","a9s-annotation"),b(t,"data-id",n=r[0].id)},m(o,a){it(o,t,a),wt(t,e),wt(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&b(t,"data-id",n)},i:Dt,o:Dt,d(o){o&&rt(t)}}}function H0(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:u}=n;return r.$$set=c=>{"annotation"in c&&e(0,s=c.annotation),"geom"in c&&e(6,n=c.geom),"style"in c&&e(7,o=c.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=Os(s,o))},[s,i,a,l,h,u,n,o]}class $0 extends De{constructor(t){super(),Ne(this,t,H0,G0,le,{annotation:0,geom:6,style:7})}}function _c(r,t,e){const i=r.slice();return i[5]=t[e],i}function vc(r){let t,e,i;return{c(){t=Z("path"),i=Z("path"),b(t,"class","a9s-outer"),b(t,"style",e=r[1]?"display:none;":void 0),b(t,"fill-rule","evenodd"),b(t,"d",Ze(r[5])),b(i,"class","a9s-inner"),b(i,"style",r[1]),b(i,"fill-rule","evenodd"),b(i,"d",Ze(r[5]))},m(s,n){it(s,t,n),it(s,i,n)},p(s,n){n&2&&e!==(e=s[1]?"display:none;":void 0)&&b(t,"style",e),n&2&&b(i,"style",s[1])},d(s){s&&(rt(t),rt(i))}}}function X0(r){let t,e,i=ke(r[2]),s=[];for(let n=0;n<i.length;n+=1)s[n]=vc(_c(r,i,n));return{c(){t=Z("g");for(let n=0;n<s.length;n+=1)s[n].c();b(t,"class","a9s-annotation"),b(t,"data-id",e=r[0].id)},m(n,o){it(n,t,o);for(let a=0;a<s.length;a+=1)s[a]&&s[a].m(t,null)},p(n,[o]){if(o&6){i=ke(n[2]);let a;for(a=0;a<i.length;a+=1){const l=_c(n,i,a);s[a]?s[a].p(l,o):(s[a]=vc(l),s[a].c(),s[a].m(t,null))}for(;a<s.length;a+=1)s[a].d(1);s.length=i.length}o&1&&e!==(e=n[0].id)&&b(t,"data-id",e)},i:Dt,o:Dt,d(n){n&&rt(t),mi(s,n)}}}function V0(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{polygons:a}=n;return r.$$set=l=>{"annotation"in l&&e(0,s=l.annotation),"geom"in l&&e(3,n=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=Os(s,o))},[s,i,a,n,o]}class z0 extends De{constructor(t){super(),Ne(this,t,V0,X0,le,{annotation:0,geom:3,style:4})}}function Y0(r){let t,e,i,s,n;return{c(){t=Z("g"),e=Z("polygon"),s=Z("polygon"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"points",r[2].map(W0).join(" ")),b(s,"class","a9s-inner"),b(s,"style",r[1]),b(s,"points",r[2].map(j0).join(" ")),b(t,"class","a9s-annotation"),b(t,"data-id",n=r[0].id)},m(o,a){it(o,t,a),wt(t,e),wt(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&b(t,"data-id",n)},i:Dt,o:Dt,d(o){o&&rt(t)}}}const W0=r=>r.join(","),j0=r=>r.join(",");function q0(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{points:a}=n;return r.$$set=l=>{"annotation"in l&&e(0,s=l.annotation),"geom"in l&&e(3,n=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=Os(s,o))},[s,i,a,n,o]}class K0 extends De{constructor(t){super(),Ne(this,t,q0,Y0,le,{annotation:0,geom:3,style:4})}}function Z0(r){let t,e,i,s,n;return{c(){t=Z("g"),e=Z("rect"),s=Z("rect"),b(e,"class","a9s-outer"),b(e,"style",i=r[5]?"display:none;":void 0),b(e,"x",r[4]),b(e,"y",r[3]),b(e,"width",r[2]),b(e,"height",r[1]),b(s,"class","a9s-inner"),b(s,"style",r[5]),b(s,"x",r[4]),b(s,"y",r[3]),b(s,"width",r[2]),b(s,"height",r[1]),b(t,"class","a9s-annotation"),b(t,"data-id",n=r[0].id)},m(o,a){it(o,t,a),wt(t,e),wt(t,s)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&b(e,"style",i),a&16&&b(e,"x",o[4]),a&8&&b(e,"y",o[3]),a&4&&b(e,"width",o[2]),a&2&&b(e,"height",o[1]),a&32&&b(s,"style",o[5]),a&16&&b(s,"x",o[4]),a&8&&b(s,"y",o[3]),a&4&&b(s,"width",o[2]),a&2&&b(s,"height",o[1]),a&1&&n!==(n=o[0].id)&&b(t,"data-id",n)},i:Dt,o:Dt,d(o){o&&rt(t)}}}function Q0(r,t,e){let i,s,n,o,a,{annotation:l}=t,{geom:h}=t,{style:u}=t;return r.$$set=c=>{"annotation"in c&&e(0,l=c.annotation),"geom"in c&&e(6,h=c.geom),"style"in c&&e(7,u=c.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=Os(l,u)),r.$$.dirty&64&&e(4,{x:s,y:n,w:o,h:a}=h,s,(e(3,n),e(6,h)),(e(2,o),e(6,h)),(e(1,a),e(6,h)))},[l,a,o,n,s,i,h,u]}class J0 extends De{constructor(t){super(),Ne(this,t,Q0,Z0,le,{annotation:0,geom:6,style:7})}}const tv=r=>({elementToImage:(t,e)=>{const i=r.getBoundingClientRect(),s=r.createSVGPoint();s.x=t+i.x,s.y=e+i.y;const{x:n,y:o}=s.matrixTransform(r.getScreenCTM().inverse());return[n,o]}}),ev=250,rv=(r,t)=>{const e=Xr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<ev){const{x:n,y:o}=xc(s,r),a=t.getAt(n,o);a?e("click",{originalEvent:s,annotation:a}):e("click",{originalEvent:s})}}}},xc=(r,t)=>{const e=t.createSVGPoint(),i=t.getBoundingClientRect(),s=r.clientX-i.x,n=r.clientY-i.y,{left:o,top:a}=t.getBoundingClientRect();return e.x=s+o,e.y=n+a,e.matrixTransform(t.getScreenCTM().inverse())};function bc(r,t,e){const i=r.slice();i[39]=t[e];const s=i[24](i[39].target.selector);return i[40]=s,i}function Ec(r,t,e){const i=r.slice();return i[43]=t[e],i}function Da(r){const t=r.slice(),e=t[43].target.selector;return t[46]=e,t}function wc(r){let t=r[43],e,i,s=Tc(r);return{c(){s.c(),e=Fe()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&65536&&le(t,t=n[43])?(Ie(),gt(s,1,1,Dt),Re(),s=Tc(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){gt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function iv(r){let t,e;return t=new z0({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function sv(r){let t,e;return t=new K0({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function nv(r){let t,e;return t=new J0({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function ov(r){var t;let e,i;return e=new $0({props:{annotation:r[43],geom:(t=r[46])==null?void 0:t.geometry,style:r[1]}}),{c(){be(e.$$.fragment)},m(s,n){ce(e,s,n),i=!0},p(s,n){var o;const a={};n[0]&65536&&(a.annotation=s[43]),n[0]&65536&&(a.geom=(o=s[46])==null?void 0:o.geometry),n[0]&2&&(a.style=s[1]),e.$set(a)},i(s){i||(ot(e.$$.fragment,s),i=!0)},o(s){gt(e.$$.fragment,s),i=!1},d(s){de(e,s)}}}function Tc(r){let t,e,i,s;const n=[ov,nv,sv,iv],o=[];function a(l,h){var u,c,d,f;return((u=l[46])==null?void 0:u.type)===Tt.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===Tt.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===Tt.POLYGON?2:((f=l[46])==null?void 0:f.type)===Tt.MULTIPOLYGLON?3:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=Fe()},m(l,h){~t&&o[t].m(l,h),it(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(Ie(),gt(o[u],1,1,()=>{o[u]=null}),Re()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),ot(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(ot(e),s=!0)},o(l){gt(e),s=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function Ac(r){let t=ze(r[43])&&!r[9](r[43]),e,i,s=t&&wc(Da(r));return{c(){s&&s.c(),e=Fe()},m(n,o){s&&s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&66048&&(t=ze(n[43])&&!n[9](n[43])),t?s?(s.p(Da(n),o),o[0]&66048&&ot(s,1)):(s=wc(Da(n)),s.c(),ot(s,1),s.m(e.parentNode,e)):s&&(Ie(),gt(s,1,1,()=>{s=null}),Re())},i(n){i||(ot(s),i=!0)},o(n){gt(s),i=!1},d(n){n&&rt(e),s&&s.d(n)}}}function Sc(r){let t,e,i,s;const n=[lv,av],o=[];function a(l,h){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=Fe()},m(l,h){~t&&o[t].m(l,h),it(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(Ie(),gt(o[u],1,1,()=>{o[u]=null}),Re()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),ot(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(ot(e),s=!0)},o(l){gt(e),s=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function av(r){let t=`${r[2]}-${r[5]}`,e,i,s=Cc(r);return{c(){s.c(),e=Fe()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&36&&le(t,t=`${n[2]}-${n[5]}`)?(Ie(),gt(s,1,1,Dt),Re(),s=Cc(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){gt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function lv(r){let t,e,i=ke(r[8]),s=[];for(let o=0;o<i.length;o+=1)s[o]=Mc(bc(r,i,o));const n=o=>gt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Fe()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);it(o,t,a),e=!0},p(o,a){if(a[0]&21107010){i=ke(o[8]);let l;for(l=0;l<i.length;l+=1){const h=bc(o,i,l);s[l]?(s[l].p(h,a),ot(s[l],1)):(s[l]=Mc(h),s[l].c(),ot(s[l],1),s[l].m(t.parentNode,t))}for(Ie(),l=i.length;l<s.length;l+=1)n(l);Re()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)ot(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)gt(s[a]);e=!1},d(o){o&&rt(t),mi(s,o)}}}function Cc(r){let t,e;return t=new P0({props:{target:r[6],tool:r[14],drawingMode:r[13],transform:r[12],viewportScale:r[17]}}),t.$on("create",r[21]),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){const n={};s[0]&64&&(n.target=i[6]),s[0]&16384&&(n.tool=i[14]),s[0]&8192&&(n.drawingMode=i[13]),s[0]&4096&&(n.transform=i[12]),s[0]&131072&&(n.viewportScale=i[17]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function Ic(r){let t=r[39].id,e,i,s=Rc(r);return{c(){s.c(),e=Fe()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&256&&le(t,t=n[39].id)?(Ie(),gt(s,1,1,Dt),Re(),s=Rc(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){gt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function Rc(r){let t,e;return t=new R0({props:{target:r[6],editor:r[24](r[39].target.selector),annotation:r[39],style:r[1],transform:r[12],viewportScale:r[17]}}),t.$on("change",function(){Vt(r[22](r[39]))&&r[22](r[39]).apply(this,arguments)}),{c(){be(t.$$.fragment)},m(i,s){ce(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&64&&(n.target=r[6]),s[0]&256&&(n.editor=r[24](r[39].target.selector)),s[0]&256&&(n.annotation=r[39]),s[0]&2&&(n.style=r[1]),s[0]&4096&&(n.transform=r[12]),s[0]&131072&&(n.viewportScale=r[17]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){gt(t.$$.fragment,i),e=!1},d(i){de(t,i)}}}function Mc(r){let t,e,i=r[40]&&Ic(r);return{c(){i&&i.c(),t=Fe()},m(s,n){i&&i.m(s,n),it(s,t,n),e=!0},p(s,n){s[40]?i?(i.p(s,n),n[0]&256&&ot(i,1)):(i=Ic(s),i.c(),ot(i,1),i.m(t.parentNode,t)):i&&(Ie(),gt(i,1,1,()=>{i=null}),Re())},i(s){e||(ot(i),e=!0)},o(s){gt(i),e=!1},d(s){s&&rt(t),i&&i.d(s)}}}function hv(r){let t,e,i,s,n,o,a=ke(r[16].filter(r[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=Ac(Ec(r,a,c));const h=c=>gt(l[c],1,1,()=>{l[c]=null});let u=r[6]&&Sc(r);return{c(){t=Z("svg"),e=Z("g");for(let c=0;c<l.length;c+=1)l[c].c();i=Z("g"),u&&u.c(),b(i,"class","drawing"),b(t,"role","application"),b(t,"tabindex",0),b(t,"class","a9s-annotationlayer"),cr(t,"drawing",r[14]),cr(t,"editing",r[8]),cr(t,"hidden",!r[3]),cr(t,"hover",r[15])},m(c,d){it(c,t,d),wt(t,e);for(let f=0;f<l.length;f+=1)l[f]&&l[f].m(e,null);wt(t,i),u&&u.m(i,null),r[35](i),r[36](t),s=!0,n||(o=[Rt(t,"pointerup",function(){Vt(r[10])&&r[10].apply(this,arguments)}),Rt(t,"pointerdown",function(){Vt(r[11])&&r[11].apply(this,arguments)}),Rt(t,"pointermove",r[23])],n=!0)},p(c,d){if(r=c,d[0]&66050){a=ke(r[16].filter(r[34]));let f;for(f=0;f<a.length;f+=1){const p=Ec(r,a,f);l[f]?(l[f].p(p,d),ot(l[f],1)):(l[f]=Ac(p),l[f].c(),ot(l[f],1),l[f].m(e,null))}for(Ie(),f=a.length;f<l.length;f+=1)h(f);Re()}r[6]?u?(u.p(r,d),d[0]&64&&ot(u,1)):(u=Sc(r),u.c(),ot(u,1),u.m(i,null)):u&&(Ie(),gt(u,1,1,()=>{u=null}),Re()),(!s||d[0]&16384)&&cr(t,"drawing",r[14]),(!s||d[0]&256)&&cr(t,"editing",r[8]),(!s||d[0]&8)&&cr(t,"hidden",!r[3]),(!s||d[0]&32768)&&cr(t,"hover",r[15])},i(c){if(!s){for(let d=0;d<a.length;d+=1)ot(l[d]);ot(u),s=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)gt(l[d]);gt(u),s=!1},d(c){c&&rt(t),mi(l,c),u&&u.d(),r[35](null),r[36](null),n=!1,$e(o)}}}function uv(r,t,e){let i,s,n,o,a,l,h,u,c,d,f,p=Dt,m=()=>(p(),p=fu(w,W=>e(17,f=W)),w);r.$$.on_destroy.push(()=>p());let{drawingEnabled:_}=t,{image:y}=t,{preferredDrawingMode:v}=t,{state:g}=t,{style:x=void 0}=t,{toolName:E=Rn()[0]}=t,{user:R}=t,{visible:S=!0}=t,M=0;const P=()=>e(5,M+=1),F=()=>E,U=()=>_;let I,A,w;gi(()=>m(e(7,w=Z_(y,A))));const{hover:C,selection:D,store:N}=g;na(r,C,W=>e(15,u=W)),na(r,D,W=>e(33,c=W)),na(r,N,W=>e(16,d=W));let B,V;const L=W=>{B&&N.unobserve(B);const bt=W.filter(({editable:dt})=>dt).map(({id:dt})=>dt);bt.length>0?(e(8,V=bt.map(dt=>N.getAnnotation(dt)).filter(dt=>dt&&ze(dt))),B=dt=>{const{updated:mt}=dt.changes;e(8,V=mt==null?void 0:mt.map(xt=>xt.newValue))},N.observe(B,{annotations:bt})):e(8,V=void 0)},O=W=>{const bt=ku(),dt={id:bt,bodies:[],target:{annotation:bt,selector:W.detail,creator:R,created:new Date}};N.addAnnotation(dt),D.setSelected(dt.id)},k=W=>bt=>{var dt;const{target:mt}=W,xt=10*60*1e3,Mt=((dt=mt.creator)==null?void 0:dt.id)!==R.id||!mt.created||new Date().getTime()-mt.created.getTime()>xt;N.updateTarget({...mt,selector:bt.detail,created:Mt?mt.created:new Date,updated:Mt?new Date:void 0,updatedBy:Mt?R:void 0})},X=W=>{const{x:bt,y:dt}=xc(W,A),mt=N.getAt(bt,dt);mt?u!==mt.id&&C.set(mt.id):C.set(void 0)},Y=W=>dc(W),q=W=>ze(W);function pt(W){bn[W?"unshift":"push"](()=>{I=W,e(6,I)})}function _t(W){bn[W?"unshift":"push"](()=>{A=W,e(4,A)})}return r.$$set=W=>{"drawingEnabled"in W&&e(0,_=W.drawingEnabled),"image"in W&&e(25,y=W.image),"preferredDrawingMode"in W&&e(26,v=W.preferredDrawingMode),"state"in W&&e(27,g=W.state),"style"in W&&e(1,x=W.style),"toolName"in W&&e(2,E=W.toolName),"user"in W&&e(28,R=W.user),"visible"in W&&e(3,S=W.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(14,{tool:i,opts:s}=Mn(E)||{tool:void 0,opts:void 0},i,(e(32,s),e(2,E))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(13,n=(s==null?void 0:s.drawingMode)||v),r.$$.dirty[0]&16&&e(12,o=tv(A)),r.$$.dirty[0]&16&&e(11,{onPointerDown:a,onPointerUp:l}=rv(A,N),a,(e(10,l),e(4,A))),r.$$.dirty[1]&4&&e(9,h=W=>c.selected.find(bt=>bt.id===W.id&&bt.editable)),r.$$.dirty[1]&4&&L(c.selected)},[_,x,E,S,A,M,I,w,V,h,l,a,o,n,i,u,d,f,C,D,N,O,k,X,Y,y,v,g,R,P,F,U,s,c,q,pt,_t]}class cv extends De{constructor(t){super(),Ne(this,t,uv,hv,le,{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 Pc(r,t,e=0,i=r.length-1,s=dv){for(;i>e;){if(i-e>600){const l=i-e+1,h=t-e+1,u=Math.log(l),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(l-c)/l)*(h-l/2<0?-1:1),f=Math.max(e,Math.floor(t-h*c/l+d)),p=Math.min(i,Math.floor(t+(l-h)*c/l+d));Pc(r,t,f,p,s)}const n=r[t];let o=e,a=i;for(Ls(r,e,t),s(r[i],n)>0&&Ls(r,e,i);o<a;){for(Ls(r,o,a),o++,a--;s(r[o],n)<0;)o++;for(;s(r[a],n)>0;)a--}s(r[e],n)===0?Ls(r,e,a):(a++,Ls(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function Ls(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function dv(r,t){return r<t?-1:r>t?1:0}class fv{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(!On(t,e))return i;const s=this.toBBox,n=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?s(a):a;On(t,l)&&(e.leaf?i.push(a):Ba(t,l)?this._all(a,i):n.push(a))}e=n.pop()}return i}collides(t){let e=this.data;if(!On(t,e))return!1;const i=[];for(;e;){for(let s=0;s<e.children.length;s++){const n=e.children[s],o=e.leaf?this.toBBox(n):n;if(On(t,o)){if(e.leaf||Ba(t,o))return!0;i.push(n)}}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=qi([]),this}remove(t,e){if(!t)return this;let i=this.data;const s=this.toBBox(t),n=[],o=[];let a,l,h;for(;i||n.length;){if(i||(i=n.pop(),l=n[n.length-1],a=o.pop(),h=!0),i.leaf){const u=pv(t,i.children,e);if(u!==-1)return i.children.splice(u,1),n.push(i),this._condense(n),this}!h&&!i.leaf&&Ba(i,s)?(n.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,s){const n=i-e+1;let o=this._maxEntries,a;if(n<=o)return a=qi(t.slice(e,i+1)),ji(a,this.toBBox),a;s||(s=Math.ceil(Math.log(n)/Math.log(o)),o=Math.ceil(n/Math.pow(o,s-1))),a=qi([]),a.leaf=!1,a.height=s;const l=Math.ceil(n/o),h=l*Math.ceil(Math.sqrt(o));Oc(t,e,i,h,this.compareMinX);for(let u=e;u<=i;u+=h){const c=Math.min(u+h-1,i);Oc(t,u,c,l,this.compareMinY);for(let d=u;d<=c;d+=l){const f=Math.min(d+l-1,c);a.children.push(this._build(t,d,f,s-1))}}return ji(a,this.toBBox),a}_chooseSubtree(t,e,i,s){for(;s.push(e),!(e.leaf||s.length-1===i);){let n=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],u=La(h),c=yv(t,h)-u;c<o?(o=c,n=u<n?u:n,a=h):c===o&&u<n&&(n=u,a=h)}e=a||e.children[0]}return e}_insert(t,e,i){const s=i?t:this.toBBox(t),n=[],o=this._chooseSubtree(s,this.data,e,n);for(o.children.push(t),Fs(o,s);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(s,n,e)}_split(t,e){const i=t[e],s=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,s);const o=this._chooseSplitIndex(i,n,s),a=qi(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,ji(i,this.toBBox),ji(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=qi([t,e]),this.data.height=t.height+1,this.data.leaf=!1,ji(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let s,n=1/0,o=1/0;for(let a=e;a<=i-e;a++){const l=Bs(t,0,a,this.toBBox),h=Bs(t,a,i,this.toBBox),u=_v(l,h),c=La(l)+La(h);u<n?(n=u,s=a,o=c<o?c:o):u===n&&c<o&&(o=c,s=a)}return s||i-e}_chooseSplitAxis(t,e,i){const s=t.leaf?this.compareMinX:mv,n=t.leaf?this.compareMinY:gv,o=this._allDistMargin(t,e,i,s),a=this._allDistMargin(t,e,i,n);o<a&&t.children.sort(s)}_allDistMargin(t,e,i,s){t.children.sort(s);const n=this.toBBox,o=Bs(t,0,e,n),a=Bs(t,i-e,i,n);let l=Pn(o)+Pn(a);for(let h=e;h<i-e;h++){const u=t.children[h];Fs(o,t.leaf?n(u):u),l+=Pn(o)}for(let h=i-e-1;h>=e;h--){const u=t.children[h];Fs(a,t.leaf?n(u):u),l+=Pn(a)}return l}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)Fs(e[s],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():ji(t[e],this.toBBox)}}function pv(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 ji(r,t){Bs(r,0,r.children.length,t,r)}function Bs(r,t,e,i,s){s||(s=qi(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let n=t;n<e;n++){const o=r.children[n];Fs(s,r.leaf?i(o):o)}return s}function Fs(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 mv(r,t){return r.minX-t.minX}function gv(r,t){return r.minY-t.minY}function La(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Pn(r){return r.maxX-r.minX+(r.maxY-r.minY)}function yv(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 _v(r,t){const e=Math.max(r.minX,t.minX),i=Math.max(r.minY,t.minY),s=Math.min(r.maxX,t.maxX),n=Math.min(r.maxY,t.maxY);return Math.max(0,s-e)*Math.max(0,n-i)}function Ba(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function On(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function qi(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Oc(r,t,e,i,s){const n=[t,e];for(;n.length;){if(e=n.pop(),t=n.pop(),e-t<=i)continue;const o=t+Math.ceil((e-t)/i/2)*i;Pc(r,o,t,e,s),n.push(t,o,o,e)}}const vv=()=>{const r=new fv,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},s=o=>{if(!Tn(o))return;const{minX:a,minY:l,maxX:h,maxY:u}=o.selector.geometry.bounds,c={minX:a,minY:l,maxX:h,maxY:u,target:o};r.insert(c),t.set(o.annotation,c)},n=o=>{if(!Tn(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)=>{const h=r.search({minX:o,minY:a,maxX:o,maxY:a}).map(u=>u.target).filter(u=>u.selector.type===Tt.RECTANGLE||wy(u.selector,o,a));return h.length>0?(h.sort((u,c)=>ua(u.selector)-ua(c.selector)),h):[]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(u=>u.target),insert:s,remove:n,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,u)=>{if(Tn(u)){const{minX:c,minY:d,maxX:f,maxY:p}=u.selector.geometry.bounds;return[...h,{minX:c,minY:d,maxX:f,maxY:p,target:u}]}else return h},[]);l.forEach(h=>t.set(h.target.annotation,h)),r.load(l)},size:()=>r.all().length,update:(o,a)=>{n(o),s(a)}}},Nc=r=>{const t=S_(),e=vv(),i=f_(t,r.userSelectAction,r.adapter),s=d_(t),n=P_();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)=>{const h=e.getAt(o,a,l);if(l)return h.map(u=>t.getAnnotation(u.annotation)).filter(Boolean).filter(l)[0];{const u=h[0];return u?t.getAnnotation(u.annotation):void 0}},getIntersecting:(o,a,l,h)=>e.getIntersecting(o,a,l,h).map(u=>t.getAnnotation(u.annotation)).filter(Boolean)},selection:i,hover:s,viewport:n}},xv=r=>{const t=Nc(r);return{...t,store:C_(t.store)}},bv=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const s=r;t=document.createElement("canvas"),t.width=s.width,t.height=s.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(s,0,0,s.width,s.height)}let i=0;for(let s=1;s<10;s++)for(let n=1;n<10;n++){const o=Math.round(n*t.width/10),a=Math.round(s*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},Dc=r=>{const t=bv(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},Lc=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?Dc(r):e),Bc=(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}),Fc=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,kc=(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()},s=o=>{const a=o;a.key==="z"&&a.metaKey&&(a.shiftKey?r.redo():r.undo())},n=()=>{Fc?e.removeEventListener("keydown",s):e.removeEventListener("keydown",i)};return Fc?e.addEventListener("keydown",s):e.addEventListener("keydown",i),{destroy:n}},Ev=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=Bc(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Gu.EDIT,theme:"light"}),s=xv(i),{selection:n,store:o}=s,a=M_(o,i.initialHistory),l=O_(s,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 u=kc(a);let c=$_();Lc(e,h,i.theme);const d=new cv({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:s,style:i.style,user:c}});d.$on("click",I=>{const{originalEvent:A,annotation:w}=I.detail;w?n.userSelect(w.id,A):n.isEmpty()||n.clear()});const f=D_(s,a,i.adapter),p=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),u.destroy(),a.destroy()},_=()=>d.getDrawingTool(),y=()=>c,v=()=>d.isDrawingEnabled(),g=(I,A,w)=>yc(I,A,w),x=(I,A)=>fc(I,A),E=I=>{if(!Mn(I))throw`No drawing tool named ${I}`;d.$set({toolName:I})},R=I=>d.$set({drawingEnabled:I}),S=I=>{console.warn("Filter not implemented yet")},M=I=>d.$set({style:I}),P=I=>Lc(e,h,I),F=I=>{c=I,d.$set({user:I})},U=I=>d.$set({visible:I});return{...f,cancelDrawing:p,destroy:m,getDrawingTool:_,getUser:y,isDrawingEnabled:v,listDrawingTools:Rn,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:x,setDrawingEnabled:R,setDrawingTool:E,setFilter:S,setStyle:M,setTheme:P,setUser:F,setVisible:U,element:h,state:s}};function Qt(){}function Fa(r,t){for(const e in t)r[e]=t[e];return r}function Uc(r){return r()}function Gc(){return Object.create(null)}function Ye(r){r.forEach(Uc)}function Jt(r){return typeof r=="function"}function qt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function wv(r){return Object.keys(r).length===0}function Tv(r,...t){if(r==null){for(const i of t)i(void 0);return Qt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Nn(r,t,e){r.$$.on_destroy.push(Tv(t,e))}function Hc(r,t,e,i){if(r){const s=$c(r,t,e,i);return r[0](s)}}function $c(r,t,e,i){return r[1]&&i?Fa(e.ctx.slice(),r[1](i(t))):e.ctx}function Xc(r,t,e,i){if(r[2]&&i){const s=r[2](i(e));if(t.dirty===void 0)return s;if(typeof s=="object"){const n=[],o=Math.max(t.dirty.length,s.length);for(let a=0;a<o;a+=1)n[a]=t.dirty[a]|s[a];return n}return t.dirty|s}return t.dirty}function Vc(r,t,e,i,s,n){if(s){const o=$c(t,e,i,n);r.p(o,s)}}function zc(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 Yc(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}const ka=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Ct(r,t){r.appendChild(t)}function at(r,t,e){r.insertBefore(t,e||null)}function nt(r){r.parentNode&&r.parentNode.removeChild(r)}function Wr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function st(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Ua(r){return document.createTextNode(r)}function Le(){return Ua(" ")}function Ge(){return Ua("")}function Pt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function T(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function Av(r){return Array.from(r.childNodes)}function Sv(r,t){t=""+t,r.data!==t&&(r.data=t)}function jr(r,t,e){r.classList.toggle(t,!!e)}function Cv(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let ks;function Us(r){ks=r}function Ga(){if(!ks)throw new Error("Function called outside component initialization");return ks}function vi(r){Ga().$$.on_mount.push(r)}function Iv(r){Ga().$$.on_destroy.push(r)}function Ki(){const r=Ga();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=Cv(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function Me(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Zi=[],Dn=[];let Qi=[];const Wc=[],jc=Promise.resolve();let Ha=!1;function qc(){Ha||(Ha=!0,jc.then(Zc))}function Kc(){return qc(),jc}function $a(r){Qi.push(r)}const Xa=new Set;let Ji=0;function Zc(){if(Ji!==0)return;const r=ks;do{try{for(;Ji<Zi.length;){const t=Zi[Ji];Ji++,Us(t),Rv(t.$$)}}catch(t){throw Zi.length=0,Ji=0,t}for(Us(null),Zi.length=0,Ji=0;Dn.length;)Dn.pop()();for(let t=0;t<Qi.length;t+=1){const e=Qi[t];Xa.has(e)||(Xa.add(e),e())}Qi.length=0}while(Zi.length);for(;Wc.length;)Wc.pop()();Ha=!1,Xa.clear(),Us(r)}function Rv(r){if(r.fragment!==null){r.update(),Ye(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach($a)}}function Mv(r){const t=[],e=[];Qi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Qi=t}const Ln=new Set;let xi;function fe(){xi={r:0,c:[],p:xi}}function pe(){xi.r||Ye(xi.c),xi=xi.p}function K(r,t){r&&r.i&&(Ln.delete(r),r.i(t))}function lt(r,t,e,i){if(r&&r.o){if(Ln.has(r))return;Ln.add(r),xi.c.push(()=>{Ln.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Pe(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Ht(r){r&&r.c()}function Ft(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),$a(()=>{const n=r.$$.on_mount.map(Uc).filter(Jt);r.$$.on_destroy?r.$$.on_destroy.push(...n):Ye(n),r.$$.on_mount=[]}),s.forEach($a)}function kt(r,t){const e=r.$$;e.fragment!==null&&(Mv(e.after_update),Ye(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Pv(r,t){r.$$.dirty[0]===-1&&(Zi.push(r),qc(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ie(r,t,e,i,s,n,o=null,a=[-1]){const l=ks;Us(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Qt,not_equal:s,bound:Gc(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Gc(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let u=!1;if(h.ctx=e?e(r,t.props||{},(c,d,...f)=>{const p=f.length?f[0]:d;return h.ctx&&s(h.ctx[c],h.ctx[c]=p)&&(!h.skip_bound&&h.bound[c]&&h.bound[c](p),u&&Pv(r,c)),d}):[],h.update(),u=!0,Ye(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=Av(t.target);h.fragment&&h.fragment.l(c),c.forEach(nt)}else h.fragment&&h.fragment.c();t.intro&&K(r.$$.fragment),Ft(r,t.target,t.anchor),Zc()}Us(l)}class se{constructor(){$t(this,"$$");$t(this,"$$set")}$destroy(){kt(this,1),this.$destroy=Qt}$on(t,e){if(!Jt(e))return Qt;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const s=i.indexOf(e);s!==-1&&i.splice(s,1)}}$set(t){this.$$set&&!wv(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Ov="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ov);var qr=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGLON="MULTIPOLYGON",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(qr||{}),Gs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Va(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 s=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return r[i]}})}),e}var Qc={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,u=a.y-l.y;return h*h+u*u}function e(a,l,h){var u=l.x,c=l.y,d=h.x-u,f=h.y-c;if(d!==0||f!==0){var p=((a.x-u)*d+(a.y-c)*f)/(d*d+f*f);p>1?(u=h.x,c=h.y):p>0&&(u+=d*p,c+=f*p)}return d=a.x-u,f=a.y-c,d*d+f*f}function i(a,l){for(var h=a[0],u=[h],c,d=1,f=a.length;d<f;d++)c=a[d],t(c,h)>l&&(u.push(c),h=c);return h!==c&&u.push(c),u}function s(a,l,h,u,c){for(var d=u,f,p=l+1;p<h;p++){var m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}d>u&&(f-l>1&&s(a,l,f,u,c),c.push(a[f]),h-f>1&&s(a,f,h,u,c))}function n(a,l){var h=a.length-1,u=[a[0]];return s(a,0,h,l,u),u.push(a[h]),u}function o(a,l,h){if(a.length<=2)return a;var u=l!==void 0?l*l:1;return a=h?a:i(a,u),a=n(a,u),a}r.exports=o,r.exports.default=o})()})(Qc);var Dv=Qc.exports;const Lv=Va(Dv),Bn=(r,t)=>t,dr=r=>{let t=1/0,e=1/0,i=-1/0,s=-1/0;return r.forEach(([n,o])=>{t=Math.min(t,n),e=Math.min(e,o),i=Math.max(i,n),s=Math.max(s,o)}),{minX:t,minY:e,maxX:i,maxY:s}},za=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)},Ya=(r,t,e)=>{let i=!1;for(let s=0,n=r.length-1;s<r.length;n=s++){const o=r[s][0],a=r[s][1],l=r[n][0],h=r[n][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},Bv=(r,t=!0)=>{let e="M ";return r.forEach(([i,s],n)=>{n===0?e+=`${i},${s}`:e+=` L ${i},${s}`}),t&&(e+=" Z"),e},Jc=(r,t=1)=>{const e=r.map(([i,s])=>({x:i,y:s}));return Lv(e,t,!0).map(i=>[i.x,i.y])},Fv={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:s,rx:n,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),u=t-i,c=e-s,d=l*u+h*c,f=h*u-l*c;return d*d/(n*n)+f*f/(o*o)<=1}};Bn(qr.ELLIPSE,Fv);const kv={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[s,...n]=i.rings,o=za(s.points),a=n.reduce((l,h)=>l+za(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const s of i){const[n,...o]=s.rings;if(Ya(n.points,t,e)){let a=!1;for(const l of o)if(Ya(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Fn=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return dr(t)},ts=r=>r.rings.map(e=>Bv(e.points)).join(" "),Uv=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,s)=>[...i,...s.points],[])],[]),Gv=(r,t=1)=>{const e=r.geometry.polygons.map(s=>{const n=s.rings.map(a=>{const l=Jc(a.points,t);return{...a,points:l}}),o=dr(n[0].points);return{...s,rings:n,bounds:o}}),i=Fn(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Bn(qr.MULTIPOLYGLON,kv);const Hv={area:r=>{const t=r.geometry.points;return za(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Ya(i,t,e)}},$v=(r,t=1)=>{const e=Jc(r.geometry.points,t),i=dr(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Bn(qr.POLYGON,Hv);const Xv={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};Bn(qr.RECTANGLE,Xv);const ne=" ";function Vv(r){let t="";Array.isArray(r)||(r=[r]);for(let e=0;e<r.length;e++){const i=r[e];if(i.type===$.CLOSE_PATH)t+="z";else if(i.type===$.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===$.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===$.MOVE_TO)t+=(i.relative?"m":"M")+i.x+ne+i.y;else if(i.type===$.LINE_TO)t+=(i.relative?"l":"L")+i.x+ne+i.y;else if(i.type===$.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+ne+i.y1+ne+i.x2+ne+i.y2+ne+i.x+ne+i.y;else if(i.type===$.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+ne+i.y2+ne+i.x+ne+i.y;else if(i.type===$.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+ne+i.y1+ne+i.x+ne+i.y;else if(i.type===$.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+ne+i.y;else if(i.type===$.ARC)t+=(i.relative?"a":"A")+i.rX+ne+i.rY+ne+i.xRot+ne+ +i.lArcFlag+ne+ +i.sweepFlag+ne+i.x+ne+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${e}.`)}return t}function Wa([r,t],e){return[r*Math.cos(e)-t*Math.sin(e),r*Math.sin(e)+t*Math.cos(e)]}function tr(...r){for(let t=0;t<r.length;t++)if(typeof r[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof r[t]} == typeof ${r[t]}`);return!0}const Kr=Math.PI;function ja(r,t,e){r.lArcFlag=r.lArcFlag===0?0:1,r.sweepFlag=r.sweepFlag===0?0:1;let{rX:i,rY:s}=r;const{x:n,y:o}=r;if(Math.abs(i)<1e-10||Math.abs(s)<1e-10){r.rX=0,r.rY=0,r.cX=(t+n)/2,r.cY=(e+o)/2,r.phi1=0,r.phi2=0;return}i=Math.abs(r.rX),s=Math.abs(r.rY);const a=r.xRot/180*Kr,[l,h]=Wa([(t-n)/2,(e-o)/2],-a),u=Math.pow(l,2)/Math.pow(i,2)+Math.pow(h,2)/Math.pow(s,2);1<u&&(i*=Math.sqrt(u),s*=Math.sqrt(u)),r.rX=i,r.rY=s;const c=Math.pow(i,2)*Math.pow(h,2)+Math.pow(s,2)*Math.pow(l,2),d=(r.lArcFlag!==r.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(s,2)-c)/c)),f=i*h/s*d,p=-s*l/i*d,m=Wa([f,p],a);r.cX=m[0]+(t+n)/2,r.cY=m[1]+(e+o)/2,r.phi1=Math.atan2((h-p)/s,(l-f)/i),r.phi2=Math.atan2((-h-p)/s,(-l-f)/i),r.sweepFlag===0&&r.phi2>r.phi1&&(r.phi2-=2*Kr),r.sweepFlag===1&&r.phi2<r.phi1&&(r.phi2+=2*Kr),r.phi1*=180/Kr,r.phi2*=180/Kr}function td(r,t,e){tr(r,t,e);const i=r*r+t*t-e*e;if(0>i)return[];if(i===0)return[[r*e/(r*r+t*t),t*e/(r*r+t*t)]];const s=Math.sqrt(i);return[[(r*e+t*s)/(r*r+t*t),(t*e-r*s)/(r*r+t*t)],[(r*e-t*s)/(r*r+t*t),(t*e+r*s)/(r*r+t*t)]]}const bi=Math.PI/180;function ed(r,t,e){return(1-e)*r+e*t}function rd(r,t,e,i){return r+Math.cos(i/180*Kr)*t+Math.sin(i/180*Kr)*e}function id(r,t,e,i){const n=t-r,o=e-t,a=i-e,l=3*n+3*a-6*o,h=(o-n)*6,u=3*n;return Math.abs(l)<1e-6?Math.abs(h)<1e-6?[]:[-u/h]:zv(h/l,u/l,1e-6)}function sd(r,t,e,i,s){const n=1-s,o=n*n*n,a=3*n*n*s,l=3*n*s*s,h=s*s*s;return r*o+t*a+e*l+i*h}function zv(r,t,e=1e-6){const i=r*r/4-t;if(i<-e)return[];if(i<=e)return[-r/2];const s=Math.sqrt(i);return[-(r/2)-s,-(r/2)+s]}function Yv(r,t,e){r.cX||ja(r,t,e);const i=r.xRot/180*Kr;if(Math.abs(r.rX)<1e-10||Math.abs(r.rY)<1e-10)return[{relative:r.relative,type:$.CURVE_TO,x1:t+(r.x-t)/3,y1:e+(r.y-e)/3,x2:t+2*(r.x-t)/3,y2:e+2*(r.y-e)/3,x:r.x,y:r.y}];const s=Math.min(r.phi1,r.phi2),n=Math.max(r.phi1,r.phi2),o=n-s,a=Math.ceil(o/90),l=new Array(a);let h=t,u=e;const c=(d,f)=>{const[p,m]=Wa([d*r.rX,f*r.rY],i);return[r.cX+p,r.cY+m]};for(let d=0;d<a;d++){const f=ed(r.phi1,r.phi2,d/a),p=ed(r.phi1,r.phi2,(d+1)/a),m=p-f,_=4/3*Math.tan(m*bi/4),y=Math.cos(f*bi)-_*Math.sin(f*bi),v=Math.sin(f*bi)+_*Math.cos(f*bi),g=Math.cos(p*bi),x=Math.sin(p*bi),E=g+_*x,R=x-_*g,S=c(y,v),M=c(E,R),P=c(g,x),F={relative:r.relative,type:$.CURVE_TO,x:P[0],y:P[1],x1:S[0],y1:S[1],x2:M[0],y2:M[1]};r.relative&&(F.x1-=h,F.y1-=u,F.x2-=h,F.y2-=u,F.x-=h,F.y-=u),h=P[0],u=P[1],l[d]=F}return l}function qa(r,t,e){const i=t[0]-r[0],s=t[1]-r[1],n=e[0]-r[0],o=e[1]-r[1],a=i*o-s*n;if(!(Math.abs(a)<1e-10))return!1;const h=i*n+s*o,u=i*i+s*s,c=n*n+o*o;return 0<=h&&h<=c&&u<=c}function Wv(r,t=!0){if(r.length<2)return r;const e=oe.INFO((n,o,a)=>({...n,x:n.x??o,y:n.y??a,relative:n.relative??!1})),i=[];let s=[];for(const n of r){const o=e(n);o.type===$.MOVE_TO&&s.length>0&&(t?i.push(...kn(s)):i.unshift(...kn(s)),s=[]),s.push(o)}return s.length>0&&(t?i.push(...kn(s)):i.unshift(...kn(s))),i}function kn(r){var s;const t=((s=r[r.length-1])==null?void 0:s.type)===$.CLOSE_PATH,e=t?r.length-2:r.length-1,i=[{type:$.MOVE_TO,relative:!1,x:r[e].x,y:r[e].y}];for(let n=e;n>0;n--){const o=r[n],a=r[n-1];if(o.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(o.type){case $.HORIZ_LINE_TO:i.push({type:$.HORIZ_LINE_TO,relative:!1,x:a.x});break;case $.VERT_LINE_TO:i.push({type:$.VERT_LINE_TO,relative:!1,y:a.y});break;case $.LINE_TO:case $.MOVE_TO:i.push({type:$.LINE_TO,relative:!1,x:a.x,y:a.y});break;case $.CURVE_TO:i.push({type:$.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:o.x2,y1:o.y2,x2:o.x1,y2:o.y1});break;case $.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case $.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case $.ARC:throw new Error("Unsupported command: A (arc)");case $.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:$.CLOSE_PATH}),i}function jv(r=1e13){tr(r);function t(e){return Math.round(e*r)/r}return function(i){return"x1"in i&&typeof i.x1<"u"&&(i.x1=t(i.x1)),"y1"in i&&typeof i.y1<"u"&&(i.y1=t(i.y1)),"x2"in i&&typeof i.x2<"u"&&(i.x2=t(i.x2)),"y2"in i&&typeof i.y2<"u"&&(i.y2=t(i.y2)),"x"in i&&typeof i.x<"u"&&(i.x=t(i.x)),"y"in i&&typeof i.y<"u"&&(i.y=t(i.y)),"rX"in i&&typeof i.rX<"u"&&(i.rX=t(i.rX)),"rY"in i&&typeof i.rY<"u"&&(i.rY=t(i.rY)),i}}function nd(){return er((r,t,e)=>(r.relative&&(typeof r.x1<"u"&&(r.x1+=t),typeof r.y1<"u"&&(r.y1+=e),typeof r.x2<"u"&&(r.x2+=t),typeof r.y2<"u"&&(r.y2+=e),typeof r.x<"u"&&(r.x+=t),typeof r.y<"u"&&(r.y+=e),r.relative=!1),r))}function qv(){return er((r,t,e)=>(r.relative||(typeof r.x1<"u"&&(r.x1-=t),typeof r.y1<"u"&&(r.y1-=e),typeof r.x2<"u"&&(r.x2-=t),typeof r.y2<"u"&&(r.y2-=e),typeof r.x<"u"&&(r.x-=t),typeof r.y<"u"&&(r.y-=e),r.relative=!0),r))}function Kv(r=!0,t=!0,e=!0,i=!0){return er((s,n,o,a,l)=>{if(isNaN(a)&&!(s.type&$.MOVE_TO))throw new Error("path must start with moveto");if(t&&s.type&$.HORIZ_LINE_TO&&(s.type=$.LINE_TO,s.y=s.relative?0:o),e&&s.type&$.VERT_LINE_TO&&(s.type=$.LINE_TO,s.x=s.relative?0:n),r&&s.type&$.CLOSE_PATH&&(s.type=$.LINE_TO,s.x=s.relative?a-n:a,s.y=s.relative?l-o:l),s.type&$.ARC&&(s.rX===0||s.rY===0)&&(s.type=$.LINE_TO,delete s.rX,delete s.rY,delete s.xRot,delete s.lArcFlag,delete s.sweepFlag),i&&s.type&$.QUAD_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x,o+s.y]:[s.x,s.y];qa(h,u,c)&&(s.type=$.LINE_TO,delete s.x1,delete s.y1)}if(i&&s.type&$.CURVE_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x2,o+s.y2]:[s.x2,s.y2],d=s.relative?[n+s.x,o+s.y]:[s.x,s.y];qa(h,u,d)&&qa(h,c,d)&&(s.type=$.LINE_TO,delete s.x1,delete s.y1,delete s.x2,delete s.y2)}return s})}function od(){let r=NaN,t=NaN,e=NaN,i=NaN;return er((s,n,o)=>(s.type&$.SMOOTH_CURVE_TO&&(s.type=$.CURVE_TO,r=isNaN(r)?n:r,t=isNaN(t)?o:t,s.x1=s.relative?n-r:2*n-r,s.y1=s.relative?o-t:2*o-t),s.type&$.CURVE_TO?(r=s.relative?n+s.x2:s.x2,t=s.relative?o+s.y2:s.y2):(r=NaN,t=NaN),s.type&$.SMOOTH_QUAD_TO&&(s.type=$.QUAD_TO,e=isNaN(e)?n:e,i=isNaN(i)?o:i,s.x1=s.relative?n-e:2*n-e,s.y1=s.relative?o-i:2*o-i),s.type&$.QUAD_TO?(e=s.relative?n+s.x1:s.x1,i=s.relative?o+s.y1:s.y1):(e=NaN,i=NaN),s))}function ad(){let r=NaN,t=NaN;return er((e,i,s)=>{if(e.type&$.SMOOTH_QUAD_TO&&(e.type=$.QUAD_TO,r=isNaN(r)?i:r,t=isNaN(t)?s:t,e.x1=e.relative?i-r:2*i-r,e.y1=e.relative?s-t:2*s-t),e.type&$.QUAD_TO){r=e.relative?i+e.x1:e.x1,t=e.relative?s+e.y1:e.y1;const n=e.x1,o=e.y1;e.type=$.CURVE_TO,e.x1=((e.relative?0:i)+n*2)/3,e.y1=((e.relative?0:s)+o*2)/3,e.x2=(e.x+n*2)/3,e.y2=(e.y+o*2)/3}else r=NaN,t=NaN;return e})}function er(r){let t=0,e=0,i=NaN,s=NaN;return function(o){if(isNaN(i)&&!(o.type&$.MOVE_TO))throw new Error("path must start with moveto");const a=r(o,t,e,i,s);return o.type&$.CLOSE_PATH&&(t=i,e=s),"x"in o&&typeof o.x<"u"&&(t=o.relative?t+o.x:o.x),"y"in o&&typeof o.y<"u"&&(e=o.relative?e+o.y:o.y),o.type&$.MOVE_TO&&(i=t,s=e),a}}function Zv(r=0){tr(r);let t=NaN,e=NaN,i=NaN,s=NaN;return er((n,o,a,l,h)=>{const u=Math.abs;let c=!1,d=0,f=0;if(n.type&$.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:o-t,f=isNaN(e)?0:a-e),n.type&($.CURVE_TO|$.SMOOTH_CURVE_TO)?(t=n.relative?o+n.x2:n.x2,e=n.relative?a+n.y2:n.y2):(t=NaN,e=NaN),n.type&$.SMOOTH_QUAD_TO?(i=isNaN(i)?o:2*o-i,s=isNaN(s)?a:2*a-s):n.type&$.QUAD_TO?(i=n.relative?o+n.x1:n.x1,s=n.relative?a+n.y1:n.y2):(i=NaN,s=NaN),n.type&$.LINE_COMMANDS||n.type&$.ARC&&(n.rX===0||n.rY===0||!n.lArcFlag)||n.type&$.CURVE_TO||n.type&$.SMOOTH_CURVE_TO||n.type&$.QUAD_TO||n.type&$.SMOOTH_QUAD_TO){const p=typeof n.x>"u"?0:n.relative?n.x:n.x-o,m=typeof n.y>"u"?0:n.relative?n.y:n.y-a;d=isNaN(i)?typeof n.x1>"u"?d:n.relative?n.x:n.x1-o:i-o,f=isNaN(s)?typeof n.y1>"u"?f:n.relative?n.y:n.y1-a:s-a;const _=typeof n.x2>"u"?0:n.relative?n.x:n.x2-o,y=typeof n.y2>"u"?0:n.relative?n.y:n.y2-a;u(p)<=r&&u(m)<=r&&u(d)<=r&&u(f)<=r&&u(_)<=r&&u(y)<=r&&(c=!0)}return n.type&$.CLOSE_PATH&&u(o-l)<=r&&u(a-h)<=r&&(c=!0),c?[]:n})}function Zr(r,t,e,i,s,n){return tr(r,t,e,i,s,n),er((o,a,l,h)=>{const u=o.x1,c=o.x2,d=o.relative&&!isNaN(h),f=typeof o.x<"u"?o.x:d?0:a,p=typeof o.y<"u"?o.y:d?0:l;o.type&$.HORIZ_LINE_TO&&t!==0&&(o.type=$.LINE_TO,o.y=o.relative?0:l),o.type&$.VERT_LINE_TO&&e!==0&&(o.type=$.LINE_TO,o.x=o.relative?0:a),typeof o.x<"u"&&(o.x=o.x*r+p*e+(d?0:s)),typeof o.y<"u"&&(o.y=f*t+o.y*i+(d?0:n)),typeof o.x1<"u"&&(o.x1=o.x1*r+o.y1*e+(d?0:s)),typeof o.y1<"u"&&(o.y1=u*t+o.y1*i+(d?0:n)),typeof o.x2<"u"&&(o.x2=o.x2*r+o.y2*e+(d?0:s)),typeof o.y2<"u"&&(o.y2=c*t+o.y2*i+(d?0:n));function m(y){return y*y}const _=r*i-t*e;if(typeof o.xRot<"u"&&(r!==1||t!==0||e!==0||i!==1))if(_===0)delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag,o.type=$.LINE_TO;else{const y=o.xRot*Math.PI/180,v=Math.sin(y),g=Math.cos(y),x=1/m(o.rX),E=1/m(o.rY),R=m(g)*x+m(v)*E,S=2*v*g*(x-E),M=m(v)*x+m(g)*E,P=R*i*i-S*t*i+M*t*t,F=S*(r*i+t*e)-2*(R*e*i+M*r*t),U=R*e*e-S*r*e+M*r*r,I=(Math.atan2(F,P-U)+Math.PI)%Math.PI/2,A=Math.sin(I),w=Math.cos(I);o.rX=Math.abs(_)/Math.sqrt(P*m(w)+F*A*w+U*m(A)),o.rY=Math.abs(_)/Math.sqrt(P*m(A)-F*A*w+U*m(w)),o.xRot=I*180/Math.PI}return typeof o.sweepFlag<"u"&&0>_&&(o.sweepFlag=+!o.sweepFlag),o})}function Qv(r,t=0,e=0){tr(r,t,e);const i=Math.sin(r),s=Math.cos(r);return Zr(s,i,-i,s,t-t*s+e*i,e-t*i-e*s)}function Jv(r,t=0){return tr(r,t),Zr(1,0,0,1,r,t)}function t1(r,t=r){return tr(r,t),Zr(r,0,0,t,0,0)}function e1(r){return tr(r),Zr(1,0,Math.tan(r),1,0,0)}function r1(r){return tr(r),Zr(1,Math.tan(r),0,1,0,0)}function i1(r=0){return tr(r),Zr(-1,0,0,1,r,0)}function s1(r=0){return tr(r),Zr(1,0,0,-1,0,r)}function n1(){return er((r,t,e)=>$.ARC===r.type?Yv(r,r.relative?0:t,r.relative?0:e):r)}function o1(){return er((r,t,e)=>(r.relative&&(t=0,e=0),$.ARC===r.type&&ja(r,t,e),r))}function ld(){return r=>({...r})}function a1(){const r=ld(),t=nd(),e=ad(),i=od(),s=er((n,o,a)=>{const l=i(e(t(r(n))));function h(c){c>s.maxX&&(s.maxX=c),c<s.minX&&(s.minX=c)}function u(c){c>s.maxY&&(s.maxY=c),c<s.minY&&(s.minY=c)}if(l.type&$.DRAWING_COMMANDS&&(h(o),u(a)),l.type&$.HORIZ_LINE_TO&&h(l.x),l.type&$.VERT_LINE_TO&&u(l.y),l.type&$.LINE_TO&&(h(l.x),u(l.y)),l.type&$.CURVE_TO){h(l.x),u(l.y);const c=id(o,l.x1,l.x2,l.x);for(const f of c)0<f&&1>f&&h(sd(o,l.x1,l.x2,l.x,f));const d=id(a,l.y1,l.y2,l.y);for(const f of d)0<f&&1>f&&u(sd(a,l.y1,l.y2,l.y,f))}if(l.type&$.ARC){h(l.x),u(l.y),ja(l,o,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,f=Math.sin(c)*l.rX,p=-Math.sin(c)*l.rY,m=Math.cos(c)*l.rY,[_,y]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],v=([E,R])=>{const M=Math.atan2(R,E)*180/Math.PI;return M<_?M+360:M},g=td(p,-d,0).map(v);for(const E of g)E>_&&E<y&&h(rd(l.cX,d,p,E));const x=td(m,-f,0).map(v);for(const E of x)E>_&&E<y&&u(rd(l.cY,f,m,E))}return n});return s.minX=1/0,s.maxX=-1/0,s.minY=1/0,s.maxY=-1/0,s}const oe={ROUND:jv,TO_ABS:nd,TO_REL:qv,NORMALIZE_HVZ:Kv,NORMALIZE_ST:od,QT_TO_C:ad,INFO:er,SANITIZE:Zv,MATRIX:Zr,ROTATE:Qv,TRANSLATE:Jv,SCALE:t1,SKEW_X:e1,SKEW_Y:r1,X_AXIS_SYMMETRY:i1,Y_AXIS_SYMMETRY:s1,A_TO_C:n1,ANNOTATE_ARCS:o1,CLONE:ld,CALCULATE_BOUNDS:a1,REVERSE_PATH:Wv};class hd{round(t){return this.transform(oe.ROUND(t))}toAbs(){return this.transform(oe.TO_ABS())}toRel(){return this.transform(oe.TO_REL())}normalizeHVZ(t,e,i){return this.transform(oe.NORMALIZE_HVZ(t,e,i))}normalizeST(){return this.transform(oe.NORMALIZE_ST())}qtToC(){return this.transform(oe.QT_TO_C())}aToC(){return this.transform(oe.A_TO_C())}sanitize(t){return this.transform(oe.SANITIZE(t))}translate(t,e){return this.transform(oe.TRANSLATE(t,e))}scale(t,e){return this.transform(oe.SCALE(t,e))}rotate(t,e,i){return this.transform(oe.ROTATE(t,e,i))}matrix(t,e,i,s,n,o){return this.transform(oe.MATRIX(t,e,i,s,n,o))}skewX(t){return this.transform(oe.SKEW_X(t))}skewY(t){return this.transform(oe.SKEW_Y(t))}xSymmetry(t){return this.transform(oe.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(oe.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(oe.ANNOTATE_ARCS())}}const l1=r=>r===" "||r===" "||r==="\r"||r===`
|
|
3
3
|
`,ud=r=>48<=r.charCodeAt(0)&&r.charCodeAt(0)<=57;class h1 extends hd{constructor(){super();$t(this,"curNumber","");$t(this,"curCommandType",-1);$t(this,"curCommandRelative",!1);$t(this,"canParseCommandOrComma",!0);$t(this,"curNumberHasExp",!1);$t(this,"curNumberHasExpDigits",!1);$t(this,"curNumberHasDecimal",!1);$t(this,"curArgs",[])}finish(e=[]){if(this.parse(" ",e),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return e}parse(e,i=[]){const s=n=>{i.push(n),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let n=0;n<e.length;n++){const o=e[n],a=this.curCommandType===$.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),l=ud(o)&&(this.curNumber==="0"&&o==="0"||a);if(ud(o)&&!l){this.curNumber+=o,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(o==="e"||o==="E"){this.curNumber+=o,this.curNumberHasExp=!0;continue}if((o==="-"||o==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=o;continue}if(o==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!a){this.curNumber+=o,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const h=Number(this.curNumber);if(isNaN(h))throw new SyntaxError(`Invalid number ending at ${n}`);if(this.curCommandType===$.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>h)throw new SyntaxError(`Expected positive number, got "${h}" at index "${n}"`)}else if((this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber!=="0"&&this.curNumber!=="1")throw new SyntaxError(`Expected a flag, got "${this.curNumber}" at index "${n}"`)}this.curArgs.push(h),this.curArgs.length===u1[this.curCommandType]&&($.HORIZ_LINE_TO===this.curCommandType?s({type:$.HORIZ_LINE_TO,relative:this.curCommandRelative,x:h}):$.VERT_LINE_TO===this.curCommandType?s({type:$.VERT_LINE_TO,relative:this.curCommandRelative,y:h}):this.curCommandType===$.MOVE_TO||this.curCommandType===$.LINE_TO||this.curCommandType===$.SMOOTH_QUAD_TO?(s({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),$.MOVE_TO===this.curCommandType&&(this.curCommandType=$.LINE_TO)):this.curCommandType===$.CURVE_TO?s({type:$.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===$.SMOOTH_CURVE_TO?s({type:$.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===$.QUAD_TO?s({type:$.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===$.ARC&&s({type:$.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!l1(o)){if(o===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(o==="+"||o==="-"||o==="."){this.curNumber=o,this.curNumberHasDecimal=o===".";continue}if(l){this.curNumber=o,this.curNumberHasDecimal=!1;continue}if(this.curArgs.length!==0)throw new SyntaxError(`Unterminated command at index ${n}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${o}" at index ${n}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,o==="z"||o==="Z"){i.push({type:$.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(o==="h"||o==="H")this.curCommandType=$.HORIZ_LINE_TO,this.curCommandRelative=o==="h";else if(o==="v"||o==="V")this.curCommandType=$.VERT_LINE_TO,this.curCommandRelative=o==="v";else if(o==="m"||o==="M")this.curCommandType=$.MOVE_TO,this.curCommandRelative=o==="m";else if(o==="l"||o==="L")this.curCommandType=$.LINE_TO,this.curCommandRelative=o==="l";else if(o==="c"||o==="C")this.curCommandType=$.CURVE_TO,this.curCommandRelative=o==="c";else if(o==="s"||o==="S")this.curCommandType=$.SMOOTH_CURVE_TO,this.curCommandRelative=o==="s";else if(o==="q"||o==="Q")this.curCommandType=$.QUAD_TO,this.curCommandRelative=o==="q";else if(o==="t"||o==="T")this.curCommandType=$.SMOOTH_QUAD_TO,this.curCommandRelative=o==="t";else if(o==="a"||o==="A")this.curCommandType=$.ARC,this.curCommandRelative=o==="a";else throw new SyntaxError(`Unexpected character "${o}" at index ${n}.`)}}return i}transform(e){return Object.create(this,{parse:{value(s,n=[]){const o=Object.getPrototypeOf(this).parse.call(this,s);for(const a of o){const l=e(a);Array.isArray(l)?n.push(...l):n.push(l)}return n}}})}}const Lt=class Lt extends hd{constructor(e){super();$t(this,"commands");typeof e=="string"?this.commands=Lt.parse(e):this.commands=e}encode(){return Lt.encode(this.commands)}getBounds(){const e=oe.CALCULATE_BOUNDS();return this.transform(e),e}transform(e){const i=[];for(const s of this.commands){const n=e(s);Array.isArray(n)?i.push(...n):i.push(n)}return this.commands=i,this}reverse(e=!0){return this.commands=oe.REVERSE_PATH(this.commands,e),this}static encode(e){return Vv(e)}static parse(e){const i=new h1,s=[];return i.parse(e,s),i.finish(s),s}};$t(Lt,"CLOSE_PATH",1),$t(Lt,"MOVE_TO",2),$t(Lt,"HORIZ_LINE_TO",4),$t(Lt,"VERT_LINE_TO",8),$t(Lt,"LINE_TO",16),$t(Lt,"CURVE_TO",32),$t(Lt,"SMOOTH_CURVE_TO",64),$t(Lt,"QUAD_TO",128),$t(Lt,"SMOOTH_QUAD_TO",256),$t(Lt,"ARC",512),$t(Lt,"LINE_COMMANDS",Lt.LINE_TO|Lt.HORIZ_LINE_TO|Lt.VERT_LINE_TO),$t(Lt,"DRAWING_COMMANDS",Lt.HORIZ_LINE_TO|Lt.VERT_LINE_TO|Lt.LINE_TO|Lt.CURVE_TO|Lt.SMOOTH_CURVE_TO|Lt.QUAD_TO|Lt.SMOOTH_QUAD_TO|Lt.ARC);let $=Lt;const u1={[$.MOVE_TO]:2,[$.LINE_TO]:2,[$.HORIZ_LINE_TO]:1,[$.VERT_LINE_TO]:1,[$.CLOSE_PATH]:0,[$.QUAD_TO]:4,[$.SMOOTH_QUAD_TO]:2,[$.CURVE_TO]:6,[$.SMOOTH_CURVE_TO]:4,[$.ARC]:7},Te=[];for(let r=0;r<256;++r)Te.push((r+256).toString(16).slice(1));function c1(r,t=0){return(Te[r[t+0]]+Te[r[t+1]]+Te[r[t+2]]+Te[r[t+3]]+"-"+Te[r[t+4]]+Te[r[t+5]]+"-"+Te[r[t+6]]+Te[r[t+7]]+"-"+Te[r[t+8]]+Te[r[t+9]]+"-"+Te[r[t+10]]+Te[r[t+11]]+Te[r[t+12]]+Te[r[t+13]]+Te[r[t+14]]+Te[r[t+15]]).toLowerCase()}let Ka;const d1=new Uint8Array(16);function f1(){if(!Ka){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ka=crypto.getRandomValues.bind(crypto)}return Ka(d1)}const cd={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function p1(r,t,e){var s;if(cd.randomUUID&&!r)return cd.randomUUID();r=r||{};const i=r.random??((s=r.rng)==null?void 0:s.call(r))??f1();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,c1(i)}const m1=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:s,stroke:n,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${s||"0.25"};`),n&&(l+=`stroke:${n};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},Za=(r,t=0)=>{const{minX:e,minY:i,maxX:s,maxY:n}=r;return{x:e-t,y:i-t,w:s-e+2*t,h:n-i+2*t}},Qr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,g1=r=>({}),dd=r=>({grab:r[0]});function y1(r){let t,e,i,s;const n=r[8].default,o=Hc(n,r,r[7],dd);return{c(){t=st("g"),o&&o.c(),T(t,"class","a9s-annotation selected")},m(a,l){at(a,t,l),o&&o.m(t,null),e=!0,i||(s=[Pt(t,"pointerup",r[2]),Pt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Vc(o,n,a,a[7],e?Xc(n,a[7],l,g1):zc(a[7]),dd)},i(a){e||(K(o,a),e=!0)},o(a){lt(o,a),e=!1},d(a){a&&nt(t),o&&o.d(a),i=!1,Ye(s)}}}function _1(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Ki();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,u,c,d;const f=_=>y=>{if(u=_,h){const{left:g,top:x}=h.getBoundingClientRect(),E=y.clientX-g,R=y.clientY-x;c=l.elementToImage(E,R)}else{const{offsetX:g,offsetY:x}=y;c=l.elementToImage(g,x)}d=o,y.target.setPointerCapture(y.pointerId),n("grab",y)},p=_=>{if(u){const[y,v]=l.elementToImage(_.offsetX,_.offsetY),g=[y-c[0],v-c[1]];e(3,o=a(d,u,g)),n("change",o)}},m=_=>{_.target.releasePointerCapture(_.pointerId),u=void 0,d=o,n("release",_)};return r.$$set=_=>{"shape"in _&&e(3,o=_.shape),"editor"in _&&e(4,a=_.editor),"transform"in _&&e(5,l=_.transform),"svgEl"in _&&e(6,h=_.svgEl),"$$scope"in _&&e(7,s=_.$$scope)},[f,p,m,o,a,l,h,s,i]}class Qa extends se{constructor(t){super(),ie(this,t,_1,y1,qt,{shape:3,editor:4,transform:5,svgEl:6})}}function v1(r){let t,e,i,s,n,o,a,l,h=r[3]&&fd(r);return{c(){t=st("g"),e=st("circle"),h&&h.c(),s=st("circle"),T(e,"class","a9s-handle-buffer"),T(e,"cx",r[0]),T(e,"cy",r[1]),T(e,"r",i=r[5]+6/r[2]),T(s,"class",n=`a9s-handle-dot${r[3]?" selected":""}`),T(s,"cx",r[0]),T(s,"cy",r[1]),T(s,"r",r[5]),T(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(u,c){at(u,t,c),Ct(t,e),h&&h.m(t,null),Ct(t,s),a||(l=[Pt(e,"pointerenter",r[11]),Pt(e,"pointerleave",r[12]),Pt(e,"pointerdown",r[13]),Pt(e,"pointerdown",r[6]),Pt(e,"pointerup",r[14]),Pt(e,"pointerup",r[7])],a=!0)},p(u,c){c&1&&T(e,"cx",u[0]),c&2&&T(e,"cy",u[1]),c&36&&i!==(i=u[5]+6/u[2])&&T(e,"r",i),u[3]?h?h.p(u,c):(h=fd(u),h.c(),h.m(t,s)):h&&(h.d(1),h=null),c&8&&n!==(n=`a9s-handle-dot${u[3]?" selected":""}`)&&T(s,"class",n),c&1&&T(s,"cx",u[0]),c&2&&T(s,"cy",u[1]),c&32&&T(s,"r",u[5]),c&256&&o!==(o=`a9s-handle ${u[8].class||""}`.trim())&&T(t,"class",o)},d(u){u&&nt(t),h&&h.d(),a=!1,Ye(l)}}}function x1(r){let t,e,i,s,n,o,a,l,h;return{c(){t=st("g"),e=st("circle"),s=st("circle"),o=st("circle"),T(e,"cx",r[0]),T(e,"cy",r[1]),T(e,"r",i=r[5]*10),T(e,"class","a9s-touch-halo"),jr(e,"touched",r[4]),T(s,"cx",r[0]),T(s,"cy",r[1]),T(s,"r",n=r[5]+10/r[2]),T(s,"class","a9s-handle-buffer"),T(o,"class","a9s-handle-dot"),T(o,"cx",r[0]),T(o,"cy",r[1]),T(o,"r",a=r[5]+2/r[2]),T(t,"class","a9s-touch-handle")},m(u,c){at(u,t,c),Ct(t,e),Ct(t,s),Ct(t,o),l||(h=[Pt(s,"pointerdown",r[9]),Pt(s,"pointerup",r[10]),Pt(s,"pointerdown",r[6]),Pt(s,"pointerup",r[7])],l=!0)},p(u,c){c&1&&T(e,"cx",u[0]),c&2&&T(e,"cy",u[1]),c&32&&i!==(i=u[5]*10)&&T(e,"r",i),c&16&&jr(e,"touched",u[4]),c&1&&T(s,"cx",u[0]),c&2&&T(s,"cy",u[1]),c&36&&n!==(n=u[5]+10/u[2])&&T(s,"r",n),c&1&&T(o,"cx",u[0]),c&2&&T(o,"cy",u[1]),c&36&&a!==(a=u[5]+2/u[2])&&T(o,"r",a)},d(u){u&&nt(t),l=!1,Ye(h)}}}function fd(r){let t,e;return{c(){t=st("circle"),T(t,"class","a9s-handle-selected"),T(t,"cx",r[0]),T(t,"cy",r[1]),T(t,"r",e=r[5]+8/r[2])},m(i,s){at(i,t,s)},p(i,s){s&1&&T(t,"cx",i[0]),s&2&&T(t,"cy",i[1]),s&36&&e!==(e=i[5]+8/i[2])&&T(t,"r",e)},d(i){i&&nt(t)}}}function b1(r){let t;function e(n,o){return Qr?x1:v1}let s=e()(r);return{c(){s.c(),t=Ge()},m(n,o){s.m(n,o),at(n,t,o)},p(n,[o]){s.p(n,o)},i:Qt,o:Qt,d(n){n&&nt(t),s.d(n)}}}function E1(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=y=>{y.pointerType==="touch"&&e(4,l=!0)},u=()=>e(4,l=!1);function c(y){Me.call(this,r,y)}function d(y){Me.call(this,r,y)}function f(y){Me.call(this,r,y)}function p(y){Me.call(this,r,y)}function m(y){Me.call(this,r,y)}function _(y){Me.call(this,r,y)}return r.$$set=y=>{e(8,t=Fa(Fa({},t),Yc(y))),"x"in y&&e(0,s=y.x),"y"in y&&e(1,n=y.y),"scale"in y&&e(2,o=y.scale),"selected"in y&&e(3,a=y.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Yc(t),[s,n,o,a,l,i,h,u,t,c,d,f,p,m,_]}class es extends se{constructor(t){super(),ie(this,t,E1,b1,qt,{x:0,y:1,scale:2,selected:3})}}function w1(r){let t,e,i,s,n,o,a;return{c(){t=st("g"),e=st("circle"),s=st("circle"),n=st("circle"),T(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),T(e,"cx",r[0]),T(e,"cy",r[1]),T(e,"r",i=1.75*r[2]),T(s,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),T(s,"cx",r[0]),T(s,"cy",r[1]),T(s,"r",r[2]),T(n,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),T(n,"cx",r[0]),T(n,"cy",r[1]),T(n,"r",r[2]),T(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){at(l,t,h),Ct(t,e),Ct(t,s),Ct(t,n),o||(a=[Pt(e,"pointerdown",r[5]),Pt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&T(e,"cx",l[0]),h&2&&T(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&T(e,"r",i),h&1&&T(s,"cx",l[0]),h&2&&T(s,"cy",l[1]),h&4&&T(s,"r",l[2]),h&1&&T(n,"cx",l[0]),h&2&&T(n,"cy",l[1]),h&4&&T(n,"r",l[2])},d(l){l&&nt(t),o=!1,Ye(a)}}}function T1(r){let t;return{c(){t=st("circle"),T(t,"cx",r[0]),T(t,"cy",r[1]),T(t,"r",r[2])},m(e,i){at(e,t,i)},p(e,i){i&1&&T(t,"cx",e[0]),i&2&&T(t,"cy",e[1]),i&4&&T(t,"r",e[2])},d(e){e&&nt(t)}}}function A1(r){let t;function e(n,o){return Qr?T1:w1}let s=e()(r);return{c(){s.c(),t=Ge()},m(n,o){s.m(n,o),at(n,t,o)},p(n,[o]){s.p(n,o)},i:Qt,o:Qt,d(n){n&&nt(t),s.d(n)}}}function S1(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){Me.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,s=h.x),"y"in h&&e(1,n=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[s,n,i,a,o,l]}class pd extends se{constructor(t){super(),ie(this,t,S1,A1,qt,{x:0,y:1,scale:4})}}function Ja(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function md(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function tl(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function el(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function gd(r){let t,e,i,s;return{c(){t=st("circle"),T(t,"cx",e=r[28][0]),T(t,"cy",i=r[28][1]),T(t,"r",s=Hs/r[3]),T(t,"class","svelte-1h2slbm")},m(n,o){at(n,t,o)},p(n,o){o[0]&1088&&e!==(e=n[28][0])&&T(t,"cx",e),o[0]&1088&&i!==(i=n[28][1])&&T(t,"cy",i),o[0]&8&&s!==(s=Hs/n[3])&&T(t,"r",s)},d(n){n&&nt(t)}}}function yd(r){let t,e,i,s,n,o,a,l,h,u;return{c(){t=st("mask"),e=st("rect"),a=st("circle"),T(e,"x",i=r[9].x),T(e,"y",s=r[9].y),T(e,"width",n=r[9].w),T(e,"height",o=r[9].h),T(e,"class","svelte-1h2slbm"),T(a,"cx",l=r[28][0]),T(a,"cy",h=r[28][1]),T(a,"r",u=Hs/r[3]),T(a,"class","svelte-1h2slbm"),T(t,"id",`${r[19]}-inner`),T(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,d){at(c,t,d),Ct(t,e),Ct(t,a)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&T(e,"x",i),d[0]&512&&s!==(s=c[9].y)&&T(e,"y",s),d[0]&512&&n!==(n=c[9].w)&&T(e,"width",n),d[0]&512&&o!==(o=c[9].h)&&T(e,"height",o),d[0]&1088&&l!==(l=c[28][0])&&T(a,"cx",l),d[0]&1088&&h!==(h=c[28][1])&&T(a,"cy",h),d[0]&8&&u!==(u=Hs/c[3])&&T(a,"r",u)},d(c){c&&nt(t)}}}function _d(r){let t,e;return t=new es({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(){Jt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){Ht(t.$$.fragment)},m(i,s){Ft(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&32&&(n.x=r[28][0]),s[0]&32&&(n.y=r[28][1]),s[0]&8&&(n.scale=r[3]),s[0]&256&&(n.selected=r[8].includes(r[30])),t.$set(n)},i(i){e||(K(t.$$.fragment,i),e=!0)},o(i){lt(t.$$.fragment,i),e=!1},d(i){kt(t,i)}}}function vd(r){let t,e;return t=new pd({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Jt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Ht(t.$$.fragment)},m(i,s){Ft(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&1088&&(n.x=r[28][0]),s[0]&1088&&(n.y=r[28][1]),s[0]&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(K(t.$$.fragment,i),e=!0)},o(i){lt(t.$$.fragment,i),e=!1},d(i){kt(t,i)}}}function C1(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v,g,x,E,R=r[6]!==void 0&&!r[7]&&gd(el(r)),S=r[6]!==void 0&&!r[7]&&yd(tl(r)),M=Pe(r[5].points),P=[];for(let I=0;I<M.length;I+=1)P[I]=_d(md(r,M,I));const F=I=>lt(P[I],1,1,()=>{P[I]=null});let U=r[6]!==void 0&&!r[7]&&vd(Ja(r));return{c(){t=st("defs"),e=st("mask"),i=st("rect"),l=st("polygon"),R&&R.c(),S&&S.c(),u=Le(),c=st("polygon"),f=Le(),p=st("polygon"),_=Le();for(let I=0;I<P.length;I+=1)P[I].c();y=Le(),U&&U.c(),v=Ge(),T(i,"x",s=r[9].x),T(i,"y",n=r[9].y),T(i,"width",o=r[9].w),T(i,"height",a=r[9].h),T(i,"class","svelte-1h2slbm"),T(l,"points",h=r[5].points.map(xd).join(" ")),T(l,"class","svelte-1h2slbm"),T(e,"id",`${r[19]}-outer`),T(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),T(c,"class","a9s-outer"),T(c,"mask",`url(#${r[19]}-outer)`),T(c,"points",d=r[5].points.map(bd).join(" ")),T(p,"class","a9s-inner a9s-shape-handle"),T(p,"mask",`url(#${r[19]}-inner)`),T(p,"style",r[1]),T(p,"points",m=r[5].points.map(Ed).join(" "))},m(I,A){at(I,t,A),Ct(t,e),Ct(e,i),Ct(e,l),R&&R.m(e,null),S&&S.m(t,null),at(I,u,A),at(I,c,A),at(I,f,A),at(I,p,A),at(I,_,A);for(let w=0;w<P.length;w+=1)P[w]&&P[w].m(I,A);at(I,y,A),U&&U.m(I,A),at(I,v,A),g=!0,x||(E=[Pt(c,"pointerup",r[14]),Pt(c,"pointerdown",function(){Jt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(p,"pointermove",r[13]),Pt(p,"pointerup",r[14]),Pt(p,"pointerdown",function(){Jt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],x=!0)},p(I,A){if(r=I,(!g||A[0]&512&&s!==(s=r[9].x))&&T(i,"x",s),(!g||A[0]&512&&n!==(n=r[9].y))&&T(i,"y",n),(!g||A[0]&512&&o!==(o=r[9].w))&&T(i,"width",o),(!g||A[0]&512&&a!==(a=r[9].h))&&T(i,"height",a),(!g||A[0]&32&&h!==(h=r[5].points.map(xd).join(" ")))&&T(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(el(r),A):(R=gd(el(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?S?S.p(tl(r),A):(S=yd(tl(r)),S.c(),S.m(t,null)):S&&(S.d(1),S=null),(!g||A[0]&32&&d!==(d=r[5].points.map(bd).join(" ")))&&T(c,"points",d),(!g||A[0]&2)&&T(p,"style",r[1]),(!g||A[0]&32&&m!==(m=r[5].points.map(Ed).join(" ")))&&T(p,"points",m),A[0]&134322472){M=Pe(r[5].points);let w;for(w=0;w<M.length;w+=1){const C=md(r,M,w);P[w]?(P[w].p(C,A),K(P[w],1)):(P[w]=_d(C),P[w].c(),K(P[w],1),P[w].m(y.parentNode,y))}for(fe(),w=M.length;w<P.length;w+=1)F(w);pe()}r[6]!==void 0&&!r[7]?U?(U.p(Ja(r),A),A[0]&192&&K(U,1)):(U=vd(Ja(r)),U.c(),K(U,1),U.m(v.parentNode,v)):U&&(fe(),lt(U,1,1,()=>{U=null}),pe())},i(I){if(!g){for(let A=0;A<M.length;A+=1)K(P[A]);K(U),g=!0}},o(I){P=P.filter(Boolean);for(let A=0;A<P.length;A+=1)lt(P[A]);lt(U),g=!1},d(I){I&&(nt(t),nt(u),nt(c),nt(f),nt(p),nt(_),nt(y),nt(v)),R&&R.d(),S&&S.d(),Wr(P,I),U&&U.d(I),x=!1,Ye(E)}}}function I1(r){let t,e;return t=new Qa({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[C1,({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(){Ht(t.$$.fragment)},m(i,s){Ft(t,i,s),e=!0},p(i,s){const n={};s[0]&1&&(n.shape=i[0]),s[0]&4&&(n.transform=i[2]),s[0]&16&&(n.svgEl=i[4]),s[0]&134219754|s[1]&1&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(K(t.$$.fragment,i),e=!0)},o(i){lt(t.$$.fragment,i),e=!1},d(i){kt(t,i)}}}const R1=250,M1=1e3,P1=12,Hs=4.5,xd=r=>r.join(","),bd=r=>r.join(","),Ed=r=>r.join(",");function O1(r,t,e){let i,s,n;const o=Ki();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:u=1}=t,{svgEl:c}=t,d,f=!1,p,m=[];const _=()=>e(7,f=!0),y=()=>e(7,f=!1),v=w=>{if(m.length>0||!s.some(k=>k.visible)){e(6,d=void 0);return}const[C,D]=h.elementToImage(w.offsetX,w.offsetY),N=k=>Math.pow(k[0]-C,2)+Math.pow(k[1]-D,2),B=i.points.reduce((k,X)=>N(X)<N(k)?X:k),V=s.filter(k=>k.visible).reduce((k,X)=>N(X.point)<N(k.point)?X:k),L=Math.pow(M1/u,2);N(B)<L||N(V.point)<L?e(6,d=s.indexOf(V)):e(6,d=void 0)},g=()=>{document.activeElement!==c&&c.focus()},x=()=>{e(8,m=[]),g()},E=w=>{e(7,f=!0),w.preventDefault(),w.stopPropagation(),p=performance.now()},R=w=>C=>{if(!p||Qr||performance.now()-p>R1)return;const D=m.includes(w);C.metaKey||C.ctrlKey||C.shiftKey?D?e(8,m=m.filter(N=>N!==w)):e(8,m=[...m,w]):D&&m.length>1?e(8,m=[w]):D?e(8,m=[]):e(8,m=[w]),g()},S=(w,C,D)=>{g();let N;const B=w.geometry;m.length>1?N=B.points.map(([L,O],k)=>m.includes(k)?[L+D[0],O+D[1]]:[L,O]):C==="SHAPE"?N=B.points.map(([L,O])=>[L+D[0],O+D[1]]):N=B.points.map(([L,O],k)=>C===`HANDLE-${k}`?[L+D[0],O+D[1]]:[L,O]);const V=dr(N);return{...w,geometry:{points:N,bounds:V}}},M=w=>async C=>{C.stopPropagation();const D=[...i.points.slice(0,w+1),s[w].point,...i.points.slice(w+1)],N=dr(D);o("change",{...a,geometry:{points:D,bounds:N}}),await Kc();const B=[...document.querySelectorAll(".a9s-handle")][w+1];if(B!=null&&B.firstChild){const V=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:C.clientX,clientY:C.clientY,pointerId:C.pointerId,pointerType:C.pointerType,isPrimary:C.isPrimary,buttons:C.buttons});B.firstChild.dispatchEvent(V)}},P=()=>{if(i.points.length<4)return;const w=i.points.filter((D,N)=>!m.includes(N)),C=dr(w);o("change",{...a,geometry:{points:w,bounds:C}}),e(8,m=[])};vi(()=>{if(Qr)return;const w=C=>{(C.key==="Delete"||C.key==="Backspace")&&(C.preventDefault(),P())};return c.addEventListener("pointermove",v),c.addEventListener("keydown",w),()=>{c.removeEventListener("pointermove",v),c.removeEventListener("keydown",w)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(w){Me.call(this,r,w)}function I(w){Me.call(this,r,w)}function A(w){Me.call(this,r,w)}return r.$$set=w=>{"shape"in w&&e(0,a=w.shape),"computedStyle"in w&&e(1,l=w.computedStyle),"transform"in w&&e(2,h=w.transform),"viewportScale"in w&&e(3,u=w.viewportScale),"svgEl"in w&&e(4,c=w.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,s=Qr?[]:i.points.map((w,C)=>{const D=C===i.points.length-1?i.points[0]:i.points[C+1],N=(w[0]+D[0])/2,B=(w[1]+D[1])/2,L=Math.sqrt(Math.pow(D[0]-N,2)+Math.pow(D[1]-B,2))>P1/u;return{point:[N,B],visible:L}})),r.$$.dirty[0]&40&&e(9,n=Za(i.bounds,Hs/u))},[a,l,h,u,c,i,d,f,m,n,s,_,y,v,x,E,R,S,M,F,U,I,A]}class N1 extends se{constructor(t){super(),ie(this,t,O1,I1,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function D1(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v,g,x,E,R,S,M,P,F,U,I,A,w,C,D,N,B,V,L,O,k,X,Y,q,pt,_t,W,bt,dt,mt,xt,Mt,Nt,_e,jt,et,Ke,mn;return dt=new es({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),dt.$on("pointerdown",function(){Jt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),xt=new es({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),xt.$on("pointerdown",function(){Jt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Nt=new es({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Nt.$on("pointerdown",function(){Jt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),jt=new es({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),jt.$on("pointerdown",function(){Jt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=st("defs"),e=st("mask"),i=st("rect"),l=st("rect"),f=Le(),p=st("rect"),g=Le(),x=st("rect"),P=Le(),F=st("rect"),w=Le(),C=st("rect"),V=Le(),L=st("rect"),Y=Le(),q=st("rect"),bt=Le(),Ht(dt.$$.fragment),mt=Le(),Ht(xt.$$.fragment),Mt=Le(),Ht(Nt.$$.fragment),_e=Le(),Ht(jt.$$.fragment),T(i,"class","rect-mask-bg svelte-1njczvj"),T(i,"x",s=r[6].x),T(i,"y",n=r[6].y),T(i,"width",o=r[6].w),T(i,"height",a=r[6].h),T(l,"class","rect-mask-fg svelte-1njczvj"),T(l,"x",h=r[5].x),T(l,"y",u=r[5].y),T(l,"width",c=r[5].w),T(l,"height",d=r[5].h),T(e,"id",r[8]),T(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),T(p,"class","a9s-outer"),T(p,"mask",`url(#${r[8]})`),T(p,"x",m=r[5].x),T(p,"y",_=r[5].y),T(p,"width",y=r[5].w),T(p,"height",v=r[5].h),T(x,"class","a9s-inner a9s-shape-handle"),T(x,"style",r[1]),T(x,"x",E=r[5].x),T(x,"y",R=r[5].y),T(x,"width",S=r[5].w),T(x,"height",M=r[5].h),T(F,"class","a9s-edge-handle a9s-edge-handle-top"),T(F,"x",U=r[5].x),T(F,"y",I=r[5].y),T(F,"height",1),T(F,"width",A=r[5].w),T(C,"class","a9s-edge-handle a9s-edge-handle-right"),T(C,"x",D=r[5].x+r[5].w),T(C,"y",N=r[5].y),T(C,"height",B=r[5].h),T(C,"width",1),T(L,"class","a9s-edge-handle a9s-edge-handle-bottom"),T(L,"x",O=r[5].x),T(L,"y",k=r[5].y+r[5].h),T(L,"height",1),T(L,"width",X=r[5].w),T(q,"class","a9s-edge-handle a9s-edge-handle-left"),T(q,"x",pt=r[5].x),T(q,"y",_t=r[5].y),T(q,"height",W=r[5].h),T(q,"width",1)},m(j,H){at(j,t,H),Ct(t,e),Ct(e,i),Ct(e,l),at(j,f,H),at(j,p,H),at(j,g,H),at(j,x,H),at(j,P,H),at(j,F,H),at(j,w,H),at(j,C,H),at(j,V,H),at(j,L,H),at(j,Y,H),at(j,q,H),at(j,bt,H),Ft(dt,j,H),at(j,mt,H),Ft(xt,j,H),at(j,Mt,H),Ft(Nt,j,H),at(j,_e,H),Ft(jt,j,H),et=!0,Ke||(mn=[Pt(p,"pointerdown",function(){Jt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(x,"pointerdown",function(){Jt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(F,"pointerdown",function(){Jt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Pt(C,"pointerdown",function(){Jt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Pt(L,"pointerdown",function(){Jt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Pt(q,"pointerdown",function(){Jt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],Ke=!0)},p(j,H){r=j,(!et||H&64&&s!==(s=r[6].x))&&T(i,"x",s),(!et||H&64&&n!==(n=r[6].y))&&T(i,"y",n),(!et||H&64&&o!==(o=r[6].w))&&T(i,"width",o),(!et||H&64&&a!==(a=r[6].h))&&T(i,"height",a),(!et||H&32&&h!==(h=r[5].x))&&T(l,"x",h),(!et||H&32&&u!==(u=r[5].y))&&T(l,"y",u),(!et||H&32&&c!==(c=r[5].w))&&T(l,"width",c),(!et||H&32&&d!==(d=r[5].h))&&T(l,"height",d),(!et||H&32&&m!==(m=r[5].x))&&T(p,"x",m),(!et||H&32&&_!==(_=r[5].y))&&T(p,"y",_),(!et||H&32&&y!==(y=r[5].w))&&T(p,"width",y),(!et||H&32&&v!==(v=r[5].h))&&T(p,"height",v),(!et||H&2)&&T(x,"style",r[1]),(!et||H&32&&E!==(E=r[5].x))&&T(x,"x",E),(!et||H&32&&R!==(R=r[5].y))&&T(x,"y",R),(!et||H&32&&S!==(S=r[5].w))&&T(x,"width",S),(!et||H&32&&M!==(M=r[5].h))&&T(x,"height",M),(!et||H&32&&U!==(U=r[5].x))&&T(F,"x",U),(!et||H&32&&I!==(I=r[5].y))&&T(F,"y",I),(!et||H&32&&A!==(A=r[5].w))&&T(F,"width",A),(!et||H&32&&D!==(D=r[5].x+r[5].w))&&T(C,"x",D),(!et||H&32&&N!==(N=r[5].y))&&T(C,"y",N),(!et||H&32&&B!==(B=r[5].h))&&T(C,"height",B),(!et||H&32&&O!==(O=r[5].x))&&T(L,"x",O),(!et||H&32&&k!==(k=r[5].y+r[5].h))&&T(L,"y",k),(!et||H&32&&X!==(X=r[5].w))&&T(L,"width",X),(!et||H&32&&pt!==(pt=r[5].x))&&T(q,"x",pt),(!et||H&32&&_t!==(_t=r[5].y))&&T(q,"y",_t),(!et||H&32&&W!==(W=r[5].h))&&T(q,"height",W);const kr={};H&32&&(kr.x=r[5].x),H&32&&(kr.y=r[5].y),H&8&&(kr.scale=r[3]),dt.$set(kr);const Ur={};H&32&&(Ur.x=r[5].x+r[5].w),H&32&&(Ur.y=r[5].y),H&8&&(Ur.scale=r[3]),xt.$set(Ur);const Gr={};H&32&&(Gr.x=r[5].x+r[5].w),H&32&&(Gr.y=r[5].y+r[5].h),H&8&&(Gr.scale=r[3]),Nt.$set(Gr);const Hr={};H&32&&(Hr.x=r[5].x),H&32&&(Hr.y=r[5].y+r[5].h),H&8&&(Hr.scale=r[3]),jt.$set(Hr)},i(j){et||(K(dt.$$.fragment,j),K(xt.$$.fragment,j),K(Nt.$$.fragment,j),K(jt.$$.fragment,j),et=!0)},o(j){lt(dt.$$.fragment,j),lt(xt.$$.fragment,j),lt(Nt.$$.fragment,j),lt(jt.$$.fragment,j),et=!1},d(j){j&&(nt(t),nt(f),nt(p),nt(g),nt(x),nt(P),nt(F),nt(w),nt(C),nt(V),nt(L),nt(Y),nt(q),nt(bt),nt(mt),nt(Mt),nt(_e)),kt(dt,j),kt(xt,j),kt(Nt,j),kt(jt,j),Ke=!1,Ye(mn)}}}function L1(r){let t,e;return t=new Qa({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[D1,({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(){Ht(t.$$.fragment)},m(i,s){Ft(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&16&&(n.svgEl=i[4]),s&12394&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(K(t.$$.fragment,i),e=!0)},o(i){lt(t.$$.fragment,i),e=!1},d(i){kt(t,i)}}}function B1(r,t,e){let i,s,{shape:n}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const u=(m,_,y)=>{const v=m.geometry.bounds;let[g,x]=[v.minX,v.minY],[E,R]=[v.maxX,v.maxY];const[S,M]=y;if(_==="SHAPE")g+=S,E+=S,x+=M,R+=M;else{switch(_){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{x+=M;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=M;break}}switch(_){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=S;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{E+=S;break}}}const P=Math.min(g,E),F=Math.min(x,R),U=Math.abs(E-g),I=Math.abs(R-x);return{...m,geometry:{x:P,y:F,w:U,h:I,bounds:{minX:P,minY:F,maxX:P+U,maxY:F+I}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){Me.call(this,r,m)}function f(m){Me.call(this,r,m)}function p(m){Me.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,n=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=n.geometry),r.$$.dirty&40&&e(6,s=Za(i.bounds,2/l))},[n,o,a,l,h,i,s,u,c,d,f,p]}class F1 extends se{constructor(t){super(),ie(this,t,B1,L1,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var wd=Object.prototype.hasOwnProperty;function rl(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--&&rl(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(wd.call(r,e)&&++i&&!wd.call(t,e)||!(e in t)||!rl(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const k1=12,U1=(r,t)=>r.polygons.reduce((e,i,s)=>{const n=i.rings.reduce((o,a,l)=>{const h=a.points.map((u,c)=>{const d=c===a.points.length-1?a.points[0]:a.points[c+1],f=(u[0]+d[0])/2,p=(u[1]+d[1])/2,_=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>k1/t;return{point:[f,p],visible:_,elementIdx:s,ringIdx:l,pointIdx:c}});return[...o,...h]},[]);return[...e,...n]},[]);function il(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Td(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Ad(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Sd(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function sl(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function nl(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Cd(r){let t,e,i,s;return{c(){t=st("circle"),T(t,"cx",e=r[29][0]),T(t,"cy",i=r[29][1]),T(t,"r",s=$s/r[3]),T(t,"class","svelte-1vxo6dc")},m(n,o){at(n,t,o)},p(n,o){o[0]&1088&&e!==(e=n[29][0])&&T(t,"cx",e),o[0]&1088&&i!==(i=n[29][1])&&T(t,"cy",i),o[0]&8&&s!==(s=$s/n[3])&&T(t,"r",s)},d(n){n&&nt(t)}}}function Id(r){let t,e,i,s,n,o,a,l,h,u;return{c(){t=st("mask"),e=st("rect"),a=st("circle"),T(e,"x",i=r[9].x),T(e,"y",s=r[9].y),T(e,"width",n=r[9].w),T(e,"height",o=r[9].h),T(e,"class","svelte-1vxo6dc"),T(a,"cx",l=r[29][0]),T(a,"cy",h=r[29][1]),T(a,"r",u=$s/r[3]),T(a,"class","svelte-1vxo6dc"),T(t,"id",`${r[18]}-${r[32]}-inner`),T(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(c,d){at(c,t,d),Ct(t,e),Ct(t,a)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&T(e,"x",i),d[0]&512&&s!==(s=c[9].y)&&T(e,"y",s),d[0]&512&&n!==(n=c[9].w)&&T(e,"width",n),d[0]&512&&o!==(o=c[9].h)&&T(e,"height",o),d[0]&1088&&l!==(l=c[29][0])&&T(a,"cx",l),d[0]&1088&&h!==(h=c[29][1])&&T(a,"cy",h),d[0]&8&&u!==(u=$s/c[3])&&T(a,"r",u)},d(c){c&&nt(t)}}}function Rd(r){let t,e;function i(...s){return r[19](r[32],r[35],r[37],...s)}return t=new es({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(){Jt(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(){Ht(t.$$.fragment)},m(s,n){Ft(t,s,n),e=!0},p(s,n){r=s;const o={};n[0]&32&&(o.x=r[29][0]),n[0]&32&&(o.y=r[29][1]),n[0]&8&&(o.scale=r[3]),n[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(s){e||(K(t.$$.fragment,s),e=!0)},o(s){lt(t.$$.fragment,s),e=!1},d(s){kt(t,s)}}}function Md(r){let t,e,i=Pe(r[33].points),s=[];for(let o=0;o<i.length;o+=1)s[o]=Rd(Sd(r,i,o));const n=o=>lt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Ge()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);at(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Pe(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Sd(o,i,l);s[l]?(s[l].p(h,a),K(s[l],1)):(s[l]=Rd(h),s[l].c(),K(s[l],1),s[l].m(t.parentNode,t))}for(fe(),l=i.length;l<s.length;l+=1)n(l);pe()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)K(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)lt(s[a]);e=!1},d(o){o&&nt(t),Wr(s,o)}}}function Pd(r){let t,e,i,s,n,o,a,l,h,u,c,d,f,p,m,_,y,v=r[6]!==void 0&&!r[7]&&Cd(nl(r)),g=r[6]!==void 0&&!r[7]&&Id(sl(r)),x=Pe(r[30].rings),E=[];for(let S=0;S<x.length;S+=1)E[S]=Md(Ad(r,x,S));const R=S=>lt(E[S],1,1,()=>{E[S]=null});return{c(){t=st("g"),e=st("defs"),i=st("mask"),s=st("rect"),h=st("path"),v&&v.c(),g&&g.c(),c=st("path"),f=st("path");for(let S=0;S<E.length;S+=1)E[S].c();T(s,"x",n=r[9].x),T(s,"y",o=r[9].y),T(s,"width",a=r[9].w),T(s,"height",l=r[9].h),T(s,"class","svelte-1vxo6dc"),T(h,"d",u=ts(r[30])),T(h,"class","svelte-1vxo6dc"),T(i,"id",`${r[18]}-${r[32]}-outer`),T(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),T(c,"class","a9s-outer"),T(c,"mask",`url(#${r[18]}-${r[32]}-outer)`),T(c,"fill-rule","evenodd"),T(c,"d",d=ts(r[30])),T(f,"class","a9s-inner"),T(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),T(f,"style",r[1]),T(f,"fill-rule","evenodd"),T(f,"d",p=ts(r[30]))},m(S,M){at(S,t,M),Ct(t,e),Ct(e,i),Ct(i,s),Ct(i,h),v&&v.m(i,null),g&&g.m(e,null),Ct(t,c),Ct(t,f);for(let P=0;P<E.length;P+=1)E[P]&&E[P].m(t,null);m=!0,_||(y=[Pt(c,"pointerup",r[13]),Pt(c,"pointerdown",function(){Jt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Pt(f,"pointerup",r[13]),Pt(f,"pointerdown",function(){Jt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],_=!0)},p(S,M){if(r=S,(!m||M[0]&512&&n!==(n=r[9].x))&&T(s,"x",n),(!m||M[0]&512&&o!==(o=r[9].y))&&T(s,"y",o),(!m||M[0]&512&&a!==(a=r[9].w))&&T(s,"width",a),(!m||M[0]&512&&l!==(l=r[9].h))&&T(s,"height",l),(!m||M[0]&32&&u!==(u=ts(r[30])))&&T(h,"d",u),r[6]!==void 0&&!r[7]?v?v.p(nl(r),M):(v=Cd(nl(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(sl(r),M):(g=Id(sl(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||M[0]&32&&d!==(d=ts(r[30])))&&T(c,"d",d),(!m||M[0]&2)&&T(f,"style",r[1]),(!m||M[0]&32&&p!==(p=ts(r[30])))&&T(f,"d",p),M[0]&268491048){x=Pe(r[30].rings);let P;for(P=0;P<x.length;P+=1){const F=Ad(r,x,P);E[P]?(E[P].p(F,M),K(E[P],1)):(E[P]=Md(F),E[P].c(),K(E[P],1),E[P].m(t,null))}for(fe(),P=x.length;P<E.length;P+=1)R(P);pe()}},i(S){if(!m){for(let M=0;M<x.length;M+=1)K(E[M]);m=!0}},o(S){E=E.filter(Boolean);for(let M=0;M<E.length;M+=1)lt(E[M]);m=!1},d(S){S&&nt(t),v&&v.d(),g&&g.d(),Wr(E,S),_=!1,Ye(y)}}}function Od(r){let t,e;return t=new pd({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Jt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Ht(t.$$.fragment)},m(i,s){Ft(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&1088&&(n.x=r[29][0]),s[0]&1088&&(n.y=r[29][1]),s[0]&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(K(t.$$.fragment,i),e=!0)},o(i){lt(t.$$.fragment,i),e=!1},d(i){kt(t,i)}}}function G1(r){let t,e,i,s=Pe(r[5].polygons),n=[];for(let l=0;l<s.length;l+=1)n[l]=Pd(Td(r,s,l));const o=l=>lt(n[l],1,1,()=>{n[l]=null});let a=r[6]!==void 0&&!r[7]&&Od(il(r));return{c(){for(let l=0;l<n.length;l+=1)n[l].c();t=Le(),a&&a.c(),e=Ge()},m(l,h){for(let u=0;u<n.length;u+=1)n[u]&&n[u].m(l,h);at(l,t,h),a&&a.m(l,h),at(l,e,h),i=!0},p(l,h){if(h[0]&268763114){s=Pe(l[5].polygons);let u;for(u=0;u<s.length;u+=1){const c=Td(l,s,u);n[u]?(n[u].p(c,h),K(n[u],1)):(n[u]=Pd(c),n[u].c(),K(n[u],1),n[u].m(t.parentNode,t))}for(fe(),u=s.length;u<n.length;u+=1)o(u);pe()}l[6]!==void 0&&!l[7]?a?(a.p(il(l),h),h[0]&192&&K(a,1)):(a=Od(il(l)),a.c(),K(a,1),a.m(e.parentNode,e)):a&&(fe(),lt(a,1,1,()=>{a=null}),pe())},i(l){if(!i){for(let h=0;h<s.length;h+=1)K(n[h]);K(a),i=!0}},o(l){n=n.filter(Boolean);for(let h=0;h<n.length;h+=1)lt(n[h]);lt(a),i=!1},d(l){l&&(nt(t),nt(e)),Wr(n,l),a&&a.d(l)}}}function H1(r){let t,e;return t=new Qa({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[G1,({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(){Ht(t.$$.fragment)},m(i,s){Ft(t,i,s),e=!0},p(i,s){const n={};s[0]&1&&(n.shape=i[0]),s[0]&4&&(n.transform=i[2]),s[0]&16&&(n.svgEl=i[4]),s[0]&268437482|s[1]&128&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(K(t.$$.fragment,i),e=!0)},o(i){lt(t.$$.fragment,i),e=!1},d(i){kt(t,i)}}}const $1=250,X1=1e3,$s=4.5;function V1(r,t,e){let i,s,n;const o=Ki();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:u=1}=t,{svgEl:c}=t,d,f=!1,p,m=[];const _=()=>e(7,f=!0),y=()=>e(7,f=!1),v=C=>{if(m.length>0||!s.some(X=>X.visible)){e(6,d=void 0);return}const[D,N]=h.elementToImage(C.offsetX,C.offsetY),B=X=>Math.pow(X[0]-D,2)+Math.pow(X[1]-N,2),V=Uv(i).reduce((X,Y)=>B(Y)<B(X)?Y:X),L=s.filter(X=>X.visible).reduce((X,Y)=>B(Y.point)<B(X.point)?Y:X),O=Math.pow(X1/u,2);B(V)<O||B(L.point)<O?e(6,d=s.indexOf(L)):e(6,d=void 0)},g=()=>{document.activeElement!==c&&c.focus()},x=()=>{e(8,m=[]),g()},E=C=>{e(7,f=!0),C.preventDefault(),C.stopPropagation(),p=performance.now()},R=(C,D,N)=>B=>{if(!p||Qr||performance.now()-p>$1)return;const V=O=>O.polygon===C&&O.ring===D&&O.point===N,L=m.some(V);B.metaKey||B.ctrlKey||B.shiftKey?L?e(8,m=m.filter(O=>!V(O))):e(8,m=[...m,{polygon:C,ring:D,point:N}]):L&&m.length>1?e(8,m=[{polygon:C,ring:D,point:N}]):L?e(8,m=[]):e(8,m=[{polygon:C,ring:D,point:N}]),g()},S=(C,D,N)=>{g();const B=C.geometry.polygons;let V;if(D==="SHAPE")V=B.map(L=>{const O=L.rings.map((X,Y)=>({points:X.points.map((pt,_t)=>[pt[0]+N[0],pt[1]+N[1]])})),k=dr(O[0].points);return{rings:O,bounds:k}});else{const[L,O,k,X]=D.split("-").map(Y=>parseInt(Y));V=B.map((Y,q)=>{if(q===O){const pt=Y.rings.map((W,bt)=>bt===k?{points:W.points.map((mt,xt)=>xt===X?[mt[0]+N[0],mt[1]+N[1]]:mt)}:W),_t=dr(pt[0].points);return{rings:pt,bounds:_t}}else return Y})}return{...C,geometry:{polygons:V,bounds:Fn(V)}}},M=C=>async D=>{D.stopPropagation();const N=s[C],B=i.polygons.map((L,O)=>{if(O===N.elementIdx){const k=L.rings.map((Y,q)=>q===N.ringIdx?{points:[...Y.points.slice(0,N.pointIdx+1),N.point,...Y.points.slice(N.pointIdx+1)]}:Y),X=dr(k[0].points);return{rings:k,bounds:X}}else return L});o("change",{...a,geometry:{polygons:B,bounds:Fn(B)}}),await Kc();const V=[...document.querySelectorAll(".a9s-handle")][C+1];if(V!=null&&V.firstChild){const L=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:D.clientX,clientY:D.clientY,pointerId:D.pointerId,pointerType:D.pointerType,isPrimary:D.isPrimary,buttons:D.buttons});V.firstChild.dispatchEvent(L)}},P=()=>{const C=i.polygons.map((N,B)=>{if(m.some(L=>L.polygon===B)){const L=N.rings.map((k,X)=>m.some(q=>q.polygon===B&&q.ring===X)&&k.points.length>3?{points:k.points.filter((pt,_t)=>!m.some(W=>W.polygon===B&&W.ring===X&&W.point===_t))}:k),O=dr(L[0].points);return{rings:L,bounds:O}}else return N});!rl(i.polygons,C)&&(o("change",{...a,geometry:{polygons:C,bounds:Fn(C)}}),e(8,m=[]))};vi(()=>{if(Qr)return;const C=D=>{(D.key==="Delete"||D.key==="Backspace")&&(D.preventDefault(),P())};return c.addEventListener("pointermove",v),c.addEventListener("keydown",C),()=>{c.removeEventListener("pointermove",v),c.removeEventListener("keydown",C)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(C,D,N,{polygon:B,ring:V,point:L})=>B===C&&V===D&&L===N;function I(C){Me.call(this,r,C)}function A(C){Me.call(this,r,C)}function w(C){Me.call(this,r,C)}return r.$$set=C=>{"shape"in C&&e(0,a=C.shape),"computedStyle"in C&&e(1,l=C.computedStyle),"transform"in C&&e(2,h=C.transform),"viewportScale"in C&&e(3,u=C.viewportScale),"svgEl"in C&&e(4,c=C.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,s=Qr?[]:U1(i,u)),r.$$.dirty[0]&40&&e(9,n=Za(i.bounds,$s/u))},[a,l,h,u,c,i,d,f,m,n,s,_,y,x,E,R,S,M,F,U,I,A,w]}class z1 extends se{constructor(t){super(),ie(this,t,V1,H1,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}qr.RECTANGLE,qr.POLYGON,qr.MULTIPOLYGLON;function Y1(r,t,e){let i;const s=Ki();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:u}=t,c;return vi(()=>(e(6,c=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:u,svgEl:l.closest("svg")}})),c.$on("change",d=>{c.$$set({shape:d.detail}),s("change",d.detail)}),c.$on("grab",d=>s("grab",d.detail)),c.$on("release",d=>s("release",d.detail)),()=>{c.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,n=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,u=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=m1(n,a)),r.$$.dirty&65&&n&&(c==null||c.$set({shape:n.target.selector})),r.$$.dirty&80&&c&&c.$set({transform:h}),r.$$.dirty&96&&c&&c.$set({viewportScale:u}),r.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[n,o,a,l,h,u,c,i]}class W1 extends se{constructor(t){super(),ie(this,t,Y1,null,qt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1;var Ei=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(Ei||{}),Nd=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(Nd||{}),ol=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(ol||{}),yt=(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))(yt||{}),fr=(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))(fr||{}),z=(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))(z||{}),rs=(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))(rs||{}),ft=(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))(ft||{}),J=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(J||{}),Ir=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(Ir||{}),Jr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Jr||{}),pr=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(pr||{}),He=(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))(He||{}),mr=(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))(mr||{}),al=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(al||{}),We=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(We||{}),he=(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))(he||{}),ae=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(ae||{}),gr=(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))(gr||{});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 ll=/iPhone/i,Dd=/iPod/i,Ld=/iPad/i,Bd=/\biOS-universal(?:.+)Mac\b/i,hl=/\bAndroid(?:.+)Mobile\b/i,Fd=/Android/i,is=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Un=/Silk/i,Rr=/Windows Phone/i,kd=/\bWindows(?:.+)ARM\b/i,Ud=/BlackBerry/i,Gd=/BB10/i,Hd=/Opera Mini/i,$d=/\b(CriOS|Chrome)(?:.+)Mobile/i,Xd=/Mobile(?:.+)Firefox\b/i,Vd=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function j1(r){return function(t){return t.test(r)}}function zd(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 s=j1(e),n={apple:{phone:s(ll)&&!s(Rr),ipod:s(Dd),tablet:!s(ll)&&(s(Ld)||Vd(t))&&!s(Rr),universal:s(Bd),device:(s(ll)||s(Dd)||s(Ld)||s(Bd)||Vd(t))&&!s(Rr)},amazon:{phone:s(is),tablet:!s(is)&&s(Un),device:s(is)||s(Un)},android:{phone:!s(Rr)&&s(is)||!s(Rr)&&s(hl),tablet:!s(Rr)&&!s(is)&&!s(hl)&&(s(Un)||s(Fd)),device:!s(Rr)&&(s(is)||s(Un)||s(hl)||s(Fd))||s(/\bokhttp\b/i)},windows:{phone:s(Rr),tablet:s(kd),device:s(Rr)||s(kd)},other:{blackberry:s(Ud),blackberry10:s(Gd),opera:s(Hd),firefox:s(Xd),chrome:s($d),device:s(Ud)||s(Gd)||s(Hd)||s(Xd)||s($d)},any:!1,phone:!1,tablet:!1};return n.any=n.apple.device||n.android.device||n.windows.device||n.other.device,n.phone=n.apple.phone||n.android.phone||n.windows.phone,n.tablet=n.apple.tablet||n.android.tablet||n.windows.tablet,n}const q1=zd.default??zd,Mr=q1(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Yd={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function s(l,h,u){this.fn=l,this.context=h,this.once=u||!1}function n(l,h,u,c,d){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new s(u,c||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=[],u,c;if(this._eventsCount===0)return h;for(c in u=this._events)t.call(u,c)&&h.push(e?c.slice(1):c);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(u)):h},a.prototype.listeners=function(h){var u=e?e+h:h,c=this._events[u];if(!c)return[];if(c.fn)return[c.fn];for(var d=0,f=c.length,p=new Array(f);d<f;d++)p[d]=c[d].fn;return p},a.prototype.listenerCount=function(h){var u=e?e+h:h,c=this._events[u];return c?c.fn?1:c.length:0},a.prototype.emit=function(h,u,c,d,f,p){var m=e?e+h:h;if(!this._events[m])return!1;var _=this._events[m],y=arguments.length,v,g;if(_.fn){switch(_.once&&this.removeListener(h,_.fn,void 0,!0),y){case 1:return _.fn.call(_.context),!0;case 2:return _.fn.call(_.context,u),!0;case 3:return _.fn.call(_.context,u,c),!0;case 4:return _.fn.call(_.context,u,c,d),!0;case 5:return _.fn.call(_.context,u,c,d,f),!0;case 6:return _.fn.call(_.context,u,c,d,f,p),!0}for(g=1,v=new Array(y-1);g<y;g++)v[g-1]=arguments[g];_.fn.apply(_.context,v)}else{var x=_.length,E;for(g=0;g<x;g++)switch(_[g].once&&this.removeListener(h,_[g].fn,void 0,!0),y){case 1:_[g].fn.call(_[g].context);break;case 2:_[g].fn.call(_[g].context,u);break;case 3:_[g].fn.call(_[g].context,u,c);break;case 4:_[g].fn.call(_[g].context,u,c,d);break;default:if(!v)for(E=1,v=new Array(y-1);E<y;E++)v[E-1]=arguments[E];_[g].fn.apply(_[g].context,v)}}return!0},a.prototype.on=function(h,u,c){return n(this,h,u,c,!1)},a.prototype.once=function(h,u,c){return n(this,h,u,c,!0)},a.prototype.removeListener=function(h,u,c,d){var f=e?e+h:h;if(!this._events[f])return this;if(!u)return o(this,f),this;var p=this._events[f];if(p.fn)p.fn===u&&(!d||p.once)&&(!c||p.context===c)&&o(this,f);else{for(var m=0,_=[],y=p.length;m<y;m++)(p[m].fn!==u||d&&!p[m].once||c&&p[m].context!==c)&&_.push(p[m]);_.length?this._events[f]=_.length===1?_[0]:_:o(this,f)}return this},a.prototype.removeAllListeners=function(h){var u;return h?(u=e?e+h:h,this._events[u]&&o(this,u)):(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})(Yd);var K1=Yd.exports;const Xs=Va(K1);var ul={exports:{}};ul.exports=Gn,ul.exports.default=Gn;function Gn(r,t,e){e=e||2;var i=t&&t.length,s=i?t[0]*e:r.length,n=Wd(r,0,s,e,!0),o=[];if(!n||n.next===n.prev)return o;var a,l,h,u,c,d,f;if(i&&(n=ex(r,t,n,e)),r.length>80*e){a=h=r[0],l=u=r[1];for(var p=e;p<s;p+=e)c=r[p],d=r[p+1],c<a&&(a=c),d<l&&(l=d),c>h&&(h=c),d>u&&(u=d);f=Math.max(h-a,u-l),f=f!==0?32767/f:0}return Vs(n,o,e,a,l,f,0),o}function Wd(r,t,e,i,s){var n,o;if(s===fl(r,t,e,i)>0)for(n=t;n<e;n+=i)o=Kd(n,r[n],r[n+1],o);else for(n=e-i;n>=t;n-=i)o=Kd(n,r[n],r[n+1],o);return o&&Hn(o,o.next)&&(Ys(o),o=o.next),o}function wi(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(Hn(e,e.next)||zt(e.prev,e,e.next)===0)){if(Ys(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Vs(r,t,e,i,s,n,o){if(r){!o&&n&&ox(r,i,s,n);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,n?Q1(r,i,s,n):Z1(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Ys(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=J1(wi(r),t,e),Vs(r,t,e,i,s,n,2)):o===2&&tx(r,t,e,i,s,n):Vs(wi(r),t,e,i,s,n,1);break}}}}function Z1(r){var t=r.prev,e=r,i=r.next;if(zt(t,e,i)>=0)return!1;for(var s=t.x,n=e.x,o=i.x,a=t.y,l=e.y,h=i.y,u=s<n?s<o?s:o:n<o?n:o,c=a<l?a<h?a:h:l<h?l:h,d=s>n?s>o?s:o:n>o?n:o,f=a>l?a>h?a:h:l>h?l:h,p=i.next;p!==t;){if(p.x>=u&&p.x<=d&&p.y>=c&&p.y<=f&&ss(s,a,n,l,o,h,p.x,p.y)&&zt(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function Q1(r,t,e,i){var s=r.prev,n=r,o=r.next;if(zt(s,n,o)>=0)return!1;for(var a=s.x,l=n.x,h=o.x,u=s.y,c=n.y,d=o.y,f=a<l?a<h?a:h:l<h?l:h,p=u<c?u<d?u:d:c<d?c:d,m=a>l?a>h?a:h:l>h?l:h,_=u>c?u>d?u:d:c>d?c:d,y=cl(f,p,t,e,i),v=cl(m,_,t,e,i),g=r.prevZ,x=r.nextZ;g&&g.z>=y&&x&&x.z<=v;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=_&&g!==s&&g!==o&&ss(a,u,l,c,h,d,g.x,g.y)&&zt(g.prev,g,g.next)>=0||(g=g.prevZ,x.x>=f&&x.x<=m&&x.y>=p&&x.y<=_&&x!==s&&x!==o&&ss(a,u,l,c,h,d,x.x,x.y)&&zt(x.prev,x,x.next)>=0))return!1;x=x.nextZ}for(;g&&g.z>=y;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=_&&g!==s&&g!==o&&ss(a,u,l,c,h,d,g.x,g.y)&&zt(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;x&&x.z<=v;){if(x.x>=f&&x.x<=m&&x.y>=p&&x.y<=_&&x!==s&&x!==o&&ss(a,u,l,c,h,d,x.x,x.y)&&zt(x.prev,x,x.next)>=0)return!1;x=x.nextZ}return!0}function J1(r,t,e){var i=r;do{var s=i.prev,n=i.next.next;!Hn(s,n)&&jd(s,i,i.next,n)&&zs(s,n)&&zs(n,s)&&(t.push(s.i/e|0),t.push(i.i/e|0),t.push(n.i/e|0),Ys(i),Ys(i.next),i=r=n),i=i.next}while(i!==r);return wi(i)}function tx(r,t,e,i,s,n){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&hx(o,a)){var l=qd(o,a);o=wi(o,o.next),l=wi(l,l.next),Vs(o,t,e,i,s,n,0),Vs(l,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function ex(r,t,e,i){var s=[],n,o,a,l,h;for(n=0,o=t.length;n<o;n++)a=t[n]*i,l=n<o-1?t[n+1]*i:r.length,h=Wd(r,a,l,i,!1),h===h.next&&(h.steiner=!0),s.push(lx(h));for(s.sort(rx),n=0;n<s.length;n++)e=ix(s[n],e);return e}function rx(r,t){return r.x-t.x}function ix(r,t){var e=sx(r,t);if(!e)return t;var i=qd(e,r);return wi(i,i.next),wi(e,e.next)}function sx(r,t){var e=t,i=r.x,s=r.y,n=-1/0,o;do{if(s<=e.y&&s>=e.next.y&&e.next.y!==e.y){var a=e.x+(s-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(a<=i&&a>n&&(n=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,u=o.y,c=1/0,d;e=o;do i>=e.x&&e.x>=h&&i!==e.x&&ss(s<u?i:n,s,h,u,s<u?n:i,s,e.x,e.y)&&(d=Math.abs(s-e.y)/(i-e.x),zs(e,r)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&nx(o,e)))&&(o=e,c=d)),e=e.next;while(e!==l);return o}function nx(r,t){return zt(r.prev,r,t.prev)<0&&zt(t.next,r,r.next)<0}function ox(r,t,e,i){var s=r;do s.z===0&&(s.z=cl(s.x,s.y,t,e,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==r);s.prevZ.nextZ=null,s.prevZ=null,ax(s)}function ax(r){var t,e,i,s,n,o,a,l,h=1;do{for(e=r,r=null,n=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)?(s=e,e=e.nextZ,a--):(s=i,i=i.nextZ,l--),n?n.nextZ=s:r=s,s.prevZ=n,n=s;e=i}n.nextZ=null,h*=2}while(o>1);return r}function cl(r,t,e,i,s){return r=(r-e)*s|0,t=(t-i)*s|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 lx(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 ss(r,t,e,i,s,n,o,a){return(s-o)*(t-a)>=(r-o)*(n-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(n-a)>=(s-o)*(i-a)}function hx(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!ux(r,t)&&(zs(r,t)&&zs(t,r)&&cx(r,t)&&(zt(r.prev,r,t.prev)||zt(r,t.prev,t))||Hn(r,t)&&zt(r.prev,r,r.next)>0&&zt(t.prev,t,t.next)>0)}function zt(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function Hn(r,t){return r.x===t.x&&r.y===t.y}function jd(r,t,e,i){var s=Xn(zt(r,t,e)),n=Xn(zt(r,t,i)),o=Xn(zt(e,i,r)),a=Xn(zt(e,i,t));return!!(s!==n&&o!==a||s===0&&$n(r,e,t)||n===0&&$n(r,i,t)||o===0&&$n(e,r,i)||a===0&&$n(e,t,i))}function $n(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 Xn(r){return r>0?1:r<0?-1:0}function ux(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&&jd(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function zs(r,t){return zt(r.prev,r,r.next)<0?zt(r,t,r.next)>=0&&zt(r,r.prev,t)>=0:zt(r,t,r.prev)<0||zt(r,r.next,t)<0}function cx(r,t){var e=r,i=!1,s=(r.x+t.x)/2,n=(r.y+t.y)/2;do e.y>n!=e.next.y>n&&e.next.y!==e.y&&s<(e.next.x-e.x)*(n-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function qd(r,t){var e=new dl(r.i,r.x,r.y),i=new dl(t.i,t.x,t.y),s=r.next,n=t.prev;return r.next=t,t.prev=r,e.next=s,s.prev=e,i.next=e,e.prev=i,n.next=i,i.prev=n,i}function Kd(r,t,e,i){var s=new dl(r,t,e);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function Ys(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 dl(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}Gn.deviation=function(r,t,e,i){var s=t&&t.length,n=s?t[0]*e:r.length,o=Math.abs(fl(r,0,n,e));if(s)for(var a=0,l=t.length;a<l;a++){var h=t[a]*e,u=a<l-1?t[a+1]*e:r.length;o-=Math.abs(fl(r,h,u,e))}var c=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,f=i[a+1]*e,p=i[a+2]*e;c+=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&&c===0?0:Math.abs((c-o)/o)};function fl(r,t,e,i){for(var s=0,n=t,o=e-i;n<e;n+=i)s+=(r[o]-r[n])*(r[n+1]+r[o+1]),o=n;return s}Gn.flatten=function(r){for(var t=r[0][0].length,e={vertices:[],holes:[],dimensions:t},i=0,s=0;s<r.length;s++){for(var n=0;n<r[s].length;n++)for(var o=0;o<t;o++)e.vertices.push(r[s][n][o]);s>0&&(i+=r[s-1].length,e.holes.push(i))}return e};var dx=ul.exports;const fx=Va(dx);var Vn={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Vn.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,s=r&&!r.nodeType&&r,n=typeof Gs=="object"&&Gs;(n.global===n||n.window===n||n.self===n)&&(e=n);var o,a=2147483647,l=36,h=1,u=26,c=38,d=700,f=72,p=128,m="-",_=/^xn--/,y=/[^\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"},x=l-h,E=Math.floor,R=String.fromCharCode,S;function M(L){throw new RangeError(g[L])}function P(L,O){for(var k=L.length,X=[];k--;)X[k]=O(L[k]);return X}function F(L,O){var k=L.split("@"),X="";k.length>1&&(X=k[0]+"@",L=k[1]),L=L.replace(v,".");var Y=L.split("."),q=P(Y,O).join(".");return X+q}function U(L){for(var O=[],k=0,X=L.length,Y,q;k<X;)Y=L.charCodeAt(k++),Y>=55296&&Y<=56319&&k<X?(q=L.charCodeAt(k++),(q&64512)==56320?O.push(((Y&1023)<<10)+(q&1023)+65536):(O.push(Y),k--)):O.push(Y);return O}function I(L){return P(L,function(O){var k="";return O>65535&&(O-=65536,k+=R(O>>>10&1023|55296),O=56320|O&1023),k+=R(O),k}).join("")}function A(L){return L-48<10?L-22:L-65<26?L-65:L-97<26?L-97:l}function w(L,O){return L+22+75*(L<26)-((O!=0)<<5)}function C(L,O,k){var X=0;for(L=k?E(L/d):L>>1,L+=E(L/O);L>x*u>>1;X+=l)L=E(L/x);return E(X+(x+1)*L/(L+c))}function D(L){var O=[],k=L.length,X,Y=0,q=p,pt=f,_t,W,bt,dt,mt,xt,Mt,Nt,_e;for(_t=L.lastIndexOf(m),_t<0&&(_t=0),W=0;W<_t;++W)L.charCodeAt(W)>=128&&M("not-basic"),O.push(L.charCodeAt(W));for(bt=_t>0?_t+1:0;bt<k;){for(dt=Y,mt=1,xt=l;bt>=k&&M("invalid-input"),Mt=A(L.charCodeAt(bt++)),(Mt>=l||Mt>E((a-Y)/mt))&&M("overflow"),Y+=Mt*mt,Nt=xt<=pt?h:xt>=pt+u?u:xt-pt,!(Mt<Nt);xt+=l)_e=l-Nt,mt>E(a/_e)&&M("overflow"),mt*=_e;X=O.length+1,pt=C(Y-dt,X,dt==0),E(Y/X)>a-q&&M("overflow"),q+=E(Y/X),Y%=X,O.splice(Y++,0,q)}return I(O)}function N(L){var O,k,X,Y,q,pt,_t,W,bt,dt,mt,xt=[],Mt,Nt,_e,jt;for(L=U(L),Mt=L.length,O=p,k=0,q=f,pt=0;pt<Mt;++pt)mt=L[pt],mt<128&&xt.push(R(mt));for(X=Y=xt.length,Y&&xt.push(m);X<Mt;){for(_t=a,pt=0;pt<Mt;++pt)mt=L[pt],mt>=O&&mt<_t&&(_t=mt);for(Nt=X+1,_t-O>E((a-k)/Nt)&&M("overflow"),k+=(_t-O)*Nt,O=_t,pt=0;pt<Mt;++pt)if(mt=L[pt],mt<O&&++k>a&&M("overflow"),mt==O){for(W=k,bt=l;dt=bt<=q?h:bt>=q+u?u:bt-q,!(W<dt);bt+=l)jt=W-dt,_e=l-dt,xt.push(R(w(dt+jt%_e,0))),W=E(jt/_e);xt.push(R(w(W,0))),q=C(k,Nt,X==Y),k=0,++X}++k,++O}return xt.join("")}function B(L){return F(L,function(O){return _.test(O)?D(O.slice(4).toLowerCase()):O})}function V(L){return F(L,function(O){return y.test(O)?"xn--"+N(O):O})}if(o={version:"1.4.1",ucs2:{decode:U,encode:I},decode:D,encode:N,toASCII:V,toUnicode:B},i&&s)if(r.exports==i)s.exports=o;else for(S in o)o.hasOwnProperty(S)&&(i[S]=o[S]);else e.punycode=o})(Gs)}(Vn,Vn.exports);var px=Vn.exports,ns=TypeError;const mx=Nv(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var pl=typeof Map=="function"&&Map.prototype,ml=Object.getOwnPropertyDescriptor&&pl?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,zn=pl&&ml&&typeof ml.get=="function"?ml.get:null,Zd=pl&&Map.prototype.forEach,gl=typeof Set=="function"&&Set.prototype,yl=Object.getOwnPropertyDescriptor&&gl?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Yn=gl&&yl&&typeof yl.get=="function"?yl.get:null,Qd=gl&&Set.prototype.forEach,gx=typeof WeakMap=="function"&&WeakMap.prototype,Ws=gx?WeakMap.prototype.has:null,yx=typeof WeakSet=="function"&&WeakSet.prototype,js=yx?WeakSet.prototype.has:null,_x=typeof WeakRef=="function"&&WeakRef.prototype,Jd=_x?WeakRef.prototype.deref:null,vx=Boolean.prototype.valueOf,xx=Object.prototype.toString,bx=Function.prototype.toString,Ex=String.prototype.match,_l=String.prototype.slice,ti=String.prototype.replace,wx=String.prototype.toUpperCase,tf=String.prototype.toLowerCase,ef=RegExp.prototype.test,rf=Array.prototype.concat,yr=Array.prototype.join,Tx=Array.prototype.slice,sf=Math.floor,vl=typeof BigInt=="function"?BigInt.prototype.valueOf:null,xl=Object.getOwnPropertySymbols,bl=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,os=typeof Symbol=="function"&&typeof Symbol.iterator=="object",qs=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===os||!0)?Symbol.toStringTag:null,nf=Object.prototype.propertyIsEnumerable,of=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function af(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||ef.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-sf(-r):sf(r);if(i!==r){var s=String(i),n=_l.call(t,s.length+1);return ti.call(s,e,"$&_")+"."+ti.call(ti.call(n,/([0-9]{3})/g,"$&_"),/_$/,"")}}return ti.call(t,e,"$&_")}var El=mx,lf=El.custom,hf=ff(lf)?lf:null,uf={__proto__:null,double:'"',single:"'"},Ax={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Wn=function r(t,e,i,s){var n=e||{};if(Pr(n,"quoteStyle")&&!Pr(uf,n.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Pr(n,"maxStringLength")&&(typeof n.maxStringLength=="number"?n.maxStringLength<0&&n.maxStringLength!==1/0:n.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=Pr(n,"customInspect")?n.customInspect:!0;if(typeof o!="boolean"&&o!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Pr(n,"indent")&&n.indent!==null&&n.indent!==" "&&!(parseInt(n.indent,10)===n.indent&&n.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Pr(n,"numericSeparator")&&typeof n.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=n.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 mf(t,n);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?af(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?af(t,h):h}var u=typeof n.depth>"u"?5:n.depth;if(typeof i>"u"&&(i=0),i>=u&&u>0&&typeof t=="object")return wl(t)?"[Array]":"[Object]";var c=Xx(n,i);if(typeof s>"u")s=[];else if(pf(s,t)>=0)return"[Circular]";function d(A,w,C){if(w&&(s=Tx.call(s),s.push(w)),C){var D={depth:n.depth};return Pr(n,"quoteStyle")&&(D.quoteStyle=n.quoteStyle),r(A,D,i+1,s)}return r(A,n,i+1,s)}if(typeof t=="function"&&!df(t)){var f=Dx(t),p=jn(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+yr.call(p,", ")+" }":"")}if(ff(t)){var m=os?ti.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):bl.call(t);return typeof t=="object"&&!os?Ks(m):m}if(Gx(t)){for(var _="<"+tf.call(String(t.nodeName)),y=t.attributes||[],v=0;v<y.length;v++)_+=" "+y[v].name+"="+cf(Sx(y[v].value),"double",n);return _+=">",t.childNodes&&t.childNodes.length&&(_+="..."),_+="</"+tf.call(String(t.nodeName))+">",_}if(wl(t)){if(t.length===0)return"[]";var g=jn(t,d);return c&&!$x(g)?"["+Al(g,c)+"]":"[ "+yr.call(g,", ")+" ]"}if(Ix(t)){var x=jn(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!nf.call(t,"cause")?"{ ["+String(t)+"] "+yr.call(rf.call("[cause]: "+d(t.cause),x),", ")+" }":x.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+yr.call(x,", ")+" }"}if(typeof t=="object"&&o){if(hf&&typeof t[hf]=="function"&&El)return El(t,{depth:u-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(Lx(t)){var E=[];return Zd&&Zd.call(t,function(A,w){E.push(d(w,t,!0)+" => "+d(A,t))}),gf("Map",zn.call(t),E,c)}if(kx(t)){var R=[];return Qd&&Qd.call(t,function(A){R.push(d(A,t))}),gf("Set",Yn.call(t),R,c)}if(Bx(t))return Tl("WeakMap");if(Ux(t))return Tl("WeakSet");if(Fx(t))return Tl("WeakRef");if(Mx(t))return Ks(d(Number(t)));if(Ox(t))return Ks(d(vl.call(t)));if(Px(t))return Ks(vx.call(t));if(Rx(t))return Ks(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Gs<"u"&&t===Gs)return"{ [object globalThis] }";if(!Cx(t)&&!df(t)){var S=jn(t,d),M=of?of(t)===Object.prototype:t instanceof Object||t.constructor===Object,P=t instanceof Object?"":"null prototype",F=!M&&qs&&Object(t)===t&&qs in t?_l.call(ei(t),8,-1):P?"Object":"",U=M||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",I=U+(F||P?"["+yr.call(rf.call([],F||[],P||[]),": ")+"] ":"");return S.length===0?I+"{}":c?I+"{"+Al(S,c)+"}":I+"{ "+yr.call(S,", ")+" }"}return String(t)};function cf(r,t,e){var i=e.quoteStyle||t,s=uf[i];return s+r+s}function Sx(r){return ti.call(String(r),/"/g,""")}function Ti(r){return!qs||!(typeof r=="object"&&(qs in r||typeof r[qs]<"u"))}function wl(r){return ei(r)==="[object Array]"&&Ti(r)}function Cx(r){return ei(r)==="[object Date]"&&Ti(r)}function df(r){return ei(r)==="[object RegExp]"&&Ti(r)}function Ix(r){return ei(r)==="[object Error]"&&Ti(r)}function Rx(r){return ei(r)==="[object String]"&&Ti(r)}function Mx(r){return ei(r)==="[object Number]"&&Ti(r)}function Px(r){return ei(r)==="[object Boolean]"&&Ti(r)}function ff(r){if(os)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!bl)return!1;try{return bl.call(r),!0}catch{}return!1}function Ox(r){if(!r||typeof r!="object"||!vl)return!1;try{return vl.call(r),!0}catch{}return!1}var Nx=Object.prototype.hasOwnProperty||function(r){return r in this};function Pr(r,t){return Nx.call(r,t)}function ei(r){return xx.call(r)}function Dx(r){if(r.name)return r.name;var t=Ex.call(bx.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function pf(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 Lx(r){if(!zn||!r||typeof r!="object")return!1;try{zn.call(r);try{Yn.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function Bx(r){if(!Ws||!r||typeof r!="object")return!1;try{Ws.call(r,Ws);try{js.call(r,js)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function Fx(r){if(!Jd||!r||typeof r!="object")return!1;try{return Jd.call(r),!0}catch{}return!1}function kx(r){if(!Yn||!r||typeof r!="object")return!1;try{Yn.call(r);try{zn.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function Ux(r){if(!js||!r||typeof r!="object")return!1;try{js.call(r,js);try{Ws.call(r,Ws)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function Gx(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function mf(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return mf(_l.call(r,0,t.maxStringLength),t)+i}var s=Ax[t.quoteStyle||"single"];s.lastIndex=0;var n=ti.call(ti.call(r,s,"\\$1"),/[\x00-\x1f]/g,Hx);return cf(n,"single",t)}function Hx(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":"")+wx.call(t.toString(16))}function Ks(r){return"Object("+r+")"}function Tl(r){return r+" { ? }"}function gf(r,t,e,i){var s=i?Al(e,i):yr.call(e,", ");return r+" ("+t+") {"+s+"}"}function $x(r){for(var t=0;t<r.length;t++)if(pf(r[t],`
|
|
4
4
|
`)>=0)return!1;return!0}function Xx(r,t){var e;if(r.indent===" ")e=" ";else if(typeof r.indent=="number"&&r.indent>0)e=yr.call(Array(r.indent+1)," ");else return null;return{base:e,prev:yr.call(Array(t+1),e)}}function Al(r,t){if(r.length===0)return"";var e=`
|
|
5
5
|
`+t.prev+t.base;return e+yr.call(r,","+e)+`
|