UNPKG

@recogito/annotorious

Version:

A JavaScript image annotation library

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