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