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