@annotorious/annotorious 3.4.1 → 3.4.2
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/multipolygon/utils.d.ts +9 -0
- package/dist/annotorious.css +1 -1
- package/dist/annotorious.es.js +2562 -2194
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +2 -2
- package/dist/annotorious.js.map +1 -1
- package/dist/model/core/multipolygon/multiPolygonUtils.d.ts +2 -1
- package/package.json +3 -2
- package/src/annotation/editors/{polygon/MidpointHandle.svelte → MidpointHandle.svelte} +1 -1
- package/src/annotation/editors/multipolygon/MultiPolygonEditor.svelte +290 -17
- package/src/annotation/editors/multipolygon/utils.ts +42 -0
- package/src/annotation/editors/polygon/PolygonEditor.svelte +2 -4
- package/src/model/core/multipolygon/multiPolygonUtils.ts +11 -1
- /package/dist/annotation/editors/{polygon/MidpointHandle.svelte.d.ts → MidpointHandle.svelte.d.ts} +0 -0
package/dist/annotorious.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(k,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(k=typeof globalThis<"u"?globalThis:k||self,j(k.Annotorious={}))})(this,function(k){"use strict";var Yr=Object.defineProperty;var Xr=(k,j,De)=>j in k?Yr(k,j,{enumerable:!0,configurable:!0,writable:!0,value:De}):k[j]=De;var ne=(k,j,De)=>Xr(k,typeof j!="symbol"?j+"":j,De);function j(){}function De(e,t){for(const n in t)e[n]=t[n];return e}function ln(e){return e()}function an(){return Object.create(null)}function ve(e){e.forEach(ln)}function ie(e){return typeof e=="function"}function ae(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Wi(e){return Object.keys(e).length===0}function un(e,...t){if(e==null){for(const i of t)i(void 0);return j}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function It(e,t,n){e.$$.on_destroy.push(un(t,n))}function Ki(e,t,n,i){if(e){const o=fn(e,t,n,i);return e[0](o)}}function fn(e,t,n,i){return e[1]&&i?De(n.ctx.slice(),e[1](i(t))):n.ctx}function Ji(e,t,n,i){if(e[2]&&i){const o=e[2](i(n));if(t.dirty===void 0)return o;if(typeof o=="object"){const s=[],r=Math.max(t.dirty.length,o.length);for(let a=0;a<r;a+=1)s[a]=t.dirty[a]|o[a];return s}return t.dirty|o}return t.dirty}function xi(e,t,n,i,o,s){if(o){const r=fn(t,n,i,s);e.p(r,o)}}function $i(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let i=0;i<n;i++)t[i]=-1;return t}return-1}function cn(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function pt(e){return e??""}function Z(e,t){e.appendChild(t)}function P(e,t,n){e.insertBefore(t,n||null)}function D(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 I(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function hn(e){return document.createTextNode(e)}function Te(){return hn(" ")}function Ae(){return hn("")}function K(e,t,n,i){return e.addEventListener(t,n,i),()=>e.removeEventListener(t,n,i)}function u(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function eo(e){return Array.from(e.childNodes)}function Le(e,t,n){e.classList.toggle(t,!!n)}function to(e,t,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:i})}let it;function ot(e){it=e}function dn(){if(!it)throw new Error("Function called outside component initialization");return it}function je(e){dn().$$.on_mount.push(e)}function Xe(){const e=dn();return(t,n,{cancelable:i=!1}={})=>{const o=e.$$.callbacks[t];if(o){const s=to(t,n,{cancelable:i});return o.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function pe(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(i=>i.call(this,t))}const Qe=[],st=[];let qe=[];const gn=[],pn=Promise.resolve();let Lt=!1;function yn(){Lt||(Lt=!0,pn.then(_n))}function no(){return yn(),pn}function kt(e){qe.push(e)}const Dt=new Set;let Ze=0;function _n(){if(Ze!==0)return;const e=it;do{try{for(;Ze<Qe.length;){const t=Qe[Ze];Ze++,ot(t),io(t.$$)}}catch(t){throw Qe.length=0,Ze=0,t}for(ot(null),Qe.length=0,Ze=0;st.length;)st.pop()();for(let t=0;t<qe.length;t+=1){const n=qe[t];Dt.has(n)||(Dt.add(n),n())}qe.length=0}while(Qe.length);for(;gn.length;)gn.pop()();Lt=!1,Dt.clear(),ot(e)}function io(e){if(e.fragment!==null){e.update(),ve(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(kt)}}function oo(e){const t=[],n=[];qe.forEach(i=>e.indexOf(i)===-1?t.push(i):n.push(i)),n.forEach(i=>i()),qe=t}const yt=new Set;let Fe;function _e(){Fe={r:0,c:[],p:Fe}}function me(){Fe.r||ve(Fe.c),Fe=Fe.p}function V(e,t){e&&e.i&&(yt.delete(e),e.i(t))}function z(e,t,n,i){if(e&&e.o){if(yt.has(e))return;yt.add(e),Fe.c.push(()=>{yt.delete(e),i&&(n&&e.d(1),i())}),e.o(t)}else i&&i()}function Oe(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ye(e){e&&e.c()}function fe(e,t,n){const{fragment:i,after_update:o}=e.$$;i&&i.m(t,n),kt(()=>{const s=e.$$.on_mount.map(ln).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):ve(s),e.$$.on_mount=[]}),o.forEach(kt)}function ce(e,t){const n=e.$$;n.fragment!==null&&(oo(n.after_update),ve(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function so(e,t){e.$$.dirty[0]===-1&&(Qe.push(e),yn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function we(e,t,n,i,o,s,r=null,a=[-1]){const l=it;ot(e);const f=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:o,bound:an(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:an(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};r&&r(f.root);let h=!1;if(f.ctx=n?n(e,t.props||{},(c,d,..._)=>{const g=_.length?_[0]:d;return f.ctx&&o(f.ctx[c],f.ctx[c]=g)&&(!f.skip_bound&&f.bound[c]&&f.bound[c](g),h&&so(e,c)),d}):[],f.update(),h=!0,ve(f.before_update),f.fragment=i?i(f.ctx):!1,t.target){if(t.hydrate){const c=eo(t.target);f.fragment&&f.fragment.l(c),c.forEach(D)}else f.fragment&&f.fragment.c();t.intro&&V(e.$$.fragment),fe(e,t.target,t.anchor),_n()}ot(l)}class Ee{constructor(){ne(this,"$$");ne(this,"$$set")}$destroy(){ce(this,1),this.$destroy=j}$on(t,n){if(!ie(n))return j;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(n),()=>{const o=i.indexOf(n);o!==-1&&i.splice(o,1)}}$set(t){this.$$set&&!Wi(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ro="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ro);var ee=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGLON="MULTIPOLYGON",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(ee||{});const Pt={},rt=(e,t)=>Pt[e]=t,_t=e=>Pt[e.type].area(e),mn=(e,t,n)=>Pt[e.type].intersects(e,t,n),Ne=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),i=Math.max(i,s),o=Math.max(o,r)}),{minX:t,minY:n,maxX:i,maxY:o}},mt=e=>{let t=0,n=e.length-1;for(let i=0;i<e.length;i++)t+=(e[n][0]+e[i][0])*(e[n][1]-e[i][1]),n=i;return Math.abs(.5*t)},wt=(e,t,n)=>{let i=!1;for(let o=0,s=e.length-1;o<e.length;s=o++){const r=e[o][0],a=e[o][1],l=e[s][0],f=e[s][1];a>n!=f>n&&t<(l-r)*(n-a)/(f-a)+r&&(i=!i)}return i},wn=(e,t=!0)=>{let n="M ";return e.forEach(([i,o],s)=>{s===0?n+=`${i},${o}`:n+=` L ${i},${o}`}),t&&(n+=" Z"),n},lo={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:i,cy:o,rx:s,ry:r}=e.geometry,a=0,l=Math.cos(a),f=Math.sin(a),h=t-i,c=n-o,d=l*h+f*c,_=f*h-l*c;return d*d/(s*s)+_*_/(r*r)<=1}};rt(ee.ELLIPSE,lo);const ao={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,i)=>{const[o,...s]=i.rings,r=mt(o.points),a=s.reduce((l,f)=>l+mt(f.points),0);return n+r-a},0)},intersects:(e,t,n)=>{const{polygons:i}=e.geometry;for(const o of i){const[s,...r]=o.rings;if(wt(s.points,t,n)){let a=!1;for(const l of r)if(wt(l.points,t,n)){a=!0;break}if(!a)return!0}}return!1}},En=e=>{const t=e.reduce((n,i)=>[...n,...i.rings[0].points],[]);return Ne(t)},ke=e=>e.rings.map(n=>wn(n.points)).join(" ");rt(ee.MULTIPOLYGLON,ao);const uo={area:e=>{const t=e.geometry.points;return mt(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return wt(i,t,n)}};rt(ee.POLYGON,uo);const bn={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};rt(ee.RECTANGLE,bn);const lt=e=>at(e.target),at=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},Tn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,o=[...n.matchAll(i)][0],[s,r,a,l,f,h,c]=o;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,_,g,p]=[l,f,h,c].map(parseFloat);return{type:ee.RECTANGLE,geometry:{x:d,y:_,w:g,h:p,bounds:{minX:d,minY:t?_-p:_,maxX:d+g,maxY:t?_:_+p}}}},An=e=>{const{x:t,y:n,w:i,h:o}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${i},${o}`}},On="http://www.w3.org/2000/svg",Mn=e=>{const t=i=>{Array.from(i.attributes).forEach(o=>{o.name.startsWith("on")&&i.removeAttribute(o.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(e.querySelectorAll("*")).forEach(t),e},fo=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${On}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},Sn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),i=n.lookupPrefix(On),o=n.lookupNamespaceURI(null);return i||o?Mn(n).firstChild:Mn(fo(n)).firstChild},oe=" ";function co(e){let t="";Array.isArray(e)||(e=[e]);for(let n=0;n<e.length;n++){const i=e[n];if(i.type===T.CLOSE_PATH)t+="z";else if(i.type===T.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===T.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===T.MOVE_TO)t+=(i.relative?"m":"M")+i.x+oe+i.y;else if(i.type===T.LINE_TO)t+=(i.relative?"l":"L")+i.x+oe+i.y;else if(i.type===T.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+oe+i.y1+oe+i.x2+oe+i.y2+oe+i.x+oe+i.y;else if(i.type===T.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+oe+i.y2+oe+i.x+oe+i.y;else if(i.type===T.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+oe+i.y1+oe+i.x+oe+i.y;else if(i.type===T.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+oe+i.y;else if(i.type===T.ARC)t+=(i.relative?"a":"A")+i.rX+oe+i.rY+oe+i.xRot+oe+ +i.lArcFlag+oe+ +i.sweepFlag+oe+i.x+oe+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Ut([e,t],n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function Re(...e){for(let t=0;t<e.length;t++)if(typeof e[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof e[t]} == typeof ${e[t]}`);return!0}const Pe=Math.PI;function Vt(e,t,n){e.lArcFlag=e.lArcFlag===0?0:1,e.sweepFlag=e.sweepFlag===0?0:1;let{rX:i,rY:o}=e;const{x:s,y:r}=e;if(Math.abs(i)<1e-10||Math.abs(o)<1e-10){e.rX=0,e.rY=0,e.cX=(t+s)/2,e.cY=(n+r)/2,e.phi1=0,e.phi2=0;return}i=Math.abs(e.rX),o=Math.abs(e.rY);const a=e.xRot/180*Pe,[l,f]=Ut([(t-s)/2,(n-r)/2],-a),h=Math.pow(l,2)/Math.pow(i,2)+Math.pow(f,2)/Math.pow(o,2);1<h&&(i*=Math.sqrt(h),o*=Math.sqrt(h)),e.rX=i,e.rY=o;const c=Math.pow(i,2)*Math.pow(f,2)+Math.pow(o,2)*Math.pow(l,2),d=(e.lArcFlag!==e.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(o,2)-c)/c)),_=i*f/o*d,g=-o*l/i*d,p=Ut([_,g],a);e.cX=p[0]+(t+s)/2,e.cY=p[1]+(n+r)/2,e.phi1=Math.atan2((f-g)/o,(l-_)/i),e.phi2=Math.atan2((-f-g)/o,(-l-_)/i),e.sweepFlag===0&&e.phi2>e.phi1&&(e.phi2-=2*Pe),e.sweepFlag===1&&e.phi2<e.phi1&&(e.phi2+=2*Pe),e.phi1*=180/Pe,e.phi2*=180/Pe}function vn(e,t,n){Re(e,t,n);const i=e*e+t*t-n*n;if(0>i)return[];if(i===0)return[[e*n/(e*e+t*t),t*n/(e*e+t*t)]];const o=Math.sqrt(i);return[[(e*n+t*o)/(e*e+t*t),(t*n-e*o)/(e*e+t*t)],[(e*n-t*o)/(e*e+t*t),(t*n+e*o)/(e*e+t*t)]]}const ze=Math.PI/180;function Nn(e,t,n){return(1-n)*e+n*t}function Cn(e,t,n,i){return e+Math.cos(i/180*Pe)*t+Math.sin(i/180*Pe)*n}function Rn(e,t,n,i){const s=t-e,r=n-t,a=i-n,l=3*s+3*a-6*r,f=(r-s)*6,h=3*s;return Math.abs(l)<1e-6?Math.abs(f)<1e-6?[]:[-h/f]:ho(f/l,h/l,1e-6)}function In(e,t,n,i,o){const s=1-o,r=s*s*s,a=3*s*s*o,l=3*s*o*o,f=o*o*o;return e*r+t*a+n*l+i*f}function ho(e,t,n=1e-6){const i=e*e/4-t;if(i<-n)return[];if(i<=n)return[-e/2];const o=Math.sqrt(i);return[-(e/2)-o,-(e/2)+o]}function go(e,t,n){e.cX||Vt(e,t,n);const i=e.xRot/180*Pe;if(Math.abs(e.rX)<1e-10||Math.abs(e.rY)<1e-10)return[{relative:e.relative,type:T.CURVE_TO,x1:t+(e.x-t)/3,y1:n+(e.y-n)/3,x2:t+2*(e.x-t)/3,y2:n+2*(e.y-n)/3,x:e.x,y:e.y}];const o=Math.min(e.phi1,e.phi2),s=Math.max(e.phi1,e.phi2),r=s-o,a=Math.ceil(r/90),l=new Array(a);let f=t,h=n;const c=(d,_)=>{const[g,p]=Ut([d*e.rX,_*e.rY],i);return[e.cX+g,e.cY+p]};for(let d=0;d<a;d++){const _=Nn(e.phi1,e.phi2,d/a),g=Nn(e.phi1,e.phi2,(d+1)/a),p=g-_,w=4/3*Math.tan(p*ze/4),y=Math.cos(_*ze)-w*Math.sin(_*ze),A=Math.sin(_*ze)+w*Math.cos(_*ze),E=Math.cos(g*ze),M=Math.sin(g*ze),v=E+w*M,S=M-w*E,N=c(y,A),H=c(v,S),B=c(E,M),X={relative:e.relative,type:T.CURVE_TO,x:B[0],y:B[1],x1:N[0],y1:N[1],x2:H[0],y2:H[1]};e.relative&&(X.x1-=f,X.y1-=h,X.x2-=f,X.y2-=h,X.x-=f,X.y-=h),f=B[0],h=B[1],l[d]=X}return l}function Ht(e,t,n){const i=t[0]-e[0],o=t[1]-e[1],s=n[0]-e[0],r=n[1]-e[1],a=i*r-o*s;if(!(Math.abs(a)<1e-10))return!1;const f=i*s+o*r,h=i*i+o*o,c=s*s+r*r;return 0<=f&&f<=c&&h<=c}function po(e,t=!0){if(e.length<2)return e;const n=se.INFO((s,r,a)=>({...s,x:s.x??r,y:s.y??a,relative:s.relative??!1})),i=[];let o=[];for(const s of e){const r=n(s);r.type===T.MOVE_TO&&o.length>0&&(t?i.push(...Et(o)):i.unshift(...Et(o)),o=[]),o.push(r)}return o.length>0&&(t?i.push(...Et(o)):i.unshift(...Et(o))),i}function Et(e){var o;const t=((o=e[e.length-1])==null?void 0:o.type)===T.CLOSE_PATH,n=t?e.length-2:e.length-1,i=[{type:T.MOVE_TO,relative:!1,x:e[n].x,y:e[n].y}];for(let s=n;s>0;s--){const r=e[s],a=e[s-1];if(r.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(r.type){case T.HORIZ_LINE_TO:i.push({type:T.HORIZ_LINE_TO,relative:!1,x:a.x});break;case T.VERT_LINE_TO:i.push({type:T.VERT_LINE_TO,relative:!1,y:a.y});break;case T.LINE_TO:case T.MOVE_TO:i.push({type:T.LINE_TO,relative:!1,x:a.x,y:a.y});break;case T.CURVE_TO:i.push({type:T.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:r.x2,y1:r.y2,x2:r.x1,y2:r.y1});break;case T.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case T.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case T.ARC:throw new Error("Unsupported command: A (arc)");case T.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:T.CLOSE_PATH}),i}function yo(e=1e13){Re(e);function t(n){return Math.round(n*e)/e}return function(i){return"x1"in i&&typeof i.x1<"u"&&(i.x1=t(i.x1)),"y1"in i&&typeof i.y1<"u"&&(i.y1=t(i.y1)),"x2"in i&&typeof i.x2<"u"&&(i.x2=t(i.x2)),"y2"in i&&typeof i.y2<"u"&&(i.y2=t(i.y2)),"x"in i&&typeof i.x<"u"&&(i.x=t(i.x)),"y"in i&&typeof i.y<"u"&&(i.y=t(i.y)),"rX"in i&&typeof i.rX<"u"&&(i.rX=t(i.rX)),"rY"in i&&typeof i.rY<"u"&&(i.rY=t(i.rY)),i}}function Ln(){return Ie((e,t,n)=>(e.relative&&(typeof e.x1<"u"&&(e.x1+=t),typeof e.y1<"u"&&(e.y1+=n),typeof e.x2<"u"&&(e.x2+=t),typeof e.y2<"u"&&(e.y2+=n),typeof e.x<"u"&&(e.x+=t),typeof e.y<"u"&&(e.y+=n),e.relative=!1),e))}function _o(){return Ie((e,t,n)=>(e.relative||(typeof e.x1<"u"&&(e.x1-=t),typeof e.y1<"u"&&(e.y1-=n),typeof e.x2<"u"&&(e.x2-=t),typeof e.y2<"u"&&(e.y2-=n),typeof e.x<"u"&&(e.x-=t),typeof e.y<"u"&&(e.y-=n),e.relative=!0),e))}function mo(e=!0,t=!0,n=!0,i=!0){return Ie((o,s,r,a,l)=>{if(isNaN(a)&&!(o.type&T.MOVE_TO))throw new Error("path must start with moveto");if(t&&o.type&T.HORIZ_LINE_TO&&(o.type=T.LINE_TO,o.y=o.relative?0:r),n&&o.type&T.VERT_LINE_TO&&(o.type=T.LINE_TO,o.x=o.relative?0:s),e&&o.type&T.CLOSE_PATH&&(o.type=T.LINE_TO,o.x=o.relative?a-s:a,o.y=o.relative?l-r:l),o.type&T.ARC&&(o.rX===0||o.rY===0)&&(o.type=T.LINE_TO,delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag),i&&o.type&T.QUAD_TO){const f=[s,r],h=o.relative?[s+o.x1,r+o.y1]:[o.x1,o.y1],c=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Ht(f,h,c)&&(o.type=T.LINE_TO,delete o.x1,delete o.y1)}if(i&&o.type&T.CURVE_TO){const f=[s,r],h=o.relative?[s+o.x1,r+o.y1]:[o.x1,o.y1],c=o.relative?[s+o.x2,r+o.y2]:[o.x2,o.y2],d=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Ht(f,h,d)&&Ht(f,c,d)&&(o.type=T.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function kn(){let e=NaN,t=NaN,n=NaN,i=NaN;return Ie((o,s,r)=>(o.type&T.SMOOTH_CURVE_TO&&(o.type=T.CURVE_TO,e=isNaN(e)?s:e,t=isNaN(t)?r:t,o.x1=o.relative?s-e:2*s-e,o.y1=o.relative?r-t:2*r-t),o.type&T.CURVE_TO?(e=o.relative?s+o.x2:o.x2,t=o.relative?r+o.y2:o.y2):(e=NaN,t=NaN),o.type&T.SMOOTH_QUAD_TO&&(o.type=T.QUAD_TO,n=isNaN(n)?s:n,i=isNaN(i)?r:i,o.x1=o.relative?s-n:2*s-n,o.y1=o.relative?r-i:2*r-i),o.type&T.QUAD_TO?(n=o.relative?s+o.x1:o.x1,i=o.relative?r+o.y1:o.y1):(n=NaN,i=NaN),o))}function Dn(){let e=NaN,t=NaN;return Ie((n,i,o)=>{if(n.type&T.SMOOTH_QUAD_TO&&(n.type=T.QUAD_TO,e=isNaN(e)?i:e,t=isNaN(t)?o:t,n.x1=n.relative?i-e:2*i-e,n.y1=n.relative?o-t:2*o-t),n.type&T.QUAD_TO){e=n.relative?i+n.x1:n.x1,t=n.relative?o+n.y1:n.y1;const s=n.x1,r=n.y1;n.type=T.CURVE_TO,n.x1=((n.relative?0:i)+s*2)/3,n.y1=((n.relative?0:o)+r*2)/3,n.x2=(n.x+s*2)/3,n.y2=(n.y+r*2)/3}else e=NaN,t=NaN;return n})}function Ie(e){let t=0,n=0,i=NaN,o=NaN;return function(r){if(isNaN(i)&&!(r.type&T.MOVE_TO))throw new Error("path must start with moveto");const a=e(r,t,n,i,o);return r.type&T.CLOSE_PATH&&(t=i,n=o),"x"in r&&typeof r.x<"u"&&(t=r.relative?t+r.x:r.x),"y"in r&&typeof r.y<"u"&&(n=r.relative?n+r.y:r.y),r.type&T.MOVE_TO&&(i=t,o=n),a}}function wo(e=0){Re(e);let t=NaN,n=NaN,i=NaN,o=NaN;return Ie((s,r,a,l,f)=>{const h=Math.abs;let c=!1,d=0,_=0;if(s.type&T.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:r-t,_=isNaN(n)?0:a-n),s.type&(T.CURVE_TO|T.SMOOTH_CURVE_TO)?(t=s.relative?r+s.x2:s.x2,n=s.relative?a+s.y2:s.y2):(t=NaN,n=NaN),s.type&T.SMOOTH_QUAD_TO?(i=isNaN(i)?r:2*r-i,o=isNaN(o)?a:2*a-o):s.type&T.QUAD_TO?(i=s.relative?r+s.x1:s.x1,o=s.relative?a+s.y1:s.y2):(i=NaN,o=NaN),s.type&T.LINE_COMMANDS||s.type&T.ARC&&(s.rX===0||s.rY===0||!s.lArcFlag)||s.type&T.CURVE_TO||s.type&T.SMOOTH_CURVE_TO||s.type&T.QUAD_TO||s.type&T.SMOOTH_QUAD_TO){const g=typeof s.x>"u"?0:s.relative?s.x:s.x-r,p=typeof s.y>"u"?0:s.relative?s.y:s.y-a;d=isNaN(i)?typeof s.x1>"u"?d:s.relative?s.x:s.x1-r:i-r,_=isNaN(o)?typeof s.y1>"u"?_:s.relative?s.y:s.y1-a:o-a;const w=typeof s.x2>"u"?0:s.relative?s.x:s.x2-r,y=typeof s.y2>"u"?0:s.relative?s.y:s.y2-a;h(g)<=e&&h(p)<=e&&h(d)<=e&&h(_)<=e&&h(w)<=e&&h(y)<=e&&(c=!0)}return s.type&T.CLOSE_PATH&&h(r-l)<=e&&h(a-f)<=e&&(c=!0),c?[]:s})}function Ue(e,t,n,i,o,s){return Re(e,t,n,i,o,s),Ie((r,a,l,f)=>{const h=r.x1,c=r.x2,d=r.relative&&!isNaN(f),_=typeof r.x<"u"?r.x:d?0:a,g=typeof r.y<"u"?r.y:d?0:l;r.type&T.HORIZ_LINE_TO&&t!==0&&(r.type=T.LINE_TO,r.y=r.relative?0:l),r.type&T.VERT_LINE_TO&&n!==0&&(r.type=T.LINE_TO,r.x=r.relative?0:a),typeof r.x<"u"&&(r.x=r.x*e+g*n+(d?0:o)),typeof r.y<"u"&&(r.y=_*t+r.y*i+(d?0:s)),typeof r.x1<"u"&&(r.x1=r.x1*e+r.y1*n+(d?0:o)),typeof r.y1<"u"&&(r.y1=h*t+r.y1*i+(d?0:s)),typeof r.x2<"u"&&(r.x2=r.x2*e+r.y2*n+(d?0:o)),typeof r.y2<"u"&&(r.y2=c*t+r.y2*i+(d?0:s));function p(y){return y*y}const w=e*i-t*n;if(typeof r.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(w===0)delete r.rX,delete r.rY,delete r.xRot,delete r.lArcFlag,delete r.sweepFlag,r.type=T.LINE_TO;else{const y=r.xRot*Math.PI/180,A=Math.sin(y),E=Math.cos(y),M=1/p(r.rX),v=1/p(r.rY),S=p(E)*M+p(A)*v,N=2*A*E*(M-v),H=p(A)*M+p(E)*v,B=S*i*i-N*t*i+H*t*t,X=N*(e*i+t*n)-2*(S*n*i+H*e*t),G=S*n*n-N*e*n+H*e*e,m=(Math.atan2(X,B-G)+Math.PI)%Math.PI/2,b=Math.sin(m),O=Math.cos(m);r.rX=Math.abs(w)/Math.sqrt(B*p(O)+X*b*O+G*p(b)),r.rY=Math.abs(w)/Math.sqrt(B*p(b)-X*b*O+G*p(O)),r.xRot=m*180/Math.PI}return typeof r.sweepFlag<"u"&&0>w&&(r.sweepFlag=+!r.sweepFlag),r})}function Eo(e,t=0,n=0){Re(e,t,n);const i=Math.sin(e),o=Math.cos(e);return Ue(o,i,-i,o,t-t*o+n*i,n-t*i-n*o)}function bo(e,t=0){return Re(e,t),Ue(1,0,0,1,e,t)}function To(e,t=e){return Re(e,t),Ue(e,0,0,t,0,0)}function Ao(e){return Re(e),Ue(1,0,Math.tan(e),1,0,0)}function Oo(e){return Re(e),Ue(1,Math.tan(e),0,1,0,0)}function Mo(e=0){return Re(e),Ue(-1,0,0,1,e,0)}function So(e=0){return Re(e),Ue(1,0,0,-1,0,e)}function vo(){return Ie((e,t,n)=>T.ARC===e.type?go(e,e.relative?0:t,e.relative?0:n):e)}function No(){return Ie((e,t,n)=>(e.relative&&(t=0,n=0),T.ARC===e.type&&Vt(e,t,n),e))}function Pn(){return e=>({...e})}function Co(){const e=Pn(),t=Ln(),n=Dn(),i=kn(),o=Ie((s,r,a)=>{const l=i(n(t(e(s))));function f(c){c>o.maxX&&(o.maxX=c),c<o.minX&&(o.minX=c)}function h(c){c>o.maxY&&(o.maxY=c),c<o.minY&&(o.minY=c)}if(l.type&T.DRAWING_COMMANDS&&(f(r),h(a)),l.type&T.HORIZ_LINE_TO&&f(l.x),l.type&T.VERT_LINE_TO&&h(l.y),l.type&T.LINE_TO&&(f(l.x),h(l.y)),l.type&T.CURVE_TO){f(l.x),h(l.y);const c=Rn(r,l.x1,l.x2,l.x);for(const _ of c)0<_&&1>_&&f(In(r,l.x1,l.x2,l.x,_));const d=Rn(a,l.y1,l.y2,l.y);for(const _ of d)0<_&&1>_&&h(In(a,l.y1,l.y2,l.y,_))}if(l.type&T.ARC){f(l.x),h(l.y),Vt(l,r,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,_=Math.sin(c)*l.rX,g=-Math.sin(c)*l.rY,p=Math.cos(c)*l.rY,[w,y]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],A=([v,S])=>{const H=Math.atan2(S,v)*180/Math.PI;return H<w?H+360:H},E=vn(g,-d,0).map(A);for(const v of E)v>w&&v<y&&f(Cn(l.cX,d,g,v));const M=vn(p,-_,0).map(A);for(const v of M)v>w&&v<y&&h(Cn(l.cY,_,p,v))}return s});return o.minX=1/0,o.maxX=-1/0,o.minY=1/0,o.maxY=-1/0,o}const se={ROUND:yo,TO_ABS:Ln,TO_REL:_o,NORMALIZE_HVZ:mo,NORMALIZE_ST:kn,QT_TO_C:Dn,INFO:Ie,SANITIZE:wo,MATRIX:Ue,ROTATE:Eo,TRANSLATE:bo,SCALE:To,SKEW_X:Ao,SKEW_Y:Oo,X_AXIS_SYMMETRY:Mo,Y_AXIS_SYMMETRY:So,A_TO_C:vo,ANNOTATE_ARCS:No,CLONE:Pn,CALCULATE_BOUNDS:Co,REVERSE_PATH:po};class Un{round(t){return this.transform(se.ROUND(t))}toAbs(){return this.transform(se.TO_ABS())}toRel(){return this.transform(se.TO_REL())}normalizeHVZ(t,n,i){return this.transform(se.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(se.NORMALIZE_ST())}qtToC(){return this.transform(se.QT_TO_C())}aToC(){return this.transform(se.A_TO_C())}sanitize(t){return this.transform(se.SANITIZE(t))}translate(t,n){return this.transform(se.TRANSLATE(t,n))}scale(t,n){return this.transform(se.SCALE(t,n))}rotate(t,n,i){return this.transform(se.ROTATE(t,n,i))}matrix(t,n,i,o,s,r){return this.transform(se.MATRIX(t,n,i,o,s,r))}skewX(t){return this.transform(se.SKEW_X(t))}skewY(t){return this.transform(se.SKEW_Y(t))}xSymmetry(t){return this.transform(se.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(se.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(se.ANNOTATE_ARCS())}}const Ro=e=>e===" "||e===" "||e==="\r"||e===`
|
|
2
|
-
`,Vn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class Io extends Un{constructor(){super();ne(this,"curNumber","");ne(this,"curCommandType",-1);ne(this,"curCommandRelative",!1);ne(this,"canParseCommandOrComma",!0);ne(this,"curNumberHasExp",!1);ne(this,"curNumberHasExpDigits",!1);ne(this,"curNumberHasDecimal",!1);ne(this,"curArgs",[])}finish(n=[]){if(this.parse(" ",n),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return n}parse(n,i=[]){const o=s=>{i.push(s),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let s=0;s<n.length;s++){const r=n[s],a=this.curCommandType===T.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),l=Vn(r)&&(this.curNumber==="0"&&r==="0"||a);if(Vn(r)&&!l){this.curNumber+=r,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(r==="e"||r==="E"){this.curNumber+=r,this.curNumberHasExp=!0;continue}if((r==="-"||r==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=r;continue}if(r==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!a){this.curNumber+=r,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const f=Number(this.curNumber);if(isNaN(f))throw new SyntaxError(`Invalid number ending at ${s}`);if(this.curCommandType===T.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>f)throw new SyntaxError(`Expected positive number, got "${f}" at index "${s}"`)}else if((this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber!=="0"&&this.curNumber!=="1")throw new SyntaxError(`Expected a flag, got "${this.curNumber}" at index "${s}"`)}this.curArgs.push(f),this.curArgs.length===Lo[this.curCommandType]&&(T.HORIZ_LINE_TO===this.curCommandType?o({type:T.HORIZ_LINE_TO,relative:this.curCommandRelative,x:f}):T.VERT_LINE_TO===this.curCommandType?o({type:T.VERT_LINE_TO,relative:this.curCommandRelative,y:f}):this.curCommandType===T.MOVE_TO||this.curCommandType===T.LINE_TO||this.curCommandType===T.SMOOTH_QUAD_TO?(o({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),T.MOVE_TO===this.curCommandType&&(this.curCommandType=T.LINE_TO)):this.curCommandType===T.CURVE_TO?o({type:T.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===T.SMOOTH_CURVE_TO?o({type:T.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===T.QUAD_TO?o({type:T.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===T.ARC&&o({type:T.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!Ro(r)){if(r===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(r==="+"||r==="-"||r==="."){this.curNumber=r,this.curNumberHasDecimal=r===".";continue}if(l){this.curNumber=r,this.curNumberHasDecimal=!1;continue}if(this.curArgs.length!==0)throw new SyntaxError(`Unterminated command at index ${s}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${r}" at index ${s}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,r==="z"||r==="Z"){i.push({type:T.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(r==="h"||r==="H")this.curCommandType=T.HORIZ_LINE_TO,this.curCommandRelative=r==="h";else if(r==="v"||r==="V")this.curCommandType=T.VERT_LINE_TO,this.curCommandRelative=r==="v";else if(r==="m"||r==="M")this.curCommandType=T.MOVE_TO,this.curCommandRelative=r==="m";else if(r==="l"||r==="L")this.curCommandType=T.LINE_TO,this.curCommandRelative=r==="l";else if(r==="c"||r==="C")this.curCommandType=T.CURVE_TO,this.curCommandRelative=r==="c";else if(r==="s"||r==="S")this.curCommandType=T.SMOOTH_CURVE_TO,this.curCommandRelative=r==="s";else if(r==="q"||r==="Q")this.curCommandType=T.QUAD_TO,this.curCommandRelative=r==="q";else if(r==="t"||r==="T")this.curCommandType=T.SMOOTH_QUAD_TO,this.curCommandRelative=r==="t";else if(r==="a"||r==="A")this.curCommandType=T.ARC,this.curCommandRelative=r==="a";else throw new SyntaxError(`Unexpected character "${r}" at index ${s}.`)}}return i}transform(n){return Object.create(this,{parse:{value(o,s=[]){const r=Object.getPrototypeOf(this).parse.call(this,o);for(const a of r){const l=n(a);Array.isArray(l)?s.push(...l):s.push(l)}return s}}})}}const $=class $ extends Un{constructor(n){super();ne(this,"commands");typeof n=="string"?this.commands=$.parse(n):this.commands=n}encode(){return $.encode(this.commands)}getBounds(){const n=se.CALCULATE_BOUNDS();return this.transform(n),n}transform(n){const i=[];for(const o of this.commands){const s=n(o);Array.isArray(s)?i.push(...s):i.push(s)}return this.commands=i,this}reverse(n=!0){return this.commands=se.REVERSE_PATH(this.commands,n),this}static encode(n){return co(n)}static parse(n){const i=new Io,o=[];return i.parse(n,o),i.finish(o),o}};ne($,"CLOSE_PATH",1),ne($,"MOVE_TO",2),ne($,"HORIZ_LINE_TO",4),ne($,"VERT_LINE_TO",8),ne($,"LINE_TO",16),ne($,"CURVE_TO",32),ne($,"SMOOTH_CURVE_TO",64),ne($,"QUAD_TO",128),ne($,"SMOOTH_QUAD_TO",256),ne($,"ARC",512),ne($,"LINE_COMMANDS",$.LINE_TO|$.HORIZ_LINE_TO|$.VERT_LINE_TO),ne($,"DRAWING_COMMANDS",$.HORIZ_LINE_TO|$.VERT_LINE_TO|$.LINE_TO|$.CURVE_TO|$.SMOOTH_CURVE_TO|$.QUAD_TO|$.SMOOTH_QUAD_TO|$.ARC);let T=$;const Lo={[T.MOVE_TO]:2,[T.LINE_TO]:2,[T.HORIZ_LINE_TO]:1,[T.VERT_LINE_TO]:1,[T.CLOSE_PATH]:0,[T.QUAD_TO]:4,[T.SMOOTH_QUAD_TO]:2,[T.CURVE_TO]:6,[T.SMOOTH_CURVE_TO]:4,[T.ARC]:7},ko=e=>{const t=new T(e).toAbs().commands,n=[];let i=[],o=null;for(const s of t)switch(s.type){case T.MOVE_TO:i.length>0&&(n.push({points:i}),i=[]),o=[s.x,s.y],i.push(o);break;case T.LINE_TO:i.push([s.x,s.y]);break;case T.HORIZ_LINE_TO:const r=i[i.length-1][1];i.push([s.x,r]);break;case T.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,s.y]);break;case T.CURVE_TO:case T.SMOOTH_CURVE_TO:case T.QUAD_TO:case T.SMOOTH_QUAD_TO:case T.ARC:i.push([s.x,s.y]);break}if(i.length>2&&n.push({points:i}),n.length>0){const s=Ne(n[0].points);return{rings:n,bounds:s}}},Do=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:ee.POLYGON,geometry:{points:o,bounds:Ne(o)}}},Po=e=>{const t=Sn(e),n=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),o=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-o,minY:i-s,maxX:n+o,maxY:i+s};return{type:ee.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:s,bounds:r}}},Uo=e=>{const t=Sn(e),o=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(l=>l.getAttribute("d")||"").map(l=>ko(l)).filter(Boolean),s=o.reduce((l,f)=>[...l,...f.rings[0].points],[]),r=Ne(s);return o.length===1&&o[0].rings.length===1?{type:ee.POLYGON,geometry:{points:s,bounds:r}}:{type:ee.MULTIPOLYGLON,geometry:{polygons:o,bounds:r}}},Hn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Do(t);if(t.includes("<path "))return Uo(t);if(t.includes("<ellipse "))return Po(t);throw"Unsupported SVG shape: "+t},Vo=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${ke(n)}" />`).join("")}</g>`,Bn=e=>{let t;if(e.type===ee.POLYGON){const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`}else if(e.type===ee.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}else if(e.type===ee.MULTIPOLYGLON){const n=e.geometry;t=`<svg>${Vo(n)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},he=[];for(let e=0;e<256;++e)he.push((e+256).toString(16).slice(1));function Ho(e,t=0){return(he[e[t+0]]+he[e[t+1]]+he[e[t+2]]+he[e[t+3]]+"-"+he[e[t+4]]+he[e[t+5]]+"-"+he[e[t+6]]+he[e[t+7]]+"-"+he[e[t+8]]+he[e[t+9]]+"-"+he[e[t+10]]+he[e[t+11]]+he[e[t+12]]+he[e[t+13]]+he[e[t+14]]+he[e[t+15]]).toLowerCase()}let Bt;const Bo=new Uint8Array(16);function Yo(){if(!Bt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Bt=crypto.getRandomValues.bind(crypto)}return Bt(Bo)}const Yn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Xn(e,t,n){var o;if(Yn.randomUUID&&!e)return Yn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Yo();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,Ho(i)}var Fn=Object.prototype.hasOwnProperty;function Ve(e,t){var n,i;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((i=e.length)===t.length)for(;i--&&Ve(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(Fn.call(e,n)&&++i&&!Fn.call(t,n)||!(n in t)||!Ve(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}function Yt(){}function Xo(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const We=[];function Xt(e,t=Yt){let n;const i=new Set;function o(a){if(Xo(e,a)&&(e=a,n)){const l=!We.length;for(const f of i)f[1](),We.push(f,e);if(l){for(let f=0;f<We.length;f+=2)We[f][0](We[f+1]);We.length=0}}}function s(a){o(a(e))}function r(a,l=Yt){const f=[a,l];return i.add(f),i.size===1&&(n=t(o,s)||Yt),a(e),()=>{i.delete(f),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const Fo=e=>{const{subscribe:t,set:n}=Xt();let i;return t(o=>i=o),e.observe(({changes:o})=>{if(i){(o.deleted||[]).some(r=>r.id===i)&&n(void 0);const s=(o.updated||[]).find(({oldValue:r})=>r.id===i);s&&n(s.newValue.id)}}),{get current(){return i},subscribe:t,set:n}};var Ft=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Ft||{});const bt={selected:[]},zo=(e,t,n)=>{const{subscribe:i,set:o}=Xt(bt);let s=t,r=bt;i(g=>r=g);const a=()=>{Ve(r,bt)||o(bt)},l=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},f=g=>{if(l())return!1;const p=typeof g=="string"?g:g.id;return r.selected.some(w=>w.id===p)},h=(g,p)=>{let w;if(Array.isArray(g)){if(w=g.map(A=>e.getAnnotation(A)).filter(Boolean),w.length<g.length){console.warn("Invalid selection: "+g.filter(A=>!w.some(E=>E.id===A)));return}}else{const A=e.getAnnotation(g);if(!A){console.warn("Invalid selection: "+g);return}w=[A]}const y=w.reduce((A,E)=>{const M=zn(E,s,n);return M==="EDIT"?[...A,{id:E.id,editable:!0}]:M==="SELECT"?[...A,{id:E.id}]:A},[]);o({selected:y,event:p})},c=(g,p)=>{const w=Array.isArray(g)?g:[g],y=w.map(A=>e.getAnnotation(A)).filter(A=>!!A);o({selected:y.map(A=>{const E=p===void 0?zn(A,s,n)==="EDIT":p;return{id:A.id,editable:E}})}),y.length!==w.length&&console.warn("Invalid selection",g)},d=g=>{if(l())return!1;const{selected:p}=r;p.some(({id:w})=>g.includes(w))&&o({selected:p.filter(({id:w})=>!g.includes(w))})},_=g=>{s=g,c(r.selected.map(({id:p})=>p))};return e.observe(({changes:g})=>d((g.deleted||[]).map(p=>p.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:a,isEmpty:l,isSelected:f,setSelected:c,setUserSelectAction:_,subscribe:i,userSelect:h}},zn=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},de=[];for(let e=0;e<256;++e)de.push((e+256).toString(16).slice(1));function Go(e,t=0){return(de[e[t+0]]+de[e[t+1]]+de[e[t+2]]+de[e[t+3]]+"-"+de[e[t+4]]+de[e[t+5]]+"-"+de[e[t+6]]+de[e[t+7]]+"-"+de[e[t+8]]+de[e[t+9]]+"-"+de[e[t+10]]+de[e[t+11]]+de[e[t+12]]+de[e[t+13]]+de[e[t+14]]+de[e[t+15]]).toLowerCase()}let zt;const jo=new Uint8Array(16);function Qo(){if(!zt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");zt=crypto.getRandomValues.bind(crypto)}return zt(jo)}const qo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Gn={randomUUID:qo};function jn(e,t,n){var i;if(Gn.randomUUID&&!e)return Gn.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Qo();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,Go(o)}const Gt=e=>{const t=n=>{const i={...n};return n.created&&typeof n.created=="string"&&(i.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(i.updated=new Date(n.updated)),i};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Zo=(e,t,n,i)=>({id:jn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),Wo=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},Ko=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},Jo=(e,t)=>t.bodies.map(n=>{const i=e.bodies.find(o=>o.id===n.id);return{newBody:n,oldBody:i&&!Ve(i,n)?i:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:i})=>({oldBody:n,newBody:i})),xo=(e,t)=>!Ve(e.target,t.target),Qn=(e,t)=>{const n=Wo(e,t),i=Ko(e,t),o=Jo(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:o.length>0?o:void 0,targetUpdated:xo(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var te=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(te||{});const $o=(e,t)=>{var n,i;const{changes:o,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>l&&l.length>0;if(!(a(o.created)||a(o.deleted))){const l=(n=o.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),f=(i=o.updated)==null?void 0:i.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!f||r==="TARGET_ONLY"&&f&&!l)return!1}}if(e.options.annotations){const r=new Set([...(o.created||[]).map(a=>a.id),...(o.deleted||[]).map(a=>a.id),...(o.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},es=(e,t)=>{const n=new Set((e.created||[]).map(c=>c.id)),i=new Set((e.updated||[]).map(({newValue:c})=>c.id)),o=new Set((t.created||[]).map(c=>c.id)),s=new Set((t.deleted||[]).map(c=>c.id)),r=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>n.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(e.created||[]).filter(c=>!s.has(c.id)).map(c=>r.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],f=[...(e.deleted||[]).filter(c=>!o.has(c.id)),...(t.deleted||[]).filter(c=>!n.has(c.id))],h=[...(e.updated||[]).filter(({newValue:c})=>!s.has(c.id)).map(c=>{const{oldValue:d,newValue:_}=c;if(r.has(_.id)){const g=t.updated.find(p=>p.oldValue.id===_.id).newValue;return Qn(d,g)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:f,updated:h}},Tt=e=>{const t=e.id===void 0?jn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},ts=e=>e.id!==void 0,ns=()=>{const e=new Map,t=new Map,n=[],i=(m,b={})=>{n.push({onChange:m,options:b})},o=m=>{const b=n.findIndex(O=>O.onChange==m);b>-1&&n.splice(b,1)},s=(m,b)=>{const O={origin:m,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(C=>{$o(C,O)&&C.onChange(O)})},r=(m,b=te.LOCAL)=>{if(m.id&&e.get(m.id))throw Error(`Cannot add annotation ${m.id} - exists already`);{const O=Tt(m);e.set(O.id,O),O.bodies.forEach(C=>t.set(C.id,O.id)),s(b,{created:[O]})}},a=(m,b)=>{const O=Tt(typeof m=="string"?b:m),C=typeof m=="string"?m:m.id,R=C&&e.get(C);if(R){const L=Qn(R,O);return C===O.id?e.set(C,O):(e.delete(C),e.set(O.id,O)),R.bodies.forEach(Y=>t.delete(Y.id)),O.bodies.forEach(Y=>t.set(Y.id,O.id)),L}else console.warn(`Cannot update annotation ${C} - does not exist`)},l=(m,b=te.LOCAL,O=te.LOCAL)=>{const C=ts(b)?O:b,R=a(m,b);R&&s(C,{updated:[R]})},f=(m,b=te.LOCAL)=>{e.get(m.id)?l(m,b):r(m,b)},h=(m,b=te.LOCAL)=>{const O=m.reduce((C,R)=>{const L=a(R);return L?[...C,L]:C},[]);O.length>0&&s(b,{updated:O})},c=(m,b=te.LOCAL)=>{const O=m.map(Tt),{toAdd:C,toUpdate:R}=O.reduce((Y,Q)=>e.get(Q.id)?{...Y,toUpdate:[...Y.toUpdate,Q]}:{...Y,toAdd:[...Y.toAdd,Q]},{toAdd:[],toUpdate:[]}),L=R.map(Y=>a(Y,b)).filter(Boolean);C.forEach(Y=>{e.set(Y.id,Y),Y.bodies.forEach(Q=>t.set(Q.id,Y.id))}),s(b,{created:C,updated:L})},d=(m,b=te.LOCAL)=>{const O=e.get(m.annotation);if(O){const C={...O,bodies:[...O.bodies,m]};e.set(O.id,C),t.set(m.id,C.id),s(b,{updated:[{oldValue:O,newValue:C,bodiesCreated:[m]}]})}else console.warn(`Attempt to add body to missing annotation: ${m.annotation}`)},_=()=>[...e.values()],g=(m=te.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(m,{deleted:b})},p=(m,b=!0,O=te.LOCAL)=>{const C=m.map(Tt);if(b){const R=[...e.values()];e.clear(),t.clear(),C.forEach(L=>{e.set(L.id,L),L.bodies.forEach(Y=>t.set(Y.id,L.id))}),s(O,{created:C,deleted:R})}else{const R=m.reduce((L,Y)=>{const Q=Y.id&&e.get(Y.id);return Q?[...L,Q]:L},[]);if(R.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${R.map(L=>L.id).join(", ")}`);C.forEach(L=>{e.set(L.id,L),L.bodies.forEach(Y=>t.set(Y.id,L.id))}),s(O,{created:C})}},w=m=>{const b=typeof m=="string"?m:m.id,O=e.get(b);if(O)return e.delete(b),O.bodies.forEach(C=>t.delete(C.id)),O;console.warn(`Attempt to delete missing annotation: ${b}`)},y=(m,b=te.LOCAL)=>{const O=w(m);O&&s(b,{deleted:[O]})},A=(m,b=te.LOCAL)=>{const O=m.reduce((C,R)=>{const L=w(R);return L?[...C,L]:C},[]);O.length>0&&s(b,{deleted:O})},E=m=>{const b=e.get(m.annotation);if(b){const O=b.bodies.find(C=>C.id===m.id);if(O){t.delete(O.id);const C={...b,bodies:b.bodies.filter(R=>R.id!==m.id)};return e.set(b.id,C),{oldValue:b,newValue:C,bodiesDeleted:[O]}}else console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${m.annotation}`)},M=(m,b=te.LOCAL)=>{const O=E(m);O&&s(b,{updated:[O]})},v=(m,b=te.LOCAL)=>{const O=m.map(C=>E(C)).filter(Boolean);O.length>0&&s(b,{updated:O})},S=m=>{const b=e.get(m);return b?{...b}:void 0},N=m=>{const b=t.get(m);if(b){const O=S(b).bodies.find(C=>C.id===m);if(O)return O;console.error(`Store integrity error: body ${m} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${m}`)},H=(m,b)=>{if(m.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const O=e.get(m.annotation);if(O){const C=O.bodies.find(L=>L.id===m.id),R={...O,bodies:O.bodies.map(L=>L.id===C.id?b:L)};return e.set(O.id,R),C.id!==b.id&&(t.delete(C.id),t.set(b.id,R.id)),{oldValue:O,newValue:R,bodiesUpdated:[{oldBody:C,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${m.annotation}`)},B=(m,b,O=te.LOCAL)=>{const C=H(m,b);C&&s(O,{updated:[C]})},X=(m,b=te.LOCAL)=>{const O=m.map(C=>H({id:C.id,annotation:C.annotation},C)).filter(Boolean);s(b,{updated:O})},G=m=>{const b=e.get(m.annotation);if(b){const O={...b,target:{...b.target,...m}};return e.set(b.id,O),{oldValue:b,newValue:O,targetUpdated:{oldTarget:b.target,newTarget:m}}}else console.warn(`Attempt to update target on missing annotation: ${m.annotation}`)};return{addAnnotation:r,addBody:d,all:_,bulkAddAnnotations:p,bulkDeleteAnnotations:A,bulkDeleteBodies:v,bulkUpdateAnnotations:h,bulkUpdateBodies:X,bulkUpdateTargets:(m,b=te.LOCAL)=>{const O=m.map(C=>G(C)).filter(Boolean);O.length>0&&s(b,{updated:O})},bulkUpsertAnnotations:c,clear:g,deleteAnnotation:y,deleteBody:M,getAnnotation:S,getBody:N,observe:i,unobserve:o,updateAnnotation:l,updateBody:B,updateTarget:(m,b=te.LOCAL)=>{const O=G(m);O&&s(b,{updated:[O]})},upsertAnnotation:f}},is=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let os=()=>({emit(e,...t){for(let n=this.events[e]||[],i=0,o=n.length;i<o;i++)n[i](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var i;this.events[e]=(i=this.events[e])==null?void 0:i.filter(o=>t!==o)}}});const ss=250,rs=(e,t)=>{const n=os(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,s=!1,r=0;const a=g=>{if(!s){const{changes:p}=g,w=performance.now();if(w-r>ss)i.splice(o+1),i.push(p),o=i.length-1;else{const y=i.length-1;i[y]=es(i[y],p)}r=w}s=!1};e.observe(a,{origin:te.LOCAL});const l=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g),f=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),h=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({oldValue:p})=>p)),c=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({newValue:p})=>p)),d=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),_=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g);return{canRedo:()=>i.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...i],pointer:o}),on:(g,p)=>n.on(g,p),redo:()=>{if(i.length-1>o){s=!0;const{created:g,updated:p,deleted:w}=i[o+1];f(g),c(p),_(w),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){s=!0;const{created:g,updated:p,deleted:w}=i[o];l(g),h(p),d(w),n.emit("undo",i[o]),o-=1}}}},ls=()=>{const{subscribe:e,set:t}=Xt([]);return{subscribe:e,set:t}},as=(e,t,n,i)=>{const{hover:o,selection:s,store:r,viewport:a}=e,l=new Map;let f=[],h,c;const d=(y,A)=>{l.has(y)?l.get(y).push(A):l.set(y,[A])},_=(y,A)=>{const E=l.get(y);if(E){const M=E.indexOf(A);M!==-1&&E.splice(M,1)}},g=(y,A,E)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(M=>{if(n){const v=Array.isArray(A)?A.map(N=>n.serialize(N)):n.serialize(A),S=E?E instanceof PointerEvent?E:n.serialize(E):void 0;M(v,S)}else M(A,E)})},1)},p=()=>{const{selected:y}=s,A=(y||[]).map(({id:E})=>r.getAnnotation(E));A.forEach(E=>{const M=f.find(v=>v.id===E.id);(!M||!Ve(M,E))&&g("updateAnnotation",E,M)}),f=f.map(E=>A.find(({id:v})=>v===E.id)||E)};s.subscribe(({selected:y})=>{if(!(f.length===0&&y.length===0)){if(f.length===0&&y.length>0)f=y.map(({id:A})=>r.getAnnotation(A));else if(f.length>0&&y.length===0)f.forEach(A=>{const E=r.getAnnotation(A.id);E&&!Ve(E,A)&&g("updateAnnotation",E,A)}),f=[];else{const A=new Set(f.map(M=>M.id)),E=new Set(y.map(({id:M})=>M));f.filter(M=>!E.has(M.id)).forEach(M=>{const v=r.getAnnotation(M.id);v&&!Ve(v,M)&&g("updateAnnotation",v,M)}),f=[...f.filter(M=>E.has(M.id)),...y.filter(({id:M})=>!A.has(M)).map(({id:M})=>r.getAnnotation(M))]}g("selectionChanged",f)}}),o.subscribe(y=>{!h&&y?g("mouseEnterAnnotation",r.getAnnotation(y)):h&&!y?g("mouseLeaveAnnotation",r.getAnnotation(h)):h&&y&&(g("mouseLeaveAnnotation",r.getAnnotation(h)),g("mouseEnterAnnotation",r.getAnnotation(y))),h=y}),a==null||a.subscribe(y=>g("viewportIntersect",y.map(A=>r.getAnnotation(A)))),r.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(p,1e3));const{created:A,deleted:E}=y.changes;(A||[]).forEach(M=>g("createAnnotation",M)),(E||[]).forEach(M=>g("deleteAnnotation",M)),(y.changes.updated||[]).filter(M=>[...M.bodiesCreated||[],...M.bodiesDeleted||[],...M.bodiesUpdated||[]].length>0).forEach(({oldValue:M,newValue:v})=>{const S=f.find(N=>N.id===M.id)||M;f=f.map(N=>N.id===M.id?v:N),g("updateAnnotation",v,S)})},{origin:te.LOCAL}),r.observe(y=>{if(f){const A=new Set(f.map(M=>M.id)),E=(y.changes.updated||[]).filter(({newValue:M})=>A.has(M.id)).map(({newValue:M})=>M);E.length>0&&(f=f.map(M=>E.find(S=>S.id===M.id)||M))}},{origin:te.REMOTE});const w=y=>A=>{const{updated:E}=A;y?(E||[]).forEach(M=>g("updateAnnotation",M.oldValue,M.newValue)):(E||[]).forEach(M=>g("updateAnnotation",M.newValue,M.oldValue))};return t.on("undo",w(!0)),t.on("redo",w(!1)),{on:d,off:_,emit:g}},us=e=>t=>t.reduce((n,i)=>{const{parsed:o,error:s}=e.parse(i);return s?{parsed:n.parsed,failed:[...n.failed,i]}:o?{parsed:[...n.parsed,o],failed:n.failed}:{...n}},{parsed:[],failed:[]}),fs=(e,t,n)=>{const{store:i,selection:o}=e,s=y=>{if(n){const{parsed:A,error:E}=n.parse(y);A?i.addAnnotation(A,te.REMOTE):console.error(E)}else i.addAnnotation(Gt(y),te.REMOTE)},r=()=>o.clear(),a=()=>i.clear(),l=y=>{const A=i.getAnnotation(y);return n&&A?n.serialize(A):A},f=()=>n?i.all().map(n.serialize):i.all(),h=()=>{var y;const A=(((y=o.selected)==null?void 0:y.map(E=>E.id))||[]).map(E=>i.getAnnotation(E)).filter(Boolean);return n?A.map(n.serialize):A},c=(y,A=!0)=>fetch(y).then(E=>E.json()).then(E=>(_(E,A),E)),d=y=>{if(typeof y=="string"){const A=i.getAnnotation(y);if(i.deleteAnnotation(y),A)return n?n.serialize(A):A}else{const A=n?n.parse(y).parsed:y;if(A)return i.deleteAnnotation(A),y}},_=(y,A=!0)=>{if(n){const E=n.parseAll||us(n),{parsed:M,failed:v}=E(y);v.length>0&&console.warn(`Discarded ${v.length} invalid annotations`,v),i.bulkAddAnnotations(M,A,te.REMOTE)}else i.bulkAddAnnotations(y.map(Gt),A,te.REMOTE)},g=(y,A)=>{y?o.setSelected(y,A):o.clear()},p=y=>{o.clear(),o.setUserSelectAction(y)},w=y=>{if(n){const A=n.parse(y).parsed,E=n.serialize(i.getAnnotation(A.id));return i.updateAnnotation(A),E}else{const A=i.getAnnotation(y.id);return i.updateAnnotation(Gt(y)),A}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:f,getHistory:t.getHistory,getSelected:h,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:_,setSelected:g,setUserSelectAction:p,undo:t.undo,updateAnnotation:w}},cs=(e,t,n)=>typeof t=="function"?t(e,n):t,hs=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,i)=>{const o=typeof e=="function"?e(n,i):e,s=typeof t=="function"?t(n,i):t;return{...o||{},...s||{}}},ds="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let gs=e=>crypto.getRandomValues(new Uint8Array(e)),ps=(e,t,n)=>{let i=(2<<Math.log2(e.length-1))-1,o=-~(1.6*i*t/e.length);return(s=t)=>{let r="";for(;;){let a=n(o),l=o|0;for(;l--;)if(r+=e[a[l]&i]||"",r.length>=s)return r}}},ys=(e,t=21)=>ps(e,t|0,gs),_s=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=ds[n[e]&63];return t};const ms=()=>({isGuest:!0,id:ys("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ws=e=>{const t=JSON.stringify(e);let n=0;for(let i=0,o=t.length;i<o;i++){let s=t.charCodeAt(i);n=(n<<5)-n+s,n|=0}return`${n}`},qn=e=>e?typeof e=="object"?{...e}:e:void 0,Es=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:i,type:o,purpose:s,value:r,created:a,modified:l,creator:f,...h}=n;return{id:i||`temp-${ws(n)}`,annotation:t,type:o,purpose:s,value:r,creator:qn(f),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...h}}),bs=e=>e.map(t=>{var n;const{annotation:i,created:o,updated:s,...r}=t,a={...r,created:o==null?void 0:o.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a}),Ts=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],As=()=>{const e=[...Ts];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};_s();const Os=(e,t={strict:!0,invertY:!1})=>({parse:o=>Zn(o,t),serialize:o=>Wn(o,e,t)}),Zn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Xn(),{creator:i,created:o,modified:s,body:r,...a}=e,l=Es(r||[],n),f=Array.isArray(e.target)?e.target[0]:e.target,h=typeof f=="string"?f:Array.isArray(f.selector)?f.selector[0]:f.selector,c=typeof h=="string"||(h==null?void 0:h.type)==="FragmentSelector"?Tn(h,t.invertY):(h==null?void 0:h.type)==="SvgSelector"?Hn(h):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return c||!t.strict?{parsed:{...a,id:n,bodies:l,target:{created:o?new Date(o):void 0,creator:qn(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:n,selector:c||h}}}:{error:Error(`Invalid selector: ${JSON.stringify(h)}`)}},Wn=(e,t,n={strict:!0,invertY:!1})=>{const{selector:i,creator:o,created:s,updated:r,updatedBy:a,...l}=e.target;let f;try{f=i.type==ee.RECTANGLE?An(i.geometry):Bn(i)}catch(c){if(n.strict)throw c;f=i}const h={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:bs(e.bodies),created:s==null?void 0:s.toISOString(),creator:o,modified:r==null?void 0:r.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:f}};return delete h.bodies,"annotation"in h.target&&delete h.target.annotation,h},At=(e,t)=>{const n=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(i,2))},Ke=[];function Ms(e,t=j){let n;const i=new Set;function o(a){if(ae(e,a)&&(e=a,n)){const l=!Ke.length;for(const f of i)f[1](),Ke.push(f,e);if(l){for(let f=0;f<Ke.length;f+=2)Ke[f][0](Ke[f+1]);Ke.length=0}}}function s(a){o(a(e))}function r(a,l=j){const f=[a,l];return i.add(f),i.size===1&&(n=t(o,s)||j),a(e),()=>{i.delete(f),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const Ss=(e,t)=>{const{naturalWidth:n,naturalHeight:i}=e;if(!n&&!i){const{width:o,height:s}=e;t.setAttribute("viewBox",`0 0 ${o} ${s}`),e.addEventListener("load",r=>{const a=r.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${i}`)},Kn=(e,t)=>{Ss(e,t);const{subscribe:n,set:i}=Ms(1);let o;return window.ResizeObserver&&(o=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,f=Math.max(r.width/a,r.height/l);i(f)}),o.observe(t.parentElement)),{destroy:()=>{o&&o.disconnect()},subscribe:n}},ut=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:i,fillOpacity:o,stroke:s,strokeWidth:r,strokeOpacity:a}=n;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${o||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${r||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},ft=(e,t=0)=>{const{minX:n,minY:i,maxX:o,maxY:s}=e;return{x:n-t,y:i-t,w:o-n+2*t,h:s-i+2*t}},Je=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,vs=e=>({}),Jn=e=>({grab:e[0]});function Ns(e){let t,n,i,o;const s=e[8].default,r=Ki(s,e,e[7],Jn);return{c(){t=I("g"),r&&r.c(),u(t,"class","a9s-annotation selected")},m(a,l){P(a,t,l),r&&r.m(t,null),n=!0,i||(o=[K(t,"pointerup",e[2]),K(t,"pointermove",e[1])],i=!0)},p(a,[l]){r&&r.p&&(!n||l&128)&&xi(r,s,a,a[7],n?Ji(s,a[7],l,vs):$i(a[7]),Jn)},i(a){n||(V(r,a),n=!0)},o(a){z(r,a),n=!1},d(a){a&&D(t),r&&r.d(a),i=!1,ve(o)}}}function Cs(e,t,n){let{$$slots:i={},$$scope:o}=t;const s=Xe();let{shape:r}=t,{editor:a}=t,{transform:l}=t,{svgEl:f}=t,h,c,d;const _=w=>y=>{if(h=w,f){const{left:E,top:M}=f.getBoundingClientRect(),v=y.clientX-E,S=y.clientY-M;c=l.elementToImage(v,S)}else{const{offsetX:E,offsetY:M}=y;c=l.elementToImage(E,M)}d=r,y.target.setPointerCapture(y.pointerId),s("grab",y)},g=w=>{if(h){const[y,A]=l.elementToImage(w.offsetX,w.offsetY),E=[y-c[0],A-c[1]];n(3,r=a(d,h,E)),s("change",r)}},p=w=>{w.target.releasePointerCapture(w.pointerId),h=void 0,d=r,s("release",w)};return e.$$set=w=>{"shape"in w&&n(3,r=w.shape),"editor"in w&&n(4,a=w.editor),"transform"in w&&n(5,l=w.transform),"svgEl"in w&&n(6,f=w.svgEl),"$$scope"in w&&n(7,o=w.$$scope)},[_,g,p,r,a,l,f,o,i]}class Ot extends Ee{constructor(t){super(),we(this,t,Cs,Ns,ae,{shape:3,editor:4,transform:5,svgEl:6})}}function Rs(e){let t,n,i,o,s,r,a,l,f=e[3]&&xn(e);return{c(){t=I("g"),n=I("circle"),f&&f.c(),o=I("circle"),u(n,"class","a9s-handle-buffer svelte-160z737"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=e[5]+6/e[2]),u(o,"class",s=pt(`a9s-handle-dot${e[3]?" selected":""}`)+" svelte-160z737"),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",e[5]),u(t,"class",r=pt(`a9s-handle ${e[8].class||""}`.trim())+" svelte-160z737")},m(h,c){P(h,t,c),Z(t,n),f&&f.m(t,null),Z(t,o),a||(l=[K(n,"pointerenter",e[11]),K(n,"pointerleave",e[12]),K(n,"pointerdown",e[13]),K(n,"pointerdown",e[6]),K(n,"pointerup",e[14]),K(n,"pointerup",e[7])],a=!0)},p(h,c){c&1&&u(n,"cx",h[0]),c&2&&u(n,"cy",h[1]),c&36&&i!==(i=h[5]+6/h[2])&&u(n,"r",i),h[3]?f?f.p(h,c):(f=xn(h),f.c(),f.m(t,o)):f&&(f.d(1),f=null),c&8&&s!==(s=pt(`a9s-handle-dot${h[3]?" selected":""}`)+" svelte-160z737")&&u(o,"class",s),c&1&&u(o,"cx",h[0]),c&2&&u(o,"cy",h[1]),c&32&&u(o,"r",h[5]),c&256&&r!==(r=pt(`a9s-handle ${h[8].class||""}`.trim())+" svelte-160z737")&&u(t,"class",r)},d(h){h&&D(t),f&&f.d(),a=!1,ve(l)}}}function Is(e){let t,n,i,o,s,r,a,l,f;return{c(){t=I("g"),n=I("circle"),o=I("circle"),r=I("circle"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=e[5]*10),u(n,"class","a9s-touch-halo svelte-160z737"),Le(n,"touched",e[4]),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",s=e[5]+10/e[2]),u(o,"class","a9s-handle-buffer svelte-160z737"),u(r,"class","a9s-handle-dot svelte-160z737"),u(r,"cx",e[0]),u(r,"cy",e[1]),u(r,"r",a=e[5]+2/e[2]),u(t,"class","a9s-touch-handle")},m(h,c){P(h,t,c),Z(t,n),Z(t,o),Z(t,r),l||(f=[K(o,"pointerdown",e[9]),K(o,"pointerup",e[10]),K(o,"pointerdown",e[6]),K(o,"pointerup",e[7])],l=!0)},p(h,c){c&1&&u(n,"cx",h[0]),c&2&&u(n,"cy",h[1]),c&32&&i!==(i=h[5]*10)&&u(n,"r",i),c&16&&Le(n,"touched",h[4]),c&1&&u(o,"cx",h[0]),c&2&&u(o,"cy",h[1]),c&36&&s!==(s=h[5]+10/h[2])&&u(o,"r",s),c&1&&u(r,"cx",h[0]),c&2&&u(r,"cy",h[1]),c&36&&a!==(a=h[5]+2/h[2])&&u(r,"r",a)},d(h){h&&D(t),l=!1,ve(f)}}}function xn(e){let t,n;return{c(){t=I("circle"),u(t,"class","a9s-handle-selected svelte-160z737"),u(t,"cx",e[0]),u(t,"cy",e[1]),u(t,"r",n=e[5]+8/e[2])},m(i,o){P(i,t,o)},p(i,o){o&1&&u(t,"cx",i[0]),o&2&&u(t,"cy",i[1]),o&36&&n!==(n=i[5]+8/i[2])&&u(t,"r",n)},d(i){i&&D(t)}}}function Ls(e){let t;function n(s,r){return Je?Is:Rs}let o=n()(e);return{c(){o.c(),t=Ae()},m(s,r){o.m(s,r),P(s,t,r)},p(s,[r]){o.p(s,r)},i:j,o:j,d(s){s&&D(t),o.d(s)}}}function ks(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t,{selected:a=void 0}=t,l=!1;const f=y=>{y.pointerType==="touch"&&n(4,l=!0)},h=()=>n(4,l=!1);function c(y){pe.call(this,e,y)}function d(y){pe.call(this,e,y)}function _(y){pe.call(this,e,y)}function g(y){pe.call(this,e,y)}function p(y){pe.call(this,e,y)}function w(y){pe.call(this,e,y)}return e.$$set=y=>{n(8,t=De(De({},t),cn(y))),"x"in y&&n(0,o=y.x),"y"in y&&n(1,s=y.y),"scale"in y&&n(2,r=y.scale),"selected"in y&&n(3,a=y.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,i=4/r)},t=cn(t),[o,s,r,a,l,i,f,h,t,c,d,_,g,p,w]}class Ge extends Ee{constructor(t){super(),we(this,t,ks,Ls,ae,{x:0,y:1,scale:2,selected:3})}}function Ds(e){let t,n,i,o,s,r,a;return{c(){t=I("g"),n=I("circle"),o=I("circle"),s=I("circle"),u(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=1.75*e[2]),u(o,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",e[2]),u(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),u(s,"cx",e[0]),u(s,"cy",e[1]),u(s,"r",e[2]),u(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,f){P(l,t,f),Z(t,n),Z(t,o),Z(t,s),r||(a=[K(n,"pointerdown",e[5]),K(n,"pointerdown",e[3])],r=!0)},p(l,f){f&1&&u(n,"cx",l[0]),f&2&&u(n,"cy",l[1]),f&4&&i!==(i=1.75*l[2])&&u(n,"r",i),f&1&&u(o,"cx",l[0]),f&2&&u(o,"cy",l[1]),f&4&&u(o,"r",l[2]),f&1&&u(s,"cx",l[0]),f&2&&u(s,"cy",l[1]),f&4&&u(s,"r",l[2])},d(l){l&&D(t),r=!1,ve(a)}}}function Ps(e){let t;return{c(){t=I("circle"),u(t,"cx",e[0]),u(t,"cy",e[1]),u(t,"r",e[2])},m(n,i){P(n,t,i)},p(n,i){i&1&&u(t,"cx",n[0]),i&2&&u(t,"cy",n[1]),i&4&&u(t,"r",n[2])},d(n){n&&D(t)}}}function Us(e){let t;function n(s,r){return Je?Ps:Ds}let o=n()(e);return{c(){o.c(),t=Ae()},m(s,r){o.m(s,r),P(s,t,r)},p(s,[r]){o.p(s,r)},i:j,o:j,d(s){s&&D(t),o.d(s)}}}function Vs(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t;const a=f=>{f.pointerType};function l(f){pe.call(this,e,f)}return e.$$set=f=>{"x"in f&&n(0,o=f.x),"y"in f&&n(1,s=f.y),"scale"in f&&n(4,r=f.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,i=4/r)},[o,s,i,a,r,l]}class Hs extends Ee{constructor(t){super(),we(this,t,Vs,Us,ae,{x:0,y:1,scale:4})}}function jt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function $n(e,t,n){const i=e.slice();return i[30]=t[n],i[32]=n,i}function Qt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function qt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function ei(e){let t,n,i,o;return{c(){t=I("circle"),u(t,"cx",n=e[30][0]),u(t,"cy",i=e[30][1]),u(t,"r",o=ct/e[3]),u(t,"class","svelte-1h2slbm")},m(s,r){P(s,t,r)},p(s,r){r[0]&2176&&n!==(n=s[30][0])&&u(t,"cx",n),r[0]&2176&&i!==(i=s[30][1])&&u(t,"cy",i),r[0]&8&&o!==(o=ct/s[3])&&u(t,"r",o)},d(s){s&&D(t)}}}function ti(e){let t,n,i,o,s,r,a,l,f,h;return{c(){t=I("mask"),n=I("rect"),a=I("circle"),u(n,"x",i=e[10].x),u(n,"y",o=e[10].y),u(n,"width",s=e[10].w),u(n,"height",r=e[10].h),u(n,"class","svelte-1h2slbm"),u(a,"cx",l=e[30][0]),u(a,"cy",f=e[30][1]),u(a,"r",h=ct/e[3]),u(a,"class","svelte-1h2slbm"),u(t,"id",`${e[20]}-inner`),u(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,d){P(c,t,d),Z(t,n),Z(t,a)},p(c,d){d[0]&1024&&i!==(i=c[10].x)&&u(n,"x",i),d[0]&1024&&o!==(o=c[10].y)&&u(n,"y",o),d[0]&1024&&s!==(s=c[10].w)&&u(n,"width",s),d[0]&1024&&r!==(r=c[10].h)&&u(n,"height",r),d[0]&2176&&l!==(l=c[30][0])&&u(a,"cx",l),d[0]&2176&&f!==(f=c[30][1])&&u(a,"cy",f),d[0]&8&&h!==(h=ct/c[3])&&u(a,"r",h)},d(c){c&&D(t)}}}function ni(e){let t,n;return t=new Ge({props:{class:"a9s-corner-handle",x:e[30][0],y:e[30][1],scale:e[3],selected:e[9].includes(e[32])}}),t.$on("pointerenter",e[12]),t.$on("pointerleave",e[13]),t.$on("pointerdown",e[16]),t.$on("pointerdown",function(){ie(e[29](`HANDLE-${e[32]}`))&&e[29](`HANDLE-${e[32]}`).apply(this,arguments)}),t.$on("pointerup",e[17](e[32])),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&32&&(s.x=e[30][0]),o[0]&32&&(s.y=e[30][1]),o[0]&8&&(s.scale=e[3]),o[0]&512&&(s.selected=e[9].includes(e[32])),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function ii(e){let t,n;return t=new Hs({props:{x:e[30][0],y:e[30][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[19](e[7]))&&e[19](e[7]).apply(this,arguments)}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&2176&&(s.x=e[30][0]),o[0]&2176&&(s.y=e[30][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Bs(e){let t,n,i,o,s,r,a,l,f,h,c,d,_,g,p,w,y,A,E,M,v,S=e[7]!==void 0&&!e[8]&&ei(qt(e)),N=e[7]!==void 0&&!e[8]&&ti(Qt(e)),H=Oe(e[5].points),B=[];for(let m=0;m<H.length;m+=1)B[m]=ni($n(e,H,m));const X=m=>z(B[m],1,1,()=>{B[m]=null});let G=e[7]!==void 0&&!e[8]&&ii(jt(e));return{c(){t=I("defs"),n=I("mask"),i=I("rect"),l=I("polygon"),S&&S.c(),N&&N.c(),h=Te(),c=I("polygon"),_=Te(),g=I("polygon"),w=Te();for(let m=0;m<B.length;m+=1)B[m].c();y=Te(),G&&G.c(),A=Ae(),u(i,"x",o=e[10].x),u(i,"y",s=e[10].y),u(i,"width",r=e[10].w),u(i,"height",a=e[10].h),u(i,"class","svelte-1h2slbm"),u(l,"points",f=e[5].points.map(oi).join(" ")),u(l,"class","svelte-1h2slbm"),u(n,"id",`${e[20]}-outer`),u(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),u(c,"class","a9s-outer"),u(c,"mask",`url(#${e[20]}-outer)`),u(c,"points",d=e[5].points.map(si).join(" ")),u(g,"class","a9s-inner a9s-shape-handle"),u(g,"mask",`url(#${e[20]}-inner)`),u(g,"style",e[1]),u(g,"points",p=e[5].points.map(ri).join(" "))},m(m,b){P(m,t,b),Z(t,n),Z(n,i),Z(n,l),S&&S.m(n,null),N&&N.m(t,null),P(m,h,b),P(m,c,b),P(m,_,b),P(m,g,b),e[21](g),P(m,w,b);for(let O=0;O<B.length;O+=1)B[O]&&B[O].m(m,b);P(m,y,b),G&&G.m(m,b),P(m,A,b),E=!0,M||(v=[K(c,"pointerup",e[15]),K(c,"pointerdown",function(){ie(e[29]("SHAPE"))&&e[29]("SHAPE").apply(this,arguments)}),K(g,"pointermove",e[14]),K(g,"pointerup",e[15]),K(g,"pointerdown",function(){ie(e[29]("SHAPE"))&&e[29]("SHAPE").apply(this,arguments)})],M=!0)},p(m,b){if(e=m,(!E||b[0]&1024&&o!==(o=e[10].x))&&u(i,"x",o),(!E||b[0]&1024&&s!==(s=e[10].y))&&u(i,"y",s),(!E||b[0]&1024&&r!==(r=e[10].w))&&u(i,"width",r),(!E||b[0]&1024&&a!==(a=e[10].h))&&u(i,"height",a),(!E||b[0]&32&&f!==(f=e[5].points.map(oi).join(" ")))&&u(l,"points",f),e[7]!==void 0&&!e[8]?S?S.p(qt(e),b):(S=ei(qt(e)),S.c(),S.m(n,null)):S&&(S.d(1),S=null),e[7]!==void 0&&!e[8]?N?N.p(Qt(e),b):(N=ti(Qt(e)),N.c(),N.m(t,null)):N&&(N.d(1),N=null),(!E||b[0]&32&&d!==(d=e[5].points.map(si).join(" ")))&&u(c,"points",d),(!E||b[0]&2)&&u(g,"style",e[1]),(!E||b[0]&32&&p!==(p=e[5].points.map(ri).join(" ")))&&u(g,"points",p),b[0]&537080360){H=Oe(e[5].points);let O;for(O=0;O<H.length;O+=1){const C=$n(e,H,O);B[O]?(B[O].p(C,b),V(B[O],1)):(B[O]=ni(C),B[O].c(),V(B[O],1),B[O].m(y.parentNode,y))}for(_e(),O=H.length;O<B.length;O+=1)X(O);me()}e[7]!==void 0&&!e[8]?G?(G.p(jt(e),b),b[0]&384&&V(G,1)):(G=ii(jt(e)),G.c(),V(G,1),G.m(A.parentNode,A)):G&&(_e(),z(G,1,1,()=>{G=null}),me())},i(m){if(!E){for(let b=0;b<H.length;b+=1)V(B[b]);V(G),E=!0}},o(m){B=B.filter(Boolean);for(let b=0;b<B.length;b+=1)z(B[b]);z(G),E=!1},d(m){m&&(D(t),D(h),D(c),D(_),D(g),D(w),D(y),D(A)),S&&S.d(),N&&N.d(),e[21](null),Ye(B,m),G&&G.d(m),M=!1,ve(v)}}}function Ys(e){let t,n;return t=new Ot({props:{shape:e[0],transform:e[2],editor:e[18],svgEl:e[4],$$slots:{default:[Bs,({grab:i})=>({29:i}),({grab:i})=>[i?536870912:0]]},$$scope:{ctx:e}}}),t.$on("change",e[22]),t.$on("grab",e[23]),t.$on("release",e[24]),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&1&&(s.shape=i[0]),o[0]&4&&(s.transform=i[2]),o[0]&16&&(s.svgEl=i[4]),o[0]&536874986|o[1]&4&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}const Xs=250,Fs=1e3,zs=12,ct=4.5,oi=e=>e.join(","),si=e=>e.join(","),ri=e=>e.join(",");function Gs(e,t,n){let i,o,s;const r=Xe();let{shape:a}=t,{computedStyle:l}=t,{transform:f}=t,{viewportScale:h=1}=t,{svgEl:c}=t,d,_,g=!1,p,w=[];const y=()=>n(8,g=!0),A=()=>n(8,g=!1),E=R=>{if(w.length>0){n(7,_=void 0);return}const[L,Y]=f.elementToImage(R.offsetX,R.offsetY),Q=re=>Math.pow(re[0]-L,2)+Math.pow(re[1]-Y,2),x=i.points.reduce((re,le)=>Q(le)<Q(re)?le:re),Me=o.filter(re=>re.visible).reduce((re,le)=>Q(le.point)<Q(re.point)?le:re),ue=Math.pow(Fs/h,2);Q(x)<ue||Q(Me.point)<ue?n(7,_=o.indexOf(Me)):n(7,_=void 0)},M=()=>{document.activeElement!==c&&c.focus()},v=()=>{n(9,w=[]),M()},S=R=>{n(8,g=!0),R.preventDefault(),R.stopPropagation(),p=performance.now()},N=R=>L=>{if(!p||Je||performance.now()-p>Xs)return;const Y=w.includes(R);L.metaKey||L.ctrlKey||L.shiftKey?Y?n(9,w=w.filter(Q=>Q!==R)):n(9,w=[...w,R]):Y&&w.length>1?n(9,w=[R]):Y?n(9,w=[]):n(9,w=[R]),M()},H=(R,L,Y)=>{M();let Q;const x=R.geometry;w.length>1?Q=x.points.map(([ue,be],re)=>w.includes(re)?[ue+Y[0],be+Y[1]]:[ue,be]):L==="SHAPE"?Q=x.points.map(([ue,be])=>[ue+Y[0],be+Y[1]]):Q=x.points.map(([ue,be],re)=>L===`HANDLE-${re}`?[ue+Y[0],be+Y[1]]:[ue,be]);const Me=Ne(Q);return{...R,geometry:{points:Q,bounds:Me}}},B=R=>async L=>{L.stopPropagation();const Y=[...i.points.slice(0,R+1),o[R].point,...i.points.slice(R+1)],Q=Ne(Y);r("change",{...a,geometry:{points:Y,bounds:Q}}),await no();const x=[...document.querySelectorAll(".a9s-handle")][R+1];if(x!=null&&x.firstChild){const Me=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});x.firstChild.dispatchEvent(Me)}},X=()=>{if(i.points.length<4)return;const R=i.points.filter((Y,Q)=>!w.includes(Q)),L=Ne(R);r("change",{...a,geometry:{points:R,bounds:L}}),n(9,w=[])};je(()=>{if(Je)return;const R=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),X())};return c.addEventListener("pointermove",E),c.addEventListener("keydown",R),()=>{c.removeEventListener("pointermove",E),c.removeEventListener("keydown",R)}});const G=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function m(R){st[R?"unshift":"push"](()=>{d=R,n(6,d)})}function b(R){pe.call(this,e,R)}function O(R){pe.call(this,e,R)}function C(R){pe.call(this,e,R)}return e.$$set=R=>{"shape"in R&&n(0,a=R.shape),"computedStyle"in R&&n(1,l=R.computedStyle),"transform"in R&&n(2,f=R.transform),"viewportScale"in R&&n(3,h=R.viewportScale),"svgEl"in R&&n(4,c=R.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=a.geometry),e.$$.dirty[0]&40&&n(11,o=Je?[]:i.points.map((R,L)=>{const Y=L===i.points.length-1?i.points[0]:i.points[L+1],Q=(R[0]+Y[0])/2,x=(R[1]+Y[1])/2,ue=Math.sqrt(Math.pow(Y[0]-Q,2)+Math.pow(Y[1]-x,2))>zs/h;return{point:[Q,x],visible:ue}})),e.$$.dirty[0]&40&&n(10,s=ft(i.bounds,ct/h))},[a,l,f,h,c,i,d,_,g,w,s,o,y,A,E,v,S,N,H,B,G,m,b,O,C]}class li extends Ee{constructor(t){super(),we(this,t,Gs,Ys,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function js(e){let t,n,i,o,s,r,a,l,f,h,c,d,_,g,p,w,y,A,E,M,v,S,N,H,B,X,G,m,b,O,C,R,L,Y,Q,x,Me,ue,be,re,le,et,tt,F,ge,J,Ce,Se,nt,He,sn,Be,W,rn,Zi;return J=new Ge({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),J.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),Se=new Ge({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),Se.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),He=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]}}),He.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Be=new Ge({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Be.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=I("defs"),n=I("mask"),i=I("rect"),l=I("rect"),_=Te(),g=I("rect"),E=Te(),M=I("rect"),B=Te(),X=I("rect"),O=Te(),C=I("rect"),Q=Te(),x=I("rect"),re=Te(),le=I("rect"),ge=Te(),ye(J.$$.fragment),Ce=Te(),ye(Se.$$.fragment),nt=Te(),ye(He.$$.fragment),sn=Te(),ye(Be.$$.fragment),u(i,"class","rect-mask-bg svelte-1njczvj"),u(i,"x",o=e[6].x),u(i,"y",s=e[6].y),u(i,"width",r=e[6].w),u(i,"height",a=e[6].h),u(l,"class","rect-mask-fg svelte-1njczvj"),u(l,"x",f=e[5].x),u(l,"y",h=e[5].y),u(l,"width",c=e[5].w),u(l,"height",d=e[5].h),u(n,"id",e[8]),u(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),u(g,"class","a9s-outer"),u(g,"mask",`url(#${e[8]})`),u(g,"x",p=e[5].x),u(g,"y",w=e[5].y),u(g,"width",y=e[5].w),u(g,"height",A=e[5].h),u(M,"class","a9s-inner a9s-shape-handle"),u(M,"style",e[1]),u(M,"x",v=e[5].x),u(M,"y",S=e[5].y),u(M,"width",N=e[5].w),u(M,"height",H=e[5].h),u(X,"class","a9s-edge-handle a9s-edge-handle-top"),u(X,"x",G=e[5].x),u(X,"y",m=e[5].y),u(X,"height",1),u(X,"width",b=e[5].w),u(C,"class","a9s-edge-handle a9s-edge-handle-right"),u(C,"x",R=e[5].x+e[5].w),u(C,"y",L=e[5].y),u(C,"height",Y=e[5].h),u(C,"width",1),u(x,"class","a9s-edge-handle a9s-edge-handle-bottom"),u(x,"x",Me=e[5].x),u(x,"y",ue=e[5].y+e[5].h),u(x,"height",1),u(x,"width",be=e[5].w),u(le,"class","a9s-edge-handle a9s-edge-handle-left"),u(le,"x",et=e[5].x),u(le,"y",tt=e[5].y),u(le,"height",F=e[5].h),u(le,"width",1)},m(q,U){P(q,t,U),Z(t,n),Z(n,i),Z(n,l),P(q,_,U),P(q,g,U),P(q,E,U),P(q,M,U),P(q,B,U),P(q,X,U),P(q,O,U),P(q,C,U),P(q,Q,U),P(q,x,U),P(q,re,U),P(q,le,U),P(q,ge,U),fe(J,q,U),P(q,Ce,U),fe(Se,q,U),P(q,nt,U),fe(He,q,U),P(q,sn,U),fe(Be,q,U),W=!0,rn||(Zi=[K(g,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),K(M,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),K(X,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),K(C,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),K(x,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),K(le,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],rn=!0)},p(q,U){e=q,(!W||U&64&&o!==(o=e[6].x))&&u(i,"x",o),(!W||U&64&&s!==(s=e[6].y))&&u(i,"y",s),(!W||U&64&&r!==(r=e[6].w))&&u(i,"width",r),(!W||U&64&&a!==(a=e[6].h))&&u(i,"height",a),(!W||U&32&&f!==(f=e[5].x))&&u(l,"x",f),(!W||U&32&&h!==(h=e[5].y))&&u(l,"y",h),(!W||U&32&&c!==(c=e[5].w))&&u(l,"width",c),(!W||U&32&&d!==(d=e[5].h))&&u(l,"height",d),(!W||U&32&&p!==(p=e[5].x))&&u(g,"x",p),(!W||U&32&&w!==(w=e[5].y))&&u(g,"y",w),(!W||U&32&&y!==(y=e[5].w))&&u(g,"width",y),(!W||U&32&&A!==(A=e[5].h))&&u(g,"height",A),(!W||U&2)&&u(M,"style",e[1]),(!W||U&32&&v!==(v=e[5].x))&&u(M,"x",v),(!W||U&32&&S!==(S=e[5].y))&&u(M,"y",S),(!W||U&32&&N!==(N=e[5].w))&&u(M,"width",N),(!W||U&32&&H!==(H=e[5].h))&&u(M,"height",H),(!W||U&32&&G!==(G=e[5].x))&&u(X,"x",G),(!W||U&32&&m!==(m=e[5].y))&&u(X,"y",m),(!W||U&32&&b!==(b=e[5].w))&&u(X,"width",b),(!W||U&32&&R!==(R=e[5].x+e[5].w))&&u(C,"x",R),(!W||U&32&&L!==(L=e[5].y))&&u(C,"y",L),(!W||U&32&&Y!==(Y=e[5].h))&&u(C,"height",Y),(!W||U&32&&Me!==(Me=e[5].x))&&u(x,"x",Me),(!W||U&32&&ue!==(ue=e[5].y+e[5].h))&&u(x,"y",ue),(!W||U&32&&be!==(be=e[5].w))&&u(x,"width",be),(!W||U&32&&et!==(et=e[5].x))&&u(le,"x",et),(!W||U&32&&tt!==(tt=e[5].y))&&u(le,"y",tt),(!W||U&32&&F!==(F=e[5].h))&&u(le,"height",F);const vt={};U&32&&(vt.x=e[5].x),U&32&&(vt.y=e[5].y),U&8&&(vt.scale=e[3]),J.$set(vt);const Nt={};U&32&&(Nt.x=e[5].x+e[5].w),U&32&&(Nt.y=e[5].y),U&8&&(Nt.scale=e[3]),Se.$set(Nt);const Ct={};U&32&&(Ct.x=e[5].x+e[5].w),U&32&&(Ct.y=e[5].y+e[5].h),U&8&&(Ct.scale=e[3]),He.$set(Ct);const Rt={};U&32&&(Rt.x=e[5].x),U&32&&(Rt.y=e[5].y+e[5].h),U&8&&(Rt.scale=e[3]),Be.$set(Rt)},i(q){W||(V(J.$$.fragment,q),V(Se.$$.fragment,q),V(He.$$.fragment,q),V(Be.$$.fragment,q),W=!0)},o(q){z(J.$$.fragment,q),z(Se.$$.fragment,q),z(He.$$.fragment,q),z(Be.$$.fragment,q),W=!1},d(q){q&&(D(t),D(_),D(g),D(E),D(M),D(B),D(X),D(O),D(C),D(Q),D(x),D(re),D(le),D(ge),D(Ce),D(nt),D(sn)),ce(J,q),ce(Se,q),ce(He,q),ce(Be,q),rn=!1,ve(Zi)}}}function Qs(e){let t,n;return t=new Ot({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[js,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,[o]){const s={};o&1&&(s.shape=i[0]),o&4&&(s.transform=i[2]),o&16&&(s.svgEl=i[4]),o&12394&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function qs(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:f}=t;const h=(p,w,y)=>{const A=p.geometry.bounds;let[E,M]=[A.minX,A.minY],[v,S]=[A.maxX,A.maxY];const[N,H]=y;if(w==="SHAPE")E+=N,v+=N,M+=H,S+=H;else{switch(w){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{M+=H;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{S+=H;break}}switch(w){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{E+=N;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{v+=N;break}}}const B=Math.min(E,v),X=Math.min(M,S),G=Math.abs(v-E),m=Math.abs(S-M);return{...p,geometry:{x:B,y:X,w:G,h:m,bounds:{minX:B,minY:X,maxX:B+G,maxY:X+m}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(p){pe.call(this,e,p)}function _(p){pe.call(this,e,p)}function g(p){pe.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,a=p.transform),"viewportScale"in p&&n(3,l=p.viewportScale),"svgEl"in p&&n(4,f=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,i=s.geometry),e.$$.dirty&40&&n(6,o=ft(i.bounds,2/l))},[s,r,a,l,f,i,o,h,c,d,_,g]}class ai extends Ee{constructor(t){super(),we(this,t,qs,Qs,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}function ui(e,t,n){const i=e.slice();return i[13]=t[n],i[15]=n,i}function fi(e,t,n){const i=e.slice();return i[16]=t[n],i[18]=n,i}function ci(e,t,n){const i=e.slice();return i[19]=t[n],i[21]=n,i}function hi(e){let t,n;return t=new Ge({props:{class:"a9s-corner-handle",x:e[19][0],y:e[19][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[12](`HANDLE-${e[15]}-${e[18]}-${e[21]}`))&&e[12](`HANDLE-${e[15]}-${e[18]}-${e[21]}`).apply(this,arguments)}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o&32&&(s.x=e[19][0]),o&32&&(s.y=e[19][1]),o&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function di(e){let t,n,i=Oe(e[16].points),o=[];for(let r=0;r<i.length;r+=1)o[r]=hi(ci(e,i,r));const s=r=>z(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Ae()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a&4136){i=Oe(r[16].points);let l;for(l=0;l<i.length;l+=1){const f=ci(r,i,l);o[l]?(o[l].p(f,a),V(o[l],1)):(o[l]=hi(f),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(_e(),l=i.length;l<o.length;l+=1)s(l);me()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)z(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function gi(e){let t,n,i,o,s,r,a,l,f,h,c,d,_,g,p,w,y,A=Oe(e[13].rings),E=[];for(let v=0;v<A.length;v+=1)E[v]=di(fi(e,A,v));const M=v=>z(E[v],1,1,()=>{E[v]=null});return{c(){t=I("g"),n=I("defs"),i=I("mask"),o=I("rect"),f=I("path"),c=I("path"),_=I("path");for(let v=0;v<E.length;v+=1)E[v].c();u(o,"x",s=e[6].x),u(o,"y",r=e[6].y),u(o,"width",a=e[6].w),u(o,"height",l=e[6].h),u(o,"class","svelte-rfq8ys"),u(f,"d",h=ke(e[13])),u(f,"class","svelte-rfq8ys"),u(i,"id",`${e[8]}-${e[15]}`),u(i,"class","a9s-multipolygon-editor-mask svelte-rfq8ys"),u(c,"class","a9s-outer"),u(c,"mask",`url(#${e[8]}-${e[15]})`),u(c,"fill-rule","evenodd"),u(c,"d",d=ke(e[13])),u(_,"class","a9s-inner"),u(_,"style",e[1]),u(_,"fill-rule","evenodd"),u(_,"d",g=ke(e[13]))},m(v,S){P(v,t,S),Z(t,n),Z(n,i),Z(i,o),Z(i,f),Z(t,c),Z(t,_);for(let N=0;N<E.length;N+=1)E[N]&&E[N].m(t,null);p=!0,w||(y=[K(c,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),K(_,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)})],w=!0)},p(v,S){if(e=v,(!p||S&64&&s!==(s=e[6].x))&&u(o,"x",s),(!p||S&64&&r!==(r=e[6].y))&&u(o,"y",r),(!p||S&64&&a!==(a=e[6].w))&&u(o,"width",a),(!p||S&64&&l!==(l=e[6].h))&&u(o,"height",l),(!p||S&32&&h!==(h=ke(e[13])))&&u(f,"d",h),(!p||S&32&&d!==(d=ke(e[13])))&&u(c,"d",d),(!p||S&2)&&u(_,"style",e[1]),(!p||S&32&&g!==(g=ke(e[13])))&&u(_,"d",g),S&4136){A=Oe(e[13].rings);let N;for(N=0;N<A.length;N+=1){const H=fi(e,A,N);E[N]?(E[N].p(H,S),V(E[N],1)):(E[N]=di(H),E[N].c(),V(E[N],1),E[N].m(t,null))}for(_e(),N=A.length;N<E.length;N+=1)M(N);me()}},i(v){if(!p){for(let S=0;S<A.length;S+=1)V(E[S]);p=!0}},o(v){E=E.filter(Boolean);for(let S=0;S<E.length;S+=1)z(E[S]);p=!1},d(v){v&&D(t),Ye(E,v),w=!1,ve(y)}}}function Zs(e){let t,n,i=Oe(e[5].polygons),o=[];for(let r=0;r<i.length;r+=1)o[r]=gi(ui(e,i,r));const s=r=>z(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Ae()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a&4458){i=Oe(r[5].polygons);let l;for(l=0;l<i.length;l+=1){const f=ui(r,i,l);o[l]?(o[l].p(f,a),V(o[l],1)):(o[l]=gi(f),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(_e(),l=i.length;l<o.length;l+=1)s(l);me()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)z(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function Ws(e){let t,n;return t=new Ot({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Zs,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:e}}}),t.$on("change",e[9]),t.$on("grab",e[10]),t.$on("release",e[11]),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,[o]){const s={};o&1&&(s.shape=i[0]),o&4&&(s.transform=i[2]),o&16&&(s.svgEl=i[4]),o&4198506&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Ks(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:f}=t;const h=(p,w,y)=>{const A=p.geometry.polygons;let E;if(w==="SHAPE")E=A.map(M=>{const v=M.rings.map((N,H)=>({points:N.points.map((X,G)=>[X[0]+y[0],X[1]+y[1]])})),S=Ne(v[0].points);return{rings:v,bounds:S}});else{const[M,v,S,N]=w.split("-").map(H=>parseInt(H));E=A.map((H,B)=>{if(B===v){const X=H.rings.map((m,b)=>b===S?{points:m.points.map((C,R)=>R===N?[C[0]+y[0],C[1]+y[1]]:C)}:m),G=Ne(X[0].points);return{rings:X,bounds:G}}else return H})}return{...p,geometry:{polygons:E,bounds:En(E)}}},c=`multipoly-mask-${Math.random().toString(36).substring(2,12)}`;function d(p){pe.call(this,e,p)}function _(p){pe.call(this,e,p)}function g(p){pe.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,a=p.transform),"viewportScale"in p&&n(3,l=p.viewportScale),"svgEl"in p&&n(4,f=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,i=s.geometry),e.$$.dirty&40&&n(6,o=ft(i.bounds,2/l))},[s,r,a,l,f,i,o,h,c,d,_,g]}class Js extends Ee{constructor(t){super(),we(this,t,Ks,Ws,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}const pi=new Map([[ee.RECTANGLE,ai],[ee.POLYGON,li],[ee.MULTIPOLYGLON,Js]]),yi=e=>pi.get(e.type),_i=(e,t)=>pi.set(e,t);function xs(e,t,n){let i;const o=Xe();let{annotation:s}=t,{editor:r}=t,{style:a}=t,{target:l}=t,{transform:f}=t,{viewportScale:h}=t,c;return je(()=>(n(6,c=new r({target:l,props:{shape:s.target.selector,computedStyle:i,transform:f,viewportScale:h,svgEl:l.closest("svg")}})),c.$on("change",d=>{c.$$set({shape:d.detail}),o("change",d.detail)}),c.$on("grab",d=>o("grab",d.detail)),c.$on("release",d=>o("release",d.detail)),()=>{c.$destroy()})),e.$$set=d=>{"annotation"in d&&n(0,s=d.annotation),"editor"in d&&n(1,r=d.editor),"style"in d&&n(2,a=d.style),"target"in d&&n(3,l=d.target),"transform"in d&&n(4,f=d.transform),"viewportScale"in d&&n(5,h=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,i=ut(s,a)),e.$$.dirty&65&&s&&(c==null||c.$set({shape:s.target.selector})),e.$$.dirty&80&&c&&c.$set({transform:f}),e.$$.dirty&96&&c&&c.$set({viewportScale:h}),e.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[s,r,a,l,f,h,c,i]}class mi extends Ee{constructor(t){super(),we(this,t,xs,null,ae,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function $s(e,t,n){const i=Xe();let{drawingMode:o}=t,{target:s}=t,{tool:r}=t,{transform:a}=t,{viewportScale:l}=t,f;return je(()=>{const h=s.closest("svg"),c=[],d=(_,g,p)=>{h==null||h.addEventListener(_,g,p),c.push(()=>h==null?void 0:h.removeEventListener(_,g,p))};return n(5,f=new r({target:s,props:{addEventListener:d,drawingMode:o,transform:a,viewportScale:l}})),f.$on("create",_=>i("create",_.detail)),()=>{c.forEach(_=>_()),f.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,o=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,a=h.transform),"viewportScale"in h&&n(4,l=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&f&&f.$set({transform:a}),e.$$.dirty&48&&f&&f.$set({viewportScale:l})},[o,s,r,a,l,f]}class wi extends Ee{constructor(t){super(),we(this,t,$s,null,ae,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Ei(e){let t,n,i,o,s,r,a,l,f,h;return{c(){t=I("defs"),n=I("mask"),i=I("rect"),l=I("rect"),f=I("rect"),h=I("rect"),u(i,"class","rect-mask-bg svelte-1a76qe7"),u(i,"x",o=e[1]-e[5]),u(i,"y",s=e[2]-e[5]),u(i,"width",r=e[3]+2*e[5]),u(i,"height",a=e[4]+2*e[5]),u(l,"class","rect-mask-fg svelte-1a76qe7"),u(l,"x",e[1]),u(l,"y",e[2]),u(l,"width",e[3]),u(l,"height",e[4]),u(n,"id",e[6]),u(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),u(f,"class","a9s-outer"),u(f,"mask",`url(#${e[6]})`),u(f,"x",e[1]),u(f,"y",e[2]),u(f,"width",e[3]),u(f,"height",e[4]),u(h,"class","a9s-inner"),u(h,"x",e[1]),u(h,"y",e[2]),u(h,"width",e[3]),u(h,"height",e[4])},m(c,d){P(c,t,d),Z(t,n),Z(n,i),Z(n,l),P(c,f,d),P(c,h,d)},p(c,d){d&34&&o!==(o=c[1]-c[5])&&u(i,"x",o),d&36&&s!==(s=c[2]-c[5])&&u(i,"y",s),d&40&&r!==(r=c[3]+2*c[5])&&u(i,"width",r),d&48&&a!==(a=c[4]+2*c[5])&&u(i,"height",a),d&2&&u(l,"x",c[1]),d&4&&u(l,"y",c[2]),d&8&&u(l,"width",c[3]),d&16&&u(l,"height",c[4]),d&2&&u(f,"x",c[1]),d&4&&u(f,"y",c[2]),d&8&&u(f,"width",c[3]),d&16&&u(f,"height",c[4]),d&2&&u(h,"x",c[1]),d&4&&u(h,"y",c[2]),d&8&&u(h,"width",c[3]),d&16&&u(h,"height",c[4])},d(c){c&&(D(t),D(f),D(h))}}}function er(e){let t,n=e[0]&&Ei(e);return{c(){t=I("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(i,o){P(i,t,o),n&&n.m(t,null)},p(i,[o]){i[0]?n?n.p(i,o):(n=Ei(i),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(i){i&&D(t),n&&n.d()}}}function tr(e,t,n){let i;const o=Xe();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:a}=t,{viewportScale:l=1}=t,f,h,c,d,_,g,p;const w=v=>{const S=v;f=performance.now(),r==="drag"&&(n(0,h=a.elementToImage(S.offsetX,S.offsetY)),c=h,n(1,d=h[0]),n(2,_=h[1]),n(3,g=1),n(4,p=1))},y=v=>{const S=v;h&&(c=a.elementToImage(S.offsetX,S.offsetY),n(1,d=Math.min(c[0],h[0])),n(2,_=Math.min(c[1],h[1])),n(3,g=Math.abs(c[0]-h[0])),n(4,p=Math.abs(c[1]-h[1])))},A=v=>{const S=v,N=performance.now()-f;if(r==="click"){if(N>300)return;h?E():(n(0,h=a.elementToImage(S.offsetX,S.offsetY)),c=h,n(1,d=h[0]),n(2,_=h[1]),n(3,g=1),n(4,p=1))}else h&&(N>300||g*p>100?(S.stopPropagation(),E()):(n(0,h=void 0),c=void 0))},E=()=>{if(g*p>15){const v={type:ee.RECTANGLE,geometry:{bounds:{minX:d,minY:_,maxX:d+g,maxY:_+p},x:d,y:_,w:g,h:p}};o("create",v)}n(0,h=void 0),c=void 0};je(()=>{s("pointerdown",w),s("pointermove",y),s("pointerup",A,!0)});const M=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=v=>{"addEventListener"in v&&n(7,s=v.addEventListener),"drawingMode"in v&&n(8,r=v.drawingMode),"transform"in v&&n(9,a=v.transform),"viewportScale"in v&&n(10,l=v.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,i=2/l)},[h,d,_,g,p,i,M,s,r,a,l]}class bi extends Ee{constructor(t){super(),we(this,t,tr,er,ae,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function Zt(e){const t=e.slice(),n=t[2].map(i=>i.join(",")).join(" ");return t[19]=n,t}function Ti(e){let t,n,i,o,s,r,a,l,f,h,c,d,_,g,p=e[1]&&Ai(e);return{c(){t=I("defs"),n=I("mask"),i=I("rect"),l=I("polygon"),h=I("polygon"),d=I("polygon"),p&&p.c(),g=Ae(),u(i,"x",o=e[3].x),u(i,"y",s=e[3].y),u(i,"width",r=e[3].w),u(i,"height",a=e[3].h),u(i,"class","svelte-18wrg3t"),u(l,"points",f=e[19]),u(l,"class","svelte-18wrg3t"),u(n,"id",e[5]),u(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),u(h,"class","a9s-outer"),u(h,"mask",`url(#${e[5]})`),u(h,"points",c=e[19]),u(d,"class","a9s-inner"),u(d,"points",_=e[19])},m(w,y){P(w,t,y),Z(t,n),Z(n,i),Z(n,l),P(w,h,y),P(w,d,y),p&&p.m(w,y),P(w,g,y)},p(w,y){y&8&&o!==(o=w[3].x)&&u(i,"x",o),y&8&&s!==(s=w[3].y)&&u(i,"y",s),y&8&&r!==(r=w[3].w)&&u(i,"width",r),y&8&&a!==(a=w[3].h)&&u(i,"height",a),y&4&&f!==(f=w[19])&&u(l,"points",f),y&4&&c!==(c=w[19])&&u(h,"points",c),y&4&&_!==(_=w[19])&&u(d,"points",_),w[1]?p?p.p(w,y):(p=Ai(w),p.c(),p.m(g.parentNode,g)):p&&(p.d(1),p=null)},d(w){w&&(D(t),D(h),D(d),D(g)),p&&p.d(w)}}}function Ai(e){let t,n,i;return{c(){t=I("circle"),u(t,"class","a9s-handle svelte-18wrg3t"),u(t,"cx",n=e[0][0][0]),u(t,"cy",i=e[0][0][1]),u(t,"r",e[4])},m(o,s){P(o,t,s)},p(o,s){s&1&&n!==(n=o[0][0][0])&&u(t,"cx",n),s&1&&i!==(i=o[0][0][1])&&u(t,"cy",i),s&16&&u(t,"r",o[4])},d(o){o&&D(t)}}}function nr(e){let t,n=e[3]&&Ti(Zt(e));return{c(){t=I("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(i,o){P(i,t,o),n&&n.m(t,null)},p(i,[o]){i[3]?n?n.p(Zt(i),o):(n=Ti(Zt(i)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(i){i&&D(t),n&&n.d()}}}const ir=20,or=1500;function sr(e,t,n){let i,o,s;const r=Xe();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:f}=t,{viewportScale:h=1}=t,c,d=[],_,g,p=!1;const w=S=>{const N=S,{timeStamp:H,offsetX:B,offsetY:X}=N;if(c={timeStamp:H,offsetX:B,offsetY:X},l==="drag"&&d.length===0){const G=f.elementToImage(N.offsetX,N.offsetY);d.push(G),n(10,_=G)}},y=S=>{const N=S;if(g&&clearTimeout(g),d.length>0){if(n(10,_=f.elementToImage(N.offsetX,N.offsetY)),d.length>2){const H=At(_,d[0])*h;n(1,p=H<ir)}N.pointerType==="touch"&&(g=setTimeout(()=>{E()},or))}},A=S=>{const N=S;if(g&&clearTimeout(g),l==="click"){const H=N.timeStamp-c.timeStamp,B=At([c.offsetX,c.offsetY],[N.offsetX,N.offsetY]);if(H>300||B>15)return;if(p)M();else if(d.length===0){const X=f.elementToImage(N.offsetX,N.offsetY);d.push(X),n(10,_=X)}else d.push(_)}else{if(d.length===1&&At(d[0],_)<=4){n(0,d=[]),n(10,_=void 0);return}N.stopImmediatePropagation(),p?M():d.push(_)}},E=()=>{if(!_)return;const S=d.slice(0,-1);if(S.length<3)return;const N={type:ee.POLYGON,geometry:{bounds:Ne(d),points:S}};_t(N)>4&&(n(0,d=[]),n(10,_=void 0),r("create",N))},M=()=>{const S={type:ee.POLYGON,geometry:{bounds:Ne(d),points:[...d]}};n(0,d=[]),n(10,_=void 0),r("create",S)};je(()=>{a("pointerdown",w,!0),a("pointermove",y),a("pointerup",A,!0),a("dblclick",E,!0)});const v=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=S=>{"addEventListener"in S&&n(6,a=S.addEventListener),"drawingMode"in S&&n(7,l=S.drawingMode),"transform"in S&&n(8,f=S.transform),"viewportScale"in S&&n(9,h=S.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,i=4/h),e.$$.dirty&1027&&n(2,o=_?p?d:[...d,_]:[]),e.$$.dirty&516&&n(3,s=o.length>0?ft(Ne(o),2/h):void 0)},[d,p,o,s,i,v,a,l,f,h,_]}class rr extends Ee{constructor(t){super(),we(this,t,sr,nr,ae,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Wt=new Map([["rectangle",{tool:bi}],["polygon",{tool:rr}]]),Kt=()=>[...Wt.keys()],Jt=e=>Wt.get(e),Oi=(e,t,n={})=>Wt.set(e,{tool:t,opts:n});function lr(e){let t,n,i,o,s;return{c(){t=I("g"),n=I("ellipse"),o=I("ellipse"),u(n,"class","a9s-outer"),u(n,"style",i=e[1]?"display:none;":void 0),u(n,"cx",e[2]),u(n,"cy",e[3]),u(n,"rx",e[4]),u(n,"ry",e[5]),u(o,"class","a9s-inner"),u(o,"style",e[1]),u(o,"cx",e[2]),u(o,"cy",e[3]),u(o,"rx",e[4]),u(o,"ry",e[5]),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&2&&i!==(i=r[1]?"display:none;":void 0)&&u(n,"style",i),a&2&&u(o,"style",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:j,o:j,d(r){r&&D(t)}}}function ar(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{cx:a,cy:l,rx:f,ry:h}=s;return e.$$set=c=>{"annotation"in c&&n(0,o=c.annotation),"geom"in c&&n(6,s=c.geom),"style"in c&&n(7,r=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,i=ut(o,r))},[o,i,a,l,f,h,s,r]}class ur extends Ee{constructor(t){super(),we(this,t,ar,lr,ae,{annotation:0,geom:6,style:7})}}function Mi(e,t,n){const i=e.slice();return i[5]=t[n],i}function Si(e){let t,n,i;return{c(){t=I("path"),i=I("path"),u(t,"class","a9s-outer"),u(t,"style",n=e[1]?"display:none;":void 0),u(t,"fill-rule","evenodd"),u(t,"d",ke(e[5])),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"fill-rule","evenodd"),u(i,"d",ke(e[5]))},m(o,s){P(o,t,s),P(o,i,s)},p(o,s){s&2&&n!==(n=o[1]?"display:none;":void 0)&&u(t,"style",n),s&2&&u(i,"style",o[1])},d(o){o&&(D(t),D(i))}}}function fr(e){let t,n,i=Oe(e[2]),o=[];for(let s=0;s<i.length;s+=1)o[s]=Si(Mi(e,i,s));return{c(){t=I("g");for(let s=0;s<o.length;s+=1)o[s].c();u(t,"class","a9s-annotation"),u(t,"data-id",n=e[0].id)},m(s,r){P(s,t,r);for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(t,null)},p(s,[r]){if(r&6){i=Oe(s[2]);let a;for(a=0;a<i.length;a+=1){const l=Mi(s,i,a);o[a]?o[a].p(l,r):(o[a]=Si(l),o[a].c(),o[a].m(t,null))}for(;a<o.length;a+=1)o[a].d(1);o.length=i.length}r&1&&n!==(n=s[0].id)&&u(t,"data-id",n)},i:j,o:j,d(s){s&&D(t),Ye(o,s)}}}function cr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{polygons:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=ut(o,r))},[o,i,a,s,r]}class hr extends Ee{constructor(t){super(),we(this,t,cr,fr,ae,{annotation:0,geom:3,style:4})}}function dr(e){let t,n,i,o,s;return{c(){t=I("g"),n=I("polygon"),o=I("polygon"),u(n,"class","a9s-outer"),u(n,"style",i=e[1]?"display:none;":void 0),u(n,"points",e[2].map(gr).join(" ")),u(o,"class","a9s-inner"),u(o,"style",e[1]),u(o,"points",e[2].map(pr).join(" ")),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&2&&i!==(i=r[1]?"display:none;":void 0)&&u(n,"style",i),a&2&&u(o,"style",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:j,o:j,d(r){r&&D(t)}}}const gr=e=>e.join(","),pr=e=>e.join(",");function yr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{points:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=ut(o,r))},[o,i,a,s,r]}class _r extends Ee{constructor(t){super(),we(this,t,yr,dr,ae,{annotation:0,geom:3,style:4})}}function mr(e){let t,n,i,o,s;return{c(){t=I("g"),n=I("rect"),o=I("rect"),u(n,"class","a9s-outer"),u(n,"style",i=e[5]?"display:none;":void 0),u(n,"x",e[4]),u(n,"y",e[3]),u(n,"width",e[2]),u(n,"height",e[1]),u(o,"class","a9s-inner"),u(o,"style",e[5]),u(o,"x",e[4]),u(o,"y",e[3]),u(o,"width",e[2]),u(o,"height",e[1]),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&32&&i!==(i=r[5]?"display:none;":void 0)&&u(n,"style",i),a&16&&u(n,"x",r[4]),a&8&&u(n,"y",r[3]),a&4&&u(n,"width",r[2]),a&2&&u(n,"height",r[1]),a&32&&u(o,"style",r[5]),a&16&&u(o,"x",r[4]),a&8&&u(o,"y",r[3]),a&4&&u(o,"width",r[2]),a&2&&u(o,"height",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:j,o:j,d(r){r&&D(t)}}}function wr(e,t,n){let i,o,s,r,a,{annotation:l}=t,{geom:f}=t,{style:h}=t;return e.$$set=c=>{"annotation"in c&&n(0,l=c.annotation),"geom"in c&&n(6,f=c.geom),"style"in c&&n(7,h=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,i=ut(l,h)),e.$$.dirty&64&&n(4,{x:o,y:s,w:r,h:a}=f,o,(n(3,s),n(6,f)),(n(2,r),n(6,f)),(n(1,a),n(6,f)))},[l,a,r,s,o,i,f,h]}class Er extends Ee{constructor(t){super(),we(this,t,wr,mr,ae,{annotation:0,geom:6,style:7})}}const br={elementToImage:(e,t)=>[e,t]},vi=e=>({elementToImage:(t,n)=>{const i=e.getBoundingClientRect(),o=e.createSVGPoint();o.x=t+i.x,o.y=n+i.y;const{x:s,y:r}=o.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),Tr=250,Ni=(e,t)=>{const n=Xe();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:r=>{if(performance.now()-i<Tr){const{x:l,y:f}=xt(r,e),h=t.getAt(l,f);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},xt=(e,t)=>{const n=t.createSVGPoint(),i=t.getBoundingClientRect(),o=e.clientX-i.x,s=e.clientY-i.y,{left:r,top:a}=t.getBoundingClientRect();return n.x=o+r,n.y=s+a,n.matrixTransform(t.getScreenCTM().inverse())};function Ci(e,t,n){const i=e.slice();i[39]=t[n];const o=i[24](i[39].target.selector);return i[40]=o,i}function Ri(e,t,n){const i=e.slice();return i[43]=t[n],i}function $t(e){const t=e.slice(),n=t[43].target.selector;return t[46]=n,t}function Ii(e){let t=e[43],n,i,o=Li(e);return{c(){o.c(),n=Ae()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&65536&&ae(t,t=s[43])?(_e(),z(o,1,1,j),me(),o=Li(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){z(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Ar(e){let t,n;return t=new hr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Or(e){let t,n;return t=new _r({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Mr(e){let t,n;return t=new Er({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Sr(e){var i;let t,n;return t=new ur({props:{annotation:e[43],geom:(i=e[46])==null?void 0:i.geometry,style:e[1]}}),{c(){ye(t.$$.fragment)},m(o,s){fe(t,o,s),n=!0},p(o,s){var a;const r={};s[0]&65536&&(r.annotation=o[43]),s[0]&65536&&(r.geom=(a=o[46])==null?void 0:a.geometry),s[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(V(t.$$.fragment,o),n=!0)},o(o){z(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function Li(e){let t,n,i,o;const s=[Sr,Mr,Or,Ar],r=[];function a(l,f){var h,c,d,_;return((h=l[46])==null?void 0:h.type)===ee.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===ee.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===ee.POLYGON?2:((_=l[46])==null?void 0:_.type)===ee.MULTIPOLYGLON?3:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Ae()},m(l,f){~t&&r[t].m(l,f),P(l,i,f),o=!0},p(l,f){let h=t;t=a(l),t===h?~t&&r[t].p(l,f):(n&&(_e(),z(r[h],1,1,()=>{r[h]=null}),me()),~t?(n=r[t],n?n.p(l,f):(n=r[t]=s[t](l),n.c()),V(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(V(n),o=!0)},o(l){z(n),o=!1},d(l){l&&D(i),~t&&r[t].d(l)}}}function ki(e){let t=lt(e[43])&&!e[9](e[43]),n,i,o=t&&Ii($t(e));return{c(){o&&o.c(),n=Ae()},m(s,r){o&&o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&66048&&(t=lt(s[43])&&!s[9](s[43])),t?o?(o.p($t(s),r),r[0]&66048&&V(o,1)):(o=Ii($t(s)),o.c(),V(o,1),o.m(n.parentNode,n)):o&&(_e(),z(o,1,1,()=>{o=null}),me())},i(s){i||(V(o),i=!0)},o(s){z(o),i=!1},d(s){s&&D(n),o&&o.d(s)}}}function Di(e){let t,n,i,o;const s=[Nr,vr],r=[];function a(l,f){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Ae()},m(l,f){~t&&r[t].m(l,f),P(l,i,f),o=!0},p(l,f){let h=t;t=a(l),t===h?~t&&r[t].p(l,f):(n&&(_e(),z(r[h],1,1,()=>{r[h]=null}),me()),~t?(n=r[t],n?n.p(l,f):(n=r[t]=s[t](l),n.c()),V(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(V(n),o=!0)},o(l){z(n),o=!1},d(l){l&&D(i),~t&&r[t].d(l)}}}function vr(e){let t=`${e[2]}-${e[5]}`,n,i,o=Pi(e);return{c(){o.c(),n=Ae()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&36&&ae(t,t=`${s[2]}-${s[5]}`)?(_e(),z(o,1,1,j),me(),o=Pi(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){z(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Nr(e){let t,n,i=Oe(e[8]),o=[];for(let r=0;r<i.length;r+=1)o[r]=Hi(Ci(e,i,r));const s=r=>z(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Ae()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a[0]&21107010){i=Oe(r[8]);let l;for(l=0;l<i.length;l+=1){const f=Ci(r,i,l);o[l]?(o[l].p(f,a),V(o[l],1)):(o[l]=Hi(f),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(_e(),l=i.length;l<o.length;l+=1)s(l);me()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)z(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function Pi(e){let t,n;return t=new wi({props:{target:e[6],tool:e[14],drawingMode:e[13],transform:e[12],viewportScale:e[17]}}),t.$on("create",e[21]),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&64&&(s.target=i[6]),o[0]&16384&&(s.tool=i[14]),o[0]&8192&&(s.drawingMode=i[13]),o[0]&4096&&(s.transform=i[12]),o[0]&131072&&(s.viewportScale=i[17]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Ui(e){let t=e[39].id,n,i,o=Vi(e);return{c(){o.c(),n=Ae()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&256&&ae(t,t=s[39].id)?(_e(),z(o,1,1,j),me(),o=Vi(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){z(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Vi(e){let t,n;return t=new mi({props:{target:e[6],editor:e[24](e[39].target.selector),annotation:e[39],style:e[1],transform:e[12],viewportScale:e[17]}}),t.$on("change",function(){ie(e[22](e[39]))&&e[22](e[39]).apply(this,arguments)}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&64&&(s.target=e[6]),o[0]&256&&(s.editor=e[24](e[39].target.selector)),o[0]&256&&(s.annotation=e[39]),o[0]&2&&(s.style=e[1]),o[0]&4096&&(s.transform=e[12]),o[0]&131072&&(s.viewportScale=e[17]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Hi(e){let t,n,i=e[40]&&Ui(e);return{c(){i&&i.c(),t=Ae()},m(o,s){i&&i.m(o,s),P(o,t,s),n=!0},p(o,s){o[40]?i?(i.p(o,s),s[0]&256&&V(i,1)):(i=Ui(o),i.c(),V(i,1),i.m(t.parentNode,t)):i&&(_e(),z(i,1,1,()=>{i=null}),me())},i(o){n||(V(i),n=!0)},o(o){z(i),n=!1},d(o){o&&D(t),i&&i.d(o)}}}function Cr(e){let t,n,i,o,s,r,a=Oe(e[16].filter(e[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=ki(Ri(e,a,c));const f=c=>z(l[c],1,1,()=>{l[c]=null});let h=e[6]&&Di(e);return{c(){t=I("svg"),n=I("g");for(let c=0;c<l.length;c+=1)l[c].c();i=I("g"),h&&h.c(),u(i,"class","drawing"),u(t,"role","application"),u(t,"tabindex",0),u(t,"class","a9s-annotationlayer"),Le(t,"drawing",e[14]),Le(t,"editing",e[8]),Le(t,"hidden",!e[3]),Le(t,"hover",e[15])},m(c,d){P(c,t,d),Z(t,n);for(let _=0;_<l.length;_+=1)l[_]&&l[_].m(n,null);Z(t,i),h&&h.m(i,null),e[35](i),e[36](t),o=!0,s||(r=[K(t,"pointerup",function(){ie(e[10])&&e[10].apply(this,arguments)}),K(t,"pointerdown",function(){ie(e[11])&&e[11].apply(this,arguments)}),K(t,"pointermove",e[23])],s=!0)},p(c,d){if(e=c,d[0]&66050){a=Oe(e[16].filter(e[34]));let _;for(_=0;_<a.length;_+=1){const g=Ri(e,a,_);l[_]?(l[_].p(g,d),V(l[_],1)):(l[_]=ki(g),l[_].c(),V(l[_],1),l[_].m(n,null))}for(_e(),_=a.length;_<l.length;_+=1)f(_);me()}e[6]?h?(h.p(e,d),d[0]&64&&V(h,1)):(h=Di(e),h.c(),V(h,1),h.m(i,null)):h&&(_e(),z(h,1,1,()=>{h=null}),me()),(!o||d[0]&16384)&&Le(t,"drawing",e[14]),(!o||d[0]&256)&&Le(t,"editing",e[8]),(!o||d[0]&8)&&Le(t,"hidden",!e[3]),(!o||d[0]&32768)&&Le(t,"hover",e[15])},i(c){if(!o){for(let d=0;d<a.length;d+=1)V(l[d]);V(h),o=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)z(l[d]);z(h),o=!1},d(c){c&&D(t),Ye(l,c),h&&h.d(),e[35](null),e[36](null),s=!1,ve(r)}}}function Rr(e,t,n){let i,o,s,r,a,l,f,h,c,d,_,g=j,p=()=>(g(),g=un(O,F=>n(17,_=F)),O);e.$$.on_destroy.push(()=>g());let{drawingEnabled:w}=t,{image:y}=t,{preferredDrawingMode:A}=t,{state:E}=t,{style:M=void 0}=t,{toolName:v=Kt()[0]}=t,{user:S}=t,{visible:N=!0}=t,H=0;const B=()=>n(5,H+=1),X=()=>v,G=()=>w;let m,b,O;je(()=>p(n(7,O=Kn(y,b))));const{hover:C,selection:R,store:L}=E;It(e,C,F=>n(15,h=F)),It(e,R,F=>n(33,c=F)),It(e,L,F=>n(16,d=F));let Y,Q;const x=F=>{Y&&L.unobserve(Y);const ge=F.filter(({editable:J})=>J).map(({id:J})=>J);ge.length>0?(n(8,Q=ge.map(J=>L.getAnnotation(J)).filter(J=>J&<(J))),Y=J=>{const{updated:Ce}=J.changes;n(8,Q=Ce==null?void 0:Ce.map(Se=>Se.newValue))},L.observe(Y,{annotations:ge})):n(8,Q=void 0)},Me=F=>{const ge=Xn(),J={id:ge,bodies:[],target:{annotation:ge,selector:F.detail,creator:S,created:new Date}};L.addAnnotation(J),R.setSelected(J.id)},ue=F=>ge=>{var nt;const{target:J}=F,Ce=10*60*1e3,Se=((nt=J.creator)==null?void 0:nt.id)!==S.id||!J.created||new Date().getTime()-J.created.getTime()>Ce;L.updateTarget({...J,selector:ge.detail,created:Se?J.created:new Date,updated:Se?new Date:void 0,updatedBy:Se?S:void 0})},be=F=>{const{x:ge,y:J}=xt(F,b),Ce=L.getAt(ge,J);Ce?h!==Ce.id&&C.set(Ce.id):C.set(void 0)},re=F=>yi(F),le=F=>lt(F);function et(F){st[F?"unshift":"push"](()=>{m=F,n(6,m)})}function tt(F){st[F?"unshift":"push"](()=>{b=F,n(4,b)})}return e.$$set=F=>{"drawingEnabled"in F&&n(0,w=F.drawingEnabled),"image"in F&&n(25,y=F.image),"preferredDrawingMode"in F&&n(26,A=F.preferredDrawingMode),"state"in F&&n(27,E=F.state),"style"in F&&n(1,M=F.style),"toolName"in F&&n(2,v=F.toolName),"user"in F&&n(28,S=F.user),"visible"in F&&n(3,N=F.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(14,{tool:i,opts:o}=Jt(v)||{tool:void 0,opts:void 0},i,(n(32,o),n(2,v))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(13,s=(o==null?void 0:o.drawingMode)||A),e.$$.dirty[0]&16&&n(12,r=vi(b)),e.$$.dirty[0]&16&&n(11,{onPointerDown:a,onPointerUp:l}=Ni(b,L),a,(n(10,l),n(4,b))),e.$$.dirty[1]&4&&n(9,f=F=>c.selected.find(ge=>ge.id===F.id&&ge.editable)),e.$$.dirty[1]&4&&x(c.selected)},[w,M,v,N,b,H,m,O,Q,f,l,a,r,s,i,h,d,_,C,R,L,Me,ue,be,re,y,A,E,S,B,X,G,o,c,le,et,tt]}class Bi extends Ee{constructor(t){super(),we(this,t,Rr,Cr,ae,{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 Yi(e,t,n=0,i=e.length-1,o=Ir){for(;i>n;){if(i-n>600){const l=i-n+1,f=t-n+1,h=Math.log(l),c=.5*Math.exp(2*h/3),d=.5*Math.sqrt(h*c*(l-c)/l)*(f-l/2<0?-1:1),_=Math.max(n,Math.floor(t-f*c/l+d)),g=Math.min(i,Math.floor(t+(l-f)*c/l+d));Yi(e,t,_,g,o)}const s=e[t];let r=n,a=i;for(ht(e,n,t),o(e[i],s)>0&&ht(e,n,i);r<a;){for(ht(e,r,a),r++,a--;o(e[r],s)<0;)r++;for(;o(e[a],s)>0;)a--}o(e[n],s)===0?ht(e,n,a):(a++,ht(e,a,i)),a<=t&&(n=a+1),t<=a&&(i=a-1)}}function ht(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function Ir(e,t){return e<t?-1:e>t?1:0}class Lr{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const i=[];if(!St(t,n))return i;const o=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const a=n.children[r],l=n.leaf?o(a):a;St(t,l)&&(n.leaf?i.push(a):tn(t,l)?this._all(a,i):s.push(a))}n=s.pop()}return i}collides(t){let n=this.data;if(!St(t,n))return!1;const i=[];for(;n;){for(let o=0;o<n.children.length;o++){const s=n.children[o],r=n.leaf?this.toBBox(s):s;if(St(t,r)){if(n.leaf||tn(t,r))return!0;i.push(s)}}n=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let 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 i=this.data;this.data=n,n=i}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 i=this.data;const o=this.toBBox(t),s=[],r=[];let a,l,f;for(;i||s.length;){if(i||(i=s.pop(),l=s[s.length-1],a=r.pop(),f=!0),i.leaf){const h=kr(t,i.children,n);if(h!==-1)return i.children.splice(h,1),s.push(i),this._condense(s),this}!f&&!i.leaf&&tn(i,o)?(s.push(i),r.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],f=!1):i=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 i=[];for(;t;)t.leaf?n.push(...t.children):i.push(...t.children),t=i.pop();return n}_build(t,n,i,o){const s=i-n+1;let r=this._maxEntries,a;if(s<=r)return a=$e(t.slice(n,i+1)),xe(a,this.toBBox),a;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),a=$e([]),a.leaf=!1,a.height=o;const l=Math.ceil(s/r),f=l*Math.ceil(Math.sqrt(r));Xi(t,n,i,f,this.compareMinX);for(let h=n;h<=i;h+=f){const c=Math.min(h+f-1,i);Xi(t,h,c,l,this.compareMinY);for(let d=h;d<=c;d+=l){const _=Math.min(d+l-1,c);a.children.push(this._build(t,d,_,o-1))}}return xe(a,this.toBBox),a}_chooseSubtree(t,n,i,o){for(;o.push(n),!(n.leaf||o.length-1===i);){let s=1/0,r=1/0,a;for(let l=0;l<n.children.length;l++){const f=n.children[l],h=en(f),c=Ur(t,f)-h;c<r?(r=c,s=h<s?h:s,a=f):c===r&&h<s&&(s=h,a=f)}n=a||n.children[0]}return n}_insert(t,n,i){const o=i?t:this.toBBox(t),s=[],r=this._chooseSubtree(o,this.data,n,s);for(r.children.push(t),gt(r,o);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(o,s,n)}_split(t,n){const i=t[n],o=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,o);const r=this._chooseSplitIndex(i,s,o),a=$e(i.children.splice(r,i.children.length-r));a.height=i.height,a.leaf=i.leaf,xe(i,this.toBBox),xe(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,n){this.data=$e([t,n]),this.data.height=t.height+1,this.data.leaf=!1,xe(this.data,this.toBBox)}_chooseSplitIndex(t,n,i){let o,s=1/0,r=1/0;for(let a=n;a<=i-n;a++){const l=dt(t,0,a,this.toBBox),f=dt(t,a,i,this.toBBox),h=Vr(l,f),c=en(l)+en(f);h<s?(s=h,o=a,r=c<r?c:r):h===s&&c<r&&(r=c,o=a)}return o||i-n}_chooseSplitAxis(t,n,i){const o=t.leaf?this.compareMinX:Dr,s=t.leaf?this.compareMinY:Pr,r=this._allDistMargin(t,n,i,o),a=this._allDistMargin(t,n,i,s);r<a&&t.children.sort(o)}_allDistMargin(t,n,i,o){t.children.sort(o);const s=this.toBBox,r=dt(t,0,n,s),a=dt(t,i-n,i,s);let l=Mt(r)+Mt(a);for(let f=n;f<i-n;f++){const h=t.children[f];gt(r,t.leaf?s(h):h),l+=Mt(r)}for(let f=i-n-1;f>=n;f--){const h=t.children[f];gt(a,t.leaf?s(h):h),l+=Mt(a)}return l}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)gt(n[o],t)}_condense(t){for(let n=t.length-1,i;n>=0;n--)t[n].children.length===0?n>0?(i=t[n-1].children,i.splice(i.indexOf(t[n]),1)):this.clear():xe(t[n],this.toBBox)}}function kr(e,t,n){if(!n)return t.indexOf(e);for(let i=0;i<t.length;i++)if(n(e,t[i]))return i;return-1}function xe(e,t){dt(e,0,e.children.length,t,e)}function dt(e,t,n,i,o){o||(o=$e(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];gt(o,e.leaf?i(r):r)}return o}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 Dr(e,t){return e.minX-t.minX}function Pr(e,t){return e.minY-t.minY}function en(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Mt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Ur(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 Vr(e,t){const n=Math.max(e.minX,t.minX),i=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,o-n)*Math.max(0,s-i)}function tn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function St(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 Xi(e,t,n,i,o){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=i)continue;const r=t+Math.ceil((n-t)/i/2)*i;Yi(e,r,t,n,o),s.push(t,r,r,n)}}const Hr=()=>{const e=new Lr,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=c=>{if(!at(c))return;const{minX:d,minY:_,maxX:g,maxY:p}=c.selector.geometry.bounds,w={minX:d,minY:_,maxX:g,maxY:p,target:c};e.insert(w),t.set(c.annotation,w)},s=c=>{if(!at(c))return;const d=t.get(c.annotation);d&&e.remove(d),t.delete(c.annotation)};return{all:n,clear:i,getAt:(c,d,_)=>{const p=e.search({minX:c,minY:d,maxX:c,maxY:d}).map(w=>w.target).filter(w=>w.selector.type===ee.RECTANGLE||mn(w.selector,c,d));return p.length>0?(p.sort((w,y)=>_t(w.selector)-_t(y.selector)),p):[]},getIntersecting:(c,d,_,g)=>e.search({minX:c,minY:d,maxX:c+_,maxY:d+g}).map(p=>p.target),insert:o,remove:s,set:(c,d=!0)=>{d&&i();const _=c.reduce((g,p)=>{if(at(p)){const{minX:w,minY:y,maxX:A,maxY:E}=p.selector.geometry.bounds;return[...g,{minX:w,minY:y,maxX:A,maxY:E,target:p}]}else return g},[]);_.forEach(g=>t.set(g.target.annotation,g)),e.load(_)},size:()=>e.all().length,update:(c,d)=>{s(c),o(d)}}},Fi=e=>{const t=ns(),n=Hr(),i=zo(t,e.userSelectAction,e.adapter),o=Fo(t),s=ls();return t.observe(({changes:l})=>{n.set((l.created||[]).map(f=>f.target),!1),(l.deleted||[]).forEach(f=>n.remove(f.target)),(l.updated||[]).forEach(({oldValue:f,newValue:h})=>n.update(f.target,h.target))}),{store:{...t,getAt:(l,f,h)=>{const c=n.getAt(l,f,h);if(h)return c.map(_=>t.getAnnotation(_.annotation)).filter(Boolean).filter(h)[0];{const d=c[0];return d?t.getAnnotation(d.annotation):void 0}},getIntersecting:(l,f,h,c)=>n.getIntersecting(l,f,h,c).map(d=>t.getAnnotation(d.annotation))},selection:i,hover:o,viewport:s}},zi=e=>{const t=Fi(e);return{...t,store:is(t.store)}},Gi=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const o=e;t=document.createElement("canvas"),t.width=o.width,t.height=o.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(o,0,0,o.width,o.height)}let i=0;for(let o=1;o<10;o++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),a=Math.round(o*t.height/10),l=n.getImageData(r,a,1,1).data,f=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=f}return i/81},ji=e=>{const t=Gi(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},nn=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?ji(e):n),Qi=(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}),on=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,qi=(e,t)=>{const n=t||document,i=r=>{const a=r;a.key==="z"&&a.ctrlKey?e.undo():a.key==="y"&&a.ctrlKey&&e.redo()},o=r=>{const a=r;a.key==="z"&&a.metaKey&&(a.shiftKey?e.redo():e.undo())},s=()=>{on?n.removeEventListener("keydown",o):n.removeEventListener("keydown",i)};return on?n.addEventListener("keydown",o):n.addEventListener("keydown",i),{destroy:s}},Br=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=Qi(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Ft.EDIT,theme:"light"}),o=zi(i),{selection:s,store:r}=o,a=rs(r,i.initialHistory),l=as(o,a,i.adapter,i.autoSave),f=document.createElement("DIV");f.style.position="relative",f.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(f,n),f.appendChild(n);const h=qi(a);let c=ms();nn(n,f,i.theme);const d=new Bi({target:f,props:{drawingEnabled:!!i.drawingEnabled,image:n,preferredDrawingMode:i.drawingMode,state:o,style:i.style,user:c}});d.$on("click",m=>{const{originalEvent:b,annotation:O}=m.detail;O?s.userSelect(O.id,b):s.isEmpty()||s.clear()});const _=fs(o,a,i.adapter),g=()=>d.cancelDrawing(),p=()=>{d.$destroy(),f.parentNode.insertBefore(n,f),f.parentNode.removeChild(f),h.destroy(),a.destroy()},w=()=>d.getDrawingTool(),y=()=>c,A=()=>d.isDrawingEnabled(),E=(m,b,O)=>Oi(m,b,O),M=(m,b)=>_i(m,b),v=m=>{if(!Jt(m))throw`No drawing tool named ${m}`;d.$set({toolName:m})},S=m=>d.$set({drawingEnabled:m}),N=m=>{console.warn("Filter not implemented yet")},H=m=>d.$set({style:m}),B=m=>nn(n,f,m),X=m=>{c=m,d.$set({user:m})},G=m=>d.$set({visible:m});return{..._,cancelDrawing:g,destroy:p,getDrawingTool:w,getUser:y,isDrawingEnabled:A,listDrawingTools:Kt,on:l.on,off:l.off,registerDrawingTool:E,registerShapeEditor:M,setDrawingEnabled:S,setDrawingTool:v,setFilter:N,setStyle:H,setTheme:B,setUser:X,setVisible:G,element:f,state:o}};k.Editor=Ot,k.EditorMount=mi,k.Handle=Ge,k.IdentityTransform=br,k.PolygonEditor=li,k.RectangleEditor=ai,k.RectangleUtil=bn,k.RubberbandRectangle=bi,k.SVGAnnotationLayer=Bi,k.ShapeType=ee,k.ToolMount=wi,k.UserSelectAction=Ft,k.W3CImageFormat=Os,k.addEventListeners=Ni,k.boundsFromMultiPolygonElements=En,k.boundsFromPoints=Ne,k.chainStyles=hs,k.computeArea=_t,k.computePolygonArea=mt,k.computeStyle=cs,k.createBody=Zo,k.createImageAnnotator=Br,k.createImageAnnotatorState=Fi,k.createSVGTransform=vi,k.createSvelteImageAnnotatorState=zi,k.defaultColorProvider=As,k.detectTheme=ji,k.distance=At,k.enableResponsive=Kn,k.fillDefaults=Qi,k.getEditor=yi,k.getMaskDimensions=ft,k.getSVGPoint=xt,k.getTool=Jt,k.initKeyboardCommands=qi,k.intersects=mn,k.isImageAnnotation=lt,k.isImageAnnotationTarget=at,k.isMac=on,k.isPointInPolygon=wt,k.isTouch=Je,k.listDrawingTools=Kt,k.multipolygonElementToPath=ke,k.parseFragmentSelector=Tn,k.parseSVGSelector=Hn,k.parseW3CImageAnnotation=Zn,k.pointsToPath=wn,k.registerEditor=_i,k.registerShapeUtil=rt,k.registerTool=Oi,k.sampleBrightness=Gi,k.serializeFragmentSelector=An,k.serializeSVGSelector=Bn,k.serializeW3CImageAnnotation=Wn,k.setTheme=nn,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(U,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(U=typeof globalThis<"u"?globalThis:U||self,q(U.Annotorious={}))})(this,function(U){"use strict";var el=Object.defineProperty;var tl=(U,q,He)=>q in U?el(U,q,{enumerable:!0,configurable:!0,writable:!0,value:He}):U[q]=He;var se=(U,q,He)=>tl(U,typeof q!="symbol"?q+"":q,He);function q(){}function He(e,t){for(const n in t)e[n]=t[n];return e}function dn(e){return e()}function gn(){return Object.create(null)}function Ie(e){e.forEach(dn)}function re(e){return typeof e=="function"}function ce(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function lo(e){return Object.keys(e).length===0}function pn(e,...t){if(e==null){for(const i of t)i(void 0);return q}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function kt(e,t,n){e.$$.on_destroy.push(pn(t,n))}function ao(e,t,n,i){if(e){const o=yn(e,t,n,i);return e[0](o)}}function yn(e,t,n,i){return e[1]&&i?He(n.ctx.slice(),e[1](i(t))):n.ctx}function uo(e,t,n,i){if(e[2]&&i){const o=e[2](i(n));if(t.dirty===void 0)return o;if(typeof o=="object"){const s=[],r=Math.max(t.dirty.length,o.length);for(let a=0;a<r;a+=1)s[a]=t.dirty[a]|o[a];return s}return t.dirty|o}return t.dirty}function fo(e,t,n,i,o,s){if(o){const r=yn(t,n,i,s);e.p(r,o)}}function co(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let i=0;i<n;i++)t[i]=-1;return t}return-1}function _n(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function pt(e){return e??""}function K(e,t){e.appendChild(t)}function V(e,t,n){e.insertBefore(t,n||null)}function H(e){e.parentNode&&e.parentNode.removeChild(e)}function je(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 mn(e){return document.createTextNode(e)}function Ae(){return mn(" ")}function ve(){return mn("")}function $(e,t,n,i){return e.addEventListener(t,n,i),()=>e.removeEventListener(t,n,i)}function u(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function ho(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function go(e,t,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:i})}let it;function ot(e){it=e}function wn(){if(!it)throw new Error("Function called outside component initialization");return it}function Ge(e){wn().$$.on_mount.push(e)}function Ve(){const e=wn();return(t,n,{cancelable:i=!1}={})=>{const o=e.$$.callbacks[t];if(o){const s=go(t,n,{cancelable:i});return o.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function we(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(i=>i.call(this,t))}const Ke=[],yt=[];let We=[];const En=[],bn=Promise.resolve();let Pt=!1;function Tn(){Pt||(Pt=!0,bn.then(On))}function An(){return Tn(),bn}function Dt(e){We.push(e)}const Ut=new Set;let Je=0;function On(){if(Je!==0)return;const e=it;do{try{for(;Je<Ke.length;){const t=Ke[Je];Je++,ot(t),po(t.$$)}}catch(t){throw Ke.length=0,Je=0,t}for(ot(null),Ke.length=0,Je=0;yt.length;)yt.pop()();for(let t=0;t<We.length;t+=1){const n=We[t];Ut.has(n)||(Ut.add(n),n())}We.length=0}while(Ke.length);for(;En.length;)En.pop()();Pt=!1,Ut.clear(),ot(e)}function po(e){if(e.fragment!==null){e.update(),Ie(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Dt)}}function yo(e){const t=[],n=[];We.forEach(i=>e.indexOf(i)===-1?t.push(i):n.push(i)),n.forEach(i=>i()),We=t}const _t=new Set;let Qe;function Ee(){Qe={r:0,c:[],p:Qe}}function be(){Qe.r||Ie(Qe.c),Qe=Qe.p}function B(e,t){e&&e.i&&(_t.delete(e),e.i(t))}function F(e,t,n,i){if(e&&e.o){if(_t.has(e))return;_t.add(e),Qe.c.push(()=>{_t.delete(e),i&&(n&&e.d(1),i())}),e.o(t)}else i&&i()}function Ce(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function pe(e){e&&e.c()}function de(e,t,n){const{fragment:i,after_update:o}=e.$$;i&&i.m(t,n),Dt(()=>{const s=e.$$.on_mount.map(dn).filter(re);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ie(s),e.$$.on_mount=[]}),o.forEach(Dt)}function ge(e,t){const n=e.$$;n.fragment!==null&&(yo(n.after_update),Ie(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function _o(e,t){e.$$.dirty[0]===-1&&(Ke.push(e),Tn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function Oe(e,t,n,i,o,s,r=null,a=[-1]){const l=it;ot(e);const f=e.$$={fragment:null,ctx:[],props:s,update:q,not_equal:o,bound:gn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:gn(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};r&&r(f.root);let h=!1;if(f.ctx=n?n(e,t.props||{},(c,d,...y)=>{const g=y.length?y[0]:d;return f.ctx&&o(f.ctx[c],f.ctx[c]=g)&&(!f.skip_bound&&f.bound[c]&&f.bound[c](g),h&&_o(e,c)),d}):[],f.update(),h=!0,Ie(f.before_update),f.fragment=i?i(f.ctx):!1,t.target){if(t.hydrate){const c=ho(t.target);f.fragment&&f.fragment.l(c),c.forEach(H)}else f.fragment&&f.fragment.c();t.intro&&B(e.$$.fragment),de(e,t.target,t.anchor),On()}ot(l)}class Me{constructor(){se(this,"$$");se(this,"$$set")}$destroy(){ge(this,1),this.$destroy=q}$on(t,n){if(!re(n))return q;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(n),()=>{const o=i.indexOf(n);o!==-1&&i.splice(o,1)}}$set(t){this.$$set&&!lo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const mo="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(mo);var ie=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGLON="MULTIPOLYGON",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(ie||{});const Ht={},st=(e,t)=>Ht[e]=t,mt=e=>Ht[e.type].area(e),Mn=(e,t,n)=>Ht[e.type].intersects(e,t,n),Se=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),i=Math.max(i,s),o=Math.max(o,r)}),{minX:t,minY:n,maxX:i,maxY:o}},wt=e=>{let t=0,n=e.length-1;for(let i=0;i<e.length;i++)t+=(e[n][0]+e[i][0])*(e[n][1]-e[i][1]),n=i;return Math.abs(.5*t)},Et=(e,t,n)=>{let i=!1;for(let o=0,s=e.length-1;o<e.length;s=o++){const r=e[o][0],a=e[o][1],l=e[s][0],f=e[s][1];a>n!=f>n&&t<(l-r)*(n-a)/(f-a)+r&&(i=!i)}return i},Sn=(e,t=!0)=>{let n="M ";return e.forEach(([i,o],s)=>{s===0?n+=`${i},${o}`:n+=` L ${i},${o}`}),t&&(n+=" Z"),n},wo={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:i,cy:o,rx:s,ry:r}=e.geometry,a=0,l=Math.cos(a),f=Math.sin(a),h=t-i,c=n-o,d=l*h+f*c,y=f*h-l*c;return d*d/(s*s)+y*y/(r*r)<=1}};st(ie.ELLIPSE,wo);const Eo={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,i)=>{const[o,...s]=i.rings,r=wt(o.points),a=s.reduce((l,f)=>l+wt(f.points),0);return n+r-a},0)},intersects:(e,t,n)=>{const{polygons:i}=e.geometry;for(const o of i){const[s,...r]=o.rings;if(Et(s.points,t,n)){let a=!1;for(const l of r)if(Et(l.points,t,n)){a=!0;break}if(!a)return!0}}return!1}},bt=e=>{const t=e.reduce((n,i)=>[...n,...i.rings[0].points],[]);return Se(t)},De=e=>e.rings.map(n=>Sn(n.points)).join(" "),vn=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((i,o)=>[...i,...o.points],[])],[]);st(ie.MULTIPOLYGLON,Eo);const bo={area:e=>{const t=e.geometry.points;return wt(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return Et(i,t,n)}};st(ie.POLYGON,bo);const Cn={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};st(ie.RECTANGLE,Cn);const rt=e=>lt(e.target),lt=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,t=!1)=>{const n=typeof e=="string"?e:e.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,o=[...n.matchAll(i)][0],[s,r,a,l,f,h,c]=o;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,y,g,p]=[l,f,h,c].map(parseFloat);return{type:ie.RECTANGLE,geometry:{x:d,y,w:g,h:p,bounds:{minX:d,minY:t?y-p:y,maxX:d+g,maxY:t?y:y+p}}}},In=e=>{const{x:t,y:n,w:i,h:o}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${i},${o}`}},Rn="http://www.w3.org/2000/svg",Ln=e=>{const t=i=>{Array.from(i.attributes).forEach(o=>{o.name.startsWith("on")&&i.removeAttribute(o.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(e.querySelectorAll("*")).forEach(t),e},To=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Rn}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},kn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),i=n.lookupPrefix(Rn),o=n.lookupNamespaceURI(null);return i||o?Ln(n).firstChild:Ln(To(n)).firstChild},ue=" ";function Ao(e){let t="";Array.isArray(e)||(e=[e]);for(let n=0;n<e.length;n++){const i=e[n];if(i.type===M.CLOSE_PATH)t+="z";else if(i.type===M.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===M.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===M.MOVE_TO)t+=(i.relative?"m":"M")+i.x+ue+i.y;else if(i.type===M.LINE_TO)t+=(i.relative?"l":"L")+i.x+ue+i.y;else if(i.type===M.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+ue+i.y1+ue+i.x2+ue+i.y2+ue+i.x+ue+i.y;else if(i.type===M.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+ue+i.y2+ue+i.x+ue+i.y;else if(i.type===M.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+ue+i.y1+ue+i.x+ue+i.y;else if(i.type===M.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+ue+i.y;else if(i.type===M.ARC)t+=(i.relative?"a":"A")+i.rX+ue+i.rY+ue+i.xRot+ue+ +i.lArcFlag+ue+ +i.sweepFlag+ue+i.x+ue+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Vt([e,t],n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function Re(...e){for(let t=0;t<e.length;t++)if(typeof e[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof e[t]} == typeof ${e[t]}`);return!0}const Ye=Math.PI;function Yt(e,t,n){e.lArcFlag=e.lArcFlag===0?0:1,e.sweepFlag=e.sweepFlag===0?0:1;let{rX:i,rY:o}=e;const{x:s,y:r}=e;if(Math.abs(i)<1e-10||Math.abs(o)<1e-10){e.rX=0,e.rY=0,e.cX=(t+s)/2,e.cY=(n+r)/2,e.phi1=0,e.phi2=0;return}i=Math.abs(e.rX),o=Math.abs(e.rY);const a=e.xRot/180*Ye,[l,f]=Vt([(t-s)/2,(n-r)/2],-a),h=Math.pow(l,2)/Math.pow(i,2)+Math.pow(f,2)/Math.pow(o,2);1<h&&(i*=Math.sqrt(h),o*=Math.sqrt(h)),e.rX=i,e.rY=o;const c=Math.pow(i,2)*Math.pow(f,2)+Math.pow(o,2)*Math.pow(l,2),d=(e.lArcFlag!==e.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(o,2)-c)/c)),y=i*f/o*d,g=-o*l/i*d,p=Vt([y,g],a);e.cX=p[0]+(t+s)/2,e.cY=p[1]+(n+r)/2,e.phi1=Math.atan2((f-g)/o,(l-y)/i),e.phi2=Math.atan2((-f-g)/o,(-l-y)/i),e.sweepFlag===0&&e.phi2>e.phi1&&(e.phi2-=2*Ye),e.sweepFlag===1&&e.phi2<e.phi1&&(e.phi2+=2*Ye),e.phi1*=180/Ye,e.phi2*=180/Ye}function Pn(e,t,n){Re(e,t,n);const i=e*e+t*t-n*n;if(0>i)return[];if(i===0)return[[e*n/(e*e+t*t),t*n/(e*e+t*t)]];const o=Math.sqrt(i);return[[(e*n+t*o)/(e*e+t*t),(t*n-e*o)/(e*e+t*t)],[(e*n-t*o)/(e*e+t*t),(t*n+e*o)/(e*e+t*t)]]}const qe=Math.PI/180;function Dn(e,t,n){return(1-n)*e+n*t}function Un(e,t,n,i){return e+Math.cos(i/180*Ye)*t+Math.sin(i/180*Ye)*n}function Hn(e,t,n,i){const s=t-e,r=n-t,a=i-n,l=3*s+3*a-6*r,f=(r-s)*6,h=3*s;return Math.abs(l)<1e-6?Math.abs(f)<1e-6?[]:[-h/f]:Oo(f/l,h/l,1e-6)}function Vn(e,t,n,i,o){const s=1-o,r=s*s*s,a=3*s*s*o,l=3*s*o*o,f=o*o*o;return e*r+t*a+n*l+i*f}function Oo(e,t,n=1e-6){const i=e*e/4-t;if(i<-n)return[];if(i<=n)return[-e/2];const o=Math.sqrt(i);return[-(e/2)-o,-(e/2)+o]}function Mo(e,t,n){e.cX||Yt(e,t,n);const i=e.xRot/180*Ye;if(Math.abs(e.rX)<1e-10||Math.abs(e.rY)<1e-10)return[{relative:e.relative,type:M.CURVE_TO,x1:t+(e.x-t)/3,y1:n+(e.y-n)/3,x2:t+2*(e.x-t)/3,y2:n+2*(e.y-n)/3,x:e.x,y:e.y}];const o=Math.min(e.phi1,e.phi2),s=Math.max(e.phi1,e.phi2),r=s-o,a=Math.ceil(r/90),l=new Array(a);let f=t,h=n;const c=(d,y)=>{const[g,p]=Vt([d*e.rX,y*e.rY],i);return[e.cX+g,e.cY+p]};for(let d=0;d<a;d++){const y=Dn(e.phi1,e.phi2,d/a),g=Dn(e.phi1,e.phi2,(d+1)/a),p=g-y,O=4/3*Math.tan(p*qe/4),_=Math.cos(y*qe)-O*Math.sin(y*qe),T=Math.sin(y*qe)+O*Math.cos(y*qe),A=Math.cos(g*qe),S=Math.sin(g*qe),v=A+O*S,I=S-O*A,C=c(_,T),P=c(v,I),k=c(A,S),j={relative:e.relative,type:M.CURVE_TO,x:k[0],y:k[1],x1:C[0],y1:C[1],x2:P[0],y2:P[1]};e.relative&&(j.x1-=f,j.y1-=h,j.x2-=f,j.y2-=h,j.x-=f,j.y-=h),f=k[0],h=k[1],l[d]=j}return l}function Bt(e,t,n){const i=t[0]-e[0],o=t[1]-e[1],s=n[0]-e[0],r=n[1]-e[1],a=i*r-o*s;if(!(Math.abs(a)<1e-10))return!1;const f=i*s+o*r,h=i*i+o*o,c=s*s+r*r;return 0<=f&&f<=c&&h<=c}function So(e,t=!0){if(e.length<2)return e;const n=fe.INFO((s,r,a)=>({...s,x:s.x??r,y:s.y??a,relative:s.relative??!1})),i=[];let o=[];for(const s of e){const r=n(s);r.type===M.MOVE_TO&&o.length>0&&(t?i.push(...Tt(o)):i.unshift(...Tt(o)),o=[]),o.push(r)}return o.length>0&&(t?i.push(...Tt(o)):i.unshift(...Tt(o))),i}function Tt(e){var o;const t=((o=e[e.length-1])==null?void 0:o.type)===M.CLOSE_PATH,n=t?e.length-2:e.length-1,i=[{type:M.MOVE_TO,relative:!1,x:e[n].x,y:e[n].y}];for(let s=n;s>0;s--){const r=e[s],a=e[s-1];if(r.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(r.type){case M.HORIZ_LINE_TO:i.push({type:M.HORIZ_LINE_TO,relative:!1,x:a.x});break;case M.VERT_LINE_TO:i.push({type:M.VERT_LINE_TO,relative:!1,y:a.y});break;case M.LINE_TO:case M.MOVE_TO:i.push({type:M.LINE_TO,relative:!1,x:a.x,y:a.y});break;case M.CURVE_TO:i.push({type:M.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:r.x2,y1:r.y2,x2:r.x1,y2:r.y1});break;case M.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case M.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case M.ARC:throw new Error("Unsupported command: A (arc)");case M.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:M.CLOSE_PATH}),i}function vo(e=1e13){Re(e);function t(n){return Math.round(n*e)/e}return function(i){return"x1"in i&&typeof i.x1<"u"&&(i.x1=t(i.x1)),"y1"in i&&typeof i.y1<"u"&&(i.y1=t(i.y1)),"x2"in i&&typeof i.x2<"u"&&(i.x2=t(i.x2)),"y2"in i&&typeof i.y2<"u"&&(i.y2=t(i.y2)),"x"in i&&typeof i.x<"u"&&(i.x=t(i.x)),"y"in i&&typeof i.y<"u"&&(i.y=t(i.y)),"rX"in i&&typeof i.rX<"u"&&(i.rX=t(i.rX)),"rY"in i&&typeof i.rY<"u"&&(i.rY=t(i.rY)),i}}function Yn(){return Le((e,t,n)=>(e.relative&&(typeof e.x1<"u"&&(e.x1+=t),typeof e.y1<"u"&&(e.y1+=n),typeof e.x2<"u"&&(e.x2+=t),typeof e.y2<"u"&&(e.y2+=n),typeof e.x<"u"&&(e.x+=t),typeof e.y<"u"&&(e.y+=n),e.relative=!1),e))}function Co(){return Le((e,t,n)=>(e.relative||(typeof e.x1<"u"&&(e.x1-=t),typeof e.y1<"u"&&(e.y1-=n),typeof e.x2<"u"&&(e.x2-=t),typeof e.y2<"u"&&(e.y2-=n),typeof e.x<"u"&&(e.x-=t),typeof e.y<"u"&&(e.y-=n),e.relative=!0),e))}function No(e=!0,t=!0,n=!0,i=!0){return Le((o,s,r,a,l)=>{if(isNaN(a)&&!(o.type&M.MOVE_TO))throw new Error("path must start with moveto");if(t&&o.type&M.HORIZ_LINE_TO&&(o.type=M.LINE_TO,o.y=o.relative?0:r),n&&o.type&M.VERT_LINE_TO&&(o.type=M.LINE_TO,o.x=o.relative?0:s),e&&o.type&M.CLOSE_PATH&&(o.type=M.LINE_TO,o.x=o.relative?a-s:a,o.y=o.relative?l-r:l),o.type&M.ARC&&(o.rX===0||o.rY===0)&&(o.type=M.LINE_TO,delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag),i&&o.type&M.QUAD_TO){const f=[s,r],h=o.relative?[s+o.x1,r+o.y1]:[o.x1,o.y1],c=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Bt(f,h,c)&&(o.type=M.LINE_TO,delete o.x1,delete o.y1)}if(i&&o.type&M.CURVE_TO){const f=[s,r],h=o.relative?[s+o.x1,r+o.y1]:[o.x1,o.y1],c=o.relative?[s+o.x2,r+o.y2]:[o.x2,o.y2],d=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Bt(f,h,d)&&Bt(f,c,d)&&(o.type=M.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function Bn(){let e=NaN,t=NaN,n=NaN,i=NaN;return Le((o,s,r)=>(o.type&M.SMOOTH_CURVE_TO&&(o.type=M.CURVE_TO,e=isNaN(e)?s:e,t=isNaN(t)?r:t,o.x1=o.relative?s-e:2*s-e,o.y1=o.relative?r-t:2*r-t),o.type&M.CURVE_TO?(e=o.relative?s+o.x2:o.x2,t=o.relative?r+o.y2:o.y2):(e=NaN,t=NaN),o.type&M.SMOOTH_QUAD_TO&&(o.type=M.QUAD_TO,n=isNaN(n)?s:n,i=isNaN(i)?r:i,o.x1=o.relative?s-n:2*s-n,o.y1=o.relative?r-i:2*r-i),o.type&M.QUAD_TO?(n=o.relative?s+o.x1:o.x1,i=o.relative?r+o.y1:o.y1):(n=NaN,i=NaN),o))}function Xn(){let e=NaN,t=NaN;return Le((n,i,o)=>{if(n.type&M.SMOOTH_QUAD_TO&&(n.type=M.QUAD_TO,e=isNaN(e)?i:e,t=isNaN(t)?o:t,n.x1=n.relative?i-e:2*i-e,n.y1=n.relative?o-t:2*o-t),n.type&M.QUAD_TO){e=n.relative?i+n.x1:n.x1,t=n.relative?o+n.y1:n.y1;const s=n.x1,r=n.y1;n.type=M.CURVE_TO,n.x1=((n.relative?0:i)+s*2)/3,n.y1=((n.relative?0:o)+r*2)/3,n.x2=(n.x+s*2)/3,n.y2=(n.y+r*2)/3}else e=NaN,t=NaN;return n})}function Le(e){let t=0,n=0,i=NaN,o=NaN;return function(r){if(isNaN(i)&&!(r.type&M.MOVE_TO))throw new Error("path must start with moveto");const a=e(r,t,n,i,o);return r.type&M.CLOSE_PATH&&(t=i,n=o),"x"in r&&typeof r.x<"u"&&(t=r.relative?t+r.x:r.x),"y"in r&&typeof r.y<"u"&&(n=r.relative?n+r.y:r.y),r.type&M.MOVE_TO&&(i=t,o=n),a}}function Io(e=0){Re(e);let t=NaN,n=NaN,i=NaN,o=NaN;return Le((s,r,a,l,f)=>{const h=Math.abs;let c=!1,d=0,y=0;if(s.type&M.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:r-t,y=isNaN(n)?0:a-n),s.type&(M.CURVE_TO|M.SMOOTH_CURVE_TO)?(t=s.relative?r+s.x2:s.x2,n=s.relative?a+s.y2:s.y2):(t=NaN,n=NaN),s.type&M.SMOOTH_QUAD_TO?(i=isNaN(i)?r:2*r-i,o=isNaN(o)?a:2*a-o):s.type&M.QUAD_TO?(i=s.relative?r+s.x1:s.x1,o=s.relative?a+s.y1:s.y2):(i=NaN,o=NaN),s.type&M.LINE_COMMANDS||s.type&M.ARC&&(s.rX===0||s.rY===0||!s.lArcFlag)||s.type&M.CURVE_TO||s.type&M.SMOOTH_CURVE_TO||s.type&M.QUAD_TO||s.type&M.SMOOTH_QUAD_TO){const g=typeof s.x>"u"?0:s.relative?s.x:s.x-r,p=typeof s.y>"u"?0:s.relative?s.y:s.y-a;d=isNaN(i)?typeof s.x1>"u"?d:s.relative?s.x:s.x1-r:i-r,y=isNaN(o)?typeof s.y1>"u"?y:s.relative?s.y:s.y1-a:o-a;const O=typeof s.x2>"u"?0:s.relative?s.x:s.x2-r,_=typeof s.y2>"u"?0:s.relative?s.y:s.y2-a;h(g)<=e&&h(p)<=e&&h(d)<=e&&h(y)<=e&&h(O)<=e&&h(_)<=e&&(c=!0)}return s.type&M.CLOSE_PATH&&h(r-l)<=e&&h(a-f)<=e&&(c=!0),c?[]:s})}function Be(e,t,n,i,o,s){return Re(e,t,n,i,o,s),Le((r,a,l,f)=>{const h=r.x1,c=r.x2,d=r.relative&&!isNaN(f),y=typeof r.x<"u"?r.x:d?0:a,g=typeof r.y<"u"?r.y:d?0:l;r.type&M.HORIZ_LINE_TO&&t!==0&&(r.type=M.LINE_TO,r.y=r.relative?0:l),r.type&M.VERT_LINE_TO&&n!==0&&(r.type=M.LINE_TO,r.x=r.relative?0:a),typeof r.x<"u"&&(r.x=r.x*e+g*n+(d?0:o)),typeof r.y<"u"&&(r.y=y*t+r.y*i+(d?0:s)),typeof r.x1<"u"&&(r.x1=r.x1*e+r.y1*n+(d?0:o)),typeof r.y1<"u"&&(r.y1=h*t+r.y1*i+(d?0:s)),typeof r.x2<"u"&&(r.x2=r.x2*e+r.y2*n+(d?0:o)),typeof r.y2<"u"&&(r.y2=c*t+r.y2*i+(d?0:s));function p(_){return _*_}const O=e*i-t*n;if(typeof r.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(O===0)delete r.rX,delete r.rY,delete r.xRot,delete r.lArcFlag,delete r.sweepFlag,r.type=M.LINE_TO;else{const _=r.xRot*Math.PI/180,T=Math.sin(_),A=Math.cos(_),S=1/p(r.rX),v=1/p(r.rY),I=p(A)*S+p(T)*v,C=2*T*A*(S-v),P=p(T)*S+p(A)*v,k=I*i*i-C*t*i+P*t*t,j=C*(e*i+t*n)-2*(I*n*i+P*e*t),G=I*n*n-C*e*n+P*e*e,w=(Math.atan2(j,k-G)+Math.PI)%Math.PI/2,b=Math.sin(w),m=Math.cos(w);r.rX=Math.abs(O)/Math.sqrt(k*p(m)+j*b*m+G*p(b)),r.rY=Math.abs(O)/Math.sqrt(k*p(b)-j*b*m+G*p(m)),r.xRot=w*180/Math.PI}return typeof r.sweepFlag<"u"&&0>O&&(r.sweepFlag=+!r.sweepFlag),r})}function Ro(e,t=0,n=0){Re(e,t,n);const i=Math.sin(e),o=Math.cos(e);return Be(o,i,-i,o,t-t*o+n*i,n-t*i-n*o)}function Lo(e,t=0){return Re(e,t),Be(1,0,0,1,e,t)}function ko(e,t=e){return Re(e,t),Be(e,0,0,t,0,0)}function Po(e){return Re(e),Be(1,0,Math.tan(e),1,0,0)}function Do(e){return Re(e),Be(1,Math.tan(e),0,1,0,0)}function Uo(e=0){return Re(e),Be(-1,0,0,1,e,0)}function Ho(e=0){return Re(e),Be(1,0,0,-1,0,e)}function Vo(){return Le((e,t,n)=>M.ARC===e.type?Mo(e,e.relative?0:t,e.relative?0:n):e)}function Yo(){return Le((e,t,n)=>(e.relative&&(t=0,n=0),M.ARC===e.type&&Yt(e,t,n),e))}function Fn(){return e=>({...e})}function Bo(){const e=Fn(),t=Yn(),n=Xn(),i=Bn(),o=Le((s,r,a)=>{const l=i(n(t(e(s))));function f(c){c>o.maxX&&(o.maxX=c),c<o.minX&&(o.minX=c)}function h(c){c>o.maxY&&(o.maxY=c),c<o.minY&&(o.minY=c)}if(l.type&M.DRAWING_COMMANDS&&(f(r),h(a)),l.type&M.HORIZ_LINE_TO&&f(l.x),l.type&M.VERT_LINE_TO&&h(l.y),l.type&M.LINE_TO&&(f(l.x),h(l.y)),l.type&M.CURVE_TO){f(l.x),h(l.y);const c=Hn(r,l.x1,l.x2,l.x);for(const y of c)0<y&&1>y&&f(Vn(r,l.x1,l.x2,l.x,y));const d=Hn(a,l.y1,l.y2,l.y);for(const y of d)0<y&&1>y&&h(Vn(a,l.y1,l.y2,l.y,y))}if(l.type&M.ARC){f(l.x),h(l.y),Yt(l,r,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,y=Math.sin(c)*l.rX,g=-Math.sin(c)*l.rY,p=Math.cos(c)*l.rY,[O,_]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],T=([v,I])=>{const P=Math.atan2(I,v)*180/Math.PI;return P<O?P+360:P},A=Pn(g,-d,0).map(T);for(const v of A)v>O&&v<_&&f(Un(l.cX,d,g,v));const S=Pn(p,-y,0).map(T);for(const v of S)v>O&&v<_&&h(Un(l.cY,y,p,v))}return s});return o.minX=1/0,o.maxX=-1/0,o.minY=1/0,o.maxY=-1/0,o}const fe={ROUND:vo,TO_ABS:Yn,TO_REL:Co,NORMALIZE_HVZ:No,NORMALIZE_ST:Bn,QT_TO_C:Xn,INFO:Le,SANITIZE:Io,MATRIX:Be,ROTATE:Ro,TRANSLATE:Lo,SCALE:ko,SKEW_X:Po,SKEW_Y:Do,X_AXIS_SYMMETRY:Uo,Y_AXIS_SYMMETRY:Ho,A_TO_C:Vo,ANNOTATE_ARCS:Yo,CLONE:Fn,CALCULATE_BOUNDS:Bo,REVERSE_PATH:So};class zn{round(t){return this.transform(fe.ROUND(t))}toAbs(){return this.transform(fe.TO_ABS())}toRel(){return this.transform(fe.TO_REL())}normalizeHVZ(t,n,i){return this.transform(fe.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(fe.NORMALIZE_ST())}qtToC(){return this.transform(fe.QT_TO_C())}aToC(){return this.transform(fe.A_TO_C())}sanitize(t){return this.transform(fe.SANITIZE(t))}translate(t,n){return this.transform(fe.TRANSLATE(t,n))}scale(t,n){return this.transform(fe.SCALE(t,n))}rotate(t,n,i){return this.transform(fe.ROTATE(t,n,i))}matrix(t,n,i,o,s,r){return this.transform(fe.MATRIX(t,n,i,o,s,r))}skewX(t){return this.transform(fe.SKEW_X(t))}skewY(t){return this.transform(fe.SKEW_Y(t))}xSymmetry(t){return this.transform(fe.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(fe.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(fe.ANNOTATE_ARCS())}}const Xo=e=>e===" "||e===" "||e==="\r"||e===`
|
|
2
|
+
`,jn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class Fo extends zn{constructor(){super();se(this,"curNumber","");se(this,"curCommandType",-1);se(this,"curCommandRelative",!1);se(this,"canParseCommandOrComma",!0);se(this,"curNumberHasExp",!1);se(this,"curNumberHasExpDigits",!1);se(this,"curNumberHasDecimal",!1);se(this,"curArgs",[])}finish(n=[]){if(this.parse(" ",n),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return n}parse(n,i=[]){const o=s=>{i.push(s),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let s=0;s<n.length;s++){const r=n[s],a=this.curCommandType===M.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),l=jn(r)&&(this.curNumber==="0"&&r==="0"||a);if(jn(r)&&!l){this.curNumber+=r,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(r==="e"||r==="E"){this.curNumber+=r,this.curNumberHasExp=!0;continue}if((r==="-"||r==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=r;continue}if(r==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!a){this.curNumber+=r,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const f=Number(this.curNumber);if(isNaN(f))throw new SyntaxError(`Invalid number ending at ${s}`);if(this.curCommandType===M.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>f)throw new SyntaxError(`Expected positive number, got "${f}" at index "${s}"`)}else if((this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber!=="0"&&this.curNumber!=="1")throw new SyntaxError(`Expected a flag, got "${this.curNumber}" at index "${s}"`)}this.curArgs.push(f),this.curArgs.length===zo[this.curCommandType]&&(M.HORIZ_LINE_TO===this.curCommandType?o({type:M.HORIZ_LINE_TO,relative:this.curCommandRelative,x:f}):M.VERT_LINE_TO===this.curCommandType?o({type:M.VERT_LINE_TO,relative:this.curCommandRelative,y:f}):this.curCommandType===M.MOVE_TO||this.curCommandType===M.LINE_TO||this.curCommandType===M.SMOOTH_QUAD_TO?(o({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),M.MOVE_TO===this.curCommandType&&(this.curCommandType=M.LINE_TO)):this.curCommandType===M.CURVE_TO?o({type:M.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===M.SMOOTH_CURVE_TO?o({type:M.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===M.QUAD_TO?o({type:M.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===M.ARC&&o({type:M.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!Xo(r)){if(r===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(r==="+"||r==="-"||r==="."){this.curNumber=r,this.curNumberHasDecimal=r===".";continue}if(l){this.curNumber=r,this.curNumberHasDecimal=!1;continue}if(this.curArgs.length!==0)throw new SyntaxError(`Unterminated command at index ${s}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${r}" at index ${s}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,r==="z"||r==="Z"){i.push({type:M.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(r==="h"||r==="H")this.curCommandType=M.HORIZ_LINE_TO,this.curCommandRelative=r==="h";else if(r==="v"||r==="V")this.curCommandType=M.VERT_LINE_TO,this.curCommandRelative=r==="v";else if(r==="m"||r==="M")this.curCommandType=M.MOVE_TO,this.curCommandRelative=r==="m";else if(r==="l"||r==="L")this.curCommandType=M.LINE_TO,this.curCommandRelative=r==="l";else if(r==="c"||r==="C")this.curCommandType=M.CURVE_TO,this.curCommandRelative=r==="c";else if(r==="s"||r==="S")this.curCommandType=M.SMOOTH_CURVE_TO,this.curCommandRelative=r==="s";else if(r==="q"||r==="Q")this.curCommandType=M.QUAD_TO,this.curCommandRelative=r==="q";else if(r==="t"||r==="T")this.curCommandType=M.SMOOTH_QUAD_TO,this.curCommandRelative=r==="t";else if(r==="a"||r==="A")this.curCommandType=M.ARC,this.curCommandRelative=r==="a";else throw new SyntaxError(`Unexpected character "${r}" at index ${s}.`)}}return i}transform(n){return Object.create(this,{parse:{value(o,s=[]){const r=Object.getPrototypeOf(this).parse.call(this,o);for(const a of r){const l=n(a);Array.isArray(l)?s.push(...l):s.push(l)}return s}}})}}const ne=class ne extends zn{constructor(n){super();se(this,"commands");typeof n=="string"?this.commands=ne.parse(n):this.commands=n}encode(){return ne.encode(this.commands)}getBounds(){const n=fe.CALCULATE_BOUNDS();return this.transform(n),n}transform(n){const i=[];for(const o of this.commands){const s=n(o);Array.isArray(s)?i.push(...s):i.push(s)}return this.commands=i,this}reverse(n=!0){return this.commands=fe.REVERSE_PATH(this.commands,n),this}static encode(n){return Ao(n)}static parse(n){const i=new Fo,o=[];return i.parse(n,o),i.finish(o),o}};se(ne,"CLOSE_PATH",1),se(ne,"MOVE_TO",2),se(ne,"HORIZ_LINE_TO",4),se(ne,"VERT_LINE_TO",8),se(ne,"LINE_TO",16),se(ne,"CURVE_TO",32),se(ne,"SMOOTH_CURVE_TO",64),se(ne,"QUAD_TO",128),se(ne,"SMOOTH_QUAD_TO",256),se(ne,"ARC",512),se(ne,"LINE_COMMANDS",ne.LINE_TO|ne.HORIZ_LINE_TO|ne.VERT_LINE_TO),se(ne,"DRAWING_COMMANDS",ne.HORIZ_LINE_TO|ne.VERT_LINE_TO|ne.LINE_TO|ne.CURVE_TO|ne.SMOOTH_CURVE_TO|ne.QUAD_TO|ne.SMOOTH_QUAD_TO|ne.ARC);let M=ne;const zo={[M.MOVE_TO]:2,[M.LINE_TO]:2,[M.HORIZ_LINE_TO]:1,[M.VERT_LINE_TO]:1,[M.CLOSE_PATH]:0,[M.QUAD_TO]:4,[M.SMOOTH_QUAD_TO]:2,[M.CURVE_TO]:6,[M.SMOOTH_CURVE_TO]:4,[M.ARC]:7},jo=e=>{const t=new M(e).toAbs().commands,n=[];let i=[],o=null;for(const s of t)switch(s.type){case M.MOVE_TO:i.length>0&&(n.push({points:i}),i=[]),o=[s.x,s.y],i.push(o);break;case M.LINE_TO:i.push([s.x,s.y]);break;case M.HORIZ_LINE_TO:const r=i[i.length-1][1];i.push([s.x,r]);break;case M.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,s.y]);break;case M.CURVE_TO:case M.SMOOTH_CURVE_TO:case M.QUAD_TO:case M.SMOOTH_QUAD_TO:case M.ARC:i.push([s.x,s.y]);break}if(i.length>2&&n.push({points:i}),n.length>0){const s=Se(n[0].points);return{rings:n,bounds:s}}},Go=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:ie.POLYGON,geometry:{points:o,bounds:Se(o)}}},Qo=e=>{const t=kn(e),n=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),o=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-o,minY:i-s,maxX:n+o,maxY:i+s};return{type:ie.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:s,bounds:r}}},qo=e=>{const t=kn(e),o=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(l=>l.getAttribute("d")||"").map(l=>jo(l)).filter(Boolean),s=o.reduce((l,f)=>[...l,...f.rings[0].points],[]),r=Se(s);return o.length===1&&o[0].rings.length===1?{type:ie.POLYGON,geometry:{points:s,bounds:r}}:{type:ie.MULTIPOLYGLON,geometry:{polygons:o,bounds:r}}},Gn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Go(t);if(t.includes("<path "))return qo(t);if(t.includes("<ellipse "))return Qo(t);throw"Unsupported SVG shape: "+t},Zo=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${De(n)}" />`).join("")}</g>`,Qn=e=>{let t;if(e.type===ie.POLYGON){const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`}else if(e.type===ie.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}else if(e.type===ie.MULTIPOLYGLON){const n=e.geometry;t=`<svg>${Zo(n)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},ye=[];for(let e=0;e<256;++e)ye.push((e+256).toString(16).slice(1));function Ko(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 Xt;const Wo=new Uint8Array(16);function Jo(){if(!Xt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Xt=crypto.getRandomValues.bind(crypto)}return Xt(Wo)}const qn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Zn(e,t,n){var o;if(qn.randomUUID&&!e)return qn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Jo();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,Ko(i)}var Kn=Object.prototype.hasOwnProperty;function Xe(e,t){var n,i;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((i=e.length)===t.length)for(;i--&&Xe(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(Kn.call(e,n)&&++i&&!Kn.call(t,n)||!(n in t)||!Xe(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}function Ft(){}function xo(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const xe=[];function zt(e,t=Ft){let n;const i=new Set;function o(a){if(xo(e,a)&&(e=a,n)){const l=!xe.length;for(const f of i)f[1](),xe.push(f,e);if(l){for(let f=0;f<xe.length;f+=2)xe[f][0](xe[f+1]);xe.length=0}}}function s(a){o(a(e))}function r(a,l=Ft){const f=[a,l];return i.add(f),i.size===1&&(n=t(o,s)||Ft),a(e),()=>{i.delete(f),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const $o=e=>{const{subscribe:t,set:n}=zt();let i;return t(o=>i=o),e.observe(({changes:o})=>{if(i){(o.deleted||[]).some(r=>r.id===i)&&n(void 0);const s=(o.updated||[]).find(({oldValue:r})=>r.id===i);s&&n(s.newValue.id)}}),{get current(){return i},subscribe:t,set:n}};var jt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(jt||{});const At={selected:[]},es=(e,t,n)=>{const{subscribe:i,set:o}=zt(At);let s=t,r=At;i(g=>r=g);const a=()=>{Xe(r,At)||o(At)},l=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},f=g=>{if(l())return!1;const p=typeof g=="string"?g:g.id;return r.selected.some(O=>O.id===p)},h=(g,p)=>{let O;if(Array.isArray(g)){if(O=g.map(T=>e.getAnnotation(T)).filter(Boolean),O.length<g.length){console.warn("Invalid selection: "+g.filter(T=>!O.some(A=>A.id===T)));return}}else{const T=e.getAnnotation(g);if(!T){console.warn("Invalid selection: "+g);return}O=[T]}const _=O.reduce((T,A)=>{const S=Wn(A,s,n);return S==="EDIT"?[...T,{id:A.id,editable:!0}]:S==="SELECT"?[...T,{id:A.id}]:T},[]);o({selected:_,event:p})},c=(g,p)=>{const O=Array.isArray(g)?g:[g],_=O.map(T=>e.getAnnotation(T)).filter(T=>!!T);o({selected:_.map(T=>{const A=p===void 0?Wn(T,s,n)==="EDIT":p;return{id:T.id,editable:A}})}),_.length!==O.length&&console.warn("Invalid selection",g)},d=g=>{if(l())return!1;const{selected:p}=r;p.some(({id:O})=>g.includes(O))&&o({selected:p.filter(({id:O})=>!g.includes(O))})},y=g=>{s=g,c(r.selected.map(({id:p})=>p))};return e.observe(({changes:g})=>d((g.deleted||[]).map(p=>p.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:a,isEmpty:l,isSelected:f,setSelected:c,setUserSelectAction:y,subscribe:i,userSelect:h}},Wn=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},_e=[];for(let e=0;e<256;++e)_e.push((e+256).toString(16).slice(1));function ts(e,t=0){return(_e[e[t+0]]+_e[e[t+1]]+_e[e[t+2]]+_e[e[t+3]]+"-"+_e[e[t+4]]+_e[e[t+5]]+"-"+_e[e[t+6]]+_e[e[t+7]]+"-"+_e[e[t+8]]+_e[e[t+9]]+"-"+_e[e[t+10]]+_e[e[t+11]]+_e[e[t+12]]+_e[e[t+13]]+_e[e[t+14]]+_e[e[t+15]]).toLowerCase()}let Gt;const ns=new Uint8Array(16);function is(){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(ns)}const os=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Jn={randomUUID:os};function xn(e,t,n){var i;if(Jn.randomUUID&&!e)return Jn.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??is();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,ts(o)}const Qt=e=>{const t=n=>{const i={...n};return n.created&&typeof n.created=="string"&&(i.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(i.updated=new Date(n.updated)),i};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},ss=(e,t,n,i)=>({id:xn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),rs=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},ls=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},as=(e,t)=>t.bodies.map(n=>{const i=e.bodies.find(o=>o.id===n.id);return{newBody:n,oldBody:i&&!Xe(i,n)?i:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:i})=>({oldBody:n,newBody:i})),us=(e,t)=>!Xe(e.target,t.target),$n=(e,t)=>{const n=rs(e,t),i=ls(e,t),o=as(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:o.length>0?o:void 0,targetUpdated:us(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 fs=(e,t)=>{var n,i;const{changes:o,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>l&&l.length>0;if(!(a(o.created)||a(o.deleted))){const l=(n=o.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),f=(i=o.updated)==null?void 0:i.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!f||r==="TARGET_ONLY"&&f&&!l)return!1}}if(e.options.annotations){const r=new Set([...(o.created||[]).map(a=>a.id),...(o.deleted||[]).map(a=>a.id),...(o.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},cs=(e,t)=>{const n=new Set((e.created||[]).map(c=>c.id)),i=new Set((e.updated||[]).map(({newValue:c})=>c.id)),o=new Set((t.created||[]).map(c=>c.id)),s=new Set((t.deleted||[]).map(c=>c.id)),r=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>n.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(e.created||[]).filter(c=>!s.has(c.id)).map(c=>r.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],f=[...(e.deleted||[]).filter(c=>!o.has(c.id)),...(t.deleted||[]).filter(c=>!n.has(c.id))],h=[...(e.updated||[]).filter(({newValue:c})=>!s.has(c.id)).map(c=>{const{oldValue:d,newValue:y}=c;if(r.has(y.id)){const g=t.updated.find(p=>p.oldValue.id===y.id).newValue;return $n(d,g)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:f,updated:h}},Ot=e=>{const t=e.id===void 0?xn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},hs=e=>e.id!==void 0,ds=()=>{const e=new Map,t=new Map,n=[],i=(w,b={})=>{n.push({onChange:w,options:b})},o=w=>{const b=n.findIndex(m=>m.onChange==w);b>-1&&n.splice(b,1)},s=(w,b)=>{const m={origin:w,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(E=>{fs(E,m)&&E.onChange(m)})},r=(w,b=oe.LOCAL)=>{if(w.id&&e.get(w.id))throw Error(`Cannot add annotation ${w.id} - exists already`);{const m=Ot(w);e.set(m.id,m),m.bodies.forEach(E=>t.set(E.id,m.id)),s(b,{created:[m]})}},a=(w,b)=>{const m=Ot(typeof w=="string"?b:w),E=typeof w=="string"?w:w.id,R=E&&e.get(E);if(R){const N=$n(R,m);return E===m.id?e.set(E,m):(e.delete(E),e.set(m.id,m)),R.bodies.forEach(D=>t.delete(D.id)),m.bodies.forEach(D=>t.set(D.id,m.id)),N}else console.warn(`Cannot update annotation ${E} - does not exist`)},l=(w,b=oe.LOCAL,m=oe.LOCAL)=>{const E=hs(b)?m:b,R=a(w,b);R&&s(E,{updated:[R]})},f=(w,b=oe.LOCAL)=>{e.get(w.id)?l(w,b):r(w,b)},h=(w,b=oe.LOCAL)=>{const m=w.reduce((E,R)=>{const N=a(R);return N?[...E,N]:E},[]);m.length>0&&s(b,{updated:m})},c=(w,b=oe.LOCAL)=>{const m=w.map(Ot),{toAdd:E,toUpdate:R}=m.reduce((D,Q)=>e.get(Q.id)?{...D,toUpdate:[...D.toUpdate,Q]}:{...D,toAdd:[...D.toAdd,Q]},{toAdd:[],toUpdate:[]}),N=R.map(D=>a(D,b)).filter(Boolean);E.forEach(D=>{e.set(D.id,D),D.bodies.forEach(Q=>t.set(Q.id,D.id))}),s(b,{created:E,updated:N})},d=(w,b=oe.LOCAL)=>{const m=e.get(w.annotation);if(m){const E={...m,bodies:[...m.bodies,w]};e.set(m.id,E),t.set(w.id,E.id),s(b,{updated:[{oldValue:m,newValue:E,bodiesCreated:[w]}]})}else console.warn(`Attempt to add body to missing annotation: ${w.annotation}`)},y=()=>[...e.values()],g=(w=oe.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(w,{deleted:b})},p=(w,b=!0,m=oe.LOCAL)=>{const E=w.map(Ot);if(b){const R=[...e.values()];e.clear(),t.clear(),E.forEach(N=>{e.set(N.id,N),N.bodies.forEach(D=>t.set(D.id,N.id))}),s(m,{created:E,deleted:R})}else{const R=w.reduce((N,D)=>{const Q=D.id&&e.get(D.id);return Q?[...N,Q]:N},[]);if(R.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${R.map(N=>N.id).join(", ")}`);E.forEach(N=>{e.set(N.id,N),N.bodies.forEach(D=>t.set(D.id,N.id))}),s(m,{created:E})}},O=w=>{const b=typeof w=="string"?w:w.id,m=e.get(b);if(m)return e.delete(b),m.bodies.forEach(E=>t.delete(E.id)),m;console.warn(`Attempt to delete missing annotation: ${b}`)},_=(w,b=oe.LOCAL)=>{const m=O(w);m&&s(b,{deleted:[m]})},T=(w,b=oe.LOCAL)=>{const m=w.reduce((E,R)=>{const N=O(R);return N?[...E,N]:E},[]);m.length>0&&s(b,{deleted:m})},A=w=>{const b=e.get(w.annotation);if(b){const m=b.bodies.find(E=>E.id===w.id);if(m){t.delete(m.id);const E={...b,bodies:b.bodies.filter(R=>R.id!==w.id)};return e.set(b.id,E),{oldValue:b,newValue:E,bodiesDeleted:[m]}}else console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${w.annotation}`)},S=(w,b=oe.LOCAL)=>{const m=A(w);m&&s(b,{updated:[m]})},v=(w,b=oe.LOCAL)=>{const m=w.map(E=>A(E)).filter(Boolean);m.length>0&&s(b,{updated:m})},I=w=>{const b=e.get(w);return b?{...b}:void 0},C=w=>{const b=t.get(w);if(b){const m=I(b).bodies.find(E=>E.id===w);if(m)return m;console.error(`Store integrity error: body ${w} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${w}`)},P=(w,b)=>{if(w.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const m=e.get(w.annotation);if(m){const E=m.bodies.find(N=>N.id===w.id),R={...m,bodies:m.bodies.map(N=>N.id===E.id?b:N)};return e.set(m.id,R),E.id!==b.id&&(t.delete(E.id),t.set(b.id,R.id)),{oldValue:m,newValue:R,bodiesUpdated:[{oldBody:E,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${w.annotation}`)},k=(w,b,m=oe.LOCAL)=>{const E=P(w,b);E&&s(m,{updated:[E]})},j=(w,b=oe.LOCAL)=>{const m=w.map(E=>P({id:E.id,annotation:E.annotation},E)).filter(Boolean);s(b,{updated:m})},G=w=>{const b=e.get(w.annotation);if(b){const m={...b,target:{...b.target,...w}};return e.set(b.id,m),{oldValue:b,newValue:m,targetUpdated:{oldTarget:b.target,newTarget:w}}}else console.warn(`Attempt to update target on missing annotation: ${w.annotation}`)};return{addAnnotation:r,addBody:d,all:y,bulkAddAnnotations:p,bulkDeleteAnnotations:T,bulkDeleteBodies:v,bulkUpdateAnnotations:h,bulkUpdateBodies:j,bulkUpdateTargets:(w,b=oe.LOCAL)=>{const m=w.map(E=>G(E)).filter(Boolean);m.length>0&&s(b,{updated:m})},bulkUpsertAnnotations:c,clear:g,deleteAnnotation:_,deleteBody:S,getAnnotation:I,getBody:C,observe:i,unobserve:o,updateAnnotation:l,updateBody:k,updateTarget:(w,b=oe.LOCAL)=>{const m=G(w);m&&s(b,{updated:[m]})},upsertAnnotation:f}},gs=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let ps=()=>({emit(e,...t){for(let n=this.events[e]||[],i=0,o=n.length;i<o;i++)n[i](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var i;this.events[e]=(i=this.events[e])==null?void 0:i.filter(o=>t!==o)}}});const ys=250,_s=(e,t)=>{const n=ps(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,s=!1,r=0;const a=g=>{if(!s){const{changes:p}=g,O=performance.now();if(O-r>ys)i.splice(o+1),i.push(p),o=i.length-1;else{const _=i.length-1;i[_]=cs(i[_],p)}r=O}s=!1};e.observe(a,{origin:oe.LOCAL});const l=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g),f=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),h=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({oldValue:p})=>p)),c=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({newValue:p})=>p)),d=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),y=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g);return{canRedo:()=>i.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...i],pointer:o}),on:(g,p)=>n.on(g,p),redo:()=>{if(i.length-1>o){s=!0;const{created:g,updated:p,deleted:O}=i[o+1];f(g),c(p),y(O),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){s=!0;const{created:g,updated:p,deleted:O}=i[o];l(g),h(p),d(O),n.emit("undo",i[o]),o-=1}}}},ms=()=>{const{subscribe:e,set:t}=zt([]);return{subscribe:e,set:t}},ws=(e,t,n,i)=>{const{hover:o,selection:s,store:r,viewport:a}=e,l=new Map;let f=[],h,c;const d=(_,T)=>{l.has(_)?l.get(_).push(T):l.set(_,[T])},y=(_,T)=>{const A=l.get(_);if(A){const S=A.indexOf(T);S!==-1&&A.splice(S,1)}},g=(_,T,A)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(S=>{if(n){const v=Array.isArray(T)?T.map(C=>n.serialize(C)):n.serialize(T),I=A?A instanceof PointerEvent?A:n.serialize(A):void 0;S(v,I)}else S(T,A)})},1)},p=()=>{const{selected:_}=s,T=(_||[]).map(({id:A})=>r.getAnnotation(A));T.forEach(A=>{const S=f.find(v=>v.id===A.id);(!S||!Xe(S,A))&&g("updateAnnotation",A,S)}),f=f.map(A=>T.find(({id:v})=>v===A.id)||A)};s.subscribe(({selected:_})=>{if(!(f.length===0&&_.length===0)){if(f.length===0&&_.length>0)f=_.map(({id:T})=>r.getAnnotation(T));else if(f.length>0&&_.length===0)f.forEach(T=>{const A=r.getAnnotation(T.id);A&&!Xe(A,T)&&g("updateAnnotation",A,T)}),f=[];else{const T=new Set(f.map(S=>S.id)),A=new Set(_.map(({id:S})=>S));f.filter(S=>!A.has(S.id)).forEach(S=>{const v=r.getAnnotation(S.id);v&&!Xe(v,S)&&g("updateAnnotation",v,S)}),f=[...f.filter(S=>A.has(S.id)),..._.filter(({id:S})=>!T.has(S)).map(({id:S})=>r.getAnnotation(S))]}g("selectionChanged",f)}}),o.subscribe(_=>{!h&&_?g("mouseEnterAnnotation",r.getAnnotation(_)):h&&!_?g("mouseLeaveAnnotation",r.getAnnotation(h)):h&&_&&(g("mouseLeaveAnnotation",r.getAnnotation(h)),g("mouseEnterAnnotation",r.getAnnotation(_))),h=_}),a==null||a.subscribe(_=>g("viewportIntersect",_.map(T=>r.getAnnotation(T)))),r.observe(_=>{i&&(c&&clearTimeout(c),c=setTimeout(p,1e3));const{created:T,deleted:A}=_.changes;(T||[]).forEach(S=>g("createAnnotation",S)),(A||[]).forEach(S=>g("deleteAnnotation",S)),(_.changes.updated||[]).filter(S=>[...S.bodiesCreated||[],...S.bodiesDeleted||[],...S.bodiesUpdated||[]].length>0).forEach(({oldValue:S,newValue:v})=>{const I=f.find(C=>C.id===S.id)||S;f=f.map(C=>C.id===S.id?v:C),g("updateAnnotation",v,I)})},{origin:oe.LOCAL}),r.observe(_=>{if(f){const T=new Set(f.map(S=>S.id)),A=(_.changes.updated||[]).filter(({newValue:S})=>T.has(S.id)).map(({newValue:S})=>S);A.length>0&&(f=f.map(S=>A.find(I=>I.id===S.id)||S))}},{origin:oe.REMOTE});const O=_=>T=>{const{updated:A}=T;_?(A||[]).forEach(S=>g("updateAnnotation",S.oldValue,S.newValue)):(A||[]).forEach(S=>g("updateAnnotation",S.newValue,S.oldValue))};return t.on("undo",O(!0)),t.on("redo",O(!1)),{on:d,off:y,emit:g}},Es=e=>t=>t.reduce((n,i)=>{const{parsed:o,error:s}=e.parse(i);return s?{parsed:n.parsed,failed:[...n.failed,i]}:o?{parsed:[...n.parsed,o],failed:n.failed}:{...n}},{parsed:[],failed:[]}),bs=(e,t,n)=>{const{store:i,selection:o}=e,s=_=>{if(n){const{parsed:T,error:A}=n.parse(_);T?i.addAnnotation(T,oe.REMOTE):console.error(A)}else i.addAnnotation(Qt(_),oe.REMOTE)},r=()=>o.clear(),a=()=>i.clear(),l=_=>{const T=i.getAnnotation(_);return n&&T?n.serialize(T):T},f=()=>n?i.all().map(n.serialize):i.all(),h=()=>{var _;const T=(((_=o.selected)==null?void 0:_.map(A=>A.id))||[]).map(A=>i.getAnnotation(A)).filter(Boolean);return n?T.map(n.serialize):T},c=(_,T=!0)=>fetch(_).then(A=>A.json()).then(A=>(y(A,T),A)),d=_=>{if(typeof _=="string"){const T=i.getAnnotation(_);if(i.deleteAnnotation(_),T)return n?n.serialize(T):T}else{const T=n?n.parse(_).parsed:_;if(T)return i.deleteAnnotation(T),_}},y=(_,T=!0)=>{if(n){const A=n.parseAll||Es(n),{parsed:S,failed:v}=A(_);v.length>0&&console.warn(`Discarded ${v.length} invalid annotations`,v),i.bulkAddAnnotations(S,T,oe.REMOTE)}else i.bulkAddAnnotations(_.map(Qt),T,oe.REMOTE)},g=(_,T)=>{_?o.setSelected(_,T):o.clear()},p=_=>{o.clear(),o.setUserSelectAction(_)},O=_=>{if(n){const T=n.parse(_).parsed,A=n.serialize(i.getAnnotation(T.id));return i.updateAnnotation(T),A}else{const T=i.getAnnotation(_.id);return i.updateAnnotation(Qt(_)),T}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:f,getHistory:t.getHistory,getSelected:h,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:y,setSelected:g,setUserSelectAction:p,undo:t.undo,updateAnnotation:O}},Ts=(e,t,n)=>typeof t=="function"?t(e,n):t,As=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,i)=>{const o=typeof e=="function"?e(n,i):e,s=typeof t=="function"?t(n,i):t;return{...o||{},...s||{}}},Os="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Ms=e=>crypto.getRandomValues(new Uint8Array(e)),Ss=(e,t,n)=>{let i=(2<<Math.log2(e.length-1))-1,o=-~(1.6*i*t/e.length);return(s=t)=>{let r="";for(;;){let a=n(o),l=o|0;for(;l--;)if(r+=e[a[l]&i]||"",r.length>=s)return r}}},vs=(e,t=21)=>Ss(e,t|0,Ms),Cs=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Os[n[e]&63];return t};const Ns=()=>({isGuest:!0,id:vs("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Is=e=>{const t=JSON.stringify(e);let n=0;for(let i=0,o=t.length;i<o;i++){let s=t.charCodeAt(i);n=(n<<5)-n+s,n|=0}return`${n}`},ei=e=>e?typeof e=="object"?{...e}:e:void 0,Rs=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:i,type:o,purpose:s,value:r,created:a,modified:l,creator:f,...h}=n;return{id:i||`temp-${Is(n)}`,annotation:t,type:o,purpose:s,value:r,creator:ei(f),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...h}}),Ls=e=>e.map(t=>{var n;const{annotation:i,created:o,updated:s,...r}=t,a={...r,created:o==null?void 0:o.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a}),ks=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Ps=()=>{const e=[...ks];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};Cs();const Ds=(e,t={strict:!0,invertY:!1})=>({parse:o=>ti(o,t),serialize:o=>ni(o,e,t)}),ti=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Zn(),{creator:i,created:o,modified:s,body:r,...a}=e,l=Rs(r||[],n),f=Array.isArray(e.target)?e.target[0]:e.target,h=typeof f=="string"?f:Array.isArray(f.selector)?f.selector[0]:f.selector,c=typeof h=="string"||(h==null?void 0:h.type)==="FragmentSelector"?Nn(h,t.invertY):(h==null?void 0:h.type)==="SvgSelector"?Gn(h):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return c||!t.strict?{parsed:{...a,id:n,bodies:l,target:{created:o?new Date(o):void 0,creator:ei(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:n,selector:c||h}}}:{error:Error(`Invalid selector: ${JSON.stringify(h)}`)}},ni=(e,t,n={strict:!0,invertY:!1})=>{const{selector:i,creator:o,created:s,updated:r,updatedBy:a,...l}=e.target;let f;try{f=i.type==ie.RECTANGLE?In(i.geometry):Qn(i)}catch(c){if(n.strict)throw c;f=i}const h={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Ls(e.bodies),created:s==null?void 0:s.toISOString(),creator:o,modified:r==null?void 0:r.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:f}};return delete h.bodies,"annotation"in h.target&&delete h.target.annotation,h},Mt=(e,t)=>{const n=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(i,2))},$e=[];function Us(e,t=q){let n;const i=new Set;function o(a){if(ce(e,a)&&(e=a,n)){const l=!$e.length;for(const f of i)f[1](),$e.push(f,e);if(l){for(let f=0;f<$e.length;f+=2)$e[f][0]($e[f+1]);$e.length=0}}}function s(a){o(a(e))}function r(a,l=q){const f=[a,l];return i.add(f),i.size===1&&(n=t(o,s)||q),a(e),()=>{i.delete(f),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const Hs=(e,t)=>{const{naturalWidth:n,naturalHeight:i}=e;if(!n&&!i){const{width:o,height:s}=e;t.setAttribute("viewBox",`0 0 ${o} ${s}`),e.addEventListener("load",r=>{const a=r.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${i}`)},ii=(e,t)=>{Hs(e,t);const{subscribe:n,set:i}=Us(1);let o;return window.ResizeObserver&&(o=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,f=Math.max(r.width/a,r.height/l);i(f)}),o.observe(t.parentElement)),{destroy:()=>{o&&o.disconnect()},subscribe:n}},at=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:i,fillOpacity:o,stroke:s,strokeWidth:r,strokeOpacity:a}=n;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${o||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${r||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},ut=(e,t=0)=>{const{minX:n,minY:i,maxX:o,maxY:s}=e;return{x:n-t,y:i-t,w:o-n+2*t,h:s-i+2*t}},Ue=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Vs=e=>({}),oi=e=>({grab:e[0]});function Ys(e){let t,n,i,o;const s=e[8].default,r=ao(s,e,e[7],oi);return{c(){t=L("g"),r&&r.c(),u(t,"class","a9s-annotation selected")},m(a,l){V(a,t,l),r&&r.m(t,null),n=!0,i||(o=[$(t,"pointerup",e[2]),$(t,"pointermove",e[1])],i=!0)},p(a,[l]){r&&r.p&&(!n||l&128)&&fo(r,s,a,a[7],n?uo(s,a[7],l,Vs):co(a[7]),oi)},i(a){n||(B(r,a),n=!0)},o(a){F(r,a),n=!1},d(a){a&&H(t),r&&r.d(a),i=!1,Ie(o)}}}function Bs(e,t,n){let{$$slots:i={},$$scope:o}=t;const s=Ve();let{shape:r}=t,{editor:a}=t,{transform:l}=t,{svgEl:f}=t,h,c,d;const y=O=>_=>{if(h=O,f){const{left:A,top:S}=f.getBoundingClientRect(),v=_.clientX-A,I=_.clientY-S;c=l.elementToImage(v,I)}else{const{offsetX:A,offsetY:S}=_;c=l.elementToImage(A,S)}d=r,_.target.setPointerCapture(_.pointerId),s("grab",_)},g=O=>{if(h){const[_,T]=l.elementToImage(O.offsetX,O.offsetY),A=[_-c[0],T-c[1]];n(3,r=a(d,h,A)),s("change",r)}},p=O=>{O.target.releasePointerCapture(O.pointerId),h=void 0,d=r,s("release",O)};return e.$$set=O=>{"shape"in O&&n(3,r=O.shape),"editor"in O&&n(4,a=O.editor),"transform"in O&&n(5,l=O.transform),"svgEl"in O&&n(6,f=O.svgEl),"$$scope"in O&&n(7,o=O.$$scope)},[y,g,p,r,a,l,f,o,i]}class St extends Me{constructor(t){super(),Oe(this,t,Bs,Ys,ce,{shape:3,editor:4,transform:5,svgEl:6})}}function Xs(e){let t,n,i,o,s,r,a,l,f=e[3]&&si(e);return{c(){t=L("g"),n=L("circle"),f&&f.c(),o=L("circle"),u(n,"class","a9s-handle-buffer svelte-160z737"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=e[5]+6/e[2]),u(o,"class",s=pt(`a9s-handle-dot${e[3]?" selected":""}`)+" svelte-160z737"),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",e[5]),u(t,"class",r=pt(`a9s-handle ${e[8].class||""}`.trim())+" svelte-160z737")},m(h,c){V(h,t,c),K(t,n),f&&f.m(t,null),K(t,o),a||(l=[$(n,"pointerenter",e[11]),$(n,"pointerleave",e[12]),$(n,"pointerdown",e[13]),$(n,"pointerdown",e[6]),$(n,"pointerup",e[14]),$(n,"pointerup",e[7])],a=!0)},p(h,c){c&1&&u(n,"cx",h[0]),c&2&&u(n,"cy",h[1]),c&36&&i!==(i=h[5]+6/h[2])&&u(n,"r",i),h[3]?f?f.p(h,c):(f=si(h),f.c(),f.m(t,o)):f&&(f.d(1),f=null),c&8&&s!==(s=pt(`a9s-handle-dot${h[3]?" selected":""}`)+" svelte-160z737")&&u(o,"class",s),c&1&&u(o,"cx",h[0]),c&2&&u(o,"cy",h[1]),c&32&&u(o,"r",h[5]),c&256&&r!==(r=pt(`a9s-handle ${h[8].class||""}`.trim())+" svelte-160z737")&&u(t,"class",r)},d(h){h&&H(t),f&&f.d(),a=!1,Ie(l)}}}function Fs(e){let t,n,i,o,s,r,a,l,f;return{c(){t=L("g"),n=L("circle"),o=L("circle"),r=L("circle"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=e[5]*10),u(n,"class","a9s-touch-halo svelte-160z737"),Pe(n,"touched",e[4]),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",s=e[5]+10/e[2]),u(o,"class","a9s-handle-buffer svelte-160z737"),u(r,"class","a9s-handle-dot svelte-160z737"),u(r,"cx",e[0]),u(r,"cy",e[1]),u(r,"r",a=e[5]+2/e[2]),u(t,"class","a9s-touch-handle")},m(h,c){V(h,t,c),K(t,n),K(t,o),K(t,r),l||(f=[$(o,"pointerdown",e[9]),$(o,"pointerup",e[10]),$(o,"pointerdown",e[6]),$(o,"pointerup",e[7])],l=!0)},p(h,c){c&1&&u(n,"cx",h[0]),c&2&&u(n,"cy",h[1]),c&32&&i!==(i=h[5]*10)&&u(n,"r",i),c&16&&Pe(n,"touched",h[4]),c&1&&u(o,"cx",h[0]),c&2&&u(o,"cy",h[1]),c&36&&s!==(s=h[5]+10/h[2])&&u(o,"r",s),c&1&&u(r,"cx",h[0]),c&2&&u(r,"cy",h[1]),c&36&&a!==(a=h[5]+2/h[2])&&u(r,"r",a)},d(h){h&&H(t),l=!1,Ie(f)}}}function si(e){let t,n;return{c(){t=L("circle"),u(t,"class","a9s-handle-selected svelte-160z737"),u(t,"cx",e[0]),u(t,"cy",e[1]),u(t,"r",n=e[5]+8/e[2])},m(i,o){V(i,t,o)},p(i,o){o&1&&u(t,"cx",i[0]),o&2&&u(t,"cy",i[1]),o&36&&n!==(n=i[5]+8/i[2])&&u(t,"r",n)},d(i){i&&H(t)}}}function zs(e){let t;function n(s,r){return Ue?Fs:Xs}let o=n()(e);return{c(){o.c(),t=ve()},m(s,r){o.m(s,r),V(s,t,r)},p(s,[r]){o.p(s,r)},i:q,o:q,d(s){s&&H(t),o.d(s)}}}function js(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t,{selected:a=void 0}=t,l=!1;const f=_=>{_.pointerType==="touch"&&n(4,l=!0)},h=()=>n(4,l=!1);function c(_){we.call(this,e,_)}function d(_){we.call(this,e,_)}function y(_){we.call(this,e,_)}function g(_){we.call(this,e,_)}function p(_){we.call(this,e,_)}function O(_){we.call(this,e,_)}return e.$$set=_=>{n(8,t=He(He({},t),_n(_))),"x"in _&&n(0,o=_.x),"y"in _&&n(1,s=_.y),"scale"in _&&n(2,r=_.scale),"selected"in _&&n(3,a=_.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,i=4/r)},t=_n(t),[o,s,r,a,l,i,f,h,t,c,d,y,g,p,O]}class Ze extends Me{constructor(t){super(),Oe(this,t,js,zs,ce,{x:0,y:1,scale:2,selected:3})}}function Gs(e){let t,n,i,o,s,r,a;return{c(){t=L("g"),n=L("circle"),o=L("circle"),s=L("circle"),u(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=1.75*e[2]),u(o,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",e[2]),u(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),u(s,"cx",e[0]),u(s,"cy",e[1]),u(s,"r",e[2]),u(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,f){V(l,t,f),K(t,n),K(t,o),K(t,s),r||(a=[$(n,"pointerdown",e[5]),$(n,"pointerdown",e[3])],r=!0)},p(l,f){f&1&&u(n,"cx",l[0]),f&2&&u(n,"cy",l[1]),f&4&&i!==(i=1.75*l[2])&&u(n,"r",i),f&1&&u(o,"cx",l[0]),f&2&&u(o,"cy",l[1]),f&4&&u(o,"r",l[2]),f&1&&u(s,"cx",l[0]),f&2&&u(s,"cy",l[1]),f&4&&u(s,"r",l[2])},d(l){l&&H(t),r=!1,Ie(a)}}}function Qs(e){let t;return{c(){t=L("circle"),u(t,"cx",e[0]),u(t,"cy",e[1]),u(t,"r",e[2])},m(n,i){V(n,t,i)},p(n,i){i&1&&u(t,"cx",n[0]),i&2&&u(t,"cy",n[1]),i&4&&u(t,"r",n[2])},d(n){n&&H(t)}}}function qs(e){let t;function n(s,r){return Ue?Qs:Gs}let o=n()(e);return{c(){o.c(),t=ve()},m(s,r){o.m(s,r),V(s,t,r)},p(s,[r]){o.p(s,r)},i:q,o:q,d(s){s&&H(t),o.d(s)}}}function Zs(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t;const a=f=>{f.pointerType};function l(f){we.call(this,e,f)}return e.$$set=f=>{"x"in f&&n(0,o=f.x),"y"in f&&n(1,s=f.y),"scale"in f&&n(4,r=f.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,i=4/r)},[o,s,i,a,r,l]}class ri extends Me{constructor(t){super(),Oe(this,t,Zs,qs,ce,{x:0,y:1,scale:4})}}function qt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function li(e,t,n){const i=e.slice();return i[28]=t[n],i[30]=n,i}function Zt(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 ai(e){let t,n,i,o;return{c(){t=L("circle"),u(t,"cx",n=e[28][0]),u(t,"cy",i=e[28][1]),u(t,"r",o=ft/e[3]),u(t,"class","svelte-1h2slbm")},m(s,r){V(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&u(t,"cx",n),r[0]&1088&&i!==(i=s[28][1])&&u(t,"cy",i),r[0]&8&&o!==(o=ft/s[3])&&u(t,"r",o)},d(s){s&&H(t)}}}function ui(e){let t,n,i,o,s,r,a,l,f,h;return{c(){t=L("mask"),n=L("rect"),a=L("circle"),u(n,"x",i=e[9].x),u(n,"y",o=e[9].y),u(n,"width",s=e[9].w),u(n,"height",r=e[9].h),u(n,"class","svelte-1h2slbm"),u(a,"cx",l=e[28][0]),u(a,"cy",f=e[28][1]),u(a,"r",h=ft/e[3]),u(a,"class","svelte-1h2slbm"),u(t,"id",`${e[19]}-inner`),u(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,d){V(c,t,d),K(t,n),K(t,a)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&u(n,"x",i),d[0]&512&&o!==(o=c[9].y)&&u(n,"y",o),d[0]&512&&s!==(s=c[9].w)&&u(n,"width",s),d[0]&512&&r!==(r=c[9].h)&&u(n,"height",r),d[0]&1088&&l!==(l=c[28][0])&&u(a,"cx",l),d[0]&1088&&f!==(f=c[28][1])&&u(a,"cy",f),d[0]&8&&h!==(h=ft/c[3])&&u(a,"r",h)},d(c){c&&H(t)}}}function fi(e){let t,n;return t=new Ze({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(){re(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&32&&(s.x=e[28][0]),o[0]&32&&(s.y=e[28][1]),o[0]&8&&(s.scale=e[3]),o[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function ci(e){let t,n;return t=new ri({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){re(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&1088&&(s.x=e[28][0]),o[0]&1088&&(s.y=e[28][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Ks(e){let t,n,i,o,s,r,a,l,f,h,c,d,y,g,p,O,_,T,A,S,v,I=e[6]!==void 0&&!e[7]&&ai(Kt(e)),C=e[6]!==void 0&&!e[7]&&ui(Zt(e)),P=Ce(e[5].points),k=[];for(let w=0;w<P.length;w+=1)k[w]=fi(li(e,P,w));const j=w=>F(k[w],1,1,()=>{k[w]=null});let G=e[6]!==void 0&&!e[7]&&ci(qt(e));return{c(){t=L("defs"),n=L("mask"),i=L("rect"),l=L("polygon"),I&&I.c(),C&&C.c(),h=Ae(),c=L("polygon"),y=Ae(),g=L("polygon"),O=Ae();for(let w=0;w<k.length;w+=1)k[w].c();_=Ae(),G&&G.c(),T=ve(),u(i,"x",o=e[9].x),u(i,"y",s=e[9].y),u(i,"width",r=e[9].w),u(i,"height",a=e[9].h),u(i,"class","svelte-1h2slbm"),u(l,"points",f=e[5].points.map(hi).join(" ")),u(l,"class","svelte-1h2slbm"),u(n,"id",`${e[19]}-outer`),u(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),u(c,"class","a9s-outer"),u(c,"mask",`url(#${e[19]}-outer)`),u(c,"points",d=e[5].points.map(di).join(" ")),u(g,"class","a9s-inner a9s-shape-handle"),u(g,"mask",`url(#${e[19]}-inner)`),u(g,"style",e[1]),u(g,"points",p=e[5].points.map(gi).join(" "))},m(w,b){V(w,t,b),K(t,n),K(n,i),K(n,l),I&&I.m(n,null),C&&C.m(t,null),V(w,h,b),V(w,c,b),V(w,y,b),V(w,g,b),V(w,O,b);for(let m=0;m<k.length;m+=1)k[m]&&k[m].m(w,b);V(w,_,b),G&&G.m(w,b),V(w,T,b),A=!0,S||(v=[$(c,"pointerup",e[14]),$(c,"pointerdown",function(){re(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),$(g,"pointermove",e[13]),$(g,"pointerup",e[14]),$(g,"pointerdown",function(){re(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],S=!0)},p(w,b){if(e=w,(!A||b[0]&512&&o!==(o=e[9].x))&&u(i,"x",o),(!A||b[0]&512&&s!==(s=e[9].y))&&u(i,"y",s),(!A||b[0]&512&&r!==(r=e[9].w))&&u(i,"width",r),(!A||b[0]&512&&a!==(a=e[9].h))&&u(i,"height",a),(!A||b[0]&32&&f!==(f=e[5].points.map(hi).join(" ")))&&u(l,"points",f),e[6]!==void 0&&!e[7]?I?I.p(Kt(e),b):(I=ai(Kt(e)),I.c(),I.m(n,null)):I&&(I.d(1),I=null),e[6]!==void 0&&!e[7]?C?C.p(Zt(e),b):(C=ui(Zt(e)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!A||b[0]&32&&d!==(d=e[5].points.map(di).join(" ")))&&u(c,"points",d),(!A||b[0]&2)&&u(g,"style",e[1]),(!A||b[0]&32&&p!==(p=e[5].points.map(gi).join(" ")))&&u(g,"points",p),b[0]&134322472){P=Ce(e[5].points);let m;for(m=0;m<P.length;m+=1){const E=li(e,P,m);k[m]?(k[m].p(E,b),B(k[m],1)):(k[m]=fi(E),k[m].c(),B(k[m],1),k[m].m(_.parentNode,_))}for(Ee(),m=P.length;m<k.length;m+=1)j(m);be()}e[6]!==void 0&&!e[7]?G?(G.p(qt(e),b),b[0]&192&&B(G,1)):(G=ci(qt(e)),G.c(),B(G,1),G.m(T.parentNode,T)):G&&(Ee(),F(G,1,1,()=>{G=null}),be())},i(w){if(!A){for(let b=0;b<P.length;b+=1)B(k[b]);B(G),A=!0}},o(w){k=k.filter(Boolean);for(let b=0;b<k.length;b+=1)F(k[b]);F(G),A=!1},d(w){w&&(H(t),H(h),H(c),H(y),H(g),H(O),H(_),H(T)),I&&I.d(),C&&C.d(),je(k,w),G&&G.d(w),S=!1,Ie(v)}}}function Ws(e){let t,n;return t=new St({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[Ks,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){const s={};o[0]&1&&(s.shape=i[0]),o[0]&4&&(s.transform=i[2]),o[0]&16&&(s.svgEl=i[4]),o[0]&134219754|o[1]&1&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}const Js=250,xs=1e3,$s=12,ft=4.5,hi=e=>e.join(","),di=e=>e.join(","),gi=e=>e.join(",");function er(e,t,n){let i,o,s;const r=Ve();let{shape:a}=t,{computedStyle:l}=t,{transform:f}=t,{viewportScale:h=1}=t,{svgEl:c}=t,d,y=!1,g,p=[];const O=()=>n(7,y=!0),_=()=>n(7,y=!1),T=m=>{if(p.length>0){n(6,d=void 0);return}const[E,R]=f.elementToImage(m.offsetX,m.offsetY),N=J=>Math.pow(J[0]-E,2)+Math.pow(J[1]-R,2),D=i.points.reduce((J,ee)=>N(ee)<N(J)?ee:J),Q=o.filter(J=>J.visible).reduce((J,ee)=>N(ee.point)<N(J.point)?ee:J),z=Math.pow(xs/h,2);N(D)<z||N(Q.point)<z?n(6,d=o.indexOf(Q)):n(6,d=void 0)},A=()=>{document.activeElement!==c&&c.focus()},S=()=>{n(8,p=[]),A()},v=m=>{n(7,y=!0),m.preventDefault(),m.stopPropagation(),g=performance.now()},I=m=>E=>{if(!g||Ue||performance.now()-g>Js)return;const R=p.includes(m);E.metaKey||E.ctrlKey||E.shiftKey?R?n(8,p=p.filter(N=>N!==m)):n(8,p=[...p,m]):R&&p.length>1?n(8,p=[m]):R?n(8,p=[]):n(8,p=[m]),A()},C=(m,E,R)=>{A();let N;const D=m.geometry;p.length>1?N=D.points.map(([z,W],J)=>p.includes(J)?[z+R[0],W+R[1]]:[z,W]):E==="SHAPE"?N=D.points.map(([z,W])=>[z+R[0],W+R[1]]):N=D.points.map(([z,W],J)=>E===`HANDLE-${J}`?[z+R[0],W+R[1]]:[z,W]);const Q=Se(N);return{...m,geometry:{points:N,bounds:Q}}},P=m=>async E=>{E.stopPropagation();const R=[...i.points.slice(0,m+1),o[m].point,...i.points.slice(m+1)],N=Se(R);r("change",{...a,geometry:{points:R,bounds:N}}),await An();const D=[...document.querySelectorAll(".a9s-handle")][m+1];if(D!=null&&D.firstChild){const Q=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:E.clientX,clientY:E.clientY,pointerId:E.pointerId,pointerType:E.pointerType,isPrimary:E.isPrimary,buttons:E.buttons});D.firstChild.dispatchEvent(Q)}},k=()=>{if(i.points.length<4)return;const m=i.points.filter((R,N)=>!p.includes(N)),E=Se(m);r("change",{...a,geometry:{points:m,bounds:E}}),n(8,p=[])};Ge(()=>{if(Ue)return;const m=E=>{(E.key==="Delete"||E.key==="Backspace")&&(E.preventDefault(),k())};return c.addEventListener("pointermove",T),c.addEventListener("keydown",m),()=>{c.removeEventListener("pointermove",T),c.removeEventListener("keydown",m)}});const j=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function G(m){we.call(this,e,m)}function w(m){we.call(this,e,m)}function b(m){we.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,a=m.shape),"computedStyle"in m&&n(1,l=m.computedStyle),"transform"in m&&n(2,f=m.transform),"viewportScale"in m&&n(3,h=m.viewportScale),"svgEl"in m&&n(4,c=m.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=a.geometry),e.$$.dirty[0]&40&&n(10,o=Ue?[]:i.points.map((m,E)=>{const R=E===i.points.length-1?i.points[0]:i.points[E+1],N=(m[0]+R[0])/2,D=(m[1]+R[1])/2,z=Math.sqrt(Math.pow(R[0]-N,2)+Math.pow(R[1]-D,2))>$s/h;return{point:[N,D],visible:z}})),e.$$.dirty[0]&40&&n(9,s=ut(i.bounds,ft/h))},[a,l,f,h,c,i,d,y,p,s,o,O,_,T,S,v,I,C,P,j,G,w,b]}class pi extends Me{constructor(t){super(),Oe(this,t,er,Ws,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function tr(e){let t,n,i,o,s,r,a,l,f,h,c,d,y,g,p,O,_,T,A,S,v,I,C,P,k,j,G,w,b,m,E,R,N,D,Q,z,W,J,ee,ae,le,Ne,ke,X,he,te,me,Te,nt,Fe,cn,ze,x,hn,ro;return te=new Ze({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){re(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),Te=new Ze({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),Te.$on("pointerdown",function(){re(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),Fe=new Ze({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),Fe.$on("pointerdown",function(){re(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),ze=new Ze({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),ze.$on("pointerdown",function(){re(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),i=L("rect"),l=L("rect"),y=Ae(),g=L("rect"),A=Ae(),S=L("rect"),k=Ae(),j=L("rect"),m=Ae(),E=L("rect"),Q=Ae(),z=L("rect"),ae=Ae(),le=L("rect"),he=Ae(),pe(te.$$.fragment),me=Ae(),pe(Te.$$.fragment),nt=Ae(),pe(Fe.$$.fragment),cn=Ae(),pe(ze.$$.fragment),u(i,"class","rect-mask-bg svelte-1njczvj"),u(i,"x",o=e[6].x),u(i,"y",s=e[6].y),u(i,"width",r=e[6].w),u(i,"height",a=e[6].h),u(l,"class","rect-mask-fg svelte-1njczvj"),u(l,"x",f=e[5].x),u(l,"y",h=e[5].y),u(l,"width",c=e[5].w),u(l,"height",d=e[5].h),u(n,"id",e[8]),u(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),u(g,"class","a9s-outer"),u(g,"mask",`url(#${e[8]})`),u(g,"x",p=e[5].x),u(g,"y",O=e[5].y),u(g,"width",_=e[5].w),u(g,"height",T=e[5].h),u(S,"class","a9s-inner a9s-shape-handle"),u(S,"style",e[1]),u(S,"x",v=e[5].x),u(S,"y",I=e[5].y),u(S,"width",C=e[5].w),u(S,"height",P=e[5].h),u(j,"class","a9s-edge-handle a9s-edge-handle-top"),u(j,"x",G=e[5].x),u(j,"y",w=e[5].y),u(j,"height",1),u(j,"width",b=e[5].w),u(E,"class","a9s-edge-handle a9s-edge-handle-right"),u(E,"x",R=e[5].x+e[5].w),u(E,"y",N=e[5].y),u(E,"height",D=e[5].h),u(E,"width",1),u(z,"class","a9s-edge-handle a9s-edge-handle-bottom"),u(z,"x",W=e[5].x),u(z,"y",J=e[5].y+e[5].h),u(z,"height",1),u(z,"width",ee=e[5].w),u(le,"class","a9s-edge-handle a9s-edge-handle-left"),u(le,"x",Ne=e[5].x),u(le,"y",ke=e[5].y),u(le,"height",X=e[5].h),u(le,"width",1)},m(Z,Y){V(Z,t,Y),K(t,n),K(n,i),K(n,l),V(Z,y,Y),V(Z,g,Y),V(Z,A,Y),V(Z,S,Y),V(Z,k,Y),V(Z,j,Y),V(Z,m,Y),V(Z,E,Y),V(Z,Q,Y),V(Z,z,Y),V(Z,ae,Y),V(Z,le,Y),V(Z,he,Y),de(te,Z,Y),V(Z,me,Y),de(Te,Z,Y),V(Z,nt,Y),de(Fe,Z,Y),V(Z,cn,Y),de(ze,Z,Y),x=!0,hn||(ro=[$(g,"pointerdown",function(){re(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),$(S,"pointerdown",function(){re(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),$(j,"pointerdown",function(){re(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),$(E,"pointerdown",function(){re(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),$(z,"pointerdown",function(){re(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),$(le,"pointerdown",function(){re(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],hn=!0)},p(Z,Y){e=Z,(!x||Y&64&&o!==(o=e[6].x))&&u(i,"x",o),(!x||Y&64&&s!==(s=e[6].y))&&u(i,"y",s),(!x||Y&64&&r!==(r=e[6].w))&&u(i,"width",r),(!x||Y&64&&a!==(a=e[6].h))&&u(i,"height",a),(!x||Y&32&&f!==(f=e[5].x))&&u(l,"x",f),(!x||Y&32&&h!==(h=e[5].y))&&u(l,"y",h),(!x||Y&32&&c!==(c=e[5].w))&&u(l,"width",c),(!x||Y&32&&d!==(d=e[5].h))&&u(l,"height",d),(!x||Y&32&&p!==(p=e[5].x))&&u(g,"x",p),(!x||Y&32&&O!==(O=e[5].y))&&u(g,"y",O),(!x||Y&32&&_!==(_=e[5].w))&&u(g,"width",_),(!x||Y&32&&T!==(T=e[5].h))&&u(g,"height",T),(!x||Y&2)&&u(S,"style",e[1]),(!x||Y&32&&v!==(v=e[5].x))&&u(S,"x",v),(!x||Y&32&&I!==(I=e[5].y))&&u(S,"y",I),(!x||Y&32&&C!==(C=e[5].w))&&u(S,"width",C),(!x||Y&32&&P!==(P=e[5].h))&&u(S,"height",P),(!x||Y&32&&G!==(G=e[5].x))&&u(j,"x",G),(!x||Y&32&&w!==(w=e[5].y))&&u(j,"y",w),(!x||Y&32&&b!==(b=e[5].w))&&u(j,"width",b),(!x||Y&32&&R!==(R=e[5].x+e[5].w))&&u(E,"x",R),(!x||Y&32&&N!==(N=e[5].y))&&u(E,"y",N),(!x||Y&32&&D!==(D=e[5].h))&&u(E,"height",D),(!x||Y&32&&W!==(W=e[5].x))&&u(z,"x",W),(!x||Y&32&&J!==(J=e[5].y+e[5].h))&&u(z,"y",J),(!x||Y&32&&ee!==(ee=e[5].w))&&u(z,"width",ee),(!x||Y&32&&Ne!==(Ne=e[5].x))&&u(le,"x",Ne),(!x||Y&32&&ke!==(ke=e[5].y))&&u(le,"y",ke),(!x||Y&32&&X!==(X=e[5].h))&&u(le,"height",X);const Nt={};Y&32&&(Nt.x=e[5].x),Y&32&&(Nt.y=e[5].y),Y&8&&(Nt.scale=e[3]),te.$set(Nt);const It={};Y&32&&(It.x=e[5].x+e[5].w),Y&32&&(It.y=e[5].y),Y&8&&(It.scale=e[3]),Te.$set(It);const Rt={};Y&32&&(Rt.x=e[5].x+e[5].w),Y&32&&(Rt.y=e[5].y+e[5].h),Y&8&&(Rt.scale=e[3]),Fe.$set(Rt);const Lt={};Y&32&&(Lt.x=e[5].x),Y&32&&(Lt.y=e[5].y+e[5].h),Y&8&&(Lt.scale=e[3]),ze.$set(Lt)},i(Z){x||(B(te.$$.fragment,Z),B(Te.$$.fragment,Z),B(Fe.$$.fragment,Z),B(ze.$$.fragment,Z),x=!0)},o(Z){F(te.$$.fragment,Z),F(Te.$$.fragment,Z),F(Fe.$$.fragment,Z),F(ze.$$.fragment,Z),x=!1},d(Z){Z&&(H(t),H(y),H(g),H(A),H(S),H(k),H(j),H(m),H(E),H(Q),H(z),H(ae),H(le),H(he),H(me),H(nt),H(cn)),ge(te,Z),ge(Te,Z),ge(Fe,Z),ge(ze,Z),hn=!1,Ie(ro)}}}function nr(e){let t,n;return t=new St({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[tr,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,[o]){const s={};o&1&&(s.shape=i[0]),o&4&&(s.transform=i[2]),o&16&&(s.svgEl=i[4]),o&12394&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function ir(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:f}=t;const h=(p,O,_)=>{const T=p.geometry.bounds;let[A,S]=[T.minX,T.minY],[v,I]=[T.maxX,T.maxY];const[C,P]=_;if(O==="SHAPE")A+=C,v+=C,S+=P,I+=P;else{switch(O){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{S+=P;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{I+=P;break}}switch(O){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{A+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{v+=C;break}}}const k=Math.min(A,v),j=Math.min(S,I),G=Math.abs(v-A),w=Math.abs(I-S);return{...p,geometry:{x:k,y:j,w:G,h:w,bounds:{minX:k,minY:j,maxX:k+G,maxY:j+w}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(p){we.call(this,e,p)}function y(p){we.call(this,e,p)}function g(p){we.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,a=p.transform),"viewportScale"in p&&n(3,l=p.viewportScale),"svgEl"in p&&n(4,f=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,i=s.geometry),e.$$.dirty&40&&n(6,o=ut(i.bounds,2/l))},[s,r,a,l,f,i,o,h,c,d,y,g]}class yi extends Me{constructor(t){super(),Oe(this,t,ir,nr,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var _i=Object.prototype.hasOwnProperty;function Wt(e,t){var n,i;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((i=e.length)===t.length)for(;i--&&Wt(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(_i.call(e,n)&&++i&&!_i.call(t,n)||!(n in t)||!Wt(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}const or=12,sr=(e,t)=>e.polygons.reduce((n,i,o)=>{const s=i.rings.reduce((r,a,l)=>{const f=a.points.map((h,c)=>{const d=c===a.points.length-1?a.points[0]:a.points[c+1],y=(h[0]+d[0])/2,g=(h[1]+d[1])/2,O=Math.sqrt(Math.pow(d[0]-y,2)+Math.pow(d[1]-g,2))>or/t;return{point:[y,g],visible:O,elementIdx:o,ringIdx:l,pointIdx:c}});return[...r,...f]},[]);return[...n,...s]},[]);function Jt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function mi(e,t,n){const i=e.slice();return i[30]=t[n],i[32]=n,i}function wi(e,t,n){const i=e.slice();return i[33]=t[n],i[35]=n,i}function Ei(e,t,n){const i=e.slice();return i[29]=t[n],i[37]=n,i}function xt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function $t(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function bi(e){let t,n,i,o;return{c(){t=L("circle"),u(t,"cx",n=e[29][0]),u(t,"cy",i=e[29][1]),u(t,"r",o=ct/e[3]),u(t,"class","svelte-1vxo6dc")},m(s,r){V(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&u(t,"cx",n),r[0]&1088&&i!==(i=s[29][1])&&u(t,"cy",i),r[0]&8&&o!==(o=ct/s[3])&&u(t,"r",o)},d(s){s&&H(t)}}}function Ti(e){let t,n,i,o,s,r,a,l,f,h;return{c(){t=L("mask"),n=L("rect"),a=L("circle"),u(n,"x",i=e[9].x),u(n,"y",o=e[9].y),u(n,"width",s=e[9].w),u(n,"height",r=e[9].h),u(n,"class","svelte-1vxo6dc"),u(a,"cx",l=e[29][0]),u(a,"cy",f=e[29][1]),u(a,"r",h=ct/e[3]),u(a,"class","svelte-1vxo6dc"),u(t,"id",`${e[18]}-${e[32]}-inner`),u(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(c,d){V(c,t,d),K(t,n),K(t,a)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&u(n,"x",i),d[0]&512&&o!==(o=c[9].y)&&u(n,"y",o),d[0]&512&&s!==(s=c[9].w)&&u(n,"width",s),d[0]&512&&r!==(r=c[9].h)&&u(n,"height",r),d[0]&1088&&l!==(l=c[29][0])&&u(a,"cx",l),d[0]&1088&&f!==(f=c[29][1])&&u(a,"cy",f),d[0]&8&&h!==(h=ct/c[3])&&u(a,"r",h)},d(c){c&&H(t)}}}function Ai(e){let t,n;function i(...o){return e[19](e[32],e[35],e[37],...o)}return t=new Ze({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(i)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){re(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(){pe(t.$$.fragment)},m(o,s){de(t,o,s),n=!0},p(o,s){e=o;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(i)),t.$set(r)},i(o){n||(B(t.$$.fragment,o),n=!0)},o(o){F(t.$$.fragment,o),n=!1},d(o){ge(t,o)}}}function Oi(e){let t,n,i=Ce(e[33].points),o=[];for(let r=0;r<i.length;r+=1)o[r]=Ai(Ei(e,i,r));const s=r=>F(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=ve()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);V(r,t,a),n=!0},p(r,a){if(a[0]&268491048){i=Ce(r[33].points);let l;for(l=0;l<i.length;l+=1){const f=Ei(r,i,l);o[l]?(o[l].p(f,a),B(o[l],1)):(o[l]=Ai(f),o[l].c(),B(o[l],1),o[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<o.length;l+=1)s(l);be()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)B(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)F(o[a]);n=!1},d(r){r&&H(t),je(o,r)}}}function Mi(e){let t,n,i,o,s,r,a,l,f,h,c,d,y,g,p,O,_,T=e[6]!==void 0&&!e[7]&&bi($t(e)),A=e[6]!==void 0&&!e[7]&&Ti(xt(e)),S=Ce(e[30].rings),v=[];for(let C=0;C<S.length;C+=1)v[C]=Oi(wi(e,S,C));const I=C=>F(v[C],1,1,()=>{v[C]=null});return{c(){t=L("g"),n=L("defs"),i=L("mask"),o=L("rect"),f=L("path"),T&&T.c(),A&&A.c(),c=L("path"),y=L("path");for(let C=0;C<v.length;C+=1)v[C].c();u(o,"x",s=e[9].x),u(o,"y",r=e[9].y),u(o,"width",a=e[9].w),u(o,"height",l=e[9].h),u(o,"class","svelte-1vxo6dc"),u(f,"d",h=De(e[30])),u(f,"class","svelte-1vxo6dc"),u(i,"id",`${e[18]}-${e[32]}-outer`),u(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),u(c,"class","a9s-outer"),u(c,"mask",`url(#${e[18]}-${e[32]}-outer)`),u(c,"fill-rule","evenodd"),u(c,"d",d=De(e[30])),u(y,"class","a9s-inner"),u(y,"mask",`url(#${e[18]}-${e[32]}-inner)`),u(y,"style",e[1]),u(y,"fill-rule","evenodd"),u(y,"d",g=De(e[30]))},m(C,P){V(C,t,P),K(t,n),K(n,i),K(i,o),K(i,f),T&&T.m(i,null),A&&A.m(n,null),K(t,c),K(t,y);for(let k=0;k<v.length;k+=1)v[k]&&v[k].m(t,null);p=!0,O||(_=[$(c,"pointerup",e[13]),$(c,"pointerdown",function(){re(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),$(y,"pointerup",e[13]),$(y,"pointerdown",function(){re(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],O=!0)},p(C,P){if(e=C,(!p||P[0]&512&&s!==(s=e[9].x))&&u(o,"x",s),(!p||P[0]&512&&r!==(r=e[9].y))&&u(o,"y",r),(!p||P[0]&512&&a!==(a=e[9].w))&&u(o,"width",a),(!p||P[0]&512&&l!==(l=e[9].h))&&u(o,"height",l),(!p||P[0]&32&&h!==(h=De(e[30])))&&u(f,"d",h),e[6]!==void 0&&!e[7]?T?T.p($t(e),P):(T=bi($t(e)),T.c(),T.m(i,null)):T&&(T.d(1),T=null),e[6]!==void 0&&!e[7]?A?A.p(xt(e),P):(A=Ti(xt(e)),A.c(),A.m(n,null)):A&&(A.d(1),A=null),(!p||P[0]&32&&d!==(d=De(e[30])))&&u(c,"d",d),(!p||P[0]&2)&&u(y,"style",e[1]),(!p||P[0]&32&&g!==(g=De(e[30])))&&u(y,"d",g),P[0]&268491048){S=Ce(e[30].rings);let k;for(k=0;k<S.length;k+=1){const j=wi(e,S,k);v[k]?(v[k].p(j,P),B(v[k],1)):(v[k]=Oi(j),v[k].c(),B(v[k],1),v[k].m(t,null))}for(Ee(),k=S.length;k<v.length;k+=1)I(k);be()}},i(C){if(!p){for(let P=0;P<S.length;P+=1)B(v[P]);p=!0}},o(C){v=v.filter(Boolean);for(let P=0;P<v.length;P+=1)F(v[P]);p=!1},d(C){C&&H(t),T&&T.d(),A&&A.d(),je(v,C),O=!1,Ie(_)}}}function Si(e){let t,n;return t=new ri({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){re(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&1088&&(s.x=e[29][0]),o[0]&1088&&(s.y=e[29][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function rr(e){let t,n,i,o=Ce(e[5].polygons),s=[];for(let l=0;l<o.length;l+=1)s[l]=Mi(mi(e,o,l));const r=l=>F(s[l],1,1,()=>{s[l]=null});let a=e[6]!==void 0&&!e[7]&&Si(Jt(e));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Ae(),a&&a.c(),n=ve()},m(l,f){for(let h=0;h<s.length;h+=1)s[h]&&s[h].m(l,f);V(l,t,f),a&&a.m(l,f),V(l,n,f),i=!0},p(l,f){if(f[0]&268763114){o=Ce(l[5].polygons);let h;for(h=0;h<o.length;h+=1){const c=mi(l,o,h);s[h]?(s[h].p(c,f),B(s[h],1)):(s[h]=Mi(c),s[h].c(),B(s[h],1),s[h].m(t.parentNode,t))}for(Ee(),h=o.length;h<s.length;h+=1)r(h);be()}l[6]!==void 0&&!l[7]?a?(a.p(Jt(l),f),f[0]&192&&B(a,1)):(a=Si(Jt(l)),a.c(),B(a,1),a.m(n.parentNode,n)):a&&(Ee(),F(a,1,1,()=>{a=null}),be())},i(l){if(!i){for(let f=0;f<o.length;f+=1)B(s[f]);B(a),i=!0}},o(l){s=s.filter(Boolean);for(let f=0;f<s.length;f+=1)F(s[f]);F(a),i=!1},d(l){l&&(H(t),H(n)),je(s,l),a&&a.d(l)}}}function lr(e){let t,n;return t=new St({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[rr,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){const s={};o[0]&1&&(s.shape=i[0]),o[0]&4&&(s.transform=i[2]),o[0]&16&&(s.svgEl=i[4]),o[0]&268437482|o[1]&128&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}const ar=250,ur=1e3,ct=4.5;function fr(e,t,n){let i,o,s;const r=Ve();let{shape:a}=t,{computedStyle:l}=t,{transform:f}=t,{viewportScale:h=1}=t,{svgEl:c}=t,d,y=!1,g,p=[];const O=()=>n(7,y=!0),_=()=>n(7,y=!1),T=E=>{if(p.length>0){n(6,d=void 0);return}const[R,N]=f.elementToImage(E.offsetX,E.offsetY),D=ee=>Math.pow(ee[0]-R,2)+Math.pow(ee[1]-N,2),Q=vn(i).reduce((ee,ae)=>D(ae)<D(ee)?ae:ee),z=o.filter(ee=>ee.visible).reduce((ee,ae)=>D(ae.point)<D(ee.point)?ae:ee),W=Math.pow(ur/h,2);D(Q)<W||D(z.point)<W?n(6,d=o.indexOf(z)):n(6,d=void 0)},A=()=>{document.activeElement!==c&&c.focus()},S=()=>{n(8,p=[]),A()},v=E=>{n(7,y=!0),E.preventDefault(),E.stopPropagation(),g=performance.now()},I=(E,R,N)=>D=>{if(!g||Ue||performance.now()-g>ar)return;const Q=W=>W.polygon===E&&W.ring===R&&W.point===N,z=p.some(Q);D.metaKey||D.ctrlKey||D.shiftKey?z?n(8,p=p.filter(W=>!Q(W))):n(8,p=[...p,{polygon:E,ring:R,point:N}]):z&&p.length>1?n(8,p=[{polygon:E,ring:R,point:N}]):z?n(8,p=[]):n(8,p=[{polygon:E,ring:R,point:N}]),A()},C=(E,R,N)=>{A();const D=E.geometry.polygons;let Q;if(R==="SHAPE")Q=D.map(z=>{const W=z.rings.map((ee,ae)=>({points:ee.points.map((Ne,ke)=>[Ne[0]+N[0],Ne[1]+N[1]])})),J=Se(W[0].points);return{rings:W,bounds:J}});else{const[z,W,J,ee]=R.split("-").map(ae=>parseInt(ae));Q=D.map((ae,le)=>{if(le===W){const Ne=ae.rings.map((X,he)=>he===J?{points:X.points.map((me,Te)=>Te===ee?[me[0]+N[0],me[1]+N[1]]:me)}:X),ke=Se(Ne[0].points);return{rings:Ne,bounds:ke}}else return ae})}return{...E,geometry:{polygons:Q,bounds:bt(Q)}}},P=E=>async R=>{R.stopPropagation();const N=o[E],D=i.polygons.map((z,W)=>{if(W===N.elementIdx){const J=z.rings.map((ae,le)=>le===N.ringIdx?{points:[...ae.points.slice(0,N.pointIdx+1),N.point,...ae.points.slice(N.pointIdx+1)]}:ae),ee=Se(J[0].points);return{rings:J,bounds:ee}}else return z});r("change",{...a,geometry:{polygons:D,bounds:bt(D)}}),await An();const Q=[...document.querySelectorAll(".a9s-handle")][E+1];if(Q!=null&&Q.firstChild){const z=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:R.clientX,clientY:R.clientY,pointerId:R.pointerId,pointerType:R.pointerType,isPrimary:R.isPrimary,buttons:R.buttons});Q.firstChild.dispatchEvent(z)}},k=()=>{const E=i.polygons.map((N,D)=>{if(p.some(z=>z.polygon===D)){const z=N.rings.map((J,ee)=>p.some(le=>le.polygon===D&&le.ring===ee)&&J.points.length>3?{points:J.points.filter((Ne,ke)=>!p.some(X=>X.polygon===D&&X.ring===ee&&X.point===ke))}:J),W=Se(z[0].points);return{rings:z,bounds:W}}else return N});!Wt(i.polygons,E)&&(r("change",{...a,geometry:{polygons:E,bounds:bt(E)}}),n(8,p=[]))};Ge(()=>{if(Ue)return;const E=R=>{(R.key==="Delete"||R.key==="Backspace")&&(R.preventDefault(),k())};return c.addEventListener("pointermove",T),c.addEventListener("keydown",E),()=>{c.removeEventListener("pointermove",T),c.removeEventListener("keydown",E)}});const j=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,G=(E,R,N,{polygon:D,ring:Q,point:z})=>D===E&&Q===R&&z===N;function w(E){we.call(this,e,E)}function b(E){we.call(this,e,E)}function m(E){we.call(this,e,E)}return e.$$set=E=>{"shape"in E&&n(0,a=E.shape),"computedStyle"in E&&n(1,l=E.computedStyle),"transform"in E&&n(2,f=E.transform),"viewportScale"in E&&n(3,h=E.viewportScale),"svgEl"in E&&n(4,c=E.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=a.geometry),e.$$.dirty[0]&40&&n(10,o=Ue?[]:sr(i,h)),e.$$.dirty[0]&40&&n(9,s=ut(i.bounds,ct/h))},[a,l,f,h,c,i,d,y,p,s,o,O,_,S,v,I,C,P,j,G,w,b,m]}class cr extends Me{constructor(t){super(),Oe(this,t,fr,lr,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const vi=new Map([[ie.RECTANGLE,yi],[ie.POLYGON,pi],[ie.MULTIPOLYGLON,cr]]),Ci=e=>vi.get(e.type),Ni=(e,t)=>vi.set(e,t);function hr(e,t,n){let i;const o=Ve();let{annotation:s}=t,{editor:r}=t,{style:a}=t,{target:l}=t,{transform:f}=t,{viewportScale:h}=t,c;return Ge(()=>(n(6,c=new r({target:l,props:{shape:s.target.selector,computedStyle:i,transform:f,viewportScale:h,svgEl:l.closest("svg")}})),c.$on("change",d=>{c.$$set({shape:d.detail}),o("change",d.detail)}),c.$on("grab",d=>o("grab",d.detail)),c.$on("release",d=>o("release",d.detail)),()=>{c.$destroy()})),e.$$set=d=>{"annotation"in d&&n(0,s=d.annotation),"editor"in d&&n(1,r=d.editor),"style"in d&&n(2,a=d.style),"target"in d&&n(3,l=d.target),"transform"in d&&n(4,f=d.transform),"viewportScale"in d&&n(5,h=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,i=at(s,a)),e.$$.dirty&65&&s&&(c==null||c.$set({shape:s.target.selector})),e.$$.dirty&80&&c&&c.$set({transform:f}),e.$$.dirty&96&&c&&c.$set({viewportScale:h}),e.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[s,r,a,l,f,h,c,i]}class Ii extends Me{constructor(t){super(),Oe(this,t,hr,null,ce,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function dr(e,t,n){const i=Ve();let{drawingMode:o}=t,{target:s}=t,{tool:r}=t,{transform:a}=t,{viewportScale:l}=t,f;return Ge(()=>{const h=s.closest("svg"),c=[],d=(y,g,p)=>{h==null||h.addEventListener(y,g,p),c.push(()=>h==null?void 0:h.removeEventListener(y,g,p))};return n(5,f=new r({target:s,props:{addEventListener:d,drawingMode:o,transform:a,viewportScale:l}})),f.$on("create",y=>i("create",y.detail)),()=>{c.forEach(y=>y()),f.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,o=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,a=h.transform),"viewportScale"in h&&n(4,l=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&f&&f.$set({transform:a}),e.$$.dirty&48&&f&&f.$set({viewportScale:l})},[o,s,r,a,l,f]}class Ri extends Me{constructor(t){super(),Oe(this,t,dr,null,ce,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Li(e){let t,n,i,o,s,r,a,l,f,h;return{c(){t=L("defs"),n=L("mask"),i=L("rect"),l=L("rect"),f=L("rect"),h=L("rect"),u(i,"class","rect-mask-bg svelte-1a76qe7"),u(i,"x",o=e[1]-e[5]),u(i,"y",s=e[2]-e[5]),u(i,"width",r=e[3]+2*e[5]),u(i,"height",a=e[4]+2*e[5]),u(l,"class","rect-mask-fg svelte-1a76qe7"),u(l,"x",e[1]),u(l,"y",e[2]),u(l,"width",e[3]),u(l,"height",e[4]),u(n,"id",e[6]),u(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),u(f,"class","a9s-outer"),u(f,"mask",`url(#${e[6]})`),u(f,"x",e[1]),u(f,"y",e[2]),u(f,"width",e[3]),u(f,"height",e[4]),u(h,"class","a9s-inner"),u(h,"x",e[1]),u(h,"y",e[2]),u(h,"width",e[3]),u(h,"height",e[4])},m(c,d){V(c,t,d),K(t,n),K(n,i),K(n,l),V(c,f,d),V(c,h,d)},p(c,d){d&34&&o!==(o=c[1]-c[5])&&u(i,"x",o),d&36&&s!==(s=c[2]-c[5])&&u(i,"y",s),d&40&&r!==(r=c[3]+2*c[5])&&u(i,"width",r),d&48&&a!==(a=c[4]+2*c[5])&&u(i,"height",a),d&2&&u(l,"x",c[1]),d&4&&u(l,"y",c[2]),d&8&&u(l,"width",c[3]),d&16&&u(l,"height",c[4]),d&2&&u(f,"x",c[1]),d&4&&u(f,"y",c[2]),d&8&&u(f,"width",c[3]),d&16&&u(f,"height",c[4]),d&2&&u(h,"x",c[1]),d&4&&u(h,"y",c[2]),d&8&&u(h,"width",c[3]),d&16&&u(h,"height",c[4])},d(c){c&&(H(t),H(f),H(h))}}}function gr(e){let t,n=e[0]&&Li(e);return{c(){t=L("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(i,o){V(i,t,o),n&&n.m(t,null)},p(i,[o]){i[0]?n?n.p(i,o):(n=Li(i),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(i){i&&H(t),n&&n.d()}}}function pr(e,t,n){let i;const o=Ve();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:a}=t,{viewportScale:l=1}=t,f,h,c,d,y,g,p;const O=v=>{const I=v;f=performance.now(),r==="drag"&&(n(0,h=a.elementToImage(I.offsetX,I.offsetY)),c=h,n(1,d=h[0]),n(2,y=h[1]),n(3,g=1),n(4,p=1))},_=v=>{const I=v;h&&(c=a.elementToImage(I.offsetX,I.offsetY),n(1,d=Math.min(c[0],h[0])),n(2,y=Math.min(c[1],h[1])),n(3,g=Math.abs(c[0]-h[0])),n(4,p=Math.abs(c[1]-h[1])))},T=v=>{const I=v,C=performance.now()-f;if(r==="click"){if(C>300)return;h?A():(n(0,h=a.elementToImage(I.offsetX,I.offsetY)),c=h,n(1,d=h[0]),n(2,y=h[1]),n(3,g=1),n(4,p=1))}else h&&(C>300||g*p>100?(I.stopPropagation(),A()):(n(0,h=void 0),c=void 0))},A=()=>{if(g*p>15){const v={type:ie.RECTANGLE,geometry:{bounds:{minX:d,minY:y,maxX:d+g,maxY:y+p},x:d,y,w:g,h:p}};o("create",v)}n(0,h=void 0),c=void 0};Ge(()=>{s("pointerdown",O),s("pointermove",_),s("pointerup",T,!0)});const S=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=v=>{"addEventListener"in v&&n(7,s=v.addEventListener),"drawingMode"in v&&n(8,r=v.drawingMode),"transform"in v&&n(9,a=v.transform),"viewportScale"in v&&n(10,l=v.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,i=2/l)},[h,d,y,g,p,i,S,s,r,a,l]}class ki extends Me{constructor(t){super(),Oe(this,t,pr,gr,ce,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function en(e){const t=e.slice(),n=t[2].map(i=>i.join(",")).join(" ");return t[19]=n,t}function Pi(e){let t,n,i,o,s,r,a,l,f,h,c,d,y,g,p=e[1]&&Di(e);return{c(){t=L("defs"),n=L("mask"),i=L("rect"),l=L("polygon"),h=L("polygon"),d=L("polygon"),p&&p.c(),g=ve(),u(i,"x",o=e[3].x),u(i,"y",s=e[3].y),u(i,"width",r=e[3].w),u(i,"height",a=e[3].h),u(i,"class","svelte-18wrg3t"),u(l,"points",f=e[19]),u(l,"class","svelte-18wrg3t"),u(n,"id",e[5]),u(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),u(h,"class","a9s-outer"),u(h,"mask",`url(#${e[5]})`),u(h,"points",c=e[19]),u(d,"class","a9s-inner"),u(d,"points",y=e[19])},m(O,_){V(O,t,_),K(t,n),K(n,i),K(n,l),V(O,h,_),V(O,d,_),p&&p.m(O,_),V(O,g,_)},p(O,_){_&8&&o!==(o=O[3].x)&&u(i,"x",o),_&8&&s!==(s=O[3].y)&&u(i,"y",s),_&8&&r!==(r=O[3].w)&&u(i,"width",r),_&8&&a!==(a=O[3].h)&&u(i,"height",a),_&4&&f!==(f=O[19])&&u(l,"points",f),_&4&&c!==(c=O[19])&&u(h,"points",c),_&4&&y!==(y=O[19])&&u(d,"points",y),O[1]?p?p.p(O,_):(p=Di(O),p.c(),p.m(g.parentNode,g)):p&&(p.d(1),p=null)},d(O){O&&(H(t),H(h),H(d),H(g)),p&&p.d(O)}}}function Di(e){let t,n,i;return{c(){t=L("circle"),u(t,"class","a9s-handle svelte-18wrg3t"),u(t,"cx",n=e[0][0][0]),u(t,"cy",i=e[0][0][1]),u(t,"r",e[4])},m(o,s){V(o,t,s)},p(o,s){s&1&&n!==(n=o[0][0][0])&&u(t,"cx",n),s&1&&i!==(i=o[0][0][1])&&u(t,"cy",i),s&16&&u(t,"r",o[4])},d(o){o&&H(t)}}}function yr(e){let t,n=e[3]&&Pi(en(e));return{c(){t=L("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(i,o){V(i,t,o),n&&n.m(t,null)},p(i,[o]){i[3]?n?n.p(en(i),o):(n=Pi(en(i)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(i){i&&H(t),n&&n.d()}}}const _r=20,mr=1500;function wr(e,t,n){let i,o,s;const r=Ve();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:f}=t,{viewportScale:h=1}=t,c,d=[],y,g,p=!1;const O=I=>{const C=I,{timeStamp:P,offsetX:k,offsetY:j}=C;if(c={timeStamp:P,offsetX:k,offsetY:j},l==="drag"&&d.length===0){const G=f.elementToImage(C.offsetX,C.offsetY);d.push(G),n(10,y=G)}},_=I=>{const C=I;if(g&&clearTimeout(g),d.length>0){if(n(10,y=f.elementToImage(C.offsetX,C.offsetY)),d.length>2){const P=Mt(y,d[0])*h;n(1,p=P<_r)}C.pointerType==="touch"&&(g=setTimeout(()=>{A()},mr))}},T=I=>{const C=I;if(g&&clearTimeout(g),l==="click"){const P=C.timeStamp-c.timeStamp,k=Mt([c.offsetX,c.offsetY],[C.offsetX,C.offsetY]);if(P>300||k>15)return;if(p)S();else if(d.length===0){const j=f.elementToImage(C.offsetX,C.offsetY);d.push(j),n(10,y=j)}else d.push(y)}else{if(d.length===1&&Mt(d[0],y)<=4){n(0,d=[]),n(10,y=void 0);return}C.stopImmediatePropagation(),p?S():d.push(y)}},A=()=>{if(!y)return;const I=d.slice(0,-1);if(I.length<3)return;const C={type:ie.POLYGON,geometry:{bounds:Se(d),points:I}};mt(C)>4&&(n(0,d=[]),n(10,y=void 0),r("create",C))},S=()=>{const I={type:ie.POLYGON,geometry:{bounds:Se(d),points:[...d]}};n(0,d=[]),n(10,y=void 0),r("create",I)};Ge(()=>{a("pointerdown",O,!0),a("pointermove",_),a("pointerup",T,!0),a("dblclick",A,!0)});const v=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=I=>{"addEventListener"in I&&n(6,a=I.addEventListener),"drawingMode"in I&&n(7,l=I.drawingMode),"transform"in I&&n(8,f=I.transform),"viewportScale"in I&&n(9,h=I.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,i=4/h),e.$$.dirty&1027&&n(2,o=y?p?d:[...d,y]:[]),e.$$.dirty&516&&n(3,s=o.length>0?ut(Se(o),2/h):void 0)},[d,p,o,s,i,v,a,l,f,h,y]}class Er extends Me{constructor(t){super(),Oe(this,t,wr,yr,ce,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const tn=new Map([["rectangle",{tool:ki}],["polygon",{tool:Er}]]),nn=()=>[...tn.keys()],on=e=>tn.get(e),Ui=(e,t,n={})=>tn.set(e,{tool:t,opts:n});function br(e){let t,n,i,o,s;return{c(){t=L("g"),n=L("ellipse"),o=L("ellipse"),u(n,"class","a9s-outer"),u(n,"style",i=e[1]?"display:none;":void 0),u(n,"cx",e[2]),u(n,"cy",e[3]),u(n,"rx",e[4]),u(n,"ry",e[5]),u(o,"class","a9s-inner"),u(o,"style",e[1]),u(o,"cx",e[2]),u(o,"cy",e[3]),u(o,"rx",e[4]),u(o,"ry",e[5]),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){V(r,t,a),K(t,n),K(t,o)},p(r,[a]){a&2&&i!==(i=r[1]?"display:none;":void 0)&&u(n,"style",i),a&2&&u(o,"style",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}function Tr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{cx:a,cy:l,rx:f,ry:h}=s;return e.$$set=c=>{"annotation"in c&&n(0,o=c.annotation),"geom"in c&&n(6,s=c.geom),"style"in c&&n(7,r=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,i=at(o,r))},[o,i,a,l,f,h,s,r]}class Ar extends Me{constructor(t){super(),Oe(this,t,Tr,br,ce,{annotation:0,geom:6,style:7})}}function Hi(e,t,n){const i=e.slice();return i[5]=t[n],i}function Vi(e){let t,n,i;return{c(){t=L("path"),i=L("path"),u(t,"class","a9s-outer"),u(t,"style",n=e[1]?"display:none;":void 0),u(t,"fill-rule","evenodd"),u(t,"d",De(e[5])),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"fill-rule","evenodd"),u(i,"d",De(e[5]))},m(o,s){V(o,t,s),V(o,i,s)},p(o,s){s&2&&n!==(n=o[1]?"display:none;":void 0)&&u(t,"style",n),s&2&&u(i,"style",o[1])},d(o){o&&(H(t),H(i))}}}function Or(e){let t,n,i=Ce(e[2]),o=[];for(let s=0;s<i.length;s+=1)o[s]=Vi(Hi(e,i,s));return{c(){t=L("g");for(let s=0;s<o.length;s+=1)o[s].c();u(t,"class","a9s-annotation"),u(t,"data-id",n=e[0].id)},m(s,r){V(s,t,r);for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(t,null)},p(s,[r]){if(r&6){i=Ce(s[2]);let a;for(a=0;a<i.length;a+=1){const l=Hi(s,i,a);o[a]?o[a].p(l,r):(o[a]=Vi(l),o[a].c(),o[a].m(t,null))}for(;a<o.length;a+=1)o[a].d(1);o.length=i.length}r&1&&n!==(n=s[0].id)&&u(t,"data-id",n)},i:q,o:q,d(s){s&&H(t),je(o,s)}}}function Mr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{polygons:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=at(o,r))},[o,i,a,s,r]}class Sr extends Me{constructor(t){super(),Oe(this,t,Mr,Or,ce,{annotation:0,geom:3,style:4})}}function vr(e){let t,n,i,o,s;return{c(){t=L("g"),n=L("polygon"),o=L("polygon"),u(n,"class","a9s-outer"),u(n,"style",i=e[1]?"display:none;":void 0),u(n,"points",e[2].map(Cr).join(" ")),u(o,"class","a9s-inner"),u(o,"style",e[1]),u(o,"points",e[2].map(Nr).join(" ")),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){V(r,t,a),K(t,n),K(t,o)},p(r,[a]){a&2&&i!==(i=r[1]?"display:none;":void 0)&&u(n,"style",i),a&2&&u(o,"style",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}const Cr=e=>e.join(","),Nr=e=>e.join(",");function Ir(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{points:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=at(o,r))},[o,i,a,s,r]}class Rr extends Me{constructor(t){super(),Oe(this,t,Ir,vr,ce,{annotation:0,geom:3,style:4})}}function Lr(e){let t,n,i,o,s;return{c(){t=L("g"),n=L("rect"),o=L("rect"),u(n,"class","a9s-outer"),u(n,"style",i=e[5]?"display:none;":void 0),u(n,"x",e[4]),u(n,"y",e[3]),u(n,"width",e[2]),u(n,"height",e[1]),u(o,"class","a9s-inner"),u(o,"style",e[5]),u(o,"x",e[4]),u(o,"y",e[3]),u(o,"width",e[2]),u(o,"height",e[1]),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){V(r,t,a),K(t,n),K(t,o)},p(r,[a]){a&32&&i!==(i=r[5]?"display:none;":void 0)&&u(n,"style",i),a&16&&u(n,"x",r[4]),a&8&&u(n,"y",r[3]),a&4&&u(n,"width",r[2]),a&2&&u(n,"height",r[1]),a&32&&u(o,"style",r[5]),a&16&&u(o,"x",r[4]),a&8&&u(o,"y",r[3]),a&4&&u(o,"width",r[2]),a&2&&u(o,"height",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}function kr(e,t,n){let i,o,s,r,a,{annotation:l}=t,{geom:f}=t,{style:h}=t;return e.$$set=c=>{"annotation"in c&&n(0,l=c.annotation),"geom"in c&&n(6,f=c.geom),"style"in c&&n(7,h=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,i=at(l,h)),e.$$.dirty&64&&n(4,{x:o,y:s,w:r,h:a}=f,o,(n(3,s),n(6,f)),(n(2,r),n(6,f)),(n(1,a),n(6,f)))},[l,a,r,s,o,i,f,h]}class Pr extends Me{constructor(t){super(),Oe(this,t,kr,Lr,ce,{annotation:0,geom:6,style:7})}}const Dr={elementToImage:(e,t)=>[e,t]},Yi=e=>({elementToImage:(t,n)=>{const i=e.getBoundingClientRect(),o=e.createSVGPoint();o.x=t+i.x,o.y=n+i.y;const{x:s,y:r}=o.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),Ur=250,Bi=(e,t)=>{const n=Ve();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:r=>{if(performance.now()-i<Ur){const{x:l,y:f}=sn(r,e),h=t.getAt(l,f);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},sn=(e,t)=>{const n=t.createSVGPoint(),i=t.getBoundingClientRect(),o=e.clientX-i.x,s=e.clientY-i.y,{left:r,top:a}=t.getBoundingClientRect();return n.x=o+r,n.y=s+a,n.matrixTransform(t.getScreenCTM().inverse())};function Xi(e,t,n){const i=e.slice();i[39]=t[n];const o=i[24](i[39].target.selector);return i[40]=o,i}function Fi(e,t,n){const i=e.slice();return i[43]=t[n],i}function rn(e){const t=e.slice(),n=t[43].target.selector;return t[46]=n,t}function zi(e){let t=e[43],n,i,o=ji(e);return{c(){o.c(),n=ve()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&65536&&ce(t,t=s[43])?(Ee(),F(o,1,1,q),be(),o=ji(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function Hr(e){let t,n;return t=new Sr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Vr(e){let t,n;return t=new Rr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Yr(e){let t,n;return t=new Pr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Br(e){var i;let t,n;return t=new Ar({props:{annotation:e[43],geom:(i=e[46])==null?void 0:i.geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(o,s){de(t,o,s),n=!0},p(o,s){var a;const r={};s[0]&65536&&(r.annotation=o[43]),s[0]&65536&&(r.geom=(a=o[46])==null?void 0:a.geometry),s[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(B(t.$$.fragment,o),n=!0)},o(o){F(t.$$.fragment,o),n=!1},d(o){ge(t,o)}}}function ji(e){let t,n,i,o;const s=[Br,Yr,Vr,Hr],r=[];function a(l,f){var h,c,d,y;return((h=l[46])==null?void 0:h.type)===ie.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===ie.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===ie.POLYGON?2:((y=l[46])==null?void 0:y.type)===ie.MULTIPOLYGLON?3:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=ve()},m(l,f){~t&&r[t].m(l,f),V(l,i,f),o=!0},p(l,f){let h=t;t=a(l),t===h?~t&&r[t].p(l,f):(n&&(Ee(),F(r[h],1,1,()=>{r[h]=null}),be()),~t?(n=r[t],n?n.p(l,f):(n=r[t]=s[t](l),n.c()),B(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(B(n),o=!0)},o(l){F(n),o=!1},d(l){l&&H(i),~t&&r[t].d(l)}}}function Gi(e){let t=rt(e[43])&&!e[9](e[43]),n,i,o=t&&zi(rn(e));return{c(){o&&o.c(),n=ve()},m(s,r){o&&o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&66048&&(t=rt(s[43])&&!s[9](s[43])),t?o?(o.p(rn(s),r),r[0]&66048&&B(o,1)):(o=zi(rn(s)),o.c(),B(o,1),o.m(n.parentNode,n)):o&&(Ee(),F(o,1,1,()=>{o=null}),be())},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o&&o.d(s)}}}function Qi(e){let t,n,i,o;const s=[Fr,Xr],r=[];function a(l,f){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=ve()},m(l,f){~t&&r[t].m(l,f),V(l,i,f),o=!0},p(l,f){let h=t;t=a(l),t===h?~t&&r[t].p(l,f):(n&&(Ee(),F(r[h],1,1,()=>{r[h]=null}),be()),~t?(n=r[t],n?n.p(l,f):(n=r[t]=s[t](l),n.c()),B(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(B(n),o=!0)},o(l){F(n),o=!1},d(l){l&&H(i),~t&&r[t].d(l)}}}function Xr(e){let t=`${e[2]}-${e[5]}`,n,i,o=qi(e);return{c(){o.c(),n=ve()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&36&&ce(t,t=`${s[2]}-${s[5]}`)?(Ee(),F(o,1,1,q),be(),o=qi(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function Fr(e){let t,n,i=Ce(e[8]),o=[];for(let r=0;r<i.length;r+=1)o[r]=Wi(Xi(e,i,r));const s=r=>F(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=ve()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);V(r,t,a),n=!0},p(r,a){if(a[0]&21107010){i=Ce(r[8]);let l;for(l=0;l<i.length;l+=1){const f=Xi(r,i,l);o[l]?(o[l].p(f,a),B(o[l],1)):(o[l]=Wi(f),o[l].c(),B(o[l],1),o[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<o.length;l+=1)s(l);be()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)B(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)F(o[a]);n=!1},d(r){r&&H(t),je(o,r)}}}function qi(e){let t,n;return t=new Ri({props:{target:e[6],tool:e[14],drawingMode:e[13],transform:e[12],viewportScale:e[17]}}),t.$on("create",e[21]),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){const s={};o[0]&64&&(s.target=i[6]),o[0]&16384&&(s.tool=i[14]),o[0]&8192&&(s.drawingMode=i[13]),o[0]&4096&&(s.transform=i[12]),o[0]&131072&&(s.viewportScale=i[17]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Zi(e){let t=e[39].id,n,i,o=Ki(e);return{c(){o.c(),n=ve()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&256&&ce(t,t=s[39].id)?(Ee(),F(o,1,1,q),be(),o=Ki(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function Ki(e){let t,n;return t=new Ii({props:{target:e[6],editor:e[24](e[39].target.selector),annotation:e[39],style:e[1],transform:e[12],viewportScale:e[17]}}),t.$on("change",function(){re(e[22](e[39]))&&e[22](e[39]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&64&&(s.target=e[6]),o[0]&256&&(s.editor=e[24](e[39].target.selector)),o[0]&256&&(s.annotation=e[39]),o[0]&2&&(s.style=e[1]),o[0]&4096&&(s.transform=e[12]),o[0]&131072&&(s.viewportScale=e[17]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Wi(e){let t,n,i=e[40]&&Zi(e);return{c(){i&&i.c(),t=ve()},m(o,s){i&&i.m(o,s),V(o,t,s),n=!0},p(o,s){o[40]?i?(i.p(o,s),s[0]&256&&B(i,1)):(i=Zi(o),i.c(),B(i,1),i.m(t.parentNode,t)):i&&(Ee(),F(i,1,1,()=>{i=null}),be())},i(o){n||(B(i),n=!0)},o(o){F(i),n=!1},d(o){o&&H(t),i&&i.d(o)}}}function zr(e){let t,n,i,o,s,r,a=Ce(e[16].filter(e[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=Gi(Fi(e,a,c));const f=c=>F(l[c],1,1,()=>{l[c]=null});let h=e[6]&&Qi(e);return{c(){t=L("svg"),n=L("g");for(let c=0;c<l.length;c+=1)l[c].c();i=L("g"),h&&h.c(),u(i,"class","drawing"),u(t,"role","application"),u(t,"tabindex",0),u(t,"class","a9s-annotationlayer"),Pe(t,"drawing",e[14]),Pe(t,"editing",e[8]),Pe(t,"hidden",!e[3]),Pe(t,"hover",e[15])},m(c,d){V(c,t,d),K(t,n);for(let y=0;y<l.length;y+=1)l[y]&&l[y].m(n,null);K(t,i),h&&h.m(i,null),e[35](i),e[36](t),o=!0,s||(r=[$(t,"pointerup",function(){re(e[10])&&e[10].apply(this,arguments)}),$(t,"pointerdown",function(){re(e[11])&&e[11].apply(this,arguments)}),$(t,"pointermove",e[23])],s=!0)},p(c,d){if(e=c,d[0]&66050){a=Ce(e[16].filter(e[34]));let y;for(y=0;y<a.length;y+=1){const g=Fi(e,a,y);l[y]?(l[y].p(g,d),B(l[y],1)):(l[y]=Gi(g),l[y].c(),B(l[y],1),l[y].m(n,null))}for(Ee(),y=a.length;y<l.length;y+=1)f(y);be()}e[6]?h?(h.p(e,d),d[0]&64&&B(h,1)):(h=Qi(e),h.c(),B(h,1),h.m(i,null)):h&&(Ee(),F(h,1,1,()=>{h=null}),be()),(!o||d[0]&16384)&&Pe(t,"drawing",e[14]),(!o||d[0]&256)&&Pe(t,"editing",e[8]),(!o||d[0]&8)&&Pe(t,"hidden",!e[3]),(!o||d[0]&32768)&&Pe(t,"hover",e[15])},i(c){if(!o){for(let d=0;d<a.length;d+=1)B(l[d]);B(h),o=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)F(l[d]);F(h),o=!1},d(c){c&&H(t),je(l,c),h&&h.d(),e[35](null),e[36](null),s=!1,Ie(r)}}}function jr(e,t,n){let i,o,s,r,a,l,f,h,c,d,y,g=q,p=()=>(g(),g=pn(m,X=>n(17,y=X)),m);e.$$.on_destroy.push(()=>g());let{drawingEnabled:O}=t,{image:_}=t,{preferredDrawingMode:T}=t,{state:A}=t,{style:S=void 0}=t,{toolName:v=nn()[0]}=t,{user:I}=t,{visible:C=!0}=t,P=0;const k=()=>n(5,P+=1),j=()=>v,G=()=>O;let w,b,m;Ge(()=>p(n(7,m=ii(_,b))));const{hover:E,selection:R,store:N}=A;kt(e,E,X=>n(15,h=X)),kt(e,R,X=>n(33,c=X)),kt(e,N,X=>n(16,d=X));let D,Q;const z=X=>{D&&N.unobserve(D);const he=X.filter(({editable:te})=>te).map(({id:te})=>te);he.length>0?(n(8,Q=he.map(te=>N.getAnnotation(te)).filter(te=>te&&rt(te))),D=te=>{const{updated:me}=te.changes;n(8,Q=me==null?void 0:me.map(Te=>Te.newValue))},N.observe(D,{annotations:he})):n(8,Q=void 0)},W=X=>{const he=Zn(),te={id:he,bodies:[],target:{annotation:he,selector:X.detail,creator:I,created:new Date}};N.addAnnotation(te),R.setSelected(te.id)},J=X=>he=>{var nt;const{target:te}=X,me=10*60*1e3,Te=((nt=te.creator)==null?void 0:nt.id)!==I.id||!te.created||new Date().getTime()-te.created.getTime()>me;N.updateTarget({...te,selector:he.detail,created:Te?te.created:new Date,updated:Te?new Date:void 0,updatedBy:Te?I:void 0})},ee=X=>{const{x:he,y:te}=sn(X,b),me=N.getAt(he,te);me?h!==me.id&&E.set(me.id):E.set(void 0)},ae=X=>Ci(X),le=X=>rt(X);function Ne(X){yt[X?"unshift":"push"](()=>{w=X,n(6,w)})}function ke(X){yt[X?"unshift":"push"](()=>{b=X,n(4,b)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,O=X.drawingEnabled),"image"in X&&n(25,_=X.image),"preferredDrawingMode"in X&&n(26,T=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,S=X.style),"toolName"in X&&n(2,v=X.toolName),"user"in X&&n(28,I=X.user),"visible"in X&&n(3,C=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(14,{tool:i,opts:o}=on(v)||{tool:void 0,opts:void 0},i,(n(32,o),n(2,v))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(13,s=(o==null?void 0:o.drawingMode)||T),e.$$.dirty[0]&16&&n(12,r=Yi(b)),e.$$.dirty[0]&16&&n(11,{onPointerDown:a,onPointerUp:l}=Bi(b,N),a,(n(10,l),n(4,b))),e.$$.dirty[1]&4&&n(9,f=X=>c.selected.find(he=>he.id===X.id&&he.editable)),e.$$.dirty[1]&4&&z(c.selected)},[O,S,v,C,b,P,w,m,Q,f,l,a,r,s,i,h,d,y,E,R,N,W,J,ee,ae,_,T,A,I,k,j,G,o,c,le,Ne,ke]}class Ji extends Me{constructor(t){super(),Oe(this,t,jr,zr,ce,{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 xi(e,t,n=0,i=e.length-1,o=Gr){for(;i>n;){if(i-n>600){const l=i-n+1,f=t-n+1,h=Math.log(l),c=.5*Math.exp(2*h/3),d=.5*Math.sqrt(h*c*(l-c)/l)*(f-l/2<0?-1:1),y=Math.max(n,Math.floor(t-f*c/l+d)),g=Math.min(i,Math.floor(t+(l-f)*c/l+d));xi(e,t,y,g,o)}const s=e[t];let r=n,a=i;for(ht(e,n,t),o(e[i],s)>0&&ht(e,n,i);r<a;){for(ht(e,r,a),r++,a--;o(e[r],s)<0;)r++;for(;o(e[a],s)>0;)a--}o(e[n],s)===0?ht(e,n,a):(a++,ht(e,a,i)),a<=t&&(n=a+1),t<=a&&(i=a-1)}}function ht(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function Gr(e,t){return e<t?-1:e>t?1:0}class Qr{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 i=[];if(!Ct(t,n))return i;const o=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const a=n.children[r],l=n.leaf?o(a):a;Ct(t,l)&&(n.leaf?i.push(a):an(t,l)?this._all(a,i):s.push(a))}n=s.pop()}return i}collides(t){let n=this.data;if(!Ct(t,n))return!1;const i=[];for(;n;){for(let o=0;o<n.children.length;o++){const s=n.children[o],r=n.leaf?this.toBBox(s):s;if(Ct(t,r)){if(n.leaf||an(t,r))return!0;i.push(s)}}n=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let 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 i=this.data;this.data=n,n=i}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=tt([]),this}remove(t,n){if(!t)return this;let i=this.data;const o=this.toBBox(t),s=[],r=[];let a,l,f;for(;i||s.length;){if(i||(i=s.pop(),l=s[s.length-1],a=r.pop(),f=!0),i.leaf){const h=qr(t,i.children,n);if(h!==-1)return i.children.splice(h,1),s.push(i),this._condense(s),this}!f&&!i.leaf&&an(i,o)?(s.push(i),r.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],f=!1):i=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 i=[];for(;t;)t.leaf?n.push(...t.children):i.push(...t.children),t=i.pop();return n}_build(t,n,i,o){const s=i-n+1;let r=this._maxEntries,a;if(s<=r)return a=tt(t.slice(n,i+1)),et(a,this.toBBox),a;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),a=tt([]),a.leaf=!1,a.height=o;const l=Math.ceil(s/r),f=l*Math.ceil(Math.sqrt(r));$i(t,n,i,f,this.compareMinX);for(let h=n;h<=i;h+=f){const c=Math.min(h+f-1,i);$i(t,h,c,l,this.compareMinY);for(let d=h;d<=c;d+=l){const y=Math.min(d+l-1,c);a.children.push(this._build(t,d,y,o-1))}}return et(a,this.toBBox),a}_chooseSubtree(t,n,i,o){for(;o.push(n),!(n.leaf||o.length-1===i);){let s=1/0,r=1/0,a;for(let l=0;l<n.children.length;l++){const f=n.children[l],h=ln(f),c=Wr(t,f)-h;c<r?(r=c,s=h<s?h:s,a=f):c===r&&h<s&&(s=h,a=f)}n=a||n.children[0]}return n}_insert(t,n,i){const o=i?t:this.toBBox(t),s=[],r=this._chooseSubtree(o,this.data,n,s);for(r.children.push(t),gt(r,o);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(o,s,n)}_split(t,n){const i=t[n],o=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,o);const r=this._chooseSplitIndex(i,s,o),a=tt(i.children.splice(r,i.children.length-r));a.height=i.height,a.leaf=i.leaf,et(i,this.toBBox),et(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,n){this.data=tt([t,n]),this.data.height=t.height+1,this.data.leaf=!1,et(this.data,this.toBBox)}_chooseSplitIndex(t,n,i){let o,s=1/0,r=1/0;for(let a=n;a<=i-n;a++){const l=dt(t,0,a,this.toBBox),f=dt(t,a,i,this.toBBox),h=Jr(l,f),c=ln(l)+ln(f);h<s?(s=h,o=a,r=c<r?c:r):h===s&&c<r&&(r=c,o=a)}return o||i-n}_chooseSplitAxis(t,n,i){const o=t.leaf?this.compareMinX:Zr,s=t.leaf?this.compareMinY:Kr,r=this._allDistMargin(t,n,i,o),a=this._allDistMargin(t,n,i,s);r<a&&t.children.sort(o)}_allDistMargin(t,n,i,o){t.children.sort(o);const s=this.toBBox,r=dt(t,0,n,s),a=dt(t,i-n,i,s);let l=vt(r)+vt(a);for(let f=n;f<i-n;f++){const h=t.children[f];gt(r,t.leaf?s(h):h),l+=vt(r)}for(let f=i-n-1;f>=n;f--){const h=t.children[f];gt(a,t.leaf?s(h):h),l+=vt(a)}return l}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)gt(n[o],t)}_condense(t){for(let n=t.length-1,i;n>=0;n--)t[n].children.length===0?n>0?(i=t[n-1].children,i.splice(i.indexOf(t[n]),1)):this.clear():et(t[n],this.toBBox)}}function qr(e,t,n){if(!n)return t.indexOf(e);for(let i=0;i<t.length;i++)if(n(e,t[i]))return i;return-1}function et(e,t){dt(e,0,e.children.length,t,e)}function dt(e,t,n,i,o){o||(o=tt(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];gt(o,e.leaf?i(r):r)}return o}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 Zr(e,t){return e.minX-t.minX}function Kr(e,t){return e.minY-t.minY}function ln(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function vt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Wr(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 Jr(e,t){const n=Math.max(e.minX,t.minX),i=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,o-n)*Math.max(0,s-i)}function an(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Ct(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function tt(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function $i(e,t,n,i,o){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=i)continue;const r=t+Math.ceil((n-t)/i/2)*i;xi(e,r,t,n,o),s.push(t,r,r,n)}}const xr=()=>{const e=new Qr,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=c=>{if(!lt(c))return;const{minX:d,minY:y,maxX:g,maxY:p}=c.selector.geometry.bounds,O={minX:d,minY:y,maxX:g,maxY:p,target:c};e.insert(O),t.set(c.annotation,O)},s=c=>{if(!lt(c))return;const d=t.get(c.annotation);d&&e.remove(d),t.delete(c.annotation)};return{all:n,clear:i,getAt:(c,d,y)=>{const p=e.search({minX:c,minY:d,maxX:c,maxY:d}).map(O=>O.target).filter(O=>O.selector.type===ie.RECTANGLE||Mn(O.selector,c,d));return p.length>0?(p.sort((O,_)=>mt(O.selector)-mt(_.selector)),p):[]},getIntersecting:(c,d,y,g)=>e.search({minX:c,minY:d,maxX:c+y,maxY:d+g}).map(p=>p.target),insert:o,remove:s,set:(c,d=!0)=>{d&&i();const y=c.reduce((g,p)=>{if(lt(p)){const{minX:O,minY:_,maxX:T,maxY:A}=p.selector.geometry.bounds;return[...g,{minX:O,minY:_,maxX:T,maxY:A,target:p}]}else return g},[]);y.forEach(g=>t.set(g.target.annotation,g)),e.load(y)},size:()=>e.all().length,update:(c,d)=>{s(c),o(d)}}},eo=e=>{const t=ds(),n=xr(),i=es(t,e.userSelectAction,e.adapter),o=$o(t),s=ms();return t.observe(({changes:l})=>{n.set((l.created||[]).map(f=>f.target),!1),(l.deleted||[]).forEach(f=>n.remove(f.target)),(l.updated||[]).forEach(({oldValue:f,newValue:h})=>n.update(f.target,h.target))}),{store:{...t,getAt:(l,f,h)=>{const c=n.getAt(l,f,h);if(h)return c.map(y=>t.getAnnotation(y.annotation)).filter(Boolean).filter(h)[0];{const d=c[0];return d?t.getAnnotation(d.annotation):void 0}},getIntersecting:(l,f,h,c)=>n.getIntersecting(l,f,h,c).map(d=>t.getAnnotation(d.annotation))},selection:i,hover:o,viewport:s}},to=e=>{const t=eo(e);return{...t,store:gs(t.store)}},no=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const o=e;t=document.createElement("canvas"),t.width=o.width,t.height=o.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(o,0,0,o.width,o.height)}let i=0;for(let o=1;o<10;o++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),a=Math.round(o*t.height/10),l=n.getImageData(r,a,1,1).data,f=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=f}return i/81},io=e=>{const t=no(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},un=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?io(e):n),oo=(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}),fn=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,so=(e,t)=>{const n=t||document,i=r=>{const a=r;a.key==="z"&&a.ctrlKey?e.undo():a.key==="y"&&a.ctrlKey&&e.redo()},o=r=>{const a=r;a.key==="z"&&a.metaKey&&(a.shiftKey?e.redo():e.undo())},s=()=>{fn?n.removeEventListener("keydown",o):n.removeEventListener("keydown",i)};return fn?n.addEventListener("keydown",o):n.addEventListener("keydown",i),{destroy:s}},$r=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=oo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:jt.EDIT,theme:"light"}),o=to(i),{selection:s,store:r}=o,a=_s(r,i.initialHistory),l=ws(o,a,i.adapter,i.autoSave),f=document.createElement("DIV");f.style.position="relative",f.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(f,n),f.appendChild(n);const h=so(a);let c=Ns();un(n,f,i.theme);const d=new Ji({target:f,props:{drawingEnabled:!!i.drawingEnabled,image:n,preferredDrawingMode:i.drawingMode,state:o,style:i.style,user:c}});d.$on("click",w=>{const{originalEvent:b,annotation:m}=w.detail;m?s.userSelect(m.id,b):s.isEmpty()||s.clear()});const y=bs(o,a,i.adapter),g=()=>d.cancelDrawing(),p=()=>{d.$destroy(),f.parentNode.insertBefore(n,f),f.parentNode.removeChild(f),h.destroy(),a.destroy()},O=()=>d.getDrawingTool(),_=()=>c,T=()=>d.isDrawingEnabled(),A=(w,b,m)=>Ui(w,b,m),S=(w,b)=>Ni(w,b),v=w=>{if(!on(w))throw`No drawing tool named ${w}`;d.$set({toolName:w})},I=w=>d.$set({drawingEnabled:w}),C=w=>{console.warn("Filter not implemented yet")},P=w=>d.$set({style:w}),k=w=>un(n,f,w),j=w=>{c=w,d.$set({user:w})},G=w=>d.$set({visible:w});return{...y,cancelDrawing:g,destroy:p,getDrawingTool:O,getUser:_,isDrawingEnabled:T,listDrawingTools:nn,on:l.on,off:l.off,registerDrawingTool:A,registerShapeEditor:S,setDrawingEnabled:I,setDrawingTool:v,setFilter:C,setStyle:P,setTheme:k,setUser:j,setVisible:G,element:f,state:o}};U.Editor=St,U.EditorMount=Ii,U.Handle=Ze,U.IdentityTransform=Dr,U.PolygonEditor=pi,U.RectangleEditor=yi,U.RectangleUtil=Cn,U.RubberbandRectangle=ki,U.SVGAnnotationLayer=Ji,U.ShapeType=ie,U.ToolMount=Ri,U.UserSelectAction=jt,U.W3CImageFormat=Ds,U.addEventListeners=Bi,U.boundsFromMultiPolygonElements=bt,U.boundsFromPoints=Se,U.chainStyles=As,U.computeArea=mt,U.computePolygonArea=wt,U.computeStyle=Ts,U.createBody=ss,U.createImageAnnotator=$r,U.createImageAnnotatorState=eo,U.createSVGTransform=Yi,U.createSvelteImageAnnotatorState=to,U.defaultColorProvider=Ps,U.detectTheme=io,U.distance=Mt,U.enableResponsive=ii,U.fillDefaults=oo,U.getAllCorners=vn,U.getEditor=Ci,U.getMaskDimensions=ut,U.getSVGPoint=sn,U.getTool=on,U.initKeyboardCommands=so,U.intersects=Mn,U.isImageAnnotation=rt,U.isImageAnnotationTarget=lt,U.isMac=fn,U.isPointInPolygon=Et,U.isTouch=Ue,U.listDrawingTools=nn,U.multipolygonElementToPath=De,U.parseFragmentSelector=Nn,U.parseSVGSelector=Gn,U.parseW3CImageAnnotation=ti,U.pointsToPath=Sn,U.registerEditor=Ni,U.registerShapeUtil=st,U.registerTool=Ui,U.sampleBrightness=no,U.serializeFragmentSelector=In,U.serializeSVGSelector=Qn,U.serializeW3CImageAnnotation=ni,U.setTheme=un,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})});
|
|
3
3
|
//# sourceMappingURL=annotorious.js.map
|