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