@annotorious/annotorious 3.0.2 → 3.0.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.
@@ -1,2 +1,2 @@
1
- (function(L,X){typeof exports=="object"&&typeof module<"u"?X(exports):typeof define=="function"&&define.amd?define(["exports"],X):(L=typeof globalThis<"u"?globalThis:L||self,X(L.Annotorious={}))})(this,function(L){"use strict";var Fi=Object.defineProperty;var Hi=(L,X,me)=>X in L?Fi(L,X,{enumerable:!0,configurable:!0,writable:!0,value:me}):L[X]=me;var Mt=(L,X,me)=>Hi(L,typeof X!="symbol"?X+"":X,me);function X(){}function me(e,t){for(const n in t)e[n]=t[n];return e}function Lt(e){return e()}function kt(){return Object.create(null)}function ce(e){e.forEach(Lt)}function q(e){return typeof e=="function"}function x(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Gn(e){return Object.keys(e).length===0}function It(e,...t){if(e==null){for(const o of t)o(void 0);return X}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function it(e,t,n){e.$$.on_destroy.push(It(t,n))}function jn(e,t,n,o){if(e){const i=Ot(e,t,n,o);return e[0](i)}}function Ot(e,t,n,o){return e[1]&&o?me(n.ctx.slice(),e[1](o(t))):n.ctx}function zn(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 r=[],s=Math.max(t.dirty.length,i.length);for(let l=0;l<s;l+=1)r[l]=t.dirty[l]|i[l];return r}return t.dirty|i}return t.dirty}function Fn(e,t,n,o,i,r){if(i){const s=Ot(t,n,o,r);e.p(s,i)}}function Hn(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 Bt(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function je(e){return e??""}function fe(e,t){e.appendChild(t)}function O(e,t,n){e.insertBefore(t,n||null)}function I(e){e.parentNode&&e.parentNode.removeChild(e)}function rt(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function N(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function Pt(e){return document.createTextNode(e)}function re(){return Pt(" ")}function se(){return Pt("")}function W(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function d(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Wn(e){return Array.from(e.childNodes)}function pe(e,t,n){e.classList.toggle(t,!!n)}function Kn(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Oe;function Be(e){Oe=e}function Dt(){if(!Oe)throw new Error("Function called outside component initialization");return Oe}function Pe(e){Dt().$$.on_mount.push(e)}function be(){const e=Dt();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const r=Kn(t,n,{cancelable:o});return i.slice().forEach(s=>{s.call(e,r)}),!r.defaultPrevented}return!0}}function ge(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const Ee=[],ze=[];let Ae=[];const Yt=[],qn=Promise.resolve();let st=!1;function Jn(){st||(st=!0,qn.then(Rt))}function lt(e){Ae.push(e)}const at=new Set;let Se=0;function Rt(){if(Se!==0)return;const e=Oe;do{try{for(;Se<Ee.length;){const t=Ee[Se];Se++,Be(t),Qn(t.$$)}}catch(t){throw Ee.length=0,Se=0,t}for(Be(null),Ee.length=0,Se=0;ze.length;)ze.pop()();for(let t=0;t<Ae.length;t+=1){const n=Ae[t];at.has(n)||(at.add(n),n())}Ae.length=0}while(Ee.length);for(;Yt.length;)Yt.pop()();st=!1,at.clear(),Be(e)}function Qn(e){if(e.fragment!==null){e.update(),ce(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(lt)}}function Zn(e){const t=[],n=[];Ae.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),Ae=t}const Fe=new Set;let we;function le(){we={r:0,c:[],p:we}}function ae(){we.r||ce(we.c),we=we.p}function P(e,t){e&&e.i&&(Fe.delete(e),e.i(t))}function U(e,t,n,o){if(e&&e.o){if(Fe.has(e))return;Fe.add(e),we.c.push(()=>{Fe.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function Te(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function te(e){e&&e.c()}function $(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),lt(()=>{const r=e.$$.on_mount.map(Lt).filter(q);e.$$.on_destroy?e.$$.on_destroy.push(...r):ce(r),e.$$.on_mount=[]}),i.forEach(lt)}function ee(e,t){const n=e.$$;n.fragment!==null&&(Zn(n.after_update),ce(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function xn(e,t){e.$$.dirty[0]===-1&&(Ee.push(e),Jn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function ne(e,t,n,o,i,r,s=null,l=[-1]){const a=Oe;Be(e);const c=e.$$={fragment:null,ctx:[],props:r,update:X,not_equal:i,bound:kt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:kt(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};s&&s(c.root);let u=!1;if(c.ctx=n?n(e,t.props||{},(f,g,...h)=>{const m=h.length?h[0]:g;return c.ctx&&i(c.ctx[f],c.ctx[f]=m)&&(!c.skip_bound&&c.bound[f]&&c.bound[f](m),u&&xn(e,f)),g}):[],c.update(),u=!0,ce(c.before_update),c.fragment=o?o(c.ctx):!1,t.target){if(t.hydrate){const f=Wn(t.target);c.fragment&&c.fragment.l(f),f.forEach(I)}else c.fragment&&c.fragment.c();t.intro&&P(e.$$.fragment),$(e,t.target,t.anchor),Rt()}Be(a)}class oe{constructor(){Mt(this,"$$");Mt(this,"$$set")}$destroy(){ee(this,1),this.$destroy=X}$on(t,n){if(!q(n))return X;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&&!Gn(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $n="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($n);var K=(e=>(e.ELLIPSE="ELLIPSE",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(K||{});const ct={},He=(e,t)=>ct[e]=t,We=e=>ct[e.type].area(e),Ct=(e,t,n)=>ct[e.type].intersects(e,t,n),De=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([r,s])=>{t=Math.min(t,r),n=Math.min(n,s),o=Math.max(o,r),i=Math.max(i,s)}),{minX:t,minY:n,maxX:o,maxY:i}},eo={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:r,ry:s}=e.geometry,l=0,a=Math.cos(l),c=Math.sin(l),u=t-o,f=n-i,g=a*u+c*f,h=c*u-a*f;return g*g/(r*r)+h*h/(s*s)<=1}};He(K.ELLIPSE,eo);const to={area:e=>{const{points:t}=e.geometry;let n=0,o=t.length-1;for(let i=0;i<t.length;i++)n+=(t[o][0]+t[i][0])*(t[o][1]-t[i][1]),o=i;return Math.abs(.5*n)},intersects:(e,t,n)=>{const{points:o}=e.geometry;let i=!1;for(let r=0,s=o.length-1;r<o.length;s=r++){const l=o[r][0],a=o[r][1],c=o[s][0],u=o[s][1];a>n!=u>n&&t<(c-l)*(n-a)/(u-a)+l&&(i=!i)}return i}};He(K.POLYGON,to);const Xt={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};He(K.RECTANGLE,Xt);const Ye=e=>Re(e.target),Re=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},Ut=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[r,s,l,a,c,u,f]=i;if(s!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[g,h,m,y]=[a,c,u,f].map(parseFloat);return{type:K.RECTANGLE,geometry:{x:g,y:h,w:m,h:y,bounds:{minX:g,minY:t?h-y:h,maxX:g+m,maxY:t?h:h+y}}}},Nt=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}`}},Vt="http://www.w3.org/2000/svg",Gt=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},no=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Vt}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},oo=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Vt),i=n.lookupNamespaceURI(null);return o||i?Gt(n).firstChild:Gt(no(n)).firstChild},io=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(r=>r.split(",").map(parseFloat));return{type:K.POLYGON,geometry:{points:i,bounds:De(i)}}},ro=e=>{const t=oo(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),r=parseFloat(t.getAttribute("ry")),s={minX:n-i,minY:o-r,maxX:n+i,maxY:o+r};return{type:K.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:r,bounds:s}}},jt=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return io(t);if(t.includes("<ellipse "))return ro(t);throw"Unsupported SVG shape: "+t},zt=e=>{let t;if(e.type===K.POLYGON){const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`}else if(e.type===K.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`};for(var J=[],ft=0;ft<256;++ft)J.push((ft+256).toString(16).slice(1));function so(e,t=0){return(J[e[t+0]]+J[e[t+1]]+J[e[t+2]]+J[e[t+3]]+"-"+J[e[t+4]]+J[e[t+5]]+"-"+J[e[t+6]]+J[e[t+7]]+"-"+J[e[t+8]]+J[e[t+9]]+"-"+J[e[t+10]]+J[e[t+11]]+J[e[t+12]]+J[e[t+13]]+J[e[t+14]]+J[e[t+15]]).toLowerCase()}var Ke,lo=new Uint8Array(16);function ao(){if(!Ke&&(Ke=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ke))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ke(lo)}var co=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ft={randomUUID:co};function Ht(e,t,n){if(Ft.randomUUID&&!t&&!e)return Ft.randomUUID();e=e||{};var o=e.random||(e.rng||ao)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,so(o)}var Wt=Object.prototype.hasOwnProperty;function ye(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--&&ye(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Wt.call(e,n)&&++o&&!Wt.call(t,n)||!(n in t)||!ye(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function ut(){}function fo(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const ve=[];function dt(e,t=ut){let n;const o=new Set;function i(l){if(fo(e,l)&&(e=l,n)){const a=!ve.length;for(const c of o)c[1](),ve.push(c,e);if(a){for(let c=0;c<ve.length;c+=2)ve[c][0](ve[c+1]);ve.length=0}}}function r(l){i(l(e))}function s(l,a=ut){const c=[l,a];return o.add(c),o.size===1&&(n=t(i,r)||ut),l(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:r,subscribe:s}}const uo=e=>{const{subscribe:t,set:n}=dt();let o;return t(i=>o=i),e.observe(({changes:i})=>{if(o){(i.deleted||[]).some(s=>s.id===o)&&n(void 0);const r=(i.updated||[]).find(({oldValue:s})=>s.id===o);r&&n(r.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Kt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Kt||{});const qe={selected:[]},ho=(e,t)=>{const{subscribe:n,set:o}=dt(qe);let i=t,r=qe;n(h=>r=h);const s=()=>{ye(r,qe)||o(qe)},l=()=>{var h;return((h=r.selected)==null?void 0:h.length)===0},a=h=>{if(l())return!1;const m=typeof h=="string"?h:h.id;return r.selected.some(y=>y.id===m)},c=(h,m)=>{const y=e.getAnnotation(h);if(!y){console.warn("Invalid selection: "+h);return}switch(qt(y,i)){case"EDIT":o({selected:[{id:h,editable:!0}],event:m});break;case"SELECT":o({selected:[{id:h}],event:m});break;default:o({selected:[],event:m})}},u=(h,m)=>{const y=Array.isArray(h)?h:[h],v=y.map(p=>e.getAnnotation(p)).filter(p=>!!p);o({selected:v.map(p=>{const w=m===void 0?qt(p,i)==="EDIT":m;return{id:p.id,editable:w}})}),v.length!==y.length&&console.warn("Invalid selection",h)},f=h=>{if(l())return!1;const{selected:m}=r;m.some(({id:y})=>h.includes(y))&&o({selected:m.filter(({id:y})=>!h.includes(y))})},g=h=>i=h;return e.observe(({changes:h})=>f((h.deleted||[]).map(m=>m.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return i},clear:s,isEmpty:l,isSelected:a,setSelected:u,setUserSelectAction:g,subscribe:n,userSelect:c}},qt=(e,t)=>typeof t=="function"?t(e):t||"EDIT";for(var Q=[],ht=0;ht<256;++ht)Q.push((ht+256).toString(16).slice(1));function go(e,t=0){return(Q[e[t+0]]+Q[e[t+1]]+Q[e[t+2]]+Q[e[t+3]]+"-"+Q[e[t+4]]+Q[e[t+5]]+"-"+Q[e[t+6]]+Q[e[t+7]]+"-"+Q[e[t+8]]+Q[e[t+9]]+"-"+Q[e[t+10]]+Q[e[t+11]]+Q[e[t+12]]+Q[e[t+13]]+Q[e[t+14]]+Q[e[t+15]]).toLowerCase()}var Je,mo=new Uint8Array(16);function po(){if(!Je&&(Je=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Je))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Je(mo)}var yo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Jt={randomUUID:yo};function _o(e,t,n){if(Jt.randomUUID&&!t&&!e)return Jt.randomUUID();e=e||{};var o=e.random||(e.rng||po)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,go(o)}const wo=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},bo=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Eo=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!ye(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Ao=(e,t)=>!ye(e.target,t.target),Qt=(e,t)=>{const n=wo(e,t),o=bo(e,t),i=Eo(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:Ao(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var H=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e))(H||{});const So=(e,t)=>{var n,o;const{changes:i,origin:r}=t;if(!(!e.options.origin||e.options.origin===r))return!1;if(e.options.ignore){const{ignore:s}=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(u=>l(u.bodiesCreated)||l(u.bodiesDeleted)||l(u.bodiesUpdated)),c=(o=i.updated)==null?void 0:o.some(u=>u.targetUpdated);if(s==="BODY_ONLY"&&a&&!c||s==="TARGET_ONLY"&&c&&!a)return!1}}if(e.options.annotations){const s=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=>s.has(l))}else return!0},To=(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)),r=new Set((t.deleted||[]).map(f=>f.id)),s=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=>!r.has(f.id)).map(f=>s.has(f.id)?t.updated.find(({oldValue:g})=>g.id===f.id).newValue:f),...t.created||[]],c=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],u=[...(e.updated||[]).filter(({newValue:f})=>!r.has(f.id)).map(f=>{const{oldValue:g,newValue:h}=f;if(s.has(h.id)){const m=t.updated.find(y=>y.oldValue.id===h.id).newValue;return Qt(g,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:c,updated:u}},gt=e=>{const t=e.id===void 0?_o():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},vo=e=>e.id!==void 0,Mo=()=>{const e=new Map,t=new Map,n=[],o=(E,A={})=>n.push({onChange:E,options:A}),i=E=>{const A=n.findIndex(S=>S.onChange==E);A>-1&&n.splice(A,1)},r=(E,A)=>{const S={origin:E,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...e.values()]};n.forEach(T=>{So(T,S)&&T.onChange(S)})},s=(E,A=H.LOCAL)=>{if(E.id&&e.get(E.id))throw Error(`Cannot add annotation ${E.id} - exists already`);{const S=gt(E);e.set(S.id,S),S.bodies.forEach(T=>t.set(T.id,S.id)),r(A,{created:[S]})}},l=(E,A)=>{const S=gt(typeof E=="string"?A:E),T=typeof E=="string"?E:E.id,V=T&&e.get(T);if(V){const C=Qt(V,S);return T===S.id?e.set(T,S):(e.delete(T),e.set(S.id,S)),V.bodies.forEach(Z=>t.delete(Z.id)),S.bodies.forEach(Z=>t.set(Z.id,S.id)),C}else console.warn(`Cannot update annotation ${T} - does not exist`)},a=(E,A=H.LOCAL,S=H.LOCAL)=>{const T=vo(A)?S:A,V=l(E,A);V&&r(T,{updated:[V]})},c=(E,A=H.LOCAL)=>{const S=E.reduce((T,V)=>{const C=l(V);return C?[...T,C]:T},[]);S.length>0&&r(A,{updated:S})},u=(E,A=H.LOCAL)=>{const S=e.get(E.annotation);if(S){const T={...S,bodies:[...S.bodies,E]};e.set(S.id,T),t.set(E.id,T.id),r(A,{updated:[{oldValue:S,newValue:T,bodiesCreated:[E]}]})}else console.warn(`Attempt to add body to missing annotation: ${E.annotation}`)},f=()=>[...e.values()],g=(E=H.LOCAL)=>{const A=[...e.values()];e.clear(),t.clear(),r(E,{deleted:A})},h=(E,A=!0,S=H.LOCAL)=>{const T=E.map(gt);if(A){const V=[...e.values()];e.clear(),t.clear(),T.forEach(C=>{e.set(C.id,C),C.bodies.forEach(Z=>t.set(Z.id,C.id))}),r(S,{created:T,deleted:V})}else{const V=E.reduce((C,Z)=>{const _e=Z.id&&e.get(Z.id);return _e?[...C,_e]:C},[]);if(V.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${V.map(C=>C.id).join(", ")}`);T.forEach(C=>{e.set(C.id,C),C.bodies.forEach(Z=>t.set(Z.id,C.id))}),r(S,{created:T})}},m=E=>{const A=typeof E=="string"?E:E.id,S=e.get(A);if(S)return e.delete(A),S.bodies.forEach(T=>t.delete(T.id)),S;console.warn(`Attempt to delete missing annotation: ${A}`)},y=(E,A=H.LOCAL)=>{const S=m(E);S&&r(A,{deleted:[S]})},v=(E,A=H.LOCAL)=>{const S=E.reduce((T,V)=>{const C=m(V);return C?[...T,C]:T},[]);S.length>0&&r(A,{deleted:S})},p=E=>{const A=e.get(E.annotation);if(A){const S=A.bodies.find(T=>T.id===E.id);if(S){t.delete(S.id);const T={...A,bodies:A.bodies.filter(V=>V.id!==E.id)};return e.set(A.id,T),{oldValue:A,newValue:T,bodiesDeleted:[S]}}else console.warn(`Attempt to delete missing body ${E.id} from annotation ${E.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${E.annotation}`)},w=(E,A=H.LOCAL)=>{const S=p(E);S&&r(A,{updated:[S]})},_=(E,A=H.LOCAL)=>{const S=E.map(T=>p(T)).filter(Boolean);S.length>0&&r(A,{updated:S})},b=E=>{const A=e.get(E);return A?{...A}:void 0},Y=E=>{const A=t.get(E);if(A){const S=b(A).bodies.find(T=>T.id===E);if(S)return S;console.error(`Store integrity error: body ${E} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${E}`)},G=(E,A)=>{if(E.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const S=e.get(E.annotation);if(S){const T=S.bodies.find(C=>C.id===E.id),V={...S,bodies:S.bodies.map(C=>C.id===T.id?A:C)};return e.set(S.id,V),T.id!==A.id&&(t.delete(T.id),t.set(A.id,V.id)),{oldValue:S,newValue:V,bodiesUpdated:[{oldBody:T,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${E.annotation}`)},j=(E,A,S=H.LOCAL)=>{const T=G(E,A);T&&r(S,{updated:[T]})},z=(E,A=H.LOCAL)=>{const S=E.map(T=>G({id:T.id,annotation:T.annotation},T)).filter(Boolean);r(A,{updated:S})},D=E=>{const A=e.get(E.annotation);if(A){const S={...A,target:{...A.target,...E}};return e.set(A.id,S),{oldValue:A,newValue:S,targetUpdated:{oldTarget:A.target,newTarget:E}}}else console.warn(`Attempt to update target on missing annotation: ${E.annotation}`)};return{addAnnotation:s,addBody:u,all:f,bulkAddAnnotation:h,bulkDeleteAnnotation:v,bulkDeleteBodies:_,bulkUpdateAnnotation:c,bulkUpdateBodies:z,bulkUpdateTargets:(E,A=H.LOCAL)=>{const S=E.map(T=>D(T)).filter(Boolean);S.length>0&&r(A,{updated:S})},clear:g,deleteAnnotation:y,deleteBody:w,getAnnotation:b,getBody:Y,observe:o,unobserve:i,updateAnnotation:a,updateBody:j,updateTarget:(E,A=H.LOCAL)=>{const S=D(E);S&&r(A,{updated:[S]})}}},Lo=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let ko=()=>({emit(e,...t){for(let n=0,o=this.events[e]||[],i=o.length;n<i;n++)o[n](...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 Io=250,Oo=e=>{const t=ko(),n=[];let o=-1,i=!1,r=0;const s=h=>{if(!i){const{changes:m}=h,y=performance.now();if(y-r>Io)n.splice(o+1),n.push(m),o=n.length-1;else{const v=n.length-1;n[v]=To(n[v],m)}r=y}i=!1};e.observe(s,{origin:H.LOCAL});const l=h=>h&&h.length>0&&e.bulkDeleteAnnotation(h),a=h=>h&&h.length>0&&e.bulkAddAnnotation(h,!1),c=h=>h&&h.length>0&&e.bulkUpdateAnnotation(h.map(({oldValue:m})=>m)),u=h=>h&&h.length>0&&e.bulkUpdateAnnotation(h.map(({newValue:m})=>m)),f=h=>h&&h.length>0&&e.bulkAddAnnotation(h,!1),g=h=>h&&h.length>0&&e.bulkDeleteAnnotation(h);return{canRedo:()=>n.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(s),on:(h,m)=>t.on(h,m),redo:()=>{if(n.length-1>o){i=!0;const{created:h,updated:m,deleted:y}=n[o+1];a(h),u(m),g(y),t.emit("redo",n[o+1]),o+=1}},undo:()=>{if(o>-1){i=!0;const{created:h,updated:m,deleted:y}=n[o];l(h),c(m),f(y),t.emit("undo",n[o]),o-=1}}}},Bo=()=>{const{subscribe:e,set:t}=dt([]);return{subscribe:e,set:t}},Po=(e,t,n,o)=>{const{store:i,selection:r,hover:s,viewport:l}=e,a=new Map;let c=[],u,f;const g=(p,w)=>{a.has(p)?a.get(p).push(w):a.set(p,[w])},h=(p,w)=>{const _=a.get(p);if(_){const b=_.indexOf(w);b!==-1&&_.splice(b,1)}},m=(p,w,_)=>{a.has(p)&&setTimeout(()=>{a.get(p).forEach(b=>{if(n){const Y=Array.isArray(w)?w.map(j=>n.serialize(j)):n.serialize(w),G=_?_ instanceof PointerEvent?_:n.serialize(_):void 0;b(Y,G)}else b(w,_)})},1)},y=()=>{const{selected:p}=r,w=(p||[]).map(({id:_})=>i.getAnnotation(_));w.forEach(_=>{const b=c.find(Y=>Y.id===_.id);(!b||!ye(b,_))&&m("updateAnnotation",_,b)}),c=c.map(_=>w.find(({id:Y})=>Y===_.id)||_)};r.subscribe(({selected:p})=>{if(!(c.length===0&&p.length===0)){if(c.length===0&&p.length>0)c=p.map(({id:w})=>i.getAnnotation(w));else if(c.length>0&&p.length===0)c.forEach(w=>{const _=i.getAnnotation(w.id);_&&!ye(_,w)&&m("updateAnnotation",_,w)}),c=[];else{const w=new Set(c.map(b=>b.id)),_=new Set(p.map(({id:b})=>b));c.filter(b=>!_.has(b.id)).forEach(b=>{const Y=i.getAnnotation(b.id);Y&&!ye(Y,b)&&m("updateAnnotation",Y,b)}),c=[...c.filter(b=>_.has(b.id)),...p.filter(({id:b})=>!w.has(b)).map(({id:b})=>i.getAnnotation(b))]}m("selectionChanged",c)}}),s.subscribe(p=>{!u&&p?m("mouseEnterAnnotation",i.getAnnotation(p)):u&&!p?m("mouseLeaveAnnotation",i.getAnnotation(u)):u&&p&&(m("mouseLeaveAnnotation",i.getAnnotation(u)),m("mouseEnterAnnotation",i.getAnnotation(p))),u=p}),l==null||l.subscribe(p=>m("viewportIntersect",p.map(w=>i.getAnnotation(w)))),i.observe(p=>{o&&(f&&clearTimeout(f),f=setTimeout(y,1e3));const{created:w,deleted:_}=p.changes;(w||[]).forEach(b=>m("createAnnotation",b)),(_||[]).forEach(b=>m("deleteAnnotation",b)),(p.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:Y})=>{const G=c.find(j=>j.id===b.id)||b;c=c.map(j=>j.id===b.id?Y:j),m("updateAnnotation",Y,G)})},{origin:H.LOCAL}),i.observe(p=>{if(c){const w=new Set(c.map(b=>b.id)),_=(p.changes.updated||[]).filter(({newValue:b})=>w.has(b.id)).map(({newValue:b})=>b);_.length>0&&(c=c.map(b=>_.find(G=>G.id===b.id)||b))}},{origin:H.REMOTE});const v=p=>w=>{const{updated:_}=w;p?(_||[]).forEach(b=>m("updateAnnotation",b.oldValue,b.newValue)):(_||[]).forEach(b=>m("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",v(!0)),t.on("redo",v(!1)),{on:g,off:h,emit:m}},Do=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:r}=e.parse(o);return r?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Yo=(e,t,n)=>{const{store:o,selection:i}=e,r=p=>{if(n){const{parsed:w,error:_}=n.parse(p);w?o.addAnnotation(w,H.REMOTE):console.error(_)}else o.addAnnotation(p,H.REMOTE)},s=()=>i.clear(),l=()=>o.clear(),a=p=>{const w=o.getAnnotation(p);return n&&w?n.serialize(w):w},c=()=>n?o.all().map(n.serialize):o.all(),u=()=>{var p;const w=(((p=i.selected)==null?void 0:p.map(_=>_.id))||[]).map(_=>o.getAnnotation(_)).filter(Boolean);return n?w.map(n.serialize):w},f=(p,w=!0)=>fetch(p).then(_=>_.json()).then(_=>(h(_,w),_)),g=p=>{if(typeof p=="string"){const w=o.getAnnotation(p);if(o.deleteAnnotation(p),w)return n?n.serialize(w):w}else{const w=n?n.parse(p).parsed:p;if(w)return o.deleteAnnotation(w),p}},h=(p,w=!0)=>{if(n){const{parsed:_,failed:b}=Do(n)(p);b.length>0&&console.warn(`Discarded ${b.length} invalid annotations`,b),o.bulkAddAnnotation(_,w,H.REMOTE)}else o.bulkAddAnnotation(p,w,H.REMOTE)},m=(p,w)=>{p?i.setSelected(p,w):i.clear()},y=p=>{i.clear(),i.setUserSelectAction(p)},v=p=>{if(n){const w=n.parse(p).parsed,_=n.serialize(o.getAnnotation(w.id));return o.updateAnnotation(w),_}else{const w=o.getAnnotation(p.id);return o.updateAnnotation(p),w}};return{addAnnotation:r,cancelSelected:s,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:c,getSelected:u,loadAnnotations:f,redo:t.redo,removeAnnotation:g,setAnnotations:h,setSelected:m,setUserSelectAction:y,undo:t.undo,updateAnnotation:v}},Ro="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Co=e=>crypto.getRandomValues(new Uint8Array(e)),Xo=(e,t,n)=>{let o=(2<<Math.log(e.length-1)/Math.LN2)-1,i=-~(1.6*o*t/e.length);return(r=t)=>{let s="";for(;;){let l=n(i),a=i;for(;a--;)if(s+=e[l[a]&o]||"",s.length===r)return s}}},Uo=(e,t=21)=>Xo(e,t,Co),No=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;)t+=Ro[n[e]&63];return t};const Vo=()=>({isGuest:!0,id:Uo("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Go=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let r=t.charCodeAt(o);n=(n<<5)-n+r,n|=0}return`${n}`},Zt=e=>e?typeof e=="object"?{...e}:e:void 0,jo=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:r,value:s,created:l,modified:a,creator:c,...u}=n;return{id:o||`temp-${Go(n)}`,annotation:t,type:i,purpose:r,value:s,creator:Zt(c),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...u}}),zo=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:r,...s}=t,l={...s,created:i==null?void 0:i.toISOString(),modified:r==null?void 0:r.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l});No();const Fo=(e,t={strict:!0,invertY:!1})=>({parse:i=>xt(i,t),serialize:i=>$t(i,e,t)}),xt=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Ht(),{creator:o,created:i,modified:r,body:s,...l}=e,a=jo(s||[],n),c=Array.isArray(e.target)?e.target[0]:e.target,u=Array.isArray(c.selector)?c.selector[0]:c.selector,f=(u==null?void 0:u.type)==="FragmentSelector"?Ut(u,t.invertY):(u==null?void 0:u.type)==="SvgSelector"?jt(u):void 0;return f||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Zt(o),updated:r?new Date(r):void 0,...Array.isArray(l.target)?l.target[0]:l.target,annotation:n,selector:f||u}}}:{error:Error(`Invalid selector: ${JSON.stringify(u)}`)}},$t=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:r,updated:s,updatedBy:l,...a}=e.target;let c;try{c=o.type==K.RECTANGLE?Nt(o.geometry):zt(o)}catch(f){if(n.strict)throw f;c=o}const u={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:zo(e.bodies),created:r==null?void 0:r.toISOString(),creator:i,modified:s==null?void 0:s.toISOString(),target:{...a,source:t,selector:c}};return delete u.bodies,"annotation"in u.target&&delete u.target.annotation,u};function en(e,t,n){const o=e.slice();return o[10]=t[n],o[12]=n,o}function tn(e){let t,n;return t=new Le({props:{x:e[10][0],y:e[10][1],scale:e[3]}}),t.$on("pointerdown",function(){q(e[9](`HANDLE-${e[12]}`))&&e[9](`HANDLE-${e[12]}`).apply(this,arguments)}),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){e=o;const r={};i&16&&(r.x=e[10][0]),i&16&&(r.y=e[10][1]),i&8&&(r.scale=e[3]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Ho(e){let t,n,o,i,r,s,l,a,c,u,f,g=Te(e[4].points),h=[];for(let y=0;y<g.length;y+=1)h[y]=tn(en(e,g,y));const m=y=>U(h[y],1,1,()=>{h[y]=null});return{c(){t=N("polygon"),i=re(),r=N("polygon"),l=re();for(let y=0;y<h.length;y+=1)h[y].c();a=se(),d(t,"class","a9s-outer"),d(t,"style",n=e[1]?"display:none;":void 0),d(t,"points",o=e[4].points.map(nn).join(" ")),d(r,"class","a9s-inner a9s-shape-handle"),d(r,"style",e[1]),d(r,"points",s=e[4].points.map(on).join(" "))},m(y,v){O(y,t,v),O(y,i,v),O(y,r,v),O(y,l,v);for(let p=0;p<h.length;p+=1)h[p]&&h[p].m(y,v);O(y,a,v),c=!0,u||(f=[W(t,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(r,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)})],u=!0)},p(y,v){if(e=y,(!c||v&2&&n!==(n=e[1]?"display:none;":void 0))&&d(t,"style",n),(!c||v&16&&o!==(o=e[4].points.map(nn).join(" ")))&&d(t,"points",o),(!c||v&2)&&d(r,"style",e[1]),(!c||v&16&&s!==(s=e[4].points.map(on).join(" ")))&&d(r,"points",s),v&536){g=Te(e[4].points);let p;for(p=0;p<g.length;p+=1){const w=en(e,g,p);h[p]?(h[p].p(w,v),P(h[p],1)):(h[p]=tn(w),h[p].c(),P(h[p],1),h[p].m(a.parentNode,a))}for(le(),p=g.length;p<h.length;p+=1)m(p);ae()}},i(y){if(!c){for(let v=0;v<g.length;v+=1)P(h[v]);c=!0}},o(y){h=h.filter(Boolean);for(let v=0;v<h.length;v+=1)U(h[v]);c=!1},d(y){y&&(I(t),I(i),I(r),I(l),I(a)),rt(h,y),u=!1,ce(f)}}}function Wo(e){let t,n;return t=new mt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Ho,({grab:o})=>({9:o}),({grab:o})=>o?512:0]},$$scope:{ctx:e}}}),t.$on("change",e[6]),t.$on("grab",e[7]),t.$on("release",e[8]),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,[i]){const r={};i&1&&(r.shape=o[0]),i&4&&(r.transform=o[2]),i&8730&&(r.$$scope={dirty:i,ctx:o}),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}const nn=e=>e.join(","),on=e=>e.join(",");function Ko(e,t,n){let o,{shape:i}=t,{computedStyle:r}=t,{transform:s}=t,{viewportScale:l=1}=t;const a=(g,h,m)=>{let y;const v=g.geometry;h==="SHAPE"?y=v.points.map(([w,_])=>[w+m[0],_+m[1]]):y=v.points.map(([w,_],b)=>h===`HANDLE-${b}`?[w+m[0],_+m[1]]:[w,_]);const p=De(y);return{...g,geometry:{points:y,bounds:p}}};function c(g){ge.call(this,e,g)}function u(g){ge.call(this,e,g)}function f(g){ge.call(this,e,g)}return e.$$set=g=>{"shape"in g&&n(0,i=g.shape),"computedStyle"in g&&n(1,r=g.computedStyle),"transform"in g&&n(2,s=g.transform),"viewportScale"in g&&n(3,l=g.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=i.geometry)},[i,r,s,l,o,a,c,u,f]}class rn extends oe{constructor(t){super(),ne(this,t,Ko,Wo,x,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const Qe=(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))},Me=[];function qo(e,t=X){let n;const o=new Set;function i(l){if(x(e,l)&&(e=l,n)){const a=!Me.length;for(const c of o)c[1](),Me.push(c,e);if(a){for(let c=0;c<Me.length;c+=2)Me[c][0](Me[c+1]);Me.length=0}}}function r(l){i(l(e))}function s(l,a=X){const c=[l,a];return o.add(c),o.size===1&&(n=t(i,r)||X),l(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:r,subscribe:s}}const Jo=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:r}=e;t.setAttribute("viewBox",`0 0 ${i} ${r}`),e.addEventListener("load",s=>{const l=s.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},sn=(e,t)=>{Jo(e,t);const{subscribe:n,set:o}=qo(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const s=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,c=Math.max(s.width/l,s.height/a);o(c)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},ln=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function Qo(e){let t,n,o,i,r,s;return{c(){t=N("rect"),d(t,"class",n=je(`a9s-handle ${e[8].class||""}`.trim())+" svelte-1sgkh33"),d(t,"x",o=e[0]-e[5]/2),d(t,"y",i=e[1]-e[5]/2),d(t,"width",e[5]),d(t,"height",e[5])},m(l,a){O(l,t,a),r||(s=W(t,"pointerdown",e[11]),r=!0)},p(l,a){a&256&&n!==(n=je(`a9s-handle ${l[8].class||""}`.trim())+" svelte-1sgkh33")&&d(t,"class",n),a&33&&o!==(o=l[0]-l[5]/2)&&d(t,"x",o),a&34&&i!==(i=l[1]-l[5]/2)&&d(t,"y",i),a&32&&d(t,"width",l[5]),a&32&&d(t,"height",l[5])},d(l){l&&I(t),r=!1,s()}}}function Zo(e){let t,n,o,i,r,s,l,a,c;return{c(){t=N("g"),n=N("circle"),i=N("rect"),d(n,"cx",e[0]),d(n,"cy",e[1]),d(n,"r",o=e[3]/e[2]),d(n,"class","a9s-touch-halo svelte-1sgkh33"),pe(n,"touched",e[4]),d(i,"class",r=je(`a9s-handle ${e[8].class||""}`.trim())+" svelte-1sgkh33"),d(i,"x",s=e[0]-e[5]/2),d(i,"y",l=e[1]-e[5]/2),d(i,"width",e[5]),d(i,"height",e[5]),d(t,"class","a9s-touch-handle")},m(u,f){O(u,t,f),fe(t,n),fe(t,i),a||(c=[W(n,"pointerdown",e[10]),W(n,"pointerdown",e[6]),W(n,"pointerup",e[7]),W(i,"pointerdown",e[9]),W(i,"pointerdown",e[6]),W(i,"pointerup",e[7])],a=!0)},p(u,f){f&1&&d(n,"cx",u[0]),f&2&&d(n,"cy",u[1]),f&12&&o!==(o=u[3]/u[2])&&d(n,"r",o),f&16&&pe(n,"touched",u[4]),f&256&&r!==(r=je(`a9s-handle ${u[8].class||""}`.trim())+" svelte-1sgkh33")&&d(i,"class",r),f&33&&s!==(s=u[0]-u[5]/2)&&d(i,"x",s),f&34&&l!==(l=u[1]-u[5]/2)&&d(i,"y",l),f&32&&d(i,"width",u[5]),f&32&&d(i,"height",u[5])},d(u){u&&I(t),a=!1,ce(c)}}}function xo(e){let t;function n(r,s){return ln?Zo:Qo}let i=n()(e);return{c(){i.c(),t=se()},m(r,s){i.m(r,s),O(r,t,s)},p(r,[s]){i.p(r,s)},i:X,o:X,d(r){r&&I(t),i.d(r)}}}function $o(e,t,n){let o,{x:i}=t,{y:r}=t,{scale:s}=t,{radius:l=30}=t,a=!1;const c=m=>{m.pointerType==="touch"&&n(4,a=!0)},u=()=>n(4,a=!1);function f(m){ge.call(this,e,m)}function g(m){ge.call(this,e,m)}function h(m){ge.call(this,e,m)}return e.$$set=m=>{n(8,t=me(me({},t),Bt(m))),"x"in m&&n(0,i=m.x),"y"in m&&n(1,r=m.y),"scale"in m&&n(2,s=m.scale),"radius"in m&&n(3,l=m.radius)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=10/s)},t=Bt(t),[i,r,s,l,a,o,c,u,t,f,g,h]}class Le extends oe{constructor(t){super(),ne(this,t,$o,xo,x,{x:0,y:1,scale:2,radius:3})}}function ei(e){let t,n,o,i,r,s,l,a,c,u,f,g,h,m,y,v,p,w,_,b,Y,G,j,z,D,E,A,S,T,V,C,Z,_e,ue,Ne,de,Ve,he,Ge,k,R,F,ie;return ue=new Le({props:{class:"a9s-corner-handle-topleft",x:e[4].x,y:e[4].y,scale:e[3]}}),ue.$on("pointerdown",function(){q(e[9]("TOP_LEFT"))&&e[9]("TOP_LEFT").apply(this,arguments)}),de=new Le({props:{class:"a9s-corner-handle-topright",x:e[4].x+e[4].w,y:e[4].y,scale:e[3]}}),de.$on("pointerdown",function(){q(e[9]("TOP_RIGHT"))&&e[9]("TOP_RIGHT").apply(this,arguments)}),he=new Le({props:{class:"a9s-corner-handle-bottomright",x:e[4].x+e[4].w,y:e[4].y+e[4].h,scale:e[3]}}),he.$on("pointerdown",function(){q(e[9]("BOTTOM_RIGHT"))&&e[9]("BOTTOM_RIGHT").apply(this,arguments)}),k=new Le({props:{class:"a9s-corner-handle-bottomleft",x:e[4].x,y:e[4].y+e[4].h,scale:e[3]}}),k.$on("pointerdown",function(){q(e[9]("BOTTOM_LEFT"))&&e[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=N("rect"),l=re(),a=N("rect"),h=re(),m=N("rect"),w=re(),_=N("rect"),j=re(),z=N("rect"),S=re(),T=N("rect"),_e=re(),te(ue.$$.fragment),Ne=re(),te(de.$$.fragment),Ve=re(),te(he.$$.fragment),Ge=re(),te(k.$$.fragment),d(t,"class","a9s-outer"),d(t,"style",n=e[1]?"display:none;":void 0),d(t,"x",o=e[4].x),d(t,"y",i=e[4].y),d(t,"width",r=e[4].w),d(t,"height",s=e[4].h),d(a,"class","a9s-inner a9s-shape-handle"),d(a,"style",e[1]),d(a,"x",c=e[4].x),d(a,"y",u=e[4].y),d(a,"width",f=e[4].w),d(a,"height",g=e[4].h),d(m,"class","a9s-edge-handle a9s-edge-handle-top"),d(m,"x",y=e[4].x),d(m,"y",v=e[4].y),d(m,"height",1),d(m,"width",p=e[4].w),d(_,"class","a9s-edge-handle a9s-edge-handle-right"),d(_,"x",b=e[4].x+e[4].w),d(_,"y",Y=e[4].y),d(_,"height",G=e[4].h),d(_,"width",1),d(z,"class","a9s-edge-handle a9s-edge-handle-bottom"),d(z,"x",D=e[4].x),d(z,"y",E=e[4].y+e[4].h),d(z,"height",1),d(z,"width",A=e[4].w),d(T,"class","a9s-edge-handle a9s-edge-handle-left"),d(T,"x",V=e[4].x),d(T,"y",C=e[4].y),d(T,"height",Z=e[4].h),d(T,"width",1)},m(B,M){O(B,t,M),O(B,l,M),O(B,a,M),O(B,h,M),O(B,m,M),O(B,w,M),O(B,_,M),O(B,j,M),O(B,z,M),O(B,S,M),O(B,T,M),O(B,_e,M),$(ue,B,M),O(B,Ne,M),$(de,B,M),O(B,Ve,M),$(he,B,M),O(B,Ge,M),$(k,B,M),R=!0,F||(ie=[W(t,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(a,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(m,"pointerdown",function(){q(e[9]("TOP"))&&e[9]("TOP").apply(this,arguments)}),W(_,"pointerdown",function(){q(e[9]("RIGHT"))&&e[9]("RIGHT").apply(this,arguments)}),W(z,"pointerdown",function(){q(e[9]("BOTTOM"))&&e[9]("BOTTOM").apply(this,arguments)}),W(T,"pointerdown",function(){q(e[9]("LEFT"))&&e[9]("LEFT").apply(this,arguments)})],F=!0)},p(B,M){e=B,(!R||M&2&&n!==(n=e[1]?"display:none;":void 0))&&d(t,"style",n),(!R||M&16&&o!==(o=e[4].x))&&d(t,"x",o),(!R||M&16&&i!==(i=e[4].y))&&d(t,"y",i),(!R||M&16&&r!==(r=e[4].w))&&d(t,"width",r),(!R||M&16&&s!==(s=e[4].h))&&d(t,"height",s),(!R||M&2)&&d(a,"style",e[1]),(!R||M&16&&c!==(c=e[4].x))&&d(a,"x",c),(!R||M&16&&u!==(u=e[4].y))&&d(a,"y",u),(!R||M&16&&f!==(f=e[4].w))&&d(a,"width",f),(!R||M&16&&g!==(g=e[4].h))&&d(a,"height",g),(!R||M&16&&y!==(y=e[4].x))&&d(m,"x",y),(!R||M&16&&v!==(v=e[4].y))&&d(m,"y",v),(!R||M&16&&p!==(p=e[4].w))&&d(m,"width",p),(!R||M&16&&b!==(b=e[4].x+e[4].w))&&d(_,"x",b),(!R||M&16&&Y!==(Y=e[4].y))&&d(_,"y",Y),(!R||M&16&&G!==(G=e[4].h))&&d(_,"height",G),(!R||M&16&&D!==(D=e[4].x))&&d(z,"x",D),(!R||M&16&&E!==(E=e[4].y+e[4].h))&&d(z,"y",E),(!R||M&16&&A!==(A=e[4].w))&&d(z,"width",A),(!R||M&16&&V!==(V=e[4].x))&&d(T,"x",V),(!R||M&16&&C!==(C=e[4].y))&&d(T,"y",C),(!R||M&16&&Z!==(Z=e[4].h))&&d(T,"height",Z);const et={};M&16&&(et.x=e[4].x),M&16&&(et.y=e[4].y),M&8&&(et.scale=e[3]),ue.$set(et);const tt={};M&16&&(tt.x=e[4].x+e[4].w),M&16&&(tt.y=e[4].y),M&8&&(tt.scale=e[3]),de.$set(tt);const nt={};M&16&&(nt.x=e[4].x+e[4].w),M&16&&(nt.y=e[4].y+e[4].h),M&8&&(nt.scale=e[3]),he.$set(nt);const ot={};M&16&&(ot.x=e[4].x),M&16&&(ot.y=e[4].y+e[4].h),M&8&&(ot.scale=e[3]),k.$set(ot)},i(B){R||(P(ue.$$.fragment,B),P(de.$$.fragment,B),P(he.$$.fragment,B),P(k.$$.fragment,B),R=!0)},o(B){U(ue.$$.fragment,B),U(de.$$.fragment,B),U(he.$$.fragment,B),U(k.$$.fragment,B),R=!1},d(B){B&&(I(t),I(l),I(a),I(h),I(m),I(w),I(_),I(j),I(z),I(S),I(T),I(_e),I(Ne),I(Ve),I(Ge)),ee(ue,B),ee(de,B),ee(he,B),ee(k,B),F=!1,ce(ie)}}}function ti(e){let t,n;return t=new mt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[ei,({grab:o})=>({9:o}),({grab:o})=>o?512:0]},$$scope:{ctx:e}}}),t.$on("grab",e[6]),t.$on("change",e[7]),t.$on("release",e[8]),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,[i]){const r={};i&1&&(r.shape=o[0]),i&4&&(r.transform=o[2]),i&1562&&(r.$$scope={dirty:i,ctx:o}),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function ni(e,t,n){let o,{shape:i}=t,{computedStyle:r}=t,{transform:s}=t,{viewportScale:l=1}=t;const a=(g,h,m)=>{const y=g.geometry.bounds;let[v,p]=[y.minX,y.minY],[w,_]=[y.maxX,y.maxY];const[b,Y]=m;if(h==="SHAPE")v+=b,w+=b,p+=Y,_+=Y;else{switch(h){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{p+=Y;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{_+=Y;break}}switch(h){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{v+=b;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{w+=b;break}}}const G=Math.min(v,w),j=Math.min(p,_),z=Math.abs(w-v),D=Math.abs(_-p);return{...g,geometry:{x:G,y:j,w:z,h:D,bounds:{minX:G,minY:j,maxX:G+z,maxY:j+D}}}};function c(g){ge.call(this,e,g)}function u(g){ge.call(this,e,g)}function f(g){ge.call(this,e,g)}return e.$$set=g=>{"shape"in g&&n(0,i=g.shape),"computedStyle"in g&&n(1,r=g.computedStyle),"transform"in g&&n(2,s=g.transform),"viewportScale"in g&&n(3,l=g.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=i.geometry)},[i,r,s,l,o,a,c,u,f]}class an extends oe{constructor(t){super(),ne(this,t,ni,ti,x,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const cn=new Map([[K.RECTANGLE,an],[K.POLYGON,rn]]),fn=e=>cn.get(e.type),un=(e,t)=>cn.set(e,t),oi=e=>({}),dn=e=>({grab:e[0]});function ii(e){let t,n,o,i;const r=e[7].default,s=jn(r,e,e[6],dn);return{c(){t=N("g"),s&&s.c(),d(t,"class","a9s-annotation selected")},m(l,a){O(l,t,a),s&&s.m(t,null),n=!0,o||(i=[W(t,"pointerup",e[2]),W(t,"pointermove",e[1])],o=!0)},p(l,[a]){s&&s.p&&(!n||a&64)&&Fn(s,r,l,l[6],n?zn(r,l[6],a,oi):Hn(l[6]),dn)},i(l){n||(P(s,l),n=!0)},o(l){U(s,l),n=!1},d(l){l&&I(t),s&&s.d(l),o=!1,ce(i)}}}function ri(e,t,n){let{$$slots:o={},$$scope:i}=t;const r=be();let{shape:s}=t,{editor:l}=t,{transform:a}=t,c,u,f;const g=y=>v=>{c=y,u=a.elementToImage(v.offsetX,v.offsetY),f=s,v.target.setPointerCapture(v.pointerId),r("grab",v)},h=y=>{if(c){const[v,p]=a.elementToImage(y.offsetX,y.offsetY),w=[v-u[0],p-u[1]];n(3,s=l(f,c,w)),r("change",s)}},m=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,f=s,r("release",y)};return e.$$set=y=>{"shape"in y&&n(3,s=y.shape),"editor"in y&&n(4,l=y.editor),"transform"in y&&n(5,a=y.transform),"$$scope"in y&&n(6,i=y.$$scope)},[g,h,m,s,l,a,i,o]}class mt extends oe{constructor(t){super(),ne(this,t,ri,ii,x,{shape:3,editor:4,transform:5})}}const Ze=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i,stroke:r,strokeWidth:s,strokeOpacity:l}=n;let a="";return o&&(a+=`fill:${o};`,a+=`fill-opacity:${i||"0.25"};`),r&&(a+=`stroke:${r};`,a+=`stroke-width:${s||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}};function si(e,t,n){let o;const i=be();let{annotation:r}=t,{editor:s}=t,{style:l}=t,{target:a}=t,{transform:c}=t,{viewportScale:u}=t,f;return Pe(()=>(n(6,f=new s({target:a,props:{shape:r.target.selector,computedStyle:o,transform:c,viewportScale:u}})),f.$on("change",g=>{f.$$set({shape:g.detail}),i("change",g.detail)}),f.$on("grab",g=>i("grab",g.detail)),f.$on("release",g=>i("release",g.detail)),()=>{f.$destroy()})),e.$$set=g=>{"annotation"in g&&n(0,r=g.annotation),"editor"in g&&n(1,s=g.editor),"style"in g&&n(2,l=g.style),"target"in g&&n(3,a=g.target),"transform"in g&&n(4,c=g.transform),"viewportScale"in g&&n(5,u=g.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&(o=Ze(r,l)),e.$$.dirty&65&&r&&(f==null||f.$set({shape:r.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:c}),e.$$.dirty&96&&f&&f.$set({viewportScale:u})},[r,s,l,a,c,u,f]}class hn extends oe{constructor(t){super(),ne(this,t,si,null,x,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function li(e,t,n){const o=be();let{drawingMode:i}=t,{target:r}=t,{tool:s}=t,{transform:l}=t,{viewportScale:a}=t,c;return Pe(()=>{const u=r.closest("svg"),f=[],g=(h,m,y)=>{u==null||u.addEventListener(h,m,y),f.push(()=>u==null?void 0:u.removeEventListener(h,m,y))};return n(5,c=new s({target:r,props:{addEventListener:g,drawingMode:i,transform:l,viewportScale:a}})),c.$on("create",h=>o("create",h.detail)),()=>{f.forEach(h=>h()),c.$destroy()}}),e.$$set=u=>{"drawingMode"in u&&n(0,i=u.drawingMode),"target"in u&&n(1,r=u.target),"tool"in u&&n(2,s=u.tool),"transform"in u&&n(3,l=u.transform),"viewportScale"in u&&n(4,a=u.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&c&&c.$set({transform:l}),e.$$.dirty&48&&c&&c.$set({viewportScale:a})},[i,r,s,l,a,c]}class gn extends oe{constructor(t){super(),ne(this,t,li,null,x,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function mn(e){let t,n;return{c(){t=N("rect"),n=N("rect"),d(t,"class","a9s-outer"),d(t,"x",e[1]),d(t,"y",e[2]),d(t,"width",e[3]),d(t,"height",e[4]),d(n,"class","a9s-inner"),d(n,"x",e[1]),d(n,"y",e[2]),d(n,"width",e[3]),d(n,"height",e[4])},m(o,i){O(o,t,i),O(o,n,i)},p(o,i){i&2&&d(t,"x",o[1]),i&4&&d(t,"y",o[2]),i&8&&d(t,"width",o[3]),i&16&&d(t,"height",o[4]),i&2&&d(n,"x",o[1]),i&4&&d(n,"y",o[2]),i&8&&d(n,"width",o[3]),i&16&&d(n,"height",o[4])},d(o){o&&(I(t),I(n))}}}function ai(e){let t,n=e[0]&&mn(e);return{c(){t=N("g"),n&&n.c(),d(t,"class","a9s-annotation a9s-rubberband")},m(o,i){O(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=mn(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:X,o:X,d(o){o&&I(t),n&&n.d()}}}function ci(e,t,n){const o=be();let{addEventListener:i}=t,{drawingMode:r}=t,{transform:s}=t,l,a,c,u,f,g,h;const m=w=>{const _=w;l=performance.now(),r==="drag"&&(n(0,a=s.elementToImage(_.offsetX,_.offsetY)),c=a,n(1,u=a[0]),n(2,f=a[1]),n(3,g=1),n(4,h=1))},y=w=>{const _=w;a&&(c=s.elementToImage(_.offsetX,_.offsetY),n(1,u=Math.min(c[0],a[0])),n(2,f=Math.min(c[1],a[1])),n(3,g=Math.abs(c[0]-a[0])),n(4,h=Math.abs(c[1]-a[1])))},v=w=>{const _=w,b=performance.now()-l;if(r==="click"){if(b>300)return;a?p():(n(0,a=s.elementToImage(_.offsetX,_.offsetY)),c=a,n(1,u=a[0]),n(2,f=a[1]),n(3,g=1),n(4,h=1))}else a&&(b>300||g*h>100?(_.stopPropagation(),p()):(n(0,a=void 0),c=void 0))},p=()=>{if(g*h>15){const w={type:K.RECTANGLE,geometry:{bounds:{minX:u,minY:f,maxX:u+g,maxY:f+h},x:u,y:f,w:g,h}};o("create",w)}n(0,a=void 0),c=void 0};return Pe(()=>{i("pointerdown",m),i("pointermove",y),i("pointerup",v,!0)}),e.$$set=w=>{"addEventListener"in w&&n(5,i=w.addEventListener),"drawingMode"in w&&n(6,r=w.drawingMode),"transform"in w&&n(7,s=w.transform)},[a,u,f,g,h,i,r,s]}class pn extends oe{constructor(t){super(),ne(this,t,ci,ai,x,{addEventListener:5,drawingMode:6,transform:7})}}function pt(e){const t=e.slice(),n=(t[2]?t[0]:[...t[0],t[1]]).map(o=>o.join(",")).join(" ");return t[16]=n,t}function yn(e){let t,n,o,i,r,s=e[2]&&_n(e);return{c(){t=N("polygon"),o=N("polygon"),s&&s.c(),r=se(),d(t,"class","a9s-outer"),d(t,"points",n=e[16]),d(o,"class","a9s-inner"),d(o,"points",i=e[16])},m(l,a){O(l,t,a),O(l,o,a),s&&s.m(l,a),O(l,r,a)},p(l,a){a&7&&n!==(n=l[16])&&d(t,"points",n),a&7&&i!==(i=l[16])&&d(o,"points",i),l[2]?s?s.p(l,a):(s=_n(l),s.c(),s.m(r.parentNode,r)):s&&(s.d(1),s=null)},d(l){l&&(I(t),I(o),I(r)),s&&s.d(l)}}}function _n(e){let t,n,o;return{c(){t=N("rect"),d(t,"class","a9s-corner-handle"),d(t,"x",n=e[0][0][0]-e[3]/2),d(t,"y",o=e[0][0][1]-e[3]/2),d(t,"height",e[3]),d(t,"width",e[3])},m(i,r){O(i,t,r)},p(i,r){r&9&&n!==(n=i[0][0][0]-i[3]/2)&&d(t,"x",n),r&9&&o!==(o=i[0][0][1]-i[3]/2)&&d(t,"y",o),r&8&&d(t,"height",i[3]),r&8&&d(t,"width",i[3])},d(i){i&&I(t)}}}function fi(e){let t,n=e[1]&&yn(pt(e));return{c(){t=N("g"),n&&n.c(),d(t,"class","a9s-annotation a9s-rubberband")},m(o,i){O(o,t,i),n&&n.m(t,null)},p(o,[i]){o[1]?n?n.p(pt(o),i):(n=yn(pt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:X,o:X,d(o){o&&I(t),n&&n.d()}}}const ui=20,di=1500;function hi(e,t,n){let o;const i=be();let{addEventListener:r}=t,{drawingMode:s}=t,{transform:l}=t,{viewportScale:a=1}=t,c,u=[],f,g,h=!1;const m=_=>{const b=_,{timeStamp:Y,offsetX:G,offsetY:j}=b;if(c={timeStamp:Y,offsetX:G,offsetY:j},s==="drag"&&u.length===0){const z=l.elementToImage(b.offsetX,b.offsetY);u.push(z),n(1,f=z)}},y=_=>{const b=_;if(g&&clearTimeout(g),u.length>0){if(n(1,f=l.elementToImage(b.offsetX,b.offsetY)),u.length>2){const Y=Qe(f,u[0])*a;n(2,h=Y<ui)}b.pointerType==="touch"&&(g=setTimeout(()=>{p()},di))}},v=_=>{const b=_;if(g&&clearTimeout(g),s==="click"){const Y=b.timeStamp-c.timeStamp,G=Qe([c.offsetX,c.offsetY],[b.offsetX,b.offsetY]);if(Y>300||G>15)return;if(h)w();else if(u.length===0){const j=l.elementToImage(b.offsetX,b.offsetY);u.push(j),n(1,f=j)}else u.push(f)}else{if(u.length===1&&Qe(u[0],f)<=4){n(0,u=[]),n(1,f=void 0);return}b.stopImmediatePropagation(),h?w():u.push(f)}},p=()=>{if(!f)return;const _=[...u,f],b={type:K.POLYGON,geometry:{bounds:De(_),points:_}};We(b)>4&&(n(0,u=[]),n(1,f=void 0),i("create",b))},w=()=>{const _={type:K.POLYGON,geometry:{bounds:De(u),points:[...u]}};n(0,u=[]),n(1,f=void 0),i("create",_)};return Pe(()=>{r("pointerdown",m,!0),r("pointermove",y),r("pointerup",v,!0),r("dblclick",p,!0)}),e.$$set=_=>{"addEventListener"in _&&n(4,r=_.addEventListener),"drawingMode"in _&&n(5,s=_.drawingMode),"transform"in _&&n(6,l=_.transform),"viewportScale"in _&&n(7,a=_.viewportScale)},e.$$.update=()=>{e.$$.dirty&128&&n(3,o=10/a)},[u,f,h,o,r,s,l,a]}class gi extends oe{constructor(t){super(),ne(this,t,hi,fi,x,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const yt=new Map([["rectangle",{tool:pn}],["polygon",{tool:gi}]]),_t=()=>[...yt.keys()],wt=e=>yt.get(e),wn=(e,t,n)=>yt.set(e,{tool:t,opts:n});function mi(e){let t,n,o,i,r;return{c(){t=N("g"),n=N("ellipse"),i=N("ellipse"),d(n,"class","a9s-outer"),d(n,"style",o=e[1]?"display:none;":void 0),d(n,"cx",e[2]),d(n,"cy",e[3]),d(n,"rx",e[4]),d(n,"ry",e[5]),d(i,"class","a9s-inner"),d(i,"style",e[1]),d(i,"cx",e[2]),d(i,"cy",e[3]),d(i,"rx",e[4]),d(i,"ry",e[5]),d(t,"class","a9s-annotation"),d(t,"data-id",r=e[0].id)},m(s,l){O(s,t,l),fe(t,n),fe(t,i)},p(s,[l]){l&2&&o!==(o=s[1]?"display:none;":void 0)&&d(n,"style",o),l&2&&d(i,"style",s[1]),l&1&&r!==(r=s[0].id)&&d(t,"data-id",r)},i:X,o:X,d(s){s&&I(t)}}}function pi(e,t,n){let o,{annotation:i}=t,{geom:r}=t,{style:s}=t;const{cx:l,cy:a,rx:c,ry:u}=r;return e.$$set=f=>{"annotation"in f&&n(0,i=f.annotation),"geom"in f&&n(6,r=f.geom),"style"in f&&n(7,s=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ze(i,s))},[i,o,l,a,c,u,r,s]}class yi extends oe{constructor(t){super(),ne(this,t,pi,mi,x,{annotation:0,geom:6,style:7})}}function _i(e){let t,n,o,i,r;return{c(){t=N("g"),n=N("polygon"),i=N("polygon"),d(n,"class","a9s-outer"),d(n,"style",o=e[1]?"display:none;":void 0),d(n,"points",e[2].map(wi).join(" ")),d(i,"class","a9s-inner"),d(i,"style",e[1]),d(i,"points",e[2].map(bi).join(" ")),d(t,"class","a9s-annotation"),d(t,"data-id",r=e[0].id)},m(s,l){O(s,t,l),fe(t,n),fe(t,i)},p(s,[l]){l&2&&o!==(o=s[1]?"display:none;":void 0)&&d(n,"style",o),l&2&&d(i,"style",s[1]),l&1&&r!==(r=s[0].id)&&d(t,"data-id",r)},i:X,o:X,d(s){s&&I(t)}}}const wi=e=>e.join(","),bi=e=>e.join(",");function Ei(e,t,n){let o,{annotation:i}=t,{geom:r}=t,{style:s}=t;const{points:l}=r;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,r=a.geom),"style"in a&&n(4,s=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ze(i,s))},[i,o,l,r,s]}class Ai extends oe{constructor(t){super(),ne(this,t,Ei,_i,x,{annotation:0,geom:3,style:4})}}function Si(e){let t,n,o,i,r;return{c(){t=N("g"),n=N("rect"),i=N("rect"),d(n,"class","a9s-outer"),d(n,"style",o=e[5]?"display:none;":void 0),d(n,"x",e[4]),d(n,"y",e[3]),d(n,"width",e[2]),d(n,"height",e[1]),d(i,"class","a9s-inner"),d(i,"style",e[5]),d(i,"x",e[4]),d(i,"y",e[3]),d(i,"width",e[2]),d(i,"height",e[1]),d(t,"class","a9s-annotation"),d(t,"data-id",r=e[0].id)},m(s,l){O(s,t,l),fe(t,n),fe(t,i)},p(s,[l]){l&32&&o!==(o=s[5]?"display:none;":void 0)&&d(n,"style",o),l&16&&d(n,"x",s[4]),l&8&&d(n,"y",s[3]),l&4&&d(n,"width",s[2]),l&2&&d(n,"height",s[1]),l&32&&d(i,"style",s[5]),l&16&&d(i,"x",s[4]),l&8&&d(i,"y",s[3]),l&4&&d(i,"width",s[2]),l&2&&d(i,"height",s[1]),l&1&&r!==(r=s[0].id)&&d(t,"data-id",r)},i:X,o:X,d(s){s&&I(t)}}}function Ti(e,t,n){let o,i,r,s,l,{annotation:a}=t,{geom:c}=t,{style:u}=t;return e.$$set=f=>{"annotation"in f&&n(0,a=f.annotation),"geom"in f&&n(6,c=f.geom),"style"in f&&n(7,u=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=Ze(a,u)),e.$$.dirty&64&&n(4,{x:i,y:r,w:s,h:l}=c,i,(n(3,r),n(6,c)),(n(2,s),n(6,c)),(n(1,l),n(6,c)))},[a,l,s,r,i,o,c,u]}class vi extends oe{constructor(t){super(),ne(this,t,Ti,Si,x,{annotation:0,geom:6,style:7})}}const Mi={elementToImage:(e,t)=>[e,t]},bn=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:r,y:s}=i.matrixTransform(e.getScreenCTM().inverse());return[r,s]}}),Li=250,En=(e,t)=>{const n=be();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:s=>{if(performance.now()-o<Li){const{x:a,y:c}=bt(s,e),u=t.getAt(a,c);u?n("click",{originalEvent:s,annotation:u}):n("click",{originalEvent:s})}}}},bt=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,r=e.clientY-o.y,{left:s,top:l}=t.getBoundingClientRect();return n.x=i+s,n.y=r+l,n.matrixTransform(t.getScreenCTM().inverse())};function An(e,t,n){const o=e.slice();o[35]=t[n];const i=o[23](o[35].target.selector);return o[36]=i,o}function Sn(e,t,n){const o=e.slice();return o[39]=t[n],o}function Et(e){const t=e.slice(),n=t[39].target.selector;return t[42]=n,t}function Tn(e){let t=e[39].id,n,o,i=vn(e);return{c(){i.c(),n=se()},m(r,s){i.m(r,s),O(r,n,s),o=!0},p(r,s){s[0]&32768&&x(t,t=r[39].id)?(le(),U(i,1,1,X),ae(),i=vn(r),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(r,s)},i(r){o||(P(i),o=!0)},o(r){U(i),o=!1},d(r){r&&I(n),i.d(r)}}}function ki(e){let t,n;return t=new Ai({props:{annotation:e[39],geom:e[42].geometry,style:e[1]}}),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const r={};i[0]&32768&&(r.annotation=o[39]),i[0]&32768&&(r.geom=o[42].geometry),i[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Ii(e){let t,n;return t=new vi({props:{annotation:e[39],geom:e[42].geometry,style:e[1]}}),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const r={};i[0]&32768&&(r.annotation=o[39]),i[0]&32768&&(r.geom=o[42].geometry),i[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Oi(e){var o;let t,n;return t=new yi({props:{annotation:e[39],geom:(o=e[42])==null?void 0:o.geometry,style:e[1]}}),{c(){te(t.$$.fragment)},m(i,r){$(t,i,r),n=!0},p(i,r){var l;const s={};r[0]&32768&&(s.annotation=i[39]),r[0]&32768&&(s.geom=(l=i[42])==null?void 0:l.geometry),r[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(P(t.$$.fragment,i),n=!0)},o(i){U(t.$$.fragment,i),n=!1},d(i){ee(t,i)}}}function vn(e){let t,n,o,i;const r=[Oi,Ii,ki],s=[];function l(a,c){var u,f,g;return((u=a[42])==null?void 0:u.type)===K.ELLIPSE?0:((f=a[42])==null?void 0:f.type)===K.RECTANGLE?1:((g=a[42])==null?void 0:g.type)===K.POLYGON?2:-1}return~(t=l(e))&&(n=s[t]=r[t](e)),{c(){n&&n.c(),o=se()},m(a,c){~t&&s[t].m(a,c),O(a,o,c),i=!0},p(a,c){let u=t;t=l(a),t===u?~t&&s[t].p(a,c):(n&&(le(),U(s[u],1,1,()=>{s[u]=null}),ae()),~t?(n=s[t],n?n.p(a,c):(n=s[t]=r[t](a),n.c()),P(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(P(n),i=!0)},o(a){U(n),i=!1},d(a){a&&I(o),~t&&s[t].d(a)}}}function Mn(e){let t=Ye(e[39])&&!e[8](e[39]),n,o,i=t&&Tn(Et(e));return{c(){i&&i.c(),n=se()},m(r,s){i&&i.m(r,s),O(r,n,s),o=!0},p(r,s){s[0]&33024&&(t=Ye(r[39])&&!r[8](r[39])),t?i?(i.p(Et(r),s),s[0]&33024&&P(i,1)):(i=Tn(Et(r)),i.c(),P(i,1),i.m(n.parentNode,n)):i&&(le(),U(i,1,1,()=>{i=null}),ae())},i(r){o||(P(i),o=!0)},o(r){U(i),o=!1},d(r){r&&I(n),i&&i.d(r)}}}function Ln(e){let t,n,o,i;const r=[Pi,Bi],s=[];function l(a,c){return a[7]?0:a[13]&&a[0]?1:-1}return~(t=l(e))&&(n=s[t]=r[t](e)),{c(){n&&n.c(),o=se()},m(a,c){~t&&s[t].m(a,c),O(a,o,c),i=!0},p(a,c){let u=t;t=l(a),t===u?~t&&s[t].p(a,c):(n&&(le(),U(s[u],1,1,()=>{s[u]=null}),ae()),~t?(n=s[t],n?n.p(a,c):(n=s[t]=r[t](a),n.c()),P(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(P(n),i=!0)},o(a){U(n),i=!1},d(a){a&&I(o),~t&&s[t].d(a)}}}function Bi(e){let t=e[2],n,o,i=kn(e);return{c(){i.c(),n=se()},m(r,s){i.m(r,s),O(r,n,s),o=!0},p(r,s){s[0]&4&&x(t,t=r[2])?(le(),U(i,1,1,X),ae(),i=kn(r),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(r,s)},i(r){o||(P(i),o=!0)},o(r){U(i),o=!1},d(r){r&&I(n),i.d(r)}}}function Pi(e){let t,n,o=Te(e[7]),i=[];for(let s=0;s<o.length;s+=1)i[s]=Bn(An(e,o,s));const r=s=>U(i[s],1,1,()=>{i[s]=null});return{c(){for(let s=0;s<i.length;s+=1)i[s].c();t=se()},m(s,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(s,l);O(s,t,l),n=!0},p(s,l){if(l[0]&10553506){o=Te(s[7]);let a;for(a=0;a<o.length;a+=1){const c=An(s,o,a);i[a]?(i[a].p(c,l),P(i[a],1)):(i[a]=Bn(c),i[a].c(),P(i[a],1),i[a].m(t.parentNode,t))}for(le(),a=o.length;a<i.length;a+=1)r(a);ae()}},i(s){if(!n){for(let l=0;l<o.length;l+=1)P(i[l]);n=!0}},o(s){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)U(i[l]);n=!1},d(s){s&&I(t),rt(i,s)}}}function kn(e){let t,n;return t=new gn({props:{target:e[5],tool:e[13],drawingMode:e[12],transform:e[11],viewportScale:e[16]}}),t.$on("create",e[20]),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const r={};i[0]&32&&(r.target=o[5]),i[0]&8192&&(r.tool=o[13]),i[0]&4096&&(r.drawingMode=o[12]),i[0]&2048&&(r.transform=o[11]),i[0]&65536&&(r.viewportScale=o[16]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function In(e){let t=e[35].id,n,o,i=On(e);return{c(){i.c(),n=se()},m(r,s){i.m(r,s),O(r,n,s),o=!0},p(r,s){s[0]&128&&x(t,t=r[35].id)?(le(),U(i,1,1,X),ae(),i=On(r),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(r,s)},i(r){o||(P(i),o=!0)},o(r){U(i),o=!1},d(r){r&&I(n),i.d(r)}}}function On(e){let t,n;return t=new hn({props:{target:e[5],editor:e[23](e[35].target.selector),annotation:e[35],style:e[1],transform:e[11],viewportScale:e[16]}}),t.$on("change",function(){q(e[21](e[35]))&&e[21](e[35]).apply(this,arguments)}),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){e=o;const r={};i[0]&32&&(r.target=e[5]),i[0]&128&&(r.editor=e[23](e[35].target.selector)),i[0]&128&&(r.annotation=e[35]),i[0]&2&&(r.style=e[1]),i[0]&2048&&(r.transform=e[11]),i[0]&65536&&(r.viewportScale=e[16]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Bn(e){let t,n,o=e[36]&&In(e);return{c(){o&&o.c(),t=se()},m(i,r){o&&o.m(i,r),O(i,t,r),n=!0},p(i,r){i[36]?o?(o.p(i,r),r[0]&128&&P(o,1)):(o=In(i),o.c(),P(o,1),o.m(t.parentNode,t)):o&&(le(),U(o,1,1,()=>{o=null}),ae())},i(i){n||(P(o),n=!0)},o(i){U(o),n=!1},d(i){i&&I(t),o&&o.d(i)}}}function Di(e){let t,n,o,i,r,s,l=Te(e[15].filter(e[30])),a=[];for(let f=0;f<l.length;f+=1)a[f]=Mn(Sn(e,l,f));const c=f=>U(a[f],1,1,()=>{a[f]=null});let u=e[5]&&Ln(e);return{c(){t=N("svg"),n=N("g");for(let f=0;f<a.length;f+=1)a[f].c();o=N("g"),u&&u.c(),d(o,"class","drawing"),d(t,"class","a9s-annotationlayer"),pe(t,"drawing",e[13]),pe(t,"hidden",!e[3]),pe(t,"hover",e[14])},m(f,g){O(f,t,g),fe(t,n);for(let h=0;h<a.length;h+=1)a[h]&&a[h].m(n,null);fe(t,o),u&&u.m(o,null),e[31](o),e[32](t),i=!0,r||(s=[W(t,"pointerup",function(){q(e[9])&&e[9].apply(this,arguments)}),W(t,"pointerdown",function(){q(e[10])&&e[10].apply(this,arguments)}),W(t,"pointermove",e[22])],r=!0)},p(f,g){if(e=f,g[0]&33026){l=Te(e[15].filter(e[30]));let h;for(h=0;h<l.length;h+=1){const m=Sn(e,l,h);a[h]?(a[h].p(m,g),P(a[h],1)):(a[h]=Mn(m),a[h].c(),P(a[h],1),a[h].m(n,null))}for(le(),h=l.length;h<a.length;h+=1)c(h);ae()}e[5]?u?(u.p(e,g),g[0]&32&&P(u,1)):(u=Ln(e),u.c(),P(u,1),u.m(o,null)):u&&(le(),U(u,1,1,()=>{u=null}),ae()),(!i||g[0]&8192)&&pe(t,"drawing",e[13]),(!i||g[0]&8)&&pe(t,"hidden",!e[3]),(!i||g[0]&16384)&&pe(t,"hover",e[14])},i(f){if(!i){for(let g=0;g<l.length;g+=1)P(a[g]);P(u),i=!0}},o(f){a=a.filter(Boolean);for(let g=0;g<a.length;g+=1)U(a[g]);U(u),i=!1},d(f){f&&I(t),rt(a,f),u&&u.d(),e[31](null),e[32](null),r=!1,ce(s)}}}function Yi(e,t,n){let o,i,r,s,l,a,c,u,f,g,h,m=X,y=()=>(m(),m=It(E,k=>n(16,h=k)),E);e.$$.on_destroy.push(()=>m());let{drawingEnabled:v}=t,{image:p}=t,{preferredDrawingMode:w}=t,{state:_}=t,{style:b=void 0}=t,{toolName:Y=_t()[0]}=t,{user:G}=t,{visible:j=!0}=t,z,D,E;Pe(()=>y(n(6,E=sn(p,D))));const{hover:A,selection:S,store:T}=_;it(e,A,k=>n(14,u=k)),it(e,S,k=>n(29,f=k)),it(e,T,k=>n(15,g=k));let V,C;const Z=k=>{V&&T.unobserve(V);const R=k.filter(({editable:F})=>F).map(({id:F})=>F);R.length>0?(n(7,C=R.map(F=>T.getAnnotation(F)).filter(F=>F&&Ye(F))),V=F=>{const{updated:ie}=F.changes;n(7,C=ie==null?void 0:ie.map(B=>B.newValue))},T.observe(V,{annotations:R})):n(7,C=void 0)},_e=k=>{const R=Ht(),F={id:R,bodies:[],target:{annotation:R,selector:k.detail,creator:G,created:new Date}};T.addAnnotation(F),S.setSelected(F.id)},ue=k=>R=>{var M;const{target:F}=k,ie=10*60*1e3,B=((M=F.creator)==null?void 0:M.id)!==G.id||!F.created||new Date().getTime()-F.created.getTime()>ie;T.updateTarget({...F,selector:R.detail,created:B?F.created:new Date,updated:B?new Date:void 0,updatedBy:B?G:void 0})},Ne=k=>{const{x:R,y:F}=bt(k,D),ie=T.getAt(R,F);ie?u!==ie.id&&A.set(ie.id):A.set(void 0)},de=k=>fn(k),Ve=k=>Ye(k);function he(k){ze[k?"unshift":"push"](()=>{z=k,n(5,z)})}function Ge(k){ze[k?"unshift":"push"](()=>{D=k,n(4,D)})}return e.$$set=k=>{"drawingEnabled"in k&&n(0,v=k.drawingEnabled),"image"in k&&n(24,p=k.image),"preferredDrawingMode"in k&&n(25,w=k.preferredDrawingMode),"state"in k&&n(26,_=k.state),"style"in k&&n(1,b=k.style),"toolName"in k&&n(2,Y=k.toolName),"user"in k&&n(27,G=k.user),"visible"in k&&n(3,j=k.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(13,{tool:o,opts:i}=wt(Y)||{tool:void 0,opts:void 0},o,(n(28,i),n(2,Y))),e.$$.dirty[0]&301989888&&n(12,r=(i==null?void 0:i.drawingMode)||w),e.$$.dirty[0]&16&&n(11,s=bn(D)),e.$$.dirty[0]&16&&n(10,{onPointerDown:l,onPointerUp:a}=En(D,T),l,(n(9,a),n(4,D))),e.$$.dirty[0]&536870912&&n(8,c=k=>f.selected.find(R=>R.id===k.id&&R.editable)),e.$$.dirty[0]&536870912&&Z(f.selected)},[v,b,Y,j,D,z,E,C,c,a,l,s,r,o,u,g,h,A,S,T,_e,ue,Ne,de,p,w,_,G,i,f,Ve,he,Ge]}class Pn extends oe{constructor(t){super(),ne(this,t,Yi,Di,x,{drawingEnabled:0,image:24,preferredDrawingMode:25,state:26,style:1,toolName:2,user:27,visible:3},null,[-1,-1])}}function Dn(e,t,n=0,o=e.length-1,i=Ri){for(;o>n;){if(o-n>600){const a=o-n+1,c=t-n+1,u=Math.log(a),f=.5*Math.exp(2*u/3),g=.5*Math.sqrt(u*f*(a-f)/a)*(c-a/2<0?-1:1),h=Math.max(n,Math.floor(t-c*f/a+g)),m=Math.min(o,Math.floor(t+(a-c)*f/a+g));Dn(e,t,h,m,i)}const r=e[t];let s=n,l=o;for(Ce(e,n,t),i(e[o],r)>0&&Ce(e,n,o);s<l;){for(Ce(e,s,l),s++,l--;i(e[s],r)<0;)s++;for(;i(e[l],r)>0;)l--}i(e[n],r)===0?Ce(e,n,l):(l++,Ce(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function Ce(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Ri(e,t){return e<t?-1:e>t?1:0}class Ci{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(!$e(t,n))return o;const i=this.toBBox,r=[];for(;n;){for(let s=0;s<n.children.length;s++){const l=n.children[s],a=n.leaf?i(l):l;$e(t,a)&&(n.leaf?o.push(l):St(t,a)?this._all(l,o):r.push(l))}n=r.pop()}return o}collides(t){let n=this.data;if(!$e(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const r=n.children[i],s=n.leaf?this.toBBox(r):r;if($e(t,s)){if(n.leaf||St(t,s))return!0;o.push(r)}}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=Ie([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),r=[],s=[];let l,a,c;for(;o||r.length;){if(o||(o=r.pop(),a=r[r.length-1],l=s.pop(),c=!0),o.leaf){const u=Xi(t,o.children,n);if(u!==-1)return o.children.splice(u,1),r.push(o),this._condense(r),this}!c&&!o.leaf&&St(o,i)?(r.push(o),s.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],c=!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 r=o-n+1;let s=this._maxEntries,l;if(r<=s)return l=Ie(t.slice(n,o+1)),ke(l,this.toBBox),l;i||(i=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,i-1))),l=Ie([]),l.leaf=!1,l.height=i;const a=Math.ceil(r/s),c=a*Math.ceil(Math.sqrt(s));Yn(t,n,o,c,this.compareMinX);for(let u=n;u<=o;u+=c){const f=Math.min(u+c-1,o);Yn(t,u,f,a,this.compareMinY);for(let g=u;g<=f;g+=a){const h=Math.min(g+a-1,f);l.children.push(this._build(t,g,h,i-1))}}return ke(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let r=1/0,s=1/0,l;for(let a=0;a<n.children.length;a++){const c=n.children[a],u=At(c),f=Vi(t,c)-u;f<s?(s=f,r=u<r?u:r,l=c):f===s&&u<r&&(r=u,l=c)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),r=[],s=this._chooseSubtree(i,this.data,n,r);for(s.children.push(t),Ue(s,i);n>=0&&r[n].children.length>this._maxEntries;)this._split(r,n),n--;this._adjustParentBBoxes(i,r,n)}_split(t,n){const o=t[n],i=o.children.length,r=this._minEntries;this._chooseSplitAxis(o,r,i);const s=this._chooseSplitIndex(o,r,i),l=Ie(o.children.splice(s,o.children.length-s));l.height=o.height,l.leaf=o.leaf,ke(o,this.toBBox),ke(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=Ie([t,n]),this.data.height=t.height+1,this.data.leaf=!1,ke(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,r=1/0,s=1/0;for(let l=n;l<=o-n;l++){const a=Xe(t,0,l,this.toBBox),c=Xe(t,l,o,this.toBBox),u=Gi(a,c),f=At(a)+At(c);u<r?(r=u,i=l,s=f<s?f:s):u===r&&f<s&&(s=f,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Ui,r=t.leaf?this.compareMinY:Ni,s=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,r);s<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const r=this.toBBox,s=Xe(t,0,n,r),l=Xe(t,o-n,o,r);let a=xe(s)+xe(l);for(let c=n;c<o-n;c++){const u=t.children[c];Ue(s,t.leaf?r(u):u),a+=xe(s)}for(let c=o-n-1;c>=n;c--){const u=t.children[c];Ue(l,t.leaf?r(u):u),a+=xe(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)Ue(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():ke(t[n],this.toBBox)}}function Xi(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 ke(e,t){Xe(e,0,e.children.length,t,e)}function Xe(e,t,n,o,i){i||(i=Ie(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let r=t;r<n;r++){const s=e.children[r];Ue(i,e.leaf?o(s):s)}return i}function Ue(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 Ui(e,t){return e.minX-t.minX}function Ni(e,t){return e.minY-t.minY}function At(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function xe(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Vi(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 Gi(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),r=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,r-o)}function St(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function $e(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ie(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Yn(e,t,n,o,i){const r=[t,n];for(;r.length;){if(n=r.pop(),t=r.pop(),n-t<=o)continue;const s=t+Math.ceil((n-t)/o/2)*o;Dn(e,s,t,n,i),r.push(t,s,s,n)}}const ji=()=>{const e=new Ci,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!Re(f))return;const{minX:g,minY:h,maxX:m,maxY:y}=f.selector.geometry.bounds,v={minX:g,minY:h,maxX:m,maxY:y,target:f};e.insert(v),t.set(f.annotation,v)},r=f=>{if(!Re(f))return;const g=t.get(f.annotation);g&&e.remove(g),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,g)=>{const m=e.search({minX:f,minY:g,maxX:f,maxY:g}).map(y=>y.target).filter(y=>y.selector.type===K.RECTANGLE||Ct(y.selector,f,g));if(m.length>0)return m.sort((y,v)=>We(y.selector)-We(v.selector)),m[0]},getIntersecting:(f,g,h,m)=>e.search({minX:f,minY:g,maxX:f+h,maxY:g+m}).map(y=>y.target),insert:i,remove:r,set:(f,g=!0)=>{g&&o();const h=f.reduce((m,y)=>{if(Re(y)){const{minX:v,minY:p,maxX:w,maxY:_}=y.selector.geometry.bounds;return[...m,{minX:v,minY:p,maxX:w,maxY:_,target:y}]}else return m},[]);h.forEach(m=>t.set(m.target.annotation,m)),e.load(h)},size:()=>e.all().length,update:(f,g)=>{r(f),i(g)}}},Rn=e=>{const t=Mo(),n=ji(),o=ho(t,e.userSelectAction),i=uo(t),r=Bo();return t.observe(({changes:a})=>{n.set((a.created||[]).map(c=>c.target),!1),(a.deleted||[]).forEach(c=>n.remove(c.target)),(a.updated||[]).forEach(({oldValue:c,newValue:u})=>n.update(c.target,u.target))}),{store:{...t,getAt:(a,c)=>{const u=n.getAt(a,c);return u?t.getAnnotation(u.annotation):void 0},getIntersecting:(a,c,u,f)=>n.getIntersecting(a,c,u,f).map(g=>t.getAnnotation(g.annotation))},selection:o,hover:i,viewport:r}},Cn=e=>{const t=Rn(e);return{...t,store:Lo(t.store)}},Xn=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 r=1;r<10;r++){const s=Math.round(r*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(s,l,1,1).data,c=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=c}return o/81},Un=e=>{const t=Xn(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},Tt=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Un(e):n),Nn=(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}),vt=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Vn=(e,t)=>{const n=t||document,o=s=>{const l=s;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},i=s=>{const l=s;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},r=()=>{vt?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return vt?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:r}},zi=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=Nn(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Kt.EDIT,theme:"light"}),i=Cn(o),{selection:r,store:s}=i,l=Oo(s),a=Po(i,l,o.adapter,o.autoSave),c=document.createElement("DIV");c.style.position="relative",c.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(c,n),c.appendChild(n);const u=Vn(l);let f=Vo();Tt(n,c,o.theme);const g=new Pn({target:c,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});g.$on("click",D=>{const{originalEvent:E,annotation:A}=D.detail;A?r.userSelect(A.id,E):r.isEmpty()||r.clear()});const h=Yo(i,l,o.adapter),m=()=>{g.$destroy(),c.parentNode.insertBefore(n,c),c.parentNode.removeChild(c),u.destroy(),l.destroy()},y=()=>f,v=(D,E,A)=>wn(D,E,A),p=(D,E)=>un(D,E),w=D=>{if(!wt(D))throw`No drawing tool named ${D}`;g.$set({toolName:D})},_=D=>g.$set({drawingEnabled:D}),b=D=>{console.warn("Filter not implemented yet")},Y=D=>g.$set({style:D}),G=D=>Tt(n,c,D),j=D=>{f=D,g.$set({user:D})},z=D=>g.$set({visible:D});return{...h,destroy:m,getUser:y,listDrawingTools:_t,on:a.on,off:a.off,registerDrawingTool:v,registerShapeEditor:p,setDrawingEnabled:_,setDrawingTool:w,setFilter:b,setStyle:Y,setTheme:G,setUser:j,setVisible:z,element:c,state:i}};L.Editor=mt,L.EditorMount=hn,L.Handle=Le,L.IdentityTransform=Mi,L.PolygonEditor=rn,L.RectangleEditor=an,L.RectangleUtil=Xt,L.RubberbandRectangle=pn,L.SVGAnnotationLayer=Pn,L.ShapeType=K,L.ToolMount=gn,L.W3CImageFormat=Fo,L.addEventListeners=En,L.boundsFromPoints=De,L.computeArea=We,L.createImageAnnotator=zi,L.createImageAnnotatorState=Rn,L.createSVGTransform=bn,L.createSvelteImageAnnotatorState=Cn,L.detectTheme=Un,L.distance=Qe,L.enableResponsive=sn,L.fillDefaults=Nn,L.getEditor=fn,L.getSVGPoint=bt,L.getTool=wt,L.initKeyboardCommands=Vn,L.intersects=Ct,L.isImageAnnotation=Ye,L.isImageAnnotationTarget=Re,L.isMac=vt,L.isTouch=ln,L.listDrawingTools=_t,L.parseFragmentSelector=Ut,L.parseSVGSelector=jt,L.parseW3CImageAnnotation=xt,L.registerEditor=un,L.registerShapeUtil=He,L.registerTool=wn,L.sampleBrightness=Xn,L.serializeFragmentSelector=Nt,L.serializeSVGSelector=zt,L.serializeW3CImageAnnotation=$t,L.setTheme=Tt,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
1
+ (function(L,X){typeof exports=="object"&&typeof module<"u"?X(exports):typeof define=="function"&&define.amd?define(["exports"],X):(L=typeof globalThis<"u"?globalThis:L||self,X(L.Annotorious={}))})(this,function(L){"use strict";var Fi=Object.defineProperty;var Hi=(L,X,me)=>X in L?Fi(L,X,{enumerable:!0,configurable:!0,writable:!0,value:me}):L[X]=me;var Mt=(L,X,me)=>Hi(L,typeof X!="symbol"?X+"":X,me);function X(){}function me(e,t){for(const n in t)e[n]=t[n];return e}function Lt(e){return e()}function kt(){return Object.create(null)}function ce(e){e.forEach(Lt)}function q(e){return typeof e=="function"}function x(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Gn(e){return Object.keys(e).length===0}function It(e,...t){if(e==null){for(const o of t)o(void 0);return X}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function it(e,t,n){e.$$.on_destroy.push(It(t,n))}function jn(e,t,n,o){if(e){const i=Ot(e,t,n,o);return e[0](i)}}function Ot(e,t,n,o){return e[1]&&o?me(n.ctx.slice(),e[1](o(t))):n.ctx}function zn(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 r=[],s=Math.max(t.dirty.length,i.length);for(let l=0;l<s;l+=1)r[l]=t.dirty[l]|i[l];return r}return t.dirty|i}return t.dirty}function Fn(e,t,n,o,i,r){if(i){const s=Ot(t,n,o,r);e.p(s,i)}}function Hn(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 Bt(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function je(e){return e??""}function fe(e,t){e.appendChild(t)}function O(e,t,n){e.insertBefore(t,n||null)}function I(e){e.parentNode&&e.parentNode.removeChild(e)}function rt(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function U(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function Pt(e){return document.createTextNode(e)}function re(){return Pt(" ")}function se(){return Pt("")}function W(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function d(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Wn(e){return Array.from(e.childNodes)}function pe(e,t,n){e.classList.toggle(t,!!n)}function Kn(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Oe;function Be(e){Oe=e}function Dt(){if(!Oe)throw new Error("Function called outside component initialization");return Oe}function Pe(e){Dt().$$.on_mount.push(e)}function be(){const e=Dt();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const r=Kn(t,n,{cancelable:o});return i.slice().forEach(s=>{s.call(e,r)}),!r.defaultPrevented}return!0}}function ge(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const Ee=[],ze=[];let Ae=[];const Yt=[],qn=Promise.resolve();let st=!1;function Jn(){st||(st=!0,qn.then(Rt))}function lt(e){Ae.push(e)}const at=new Set;let Se=0;function Rt(){if(Se!==0)return;const e=Oe;do{try{for(;Se<Ee.length;){const t=Ee[Se];Se++,Be(t),Qn(t.$$)}}catch(t){throw Ee.length=0,Se=0,t}for(Be(null),Ee.length=0,Se=0;ze.length;)ze.pop()();for(let t=0;t<Ae.length;t+=1){const n=Ae[t];at.has(n)||(at.add(n),n())}Ae.length=0}while(Ee.length);for(;Yt.length;)Yt.pop()();st=!1,at.clear(),Be(e)}function Qn(e){if(e.fragment!==null){e.update(),ce(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(lt)}}function Zn(e){const t=[],n=[];Ae.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),Ae=t}const Fe=new Set;let we;function le(){we={r:0,c:[],p:we}}function ae(){we.r||ce(we.c),we=we.p}function P(e,t){e&&e.i&&(Fe.delete(e),e.i(t))}function N(e,t,n,o){if(e&&e.o){if(Fe.has(e))return;Fe.add(e),we.c.push(()=>{Fe.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function Te(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function te(e){e&&e.c()}function $(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),lt(()=>{const r=e.$$.on_mount.map(Lt).filter(q);e.$$.on_destroy?e.$$.on_destroy.push(...r):ce(r),e.$$.on_mount=[]}),i.forEach(lt)}function ee(e,t){const n=e.$$;n.fragment!==null&&(Zn(n.after_update),ce(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function xn(e,t){e.$$.dirty[0]===-1&&(Ee.push(e),Jn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function ne(e,t,n,o,i,r,s=null,l=[-1]){const a=Oe;Be(e);const c=e.$$={fragment:null,ctx:[],props:r,update:X,not_equal:i,bound:kt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:kt(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};s&&s(c.root);let u=!1;if(c.ctx=n?n(e,t.props||{},(f,g,...h)=>{const m=h.length?h[0]:g;return c.ctx&&i(c.ctx[f],c.ctx[f]=m)&&(!c.skip_bound&&c.bound[f]&&c.bound[f](m),u&&xn(e,f)),g}):[],c.update(),u=!0,ce(c.before_update),c.fragment=o?o(c.ctx):!1,t.target){if(t.hydrate){const f=Wn(t.target);c.fragment&&c.fragment.l(f),f.forEach(I)}else c.fragment&&c.fragment.c();t.intro&&P(e.$$.fragment),$(e,t.target,t.anchor),Rt()}Be(a)}class oe{constructor(){Mt(this,"$$");Mt(this,"$$set")}$destroy(){ee(this,1),this.$destroy=X}$on(t,n){if(!q(n))return X;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&&!Gn(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $n="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($n);var K=(e=>(e.ELLIPSE="ELLIPSE",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(K||{});const ct={},He=(e,t)=>ct[e]=t,We=e=>ct[e.type].area(e),Ct=(e,t,n)=>ct[e.type].intersects(e,t,n),De=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([r,s])=>{t=Math.min(t,r),n=Math.min(n,s),o=Math.max(o,r),i=Math.max(i,s)}),{minX:t,minY:n,maxX:o,maxY:i}},eo={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:r,ry:s}=e.geometry,l=0,a=Math.cos(l),c=Math.sin(l),u=t-o,f=n-i,g=a*u+c*f,h=c*u-a*f;return g*g/(r*r)+h*h/(s*s)<=1}};He(K.ELLIPSE,eo);const to={area:e=>{const{points:t}=e.geometry;let n=0,o=t.length-1;for(let i=0;i<t.length;i++)n+=(t[o][0]+t[i][0])*(t[o][1]-t[i][1]),o=i;return Math.abs(.5*n)},intersects:(e,t,n)=>{const{points:o}=e.geometry;let i=!1;for(let r=0,s=o.length-1;r<o.length;s=r++){const l=o[r][0],a=o[r][1],c=o[s][0],u=o[s][1];a>n!=u>n&&t<(c-l)*(n-a)/(u-a)+l&&(i=!i)}return i}};He(K.POLYGON,to);const Xt={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};He(K.RECTANGLE,Xt);const Ye=e=>Re(e.target),Re=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},Nt=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[r,s,l,a,c,u,f]=i;if(s!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[g,h,m,y]=[a,c,u,f].map(parseFloat);return{type:K.RECTANGLE,geometry:{x:g,y:h,w:m,h:y,bounds:{minX:g,minY:t?h-y:h,maxX:g+m,maxY:t?h:h+y}}}},Ut=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}`}},Vt="http://www.w3.org/2000/svg",Gt=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},no=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Vt}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},oo=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Vt),i=n.lookupNamespaceURI(null);return o||i?Gt(n).firstChild:Gt(no(n)).firstChild},io=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(r=>r.split(",").map(parseFloat));return{type:K.POLYGON,geometry:{points:i,bounds:De(i)}}},ro=e=>{const t=oo(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),r=parseFloat(t.getAttribute("ry")),s={minX:n-i,minY:o-r,maxX:n+i,maxY:o+r};return{type:K.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:r,bounds:s}}},jt=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return io(t);if(t.includes("<ellipse "))return ro(t);throw"Unsupported SVG shape: "+t},zt=e=>{let t;if(e.type===K.POLYGON){const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`}else if(e.type===K.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`};for(var J=[],ft=0;ft<256;++ft)J.push((ft+256).toString(16).slice(1));function so(e,t=0){return(J[e[t+0]]+J[e[t+1]]+J[e[t+2]]+J[e[t+3]]+"-"+J[e[t+4]]+J[e[t+5]]+"-"+J[e[t+6]]+J[e[t+7]]+"-"+J[e[t+8]]+J[e[t+9]]+"-"+J[e[t+10]]+J[e[t+11]]+J[e[t+12]]+J[e[t+13]]+J[e[t+14]]+J[e[t+15]]).toLowerCase()}var Ke,lo=new Uint8Array(16);function ao(){if(!Ke&&(Ke=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ke))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ke(lo)}var co=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ft={randomUUID:co};function Ht(e,t,n){if(Ft.randomUUID&&!t&&!e)return Ft.randomUUID();e=e||{};var o=e.random||(e.rng||ao)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,so(o)}var Wt=Object.prototype.hasOwnProperty;function ye(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--&&ye(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Wt.call(e,n)&&++o&&!Wt.call(t,n)||!(n in t)||!ye(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function ut(){}function fo(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const ve=[];function dt(e,t=ut){let n;const o=new Set;function i(l){if(fo(e,l)&&(e=l,n)){const a=!ve.length;for(const c of o)c[1](),ve.push(c,e);if(a){for(let c=0;c<ve.length;c+=2)ve[c][0](ve[c+1]);ve.length=0}}}function r(l){i(l(e))}function s(l,a=ut){const c=[l,a];return o.add(c),o.size===1&&(n=t(i,r)||ut),l(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:r,subscribe:s}}const uo=e=>{const{subscribe:t,set:n}=dt();let o;return t(i=>o=i),e.observe(({changes:i})=>{if(o){(i.deleted||[]).some(s=>s.id===o)&&n(void 0);const r=(i.updated||[]).find(({oldValue:s})=>s.id===o);r&&n(r.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Kt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Kt||{});const qe={selected:[]},ho=(e,t)=>{const{subscribe:n,set:o}=dt(qe);let i=t,r=qe;n(h=>r=h);const s=()=>{ye(r,qe)||o(qe)},l=()=>{var h;return((h=r.selected)==null?void 0:h.length)===0},a=h=>{if(l())return!1;const m=typeof h=="string"?h:h.id;return r.selected.some(y=>y.id===m)},c=(h,m)=>{const y=e.getAnnotation(h);if(!y){console.warn("Invalid selection: "+h);return}switch(qt(y,i)){case"EDIT":o({selected:[{id:h,editable:!0}],event:m});break;case"SELECT":o({selected:[{id:h}],event:m});break;default:o({selected:[],event:m})}},u=(h,m)=>{const y=Array.isArray(h)?h:[h],v=y.map(p=>e.getAnnotation(p)).filter(p=>!!p);o({selected:v.map(p=>{const w=m===void 0?qt(p,i)==="EDIT":m;return{id:p.id,editable:w}})}),v.length!==y.length&&console.warn("Invalid selection",h)},f=h=>{if(l())return!1;const{selected:m}=r;m.some(({id:y})=>h.includes(y))&&o({selected:m.filter(({id:y})=>!h.includes(y))})},g=h=>i=h;return e.observe(({changes:h})=>f((h.deleted||[]).map(m=>m.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return i},clear:s,isEmpty:l,isSelected:a,setSelected:u,setUserSelectAction:g,subscribe:n,userSelect:c}},qt=(e,t)=>typeof t=="function"?t(e):t||"EDIT";for(var Q=[],ht=0;ht<256;++ht)Q.push((ht+256).toString(16).slice(1));function go(e,t=0){return(Q[e[t+0]]+Q[e[t+1]]+Q[e[t+2]]+Q[e[t+3]]+"-"+Q[e[t+4]]+Q[e[t+5]]+"-"+Q[e[t+6]]+Q[e[t+7]]+"-"+Q[e[t+8]]+Q[e[t+9]]+"-"+Q[e[t+10]]+Q[e[t+11]]+Q[e[t+12]]+Q[e[t+13]]+Q[e[t+14]]+Q[e[t+15]]).toLowerCase()}var Je,mo=new Uint8Array(16);function po(){if(!Je&&(Je=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Je))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Je(mo)}var yo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Jt={randomUUID:yo};function _o(e,t,n){if(Jt.randomUUID&&!t&&!e)return Jt.randomUUID();e=e||{};var o=e.random||(e.rng||po)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,go(o)}const wo=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},bo=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Eo=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!ye(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Ao=(e,t)=>!ye(e.target,t.target),Qt=(e,t)=>{const n=wo(e,t),o=bo(e,t),i=Eo(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:Ao(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var H=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(H||{});const So=(e,t)=>{var n,o;const{changes:i,origin:r}=t;if(!(e.options.origin?e.options.origin===r:r!=="SILENT"))return!1;if(e.options.ignore){const{ignore:s}=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(u=>l(u.bodiesCreated)||l(u.bodiesDeleted)||l(u.bodiesUpdated)),c=(o=i.updated)==null?void 0:o.some(u=>u.targetUpdated);if(s==="BODY_ONLY"&&a&&!c||s==="TARGET_ONLY"&&c&&!a)return!1}}if(e.options.annotations){const s=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=>s.has(l))}else return!0},To=(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)),r=new Set((t.deleted||[]).map(f=>f.id)),s=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=>!r.has(f.id)).map(f=>s.has(f.id)?t.updated.find(({oldValue:g})=>g.id===f.id).newValue:f),...t.created||[]],c=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],u=[...(e.updated||[]).filter(({newValue:f})=>!r.has(f.id)).map(f=>{const{oldValue:g,newValue:h}=f;if(s.has(h.id)){const m=t.updated.find(y=>y.oldValue.id===h.id).newValue;return Qt(g,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:c,updated:u}},gt=e=>{const t=e.id===void 0?_o():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},vo=e=>e.id!==void 0,Mo=()=>{const e=new Map,t=new Map,n=[],o=(E,A={})=>{n.push({onChange:E,options:A})},i=E=>{const A=n.findIndex(S=>S.onChange==E);A>-1&&n.splice(A,1)},r=(E,A)=>{const S={origin:E,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...e.values()]};n.forEach(T=>{So(T,S)&&T.onChange(S)})},s=(E,A=H.LOCAL)=>{if(E.id&&e.get(E.id))throw Error(`Cannot add annotation ${E.id} - exists already`);{const S=gt(E);e.set(S.id,S),S.bodies.forEach(T=>t.set(T.id,S.id)),r(A,{created:[S]})}},l=(E,A)=>{const S=gt(typeof E=="string"?A:E),T=typeof E=="string"?E:E.id,V=T&&e.get(T);if(V){const C=Qt(V,S);return T===S.id?e.set(T,S):(e.delete(T),e.set(S.id,S)),V.bodies.forEach(Z=>t.delete(Z.id)),S.bodies.forEach(Z=>t.set(Z.id,S.id)),C}else console.warn(`Cannot update annotation ${T} - does not exist`)},a=(E,A=H.LOCAL,S=H.LOCAL)=>{const T=vo(A)?S:A,V=l(E,A);V&&r(T,{updated:[V]})},c=(E,A=H.LOCAL)=>{const S=E.reduce((T,V)=>{const C=l(V);return C?[...T,C]:T},[]);S.length>0&&r(A,{updated:S})},u=(E,A=H.LOCAL)=>{const S=e.get(E.annotation);if(S){const T={...S,bodies:[...S.bodies,E]};e.set(S.id,T),t.set(E.id,T.id),r(A,{updated:[{oldValue:S,newValue:T,bodiesCreated:[E]}]})}else console.warn(`Attempt to add body to missing annotation: ${E.annotation}`)},f=()=>[...e.values()],g=(E=H.LOCAL)=>{const A=[...e.values()];e.clear(),t.clear(),r(E,{deleted:A})},h=(E,A=!0,S=H.LOCAL)=>{const T=E.map(gt);if(A){const V=[...e.values()];e.clear(),t.clear(),T.forEach(C=>{e.set(C.id,C),C.bodies.forEach(Z=>t.set(Z.id,C.id))}),r(S,{created:T,deleted:V})}else{const V=E.reduce((C,Z)=>{const _e=Z.id&&e.get(Z.id);return _e?[...C,_e]:C},[]);if(V.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${V.map(C=>C.id).join(", ")}`);T.forEach(C=>{e.set(C.id,C),C.bodies.forEach(Z=>t.set(Z.id,C.id))}),r(S,{created:T})}},m=E=>{const A=typeof E=="string"?E:E.id,S=e.get(A);if(S)return e.delete(A),S.bodies.forEach(T=>t.delete(T.id)),S;console.warn(`Attempt to delete missing annotation: ${A}`)},y=(E,A=H.LOCAL)=>{const S=m(E);S&&r(A,{deleted:[S]})},v=(E,A=H.LOCAL)=>{const S=E.reduce((T,V)=>{const C=m(V);return C?[...T,C]:T},[]);S.length>0&&r(A,{deleted:S})},p=E=>{const A=e.get(E.annotation);if(A){const S=A.bodies.find(T=>T.id===E.id);if(S){t.delete(S.id);const T={...A,bodies:A.bodies.filter(V=>V.id!==E.id)};return e.set(A.id,T),{oldValue:A,newValue:T,bodiesDeleted:[S]}}else console.warn(`Attempt to delete missing body ${E.id} from annotation ${E.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${E.annotation}`)},w=(E,A=H.LOCAL)=>{const S=p(E);S&&r(A,{updated:[S]})},_=(E,A=H.LOCAL)=>{const S=E.map(T=>p(T)).filter(Boolean);S.length>0&&r(A,{updated:S})},b=E=>{const A=e.get(E);return A?{...A}:void 0},Y=E=>{const A=t.get(E);if(A){const S=b(A).bodies.find(T=>T.id===E);if(S)return S;console.error(`Store integrity error: body ${E} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${E}`)},G=(E,A)=>{if(E.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const S=e.get(E.annotation);if(S){const T=S.bodies.find(C=>C.id===E.id),V={...S,bodies:S.bodies.map(C=>C.id===T.id?A:C)};return e.set(S.id,V),T.id!==A.id&&(t.delete(T.id),t.set(A.id,V.id)),{oldValue:S,newValue:V,bodiesUpdated:[{oldBody:T,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${E.annotation}`)},j=(E,A,S=H.LOCAL)=>{const T=G(E,A);T&&r(S,{updated:[T]})},z=(E,A=H.LOCAL)=>{const S=E.map(T=>G({id:T.id,annotation:T.annotation},T)).filter(Boolean);r(A,{updated:S})},D=E=>{const A=e.get(E.annotation);if(A){const S={...A,target:{...A.target,...E}};return e.set(A.id,S),{oldValue:A,newValue:S,targetUpdated:{oldTarget:A.target,newTarget:E}}}else console.warn(`Attempt to update target on missing annotation: ${E.annotation}`)};return{addAnnotation:s,addBody:u,all:f,bulkAddAnnotation:h,bulkDeleteAnnotation:v,bulkDeleteBodies:_,bulkUpdateAnnotation:c,bulkUpdateBodies:z,bulkUpdateTargets:(E,A=H.LOCAL)=>{const S=E.map(T=>D(T)).filter(Boolean);S.length>0&&r(A,{updated:S})},clear:g,deleteAnnotation:y,deleteBody:w,getAnnotation:b,getBody:Y,observe:o,unobserve:i,updateAnnotation:a,updateBody:j,updateTarget:(E,A=H.LOCAL)=>{const S=D(E);S&&r(A,{updated:[S]})}}},Lo=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let ko=()=>({emit(e,...t){for(let n=0,o=this.events[e]||[],i=o.length;n<i;n++)o[n](...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 Io=250,Oo=e=>{const t=ko(),n=[];let o=-1,i=!1,r=0;const s=h=>{if(!i){const{changes:m}=h,y=performance.now();if(y-r>Io)n.splice(o+1),n.push(m),o=n.length-1;else{const v=n.length-1;n[v]=To(n[v],m)}r=y}i=!1};e.observe(s,{origin:H.LOCAL});const l=h=>h&&h.length>0&&e.bulkDeleteAnnotation(h),a=h=>h&&h.length>0&&e.bulkAddAnnotation(h,!1),c=h=>h&&h.length>0&&e.bulkUpdateAnnotation(h.map(({oldValue:m})=>m)),u=h=>h&&h.length>0&&e.bulkUpdateAnnotation(h.map(({newValue:m})=>m)),f=h=>h&&h.length>0&&e.bulkAddAnnotation(h,!1),g=h=>h&&h.length>0&&e.bulkDeleteAnnotation(h);return{canRedo:()=>n.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(s),on:(h,m)=>t.on(h,m),redo:()=>{if(n.length-1>o){i=!0;const{created:h,updated:m,deleted:y}=n[o+1];a(h),u(m),g(y),t.emit("redo",n[o+1]),o+=1}},undo:()=>{if(o>-1){i=!0;const{created:h,updated:m,deleted:y}=n[o];l(h),c(m),f(y),t.emit("undo",n[o]),o-=1}}}},Bo=()=>{const{subscribe:e,set:t}=dt([]);return{subscribe:e,set:t}},Po=(e,t,n,o)=>{const{store:i,selection:r,hover:s,viewport:l}=e,a=new Map;let c=[],u,f;const g=(p,w)=>{a.has(p)?a.get(p).push(w):a.set(p,[w])},h=(p,w)=>{const _=a.get(p);if(_){const b=_.indexOf(w);b!==-1&&_.splice(b,1)}},m=(p,w,_)=>{a.has(p)&&setTimeout(()=>{a.get(p).forEach(b=>{if(n){const Y=Array.isArray(w)?w.map(j=>n.serialize(j)):n.serialize(w),G=_?_ instanceof PointerEvent?_:n.serialize(_):void 0;b(Y,G)}else b(w,_)})},1)},y=()=>{const{selected:p}=r,w=(p||[]).map(({id:_})=>i.getAnnotation(_));w.forEach(_=>{const b=c.find(Y=>Y.id===_.id);(!b||!ye(b,_))&&m("updateAnnotation",_,b)}),c=c.map(_=>w.find(({id:Y})=>Y===_.id)||_)};r.subscribe(({selected:p})=>{if(!(c.length===0&&p.length===0)){if(c.length===0&&p.length>0)c=p.map(({id:w})=>i.getAnnotation(w));else if(c.length>0&&p.length===0)c.forEach(w=>{const _=i.getAnnotation(w.id);_&&!ye(_,w)&&m("updateAnnotation",_,w)}),c=[];else{const w=new Set(c.map(b=>b.id)),_=new Set(p.map(({id:b})=>b));c.filter(b=>!_.has(b.id)).forEach(b=>{const Y=i.getAnnotation(b.id);Y&&!ye(Y,b)&&m("updateAnnotation",Y,b)}),c=[...c.filter(b=>_.has(b.id)),...p.filter(({id:b})=>!w.has(b)).map(({id:b})=>i.getAnnotation(b))]}m("selectionChanged",c)}}),s.subscribe(p=>{!u&&p?m("mouseEnterAnnotation",i.getAnnotation(p)):u&&!p?m("mouseLeaveAnnotation",i.getAnnotation(u)):u&&p&&(m("mouseLeaveAnnotation",i.getAnnotation(u)),m("mouseEnterAnnotation",i.getAnnotation(p))),u=p}),l==null||l.subscribe(p=>m("viewportIntersect",p.map(w=>i.getAnnotation(w)))),i.observe(p=>{o&&(f&&clearTimeout(f),f=setTimeout(y,1e3));const{created:w,deleted:_}=p.changes;(w||[]).forEach(b=>m("createAnnotation",b)),(_||[]).forEach(b=>m("deleteAnnotation",b)),(p.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:Y})=>{const G=c.find(j=>j.id===b.id)||b;c=c.map(j=>j.id===b.id?Y:j),m("updateAnnotation",Y,G)})},{origin:H.LOCAL}),i.observe(p=>{if(c){const w=new Set(c.map(b=>b.id)),_=(p.changes.updated||[]).filter(({newValue:b})=>w.has(b.id)).map(({newValue:b})=>b);_.length>0&&(c=c.map(b=>_.find(G=>G.id===b.id)||b))}},{origin:H.REMOTE});const v=p=>w=>{const{updated:_}=w;p?(_||[]).forEach(b=>m("updateAnnotation",b.oldValue,b.newValue)):(_||[]).forEach(b=>m("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",v(!0)),t.on("redo",v(!1)),{on:g,off:h,emit:m}},Do=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:r}=e.parse(o);return r?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Yo=(e,t,n)=>{const{store:o,selection:i}=e,r=p=>{if(n){const{parsed:w,error:_}=n.parse(p);w?o.addAnnotation(w,H.REMOTE):console.error(_)}else o.addAnnotation(p,H.REMOTE)},s=()=>i.clear(),l=()=>o.clear(),a=p=>{const w=o.getAnnotation(p);return n&&w?n.serialize(w):w},c=()=>n?o.all().map(n.serialize):o.all(),u=()=>{var p;const w=(((p=i.selected)==null?void 0:p.map(_=>_.id))||[]).map(_=>o.getAnnotation(_)).filter(Boolean);return n?w.map(n.serialize):w},f=(p,w=!0)=>fetch(p).then(_=>_.json()).then(_=>(h(_,w),_)),g=p=>{if(typeof p=="string"){const w=o.getAnnotation(p);if(o.deleteAnnotation(p),w)return n?n.serialize(w):w}else{const w=n?n.parse(p).parsed:p;if(w)return o.deleteAnnotation(w),p}},h=(p,w=!0)=>{if(n){const{parsed:_,failed:b}=Do(n)(p);b.length>0&&console.warn(`Discarded ${b.length} invalid annotations`,b),o.bulkAddAnnotation(_,w,H.REMOTE)}else o.bulkAddAnnotation(p,w,H.REMOTE)},m=(p,w)=>{p?i.setSelected(p,w):i.clear()},y=p=>{i.clear(),i.setUserSelectAction(p)},v=p=>{if(n){const w=n.parse(p).parsed,_=n.serialize(o.getAnnotation(w.id));return o.updateAnnotation(w),_}else{const w=o.getAnnotation(p.id);return o.updateAnnotation(p),w}};return{addAnnotation:r,cancelSelected:s,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:c,getSelected:u,loadAnnotations:f,redo:t.redo,removeAnnotation:g,setAnnotations:h,setSelected:m,setUserSelectAction:y,undo:t.undo,updateAnnotation:v}},Ro="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Co=e=>crypto.getRandomValues(new Uint8Array(e)),Xo=(e,t,n)=>{let o=(2<<Math.log(e.length-1)/Math.LN2)-1,i=-~(1.6*o*t/e.length);return(r=t)=>{let s="";for(;;){let l=n(i),a=i;for(;a--;)if(s+=e[l[a]&o]||"",s.length===r)return s}}},No=(e,t=21)=>Xo(e,t,Co),Uo=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;)t+=Ro[n[e]&63];return t};const Vo=()=>({isGuest:!0,id:No("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Go=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let r=t.charCodeAt(o);n=(n<<5)-n+r,n|=0}return`${n}`},Zt=e=>e?typeof e=="object"?{...e}:e:void 0,jo=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:r,value:s,created:l,modified:a,creator:c,...u}=n;return{id:o||`temp-${Go(n)}`,annotation:t,type:i,purpose:r,value:s,creator:Zt(c),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...u}}),zo=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:r,...s}=t,l={...s,created:i==null?void 0:i.toISOString(),modified:r==null?void 0:r.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l});Uo();const Fo=(e,t={strict:!0,invertY:!1})=>({parse:i=>xt(i,t),serialize:i=>$t(i,e,t)}),xt=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Ht(),{creator:o,created:i,modified:r,body:s,...l}=e,a=jo(s||[],n),c=Array.isArray(e.target)?e.target[0]:e.target,u=Array.isArray(c.selector)?c.selector[0]:c.selector,f=(u==null?void 0:u.type)==="FragmentSelector"?Nt(u,t.invertY):(u==null?void 0:u.type)==="SvgSelector"?jt(u):void 0;return f||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Zt(o),updated:r?new Date(r):void 0,...Array.isArray(l.target)?l.target[0]:l.target,annotation:n,selector:f||u}}}:{error:Error(`Invalid selector: ${JSON.stringify(u)}`)}},$t=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:r,updated:s,updatedBy:l,...a}=e.target;let c;try{c=o.type==K.RECTANGLE?Ut(o.geometry):zt(o)}catch(f){if(n.strict)throw f;c=o}const u={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:zo(e.bodies),created:r==null?void 0:r.toISOString(),creator:i,modified:s==null?void 0:s.toISOString(),target:{...a,source:t,selector:c}};return delete u.bodies,"annotation"in u.target&&delete u.target.annotation,u};function en(e,t,n){const o=e.slice();return o[10]=t[n],o[12]=n,o}function tn(e){let t,n;return t=new Le({props:{x:e[10][0],y:e[10][1],scale:e[3]}}),t.$on("pointerdown",function(){q(e[9](`HANDLE-${e[12]}`))&&e[9](`HANDLE-${e[12]}`).apply(this,arguments)}),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){e=o;const r={};i&16&&(r.x=e[10][0]),i&16&&(r.y=e[10][1]),i&8&&(r.scale=e[3]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Ho(e){let t,n,o,i,r,s,l,a,c,u,f,g=Te(e[4].points),h=[];for(let y=0;y<g.length;y+=1)h[y]=tn(en(e,g,y));const m=y=>N(h[y],1,1,()=>{h[y]=null});return{c(){t=U("polygon"),i=re(),r=U("polygon"),l=re();for(let y=0;y<h.length;y+=1)h[y].c();a=se(),d(t,"class","a9s-outer"),d(t,"style",n=e[1]?"display:none;":void 0),d(t,"points",o=e[4].points.map(nn).join(" ")),d(r,"class","a9s-inner a9s-shape-handle"),d(r,"style",e[1]),d(r,"points",s=e[4].points.map(on).join(" "))},m(y,v){O(y,t,v),O(y,i,v),O(y,r,v),O(y,l,v);for(let p=0;p<h.length;p+=1)h[p]&&h[p].m(y,v);O(y,a,v),c=!0,u||(f=[W(t,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(r,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)})],u=!0)},p(y,v){if(e=y,(!c||v&2&&n!==(n=e[1]?"display:none;":void 0))&&d(t,"style",n),(!c||v&16&&o!==(o=e[4].points.map(nn).join(" ")))&&d(t,"points",o),(!c||v&2)&&d(r,"style",e[1]),(!c||v&16&&s!==(s=e[4].points.map(on).join(" ")))&&d(r,"points",s),v&536){g=Te(e[4].points);let p;for(p=0;p<g.length;p+=1){const w=en(e,g,p);h[p]?(h[p].p(w,v),P(h[p],1)):(h[p]=tn(w),h[p].c(),P(h[p],1),h[p].m(a.parentNode,a))}for(le(),p=g.length;p<h.length;p+=1)m(p);ae()}},i(y){if(!c){for(let v=0;v<g.length;v+=1)P(h[v]);c=!0}},o(y){h=h.filter(Boolean);for(let v=0;v<h.length;v+=1)N(h[v]);c=!1},d(y){y&&(I(t),I(i),I(r),I(l),I(a)),rt(h,y),u=!1,ce(f)}}}function Wo(e){let t,n;return t=new mt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Ho,({grab:o})=>({9:o}),({grab:o})=>o?512:0]},$$scope:{ctx:e}}}),t.$on("change",e[6]),t.$on("grab",e[7]),t.$on("release",e[8]),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,[i]){const r={};i&1&&(r.shape=o[0]),i&4&&(r.transform=o[2]),i&8730&&(r.$$scope={dirty:i,ctx:o}),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}const nn=e=>e.join(","),on=e=>e.join(",");function Ko(e,t,n){let o,{shape:i}=t,{computedStyle:r}=t,{transform:s}=t,{viewportScale:l=1}=t;const a=(g,h,m)=>{let y;const v=g.geometry;h==="SHAPE"?y=v.points.map(([w,_])=>[w+m[0],_+m[1]]):y=v.points.map(([w,_],b)=>h===`HANDLE-${b}`?[w+m[0],_+m[1]]:[w,_]);const p=De(y);return{...g,geometry:{points:y,bounds:p}}};function c(g){ge.call(this,e,g)}function u(g){ge.call(this,e,g)}function f(g){ge.call(this,e,g)}return e.$$set=g=>{"shape"in g&&n(0,i=g.shape),"computedStyle"in g&&n(1,r=g.computedStyle),"transform"in g&&n(2,s=g.transform),"viewportScale"in g&&n(3,l=g.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=i.geometry)},[i,r,s,l,o,a,c,u,f]}class rn extends oe{constructor(t){super(),ne(this,t,Ko,Wo,x,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const Qe=(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))},Me=[];function qo(e,t=X){let n;const o=new Set;function i(l){if(x(e,l)&&(e=l,n)){const a=!Me.length;for(const c of o)c[1](),Me.push(c,e);if(a){for(let c=0;c<Me.length;c+=2)Me[c][0](Me[c+1]);Me.length=0}}}function r(l){i(l(e))}function s(l,a=X){const c=[l,a];return o.add(c),o.size===1&&(n=t(i,r)||X),l(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:r,subscribe:s}}const Jo=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:r}=e;t.setAttribute("viewBox",`0 0 ${i} ${r}`),e.addEventListener("load",s=>{const l=s.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},sn=(e,t)=>{Jo(e,t);const{subscribe:n,set:o}=qo(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const s=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,c=Math.max(s.width/l,s.height/a);o(c)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},ln=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function Qo(e){let t,n,o,i,r,s;return{c(){t=U("rect"),d(t,"class",n=je(`a9s-handle ${e[8].class||""}`.trim())+" svelte-1sgkh33"),d(t,"x",o=e[0]-e[5]/2),d(t,"y",i=e[1]-e[5]/2),d(t,"width",e[5]),d(t,"height",e[5])},m(l,a){O(l,t,a),r||(s=W(t,"pointerdown",e[11]),r=!0)},p(l,a){a&256&&n!==(n=je(`a9s-handle ${l[8].class||""}`.trim())+" svelte-1sgkh33")&&d(t,"class",n),a&33&&o!==(o=l[0]-l[5]/2)&&d(t,"x",o),a&34&&i!==(i=l[1]-l[5]/2)&&d(t,"y",i),a&32&&d(t,"width",l[5]),a&32&&d(t,"height",l[5])},d(l){l&&I(t),r=!1,s()}}}function Zo(e){let t,n,o,i,r,s,l,a,c;return{c(){t=U("g"),n=U("circle"),i=U("rect"),d(n,"cx",e[0]),d(n,"cy",e[1]),d(n,"r",o=e[3]/e[2]),d(n,"class","a9s-touch-halo svelte-1sgkh33"),pe(n,"touched",e[4]),d(i,"class",r=je(`a9s-handle ${e[8].class||""}`.trim())+" svelte-1sgkh33"),d(i,"x",s=e[0]-e[5]/2),d(i,"y",l=e[1]-e[5]/2),d(i,"width",e[5]),d(i,"height",e[5]),d(t,"class","a9s-touch-handle")},m(u,f){O(u,t,f),fe(t,n),fe(t,i),a||(c=[W(n,"pointerdown",e[10]),W(n,"pointerdown",e[6]),W(n,"pointerup",e[7]),W(i,"pointerdown",e[9]),W(i,"pointerdown",e[6]),W(i,"pointerup",e[7])],a=!0)},p(u,f){f&1&&d(n,"cx",u[0]),f&2&&d(n,"cy",u[1]),f&12&&o!==(o=u[3]/u[2])&&d(n,"r",o),f&16&&pe(n,"touched",u[4]),f&256&&r!==(r=je(`a9s-handle ${u[8].class||""}`.trim())+" svelte-1sgkh33")&&d(i,"class",r),f&33&&s!==(s=u[0]-u[5]/2)&&d(i,"x",s),f&34&&l!==(l=u[1]-u[5]/2)&&d(i,"y",l),f&32&&d(i,"width",u[5]),f&32&&d(i,"height",u[5])},d(u){u&&I(t),a=!1,ce(c)}}}function xo(e){let t;function n(r,s){return ln?Zo:Qo}let i=n()(e);return{c(){i.c(),t=se()},m(r,s){i.m(r,s),O(r,t,s)},p(r,[s]){i.p(r,s)},i:X,o:X,d(r){r&&I(t),i.d(r)}}}function $o(e,t,n){let o,{x:i}=t,{y:r}=t,{scale:s}=t,{radius:l=30}=t,a=!1;const c=m=>{m.pointerType==="touch"&&n(4,a=!0)},u=()=>n(4,a=!1);function f(m){ge.call(this,e,m)}function g(m){ge.call(this,e,m)}function h(m){ge.call(this,e,m)}return e.$$set=m=>{n(8,t=me(me({},t),Bt(m))),"x"in m&&n(0,i=m.x),"y"in m&&n(1,r=m.y),"scale"in m&&n(2,s=m.scale),"radius"in m&&n(3,l=m.radius)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=10/s)},t=Bt(t),[i,r,s,l,a,o,c,u,t,f,g,h]}class Le extends oe{constructor(t){super(),ne(this,t,$o,xo,x,{x:0,y:1,scale:2,radius:3})}}function ei(e){let t,n,o,i,r,s,l,a,c,u,f,g,h,m,y,v,p,w,_,b,Y,G,j,z,D,E,A,S,T,V,C,Z,_e,ue,Ue,de,Ve,he,Ge,k,R,F,ie;return ue=new Le({props:{class:"a9s-corner-handle-topleft",x:e[4].x,y:e[4].y,scale:e[3]}}),ue.$on("pointerdown",function(){q(e[9]("TOP_LEFT"))&&e[9]("TOP_LEFT").apply(this,arguments)}),de=new Le({props:{class:"a9s-corner-handle-topright",x:e[4].x+e[4].w,y:e[4].y,scale:e[3]}}),de.$on("pointerdown",function(){q(e[9]("TOP_RIGHT"))&&e[9]("TOP_RIGHT").apply(this,arguments)}),he=new Le({props:{class:"a9s-corner-handle-bottomright",x:e[4].x+e[4].w,y:e[4].y+e[4].h,scale:e[3]}}),he.$on("pointerdown",function(){q(e[9]("BOTTOM_RIGHT"))&&e[9]("BOTTOM_RIGHT").apply(this,arguments)}),k=new Le({props:{class:"a9s-corner-handle-bottomleft",x:e[4].x,y:e[4].y+e[4].h,scale:e[3]}}),k.$on("pointerdown",function(){q(e[9]("BOTTOM_LEFT"))&&e[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=U("rect"),l=re(),a=U("rect"),h=re(),m=U("rect"),w=re(),_=U("rect"),j=re(),z=U("rect"),S=re(),T=U("rect"),_e=re(),te(ue.$$.fragment),Ue=re(),te(de.$$.fragment),Ve=re(),te(he.$$.fragment),Ge=re(),te(k.$$.fragment),d(t,"class","a9s-outer"),d(t,"style",n=e[1]?"display:none;":void 0),d(t,"x",o=e[4].x),d(t,"y",i=e[4].y),d(t,"width",r=e[4].w),d(t,"height",s=e[4].h),d(a,"class","a9s-inner a9s-shape-handle"),d(a,"style",e[1]),d(a,"x",c=e[4].x),d(a,"y",u=e[4].y),d(a,"width",f=e[4].w),d(a,"height",g=e[4].h),d(m,"class","a9s-edge-handle a9s-edge-handle-top"),d(m,"x",y=e[4].x),d(m,"y",v=e[4].y),d(m,"height",1),d(m,"width",p=e[4].w),d(_,"class","a9s-edge-handle a9s-edge-handle-right"),d(_,"x",b=e[4].x+e[4].w),d(_,"y",Y=e[4].y),d(_,"height",G=e[4].h),d(_,"width",1),d(z,"class","a9s-edge-handle a9s-edge-handle-bottom"),d(z,"x",D=e[4].x),d(z,"y",E=e[4].y+e[4].h),d(z,"height",1),d(z,"width",A=e[4].w),d(T,"class","a9s-edge-handle a9s-edge-handle-left"),d(T,"x",V=e[4].x),d(T,"y",C=e[4].y),d(T,"height",Z=e[4].h),d(T,"width",1)},m(B,M){O(B,t,M),O(B,l,M),O(B,a,M),O(B,h,M),O(B,m,M),O(B,w,M),O(B,_,M),O(B,j,M),O(B,z,M),O(B,S,M),O(B,T,M),O(B,_e,M),$(ue,B,M),O(B,Ue,M),$(de,B,M),O(B,Ve,M),$(he,B,M),O(B,Ge,M),$(k,B,M),R=!0,F||(ie=[W(t,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(a,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(m,"pointerdown",function(){q(e[9]("TOP"))&&e[9]("TOP").apply(this,arguments)}),W(_,"pointerdown",function(){q(e[9]("RIGHT"))&&e[9]("RIGHT").apply(this,arguments)}),W(z,"pointerdown",function(){q(e[9]("BOTTOM"))&&e[9]("BOTTOM").apply(this,arguments)}),W(T,"pointerdown",function(){q(e[9]("LEFT"))&&e[9]("LEFT").apply(this,arguments)})],F=!0)},p(B,M){e=B,(!R||M&2&&n!==(n=e[1]?"display:none;":void 0))&&d(t,"style",n),(!R||M&16&&o!==(o=e[4].x))&&d(t,"x",o),(!R||M&16&&i!==(i=e[4].y))&&d(t,"y",i),(!R||M&16&&r!==(r=e[4].w))&&d(t,"width",r),(!R||M&16&&s!==(s=e[4].h))&&d(t,"height",s),(!R||M&2)&&d(a,"style",e[1]),(!R||M&16&&c!==(c=e[4].x))&&d(a,"x",c),(!R||M&16&&u!==(u=e[4].y))&&d(a,"y",u),(!R||M&16&&f!==(f=e[4].w))&&d(a,"width",f),(!R||M&16&&g!==(g=e[4].h))&&d(a,"height",g),(!R||M&16&&y!==(y=e[4].x))&&d(m,"x",y),(!R||M&16&&v!==(v=e[4].y))&&d(m,"y",v),(!R||M&16&&p!==(p=e[4].w))&&d(m,"width",p),(!R||M&16&&b!==(b=e[4].x+e[4].w))&&d(_,"x",b),(!R||M&16&&Y!==(Y=e[4].y))&&d(_,"y",Y),(!R||M&16&&G!==(G=e[4].h))&&d(_,"height",G),(!R||M&16&&D!==(D=e[4].x))&&d(z,"x",D),(!R||M&16&&E!==(E=e[4].y+e[4].h))&&d(z,"y",E),(!R||M&16&&A!==(A=e[4].w))&&d(z,"width",A),(!R||M&16&&V!==(V=e[4].x))&&d(T,"x",V),(!R||M&16&&C!==(C=e[4].y))&&d(T,"y",C),(!R||M&16&&Z!==(Z=e[4].h))&&d(T,"height",Z);const et={};M&16&&(et.x=e[4].x),M&16&&(et.y=e[4].y),M&8&&(et.scale=e[3]),ue.$set(et);const tt={};M&16&&(tt.x=e[4].x+e[4].w),M&16&&(tt.y=e[4].y),M&8&&(tt.scale=e[3]),de.$set(tt);const nt={};M&16&&(nt.x=e[4].x+e[4].w),M&16&&(nt.y=e[4].y+e[4].h),M&8&&(nt.scale=e[3]),he.$set(nt);const ot={};M&16&&(ot.x=e[4].x),M&16&&(ot.y=e[4].y+e[4].h),M&8&&(ot.scale=e[3]),k.$set(ot)},i(B){R||(P(ue.$$.fragment,B),P(de.$$.fragment,B),P(he.$$.fragment,B),P(k.$$.fragment,B),R=!0)},o(B){N(ue.$$.fragment,B),N(de.$$.fragment,B),N(he.$$.fragment,B),N(k.$$.fragment,B),R=!1},d(B){B&&(I(t),I(l),I(a),I(h),I(m),I(w),I(_),I(j),I(z),I(S),I(T),I(_e),I(Ue),I(Ve),I(Ge)),ee(ue,B),ee(de,B),ee(he,B),ee(k,B),F=!1,ce(ie)}}}function ti(e){let t,n;return t=new mt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[ei,({grab:o})=>({9:o}),({grab:o})=>o?512:0]},$$scope:{ctx:e}}}),t.$on("grab",e[6]),t.$on("change",e[7]),t.$on("release",e[8]),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,[i]){const r={};i&1&&(r.shape=o[0]),i&4&&(r.transform=o[2]),i&1562&&(r.$$scope={dirty:i,ctx:o}),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function ni(e,t,n){let o,{shape:i}=t,{computedStyle:r}=t,{transform:s}=t,{viewportScale:l=1}=t;const a=(g,h,m)=>{const y=g.geometry.bounds;let[v,p]=[y.minX,y.minY],[w,_]=[y.maxX,y.maxY];const[b,Y]=m;if(h==="SHAPE")v+=b,w+=b,p+=Y,_+=Y;else{switch(h){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{p+=Y;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{_+=Y;break}}switch(h){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{v+=b;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{w+=b;break}}}const G=Math.min(v,w),j=Math.min(p,_),z=Math.abs(w-v),D=Math.abs(_-p);return{...g,geometry:{x:G,y:j,w:z,h:D,bounds:{minX:G,minY:j,maxX:G+z,maxY:j+D}}}};function c(g){ge.call(this,e,g)}function u(g){ge.call(this,e,g)}function f(g){ge.call(this,e,g)}return e.$$set=g=>{"shape"in g&&n(0,i=g.shape),"computedStyle"in g&&n(1,r=g.computedStyle),"transform"in g&&n(2,s=g.transform),"viewportScale"in g&&n(3,l=g.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=i.geometry)},[i,r,s,l,o,a,c,u,f]}class an extends oe{constructor(t){super(),ne(this,t,ni,ti,x,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const cn=new Map([[K.RECTANGLE,an],[K.POLYGON,rn]]),fn=e=>cn.get(e.type),un=(e,t)=>cn.set(e,t),oi=e=>({}),dn=e=>({grab:e[0]});function ii(e){let t,n,o,i;const r=e[7].default,s=jn(r,e,e[6],dn);return{c(){t=U("g"),s&&s.c(),d(t,"class","a9s-annotation selected")},m(l,a){O(l,t,a),s&&s.m(t,null),n=!0,o||(i=[W(t,"pointerup",e[2]),W(t,"pointermove",e[1])],o=!0)},p(l,[a]){s&&s.p&&(!n||a&64)&&Fn(s,r,l,l[6],n?zn(r,l[6],a,oi):Hn(l[6]),dn)},i(l){n||(P(s,l),n=!0)},o(l){N(s,l),n=!1},d(l){l&&I(t),s&&s.d(l),o=!1,ce(i)}}}function ri(e,t,n){let{$$slots:o={},$$scope:i}=t;const r=be();let{shape:s}=t,{editor:l}=t,{transform:a}=t,c,u,f;const g=y=>v=>{c=y,u=a.elementToImage(v.offsetX,v.offsetY),f=s,v.target.setPointerCapture(v.pointerId),r("grab",v)},h=y=>{if(c){const[v,p]=a.elementToImage(y.offsetX,y.offsetY),w=[v-u[0],p-u[1]];n(3,s=l(f,c,w)),r("change",s)}},m=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,f=s,r("release",y)};return e.$$set=y=>{"shape"in y&&n(3,s=y.shape),"editor"in y&&n(4,l=y.editor),"transform"in y&&n(5,a=y.transform),"$$scope"in y&&n(6,i=y.$$scope)},[g,h,m,s,l,a,i,o]}class mt extends oe{constructor(t){super(),ne(this,t,ri,ii,x,{shape:3,editor:4,transform:5})}}const Ze=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i,stroke:r,strokeWidth:s,strokeOpacity:l}=n;let a="";return o&&(a+=`fill:${o};`,a+=`fill-opacity:${i||"0.25"};`),r&&(a+=`stroke:${r};`,a+=`stroke-width:${s||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}};function si(e,t,n){let o;const i=be();let{annotation:r}=t,{editor:s}=t,{style:l}=t,{target:a}=t,{transform:c}=t,{viewportScale:u}=t,f;return Pe(()=>(n(6,f=new s({target:a,props:{shape:r.target.selector,computedStyle:o,transform:c,viewportScale:u}})),f.$on("change",g=>{f.$$set({shape:g.detail}),i("change",g.detail)}),f.$on("grab",g=>i("grab",g.detail)),f.$on("release",g=>i("release",g.detail)),()=>{f.$destroy()})),e.$$set=g=>{"annotation"in g&&n(0,r=g.annotation),"editor"in g&&n(1,s=g.editor),"style"in g&&n(2,l=g.style),"target"in g&&n(3,a=g.target),"transform"in g&&n(4,c=g.transform),"viewportScale"in g&&n(5,u=g.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&(o=Ze(r,l)),e.$$.dirty&65&&r&&(f==null||f.$set({shape:r.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:c}),e.$$.dirty&96&&f&&f.$set({viewportScale:u})},[r,s,l,a,c,u,f]}class hn extends oe{constructor(t){super(),ne(this,t,si,null,x,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function li(e,t,n){const o=be();let{drawingMode:i}=t,{target:r}=t,{tool:s}=t,{transform:l}=t,{viewportScale:a}=t,c;return Pe(()=>{const u=r.closest("svg"),f=[],g=(h,m,y)=>{u==null||u.addEventListener(h,m,y),f.push(()=>u==null?void 0:u.removeEventListener(h,m,y))};return n(5,c=new s({target:r,props:{addEventListener:g,drawingMode:i,transform:l,viewportScale:a}})),c.$on("create",h=>o("create",h.detail)),()=>{f.forEach(h=>h()),c.$destroy()}}),e.$$set=u=>{"drawingMode"in u&&n(0,i=u.drawingMode),"target"in u&&n(1,r=u.target),"tool"in u&&n(2,s=u.tool),"transform"in u&&n(3,l=u.transform),"viewportScale"in u&&n(4,a=u.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&c&&c.$set({transform:l}),e.$$.dirty&48&&c&&c.$set({viewportScale:a})},[i,r,s,l,a,c]}class gn extends oe{constructor(t){super(),ne(this,t,li,null,x,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function mn(e){let t,n;return{c(){t=U("rect"),n=U("rect"),d(t,"class","a9s-outer"),d(t,"x",e[1]),d(t,"y",e[2]),d(t,"width",e[3]),d(t,"height",e[4]),d(n,"class","a9s-inner"),d(n,"x",e[1]),d(n,"y",e[2]),d(n,"width",e[3]),d(n,"height",e[4])},m(o,i){O(o,t,i),O(o,n,i)},p(o,i){i&2&&d(t,"x",o[1]),i&4&&d(t,"y",o[2]),i&8&&d(t,"width",o[3]),i&16&&d(t,"height",o[4]),i&2&&d(n,"x",o[1]),i&4&&d(n,"y",o[2]),i&8&&d(n,"width",o[3]),i&16&&d(n,"height",o[4])},d(o){o&&(I(t),I(n))}}}function ai(e){let t,n=e[0]&&mn(e);return{c(){t=U("g"),n&&n.c(),d(t,"class","a9s-annotation a9s-rubberband")},m(o,i){O(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=mn(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:X,o:X,d(o){o&&I(t),n&&n.d()}}}function ci(e,t,n){const o=be();let{addEventListener:i}=t,{drawingMode:r}=t,{transform:s}=t,l,a,c,u,f,g,h;const m=w=>{const _=w;l=performance.now(),r==="drag"&&(n(0,a=s.elementToImage(_.offsetX,_.offsetY)),c=a,n(1,u=a[0]),n(2,f=a[1]),n(3,g=1),n(4,h=1))},y=w=>{const _=w;a&&(c=s.elementToImage(_.offsetX,_.offsetY),n(1,u=Math.min(c[0],a[0])),n(2,f=Math.min(c[1],a[1])),n(3,g=Math.abs(c[0]-a[0])),n(4,h=Math.abs(c[1]-a[1])))},v=w=>{const _=w,b=performance.now()-l;if(r==="click"){if(b>300)return;a?p():(n(0,a=s.elementToImage(_.offsetX,_.offsetY)),c=a,n(1,u=a[0]),n(2,f=a[1]),n(3,g=1),n(4,h=1))}else a&&(b>300||g*h>100?(_.stopPropagation(),p()):(n(0,a=void 0),c=void 0))},p=()=>{if(g*h>15){const w={type:K.RECTANGLE,geometry:{bounds:{minX:u,minY:f,maxX:u+g,maxY:f+h},x:u,y:f,w:g,h}};o("create",w)}n(0,a=void 0),c=void 0};return Pe(()=>{i("pointerdown",m),i("pointermove",y),i("pointerup",v,!0)}),e.$$set=w=>{"addEventListener"in w&&n(5,i=w.addEventListener),"drawingMode"in w&&n(6,r=w.drawingMode),"transform"in w&&n(7,s=w.transform)},[a,u,f,g,h,i,r,s]}class pn extends oe{constructor(t){super(),ne(this,t,ci,ai,x,{addEventListener:5,drawingMode:6,transform:7})}}function pt(e){const t=e.slice(),n=(t[2]?t[0]:[...t[0],t[1]]).map(o=>o.join(",")).join(" ");return t[16]=n,t}function yn(e){let t,n,o,i,r,s=e[2]&&_n(e);return{c(){t=U("polygon"),o=U("polygon"),s&&s.c(),r=se(),d(t,"class","a9s-outer"),d(t,"points",n=e[16]),d(o,"class","a9s-inner"),d(o,"points",i=e[16])},m(l,a){O(l,t,a),O(l,o,a),s&&s.m(l,a),O(l,r,a)},p(l,a){a&7&&n!==(n=l[16])&&d(t,"points",n),a&7&&i!==(i=l[16])&&d(o,"points",i),l[2]?s?s.p(l,a):(s=_n(l),s.c(),s.m(r.parentNode,r)):s&&(s.d(1),s=null)},d(l){l&&(I(t),I(o),I(r)),s&&s.d(l)}}}function _n(e){let t,n,o;return{c(){t=U("rect"),d(t,"class","a9s-corner-handle"),d(t,"x",n=e[0][0][0]-e[3]/2),d(t,"y",o=e[0][0][1]-e[3]/2),d(t,"height",e[3]),d(t,"width",e[3])},m(i,r){O(i,t,r)},p(i,r){r&9&&n!==(n=i[0][0][0]-i[3]/2)&&d(t,"x",n),r&9&&o!==(o=i[0][0][1]-i[3]/2)&&d(t,"y",o),r&8&&d(t,"height",i[3]),r&8&&d(t,"width",i[3])},d(i){i&&I(t)}}}function fi(e){let t,n=e[1]&&yn(pt(e));return{c(){t=U("g"),n&&n.c(),d(t,"class","a9s-annotation a9s-rubberband")},m(o,i){O(o,t,i),n&&n.m(t,null)},p(o,[i]){o[1]?n?n.p(pt(o),i):(n=yn(pt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:X,o:X,d(o){o&&I(t),n&&n.d()}}}const ui=20,di=1500;function hi(e,t,n){let o;const i=be();let{addEventListener:r}=t,{drawingMode:s}=t,{transform:l}=t,{viewportScale:a=1}=t,c,u=[],f,g,h=!1;const m=_=>{const b=_,{timeStamp:Y,offsetX:G,offsetY:j}=b;if(c={timeStamp:Y,offsetX:G,offsetY:j},s==="drag"&&u.length===0){const z=l.elementToImage(b.offsetX,b.offsetY);u.push(z),n(1,f=z)}},y=_=>{const b=_;if(g&&clearTimeout(g),u.length>0){if(n(1,f=l.elementToImage(b.offsetX,b.offsetY)),u.length>2){const Y=Qe(f,u[0])*a;n(2,h=Y<ui)}b.pointerType==="touch"&&(g=setTimeout(()=>{p()},di))}},v=_=>{const b=_;if(g&&clearTimeout(g),s==="click"){const Y=b.timeStamp-c.timeStamp,G=Qe([c.offsetX,c.offsetY],[b.offsetX,b.offsetY]);if(Y>300||G>15)return;if(h)w();else if(u.length===0){const j=l.elementToImage(b.offsetX,b.offsetY);u.push(j),n(1,f=j)}else u.push(f)}else{if(u.length===1&&Qe(u[0],f)<=4){n(0,u=[]),n(1,f=void 0);return}b.stopImmediatePropagation(),h?w():u.push(f)}},p=()=>{if(!f)return;const _=[...u,f],b={type:K.POLYGON,geometry:{bounds:De(_),points:_}};We(b)>4&&(n(0,u=[]),n(1,f=void 0),i("create",b))},w=()=>{const _={type:K.POLYGON,geometry:{bounds:De(u),points:[...u]}};n(0,u=[]),n(1,f=void 0),i("create",_)};return Pe(()=>{r("pointerdown",m,!0),r("pointermove",y),r("pointerup",v,!0),r("dblclick",p,!0)}),e.$$set=_=>{"addEventListener"in _&&n(4,r=_.addEventListener),"drawingMode"in _&&n(5,s=_.drawingMode),"transform"in _&&n(6,l=_.transform),"viewportScale"in _&&n(7,a=_.viewportScale)},e.$$.update=()=>{e.$$.dirty&128&&n(3,o=10/a)},[u,f,h,o,r,s,l,a]}class gi extends oe{constructor(t){super(),ne(this,t,hi,fi,x,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const yt=new Map([["rectangle",{tool:pn}],["polygon",{tool:gi}]]),_t=()=>[...yt.keys()],wt=e=>yt.get(e),wn=(e,t,n)=>yt.set(e,{tool:t,opts:n});function mi(e){let t,n,o,i,r;return{c(){t=U("g"),n=U("ellipse"),i=U("ellipse"),d(n,"class","a9s-outer"),d(n,"style",o=e[1]?"display:none;":void 0),d(n,"cx",e[2]),d(n,"cy",e[3]),d(n,"rx",e[4]),d(n,"ry",e[5]),d(i,"class","a9s-inner"),d(i,"style",e[1]),d(i,"cx",e[2]),d(i,"cy",e[3]),d(i,"rx",e[4]),d(i,"ry",e[5]),d(t,"class","a9s-annotation"),d(t,"data-id",r=e[0].id)},m(s,l){O(s,t,l),fe(t,n),fe(t,i)},p(s,[l]){l&2&&o!==(o=s[1]?"display:none;":void 0)&&d(n,"style",o),l&2&&d(i,"style",s[1]),l&1&&r!==(r=s[0].id)&&d(t,"data-id",r)},i:X,o:X,d(s){s&&I(t)}}}function pi(e,t,n){let o,{annotation:i}=t,{geom:r}=t,{style:s}=t;const{cx:l,cy:a,rx:c,ry:u}=r;return e.$$set=f=>{"annotation"in f&&n(0,i=f.annotation),"geom"in f&&n(6,r=f.geom),"style"in f&&n(7,s=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ze(i,s))},[i,o,l,a,c,u,r,s]}class yi extends oe{constructor(t){super(),ne(this,t,pi,mi,x,{annotation:0,geom:6,style:7})}}function _i(e){let t,n,o,i,r;return{c(){t=U("g"),n=U("polygon"),i=U("polygon"),d(n,"class","a9s-outer"),d(n,"style",o=e[1]?"display:none;":void 0),d(n,"points",e[2].map(wi).join(" ")),d(i,"class","a9s-inner"),d(i,"style",e[1]),d(i,"points",e[2].map(bi).join(" ")),d(t,"class","a9s-annotation"),d(t,"data-id",r=e[0].id)},m(s,l){O(s,t,l),fe(t,n),fe(t,i)},p(s,[l]){l&2&&o!==(o=s[1]?"display:none;":void 0)&&d(n,"style",o),l&2&&d(i,"style",s[1]),l&1&&r!==(r=s[0].id)&&d(t,"data-id",r)},i:X,o:X,d(s){s&&I(t)}}}const wi=e=>e.join(","),bi=e=>e.join(",");function Ei(e,t,n){let o,{annotation:i}=t,{geom:r}=t,{style:s}=t;const{points:l}=r;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,r=a.geom),"style"in a&&n(4,s=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ze(i,s))},[i,o,l,r,s]}class Ai extends oe{constructor(t){super(),ne(this,t,Ei,_i,x,{annotation:0,geom:3,style:4})}}function Si(e){let t,n,o,i,r;return{c(){t=U("g"),n=U("rect"),i=U("rect"),d(n,"class","a9s-outer"),d(n,"style",o=e[5]?"display:none;":void 0),d(n,"x",e[4]),d(n,"y",e[3]),d(n,"width",e[2]),d(n,"height",e[1]),d(i,"class","a9s-inner"),d(i,"style",e[5]),d(i,"x",e[4]),d(i,"y",e[3]),d(i,"width",e[2]),d(i,"height",e[1]),d(t,"class","a9s-annotation"),d(t,"data-id",r=e[0].id)},m(s,l){O(s,t,l),fe(t,n),fe(t,i)},p(s,[l]){l&32&&o!==(o=s[5]?"display:none;":void 0)&&d(n,"style",o),l&16&&d(n,"x",s[4]),l&8&&d(n,"y",s[3]),l&4&&d(n,"width",s[2]),l&2&&d(n,"height",s[1]),l&32&&d(i,"style",s[5]),l&16&&d(i,"x",s[4]),l&8&&d(i,"y",s[3]),l&4&&d(i,"width",s[2]),l&2&&d(i,"height",s[1]),l&1&&r!==(r=s[0].id)&&d(t,"data-id",r)},i:X,o:X,d(s){s&&I(t)}}}function Ti(e,t,n){let o,i,r,s,l,{annotation:a}=t,{geom:c}=t,{style:u}=t;return e.$$set=f=>{"annotation"in f&&n(0,a=f.annotation),"geom"in f&&n(6,c=f.geom),"style"in f&&n(7,u=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=Ze(a,u)),e.$$.dirty&64&&n(4,{x:i,y:r,w:s,h:l}=c,i,(n(3,r),n(6,c)),(n(2,s),n(6,c)),(n(1,l),n(6,c)))},[a,l,s,r,i,o,c,u]}class vi extends oe{constructor(t){super(),ne(this,t,Ti,Si,x,{annotation:0,geom:6,style:7})}}const Mi={elementToImage:(e,t)=>[e,t]},bn=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:r,y:s}=i.matrixTransform(e.getScreenCTM().inverse());return[r,s]}}),Li=250,En=(e,t)=>{const n=be();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:s=>{if(performance.now()-o<Li){const{x:a,y:c}=bt(s,e),u=t.getAt(a,c);u?n("click",{originalEvent:s,annotation:u}):n("click",{originalEvent:s})}}}},bt=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,r=e.clientY-o.y,{left:s,top:l}=t.getBoundingClientRect();return n.x=i+s,n.y=r+l,n.matrixTransform(t.getScreenCTM().inverse())};function An(e,t,n){const o=e.slice();o[35]=t[n];const i=o[23](o[35].target.selector);return o[36]=i,o}function Sn(e,t,n){const o=e.slice();return o[39]=t[n],o}function Et(e){const t=e.slice(),n=t[39].target.selector;return t[42]=n,t}function Tn(e){let t=e[39].id,n,o,i=vn(e);return{c(){i.c(),n=se()},m(r,s){i.m(r,s),O(r,n,s),o=!0},p(r,s){s[0]&32768&&x(t,t=r[39].id)?(le(),N(i,1,1,X),ae(),i=vn(r),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(r,s)},i(r){o||(P(i),o=!0)},o(r){N(i),o=!1},d(r){r&&I(n),i.d(r)}}}function ki(e){let t,n;return t=new Ai({props:{annotation:e[39],geom:e[42].geometry,style:e[1]}}),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const r={};i[0]&32768&&(r.annotation=o[39]),i[0]&32768&&(r.geom=o[42].geometry),i[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Ii(e){let t,n;return t=new vi({props:{annotation:e[39],geom:e[42].geometry,style:e[1]}}),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const r={};i[0]&32768&&(r.annotation=o[39]),i[0]&32768&&(r.geom=o[42].geometry),i[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Oi(e){var o;let t,n;return t=new yi({props:{annotation:e[39],geom:(o=e[42])==null?void 0:o.geometry,style:e[1]}}),{c(){te(t.$$.fragment)},m(i,r){$(t,i,r),n=!0},p(i,r){var l;const s={};r[0]&32768&&(s.annotation=i[39]),r[0]&32768&&(s.geom=(l=i[42])==null?void 0:l.geometry),r[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(P(t.$$.fragment,i),n=!0)},o(i){N(t.$$.fragment,i),n=!1},d(i){ee(t,i)}}}function vn(e){let t,n,o,i;const r=[Oi,Ii,ki],s=[];function l(a,c){var u,f,g;return((u=a[42])==null?void 0:u.type)===K.ELLIPSE?0:((f=a[42])==null?void 0:f.type)===K.RECTANGLE?1:((g=a[42])==null?void 0:g.type)===K.POLYGON?2:-1}return~(t=l(e))&&(n=s[t]=r[t](e)),{c(){n&&n.c(),o=se()},m(a,c){~t&&s[t].m(a,c),O(a,o,c),i=!0},p(a,c){let u=t;t=l(a),t===u?~t&&s[t].p(a,c):(n&&(le(),N(s[u],1,1,()=>{s[u]=null}),ae()),~t?(n=s[t],n?n.p(a,c):(n=s[t]=r[t](a),n.c()),P(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(P(n),i=!0)},o(a){N(n),i=!1},d(a){a&&I(o),~t&&s[t].d(a)}}}function Mn(e){let t=Ye(e[39])&&!e[8](e[39]),n,o,i=t&&Tn(Et(e));return{c(){i&&i.c(),n=se()},m(r,s){i&&i.m(r,s),O(r,n,s),o=!0},p(r,s){s[0]&33024&&(t=Ye(r[39])&&!r[8](r[39])),t?i?(i.p(Et(r),s),s[0]&33024&&P(i,1)):(i=Tn(Et(r)),i.c(),P(i,1),i.m(n.parentNode,n)):i&&(le(),N(i,1,1,()=>{i=null}),ae())},i(r){o||(P(i),o=!0)},o(r){N(i),o=!1},d(r){r&&I(n),i&&i.d(r)}}}function Ln(e){let t,n,o,i;const r=[Pi,Bi],s=[];function l(a,c){return a[7]?0:a[13]&&a[0]?1:-1}return~(t=l(e))&&(n=s[t]=r[t](e)),{c(){n&&n.c(),o=se()},m(a,c){~t&&s[t].m(a,c),O(a,o,c),i=!0},p(a,c){let u=t;t=l(a),t===u?~t&&s[t].p(a,c):(n&&(le(),N(s[u],1,1,()=>{s[u]=null}),ae()),~t?(n=s[t],n?n.p(a,c):(n=s[t]=r[t](a),n.c()),P(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(P(n),i=!0)},o(a){N(n),i=!1},d(a){a&&I(o),~t&&s[t].d(a)}}}function Bi(e){let t=e[2],n,o,i=kn(e);return{c(){i.c(),n=se()},m(r,s){i.m(r,s),O(r,n,s),o=!0},p(r,s){s[0]&4&&x(t,t=r[2])?(le(),N(i,1,1,X),ae(),i=kn(r),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(r,s)},i(r){o||(P(i),o=!0)},o(r){N(i),o=!1},d(r){r&&I(n),i.d(r)}}}function Pi(e){let t,n,o=Te(e[7]),i=[];for(let s=0;s<o.length;s+=1)i[s]=Bn(An(e,o,s));const r=s=>N(i[s],1,1,()=>{i[s]=null});return{c(){for(let s=0;s<i.length;s+=1)i[s].c();t=se()},m(s,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(s,l);O(s,t,l),n=!0},p(s,l){if(l[0]&10553506){o=Te(s[7]);let a;for(a=0;a<o.length;a+=1){const c=An(s,o,a);i[a]?(i[a].p(c,l),P(i[a],1)):(i[a]=Bn(c),i[a].c(),P(i[a],1),i[a].m(t.parentNode,t))}for(le(),a=o.length;a<i.length;a+=1)r(a);ae()}},i(s){if(!n){for(let l=0;l<o.length;l+=1)P(i[l]);n=!0}},o(s){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)N(i[l]);n=!1},d(s){s&&I(t),rt(i,s)}}}function kn(e){let t,n;return t=new gn({props:{target:e[5],tool:e[13],drawingMode:e[12],transform:e[11],viewportScale:e[16]}}),t.$on("create",e[20]),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const r={};i[0]&32&&(r.target=o[5]),i[0]&8192&&(r.tool=o[13]),i[0]&4096&&(r.drawingMode=o[12]),i[0]&2048&&(r.transform=o[11]),i[0]&65536&&(r.viewportScale=o[16]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function In(e){let t=e[35].id,n,o,i=On(e);return{c(){i.c(),n=se()},m(r,s){i.m(r,s),O(r,n,s),o=!0},p(r,s){s[0]&128&&x(t,t=r[35].id)?(le(),N(i,1,1,X),ae(),i=On(r),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(r,s)},i(r){o||(P(i),o=!0)},o(r){N(i),o=!1},d(r){r&&I(n),i.d(r)}}}function On(e){let t,n;return t=new hn({props:{target:e[5],editor:e[23](e[35].target.selector),annotation:e[35],style:e[1],transform:e[11],viewportScale:e[16]}}),t.$on("change",function(){q(e[21](e[35]))&&e[21](e[35]).apply(this,arguments)}),{c(){te(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){e=o;const r={};i[0]&32&&(r.target=e[5]),i[0]&128&&(r.editor=e[23](e[35].target.selector)),i[0]&128&&(r.annotation=e[35]),i[0]&2&&(r.style=e[1]),i[0]&2048&&(r.transform=e[11]),i[0]&65536&&(r.viewportScale=e[16]),t.$set(r)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Bn(e){let t,n,o=e[36]&&In(e);return{c(){o&&o.c(),t=se()},m(i,r){o&&o.m(i,r),O(i,t,r),n=!0},p(i,r){i[36]?o?(o.p(i,r),r[0]&128&&P(o,1)):(o=In(i),o.c(),P(o,1),o.m(t.parentNode,t)):o&&(le(),N(o,1,1,()=>{o=null}),ae())},i(i){n||(P(o),n=!0)},o(i){N(o),n=!1},d(i){i&&I(t),o&&o.d(i)}}}function Di(e){let t,n,o,i,r,s,l=Te(e[15].filter(e[30])),a=[];for(let f=0;f<l.length;f+=1)a[f]=Mn(Sn(e,l,f));const c=f=>N(a[f],1,1,()=>{a[f]=null});let u=e[5]&&Ln(e);return{c(){t=U("svg"),n=U("g");for(let f=0;f<a.length;f+=1)a[f].c();o=U("g"),u&&u.c(),d(o,"class","drawing"),d(t,"class","a9s-annotationlayer"),pe(t,"drawing",e[13]),pe(t,"hidden",!e[3]),pe(t,"hover",e[14])},m(f,g){O(f,t,g),fe(t,n);for(let h=0;h<a.length;h+=1)a[h]&&a[h].m(n,null);fe(t,o),u&&u.m(o,null),e[31](o),e[32](t),i=!0,r||(s=[W(t,"pointerup",function(){q(e[9])&&e[9].apply(this,arguments)}),W(t,"pointerdown",function(){q(e[10])&&e[10].apply(this,arguments)}),W(t,"pointermove",e[22])],r=!0)},p(f,g){if(e=f,g[0]&33026){l=Te(e[15].filter(e[30]));let h;for(h=0;h<l.length;h+=1){const m=Sn(e,l,h);a[h]?(a[h].p(m,g),P(a[h],1)):(a[h]=Mn(m),a[h].c(),P(a[h],1),a[h].m(n,null))}for(le(),h=l.length;h<a.length;h+=1)c(h);ae()}e[5]?u?(u.p(e,g),g[0]&32&&P(u,1)):(u=Ln(e),u.c(),P(u,1),u.m(o,null)):u&&(le(),N(u,1,1,()=>{u=null}),ae()),(!i||g[0]&8192)&&pe(t,"drawing",e[13]),(!i||g[0]&8)&&pe(t,"hidden",!e[3]),(!i||g[0]&16384)&&pe(t,"hover",e[14])},i(f){if(!i){for(let g=0;g<l.length;g+=1)P(a[g]);P(u),i=!0}},o(f){a=a.filter(Boolean);for(let g=0;g<a.length;g+=1)N(a[g]);N(u),i=!1},d(f){f&&I(t),rt(a,f),u&&u.d(),e[31](null),e[32](null),r=!1,ce(s)}}}function Yi(e,t,n){let o,i,r,s,l,a,c,u,f,g,h,m=X,y=()=>(m(),m=It(E,k=>n(16,h=k)),E);e.$$.on_destroy.push(()=>m());let{drawingEnabled:v}=t,{image:p}=t,{preferredDrawingMode:w}=t,{state:_}=t,{style:b=void 0}=t,{toolName:Y=_t()[0]}=t,{user:G}=t,{visible:j=!0}=t,z,D,E;Pe(()=>y(n(6,E=sn(p,D))));const{hover:A,selection:S,store:T}=_;it(e,A,k=>n(14,u=k)),it(e,S,k=>n(29,f=k)),it(e,T,k=>n(15,g=k));let V,C;const Z=k=>{V&&T.unobserve(V);const R=k.filter(({editable:F})=>F).map(({id:F})=>F);R.length>0?(n(7,C=R.map(F=>T.getAnnotation(F)).filter(F=>F&&Ye(F))),V=F=>{const{updated:ie}=F.changes;n(7,C=ie==null?void 0:ie.map(B=>B.newValue))},T.observe(V,{annotations:R})):n(7,C=void 0)},_e=k=>{const R=Ht(),F={id:R,bodies:[],target:{annotation:R,selector:k.detail,creator:G,created:new Date}};T.addAnnotation(F),S.setSelected(F.id)},ue=k=>R=>{var M;const{target:F}=k,ie=10*60*1e3,B=((M=F.creator)==null?void 0:M.id)!==G.id||!F.created||new Date().getTime()-F.created.getTime()>ie;T.updateTarget({...F,selector:R.detail,created:B?F.created:new Date,updated:B?new Date:void 0,updatedBy:B?G:void 0})},Ue=k=>{const{x:R,y:F}=bt(k,D),ie=T.getAt(R,F);ie?u!==ie.id&&A.set(ie.id):A.set(void 0)},de=k=>fn(k),Ve=k=>Ye(k);function he(k){ze[k?"unshift":"push"](()=>{z=k,n(5,z)})}function Ge(k){ze[k?"unshift":"push"](()=>{D=k,n(4,D)})}return e.$$set=k=>{"drawingEnabled"in k&&n(0,v=k.drawingEnabled),"image"in k&&n(24,p=k.image),"preferredDrawingMode"in k&&n(25,w=k.preferredDrawingMode),"state"in k&&n(26,_=k.state),"style"in k&&n(1,b=k.style),"toolName"in k&&n(2,Y=k.toolName),"user"in k&&n(27,G=k.user),"visible"in k&&n(3,j=k.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(13,{tool:o,opts:i}=wt(Y)||{tool:void 0,opts:void 0},o,(n(28,i),n(2,Y))),e.$$.dirty[0]&301989888&&n(12,r=(i==null?void 0:i.drawingMode)||w),e.$$.dirty[0]&16&&n(11,s=bn(D)),e.$$.dirty[0]&16&&n(10,{onPointerDown:l,onPointerUp:a}=En(D,T),l,(n(9,a),n(4,D))),e.$$.dirty[0]&536870912&&n(8,c=k=>f.selected.find(R=>R.id===k.id&&R.editable)),e.$$.dirty[0]&536870912&&Z(f.selected)},[v,b,Y,j,D,z,E,C,c,a,l,s,r,o,u,g,h,A,S,T,_e,ue,Ue,de,p,w,_,G,i,f,Ve,he,Ge]}class Pn extends oe{constructor(t){super(),ne(this,t,Yi,Di,x,{drawingEnabled:0,image:24,preferredDrawingMode:25,state:26,style:1,toolName:2,user:27,visible:3},null,[-1,-1])}}function Dn(e,t,n=0,o=e.length-1,i=Ri){for(;o>n;){if(o-n>600){const a=o-n+1,c=t-n+1,u=Math.log(a),f=.5*Math.exp(2*u/3),g=.5*Math.sqrt(u*f*(a-f)/a)*(c-a/2<0?-1:1),h=Math.max(n,Math.floor(t-c*f/a+g)),m=Math.min(o,Math.floor(t+(a-c)*f/a+g));Dn(e,t,h,m,i)}const r=e[t];let s=n,l=o;for(Ce(e,n,t),i(e[o],r)>0&&Ce(e,n,o);s<l;){for(Ce(e,s,l),s++,l--;i(e[s],r)<0;)s++;for(;i(e[l],r)>0;)l--}i(e[n],r)===0?Ce(e,n,l):(l++,Ce(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function Ce(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Ri(e,t){return e<t?-1:e>t?1:0}class Ci{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(!$e(t,n))return o;const i=this.toBBox,r=[];for(;n;){for(let s=0;s<n.children.length;s++){const l=n.children[s],a=n.leaf?i(l):l;$e(t,a)&&(n.leaf?o.push(l):St(t,a)?this._all(l,o):r.push(l))}n=r.pop()}return o}collides(t){let n=this.data;if(!$e(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const r=n.children[i],s=n.leaf?this.toBBox(r):r;if($e(t,s)){if(n.leaf||St(t,s))return!0;o.push(r)}}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=Ie([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),r=[],s=[];let l,a,c;for(;o||r.length;){if(o||(o=r.pop(),a=r[r.length-1],l=s.pop(),c=!0),o.leaf){const u=Xi(t,o.children,n);if(u!==-1)return o.children.splice(u,1),r.push(o),this._condense(r),this}!c&&!o.leaf&&St(o,i)?(r.push(o),s.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],c=!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 r=o-n+1;let s=this._maxEntries,l;if(r<=s)return l=Ie(t.slice(n,o+1)),ke(l,this.toBBox),l;i||(i=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,i-1))),l=Ie([]),l.leaf=!1,l.height=i;const a=Math.ceil(r/s),c=a*Math.ceil(Math.sqrt(s));Yn(t,n,o,c,this.compareMinX);for(let u=n;u<=o;u+=c){const f=Math.min(u+c-1,o);Yn(t,u,f,a,this.compareMinY);for(let g=u;g<=f;g+=a){const h=Math.min(g+a-1,f);l.children.push(this._build(t,g,h,i-1))}}return ke(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let r=1/0,s=1/0,l;for(let a=0;a<n.children.length;a++){const c=n.children[a],u=At(c),f=Vi(t,c)-u;f<s?(s=f,r=u<r?u:r,l=c):f===s&&u<r&&(r=u,l=c)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),r=[],s=this._chooseSubtree(i,this.data,n,r);for(s.children.push(t),Ne(s,i);n>=0&&r[n].children.length>this._maxEntries;)this._split(r,n),n--;this._adjustParentBBoxes(i,r,n)}_split(t,n){const o=t[n],i=o.children.length,r=this._minEntries;this._chooseSplitAxis(o,r,i);const s=this._chooseSplitIndex(o,r,i),l=Ie(o.children.splice(s,o.children.length-s));l.height=o.height,l.leaf=o.leaf,ke(o,this.toBBox),ke(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=Ie([t,n]),this.data.height=t.height+1,this.data.leaf=!1,ke(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,r=1/0,s=1/0;for(let l=n;l<=o-n;l++){const a=Xe(t,0,l,this.toBBox),c=Xe(t,l,o,this.toBBox),u=Gi(a,c),f=At(a)+At(c);u<r?(r=u,i=l,s=f<s?f:s):u===r&&f<s&&(s=f,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Ni,r=t.leaf?this.compareMinY:Ui,s=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,r);s<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const r=this.toBBox,s=Xe(t,0,n,r),l=Xe(t,o-n,o,r);let a=xe(s)+xe(l);for(let c=n;c<o-n;c++){const u=t.children[c];Ne(s,t.leaf?r(u):u),a+=xe(s)}for(let c=o-n-1;c>=n;c--){const u=t.children[c];Ne(l,t.leaf?r(u):u),a+=xe(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)Ne(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():ke(t[n],this.toBBox)}}function Xi(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 ke(e,t){Xe(e,0,e.children.length,t,e)}function Xe(e,t,n,o,i){i||(i=Ie(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let r=t;r<n;r++){const s=e.children[r];Ne(i,e.leaf?o(s):s)}return i}function Ne(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 Ni(e,t){return e.minX-t.minX}function Ui(e,t){return e.minY-t.minY}function At(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function xe(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Vi(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 Gi(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),r=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,r-o)}function St(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function $e(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ie(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Yn(e,t,n,o,i){const r=[t,n];for(;r.length;){if(n=r.pop(),t=r.pop(),n-t<=o)continue;const s=t+Math.ceil((n-t)/o/2)*o;Dn(e,s,t,n,i),r.push(t,s,s,n)}}const ji=()=>{const e=new Ci,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!Re(f))return;const{minX:g,minY:h,maxX:m,maxY:y}=f.selector.geometry.bounds,v={minX:g,minY:h,maxX:m,maxY:y,target:f};e.insert(v),t.set(f.annotation,v)},r=f=>{if(!Re(f))return;const g=t.get(f.annotation);g&&e.remove(g),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,g)=>{const m=e.search({minX:f,minY:g,maxX:f,maxY:g}).map(y=>y.target).filter(y=>y.selector.type===K.RECTANGLE||Ct(y.selector,f,g));if(m.length>0)return m.sort((y,v)=>We(y.selector)-We(v.selector)),m[0]},getIntersecting:(f,g,h,m)=>e.search({minX:f,minY:g,maxX:f+h,maxY:g+m}).map(y=>y.target),insert:i,remove:r,set:(f,g=!0)=>{g&&o();const h=f.reduce((m,y)=>{if(Re(y)){const{minX:v,minY:p,maxX:w,maxY:_}=y.selector.geometry.bounds;return[...m,{minX:v,minY:p,maxX:w,maxY:_,target:y}]}else return m},[]);h.forEach(m=>t.set(m.target.annotation,m)),e.load(h)},size:()=>e.all().length,update:(f,g)=>{r(f),i(g)}}},Rn=e=>{const t=Mo(),n=ji(),o=ho(t,e.userSelectAction),i=uo(t),r=Bo();return t.observe(({changes:a})=>{n.set((a.created||[]).map(c=>c.target),!1),(a.deleted||[]).forEach(c=>n.remove(c.target)),(a.updated||[]).forEach(({oldValue:c,newValue:u})=>n.update(c.target,u.target))}),{store:{...t,getAt:(a,c)=>{const u=n.getAt(a,c);return u?t.getAnnotation(u.annotation):void 0},getIntersecting:(a,c,u,f)=>n.getIntersecting(a,c,u,f).map(g=>t.getAnnotation(g.annotation))},selection:o,hover:i,viewport:r}},Cn=e=>{const t=Rn(e);return{...t,store:Lo(t.store)}},Xn=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 r=1;r<10;r++){const s=Math.round(r*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(s,l,1,1).data,c=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=c}return o/81},Nn=e=>{const t=Xn(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},Tt=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Nn(e):n),Un=(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}),vt=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Vn=(e,t)=>{const n=t||document,o=s=>{const l=s;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},i=s=>{const l=s;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},r=()=>{vt?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return vt?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:r}},zi=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=Un(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Kt.EDIT,theme:"light"}),i=Cn(o),{selection:r,store:s}=i,l=Oo(s),a=Po(i,l,o.adapter,o.autoSave),c=document.createElement("DIV");c.style.position="relative",c.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(c,n),c.appendChild(n);const u=Vn(l);let f=Vo();Tt(n,c,o.theme);const g=new Pn({target:c,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});g.$on("click",D=>{const{originalEvent:E,annotation:A}=D.detail;A?r.userSelect(A.id,E):r.isEmpty()||r.clear()});const h=Yo(i,l,o.adapter),m=()=>{g.$destroy(),c.parentNode.insertBefore(n,c),c.parentNode.removeChild(c),u.destroy(),l.destroy()},y=()=>f,v=(D,E,A)=>wn(D,E,A),p=(D,E)=>un(D,E),w=D=>{if(!wt(D))throw`No drawing tool named ${D}`;g.$set({toolName:D})},_=D=>g.$set({drawingEnabled:D}),b=D=>{console.warn("Filter not implemented yet")},Y=D=>g.$set({style:D}),G=D=>Tt(n,c,D),j=D=>{f=D,g.$set({user:D})},z=D=>g.$set({visible:D});return{...h,destroy:m,getUser:y,listDrawingTools:_t,on:a.on,off:a.off,registerDrawingTool:v,registerShapeEditor:p,setDrawingEnabled:_,setDrawingTool:w,setFilter:b,setStyle:Y,setTheme:G,setUser:j,setVisible:z,element:c,state:i}};L.Editor=mt,L.EditorMount=hn,L.Handle=Le,L.IdentityTransform=Mi,L.PolygonEditor=rn,L.RectangleEditor=an,L.RectangleUtil=Xt,L.RubberbandRectangle=pn,L.SVGAnnotationLayer=Pn,L.ShapeType=K,L.ToolMount=gn,L.W3CImageFormat=Fo,L.addEventListeners=En,L.boundsFromPoints=De,L.computeArea=We,L.createImageAnnotator=zi,L.createImageAnnotatorState=Rn,L.createSVGTransform=bn,L.createSvelteImageAnnotatorState=Cn,L.detectTheme=Nn,L.distance=Qe,L.enableResponsive=sn,L.fillDefaults=Un,L.getEditor=fn,L.getSVGPoint=bt,L.getTool=wt,L.initKeyboardCommands=Vn,L.intersects=Ct,L.isImageAnnotation=Ye,L.isImageAnnotationTarget=Re,L.isMac=vt,L.isTouch=ln,L.listDrawingTools=_t,L.parseFragmentSelector=Nt,L.parseSVGSelector=jt,L.parseW3CImageAnnotation=xt,L.registerEditor=un,L.registerShapeUtil=He,L.registerTool=wn,L.sampleBrightness=Xn,L.serializeFragmentSelector=Ut,L.serializeSVGSelector=zt,L.serializeW3CImageAnnotation=$t,L.setTheme=Tt,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=annotorious.js.map