@annotorious/annotorious 3.3.6 → 3.4.1
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/polygon/MidpointHandle.svelte.d.ts +1 -0
- package/dist/annotation/utils/index.d.ts +2 -0
- package/dist/annotation/utils/svg.d.ts +7 -0
- package/dist/annotorious.css +1 -1
- package/dist/annotorious.es.js +4057 -3165
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +2 -2
- package/dist/annotorious.js.map +1 -1
- package/package.json +6 -6
- package/src/Annotorious.css +6 -1
- package/src/annotation/SVGAnnotationLayer.svelte +4 -1
- package/src/annotation/editors/Editor.svelte +17 -1
- package/src/annotation/editors/EditorMount.svelte +7 -1
- package/src/annotation/editors/Handle.svelte +84 -25
- package/src/annotation/editors/multipolygon/MultiPolygonEditor.svelte +27 -3
- package/src/annotation/editors/polygon/MidpointHandle.svelte +76 -0
- package/src/annotation/editors/polygon/PolygonEditor.svelte +277 -9
- package/src/annotation/editors/rectangle/RectangleEditor.svelte +26 -2
- package/src/annotation/tools/polygon/RubberbandPolygon.svelte +49 -17
- package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +36 -2
- package/src/annotation/utils/index.ts +2 -0
- package/src/annotation/utils/svg.ts +11 -0
- package/src/themes/light/index.css +2 -2
package/dist/annotorious.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(L,Y){typeof exports=="object"&&typeof module<"u"?Y(exports):typeof define=="function"&&define.amd?define(["exports"],Y):(L=typeof globalThis<"u"?globalThis:L||self,Y(L.Annotorious={}))})(this,function(L){"use strict";var us=Object.defineProperty;var fs=(L,Y,Ne)=>Y in L?us(L,Y,{enumerable:!0,configurable:!0,writable:!0,value:Ne}):L[Y]=Ne;var W=(L,Y,Ne)=>fs(L,typeof Y!="symbol"?Y+"":Y,Ne);function Y(){}function Ne(e,t){for(const n in t)e[n]=t[n];return e}function Ft(e){return e()}function Gt(){return Object.create(null)}function me(e){e.forEach(Ft)}function J(e){return typeof e=="function"}function te(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Mi(e){return Object.keys(e).length===0}function zt(e,...t){if(e==null){for(const i of t)i(void 0);return Y}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function wt(e,t,n){e.$$.on_destroy.push(zt(t,n))}function Si(e,t,n,i){if(e){const o=jt(e,t,n,i);return e[0](o)}}function jt(e,t,n,i){return e[1]&&i?Ne(n.ctx.slice(),e[1](i(t))):n.ctx}function Ni(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 r=[],s=Math.max(t.dirty.length,o.length);for(let a=0;a<s;a+=1)r[a]=t.dirty[a]|o[a];return r}return t.dirty|o}return t.dirty}function Ci(e,t,n,i,o,r){if(o){const s=jt(t,n,i,r);e.p(s,o)}}function Ri(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 Qt(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function rt(e){return e??""}function ye(e,t){e.appendChild(t)}function U(e,t,n){e.insertBefore(t,n||null)}function v(e){e.parentNode&&e.parentNode.removeChild(e)}function Ue(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function B(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function qt(e){return document.createTextNode(e)}function we(){return qt(" ")}function pe(){return qt("")}function K(e,t,n,i){return e.addEventListener(t,n,i),()=>e.removeEventListener(t,n,i)}function h(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Li(e){return Array.from(e.childNodes)}function Ce(e,t,n){e.classList.toggle(t,!!n)}function Ii(e,t,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:i})}let je;function Qe(e){je=e}function Zt(){if(!je)throw new Error("Function called outside component initialization");return je}function qe(e){Zt().$$.on_mount.push(e)}function He(){const e=Zt();return(t,n,{cancelable:i=!1}={})=>{const o=e.$$.callbacks[t];if(o){const r=Ii(t,n,{cancelable:i});return o.slice().forEach(s=>{s.call(e,r)}),!r.defaultPrevented}return!0}}function _e(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(i=>i.call(this,t))}const Be=[],st=[];let Ye=[];const Wt=[],vi=Promise.resolve();let Et=!1;function Ui(){Et||(Et=!0,vi.then(Kt))}function Tt(e){Ye.push(e)}const At=new Set;let Xe=0;function Kt(){if(Xe!==0)return;const e=je;do{try{for(;Xe<Be.length;){const t=Be[Xe];Xe++,Qe(t),Di(t.$$)}}catch(t){throw Be.length=0,Xe=0,t}for(Qe(null),Be.length=0,Xe=0;st.length;)st.pop()();for(let t=0;t<Ye.length;t+=1){const n=Ye[t];At.has(n)||(At.add(n),n())}Ye.length=0}while(Be.length);for(;Wt.length;)Wt.pop()();Et=!1,At.clear(),Qe(e)}function Di(e){if(e.fragment!==null){e.update(),me(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Tt)}}function Pi(e){const t=[],n=[];Ye.forEach(i=>e.indexOf(i)===-1?t.push(i):n.push(i)),n.forEach(i=>i()),Ye=t}const lt=new Set;let De;function ue(){De={r:0,c:[],p:De}}function fe(){De.r||me(De.c),De=De.p}function I(e,t){e&&e.i&&(lt.delete(e),e.i(t))}function D(e,t,n,i){if(e&&e.o){if(lt.has(e))return;lt.add(e),De.c.push(()=>{lt.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 ae(e){e&&e.c()}function re(e,t,n){const{fragment:i,after_update:o}=e.$$;i&&i.m(t,n),Tt(()=>{const r=e.$$.on_mount.map(Ft).filter(J);e.$$.on_destroy?e.$$.on_destroy.push(...r):me(r),e.$$.on_mount=[]}),o.forEach(Tt)}function se(e,t){const n=e.$$;n.fragment!==null&&(Pi(n.after_update),me(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function ki(e,t){e.$$.dirty[0]===-1&&(Be.push(e),Ui(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function de(e,t,n,i,o,r,s=null,a=[-1]){const l=je;Qe(e);const u=e.$$={fragment:null,ctx:[],props:r,update:Y,not_equal:o,bound:Gt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Gt(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};s&&s(u.root);let c=!1;if(u.ctx=n?n(e,t.props||{},(f,d,...p)=>{const g=p.length?p[0]:d;return u.ctx&&o(u.ctx[f],u.ctx[f]=g)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](g),c&&ki(e,f)),d}):[],u.update(),c=!0,me(u.before_update),u.fragment=i?i(u.ctx):!1,t.target){if(t.hydrate){const f=Li(t.target);u.fragment&&u.fragment.l(f),f.forEach(v)}else u.fragment&&u.fragment.c();t.intro&&I(e.$$.fragment),re(e,t.target,t.anchor),Kt()}Qe(l)}class he{constructor(){W(this,"$$");W(this,"$$set")}$destroy(){se(this,1),this.$destroy=Y}$on(t,n){if(!J(n))return Y;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&&!Mi(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Vi="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Vi);var z=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGLON="MULTIPOLYGON",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(z||{});const bt={},Ze=(e,t)=>bt[e]=t,at=e=>bt[e.type].area(e),Jt=(e,t,n)=>bt[e.type].intersects(e,t,n),Ae=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;return e.forEach(([r,s])=>{t=Math.min(t,r),n=Math.min(n,s),i=Math.max(i,r),o=Math.max(o,s)}),{minX:t,minY:n,maxX:i,maxY:o}},ut=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)},ft=(e,t,n)=>{let i=!1;for(let o=0,r=e.length-1;o<e.length;r=o++){const s=e[o][0],a=e[o][1],l=e[r][0],u=e[r][1];a>n!=u>n&&t<(l-s)*(n-a)/(u-a)+s&&(i=!i)}return i},$t=(e,t=!0)=>{let n="M ";return e.forEach(([i,o],r)=>{r===0?n+=`${i},${o}`:n+=` L ${i},${o}`}),t&&(n+=" Z"),n},Hi={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:i,cy:o,rx:r,ry:s}=e.geometry,a=0,l=Math.cos(a),u=Math.sin(a),c=t-i,f=n-o,d=l*c+u*f,p=u*c-l*f;return d*d/(r*r)+p*p/(s*s)<=1}};Ze(z.ELLIPSE,Hi);const Bi={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,i)=>{const[o,...r]=i.rings,s=ut(o.points),a=r.reduce((l,u)=>l+ut(u.points),0);return n+s-a},0)},intersects:(e,t,n)=>{const{polygons:i}=e.geometry;for(const o of i){const[r,...s]=o.rings;if(ft(r.points,t,n)){let a=!1;for(const l of s)if(ft(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 Ae(t)},Re=e=>e.rings.map(n=>$t(n.points)).join(" ");Ze(z.MULTIPOLYGLON,Bi);const Yi={area:e=>{const t=e.geometry.points;return ut(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return ft(i,t,n)}};Ze(z.POLYGON,Yi);const tn={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};Ze(z.RECTANGLE,tn);const We=e=>Ke(e.target),Ke=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],[r,s,a,l,u,c,f]=o;if(s!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,p,g,y]=[l,u,c,f].map(parseFloat);return{type:z.RECTANGLE,geometry:{x:d,y:p,w:g,h:y,bounds:{minX:d,minY:t?p-y:p,maxX:d+g,maxY:t?p:p+y}}}},on=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",sn=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},Xi=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${rn}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},ln=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),i=n.lookupPrefix(rn),o=n.lookupNamespaceURI(null);return i||o?sn(n).firstChild:sn(Xi(n)).firstChild},$=" ";function xi(e){let t="";Array.isArray(e)||(e=[e]);for(let n=0;n<e.length;n++){const i=e[n];if(i.type===E.CLOSE_PATH)t+="z";else if(i.type===E.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===E.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===E.MOVE_TO)t+=(i.relative?"m":"M")+i.x+$+i.y;else if(i.type===E.LINE_TO)t+=(i.relative?"l":"L")+i.x+$+i.y;else if(i.type===E.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+$+i.y1+$+i.x2+$+i.y2+$+i.x+$+i.y;else if(i.type===E.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+$+i.y2+$+i.x+$+i.y;else if(i.type===E.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+$+i.y1+$+i.x+$+i.y;else if(i.type===E.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+$+i.y;else if(i.type===E.ARC)t+=(i.relative?"a":"A")+i.rX+$+i.rY+$+i.xRot+$+ +i.lArcFlag+$+ +i.sweepFlag+$+i.x+$+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Ot([e,t],n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function Ee(...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 Le=Math.PI;function Mt(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:r,y:s}=e;if(Math.abs(i)<1e-10||Math.abs(o)<1e-10){e.rX=0,e.rY=0,e.cX=(t+r)/2,e.cY=(n+s)/2,e.phi1=0,e.phi2=0;return}i=Math.abs(e.rX),o=Math.abs(e.rY);const a=e.xRot/180*Le,[l,u]=Ot([(t-r)/2,(n-s)/2],-a),c=Math.pow(l,2)/Math.pow(i,2)+Math.pow(u,2)/Math.pow(o,2);1<c&&(i*=Math.sqrt(c),o*=Math.sqrt(c)),e.rX=i,e.rY=o;const f=Math.pow(i,2)*Math.pow(u,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)-f)/f)),p=i*u/o*d,g=-o*l/i*d,y=Ot([p,g],a);e.cX=y[0]+(t+r)/2,e.cY=y[1]+(n+s)/2,e.phi1=Math.atan2((u-g)/o,(l-p)/i),e.phi2=Math.atan2((-u-g)/o,(-l-p)/i),e.sweepFlag===0&&e.phi2>e.phi1&&(e.phi2-=2*Le),e.sweepFlag===1&&e.phi2<e.phi1&&(e.phi2+=2*Le),e.phi1*=180/Le,e.phi2*=180/Le}function an(e,t,n){Ee(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 Pe=Math.PI/180;function un(e,t,n){return(1-n)*e+n*t}function fn(e,t,n,i){return e+Math.cos(i/180*Le)*t+Math.sin(i/180*Le)*n}function cn(e,t,n,i){const r=t-e,s=n-t,a=i-n,l=3*r+3*a-6*s,u=(s-r)*6,c=3*r;return Math.abs(l)<1e-6?Math.abs(u)<1e-6?[]:[-c/u]:Fi(u/l,c/l,1e-6)}function dn(e,t,n,i,o){const r=1-o,s=r*r*r,a=3*r*r*o,l=3*r*o*o,u=o*o*o;return e*s+t*a+n*l+i*u}function Fi(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 Gi(e,t,n){e.cX||Mt(e,t,n);const i=e.xRot/180*Le;if(Math.abs(e.rX)<1e-10||Math.abs(e.rY)<1e-10)return[{relative:e.relative,type:E.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),r=Math.max(e.phi1,e.phi2),s=r-o,a=Math.ceil(s/90),l=new Array(a);let u=t,c=n;const f=(d,p)=>{const[g,y]=Ot([d*e.rX,p*e.rY],i);return[e.cX+g,e.cY+y]};for(let d=0;d<a;d++){const p=un(e.phi1,e.phi2,d/a),g=un(e.phi1,e.phi2,(d+1)/a),y=g-p,T=4/3*Math.tan(y*Pe/4),_=Math.cos(p*Pe)-T*Math.sin(p*Pe),m=Math.sin(p*Pe)+T*Math.cos(p*Pe),w=Math.cos(g*Pe),b=Math.sin(g*Pe),C=w+T*b,k=b-T*w,V=f(_,m),H=f(C,k),q=f(w,b),Z={relative:e.relative,type:E.CURVE_TO,x:q[0],y:q[1],x1:V[0],y1:V[1],x2:H[0],y2:H[1]};e.relative&&(Z.x1-=u,Z.y1-=c,Z.x2-=u,Z.y2-=c,Z.x-=u,Z.y-=c),u=q[0],c=q[1],l[d]=Z}return l}function St(e,t,n){const i=t[0]-e[0],o=t[1]-e[1],r=n[0]-e[0],s=n[1]-e[1],a=i*s-o*r;if(!(Math.abs(a)<1e-10))return!1;const u=i*r+o*s,c=i*i+o*o,f=r*r+s*s;return 0<=u&&u<=f&&c<=f}function zi(e,t=!0){if(e.length<2)return e;const n=ee.INFO((r,s,a)=>({...r,x:r.x??s,y:r.y??a,relative:r.relative??!1})),i=[];let o=[];for(const r of e){const s=n(r);s.type===E.MOVE_TO&&o.length>0&&(t?i.push(...ct(o)):i.unshift(...ct(o)),o=[]),o.push(s)}return o.length>0&&(t?i.push(...ct(o)):i.unshift(...ct(o))),i}function ct(e){var o;const t=((o=e[e.length-1])==null?void 0:o.type)===E.CLOSE_PATH,n=t?e.length-2:e.length-1,i=[{type:E.MOVE_TO,relative:!1,x:e[n].x,y:e[n].y}];for(let r=n;r>0;r--){const s=e[r],a=e[r-1];if(s.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(s.type){case E.HORIZ_LINE_TO:i.push({type:E.HORIZ_LINE_TO,relative:!1,x:a.x});break;case E.VERT_LINE_TO:i.push({type:E.VERT_LINE_TO,relative:!1,y:a.y});break;case E.LINE_TO:case E.MOVE_TO:i.push({type:E.LINE_TO,relative:!1,x:a.x,y:a.y});break;case E.CURVE_TO:i.push({type:E.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:s.x2,y1:s.y2,x2:s.x1,y2:s.y1});break;case E.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case E.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case E.ARC:throw new Error("Unsupported command: A (arc)");case E.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:E.CLOSE_PATH}),i}function ji(e=1e13){Ee(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 hn(){return Te((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 Qi(){return Te((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 qi(e=!0,t=!0,n=!0,i=!0){return Te((o,r,s,a,l)=>{if(isNaN(a)&&!(o.type&E.MOVE_TO))throw new Error("path must start with moveto");if(t&&o.type&E.HORIZ_LINE_TO&&(o.type=E.LINE_TO,o.y=o.relative?0:s),n&&o.type&E.VERT_LINE_TO&&(o.type=E.LINE_TO,o.x=o.relative?0:r),e&&o.type&E.CLOSE_PATH&&(o.type=E.LINE_TO,o.x=o.relative?a-r:a,o.y=o.relative?l-s:l),o.type&E.ARC&&(o.rX===0||o.rY===0)&&(o.type=E.LINE_TO,delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag),i&&o.type&E.QUAD_TO){const u=[r,s],c=o.relative?[r+o.x1,s+o.y1]:[o.x1,o.y1],f=o.relative?[r+o.x,s+o.y]:[o.x,o.y];St(u,c,f)&&(o.type=E.LINE_TO,delete o.x1,delete o.y1)}if(i&&o.type&E.CURVE_TO){const u=[r,s],c=o.relative?[r+o.x1,s+o.y1]:[o.x1,o.y1],f=o.relative?[r+o.x2,s+o.y2]:[o.x2,o.y2],d=o.relative?[r+o.x,s+o.y]:[o.x,o.y];St(u,c,d)&&St(u,f,d)&&(o.type=E.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function gn(){let e=NaN,t=NaN,n=NaN,i=NaN;return Te((o,r,s)=>(o.type&E.SMOOTH_CURVE_TO&&(o.type=E.CURVE_TO,e=isNaN(e)?r:e,t=isNaN(t)?s:t,o.x1=o.relative?r-e:2*r-e,o.y1=o.relative?s-t:2*s-t),o.type&E.CURVE_TO?(e=o.relative?r+o.x2:o.x2,t=o.relative?s+o.y2:o.y2):(e=NaN,t=NaN),o.type&E.SMOOTH_QUAD_TO&&(o.type=E.QUAD_TO,n=isNaN(n)?r:n,i=isNaN(i)?s:i,o.x1=o.relative?r-n:2*r-n,o.y1=o.relative?s-i:2*s-i),o.type&E.QUAD_TO?(n=o.relative?r+o.x1:o.x1,i=o.relative?s+o.y1:o.y1):(n=NaN,i=NaN),o))}function pn(){let e=NaN,t=NaN;return Te((n,i,o)=>{if(n.type&E.SMOOTH_QUAD_TO&&(n.type=E.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&E.QUAD_TO){e=n.relative?i+n.x1:n.x1,t=n.relative?o+n.y1:n.y1;const r=n.x1,s=n.y1;n.type=E.CURVE_TO,n.x1=((n.relative?0:i)+r*2)/3,n.y1=((n.relative?0:o)+s*2)/3,n.x2=(n.x+r*2)/3,n.y2=(n.y+s*2)/3}else e=NaN,t=NaN;return n})}function Te(e){let t=0,n=0,i=NaN,o=NaN;return function(s){if(isNaN(i)&&!(s.type&E.MOVE_TO))throw new Error("path must start with moveto");const a=e(s,t,n,i,o);return s.type&E.CLOSE_PATH&&(t=i,n=o),"x"in s&&typeof s.x<"u"&&(t=s.relative?t+s.x:s.x),"y"in s&&typeof s.y<"u"&&(n=s.relative?n+s.y:s.y),s.type&E.MOVE_TO&&(i=t,o=n),a}}function Zi(e=0){Ee(e);let t=NaN,n=NaN,i=NaN,o=NaN;return Te((r,s,a,l,u)=>{const c=Math.abs;let f=!1,d=0,p=0;if(r.type&E.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:s-t,p=isNaN(n)?0:a-n),r.type&(E.CURVE_TO|E.SMOOTH_CURVE_TO)?(t=r.relative?s+r.x2:r.x2,n=r.relative?a+r.y2:r.y2):(t=NaN,n=NaN),r.type&E.SMOOTH_QUAD_TO?(i=isNaN(i)?s:2*s-i,o=isNaN(o)?a:2*a-o):r.type&E.QUAD_TO?(i=r.relative?s+r.x1:r.x1,o=r.relative?a+r.y1:r.y2):(i=NaN,o=NaN),r.type&E.LINE_COMMANDS||r.type&E.ARC&&(r.rX===0||r.rY===0||!r.lArcFlag)||r.type&E.CURVE_TO||r.type&E.SMOOTH_CURVE_TO||r.type&E.QUAD_TO||r.type&E.SMOOTH_QUAD_TO){const g=typeof r.x>"u"?0:r.relative?r.x:r.x-s,y=typeof r.y>"u"?0:r.relative?r.y:r.y-a;d=isNaN(i)?typeof r.x1>"u"?d:r.relative?r.x:r.x1-s:i-s,p=isNaN(o)?typeof r.y1>"u"?p:r.relative?r.y:r.y1-a:o-a;const T=typeof r.x2>"u"?0:r.relative?r.x:r.x2-s,_=typeof r.y2>"u"?0:r.relative?r.y:r.y2-a;c(g)<=e&&c(y)<=e&&c(d)<=e&&c(p)<=e&&c(T)<=e&&c(_)<=e&&(f=!0)}return r.type&E.CLOSE_PATH&&c(s-l)<=e&&c(a-u)<=e&&(f=!0),f?[]:r})}function Ie(e,t,n,i,o,r){return Ee(e,t,n,i,o,r),Te((s,a,l,u)=>{const c=s.x1,f=s.x2,d=s.relative&&!isNaN(u),p=typeof s.x<"u"?s.x:d?0:a,g=typeof s.y<"u"?s.y:d?0:l;s.type&E.HORIZ_LINE_TO&&t!==0&&(s.type=E.LINE_TO,s.y=s.relative?0:l),s.type&E.VERT_LINE_TO&&n!==0&&(s.type=E.LINE_TO,s.x=s.relative?0:a),typeof s.x<"u"&&(s.x=s.x*e+g*n+(d?0:o)),typeof s.y<"u"&&(s.y=p*t+s.y*i+(d?0:r)),typeof s.x1<"u"&&(s.x1=s.x1*e+s.y1*n+(d?0:o)),typeof s.y1<"u"&&(s.y1=c*t+s.y1*i+(d?0:r)),typeof s.x2<"u"&&(s.x2=s.x2*e+s.y2*n+(d?0:o)),typeof s.y2<"u"&&(s.y2=f*t+s.y2*i+(d?0:r));function y(_){return _*_}const T=e*i-t*n;if(typeof s.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(T===0)delete s.rX,delete s.rY,delete s.xRot,delete s.lArcFlag,delete s.sweepFlag,s.type=E.LINE_TO;else{const _=s.xRot*Math.PI/180,m=Math.sin(_),w=Math.cos(_),b=1/y(s.rX),C=1/y(s.rY),k=y(w)*b+y(m)*C,V=2*m*w*(b-C),H=y(m)*b+y(w)*C,q=k*i*i-V*t*i+H*t*t,Z=V*(e*i+t*n)-2*(k*n*i+H*e*t),le=k*n*n-V*e*n+H*e*e,A=(Math.atan2(Z,q-le)+Math.PI)%Math.PI/2,O=Math.sin(A),M=Math.cos(A);s.rX=Math.abs(T)/Math.sqrt(q*y(M)+Z*O*M+le*y(O)),s.rY=Math.abs(T)/Math.sqrt(q*y(O)-Z*O*M+le*y(M)),s.xRot=A*180/Math.PI}return typeof s.sweepFlag<"u"&&0>T&&(s.sweepFlag=+!s.sweepFlag),s})}function Wi(e,t=0,n=0){Ee(e,t,n);const i=Math.sin(e),o=Math.cos(e);return Ie(o,i,-i,o,t-t*o+n*i,n-t*i-n*o)}function Ki(e,t=0){return Ee(e,t),Ie(1,0,0,1,e,t)}function Ji(e,t=e){return Ee(e,t),Ie(e,0,0,t,0,0)}function $i(e){return Ee(e),Ie(1,0,Math.tan(e),1,0,0)}function eo(e){return Ee(e),Ie(1,Math.tan(e),0,1,0,0)}function to(e=0){return Ee(e),Ie(-1,0,0,1,e,0)}function no(e=0){return Ee(e),Ie(1,0,0,-1,0,e)}function io(){return Te((e,t,n)=>E.ARC===e.type?Gi(e,e.relative?0:t,e.relative?0:n):e)}function oo(){return Te((e,t,n)=>(e.relative&&(t=0,n=0),E.ARC===e.type&&Mt(e,t,n),e))}function yn(){return e=>({...e})}function ro(){const e=yn(),t=hn(),n=pn(),i=gn(),o=Te((r,s,a)=>{const l=i(n(t(e(r))));function u(f){f>o.maxX&&(o.maxX=f),f<o.minX&&(o.minX=f)}function c(f){f>o.maxY&&(o.maxY=f),f<o.minY&&(o.minY=f)}if(l.type&E.DRAWING_COMMANDS&&(u(s),c(a)),l.type&E.HORIZ_LINE_TO&&u(l.x),l.type&E.VERT_LINE_TO&&c(l.y),l.type&E.LINE_TO&&(u(l.x),c(l.y)),l.type&E.CURVE_TO){u(l.x),c(l.y);const f=cn(s,l.x1,l.x2,l.x);for(const p of f)0<p&&1>p&&u(dn(s,l.x1,l.x2,l.x,p));const d=cn(a,l.y1,l.y2,l.y);for(const p of d)0<p&&1>p&&c(dn(a,l.y1,l.y2,l.y,p))}if(l.type&E.ARC){u(l.x),c(l.y),Mt(l,s,a);const f=l.xRot/180*Math.PI,d=Math.cos(f)*l.rX,p=Math.sin(f)*l.rX,g=-Math.sin(f)*l.rY,y=Math.cos(f)*l.rY,[T,_]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],m=([C,k])=>{const H=Math.atan2(k,C)*180/Math.PI;return H<T?H+360:H},w=an(g,-d,0).map(m);for(const C of w)C>T&&C<_&&u(fn(l.cX,d,g,C));const b=an(y,-p,0).map(m);for(const C of b)C>T&&C<_&&c(fn(l.cY,p,y,C))}return r});return o.minX=1/0,o.maxX=-1/0,o.minY=1/0,o.maxY=-1/0,o}const ee={ROUND:ji,TO_ABS:hn,TO_REL:Qi,NORMALIZE_HVZ:qi,NORMALIZE_ST:gn,QT_TO_C:pn,INFO:Te,SANITIZE:Zi,MATRIX:Ie,ROTATE:Wi,TRANSLATE:Ki,SCALE:Ji,SKEW_X:$i,SKEW_Y:eo,X_AXIS_SYMMETRY:to,Y_AXIS_SYMMETRY:no,A_TO_C:io,ANNOTATE_ARCS:oo,CLONE:yn,CALCULATE_BOUNDS:ro,REVERSE_PATH:zi};class _n{round(t){return this.transform(ee.ROUND(t))}toAbs(){return this.transform(ee.TO_ABS())}toRel(){return this.transform(ee.TO_REL())}normalizeHVZ(t,n,i){return this.transform(ee.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(ee.NORMALIZE_ST())}qtToC(){return this.transform(ee.QT_TO_C())}aToC(){return this.transform(ee.A_TO_C())}sanitize(t){return this.transform(ee.SANITIZE(t))}translate(t,n){return this.transform(ee.TRANSLATE(t,n))}scale(t,n){return this.transform(ee.SCALE(t,n))}rotate(t,n,i){return this.transform(ee.ROTATE(t,n,i))}matrix(t,n,i,o,r,s){return this.transform(ee.MATRIX(t,n,i,o,r,s))}skewX(t){return this.transform(ee.SKEW_X(t))}skewY(t){return this.transform(ee.SKEW_Y(t))}xSymmetry(t){return this.transform(ee.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(ee.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(ee.ANNOTATE_ARCS())}}const so=e=>e===" "||e===" "||e==="\r"||e===`
|
|
2
|
-
`,mn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class lo extends _n{constructor(){super();W(this,"curNumber","");W(this,"curCommandType",-1);W(this,"curCommandRelative",!1);W(this,"canParseCommandOrComma",!0);W(this,"curNumberHasExp",!1);W(this,"curNumberHasExpDigits",!1);W(this,"curNumberHasDecimal",!1);W(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=r=>{i.push(r),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let r=0;r<n.length;r++){const s=n[r],a=this.curCommandType===E.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),l=mn(s)&&(this.curNumber==="0"&&s==="0"||a);if(mn(s)&&!l){this.curNumber+=s,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(s==="e"||s==="E"){this.curNumber+=s,this.curNumberHasExp=!0;continue}if((s==="-"||s==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=s;continue}if(s==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!a){this.curNumber+=s,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const u=Number(this.curNumber);if(isNaN(u))throw new SyntaxError(`Invalid number ending at ${r}`);if(this.curCommandType===E.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>u)throw new SyntaxError(`Expected positive number, got "${u}" at index "${r}"`)}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 "${r}"`)}this.curArgs.push(u),this.curArgs.length===ao[this.curCommandType]&&(E.HORIZ_LINE_TO===this.curCommandType?o({type:E.HORIZ_LINE_TO,relative:this.curCommandRelative,x:u}):E.VERT_LINE_TO===this.curCommandType?o({type:E.VERT_LINE_TO,relative:this.curCommandRelative,y:u}):this.curCommandType===E.MOVE_TO||this.curCommandType===E.LINE_TO||this.curCommandType===E.SMOOTH_QUAD_TO?(o({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),E.MOVE_TO===this.curCommandType&&(this.curCommandType=E.LINE_TO)):this.curCommandType===E.CURVE_TO?o({type:E.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===E.SMOOTH_CURVE_TO?o({type:E.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===E.QUAD_TO?o({type:E.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===E.ARC&&o({type:E.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(!so(s)){if(s===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(s==="+"||s==="-"||s==="."){this.curNumber=s,this.curNumberHasDecimal=s===".";continue}if(l){this.curNumber=s,this.curNumberHasDecimal=!1;continue}if(this.curArgs.length!==0)throw new SyntaxError(`Unterminated command at index ${r}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${s}" at index ${r}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,s==="z"||s==="Z"){i.push({type:E.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(s==="h"||s==="H")this.curCommandType=E.HORIZ_LINE_TO,this.curCommandRelative=s==="h";else if(s==="v"||s==="V")this.curCommandType=E.VERT_LINE_TO,this.curCommandRelative=s==="v";else if(s==="m"||s==="M")this.curCommandType=E.MOVE_TO,this.curCommandRelative=s==="m";else if(s==="l"||s==="L")this.curCommandType=E.LINE_TO,this.curCommandRelative=s==="l";else if(s==="c"||s==="C")this.curCommandType=E.CURVE_TO,this.curCommandRelative=s==="c";else if(s==="s"||s==="S")this.curCommandType=E.SMOOTH_CURVE_TO,this.curCommandRelative=s==="s";else if(s==="q"||s==="Q")this.curCommandType=E.QUAD_TO,this.curCommandRelative=s==="q";else if(s==="t"||s==="T")this.curCommandType=E.SMOOTH_QUAD_TO,this.curCommandRelative=s==="t";else if(s==="a"||s==="A")this.curCommandType=E.ARC,this.curCommandRelative=s==="a";else throw new SyntaxError(`Unexpected character "${s}" at index ${r}.`)}}return i}transform(n){return Object.create(this,{parse:{value(o,r=[]){const s=Object.getPrototypeOf(this).parse.call(this,o);for(const a of s){const l=n(a);Array.isArray(l)?r.push(...l):r.push(l)}return r}}})}}const G=class G extends _n{constructor(n){super();W(this,"commands");typeof n=="string"?this.commands=G.parse(n):this.commands=n}encode(){return G.encode(this.commands)}getBounds(){const n=ee.CALCULATE_BOUNDS();return this.transform(n),n}transform(n){const i=[];for(const o of this.commands){const r=n(o);Array.isArray(r)?i.push(...r):i.push(r)}return this.commands=i,this}reverse(n=!0){return this.commands=ee.REVERSE_PATH(this.commands,n),this}static encode(n){return xi(n)}static parse(n){const i=new lo,o=[];return i.parse(n,o),i.finish(o),o}};W(G,"CLOSE_PATH",1),W(G,"MOVE_TO",2),W(G,"HORIZ_LINE_TO",4),W(G,"VERT_LINE_TO",8),W(G,"LINE_TO",16),W(G,"CURVE_TO",32),W(G,"SMOOTH_CURVE_TO",64),W(G,"QUAD_TO",128),W(G,"SMOOTH_QUAD_TO",256),W(G,"ARC",512),W(G,"LINE_COMMANDS",G.LINE_TO|G.HORIZ_LINE_TO|G.VERT_LINE_TO),W(G,"DRAWING_COMMANDS",G.HORIZ_LINE_TO|G.VERT_LINE_TO|G.LINE_TO|G.CURVE_TO|G.SMOOTH_CURVE_TO|G.QUAD_TO|G.SMOOTH_QUAD_TO|G.ARC);let E=G;const ao={[E.MOVE_TO]:2,[E.LINE_TO]:2,[E.HORIZ_LINE_TO]:1,[E.VERT_LINE_TO]:1,[E.CLOSE_PATH]:0,[E.QUAD_TO]:4,[E.SMOOTH_QUAD_TO]:2,[E.CURVE_TO]:6,[E.SMOOTH_CURVE_TO]:4,[E.ARC]:7},uo=e=>{const t=new E(e).toAbs().commands,n=[];let i=[],o=null;for(const r of t)switch(r.type){case E.MOVE_TO:i.length>0&&(n.push({points:i}),i=[]),o=[r.x,r.y],i.push(o);break;case E.LINE_TO:i.push([r.x,r.y]);break;case E.HORIZ_LINE_TO:const s=i[i.length-1][1];i.push([r.x,s]);break;case E.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,r.y]);break;case E.CURVE_TO:case E.SMOOTH_CURVE_TO:case E.QUAD_TO:case E.SMOOTH_QUAD_TO:case E.ARC:i.push([r.x,r.y]);break}if(i.length>2&&n.push({points:i}),n.length>0){const r=Ae(n[0].points);return{rings:n,bounds:r}}},fo=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(r=>r.split(",").map(parseFloat));return{type:z.POLYGON,geometry:{points:o,bounds:Ae(o)}}},co=e=>{const t=ln(e),n=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),o=parseFloat(t.getAttribute("rx")),r=parseFloat(t.getAttribute("ry")),s={minX:n-o,minY:i-r,maxX:n+o,maxY:i+r};return{type:z.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:r,bounds:s}}},ho=e=>{const t=ln(e),o=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(l=>l.getAttribute("d")||"").map(l=>uo(l)).filter(Boolean),r=o.reduce((l,u)=>[...l,...u.rings[0].points],[]),s=Ae(r);return o.length===1&&o[0].rings.length===1?{type:z.POLYGON,geometry:{points:r,bounds:s}}:{type:z.MULTIPOLYGLON,geometry:{polygons:o,bounds:s}}},wn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return fo(t);if(t.includes("<path "))return ho(t);if(t.includes("<ellipse "))return co(t);throw"Unsupported SVG shape: "+t},go=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Re(n)}" />`).join("")}</g>`,En=e=>{let t;if(e.type===z.POLYGON){const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`}else if(e.type===z.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===z.MULTIPOLYGLON){const n=e.geometry;t=`<svg>${go(n)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},ne=[];for(let e=0;e<256;++e)ne.push((e+256).toString(16).slice(1));function po(e,t=0){return(ne[e[t+0]]+ne[e[t+1]]+ne[e[t+2]]+ne[e[t+3]]+"-"+ne[e[t+4]]+ne[e[t+5]]+"-"+ne[e[t+6]]+ne[e[t+7]]+"-"+ne[e[t+8]]+ne[e[t+9]]+"-"+ne[e[t+10]]+ne[e[t+11]]+ne[e[t+12]]+ne[e[t+13]]+ne[e[t+14]]+ne[e[t+15]]).toLowerCase()}let Nt;const yo=new Uint8Array(16);function _o(){if(!Nt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Nt=crypto.getRandomValues.bind(crypto)}return Nt(yo)}const Tn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function An(e,t,n){var o;if(Tn.randomUUID&&!e)return Tn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??_o();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,po(i)}var bn=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(bn.call(e,n)&&++i&&!bn.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 Ct(){}function mo(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const xe=[];function Rt(e,t=Ct){let n;const i=new Set;function o(a){if(mo(e,a)&&(e=a,n)){const l=!xe.length;for(const u of i)u[1](),xe.push(u,e);if(l){for(let u=0;u<xe.length;u+=2)xe[u][0](xe[u+1]);xe.length=0}}}function r(a){o(a(e))}function s(a,l=Ct){const u=[a,l];return i.add(u),i.size===1&&(n=t(o,r)||Ct),a(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:r,subscribe:s}}const wo=e=>{const{subscribe:t,set:n}=Rt();let i;return t(o=>i=o),e.observe(({changes:o})=>{if(i){(o.deleted||[]).some(s=>s.id===i)&&n(void 0);const r=(o.updated||[]).find(({oldValue:s})=>s.id===i);r&&n(r.newValue.id)}}),{get current(){return i},subscribe:t,set:n}};var Lt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Lt||{});const dt={selected:[]},Eo=(e,t,n)=>{const{subscribe:i,set:o}=Rt(dt);let r=t,s=dt;i(g=>s=g);const a=()=>{ve(s,dt)||o(dt)},l=()=>{var g;return((g=s.selected)==null?void 0:g.length)===0},u=g=>{if(l())return!1;const y=typeof g=="string"?g:g.id;return s.selected.some(T=>T.id===y)},c=(g,y)=>{let T;if(Array.isArray(g)){if(T=g.map(m=>e.getAnnotation(m)).filter(Boolean),T.length<g.length){console.warn("Invalid selection: "+g.filter(m=>!T.some(w=>w.id===m)));return}}else{const m=e.getAnnotation(g);if(!m){console.warn("Invalid selection: "+g);return}T=[m]}const _=T.reduce((m,w)=>{const b=On(w,r,n);return b==="EDIT"?[...m,{id:w.id,editable:!0}]:b==="SELECT"?[...m,{id:w.id}]:m},[]);o({selected:_,event:y})},f=(g,y)=>{const T=Array.isArray(g)?g:[g],_=T.map(m=>e.getAnnotation(m)).filter(m=>!!m);o({selected:_.map(m=>{const w=y===void 0?On(m,r,n)==="EDIT":y;return{id:m.id,editable:w}})}),_.length!==T.length&&console.warn("Invalid selection",g)},d=g=>{if(l())return!1;const{selected:y}=s;y.some(({id:T})=>g.includes(T))&&o({selected:y.filter(({id:T})=>!g.includes(T))})},p=g=>{r=g,f(s.selected.map(({id:y})=>y))};return e.observe(({changes:g})=>d((g.deleted||[]).map(y=>y.id))),{get event(){return s?s.event:null},get selected(){return s?[...s.selected]:null},get userSelectAction(){return r},clear:a,isEmpty:l,isSelected:u,setSelected:f,setUserSelectAction:p,subscribe:i,userSelect:c}},On=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},ie=[];for(let e=0;e<256;++e)ie.push((e+256).toString(16).slice(1));function To(e,t=0){return(ie[e[t+0]]+ie[e[t+1]]+ie[e[t+2]]+ie[e[t+3]]+"-"+ie[e[t+4]]+ie[e[t+5]]+"-"+ie[e[t+6]]+ie[e[t+7]]+"-"+ie[e[t+8]]+ie[e[t+9]]+"-"+ie[e[t+10]]+ie[e[t+11]]+ie[e[t+12]]+ie[e[t+13]]+ie[e[t+14]]+ie[e[t+15]]).toLowerCase()}let It;const Ao=new Uint8Array(16);function bo(){if(!It){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");It=crypto.getRandomValues.bind(crypto)}return It(Ao)}const Oo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Mn={randomUUID:Oo};function Sn(e,t,n){var i;if(Mn.randomUUID&&!e)return Mn.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??bo();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,To(o)}const vt=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)}},Mo=(e,t,n,i)=>({id:Sn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),So=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},No=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},Co=(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})),Ro=(e,t)=>!ve(e.target,t.target),Nn=(e,t)=>{const n=So(e,t),i=No(e,t),o=Co(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:Ro(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var Q=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(Q||{});const Lo=(e,t)=>{var n,i;const{changes:o,origin:r}=t;if(!(e.options.origin?e.options.origin===r:r!=="SILENT"))return!1;if(e.options.ignore){const{ignore:s}=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(c=>a(c.bodiesCreated)||a(c.bodiesDeleted)||a(c.bodiesUpdated)),u=(i=o.updated)==null?void 0:i.some(c=>c.targetUpdated);if(s==="BODY_ONLY"&&l&&!u||s==="TARGET_ONLY"&&u&&!l)return!1}}if(e.options.annotations){const s=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=>s.has(a))}else return!0},Io=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),i=new Set((e.updated||[]).map(({newValue:f})=>f.id)),o=new Set((t.created||[]).map(f=>f.id)),r=new Set((t.deleted||[]).map(f=>f.id)),s=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),a=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||i.has(f.id)).map(({oldValue:f})=>f.id)),l=[...(e.created||[]).filter(f=>!r.has(f.id)).map(f=>s.has(f.id)?t.updated.find(({oldValue:d})=>d.id===f.id).newValue:f),...t.created||[]],u=[...(e.deleted||[]).filter(f=>!o.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],c=[...(e.updated||[]).filter(({newValue:f})=>!r.has(f.id)).map(f=>{const{oldValue:d,newValue:p}=f;if(s.has(p.id)){const g=t.updated.find(y=>y.oldValue.id===p.id).newValue;return Nn(d,g)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!a.has(f.id))];return{created:l,deleted:u,updated:c}},ht=e=>{const t=e.id===void 0?Sn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},vo=e=>e.id!==void 0,Uo=()=>{const e=new Map,t=new Map,n=[],i=(A,O={})=>{n.push({onChange:A,options:O})},o=A=>{const O=n.findIndex(M=>M.onChange==A);O>-1&&n.splice(O,1)},r=(A,O)=>{const M={origin:A,changes:{created:O.created||[],updated:O.updated||[],deleted:O.deleted||[]},state:[...e.values()]};n.forEach(R=>{Lo(R,M)&&R.onChange(M)})},s=(A,O=Q.LOCAL)=>{if(A.id&&e.get(A.id))throw Error(`Cannot add annotation ${A.id} - exists already`);{const M=ht(A);e.set(M.id,M),M.bodies.forEach(R=>t.set(R.id,M.id)),r(O,{created:[M]})}},a=(A,O)=>{const M=ht(typeof A=="string"?O:A),R=typeof A=="string"?A:A.id,x=R&&e.get(R);if(x){const P=Nn(x,M);return R===M.id?e.set(R,M):(e.delete(R),e.set(M.id,M)),x.bodies.forEach(X=>t.delete(X.id)),M.bodies.forEach(X=>t.set(X.id,M.id)),P}else console.warn(`Cannot update annotation ${R} - does not exist`)},l=(A,O=Q.LOCAL,M=Q.LOCAL)=>{const R=vo(O)?M:O,x=a(A,O);x&&r(R,{updated:[x]})},u=(A,O=Q.LOCAL)=>{e.get(A.id)?l(A,O):s(A,O)},c=(A,O=Q.LOCAL)=>{const M=A.reduce((R,x)=>{const P=a(x);return P?[...R,P]:R},[]);M.length>0&&r(O,{updated:M})},f=(A,O=Q.LOCAL)=>{const M=A.map(ht),{toAdd:R,toUpdate:x}=M.reduce((X,oe)=>e.get(oe.id)?{...X,toUpdate:[...X.toUpdate,oe]}:{...X,toAdd:[...X.toAdd,oe]},{toAdd:[],toUpdate:[]}),P=x.map(X=>a(X,O)).filter(Boolean);R.forEach(X=>{e.set(X.id,X),X.bodies.forEach(oe=>t.set(oe.id,X.id))}),r(O,{created:R,updated:P})},d=(A,O=Q.LOCAL)=>{const M=e.get(A.annotation);if(M){const R={...M,bodies:[...M.bodies,A]};e.set(M.id,R),t.set(A.id,R.id),r(O,{updated:[{oldValue:M,newValue:R,bodiesCreated:[A]}]})}else console.warn(`Attempt to add body to missing annotation: ${A.annotation}`)},p=()=>[...e.values()],g=(A=Q.LOCAL)=>{const O=[...e.values()];e.clear(),t.clear(),r(A,{deleted:O})},y=(A,O=!0,M=Q.LOCAL)=>{const R=A.map(ht);if(O){const x=[...e.values()];e.clear(),t.clear(),R.forEach(P=>{e.set(P.id,P),P.bodies.forEach(X=>t.set(X.id,P.id))}),r(M,{created:R,deleted:x})}else{const x=A.reduce((P,X)=>{const oe=X.id&&e.get(X.id);return oe?[...P,oe]:P},[]);if(x.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${x.map(P=>P.id).join(", ")}`);R.forEach(P=>{e.set(P.id,P),P.bodies.forEach(X=>t.set(X.id,P.id))}),r(M,{created:R})}},T=A=>{const O=typeof A=="string"?A:A.id,M=e.get(O);if(M)return e.delete(O),M.bodies.forEach(R=>t.delete(R.id)),M;console.warn(`Attempt to delete missing annotation: ${O}`)},_=(A,O=Q.LOCAL)=>{const M=T(A);M&&r(O,{deleted:[M]})},m=(A,O=Q.LOCAL)=>{const M=A.reduce((R,x)=>{const P=T(x);return P?[...R,P]:R},[]);M.length>0&&r(O,{deleted:M})},w=A=>{const O=e.get(A.annotation);if(O){const M=O.bodies.find(R=>R.id===A.id);if(M){t.delete(M.id);const R={...O,bodies:O.bodies.filter(x=>x.id!==A.id)};return e.set(O.id,R),{oldValue:O,newValue:R,bodiesDeleted:[M]}}else console.warn(`Attempt to delete missing body ${A.id} from annotation ${A.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${A.annotation}`)},b=(A,O=Q.LOCAL)=>{const M=w(A);M&&r(O,{updated:[M]})},C=(A,O=Q.LOCAL)=>{const M=A.map(R=>w(R)).filter(Boolean);M.length>0&&r(O,{updated:M})},k=A=>{const O=e.get(A);return O?{...O}:void 0},V=A=>{const O=t.get(A);if(O){const M=k(O).bodies.find(R=>R.id===A);if(M)return M;console.error(`Store integrity error: body ${A} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${A}`)},H=(A,O)=>{if(A.annotation!==O.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const M=e.get(A.annotation);if(M){const R=M.bodies.find(P=>P.id===A.id),x={...M,bodies:M.bodies.map(P=>P.id===R.id?O:P)};return e.set(M.id,x),R.id!==O.id&&(t.delete(R.id),t.set(O.id,x.id)),{oldValue:M,newValue:x,bodiesUpdated:[{oldBody:R,newBody:O}]}}else console.warn(`Attempt to add body to missing annotation ${A.annotation}`)},q=(A,O,M=Q.LOCAL)=>{const R=H(A,O);R&&r(M,{updated:[R]})},Z=(A,O=Q.LOCAL)=>{const M=A.map(R=>H({id:R.id,annotation:R.annotation},R)).filter(Boolean);r(O,{updated:M})},le=A=>{const O=e.get(A.annotation);if(O){const M={...O,target:{...O.target,...A}};return e.set(O.id,M),{oldValue:O,newValue:M,targetUpdated:{oldTarget:O.target,newTarget:A}}}else console.warn(`Attempt to update target on missing annotation: ${A.annotation}`)};return{addAnnotation:s,addBody:d,all:p,bulkAddAnnotations:y,bulkDeleteAnnotations:m,bulkDeleteBodies:C,bulkUpdateAnnotations:c,bulkUpdateBodies:Z,bulkUpdateTargets:(A,O=Q.LOCAL)=>{const M=A.map(R=>le(R)).filter(Boolean);M.length>0&&r(O,{updated:M})},bulkUpsertAnnotations:f,clear:g,deleteAnnotation:_,deleteBody:b,getAnnotation:k,getBody:V,observe:i,unobserve:o,updateAnnotation:l,updateBody:q,updateTarget:(A,O=Q.LOCAL)=>{const M=le(A);M&&r(O,{updated:[M]})},upsertAnnotation:u}},Do=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let Po=()=>({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 ko=250,Vo=(e,t)=>{const n=Po(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,r=!1,s=0;const a=g=>{if(!r){const{changes:y}=g,T=performance.now();if(T-s>ko)i.splice(o+1),i.push(y),o=i.length-1;else{const _=i.length-1;i[_]=Io(i[_],y)}s=T}r=!1};e.observe(a,{origin:Q.LOCAL});const l=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g),u=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),c=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({oldValue:y})=>y)),f=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({newValue:y})=>y)),d=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),p=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,y)=>n.on(g,y),redo:()=>{if(i.length-1>o){r=!0;const{created:g,updated:y,deleted:T}=i[o+1];u(g),f(y),p(T),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){r=!0;const{created:g,updated:y,deleted:T}=i[o];l(g),c(y),d(T),n.emit("undo",i[o]),o-=1}}}},Ho=()=>{const{subscribe:e,set:t}=Rt([]);return{subscribe:e,set:t}},Bo=(e,t,n,i)=>{const{hover:o,selection:r,store:s,viewport:a}=e,l=new Map;let u=[],c,f;const d=(_,m)=>{l.has(_)?l.get(_).push(m):l.set(_,[m])},p=(_,m)=>{const w=l.get(_);if(w){const b=w.indexOf(m);b!==-1&&w.splice(b,1)}},g=(_,m,w)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(n){const C=Array.isArray(m)?m.map(V=>n.serialize(V)):n.serialize(m),k=w?w instanceof PointerEvent?w:n.serialize(w):void 0;b(C,k)}else b(m,w)})},1)},y=()=>{const{selected:_}=r,m=(_||[]).map(({id:w})=>s.getAnnotation(w));m.forEach(w=>{const b=u.find(C=>C.id===w.id);(!b||!ve(b,w))&&g("updateAnnotation",w,b)}),u=u.map(w=>m.find(({id:C})=>C===w.id)||w)};r.subscribe(({selected:_})=>{if(!(u.length===0&&_.length===0)){if(u.length===0&&_.length>0)u=_.map(({id:m})=>s.getAnnotation(m));else if(u.length>0&&_.length===0)u.forEach(m=>{const w=s.getAnnotation(m.id);w&&!ve(w,m)&&g("updateAnnotation",w,m)}),u=[];else{const m=new Set(u.map(b=>b.id)),w=new Set(_.map(({id:b})=>b));u.filter(b=>!w.has(b.id)).forEach(b=>{const C=s.getAnnotation(b.id);C&&!ve(C,b)&&g("updateAnnotation",C,b)}),u=[...u.filter(b=>w.has(b.id)),..._.filter(({id:b})=>!m.has(b)).map(({id:b})=>s.getAnnotation(b))]}g("selectionChanged",u)}}),o.subscribe(_=>{!c&&_?g("mouseEnterAnnotation",s.getAnnotation(_)):c&&!_?g("mouseLeaveAnnotation",s.getAnnotation(c)):c&&_&&(g("mouseLeaveAnnotation",s.getAnnotation(c)),g("mouseEnterAnnotation",s.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>g("viewportIntersect",_.map(m=>s.getAnnotation(m)))),s.observe(_=>{i&&(f&&clearTimeout(f),f=setTimeout(y,1e3));const{created:m,deleted:w}=_.changes;(m||[]).forEach(b=>g("createAnnotation",b)),(w||[]).forEach(b=>g("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:C})=>{const k=u.find(V=>V.id===b.id)||b;u=u.map(V=>V.id===b.id?C:V),g("updateAnnotation",C,k)})},{origin:Q.LOCAL}),s.observe(_=>{if(u){const m=new Set(u.map(b=>b.id)),w=(_.changes.updated||[]).filter(({newValue:b})=>m.has(b.id)).map(({newValue:b})=>b);w.length>0&&(u=u.map(b=>w.find(k=>k.id===b.id)||b))}},{origin:Q.REMOTE});const T=_=>m=>{const{updated:w}=m;_?(w||[]).forEach(b=>g("updateAnnotation",b.oldValue,b.newValue)):(w||[]).forEach(b=>g("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",T(!0)),t.on("redo",T(!1)),{on:d,off:p,emit:g}},Yo=e=>t=>t.reduce((n,i)=>{const{parsed:o,error:r}=e.parse(i);return r?{parsed:n.parsed,failed:[...n.failed,i]}:o?{parsed:[...n.parsed,o],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Xo=(e,t,n)=>{const{store:i,selection:o}=e,r=_=>{if(n){const{parsed:m,error:w}=n.parse(_);m?i.addAnnotation(m,Q.REMOTE):console.error(w)}else i.addAnnotation(vt(_),Q.REMOTE)},s=()=>o.clear(),a=()=>i.clear(),l=_=>{const m=i.getAnnotation(_);return n&&m?n.serialize(m):m},u=()=>n?i.all().map(n.serialize):i.all(),c=()=>{var _;const m=(((_=o.selected)==null?void 0:_.map(w=>w.id))||[]).map(w=>i.getAnnotation(w)).filter(Boolean);return n?m.map(n.serialize):m},f=(_,m=!0)=>fetch(_).then(w=>w.json()).then(w=>(p(w,m),w)),d=_=>{if(typeof _=="string"){const m=i.getAnnotation(_);if(i.deleteAnnotation(_),m)return n?n.serialize(m):m}else{const m=n?n.parse(_).parsed:_;if(m)return i.deleteAnnotation(m),_}},p=(_,m=!0)=>{if(n){const w=n.parseAll||Yo(n),{parsed:b,failed:C}=w(_);C.length>0&&console.warn(`Discarded ${C.length} invalid annotations`,C),i.bulkAddAnnotations(b,m,Q.REMOTE)}else i.bulkAddAnnotations(_.map(vt),m,Q.REMOTE)},g=(_,m)=>{_?o.setSelected(_,m):o.clear()},y=_=>{o.clear(),o.setUserSelectAction(_)},T=_=>{if(n){const m=n.parse(_).parsed,w=n.serialize(i.getAnnotation(m.id));return i.updateAnnotation(m),w}else{const m=i.getAnnotation(_.id);return i.updateAnnotation(vt(_)),m}};return{addAnnotation:r,cancelSelected:s,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:u,getHistory:t.getHistory,getSelected:c,loadAnnotations:f,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:g,setUserSelectAction:y,undo:t.undo,updateAnnotation:T}},xo=(e,t,n)=>typeof t=="function"?t(e,n):t,Fo=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,i)=>{const o=typeof e=="function"?e(n,i):e,r=typeof t=="function"?t(n,i):t;return{...o||{},...r||{}}},Go="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let zo=e=>crypto.getRandomValues(new Uint8Array(e)),jo=(e,t,n)=>{let i=(2<<Math.log2(e.length-1))-1,o=-~(1.6*i*t/e.length);return(r=t)=>{let s="";for(;;){let a=n(o),l=o|0;for(;l--;)if(s+=e[a[l]&i]||"",s.length>=r)return s}}},Qo=(e,t=21)=>jo(e,t|0,zo),qo=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Go[n[e]&63];return t};const Zo=()=>({isGuest:!0,id:Qo("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Wo=e=>{const t=JSON.stringify(e);let n=0;for(let i=0,o=t.length;i<o;i++){let r=t.charCodeAt(i);n=(n<<5)-n+r,n|=0}return`${n}`},Cn=e=>e?typeof e=="object"?{...e}:e:void 0,Ko=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:i,type:o,purpose:r,value:s,created:a,modified:l,creator:u,...c}=n;return{id:i||`temp-${Wo(n)}`,annotation:t,type:o,purpose:r,value:s,creator:Cn(u),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),Jo=e=>e.map(t=>{var n;const{annotation:i,created:o,updated:r,...s}=t,a={...s,created:o==null?void 0:o.toISOString(),modified:r==null?void 0:r.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a}),$o=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],er=()=>{const e=[...$o];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};qo();const tr=(e,t={strict:!0,invertY:!1})=>({parse:o=>Rn(o,t),serialize:o=>Ln(o,e,t)}),Rn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||An(),{creator:i,created:o,modified:r,body:s,...a}=e,l=Ko(s||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,c=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,f=typeof c=="string"||(c==null?void 0:c.type)==="FragmentSelector"?nn(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?wn(c):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return f||!t.strict?{parsed:{...a,id:n,bodies:l,target:{created:o?new Date(o):void 0,creator:Cn(i),updated:r?new Date(r):void 0,...typeof d=="string"?{}:d,annotation:n,selector:f||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},Ln=(e,t,n={strict:!0,invertY:!1})=>{const{selector:i,creator:o,created:r,updated:s,updatedBy:a,...l}=e.target;let u;try{u=i.type==z.RECTANGLE?on(i.geometry):En(i)}catch(f){if(n.strict)throw f;u=i}const c={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Jo(e.bodies),created:r==null?void 0:r.toISOString(),creator:o,modified:s==null?void 0:s.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:u}};return delete c.bodies,"annotation"in c.target&&delete c.target.annotation,c};function In(e,t,n){const i=e.slice();return i[10]=t[n],i[12]=n,i}function vn(e){let t,n;return t=new ke({props:{x:e[10][0],y:e[10][1],scale:e[3]}}),t.$on("pointerdown",function(){J(e[9](`HANDLE-${e[12]}`))&&e[9](`HANDLE-${e[12]}`).apply(this,arguments)}),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,o){e=i;const r={};o&16&&(r.x=e[10][0]),o&16&&(r.y=e[10][1]),o&8&&(r.scale=e[3]),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function nr(e){let t,n,i,o,r,s,a,l,u,c,f,d=ce(e[4].points),p=[];for(let y=0;y<d.length;y+=1)p[y]=vn(In(e,d,y));const g=y=>D(p[y],1,1,()=>{p[y]=null});return{c(){t=B("polygon"),o=we(),r=B("polygon"),a=we();for(let y=0;y<p.length;y+=1)p[y].c();l=pe(),h(t,"class","a9s-outer"),h(t,"style",n=e[1]?"display:none;":void 0),h(t,"points",i=e[4].points.map(Un).join(" ")),h(r,"class","a9s-inner a9s-shape-handle"),h(r,"style",e[1]),h(r,"points",s=e[4].points.map(Dn).join(" "))},m(y,T){U(y,t,T),U(y,o,T),U(y,r,T),U(y,a,T);for(let _=0;_<p.length;_+=1)p[_]&&p[_].m(y,T);U(y,l,T),u=!0,c||(f=[K(t,"pointerdown",function(){J(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),K(r,"pointerdown",function(){J(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)})],c=!0)},p(y,T){if(e=y,(!u||T&2&&n!==(n=e[1]?"display:none;":void 0))&&h(t,"style",n),(!u||T&16&&i!==(i=e[4].points.map(Un).join(" ")))&&h(t,"points",i),(!u||T&2)&&h(r,"style",e[1]),(!u||T&16&&s!==(s=e[4].points.map(Dn).join(" ")))&&h(r,"points",s),T&536){d=ce(e[4].points);let _;for(_=0;_<d.length;_+=1){const m=In(e,d,_);p[_]?(p[_].p(m,T),I(p[_],1)):(p[_]=vn(m),p[_].c(),I(p[_],1),p[_].m(l.parentNode,l))}for(ue(),_=d.length;_<p.length;_+=1)g(_);fe()}},i(y){if(!u){for(let T=0;T<d.length;T+=1)I(p[T]);u=!0}},o(y){p=p.filter(Boolean);for(let T=0;T<p.length;T+=1)D(p[T]);u=!1},d(y){y&&(v(t),v(o),v(r),v(a),v(l)),Ue(p,y),c=!1,me(f)}}}function ir(e){let t,n;return t=new pt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[nr,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:e}}}),t.$on("change",e[6]),t.$on("grab",e[7]),t.$on("release",e[8]),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,[o]){const r={};o&1&&(r.shape=i[0]),o&4&&(r.transform=i[2]),o&8730&&(r.$$scope={dirty:o,ctx:i}),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}const Un=e=>e.join(","),Dn=e=>e.join(",");function or(e,t,n){let i,{shape:o}=t,{computedStyle:r}=t,{transform:s}=t,{viewportScale:a=1}=t;const l=(d,p,g)=>{let y;const T=d.geometry;p==="SHAPE"?y=T.points.map(([m,w])=>[m+g[0],w+g[1]]):y=T.points.map(([m,w],b)=>p===`HANDLE-${b}`?[m+g[0],w+g[1]]:[m,w]);const _=Ae(y);return{...d,geometry:{points:y,bounds:_}}};function u(d){_e.call(this,e,d)}function c(d){_e.call(this,e,d)}function f(d){_e.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,o=d.shape),"computedStyle"in d&&n(1,r=d.computedStyle),"transform"in d&&n(2,s=d.transform),"viewportScale"in d&&n(3,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,i=o.geometry)},[o,r,s,a,i,l,u,c,f]}class Pn extends he{constructor(t){super(),de(this,t,or,ir,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const gt=(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))},Fe=[];function rr(e,t=Y){let n;const i=new Set;function o(a){if(te(e,a)&&(e=a,n)){const l=!Fe.length;for(const u of i)u[1](),Fe.push(u,e);if(l){for(let u=0;u<Fe.length;u+=2)Fe[u][0](Fe[u+1]);Fe.length=0}}}function r(a){o(a(e))}function s(a,l=Y){const u=[a,l];return i.add(u),i.size===1&&(n=t(o,r)||Y),a(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:r,subscribe:s}}const sr=(e,t)=>{const{naturalWidth:n,naturalHeight:i}=e;if(!n&&!i){const{width:o,height:r}=e;t.setAttribute("viewBox",`0 0 ${o} ${r}`),e.addEventListener("load",s=>{const a=s.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${i}`)},kn=(e,t)=>{sr(e,t);const{subscribe:n,set:i}=rr(1);let o;return window.ResizeObserver&&(o=new ResizeObserver(()=>{const s=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,u=Math.max(s.width/a,s.height/l);i(u)}),o.observe(t.parentElement)),{destroy:()=>{o&&o.disconnect()},subscribe:n}},Vn=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function lr(e){let t,n,i,o,r,s;return{c(){t=B("rect"),h(t,"class",n=rt(`a9s-handle ${e[8].class||""}`.trim())+" svelte-1sgkh33"),h(t,"x",i=e[0]-e[5]/2),h(t,"y",o=e[1]-e[5]/2),h(t,"width",e[5]),h(t,"height",e[5])},m(a,l){U(a,t,l),r||(s=K(t,"pointerdown",e[11]),r=!0)},p(a,l){l&256&&n!==(n=rt(`a9s-handle ${a[8].class||""}`.trim())+" svelte-1sgkh33")&&h(t,"class",n),l&33&&i!==(i=a[0]-a[5]/2)&&h(t,"x",i),l&34&&o!==(o=a[1]-a[5]/2)&&h(t,"y",o),l&32&&h(t,"width",a[5]),l&32&&h(t,"height",a[5])},d(a){a&&v(t),r=!1,s()}}}function ar(e){let t,n,i,o,r,s,a,l,u;return{c(){t=B("g"),n=B("circle"),o=B("rect"),h(n,"cx",e[0]),h(n,"cy",e[1]),h(n,"r",i=e[3]/e[2]),h(n,"class","a9s-touch-halo svelte-1sgkh33"),Ce(n,"touched",e[4]),h(o,"class",r=rt(`a9s-handle ${e[8].class||""}`.trim())+" svelte-1sgkh33"),h(o,"x",s=e[0]-e[5]/2),h(o,"y",a=e[1]-e[5]/2),h(o,"width",e[5]),h(o,"height",e[5]),h(t,"class","a9s-touch-handle")},m(c,f){U(c,t,f),ye(t,n),ye(t,o),l||(u=[K(n,"pointerdown",e[10]),K(n,"pointerdown",e[6]),K(n,"pointerup",e[7]),K(o,"pointerdown",e[9]),K(o,"pointerdown",e[6]),K(o,"pointerup",e[7])],l=!0)},p(c,f){f&1&&h(n,"cx",c[0]),f&2&&h(n,"cy",c[1]),f&12&&i!==(i=c[3]/c[2])&&h(n,"r",i),f&16&&Ce(n,"touched",c[4]),f&256&&r!==(r=rt(`a9s-handle ${c[8].class||""}`.trim())+" svelte-1sgkh33")&&h(o,"class",r),f&33&&s!==(s=c[0]-c[5]/2)&&h(o,"x",s),f&34&&a!==(a=c[1]-c[5]/2)&&h(o,"y",a),f&32&&h(o,"width",c[5]),f&32&&h(o,"height",c[5])},d(c){c&&v(t),l=!1,me(u)}}}function ur(e){let t;function n(r,s){return Vn?ar:lr}let o=n()(e);return{c(){o.c(),t=pe()},m(r,s){o.m(r,s),U(r,t,s)},p(r,[s]){o.p(r,s)},i:Y,o:Y,d(r){r&&v(t),o.d(r)}}}function fr(e,t,n){let i,{x:o}=t,{y:r}=t,{scale:s}=t,{radius:a=30}=t,l=!1;const u=g=>{g.pointerType==="touch"&&n(4,l=!0)},c=()=>n(4,l=!1);function f(g){_e.call(this,e,g)}function d(g){_e.call(this,e,g)}function p(g){_e.call(this,e,g)}return e.$$set=g=>{n(8,t=Ne(Ne({},t),Qt(g))),"x"in g&&n(0,o=g.x),"y"in g&&n(1,r=g.y),"scale"in g&&n(2,s=g.scale),"radius"in g&&n(3,a=g.radius)},e.$$.update=()=>{e.$$.dirty&4&&n(5,i=10/s)},t=Qt(t),[o,r,s,a,l,i,u,c,t,f,d,p]}class ke extends he{constructor(t){super(),de(this,t,fr,ur,te,{x:0,y:1,scale:2,radius:3})}}function cr(e){let t,n,i,o,r,s,a,l,u,c,f,d,p,g,y,T,_,m,w,b,C,k,V,H,q,Z,le,A,O,M,R,x,P,X,oe,be,nt,Oe,it,Me,F,ot,mt;return X=new ke({props:{class:"a9s-corner-handle-topleft",x:e[4].x,y:e[4].y,scale:e[3]}}),X.$on("pointerdown",function(){J(e[9]("TOP_LEFT"))&&e[9]("TOP_LEFT").apply(this,arguments)}),be=new ke({props:{class:"a9s-corner-handle-topright",x:e[4].x+e[4].w,y:e[4].y,scale:e[3]}}),be.$on("pointerdown",function(){J(e[9]("TOP_RIGHT"))&&e[9]("TOP_RIGHT").apply(this,arguments)}),Oe=new ke({props:{class:"a9s-corner-handle-bottomright",x:e[4].x+e[4].w,y:e[4].y+e[4].h,scale:e[3]}}),Oe.$on("pointerdown",function(){J(e[9]("BOTTOM_RIGHT"))&&e[9]("BOTTOM_RIGHT").apply(this,arguments)}),Me=new ke({props:{class:"a9s-corner-handle-bottomleft",x:e[4].x,y:e[4].y+e[4].h,scale:e[3]}}),Me.$on("pointerdown",function(){J(e[9]("BOTTOM_LEFT"))&&e[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=B("rect"),a=we(),l=B("rect"),p=we(),g=B("rect"),m=we(),w=B("rect"),V=we(),H=B("rect"),A=we(),O=B("rect"),P=we(),ae(X.$$.fragment),oe=we(),ae(be.$$.fragment),nt=we(),ae(Oe.$$.fragment),it=we(),ae(Me.$$.fragment),h(t,"class","a9s-outer"),h(t,"style",n=e[1]?"display:none;":void 0),h(t,"x",i=e[4].x),h(t,"y",o=e[4].y),h(t,"width",r=e[4].w),h(t,"height",s=e[4].h),h(l,"class","a9s-inner a9s-shape-handle"),h(l,"style",e[1]),h(l,"x",u=e[4].x),h(l,"y",c=e[4].y),h(l,"width",f=e[4].w),h(l,"height",d=e[4].h),h(g,"class","a9s-edge-handle a9s-edge-handle-top"),h(g,"x",y=e[4].x),h(g,"y",T=e[4].y),h(g,"height",1),h(g,"width",_=e[4].w),h(w,"class","a9s-edge-handle a9s-edge-handle-right"),h(w,"x",b=e[4].x+e[4].w),h(w,"y",C=e[4].y),h(w,"height",k=e[4].h),h(w,"width",1),h(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),h(H,"x",q=e[4].x),h(H,"y",Z=e[4].y+e[4].h),h(H,"height",1),h(H,"width",le=e[4].w),h(O,"class","a9s-edge-handle a9s-edge-handle-left"),h(O,"x",M=e[4].x),h(O,"y",R=e[4].y),h(O,"height",x=e[4].h),h(O,"width",1)},m(S,N){U(S,t,N),U(S,a,N),U(S,l,N),U(S,p,N),U(S,g,N),U(S,m,N),U(S,w,N),U(S,V,N),U(S,H,N),U(S,A,N),U(S,O,N),U(S,P,N),re(X,S,N),U(S,oe,N),re(be,S,N),U(S,nt,N),re(Oe,S,N),U(S,it,N),re(Me,S,N),F=!0,ot||(mt=[K(t,"pointerdown",function(){J(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),K(l,"pointerdown",function(){J(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),K(g,"pointerdown",function(){J(e[9]("TOP"))&&e[9]("TOP").apply(this,arguments)}),K(w,"pointerdown",function(){J(e[9]("RIGHT"))&&e[9]("RIGHT").apply(this,arguments)}),K(H,"pointerdown",function(){J(e[9]("BOTTOM"))&&e[9]("BOTTOM").apply(this,arguments)}),K(O,"pointerdown",function(){J(e[9]("LEFT"))&&e[9]("LEFT").apply(this,arguments)})],ot=!0)},p(S,N){e=S,(!F||N&2&&n!==(n=e[1]?"display:none;":void 0))&&h(t,"style",n),(!F||N&16&&i!==(i=e[4].x))&&h(t,"x",i),(!F||N&16&&o!==(o=e[4].y))&&h(t,"y",o),(!F||N&16&&r!==(r=e[4].w))&&h(t,"width",r),(!F||N&16&&s!==(s=e[4].h))&&h(t,"height",s),(!F||N&2)&&h(l,"style",e[1]),(!F||N&16&&u!==(u=e[4].x))&&h(l,"x",u),(!F||N&16&&c!==(c=e[4].y))&&h(l,"y",c),(!F||N&16&&f!==(f=e[4].w))&&h(l,"width",f),(!F||N&16&&d!==(d=e[4].h))&&h(l,"height",d),(!F||N&16&&y!==(y=e[4].x))&&h(g,"x",y),(!F||N&16&&T!==(T=e[4].y))&&h(g,"y",T),(!F||N&16&&_!==(_=e[4].w))&&h(g,"width",_),(!F||N&16&&b!==(b=e[4].x+e[4].w))&&h(w,"x",b),(!F||N&16&&C!==(C=e[4].y))&&h(w,"y",C),(!F||N&16&&k!==(k=e[4].h))&&h(w,"height",k),(!F||N&16&&q!==(q=e[4].x))&&h(H,"x",q),(!F||N&16&&Z!==(Z=e[4].y+e[4].h))&&h(H,"y",Z),(!F||N&16&&le!==(le=e[4].w))&&h(H,"width",le),(!F||N&16&&M!==(M=e[4].x))&&h(O,"x",M),(!F||N&16&&R!==(R=e[4].y))&&h(O,"y",R),(!F||N&16&&x!==(x=e[4].h))&&h(O,"height",x);const j={};N&16&&(j.x=e[4].x),N&16&&(j.y=e[4].y),N&8&&(j.scale=e[3]),X.$set(j);const ge={};N&16&&(ge.x=e[4].x+e[4].w),N&16&&(ge.y=e[4].y),N&8&&(ge.scale=e[3]),be.$set(ge);const Se={};N&16&&(Se.x=e[4].x+e[4].w),N&16&&(Se.y=e[4].y+e[4].h),N&8&&(Se.scale=e[3]),Oe.$set(Se);const Ve={};N&16&&(Ve.x=e[4].x),N&16&&(Ve.y=e[4].y+e[4].h),N&8&&(Ve.scale=e[3]),Me.$set(Ve)},i(S){F||(I(X.$$.fragment,S),I(be.$$.fragment,S),I(Oe.$$.fragment,S),I(Me.$$.fragment,S),F=!0)},o(S){D(X.$$.fragment,S),D(be.$$.fragment,S),D(Oe.$$.fragment,S),D(Me.$$.fragment,S),F=!1},d(S){S&&(v(t),v(a),v(l),v(p),v(g),v(m),v(w),v(V),v(H),v(A),v(O),v(P),v(oe),v(nt),v(it)),se(X,S),se(be,S),se(Oe,S),se(Me,S),ot=!1,me(mt)}}}function dr(e){let t,n;return t=new pt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[cr,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:e}}}),t.$on("grab",e[6]),t.$on("change",e[7]),t.$on("release",e[8]),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,[o]){const r={};o&1&&(r.shape=i[0]),o&4&&(r.transform=i[2]),o&1562&&(r.$$scope={dirty:o,ctx:i}),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function hr(e,t,n){let i,{shape:o}=t,{computedStyle:r}=t,{transform:s}=t,{viewportScale:a=1}=t;const l=(d,p,g)=>{const y=d.geometry.bounds;let[T,_]=[y.minX,y.minY],[m,w]=[y.maxX,y.maxY];const[b,C]=g;if(p==="SHAPE")T+=b,m+=b,_+=C,w+=C;else{switch(p){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{_+=C;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{w+=C;break}}switch(p){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{T+=b;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{m+=b;break}}}const k=Math.min(T,m),V=Math.min(_,w),H=Math.abs(m-T),q=Math.abs(w-_);return{...d,geometry:{x:k,y:V,w:H,h:q,bounds:{minX:k,minY:V,maxX:k+H,maxY:V+q}}}};function u(d){_e.call(this,e,d)}function c(d){_e.call(this,e,d)}function f(d){_e.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,o=d.shape),"computedStyle"in d&&n(1,r=d.computedStyle),"transform"in d&&n(2,s=d.transform),"viewportScale"in d&&n(3,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,i=o.geometry)},[o,r,s,a,i,l,u,c,f]}class Hn extends he{constructor(t){super(),de(this,t,hr,dr,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}function Bn(e,t,n){const i=e.slice();return i[10]=t[n],i[12]=n,i}function Yn(e,t,n){const i=e.slice();return i[13]=t[n],i[15]=n,i}function Xn(e,t,n){const i=e.slice();return i[16]=t[n],i[18]=n,i}function xn(e){let t,n;return t=new ke({props:{x:e[16][0],y:e[16][1],scale:e[3]}}),t.$on("pointerdown",function(){J(e[9](`HANDLE-${e[12]}-${e[15]}-${e[18]}`))&&e[9](`HANDLE-${e[12]}-${e[15]}-${e[18]}`).apply(this,arguments)}),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,o){e=i;const r={};o&16&&(r.x=e[16][0]),o&16&&(r.y=e[16][1]),o&8&&(r.scale=e[3]),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function Fn(e){let t,n,i=ce(e[13].points),o=[];for(let s=0;s<i.length;s+=1)o[s]=xn(Xn(e,i,s));const r=s=>D(o[s],1,1,()=>{o[s]=null});return{c(){for(let s=0;s<o.length;s+=1)o[s].c();t=pe()},m(s,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(s,a);U(s,t,a),n=!0},p(s,a){if(a&536){i=ce(s[13].points);let l;for(l=0;l<i.length;l+=1){const u=Xn(s,i,l);o[l]?(o[l].p(u,a),I(o[l],1)):(o[l]=xn(u),o[l].c(),I(o[l],1),o[l].m(t.parentNode,t))}for(ue(),l=i.length;l<o.length;l+=1)r(l);fe()}},i(s){if(!n){for(let a=0;a<i.length;a+=1)I(o[a]);n=!0}},o(s){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)D(o[a]);n=!1},d(s){s&&v(t),Ue(o,s)}}}function Gn(e){let t,n,i,o,r,s,a,l,u,c=ce(e[10].rings),f=[];for(let p=0;p<c.length;p+=1)f[p]=Fn(Yn(e,c,p));const d=p=>D(f[p],1,1,()=>{f[p]=null});return{c(){t=B("g"),n=B("path"),r=B("path");for(let p=0;p<f.length;p+=1)f[p].c();h(n,"class","a9s-outer"),h(n,"style",i=e[1]?"display:none;":void 0),h(n,"fill-rule","evenodd"),h(n,"d",o=Re(e[10])),h(r,"class","a9s-inner"),h(r,"style",e[1]),h(r,"fill-rule","evenodd"),h(r,"d",s=Re(e[10]))},m(p,g){U(p,t,g),ye(t,n),ye(t,r);for(let y=0;y<f.length;y+=1)f[y]&&f[y].m(t,null);a=!0,l||(u=[K(n,"pointerdown",function(){J(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),K(r,"pointerdown",function(){J(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)})],l=!0)},p(p,g){if(e=p,(!a||g&2&&i!==(i=e[1]?"display:none;":void 0))&&h(n,"style",i),(!a||g&16&&o!==(o=Re(e[10])))&&h(n,"d",o),(!a||g&2)&&h(r,"style",e[1]),(!a||g&16&&s!==(s=Re(e[10])))&&h(r,"d",s),g&536){c=ce(e[10].rings);let y;for(y=0;y<c.length;y+=1){const T=Yn(e,c,y);f[y]?(f[y].p(T,g),I(f[y],1)):(f[y]=Fn(T),f[y].c(),I(f[y],1),f[y].m(t,null))}for(ue(),y=c.length;y<f.length;y+=1)d(y);fe()}},i(p){if(!a){for(let g=0;g<c.length;g+=1)I(f[g]);a=!0}},o(p){f=f.filter(Boolean);for(let g=0;g<f.length;g+=1)D(f[g]);a=!1},d(p){p&&v(t),Ue(f,p),l=!1,me(u)}}}function gr(e){let t,n,i=ce(e[4].polygons),o=[];for(let s=0;s<i.length;s+=1)o[s]=Gn(Bn(e,i,s));const r=s=>D(o[s],1,1,()=>{o[s]=null});return{c(){for(let s=0;s<o.length;s+=1)o[s].c();t=pe()},m(s,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(s,a);U(s,t,a),n=!0},p(s,a){if(a&538){i=ce(s[4].polygons);let l;for(l=0;l<i.length;l+=1){const u=Bn(s,i,l);o[l]?(o[l].p(u,a),I(o[l],1)):(o[l]=Gn(u),o[l].c(),I(o[l],1),o[l].m(t.parentNode,t))}for(ue(),l=i.length;l<o.length;l+=1)r(l);fe()}},i(s){if(!n){for(let a=0;a<i.length;a+=1)I(o[a]);n=!0}},o(s){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)D(o[a]);n=!1},d(s){s&&v(t),Ue(o,s)}}}function pr(e){let t,n;return t=new pt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[gr,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:e}}}),t.$on("change",e[6]),t.$on("grab",e[7]),t.$on("release",e[8]),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,[o]){const r={};o&1&&(r.shape=i[0]),o&4&&(r.transform=i[2]),o&524826&&(r.$$scope={dirty:o,ctx:i}),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function yr(e,t,n){let i,{shape:o}=t,{computedStyle:r}=t,{transform:s}=t,{viewportScale:a=1}=t;const l=(d,p,g)=>{const y=d.geometry.polygons;let T;if(p==="SHAPE")T=y.map(_=>{const m=_.rings.map((b,C)=>({points:b.points.map((V,H)=>[V[0]+g[0],V[1]+g[1]])})),w=Ae(m[0].points);return{rings:m,bounds:w}});else{const[_,m,w,b]=p.split("-").map(C=>parseInt(C));T=y.map((C,k)=>{if(k===m){const V=C.rings.map((q,Z)=>Z===w?{points:q.points.map((A,O)=>O===b?[A[0]+g[0],A[1]+g[1]]:A)}:q),H=Ae(V[0].points);return{rings:V,bounds:H}}else return C})}return{...d,geometry:{polygons:T,bounds:en(T)}}};function u(d){_e.call(this,e,d)}function c(d){_e.call(this,e,d)}function f(d){_e.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,o=d.shape),"computedStyle"in d&&n(1,r=d.computedStyle),"transform"in d&&n(2,s=d.transform),"viewportScale"in d&&n(3,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,i=o.geometry)},[o,r,s,a,i,l,u,c,f]}class _r extends he{constructor(t){super(),de(this,t,yr,pr,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const zn=new Map([[z.RECTANGLE,Hn],[z.POLYGON,Pn],[z.MULTIPOLYGLON,_r]]),jn=e=>zn.get(e.type),Qn=(e,t)=>zn.set(e,t),mr=e=>({}),qn=e=>({grab:e[0]});function wr(e){let t,n,i,o;const r=e[7].default,s=Si(r,e,e[6],qn);return{c(){t=B("g"),s&&s.c(),h(t,"class","a9s-annotation selected")},m(a,l){U(a,t,l),s&&s.m(t,null),n=!0,i||(o=[K(t,"pointerup",e[2]),K(t,"pointermove",e[1])],i=!0)},p(a,[l]){s&&s.p&&(!n||l&64)&&Ci(s,r,a,a[6],n?Ni(r,a[6],l,mr):Ri(a[6]),qn)},i(a){n||(I(s,a),n=!0)},o(a){D(s,a),n=!1},d(a){a&&v(t),s&&s.d(a),i=!1,me(o)}}}function Er(e,t,n){let{$$slots:i={},$$scope:o}=t;const r=He();let{shape:s}=t,{editor:a}=t,{transform:l}=t,u,c,f;const d=y=>T=>{u=y,c=l.elementToImage(T.offsetX,T.offsetY),f=s,T.target.setPointerCapture(T.pointerId),r("grab",T)},p=y=>{if(u){const[T,_]=l.elementToImage(y.offsetX,y.offsetY),m=[T-c[0],_-c[1]];n(3,s=a(f,u,m)),r("change",s)}},g=y=>{y.target.releasePointerCapture(y.pointerId),u=void 0,f=s,r("release",y)};return e.$$set=y=>{"shape"in y&&n(3,s=y.shape),"editor"in y&&n(4,a=y.editor),"transform"in y&&n(5,l=y.transform),"$$scope"in y&&n(6,o=y.$$scope)},[d,p,g,s,a,l,o,i]}class pt extends he{constructor(t){super(),de(this,t,Er,wr,te,{shape:3,editor:4,transform:5})}}const Je=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:i,fillOpacity:o,stroke:r,strokeWidth:s,strokeOpacity:a}=n;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${o||"0.25"};`),r&&(l+=`stroke:${r};`,l+=`stroke-width:${s||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}};function Tr(e,t,n){let i;const o=He();let{annotation:r}=t,{editor:s}=t,{style:a}=t,{target:l}=t,{transform:u}=t,{viewportScale:c}=t,f;return qe(()=>(n(6,f=new s({target:l,props:{shape:r.target.selector,computedStyle:i,transform:u,viewportScale:c}})),f.$on("change",d=>{f.$$set({shape:d.detail}),o("change",d.detail)}),f.$on("grab",d=>o("grab",d.detail)),f.$on("release",d=>o("release",d.detail)),()=>{f.$destroy()})),e.$$set=d=>{"annotation"in d&&n(0,r=d.annotation),"editor"in d&&n(1,s=d.editor),"style"in d&&n(2,a=d.style),"target"in d&&n(3,l=d.target),"transform"in d&&n(4,u=d.transform),"viewportScale"in d&&n(5,c=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,i=Je(r,a)),e.$$.dirty&65&&r&&(f==null||f.$set({shape:r.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:u}),e.$$.dirty&96&&f&&f.$set({viewportScale:c}),e.$$.dirty&192&&f&&i&&f.$set({computedStyle:i})},[r,s,a,l,u,c,f,i]}class Zn extends he{constructor(t){super(),de(this,t,Tr,null,te,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Ar(e,t,n){const i=He();let{drawingMode:o}=t,{target:r}=t,{tool:s}=t,{transform:a}=t,{viewportScale:l}=t,u;return qe(()=>{const c=r.closest("svg"),f=[],d=(p,g,y)=>{c==null||c.addEventListener(p,g,y),f.push(()=>c==null?void 0:c.removeEventListener(p,g,y))};return n(5,u=new s({target:r,props:{addEventListener:d,drawingMode:o,transform:a,viewportScale:l}})),u.$on("create",p=>i("create",p.detail)),()=>{f.forEach(p=>p()),u.$destroy()}}),e.$$set=c=>{"drawingMode"in c&&n(0,o=c.drawingMode),"target"in c&&n(1,r=c.target),"tool"in c&&n(2,s=c.tool),"transform"in c&&n(3,a=c.transform),"viewportScale"in c&&n(4,l=c.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:a}),e.$$.dirty&48&&u&&u.$set({viewportScale:l})},[o,r,s,a,l,u]}class Wn extends he{constructor(t){super(),de(this,t,Ar,null,te,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Kn(e){let t,n;return{c(){t=B("rect"),n=B("rect"),h(t,"class","a9s-outer"),h(t,"x",e[1]),h(t,"y",e[2]),h(t,"width",e[3]),h(t,"height",e[4]),h(n,"class","a9s-inner"),h(n,"x",e[1]),h(n,"y",e[2]),h(n,"width",e[3]),h(n,"height",e[4])},m(i,o){U(i,t,o),U(i,n,o)},p(i,o){o&2&&h(t,"x",i[1]),o&4&&h(t,"y",i[2]),o&8&&h(t,"width",i[3]),o&16&&h(t,"height",i[4]),o&2&&h(n,"x",i[1]),o&4&&h(n,"y",i[2]),o&8&&h(n,"width",i[3]),o&16&&h(n,"height",i[4])},d(i){i&&(v(t),v(n))}}}function br(e){let t,n=e[0]&&Kn(e);return{c(){t=B("g"),n&&n.c(),h(t,"class","a9s-annotation a9s-rubberband")},m(i,o){U(i,t,o),n&&n.m(t,null)},p(i,[o]){i[0]?n?n.p(i,o):(n=Kn(i),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:Y,o:Y,d(i){i&&v(t),n&&n.d()}}}function Or(e,t,n){const i=He();let{addEventListener:o}=t,{drawingMode:r}=t,{transform:s}=t,a,l,u,c,f,d,p;const g=m=>{const w=m;a=performance.now(),r==="drag"&&(n(0,l=s.elementToImage(w.offsetX,w.offsetY)),u=l,n(1,c=l[0]),n(2,f=l[1]),n(3,d=1),n(4,p=1))},y=m=>{const w=m;l&&(u=s.elementToImage(w.offsetX,w.offsetY),n(1,c=Math.min(u[0],l[0])),n(2,f=Math.min(u[1],l[1])),n(3,d=Math.abs(u[0]-l[0])),n(4,p=Math.abs(u[1]-l[1])))},T=m=>{const w=m,b=performance.now()-a;if(r==="click"){if(b>300)return;l?_():(n(0,l=s.elementToImage(w.offsetX,w.offsetY)),u=l,n(1,c=l[0]),n(2,f=l[1]),n(3,d=1),n(4,p=1))}else l&&(b>300||d*p>100?(w.stopPropagation(),_()):(n(0,l=void 0),u=void 0))},_=()=>{if(d*p>15){const m={type:z.RECTANGLE,geometry:{bounds:{minX:c,minY:f,maxX:c+d,maxY:f+p},x:c,y:f,w:d,h:p}};i("create",m)}n(0,l=void 0),u=void 0};return qe(()=>{o("pointerdown",g),o("pointermove",y),o("pointerup",T,!0)}),e.$$set=m=>{"addEventListener"in m&&n(5,o=m.addEventListener),"drawingMode"in m&&n(6,r=m.drawingMode),"transform"in m&&n(7,s=m.transform)},[l,c,f,d,p,o,r,s]}class Jn extends he{constructor(t){super(),de(this,t,Or,br,te,{addEventListener:5,drawingMode:6,transform:7})}}function Ut(e){const t=e.slice(),n=(t[2]?t[0]:[...t[0],t[1]]).map(i=>i.join(",")).join(" ");return t[16]=n,t}function $n(e){let t,n,i,o,r,s=e[2]&&ei(e);return{c(){t=B("polygon"),i=B("polygon"),s&&s.c(),r=pe(),h(t,"class","a9s-outer"),h(t,"points",n=e[16]),h(i,"class","a9s-inner"),h(i,"points",o=e[16])},m(a,l){U(a,t,l),U(a,i,l),s&&s.m(a,l),U(a,r,l)},p(a,l){l&7&&n!==(n=a[16])&&h(t,"points",n),l&7&&o!==(o=a[16])&&h(i,"points",o),a[2]?s?s.p(a,l):(s=ei(a),s.c(),s.m(r.parentNode,r)):s&&(s.d(1),s=null)},d(a){a&&(v(t),v(i),v(r)),s&&s.d(a)}}}function ei(e){let t,n,i;return{c(){t=B("rect"),h(t,"class","a9s-handle"),h(t,"x",n=e[0][0][0]-e[3]/2),h(t,"y",i=e[0][0][1]-e[3]/2),h(t,"height",e[3]),h(t,"width",e[3])},m(o,r){U(o,t,r)},p(o,r){r&9&&n!==(n=o[0][0][0]-o[3]/2)&&h(t,"x",n),r&9&&i!==(i=o[0][0][1]-o[3]/2)&&h(t,"y",i),r&8&&h(t,"height",o[3]),r&8&&h(t,"width",o[3])},d(o){o&&v(t)}}}function Mr(e){let t,n=e[1]&&$n(Ut(e));return{c(){t=B("g"),n&&n.c(),h(t,"class","a9s-annotation a9s-rubberband")},m(i,o){U(i,t,o),n&&n.m(t,null)},p(i,[o]){i[1]?n?n.p(Ut(i),o):(n=$n(Ut(i)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:Y,o:Y,d(i){i&&v(t),n&&n.d()}}}const Sr=20,Nr=1500;function Cr(e,t,n){let i;const o=He();let{addEventListener:r}=t,{drawingMode:s}=t,{transform:a}=t,{viewportScale:l=1}=t,u,c=[],f,d,p=!1;const g=w=>{const b=w,{timeStamp:C,offsetX:k,offsetY:V}=b;if(u={timeStamp:C,offsetX:k,offsetY:V},s==="drag"&&c.length===0){const H=a.elementToImage(b.offsetX,b.offsetY);c.push(H),n(1,f=H)}},y=w=>{const b=w;if(d&&clearTimeout(d),c.length>0){if(n(1,f=a.elementToImage(b.offsetX,b.offsetY)),c.length>2){const C=gt(f,c[0])*l;n(2,p=C<Sr)}b.pointerType==="touch"&&(d=setTimeout(()=>{_()},Nr))}},T=w=>{const b=w;if(d&&clearTimeout(d),s==="click"){const C=b.timeStamp-u.timeStamp,k=gt([u.offsetX,u.offsetY],[b.offsetX,b.offsetY]);if(C>300||k>15)return;if(p)m();else if(c.length===0){const V=a.elementToImage(b.offsetX,b.offsetY);c.push(V),n(1,f=V)}else c.push(f)}else{if(c.length===1&>(c[0],f)<=4){n(0,c=[]),n(1,f=void 0);return}b.stopImmediatePropagation(),p?m():c.push(f)}},_=()=>{if(!f)return;const w=c.slice(0,-1);if(w.length<3)return;const b={type:z.POLYGON,geometry:{bounds:Ae(c),points:w}};at(b)>4&&(n(0,c=[]),n(1,f=void 0),o("create",b))},m=()=>{const w={type:z.POLYGON,geometry:{bounds:Ae(c),points:[...c]}};n(0,c=[]),n(1,f=void 0),o("create",w)};return qe(()=>{r("pointerdown",g,!0),r("pointermove",y),r("pointerup",T,!0),r("dblclick",_,!0)}),e.$$set=w=>{"addEventListener"in w&&n(4,r=w.addEventListener),"drawingMode"in w&&n(5,s=w.drawingMode),"transform"in w&&n(6,a=w.transform),"viewportScale"in w&&n(7,l=w.viewportScale)},e.$$.update=()=>{e.$$.dirty&128&&n(3,i=10/l)},[c,f,p,i,r,s,a,l]}class Rr extends he{constructor(t){super(),de(this,t,Cr,Mr,te,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const Dt=new Map([["rectangle",{tool:Jn}],["polygon",{tool:Rr}]]),Pt=()=>[...Dt.keys()],kt=e=>Dt.get(e),ti=(e,t,n={})=>Dt.set(e,{tool:t,opts:n});function Lr(e){let t,n,i,o,r;return{c(){t=B("g"),n=B("ellipse"),o=B("ellipse"),h(n,"class","a9s-outer"),h(n,"style",i=e[1]?"display:none;":void 0),h(n,"cx",e[2]),h(n,"cy",e[3]),h(n,"rx",e[4]),h(n,"ry",e[5]),h(o,"class","a9s-inner"),h(o,"style",e[1]),h(o,"cx",e[2]),h(o,"cy",e[3]),h(o,"rx",e[4]),h(o,"ry",e[5]),h(t,"class","a9s-annotation"),h(t,"data-id",r=e[0].id)},m(s,a){U(s,t,a),ye(t,n),ye(t,o)},p(s,[a]){a&2&&i!==(i=s[1]?"display:none;":void 0)&&h(n,"style",i),a&2&&h(o,"style",s[1]),a&1&&r!==(r=s[0].id)&&h(t,"data-id",r)},i:Y,o:Y,d(s){s&&v(t)}}}function Ir(e,t,n){let i,{annotation:o}=t,{geom:r}=t,{style:s}=t;const{cx:a,cy:l,rx:u,ry:c}=r;return e.$$set=f=>{"annotation"in f&&n(0,o=f.annotation),"geom"in f&&n(6,r=f.geom),"style"in f&&n(7,s=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,i=Je(o,s))},[o,i,a,l,u,c,r,s]}class vr extends he{constructor(t){super(),de(this,t,Ir,Lr,te,{annotation:0,geom:6,style:7})}}function ni(e,t,n){const i=e.slice();return i[5]=t[n],i}function ii(e){let t,n,i;return{c(){t=B("path"),i=B("path"),h(t,"class","a9s-outer"),h(t,"style",n=e[1]?"display:none;":void 0),h(t,"fill-rule","evenodd"),h(t,"d",Re(e[5])),h(i,"class","a9s-inner"),h(i,"style",e[1]),h(i,"fill-rule","evenodd"),h(i,"d",Re(e[5]))},m(o,r){U(o,t,r),U(o,i,r)},p(o,r){r&2&&n!==(n=o[1]?"display:none;":void 0)&&h(t,"style",n),r&2&&h(i,"style",o[1])},d(o){o&&(v(t),v(i))}}}function Ur(e){let t,n,i=ce(e[2]),o=[];for(let r=0;r<i.length;r+=1)o[r]=ii(ni(e,i,r));return{c(){t=B("g");for(let r=0;r<o.length;r+=1)o[r].c();h(t,"class","a9s-annotation"),h(t,"data-id",n=e[0].id)},m(r,s){U(r,t,s);for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(t,null)},p(r,[s]){if(s&6){i=ce(r[2]);let a;for(a=0;a<i.length;a+=1){const l=ni(r,i,a);o[a]?o[a].p(l,s):(o[a]=ii(l),o[a].c(),o[a].m(t,null))}for(;a<o.length;a+=1)o[a].d(1);o.length=i.length}s&1&&n!==(n=r[0].id)&&h(t,"data-id",n)},i:Y,o:Y,d(r){r&&v(t),Ue(o,r)}}}function Dr(e,t,n){let i,{annotation:o}=t,{geom:r}=t,{style:s}=t;const{polygons:a}=r;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,r=l.geom),"style"in l&&n(4,s=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=Je(o,s))},[o,i,a,r,s]}class Pr extends he{constructor(t){super(),de(this,t,Dr,Ur,te,{annotation:0,geom:3,style:4})}}function kr(e){let t,n,i,o,r;return{c(){t=B("g"),n=B("polygon"),o=B("polygon"),h(n,"class","a9s-outer"),h(n,"style",i=e[1]?"display:none;":void 0),h(n,"points",e[2].map(Vr).join(" ")),h(o,"class","a9s-inner"),h(o,"style",e[1]),h(o,"points",e[2].map(Hr).join(" ")),h(t,"class","a9s-annotation"),h(t,"data-id",r=e[0].id)},m(s,a){U(s,t,a),ye(t,n),ye(t,o)},p(s,[a]){a&2&&i!==(i=s[1]?"display:none;":void 0)&&h(n,"style",i),a&2&&h(o,"style",s[1]),a&1&&r!==(r=s[0].id)&&h(t,"data-id",r)},i:Y,o:Y,d(s){s&&v(t)}}}const Vr=e=>e.join(","),Hr=e=>e.join(",");function Br(e,t,n){let i,{annotation:o}=t,{geom:r}=t,{style:s}=t;const{points:a}=r;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,r=l.geom),"style"in l&&n(4,s=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=Je(o,s))},[o,i,a,r,s]}class Yr extends he{constructor(t){super(),de(this,t,Br,kr,te,{annotation:0,geom:3,style:4})}}function Xr(e){let t,n,i,o,r;return{c(){t=B("g"),n=B("rect"),o=B("rect"),h(n,"class","a9s-outer"),h(n,"style",i=e[5]?"display:none;":void 0),h(n,"x",e[4]),h(n,"y",e[3]),h(n,"width",e[2]),h(n,"height",e[1]),h(o,"class","a9s-inner"),h(o,"style",e[5]),h(o,"x",e[4]),h(o,"y",e[3]),h(o,"width",e[2]),h(o,"height",e[1]),h(t,"class","a9s-annotation"),h(t,"data-id",r=e[0].id)},m(s,a){U(s,t,a),ye(t,n),ye(t,o)},p(s,[a]){a&32&&i!==(i=s[5]?"display:none;":void 0)&&h(n,"style",i),a&16&&h(n,"x",s[4]),a&8&&h(n,"y",s[3]),a&4&&h(n,"width",s[2]),a&2&&h(n,"height",s[1]),a&32&&h(o,"style",s[5]),a&16&&h(o,"x",s[4]),a&8&&h(o,"y",s[3]),a&4&&h(o,"width",s[2]),a&2&&h(o,"height",s[1]),a&1&&r!==(r=s[0].id)&&h(t,"data-id",r)},i:Y,o:Y,d(s){s&&v(t)}}}function xr(e,t,n){let i,o,r,s,a,{annotation:l}=t,{geom:u}=t,{style:c}=t;return e.$$set=f=>{"annotation"in f&&n(0,l=f.annotation),"geom"in f&&n(6,u=f.geom),"style"in f&&n(7,c=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,i=Je(l,c)),e.$$.dirty&64&&n(4,{x:o,y:r,w:s,h:a}=u,o,(n(3,r),n(6,u)),(n(2,s),n(6,u)),(n(1,a),n(6,u)))},[l,a,s,r,o,i,u,c]}class Fr extends he{constructor(t){super(),de(this,t,xr,Xr,te,{annotation:0,geom:6,style:7})}}const Gr={elementToImage:(e,t)=>[e,t]},oi=e=>({elementToImage:(t,n)=>{const i=e.getBoundingClientRect(),o=e.createSVGPoint();o.x=t+i.x,o.y=n+i.y;const{x:r,y:s}=o.matrixTransform(e.getScreenCTM().inverse());return[r,s]}}),zr=250,ri=(e,t)=>{const n=He();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<zr){const{x:l,y:u}=Vt(s,e),c=t.getAt(l,u);c?n("click",{originalEvent:s,annotation:c}):n("click",{originalEvent:s})}}}},Vt=(e,t)=>{const n=t.createSVGPoint(),i=t.getBoundingClientRect(),o=e.clientX-i.x,r=e.clientY-i.y,{left:s,top:a}=t.getBoundingClientRect();return n.x=o+s,n.y=r+a,n.matrixTransform(t.getScreenCTM().inverse())};function si(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 li(e,t,n){const i=e.slice();return i[43]=t[n],i}function Ht(e){const t=e.slice(),n=t[43].target.selector;return t[46]=n,t}function ai(e){let t=e[43],n,i,o=ui(e);return{c(){o.c(),n=pe()},m(r,s){o.m(r,s),U(r,n,s),i=!0},p(r,s){s[0]&65536&&te(t,t=r[43])?(ue(),D(o,1,1,Y),fe(),o=ui(r),o.c(),I(o,1),o.m(n.parentNode,n)):o.p(r,s)},i(r){i||(I(o),i=!0)},o(r){D(o),i=!1},d(r){r&&v(n),o.d(r)}}}function jr(e){let t,n;return t=new Pr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,o){const r={};o[0]&65536&&(r.annotation=i[43]),o[0]&65536&&(r.geom=i[46].geometry),o[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function Qr(e){let t,n;return t=new Yr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,o){const r={};o[0]&65536&&(r.annotation=i[43]),o[0]&65536&&(r.geom=i[46].geometry),o[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function qr(e){let t,n;return t=new Fr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,o){const r={};o[0]&65536&&(r.annotation=i[43]),o[0]&65536&&(r.geom=i[46].geometry),o[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function Zr(e){var i;let t,n;return t=new vr({props:{annotation:e[43],geom:(i=e[46])==null?void 0:i.geometry,style:e[1]}}),{c(){ae(t.$$.fragment)},m(o,r){re(t,o,r),n=!0},p(o,r){var a;const s={};r[0]&65536&&(s.annotation=o[43]),r[0]&65536&&(s.geom=(a=o[46])==null?void 0:a.geometry),r[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(I(t.$$.fragment,o),n=!0)},o(o){D(t.$$.fragment,o),n=!1},d(o){se(t,o)}}}function ui(e){let t,n,i,o;const r=[Zr,qr,Qr,jr],s=[];function a(l,u){var c,f,d,p;return((c=l[46])==null?void 0:c.type)===z.ELLIPSE?0:((f=l[46])==null?void 0:f.type)===z.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===z.POLYGON?2:((p=l[46])==null?void 0:p.type)===z.MULTIPOLYGLON?3:-1}return~(t=a(e))&&(n=s[t]=r[t](e)),{c(){n&&n.c(),i=pe()},m(l,u){~t&&s[t].m(l,u),U(l,i,u),o=!0},p(l,u){let c=t;t=a(l),t===c?~t&&s[t].p(l,u):(n&&(ue(),D(s[c],1,1,()=>{s[c]=null}),fe()),~t?(n=s[t],n?n.p(l,u):(n=s[t]=r[t](l),n.c()),I(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(I(n),o=!0)},o(l){D(n),o=!1},d(l){l&&v(i),~t&&s[t].d(l)}}}function fi(e){let t=We(e[43])&&!e[9](e[43]),n,i,o=t&&ai(Ht(e));return{c(){o&&o.c(),n=pe()},m(r,s){o&&o.m(r,s),U(r,n,s),i=!0},p(r,s){s[0]&66048&&(t=We(r[43])&&!r[9](r[43])),t?o?(o.p(Ht(r),s),s[0]&66048&&I(o,1)):(o=ai(Ht(r)),o.c(),I(o,1),o.m(n.parentNode,n)):o&&(ue(),D(o,1,1,()=>{o=null}),fe())},i(r){i||(I(o),i=!0)},o(r){D(o),i=!1},d(r){r&&v(n),o&&o.d(r)}}}function ci(e){let t,n,i,o;const r=[Kr,Wr],s=[];function a(l,u){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(e))&&(n=s[t]=r[t](e)),{c(){n&&n.c(),i=pe()},m(l,u){~t&&s[t].m(l,u),U(l,i,u),o=!0},p(l,u){let c=t;t=a(l),t===c?~t&&s[t].p(l,u):(n&&(ue(),D(s[c],1,1,()=>{s[c]=null}),fe()),~t?(n=s[t],n?n.p(l,u):(n=s[t]=r[t](l),n.c()),I(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(I(n),o=!0)},o(l){D(n),o=!1},d(l){l&&v(i),~t&&s[t].d(l)}}}function Wr(e){let t=`${e[2]}-${e[5]}`,n,i,o=di(e);return{c(){o.c(),n=pe()},m(r,s){o.m(r,s),U(r,n,s),i=!0},p(r,s){s[0]&36&&te(t,t=`${r[2]}-${r[5]}`)?(ue(),D(o,1,1,Y),fe(),o=di(r),o.c(),I(o,1),o.m(n.parentNode,n)):o.p(r,s)},i(r){i||(I(o),i=!0)},o(r){D(o),i=!1},d(r){r&&v(n),o.d(r)}}}function Kr(e){let t,n,i=ce(e[8]),o=[];for(let s=0;s<i.length;s+=1)o[s]=pi(si(e,i,s));const r=s=>D(o[s],1,1,()=>{o[s]=null});return{c(){for(let s=0;s<o.length;s+=1)o[s].c();t=pe()},m(s,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(s,a);U(s,t,a),n=!0},p(s,a){if(a[0]&21107010){i=ce(s[8]);let l;for(l=0;l<i.length;l+=1){const u=si(s,i,l);o[l]?(o[l].p(u,a),I(o[l],1)):(o[l]=pi(u),o[l].c(),I(o[l],1),o[l].m(t.parentNode,t))}for(ue(),l=i.length;l<o.length;l+=1)r(l);fe()}},i(s){if(!n){for(let a=0;a<i.length;a+=1)I(o[a]);n=!0}},o(s){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)D(o[a]);n=!1},d(s){s&&v(t),Ue(o,s)}}}function di(e){let t,n;return t=new Wn({props:{target:e[6],tool:e[14],drawingMode:e[13],transform:e[12],viewportScale:e[17]}}),t.$on("create",e[21]),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,o){const r={};o[0]&64&&(r.target=i[6]),o[0]&16384&&(r.tool=i[14]),o[0]&8192&&(r.drawingMode=i[13]),o[0]&4096&&(r.transform=i[12]),o[0]&131072&&(r.viewportScale=i[17]),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function hi(e){let t=e[39].id,n,i,o=gi(e);return{c(){o.c(),n=pe()},m(r,s){o.m(r,s),U(r,n,s),i=!0},p(r,s){s[0]&256&&te(t,t=r[39].id)?(ue(),D(o,1,1,Y),fe(),o=gi(r),o.c(),I(o,1),o.m(n.parentNode,n)):o.p(r,s)},i(r){i||(I(o),i=!0)},o(r){D(o),i=!1},d(r){r&&v(n),o.d(r)}}}function gi(e){let t,n;return t=new Zn({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(){J(e[22](e[39]))&&e[22](e[39]).apply(this,arguments)}),{c(){ae(t.$$.fragment)},m(i,o){re(t,i,o),n=!0},p(i,o){e=i;const r={};o[0]&64&&(r.target=e[6]),o[0]&256&&(r.editor=e[24](e[39].target.selector)),o[0]&256&&(r.annotation=e[39]),o[0]&2&&(r.style=e[1]),o[0]&4096&&(r.transform=e[12]),o[0]&131072&&(r.viewportScale=e[17]),t.$set(r)},i(i){n||(I(t.$$.fragment,i),n=!0)},o(i){D(t.$$.fragment,i),n=!1},d(i){se(t,i)}}}function pi(e){let t,n,i=e[40]&&hi(e);return{c(){i&&i.c(),t=pe()},m(o,r){i&&i.m(o,r),U(o,t,r),n=!0},p(o,r){o[40]?i?(i.p(o,r),r[0]&256&&I(i,1)):(i=hi(o),i.c(),I(i,1),i.m(t.parentNode,t)):i&&(ue(),D(i,1,1,()=>{i=null}),fe())},i(o){n||(I(i),n=!0)},o(o){D(i),n=!1},d(o){o&&v(t),i&&i.d(o)}}}function Jr(e){let t,n,i,o,r,s,a=ce(e[16].filter(e[34])),l=[];for(let f=0;f<a.length;f+=1)l[f]=fi(li(e,a,f));const u=f=>D(l[f],1,1,()=>{l[f]=null});let c=e[6]&&ci(e);return{c(){t=B("svg"),n=B("g");for(let f=0;f<l.length;f+=1)l[f].c();i=B("g"),c&&c.c(),h(i,"class","drawing"),h(t,"class","a9s-annotationlayer"),Ce(t,"drawing",e[14]),Ce(t,"hidden",!e[3]),Ce(t,"hover",e[15])},m(f,d){U(f,t,d),ye(t,n);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(n,null);ye(t,i),c&&c.m(i,null),e[35](i),e[36](t),o=!0,r||(s=[K(t,"pointerup",function(){J(e[10])&&e[10].apply(this,arguments)}),K(t,"pointerdown",function(){J(e[11])&&e[11].apply(this,arguments)}),K(t,"pointermove",e[23])],r=!0)},p(f,d){if(e=f,d[0]&66050){a=ce(e[16].filter(e[34]));let p;for(p=0;p<a.length;p+=1){const g=li(e,a,p);l[p]?(l[p].p(g,d),I(l[p],1)):(l[p]=fi(g),l[p].c(),I(l[p],1),l[p].m(n,null))}for(ue(),p=a.length;p<l.length;p+=1)u(p);fe()}e[6]?c?(c.p(e,d),d[0]&64&&I(c,1)):(c=ci(e),c.c(),I(c,1),c.m(i,null)):c&&(ue(),D(c,1,1,()=>{c=null}),fe()),(!o||d[0]&16384)&&Ce(t,"drawing",e[14]),(!o||d[0]&8)&&Ce(t,"hidden",!e[3]),(!o||d[0]&32768)&&Ce(t,"hover",e[15])},i(f){if(!o){for(let d=0;d<a.length;d+=1)I(l[d]);I(c),o=!0}},o(f){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)D(l[d]);D(c),o=!1},d(f){f&&v(t),Ue(l,f),c&&c.d(),e[35](null),e[36](null),r=!1,me(s)}}}function $r(e,t,n){let i,o,r,s,a,l,u,c,f,d,p,g=Y,y=()=>(g(),g=zt(M,S=>n(17,p=S)),M);e.$$.on_destroy.push(()=>g());let{drawingEnabled:T}=t,{image:_}=t,{preferredDrawingMode:m}=t,{state:w}=t,{style:b=void 0}=t,{toolName:C=Pt()[0]}=t,{user:k}=t,{visible:V=!0}=t,H=0;const q=()=>n(5,H+=1),Z=()=>C,le=()=>T;let A,O,M;qe(()=>y(n(7,M=kn(_,O))));const{hover:R,selection:x,store:P}=w;wt(e,R,S=>n(15,c=S)),wt(e,x,S=>n(33,f=S)),wt(e,P,S=>n(16,d=S));let X,oe;const be=S=>{X&&P.unobserve(X);const N=S.filter(({editable:j})=>j).map(({id:j})=>j);N.length>0?(n(8,oe=N.map(j=>P.getAnnotation(j)).filter(j=>j&&We(j))),X=j=>{const{updated:ge}=j.changes;n(8,oe=ge==null?void 0:ge.map(Se=>Se.newValue))},P.observe(X,{annotations:N})):n(8,oe=void 0)},nt=S=>{const N=An(),j={id:N,bodies:[],target:{annotation:N,selector:S.detail,creator:k,created:new Date}};P.addAnnotation(j),x.setSelected(j.id)},Oe=S=>N=>{var Ve;const{target:j}=S,ge=10*60*1e3,Se=((Ve=j.creator)==null?void 0:Ve.id)!==k.id||!j.created||new Date().getTime()-j.created.getTime()>ge;P.updateTarget({...j,selector:N.detail,created:Se?j.created:new Date,updated:Se?new Date:void 0,updatedBy:Se?k:void 0})},it=S=>{const{x:N,y:j}=Vt(S,O),ge=P.getAt(N,j);ge?c!==ge.id&&R.set(ge.id):R.set(void 0)},Me=S=>jn(S),F=S=>We(S);function ot(S){st[S?"unshift":"push"](()=>{A=S,n(6,A)})}function mt(S){st[S?"unshift":"push"](()=>{O=S,n(4,O)})}return e.$$set=S=>{"drawingEnabled"in S&&n(0,T=S.drawingEnabled),"image"in S&&n(25,_=S.image),"preferredDrawingMode"in S&&n(26,m=S.preferredDrawingMode),"state"in S&&n(27,w=S.state),"style"in S&&n(1,b=S.style),"toolName"in S&&n(2,C=S.toolName),"user"in S&&n(28,k=S.user),"visible"in S&&n(3,V=S.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(14,{tool:i,opts:o}=kt(C)||{tool:void 0,opts:void 0},i,(n(32,o),n(2,C))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(13,r=(o==null?void 0:o.drawingMode)||m),e.$$.dirty[0]&16&&n(12,s=oi(O)),e.$$.dirty[0]&16&&n(11,{onPointerDown:a,onPointerUp:l}=ri(O,P),a,(n(10,l),n(4,O))),e.$$.dirty[1]&4&&n(9,u=S=>f.selected.find(N=>N.id===S.id&&N.editable)),e.$$.dirty[1]&4&&be(f.selected)},[T,b,C,V,O,H,A,M,oe,u,l,a,s,r,i,c,d,p,R,x,P,nt,Oe,it,Me,_,m,w,k,q,Z,le,o,f,F,ot,mt]}class yi extends he{constructor(t){super(),de(this,t,$r,Jr,te,{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 _i(e,t,n=0,i=e.length-1,o=es){for(;i>n;){if(i-n>600){const l=i-n+1,u=t-n+1,c=Math.log(l),f=.5*Math.exp(2*c/3),d=.5*Math.sqrt(c*f*(l-f)/l)*(u-l/2<0?-1:1),p=Math.max(n,Math.floor(t-u*f/l+d)),g=Math.min(i,Math.floor(t+(l-u)*f/l+d));_i(e,t,p,g,o)}const r=e[t];let s=n,a=i;for($e(e,n,t),o(e[i],r)>0&&$e(e,n,i);s<a;){for($e(e,s,a),s++,a--;o(e[s],r)<0;)s++;for(;o(e[a],r)>0;)a--}o(e[n],r)===0?$e(e,n,a):(a++,$e(e,a,i)),a<=t&&(n=a+1),t<=a&&(i=a-1)}}function $e(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function es(e,t){return e<t?-1:e>t?1:0}class ts{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(!_t(t,n))return i;const o=this.toBBox,r=[];for(;n;){for(let s=0;s<n.children.length;s++){const a=n.children[s],l=n.leaf?o(a):a;_t(t,l)&&(n.leaf?i.push(a):Yt(t,l)?this._all(a,i):r.push(a))}n=r.pop()}return i}collides(t){let n=this.data;if(!_t(t,n))return!1;const i=[];for(;n;){for(let o=0;o<n.children.length;o++){const r=n.children[o],s=n.leaf?this.toBBox(r):r;if(_t(t,s)){if(n.leaf||Yt(t,s))return!0;i.push(r)}}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=ze([]),this}remove(t,n){if(!t)return this;let i=this.data;const o=this.toBBox(t),r=[],s=[];let a,l,u;for(;i||r.length;){if(i||(i=r.pop(),l=r[r.length-1],a=s.pop(),u=!0),i.leaf){const c=ns(t,i.children,n);if(c!==-1)return i.children.splice(c,1),r.push(i),this._condense(r),this}!u&&!i.leaf&&Yt(i,o)?(r.push(i),s.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],u=!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 r=i-n+1;let s=this._maxEntries,a;if(r<=s)return a=ze(t.slice(n,i+1)),Ge(a,this.toBBox),a;o||(o=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,o-1))),a=ze([]),a.leaf=!1,a.height=o;const l=Math.ceil(r/s),u=l*Math.ceil(Math.sqrt(s));mi(t,n,i,u,this.compareMinX);for(let c=n;c<=i;c+=u){const f=Math.min(c+u-1,i);mi(t,c,f,l,this.compareMinY);for(let d=c;d<=f;d+=l){const p=Math.min(d+l-1,f);a.children.push(this._build(t,d,p,o-1))}}return Ge(a,this.toBBox),a}_chooseSubtree(t,n,i,o){for(;o.push(n),!(n.leaf||o.length-1===i);){let r=1/0,s=1/0,a;for(let l=0;l<n.children.length;l++){const u=n.children[l],c=Bt(u),f=rs(t,u)-c;f<s?(s=f,r=c<r?c:r,a=u):f===s&&c<r&&(r=c,a=u)}n=a||n.children[0]}return n}_insert(t,n,i){const o=i?t:this.toBBox(t),r=[],s=this._chooseSubtree(o,this.data,n,r);for(s.children.push(t),tt(s,o);n>=0&&r[n].children.length>this._maxEntries;)this._split(r,n),n--;this._adjustParentBBoxes(o,r,n)}_split(t,n){const i=t[n],o=i.children.length,r=this._minEntries;this._chooseSplitAxis(i,r,o);const s=this._chooseSplitIndex(i,r,o),a=ze(i.children.splice(s,i.children.length-s));a.height=i.height,a.leaf=i.leaf,Ge(i,this.toBBox),Ge(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,n){this.data=ze([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Ge(this.data,this.toBBox)}_chooseSplitIndex(t,n,i){let o,r=1/0,s=1/0;for(let a=n;a<=i-n;a++){const l=et(t,0,a,this.toBBox),u=et(t,a,i,this.toBBox),c=ss(l,u),f=Bt(l)+Bt(u);c<r?(r=c,o=a,s=f<s?f:s):c===r&&f<s&&(s=f,o=a)}return o||i-n}_chooseSplitAxis(t,n,i){const o=t.leaf?this.compareMinX:is,r=t.leaf?this.compareMinY:os,s=this._allDistMargin(t,n,i,o),a=this._allDistMargin(t,n,i,r);s<a&&t.children.sort(o)}_allDistMargin(t,n,i,o){t.children.sort(o);const r=this.toBBox,s=et(t,0,n,r),a=et(t,i-n,i,r);let l=yt(s)+yt(a);for(let u=n;u<i-n;u++){const c=t.children[u];tt(s,t.leaf?r(c):c),l+=yt(s)}for(let u=i-n-1;u>=n;u--){const c=t.children[u];tt(a,t.leaf?r(c):c),l+=yt(a)}return l}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)tt(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():Ge(t[n],this.toBBox)}}function ns(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 Ge(e,t){et(e,0,e.children.length,t,e)}function et(e,t,n,i,o){o||(o=ze(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let r=t;r<n;r++){const s=e.children[r];tt(o,e.leaf?i(s):s)}return o}function tt(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 is(e,t){return e.minX-t.minX}function os(e,t){return e.minY-t.minY}function Bt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function yt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function rs(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 ss(e,t){const n=Math.max(e.minX,t.minX),i=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),r=Math.min(e.maxY,t.maxY);return Math.max(0,o-n)*Math.max(0,r-i)}function Yt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function _t(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function ze(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function mi(e,t,n,i,o){const r=[t,n];for(;r.length;){if(n=r.pop(),t=r.pop(),n-t<=i)continue;const s=t+Math.ceil((n-t)/i/2)*i;_i(e,s,t,n,o),r.push(t,s,s,n)}}const ls=()=>{const e=new ts,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=f=>{if(!Ke(f))return;const{minX:d,minY:p,maxX:g,maxY:y}=f.selector.geometry.bounds,T={minX:d,minY:p,maxX:g,maxY:y,target:f};e.insert(T),t.set(f.annotation,T)},r=f=>{if(!Ke(f))return;const d=t.get(f.annotation);d&&e.remove(d),t.delete(f.annotation)};return{all:n,clear:i,getAt:(f,d,p)=>{const y=e.search({minX:f,minY:d,maxX:f,maxY:d}).map(T=>T.target).filter(T=>T.selector.type===z.RECTANGLE||Jt(T.selector,f,d));return y.length>0?(y.sort((T,_)=>at(T.selector)-at(_.selector)),y):[]},getIntersecting:(f,d,p,g)=>e.search({minX:f,minY:d,maxX:f+p,maxY:d+g}).map(y=>y.target),insert:o,remove:r,set:(f,d=!0)=>{d&&i();const p=f.reduce((g,y)=>{if(Ke(y)){const{minX:T,minY:_,maxX:m,maxY:w}=y.selector.geometry.bounds;return[...g,{minX:T,minY:_,maxX:m,maxY:w,target:y}]}else return g},[]);p.forEach(g=>t.set(g.target.annotation,g)),e.load(p)},size:()=>e.all().length,update:(f,d)=>{r(f),o(d)}}},wi=e=>{const t=Uo(),n=ls(),i=Eo(t,e.userSelectAction,e.adapter),o=wo(t),r=Ho();return t.observe(({changes:l})=>{n.set((l.created||[]).map(u=>u.target),!1),(l.deleted||[]).forEach(u=>n.remove(u.target)),(l.updated||[]).forEach(({oldValue:u,newValue:c})=>n.update(u.target,c.target))}),{store:{...t,getAt:(l,u,c)=>{const f=n.getAt(l,u,c);if(c)return f.map(p=>t.getAnnotation(p.annotation)).filter(Boolean).filter(c)[0];{const d=f[0];return d?t.getAnnotation(d.annotation):void 0}},getIntersecting:(l,u,c,f)=>n.getIntersecting(l,u,c,f).map(d=>t.getAnnotation(d.annotation))},selection:i,hover:o,viewport:r}},Ei=e=>{const t=wi(e);return{...t,store:Do(t.store)}},Ti=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 r=1;r<10;r++){const s=Math.round(r*t.width/10),a=Math.round(o*t.height/10),l=n.getImageData(s,a,1,1).data,u=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=u}return i/81},Ai=e=>{const t=Ti(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},Xt=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Ai(e):n),bi=(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}),xt=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Oi=(e,t)=>{const n=t||document,i=s=>{const a=s;a.key==="z"&&a.ctrlKey?e.undo():a.key==="y"&&a.ctrlKey&&e.redo()},o=s=>{const a=s;a.key==="z"&&a.metaKey&&(a.shiftKey?e.redo():e.undo())},r=()=>{xt?n.removeEventListener("keydown",o):n.removeEventListener("keydown",i)};return xt?n.addEventListener("keydown",o):n.addEventListener("keydown",i),{destroy:r}},as=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=bi(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Lt.EDIT,theme:"light"}),o=Ei(i),{selection:r,store:s}=o,a=Vo(s,i.initialHistory),l=Bo(o,a,i.adapter,i.autoSave),u=document.createElement("DIV");u.style.position="relative",u.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(u,n),u.appendChild(n);const c=Oi(a);let f=Zo();Xt(n,u,i.theme);const d=new yi({target:u,props:{drawingEnabled:!!i.drawingEnabled,image:n,preferredDrawingMode:i.drawingMode,state:o,style:i.style,user:f}});d.$on("click",A=>{const{originalEvent:O,annotation:M}=A.detail;M?r.userSelect(M.id,O):r.isEmpty()||r.clear()});const p=Xo(o,a,i.adapter),g=()=>d.cancelDrawing(),y=()=>{d.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),c.destroy(),a.destroy()},T=()=>d.getDrawingTool(),_=()=>f,m=()=>d.isDrawingEnabled(),w=(A,O,M)=>ti(A,O,M),b=(A,O)=>Qn(A,O),C=A=>{if(!kt(A))throw`No drawing tool named ${A}`;d.$set({toolName:A})},k=A=>d.$set({drawingEnabled:A}),V=A=>{console.warn("Filter not implemented yet")},H=A=>d.$set({style:A}),q=A=>Xt(n,u,A),Z=A=>{f=A,d.$set({user:A})},le=A=>d.$set({visible:A});return{...p,cancelDrawing:g,destroy:y,getDrawingTool:T,getUser:_,isDrawingEnabled:m,listDrawingTools:Pt,on:l.on,off:l.off,registerDrawingTool:w,registerShapeEditor:b,setDrawingEnabled:k,setDrawingTool:C,setFilter:V,setStyle:H,setTheme:q,setUser:Z,setVisible:le,element:u,state:o}};L.Editor=pt,L.EditorMount=Zn,L.Handle=ke,L.IdentityTransform=Gr,L.PolygonEditor=Pn,L.RectangleEditor=Hn,L.RectangleUtil=tn,L.RubberbandRectangle=Jn,L.SVGAnnotationLayer=yi,L.ShapeType=z,L.ToolMount=Wn,L.UserSelectAction=Lt,L.W3CImageFormat=tr,L.addEventListeners=ri,L.boundsFromMultiPolygonElements=en,L.boundsFromPoints=Ae,L.chainStyles=Fo,L.computeArea=at,L.computePolygonArea=ut,L.computeStyle=xo,L.createBody=Mo,L.createImageAnnotator=as,L.createImageAnnotatorState=wi,L.createSVGTransform=oi,L.createSvelteImageAnnotatorState=Ei,L.defaultColorProvider=er,L.detectTheme=Ai,L.distance=gt,L.enableResponsive=kn,L.fillDefaults=bi,L.getEditor=jn,L.getSVGPoint=Vt,L.getTool=kt,L.initKeyboardCommands=Oi,L.intersects=Jt,L.isImageAnnotation=We,L.isImageAnnotationTarget=Ke,L.isMac=xt,L.isPointInPolygon=ft,L.isTouch=Vn,L.listDrawingTools=Pt,L.multipolygonElementToPath=Re,L.parseFragmentSelector=nn,L.parseSVGSelector=wn,L.parseW3CImageAnnotation=Rn,L.pointsToPath=$t,L.registerEditor=Qn,L.registerShapeUtil=Ze,L.registerTool=ti,L.sampleBrightness=Ti,L.serializeFragmentSelector=on,L.serializeSVGSelector=En,L.serializeW3CImageAnnotation=Ln,L.setTheme=Xt,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
|
|
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"})});
|
|
3
3
|
//# sourceMappingURL=annotorious.js.map
|