@recogito/annotorious
Version:
A JavaScript image annotation library
1,743 lines • 97.6 kB
JavaScript
function N() {
}
function We(t, e) {
for (const n in e)
t[n] = e[n];
return t;
}
function Xe(t) {
return t();
}
function ie() {
return /* @__PURE__ */ Object.create(null);
}
function ot(t) {
t.forEach(Xe);
}
function U(t) {
return typeof t == "function";
}
function z(t, e) {
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
}
function qe(t) {
return Object.keys(t).length === 0;
}
function Pe(t, ...e) {
if (t == null)
return N;
const n = t.subscribe(...e);
return n.unsubscribe ? () => n.unsubscribe() : n;
}
function se(t, e, n) {
t.$$.on_destroy.push(Pe(e, n));
}
function Je(t, e, n, o) {
if (t) {
const r = Se(t, e, n, o);
return t[0](r);
}
}
function Se(t, e, n, o) {
return t[1] && o ? We(n.ctx.slice(), t[1](o(e))) : n.ctx;
}
function ke(t, e, n, o) {
if (t[2] && o) {
const r = t[2](o(n));
if (e.dirty === void 0)
return r;
if (typeof r == "object") {
const i = [], s = Math.max(e.dirty.length, r.length);
for (let a = 0; a < s; a += 1)
i[a] = e.dirty[a] | r[a];
return i;
}
return e.dirty | r;
}
return e.dirty;
}
function Ke(t, e, n, o, r, i) {
if (r) {
const s = Se(e, n, o, i);
t.p(s, r);
}
}
function Qe(t) {
if (t.ctx.length > 32) {
const e = [], n = t.ctx.length / 32;
for (let o = 0; o < n; o++)
e[o] = -1;
return e;
}
return -1;
}
function st(t, e) {
t.appendChild(e);
}
function O(t, e, n) {
t.insertBefore(e, n || null);
}
function T(t) {
t.parentNode && t.parentNode.removeChild(t);
}
function ee(t, e) {
for (let n = 0; n < t.length; n += 1)
t[n] && t[n].d(e);
}
function _(t) {
return document.createElementNS("http://www.w3.org/2000/svg", t);
}
function Ce(t) {
return document.createTextNode(t);
}
function K() {
return Ce(" ");
}
function rt() {
return Ce("");
}
function j(t, e, n, o) {
return t.addEventListener(e, n, o), () => t.removeEventListener(e, n, o);
}
function d(t, e, n) {
n == null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n);
}
function Ze(t) {
return Array.from(t.childNodes);
}
function ae(t, e, n) {
t.classList[n ? "add" : "remove"](e);
}
function tn(t, e, { bubbles: n = !1, cancelable: o = !1 } = {}) {
const r = document.createEvent("CustomEvent");
return r.initCustomEvent(t, n, o, e), r;
}
let Tt;
function At(t) {
Tt = t;
}
function Re() {
if (!Tt)
throw new Error("Function called outside component initialization");
return Tt;
}
function Ot(t) {
Re().$$.on_mount.push(t);
}
function wt() {
const t = Re();
return (e, n, { cancelable: o = !1 } = {}) => {
const r = t.$$.callbacks[e];
if (r) {
const i = tn(e, n, { cancelable: o });
return r.slice().forEach((s) => {
s.call(t, i);
}), !i.defaultPrevented;
}
return !0;
};
}
function yt(t, e) {
const n = t.$$.callbacks[e.type];
n && n.slice().forEach((o) => o.call(this, e));
}
const mt = [], xt = [];
let $t = [];
const le = [], en = /* @__PURE__ */ Promise.resolve();
let Zt = !1;
function nn() {
Zt || (Zt = !0, en.then(Ge));
}
function te(t) {
$t.push(t);
}
const Wt = /* @__PURE__ */ new Set();
let ht = 0;
function Ge() {
if (ht !== 0)
return;
const t = Tt;
do {
try {
for (; ht < mt.length; ) {
const e = mt[ht];
ht++, At(e), on(e.$$);
}
} catch (e) {
throw mt.length = 0, ht = 0, e;
}
for (At(null), mt.length = 0, ht = 0; xt.length; )
xt.pop()();
for (let e = 0; e < $t.length; e += 1) {
const n = $t[e];
Wt.has(n) || (Wt.add(n), n());
}
$t.length = 0;
} while (mt.length);
for (; le.length; )
le.pop()();
Zt = !1, Wt.clear(), At(t);
}
function on(t) {
if (t.fragment !== null) {
t.update(), ot(t.before_update);
const e = t.dirty;
t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(te);
}
}
function rn(t) {
const e = [], n = [];
$t.forEach((o) => t.indexOf(o) === -1 ? e.push(o) : n.push(o)), n.forEach((o) => o()), $t = e;
}
const Gt = /* @__PURE__ */ new Set();
let ct;
function et() {
ct = {
r: 0,
c: [],
p: ct
// parent group
};
}
function nt() {
ct.r || ot(ct.c), ct = ct.p;
}
function P(t, e) {
t && t.i && (Gt.delete(t), t.i(e));
}
function R(t, e, n, o) {
if (t && t.o) {
if (Gt.has(t))
return;
Gt.add(t), ct.c.push(() => {
Gt.delete(t), o && (n && t.d(1), o());
}), t.o(e);
} else
o && o();
}
function ut(t) {
t && t.c();
}
function at(t, e, n, o) {
const { fragment: r, after_update: i } = t.$$;
r && r.m(e, n), o || te(() => {
const s = t.$$.on_mount.map(Xe).filter(U);
t.$$.on_destroy ? t.$$.on_destroy.push(...s) : ot(s), t.$$.on_mount = [];
}), i.forEach(te);
}
function lt(t, e) {
const n = t.$$;
n.fragment !== null && (rn(n.after_update), ot(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []);
}
function sn(t, e) {
t.$$.dirty[0] === -1 && (mt.push(t), nn(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31;
}
function Q(t, e, n, o, r, i, s, a = [-1]) {
const l = Tt;
At(t);
const c = t.$$ = {
fragment: null,
ctx: [],
// state
props: i,
update: N,
not_equal: r,
bound: ie(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(e.context || (l ? l.$$.context : [])),
// everything else
callbacks: ie(),
dirty: a,
skip_bound: !1,
root: e.target || l.$$.root
};
s && s(c.root);
let h = !1;
if (c.ctx = n ? n(t, e.props || {}, (u, f, ...p) => {
const g = p.length ? p[0] : f;
return c.ctx && r(c.ctx[u], c.ctx[u] = g) && (!c.skip_bound && c.bound[u] && c.bound[u](g), h && sn(t, u)), f;
}) : [], c.update(), h = !0, ot(c.before_update), c.fragment = o ? o(c.ctx) : !1, e.target) {
if (e.hydrate) {
const u = Ze(e.target);
c.fragment && c.fragment.l(u), u.forEach(T);
} else
c.fragment && c.fragment.c();
e.intro && P(t.$$.fragment), at(t, e.target, e.anchor, e.customElement), Ge();
}
At(l);
}
class Z {
$destroy() {
lt(this, 1), this.$destroy = N;
}
$on(e, n) {
if (!U(n))
return N;
const o = this.$$.callbacks[e] || (this.$$.callbacks[e] = []);
return o.push(n), () => {
const r = o.indexOf(n);
r !== -1 && o.splice(r, 1);
};
}
$set(e) {
this.$$set && !qe(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1);
}
}
var F = /* @__PURE__ */ ((t) => (t.ELLIPSE = "ELLIPSE", t.POLYGON = "POLYGON", t.RECTANGLE = "RECTANGLE", t))(F || {});
const ne = {}, oe = (t, e) => ne[t] = e, ce = (t) => ne[t.type].area(t), an = (t, e, n) => ne[t.type].intersects(t, e, n), Nt = (t) => {
let e = 1 / 0, n = 1 / 0, o = -1 / 0, r = -1 / 0;
return t.forEach(([i, s]) => {
e = Math.min(e, i), n = Math.min(n, s), o = Math.max(o, i), r = Math.max(r, s);
}), { minX: e, minY: n, maxX: o, maxY: r };
}, ln = {
area: (t) => Math.PI * t.geometry.rx * t.geometry.ry,
intersects: (t, e, n) => {
const { cx: o, cy: r, rx: i, ry: s } = t.geometry, a = 0, l = Math.cos(a), c = Math.sin(a), h = e - o, u = n - r, f = l * h + c * u, p = c * h - l * u;
return f * f / (i * i) + p * p / (s * s) <= 1;
}
};
oe(F.ELLIPSE, ln);
const cn = {
area: (t) => {
const { points: e } = t.geometry;
let n = 0, o = e.length - 1;
for (let r = 0; r < e.length; r++)
n += (e[o][0] + e[r][0]) * (e[o][1] - e[r][1]), o = r;
return Math.abs(0.5 * n);
},
intersects: (t, e, n) => {
const { points: o } = t.geometry;
let r = !1;
for (let i = 0, s = o.length - 1; i < o.length; s = i++) {
const a = o[i][0], l = o[i][1], c = o[s][0], h = o[s][1];
l > n != h > n && e < (c - a) * (n - l) / (h - l) + a && (r = !r);
}
return r;
}
};
oe(F.POLYGON, cn);
const dn = {
area: (t) => t.geometry.w * t.geometry.h,
intersects: (t, e, n) => e >= t.geometry.x && e <= t.geometry.x + t.geometry.w && n >= t.geometry.y && n <= t.geometry.y + t.geometry.h
};
oe(F.RECTANGLE, dn);
const un = (t, e = !1) => {
const n = typeof t == "string" ? t : t.value, o = /^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g, r = [...n.matchAll(o)][0], [i, s, a, l, c, h, u] = r;
if (s !== "xywh")
throw new Error("Unsupported MediaFragment: " + n);
if (a && a !== "pixel")
throw new Error(`Unsupported MediaFragment unit: ${a}`);
const [f, p, g, $] = [l, c, h, u].map(parseFloat);
return {
type: F.RECTANGLE,
geometry: {
x: f,
y: p,
w: g,
h: $,
bounds: {
minX: f,
minY: e ? p - $ : p,
maxX: f + g,
maxY: e ? p : p + $
}
}
};
}, hn = (t) => {
const { x: e, y: n, w: o, h: r } = t;
return {
type: "FragmentSelector",
conformsTo: "http://www.w3.org/TR/media-frags/",
value: `xywh=pixel:${e},${n},${o},${r}`
};
}, Ne = "http://www.w3.org/2000/svg", de = (t) => {
const e = (o) => {
Array.from(o.attributes).forEach((r) => {
r.name.startsWith("on") && o.removeAttribute(r.name);
});
}, n = t.getElementsByTagName("script");
return Array.from(n).reverse().forEach((o) => o.parentNode.removeChild(o)), Array.from(t.querySelectorAll("*")).forEach(e), t;
}, pn = (t) => {
const e = new XMLSerializer().serializeToString(t.documentElement).replace("<svg>", `<svg xmlns="${Ne}">`);
return new DOMParser().parseFromString(e, "image/svg+xml").documentElement;
}, fn = (t) => {
const e = new DOMParser().parseFromString(t, "image/svg+xml"), n = e.lookupPrefix(Ne), o = e.lookupNamespaceURI(null);
return n || o ? de(e).firstChild : de(pn(e)).firstChild;
}, mn = (t) => {
const [e, n, o] = t.match(/(<polygon points=["|'])([^("|')]*)/) || [];
if (!o)
return;
const r = o.split(" ").map((i) => i.split(",").map(parseFloat));
return {
type: F.POLYGON,
geometry: {
points: r,
bounds: Nt(r)
}
};
}, gn = (t) => {
const e = fn(t), n = parseFloat(e.getAttribute("cx")), o = parseFloat(e.getAttribute("cy")), r = parseFloat(e.getAttribute("rx")), i = parseFloat(e.getAttribute("ry")), s = {
minX: n - r,
minY: o - i,
maxX: n + r,
maxY: o + i
};
return {
type: F.ELLIPSE,
geometry: {
cx: n,
cy: o,
rx: r,
ry: i,
bounds: s
}
};
}, yn = (t) => {
const e = typeof t == "string" ? t : t.value;
if (e.includes("<polygon points="))
return mn(e);
if (e.includes("<ellipse "))
return gn(e);
}, $n = (t) => {
let e;
if (t.type === F.POLYGON) {
const n = t.geometry, { points: o } = n;
e = `<svg><polygon points="${o.map((r) => r.join(",")).join(" ")}" /></svg>`;
} else if (t.type === F.ELLIPSE) {
const n = t.geometry;
e = `<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;
}
if (e)
return { type: "SvgSelector", value: e };
throw `Unsupported shape type: ${t.type}`;
};
let St;
const xn = new Uint8Array(16);
function wn() {
if (!St && (St = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !St))
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
return St(xn);
}
const V = [];
for (let t = 0; t < 256; ++t)
V.push((t + 256).toString(16).slice(1));
function bn(t, e = 0) {
return V[t[e + 0]] + V[t[e + 1]] + V[t[e + 2]] + V[t[e + 3]] + "-" + V[t[e + 4]] + V[t[e + 5]] + "-" + V[t[e + 6]] + V[t[e + 7]] + "-" + V[t[e + 8]] + V[t[e + 9]] + "-" + V[t[e + 10]] + V[t[e + 11]] + V[t[e + 12]] + V[t[e + 13]] + V[t[e + 14]] + V[t[e + 15]];
}
const vn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ue = {
randomUUID: vn
};
function He(t, e, n) {
if (ue.randomUUID && !e && !t)
return ue.randomUUID();
t = t || {};
const o = t.random || (t.rng || wn)();
if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, e) {
n = n || 0;
for (let r = 0; r < 16; ++r)
e[n + r] = o[r];
return e;
}
return bn(o);
}
var he = Object.prototype.hasOwnProperty;
function dt(t, e) {
var n, o;
if (t === e)
return !0;
if (t && e && (n = t.constructor) === e.constructor) {
if (n === Date)
return t.getTime() === e.getTime();
if (n === RegExp)
return t.toString() === e.toString();
if (n === Array) {
if ((o = t.length) === e.length)
for (; o-- && dt(t[o], e[o]); )
;
return o === -1;
}
if (!n || typeof t == "object") {
o = 0;
for (n in t)
if (he.call(t, n) && ++o && !he.call(e, n) || !(n in e) || !dt(t[n], e[n]))
return !1;
return Object.keys(e).length === o;
}
}
return t !== t && e !== e;
}
const pt = [];
function Ht(t, e = N) {
let n;
const o = /* @__PURE__ */ new Set();
function r(a) {
if (z(t, a) && (t = a, n)) {
const l = !pt.length;
for (const c of o)
c[1](), pt.push(c, t);
if (l) {
for (let c = 0; c < pt.length; c += 2)
pt[c][0](pt[c + 1]);
pt.length = 0;
}
}
}
function i(a) {
r(a(t));
}
function s(a, l = N) {
const c = [a, l];
return o.add(c), o.size === 1 && (n = e(r) || N), a(t), () => {
o.delete(c), o.size === 0 && n && (n(), n = null);
};
}
return { set: r, update: i, subscribe: s };
}
const En = (t) => {
const { subscribe: e, set: n } = Ht(null);
let o = null;
return e((r) => o = r), t.observe(({ changes: r }) => {
if (o) {
r.deleted.some((s) => s.id === o) && n(null);
const i = r.updated.find(({ oldValue: s }) => s.id === o);
i && n(i.newValue.id);
}
}), {
get current() {
return o;
},
subscribe: e,
set: n
};
};
var Fe = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.HIGHLIGHT = "HIGHLIGHT", t.NONE = "NONE", t))(Fe || {});
const qt = { selected: [] }, An = (t, e = "EDIT") => {
const { subscribe: n, set: o } = Ht(qt);
let r = qt;
n((u) => r = u);
const i = () => o(qt), s = () => {
var u;
return ((u = r.selected) == null ? void 0 : u.length) === 0;
}, a = (u) => {
if (r.selected.length === 0)
return !1;
const f = typeof u == "string" ? u : u.id;
return r.selected.some((p) => p.id === f);
}, l = (u, f) => {
const p = t.getAnnotation(u);
if (p) {
const g = Tn(p, e);
o(g === "EDIT" ? { selected: [{ id: u, editable: !0 }], pointerEvent: f } : g === "HIGHLIGHT" ? { selected: [{ id: u }], pointerEvent: f } : { selected: [], pointerEvent: f });
} else
console.warn("Invalid selection: " + u);
}, c = (u, f = !0) => {
const p = Array.isArray(u) ? u : [u], g = p.map(($) => t.getAnnotation($)).filter(($) => $);
o({ selected: g.map(({ id: $ }) => ({ id: $, editable: f })) }), g.length !== p.length && console.warn("Invalid selection", u);
}, h = (u) => {
if (r.selected.length === 0)
return !1;
const { selected: f } = r;
f.filter(({ id: p }) => u.includes(p)).length > 0 && o({ selected: f.filter(({ id: p }) => !u.includes(p)) });
};
return t.observe(({ changes: u }) => h(u.deleted.map((f) => f.id))), {
clear: i,
clickSelect: l,
get selected() {
return r ? [...r.selected] : null;
},
get pointerEvent() {
return r ? r.pointerEvent : null;
},
isEmpty: s,
isSelected: a,
setSelected: c,
subscribe: n
};
}, Tn = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT", On = (t, e) => {
const n = new Set(t.bodies.map((o) => o.id));
return e.bodies.filter((o) => !n.has(o.id));
}, Mn = (t, e) => {
const n = new Set(e.bodies.map((o) => o.id));
return t.bodies.filter((o) => !n.has(o.id));
}, Ln = (t, e) => e.bodies.map((n) => {
const o = t.bodies.find((r) => r.id === n.id);
return { newBody: n, oldBody: o && !dt(o, n) ? o : void 0 };
}).filter(({ oldBody: n }) => n), Yn = (t, e) => !dt(t.target, e.target), Bn = (t, e) => ({
oldValue: t,
newValue: e,
bodiesCreated: On(t, e),
bodiesDeleted: Mn(t, e),
bodiesUpdated: Ln(t, e),
targetUpdated: Yn(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
});
var H = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(H || {});
const In = (t, e) => {
var n, o;
const { changes: r, origin: i } = e;
if (!(!t.options.origin || t.options.origin === i))
return !1;
if (t.options.ignore) {
const { ignore: s } = t.options, a = (l) => (l == null ? void 0 : l.length) > 0;
if (!(a(r.created) || a(r.deleted))) {
const l = (n = r.updated) == null ? void 0 : n.some((h) => a(h.bodiesCreated) || a(h.bodiesDeleted) || a(h.bodiesUpdated)), c = (o = r.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
if (s === "BODY_ONLY" && l && !c || s === "TARGET_ONLY" && c && !l)
return !1;
}
}
if (t.options.annotations) {
const s = /* @__PURE__ */ new Set([
...r.created.map((a) => a.id),
...r.deleted.map((a) => a.id),
...r.updated.map(({ oldValue: a }) => a.id)
]);
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((a) => s.has(a));
} else
return !0;
}, _n = (t) => t.id !== void 0, Xn = () => {
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (y, b = {}) => n.push({ onChange: y, options: b }), r = (y) => {
const b = n.findIndex((w) => w.onChange == y);
b > -1 && n.splice(b, 1);
}, i = (y, b) => {
const w = {
origin: y,
changes: {
created: b.created || [],
updated: b.updated || [],
deleted: b.deleted || []
},
state: [...t.values()]
};
n.forEach((A) => {
In(A, w) && A.onChange(w);
});
}, s = (y, b = H.LOCAL) => {
if (t.get(y.id))
throw Error(`Cannot add annotation ${y.id} - exists already`);
t.set(y.id, y), y.bodies.forEach((w) => e.set(w.id, y.id)), i(b, { created: [y] });
}, a = (y, b = H.LOCAL, w = H.LOCAL) => {
const A = _n(b) ? w : b, M = typeof y == "string" ? b : y, S = typeof y == "string" ? y : y.id, B = t.get(S);
if (B) {
const C = Bn(B, M);
S === M.id ? t.set(S, M) : (t.delete(S), t.set(M.id, M)), B.bodies.forEach((G) => e.delete(G.id)), M.bodies.forEach((G) => e.set(G.id, M.id)), i(A, { updated: [C] });
} else
throw Error(`Cannot update annotation ${S} - does not exist`);
}, l = (y, b = H.LOCAL) => {
const w = t.get(y.annotation);
if (w) {
const A = {
...w,
bodies: [...w.bodies, y]
};
t.set(w.id, A), e.set(y.id, A.id), i(b, { updated: [{
oldValue: w,
newValue: A,
bodiesCreated: [y]
}] });
} else
console.warn(`Attempt to add body to missing annotation: ${y.annotation}`);
}, c = () => [...t.values()], h = (y = H.LOCAL) => {
const b = [...t.values()];
t.clear(), e.clear(), i(y, { deleted: b });
}, u = (y, b = !0, w = H.LOCAL) => {
if (b) {
const A = [...t.values()];
t.clear(), e.clear(), y.forEach((M) => {
t.set(M.id, M), M.bodies.forEach((S) => e.set(S.id, M.id));
}), i(w, { created: y, deleted: A });
} else {
const A = y.reduce((M, S) => {
const B = t.get(S.id);
return B ? [...M, B] : M;
}, []);
if (A.length > 0)
throw Error(`Bulk insert would overwrite the following annotations: ${A.map((M) => M.id).join(", ")}`);
y.forEach((M) => {
t.set(M.id, M), M.bodies.forEach((S) => e.set(S.id, M.id));
}), i(w, { created: y });
}
}, f = (y) => {
const b = typeof y == "string" ? y : y.id, w = t.get(b);
if (w)
return t.delete(b), w.bodies.forEach((A) => e.delete(A.id)), w;
console.warn(`Attempt to delete missing annotation: ${b}`);
}, p = (y, b = H.LOCAL) => {
const w = f(y);
w && i(b, { deleted: [w] });
}, g = (y, b = H.LOCAL) => {
const w = y.reduce((A, M) => {
const S = f(M);
return S ? [...A, S] : A;
}, []);
w.length > 0 && i(b, { deleted: w });
}, $ = (y, b = H.LOCAL) => {
const w = t.get(y.annotation);
if (w) {
const A = w.bodies.find((M) => M.id === y.id);
if (A) {
e.delete(A.id);
const M = {
...w,
bodies: w.bodies.filter((S) => S.id !== y.id)
};
t.set(w.id, M), i(b, { updated: [{
oldValue: w,
newValue: M,
bodiesDeleted: [A]
}] });
} else
console.warn(`Attempt to delete missing body ${y.id} from annotation ${y.annotation}`);
} else
console.warn(`Attempt to delete body from missing annotation ${y.annotation}`);
}, m = (y) => {
const b = t.get(y);
return b ? { ...b } : void 0;
}, x = (y) => {
const b = e.get(y);
if (b) {
const w = m(b).bodies.find((A) => A.id === y);
if (w)
return w;
console.error(`Store integrity error: body ${y} in index, but not in annotation`);
} else
console.warn(`Attempt to retrieve missing body: ${y}`);
}, Y = (y, b) => {
if (y.annotation !== b.annotation)
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
const w = t.get(y.annotation);
if (w) {
const A = w.bodies.find((S) => S.id === y.id), M = {
...w,
bodies: w.bodies.map((S) => S.id === A.id ? b : S)
};
return t.set(w.id, M), A.id !== b.id && (e.delete(A.id), e.set(b.id, M.id)), {
oldValue: w,
newValue: M,
bodiesUpdated: [{ oldBody: A, newBody: b }]
};
} else
console.warn(`Attempt to add body to missing annotation ${y.annotation}`);
}, I = (y, b, w = H.LOCAL) => {
const A = Y(y, b);
i(w, { updated: [A] });
}, X = (y, b = H.LOCAL) => {
const w = y.map((A) => Y({ id: A.id, annotation: A.annotation }, A));
i(b, { updated: w });
}, D = (y) => {
const b = t.get(y.annotation);
if (b) {
const w = {
...b,
target: {
...b.target,
...y
}
};
return t.set(b.id, w), {
oldValue: b,
newValue: w,
targetUpdated: {
oldTarget: b.target,
newTarget: y
}
};
} else
console.warn(`Attempt to update target on missing annotation: ${y.annotation}`);
};
return {
addAnnotation: s,
addBody: l,
all: c,
bulkAddAnnotation: u,
bulkDeleteAnnotation: g,
bulkUpdateBodies: X,
bulkUpdateTargets: (y, b = H.LOCAL) => {
const w = y.map(D).filter((A) => A);
w.length > 0 && i(b, { updated: w });
},
clear: h,
deleteAnnotation: p,
deleteBody: $,
getAnnotation: m,
getBody: x,
observe: o,
unobserve: r,
updateAnnotation: a,
updateBody: I,
updateTarget: (y, b = H.LOCAL) => {
const w = D(y);
w && i(b, { updated: [w] });
}
};
}, Pn = (t) => ({
...t,
subscribe: (e) => {
const n = (o) => e(o.state);
return t.observe(n), e(t.all()), () => t.unobserve(n);
}
}), Sn = () => {
const { subscribe: t, set: e } = Ht([]);
return {
subscribe: t,
set: e
};
}, Cn = (t, e, n, o, r, i) => {
const s = /* @__PURE__ */ new Map();
let a = [], l, c;
const h = (g, $) => {
s.has(g) ? s.get(g).push($) : s.set(g, [$]);
}, u = (g, $) => {
const m = s.get(g);
m && m.indexOf($) > 0 && m.splice(m.indexOf($), 1);
}, f = (g, $, m) => {
s.has(g) && setTimeout(() => {
s.get(g).forEach((x) => {
if (r) {
const Y = Array.isArray($) ? $.map((X) => r.serialize(X)) : r.serialize($), I = m ? m instanceof PointerEvent ? m : r.serialize(m) : void 0;
x(Y, I);
} else
x($, m);
});
}, 1);
}, p = () => {
const { selected: g } = e, $ = g.map(({ id: m }) => t.getAnnotation(m));
$.forEach((m) => {
const x = a.find((Y) => Y.id === m.id);
(!x || !dt(x, m)) && f("updateAnnotation", m, x);
}), a = a.map((m) => $.find(({ id: Y }) => Y === m.id) || m);
};
return e.subscribe(({ selected: g }) => {
if (!(a.length === 0 && g.length === 0)) {
if (a.length === 0 && g.length > 0)
a = g.map(({ id: $ }) => t.getAnnotation($));
else if (a.length > 0 && g.length === 0)
a.forEach(($) => {
const m = t.getAnnotation($.id);
m && !dt(m, $) && f("updateAnnotation", m, $);
}), a = [];
else {
const $ = new Set(a.map((x) => x.id)), m = new Set(g.map(({ id: x }) => x));
a.filter((x) => !m.has(x.id)).forEach((x) => {
const Y = t.getAnnotation(x.id);
Y && !dt(Y, x) && f("updateAnnotation", Y, x);
}), a = [
// Remove annotations that were deselected
...a.filter((x) => m.has(x.id)),
// Add editable annotations that were selected
...g.filter(({ id: x }) => !$.has(x)).map(({ id: x }) => t.getAnnotation(x))
];
}
f("selectionChanged", a);
}
}), n.subscribe((g) => {
!l && g ? f("mouseEnterAnnotation", t.getAnnotation(g)) : l && !g ? f("mouseLeaveAnnotation", t.getAnnotation(l)) : l && g && (f("mouseLeaveAnnotation", t.getAnnotation(l)), f("mouseEnterAnnotation", t.getAnnotation(g))), l = g;
}), o == null || o.subscribe((g) => f("viewportIntersect", g.map(t.getAnnotation))), t.observe((g) => {
i && (c && clearTimeout(c), c = setTimeout(p, 1e3));
const { created: $, deleted: m } = g.changes;
$.forEach((x) => f("createAnnotation", x)), m.forEach((x) => f("deleteAnnotation", x)), g.changes.updated.filter((x) => [
...x.bodiesCreated || [],
...x.bodiesDeleted || [],
...x.bodiesUpdated || []
].length > 0).forEach(({ oldValue: x, newValue: Y }) => {
const I = a.find((X) => X.id === x.id) || x;
a = a.map((X) => X.id === x.id ? Y : X), f("updateAnnotation", Y, I);
});
}, { origin: H.LOCAL }), t.observe((g) => {
if (a) {
const $ = new Set(a.map((x) => x.id)), m = g.changes.updated.filter(({ newValue: x }) => $.has(x.id)).map(({ newValue: x }) => x);
m.length > 0 && (a = a.map((x) => m.find((I) => I.id === x.id) || x));
}
}, { origin: H.REMOTE }), { on: h, off: u, emit: f };
}, Rn = (t) => (e) => e.reduce((n, o) => {
const { parsed: r, error: i } = t.parse(o);
return i ? {
parsed: n.parsed,
failed: [...n.failed, o]
} : {
parsed: [...n.parsed, r],
failed: n.failed
};
}, { parsed: [], failed: [] }), Gn = (t, e) => {
const n = (c) => {
if (e) {
const { parsed: h, error: u } = e.parse(c);
h ? t.addAnnotation(h, H.REMOTE) : console.error(u);
} else
t.addAnnotation(c, H.REMOTE);
}, o = () => t.clear(), r = (c) => {
const h = t.getAnnotation(c);
return e && h ? e.serialize(h) : h;
}, i = () => e ? t.all().map(e.serialize) : t.all(), s = (c) => fetch(c).then((h) => h.json()).then((h) => (l(h), h)), a = (c) => {
if (typeof c == "string") {
const h = t.getAnnotation(c);
return t.deleteAnnotation(c), e ? e.serialize(h) : h;
} else {
const h = e ? e.parse(c).parsed : c;
return t.deleteAnnotation(h), c;
}
}, l = (c) => {
if (e) {
const { parsed: h, failed: u } = Rn(e)(c);
u.length > 0 && console.warn(`Discarded ${u.length} invalid annotations`, u), t.bulkAddAnnotation(h, !0, H.REMOTE);
} else
t.bulkAddAnnotation(c, !0, H.REMOTE);
};
return {
addAnnotation: n,
clearAnnotations: o,
getAnnotationById: r,
getAnnotations: i,
loadAnnotations: s,
removeAnnotation: a,
setAnnotations: l,
updateAnnotation: (c) => {
if (e) {
const h = e.parse(c).parsed, u = e.serialize(t.getAnnotation(h.id));
return t.updateAnnotation(h), u;
} else {
const h = t.getAnnotation(c.id);
return t.updateAnnotation(c), h;
}
}
};
};
let Nn = (t) => crypto.getRandomValues(new Uint8Array(t)), Hn = (t, e, n) => {
let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, r = -~(1.6 * o * e / t.length);
return (i = e) => {
let s = "";
for (; ; ) {
let a = n(r), l = r;
for (; l--; )
if (s += t[a[l] & o] || "", s.length === i)
return s;
}
};
}, Fn = (t, e = 21) => Hn(t, e, Nn), Dn = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce((e, n) => (n &= 63, n < 36 ? e += n.toString(36) : n < 62 ? e += (n - 26).toString(36).toUpperCase() : n > 62 ? e += "-" : e += "_", e), "");
const Un = () => ({ isGuest: !0, id: Fn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Vn = (t) => {
const e = JSON.stringify(t);
let n = 0;
for (let o = 0, r = e.length; o < r; o++) {
let i = e.charCodeAt(o);
n = (n << 5) - n + i, n |= 0;
}
return `${n}`;
}, jn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
const { id: o, type: r, purpose: i, value: s, created: a, creator: l, ...c } = n;
return {
id: o || Vn(n),
annotation: e,
type: r,
purpose: i,
value: s,
created: a,
creator: l ? typeof l == "object" ? { ...l } : l : void 0,
...c
};
}), zn = (t) => t.map((e) => {
const n = { ...e };
return delete n.annotation, delete n.id, n;
});
Dn();
const sr = (t, e = !1) => ({ parse: (n) => Wn(n, e), serialize: (n) => qn(n, t) }), Wn = (t, e = !1) => {
const n = t.id || He(), o = jn(t.body, n), r = Array.isArray(t.target) ? t.target[0] : t.target, i = Array.isArray(r.selector) ? r.selector[0] : r.selector, s = i.type === "FragmentSelector" ? un(i, e) : i.type === "SvgSelector" ? yn(i) : void 0;
return s ? {
parsed: {
id: n,
bodies: o,
target: {
annotation: n,
selector: s
}
}
} : {
error: Error(`Unknown selector type: ${s.type}`)
};
}, qn = (t, e) => {
const n = t.target.selector, o = n.type == F.RECTANGLE ? hn(n.geometry) : $n(n);
return {
"@context": "http://www.w3.org/ns/anno.jsonld",
id: t.id,
type: "Annotation",
body: zn(t.bodies),
target: {
source: e,
selector: o
}
};
};
function pe(t, e, n) {
const o = t.slice();
return o[11] = e[n], o[13] = n, o;
}
function fe(t) {
let e, n, o, r, i;
return {
c() {
e = _("rect"), d(e, "class", "a9s-corner-handle"), d(e, "x", n = /*point*/
t[11][0] - /*handleSize*/
t[3] / 2), d(e, "y", o = /*point*/
t[11][1] - /*handleSize*/
t[3] / 2), d(
e,
"height",
/*handleSize*/
t[3]
), d(
e,
"width",
/*handleSize*/
t[3]
);
},
m(s, a) {
O(s, e, a), r || (i = j(e, "pointerdown", function() {
U(
/*grab*/
t[10](E(
/*idx*/
t[13]
))
) && t[10](E(
/*idx*/
t[13]
)).apply(this, arguments);
}), r = !0);
},
p(s, a) {
t = s, a & /*geom, handleSize*/
24 && n !== (n = /*point*/
t[11][0] - /*handleSize*/
t[3] / 2) && d(e, "x", n), a & /*geom, handleSize*/
24 && o !== (o = /*point*/
t[11][1] - /*handleSize*/
t[3] / 2) && d(e, "y", o), a & /*handleSize*/
8 && d(
e,
"height",
/*handleSize*/
t[3]
), a & /*handleSize*/
8 && d(
e,
"width",
/*handleSize*/
t[3]
);
},
d(s) {
s && T(e), r = !1, i();
}
};
}
function Jn(t) {
let e, n, o, r, i, s, a, l, c, h, u = (
/*geom*/
t[4].points
), f = [];
for (let p = 0; p < u.length; p += 1)
f[p] = fe(pe(t, u, p));
return {
c() {
e = _("polygon"), r = K(), i = _("polygon"), a = K();
for (let p = 0; p < f.length; p += 1)
f[p].c();
l = rt(), d(e, "class", "a9s-outer"), d(e, "style", n = /*computedStyle*/
t[1] ? "display:none;" : void 0), d(e, "points", o = /*geom*/
t[4].points.map(me).join(" ")), d(i, "class", "a9s-inner a9s-shape-handle"), d(
i,
"style",
/*computedStyle*/
t[1]
), d(i, "points", s = /*geom*/
t[4].points.map(ge).join(" "));
},
m(p, g) {
O(p, e, g), O(p, r, g), O(p, i, g), O(p, a, g);
for (let $ = 0; $ < f.length; $ += 1)
f[$] && f[$].m(p, g);
O(p, l, g), c || (h = [
j(e, "pointerdown", function() {
U(
/*grab*/
t[10](E.SHAPE)
) && t[10](E.SHAPE).apply(this, arguments);
}),
j(i, "pointerdown", function() {
U(
/*grab*/
t[10](E.SHAPE)
) && t[10](E.SHAPE).apply(this, arguments);
})
], c = !0);
},
p(p, g) {
if (t = p, g & /*computedStyle*/
2 && n !== (n = /*computedStyle*/
t[1] ? "display:none;" : void 0) && d(e, "style", n), g & /*geom*/
16 && o !== (o = /*geom*/
t[4].points.map(me).join(" ")) && d(e, "points", o), g & /*computedStyle*/
2 && d(
i,
"style",
/*computedStyle*/
t[1]
), g & /*geom*/
16 && s !== (s = /*geom*/
t[4].points.map(ge).join(" ")) && d(i, "points", s), g & /*geom, handleSize, grab, Handle*/
1048) {
u = /*geom*/
t[4].points;
let $;
for ($ = 0; $ < u.length; $ += 1) {
const m = pe(t, u, $);
f[$] ? f[$].p(m, g) : (f[$] = fe(m), f[$].c(), f[$].m(l.parentNode, l));
}
for (; $ < f.length; $ += 1)
f[$].d(1);
f.length = u.length;
}
},
d(p) {
p && T(e), p && T(r), p && T(i), p && T(a), ee(f, p), p && T(l), c = !1, ot(h);
}
};
}
function kn(t) {
let e, n;
return e = new Ue({
props: {
shape: (
/*shape*/
t[0]
),
transform: (
/*transform*/
t[2]
),
editor: (
/*editor*/
t[5]
),
$$slots: {
default: [
Jn,
({ grab: o }) => ({ 10: o }),
({ grab: o }) => o ? 1024 : 0
]
},
$$scope: { ctx: t }
}
}), e.$on(
"change",
/*change_handler*/
t[7]
), e.$on(
"grab",
/*grab_handler*/
t[8]
), e.$on(
"release",
/*release_handler*/
t[9]
), {
c() {
ut(e.$$.fragment);
},
m(o, r) {
at(e, o, r), n = !0;
},
p(o, [r]) {
const i = {};
r & /*shape*/
1 && (i.shape = /*shape*/
o[0]), r & /*transform*/
4 && (i.transform = /*transform*/
o[2]), r & /*$$scope, geom, handleSize, grab, computedStyle*/
17434 && (i.$$scope = { dirty: r, ctx: o }), e.$set(i);
},
i(o) {
n || (P(e.$$.fragment, o), n = !0);
},
o(o) {
R(e.$$.fragment, o), n = !1;
},
d(o) {
lt(e, o);
}
};
}
const me = (t) => t.join(","), ge = (t) => t.join(",");
function Kn(t, e, n) {
let o, r, { shape: i } = e, { computedStyle: s = void 0 } = e, { transform: a } = e, { viewportScale: l = 1 } = e;
const c = (p, g, $) => {
let m;
g === E.SHAPE ? m = p.geometry.points.map(([Y, I]) => [Y + $[0], I + $[1]]) : m = p.geometry.points.map(([Y, I], X) => g === E(X) ? [Y + $[0], I + $[1]] : [Y, I]);
const x = Nt(m);
return { ...p, geometry: { points: m, bounds: x } };
};
function h(p) {
yt.call(this, t, p);
}
function u(p) {
yt.call(this, t, p);
}
function f(p) {
yt.call(this, t, p);
}
return t.$$set = (p) => {
"shape" in p && n(0, i = p.shape), "computedStyle" in p && n(1, s = p.computedStyle), "transform" in p && n(2, a = p.transform), "viewportScale" in p && n(6, l = p.viewportScale);
}, t.$$.update = () => {
t.$$.dirty & /*shape*/
1 && n(4, o = i.geometry), t.$$.dirty & /*viewportScale*/
64 && n(3, r = 10 / l);
}, [
i,
s,
a,
r,
o,
c,
l,
h,
u,
f
];
}
class Qn extends Z {
constructor(e) {
super(), Q(this, e, Kn, kn, z, {
shape: 0,
computedStyle: 1,
transform: 2,
viewportScale: 6
});
}
}
function Zn(t) {
let e, n, o, r, i, s, a, l, c, h, u, f, p, g, $, m, x, Y, I, X, D, y, b, w, A, M, S, B, C, G, it, tt, Dt, W, Mt, Lt, Ut, q, Yt, Bt, Vt, J, It, _t, jt, k, Xt, Pt, zt, re;
return {
c() {
e = _("rect"), a = K(), l = _("rect"), p = K(), g = _("rect"), Y = K(), I = _("rect"), b = K(), w = _("rect"), B = K(), C = _("rect"), Dt = K(), W = _("rect"), Ut = K(), q = _("rect"), Vt = K(), J = _("rect"), jt = K(), k = _("rect"), d(e, "class", "a9s-outer"), d(e, "style", n = /*computedStyle*/
t[1] ? "display:none;" : void 0), d(e, "x", o = /*geom*/
t[4].x), d(e, "y", r = /*geom*/
t[4].y), d(e, "width", i = /*geom*/
t[4].w), d(e, "height", s = /*geom*/
t[4].h), d(l, "class", "a9s-inner a9s-shape-handle"), d(
l,
"style",
/*computedStyle*/
t[1]
), d(l, "x", c = /*geom*/
t[4].x), d(l, "y", h = /*geom*/
t[4].y), d(l, "width", u = /*geom*/
t[4].w), d(l, "height", f = /*geom*/
t[4].h), d(g, "class", "a9s-edge-handle a9s-edge-handle-top"), d(g, "x", $ = /*geom*/
t[4].x), d(g, "y", m = /*geom*/
t[4].y), d(g, "height", 1), d(g, "width", x = /*geom*/
t[4].w), d(I, "class", "a9s-edge-handle a9s-edge-handle-right"), d(I, "x", X = /*geom*/
t[4].x + /*geom*/
t[4].w), d(I, "y", D = /*geom*/
t[4].y), d(I, "height", y = /*geom*/
t[4].h), d(I, "width", 1), d(w, "class", "a9s-edge-handle a9s-edge-handle-bottom"), d(w, "x", A = /*geom*/
t[4].x), d(w, "y", M = /*geom*/
t[4].y + /*geom*/
t[4].h), d(w, "height", 1), d(w, "width", S = /*geom*/
t[4].w), d(C, "class", "a9s-edge-handle a9s-edge-handle-left"), d(C, "x", G = /*geom*/
t[4].x), d(C, "y", it = /*geom*/
t[4].y), d(C, "height", tt = /*geom*/
t[4].h), d(C, "width", 1), d(W, "class", "a9s-corner-handle a9s-corner-handle-topleft"), d(W, "x", Mt = /*geom*/
t[4].x - /*handleSize*/
t[3] / 2), d(W, "y", Lt = /*geom*/
t[4].y - /*handleSize*/
t[3] / 2), d(
W,
"height",
/*handleSize*/
t[3]
), d(
W,
"width",
/*handleSize*/
t[3]
), d(q, "class", "a9s-corner-handle a9s-corner-handle-topright"), d(q, "x", Yt = /*geom*/
t[4].x + /*geom*/
t[4].w - /*handleSize*/
t[3] / 2), d(q, "y", Bt = /*geom*/
t[4].y - /*handleSize*/
t[3] / 2), d(
q,
"height",
/*handleSize*/
t[3]
), d(
q,
"width",
/*handleSize*/
t[3]
), d(J, "class", "a9s-corner-handle a9s-corner-handle-bottomright"), d(J, "x", It = /*geom*/
t[4].x + /*geom*/
t[4].w - /*handleSize*/
t[3] / 2), d(J, "y", _t = /*geom*/
t[4].y + /*geom*/
t[4].h - /*handleSize*/
t[3] / 2), d(
J,
"height",
/*handleSize*/
t[3]
), d(
J,
"width",
/*handleSize*/
t[3]
), d(k, "class", "a9s-corner-handle a9s-corner-handle-bottomleft"), d(k, "x", Xt = /*geom*/
t[4].x - /*handleSize*/
t[3] / 2), d(k, "y", Pt = /*geom*/
t[4].y + /*geom*/
t[4].h - /*handleSize*/
t[3] / 2), d(
k,
"height",
/*handleSize*/
t[3]
), d(
k,
"width",
/*handleSize*/
t[3]
);
},
m(L, v) {
O(L, e, v), O(L, a, v), O(L, l, v), O(L, p, v), O(L, g, v), O(L, Y, v), O(L, I, v), O(L, b, v), O(L, w, v), O(L, B, v), O(L, C, v), O(L, Dt, v), O(L, W, v), O(L, Ut, v), O(L, q, v), O(L, Vt, v), O(L, J, v), O(L, jt, v), O(L, k, v), zt || (re = [
j(e, "pointerdown", function() {
U(
/*grab*/
t[10](E.SHAPE)
) && t[10](E.SHAPE).apply(this, arguments);
}),
j(l, "pointerdown", function() {
U(
/*grab*/
t[10](E.SHAPE)
) && t[10](E.SHAPE).apply(this, arguments);
}),
j(g, "pointerdown", function() {
U(
/*grab*/
t[10](E.TOP)
) && t[10](E.TOP).apply(this, arguments);
}),
j(I, "pointerdown", function() {
U(
/*grab*/
t[10](E.RIGHT)
) && t[10](E.RIGHT).apply(this, arguments);
}),
j(w, "pointerdown", function() {
U(
/*grab*/
t[10](E.BOTTOM)
) && t[10](E.BOTTOM).apply(this, arguments);
}),
j(C, "pointerdown", function() {
U(
/*grab*/
t[10](E.LEFT)
) && t[10](E.LEFT).apply(this, arguments);
}),
j(W, "pointerdown", function() {
U(
/*grab*/
t[10](E.TOP_LEFT)
) && t[10](E.TOP_LEFT).apply(this, arguments);
}),
j(q, "pointerdown", function() {
U(
/*grab*/
t[10](E.TOP_RIGHT)
) && t[10](E.TOP_RIGHT).apply(this, arguments);
}),
j(J, "pointerdown", function() {
U(
/*grab*/
t[10](E.BOTTOM_RIGHT)
) && t[10](E.BOTTOM_RIGHT).apply(this, arguments);
}),
j(k, "pointerdown", function() {
U(
/*grab*/
t[10](E.BOTTOM_LEFT)
) && t[10](E.BOTTOM_LEFT).apply(this, arguments);
})
], zt = !0);
},
p(L, v) {
t = L, v & /*computedStyle*/
2 && n !== (n = /*computedStyle*/
t[1] ? "display:none;" : void 0) && d(e, "style", n), v & /*geom*/
16 && o !== (o = /*geom*/
t[4].x) && d(e, "x", o), v & /*geom*/
16 && r !== (r = /*geom*/
t[4].y) && d(e, "y", r), v & /*geom*/
16 && i !== (i = /*geom*/
t[4].w) && d(e, "width", i), v & /*geom*/
16 && s !== (s = /*geom*/
t[4].h) && d(e, "height", s), v & /*computedStyle*/
2 && d(
l,
"style",
/*computedStyle*/
t[1]
), v & /*geom*/
16 && c !== (c = /*geom*/
t[4].x) && d(l, "x", c), v & /*geom*/
16 && h !== (h = /*geom*/
t[4].y) && d(l, "y", h), v & /*geom*/
16 && u !== (u = /*geom*/
t[4].w) && d(l, "width", u), v & /*geom*/
16 && f !== (f = /*geom*/
t[4].h) && d(l, "height", f), v & /*geom*/
16 && $ !== ($ = /*geom*/
t[4].x) && d(g, "x", $), v & /*geom*/
16 && m !== (m = /*geom*/
t[4].y) && d(g, "y", m), v & /*geom*/
16 && x !== (x = /*geom*/
t[4].w) && d(g, "width", x), v & /*geom*/
16 && X !== (X = /*geom*/
t[4].x + /*geom*/
t[4].w) && d(I, "x", X), v & /*geom*/
16 && D !== (D = /*geom*/
t[4].y) && d(I, "y", D), v & /*geom*/
16 && y !== (y = /*geom*/
t[4].h) && d(I, "height", y), v & /*geom*/
16 && A !== (A = /*geom*/
t[4].x) && d(w, "x", A), v & /*geom*/
16 && M !== (M = /*geom*/
t[4].y + /*geom*/
t[4].h) && d(w, "y", M), v & /*geom*/
16 && S !== (S = /*geom*/
t[4].w) && d(w, "width", S), v & /*geom*/
16 && G !== (G = /*geom*/
t[4].x) && d(C, "x", G), v & /*geom*/
16 && it !== (it = /*geom*/
t[4].y) && d(C, "y", it), v & /*geom*/
16 && tt !== (tt = /*geom*/
t[4].h) && d(C, "height", tt), v & /*geom, handleSize*/
24 && Mt !== (Mt = /*geom*/
t[4].x - /*handleSize*/
t[3] / 2) && d(W, "x", Mt), v & /*geom, handleSize*/
24 && Lt !== (Lt = /*geom*/
t[4].y - /*handleSize*/
t[3] / 2) && d(W, "y", Lt), v & /*handleSize*/
8 && d(
W,
"height",
/*handleSize*/
t[3]
), v & /*handleSize*/
8 && d(
W,
"width",
/*handleSize*/
t[3]
), v & /*geom, handleSize*/
24 && Yt !== (Yt = /*geom*/
t[4].x + /*geom*/
t[4].w - /*handleSize*/
t[3] / 2) && d(q, "x", Yt), v & /*geom, handleSize*/
24 && Bt !== (Bt = /*geom*/
t[4].y - /*handleSize*/
t[3] / 2) && d(q, "y", Bt), v & /*handleSize*/
8 && d(
q,
"height",
/*handleSize*/
t[3]
), v & /*handleSize*/
8 && d(
q,
"width",
/*handleSize*/
t[3]
), v & /*geom, handleSize*/
24 && It !== (It = /*geom*/
t[4].x + /*geom*/
t[4].w - /*handleSize*/
t[3] / 2) && d(J, "x", It), v & /*geom, handleSize*/
24 && _t !== (_t = /*geom*/
t[4].y + /*geom*/
t[4].h - /*handleSize*/
t[3] / 2) && d(J, "y", _t), v & /*handleSize*/
8 && d(
J,
"height",
/*handleSize*/
t[3]
), v & /*handleSize*/
8 && d(
J,
"width",
/*handleSize*/
t[3]
), v & /*geom, handleSize*/
24 && Xt !== (Xt = /*geom*/
t[4].x - /*handleSize*/
t[3] / 2) && d(k, "x", Xt), v & /*geom, handleSize*/
24 && Pt !== (Pt = /*geom*/
t[4].y + /*geom*/
t[4].h - /*handleSize*/
t[3] / 2) && d(k, "y", Pt), v & /*handleSize*/
8 && d(
k,
"height",
/*handleSize*/
t[3]
), v & /*handleSize*/
8 && d(
k,
"width",
/*handleSize*/
t[3]
);
},
d(L) {
L && T(e), L && T(a), L && T(l), L && T(p), L && T(g), L && T(Y), L && T(I), L && T(b), L && T(w), L && T(B), L && T(C), L && T(Dt), L && T(W), L && T(Ut), L && T(q), L && T(Vt), L && T(J), L && T(jt), L && T(k), zt = !1, ot(re);
}
};
}
function to(t) {
let e, n;
return e = new Ue({
props: {
shape: (
/*shape*/
t[0]
),
transform: (
/*transform*/
t[2]
),
editor: (
/*editor*/
t[5]
),
$$slots: {
default: [
Zn,
({ grab: o }) => ({ 10: o }),
({ grab: o }) => o ? 1024 : 0
]
},
$$scope: { ctx: t }
}
}), e.$on(
"grab",
/*grab_handler*/
t[7]
), e.$on(
"change",
/*change_handler*/
t[8]
), e.$on(
"release",
/*release_handler*/
t[9]
), {
c() {
ut(e.$$.fragment);
},
m(o, r) {
at(e, o, r), n = !0;
},
p(o, [r]) {
const i = {};
r & /*shape*/
1 && (i.shape = /*shape*/
o[0]), r & /*transform*/
4 && (i.transform = /*transform*/
o[2]), r & /*$$scope, geom, handleSize, grab, computedStyle*/
3098 && (i.$$scope = { dirty: r, ctx: o }), e.$set(i);
},
i(o) {
n || (P(e.$$.fragment, o), n = !0);
},
o(o) {
R(e.$$.fragment, o), n = !1;
},
d(o) {
lt(e, o);
}
};
}
function eo(t, e, n) {
let o, r, { shape: i } = e, { computedStyle: s = void 0 } = e, { transform: a } = e, { viewportScale: l = 1 } = e;
const c = (p, g, $) => {
const m = p.geometry.bounds;
let [x, Y] = [m.minX, m.minY], [I, X] = [m.maxX, m.maxY];
const [D, y] = $;
if (g === E.SHAPE)
x += D, I += D, Y += y, X += y;
else {
switch (g) {
case E.TOP:
case E.TOP_LEFT:
case E.TOP_RIGHT: {
Y += y;
break;
}
case E.BOTTOM:
case E.BOTTOM_LEFT:
case E.BOTTOM_RIGHT: {
X += y;
break;
}
}
switch (g) {
case E.LEFT:
case E.TOP_LEFT:
case E.BOTTOM_LEFT: {
x += D;
break;
}
case E.RIGHT:
case E.TOP_RIGHT:
case E.BOTTOM_RIGHT: {
I += D;
break;
}
}
}
const b = Math.min(x, I), w = Math.min(Y, X), A = Math.abs(I - x), M = Math.abs(X - Y);
return {
...p,
geometry: {
x: b,
y: w,
w: A,
h: M,
bounds: {
minX: b,
minY: w,
maxX: b + A,
maxY: w + M
}
}
};
};
function h(p) {
yt.call(this, t, p);
}
function u(p) {
yt.call(this, t, p);
}
function f(p) {
yt.call(this, t, p);
}
return t.$$set = (p) => {
"shape" in p && n(0, i = p.shape), "computedStyle" in p && n(1, s = p.computedStyle), "transform" in p && n(2, a = p.transform), "viewportScale" in p && n(6, l = p.viewportScale);
}, t.$$.update = () => {
t.$$.dirty & /*shape*/
1 && n(4, o = i.geometry), t.$$.dirty & /*viewportScale*/
64 && n(3, r = 10 / l);
}, [
i,
s,
a,
r,
o,
c,
l,
h,
u,
f
];
}
class no extends Z {
constructor(e) {
super(), Q(this, e, eo, to, z, {
shape: 0,
computedStyle: 1,
transform: 2,
viewportScale: 6
});
}
}
const De = /* @__PURE__ */ new Map([
[F.RECTANGLE, no],
[F.POLYGON, Qn]
]), ye = (t) => De.get(t.type), oo = (t, e) => De.set(t, e), E = (t) => `HANDLE-${t}`;
E.SHAPE = "SHAPE";
E.TOP = "TOP";
E.RIGHT = "RIGHT";
E.BOTTOM = "BOTTOM";
E.LEFT = "LEFT";
E.TOP_LEFT = "TOP_LEFT";
E.TOP_RIGHT = "TOP_RIGHT";
E.BOTTOM_RIGHT = "BOTTOM_RIGHT";
E.BOTTOM_LEFT = "BOTTOM_LEFT";
const ro = (t) => ({}), $e = (t) => ({ grab: (
/*onGrab*/
t[0]
) });
function io(t) {
let e, n, o, r;
const i = (
/*#slots*/
t[7].default
), s = Je(
i,
t,
/*$$scope*/
t[6],
$e
);
return {
c() {
e = _("g"), s && s.c(), d(e, "class", "a9s-annotation selected");
},
m(a, l) {
O(a, e, l), s && s.m(e, null), n = !0, o || (r = [
j(
e,
"pointerup",
/*onRelease*/
t[2]
),
j(
e,
"pointermove",
/*onPointerMove*/
t[1]
)
], o = !0);
},
p(a, [l]) {
s && s.p && (!n || l & /*$$scope*/
64) && Ke(
s,
i,
a,
/*$$scope*/
a[6],
n ? ke(
i,
/*$$scope*/
a[6],
l,
ro
) : Qe(
/*$$scope*/
a[6]
),
$e
);
},
i(a) {
n || (P(s, a), n = !0);
},
o(a) {
R