@annotorious/annotorious 3.3.5 → 3.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/annotorious.es.js +183 -179
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +2 -2
- package/dist/annotorious.js.map +1 -1
- package/dist/state/ImageAnnotationStore.d.ts +3 -4
- package/dist/state/spatialTree.d.ts +2 -2
- package/package.json +2 -2
- package/src/state/ImageAnnotationStore.ts +3 -4
- package/src/state/ImageAnnotatorState.ts +16 -4
- package/src/state/spatialTree.ts +6 -3
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,A=4/3*Math.tan(y*Pe/4),_=Math.cos(p*Pe)-A*Math.sin(p*Pe),m=Math.sin(p*Pe)+A*Math.cos(p*Pe),w=Math.cos(g*Pe),b=Math.sin(g*Pe),C=w+A*b,k=b-A*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 A=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(A)<=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 A=e*i-t*n;if(typeof s.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(A===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,T=(Math.atan2(Z,q-le)+Math.PI)%Math.PI/2,O=Math.sin(T),M=Math.cos(T);s.rX=Math.abs(A)/Math.sqrt(q*y(M)+Z*O*M+le*y(O)),s.rY=Math.abs(A)/Math.sqrt(q*y(O)-Z*O*M+le*y(M)),s.xRot=T*180/Math.PI}return typeof s.sweepFlag<"u"&&0>A&&(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,[A,_]=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<A?H+360:H},w=an(g,-d,0).map(m);for(const C of w)C>A&&C<_&&u(fn(l.cX,d,g,C));const b=an(y,-p,0).map(m);for(const C of b)C>A&&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(A=>A.id===y)},c=(g,y)=>{let A;if(Array.isArray(g)){if(A=g.map(m=>e.getAnnotation(m)).filter(Boolean),A.length<g.length){console.warn("Invalid selection: "+g.filter(m=>!A.some(w=>w.id===m)));return}}else{const m=e.getAnnotation(g);if(!m){console.warn("Invalid selection: "+g);return}A=[m]}const _=A.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 A=Array.isArray(g)?g:[g],_=A.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!==A.length&&console.warn("Invalid selection",g)},d=g=>{if(l())return!1;const{selected:y}=s;y.some(({id:A})=>g.includes(A))&&o({selected:y.filter(({id:A})=>!g.includes(A))})},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=(T,O={})=>{n.push({onChange:T,options:O})},o=T=>{const O=n.findIndex(M=>M.onChange==T);O>-1&&n.splice(O,1)},r=(T,O)=>{const M={origin:T,changes:{created:O.created||[],updated:O.updated||[],deleted:O.deleted||[]},state:[...e.values()]};n.forEach(R=>{Lo(R,M)&&R.onChange(M)})},s=(T,O=Q.LOCAL)=>{if(T.id&&e.get(T.id))throw Error(`Cannot add annotation ${T.id} - exists already`);{const M=ht(T);e.set(M.id,M),M.bodies.forEach(R=>t.set(R.id,M.id)),r(O,{created:[M]})}},a=(T,O)=>{const M=ht(typeof T=="string"?O:T),R=typeof T=="string"?T:T.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=(T,O=Q.LOCAL,M=Q.LOCAL)=>{const R=vo(O)?M:O,x=a(T,O);x&&r(R,{updated:[x]})},u=(T,O=Q.LOCAL)=>{e.get(T.id)?l(T,O):s(T,O)},c=(T,O=Q.LOCAL)=>{const M=T.reduce((R,x)=>{const P=a(x);return P?[...R,P]:R},[]);M.length>0&&r(O,{updated:M})},f=(T,O=Q.LOCAL)=>{const M=T.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=(T,O=Q.LOCAL)=>{const M=e.get(T.annotation);if(M){const R={...M,bodies:[...M.bodies,T]};e.set(M.id,R),t.set(T.id,R.id),r(O,{updated:[{oldValue:M,newValue:R,bodiesCreated:[T]}]})}else console.warn(`Attempt to add body to missing annotation: ${T.annotation}`)},p=()=>[...e.values()],g=(T=Q.LOCAL)=>{const O=[...e.values()];e.clear(),t.clear(),r(T,{deleted:O})},y=(T,O=!0,M=Q.LOCAL)=>{const R=T.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=T.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})}},A=T=>{const O=typeof T=="string"?T:T.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}`)},_=(T,O=Q.LOCAL)=>{const M=A(T);M&&r(O,{deleted:[M]})},m=(T,O=Q.LOCAL)=>{const M=T.reduce((R,x)=>{const P=A(x);return P?[...R,P]:R},[]);M.length>0&&r(O,{deleted:M})},w=T=>{const O=e.get(T.annotation);if(O){const M=O.bodies.find(R=>R.id===T.id);if(M){t.delete(M.id);const R={...O,bodies:O.bodies.filter(x=>x.id!==T.id)};return e.set(O.id,R),{oldValue:O,newValue:R,bodiesDeleted:[M]}}else console.warn(`Attempt to delete missing body ${T.id} from annotation ${T.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${T.annotation}`)},b=(T,O=Q.LOCAL)=>{const M=w(T);M&&r(O,{updated:[M]})},C=(T,O=Q.LOCAL)=>{const M=T.map(R=>w(R)).filter(Boolean);M.length>0&&r(O,{updated:M})},k=T=>{const O=e.get(T);return O?{...O}:void 0},V=T=>{const O=t.get(T);if(O){const M=k(O).bodies.find(R=>R.id===T);if(M)return M;console.error(`Store integrity error: body ${T} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${T}`)},H=(T,O)=>{if(T.annotation!==O.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const M=e.get(T.annotation);if(M){const R=M.bodies.find(P=>P.id===T.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 ${T.annotation}`)},q=(T,O,M=Q.LOCAL)=>{const R=H(T,O);R&&r(M,{updated:[R]})},Z=(T,O=Q.LOCAL)=>{const M=T.map(R=>H({id:R.id,annotation:R.annotation},R)).filter(Boolean);r(O,{updated:M})},le=T=>{const O=e.get(T.annotation);if(O){const M={...O,target:{...O.target,...T}};return e.set(O.id,M),{oldValue:O,newValue:M,targetUpdated:{oldTarget:O.target,newTarget:T}}}else console.warn(`Attempt to update target on missing annotation: ${T.annotation}`)};return{addAnnotation:s,addBody:d,all:p,bulkAddAnnotations:y,bulkDeleteAnnotations:m,bulkDeleteBodies:C,bulkUpdateAnnotations:c,bulkUpdateBodies:Z,bulkUpdateTargets:(T,O=Q.LOCAL)=>{const M=T.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:(T,O=Q.LOCAL)=>{const M=le(T);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,A=performance.now();if(A-s>ko)i.splice(o+1),i.push(y),o=i.length-1;else{const _=i.length-1;i[_]=Io(i[_],y)}s=A}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:A}=i[o+1];u(g),f(y),p(A),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){r=!0;const{created:g,updated:y,deleted:A}=i[o];l(g),c(y),d(A),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 A=_=>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",A(!0)),t.on("redo",A(!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(_)},A=_=>{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:A}},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,A){U(y,t,A),U(y,o,A),U(y,r,A),U(y,a,A);for(let _=0;_<p.length;_+=1)p[_]&&p[_].m(y,A);U(y,l,A),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,A){if(e=y,(!u||A&2&&n!==(n=e[1]?"display:none;":void 0))&&h(t,"style",n),(!u||A&16&&i!==(i=e[4].points.map(Un).join(" ")))&&h(t,"points",i),(!u||A&2)&&h(r,"style",e[1]),(!u||A&16&&s!==(s=e[4].points.map(Dn).join(" ")))&&h(r,"points",s),A&536){d=ce(e[4].points);let _;for(_=0;_<d.length;_+=1){const m=In(e,d,_);p[_]?(p[_].p(m,A),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 A=0;A<d.length;A+=1)I(p[A]);u=!0}},o(y){p=p.filter(Boolean);for(let A=0;A<p.length;A+=1)D(p[A]);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 A=d.geometry;p==="SHAPE"?y=A.points.map(([m,w])=>[m+g[0],w+g[1]]):y=A.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,A,_,m,w,b,C,k,V,H,q,Z,le,T,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"),T=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",A=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,T,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&&A!==(A=e[4].y))&&h(g,"y",A),(!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(T),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[A,_]=[y.minX,y.minY],[m,w]=[y.maxX,y.maxY];const[b,C]=g;if(p==="SHAPE")A+=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":{A+=b;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{m+=b;break}}}const k=Math.min(A,m),V=Math.min(_,w),H=Math.abs(m-A),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 A=Yn(e,c,y);f[y]?(f[y].p(A,g),I(f[y],1)):(f[y]=Fn(A),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 A;if(p==="SHAPE")A=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));A=y.map((C,k)=>{if(k===m){const V=C.rings.map((q,Z)=>Z===w?{points:q.points.map((T,O)=>O===b?[T[0]+g[0],T[1]+g[1]]:T)}:q),H=Ae(V[0].points);return{rings:V,bounds:H}}else return C})}return{...d,geometry:{polygons:A,bounds:en(A)}}};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=>A=>{u=y,c=l.elementToImage(A.offsetX,A.offsetY),f=s,A.target.setPointerCapture(A.pointerId),r("grab",A)},p=y=>{if(u){const[A,_]=l.elementToImage(y.offsetX,y.offsetY),m=[A-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])))},A=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",A,!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))}},A=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",A,!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:A}=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=()=>A;let T,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"](()=>{T=S,n(6,T)})}function mt(S){st[S?"unshift":"push"](()=>{O=S,n(4,O)})}return e.$$set=S=>{"drawingEnabled"in S&&n(0,A=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)},[A,b,C,V,O,H,T,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,A={minX:d,minY:p,maxX:g,maxY:y,target:f};e.insert(A),t.set(f.annotation,A)},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)=>{const g=e.search({minX:f,minY:d,maxX:f,maxY:d}).map(y=>y.target).filter(y=>y.selector.type===z.RECTANGLE||Jt(y.selector,f,d));if(g.length>0)return g.sort((y,A)=>at(y.selector)-at(A.selector)),g[0]},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:A,minY:_,maxX:m,maxY:w}=y.selector.geometry.bounds;return[...g,{minX:A,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)=>{const c=n.getAt(l,u);return c?t.getAnnotation(c.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",T=>{const{originalEvent:O,annotation:M}=T.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()},A=()=>d.getDrawingTool(),_=()=>f,m=()=>d.isDrawingEnabled(),w=(T,O,M)=>ti(T,O,M),b=(T,O)=>Qn(T,O),C=T=>{if(!kt(T))throw`No drawing tool named ${T}`;d.$set({toolName:T})},k=T=>d.$set({drawingEnabled:T}),V=T=>{console.warn("Filter not implemented yet")},H=T=>d.$set({style:T}),q=T=>Xt(n,u,T),Z=T=>{f=T,d.$set({user:T})},le=T=>d.$set({visible:T});return{...p,cancelDrawing:g,destroy:y,getDrawingTool:A,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(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"})});
|
|
3
3
|
//# sourceMappingURL=annotorious.js.map
|