@recogito/annotorious
Version:
A JavaScript image annotation library
1,814 lines • 848 kB
JavaScript
import vi from "openseadragon";
var ds = Object.prototype.hasOwnProperty;
function nr(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-- && nr(r[n], t[n]); )
;
return n === -1;
}
if (!e || typeof r == "object") {
n = 0;
for (e in r)
if (ds.call(r, e) && ++n && !ds.call(t, e) || !(e in t) || !nr(r[e], t[e]))
return !1;
return Object.keys(t).length === n;
}
}
return r !== r && t !== t;
}
function Kt() {
}
function nf(r, t) {
for (const e in t)
r[e] = t[e];
return r;
}
function Eu(r) {
return r();
}
function ps() {
return /* @__PURE__ */ Object.create(null);
}
function ke(r) {
r.forEach(Eu);
}
function Gt(r) {
return typeof r == "function";
}
function te(r, t) {
return r != r ? t == t : r !== t || r && typeof r == "object" || typeof r == "function";
}
function of(r) {
return Object.keys(r).length === 0;
}
function af(r, ...t) {
if (r == null)
return Kt;
const e = r.subscribe(...t);
return e.unsubscribe ? () => e.unsubscribe() : e;
}
function wu(r, t, e) {
r.$$.on_destroy.push(af(t, e));
}
function Su(r, t, e, n) {
if (r) {
const i = Au(r, t, e, n);
return r[0](i);
}
}
function Au(r, t, e, n) {
return r[1] && n ? nf(e.ctx.slice(), r[1](n(t))) : e.ctx;
}
function Pu(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 Ou(r, t, e, n, i, o) {
if (i) {
const a = Au(t, e, n, o);
r.p(a, i);
}
}
function Ru(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 Iu = typeof window < "u" ? window : typeof globalThis < "u" ? globalThis : global;
function ir(r, t) {
r.appendChild(t);
}
function Z(r, t, e) {
r.insertBefore(t, e || null);
}
function K(r) {
r.parentNode && r.parentNode.removeChild(r);
}
function Ba(r, t) {
for (let e = 0; e < r.length; e += 1)
r[e] && r[e].d(t);
}
function ft(r) {
return document.createElementNS("http://www.w3.org/2000/svg", r);
}
function Na(r) {
return document.createTextNode(r);
}
function ae() {
return Na(" ");
}
function He() {
return Na("");
}
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 sf(r) {
return Array.from(r.childNodes);
}
function hf(r, t) {
t = "" + t, r.data !== t && (r.data = t);
}
function vs(r, t, e) {
r.classList[e ? "add" : "remove"](t);
}
function uf(r, t, { bubbles: e = !1, cancelable: n = !1 } = {}) {
const i = document.createEvent("CustomEvent");
return i.initCustomEvent(r, e, n, t), i;
}
function _i(r, t) {
return new r(t);
}
let cn;
function an(r) {
cn = r;
}
function La() {
if (!cn)
throw new Error("Function called outside component initialization");
return cn;
}
function Fi(r) {
La().$$.on_mount.push(r);
}
function lf(r) {
La().$$.on_destroy.push(r);
}
function Bi() {
const r = La();
return (t, e, { cancelable: n = !1 } = {}) => {
const i = r.$$.callbacks[t];
if (i) {
const o = uf(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 wr = [], dn = [];
let Dr = [];
const _s = [], ff = /* @__PURE__ */ Promise.resolve();
let Uo = !1;
function cf() {
Uo || (Uo = !0, ff.then(Cu));
}
function Go(r) {
Dr.push(r);
}
const Xi = /* @__PURE__ */ new Set();
let _r = 0;
function Cu() {
if (_r !== 0)
return;
const r = cn;
do {
try {
for (; _r < wr.length; ) {
const t = wr[_r];
_r++, an(t), df(t.$$);
}
} catch (t) {
throw wr.length = 0, _r = 0, t;
}
for (an(null), wr.length = 0, _r = 0; dn.length; )
dn.pop()();
for (let t = 0; t < Dr.length; t += 1) {
const e = Dr[t];
Xi.has(e) || (Xi.add(e), e());
}
Dr.length = 0;
} while (wr.length);
for (; _s.length; )
_s.pop()();
Uo = !1, Xi.clear(), an(r);
}
function df(r) {
if (r.fragment !== null) {
r.update(), ke(r.before_update);
const t = r.dirty;
r.dirty = [-1], r.fragment && r.fragment.p(r.ctx, t), r.after_update.forEach(Go);
}
}
function pf(r) {
const t = [], e = [];
Dr.forEach((n) => r.indexOf(n) === -1 ? t.push(n) : e.push(n)), e.forEach((n) => n()), Dr = t;
}
const li = /* @__PURE__ */ new Set();
let rr;
function Xe() {
rr = {
r: 0,
c: [],
p: rr
// parent group
};
}
function je() {
rr.r || ke(rr.c), rr = rr.p;
}
function ct(r, t) {
r && r.i && (li.delete(r), r.i(t));
}
function bt(r, t, e, n) {
if (r && r.o) {
if (li.has(r))
return;
li.add(r), rr.c.push(() => {
li.delete(r), n && (e && r.d(1), n());
}), r.o(t);
} else
n && n();
}
function ee(r) {
r && r.c();
}
function Zt(r, t, e, n) {
const { fragment: i, after_update: o } = r.$$;
i && i.m(t, e), n || Go(() => {
const a = r.$$.on_mount.map(Eu).filter(Gt);
r.$$.on_destroy ? r.$$.on_destroy.push(...a) : ke(a), r.$$.on_mount = [];
}), o.forEach(Go);
}
function Jt(r, t) {
const e = r.$$;
e.fragment !== null && (pf(e.after_update), ke(e.on_destroy), e.fragment && e.fragment.d(t), e.on_destroy = e.fragment = null, e.ctx = []);
}
function vf(r, t) {
r.$$.dirty[0] === -1 && (wr.push(r), cf(), r.$$.dirty.fill(0)), r.$$.dirty[t / 31 | 0] |= 1 << t % 31;
}
function re(r, t, e, n, i, o, a, s = [-1]) {
const h = cn;
an(r);
const u = r.$$ = {
fragment: null,
ctx: [],
// state
props: o,
update: Kt,
not_equal: i,
bound: ps(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(t.context || (h ? h.$$.context : [])),
// everything else
callbacks: ps(),
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 && vf(r, f)), c;
}) : [], u.update(), l = !0, ke(u.before_update), u.fragment = n ? n(u.ctx) : !1, t.target) {
if (t.hydrate) {
const f = sf(t.target);
u.fragment && u.fragment.l(f), f.forEach(K);
} else
u.fragment && u.fragment.c();
t.intro && ct(r.$$.fragment), Zt(r, t.target, t.anchor, t.customElement), Cu();
}
an(h);
}
class ne {
$destroy() {
Jt(this, 1), this.$destroy = Kt;
}
$on(t, e) {
if (!Gt(e))
return Kt;
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 && !of(t) && (this.$$.skip_bound = !0, this.$$set(t), this.$$.skip_bound = !1);
}
}
const mr = [];
function Ua(r, t = Kt) {
let e;
const n = /* @__PURE__ */ new Set();
function i(s) {
if (te(r, s) && (r = s, e)) {
const h = !mr.length;
for (const u of n)
u[1](), mr.push(u, r);
if (h) {
for (let u = 0; u < mr.length; u += 2)
mr[u][0](mr[u + 1]);
mr.length = 0;
}
}
}
function o(s) {
i(s(r));
}
function a(s, h = Kt) {
const u = [s, h];
return n.add(u), n.size === 1 && (e = t(i) || Kt), s(r), () => {
n.delete(u), n.size === 0 && e && (e(), e = null);
};
}
return { set: i, update: o, subscribe: a };
}
const _f = (r) => {
const { subscribe: t, set: e } = Ua(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 Ga = /* @__PURE__ */ ((r) => (r.EDIT = "EDIT", r.HIGHLIGHT = "HIGHLIGHT", r.NONE = "NONE", r))(Ga || {});
const ji = { selected: [] }, mf = (r, t = "EDIT") => {
const { subscribe: e, set: n } = Ua(ji);
let i = ji;
e((f) => i = f);
const o = () => n(ji), 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 = yf(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
};
}, yf = (r, t) => typeof t == "function" ? t(r) || "EDIT" : t || "EDIT";
let Mn;
const gf = new Uint8Array(16);
function bf() {
if (!Mn && (Mn = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Mn))
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
return Mn(gf);
}
const Lt = [];
for (let r = 0; r < 256; ++r)
Lt.push((r + 256).toString(16).slice(1));
function xf(r, t = 0) {
return Lt[r[t + 0]] + Lt[r[t + 1]] + Lt[r[t + 2]] + Lt[r[t + 3]] + "-" + Lt[r[t + 4]] + Lt[r[t + 5]] + "-" + Lt[r[t + 6]] + Lt[r[t + 7]] + "-" + Lt[r[t + 8]] + Lt[r[t + 9]] + "-" + Lt[r[t + 10]] + Lt[r[t + 11]] + Lt[r[t + 12]] + Lt[r[t + 13]] + Lt[r[t + 14]] + Lt[r[t + 15]];
}
const Tf = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ms = {
randomUUID: Tf
};
function Mu(r, t, e) {
if (ms.randomUUID && !t && !r)
return ms.randomUUID();
r = r || {};
const n = r.random || (r.rng || bf)();
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 xf(n);
}
const Ef = (r, t, e, n) => ({
id: Mu(),
annotation: r.id,
created: e || /* @__PURE__ */ 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 && !nr(n, e) ? n : void 0 };
}).filter(({ oldBody: e }) => e), Pf = (r, t) => !nr(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 Ct = /* @__PURE__ */ ((r) => (r.LOCAL = "LOCAL", r.REMOTE = "REMOTE", r))(Ct || {});
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 = /* @__PURE__ */ 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 = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ 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 = Ct.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 = Ct.LOCAL, A = Ct.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 = Ct.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 = Ct.LOCAL) => {
const w = [...r.values()];
r.clear(), t.clear(), o(b, { deleted: w });
}, f = (b, w = !0, A = Ct.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 = Ct.LOCAL) => {
const A = c(b);
A && o(w, { deleted: [A] });
}, p = (b, w = Ct.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 = Ct.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 = Ct.LOCAL) => {
const R = y(b, w);
o(A, { updated: [R] });
}, x = (b, w = Ct.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 = Ct.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 = Ct.LOCAL) => {
const A = T(b);
A && o(w, { updated: [A] });
}
};
}, Mf = () => {
const { subscribe: r, set: t } = Ua([]);
return {
subscribe: r,
set: t
};
}, Df = (r, t, e, n, i, o) => {
const a = /* @__PURE__ */ 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 || !nr(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);
_ && !nr(_, 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 && !nr(g, y) && c("updateAnnotation", g, y);
}), s = [
// Remove annotations that were deselected
...s.filter((y) => _.has(y.id)),
// Add editable annotations that were selected
...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: Ct.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: Ct.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, Ct.REMOTE) : console.error(c);
} else
r.addAnnotation(l, Ct.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, Ct.REMOTE);
} else
r.bulkAddAnnotation(l, !0, Ct.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",
// orange
"#1ac938",
// green
"#e8000b",
// red
"#8b2be2",
// purple
"#9f4800",
// brown
"#f14cc1",
// pink
"#ffc400",
// khaki
"#00d7ff",
// cyan
"#023eff"
// blue
], 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 $t = /* @__PURE__ */ ((r) => (r.ELLIPSE = "ELLIPSE", r.POLYGON = "POLYGON", r.RECTANGLE = "RECTANGLE", r))($t || {});
const ka = {}, Ha = (r, t) => ka[r] = t, ys = (r) => ka[r.type].area(r), jf = (r, t, e) => ka[r.type].intersects(r, t, e), ko = (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;
}
};
Ha($t.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(0.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;
}
};
Ha($t.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
};
Ha($t.RECTANGLE, zf);
function gs(r, t, e) {
const n = r.slice();
return n[11] = t[e], n[13] = e, n;
}
function bs(r) {
let t, e, n, i, o;
return {
c() {
t = ft("rect"), S(t, "class", "a9s-corner-handle"), S(t, "x", e = /*point*/
r[11][0] - /*handleSize*/
r[3] / 2), S(t, "y", n = /*point*/
r[11][1] - /*handleSize*/
r[3] / 2), S(
t,
"height",
/*handleSize*/
r[3]
), S(
t,
"width",
/*handleSize*/
r[3]
);
},
m(a, s) {
Z(a, t, s), i || (o = Yt(t, "pointerdown", function() {
Gt(
/*grab*/
r[10](V(
/*idx*/
r[13]
))
) && r[10](V(
/*idx*/
r[13]
)).apply(this, arguments);
}), i = !0);
},
p(a, s) {
r = a, s & /*geom, handleSize*/
24 && e !== (e = /*point*/
r[11][0] - /*handleSize*/
r[3] / 2) && S(t, "x", e), s & /*geom, handleSize*/
24 && n !== (n = /*point*/
r[11][1] - /*handleSize*/
r[3] / 2) && S(t, "y", n), s & /*handleSize*/
8 && S(
t,
"height",
/*handleSize*/
r[3]
), s & /*handleSize*/
8 && S(
t,
"width",
/*handleSize*/
r[3]
);
},
d(a) {
a && K(t), i = !1, o();
}
};
}
function Wf(r) {
let t, e, n, i, o, a, s, h, u, l, f = (
/*geom*/
r[4].points
), c = [];
for (let d = 0; d < f.length; d += 1)
c[d] = bs(gs(r, f, d));
return {
c() {
t = ft("polygon"), i = ae(), o = ft("polygon"), s = ae();
for (let d = 0; d < c.length; d += 1)
c[d].c();
h = He(), S(t, "class", "a9s-outer"), S(t, "style", e = /*computedStyle*/
r[1] ? "display:none;" : void 0), S(t, "points", n = /*geom*/
r[4].points.map(xs).join(" ")), S(o, "class", "a9s-inner a9s-shape-handle"), S(
o,
"style",
/*computedStyle*/
r[1]
), S(o, "points", a = /*geom*/
r[4].points.map(Ts).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() {
Gt(
/*grab*/
r[10](V.SHAPE)
) && r[10](V.SHAPE).apply(this, arguments);
}),
Yt(o, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.SHAPE)
) && r[10](V.SHAPE).apply(this, arguments);
})
], u = !0);
},
p(d, p) {
if (r = d, p & /*computedStyle*/
2 && e !== (e = /*computedStyle*/
r[1] ? "display:none;" : void 0) && S(t, "style", e), p & /*geom*/
16 && n !== (n = /*geom*/
r[4].points.map(xs).join(" ")) && S(t, "points", n), p & /*computedStyle*/
2 && S(
o,
"style",
/*computedStyle*/
r[1]
), p & /*geom*/
16 && a !== (a = /*geom*/
r[4].points.map(Ts).join(" ")) && S(o, "points", a), p & /*geom, handleSize, grab, Handle*/
1048) {
f = /*geom*/
r[4].points;
let v;
for (v = 0; v < f.length; v += 1) {
const _ = gs(r, f, v);
c[v] ? c[v].p(_, p) : (c[v] = bs(_), 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 && K(t), d && K(i), d && K(o), d && K(s), Ba(c, d), d && K(h), u = !1, ke(l);
}
};
}
function $f(r) {
let t, e;
return t = new Du({
props: {
shape: (
/*shape*/
r[0]
),
transform: (
/*transform*/
r[2]
),
editor: (
/*editor*/
r[5]
),
$$slots: {
default: [
Wf,
({ grab: n }) => ({ 10: n }),
({ grab: n }) => n ? 1024 : 0
]
},
$$scope: { ctx: r }
}
}), t.$on(
"change",
/*change_handler*/
r[7]
), t.$on(
"grab",
/*grab_handler*/
r[8]
), t.$on(
"release",
/*release_handler*/
r[9]
), {
c() {
ee(t.$$.fragment);
},
m(n, i) {
Zt(t, n, i), e = !0;
},
p(n, [i]) {
const o = {};
i & /*shape*/
1 && (o.shape = /*shape*/
n[0]), i & /*transform*/
4 && (o.transform = /*transform*/
n[2]), i & /*$$scope, geom, handleSize, grab, computedStyle*/
17434 && (o.$$scope = { dirty: i, ctx: n }), t.$set(o);
},
i(n) {
e || (ct(t.$$.fragment, n), e = !0);
},
o(n) {
bt(t.$$.fragment, n), e = !1;
},
d(n) {
Jt(t, n);
}
};
}
const xs = (r) => r.join(","), Ts = (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 = ko(_);
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 & /*shape*/
1 && e(4, n = o.geometry), r.$$.dirty & /*viewportScale*/
64 && e(3, i = 10 / h);
}, [
o,
a,
s,
i,
n,
u,
h,
l,
f,
c
];
}
class Kf extends ne {
constructor(t) {
super(), re(this, t, qf, $f, te, {
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, $, q, Q, N, F, k, tt, et, pt, j, st, _t, Tt, W, it, at, lt, nt;
return {
c() {
t = ft("rect"), s = ae(), h = ft("rect"), d = ae(), p = ft("rect"), y = ae(), g = ft("rect"), P = ae(), b = ft("rect"), C = ae(), M = ft("rect"), $ = ae(), q = ft("rect"), F = ae(), k = ft("rect"), pt = ae(), j = ft("rect"), Tt = ae(), W = ft("rect"), S(t, "class", "a9s-outer"), S(t, "style", e = /*computedStyle*/
r[1] ? "display:none;" : void 0), S(t, "x", n = /*geom*/
r[4].x), S(t, "y", i = /*geom*/
r[4].y), S(t, "width", o = /*geom*/
r[4].w), S(t, "height", a = /*geom*/
r[4].h), S(h, "class", "a9s-inner a9s-shape-handle"), S(
h,
"style",
/*computedStyle*/
r[1]
), S(h, "x", u = /*geom*/
r[4].x), S(h, "y", l = /*geom*/
r[4].y), S(h, "width", f = /*geom*/
r[4].w), S(h, "height", c = /*geom*/
r[4].h), S(p, "class", "a9s-edge-handle a9s-edge-handle-top"), S(p, "x", v = /*geom*/
r[4].x), S(p, "y", _ = /*geom*/
r[4].y), S(p, "height", 1), S(p, "width", m = /*geom*/
r[4].w), S(g, "class", "a9s-edge-handle a9s-edge-handle-right"), S(g, "x", x = /*geom*/
r[4].x + /*geom*/
r[4].w), S(g, "y", T = /*geom*/
r[4].y), S(g, "height", E = /*geom*/
r[4].h), S(g, "width", 1), S(b, "class", "a9s-edge-handle a9s-edge-handle-bottom"), S(b, "x", w = /*geom*/
r[4].x), S(b, "y", A = /*geom*/
r[4].y + /*geom*/
r[4].h), S(b, "height", 1), S(b, "width", R = /*geom*/
r[4].w), S(M, "class", "a9s-edge-handle a9s-edge-handle-left"), S(M, "x", H = /*geom*/
r[4].x), S(M, "y", U = /*geom*/
r[4].y), S(M, "height", B = /*geom*/
r[4].h), S(M, "width", 1), S(q, "class", "a9s-corner-handle a9s-corner-handle-topleft"), S(q, "x", Q = /*geom*/
r[4].x - /*handleSize*/
r[3] / 2), S(q, "y", N = /*geom*/
r[4].y - /*handleSize*/
r[3] / 2), S(
q,
"height",
/*handleSize*/
r[3]
), S(
q,
"width",
/*handleSize*/
r[3]
), S(k, "class", "a9s-corner-handle a9s-corner-handle-topright"), S(k, "x", tt = /*geom*/
r[4].x + /*geom*/
r[4].w - /*handleSize*/
r[3] / 2), S(k, "y", et = /*geom*/
r[4].y - /*handleSize*/
r[3] / 2), S(
k,
"height",
/*handleSize*/
r[3]
), S(
k,
"width",
/*handleSize*/
r[3]
), S(j, "class", "a9s-corner-handle a9s-corner-handle-bottomright"), S(j, "x", st = /*geom*/
r[4].x + /*geom*/
r[4].w - /*handleSize*/
r[3] / 2), S(j, "y", _t = /*geom*/
r[4].y + /*geom*/
r[4].h - /*handleSize*/
r[3] / 2), S(
j,
"height",
/*handleSize*/
r[3]
), S(
j,
"width",
/*handleSize*/
r[3]
), S(W, "class", "a9s-corner-handle a9s-corner-handle-bottomleft"), S(W, "x", it = /*geom*/
r[4].x - /*handleSize*/
r[3] / 2), S(W, "y", at = /*geom*/
r[4].y + /*geom*/
r[4].h - /*handleSize*/
r[3] / 2), S(
W,
"height",
/*handleSize*/
r[3]
), S(
W,
"width",
/*handleSize*/
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, q, O), Z(D, F, O), Z(D, k, O), Z(D, pt, O), Z(D, j, O), Z(D, Tt, O), Z(D, W, O), lt || (nt = [
Yt(t, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.SHAPE)
) && r[10](V.SHAPE).apply(this, arguments);
}),
Yt(h, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.SHAPE)
) && r[10](V.SHAPE).apply(this, arguments);
}),
Yt(p, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.TOP)
) && r[10](V.TOP).apply(this, arguments);
}),
Yt(g, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.RIGHT)
) && r[10](V.RIGHT).apply(this, arguments);
}),
Yt(b, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.BOTTOM)
) && r[10](V.BOTTOM).apply(this, arguments);
}),
Yt(M, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.LEFT)
) && r[10](V.LEFT).apply(this, arguments);
}),
Yt(q, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.TOP_LEFT)
) && r[10](V.TOP_LEFT).apply(this, arguments);
}),
Yt(k, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.TOP_RIGHT)
) && r[10](V.TOP_RIGHT).apply(this, arguments);
}),
Yt(j, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.BOTTOM_RIGHT)
) && r[10](V.BOTTOM_RIGHT).apply(this, arguments);
}),
Yt(W, "pointerdown", function() {
Gt(
/*grab*/
r[10](V.BOTTOM_LEFT)
) && r[10](V.BOTTOM_LEFT).apply(this, arguments);
})
], lt = !0);
},
p(D, O) {
r = D, O & /*computedStyle*/
2 && e !== (e = /*computedStyle*/
r[1] ? "display:none;" : void 0) && S(t, "style", e), O & /*geom*/
16 && n !== (n = /*geom*/
r[4].x) && S(t, "x", n), O & /*geom*/
16 && i !== (i = /*geom*/
r[4].y) && S(t, "y", i), O & /*geom*/
16 && o !== (o = /*geom*/
r[4].w) && S(t, "width", o), O & /*geom*/
16 && a !== (a = /*geom*/
r[4].h) && S(t, "height", a), O & /*computedStyle*/
2 && S(
h,
"style",
/*computedStyle*/
r[1]
), O & /*geom*/
16 && u !== (u = /*geom*/
r[4].x) && S(h, "x", u), O & /*geom*/
16 && l !== (l = /*geom*/
r[4].y) && S(h, "y", l), O & /*geom*/
16 && f !== (f = /*geom*/
r[4].w) && S(h, "width", f), O & /*geom*/
16 && c !== (c = /*geom*/
r[4].h) && S(h, "height", c), O & /*geom*/
16 && v !== (v = /*geom*/
r[4].x) && S(p, "x", v), O & /*geom*/
16 && _ !== (_ = /*geom*/
r[4].y) && S(p, "y", _), O & /*geom*/
16 && m !== (m = /*geom*/
r[4].w) && S(p, "width", m), O & /*geom*/
16 && x !== (x = /*geom*/
r[4].x + /*geom*/
r[4].w) && S(g, "x", x), O & /*geom*/
16 && T !== (T = /*geom*/
r[4].y) && S(g, "y", T), O & /*geom*/
16 && E !== (E = /*geom*/
r[4].h) && S(g, "height", E), O & /*geom*/
16 && w !== (w = /*geom*/
r[4].x) && S(b, "x", w), O & /*geom*/
16 && A !== (A = /*geom*/
r[4].y + /*geom*/
r[4].h) && S(b, "y", A), O & /*geom*/
16 && R !== (R = /*geom*/
r[4].w) && S(b, "width", R), O & /*geom*/
16 && H !== (H = /*geom*/
r[4].x) && S(M, "x", H), O & /*geom*/
16 && U !== (U = /*geom*/
r[4].y) && S(M, "y", U), O & /*geom*/
16 && B !== (B = /*geom*/
r[4].h) && S(M, "height", B), O & /*geom, handleSize*/
24 && Q !== (Q = /*geom*/
r[4].x - /*handleSize*/
r[3] / 2) && S(q, "x", Q), O & /*geom, handleSize*/
24 && N !== (N = /*geom*/
r[4].y - /*handleSize*/
r[3] / 2) && S(q, "y", N), O & /*handleSize*/
8 && S(
q,
"height",
/*handleSize*/
r[3]
), O & /*handleSize*/
8 && S(
q,
"width",
/*handleSize*/
r[3]
), O & /*geom, handleSize*/
24 && tt !== (tt = /*geom*/
r[4].x + /*geom*/
r[4].w - /*handleSize*/
r[3] / 2) && S(k, "x", tt), O & /*geom, handleSize*/
24 && et !== (et = /*geom*/
r[4].y - /*handleSize*/
r[3] / 2) && S(k, "y", et), O & /*handleSize*/
8 && S(
k,
"height",
/*handleSize*/
r[3]
), O & /*handleSize*/
8 && S(
k,
"width",
/*handleSize*/
r[3]
), O & /*geom, handleSize*/
24 && st !== (st = /*geom*/
r[4].x + /*geom*/
r[4].w - /*handleSize*/
r[3] / 2) && S(j, "x", st), O & /*geom, handleSize*/
24 && _t !== (_t = /*geom*/
r[4].y + /*geom*/
r[4].h - /*handleSize*/
r[3] / 2) && S(j, "y", _t), O & /*handleSize*/
8 && S(
j,
"height",
/*handleSize*/
r[3]
), O & /*handleSize*/
8 && S(
j,
"width",
/*handleSize*/
r[3]
), O & /*geom, handleSize*/
24 && it !== (it = /*geom*/
r[4].x - /*handleSize*/
r[3] / 2) && S(W, "x", it), O & /*geom, handleSize*/
24 && at !== (at = /*geom*/
r[4].y + /*geom*/
r[4].h - /*handleSize*/
r[3] / 2) && S(W, "y", at), O & /*handleSize*/
8 && S(
W,
"height",
/*handleSize*/
r[3]
), O & /*handleSize*/
8 && S(
W,
"width",
/*handleSize*/
r[3]
);
},
d(D) {
D && K(t), D && K(s), D && K(h), D && K(d), D && K(p), D && K(y), D && K(g), D && K(P), D && K(b), D && K(C), D && K(M), D && K($), D && K(q), D && K(F), D && K(k), D && K(pt), D && K(j), D && K(Tt), D && K(W), lt = !1, ke(nt);
}
};
}
function Jf(r) {
let t, e;
return t = new Du({
props: {
shape: (
/*shape*/
r[0]
),
transform: (
/*transform*/
r[2]
),
editor: (
/*editor*/
r[5]
),
$$slots: {
default: [
Zf,
({ grab: n }) => ({ 10: n }),
({ grab: n }) => n ? 1024 : 0
]
},
$$scope: { ctx: r }
}
}), t.$on(
"grab",
/*grab_handler*/
r[7]
), t.$on(
"change",
/*change_handler*/
r[8]
), t.$on(
"release",
/*release_handler*/
r[9]
), {
c() {
ee(t.$$.fragment);
},
m(n, i) {
Zt(t, n, i), e = !0;
},
p(n, [i]) {
const o = {};
i & /*shape*/
1 && (o.shape = /*shape*/
n[0]), i & /*transform*/
4 && (o.transform = /*transform*/
n[2]), i & /*$$scope, geom, handleSize, grab, computedStyle*/
3098 && (o.$$scope = { dirty: i, ctx: n }), t.$set(o);
},
i(n) {
e || (ct(t.$$.fragment, n), e = !0);
},
o(n) {
bt(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 & /*shape*/
1 && e(4, n = o.geometry), r.$$.dirty & /*viewportScale*/
64 && e(3, i = 10 / h);
}, [
o,
a,
s,
i,
n,
u,
h,
l,
f,
c
];
}
class tc extends ne {
constructor(t) {
super(), re(this, t, Qf, Jf, te, {
shape: 0,
computedStyle: 1,
transform: 2,
viewportScale: 6
});
}
}
const ec = /* @__PURE__ */ new Map([
[$t.RECTANGLE, tc],
[$t.POLYGON, Kf]
]), Es = (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) => ({}), ws = (r) => ({ grab: (
/*onGrab*/
r[0]
) });
function nc(r) {
let t, e, n, i;
const o = (
/*#slots*/
r[7].default
), a = Su(
o,
r,
/*$$scope*/
r[6],
ws
);
return {
c() {
t = ft("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",
/*onRelease*/
r[2]
),
Yt(
t,
"pointermove",
/*onPointerMove*/
r[1]
)
], n = !0);
},
p(s, [h]) {
a && a.p && (!e || h & /*$$scope*/
64) && Ou(
a,
o,
s,
/*$$scope*/
s[6],
e ? Pu(
o,
/*$$scope*/
s[6],
h,
rc
) : Ru(
/*$$scope*/
s[6]
),
ws
);
},
i(s) {
e || (ct(a, s), e = !0);
},
o(s) {
bt(a, s), e = !1;
},
d(s) {
s && K(t), a && a.d(s), n = !1, ke(i);
}
};
}
function ic(r, t, e) {
let { $$slots: n = {}, $$scope: i } = t;
const o = Bi();
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 Du extends ne {
constructor(t) {
super(), re(this, t, ic, nc, te, { shape: 3, editor: 4, transform: 5 });
}
}
function Ss(r) {
let t, e;
return {
c() {
t = ft("rect"), e = ft("rect"), S(t, "class", "a9s-outer"), S(
t,
"x",
/*x*/
r[2]
), S(
t,
"y",
/*y*/
r[3]
), S(
t,
"width",
/*w*/
r[4]
), S(
t,
"height",
/*h*/
r[5]
), S(e, "class", "a9s-inner"), S(
e,
"x",
/*x*/
r[2]
), S(
e,
"y",
/*y*/
r[3]
), S(
e,
"width",
/*w*/
r[4]
), S(
e,
"height",
/*h*/
r[5]
);
},
m(n, i) {
Z(n, t, i), Z(n, e, i);
},
p(n, i) {
i & /*x*/
4 && S(
t,
"x",
/*x*/
n[2]
), i & /*y*/
8 && S(
t,
"y",
/*y*/
n[3]
), i & /*w*/
16 && S(
t,
"width",
/*w*/
n[4]
), i & /*h*/
32 && S(
t,
"height",
/*h*/
n[5]
), i & /*x*/
4 && S(
e,
"x",
/*x*/
n[2]
), i & /*y*/
8 && S(
e,
"y",
/*y*/
n[3]
), i & /*w*/
16 && S(
e,
"width",
/*w*/
n[4]
), i & /*h*/
32 && S(
e,
"height",
/*h*/
n[5]
);
},
d(n) {
n && K(t), n && K(e);
}
};
}
function oc(r) {
let t, e = (
/*origin*/
r[1] && Ss(r)
);
return {
c() {
t = ft("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]) {
/*origin*/
n[1] ? e ? e.p(n, i) : (e = Ss(n), e.c(), e.m(t, null)) : e && (e.d(1), e = null);
},
i: Kt,
o: Kt,
d(n) {
n && K(t), e && e.d(), r[7](null);
}
};
}
function ac(r, t, e) {
const n = Bi();
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: $t.