@annotorious/annotorious 3.7.11 → 3.7.13
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.
- package/dist/annotorious.es.js +1561 -1542
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +1 -1
- package/dist/annotorious.js.map +1 -1
- package/dist/state/ImageAnnotationStore.d.ts +2 -1
- package/dist/state/SvelteStore.d.ts +20 -0
- package/dist/state/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/state/ImageAnnotationStore.ts +2 -1
- package/src/state/ImageAnnotatorState.ts +1 -1
- package/src/state/SvelteStore.ts +52 -0
- package/src/state/index.ts +2 -1
package/dist/annotorious.js
CHANGED
|
@@ -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 Yr=Object.defineProperty;var Br=(O,j,Ie)=>j in O?Yr(O,j,{enumerable:!0,configurable:!0,writable:!0,value:Ie}):O[j]=Ie;var on=(O,j,Ie)=>Br(O,typeof j!="symbol"?j+"":j,Ie);function j(){}function Ie(e,t){for(const n in t)e[n]=t[n];return e}function sn(e){return e()}function rn(){return Object.create(null)}function Ae(e){e.forEach(sn)}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 jo(e){return Object.keys(e).length===0}function ln(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 At(e,t,n){e.$$.on_destroy.push(ln(t,n))}function zo(e,t,n,o){if(e){const i=an(e,t,n,o);return e[0](i)}}function an(e,t,n,o){return e[1]&&o?Ie(n.ctx.slice(),e[1](o(t))):n.ctx}function Fo(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 qo(e,t,n,o,i,s){if(i){const r=an(t,n,o,s);e.p(r,i)}}function Ko(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 cn(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function He(e){return e??""}function F(e,t){e.appendChild(t)}function N(e,t,n){e.insertBefore(t,n||null)}function R(e){e.parentNode&&e.parentNode.removeChild(e)}function Ne(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 un(e){return document.createTextNode(e)}function we(){return un(" ")}function ke(){return un("")}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 Wo(e){return Array.from(e.childNodes)}function Te(e,t,n){e.classList.toggle(t,!!n)}function Zo(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Je;function Qe(e){Je=e}function fn(){if(!Je)throw new Error("Function called outside component initialization");return Je}function Ue(e){fn().$$.on_mount.push(e)}function Ce(){const e=fn();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Zo(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 Ge=[],ut=[];let je=[];const dn=[],hn=Promise.resolve();let kt=!1;function gn(){kt||(kt=!0,hn.then(pn))}function mn(){return gn(),hn}function Mt(e){je.push(e)}const Tt=new Set;let ze=0;function pn(){if(ze!==0)return;const e=Je;do{try{for(;ze<Ge.length;){const t=Ge[ze];ze++,Qe(t),Jo(t.$$)}}catch(t){throw Ge.length=0,ze=0,t}for(Qe(null),Ge.length=0,ze=0;ut.length;)ut.pop()();for(let t=0;t<je.length;t+=1){const n=je[t];Tt.has(n)||(Tt.add(n),n())}je.length=0}while(Ge.length);for(;dn.length;)dn.pop()();kt=!1,Tt.clear(),Qe(e)}function Jo(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(Mt)}}function Qo(e){const t=[],n=[];je.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),je=t}const ft=new Set;let Ye;function be(){Ye={r:0,c:[],p:Ye}}function Ee(){Ye.r||Ae(Ye.c),Ye=Ye.p}function B(e,t){e&&e.i&&(ft.delete(e),e.i(t))}function G(e,t,n,o){if(e&&e.o){if(ft.has(e))return;ft.add(e),Ye.c.push(()=>{ft.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),Mt(()=>{const s=e.$$.on_mount.map(sn).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ae(s),e.$$.on_mount=[]}),i.forEach(Mt)}function ae(e,t){const n=e.$$;n.fragment!==null&&(Qo(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function xo(e,t){e.$$.dirty[0]===-1&&(Ge.push(e),gn(),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=Je;Qe(e);const u=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:i,bound:rn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:rn(),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,...p)=>{const m=p.length?p[0]:h;return u.ctx&&i(u.ctx[f],u.ctx[f]=m)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](m),d&&xo(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=Wo(t.target);u.fragment&&u.fragment.l(f),f.forEach(R)}else u.fragment&&u.fragment.c();t.intro&&B(e.$$.fragment),le(e,t.target,t.anchor),pn()}Qe(a)}class ge{constructor(){on(this,"$$");on(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&&!jo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $o="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($o);var Q=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(Q||{});function ei(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var yn={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,p=u.y-f;if(h!==0||p!==0){var m=((l.x-d)*h+(l.y-f)*p)/(h*h+p*p);m>1?(d=u.x,f=u.y):m>0&&(d+=h*m,f+=p*m)}return h=l.x-d,p=l.y-f,h*h+p*p}function o(l,a){for(var u=l[0],d=[u],f,h=1,p=l.length;h<p;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,p,m=a+1;m<u;m++){var g=n(l[m],l[a],l[u]);g>h&&(p=m,h=g)}h>d&&(p-a>1&&i(l,a,p,d,f),f.push(l[p]),u-p>1&&i(l,p,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})()})(yn);var ti=yn.exports;const ni=ei(ti),Pt={},Be=(e,t)=>Pt[e]=t,dt=e=>Pt[e.type].area(e),_n=(e,t,n,o)=>Pt[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}},xe=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)},$e=(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},wn=(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},Lt=(e,t=1)=>{const n=e.map(([o,i])=>({x:o,y:i}));return ni(n,t,!0).map(o=>[o.x,o.y])},et=(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))},oi={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,p=u*d-a*f;return h*h/(s*s)+p*p/(r*r)<=1}};Be(Q.ELLIPSE,oi);const ii={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=et([i,s],[r,l]);return a/u<=o}};Be(Q.LINE,ii);const si={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,o)=>{const[i,...s]=o.rings,r=xe(i.points),l=s.reduce((a,u)=>a+xe(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($e(s.points,t,n)){let l=!1;for(const a of r)if($e(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},tt=e=>{const t=e.reduce((n,o)=>[...n,...o.rings[0].points],[]);return fe(t)},Pe=e=>e.rings.map(n=>wn(n.points)).join(" "),bn=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((o,i)=>[...o,...i.points],[])],[]),ri=(e,t=1)=>{const n=e.geometry.polygons.map(i=>{const s=i.rings.map(l=>{const a=Lt(l.points,t);return{...l,points:a}}),r=fe(s[0].points);return{...i,rings:s,bounds:r}}),o=tt(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:o}}};Be(Q.MULTIPOLYGON,si);const li={area:e=>{const t=e.geometry.points;return xe(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return $e(o,t,n)}},ai=(e,t=1)=>{const n=Lt(e.geometry.points,t),o=fe(n);return{...e,geometry:{...e.geometry,bounds:o,points:n}}};Be(Q.POLYGON,li);const ci={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=ht(t.points,t.closed);return xe(n)},intersects:(e,t,n,o=2)=>{const i=e.geometry;if(i.closed){const s=ht(i.points,i.closed);return $e(s,t,n)}else return ui(i,[t,n],o)}},ht=(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=En(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},En=(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},ui=(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=En(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(vn(t,l[a],l[a+1])<=n)return!0}else if(vn(t,i.point,s.point)<=n)return!0}return!1},vn=(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},It=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(" ")};Be(Q.POLYLINE,ci);const Sn={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};Be(Q.RECTANGLE,Sn);const nt=e=>ot(e.target),ot=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},An=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[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,p,m,g]=[a,u,d,f].map(parseFloat);return{type:Q.RECTANGLE,geometry:{x:h,y:p,w:m,h:g,bounds:{minX:h,minY:t?p-g:p,maxX:h+m,maxY:t?p:p+g}}}},kn=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}`}},Mn="http://www.w3.org/2000/svg",Tn=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},fi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Mn}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},gt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Mn),i=n.lookupNamespaceURI(null);return o||i?Tn(n).firstChild:Tn(fi(n)).firstChild},di=e=>{const t=Pn(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}}},hi=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},gi=e=>{const t=Pn(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=>hi(r)?{...r,locked:!0}:r);const s=fe(ht(n,i));return{points:n,closed:i,bounds:s}},Pn=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},mi=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)}}},pi=e=>{const t=gt(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}}},yi=e=>{const t=gt(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}}},_i=e=>{const t=gt(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=gi(o);if(!i)throw new Error("Could not parse SVG path");return{type:Q.POLYLINE,geometry:i}},wi=e=>{const t=gt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>di(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}}},Ln=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return mi(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return _i(t);if(t.includes("<path "))return wi(t);if(t.includes("<ellipse "))return pi(t);if(t.includes("<line "))return yi(t);throw"Unsupported SVG shape: "+t},bi=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Pe(n)}" />`).join("")}</g>`,In=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>${bi(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="${It(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 Ei(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 Ct;const vi=new Uint8Array(16);function Si(){if(!Ct){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ct=crypto.getRandomValues.bind(crypto)}return Ct(vi)}const Cn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ai(e,t,n){var i;e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Si();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,Ei(o)}function On(e,t,n){return Cn.randomUUID&&!e?Cn.randomUUID():Ai(e)}var Dn=Object.prototype.hasOwnProperty;function Oe(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--&&Oe(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Dn.call(e,n)&&++o&&!Dn.call(t,n)||!(n in t)||!Oe(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function Ot(){}function ki(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const Fe=[];function Dt(e,t=Ot){let n;const o=new Set;function i(l){if(ki(e,l)&&(e=l,n)){const a=!Fe.length;for(const u of o)u[1](),Fe.push(u,e);if(a){for(let u=0;u<Fe.length;u+=2)Fe[u][0](Fe[u+1]);Fe.length=0}}}function s(l){i(l(e))}function r(l,a=Ot){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||Ot),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Mi=e=>{const{subscribe:t,set:n}=Dt();let o;return t(i=>o=i),e.observe(({changes:i})=>{if(o){(i.deleted||[]).some(r=>r.id===o)&&n(void 0);const s=(i.updated||[]).find(({oldValue:r})=>r.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Rt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Rt||{});const mt={selected:[]},Ti=(e,t,n)=>{const{subscribe:o,set:i}=Dt(mt);let s=t,r=mt;o(g=>r=g);const l=()=>{Oe(r,mt)||i(mt)},a=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},u=g=>{if(a())return!1;const k=typeof g=="string"?g:g.id;return r.selected.some(E=>E.id===k)},d=(g,k)=>{let E;if(Array.isArray(g)){if(E=g.map(_=>e.getAnnotation(_)).filter(Boolean),E.length<g.length){console.warn("Invalid selection: "+g.filter(_=>!E.some(A=>A.id===_)));return}}else{const _=e.getAnnotation(g);if(!_){console.warn("Invalid selection: "+g);return}E=[_]}const S=E.reduce((_,A)=>{const M=m(A);return M==="EDIT"?[..._,{id:A.id,editable:!0}]:M==="SELECT"?[..._,{id:A.id}]:_},[]);i({selected:S,event:k})},f=(g,k)=>{const E=Array.isArray(g)?g:[g],S=E.map(_=>e.getAnnotation(_)).filter(_=>!!_);i({selected:S.map(_=>{const A=k===void 0?m(_)==="EDIT":k;return{id:_.id,editable:A}})}),S.length!==E.length&&console.warn("Invalid selection",g)},h=g=>{if(a())return!1;const{selected:k}=r;k.some(({id:E})=>g.includes(E))&&i({selected:k.filter(({id:E})=>!g.includes(E))})},p=g=>{s=g,f(r.selected.map(({id:k})=>k))},m=g=>Pi(g,s,n);return e.observe(({changes:g})=>h((g.deleted||[]).map(k=>k.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:l,evalSelectAction:m,isEmpty:a,isSelected:u,setSelected:f,setUserSelectAction:p,subscribe:o,userSelect:d}},Pi=(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 Li(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 Nt;const Ii=new Uint8Array(16);function Ci(){if(!Nt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Nt=crypto.getRandomValues.bind(crypto)}return Nt(Ii)}const Oi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Rn={randomUUID:Oi};function Di(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Ci();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,Li(i)}function Nn(e,t,n){return Rn.randomUUID&&!e?Rn.randomUUID():Di(e)}const Ut=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)}},Ri=(e,t,n,o)=>({id:Nn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Ni=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Ui=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Yi=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!Oe(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Bi=(e,t)=>!Oe(e.target,t.target),Un=(e,t)=>{const n=Ni(e,t),o=Ui(e,t),i=Yi(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:Bi(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 Vi=(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},Xi=(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:p}=f;if(r.has(p.id)){const m=t.updated.find(g=>g.oldValue.id===p.id).newValue;return Un(h,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:u,updated:d}},pt=e=>{const t=e.id===void 0?Nn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},Hi=e=>e.id!==void 0,Gi=()=>{const e=new Map,t=new Map,n=[],o=(w,v={})=>{n.push({onChange:w,options:v})},i=w=>{const v=n.findIndex(y=>y.onChange==w);v>-1&&n.splice(v,1)},s=(w,v)=>{const y={origin:w,changes:{created:v.created||[],updated:v.updated||[],deleted:v.deleted||[]},state:[...e.values()]};n.forEach(b=>{Vi(b,y)&&b.onChange(y)})},r=(w,v=ne.LOCAL)=>{if(w.id&&e.get(w.id))throw Error(`Cannot add annotation ${w.id} - exists already`);{const y=pt(w);e.set(y.id,y),y.bodies.forEach(b=>t.set(b.id,y.id)),s(v,{created:[y]})}},l=(w,v)=>{const y=pt(typeof w=="string"?v:w),b=typeof w=="string"?w:w.id,I=b&&e.get(b);if(I){const P=Un(I,y);return b===y.id?e.set(b,y):(e.delete(b),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 ${b} - does not exist`)},a=(w,v=ne.LOCAL,y=ne.LOCAL)=>{const b=Hi(v)?y:v,I=l(w,v);I&&s(b,{updated:[I]})},u=(w,v=ne.LOCAL)=>{e.get(w.id)?a(w,v):r(w,v)},d=(w,v=ne.LOCAL)=>{const y=w.reduce((b,I)=>{const P=l(I);return P?[...b,P]:b},[]);y.length>0&&s(v,{updated:y})},f=(w,v=ne.LOCAL)=>{const y=w.map(pt),{toAdd:b,toUpdate:I}=y.reduce((D,z)=>e.get(z.id)?{...D,toUpdate:[...D.toUpdate,z]}:{...D,toAdd:[...D.toAdd,z]},{toAdd:[],toUpdate:[]}),P=I.map(D=>l(D,v)).filter(Boolean);b.forEach(D=>{e.set(D.id,D),D.bodies.forEach(z=>t.set(z.id,D.id))}),s(v,{created:b,updated:P})},h=(w,v=ne.LOCAL)=>{const y=e.get(w.annotation);if(y){const b={...y,bodies:[...y.bodies,w]};e.set(y.id,b),t.set(w.id,b.id),s(v,{updated:[{oldValue:y,newValue:b,bodiesCreated:[w]}]})}else console.warn(`Attempt to add body to missing annotation: ${w.annotation}`)},p=()=>[...e.values()],m=(w=ne.LOCAL)=>{const v=[...e.values()];e.clear(),t.clear(),s(w,{deleted:v})},g=(w,v=!0,y=ne.LOCAL)=>{const b=w.map(pt);if(v){const I=[...e.values()];e.clear(),t.clear(),b.forEach(P=>{e.set(P.id,P),P.bodies.forEach(D=>t.set(D.id,P.id))}),s(y,{created:b,deleted:I})}else{const I=w.reduce((P,D)=>{const z=D.id&&e.get(D.id);return z?[...P,z]:P},[]);if(I.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${I.map(P=>P.id).join(", ")}`);b.forEach(P=>{e.set(P.id,P),P.bodies.forEach(D=>t.set(D.id,P.id))}),s(y,{created:b})}},k=w=>{const v=typeof w=="string"?w:w.id,y=e.get(v);if(y)return e.delete(v),y.bodies.forEach(b=>t.delete(b.id)),y;console.warn(`Attempt to delete missing annotation: ${v}`)},E=(w,v=ne.LOCAL)=>{const y=k(w);y&&s(v,{deleted:[y]})},S=(w,v=ne.LOCAL)=>{const y=w.reduce((b,I)=>{const P=k(I);return P?[...b,P]:b},[]);y.length>0&&s(v,{deleted:y})},_=w=>{const v=e.get(w.annotation);if(v){const y=v.bodies.find(b=>b.id===w.id);if(y){t.delete(y.id);const b={...v,bodies:v.bodies.filter(I=>I.id!==w.id)};return e.set(v.id,b),{oldValue:v,newValue:b,bodiesDeleted:[y]}}else console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${w.annotation}`)},A=(w,v=ne.LOCAL)=>{const y=_(w);y&&s(v,{updated:[y]})},M=(w,v=ne.LOCAL)=>{const y=w.map(b=>_(b)).filter(Boolean);y.length>0&&s(v,{updated:y})},C=w=>{const v=e.get(w);return v?{...v}:void 0},T=w=>{const v=t.get(w);if(v){const y=C(v).bodies.find(b=>b.id===w);if(y)return y;console.error(`Store integrity error: body ${w} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${w}`)},V=(w,v)=>{if(w.annotation!==v.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const y=e.get(w.annotation);if(y){const b=y.bodies.find(P=>P.id===w.id),I={...y,bodies:y.bodies.map(P=>P.id===b.id?v:P)};return e.set(y.id,I),b.id!==v.id&&(t.delete(b.id),t.set(v.id,I.id)),{oldValue:y,newValue:I,bodiesUpdated:[{oldBody:b,newBody:v}]}}else console.warn(`Attempt to add body to missing annotation ${w.annotation}`)},U=(w,v,y=ne.LOCAL)=>{const b=V(w,v);b&&s(y,{updated:[b]})},W=(w,v=ne.LOCAL)=>{const y=w.map(b=>V({id:b.id,annotation:b.annotation},b)).filter(Boolean);s(v,{updated:y})},q=w=>{const v=e.get(w.annotation);if(v){const y={...v,target:{...v.target,...w}};return e.set(v.id,y),{oldValue:v,newValue:y,targetUpdated:{oldTarget:v.target,newTarget:w}}}else console.warn(`Attempt to update target on missing annotation: ${w.annotation}`)};return{addAnnotation:r,addBody:h,all:p,bulkAddAnnotations:g,bulkDeleteAnnotations:S,bulkDeleteBodies:M,bulkUpdateAnnotations:d,bulkUpdateBodies:W,bulkUpdateTargets:(w,v=ne.LOCAL)=>{const y=w.map(b=>q(b)).filter(Boolean);y.length>0&&s(v,{updated:y})},bulkUpsertAnnotations:f,clear:m,deleteAnnotation:E,deleteBody:A,getAnnotation:C,getBody:T,observe:o,unobserve:i,updateAnnotation:a,updateBody:U,updateTarget:(w,v=ne.LOCAL)=>{const y=q(w);y&&s(v,{updated:[y]})},upsertAnnotation:u}},ji=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});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 Fi=250,qi=(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:g}=m,k=performance.now();if(k-r>Fi)o.splice(i+1),o.push(g),i=o.length-1;else{const E=o.length-1;o[E]=Xi(o[E],g)}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:g})=>g)),f=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({newValue:g})=>g)),h=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),p=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,g)=>n.on(m,g),redo:()=>{if(o.length-1>i){s=!0;const{created:m,updated:g,deleted:k}=o[i+1];u(m),f(g),p(k),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:m,updated:g,deleted:k}=o[i];a(m),d(g),h(k),n.emit("undo",o[i]),i-=1}}}},Ki=()=>{const{subscribe:e,set:t}=Dt([]);return{subscribe:e,set:t}},Wi=(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])},p=(E,S)=>{const _=a.get(E);if(_){const A=_.indexOf(S);A!==-1&&_.splice(A,1)}},m=(E,S,_)=>{a.has(E)&&setTimeout(()=>{a.get(E).forEach(A=>{if(n){const M=Array.isArray(S)?S.map(T=>n.serialize(T)):n.serialize(S),C=_?_ instanceof PointerEvent?_:n.serialize(_):void 0;A(M,C)}else A(S,_)})},1)},g=()=>{const{selected:E}=s,S=(E||[]).map(({id:_})=>r.getAnnotation(_));S.forEach(_=>{const A=u.find(M=>M.id===_.id);(!A||!Oe(A,_))&&m("updateAnnotation",_,A)}),u=u.map(_=>S.find(({id:M})=>M===_.id)||_)};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 _=r.getAnnotation(S.id);_&&!Oe(_,S)&&m("updateAnnotation",_,S)}),u=[];else{const S=new Set(u.map(A=>A.id)),_=new Set(E.map(({id:A})=>A));u.filter(A=>!_.has(A.id)).forEach(A=>{const M=r.getAnnotation(A.id);M&&!Oe(M,A)&&m("updateAnnotation",M,A)}),u=[...u.filter(A=>_.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(g,1e3));const{created:S,deleted:_}=E.changes;(S||[]).forEach(A=>m("createAnnotation",A)),(_||[]).forEach(A=>m("deleteAnnotation",A)),(E.changes.updated||[]).filter(A=>[...A.bodiesCreated||[],...A.bodiesDeleted||[],...A.bodiesUpdated||[]].length>0).forEach(({oldValue:A,newValue:M})=>{const C=u.find(T=>T.id===A.id)||A;u=u.map(T=>T.id===A.id?M:T),m("updateAnnotation",M,C)})},{origin:ne.LOCAL}),r.observe(E=>{if(u){const S=new Set(u.map(A=>A.id)),_=(E.changes.updated||[]).filter(({newValue:A})=>S.has(A.id)).map(({newValue:A})=>A);_.length>0&&(u=u.map(A=>_.find(C=>C.id===A.id)||A))}},{origin:ne.REMOTE});const k=E=>S=>{const{updated:_}=S;E?(_||[]).forEach(A=>m("updateAnnotation",A.oldValue,A.newValue)):(_||[]).forEach(A=>m("updateAnnotation",A.newValue,A.oldValue))};return t.on("undo",k(!0)),t.on("redo",k(!1)),{on:h,off:p,emit:m}},Zi=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:[]}),Ji=(e,t,n)=>{const{store:o,selection:i}=e,s=E=>{if(n){const{parsed:S,error:_}=n.parse(E);S?o.addAnnotation(S,ne.REMOTE):console.error(_)}else o.addAnnotation(Ut(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(_=>_.id))||[]).map(_=>o.getAnnotation(_)).filter(Boolean);return n?S.map(n.serialize):S},f=(E,S=!0)=>fetch(E).then(_=>_.json()).then(_=>(p(_,S),_)),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}},p=(E,S=!0)=>{if(n){const _=n.parseAll||Zi(n),{parsed:A,failed:M}=_(E);M.length>0&&console.warn(`Discarded ${M.length} invalid annotations`,M),o.bulkAddAnnotations(A,S,ne.REMOTE)}else o.bulkAddAnnotations(E.map(Ut),S,ne.REMOTE)},m=(E,S)=>{E?i.setSelected(E,S):i.clear()},g=E=>{i.setUserSelectAction(E)},k=E=>{if(n){const S=n.parse(E).parsed,_=n.serialize(o.getAnnotation(S.id));return o.updateAnnotation(S),_}else{const S=o.getAnnotation(E.id);return o.updateAnnotation(Ut(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:p,setSelected:m,setUserSelectAction:g,undo:t.undo,updateAnnotation:k}},Qi=(e,t,n)=>typeof t=="function"?t(e,n):t,xi=(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||{}}},$i="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let es=e=>crypto.getRandomValues(new Uint8Array(e)),ts=(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}}},ns=(e,t=21)=>ts(e,t|0,es),os=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=$i[n[e]&63];return t};const is=()=>({isGuest:!0,id:ns("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ss=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}`},Yn=e=>e?typeof e=="object"?{...e}:e:void 0,rs=(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-${ss(n)}`,annotation:t,type:i,purpose:s,value:r,creator:Yn(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...d}}),ls=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}),as=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],cs=()=>{const e=[...as];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};os();const us=(e,t={strict:!0,invertY:!1})=>({parse:i=>Bn(i,t),serialize:i=>Vn(i,e,t)}),Bn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||On(),{creator:o,created:i,modified:s,body:r,...l}=e,a=rs(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=typeof d=="string"||(d==null?void 0:d.type)==="FragmentSelector"?An(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?Ln(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:Yn(o),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Vn=(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?kn(o.geometry):In(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:ls(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,"annotation"in d.target&&delete d.target.annotation,d},qe=[];function fs(e,t=j){let n;const o=new Set;function i(l){if(re(e,l)&&(e=l,n)){const a=!qe.length;for(const u of o)u[1](),qe.push(u,e);if(a){for(let u=0;u<qe.length;u+=2)qe[u][0](qe[u+1]);qe.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 ds=(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}`)},Xn=(e,t)=>{ds(e,t);const{subscribe:n,set:o}=fs(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}},Ve=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i,stroke:s,strokeWidth:r,strokeOpacity:l}=n;let a="";return o&&(a+=`fill:${o};`),i||i===0?a+=`fill-opacity:${i};`:o&&(a+="fill-opacity:0.25;"),s&&(a+=`stroke:${s};`,a+=`stroke-width:${r||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}},it=(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}},Le=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,hs=e=>({}),Hn=e=>({grab:e[0]});function gs(e){let t,n,o,i;const s=e[8].default,r=zo(s,e,e[7],Hn);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)&&qo(r,s,l,l[7],n?Fo(s,l[7],a,hs):Ko(l[7]),Hn)},i(l){n||(B(r,l),n=!0)},o(l){G(r,l),n=!1},d(l){l&&R(t),r&&r.d(l),o=!1,Ae(i)}}}function ms(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=Ce();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,d,f,h;const p=k=>E=>{if(d=k,u){const{left:_,top:A}=u.getBoundingClientRect(),M=E.clientX-_,C=E.clientY-A;f=a.elementToImage(M,C)}else{const{offsetX:_,offsetY:A}=E;f=a.elementToImage(_,A)}h=r,E.target.setPointerCapture(E.pointerId),s("grab",E)},m=k=>{if(d){const[E,S]=a.elementToImage(k.offsetX,k.offsetY),_=[E-f[0],S-f[1]];n(3,r=l(h,d,_)),s("change",r)}},g=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)},[p,m,g,r,l,a,u,i,o]}class yt extends ge{constructor(t){super(),he(this,t,ms,gs,re,{shape:3,editor:4,transform:5,svgEl:6})}}function ps(e){let t,n,o,i,s,r,l,a,u=e[3]&&Gn(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=He(`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),F(t,n),u&&u.m(t,null),F(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=Gn(d),u.c(),u.m(t,i)):u&&(u.d(1),u=null),f&8&&s!==(s=He(`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&&R(t),u&&u.d(),l=!1,Ae(a)}}}function ys(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"),Te(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),F(t,n),F(t,i),F(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&&Te(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&&R(t),a=!1,Ae(u)}}}function Gn(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&&R(t)}}}function _s(e){let t;function n(s,r){return Le?ys:ps}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&&R(t),i.d(s)}}}function ws(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=_=>{_.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function f(_){ue.call(this,e,_)}function h(_){ue.call(this,e,_)}function p(_){ue.call(this,e,_)}function m(_){ue.call(this,e,_)}function g(_){ue.call(this,e,_)}function k(_){ue.call(this,e,_)}function E(_){ue.call(this,e,_)}function S(_){ue.call(this,e,_)}return e.$$set=_=>{n(8,t=Ie(Ie({},t),cn(_))),"x"in _&&n(0,i=_.x),"y"in _&&n(1,s=_.y),"scale"in _&&n(2,r=_.scale),"selected"in _&&n(3,l=_.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=4/r)},t=cn(t),[i,s,r,l,a,o,u,d,t,f,h,p,m,g,k,E,S]}class Xe extends ge{constructor(t){super(),he(this,t,ws,_s,re,{x:0,y:1,scale:2,selected:3})}}function bs(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),F(t,n),F(t,i),F(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&&R(t),r=!1,Ae(l)}}}function Es(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&&R(t)}}}function vs(e){let t;function n(s,r){return Le?Es:bs}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&&R(t),i.d(s)}}}function Ss(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 Yt extends ge{constructor(t){super(),he(this,t,Ss,vs,re,{x:0,y:1,scale:4})}}function Bt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function jn(e,t,n){const o=e.slice();return o[28]=t[n],o[30]=n,o}function Vt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Xt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function zn(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=st/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=st/s[3])&&c(t,"r",i)},d(s){s&&R(t)}}}function Fn(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=st/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),F(t,n),F(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=st/f[3])&&c(l,"r",d)},d(f){f&&R(t)}}}function qn(e){let t,n;return t=new Xe({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Kn(e){let t,n;return t=new Yt({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function As(e){let t,n,o,i,s,r,l,a,u,d,f,h,p,m,g,k,E,S,_,A,M,C=e[6]!==void 0&&!e[7]&&zn(Xt(e)),T=e[6]!==void 0&&!e[7]&&Fn(Vt(e)),V=ve(e[5].points),U=[];for(let w=0;w<V.length;w+=1)U[w]=qn(jn(e,V,w));const W=w=>G(U[w],1,1,()=>{U[w]=null});let q=e[6]!==void 0&&!e[7]&&Kn(Bt(e));return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),C&&C.c(),T&&T.c(),d=we(),f=L("polygon"),p=we(),m=L("polygon"),k=we();for(let w=0;w<U.length;w+=1)U[w].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(Wn).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(Zn).join(" ")),c(m,"class","a9s-inner a9s-shape-handle"),c(m,"mask",`url(#${e[19]}-inner)`),c(m,"style",e[1]),c(m,"points",g=e[5].points.map(Jn).join(" "))},m(w,v){N(w,t,v),F(t,n),F(n,o),F(n,a),C&&C.m(n,null),T&&T.m(t,null),N(w,d,v),N(w,f,v),N(w,p,v),N(w,m,v),N(w,k,v);for(let y=0;y<U.length;y+=1)U[y]&&U[y].m(w,v);N(w,E,v),q&&q.m(w,v),N(w,S,v),_=!0,A||(M=[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(w,v){if(e=w,(!_||v[0]&512&&i!==(i=e[9].x))&&c(o,"x",i),(!_||v[0]&512&&s!==(s=e[9].y))&&c(o,"y",s),(!_||v[0]&512&&r!==(r=e[9].w))&&c(o,"width",r),(!_||v[0]&512&&l!==(l=e[9].h))&&c(o,"height",l),(!_||v[0]&32&&u!==(u=e[5].points.map(Wn).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Xt(e),v):(C=zn(Xt(e)),C.c(),C.m(n,null)):C&&(C.d(1),C=null),e[6]!==void 0&&!e[7]?T?T.p(Vt(e),v):(T=Fn(Vt(e)),T.c(),T.m(t,null)):T&&(T.d(1),T=null),(!_||v[0]&32&&h!==(h=e[5].points.map(Zn).join(" ")))&&c(f,"points",h),(!_||v[0]&2)&&c(m,"style",e[1]),(!_||v[0]&32&&g!==(g=e[5].points.map(Jn).join(" ")))&&c(m,"points",g),v[0]&134322472){V=ve(e[5].points);let y;for(y=0;y<V.length;y+=1){const b=jn(e,V,y);U[y]?(U[y].p(b,v),B(U[y],1)):(U[y]=qn(b),U[y].c(),B(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(Bt(e),v),v[0]&192&&B(q,1)):(q=Kn(Bt(e)),q.c(),B(q,1),q.m(S.parentNode,S)):q&&(be(),G(q,1,1,()=>{q=null}),Ee())},i(w){if(!_){for(let v=0;v<V.length;v+=1)B(U[v]);B(q),_=!0}},o(w){U=U.filter(Boolean);for(let v=0;v<U.length;v+=1)G(U[v]);G(q),_=!1},d(w){w&&(R(t),R(d),R(f),R(p),R(m),R(k),R(E),R(S)),C&&C.d(),T&&T.d(),Ne(U,w),q&&q.d(w),A=!1,Ae(M)}}}function ks(e){let t,n;return t=new yt({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[As,({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ms=250,Ts=1e3,Ps=12,st=4.5,Wn=e=>e.join(","),Zn=e=>e.join(","),Jn=e=>e.join(",");function Ls(e,t,n){let o,i,s;const r=Ce();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,p=!1,m,g=[];const k=()=>n(7,p=!0),E=()=>n(7,p=!1),S=y=>{if(g.length>0||!i.some(Z=>Z.visible)){n(6,h=void 0);return}const[b,I]=u.elementToImage(y.offsetX,y.offsetY),P=Z=>Math.pow(Z[0]-b,2)+Math.pow(Z[1]-I,2),D=o.points.reduce((Z,$)=>P($)<P(Z)?$:Z),z=i.filter(Z=>Z.visible).reduce((Z,$)=>P($.point)<P(Z.point)?$:Z),H=Math.pow(Ts/d,2);P(D)<H||P(z.point)<H?n(6,h=i.indexOf(z)):n(6,h=void 0)},_=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,g=[]),_()},M=y=>{n(7,p=!0),y.preventDefault(),y.stopPropagation(),m=performance.now()},C=y=>b=>{if(!m||Le||performance.now()-m>Ms)return;const I=g.includes(y);b.metaKey||b.ctrlKey||b.shiftKey?I?n(8,g=g.filter(P=>P!==y)):n(8,g=[...g,y]):I&&g.length>1?n(8,g=[y]):I?n(8,g=[]):n(8,g=[y]),_()},T=(y,b,I)=>{_();let P;const D=y.geometry;g.length>1?P=D.points.map(([H,x],Z)=>g.includes(Z)?[H+I[0],x+I[1]]:[H,x]):b==="SHAPE"?P=D.points.map(([H,x])=>[H+I[0],x+I[1]]):P=D.points.map(([H,x],Z)=>b===`HANDLE-${Z}`?[H+I[0],x+I[1]]:[H,x]);const z=fe(P);return{...y,geometry:{points:P,bounds:z}}},V=y=>async b=>{b.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 mn();const D=[...document.querySelectorAll(".a9s-handle")][y+1];if(D!=null&&D.firstChild){const z=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:b.clientX,clientY:b.clientY,pointerId:b.pointerId,pointerType:b.pointerType,isPrimary:b.isPrimary,buttons:b.buttons});D.firstChild.dispatchEvent(z)}},U=()=>{if(o.points.length-g.length<3)return;const y=o.points.filter((I,P)=>!g.includes(P)),b=fe(y);r("change",{...l,geometry:{points:y,bounds:b}}),n(8,g=[])};Ue(()=>{if(Le)return;const y=b=>{(b.key==="Delete"||b.key==="Backspace")&&(b.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 w(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=Le?[]:o.points.map((y,b)=>{const I=b===o.points.length-1?o.points[0]:o.points[b+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))>Ps/d;return{point:[P,D],visible:H}})),e.$$.dirty[0]&40&&n(9,s=it(o.bounds,st/d))},[l,a,u,d,f,o,h,p,g,s,i,k,E,S,A,M,C,T,V,W,q,w,v]}class Qn extends ge{constructor(t){super(),he(this,t,Ls,ks,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Is(e){let t,n,o,i,s,r,l,a,u,d,f,h,p,m,g,k,E,S,_,A,M,C,T,V,U,W,q,w,v,y,b,I,P,D,z,H,x,Z,$,oe,se,Se,Me,X,de,te,ye,_e,Ze,De,tn,Re,ee,nn,Go;return te=new Xe({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 Xe({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)}),De=new Xe({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),De.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Re=new Xe({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Re.$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"),p=we(),m=L("rect"),_=we(),A=L("rect"),U=we(),W=L("rect"),y=we(),b=L("rect"),z=we(),H=L("rect"),oe=we(),se=L("rect"),de=we(),ce(te.$$.fragment),ye=we(),ce(_e.$$.fragment),Ze=we(),ce(De.$$.fragment),tn=we(),ce(Re.$$.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",g=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",M=e[5].x),c(A,"y",C=e[5].y),c(A,"width",T=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",w=e[5].y),c(W,"height",1),c(W,"width",v=e[5].w),c(b,"class","a9s-edge-handle a9s-edge-handle-right"),c(b,"x",I=e[5].x+e[5].w),c(b,"y",P=e[5].y),c(b,"height",D=e[5].h),c(b,"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",Me=e[5].y),c(se,"height",X=e[5].h),c(se,"width",1)},m(K,Y){N(K,t,Y),F(t,n),F(n,o),F(n,a),N(K,p,Y),N(K,m,Y),N(K,_,Y),N(K,A,Y),N(K,U,Y),N(K,W,Y),N(K,y,Y),N(K,b,Y),N(K,z,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,Ze,Y),le(De,K,Y),N(K,tn,Y),le(Re,K,Y),ee=!0,nn||(Go=[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(b,"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)})],nn=!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&&g!==(g=e[5].x))&&c(m,"x",g),(!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&&M!==(M=e[5].x))&&c(A,"x",M),(!ee||Y&32&&C!==(C=e[5].y))&&c(A,"y",C),(!ee||Y&32&&T!==(T=e[5].w))&&c(A,"width",T),(!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&&w!==(w=e[5].y))&&c(W,"y",w),(!ee||Y&32&&v!==(v=e[5].w))&&c(W,"width",v),(!ee||Y&32&&I!==(I=e[5].x+e[5].w))&&c(b,"x",I),(!ee||Y&32&&P!==(P=e[5].y))&&c(b,"y",P),(!ee||Y&32&&D!==(D=e[5].h))&&c(b,"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&&Me!==(Me=e[5].y))&&c(se,"y",Me),(!ee||Y&32&&X!==(X=e[5].h))&&c(se,"height",X);const bt={};Y&32&&(bt.x=e[5].x),Y&32&&(bt.y=e[5].y),Y&8&&(bt.scale=e[3]),te.$set(bt);const Et={};Y&32&&(Et.x=e[5].x+e[5].w),Y&32&&(Et.y=e[5].y),Y&8&&(Et.scale=e[3]),_e.$set(Et);const vt={};Y&32&&(vt.x=e[5].x+e[5].w),Y&32&&(vt.y=e[5].y+e[5].h),Y&8&&(vt.scale=e[3]),De.$set(vt);const St={};Y&32&&(St.x=e[5].x),Y&32&&(St.y=e[5].y+e[5].h),Y&8&&(St.scale=e[3]),Re.$set(St)},i(K){ee||(B(te.$$.fragment,K),B(_e.$$.fragment,K),B(De.$$.fragment,K),B(Re.$$.fragment,K),ee=!0)},o(K){G(te.$$.fragment,K),G(_e.$$.fragment,K),G(De.$$.fragment,K),G(Re.$$.fragment,K),ee=!1},d(K){K&&(R(t),R(p),R(m),R(_),R(A),R(U),R(W),R(y),R(b),R(z),R(H),R(oe),R(se),R(de),R(ye),R(Ze),R(tn)),ae(te,K),ae(_e,K),ae(De,K),ae(Re,K),nn=!1,Ae(Go)}}}function Cs(e){let t,n;return t=new yt({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Is,({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Os(e,t,n){let o,i,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const d=(g,k,E)=>{const S=g.geometry.bounds;let[_,A]=[S.minX,S.minY],[M,C]=[S.maxX,S.maxY];const[T,V]=E;if(k==="SHAPE")_+=T,M+=T,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":{_+=T;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{M+=T;break}}}const U=Math.min(_,M),W=Math.min(A,C),q=Math.abs(M-_),w=Math.abs(C-A);return{...g,geometry:{x:U,y:W,w:q,h:w,bounds:{minX:U,minY:W,maxX:U+q,maxY:W+w}}}},f=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function h(g){ue.call(this,e,g)}function p(g){ue.call(this,e,g)}function m(g){ue.call(this,e,g)}return e.$$set=g=>{"shape"in g&&n(0,s=g.shape),"computedStyle"in g&&n(1,r=g.computedStyle),"transform"in g&&n(2,l=g.transform),"viewportScale"in g&&n(3,a=g.viewportScale),"svgEl"in g&&n(4,u=g.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,o=s.geometry),e.$$.dirty&40&&n(6,i=it(o.bounds,2/a))},[s,r,l,a,u,o,i,d,f,h,p,m]}class xn extends ge{constructor(t){super(),he(this,t,Os,Cs,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var $n=Object.prototype.hasOwnProperty;function Ht(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--&&Ht(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if($n.call(e,n)&&++o&&!$n.call(t,n)||!(n in t)||!Ht(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Ds=12,Rs=(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],p=(d[0]+h[0])/2,m=(d[1]+h[1])/2,k=Math.sqrt(Math.pow(h[0]-p,2)+Math.pow(h[1]-m,2))>Ds/t;return{point:[p,m],visible:k,elementIdx:i,ringIdx:a,pointIdx:f}});return[...r,...u]},[]);return[...n,...s]},[]);function Gt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function eo(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function to(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function no(e,t,n){const o=e.slice();return o[29]=t[n],o[37]=n,o}function jt(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 oo(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=rt/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=rt/s[3])&&c(t,"r",i)},d(s){s&&R(t)}}}function io(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=rt/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),F(t,n),F(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=rt/f[3])&&c(l,"r",d)},d(f){f&&R(t)}}}function so(e){let t,n;function o(...i){return e[19](e[32],e[35],e[37],...i)}return t=new Xe({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||(B(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function ro(e){let t,n,o=ve(e[33].points),i=[];for(let r=0;r<o.length;r+=1)i[r]=so(no(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=no(r,o,a);i[a]?(i[a].p(u,l),B(i[a],1)):(i[a]=so(u),i[a].c(),B(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)B(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&&R(t),Ne(i,r)}}}function lo(e){let t,n,o,i,s,r,l,a,u,d,f,h,p,m,g,k,E,S=e[6]!==void 0&&!e[7]&&oo(zt(e)),_=e[6]!==void 0&&!e[7]&&io(jt(e)),A=ve(e[30].rings),M=[];for(let T=0;T<A.length;T+=1)M[T]=ro(to(e,A,T));const C=T=>G(M[T],1,1,()=>{M[T]=null});return{c(){t=L("g"),n=L("defs"),o=L("mask"),i=L("rect"),u=L("path"),S&&S.c(),_&&_.c(),f=L("path"),p=L("path");for(let T=0;T<M.length;T+=1)M[T].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=Pe(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=Pe(e[30])),c(p,"class","a9s-inner"),c(p,"mask",`url(#${e[18]}-${e[32]}-inner)`),c(p,"style",e[1]),c(p,"fill-rule","evenodd"),c(p,"d",m=Pe(e[30]))},m(T,V){N(T,t,V),F(t,n),F(n,o),F(o,i),F(o,u),S&&S.m(o,null),_&&_.m(n,null),F(t,f),F(t,p);for(let U=0;U<M.length;U+=1)M[U]&&M[U].m(t,null);g=!0,k||(E=[J(f,"pointerup",e[13]),J(f,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),J(p,"pointerup",e[13]),J(p,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],k=!0)},p(T,V){if(e=T,(!g||V[0]&512&&s!==(s=e[9].x))&&c(i,"x",s),(!g||V[0]&512&&r!==(r=e[9].y))&&c(i,"y",r),(!g||V[0]&512&&l!==(l=e[9].w))&&c(i,"width",l),(!g||V[0]&512&&a!==(a=e[9].h))&&c(i,"height",a),(!g||V[0]&32&&d!==(d=Pe(e[30])))&&c(u,"d",d),e[6]!==void 0&&!e[7]?S?S.p(zt(e),V):(S=oo(zt(e)),S.c(),S.m(o,null)):S&&(S.d(1),S=null),e[6]!==void 0&&!e[7]?_?_.p(jt(e),V):(_=io(jt(e)),_.c(),_.m(n,null)):_&&(_.d(1),_=null),(!g||V[0]&32&&h!==(h=Pe(e[30])))&&c(f,"d",h),(!g||V[0]&2)&&c(p,"style",e[1]),(!g||V[0]&32&&m!==(m=Pe(e[30])))&&c(p,"d",m),V[0]&268491048){A=ve(e[30].rings);let U;for(U=0;U<A.length;U+=1){const W=to(e,A,U);M[U]?(M[U].p(W,V),B(M[U],1)):(M[U]=ro(W),M[U].c(),B(M[U],1),M[U].m(t,null))}for(be(),U=A.length;U<M.length;U+=1)C(U);Ee()}},i(T){if(!g){for(let V=0;V<A.length;V+=1)B(M[V]);g=!0}},o(T){M=M.filter(Boolean);for(let V=0;V<M.length;V+=1)G(M[V]);g=!1},d(T){T&&R(t),S&&S.d(),_&&_.d(),Ne(M,T),k=!1,Ae(E)}}}function ao(e){let t,n;return t=new Yt({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ns(e){let t,n,o,i=ve(e[5].polygons),s=[];for(let a=0;a<i.length;a+=1)s[a]=lo(eo(e,i,a));const r=a=>G(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&ao(Gt(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=eo(a,i,d);s[d]?(s[d].p(f,u),B(s[d],1)):(s[d]=lo(f),s[d].c(),B(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(Gt(a),u),u[0]&192&&B(l,1)):(l=ao(Gt(a)),l.c(),B(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)B(s[u]);B(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&&(R(t),R(n)),Ne(s,a),l&&l.d(a)}}}function Us(e){let t,n;return t=new yt({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[Ns,({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ys=250,Bs=1e3,rt=4.5;function Vs(e,t,n){let o,i,s;const r=Ce();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,p=!1,m,g=[];const k=()=>n(7,p=!0),E=()=>n(7,p=!1),S=b=>{if(g.length>0||!i.some($=>$.visible)){n(6,h=void 0);return}const[I,P]=u.elementToImage(b.offsetX,b.offsetY),D=$=>Math.pow($[0]-I,2)+Math.pow($[1]-P,2),z=bn(o).reduce(($,oe)=>D(oe)<D($)?oe:$),H=i.filter($=>$.visible).reduce(($,oe)=>D(oe.point)<D($.point)?oe:$),x=Math.pow(Bs/d,2);D(z)<x||D(H.point)<x?n(6,h=i.indexOf(H)):n(6,h=void 0)},_=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,g=[]),_()},M=b=>{n(7,p=!0),b.preventDefault(),b.stopPropagation(),m=performance.now()},C=(b,I,P)=>D=>{if(!m||Le||performance.now()-m>Ys)return;const z=x=>x.polygon===b&&x.ring===I&&x.point===P,H=g.some(z);D.metaKey||D.ctrlKey||D.shiftKey?H?n(8,g=g.filter(x=>!z(x))):n(8,g=[...g,{polygon:b,ring:I,point:P}]):H&&g.length>1?n(8,g=[{polygon:b,ring:I,point:P}]):H?n(8,g=[]):n(8,g=[{polygon:b,ring:I,point:P}]),_()},T=(b,I,P)=>{_();const D=b.geometry.polygons;let z;if(I==="SHAPE")z=D.map(H=>{const x=H.rings.map(($,oe)=>({points:$.points.map((Se,Me)=>[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));z=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),Me=fe(Se[0].points);return{rings:Se,bounds:Me}}else return oe})}return{...b,geometry:{polygons:z,bounds:tt(z)}}},V=b=>async I=>{I.stopPropagation();const P=i[b],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:tt(D)}}),await mn();const z=[...document.querySelectorAll(".a9s-handle")][b+1];if(z!=null&&z.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});z.firstChild.dispatchEvent(H)}},U=()=>{const b=o.polygons.map((P,D)=>{if(g.some(H=>H.polygon===D)){const H=P.rings.map((Z,$)=>{const oe=g.filter(se=>se.polygon===D&&se.ring===$);return oe.length&&Z.points.length-oe.length>=3?{points:Z.points.filter((Se,Me)=>!oe.some(X=>X.point===Me))}:Z}),x=fe(H[0].points);return{rings:H,bounds:x}}else return P});!Ht(o.polygons,b)&&(r("change",{...l,geometry:{polygons:b,bounds:tt(b)}}),n(8,g=[]))};Ue(()=>{if(Le)return;const b=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),U())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",b),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",b)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,q=(b,I,P,{polygon:D,ring:z,point:H})=>D===b&&z===I&&H===P;function w(b){ue.call(this,e,b)}function v(b){ue.call(this,e,b)}function y(b){ue.call(this,e,b)}return e.$$set=b=>{"shape"in b&&n(0,l=b.shape),"computedStyle"in b&&n(1,a=b.computedStyle),"transform"in b&&n(2,u=b.transform),"viewportScale"in b&&n(3,d=b.viewportScale),"svgEl"in b&&n(4,f=b.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Le?[]:Rs(o,d)),e.$$.dirty[0]&40&&n(9,s=it(o.bounds,rt/d))},[l,a,u,d,f,o,h,p,g,s,i,k,E,A,M,C,T,V,W,q,w,v,y]}class Xs extends ge{constructor(t){super(),he(this,t,Vs,Us,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const co=new Map([[Q.RECTANGLE,xn],[Q.POLYGON,Qn],[Q.MULTIPOLYGON,Xs]]),uo=e=>co.get(e.type),fo=(e,t)=>co.set(e,t);function Hs(e,t,n){let o;const i=Ce();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,f;return Ue(()=>(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=Ve(s,l)),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 ho extends ge{constructor(t){super(),he(this,t,Hs,null,re,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Gs(e,t,n){const o=Ce();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return Ue(()=>{const d=s.closest("svg"),f=[],h=(p,m,g)=>{d==null||d.addEventListener(p,m,g),f.push(()=>d==null?void 0:d.removeEventListener(p,m,g))};return n(5,u=new r({target:s,props:{addEventListener:h,drawingMode:i,transform:l,viewportScale:a}})),u.$on("create",p=>o("create",p.detail)),()=>{f.forEach(p=>p()),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 go extends ge{constructor(t){super(),he(this,t,Gs,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function mo(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),F(t,n),F(n,o),F(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&&(R(t),R(u),R(d))}}}function js(e){let t,n=e[0]&&mo(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=mo(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&R(t),n&&n.d()}}}function zs(e,t,n){let o;const i=Ce();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,d,f,h,p,m,g;const k=M=>{const C=M;u=performance.now(),r==="drag"&&(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,p=d[1]),n(3,m=1),n(4,g=1))},E=M=>{const C=M;d&&(f=l.elementToImage(C.offsetX,C.offsetY),n(1,h=Math.min(f[0],d[0])),n(2,p=Math.min(f[1],d[1])),n(3,m=Math.abs(f[0]-d[0])),n(4,g=Math.abs(f[1]-d[1])))},S=M=>{const C=M,T=performance.now()-u;if(r==="click"){if(T>300)return;d?_():(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,p=d[1]),n(3,m=1),n(4,g=1))}else d&&(T>300||m*g>100?(C.stopPropagation(),_()):(n(0,d=void 0),f=void 0))},_=()=>{if(m*g>15){const M={type:Q.RECTANGLE,geometry:{bounds:{minX:h,minY:p,maxX:h+m,maxY:p+g},x:h,y:p,w:m,h:g}};i("create",M)}n(0,d=void 0),f=void 0};Ue(()=>{s("pointerdown",k),s("pointermove",E),s("pointerup",S,!0)});const A=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=M=>{"addEventListener"in M&&n(7,s=M.addEventListener),"drawingMode"in M&&n(8,r=M.drawingMode),"transform"in M&&n(9,l=M.transform),"viewportScale"in M&&n(10,a=M.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,o=2/a)},[d,h,p,m,g,o,A,s,r,l,a]}class po extends ge{constructor(t){super(),he(this,t,zs,js,re,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function Ft(e){const t=e.slice(),n=t[2].map(o=>o.join(",")).join(" ");return t[19]=n,t}function yo(e){let t,n,o,i,s,r,l,a,u,d,f,h,p,m,g=e[1]&&_o(e);return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),d=L("polygon"),h=L("polygon"),g&&g.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",p=e[19])},m(k,E){N(k,t,E),F(t,n),F(n,o),F(n,a),N(k,d,E),N(k,h,E),g&&g.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&&p!==(p=k[19])&&c(h,"points",p),k[1]?g?g.p(k,E):(g=_o(k),g.c(),g.m(m.parentNode,m)):g&&(g.d(1),g=null)},d(k){k&&(R(t),R(d),R(h),R(m)),g&&g.d(k)}}}function _o(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&&R(t)}}}function Fs(e){let t,n=e[3]&&yo(Ft(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(Ft(o),i):(n=yo(Ft(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&R(t),n&&n.d()}}}const qs=20,Ks=1500;function Ws(e,t,n){let o,i,s;const r=Ce();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,f,h=[],p,m,g=!1;const k=C=>{const T=C,{timeStamp:V,offsetX:U,offsetY:W}=T;if(f={timeStamp:V,offsetX:U,offsetY:W},a==="drag"&&h.length===0){const q=u.elementToImage(T.offsetX,T.offsetY);h.push(q),n(10,p=q)}},E=C=>{const T=C;if(m&&clearTimeout(m),h.length>0){if(n(10,p=u.elementToImage(T.offsetX,T.offsetY)),h.length>2){const V=et(p,h[0])*d;n(1,g=V<qs)}T.pointerType==="touch"&&(m=setTimeout(()=>{_()},Ks))}},S=C=>{const T=C;if(m&&clearTimeout(m),a==="click"){const V=T.timeStamp-f.timeStamp,U=et([f.offsetX,f.offsetY],[T.offsetX,T.offsetY]);if(V>300||U>15)return;if(g)A();else if(h.length===0){const W=u.elementToImage(T.offsetX,T.offsetY);h.push(W),n(10,p=W)}else p&&h.push(p)}else{if(!p)return;if(h.length===1&&et(h[0],p)<=4){n(0,h=[]),n(10,p=void 0);return}T.stopImmediatePropagation(),g?A():h.push(p)}},_=()=>{if(!p)return;const C=h.slice(0,-1);if(C.length<3)return;const T={type:Q.POLYGON,geometry:{bounds:fe(h),points:C}};dt(T)>4&&(n(0,h=[]),n(10,p=void 0),r("create",T))},A=()=>{const C={type:Q.POLYGON,geometry:{bounds:fe(h),points:[...h]}};n(0,h=[]),n(10,p=void 0),r("create",C)};Ue(()=>{l("pointerdown",k,!0),l("pointermove",E),l("pointerup",S,!0),l("dblclick",_,!0)});const M=`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=p?g?h:[...h,p]:[]),e.$$.dirty&516&&n(3,s=i.length>0?it(fe(i),2/d):void 0)},[h,g,i,s,o,M,l,a,u,d,p]}class Zs extends ge{constructor(t){super(),he(this,t,Ws,Fs,re,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const qt=new Map([["rectangle",{tool:po}],["polygon",{tool:Zs}]]),Kt=()=>[...qt.keys()],Wt=e=>qt.get(e),wo=(e,t,n={})=>qt.set(e,{tool:t,opts:n});function Js(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),F(t,n),F(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&&R(t)}}}function Qs(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=Ve(i,r))},[i,o,l,a,u,d,s,r]}class xs extends ge{constructor(t){super(),he(this,t,Qs,Js,re,{annotation:0,geom:6,style:7})}}function $s(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),F(t,n),F(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&&R(t)}}}function er(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=Ve(i,r))},[i,o,a,u,d,f,s,r]}class tr extends ge{constructor(t){super(),he(this,t,er,$s,re,{annotation:0,geom:6,style:7})}}function bo(e,t,n){const o=e.slice();return o[5]=t[n],o}function Eo(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",Pe(e[5])),c(o,"class","a9s-inner"),c(o,"style",e[1]),c(o,"fill-rule","evenodd"),c(o,"d",Pe(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&&(R(t),R(o))}}}function nr(e){let t,n,o=ve(e[2]),i=[];for(let s=0;s<o.length;s+=1)i[s]=Eo(bo(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=bo(s,o,l);i[l]?i[l].p(a,r):(i[l]=Eo(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&&R(t),Ne(i,s)}}}function or(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=Ve(i,r))},[i,o,l,s,r]}class ir extends ge{constructor(t){super(),he(this,t,or,nr,re,{annotation:0,geom:3,style:4})}}function sr(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(rr).join(" ")),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"points",e[2].map(lr).join(" ")),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),F(t,n),F(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&&R(t)}}}const rr=e=>e.join(","),lr=e=>e.join(",");function ar(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=Ve(i,r))},[i,o,l,s,r]}class cr extends ge{constructor(t){super(),he(this,t,ar,sr,re,{annotation:0,geom:3,style:4})}}function ur(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("path"),s=L("path"),c(n,"class",o=He(`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=He(`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),F(t,n),F(t,s)},p(a,[u]){u&2&&o!==(o=He(`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=He(`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&&R(t)}}}function fr(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=Ve(r,a)),e.$$.dirty&16&&n(2,i=It(l)),e.$$.dirty&16&&n(1,s=l.closed?"closed":"open")},[r,s,i,o,l,a]}class dr extends ge{constructor(t){super(),he(this,t,fr,ur,re,{annotation:0,geom:4,style:5})}}function hr(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),F(t,n),F(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&&R(t)}}}function gr(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=Ve(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 mr extends ge{constructor(t){super(),he(this,t,gr,hr,re,{annotation:0,geom:6,style:7})}}const pr={elementToImage:(e,t)=>[e,t]},vo=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]}}),yr=250,So=(e,t)=>{const n=Ce();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<yr){const{x:a,y:u}=Zt(r,e),d=Le?10:2,f=t.getAt(a,u,void 0,d);f?n("click",{originalEvent:r,annotation:f}):n("click",{originalEvent:r})}}}},Zt=(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 Ao(e,t,n){const o=e.slice();return o[39]=t[n],o}function ko(e,t,n){const o=e.slice();return o[42]=t[n],o}function Jt(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Mo(e){let t=e[42],n,o,i=To(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=To(s),i.c(),B(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(B(i),o=!0)},o(s){G(i),o=!1},d(s){s&&R(n),i.d(s)}}}function _r(e){let t,n;return t=new tr({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function wr(e){let t,n;return t=new dr({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||(B(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 ir({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||(B(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 cr({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||(B(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 mr({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Sr(e){var o;let t,n;return t=new xs({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||(B(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function To(e){let t,n,o,i;const s=[Sr,vr,Er,br,wr,_r],r=[];function l(a,u){var d,f,h,p,m,g;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:((p=a[45])==null?void 0:p.type)===Q.MULTIPOLYGON?3:((m=a[45])==null?void 0:m.type)===Q.POLYLINE?4:((g=a[45])==null?void 0:g.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()),B(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(B(n),i=!0)},o(a){G(n),i=!1},d(a){a&&R(o),~t&&r[t].d(a)}}}function Po(e){let t=nt(e[42])&&!e[10](e[42]),n,o,i=t&&Mo(Jt(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=nt(s[42])&&!s[10](s[42])),t?i?(i.p(Jt(s),r),r[0]&132096&&B(i,1)):(i=Mo(Jt(s)),i.c(),B(i,1),i.m(n.parentNode,n)):i&&(be(),G(i,1,1,()=>{i=null}),Ee())},i(s){o||(B(i),o=!0)},o(s){G(i),o=!1},d(s){s&&R(n),i&&i.d(s)}}}function Lo(e){let t,n,o,i;const s=[kr,Ar],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()),B(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(B(n),i=!0)},o(a){G(n),i=!1},d(a){a&&R(o),~t&&r[t].d(a)}}}function Ar(e){let t=`${e[2]}-${e[7]}`,n,o,i=Io(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=Io(s),i.c(),B(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(B(i),o=!0)},o(s){G(i),o=!1},d(s){s&&R(n),i.d(s)}}}function kr(e){let t,n,o=ve(e[6]),i=[];for(let r=0;r<o.length;r+=1)i[r]=Oo(Ao(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=Ao(r,o,a);i[a]?(i[a].p(u,l),B(i[a],1)):(i[a]=Oo(u),i[a].c(),B(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)B(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&&R(t),Ne(i,r)}}}function Io(e){let t,n;return t=new go({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Co(e){let t,n;return t=new ho({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||(B(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Oo(e){let t=e[39].annotation.id,n,o,i=Co(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=Co(s),i.c(),B(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(B(i),o=!0)},o(s){G(i),o=!1},d(s){s&&R(n),i.d(s)}}}function Mr(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]=Po(ko(e,l,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&Lo(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"),Te(t,"drawing",e[15]),Te(t,"editing",e[5]),Te(t,"hidden",!e[3]),Te(t,"hover",e[16])},m(f,h){N(f,t,h),F(t,n);for(let p=0;p<a.length;p+=1)a[p]&&a[p].m(n,null);F(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 p;for(p=0;p<l.length;p+=1){const m=ko(e,l,p);a[p]?(a[p].p(m,h),B(a[p],1)):(a[p]=Po(m),a[p].c(),B(a[p],1),a[p].m(n,null))}for(be(),p=l.length;p<a.length;p+=1)u(p);Ee()}e[8]?d?(d.p(e,h),h[0]&256&&B(d,1)):(d=Lo(e),d.c(),B(d,1),d.m(o,null)):d&&(be(),G(d,1,1,()=>{d=null}),Ee()),(!i||h[0]&32768)&&Te(t,"drawing",e[15]),(!i||h[0]&32)&&Te(t,"editing",e[5]),(!i||h[0]&8)&&Te(t,"hidden",!e[3]),(!i||h[0]&65536)&&Te(t,"hover",e[16])},i(f){if(!i){for(let h=0;h<l.length;h+=1)B(a[h]);B(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&&R(t),Ne(a,f),d&&d.d(),e[35](null),e[36](null),s=!1,Ae(r)}}}function Tr(e,t,n){let o,i,s,r,l,a,u,d,f,h,p,m,g=j,k=()=>(g(),g=ln(b,X=>n(18,m=X)),b);e.$$.on_destroy.push(()=>g());let{drawingEnabled:E}=t,{image:S}=t,{preferredDrawingMode:_}=t,{state:A}=t,{style:M=void 0}=t,{toolName:C=Kt()[0]}=t,{user:T}=t,{visible:V=!0}=t,U=0;const W=()=>n(7,U+=1),q=()=>C,w=()=>E;let v,y,b;Ue(()=>k(n(9,b=Xn(S,y))));const{hover:I,selection:P,store:D}=A;At(e,I,X=>n(16,f=X)),At(e,P,X=>n(33,h=X)),At(e,D,X=>n(17,p=X));let z,H;const x=X=>{z&&D.unobserve(z);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&&nt(te))),z=te=>{const{updated:ye}=te.changes;n(5,H=ye==null?void 0:ye.map(_e=>_e.newValue))},D.observe(z,{annotations:de})):n(5,H=void 0)},Z=X=>{const de=On(),te={id:de,bodies:[],target:{annotation:de,selector:X.detail,creator:T,created:new Date}};D.addAnnotation(te),P.setSelected(te.id)},$=X=>de=>{var Ze;const{target:te}=X,ye=10*60*1e3,_e=((Ze=te.creator)==null?void 0:Ze.id)!==T.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?T:void 0})},oe=X=>{const{x:de,y:te}=Zt(X,y),ye=D.getAt(de,te,void 0,2);ye?f!==ye.id&&I.set(ye.id):I.set(void 0)},se=X=>nt(X);function Se(X){ut[X?"unshift":"push"](()=>{v=X,n(8,v)})}function Me(X){ut[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,_=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,M=X.style),"toolName"in X&&n(2,C=X.toolName),"user"in X&&n(28,T=X.user),"visible"in X&&n(3,V=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:o,opts:i}=Wt(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)||_),e.$$.dirty[0]&16&&n(13,r=vo(y)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=So(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:uo(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,M,C,V,y,H,u,U,v,b,d,a,l,r,s,o,f,p,m,I,P,D,Z,$,oe,S,_,A,T,W,q,w,i,h,se,Se,Me]}class Do extends ge{constructor(t){super(),he(this,t,Tr,Mr,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 Ro(e,t,n=0,o=e.length-1,i=Pr){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),p=Math.max(n,Math.floor(t-u*f/a+h)),m=Math.min(o,Math.floor(t+(a-u)*f/a+h));Ro(e,t,p,m,i)}const s=e[t];let r=n,l=o;for(lt(e,n,t),i(e[o],s)>0&<(e,n,o);r<l;){for(lt(e,r,l),r++,l--;i(e[r],s)<0;)r++;for(;i(e[l],s)>0;)l--}i(e[n],s)===0?lt(e,n,l):(l++,lt(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function lt(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Pr(e,t){return e<t?-1:e>t?1:0}class Lr{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(!wt(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;wt(t,a)&&(n.leaf?o.push(l):xt(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!wt(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(wt(t,r)){if(n.leaf||xt(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=We([]),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=Ir(t,o.children,n);if(d!==-1)return o.children.splice(d,1),s.push(o),this._condense(s),this}!u&&!o.leaf&&xt(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=We(t.slice(n,o+1)),Ke(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=We([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));No(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);No(t,d,f,a,this.compareMinY);for(let h=d;h<=f;h+=a){const p=Math.min(h+a-1,f);l.children.push(this._build(t,h,p,i-1))}}return Ke(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=Qt(u),f=Dr(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),ct(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=We(o.children.splice(r,o.children.length-r));l.height=o.height,l.leaf=o.leaf,Ke(o,this.toBBox),Ke(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=We([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Ke(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=at(t,0,l,this.toBBox),u=at(t,l,o,this.toBBox),d=Rr(a,u),f=Qt(a)+Qt(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:Cr,s=t.leaf?this.compareMinY:Or,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=at(t,0,n,s),l=at(t,o-n,o,s);let a=_t(r)+_t(l);for(let u=n;u<o-n;u++){const d=t.children[u];ct(r,t.leaf?s(d):d),a+=_t(r)}for(let u=o-n-1;u>=n;u--){const d=t.children[u];ct(l,t.leaf?s(d):d),a+=_t(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)ct(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():Ke(t[n],this.toBBox)}}function Ir(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 Ke(e,t){at(e,0,e.children.length,t,e)}function at(e,t,n,o,i){i||(i=We(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];ct(i,e.leaf?o(r):r)}return i}function ct(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 Cr(e,t){return e.minX-t.minX}function Or(e,t){return e.minY-t.minY}function Qt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function _t(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Dr(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 Rr(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 xt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function wt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function We(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function No(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;Ro(e,r,t,n,i),s.push(t,r,r,n)}}const Nr=()=>{const e=new Lr,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!ot(f))return;const{minX:h,minY:p,maxX:m,maxY:g}=f.selector.geometry.bounds,k={minX:h,minY:p,maxX:m,maxY:g,target:f};e.insert(k),t.set(f.annotation,k)},s=f=>{if(!ot(f))return;const h=t.get(f.annotation);h&&e.remove(h),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,h,p=0)=>{const g=e.search({minX:f-p,minY:h-p,maxX:f+p,maxY:h+p}).map(k=>k.target).filter(k=>k.selector.type===Q.RECTANGLE||_n(k.selector,f,h,p));return g.length>0?(g.sort((k,E)=>dt(k.selector)-dt(E.selector)),g):[]},getIntersecting:(f,h,p,m)=>e.search({minX:f,minY:h,maxX:f+p,maxY:h+m}).map(g=>g.target),insert:i,remove:s,set:(f,h=!0)=>{h&&o();const p=f.reduce((m,g)=>{if(ot(g)){const{minX:k,minY:E,maxX:S,maxY:_}=g.selector.geometry.bounds;return[...m,{minX:k,minY:E,maxX:S,maxY:_,target:g}]}else return m},[]);p.forEach(m=>t.set(m.target.annotation,m)),e.load(p)},size:()=>e.all().length,update:(f,h)=>{s(f),i(h)}}},Uo=e=>{const t=Gi(),n=Nr(),o=Ti(t,e.userSelectAction,e.adapter),i=Mi(t),s=Ki();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 p=h[0];return p?t.getAnnotation(p.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}},Yo=e=>{const t=Uo(e);return{...t,store:ji(t.store)}},Bo=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},Vo=e=>{const t=Bo(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},$t=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Vo(e):n),Xo=(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}),en=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Ho=(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=()=>{en?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return en?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Ur=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=Xo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Rt.EDIT,theme:"light"}),i=Yo(o),{selection:s,store:r}=i,l=qi(r,o.initialHistory),a=Wi(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=Ho(l);let f=is();$t(n,u,o.theme);const h=new Do({target:u,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});h.$on("click",w=>{const{originalEvent:v,annotation:y}=w.detail;y?s.userSelect(y.id,v):s.isEmpty()||s.clear()});const p=Ji(i,l,o.adapter),m=()=>h.cancelDrawing(),g=()=>{h.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),l.destroy()},k=()=>h.getDrawingTool(),E=()=>f,S=()=>h.isDrawingEnabled(),_=(w,v,y)=>wo(w,v,y),A=(w,v)=>fo(w,v),M=w=>{if(!Wt(w))throw`No drawing tool named ${w}`;h.$set({toolName:w})},C=w=>h.$set({drawingEnabled:w}),T=w=>{console.warn("Filter not implemented yet")},V=w=>h.$set({style:w}),U=w=>$t(n,u,w),W=w=>{f=w,h.$set({user:w})},q=w=>h.$set({visible:w});return{...p,cancelDrawing:m,destroy:g,getDrawingTool:k,getUser:E,isDrawingEnabled:S,listDrawingTools:Kt,on:a.on,off:a.off,registerDrawingTool:_,registerShapeEditor:A,setDrawingEnabled:C,setDrawingTool:M,setFilter:T,setStyle:V,setTheme:U,setUser:W,setVisible:q,element:u,state:i}};O.Editor=yt,O.EditorMount=ho,O.Handle=Xe,O.IdentityTransform=pr,O.MidpointHandle=Yt,O.PolygonEditor=Qn,O.RectangleEditor=xn,O.RectangleUtil=Sn,O.RubberbandRectangle=po,O.SVGAnnotationLayer=Do,O.ShapeType=Q,O.ToolMount=go,O.UserSelectAction=Rt,O.W3CImageFormat=us,O.addEventListeners=So,O.approximateAsPolygon=ht,O.boundsFromMultiPolygonElements=tt,O.boundsFromPoints=fe,O.chainStyles=xi,O.computeArea=dt,O.computePolygonArea=xe,O.computeSVGPath=It,O.computeStyle=Qi,O.createBody=Ri,O.createImageAnnotator=Ur,O.createImageAnnotatorState=Uo,O.createSVGTransform=vo,O.createSvelteImageAnnotatorState=Yo,O.defaultColorProvider=cs,O.detectTheme=Vo,O.distance=et,O.enableResponsive=Xn,O.fillDefaults=Xo,O.getAllCorners=bn,O.getEditor=uo,O.getMaskDimensions=it,O.getSVGPoint=Zt,O.getTool=Wt,O.initKeyboardCommands=Ho,O.intersects=_n,O.isImageAnnotation=nt,O.isImageAnnotationTarget=ot,O.isMac=en,O.isPointInPolygon=$e,O.isTouch=Le,O.listDrawingTools=Kt,O.multipolygonElementToPath=Pe,O.parseFragmentSelector=An,O.parseSVGSelector=Ln,O.parseW3CImageAnnotation=Bn,O.pointsToPath=wn,O.registerEditor=fo,O.registerShapeUtil=Be,O.registerTool=wo,O.sampleBrightness=Bo,O.serializeFragmentSelector=kn,O.serializeSVGSelector=In,O.serializeW3CImageAnnotation=Vn,O.setTheme=$t,O.simplifyMultiPolygon=ri,O.simplifyPoints=Lt,O.simplifyPolygon=ai,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 zo(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 qo(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 Ko(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 Wo(e,t,n,o,i,s){if(i){const r=cn(t,n,o,s);e.p(r,i)}}function Zo(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 Jo(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function Qo(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=Qo(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),xo(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 xo(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 $o(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&&($o(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function ei(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&&ei(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=Jo(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&&!zo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ti="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ti);var Q=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(Q||{});function ni(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 oi=_n.exports;const ii=ni(oi),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 ii(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))},si={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,si);const ri={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,ri);const li={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],[])],[]),ai=(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,li);const ci={area:e=>{const t=e.geometry.points;return $e(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return et(o,t,n)}},ui=(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,ci);const fi={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 di(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},di=(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,fi);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,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[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}}}},Mn=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}`}},Tn="http://www.w3.org/2000/svg",Pn=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},hi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Tn}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},mt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Tn),i=n.lookupNamespaceURI(null);return o||i?Pn(n).firstChild:Pn(hi(n)).firstChild},gi=e=>{const t=Ln(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}}},mi=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},pi=e=>{const t=Ln(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=>mi(r)?{...r,locked:!0}:r);const s=fe(gt(n,i));return{points:n,closed:i,bounds:s}},Ln=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},yi=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)}}},_i=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}}},wi=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}}},bi=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=pi(o);if(!i)throw new Error("Could not parse SVG path");return{type:Q.POLYLINE,geometry:i}},Ei=e=>{const t=mt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>gi(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}}},In=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return yi(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return bi(t);if(t.includes("<path "))return Ei(t);if(t.includes("<ellipse "))return _i(t);if(t.includes("<line "))return wi(t);throw"Unsupported SVG shape: "+t},vi=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Le(n)}" />`).join("")}</g>`,Cn=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>${vi(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 Si(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 Ai=new Uint8Array(16);function ki(){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(Ai)}const On={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Mi(e,t,n){var i;e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??ki();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,Si(o)}function Dn(e,t,n){return On.randomUUID&&!e?On.randomUUID():Mi(e)}var Bn=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(Bn.call(e,n)&&++o&&!Bn.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 Ti=Symbol("clean"),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 process.env.NODE_ENV!=="production"&&(n[Ti]=()=>{t=[],n.lc=0,n.off()}),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),Nn={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 Un(e,t,n){return Nn.randomUUID&&!e?Nn.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:Un(),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),Yn=(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 Yn(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?Un():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=Yn(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}`},Rn=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:Rn(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=>Vn(i,t),serialize:i=>Xn(i,e,t)}),Vn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Dn(),{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=typeof d=="string"||(d==null?void 0:d.type)==="FragmentSelector"?kn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?In(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:Rn(o),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Xn=(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?Mn(o.geometry):Cn(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,"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}`)},Hn=(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)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i,stroke:s,strokeWidth:r,strokeOpacity:l}=n;let a="";return o&&(a+=`fill:${o};`),i||i===0?a+=`fill-opacity:${i};`:o&&(a+="fill-opacity:0.25;"),s&&(a+=`stroke:${s};`,a+=`stroke-width:${r||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}},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=>({}),Gn=e=>({grab:e[0]});function ms(e){let t,n,o,i;const s=e[8].default,r=qo(s,e,e[7],Gn);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)&&Wo(r,s,l,l[7],n?Ko(s,l[7],a,gs):Zo(l[7]),Gn)},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]&&jn(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=jn(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 jn(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 Fn(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 zn(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 qn(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 Kn(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 Wn(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]&&zn(Ht(e)),M=e[6]!==void 0&&!e[7]&&qn(Xt(e)),V=ve(e[5].points),U=[];for(let _=0;_<V.length;_+=1)U[_]=Kn(Fn(e,V,_));const W=_=>G(U[_],1,1,()=>{U[_]=null});let q=e[6]!==void 0&&!e[7]&&Wn(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(Zn).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(Jn).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(Qn).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(Zn).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Ht(e),v):(C=zn(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=qn(Xt(e)),M.c(),M.m(t,null)):M&&(M.d(1),M=null),(!w||v[0]&32&&h!==(h=e[5].points.map(Jn).join(" ")))&&c(f,"points",h),(!w||v[0]&2)&&c(m,"style",e[1]),(!w||v[0]&32&&p!==(p=e[5].points.map(Qn).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=Fn(e,V,y);U[y]?(U[y].p(E,v),R(U[y],1)):(U[y]=Kn(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=Wn(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,Zn=e=>e.join(","),Jn=e=>e.join(","),Qn=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 xn 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,Fo;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||(Fo=[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(Fo)}}}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 $n extends ge{constructor(t){super(),he(this,t,Ds,Os,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var eo=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(eo.call(e,n)&&++o&&!eo.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 to(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function no(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function oo(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 io(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 so(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 ro(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 lo(e){let t,n,o=ve(e[33].points),i=[];for(let r=0;r<o.length;r+=1)i[r]=ro(oo(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=oo(r,o,a);i[a]?(i[a].p(u,l),R(i[a],1)):(i[a]=ro(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 ao(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]&&io(zt(e)),w=e[6]!==void 0&&!e[7]&&so(Ft(e)),A=ve(e[30].rings),T=[];for(let M=0;M<A.length;M+=1)T[M]=lo(no(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=io(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=so(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=no(e,A,U);T[U]?(T[U].p(W,V),R(T[U],1)):(T[U]=lo(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 co(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]=ao(to(e,i,a));const r=a=>G(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&co(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=to(a,i,d);s[d]?(s[d].p(f,u),R(s[d],1)):(s[d]=ao(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=co(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 uo=new Map([[Q.RECTANGLE,$n],[Q.POLYGON,xn],[Q.MULTIPOLYGON,Hs]]),fo=e=>uo.get(e.type),ho=(e,t)=>uo.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)),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 go 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 mo extends ge{constructor(t){super(),he(this,t,js,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function po(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]&&po(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=po(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 yo 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 _o(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p=e[1]&&wo(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=wo(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 wo(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]&&_o(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=_o(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:yo}],["polygon",{tool:Js}]]),Wt=()=>[...Kt.keys()],Zt=e=>Kt.get(e),bo=(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 Eo(e,t,n){const o=e.slice();return o[5]=t[n],o}function vo(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]=vo(Eo(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=Eo(s,o,l);i[l]?i[l].p(a,r):(i[l]=vo(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]},So=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,Ao=(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 ko(e,t,n){const o=e.slice();return o[39]=t[n],o}function Mo(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 To(e){let t=e[42],n,o,i=Po(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=Po(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 Po(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 Lo(e){let t=ot(e[42])&&!e[10](e[42]),n,o,i=t&&To(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=To(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 Io(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=Co(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=Co(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]=Do(ko(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=ko(r,o,a);i[a]?(i[a].p(u,l),R(i[a],1)):(i[a]=Do(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;return t=new mo({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 Oo(e){let t,n;return t=new go({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 Do(e){let t=e[39].annotation.id,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]&64&&re(t,t=s[39].annotation.id)?(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 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]=Lo(Mo(e,l,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&Io(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=Mo(e,l,g);a[g]?(a[g].p(m,h),R(a[g],1)):(a[g]=Lo(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=Io(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=Hn(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=Dn(),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=So(y)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=Ao(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:fo(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 Bo 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 No(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));No(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));Uo(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);Uo(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 Uo(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;No(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)}}},Yo=e=>({...e,subscribe:n=>{const o=i=>n(i.state);return e.observe(o),n(e.all()),()=>e.unobserve(o)}}),Ro=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}},Vo=e=>{const t=Ro(e);return{...t,store:Yo(t.store)}},Xo=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},Ho=e=>{const t=Xo(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"?Ho(e):n),Go=(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,jo=(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=Go(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Bt.EDIT,theme:"light"}),i=Vo(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=jo(l);let f=ss();en(n,u,o.theme);const h=new Bo({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)=>bo(_,v,y),A=(_,v)=>ho(_,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=go,O.Handle=Ge,O.IdentityTransform=yr,O.MidpointHandle=Rt,O.PolygonEditor=xn,O.RectangleEditor=$n,O.RectangleUtil=An,O.RubberbandRectangle=yo,O.SVGAnnotationLayer=Bo,O.ShapeType=Q,O.ToolMount=mo,O.UserSelectAction=Bt,O.W3CImageFormat=fs,O.addEventListeners=Ao,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=Ro,O.createSVGTransform=So,O.createSvelteImageAnnotatorState=Vo,O.defaultColorProvider=us,O.detectTheme=Ho,O.distance=tt,O.enableResponsive=Hn,O.fillDefaults=Go,O.getAllCorners=En,O.getEditor=fo,O.getMaskDimensions=st,O.getSVGPoint=Jt,O.getTool=Zt,O.initKeyboardCommands=jo,O.intersects=wn,O.isImageAnnotation=ot,O.isImageAnnotationTarget=it,O.isMac=tn,O.isPointInPolygon=et,O.isTouch=Ie,O.listDrawingTools=Wt,O.multipolygonElementToPath=Le,O.parseFragmentSelector=kn,O.parseSVGSelector=In,O.parseW3CImageAnnotation=Vn,O.pointsToPath=bn,O.registerEditor=ho,O.registerShapeUtil=Xe,O.registerTool=bo,O.sampleBrightness=Xo,O.serializeFragmentSelector=Mn,O.serializeSVGSelector=Cn,O.serializeW3CImageAnnotation=Xn,O.setTheme=en,O.simplifyMultiPolygon=ai,O.simplifyPoints=It,O.simplifyPolygon=ui,O.toSvelteStore=Yo,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=annotorious.js.map
|