@annotorious/annotorious 3.7.22 → 3.8.0
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/annotation/editors/rectangle/rotationUtils.d.ts +26 -0
- package/dist/annotorious.css +1 -1
- package/dist/annotorious.es.js +3362 -3209
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +1 -1
- package/dist/annotorious.js.map +1 -1
- package/dist/model/core/rectangle/Rectangle.d.ts +1 -0
- package/package.json +2 -2
- package/src/Annotorious.css +1 -0
- package/src/annotation/SVGAnnotationLayer.svelte +3 -3
- package/src/annotation/editors/rectangle/RectangleEditor.svelte +184 -68
- package/src/annotation/editors/rectangle/rotationUtils.ts +104 -0
- package/src/annotation/shapes/Rectangle.svelte +22 -15
- package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +1 -0
- package/src/model/core/rectangle/Rectangle.ts +2 -0
- package/src/model/core/rectangle/rectangleUtils.ts +31 -5
- package/src/model/w3c/W3CImageFormatAdapter.ts +6 -4
- package/src/model/w3c/fragment/FragmentSelector.ts +1 -0
- package/src/model/w3c/svg/SVGSelector.ts +81 -0
- package/src/state/spatialTree.ts +2 -5
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 Rr=Object.defineProperty;var Vr=(O,j,Ce)=>j in O?Rr(O,j,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):O[j]=Ce;var sn=(O,j,Ce)=>Vr(O,typeof j!="symbol"?j+"":j,Ce);function j(){}function Ce(e,t){for(const n in t)e[n]=t[n];return e}function rn(e){return e()}function ln(){return Object.create(null)}function Ae(e){e.forEach(rn)}function ie(e){return typeof e=="function"}function re(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function qo(e){return Object.keys(e).length===0}function an(e,...t){if(e==null){for(const o of t)o(void 0);return j}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function kt(e,t,n){e.$$.on_destroy.push(an(t,n))}function Ko(e,t,n,o){if(e){const i=cn(e,t,n,o);return e[0](i)}}function cn(e,t,n,o){return e[1]&&o?Ce(n.ctx.slice(),e[1](o(t))):n.ctx}function Wo(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let l=0;l<r;l+=1)s[l]=t.dirty[l]|i[l];return s}return t.dirty|i}return t.dirty}function Zo(e,t,n,o,i,s){if(i){const r=cn(t,n,o,s);e.p(r,i)}}function Jo(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function un(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function je(e){return e??""}function z(e,t){e.appendChild(t)}function N(e,t,n){e.insertBefore(t,n||null)}function B(e){e.parentNode&&e.parentNode.removeChild(e)}function Ye(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function L(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function fn(e){return document.createTextNode(e)}function we(){return fn(" ")}function ke(){return fn("")}function J(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function c(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Qo(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function xo(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Qe;function xe(e){Qe=e}function dn(){if(!Qe)throw new Error("Function called outside component initialization");return Qe}function Re(e){dn().$$.on_mount.push(e)}function Oe(){const e=dn();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=xo(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function ue(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const Fe=[],ft=[];let ze=[];const hn=[],gn=Promise.resolve();let Mt=!1;function mn(){Mt||(Mt=!0,gn.then(yn))}function pn(){return mn(),gn}function Tt(e){ze.push(e)}const Pt=new Set;let qe=0;function yn(){if(qe!==0)return;const e=Qe;do{try{for(;qe<Fe.length;){const t=Fe[qe];qe++,xe(t),$o(t.$$)}}catch(t){throw Fe.length=0,qe=0,t}for(xe(null),Fe.length=0,qe=0;ft.length;)ft.pop()();for(let t=0;t<ze.length;t+=1){const n=ze[t];Pt.has(n)||(Pt.add(n),n())}ze.length=0}while(Fe.length);for(;hn.length;)hn.pop()();Mt=!1,Pt.clear(),xe(e)}function $o(e){if(e.fragment!==null){e.update(),Ae(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Tt)}}function ei(e){const t=[],n=[];ze.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),ze=t}const dt=new Set;let Ve;function be(){Ve={r:0,c:[],p:Ve}}function Ee(){Ve.r||Ae(Ve.c),Ve=Ve.p}function R(e,t){e&&e.i&&(dt.delete(e),e.i(t))}function G(e,t,n,o){if(e&&e.o){if(dt.has(e))return;dt.add(e),Ve.c.push(()=>{dt.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ve(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ce(e){e&&e.c()}function le(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),Tt(()=>{const s=e.$$.on_mount.map(rn).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ae(s),e.$$.on_mount=[]}),i.forEach(Tt)}function ae(e,t){const n=e.$$;n.fragment!==null&&(ei(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function ti(e,t){e.$$.dirty[0]===-1&&(Fe.push(e),mn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function he(e,t,n,o,i,s,r=null,l=[-1]){const a=Qe;xe(e);const u=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:i,bound:ln(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:ln(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(u.root);let d=!1;if(u.ctx=n?n(e,t.props||{},(f,h,...g)=>{const m=g.length?g[0]:h;return u.ctx&&i(u.ctx[f],u.ctx[f]=m)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](m),d&&ti(e,f)),h}):[],u.update(),d=!0,Ae(u.before_update),u.fragment=o?o(u.ctx):!1,t.target){if(t.hydrate){const f=Qo(t.target);u.fragment&&u.fragment.l(f),f.forEach(B)}else u.fragment&&u.fragment.c();t.intro&&R(e.$$.fragment),le(e,t.target,t.anchor),yn()}xe(a)}class ge{constructor(){sn(this,"$$");sn(this,"$$set")}$destroy(){ae(this,1),this.$destroy=j}$on(t,n){if(!ie(n))return j;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!qo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ni="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ni);var Q=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(Q||{});function oi(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _n={exports:{}};(function(e){(function(){function t(l,a){var u=l.x-a.x,d=l.y-a.y;return u*u+d*d}function n(l,a,u){var d=a.x,f=a.y,h=u.x-d,g=u.y-f;if(h!==0||g!==0){var m=((l.x-d)*h+(l.y-f)*g)/(h*h+g*g);m>1?(d=u.x,f=u.y):m>0&&(d+=h*m,f+=g*m)}return h=l.x-d,g=l.y-f,h*h+g*g}function o(l,a){for(var u=l[0],d=[u],f,h=1,g=l.length;h<g;h++)f=l[h],t(f,u)>a&&(d.push(f),u=f);return u!==f&&d.push(f),d}function i(l,a,u,d,f){for(var h=d,g,m=a+1;m<u;m++){var p=n(l[m],l[a],l[u]);p>h&&(g=m,h=p)}h>d&&(g-a>1&&i(l,a,g,d,f),f.push(l[g]),u-g>1&&i(l,g,u,d,f))}function s(l,a){var u=l.length-1,d=[l[0]];return i(l,0,u,a,d),d.push(l[u]),d}function r(l,a,u){if(l.length<=2)return l;var d=a!==void 0?a*a:1;return l=u?l:o(l,d),l=s(l,d),l}e.exports=r,e.exports.default=r})()})(_n);var ii=_n.exports;const si=oi(ii),Lt={},Xe=(e,t)=>Lt[e]=t,ht=e=>Lt[e.type].area(e),wn=(e,t,n,o)=>Lt[e.type].intersects(e,t,n,o),fe=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},$e=e=>{let t=0,n=e.length-1;for(let o=0;o<e.length;o++)t+=(e[n][0]+e[o][0])*(e[n][1]-e[o][1]),n=o;return Math.abs(.5*t)},et=(e,t,n)=>{let o=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const r=e[i][0],l=e[i][1],a=e[s][0],u=e[s][1];l>n!=u>n&&t<(a-r)*(n-l)/(u-l)+r&&(o=!o)}return o},bn=(e,t=!0)=>{let n="M ";return e.forEach(([o,i],s)=>{s===0?n+=`${o},${i}`:n+=` L ${o},${i}`}),t&&(n+=" Z"),n},It=(e,t=1)=>{const n=e.map(([o,i])=>({x:o,y:i}));return si(n,t,!0).map(o=>[o.x,o.y])},tt=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},ri={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,l=0,a=Math.cos(l),u=Math.sin(l),d=t-o,f=n-i,h=a*d+u*f,g=u*d-a*f;return h*h/(s*s)+g*g/(r*r)<=1}};Xe(Q.ELLIPSE,ri);const li={area:e=>0,intersects:(e,t,n,o=2)=>{const[[i,s],[r,l]]=e.geometry.points,a=Math.abs((l-s)*t-(r-i)*n+r*s-l*i),u=tt([i,s],[r,l]);return a/u<=o}};Xe(Q.LINE,li);const ai={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,o)=>{const[i,...s]=o.rings,r=$e(i.points),l=s.reduce((a,u)=>a+$e(u.points),0);return n+r-l},0)},intersects:(e,t,n)=>{const{polygons:o}=e.geometry;for(const i of o){const[s,...r]=i.rings;if(et(s.points,t,n)){let l=!1;for(const a of r)if(et(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},nt=e=>{const t=e.reduce((n,o)=>[...n,...o.rings[0].points],[]);return fe(t)},Le=e=>e.rings.map(n=>bn(n.points)).join(" "),En=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((o,i)=>[...o,...i.points],[])],[]),ci=(e,t=1)=>{const n=e.geometry.polygons.map(i=>{const s=i.rings.map(l=>{const a=It(l.points,t);return{...l,points:a}}),r=fe(s[0].points);return{...i,rings:s,bounds:r}}),o=nt(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:o}}};Xe(Q.MULTIPOLYGON,ai);const ui={area:e=>{const t=e.geometry.points;return $e(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return et(o,t,n)}},fi=(e,t=1)=>{const n=It(e.geometry.points,t),o=fe(n);return{...e,geometry:{...e.geometry,bounds:o,points:n}}};Xe(Q.POLYGON,ui);const di={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=gt(t.points,t.closed);return $e(n)},intersects:(e,t,n,o=2)=>{const i=e.geometry;if(i.closed){const s=gt(i.points,i.closed);return et(s,t,n)}else return hi(i,[t,n],o)}},gt=(e,t=!1)=>{const n=[];for(let o=0;o<e.length;o++){const i=e[o],s=e[(o+1)%e.length];if(n.push(i.point),(o<e.length-1||t)&&(i.type==="CURVE"||s.type=="CURVE")){const l=vn(i.point,i.type==="CURVE"&&i.outHandle||i.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);n.push(...l.slice(1))}}return n},vn=(e,t,n,o,i=10)=>{const s=[];for(let r=0;r<=i;r++){const l=r/i,a=Math.pow(1-l,3)*e[0]+3*Math.pow(1-l,2)*l*t[0]+3*(1-l)*Math.pow(l,2)*n[0]+Math.pow(l,3)*o[0],u=Math.pow(1-l,3)*e[1]+3*Math.pow(1-l,2)*l*t[1]+3*(1-l)*Math.pow(l,2)*n[1]+Math.pow(l,3)*o[1];s.push([a,u])}return s},hi=(e,t,n)=>{for(let o=0;o<e.points.length-1;o++){const i=e.points[o],s=e.points[o+1];if(i.type==="CURVE"||s.type==="CURVE"){const l=vn(i.point,i.type==="CURVE"&&i.outHandle||i.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let a=0;a<l.length-1;a++)if(Sn(t,l[a],l[a+1])<=n)return!0}else if(Sn(t,i.point,s.point)<=n)return!0}return!1},Sn=(e,t,n)=>{const[o,i]=e,[s,r]=t,[l,a]=n,u=l-s,d=a-r,f=Math.sqrt(u*u+d*d);if(f===0)return Math.sqrt((o-s)*(o-s)+(i-r)*(i-r));const h=((o-s)*u+(i-r)*d)/(f*f);return h<=0?Math.sqrt((o-s)*(o-s)+(i-r)*(i-r)):h>=1?Math.sqrt((o-l)*(o-l)+(i-a)*(i-a)):Math.abs((a-r)*o-(l-s)*i+l*r-a*s)/f},Ct=e=>{if(!e.points||e.points.length===0)return"";const t=[],n=e.points[0];t.push(`M ${n.point[0]} ${n.point[1]}`);for(let o=1;o<e.points.length;o++){const i=e.points[o],s=e.points[o-1];if(i.type==="CURVE"||s.type==="CURVE"){const r=s.type==="CURVE"&&s.outHandle||s.point,l=i.type==="CURVE"&&i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}else t.push(`L ${i.point[0]} ${i.point[1]}`)}if(e.closed){const o=e.points[e.points.length-1],i=e.points[0];if(o.type==="CURVE"||i.type==="CURVE"){const r=o.outHandle||o.point,l=i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Xe(Q.POLYLINE,di);const An={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};Xe(Q.RECTANGLE,An);const ot=e=>it(e.target),it=e=>{var t,n;return(e==null?void 0:e.annotation)!==void 0&&((n=(t=e==null?void 0:e.selector)==null?void 0:t.geometry)==null?void 0:n.bounds)!==void 0},kn=e=>(e==null?void 0:e.type)==="FragmentSelector"?!0:typeof e=="string"?e.indexOf("#")<0?!1:/#xywh(?:=(?:pixel:|percent:)?)(.+?),(.+?),(.+?),(.+)$/i.test(e):!1,Mn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(?:(pixel|percent):)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0];if(!i)throw new Error("Not a MediaFragment: "+n);const[s,r,l,a,u,d,f]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[h,g,m,p]=[a,u,d,f].map(parseFloat);return{type:Q.RECTANGLE,geometry:{x:h,y:g,w:m,h:p,bounds:{minX:h,minY:t?g-p:g,maxX:h+m,maxY:t?g:g+p}}}},Tn=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},Pn="http://www.w3.org/2000/svg",Ln=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},gi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Pn}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},mt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Pn),i=n.lookupNamespaceURI(null);return o||i?Ln(n).firstChild:Ln(gi(n)).firstChild},mi=e=>{const t=In(e),n=[];let o=[],i=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":o.length>0&&(n.push({points:o}),o=[]),i=[s.args[0],s.args[1]],o.push([...i]);break;case"L":i=[s.args[0],s.args[1]],o.push([...i]);break;case"H":i=[s.args[0],i[1]],o.push([...i]);break;case"V":i=[i[0],s.args[0]],o.push([...i]);break;case"C":i=[s.args[4],s.args[5]],o.push([...i]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(o.length>2&&n.push({points:o}),n.length>0){const s=fe(n[0].points);return{rings:n,bounds:s}}},pi=e=>{const{point:t,inHandle:n,outHandle:o}=e;if(!n||!o)return!1;const i=n[0]-t[0],s=n[1]-t[1],r=o[0]-t[0],l=o[1]-t[1],a=i*l-s*r;return Math.abs(a)<.01},yi=e=>{const t=In(e);let n=[],o=[0,0],i=!1;for(let r=0;r<t.length;r++){const l=t[r];switch(l.type.toUpperCase()){case"M":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"L":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"C":const a=[l.args[0],l.args[1]],u=[l.args[2],l.args[3]],d=[l.args[4],l.args[5]];if(n.length>0){const h=n[n.length-1];(a[0]!==h.point[0]||a[1]!==h.point[1])&&(h.type="CURVE",h.outHandle=a)}const f={type:u[0]!==d[0]||u[1]!==d[1]?"CURVE":"CORNER",point:d};f.type==="CURVE"&&(f.inHandle=u),n.push(f),o=d;break;case"Z":i=!0;break;default:console.warn(`Unsupported SVG path command: ${l.type}`);break}}n=n.map(r=>pi(r)?{...r,locked:!0}:r);const s=fe(gt(n,i));return{points:n,closed:i,bounds:s}},In=e=>{const t=[],n=e.replace(/,/g," ").trim(),o=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let i;for(;(i=o.exec(n))!==null;){const[,s,r]=i,l=r.trim()===""?[]:r.trim().split(/\s+/).map(Number).filter(a=>!isNaN(a));t.push({type:s,args:l})}return t},_i=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:Q.POLYGON,geometry:{points:i,bounds:fe(i)}}},wi=e=>{const t=mt(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:Q.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},bi=e=>{const t=mt(e),n=parseFloat(t.getAttribute("x1")),o=parseFloat(t.getAttribute("x2")),i=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),r={minX:Math.min(n,o),minY:Math.min(i,s),maxX:Math.max(n,o),maxY:Math.max(i,s)};return{type:Q.LINE,geometry:{points:[[n,i],[o,s]],bounds:r}}},Ei=e=>{const t=mt(e),n=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],o=n==null?void 0:n.getAttribute("d");if(!o)throw new Error("Could not parse SVG path");const i=yi(o);if(!i)throw new Error("Could not parse SVG path");return{type:Q.POLYLINE,geometry:i}},vi=e=>{const t=mt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>mi(a)).filter(Boolean),s=i.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=fe(s);return i.length===1&&i[0].rings.length===1?{type:Q.POLYGON,geometry:{points:s,bounds:r}}:{type:Q.MULTIPOLYGON,geometry:{polygons:i,bounds:r}}},Cn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return _i(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return Ei(t);if(t.includes("<path "))return vi(t);if(t.includes("<ellipse "))return wi(t);if(t.includes("<line "))return bi(t);throw"Unsupported SVG shape: "+t},Si=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Le(n)}" />`).join("")}</g>`,On=e=>{let t;switch(e.type){case Q.POLYGON:{const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`;break}case Q.ELLIPSE:{const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;break}case Q.MULTIPOLYGON:{const n=e.geometry;t=`<svg>${Si(n)}</svg>`;break}case Q.LINE:{const n=e.geometry,[[o,i],[s,r]]=n.points;t=`<svg><line x1="${o}" y1="${i}" x2="${s}" y2="${r}" /></svg>`;break}case Q.POLYLINE:t=`<svg><path d="${Ct(e.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},me=[];for(let e=0;e<256;++e)me.push((e+256).toString(16).slice(1));function Ai(e,t=0){return(me[e[t+0]]+me[e[t+1]]+me[e[t+2]]+me[e[t+3]]+"-"+me[e[t+4]]+me[e[t+5]]+"-"+me[e[t+6]]+me[e[t+7]]+"-"+me[e[t+8]]+me[e[t+9]]+"-"+me[e[t+10]]+me[e[t+11]]+me[e[t+12]]+me[e[t+13]]+me[e[t+14]]+me[e[t+15]]).toLowerCase()}let Ot;const ki=new Uint8Array(16);function Mi(){if(!Ot){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ot=crypto.getRandomValues.bind(crypto)}return Ot(ki)}const Dn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ti(e,t,n){var i;e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Mi();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Ai(o)}function Bn(e,t,n){return Dn.randomUUID&&!e?Dn.randomUUID():Ti(e)}var Nn=Object.prototype.hasOwnProperty;function De(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&De(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Nn.call(e,n)&&++o&&!Nn.call(t,n)||!(n in t)||!De(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}let Me=[],Be=0;const pt=4,Dt=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},lc:0,listen(o){return n.lc=t.push(o),()=>{for(let s=Be+pt;s<Me.length;)Me[s]===o?Me.splice(s,pt):s+=pt;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){let s=!Me.length;for(let r of t)Me.push(r,n.value,o,i);if(s){for(Be=0;Be<Me.length;Be+=pt)Me[Be](Me[Be+1],Me[Be+2],Me[Be+3]);Me.length=0}},off(){},set(o){let i=n.value;i!==o&&(n.value=o,n.notify(i))},subscribe(o){let i=n.listen(o);return o(n.value),i},value:e};return n},Pi=e=>{const t=Dt(null);return e.observe(({changes:n})=>{const o=t.get();if(o){(n.deleted||[]).some(s=>s.id===o)&&t.set(null);const i=(n.updated||[]).find(({oldValue:s})=>s.id===o);i&&t.set(i.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var Bt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Bt||{});const Nt={selected:[]},Li=(e,t,n)=>{const o=Dt(Nt);let i=t;const s=()=>{De(o.get(),Nt)||o.set(Nt)},r=()=>{var g;return((g=o.get().selected)==null?void 0:g.length)===0},l=g=>{if(r())return!1;const m=typeof g=="string"?g:g.id;return o.get().selected.some(p=>p.id===m)},a=(g,m)=>{let p;if(Array.isArray(g)){if(p=g.map(E=>e.getAnnotation(E)).filter(Boolean),p.length<g.length){console.warn("Invalid selection: "+g.filter(E=>!p.some(S=>S.id===E)));return}}else{const E=e.getAnnotation(g);if(!E){console.warn("Invalid selection: "+g);return}p=[E]}const k=p.reduce((E,S)=>{const w=h(S);return w==="EDIT"?[...E,{id:S.id,editable:!0}]:w==="SELECT"?[...E,{id:S.id}]:E},[]);o.set({selected:k,event:m})},u=(g,m)=>{const p=Array.isArray(g)?g:[g],k=p.map(E=>e.getAnnotation(E)).filter(E=>!!E);o.set({selected:k.map(E=>{const S=m===void 0?h(E)==="EDIT":m;return{id:E.id,editable:S}})}),k.length!==p.length&&console.warn("Invalid selection",g)},d=g=>{if(r())return!1;const{selected:m}=o.get();m.some(({id:p})=>g.includes(p))&&o.set({selected:m.filter(({id:p})=>!g.includes(p))})},f=g=>{i=g,u(o.get().selected.map(({id:m})=>m))},h=g=>Ii(g,i,n);return e.observe(({changes:g})=>d((g.deleted||[]).map(m=>m.id))),{get event(){const g=o.get();return g?g.event:null},get selected(){const g=o.get();return g?[...g.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:h,isEmpty:r,isSelected:l,setSelected:u,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:a}},Ii=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},pe=[];for(let e=0;e<256;++e)pe.push((e+256).toString(16).slice(1));function Ci(e,t=0){return(pe[e[t+0]]+pe[e[t+1]]+pe[e[t+2]]+pe[e[t+3]]+"-"+pe[e[t+4]]+pe[e[t+5]]+"-"+pe[e[t+6]]+pe[e[t+7]]+"-"+pe[e[t+8]]+pe[e[t+9]]+"-"+pe[e[t+10]]+pe[e[t+11]]+pe[e[t+12]]+pe[e[t+13]]+pe[e[t+14]]+pe[e[t+15]]).toLowerCase()}let Ut;const Oi=new Uint8Array(16);function Di(){if(!Ut){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ut=crypto.getRandomValues.bind(crypto)}return Ut(Oi)}const Bi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Un={randomUUID:Bi};function Ni(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Di();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Ci(i)}function Yn(e,t,n){return Un.randomUUID&&!e?Un.randomUUID():Ni(e)}const Yt=e=>{const t=n=>{const o={...n};return n.created&&typeof n.created=="string"&&(o.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(o.updated=new Date(n.updated)),o};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Ui=(e,t,n,o)=>({id:Yn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Yi=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Ri=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Vi=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!De(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Xi=(e,t)=>!De(e.target,t.target),Rn=(e,t)=>{const n=Yi(e,t),o=Ri(e,t),i=Vi(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Xi(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var ne=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(ne||{});const Hi=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,l=a=>a&&a.length>0;if(!(l(i.created)||l(i.deleted))){const a=(n=i.updated)==null?void 0:n.some(d=>l(d.bodiesCreated)||l(d.bodiesDeleted)||l(d.bodiesUpdated)),u=(o=i.updated)==null?void 0:o.some(d=>d.targetUpdated);if(r==="BODY_ONLY"&&a&&!u||r==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const r=new Set([...(i.created||[]).map(l=>l.id),...(i.deleted||[]).map(l=>l.id),...(i.updated||[]).map(({oldValue:l})=>l.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(l=>r.has(l))}else return!0},Gi=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),l=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),a=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:h})=>h.id===f.id).newValue:f),...t.created||[]],u=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],d=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:h,newValue:g}=f;if(r.has(g.id)){const m=t.updated.find(p=>p.oldValue.id===g.id).newValue;return Rn(h,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:u,updated:d}},yt=e=>{const t=e.id===void 0?Yn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},ji=e=>e.id!==void 0,Fi=()=>{const e=new Map,t=new Map,n=[],o=(v,b={})=>{n.push({onChange:v,options:b})},i=v=>{const b=n.findIndex(y=>y.onChange==v);b>-1&&n.splice(b,1)},s=(v,b)=>{const y={origin:v,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(_=>{Hi(_,y)&&_.onChange(y)})},r=(v,b=ne.LOCAL)=>{if(v.id&&e.get(v.id))throw Error(`Cannot add annotation ${v.id} - exists already`);{const y=yt(v);e.set(y.id,y),y.bodies.forEach(_=>t.set(_.id,y.id)),s(b,{created:[y]})}},l=(v,b)=>{const y=yt(typeof v=="string"?b:v),_=typeof v=="string"?v:v.id,I=_&&e.get(_);if(I){const P=Rn(I,y);return _===y.id?e.set(_,y):(e.delete(_),e.set(y.id,y)),I.bodies.forEach(D=>t.delete(D.id)),y.bodies.forEach(D=>t.set(D.id,y.id)),P}else console.warn(`Cannot update annotation ${_} - does not exist`)},a=(v,b=ne.LOCAL,y=ne.LOCAL)=>{const _=ji(b)?y:b,I=l(v,b);I&&s(_,{updated:[I]})},u=(v,b=ne.LOCAL)=>{e.get(v.id)?a(v,b):r(v,b)},d=(v,b=ne.LOCAL)=>{const y=v.reduce((_,I)=>{const P=l(I);return P?[..._,P]:_},[]);y.length>0&&s(b,{updated:y})},f=(v,b=ne.LOCAL)=>{const y=v.map(yt),{toAdd:_,toUpdate:I}=y.reduce((D,F)=>e.get(F.id)?{...D,toUpdate:[...D.toUpdate,F]}:{...D,toAdd:[...D.toAdd,F]},{toAdd:[],toUpdate:[]}),P=I.map(D=>l(D,b)).filter(Boolean);_.forEach(D=>{e.set(D.id,D),D.bodies.forEach(F=>t.set(F.id,D.id))}),s(b,{created:_,updated:P})},h=(v,b=ne.LOCAL)=>{const y=e.get(v.annotation);if(y){const _={...y,bodies:[...y.bodies,v]};e.set(y.id,_),t.set(v.id,_.id),s(b,{updated:[{oldValue:y,newValue:_,bodiesCreated:[v]}]})}else console.warn(`Attempt to add body to missing annotation: ${v.annotation}`)},g=()=>[...e.values()],m=(v=ne.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(v,{deleted:b})},p=(v,b=!0,y=ne.LOCAL)=>{const _=v.map(yt);if(b){const I=[...e.values()];e.clear(),t.clear(),_.forEach(P=>{e.set(P.id,P),P.bodies.forEach(D=>t.set(D.id,P.id))}),s(y,{created:_,deleted:I})}else{const I=v.reduce((P,D)=>{const F=D.id&&e.get(D.id);return F?[...P,F]:P},[]);if(I.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${I.map(P=>P.id).join(", ")}`);_.forEach(P=>{e.set(P.id,P),P.bodies.forEach(D=>t.set(D.id,P.id))}),s(y,{created:_})}},k=v=>{const b=typeof v=="string"?v:v.id,y=e.get(b);if(y)return e.delete(b),y.bodies.forEach(_=>t.delete(_.id)),y;console.warn(`Attempt to delete missing annotation: ${b}`)},E=(v,b=ne.LOCAL)=>{const y=k(v);y&&s(b,{deleted:[y]})},S=(v,b=ne.LOCAL)=>{const y=v.reduce((_,I)=>{const P=k(I);return P?[..._,P]:_},[]);y.length>0&&s(b,{deleted:y})},w=v=>{const b=e.get(v.annotation);if(b){const y=b.bodies.find(_=>_.id===v.id);if(y){t.delete(y.id);const _={...b,bodies:b.bodies.filter(I=>I.id!==v.id)};return e.set(b.id,_),{oldValue:b,newValue:_,bodiesDeleted:[y]}}else console.warn(`Attempt to delete missing body ${v.id} from annotation ${v.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${v.annotation}`)},A=(v,b=ne.LOCAL)=>{const y=w(v);y&&s(b,{updated:[y]})},T=(v,b=ne.LOCAL)=>{const y=v.map(_=>w(_)).filter(Boolean);y.length>0&&s(b,{updated:y})},C=v=>{const b=e.get(v);return b?{...b}:void 0},M=v=>{const b=t.get(v);if(b){const y=C(b).bodies.find(_=>_.id===v);if(y)return y;console.error(`Store integrity error: body ${v} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${v}`)},V=(v,b)=>{if(v.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const y=e.get(v.annotation);if(y){const _=y.bodies.find(P=>P.id===v.id),I={...y,bodies:y.bodies.map(P=>P.id===_.id?b:P)};return e.set(y.id,I),_.id!==b.id&&(t.delete(_.id),t.set(b.id,I.id)),{oldValue:y,newValue:I,bodiesUpdated:[{oldBody:_,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${v.annotation}`)},U=(v,b,y=ne.LOCAL)=>{const _=V(v,b);_&&s(y,{updated:[_]})},W=(v,b=ne.LOCAL)=>{const y=v.map(_=>V({id:_.id,annotation:_.annotation},_)).filter(Boolean);s(b,{updated:y})},q=v=>{const b=e.get(v.annotation);if(b){const y={...b,target:{...b.target,...v}};return e.set(b.id,y),{oldValue:b,newValue:y,targetUpdated:{oldTarget:b.target,newTarget:v}}}else console.warn(`Attempt to update target on missing annotation: ${v.annotation}`)};return{addAnnotation:r,addBody:h,all:g,bulkAddAnnotations:p,bulkDeleteAnnotations:S,bulkDeleteBodies:T,bulkUpdateAnnotations:d,bulkUpdateBodies:W,bulkUpdateTargets:(v,b=ne.LOCAL)=>{const y=v.map(_=>q(_)).filter(Boolean);y.length>0&&s(b,{updated:y})},bulkUpsertAnnotations:f,clear:m,deleteAnnotation:E,deleteBody:A,getAnnotation:C,getBody:M,observe:o,unobserve:i,updateAnnotation:a,updateBody:U,updateTarget:(v,b=ne.LOCAL)=>{const y=q(v);y&&s(b,{updated:[y]})},upsertAnnotation:u}};let zi=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const qi=250,Ki=(e,t)=>{const n=zi(),o=(t==null?void 0:t.changes)||[];let i=t?t.pointer:-1,s=!1,r=0;const l=m=>{if(!s){const{changes:p}=m,k=performance.now();if(k-r>qi)o.splice(i+1),o.push(p),i=o.length-1;else{const E=o.length-1;o[E]=Gi(o[E],p)}r=k}s=!1};e.observe(l,{origin:ne.LOCAL});const a=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m),u=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),d=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({oldValue:p})=>p)),f=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({newValue:p})=>p)),h=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),g=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...o],pointer:i}),on:(m,p)=>n.on(m,p),redo:()=>{if(o.length-1>i){s=!0;const{created:m,updated:p,deleted:k}=o[i+1];u(m),f(p),g(k),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:m,updated:p,deleted:k}=o[i];a(m),d(p),h(k),n.emit("undo",o[i]),i-=1}}}},Wi=()=>{const e=Dt([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},Zi=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],d,f;const h=(E,S)=>{a.has(E)?a.get(E).push(S):a.set(E,[S])},g=(E,S)=>{const w=a.get(E);if(w){const A=w.indexOf(S);A!==-1&&w.splice(A,1)}},m=(E,S,w)=>{a.has(E)&&setTimeout(()=>{a.get(E).forEach(A=>{if(n){const T=Array.isArray(S)?S.map(M=>n.serialize(M)):n.serialize(S),C=w?w instanceof PointerEvent?w:n.serialize(w):void 0;A(T,C)}else A(S,w)})},1)},p=()=>{const{selected:E}=s,S=(E||[]).map(({id:w})=>r.getAnnotation(w));S.forEach(w=>{const A=u.find(T=>T.id===w.id);(!A||!De(A,w))&&m("updateAnnotation",w,A)}),u=u.map(w=>S.find(({id:T})=>T===w.id)||w)};s.subscribe(({selected:E})=>{if(!(u.length===0&&E.length===0)){if(u.length===0&&E.length>0)u=E.map(({id:S})=>r.getAnnotation(S));else if(u.length>0&&E.length===0)u.forEach(S=>{const w=r.getAnnotation(S.id);w&&!De(w,S)&&m("updateAnnotation",w,S)}),u=[];else{const S=new Set(u.map(A=>A.id)),w=new Set(E.map(({id:A})=>A));u.filter(A=>!w.has(A.id)).forEach(A=>{const T=r.getAnnotation(A.id);T&&!De(T,A)&&m("updateAnnotation",T,A)}),u=[...u.filter(A=>w.has(A.id)),...E.filter(({id:A})=>!S.has(A)).map(({id:A})=>r.getAnnotation(A))]}m("selectionChanged",u)}}),i.subscribe(E=>{!d&&E?m("mouseEnterAnnotation",r.getAnnotation(E)):d&&!E?m("mouseLeaveAnnotation",r.getAnnotation(d)):d&&E&&(m("mouseLeaveAnnotation",r.getAnnotation(d)),m("mouseEnterAnnotation",r.getAnnotation(E))),d=E}),l==null||l.subscribe(E=>m("viewportIntersect",E.map(S=>r.getAnnotation(S)))),r.observe(E=>{o&&(f&&clearTimeout(f),f=setTimeout(p,1e3));const{created:S,deleted:w}=E.changes;(S||[]).forEach(A=>m("createAnnotation",A)),(w||[]).forEach(A=>m("deleteAnnotation",A)),(E.changes.updated||[]).filter(A=>[...A.bodiesCreated||[],...A.bodiesDeleted||[],...A.bodiesUpdated||[]].length>0).forEach(({oldValue:A,newValue:T})=>{const C=u.find(M=>M.id===A.id)||A;u=u.map(M=>M.id===A.id?T:M),m("updateAnnotation",T,C)})},{origin:ne.LOCAL}),r.observe(E=>{if(u){const S=new Set(u.map(A=>A.id)),w=(E.changes.updated||[]).filter(({newValue:A})=>S.has(A.id)).map(({newValue:A})=>A);w.length>0&&(u=u.map(A=>w.find(C=>C.id===A.id)||A))}},{origin:ne.REMOTE});const k=E=>S=>{const{updated:w}=S;E?(w||[]).forEach(A=>m("updateAnnotation",A.oldValue,A.newValue)):(w||[]).forEach(A=>m("updateAnnotation",A.newValue,A.oldValue))};return t.on("undo",k(!0)),t.on("redo",k(!1)),{on:h,off:g,emit:m}},Ji=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Qi=(e,t,n)=>{const{store:o,selection:i}=e,s=E=>{if(n){const{parsed:S,error:w}=n.parse(E);S?o.addAnnotation(S,ne.REMOTE):console.error(w)}else o.addAnnotation(Yt(E),ne.REMOTE)},r=()=>i.clear(),l=()=>o.clear(),a=E=>{const S=o.getAnnotation(E);return n&&S?n.serialize(S):S},u=()=>n?o.all().map(n.serialize):o.all(),d=()=>{var E;const S=(((E=i.selected)==null?void 0:E.map(w=>w.id))||[]).map(w=>o.getAnnotation(w)).filter(Boolean);return n?S.map(n.serialize):S},f=(E,S=!0)=>fetch(E).then(w=>w.json()).then(w=>(g(w,S),w)),h=E=>{if(typeof E=="string"){const S=o.getAnnotation(E);if(o.deleteAnnotation(E),S)return n?n.serialize(S):S}else{const S=n?n.parse(E).parsed:E;if(S)return o.deleteAnnotation(S),E}},g=(E,S=!0)=>{if(n){const w=n.parseAll||Ji(n),{parsed:A,failed:T}=w(E);T.length>0&&console.warn(`Discarded ${T.length} invalid annotations`,T),o.bulkAddAnnotations(A,S,ne.REMOTE)}else o.bulkAddAnnotations(E.map(Yt),S,ne.REMOTE)},m=(E,S)=>{E?i.setSelected(E,S):i.clear()},p=E=>{i.setUserSelectAction(E)},k=E=>{if(n){const S=n.parse(E).parsed,w=n.serialize(o.getAnnotation(S.id));return o.updateAnnotation(S),w}else{const S=o.getAnnotation(E.id);return o.updateAnnotation(Yt(E)),S}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:d,loadAnnotations:f,redo:t.redo,removeAnnotation:h,setAnnotations:g,setSelected:m,setUserSelectAction:p,undo:t.undo,updateAnnotation:k}},xi=(e,t,n)=>typeof t=="function"?t(e,n):t,$i=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,o)=>{const i=typeof e=="function"?e(n,o):e,s=typeof t=="function"?t(n,o):t;return{...i||{},...s||{}}},es="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ts=e=>crypto.getRandomValues(new Uint8Array(e)),ns=(e,t,n)=>{let o=(2<<Math.log2(e.length-1))-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let l=n(i),a=i|0;for(;a--;)if(r+=e[l[a]&o]||"",r.length>=s)return r}}},os=(e,t=21)=>ns(e,t|0,ts),is=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=es[n[e]&63];return t};const ss=()=>({isGuest:!0,id:os("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),rs=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Vn=e=>e?typeof e=="object"?{...e}:e:void 0,ls=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:l,modified:a,creator:u,...d}=n;return{id:o||`temp-${rs(n)}`,annotation:t,type:i,purpose:s,value:r,creator:Vn(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...d}}),as=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,l={...r,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l}),cs=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],us=()=>{const e=[...cs];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};is();const fs=(e,t={strict:!0,invertY:!1})=>({parse:i=>Xn(i,t),serialize:i=>Hn(i,e,t)}),Xn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Bn(),{creator:o,created:i,modified:s,body:r,...l}=e,a=ls(r||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,d=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,f=kn(d)?Mn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?Cn(d):void 0,h=Array.isArray(l.target)?l.target[0]:l.targret;return f||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Vn(o),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Hn=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:s,updated:r,updatedBy:l,...a}=e.target;let u;try{u=o.type==Q.RECTANGLE?Tn(o.geometry):On(o)}catch(f){if(n.strict)throw f;u=o}const d={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:as(e.bodies),created:s==null?void 0:s.toISOString(),creator:i,modified:r==null?void 0:r.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete d.bodies,typeof d.target!="string"&&"annotation"in d.target&&delete d.target.annotation,d},Ke=[];function ds(e,t=j){let n;const o=new Set;function i(l){if(re(e,l)&&(e=l,n)){const a=!Ke.length;for(const u of o)u[1](),Ke.push(u,e);if(a){for(let u=0;u<Ke.length;u+=2)Ke[u][0](Ke[u+1]);Ke.length=0}}}function s(l){i(l(e))}function r(l,a=j){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||j),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const hs=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},Gn=(e,t)=>{hs(e,t);const{subscribe:n,set:o}=ds(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,u=Math.max(r.width/l,r.height/a);o(u)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},He=(e,t,n)=>{const o=typeof t=="function"?t(e,n):t;if(o){const{fill:i,fillOpacity:s,stroke:r,strokeWidth:l,strokeOpacity:a}=o;let u="";return i&&(u+=`fill:${i};`),s||s===0?u+=`fill-opacity:${s};`:i&&(u+="fill-opacity:0.25;"),r&&(u+=`stroke:${r};`,u+=`stroke-width:${l||"1"};`,u+=`stroke-opacity:${a||"1"};`),u}},st=(e,t=0)=>{const{minX:n,minY:o,maxX:i,maxY:s}=e;return{x:n-t,y:o-t,w:i-n+2*t,h:s-o+2*t}},Ie=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,gs=e=>({}),jn=e=>({grab:e[0]});function ms(e){let t,n,o,i;const s=e[8].default,r=Ko(s,e,e[7],jn);return{c(){t=L("g"),r&&r.c(),c(t,"class","a9s-annotation selected")},m(l,a){N(l,t,a),r&&r.m(t,null),n=!0,o||(i=[J(t,"pointerup",e[2]),J(t,"pointermove",e[1])],o=!0)},p(l,[a]){r&&r.p&&(!n||a&128)&&Zo(r,s,l,l[7],n?Wo(s,l[7],a,gs):Jo(l[7]),jn)},i(l){n||(R(r,l),n=!0)},o(l){G(r,l),n=!1},d(l){l&&B(t),r&&r.d(l),o=!1,Ae(i)}}}function ps(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=Oe();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,d,f,h;const g=k=>E=>{if(d=k,u){const{left:w,top:A}=u.getBoundingClientRect(),T=E.clientX-w,C=E.clientY-A;f=a.elementToImage(T,C)}else{const{offsetX:w,offsetY:A}=E;f=a.elementToImage(w,A)}h=r,E.target.setPointerCapture(E.pointerId),s("grab",E)},m=k=>{if(d){const[E,S]=a.elementToImage(k.offsetX,k.offsetY),w=[E-f[0],S-f[1]];n(3,r=l(h,d,w)),s("change",r)}},p=k=>{k.target.releasePointerCapture(k.pointerId),d=void 0,h=r,s("release",k)};return e.$$set=k=>{"shape"in k&&n(3,r=k.shape),"editor"in k&&n(4,l=k.editor),"transform"in k&&n(5,a=k.transform),"svgEl"in k&&n(6,u=k.svgEl),"$$scope"in k&&n(7,i=k.$$scope)},[g,m,p,r,l,a,u,i,o]}class _t extends ge{constructor(t){super(),he(this,t,ps,ms,re,{shape:3,editor:4,transform:5,svgEl:6})}}function ys(e){let t,n,o,i,s,r,l,a,u=e[3]&&Fn(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),i=L("circle"),c(n,"class","a9s-handle-buffer svelte-qtyc7s"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]+6/e[2]),c(n,"role","button"),c(n,"tabindex","0"),c(i,"class",s=je(`a9s-handle-dot${e[3]?" selected":""}`)+" svelte-qtyc7s"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[5]),c(t,"class",r=`a9s-handle ${e[8].class||""}`.trim())},m(d,f){N(d,t,f),z(t,n),u&&u.m(t,null),z(t,i),l||(a=[J(n,"dblclick",e[12]),J(n,"pointerenter",e[13]),J(n,"pointerleave",e[14]),J(n,"pointerdown",e[15]),J(n,"pointerdown",e[6]),J(n,"pointerup",e[16]),J(n,"pointerup",e[7])],l=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&36&&o!==(o=d[5]+6/d[2])&&c(n,"r",o),d[3]?u?u.p(d,f):(u=Fn(d),u.c(),u.m(t,i)):u&&(u.d(1),u=null),f&8&&s!==(s=je(`a9s-handle-dot${d[3]?" selected":""}`)+" svelte-qtyc7s")&&c(i,"class",s),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&32&&c(i,"r",d[5]),f&256&&r!==(r=`a9s-handle ${d[8].class||""}`.trim())&&c(t,"class",r)},d(d){d&&B(t),u&&u.d(),l=!1,Ae(a)}}}function _s(e){let t,n,o,i,s,r,l,a,u;return{c(){t=L("g"),n=L("circle"),i=L("circle"),r=L("circle"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]*10),c(n,"class","a9s-touch-halo"),Pe(n,"touched",e[4]),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",s=e[5]+10/e[2]),c(i,"class","a9s-handle-buffer svelte-qtyc7s"),c(i,"role","button"),c(i,"tabindex","0"),c(r,"class","a9s-handle-dot"),c(r,"cx",e[0]),c(r,"cy",e[1]),c(r,"r",l=e[5]+2/e[2]),c(t,"class","a9s-touch-handle")},m(d,f){N(d,t,f),z(t,n),z(t,i),z(t,r),a||(u=[J(i,"dblclick",e[9]),J(i,"pointerdown",e[10]),J(i,"pointerdown",e[6]),J(i,"pointerup",e[11]),J(i,"pointerup",e[7])],a=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&32&&o!==(o=d[5]*10)&&c(n,"r",o),f&16&&Pe(n,"touched",d[4]),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&36&&s!==(s=d[5]+10/d[2])&&c(i,"r",s),f&1&&c(r,"cx",d[0]),f&2&&c(r,"cy",d[1]),f&36&&l!==(l=d[5]+2/d[2])&&c(r,"r",l)},d(d){d&&B(t),a=!1,Ae(u)}}}function Fn(e){let t,n;return{c(){t=L("circle"),c(t,"class","a9s-handle-selected"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",n=e[5]+8/e[2])},m(o,i){N(o,t,i)},p(o,i){i&1&&c(t,"cx",o[0]),i&2&&c(t,"cy",o[1]),i&36&&n!==(n=o[5]+8/o[2])&&c(t,"r",n)},d(o){o&&B(t)}}}function ws(e){let t;function n(s,r){return Ie?_s:ys}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),N(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&B(t),i.d(s)}}}function bs(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=w=>{w.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function f(w){ue.call(this,e,w)}function h(w){ue.call(this,e,w)}function g(w){ue.call(this,e,w)}function m(w){ue.call(this,e,w)}function p(w){ue.call(this,e,w)}function k(w){ue.call(this,e,w)}function E(w){ue.call(this,e,w)}function S(w){ue.call(this,e,w)}return e.$$set=w=>{n(8,t=Ce(Ce({},t),un(w))),"x"in w&&n(0,i=w.x),"y"in w&&n(1,s=w.y),"scale"in w&&n(2,r=w.scale),"selected"in w&&n(3,l=w.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=4/r)},t=un(t),[i,s,r,l,a,o,u,d,t,f,h,g,m,p,k,E,S]}class Ge extends ge{constructor(t){super(),he(this,t,bs,ws,re,{x:0,y:1,scale:2,selected:3})}}function Es(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("circle"),i=L("circle"),s=L("circle"),c(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=1.75*e[2]),c(i,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[2]),c(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),c(s,"cx",e[0]),c(s,"cy",e[1]),c(s,"r",e[2]),c(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(a,u){N(a,t,u),z(t,n),z(t,i),z(t,s),r||(l=[J(n,"pointerdown",e[5]),J(n,"pointerdown",e[3])],r=!0)},p(a,u){u&1&&c(n,"cx",a[0]),u&2&&c(n,"cy",a[1]),u&4&&o!==(o=1.75*a[2])&&c(n,"r",o),u&1&&c(i,"cx",a[0]),u&2&&c(i,"cy",a[1]),u&4&&c(i,"r",a[2]),u&1&&c(s,"cx",a[0]),u&2&&c(s,"cy",a[1]),u&4&&c(s,"r",a[2])},d(a){a&&B(t),r=!1,Ae(l)}}}function vs(e){let t;return{c(){t=L("circle"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",e[2])},m(n,o){N(n,t,o)},p(n,o){o&1&&c(t,"cx",n[0]),o&2&&c(t,"cy",n[1]),o&4&&c(t,"r",n[2])},d(n){n&&B(t)}}}function Ss(e){let t;function n(s,r){return Ie?vs:Es}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),N(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&B(t),i.d(s)}}}function As(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){ue.call(this,e,u)}return e.$$set=u=>{"x"in u&&n(0,i=u.x),"y"in u&&n(1,s=u.y),"scale"in u&&n(4,r=u.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,o=4/r)},[i,s,o,l,r,a]}class Rt extends ge{constructor(t){super(),he(this,t,As,Ss,re,{x:0,y:1,scale:4})}}function Vt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function zn(e,t,n){const o=e.slice();return o[28]=t[n],o[30]=n,o}function Xt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Ht(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function qn(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[28][0]),c(t,"cy",o=e[28][1]),c(t,"r",i=rt/e[3]),c(t,"class","svelte-1h2slbm")},m(s,r){N(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[28][1])&&c(t,"cy",o),r[0]&8&&i!==(i=rt/s[3])&&c(t,"r",i)},d(s){s&&B(t)}}}function Kn(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1h2slbm"),c(l,"cx",a=e[28][0]),c(l,"cy",u=e[28][1]),c(l,"r",d=rt/e[3]),c(l,"class","svelte-1h2slbm"),c(t,"id",`${e[19]}-inner`),c(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(f,h){N(f,t,h),z(t,n),z(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[28][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[28][1])&&c(l,"cy",u),h[0]&8&&d!==(d=rt/f[3])&&c(l,"r",d)},d(f){f&&B(t)}}}function Wn(e){let t,n;return t=new Ge({props:{class:"a9s-corner-handle",x:e[28][0],y:e[28][1],scale:e[3],selected:e[8].includes(e[30])}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[15]),t.$on("pointerdown",function(){ie(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&32&&(s.x=e[28][0]),i[0]&32&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),i[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Zn(e){let t,n;return t=new Rt({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[28][0]),i[0]&1088&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function ks(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,E,S,w,A,T,C=e[6]!==void 0&&!e[7]&&qn(Ht(e)),M=e[6]!==void 0&&!e[7]&&Kn(Xt(e)),V=ve(e[5].points),U=[];for(let v=0;v<V.length;v+=1)U[v]=Wn(zn(e,V,v));const W=v=>G(U[v],1,1,()=>{U[v]=null});let q=e[6]!==void 0&&!e[7]&&Zn(Vt(e));return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),C&&C.c(),M&&M.c(),d=we(),f=L("polygon"),g=we(),m=L("polygon"),k=we();for(let v=0;v<U.length;v+=1)U[v].c();E=we(),q&&q.c(),S=ke(),c(o,"x",i=e[9].x),c(o,"y",s=e[9].y),c(o,"width",r=e[9].w),c(o,"height",l=e[9].h),c(o,"class","svelte-1h2slbm"),c(a,"points",u=e[5].points.map(Jn).join(" ")),c(a,"class","svelte-1h2slbm"),c(n,"id",`${e[19]}-outer`),c(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[19]}-outer)`),c(f,"points",h=e[5].points.map(Qn).join(" ")),c(m,"class","a9s-inner a9s-shape-handle"),c(m,"mask",`url(#${e[19]}-inner)`),c(m,"style",e[1]),c(m,"points",p=e[5].points.map(xn).join(" "))},m(v,b){N(v,t,b),z(t,n),z(n,o),z(n,a),C&&C.m(n,null),M&&M.m(t,null),N(v,d,b),N(v,f,b),N(v,g,b),N(v,m,b),N(v,k,b);for(let y=0;y<U.length;y+=1)U[y]&&U[y].m(v,b);N(v,E,b),q&&q.m(v,b),N(v,S,b),w=!0,A||(T=[J(f,"pointerup",e[14]),J(f,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),J(m,"pointermove",e[13]),J(m,"pointerup",e[14]),J(m,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],A=!0)},p(v,b){if(e=v,(!w||b[0]&512&&i!==(i=e[9].x))&&c(o,"x",i),(!w||b[0]&512&&s!==(s=e[9].y))&&c(o,"y",s),(!w||b[0]&512&&r!==(r=e[9].w))&&c(o,"width",r),(!w||b[0]&512&&l!==(l=e[9].h))&&c(o,"height",l),(!w||b[0]&32&&u!==(u=e[5].points.map(Jn).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Ht(e),b):(C=qn(Ht(e)),C.c(),C.m(n,null)):C&&(C.d(1),C=null),e[6]!==void 0&&!e[7]?M?M.p(Xt(e),b):(M=Kn(Xt(e)),M.c(),M.m(t,null)):M&&(M.d(1),M=null),(!w||b[0]&32&&h!==(h=e[5].points.map(Qn).join(" ")))&&c(f,"points",h),(!w||b[0]&2)&&c(m,"style",e[1]),(!w||b[0]&32&&p!==(p=e[5].points.map(xn).join(" ")))&&c(m,"points",p),b[0]&134322472){V=ve(e[5].points);let y;for(y=0;y<V.length;y+=1){const _=zn(e,V,y);U[y]?(U[y].p(_,b),R(U[y],1)):(U[y]=Wn(_),U[y].c(),R(U[y],1),U[y].m(E.parentNode,E))}for(be(),y=V.length;y<U.length;y+=1)W(y);Ee()}e[6]!==void 0&&!e[7]?q?(q.p(Vt(e),b),b[0]&192&&R(q,1)):(q=Zn(Vt(e)),q.c(),R(q,1),q.m(S.parentNode,S)):q&&(be(),G(q,1,1,()=>{q=null}),Ee())},i(v){if(!w){for(let b=0;b<V.length;b+=1)R(U[b]);R(q),w=!0}},o(v){U=U.filter(Boolean);for(let b=0;b<U.length;b+=1)G(U[b]);G(q),w=!1},d(v){v&&(B(t),B(d),B(f),B(g),B(m),B(k),B(E),B(S)),C&&C.d(),M&&M.d(),Ye(U,v),q&&q.d(v),A=!1,Ae(T)}}}function Ms(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[ks,({grab:o})=>({27:o}),({grab:o})=>[o?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&134219754|i[1]&1&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ts=250,Ps=1e3,Ls=12,rt=4.5,Jn=e=>e.join(","),Qn=e=>e.join(","),xn=e=>e.join(",");function Is(e,t,n){let o,i,s;const r=Oe();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,g=!1,m,p=[];const k=()=>n(7,g=!0),E=()=>n(7,g=!1),S=y=>{if(p.length>0||!i.some(Z=>Z.visible)){n(6,h=void 0);return}const[_,I]=u.elementToImage(y.offsetX,y.offsetY),P=Z=>Math.pow(Z[0]-_,2)+Math.pow(Z[1]-I,2),D=o.points.reduce((Z,$)=>P($)<P(Z)?$:Z),F=i.filter(Z=>Z.visible).reduce((Z,$)=>P($.point)<P(Z.point)?$:Z),H=Math.pow(Ps/d,2);P(D)<H||P(F.point)<H?n(6,h=i.indexOf(F)):n(6,h=void 0)},w=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,p=[]),w()},T=y=>{n(7,g=!0),y.preventDefault(),y.stopPropagation(),m=performance.now()},C=y=>_=>{if(!m||Ie||performance.now()-m>Ts)return;const I=p.includes(y);_.metaKey||_.ctrlKey||_.shiftKey?I?n(8,p=p.filter(P=>P!==y)):n(8,p=[...p,y]):I&&p.length>1?n(8,p=[y]):I?n(8,p=[]):n(8,p=[y]),w()},M=(y,_,I)=>{w();let P;const D=y.geometry;p.length>1?P=D.points.map(([H,x],Z)=>p.includes(Z)?[H+I[0],x+I[1]]:[H,x]):_==="SHAPE"?P=D.points.map(([H,x])=>[H+I[0],x+I[1]]):P=D.points.map(([H,x],Z)=>_===`HANDLE-${Z}`?[H+I[0],x+I[1]]:[H,x]);const F=fe(P);return{...y,geometry:{points:P,bounds:F}}},V=y=>async _=>{_.stopPropagation();const I=[...o.points.slice(0,y+1),i[y].point,...o.points.slice(y+1)],P=fe(I);r("change",{...l,geometry:{points:I,bounds:P}}),await pn();const D=[...document.querySelectorAll(".a9s-handle")][y+1];if(D!=null&&D.firstChild){const F=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:_.clientX,clientY:_.clientY,pointerId:_.pointerId,pointerType:_.pointerType,isPrimary:_.isPrimary,buttons:_.buttons});D.firstChild.dispatchEvent(F)}},U=()=>{if(o.points.length-p.length<3)return;const y=o.points.filter((I,P)=>!p.includes(P)),_=fe(y);r("change",{...l,geometry:{points:y,bounds:_}}),n(8,p=[])};Re(()=>{if(Ie)return;const y=_=>{(_.key==="Delete"||_.key==="Backspace")&&(_.preventDefault(),U())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",y),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",y)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function q(y){ue.call(this,e,y)}function v(y){ue.call(this,e,y)}function b(y){ue.call(this,e,y)}return e.$$set=y=>{"shape"in y&&n(0,l=y.shape),"computedStyle"in y&&n(1,a=y.computedStyle),"transform"in y&&n(2,u=y.transform),"viewportScale"in y&&n(3,d=y.viewportScale),"svgEl"in y&&n(4,f=y.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Ie?[]:o.points.map((y,_)=>{const I=_===o.points.length-1?o.points[0]:o.points[_+1],P=(y[0]+I[0])/2,D=(y[1]+I[1])/2,H=Math.sqrt(Math.pow(I[0]-P,2)+Math.pow(I[1]-D,2))>Ls/d;return{point:[P,D],visible:H}})),e.$$.dirty[0]&40&&n(9,s=st(o.bounds,rt/d))},[l,a,u,d,f,o,h,g,p,s,i,k,E,S,A,T,C,M,V,W,q,v,b]}class $n extends ge{constructor(t){super(),he(this,t,Is,Ms,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Cs(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,E,S,w,A,T,C,M,V,U,W,q,v,b,y,_,I,P,D,F,H,x,Z,$,oe,se,Se,Te,X,de,te,ye,_e,Je,Ne,nn,Ue,ee,on,zo;return te=new Ge({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),_e=new Ge({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),_e.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),Ne=new Ge({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),Ne.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Ue=new Ge({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Ue.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),g=we(),m=L("rect"),w=we(),A=L("rect"),U=we(),W=L("rect"),y=we(),_=L("rect"),F=we(),H=L("rect"),oe=we(),se=L("rect"),de=we(),ce(te.$$.fragment),ye=we(),ce(_e.$$.fragment),Je=we(),ce(Ne.$$.fragment),nn=we(),ce(Ue.$$.fragment),c(o,"class","rect-mask-bg svelte-1njczvj"),c(o,"x",i=e[6].x),c(o,"y",s=e[6].y),c(o,"width",r=e[6].w),c(o,"height",l=e[6].h),c(a,"class","rect-mask-fg svelte-1njczvj"),c(a,"x",u=e[5].x),c(a,"y",d=e[5].y),c(a,"width",f=e[5].w),c(a,"height",h=e[5].h),c(n,"id",e[8]),c(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),c(m,"class","a9s-outer"),c(m,"mask",`url(#${e[8]})`),c(m,"x",p=e[5].x),c(m,"y",k=e[5].y),c(m,"width",E=e[5].w),c(m,"height",S=e[5].h),c(A,"class","a9s-inner a9s-shape-handle"),c(A,"style",e[1]),c(A,"x",T=e[5].x),c(A,"y",C=e[5].y),c(A,"width",M=e[5].w),c(A,"height",V=e[5].h),c(W,"class","a9s-edge-handle a9s-edge-handle-top"),c(W,"x",q=e[5].x),c(W,"y",v=e[5].y),c(W,"height",1),c(W,"width",b=e[5].w),c(_,"class","a9s-edge-handle a9s-edge-handle-right"),c(_,"x",I=e[5].x+e[5].w),c(_,"y",P=e[5].y),c(_,"height",D=e[5].h),c(_,"width",1),c(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),c(H,"x",x=e[5].x),c(H,"y",Z=e[5].y+e[5].h),c(H,"height",1),c(H,"width",$=e[5].w),c(se,"class","a9s-edge-handle a9s-edge-handle-left"),c(se,"x",Se=e[5].x),c(se,"y",Te=e[5].y),c(se,"height",X=e[5].h),c(se,"width",1)},m(K,Y){N(K,t,Y),z(t,n),z(n,o),z(n,a),N(K,g,Y),N(K,m,Y),N(K,w,Y),N(K,A,Y),N(K,U,Y),N(K,W,Y),N(K,y,Y),N(K,_,Y),N(K,F,Y),N(K,H,Y),N(K,oe,Y),N(K,se,Y),N(K,de,Y),le(te,K,Y),N(K,ye,Y),le(_e,K,Y),N(K,Je,Y),le(Ne,K,Y),N(K,nn,Y),le(Ue,K,Y),ee=!0,on||(zo=[J(m,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),J(A,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),J(W,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),J(_,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),J(H,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),J(se,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],on=!0)},p(K,Y){e=K,(!ee||Y&64&&i!==(i=e[6].x))&&c(o,"x",i),(!ee||Y&64&&s!==(s=e[6].y))&&c(o,"y",s),(!ee||Y&64&&r!==(r=e[6].w))&&c(o,"width",r),(!ee||Y&64&&l!==(l=e[6].h))&&c(o,"height",l),(!ee||Y&32&&u!==(u=e[5].x))&&c(a,"x",u),(!ee||Y&32&&d!==(d=e[5].y))&&c(a,"y",d),(!ee||Y&32&&f!==(f=e[5].w))&&c(a,"width",f),(!ee||Y&32&&h!==(h=e[5].h))&&c(a,"height",h),(!ee||Y&32&&p!==(p=e[5].x))&&c(m,"x",p),(!ee||Y&32&&k!==(k=e[5].y))&&c(m,"y",k),(!ee||Y&32&&E!==(E=e[5].w))&&c(m,"width",E),(!ee||Y&32&&S!==(S=e[5].h))&&c(m,"height",S),(!ee||Y&2)&&c(A,"style",e[1]),(!ee||Y&32&&T!==(T=e[5].x))&&c(A,"x",T),(!ee||Y&32&&C!==(C=e[5].y))&&c(A,"y",C),(!ee||Y&32&&M!==(M=e[5].w))&&c(A,"width",M),(!ee||Y&32&&V!==(V=e[5].h))&&c(A,"height",V),(!ee||Y&32&&q!==(q=e[5].x))&&c(W,"x",q),(!ee||Y&32&&v!==(v=e[5].y))&&c(W,"y",v),(!ee||Y&32&&b!==(b=e[5].w))&&c(W,"width",b),(!ee||Y&32&&I!==(I=e[5].x+e[5].w))&&c(_,"x",I),(!ee||Y&32&&P!==(P=e[5].y))&&c(_,"y",P),(!ee||Y&32&&D!==(D=e[5].h))&&c(_,"height",D),(!ee||Y&32&&x!==(x=e[5].x))&&c(H,"x",x),(!ee||Y&32&&Z!==(Z=e[5].y+e[5].h))&&c(H,"y",Z),(!ee||Y&32&&$!==($=e[5].w))&&c(H,"width",$),(!ee||Y&32&&Se!==(Se=e[5].x))&&c(se,"x",Se),(!ee||Y&32&&Te!==(Te=e[5].y))&&c(se,"y",Te),(!ee||Y&32&&X!==(X=e[5].h))&&c(se,"height",X);const Et={};Y&32&&(Et.x=e[5].x),Y&32&&(Et.y=e[5].y),Y&8&&(Et.scale=e[3]),te.$set(Et);const vt={};Y&32&&(vt.x=e[5].x+e[5].w),Y&32&&(vt.y=e[5].y),Y&8&&(vt.scale=e[3]),_e.$set(vt);const St={};Y&32&&(St.x=e[5].x+e[5].w),Y&32&&(St.y=e[5].y+e[5].h),Y&8&&(St.scale=e[3]),Ne.$set(St);const At={};Y&32&&(At.x=e[5].x),Y&32&&(At.y=e[5].y+e[5].h),Y&8&&(At.scale=e[3]),Ue.$set(At)},i(K){ee||(R(te.$$.fragment,K),R(_e.$$.fragment,K),R(Ne.$$.fragment,K),R(Ue.$$.fragment,K),ee=!0)},o(K){G(te.$$.fragment,K),G(_e.$$.fragment,K),G(Ne.$$.fragment,K),G(Ue.$$.fragment,K),ee=!1},d(K){K&&(B(t),B(g),B(m),B(w),B(A),B(U),B(W),B(y),B(_),B(F),B(H),B(oe),B(se),B(de),B(ye),B(Je),B(nn)),ae(te,K),ae(_e,K),ae(Ne,K),ae(Ue,K),on=!1,Ae(zo)}}}function Os(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Cs,({grab:o})=>({12:o}),({grab:o})=>o?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&16&&(s.svgEl=o[4]),i&12394&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ds(e,t,n){let o,i,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const d=(p,k,E)=>{const S=p.geometry.bounds;let[w,A]=[S.minX,S.minY],[T,C]=[S.maxX,S.maxY];const[M,V]=E;if(k==="SHAPE")w+=M,T+=M,A+=V,C+=V;else{switch(k){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{A+=V;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{C+=V;break}}switch(k){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{w+=M;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{T+=M;break}}}const U=Math.min(w,T),W=Math.min(A,C),q=Math.abs(T-w),v=Math.abs(C-A);return{...p,geometry:{x:U,y:W,w:q,h:v,bounds:{minX:U,minY:W,maxX:U+q,maxY:W+v}}}},f=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function h(p){ue.call(this,e,p)}function g(p){ue.call(this,e,p)}function m(p){ue.call(this,e,p)}return e.$$set=p=>{"shape"in p&&n(0,s=p.shape),"computedStyle"in p&&n(1,r=p.computedStyle),"transform"in p&&n(2,l=p.transform),"viewportScale"in p&&n(3,a=p.viewportScale),"svgEl"in p&&n(4,u=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,o=s.geometry),e.$$.dirty&40&&n(6,i=st(o.bounds,2/a))},[s,r,l,a,u,o,i,d,f,h,g,m]}class eo extends ge{constructor(t){super(),he(this,t,Ds,Os,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var to=Object.prototype.hasOwnProperty;function Gt(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&Gt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(to.call(e,n)&&++o&&!to.call(t,n)||!(n in t)||!Gt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Bs=12,Ns=(e,t)=>e.polygons.reduce((n,o,i)=>{const s=o.rings.reduce((r,l,a)=>{const u=l.points.map((d,f)=>{const h=f===l.points.length-1?l.points[0]:l.points[f+1],g=(d[0]+h[0])/2,m=(d[1]+h[1])/2,k=Math.sqrt(Math.pow(h[0]-g,2)+Math.pow(h[1]-m,2))>Bs/t;return{point:[g,m],visible:k,elementIdx:i,ringIdx:a,pointIdx:f}});return[...r,...u]},[]);return[...n,...s]},[]);function jt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function no(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function oo(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function io(e,t,n){const o=e.slice();return o[29]=t[n],o[37]=n,o}function Ft(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function zt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function so(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[29][0]),c(t,"cy",o=e[29][1]),c(t,"r",i=lt/e[3]),c(t,"class","svelte-1vxo6dc")},m(s,r){N(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[29][1])&&c(t,"cy",o),r[0]&8&&i!==(i=lt/s[3])&&c(t,"r",i)},d(s){s&&B(t)}}}function ro(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1vxo6dc"),c(l,"cx",a=e[29][0]),c(l,"cy",u=e[29][1]),c(l,"r",d=lt/e[3]),c(l,"class","svelte-1vxo6dc"),c(t,"id",`${e[18]}-${e[32]}-inner`),c(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(f,h){N(f,t,h),z(t,n),z(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[29][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[29][1])&&c(l,"cy",u),h[0]&8&&d!==(d=lt/f[3])&&c(l,"r",d)},d(f){f&&B(t)}}}function lo(e){let t,n;function o(...i){return e[19](e[32],e[35],e[37],...i)}return t=new Ge({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(o)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){ie(e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`))&&e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`).apply(this,arguments)}),t.$on("pointerup",e[15](e[32],e[35],e[37])),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){e=i;const r={};s[0]&32&&(r.x=e[29][0]),s[0]&32&&(r.y=e[29][1]),s[0]&8&&(r.scale=e[3]),s[0]&256&&(r.selected=e[8].some(o)),t.$set(r)},i(i){n||(R(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function ao(e){let t,n,o=ve(e[33].points),i=[];for(let r=0;r<o.length;r+=1)i[r]=lo(io(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);N(r,t,l),n=!0},p(r,l){if(l[0]&268491048){o=ve(r[33].points);let a;for(a=0;a<o.length;a+=1){const u=io(r,o,a);i[a]?(i[a].p(u,l),R(i[a],1)):(i[a]=lo(u),i[a].c(),R(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)R(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&B(t),Ye(i,r)}}}function co(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p,k,E,S=e[6]!==void 0&&!e[7]&&so(zt(e)),w=e[6]!==void 0&&!e[7]&&ro(Ft(e)),A=ve(e[30].rings),T=[];for(let M=0;M<A.length;M+=1)T[M]=ao(oo(e,A,M));const C=M=>G(T[M],1,1,()=>{T[M]=null});return{c(){t=L("g"),n=L("defs"),o=L("mask"),i=L("rect"),u=L("path"),S&&S.c(),w&&w.c(),f=L("path"),g=L("path");for(let M=0;M<T.length;M+=1)T[M].c();c(i,"x",s=e[9].x),c(i,"y",r=e[9].y),c(i,"width",l=e[9].w),c(i,"height",a=e[9].h),c(i,"class","svelte-1vxo6dc"),c(u,"d",d=Le(e[30])),c(u,"class","svelte-1vxo6dc"),c(o,"id",`${e[18]}-${e[32]}-outer`),c(o,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[18]}-${e[32]}-outer)`),c(f,"fill-rule","evenodd"),c(f,"d",h=Le(e[30])),c(g,"class","a9s-inner"),c(g,"mask",`url(#${e[18]}-${e[32]}-inner)`),c(g,"style",e[1]),c(g,"fill-rule","evenodd"),c(g,"d",m=Le(e[30]))},m(M,V){N(M,t,V),z(t,n),z(n,o),z(o,i),z(o,u),S&&S.m(o,null),w&&w.m(n,null),z(t,f),z(t,g);for(let U=0;U<T.length;U+=1)T[U]&&T[U].m(t,null);p=!0,k||(E=[J(f,"pointerup",e[13]),J(f,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),J(g,"pointerup",e[13]),J(g,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],k=!0)},p(M,V){if(e=M,(!p||V[0]&512&&s!==(s=e[9].x))&&c(i,"x",s),(!p||V[0]&512&&r!==(r=e[9].y))&&c(i,"y",r),(!p||V[0]&512&&l!==(l=e[9].w))&&c(i,"width",l),(!p||V[0]&512&&a!==(a=e[9].h))&&c(i,"height",a),(!p||V[0]&32&&d!==(d=Le(e[30])))&&c(u,"d",d),e[6]!==void 0&&!e[7]?S?S.p(zt(e),V):(S=so(zt(e)),S.c(),S.m(o,null)):S&&(S.d(1),S=null),e[6]!==void 0&&!e[7]?w?w.p(Ft(e),V):(w=ro(Ft(e)),w.c(),w.m(n,null)):w&&(w.d(1),w=null),(!p||V[0]&32&&h!==(h=Le(e[30])))&&c(f,"d",h),(!p||V[0]&2)&&c(g,"style",e[1]),(!p||V[0]&32&&m!==(m=Le(e[30])))&&c(g,"d",m),V[0]&268491048){A=ve(e[30].rings);let U;for(U=0;U<A.length;U+=1){const W=oo(e,A,U);T[U]?(T[U].p(W,V),R(T[U],1)):(T[U]=ao(W),T[U].c(),R(T[U],1),T[U].m(t,null))}for(be(),U=A.length;U<T.length;U+=1)C(U);Ee()}},i(M){if(!p){for(let V=0;V<A.length;V+=1)R(T[V]);p=!0}},o(M){T=T.filter(Boolean);for(let V=0;V<T.length;V+=1)G(T[V]);p=!1},d(M){M&&B(t),S&&S.d(),w&&w.d(),Ye(T,M),k=!1,Ae(E)}}}function uo(e){let t,n;return t=new Rt({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[29][0]),i[0]&1088&&(s.y=e[29][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Us(e){let t,n,o,i=ve(e[5].polygons),s=[];for(let a=0;a<i.length;a+=1)s[a]=co(no(e,i,a));const r=a=>G(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&uo(jt(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=we(),l&&l.c(),n=ke()},m(a,u){for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(a,u);N(a,t,u),l&&l.m(a,u),N(a,n,u),o=!0},p(a,u){if(u[0]&268763114){i=ve(a[5].polygons);let d;for(d=0;d<i.length;d+=1){const f=no(a,i,d);s[d]?(s[d].p(f,u),R(s[d],1)):(s[d]=co(f),s[d].c(),R(s[d],1),s[d].m(t.parentNode,t))}for(be(),d=i.length;d<s.length;d+=1)r(d);Ee()}a[6]!==void 0&&!a[7]?l?(l.p(jt(a),u),u[0]&192&&R(l,1)):(l=uo(jt(a)),l.c(),R(l,1),l.m(n.parentNode,n)):l&&(be(),G(l,1,1,()=>{l=null}),Ee())},i(a){if(!o){for(let u=0;u<i.length;u+=1)R(s[u]);R(l),o=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)G(s[u]);G(l),o=!1},d(a){a&&(B(t),B(n)),Ye(s,a),l&&l.d(a)}}}function Ys(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[Us,({grab:o})=>({28:o}),({grab:o})=>[o?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&268437482|i[1]&128&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Rs=250,Vs=1e3,lt=4.5;function Xs(e,t,n){let o,i,s;const r=Oe();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,g=!1,m,p=[];const k=()=>n(7,g=!0),E=()=>n(7,g=!1),S=_=>{if(p.length>0||!i.some($=>$.visible)){n(6,h=void 0);return}const[I,P]=u.elementToImage(_.offsetX,_.offsetY),D=$=>Math.pow($[0]-I,2)+Math.pow($[1]-P,2),F=En(o).reduce(($,oe)=>D(oe)<D($)?oe:$),H=i.filter($=>$.visible).reduce(($,oe)=>D(oe.point)<D($.point)?oe:$),x=Math.pow(Vs/d,2);D(F)<x||D(H.point)<x?n(6,h=i.indexOf(H)):n(6,h=void 0)},w=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,p=[]),w()},T=_=>{n(7,g=!0),_.preventDefault(),_.stopPropagation(),m=performance.now()},C=(_,I,P)=>D=>{if(!m||Ie||performance.now()-m>Rs)return;const F=x=>x.polygon===_&&x.ring===I&&x.point===P,H=p.some(F);D.metaKey||D.ctrlKey||D.shiftKey?H?n(8,p=p.filter(x=>!F(x))):n(8,p=[...p,{polygon:_,ring:I,point:P}]):H&&p.length>1?n(8,p=[{polygon:_,ring:I,point:P}]):H?n(8,p=[]):n(8,p=[{polygon:_,ring:I,point:P}]),w()},M=(_,I,P)=>{w();const D=_.geometry.polygons;let F;if(I==="SHAPE")F=D.map(H=>{const x=H.rings.map(($,oe)=>({points:$.points.map((Se,Te)=>[Se[0]+P[0],Se[1]+P[1]])})),Z=fe(x[0].points);return{rings:x,bounds:Z}});else{const[H,x,Z,$]=I.split("-").map(oe=>parseInt(oe));F=D.map((oe,se)=>{if(se===x){const Se=oe.rings.map((X,de)=>de===Z?{points:X.points.map((ye,_e)=>_e===$?[ye[0]+P[0],ye[1]+P[1]]:ye)}:X),Te=fe(Se[0].points);return{rings:Se,bounds:Te}}else return oe})}return{..._,geometry:{polygons:F,bounds:nt(F)}}},V=_=>async I=>{I.stopPropagation();const P=i[_],D=o.polygons.map((H,x)=>{if(x===P.elementIdx){const Z=H.rings.map((oe,se)=>se===P.ringIdx?{points:[...oe.points.slice(0,P.pointIdx+1),P.point,...oe.points.slice(P.pointIdx+1)]}:oe),$=fe(Z[0].points);return{rings:Z,bounds:$}}else return H});r("change",{...l,geometry:{polygons:D,bounds:nt(D)}}),await pn();const F=[...document.querySelectorAll(".a9s-handle")][_+1];if(F!=null&&F.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:I.clientX,clientY:I.clientY,pointerId:I.pointerId,pointerType:I.pointerType,isPrimary:I.isPrimary,buttons:I.buttons});F.firstChild.dispatchEvent(H)}},U=()=>{const _=o.polygons.map((P,D)=>{if(p.some(H=>H.polygon===D)){const H=P.rings.map((Z,$)=>{const oe=p.filter(se=>se.polygon===D&&se.ring===$);return oe.length&&Z.points.length-oe.length>=3?{points:Z.points.filter((Se,Te)=>!oe.some(X=>X.point===Te))}:Z}),x=fe(H[0].points);return{rings:H,bounds:x}}else return P});!Gt(o.polygons,_)&&(r("change",{...l,geometry:{polygons:_,bounds:nt(_)}}),n(8,p=[]))};Re(()=>{if(Ie)return;const _=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),U())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",_),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",_)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,q=(_,I,P,{polygon:D,ring:F,point:H})=>D===_&&F===I&&H===P;function v(_){ue.call(this,e,_)}function b(_){ue.call(this,e,_)}function y(_){ue.call(this,e,_)}return e.$$set=_=>{"shape"in _&&n(0,l=_.shape),"computedStyle"in _&&n(1,a=_.computedStyle),"transform"in _&&n(2,u=_.transform),"viewportScale"in _&&n(3,d=_.viewportScale),"svgEl"in _&&n(4,f=_.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Ie?[]:Ns(o,d)),e.$$.dirty[0]&40&&n(9,s=st(o.bounds,lt/d))},[l,a,u,d,f,o,h,g,p,s,i,k,E,A,T,C,M,V,W,q,v,b,y]}class Hs extends ge{constructor(t){super(),he(this,t,Xs,Ys,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const fo=new Map([[Q.RECTANGLE,eo],[Q.POLYGON,$n],[Q.MULTIPOLYGON,Hs]]),ho=e=>fo.get(e.type),go=(e,t)=>fo.set(e,t);function Gs(e,t,n){let o;const i=Oe();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,f;return Re(()=>(n(6,f=new r({target:a,props:{shape:s.target.selector,computedStyle:o,transform:u,viewportScale:d,svgEl:a.closest("svg")}})),f.$on("change",h=>{f.$$set({shape:h.detail}),i("change",h.detail)}),f.$on("grab",h=>i("grab",h.detail)),f.$on("release",h=>i("release",h.detail)),()=>{f.$destroy()})),e.$$set=h=>{"annotation"in h&&n(0,s=h.annotation),"editor"in h&&n(1,r=h.editor),"style"in h&&n(2,l=h.style),"target"in h&&n(3,a=h.target),"transform"in h&&n(4,u=h.transform),"viewportScale"in h&&n(5,d=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,o=He(s,l,{selected:!0,hovered:!0})),e.$$.dirty&65&&s&&(f==null||f.$set({shape:s.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:u}),e.$$.dirty&96&&f&&f.$set({viewportScale:d}),e.$$.dirty&192&&f&&o&&f.$set({computedStyle:o})},[s,r,l,a,u,d,f,o]}class mo extends ge{constructor(t){super(),he(this,t,Gs,null,re,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function js(e,t,n){const o=Oe();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return Re(()=>{const d=s.closest("svg"),f=[],h=(g,m,p)=>{d==null||d.addEventListener(g,m,p),f.push(()=>d==null?void 0:d.removeEventListener(g,m,p))};return n(5,u=new r({target:s,props:{addEventListener:h,drawingMode:i,transform:l,viewportScale:a}})),u.$on("create",g=>o("create",g.detail)),()=>{f.forEach(g=>g()),u.$destroy()}}),e.$$set=d=>{"drawingMode"in d&&n(0,i=d.drawingMode),"target"in d&&n(1,s=d.target),"tool"in d&&n(2,r=d.tool),"transform"in d&&n(3,l=d.transform),"viewportScale"in d&&n(4,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:l}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[i,s,r,l,a,u]}class po extends ge{constructor(t){super(),he(this,t,js,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function yo(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),u=L("rect"),d=L("rect"),c(o,"class","rect-mask-bg svelte-1a76qe7"),c(o,"x",i=e[1]-e[5]),c(o,"y",s=e[2]-e[5]),c(o,"width",r=e[3]+2*e[5]),c(o,"height",l=e[4]+2*e[5]),c(a,"class","rect-mask-fg svelte-1a76qe7"),c(a,"x",e[1]),c(a,"y",e[2]),c(a,"width",e[3]),c(a,"height",e[4]),c(n,"id",e[6]),c(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),c(u,"class","a9s-outer"),c(u,"mask",`url(#${e[6]})`),c(u,"x",e[1]),c(u,"y",e[2]),c(u,"width",e[3]),c(u,"height",e[4]),c(d,"class","a9s-inner"),c(d,"x",e[1]),c(d,"y",e[2]),c(d,"width",e[3]),c(d,"height",e[4])},m(f,h){N(f,t,h),z(t,n),z(n,o),z(n,a),N(f,u,h),N(f,d,h)},p(f,h){h&34&&i!==(i=f[1]-f[5])&&c(o,"x",i),h&36&&s!==(s=f[2]-f[5])&&c(o,"y",s),h&40&&r!==(r=f[3]+2*f[5])&&c(o,"width",r),h&48&&l!==(l=f[4]+2*f[5])&&c(o,"height",l),h&2&&c(a,"x",f[1]),h&4&&c(a,"y",f[2]),h&8&&c(a,"width",f[3]),h&16&&c(a,"height",f[4]),h&2&&c(u,"x",f[1]),h&4&&c(u,"y",f[2]),h&8&&c(u,"width",f[3]),h&16&&c(u,"height",f[4]),h&2&&c(d,"x",f[1]),h&4&&c(d,"y",f[2]),h&8&&c(d,"width",f[3]),h&16&&c(d,"height",f[4])},d(f){f&&(B(t),B(u),B(d))}}}function Fs(e){let t,n=e[0]&&yo(e);return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){N(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=yo(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&B(t),n&&n.d()}}}function zs(e,t,n){let o;const i=Oe();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,d,f,h,g,m,p;const k=T=>{const C=T;u=performance.now(),r==="drag"&&(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,g=d[1]),n(3,m=1),n(4,p=1))},E=T=>{const C=T;d&&(f=l.elementToImage(C.offsetX,C.offsetY),n(1,h=Math.min(f[0],d[0])),n(2,g=Math.min(f[1],d[1])),n(3,m=Math.abs(f[0]-d[0])),n(4,p=Math.abs(f[1]-d[1])))},S=T=>{const C=T,M=performance.now()-u;if(r==="click"){if(M>300)return;d?w():(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,g=d[1]),n(3,m=1),n(4,p=1))}else d&&(M>300||m*p>100?(C.stopPropagation(),w()):(n(0,d=void 0),f=void 0))},w=()=>{if(m*p>15){const T={type:Q.RECTANGLE,geometry:{bounds:{minX:h,minY:g,maxX:h+m,maxY:g+p},x:h,y:g,w:m,h:p}};i("create",T)}n(0,d=void 0),f=void 0};Re(()=>{s("pointerdown",k),s("pointermove",E),s("pointerup",S,!0)});const A=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=T=>{"addEventListener"in T&&n(7,s=T.addEventListener),"drawingMode"in T&&n(8,r=T.drawingMode),"transform"in T&&n(9,l=T.transform),"viewportScale"in T&&n(10,a=T.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,o=2/a)},[d,h,g,m,p,o,A,s,r,l,a]}class _o extends ge{constructor(t){super(),he(this,t,zs,Fs,re,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function qt(e){const t=e.slice(),n=t[2].map(o=>o.join(",")).join(" ");return t[19]=n,t}function wo(e){let t,n,o,i,s,r,l,a,u,d,f,h,g,m,p=e[1]&&bo(e);return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),d=L("polygon"),h=L("polygon"),p&&p.c(),m=ke(),c(o,"x",i=e[3].x),c(o,"y",s=e[3].y),c(o,"width",r=e[3].w),c(o,"height",l=e[3].h),c(o,"class","svelte-18wrg3t"),c(a,"points",u=e[19]),c(a,"class","svelte-18wrg3t"),c(n,"id",e[5]),c(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),c(d,"class","a9s-outer"),c(d,"mask",`url(#${e[5]})`),c(d,"points",f=e[19]),c(h,"class","a9s-inner"),c(h,"points",g=e[19])},m(k,E){N(k,t,E),z(t,n),z(n,o),z(n,a),N(k,d,E),N(k,h,E),p&&p.m(k,E),N(k,m,E)},p(k,E){E&8&&i!==(i=k[3].x)&&c(o,"x",i),E&8&&s!==(s=k[3].y)&&c(o,"y",s),E&8&&r!==(r=k[3].w)&&c(o,"width",r),E&8&&l!==(l=k[3].h)&&c(o,"height",l),E&4&&u!==(u=k[19])&&c(a,"points",u),E&4&&f!==(f=k[19])&&c(d,"points",f),E&4&&g!==(g=k[19])&&c(h,"points",g),k[1]?p?p.p(k,E):(p=bo(k),p.c(),p.m(m.parentNode,m)):p&&(p.d(1),p=null)},d(k){k&&(B(t),B(d),B(h),B(m)),p&&p.d(k)}}}function bo(e){let t,n,o;return{c(){t=L("circle"),c(t,"class","a9s-handle svelte-18wrg3t"),c(t,"cx",n=e[0][0][0]),c(t,"cy",o=e[0][0][1]),c(t,"r",e[4])},m(i,s){N(i,t,s)},p(i,s){s&1&&n!==(n=i[0][0][0])&&c(t,"cx",n),s&1&&o!==(o=i[0][0][1])&&c(t,"cy",o),s&16&&c(t,"r",i[4])},d(i){i&&B(t)}}}function qs(e){let t,n=e[3]&&wo(qt(e));return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){N(o,t,i),n&&n.m(t,null)},p(o,[i]){o[3]?n?n.p(qt(o),i):(n=wo(qt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&B(t),n&&n.d()}}}const Ks=20,Ws=1500;function Zs(e,t,n){let o,i,s;const r=Oe();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,f,h=[],g,m,p=!1;const k=C=>{const M=C,{timeStamp:V,offsetX:U,offsetY:W}=M;if(f={timeStamp:V,offsetX:U,offsetY:W},a==="drag"&&h.length===0){const q=u.elementToImage(M.offsetX,M.offsetY);h.push(q),n(10,g=q)}},E=C=>{const M=C;if(m&&clearTimeout(m),h.length>0){if(n(10,g=u.elementToImage(M.offsetX,M.offsetY)),h.length>2){const V=tt(g,h[0])*d;n(1,p=V<Ks)}M.pointerType==="touch"&&(m=setTimeout(()=>{w()},Ws))}},S=C=>{const M=C;if(m&&clearTimeout(m),a==="click"){const V=M.timeStamp-f.timeStamp,U=tt([f.offsetX,f.offsetY],[M.offsetX,M.offsetY]);if(V>300||U>15)return;if(p)A();else if(h.length===0){const W=u.elementToImage(M.offsetX,M.offsetY);h.push(W),n(10,g=W)}else g&&h.push(g)}else{if(!g)return;if(h.length===1&&tt(h[0],g)<=4){n(0,h=[]),n(10,g=void 0);return}M.stopImmediatePropagation(),p?A():h.push(g)}},w=()=>{if(!g)return;const C=h.slice(0,-1);if(C.length<3)return;const M={type:Q.POLYGON,geometry:{bounds:fe(h),points:C}};ht(M)>4&&(n(0,h=[]),n(10,g=void 0),r("create",M))},A=()=>{const C={type:Q.POLYGON,geometry:{bounds:fe(h),points:[...h]}};n(0,h=[]),n(10,g=void 0),r("create",C)};Re(()=>{l("pointerdown",k,!0),l("pointermove",E),l("pointerup",S,!0),l("dblclick",w,!0)});const T=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=C=>{"addEventListener"in C&&n(6,l=C.addEventListener),"drawingMode"in C&&n(7,a=C.drawingMode),"transform"in C&&n(8,u=C.transform),"viewportScale"in C&&n(9,d=C.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,o=4/d),e.$$.dirty&1027&&n(2,i=g?p?h:[...h,g]:[]),e.$$.dirty&516&&n(3,s=i.length>0?st(fe(i),2/d):void 0)},[h,p,i,s,o,T,l,a,u,d,g]}class Js extends ge{constructor(t){super(),he(this,t,Zs,qs,re,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Kt=new Map([["rectangle",{tool:_o}],["polygon",{tool:Js}]]),Wt=()=>[...Kt.keys()],Zt=e=>Kt.get(e),Eo=(e,t,n={})=>Kt.set(e,{tool:t,opts:n});function Qs(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("ellipse"),i=L("ellipse"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"cx",e[2]),c(n,"cy",e[3]),c(n,"rx",e[4]),c(n,"ry",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"cx",e[2]),c(i,"cy",e[3]),c(i,"rx",e[4]),c(i,"ry",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function xs(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{cx:l,cy:a,rx:u,ry:d}=s;return e.$$set=f=>{"annotation"in f&&n(0,i=f.annotation),"geom"in f&&n(6,s=f.geom),"style"in f&&n(7,r=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=He(i,r))},[i,o,l,a,u,d,s,r]}class $s extends ge{constructor(t){super(),he(this,t,xs,Qs,re,{annotation:0,geom:6,style:7})}}function er(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("line"),i=L("line"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"x1",e[2]),c(n,"y1",e[3]),c(n,"x2",e[4]),c(n,"y2",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"x1",e[2]),c(i,"y1",e[3]),c(i,"x2",e[4]),c(i,"y2",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function tr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s,[[a,u],[d,f]]=l;return e.$$set=h=>{"annotation"in h&&n(0,i=h.annotation),"geom"in h&&n(6,s=h.geom),"style"in h&&n(7,r=h.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=He(i,r))},[i,o,a,u,d,f,s,r]}class nr extends ge{constructor(t){super(),he(this,t,tr,er,re,{annotation:0,geom:6,style:7})}}function vo(e,t,n){const o=e.slice();return o[5]=t[n],o}function So(e){let t,n,o;return{c(){t=L("path"),o=L("path"),c(t,"class","a9s-outer"),c(t,"style",n=e[1]?"display:none;":void 0),c(t,"fill-rule","evenodd"),c(t,"d",Le(e[5])),c(o,"class","a9s-inner"),c(o,"style",e[1]),c(o,"fill-rule","evenodd"),c(o,"d",Le(e[5]))},m(i,s){N(i,t,s),N(i,o,s)},p(i,s){s&2&&n!==(n=i[1]?"display:none;":void 0)&&c(t,"style",n),s&2&&c(o,"style",i[1])},d(i){i&&(B(t),B(o))}}}function or(e){let t,n,o=ve(e[2]),i=[];for(let s=0;s<o.length;s+=1)i[s]=So(vo(e,o,s));return{c(){t=L("g");for(let s=0;s<i.length;s+=1)i[s].c();c(t,"class","a9s-annotation"),c(t,"data-id",n=e[0].id)},m(s,r){N(s,t,r);for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(t,null)},p(s,[r]){if(r&6){o=ve(s[2]);let l;for(l=0;l<o.length;l+=1){const a=vo(s,o,l);i[l]?i[l].p(a,r):(i[l]=So(a),i[l].c(),i[l].m(t,null))}for(;l<i.length;l+=1)i[l].d(1);i.length=o.length}r&1&&n!==(n=s[0].id)&&c(t,"data-id",n)},i:j,o:j,d(s){s&&B(t),Ye(i,s)}}}function ir(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{polygons:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=He(i,r))},[i,o,l,s,r]}class sr extends ge{constructor(t){super(),he(this,t,ir,or,re,{annotation:0,geom:3,style:4})}}function rr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("polygon"),i=L("polygon"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"points",e[2].map(lr).join(" ")),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"points",e[2].map(ar).join(" ")),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}const lr=e=>e.join(","),ar=e=>e.join(",");function cr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=He(i,r))},[i,o,l,s,r]}class ur extends ge{constructor(t){super(),he(this,t,cr,rr,re,{annotation:0,geom:3,style:4})}}function fr(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("path"),s=L("path"),c(n,"class",o=je(`a9s-outer ${e[1]}`)+" svelte-1w0132l"),c(n,"style",i=e[3]?"display:none;":void 0),c(n,"d",e[2]),c(s,"class",r=je(`a9s-inner ${e[1]}`)+" svelte-1w0132l"),c(s,"style",e[3]),c(s,"d",e[2]),c(t,"class","a9s-annotation"),c(t,"data-id",l=e[0].id)},m(a,u){N(a,t,u),z(t,n),z(t,s)},p(a,[u]){u&2&&o!==(o=je(`a9s-outer ${a[1]}`)+" svelte-1w0132l")&&c(n,"class",o),u&8&&i!==(i=a[3]?"display:none;":void 0)&&c(n,"style",i),u&4&&c(n,"d",a[2]),u&2&&r!==(r=je(`a9s-inner ${a[1]}`)+" svelte-1w0132l")&&c(s,"class",r),u&8&&c(s,"style",a[3]),u&4&&c(s,"d",a[2]),u&1&&l!==(l=a[0].id)&&c(t,"data-id",l)},i:j,o:j,d(a){a&&B(t)}}}function dr(e,t,n){let o,i,s,{annotation:r}=t,{geom:l}=t,{style:a}=t;return e.$$set=u=>{"annotation"in u&&n(0,r=u.annotation),"geom"in u&&n(4,l=u.geom),"style"in u&&n(5,a=u.style)},e.$$.update=()=>{e.$$.dirty&33&&n(3,o=He(r,a)),e.$$.dirty&16&&n(2,i=Ct(l)),e.$$.dirty&16&&n(1,s=l.closed?"closed":"open")},[r,s,i,o,l,a]}class hr extends ge{constructor(t){super(),he(this,t,dr,fr,re,{annotation:0,geom:4,style:5})}}function gr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("rect"),i=L("rect"),c(n,"class","a9s-outer"),c(n,"style",o=e[5]?"display:none;":void 0),c(n,"x",e[4]),c(n,"y",e[3]),c(n,"width",e[2]),c(n,"height",e[1]),c(i,"class","a9s-inner"),c(i,"style",e[5]),c(i,"x",e[4]),c(i,"y",e[3]),c(i,"width",e[2]),c(i,"height",e[1]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){N(r,t,l),z(t,n),z(t,i)},p(r,[l]){l&32&&o!==(o=r[5]?"display:none;":void 0)&&c(n,"style",o),l&16&&c(n,"x",r[4]),l&8&&c(n,"y",r[3]),l&4&&c(n,"width",r[2]),l&2&&c(n,"height",r[1]),l&32&&c(i,"style",r[5]),l&16&&c(i,"x",r[4]),l&8&&c(i,"y",r[3]),l&4&&c(i,"width",r[2]),l&2&&c(i,"height",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&B(t)}}}function mr(e,t,n){let o,i,s,r,l,{annotation:a}=t,{geom:u}=t,{style:d}=t;return e.$$set=f=>{"annotation"in f&&n(0,a=f.annotation),"geom"in f&&n(6,u=f.geom),"style"in f&&n(7,d=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=He(a,d)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:l}=u,i,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,l),n(6,u)))},[a,l,r,s,i,o,u,d]}class pr extends ge{constructor(t){super(),he(this,t,mr,gr,re,{annotation:0,geom:6,style:7})}}const yr={elementToImage:(e,t)=>[e,t]},Ao=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),_r=250,ko=(e,t)=>{const n=Oe();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<_r){const{x:a,y:u}=Jt(r,e),d=Ie?10:2,f=t.getAt(a,u,void 0,d);f?n("click",{originalEvent:r,annotation:f}):n("click",{originalEvent:r})}}}},Jt=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=i+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function Mo(e,t,n){const o=e.slice();return o[39]=t[n],o}function To(e,t,n){const o=e.slice();return o[42]=t[n],o}function Qt(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Po(e){let t=e[42],n,o,i=Lo(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&131072&&re(t,t=s[42])?(be(),G(i,1,1,j),Ee(),i=Lo(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function wr(e){let t,n;return t=new nr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function br(e){let t,n;return t=new hr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Er(e){let t,n;return t=new sr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function vr(e){let t,n;return t=new ur({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Sr(e){let t,n;return t=new pr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ar(e){var o;let t,n;return t=new $s({props:{annotation:e[42],geom:(o=e[45])==null?void 0:o.geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){var l;const r={};s[0]&131072&&(r.annotation=i[42]),s[0]&131072&&(r.geom=(l=i[45])==null?void 0:l.geometry),s[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(R(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function Lo(e){let t,n,o,i;const s=[Ar,Sr,vr,Er,br,wr],r=[];function l(a,u){var d,f,h,g,m,p;return((d=a[45])==null?void 0:d.type)===Q.ELLIPSE?0:((f=a[45])==null?void 0:f.type)===Q.RECTANGLE?1:((h=a[45])==null?void 0:h.type)===Q.POLYGON?2:((g=a[45])==null?void 0:g.type)===Q.MULTIPOLYGON?3:((m=a[45])==null?void 0:m.type)===Q.POLYLINE?4:((p=a[45])==null?void 0:p.type)===Q.LINE?5:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),N(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),R(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(R(n),i=!0)},o(a){G(n),i=!1},d(a){a&&B(o),~t&&r[t].d(a)}}}function Io(e){let t=ot(e[42])&&!e[10](e[42]),n,o,i=t&&Po(Qt(e));return{c(){i&&i.c(),n=ke()},m(s,r){i&&i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&132096&&(t=ot(s[42])&&!s[10](s[42])),t?i?(i.p(Qt(s),r),r[0]&132096&&R(i,1)):(i=Po(Qt(s)),i.c(),R(i,1),i.m(n.parentNode,n)):i&&(be(),G(i,1,1,()=>{i=null}),Ee())},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i&&i.d(s)}}}function Co(e){let t,n,o,i;const s=[Mr,kr],r=[];function l(a,u){return a[6]?0:a[15]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),N(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),R(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(R(n),i=!0)},o(a){G(n),i=!1},d(a){a&&B(o),~t&&r[t].d(a)}}}function kr(e){let t=`${e[2]}-${e[7]}`,n,o,i=Oo(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&132&&re(t,t=`${s[2]}-${s[7]}`)?(be(),G(i,1,1,j),Ee(),i=Oo(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function Mr(e){let t,n,o=ve(e[6]),i=[];for(let r=0;r<o.length;r+=1)i[r]=Bo(Mo(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);N(r,t,l),n=!0},p(r,l){if(l[0]&8659266){o=ve(r[6]);let a;for(a=0;a<o.length;a+=1){const u=Mo(r,o,a);i[a]?(i[a].p(u,l),R(i[a],1)):(i[a]=Bo(u),i[a].c(),R(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)R(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&B(t),Ye(i,r)}}}function Oo(e){let t,n;return t=new po({props:{target:e[8],tool:e[15],drawingMode:e[14],transform:e[13],viewportScale:e[18]}}),t.$on("create",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&256&&(s.target=o[8]),i[0]&32768&&(s.tool=o[15]),i[0]&16384&&(s.drawingMode=o[14]),i[0]&8192&&(s.transform=o[13]),i[0]&262144&&(s.viewportScale=o[18]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Do(e){let t,n;return t=new mo({props:{target:e[8],editor:e[39].editor,annotation:e[39].annotation,style:e[1],transform:e[13],viewportScale:e[18]}}),t.$on("change",function(){ie(e[23](e[39].annotation))&&e[23](e[39].annotation).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&256&&(s.target=e[8]),i[0]&64&&(s.editor=e[39].editor),i[0]&64&&(s.annotation=e[39].annotation),i[0]&2&&(s.style=e[1]),i[0]&8192&&(s.transform=e[13]),i[0]&262144&&(s.viewportScale=e[18]),t.$set(s)},i(o){n||(R(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Bo(e){let t=e[39].annotation.id,n,o,i=Do(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),N(s,n,r),o=!0},p(s,r){r[0]&64&&re(t,t=s[39].annotation.id)?(be(),G(i,1,1,j),Ee(),i=Do(s),i.c(),R(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(R(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function Tr(e){let t,n,o,i,s,r,l=ve(e[17].filter(e[34])),a=[];for(let f=0;f<l.length;f+=1)a[f]=Io(To(e,l,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&Co(e);return{c(){t=L("svg"),n=L("g");for(let f=0;f<a.length;f+=1)a[f].c();o=L("g"),d&&d.c(),c(o,"class","drawing"),c(t,"role","application"),c(t,"tabindex",0),c(t,"class","a9s-annotationlayer"),Pe(t,"drawing",e[15]),Pe(t,"editing",e[5]),Pe(t,"hidden",!e[3]),Pe(t,"hover",e[16])},m(f,h){N(f,t,h),z(t,n);for(let g=0;g<a.length;g+=1)a[g]&&a[g].m(n,null);z(t,o),d&&d.m(o,null),e[35](o),e[36](t),i=!0,s||(r=[J(t,"pointerup",function(){ie(e[11])&&e[11].apply(this,arguments)}),J(t,"pointerdown",function(){ie(e[12])&&e[12].apply(this,arguments)}),J(t,"pointermove",e[24])],s=!0)},p(f,h){if(e=f,h[0]&132098){l=ve(e[17].filter(e[34]));let g;for(g=0;g<l.length;g+=1){const m=To(e,l,g);a[g]?(a[g].p(m,h),R(a[g],1)):(a[g]=Io(m),a[g].c(),R(a[g],1),a[g].m(n,null))}for(be(),g=l.length;g<a.length;g+=1)u(g);Ee()}e[8]?d?(d.p(e,h),h[0]&256&&R(d,1)):(d=Co(e),d.c(),R(d,1),d.m(o,null)):d&&(be(),G(d,1,1,()=>{d=null}),Ee()),(!i||h[0]&32768)&&Pe(t,"drawing",e[15]),(!i||h[0]&32)&&Pe(t,"editing",e[5]),(!i||h[0]&8)&&Pe(t,"hidden",!e[3]),(!i||h[0]&65536)&&Pe(t,"hover",e[16])},i(f){if(!i){for(let h=0;h<l.length;h+=1)R(a[h]);R(d),i=!0}},o(f){a=a.filter(Boolean);for(let h=0;h<a.length;h+=1)G(a[h]);G(d),i=!1},d(f){f&&B(t),Ye(a,f),d&&d.d(),e[35](null),e[36](null),s=!1,Ae(r)}}}function Pr(e,t,n){let o,i,s,r,l,a,u,d,f,h,g,m,p=j,k=()=>(p(),p=an(_,X=>n(18,m=X)),_);e.$$.on_destroy.push(()=>p());let{drawingEnabled:E}=t,{image:S}=t,{preferredDrawingMode:w}=t,{state:A}=t,{style:T=void 0}=t,{toolName:C=Wt()[0]}=t,{user:M}=t,{visible:V=!0}=t,U=0;const W=()=>n(7,U+=1),q=()=>C,v=()=>E;let b,y,_;Re(()=>k(n(9,_=Gn(S,y))));const{hover:I,selection:P,store:D}=A;kt(e,I,X=>n(16,f=X)),kt(e,P,X=>n(33,h=X)),kt(e,D,X=>n(17,g=X));let F,H;const x=X=>{F&&D.unobserve(F);const de=X.filter(({editable:te})=>te).map(({id:te})=>te);de.length>0?(n(5,H=de.map(te=>D.getAnnotation(te)).filter(te=>te&&ot(te))),F=te=>{const{updated:ye}=te.changes;n(5,H=ye==null?void 0:ye.map(_e=>_e.newValue))},D.observe(F,{annotations:de})):n(5,H=void 0)},Z=X=>{const de=Bn(),te={id:de,bodies:[],target:{annotation:de,selector:X.detail,creator:M,created:new Date}};D.addAnnotation(te),P.setSelected(te.id)},$=X=>de=>{var Je;const{target:te}=X,ye=10*60*1e3,_e=((Je=te.creator)==null?void 0:Je.id)!==M.id||!te.created||new Date().getTime()-te.created.getTime()>ye;D.updateTarget({...te,selector:de.detail,created:_e?te.created:new Date,updated:_e?new Date:void 0,updatedBy:_e?M:void 0})},oe=X=>{const{x:de,y:te}=Jt(X,y),ye=D.getAt(de,te,void 0,2);ye?f!==ye.id&&I.set(ye.id):I.set(void 0)},se=X=>ot(X);function Se(X){ft[X?"unshift":"push"](()=>{b=X,n(8,b)})}function Te(X){ft[X?"unshift":"push"](()=>{y=X,n(4,y)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,E=X.drawingEnabled),"image"in X&&n(25,S=X.image),"preferredDrawingMode"in X&&n(26,w=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,T=X.style),"toolName"in X&&n(2,C=X.toolName),"user"in X&&n(28,M=X.user),"visible"in X&&n(3,V=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:o,opts:i}=Zt(C)||{tool:void 0,opts:void 0},o,(n(32,i),n(2,C))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(14,s=(i==null?void 0:i.drawingMode)||w),e.$$.dirty[0]&16&&n(13,r=Ao(y)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=ko(y,D),l,(n(11,a),n(4,y))),e.$$.dirty[1]&4&&x(h.selected),e.$$.dirty[0]&32&&n(6,u=H?H.map(X=>({annotation:X,editor:ho(X.target.selector)})).filter(X=>X.editor):void 0),e.$$.dirty[0]&64&&n(10,d=X=>u&&u.some(de=>de.annotation.id===X.id))},[E,T,C,V,y,H,u,U,b,_,d,a,l,r,s,o,f,g,m,I,P,D,Z,$,oe,S,w,A,M,W,q,v,i,h,se,Se,Te]}class No extends ge{constructor(t){super(),he(this,t,Pr,Tr,re,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function Uo(e,t,n=0,o=e.length-1,i=Lr){for(;o>n;){if(o-n>600){const a=o-n+1,u=t-n+1,d=Math.log(a),f=.5*Math.exp(2*d/3),h=.5*Math.sqrt(d*f*(a-f)/a)*(u-a/2<0?-1:1),g=Math.max(n,Math.floor(t-u*f/a+h)),m=Math.min(o,Math.floor(t+(a-u)*f/a+h));Uo(e,t,g,m,i)}const s=e[t];let r=n,l=o;for(at(e,n,t),i(e[o],s)>0&&at(e,n,o);r<l;){for(at(e,r,l),r++,l--;i(e[r],s)<0;)r++;for(;i(e[l],s)>0;)l--}i(e[n],s)===0?at(e,n,l):(l++,at(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function at(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Lr(e,t){return e<t?-1:e>t?1:0}class Ir{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!bt(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?i(l):l;bt(t,a)&&(n.leaf?o.push(l):$t(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!bt(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(bt(t,r)){if(n.leaf||$t(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Ze([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let l,a,u;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],l=r.pop(),u=!0),o.leaf){const d=Cr(t,o.children,n);if(d!==-1)return o.children.splice(d,1),s.push(o),this._condense(s),this}!u&&!o.leaf&&$t(o,i)?(s.push(o),r.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],u=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,l;if(s<=r)return l=Ze(t.slice(n,o+1)),We(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=Ze([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));Yo(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);Yo(t,d,f,a,this.compareMinY);for(let h=d;h<=f;h+=a){const g=Math.min(h+a-1,f);l.children.push(this._build(t,h,g,i-1))}}return We(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const u=n.children[a],d=xt(u),f=Br(t,u)-d;f<r?(r=f,s=d<s?d:s,l=u):f===r&&d<s&&(s=d,l=u)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),ut(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),l=Ze(o.children.splice(r,o.children.length-r));l.height=o.height,l.leaf=o.leaf,We(o,this.toBBox),We(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=Ze([t,n]),this.data.height=t.height+1,this.data.leaf=!1,We(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let l=n;l<=o-n;l++){const a=ct(t,0,l,this.toBBox),u=ct(t,l,o,this.toBBox),d=Nr(a,u),f=xt(a)+xt(u);d<s?(s=d,i=l,r=f<r?f:r):d===s&&f<r&&(r=f,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Or,s=t.leaf?this.compareMinY:Dr,r=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,s);r<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=ct(t,0,n,s),l=ct(t,o-n,o,s);let a=wt(r)+wt(l);for(let u=n;u<o-n;u++){const d=t.children[u];ut(r,t.leaf?s(d):d),a+=wt(r)}for(let u=o-n-1;u>=n;u--){const d=t.children[u];ut(l,t.leaf?s(d):d),a+=wt(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)ut(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():We(t[n],this.toBBox)}}function Cr(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function We(e,t){ct(e,0,e.children.length,t,e)}function ct(e,t,n,o,i){i||(i=Ze(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];ut(i,e.leaf?o(r):r)}return i}function ut(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Or(e,t){return e.minX-t.minX}function Dr(e,t){return e.minY-t.minY}function xt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function wt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Br(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Nr(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function $t(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function bt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ze(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Yo(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;Uo(e,r,t,n,i),s.push(t,r,r,n)}}const Ur=()=>{const e=new Ir,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!it(f))return;const{minX:h,minY:g,maxX:m,maxY:p}=f.selector.geometry.bounds,k={minX:h,minY:g,maxX:m,maxY:p,target:f};e.insert(k),t.set(f.annotation,k)},s=f=>{if(!it(f))return;const h=t.get(f.annotation);h&&e.remove(h),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,h,g=0)=>{const p=e.search({minX:f-g,minY:h-g,maxX:f+g,maxY:h+g}).map(k=>k.target).filter(k=>k.selector.type===Q.RECTANGLE||wn(k.selector,f,h,g));return p.length>0?(p.sort((k,E)=>ht(k.selector)-ht(E.selector)),p):[]},getIntersecting:(f,h,g,m)=>e.search({minX:f,minY:h,maxX:f+g,maxY:h+m}).map(p=>p.target),insert:i,remove:s,set:(f,h=!0)=>{h&&o();const g=f.reduce((m,p)=>{if(it(p)){const{minX:k,minY:E,maxX:S,maxY:w}=p.selector.geometry.bounds;return[...m,{minX:k,minY:E,maxX:S,maxY:w,target:p}]}else return m},[]);g.forEach(m=>t.set(m.target.annotation,m)),e.load(g)},size:()=>e.all().length,update:(f,h)=>{s(f),i(h)}}},Ro=e=>({...e,subscribe:n=>{const o=i=>n(i.state);return e.observe(o),n(e.all()),()=>e.unobserve(o)}}),Vo=e=>{const t=Fi(),n=Ur(),o=Li(t,e.userSelectAction,e.adapter),i=Pi(t),s=Wi();return t.observe(({changes:a})=>{n.set((a.created||[]).map(u=>u.target),!1),(a.deleted||[]).forEach(u=>n.remove(u.target)),(a.updated||[]).forEach(({oldValue:u,newValue:d})=>n.update(u.target,d.target))}),{store:{...t,getAt:(a,u,d,f)=>{const h=n.getAt(a,u,f);if(d)return h.map(m=>t.getAnnotation(m.annotation)).filter(Boolean).filter(d)[0];{const g=h[0];return g?t.getAnnotation(g.annotation):void 0}},getIntersecting:(a,u,d,f)=>n.getIntersecting(a,u,d,f).map(h=>t.getAnnotation(h.annotation)).filter(Boolean)},selection:o,hover:i,viewport:s}},Xo=e=>{const t=Vo(e);return{...t,store:Ro(t.store)}},Ho=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(r,l,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=u}return o/81},Go=e=>{const t=Ho(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},en=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Go(e):n),jo=(e,t)=>({...e,drawingEnabled:e.drawingEnabled===void 0?t.drawingEnabled:e.drawingEnabled,drawingMode:e.drawingMode||t.drawingMode,userSelectAction:e.userSelectAction||t.userSelectAction,theme:e.theme||t.theme}),tn=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Fo=(e,t)=>{const n=t||document,o=r=>{const l=r;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},i=r=>{const l=r;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},s=()=>{tn?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return tn?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Yr=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=jo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Bt.EDIT,theme:"light"}),i=Xo(o),{selection:s,store:r}=i,l=Ki(r,o.initialHistory),a=Zi(i,l,o.adapter,o.autoSave),u=document.createElement("DIV");u.style.position="relative",u.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(u,n),u.appendChild(n);const d=Fo(l);let f=ss();en(n,u,o.theme);const h=new No({target:u,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});h.$on("click",b=>{const{originalEvent:y,annotation:_}=b.detail;_?s.userSelect(_.id,y):s.isEmpty()||s.clear()});const g=Qi(i,l,o.adapter),m=()=>h.cancelDrawing(),p=()=>{h.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),l.destroy()},k=()=>h.getDrawingTool(),E=()=>f,S=()=>h.isDrawingEnabled(),w=(b,y,_)=>Eo(b,y,_),A=(b,y)=>go(b,y),T=b=>{if(!Zt(b))throw`No drawing tool named ${b}`;h.$set({toolName:b})},C=b=>h.$set({drawingEnabled:b}),M=b=>h.$set({preferredDrawingMode:b}),V=b=>{console.warn("Filter not implemented yet")},U=b=>h.$set({style:b}),W=b=>en(n,u,b),q=b=>{f=b,h.$set({user:b})},v=b=>h.$set({visible:b});return{...g,cancelDrawing:m,destroy:p,getDrawingTool:k,getUser:E,isDrawingEnabled:S,listDrawingTools:Wt,on:a.on,off:a.off,registerDrawingTool:w,registerShapeEditor:A,setDrawingEnabled:C,setDrawingMode:M,setDrawingTool:T,setFilter:V,setStyle:U,setTheme:W,setUser:q,setVisible:v,element:u,state:i}};O.Editor=_t,O.EditorMount=mo,O.Handle=Ge,O.IdentityTransform=yr,O.MidpointHandle=Rt,O.PolygonEditor=$n,O.RectangleEditor=eo,O.RectangleUtil=An,O.RubberbandRectangle=_o,O.SVGAnnotationLayer=No,O.ShapeType=Q,O.ToolMount=po,O.UserSelectAction=Bt,O.W3CImageFormat=fs,O.addEventListeners=ko,O.approximateAsPolygon=gt,O.boundsFromMultiPolygonElements=nt,O.boundsFromPoints=fe,O.chainStyles=$i,O.computeArea=ht,O.computePolygonArea=$e,O.computeSVGPath=Ct,O.computeStyle=xi,O.createBody=Ui,O.createImageAnnotator=Yr,O.createImageAnnotatorState=Vo,O.createSVGTransform=Ao,O.createSvelteImageAnnotatorState=Xo,O.defaultColorProvider=us,O.detectTheme=Go,O.distance=tt,O.enableResponsive=Gn,O.fillDefaults=jo,O.getAllCorners=En,O.getEditor=ho,O.getMaskDimensions=st,O.getSVGPoint=Jt,O.getTool=Zt,O.initKeyboardCommands=Fo,O.intersects=wn,O.isFragmentSelector=kn,O.isImageAnnotation=ot,O.isImageAnnotationTarget=it,O.isMac=tn,O.isPointInPolygon=et,O.isTouch=Ie,O.listDrawingTools=Wt,O.multipolygonElementToPath=Le,O.parseFragmentSelector=Mn,O.parseSVGSelector=Cn,O.parseW3CImageAnnotation=Xn,O.pointsToPath=bn,O.registerEditor=go,O.registerShapeUtil=Xe,O.registerTool=Eo,O.sampleBrightness=Ho,O.serializeFragmentSelector=Tn,O.serializeSVGSelector=On,O.serializeW3CImageAnnotation=Hn,O.setTheme=en,O.simplifyMultiPolygon=ci,O.simplifyPoints=It,O.simplifyPolygon=fi,O.toSvelteStore=Ro,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(D,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(D=typeof globalThis<"u"?globalThis:D||self,q(D.Annotorious={}))})(this,function(D){"use strict";var ol=Object.defineProperty;var il=(D,q,Ce)=>q in D?ol(D,q,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):D[q]=Ce;var hn=(D,q,Ce)=>il(D,typeof q!="symbol"?q+"":q,Ce);function q(){}function Ce(e,t){for(const n in t)e[n]=t[n];return e}function mn(e){return e()}function pn(){return Object.create(null)}function Ae(e){e.forEach(mn)}function se(e){return typeof e=="function"}function re(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function ri(e){return Object.keys(e).length===0}function yn(e,...t){if(e==null){for(const o of t)o(void 0);return q}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function Ct(e,t,n){e.$$.on_destroy.push(yn(t,n))}function li(e,t,n,o){if(e){const i=_n(e,t,n,o);return e[0](i)}}function _n(e,t,n,o){return e[1]&&o?Ce(n.ctx.slice(),e[1](o(t))):n.ctx}function ai(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=[],l=Math.max(t.dirty.length,i.length);for(let r=0;r<l;r+=1)s[r]=t.dirty[r]|i[r];return s}return t.dirty|i}return t.dirty}function ci(e,t,n,o,i,s){if(i){const l=_n(t,n,o,s);e.p(l,i)}}function ui(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 wn(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function qe(e){return e??""}function j(e,t){e.appendChild(t)}function U(e,t,n){e.insertBefore(t,n||null)}function B(e){e.parentNode&&e.parentNode.removeChild(e)}function He(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function P(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function bn(e){return document.createTextNode(e)}function be(){return bn(" ")}function Me(){return bn("")}function x(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 fi(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function di(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let xe;function et(e){xe=e}function En(){if(!xe)throw new Error("Function called outside component initialization");return xe}function Oe(e){En().$$.on_mount.push(e)}function De(){const e=En();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=di(t,n,{cancelable:o});return i.slice().forEach(l=>{l.call(e,s)}),!s.defaultPrevented}return!0}}function ge(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const Ke=[],ht=[];let We=[];const vn=[],Sn=Promise.resolve();let Ot=!1;function An(){Ot||(Ot=!0,Sn.then(kn))}function Mn(){return An(),Sn}function Dt(e){We.push(e)}const Nt=new Set;let Ze=0;function kn(){if(Ze!==0)return;const e=xe;do{try{for(;Ze<Ke.length;){const t=Ke[Ze];Ze++,et(t),gi(t.$$)}}catch(t){throw Ke.length=0,Ze=0,t}for(et(null),Ke.length=0,Ze=0;ht.length;)ht.pop()();for(let t=0;t<We.length;t+=1){const n=We[t];Nt.has(n)||(Nt.add(n),n())}We.length=0}while(Ke.length);for(;vn.length;)vn.pop()();Ot=!1,Nt.clear(),et(e)}function gi(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(Dt)}}function hi(e){const t=[],n=[];We.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),We=t}const mt=new Set;let Ge;function Ee(){Ge={r:0,c:[],p:Ge}}function ve(){Ge.r||Ae(Ge.c),Ge=Ge.p}function Y(e,t){e&&e.i&&(mt.delete(e),e.i(t))}function G(e,t,n,o){if(e&&e.o){if(mt.has(e))return;mt.add(e),Ge.c.push(()=>{mt.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function Se(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ue(e){e&&e.c()}function le(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),Dt(()=>{const s=e.$$.on_mount.map(mn).filter(se);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ae(s),e.$$.on_mount=[]}),i.forEach(Dt)}function ae(e,t){const n=e.$$;n.fragment!==null&&(hi(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function mi(e,t){e.$$.dirty[0]===-1&&(Ke.push(e),An(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function he(e,t,n,o,i,s,l=null,r=[-1]){const a=xe;et(e);const u=e.$$={fragment:null,ctx:[],props:s,update:q,not_equal:i,bound:pn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:pn(),dirty:r,skip_bound:!1,root:t.target||a.$$.root};l&&l(u.root);let d=!1;if(u.ctx=n?n(e,t.props||{},(f,g,...h)=>{const p=h.length?h[0]:g;return u.ctx&&i(u.ctx[f],u.ctx[f]=p)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](p),d&&mi(e,f)),g}):[],u.update(),d=!0,Ae(u.before_update),u.fragment=o?o(u.ctx):!1,t.target){if(t.hydrate){const f=fi(t.target);u.fragment&&u.fragment.l(f),f.forEach(B)}else u.fragment&&u.fragment.c();t.intro&&Y(e.$$.fragment),le(e,t.target,t.anchor),kn()}et(a)}class me{constructor(){hn(this,"$$");hn(this,"$$set")}$destroy(){ae(this,1),this.$destroy=q}$on(t,n){if(!se(n))return q;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&&!ri(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const pi="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(pi);var Q=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(Q||{});function yi(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Tn={exports:{}};(function(e){(function(){function t(r,a){var u=r.x-a.x,d=r.y-a.y;return u*u+d*d}function n(r,a,u){var d=a.x,f=a.y,g=u.x-d,h=u.y-f;if(g!==0||h!==0){var p=((r.x-d)*g+(r.y-f)*h)/(g*g+h*h);p>1?(d=u.x,f=u.y):p>0&&(d+=g*p,f+=h*p)}return g=r.x-d,h=r.y-f,g*g+h*h}function o(r,a){for(var u=r[0],d=[u],f,g=1,h=r.length;g<h;g++)f=r[g],t(f,u)>a&&(d.push(f),u=f);return u!==f&&d.push(f),d}function i(r,a,u,d,f){for(var g=d,h,p=a+1;p<u;p++){var _=n(r[p],r[a],r[u]);_>g&&(h=p,g=_)}g>d&&(h-a>1&&i(r,a,h,d,f),f.push(r[h]),u-h>1&&i(r,h,u,d,f))}function s(r,a){var u=r.length-1,d=[r[0]];return i(r,0,u,a,d),d.push(r[u]),d}function l(r,a,u){if(r.length<=2)return r;var d=a!==void 0?a*a:1;return r=u?r:o(r,d),r=s(r,d),r}e.exports=l,e.exports.default=l})()})(Tn);var _i=Tn.exports;const wi=yi(_i),Rt={},je=(e,t)=>Rt[e]=t,pt=e=>Rt[e.type].area(e),Pn=(e,t,n,o)=>Rt[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,l])=>{t=Math.min(t,s),n=Math.min(n,l),o=Math.max(o,s),i=Math.max(i,l)}),{minX:t,minY:n,maxX:o,maxY:i}},tt=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)},nt=(e,t,n)=>{let o=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const l=e[i][0],r=e[i][1],a=e[s][0],u=e[s][1];r>n!=u>n&&t<(a-l)*(n-r)/(u-r)+l&&(o=!o)}return o},Ln=(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},Bt=(e,t=1)=>{const n=e.map(([o,i])=>({x:o,y:i}));return wi(n,t,!0).map(o=>[o.x,o.y])},ot=(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))},bi={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:l}=e.geometry,r=0,a=Math.cos(r),u=Math.sin(r),d=t-o,f=n-i,g=a*d+u*f,h=u*d-a*f;return g*g/(s*s)+h*h/(l*l)<=1}};je(Q.ELLIPSE,bi);const Ei={area:e=>0,intersects:(e,t,n,o=2)=>{const[[i,s],[l,r]]=e.geometry.points,a=Math.abs((r-s)*t-(l-i)*n+l*s-r*i),u=ot([i,s],[l,r]);return a/u<=o}};je(Q.LINE,Ei);const vi={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,o)=>{const[i,...s]=o.rings,l=tt(i.points),r=s.reduce((a,u)=>a+tt(u.points),0);return n+l-r},0)},intersects:(e,t,n)=>{const{polygons:o}=e.geometry;for(const i of o){const[s,...l]=i.rings;if(nt(s.points,t,n)){let r=!1;for(const a of l)if(nt(a.points,t,n)){r=!0;break}if(!r)return!0}}return!1}},it=e=>{const t=e.reduce((n,o)=>[...n,...o.rings[0].points],[]);return fe(t)},Le=e=>e.rings.map(n=>Ln(n.points)).join(" "),In=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((o,i)=>[...o,...i.points],[])],[]),Si=(e,t=1)=>{const n=e.geometry.polygons.map(i=>{const s=i.rings.map(r=>{const a=Bt(r.points,t);return{...r,points:a}}),l=fe(s[0].points);return{...i,rings:s,bounds:l}}),o=it(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:o}}};je(Q.MULTIPOLYGON,vi);const Ai={area:e=>{const t=e.geometry.points;return tt(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return nt(o,t,n)}},Mi=(e,t=1)=>{const n=Bt(e.geometry.points,t),o=fe(n);return{...e,geometry:{...e.geometry,bounds:o,points:n}}};je(Q.POLYGON,Ai);const ki={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=yt(t.points,t.closed);return tt(n)},intersects:(e,t,n,o=2)=>{const i=e.geometry;if(i.closed){const s=yt(i.points,i.closed);return nt(s,t,n)}else return Ti(i,[t,n],o)}},yt=(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 r=Cn(i.point,i.type==="CURVE"&&i.outHandle||i.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);n.push(...r.slice(1))}}return n},Cn=(e,t,n,o,i=10)=>{const s=[];for(let l=0;l<=i;l++){const r=l/i,a=Math.pow(1-r,3)*e[0]+3*Math.pow(1-r,2)*r*t[0]+3*(1-r)*Math.pow(r,2)*n[0]+Math.pow(r,3)*o[0],u=Math.pow(1-r,3)*e[1]+3*Math.pow(1-r,2)*r*t[1]+3*(1-r)*Math.pow(r,2)*n[1]+Math.pow(r,3)*o[1];s.push([a,u])}return s},Ti=(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 r=Cn(i.point,i.type==="CURVE"&&i.outHandle||i.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let a=0;a<r.length-1;a++)if(On(t,r[a],r[a+1])<=n)return!0}else if(On(t,i.point,s.point)<=n)return!0}return!1},On=(e,t,n)=>{const[o,i]=e,[s,l]=t,[r,a]=n,u=r-s,d=a-l,f=Math.sqrt(u*u+d*d);if(f===0)return Math.sqrt((o-s)*(o-s)+(i-l)*(i-l));const g=((o-s)*u+(i-l)*d)/(f*f);return g<=0?Math.sqrt((o-s)*(o-s)+(i-l)*(i-l)):g>=1?Math.sqrt((o-r)*(o-r)+(i-a)*(i-a)):Math.abs((a-l)*o-(r-s)*i+r*l-a*s)/f},Ut=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 l=s.type==="CURVE"&&s.outHandle||s.point,r=i.type==="CURVE"&&i.inHandle||i.point,a=i.point;t.push(`C ${l[0]} ${l[1]} ${r[0]} ${r[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 l=o.outHandle||o.point,r=i.inHandle||i.point,a=i.point;t.push(`C ${l[0]} ${l[1]} ${r[0]} ${r[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};je(Q.POLYLINE,ki);const Dn={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>{const o=e.geometry;if(o.rot){const i=o.x+o.w/2,s=o.y+o.h/2,l=t-i,r=n-s,a=Math.cos(o.rot),u=Math.sin(o.rot),d=l*a+r*u,f=-l*u+r*a;return d>=-o.w/2&&d<=o.w/2&&f>=-o.h/2&&f<=o.h/2}else return t>=o.x&&t<=o.x+o.w&&n>=o.y&&n<=o.y+o.h}};je(Q.RECTANGLE,Dn);const st=e=>rt(e.target),rt=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},Nn=e=>(e==null?void 0:e.type)==="FragmentSelector"?!0:typeof e=="string"?e.indexOf("#")<0?!1:/#xywh(?:=(?:pixel:|percent:)?)(.+?),(.+?),(.+?),(.+)$/i.test(e):!1,Rn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(?:(pixel|percent):)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0];if(!i)throw new Error("Not a MediaFragment: "+n);const[s,l,r,a,u,d,f]=i;if(l!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(r&&r!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${r}`);const[g,h,p,_]=[a,u,d,f].map(parseFloat);return{type:Q.RECTANGLE,geometry:{x:g,y:h,w:p,h:_,rot:0,bounds:{minX:g,minY:t?h-_:h,maxX:g+p,maxY:t?h:h+_}}}},Bn=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}`}},Un="http://www.w3.org/2000/svg",Yn=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},Pi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Un}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},lt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Un),i=n.lookupNamespaceURI(null);return o||i?Yn(n).firstChild:Yn(Pi(n)).firstChild},Li=e=>{const t=Vn(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}}},Ii=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],l=o[0]-t[0],r=o[1]-t[1],a=i*r-s*l;return Math.abs(a)<.01},Ci=e=>{const t=Vn(e);let n=[],o=[0,0],i=!1;for(let l=0;l<t.length;l++){const r=t[l];switch(r.type.toUpperCase()){case"M":o=[r.args[0],r.args[1]],n.push({type:"CORNER",point:[...o]});break;case"L":o=[r.args[0],r.args[1]],n.push({type:"CORNER",point:[...o]});break;case"C":const a=[r.args[0],r.args[1]],u=[r.args[2],r.args[3]],d=[r.args[4],r.args[5]];if(n.length>0){const g=n[n.length-1];(a[0]!==g.point[0]||a[1]!==g.point[1])&&(g.type="CURVE",g.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: ${r.type}`);break}}n=n.map(l=>Ii(l)?{...l,locked:!0}:l);const s=fe(yt(n,i));return{points:n,closed:i,bounds:s}},Vn=e=>{const t=[],n=e.replace(/,/g," ").trim(),o=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let i;for(;(i=o.exec(n))!==null;){const[,s,l]=i,r=l.trim()===""?[]:l.trim().split(/\s+/).map(Number).filter(a=>!isNaN(a));t.push({type:s,args:r})}return t},Oi=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)}}},Di=e=>{const t=lt(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),l={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:l}}},Ni=e=>{const t=lt(e),n=parseFloat(t.getAttribute("x1")),o=parseFloat(t.getAttribute("x2")),i=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),l={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:l}}},Ri=e=>{const t=lt(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=Ci(o);if(!i)throw new Error("Could not parse SVG path");return{type:Q.POLYLINE,geometry:i}},Bi=e=>{const t=lt(e),n=t.nodeName==="rect"?t:Array.from(t.querySelectorAll("rect"))[0];if(!n)throw new Error("Could not parse SVG rect");const o=parseFloat(n.getAttribute("x")),i=parseFloat(n.getAttribute("y")),s=parseFloat(n.getAttribute("width")),l=parseFloat(n.getAttribute("height")),r=n.getAttribute("transform");let a=0;if(r&&r.startsWith("rotate(")){const p=r.match(/rotate\(([^)]+)\)/);p&&(a=p[1].split(/\s+/).map(parseFloat)[0]*Math.PI/180)}const u=o+s/2,d=i+l/2,g=[[o,i],[o+s,i],[o+s,i+l],[o,i+l]].map(([p,_])=>{const A=p-u,w=_-d,S=Math.cos(a),y=Math.sin(a);return[u+A*S-w*y,d+A*y+w*S]}),h=fe(g);return{type:Q.RECTANGLE,geometry:{x:o,y:i,w:s,h:l,rot:a,bounds:h}}},Ui=e=>{const t=lt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>Li(a)).filter(Boolean),s=i.reduce((a,u)=>[...a,...u.rings[0].points],[]),l=fe(s);return i.length===1&&i[0].rings.length===1?{type:Q.POLYGON,geometry:{points:s,bounds:l}}:{type:Q.MULTIPOLYGON,geometry:{polygons:i,bounds:l}}},Xn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Oi(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return Ri(t);if(t.includes("<path "))return Ui(t);if(t.includes("<ellipse "))return Di(t);if(t.includes("<line "))return Ni(t);if(t.includes("<rect "))return Bi(t);throw"Unsupported SVG shape: "+t},Yi=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Le(n)}" />`).join("")}</g>`,Hn=e=>{let t;switch(e.type){case Q.RECTANGLE:{const n=e.geometry,{x:o,y:i,w:s,h:l,rot:r}=n;if(!r)t=`<svg><rect x="${o}" y="${i}" width="${s}" height="${l}" /></svg>`;else{const a=o+s/2,u=i+l/2,d=(r??0)*180/Math.PI;t=`<svg><rect x="${o}" y="${i}" width="${s}" height="${l}" transform="rotate(${d} ${a} ${u})" /></svg>`}break}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>${Yi(n)}</svg>`;break}case Q.LINE:{const n=e.geometry,[[o,i],[s,l]]=n.points;t=`<svg><line x1="${o}" y1="${i}" x2="${s}" y2="${l}" /></svg>`;break}case Q.POLYLINE:t=`<svg><path d="${Ut(e.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},pe=[];for(let e=0;e<256;++e)pe.push((e+256).toString(16).slice(1));function Vi(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 Yt;const Xi=new Uint8Array(16);function Hi(){if(!Yt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Yt=crypto.getRandomValues.bind(crypto)}return Yt(Xi)}const Gn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Gi(e,t,n){var i;e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Hi();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,Vi(o)}function jn(e,t,n){return Gn.randomUUID&&!e?Gn.randomUUID():Gi(e)}var Fn=Object.prototype.hasOwnProperty;function Ne(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--&&Ne(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Fn.call(e,n)&&++o&&!Fn.call(t,n)||!(n in t)||!Ne(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}let Te=[],Re=0;const _t=4,Vt=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(o){return n.lc=t.push(o),()=>{for(let s=Re+_t;s<Te.length;)Te[s]===o?Te.splice(s,_t):s+=_t;let i=t.indexOf(o);~i&&(t.splice(i,1),--n.lc||n.off())}},notify(o,i){let s=!Te.length;for(let l of t)Te.push(l,n.value,o,i);if(s){for(Re=0;Re<Te.length;Re+=_t)Te[Re](Te[Re+1],Te[Re+2],Te[Re+3]);Te.length=0}},off(){},set(o){let i=n.value;i!==o&&(n.value=o,n.notify(i))},subscribe(o){let i=n.listen(o);return o(n.value),i},value:e};return n},ji=e=>{const t=Vt(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 Xt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Xt||{});const Ht={selected:[]},Fi=(e,t,n)=>{const o=Vt(Ht);let i=t;const s=()=>{Ne(o.get(),Ht)||o.set(Ht)},l=()=>{var h;return((h=o.get().selected)==null?void 0:h.length)===0},r=h=>{if(l())return!1;const p=typeof h=="string"?h:h.id;return o.get().selected.some(_=>_.id===p)},a=(h,p)=>{let _;if(Array.isArray(h)){if(_=h.map(w=>e.getAnnotation(w)).filter(Boolean),_.length<h.length){console.warn("Invalid selection: "+h.filter(w=>!_.some(S=>S.id===w)));return}}else{const w=e.getAnnotation(h);if(!w){console.warn("Invalid selection: "+h);return}_=[w]}const A=_.reduce((w,S)=>{const y=g(S);return y==="EDIT"?[...w,{id:S.id,editable:!0}]:y==="SELECT"?[...w,{id:S.id}]:w},[]);o.set({selected:A,event:p})},u=(h,p)=>{const _=Array.isArray(h)?h:[h],A=_.map(w=>e.getAnnotation(w)).filter(w=>!!w);o.set({selected:A.map(w=>{const S=p===void 0?g(w)==="EDIT":p;return{id:w.id,editable:S}})}),A.length!==_.length&&console.warn("Invalid selection",h)},d=h=>{if(l())return!1;const{selected:p}=o.get();p.some(({id:_})=>h.includes(_))&&o.set({selected:p.filter(({id:_})=>!h.includes(_))})},f=h=>{i=h,u(o.get().selected.map(({id:p})=>p))},g=h=>zi(h,i,n);return e.observe(({changes:h})=>d((h.deleted||[]).map(p=>p.id))),{get event(){const h=o.get();return h?h.event:null},get selected(){const h=o.get();return h?[...h.selected]:null},get userSelectAction(){return i},clear:s,evalSelectAction:g,isEmpty:l,isSelected:r,setSelected:u,setUserSelectAction:f,subscribe:o.subscribe.bind(o),userSelect:a}},zi=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},ye=[];for(let e=0;e<256;++e)ye.push((e+256).toString(16).slice(1));function qi(e,t=0){return(ye[e[t+0]]+ye[e[t+1]]+ye[e[t+2]]+ye[e[t+3]]+"-"+ye[e[t+4]]+ye[e[t+5]]+"-"+ye[e[t+6]]+ye[e[t+7]]+"-"+ye[e[t+8]]+ye[e[t+9]]+"-"+ye[e[t+10]]+ye[e[t+11]]+ye[e[t+12]]+ye[e[t+13]]+ye[e[t+14]]+ye[e[t+15]]).toLowerCase()}let Gt;const Ki=new Uint8Array(16);function Wi(){if(!Gt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Gt=crypto.getRandomValues.bind(crypto)}return Gt(Ki)}const Zi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),zn={randomUUID:Zi};function Ji(e,t,n){var o;e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Wi();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,qi(i)}function qn(e,t,n){return zn.randomUUID&&!e?zn.randomUUID():Ji(e)}const jt=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)}},Qi=(e,t,n,o)=>({id:qn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),$i=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},xi=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},es=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!Ne(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),ts=(e,t)=>!Ne(e.target,t.target),Kn=(e,t)=>{const n=$i(e,t),o=xi(e,t),i=es(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:ts(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var oe=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(oe||{});const ns=(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:l}=e.options,r=a=>a&&a.length>0;if(!(r(i.created)||r(i.deleted))){const a=(n=i.updated)==null?void 0:n.some(d=>r(d.bodiesCreated)||r(d.bodiesDeleted)||r(d.bodiesUpdated)),u=(o=i.updated)==null?void 0:o.some(d=>d.targetUpdated);if(l==="BODY_ONLY"&&a&&!u||l==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const l=new Set([...(i.created||[]).map(r=>r.id),...(i.deleted||[]).map(r=>r.id),...(i.updated||[]).map(({oldValue:r})=>r.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(r=>l.has(r))}else return!0},os=(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)),l=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),r=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=>l.has(f.id)?t.updated.find(({oldValue:g})=>g.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:g,newValue:h}=f;if(l.has(h.id)){const p=t.updated.find(_=>_.oldValue.id===h.id).newValue;return Kn(g,p)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!r.has(f.id))];return{created:a,deleted:u,updated:d}},wt=e=>{const t=e.id===void 0?qn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},is=e=>e.id!==void 0,ss=()=>{const e=new Map,t=new Map,n=[],o=(v,E={})=>{n.push({onChange:v,options:E})},i=v=>{const E=n.findIndex(m=>m.onChange==v);E>-1&&n.splice(E,1)},s=(v,E)=>{const m={origin:v,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...e.values()]};n.forEach(b=>{ns(b,m)&&b.onChange(m)})},l=(v,E=oe.LOCAL)=>{if(v.id&&e.get(v.id))throw Error(`Cannot add annotation ${v.id} - exists already`);{const m=wt(v);e.set(m.id,m),m.bodies.forEach(b=>t.set(b.id,m.id)),s(E,{created:[m]})}},r=(v,E)=>{const m=wt(typeof v=="string"?E:v),b=typeof v=="string"?v:v.id,I=b&&e.get(b);if(I){const k=Kn(I,m);return b===m.id?e.set(b,m):(e.delete(b),e.set(m.id,m)),I.bodies.forEach(O=>t.delete(O.id)),m.bodies.forEach(O=>t.set(O.id,m.id)),k}else console.warn(`Cannot update annotation ${b} - does not exist`)},a=(v,E=oe.LOCAL,m=oe.LOCAL)=>{const b=is(E)?m:E,I=r(v,E);I&&s(b,{updated:[I]})},u=(v,E=oe.LOCAL)=>{e.get(v.id)?a(v,E):l(v,E)},d=(v,E=oe.LOCAL)=>{const m=v.reduce((b,I)=>{const k=r(I);return k?[...b,k]:b},[]);m.length>0&&s(E,{updated:m})},f=(v,E=oe.LOCAL)=>{const m=v.map(wt),{toAdd:b,toUpdate:I}=m.reduce((O,z)=>e.get(z.id)?{...O,toUpdate:[...O.toUpdate,z]}:{...O,toAdd:[...O.toAdd,z]},{toAdd:[],toUpdate:[]}),k=I.map(O=>r(O,E)).filter(Boolean);b.forEach(O=>{e.set(O.id,O),O.bodies.forEach(z=>t.set(z.id,O.id))}),s(E,{created:b,updated:k})},g=(v,E=oe.LOCAL)=>{const m=e.get(v.annotation);if(m){const b={...m,bodies:[...m.bodies,v]};e.set(m.id,b),t.set(v.id,b.id),s(E,{updated:[{oldValue:m,newValue:b,bodiesCreated:[v]}]})}else console.warn(`Attempt to add body to missing annotation: ${v.annotation}`)},h=()=>[...e.values()],p=(v=oe.LOCAL)=>{const E=[...e.values()];e.clear(),t.clear(),s(v,{deleted:E})},_=(v,E=!0,m=oe.LOCAL)=>{const b=v.map(wt);if(E){const I=[...e.values()];e.clear(),t.clear(),b.forEach(k=>{e.set(k.id,k),k.bodies.forEach(O=>t.set(O.id,k.id))}),s(m,{created:b,deleted:I})}else{const I=v.reduce((k,O)=>{const z=O.id&&e.get(O.id);return z?[...k,z]:k},[]);if(I.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${I.map(k=>k.id).join(", ")}`);b.forEach(k=>{e.set(k.id,k),k.bodies.forEach(O=>t.set(O.id,k.id))}),s(m,{created:b})}},A=v=>{const E=typeof v=="string"?v:v.id,m=e.get(E);if(m)return e.delete(E),m.bodies.forEach(b=>t.delete(b.id)),m;console.warn(`Attempt to delete missing annotation: ${E}`)},w=(v,E=oe.LOCAL)=>{const m=A(v);m&&s(E,{deleted:[m]})},S=(v,E=oe.LOCAL)=>{const m=v.reduce((b,I)=>{const k=A(I);return k?[...b,k]:b},[]);m.length>0&&s(E,{deleted:m})},y=v=>{const E=e.get(v.annotation);if(E){const m=E.bodies.find(b=>b.id===v.id);if(m){t.delete(m.id);const b={...E,bodies:E.bodies.filter(I=>I.id!==v.id)};return e.set(E.id,b),{oldValue:E,newValue:b,bodiesDeleted:[m]}}else console.warn(`Attempt to delete missing body ${v.id} from annotation ${v.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${v.annotation}`)},M=(v,E=oe.LOCAL)=>{const m=y(v);m&&s(E,{updated:[m]})},L=(v,E=oe.LOCAL)=>{const m=v.map(b=>y(b)).filter(Boolean);m.length>0&&s(E,{updated:m})},C=v=>{const E=e.get(v);return E?{...E}:void 0},T=v=>{const E=t.get(v);if(E){const m=C(E).bodies.find(b=>b.id===v);if(m)return m;console.error(`Store integrity error: body ${v} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${v}`)},V=(v,E)=>{if(v.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const m=e.get(v.annotation);if(m){const b=m.bodies.find(k=>k.id===v.id),I={...m,bodies:m.bodies.map(k=>k.id===b.id?E:k)};return e.set(m.id,I),b.id!==E.id&&(t.delete(b.id),t.set(E.id,I.id)),{oldValue:m,newValue:I,bodiesUpdated:[{oldBody:b,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${v.annotation}`)},N=(v,E,m=oe.LOCAL)=>{const b=V(v,E);b&&s(m,{updated:[b]})},ee=(v,E=oe.LOCAL)=>{const m=v.map(b=>V({id:b.id,annotation:b.annotation},b)).filter(Boolean);s(E,{updated:m})},F=v=>{const E=e.get(v.annotation);if(E){const m={...E,target:{...E.target,...v}};return e.set(E.id,m),{oldValue:E,newValue:m,targetUpdated:{oldTarget:E.target,newTarget:v}}}else console.warn(`Attempt to update target on missing annotation: ${v.annotation}`)};return{addAnnotation:l,addBody:g,all:h,bulkAddAnnotations:_,bulkDeleteAnnotations:S,bulkDeleteBodies:L,bulkUpdateAnnotations:d,bulkUpdateBodies:ee,bulkUpdateTargets:(v,E=oe.LOCAL)=>{const m=v.map(b=>F(b)).filter(Boolean);m.length>0&&s(E,{updated:m})},bulkUpsertAnnotations:f,clear:p,deleteAnnotation:w,deleteBody:M,getAnnotation:C,getBody:T,observe:o,unobserve:i,updateAnnotation:a,updateBody:N,updateTarget:(v,E=oe.LOCAL)=>{const m=F(v);m&&s(E,{updated:[m]})},upsertAnnotation:u}};let rs=()=>({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 ls=250,as=(e,t)=>{const n=rs(),o=(t==null?void 0:t.changes)||[];let i=t?t.pointer:-1,s=!1,l=0;const r=p=>{if(!s){const{changes:_}=p,A=performance.now();if(A-l>ls)o.splice(i+1),o.push(_),i=o.length-1;else{const w=o.length-1;o[w]=os(o[w],_)}l=A}s=!1};e.observe(r,{origin:oe.LOCAL});const a=p=>p&&p.length>0&&e.bulkDeleteAnnotations(p),u=p=>p&&p.length>0&&e.bulkAddAnnotations(p,!1),d=p=>p&&p.length>0&&e.bulkUpdateAnnotations(p.map(({oldValue:_})=>_)),f=p=>p&&p.length>0&&e.bulkUpdateAnnotations(p.map(({newValue:_})=>_)),g=p=>p&&p.length>0&&e.bulkAddAnnotations(p,!1),h=p=>p&&p.length>0&&e.bulkDeleteAnnotations(p);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(r),getHistory:()=>({changes:[...o],pointer:i}),on:(p,_)=>n.on(p,_),redo:()=>{if(o.length-1>i){s=!0;const{created:p,updated:_,deleted:A}=o[i+1];u(p),f(_),h(A),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:p,updated:_,deleted:A}=o[i];a(p),d(_),g(A),n.emit("undo",o[i]),i-=1}}}},cs=()=>{const e=Vt([]);return{subscribe:e.subscribe.bind(e),set:e.set.bind(e)}},us=(e,t,n,o)=>{const{hover:i,selection:s,store:l,viewport:r}=e,a=new Map;let u=[],d,f;const g=(w,S)=>{a.has(w)?a.get(w).push(S):a.set(w,[S])},h=(w,S)=>{const y=a.get(w);if(y){const M=y.indexOf(S);M!==-1&&y.splice(M,1)}},p=(w,S,y)=>{a.has(w)&&setTimeout(()=>{a.get(w).forEach(M=>{if(n){const L=Array.isArray(S)?S.map(T=>n.serialize(T)):n.serialize(S),C=y?y instanceof PointerEvent?y:n.serialize(y):void 0;M(L,C)}else M(S,y)})},1)},_=()=>{const{selected:w}=s,S=(w||[]).map(({id:y})=>l.getAnnotation(y));S.forEach(y=>{const M=u.find(L=>L.id===y.id);(!M||!Ne(M,y))&&p("updateAnnotation",y,M)}),u=u.map(y=>S.find(({id:L})=>L===y.id)||y)};s.subscribe(({selected:w})=>{if(!(u.length===0&&w.length===0)){if(u.length===0&&w.length>0)u=w.map(({id:S})=>l.getAnnotation(S));else if(u.length>0&&w.length===0)u.forEach(S=>{const y=l.getAnnotation(S.id);y&&!Ne(y,S)&&p("updateAnnotation",y,S)}),u=[];else{const S=new Set(u.map(M=>M.id)),y=new Set(w.map(({id:M})=>M));u.filter(M=>!y.has(M.id)).forEach(M=>{const L=l.getAnnotation(M.id);L&&!Ne(L,M)&&p("updateAnnotation",L,M)}),u=[...u.filter(M=>y.has(M.id)),...w.filter(({id:M})=>!S.has(M)).map(({id:M})=>l.getAnnotation(M))]}p("selectionChanged",u)}}),i.subscribe(w=>{!d&&w?p("mouseEnterAnnotation",l.getAnnotation(w)):d&&!w?p("mouseLeaveAnnotation",l.getAnnotation(d)):d&&w&&(p("mouseLeaveAnnotation",l.getAnnotation(d)),p("mouseEnterAnnotation",l.getAnnotation(w))),d=w}),r==null||r.subscribe(w=>p("viewportIntersect",w.map(S=>l.getAnnotation(S)))),l.observe(w=>{o&&(f&&clearTimeout(f),f=setTimeout(_,1e3));const{created:S,deleted:y}=w.changes;(S||[]).forEach(M=>p("createAnnotation",M)),(y||[]).forEach(M=>p("deleteAnnotation",M)),(w.changes.updated||[]).filter(M=>[...M.bodiesCreated||[],...M.bodiesDeleted||[],...M.bodiesUpdated||[]].length>0).forEach(({oldValue:M,newValue:L})=>{const C=u.find(T=>T.id===M.id)||M;u=u.map(T=>T.id===M.id?L:T),p("updateAnnotation",L,C)})},{origin:oe.LOCAL}),l.observe(w=>{if(u){const S=new Set(u.map(M=>M.id)),y=(w.changes.updated||[]).filter(({newValue:M})=>S.has(M.id)).map(({newValue:M})=>M);y.length>0&&(u=u.map(M=>y.find(C=>C.id===M.id)||M))}},{origin:oe.REMOTE});const A=w=>S=>{const{updated:y}=S;w?(y||[]).forEach(M=>p("updateAnnotation",M.oldValue,M.newValue)):(y||[]).forEach(M=>p("updateAnnotation",M.newValue,M.oldValue))};return t.on("undo",A(!0)),t.on("redo",A(!1)),{on:g,off:h,emit:p}},fs=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:[]}),ds=(e,t,n)=>{const{store:o,selection:i}=e,s=w=>{if(n){const{parsed:S,error:y}=n.parse(w);S?o.addAnnotation(S,oe.REMOTE):console.error(y)}else o.addAnnotation(jt(w),oe.REMOTE)},l=()=>i.clear(),r=()=>o.clear(),a=w=>{const S=o.getAnnotation(w);return n&&S?n.serialize(S):S},u=()=>n?o.all().map(n.serialize):o.all(),d=()=>{var w;const S=(((w=i.selected)==null?void 0:w.map(y=>y.id))||[]).map(y=>o.getAnnotation(y)).filter(Boolean);return n?S.map(n.serialize):S},f=(w,S=!0)=>fetch(w).then(y=>y.json()).then(y=>(h(y,S),y)),g=w=>{if(typeof w=="string"){const S=o.getAnnotation(w);if(o.deleteAnnotation(w),S)return n?n.serialize(S):S}else{const S=n?n.parse(w).parsed:w;if(S)return o.deleteAnnotation(S),w}},h=(w,S=!0)=>{if(n){const y=n.parseAll||fs(n),{parsed:M,failed:L}=y(w);L.length>0&&console.warn(`Discarded ${L.length} invalid annotations`,L),o.bulkAddAnnotations(M,S,oe.REMOTE)}else o.bulkAddAnnotations(w.map(jt),S,oe.REMOTE)},p=(w,S)=>{w?i.setSelected(w,S):i.clear()},_=w=>{i.setUserSelectAction(w)},A=w=>{if(n){const S=n.parse(w).parsed,y=n.serialize(o.getAnnotation(S.id));return o.updateAnnotation(S),y}else{const S=o.getAnnotation(w.id);return o.updateAnnotation(jt(w)),S}};return{addAnnotation:s,cancelSelected:l,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:r,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:d,loadAnnotations:f,redo:t.redo,removeAnnotation:g,setAnnotations:h,setSelected:p,setUserSelectAction:_,undo:t.undo,updateAnnotation:A}},gs=(e,t,n)=>typeof t=="function"?t(e,n):t,hs=(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||{}}};let ms="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",ps=e=>crypto.getRandomValues(new Uint8Array(e)),ys=(e,t,n)=>{let o=(2<<Math.log2(e.length-1))-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let l="";for(;;){let r=n(i),a=i|0;for(;a--;)if(l+=e[r[a]&o]||"",l.length>=s)return l}}},_s=(e,t=21)=>ys(e,t|0,ps),ws=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=ms[n[e]&63];return t};const bs=()=>({isGuest:!0,id:_s("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Es=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}`},Wn=e=>e?typeof e=="object"?{...e}:e:void 0,vs=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:l,created:r,modified:a,creator:u,...d}=n;return{id:o||`temp-${Es(n)}`,annotation:t,type:i,purpose:s,value:l,creator:Wn(u),created:r?new Date(r):void 0,updated:a?new Date(a):void 0,...d}}),Ss=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...l}=t,r={...l,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=r.id)!=null&&n.startsWith("temp-")&&delete r.id,r}),As=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Ms=()=>{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)}};ws();const ks=(e,t={strict:!0,invertY:!1})=>({parse:i=>Zn(i,t),serialize:i=>Jn(i,e,t)}),Zn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||jn(),{creator:o,created:i,modified:s,body:l,...r}=e,a=vs(l||[],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=Nn(d)?Rn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?Xn(d):void 0,g=Array.isArray(r.target)?r.target[0]:r.targret;return f||!t.strict?{parsed:{...r,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Wn(o),updated:s?new Date(s):void 0,...typeof g=="string"?{}:g,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Jn=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:s,updated:l,updatedBy:r,...a}=e.target;let u;try{o.type===Q.RECTANGLE&&!o.geometry.rot?u=Bn(o.geometry):u=Hn(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:Ss(e.bodies),created:s==null?void 0:s.toISOString(),creator:i,modified:l==null?void 0:l.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete d.bodies,typeof d.target!="string"&&"annotation"in d.target&&delete d.target.annotation,d},Je=[];function Ts(e,t=q){let n;const o=new Set;function i(r){if(re(e,r)&&(e=r,n)){const a=!Je.length;for(const u of o)u[1](),Je.push(u,e);if(a){for(let u=0;u<Je.length;u+=2)Je[u][0](Je[u+1]);Je.length=0}}}function s(r){i(r(e))}function l(r,a=q){const u=[r,a];return o.add(u),o.size===1&&(n=t(i,s)||q),r(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:l}}const Ps=(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",l=>{const r=l.target;t.setAttribute("viewBox",`0 0 ${r.naturalWidth} ${r.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},Qn=(e,t)=>{Ps(e,t);const{subscribe:n,set:o}=Ts(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const l=t.getBoundingClientRect(),{width:r,height:a}=t.viewBox.baseVal,u=Math.max(l.width/r,l.height/a);o(u)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},Fe=(e,t,n)=>{const o=typeof t=="function"?t(e,n):t;if(o){const{fill:i,fillOpacity:s,stroke:l,strokeWidth:r,strokeOpacity:a}=o;let u="";return i&&(u+=`fill:${i};`),s||s===0?u+=`fill-opacity:${s};`:i&&(u+="fill-opacity:0.25;"),l&&(u+=`stroke:${l};`,u+=`stroke-width:${r||"1"};`,u+=`stroke-opacity:${a||"1"};`),u}},at=(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,Ls=e=>({}),$n=e=>({grab:e[0]});function Is(e){let t,n,o,i;const s=e[8].default,l=li(s,e,e[7],$n);return{c(){t=P("g"),l&&l.c(),c(t,"class","a9s-annotation selected")},m(r,a){U(r,t,a),l&&l.m(t,null),n=!0,o||(i=[x(t,"pointerup",e[2]),x(t,"pointermove",e[1])],o=!0)},p(r,[a]){l&&l.p&&(!n||a&128)&&ci(l,s,r,r[7],n?ai(s,r[7],a,Ls):ui(r[7]),$n)},i(r){n||(Y(l,r),n=!0)},o(r){G(l,r),n=!1},d(r){r&&B(t),l&&l.d(r),o=!1,Ae(i)}}}function Cs(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=De();let{shape:l}=t,{editor:r}=t,{transform:a}=t,{svgEl:u}=t,d,f,g;const h=A=>w=>{if(d=A,u){const{left:y,top:M}=u.getBoundingClientRect(),L=w.clientX-y,C=w.clientY-M;f=a.elementToImage(L,C)}else{const{offsetX:y,offsetY:M}=w;f=a.elementToImage(y,M)}g=l,w.target.setPointerCapture(w.pointerId),s("grab",w)},p=A=>{if(d){const[w,S]=a.elementToImage(A.offsetX,A.offsetY),y=[w-f[0],S-f[1]];n(3,l=r(g,d,y)),s("change",l)}},_=A=>{A.target.releasePointerCapture(A.pointerId),d=void 0,g=l,s("release",A)};return e.$$set=A=>{"shape"in A&&n(3,l=A.shape),"editor"in A&&n(4,r=A.editor),"transform"in A&&n(5,a=A.transform),"svgEl"in A&&n(6,u=A.svgEl),"$$scope"in A&&n(7,i=A.$$scope)},[h,p,_,l,r,a,u,i,o]}class bt extends me{constructor(t){super(),he(this,t,Cs,Is,re,{shape:3,editor:4,transform:5,svgEl:6})}}function Os(e){let t,n,o,i,s,l,r,a,u=e[3]&&xn(e);return{c(){t=P("g"),n=P("circle"),u&&u.c(),i=P("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=qe(`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",l=`a9s-handle ${e[8].class||""}`.trim())},m(d,f){U(d,t,f),j(t,n),u&&u.m(t,null),j(t,i),r||(a=[x(n,"dblclick",e[12]),x(n,"pointerenter",e[13]),x(n,"pointerleave",e[14]),x(n,"pointerdown",e[15]),x(n,"pointerdown",e[6]),x(n,"pointerup",e[16]),x(n,"pointerup",e[7])],r=!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=xn(d),u.c(),u.m(t,i)):u&&(u.d(1),u=null),f&8&&s!==(s=qe(`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&&l!==(l=`a9s-handle ${d[8].class||""}`.trim())&&c(t,"class",l)},d(d){d&&B(t),u&&u.d(),r=!1,Ae(a)}}}function Ds(e){let t,n,o,i,s,l,r,a,u;return{c(){t=P("g"),n=P("circle"),i=P("circle"),l=P("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(l,"class","a9s-handle-dot"),c(l,"cx",e[0]),c(l,"cy",e[1]),c(l,"r",r=e[5]+2/e[2]),c(t,"class","a9s-touch-handle")},m(d,f){U(d,t,f),j(t,n),j(t,i),j(t,l),a||(u=[x(i,"dblclick",e[9]),x(i,"pointerdown",e[10]),x(i,"pointerdown",e[6]),x(i,"pointerup",e[11]),x(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(l,"cx",d[0]),f&2&&c(l,"cy",d[1]),f&36&&r!==(r=d[5]+2/d[2])&&c(l,"r",r)},d(d){d&&B(t),a=!1,Ae(u)}}}function xn(e){let t,n;return{c(){t=P("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){U(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 Ns(e){let t;function n(s,l){return Ie?Ds:Os}let i=n()(e);return{c(){i.c(),t=Me()},m(s,l){i.m(s,l),U(s,t,l)},p(s,[l]){i.p(s,l)},i:q,o:q,d(s){s&&B(t),i.d(s)}}}function Rs(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:l}=t,{selected:r=void 0}=t,a=!1;const u=y=>{y.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function f(y){ge.call(this,e,y)}function g(y){ge.call(this,e,y)}function h(y){ge.call(this,e,y)}function p(y){ge.call(this,e,y)}function _(y){ge.call(this,e,y)}function A(y){ge.call(this,e,y)}function w(y){ge.call(this,e,y)}function S(y){ge.call(this,e,y)}return e.$$set=y=>{n(8,t=Ce(Ce({},t),wn(y))),"x"in y&&n(0,i=y.x),"y"in y&&n(1,s=y.y),"scale"in y&&n(2,l=y.scale),"selected"in y&&n(3,r=y.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=4/l)},t=wn(t),[i,s,l,r,a,o,u,d,t,f,g,h,p,_,A,w,S]}class Be extends me{constructor(t){super(),he(this,t,Rs,Ns,re,{x:0,y:1,scale:2,selected:3})}}function Bs(e){let t,n,o,i,s,l,r;return{c(){t=P("g"),n=P("circle"),i=P("circle"),s=P("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){U(a,t,u),j(t,n),j(t,i),j(t,s),l||(r=[x(n,"pointerdown",e[5]),x(n,"pointerdown",e[3])],l=!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),l=!1,Ae(r)}}}function Us(e){let t;return{c(){t=P("circle"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",e[2])},m(n,o){U(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 Ys(e){let t;function n(s,l){return Ie?Us:Bs}let i=n()(e);return{c(){i.c(),t=Me()},m(s,l){i.m(s,l),U(s,t,l)},p(s,[l]){i.p(s,l)},i:q,o:q,d(s){s&&B(t),i.d(s)}}}function Vs(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:l}=t;const r=u=>{u.pointerType};function a(u){ge.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,l=u.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,o=4/l)},[i,s,o,r,l,a]}class Ft extends me{constructor(t){super(),he(this,t,Vs,Ys,re,{x:0,y:1,scale:4})}}function zt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function eo(e,t,n){const o=e.slice();return o[28]=t[n],o[30]=n,o}function qt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Kt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function to(e){let t,n,o,i;return{c(){t=P("circle"),c(t,"cx",n=e[28][0]),c(t,"cy",o=e[28][1]),c(t,"r",i=ct/e[3]),c(t,"class","svelte-1h2slbm")},m(s,l){U(s,t,l)},p(s,l){l[0]&1088&&n!==(n=s[28][0])&&c(t,"cx",n),l[0]&1088&&o!==(o=s[28][1])&&c(t,"cy",o),l[0]&8&&i!==(i=ct/s[3])&&c(t,"r",i)},d(s){s&&B(t)}}}function no(e){let t,n,o,i,s,l,r,a,u,d;return{c(){t=P("mask"),n=P("rect"),r=P("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",l=e[9].h),c(n,"class","svelte-1h2slbm"),c(r,"cx",a=e[28][0]),c(r,"cy",u=e[28][1]),c(r,"r",d=ct/e[3]),c(r,"class","svelte-1h2slbm"),c(t,"id",`${e[19]}-inner`),c(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(f,g){U(f,t,g),j(t,n),j(t,r)},p(f,g){g[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),g[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),g[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),g[0]&512&&l!==(l=f[9].h)&&c(n,"height",l),g[0]&1088&&a!==(a=f[28][0])&&c(r,"cx",a),g[0]&1088&&u!==(u=f[28][1])&&c(r,"cy",u),g[0]&8&&d!==(d=ct/f[3])&&c(r,"r",d)},d(f){f&&B(t)}}}function oo(e){let t,n;return t=new Be({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(){se(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function io(e){let t,n;return t=new Ft({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){se(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Xs(e){let t,n,o,i,s,l,r,a,u,d,f,g,h,p,_,A,w,S,y,M,L,C=e[6]!==void 0&&!e[7]&&to(Kt(e)),T=e[6]!==void 0&&!e[7]&&no(qt(e)),V=Se(e[5].points),N=[];for(let v=0;v<V.length;v+=1)N[v]=oo(eo(e,V,v));const ee=v=>G(N[v],1,1,()=>{N[v]=null});let F=e[6]!==void 0&&!e[7]&&io(zt(e));return{c(){t=P("defs"),n=P("mask"),o=P("rect"),a=P("polygon"),C&&C.c(),T&&T.c(),d=be(),f=P("polygon"),h=be(),p=P("polygon"),A=be();for(let v=0;v<N.length;v+=1)N[v].c();w=be(),F&&F.c(),S=Me(),c(o,"x",i=e[9].x),c(o,"y",s=e[9].y),c(o,"width",l=e[9].w),c(o,"height",r=e[9].h),c(o,"class","svelte-1h2slbm"),c(a,"points",u=e[5].points.map(so).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",g=e[5].points.map(ro).join(" ")),c(p,"class","a9s-inner a9s-shape-handle"),c(p,"mask",`url(#${e[19]}-inner)`),c(p,"style",e[1]),c(p,"points",_=e[5].points.map(lo).join(" "))},m(v,E){U(v,t,E),j(t,n),j(n,o),j(n,a),C&&C.m(n,null),T&&T.m(t,null),U(v,d,E),U(v,f,E),U(v,h,E),U(v,p,E),U(v,A,E);for(let m=0;m<N.length;m+=1)N[m]&&N[m].m(v,E);U(v,w,E),F&&F.m(v,E),U(v,S,E),y=!0,M||(L=[x(f,"pointerup",e[14]),x(f,"pointerdown",function(){se(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),x(p,"pointermove",e[13]),x(p,"pointerup",e[14]),x(p,"pointerdown",function(){se(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],M=!0)},p(v,E){if(e=v,(!y||E[0]&512&&i!==(i=e[9].x))&&c(o,"x",i),(!y||E[0]&512&&s!==(s=e[9].y))&&c(o,"y",s),(!y||E[0]&512&&l!==(l=e[9].w))&&c(o,"width",l),(!y||E[0]&512&&r!==(r=e[9].h))&&c(o,"height",r),(!y||E[0]&32&&u!==(u=e[5].points.map(so).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Kt(e),E):(C=to(Kt(e)),C.c(),C.m(n,null)):C&&(C.d(1),C=null),e[6]!==void 0&&!e[7]?T?T.p(qt(e),E):(T=no(qt(e)),T.c(),T.m(t,null)):T&&(T.d(1),T=null),(!y||E[0]&32&&g!==(g=e[5].points.map(ro).join(" ")))&&c(f,"points",g),(!y||E[0]&2)&&c(p,"style",e[1]),(!y||E[0]&32&&_!==(_=e[5].points.map(lo).join(" ")))&&c(p,"points",_),E[0]&134322472){V=Se(e[5].points);let m;for(m=0;m<V.length;m+=1){const b=eo(e,V,m);N[m]?(N[m].p(b,E),Y(N[m],1)):(N[m]=oo(b),N[m].c(),Y(N[m],1),N[m].m(w.parentNode,w))}for(Ee(),m=V.length;m<N.length;m+=1)ee(m);ve()}e[6]!==void 0&&!e[7]?F?(F.p(zt(e),E),E[0]&192&&Y(F,1)):(F=io(zt(e)),F.c(),Y(F,1),F.m(S.parentNode,S)):F&&(Ee(),G(F,1,1,()=>{F=null}),ve())},i(v){if(!y){for(let E=0;E<V.length;E+=1)Y(N[E]);Y(F),y=!0}},o(v){N=N.filter(Boolean);for(let E=0;E<N.length;E+=1)G(N[E]);G(F),y=!1},d(v){v&&(B(t),B(d),B(f),B(h),B(p),B(A),B(w),B(S)),C&&C.d(),T&&T.d(),He(N,v),F&&F.d(v),M=!1,Ae(L)}}}function Hs(e){let t,n;return t=new bt({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[Xs,({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(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Gs=250,js=1e3,Fs=12,ct=4.5,so=e=>e.join(","),ro=e=>e.join(","),lo=e=>e.join(",");function zs(e,t,n){let o,i,s;const l=De();let{shape:r}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,g,h=!1,p,_=[];const A=()=>n(7,h=!0),w=()=>n(7,h=!1),S=m=>{if(_.length>0||!i.some(W=>W.visible)){n(6,g=void 0);return}const[b,I]=u.elementToImage(m.offsetX,m.offsetY),k=W=>Math.pow(W[0]-b,2)+Math.pow(W[1]-I,2),O=o.points.reduce((W,Z)=>k(Z)<k(W)?Z:W),z=i.filter(W=>W.visible).reduce((W,Z)=>k(Z.point)<k(W.point)?Z:W),X=Math.pow(js/d,2);k(O)<X||k(z.point)<X?n(6,g=i.indexOf(z)):n(6,g=void 0)},y=()=>{document.activeElement!==f&&f.focus()},M=()=>{n(8,_=[]),y()},L=m=>{n(7,h=!0),m.preventDefault(),m.stopPropagation(),p=performance.now()},C=m=>b=>{if(!p||Ie||performance.now()-p>Gs)return;const I=_.includes(m);b.metaKey||b.ctrlKey||b.shiftKey?I?n(8,_=_.filter(k=>k!==m)):n(8,_=[..._,m]):I&&_.length>1?n(8,_=[m]):I?n(8,_=[]):n(8,_=[m]),y()},T=(m,b,I)=>{y();let k;const O=m.geometry;_.length>1?k=O.points.map(([X,$],W)=>_.includes(W)?[X+I[0],$+I[1]]:[X,$]):b==="SHAPE"?k=O.points.map(([X,$])=>[X+I[0],$+I[1]]):k=O.points.map(([X,$],W)=>b===`HANDLE-${W}`?[X+I[0],$+I[1]]:[X,$]);const z=fe(k);return{...m,geometry:{points:k,bounds:z}}},V=m=>async b=>{b.stopPropagation();const I=[...o.points.slice(0,m+1),i[m].point,...o.points.slice(m+1)],k=fe(I);l("change",{...r,geometry:{points:I,bounds:k}}),await Mn();const O=[...document.querySelectorAll(".a9s-handle")][m+1];if(O!=null&&O.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});O.firstChild.dispatchEvent(z)}},N=()=>{if(o.points.length-_.length<3)return;const m=o.points.filter((I,k)=>!_.includes(k)),b=fe(m);l("change",{...r,geometry:{points:m,bounds:b}}),n(8,_=[])};Oe(()=>{if(Ie)return;const m=b=>{(b.key==="Delete"||b.key==="Backspace")&&(b.preventDefault(),N())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",m),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",m)}});const ee=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function F(m){ge.call(this,e,m)}function v(m){ge.call(this,e,m)}function E(m){ge.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,r=m.shape),"computedStyle"in m&&n(1,a=m.computedStyle),"transform"in m&&n(2,u=m.transform),"viewportScale"in m&&n(3,d=m.viewportScale),"svgEl"in m&&n(4,f=m.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=r.geometry),e.$$.dirty[0]&40&&n(10,i=Ie?[]:o.points.map((m,b)=>{const I=b===o.points.length-1?o.points[0]:o.points[b+1],k=(m[0]+I[0])/2,O=(m[1]+I[1])/2,X=Math.sqrt(Math.pow(I[0]-k,2)+Math.pow(I[1]-O,2))>Fs/d;return{point:[k,O],visible:X}})),e.$$.dirty[0]&40&&n(9,s=at(o.bounds,ct/d))},[r,a,u,d,f,o,g,h,_,s,i,A,w,S,M,L,C,T,V,ee,F,v,E]}class ao extends me{constructor(t){super(),he(this,t,zs,Hs,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const co=(e,t,n)=>{const[o,i]=e,[s,l]=t,r=Math.cos(n),a=Math.sin(n),u=o-s,d=i-l;return[s+u*r-d*a,l+u*a+d*r]},qs=(e,t,n,o,i=0)=>{const s=[[e,t],[e+n,t],[e+n,t+o],[e,t+o]],l=[e+n/2,t+o/2];return s.map(r=>co(r,l,i))},uo=(e,t)=>{const{x:n,y:o,w:i,h:s,rot:l=0}=e,r=[n+i/2,o+s/2];let a=[n+i/2,o-t];return co(a,r,l)},Ks=(e,t,n)=>{const o=Math.cos(n),i=Math.sin(n);return[e*o+t*i,-e*i+t*o]},Ws=(e,t,n)=>{const o=e[0]-n[0],i=e[1]-n[1],s=Math.atan2(i,o),l=t[0]-n[0],r=t[1]-n[1];return Math.atan2(r,l)-s},Zs=(e,t=10)=>{const n=t*Math.PI/180;return Math.round(e/n)*n};function Js(e){let t,n,o,i,s,l,r,a,u,d,f,g,h,p,_,A,w,S,y,M,L,C,T,V,N,ee,F,v,E,m,b,I,k,O,z,X,$,W,Z,te,_e,ie,ke,H,de,ne,we,ce,ze,St,At,Mt,cn,Ue,un,Ye,fn,Ve,dn,Xe,J,gn,si;return C=new Be({props:{class:"a9s-rotation-handle",x:e[7][0],y:e[7][1],scale:e[3]}}),C.$on("pointerdown",function(){se(e[16]("ROTATION"))&&e[16]("ROTATION").apply(this,arguments)}),Ue=new Be({props:{class:"a9s-corner-handle-topleft",x:e[6][0][0],y:e[6][0][1],scale:e[3]}}),Ue.$on("pointerdown",function(){se(e[16]("TOP_LEFT"))&&e[16]("TOP_LEFT").apply(this,arguments)}),Ye=new Be({props:{class:"a9s-corner-handle-topright",x:e[6][1][0],y:e[6][1][1],scale:e[3]}}),Ye.$on("pointerdown",function(){se(e[16]("TOP_RIGHT"))&&e[16]("TOP_RIGHT").apply(this,arguments)}),Ve=new Be({props:{class:"a9s-corner-handle-bottomright",x:e[6][2][0],y:e[6][2][1],scale:e[3]}}),Ve.$on("pointerdown",function(){se(e[16]("BOTTOM_RIGHT"))&&e[16]("BOTTOM_RIGHT").apply(this,arguments)}),Xe=new Be({props:{class:"a9s-corner-handle-bottomleft",x:e[6][3][0],y:e[6][3][1],scale:e[3]}}),Xe.$on("pointerdown",function(){se(e[16]("BOTTOM_LEFT"))&&e[16]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=P("defs"),n=P("mask"),o=P("rect"),a=P("polygon"),d=be(),f=P("g"),g=P("line"),w=P("line"),ue(C.$$.fragment),T=be(),V=P("g"),N=P("polygon"),F=P("polygon"),E=be(),m=P("line"),z=be(),X=P("line"),_e=be(),ie=P("line"),we=be(),ce=P("line"),cn=be(),ue(Ue.$$.fragment),un=be(),ue(Ye.$$.fragment),fn=be(),ue(Ve.$$.fragment),dn=be(),ue(Xe.$$.fragment),c(o,"class","rect-mask-bg svelte-1bwhzbc"),c(o,"x",i=e[5].x),c(o,"y",s=e[5].y),c(o,"width",l=e[5].w),c(o,"height",r=e[5].h),c(a,"class","rect-mask-fg svelte-1bwhzbc"),c(a,"points",u=e[6].map(fo).join(" ")),c(n,"id",e[9]),c(n,"class","a9s-rectangle-editor-mask svelte-1bwhzbc"),c(g,"class","a9s-rotation-handle-line-bg"),c(g,"x1",h=e[6][0][0]+(e[6][1][0]-e[6][0][0])/2),c(g,"y1",p=e[6][0][1]+(e[6][1][1]-e[6][0][1])/2),c(g,"x2",_=e[7][0]),c(g,"y2",A=e[7][1]),c(g,"pointer-events","none"),c(w,"class","a9s-rotation-handle-line-fg"),c(w,"x1",S=e[6][0][0]+(e[6][1][0]-e[6][0][0])/2),c(w,"y1",y=e[6][0][1]+(e[6][1][1]-e[6][0][1])/2),c(w,"x2",M=e[7][0]),c(w,"y2",L=e[7][1]),c(w,"pointer-events","none"),c(N,"class","a9s-outer"),c(N,"mask",`url(#${e[9]})`),c(N,"points",ee=e[6].map(go).join(" ")),c(F,"class","a9s-inner a9s-shape-handle"),c(F,"style",e[1]),c(F,"points",v=e[6].map(ho).join(" ")),c(m,"class","a9s-edge-handle a9s-edge-handle-top"),c(m,"x1",b=e[6][0][0]),c(m,"y1",I=e[6][0][1]),c(m,"x2",k=e[6][1][0]),c(m,"y2",O=e[6][1][1]),c(X,"class","a9s-edge-handle a9s-edge-handle-right"),c(X,"x1",$=e[6][1][0]),c(X,"y1",W=e[6][1][1]),c(X,"x2",Z=e[6][2][0]),c(X,"y2",te=e[6][2][1]),c(ie,"class","a9s-edge-handle a9s-edge-handle-bottom"),c(ie,"x1",ke=e[6][2][0]),c(ie,"y1",H=e[6][2][1]),c(ie,"x2",de=e[6][3][0]),c(ie,"y2",ne=e[6][3][1]),c(ce,"class","a9s-edge-handle a9s-edge-handle-left"),c(ce,"x1",ze=e[6][3][0]),c(ce,"y1",St=e[6][3][1]),c(ce,"x2",At=e[6][0][0]),c(ce,"y2",Mt=e[6][0][1])},m(K,R){U(K,t,R),j(t,n),j(n,o),j(n,a),U(K,d,R),U(K,f,R),j(f,g),j(f,w),le(C,f,null),U(K,T,R),U(K,V,R),j(V,N),j(V,F),U(K,E,R),U(K,m,R),U(K,z,R),U(K,X,R),U(K,_e,R),U(K,ie,R),U(K,we,R),U(K,ce,R),U(K,cn,R),le(Ue,K,R),U(K,un,R),le(Ye,K,R),U(K,fn,R),le(Ve,K,R),U(K,dn,R),le(Xe,K,R),J=!0,gn||(si=[x(N,"pointerdown",function(){se(e[16]("SHAPE"))&&e[16]("SHAPE").apply(this,arguments)}),x(F,"pointerdown",function(){se(e[16]("SHAPE"))&&e[16]("SHAPE").apply(this,arguments)}),x(m,"pointerdown",function(){se(e[16]("TOP"))&&e[16]("TOP").apply(this,arguments)}),x(X,"pointerdown",function(){se(e[16]("RIGHT"))&&e[16]("RIGHT").apply(this,arguments)}),x(ie,"pointerdown",function(){se(e[16]("BOTTOM"))&&e[16]("BOTTOM").apply(this,arguments)}),x(ce,"pointerdown",function(){se(e[16]("LEFT"))&&e[16]("LEFT").apply(this,arguments)})],gn=!0)},p(K,R){e=K,(!J||R&32&&i!==(i=e[5].x))&&c(o,"x",i),(!J||R&32&&s!==(s=e[5].y))&&c(o,"y",s),(!J||R&32&&l!==(l=e[5].w))&&c(o,"width",l),(!J||R&32&&r!==(r=e[5].h))&&c(o,"height",r),(!J||R&64&&u!==(u=e[6].map(fo).join(" ")))&&c(a,"points",u),(!J||R&64&&h!==(h=e[6][0][0]+(e[6][1][0]-e[6][0][0])/2))&&c(g,"x1",h),(!J||R&64&&p!==(p=e[6][0][1]+(e[6][1][1]-e[6][0][1])/2))&&c(g,"y1",p),(!J||R&128&&_!==(_=e[7][0]))&&c(g,"x2",_),(!J||R&128&&A!==(A=e[7][1]))&&c(g,"y2",A),(!J||R&64&&S!==(S=e[6][0][0]+(e[6][1][0]-e[6][0][0])/2))&&c(w,"x1",S),(!J||R&64&&y!==(y=e[6][0][1]+(e[6][1][1]-e[6][0][1])/2))&&c(w,"y1",y),(!J||R&128&&M!==(M=e[7][0]))&&c(w,"x2",M),(!J||R&128&&L!==(L=e[7][1]))&&c(w,"y2",L);const kt={};R&128&&(kt.x=e[7][0]),R&128&&(kt.y=e[7][1]),R&8&&(kt.scale=e[3]),C.$set(kt),(!J||R&64&&ee!==(ee=e[6].map(go).join(" ")))&&c(N,"points",ee),(!J||R&2)&&c(F,"style",e[1]),(!J||R&64&&v!==(v=e[6].map(ho).join(" ")))&&c(F,"points",v),(!J||R&64&&b!==(b=e[6][0][0]))&&c(m,"x1",b),(!J||R&64&&I!==(I=e[6][0][1]))&&c(m,"y1",I),(!J||R&64&&k!==(k=e[6][1][0]))&&c(m,"x2",k),(!J||R&64&&O!==(O=e[6][1][1]))&&c(m,"y2",O),(!J||R&64&&$!==($=e[6][1][0]))&&c(X,"x1",$),(!J||R&64&&W!==(W=e[6][1][1]))&&c(X,"y1",W),(!J||R&64&&Z!==(Z=e[6][2][0]))&&c(X,"x2",Z),(!J||R&64&&te!==(te=e[6][2][1]))&&c(X,"y2",te),(!J||R&64&&ke!==(ke=e[6][2][0]))&&c(ie,"x1",ke),(!J||R&64&&H!==(H=e[6][2][1]))&&c(ie,"y1",H),(!J||R&64&&de!==(de=e[6][3][0]))&&c(ie,"x2",de),(!J||R&64&&ne!==(ne=e[6][3][1]))&&c(ie,"y2",ne),(!J||R&64&&ze!==(ze=e[6][3][0]))&&c(ce,"x1",ze),(!J||R&64&&St!==(St=e[6][3][1]))&&c(ce,"y1",St),(!J||R&64&&At!==(At=e[6][0][0]))&&c(ce,"x2",At),(!J||R&64&&Mt!==(Mt=e[6][0][1]))&&c(ce,"y2",Mt);const Tt={};R&64&&(Tt.x=e[6][0][0]),R&64&&(Tt.y=e[6][0][1]),R&8&&(Tt.scale=e[3]),Ue.$set(Tt);const Pt={};R&64&&(Pt.x=e[6][1][0]),R&64&&(Pt.y=e[6][1][1]),R&8&&(Pt.scale=e[3]),Ye.$set(Pt);const Lt={};R&64&&(Lt.x=e[6][2][0]),R&64&&(Lt.y=e[6][2][1]),R&8&&(Lt.scale=e[3]),Ve.$set(Lt);const It={};R&64&&(It.x=e[6][3][0]),R&64&&(It.y=e[6][3][1]),R&8&&(It.scale=e[3]),Xe.$set(It)},i(K){J||(Y(C.$$.fragment,K),Y(Ue.$$.fragment,K),Y(Ye.$$.fragment,K),Y(Ve.$$.fragment,K),Y(Xe.$$.fragment,K),J=!0)},o(K){G(C.$$.fragment,K),G(Ue.$$.fragment,K),G(Ye.$$.fragment,K),G(Ve.$$.fragment,K),G(Xe.$$.fragment,K),J=!1},d(K){K&&(B(t),B(d),B(f),B(T),B(V),B(E),B(m),B(z),B(X),B(_e),B(ie),B(we),B(ce),B(cn),B(un),B(fn),B(dn)),ae(C),ae(Ue,K),ae(Ye,K),ae(Ve,K),ae(Xe,K),gn=!1,Ae(si)}}}function Qs(e){let t,n;return t=new bt({props:{shape:e[0],transform:e[2],editor:e[8],svgEl:e[4],$$slots:{default:[Js,({grab:o})=>({16:o}),({grab:o})=>o?65536:0]},$$scope:{ctx:e}}}),t.$on("grab",e[12]),t.$on("change",e[13]),t.$on("release",e[14]),{c(){ue(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&196842&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const fo=e=>`${e[0]},${e[1]}`,go=e=>`${e[0]},${e[1]}`,ho=e=>`${e[0]},${e[1]}`;function $s(e,t,n){let o,i,s,l,r,{shape:a}=t,{computedStyle:u}=t,{transform:d}=t,{viewportScale:f=1}=t,{svgEl:g}=t,h=!1;const p=(y,M,L)=>{let{x:C,y:T,w:V,h:N,rot:ee=0}=y.geometry;const[F,v]=L;if(M==="ROTATION"){const m=uo(y.geometry,o),b=m[0]+F,I=m[1]+v,k=[C+V/2,T+N/2];ee+=Ws([m[0],m[1]],[b,I],k),h&&(ee=Zs(ee))}else if(M==="SHAPE")C+=F,T+=v;else{let m=0,b=0,I=V,k=N;const[O,z]=ee!==0?Ks(F,v,ee):[F,v];switch(M){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":b+=z;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":k+=z;break}switch(M){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":m+=O;break;case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":I+=O;break}const X=(m+I)/2,$=(b+k)/2;V=Math.abs(I-m),N=Math.abs(k-b);const W=[C+y.geometry.w/2,T+y.geometry.h/2],Z=[X-y.geometry.w/2,$-y.geometry.h/2],te=Math.cos(ee),_e=Math.sin(ee),ie=W[0]+Z[0]*te-Z[1]*_e,ke=W[1]+Z[0]*_e+Z[1]*te;C=ie-V/2,T=ke-N/2}const E=fe(s);return{...y,geometry:{x:C,y:T,w:V,h:N,rot:ee,bounds:E}}};Oe(()=>{const y=L=>{L.key==="Shift"&&(h=!0)},M=L=>{L.key==="Shift"&&(h=!1)};return window.addEventListener("keydown",y),window.addEventListener("keyup",M),()=>{window.removeEventListener("keydown",y),window.removeEventListener("keyup",M)}});const _=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function A(y){ge.call(this,e,y)}function w(y){ge.call(this,e,y)}function S(y){ge.call(this,e,y)}return e.$$set=y=>{"shape"in y&&n(0,a=y.shape),"computedStyle"in y&&n(1,u=y.computedStyle),"transform"in y&&n(2,d=y.transform),"viewportScale"in y&&n(3,f=y.viewportScale),"svgEl"in y&&n(4,g=y.svgEl)},e.$$.update=()=>{e.$$.dirty&8&&n(11,o=20/f),e.$$.dirty&1&&n(10,i=a.geometry),e.$$.dirty&1024&&n(6,s=qs(i.x,i.y,i.w,i.h,i.rot)),e.$$.dirty&3072&&n(7,l=uo(i,o)),e.$$.dirty&1032&&n(5,r=at(i.bounds,5/f))},[a,u,d,f,g,r,s,l,p,_,i,o,A,w,S]}class mo extends me{constructor(t){super(),he(this,t,$s,Qs,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var po=Object.prototype.hasOwnProperty;function Wt(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--&&Wt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(po.call(e,n)&&++o&&!po.call(t,n)||!(n in t)||!Wt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const xs=12,er=(e,t)=>e.polygons.reduce((n,o,i)=>{const s=o.rings.reduce((l,r,a)=>{const u=r.points.map((d,f)=>{const g=f===r.points.length-1?r.points[0]:r.points[f+1],h=(d[0]+g[0])/2,p=(d[1]+g[1])/2,A=Math.sqrt(Math.pow(g[0]-h,2)+Math.pow(g[1]-p,2))>xs/t;return{point:[h,p],visible:A,elementIdx:i,ringIdx:a,pointIdx:f}});return[...l,...u]},[]);return[...n,...s]},[]);function Zt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function yo(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function _o(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function wo(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 Qt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function bo(e){let t,n,o,i;return{c(){t=P("circle"),c(t,"cx",n=e[29][0]),c(t,"cy",o=e[29][1]),c(t,"r",i=ut/e[3]),c(t,"class","svelte-1vxo6dc")},m(s,l){U(s,t,l)},p(s,l){l[0]&1088&&n!==(n=s[29][0])&&c(t,"cx",n),l[0]&1088&&o!==(o=s[29][1])&&c(t,"cy",o),l[0]&8&&i!==(i=ut/s[3])&&c(t,"r",i)},d(s){s&&B(t)}}}function Eo(e){let t,n,o,i,s,l,r,a,u,d;return{c(){t=P("mask"),n=P("rect"),r=P("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",l=e[9].h),c(n,"class","svelte-1vxo6dc"),c(r,"cx",a=e[29][0]),c(r,"cy",u=e[29][1]),c(r,"r",d=ut/e[3]),c(r,"class","svelte-1vxo6dc"),c(t,"id",`${e[18]}-${e[32]}-inner`),c(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(f,g){U(f,t,g),j(t,n),j(t,r)},p(f,g){g[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),g[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),g[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),g[0]&512&&l!==(l=f[9].h)&&c(n,"height",l),g[0]&1088&&a!==(a=f[29][0])&&c(r,"cx",a),g[0]&1088&&u!==(u=f[29][1])&&c(r,"cy",u),g[0]&8&&d!==(d=ut/f[3])&&c(r,"r",d)},d(f){f&&B(t)}}}function vo(e){let t,n;function o(...i){return e[19](e[32],e[35],e[37],...i)}return t=new Be({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(){se(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(){ue(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){e=i;const l={};s[0]&32&&(l.x=e[29][0]),s[0]&32&&(l.y=e[29][1]),s[0]&8&&(l.scale=e[3]),s[0]&256&&(l.selected=e[8].some(o)),t.$set(l)},i(i){n||(Y(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function So(e){let t,n,o=Se(e[33].points),i=[];for(let l=0;l<o.length;l+=1)i[l]=vo(wo(e,o,l));const s=l=>G(i[l],1,1,()=>{i[l]=null});return{c(){for(let l=0;l<i.length;l+=1)i[l].c();t=Me()},m(l,r){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(l,r);U(l,t,r),n=!0},p(l,r){if(r[0]&268491048){o=Se(l[33].points);let a;for(a=0;a<o.length;a+=1){const u=wo(l,o,a);i[a]?(i[a].p(u,r),Y(i[a],1)):(i[a]=vo(u),i[a].c(),Y(i[a],1),i[a].m(t.parentNode,t))}for(Ee(),a=o.length;a<i.length;a+=1)s(a);ve()}},i(l){if(!n){for(let r=0;r<o.length;r+=1)Y(i[r]);n=!0}},o(l){i=i.filter(Boolean);for(let r=0;r<i.length;r+=1)G(i[r]);n=!1},d(l){l&&B(t),He(i,l)}}}function Ao(e){let t,n,o,i,s,l,r,a,u,d,f,g,h,p,_,A,w,S=e[6]!==void 0&&!e[7]&&bo(Qt(e)),y=e[6]!==void 0&&!e[7]&&Eo(Jt(e)),M=Se(e[30].rings),L=[];for(let T=0;T<M.length;T+=1)L[T]=So(_o(e,M,T));const C=T=>G(L[T],1,1,()=>{L[T]=null});return{c(){t=P("g"),n=P("defs"),o=P("mask"),i=P("rect"),u=P("path"),S&&S.c(),y&&y.c(),f=P("path"),h=P("path");for(let T=0;T<L.length;T+=1)L[T].c();c(i,"x",s=e[9].x),c(i,"y",l=e[9].y),c(i,"width",r=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",g=Le(e[30])),c(h,"class","a9s-inner"),c(h,"mask",`url(#${e[18]}-${e[32]}-inner)`),c(h,"style",e[1]),c(h,"fill-rule","evenodd"),c(h,"d",p=Le(e[30]))},m(T,V){U(T,t,V),j(t,n),j(n,o),j(o,i),j(o,u),S&&S.m(o,null),y&&y.m(n,null),j(t,f),j(t,h);for(let N=0;N<L.length;N+=1)L[N]&&L[N].m(t,null);_=!0,A||(w=[x(f,"pointerup",e[13]),x(f,"pointerdown",function(){se(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),x(h,"pointerup",e[13]),x(h,"pointerdown",function(){se(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],A=!0)},p(T,V){if(e=T,(!_||V[0]&512&&s!==(s=e[9].x))&&c(i,"x",s),(!_||V[0]&512&&l!==(l=e[9].y))&&c(i,"y",l),(!_||V[0]&512&&r!==(r=e[9].w))&&c(i,"width",r),(!_||V[0]&512&&a!==(a=e[9].h))&&c(i,"height",a),(!_||V[0]&32&&d!==(d=Le(e[30])))&&c(u,"d",d),e[6]!==void 0&&!e[7]?S?S.p(Qt(e),V):(S=bo(Qt(e)),S.c(),S.m(o,null)):S&&(S.d(1),S=null),e[6]!==void 0&&!e[7]?y?y.p(Jt(e),V):(y=Eo(Jt(e)),y.c(),y.m(n,null)):y&&(y.d(1),y=null),(!_||V[0]&32&&g!==(g=Le(e[30])))&&c(f,"d",g),(!_||V[0]&2)&&c(h,"style",e[1]),(!_||V[0]&32&&p!==(p=Le(e[30])))&&c(h,"d",p),V[0]&268491048){M=Se(e[30].rings);let N;for(N=0;N<M.length;N+=1){const ee=_o(e,M,N);L[N]?(L[N].p(ee,V),Y(L[N],1)):(L[N]=So(ee),L[N].c(),Y(L[N],1),L[N].m(t,null))}for(Ee(),N=M.length;N<L.length;N+=1)C(N);ve()}},i(T){if(!_){for(let V=0;V<M.length;V+=1)Y(L[V]);_=!0}},o(T){L=L.filter(Boolean);for(let V=0;V<L.length;V+=1)G(L[V]);_=!1},d(T){T&&B(t),S&&S.d(),y&&y.d(),He(L,T),A=!1,Ae(w)}}}function Mo(e){let t,n;return t=new Ft({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){se(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function tr(e){let t,n,o,i=Se(e[5].polygons),s=[];for(let a=0;a<i.length;a+=1)s[a]=Ao(yo(e,i,a));const l=a=>G(s[a],1,1,()=>{s[a]=null});let r=e[6]!==void 0&&!e[7]&&Mo(Zt(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=be(),r&&r.c(),n=Me()},m(a,u){for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(a,u);U(a,t,u),r&&r.m(a,u),U(a,n,u),o=!0},p(a,u){if(u[0]&268763114){i=Se(a[5].polygons);let d;for(d=0;d<i.length;d+=1){const f=yo(a,i,d);s[d]?(s[d].p(f,u),Y(s[d],1)):(s[d]=Ao(f),s[d].c(),Y(s[d],1),s[d].m(t.parentNode,t))}for(Ee(),d=i.length;d<s.length;d+=1)l(d);ve()}a[6]!==void 0&&!a[7]?r?(r.p(Zt(a),u),u[0]&192&&Y(r,1)):(r=Mo(Zt(a)),r.c(),Y(r,1),r.m(n.parentNode,n)):r&&(Ee(),G(r,1,1,()=>{r=null}),ve())},i(a){if(!o){for(let u=0;u<i.length;u+=1)Y(s[u]);Y(r),o=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)G(s[u]);G(r),o=!1},d(a){a&&(B(t),B(n)),He(s,a),r&&r.d(a)}}}function nr(e){let t,n;return t=new bt({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[tr,({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(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const or=250,ir=1e3,ut=4.5;function sr(e,t,n){let o,i,s;const l=De();let{shape:r}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,g,h=!1,p,_=[];const A=()=>n(7,h=!0),w=()=>n(7,h=!1),S=b=>{if(_.length>0||!i.some(Z=>Z.visible)){n(6,g=void 0);return}const[I,k]=u.elementToImage(b.offsetX,b.offsetY),O=Z=>Math.pow(Z[0]-I,2)+Math.pow(Z[1]-k,2),z=In(o).reduce((Z,te)=>O(te)<O(Z)?te:Z),X=i.filter(Z=>Z.visible).reduce((Z,te)=>O(te.point)<O(Z.point)?te:Z),$=Math.pow(ir/d,2);O(z)<$||O(X.point)<$?n(6,g=i.indexOf(X)):n(6,g=void 0)},y=()=>{document.activeElement!==f&&f.focus()},M=()=>{n(8,_=[]),y()},L=b=>{n(7,h=!0),b.preventDefault(),b.stopPropagation(),p=performance.now()},C=(b,I,k)=>O=>{if(!p||Ie||performance.now()-p>or)return;const z=$=>$.polygon===b&&$.ring===I&&$.point===k,X=_.some(z);O.metaKey||O.ctrlKey||O.shiftKey?X?n(8,_=_.filter($=>!z($))):n(8,_=[..._,{polygon:b,ring:I,point:k}]):X&&_.length>1?n(8,_=[{polygon:b,ring:I,point:k}]):X?n(8,_=[]):n(8,_=[{polygon:b,ring:I,point:k}]),y()},T=(b,I,k)=>{y();const O=b.geometry.polygons;let z;if(I==="SHAPE")z=O.map(X=>{const $=X.rings.map((Z,te)=>({points:Z.points.map((ie,ke)=>[ie[0]+k[0],ie[1]+k[1]])})),W=fe($[0].points);return{rings:$,bounds:W}});else{const[X,$,W,Z]=I.split("-").map(te=>parseInt(te));z=O.map((te,_e)=>{if(_e===$){const ie=te.rings.map((H,de)=>de===W?{points:H.points.map((we,ce)=>ce===Z?[we[0]+k[0],we[1]+k[1]]:we)}:H),ke=fe(ie[0].points);return{rings:ie,bounds:ke}}else return te})}return{...b,geometry:{polygons:z,bounds:it(z)}}},V=b=>async I=>{I.stopPropagation();const k=i[b],O=o.polygons.map((X,$)=>{if($===k.elementIdx){const W=X.rings.map((te,_e)=>_e===k.ringIdx?{points:[...te.points.slice(0,k.pointIdx+1),k.point,...te.points.slice(k.pointIdx+1)]}:te),Z=fe(W[0].points);return{rings:W,bounds:Z}}else return X});l("change",{...r,geometry:{polygons:O,bounds:it(O)}}),await Mn();const z=[...document.querySelectorAll(".a9s-handle")][b+1];if(z!=null&&z.firstChild){const X=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(X)}},N=()=>{const b=o.polygons.map((k,O)=>{if(_.some(X=>X.polygon===O)){const X=k.rings.map((W,Z)=>{const te=_.filter(_e=>_e.polygon===O&&_e.ring===Z);return te.length&&W.points.length-te.length>=3?{points:W.points.filter((ie,ke)=>!te.some(H=>H.point===ke))}:W}),$=fe(X[0].points);return{rings:X,bounds:$}}else return k});!Wt(o.polygons,b)&&(l("change",{...r,geometry:{polygons:b,bounds:it(b)}}),n(8,_=[]))};Oe(()=>{if(Ie)return;const b=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),N())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",b),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",b)}});const ee=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,F=(b,I,k,{polygon:O,ring:z,point:X})=>O===b&&z===I&&X===k;function v(b){ge.call(this,e,b)}function E(b){ge.call(this,e,b)}function m(b){ge.call(this,e,b)}return e.$$set=b=>{"shape"in b&&n(0,r=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=r.geometry),e.$$.dirty[0]&40&&n(10,i=Ie?[]:er(o,d)),e.$$.dirty[0]&40&&n(9,s=at(o.bounds,ut/d))},[r,a,u,d,f,o,g,h,_,s,i,A,w,M,L,C,T,V,ee,F,v,E,m]}class rr extends me{constructor(t){super(),he(this,t,sr,nr,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const ko=new Map([[Q.RECTANGLE,mo],[Q.POLYGON,ao],[Q.MULTIPOLYGON,rr]]),To=e=>ko.get(e.type),Po=(e,t)=>ko.set(e,t);function lr(e,t,n){let o;const i=De();let{annotation:s}=t,{editor:l}=t,{style:r}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,f;return Oe(()=>(n(6,f=new l({target:a,props:{shape:s.target.selector,computedStyle:o,transform:u,viewportScale:d,svgEl:a.closest("svg")}})),f.$on("change",g=>{f.$$set({shape:g.detail}),i("change",g.detail)}),f.$on("grab",g=>i("grab",g.detail)),f.$on("release",g=>i("release",g.detail)),()=>{f.$destroy()})),e.$$set=g=>{"annotation"in g&&n(0,s=g.annotation),"editor"in g&&n(1,l=g.editor),"style"in g&&n(2,r=g.style),"target"in g&&n(3,a=g.target),"transform"in g&&n(4,u=g.transform),"viewportScale"in g&&n(5,d=g.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,o=Fe(s,r,{selected:!0,hovered:!0})),e.$$.dirty&65&&s&&(f==null||f.$set({shape:s.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:u}),e.$$.dirty&96&&f&&f.$set({viewportScale:d}),e.$$.dirty&192&&f&&o&&f.$set({computedStyle:o})},[s,l,r,a,u,d,f,o]}class Lo extends me{constructor(t){super(),he(this,t,lr,null,re,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function ar(e,t,n){const o=De();let{drawingMode:i}=t,{target:s}=t,{tool:l}=t,{transform:r}=t,{viewportScale:a}=t,u;return Oe(()=>{const d=s.closest("svg"),f=[],g=(h,p,_)=>{d==null||d.addEventListener(h,p,_),f.push(()=>d==null?void 0:d.removeEventListener(h,p,_))};return n(5,u=new l({target:s,props:{addEventListener:g,drawingMode:i,transform:r,viewportScale:a}})),u.$on("create",h=>o("create",h.detail)),()=>{f.forEach(h=>h()),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,l=d.tool),"transform"in d&&n(3,r=d.transform),"viewportScale"in d&&n(4,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:r}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[i,s,l,r,a,u]}class Io extends me{constructor(t){super(),he(this,t,ar,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Co(e){let t,n,o,i,s,l,r,a,u,d;return{c(){t=P("defs"),n=P("mask"),o=P("rect"),a=P("rect"),u=P("rect"),d=P("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",l=e[3]+2*e[5]),c(o,"height",r=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,g){U(f,t,g),j(t,n),j(n,o),j(n,a),U(f,u,g),U(f,d,g)},p(f,g){g&34&&i!==(i=f[1]-f[5])&&c(o,"x",i),g&36&&s!==(s=f[2]-f[5])&&c(o,"y",s),g&40&&l!==(l=f[3]+2*f[5])&&c(o,"width",l),g&48&&r!==(r=f[4]+2*f[5])&&c(o,"height",r),g&2&&c(a,"x",f[1]),g&4&&c(a,"y",f[2]),g&8&&c(a,"width",f[3]),g&16&&c(a,"height",f[4]),g&2&&c(u,"x",f[1]),g&4&&c(u,"y",f[2]),g&8&&c(u,"width",f[3]),g&16&&c(u,"height",f[4]),g&2&&c(d,"x",f[1]),g&4&&c(d,"y",f[2]),g&8&&c(d,"width",f[3]),g&16&&c(d,"height",f[4])},d(f){f&&(B(t),B(u),B(d))}}}function cr(e){let t,n=e[0]&&Co(e);return{c(){t=P("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){U(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=Co(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(o){o&&B(t),n&&n.d()}}}function ur(e,t,n){let o;const i=De();let{addEventListener:s}=t,{drawingMode:l}=t,{transform:r}=t,{viewportScale:a=1}=t,u,d,f,g,h,p,_;const A=L=>{const C=L;u=performance.now(),l==="drag"&&(n(0,d=r.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,g=d[0]),n(2,h=d[1]),n(3,p=1),n(4,_=1))},w=L=>{const C=L;d&&(f=r.elementToImage(C.offsetX,C.offsetY),n(1,g=Math.min(f[0],d[0])),n(2,h=Math.min(f[1],d[1])),n(3,p=Math.abs(f[0]-d[0])),n(4,_=Math.abs(f[1]-d[1])))},S=L=>{const C=L,T=performance.now()-u;if(l==="click"){if(T>300)return;d?y():(n(0,d=r.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,g=d[0]),n(2,h=d[1]),n(3,p=1),n(4,_=1))}else d&&(T>300||p*_>100?(C.stopPropagation(),y()):(n(0,d=void 0),f=void 0))},y=()=>{if(p*_>15){const L={type:Q.RECTANGLE,geometry:{bounds:{minX:g,minY:h,maxX:g+p,maxY:h+_},rot:0,x:g,y:h,w:p,h:_}};i("create",L)}n(0,d=void 0),f=void 0};Oe(()=>{s("pointerdown",A),s("pointermove",w),s("pointerup",S,!0)});const M=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=L=>{"addEventListener"in L&&n(7,s=L.addEventListener),"drawingMode"in L&&n(8,l=L.drawingMode),"transform"in L&&n(9,r=L.transform),"viewportScale"in L&&n(10,a=L.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,o=2/a)},[d,g,h,p,_,o,M,s,l,r,a]}class Oo extends me{constructor(t){super(),he(this,t,ur,cr,re,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function $t(e){const t=e.slice(),n=t[2].map(o=>o.join(",")).join(" ");return t[19]=n,t}function Do(e){let t,n,o,i,s,l,r,a,u,d,f,g,h,p,_=e[1]&&No(e);return{c(){t=P("defs"),n=P("mask"),o=P("rect"),a=P("polygon"),d=P("polygon"),g=P("polygon"),_&&_.c(),p=Me(),c(o,"x",i=e[3].x),c(o,"y",s=e[3].y),c(o,"width",l=e[3].w),c(o,"height",r=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(g,"class","a9s-inner"),c(g,"points",h=e[19])},m(A,w){U(A,t,w),j(t,n),j(n,o),j(n,a),U(A,d,w),U(A,g,w),_&&_.m(A,w),U(A,p,w)},p(A,w){w&8&&i!==(i=A[3].x)&&c(o,"x",i),w&8&&s!==(s=A[3].y)&&c(o,"y",s),w&8&&l!==(l=A[3].w)&&c(o,"width",l),w&8&&r!==(r=A[3].h)&&c(o,"height",r),w&4&&u!==(u=A[19])&&c(a,"points",u),w&4&&f!==(f=A[19])&&c(d,"points",f),w&4&&h!==(h=A[19])&&c(g,"points",h),A[1]?_?_.p(A,w):(_=No(A),_.c(),_.m(p.parentNode,p)):_&&(_.d(1),_=null)},d(A){A&&(B(t),B(d),B(g),B(p)),_&&_.d(A)}}}function No(e){let t,n,o;return{c(){t=P("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){U(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 fr(e){let t,n=e[3]&&Do($t(e));return{c(){t=P("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){U(o,t,i),n&&n.m(t,null)},p(o,[i]){o[3]?n?n.p($t(o),i):(n=Do($t(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(o){o&&B(t),n&&n.d()}}}const dr=20,gr=1500;function hr(e,t,n){let o,i,s;const l=De();let{addEventListener:r}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,f,g=[],h,p,_=!1;const A=C=>{const T=C,{timeStamp:V,offsetX:N,offsetY:ee}=T;if(f={timeStamp:V,offsetX:N,offsetY:ee},a==="drag"&&g.length===0){const F=u.elementToImage(T.offsetX,T.offsetY);g.push(F),n(10,h=F)}},w=C=>{const T=C;if(p&&clearTimeout(p),g.length>0){if(n(10,h=u.elementToImage(T.offsetX,T.offsetY)),g.length>2){const V=ot(h,g[0])*d;n(1,_=V<dr)}T.pointerType==="touch"&&(p=setTimeout(()=>{y()},gr))}},S=C=>{const T=C;if(p&&clearTimeout(p),a==="click"){const V=T.timeStamp-f.timeStamp,N=ot([f.offsetX,f.offsetY],[T.offsetX,T.offsetY]);if(V>300||N>15)return;if(_)M();else if(g.length===0){const ee=u.elementToImage(T.offsetX,T.offsetY);g.push(ee),n(10,h=ee)}else h&&g.push(h)}else{if(!h)return;if(g.length===1&&ot(g[0],h)<=4){n(0,g=[]),n(10,h=void 0);return}T.stopImmediatePropagation(),_?M():g.push(h)}},y=()=>{if(!h)return;const C=g.slice(0,-1);if(C.length<3)return;const T={type:Q.POLYGON,geometry:{bounds:fe(g),points:C}};pt(T)>4&&(n(0,g=[]),n(10,h=void 0),l("create",T))},M=()=>{const C={type:Q.POLYGON,geometry:{bounds:fe(g),points:[...g]}};n(0,g=[]),n(10,h=void 0),l("create",C)};Oe(()=>{r("pointerdown",A,!0),r("pointermove",w),r("pointerup",S,!0),r("dblclick",y,!0)});const L=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=C=>{"addEventListener"in C&&n(6,r=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=h?_?g:[...g,h]:[]),e.$$.dirty&516&&n(3,s=i.length>0?at(fe(i),2/d):void 0)},[g,_,i,s,o,L,r,a,u,d,h]}class mr extends me{constructor(t){super(),he(this,t,hr,fr,re,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const xt=new Map([["rectangle",{tool:Oo}],["polygon",{tool:mr}]]),en=()=>[...xt.keys()],tn=e=>xt.get(e),Ro=(e,t,n={})=>xt.set(e,{tool:t,opts:n});function pr(e){let t,n,o,i,s;return{c(){t=P("g"),n=P("ellipse"),i=P("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(l,r){U(l,t,r),j(t,n),j(t,i)},p(l,[r]){r&2&&o!==(o=l[1]?"display:none;":void 0)&&c(n,"style",o),r&2&&c(i,"style",l[1]),r&1&&s!==(s=l[0].id)&&c(t,"data-id",s)},i:q,o:q,d(l){l&&B(t)}}}function yr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:l}=t;const{cx:r,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,l=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Fe(i,l))},[i,o,r,a,u,d,s,l]}class _r extends me{constructor(t){super(),he(this,t,yr,pr,re,{annotation:0,geom:6,style:7})}}function wr(e){let t,n,o,i,s;return{c(){t=P("g"),n=P("line"),i=P("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(l,r){U(l,t,r),j(t,n),j(t,i)},p(l,[r]){r&2&&o!==(o=l[1]?"display:none;":void 0)&&c(n,"style",o),r&2&&c(i,"style",l[1]),r&1&&s!==(s=l[0].id)&&c(t,"data-id",s)},i:q,o:q,d(l){l&&B(t)}}}function br(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:l}=t;const{points:r}=s,[[a,u],[d,f]]=r;return e.$$set=g=>{"annotation"in g&&n(0,i=g.annotation),"geom"in g&&n(6,s=g.geom),"style"in g&&n(7,l=g.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Fe(i,l))},[i,o,a,u,d,f,s,l]}class Er extends me{constructor(t){super(),he(this,t,br,wr,re,{annotation:0,geom:6,style:7})}}function Bo(e,t,n){const o=e.slice();return o[5]=t[n],o}function Uo(e){let t,n,o;return{c(){t=P("path"),o=P("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){U(i,t,s),U(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 vr(e){let t,n,o=Se(e[2]),i=[];for(let s=0;s<o.length;s+=1)i[s]=Uo(Bo(e,o,s));return{c(){t=P("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,l){U(s,t,l);for(let r=0;r<i.length;r+=1)i[r]&&i[r].m(t,null)},p(s,[l]){if(l&6){o=Se(s[2]);let r;for(r=0;r<o.length;r+=1){const a=Bo(s,o,r);i[r]?i[r].p(a,l):(i[r]=Uo(a),i[r].c(),i[r].m(t,null))}for(;r<i.length;r+=1)i[r].d(1);i.length=o.length}l&1&&n!==(n=s[0].id)&&c(t,"data-id",n)},i:q,o:q,d(s){s&&B(t),He(i,s)}}}function Sr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:l}=t;const{polygons:r}=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,l=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Fe(i,l))},[i,o,r,s,l]}class Ar extends me{constructor(t){super(),he(this,t,Sr,vr,re,{annotation:0,geom:3,style:4})}}function Mr(e){let t,n,o,i,s;return{c(){t=P("g"),n=P("polygon"),i=P("polygon"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"points",e[2].map(kr).join(" ")),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"points",e[2].map(Tr).join(" ")),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(l,r){U(l,t,r),j(t,n),j(t,i)},p(l,[r]){r&2&&o!==(o=l[1]?"display:none;":void 0)&&c(n,"style",o),r&2&&c(i,"style",l[1]),r&1&&s!==(s=l[0].id)&&c(t,"data-id",s)},i:q,o:q,d(l){l&&B(t)}}}const kr=e=>e.join(","),Tr=e=>e.join(",");function Pr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:l}=t;const{points:r}=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,l=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Fe(i,l))},[i,o,r,s,l]}class Lr extends me{constructor(t){super(),he(this,t,Pr,Mr,re,{annotation:0,geom:3,style:4})}}function Ir(e){let t,n,o,i,s,l,r;return{c(){t=P("g"),n=P("path"),s=P("path"),c(n,"class",o=qe(`a9s-outer ${e[1]}`)+" svelte-1w0132l"),c(n,"style",i=e[3]?"display:none;":void 0),c(n,"d",e[2]),c(s,"class",l=qe(`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",r=e[0].id)},m(a,u){U(a,t,u),j(t,n),j(t,s)},p(a,[u]){u&2&&o!==(o=qe(`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&&l!==(l=qe(`a9s-inner ${a[1]}`)+" svelte-1w0132l")&&c(s,"class",l),u&8&&c(s,"style",a[3]),u&4&&c(s,"d",a[2]),u&1&&r!==(r=a[0].id)&&c(t,"data-id",r)},i:q,o:q,d(a){a&&B(t)}}}function Cr(e,t,n){let o,i,s,{annotation:l}=t,{geom:r}=t,{style:a}=t;return e.$$set=u=>{"annotation"in u&&n(0,l=u.annotation),"geom"in u&&n(4,r=u.geom),"style"in u&&n(5,a=u.style)},e.$$.update=()=>{e.$$.dirty&33&&n(3,o=Fe(l,a)),e.$$.dirty&16&&n(2,i=Ut(r)),e.$$.dirty&16&&n(1,s=r.closed?"closed":"open")},[l,s,i,o,r,a]}class Or extends me{constructor(t){super(),he(this,t,Cr,Ir,re,{annotation:0,geom:4,style:5})}}function Dr(e){let t,n,o,i,s,l;return{c(){t=P("g"),n=P("g"),o=P("rect"),s=P("rect"),c(o,"class","a9s-outer"),c(o,"style",i=e[6]?"display:none;":void 0),c(o,"x",e[4]),c(o,"y",e[2]),c(o,"width",e[3]),c(o,"height",e[1]),c(s,"class","a9s-inner"),c(s,"style",e[6]),c(s,"x",e[4]),c(s,"y",e[2]),c(s,"width",e[3]),c(s,"height",e[1]),c(n,"transform",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",l=e[0].id)},m(r,a){U(r,t,a),j(t,n),j(n,o),j(n,s)},p(r,[a]){a&64&&i!==(i=r[6]?"display:none;":void 0)&&c(o,"style",i),a&16&&c(o,"x",r[4]),a&4&&c(o,"y",r[2]),a&8&&c(o,"width",r[3]),a&2&&c(o,"height",r[1]),a&64&&c(s,"style",r[6]),a&16&&c(s,"x",r[4]),a&4&&c(s,"y",r[2]),a&8&&c(s,"width",r[3]),a&2&&c(s,"height",r[1]),a&32&&c(n,"transform",r[5]),a&1&&l!==(l=r[0].id)&&c(t,"data-id",l)},i:q,o:q,d(r){r&&B(t)}}}function Nr(e,t,n){let o,i,s,l,r,a,u,{annotation:d}=t,{geom:f}=t,{style:g}=t;return e.$$set=h=>{"annotation"in h&&n(0,d=h.annotation),"geom"in h&&n(7,f=h.geom),"style"in h&&n(8,g=h.style)},e.$$.update=()=>{e.$$.dirty&257&&n(6,o=Fe(d,g)),e.$$.dirty&128&&n(4,{x:i,y:s,w:l,h:r,rot:a}=f,i,(n(2,s),n(7,f)),(n(3,l),n(7,f)),(n(1,r),n(7,f)),(n(9,a),n(7,f))),e.$$.dirty&542&&n(5,u=(a??0)!==0?`translate(${i+l/2}, ${s+r/2}) rotate(${(a??0)*180/Math.PI}) translate(${-(i+l/2)}, ${-(s+r/2)})`:void 0)},[d,r,s,l,i,u,o,f,g,a]}class Rr extends me{constructor(t){super(),he(this,t,Nr,Dr,re,{annotation:0,geom:7,style:8})}}const Br={elementToImage:(e,t)=>[e,t]},Yo=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:l}=i.matrixTransform(e.getScreenCTM().inverse());return[s,l]}}),Ur=250,Vo=(e,t)=>{const n=De();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:l=>{if(performance.now()-o<Ur){const{x:a,y:u}=nn(l,e),d=Ie?10:2,f=t.getAt(a,u,void 0,d);f?n("click",{originalEvent:l,annotation:f}):n("click",{originalEvent:l})}}}},nn=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:l,top:r}=t.getBoundingClientRect();return n.x=i+l,n.y=s+r,n.matrixTransform(t.getScreenCTM().inverse())};function Xo(e,t,n){const o=e.slice();return o[39]=t[n],o}function Ho(e,t,n){const o=e.slice();return o[42]=t[n],o}function on(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Go(e){let t=e[42],n,o,i=jo(e);return{c(){i.c(),n=Me()},m(s,l){i.m(s,l),U(s,n,l),o=!0},p(s,l){l[0]&131072&&re(t,t=s[42])?(Ee(),G(i,1,1,q),ve(),i=jo(s),i.c(),Y(i,1),i.m(n.parentNode,n)):i.p(s,l)},i(s){o||(Y(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function Yr(e){let t,n;return t=new Er({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ue(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||(Y(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 Or({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Xr(e){let t,n;return t=new Ar({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Hr(e){let t,n;return t=new Lr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Gr(e){let t,n;return t=new Rr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function jr(e){var o;let t,n;return t=new _r({props:{annotation:e[42],geom:(o=e[45])==null?void 0:o.geometry,style:e[1]}}),{c(){ue(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){var r;const l={};s[0]&131072&&(l.annotation=i[42]),s[0]&131072&&(l.geom=(r=i[45])==null?void 0:r.geometry),s[0]&2&&(l.style=i[1]),t.$set(l)},i(i){n||(Y(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function jo(e){let t,n,o,i;const s=[jr,Gr,Hr,Xr,Vr,Yr],l=[];function r(a,u){var d,f,g,h,p,_;return((d=a[45])==null?void 0:d.type)===Q.ELLIPSE?0:((f=a[45])==null?void 0:f.type)===Q.RECTANGLE?1:((g=a[45])==null?void 0:g.type)===Q.POLYGON?2:((h=a[45])==null?void 0:h.type)===Q.MULTIPOLYGON?3:((p=a[45])==null?void 0:p.type)===Q.POLYLINE?4:((_=a[45])==null?void 0:_.type)===Q.LINE?5:-1}return~(t=r(e))&&(n=l[t]=s[t](e)),{c(){n&&n.c(),o=Me()},m(a,u){~t&&l[t].m(a,u),U(a,o,u),i=!0},p(a,u){let d=t;t=r(a),t===d?~t&&l[t].p(a,u):(n&&(Ee(),G(l[d],1,1,()=>{l[d]=null}),ve()),~t?(n=l[t],n?n.p(a,u):(n=l[t]=s[t](a),n.c()),Y(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(Y(n),i=!0)},o(a){G(n),i=!1},d(a){a&&B(o),~t&&l[t].d(a)}}}function Fo(e){let t=st(e[42])&&!e[10](e[42]),n,o,i=t&&Go(on(e));return{c(){i&&i.c(),n=Me()},m(s,l){i&&i.m(s,l),U(s,n,l),o=!0},p(s,l){l[0]&132096&&(t=st(s[42])&&!s[10](s[42])),t?i?(i.p(on(s),l),l[0]&132096&&Y(i,1)):(i=Go(on(s)),i.c(),Y(i,1),i.m(n.parentNode,n)):i&&(Ee(),G(i,1,1,()=>{i=null}),ve())},i(s){o||(Y(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i&&i.d(s)}}}function zo(e){let t,n,o,i;const s=[zr,Fr],l=[];function r(a,u){return a[6]?0:a[15]&&a[0]?1:-1}return~(t=r(e))&&(n=l[t]=s[t](e)),{c(){n&&n.c(),o=Me()},m(a,u){~t&&l[t].m(a,u),U(a,o,u),i=!0},p(a,u){let d=t;t=r(a),t===d?~t&&l[t].p(a,u):(n&&(Ee(),G(l[d],1,1,()=>{l[d]=null}),ve()),~t?(n=l[t],n?n.p(a,u):(n=l[t]=s[t](a),n.c()),Y(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(Y(n),i=!0)},o(a){G(n),i=!1},d(a){a&&B(o),~t&&l[t].d(a)}}}function Fr(e){let t=`${e[2]}-${e[7]}`,n,o,i=qo(e);return{c(){i.c(),n=Me()},m(s,l){i.m(s,l),U(s,n,l),o=!0},p(s,l){l[0]&132&&re(t,t=`${s[2]}-${s[7]}`)?(Ee(),G(i,1,1,q),ve(),i=qo(s),i.c(),Y(i,1),i.m(n.parentNode,n)):i.p(s,l)},i(s){o||(Y(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function zr(e){let t,n,o=Se(e[6]),i=[];for(let l=0;l<o.length;l+=1)i[l]=Wo(Xo(e,o,l));const s=l=>G(i[l],1,1,()=>{i[l]=null});return{c(){for(let l=0;l<i.length;l+=1)i[l].c();t=Me()},m(l,r){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(l,r);U(l,t,r),n=!0},p(l,r){if(r[0]&8659266){o=Se(l[6]);let a;for(a=0;a<o.length;a+=1){const u=Xo(l,o,a);i[a]?(i[a].p(u,r),Y(i[a],1)):(i[a]=Wo(u),i[a].c(),Y(i[a],1),i[a].m(t.parentNode,t))}for(Ee(),a=o.length;a<i.length;a+=1)s(a);ve()}},i(l){if(!n){for(let r=0;r<o.length;r+=1)Y(i[r]);n=!0}},o(l){i=i.filter(Boolean);for(let r=0;r<i.length;r+=1)G(i[r]);n=!1},d(l){l&&B(t),He(i,l)}}}function qo(e){let t,n;return t=new Io({props:{target:e[8],tool:e[15],drawingMode:e[14],transform:e[13],viewportScale:e[18]}}),t.$on("create",e[22]),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ko(e){let t,n;return t=new Lo({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(){se(e[23](e[39].annotation))&&e[23](e[39].annotation).apply(this,arguments)}),{c(){ue(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||(Y(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Wo(e){let t=e[39].annotation.id,n,o,i=Ko(e);return{c(){i.c(),n=Me()},m(s,l){i.m(s,l),U(s,n,l),o=!0},p(s,l){l[0]&64&&re(t,t=s[39].annotation.id)?(Ee(),G(i,1,1,q),ve(),i=Ko(s),i.c(),Y(i,1),i.m(n.parentNode,n)):i.p(s,l)},i(s){o||(Y(i),o=!0)},o(s){G(i),o=!1},d(s){s&&B(n),i.d(s)}}}function qr(e){let t,n,o,i,s,l,r=Se(e[17].filter(e[34])),a=[];for(let f=0;f<r.length;f+=1)a[f]=Fo(Ho(e,r,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&zo(e);return{c(){t=P("svg"),n=P("g");for(let f=0;f<a.length;f+=1)a[f].c();o=P("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,g){U(f,t,g),j(t,n);for(let h=0;h<a.length;h+=1)a[h]&&a[h].m(n,null);j(t,o),d&&d.m(o,null),e[35](o),e[36](t),i=!0,s||(l=[x(t,"pointerup",function(){se(e[11])&&e[11].apply(this,arguments)}),x(t,"pointerdown",function(){se(e[12])&&e[12].apply(this,arguments)}),x(t,"pointermove",e[24])],s=!0)},p(f,g){if(e=f,g[0]&132098){r=Se(e[17].filter(e[34]));let h;for(h=0;h<r.length;h+=1){const p=Ho(e,r,h);a[h]?(a[h].p(p,g),Y(a[h],1)):(a[h]=Fo(p),a[h].c(),Y(a[h],1),a[h].m(n,null))}for(Ee(),h=r.length;h<a.length;h+=1)u(h);ve()}e[8]?d?(d.p(e,g),g[0]&256&&Y(d,1)):(d=zo(e),d.c(),Y(d,1),d.m(o,null)):d&&(Ee(),G(d,1,1,()=>{d=null}),ve()),(!i||g[0]&32768)&&Pe(t,"drawing",e[15]),(!i||g[0]&32)&&Pe(t,"editing",e[5]),(!i||g[0]&8)&&Pe(t,"hidden",!e[3]),(!i||g[0]&65536)&&Pe(t,"hover",e[16])},i(f){if(!i){for(let g=0;g<r.length;g+=1)Y(a[g]);Y(d),i=!0}},o(f){a=a.filter(Boolean);for(let g=0;g<a.length;g+=1)G(a[g]);G(d),i=!1},d(f){f&&B(t),He(a,f),d&&d.d(),e[35](null),e[36](null),s=!1,Ae(l)}}}function Kr(e,t,n){let o,i,s,l,r,a,u,d,f,g,h,p,_=q,A=()=>(_(),_=yn(b,H=>n(18,p=H)),b);e.$$.on_destroy.push(()=>_());let{drawingEnabled:w}=t,{image:S}=t,{preferredDrawingMode:y}=t,{state:M}=t,{style:L=void 0}=t,{toolName:C=en()[0]}=t,{user:T}=t,{visible:V=!0}=t,N=0;const ee=()=>n(7,N+=1),F=()=>C,v=()=>w;let E,m,b;Oe(()=>A(n(9,b=Qn(S,m))));const{hover:I,selection:k,store:O}=M;Ct(e,I,H=>n(16,f=H)),Ct(e,k,H=>n(33,g=H)),Ct(e,O,H=>n(17,h=H));let z,X;const $=H=>{z&&O.unobserve(z);const de=H.filter(({editable:ne})=>ne).map(({id:ne})=>ne);de.length>0?(n(5,X=de.map(ne=>O.getAnnotation(ne)).filter(ne=>ne&&st(ne))),z=ne=>{const{updated:we}=ne.changes;n(5,X=we==null?void 0:we.map(ce=>ce.newValue))},O.observe(z,{annotations:de})):n(5,X=void 0)},W=H=>{const de=jn(),ne={id:de,bodies:[],target:{annotation:de,selector:H.detail,creator:T,created:new Date}};O.addAnnotation(ne),k.setSelected(ne.id)},Z=H=>de=>{var ze;const{target:ne}=H,we=10*60*1e3,ce=((ze=ne.creator)==null?void 0:ze.id)!==T.id||!ne.created||new Date().getTime()-ne.created.getTime()>we;O.updateTarget({...ne,selector:de.detail,created:ce?ne.created:new Date,updated:ce?new Date:void 0,updatedBy:ce?T:void 0})},te=H=>{const{x:de,y:ne}=nn(H,m),we=O.getAt(de,ne,void 0,2);we?f!==we.id&&I.set(we.id):I.set(void 0)},_e=H=>st(H);function ie(H){ht[H?"unshift":"push"](()=>{E=H,n(8,E)})}function ke(H){ht[H?"unshift":"push"](()=>{m=H,n(4,m)})}return e.$$set=H=>{"drawingEnabled"in H&&n(0,w=H.drawingEnabled),"image"in H&&n(25,S=H.image),"preferredDrawingMode"in H&&n(26,y=H.preferredDrawingMode),"state"in H&&n(27,M=H.state),"style"in H&&n(1,L=H.style),"toolName"in H&&n(2,C=H.toolName),"user"in H&&n(28,T=H.user),"visible"in H&&n(3,V=H.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:o,opts:i}=tn(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)||y),e.$$.dirty[0]&16&&n(13,l=Yo(m)),e.$$.dirty[0]&16&&n(12,{onPointerDown:r,onPointerUp:a}=Vo(m,O),r,(n(11,a),n(4,m))),e.$$.dirty[1]&4&&$(g.selected),e.$$.dirty[0]&32&&n(6,u=X?X.map(H=>({annotation:H,editor:To(H.target.selector)})).filter(H=>H.editor):void 0),e.$$.dirty[0]&64&&n(10,d=H=>u&&u.some(de=>de.annotation.id===H.id))},[w,L,C,V,m,X,u,N,E,b,d,a,r,l,s,o,f,h,p,I,k,O,W,Z,te,S,y,M,T,ee,F,v,i,g,_e,ie,ke]}class Zo extends me{constructor(t){super(),he(this,t,Kr,qr,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 Jo(e,t,n=0,o=e.length-1,i=Wr){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),g=.5*Math.sqrt(d*f*(a-f)/a)*(u-a/2<0?-1:1),h=Math.max(n,Math.floor(t-u*f/a+g)),p=Math.min(o,Math.floor(t+(a-u)*f/a+g));Jo(e,t,h,p,i)}const s=e[t];let l=n,r=o;for(ft(e,n,t),i(e[o],s)>0&&ft(e,n,o);l<r;){for(ft(e,l,r),l++,r--;i(e[l],s)<0;)l++;for(;i(e[r],s)>0;)r--}i(e[n],s)===0?ft(e,n,r):(r++,ft(e,r,o)),r<=t&&(n=r+1),t<=r&&(o=r-1)}}function ft(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Wr(e,t){return e<t?-1:e>t?1:0}class Zr{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(!vt(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let l=0;l<n.children.length;l++){const r=n.children[l],a=n.leaf?i(r):r;vt(t,a)&&(n.leaf?o.push(r):rn(t,a)?this._all(r,o):s.push(r))}n=s.pop()}return o}collides(t){let n=this.data;if(!vt(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],l=n.leaf?this.toBBox(s):s;if(vt(t,l)){if(n.leaf||rn(t,l))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=$e([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],l=[];let r,a,u;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],r=l.pop(),u=!0),o.leaf){const d=Jr(t,o.children,n);if(d!==-1)return o.children.splice(d,1),s.push(o),this._condense(s),this}!u&&!o.leaf&&rn(o,i)?(s.push(o),l.push(r),r=0,a=o,o=o.children[0]):a?(r++,o=a.children[r],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 l=this._maxEntries,r;if(s<=l)return r=$e(t.slice(n,o+1)),Qe(r,this.toBBox),r;i||(i=Math.ceil(Math.log(s)/Math.log(l)),l=Math.ceil(s/Math.pow(l,i-1))),r=$e([]),r.leaf=!1,r.height=i;const a=Math.ceil(s/l),u=a*Math.ceil(Math.sqrt(l));Qo(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);Qo(t,d,f,a,this.compareMinY);for(let g=d;g<=f;g+=a){const h=Math.min(g+a-1,f);r.children.push(this._build(t,g,h,i-1))}}return Qe(r,this.toBBox),r}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,l=1/0,r;for(let a=0;a<n.children.length;a++){const u=n.children[a],d=sn(u),f=xr(t,u)-d;f<l?(l=f,s=d<s?d:s,r=u):f===l&&d<s&&(s=d,r=u)}n=r||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],l=this._chooseSubtree(i,this.data,n,s);for(l.children.push(t),gt(l,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 l=this._chooseSplitIndex(o,s,i),r=$e(o.children.splice(l,o.children.length-l));r.height=o.height,r.leaf=o.leaf,Qe(o,this.toBBox),Qe(r,this.toBBox),n?t[n-1].children.push(r):this._splitRoot(o,r)}_splitRoot(t,n){this.data=$e([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Qe(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,l=1/0;for(let r=n;r<=o-n;r++){const a=dt(t,0,r,this.toBBox),u=dt(t,r,o,this.toBBox),d=el(a,u),f=sn(a)+sn(u);d<s?(s=d,i=r,l=f<l?f:l):d===s&&f<l&&(l=f,i=r)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Qr,s=t.leaf?this.compareMinY:$r,l=this._allDistMargin(t,n,o,i),r=this._allDistMargin(t,n,o,s);l<r&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,l=dt(t,0,n,s),r=dt(t,o-n,o,s);let a=Et(l)+Et(r);for(let u=n;u<o-n;u++){const d=t.children[u];gt(l,t.leaf?s(d):d),a+=Et(l)}for(let u=o-n-1;u>=n;u--){const d=t.children[u];gt(r,t.leaf?s(d):d),a+=Et(r)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)gt(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():Qe(t[n],this.toBBox)}}function Jr(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 Qe(e,t){dt(e,0,e.children.length,t,e)}function dt(e,t,n,o,i){i||(i=$e(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 l=e.children[s];gt(i,e.leaf?o(l):l)}return i}function gt(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 Qr(e,t){return e.minX-t.minX}function $r(e,t){return e.minY-t.minY}function sn(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Et(e){return e.maxX-e.minX+(e.maxY-e.minY)}function xr(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 el(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 rn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function vt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function $e(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Qo(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const l=t+Math.ceil((n-t)/o/2)*o;Jo(e,l,t,n,i),s.push(t,l,l,n)}}const tl=()=>{const e=new Zr,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!rt(f))return;const{minX:g,minY:h,maxX:p,maxY:_}=f.selector.geometry.bounds,A={minX:g,minY:h,maxX:p,maxY:_,target:f};e.insert(A),t.set(f.annotation,A)},s=f=>{if(!rt(f))return;const g=t.get(f.annotation);g&&e.remove(g),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,g,h=0)=>{const _=e.search({minX:f-h,minY:g-h,maxX:f+h,maxY:g+h}).map(A=>A.target).filter(({selector:A})=>Pn(A,f,g,h));return _.length>0?(_.sort((A,w)=>pt(A.selector)-pt(w.selector)),_):[]},getIntersecting:(f,g,h,p)=>e.search({minX:f,minY:g,maxX:f+h,maxY:g+p}).map(_=>_.target),insert:i,remove:s,set:(f,g=!0)=>{g&&o();const h=f.reduce((p,_)=>{if(rt(_)){const{minX:A,minY:w,maxX:S,maxY:y}=_.selector.geometry.bounds;return[...p,{minX:A,minY:w,maxX:S,maxY:y,target:_}]}else return p},[]);h.forEach(p=>t.set(p.target.annotation,p)),e.load(h)},size:()=>e.all().length,update:(f,g)=>{s(f),i(g)}}},$o=e=>({...e,subscribe:n=>{const o=i=>n(i.state);return e.observe(o),n(e.all()),()=>e.unobserve(o)}}),xo=e=>{const t=ss(),n=tl(),o=Fi(t,e.userSelectAction,e.adapter),i=ji(t),s=cs();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 g=n.getAt(a,u,f);if(d)return g.map(p=>t.getAnnotation(p.annotation)).filter(Boolean).filter(d)[0];{const h=g[0];return h?t.getAnnotation(h.annotation):void 0}},getIntersecting:(a,u,d,f)=>n.getIntersecting(a,u,d,f).map(g=>t.getAnnotation(g.annotation)).filter(Boolean)},selection:o,hover:i,viewport:s}},ei=e=>{const t=xo(e);return{...t,store:$o(t.store)}},ti=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 l=Math.round(s*t.width/10),r=Math.round(i*t.height/10),a=n.getImageData(l,r,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=u}return o/81},ni=e=>{const t=ti(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},ln=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?ni(e):n),oi=(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}),an=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,ii=(e,t)=>{const n=t||document,o=l=>{const r=l;r.key==="z"&&r.ctrlKey?e.undo():r.key==="y"&&r.ctrlKey&&e.redo()},i=l=>{const r=l;r.key==="z"&&r.metaKey&&(r.shiftKey?e.redo():e.undo())},s=()=>{an?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return an?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},nl=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=oi(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Xt.EDIT,theme:"light"}),i=ei(o),{selection:s,store:l}=i,r=as(l,o.initialHistory),a=us(i,r,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=ii(r);let f=bs();ln(n,u,o.theme);const g=new Zo({target:u,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});g.$on("click",E=>{const{originalEvent:m,annotation:b}=E.detail;b?s.userSelect(b.id,m):s.isEmpty()||s.clear()});const h=ds(i,r,o.adapter),p=()=>g.cancelDrawing(),_=()=>{g.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),r.destroy()},A=()=>g.getDrawingTool(),w=()=>f,S=()=>g.isDrawingEnabled(),y=(E,m,b)=>Ro(E,m,b),M=(E,m)=>Po(E,m),L=E=>{if(!tn(E))throw`No drawing tool named ${E}`;g.$set({toolName:E})},C=E=>g.$set({drawingEnabled:E}),T=E=>g.$set({preferredDrawingMode:E}),V=E=>{console.warn("Filter not implemented yet")},N=E=>g.$set({style:E}),ee=E=>ln(n,u,E),F=E=>{f=E,g.$set({user:E})},v=E=>g.$set({visible:E});return{...h,cancelDrawing:p,destroy:_,getDrawingTool:A,getUser:w,isDrawingEnabled:S,listDrawingTools:en,on:a.on,off:a.off,registerDrawingTool:y,registerShapeEditor:M,setDrawingEnabled:C,setDrawingMode:T,setDrawingTool:L,setFilter:V,setStyle:N,setTheme:ee,setUser:F,setVisible:v,element:u,state:i}};D.Editor=bt,D.EditorMount=Lo,D.Handle=Be,D.IdentityTransform=Br,D.MidpointHandle=Ft,D.PolygonEditor=ao,D.RectangleEditor=mo,D.RectangleUtil=Dn,D.RubberbandRectangle=Oo,D.SVGAnnotationLayer=Zo,D.ShapeType=Q,D.ToolMount=Io,D.UserSelectAction=Xt,D.W3CImageFormat=ks,D.addEventListeners=Vo,D.approximateAsPolygon=yt,D.boundsFromMultiPolygonElements=it,D.boundsFromPoints=fe,D.chainStyles=hs,D.computeArea=pt,D.computePolygonArea=tt,D.computeSVGPath=Ut,D.computeStyle=gs,D.createBody=Qi,D.createImageAnnotator=nl,D.createImageAnnotatorState=xo,D.createSVGTransform=Yo,D.createSvelteImageAnnotatorState=ei,D.defaultColorProvider=Ms,D.detectTheme=ni,D.distance=ot,D.enableResponsive=Qn,D.fillDefaults=oi,D.getAllCorners=In,D.getEditor=To,D.getMaskDimensions=at,D.getSVGPoint=nn,D.getTool=tn,D.initKeyboardCommands=ii,D.intersects=Pn,D.isFragmentSelector=Nn,D.isImageAnnotation=st,D.isImageAnnotationTarget=rt,D.isMac=an,D.isPointInPolygon=nt,D.isTouch=Ie,D.listDrawingTools=en,D.multipolygonElementToPath=Le,D.parseFragmentSelector=Rn,D.parseSVGSelector=Xn,D.parseW3CImageAnnotation=Zn,D.pointsToPath=Ln,D.registerEditor=Po,D.registerShapeUtil=je,D.registerTool=Ro,D.sampleBrightness=ti,D.serializeFragmentSelector=Bn,D.serializeSVGSelector=Hn,D.serializeW3CImageAnnotation=Jn,D.setTheme=ln,D.simplifyMultiPolygon=Si,D.simplifyPoints=Bt,D.simplifyPolygon=Mi,D.toSvelteStore=$o,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=annotorious.js.map
|