UNPKG

@recogito/annotorious

Version:

A JavaScript image annotation library

17 lines 590 kB
(function(ee,Fe){typeof exports=="object"&&typeof module<"u"?Fe(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],Fe):(ee=typeof globalThis<"u"?globalThis:ee||self,Fe(ee.AnnotoriousOSD={},ee.OpenSeadragon))})(this,function(ee,Fe){"use strict";var ls=Object.prototype.hasOwnProperty;function $e(r,t){var e,n;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((n=r.length)===t.length)for(;n--&&$e(r[n],t[n]););return n===-1}if(!e||typeof r=="object"){n=0;for(e in r)if(ls.call(r,e)&&++n&&!ls.call(t,e)||!(e in t)||!$e(r[e],t[e]))return!1;return Object.keys(t).length===n}}return r!==r&&t!==t}function qt(){}function of(r,t){for(const e in t)r[e]=t[e];return r}function fs(r){return r()}function cs(){return Object.create(null)}function Be(r){r.forEach(fs)}function Lt(r){return typeof r=="function"}function Kt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function af(r){return Object.keys(r).length===0}function sf(r,...t){if(r==null)return qt;const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function ds(r,t,e){r.$$.on_destroy.push(sf(t,e))}function ps(r,t,e,n){if(r){const i=vs(r,t,e,n);return r[0](i)}}function vs(r,t,e,n){return r[1]&&n?of(e.ctx.slice(),r[1](n(t))):e.ctx}function _s(r,t,e,n){if(r[2]&&n){const i=r[2](n(e));if(t.dirty===void 0)return i;if(typeof i=="object"){const o=[],a=Math.max(t.dirty.length,i.length);for(let s=0;s<a;s+=1)o[s]=t.dirty[s]|i[s];return o}return t.dirty|i}return t.dirty}function ms(r,t,e,n,i,o){if(i){const a=vs(t,e,n,o);r.p(a,i)}}function ys(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let n=0;n<e;n++)t[n]=-1;return t}return-1}const gs=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function qe(r,t){r.appendChild(t)}function Z(r,t,e){r.insertBefore(t,e||null)}function q(r){r.parentNode&&r.parentNode.removeChild(r)}function ji(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function lt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Yi(r){return document.createTextNode(r)}function oe(){return Yi(" ")}function Ne(){return Yi("")}function Yt(r,t,e,n){return r.addEventListener(t,e,n),()=>r.removeEventListener(t,e,n)}function S(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function hf(r){return Array.from(r.childNodes)}function uf(r,t){t=""+t,r.data!==t&&(r.data=t)}function bs(r,t,e){r.classList[e?"add":"remove"](t)}function lf(r,t,{bubbles:e=!1,cancelable:n=!1}={}){const i=document.createEvent("CustomEvent");return i.initCustomEvent(r,e,n,t),i}function Dn(r,t){return new r(t)}let Kr;function Zr(r){Kr=r}function Vi(){if(!Kr)throw new Error("Function called outside component initialization");return Kr}function Fn(r){Vi().$$.on_mount.push(r)}function ff(r){Vi().$$.on_destroy.push(r)}function Bn(){const r=Vi();return(t,e,{cancelable:n=!1}={})=>{const i=r.$$.callbacks[t];if(i){const o=lf(t,e,{cancelable:n});return i.slice().forEach(a=>{a.call(r,o)}),!o.defaultPrevented}return!0}}function mr(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(n=>n.call(this,t))}const yr=[],Jr=[];let gr=[];const xs=[],cf=Promise.resolve();let zi=!1;function df(){zi||(zi=!0,cf.then(Ts))}function Wi(r){gr.push(r)}const $i=new Set;let br=0;function Ts(){if(br!==0)return;const r=Kr;do{try{for(;br<yr.length;){const t=yr[br];br++,Zr(t),pf(t.$$)}}catch(t){throw yr.length=0,br=0,t}for(Zr(null),yr.length=0,br=0;Jr.length;)Jr.pop()();for(let t=0;t<gr.length;t+=1){const e=gr[t];$i.has(e)||($i.add(e),e())}gr.length=0}while(yr.length);for(;xs.length;)xs.pop()();zi=!1,$i.clear(),Zr(r)}function pf(r){if(r.fragment!==null){r.update(),Be(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Wi)}}function vf(r){const t=[],e=[];gr.forEach(n=>r.indexOf(n)===-1?t.push(n):e.push(n)),e.forEach(n=>n()),gr=t}const Nn=new Set;let Ke;function Le(){Ke={r:0,c:[],p:Ke}}function Ue(){Ke.r||Be(Ke.c),Ke=Ke.p}function ct(r,t){r&&r.i&&(Nn.delete(r),r.i(t))}function gt(r,t,e,n){if(r&&r.o){if(Nn.has(r))return;Nn.add(r),Ke.c.push(()=>{Nn.delete(r),n&&(e&&r.d(1),n())}),r.o(t)}else n&&n()}function re(r){r&&r.c()}function Zt(r,t,e,n){const{fragment:i,after_update:o}=r.$$;i&&i.m(t,e),n||Wi(()=>{const a=r.$$.on_mount.map(fs).filter(Lt);r.$$.on_destroy?r.$$.on_destroy.push(...a):Be(a),r.$$.on_mount=[]}),o.forEach(Wi)}function Jt(r,t){const e=r.$$;e.fragment!==null&&(vf(e.after_update),Be(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function _f(r,t){r.$$.dirty[0]===-1&&(yr.push(r),df(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ne(r,t,e,n,i,o,a,s=[-1]){const h=Kr;Zr(r);const u=r.$$={fragment:null,ctx:[],props:o,update:qt,not_equal:i,bound:cs(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(h?h.$$.context:[])),callbacks:cs(),dirty:s,skip_bound:!1,root:t.target||h.$$.root};a&&a(u.root);let l=!1;if(u.ctx=e?e(r,t.props||{},(f,c,...d)=>{const p=d.length?d[0]:c;return u.ctx&&i(u.ctx[f],u.ctx[f]=p)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](p),l&&_f(r,f)),c}):[],u.update(),l=!0,Be(u.before_update),u.fragment=n?n(u.ctx):!1,t.target){if(t.hydrate){const f=hf(t.target);u.fragment&&u.fragment.l(f),f.forEach(q)}else u.fragment&&u.fragment.c();t.intro&&ct(r.$$.fragment),Zt(r,t.target,t.anchor,t.customElement),Ts()}Zr(h)}class ie{$destroy(){Jt(this,1),this.$destroy=qt}$on(t,e){if(!Lt(e))return qt;const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const i=n.indexOf(e);i!==-1&&n.splice(i,1)}}$set(t){this.$$set&&!af(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const xr=[];function qi(r,t=qt){let e;const n=new Set;function i(s){if(Kt(r,s)&&(r=s,e)){const h=!xr.length;for(const u of n)u[1](),xr.push(u,r);if(h){for(let u=0;u<xr.length;u+=2)xr[u][0](xr[u+1]);xr.length=0}}}function o(s){i(s(r))}function a(s,h=qt){const u=[s,h];return n.add(u),n.size===1&&(e=t(i)||qt),s(r),()=>{n.delete(u),n.size===0&&e&&(e(),e=null)}}return{set:i,update:o,subscribe:a}}const mf=r=>{const{subscribe:t,set:e}=qi(null);let n=null;return t(i=>n=i),r.observe(({changes:i})=>{if(n){i.deleted.some(s=>s.id===n)&&e(null);const a=i.updated.find(({oldValue:s})=>s.id===n);a&&e(a.newValue.id)}}),{get current(){return n},subscribe:t,set:e}};var Ki=(r=>(r.EDIT="EDIT",r.HIGHLIGHT="HIGHLIGHT",r.NONE="NONE",r))(Ki||{});const Zi={selected:[]},yf=(r,t="EDIT")=>{const{subscribe:e,set:n}=qi(Zi);let i=Zi;e(f=>i=f);const o=()=>n(Zi),a=()=>{var f;return((f=i.selected)==null?void 0:f.length)===0},s=f=>{if(i.selected.length===0)return!1;const c=typeof f=="string"?f:f.id;return i.selected.some(d=>d.id===c)},h=(f,c)=>{const d=r.getAnnotation(f);if(d){const p=gf(d,t);n(p==="EDIT"?{selected:[{id:f,editable:!0}],pointerEvent:c}:p==="HIGHLIGHT"?{selected:[{id:f}],pointerEvent:c}:{selected:[],pointerEvent:c})}else console.warn("Invalid selection: "+f)},u=(f,c=!0)=>{const d=Array.isArray(f)?f:[f],p=d.map(v=>r.getAnnotation(v)).filter(v=>v);n({selected:p.map(({id:v})=>({id:v,editable:c}))}),p.length!==d.length&&console.warn("Invalid selection",f)},l=f=>{if(i.selected.length===0)return!1;const{selected:c}=i;c.filter(({id:p})=>f.includes(p)).length>0&&n({selected:c.filter(({id:p})=>!f.includes(p))})};return r.observe(({changes:f})=>l(f.deleted.map(c=>c.id))),{clear:o,clickSelect:h,get selected(){return i?[...i.selected]:null},get pointerEvent(){return i?i.pointerEvent:null},isEmpty:a,isSelected:s,setSelected:u,subscribe:e}},gf=(r,t)=>typeof t=="function"?t(r)||"EDIT":t||"EDIT";let Ln;const bf=new Uint8Array(16);function xf(){if(!Ln&&(Ln=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ln))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ln(bf)}const Ut=[];for(let r=0;r<256;++r)Ut.push((r+256).toString(16).slice(1));function Tf(r,t=0){return Ut[r[t+0]]+Ut[r[t+1]]+Ut[r[t+2]]+Ut[r[t+3]]+"-"+Ut[r[t+4]]+Ut[r[t+5]]+"-"+Ut[r[t+6]]+Ut[r[t+7]]+"-"+Ut[r[t+8]]+Ut[r[t+9]]+"-"+Ut[r[t+10]]+Ut[r[t+11]]+Ut[r[t+12]]+Ut[r[t+13]]+Ut[r[t+14]]+Ut[r[t+15]]}const Es={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ws(r,t,e){if(Es.randomUUID&&!t&&!r)return Es.randomUUID();r=r||{};const n=r.random||(r.rng||xf)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){e=e||0;for(let i=0;i<16;++i)t[e+i]=n[i];return t}return Tf(n)}const Ef=(r,t,e,n)=>({id:ws(),annotation:r.id,created:e||new Date,creator:n,...t}),wf=(r,t)=>{const e=new Set(r.bodies.map(n=>n.id));return t.bodies.filter(n=>!e.has(n.id))},Sf=(r,t)=>{const e=new Set(t.bodies.map(n=>n.id));return r.bodies.filter(n=>!e.has(n.id))},Af=(r,t)=>t.bodies.map(e=>{const n=r.bodies.find(i=>i.id===e.id);return{newBody:e,oldBody:n&&!$e(n,e)?n:void 0}}).filter(({oldBody:e})=>e),Pf=(r,t)=>!$e(r.target,t.target),Of=(r,t)=>({oldValue:r,newValue:t,bodiesCreated:wf(r,t),bodiesDeleted:Sf(r,t),bodiesUpdated:Af(r,t),targetUpdated:Pf(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0});var It=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r))(It||{});const Rf=(r,t)=>{var o,a;const{changes:e,origin:n}=t;if(!(!r.options.origin||r.options.origin===n))return!1;if(r.options.ignore){const{ignore:s}=r.options,h=l=>(l==null?void 0:l.length)>0;if(!(h(e.created)||h(e.deleted))){const l=(o=e.updated)==null?void 0:o.some(c=>h(c.bodiesCreated)||h(c.bodiesDeleted)||h(c.bodiesUpdated)),f=(a=e.updated)==null?void 0:a.some(c=>c.targetUpdated);if(s==="BODY_ONLY"&&l&&!f||s==="TARGET_ONLY"&&f&&!l)return!1}}if(r.options.annotations){const s=new Set([...e.created.map(u=>u.id),...e.deleted.map(u=>u.id),...e.updated.map(({oldValue:u})=>u.id)]);return!!(Array.isArray(r.options.annotations)?r.options.annotations:[r.options.annotations]).find(u=>s.has(u))}else return!0},If=r=>r.id!==void 0,Cf=()=>{const r=new Map,t=new Map,e=[],n=(b,w={})=>e.push({onChange:b,options:w}),i=b=>{const w=e.findIndex(A=>A.onChange==b);w>-1&&e.splice(w,1)},o=(b,w)=>{const A={origin:b,changes:{created:w.created||[],updated:w.updated||[],deleted:w.deleted||[]},state:[...r.values()]};e.forEach(R=>{Rf(R,A)&&R.onChange(A)})},a=(b,w=It.LOCAL)=>{if(r.get(b.id))throw Error(`Cannot add annotation ${b.id} - exists already`);r.set(b.id,b),b.bodies.forEach(R=>t.set(R.id,b.id)),o(w,{created:[b]})},s=(b,w=It.LOCAL,A=It.LOCAL)=>{const R=If(w)?A:w,C=typeof b=="string"?w:b,M=typeof b=="string"?b:b.id,H=r.get(M);if(H){const U=Of(H,C);M===C.id?r.set(M,C):(r.delete(M),r.set(C.id,C)),H.bodies.forEach(B=>t.delete(B.id)),C.bodies.forEach(B=>t.set(B.id,C.id)),o(R,{updated:[U]})}else throw Error(`Cannot update annotation ${M} - does not exist`)},h=(b,w=It.LOCAL)=>{const A=r.get(b.annotation);if(A){const R={...A,bodies:[...A.bodies,b]};r.set(A.id,R),t.set(b.id,R.id),o(w,{updated:[{oldValue:A,newValue:R,bodiesCreated:[b]}]})}else console.warn(`Attempt to add body to missing annotation: ${b.annotation}`)},u=()=>[...r.values()],l=(b=It.LOCAL)=>{const w=[...r.values()];r.clear(),t.clear(),o(b,{deleted:w})},f=(b,w=!0,A=It.LOCAL)=>{if(w){const R=[...r.values()];r.clear(),t.clear(),b.forEach(C=>{r.set(C.id,C),C.bodies.forEach(M=>t.set(M.id,C.id))}),o(A,{created:b,deleted:R})}else{const R=b.reduce((C,M)=>{const H=r.get(M.id);return H?[...C,H]:C},[]);if(R.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${R.map(C=>C.id).join(", ")}`);b.forEach(C=>{r.set(C.id,C),C.bodies.forEach(M=>t.set(M.id,C.id))}),o(A,{created:b})}},c=b=>{const w=typeof b=="string"?b:b.id,A=r.get(w);if(A)return r.delete(w),A.bodies.forEach(R=>t.delete(R.id)),A;console.warn(`Attempt to delete missing annotation: ${w}`)},d=(b,w=It.LOCAL)=>{const A=c(b);A&&o(w,{deleted:[A]})},p=(b,w=It.LOCAL)=>{const A=b.reduce((R,C)=>{const M=c(C);return M?[...R,M]:R},[]);A.length>0&&o(w,{deleted:A})},v=(b,w=It.LOCAL)=>{const A=r.get(b.annotation);if(A){const R=A.bodies.find(C=>C.id===b.id);if(R){t.delete(R.id);const C={...A,bodies:A.bodies.filter(H=>H.id!==b.id)};r.set(A.id,C),o(w,{updated:[{oldValue:A,newValue:C,bodiesDeleted:[R]}]})}else console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${b.annotation}`)},_=b=>{const w=r.get(b);return w?{...w}:void 0},m=b=>{const w=t.get(b);if(w){const R=_(w).bodies.find(C=>C.id===b);if(R)return R;console.error(`Store integrity error: body ${b} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${b}`)},y=(b,w)=>{if(b.annotation!==w.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const A=r.get(b.annotation);if(A){const R=A.bodies.find(M=>M.id===b.id),C={...A,bodies:A.bodies.map(M=>M.id===R.id?w:M)};return r.set(A.id,C),R.id!==w.id&&(t.delete(R.id),t.set(w.id,C.id)),{oldValue:A,newValue:C,bodiesUpdated:[{oldBody:R,newBody:w}]}}else console.warn(`Attempt to add body to missing annotation ${b.annotation}`)},g=(b,w,A=It.LOCAL)=>{const R=y(b,w);o(A,{updated:[R]})},x=(b,w=It.LOCAL)=>{const A=b.map(R=>y({id:R.id,annotation:R.annotation},R));o(w,{updated:A})},T=b=>{const w=r.get(b.annotation);if(w){const A={...w,target:{...w.target,...b}};return r.set(w.id,A),{oldValue:w,newValue:A,targetUpdated:{oldTarget:w.target,newTarget:b}}}else console.warn(`Attempt to update target on missing annotation: ${b.annotation}`)};return{addAnnotation:a,addBody:h,all:u,bulkAddAnnotation:f,bulkDeleteAnnotation:p,bulkUpdateBodies:x,bulkUpdateTargets:(b,w=It.LOCAL)=>{const A=b.map(T).filter(R=>R);A.length>0&&o(w,{updated:A})},clear:l,deleteAnnotation:d,deleteBody:v,getAnnotation:_,getBody:m,observe:n,unobserve:i,updateAnnotation:s,updateBody:g,updateTarget:(b,w=It.LOCAL)=>{const A=T(b);A&&o(w,{updated:[A]})}}},Mf=()=>{const{subscribe:r,set:t}=qi([]);return{subscribe:r,set:t}},Df=(r,t,e,n,i,o)=>{const a=new Map;let s=[],h,u;const l=(p,v)=>{a.has(p)?a.get(p).push(v):a.set(p,[v])},f=(p,v)=>{const _=a.get(p);_&&_.indexOf(v)>0&&_.splice(_.indexOf(v),1)},c=(p,v,_)=>{a.has(p)&&setTimeout(()=>{a.get(p).forEach(m=>{if(i){const y=Array.isArray(v)?v.map(x=>i.serialize(x)):i.serialize(v),g=_?_ instanceof PointerEvent?_:i.serialize(_):void 0;m(y,g)}else m(v,_)})},1)},d=()=>{const{selected:p}=t,v=p.map(({id:_})=>r.getAnnotation(_));v.forEach(_=>{const m=s.find(y=>y.id===_.id);(!m||!$e(m,_))&&c("updateAnnotation",_,m)}),s=s.map(_=>{const m=v.find(({id:y})=>y===_.id);return m||_})};return t.subscribe(({selected:p})=>{if(!(s.length===0&&p.length===0)){if(s.length===0&&p.length>0)s=p.map(({id:v})=>r.getAnnotation(v));else if(s.length>0&&p.length===0)s.forEach(v=>{const _=r.getAnnotation(v.id);_&&!$e(_,v)&&c("updateAnnotation",_,v)}),s=[];else{const v=new Set(s.map(y=>y.id)),_=new Set(p.map(({id:y})=>y));s.filter(y=>!_.has(y.id)).forEach(y=>{const g=r.getAnnotation(y.id);g&&!$e(g,y)&&c("updateAnnotation",g,y)}),s=[...s.filter(y=>_.has(y.id)),...p.filter(({id:y})=>!v.has(y)).map(({id:y})=>r.getAnnotation(y))]}c("selectionChanged",s)}}),e.subscribe(p=>{!h&&p?c("mouseEnterAnnotation",r.getAnnotation(p)):h&&!p?c("mouseLeaveAnnotation",r.getAnnotation(h)):h&&p&&(c("mouseLeaveAnnotation",r.getAnnotation(h)),c("mouseEnterAnnotation",r.getAnnotation(p))),h=p}),n==null||n.subscribe(p=>c("viewportIntersect",p.map(r.getAnnotation))),r.observe(p=>{o&&(u&&clearTimeout(u),u=setTimeout(d,1e3));const{created:v,deleted:_}=p.changes;v.forEach(y=>c("createAnnotation",y)),_.forEach(y=>c("deleteAnnotation",y)),p.changes.updated.filter(y=>[...y.bodiesCreated||[],...y.bodiesDeleted||[],...y.bodiesUpdated||[]].length>0).forEach(({oldValue:y,newValue:g})=>{const x=s.find(T=>T.id===y.id)||y;s=s.map(T=>T.id===y.id?g:T),c("updateAnnotation",g,x)})},{origin:It.LOCAL}),r.observe(p=>{if(s){const v=new Set(s.map(m=>m.id)),_=p.changes.updated.filter(({newValue:m})=>v.has(m.id)).map(({newValue:m})=>m);_.length>0&&(s=s.map(m=>{const y=_.find(g=>g.id===m.id);return y||m}))}},{origin:It.REMOTE}),{on:l,off:f,emit:c}},Ff=r=>t=>t.reduce((e,n)=>{const{parsed:i,error:o}=r.parse(n);return o?{parsed:e.parsed,failed:[...e.failed,n]}:{parsed:[...e.parsed,i],failed:e.failed}},{parsed:[],failed:[]}),Bf=(r,t)=>{const e=l=>{if(t){const{parsed:f,error:c}=t.parse(l);f?r.addAnnotation(f,It.REMOTE):console.error(c)}else r.addAnnotation(l,It.REMOTE)},n=()=>r.clear(),i=l=>{const f=r.getAnnotation(l);return t&&f?t.serialize(f):f},o=()=>t?r.all().map(t.serialize):r.all(),a=l=>fetch(l).then(f=>f.json()).then(f=>(h(f),f)),s=l=>{if(typeof l=="string"){const f=r.getAnnotation(l);return r.deleteAnnotation(l),t?t.serialize(f):f}else{const f=t?t.parse(l).parsed:l;return r.deleteAnnotation(f),l}},h=l=>{if(t){const{parsed:f,failed:c}=Ff(t)(l);c.length>0&&console.warn(`Discarded ${c.length} invalid annotations`,c),r.bulkAddAnnotation(f,!0,It.REMOTE)}else r.bulkAddAnnotation(l,!0,It.REMOTE)};return{addAnnotation:e,clearAnnotations:n,getAnnotationById:i,getAnnotations:o,loadAnnotations:a,removeAnnotation:s,setAnnotations:h,updateAnnotation:l=>{if(t){const f=t.parse(l).parsed,c=t.serialize(r.getAnnotation(f.id));return r.updateAnnotation(f),c}else{const f=r.getAnnotation(l.id);return r.updateAnnotation(l),f}}}};let Nf=r=>crypto.getRandomValues(new Uint8Array(r)),Lf=(r,t,e)=>{let n=(2<<Math.log(r.length-1)/Math.LN2)-1,i=-~(1.6*n*t/r.length);return(o=t)=>{let a="";for(;;){let s=e(i),h=i;for(;h--;)if(a+=r[s[h]&n]||"",a.length===o)return a}}},Uf=(r,t=21)=>Lf(r,t,Nf),Gf=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((t,e)=>(e&=63,e<36?t+=e.toString(36):e<62?t+=(e-26).toString(36).toUpperCase():e>62?t+="-":t+="_",t),"");const kf=()=>({isGuest:!0,id:Uf("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Hf=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Xf=()=>{const r=[...Hf];return{assignRandomColor:()=>{const n=Math.floor(Math.random()*r.length),i=r[n];return r.splice(n,1),i},releaseColor:n=>r.push(n)}};Gf();var Wt=(r=>(r.ELLIPSE="ELLIPSE",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(Wt||{});const Ji={},Qi=(r,t)=>Ji[r]=t,Ss=r=>Ji[r.type].area(r),jf=(r,t,e)=>Ji[r.type].intersects(r,t,e),to=r=>{let t=1/0,e=1/0,n=-1/0,i=-1/0;return r.forEach(([o,a])=>{t=Math.min(t,o),e=Math.min(e,a),n=Math.max(n,o),i=Math.max(i,a)}),{minX:t,minY:e,maxX:n,maxY:i}},Yf={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:n,cy:i,rx:o,ry:a}=r.geometry,s=0,h=Math.cos(s),u=Math.sin(s),l=t-n,f=e-i,c=h*l+u*f,d=u*l-h*f;return c*c/(o*o)+d*d/(a*a)<=1}};Qi(Wt.ELLIPSE,Yf);const Vf={area:r=>{const{points:t}=r.geometry;let e=0,n=t.length-1;for(let i=0;i<t.length;i++)e+=(t[n][0]+t[i][0])*(t[n][1]-t[i][1]),n=i;return Math.abs(.5*e)},intersects:(r,t,e)=>{const{points:n}=r.geometry;let i=!1;for(let o=0,a=n.length-1;o<n.length;a=o++){const s=n[o][0],h=n[o][1],u=n[a][0],l=n[a][1];h>e!=l>e&&t<(u-s)*(e-h)/(l-h)+s&&(i=!i)}return i}};Qi(Wt.POLYGON,Vf);const zf={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};Qi(Wt.RECTANGLE,zf);function As(r,t,e){const n=r.slice();return n[11]=t[e],n[13]=e,n}function Ps(r){let t,e,n,i,o;return{c(){t=lt("rect"),S(t,"class","a9s-corner-handle"),S(t,"x",e=r[11][0]-r[3]/2),S(t,"y",n=r[11][1]-r[3]/2),S(t,"height",r[3]),S(t,"width",r[3])},m(a,s){Z(a,t,s),i||(o=Yt(t,"pointerdown",function(){Lt(r[10](V(r[13])))&&r[10](V(r[13])).apply(this,arguments)}),i=!0)},p(a,s){r=a,s&24&&e!==(e=r[11][0]-r[3]/2)&&S(t,"x",e),s&24&&n!==(n=r[11][1]-r[3]/2)&&S(t,"y",n),s&8&&S(t,"height",r[3]),s&8&&S(t,"width",r[3])},d(a){a&&q(t),i=!1,o()}}}function Wf(r){let t,e,n,i,o,a,s,h,u,l,f=r[4].points,c=[];for(let d=0;d<f.length;d+=1)c[d]=Ps(As(r,f,d));return{c(){t=lt("polygon"),i=oe(),o=lt("polygon"),s=oe();for(let d=0;d<c.length;d+=1)c[d].c();h=Ne(),S(t,"class","a9s-outer"),S(t,"style",e=r[1]?"display:none;":void 0),S(t,"points",n=r[4].points.map(Os).join(" ")),S(o,"class","a9s-inner a9s-shape-handle"),S(o,"style",r[1]),S(o,"points",a=r[4].points.map(Rs).join(" "))},m(d,p){Z(d,t,p),Z(d,i,p),Z(d,o,p),Z(d,s,p);for(let v=0;v<c.length;v+=1)c[v]&&c[v].m(d,p);Z(d,h,p),u||(l=[Yt(t,"pointerdown",function(){Lt(r[10](V.SHAPE))&&r[10](V.SHAPE).apply(this,arguments)}),Yt(o,"pointerdown",function(){Lt(r[10](V.SHAPE))&&r[10](V.SHAPE).apply(this,arguments)})],u=!0)},p(d,p){if(r=d,p&2&&e!==(e=r[1]?"display:none;":void 0)&&S(t,"style",e),p&16&&n!==(n=r[4].points.map(Os).join(" "))&&S(t,"points",n),p&2&&S(o,"style",r[1]),p&16&&a!==(a=r[4].points.map(Rs).join(" "))&&S(o,"points",a),p&1048){f=r[4].points;let v;for(v=0;v<f.length;v+=1){const _=As(r,f,v);c[v]?c[v].p(_,p):(c[v]=Ps(_),c[v].c(),c[v].m(h.parentNode,h))}for(;v<c.length;v+=1)c[v].d(1);c.length=f.length}},d(d){d&&q(t),d&&q(i),d&&q(o),d&&q(s),ji(c,d),d&&q(h),u=!1,Be(l)}}}function $f(r){let t,e;return t=new Ms({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[Wf,({grab:n})=>({10:n}),({grab:n})=>n?1024:0]},$$scope:{ctx:r}}}),t.$on("change",r[7]),t.$on("grab",r[8]),t.$on("release",r[9]),{c(){re(t.$$.fragment)},m(n,i){Zt(t,n,i),e=!0},p(n,[i]){const o={};i&1&&(o.shape=n[0]),i&4&&(o.transform=n[2]),i&17434&&(o.$$scope={dirty:i,ctx:n}),t.$set(o)},i(n){e||(ct(t.$$.fragment,n),e=!0)},o(n){gt(t.$$.fragment,n),e=!1},d(n){Jt(t,n)}}}const Os=r=>r.join(","),Rs=r=>r.join(",");function qf(r,t,e){let n,i,{shape:o}=t,{computedStyle:a=void 0}=t,{transform:s}=t,{viewportScale:h=1}=t;const u=(d,p,v)=>{let _;p===V.SHAPE?_=d.geometry.points.map(([y,g])=>[y+v[0],g+v[1]]):_=d.geometry.points.map(([y,g],x)=>p===V(x)?[y+v[0],g+v[1]]:[y,g]);const m=to(_);return{...d,geometry:{points:_,bounds:m}}};function l(d){mr.call(this,r,d)}function f(d){mr.call(this,r,d)}function c(d){mr.call(this,r,d)}return r.$$set=d=>{"shape"in d&&e(0,o=d.shape),"computedStyle"in d&&e(1,a=d.computedStyle),"transform"in d&&e(2,s=d.transform),"viewportScale"in d&&e(6,h=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&1&&e(4,n=o.geometry),r.$$.dirty&64&&e(3,i=10/h)},[o,a,s,i,n,u,h,l,f,c]}class Kf extends ie{constructor(t){super(),ne(this,t,qf,$f,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}function Zf(r){let t,e,n,i,o,a,s,h,u,l,f,c,d,p,v,_,m,y,g,x,T,E,P,b,w,A,R,C,M,H,U,B,$,K,Q,N,F,k,tt,rt,vt,Y,ut,mt,Et,W,it,at,ft,nt;return{c(){t=lt("rect"),s=oe(),h=lt("rect"),d=oe(),p=lt("rect"),y=oe(),g=lt("rect"),P=oe(),b=lt("rect"),C=oe(),M=lt("rect"),$=oe(),K=lt("rect"),F=oe(),k=lt("rect"),vt=oe(),Y=lt("rect"),Et=oe(),W=lt("rect"),S(t,"class","a9s-outer"),S(t,"style",e=r[1]?"display:none;":void 0),S(t,"x",n=r[4].x),S(t,"y",i=r[4].y),S(t,"width",o=r[4].w),S(t,"height",a=r[4].h),S(h,"class","a9s-inner a9s-shape-handle"),S(h,"style",r[1]),S(h,"x",u=r[4].x),S(h,"y",l=r[4].y),S(h,"width",f=r[4].w),S(h,"height",c=r[4].h),S(p,"class","a9s-edge-handle a9s-edge-handle-top"),S(p,"x",v=r[4].x),S(p,"y",_=r[4].y),S(p,"height",1),S(p,"width",m=r[4].w),S(g,"class","a9s-edge-handle a9s-edge-handle-right"),S(g,"x",x=r[4].x+r[4].w),S(g,"y",T=r[4].y),S(g,"height",E=r[4].h),S(g,"width",1),S(b,"class","a9s-edge-handle a9s-edge-handle-bottom"),S(b,"x",w=r[4].x),S(b,"y",A=r[4].y+r[4].h),S(b,"height",1),S(b,"width",R=r[4].w),S(M,"class","a9s-edge-handle a9s-edge-handle-left"),S(M,"x",H=r[4].x),S(M,"y",U=r[4].y),S(M,"height",B=r[4].h),S(M,"width",1),S(K,"class","a9s-corner-handle a9s-corner-handle-topleft"),S(K,"x",Q=r[4].x-r[3]/2),S(K,"y",N=r[4].y-r[3]/2),S(K,"height",r[3]),S(K,"width",r[3]),S(k,"class","a9s-corner-handle a9s-corner-handle-topright"),S(k,"x",tt=r[4].x+r[4].w-r[3]/2),S(k,"y",rt=r[4].y-r[3]/2),S(k,"height",r[3]),S(k,"width",r[3]),S(Y,"class","a9s-corner-handle a9s-corner-handle-bottomright"),S(Y,"x",ut=r[4].x+r[4].w-r[3]/2),S(Y,"y",mt=r[4].y+r[4].h-r[3]/2),S(Y,"height",r[3]),S(Y,"width",r[3]),S(W,"class","a9s-corner-handle a9s-corner-handle-bottomleft"),S(W,"x",it=r[4].x-r[3]/2),S(W,"y",at=r[4].y+r[4].h-r[3]/2),S(W,"height",r[3]),S(W,"width",r[3])},m(D,O){Z(D,t,O),Z(D,s,O),Z(D,h,O),Z(D,d,O),Z(D,p,O),Z(D,y,O),Z(D,g,O),Z(D,P,O),Z(D,b,O),Z(D,C,O),Z(D,M,O),Z(D,$,O),Z(D,K,O),Z(D,F,O),Z(D,k,O),Z(D,vt,O),Z(D,Y,O),Z(D,Et,O),Z(D,W,O),ft||(nt=[Yt(t,"pointerdown",function(){Lt(r[10](V.SHAPE))&&r[10](V.SHAPE).apply(this,arguments)}),Yt(h,"pointerdown",function(){Lt(r[10](V.SHAPE))&&r[10](V.SHAPE).apply(this,arguments)}),Yt(p,"pointerdown",function(){Lt(r[10](V.TOP))&&r[10](V.TOP).apply(this,arguments)}),Yt(g,"pointerdown",function(){Lt(r[10](V.RIGHT))&&r[10](V.RIGHT).apply(this,arguments)}),Yt(b,"pointerdown",function(){Lt(r[10](V.BOTTOM))&&r[10](V.BOTTOM).apply(this,arguments)}),Yt(M,"pointerdown",function(){Lt(r[10](V.LEFT))&&r[10](V.LEFT).apply(this,arguments)}),Yt(K,"pointerdown",function(){Lt(r[10](V.TOP_LEFT))&&r[10](V.TOP_LEFT).apply(this,arguments)}),Yt(k,"pointerdown",function(){Lt(r[10](V.TOP_RIGHT))&&r[10](V.TOP_RIGHT).apply(this,arguments)}),Yt(Y,"pointerdown",function(){Lt(r[10](V.BOTTOM_RIGHT))&&r[10](V.BOTTOM_RIGHT).apply(this,arguments)}),Yt(W,"pointerdown",function(){Lt(r[10](V.BOTTOM_LEFT))&&r[10](V.BOTTOM_LEFT).apply(this,arguments)})],ft=!0)},p(D,O){r=D,O&2&&e!==(e=r[1]?"display:none;":void 0)&&S(t,"style",e),O&16&&n!==(n=r[4].x)&&S(t,"x",n),O&16&&i!==(i=r[4].y)&&S(t,"y",i),O&16&&o!==(o=r[4].w)&&S(t,"width",o),O&16&&a!==(a=r[4].h)&&S(t,"height",a),O&2&&S(h,"style",r[1]),O&16&&u!==(u=r[4].x)&&S(h,"x",u),O&16&&l!==(l=r[4].y)&&S(h,"y",l),O&16&&f!==(f=r[4].w)&&S(h,"width",f),O&16&&c!==(c=r[4].h)&&S(h,"height",c),O&16&&v!==(v=r[4].x)&&S(p,"x",v),O&16&&_!==(_=r[4].y)&&S(p,"y",_),O&16&&m!==(m=r[4].w)&&S(p,"width",m),O&16&&x!==(x=r[4].x+r[4].w)&&S(g,"x",x),O&16&&T!==(T=r[4].y)&&S(g,"y",T),O&16&&E!==(E=r[4].h)&&S(g,"height",E),O&16&&w!==(w=r[4].x)&&S(b,"x",w),O&16&&A!==(A=r[4].y+r[4].h)&&S(b,"y",A),O&16&&R!==(R=r[4].w)&&S(b,"width",R),O&16&&H!==(H=r[4].x)&&S(M,"x",H),O&16&&U!==(U=r[4].y)&&S(M,"y",U),O&16&&B!==(B=r[4].h)&&S(M,"height",B),O&24&&Q!==(Q=r[4].x-r[3]/2)&&S(K,"x",Q),O&24&&N!==(N=r[4].y-r[3]/2)&&S(K,"y",N),O&8&&S(K,"height",r[3]),O&8&&S(K,"width",r[3]),O&24&&tt!==(tt=r[4].x+r[4].w-r[3]/2)&&S(k,"x",tt),O&24&&rt!==(rt=r[4].y-r[3]/2)&&S(k,"y",rt),O&8&&S(k,"height",r[3]),O&8&&S(k,"width",r[3]),O&24&&ut!==(ut=r[4].x+r[4].w-r[3]/2)&&S(Y,"x",ut),O&24&&mt!==(mt=r[4].y+r[4].h-r[3]/2)&&S(Y,"y",mt),O&8&&S(Y,"height",r[3]),O&8&&S(Y,"width",r[3]),O&24&&it!==(it=r[4].x-r[3]/2)&&S(W,"x",it),O&24&&at!==(at=r[4].y+r[4].h-r[3]/2)&&S(W,"y",at),O&8&&S(W,"height",r[3]),O&8&&S(W,"width",r[3])},d(D){D&&q(t),D&&q(s),D&&q(h),D&&q(d),D&&q(p),D&&q(y),D&&q(g),D&&q(P),D&&q(b),D&&q(C),D&&q(M),D&&q($),D&&q(K),D&&q(F),D&&q(k),D&&q(vt),D&&q(Y),D&&q(Et),D&&q(W),ft=!1,Be(nt)}}}function Jf(r){let t,e;return t=new Ms({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[Zf,({grab:n})=>({10:n}),({grab:n})=>n?1024:0]},$$scope:{ctx:r}}}),t.$on("grab",r[7]),t.$on("change",r[8]),t.$on("release",r[9]),{c(){re(t.$$.fragment)},m(n,i){Zt(t,n,i),e=!0},p(n,[i]){const o={};i&1&&(o.shape=n[0]),i&4&&(o.transform=n[2]),i&3098&&(o.$$scope={dirty:i,ctx:n}),t.$set(o)},i(n){e||(ct(t.$$.fragment,n),e=!0)},o(n){gt(t.$$.fragment,n),e=!1},d(n){Jt(t,n)}}}function Qf(r,t,e){let n,i,{shape:o}=t,{computedStyle:a=void 0}=t,{transform:s}=t,{viewportScale:h=1}=t;const u=(d,p,v)=>{const _=d.geometry.bounds;let[m,y]=[_.minX,_.minY],[g,x]=[_.maxX,_.maxY];const[T,E]=v;if(p===V.SHAPE)m+=T,g+=T,y+=E,x+=E;else{switch(p){case V.TOP:case V.TOP_LEFT:case V.TOP_RIGHT:{y+=E;break}case V.BOTTOM:case V.BOTTOM_LEFT:case V.BOTTOM_RIGHT:{x+=E;break}}switch(p){case V.LEFT:case V.TOP_LEFT:case V.BOTTOM_LEFT:{m+=T;break}case V.RIGHT:case V.TOP_RIGHT:case V.BOTTOM_RIGHT:{g+=T;break}}}const P=Math.min(m,g),b=Math.min(y,x),w=Math.abs(g-m),A=Math.abs(x-y);return{...d,geometry:{x:P,y:b,w,h:A,bounds:{minX:P,minY:b,maxX:P+w,maxY:b+A}}}};function l(d){mr.call(this,r,d)}function f(d){mr.call(this,r,d)}function c(d){mr.call(this,r,d)}return r.$$set=d=>{"shape"in d&&e(0,o=d.shape),"computedStyle"in d&&e(1,a=d.computedStyle),"transform"in d&&e(2,s=d.transform),"viewportScale"in d&&e(6,h=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&1&&e(4,n=o.geometry),r.$$.dirty&64&&e(3,i=10/h)},[o,a,s,i,n,u,h,l,f,c]}class tc extends ie{constructor(t){super(),ne(this,t,Qf,Jf,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}const ec=new Map([[Wt.RECTANGLE,tc],[Wt.POLYGON,Kf]]),Is=r=>ec.get(r.type),V=r=>`HANDLE-${r}`;V.SHAPE="SHAPE",V.TOP="TOP",V.RIGHT="RIGHT",V.BOTTOM="BOTTOM",V.LEFT="LEFT",V.TOP_LEFT="TOP_LEFT",V.TOP_RIGHT="TOP_RIGHT",V.BOTTOM_RIGHT="BOTTOM_RIGHT",V.BOTTOM_LEFT="BOTTOM_LEFT";const rc=r=>({}),Cs=r=>({grab:r[0]});function nc(r){let t,e,n,i;const o=r[7].default,a=ps(o,r,r[6],Cs);return{c(){t=lt("g"),a&&a.c(),S(t,"class","a9s-annotation selected")},m(s,h){Z(s,t,h),a&&a.m(t,null),e=!0,n||(i=[Yt(t,"pointerup",r[2]),Yt(t,"pointermove",r[1])],n=!0)},p(s,[h]){a&&a.p&&(!e||h&64)&&ms(a,o,s,s[6],e?_s(o,s[6],h,rc):ys(s[6]),Cs)},i(s){e||(ct(a,s),e=!0)},o(s){gt(a,s),e=!1},d(s){s&&q(t),a&&a.d(s),n=!1,Be(i)}}}function ic(r,t,e){let{$$slots:n={},$$scope:i}=t;const o=Bn();let{shape:a}=t,{editor:s}=t,{transform:h}=t,u=null,l,f=null;const c=v=>_=>{u=v,l=h.elementToImage(_.offsetX,_.offsetY),f=a,_.target.setPointerCapture(_.pointerId),o("grab")},d=v=>{if(u){const[_,m]=h.elementToImage(v.offsetX,v.offsetY),y=[_-l[0],m-l[1]];e(3,a=s(f,u,y)),o("change",a)}},p=v=>{v.target.releasePointerCapture(v.pointerId),u=null,f=a,o("release")};return r.$$set=v=>{"shape"in v&&e(3,a=v.shape),"editor"in v&&e(4,s=v.editor),"transform"in v&&e(5,h=v.transform),"$$scope"in v&&e(6,i=v.$$scope)},[c,d,p,a,s,h,i,n]}class Ms extends ie{constructor(t){super(),ne(this,t,ic,nc,Kt,{shape:3,editor:4,transform:5})}}function Ds(r){let t,e;return{c(){t=lt("rect"),e=lt("rect"),S(t,"class","a9s-outer"),S(t,"x",r[2]),S(t,"y",r[3]),S(t,"width",r[4]),S(t,"height",r[5]),S(e,"class","a9s-inner"),S(e,"x",r[2]),S(e,"y",r[3]),S(e,"width",r[4]),S(e,"height",r[5])},m(n,i){Z(n,t,i),Z(n,e,i)},p(n,i){i&4&&S(t,"x",n[2]),i&8&&S(t,"y",n[3]),i&16&&S(t,"width",n[4]),i&32&&S(t,"height",n[5]),i&4&&S(e,"x",n[2]),i&8&&S(e,"y",n[3]),i&16&&S(e,"width",n[4]),i&32&&S(e,"height",n[5])},d(n){n&&q(t),n&&q(e)}}}function oc(r){let t,e=r[1]&&Ds(r);return{c(){t=lt("g"),e&&e.c(),S(t,"class","a9s-annotation a9s-rubberband")},m(n,i){Z(n,t,i),e&&e.m(t,null),r[7](t)},p(n,[i]){n[1]?e?e.p(n,i):(e=Ds(n),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:qt,o:qt,d(n){n&&q(t),e&&e.d(),r[7](null)}}}function ac(r,t,e){const n=Bn();let{transform:i}=t,o,a,s,h,u,l,f;const c=_=>{e(1,a=i.elementToImage(_.offsetX,_.offsetY)),s=a,e(2,h=a[0]),e(3,u=a[1]),e(4,l=1),e(5,f=1)},d=_=>{a&&(s=i.elementToImage(_.offsetX,_.offsetY),e(2,h=Math.min(s[0],a[0])),e(3,u=Math.min(s[1],a[1])),e(4,l=Math.abs(s[0]-a[0])),e(5,f=Math.abs(s[1]-a[1])))},p=()=>{if(l*f>15){const _={type:Wt.RECTANGLE,geometry:{bounds:{minX:h,minY:u,maxX:h+l,maxY:u+f},x:h,y:u,w:l,h:f}};n("create",_)}e(1,a=null),s=null};Fn(()=>{const _=o.closest("svg");return _.addEventListener("pointerdown",c),_.addEventListener("pointermove",d),_.addEventListener("pointerup",p),()=>{_.removeEventListener("pointerdown",c),_.removeEventListener("pointermove",d),_.removeEventListener("pointerup",p)}});function v(_){Jr[_?"unshift":"push"](()=>{o=_,e(0,o)})}return r.$$set=_=>{"transform"in _&&e(6,i=_.transform)},[o,a,h,u,l,f,i,v]}class sc extends ie{constructor(t){super(),ne(this,t,ac,oc,Kt,{transform:6})}}const Fs=(r,t)=>{const e=Math.abs(t[0]-r[0]),n=Math.abs(t[1]-r[1]);return Math.sqrt(Math.pow(e,2)+Math.pow(n,2))};function eo(r){const t=r.slice(),e=(t[3]?t[1]:[...t[1],t[2]]).map(n=>n.join(",")).join(" ");return t[13]=e,t}function Bs(r){let t,e,n,i,o,a=r[3]&&Ns(r);return{c(){t=lt("polygon"),n=lt("polygon"),a&&a.c(),o=Ne(),S(t,"class","a9s-outer"),S(t,"points",e=r[13]),S(n,"class","a9s-inner"),S(n,"points",i=r[13])},m(s,h){Z(s,t,h),Z(s,n,h),a&&a.m(s,h),Z(s,o,h)},p(s,h){h&14&&e!==(e=s[13])&&S(t,"points",e),h&14&&i!==(i=s[13])&&S(n,"points",i),s[3]?a?a.p(s,h):(a=Ns(s),a.c(),a.m(o.parentNode,o)):a&&(a.d(1),a=null)},d(s){s&&q(t),s&&q(n),a&&a.d(s),s&&q(o)}}}function Ns(r){let t,e,n;return{c(){t=lt("rect"),S(t,"class","a9s-corner-handle"),S(t,"x",e=r[1][0][0]-r[4]/2),S(t,"y",n=r[1][0][1]-r[4]/2),S(t,"height",r[4]),S(t,"width",r[4])},m(i,o){Z(i,t,o)},p(i,o){o&18&&e!==(e=i[1][0][0]-i[4]/2)&&S(t,"x",e),o&18&&n!==(n=i[1][0][1]-i[4]/2)&&S(t,"y",n),o&16&&S(t,"height",i[4]),o&16&&S(t,"width",i[4])},d(i){i&&q(t)}}}function hc(r){let t,e=r[2]&&Bs(eo(r));return{c(){t=lt("g"),e&&e.c(),S(t,"class","a9s-annotation a9s-rubberband")},m(n,i){Z(n,t,i),e&&e.m(t,null),r[7](t)},p(n,[i]){n[2]?e?e.p(eo(n),i):(e=Bs(eo(n)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:qt,o:qt,d(n){n&&q(t),e&&e.d(),r[7](null)}}}const uc=20;function lc(r,t,e){let n;const i=Bn();let{transform:o}=t,{viewportScale:a=1}=t,s,h=[],u=null,l=!1;const f=_=>{const m=o.elementToImage(_.offsetX,_.offsetY);h.length===0&&h.push(m),e(2,u=m)},c=_=>{if(h.length>0&&(e(2,u=o.elementToImage(_.offsetX,_.offsetY)),h.length>2)){const m=Fs(u,h[0])*a;e(3,l=m<uc)}},d=_=>{if(h.length===1&&Fs(h[0],u)<=4){e(1,h=[]),e(2,u=null);return}if(_.stopImmediatePropagation(),l){const m={type:Wt.POLYGON,geometry:{bounds:to(h),points:[...h]}};e(1,h=[]),e(2,u=null),i("create",m)}else h.push(u)},p=()=>{const _=[...h,u],m={type:Wt.POLYGON,geometry:{bounds:to(_),points:_}};e(1,h=[]),e(2,u=null),i("create",m)};Fn(()=>{const _=s.closest("svg");return _.addEventListener("pointerdown",f,!0),_.addEventListener("pointermove",c),_.addEventListener("pointerup",d,!0),_.addEventListener("dblclick",p,!0),()=>{_.removeEventListener("pointerdown",f,!0),_.removeEventListener("pointermove",c,!0),_.removeEventListener("pointerup",d,!0),_.removeEventListener("dblclick",p,!0)}});function v(_){Jr[_?"unshift":"push"](()=>{s=_,e(0,s)})}return r.$$set=_=>{"transform"in _&&e(5,o=_.transform),"viewportScale"in _&&e(6,a=_.viewportScale)},r.$$.update=()=>{r.$$.dirty&64&&e(4,n=10/a)},[s,h,u,l,n,o,a,v]}class fc extends ie{constructor(t){super(),ne(this,t,lc,hc,Kt,{transform:5,viewportScale:6})}}const Ls=new Map([["rectangle",sc],["polygon",fc]]),cc=()=>[...Ls.keys()],dc=r=>Ls.get(r);function pc(r,t,e,n,i){Us(r,t,e||0,n||r.length-1,i||vc)}function Us(r,t,e,n,i){for(;n>e;){if(n-e>600){var o=n-e+1,a=t-e+1,s=Math.log(o),h=.5*Math.exp(2*s/3),u=.5*Math.sqrt(s*h*(o-h)/o)*(a-o/2<0?-1:1),l=Math.max(e,Math.floor(t-a*h/o+u)),f=Math.min(n,Math.floor(t+(o-a)*h/o+u));Us(r,t,l,f,i)}var c=r[t],d=e,p=n;for(Qr(r,e,t),i(r[n],c)>0&&Qr(r,e,n);d<p;){for(Qr(r,d,p),d++,p--;i(r[d],c)<0;)d++;for(;i(r[p],c)>0;)p--}i(r[e],c)===0?Qr(r,e,p):(p++,Qr(r,p,n)),p<=t&&(e=p+1),t<=p&&(n=p-1)}}function Qr(r,t,e){var n=r[t];r[t]=r[e],r[e]=n}function vc(r,t){return r<t?-1:r>t?1:0}class _c{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 e=this.data;const n=[];if(!Gn(t,e))return n;const i=this.toBBox,o=[];for(;e;){for(let a=0;a<e.children.length;a++){const s=e.children[a],h=e.leaf?i(s):s;Gn(t,h)&&(e.leaf?n.push(s):no(t,h)?this._all(s,n):o.push(s))}e=o.pop()}return n}collides(t){let e=this.data;if(!Gn(t,e))return!1;const n=[];for(;e;){for(let i=0;i<e.children.length;i++){const o=e.children[i],a=e.leaf?this.toBBox(o):o;if(Gn(t,a)){if(e.leaf||no(t,a))return!0;n.push(o)}}e=n.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let n=0;n<t.length;n++)this.insert(t[n]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const n=this.data;this.data=e,e=n}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Er([]),this}remove(t,e){if(!t)return this;let n=this.data;const i=this.toBBox(t),o=[],a=[];let s,h,u;for(;n||o.length;){if(n||(n=o.pop(),h=o[o.length-1],s=a.pop(),u=!0),n.leaf){const l=mc(t,n.children,e);if(l!==-1)return n.children.splice(l,1),o.push(n),this._condense(o),this}!u&&!n.leaf&&no(n,i)?(o.push(n),a.push(s),s=0,h=n,n=n.children[0]):h?(s++,n=h.children[s],u=!1):n=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}_build(t,e,n,i){const o=n-e+1;let a=this._maxEntries,s;if(o<=a)return s=Er(t.slice(e,n+1)),Tr(s,this.toBBox),s;i||(i=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,i-1))),s=Er([]),s.leaf=!1,s.height=i;const h=Math.ceil(o/a),u=h*Math.ceil(Math.sqrt(a));Gs(t,e,n,u,this.compareMinX);for(let l=e;l<=n;l+=u){const f=Math.min(l+u-1,n);Gs(t,l,f,h,this.compareMinY);for(let c=l;c<=f;c+=h){const d=Math.min(c+h-1,f);s.children.push(this._build(t,c,d,i-1))}}return Tr(s,this.toBBox),s}_chooseSubtree(t,e,n,i){for(;i.push(e),!(e.leaf||i.length-1===n);){let o=1/0,a=1/0,s;for(let h=0;h<e.children.length;h++){const u=e.children[h],l=ro(u),f=bc(t,u)-l;f<a?(a=f,o=l<o?l:o,s=u):f===a&&l<o&&(o=l,s=u)}e=s||e.children[0]}return e}_insert(t,e,n){const i=n?t:this.toBBox(t),o=[],a=this._chooseSubtree(i,this.data,e,o);for(a.children.push(t),en(a,i);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(i,o,e)}_split(t,e){const n=t[e],i=n.children.length,o=this._minEntries;this._chooseSplitAxis(n,o,i);const a=this._chooseSplitIndex(n,o,i),s=Er(n.children.splice(a,n.children.length-a));s.height=n.height,s.leaf=n.leaf,Tr(n,this.toBBox),Tr(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(n,s)}_splitRoot(t,e){this.data=Er([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Tr(this.data,this.toBBox)}_chooseSplitIndex(t,e,n){let i,o=1/0,a=1/0;for(let s=e;s<=n-e;s++){const h=tn(t,0,s,this.toBBox),u=tn(t,s,n,this.toBBox),l=xc(h,u),f=ro(h)+ro(u);l<o?(o=l,i=s,a=f<a?f:a):l===o&&f<a&&(a=f,i=s)}return i||n-e}_chooseSplitAxis(t,e,n){const i=t.leaf?this.compareMinX:yc,o=t.leaf?this.compareMinY:gc,a=this._allDistMargin(t,e,n,i),s=this._allDistMargin(t,e,n,o);a<s&&t.children.sort(i)}_allDistMargin(t,e,n,i){t.children.sort(i);const o=this.toBBox,a=tn(t,0,e,o),s=tn(t,n-e,n,o);let h=Un(a)+Un(s);for(let u=e;u<n-e;u++){const l=t.children[u];en(a,t.leaf?o(l):l),h+=Un(a)}for(let u=n-e-1;u>=e;u--){const l=t.children[u];en(s,t.leaf?o(l):l),h+=Un(s)}return h}_adjustParentBBoxes(t,e,n){for(let i=n;i>=0;i--)en(e[i],t)}_condense(t){for(let e=t.length-1,n;e>=0;e--)t[e].children.length===0?e>0?(n=t[e-1].children,n.splice(n.indexOf(t[e]),1)):this.clear():Tr(t[e],this.toBBox)}}function mc(r,t,e){if(!e)return t.indexOf(r);for(let n=0;n<t.length;n++)if(e(r,t[n]))return n;return-1}function Tr(r,t){tn(r,0,r.children.length,t,r)}function tn(r,t,e,n,i){i||(i=Er(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let o=t;o<e;o++){const a=r.children[o];en(i,r.leaf?n(a):a)}return i}function en(r,t){return r.minX=Math.min(r.minX,t.minX),r.minY=Math.min(r.minY,t.minY),r.maxX=Math.max(r.maxX,t.maxX),r.maxY=Math.max(r.maxY,t.maxY),r}function yc(r,t){return r.minX-t.minX}function gc(r,t){return r.minY-t.minY}function ro(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Un(r){return r.maxX-r.minX+(r.maxY-r.minY)}function bc(r,t){return(Math.max(t.maxX,r.maxX)-Math.min(t.minX,r.minX))*(Math.max(t.maxY,r.maxY)-Math.min(t.minY,r.minY))}function xc(r,t){const e=Math.max(r.minX,t.minX),n=Math.max(r.minY,t.minY),i=Math.min(r.maxX,t.maxX),o=Math.min(r.maxY,t.maxY);return Math.max(0,i-e)*Math.max(0,o-n)}function no(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function Gn(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Er(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Gs(r,t,e,n,i){const o=[t,e];for(;o.length;){if(e=o.pop(),t=o.pop(),e-t<=n)continue;const a=t+Math.ceil((e-t)/n/2)*n;pc(r,a,t,e,i),o.push(t,a,a,e)}}const Tc=()=>{const r=new _c,t=new Map,e=()=>[...t.values()],n=()=>{r.clear(),t.clear()},i=f=>{const{minX:c,minY:d,maxX:p,maxY:v}=f.selector.geometry.bounds,_={minX:c,minY:d,maxX:p,maxY:v,target:f};r.insert(_),t.set(f.annotation,_)},o=f=>{const c=t.get(f.annotation);r.remove(c),t.delete(f.annotation)};return{all:e,clear:n,getAt:(f,c)=>{const p=r.search({minX:f,minY:c,maxX:f,maxY:c}).map(v=>v.target).filter(v=>v.selector.type===Wt.RECTANGLE||jf(v.selector,f,c));if(p.length>0)return p.sort((v,_)=>Ss(v.selector)-Ss(_.selector)),p[0]},getIntersecting:(f,c,d,p)=>r.search({minX:f,minY:c,maxX:f+d,maxY:c+p}).map(v=>v.target),insert:i,remove:o,set:(f,c=!0)=>{c&&n();const d=f.map(p=>{const{minX:v,minY:_,maxX:m,maxY:y}=p.selector.geometry.bounds;return{minX:v,minY:_,maxX:m,maxY:y,target:p}});d.forEach(p=>t.set(p.target.annotation,p)),r.load(d)},size:()=>r.all().length,update:(f,c)=>{o(f),i(c)}}},Ec=r=>{const t=Cf(),e=Tc(),n=yf(t,r.pointerSelectAction),i=mf(t),o=Mf();return t.observe(({changes:h})=>{e.set(h.created.map(u=>u.target),!1),h.deleted.forEach(u=>e.remove(u.target)),h.updated.forEach(({oldValue:u,newValue:l})=>e.update(u.target,l.target))}),{store:{...t,getAt:(h,u)=>{const l=e.getAt(h,u);return l?t.getAnnotation(l.annotation):void 0},getIntersecting:(h,u,l,f)=>e.getIntersecting(h,u,l,f).map(c=>t.getAnnotation(c.annotation))},selection:n,hover:i,viewport:o}},wc=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const i=r;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(i,0,0,i.width,i.height)}let n=0;for(let i=1;i<10;i++)for(let o=1;o<10;o++){const a=Math.round(o*t.width/10),s=Math.round(i*t.height/10),h=e.getImageData(a,s,1,1).data,u=(.299*h[0]+.587*h[1]+.114*h[2])/255;n+=u}return n/81},Sc=(r,t)=>{const e=wc(r),n=e>.6?"dark":"light";console.log(`[Annotorious] Image brightness: ${e.toFixed(1)}. Setting ${n} theme.`),t.setAttribute("data-theme",n)},Ac=r=>({...r,pointerSelectAction:r.pointerSelectAction||Ki.EDIT}),aT="",sT="",hT="";function Pc(r){var t=this.constructor;return this.then(function(e){return t.resolve(r()).then(function(){return e})},function(e){return t.resolve(r()).then(function(){return t.reject(e)})})}function Oc(r){var t=this;return new t(function(e,n){if(!(r&&typeof r.length<"u"))return n(new TypeError(typeof r+" "+r+" is not iterable(cannot read property Symbol(Symbol.iterator))"));var i=Array.prototype.slice.call(r);if(i.length===0)return e([]);var o=i.length;function a(h,u){if(u&&(typeof u=="object"||typeof u=="function")){var l=u.then;if(typeof l=="function"){l.call(u,function(f){a(h,f)},function(f){i[h]={status:"rejected",reason:f},--o===0&&e(i)});return}}i[h]={status:"fulfilled",value:u},--o===0&&e(i)}for(var s=0;s<i.length;s++)a(s,i[s])})}function ks(r,t){this.name="AggregateError",this.errors=r,this.message=t||""}ks.prototype=Error.prototype;function Rc(r){var t=this;return new t(function(e,n){if(!(r&&typeof r.length<"u"))return n(new TypeError("Promise.any accepts an array"));var i=Array.prototype.slice.call(r);if(i.length===0)return n();for(var o=[],a=0;a<i.length;a++)try{t.resolve(i[a]).then(e).catch(function(s){o.push(s),o.length===i.length&&n(new ks(o,"All promises were rejected"))})}catch(s){n(s)}})}var Ic=setTimeout;function Hs(r){return!!(r&&typeof r.length<"u")}function Cc(){}function Mc(r,t){return function(){r.apply(t,arguments)}}function St(r){if(!(this instanceof St))throw new TypeError("Promises must be constructed via new");if(typeof r!="function")throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],js(r,this)}function Xs(r,t){for(;r._state===3;)r=r._value;if(r._state===0){r._deferreds.push(t);return}r._handled=!0,St._immediateFn(function(){var e=r._state===1?t.onFulfilled:t.onRejected;if(e===null){(r._state===1?io:rn)(t.promise,r._value);return}var n;try{n=e(r._value)}catch(i){rn(t.promise,i);return}io(t.promise,n)})}function io(r,t){try{if(t===r)throw new TypeError("A promise cannot be resolved with itself.");if(t&&(typeof t=="object"||typeof t=="function")){var e=t.then;if(t instanceof St){r._state=3,r._value=t,oo(r);return}else if(typeof e=="function"){js(Mc(e,t),r);return}}r._state=1,r._value=t,oo(r)}catch(n){rn(r,n)}}function rn(r,t){r._state=2,r._value=t,oo(r)}function oo(r){r._state===2&&r._deferreds.length===0&&St._immediateFn(function(){r._handled||St._unhandledRejectionFn(r._value)});for(var t=0,e=r._deferreds.length;t<e;t++)Xs(r,r._deferreds[t]);r._deferreds=null}function Dc(r,t,e){this.onFulfilled=typeof r=="function"?r:null,this.onRejected=typeof t=="function"?t:null,this.promise=e}function js(r,t){var e=!1;try{r(function(n){e||(e=!0,io(t,n))},function(n){e||(e=!0,rn(t,n))})}catch(n){if(e)return;e=!0,rn(t,n)}}St.prototype.catch=function(r){return this.then(null,r)},St.prototype.then=function(r,t){var e=new this.constructor(Cc);return Xs(this,new Dc(r,t,e)),e},St.prototype.finally=Pc,St.all=function(r){return new St(function(t,e){if(!Hs(r))return e(new TypeError("Promise.all accepts an array"));var n=Array.prototype.slice.call(r);if(n.length===0)return t([]);var i=n.length;function o(s,h){try{if(h&&(typeof h=="object"||typeof h=="function")){var u=h.then;if(typeof u=="function"){u.call(h,function(l){o(s,l)},e);return}}n[s]=h,--i===0&&t(n)}catch(l){e(l)}}for(var a=0;a<n.length;a++)o(a,n[a])})},St.any=Rc,St.allSettled=Oc,St.resolve=function(r){return r&&typeof r=="object"&&r.constructor===St?r:new St(function(t){t(r)})},St.reject=function(r){return new St(function(t,e){e(r)})},St.race=function(r){return new St(function(t,e){if(!Hs(r))return e(new TypeError("Promise.race accepts an array"));for(var n=0,i=r.length;n<i;n++)St.resolve(r[n]).then(t,e)})},St._immediateFn=typeof setImmediate=="function"&&function(r){setImmediate(r)}||function(r){Ic(r,0)},St._unhandledRejectionFn=function(t){typeof console<"u"&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};var ao=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function so(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function Fc(r){if(r.__esModule)return r;var t=r.default;if(typeof t=="function"){var e=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(r).forEach(function(n){var i=Object.getOwnPropertyDescriptor(r,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return r[n]}})}),e}/* object-assign (c) Sindre Sorhus @license MIT */var Ys=Object.getOwnPropertySymbols,Bc=Object.prototype.hasOwnProperty,Nc=Object.prototype.propertyIsEnumerable;function Lc(r){if(r==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(r)}function Uc(){try{if(!Object.assign)return!1;var r=new String("abc");if(r[5]="de",Object.getOwnPropertyNames(r)[0]==="5")return!1;for(var t={},e=0;e<10;e++)t["_"+String.fromCharCode(e)]=e;var n=Object.getOwnPropertyNames(t).map(function(o){return t[o]});if(n.join("")!=="0123456789")return!1;var i={};return"abcdefghijklmnopqrst".split("").forEach(function(o){i[o]=o}),Object.keys(Object.assign({},i)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}var Gc=Uc()?Object.assign:function(r,t){for(var e,n=Lc(r),i,o=1;o<arguments.length;o++){e=Object(arguments[o]);for(var a in e)Bc.call(e,a)&&(n[a]=e[a]);if(Ys){i=Ys(e);for(var s=0;s<i.length;s++)Nc.call(e,i[s])&&(n[i[s]]=e[i[s]])}}return n};const kc=so(Gc);/*! * @pixi/polyfill - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * * @pixi/polyfill is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license */typeof globalThis>"u"&&(typeof self<"u"?self.globalThis=self:typeof global<"u"&&(global.globalThis=global)),globalThis.Promise||(globalThis.Promise=St),Object.assign||(Object.assign=kc);var Hc=16;if(Date.now&&Date.prototype.getTime||(Date.now=function(){return new Date().getTime()}),!(globalThis.performance&&globalThis.performance.now)){var Xc=Date.now();globalThis.performance||(globalThis.performance={}),globalThis.performance.now=function(){return Date.now()-Xc}}for(var ho=Date.now(),Vs=["ms","moz","webkit","o"],uo=0;uo<Vs.length&&!globalThis.requestAnimationFrame;++uo){var lo=Vs[uo];globalThis.requestAnimationFrame=globalThis[lo+"RequestAnimationFrame"],globalThis.cancelAnimationFrame=globalThis[lo+"CancelAnimationFrame"]||globalThis[lo+"CancelRequestAnimationFrame"]}globalThis.requestAnimationFrame||(globalThis.requestAnimationFrame=function(r){if(typeof r!="function")throw new TypeError(r+"is not a function");var t=Date.now(),e=Hc+ho-t;return e<0&&(e=0),ho=t,globalThis.self.setTimeout(function(){ho=Date.now(),r(performance.now())},e)}),globalThis.cancelAnimationFrame||(globalThis.cancelAnimationFrame=function(r){return clearTimeout(r)}),Math.sign||(Math.sign=function(t){return t=Number(t),t===0||isNaN(t)?t:t>0?1:-1}),Number.isInteger||(Number.isInteger=function(t){return typeof t=="number"&&isFinite(t)&&Math.floor(t)===t}),globalThis.ArrayBuffer||(globalThis.ArrayBuffer=Array),globalThis.Float32Array||(globalThis.Float32Array=Array),globalThis.Uint32Array||(globalThis.Uint32Array=Array),globalThis.Uint16Array||(globalThis.Uint16Array=Array),globalThis.Uint8Array||(globalThis.Uint8Array=Array),globalThis.Int32Array||(globalThis.Int32Array=Array);/*! * @pixi/constants - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * * @pixi/constants is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license */var Se;(function(r){r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2"})(Se||(Se={}));var nn;(function(r){r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS"})(nn||(nn={}));var kn;(function(r){r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL"})(kn||(kn={}));var j;(function(r){r[r.NORMAL=0]="NORMAL",r[r.ADD=1]="