@recogito/annotorious
Version:
A JavaScript image annotation library
1,801 lines • 814 kB
JavaScript
import Ki from "openseadragon";
var Bs = Object.prototype.hasOwnProperty;
function We(r, e) {
var t, i;
if (r === e)
return !0;
if (r && e && (t = r.constructor) === e.constructor) {
if (t === Date)
return r.getTime() === e.getTime();
if (t === RegExp)
return r.toString() === e.toString();
if (t === Array) {
if ((i = r.length) === e.length)
for (; i-- && We(r[i], e[i]); )
;
return i === -1;
}
if (!t || typeof r == "object") {
i = 0;
for (t in r)
if (Bs.call(r, t) && ++i && !Bs.call(e, t) || !(t in e) || !We(r[t], e[t]))
return !1;
return Object.keys(e).length === i;
}
}
return r !== r && e !== e;
}
function jt() {
}
function ul(r, e) {
for (const t in e)
r[t] = e[t];
return r;
}
function Bh(r) {
return r();
}
function Gs() {
return /* @__PURE__ */ Object.create(null);
}
function Pe(r) {
r.forEach(Bh);
}
function Ft(r) {
return typeof r == "function";
}
function Vt(r, e) {
return r != r ? e == e : r !== e || r && typeof r == "object" || typeof r == "function";
}
function ll(r) {
return Object.keys(r).length === 0;
}
function cl(r, ...e) {
if (r == null)
return jt;
const t = r.subscribe(...e);
return t.unsubscribe ? () => t.unsubscribe() : t;
}
function Gh(r, e, t) {
r.$$.on_destroy.push(cl(e, t));
}
function Uh(r, e, t, i) {
if (r) {
const n = kh(r, e, t, i);
return r[0](n);
}
}
function kh(r, e, t, i) {
return r[1] && i ? ul(t.ctx.slice(), r[1](i(e))) : t.ctx;
}
function Xh(r, e, t, i) {
if (r[2] && i) {
const n = r[2](i(t));
if (e.dirty === void 0)
return n;
if (typeof n == "object") {
const o = [], s = Math.max(e.dirty.length, n.length);
for (let a = 0; a < s; a += 1)
o[a] = e.dirty[a] | n[a];
return o;
}
return e.dirty | n;
}
return e.dirty;
}
function jh(r, e, t, i, n, o) {
if (n) {
const s = kh(e, t, i, o);
r.p(s, n);
}
}
function Hh(r) {
if (r.ctx.length > 32) {
const e = [], t = r.ctx.length / 32;
for (let i = 0; i < t; i++)
e[i] = -1;
return e;
}
return -1;
}
const Yh = typeof window < "u" ? window : typeof globalThis < "u" ? globalThis : global;
function $e(r, e) {
r.appendChild(e);
}
function Y(r, e, t) {
r.insertBefore(e, t || null);
}
function H(r) {
r.parentNode && r.parentNode.removeChild(r);
}
function ps(r, e) {
for (let t = 0; t < r.length; t += 1)
r[t] && r[t].d(e);
}
function st(r) {
return document.createElementNS("http://www.w3.org/2000/svg", r);
}
function ds(r) {
return document.createTextNode(r);
}
function Zt() {
return ds(" ");
}
function Me() {
return ds("");
}
function Ut(r, e, t, i) {
return r.addEventListener(e, t, i), () => r.removeEventListener(e, t, i);
}
function A(r, e, t) {
t == null ? r.removeAttribute(e) : r.getAttribute(e) !== t && r.setAttribute(e, t);
}
function pl(r) {
return Array.from(r.childNodes);
}
function dl(r, e) {
e = "" + e, r.data !== e && (r.data = e);
}
function Us(r, e, t) {
r.classList[t ? "add" : "remove"](e);
}
function fl(r, e, { bubbles: t = !1, cancelable: i = !1 } = {}) {
const n = document.createEvent("CustomEvent");
return n.initCustomEvent(r, t, i, e), n;
}
function Zi(r, e) {
return new r(e);
}
let Kr;
function Vr(r) {
Kr = r;
}
function fs() {
if (!Kr)
throw new Error("Function called outside component initialization");
return Kr;
}
function mn(r) {
fs().$$.on_mount.push(r);
}
function yl(r) {
fs().$$.on_destroy.push(r);
}
function _n() {
const r = fs();
return (e, t, { cancelable: i = !1 } = {}) => {
const n = r.$$.callbacks[e];
if (n) {
const o = fl(e, t, { cancelable: i });
return n.slice().forEach((s) => {
s.call(r, o);
}), !o.defaultPrevented;
}
return !0;
};
}
function vr(r, e) {
const t = r.$$.callbacks[e.type];
t && t.slice().forEach((i) => i.call(this, e));
}
const pr = [], Zr = [];
let br = [];
const ks = [], ml = /* @__PURE__ */ Promise.resolve();
let go = !1;
function _l() {
go || (go = !0, ml.then(Vh));
}
function vo(r) {
br.push(r);
}
const En = /* @__PURE__ */ new Set();
let or = 0;
function Vh() {
if (or !== 0)
return;
const r = Kr;
do {
try {
for (; or < pr.length; ) {
const e = pr[or];
or++, Vr(e), gl(e.$$);
}
} catch (e) {
throw pr.length = 0, or = 0, e;
}
for (Vr(null), pr.length = 0, or = 0; Zr.length; )
Zr.pop()();
for (let e = 0; e < br.length; e += 1) {
const t = br[e];
En.has(t) || (En.add(t), t());
}
br.length = 0;
} while (pr.length);
for (; ks.length; )
ks.pop()();
go = !1, En.clear(), Vr(r);
}
function gl(r) {
if (r.fragment !== null) {
r.update(), Pe(r.before_update);
const e = r.dirty;
r.dirty = [-1], r.fragment && r.fragment.p(r.ctx, e), r.after_update.forEach(vo);
}
}
function vl(r) {
const e = [], t = [];
br.forEach((i) => r.indexOf(i) === -1 ? e.push(i) : t.push(i)), t.forEach((i) => i()), br = e;
}
const zi = /* @__PURE__ */ new Set();
let ze;
function De() {
ze = {
r: 0,
c: [],
p: ze
// parent group
};
}
function Ce() {
ze.r || Pe(ze.c), ze = ze.p;
}
function at(r, e) {
r && r.i && (zi.delete(r), r.i(e));
}
function ft(r, e, t, i) {
if (r && r.o) {
if (zi.has(r))
return;
zi.add(r), ze.c.push(() => {
zi.delete(r), i && (t && r.d(1), i());
}), r.o(e);
} else
i && i();
}
function zt(r) {
r && r.c();
}
function Ht(r, e, t, i) {
const { fragment: n, after_update: o } = r.$$;
n && n.m(e, t), i || vo(() => {
const s = r.$$.on_mount.map(Bh).filter(Ft);
r.$$.on_destroy ? r.$$.on_destroy.push(...s) : Pe(s), r.$$.on_mount = [];
}), o.forEach(vo);
}
function Yt(r, e) {
const t = r.$$;
t.fragment !== null && (vl(t.after_update), Pe(t.on_destroy), t.fragment && t.fragment.d(e), t.on_destroy = t.fragment = null, t.ctx = []);
}
function bl(r, e) {
r.$$.dirty[0] === -1 && (pr.push(r), _l(), r.$$.dirty.fill(0)), r.$$.dirty[e / 31 | 0] |= 1 << e % 31;
}
function Wt(r, e, t, i, n, o, s, a = [-1]) {
const h = Kr;
Vr(r);
const u = r.$$ = {
fragment: null,
ctx: [],
// state
props: o,
update: jt,
not_equal: n,
bound: Gs(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(e.context || (h ? h.$$.context : [])),
// everything else
callbacks: Gs(),
dirty: a,
skip_bound: !1,
root: e.target || h.$$.root
};
s && s(u.root);
let l = !1;
if (u.ctx = t ? t(r, e.props || {}, (c, p, ...d) => {
const f = d.length ? d[0] : p;
return u.ctx && n(u.ctx[c], u.ctx[c] = f) && (!u.skip_bound && u.bound[c] && u.bound[c](f), l && bl(r, c)), p;
}) : [], u.update(), l = !0, Pe(u.before_update), u.fragment = i ? i(u.ctx) : !1, e.target) {
if (e.hydrate) {
const c = pl(e.target);
u.fragment && u.fragment.l(c), c.forEach(H);
} else
u.fragment && u.fragment.c();
e.intro && at(r.$$.fragment), Ht(r, e.target, e.anchor, e.customElement), Vh();
}
Vr(h);
}
class $t {
$destroy() {
Yt(this, 1), this.$destroy = jt;
}
$on(e, t) {
if (!Ft(t))
return jt;
const i = this.$$.callbacks[e] || (this.$$.callbacks[e] = []);
return i.push(t), () => {
const n = i.indexOf(t);
n !== -1 && i.splice(n, 1);
};
}
$set(e) {
this.$$set && !ll(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1);
}
}
const sr = [];
function ys(r, e = jt) {
let t;
const i = /* @__PURE__ */ new Set();
function n(a) {
if (Vt(r, a) && (r = a, t)) {
const h = !sr.length;
for (const u of i)
u[1](), sr.push(u, r);
if (h) {
for (let u = 0; u < sr.length; u += 2)
sr[u][0](sr[u + 1]);
sr.length = 0;
}
}
}
function o(a) {
n(a(r));
}
function s(a, h = jt) {
const u = [a, h];
return i.add(u), i.size === 1 && (t = e(n) || jt), a(r), () => {
i.delete(u), i.size === 0 && t && (t(), t = null);
};
}
return { set: n, update: o, subscribe: s };
}
const xl = (r) => {
const { subscribe: e, set: t } = ys(null);
let i = null;
return e((n) => i = n), r.observe(({ changes: n }) => {
if (i) {
n.deleted.some((s) => s.id === i) && t(null);
const o = n.updated.find(({ oldValue: s }) => s.id === i);
o && t(o.newValue.id);
}
}), {
get current() {
return i;
},
subscribe: e,
set: t
};
};
var zh = /* @__PURE__ */ ((r) => (r.EDIT = "EDIT", r.HIGHLIGHT = "HIGHLIGHT", r.NONE = "NONE", r))(zh || {});
const An = { selected: [] }, Tl = (r, e = "EDIT") => {
const { subscribe: t, set: i } = ys(An);
let n = An;
t((c) => n = c);
const o = () => i(An), s = () => {
var c;
return ((c = n.selected) == null ? void 0 : c.length) === 0;
}, a = (c) => {
if (n.selected.length === 0)
return !1;
const p = typeof c == "string" ? c : c.id;
return n.selected.some((d) => d.id === p);
}, h = (c, p) => {
const d = r.getAnnotation(c);
if (d) {
const f = El(d, e);
i(f === "EDIT" ? { selected: [{ id: c, editable: !0 }], pointerEvent: p } : f === "HIGHLIGHT" ? { selected: [{ id: c }], pointerEvent: p } : { selected: [], pointerEvent: p });
} else
console.warn("Invalid selection: " + c);
}, u = (c, p = !0) => {
const d = Array.isArray(c) ? c : [c], f = d.map((y) => r.getAnnotation(y)).filter((y) => y);
i({ selected: f.map(({ id: y }) => ({ id: y, editable: p })) }), f.length !== d.length && console.warn("Invalid selection", c);
}, l = (c) => {
if (n.selected.length === 0)
return !1;
const { selected: p } = n;
p.filter(({ id: d }) => c.includes(d)).length > 0 && i({ selected: p.filter(({ id: d }) => !c.includes(d)) });
};
return r.observe(({ changes: c }) => l(c.deleted.map((p) => p.id))), {
clear: o,
clickSelect: h,
get selected() {
return n ? [...n.selected] : null;
},
get pointerEvent() {
return n ? n.pointerEvent : null;
},
isEmpty: s,
isSelected: a,
setSelected: u,
subscribe: t
};
}, El = (r, e) => typeof e == "function" ? e(r) || "EDIT" : e || "EDIT";
let yi;
const Al = new Uint8Array(16);
function Sl() {
if (!yi && (yi = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !yi))
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
return yi(Al);
}
const Ct = [];
for (let r = 0; r < 256; ++r)
Ct.push((r + 256).toString(16).slice(1));
function Rl(r, e = 0) {
return Ct[r[e + 0]] + Ct[r[e + 1]] + Ct[r[e + 2]] + Ct[r[e + 3]] + "-" + Ct[r[e + 4]] + Ct[r[e + 5]] + "-" + Ct[r[e + 6]] + Ct[r[e + 7]] + "-" + Ct[r[e + 8]] + Ct[r[e + 9]] + "-" + Ct[r[e + 10]] + Ct[r[e + 11]] + Ct[r[e + 12]] + Ct[r[e + 13]] + Ct[r[e + 14]] + Ct[r[e + 15]];
}
const Ol = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Xs = {
randomUUID: Ol
};
function wl(r, e, t) {
if (Xs.randomUUID && !e && !r)
return Xs.randomUUID();
r = r || {};
const i = r.random || (r.rng || Sl)();
if (i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, e) {
t = t || 0;
for (let n = 0; n < 16; ++n)
e[t + n] = i[n];
return e;
}
return Rl(i);
}
const Il = (r, e) => {
const t = new Set(r.bodies.map((i) => i.id));
return e.bodies.filter((i) => !t.has(i.id));
}, Pl = (r, e) => {
const t = new Set(e.bodies.map((i) => i.id));
return r.bodies.filter((i) => !t.has(i.id));
}, Ml = (r, e) => e.bodies.map((t) => {
const i = r.bodies.find((n) => n.id === t.id);
return { newBody: t, oldBody: i && !We(i, t) ? i : void 0 };
}).filter(({ oldBody: t }) => t), Dl = (r, e) => !We(r.target, e.target), Cl = (r, e) => ({
oldValue: r,
newValue: e,
bodiesCreated: Il(r, e),
bodiesDeleted: Pl(r, e),
bodiesUpdated: Ml(r, e),
targetUpdated: Dl(r, e) ? { oldTarget: r.target, newTarget: e.target } : void 0
});
var Ot = /* @__PURE__ */ ((r) => (r.LOCAL = "LOCAL", r.REMOTE = "REMOTE", r))(Ot || {});
const Fl = (r, e) => {
var t, i;
const { changes: n, origin: o } = e;
if (!(!r.options.origin || r.options.origin === o))
return !1;
if (r.options.ignore) {
const { ignore: s } = r.options, a = (h) => (h == null ? void 0 : h.length) > 0;
if (!(a(n.created) || a(n.deleted))) {
const h = (t = n.updated) == null ? void 0 : t.some((l) => a(l.bodiesCreated) || a(l.bodiesDeleted) || a(l.bodiesUpdated)), u = (i = n.updated) == null ? void 0 : i.some((l) => l.targetUpdated);
if (s === "BODY_ONLY" && h && !u || s === "TARGET_ONLY" && u && !h)
return !1;
}
}
if (r.options.annotations) {
const s = /* @__PURE__ */ new Set([
...n.created.map((a) => a.id),
...n.deleted.map((a) => a.id),
...n.updated.map(({ oldValue: a }) => a.id)
]);
return !!(Array.isArray(r.options.annotations) ? r.options.annotations : [r.options.annotations]).find((a) => s.has(a));
} else
return !0;
}, Nl = (r) => r.id !== void 0, Ll = () => {
const r = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), t = [], i = (v, T = {}) => t.push({ onChange: v, options: T }), n = (v) => {
const T = t.findIndex((S) => S.onChange == v);
T > -1 && t.splice(T, 1);
}, o = (v, T) => {
const S = {
origin: v,
changes: {
created: T.created || [],
updated: T.updated || [],
deleted: T.deleted || []
},
state: [...r.values()]
};
t.forEach((R) => {
Fl(R, S) && R.onChange(S);
});
}, s = (v, T = Ot.LOCAL) => {
if (r.get(v.id))
throw Error(`Cannot add annotation ${v.id} - exists already`);
r.set(v.id, v), v.bodies.forEach((S) => e.set(S.id, v.id)), o(T, { created: [v] });
}, a = (v, T = Ot.LOCAL, S = Ot.LOCAL) => {
const R = Nl(T) ? S : T, O = typeof v == "string" ? T : v, w = typeof v == "string" ? v : v.id, C = r.get(w);
if (C) {
const B = Cl(C, O);
w === O.id ? r.set(w, O) : (r.delete(w), r.set(O.id, O)), C.bodies.forEach((V) => e.delete(V.id)), O.bodies.forEach((V) => e.set(V.id, O.id)), o(R, { updated: [B] });
} else
throw Error(`Cannot update annotation ${w} - does not exist`);
}, h = (v, T = Ot.LOCAL) => {
const S = r.get(v.annotation);
if (S) {
const R = {
...S,
bodies: [...S.bodies, v]
};
r.set(S.id, R), e.set(v.id, R.id), o(T, { updated: [{
oldValue: S,
newValue: R,
bodiesCreated: [v]
}] });
} else
console.warn(`Attempt to add body to missing annotation: ${v.annotation}`);
}, u = () => [...r.values()], l = (v = Ot.LOCAL) => {
const T = [...r.values()];
r.clear(), e.clear(), o(v, { deleted: T });
}, c = (v, T = !0, S = Ot.LOCAL) => {
if (T) {
const R = [...r.values()];
r.clear(), e.clear(), v.forEach((O) => {
r.set(O.id, O), O.bodies.forEach((w) => e.set(w.id, O.id));
}), o(S, { created: v, deleted: R });
} else {
const R = v.reduce((O, w) => {
const C = r.get(w.id);
return C ? [...O, C] : O;
}, []);
if (R.length > 0)
throw Error(`Bulk insert would overwrite the following annotations: ${R.map((O) => O.id).join(", ")}`);
v.forEach((O) => {
r.set(O.id, O), O.bodies.forEach((w) => e.set(w.id, O.id));
}), o(S, { created: v });
}
}, p = (v) => {
const T = typeof v == "string" ? v : v.id, S = r.get(T);
if (S)
return r.delete(T), S.bodies.forEach((R) => e.delete(R.id)), S;
console.warn(`Attempt to delete missing annotation: ${T}`);
}, d = (v, T = Ot.LOCAL) => {
const S = p(v);
S && o(T, { deleted: [S] });
}, f = (v, T = Ot.LOCAL) => {
const S = v.reduce((R, O) => {
const w = p(O);
return w ? [...R, w] : R;
}, []);
S.length > 0 && o(T, { deleted: S });
}, y = (v, T = Ot.LOCAL) => {
const S = r.get(v.annotation);
if (S) {
const R = S.bodies.find((O) => O.id === v.id);
if (R) {
e.delete(R.id);
const O = {
...S,
bodies: S.bodies.filter((w) => w.id !== v.id)
};
r.set(S.id, O), o(T, { updated: [{
oldValue: S,
newValue: O,
bodiesDeleted: [R]
}] });
} else
console.warn(`Attempt to delete missing body ${v.id} from annotation ${v.annotation}`);
} else
console.warn(`Attempt to delete body from missing annotation ${v.annotation}`);
}, m = (v) => {
const T = r.get(v);
return T ? { ...T } : void 0;
}, _ = (v) => {
const T = e.get(v);
if (T) {
const S = m(T).bodies.find((R) => R.id === v);
if (S)
return S;
console.error(`Store integrity error: body ${v} in index, but not in annotation`);
} else
console.warn(`Attempt to retrieve missing body: ${v}`);
}, g = (v, T) => {
if (v.annotation !== T.annotation)
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
const S = r.get(v.annotation);
if (S) {
const R = S.bodies.find((w) => w.id === v.id), O = {
...S,
bodies: S.bodies.map((w) => w.id === R.id ? T : w)
};
return r.set(S.id, O), R.id !== T.id && (e.delete(R.id), e.set(T.id, O.id)), {
oldValue: S,
newValue: O,
bodiesUpdated: [{ oldBody: R, newBody: T }]
};
} else
console.warn(`Attempt to add body to missing annotation ${v.annotation}`);
}, b = (v, T, S = Ot.LOCAL) => {
const R = g(v, T);
o(S, { updated: [R] });
}, x = (v, T = Ot.LOCAL) => {
const S = v.map((R) => g({ id: R.id, annotation: R.annotation }, R));
o(T, { updated: S });
}, E = (v) => {
const T = r.get(v.annotation);
if (T) {
const S = {
...T,
target: {
...T.target,
...v
}
};
return r.set(T.id, S), {
oldValue: T,
newValue: S,
targetUpdated: {
oldTarget: T.target,
newTarget: v
}
};
} else
console.warn(`Attempt to update target on missing annotation: ${v.annotation}`);
};
return {
addAnnotation: s,
addBody: h,
all: u,
bulkAddAnnotation: c,
bulkDeleteAnnotation: f,
bulkUpdateBodies: x,
bulkUpdateTargets: (v, T = Ot.LOCAL) => {
const S = v.map(E).filter((R) => R);
S.length > 0 && o(T, { updated: S });
},
clear: l,
deleteAnnotation: d,
deleteBody: y,
getAnnotation: m,
getBody: _,
observe: i,
unobserve: n,
updateAnnotation: a,
updateBody: b,
updateTarget: (v, T = Ot.LOCAL) => {
const S = E(v);
S && o(T, { updated: [S] });
}
};
}, Bl = () => {
const { subscribe: r, set: e } = ys([]);
return {
subscribe: r,
set: e
};
}, Gl = (r, e, t, i, n, o) => {
const s = /* @__PURE__ */ new Map();
let a = [], h, u;
const l = (f, y) => {
s.has(f) ? s.get(f).push(y) : s.set(f, [y]);
}, c = (f, y) => {
const m = s.get(f);
m && m.indexOf(y) > 0 && m.splice(m.indexOf(y), 1);
}, p = (f, y, m) => {
s.has(f) && setTimeout(() => {
s.get(f).forEach((_) => {
if (n) {
const g = Array.isArray(y) ? y.map((x) => n.serialize(x)) : n.serialize(y), b = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
_(g, b);
} else
_(y, m);
});
}, 1);
}, d = () => {
const { selected: f } = e, y = f.map(({ id: m }) => r.getAnnotation(m));
y.forEach((m) => {
const _ = a.find((g) => g.id === m.id);
(!_ || !We(_, m)) && p("updateAnnotation", m, _);
}), a = a.map((m) => y.find(({ id: g }) => g === m.id) || m);
};
return e.subscribe(({ selected: f }) => {
if (!(a.length === 0 && f.length === 0)) {
if (a.length === 0 && f.length > 0)
a = f.map(({ id: y }) => r.getAnnotation(y));
else if (a.length > 0 && f.length === 0)
a.forEach((y) => {
const m = r.getAnnotation(y.id);
m && !We(m, y) && p("updateAnnotation", m, y);
}), a = [];
else {
const y = new Set(a.map((_) => _.id)), m = new Set(f.map(({ id: _ }) => _));
a.filter((_) => !m.has(_.id)).forEach((_) => {
const g = r.getAnnotation(_.id);
g && !We(g, _) && p("updateAnnotation", g, _);
}), a = [
// Remove annotations that were deselected
...a.filter((_) => m.has(_.id)),
// Add editable annotations that were selected
...f.filter(({ id: _ }) => !y.has(_)).map(({ id: _ }) => r.getAnnotation(_))
];
}
p("selectionChanged", a);
}
}), t.subscribe((f) => {
!h && f ? p("mouseEnterAnnotation", r.getAnnotation(f)) : h && !f ? p("mouseLeaveAnnotation", r.getAnnotation(h)) : h && f && (p("mouseLeaveAnnotation", r.getAnnotation(h)), p("mouseEnterAnnotation", r.getAnnotation(f))), h = f;
}), i == null || i.subscribe((f) => p("viewportIntersect", f.map(r.getAnnotation))), r.observe((f) => {
o && (u && clearTimeout(u), u = setTimeout(d, 1e3));
const { created: y, deleted: m } = f.changes;
y.forEach((_) => p("createAnnotation", _)), m.forEach((_) => p("deleteAnnotation", _)), f.changes.updated.filter((_) => [
..._.bodiesCreated || [],
..._.bodiesDeleted || [],
..._.bodiesUpdated || []
].length > 0).forEach(({ oldValue: _, newValue: g }) => {
const b = a.find((x) => x.id === _.id) || _;
a = a.map((x) => x.id === _.id ? g : x), p("updateAnnotation", g, b);
});
}, { origin: Ot.LOCAL }), r.observe((f) => {
if (a) {
const y = new Set(a.map((_) => _.id)), m = f.changes.updated.filter(({ newValue: _ }) => y.has(_.id)).map(({ newValue: _ }) => _);
m.length > 0 && (a = a.map((_) => m.find((b) => b.id === _.id) || _));
}
}, { origin: Ot.REMOTE }), { on: l, off: c, emit: p };
}, Ul = (r) => (e) => e.reduce((t, i) => {
const { parsed: n, error: o } = r.parse(i);
return o ? {
parsed: t.parsed,
failed: [...t.failed, i]
} : {
parsed: [...t.parsed, n],
failed: t.failed
};
}, { parsed: [], failed: [] }), kl = (r, e) => {
const t = (u) => {
if (e) {
const { parsed: l, error: c } = e.parse(u);
l ? r.addAnnotation(l, Ot.REMOTE) : console.error(c);
} else
r.addAnnotation(u, Ot.REMOTE);
}, i = () => r.clear(), n = (u) => {
const l = r.getAnnotation(u);
return e && l ? e.serialize(l) : l;
}, o = () => e ? r.all().map(e.serialize) : r.all(), s = (u) => fetch(u).then((l) => l.json()).then((l) => (h(l), l)), a = (u) => {
if (typeof u == "string") {
const l = r.getAnnotation(u);
return r.deleteAnnotation(u), e ? e.serialize(l) : l;
} else {
const l = e ? e.parse(u).parsed : u;
return r.deleteAnnotation(l), u;
}
}, h = (u) => {
if (e) {
const { parsed: l, failed: c } = Ul(e)(u);
c.length > 0 && console.warn(`Discarded ${c.length} invalid annotations`, c), r.bulkAddAnnotation(l, !0, Ot.REMOTE);
} else
r.bulkAddAnnotation(u, !0, Ot.REMOTE);
};
return {
addAnnotation: t,
clearAnnotations: i,
getAnnotationById: n,
getAnnotations: o,
loadAnnotations: s,
removeAnnotation: a,
setAnnotations: h,
updateAnnotation: (u) => {
if (e) {
const l = e.parse(u).parsed, c = e.serialize(r.getAnnotation(l.id));
return r.updateAnnotation(l), c;
} else {
const l = r.getAnnotation(u.id);
return r.updateAnnotation(u), l;
}
}
};
};
let Xl = (r) => crypto.getRandomValues(new Uint8Array(r)), jl = (r, e, t) => {
let i = (2 << Math.log(r.length - 1) / Math.LN2) - 1, n = -~(1.6 * i * e / r.length);
return (o = e) => {
let s = "";
for (; ; ) {
let a = t(n), h = n;
for (; h--; )
if (s += r[a[h] & i] || "", s.length === o)
return s;
}
};
}, Hl = (r, e = 21) => jl(r, e, Xl), Yl = (r = 21) => crypto.getRandomValues(new Uint8Array(r)).reduce((e, t) => (t &= 63, t < 36 ? e += t.toString(36) : t < 62 ? e += (t - 26).toString(36).toUpperCase() : t > 62 ? e += "-" : e += "_", e), "");
const Vl = () => ({ isGuest: !0, id: Hl("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() });
Yl();
var kt = /* @__PURE__ */ ((r) => (r.ELLIPSE = "ELLIPSE", r.POLYGON = "POLYGON", r.RECTANGLE = "RECTANGLE", r))(kt || {});
const ms = {}, _s = (r, e) => ms[r] = e, js = (r) => ms[r.type].area(r), zl = (r, e, t) => ms[r.type].intersects(r, e, t), bo = (r) => {
let e = 1 / 0, t = 1 / 0, i = -1 / 0, n = -1 / 0;
return r.forEach(([o, s]) => {
e = Math.min(e, o), t = Math.min(t, s), i = Math.max(i, o), n = Math.max(n, s);
}), { minX: e, minY: t, maxX: i, maxY: n };
}, Wl = {
area: (r) => Math.PI * r.geometry.rx * r.geometry.ry,
intersects: (r, e, t) => {
const { cx: i, cy: n, rx: o, ry: s } = r.geometry, a = 0, h = Math.cos(a), u = Math.sin(a), l = e - i, c = t - n, p = h * l + u * c, d = u * l - h * c;
return p * p / (o * o) + d * d / (s * s) <= 1;
}
};
_s(kt.ELLIPSE, Wl);
const $l = {
area: (r) => {
const { points: e } = r.geometry;
let t = 0, i = e.length - 1;
for (let n = 0; n < e.length; n++)
t += (e[i][0] + e[n][0]) * (e[i][1] - e[n][1]), i = n;
return Math.abs(0.5 * t);
},
intersects: (r, e, t) => {
const { points: i } = r.geometry;
let n = !1;
for (let o = 0, s = i.length - 1; o < i.length; s = o++) {
const a = i[o][0], h = i[o][1], u = i[s][0], l = i[s][1];
h > t != l > t && e < (u - a) * (t - h) / (l - h) + a && (n = !n);
}
return n;
}
};
_s(kt.POLYGON, $l);
const ql = {
area: (r) => r.geometry.w * r.geometry.h,
intersects: (r, e, t) => e >= r.geometry.x && e <= r.geometry.x + r.geometry.w && t >= r.geometry.y && t <= r.geometry.y + r.geometry.h
};
_s(kt.RECTANGLE, ql);
function Hs(r, e, t) {
const i = r.slice();
return i[11] = e[t], i[13] = t, i;
}
function Ys(r) {
let e, t, i, n, o;
return {
c() {
e = st("rect"), A(e, "class", "a9s-corner-handle"), A(e, "x", t = /*point*/
r[11][0] - /*handleSize*/
r[3] / 2), A(e, "y", i = /*point*/
r[11][1] - /*handleSize*/
r[3] / 2), A(
e,
"height",
/*handleSize*/
r[3]
), A(
e,
"width",
/*handleSize*/
r[3]
);
},
m(s, a) {
Y(s, e, a), n || (o = Ut(e, "pointerdown", function() {
Ft(
/*grab*/
r[10](j(
/*idx*/
r[13]
))
) && r[10](j(
/*idx*/
r[13]
)).apply(this, arguments);
}), n = !0);
},
p(s, a) {
r = s, a & /*geom, handleSize*/
24 && t !== (t = /*point*/
r[11][0] - /*handleSize*/
r[3] / 2) && A(e, "x", t), a & /*geom, handleSize*/
24 && i !== (i = /*point*/
r[11][1] - /*handleSize*/
r[3] / 2) && A(e, "y", i), a & /*handleSize*/
8 && A(
e,
"height",
/*handleSize*/
r[3]
), a & /*handleSize*/
8 && A(
e,
"width",
/*handleSize*/
r[3]
);
},
d(s) {
s && H(e), n = !1, o();
}
};
}
function Kl(r) {
let e, t, i, n, o, s, a, h, u, l, c = (
/*geom*/
r[4].points
), p = [];
for (let d = 0; d < c.length; d += 1)
p[d] = Ys(Hs(r, c, d));
return {
c() {
e = st("polygon"), n = Zt(), o = st("polygon"), a = Zt();
for (let d = 0; d < p.length; d += 1)
p[d].c();
h = Me(), A(e, "class", "a9s-outer"), A(e, "style", t = /*computedStyle*/
r[1] ? "display:none;" : void 0), A(e, "points", i = /*geom*/
r[4].points.map(Vs).join(" ")), A(o, "class", "a9s-inner a9s-shape-handle"), A(
o,
"style",
/*computedStyle*/
r[1]
), A(o, "points", s = /*geom*/
r[4].points.map(zs).join(" "));
},
m(d, f) {
Y(d, e, f), Y(d, n, f), Y(d, o, f), Y(d, a, f);
for (let y = 0; y < p.length; y += 1)
p[y] && p[y].m(d, f);
Y(d, h, f), u || (l = [
Ut(e, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.SHAPE)
) && r[10](j.SHAPE).apply(this, arguments);
}),
Ut(o, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.SHAPE)
) && r[10](j.SHAPE).apply(this, arguments);
})
], u = !0);
},
p(d, f) {
if (r = d, f & /*computedStyle*/
2 && t !== (t = /*computedStyle*/
r[1] ? "display:none;" : void 0) && A(e, "style", t), f & /*geom*/
16 && i !== (i = /*geom*/
r[4].points.map(Vs).join(" ")) && A(e, "points", i), f & /*computedStyle*/
2 && A(
o,
"style",
/*computedStyle*/
r[1]
), f & /*geom*/
16 && s !== (s = /*geom*/
r[4].points.map(zs).join(" ")) && A(o, "points", s), f & /*geom, handleSize, grab, Handle*/
1048) {
c = /*geom*/
r[4].points;
let y;
for (y = 0; y < c.length; y += 1) {
const m = Hs(r, c, y);
p[y] ? p[y].p(m, f) : (p[y] = Ys(m), p[y].c(), p[y].m(h.parentNode, h));
}
for (; y < p.length; y += 1)
p[y].d(1);
p.length = c.length;
}
},
d(d) {
d && H(e), d && H(n), d && H(o), d && H(a), ps(p, d), d && H(h), u = !1, Pe(l);
}
};
}
function Zl(r) {
let e, t;
return e = new Wh({
props: {
shape: (
/*shape*/
r[0]
),
transform: (
/*transform*/
r[2]
),
editor: (
/*editor*/
r[5]
),
$$slots: {
default: [
Kl,
({ grab: i }) => ({ 10: i }),
({ grab: i }) => i ? 1024 : 0
]
},
$$scope: { ctx: r }
}
}), e.$on(
"change",
/*change_handler*/
r[7]
), e.$on(
"grab",
/*grab_handler*/
r[8]
), e.$on(
"release",
/*release_handler*/
r[9]
), {
c() {
zt(e.$$.fragment);
},
m(i, n) {
Ht(e, i, n), t = !0;
},
p(i, [n]) {
const o = {};
n & /*shape*/
1 && (o.shape = /*shape*/
i[0]), n & /*transform*/
4 && (o.transform = /*transform*/
i[2]), n & /*$$scope, geom, handleSize, grab, computedStyle*/
17434 && (o.$$scope = { dirty: n, ctx: i }), e.$set(o);
},
i(i) {
t || (at(e.$$.fragment, i), t = !0);
},
o(i) {
ft(e.$$.fragment, i), t = !1;
},
d(i) {
Yt(e, i);
}
};
}
const Vs = (r) => r.join(","), zs = (r) => r.join(",");
function Jl(r, e, t) {
let i, n, { shape: o } = e, { computedStyle: s = void 0 } = e, { transform: a } = e, { viewportScale: h = 1 } = e;
const u = (d, f, y) => {
let m;
f === j.SHAPE ? m = d.geometry.points.map(([g, b]) => [g + y[0], b + y[1]]) : m = d.geometry.points.map(([g, b], x) => f === j(x) ? [g + y[0], b + y[1]] : [g, b]);
const _ = bo(m);
return { ...d, geometry: { points: m, bounds: _ } };
};
function l(d) {
vr.call(this, r, d);
}
function c(d) {
vr.call(this, r, d);
}
function p(d) {
vr.call(this, r, d);
}
return r.$$set = (d) => {
"shape" in d && t(0, o = d.shape), "computedStyle" in d && t(1, s = d.computedStyle), "transform" in d && t(2, a = d.transform), "viewportScale" in d && t(6, h = d.viewportScale);
}, r.$$.update = () => {
r.$$.dirty & /*shape*/
1 && t(4, i = o.geometry), r.$$.dirty & /*viewportScale*/
64 && t(3, n = 10 / h);
}, [
o,
s,
a,
n,
i,
u,
h,
l,
c,
p
];
}
class Ql extends $t {
constructor(e) {
super(), Wt(this, e, Jl, Zl, Vt, {
shape: 0,
computedStyle: 1,
transform: 2,
viewportScale: 6
});
}
}
function tc(r) {
let e, t, i, n, o, s, a, h, u, l, c, p, d, f, y, m, _, g, b, x, E, v, T, S, R, O, w, C, B, V, F, D, z, ot, K, M, I, X, Z, Q, mt, q, lt, vt, At, tt, nt, ht, pt, J;
return {
c() {
e = st("rect"), a = Zt(), h = st("rect"), d = Zt(), f = st("rect"), g = Zt(), b = st("rect"), T = Zt(), S = st("rect"), C = Zt(), B = st("rect"), z = Zt(), ot = st("rect"), I = Zt(), X = st("rect"), mt = Zt(), q = st("rect"), At = Zt(), tt = st("rect"), A(e, "class", "a9s-outer"), A(e, "style", t = /*computedStyle*/
r[1] ? "display:none;" : void 0), A(e, "x", i = /*geom*/
r[4].x), A(e, "y", n = /*geom*/
r[4].y), A(e, "width", o = /*geom*/
r[4].w), A(e, "height", s = /*geom*/
r[4].h), A(h, "class", "a9s-inner a9s-shape-handle"), A(
h,
"style",
/*computedStyle*/
r[1]
), A(h, "x", u = /*geom*/
r[4].x), A(h, "y", l = /*geom*/
r[4].y), A(h, "width", c = /*geom*/
r[4].w), A(h, "height", p = /*geom*/
r[4].h), A(f, "class", "a9s-edge-handle a9s-edge-handle-top"), A(f, "x", y = /*geom*/
r[4].x), A(f, "y", m = /*geom*/
r[4].y), A(f, "height", 1), A(f, "width", _ = /*geom*/
r[4].w), A(b, "class", "a9s-edge-handle a9s-edge-handle-right"), A(b, "x", x = /*geom*/
r[4].x + /*geom*/
r[4].w), A(b, "y", E = /*geom*/
r[4].y), A(b, "height", v = /*geom*/
r[4].h), A(b, "width", 1), A(S, "class", "a9s-edge-handle a9s-edge-handle-bottom"), A(S, "x", R = /*geom*/
r[4].x), A(S, "y", O = /*geom*/
r[4].y + /*geom*/
r[4].h), A(S, "height", 1), A(S, "width", w = /*geom*/
r[4].w), A(B, "class", "a9s-edge-handle a9s-edge-handle-left"), A(B, "x", V = /*geom*/
r[4].x), A(B, "y", F = /*geom*/
r[4].y), A(B, "height", D = /*geom*/
r[4].h), A(B, "width", 1), A(ot, "class", "a9s-corner-handle a9s-corner-handle-topleft"), A(ot, "x", K = /*geom*/
r[4].x - /*handleSize*/
r[3] / 2), A(ot, "y", M = /*geom*/
r[4].y - /*handleSize*/
r[3] / 2), A(
ot,
"height",
/*handleSize*/
r[3]
), A(
ot,
"width",
/*handleSize*/
r[3]
), A(X, "class", "a9s-corner-handle a9s-corner-handle-topright"), A(X, "x", Z = /*geom*/
r[4].x + /*geom*/
r[4].w - /*handleSize*/
r[3] / 2), A(X, "y", Q = /*geom*/
r[4].y - /*handleSize*/
r[3] / 2), A(
X,
"height",
/*handleSize*/
r[3]
), A(
X,
"width",
/*handleSize*/
r[3]
), A(q, "class", "a9s-corner-handle a9s-corner-handle-bottomright"), A(q, "x", lt = /*geom*/
r[4].x + /*geom*/
r[4].w - /*handleSize*/
r[3] / 2), A(q, "y", vt = /*geom*/
r[4].y + /*geom*/
r[4].h - /*handleSize*/
r[3] / 2), A(
q,
"height",
/*handleSize*/
r[3]
), A(
q,
"width",
/*handleSize*/
r[3]
), A(tt, "class", "a9s-corner-handle a9s-corner-handle-bottomleft"), A(tt, "x", nt = /*geom*/
r[4].x - /*handleSize*/
r[3] / 2), A(tt, "y", ht = /*geom*/
r[4].y + /*geom*/
r[4].h - /*handleSize*/
r[3] / 2), A(
tt,
"height",
/*handleSize*/
r[3]
), A(
tt,
"width",
/*handleSize*/
r[3]
);
},
m(G, N) {
Y(G, e, N), Y(G, a, N), Y(G, h, N), Y(G, d, N), Y(G, f, N), Y(G, g, N), Y(G, b, N), Y(G, T, N), Y(G, S, N), Y(G, C, N), Y(G, B, N), Y(G, z, N), Y(G, ot, N), Y(G, I, N), Y(G, X, N), Y(G, mt, N), Y(G, q, N), Y(G, At, N), Y(G, tt, N), pt || (J = [
Ut(e, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.SHAPE)
) && r[10](j.SHAPE).apply(this, arguments);
}),
Ut(h, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.SHAPE)
) && r[10](j.SHAPE).apply(this, arguments);
}),
Ut(f, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.TOP)
) && r[10](j.TOP).apply(this, arguments);
}),
Ut(b, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.RIGHT)
) && r[10](j.RIGHT).apply(this, arguments);
}),
Ut(S, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.BOTTOM)
) && r[10](j.BOTTOM).apply(this, arguments);
}),
Ut(B, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.LEFT)
) && r[10](j.LEFT).apply(this, arguments);
}),
Ut(ot, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.TOP_LEFT)
) && r[10](j.TOP_LEFT).apply(this, arguments);
}),
Ut(X, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.TOP_RIGHT)
) && r[10](j.TOP_RIGHT).apply(this, arguments);
}),
Ut(q, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.BOTTOM_RIGHT)
) && r[10](j.BOTTOM_RIGHT).apply(this, arguments);
}),
Ut(tt, "pointerdown", function() {
Ft(
/*grab*/
r[10](j.BOTTOM_LEFT)
) && r[10](j.BOTTOM_LEFT).apply(this, arguments);
})
], pt = !0);
},
p(G, N) {
r = G, N & /*computedStyle*/
2 && t !== (t = /*computedStyle*/
r[1] ? "display:none;" : void 0) && A(e, "style", t), N & /*geom*/
16 && i !== (i = /*geom*/
r[4].x) && A(e, "x", i), N & /*geom*/
16 && n !== (n = /*geom*/
r[4].y) && A(e, "y", n), N & /*geom*/
16 && o !== (o = /*geom*/
r[4].w) && A(e, "width", o), N & /*geom*/
16 && s !== (s = /*geom*/
r[4].h) && A(e, "height", s), N & /*computedStyle*/
2 && A(
h,
"style",
/*computedStyle*/
r[1]
), N & /*geom*/
16 && u !== (u = /*geom*/
r[4].x) && A(h, "x", u), N & /*geom*/
16 && l !== (l = /*geom*/
r[4].y) && A(h, "y", l), N & /*geom*/
16 && c !== (c = /*geom*/
r[4].w) && A(h, "width", c), N & /*geom*/
16 && p !== (p = /*geom*/
r[4].h) && A(h, "height", p), N & /*geom*/
16 && y !== (y = /*geom*/
r[4].x) && A(f, "x", y), N & /*geom*/
16 && m !== (m = /*geom*/
r[4].y) && A(f, "y", m), N & /*geom*/
16 && _ !== (_ = /*geom*/
r[4].w) && A(f, "width", _), N & /*geom*/
16 && x !== (x = /*geom*/
r[4].x + /*geom*/
r[4].w) && A(b, "x", x), N & /*geom*/
16 && E !== (E = /*geom*/
r[4].y) && A(b, "y", E), N & /*geom*/
16 && v !== (v = /*geom*/
r[4].h) && A(b, "height", v), N & /*geom*/
16 && R !== (R = /*geom*/
r[4].x) && A(S, "x", R), N & /*geom*/
16 && O !== (O = /*geom*/
r[4].y + /*geom*/
r[4].h) && A(S, "y", O), N & /*geom*/
16 && w !== (w = /*geom*/
r[4].w) && A(S, "width", w), N & /*geom*/
16 && V !== (V = /*geom*/
r[4].x) && A(B, "x", V), N & /*geom*/
16 && F !== (F = /*geom*/
r[4].y) && A(B, "y", F), N & /*geom*/
16 && D !== (D = /*geom*/
r[4].h) && A(B, "height", D), N & /*geom, handleSize*/
24 && K !== (K = /*geom*/
r[4].x - /*handleSize*/
r[3] / 2) && A(ot, "x", K), N & /*geom, handleSize*/
24 && M !== (M = /*geom*/
r[4].y - /*handleSize*/
r[3] / 2) && A(ot, "y", M), N & /*handleSize*/
8 && A(
ot,
"height",
/*handleSize*/
r[3]
), N & /*handleSize*/
8 && A(
ot,
"width",
/*handleSize*/
r[3]
), N & /*geom, handleSize*/
24 && Z !== (Z = /*geom*/
r[4].x + /*geom*/
r[4].w - /*handleSize*/
r[3] / 2) && A(X, "x", Z), N & /*geom, handleSize*/
24 && Q !== (Q = /*geom*/
r[4].y - /*handleSize*/
r[3] / 2) && A(X, "y", Q), N & /*handleSize*/
8 && A(
X,
"height",
/*handleSize*/
r[3]
), N & /*handleSize*/
8 && A(
X,
"width",
/*handleSize*/
r[3]
), N & /*geom, handleSize*/
24 && lt !== (lt = /*geom*/
r[4].x + /*geom*/
r[4].w - /*handleSize*/
r[3] / 2) && A(q, "x", lt), N & /*geom, handleSize*/
24 && vt !== (vt = /*geom*/
r[4].y + /*geom*/
r[4].h - /*handleSize*/
r[3] / 2) && A(q, "y", vt), N & /*handleSize*/
8 && A(
q,
"height",
/*handleSize*/
r[3]
), N & /*handleSize*/
8 && A(
q,
"width",
/*handleSize*/
r[3]
), N & /*geom, handleSize*/
24 && nt !== (nt = /*geom*/
r[4].x - /*handleSize*/
r[3] / 2) && A(tt, "x", nt), N & /*geom, handleSize*/
24 && ht !== (ht = /*geom*/
r[4].y + /*geom*/
r[4].h - /*handleSize*/
r[3] / 2) && A(tt, "y", ht), N & /*handleSize*/
8 && A(
tt,
"height",
/*handleSize*/
r[3]
), N & /*handleSize*/
8 && A(
tt,
"width",
/*handleSize*/
r[3]
);
},
d(G) {
G && H(e), G && H(a), G && H(h), G && H(d), G && H(f), G && H(g), G && H(b), G && H(T), G && H(S), G && H(C), G && H(B), G && H(z), G && H(ot), G && H(I), G && H(X), G && H(mt), G && H(q), G && H(At), G && H(tt), pt = !1, Pe(J);
}
};
}
function ec(r) {
let e, t;
return e = new Wh({
props: {
shape: (
/*shape*/
r[0]
),
transform: (
/*transform*/
r[2]
),
editor: (
/*editor*/
r[5]
),
$$slots: {
default: [
tc,
({ grab: i }) => ({ 10: i }),
({ grab: i }) => i ? 1024 : 0
]
},
$$scope: { ctx: r }
}
}), e.$on(
"grab",
/*grab_handler*/
r[7]
), e.$on(
"change",
/*change_handler*/
r[8]
), e.$on(
"release",
/*release_handler*/
r[9]
), {
c() {
zt(e.$$.fragment);
},
m(i, n) {
Ht(e, i, n), t = !0;
},
p(i, [n]) {
const o = {};
n & /*shape*/
1 && (o.shape = /*shape*/
i[0]), n & /*transform*/
4 && (o.transform = /*transform*/
i[2]), n & /*$$scope, geom, handleSize, grab, computedStyle*/
3098 && (o.$$scope = { dirty: n, ctx: i }), e.$set(o);
},
i(i) {
t || (at(e.$$.fragment, i), t = !0);
},
o(i) {
ft(e.$$.fragment, i), t = !1;
},
d(i) {
Yt(e, i);
}
};
}
function rc(r, e, t) {
let i, n, { shape: o } = e, { computedStyle: s = void 0 } = e, { transform: a } = e, { viewportScale: h = 1 } = e;
const u = (d, f, y) => {
const m = d.geometry.bounds;
let [_, g] = [m.minX, m.minY], [b, x] = [m.maxX, m.maxY];
const [E, v] = y;
if (f === j.SHAPE)
_ += E, b += E, g += v, x += v;
else {
switch (f) {
case j.TOP:
case j.TOP_LEFT:
case j.TOP_RIGHT: {
g += v;
break;
}
case j.BOTTOM:
case j.BOTTOM_LEFT:
case j.BOTTOM_RIGHT: {
x += v;
break;
}
}
switch (f) {
case j.LEFT:
case j.TOP_LEFT:
case j.BOTTOM_LEFT: {
_ += E;
break;
}
case j.RIGHT:
case j.TOP_RIGHT:
case j.BOTTOM_RIGHT: {
b += E;
break;
}
}
}
const T = Math.min(_, b), S = Math.min(g, x), R = Math.abs(b - _), O = Math.abs(x - g);
return {
...d,
geometry: {
x: T,
y: S,
w: R,
h: O,
bounds: {
minX: T,
minY: S,
maxX: T + R,
maxY: S + O
}
}
};
};
function l(d) {
vr.call(this, r, d);
}
function c(d) {
vr.call(this, r, d);
}
function p(d) {
vr.call(this, r, d);
}
return r.$$set = (d) => {
"shape" in d && t(0, o = d.shape), "computedStyle" in d && t(1, s = d.computedStyle), "transform" in d && t(2, a = d.transform), "viewportScale" in d && t(6, h = d.viewportScale);
}, r.$$.update = () => {
r.$$.dirty & /*shape*/
1 && t(4, i = o.geometry), r.$$.dirty & /*viewportScale*/
64 && t(3, n = 10 / h);
}, [
o,
s,
a,
n,
i,
u,
h,
l,
c,
p
];
}
class ic extends $t {
constructor(e) {
super(), Wt(this, e, rc, ec, Vt, {
shape: 0,
computedStyle: 1,
transform: 2,
viewportScale: 6
});
}
}
const nc = /* @__PURE__ */ new Map([
[kt.RECTANGLE, ic],
[kt.POLYGON, Ql]
]), Ws = (r) => nc.get(r.type), j = (r) => `HANDLE-${r}`;
j.SHAPE = "SHAPE";
j.TOP = "TOP";
j.RIGHT = "RIGHT";
j.BOTTOM = "BOTTOM";
j.LEFT = "LEFT";
j.TOP_LEFT = "TOP_LEFT";
j.TOP_RIGHT = "TOP_RIGHT";
j.BOTTOM_RIGHT = "BOTTOM_RIGHT";
j.BOTTOM_LEFT = "BOTTOM_LEFT";
const oc = (r) => ({}), $s = (r) => ({ grab: (
/*onGrab*/
r[0]
) });
function sc(r) {
let e, t, i, n;
const o = (
/*#slots*/
r[7].default
), s = Uh(
o,
r,
/*$$scope*/
r[6],
$s
);
return {
c() {
e = st("g"), s && s.c(), A(e, "class", "a9s-annotation selected");
},
m(a, h) {
Y(a, e, h), s && s.m(e, null), t = !0, i || (n = [
Ut(
e,
"pointerup",
/*onRelease*/
r[2]
),
Ut(
e,
"pointermove",
/*onPointerMove*/
r[1]
)
], i = !0);
},
p(a, [h]) {
s && s.p && (!t || h & /*$$scope*/
64) && jh(
s,
o,
a,
/*$$scope*/
a[6],
t ? Xh(
o,
/*$$scope*/
a[6],
h,
oc
) : Hh(
/*$$scope*/
a[6]
),
$s
);
},
i(a) {
t || (at(s, a), t = !0);
},
o(a) {
ft(s, a), t = !1;
},
d(a) {
a && H(e), s && s.d(a), i = !1, Pe(n);
}
};
}
function ac(r, e, t) {
let { $$slots: i = {}, $$scope: n } = e;
const o = _n();
let { shape: s } = e, { editor: a } = e, { transform: h } = e, u = null, l, c = null;
const p = (y) => (m) => {
u = y, l = h.elementToImage(m.offsetX, m.offsetY), c = s, m.target.setPointerCapture(m.pointerId), o("grab");
}, d = (y) => {
if (u) {
const [m, _] = h.elementToImage(y.offsetX, y.offsetY), g = [m - l[0], _ - l[1]];
t(3, s = a(c, u, g)), o("change", s);
}
}, f = (y) => {
y.target.releasePointerCapture(y.pointerId), u = null, c = s, o("release");
};
return r.$$set = (y) => {
"shape" in y && t(3, s = y.shape), "editor" in y && t(4, a = y.editor), "transform" in y && t(5, h = y.transform), "$$scope" in y && t(6, n = y.$$scope);
}, [p, d, f, s, a, h, n, i];
}
class Wh extends $t {
constructor(e) {
super(), Wt(this, e, ac, sc, Vt, { shape: 3, editor: 4, transform: 5 });
}
}
function qs(r) {
let e, t;
return {
c() {
e = st("rect"), t = st("rect"), A(e, "class", "a9s-outer"), A(
e,
"x",
/*x*/
r[2]
), A(
e,
"y",
/*y*/
r[3]
), A(
e,
"width",
/*w*/
r[4]
), A(
e,
"height",
/*h*/
r[5]
), A(t, "class", "a9s-inner"), A(
t,
"x",
/*x*/
r[2]
), A(
t,
"y",
/*y*/
r[3]
), A(
t,
"width",
/*w*/
r[4]
), A(
t,
"height",
/*h*/
r[5]
);
},
m(i, n) {
Y(i, e, n), Y(i, t, n);
},
p(i, n) {
n & /*x*/
4 && A(
e,
"x",
/*x*/
i[2]
), n & /*y*/
8 && A(
e,
"y",
/*y*/
i[3]
), n & /*w*/
16 && A(
e,
"width",
/*w*/
i[4]
), n & /*h*/
32 && A(
e,
"height",
/*h*/
i[5]
), n & /*x*/
4 && A(
t,
"x",
/*x*/
i[2]
), n & /*y*/
8 && A(
t,
"y",
/*y*/
i[3]
), n & /*w*/
16 && A(
t,
"width",
/*w*/
i[4]
), n & /*h*/
32 && A(
t,
"height",
/*h*/
i[5]
);
},
d(i) {
i && H(e), i && H(t);
}
};
}
function hc(r) {
let e, t = (
/*origin*/
r[1] && qs(r)
);
return {
c() {
e = st("g"), t && t.c(), A(e, "class", "a9s-annotation a9s-rubberband");
},
m(i, n) {
Y(i, e, n), t && t.m(e, null), r[7](e);
},
p(i, [n]) {
i[1] ? t ? t.p(i, n) : (t = qs(i), t.c(), t.m(e, null)) : t && (t.d(1), t = null);
},
i: jt,
o: jt,
d(i) {
i && H(e), t && t.d(), r[7](null);
}
};
}
function uc(r, e, t) {
const i = _n();
let { transform: n } = e, o, s, a, h, u, l, c;
const p = (m) => {
t(1, s = n.elementToImage(m.offsetX, m.offsetY)), a = s, t(2, h = s[0]), t(3, u = s[1]), t(4, l = 1), t(5, c = 1);
}, d = (m) => {
s && (a = n.elementToImage(m.offsetX, m.offsetY), t(2, h = Math.min(a[0], s[0])), t(3, u = Math.min(a[1], s[1])), t(4, l = Math.abs(a[0] - s[0])), t(5, c = Math.abs(a[1] - s[1])));
}, f = () => {
if (l * c > 15) {
const m = {
type: kt.RECTANGLE,
geometry: {
bounds: {
minX: h,
minY: u,
maxX: h + l,
maxY: u + c
},
x: h,
y: u,
w: l,
h: c
}
};
i("create", m);
}
t(1, s = null), a = null;
};
mn(() => {
const m = o.closest("svg");
return m.addEventListener("pointerdown", p), m.addEventListener("pointermove", d), m.addEventListener("pointerup", f), () => {
m.removeEventListener("pointerdown", p), m.removeEventListener("pointermove", d), m.removeEventListener("pointerup", f);
};
});
function y(m) {
Zr