@annotorious/annotorious 3.6.2 → 3.6.4
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.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(D,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(D=typeof globalThis<"u"?globalThis:D||self,j(D.Annotorious={}))})(this,function(D){"use strict";var Nr=Object.defineProperty;var Yr=(D,j,Ie)=>j in D?Nr(D,j,{enumerable:!0,configurable:!0,writable:!0,value:Ie}):D[j]=Ie;var nn=(D,j,Ie)=>Yr(D,typeof j!="symbol"?j+"":j,Ie);function j(){}function Ie(e,t){for(const n in t)e[n]=t[n];return e}function on(e){return e()}function sn(){return Object.create(null)}function Ae(e){e.forEach(on)}function ie(e){return typeof e=="function"}function re(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function jo(e){return Object.keys(e).length===0}function rn(e,...t){if(e==null){for(const o of t)o(void 0);return j}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function At(e,t,n){e.$$.on_destroy.push(rn(t,n))}function zo(e,t,n,o){if(e){const i=ln(e,t,n,o);return e[0](i)}}function ln(e,t,n,o){return e[1]&&o?Ie(n.ctx.slice(),e[1](o(t))):n.ctx}function Fo(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let l=0;l<r;l+=1)s[l]=t.dirty[l]|i[l];return s}return t.dirty|i}return t.dirty}function qo(e,t,n,o,i,s){if(i){const r=ln(t,n,o,s);e.p(r,i)}}function Ko(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function an(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function ct(e){return e??""}function F(e,t){e.appendChild(t)}function Y(e,t,n){e.insertBefore(t,n||null)}function N(e){e.parentNode&&e.parentNode.removeChild(e)}function Ye(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function L(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function cn(e){return document.createTextNode(e)}function we(){return cn(" ")}function ke(){return cn("")}function ee(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function c(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Wo(e){return Array.from(e.childNodes)}function Te(e,t,n){e.classList.toggle(t,!!n)}function Zo(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Ze;function Je(e){Ze=e}function un(){if(!Ze)throw new Error("Function called outside component initialization");return Ze}function Be(e){un().$$.on_mount.push(e)}function Ce(){const e=un();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Zo(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function _e(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const He=[],ut=[];let Ge=[];const fn=[],dn=Promise.resolve();let kt=!1;function hn(){kt||(kt=!0,dn.then(mn))}function gn(){return hn(),dn}function Mt(e){Ge.push(e)}const Tt=new Set;let je=0;function mn(){if(je!==0)return;const e=Ze;do{try{for(;je<He.length;){const t=He[je];je++,Je(t),Jo(t.$$)}}catch(t){throw He.length=0,je=0,t}for(Je(null),He.length=0,je=0;ut.length;)ut.pop()();for(let t=0;t<Ge.length;t+=1){const n=Ge[t];Tt.has(n)||(Tt.add(n),n())}Ge.length=0}while(He.length);for(;fn.length;)fn.pop()();kt=!1,Tt.clear(),Je(e)}function Jo(e){if(e.fragment!==null){e.update(),Ae(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Mt)}}function Qo(e){const t=[],n=[];Ge.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),Ge=t}const ft=new Set;let Re;function be(){Re={r:0,c:[],p:Re}}function Ee(){Re.r||Ae(Re.c),Re=Re.p}function U(e,t){e&&e.i&&(ft.delete(e),e.i(t))}function G(e,t,n,o){if(e&&e.o){if(ft.has(e))return;ft.add(e),Re.c.push(()=>{ft.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ve(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ce(e){e&&e.c()}function le(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),Mt(()=>{const s=e.$$.on_mount.map(on).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ae(s),e.$$.on_mount=[]}),i.forEach(Mt)}function ae(e,t){const n=e.$$;n.fragment!==null&&(Qo(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function xo(e,t){e.$$.dirty[0]===-1&&(He.push(e),hn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function de(e,t,n,o,i,s,r=null,l=[-1]){const a=Ze;Je(e);const u=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:i,bound:sn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:sn(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(u.root);let d=!1;if(u.ctx=n?n(e,t.props||{},(f,h,...y)=>{const m=y.length?y[0]:h;return u.ctx&&i(u.ctx[f],u.ctx[f]=m)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](m),d&&xo(e,f)),h}):[],u.update(),d=!0,Ae(u.before_update),u.fragment=o?o(u.ctx):!1,t.target){if(t.hydrate){const f=Wo(t.target);u.fragment&&u.fragment.l(f),f.forEach(N)}else u.fragment&&u.fragment.c();t.intro&&U(e.$$.fragment),le(e,t.target,t.anchor),mn()}Je(a)}class he{constructor(){nn(this,"$$");nn(this,"$$set")}$destroy(){ae(this,1),this.$destroy=j}$on(t,n){if(!ie(n))return j;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!jo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $o="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($o);var J=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(J||{});function ei(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var pn={exports:{}};(function(e){(function(){function t(l,a){var u=l.x-a.x,d=l.y-a.y;return u*u+d*d}function n(l,a,u){var d=a.x,f=a.y,h=u.x-d,y=u.y-f;if(h!==0||y!==0){var m=((l.x-d)*h+(l.y-f)*y)/(h*h+y*y);m>1?(d=u.x,f=u.y):m>0&&(d+=h*m,f+=y*m)}return h=l.x-d,y=l.y-f,h*h+y*y}function o(l,a){for(var u=l[0],d=[u],f,h=1,y=l.length;h<y;h++)f=l[h],t(f,u)>a&&(d.push(f),u=f);return u!==f&&d.push(f),d}function i(l,a,u,d,f){for(var h=d,y,m=a+1;m<u;m++){var g=n(l[m],l[a],l[u]);g>h&&(y=m,h=g)}h>d&&(y-a>1&&i(l,a,y,d,f),f.push(l[y]),u-y>1&&i(l,y,u,d,f))}function s(l,a){var u=l.length-1,d=[l[0]];return i(l,0,u,a,d),d.push(l[u]),d}function r(l,a,u){if(l.length<=2)return l;var d=a!==void 0?a*a:1;return l=u?l:o(l,d),l=s(l,d),l}e.exports=r,e.exports.default=r})()})(pn);var ti=pn.exports;const ni=ei(ti),Pt={},Ue=(e,t)=>Pt[e]=t,dt=e=>Pt[e.type].area(e),_n=(e,t,n,o)=>Pt[e.type].intersects(e,t,n,o),ue=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},Qe=e=>{let t=0,n=e.length-1;for(let o=0;o<e.length;o++)t+=(e[n][0]+e[o][0])*(e[n][1]-e[o][1]),n=o;return Math.abs(.5*t)},xe=(e,t,n)=>{let o=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const r=e[i][0],l=e[i][1],a=e[s][0],u=e[s][1];l>n!=u>n&&t<(a-r)*(n-l)/(u-l)+r&&(o=!o)}return o},yn=(e,t=!0)=>{let n="M ";return e.forEach(([o,i],s)=>{s===0?n+=`${o},${i}`:n+=` L ${o},${i}`}),t&&(n+=" Z"),n},Lt=(e,t=1)=>{const n=e.map(([o,i])=>({x:o,y:i}));return ni(n,t,!0).map(o=>[o.x,o.y])},$e=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},oi={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,l=0,a=Math.cos(l),u=Math.sin(l),d=t-o,f=n-i,h=a*d+u*f,y=u*d-a*f;return h*h/(s*s)+y*y/(r*r)<=1}};Ue(J.ELLIPSE,oi);const ii={area:e=>0,intersects:(e,t,n,o=2)=>{const[[i,s],[r,l]]=e.geometry.points,a=Math.abs((l-s)*t-(r-i)*n+r*s-l*i),u=$e([i,s],[r,l]);return a/u<=o}};Ue(J.LINE,ii);const si={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,o)=>{const[i,...s]=o.rings,r=Qe(i.points),l=s.reduce((a,u)=>a+Qe(u.points),0);return n+r-l},0)},intersects:(e,t,n)=>{const{polygons:o}=e.geometry;for(const i of o){const[s,...r]=i.rings;if(xe(s.points,t,n)){let l=!1;for(const a of r)if(xe(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},et=e=>{const t=e.reduce((n,o)=>[...n,...o.rings[0].points],[]);return ue(t)},Pe=e=>e.rings.map(n=>yn(n.points)).join(" "),wn=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((o,i)=>[...o,...i.points],[])],[]),ri=(e,t=1)=>{const n=e.geometry.polygons.map(i=>{const s=i.rings.map(l=>{const a=Lt(l.points,t);return{...l,points:a}}),r=ue(s[0].points);return{...i,rings:s,bounds:r}}),o=et(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:o}}};Ue(J.MULTIPOLYGON,si);const li={area:e=>{const t=e.geometry.points;return Qe(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return xe(o,t,n)}},ai=(e,t=1)=>{const n=Lt(e.geometry.points,t),o=ue(n);return{...e,geometry:{...e.geometry,bounds:o,points:n}}};Ue(J.POLYGON,li);const ci={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=ht(t.points,t.closed);return Qe(n)},intersects:(e,t,n,o=2)=>{const i=e.geometry;if(i.closed){const s=ht(i.points,i.closed);return xe(s,t,n)}else return ui(i,[t,n],o)}},ht=(e,t=!1)=>{const n=[];for(let o=0;o<e.length;o++){const i=e[o],s=e[(o+1)%e.length];if(n.push(i.point),(o<e.length-1||t)&&(i.outHandle||s.inHandle)){const l=bn(i.point,i.outHandle||i.point,s.inHandle||s.point,s.point,10);n.push(...l.slice(1))}}return n},bn=(e,t,n,o,i=10)=>{const s=[];for(let r=0;r<=i;r++){const l=r/i,a=Math.pow(1-l,3)*e[0]+3*Math.pow(1-l,2)*l*t[0]+3*(1-l)*Math.pow(l,2)*n[0]+Math.pow(l,3)*o[0],u=Math.pow(1-l,3)*e[1]+3*Math.pow(1-l,2)*l*t[1]+3*(1-l)*Math.pow(l,2)*n[1]+Math.pow(l,3)*o[1];s.push([a,u])}return s},ui=(e,t,n)=>{for(let o=0;o<e.points.length-1;o++){const i=e.points[o],s=e.points[o+1];if(i.outHandle||s.inHandle){const l=bn(i.point,i.outHandle||i.point,s.inHandle||s.point,s.point,20);for(let a=0;a<l.length-1;a++)if(En(t,l[a],l[a+1])<=n)return!0}else if(En(t,i.point,s.point)<=n)return!0}return!1},En=(e,t,n)=>{const[o,i]=e,[s,r]=t,[l,a]=n,u=l-s,d=a-r,f=Math.sqrt(u*u+d*d);if(f===0)return Math.sqrt((o-s)*(o-s)+(i-r)*(i-r));const h=((o-s)*u+(i-r)*d)/(f*f);return h<=0?Math.sqrt((o-s)*(o-s)+(i-r)*(i-r)):h>=1?Math.sqrt((o-l)*(o-l)+(i-a)*(i-a)):Math.abs((a-r)*o-(l-s)*i+l*r-a*s)/f},It=e=>{if(!e.points||e.points.length===0)return"";const t=[],n=e.points[0];t.push(`M ${n.point[0]} ${n.point[1]}`);for(let o=1;o<e.points.length;o++){const i=e.points[o],s=e.points[o-1];if(i.type==="CURVE"||s.type==="CURVE"){const r=s.type==="CURVE"&&s.outHandle||s.point,l=i.type==="CURVE"&&i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}else t.push(`L ${i.point[0]} ${i.point[1]}`)}if(e.closed){const o=e.points[e.points.length-1],i=e.points[0];if(o.outHandle||i.inHandle){const r=o.outHandle||o.point,l=i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Ue(J.POLYLINE,ci);const vn={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};Ue(J.RECTANGLE,vn);const tt=e=>nt(e.target),nt=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},Sn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[s,r,l,a,u,d,f]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[h,y,m,g]=[a,u,d,f].map(parseFloat);return{type:J.RECTANGLE,geometry:{x:h,y,w:m,h:g,bounds:{minX:h,minY:t?y-g:y,maxX:h+m,maxY:t?y:y+g}}}},An=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},kn="http://www.w3.org/2000/svg",Mn=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},fi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${kn}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},gt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(kn),i=n.lookupNamespaceURI(null);return o||i?Mn(n).firstChild:Mn(fi(n)).firstChild},di=e=>{const t=Tn(e),n=[];let o=[],i=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":o.length>0&&(n.push({points:o}),o=[]),i=[s.args[0],s.args[1]],o.push([...i]);break;case"L":i=[s.args[0],s.args[1]],o.push([...i]);break;case"H":i=[s.args[0],i[1]],o.push([...i]);break;case"V":i=[i[0],s.args[0]],o.push([...i]);break;case"C":i=[s.args[4],s.args[5]],o.push([...i]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(o.length>2&&n.push({points:o}),n.length>0){const s=ue(n[0].points);return{rings:n,bounds:s}}},hi=e=>{const t=Tn(e),n=[];let o=[0,0],i=!1;for(let r=0;r<t.length;r++){const l=t[r];switch(l.type.toUpperCase()){case"M":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"L":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"C":const a=[l.args[0],l.args[1]],u=[l.args[2],l.args[3]],d=[l.args[4],l.args[5]];if(n.length>0){const h=n[n.length-1];(a[0]!==h.point[0]||a[1]!==h.point[1])&&(h.type="CURVE",h.outHandle=a)}const f={type:u[0]!==d[0]||u[1]!==d[1]?"CURVE":"CORNER",point:d};f.type==="CURVE"&&(f.inHandle=u),n.push(f),o=d;break;case"Z":i=!0;break;default:console.warn(`Unsupported SVG path command: ${l.type}`);break}}const s=ue(ht(n,i));return{points:n,closed:i,bounds:s}},Tn=e=>{const t=[],n=e.replace(/,/g," ").trim(),o=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let i;for(;(i=o.exec(n))!==null;){const[,s,r]=i,l=r.trim()===""?[]:r.trim().split(/\s+/).map(Number).filter(a=>!isNaN(a));t.push({type:s,args:l})}return t},gi=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:J.POLYGON,geometry:{points:i,bounds:ue(i)}}},mi=e=>{const t=gt(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:J.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},pi=e=>{const t=gt(e),n=parseFloat(t.getAttribute("x1")),o=parseFloat(t.getAttribute("x2")),i=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),r={minX:Math.min(n,o),minY:Math.min(i,s),maxX:Math.max(n,o),maxY:Math.max(i,s)};return{type:J.LINE,geometry:{points:[[n,i],[o,s]],bounds:r}}},_i=e=>{const t=gt(e),n=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],o=n==null?void 0:n.getAttribute("d");if(!o)throw new Error("Could not parse SVG path");const i=hi(o);if(!i)throw new Error("Could not parse SVG path");return{type:J.POLYLINE,geometry:i}},yi=e=>{const t=gt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>di(a)).filter(Boolean),s=i.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=ue(s);return i.length===1&&i[0].rings.length===1?{type:J.POLYGON,geometry:{points:s,bounds:r}}:{type:J.MULTIPOLYGON,geometry:{polygons:i,bounds:r}}},Pn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return gi(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return _i(t);if(t.includes("<path "))return yi(t);if(t.includes("<ellipse "))return mi(t);if(t.includes("<line "))return pi(t);throw"Unsupported SVG shape: "+t},wi=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Pe(n)}" />`).join("")}</g>`,Ln=e=>{let t;switch(e.type){case J.POLYGON:{const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`;break}case J.ELLIPSE:{const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;break}case J.MULTIPOLYGON:{const n=e.geometry;t=`<svg>${wi(n)}</svg>`;break}case J.LINE:{const n=e.geometry,[[o,i],[s,r]]=n.points;t=`<svg><line x1="${o}" y1="${i}" x2="${s}" y2="${r}" /></svg>`;break}case J.POLYLINE:t=`<svg><path d="${It(e.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},ge=[];for(let e=0;e<256;++e)ge.push((e+256).toString(16).slice(1));function bi(e,t=0){return(ge[e[t+0]]+ge[e[t+1]]+ge[e[t+2]]+ge[e[t+3]]+"-"+ge[e[t+4]]+ge[e[t+5]]+"-"+ge[e[t+6]]+ge[e[t+7]]+"-"+ge[e[t+8]]+ge[e[t+9]]+"-"+ge[e[t+10]]+ge[e[t+11]]+ge[e[t+12]]+ge[e[t+13]]+ge[e[t+14]]+ge[e[t+15]]).toLowerCase()}let Ct;const Ei=new Uint8Array(16);function vi(){if(!Ct){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ct=crypto.getRandomValues.bind(crypto)}return Ct(Ei)}const In={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Cn(e,t,n){var i;if(In.randomUUID&&!e)return In.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??vi();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,bi(o)}var On=Object.prototype.hasOwnProperty;function Oe(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&Oe(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(On.call(e,n)&&++o&&!On.call(t,n)||!(n in t)||!Oe(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function Ot(){}function Si(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const ze=[];function Dt(e,t=Ot){let n;const o=new Set;function i(l){if(Si(e,l)&&(e=l,n)){const a=!ze.length;for(const u of o)u[1](),ze.push(u,e);if(a){for(let u=0;u<ze.length;u+=2)ze[u][0](ze[u+1]);ze.length=0}}}function s(l){i(l(e))}function r(l,a=Ot){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||Ot),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Ai=e=>{const{subscribe:t,set:n}=Dt();let o;return t(i=>o=i),e.observe(({changes:i})=>{if(o){(i.deleted||[]).some(r=>r.id===o)&&n(void 0);const s=(i.updated||[]).find(({oldValue:r})=>r.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Nt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Nt||{});const mt={selected:[]},ki=(e,t,n)=>{const{subscribe:o,set:i}=Dt(mt);let s=t,r=mt;o(g=>r=g);const l=()=>{Oe(r,mt)||i(mt)},a=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},u=g=>{if(a())return!1;const k=typeof g=="string"?g:g.id;return r.selected.some(p=>p.id===k)},d=(g,k)=>{let p;if(Array.isArray(g)){if(p=g.map(E=>e.getAnnotation(E)).filter(Boolean),p.length<g.length){console.warn("Invalid selection: "+g.filter(E=>!p.some(A=>A.id===E)));return}}else{const E=e.getAnnotation(g);if(!E){console.warn("Invalid selection: "+g);return}p=[E]}const S=p.reduce((E,A)=>{const M=m(A);return M==="EDIT"?[...E,{id:A.id,editable:!0}]:M==="SELECT"?[...E,{id:A.id}]:E},[]);i({selected:S,event:k})},f=(g,k)=>{const p=Array.isArray(g)?g:[g],S=p.map(E=>e.getAnnotation(E)).filter(E=>!!E);i({selected:S.map(E=>{const A=k===void 0?m(E)==="EDIT":k;return{id:E.id,editable:A}})}),S.length!==p.length&&console.warn("Invalid selection",g)},h=g=>{if(a())return!1;const{selected:k}=r;k.some(({id:p})=>g.includes(p))&&i({selected:k.filter(({id:p})=>!g.includes(p))})},y=g=>{s=g,f(r.selected.map(({id:k})=>k))},m=g=>Mi(g,s,n);return e.observe(({changes:g})=>h((g.deleted||[]).map(k=>k.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:l,evalSelectAction:m,isEmpty:a,isSelected:u,setSelected:f,setUserSelectAction:y,subscribe:o,userSelect:d}},Mi=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},me=[];for(let e=0;e<256;++e)me.push((e+256).toString(16).slice(1));function Ti(e,t=0){return(me[e[t+0]]+me[e[t+1]]+me[e[t+2]]+me[e[t+3]]+"-"+me[e[t+4]]+me[e[t+5]]+"-"+me[e[t+6]]+me[e[t+7]]+"-"+me[e[t+8]]+me[e[t+9]]+"-"+me[e[t+10]]+me[e[t+11]]+me[e[t+12]]+me[e[t+13]]+me[e[t+14]]+me[e[t+15]]).toLowerCase()}let Yt;const Pi=new Uint8Array(16);function Li(){if(!Yt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Yt=crypto.getRandomValues.bind(crypto)}return Yt(Pi)}const Ii=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Dn={randomUUID:Ii};function Nn(e,t,n){var o;if(Dn.randomUUID&&!e)return Dn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Li();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,Ti(i)}const Bt=e=>{const t=n=>{const o={...n};return n.created&&typeof n.created=="string"&&(o.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(o.updated=new Date(n.updated)),o};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Ci=(e,t,n,o)=>({id:Nn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Oi=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Di=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Ni=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!Oe(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Yi=(e,t)=>!Oe(e.target,t.target),Yn=(e,t)=>{const n=Oi(e,t),o=Di(e,t),i=Ni(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Yi(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var ne=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(ne||{});const Bi=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,l=a=>a&&a.length>0;if(!(l(i.created)||l(i.deleted))){const a=(n=i.updated)==null?void 0:n.some(d=>l(d.bodiesCreated)||l(d.bodiesDeleted)||l(d.bodiesUpdated)),u=(o=i.updated)==null?void 0:o.some(d=>d.targetUpdated);if(r==="BODY_ONLY"&&a&&!u||r==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const r=new Set([...(i.created||[]).map(l=>l.id),...(i.deleted||[]).map(l=>l.id),...(i.updated||[]).map(({oldValue:l})=>l.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(l=>r.has(l))}else return!0},Ri=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),l=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),a=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:h})=>h.id===f.id).newValue:f),...t.created||[]],u=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],d=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:h,newValue:y}=f;if(r.has(y.id)){const m=t.updated.find(g=>g.oldValue.id===y.id).newValue;return Yn(h,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:u,updated:d}},pt=e=>{const t=e.id===void 0?Nn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},Ui=e=>e.id!==void 0,Vi=()=>{const e=new Map,t=new Map,n=[],o=(w,v={})=>{n.push({onChange:w,options:v})},i=w=>{const v=n.findIndex(_=>_.onChange==w);v>-1&&n.splice(v,1)},s=(w,v)=>{const _={origin:w,changes:{created:v.created||[],updated:v.updated||[],deleted:v.deleted||[]},state:[...e.values()]};n.forEach(b=>{Bi(b,_)&&b.onChange(_)})},r=(w,v=ne.LOCAL)=>{if(w.id&&e.get(w.id))throw Error(`Cannot add annotation ${w.id} - exists already`);{const _=pt(w);e.set(_.id,_),_.bodies.forEach(b=>t.set(b.id,_.id)),s(v,{created:[_]})}},l=(w,v)=>{const _=pt(typeof w=="string"?v:w),b=typeof w=="string"?w:w.id,I=b&&e.get(b);if(I){const P=Yn(I,_);return b===_.id?e.set(b,_):(e.delete(b),e.set(_.id,_)),I.bodies.forEach(O=>t.delete(O.id)),_.bodies.forEach(O=>t.set(O.id,_.id)),P}else console.warn(`Cannot update annotation ${b} - does not exist`)},a=(w,v=ne.LOCAL,_=ne.LOCAL)=>{const b=Ui(v)?_:v,I=l(w,v);I&&s(b,{updated:[I]})},u=(w,v=ne.LOCAL)=>{e.get(w.id)?a(w,v):r(w,v)},d=(w,v=ne.LOCAL)=>{const _=w.reduce((b,I)=>{const P=l(I);return P?[...b,P]:b},[]);_.length>0&&s(v,{updated:_})},f=(w,v=ne.LOCAL)=>{const _=w.map(pt),{toAdd:b,toUpdate:I}=_.reduce((O,z)=>e.get(z.id)?{...O,toUpdate:[...O.toUpdate,z]}:{...O,toAdd:[...O.toAdd,z]},{toAdd:[],toUpdate:[]}),P=I.map(O=>l(O,v)).filter(Boolean);b.forEach(O=>{e.set(O.id,O),O.bodies.forEach(z=>t.set(z.id,O.id))}),s(v,{created:b,updated:P})},h=(w,v=ne.LOCAL)=>{const _=e.get(w.annotation);if(_){const b={..._,bodies:[..._.bodies,w]};e.set(_.id,b),t.set(w.id,b.id),s(v,{updated:[{oldValue:_,newValue:b,bodiesCreated:[w]}]})}else console.warn(`Attempt to add body to missing annotation: ${w.annotation}`)},y=()=>[...e.values()],m=(w=ne.LOCAL)=>{const v=[...e.values()];e.clear(),t.clear(),s(w,{deleted:v})},g=(w,v=!0,_=ne.LOCAL)=>{const b=w.map(pt);if(v){const I=[...e.values()];e.clear(),t.clear(),b.forEach(P=>{e.set(P.id,P),P.bodies.forEach(O=>t.set(O.id,P.id))}),s(_,{created:b,deleted:I})}else{const I=w.reduce((P,O)=>{const z=O.id&&e.get(O.id);return z?[...P,z]:P},[]);if(I.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${I.map(P=>P.id).join(", ")}`);b.forEach(P=>{e.set(P.id,P),P.bodies.forEach(O=>t.set(O.id,P.id))}),s(_,{created:b})}},k=w=>{const v=typeof w=="string"?w:w.id,_=e.get(v);if(_)return e.delete(v),_.bodies.forEach(b=>t.delete(b.id)),_;console.warn(`Attempt to delete missing annotation: ${v}`)},p=(w,v=ne.LOCAL)=>{const _=k(w);_&&s(v,{deleted:[_]})},S=(w,v=ne.LOCAL)=>{const _=w.reduce((b,I)=>{const P=k(I);return P?[...b,P]:b},[]);_.length>0&&s(v,{deleted:_})},E=w=>{const v=e.get(w.annotation);if(v){const _=v.bodies.find(b=>b.id===w.id);if(_){t.delete(_.id);const b={...v,bodies:v.bodies.filter(I=>I.id!==w.id)};return e.set(v.id,b),{oldValue:v,newValue:b,bodiesDeleted:[_]}}else console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${w.annotation}`)},A=(w,v=ne.LOCAL)=>{const _=E(w);_&&s(v,{updated:[_]})},M=(w,v=ne.LOCAL)=>{const _=w.map(b=>E(b)).filter(Boolean);_.length>0&&s(v,{updated:_})},C=w=>{const v=e.get(w);return v?{...v}:void 0},T=w=>{const v=t.get(w);if(v){const _=C(v).bodies.find(b=>b.id===w);if(_)return _;console.error(`Store integrity error: body ${w} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${w}`)},V=(w,v)=>{if(w.annotation!==v.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const _=e.get(w.annotation);if(_){const b=_.bodies.find(P=>P.id===w.id),I={..._,bodies:_.bodies.map(P=>P.id===b.id?v:P)};return e.set(_.id,I),b.id!==v.id&&(t.delete(b.id),t.set(v.id,I.id)),{oldValue:_,newValue:I,bodiesUpdated:[{oldBody:b,newBody:v}]}}else console.warn(`Attempt to add body to missing annotation ${w.annotation}`)},B=(w,v,_=ne.LOCAL)=>{const b=V(w,v);b&&s(_,{updated:[b]})},W=(w,v=ne.LOCAL)=>{const _=w.map(b=>V({id:b.id,annotation:b.annotation},b)).filter(Boolean);s(v,{updated:_})},q=w=>{const v=e.get(w.annotation);if(v){const _={...v,target:{...v.target,...w}};return e.set(v.id,_),{oldValue:v,newValue:_,targetUpdated:{oldTarget:v.target,newTarget:w}}}else console.warn(`Attempt to update target on missing annotation: ${w.annotation}`)};return{addAnnotation:r,addBody:h,all:y,bulkAddAnnotations:g,bulkDeleteAnnotations:S,bulkDeleteBodies:M,bulkUpdateAnnotations:d,bulkUpdateBodies:W,bulkUpdateTargets:(w,v=ne.LOCAL)=>{const _=w.map(b=>q(b)).filter(Boolean);_.length>0&&s(v,{updated:_})},bulkUpsertAnnotations:f,clear:m,deleteAnnotation:p,deleteBody:A,getAnnotation:C,getBody:T,observe:o,unobserve:i,updateAnnotation:a,updateBody:B,updateTarget:(w,v=ne.LOCAL)=>{const _=q(w);_&&s(v,{updated:[_]})},upsertAnnotation:u}},Xi=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let Hi=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const Gi=250,ji=(e,t)=>{const n=Hi(),o=(t==null?void 0:t.changes)||[];let i=t?t.pointer:-1,s=!1,r=0;const l=m=>{if(!s){const{changes:g}=m,k=performance.now();if(k-r>Gi)o.splice(i+1),o.push(g),i=o.length-1;else{const p=o.length-1;o[p]=Ri(o[p],g)}r=k}s=!1};e.observe(l,{origin:ne.LOCAL});const a=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m),u=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),d=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({oldValue:g})=>g)),f=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({newValue:g})=>g)),h=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),y=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...o],pointer:i}),on:(m,g)=>n.on(m,g),redo:()=>{if(o.length-1>i){s=!0;const{created:m,updated:g,deleted:k}=o[i+1];u(m),f(g),y(k),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:m,updated:g,deleted:k}=o[i];a(m),d(g),h(k),n.emit("undo",o[i]),i-=1}}}},zi=()=>{const{subscribe:e,set:t}=Dt([]);return{subscribe:e,set:t}},Fi=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],d,f;const h=(p,S)=>{a.has(p)?a.get(p).push(S):a.set(p,[S])},y=(p,S)=>{const E=a.get(p);if(E){const A=E.indexOf(S);A!==-1&&E.splice(A,1)}},m=(p,S,E)=>{a.has(p)&&setTimeout(()=>{a.get(p).forEach(A=>{if(n){const M=Array.isArray(S)?S.map(T=>n.serialize(T)):n.serialize(S),C=E?E instanceof PointerEvent?E:n.serialize(E):void 0;A(M,C)}else A(S,E)})},1)},g=()=>{const{selected:p}=s,S=(p||[]).map(({id:E})=>r.getAnnotation(E));S.forEach(E=>{const A=u.find(M=>M.id===E.id);(!A||!Oe(A,E))&&m("updateAnnotation",E,A)}),u=u.map(E=>S.find(({id:M})=>M===E.id)||E)};s.subscribe(({selected:p})=>{if(!(u.length===0&&p.length===0)){if(u.length===0&&p.length>0)u=p.map(({id:S})=>r.getAnnotation(S));else if(u.length>0&&p.length===0)u.forEach(S=>{const E=r.getAnnotation(S.id);E&&!Oe(E,S)&&m("updateAnnotation",E,S)}),u=[];else{const S=new Set(u.map(A=>A.id)),E=new Set(p.map(({id:A})=>A));u.filter(A=>!E.has(A.id)).forEach(A=>{const M=r.getAnnotation(A.id);M&&!Oe(M,A)&&m("updateAnnotation",M,A)}),u=[...u.filter(A=>E.has(A.id)),...p.filter(({id:A})=>!S.has(A)).map(({id:A})=>r.getAnnotation(A))]}m("selectionChanged",u)}}),i.subscribe(p=>{!d&&p?m("mouseEnterAnnotation",r.getAnnotation(p)):d&&!p?m("mouseLeaveAnnotation",r.getAnnotation(d)):d&&p&&(m("mouseLeaveAnnotation",r.getAnnotation(d)),m("mouseEnterAnnotation",r.getAnnotation(p))),d=p}),l==null||l.subscribe(p=>m("viewportIntersect",p.map(S=>r.getAnnotation(S)))),r.observe(p=>{o&&(f&&clearTimeout(f),f=setTimeout(g,1e3));const{created:S,deleted:E}=p.changes;(S||[]).forEach(A=>m("createAnnotation",A)),(E||[]).forEach(A=>m("deleteAnnotation",A)),(p.changes.updated||[]).filter(A=>[...A.bodiesCreated||[],...A.bodiesDeleted||[],...A.bodiesUpdated||[]].length>0).forEach(({oldValue:A,newValue:M})=>{const C=u.find(T=>T.id===A.id)||A;u=u.map(T=>T.id===A.id?M:T),m("updateAnnotation",M,C)})},{origin:ne.LOCAL}),r.observe(p=>{if(u){const S=new Set(u.map(A=>A.id)),E=(p.changes.updated||[]).filter(({newValue:A})=>S.has(A.id)).map(({newValue:A})=>A);E.length>0&&(u=u.map(A=>E.find(C=>C.id===A.id)||A))}},{origin:ne.REMOTE});const k=p=>S=>{const{updated:E}=S;p?(E||[]).forEach(A=>m("updateAnnotation",A.oldValue,A.newValue)):(E||[]).forEach(A=>m("updateAnnotation",A.newValue,A.oldValue))};return t.on("undo",k(!0)),t.on("redo",k(!1)),{on:h,off:y,emit:m}},qi=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Ki=(e,t,n)=>{const{store:o,selection:i}=e,s=p=>{if(n){const{parsed:S,error:E}=n.parse(p);S?o.addAnnotation(S,ne.REMOTE):console.error(E)}else o.addAnnotation(Bt(p),ne.REMOTE)},r=()=>i.clear(),l=()=>o.clear(),a=p=>{const S=o.getAnnotation(p);return n&&S?n.serialize(S):S},u=()=>n?o.all().map(n.serialize):o.all(),d=()=>{var p;const S=(((p=i.selected)==null?void 0:p.map(E=>E.id))||[]).map(E=>o.getAnnotation(E)).filter(Boolean);return n?S.map(n.serialize):S},f=(p,S=!0)=>fetch(p).then(E=>E.json()).then(E=>(y(E,S),E)),h=p=>{if(typeof p=="string"){const S=o.getAnnotation(p);if(o.deleteAnnotation(p),S)return n?n.serialize(S):S}else{const S=n?n.parse(p).parsed:p;if(S)return o.deleteAnnotation(S),p}},y=(p,S=!0)=>{if(n){const E=n.parseAll||qi(n),{parsed:A,failed:M}=E(p);M.length>0&&console.warn(`Discarded ${M.length} invalid annotations`,M),o.bulkAddAnnotations(A,S,ne.REMOTE)}else o.bulkAddAnnotations(p.map(Bt),S,ne.REMOTE)},m=(p,S)=>{p?i.setSelected(p,S):i.clear()},g=p=>{i.clear(),i.setUserSelectAction(p)},k=p=>{if(n){const S=n.parse(p).parsed,E=n.serialize(o.getAnnotation(S.id));return o.updateAnnotation(S),E}else{const S=o.getAnnotation(p.id);return o.updateAnnotation(Bt(p)),S}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:d,loadAnnotations:f,redo:t.redo,removeAnnotation:h,setAnnotations:y,setSelected:m,setUserSelectAction:g,undo:t.undo,updateAnnotation:k}},Wi=(e,t,n)=>typeof t=="function"?t(e,n):t,Zi=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,o)=>{const i=typeof e=="function"?e(n,o):e,s=typeof t=="function"?t(n,o):t;return{...i||{},...s||{}}},Ji="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Qi=e=>crypto.getRandomValues(new Uint8Array(e)),xi=(e,t,n)=>{let o=(2<<Math.log2(e.length-1))-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let l=n(i),a=i|0;for(;a--;)if(r+=e[l[a]&o]||"",r.length>=s)return r}}},$i=(e,t=21)=>xi(e,t|0,Qi),es=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Ji[n[e]&63];return t};const ts=()=>({isGuest:!0,id:$i("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ns=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Bn=e=>e?typeof e=="object"?{...e}:e:void 0,os=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:l,modified:a,creator:u,...d}=n;return{id:o||`temp-${ns(n)}`,annotation:t,type:i,purpose:s,value:r,creator:Bn(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...d}}),is=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,l={...r,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l}),ss=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],rs=()=>{const e=[...ss];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};es();const ls=(e,t={strict:!0,invertY:!1})=>({parse:i=>Rn(i,t),serialize:i=>Un(i,e,t)}),Rn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Cn(),{creator:o,created:i,modified:s,body:r,...l}=e,a=os(r||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,d=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,f=typeof d=="string"||(d==null?void 0:d.type)==="FragmentSelector"?Sn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?Pn(d):void 0,h=Array.isArray(l.target)?l.target[0]:l.targret;return f||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Bn(o),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Un=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:s,updated:r,updatedBy:l,...a}=e.target;let u;try{u=o.type==J.RECTANGLE?An(o.geometry):Ln(o)}catch(f){if(n.strict)throw f;u=o}const d={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:is(e.bodies),created:s==null?void 0:s.toISOString(),creator:i,modified:r==null?void 0:r.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete d.bodies,"annotation"in d.target&&delete d.target.annotation,d},Fe=[];function as(e,t=j){let n;const o=new Set;function i(l){if(re(e,l)&&(e=l,n)){const a=!Fe.length;for(const u of o)u[1](),Fe.push(u,e);if(a){for(let u=0;u<Fe.length;u+=2)Fe[u][0](Fe[u+1]);Fe.length=0}}}function s(l){i(l(e))}function r(l,a=j){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||j),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const cs=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},Vn=(e,t)=>{cs(e,t);const{subscribe:n,set:o}=as(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,u=Math.max(r.width/l,r.height/a);o(u)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},Ve=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i,stroke:s,strokeWidth:r,strokeOpacity:l}=n;let a="";return o&&(a+=`fill:${o};`,a+=`fill-opacity:${i||"0.25"};`),s&&(a+=`stroke:${s};`,a+=`stroke-width:${r||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}},ot=(e,t=0)=>{const{minX:n,minY:o,maxX:i,maxY:s}=e;return{x:n-t,y:o-t,w:i-n+2*t,h:s-o+2*t}},Le=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,us=e=>({}),Xn=e=>({grab:e[0]});function fs(e){let t,n,o,i;const s=e[8].default,r=zo(s,e,e[7],Xn);return{c(){t=L("g"),r&&r.c(),c(t,"class","a9s-annotation selected")},m(l,a){Y(l,t,a),r&&r.m(t,null),n=!0,o||(i=[ee(t,"pointerup",e[2]),ee(t,"pointermove",e[1])],o=!0)},p(l,[a]){r&&r.p&&(!n||a&128)&&qo(r,s,l,l[7],n?Fo(s,l[7],a,us):Ko(l[7]),Xn)},i(l){n||(U(r,l),n=!0)},o(l){G(r,l),n=!1},d(l){l&&N(t),r&&r.d(l),o=!1,Ae(i)}}}function ds(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=Ce();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,d,f,h;const y=k=>p=>{if(d=k,u){const{left:E,top:A}=u.getBoundingClientRect(),M=p.clientX-E,C=p.clientY-A;f=a.elementToImage(M,C)}else{const{offsetX:E,offsetY:A}=p;f=a.elementToImage(E,A)}h=r,p.target.setPointerCapture(p.pointerId),s("grab",p)},m=k=>{if(d){const[p,S]=a.elementToImage(k.offsetX,k.offsetY),E=[p-f[0],S-f[1]];n(3,r=l(h,d,E)),s("change",r)}},g=k=>{k.target.releasePointerCapture(k.pointerId),d=void 0,h=r,s("release",k)};return e.$$set=k=>{"shape"in k&&n(3,r=k.shape),"editor"in k&&n(4,l=k.editor),"transform"in k&&n(5,a=k.transform),"svgEl"in k&&n(6,u=k.svgEl),"$$scope"in k&&n(7,i=k.$$scope)},[y,m,g,r,l,a,u,i,o]}class _t extends he{constructor(t){super(),de(this,t,ds,fs,re,{shape:3,editor:4,transform:5,svgEl:6})}}function hs(e){let t,n,o,i,s,r,l,a,u=e[3]&&Hn(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),i=L("circle"),c(n,"class","a9s-handle-buffer"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]+6/e[2]),c(i,"class",s=`a9s-handle-dot${e[3]?" selected":""}`),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[5]),c(t,"class",r=`a9s-handle ${e[8].class||""}`.trim())},m(d,f){Y(d,t,f),F(t,n),u&&u.m(t,null),F(t,i),l||(a=[ee(n,"pointerenter",e[11]),ee(n,"pointerleave",e[12]),ee(n,"pointerdown",e[13]),ee(n,"pointerdown",e[6]),ee(n,"pointerup",e[14]),ee(n,"pointerup",e[7])],l=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&36&&o!==(o=d[5]+6/d[2])&&c(n,"r",o),d[3]?u?u.p(d,f):(u=Hn(d),u.c(),u.m(t,i)):u&&(u.d(1),u=null),f&8&&s!==(s=`a9s-handle-dot${d[3]?" selected":""}`)&&c(i,"class",s),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&32&&c(i,"r",d[5]),f&256&&r!==(r=`a9s-handle ${d[8].class||""}`.trim())&&c(t,"class",r)},d(d){d&&N(t),u&&u.d(),l=!1,Ae(a)}}}function gs(e){let t,n,o,i,s,r,l,a,u;return{c(){t=L("g"),n=L("circle"),i=L("circle"),r=L("circle"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]*10),c(n,"class","a9s-touch-halo"),Te(n,"touched",e[4]),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",s=e[5]+10/e[2]),c(i,"class","a9s-handle-buffer"),c(r,"class","a9s-handle-dot"),c(r,"cx",e[0]),c(r,"cy",e[1]),c(r,"r",l=e[5]+2/e[2]),c(t,"class","a9s-touch-handle")},m(d,f){Y(d,t,f),F(t,n),F(t,i),F(t,r),a||(u=[ee(i,"pointerdown",e[9]),ee(i,"pointerup",e[10]),ee(i,"pointerdown",e[6]),ee(i,"pointerup",e[7])],a=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&32&&o!==(o=d[5]*10)&&c(n,"r",o),f&16&&Te(n,"touched",d[4]),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&36&&s!==(s=d[5]+10/d[2])&&c(i,"r",s),f&1&&c(r,"cx",d[0]),f&2&&c(r,"cy",d[1]),f&36&&l!==(l=d[5]+2/d[2])&&c(r,"r",l)},d(d){d&&N(t),a=!1,Ae(u)}}}function Hn(e){let t,n;return{c(){t=L("circle"),c(t,"class","a9s-handle-selected"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",n=e[5]+8/e[2])},m(o,i){Y(o,t,i)},p(o,i){i&1&&c(t,"cx",o[0]),i&2&&c(t,"cy",o[1]),i&36&&n!==(n=o[5]+8/o[2])&&c(t,"r",n)},d(o){o&&N(t)}}}function ms(e){let t;function n(s,r){return Le?gs:hs}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),Y(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&N(t),i.d(s)}}}function ps(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=p=>{p.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function f(p){_e.call(this,e,p)}function h(p){_e.call(this,e,p)}function y(p){_e.call(this,e,p)}function m(p){_e.call(this,e,p)}function g(p){_e.call(this,e,p)}function k(p){_e.call(this,e,p)}return e.$$set=p=>{n(8,t=Ie(Ie({},t),an(p))),"x"in p&&n(0,i=p.x),"y"in p&&n(1,s=p.y),"scale"in p&&n(2,r=p.scale),"selected"in p&&n(3,l=p.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=4/r)},t=an(t),[i,s,r,l,a,o,u,d,t,f,h,y,m,g,k]}class Xe extends he{constructor(t){super(),de(this,t,ps,ms,re,{x:0,y:1,scale:2,selected:3})}}function _s(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("circle"),i=L("circle"),s=L("circle"),c(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=1.75*e[2]),c(i,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[2]),c(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),c(s,"cx",e[0]),c(s,"cy",e[1]),c(s,"r",e[2]),c(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(a,u){Y(a,t,u),F(t,n),F(t,i),F(t,s),r||(l=[ee(n,"pointerdown",e[5]),ee(n,"pointerdown",e[3])],r=!0)},p(a,u){u&1&&c(n,"cx",a[0]),u&2&&c(n,"cy",a[1]),u&4&&o!==(o=1.75*a[2])&&c(n,"r",o),u&1&&c(i,"cx",a[0]),u&2&&c(i,"cy",a[1]),u&4&&c(i,"r",a[2]),u&1&&c(s,"cx",a[0]),u&2&&c(s,"cy",a[1]),u&4&&c(s,"r",a[2])},d(a){a&&N(t),r=!1,Ae(l)}}}function ys(e){let t;return{c(){t=L("circle"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",e[2])},m(n,o){Y(n,t,o)},p(n,o){o&1&&c(t,"cx",n[0]),o&2&&c(t,"cy",n[1]),o&4&&c(t,"r",n[2])},d(n){n&&N(t)}}}function ws(e){let t;function n(s,r){return Le?ys:_s}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),Y(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&N(t),i.d(s)}}}function bs(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){_e.call(this,e,u)}return e.$$set=u=>{"x"in u&&n(0,i=u.x),"y"in u&&n(1,s=u.y),"scale"in u&&n(4,r=u.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,o=4/r)},[i,s,o,l,r,a]}class Gn extends he{constructor(t){super(),de(this,t,bs,ws,re,{x:0,y:1,scale:4})}}function Rt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function jn(e,t,n){const o=e.slice();return o[28]=t[n],o[30]=n,o}function Ut(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Vt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function zn(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[28][0]),c(t,"cy",o=e[28][1]),c(t,"r",i=it/e[3]),c(t,"class","svelte-1h2slbm")},m(s,r){Y(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[28][1])&&c(t,"cy",o),r[0]&8&&i!==(i=it/s[3])&&c(t,"r",i)},d(s){s&&N(t)}}}function Fn(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1h2slbm"),c(l,"cx",a=e[28][0]),c(l,"cy",u=e[28][1]),c(l,"r",d=it/e[3]),c(l,"class","svelte-1h2slbm"),c(t,"id",`${e[19]}-inner`),c(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(f,h){Y(f,t,h),F(t,n),F(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[28][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[28][1])&&c(l,"cy",u),h[0]&8&&d!==(d=it/f[3])&&c(l,"r",d)},d(f){f&&N(t)}}}function qn(e){let t,n;return t=new Xe({props:{class:"a9s-corner-handle",x:e[28][0],y:e[28][1],scale:e[3],selected:e[8].includes(e[30])}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[15]),t.$on("pointerdown",function(){ie(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&32&&(s.x=e[28][0]),i[0]&32&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),i[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Kn(e){let t,n;return t=new Gn({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[28][0]),i[0]&1088&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Es(e){let t,n,o,i,s,r,l,a,u,d,f,h,y,m,g,k,p,S,E,A,M,C=e[6]!==void 0&&!e[7]&&zn(Vt(e)),T=e[6]!==void 0&&!e[7]&&Fn(Ut(e)),V=ve(e[5].points),B=[];for(let w=0;w<V.length;w+=1)B[w]=qn(jn(e,V,w));const W=w=>G(B[w],1,1,()=>{B[w]=null});let q=e[6]!==void 0&&!e[7]&&Kn(Rt(e));return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),C&&C.c(),T&&T.c(),d=we(),f=L("polygon"),y=we(),m=L("polygon"),k=we();for(let w=0;w<B.length;w+=1)B[w].c();p=we(),q&&q.c(),S=ke(),c(o,"x",i=e[9].x),c(o,"y",s=e[9].y),c(o,"width",r=e[9].w),c(o,"height",l=e[9].h),c(o,"class","svelte-1h2slbm"),c(a,"points",u=e[5].points.map(Wn).join(" ")),c(a,"class","svelte-1h2slbm"),c(n,"id",`${e[19]}-outer`),c(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[19]}-outer)`),c(f,"points",h=e[5].points.map(Zn).join(" ")),c(m,"class","a9s-inner a9s-shape-handle"),c(m,"mask",`url(#${e[19]}-inner)`),c(m,"style",e[1]),c(m,"points",g=e[5].points.map(Jn).join(" "))},m(w,v){Y(w,t,v),F(t,n),F(n,o),F(n,a),C&&C.m(n,null),T&&T.m(t,null),Y(w,d,v),Y(w,f,v),Y(w,y,v),Y(w,m,v),Y(w,k,v);for(let _=0;_<B.length;_+=1)B[_]&&B[_].m(w,v);Y(w,p,v),q&&q.m(w,v),Y(w,S,v),E=!0,A||(M=[ee(f,"pointerup",e[14]),ee(f,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),ee(m,"pointermove",e[13]),ee(m,"pointerup",e[14]),ee(m,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],A=!0)},p(w,v){if(e=w,(!E||v[0]&512&&i!==(i=e[9].x))&&c(o,"x",i),(!E||v[0]&512&&s!==(s=e[9].y))&&c(o,"y",s),(!E||v[0]&512&&r!==(r=e[9].w))&&c(o,"width",r),(!E||v[0]&512&&l!==(l=e[9].h))&&c(o,"height",l),(!E||v[0]&32&&u!==(u=e[5].points.map(Wn).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Vt(e),v):(C=zn(Vt(e)),C.c(),C.m(n,null)):C&&(C.d(1),C=null),e[6]!==void 0&&!e[7]?T?T.p(Ut(e),v):(T=Fn(Ut(e)),T.c(),T.m(t,null)):T&&(T.d(1),T=null),(!E||v[0]&32&&h!==(h=e[5].points.map(Zn).join(" ")))&&c(f,"points",h),(!E||v[0]&2)&&c(m,"style",e[1]),(!E||v[0]&32&&g!==(g=e[5].points.map(Jn).join(" ")))&&c(m,"points",g),v[0]&134322472){V=ve(e[5].points);let _;for(_=0;_<V.length;_+=1){const b=jn(e,V,_);B[_]?(B[_].p(b,v),U(B[_],1)):(B[_]=qn(b),B[_].c(),U(B[_],1),B[_].m(p.parentNode,p))}for(be(),_=V.length;_<B.length;_+=1)W(_);Ee()}e[6]!==void 0&&!e[7]?q?(q.p(Rt(e),v),v[0]&192&&U(q,1)):(q=Kn(Rt(e)),q.c(),U(q,1),q.m(S.parentNode,S)):q&&(be(),G(q,1,1,()=>{q=null}),Ee())},i(w){if(!E){for(let v=0;v<V.length;v+=1)U(B[v]);U(q),E=!0}},o(w){B=B.filter(Boolean);for(let v=0;v<B.length;v+=1)G(B[v]);G(q),E=!1},d(w){w&&(N(t),N(d),N(f),N(y),N(m),N(k),N(p),N(S)),C&&C.d(),T&&T.d(),Ye(B,w),q&&q.d(w),A=!1,Ae(M)}}}function vs(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[Es,({grab:o})=>({27:o}),({grab:o})=>[o?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&134219754|i[1]&1&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ss=250,As=1e3,ks=12,it=4.5,Wn=e=>e.join(","),Zn=e=>e.join(","),Jn=e=>e.join(",");function Ms(e,t,n){let o,i,s;const r=Ce();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,y=!1,m,g=[];const k=()=>n(7,y=!0),p=()=>n(7,y=!1),S=_=>{if(g.length>0||!i.some(Z=>Z.visible)){n(6,h=void 0);return}const[b,I]=u.elementToImage(_.offsetX,_.offsetY),P=Z=>Math.pow(Z[0]-b,2)+Math.pow(Z[1]-I,2),O=o.points.reduce((Z,x)=>P(x)<P(Z)?x:Z),z=i.filter(Z=>Z.visible).reduce((Z,x)=>P(x.point)<P(Z.point)?x:Z),H=Math.pow(As/d,2);P(O)<H||P(z.point)<H?n(6,h=i.indexOf(z)):n(6,h=void 0)},E=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,g=[]),E()},M=_=>{n(7,y=!0),_.preventDefault(),_.stopPropagation(),m=performance.now()},C=_=>b=>{if(!m||Le||performance.now()-m>Ss)return;const I=g.includes(_);b.metaKey||b.ctrlKey||b.shiftKey?I?n(8,g=g.filter(P=>P!==_)):n(8,g=[...g,_]):I&&g.length>1?n(8,g=[_]):I?n(8,g=[]):n(8,g=[_]),E()},T=(_,b,I)=>{E();let P;const O=_.geometry;g.length>1?P=O.points.map(([H,Q],Z)=>g.includes(Z)?[H+I[0],Q+I[1]]:[H,Q]):b==="SHAPE"?P=O.points.map(([H,Q])=>[H+I[0],Q+I[1]]):P=O.points.map(([H,Q],Z)=>b===`HANDLE-${Z}`?[H+I[0],Q+I[1]]:[H,Q]);const z=ue(P);return{..._,geometry:{points:P,bounds:z}}},V=_=>async b=>{b.stopPropagation();const I=[...o.points.slice(0,_+1),i[_].point,...o.points.slice(_+1)],P=ue(I);r("change",{...l,geometry:{points:I,bounds:P}}),await gn();const O=[...document.querySelectorAll(".a9s-handle")][_+1];if(O!=null&&O.firstChild){const z=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:b.clientX,clientY:b.clientY,pointerId:b.pointerId,pointerType:b.pointerType,isPrimary:b.isPrimary,buttons:b.buttons});O.firstChild.dispatchEvent(z)}},B=()=>{if(o.points.length-g.length<3)return;const _=o.points.filter((I,P)=>!g.includes(P)),b=ue(_);r("change",{...l,geometry:{points:_,bounds:b}}),n(8,g=[])};Be(()=>{if(Le)return;const _=b=>{(b.key==="Delete"||b.key==="Backspace")&&(b.preventDefault(),B())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",_),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",_)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function q(_){_e.call(this,e,_)}function w(_){_e.call(this,e,_)}function v(_){_e.call(this,e,_)}return e.$$set=_=>{"shape"in _&&n(0,l=_.shape),"computedStyle"in _&&n(1,a=_.computedStyle),"transform"in _&&n(2,u=_.transform),"viewportScale"in _&&n(3,d=_.viewportScale),"svgEl"in _&&n(4,f=_.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Le?[]:o.points.map((_,b)=>{const I=b===o.points.length-1?o.points[0]:o.points[b+1],P=(_[0]+I[0])/2,O=(_[1]+I[1])/2,H=Math.sqrt(Math.pow(I[0]-P,2)+Math.pow(I[1]-O,2))>ks/d;return{point:[P,O],visible:H}})),e.$$.dirty[0]&40&&n(9,s=ot(o.bounds,it/d))},[l,a,u,d,f,o,h,y,g,s,i,k,p,S,A,M,C,T,V,W,q,w,v]}class Qn extends he{constructor(t){super(),de(this,t,Ms,vs,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Ts(e){let t,n,o,i,s,r,l,a,u,d,f,h,y,m,g,k,p,S,E,A,M,C,T,V,B,W,q,w,v,_,b,I,P,O,z,H,Q,Z,x,oe,se,Se,Me,X,fe,te,pe,ye,We,De,en,Ne,$,tn,Go;return te=new Xe({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),ye=new Xe({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),ye.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),De=new Xe({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),De.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Ne=new Xe({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Ne.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),y=we(),m=L("rect"),E=we(),A=L("rect"),B=we(),W=L("rect"),_=we(),b=L("rect"),z=we(),H=L("rect"),oe=we(),se=L("rect"),fe=we(),ce(te.$$.fragment),pe=we(),ce(ye.$$.fragment),We=we(),ce(De.$$.fragment),en=we(),ce(Ne.$$.fragment),c(o,"class","rect-mask-bg svelte-1njczvj"),c(o,"x",i=e[6].x),c(o,"y",s=e[6].y),c(o,"width",r=e[6].w),c(o,"height",l=e[6].h),c(a,"class","rect-mask-fg svelte-1njczvj"),c(a,"x",u=e[5].x),c(a,"y",d=e[5].y),c(a,"width",f=e[5].w),c(a,"height",h=e[5].h),c(n,"id",e[8]),c(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),c(m,"class","a9s-outer"),c(m,"mask",`url(#${e[8]})`),c(m,"x",g=e[5].x),c(m,"y",k=e[5].y),c(m,"width",p=e[5].w),c(m,"height",S=e[5].h),c(A,"class","a9s-inner a9s-shape-handle"),c(A,"style",e[1]),c(A,"x",M=e[5].x),c(A,"y",C=e[5].y),c(A,"width",T=e[5].w),c(A,"height",V=e[5].h),c(W,"class","a9s-edge-handle a9s-edge-handle-top"),c(W,"x",q=e[5].x),c(W,"y",w=e[5].y),c(W,"height",1),c(W,"width",v=e[5].w),c(b,"class","a9s-edge-handle a9s-edge-handle-right"),c(b,"x",I=e[5].x+e[5].w),c(b,"y",P=e[5].y),c(b,"height",O=e[5].h),c(b,"width",1),c(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),c(H,"x",Q=e[5].x),c(H,"y",Z=e[5].y+e[5].h),c(H,"height",1),c(H,"width",x=e[5].w),c(se,"class","a9s-edge-handle a9s-edge-handle-left"),c(se,"x",Se=e[5].x),c(se,"y",Me=e[5].y),c(se,"height",X=e[5].h),c(se,"width",1)},m(K,R){Y(K,t,R),F(t,n),F(n,o),F(n,a),Y(K,y,R),Y(K,m,R),Y(K,E,R),Y(K,A,R),Y(K,B,R),Y(K,W,R),Y(K,_,R),Y(K,b,R),Y(K,z,R),Y(K,H,R),Y(K,oe,R),Y(K,se,R),Y(K,fe,R),le(te,K,R),Y(K,pe,R),le(ye,K,R),Y(K,We,R),le(De,K,R),Y(K,en,R),le(Ne,K,R),$=!0,tn||(Go=[ee(m,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(A,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(W,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),ee(b,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),ee(H,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),ee(se,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],tn=!0)},p(K,R){e=K,(!$||R&64&&i!==(i=e[6].x))&&c(o,"x",i),(!$||R&64&&s!==(s=e[6].y))&&c(o,"y",s),(!$||R&64&&r!==(r=e[6].w))&&c(o,"width",r),(!$||R&64&&l!==(l=e[6].h))&&c(o,"height",l),(!$||R&32&&u!==(u=e[5].x))&&c(a,"x",u),(!$||R&32&&d!==(d=e[5].y))&&c(a,"y",d),(!$||R&32&&f!==(f=e[5].w))&&c(a,"width",f),(!$||R&32&&h!==(h=e[5].h))&&c(a,"height",h),(!$||R&32&&g!==(g=e[5].x))&&c(m,"x",g),(!$||R&32&&k!==(k=e[5].y))&&c(m,"y",k),(!$||R&32&&p!==(p=e[5].w))&&c(m,"width",p),(!$||R&32&&S!==(S=e[5].h))&&c(m,"height",S),(!$||R&2)&&c(A,"style",e[1]),(!$||R&32&&M!==(M=e[5].x))&&c(A,"x",M),(!$||R&32&&C!==(C=e[5].y))&&c(A,"y",C),(!$||R&32&&T!==(T=e[5].w))&&c(A,"width",T),(!$||R&32&&V!==(V=e[5].h))&&c(A,"height",V),(!$||R&32&&q!==(q=e[5].x))&&c(W,"x",q),(!$||R&32&&w!==(w=e[5].y))&&c(W,"y",w),(!$||R&32&&v!==(v=e[5].w))&&c(W,"width",v),(!$||R&32&&I!==(I=e[5].x+e[5].w))&&c(b,"x",I),(!$||R&32&&P!==(P=e[5].y))&&c(b,"y",P),(!$||R&32&&O!==(O=e[5].h))&&c(b,"height",O),(!$||R&32&&Q!==(Q=e[5].x))&&c(H,"x",Q),(!$||R&32&&Z!==(Z=e[5].y+e[5].h))&&c(H,"y",Z),(!$||R&32&&x!==(x=e[5].w))&&c(H,"width",x),(!$||R&32&&Se!==(Se=e[5].x))&&c(se,"x",Se),(!$||R&32&&Me!==(Me=e[5].y))&&c(se,"y",Me),(!$||R&32&&X!==(X=e[5].h))&&c(se,"height",X);const bt={};R&32&&(bt.x=e[5].x),R&32&&(bt.y=e[5].y),R&8&&(bt.scale=e[3]),te.$set(bt);const Et={};R&32&&(Et.x=e[5].x+e[5].w),R&32&&(Et.y=e[5].y),R&8&&(Et.scale=e[3]),ye.$set(Et);const vt={};R&32&&(vt.x=e[5].x+e[5].w),R&32&&(vt.y=e[5].y+e[5].h),R&8&&(vt.scale=e[3]),De.$set(vt);const St={};R&32&&(St.x=e[5].x),R&32&&(St.y=e[5].y+e[5].h),R&8&&(St.scale=e[3]),Ne.$set(St)},i(K){$||(U(te.$$.fragment,K),U(ye.$$.fragment,K),U(De.$$.fragment,K),U(Ne.$$.fragment,K),$=!0)},o(K){G(te.$$.fragment,K),G(ye.$$.fragment,K),G(De.$$.fragment,K),G(Ne.$$.fragment,K),$=!1},d(K){K&&(N(t),N(y),N(m),N(E),N(A),N(B),N(W),N(_),N(b),N(z),N(H),N(oe),N(se),N(fe),N(pe),N(We),N(en)),ae(te,K),ae(ye,K),ae(De,K),ae(Ne,K),tn=!1,Ae(Go)}}}function Ps(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Ts,({grab:o})=>({12:o}),({grab:o})=>o?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&16&&(s.svgEl=o[4]),i&12394&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ls(e,t,n){let o,i,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const d=(g,k,p)=>{const S=g.geometry.bounds;let[E,A]=[S.minX,S.minY],[M,C]=[S.maxX,S.maxY];const[T,V]=p;if(k==="SHAPE")E+=T,M+=T,A+=V,C+=V;else{switch(k){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{A+=V;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{C+=V;break}}switch(k){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{E+=T;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{M+=T;break}}}const B=Math.min(E,M),W=Math.min(A,C),q=Math.abs(M-E),w=Math.abs(C-A);return{...g,geometry:{x:B,y:W,w:q,h:w,bounds:{minX:B,minY:W,maxX:B+q,maxY:W+w}}}},f=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function h(g){_e.call(this,e,g)}function y(g){_e.call(this,e,g)}function m(g){_e.call(this,e,g)}return e.$$set=g=>{"shape"in g&&n(0,s=g.shape),"computedStyle"in g&&n(1,r=g.computedStyle),"transform"in g&&n(2,l=g.transform),"viewportScale"in g&&n(3,a=g.viewportScale),"svgEl"in g&&n(4,u=g.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,o=s.geometry),e.$$.dirty&40&&n(6,i=ot(o.bounds,2/a))},[s,r,l,a,u,o,i,d,f,h,y,m]}class xn extends he{constructor(t){super(),de(this,t,Ls,Ps,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var $n=Object.prototype.hasOwnProperty;function Xt(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&Xt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if($n.call(e,n)&&++o&&!$n.call(t,n)||!(n in t)||!Xt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Is=12,Cs=(e,t)=>e.polygons.reduce((n,o,i)=>{const s=o.rings.reduce((r,l,a)=>{const u=l.points.map((d,f)=>{const h=f===l.points.length-1?l.points[0]:l.points[f+1],y=(d[0]+h[0])/2,m=(d[1]+h[1])/2,k=Math.sqrt(Math.pow(h[0]-y,2)+Math.pow(h[1]-m,2))>Is/t;return{point:[y,m],visible:k,elementIdx:i,ringIdx:a,pointIdx:f}});return[...r,...u]},[]);return[...n,...s]},[]);function Ht(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function eo(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function to(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function no(e,t,n){const o=e.slice();return o[29]=t[n],o[37]=n,o}function Gt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function jt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function oo(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[29][0]),c(t,"cy",o=e[29][1]),c(t,"r",i=st/e[3]),c(t,"class","svelte-1vxo6dc")},m(s,r){Y(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[29][1])&&c(t,"cy",o),r[0]&8&&i!==(i=st/s[3])&&c(t,"r",i)},d(s){s&&N(t)}}}function io(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1vxo6dc"),c(l,"cx",a=e[29][0]),c(l,"cy",u=e[29][1]),c(l,"r",d=st/e[3]),c(l,"class","svelte-1vxo6dc"),c(t,"id",`${e[18]}-${e[32]}-inner`),c(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(f,h){Y(f,t,h),F(t,n),F(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[29][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[29][1])&&c(l,"cy",u),h[0]&8&&d!==(d=st/f[3])&&c(l,"r",d)},d(f){f&&N(t)}}}function so(e){let t,n;function o(...i){return e[19](e[32],e[35],e[37],...i)}return t=new Xe({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(o)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){ie(e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`))&&e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`).apply(this,arguments)}),t.$on("pointerup",e[15](e[32],e[35],e[37])),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){e=i;const r={};s[0]&32&&(r.x=e[29][0]),s[0]&32&&(r.y=e[29][1]),s[0]&8&&(r.scale=e[3]),s[0]&256&&(r.selected=e[8].some(o)),t.$set(r)},i(i){n||(U(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function ro(e){let t,n,o=ve(e[33].points),i=[];for(let r=0;r<o.length;r+=1)i[r]=so(no(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);Y(r,t,l),n=!0},p(r,l){if(l[0]&268491048){o=ve(r[33].points);let a;for(a=0;a<o.length;a+=1){const u=no(r,o,a);i[a]?(i[a].p(u,l),U(i[a],1)):(i[a]=so(u),i[a].c(),U(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)U(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&N(t),Ye(i,r)}}}function lo(e){let t,n,o,i,s,r,l,a,u,d,f,h,y,m,g,k,p,S=e[6]!==void 0&&!e[7]&&oo(jt(e)),E=e[6]!==void 0&&!e[7]&&io(Gt(e)),A=ve(e[30].rings),M=[];for(let T=0;T<A.length;T+=1)M[T]=ro(to(e,A,T));const C=T=>G(M[T],1,1,()=>{M[T]=null});return{c(){t=L("g"),n=L("defs"),o=L("mask"),i=L("rect"),u=L("path"),S&&S.c(),E&&E.c(),f=L("path"),y=L("path");for(let T=0;T<M.length;T+=1)M[T].c();c(i,"x",s=e[9].x),c(i,"y",r=e[9].y),c(i,"width",l=e[9].w),c(i,"height",a=e[9].h),c(i,"class","svelte-1vxo6dc"),c(u,"d",d=Pe(e[30])),c(u,"class","svelte-1vxo6dc"),c(o,"id",`${e[18]}-${e[32]}-outer`),c(o,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[18]}-${e[32]}-outer)`),c(f,"fill-rule","evenodd"),c(f,"d",h=Pe(e[30])),c(y,"class","a9s-inner"),c(y,"mask",`url(#${e[18]}-${e[32]}-inner)`),c(y,"style",e[1]),c(y,"fill-rule","evenodd"),c(y,"d",m=Pe(e[30]))},m(T,V){Y(T,t,V),F(t,n),F(n,o),F(o,i),F(o,u),S&&S.m(o,null),E&&E.m(n,null),F(t,f),F(t,y);for(let B=0;B<M.length;B+=1)M[B]&&M[B].m(t,null);g=!0,k||(p=[ee(f,"pointerup",e[13]),ee(f,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),ee(y,"pointerup",e[13]),ee(y,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],k=!0)},p(T,V){if(e=T,(!g||V[0]&512&&s!==(s=e[9].x))&&c(i,"x",s),(!g||V[0]&512&&r!==(r=e[9].y))&&c(i,"y",r),(!g||V[0]&512&&l!==(l=e[9].w))&&c(i,"width",l),(!g||V[0]&512&&a!==(a=e[9].h))&&c(i,"height",a),(!g||V[0]&32&&d!==(d=Pe(e[30])))&&c(u,"d",d),e[6]!==void 0&&!e[7]?S?S.p(jt(e),V):(S=oo(jt(e)),S.c(),S.m(o,null)):S&&(S.d(1),S=null),e[6]!==void 0&&!e[7]?E?E.p(Gt(e),V):(E=io(Gt(e)),E.c(),E.m(n,null)):E&&(E.d(1),E=null),(!g||V[0]&32&&h!==(h=Pe(e[30])))&&c(f,"d",h),(!g||V[0]&2)&&c(y,"style",e[1]),(!g||V[0]&32&&m!==(m=Pe(e[30])))&&c(y,"d",m),V[0]&268491048){A=ve(e[30].rings);let B;for(B=0;B<A.length;B+=1){const W=to(e,A,B);M[B]?(M[B].p(W,V),U(M[B],1)):(M[B]=ro(W),M[B].c(),U(M[B],1),M[B].m(t,null))}for(be(),B=A.length;B<M.length;B+=1)C(B);Ee()}},i(T){if(!g){for(let V=0;V<A.length;V+=1)U(M[V]);g=!0}},o(T){M=M.filter(Boolean);for(let V=0;V<M.length;V+=1)G(M[V]);g=!1},d(T){T&&N(t),S&&S.d(),E&&E.d(),Ye(M,T),k=!1,Ae(p)}}}function ao(e){let t,n;return t=new Gn({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[29][0]),i[0]&1088&&(s.y=e[29][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Os(e){let t,n,o,i=ve(e[5].polygons),s=[];for(let a=0;a<i.length;a+=1)s[a]=lo(eo(e,i,a));const r=a=>G(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&ao(Ht(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=we(),l&&l.c(),n=ke()},m(a,u){for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(a,u);Y(a,t,u),l&&l.m(a,u),Y(a,n,u),o=!0},p(a,u){if(u[0]&268763114){i=ve(a[5].polygons);let d;for(d=0;d<i.length;d+=1){const f=eo(a,i,d);s[d]?(s[d].p(f,u),U(s[d],1)):(s[d]=lo(f),s[d].c(),U(s[d],1),s[d].m(t.parentNode,t))}for(be(),d=i.length;d<s.length;d+=1)r(d);Ee()}a[6]!==void 0&&!a[7]?l?(l.p(Ht(a),u),u[0]&192&&U(l,1)):(l=ao(Ht(a)),l.c(),U(l,1),l.m(n.parentNode,n)):l&&(be(),G(l,1,1,()=>{l=null}),Ee())},i(a){if(!o){for(let u=0;u<i.length;u+=1)U(s[u]);U(l),o=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)G(s[u]);G(l),o=!1},d(a){a&&(N(t),N(n)),Ye(s,a),l&&l.d(a)}}}function Ds(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[Os,({grab:o})=>({28:o}),({grab:o})=>[o?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&268437482|i[1]&128&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ns=250,Ys=1e3,st=4.5;function Bs(e,t,n){let o,i,s;const r=Ce();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,y=!1,m,g=[];const k=()=>n(7,y=!0),p=()=>n(7,y=!1),S=b=>{if(g.length>0||!i.some(x=>x.visible)){n(6,h=void 0);return}const[I,P]=u.elementToImage(b.offsetX,b.offsetY),O=x=>Math.pow(x[0]-I,2)+Math.pow(x[1]-P,2),z=wn(o).reduce((x,oe)=>O(oe)<O(x)?oe:x),H=i.filter(x=>x.visible).reduce((x,oe)=>O(oe.point)<O(x.point)?oe:x),Q=Math.pow(Ys/d,2);O(z)<Q||O(H.point)<Q?n(6,h=i.indexOf(H)):n(6,h=void 0)},E=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,g=[]),E()},M=b=>{n(7,y=!0),b.preventDefault(),b.stopPropagation(),m=performance.now()},C=(b,I,P)=>O=>{if(!m||Le||performance.now()-m>Ns)return;const z=Q=>Q.polygon===b&&Q.ring===I&&Q.point===P,H=g.some(z);O.metaKey||O.ctrlKey||O.shiftKey?H?n(8,g=g.filter(Q=>!z(Q))):n(8,g=[...g,{polygon:b,ring:I,point:P}]):H&&g.length>1?n(8,g=[{polygon:b,ring:I,point:P}]):H?n(8,g=[]):n(8,g=[{polygon:b,ring:I,point:P}]),E()},T=(b,I,P)=>{E();const O=b.geometry.polygons;let z;if(I==="SHAPE")z=O.map(H=>{const Q=H.rings.map((x,oe)=>({points:x.points.map((Se,Me)=>[Se[0]+P[0],Se[1]+P[1]])})),Z=ue(Q[0].points);return{rings:Q,bounds:Z}});else{const[H,Q,Z,x]=I.split("-").map(oe=>parseInt(oe));z=O.map((oe,se)=>{if(se===Q){const Se=oe.rings.map((X,fe)=>fe===Z?{points:X.points.map((pe,ye)=>ye===x?[pe[0]+P[0],pe[1]+P[1]]:pe)}:X),Me=ue(Se[0].points);return{rings:Se,bounds:Me}}else return oe})}return{...b,geometry:{polygons:z,bounds:et(z)}}},V=b=>async I=>{I.stopPropagation();const P=i[b],O=o.polygons.map((H,Q)=>{if(Q===P.elementIdx){const Z=H.rings.map((oe,se)=>se===P.ringIdx?{points:[...oe.points.slice(0,P.pointIdx+1),P.point,...oe.points.slice(P.pointIdx+1)]}:oe),x=ue(Z[0].points);return{rings:Z,bounds:x}}else return H});r("change",{...l,geometry:{polygons:O,bounds:et(O)}}),await gn();const z=[...document.querySelectorAll(".a9s-handle")][b+1];if(z!=null&&z.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:I.clientX,clientY:I.clientY,pointerId:I.pointerId,pointerType:I.pointerType,isPrimary:I.isPrimary,buttons:I.buttons});z.firstChild.dispatchEvent(H)}},B=()=>{const b=o.polygons.map((P,O)=>{if(g.some(H=>H.polygon===O)){const H=P.rings.map((Z,x)=>{const oe=g.filter(se=>se.polygon===O&&se.ring===x);return oe.length&&Z.points.length-oe.length>=3?{points:Z.points.filter((Se,Me)=>!oe.some(X=>X.point===Me))}:Z}),Q=ue(H[0].points);return{rings:H,bounds:Q}}else return P});!Xt(o.polygons,b)&&(r("change",{...l,geometry:{polygons:b,bounds:et(b)}}),n(8,g=[]))};Be(()=>{if(Le)return;const b=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),B())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",b),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",b)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,q=(b,I,P,{polygon:O,ring:z,point:H})=>O===b&&z===I&&H===P;function w(b){_e.call(this,e,b)}function v(b){_e.call(this,e,b)}function _(b){_e.call(this,e,b)}return e.$$set=b=>{"shape"in b&&n(0,l=b.shape),"computedStyle"in b&&n(1,a=b.computedStyle),"transform"in b&&n(2,u=b.transform),"viewportScale"in b&&n(3,d=b.viewportScale),"svgEl"in b&&n(4,f=b.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Le?[]:Cs(o,d)),e.$$.dirty[0]&40&&n(9,s=ot(o.bounds,st/d))},[l,a,u,d,f,o,h,y,g,s,i,k,p,A,M,C,T,V,W,q,w,v,_]}class Rs extends he{constructor(t){super(),de(this,t,Bs,Ds,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const co=new Map([[J.RECTANGLE,xn],[J.POLYGON,Qn],[J.MULTIPOLYGON,Rs]]),uo=e=>co.get(e.type),fo=(e,t)=>co.set(e,t);function Us(e,t,n){let o;const i=Ce();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,f;return Be(()=>(n(6,f=new r({target:a,props:{shape:s.target.selector,computedStyle:o,transform:u,viewportScale:d,svgEl:a.closest("svg")}})),f.$on("change",h=>{f.$$set({shape:h.detail}),i("change",h.detail)}),f.$on("grab",h=>i("grab",h.detail)),f.$on("release",h=>i("release",h.detail)),()=>{f.$destroy()})),e.$$set=h=>{"annotation"in h&&n(0,s=h.annotation),"editor"in h&&n(1,r=h.editor),"style"in h&&n(2,l=h.style),"target"in h&&n(3,a=h.target),"transform"in h&&n(4,u=h.transform),"viewportScale"in h&&n(5,d=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,o=Ve(s,l)),e.$$.dirty&65&&s&&(f==null||f.$set({shape:s.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:u}),e.$$.dirty&96&&f&&f.$set({viewportScale:d}),e.$$.dirty&192&&f&&o&&f.$set({computedStyle:o})},[s,r,l,a,u,d,f,o]}class ho extends he{constructor(t){super(),de(this,t,Us,null,re,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Vs(e,t,n){const o=Ce();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return Be(()=>{const d=s.closest("svg"),f=[],h=(y,m,g)=>{d==null||d.addEventListener(y,m,g),f.push(()=>d==null?void 0:d.removeEventListener(y,m,g))};return n(5,u=new r({target:s,props:{addEventListener:h,drawingMode:i,transform:l,viewportScale:a}})),u.$on("create",y=>o("create",y.detail)),()=>{f.forEach(y=>y()),u.$destroy()}}),e.$$set=d=>{"drawingMode"in d&&n(0,i=d.drawingMode),"target"in d&&n(1,s=d.target),"tool"in d&&n(2,r=d.tool),"transform"in d&&n(3,l=d.transform),"viewportScale"in d&&n(4,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:l}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[i,s,r,l,a,u]}class go extends he{constructor(t){super(),de(this,t,Vs,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function mo(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),u=L("rect"),d=L("rect"),c(o,"class","rect-mask-bg svelte-1a76qe7"),c(o,"x",i=e[1]-e[5]),c(o,"y",s=e[2]-e[5]),c(o,"width",r=e[3]+2*e[5]),c(o,"height",l=e[4]+2*e[5]),c(a,"class","rect-mask-fg svelte-1a76qe7"),c(a,"x",e[1]),c(a,"y",e[2]),c(a,"width",e[3]),c(a,"height",e[4]),c(n,"id",e[6]),c(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),c(u,"class","a9s-outer"),c(u,"mask",`url(#${e[6]})`),c(u,"x",e[1]),c(u,"y",e[2]),c(u,"width",e[3]),c(u,"height",e[4]),c(d,"class","a9s-inner"),c(d,"x",e[1]),c(d,"y",e[2]),c(d,"width",e[3]),c(d,"height",e[4])},m(f,h){Y(f,t,h),F(t,n),F(n,o),F(n,a),Y(f,u,h),Y(f,d,h)},p(f,h){h&34&&i!==(i=f[1]-f[5])&&c(o,"x",i),h&36&&s!==(s=f[2]-f[5])&&c(o,"y",s),h&40&&r!==(r=f[3]+2*f[5])&&c(o,"width",r),h&48&&l!==(l=f[4]+2*f[5])&&c(o,"height",l),h&2&&c(a,"x",f[1]),h&4&&c(a,"y",f[2]),h&8&&c(a,"width",f[3]),h&16&&c(a,"height",f[4]),h&2&&c(u,"x",f[1]),h&4&&c(u,"y",f[2]),h&8&&c(u,"width",f[3]),h&16&&c(u,"height",f[4]),h&2&&c(d,"x",f[1]),h&4&&c(d,"y",f[2]),h&8&&c(d,"width",f[3]),h&16&&c(d,"height",f[4])},d(f){f&&(N(t),N(u),N(d))}}}function Xs(e){let t,n=e[0]&&mo(e);return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){Y(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=mo(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&N(t),n&&n.d()}}}function Hs(e,t,n){let o;const i=Ce();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,d,f,h,y,m,g;const k=M=>{const C=M;u=performance.now(),r==="drag"&&(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,y=d[1]),n(3,m=1),n(4,g=1))},p=M=>{const C=M;d&&(f=l.elementToImage(C.offsetX,C.offsetY),n(1,h=Math.min(f[0],d[0])),n(2,y=Math.min(f[1],d[1])),n(3,m=Math.abs(f[0]-d[0])),n(4,g=Math.abs(f[1]-d[1])))},S=M=>{const C=M,T=performance.now()-u;if(r==="click"){if(T>300)return;d?E():(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,y=d[1]),n(3,m=1),n(4,g=1))}else d&&(T>300||m*g>100?(C.stopPropagation(),E()):(n(0,d=void 0),f=void 0))},E=()=>{if(m*g>15){const M={type:J.RECTANGLE,geometry:{bounds:{minX:h,minY:y,maxX:h+m,maxY:y+g},x:h,y,w:m,h:g}};i("create",M)}n(0,d=void 0),f=void 0};Be(()=>{s("pointerdown",k),s("pointermove",p),s("pointerup",S,!0)});const A=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=M=>{"addEventListener"in M&&n(7,s=M.addEventListener),"drawingMode"in M&&n(8,r=M.drawingMode),"transform"in M&&n(9,l=M.transform),"viewportScale"in M&&n(10,a=M.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,o=2/a)},[d,h,y,m,g,o,A,s,r,l,a]}class po extends he{constructor(t){super(),de(this,t,Hs,Xs,re,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function zt(e){const t=e.slice(),n=t[2].map(o=>o.join(",")).join(" ");return t[19]=n,t}function _o(e){let t,n,o,i,s,r,l,a,u,d,f,h,y,m,g=e[1]&&yo(e);return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),d=L("polygon"),h=L("polygon"),g&&g.c(),m=ke(),c(o,"x",i=e[3].x),c(o,"y",s=e[3].y),c(o,"width",r=e[3].w),c(o,"height",l=e[3].h),c(o,"class","svelte-18wrg3t"),c(a,"points",u=e[19]),c(a,"class","svelte-18wrg3t"),c(n,"id",e[5]),c(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),c(d,"class","a9s-outer"),c(d,"mask",`url(#${e[5]})`),c(d,"points",f=e[19]),c(h,"class","a9s-inner"),c(h,"points",y=e[19])},m(k,p){Y(k,t,p),F(t,n),F(n,o),F(n,a),Y(k,d,p),Y(k,h,p),g&&g.m(k,p),Y(k,m,p)},p(k,p){p&8&&i!==(i=k[3].x)&&c(o,"x",i),p&8&&s!==(s=k[3].y)&&c(o,"y",s),p&8&&r!==(r=k[3].w)&&c(o,"width",r),p&8&&l!==(l=k[3].h)&&c(o,"height",l),p&4&&u!==(u=k[19])&&c(a,"points",u),p&4&&f!==(f=k[19])&&c(d,"points",f),p&4&&y!==(y=k[19])&&c(h,"points",y),k[1]?g?g.p(k,p):(g=yo(k),g.c(),g.m(m.parentNode,m)):g&&(g.d(1),g=null)},d(k){k&&(N(t),N(d),N(h),N(m)),g&&g.d(k)}}}function yo(e){let t,n,o;return{c(){t=L("circle"),c(t,"class","a9s-handle svelte-18wrg3t"),c(t,"cx",n=e[0][0][0]),c(t,"cy",o=e[0][0][1]),c(t,"r",e[4])},m(i,s){Y(i,t,s)},p(i,s){s&1&&n!==(n=i[0][0][0])&&c(t,"cx",n),s&1&&o!==(o=i[0][0][1])&&c(t,"cy",o),s&16&&c(t,"r",i[4])},d(i){i&&N(t)}}}function Gs(e){let t,n=e[3]&&_o(zt(e));return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){Y(o,t,i),n&&n.m(t,null)},p(o,[i]){o[3]?n?n.p(zt(o),i):(n=_o(zt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&N(t),n&&n.d()}}}const js=20,zs=1500;function Fs(e,t,n){let o,i,s;const r=Ce();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,f,h=[],y,m,g=!1;const k=C=>{const T=C,{timeStamp:V,offsetX:B,offsetY:W}=T;if(f={timeStamp:V,offsetX:B,offsetY:W},a==="drag"&&h.length===0){const q=u.elementToImage(T.offsetX,T.offsetY);h.push(q),n(10,y=q)}},p=C=>{const T=C;if(m&&clearTimeout(m),h.length>0){if(n(10,y=u.elementToImage(T.offsetX,T.offsetY)),h.length>2){const V=$e(y,h[0])*d;n(1,g=V<js)}T.pointerType==="touch"&&(m=setTimeout(()=>{E()},zs))}},S=C=>{const T=C;if(m&&clearTimeout(m),a==="click"){const V=T.timeStamp-f.timeStamp,B=$e([f.offsetX,f.offsetY],[T.offsetX,T.offsetY]);if(V>300||B>15)return;if(g)A();else if(h.length===0){const W=u.elementToImage(T.offsetX,T.offsetY);h.push(W),n(10,y=W)}else h.push(y)}else{if(h.length===1&&$e(h[0],y)<=4){n(0,h=[]),n(10,y=void 0);return}T.stopImmediatePropagation(),g?A():h.push(y)}},E=()=>{if(!y)return;const C=h.slice(0,-1);if(C.length<3)return;const T={type:J.POLYGON,geometry:{bounds:ue(h),points:C}};dt(T)>4&&(n(0,h=[]),n(10,y=void 0),r("create",T))},A=()=>{const C={type:J.POLYGON,geometry:{bounds:ue(h),points:[...h]}};n(0,h=[]),n(10,y=void 0),r("create",C)};Be(()=>{l("pointerdown",k,!0),l("pointermove",p),l("pointerup",S,!0),l("dblclick",E,!0)});const M=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=C=>{"addEventListener"in C&&n(6,l=C.addEventListener),"drawingMode"in C&&n(7,a=C.drawingMode),"transform"in C&&n(8,u=C.transform),"viewportScale"in C&&n(9,d=C.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,o=4/d),e.$$.dirty&1027&&n(2,i=y?g?h:[...h,y]:[]),e.$$.dirty&516&&n(3,s=i.length>0?ot(ue(i),2/d):void 0)},[h,g,i,s,o,M,l,a,u,d,y]}class qs extends he{constructor(t){super(),de(this,t,Fs,Gs,re,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Ft=new Map([["rectangle",{tool:po}],["polygon",{tool:qs}]]),qt=()=>[...Ft.keys()],Kt=e=>Ft.get(e),wo=(e,t,n={})=>Ft.set(e,{tool:t,opts:n});function Ks(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("ellipse"),i=L("ellipse"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"cx",e[2]),c(n,"cy",e[3]),c(n,"rx",e[4]),c(n,"ry",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"cx",e[2]),c(i,"cy",e[3]),c(i,"rx",e[4]),c(i,"ry",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function Ws(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{cx:l,cy:a,rx:u,ry:d}=s;return e.$$set=f=>{"annotation"in f&&n(0,i=f.annotation),"geom"in f&&n(6,s=f.geom),"style"in f&&n(7,r=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ve(i,r))},[i,o,l,a,u,d,s,r]}class Zs extends he{constructor(t){super(),de(this,t,Ws,Ks,re,{annotation:0,geom:6,style:7})}}function Js(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("line"),i=L("line"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"x1",e[2]),c(n,"y1",e[3]),c(n,"x2",e[4]),c(n,"y2",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"x1",e[2]),c(i,"y1",e[3]),c(i,"x2",e[4]),c(i,"y2",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function Qs(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s,[[a,u],[d,f]]=l;return e.$$set=h=>{"annotation"in h&&n(0,i=h.annotation),"geom"in h&&n(6,s=h.geom),"style"in h&&n(7,r=h.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ve(i,r))},[i,o,a,u,d,f,s,r]}class xs extends he{constructor(t){super(),de(this,t,Qs,Js,re,{annotation:0,geom:6,style:7})}}function bo(e,t,n){const o=e.slice();return o[5]=t[n],o}function Eo(e){let t,n,o;return{c(){t=L("path"),o=L("path"),c(t,"class","a9s-outer"),c(t,"style",n=e[1]?"display:none;":void 0),c(t,"fill-rule","evenodd"),c(t,"d",Pe(e[5])),c(o,"class","a9s-inner"),c(o,"style",e[1]),c(o,"fill-rule","evenodd"),c(o,"d",Pe(e[5]))},m(i,s){Y(i,t,s),Y(i,o,s)},p(i,s){s&2&&n!==(n=i[1]?"display:none;":void 0)&&c(t,"style",n),s&2&&c(o,"style",i[1])},d(i){i&&(N(t),N(o))}}}function $s(e){let t,n,o=ve(e[2]),i=[];for(let s=0;s<o.length;s+=1)i[s]=Eo(bo(e,o,s));return{c(){t=L("g");for(let s=0;s<i.length;s+=1)i[s].c();c(t,"class","a9s-annotation"),c(t,"data-id",n=e[0].id)},m(s,r){Y(s,t,r);for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(t,null)},p(s,[r]){if(r&6){o=ve(s[2]);let l;for(l=0;l<o.length;l+=1){const a=bo(s,o,l);i[l]?i[l].p(a,r):(i[l]=Eo(a),i[l].c(),i[l].m(t,null))}for(;l<i.length;l+=1)i[l].d(1);i.length=o.length}r&1&&n!==(n=s[0].id)&&c(t,"data-id",n)},i:j,o:j,d(s){s&&N(t),Ye(i,s)}}}function er(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{polygons:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ve(i,r))},[i,o,l,s,r]}class tr extends he{constructor(t){super(),de(this,t,er,$s,re,{annotation:0,geom:3,style:4})}}function nr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("polygon"),i=L("polygon"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"points",e[2].map(or).join(" ")),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"points",e[2].map(ir).join(" ")),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}const or=e=>e.join(","),ir=e=>e.join(",");function sr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ve(i,r))},[i,o,l,s,r]}class rr extends he{constructor(t){super(),de(this,t,sr,nr,re,{annotation:0,geom:3,style:4})}}function lr(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("path"),s=L("path"),c(n,"class",o=ct(`a9s-outer ${e[1]}`)+" svelte-1w0132l"),c(n,"style",i=e[3]?"display:none;":void 0),c(n,"d",e[2]),c(s,"class",r=ct(`a9s-inner ${e[1]}`)+" svelte-1w0132l"),c(s,"style",e[3]),c(s,"d",e[2]),c(t,"class","a9s-annotation"),c(t,"data-id",l=e[0].id)},m(a,u){Y(a,t,u),F(t,n),F(t,s)},p(a,[u]){u&2&&o!==(o=ct(`a9s-outer ${a[1]}`)+" svelte-1w0132l")&&c(n,"class",o),u&8&&i!==(i=a[3]?"display:none;":void 0)&&c(n,"style",i),u&4&&c(n,"d",a[2]),u&2&&r!==(r=ct(`a9s-inner ${a[1]}`)+" svelte-1w0132l")&&c(s,"class",r),u&8&&c(s,"style",a[3]),u&4&&c(s,"d",a[2]),u&1&&l!==(l=a[0].id)&&c(t,"data-id",l)},i:j,o:j,d(a){a&&N(t)}}}function ar(e,t,n){let o,i,s,{annotation:r}=t,{geom:l}=t,{style:a}=t;return e.$$set=u=>{"annotation"in u&&n(0,r=u.annotation),"geom"in u&&n(4,l=u.geom),"style"in u&&n(5,a=u.style)},e.$$.update=()=>{e.$$.dirty&33&&n(3,o=Ve(r,a)),e.$$.dirty&16&&n(2,i=It(l)),e.$$.dirty&16&&n(1,s=l.closed?"closed":"open")},[r,s,i,o,l,a]}class cr extends he{constructor(t){super(),de(this,t,ar,lr,re,{annotation:0,geom:4,style:5})}}function ur(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("rect"),i=L("rect"),c(n,"class","a9s-outer"),c(n,"style",o=e[5]?"display:none;":void 0),c(n,"x",e[4]),c(n,"y",e[3]),c(n,"width",e[2]),c(n,"height",e[1]),c(i,"class","a9s-inner"),c(i,"style",e[5]),c(i,"x",e[4]),c(i,"y",e[3]),c(i,"width",e[2]),c(i,"height",e[1]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&32&&o!==(o=r[5]?"display:none;":void 0)&&c(n,"style",o),l&16&&c(n,"x",r[4]),l&8&&c(n,"y",r[3]),l&4&&c(n,"width",r[2]),l&2&&c(n,"height",r[1]),l&32&&c(i,"style",r[5]),l&16&&c(i,"x",r[4]),l&8&&c(i,"y",r[3]),l&4&&c(i,"width",r[2]),l&2&&c(i,"height",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function fr(e,t,n){let o,i,s,r,l,{annotation:a}=t,{geom:u}=t,{style:d}=t;return e.$$set=f=>{"annotation"in f&&n(0,a=f.annotation),"geom"in f&&n(6,u=f.geom),"style"in f&&n(7,d=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=Ve(a,d)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:l}=u,i,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,l),n(6,u)))},[a,l,r,s,i,o,u,d]}class dr extends he{constructor(t){super(),de(this,t,fr,ur,re,{annotation:0,geom:6,style:7})}}const hr={elementToImage:(e,t)=>[e,t]},vo=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),gr=250,So=(e,t)=>{const n=Ce();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<gr){const{x:a,y:u}=Wt(r,e),d=t.getAt(a,u,void 0,2);d?n("click",{originalEvent:r,annotation:d}):n("click",{originalEvent:r})}}}},Wt=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=i+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function Ao(e,t,n){const o=e.slice();return o[39]=t[n],o}function ko(e,t,n){const o=e.slice();return o[42]=t[n],o}function Zt(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Mo(e){let t=e[42],n,o,i=To(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&131072&&re(t,t=s[42])?(be(),G(i,1,1,j),Ee(),i=To(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function mr(e){let t,n;return t=new xs({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function pr(e){let t,n;return t=new cr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function _r(e){let t,n;return t=new tr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function yr(e){let t,n;return t=new rr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function wr(e){let t,n;return t=new dr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function br(e){var o;let t,n;return t=new Zs({props:{annotation:e[42],geom:(o=e[45])==null?void 0:o.geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){var l;const r={};s[0]&131072&&(r.annotation=i[42]),s[0]&131072&&(r.geom=(l=i[45])==null?void 0:l.geometry),s[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(U(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function To(e){let t,n,o,i;const s=[br,wr,yr,_r,pr,mr],r=[];function l(a,u){var d,f,h,y,m,g;return((d=a[45])==null?void 0:d.type)===J.ELLIPSE?0:((f=a[45])==null?void 0:f.type)===J.RECTANGLE?1:((h=a[45])==null?void 0:h.type)===J.POLYGON?2:((y=a[45])==null?void 0:y.type)===J.MULTIPOLYGON?3:((m=a[45])==null?void 0:m.type)===J.POLYLINE?4:((g=a[45])==null?void 0:g.type)===J.LINE?5:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),Y(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){G(n),i=!1},d(a){a&&N(o),~t&&r[t].d(a)}}}function Po(e){let t=tt(e[42])&&!e[10](e[42]),n,o,i=t&&Mo(Zt(e));return{c(){i&&i.c(),n=ke()},m(s,r){i&&i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&132096&&(t=tt(s[42])&&!s[10](s[42])),t?i?(i.p(Zt(s),r),r[0]&132096&&U(i,1)):(i=Mo(Zt(s)),i.c(),U(i,1),i.m(n.parentNode,n)):i&&(be(),G(i,1,1,()=>{i=null}),Ee())},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i&&i.d(s)}}}function Lo(e){let t,n,o,i;const s=[vr,Er],r=[];function l(a,u){return a[6]?0:a[15]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),Y(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){G(n),i=!1},d(a){a&&N(o),~t&&r[t].d(a)}}}function Er(e){let t=`${e[2]}-${e[7]}`,n,o,i=Io(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&132&&re(t,t=`${s[2]}-${s[7]}`)?(be(),G(i,1,1,j),Ee(),i=Io(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function vr(e){let t,n,o=ve(e[6]),i=[];for(let r=0;r<o.length;r+=1)i[r]=Oo(Ao(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);Y(r,t,l),n=!0},p(r,l){if(l[0]&8659266){o=ve(r[6]);let a;for(a=0;a<o.length;a+=1){const u=Ao(r,o,a);i[a]?(i[a].p(u,l),U(i[a],1)):(i[a]=Oo(u),i[a].c(),U(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)U(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&N(t),Ye(i,r)}}}function Io(e){let t,n;return t=new go({props:{target:e[8],tool:e[15],drawingMode:e[14],transform:e[13],viewportScale:e[18]}}),t.$on("create",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&256&&(s.target=o[8]),i[0]&32768&&(s.tool=o[15]),i[0]&16384&&(s.drawingMode=o[14]),i[0]&8192&&(s.transform=o[13]),i[0]&262144&&(s.viewportScale=o[18]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Co(e){let t,n;return t=new ho({props:{target:e[8],editor:e[39].editor,annotation:e[39].annotation,style:e[1],transform:e[13],viewportScale:e[18]}}),t.$on("change",function(){ie(e[23](e[39].annotation))&&e[23](e[39].annotation).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&256&&(s.target=e[8]),i[0]&64&&(s.editor=e[39].editor),i[0]&64&&(s.annotation=e[39].annotation),i[0]&2&&(s.style=e[1]),i[0]&8192&&(s.transform=e[13]),i[0]&262144&&(s.viewportScale=e[18]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Oo(e){let t=e[39].annotation.id,n,o,i=Co(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&64&&re(t,t=s[39].annotation.id)?(be(),G(i,1,1,j),Ee(),i=Co(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function Sr(e){let t,n,o,i,s,r,l=ve(e[17].filter(e[34])),a=[];for(let f=0;f<l.length;f+=1)a[f]=Po(ko(e,l,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&Lo(e);return{c(){t=L("svg"),n=L("g");for(let f=0;f<a.length;f+=1)a[f].c();o=L("g"),d&&d.c(),c(o,"class","drawing"),c(t,"role","application"),c(t,"tabindex",0),c(t,"class","a9s-annotationlayer"),Te(t,"drawing",e[15]),Te(t,"editing",e[5]),Te(t,"hidden",!e[3]),Te(t,"hover",e[16])},m(f,h){Y(f,t,h),F(t,n);for(let y=0;y<a.length;y+=1)a[y]&&a[y].m(n,null);F(t,o),d&&d.m(o,null),e[35](o),e[36](t),i=!0,s||(r=[ee(t,"pointerup",function(){ie(e[11])&&e[11].apply(this,arguments)}),ee(t,"pointerdown",function(){ie(e[12])&&e[12].apply(this,arguments)}),ee(t,"pointermove",e[24])],s=!0)},p(f,h){if(e=f,h[0]&132098){l=ve(e[17].filter(e[34]));let y;for(y=0;y<l.length;y+=1){const m=ko(e,l,y);a[y]?(a[y].p(m,h),U(a[y],1)):(a[y]=Po(m),a[y].c(),U(a[y],1),a[y].m(n,null))}for(be(),y=l.length;y<a.length;y+=1)u(y);Ee()}e[8]?d?(d.p(e,h),h[0]&256&&U(d,1)):(d=Lo(e),d.c(),U(d,1),d.m(o,null)):d&&(be(),G(d,1,1,()=>{d=null}),Ee()),(!i||h[0]&32768)&&Te(t,"drawing",e[15]),(!i||h[0]&32)&&Te(t,"editing",e[5]),(!i||h[0]&8)&&Te(t,"hidden",!e[3]),(!i||h[0]&65536)&&Te(t,"hover",e[16])},i(f){if(!i){for(let h=0;h<l.length;h+=1)U(a[h]);U(d),i=!0}},o(f){a=a.filter(Boolean);for(let h=0;h<a.length;h+=1)G(a[h]);G(d),i=!1},d(f){f&&N(t),Ye(a,f),d&&d.d(),e[35](null),e[36](null),s=!1,Ae(r)}}}function Ar(e,t,n){let o,i,s,r,l,a,u,d,f,h,y,m,g=j,k=()=>(g(),g=rn(b,X=>n(18,m=X)),b);e.$$.on_destroy.push(()=>g());let{drawingEnabled:p}=t,{image:S}=t,{preferredDrawingMode:E}=t,{state:A}=t,{style:M=void 0}=t,{toolName:C=qt()[0]}=t,{user:T}=t,{visible:V=!0}=t,B=0;const W=()=>n(7,B+=1),q=()=>C,w=()=>p;let v,_,b;Be(()=>k(n(9,b=Vn(S,_))));const{hover:I,selection:P,store:O}=A;At(e,I,X=>n(16,f=X)),At(e,P,X=>n(33,h=X)),At(e,O,X=>n(17,y=X));let z,H;const Q=X=>{z&&O.unobserve(z);const fe=X.filter(({editable:te})=>te).map(({id:te})=>te);fe.length>0?(n(5,H=fe.map(te=>O.getAnnotation(te)).filter(te=>te&&tt(te))),z=te=>{const{updated:pe}=te.changes;n(5,H=pe==null?void 0:pe.map(ye=>ye.newValue))},O.observe(z,{annotations:fe})):n(5,H=void 0)},Z=X=>{const fe=Cn(),te={id:fe,bodies:[],target:{annotation:fe,selector:X.detail,creator:T,created:new Date}};O.addAnnotation(te),P.setSelected(te.id)},x=X=>fe=>{var We;const{target:te}=X,pe=10*60*1e3,ye=((We=te.creator)==null?void 0:We.id)!==T.id||!te.created||new Date().getTime()-te.created.getTime()>pe;O.updateTarget({...te,selector:fe.detail,created:ye?te.created:new Date,updated:ye?new Date:void 0,updatedBy:ye?T:void 0})},oe=X=>{const{x:fe,y:te}=Wt(X,_),pe=O.getAt(fe,te,void 0,2);pe?f!==pe.id&&I.set(pe.id):I.set(void 0)},se=X=>tt(X);function Se(X){ut[X?"unshift":"push"](()=>{v=X,n(8,v)})}function Me(X){ut[X?"unshift":"push"](()=>{_=X,n(4,_)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,p=X.drawingEnabled),"image"in X&&n(25,S=X.image),"preferredDrawingMode"in X&&n(26,E=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,M=X.style),"toolName"in X&&n(2,C=X.toolName),"user"in X&&n(28,T=X.user),"visible"in X&&n(3,V=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:o,opts:i}=Kt(C)||{tool:void 0,opts:void 0},o,(n(32,i),n(2,C))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(14,s=(i==null?void 0:i.drawingMode)||E),e.$$.dirty[0]&16&&n(13,r=vo(_)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=So(_,O),l,(n(11,a),n(4,_))),e.$$.dirty[1]&4&&Q(h.selected),e.$$.dirty[0]&32&&n(6,u=H?H.map(X=>({annotation:X,editor:uo(X.target.selector)})).filter(X=>X.editor):void 0),e.$$.dirty[0]&64&&n(10,d=X=>u&&u.some(fe=>fe.annotation.id===X.id))},[p,M,C,V,_,H,u,B,v,b,d,a,l,r,s,o,f,y,m,I,P,O,Z,x,oe,S,E,A,T,W,q,w,i,h,se,Se,Me]}class Do extends he{constructor(t){super(),de(this,t,Ar,Sr,re,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function No(e,t,n=0,o=e.length-1,i=kr){for(;o>n;){if(o-n>600){const a=o-n+1,u=t-n+1,d=Math.log(a),f=.5*Math.exp(2*d/3),h=.5*Math.sqrt(d*f*(a-f)/a)*(u-a/2<0?-1:1),y=Math.max(n,Math.floor(t-u*f/a+h)),m=Math.min(o,Math.floor(t+(a-u)*f/a+h));No(e,t,y,m,i)}const s=e[t];let r=n,l=o;for(rt(e,n,t),i(e[o],s)>0&&rt(e,n,o);r<l;){for(rt(e,r,l),r++,l--;i(e[r],s)<0;)r++;for(;i(e[l],s)>0;)l--}i(e[n],s)===0?rt(e,n,l):(l++,rt(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function rt(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function kr(e,t){return e<t?-1:e>t?1:0}class Mr{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!wt(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?i(l):l;wt(t,a)&&(n.leaf?o.push(l):Qt(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!wt(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(wt(t,r)){if(n.leaf||Qt(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Ke([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let l,a,u;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],l=r.pop(),u=!0),o.leaf){const d=Tr(t,o.children,n);if(d!==-1)return o.children.splice(d,1),s.push(o),this._condense(s),this}!u&&!o.leaf&&Qt(o,i)?(s.push(o),r.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],u=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,l;if(s<=r)return l=Ke(t.slice(n,o+1)),qe(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=Ke([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));Yo(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);Yo(t,d,f,a,this.compareMinY);for(let h=d;h<=f;h+=a){const y=Math.min(h+a-1,f);l.children.push(this._build(t,h,y,i-1))}}return qe(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const u=n.children[a],d=Jt(u),f=Ir(t,u)-d;f<r?(r=f,s=d<s?d:s,l=u):f===r&&d<s&&(s=d,l=u)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),at(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),l=Ke(o.children.splice(r,o.children.length-r));l.height=o.height,l.leaf=o.leaf,qe(o,this.toBBox),qe(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=Ke([t,n]),this.data.height=t.height+1,this.data.leaf=!1,qe(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let l=n;l<=o-n;l++){const a=lt(t,0,l,this.toBBox),u=lt(t,l,o,this.toBBox),d=Cr(a,u),f=Jt(a)+Jt(u);d<s?(s=d,i=l,r=f<r?f:r):d===s&&f<r&&(r=f,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Pr,s=t.leaf?this.compareMinY:Lr,r=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,s);r<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=lt(t,0,n,s),l=lt(t,o-n,o,s);let a=yt(r)+yt(l);for(let u=n;u<o-n;u++){const d=t.children[u];at(r,t.leaf?s(d):d),a+=yt(r)}for(let u=o-n-1;u>=n;u--){const d=t.children[u];at(l,t.leaf?s(d):d),a+=yt(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)at(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():qe(t[n],this.toBBox)}}function Tr(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function qe(e,t){lt(e,0,e.children.length,t,e)}function lt(e,t,n,o,i){i||(i=Ke(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];at(i,e.leaf?o(r):r)}return i}function at(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 Pr(e,t){return e.minX-t.minX}function Lr(e,t){return e.minY-t.minY}function Jt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function yt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Ir(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 Cr(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function Qt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function wt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ke(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Yo(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;No(e,r,t,n,i),s.push(t,r,r,n)}}const Or=()=>{const e=new Mr,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!nt(f))return;const{minX:h,minY:y,maxX:m,maxY:g}=f.selector.geometry.bounds,k={minX:h,minY:y,maxX:m,maxY:g,target:f};e.insert(k),t.set(f.annotation,k)},s=f=>{if(!nt(f))return;const h=t.get(f.annotation);h&&e.remove(h),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,h,y,m=0)=>{const k=e.search({minX:f-m,minY:h-m,maxX:f+m,maxY:h+m}).map(p=>p.target).filter(p=>p.selector.type===J.RECTANGLE||_n(p.selector,f,h,m));return k.length>0?(k.sort((p,S)=>dt(p.selector)-dt(S.selector)),k):[]},getIntersecting:(f,h,y,m)=>e.search({minX:f,minY:h,maxX:f+y,maxY:h+m}).map(g=>g.target),insert:i,remove:s,set:(f,h=!0)=>{h&&o();const y=f.reduce((m,g)=>{if(nt(g)){const{minX:k,minY:p,maxX:S,maxY:E}=g.selector.geometry.bounds;return[...m,{minX:k,minY:p,maxX:S,maxY:E,target:g}]}else return m},[]);y.forEach(m=>t.set(m.target.annotation,m)),e.load(y)},size:()=>e.all().length,update:(f,h)=>{s(f),i(h)}}},Bo=e=>{const t=Vi(),n=Or(),o=ki(t,e.userSelectAction,e.adapter),i=Ai(t),s=zi();return t.observe(({changes:a})=>{n.set((a.created||[]).map(u=>u.target),!1),(a.deleted||[]).forEach(u=>n.remove(u.target)),(a.updated||[]).forEach(({oldValue:u,newValue:d})=>n.update(u.target,d.target))}),{store:{...t,getAt:(a,u,d,f)=>{const h=n.getAt(a,u,d,f);if(d)return h.map(m=>t.getAnnotation(m.annotation)).filter(Boolean).filter(d)[0];{const y=h[0];return y?t.getAnnotation(y.annotation):void 0}},getIntersecting:(a,u,d,f)=>n.getIntersecting(a,u,d,f).map(h=>t.getAnnotation(h.annotation)).filter(Boolean)},selection:o,hover:i,viewport:s}},Ro=e=>{const t=Bo(e);return{...t,store:Xi(t.store)}},Uo=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(r,l,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=u}return o/81},Vo=e=>{const t=Uo(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"?Vo(e):n),Xo=(e,t)=>({...e,drawingEnabled:e.drawingEnabled===void 0?t.drawingEnabled:e.drawingEnabled,drawingMode:e.drawingMode||t.drawingMode,userSelectAction:e.userSelectAction||t.userSelectAction,theme:e.theme||t.theme}),$t=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Ho=(e,t)=>{const n=t||document,o=r=>{const l=r;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},i=r=>{const l=r;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},s=()=>{$t?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return $t?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Dr=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=Xo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Nt.EDIT,theme:"light"}),i=Ro(o),{selection:s,store:r}=i,l=ji(r,o.initialHistory),a=Fi(i,l,o.adapter,o.autoSave),u=document.createElement("DIV");u.style.position="relative",u.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(u,n),u.appendChild(n);const d=Ho(l);let f=ts();xt(n,u,o.theme);const h=new Do({target:u,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});h.$on("click",w=>{const{originalEvent:v,annotation:_}=w.detail;_?s.userSelect(_.id,v):s.isEmpty()||s.clear()});const y=Ki(i,l,o.adapter),m=()=>h.cancelDrawing(),g=()=>{h.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),l.destroy()},k=()=>h.getDrawingTool(),p=()=>f,S=()=>h.isDrawingEnabled(),E=(w,v,_)=>wo(w,v,_),A=(w,v)=>fo(w,v),M=w=>{if(!Kt(w))throw`No drawing tool named ${w}`;h.$set({toolName:w})},C=w=>h.$set({drawingEnabled:w}),T=w=>{console.warn("Filter not implemented yet")},V=w=>h.$set({style:w}),B=w=>xt(n,u,w),W=w=>{f=w,h.$set({user:w})},q=w=>h.$set({visible:w});return{...y,cancelDrawing:m,destroy:g,getDrawingTool:k,getUser:p,isDrawingEnabled:S,listDrawingTools:qt,on:a.on,off:a.off,registerDrawingTool:E,registerShapeEditor:A,setDrawingEnabled:C,setDrawingTool:M,setFilter:T,setStyle:V,setTheme:B,setUser:W,setVisible:q,element:u,state:i}};D.Editor=_t,D.EditorMount=ho,D.Handle=Xe,D.IdentityTransform=hr,D.PolygonEditor=Qn,D.RectangleEditor=xn,D.RectangleUtil=vn,D.RubberbandRectangle=po,D.SVGAnnotationLayer=Do,D.ShapeType=J,D.ToolMount=go,D.UserSelectAction=Nt,D.W3CImageFormat=ls,D.addEventListeners=So,D.approximateAsPolygon=ht,D.boundsFromMultiPolygonElements=et,D.boundsFromPoints=ue,D.chainStyles=Zi,D.computeArea=dt,D.computePolygonArea=Qe,D.computeSVGPath=It,D.computeStyle=Wi,D.createBody=Ci,D.createImageAnnotator=Dr,D.createImageAnnotatorState=Bo,D.createSVGTransform=vo,D.createSvelteImageAnnotatorState=Ro,D.defaultColorProvider=rs,D.detectTheme=Vo,D.distance=$e,D.enableResponsive=Vn,D.fillDefaults=Xo,D.getAllCorners=wn,D.getEditor=uo,D.getMaskDimensions=ot,D.getSVGPoint=Wt,D.getTool=Kt,D.initKeyboardCommands=Ho,D.intersects=_n,D.isImageAnnotation=tt,D.isImageAnnotationTarget=nt,D.isMac=$t,D.isPointInPolygon=xe,D.isTouch=Le,D.listDrawingTools=qt,D.multipolygonElementToPath=Pe,D.parseFragmentSelector=Sn,D.parseSVGSelector=Pn,D.parseW3CImageAnnotation=Rn,D.pointsToPath=yn,D.registerEditor=fo,D.registerShapeUtil=Ue,D.registerTool=wo,D.sampleBrightness=Uo,D.serializeFragmentSelector=An,D.serializeSVGSelector=Ln,D.serializeW3CImageAnnotation=Un,D.setTheme=xt,D.simplifyMultiPolygon=ri,D.simplifyPoints=Lt,D.simplifyPolygon=ai,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(D,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(D=typeof globalThis<"u"?globalThis:D||self,j(D.Annotorious={}))})(this,function(D){"use strict";var Yr=Object.defineProperty;var Br=(D,j,Ie)=>j in D?Yr(D,j,{enumerable:!0,configurable:!0,writable:!0,value:Ie}):D[j]=Ie;var nn=(D,j,Ie)=>Br(D,typeof j!="symbol"?j+"":j,Ie);function j(){}function Ie(e,t){for(const n in t)e[n]=t[n];return e}function on(e){return e()}function sn(){return Object.create(null)}function Ae(e){e.forEach(on)}function ie(e){return typeof e=="function"}function re(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function jo(e){return Object.keys(e).length===0}function rn(e,...t){if(e==null){for(const o of t)o(void 0);return j}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function At(e,t,n){e.$$.on_destroy.push(rn(t,n))}function zo(e,t,n,o){if(e){const i=ln(e,t,n,o);return e[0](i)}}function ln(e,t,n,o){return e[1]&&o?Ie(n.ctx.slice(),e[1](o(t))):n.ctx}function Fo(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let l=0;l<r;l+=1)s[l]=t.dirty[l]|i[l];return s}return t.dirty|i}return t.dirty}function qo(e,t,n,o,i,s){if(i){const r=ln(t,n,o,s);e.p(r,i)}}function Ko(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function an(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function ct(e){return e??""}function F(e,t){e.appendChild(t)}function Y(e,t,n){e.insertBefore(t,n||null)}function N(e){e.parentNode&&e.parentNode.removeChild(e)}function Ye(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function L(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function cn(e){return document.createTextNode(e)}function we(){return cn(" ")}function ke(){return cn("")}function Q(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function c(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Wo(e){return Array.from(e.childNodes)}function Te(e,t,n){e.classList.toggle(t,!!n)}function Zo(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Ze;function Je(e){Ze=e}function un(){if(!Ze)throw new Error("Function called outside component initialization");return Ze}function Be(e){un().$$.on_mount.push(e)}function Ce(){const e=un();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Zo(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function de(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const He=[],ut=[];let Ge=[];const fn=[],dn=Promise.resolve();let kt=!1;function hn(){kt||(kt=!0,dn.then(mn))}function gn(){return hn(),dn}function Mt(e){Ge.push(e)}const Tt=new Set;let je=0;function mn(){if(je!==0)return;const e=Ze;do{try{for(;je<He.length;){const t=He[je];je++,Je(t),Jo(t.$$)}}catch(t){throw He.length=0,je=0,t}for(Je(null),He.length=0,je=0;ut.length;)ut.pop()();for(let t=0;t<Ge.length;t+=1){const n=Ge[t];Tt.has(n)||(Tt.add(n),n())}Ge.length=0}while(He.length);for(;fn.length;)fn.pop()();kt=!1,Tt.clear(),Je(e)}function Jo(e){if(e.fragment!==null){e.update(),Ae(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Mt)}}function Qo(e){const t=[],n=[];Ge.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),Ge=t}const ft=new Set;let Re;function be(){Re={r:0,c:[],p:Re}}function Ee(){Re.r||Ae(Re.c),Re=Re.p}function U(e,t){e&&e.i&&(ft.delete(e),e.i(t))}function G(e,t,n,o){if(e&&e.o){if(ft.has(e))return;ft.add(e),Re.c.push(()=>{ft.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ve(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ce(e){e&&e.c()}function le(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),Mt(()=>{const s=e.$$.on_mount.map(on).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ae(s),e.$$.on_mount=[]}),i.forEach(Mt)}function ae(e,t){const n=e.$$;n.fragment!==null&&(Qo(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function xo(e,t){e.$$.dirty[0]===-1&&(He.push(e),hn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function he(e,t,n,o,i,s,r=null,l=[-1]){const a=Ze;Je(e);const u=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:i,bound:sn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:sn(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(u.root);let d=!1;if(u.ctx=n?n(e,t.props||{},(f,h,..._)=>{const m=_.length?_[0]:h;return u.ctx&&i(u.ctx[f],u.ctx[f]=m)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](m),d&&xo(e,f)),h}):[],u.update(),d=!0,Ae(u.before_update),u.fragment=o?o(u.ctx):!1,t.target){if(t.hydrate){const f=Wo(t.target);u.fragment&&u.fragment.l(f),f.forEach(N)}else u.fragment&&u.fragment.c();t.intro&&U(e.$$.fragment),le(e,t.target,t.anchor),mn()}Je(a)}class ge{constructor(){nn(this,"$$");nn(this,"$$set")}$destroy(){ae(this,1),this.$destroy=j}$on(t,n){if(!ie(n))return j;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!jo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $o="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($o);var J=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(J||{});function ei(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var pn={exports:{}};(function(e){(function(){function t(l,a){var u=l.x-a.x,d=l.y-a.y;return u*u+d*d}function n(l,a,u){var d=a.x,f=a.y,h=u.x-d,_=u.y-f;if(h!==0||_!==0){var m=((l.x-d)*h+(l.y-f)*_)/(h*h+_*_);m>1?(d=u.x,f=u.y):m>0&&(d+=h*m,f+=_*m)}return h=l.x-d,_=l.y-f,h*h+_*_}function o(l,a){for(var u=l[0],d=[u],f,h=1,_=l.length;h<_;h++)f=l[h],t(f,u)>a&&(d.push(f),u=f);return u!==f&&d.push(f),d}function i(l,a,u,d,f){for(var h=d,_,m=a+1;m<u;m++){var g=n(l[m],l[a],l[u]);g>h&&(_=m,h=g)}h>d&&(_-a>1&&i(l,a,_,d,f),f.push(l[_]),u-_>1&&i(l,_,u,d,f))}function s(l,a){var u=l.length-1,d=[l[0]];return i(l,0,u,a,d),d.push(l[u]),d}function r(l,a,u){if(l.length<=2)return l;var d=a!==void 0?a*a:1;return l=u?l:o(l,d),l=s(l,d),l}e.exports=r,e.exports.default=r})()})(pn);var ti=pn.exports;const ni=ei(ti),Pt={},Ue=(e,t)=>Pt[e]=t,dt=e=>Pt[e.type].area(e),_n=(e,t,n,o)=>Pt[e.type].intersects(e,t,n,o),ue=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},Qe=e=>{let t=0,n=e.length-1;for(let o=0;o<e.length;o++)t+=(e[n][0]+e[o][0])*(e[n][1]-e[o][1]),n=o;return Math.abs(.5*t)},xe=(e,t,n)=>{let o=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const r=e[i][0],l=e[i][1],a=e[s][0],u=e[s][1];l>n!=u>n&&t<(a-r)*(n-l)/(u-l)+r&&(o=!o)}return o},yn=(e,t=!0)=>{let n="M ";return e.forEach(([o,i],s)=>{s===0?n+=`${o},${i}`:n+=` L ${o},${i}`}),t&&(n+=" Z"),n},Lt=(e,t=1)=>{const n=e.map(([o,i])=>({x:o,y:i}));return ni(n,t,!0).map(o=>[o.x,o.y])},$e=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},oi={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,l=0,a=Math.cos(l),u=Math.sin(l),d=t-o,f=n-i,h=a*d+u*f,_=u*d-a*f;return h*h/(s*s)+_*_/(r*r)<=1}};Ue(J.ELLIPSE,oi);const ii={area:e=>0,intersects:(e,t,n,o=2)=>{const[[i,s],[r,l]]=e.geometry.points,a=Math.abs((l-s)*t-(r-i)*n+r*s-l*i),u=$e([i,s],[r,l]);return a/u<=o}};Ue(J.LINE,ii);const si={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,o)=>{const[i,...s]=o.rings,r=Qe(i.points),l=s.reduce((a,u)=>a+Qe(u.points),0);return n+r-l},0)},intersects:(e,t,n)=>{const{polygons:o}=e.geometry;for(const i of o){const[s,...r]=i.rings;if(xe(s.points,t,n)){let l=!1;for(const a of r)if(xe(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},et=e=>{const t=e.reduce((n,o)=>[...n,...o.rings[0].points],[]);return ue(t)},Pe=e=>e.rings.map(n=>yn(n.points)).join(" "),wn=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((o,i)=>[...o,...i.points],[])],[]),ri=(e,t=1)=>{const n=e.geometry.polygons.map(i=>{const s=i.rings.map(l=>{const a=Lt(l.points,t);return{...l,points:a}}),r=ue(s[0].points);return{...i,rings:s,bounds:r}}),o=et(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:o}}};Ue(J.MULTIPOLYGON,si);const li={area:e=>{const t=e.geometry.points;return Qe(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return xe(o,t,n)}},ai=(e,t=1)=>{const n=Lt(e.geometry.points,t),o=ue(n);return{...e,geometry:{...e.geometry,bounds:o,points:n}}};Ue(J.POLYGON,li);const ci={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=ht(t.points,t.closed);return Qe(n)},intersects:(e,t,n,o=2)=>{const i=e.geometry;if(i.closed){const s=ht(i.points,i.closed);return xe(s,t,n)}else return ui(i,[t,n],o)}},ht=(e,t=!1)=>{const n=[];for(let o=0;o<e.length;o++){const i=e[o],s=e[(o+1)%e.length];if(n.push(i.point),(o<e.length-1||t)&&(i.outHandle||s.inHandle)){const l=bn(i.point,i.outHandle||i.point,s.inHandle||s.point,s.point,10);n.push(...l.slice(1))}}return n},bn=(e,t,n,o,i=10)=>{const s=[];for(let r=0;r<=i;r++){const l=r/i,a=Math.pow(1-l,3)*e[0]+3*Math.pow(1-l,2)*l*t[0]+3*(1-l)*Math.pow(l,2)*n[0]+Math.pow(l,3)*o[0],u=Math.pow(1-l,3)*e[1]+3*Math.pow(1-l,2)*l*t[1]+3*(1-l)*Math.pow(l,2)*n[1]+Math.pow(l,3)*o[1];s.push([a,u])}return s},ui=(e,t,n)=>{for(let o=0;o<e.points.length-1;o++){const i=e.points[o],s=e.points[o+1];if(i.outHandle||s.inHandle){const l=bn(i.point,i.outHandle||i.point,s.inHandle||s.point,s.point,20);for(let a=0;a<l.length-1;a++)if(En(t,l[a],l[a+1])<=n)return!0}else if(En(t,i.point,s.point)<=n)return!0}return!1},En=(e,t,n)=>{const[o,i]=e,[s,r]=t,[l,a]=n,u=l-s,d=a-r,f=Math.sqrt(u*u+d*d);if(f===0)return Math.sqrt((o-s)*(o-s)+(i-r)*(i-r));const h=((o-s)*u+(i-r)*d)/(f*f);return h<=0?Math.sqrt((o-s)*(o-s)+(i-r)*(i-r)):h>=1?Math.sqrt((o-l)*(o-l)+(i-a)*(i-a)):Math.abs((a-r)*o-(l-s)*i+l*r-a*s)/f},It=e=>{if(!e.points||e.points.length===0)return"";const t=[],n=e.points[0];t.push(`M ${n.point[0]} ${n.point[1]}`);for(let o=1;o<e.points.length;o++){const i=e.points[o],s=e.points[o-1];if(i.type==="CURVE"||s.type==="CURVE"){const r=s.type==="CURVE"&&s.outHandle||s.point,l=i.type==="CURVE"&&i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}else t.push(`L ${i.point[0]} ${i.point[1]}`)}if(e.closed){const o=e.points[e.points.length-1],i=e.points[0];if(o.outHandle||i.inHandle){const r=o.outHandle||o.point,l=i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Ue(J.POLYLINE,ci);const vn={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};Ue(J.RECTANGLE,vn);const tt=e=>nt(e.target),nt=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},Sn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[s,r,l,a,u,d,f]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[h,_,m,g]=[a,u,d,f].map(parseFloat);return{type:J.RECTANGLE,geometry:{x:h,y:_,w:m,h:g,bounds:{minX:h,minY:t?_-g:_,maxX:h+m,maxY:t?_:_+g}}}},An=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},kn="http://www.w3.org/2000/svg",Mn=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},fi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${kn}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},gt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(kn),i=n.lookupNamespaceURI(null);return o||i?Mn(n).firstChild:Mn(fi(n)).firstChild},di=e=>{const t=Tn(e),n=[];let o=[],i=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":o.length>0&&(n.push({points:o}),o=[]),i=[s.args[0],s.args[1]],o.push([...i]);break;case"L":i=[s.args[0],s.args[1]],o.push([...i]);break;case"H":i=[s.args[0],i[1]],o.push([...i]);break;case"V":i=[i[0],s.args[0]],o.push([...i]);break;case"C":i=[s.args[4],s.args[5]],o.push([...i]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(o.length>2&&n.push({points:o}),n.length>0){const s=ue(n[0].points);return{rings:n,bounds:s}}},hi=e=>{const{point:t,inHandle:n,outHandle:o}=e;if(!n||!o)return!1;const i=n[0]-t[0],s=n[1]-t[1],r=o[0]-t[0],l=o[1]-t[1],a=i*l-s*r;return Math.abs(a)<.01},gi=e=>{const t=Tn(e);let n=[],o=[0,0],i=!1;for(let r=0;r<t.length;r++){const l=t[r];switch(l.type.toUpperCase()){case"M":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"L":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"C":const a=[l.args[0],l.args[1]],u=[l.args[2],l.args[3]],d=[l.args[4],l.args[5]];if(n.length>0){const h=n[n.length-1];(a[0]!==h.point[0]||a[1]!==h.point[1])&&(h.type="CURVE",h.outHandle=a)}const f={type:u[0]!==d[0]||u[1]!==d[1]?"CURVE":"CORNER",point:d};f.type==="CURVE"&&(f.inHandle=u),n.push(f),o=d;break;case"Z":i=!0;break;default:console.warn(`Unsupported SVG path command: ${l.type}`);break}}n=n.map(r=>hi(r)?{...r,locked:!0}:r);const s=ue(ht(n,i));return{points:n,closed:i,bounds:s}},Tn=e=>{const t=[],n=e.replace(/,/g," ").trim(),o=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let i;for(;(i=o.exec(n))!==null;){const[,s,r]=i,l=r.trim()===""?[]:r.trim().split(/\s+/).map(Number).filter(a=>!isNaN(a));t.push({type:s,args:l})}return t},mi=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:J.POLYGON,geometry:{points:i,bounds:ue(i)}}},pi=e=>{const t=gt(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:J.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},_i=e=>{const t=gt(e),n=parseFloat(t.getAttribute("x1")),o=parseFloat(t.getAttribute("x2")),i=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),r={minX:Math.min(n,o),minY:Math.min(i,s),maxX:Math.max(n,o),maxY:Math.max(i,s)};return{type:J.LINE,geometry:{points:[[n,i],[o,s]],bounds:r}}},yi=e=>{const t=gt(e),n=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],o=n==null?void 0:n.getAttribute("d");if(!o)throw new Error("Could not parse SVG path");const i=gi(o);if(!i)throw new Error("Could not parse SVG path");return{type:J.POLYLINE,geometry:i}},wi=e=>{const t=gt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>di(a)).filter(Boolean),s=i.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=ue(s);return i.length===1&&i[0].rings.length===1?{type:J.POLYGON,geometry:{points:s,bounds:r}}:{type:J.MULTIPOLYGON,geometry:{polygons:i,bounds:r}}},Pn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return mi(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return yi(t);if(t.includes("<path "))return wi(t);if(t.includes("<ellipse "))return pi(t);if(t.includes("<line "))return _i(t);throw"Unsupported SVG shape: "+t},bi=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Pe(n)}" />`).join("")}</g>`,Ln=e=>{let t;switch(e.type){case J.POLYGON:{const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`;break}case J.ELLIPSE:{const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;break}case J.MULTIPOLYGON:{const n=e.geometry;t=`<svg>${bi(n)}</svg>`;break}case J.LINE:{const n=e.geometry,[[o,i],[s,r]]=n.points;t=`<svg><line x1="${o}" y1="${i}" x2="${s}" y2="${r}" /></svg>`;break}case J.POLYLINE:t=`<svg><path d="${It(e.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},me=[];for(let e=0;e<256;++e)me.push((e+256).toString(16).slice(1));function Ei(e,t=0){return(me[e[t+0]]+me[e[t+1]]+me[e[t+2]]+me[e[t+3]]+"-"+me[e[t+4]]+me[e[t+5]]+"-"+me[e[t+6]]+me[e[t+7]]+"-"+me[e[t+8]]+me[e[t+9]]+"-"+me[e[t+10]]+me[e[t+11]]+me[e[t+12]]+me[e[t+13]]+me[e[t+14]]+me[e[t+15]]).toLowerCase()}let Ct;const vi=new Uint8Array(16);function Si(){if(!Ct){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ct=crypto.getRandomValues.bind(crypto)}return Ct(vi)}const In={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Cn(e,t,n){var i;if(In.randomUUID&&!e)return In.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Si();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Ei(o)}var On=Object.prototype.hasOwnProperty;function Oe(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&Oe(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(On.call(e,n)&&++o&&!On.call(t,n)||!(n in t)||!Oe(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function Ot(){}function Ai(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const ze=[];function Dt(e,t=Ot){let n;const o=new Set;function i(l){if(Ai(e,l)&&(e=l,n)){const a=!ze.length;for(const u of o)u[1](),ze.push(u,e);if(a){for(let u=0;u<ze.length;u+=2)ze[u][0](ze[u+1]);ze.length=0}}}function s(l){i(l(e))}function r(l,a=Ot){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||Ot),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const ki=e=>{const{subscribe:t,set:n}=Dt();let o;return t(i=>o=i),e.observe(({changes:i})=>{if(o){(i.deleted||[]).some(r=>r.id===o)&&n(void 0);const s=(i.updated||[]).find(({oldValue:r})=>r.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Nt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Nt||{});const mt={selected:[]},Mi=(e,t,n)=>{const{subscribe:o,set:i}=Dt(mt);let s=t,r=mt;o(g=>r=g);const l=()=>{Oe(r,mt)||i(mt)},a=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},u=g=>{if(a())return!1;const k=typeof g=="string"?g:g.id;return r.selected.some(y=>y.id===k)},d=(g,k)=>{let y;if(Array.isArray(g)){if(y=g.map(v=>e.getAnnotation(v)).filter(Boolean),y.length<g.length){console.warn("Invalid selection: "+g.filter(v=>!y.some(A=>A.id===v)));return}}else{const v=e.getAnnotation(g);if(!v){console.warn("Invalid selection: "+g);return}y=[v]}const E=y.reduce((v,A)=>{const M=m(A);return M==="EDIT"?[...v,{id:A.id,editable:!0}]:M==="SELECT"?[...v,{id:A.id}]:v},[]);i({selected:E,event:k})},f=(g,k)=>{const y=Array.isArray(g)?g:[g],E=y.map(v=>e.getAnnotation(v)).filter(v=>!!v);i({selected:E.map(v=>{const A=k===void 0?m(v)==="EDIT":k;return{id:v.id,editable:A}})}),E.length!==y.length&&console.warn("Invalid selection",g)},h=g=>{if(a())return!1;const{selected:k}=r;k.some(({id:y})=>g.includes(y))&&i({selected:k.filter(({id:y})=>!g.includes(y))})},_=g=>{s=g,f(r.selected.map(({id:k})=>k))},m=g=>Ti(g,s,n);return e.observe(({changes:g})=>h((g.deleted||[]).map(k=>k.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:l,evalSelectAction:m,isEmpty:a,isSelected:u,setSelected:f,setUserSelectAction:_,subscribe:o,userSelect:d}},Ti=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},pe=[];for(let e=0;e<256;++e)pe.push((e+256).toString(16).slice(1));function Pi(e,t=0){return(pe[e[t+0]]+pe[e[t+1]]+pe[e[t+2]]+pe[e[t+3]]+"-"+pe[e[t+4]]+pe[e[t+5]]+"-"+pe[e[t+6]]+pe[e[t+7]]+"-"+pe[e[t+8]]+pe[e[t+9]]+"-"+pe[e[t+10]]+pe[e[t+11]]+pe[e[t+12]]+pe[e[t+13]]+pe[e[t+14]]+pe[e[t+15]]).toLowerCase()}let Yt;const Li=new Uint8Array(16);function Ii(){if(!Yt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Yt=crypto.getRandomValues.bind(crypto)}return Yt(Li)}const Ci=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Dn={randomUUID:Ci};function Nn(e,t,n){var o;if(Dn.randomUUID&&!e)return Dn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Ii();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,Pi(i)}const Bt=e=>{const t=n=>{const o={...n};return n.created&&typeof n.created=="string"&&(o.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(o.updated=new Date(n.updated)),o};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Oi=(e,t,n,o)=>({id:Nn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Di=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Ni=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Yi=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!Oe(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Bi=(e,t)=>!Oe(e.target,t.target),Yn=(e,t)=>{const n=Di(e,t),o=Ni(e,t),i=Yi(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Bi(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var ne=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(ne||{});const Ri=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,l=a=>a&&a.length>0;if(!(l(i.created)||l(i.deleted))){const a=(n=i.updated)==null?void 0:n.some(d=>l(d.bodiesCreated)||l(d.bodiesDeleted)||l(d.bodiesUpdated)),u=(o=i.updated)==null?void 0:o.some(d=>d.targetUpdated);if(r==="BODY_ONLY"&&a&&!u||r==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const r=new Set([...(i.created||[]).map(l=>l.id),...(i.deleted||[]).map(l=>l.id),...(i.updated||[]).map(({oldValue:l})=>l.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(l=>r.has(l))}else return!0},Ui=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),l=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),a=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:h})=>h.id===f.id).newValue:f),...t.created||[]],u=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],d=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:h,newValue:_}=f;if(r.has(_.id)){const m=t.updated.find(g=>g.oldValue.id===_.id).newValue;return Yn(h,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:u,updated:d}},pt=e=>{const t=e.id===void 0?Nn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},Vi=e=>e.id!==void 0,Xi=()=>{const e=new Map,t=new Map,n=[],o=(w,S={})=>{n.push({onChange:w,options:S})},i=w=>{const S=n.findIndex(p=>p.onChange==w);S>-1&&n.splice(S,1)},s=(w,S)=>{const p={origin:w,changes:{created:S.created||[],updated:S.updated||[],deleted:S.deleted||[]},state:[...e.values()]};n.forEach(b=>{Ri(b,p)&&b.onChange(p)})},r=(w,S=ne.LOCAL)=>{if(w.id&&e.get(w.id))throw Error(`Cannot add annotation ${w.id} - exists already`);{const p=pt(w);e.set(p.id,p),p.bodies.forEach(b=>t.set(b.id,p.id)),s(S,{created:[p]})}},l=(w,S)=>{const p=pt(typeof w=="string"?S:w),b=typeof w=="string"?w:w.id,I=b&&e.get(b);if(I){const P=Yn(I,p);return b===p.id?e.set(b,p):(e.delete(b),e.set(p.id,p)),I.bodies.forEach(O=>t.delete(O.id)),p.bodies.forEach(O=>t.set(O.id,p.id)),P}else console.warn(`Cannot update annotation ${b} - does not exist`)},a=(w,S=ne.LOCAL,p=ne.LOCAL)=>{const b=Vi(S)?p:S,I=l(w,S);I&&s(b,{updated:[I]})},u=(w,S=ne.LOCAL)=>{e.get(w.id)?a(w,S):r(w,S)},d=(w,S=ne.LOCAL)=>{const p=w.reduce((b,I)=>{const P=l(I);return P?[...b,P]:b},[]);p.length>0&&s(S,{updated:p})},f=(w,S=ne.LOCAL)=>{const p=w.map(pt),{toAdd:b,toUpdate:I}=p.reduce((O,z)=>e.get(z.id)?{...O,toUpdate:[...O.toUpdate,z]}:{...O,toAdd:[...O.toAdd,z]},{toAdd:[],toUpdate:[]}),P=I.map(O=>l(O,S)).filter(Boolean);b.forEach(O=>{e.set(O.id,O),O.bodies.forEach(z=>t.set(z.id,O.id))}),s(S,{created:b,updated:P})},h=(w,S=ne.LOCAL)=>{const p=e.get(w.annotation);if(p){const b={...p,bodies:[...p.bodies,w]};e.set(p.id,b),t.set(w.id,b.id),s(S,{updated:[{oldValue:p,newValue:b,bodiesCreated:[w]}]})}else console.warn(`Attempt to add body to missing annotation: ${w.annotation}`)},_=()=>[...e.values()],m=(w=ne.LOCAL)=>{const S=[...e.values()];e.clear(),t.clear(),s(w,{deleted:S})},g=(w,S=!0,p=ne.LOCAL)=>{const b=w.map(pt);if(S){const I=[...e.values()];e.clear(),t.clear(),b.forEach(P=>{e.set(P.id,P),P.bodies.forEach(O=>t.set(O.id,P.id))}),s(p,{created:b,deleted:I})}else{const I=w.reduce((P,O)=>{const z=O.id&&e.get(O.id);return z?[...P,z]:P},[]);if(I.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${I.map(P=>P.id).join(", ")}`);b.forEach(P=>{e.set(P.id,P),P.bodies.forEach(O=>t.set(O.id,P.id))}),s(p,{created:b})}},k=w=>{const S=typeof w=="string"?w:w.id,p=e.get(S);if(p)return e.delete(S),p.bodies.forEach(b=>t.delete(b.id)),p;console.warn(`Attempt to delete missing annotation: ${S}`)},y=(w,S=ne.LOCAL)=>{const p=k(w);p&&s(S,{deleted:[p]})},E=(w,S=ne.LOCAL)=>{const p=w.reduce((b,I)=>{const P=k(I);return P?[...b,P]:b},[]);p.length>0&&s(S,{deleted:p})},v=w=>{const S=e.get(w.annotation);if(S){const p=S.bodies.find(b=>b.id===w.id);if(p){t.delete(p.id);const b={...S,bodies:S.bodies.filter(I=>I.id!==w.id)};return e.set(S.id,b),{oldValue:S,newValue:b,bodiesDeleted:[p]}}else console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${w.annotation}`)},A=(w,S=ne.LOCAL)=>{const p=v(w);p&&s(S,{updated:[p]})},M=(w,S=ne.LOCAL)=>{const p=w.map(b=>v(b)).filter(Boolean);p.length>0&&s(S,{updated:p})},C=w=>{const S=e.get(w);return S?{...S}:void 0},T=w=>{const S=t.get(w);if(S){const p=C(S).bodies.find(b=>b.id===w);if(p)return p;console.error(`Store integrity error: body ${w} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${w}`)},V=(w,S)=>{if(w.annotation!==S.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const p=e.get(w.annotation);if(p){const b=p.bodies.find(P=>P.id===w.id),I={...p,bodies:p.bodies.map(P=>P.id===b.id?S:P)};return e.set(p.id,I),b.id!==S.id&&(t.delete(b.id),t.set(S.id,I.id)),{oldValue:p,newValue:I,bodiesUpdated:[{oldBody:b,newBody:S}]}}else console.warn(`Attempt to add body to missing annotation ${w.annotation}`)},B=(w,S,p=ne.LOCAL)=>{const b=V(w,S);b&&s(p,{updated:[b]})},W=(w,S=ne.LOCAL)=>{const p=w.map(b=>V({id:b.id,annotation:b.annotation},b)).filter(Boolean);s(S,{updated:p})},q=w=>{const S=e.get(w.annotation);if(S){const p={...S,target:{...S.target,...w}};return e.set(S.id,p),{oldValue:S,newValue:p,targetUpdated:{oldTarget:S.target,newTarget:w}}}else console.warn(`Attempt to update target on missing annotation: ${w.annotation}`)};return{addAnnotation:r,addBody:h,all:_,bulkAddAnnotations:g,bulkDeleteAnnotations:E,bulkDeleteBodies:M,bulkUpdateAnnotations:d,bulkUpdateBodies:W,bulkUpdateTargets:(w,S=ne.LOCAL)=>{const p=w.map(b=>q(b)).filter(Boolean);p.length>0&&s(S,{updated:p})},bulkUpsertAnnotations:f,clear:m,deleteAnnotation:y,deleteBody:A,getAnnotation:C,getBody:T,observe:o,unobserve:i,updateAnnotation:a,updateBody:B,updateTarget:(w,S=ne.LOCAL)=>{const p=q(w);p&&s(S,{updated:[p]})},upsertAnnotation:u}},Hi=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let Gi=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const ji=250,zi=(e,t)=>{const n=Gi(),o=(t==null?void 0:t.changes)||[];let i=t?t.pointer:-1,s=!1,r=0;const l=m=>{if(!s){const{changes:g}=m,k=performance.now();if(k-r>ji)o.splice(i+1),o.push(g),i=o.length-1;else{const y=o.length-1;o[y]=Ui(o[y],g)}r=k}s=!1};e.observe(l,{origin:ne.LOCAL});const a=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m),u=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),d=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({oldValue:g})=>g)),f=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({newValue:g})=>g)),h=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),_=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...o],pointer:i}),on:(m,g)=>n.on(m,g),redo:()=>{if(o.length-1>i){s=!0;const{created:m,updated:g,deleted:k}=o[i+1];u(m),f(g),_(k),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:m,updated:g,deleted:k}=o[i];a(m),d(g),h(k),n.emit("undo",o[i]),i-=1}}}},Fi=()=>{const{subscribe:e,set:t}=Dt([]);return{subscribe:e,set:t}},qi=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],d,f;const h=(y,E)=>{a.has(y)?a.get(y).push(E):a.set(y,[E])},_=(y,E)=>{const v=a.get(y);if(v){const A=v.indexOf(E);A!==-1&&v.splice(A,1)}},m=(y,E,v)=>{a.has(y)&&setTimeout(()=>{a.get(y).forEach(A=>{if(n){const M=Array.isArray(E)?E.map(T=>n.serialize(T)):n.serialize(E),C=v?v instanceof PointerEvent?v:n.serialize(v):void 0;A(M,C)}else A(E,v)})},1)},g=()=>{const{selected:y}=s,E=(y||[]).map(({id:v})=>r.getAnnotation(v));E.forEach(v=>{const A=u.find(M=>M.id===v.id);(!A||!Oe(A,v))&&m("updateAnnotation",v,A)}),u=u.map(v=>E.find(({id:M})=>M===v.id)||v)};s.subscribe(({selected:y})=>{if(!(u.length===0&&y.length===0)){if(u.length===0&&y.length>0)u=y.map(({id:E})=>r.getAnnotation(E));else if(u.length>0&&y.length===0)u.forEach(E=>{const v=r.getAnnotation(E.id);v&&!Oe(v,E)&&m("updateAnnotation",v,E)}),u=[];else{const E=new Set(u.map(A=>A.id)),v=new Set(y.map(({id:A})=>A));u.filter(A=>!v.has(A.id)).forEach(A=>{const M=r.getAnnotation(A.id);M&&!Oe(M,A)&&m("updateAnnotation",M,A)}),u=[...u.filter(A=>v.has(A.id)),...y.filter(({id:A})=>!E.has(A)).map(({id:A})=>r.getAnnotation(A))]}m("selectionChanged",u)}}),i.subscribe(y=>{!d&&y?m("mouseEnterAnnotation",r.getAnnotation(y)):d&&!y?m("mouseLeaveAnnotation",r.getAnnotation(d)):d&&y&&(m("mouseLeaveAnnotation",r.getAnnotation(d)),m("mouseEnterAnnotation",r.getAnnotation(y))),d=y}),l==null||l.subscribe(y=>m("viewportIntersect",y.map(E=>r.getAnnotation(E)))),r.observe(y=>{o&&(f&&clearTimeout(f),f=setTimeout(g,1e3));const{created:E,deleted:v}=y.changes;(E||[]).forEach(A=>m("createAnnotation",A)),(v||[]).forEach(A=>m("deleteAnnotation",A)),(y.changes.updated||[]).filter(A=>[...A.bodiesCreated||[],...A.bodiesDeleted||[],...A.bodiesUpdated||[]].length>0).forEach(({oldValue:A,newValue:M})=>{const C=u.find(T=>T.id===A.id)||A;u=u.map(T=>T.id===A.id?M:T),m("updateAnnotation",M,C)})},{origin:ne.LOCAL}),r.observe(y=>{if(u){const E=new Set(u.map(A=>A.id)),v=(y.changes.updated||[]).filter(({newValue:A})=>E.has(A.id)).map(({newValue:A})=>A);v.length>0&&(u=u.map(A=>v.find(C=>C.id===A.id)||A))}},{origin:ne.REMOTE});const k=y=>E=>{const{updated:v}=E;y?(v||[]).forEach(A=>m("updateAnnotation",A.oldValue,A.newValue)):(v||[]).forEach(A=>m("updateAnnotation",A.newValue,A.oldValue))};return t.on("undo",k(!0)),t.on("redo",k(!1)),{on:h,off:_,emit:m}},Ki=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Wi=(e,t,n)=>{const{store:o,selection:i}=e,s=y=>{if(n){const{parsed:E,error:v}=n.parse(y);E?o.addAnnotation(E,ne.REMOTE):console.error(v)}else o.addAnnotation(Bt(y),ne.REMOTE)},r=()=>i.clear(),l=()=>o.clear(),a=y=>{const E=o.getAnnotation(y);return n&&E?n.serialize(E):E},u=()=>n?o.all().map(n.serialize):o.all(),d=()=>{var y;const E=(((y=i.selected)==null?void 0:y.map(v=>v.id))||[]).map(v=>o.getAnnotation(v)).filter(Boolean);return n?E.map(n.serialize):E},f=(y,E=!0)=>fetch(y).then(v=>v.json()).then(v=>(_(v,E),v)),h=y=>{if(typeof y=="string"){const E=o.getAnnotation(y);if(o.deleteAnnotation(y),E)return n?n.serialize(E):E}else{const E=n?n.parse(y).parsed:y;if(E)return o.deleteAnnotation(E),y}},_=(y,E=!0)=>{if(n){const v=n.parseAll||Ki(n),{parsed:A,failed:M}=v(y);M.length>0&&console.warn(`Discarded ${M.length} invalid annotations`,M),o.bulkAddAnnotations(A,E,ne.REMOTE)}else o.bulkAddAnnotations(y.map(Bt),E,ne.REMOTE)},m=(y,E)=>{y?i.setSelected(y,E):i.clear()},g=y=>{i.clear(),i.setUserSelectAction(y)},k=y=>{if(n){const E=n.parse(y).parsed,v=n.serialize(o.getAnnotation(E.id));return o.updateAnnotation(E),v}else{const E=o.getAnnotation(y.id);return o.updateAnnotation(Bt(y)),E}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:d,loadAnnotations:f,redo:t.redo,removeAnnotation:h,setAnnotations:_,setSelected:m,setUserSelectAction:g,undo:t.undo,updateAnnotation:k}},Zi=(e,t,n)=>typeof t=="function"?t(e,n):t,Ji=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,o)=>{const i=typeof e=="function"?e(n,o):e,s=typeof t=="function"?t(n,o):t;return{...i||{},...s||{}}},Qi="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let xi=e=>crypto.getRandomValues(new Uint8Array(e)),$i=(e,t,n)=>{let o=(2<<Math.log2(e.length-1))-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let l=n(i),a=i|0;for(;a--;)if(r+=e[l[a]&o]||"",r.length>=s)return r}}},es=(e,t=21)=>$i(e,t|0,xi),ts=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Qi[n[e]&63];return t};const ns=()=>({isGuest:!0,id:es("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),os=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Bn=e=>e?typeof e=="object"?{...e}:e:void 0,is=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:l,modified:a,creator:u,...d}=n;return{id:o||`temp-${os(n)}`,annotation:t,type:i,purpose:s,value:r,creator:Bn(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...d}}),ss=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,l={...r,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l}),rs=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],ls=()=>{const e=[...rs];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};ts();const as=(e,t={strict:!0,invertY:!1})=>({parse:i=>Rn(i,t),serialize:i=>Un(i,e,t)}),Rn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Cn(),{creator:o,created:i,modified:s,body:r,...l}=e,a=is(r||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,d=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,f=typeof d=="string"||(d==null?void 0:d.type)==="FragmentSelector"?Sn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?Pn(d):void 0,h=Array.isArray(l.target)?l.target[0]:l.targret;return f||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Bn(o),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Un=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:s,updated:r,updatedBy:l,...a}=e.target;let u;try{u=o.type==J.RECTANGLE?An(o.geometry):Ln(o)}catch(f){if(n.strict)throw f;u=o}const d={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:ss(e.bodies),created:s==null?void 0:s.toISOString(),creator:i,modified:r==null?void 0:r.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete d.bodies,"annotation"in d.target&&delete d.target.annotation,d},Fe=[];function cs(e,t=j){let n;const o=new Set;function i(l){if(re(e,l)&&(e=l,n)){const a=!Fe.length;for(const u of o)u[1](),Fe.push(u,e);if(a){for(let u=0;u<Fe.length;u+=2)Fe[u][0](Fe[u+1]);Fe.length=0}}}function s(l){i(l(e))}function r(l,a=j){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||j),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const us=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},Vn=(e,t)=>{us(e,t);const{subscribe:n,set:o}=cs(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,u=Math.max(r.width/l,r.height/a);o(u)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},Ve=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i,stroke:s,strokeWidth:r,strokeOpacity:l}=n;let a="";return o&&(a+=`fill:${o};`,a+=`fill-opacity:${i||"0.25"};`),s&&(a+=`stroke:${s};`,a+=`stroke-width:${r||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}},ot=(e,t=0)=>{const{minX:n,minY:o,maxX:i,maxY:s}=e;return{x:n-t,y:o-t,w:i-n+2*t,h:s-o+2*t}},Le=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,fs=e=>({}),Xn=e=>({grab:e[0]});function ds(e){let t,n,o,i;const s=e[8].default,r=zo(s,e,e[7],Xn);return{c(){t=L("g"),r&&r.c(),c(t,"class","a9s-annotation selected")},m(l,a){Y(l,t,a),r&&r.m(t,null),n=!0,o||(i=[Q(t,"pointerup",e[2]),Q(t,"pointermove",e[1])],o=!0)},p(l,[a]){r&&r.p&&(!n||a&128)&&qo(r,s,l,l[7],n?Fo(s,l[7],a,fs):Ko(l[7]),Xn)},i(l){n||(U(r,l),n=!0)},o(l){G(r,l),n=!1},d(l){l&&N(t),r&&r.d(l),o=!1,Ae(i)}}}function hs(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=Ce();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,d,f,h;const _=k=>y=>{if(d=k,u){const{left:v,top:A}=u.getBoundingClientRect(),M=y.clientX-v,C=y.clientY-A;f=a.elementToImage(M,C)}else{const{offsetX:v,offsetY:A}=y;f=a.elementToImage(v,A)}h=r,y.target.setPointerCapture(y.pointerId),s("grab",y)},m=k=>{if(d){const[y,E]=a.elementToImage(k.offsetX,k.offsetY),v=[y-f[0],E-f[1]];n(3,r=l(h,d,v)),s("change",r)}},g=k=>{k.target.releasePointerCapture(k.pointerId),d=void 0,h=r,s("release",k)};return e.$$set=k=>{"shape"in k&&n(3,r=k.shape),"editor"in k&&n(4,l=k.editor),"transform"in k&&n(5,a=k.transform),"svgEl"in k&&n(6,u=k.svgEl),"$$scope"in k&&n(7,i=k.$$scope)},[_,m,g,r,l,a,u,i,o]}class _t extends ge{constructor(t){super(),he(this,t,hs,ds,re,{shape:3,editor:4,transform:5,svgEl:6})}}function gs(e){let t,n,o,i,s,r,l,a,u=e[3]&&Hn(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),i=L("circle"),c(n,"class","a9s-handle-buffer"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]+6/e[2]),c(n,"role","button"),c(n,"tabindex","0"),c(i,"class",s=`a9s-handle-dot${e[3]?" selected":""}`),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[5]),c(t,"class",r=`a9s-handle ${e[8].class||""}`.trim())},m(d,f){Y(d,t,f),F(t,n),u&&u.m(t,null),F(t,i),l||(a=[Q(n,"dblclick",e[11]),Q(n,"pointerenter",e[12]),Q(n,"pointerleave",e[13]),Q(n,"pointerdown",e[14]),Q(n,"pointerdown",e[6]),Q(n,"pointerup",e[15]),Q(n,"pointerup",e[7])],l=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&36&&o!==(o=d[5]+6/d[2])&&c(n,"r",o),d[3]?u?u.p(d,f):(u=Hn(d),u.c(),u.m(t,i)):u&&(u.d(1),u=null),f&8&&s!==(s=`a9s-handle-dot${d[3]?" selected":""}`)&&c(i,"class",s),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&32&&c(i,"r",d[5]),f&256&&r!==(r=`a9s-handle ${d[8].class||""}`.trim())&&c(t,"class",r)},d(d){d&&N(t),u&&u.d(),l=!1,Ae(a)}}}function ms(e){let t,n,o,i,s,r,l,a,u;return{c(){t=L("g"),n=L("circle"),i=L("circle"),r=L("circle"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]*10),c(n,"class","a9s-touch-halo"),Te(n,"touched",e[4]),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",s=e[5]+10/e[2]),c(i,"class","a9s-handle-buffer"),c(r,"class","a9s-handle-dot"),c(r,"cx",e[0]),c(r,"cy",e[1]),c(r,"r",l=e[5]+2/e[2]),c(t,"class","a9s-touch-handle")},m(d,f){Y(d,t,f),F(t,n),F(t,i),F(t,r),a||(u=[Q(i,"pointerdown",e[9]),Q(i,"pointerup",e[10]),Q(i,"pointerdown",e[6]),Q(i,"pointerup",e[7])],a=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&32&&o!==(o=d[5]*10)&&c(n,"r",o),f&16&&Te(n,"touched",d[4]),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&36&&s!==(s=d[5]+10/d[2])&&c(i,"r",s),f&1&&c(r,"cx",d[0]),f&2&&c(r,"cy",d[1]),f&36&&l!==(l=d[5]+2/d[2])&&c(r,"r",l)},d(d){d&&N(t),a=!1,Ae(u)}}}function Hn(e){let t,n;return{c(){t=L("circle"),c(t,"class","a9s-handle-selected"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",n=e[5]+8/e[2])},m(o,i){Y(o,t,i)},p(o,i){i&1&&c(t,"cx",o[0]),i&2&&c(t,"cy",o[1]),i&36&&n!==(n=o[5]+8/o[2])&&c(t,"r",n)},d(o){o&&N(t)}}}function ps(e){let t;function n(s,r){return Le?ms:gs}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),Y(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&N(t),i.d(s)}}}function _s(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=E=>{E.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function f(E){de.call(this,e,E)}function h(E){de.call(this,e,E)}function _(E){de.call(this,e,E)}function m(E){de.call(this,e,E)}function g(E){de.call(this,e,E)}function k(E){de.call(this,e,E)}function y(E){de.call(this,e,E)}return e.$$set=E=>{n(8,t=Ie(Ie({},t),an(E))),"x"in E&&n(0,i=E.x),"y"in E&&n(1,s=E.y),"scale"in E&&n(2,r=E.scale),"selected"in E&&n(3,l=E.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=4/r)},t=an(t),[i,s,r,l,a,o,u,d,t,f,h,_,m,g,k,y]}class Xe extends ge{constructor(t){super(),he(this,t,_s,ps,re,{x:0,y:1,scale:2,selected:3})}}function ys(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("circle"),i=L("circle"),s=L("circle"),c(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=1.75*e[2]),c(i,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[2]),c(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),c(s,"cx",e[0]),c(s,"cy",e[1]),c(s,"r",e[2]),c(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(a,u){Y(a,t,u),F(t,n),F(t,i),F(t,s),r||(l=[Q(n,"pointerdown",e[5]),Q(n,"pointerdown",e[3])],r=!0)},p(a,u){u&1&&c(n,"cx",a[0]),u&2&&c(n,"cy",a[1]),u&4&&o!==(o=1.75*a[2])&&c(n,"r",o),u&1&&c(i,"cx",a[0]),u&2&&c(i,"cy",a[1]),u&4&&c(i,"r",a[2]),u&1&&c(s,"cx",a[0]),u&2&&c(s,"cy",a[1]),u&4&&c(s,"r",a[2])},d(a){a&&N(t),r=!1,Ae(l)}}}function ws(e){let t;return{c(){t=L("circle"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",e[2])},m(n,o){Y(n,t,o)},p(n,o){o&1&&c(t,"cx",n[0]),o&2&&c(t,"cy",n[1]),o&4&&c(t,"r",n[2])},d(n){n&&N(t)}}}function bs(e){let t;function n(s,r){return Le?ws:ys}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),Y(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&N(t),i.d(s)}}}function Es(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){de.call(this,e,u)}return e.$$set=u=>{"x"in u&&n(0,i=u.x),"y"in u&&n(1,s=u.y),"scale"in u&&n(4,r=u.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,o=4/r)},[i,s,o,l,r,a]}class Gn extends ge{constructor(t){super(),he(this,t,Es,bs,re,{x:0,y:1,scale:4})}}function Rt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function jn(e,t,n){const o=e.slice();return o[28]=t[n],o[30]=n,o}function Ut(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Vt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function zn(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[28][0]),c(t,"cy",o=e[28][1]),c(t,"r",i=it/e[3]),c(t,"class","svelte-1h2slbm")},m(s,r){Y(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[28][1])&&c(t,"cy",o),r[0]&8&&i!==(i=it/s[3])&&c(t,"r",i)},d(s){s&&N(t)}}}function Fn(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1h2slbm"),c(l,"cx",a=e[28][0]),c(l,"cy",u=e[28][1]),c(l,"r",d=it/e[3]),c(l,"class","svelte-1h2slbm"),c(t,"id",`${e[19]}-inner`),c(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(f,h){Y(f,t,h),F(t,n),F(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[28][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[28][1])&&c(l,"cy",u),h[0]&8&&d!==(d=it/f[3])&&c(l,"r",d)},d(f){f&&N(t)}}}function qn(e){let t,n;return t=new Xe({props:{class:"a9s-corner-handle",x:e[28][0],y:e[28][1],scale:e[3],selected:e[8].includes(e[30])}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[15]),t.$on("pointerdown",function(){ie(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&32&&(s.x=e[28][0]),i[0]&32&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),i[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Kn(e){let t,n;return t=new Gn({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[28][0]),i[0]&1088&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function vs(e){let t,n,o,i,s,r,l,a,u,d,f,h,_,m,g,k,y,E,v,A,M,C=e[6]!==void 0&&!e[7]&&zn(Vt(e)),T=e[6]!==void 0&&!e[7]&&Fn(Ut(e)),V=ve(e[5].points),B=[];for(let w=0;w<V.length;w+=1)B[w]=qn(jn(e,V,w));const W=w=>G(B[w],1,1,()=>{B[w]=null});let q=e[6]!==void 0&&!e[7]&&Kn(Rt(e));return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),C&&C.c(),T&&T.c(),d=we(),f=L("polygon"),_=we(),m=L("polygon"),k=we();for(let w=0;w<B.length;w+=1)B[w].c();y=we(),q&&q.c(),E=ke(),c(o,"x",i=e[9].x),c(o,"y",s=e[9].y),c(o,"width",r=e[9].w),c(o,"height",l=e[9].h),c(o,"class","svelte-1h2slbm"),c(a,"points",u=e[5].points.map(Wn).join(" ")),c(a,"class","svelte-1h2slbm"),c(n,"id",`${e[19]}-outer`),c(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[19]}-outer)`),c(f,"points",h=e[5].points.map(Zn).join(" ")),c(m,"class","a9s-inner a9s-shape-handle"),c(m,"mask",`url(#${e[19]}-inner)`),c(m,"style",e[1]),c(m,"points",g=e[5].points.map(Jn).join(" "))},m(w,S){Y(w,t,S),F(t,n),F(n,o),F(n,a),C&&C.m(n,null),T&&T.m(t,null),Y(w,d,S),Y(w,f,S),Y(w,_,S),Y(w,m,S),Y(w,k,S);for(let p=0;p<B.length;p+=1)B[p]&&B[p].m(w,S);Y(w,y,S),q&&q.m(w,S),Y(w,E,S),v=!0,A||(M=[Q(f,"pointerup",e[14]),Q(f,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),Q(m,"pointermove",e[13]),Q(m,"pointerup",e[14]),Q(m,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],A=!0)},p(w,S){if(e=w,(!v||S[0]&512&&i!==(i=e[9].x))&&c(o,"x",i),(!v||S[0]&512&&s!==(s=e[9].y))&&c(o,"y",s),(!v||S[0]&512&&r!==(r=e[9].w))&&c(o,"width",r),(!v||S[0]&512&&l!==(l=e[9].h))&&c(o,"height",l),(!v||S[0]&32&&u!==(u=e[5].points.map(Wn).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Vt(e),S):(C=zn(Vt(e)),C.c(),C.m(n,null)):C&&(C.d(1),C=null),e[6]!==void 0&&!e[7]?T?T.p(Ut(e),S):(T=Fn(Ut(e)),T.c(),T.m(t,null)):T&&(T.d(1),T=null),(!v||S[0]&32&&h!==(h=e[5].points.map(Zn).join(" ")))&&c(f,"points",h),(!v||S[0]&2)&&c(m,"style",e[1]),(!v||S[0]&32&&g!==(g=e[5].points.map(Jn).join(" ")))&&c(m,"points",g),S[0]&134322472){V=ve(e[5].points);let p;for(p=0;p<V.length;p+=1){const b=jn(e,V,p);B[p]?(B[p].p(b,S),U(B[p],1)):(B[p]=qn(b),B[p].c(),U(B[p],1),B[p].m(y.parentNode,y))}for(be(),p=V.length;p<B.length;p+=1)W(p);Ee()}e[6]!==void 0&&!e[7]?q?(q.p(Rt(e),S),S[0]&192&&U(q,1)):(q=Kn(Rt(e)),q.c(),U(q,1),q.m(E.parentNode,E)):q&&(be(),G(q,1,1,()=>{q=null}),Ee())},i(w){if(!v){for(let S=0;S<V.length;S+=1)U(B[S]);U(q),v=!0}},o(w){B=B.filter(Boolean);for(let S=0;S<B.length;S+=1)G(B[S]);G(q),v=!1},d(w){w&&(N(t),N(d),N(f),N(_),N(m),N(k),N(y),N(E)),C&&C.d(),T&&T.d(),Ye(B,w),q&&q.d(w),A=!1,Ae(M)}}}function Ss(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[vs,({grab:o})=>({27:o}),({grab:o})=>[o?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&134219754|i[1]&1&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const As=250,ks=1e3,Ms=12,it=4.5,Wn=e=>e.join(","),Zn=e=>e.join(","),Jn=e=>e.join(",");function Ts(e,t,n){let o,i,s;const r=Ce();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,_=!1,m,g=[];const k=()=>n(7,_=!0),y=()=>n(7,_=!1),E=p=>{if(g.length>0||!i.some(Z=>Z.visible)){n(6,h=void 0);return}const[b,I]=u.elementToImage(p.offsetX,p.offsetY),P=Z=>Math.pow(Z[0]-b,2)+Math.pow(Z[1]-I,2),O=o.points.reduce((Z,$)=>P($)<P(Z)?$:Z),z=i.filter(Z=>Z.visible).reduce((Z,$)=>P($.point)<P(Z.point)?$:Z),H=Math.pow(ks/d,2);P(O)<H||P(z.point)<H?n(6,h=i.indexOf(z)):n(6,h=void 0)},v=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,g=[]),v()},M=p=>{n(7,_=!0),p.preventDefault(),p.stopPropagation(),m=performance.now()},C=p=>b=>{if(!m||Le||performance.now()-m>As)return;const I=g.includes(p);b.metaKey||b.ctrlKey||b.shiftKey?I?n(8,g=g.filter(P=>P!==p)):n(8,g=[...g,p]):I&&g.length>1?n(8,g=[p]):I?n(8,g=[]):n(8,g=[p]),v()},T=(p,b,I)=>{v();let P;const O=p.geometry;g.length>1?P=O.points.map(([H,x],Z)=>g.includes(Z)?[H+I[0],x+I[1]]:[H,x]):b==="SHAPE"?P=O.points.map(([H,x])=>[H+I[0],x+I[1]]):P=O.points.map(([H,x],Z)=>b===`HANDLE-${Z}`?[H+I[0],x+I[1]]:[H,x]);const z=ue(P);return{...p,geometry:{points:P,bounds:z}}},V=p=>async b=>{b.stopPropagation();const I=[...o.points.slice(0,p+1),i[p].point,...o.points.slice(p+1)],P=ue(I);r("change",{...l,geometry:{points:I,bounds:P}}),await gn();const O=[...document.querySelectorAll(".a9s-handle")][p+1];if(O!=null&&O.firstChild){const z=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:b.clientX,clientY:b.clientY,pointerId:b.pointerId,pointerType:b.pointerType,isPrimary:b.isPrimary,buttons:b.buttons});O.firstChild.dispatchEvent(z)}},B=()=>{if(o.points.length-g.length<3)return;const p=o.points.filter((I,P)=>!g.includes(P)),b=ue(p);r("change",{...l,geometry:{points:p,bounds:b}}),n(8,g=[])};Be(()=>{if(Le)return;const p=b=>{(b.key==="Delete"||b.key==="Backspace")&&(b.preventDefault(),B())};return f.addEventListener("pointermove",E),f.addEventListener("keydown",p),()=>{f.removeEventListener("pointermove",E),f.removeEventListener("keydown",p)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function q(p){de.call(this,e,p)}function w(p){de.call(this,e,p)}function S(p){de.call(this,e,p)}return e.$$set=p=>{"shape"in p&&n(0,l=p.shape),"computedStyle"in p&&n(1,a=p.computedStyle),"transform"in p&&n(2,u=p.transform),"viewportScale"in p&&n(3,d=p.viewportScale),"svgEl"in p&&n(4,f=p.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Le?[]:o.points.map((p,b)=>{const I=b===o.points.length-1?o.points[0]:o.points[b+1],P=(p[0]+I[0])/2,O=(p[1]+I[1])/2,H=Math.sqrt(Math.pow(I[0]-P,2)+Math.pow(I[1]-O,2))>Ms/d;return{point:[P,O],visible:H}})),e.$$.dirty[0]&40&&n(9,s=ot(o.bounds,it/d))},[l,a,u,d,f,o,h,_,g,s,i,k,y,E,A,M,C,T,V,W,q,w,S]}class Qn extends ge{constructor(t){super(),he(this,t,Ts,Ss,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Ps(e){let t,n,o,i,s,r,l,a,u,d,f,h,_,m,g,k,y,E,v,A,M,C,T,V,B,W,q,w,S,p,b,I,P,O,z,H,x,Z,$,oe,se,Se,Me,X,fe,te,_e,ye,We,De,en,Ne,ee,tn,Go;return te=new Xe({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),ye=new Xe({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),ye.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),De=new Xe({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),De.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Ne=new Xe({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Ne.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),_=we(),m=L("rect"),v=we(),A=L("rect"),B=we(),W=L("rect"),p=we(),b=L("rect"),z=we(),H=L("rect"),oe=we(),se=L("rect"),fe=we(),ce(te.$$.fragment),_e=we(),ce(ye.$$.fragment),We=we(),ce(De.$$.fragment),en=we(),ce(Ne.$$.fragment),c(o,"class","rect-mask-bg svelte-1njczvj"),c(o,"x",i=e[6].x),c(o,"y",s=e[6].y),c(o,"width",r=e[6].w),c(o,"height",l=e[6].h),c(a,"class","rect-mask-fg svelte-1njczvj"),c(a,"x",u=e[5].x),c(a,"y",d=e[5].y),c(a,"width",f=e[5].w),c(a,"height",h=e[5].h),c(n,"id",e[8]),c(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),c(m,"class","a9s-outer"),c(m,"mask",`url(#${e[8]})`),c(m,"x",g=e[5].x),c(m,"y",k=e[5].y),c(m,"width",y=e[5].w),c(m,"height",E=e[5].h),c(A,"class","a9s-inner a9s-shape-handle"),c(A,"style",e[1]),c(A,"x",M=e[5].x),c(A,"y",C=e[5].y),c(A,"width",T=e[5].w),c(A,"height",V=e[5].h),c(W,"class","a9s-edge-handle a9s-edge-handle-top"),c(W,"x",q=e[5].x),c(W,"y",w=e[5].y),c(W,"height",1),c(W,"width",S=e[5].w),c(b,"class","a9s-edge-handle a9s-edge-handle-right"),c(b,"x",I=e[5].x+e[5].w),c(b,"y",P=e[5].y),c(b,"height",O=e[5].h),c(b,"width",1),c(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),c(H,"x",x=e[5].x),c(H,"y",Z=e[5].y+e[5].h),c(H,"height",1),c(H,"width",$=e[5].w),c(se,"class","a9s-edge-handle a9s-edge-handle-left"),c(se,"x",Se=e[5].x),c(se,"y",Me=e[5].y),c(se,"height",X=e[5].h),c(se,"width",1)},m(K,R){Y(K,t,R),F(t,n),F(n,o),F(n,a),Y(K,_,R),Y(K,m,R),Y(K,v,R),Y(K,A,R),Y(K,B,R),Y(K,W,R),Y(K,p,R),Y(K,b,R),Y(K,z,R),Y(K,H,R),Y(K,oe,R),Y(K,se,R),Y(K,fe,R),le(te,K,R),Y(K,_e,R),le(ye,K,R),Y(K,We,R),le(De,K,R),Y(K,en,R),le(Ne,K,R),ee=!0,tn||(Go=[Q(m,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),Q(A,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),Q(W,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),Q(b,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),Q(H,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),Q(se,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],tn=!0)},p(K,R){e=K,(!ee||R&64&&i!==(i=e[6].x))&&c(o,"x",i),(!ee||R&64&&s!==(s=e[6].y))&&c(o,"y",s),(!ee||R&64&&r!==(r=e[6].w))&&c(o,"width",r),(!ee||R&64&&l!==(l=e[6].h))&&c(o,"height",l),(!ee||R&32&&u!==(u=e[5].x))&&c(a,"x",u),(!ee||R&32&&d!==(d=e[5].y))&&c(a,"y",d),(!ee||R&32&&f!==(f=e[5].w))&&c(a,"width",f),(!ee||R&32&&h!==(h=e[5].h))&&c(a,"height",h),(!ee||R&32&&g!==(g=e[5].x))&&c(m,"x",g),(!ee||R&32&&k!==(k=e[5].y))&&c(m,"y",k),(!ee||R&32&&y!==(y=e[5].w))&&c(m,"width",y),(!ee||R&32&&E!==(E=e[5].h))&&c(m,"height",E),(!ee||R&2)&&c(A,"style",e[1]),(!ee||R&32&&M!==(M=e[5].x))&&c(A,"x",M),(!ee||R&32&&C!==(C=e[5].y))&&c(A,"y",C),(!ee||R&32&&T!==(T=e[5].w))&&c(A,"width",T),(!ee||R&32&&V!==(V=e[5].h))&&c(A,"height",V),(!ee||R&32&&q!==(q=e[5].x))&&c(W,"x",q),(!ee||R&32&&w!==(w=e[5].y))&&c(W,"y",w),(!ee||R&32&&S!==(S=e[5].w))&&c(W,"width",S),(!ee||R&32&&I!==(I=e[5].x+e[5].w))&&c(b,"x",I),(!ee||R&32&&P!==(P=e[5].y))&&c(b,"y",P),(!ee||R&32&&O!==(O=e[5].h))&&c(b,"height",O),(!ee||R&32&&x!==(x=e[5].x))&&c(H,"x",x),(!ee||R&32&&Z!==(Z=e[5].y+e[5].h))&&c(H,"y",Z),(!ee||R&32&&$!==($=e[5].w))&&c(H,"width",$),(!ee||R&32&&Se!==(Se=e[5].x))&&c(se,"x",Se),(!ee||R&32&&Me!==(Me=e[5].y))&&c(se,"y",Me),(!ee||R&32&&X!==(X=e[5].h))&&c(se,"height",X);const bt={};R&32&&(bt.x=e[5].x),R&32&&(bt.y=e[5].y),R&8&&(bt.scale=e[3]),te.$set(bt);const Et={};R&32&&(Et.x=e[5].x+e[5].w),R&32&&(Et.y=e[5].y),R&8&&(Et.scale=e[3]),ye.$set(Et);const vt={};R&32&&(vt.x=e[5].x+e[5].w),R&32&&(vt.y=e[5].y+e[5].h),R&8&&(vt.scale=e[3]),De.$set(vt);const St={};R&32&&(St.x=e[5].x),R&32&&(St.y=e[5].y+e[5].h),R&8&&(St.scale=e[3]),Ne.$set(St)},i(K){ee||(U(te.$$.fragment,K),U(ye.$$.fragment,K),U(De.$$.fragment,K),U(Ne.$$.fragment,K),ee=!0)},o(K){G(te.$$.fragment,K),G(ye.$$.fragment,K),G(De.$$.fragment,K),G(Ne.$$.fragment,K),ee=!1},d(K){K&&(N(t),N(_),N(m),N(v),N(A),N(B),N(W),N(p),N(b),N(z),N(H),N(oe),N(se),N(fe),N(_e),N(We),N(en)),ae(te,K),ae(ye,K),ae(De,K),ae(Ne,K),tn=!1,Ae(Go)}}}function Ls(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Ps,({grab:o})=>({12:o}),({grab:o})=>o?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&16&&(s.svgEl=o[4]),i&12394&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Is(e,t,n){let o,i,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const d=(g,k,y)=>{const E=g.geometry.bounds;let[v,A]=[E.minX,E.minY],[M,C]=[E.maxX,E.maxY];const[T,V]=y;if(k==="SHAPE")v+=T,M+=T,A+=V,C+=V;else{switch(k){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{A+=V;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{C+=V;break}}switch(k){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{v+=T;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{M+=T;break}}}const B=Math.min(v,M),W=Math.min(A,C),q=Math.abs(M-v),w=Math.abs(C-A);return{...g,geometry:{x:B,y:W,w:q,h:w,bounds:{minX:B,minY:W,maxX:B+q,maxY:W+w}}}},f=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function h(g){de.call(this,e,g)}function _(g){de.call(this,e,g)}function m(g){de.call(this,e,g)}return e.$$set=g=>{"shape"in g&&n(0,s=g.shape),"computedStyle"in g&&n(1,r=g.computedStyle),"transform"in g&&n(2,l=g.transform),"viewportScale"in g&&n(3,a=g.viewportScale),"svgEl"in g&&n(4,u=g.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,o=s.geometry),e.$$.dirty&40&&n(6,i=ot(o.bounds,2/a))},[s,r,l,a,u,o,i,d,f,h,_,m]}class xn extends ge{constructor(t){super(),he(this,t,Is,Ls,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var $n=Object.prototype.hasOwnProperty;function Xt(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&Xt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if($n.call(e,n)&&++o&&!$n.call(t,n)||!(n in t)||!Xt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Cs=12,Os=(e,t)=>e.polygons.reduce((n,o,i)=>{const s=o.rings.reduce((r,l,a)=>{const u=l.points.map((d,f)=>{const h=f===l.points.length-1?l.points[0]:l.points[f+1],_=(d[0]+h[0])/2,m=(d[1]+h[1])/2,k=Math.sqrt(Math.pow(h[0]-_,2)+Math.pow(h[1]-m,2))>Cs/t;return{point:[_,m],visible:k,elementIdx:i,ringIdx:a,pointIdx:f}});return[...r,...u]},[]);return[...n,...s]},[]);function Ht(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function eo(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function to(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function no(e,t,n){const o=e.slice();return o[29]=t[n],o[37]=n,o}function Gt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function jt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function oo(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[29][0]),c(t,"cy",o=e[29][1]),c(t,"r",i=st/e[3]),c(t,"class","svelte-1vxo6dc")},m(s,r){Y(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[29][1])&&c(t,"cy",o),r[0]&8&&i!==(i=st/s[3])&&c(t,"r",i)},d(s){s&&N(t)}}}function io(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1vxo6dc"),c(l,"cx",a=e[29][0]),c(l,"cy",u=e[29][1]),c(l,"r",d=st/e[3]),c(l,"class","svelte-1vxo6dc"),c(t,"id",`${e[18]}-${e[32]}-inner`),c(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(f,h){Y(f,t,h),F(t,n),F(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[29][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[29][1])&&c(l,"cy",u),h[0]&8&&d!==(d=st/f[3])&&c(l,"r",d)},d(f){f&&N(t)}}}function so(e){let t,n;function o(...i){return e[19](e[32],e[35],e[37],...i)}return t=new Xe({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(o)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){ie(e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`))&&e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`).apply(this,arguments)}),t.$on("pointerup",e[15](e[32],e[35],e[37])),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){e=i;const r={};s[0]&32&&(r.x=e[29][0]),s[0]&32&&(r.y=e[29][1]),s[0]&8&&(r.scale=e[3]),s[0]&256&&(r.selected=e[8].some(o)),t.$set(r)},i(i){n||(U(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function ro(e){let t,n,o=ve(e[33].points),i=[];for(let r=0;r<o.length;r+=1)i[r]=so(no(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);Y(r,t,l),n=!0},p(r,l){if(l[0]&268491048){o=ve(r[33].points);let a;for(a=0;a<o.length;a+=1){const u=no(r,o,a);i[a]?(i[a].p(u,l),U(i[a],1)):(i[a]=so(u),i[a].c(),U(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)U(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&N(t),Ye(i,r)}}}function lo(e){let t,n,o,i,s,r,l,a,u,d,f,h,_,m,g,k,y,E=e[6]!==void 0&&!e[7]&&oo(jt(e)),v=e[6]!==void 0&&!e[7]&&io(Gt(e)),A=ve(e[30].rings),M=[];for(let T=0;T<A.length;T+=1)M[T]=ro(to(e,A,T));const C=T=>G(M[T],1,1,()=>{M[T]=null});return{c(){t=L("g"),n=L("defs"),o=L("mask"),i=L("rect"),u=L("path"),E&&E.c(),v&&v.c(),f=L("path"),_=L("path");for(let T=0;T<M.length;T+=1)M[T].c();c(i,"x",s=e[9].x),c(i,"y",r=e[9].y),c(i,"width",l=e[9].w),c(i,"height",a=e[9].h),c(i,"class","svelte-1vxo6dc"),c(u,"d",d=Pe(e[30])),c(u,"class","svelte-1vxo6dc"),c(o,"id",`${e[18]}-${e[32]}-outer`),c(o,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[18]}-${e[32]}-outer)`),c(f,"fill-rule","evenodd"),c(f,"d",h=Pe(e[30])),c(_,"class","a9s-inner"),c(_,"mask",`url(#${e[18]}-${e[32]}-inner)`),c(_,"style",e[1]),c(_,"fill-rule","evenodd"),c(_,"d",m=Pe(e[30]))},m(T,V){Y(T,t,V),F(t,n),F(n,o),F(o,i),F(o,u),E&&E.m(o,null),v&&v.m(n,null),F(t,f),F(t,_);for(let B=0;B<M.length;B+=1)M[B]&&M[B].m(t,null);g=!0,k||(y=[Q(f,"pointerup",e[13]),Q(f,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),Q(_,"pointerup",e[13]),Q(_,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],k=!0)},p(T,V){if(e=T,(!g||V[0]&512&&s!==(s=e[9].x))&&c(i,"x",s),(!g||V[0]&512&&r!==(r=e[9].y))&&c(i,"y",r),(!g||V[0]&512&&l!==(l=e[9].w))&&c(i,"width",l),(!g||V[0]&512&&a!==(a=e[9].h))&&c(i,"height",a),(!g||V[0]&32&&d!==(d=Pe(e[30])))&&c(u,"d",d),e[6]!==void 0&&!e[7]?E?E.p(jt(e),V):(E=oo(jt(e)),E.c(),E.m(o,null)):E&&(E.d(1),E=null),e[6]!==void 0&&!e[7]?v?v.p(Gt(e),V):(v=io(Gt(e)),v.c(),v.m(n,null)):v&&(v.d(1),v=null),(!g||V[0]&32&&h!==(h=Pe(e[30])))&&c(f,"d",h),(!g||V[0]&2)&&c(_,"style",e[1]),(!g||V[0]&32&&m!==(m=Pe(e[30])))&&c(_,"d",m),V[0]&268491048){A=ve(e[30].rings);let B;for(B=0;B<A.length;B+=1){const W=to(e,A,B);M[B]?(M[B].p(W,V),U(M[B],1)):(M[B]=ro(W),M[B].c(),U(M[B],1),M[B].m(t,null))}for(be(),B=A.length;B<M.length;B+=1)C(B);Ee()}},i(T){if(!g){for(let V=0;V<A.length;V+=1)U(M[V]);g=!0}},o(T){M=M.filter(Boolean);for(let V=0;V<M.length;V+=1)G(M[V]);g=!1},d(T){T&&N(t),E&&E.d(),v&&v.d(),Ye(M,T),k=!1,Ae(y)}}}function ao(e){let t,n;return t=new Gn({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[29][0]),i[0]&1088&&(s.y=e[29][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ds(e){let t,n,o,i=ve(e[5].polygons),s=[];for(let a=0;a<i.length;a+=1)s[a]=lo(eo(e,i,a));const r=a=>G(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&ao(Ht(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=we(),l&&l.c(),n=ke()},m(a,u){for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(a,u);Y(a,t,u),l&&l.m(a,u),Y(a,n,u),o=!0},p(a,u){if(u[0]&268763114){i=ve(a[5].polygons);let d;for(d=0;d<i.length;d+=1){const f=eo(a,i,d);s[d]?(s[d].p(f,u),U(s[d],1)):(s[d]=lo(f),s[d].c(),U(s[d],1),s[d].m(t.parentNode,t))}for(be(),d=i.length;d<s.length;d+=1)r(d);Ee()}a[6]!==void 0&&!a[7]?l?(l.p(Ht(a),u),u[0]&192&&U(l,1)):(l=ao(Ht(a)),l.c(),U(l,1),l.m(n.parentNode,n)):l&&(be(),G(l,1,1,()=>{l=null}),Ee())},i(a){if(!o){for(let u=0;u<i.length;u+=1)U(s[u]);U(l),o=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)G(s[u]);G(l),o=!1},d(a){a&&(N(t),N(n)),Ye(s,a),l&&l.d(a)}}}function Ns(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[Ds,({grab:o})=>({28:o}),({grab:o})=>[o?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&268437482|i[1]&128&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ys=250,Bs=1e3,st=4.5;function Rs(e,t,n){let o,i,s;const r=Ce();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,_=!1,m,g=[];const k=()=>n(7,_=!0),y=()=>n(7,_=!1),E=b=>{if(g.length>0||!i.some($=>$.visible)){n(6,h=void 0);return}const[I,P]=u.elementToImage(b.offsetX,b.offsetY),O=$=>Math.pow($[0]-I,2)+Math.pow($[1]-P,2),z=wn(o).reduce(($,oe)=>O(oe)<O($)?oe:$),H=i.filter($=>$.visible).reduce(($,oe)=>O(oe.point)<O($.point)?oe:$),x=Math.pow(Bs/d,2);O(z)<x||O(H.point)<x?n(6,h=i.indexOf(H)):n(6,h=void 0)},v=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,g=[]),v()},M=b=>{n(7,_=!0),b.preventDefault(),b.stopPropagation(),m=performance.now()},C=(b,I,P)=>O=>{if(!m||Le||performance.now()-m>Ys)return;const z=x=>x.polygon===b&&x.ring===I&&x.point===P,H=g.some(z);O.metaKey||O.ctrlKey||O.shiftKey?H?n(8,g=g.filter(x=>!z(x))):n(8,g=[...g,{polygon:b,ring:I,point:P}]):H&&g.length>1?n(8,g=[{polygon:b,ring:I,point:P}]):H?n(8,g=[]):n(8,g=[{polygon:b,ring:I,point:P}]),v()},T=(b,I,P)=>{v();const O=b.geometry.polygons;let z;if(I==="SHAPE")z=O.map(H=>{const x=H.rings.map(($,oe)=>({points:$.points.map((Se,Me)=>[Se[0]+P[0],Se[1]+P[1]])})),Z=ue(x[0].points);return{rings:x,bounds:Z}});else{const[H,x,Z,$]=I.split("-").map(oe=>parseInt(oe));z=O.map((oe,se)=>{if(se===x){const Se=oe.rings.map((X,fe)=>fe===Z?{points:X.points.map((_e,ye)=>ye===$?[_e[0]+P[0],_e[1]+P[1]]:_e)}:X),Me=ue(Se[0].points);return{rings:Se,bounds:Me}}else return oe})}return{...b,geometry:{polygons:z,bounds:et(z)}}},V=b=>async I=>{I.stopPropagation();const P=i[b],O=o.polygons.map((H,x)=>{if(x===P.elementIdx){const Z=H.rings.map((oe,se)=>se===P.ringIdx?{points:[...oe.points.slice(0,P.pointIdx+1),P.point,...oe.points.slice(P.pointIdx+1)]}:oe),$=ue(Z[0].points);return{rings:Z,bounds:$}}else return H});r("change",{...l,geometry:{polygons:O,bounds:et(O)}}),await gn();const z=[...document.querySelectorAll(".a9s-handle")][b+1];if(z!=null&&z.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:I.clientX,clientY:I.clientY,pointerId:I.pointerId,pointerType:I.pointerType,isPrimary:I.isPrimary,buttons:I.buttons});z.firstChild.dispatchEvent(H)}},B=()=>{const b=o.polygons.map((P,O)=>{if(g.some(H=>H.polygon===O)){const H=P.rings.map((Z,$)=>{const oe=g.filter(se=>se.polygon===O&&se.ring===$);return oe.length&&Z.points.length-oe.length>=3?{points:Z.points.filter((Se,Me)=>!oe.some(X=>X.point===Me))}:Z}),x=ue(H[0].points);return{rings:H,bounds:x}}else return P});!Xt(o.polygons,b)&&(r("change",{...l,geometry:{polygons:b,bounds:et(b)}}),n(8,g=[]))};Be(()=>{if(Le)return;const b=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),B())};return f.addEventListener("pointermove",E),f.addEventListener("keydown",b),()=>{f.removeEventListener("pointermove",E),f.removeEventListener("keydown",b)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,q=(b,I,P,{polygon:O,ring:z,point:H})=>O===b&&z===I&&H===P;function w(b){de.call(this,e,b)}function S(b){de.call(this,e,b)}function p(b){de.call(this,e,b)}return e.$$set=b=>{"shape"in b&&n(0,l=b.shape),"computedStyle"in b&&n(1,a=b.computedStyle),"transform"in b&&n(2,u=b.transform),"viewportScale"in b&&n(3,d=b.viewportScale),"svgEl"in b&&n(4,f=b.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Le?[]:Os(o,d)),e.$$.dirty[0]&40&&n(9,s=ot(o.bounds,st/d))},[l,a,u,d,f,o,h,_,g,s,i,k,y,A,M,C,T,V,W,q,w,S,p]}class Us extends ge{constructor(t){super(),he(this,t,Rs,Ns,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const co=new Map([[J.RECTANGLE,xn],[J.POLYGON,Qn],[J.MULTIPOLYGON,Us]]),uo=e=>co.get(e.type),fo=(e,t)=>co.set(e,t);function Vs(e,t,n){let o;const i=Ce();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,f;return Be(()=>(n(6,f=new r({target:a,props:{shape:s.target.selector,computedStyle:o,transform:u,viewportScale:d,svgEl:a.closest("svg")}})),f.$on("change",h=>{f.$$set({shape:h.detail}),i("change",h.detail)}),f.$on("grab",h=>i("grab",h.detail)),f.$on("release",h=>i("release",h.detail)),()=>{f.$destroy()})),e.$$set=h=>{"annotation"in h&&n(0,s=h.annotation),"editor"in h&&n(1,r=h.editor),"style"in h&&n(2,l=h.style),"target"in h&&n(3,a=h.target),"transform"in h&&n(4,u=h.transform),"viewportScale"in h&&n(5,d=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,o=Ve(s,l)),e.$$.dirty&65&&s&&(f==null||f.$set({shape:s.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:u}),e.$$.dirty&96&&f&&f.$set({viewportScale:d}),e.$$.dirty&192&&f&&o&&f.$set({computedStyle:o})},[s,r,l,a,u,d,f,o]}class ho extends ge{constructor(t){super(),he(this,t,Vs,null,re,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Xs(e,t,n){const o=Ce();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return Be(()=>{const d=s.closest("svg"),f=[],h=(_,m,g)=>{d==null||d.addEventListener(_,m,g),f.push(()=>d==null?void 0:d.removeEventListener(_,m,g))};return n(5,u=new r({target:s,props:{addEventListener:h,drawingMode:i,transform:l,viewportScale:a}})),u.$on("create",_=>o("create",_.detail)),()=>{f.forEach(_=>_()),u.$destroy()}}),e.$$set=d=>{"drawingMode"in d&&n(0,i=d.drawingMode),"target"in d&&n(1,s=d.target),"tool"in d&&n(2,r=d.tool),"transform"in d&&n(3,l=d.transform),"viewportScale"in d&&n(4,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:l}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[i,s,r,l,a,u]}class go extends ge{constructor(t){super(),he(this,t,Xs,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function mo(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),u=L("rect"),d=L("rect"),c(o,"class","rect-mask-bg svelte-1a76qe7"),c(o,"x",i=e[1]-e[5]),c(o,"y",s=e[2]-e[5]),c(o,"width",r=e[3]+2*e[5]),c(o,"height",l=e[4]+2*e[5]),c(a,"class","rect-mask-fg svelte-1a76qe7"),c(a,"x",e[1]),c(a,"y",e[2]),c(a,"width",e[3]),c(a,"height",e[4]),c(n,"id",e[6]),c(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),c(u,"class","a9s-outer"),c(u,"mask",`url(#${e[6]})`),c(u,"x",e[1]),c(u,"y",e[2]),c(u,"width",e[3]),c(u,"height",e[4]),c(d,"class","a9s-inner"),c(d,"x",e[1]),c(d,"y",e[2]),c(d,"width",e[3]),c(d,"height",e[4])},m(f,h){Y(f,t,h),F(t,n),F(n,o),F(n,a),Y(f,u,h),Y(f,d,h)},p(f,h){h&34&&i!==(i=f[1]-f[5])&&c(o,"x",i),h&36&&s!==(s=f[2]-f[5])&&c(o,"y",s),h&40&&r!==(r=f[3]+2*f[5])&&c(o,"width",r),h&48&&l!==(l=f[4]+2*f[5])&&c(o,"height",l),h&2&&c(a,"x",f[1]),h&4&&c(a,"y",f[2]),h&8&&c(a,"width",f[3]),h&16&&c(a,"height",f[4]),h&2&&c(u,"x",f[1]),h&4&&c(u,"y",f[2]),h&8&&c(u,"width",f[3]),h&16&&c(u,"height",f[4]),h&2&&c(d,"x",f[1]),h&4&&c(d,"y",f[2]),h&8&&c(d,"width",f[3]),h&16&&c(d,"height",f[4])},d(f){f&&(N(t),N(u),N(d))}}}function Hs(e){let t,n=e[0]&&mo(e);return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){Y(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=mo(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&N(t),n&&n.d()}}}function Gs(e,t,n){let o;const i=Ce();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,d,f,h,_,m,g;const k=M=>{const C=M;u=performance.now(),r==="drag"&&(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,_=d[1]),n(3,m=1),n(4,g=1))},y=M=>{const C=M;d&&(f=l.elementToImage(C.offsetX,C.offsetY),n(1,h=Math.min(f[0],d[0])),n(2,_=Math.min(f[1],d[1])),n(3,m=Math.abs(f[0]-d[0])),n(4,g=Math.abs(f[1]-d[1])))},E=M=>{const C=M,T=performance.now()-u;if(r==="click"){if(T>300)return;d?v():(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,_=d[1]),n(3,m=1),n(4,g=1))}else d&&(T>300||m*g>100?(C.stopPropagation(),v()):(n(0,d=void 0),f=void 0))},v=()=>{if(m*g>15){const M={type:J.RECTANGLE,geometry:{bounds:{minX:h,minY:_,maxX:h+m,maxY:_+g},x:h,y:_,w:m,h:g}};i("create",M)}n(0,d=void 0),f=void 0};Be(()=>{s("pointerdown",k),s("pointermove",y),s("pointerup",E,!0)});const A=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=M=>{"addEventListener"in M&&n(7,s=M.addEventListener),"drawingMode"in M&&n(8,r=M.drawingMode),"transform"in M&&n(9,l=M.transform),"viewportScale"in M&&n(10,a=M.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,o=2/a)},[d,h,_,m,g,o,A,s,r,l,a]}class po extends ge{constructor(t){super(),he(this,t,Gs,Hs,re,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function zt(e){const t=e.slice(),n=t[2].map(o=>o.join(",")).join(" ");return t[19]=n,t}function _o(e){let t,n,o,i,s,r,l,a,u,d,f,h,_,m,g=e[1]&&yo(e);return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),d=L("polygon"),h=L("polygon"),g&&g.c(),m=ke(),c(o,"x",i=e[3].x),c(o,"y",s=e[3].y),c(o,"width",r=e[3].w),c(o,"height",l=e[3].h),c(o,"class","svelte-18wrg3t"),c(a,"points",u=e[19]),c(a,"class","svelte-18wrg3t"),c(n,"id",e[5]),c(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),c(d,"class","a9s-outer"),c(d,"mask",`url(#${e[5]})`),c(d,"points",f=e[19]),c(h,"class","a9s-inner"),c(h,"points",_=e[19])},m(k,y){Y(k,t,y),F(t,n),F(n,o),F(n,a),Y(k,d,y),Y(k,h,y),g&&g.m(k,y),Y(k,m,y)},p(k,y){y&8&&i!==(i=k[3].x)&&c(o,"x",i),y&8&&s!==(s=k[3].y)&&c(o,"y",s),y&8&&r!==(r=k[3].w)&&c(o,"width",r),y&8&&l!==(l=k[3].h)&&c(o,"height",l),y&4&&u!==(u=k[19])&&c(a,"points",u),y&4&&f!==(f=k[19])&&c(d,"points",f),y&4&&_!==(_=k[19])&&c(h,"points",_),k[1]?g?g.p(k,y):(g=yo(k),g.c(),g.m(m.parentNode,m)):g&&(g.d(1),g=null)},d(k){k&&(N(t),N(d),N(h),N(m)),g&&g.d(k)}}}function yo(e){let t,n,o;return{c(){t=L("circle"),c(t,"class","a9s-handle svelte-18wrg3t"),c(t,"cx",n=e[0][0][0]),c(t,"cy",o=e[0][0][1]),c(t,"r",e[4])},m(i,s){Y(i,t,s)},p(i,s){s&1&&n!==(n=i[0][0][0])&&c(t,"cx",n),s&1&&o!==(o=i[0][0][1])&&c(t,"cy",o),s&16&&c(t,"r",i[4])},d(i){i&&N(t)}}}function js(e){let t,n=e[3]&&_o(zt(e));return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){Y(o,t,i),n&&n.m(t,null)},p(o,[i]){o[3]?n?n.p(zt(o),i):(n=_o(zt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&N(t),n&&n.d()}}}const zs=20,Fs=1500;function qs(e,t,n){let o,i,s;const r=Ce();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,f,h=[],_,m,g=!1;const k=C=>{const T=C,{timeStamp:V,offsetX:B,offsetY:W}=T;if(f={timeStamp:V,offsetX:B,offsetY:W},a==="drag"&&h.length===0){const q=u.elementToImage(T.offsetX,T.offsetY);h.push(q),n(10,_=q)}},y=C=>{const T=C;if(m&&clearTimeout(m),h.length>0){if(n(10,_=u.elementToImage(T.offsetX,T.offsetY)),h.length>2){const V=$e(_,h[0])*d;n(1,g=V<zs)}T.pointerType==="touch"&&(m=setTimeout(()=>{v()},Fs))}},E=C=>{const T=C;if(m&&clearTimeout(m),a==="click"){const V=T.timeStamp-f.timeStamp,B=$e([f.offsetX,f.offsetY],[T.offsetX,T.offsetY]);if(V>300||B>15)return;if(g)A();else if(h.length===0){const W=u.elementToImage(T.offsetX,T.offsetY);h.push(W),n(10,_=W)}else h.push(_)}else{if(h.length===1&&$e(h[0],_)<=4){n(0,h=[]),n(10,_=void 0);return}T.stopImmediatePropagation(),g?A():h.push(_)}},v=()=>{if(!_)return;const C=h.slice(0,-1);if(C.length<3)return;const T={type:J.POLYGON,geometry:{bounds:ue(h),points:C}};dt(T)>4&&(n(0,h=[]),n(10,_=void 0),r("create",T))},A=()=>{const C={type:J.POLYGON,geometry:{bounds:ue(h),points:[...h]}};n(0,h=[]),n(10,_=void 0),r("create",C)};Be(()=>{l("pointerdown",k,!0),l("pointermove",y),l("pointerup",E,!0),l("dblclick",v,!0)});const M=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=C=>{"addEventListener"in C&&n(6,l=C.addEventListener),"drawingMode"in C&&n(7,a=C.drawingMode),"transform"in C&&n(8,u=C.transform),"viewportScale"in C&&n(9,d=C.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,o=4/d),e.$$.dirty&1027&&n(2,i=_?g?h:[...h,_]:[]),e.$$.dirty&516&&n(3,s=i.length>0?ot(ue(i),2/d):void 0)},[h,g,i,s,o,M,l,a,u,d,_]}class Ks extends ge{constructor(t){super(),he(this,t,qs,js,re,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Ft=new Map([["rectangle",{tool:po}],["polygon",{tool:Ks}]]),qt=()=>[...Ft.keys()],Kt=e=>Ft.get(e),wo=(e,t,n={})=>Ft.set(e,{tool:t,opts:n});function Ws(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("ellipse"),i=L("ellipse"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"cx",e[2]),c(n,"cy",e[3]),c(n,"rx",e[4]),c(n,"ry",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"cx",e[2]),c(i,"cy",e[3]),c(i,"rx",e[4]),c(i,"ry",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function Zs(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{cx:l,cy:a,rx:u,ry:d}=s;return e.$$set=f=>{"annotation"in f&&n(0,i=f.annotation),"geom"in f&&n(6,s=f.geom),"style"in f&&n(7,r=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ve(i,r))},[i,o,l,a,u,d,s,r]}class Js extends ge{constructor(t){super(),he(this,t,Zs,Ws,re,{annotation:0,geom:6,style:7})}}function Qs(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("line"),i=L("line"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"x1",e[2]),c(n,"y1",e[3]),c(n,"x2",e[4]),c(n,"y2",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"x1",e[2]),c(i,"y1",e[3]),c(i,"x2",e[4]),c(i,"y2",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function xs(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s,[[a,u],[d,f]]=l;return e.$$set=h=>{"annotation"in h&&n(0,i=h.annotation),"geom"in h&&n(6,s=h.geom),"style"in h&&n(7,r=h.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ve(i,r))},[i,o,a,u,d,f,s,r]}class $s extends ge{constructor(t){super(),he(this,t,xs,Qs,re,{annotation:0,geom:6,style:7})}}function bo(e,t,n){const o=e.slice();return o[5]=t[n],o}function Eo(e){let t,n,o;return{c(){t=L("path"),o=L("path"),c(t,"class","a9s-outer"),c(t,"style",n=e[1]?"display:none;":void 0),c(t,"fill-rule","evenodd"),c(t,"d",Pe(e[5])),c(o,"class","a9s-inner"),c(o,"style",e[1]),c(o,"fill-rule","evenodd"),c(o,"d",Pe(e[5]))},m(i,s){Y(i,t,s),Y(i,o,s)},p(i,s){s&2&&n!==(n=i[1]?"display:none;":void 0)&&c(t,"style",n),s&2&&c(o,"style",i[1])},d(i){i&&(N(t),N(o))}}}function er(e){let t,n,o=ve(e[2]),i=[];for(let s=0;s<o.length;s+=1)i[s]=Eo(bo(e,o,s));return{c(){t=L("g");for(let s=0;s<i.length;s+=1)i[s].c();c(t,"class","a9s-annotation"),c(t,"data-id",n=e[0].id)},m(s,r){Y(s,t,r);for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(t,null)},p(s,[r]){if(r&6){o=ve(s[2]);let l;for(l=0;l<o.length;l+=1){const a=bo(s,o,l);i[l]?i[l].p(a,r):(i[l]=Eo(a),i[l].c(),i[l].m(t,null))}for(;l<i.length;l+=1)i[l].d(1);i.length=o.length}r&1&&n!==(n=s[0].id)&&c(t,"data-id",n)},i:j,o:j,d(s){s&&N(t),Ye(i,s)}}}function tr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{polygons:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ve(i,r))},[i,o,l,s,r]}class nr extends ge{constructor(t){super(),he(this,t,tr,er,re,{annotation:0,geom:3,style:4})}}function or(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("polygon"),i=L("polygon"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"points",e[2].map(ir).join(" ")),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"points",e[2].map(sr).join(" ")),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}const ir=e=>e.join(","),sr=e=>e.join(",");function rr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ve(i,r))},[i,o,l,s,r]}class lr extends ge{constructor(t){super(),he(this,t,rr,or,re,{annotation:0,geom:3,style:4})}}function ar(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("path"),s=L("path"),c(n,"class",o=ct(`a9s-outer ${e[1]}`)+" svelte-1w0132l"),c(n,"style",i=e[3]?"display:none;":void 0),c(n,"d",e[2]),c(s,"class",r=ct(`a9s-inner ${e[1]}`)+" svelte-1w0132l"),c(s,"style",e[3]),c(s,"d",e[2]),c(t,"class","a9s-annotation"),c(t,"data-id",l=e[0].id)},m(a,u){Y(a,t,u),F(t,n),F(t,s)},p(a,[u]){u&2&&o!==(o=ct(`a9s-outer ${a[1]}`)+" svelte-1w0132l")&&c(n,"class",o),u&8&&i!==(i=a[3]?"display:none;":void 0)&&c(n,"style",i),u&4&&c(n,"d",a[2]),u&2&&r!==(r=ct(`a9s-inner ${a[1]}`)+" svelte-1w0132l")&&c(s,"class",r),u&8&&c(s,"style",a[3]),u&4&&c(s,"d",a[2]),u&1&&l!==(l=a[0].id)&&c(t,"data-id",l)},i:j,o:j,d(a){a&&N(t)}}}function cr(e,t,n){let o,i,s,{annotation:r}=t,{geom:l}=t,{style:a}=t;return e.$$set=u=>{"annotation"in u&&n(0,r=u.annotation),"geom"in u&&n(4,l=u.geom),"style"in u&&n(5,a=u.style)},e.$$.update=()=>{e.$$.dirty&33&&n(3,o=Ve(r,a)),e.$$.dirty&16&&n(2,i=It(l)),e.$$.dirty&16&&n(1,s=l.closed?"closed":"open")},[r,s,i,o,l,a]}class ur extends ge{constructor(t){super(),he(this,t,cr,ar,re,{annotation:0,geom:4,style:5})}}function fr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("rect"),i=L("rect"),c(n,"class","a9s-outer"),c(n,"style",o=e[5]?"display:none;":void 0),c(n,"x",e[4]),c(n,"y",e[3]),c(n,"width",e[2]),c(n,"height",e[1]),c(i,"class","a9s-inner"),c(i,"style",e[5]),c(i,"x",e[4]),c(i,"y",e[3]),c(i,"width",e[2]),c(i,"height",e[1]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&32&&o!==(o=r[5]?"display:none;":void 0)&&c(n,"style",o),l&16&&c(n,"x",r[4]),l&8&&c(n,"y",r[3]),l&4&&c(n,"width",r[2]),l&2&&c(n,"height",r[1]),l&32&&c(i,"style",r[5]),l&16&&c(i,"x",r[4]),l&8&&c(i,"y",r[3]),l&4&&c(i,"width",r[2]),l&2&&c(i,"height",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function dr(e,t,n){let o,i,s,r,l,{annotation:a}=t,{geom:u}=t,{style:d}=t;return e.$$set=f=>{"annotation"in f&&n(0,a=f.annotation),"geom"in f&&n(6,u=f.geom),"style"in f&&n(7,d=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=Ve(a,d)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:l}=u,i,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,l),n(6,u)))},[a,l,r,s,i,o,u,d]}class hr extends ge{constructor(t){super(),he(this,t,dr,fr,re,{annotation:0,geom:6,style:7})}}const gr={elementToImage:(e,t)=>[e,t]},vo=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),mr=250,So=(e,t)=>{const n=Ce();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<mr){const{x:a,y:u}=Wt(r,e),d=t.getAt(a,u,void 0,2);d?n("click",{originalEvent:r,annotation:d}):n("click",{originalEvent:r})}}}},Wt=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=i+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function Ao(e,t,n){const o=e.slice();return o[39]=t[n],o}function ko(e,t,n){const o=e.slice();return o[42]=t[n],o}function Zt(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Mo(e){let t=e[42],n,o,i=To(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&131072&&re(t,t=s[42])?(be(),G(i,1,1,j),Ee(),i=To(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function pr(e){let t,n;return t=new $s({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function _r(e){let t,n;return t=new ur({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function yr(e){let t,n;return t=new nr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function wr(e){let t,n;return t=new lr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function br(e){let t,n;return t=new hr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Er(e){var o;let t,n;return t=new Js({props:{annotation:e[42],geom:(o=e[45])==null?void 0:o.geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){var l;const r={};s[0]&131072&&(r.annotation=i[42]),s[0]&131072&&(r.geom=(l=i[45])==null?void 0:l.geometry),s[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(U(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function To(e){let t,n,o,i;const s=[Er,br,wr,yr,_r,pr],r=[];function l(a,u){var d,f,h,_,m,g;return((d=a[45])==null?void 0:d.type)===J.ELLIPSE?0:((f=a[45])==null?void 0:f.type)===J.RECTANGLE?1:((h=a[45])==null?void 0:h.type)===J.POLYGON?2:((_=a[45])==null?void 0:_.type)===J.MULTIPOLYGON?3:((m=a[45])==null?void 0:m.type)===J.POLYLINE?4:((g=a[45])==null?void 0:g.type)===J.LINE?5:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),Y(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){G(n),i=!1},d(a){a&&N(o),~t&&r[t].d(a)}}}function Po(e){let t=tt(e[42])&&!e[10](e[42]),n,o,i=t&&Mo(Zt(e));return{c(){i&&i.c(),n=ke()},m(s,r){i&&i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&132096&&(t=tt(s[42])&&!s[10](s[42])),t?i?(i.p(Zt(s),r),r[0]&132096&&U(i,1)):(i=Mo(Zt(s)),i.c(),U(i,1),i.m(n.parentNode,n)):i&&(be(),G(i,1,1,()=>{i=null}),Ee())},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i&&i.d(s)}}}function Lo(e){let t,n,o,i;const s=[Sr,vr],r=[];function l(a,u){return a[6]?0:a[15]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),Y(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){G(n),i=!1},d(a){a&&N(o),~t&&r[t].d(a)}}}function vr(e){let t=`${e[2]}-${e[7]}`,n,o,i=Io(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&132&&re(t,t=`${s[2]}-${s[7]}`)?(be(),G(i,1,1,j),Ee(),i=Io(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function Sr(e){let t,n,o=ve(e[6]),i=[];for(let r=0;r<o.length;r+=1)i[r]=Oo(Ao(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);Y(r,t,l),n=!0},p(r,l){if(l[0]&8659266){o=ve(r[6]);let a;for(a=0;a<o.length;a+=1){const u=Ao(r,o,a);i[a]?(i[a].p(u,l),U(i[a],1)):(i[a]=Oo(u),i[a].c(),U(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)U(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&N(t),Ye(i,r)}}}function Io(e){let t,n;return t=new go({props:{target:e[8],tool:e[15],drawingMode:e[14],transform:e[13],viewportScale:e[18]}}),t.$on("create",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&256&&(s.target=o[8]),i[0]&32768&&(s.tool=o[15]),i[0]&16384&&(s.drawingMode=o[14]),i[0]&8192&&(s.transform=o[13]),i[0]&262144&&(s.viewportScale=o[18]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Co(e){let t,n;return t=new ho({props:{target:e[8],editor:e[39].editor,annotation:e[39].annotation,style:e[1],transform:e[13],viewportScale:e[18]}}),t.$on("change",function(){ie(e[23](e[39].annotation))&&e[23](e[39].annotation).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&256&&(s.target=e[8]),i[0]&64&&(s.editor=e[39].editor),i[0]&64&&(s.annotation=e[39].annotation),i[0]&2&&(s.style=e[1]),i[0]&8192&&(s.transform=e[13]),i[0]&262144&&(s.viewportScale=e[18]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Oo(e){let t=e[39].annotation.id,n,o,i=Co(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&64&&re(t,t=s[39].annotation.id)?(be(),G(i,1,1,j),Ee(),i=Co(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function Ar(e){let t,n,o,i,s,r,l=ve(e[17].filter(e[34])),a=[];for(let f=0;f<l.length;f+=1)a[f]=Po(ko(e,l,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&Lo(e);return{c(){t=L("svg"),n=L("g");for(let f=0;f<a.length;f+=1)a[f].c();o=L("g"),d&&d.c(),c(o,"class","drawing"),c(t,"role","application"),c(t,"tabindex",0),c(t,"class","a9s-annotationlayer"),Te(t,"drawing",e[15]),Te(t,"editing",e[5]),Te(t,"hidden",!e[3]),Te(t,"hover",e[16])},m(f,h){Y(f,t,h),F(t,n);for(let _=0;_<a.length;_+=1)a[_]&&a[_].m(n,null);F(t,o),d&&d.m(o,null),e[35](o),e[36](t),i=!0,s||(r=[Q(t,"pointerup",function(){ie(e[11])&&e[11].apply(this,arguments)}),Q(t,"pointerdown",function(){ie(e[12])&&e[12].apply(this,arguments)}),Q(t,"pointermove",e[24])],s=!0)},p(f,h){if(e=f,h[0]&132098){l=ve(e[17].filter(e[34]));let _;for(_=0;_<l.length;_+=1){const m=ko(e,l,_);a[_]?(a[_].p(m,h),U(a[_],1)):(a[_]=Po(m),a[_].c(),U(a[_],1),a[_].m(n,null))}for(be(),_=l.length;_<a.length;_+=1)u(_);Ee()}e[8]?d?(d.p(e,h),h[0]&256&&U(d,1)):(d=Lo(e),d.c(),U(d,1),d.m(o,null)):d&&(be(),G(d,1,1,()=>{d=null}),Ee()),(!i||h[0]&32768)&&Te(t,"drawing",e[15]),(!i||h[0]&32)&&Te(t,"editing",e[5]),(!i||h[0]&8)&&Te(t,"hidden",!e[3]),(!i||h[0]&65536)&&Te(t,"hover",e[16])},i(f){if(!i){for(let h=0;h<l.length;h+=1)U(a[h]);U(d),i=!0}},o(f){a=a.filter(Boolean);for(let h=0;h<a.length;h+=1)G(a[h]);G(d),i=!1},d(f){f&&N(t),Ye(a,f),d&&d.d(),e[35](null),e[36](null),s=!1,Ae(r)}}}function kr(e,t,n){let o,i,s,r,l,a,u,d,f,h,_,m,g=j,k=()=>(g(),g=rn(b,X=>n(18,m=X)),b);e.$$.on_destroy.push(()=>g());let{drawingEnabled:y}=t,{image:E}=t,{preferredDrawingMode:v}=t,{state:A}=t,{style:M=void 0}=t,{toolName:C=qt()[0]}=t,{user:T}=t,{visible:V=!0}=t,B=0;const W=()=>n(7,B+=1),q=()=>C,w=()=>y;let S,p,b;Be(()=>k(n(9,b=Vn(E,p))));const{hover:I,selection:P,store:O}=A;At(e,I,X=>n(16,f=X)),At(e,P,X=>n(33,h=X)),At(e,O,X=>n(17,_=X));let z,H;const x=X=>{z&&O.unobserve(z);const fe=X.filter(({editable:te})=>te).map(({id:te})=>te);fe.length>0?(n(5,H=fe.map(te=>O.getAnnotation(te)).filter(te=>te&&tt(te))),z=te=>{const{updated:_e}=te.changes;n(5,H=_e==null?void 0:_e.map(ye=>ye.newValue))},O.observe(z,{annotations:fe})):n(5,H=void 0)},Z=X=>{const fe=Cn(),te={id:fe,bodies:[],target:{annotation:fe,selector:X.detail,creator:T,created:new Date}};O.addAnnotation(te),P.setSelected(te.id)},$=X=>fe=>{var We;const{target:te}=X,_e=10*60*1e3,ye=((We=te.creator)==null?void 0:We.id)!==T.id||!te.created||new Date().getTime()-te.created.getTime()>_e;O.updateTarget({...te,selector:fe.detail,created:ye?te.created:new Date,updated:ye?new Date:void 0,updatedBy:ye?T:void 0})},oe=X=>{const{x:fe,y:te}=Wt(X,p),_e=O.getAt(fe,te,void 0,2);_e?f!==_e.id&&I.set(_e.id):I.set(void 0)},se=X=>tt(X);function Se(X){ut[X?"unshift":"push"](()=>{S=X,n(8,S)})}function Me(X){ut[X?"unshift":"push"](()=>{p=X,n(4,p)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,y=X.drawingEnabled),"image"in X&&n(25,E=X.image),"preferredDrawingMode"in X&&n(26,v=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,M=X.style),"toolName"in X&&n(2,C=X.toolName),"user"in X&&n(28,T=X.user),"visible"in X&&n(3,V=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:o,opts:i}=Kt(C)||{tool:void 0,opts:void 0},o,(n(32,i),n(2,C))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(14,s=(i==null?void 0:i.drawingMode)||v),e.$$.dirty[0]&16&&n(13,r=vo(p)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=So(p,O),l,(n(11,a),n(4,p))),e.$$.dirty[1]&4&&x(h.selected),e.$$.dirty[0]&32&&n(6,u=H?H.map(X=>({annotation:X,editor:uo(X.target.selector)})).filter(X=>X.editor):void 0),e.$$.dirty[0]&64&&n(10,d=X=>u&&u.some(fe=>fe.annotation.id===X.id))},[y,M,C,V,p,H,u,B,S,b,d,a,l,r,s,o,f,_,m,I,P,O,Z,$,oe,E,v,A,T,W,q,w,i,h,se,Se,Me]}class Do extends ge{constructor(t){super(),he(this,t,kr,Ar,re,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function No(e,t,n=0,o=e.length-1,i=Mr){for(;o>n;){if(o-n>600){const a=o-n+1,u=t-n+1,d=Math.log(a),f=.5*Math.exp(2*d/3),h=.5*Math.sqrt(d*f*(a-f)/a)*(u-a/2<0?-1:1),_=Math.max(n,Math.floor(t-u*f/a+h)),m=Math.min(o,Math.floor(t+(a-u)*f/a+h));No(e,t,_,m,i)}const s=e[t];let r=n,l=o;for(rt(e,n,t),i(e[o],s)>0&&rt(e,n,o);r<l;){for(rt(e,r,l),r++,l--;i(e[r],s)<0;)r++;for(;i(e[l],s)>0;)l--}i(e[n],s)===0?rt(e,n,l):(l++,rt(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function rt(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Mr(e,t){return e<t?-1:e>t?1:0}class Tr{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!wt(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?i(l):l;wt(t,a)&&(n.leaf?o.push(l):Qt(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!wt(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(wt(t,r)){if(n.leaf||Qt(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Ke([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let l,a,u;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],l=r.pop(),u=!0),o.leaf){const d=Pr(t,o.children,n);if(d!==-1)return o.children.splice(d,1),s.push(o),this._condense(s),this}!u&&!o.leaf&&Qt(o,i)?(s.push(o),r.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],u=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,l;if(s<=r)return l=Ke(t.slice(n,o+1)),qe(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=Ke([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));Yo(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);Yo(t,d,f,a,this.compareMinY);for(let h=d;h<=f;h+=a){const _=Math.min(h+a-1,f);l.children.push(this._build(t,h,_,i-1))}}return qe(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const u=n.children[a],d=Jt(u),f=Cr(t,u)-d;f<r?(r=f,s=d<s?d:s,l=u):f===r&&d<s&&(s=d,l=u)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),at(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),l=Ke(o.children.splice(r,o.children.length-r));l.height=o.height,l.leaf=o.leaf,qe(o,this.toBBox),qe(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=Ke([t,n]),this.data.height=t.height+1,this.data.leaf=!1,qe(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let l=n;l<=o-n;l++){const a=lt(t,0,l,this.toBBox),u=lt(t,l,o,this.toBBox),d=Or(a,u),f=Jt(a)+Jt(u);d<s?(s=d,i=l,r=f<r?f:r):d===s&&f<r&&(r=f,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Lr,s=t.leaf?this.compareMinY:Ir,r=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,s);r<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=lt(t,0,n,s),l=lt(t,o-n,o,s);let a=yt(r)+yt(l);for(let u=n;u<o-n;u++){const d=t.children[u];at(r,t.leaf?s(d):d),a+=yt(r)}for(let u=o-n-1;u>=n;u--){const d=t.children[u];at(l,t.leaf?s(d):d),a+=yt(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)at(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():qe(t[n],this.toBBox)}}function Pr(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function qe(e,t){lt(e,0,e.children.length,t,e)}function lt(e,t,n,o,i){i||(i=Ke(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];at(i,e.leaf?o(r):r)}return i}function at(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 Lr(e,t){return e.minX-t.minX}function Ir(e,t){return e.minY-t.minY}function Jt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function yt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Cr(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 Or(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function Qt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function wt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ke(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Yo(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;No(e,r,t,n,i),s.push(t,r,r,n)}}const Dr=()=>{const e=new Tr,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!nt(f))return;const{minX:h,minY:_,maxX:m,maxY:g}=f.selector.geometry.bounds,k={minX:h,minY:_,maxX:m,maxY:g,target:f};e.insert(k),t.set(f.annotation,k)},s=f=>{if(!nt(f))return;const h=t.get(f.annotation);h&&e.remove(h),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,h,_,m=0)=>{const k=e.search({minX:f-m,minY:h-m,maxX:f+m,maxY:h+m}).map(y=>y.target).filter(y=>y.selector.type===J.RECTANGLE||_n(y.selector,f,h,m));return k.length>0?(k.sort((y,E)=>dt(y.selector)-dt(E.selector)),k):[]},getIntersecting:(f,h,_,m)=>e.search({minX:f,minY:h,maxX:f+_,maxY:h+m}).map(g=>g.target),insert:i,remove:s,set:(f,h=!0)=>{h&&o();const _=f.reduce((m,g)=>{if(nt(g)){const{minX:k,minY:y,maxX:E,maxY:v}=g.selector.geometry.bounds;return[...m,{minX:k,minY:y,maxX:E,maxY:v,target:g}]}else return m},[]);_.forEach(m=>t.set(m.target.annotation,m)),e.load(_)},size:()=>e.all().length,update:(f,h)=>{s(f),i(h)}}},Bo=e=>{const t=Xi(),n=Dr(),o=Mi(t,e.userSelectAction,e.adapter),i=ki(t),s=Fi();return t.observe(({changes:a})=>{n.set((a.created||[]).map(u=>u.target),!1),(a.deleted||[]).forEach(u=>n.remove(u.target)),(a.updated||[]).forEach(({oldValue:u,newValue:d})=>n.update(u.target,d.target))}),{store:{...t,getAt:(a,u,d,f)=>{const h=n.getAt(a,u,d,f);if(d)return h.map(m=>t.getAnnotation(m.annotation)).filter(Boolean).filter(d)[0];{const _=h[0];return _?t.getAnnotation(_.annotation):void 0}},getIntersecting:(a,u,d,f)=>n.getIntersecting(a,u,d,f).map(h=>t.getAnnotation(h.annotation)).filter(Boolean)},selection:o,hover:i,viewport:s}},Ro=e=>{const t=Bo(e);return{...t,store:Hi(t.store)}},Uo=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(r,l,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=u}return o/81},Vo=e=>{const t=Uo(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"?Vo(e):n),Xo=(e,t)=>({...e,drawingEnabled:e.drawingEnabled===void 0?t.drawingEnabled:e.drawingEnabled,drawingMode:e.drawingMode||t.drawingMode,userSelectAction:e.userSelectAction||t.userSelectAction,theme:e.theme||t.theme}),$t=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Ho=(e,t)=>{const n=t||document,o=r=>{const l=r;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},i=r=>{const l=r;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},s=()=>{$t?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return $t?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Nr=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=Xo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Nt.EDIT,theme:"light"}),i=Ro(o),{selection:s,store:r}=i,l=zi(r,o.initialHistory),a=qi(i,l,o.adapter,o.autoSave),u=document.createElement("DIV");u.style.position="relative",u.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(u,n),u.appendChild(n);const d=Ho(l);let f=ns();xt(n,u,o.theme);const h=new Do({target:u,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});h.$on("click",w=>{const{originalEvent:S,annotation:p}=w.detail;p?s.userSelect(p.id,S):s.isEmpty()||s.clear()});const _=Wi(i,l,o.adapter),m=()=>h.cancelDrawing(),g=()=>{h.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),l.destroy()},k=()=>h.getDrawingTool(),y=()=>f,E=()=>h.isDrawingEnabled(),v=(w,S,p)=>wo(w,S,p),A=(w,S)=>fo(w,S),M=w=>{if(!Kt(w))throw`No drawing tool named ${w}`;h.$set({toolName:w})},C=w=>h.$set({drawingEnabled:w}),T=w=>{console.warn("Filter not implemented yet")},V=w=>h.$set({style:w}),B=w=>xt(n,u,w),W=w=>{f=w,h.$set({user:w})},q=w=>h.$set({visible:w});return{..._,cancelDrawing:m,destroy:g,getDrawingTool:k,getUser:y,isDrawingEnabled:E,listDrawingTools:qt,on:a.on,off:a.off,registerDrawingTool:v,registerShapeEditor:A,setDrawingEnabled:C,setDrawingTool:M,setFilter:T,setStyle:V,setTheme:B,setUser:W,setVisible:q,element:u,state:i}};D.Editor=_t,D.EditorMount=ho,D.Handle=Xe,D.IdentityTransform=gr,D.PolygonEditor=Qn,D.RectangleEditor=xn,D.RectangleUtil=vn,D.RubberbandRectangle=po,D.SVGAnnotationLayer=Do,D.ShapeType=J,D.ToolMount=go,D.UserSelectAction=Nt,D.W3CImageFormat=as,D.addEventListeners=So,D.approximateAsPolygon=ht,D.boundsFromMultiPolygonElements=et,D.boundsFromPoints=ue,D.chainStyles=Ji,D.computeArea=dt,D.computePolygonArea=Qe,D.computeSVGPath=It,D.computeStyle=Zi,D.createBody=Oi,D.createImageAnnotator=Nr,D.createImageAnnotatorState=Bo,D.createSVGTransform=vo,D.createSvelteImageAnnotatorState=Ro,D.defaultColorProvider=ls,D.detectTheme=Vo,D.distance=$e,D.enableResponsive=Vn,D.fillDefaults=Xo,D.getAllCorners=wn,D.getEditor=uo,D.getMaskDimensions=ot,D.getSVGPoint=Wt,D.getTool=Kt,D.initKeyboardCommands=Ho,D.intersects=_n,D.isImageAnnotation=tt,D.isImageAnnotationTarget=nt,D.isMac=$t,D.isPointInPolygon=xe,D.isTouch=Le,D.listDrawingTools=qt,D.multipolygonElementToPath=Pe,D.parseFragmentSelector=Sn,D.parseSVGSelector=Pn,D.parseW3CImageAnnotation=Rn,D.pointsToPath=yn,D.registerEditor=fo,D.registerShapeUtil=Ue,D.registerTool=wo,D.sampleBrightness=Uo,D.serializeFragmentSelector=An,D.serializeSVGSelector=Ln,D.serializeW3CImageAnnotation=Un,D.setTheme=xt,D.simplifyMultiPolygon=ri,D.simplifyPoints=Lt,D.simplifyPolygon=ai,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=annotorious.js.map
|