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