@annotorious/annotorious 3.7.18 → 3.7.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- (function(O,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(O=typeof globalThis<"u"?globalThis:O||self,j(O.Annotorious={}))})(this,function(O){"use strict";var Rr=Object.defineProperty;var Vr=(O,j,Ce)=>j in O?Rr(O,j,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):O[j]=Ce;var sn=(O,j,Ce)=>Vr(O,typeof j!="symbol"?j+"":j,Ce);function j(){}function Ce(e,t){for(const n in t)e[n]=t[n];return e}function rn(e){return e()}function ln(){return Object.create(null)}function Ae(e){e.forEach(rn)}function ie(e){return typeof e=="function"}function re(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function qo(e){return Object.keys(e).length===0}function an(e,...t){if(e==null){for(const o of t)o(void 0);return j}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function kt(e,t,n){e.$$.on_destroy.push(an(t,n))}function Ko(e,t,n,o){if(e){const i=cn(e,t,n,o);return e[0](i)}}function cn(e,t,n,o){return e[1]&&o?Ce(n.ctx.slice(),e[1](o(t))):n.ctx}function Wo(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let l=0;l<r;l+=1)s[l]=t.dirty[l]|i[l];return s}return t.dirty|i}return t.dirty}function Zo(e,t,n,o,i,s){if(i){const r=cn(t,n,o,s);e.p(r,i)}}function Jo(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function un(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function je(e){return e??""}function z(e,t){e.appendChild(t)}function N(e,t,n){e.insertBefore(t,n||null)}function B(e){e.parentNode&&e.parentNode.removeChild(e)}function Ye(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function L(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function fn(e){return document.createTextNode(e)}function we(){return fn(" ")}function ke(){return fn("")}function J(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function c(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Qo(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function xo(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Qe;function xe(e){Qe=e}function dn(){if(!Qe)throw new Error("Function called outside component initialization");return Qe}function Re(e){dn().$$.on_mount.push(e)}function Oe(){const e=dn();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=xo(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function ue(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const Fe=[],ft=[];let ze=[];const hn=[],gn=Promise.resolve();let Mt=!1;function mn(){Mt||(Mt=!0,gn.then(yn))}function pn(){return mn(),gn}function Tt(e){ze.push(e)}const Pt=new Set;let qe=0;function yn(){if(qe!==0)return;const e=Qe;do{try{for(;qe<Fe.length;){const t=Fe[qe];qe++,xe(t),$o(t.$$)}}catch(t){throw Fe.length=0,qe=0,t}for(xe(null),Fe.length=0,qe=0;ft.length;)ft.pop()();for(let t=0;t<ze.length;t+=1){const n=ze[t];Pt.has(n)||(Pt.add(n),n())}ze.length=0}while(Fe.length);for(;hn.length;)hn.pop()();Mt=!1,Pt.clear(),xe(e)}function $o(e){if(e.fragment!==null){e.update(),Ae(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Tt)}}function ei(e){const t=[],n=[];ze.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),ze=t}const dt=new Set;let Ve;function be(){Ve={r:0,c:[],p:Ve}}function Ee(){Ve.r||Ae(Ve.c),Ve=Ve.p}function R(e,t){e&&e.i&&(dt.delete(e),e.i(t))}function G(e,t,n,o){if(e&&e.o){if(dt.has(e))return;dt.add(e),Ve.c.push(()=>{dt.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ve(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ce(e){e&&e.c()}function le(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),Tt(()=>{const s=e.$$.on_mount.map(rn).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ae(s),e.$$.on_mount=[]}),i.forEach(Tt)}function ae(e,t){const n=e.$$;n.fragment!==null&&(ei(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function ti(e,t){e.$$.dirty[0]===-1&&(Fe.push(e),mn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function he(e,t,n,o,i,s,r=null,l=[-1]){const a=Qe;xe(e);const u=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:i,bound:ln(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:ln(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(u.root);let d=!1;if(u.ctx=n?n(e,t.props||{},(f,h,...g)=>{const m=g.length?g[0]:h;return u.ctx&&i(u.ctx[f],u.ctx[f]=m)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](m),d&&ti(e,f)),h}):[],u.update(),d=!0,Ae(u.before_update),u.fragment=o?o(u.ctx):!1,t.target){if(t.hydrate){const f=Qo(t.target);u.fragment&&u.fragment.l(f),f.forEach(B)}else u.fragment&&u.fragment.c();t.intro&&R(e.$$.fragment),le(e,t.target,t.anchor),yn()}xe(a)}class ge{constructor(){sn(this,"$$");sn(this,"$$set")}$destroy(){ae(this,1),this.$destroy=j}$on(t,n){if(!ie(n))return j;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!qo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ni="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ni);var Q=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(Q||{});function oi(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _n={exports:{}};(function(e){(function(){function t(l,a){var u=l.x-a.x,d=l.y-a.y;return u*u+d*d}function n(l,a,u){var d=a.x,f=a.y,h=u.x-d,g=u.y-f;if(h!==0||g!==0){var m=((l.x-d)*h+(l.y-f)*g)/(h*h+g*g);m>1?(d=u.x,f=u.y):m>0&&(d+=h*m,f+=g*m)}return h=l.x-d,g=l.y-f,h*h+g*g}function o(l,a){for(var u=l[0],d=[u],f,h=1,g=l.length;h<g;h++)f=l[h],t(f,u)>a&&(d.push(f),u=f);return u!==f&&d.push(f),d}function i(l,a,u,d,f){for(var h=d,g,m=a+1;m<u;m++){var p=n(l[m],l[a],l[u]);p>h&&(g=m,h=p)}h>d&&(g-a>1&&i(l,a,g,d,f),f.push(l[g]),u-g>1&&i(l,g,u,d,f))}function s(l,a){var u=l.length-1,d=[l[0]];return i(l,0,u,a,d),d.push(l[u]),d}function r(l,a,u){if(l.length<=2)return l;var d=a!==void 0?a*a:1;return l=u?l:o(l,d),l=s(l,d),l}e.exports=r,e.exports.default=r})()})(_n);var ii=_n.exports;const si=oi(ii),Lt={},Xe=(e,t)=>Lt[e]=t,ht=e=>Lt[e.type].area(e),wn=(e,t,n,o)=>Lt[e.type].intersects(e,t,n,o),fe=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},$e=e=>{let t=0,n=e.length-1;for(let o=0;o<e.length;o++)t+=(e[n][0]+e[o][0])*(e[n][1]-e[o][1]),n=o;return Math.abs(.5*t)},et=(e,t,n)=>{let o=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const r=e[i][0],l=e[i][1],a=e[s][0],u=e[s][1];l>n!=u>n&&t<(a-r)*(n-l)/(u-l)+r&&(o=!o)}return o},bn=(e,t=!0)=>{let n="M ";return e.forEach(([o,i],s)=>{s===0?n+=`${o},${i}`:n+=` L ${o},${i}`}),t&&(n+=" Z"),n},It=(e,t=1)=>{const n=e.map(([o,i])=>({x:o,y:i}));return si(n,t,!0).map(o=>[o.x,o.y])},tt=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},ri={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,l=0,a=Math.cos(l),u=Math.sin(l),d=t-o,f=n-i,h=a*d+u*f,g=u*d-a*f;return h*h/(s*s)+g*g/(r*r)<=1}};Xe(Q.ELLIPSE,ri);const li={area:e=>0,intersects:(e,t,n,o=2)=>{const[[i,s],[r,l]]=e.geometry.points,a=Math.abs((l-s)*t-(r-i)*n+r*s-l*i),u=tt([i,s],[r,l]);return a/u<=o}};Xe(Q.LINE,li);const ai={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,o)=>{const[i,...s]=o.rings,r=$e(i.points),l=s.reduce((a,u)=>a+$e(u.points),0);return n+r-l},0)},intersects:(e,t,n)=>{const{polygons:o}=e.geometry;for(const i of o){const[s,...r]=i.rings;if(et(s.points,t,n)){let l=!1;for(const a of r)if(et(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},nt=e=>{const t=e.reduce((n,o)=>[...n,...o.rings[0].points],[]);return fe(t)},Le=e=>e.rings.map(n=>bn(n.points)).join(" "),En=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((o,i)=>[...o,...i.points],[])],[]),ci=(e,t=1)=>{const n=e.geometry.polygons.map(i=>{const s=i.rings.map(l=>{const a=It(l.points,t);return{...l,points:a}}),r=fe(s[0].points);return{...i,rings:s,bounds:r}}),o=nt(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:o}}};Xe(Q.MULTIPOLYGON,ai);const ui={area:e=>{const t=e.geometry.points;return $e(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return et(o,t,n)}},fi=(e,t=1)=>{const n=It(e.geometry.points,t),o=fe(n);return{...e,geometry:{...e.geometry,bounds:o,points:n}}};Xe(Q.POLYGON,ui);const di={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=gt(t.points,t.closed);return $e(n)},intersects:(e,t,n,o=2)=>{const i=e.geometry;if(i.closed){const s=gt(i.points,i.closed);return et(s,t,n)}else return hi(i,[t,n],o)}},gt=(e,t=!1)=>{const n=[];for(let o=0;o<e.length;o++){const i=e[o],s=e[(o+1)%e.length];if(n.push(i.point),(o<e.length-1||t)&&(i.type==="CURVE"||s.type=="CURVE")){const l=vn(i.point,i.type==="CURVE"&&i.outHandle||i.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);n.push(...l.slice(1))}}return n},vn=(e,t,n,o,i=10)=>{const s=[];for(let r=0;r<=i;r++){const l=r/i,a=Math.pow(1-l,3)*e[0]+3*Math.pow(1-l,2)*l*t[0]+3*(1-l)*Math.pow(l,2)*n[0]+Math.pow(l,3)*o[0],u=Math.pow(1-l,3)*e[1]+3*Math.pow(1-l,2)*l*t[1]+3*(1-l)*Math.pow(l,2)*n[1]+Math.pow(l,3)*o[1];s.push([a,u])}return s},hi=(e,t,n)=>{for(let o=0;o<e.points.length-1;o++){const i=e.points[o],s=e.points[o+1];if(i.type==="CURVE"||s.type==="CURVE"){const l=vn(i.point,i.type==="CURVE"&&i.outHandle||i.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let a=0;a<l.length-1;a++)if(Sn(t,l[a],l[a+1])<=n)return!0}else if(Sn(t,i.point,s.point)<=n)return!0}return!1},Sn=(e,t,n)=>{const[o,i]=e,[s,r]=t,[l,a]=n,u=l-s,d=a-r,f=Math.sqrt(u*u+d*d);if(f===0)return Math.sqrt((o-s)*(o-s)+(i-r)*(i-r));const h=((o-s)*u+(i-r)*d)/(f*f);return h<=0?Math.sqrt((o-s)*(o-s)+(i-r)*(i-r)):h>=1?Math.sqrt((o-l)*(o-l)+(i-a)*(i-a)):Math.abs((a-r)*o-(l-s)*i+l*r-a*s)/f},Ct=e=>{if(!e.points||e.points.length===0)return"";const t=[],n=e.points[0];t.push(`M ${n.point[0]} ${n.point[1]}`);for(let o=1;o<e.points.length;o++){const i=e.points[o],s=e.points[o-1];if(i.type==="CURVE"||s.type==="CURVE"){const r=s.type==="CURVE"&&s.outHandle||s.point,l=i.type==="CURVE"&&i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}else t.push(`L ${i.point[0]} ${i.point[1]}`)}if(e.closed){const o=e.points[e.points.length-1],i=e.points[0];if(o.type==="CURVE"||i.type==="CURVE"){const r=o.outHandle||o.point,l=i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Xe(Q.POLYLINE,di);const An={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};Xe(Q.RECTANGLE,An);const ot=e=>it(e.target),it=e=>{var t,n;return(e==null?void 0:e.annotation)!==void 0&&((n=(t=e==null?void 0:e.selector)==null?void 0:t.geometry)==null?void 0:n.bounds)!==void 0},kn=e=>(e==null?void 0:e.type)==="FragmentSelector"?!0:typeof e=="string"?e.indexOf("#")<0?!1:/^#xywh(?:=(?:pixel:|percent:)?)\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?$/i.test(e):!1,Mn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0];if(!i)throw new Error("Not a MediaFragment: "+n);const[s,r,l,a,u,d,f]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[h,g,m,p]=[a,u,d,f].map(parseFloat);return{type:Q.RECTANGLE,geometry:{x:h,y:g,w:m,h:p,bounds:{minX:h,minY:t?g-p:g,maxX:h+m,maxY:t?g:g+p}}}},Tn=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},Pn="http://www.w3.org/2000/svg",Ln=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},gi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Pn}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},mt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Pn),i=n.lookupNamespaceURI(null);return o||i?Ln(n).firstChild:Ln(gi(n)).firstChild},mi=e=>{const t=In(e),n=[];let o=[],i=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":o.length>0&&(n.push({points:o}),o=[]),i=[s.args[0],s.args[1]],o.push([...i]);break;case"L":i=[s.args[0],s.args[1]],o.push([...i]);break;case"H":i=[s.args[0],i[1]],o.push([...i]);break;case"V":i=[i[0],s.args[0]],o.push([...i]);break;case"C":i=[s.args[4],s.args[5]],o.push([...i]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(o.length>2&&n.push({points:o}),n.length>0){const s=fe(n[0].points);return{rings:n,bounds:s}}},pi=e=>{const{point:t,inHandle:n,outHandle:o}=e;if(!n||!o)return!1;const i=n[0]-t[0],s=n[1]-t[1],r=o[0]-t[0],l=o[1]-t[1],a=i*l-s*r;return Math.abs(a)<.01},yi=e=>{const t=In(e);let n=[],o=[0,0],i=!1;for(let r=0;r<t.length;r++){const l=t[r];switch(l.type.toUpperCase()){case"M":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"L":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"C":const a=[l.args[0],l.args[1]],u=[l.args[2],l.args[3]],d=[l.args[4],l.args[5]];if(n.length>0){const h=n[n.length-1];(a[0]!==h.point[0]||a[1]!==h.point[1])&&(h.type="CURVE",h.outHandle=a)}const f={type:u[0]!==d[0]||u[1]!==d[1]?"CURVE":"CORNER",point:d};f.type==="CURVE"&&(f.inHandle=u),n.push(f),o=d;break;case"Z":i=!0;break;default:console.warn(`Unsupported SVG path command: ${l.type}`);break}}n=n.map(r=>pi(r)?{...r,locked:!0}:r);const s=fe(gt(n,i));return{points:n,closed:i,bounds:s}},In=e=>{const t=[],n=e.replace(/,/g," ").trim(),o=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let i;for(;(i=o.exec(n))!==null;){const[,s,r]=i,l=r.trim()===""?[]:r.trim().split(/\s+/).map(Number).filter(a=>!isNaN(a));t.push({type:s,args:l})}return t},_i=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:Q.POLYGON,geometry:{points:i,bounds:fe(i)}}},wi=e=>{const t=mt(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:Q.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},bi=e=>{const t=mt(e),n=parseFloat(t.getAttribute("x1")),o=parseFloat(t.getAttribute("x2")),i=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),r={minX:Math.min(n,o),minY:Math.min(i,s),maxX:Math.max(n,o),maxY:Math.max(i,s)};return{type:Q.LINE,geometry:{points:[[n,i],[o,s]],bounds:r}}},Ei=e=>{const t=mt(e),n=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],o=n==null?void 0:n.getAttribute("d");if(!o)throw new Error("Could not parse SVG path");const i=yi(o);if(!i)throw new Error("Could not parse SVG path");return{type:Q.POLYLINE,geometry:i}},vi=e=>{const t=mt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>mi(a)).filter(Boolean),s=i.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=fe(s);return i.length===1&&i[0].rings.length===1?{type:Q.POLYGON,geometry:{points:s,bounds:r}}:{type:Q.MULTIPOLYGON,geometry:{polygons:i,bounds:r}}},Cn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return _i(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return Ei(t);if(t.includes("<path "))return vi(t);if(t.includes("<ellipse "))return wi(t);if(t.includes("<line "))return bi(t);throw"Unsupported SVG shape: "+t},Si=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Le(n)}" />`).join("")}</g>`,On=e=>{let t;switch(e.type){case Q.POLYGON:{const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`;break}case Q.ELLIPSE:{const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;break}case Q.MULTIPOLYGON:{const n=e.geometry;t=`<svg>${Si(n)}</svg>`;break}case Q.LINE:{const n=e.geometry,[[o,i],[s,r]]=n.points;t=`<svg><line x1="${o}" y1="${i}" x2="${s}" y2="${r}" /></svg>`;break}case Q.POLYLINE:t=`<svg><path d="${Ct(e.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},me=[];for(let e=0;e<256;++e)me.push((e+256).toString(16).slice(1));function Ai(e,t=0){return(me[e[t+0]]+me[e[t+1]]+me[e[t+2]]+me[e[t+3]]+"-"+me[e[t+4]]+me[e[t+5]]+"-"+me[e[t+6]]+me[e[t+7]]+"-"+me[e[t+8]]+me[e[t+9]]+"-"+me[e[t+10]]+me[e[t+11]]+me[e[t+12]]+me[e[t+13]]+me[e[t+14]]+me[e[t+15]]).toLowerCase()}let Ot;const ki=new Uint8Array(16);function Mi(){if(!Ot){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ot=crypto.getRandomValues.bind(crypto)}return Ot(ki)}const Dn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ti(e,t,n){var i;e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Mi();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Ai(o)}function Bn(e,t,n){return Dn.randomUUID&&!e?Dn.randomUUID():Ti(e)}var Nn=Object.prototype.hasOwnProperty;function De(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&De(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Nn.call(e,n)&&++o&&!Nn.call(t,n)||!(n in t)||!De(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}let Me=[],Be=0;const pt=4;let Dt=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},lc:0,listen(o){return n.lc=t.push(o),()=>{for(let s=Be+pt;s<Me.length;)Me[s]===o?Me.splice(s,pt):s+=pt;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){let s=!Me.length;for(let r of t)Me.push(r,n.value,o,i);if(s){for(Be=0;Be<Me.length;Be+=pt)Me[Be](Me[Be+1],Me[Be+2],Me[Be+3]);Me.length=0}},off(){},set(o){let i=n.value;i!==o&&(n.value=o,n.notify(i))},subscribe(o){let i=n.listen(o);return o(n.value),i},value:e};return n};const Pi=e=>{const t=Dt(null);return e.observe(({changes:n})=>{const o=t.get();if(o){(n.deleted||[]).some(s=>s.id===o)&&t.set(null);const i=(n.updated||[]).find(({oldValue:s})=>s.id===o);i&&t.set(i.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var Bt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Bt||{});const Nt={selected:[]},Li=(e,t,n)=>{const o=Dt(Nt);let i=t;const s=()=>{De(o.get(),Nt)||o.set(Nt)},r=()=>{var g;return((g=o.get().selected)==null?void 0:g.length)===0},l=g=>{if(r())return!1;const m=typeof g=="string"?g:g.id;return o.get().selected.some(p=>p.id===m)},a=(g,m)=>{let p;if(Array.isArray(g)){if(p=g.map(b=>e.getAnnotation(b)).filter(Boolean),p.length<g.length){console.warn("Invalid selection: "+g.filter(b=>!p.some(S=>S.id===b)));return}}else{const b=e.getAnnotation(g);if(!b){console.warn("Invalid selection: "+g);return}p=[b]}const k=p.reduce((b,S)=>{const w=h(S);return w==="EDIT"?[...b,{id:S.id,editable:!0}]:w==="SELECT"?[...b,{id:S.id}]:b},[]);o.set({selected:k,event:m})},u=(g,m)=>{const p=Array.isArray(g)?g:[g],k=p.map(b=>e.getAnnotation(b)).filter(b=>!!b);o.set({selected:k.map(b=>{const S=m===void 0?h(b)==="EDIT":m;return{id:b.id,editable:S}})}),k.length!==p.length&&console.warn("Invalid selection",g)},d=g=>{if(r())return!1;const{selected:m}=o.get();m.some(({id:p})=>g.includes(p))&&o.set({selected:m.filter(({id:p})=>!g.includes(p))})},f=g=>{i=g,u(o.get().selected.map(({id:m})=>m))},h=g=>Ii(g,i,n);return e.observe(({changes:g})=>d((g.deleted||[]).map(m=>m.id))),{get event(){const g=o.get();return g?g.event:null},get selected(){const g=o.get();return g?[...g.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:h,isEmpty:r,isSelected:l,setSelected:u,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:a}},Ii=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},pe=[];for(let e=0;e<256;++e)pe.push((e+256).toString(16).slice(1));function Ci(e,t=0){return(pe[e[t+0]]+pe[e[t+1]]+pe[e[t+2]]+pe[e[t+3]]+"-"+pe[e[t+4]]+pe[e[t+5]]+"-"+pe[e[t+6]]+pe[e[t+7]]+"-"+pe[e[t+8]]+pe[e[t+9]]+"-"+pe[e[t+10]]+pe[e[t+11]]+pe[e[t+12]]+pe[e[t+13]]+pe[e[t+14]]+pe[e[t+15]]).toLowerCase()}let Ut;const Oi=new Uint8Array(16);function Di(){if(!Ut){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ut=crypto.getRandomValues.bind(crypto)}return Ut(Oi)}const Bi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Un={randomUUID:Bi};function Ni(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Di();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,Ci(i)}function Yn(e,t,n){return Un.randomUUID&&!e?Un.randomUUID():Ni(e)}const Yt=e=>{const t=n=>{const o={...n};return n.created&&typeof n.created=="string"&&(o.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(o.updated=new Date(n.updated)),o};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Ui=(e,t,n,o)=>({id:Yn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Yi=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Ri=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Vi=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!De(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Xi=(e,t)=>!De(e.target,t.target),Rn=(e,t)=>{const n=Yi(e,t),o=Ri(e,t),i=Vi(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Xi(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var ne=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(ne||{});const Hi=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,l=a=>a&&a.length>0;if(!(l(i.created)||l(i.deleted))){const a=(n=i.updated)==null?void 0:n.some(d=>l(d.bodiesCreated)||l(d.bodiesDeleted)||l(d.bodiesUpdated)),u=(o=i.updated)==null?void 0:o.some(d=>d.targetUpdated);if(r==="BODY_ONLY"&&a&&!u||r==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const r=new Set([...(i.created||[]).map(l=>l.id),...(i.deleted||[]).map(l=>l.id),...(i.updated||[]).map(({oldValue:l})=>l.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(l=>r.has(l))}else return!0},Gi=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),l=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),a=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:h})=>h.id===f.id).newValue:f),...t.created||[]],u=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],d=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:h,newValue:g}=f;if(r.has(g.id)){const m=t.updated.find(p=>p.oldValue.id===g.id).newValue;return Rn(h,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:u,updated:d}},yt=e=>{const t=e.id===void 0?Yn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},ji=e=>e.id!==void 0,Fi=()=>{const e=new Map,t=new Map,n=[],o=(_,v={})=>{n.push({onChange:_,options:v})},i=_=>{const v=n.findIndex(y=>y.onChange==_);v>-1&&n.splice(v,1)},s=(_,v)=>{const y={origin:_,changes:{created:v.created||[],updated:v.updated||[],deleted:v.deleted||[]},state:[...e.values()]};n.forEach(E=>{Hi(E,y)&&E.onChange(y)})},r=(_,v=ne.LOCAL)=>{if(_.id&&e.get(_.id))throw Error(`Cannot add annotation ${_.id} - exists already`);{const y=yt(_);e.set(y.id,y),y.bodies.forEach(E=>t.set(E.id,y.id)),s(v,{created:[y]})}},l=(_,v)=>{const y=yt(typeof _=="string"?v:_),E=typeof _=="string"?_:_.id,I=E&&e.get(E);if(I){const P=Rn(I,y);return E===y.id?e.set(E,y):(e.delete(E),e.set(y.id,y)),I.bodies.forEach(D=>t.delete(D.id)),y.bodies.forEach(D=>t.set(D.id,y.id)),P}else console.warn(`Cannot update annotation ${E} - does not exist`)},a=(_,v=ne.LOCAL,y=ne.LOCAL)=>{const E=ji(v)?y:v,I=l(_,v);I&&s(E,{updated:[I]})},u=(_,v=ne.LOCAL)=>{e.get(_.id)?a(_,v):r(_,v)},d=(_,v=ne.LOCAL)=>{const y=_.reduce((E,I)=>{const P=l(I);return P?[...E,P]:E},[]);y.length>0&&s(v,{updated:y})},f=(_,v=ne.LOCAL)=>{const y=_.map(yt),{toAdd:E,toUpdate:I}=y.reduce((D,F)=>e.get(F.id)?{...D,toUpdate:[...D.toUpdate,F]}:{...D,toAdd:[...D.toAdd,F]},{toAdd:[],toUpdate:[]}),P=I.map(D=>l(D,v)).filter(Boolean);E.forEach(D=>{e.set(D.id,D),D.bodies.forEach(F=>t.set(F.id,D.id))}),s(v,{created:E,updated:P})},h=(_,v=ne.LOCAL)=>{const y=e.get(_.annotation);if(y){const E={...y,bodies:[...y.bodies,_]};e.set(y.id,E),t.set(_.id,E.id),s(v,{updated:[{oldValue:y,newValue:E,bodiesCreated:[_]}]})}else console.warn(`Attempt to add body to missing annotation: ${_.annotation}`)},g=()=>[...e.values()],m=(_=ne.LOCAL)=>{const v=[...e.values()];e.clear(),t.clear(),s(_,{deleted:v})},p=(_,v=!0,y=ne.LOCAL)=>{const E=_.map(yt);if(v){const I=[...e.values()];e.clear(),t.clear(),E.forEach(P=>{e.set(P.id,P),P.bodies.forEach(D=>t.set(D.id,P.id))}),s(y,{created:E,deleted:I})}else{const I=_.reduce((P,D)=>{const F=D.id&&e.get(D.id);return F?[...P,F]:P},[]);if(I.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${I.map(P=>P.id).join(", ")}`);E.forEach(P=>{e.set(P.id,P),P.bodies.forEach(D=>t.set(D.id,P.id))}),s(y,{created:E})}},k=_=>{const v=typeof _=="string"?_:_.id,y=e.get(v);if(y)return e.delete(v),y.bodies.forEach(E=>t.delete(E.id)),y;console.warn(`Attempt to delete missing annotation: ${v}`)},b=(_,v=ne.LOCAL)=>{const y=k(_);y&&s(v,{deleted:[y]})},S=(_,v=ne.LOCAL)=>{const y=_.reduce((E,I)=>{const P=k(I);return P?[...E,P]:E},[]);y.length>0&&s(v,{deleted:y})},w=_=>{const v=e.get(_.annotation);if(v){const y=v.bodies.find(E=>E.id===_.id);if(y){t.delete(y.id);const E={...v,bodies:v.bodies.filter(I=>I.id!==_.id)};return e.set(v.id,E),{oldValue:v,newValue:E,bodiesDeleted:[y]}}else console.warn(`Attempt to delete missing body ${_.id} from annotation ${_.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${_.annotation}`)},A=(_,v=ne.LOCAL)=>{const y=w(_);y&&s(v,{updated:[y]})},T=(_,v=ne.LOCAL)=>{const y=_.map(E=>w(E)).filter(Boolean);y.length>0&&s(v,{updated:y})},C=_=>{const v=e.get(_);return v?{...v}:void 0},M=_=>{const v=t.get(_);if(v){const y=C(v).bodies.find(E=>E.id===_);if(y)return y;console.error(`Store integrity error: body ${_} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${_}`)},V=(_,v)=>{if(_.annotation!==v.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const y=e.get(_.annotation);if(y){const E=y.bodies.find(P=>P.id===_.id),I={...y,bodies:y.bodies.map(P=>P.id===E.id?v:P)};return e.set(y.id,I),E.id!==v.id&&(t.delete(E.id),t.set(v.id,I.id)),{oldValue:y,newValue:I,bodiesUpdated:[{oldBody:E,newBody:v}]}}else console.warn(`Attempt to add body to missing annotation ${_.annotation}`)},U=(_,v,y=ne.LOCAL)=>{const E=V(_,v);E&&s(y,{updated:[E]})},W=(_,v=ne.LOCAL)=>{const y=_.map(E=>V({id:E.id,annotation:E.annotation},E)).filter(Boolean);s(v,{updated:y})},q=_=>{const v=e.get(_.annotation);if(v){const y={...v,target:{...v.target,..._}};return e.set(v.id,y),{oldValue:v,newValue:y,targetUpdated:{oldTarget:v.target,newTarget:_}}}else console.warn(`Attempt to update target on missing annotation: ${_.annotation}`)};return{addAnnotation:r,addBody:h,all:g,bulkAddAnnotations:p,bulkDeleteAnnotations:S,bulkDeleteBodies:T,bulkUpdateAnnotations:d,bulkUpdateBodies:W,bulkUpdateTargets:(_,v=ne.LOCAL)=>{const y=_.map(E=>q(E)).filter(Boolean);y.length>0&&s(v,{updated:y})},bulkUpsertAnnotations:f,clear:m,deleteAnnotation:b,deleteBody:A,getAnnotation:C,getBody:M,observe:o,unobserve:i,updateAnnotation:a,updateBody:U,updateTarget:(_,v=ne.LOCAL)=>{const y=q(_);y&&s(v,{updated:[y]})},upsertAnnotation:u}};let zi=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const qi=250,Ki=(e,t)=>{const n=zi(),o=(t==null?void 0:t.changes)||[];let i=t?t.pointer:-1,s=!1,r=0;const l=m=>{if(!s){const{changes:p}=m,k=performance.now();if(k-r>qi)o.splice(i+1),o.push(p),i=o.length-1;else{const b=o.length-1;o[b]=Gi(o[b],p)}r=k}s=!1};e.observe(l,{origin:ne.LOCAL});const a=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m),u=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),d=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({oldValue:p})=>p)),f=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({newValue:p})=>p)),h=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),g=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...o],pointer:i}),on:(m,p)=>n.on(m,p),redo:()=>{if(o.length-1>i){s=!0;const{created:m,updated:p,deleted:k}=o[i+1];u(m),f(p),g(k),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:m,updated:p,deleted:k}=o[i];a(m),d(p),h(k),n.emit("undo",o[i]),i-=1}}}},Wi=()=>{const e=Dt([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Zi=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],d,f;const h=(b,S)=>{a.has(b)?a.get(b).push(S):a.set(b,[S])},g=(b,S)=>{const w=a.get(b);if(w){const A=w.indexOf(S);A!==-1&&w.splice(A,1)}},m=(b,S,w)=>{a.has(b)&&setTimeout(()=>{a.get(b).forEach(A=>{if(n){const T=Array.isArray(S)?S.map(M=>n.serialize(M)):n.serialize(S),C=w?w instanceof PointerEvent?w:n.serialize(w):void 0;A(T,C)}else A(S,w)})},1)},p=()=>{const{selected:b}=s,S=(b||[]).map(({id:w})=>r.getAnnotation(w));S.forEach(w=>{const A=u.find(T=>T.id===w.id);(!A||!De(A,w))&&m("updateAnnotation",w,A)}),u=u.map(w=>S.find(({id:T})=>T===w.id)||w)};s.subscribe(({selected:b})=>{if(!(u.length===0&&b.length===0)){if(u.length===0&&b.length>0)u=b.map(({id:S})=>r.getAnnotation(S));else if(u.length>0&&b.length===0)u.forEach(S=>{const w=r.getAnnotation(S.id);w&&!De(w,S)&&m("updateAnnotation",w,S)}),u=[];else{const S=new Set(u.map(A=>A.id)),w=new Set(b.map(({id:A})=>A));u.filter(A=>!w.has(A.id)).forEach(A=>{const T=r.getAnnotation(A.id);T&&!De(T,A)&&m("updateAnnotation",T,A)}),u=[...u.filter(A=>w.has(A.id)),...b.filter(({id:A})=>!S.has(A)).map(({id:A})=>r.getAnnotation(A))]}m("selectionChanged",u)}}),i.subscribe(b=>{!d&&b?m("mouseEnterAnnotation",r.getAnnotation(b)):d&&!b?m("mouseLeaveAnnotation",r.getAnnotation(d)):d&&b&&(m("mouseLeaveAnnotation",r.getAnnotation(d)),m("mouseEnterAnnotation",r.getAnnotation(b))),d=b}),l==null||l.subscribe(b=>m("viewportIntersect",b.map(S=>r.getAnnotation(S)))),r.observe(b=>{o&&(f&&clearTimeout(f),f=setTimeout(p,1e3));const{created:S,deleted:w}=b.changes;(S||[]).forEach(A=>m("createAnnotation",A)),(w||[]).forEach(A=>m("deleteAnnotation",A)),(b.changes.updated||[]).filter(A=>[...A.bodiesCreated||[],...A.bodiesDeleted||[],...A.bodiesUpdated||[]].length>0).forEach(({oldValue:A,newValue:T})=>{const C=u.find(M=>M.id===A.id)||A;u=u.map(M=>M.id===A.id?T:M),m("updateAnnotation",T,C)})},{origin:ne.LOCAL}),r.observe(b=>{if(u){const S=new Set(u.map(A=>A.id)),w=(b.changes.updated||[]).filter(({newValue:A})=>S.has(A.id)).map(({newValue:A})=>A);w.length>0&&(u=u.map(A=>w.find(C=>C.id===A.id)||A))}},{origin:ne.REMOTE});const k=b=>S=>{const{updated:w}=S;b?(w||[]).forEach(A=>m("updateAnnotation",A.oldValue,A.newValue)):(w||[]).forEach(A=>m("updateAnnotation",A.newValue,A.oldValue))};return t.on("undo",k(!0)),t.on("redo",k(!1)),{on:h,off:g,emit:m}},Ji=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Qi=(e,t,n)=>{const{store:o,selection:i}=e,s=b=>{if(n){const{parsed:S,error:w}=n.parse(b);S?o.addAnnotation(S,ne.REMOTE):console.error(w)}else o.addAnnotation(Yt(b),ne.REMOTE)},r=()=>i.clear(),l=()=>o.clear(),a=b=>{const S=o.getAnnotation(b);return n&&S?n.serialize(S):S},u=()=>n?o.all().map(n.serialize):o.all(),d=()=>{var b;const S=(((b=i.selected)==null?void 0:b.map(w=>w.id))||[]).map(w=>o.getAnnotation(w)).filter(Boolean);return n?S.map(n.serialize):S},f=(b,S=!0)=>fetch(b).then(w=>w.json()).then(w=>(g(w,S),w)),h=b=>{if(typeof b=="string"){const S=o.getAnnotation(b);if(o.deleteAnnotation(b),S)return n?n.serialize(S):S}else{const S=n?n.parse(b).parsed:b;if(S)return o.deleteAnnotation(S),b}},g=(b,S=!0)=>{if(n){const w=n.parseAll||Ji(n),{parsed:A,failed:T}=w(b);T.length>0&&console.warn(`Discarded ${T.length} invalid annotations`,T),o.bulkAddAnnotations(A,S,ne.REMOTE)}else o.bulkAddAnnotations(b.map(Yt),S,ne.REMOTE)},m=(b,S)=>{b?i.setSelected(b,S):i.clear()},p=b=>{i.setUserSelectAction(b)},k=b=>{if(n){const S=n.parse(b).parsed,w=n.serialize(o.getAnnotation(S.id));return o.updateAnnotation(S),w}else{const S=o.getAnnotation(b.id);return o.updateAnnotation(Yt(b)),S}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:d,loadAnnotations:f,redo:t.redo,removeAnnotation:h,setAnnotations:g,setSelected:m,setUserSelectAction:p,undo:t.undo,updateAnnotation:k}},xi=(e,t,n)=>typeof t=="function"?t(e,n):t,$i=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,o)=>{const i=typeof e=="function"?e(n,o):e,s=typeof t=="function"?t(n,o):t;return{...i||{},...s||{}}},es="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ts=e=>crypto.getRandomValues(new Uint8Array(e)),ns=(e,t,n)=>{let o=(2<<Math.log2(e.length-1))-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let l=n(i),a=i|0;for(;a--;)if(r+=e[l[a]&o]||"",r.length>=s)return r}}},os=(e,t=21)=>ns(e,t|0,ts),is=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=es[n[e]&63];return t};const ss=()=>({isGuest:!0,id:os("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),rs=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Vn=e=>e?typeof e=="object"?{...e}:e:void 0,ls=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:l,modified:a,creator:u,...d}=n;return{id:o||`temp-${rs(n)}`,annotation:t,type:i,purpose:s,value:r,creator:Vn(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...d}}),as=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,l={...r,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l}),cs=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],us=()=>{const e=[...cs];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};is();const fs=(e,t={strict:!0,invertY:!1})=>({parse:i=>Xn(i,t),serialize:i=>Hn(i,e,t)}),Xn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Bn(),{creator:o,created:i,modified:s,body:r,...l}=e,a=ls(r||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,d=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,f=kn(d)?Mn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?Cn(d):void 0,h=Array.isArray(l.target)?l.target[0]:l.targret;return f||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Vn(o),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Hn=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:s,updated:r,updatedBy:l,...a}=e.target;let u;try{u=o.type==Q.RECTANGLE?Tn(o.geometry):On(o)}catch(f){if(n.strict)throw f;u=o}const d={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:as(e.bodies),created:s==null?void 0:s.toISOString(),creator:i,modified:r==null?void 0:r.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete d.bodies,typeof d.target!="string"&&"annotation"in d.target&&delete d.target.annotation,d},Ke=[];function ds(e,t=j){let n;const o=new Set;function i(l){if(re(e,l)&&(e=l,n)){const a=!Ke.length;for(const u of o)u[1](),Ke.push(u,e);if(a){for(let u=0;u<Ke.length;u+=2)Ke[u][0](Ke[u+1]);Ke.length=0}}}function s(l){i(l(e))}function r(l,a=j){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||j),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const hs=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},Gn=(e,t)=>{hs(e,t);const{subscribe:n,set:o}=ds(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,u=Math.max(r.width/l,r.height/a);o(u)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},He=(e,t,n)=>{const o=typeof t=="function"?t(e,n):t;if(o){const{fill:i,fillOpacity:s,stroke:r,strokeWidth:l,strokeOpacity:a}=o;let u="";return i&&(u+=`fill:${i};`),s||s===0?u+=`fill-opacity:${s};`:i&&(u+="fill-opacity:0.25;"),r&&(u+=`stroke:${r};`,u+=`stroke-width:${l||"1"};`,u+=`stroke-opacity:${a||"1"};`),u}},st=(e,t=0)=>{const{minX:n,minY:o,maxX:i,maxY:s}=e;return{x:n-t,y:o-t,w:i-n+2*t,h:s-o+2*t}},Ie=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,gs=e=>({}),jn=e=>({grab:e[0]});function ms(e){let t,n,o,i;const s=e[8].default,r=Ko(s,e,e[7],jn);return{c(){t=L("g"),r&&r.c(),c(t,"class","a9s-annotation selected")},m(l,a){N(l,t,a),r&&r.m(t,null),n=!0,o||(i=[J(t,"pointerup",e[2]),J(t,"pointermove",e[1])],o=!0)},p(l,[a]){r&&r.p&&(!n||a&128)&&Zo(r,s,l,l[7],n?Wo(s,l[7],a,gs):Jo(l[7]),jn)},i(l){n||(R(r,l),n=!0)},o(l){G(r,l),n=!1},d(l){l&&B(t),r&&r.d(l),o=!1,Ae(i)}}}function ps(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=Oe();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,d,f,h;const g=k=>b=>{if(d=k,u){const{left:w,top:A}=u.getBoundingClientRect(),T=b.clientX-w,C=b.clientY-A;f=a.elementToImage(T,C)}else{const{offsetX:w,offsetY:A}=b;f=a.elementToImage(w,A)}h=r,b.target.setPointerCapture(b.pointerId),s("grab",b)},m=k=>{if(d){const[b,S]=a.elementToImage(k.offsetX,k.offsetY),w=[b-f[0],S-f[1]];n(3,r=l(h,d,w)),s("change",r)}},p=k=>{k.target.releasePointerCapture(k.pointerId),d=void 0,h=r,s("release",k)};return e.$$set=k=>{"shape"in k&&n(3,r=k.shape),"editor"in k&&n(4,l=k.editor),"transform"in k&&n(5,a=k.transform),"svgEl"in k&&n(6,u=k.svgEl),"$$scope"in k&&n(7,i=k.$$scope)},[g,m,p,r,l,a,u,i,o]}class _t extends ge{constructor(t){super(),he(this,t,ps,ms,re,{shape:3,editor:4,transform:5,svgEl:6})}}function ys(e){let t,n,o,i,s,r,l,a,u=e[3]&&Fn(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),i=L("circle"),c(n,"class","a9s-handle-buffer svelte-qtyc7s"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]+6/e[2]),c(n,"role","button"),c(n,"tabindex","0"),c(i,"class",s=je(`a9s-handle-dot${e[3]?" selected":""}`)+" svelte-qtyc7s"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[5]),c(t,"class",r=`a9s-handle ${e[8].class||""}`.trim())},m(d,f){N(d,t,f),z(t,n),u&&u.m(t,null),z(t,i),l||(a=[J(n,"dblclick",e[12]),J(n,"pointerenter",e[13]),J(n,"pointerleave",e[14]),J(n,"pointerdown",e[15]),J(n,"pointerdown",e[6]),J(n,"pointerup",e[16]),J(n,"pointerup",e[7])],l=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&36&&o!==(o=d[5]+6/d[2])&&c(n,"r",o),d[3]?u?u.p(d,f):(u=Fn(d),u.c(),u.m(t,i)):u&&(u.d(1),u=null),f&8&&s!==(s=je(`a9s-handle-dot${d[3]?" selected":""}`)+" svelte-qtyc7s")&&c(i,"class",s),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&32&&c(i,"r",d[5]),f&256&&r!==(r=`a9s-handle ${d[8].class||""}`.trim())&&c(t,"class",r)},d(d){d&&B(t),u&&u.d(),l=!1,Ae(a)}}}function _s(e){let t,n,o,i,s,r,l,a,u;return{c(){t=L("g"),n=L("circle"),i=L("circle"),r=L("circle"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]*10),c(n,"class","a9s-touch-halo"),Pe(n,"touched",e[4]),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",s=e[5]+10/e[2]),c(i,"class","a9s-handle-buffer svelte-qtyc7s"),c(i,"role","button"),c(i,"tabindex","0"),c(r,"class","a9s-handle-dot"),c(r,"cx",e[0]),c(r,"cy",e[1]),c(r,"r",l=e[5]+2/e[2]),c(t,"class","a9s-touch-handle")},m(d,f){N(d,t,f),z(t,n),z(t,i),z(t,r),a||(u=[J(i,"dblclick",e[9]),J(i,"pointerdown",e[10]),J(i,"pointerdown",e[6]),J(i,"pointerup",e[11]),J(i,"pointerup",e[7])],a=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&32&&o!==(o=d[5]*10)&&c(n,"r",o),f&16&&Pe(n,"touched",d[4]),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&36&&s!==(s=d[5]+10/d[2])&&c(i,"r",s),f&1&&c(r,"cx",d[0]),f&2&&c(r,"cy",d[1]),f&36&&l!==(l=d[5]+2/d[2])&&c(r,"r",l)},d(d){d&&B(t),a=!1,Ae(u)}}}function Fn(e){let t,n;return{c(){t=L("circle"),c(t,"class","a9s-handle-selected"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",n=e[5]+8/e[2])},m(o,i){N(o,t,i)},p(o,i){i&1&&c(t,"cx",o[0]),i&2&&c(t,"cy",o[1]),i&36&&n!==(n=o[5]+8/o[2])&&c(t,"r",n)},d(o){o&&B(t)}}}function ws(e){let t;function n(s,r){return Ie?_s:ys}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),N(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&B(t),i.d(s)}}}function bs(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=w=>{w.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function f(w){ue.call(this,e,w)}function h(w){ue.call(this,e,w)}function g(w){ue.call(this,e,w)}function m(w){ue.call(this,e,w)}function p(w){ue.call(this,e,w)}function k(w){ue.call(this,e,w)}function b(w){ue.call(this,e,w)}function S(w){ue.call(this,e,w)}return e.$$set=w=>{n(8,t=Ce(Ce({},t),un(w))),"x"in w&&n(0,i=w.x),"y"in w&&n(1,s=w.y),"scale"in w&&n(2,r=w.scale),"selected"in w&&n(3,l=w.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=4/r)},t=un(t),[i,s,r,l,a,o,u,d,t,f,h,g,m,p,k,b,S]}class Ge extends ge{constructor(t){super(),he(this,t,bs,ws,re,{x:0,y:1,scale:2,selected:3})}}function Es(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("circle"),i=L("circle"),s=L("circle"),c(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=1.75*e[2]),c(i,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[2]),c(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),c(s,"cx",e[0]),c(s,"cy",e[1]),c(s,"r",e[2]),c(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(a,u){N(a,t,u),z(t,n),z(t,i),z(t,s),r||(l=[J(n,"pointerdown",e[5]),J(n,"pointerdown",e[3])],r=!0)},p(a,u){u&1&&c(n,"cx",a[0]),u&2&&c(n,"cy",a[1]),u&4&&o!==(o=1.75*a[2])&&c(n,"r",o),u&1&&c(i,"cx",a[0]),u&2&&c(i,"cy",a[1]),u&4&&c(i,"r",a[2]),u&1&&c(s,"cx",a[0]),u&2&&c(s,"cy",a[1]),u&4&&c(s,"r",a[2])},d(a){a&&B(t),r=!1,Ae(l)}}}function vs(e){let t;return{c(){t=L("circle"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",e[2])},m(n,o){N(n,t,o)},p(n,o){o&1&&c(t,"cx",n[0]),o&2&&c(t,"cy",n[1]),o&4&&c(t,"r",n[2])},d(n){n&&B(t)}}}function Ss(e){let t;function n(s,r){return Ie?vs:Es}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),N(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&B(t),i.d(s)}}}function As(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){ue.call(this,e,u)}return e.$$set=u=>{"x"in u&&n(0,i=u.x),"y"in u&&n(1,s=u.y),"scale"in u&&n(4,r=u.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,o=4/r)},[i,s,o,l,r,a]}class Rt extends ge{constructor(t){super(),he(this,t,As,Ss,re,{x:0,y:1,scale:4})}}function Vt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function zn(e,t,n){const o=e.slice();return o[28]=t[n],o[30]=n,o}function Xt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Ht(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function qn(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[28][0]),c(t,"cy",o=e[28][1]),c(t,"r",i=rt/e[3]),c(t,"class","svelte-1h2slbm")},m(s,r){N(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[28][1])&&c(t,"cy",o),r[0]&8&&i!==(i=rt/s[3])&&c(t,"r",i)},d(s){s&&B(t)}}}function Kn(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1h2slbm"),c(l,"cx",a=e[28][0]),c(l,"cy",u=e[28][1]),c(l,"r",d=rt/e[3]),c(l,"class","svelte-1h2slbm"),c(t,"id",`${e[19]}-inner`),c(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(f,h){N(f,t,h),z(t,n),z(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[28][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[28][1])&&c(l,"cy",u),h[0]&8&&d!==(d=rt/f[3])&&c(l,"r",d)},d(f){f&&B(t)}}}function Wn(e){let t,n;return t=new Ge({props:{class:"a9s-corner-handle",x:e[28][0],y:e[28][1],scale:e[3],selected:e[8].includes(e[30])}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[15]),t.$on("pointerdown",function(){ie(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&32&&(s.x=e[28][0]),i[0]&32&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),i[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Zn(e){let t,n;return t=new Rt({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[28][0]),i[0]&1088&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function ks(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,b,S,w,A,T,C=e[6]!==void 0&&!e[7]&&qn(Ht(e)),M=e[6]!==void 0&&!e[7]&&Kn(Xt(e)),V=ve(e[5].points),U=[];for(let _=0;_<V.length;_+=1)U[_]=Wn(zn(e,V,_));const W=_=>G(U[_],1,1,()=>{U[_]=null});let q=e[6]!==void 0&&!e[7]&&Zn(Vt(e));return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),C&&C.c(),M&&M.c(),d=we(),f=L("polygon"),g=we(),m=L("polygon"),k=we();for(let _=0;_<U.length;_+=1)U[_].c();b=we(),q&&q.c(),S=ke(),c(o,"x",i=e[9].x),c(o,"y",s=e[9].y),c(o,"width",r=e[9].w),c(o,"height",l=e[9].h),c(o,"class","svelte-1h2slbm"),c(a,"points",u=e[5].points.map(Jn).join(" ")),c(a,"class","svelte-1h2slbm"),c(n,"id",`${e[19]}-outer`),c(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[19]}-outer)`),c(f,"points",h=e[5].points.map(Qn).join(" ")),c(m,"class","a9s-inner a9s-shape-handle"),c(m,"mask",`url(#${e[19]}-inner)`),c(m,"style",e[1]),c(m,"points",p=e[5].points.map(xn).join(" "))},m(_,v){N(_,t,v),z(t,n),z(n,o),z(n,a),C&&C.m(n,null),M&&M.m(t,null),N(_,d,v),N(_,f,v),N(_,g,v),N(_,m,v),N(_,k,v);for(let y=0;y<U.length;y+=1)U[y]&&U[y].m(_,v);N(_,b,v),q&&q.m(_,v),N(_,S,v),w=!0,A||(T=[J(f,"pointerup",e[14]),J(f,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),J(m,"pointermove",e[13]),J(m,"pointerup",e[14]),J(m,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],A=!0)},p(_,v){if(e=_,(!w||v[0]&512&&i!==(i=e[9].x))&&c(o,"x",i),(!w||v[0]&512&&s!==(s=e[9].y))&&c(o,"y",s),(!w||v[0]&512&&r!==(r=e[9].w))&&c(o,"width",r),(!w||v[0]&512&&l!==(l=e[9].h))&&c(o,"height",l),(!w||v[0]&32&&u!==(u=e[5].points.map(Jn).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Ht(e),v):(C=qn(Ht(e)),C.c(),C.m(n,null)):C&&(C.d(1),C=null),e[6]!==void 0&&!e[7]?M?M.p(Xt(e),v):(M=Kn(Xt(e)),M.c(),M.m(t,null)):M&&(M.d(1),M=null),(!w||v[0]&32&&h!==(h=e[5].points.map(Qn).join(" ")))&&c(f,"points",h),(!w||v[0]&2)&&c(m,"style",e[1]),(!w||v[0]&32&&p!==(p=e[5].points.map(xn).join(" ")))&&c(m,"points",p),v[0]&134322472){V=ve(e[5].points);let y;for(y=0;y<V.length;y+=1){const E=zn(e,V,y);U[y]?(U[y].p(E,v),R(U[y],1)):(U[y]=Wn(E),U[y].c(),R(U[y],1),U[y].m(b.parentNode,b))}for(be(),y=V.length;y<U.length;y+=1)W(y);Ee()}e[6]!==void 0&&!e[7]?q?(q.p(Vt(e),v),v[0]&192&&R(q,1)):(q=Zn(Vt(e)),q.c(),R(q,1),q.m(S.parentNode,S)):q&&(be(),G(q,1,1,()=>{q=null}),Ee())},i(_){if(!w){for(let v=0;v<V.length;v+=1)R(U[v]);R(q),w=!0}},o(_){U=U.filter(Boolean);for(let v=0;v<U.length;v+=1)G(U[v]);G(q),w=!1},d(_){_&&(B(t),B(d),B(f),B(g),B(m),B(k),B(b),B(S)),C&&C.d(),M&&M.d(),Ye(U,_),q&&q.d(_),A=!1,Ae(T)}}}function Ms(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[ks,({grab:o})=>({27:o}),({grab:o})=>[o?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&134219754|i[1]&1&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ts=250,Ps=1e3,Ls=12,rt=4.5,Jn=e=>e.join(","),Qn=e=>e.join(","),xn=e=>e.join(",");function Is(e,t,n){let o,i,s;const r=Oe();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,g=!1,m,p=[];const k=()=>n(7,g=!0),b=()=>n(7,g=!1),S=y=>{if(p.length>0||!i.some(Z=>Z.visible)){n(6,h=void 0);return}const[E,I]=u.elementToImage(y.offsetX,y.offsetY),P=Z=>Math.pow(Z[0]-E,2)+Math.pow(Z[1]-I,2),D=o.points.reduce((Z,$)=>P($)<P(Z)?$:Z),F=i.filter(Z=>Z.visible).reduce((Z,$)=>P($.point)<P(Z.point)?$:Z),H=Math.pow(Ps/d,2);P(D)<H||P(F.point)<H?n(6,h=i.indexOf(F)):n(6,h=void 0)},w=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,p=[]),w()},T=y=>{n(7,g=!0),y.preventDefault(),y.stopPropagation(),m=performance.now()},C=y=>E=>{if(!m||Ie||performance.now()-m>Ts)return;const I=p.includes(y);E.metaKey||E.ctrlKey||E.shiftKey?I?n(8,p=p.filter(P=>P!==y)):n(8,p=[...p,y]):I&&p.length>1?n(8,p=[y]):I?n(8,p=[]):n(8,p=[y]),w()},M=(y,E,I)=>{w();let P;const D=y.geometry;p.length>1?P=D.points.map(([H,x],Z)=>p.includes(Z)?[H+I[0],x+I[1]]:[H,x]):E==="SHAPE"?P=D.points.map(([H,x])=>[H+I[0],x+I[1]]):P=D.points.map(([H,x],Z)=>E===`HANDLE-${Z}`?[H+I[0],x+I[1]]:[H,x]);const F=fe(P);return{...y,geometry:{points:P,bounds:F}}},V=y=>async E=>{E.stopPropagation();const I=[...o.points.slice(0,y+1),i[y].point,...o.points.slice(y+1)],P=fe(I);r("change",{...l,geometry:{points:I,bounds:P}}),await pn();const D=[...document.querySelectorAll(".a9s-handle")][y+1];if(D!=null&&D.firstChild){const F=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:E.clientX,clientY:E.clientY,pointerId:E.pointerId,pointerType:E.pointerType,isPrimary:E.isPrimary,buttons:E.buttons});D.firstChild.dispatchEvent(F)}},U=()=>{if(o.points.length-p.length<3)return;const y=o.points.filter((I,P)=>!p.includes(P)),E=fe(y);r("change",{...l,geometry:{points:y,bounds:E}}),n(8,p=[])};Re(()=>{if(Ie)return;const y=E=>{(E.key==="Delete"||E.key==="Backspace")&&(E.preventDefault(),U())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",y),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",y)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function q(y){ue.call(this,e,y)}function _(y){ue.call(this,e,y)}function v(y){ue.call(this,e,y)}return e.$$set=y=>{"shape"in y&&n(0,l=y.shape),"computedStyle"in y&&n(1,a=y.computedStyle),"transform"in y&&n(2,u=y.transform),"viewportScale"in y&&n(3,d=y.viewportScale),"svgEl"in y&&n(4,f=y.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Ie?[]:o.points.map((y,E)=>{const I=E===o.points.length-1?o.points[0]:o.points[E+1],P=(y[0]+I[0])/2,D=(y[1]+I[1])/2,H=Math.sqrt(Math.pow(I[0]-P,2)+Math.pow(I[1]-D,2))>Ls/d;return{point:[P,D],visible:H}})),e.$$.dirty[0]&40&&n(9,s=st(o.bounds,rt/d))},[l,a,u,d,f,o,h,g,p,s,i,k,b,S,A,T,C,M,V,W,q,_,v]}class $n extends ge{constructor(t){super(),he(this,t,Is,Ms,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Cs(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,b,S,w,A,T,C,M,V,U,W,q,_,v,y,E,I,P,D,F,H,x,Z,$,oe,se,Se,Te,X,de,te,ye,_e,Je,Ne,nn,Ue,ee,on,zo;return te=new Ge({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),_e=new Ge({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),_e.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),Ne=new Ge({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),Ne.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Ue=new Ge({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Ue.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),g=we(),m=L("rect"),w=we(),A=L("rect"),U=we(),W=L("rect"),y=we(),E=L("rect"),F=we(),H=L("rect"),oe=we(),se=L("rect"),de=we(),ce(te.$$.fragment),ye=we(),ce(_e.$$.fragment),Je=we(),ce(Ne.$$.fragment),nn=we(),ce(Ue.$$.fragment),c(o,"class","rect-mask-bg svelte-1njczvj"),c(o,"x",i=e[6].x),c(o,"y",s=e[6].y),c(o,"width",r=e[6].w),c(o,"height",l=e[6].h),c(a,"class","rect-mask-fg svelte-1njczvj"),c(a,"x",u=e[5].x),c(a,"y",d=e[5].y),c(a,"width",f=e[5].w),c(a,"height",h=e[5].h),c(n,"id",e[8]),c(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),c(m,"class","a9s-outer"),c(m,"mask",`url(#${e[8]})`),c(m,"x",p=e[5].x),c(m,"y",k=e[5].y),c(m,"width",b=e[5].w),c(m,"height",S=e[5].h),c(A,"class","a9s-inner a9s-shape-handle"),c(A,"style",e[1]),c(A,"x",T=e[5].x),c(A,"y",C=e[5].y),c(A,"width",M=e[5].w),c(A,"height",V=e[5].h),c(W,"class","a9s-edge-handle a9s-edge-handle-top"),c(W,"x",q=e[5].x),c(W,"y",_=e[5].y),c(W,"height",1),c(W,"width",v=e[5].w),c(E,"class","a9s-edge-handle a9s-edge-handle-right"),c(E,"x",I=e[5].x+e[5].w),c(E,"y",P=e[5].y),c(E,"height",D=e[5].h),c(E,"width",1),c(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),c(H,"x",x=e[5].x),c(H,"y",Z=e[5].y+e[5].h),c(H,"height",1),c(H,"width",$=e[5].w),c(se,"class","a9s-edge-handle a9s-edge-handle-left"),c(se,"x",Se=e[5].x),c(se,"y",Te=e[5].y),c(se,"height",X=e[5].h),c(se,"width",1)},m(K,Y){N(K,t,Y),z(t,n),z(n,o),z(n,a),N(K,g,Y),N(K,m,Y),N(K,w,Y),N(K,A,Y),N(K,U,Y),N(K,W,Y),N(K,y,Y),N(K,E,Y),N(K,F,Y),N(K,H,Y),N(K,oe,Y),N(K,se,Y),N(K,de,Y),le(te,K,Y),N(K,ye,Y),le(_e,K,Y),N(K,Je,Y),le(Ne,K,Y),N(K,nn,Y),le(Ue,K,Y),ee=!0,on||(zo=[J(m,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),J(A,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),J(W,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),J(E,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),J(H,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),J(se,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],on=!0)},p(K,Y){e=K,(!ee||Y&64&&i!==(i=e[6].x))&&c(o,"x",i),(!ee||Y&64&&s!==(s=e[6].y))&&c(o,"y",s),(!ee||Y&64&&r!==(r=e[6].w))&&c(o,"width",r),(!ee||Y&64&&l!==(l=e[6].h))&&c(o,"height",l),(!ee||Y&32&&u!==(u=e[5].x))&&c(a,"x",u),(!ee||Y&32&&d!==(d=e[5].y))&&c(a,"y",d),(!ee||Y&32&&f!==(f=e[5].w))&&c(a,"width",f),(!ee||Y&32&&h!==(h=e[5].h))&&c(a,"height",h),(!ee||Y&32&&p!==(p=e[5].x))&&c(m,"x",p),(!ee||Y&32&&k!==(k=e[5].y))&&c(m,"y",k),(!ee||Y&32&&b!==(b=e[5].w))&&c(m,"width",b),(!ee||Y&32&&S!==(S=e[5].h))&&c(m,"height",S),(!ee||Y&2)&&c(A,"style",e[1]),(!ee||Y&32&&T!==(T=e[5].x))&&c(A,"x",T),(!ee||Y&32&&C!==(C=e[5].y))&&c(A,"y",C),(!ee||Y&32&&M!==(M=e[5].w))&&c(A,"width",M),(!ee||Y&32&&V!==(V=e[5].h))&&c(A,"height",V),(!ee||Y&32&&q!==(q=e[5].x))&&c(W,"x",q),(!ee||Y&32&&_!==(_=e[5].y))&&c(W,"y",_),(!ee||Y&32&&v!==(v=e[5].w))&&c(W,"width",v),(!ee||Y&32&&I!==(I=e[5].x+e[5].w))&&c(E,"x",I),(!ee||Y&32&&P!==(P=e[5].y))&&c(E,"y",P),(!ee||Y&32&&D!==(D=e[5].h))&&c(E,"height",D),(!ee||Y&32&&x!==(x=e[5].x))&&c(H,"x",x),(!ee||Y&32&&Z!==(Z=e[5].y+e[5].h))&&c(H,"y",Z),(!ee||Y&32&&$!==($=e[5].w))&&c(H,"width",$),(!ee||Y&32&&Se!==(Se=e[5].x))&&c(se,"x",Se),(!ee||Y&32&&Te!==(Te=e[5].y))&&c(se,"y",Te),(!ee||Y&32&&X!==(X=e[5].h))&&c(se,"height",X);const Et={};Y&32&&(Et.x=e[5].x),Y&32&&(Et.y=e[5].y),Y&8&&(Et.scale=e[3]),te.$set(Et);const vt={};Y&32&&(vt.x=e[5].x+e[5].w),Y&32&&(vt.y=e[5].y),Y&8&&(vt.scale=e[3]),_e.$set(vt);const St={};Y&32&&(St.x=e[5].x+e[5].w),Y&32&&(St.y=e[5].y+e[5].h),Y&8&&(St.scale=e[3]),Ne.$set(St);const At={};Y&32&&(At.x=e[5].x),Y&32&&(At.y=e[5].y+e[5].h),Y&8&&(At.scale=e[3]),Ue.$set(At)},i(K){ee||(R(te.$$.fragment,K),R(_e.$$.fragment,K),R(Ne.$$.fragment,K),R(Ue.$$.fragment,K),ee=!0)},o(K){G(te.$$.fragment,K),G(_e.$$.fragment,K),G(Ne.$$.fragment,K),G(Ue.$$.fragment,K),ee=!1},d(K){K&&(B(t),B(g),B(m),B(w),B(A),B(U),B(W),B(y),B(E),B(F),B(H),B(oe),B(se),B(de),B(ye),B(Je),B(nn)),ae(te,K),ae(_e,K),ae(Ne,K),ae(Ue,K),on=!1,Ae(zo)}}}function Os(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Cs,({grab:o})=>({12:o}),({grab:o})=>o?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&16&&(s.svgEl=o[4]),i&12394&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ds(e,t,n){let o,i,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const d=(p,k,b)=>{const S=p.geometry.bounds;let[w,A]=[S.minX,S.minY],[T,C]=[S.maxX,S.maxY];const[M,V]=b;if(k==="SHAPE")w+=M,T+=M,A+=V,C+=V;else{switch(k){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{A+=V;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{C+=V;break}}switch(k){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{w+=M;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{T+=M;break}}}const U=Math.min(w,T),W=Math.min(A,C),q=Math.abs(T-w),_=Math.abs(C-A);return{...p,geometry:{x:U,y:W,w:q,h:_,bounds:{minX:U,minY:W,maxX:U+q,maxY:W+_}}}},f=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function h(p){ue.call(this,e,p)}function g(p){ue.call(this,e,p)}function m(p){ue.call(this,e,p)}return e.$$set=p=>{"shape"in p&&n(0,s=p.shape),"computedStyle"in p&&n(1,r=p.computedStyle),"transform"in p&&n(2,l=p.transform),"viewportScale"in p&&n(3,a=p.viewportScale),"svgEl"in p&&n(4,u=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,o=s.geometry),e.$$.dirty&40&&n(6,i=st(o.bounds,2/a))},[s,r,l,a,u,o,i,d,f,h,g,m]}class eo extends ge{constructor(t){super(),he(this,t,Ds,Os,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var to=Object.prototype.hasOwnProperty;function Gt(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&Gt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(to.call(e,n)&&++o&&!to.call(t,n)||!(n in t)||!Gt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Bs=12,Ns=(e,t)=>e.polygons.reduce((n,o,i)=>{const s=o.rings.reduce((r,l,a)=>{const u=l.points.map((d,f)=>{const h=f===l.points.length-1?l.points[0]:l.points[f+1],g=(d[0]+h[0])/2,m=(d[1]+h[1])/2,k=Math.sqrt(Math.pow(h[0]-g,2)+Math.pow(h[1]-m,2))>Bs/t;return{point:[g,m],visible:k,elementIdx:i,ringIdx:a,pointIdx:f}});return[...r,...u]},[]);return[...n,...s]},[]);function jt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function no(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function oo(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function io(e,t,n){const o=e.slice();return o[29]=t[n],o[37]=n,o}function Ft(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function zt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function so(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[29][0]),c(t,"cy",o=e[29][1]),c(t,"r",i=lt/e[3]),c(t,"class","svelte-1vxo6dc")},m(s,r){N(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[29][1])&&c(t,"cy",o),r[0]&8&&i!==(i=lt/s[3])&&c(t,"r",i)},d(s){s&&B(t)}}}function ro(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1vxo6dc"),c(l,"cx",a=e[29][0]),c(l,"cy",u=e[29][1]),c(l,"r",d=lt/e[3]),c(l,"class","svelte-1vxo6dc"),c(t,"id",`${e[18]}-${e[32]}-inner`),c(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(f,h){N(f,t,h),z(t,n),z(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[29][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[29][1])&&c(l,"cy",u),h[0]&8&&d!==(d=lt/f[3])&&c(l,"r",d)},d(f){f&&B(t)}}}function lo(e){let t,n;function o(...i){return e[19](e[32],e[35],e[37],...i)}return t=new Ge({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(o)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){ie(e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`))&&e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`).apply(this,arguments)}),t.$on("pointerup",e[15](e[32],e[35],e[37])),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){e=i;const r={};s[0]&32&&(r.x=e[29][0]),s[0]&32&&(r.y=e[29][1]),s[0]&8&&(r.scale=e[3]),s[0]&256&&(r.selected=e[8].some(o)),t.$set(r)},i(i){n||(R(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function ao(e){let t,n,o=ve(e[33].points),i=[];for(let r=0;r<o.length;r+=1)i[r]=lo(io(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);N(r,t,l),n=!0},p(r,l){if(l[0]&268491048){o=ve(r[33].points);let a;for(a=0;a<o.length;a+=1){const u=io(r,o,a);i[a]?(i[a].p(u,l),R(i[a],1)):(i[a]=lo(u),i[a].c(),R(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)R(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&B(t),Ye(i,r)}}}function co(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,b,S=e[6]!==void 0&&!e[7]&&so(zt(e)),w=e[6]!==void 0&&!e[7]&&ro(Ft(e)),A=ve(e[30].rings),T=[];for(let M=0;M<A.length;M+=1)T[M]=ao(oo(e,A,M));const C=M=>G(T[M],1,1,()=>{T[M]=null});return{c(){t=L("g"),n=L("defs"),o=L("mask"),i=L("rect"),u=L("path"),S&&S.c(),w&&w.c(),f=L("path"),g=L("path");for(let M=0;M<T.length;M+=1)T[M].c();c(i,"x",s=e[9].x),c(i,"y",r=e[9].y),c(i,"width",l=e[9].w),c(i,"height",a=e[9].h),c(i,"class","svelte-1vxo6dc"),c(u,"d",d=Le(e[30])),c(u,"class","svelte-1vxo6dc"),c(o,"id",`${e[18]}-${e[32]}-outer`),c(o,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[18]}-${e[32]}-outer)`),c(f,"fill-rule","evenodd"),c(f,"d",h=Le(e[30])),c(g,"class","a9s-inner"),c(g,"mask",`url(#${e[18]}-${e[32]}-inner)`),c(g,"style",e[1]),c(g,"fill-rule","evenodd"),c(g,"d",m=Le(e[30]))},m(M,V){N(M,t,V),z(t,n),z(n,o),z(o,i),z(o,u),S&&S.m(o,null),w&&w.m(n,null),z(t,f),z(t,g);for(let U=0;U<T.length;U+=1)T[U]&&T[U].m(t,null);p=!0,k||(b=[J(f,"pointerup",e[13]),J(f,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),J(g,"pointerup",e[13]),J(g,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],k=!0)},p(M,V){if(e=M,(!p||V[0]&512&&s!==(s=e[9].x))&&c(i,"x",s),(!p||V[0]&512&&r!==(r=e[9].y))&&c(i,"y",r),(!p||V[0]&512&&l!==(l=e[9].w))&&c(i,"width",l),(!p||V[0]&512&&a!==(a=e[9].h))&&c(i,"height",a),(!p||V[0]&32&&d!==(d=Le(e[30])))&&c(u,"d",d),e[6]!==void 0&&!e[7]?S?S.p(zt(e),V):(S=so(zt(e)),S.c(),S.m(o,null)):S&&(S.d(1),S=null),e[6]!==void 0&&!e[7]?w?w.p(Ft(e),V):(w=ro(Ft(e)),w.c(),w.m(n,null)):w&&(w.d(1),w=null),(!p||V[0]&32&&h!==(h=Le(e[30])))&&c(f,"d",h),(!p||V[0]&2)&&c(g,"style",e[1]),(!p||V[0]&32&&m!==(m=Le(e[30])))&&c(g,"d",m),V[0]&268491048){A=ve(e[30].rings);let U;for(U=0;U<A.length;U+=1){const W=oo(e,A,U);T[U]?(T[U].p(W,V),R(T[U],1)):(T[U]=ao(W),T[U].c(),R(T[U],1),T[U].m(t,null))}for(be(),U=A.length;U<T.length;U+=1)C(U);Ee()}},i(M){if(!p){for(let V=0;V<A.length;V+=1)R(T[V]);p=!0}},o(M){T=T.filter(Boolean);for(let V=0;V<T.length;V+=1)G(T[V]);p=!1},d(M){M&&B(t),S&&S.d(),w&&w.d(),Ye(T,M),k=!1,Ae(b)}}}function uo(e){let t,n;return t=new Rt({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[29][0]),i[0]&1088&&(s.y=e[29][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Us(e){let t,n,o,i=ve(e[5].polygons),s=[];for(let a=0;a<i.length;a+=1)s[a]=co(no(e,i,a));const r=a=>G(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&uo(jt(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=we(),l&&l.c(),n=ke()},m(a,u){for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(a,u);N(a,t,u),l&&l.m(a,u),N(a,n,u),o=!0},p(a,u){if(u[0]&268763114){i=ve(a[5].polygons);let d;for(d=0;d<i.length;d+=1){const f=no(a,i,d);s[d]?(s[d].p(f,u),R(s[d],1)):(s[d]=co(f),s[d].c(),R(s[d],1),s[d].m(t.parentNode,t))}for(be(),d=i.length;d<s.length;d+=1)r(d);Ee()}a[6]!==void 0&&!a[7]?l?(l.p(jt(a),u),u[0]&192&&R(l,1)):(l=uo(jt(a)),l.c(),R(l,1),l.m(n.parentNode,n)):l&&(be(),G(l,1,1,()=>{l=null}),Ee())},i(a){if(!o){for(let u=0;u<i.length;u+=1)R(s[u]);R(l),o=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)G(s[u]);G(l),o=!1},d(a){a&&(B(t),B(n)),Ye(s,a),l&&l.d(a)}}}function Ys(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[Us,({grab:o})=>({28:o}),({grab:o})=>[o?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&268437482|i[1]&128&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Rs=250,Vs=1e3,lt=4.5;function Xs(e,t,n){let o,i,s;const r=Oe();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,g=!1,m,p=[];const k=()=>n(7,g=!0),b=()=>n(7,g=!1),S=E=>{if(p.length>0||!i.some($=>$.visible)){n(6,h=void 0);return}const[I,P]=u.elementToImage(E.offsetX,E.offsetY),D=$=>Math.pow($[0]-I,2)+Math.pow($[1]-P,2),F=En(o).reduce(($,oe)=>D(oe)<D($)?oe:$),H=i.filter($=>$.visible).reduce(($,oe)=>D(oe.point)<D($.point)?oe:$),x=Math.pow(Vs/d,2);D(F)<x||D(H.point)<x?n(6,h=i.indexOf(H)):n(6,h=void 0)},w=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,p=[]),w()},T=E=>{n(7,g=!0),E.preventDefault(),E.stopPropagation(),m=performance.now()},C=(E,I,P)=>D=>{if(!m||Ie||performance.now()-m>Rs)return;const F=x=>x.polygon===E&&x.ring===I&&x.point===P,H=p.some(F);D.metaKey||D.ctrlKey||D.shiftKey?H?n(8,p=p.filter(x=>!F(x))):n(8,p=[...p,{polygon:E,ring:I,point:P}]):H&&p.length>1?n(8,p=[{polygon:E,ring:I,point:P}]):H?n(8,p=[]):n(8,p=[{polygon:E,ring:I,point:P}]),w()},M=(E,I,P)=>{w();const D=E.geometry.polygons;let F;if(I==="SHAPE")F=D.map(H=>{const x=H.rings.map(($,oe)=>({points:$.points.map((Se,Te)=>[Se[0]+P[0],Se[1]+P[1]])})),Z=fe(x[0].points);return{rings:x,bounds:Z}});else{const[H,x,Z,$]=I.split("-").map(oe=>parseInt(oe));F=D.map((oe,se)=>{if(se===x){const Se=oe.rings.map((X,de)=>de===Z?{points:X.points.map((ye,_e)=>_e===$?[ye[0]+P[0],ye[1]+P[1]]:ye)}:X),Te=fe(Se[0].points);return{rings:Se,bounds:Te}}else return oe})}return{...E,geometry:{polygons:F,bounds:nt(F)}}},V=E=>async I=>{I.stopPropagation();const P=i[E],D=o.polygons.map((H,x)=>{if(x===P.elementIdx){const Z=H.rings.map((oe,se)=>se===P.ringIdx?{points:[...oe.points.slice(0,P.pointIdx+1),P.point,...oe.points.slice(P.pointIdx+1)]}:oe),$=fe(Z[0].points);return{rings:Z,bounds:$}}else return H});r("change",{...l,geometry:{polygons:D,bounds:nt(D)}}),await pn();const F=[...document.querySelectorAll(".a9s-handle")][E+1];if(F!=null&&F.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:I.clientX,clientY:I.clientY,pointerId:I.pointerId,pointerType:I.pointerType,isPrimary:I.isPrimary,buttons:I.buttons});F.firstChild.dispatchEvent(H)}},U=()=>{const E=o.polygons.map((P,D)=>{if(p.some(H=>H.polygon===D)){const H=P.rings.map((Z,$)=>{const oe=p.filter(se=>se.polygon===D&&se.ring===$);return oe.length&&Z.points.length-oe.length>=3?{points:Z.points.filter((Se,Te)=>!oe.some(X=>X.point===Te))}:Z}),x=fe(H[0].points);return{rings:H,bounds:x}}else return P});!Gt(o.polygons,E)&&(r("change",{...l,geometry:{polygons:E,bounds:nt(E)}}),n(8,p=[]))};Re(()=>{if(Ie)return;const E=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),U())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",E),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",E)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,q=(E,I,P,{polygon:D,ring:F,point:H})=>D===E&&F===I&&H===P;function _(E){ue.call(this,e,E)}function v(E){ue.call(this,e,E)}function y(E){ue.call(this,e,E)}return e.$$set=E=>{"shape"in E&&n(0,l=E.shape),"computedStyle"in E&&n(1,a=E.computedStyle),"transform"in E&&n(2,u=E.transform),"viewportScale"in E&&n(3,d=E.viewportScale),"svgEl"in E&&n(4,f=E.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Ie?[]:Ns(o,d)),e.$$.dirty[0]&40&&n(9,s=st(o.bounds,lt/d))},[l,a,u,d,f,o,h,g,p,s,i,k,b,A,T,C,M,V,W,q,_,v,y]}class Hs extends ge{constructor(t){super(),he(this,t,Xs,Ys,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const fo=new Map([[Q.RECTANGLE,eo],[Q.POLYGON,$n],[Q.MULTIPOLYGON,Hs]]),ho=e=>fo.get(e.type),go=(e,t)=>fo.set(e,t);function Gs(e,t,n){let o;const i=Oe();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,f;return Re(()=>(n(6,f=new r({target:a,props:{shape:s.target.selector,computedStyle:o,transform:u,viewportScale:d,svgEl:a.closest("svg")}})),f.$on("change",h=>{f.$$set({shape:h.detail}),i("change",h.detail)}),f.$on("grab",h=>i("grab",h.detail)),f.$on("release",h=>i("release",h.detail)),()=>{f.$destroy()})),e.$$set=h=>{"annotation"in h&&n(0,s=h.annotation),"editor"in h&&n(1,r=h.editor),"style"in h&&n(2,l=h.style),"target"in h&&n(3,a=h.target),"transform"in h&&n(4,u=h.transform),"viewportScale"in h&&n(5,d=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,o=He(s,l,{selected:!0,hovered:!0})),e.$$.dirty&65&&s&&(f==null||f.$set({shape:s.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:u}),e.$$.dirty&96&&f&&f.$set({viewportScale:d}),e.$$.dirty&192&&f&&o&&f.$set({computedStyle:o})},[s,r,l,a,u,d,f,o]}class mo extends ge{constructor(t){super(),he(this,t,Gs,null,re,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function js(e,t,n){const o=Oe();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return Re(()=>{const d=s.closest("svg"),f=[],h=(g,m,p)=>{d==null||d.addEventListener(g,m,p),f.push(()=>d==null?void 0:d.removeEventListener(g,m,p))};return n(5,u=new r({target:s,props:{addEventListener:h,drawingMode:i,transform:l,viewportScale:a}})),u.$on("create",g=>o("create",g.detail)),()=>{f.forEach(g=>g()),u.$destroy()}}),e.$$set=d=>{"drawingMode"in d&&n(0,i=d.drawingMode),"target"in d&&n(1,s=d.target),"tool"in d&&n(2,r=d.tool),"transform"in d&&n(3,l=d.transform),"viewportScale"in d&&n(4,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:l}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[i,s,r,l,a,u]}class po extends ge{constructor(t){super(),he(this,t,js,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function yo(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),u=L("rect"),d=L("rect"),c(o,"class","rect-mask-bg svelte-1a76qe7"),c(o,"x",i=e[1]-e[5]),c(o,"y",s=e[2]-e[5]),c(o,"width",r=e[3]+2*e[5]),c(o,"height",l=e[4]+2*e[5]),c(a,"class","rect-mask-fg svelte-1a76qe7"),c(a,"x",e[1]),c(a,"y",e[2]),c(a,"width",e[3]),c(a,"height",e[4]),c(n,"id",e[6]),c(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),c(u,"class","a9s-outer"),c(u,"mask",`url(#${e[6]})`),c(u,"x",e[1]),c(u,"y",e[2]),c(u,"width",e[3]),c(u,"height",e[4]),c(d,"class","a9s-inner"),c(d,"x",e[1]),c(d,"y",e[2]),c(d,"width",e[3]),c(d,"height",e[4])},m(f,h){N(f,t,h),z(t,n),z(n,o),z(n,a),N(f,u,h),N(f,d,h)},p(f,h){h&34&&i!==(i=f[1]-f[5])&&c(o,"x",i),h&36&&s!==(s=f[2]-f[5])&&c(o,"y",s),h&40&&r!==(r=f[3]+2*f[5])&&c(o,"width",r),h&48&&l!==(l=f[4]+2*f[5])&&c(o,"height",l),h&2&&c(a,"x",f[1]),h&4&&c(a,"y",f[2]),h&8&&c(a,"width",f[3]),h&16&&c(a,"height",f[4]),h&2&&c(u,"x",f[1]),h&4&&c(u,"y",f[2]),h&8&&c(u,"width",f[3]),h&16&&c(u,"height",f[4]),h&2&&c(d,"x",f[1]),h&4&&c(d,"y",f[2]),h&8&&c(d,"width",f[3]),h&16&&c(d,"height",f[4])},d(f){f&&(B(t),B(u),B(d))}}}function Fs(e){let t,n=e[0]&&yo(e);return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){N(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=yo(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&B(t),n&&n.d()}}}function zs(e,t,n){let o;const i=Oe();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,d,f,h,g,m,p;const k=T=>{const C=T;u=performance.now(),r==="drag"&&(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,g=d[1]),n(3,m=1),n(4,p=1))},b=T=>{const C=T;d&&(f=l.elementToImage(C.offsetX,C.offsetY),n(1,h=Math.min(f[0],d[0])),n(2,g=Math.min(f[1],d[1])),n(3,m=Math.abs(f[0]-d[0])),n(4,p=Math.abs(f[1]-d[1])))},S=T=>{const C=T,M=performance.now()-u;if(r==="click"){if(M>300)return;d?w():(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,g=d[1]),n(3,m=1),n(4,p=1))}else d&&(M>300||m*p>100?(C.stopPropagation(),w()):(n(0,d=void 0),f=void 0))},w=()=>{if(m*p>15){const T={type:Q.RECTANGLE,geometry:{bounds:{minX:h,minY:g,maxX:h+m,maxY:g+p},x:h,y:g,w:m,h:p}};i("create",T)}n(0,d=void 0),f=void 0};Re(()=>{s("pointerdown",k),s("pointermove",b),s("pointerup",S,!0)});const A=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=T=>{"addEventListener"in T&&n(7,s=T.addEventListener),"drawingMode"in T&&n(8,r=T.drawingMode),"transform"in T&&n(9,l=T.transform),"viewportScale"in T&&n(10,a=T.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,o=2/a)},[d,h,g,m,p,o,A,s,r,l,a]}class _o extends ge{constructor(t){super(),he(this,t,zs,Fs,re,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function qt(e){const t=e.slice(),n=t[2].map(o=>o.join(",")).join(" ");return t[19]=n,t}function wo(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p=e[1]&&bo(e);return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),d=L("polygon"),h=L("polygon"),p&&p.c(),m=ke(),c(o,"x",i=e[3].x),c(o,"y",s=e[3].y),c(o,"width",r=e[3].w),c(o,"height",l=e[3].h),c(o,"class","svelte-18wrg3t"),c(a,"points",u=e[19]),c(a,"class","svelte-18wrg3t"),c(n,"id",e[5]),c(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),c(d,"class","a9s-outer"),c(d,"mask",`url(#${e[5]})`),c(d,"points",f=e[19]),c(h,"class","a9s-inner"),c(h,"points",g=e[19])},m(k,b){N(k,t,b),z(t,n),z(n,o),z(n,a),N(k,d,b),N(k,h,b),p&&p.m(k,b),N(k,m,b)},p(k,b){b&8&&i!==(i=k[3].x)&&c(o,"x",i),b&8&&s!==(s=k[3].y)&&c(o,"y",s),b&8&&r!==(r=k[3].w)&&c(o,"width",r),b&8&&l!==(l=k[3].h)&&c(o,"height",l),b&4&&u!==(u=k[19])&&c(a,"points",u),b&4&&f!==(f=k[19])&&c(d,"points",f),b&4&&g!==(g=k[19])&&c(h,"points",g),k[1]?p?p.p(k,b):(p=bo(k),p.c(),p.m(m.parentNode,m)):p&&(p.d(1),p=null)},d(k){k&&(B(t),B(d),B(h),B(m)),p&&p.d(k)}}}function bo(e){let t,n,o;return{c(){t=L("circle"),c(t,"class","a9s-handle svelte-18wrg3t"),c(t,"cx",n=e[0][0][0]),c(t,"cy",o=e[0][0][1]),c(t,"r",e[4])},m(i,s){N(i,t,s)},p(i,s){s&1&&n!==(n=i[0][0][0])&&c(t,"cx",n),s&1&&o!==(o=i[0][0][1])&&c(t,"cy",o),s&16&&c(t,"r",i[4])},d(i){i&&B(t)}}}function qs(e){let t,n=e[3]&&wo(qt(e));return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){N(o,t,i),n&&n.m(t,null)},p(o,[i]){o[3]?n?n.p(qt(o),i):(n=wo(qt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&B(t),n&&n.d()}}}const Ks=20,Ws=1500;function Zs(e,t,n){let o,i,s;const r=Oe();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,f,h=[],g,m,p=!1;const k=C=>{const M=C,{timeStamp:V,offsetX:U,offsetY:W}=M;if(f={timeStamp:V,offsetX:U,offsetY:W},a==="drag"&&h.length===0){const q=u.elementToImage(M.offsetX,M.offsetY);h.push(q),n(10,g=q)}},b=C=>{const M=C;if(m&&clearTimeout(m),h.length>0){if(n(10,g=u.elementToImage(M.offsetX,M.offsetY)),h.length>2){const V=tt(g,h[0])*d;n(1,p=V<Ks)}M.pointerType==="touch"&&(m=setTimeout(()=>{w()},Ws))}},S=C=>{const M=C;if(m&&clearTimeout(m),a==="click"){const V=M.timeStamp-f.timeStamp,U=tt([f.offsetX,f.offsetY],[M.offsetX,M.offsetY]);if(V>300||U>15)return;if(p)A();else if(h.length===0){const W=u.elementToImage(M.offsetX,M.offsetY);h.push(W),n(10,g=W)}else g&&h.push(g)}else{if(!g)return;if(h.length===1&&tt(h[0],g)<=4){n(0,h=[]),n(10,g=void 0);return}M.stopImmediatePropagation(),p?A():h.push(g)}},w=()=>{if(!g)return;const C=h.slice(0,-1);if(C.length<3)return;const M={type:Q.POLYGON,geometry:{bounds:fe(h),points:C}};ht(M)>4&&(n(0,h=[]),n(10,g=void 0),r("create",M))},A=()=>{const C={type:Q.POLYGON,geometry:{bounds:fe(h),points:[...h]}};n(0,h=[]),n(10,g=void 0),r("create",C)};Re(()=>{l("pointerdown",k,!0),l("pointermove",b),l("pointerup",S,!0),l("dblclick",w,!0)});const T=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=C=>{"addEventListener"in C&&n(6,l=C.addEventListener),"drawingMode"in C&&n(7,a=C.drawingMode),"transform"in C&&n(8,u=C.transform),"viewportScale"in C&&n(9,d=C.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,o=4/d),e.$$.dirty&1027&&n(2,i=g?p?h:[...h,g]:[]),e.$$.dirty&516&&n(3,s=i.length>0?st(fe(i),2/d):void 0)},[h,p,i,s,o,T,l,a,u,d,g]}class Js extends ge{constructor(t){super(),he(this,t,Zs,qs,re,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Kt=new Map([["rectangle",{tool:_o}],["polygon",{tool:Js}]]),Wt=()=>[...Kt.keys()],Zt=e=>Kt.get(e),Eo=(e,t,n={})=>Kt.set(e,{tool:t,opts:n});function Qs(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("ellipse"),i=L("ellipse"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"cx",e[2]),c(n,"cy",e[3]),c(n,"rx",e[4]),c(n,"ry",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"cx",e[2]),c(i,"cy",e[3]),c(i,"rx",e[4]),c(i,"ry",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function xs(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{cx:l,cy:a,rx:u,ry:d}=s;return e.$$set=f=>{"annotation"in f&&n(0,i=f.annotation),"geom"in f&&n(6,s=f.geom),"style"in f&&n(7,r=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=He(i,r))},[i,o,l,a,u,d,s,r]}class $s extends ge{constructor(t){super(),he(this,t,xs,Qs,re,{annotation:0,geom:6,style:7})}}function er(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("line"),i=L("line"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"x1",e[2]),c(n,"y1",e[3]),c(n,"x2",e[4]),c(n,"y2",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"x1",e[2]),c(i,"y1",e[3]),c(i,"x2",e[4]),c(i,"y2",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function tr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s,[[a,u],[d,f]]=l;return e.$$set=h=>{"annotation"in h&&n(0,i=h.annotation),"geom"in h&&n(6,s=h.geom),"style"in h&&n(7,r=h.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=He(i,r))},[i,o,a,u,d,f,s,r]}class nr extends ge{constructor(t){super(),he(this,t,tr,er,re,{annotation:0,geom:6,style:7})}}function vo(e,t,n){const o=e.slice();return o[5]=t[n],o}function So(e){let t,n,o;return{c(){t=L("path"),o=L("path"),c(t,"class","a9s-outer"),c(t,"style",n=e[1]?"display:none;":void 0),c(t,"fill-rule","evenodd"),c(t,"d",Le(e[5])),c(o,"class","a9s-inner"),c(o,"style",e[1]),c(o,"fill-rule","evenodd"),c(o,"d",Le(e[5]))},m(i,s){N(i,t,s),N(i,o,s)},p(i,s){s&2&&n!==(n=i[1]?"display:none;":void 0)&&c(t,"style",n),s&2&&c(o,"style",i[1])},d(i){i&&(B(t),B(o))}}}function or(e){let t,n,o=ve(e[2]),i=[];for(let s=0;s<o.length;s+=1)i[s]=So(vo(e,o,s));return{c(){t=L("g");for(let s=0;s<i.length;s+=1)i[s].c();c(t,"class","a9s-annotation"),c(t,"data-id",n=e[0].id)},m(s,r){N(s,t,r);for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(t,null)},p(s,[r]){if(r&6){o=ve(s[2]);let l;for(l=0;l<o.length;l+=1){const a=vo(s,o,l);i[l]?i[l].p(a,r):(i[l]=So(a),i[l].c(),i[l].m(t,null))}for(;l<i.length;l+=1)i[l].d(1);i.length=o.length}r&1&&n!==(n=s[0].id)&&c(t,"data-id",n)},i:j,o:j,d(s){s&&B(t),Ye(i,s)}}}function ir(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{polygons:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=He(i,r))},[i,o,l,s,r]}class sr extends ge{constructor(t){super(),he(this,t,ir,or,re,{annotation:0,geom:3,style:4})}}function rr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("polygon"),i=L("polygon"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"points",e[2].map(lr).join(" ")),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"points",e[2].map(ar).join(" ")),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}const lr=e=>e.join(","),ar=e=>e.join(",");function cr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=He(i,r))},[i,o,l,s,r]}class ur extends ge{constructor(t){super(),he(this,t,cr,rr,re,{annotation:0,geom:3,style:4})}}function fr(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("path"),s=L("path"),c(n,"class",o=je(`a9s-outer ${e[1]}`)+" svelte-1w0132l"),c(n,"style",i=e[3]?"display:none;":void 0),c(n,"d",e[2]),c(s,"class",r=je(`a9s-inner ${e[1]}`)+" svelte-1w0132l"),c(s,"style",e[3]),c(s,"d",e[2]),c(t,"class","a9s-annotation"),c(t,"data-id",l=e[0].id)},m(a,u){N(a,t,u),z(t,n),z(t,s)},p(a,[u]){u&2&&o!==(o=je(`a9s-outer ${a[1]}`)+" svelte-1w0132l")&&c(n,"class",o),u&8&&i!==(i=a[3]?"display:none;":void 0)&&c(n,"style",i),u&4&&c(n,"d",a[2]),u&2&&r!==(r=je(`a9s-inner ${a[1]}`)+" svelte-1w0132l")&&c(s,"class",r),u&8&&c(s,"style",a[3]),u&4&&c(s,"d",a[2]),u&1&&l!==(l=a[0].id)&&c(t,"data-id",l)},i:j,o:j,d(a){a&&B(t)}}}function dr(e,t,n){let o,i,s,{annotation:r}=t,{geom:l}=t,{style:a}=t;return e.$$set=u=>{"annotation"in u&&n(0,r=u.annotation),"geom"in u&&n(4,l=u.geom),"style"in u&&n(5,a=u.style)},e.$$.update=()=>{e.$$.dirty&33&&n(3,o=He(r,a)),e.$$.dirty&16&&n(2,i=Ct(l)),e.$$.dirty&16&&n(1,s=l.closed?"closed":"open")},[r,s,i,o,l,a]}class hr extends ge{constructor(t){super(),he(this,t,dr,fr,re,{annotation:0,geom:4,style:5})}}function gr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("rect"),i=L("rect"),c(n,"class","a9s-outer"),c(n,"style",o=e[5]?"display:none;":void 0),c(n,"x",e[4]),c(n,"y",e[3]),c(n,"width",e[2]),c(n,"height",e[1]),c(i,"class","a9s-inner"),c(i,"style",e[5]),c(i,"x",e[4]),c(i,"y",e[3]),c(i,"width",e[2]),c(i,"height",e[1]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&32&&o!==(o=r[5]?"display:none;":void 0)&&c(n,"style",o),l&16&&c(n,"x",r[4]),l&8&&c(n,"y",r[3]),l&4&&c(n,"width",r[2]),l&2&&c(n,"height",r[1]),l&32&&c(i,"style",r[5]),l&16&&c(i,"x",r[4]),l&8&&c(i,"y",r[3]),l&4&&c(i,"width",r[2]),l&2&&c(i,"height",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function mr(e,t,n){let o,i,s,r,l,{annotation:a}=t,{geom:u}=t,{style:d}=t;return e.$$set=f=>{"annotation"in f&&n(0,a=f.annotation),"geom"in f&&n(6,u=f.geom),"style"in f&&n(7,d=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=He(a,d)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:l}=u,i,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,l),n(6,u)))},[a,l,r,s,i,o,u,d]}class pr extends ge{constructor(t){super(),he(this,t,mr,gr,re,{annotation:0,geom:6,style:7})}}const yr={elementToImage:(e,t)=>[e,t]},Ao=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),_r=250,ko=(e,t)=>{const n=Oe();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<_r){const{x:a,y:u}=Jt(r,e),d=Ie?10:2,f=t.getAt(a,u,void 0,d);f?n("click",{originalEvent:r,annotation:f}):n("click",{originalEvent:r})}}}},Jt=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=i+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function Mo(e,t,n){const o=e.slice();return o[39]=t[n],o}function To(e,t,n){const o=e.slice();return o[42]=t[n],o}function Qt(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Po(e){let t=e[42],n,o,i=Lo(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&131072&&re(t,t=s[42])?(be(),G(i,1,1,j),Ee(),i=Lo(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function wr(e){let t,n;return t=new nr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function br(e){let t,n;return t=new hr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Er(e){let t,n;return t=new sr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function vr(e){let t,n;return t=new ur({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Sr(e){let t,n;return t=new pr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ar(e){var o;let t,n;return t=new $s({props:{annotation:e[42],geom:(o=e[45])==null?void 0:o.geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){var l;const r={};s[0]&131072&&(r.annotation=i[42]),s[0]&131072&&(r.geom=(l=i[45])==null?void 0:l.geometry),s[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(R(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function Lo(e){let t,n,o,i;const s=[Ar,Sr,vr,Er,br,wr],r=[];function l(a,u){var d,f,h,g,m,p;return((d=a[45])==null?void 0:d.type)===Q.ELLIPSE?0:((f=a[45])==null?void 0:f.type)===Q.RECTANGLE?1:((h=a[45])==null?void 0:h.type)===Q.POLYGON?2:((g=a[45])==null?void 0:g.type)===Q.MULTIPOLYGON?3:((m=a[45])==null?void 0:m.type)===Q.POLYLINE?4:((p=a[45])==null?void 0:p.type)===Q.LINE?5:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),N(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),R(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(R(n),i=!0)},o(a){G(n),i=!1},d(a){a&&B(o),~t&&r[t].d(a)}}}function Io(e){let t=ot(e[42])&&!e[10](e[42]),n,o,i=t&&Po(Qt(e));return{c(){i&&i.c(),n=ke()},m(s,r){i&&i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&132096&&(t=ot(s[42])&&!s[10](s[42])),t?i?(i.p(Qt(s),r),r[0]&132096&&R(i,1)):(i=Po(Qt(s)),i.c(),R(i,1),i.m(n.parentNode,n)):i&&(be(),G(i,1,1,()=>{i=null}),Ee())},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i&&i.d(s)}}}function Co(e){let t,n,o,i;const s=[Mr,kr],r=[];function l(a,u){return a[6]?0:a[15]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),N(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),R(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(R(n),i=!0)},o(a){G(n),i=!1},d(a){a&&B(o),~t&&r[t].d(a)}}}function kr(e){let t=`${e[2]}-${e[7]}`,n,o,i=Oo(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&132&&re(t,t=`${s[2]}-${s[7]}`)?(be(),G(i,1,1,j),Ee(),i=Oo(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function Mr(e){let t,n,o=ve(e[6]),i=[];for(let r=0;r<o.length;r+=1)i[r]=Bo(Mo(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);N(r,t,l),n=!0},p(r,l){if(l[0]&8659266){o=ve(r[6]);let a;for(a=0;a<o.length;a+=1){const u=Mo(r,o,a);i[a]?(i[a].p(u,l),R(i[a],1)):(i[a]=Bo(u),i[a].c(),R(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)R(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&B(t),Ye(i,r)}}}function Oo(e){let t,n;return t=new po({props:{target:e[8],tool:e[15],drawingMode:e[14],transform:e[13],viewportScale:e[18]}}),t.$on("create",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&256&&(s.target=o[8]),i[0]&32768&&(s.tool=o[15]),i[0]&16384&&(s.drawingMode=o[14]),i[0]&8192&&(s.transform=o[13]),i[0]&262144&&(s.viewportScale=o[18]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Do(e){let t,n;return t=new mo({props:{target:e[8],editor:e[39].editor,annotation:e[39].annotation,style:e[1],transform:e[13],viewportScale:e[18]}}),t.$on("change",function(){ie(e[23](e[39].annotation))&&e[23](e[39].annotation).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&256&&(s.target=e[8]),i[0]&64&&(s.editor=e[39].editor),i[0]&64&&(s.annotation=e[39].annotation),i[0]&2&&(s.style=e[1]),i[0]&8192&&(s.transform=e[13]),i[0]&262144&&(s.viewportScale=e[18]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Bo(e){let t=e[39].annotation.id,n,o,i=Do(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&64&&re(t,t=s[39].annotation.id)?(be(),G(i,1,1,j),Ee(),i=Do(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function Tr(e){let t,n,o,i,s,r,l=ve(e[17].filter(e[34])),a=[];for(let f=0;f<l.length;f+=1)a[f]=Io(To(e,l,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&Co(e);return{c(){t=L("svg"),n=L("g");for(let f=0;f<a.length;f+=1)a[f].c();o=L("g"),d&&d.c(),c(o,"class","drawing"),c(t,"role","application"),c(t,"tabindex",0),c(t,"class","a9s-annotationlayer"),Pe(t,"drawing",e[15]),Pe(t,"editing",e[5]),Pe(t,"hidden",!e[3]),Pe(t,"hover",e[16])},m(f,h){N(f,t,h),z(t,n);for(let g=0;g<a.length;g+=1)a[g]&&a[g].m(n,null);z(t,o),d&&d.m(o,null),e[35](o),e[36](t),i=!0,s||(r=[J(t,"pointerup",function(){ie(e[11])&&e[11].apply(this,arguments)}),J(t,"pointerdown",function(){ie(e[12])&&e[12].apply(this,arguments)}),J(t,"pointermove",e[24])],s=!0)},p(f,h){if(e=f,h[0]&132098){l=ve(e[17].filter(e[34]));let g;for(g=0;g<l.length;g+=1){const m=To(e,l,g);a[g]?(a[g].p(m,h),R(a[g],1)):(a[g]=Io(m),a[g].c(),R(a[g],1),a[g].m(n,null))}for(be(),g=l.length;g<a.length;g+=1)u(g);Ee()}e[8]?d?(d.p(e,h),h[0]&256&&R(d,1)):(d=Co(e),d.c(),R(d,1),d.m(o,null)):d&&(be(),G(d,1,1,()=>{d=null}),Ee()),(!i||h[0]&32768)&&Pe(t,"drawing",e[15]),(!i||h[0]&32)&&Pe(t,"editing",e[5]),(!i||h[0]&8)&&Pe(t,"hidden",!e[3]),(!i||h[0]&65536)&&Pe(t,"hover",e[16])},i(f){if(!i){for(let h=0;h<l.length;h+=1)R(a[h]);R(d),i=!0}},o(f){a=a.filter(Boolean);for(let h=0;h<a.length;h+=1)G(a[h]);G(d),i=!1},d(f){f&&B(t),Ye(a,f),d&&d.d(),e[35](null),e[36](null),s=!1,Ae(r)}}}function Pr(e,t,n){let o,i,s,r,l,a,u,d,f,h,g,m,p=j,k=()=>(p(),p=an(E,X=>n(18,m=X)),E);e.$$.on_destroy.push(()=>p());let{drawingEnabled:b}=t,{image:S}=t,{preferredDrawingMode:w}=t,{state:A}=t,{style:T=void 0}=t,{toolName:C=Wt()[0]}=t,{user:M}=t,{visible:V=!0}=t,U=0;const W=()=>n(7,U+=1),q=()=>C,_=()=>b;let v,y,E;Re(()=>k(n(9,E=Gn(S,y))));const{hover:I,selection:P,store:D}=A;kt(e,I,X=>n(16,f=X)),kt(e,P,X=>n(33,h=X)),kt(e,D,X=>n(17,g=X));let F,H;const x=X=>{F&&D.unobserve(F);const de=X.filter(({editable:te})=>te).map(({id:te})=>te);de.length>0?(n(5,H=de.map(te=>D.getAnnotation(te)).filter(te=>te&&ot(te))),F=te=>{const{updated:ye}=te.changes;n(5,H=ye==null?void 0:ye.map(_e=>_e.newValue))},D.observe(F,{annotations:de})):n(5,H=void 0)},Z=X=>{const de=Bn(),te={id:de,bodies:[],target:{annotation:de,selector:X.detail,creator:M,created:new Date}};D.addAnnotation(te),P.setSelected(te.id)},$=X=>de=>{var Je;const{target:te}=X,ye=10*60*1e3,_e=((Je=te.creator)==null?void 0:Je.id)!==M.id||!te.created||new Date().getTime()-te.created.getTime()>ye;D.updateTarget({...te,selector:de.detail,created:_e?te.created:new Date,updated:_e?new Date:void 0,updatedBy:_e?M:void 0})},oe=X=>{const{x:de,y:te}=Jt(X,y),ye=D.getAt(de,te,void 0,2);ye?f!==ye.id&&I.set(ye.id):I.set(void 0)},se=X=>ot(X);function Se(X){ft[X?"unshift":"push"](()=>{v=X,n(8,v)})}function Te(X){ft[X?"unshift":"push"](()=>{y=X,n(4,y)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,b=X.drawingEnabled),"image"in X&&n(25,S=X.image),"preferredDrawingMode"in X&&n(26,w=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,T=X.style),"toolName"in X&&n(2,C=X.toolName),"user"in X&&n(28,M=X.user),"visible"in X&&n(3,V=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:o,opts:i}=Zt(C)||{tool:void 0,opts:void 0},o,(n(32,i),n(2,C))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(14,s=(i==null?void 0:i.drawingMode)||w),e.$$.dirty[0]&16&&n(13,r=Ao(y)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=ko(y,D),l,(n(11,a),n(4,y))),e.$$.dirty[1]&4&&x(h.selected),e.$$.dirty[0]&32&&n(6,u=H?H.map(X=>({annotation:X,editor:ho(X.target.selector)})).filter(X=>X.editor):void 0),e.$$.dirty[0]&64&&n(10,d=X=>u&&u.some(de=>de.annotation.id===X.id))},[b,T,C,V,y,H,u,U,v,E,d,a,l,r,s,o,f,g,m,I,P,D,Z,$,oe,S,w,A,M,W,q,_,i,h,se,Se,Te]}class No extends ge{constructor(t){super(),he(this,t,Pr,Tr,re,{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 Uo(e,t,n=0,o=e.length-1,i=Lr){for(;o>n;){if(o-n>600){const a=o-n+1,u=t-n+1,d=Math.log(a),f=.5*Math.exp(2*d/3),h=.5*Math.sqrt(d*f*(a-f)/a)*(u-a/2<0?-1:1),g=Math.max(n,Math.floor(t-u*f/a+h)),m=Math.min(o,Math.floor(t+(a-u)*f/a+h));Uo(e,t,g,m,i)}const s=e[t];let r=n,l=o;for(at(e,n,t),i(e[o],s)>0&&at(e,n,o);r<l;){for(at(e,r,l),r++,l--;i(e[r],s)<0;)r++;for(;i(e[l],s)>0;)l--}i(e[n],s)===0?at(e,n,l):(l++,at(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function at(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Lr(e,t){return e<t?-1:e>t?1:0}class Ir{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!bt(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?i(l):l;bt(t,a)&&(n.leaf?o.push(l):$t(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!bt(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(bt(t,r)){if(n.leaf||$t(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Ze([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let l,a,u;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],l=r.pop(),u=!0),o.leaf){const d=Cr(t,o.children,n);if(d!==-1)return o.children.splice(d,1),s.push(o),this._condense(s),this}!u&&!o.leaf&&$t(o,i)?(s.push(o),r.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],u=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,l;if(s<=r)return l=Ze(t.slice(n,o+1)),We(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=Ze([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));Yo(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);Yo(t,d,f,a,this.compareMinY);for(let h=d;h<=f;h+=a){const g=Math.min(h+a-1,f);l.children.push(this._build(t,h,g,i-1))}}return We(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const u=n.children[a],d=xt(u),f=Br(t,u)-d;f<r?(r=f,s=d<s?d:s,l=u):f===r&&d<s&&(s=d,l=u)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),ut(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),l=Ze(o.children.splice(r,o.children.length-r));l.height=o.height,l.leaf=o.leaf,We(o,this.toBBox),We(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=Ze([t,n]),this.data.height=t.height+1,this.data.leaf=!1,We(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let l=n;l<=o-n;l++){const a=ct(t,0,l,this.toBBox),u=ct(t,l,o,this.toBBox),d=Nr(a,u),f=xt(a)+xt(u);d<s?(s=d,i=l,r=f<r?f:r):d===s&&f<r&&(r=f,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Or,s=t.leaf?this.compareMinY:Dr,r=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,s);r<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=ct(t,0,n,s),l=ct(t,o-n,o,s);let a=wt(r)+wt(l);for(let u=n;u<o-n;u++){const d=t.children[u];ut(r,t.leaf?s(d):d),a+=wt(r)}for(let u=o-n-1;u>=n;u--){const d=t.children[u];ut(l,t.leaf?s(d):d),a+=wt(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)ut(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():We(t[n],this.toBBox)}}function Cr(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function We(e,t){ct(e,0,e.children.length,t,e)}function ct(e,t,n,o,i){i||(i=Ze(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];ut(i,e.leaf?o(r):r)}return i}function ut(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Or(e,t){return e.minX-t.minX}function Dr(e,t){return e.minY-t.minY}function xt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function wt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Br(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Nr(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function $t(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function bt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ze(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Yo(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;Uo(e,r,t,n,i),s.push(t,r,r,n)}}const Ur=()=>{const e=new Ir,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!it(f))return;const{minX:h,minY:g,maxX:m,maxY:p}=f.selector.geometry.bounds,k={minX:h,minY:g,maxX:m,maxY:p,target:f};e.insert(k),t.set(f.annotation,k)},s=f=>{if(!it(f))return;const h=t.get(f.annotation);h&&e.remove(h),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,h,g=0)=>{const p=e.search({minX:f-g,minY:h-g,maxX:f+g,maxY:h+g}).map(k=>k.target).filter(k=>k.selector.type===Q.RECTANGLE||wn(k.selector,f,h,g));return p.length>0?(p.sort((k,b)=>ht(k.selector)-ht(b.selector)),p):[]},getIntersecting:(f,h,g,m)=>e.search({minX:f,minY:h,maxX:f+g,maxY:h+m}).map(p=>p.target),insert:i,remove:s,set:(f,h=!0)=>{h&&o();const g=f.reduce((m,p)=>{if(it(p)){const{minX:k,minY:b,maxX:S,maxY:w}=p.selector.geometry.bounds;return[...m,{minX:k,minY:b,maxX:S,maxY:w,target:p}]}else return m},[]);g.forEach(m=>t.set(m.target.annotation,m)),e.load(g)},size:()=>e.all().length,update:(f,h)=>{s(f),i(h)}}},Ro=e=>({...e,subscribe:n=>{const o=i=>n(i.state);return e.observe(o),n(e.all()),()=>e.unobserve(o)}}),Vo=e=>{const t=Fi(),n=Ur(),o=Li(t,e.userSelectAction,e.adapter),i=Pi(t),s=Wi();return t.observe(({changes:a})=>{n.set((a.created||[]).map(u=>u.target),!1),(a.deleted||[]).forEach(u=>n.remove(u.target)),(a.updated||[]).forEach(({oldValue:u,newValue:d})=>n.update(u.target,d.target))}),{store:{...t,getAt:(a,u,d,f)=>{const h=n.getAt(a,u,f);if(d)return h.map(m=>t.getAnnotation(m.annotation)).filter(Boolean).filter(d)[0];{const g=h[0];return g?t.getAnnotation(g.annotation):void 0}},getIntersecting:(a,u,d,f)=>n.getIntersecting(a,u,d,f).map(h=>t.getAnnotation(h.annotation)).filter(Boolean)},selection:o,hover:i,viewport:s}},Xo=e=>{const t=Vo(e);return{...t,store:Ro(t.store)}},Ho=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(r,l,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=u}return o/81},Go=e=>{const t=Ho(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},en=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Go(e):n),jo=(e,t)=>({...e,drawingEnabled:e.drawingEnabled===void 0?t.drawingEnabled:e.drawingEnabled,drawingMode:e.drawingMode||t.drawingMode,userSelectAction:e.userSelectAction||t.userSelectAction,theme:e.theme||t.theme}),tn=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Fo=(e,t)=>{const n=t||document,o=r=>{const l=r;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},i=r=>{const l=r;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},s=()=>{tn?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return tn?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Yr=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=jo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Bt.EDIT,theme:"light"}),i=Xo(o),{selection:s,store:r}=i,l=Ki(r,o.initialHistory),a=Zi(i,l,o.adapter,o.autoSave),u=document.createElement("DIV");u.style.position="relative",u.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(u,n),u.appendChild(n);const d=Fo(l);let f=ss();en(n,u,o.theme);const h=new No({target:u,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});h.$on("click",_=>{const{originalEvent:v,annotation:y}=_.detail;y?s.userSelect(y.id,v):s.isEmpty()||s.clear()});const g=Qi(i,l,o.adapter),m=()=>h.cancelDrawing(),p=()=>{h.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),l.destroy()},k=()=>h.getDrawingTool(),b=()=>f,S=()=>h.isDrawingEnabled(),w=(_,v,y)=>Eo(_,v,y),A=(_,v)=>go(_,v),T=_=>{if(!Zt(_))throw`No drawing tool named ${_}`;h.$set({toolName:_})},C=_=>h.$set({drawingEnabled:_}),M=_=>{console.warn("Filter not implemented yet")},V=_=>h.$set({style:_}),U=_=>en(n,u,_),W=_=>{f=_,h.$set({user:_})},q=_=>h.$set({visible:_});return{...g,cancelDrawing:m,destroy:p,getDrawingTool:k,getUser:b,isDrawingEnabled:S,listDrawingTools:Wt,on:a.on,off:a.off,registerDrawingTool:w,registerShapeEditor:A,setDrawingEnabled:C,setDrawingTool:T,setFilter:M,setStyle:V,setTheme:U,setUser:W,setVisible:q,element:u,state:i}};O.Editor=_t,O.EditorMount=mo,O.Handle=Ge,O.IdentityTransform=yr,O.MidpointHandle=Rt,O.PolygonEditor=$n,O.RectangleEditor=eo,O.RectangleUtil=An,O.RubberbandRectangle=_o,O.SVGAnnotationLayer=No,O.ShapeType=Q,O.ToolMount=po,O.UserSelectAction=Bt,O.W3CImageFormat=fs,O.addEventListeners=ko,O.approximateAsPolygon=gt,O.boundsFromMultiPolygonElements=nt,O.boundsFromPoints=fe,O.chainStyles=$i,O.computeArea=ht,O.computePolygonArea=$e,O.computeSVGPath=Ct,O.computeStyle=xi,O.createBody=Ui,O.createImageAnnotator=Yr,O.createImageAnnotatorState=Vo,O.createSVGTransform=Ao,O.createSvelteImageAnnotatorState=Xo,O.defaultColorProvider=us,O.detectTheme=Go,O.distance=tt,O.enableResponsive=Gn,O.fillDefaults=jo,O.getAllCorners=En,O.getEditor=ho,O.getMaskDimensions=st,O.getSVGPoint=Jt,O.getTool=Zt,O.initKeyboardCommands=Fo,O.intersects=wn,O.isFragmentSelector=kn,O.isImageAnnotation=ot,O.isImageAnnotationTarget=it,O.isMac=tn,O.isPointInPolygon=et,O.isTouch=Ie,O.listDrawingTools=Wt,O.multipolygonElementToPath=Le,O.parseFragmentSelector=Mn,O.parseSVGSelector=Cn,O.parseW3CImageAnnotation=Xn,O.pointsToPath=bn,O.registerEditor=go,O.registerShapeUtil=Xe,O.registerTool=Eo,O.sampleBrightness=Ho,O.serializeFragmentSelector=Tn,O.serializeSVGSelector=On,O.serializeW3CImageAnnotation=Hn,O.setTheme=en,O.simplifyMultiPolygon=ci,O.simplifyPoints=It,O.simplifyPolygon=fi,O.toSvelteStore=Ro,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
1
+ (function(O,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(O=typeof globalThis<"u"?globalThis:O||self,j(O.Annotorious={}))})(this,function(O){"use strict";var Rr=Object.defineProperty;var Vr=(O,j,Ce)=>j in O?Rr(O,j,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):O[j]=Ce;var sn=(O,j,Ce)=>Vr(O,typeof j!="symbol"?j+"":j,Ce);function j(){}function Ce(e,t){for(const n in t)e[n]=t[n];return e}function rn(e){return e()}function ln(){return Object.create(null)}function Ae(e){e.forEach(rn)}function ie(e){return typeof e=="function"}function re(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function qo(e){return Object.keys(e).length===0}function an(e,...t){if(e==null){for(const o of t)o(void 0);return j}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function kt(e,t,n){e.$$.on_destroy.push(an(t,n))}function Ko(e,t,n,o){if(e){const i=cn(e,t,n,o);return e[0](i)}}function cn(e,t,n,o){return e[1]&&o?Ce(n.ctx.slice(),e[1](o(t))):n.ctx}function Wo(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let l=0;l<r;l+=1)s[l]=t.dirty[l]|i[l];return s}return t.dirty|i}return t.dirty}function Zo(e,t,n,o,i,s){if(i){const r=cn(t,n,o,s);e.p(r,i)}}function Jo(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function un(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function je(e){return e??""}function z(e,t){e.appendChild(t)}function N(e,t,n){e.insertBefore(t,n||null)}function B(e){e.parentNode&&e.parentNode.removeChild(e)}function Ye(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function L(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function fn(e){return document.createTextNode(e)}function we(){return fn(" ")}function ke(){return fn("")}function J(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function c(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Qo(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function xo(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Qe;function xe(e){Qe=e}function dn(){if(!Qe)throw new Error("Function called outside component initialization");return Qe}function Re(e){dn().$$.on_mount.push(e)}function Oe(){const e=dn();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=xo(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function ue(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const Fe=[],ft=[];let ze=[];const hn=[],gn=Promise.resolve();let Mt=!1;function mn(){Mt||(Mt=!0,gn.then(yn))}function pn(){return mn(),gn}function Tt(e){ze.push(e)}const Pt=new Set;let qe=0;function yn(){if(qe!==0)return;const e=Qe;do{try{for(;qe<Fe.length;){const t=Fe[qe];qe++,xe(t),$o(t.$$)}}catch(t){throw Fe.length=0,qe=0,t}for(xe(null),Fe.length=0,qe=0;ft.length;)ft.pop()();for(let t=0;t<ze.length;t+=1){const n=ze[t];Pt.has(n)||(Pt.add(n),n())}ze.length=0}while(Fe.length);for(;hn.length;)hn.pop()();Mt=!1,Pt.clear(),xe(e)}function $o(e){if(e.fragment!==null){e.update(),Ae(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Tt)}}function ei(e){const t=[],n=[];ze.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),ze=t}const dt=new Set;let Ve;function be(){Ve={r:0,c:[],p:Ve}}function Ee(){Ve.r||Ae(Ve.c),Ve=Ve.p}function R(e,t){e&&e.i&&(dt.delete(e),e.i(t))}function G(e,t,n,o){if(e&&e.o){if(dt.has(e))return;dt.add(e),Ve.c.push(()=>{dt.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ve(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ce(e){e&&e.c()}function le(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),Tt(()=>{const s=e.$$.on_mount.map(rn).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ae(s),e.$$.on_mount=[]}),i.forEach(Tt)}function ae(e,t){const n=e.$$;n.fragment!==null&&(ei(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function ti(e,t){e.$$.dirty[0]===-1&&(Fe.push(e),mn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function he(e,t,n,o,i,s,r=null,l=[-1]){const a=Qe;xe(e);const u=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:i,bound:ln(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:ln(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(u.root);let d=!1;if(u.ctx=n?n(e,t.props||{},(f,h,...g)=>{const m=g.length?g[0]:h;return u.ctx&&i(u.ctx[f],u.ctx[f]=m)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](m),d&&ti(e,f)),h}):[],u.update(),d=!0,Ae(u.before_update),u.fragment=o?o(u.ctx):!1,t.target){if(t.hydrate){const f=Qo(t.target);u.fragment&&u.fragment.l(f),f.forEach(B)}else u.fragment&&u.fragment.c();t.intro&&R(e.$$.fragment),le(e,t.target,t.anchor),yn()}xe(a)}class ge{constructor(){sn(this,"$$");sn(this,"$$set")}$destroy(){ae(this,1),this.$destroy=j}$on(t,n){if(!ie(n))return j;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!qo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ni="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ni);var Q=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(Q||{});function oi(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _n={exports:{}};(function(e){(function(){function t(l,a){var u=l.x-a.x,d=l.y-a.y;return u*u+d*d}function n(l,a,u){var d=a.x,f=a.y,h=u.x-d,g=u.y-f;if(h!==0||g!==0){var m=((l.x-d)*h+(l.y-f)*g)/(h*h+g*g);m>1?(d=u.x,f=u.y):m>0&&(d+=h*m,f+=g*m)}return h=l.x-d,g=l.y-f,h*h+g*g}function o(l,a){for(var u=l[0],d=[u],f,h=1,g=l.length;h<g;h++)f=l[h],t(f,u)>a&&(d.push(f),u=f);return u!==f&&d.push(f),d}function i(l,a,u,d,f){for(var h=d,g,m=a+1;m<u;m++){var p=n(l[m],l[a],l[u]);p>h&&(g=m,h=p)}h>d&&(g-a>1&&i(l,a,g,d,f),f.push(l[g]),u-g>1&&i(l,g,u,d,f))}function s(l,a){var u=l.length-1,d=[l[0]];return i(l,0,u,a,d),d.push(l[u]),d}function r(l,a,u){if(l.length<=2)return l;var d=a!==void 0?a*a:1;return l=u?l:o(l,d),l=s(l,d),l}e.exports=r,e.exports.default=r})()})(_n);var ii=_n.exports;const si=oi(ii),Lt={},Xe=(e,t)=>Lt[e]=t,ht=e=>Lt[e.type].area(e),wn=(e,t,n,o)=>Lt[e.type].intersects(e,t,n,o),fe=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},$e=e=>{let t=0,n=e.length-1;for(let o=0;o<e.length;o++)t+=(e[n][0]+e[o][0])*(e[n][1]-e[o][1]),n=o;return Math.abs(.5*t)},et=(e,t,n)=>{let o=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const r=e[i][0],l=e[i][1],a=e[s][0],u=e[s][1];l>n!=u>n&&t<(a-r)*(n-l)/(u-l)+r&&(o=!o)}return o},bn=(e,t=!0)=>{let n="M ";return e.forEach(([o,i],s)=>{s===0?n+=`${o},${i}`:n+=` L ${o},${i}`}),t&&(n+=" Z"),n},It=(e,t=1)=>{const n=e.map(([o,i])=>({x:o,y:i}));return si(n,t,!0).map(o=>[o.x,o.y])},tt=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},ri={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,l=0,a=Math.cos(l),u=Math.sin(l),d=t-o,f=n-i,h=a*d+u*f,g=u*d-a*f;return h*h/(s*s)+g*g/(r*r)<=1}};Xe(Q.ELLIPSE,ri);const li={area:e=>0,intersects:(e,t,n,o=2)=>{const[[i,s],[r,l]]=e.geometry.points,a=Math.abs((l-s)*t-(r-i)*n+r*s-l*i),u=tt([i,s],[r,l]);return a/u<=o}};Xe(Q.LINE,li);const ai={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,o)=>{const[i,...s]=o.rings,r=$e(i.points),l=s.reduce((a,u)=>a+$e(u.points),0);return n+r-l},0)},intersects:(e,t,n)=>{const{polygons:o}=e.geometry;for(const i of o){const[s,...r]=i.rings;if(et(s.points,t,n)){let l=!1;for(const a of r)if(et(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},nt=e=>{const t=e.reduce((n,o)=>[...n,...o.rings[0].points],[]);return fe(t)},Le=e=>e.rings.map(n=>bn(n.points)).join(" "),En=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((o,i)=>[...o,...i.points],[])],[]),ci=(e,t=1)=>{const n=e.geometry.polygons.map(i=>{const s=i.rings.map(l=>{const a=It(l.points,t);return{...l,points:a}}),r=fe(s[0].points);return{...i,rings:s,bounds:r}}),o=nt(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:o}}};Xe(Q.MULTIPOLYGON,ai);const ui={area:e=>{const t=e.geometry.points;return $e(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return et(o,t,n)}},fi=(e,t=1)=>{const n=It(e.geometry.points,t),o=fe(n);return{...e,geometry:{...e.geometry,bounds:o,points:n}}};Xe(Q.POLYGON,ui);const di={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=gt(t.points,t.closed);return $e(n)},intersects:(e,t,n,o=2)=>{const i=e.geometry;if(i.closed){const s=gt(i.points,i.closed);return et(s,t,n)}else return hi(i,[t,n],o)}},gt=(e,t=!1)=>{const n=[];for(let o=0;o<e.length;o++){const i=e[o],s=e[(o+1)%e.length];if(n.push(i.point),(o<e.length-1||t)&&(i.type==="CURVE"||s.type=="CURVE")){const l=vn(i.point,i.type==="CURVE"&&i.outHandle||i.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);n.push(...l.slice(1))}}return n},vn=(e,t,n,o,i=10)=>{const s=[];for(let r=0;r<=i;r++){const l=r/i,a=Math.pow(1-l,3)*e[0]+3*Math.pow(1-l,2)*l*t[0]+3*(1-l)*Math.pow(l,2)*n[0]+Math.pow(l,3)*o[0],u=Math.pow(1-l,3)*e[1]+3*Math.pow(1-l,2)*l*t[1]+3*(1-l)*Math.pow(l,2)*n[1]+Math.pow(l,3)*o[1];s.push([a,u])}return s},hi=(e,t,n)=>{for(let o=0;o<e.points.length-1;o++){const i=e.points[o],s=e.points[o+1];if(i.type==="CURVE"||s.type==="CURVE"){const l=vn(i.point,i.type==="CURVE"&&i.outHandle||i.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let a=0;a<l.length-1;a++)if(Sn(t,l[a],l[a+1])<=n)return!0}else if(Sn(t,i.point,s.point)<=n)return!0}return!1},Sn=(e,t,n)=>{const[o,i]=e,[s,r]=t,[l,a]=n,u=l-s,d=a-r,f=Math.sqrt(u*u+d*d);if(f===0)return Math.sqrt((o-s)*(o-s)+(i-r)*(i-r));const h=((o-s)*u+(i-r)*d)/(f*f);return h<=0?Math.sqrt((o-s)*(o-s)+(i-r)*(i-r)):h>=1?Math.sqrt((o-l)*(o-l)+(i-a)*(i-a)):Math.abs((a-r)*o-(l-s)*i+l*r-a*s)/f},Ct=e=>{if(!e.points||e.points.length===0)return"";const t=[],n=e.points[0];t.push(`M ${n.point[0]} ${n.point[1]}`);for(let o=1;o<e.points.length;o++){const i=e.points[o],s=e.points[o-1];if(i.type==="CURVE"||s.type==="CURVE"){const r=s.type==="CURVE"&&s.outHandle||s.point,l=i.type==="CURVE"&&i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}else t.push(`L ${i.point[0]} ${i.point[1]}`)}if(e.closed){const o=e.points[e.points.length-1],i=e.points[0];if(o.type==="CURVE"||i.type==="CURVE"){const r=o.outHandle||o.point,l=i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Xe(Q.POLYLINE,di);const An={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};Xe(Q.RECTANGLE,An);const ot=e=>it(e.target),it=e=>{var t,n;return(e==null?void 0:e.annotation)!==void 0&&((n=(t=e==null?void 0:e.selector)==null?void 0:t.geometry)==null?void 0:n.bounds)!==void 0},kn=e=>(e==null?void 0:e.type)==="FragmentSelector"?!0:typeof e=="string"?e.indexOf("#")<0?!1:/^#xywh(?:=(?:pixel:|percent:)?)\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?$/i.test(e):!1,Mn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0];if(!i)throw new Error("Not a MediaFragment: "+n);const[s,r,l,a,u,d,f]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[h,g,m,p]=[a,u,d,f].map(parseFloat);return{type:Q.RECTANGLE,geometry:{x:h,y:g,w:m,h:p,bounds:{minX:h,minY:t?g-p:g,maxX:h+m,maxY:t?g:g+p}}}},Tn=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},Pn="http://www.w3.org/2000/svg",Ln=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},gi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Pn}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},mt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Pn),i=n.lookupNamespaceURI(null);return o||i?Ln(n).firstChild:Ln(gi(n)).firstChild},mi=e=>{const t=In(e),n=[];let o=[],i=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":o.length>0&&(n.push({points:o}),o=[]),i=[s.args[0],s.args[1]],o.push([...i]);break;case"L":i=[s.args[0],s.args[1]],o.push([...i]);break;case"H":i=[s.args[0],i[1]],o.push([...i]);break;case"V":i=[i[0],s.args[0]],o.push([...i]);break;case"C":i=[s.args[4],s.args[5]],o.push([...i]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(o.length>2&&n.push({points:o}),n.length>0){const s=fe(n[0].points);return{rings:n,bounds:s}}},pi=e=>{const{point:t,inHandle:n,outHandle:o}=e;if(!n||!o)return!1;const i=n[0]-t[0],s=n[1]-t[1],r=o[0]-t[0],l=o[1]-t[1],a=i*l-s*r;return Math.abs(a)<.01},yi=e=>{const t=In(e);let n=[],o=[0,0],i=!1;for(let r=0;r<t.length;r++){const l=t[r];switch(l.type.toUpperCase()){case"M":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"L":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"C":const a=[l.args[0],l.args[1]],u=[l.args[2],l.args[3]],d=[l.args[4],l.args[5]];if(n.length>0){const h=n[n.length-1];(a[0]!==h.point[0]||a[1]!==h.point[1])&&(h.type="CURVE",h.outHandle=a)}const f={type:u[0]!==d[0]||u[1]!==d[1]?"CURVE":"CORNER",point:d};f.type==="CURVE"&&(f.inHandle=u),n.push(f),o=d;break;case"Z":i=!0;break;default:console.warn(`Unsupported SVG path command: ${l.type}`);break}}n=n.map(r=>pi(r)?{...r,locked:!0}:r);const s=fe(gt(n,i));return{points:n,closed:i,bounds:s}},In=e=>{const t=[],n=e.replace(/,/g," ").trim(),o=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let i;for(;(i=o.exec(n))!==null;){const[,s,r]=i,l=r.trim()===""?[]:r.trim().split(/\s+/).map(Number).filter(a=>!isNaN(a));t.push({type:s,args:l})}return t},_i=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:Q.POLYGON,geometry:{points:i,bounds:fe(i)}}},wi=e=>{const t=mt(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:Q.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},bi=e=>{const t=mt(e),n=parseFloat(t.getAttribute("x1")),o=parseFloat(t.getAttribute("x2")),i=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),r={minX:Math.min(n,o),minY:Math.min(i,s),maxX:Math.max(n,o),maxY:Math.max(i,s)};return{type:Q.LINE,geometry:{points:[[n,i],[o,s]],bounds:r}}},Ei=e=>{const t=mt(e),n=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],o=n==null?void 0:n.getAttribute("d");if(!o)throw new Error("Could not parse SVG path");const i=yi(o);if(!i)throw new Error("Could not parse SVG path");return{type:Q.POLYLINE,geometry:i}},vi=e=>{const t=mt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>mi(a)).filter(Boolean),s=i.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=fe(s);return i.length===1&&i[0].rings.length===1?{type:Q.POLYGON,geometry:{points:s,bounds:r}}:{type:Q.MULTIPOLYGON,geometry:{polygons:i,bounds:r}}},Cn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return _i(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return Ei(t);if(t.includes("<path "))return vi(t);if(t.includes("<ellipse "))return wi(t);if(t.includes("<line "))return bi(t);throw"Unsupported SVG shape: "+t},Si=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Le(n)}" />`).join("")}</g>`,On=e=>{let t;switch(e.type){case Q.POLYGON:{const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`;break}case Q.ELLIPSE:{const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;break}case Q.MULTIPOLYGON:{const n=e.geometry;t=`<svg>${Si(n)}</svg>`;break}case Q.LINE:{const n=e.geometry,[[o,i],[s,r]]=n.points;t=`<svg><line x1="${o}" y1="${i}" x2="${s}" y2="${r}" /></svg>`;break}case Q.POLYLINE:t=`<svg><path d="${Ct(e.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},me=[];for(let e=0;e<256;++e)me.push((e+256).toString(16).slice(1));function Ai(e,t=0){return(me[e[t+0]]+me[e[t+1]]+me[e[t+2]]+me[e[t+3]]+"-"+me[e[t+4]]+me[e[t+5]]+"-"+me[e[t+6]]+me[e[t+7]]+"-"+me[e[t+8]]+me[e[t+9]]+"-"+me[e[t+10]]+me[e[t+11]]+me[e[t+12]]+me[e[t+13]]+me[e[t+14]]+me[e[t+15]]).toLowerCase()}let Ot;const ki=new Uint8Array(16);function Mi(){if(!Ot){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ot=crypto.getRandomValues.bind(crypto)}return Ot(ki)}const Dn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ti(e,t,n){var i;e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Mi();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Ai(o)}function Bn(e,t,n){return Dn.randomUUID&&!e?Dn.randomUUID():Ti(e)}var Nn=Object.prototype.hasOwnProperty;function De(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&De(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Nn.call(e,n)&&++o&&!Nn.call(t,n)||!(n in t)||!De(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}let Me=[],Be=0;const pt=4;let Dt=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},lc:0,listen(o){return n.lc=t.push(o),()=>{for(let s=Be+pt;s<Me.length;)Me[s]===o?Me.splice(s,pt):s+=pt;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){let s=!Me.length;for(let r of t)Me.push(r,n.value,o,i);if(s){for(Be=0;Be<Me.length;Be+=pt)Me[Be](Me[Be+1],Me[Be+2],Me[Be+3]);Me.length=0}},off(){},set(o){let i=n.value;i!==o&&(n.value=o,n.notify(i))},subscribe(o){let i=n.listen(o);return o(n.value),i},value:e};return n};const Pi=e=>{const t=Dt(null);return e.observe(({changes:n})=>{const o=t.get();if(o){(n.deleted||[]).some(s=>s.id===o)&&t.set(null);const i=(n.updated||[]).find(({oldValue:s})=>s.id===o);i&&t.set(i.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var Bt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Bt||{});const Nt={selected:[]},Li=(e,t,n)=>{const o=Dt(Nt);let i=t;const s=()=>{De(o.get(),Nt)||o.set(Nt)},r=()=>{var g;return((g=o.get().selected)==null?void 0:g.length)===0},l=g=>{if(r())return!1;const m=typeof g=="string"?g:g.id;return o.get().selected.some(p=>p.id===m)},a=(g,m)=>{let p;if(Array.isArray(g)){if(p=g.map(E=>e.getAnnotation(E)).filter(Boolean),p.length<g.length){console.warn("Invalid selection: "+g.filter(E=>!p.some(S=>S.id===E)));return}}else{const E=e.getAnnotation(g);if(!E){console.warn("Invalid selection: "+g);return}p=[E]}const k=p.reduce((E,S)=>{const w=h(S);return w==="EDIT"?[...E,{id:S.id,editable:!0}]:w==="SELECT"?[...E,{id:S.id}]:E},[]);o.set({selected:k,event:m})},u=(g,m)=>{const p=Array.isArray(g)?g:[g],k=p.map(E=>e.getAnnotation(E)).filter(E=>!!E);o.set({selected:k.map(E=>{const S=m===void 0?h(E)==="EDIT":m;return{id:E.id,editable:S}})}),k.length!==p.length&&console.warn("Invalid selection",g)},d=g=>{if(r())return!1;const{selected:m}=o.get();m.some(({id:p})=>g.includes(p))&&o.set({selected:m.filter(({id:p})=>!g.includes(p))})},f=g=>{i=g,u(o.get().selected.map(({id:m})=>m))},h=g=>Ii(g,i,n);return e.observe(({changes:g})=>d((g.deleted||[]).map(m=>m.id))),{get event(){const g=o.get();return g?g.event:null},get selected(){const g=o.get();return g?[...g.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:h,isEmpty:r,isSelected:l,setSelected:u,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:a}},Ii=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},pe=[];for(let e=0;e<256;++e)pe.push((e+256).toString(16).slice(1));function Ci(e,t=0){return(pe[e[t+0]]+pe[e[t+1]]+pe[e[t+2]]+pe[e[t+3]]+"-"+pe[e[t+4]]+pe[e[t+5]]+"-"+pe[e[t+6]]+pe[e[t+7]]+"-"+pe[e[t+8]]+pe[e[t+9]]+"-"+pe[e[t+10]]+pe[e[t+11]]+pe[e[t+12]]+pe[e[t+13]]+pe[e[t+14]]+pe[e[t+15]]).toLowerCase()}let Ut;const Oi=new Uint8Array(16);function Di(){if(!Ut){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ut=crypto.getRandomValues.bind(crypto)}return Ut(Oi)}const Bi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Un={randomUUID:Bi};function Ni(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Di();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,Ci(i)}function Yn(e,t,n){return Un.randomUUID&&!e?Un.randomUUID():Ni(e)}const Yt=e=>{const t=n=>{const o={...n};return n.created&&typeof n.created=="string"&&(o.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(o.updated=new Date(n.updated)),o};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Ui=(e,t,n,o)=>({id:Yn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Yi=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Ri=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Vi=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!De(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Xi=(e,t)=>!De(e.target,t.target),Rn=(e,t)=>{const n=Yi(e,t),o=Ri(e,t),i=Vi(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Xi(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var ne=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(ne||{});const Hi=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,l=a=>a&&a.length>0;if(!(l(i.created)||l(i.deleted))){const a=(n=i.updated)==null?void 0:n.some(d=>l(d.bodiesCreated)||l(d.bodiesDeleted)||l(d.bodiesUpdated)),u=(o=i.updated)==null?void 0:o.some(d=>d.targetUpdated);if(r==="BODY_ONLY"&&a&&!u||r==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const r=new Set([...(i.created||[]).map(l=>l.id),...(i.deleted||[]).map(l=>l.id),...(i.updated||[]).map(({oldValue:l})=>l.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(l=>r.has(l))}else return!0},Gi=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),l=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),a=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:h})=>h.id===f.id).newValue:f),...t.created||[]],u=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],d=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:h,newValue:g}=f;if(r.has(g.id)){const m=t.updated.find(p=>p.oldValue.id===g.id).newValue;return Rn(h,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:u,updated:d}},yt=e=>{const t=e.id===void 0?Yn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},ji=e=>e.id!==void 0,Fi=()=>{const e=new Map,t=new Map,n=[],o=(v,b={})=>{n.push({onChange:v,options:b})},i=v=>{const b=n.findIndex(y=>y.onChange==v);b>-1&&n.splice(b,1)},s=(v,b)=>{const y={origin:v,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(_=>{Hi(_,y)&&_.onChange(y)})},r=(v,b=ne.LOCAL)=>{if(v.id&&e.get(v.id))throw Error(`Cannot add annotation ${v.id} - exists already`);{const y=yt(v);e.set(y.id,y),y.bodies.forEach(_=>t.set(_.id,y.id)),s(b,{created:[y]})}},l=(v,b)=>{const y=yt(typeof v=="string"?b:v),_=typeof v=="string"?v:v.id,I=_&&e.get(_);if(I){const P=Rn(I,y);return _===y.id?e.set(_,y):(e.delete(_),e.set(y.id,y)),I.bodies.forEach(D=>t.delete(D.id)),y.bodies.forEach(D=>t.set(D.id,y.id)),P}else console.warn(`Cannot update annotation ${_} - does not exist`)},a=(v,b=ne.LOCAL,y=ne.LOCAL)=>{const _=ji(b)?y:b,I=l(v,b);I&&s(_,{updated:[I]})},u=(v,b=ne.LOCAL)=>{e.get(v.id)?a(v,b):r(v,b)},d=(v,b=ne.LOCAL)=>{const y=v.reduce((_,I)=>{const P=l(I);return P?[..._,P]:_},[]);y.length>0&&s(b,{updated:y})},f=(v,b=ne.LOCAL)=>{const y=v.map(yt),{toAdd:_,toUpdate:I}=y.reduce((D,F)=>e.get(F.id)?{...D,toUpdate:[...D.toUpdate,F]}:{...D,toAdd:[...D.toAdd,F]},{toAdd:[],toUpdate:[]}),P=I.map(D=>l(D,b)).filter(Boolean);_.forEach(D=>{e.set(D.id,D),D.bodies.forEach(F=>t.set(F.id,D.id))}),s(b,{created:_,updated:P})},h=(v,b=ne.LOCAL)=>{const y=e.get(v.annotation);if(y){const _={...y,bodies:[...y.bodies,v]};e.set(y.id,_),t.set(v.id,_.id),s(b,{updated:[{oldValue:y,newValue:_,bodiesCreated:[v]}]})}else console.warn(`Attempt to add body to missing annotation: ${v.annotation}`)},g=()=>[...e.values()],m=(v=ne.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(v,{deleted:b})},p=(v,b=!0,y=ne.LOCAL)=>{const _=v.map(yt);if(b){const I=[...e.values()];e.clear(),t.clear(),_.forEach(P=>{e.set(P.id,P),P.bodies.forEach(D=>t.set(D.id,P.id))}),s(y,{created:_,deleted:I})}else{const I=v.reduce((P,D)=>{const F=D.id&&e.get(D.id);return F?[...P,F]:P},[]);if(I.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${I.map(P=>P.id).join(", ")}`);_.forEach(P=>{e.set(P.id,P),P.bodies.forEach(D=>t.set(D.id,P.id))}),s(y,{created:_})}},k=v=>{const b=typeof v=="string"?v:v.id,y=e.get(b);if(y)return e.delete(b),y.bodies.forEach(_=>t.delete(_.id)),y;console.warn(`Attempt to delete missing annotation: ${b}`)},E=(v,b=ne.LOCAL)=>{const y=k(v);y&&s(b,{deleted:[y]})},S=(v,b=ne.LOCAL)=>{const y=v.reduce((_,I)=>{const P=k(I);return P?[..._,P]:_},[]);y.length>0&&s(b,{deleted:y})},w=v=>{const b=e.get(v.annotation);if(b){const y=b.bodies.find(_=>_.id===v.id);if(y){t.delete(y.id);const _={...b,bodies:b.bodies.filter(I=>I.id!==v.id)};return e.set(b.id,_),{oldValue:b,newValue:_,bodiesDeleted:[y]}}else console.warn(`Attempt to delete missing body ${v.id} from annotation ${v.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${v.annotation}`)},A=(v,b=ne.LOCAL)=>{const y=w(v);y&&s(b,{updated:[y]})},T=(v,b=ne.LOCAL)=>{const y=v.map(_=>w(_)).filter(Boolean);y.length>0&&s(b,{updated:y})},C=v=>{const b=e.get(v);return b?{...b}:void 0},M=v=>{const b=t.get(v);if(b){const y=C(b).bodies.find(_=>_.id===v);if(y)return y;console.error(`Store integrity error: body ${v} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${v}`)},V=(v,b)=>{if(v.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const y=e.get(v.annotation);if(y){const _=y.bodies.find(P=>P.id===v.id),I={...y,bodies:y.bodies.map(P=>P.id===_.id?b:P)};return e.set(y.id,I),_.id!==b.id&&(t.delete(_.id),t.set(b.id,I.id)),{oldValue:y,newValue:I,bodiesUpdated:[{oldBody:_,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${v.annotation}`)},U=(v,b,y=ne.LOCAL)=>{const _=V(v,b);_&&s(y,{updated:[_]})},W=(v,b=ne.LOCAL)=>{const y=v.map(_=>V({id:_.id,annotation:_.annotation},_)).filter(Boolean);s(b,{updated:y})},q=v=>{const b=e.get(v.annotation);if(b){const y={...b,target:{...b.target,...v}};return e.set(b.id,y),{oldValue:b,newValue:y,targetUpdated:{oldTarget:b.target,newTarget:v}}}else console.warn(`Attempt to update target on missing annotation: ${v.annotation}`)};return{addAnnotation:r,addBody:h,all:g,bulkAddAnnotations:p,bulkDeleteAnnotations:S,bulkDeleteBodies:T,bulkUpdateAnnotations:d,bulkUpdateBodies:W,bulkUpdateTargets:(v,b=ne.LOCAL)=>{const y=v.map(_=>q(_)).filter(Boolean);y.length>0&&s(b,{updated:y})},bulkUpsertAnnotations:f,clear:m,deleteAnnotation:E,deleteBody:A,getAnnotation:C,getBody:M,observe:o,unobserve:i,updateAnnotation:a,updateBody:U,updateTarget:(v,b=ne.LOCAL)=>{const y=q(v);y&&s(b,{updated:[y]})},upsertAnnotation:u}};let zi=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const qi=250,Ki=(e,t)=>{const n=zi(),o=(t==null?void 0:t.changes)||[];let i=t?t.pointer:-1,s=!1,r=0;const l=m=>{if(!s){const{changes:p}=m,k=performance.now();if(k-r>qi)o.splice(i+1),o.push(p),i=o.length-1;else{const E=o.length-1;o[E]=Gi(o[E],p)}r=k}s=!1};e.observe(l,{origin:ne.LOCAL});const a=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m),u=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),d=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({oldValue:p})=>p)),f=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({newValue:p})=>p)),h=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),g=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...o],pointer:i}),on:(m,p)=>n.on(m,p),redo:()=>{if(o.length-1>i){s=!0;const{created:m,updated:p,deleted:k}=o[i+1];u(m),f(p),g(k),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:m,updated:p,deleted:k}=o[i];a(m),d(p),h(k),n.emit("undo",o[i]),i-=1}}}},Wi=()=>{const e=Dt([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Zi=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],d,f;const h=(E,S)=>{a.has(E)?a.get(E).push(S):a.set(E,[S])},g=(E,S)=>{const w=a.get(E);if(w){const A=w.indexOf(S);A!==-1&&w.splice(A,1)}},m=(E,S,w)=>{a.has(E)&&setTimeout(()=>{a.get(E).forEach(A=>{if(n){const T=Array.isArray(S)?S.map(M=>n.serialize(M)):n.serialize(S),C=w?w instanceof PointerEvent?w:n.serialize(w):void 0;A(T,C)}else A(S,w)})},1)},p=()=>{const{selected:E}=s,S=(E||[]).map(({id:w})=>r.getAnnotation(w));S.forEach(w=>{const A=u.find(T=>T.id===w.id);(!A||!De(A,w))&&m("updateAnnotation",w,A)}),u=u.map(w=>S.find(({id:T})=>T===w.id)||w)};s.subscribe(({selected:E})=>{if(!(u.length===0&&E.length===0)){if(u.length===0&&E.length>0)u=E.map(({id:S})=>r.getAnnotation(S));else if(u.length>0&&E.length===0)u.forEach(S=>{const w=r.getAnnotation(S.id);w&&!De(w,S)&&m("updateAnnotation",w,S)}),u=[];else{const S=new Set(u.map(A=>A.id)),w=new Set(E.map(({id:A})=>A));u.filter(A=>!w.has(A.id)).forEach(A=>{const T=r.getAnnotation(A.id);T&&!De(T,A)&&m("updateAnnotation",T,A)}),u=[...u.filter(A=>w.has(A.id)),...E.filter(({id:A})=>!S.has(A)).map(({id:A})=>r.getAnnotation(A))]}m("selectionChanged",u)}}),i.subscribe(E=>{!d&&E?m("mouseEnterAnnotation",r.getAnnotation(E)):d&&!E?m("mouseLeaveAnnotation",r.getAnnotation(d)):d&&E&&(m("mouseLeaveAnnotation",r.getAnnotation(d)),m("mouseEnterAnnotation",r.getAnnotation(E))),d=E}),l==null||l.subscribe(E=>m("viewportIntersect",E.map(S=>r.getAnnotation(S)))),r.observe(E=>{o&&(f&&clearTimeout(f),f=setTimeout(p,1e3));const{created:S,deleted:w}=E.changes;(S||[]).forEach(A=>m("createAnnotation",A)),(w||[]).forEach(A=>m("deleteAnnotation",A)),(E.changes.updated||[]).filter(A=>[...A.bodiesCreated||[],...A.bodiesDeleted||[],...A.bodiesUpdated||[]].length>0).forEach(({oldValue:A,newValue:T})=>{const C=u.find(M=>M.id===A.id)||A;u=u.map(M=>M.id===A.id?T:M),m("updateAnnotation",T,C)})},{origin:ne.LOCAL}),r.observe(E=>{if(u){const S=new Set(u.map(A=>A.id)),w=(E.changes.updated||[]).filter(({newValue:A})=>S.has(A.id)).map(({newValue:A})=>A);w.length>0&&(u=u.map(A=>w.find(C=>C.id===A.id)||A))}},{origin:ne.REMOTE});const k=E=>S=>{const{updated:w}=S;E?(w||[]).forEach(A=>m("updateAnnotation",A.oldValue,A.newValue)):(w||[]).forEach(A=>m("updateAnnotation",A.newValue,A.oldValue))};return t.on("undo",k(!0)),t.on("redo",k(!1)),{on:h,off:g,emit:m}},Ji=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Qi=(e,t,n)=>{const{store:o,selection:i}=e,s=E=>{if(n){const{parsed:S,error:w}=n.parse(E);S?o.addAnnotation(S,ne.REMOTE):console.error(w)}else o.addAnnotation(Yt(E),ne.REMOTE)},r=()=>i.clear(),l=()=>o.clear(),a=E=>{const S=o.getAnnotation(E);return n&&S?n.serialize(S):S},u=()=>n?o.all().map(n.serialize):o.all(),d=()=>{var E;const S=(((E=i.selected)==null?void 0:E.map(w=>w.id))||[]).map(w=>o.getAnnotation(w)).filter(Boolean);return n?S.map(n.serialize):S},f=(E,S=!0)=>fetch(E).then(w=>w.json()).then(w=>(g(w,S),w)),h=E=>{if(typeof E=="string"){const S=o.getAnnotation(E);if(o.deleteAnnotation(E),S)return n?n.serialize(S):S}else{const S=n?n.parse(E).parsed:E;if(S)return o.deleteAnnotation(S),E}},g=(E,S=!0)=>{if(n){const w=n.parseAll||Ji(n),{parsed:A,failed:T}=w(E);T.length>0&&console.warn(`Discarded ${T.length} invalid annotations`,T),o.bulkAddAnnotations(A,S,ne.REMOTE)}else o.bulkAddAnnotations(E.map(Yt),S,ne.REMOTE)},m=(E,S)=>{E?i.setSelected(E,S):i.clear()},p=E=>{i.setUserSelectAction(E)},k=E=>{if(n){const S=n.parse(E).parsed,w=n.serialize(o.getAnnotation(S.id));return o.updateAnnotation(S),w}else{const S=o.getAnnotation(E.id);return o.updateAnnotation(Yt(E)),S}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:d,loadAnnotations:f,redo:t.redo,removeAnnotation:h,setAnnotations:g,setSelected:m,setUserSelectAction:p,undo:t.undo,updateAnnotation:k}},xi=(e,t,n)=>typeof t=="function"?t(e,n):t,$i=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,o)=>{const i=typeof e=="function"?e(n,o):e,s=typeof t=="function"?t(n,o):t;return{...i||{},...s||{}}},es="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ts=e=>crypto.getRandomValues(new Uint8Array(e)),ns=(e,t,n)=>{let o=(2<<Math.log2(e.length-1))-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let l=n(i),a=i|0;for(;a--;)if(r+=e[l[a]&o]||"",r.length>=s)return r}}},os=(e,t=21)=>ns(e,t|0,ts),is=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=es[n[e]&63];return t};const ss=()=>({isGuest:!0,id:os("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),rs=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Vn=e=>e?typeof e=="object"?{...e}:e:void 0,ls=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:l,modified:a,creator:u,...d}=n;return{id:o||`temp-${rs(n)}`,annotation:t,type:i,purpose:s,value:r,creator:Vn(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...d}}),as=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,l={...r,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l}),cs=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],us=()=>{const e=[...cs];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};is();const fs=(e,t={strict:!0,invertY:!1})=>({parse:i=>Xn(i,t),serialize:i=>Hn(i,e,t)}),Xn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Bn(),{creator:o,created:i,modified:s,body:r,...l}=e,a=ls(r||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,d=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,f=kn(d)?Mn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?Cn(d):void 0,h=Array.isArray(l.target)?l.target[0]:l.targret;return f||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Vn(o),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Hn=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:s,updated:r,updatedBy:l,...a}=e.target;let u;try{u=o.type==Q.RECTANGLE?Tn(o.geometry):On(o)}catch(f){if(n.strict)throw f;u=o}const d={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:as(e.bodies),created:s==null?void 0:s.toISOString(),creator:i,modified:r==null?void 0:r.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete d.bodies,typeof d.target!="string"&&"annotation"in d.target&&delete d.target.annotation,d},Ke=[];function ds(e,t=j){let n;const o=new Set;function i(l){if(re(e,l)&&(e=l,n)){const a=!Ke.length;for(const u of o)u[1](),Ke.push(u,e);if(a){for(let u=0;u<Ke.length;u+=2)Ke[u][0](Ke[u+1]);Ke.length=0}}}function s(l){i(l(e))}function r(l,a=j){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||j),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const hs=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},Gn=(e,t)=>{hs(e,t);const{subscribe:n,set:o}=ds(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,u=Math.max(r.width/l,r.height/a);o(u)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},He=(e,t,n)=>{const o=typeof t=="function"?t(e,n):t;if(o){const{fill:i,fillOpacity:s,stroke:r,strokeWidth:l,strokeOpacity:a}=o;let u="";return i&&(u+=`fill:${i};`),s||s===0?u+=`fill-opacity:${s};`:i&&(u+="fill-opacity:0.25;"),r&&(u+=`stroke:${r};`,u+=`stroke-width:${l||"1"};`,u+=`stroke-opacity:${a||"1"};`),u}},st=(e,t=0)=>{const{minX:n,minY:o,maxX:i,maxY:s}=e;return{x:n-t,y:o-t,w:i-n+2*t,h:s-o+2*t}},Ie=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,gs=e=>({}),jn=e=>({grab:e[0]});function ms(e){let t,n,o,i;const s=e[8].default,r=Ko(s,e,e[7],jn);return{c(){t=L("g"),r&&r.c(),c(t,"class","a9s-annotation selected")},m(l,a){N(l,t,a),r&&r.m(t,null),n=!0,o||(i=[J(t,"pointerup",e[2]),J(t,"pointermove",e[1])],o=!0)},p(l,[a]){r&&r.p&&(!n||a&128)&&Zo(r,s,l,l[7],n?Wo(s,l[7],a,gs):Jo(l[7]),jn)},i(l){n||(R(r,l),n=!0)},o(l){G(r,l),n=!1},d(l){l&&B(t),r&&r.d(l),o=!1,Ae(i)}}}function ps(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=Oe();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,d,f,h;const g=k=>E=>{if(d=k,u){const{left:w,top:A}=u.getBoundingClientRect(),T=E.clientX-w,C=E.clientY-A;f=a.elementToImage(T,C)}else{const{offsetX:w,offsetY:A}=E;f=a.elementToImage(w,A)}h=r,E.target.setPointerCapture(E.pointerId),s("grab",E)},m=k=>{if(d){const[E,S]=a.elementToImage(k.offsetX,k.offsetY),w=[E-f[0],S-f[1]];n(3,r=l(h,d,w)),s("change",r)}},p=k=>{k.target.releasePointerCapture(k.pointerId),d=void 0,h=r,s("release",k)};return e.$$set=k=>{"shape"in k&&n(3,r=k.shape),"editor"in k&&n(4,l=k.editor),"transform"in k&&n(5,a=k.transform),"svgEl"in k&&n(6,u=k.svgEl),"$$scope"in k&&n(7,i=k.$$scope)},[g,m,p,r,l,a,u,i,o]}class _t extends ge{constructor(t){super(),he(this,t,ps,ms,re,{shape:3,editor:4,transform:5,svgEl:6})}}function ys(e){let t,n,o,i,s,r,l,a,u=e[3]&&Fn(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),i=L("circle"),c(n,"class","a9s-handle-buffer svelte-qtyc7s"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]+6/e[2]),c(n,"role","button"),c(n,"tabindex","0"),c(i,"class",s=je(`a9s-handle-dot${e[3]?" selected":""}`)+" svelte-qtyc7s"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[5]),c(t,"class",r=`a9s-handle ${e[8].class||""}`.trim())},m(d,f){N(d,t,f),z(t,n),u&&u.m(t,null),z(t,i),l||(a=[J(n,"dblclick",e[12]),J(n,"pointerenter",e[13]),J(n,"pointerleave",e[14]),J(n,"pointerdown",e[15]),J(n,"pointerdown",e[6]),J(n,"pointerup",e[16]),J(n,"pointerup",e[7])],l=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&36&&o!==(o=d[5]+6/d[2])&&c(n,"r",o),d[3]?u?u.p(d,f):(u=Fn(d),u.c(),u.m(t,i)):u&&(u.d(1),u=null),f&8&&s!==(s=je(`a9s-handle-dot${d[3]?" selected":""}`)+" svelte-qtyc7s")&&c(i,"class",s),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&32&&c(i,"r",d[5]),f&256&&r!==(r=`a9s-handle ${d[8].class||""}`.trim())&&c(t,"class",r)},d(d){d&&B(t),u&&u.d(),l=!1,Ae(a)}}}function _s(e){let t,n,o,i,s,r,l,a,u;return{c(){t=L("g"),n=L("circle"),i=L("circle"),r=L("circle"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]*10),c(n,"class","a9s-touch-halo"),Pe(n,"touched",e[4]),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",s=e[5]+10/e[2]),c(i,"class","a9s-handle-buffer svelte-qtyc7s"),c(i,"role","button"),c(i,"tabindex","0"),c(r,"class","a9s-handle-dot"),c(r,"cx",e[0]),c(r,"cy",e[1]),c(r,"r",l=e[5]+2/e[2]),c(t,"class","a9s-touch-handle")},m(d,f){N(d,t,f),z(t,n),z(t,i),z(t,r),a||(u=[J(i,"dblclick",e[9]),J(i,"pointerdown",e[10]),J(i,"pointerdown",e[6]),J(i,"pointerup",e[11]),J(i,"pointerup",e[7])],a=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&32&&o!==(o=d[5]*10)&&c(n,"r",o),f&16&&Pe(n,"touched",d[4]),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&36&&s!==(s=d[5]+10/d[2])&&c(i,"r",s),f&1&&c(r,"cx",d[0]),f&2&&c(r,"cy",d[1]),f&36&&l!==(l=d[5]+2/d[2])&&c(r,"r",l)},d(d){d&&B(t),a=!1,Ae(u)}}}function Fn(e){let t,n;return{c(){t=L("circle"),c(t,"class","a9s-handle-selected"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",n=e[5]+8/e[2])},m(o,i){N(o,t,i)},p(o,i){i&1&&c(t,"cx",o[0]),i&2&&c(t,"cy",o[1]),i&36&&n!==(n=o[5]+8/o[2])&&c(t,"r",n)},d(o){o&&B(t)}}}function ws(e){let t;function n(s,r){return Ie?_s:ys}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),N(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&B(t),i.d(s)}}}function bs(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=w=>{w.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function f(w){ue.call(this,e,w)}function h(w){ue.call(this,e,w)}function g(w){ue.call(this,e,w)}function m(w){ue.call(this,e,w)}function p(w){ue.call(this,e,w)}function k(w){ue.call(this,e,w)}function E(w){ue.call(this,e,w)}function S(w){ue.call(this,e,w)}return e.$$set=w=>{n(8,t=Ce(Ce({},t),un(w))),"x"in w&&n(0,i=w.x),"y"in w&&n(1,s=w.y),"scale"in w&&n(2,r=w.scale),"selected"in w&&n(3,l=w.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=4/r)},t=un(t),[i,s,r,l,a,o,u,d,t,f,h,g,m,p,k,E,S]}class Ge extends ge{constructor(t){super(),he(this,t,bs,ws,re,{x:0,y:1,scale:2,selected:3})}}function Es(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("circle"),i=L("circle"),s=L("circle"),c(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=1.75*e[2]),c(i,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[2]),c(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),c(s,"cx",e[0]),c(s,"cy",e[1]),c(s,"r",e[2]),c(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(a,u){N(a,t,u),z(t,n),z(t,i),z(t,s),r||(l=[J(n,"pointerdown",e[5]),J(n,"pointerdown",e[3])],r=!0)},p(a,u){u&1&&c(n,"cx",a[0]),u&2&&c(n,"cy",a[1]),u&4&&o!==(o=1.75*a[2])&&c(n,"r",o),u&1&&c(i,"cx",a[0]),u&2&&c(i,"cy",a[1]),u&4&&c(i,"r",a[2]),u&1&&c(s,"cx",a[0]),u&2&&c(s,"cy",a[1]),u&4&&c(s,"r",a[2])},d(a){a&&B(t),r=!1,Ae(l)}}}function vs(e){let t;return{c(){t=L("circle"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",e[2])},m(n,o){N(n,t,o)},p(n,o){o&1&&c(t,"cx",n[0]),o&2&&c(t,"cy",n[1]),o&4&&c(t,"r",n[2])},d(n){n&&B(t)}}}function Ss(e){let t;function n(s,r){return Ie?vs:Es}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),N(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&B(t),i.d(s)}}}function As(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){ue.call(this,e,u)}return e.$$set=u=>{"x"in u&&n(0,i=u.x),"y"in u&&n(1,s=u.y),"scale"in u&&n(4,r=u.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,o=4/r)},[i,s,o,l,r,a]}class Rt extends ge{constructor(t){super(),he(this,t,As,Ss,re,{x:0,y:1,scale:4})}}function Vt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function zn(e,t,n){const o=e.slice();return o[28]=t[n],o[30]=n,o}function Xt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Ht(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function qn(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[28][0]),c(t,"cy",o=e[28][1]),c(t,"r",i=rt/e[3]),c(t,"class","svelte-1h2slbm")},m(s,r){N(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[28][1])&&c(t,"cy",o),r[0]&8&&i!==(i=rt/s[3])&&c(t,"r",i)},d(s){s&&B(t)}}}function Kn(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1h2slbm"),c(l,"cx",a=e[28][0]),c(l,"cy",u=e[28][1]),c(l,"r",d=rt/e[3]),c(l,"class","svelte-1h2slbm"),c(t,"id",`${e[19]}-inner`),c(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(f,h){N(f,t,h),z(t,n),z(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[28][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[28][1])&&c(l,"cy",u),h[0]&8&&d!==(d=rt/f[3])&&c(l,"r",d)},d(f){f&&B(t)}}}function Wn(e){let t,n;return t=new Ge({props:{class:"a9s-corner-handle",x:e[28][0],y:e[28][1],scale:e[3],selected:e[8].includes(e[30])}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[15]),t.$on("pointerdown",function(){ie(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&32&&(s.x=e[28][0]),i[0]&32&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),i[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Zn(e){let t,n;return t=new Rt({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[28][0]),i[0]&1088&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function ks(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,E,S,w,A,T,C=e[6]!==void 0&&!e[7]&&qn(Ht(e)),M=e[6]!==void 0&&!e[7]&&Kn(Xt(e)),V=ve(e[5].points),U=[];for(let v=0;v<V.length;v+=1)U[v]=Wn(zn(e,V,v));const W=v=>G(U[v],1,1,()=>{U[v]=null});let q=e[6]!==void 0&&!e[7]&&Zn(Vt(e));return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),C&&C.c(),M&&M.c(),d=we(),f=L("polygon"),g=we(),m=L("polygon"),k=we();for(let v=0;v<U.length;v+=1)U[v].c();E=we(),q&&q.c(),S=ke(),c(o,"x",i=e[9].x),c(o,"y",s=e[9].y),c(o,"width",r=e[9].w),c(o,"height",l=e[9].h),c(o,"class","svelte-1h2slbm"),c(a,"points",u=e[5].points.map(Jn).join(" ")),c(a,"class","svelte-1h2slbm"),c(n,"id",`${e[19]}-outer`),c(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[19]}-outer)`),c(f,"points",h=e[5].points.map(Qn).join(" ")),c(m,"class","a9s-inner a9s-shape-handle"),c(m,"mask",`url(#${e[19]}-inner)`),c(m,"style",e[1]),c(m,"points",p=e[5].points.map(xn).join(" "))},m(v,b){N(v,t,b),z(t,n),z(n,o),z(n,a),C&&C.m(n,null),M&&M.m(t,null),N(v,d,b),N(v,f,b),N(v,g,b),N(v,m,b),N(v,k,b);for(let y=0;y<U.length;y+=1)U[y]&&U[y].m(v,b);N(v,E,b),q&&q.m(v,b),N(v,S,b),w=!0,A||(T=[J(f,"pointerup",e[14]),J(f,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),J(m,"pointermove",e[13]),J(m,"pointerup",e[14]),J(m,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],A=!0)},p(v,b){if(e=v,(!w||b[0]&512&&i!==(i=e[9].x))&&c(o,"x",i),(!w||b[0]&512&&s!==(s=e[9].y))&&c(o,"y",s),(!w||b[0]&512&&r!==(r=e[9].w))&&c(o,"width",r),(!w||b[0]&512&&l!==(l=e[9].h))&&c(o,"height",l),(!w||b[0]&32&&u!==(u=e[5].points.map(Jn).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Ht(e),b):(C=qn(Ht(e)),C.c(),C.m(n,null)):C&&(C.d(1),C=null),e[6]!==void 0&&!e[7]?M?M.p(Xt(e),b):(M=Kn(Xt(e)),M.c(),M.m(t,null)):M&&(M.d(1),M=null),(!w||b[0]&32&&h!==(h=e[5].points.map(Qn).join(" ")))&&c(f,"points",h),(!w||b[0]&2)&&c(m,"style",e[1]),(!w||b[0]&32&&p!==(p=e[5].points.map(xn).join(" ")))&&c(m,"points",p),b[0]&134322472){V=ve(e[5].points);let y;for(y=0;y<V.length;y+=1){const _=zn(e,V,y);U[y]?(U[y].p(_,b),R(U[y],1)):(U[y]=Wn(_),U[y].c(),R(U[y],1),U[y].m(E.parentNode,E))}for(be(),y=V.length;y<U.length;y+=1)W(y);Ee()}e[6]!==void 0&&!e[7]?q?(q.p(Vt(e),b),b[0]&192&&R(q,1)):(q=Zn(Vt(e)),q.c(),R(q,1),q.m(S.parentNode,S)):q&&(be(),G(q,1,1,()=>{q=null}),Ee())},i(v){if(!w){for(let b=0;b<V.length;b+=1)R(U[b]);R(q),w=!0}},o(v){U=U.filter(Boolean);for(let b=0;b<U.length;b+=1)G(U[b]);G(q),w=!1},d(v){v&&(B(t),B(d),B(f),B(g),B(m),B(k),B(E),B(S)),C&&C.d(),M&&M.d(),Ye(U,v),q&&q.d(v),A=!1,Ae(T)}}}function Ms(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[ks,({grab:o})=>({27:o}),({grab:o})=>[o?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&134219754|i[1]&1&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ts=250,Ps=1e3,Ls=12,rt=4.5,Jn=e=>e.join(","),Qn=e=>e.join(","),xn=e=>e.join(",");function Is(e,t,n){let o,i,s;const r=Oe();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,g=!1,m,p=[];const k=()=>n(7,g=!0),E=()=>n(7,g=!1),S=y=>{if(p.length>0||!i.some(Z=>Z.visible)){n(6,h=void 0);return}const[_,I]=u.elementToImage(y.offsetX,y.offsetY),P=Z=>Math.pow(Z[0]-_,2)+Math.pow(Z[1]-I,2),D=o.points.reduce((Z,$)=>P($)<P(Z)?$:Z),F=i.filter(Z=>Z.visible).reduce((Z,$)=>P($.point)<P(Z.point)?$:Z),H=Math.pow(Ps/d,2);P(D)<H||P(F.point)<H?n(6,h=i.indexOf(F)):n(6,h=void 0)},w=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,p=[]),w()},T=y=>{n(7,g=!0),y.preventDefault(),y.stopPropagation(),m=performance.now()},C=y=>_=>{if(!m||Ie||performance.now()-m>Ts)return;const I=p.includes(y);_.metaKey||_.ctrlKey||_.shiftKey?I?n(8,p=p.filter(P=>P!==y)):n(8,p=[...p,y]):I&&p.length>1?n(8,p=[y]):I?n(8,p=[]):n(8,p=[y]),w()},M=(y,_,I)=>{w();let P;const D=y.geometry;p.length>1?P=D.points.map(([H,x],Z)=>p.includes(Z)?[H+I[0],x+I[1]]:[H,x]):_==="SHAPE"?P=D.points.map(([H,x])=>[H+I[0],x+I[1]]):P=D.points.map(([H,x],Z)=>_===`HANDLE-${Z}`?[H+I[0],x+I[1]]:[H,x]);const F=fe(P);return{...y,geometry:{points:P,bounds:F}}},V=y=>async _=>{_.stopPropagation();const I=[...o.points.slice(0,y+1),i[y].point,...o.points.slice(y+1)],P=fe(I);r("change",{...l,geometry:{points:I,bounds:P}}),await pn();const D=[...document.querySelectorAll(".a9s-handle")][y+1];if(D!=null&&D.firstChild){const F=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:_.clientX,clientY:_.clientY,pointerId:_.pointerId,pointerType:_.pointerType,isPrimary:_.isPrimary,buttons:_.buttons});D.firstChild.dispatchEvent(F)}},U=()=>{if(o.points.length-p.length<3)return;const y=o.points.filter((I,P)=>!p.includes(P)),_=fe(y);r("change",{...l,geometry:{points:y,bounds:_}}),n(8,p=[])};Re(()=>{if(Ie)return;const y=_=>{(_.key==="Delete"||_.key==="Backspace")&&(_.preventDefault(),U())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",y),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",y)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function q(y){ue.call(this,e,y)}function v(y){ue.call(this,e,y)}function b(y){ue.call(this,e,y)}return e.$$set=y=>{"shape"in y&&n(0,l=y.shape),"computedStyle"in y&&n(1,a=y.computedStyle),"transform"in y&&n(2,u=y.transform),"viewportScale"in y&&n(3,d=y.viewportScale),"svgEl"in y&&n(4,f=y.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Ie?[]:o.points.map((y,_)=>{const I=_===o.points.length-1?o.points[0]:o.points[_+1],P=(y[0]+I[0])/2,D=(y[1]+I[1])/2,H=Math.sqrt(Math.pow(I[0]-P,2)+Math.pow(I[1]-D,2))>Ls/d;return{point:[P,D],visible:H}})),e.$$.dirty[0]&40&&n(9,s=st(o.bounds,rt/d))},[l,a,u,d,f,o,h,g,p,s,i,k,E,S,A,T,C,M,V,W,q,v,b]}class $n extends ge{constructor(t){super(),he(this,t,Is,Ms,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Cs(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,E,S,w,A,T,C,M,V,U,W,q,v,b,y,_,I,P,D,F,H,x,Z,$,oe,se,Se,Te,X,de,te,ye,_e,Je,Ne,nn,Ue,ee,on,zo;return te=new Ge({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),_e=new Ge({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),_e.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),Ne=new Ge({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),Ne.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Ue=new Ge({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Ue.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),g=we(),m=L("rect"),w=we(),A=L("rect"),U=we(),W=L("rect"),y=we(),_=L("rect"),F=we(),H=L("rect"),oe=we(),se=L("rect"),de=we(),ce(te.$$.fragment),ye=we(),ce(_e.$$.fragment),Je=we(),ce(Ne.$$.fragment),nn=we(),ce(Ue.$$.fragment),c(o,"class","rect-mask-bg svelte-1njczvj"),c(o,"x",i=e[6].x),c(o,"y",s=e[6].y),c(o,"width",r=e[6].w),c(o,"height",l=e[6].h),c(a,"class","rect-mask-fg svelte-1njczvj"),c(a,"x",u=e[5].x),c(a,"y",d=e[5].y),c(a,"width",f=e[5].w),c(a,"height",h=e[5].h),c(n,"id",e[8]),c(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),c(m,"class","a9s-outer"),c(m,"mask",`url(#${e[8]})`),c(m,"x",p=e[5].x),c(m,"y",k=e[5].y),c(m,"width",E=e[5].w),c(m,"height",S=e[5].h),c(A,"class","a9s-inner a9s-shape-handle"),c(A,"style",e[1]),c(A,"x",T=e[5].x),c(A,"y",C=e[5].y),c(A,"width",M=e[5].w),c(A,"height",V=e[5].h),c(W,"class","a9s-edge-handle a9s-edge-handle-top"),c(W,"x",q=e[5].x),c(W,"y",v=e[5].y),c(W,"height",1),c(W,"width",b=e[5].w),c(_,"class","a9s-edge-handle a9s-edge-handle-right"),c(_,"x",I=e[5].x+e[5].w),c(_,"y",P=e[5].y),c(_,"height",D=e[5].h),c(_,"width",1),c(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),c(H,"x",x=e[5].x),c(H,"y",Z=e[5].y+e[5].h),c(H,"height",1),c(H,"width",$=e[5].w),c(se,"class","a9s-edge-handle a9s-edge-handle-left"),c(se,"x",Se=e[5].x),c(se,"y",Te=e[5].y),c(se,"height",X=e[5].h),c(se,"width",1)},m(K,Y){N(K,t,Y),z(t,n),z(n,o),z(n,a),N(K,g,Y),N(K,m,Y),N(K,w,Y),N(K,A,Y),N(K,U,Y),N(K,W,Y),N(K,y,Y),N(K,_,Y),N(K,F,Y),N(K,H,Y),N(K,oe,Y),N(K,se,Y),N(K,de,Y),le(te,K,Y),N(K,ye,Y),le(_e,K,Y),N(K,Je,Y),le(Ne,K,Y),N(K,nn,Y),le(Ue,K,Y),ee=!0,on||(zo=[J(m,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),J(A,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),J(W,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),J(_,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),J(H,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),J(se,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],on=!0)},p(K,Y){e=K,(!ee||Y&64&&i!==(i=e[6].x))&&c(o,"x",i),(!ee||Y&64&&s!==(s=e[6].y))&&c(o,"y",s),(!ee||Y&64&&r!==(r=e[6].w))&&c(o,"width",r),(!ee||Y&64&&l!==(l=e[6].h))&&c(o,"height",l),(!ee||Y&32&&u!==(u=e[5].x))&&c(a,"x",u),(!ee||Y&32&&d!==(d=e[5].y))&&c(a,"y",d),(!ee||Y&32&&f!==(f=e[5].w))&&c(a,"width",f),(!ee||Y&32&&h!==(h=e[5].h))&&c(a,"height",h),(!ee||Y&32&&p!==(p=e[5].x))&&c(m,"x",p),(!ee||Y&32&&k!==(k=e[5].y))&&c(m,"y",k),(!ee||Y&32&&E!==(E=e[5].w))&&c(m,"width",E),(!ee||Y&32&&S!==(S=e[5].h))&&c(m,"height",S),(!ee||Y&2)&&c(A,"style",e[1]),(!ee||Y&32&&T!==(T=e[5].x))&&c(A,"x",T),(!ee||Y&32&&C!==(C=e[5].y))&&c(A,"y",C),(!ee||Y&32&&M!==(M=e[5].w))&&c(A,"width",M),(!ee||Y&32&&V!==(V=e[5].h))&&c(A,"height",V),(!ee||Y&32&&q!==(q=e[5].x))&&c(W,"x",q),(!ee||Y&32&&v!==(v=e[5].y))&&c(W,"y",v),(!ee||Y&32&&b!==(b=e[5].w))&&c(W,"width",b),(!ee||Y&32&&I!==(I=e[5].x+e[5].w))&&c(_,"x",I),(!ee||Y&32&&P!==(P=e[5].y))&&c(_,"y",P),(!ee||Y&32&&D!==(D=e[5].h))&&c(_,"height",D),(!ee||Y&32&&x!==(x=e[5].x))&&c(H,"x",x),(!ee||Y&32&&Z!==(Z=e[5].y+e[5].h))&&c(H,"y",Z),(!ee||Y&32&&$!==($=e[5].w))&&c(H,"width",$),(!ee||Y&32&&Se!==(Se=e[5].x))&&c(se,"x",Se),(!ee||Y&32&&Te!==(Te=e[5].y))&&c(se,"y",Te),(!ee||Y&32&&X!==(X=e[5].h))&&c(se,"height",X);const Et={};Y&32&&(Et.x=e[5].x),Y&32&&(Et.y=e[5].y),Y&8&&(Et.scale=e[3]),te.$set(Et);const vt={};Y&32&&(vt.x=e[5].x+e[5].w),Y&32&&(vt.y=e[5].y),Y&8&&(vt.scale=e[3]),_e.$set(vt);const St={};Y&32&&(St.x=e[5].x+e[5].w),Y&32&&(St.y=e[5].y+e[5].h),Y&8&&(St.scale=e[3]),Ne.$set(St);const At={};Y&32&&(At.x=e[5].x),Y&32&&(At.y=e[5].y+e[5].h),Y&8&&(At.scale=e[3]),Ue.$set(At)},i(K){ee||(R(te.$$.fragment,K),R(_e.$$.fragment,K),R(Ne.$$.fragment,K),R(Ue.$$.fragment,K),ee=!0)},o(K){G(te.$$.fragment,K),G(_e.$$.fragment,K),G(Ne.$$.fragment,K),G(Ue.$$.fragment,K),ee=!1},d(K){K&&(B(t),B(g),B(m),B(w),B(A),B(U),B(W),B(y),B(_),B(F),B(H),B(oe),B(se),B(de),B(ye),B(Je),B(nn)),ae(te,K),ae(_e,K),ae(Ne,K),ae(Ue,K),on=!1,Ae(zo)}}}function Os(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Cs,({grab:o})=>({12:o}),({grab:o})=>o?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&16&&(s.svgEl=o[4]),i&12394&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ds(e,t,n){let o,i,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const d=(p,k,E)=>{const S=p.geometry.bounds;let[w,A]=[S.minX,S.minY],[T,C]=[S.maxX,S.maxY];const[M,V]=E;if(k==="SHAPE")w+=M,T+=M,A+=V,C+=V;else{switch(k){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{A+=V;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{C+=V;break}}switch(k){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{w+=M;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{T+=M;break}}}const U=Math.min(w,T),W=Math.min(A,C),q=Math.abs(T-w),v=Math.abs(C-A);return{...p,geometry:{x:U,y:W,w:q,h:v,bounds:{minX:U,minY:W,maxX:U+q,maxY:W+v}}}},f=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function h(p){ue.call(this,e,p)}function g(p){ue.call(this,e,p)}function m(p){ue.call(this,e,p)}return e.$$set=p=>{"shape"in p&&n(0,s=p.shape),"computedStyle"in p&&n(1,r=p.computedStyle),"transform"in p&&n(2,l=p.transform),"viewportScale"in p&&n(3,a=p.viewportScale),"svgEl"in p&&n(4,u=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,o=s.geometry),e.$$.dirty&40&&n(6,i=st(o.bounds,2/a))},[s,r,l,a,u,o,i,d,f,h,g,m]}class eo extends ge{constructor(t){super(),he(this,t,Ds,Os,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var to=Object.prototype.hasOwnProperty;function Gt(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&Gt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(to.call(e,n)&&++o&&!to.call(t,n)||!(n in t)||!Gt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Bs=12,Ns=(e,t)=>e.polygons.reduce((n,o,i)=>{const s=o.rings.reduce((r,l,a)=>{const u=l.points.map((d,f)=>{const h=f===l.points.length-1?l.points[0]:l.points[f+1],g=(d[0]+h[0])/2,m=(d[1]+h[1])/2,k=Math.sqrt(Math.pow(h[0]-g,2)+Math.pow(h[1]-m,2))>Bs/t;return{point:[g,m],visible:k,elementIdx:i,ringIdx:a,pointIdx:f}});return[...r,...u]},[]);return[...n,...s]},[]);function jt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function no(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function oo(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function io(e,t,n){const o=e.slice();return o[29]=t[n],o[37]=n,o}function Ft(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function zt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function so(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[29][0]),c(t,"cy",o=e[29][1]),c(t,"r",i=lt/e[3]),c(t,"class","svelte-1vxo6dc")},m(s,r){N(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[29][1])&&c(t,"cy",o),r[0]&8&&i!==(i=lt/s[3])&&c(t,"r",i)},d(s){s&&B(t)}}}function ro(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1vxo6dc"),c(l,"cx",a=e[29][0]),c(l,"cy",u=e[29][1]),c(l,"r",d=lt/e[3]),c(l,"class","svelte-1vxo6dc"),c(t,"id",`${e[18]}-${e[32]}-inner`),c(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(f,h){N(f,t,h),z(t,n),z(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[29][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[29][1])&&c(l,"cy",u),h[0]&8&&d!==(d=lt/f[3])&&c(l,"r",d)},d(f){f&&B(t)}}}function lo(e){let t,n;function o(...i){return e[19](e[32],e[35],e[37],...i)}return t=new Ge({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(o)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){ie(e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`))&&e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`).apply(this,arguments)}),t.$on("pointerup",e[15](e[32],e[35],e[37])),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){e=i;const r={};s[0]&32&&(r.x=e[29][0]),s[0]&32&&(r.y=e[29][1]),s[0]&8&&(r.scale=e[3]),s[0]&256&&(r.selected=e[8].some(o)),t.$set(r)},i(i){n||(R(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function ao(e){let t,n,o=ve(e[33].points),i=[];for(let r=0;r<o.length;r+=1)i[r]=lo(io(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);N(r,t,l),n=!0},p(r,l){if(l[0]&268491048){o=ve(r[33].points);let a;for(a=0;a<o.length;a+=1){const u=io(r,o,a);i[a]?(i[a].p(u,l),R(i[a],1)):(i[a]=lo(u),i[a].c(),R(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)R(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&B(t),Ye(i,r)}}}function co(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,E,S=e[6]!==void 0&&!e[7]&&so(zt(e)),w=e[6]!==void 0&&!e[7]&&ro(Ft(e)),A=ve(e[30].rings),T=[];for(let M=0;M<A.length;M+=1)T[M]=ao(oo(e,A,M));const C=M=>G(T[M],1,1,()=>{T[M]=null});return{c(){t=L("g"),n=L("defs"),o=L("mask"),i=L("rect"),u=L("path"),S&&S.c(),w&&w.c(),f=L("path"),g=L("path");for(let M=0;M<T.length;M+=1)T[M].c();c(i,"x",s=e[9].x),c(i,"y",r=e[9].y),c(i,"width",l=e[9].w),c(i,"height",a=e[9].h),c(i,"class","svelte-1vxo6dc"),c(u,"d",d=Le(e[30])),c(u,"class","svelte-1vxo6dc"),c(o,"id",`${e[18]}-${e[32]}-outer`),c(o,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[18]}-${e[32]}-outer)`),c(f,"fill-rule","evenodd"),c(f,"d",h=Le(e[30])),c(g,"class","a9s-inner"),c(g,"mask",`url(#${e[18]}-${e[32]}-inner)`),c(g,"style",e[1]),c(g,"fill-rule","evenodd"),c(g,"d",m=Le(e[30]))},m(M,V){N(M,t,V),z(t,n),z(n,o),z(o,i),z(o,u),S&&S.m(o,null),w&&w.m(n,null),z(t,f),z(t,g);for(let U=0;U<T.length;U+=1)T[U]&&T[U].m(t,null);p=!0,k||(E=[J(f,"pointerup",e[13]),J(f,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),J(g,"pointerup",e[13]),J(g,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],k=!0)},p(M,V){if(e=M,(!p||V[0]&512&&s!==(s=e[9].x))&&c(i,"x",s),(!p||V[0]&512&&r!==(r=e[9].y))&&c(i,"y",r),(!p||V[0]&512&&l!==(l=e[9].w))&&c(i,"width",l),(!p||V[0]&512&&a!==(a=e[9].h))&&c(i,"height",a),(!p||V[0]&32&&d!==(d=Le(e[30])))&&c(u,"d",d),e[6]!==void 0&&!e[7]?S?S.p(zt(e),V):(S=so(zt(e)),S.c(),S.m(o,null)):S&&(S.d(1),S=null),e[6]!==void 0&&!e[7]?w?w.p(Ft(e),V):(w=ro(Ft(e)),w.c(),w.m(n,null)):w&&(w.d(1),w=null),(!p||V[0]&32&&h!==(h=Le(e[30])))&&c(f,"d",h),(!p||V[0]&2)&&c(g,"style",e[1]),(!p||V[0]&32&&m!==(m=Le(e[30])))&&c(g,"d",m),V[0]&268491048){A=ve(e[30].rings);let U;for(U=0;U<A.length;U+=1){const W=oo(e,A,U);T[U]?(T[U].p(W,V),R(T[U],1)):(T[U]=ao(W),T[U].c(),R(T[U],1),T[U].m(t,null))}for(be(),U=A.length;U<T.length;U+=1)C(U);Ee()}},i(M){if(!p){for(let V=0;V<A.length;V+=1)R(T[V]);p=!0}},o(M){T=T.filter(Boolean);for(let V=0;V<T.length;V+=1)G(T[V]);p=!1},d(M){M&&B(t),S&&S.d(),w&&w.d(),Ye(T,M),k=!1,Ae(E)}}}function uo(e){let t,n;return t=new Rt({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[29][0]),i[0]&1088&&(s.y=e[29][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Us(e){let t,n,o,i=ve(e[5].polygons),s=[];for(let a=0;a<i.length;a+=1)s[a]=co(no(e,i,a));const r=a=>G(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&uo(jt(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=we(),l&&l.c(),n=ke()},m(a,u){for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(a,u);N(a,t,u),l&&l.m(a,u),N(a,n,u),o=!0},p(a,u){if(u[0]&268763114){i=ve(a[5].polygons);let d;for(d=0;d<i.length;d+=1){const f=no(a,i,d);s[d]?(s[d].p(f,u),R(s[d],1)):(s[d]=co(f),s[d].c(),R(s[d],1),s[d].m(t.parentNode,t))}for(be(),d=i.length;d<s.length;d+=1)r(d);Ee()}a[6]!==void 0&&!a[7]?l?(l.p(jt(a),u),u[0]&192&&R(l,1)):(l=uo(jt(a)),l.c(),R(l,1),l.m(n.parentNode,n)):l&&(be(),G(l,1,1,()=>{l=null}),Ee())},i(a){if(!o){for(let u=0;u<i.length;u+=1)R(s[u]);R(l),o=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)G(s[u]);G(l),o=!1},d(a){a&&(B(t),B(n)),Ye(s,a),l&&l.d(a)}}}function Ys(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[Us,({grab:o})=>({28:o}),({grab:o})=>[o?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&268437482|i[1]&128&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Rs=250,Vs=1e3,lt=4.5;function Xs(e,t,n){let o,i,s;const r=Oe();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,g=!1,m,p=[];const k=()=>n(7,g=!0),E=()=>n(7,g=!1),S=_=>{if(p.length>0||!i.some($=>$.visible)){n(6,h=void 0);return}const[I,P]=u.elementToImage(_.offsetX,_.offsetY),D=$=>Math.pow($[0]-I,2)+Math.pow($[1]-P,2),F=En(o).reduce(($,oe)=>D(oe)<D($)?oe:$),H=i.filter($=>$.visible).reduce(($,oe)=>D(oe.point)<D($.point)?oe:$),x=Math.pow(Vs/d,2);D(F)<x||D(H.point)<x?n(6,h=i.indexOf(H)):n(6,h=void 0)},w=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,p=[]),w()},T=_=>{n(7,g=!0),_.preventDefault(),_.stopPropagation(),m=performance.now()},C=(_,I,P)=>D=>{if(!m||Ie||performance.now()-m>Rs)return;const F=x=>x.polygon===_&&x.ring===I&&x.point===P,H=p.some(F);D.metaKey||D.ctrlKey||D.shiftKey?H?n(8,p=p.filter(x=>!F(x))):n(8,p=[...p,{polygon:_,ring:I,point:P}]):H&&p.length>1?n(8,p=[{polygon:_,ring:I,point:P}]):H?n(8,p=[]):n(8,p=[{polygon:_,ring:I,point:P}]),w()},M=(_,I,P)=>{w();const D=_.geometry.polygons;let F;if(I==="SHAPE")F=D.map(H=>{const x=H.rings.map(($,oe)=>({points:$.points.map((Se,Te)=>[Se[0]+P[0],Se[1]+P[1]])})),Z=fe(x[0].points);return{rings:x,bounds:Z}});else{const[H,x,Z,$]=I.split("-").map(oe=>parseInt(oe));F=D.map((oe,se)=>{if(se===x){const Se=oe.rings.map((X,de)=>de===Z?{points:X.points.map((ye,_e)=>_e===$?[ye[0]+P[0],ye[1]+P[1]]:ye)}:X),Te=fe(Se[0].points);return{rings:Se,bounds:Te}}else return oe})}return{..._,geometry:{polygons:F,bounds:nt(F)}}},V=_=>async I=>{I.stopPropagation();const P=i[_],D=o.polygons.map((H,x)=>{if(x===P.elementIdx){const Z=H.rings.map((oe,se)=>se===P.ringIdx?{points:[...oe.points.slice(0,P.pointIdx+1),P.point,...oe.points.slice(P.pointIdx+1)]}:oe),$=fe(Z[0].points);return{rings:Z,bounds:$}}else return H});r("change",{...l,geometry:{polygons:D,bounds:nt(D)}}),await pn();const F=[...document.querySelectorAll(".a9s-handle")][_+1];if(F!=null&&F.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:I.clientX,clientY:I.clientY,pointerId:I.pointerId,pointerType:I.pointerType,isPrimary:I.isPrimary,buttons:I.buttons});F.firstChild.dispatchEvent(H)}},U=()=>{const _=o.polygons.map((P,D)=>{if(p.some(H=>H.polygon===D)){const H=P.rings.map((Z,$)=>{const oe=p.filter(se=>se.polygon===D&&se.ring===$);return oe.length&&Z.points.length-oe.length>=3?{points:Z.points.filter((Se,Te)=>!oe.some(X=>X.point===Te))}:Z}),x=fe(H[0].points);return{rings:H,bounds:x}}else return P});!Gt(o.polygons,_)&&(r("change",{...l,geometry:{polygons:_,bounds:nt(_)}}),n(8,p=[]))};Re(()=>{if(Ie)return;const _=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),U())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",_),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",_)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,q=(_,I,P,{polygon:D,ring:F,point:H})=>D===_&&F===I&&H===P;function v(_){ue.call(this,e,_)}function b(_){ue.call(this,e,_)}function y(_){ue.call(this,e,_)}return e.$$set=_=>{"shape"in _&&n(0,l=_.shape),"computedStyle"in _&&n(1,a=_.computedStyle),"transform"in _&&n(2,u=_.transform),"viewportScale"in _&&n(3,d=_.viewportScale),"svgEl"in _&&n(4,f=_.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Ie?[]:Ns(o,d)),e.$$.dirty[0]&40&&n(9,s=st(o.bounds,lt/d))},[l,a,u,d,f,o,h,g,p,s,i,k,E,A,T,C,M,V,W,q,v,b,y]}class Hs extends ge{constructor(t){super(),he(this,t,Xs,Ys,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const fo=new Map([[Q.RECTANGLE,eo],[Q.POLYGON,$n],[Q.MULTIPOLYGON,Hs]]),ho=e=>fo.get(e.type),go=(e,t)=>fo.set(e,t);function Gs(e,t,n){let o;const i=Oe();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,f;return Re(()=>(n(6,f=new r({target:a,props:{shape:s.target.selector,computedStyle:o,transform:u,viewportScale:d,svgEl:a.closest("svg")}})),f.$on("change",h=>{f.$$set({shape:h.detail}),i("change",h.detail)}),f.$on("grab",h=>i("grab",h.detail)),f.$on("release",h=>i("release",h.detail)),()=>{f.$destroy()})),e.$$set=h=>{"annotation"in h&&n(0,s=h.annotation),"editor"in h&&n(1,r=h.editor),"style"in h&&n(2,l=h.style),"target"in h&&n(3,a=h.target),"transform"in h&&n(4,u=h.transform),"viewportScale"in h&&n(5,d=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,o=He(s,l,{selected:!0,hovered:!0})),e.$$.dirty&65&&s&&(f==null||f.$set({shape:s.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:u}),e.$$.dirty&96&&f&&f.$set({viewportScale:d}),e.$$.dirty&192&&f&&o&&f.$set({computedStyle:o})},[s,r,l,a,u,d,f,o]}class mo extends ge{constructor(t){super(),he(this,t,Gs,null,re,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function js(e,t,n){const o=Oe();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return Re(()=>{const d=s.closest("svg"),f=[],h=(g,m,p)=>{d==null||d.addEventListener(g,m,p),f.push(()=>d==null?void 0:d.removeEventListener(g,m,p))};return n(5,u=new r({target:s,props:{addEventListener:h,drawingMode:i,transform:l,viewportScale:a}})),u.$on("create",g=>o("create",g.detail)),()=>{f.forEach(g=>g()),u.$destroy()}}),e.$$set=d=>{"drawingMode"in d&&n(0,i=d.drawingMode),"target"in d&&n(1,s=d.target),"tool"in d&&n(2,r=d.tool),"transform"in d&&n(3,l=d.transform),"viewportScale"in d&&n(4,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:l}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[i,s,r,l,a,u]}class po extends ge{constructor(t){super(),he(this,t,js,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function yo(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),u=L("rect"),d=L("rect"),c(o,"class","rect-mask-bg svelte-1a76qe7"),c(o,"x",i=e[1]-e[5]),c(o,"y",s=e[2]-e[5]),c(o,"width",r=e[3]+2*e[5]),c(o,"height",l=e[4]+2*e[5]),c(a,"class","rect-mask-fg svelte-1a76qe7"),c(a,"x",e[1]),c(a,"y",e[2]),c(a,"width",e[3]),c(a,"height",e[4]),c(n,"id",e[6]),c(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),c(u,"class","a9s-outer"),c(u,"mask",`url(#${e[6]})`),c(u,"x",e[1]),c(u,"y",e[2]),c(u,"width",e[3]),c(u,"height",e[4]),c(d,"class","a9s-inner"),c(d,"x",e[1]),c(d,"y",e[2]),c(d,"width",e[3]),c(d,"height",e[4])},m(f,h){N(f,t,h),z(t,n),z(n,o),z(n,a),N(f,u,h),N(f,d,h)},p(f,h){h&34&&i!==(i=f[1]-f[5])&&c(o,"x",i),h&36&&s!==(s=f[2]-f[5])&&c(o,"y",s),h&40&&r!==(r=f[3]+2*f[5])&&c(o,"width",r),h&48&&l!==(l=f[4]+2*f[5])&&c(o,"height",l),h&2&&c(a,"x",f[1]),h&4&&c(a,"y",f[2]),h&8&&c(a,"width",f[3]),h&16&&c(a,"height",f[4]),h&2&&c(u,"x",f[1]),h&4&&c(u,"y",f[2]),h&8&&c(u,"width",f[3]),h&16&&c(u,"height",f[4]),h&2&&c(d,"x",f[1]),h&4&&c(d,"y",f[2]),h&8&&c(d,"width",f[3]),h&16&&c(d,"height",f[4])},d(f){f&&(B(t),B(u),B(d))}}}function Fs(e){let t,n=e[0]&&yo(e);return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){N(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=yo(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&B(t),n&&n.d()}}}function zs(e,t,n){let o;const i=Oe();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,d,f,h,g,m,p;const k=T=>{const C=T;u=performance.now(),r==="drag"&&(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,g=d[1]),n(3,m=1),n(4,p=1))},E=T=>{const C=T;d&&(f=l.elementToImage(C.offsetX,C.offsetY),n(1,h=Math.min(f[0],d[0])),n(2,g=Math.min(f[1],d[1])),n(3,m=Math.abs(f[0]-d[0])),n(4,p=Math.abs(f[1]-d[1])))},S=T=>{const C=T,M=performance.now()-u;if(r==="click"){if(M>300)return;d?w():(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,g=d[1]),n(3,m=1),n(4,p=1))}else d&&(M>300||m*p>100?(C.stopPropagation(),w()):(n(0,d=void 0),f=void 0))},w=()=>{if(m*p>15){const T={type:Q.RECTANGLE,geometry:{bounds:{minX:h,minY:g,maxX:h+m,maxY:g+p},x:h,y:g,w:m,h:p}};i("create",T)}n(0,d=void 0),f=void 0};Re(()=>{s("pointerdown",k),s("pointermove",E),s("pointerup",S,!0)});const A=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=T=>{"addEventListener"in T&&n(7,s=T.addEventListener),"drawingMode"in T&&n(8,r=T.drawingMode),"transform"in T&&n(9,l=T.transform),"viewportScale"in T&&n(10,a=T.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,o=2/a)},[d,h,g,m,p,o,A,s,r,l,a]}class _o extends ge{constructor(t){super(),he(this,t,zs,Fs,re,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function qt(e){const t=e.slice(),n=t[2].map(o=>o.join(",")).join(" ");return t[19]=n,t}function wo(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p=e[1]&&bo(e);return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),d=L("polygon"),h=L("polygon"),p&&p.c(),m=ke(),c(o,"x",i=e[3].x),c(o,"y",s=e[3].y),c(o,"width",r=e[3].w),c(o,"height",l=e[3].h),c(o,"class","svelte-18wrg3t"),c(a,"points",u=e[19]),c(a,"class","svelte-18wrg3t"),c(n,"id",e[5]),c(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),c(d,"class","a9s-outer"),c(d,"mask",`url(#${e[5]})`),c(d,"points",f=e[19]),c(h,"class","a9s-inner"),c(h,"points",g=e[19])},m(k,E){N(k,t,E),z(t,n),z(n,o),z(n,a),N(k,d,E),N(k,h,E),p&&p.m(k,E),N(k,m,E)},p(k,E){E&8&&i!==(i=k[3].x)&&c(o,"x",i),E&8&&s!==(s=k[3].y)&&c(o,"y",s),E&8&&r!==(r=k[3].w)&&c(o,"width",r),E&8&&l!==(l=k[3].h)&&c(o,"height",l),E&4&&u!==(u=k[19])&&c(a,"points",u),E&4&&f!==(f=k[19])&&c(d,"points",f),E&4&&g!==(g=k[19])&&c(h,"points",g),k[1]?p?p.p(k,E):(p=bo(k),p.c(),p.m(m.parentNode,m)):p&&(p.d(1),p=null)},d(k){k&&(B(t),B(d),B(h),B(m)),p&&p.d(k)}}}function bo(e){let t,n,o;return{c(){t=L("circle"),c(t,"class","a9s-handle svelte-18wrg3t"),c(t,"cx",n=e[0][0][0]),c(t,"cy",o=e[0][0][1]),c(t,"r",e[4])},m(i,s){N(i,t,s)},p(i,s){s&1&&n!==(n=i[0][0][0])&&c(t,"cx",n),s&1&&o!==(o=i[0][0][1])&&c(t,"cy",o),s&16&&c(t,"r",i[4])},d(i){i&&B(t)}}}function qs(e){let t,n=e[3]&&wo(qt(e));return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){N(o,t,i),n&&n.m(t,null)},p(o,[i]){o[3]?n?n.p(qt(o),i):(n=wo(qt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&B(t),n&&n.d()}}}const Ks=20,Ws=1500;function Zs(e,t,n){let o,i,s;const r=Oe();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,f,h=[],g,m,p=!1;const k=C=>{const M=C,{timeStamp:V,offsetX:U,offsetY:W}=M;if(f={timeStamp:V,offsetX:U,offsetY:W},a==="drag"&&h.length===0){const q=u.elementToImage(M.offsetX,M.offsetY);h.push(q),n(10,g=q)}},E=C=>{const M=C;if(m&&clearTimeout(m),h.length>0){if(n(10,g=u.elementToImage(M.offsetX,M.offsetY)),h.length>2){const V=tt(g,h[0])*d;n(1,p=V<Ks)}M.pointerType==="touch"&&(m=setTimeout(()=>{w()},Ws))}},S=C=>{const M=C;if(m&&clearTimeout(m),a==="click"){const V=M.timeStamp-f.timeStamp,U=tt([f.offsetX,f.offsetY],[M.offsetX,M.offsetY]);if(V>300||U>15)return;if(p)A();else if(h.length===0){const W=u.elementToImage(M.offsetX,M.offsetY);h.push(W),n(10,g=W)}else g&&h.push(g)}else{if(!g)return;if(h.length===1&&tt(h[0],g)<=4){n(0,h=[]),n(10,g=void 0);return}M.stopImmediatePropagation(),p?A():h.push(g)}},w=()=>{if(!g)return;const C=h.slice(0,-1);if(C.length<3)return;const M={type:Q.POLYGON,geometry:{bounds:fe(h),points:C}};ht(M)>4&&(n(0,h=[]),n(10,g=void 0),r("create",M))},A=()=>{const C={type:Q.POLYGON,geometry:{bounds:fe(h),points:[...h]}};n(0,h=[]),n(10,g=void 0),r("create",C)};Re(()=>{l("pointerdown",k,!0),l("pointermove",E),l("pointerup",S,!0),l("dblclick",w,!0)});const T=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=C=>{"addEventListener"in C&&n(6,l=C.addEventListener),"drawingMode"in C&&n(7,a=C.drawingMode),"transform"in C&&n(8,u=C.transform),"viewportScale"in C&&n(9,d=C.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,o=4/d),e.$$.dirty&1027&&n(2,i=g?p?h:[...h,g]:[]),e.$$.dirty&516&&n(3,s=i.length>0?st(fe(i),2/d):void 0)},[h,p,i,s,o,T,l,a,u,d,g]}class Js extends ge{constructor(t){super(),he(this,t,Zs,qs,re,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Kt=new Map([["rectangle",{tool:_o}],["polygon",{tool:Js}]]),Wt=()=>[...Kt.keys()],Zt=e=>Kt.get(e),Eo=(e,t,n={})=>Kt.set(e,{tool:t,opts:n});function Qs(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("ellipse"),i=L("ellipse"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"cx",e[2]),c(n,"cy",e[3]),c(n,"rx",e[4]),c(n,"ry",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"cx",e[2]),c(i,"cy",e[3]),c(i,"rx",e[4]),c(i,"ry",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function xs(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{cx:l,cy:a,rx:u,ry:d}=s;return e.$$set=f=>{"annotation"in f&&n(0,i=f.annotation),"geom"in f&&n(6,s=f.geom),"style"in f&&n(7,r=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=He(i,r))},[i,o,l,a,u,d,s,r]}class $s extends ge{constructor(t){super(),he(this,t,xs,Qs,re,{annotation:0,geom:6,style:7})}}function er(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("line"),i=L("line"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"x1",e[2]),c(n,"y1",e[3]),c(n,"x2",e[4]),c(n,"y2",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"x1",e[2]),c(i,"y1",e[3]),c(i,"x2",e[4]),c(i,"y2",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function tr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s,[[a,u],[d,f]]=l;return e.$$set=h=>{"annotation"in h&&n(0,i=h.annotation),"geom"in h&&n(6,s=h.geom),"style"in h&&n(7,r=h.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=He(i,r))},[i,o,a,u,d,f,s,r]}class nr extends ge{constructor(t){super(),he(this,t,tr,er,re,{annotation:0,geom:6,style:7})}}function vo(e,t,n){const o=e.slice();return o[5]=t[n],o}function So(e){let t,n,o;return{c(){t=L("path"),o=L("path"),c(t,"class","a9s-outer"),c(t,"style",n=e[1]?"display:none;":void 0),c(t,"fill-rule","evenodd"),c(t,"d",Le(e[5])),c(o,"class","a9s-inner"),c(o,"style",e[1]),c(o,"fill-rule","evenodd"),c(o,"d",Le(e[5]))},m(i,s){N(i,t,s),N(i,o,s)},p(i,s){s&2&&n!==(n=i[1]?"display:none;":void 0)&&c(t,"style",n),s&2&&c(o,"style",i[1])},d(i){i&&(B(t),B(o))}}}function or(e){let t,n,o=ve(e[2]),i=[];for(let s=0;s<o.length;s+=1)i[s]=So(vo(e,o,s));return{c(){t=L("g");for(let s=0;s<i.length;s+=1)i[s].c();c(t,"class","a9s-annotation"),c(t,"data-id",n=e[0].id)},m(s,r){N(s,t,r);for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(t,null)},p(s,[r]){if(r&6){o=ve(s[2]);let l;for(l=0;l<o.length;l+=1){const a=vo(s,o,l);i[l]?i[l].p(a,r):(i[l]=So(a),i[l].c(),i[l].m(t,null))}for(;l<i.length;l+=1)i[l].d(1);i.length=o.length}r&1&&n!==(n=s[0].id)&&c(t,"data-id",n)},i:j,o:j,d(s){s&&B(t),Ye(i,s)}}}function ir(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{polygons:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=He(i,r))},[i,o,l,s,r]}class sr extends ge{constructor(t){super(),he(this,t,ir,or,re,{annotation:0,geom:3,style:4})}}function rr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("polygon"),i=L("polygon"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"points",e[2].map(lr).join(" ")),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"points",e[2].map(ar).join(" ")),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}const lr=e=>e.join(","),ar=e=>e.join(",");function cr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=He(i,r))},[i,o,l,s,r]}class ur extends ge{constructor(t){super(),he(this,t,cr,rr,re,{annotation:0,geom:3,style:4})}}function fr(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("path"),s=L("path"),c(n,"class",o=je(`a9s-outer ${e[1]}`)+" svelte-1w0132l"),c(n,"style",i=e[3]?"display:none;":void 0),c(n,"d",e[2]),c(s,"class",r=je(`a9s-inner ${e[1]}`)+" svelte-1w0132l"),c(s,"style",e[3]),c(s,"d",e[2]),c(t,"class","a9s-annotation"),c(t,"data-id",l=e[0].id)},m(a,u){N(a,t,u),z(t,n),z(t,s)},p(a,[u]){u&2&&o!==(o=je(`a9s-outer ${a[1]}`)+" svelte-1w0132l")&&c(n,"class",o),u&8&&i!==(i=a[3]?"display:none;":void 0)&&c(n,"style",i),u&4&&c(n,"d",a[2]),u&2&&r!==(r=je(`a9s-inner ${a[1]}`)+" svelte-1w0132l")&&c(s,"class",r),u&8&&c(s,"style",a[3]),u&4&&c(s,"d",a[2]),u&1&&l!==(l=a[0].id)&&c(t,"data-id",l)},i:j,o:j,d(a){a&&B(t)}}}function dr(e,t,n){let o,i,s,{annotation:r}=t,{geom:l}=t,{style:a}=t;return e.$$set=u=>{"annotation"in u&&n(0,r=u.annotation),"geom"in u&&n(4,l=u.geom),"style"in u&&n(5,a=u.style)},e.$$.update=()=>{e.$$.dirty&33&&n(3,o=He(r,a)),e.$$.dirty&16&&n(2,i=Ct(l)),e.$$.dirty&16&&n(1,s=l.closed?"closed":"open")},[r,s,i,o,l,a]}class hr extends ge{constructor(t){super(),he(this,t,dr,fr,re,{annotation:0,geom:4,style:5})}}function gr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("rect"),i=L("rect"),c(n,"class","a9s-outer"),c(n,"style",o=e[5]?"display:none;":void 0),c(n,"x",e[4]),c(n,"y",e[3]),c(n,"width",e[2]),c(n,"height",e[1]),c(i,"class","a9s-inner"),c(i,"style",e[5]),c(i,"x",e[4]),c(i,"y",e[3]),c(i,"width",e[2]),c(i,"height",e[1]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&32&&o!==(o=r[5]?"display:none;":void 0)&&c(n,"style",o),l&16&&c(n,"x",r[4]),l&8&&c(n,"y",r[3]),l&4&&c(n,"width",r[2]),l&2&&c(n,"height",r[1]),l&32&&c(i,"style",r[5]),l&16&&c(i,"x",r[4]),l&8&&c(i,"y",r[3]),l&4&&c(i,"width",r[2]),l&2&&c(i,"height",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function mr(e,t,n){let o,i,s,r,l,{annotation:a}=t,{geom:u}=t,{style:d}=t;return e.$$set=f=>{"annotation"in f&&n(0,a=f.annotation),"geom"in f&&n(6,u=f.geom),"style"in f&&n(7,d=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=He(a,d)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:l}=u,i,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,l),n(6,u)))},[a,l,r,s,i,o,u,d]}class pr extends ge{constructor(t){super(),he(this,t,mr,gr,re,{annotation:0,geom:6,style:7})}}const yr={elementToImage:(e,t)=>[e,t]},Ao=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),_r=250,ko=(e,t)=>{const n=Oe();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<_r){const{x:a,y:u}=Jt(r,e),d=Ie?10:2,f=t.getAt(a,u,void 0,d);f?n("click",{originalEvent:r,annotation:f}):n("click",{originalEvent:r})}}}},Jt=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=i+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function Mo(e,t,n){const o=e.slice();return o[39]=t[n],o}function To(e,t,n){const o=e.slice();return o[42]=t[n],o}function Qt(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Po(e){let t=e[42],n,o,i=Lo(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&131072&&re(t,t=s[42])?(be(),G(i,1,1,j),Ee(),i=Lo(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function wr(e){let t,n;return t=new nr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function br(e){let t,n;return t=new hr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Er(e){let t,n;return t=new sr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function vr(e){let t,n;return t=new ur({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Sr(e){let t,n;return t=new pr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ar(e){var o;let t,n;return t=new $s({props:{annotation:e[42],geom:(o=e[45])==null?void 0:o.geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){var l;const r={};s[0]&131072&&(r.annotation=i[42]),s[0]&131072&&(r.geom=(l=i[45])==null?void 0:l.geometry),s[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(R(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function Lo(e){let t,n,o,i;const s=[Ar,Sr,vr,Er,br,wr],r=[];function l(a,u){var d,f,h,g,m,p;return((d=a[45])==null?void 0:d.type)===Q.ELLIPSE?0:((f=a[45])==null?void 0:f.type)===Q.RECTANGLE?1:((h=a[45])==null?void 0:h.type)===Q.POLYGON?2:((g=a[45])==null?void 0:g.type)===Q.MULTIPOLYGON?3:((m=a[45])==null?void 0:m.type)===Q.POLYLINE?4:((p=a[45])==null?void 0:p.type)===Q.LINE?5:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),N(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),R(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(R(n),i=!0)},o(a){G(n),i=!1},d(a){a&&B(o),~t&&r[t].d(a)}}}function Io(e){let t=ot(e[42])&&!e[10](e[42]),n,o,i=t&&Po(Qt(e));return{c(){i&&i.c(),n=ke()},m(s,r){i&&i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&132096&&(t=ot(s[42])&&!s[10](s[42])),t?i?(i.p(Qt(s),r),r[0]&132096&&R(i,1)):(i=Po(Qt(s)),i.c(),R(i,1),i.m(n.parentNode,n)):i&&(be(),G(i,1,1,()=>{i=null}),Ee())},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i&&i.d(s)}}}function Co(e){let t,n,o,i;const s=[Mr,kr],r=[];function l(a,u){return a[6]?0:a[15]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),N(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),R(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(R(n),i=!0)},o(a){G(n),i=!1},d(a){a&&B(o),~t&&r[t].d(a)}}}function kr(e){let t=`${e[2]}-${e[7]}`,n,o,i=Oo(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&132&&re(t,t=`${s[2]}-${s[7]}`)?(be(),G(i,1,1,j),Ee(),i=Oo(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function Mr(e){let t,n,o=ve(e[6]),i=[];for(let r=0;r<o.length;r+=1)i[r]=Bo(Mo(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);N(r,t,l),n=!0},p(r,l){if(l[0]&8659266){o=ve(r[6]);let a;for(a=0;a<o.length;a+=1){const u=Mo(r,o,a);i[a]?(i[a].p(u,l),R(i[a],1)):(i[a]=Bo(u),i[a].c(),R(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)R(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&B(t),Ye(i,r)}}}function Oo(e){let t,n;return t=new po({props:{target:e[8],tool:e[15],drawingMode:e[14],transform:e[13],viewportScale:e[18]}}),t.$on("create",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&256&&(s.target=o[8]),i[0]&32768&&(s.tool=o[15]),i[0]&16384&&(s.drawingMode=o[14]),i[0]&8192&&(s.transform=o[13]),i[0]&262144&&(s.viewportScale=o[18]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Do(e){let t,n;return t=new mo({props:{target:e[8],editor:e[39].editor,annotation:e[39].annotation,style:e[1],transform:e[13],viewportScale:e[18]}}),t.$on("change",function(){ie(e[23](e[39].annotation))&&e[23](e[39].annotation).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&256&&(s.target=e[8]),i[0]&64&&(s.editor=e[39].editor),i[0]&64&&(s.annotation=e[39].annotation),i[0]&2&&(s.style=e[1]),i[0]&8192&&(s.transform=e[13]),i[0]&262144&&(s.viewportScale=e[18]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Bo(e){let t=e[39].annotation.id,n,o,i=Do(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&64&&re(t,t=s[39].annotation.id)?(be(),G(i,1,1,j),Ee(),i=Do(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function Tr(e){let t,n,o,i,s,r,l=ve(e[17].filter(e[34])),a=[];for(let f=0;f<l.length;f+=1)a[f]=Io(To(e,l,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&Co(e);return{c(){t=L("svg"),n=L("g");for(let f=0;f<a.length;f+=1)a[f].c();o=L("g"),d&&d.c(),c(o,"class","drawing"),c(t,"role","application"),c(t,"tabindex",0),c(t,"class","a9s-annotationlayer"),Pe(t,"drawing",e[15]),Pe(t,"editing",e[5]),Pe(t,"hidden",!e[3]),Pe(t,"hover",e[16])},m(f,h){N(f,t,h),z(t,n);for(let g=0;g<a.length;g+=1)a[g]&&a[g].m(n,null);z(t,o),d&&d.m(o,null),e[35](o),e[36](t),i=!0,s||(r=[J(t,"pointerup",function(){ie(e[11])&&e[11].apply(this,arguments)}),J(t,"pointerdown",function(){ie(e[12])&&e[12].apply(this,arguments)}),J(t,"pointermove",e[24])],s=!0)},p(f,h){if(e=f,h[0]&132098){l=ve(e[17].filter(e[34]));let g;for(g=0;g<l.length;g+=1){const m=To(e,l,g);a[g]?(a[g].p(m,h),R(a[g],1)):(a[g]=Io(m),a[g].c(),R(a[g],1),a[g].m(n,null))}for(be(),g=l.length;g<a.length;g+=1)u(g);Ee()}e[8]?d?(d.p(e,h),h[0]&256&&R(d,1)):(d=Co(e),d.c(),R(d,1),d.m(o,null)):d&&(be(),G(d,1,1,()=>{d=null}),Ee()),(!i||h[0]&32768)&&Pe(t,"drawing",e[15]),(!i||h[0]&32)&&Pe(t,"editing",e[5]),(!i||h[0]&8)&&Pe(t,"hidden",!e[3]),(!i||h[0]&65536)&&Pe(t,"hover",e[16])},i(f){if(!i){for(let h=0;h<l.length;h+=1)R(a[h]);R(d),i=!0}},o(f){a=a.filter(Boolean);for(let h=0;h<a.length;h+=1)G(a[h]);G(d),i=!1},d(f){f&&B(t),Ye(a,f),d&&d.d(),e[35](null),e[36](null),s=!1,Ae(r)}}}function Pr(e,t,n){let o,i,s,r,l,a,u,d,f,h,g,m,p=j,k=()=>(p(),p=an(_,X=>n(18,m=X)),_);e.$$.on_destroy.push(()=>p());let{drawingEnabled:E}=t,{image:S}=t,{preferredDrawingMode:w}=t,{state:A}=t,{style:T=void 0}=t,{toolName:C=Wt()[0]}=t,{user:M}=t,{visible:V=!0}=t,U=0;const W=()=>n(7,U+=1),q=()=>C,v=()=>E;let b,y,_;Re(()=>k(n(9,_=Gn(S,y))));const{hover:I,selection:P,store:D}=A;kt(e,I,X=>n(16,f=X)),kt(e,P,X=>n(33,h=X)),kt(e,D,X=>n(17,g=X));let F,H;const x=X=>{F&&D.unobserve(F);const de=X.filter(({editable:te})=>te).map(({id:te})=>te);de.length>0?(n(5,H=de.map(te=>D.getAnnotation(te)).filter(te=>te&&ot(te))),F=te=>{const{updated:ye}=te.changes;n(5,H=ye==null?void 0:ye.map(_e=>_e.newValue))},D.observe(F,{annotations:de})):n(5,H=void 0)},Z=X=>{const de=Bn(),te={id:de,bodies:[],target:{annotation:de,selector:X.detail,creator:M,created:new Date}};D.addAnnotation(te),P.setSelected(te.id)},$=X=>de=>{var Je;const{target:te}=X,ye=10*60*1e3,_e=((Je=te.creator)==null?void 0:Je.id)!==M.id||!te.created||new Date().getTime()-te.created.getTime()>ye;D.updateTarget({...te,selector:de.detail,created:_e?te.created:new Date,updated:_e?new Date:void 0,updatedBy:_e?M:void 0})},oe=X=>{const{x:de,y:te}=Jt(X,y),ye=D.getAt(de,te,void 0,2);ye?f!==ye.id&&I.set(ye.id):I.set(void 0)},se=X=>ot(X);function Se(X){ft[X?"unshift":"push"](()=>{b=X,n(8,b)})}function Te(X){ft[X?"unshift":"push"](()=>{y=X,n(4,y)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,E=X.drawingEnabled),"image"in X&&n(25,S=X.image),"preferredDrawingMode"in X&&n(26,w=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,T=X.style),"toolName"in X&&n(2,C=X.toolName),"user"in X&&n(28,M=X.user),"visible"in X&&n(3,V=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:o,opts:i}=Zt(C)||{tool:void 0,opts:void 0},o,(n(32,i),n(2,C))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(14,s=(i==null?void 0:i.drawingMode)||w),e.$$.dirty[0]&16&&n(13,r=Ao(y)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=ko(y,D),l,(n(11,a),n(4,y))),e.$$.dirty[1]&4&&x(h.selected),e.$$.dirty[0]&32&&n(6,u=H?H.map(X=>({annotation:X,editor:ho(X.target.selector)})).filter(X=>X.editor):void 0),e.$$.dirty[0]&64&&n(10,d=X=>u&&u.some(de=>de.annotation.id===X.id))},[E,T,C,V,y,H,u,U,b,_,d,a,l,r,s,o,f,g,m,I,P,D,Z,$,oe,S,w,A,M,W,q,v,i,h,se,Se,Te]}class No extends ge{constructor(t){super(),he(this,t,Pr,Tr,re,{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 Uo(e,t,n=0,o=e.length-1,i=Lr){for(;o>n;){if(o-n>600){const a=o-n+1,u=t-n+1,d=Math.log(a),f=.5*Math.exp(2*d/3),h=.5*Math.sqrt(d*f*(a-f)/a)*(u-a/2<0?-1:1),g=Math.max(n,Math.floor(t-u*f/a+h)),m=Math.min(o,Math.floor(t+(a-u)*f/a+h));Uo(e,t,g,m,i)}const s=e[t];let r=n,l=o;for(at(e,n,t),i(e[o],s)>0&&at(e,n,o);r<l;){for(at(e,r,l),r++,l--;i(e[r],s)<0;)r++;for(;i(e[l],s)>0;)l--}i(e[n],s)===0?at(e,n,l):(l++,at(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function at(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Lr(e,t){return e<t?-1:e>t?1:0}class Ir{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!bt(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?i(l):l;bt(t,a)&&(n.leaf?o.push(l):$t(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!bt(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(bt(t,r)){if(n.leaf||$t(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Ze([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let l,a,u;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],l=r.pop(),u=!0),o.leaf){const d=Cr(t,o.children,n);if(d!==-1)return o.children.splice(d,1),s.push(o),this._condense(s),this}!u&&!o.leaf&&$t(o,i)?(s.push(o),r.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],u=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,l;if(s<=r)return l=Ze(t.slice(n,o+1)),We(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=Ze([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));Yo(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);Yo(t,d,f,a,this.compareMinY);for(let h=d;h<=f;h+=a){const g=Math.min(h+a-1,f);l.children.push(this._build(t,h,g,i-1))}}return We(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const u=n.children[a],d=xt(u),f=Br(t,u)-d;f<r?(r=f,s=d<s?d:s,l=u):f===r&&d<s&&(s=d,l=u)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),ut(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),l=Ze(o.children.splice(r,o.children.length-r));l.height=o.height,l.leaf=o.leaf,We(o,this.toBBox),We(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=Ze([t,n]),this.data.height=t.height+1,this.data.leaf=!1,We(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let l=n;l<=o-n;l++){const a=ct(t,0,l,this.toBBox),u=ct(t,l,o,this.toBBox),d=Nr(a,u),f=xt(a)+xt(u);d<s?(s=d,i=l,r=f<r?f:r):d===s&&f<r&&(r=f,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Or,s=t.leaf?this.compareMinY:Dr,r=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,s);r<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=ct(t,0,n,s),l=ct(t,o-n,o,s);let a=wt(r)+wt(l);for(let u=n;u<o-n;u++){const d=t.children[u];ut(r,t.leaf?s(d):d),a+=wt(r)}for(let u=o-n-1;u>=n;u--){const d=t.children[u];ut(l,t.leaf?s(d):d),a+=wt(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)ut(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():We(t[n],this.toBBox)}}function Cr(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function We(e,t){ct(e,0,e.children.length,t,e)}function ct(e,t,n,o,i){i||(i=Ze(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];ut(i,e.leaf?o(r):r)}return i}function ut(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Or(e,t){return e.minX-t.minX}function Dr(e,t){return e.minY-t.minY}function xt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function wt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Br(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Nr(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function $t(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function bt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ze(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Yo(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;Uo(e,r,t,n,i),s.push(t,r,r,n)}}const Ur=()=>{const e=new Ir,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!it(f))return;const{minX:h,minY:g,maxX:m,maxY:p}=f.selector.geometry.bounds,k={minX:h,minY:g,maxX:m,maxY:p,target:f};e.insert(k),t.set(f.annotation,k)},s=f=>{if(!it(f))return;const h=t.get(f.annotation);h&&e.remove(h),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,h,g=0)=>{const p=e.search({minX:f-g,minY:h-g,maxX:f+g,maxY:h+g}).map(k=>k.target).filter(k=>k.selector.type===Q.RECTANGLE||wn(k.selector,f,h,g));return p.length>0?(p.sort((k,E)=>ht(k.selector)-ht(E.selector)),p):[]},getIntersecting:(f,h,g,m)=>e.search({minX:f,minY:h,maxX:f+g,maxY:h+m}).map(p=>p.target),insert:i,remove:s,set:(f,h=!0)=>{h&&o();const g=f.reduce((m,p)=>{if(it(p)){const{minX:k,minY:E,maxX:S,maxY:w}=p.selector.geometry.bounds;return[...m,{minX:k,minY:E,maxX:S,maxY:w,target:p}]}else return m},[]);g.forEach(m=>t.set(m.target.annotation,m)),e.load(g)},size:()=>e.all().length,update:(f,h)=>{s(f),i(h)}}},Ro=e=>({...e,subscribe:n=>{const o=i=>n(i.state);return e.observe(o),n(e.all()),()=>e.unobserve(o)}}),Vo=e=>{const t=Fi(),n=Ur(),o=Li(t,e.userSelectAction,e.adapter),i=Pi(t),s=Wi();return t.observe(({changes:a})=>{n.set((a.created||[]).map(u=>u.target),!1),(a.deleted||[]).forEach(u=>n.remove(u.target)),(a.updated||[]).forEach(({oldValue:u,newValue:d})=>n.update(u.target,d.target))}),{store:{...t,getAt:(a,u,d,f)=>{const h=n.getAt(a,u,f);if(d)return h.map(m=>t.getAnnotation(m.annotation)).filter(Boolean).filter(d)[0];{const g=h[0];return g?t.getAnnotation(g.annotation):void 0}},getIntersecting:(a,u,d,f)=>n.getIntersecting(a,u,d,f).map(h=>t.getAnnotation(h.annotation)).filter(Boolean)},selection:o,hover:i,viewport:s}},Xo=e=>{const t=Vo(e);return{...t,store:Ro(t.store)}},Ho=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(r,l,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=u}return o/81},Go=e=>{const t=Ho(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},en=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Go(e):n),jo=(e,t)=>({...e,drawingEnabled:e.drawingEnabled===void 0?t.drawingEnabled:e.drawingEnabled,drawingMode:e.drawingMode||t.drawingMode,userSelectAction:e.userSelectAction||t.userSelectAction,theme:e.theme||t.theme}),tn=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Fo=(e,t)=>{const n=t||document,o=r=>{const l=r;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},i=r=>{const l=r;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},s=()=>{tn?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return tn?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Yr=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=jo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Bt.EDIT,theme:"light"}),i=Xo(o),{selection:s,store:r}=i,l=Ki(r,o.initialHistory),a=Zi(i,l,o.adapter,o.autoSave),u=document.createElement("DIV");u.style.position="relative",u.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(u,n),u.appendChild(n);const d=Fo(l);let f=ss();en(n,u,o.theme);const h=new No({target:u,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});h.$on("click",b=>{const{originalEvent:y,annotation:_}=b.detail;_?s.userSelect(_.id,y):s.isEmpty()||s.clear()});const g=Qi(i,l,o.adapter),m=()=>h.cancelDrawing(),p=()=>{h.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),l.destroy()},k=()=>h.getDrawingTool(),E=()=>f,S=()=>h.isDrawingEnabled(),w=(b,y,_)=>Eo(b,y,_),A=(b,y)=>go(b,y),T=b=>{if(!Zt(b))throw`No drawing tool named ${b}`;h.$set({toolName:b})},C=b=>h.$set({drawingEnabled:b}),M=b=>h.$set({preferredDrawingMode:b}),V=b=>{console.warn("Filter not implemented yet")},U=b=>h.$set({style:b}),W=b=>en(n,u,b),q=b=>{f=b,h.$set({user:b})},v=b=>h.$set({visible:b});return{...g,cancelDrawing:m,destroy:p,getDrawingTool:k,getUser:E,isDrawingEnabled:S,listDrawingTools:Wt,on:a.on,off:a.off,registerDrawingTool:w,registerShapeEditor:A,setDrawingEnabled:C,setDrawingMode:M,setDrawingTool:T,setFilter:V,setStyle:U,setTheme:W,setUser:q,setVisible:v,element:u,state:i}};O.Editor=_t,O.EditorMount=mo,O.Handle=Ge,O.IdentityTransform=yr,O.MidpointHandle=Rt,O.PolygonEditor=$n,O.RectangleEditor=eo,O.RectangleUtil=An,O.RubberbandRectangle=_o,O.SVGAnnotationLayer=No,O.ShapeType=Q,O.ToolMount=po,O.UserSelectAction=Bt,O.W3CImageFormat=fs,O.addEventListeners=ko,O.approximateAsPolygon=gt,O.boundsFromMultiPolygonElements=nt,O.boundsFromPoints=fe,O.chainStyles=$i,O.computeArea=ht,O.computePolygonArea=$e,O.computeSVGPath=Ct,O.computeStyle=xi,O.createBody=Ui,O.createImageAnnotator=Yr,O.createImageAnnotatorState=Vo,O.createSVGTransform=Ao,O.createSvelteImageAnnotatorState=Xo,O.defaultColorProvider=us,O.detectTheme=Go,O.distance=tt,O.enableResponsive=Gn,O.fillDefaults=jo,O.getAllCorners=En,O.getEditor=ho,O.getMaskDimensions=st,O.getSVGPoint=Jt,O.getTool=Zt,O.initKeyboardCommands=Fo,O.intersects=wn,O.isFragmentSelector=kn,O.isImageAnnotation=ot,O.isImageAnnotationTarget=it,O.isMac=tn,O.isPointInPolygon=et,O.isTouch=Ie,O.listDrawingTools=Wt,O.multipolygonElementToPath=Le,O.parseFragmentSelector=Mn,O.parseSVGSelector=Cn,O.parseW3CImageAnnotation=Xn,O.pointsToPath=bn,O.registerEditor=go,O.registerShapeUtil=Xe,O.registerTool=Eo,O.sampleBrightness=Ho,O.serializeFragmentSelector=Tn,O.serializeSVGSelector=On,O.serializeW3CImageAnnotation=Hn,O.setTheme=en,O.simplifyMultiPolygon=ci,O.simplifyPoints=It,O.simplifyPolygon=fi,O.toSvelteStore=Ro,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=annotorious.js.map