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