@annotorious/core 3.0.0-rc.16 → 3.0.0-rc.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  var Y = Object.prototype.hasOwnProperty;
2
- function B(e, n) {
2
+ function x(e, n) {
3
3
  var t, o;
4
4
  if (e === n)
5
5
  return !0;
@@ -10,14 +10,14 @@ function B(e, n) {
10
10
  return e.toString() === n.toString();
11
11
  if (t === Array) {
12
12
  if ((o = e.length) === n.length)
13
- for (; o-- && B(e[o], n[o]); )
13
+ for (; o-- && x(e[o], n[o]); )
14
14
  ;
15
15
  return o === -1;
16
16
  }
17
17
  if (!t || typeof e == "object") {
18
18
  o = 0;
19
19
  for (t in e)
20
- if (Y.call(e, t) && ++o && !Y.call(n, t) || !(t in n) || !B(e[t], n[t]))
20
+ if (Y.call(e, t) && ++o && !Y.call(n, t) || !(t in n) || !x(e[t], n[t]))
21
21
  return !1;
22
22
  return Object.keys(n).length === o;
23
23
  }
@@ -45,24 +45,24 @@ function _(e, n = $) {
45
45
  }
46
46
  }
47
47
  }
48
- function h(b) {
48
+ function p(b) {
49
49
  i(b(e));
50
50
  }
51
51
  function U(b, w = $) {
52
52
  const u = [b, w];
53
- return o.add(u), o.size === 1 && (t = n(i) || $), b(e), () => {
53
+ return o.add(u), o.size === 1 && (t = n(i, p) || $), b(e), () => {
54
54
  o.delete(u), o.size === 0 && t && (t(), t = null);
55
55
  };
56
56
  }
57
- return { set: i, update: h, subscribe: U };
57
+ return { set: i, update: p, subscribe: U };
58
58
  }
59
59
  const be = (e) => {
60
- const { subscribe: n, set: t } = _(null);
61
- let o = null;
60
+ const { subscribe: n, set: t } = _();
61
+ let o;
62
62
  return n((i) => o = i), e.observe(({ changes: i }) => {
63
63
  if (o) {
64
- i.deleted.some((b) => b.id === o) && t(null);
65
- const U = i.updated.find(({ oldValue: b }) => b.id === o);
64
+ (i.deleted || []).some((b) => b.id === o) && t(void 0);
65
+ const U = (i.updated || []).find(({ oldValue: b }) => b.id === o);
66
66
  U && t(U.newValue.id);
67
67
  }
68
68
  }), {
@@ -78,32 +78,32 @@ const V = { selected: [] }, ve = (e, n = "EDIT") => {
78
78
  const { subscribe: t, set: o } = _(V);
79
79
  let i = V;
80
80
  t((s) => i = s);
81
- const h = () => o(V), U = () => {
81
+ const p = () => o(V), U = () => {
82
82
  var s;
83
83
  return ((s = i.selected) == null ? void 0 : s.length) === 0;
84
84
  }, b = (s) => {
85
85
  if (i.selected.length === 0)
86
86
  return !1;
87
- const f = typeof s == "string" ? s : s.id;
88
- return i.selected.some((y) => y.id === f);
89
- }, w = (s, f) => {
87
+ const g = typeof s == "string" ? s : s.id;
88
+ return i.selected.some((y) => y.id === g);
89
+ }, w = (s, g) => {
90
90
  const y = e.getAnnotation(s);
91
91
  if (y) {
92
92
  const A = G(y, n);
93
- o(A === "EDIT" ? { selected: [{ id: s, editable: !0 }], pointerEvent: f } : A === "SELECT" ? { selected: [{ id: s }], pointerEvent: f } : { selected: [], pointerEvent: f });
93
+ o(A === "EDIT" ? { selected: [{ id: s, editable: !0 }], pointerEvent: g } : A === "SELECT" ? { selected: [{ id: s }], pointerEvent: g } : { selected: [], pointerEvent: g });
94
94
  } else
95
95
  console.warn("Invalid selection: " + s);
96
- }, u = (s, f = !0) => {
97
- const y = Array.isArray(s) ? s : [s], A = y.map((L) => e.getAnnotation(L)).filter((L) => L);
98
- o({ selected: A.map(({ id: L }) => ({ id: L, editable: f })) }), A.length !== y.length && console.warn("Invalid selection", s);
99
- }, T = (s) => {
96
+ }, u = (s, g = !0) => {
97
+ const y = Array.isArray(s) ? s : [s], A = y.map((O) => e.getAnnotation(O)).filter(Boolean);
98
+ o({ selected: A.map(({ id: O }) => ({ id: O, editable: g })) }), A.length !== y.length && console.warn("Invalid selection", s);
99
+ }, S = (s) => {
100
100
  if (i.selected.length === 0)
101
101
  return !1;
102
- const { selected: f } = i;
103
- f.filter(({ id: A }) => s.includes(A)).length > 0 && o({ selected: f.filter(({ id: A }) => !s.includes(A)) });
102
+ const { selected: g } = i;
103
+ g.filter(({ id: A }) => s.includes(A)).length > 0 && o({ selected: g.filter(({ id: A }) => !s.includes(A)) });
104
104
  };
105
- return e.observe(({ changes: s }) => T(s.deleted.map((f) => f.id))), {
106
- clear: h,
105
+ return e.observe(({ changes: s }) => S((s.deleted || []).map((g) => g.id))), {
106
+ clear: p,
107
107
  clickSelect: w,
108
108
  get selected() {
109
109
  return i ? [...i.selected] : null;
@@ -147,7 +147,7 @@ function X(e, n, t) {
147
147
  return J(o);
148
148
  }
149
149
  const Ce = (e) => {
150
- const { creator: n, updatedBy: t } = e.target, o = e.bodies.reduce((i, h) => [...i, h.creator, h.updatedBy], []);
150
+ const { creator: n, updatedBy: t } = e.target, o = e.bodies.reduce((i, p) => [...i, p.creator, p.updatedBy].filter(Boolean), []);
151
151
  return [
152
152
  n,
153
153
  t,
@@ -167,8 +167,8 @@ const Ce = (e) => {
167
167
  return e.bodies.filter((o) => !t.has(o.id));
168
168
  }, ee = (e, n) => n.bodies.map((t) => {
169
169
  const o = e.bodies.find((i) => i.id === t.id);
170
- return { newBody: t, oldBody: o && !B(o, t) ? o : void 0 };
171
- }).filter(({ oldBody: t }) => t), te = (e, n) => !B(e.target, n.target), M = (e, n) => {
170
+ return { newBody: t, oldBody: o && !x(o, t) ? o : void 0 };
171
+ }).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), te = (e, n) => !x(e.target, n.target), M = (e, n) => {
172
172
  const t = Z(e, n), o = K(e, n), i = ee(e, n);
173
173
  return {
174
174
  oldValue: e,
@@ -179,55 +179,55 @@ const Ce = (e) => {
179
179
  targetUpdated: te(e, n) ? { oldTarget: e.target, newTarget: n.target } : void 0
180
180
  };
181
181
  };
182
- var ne = /* @__PURE__ */ ((e) => (e.BODY_ONLY = "BODY_ONLY", e.TARGET_ONLY = "TARGET_ONLY", e))(ne || {}), O = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e))(O || {});
182
+ var ne = /* @__PURE__ */ ((e) => (e.BODY_ONLY = "BODY_ONLY", e.TARGET_ONLY = "TARGET_ONLY", e))(ne || {}), T = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e))(T || {});
183
183
  const oe = (e, n) => {
184
- var h, U;
184
+ var p, U;
185
185
  const { changes: t, origin: o } = n;
186
186
  if (!(!e.options.origin || e.options.origin === o))
187
187
  return !1;
188
188
  if (e.options.ignore) {
189
- const { ignore: b } = e.options, w = (T) => (T == null ? void 0 : T.length) > 0;
189
+ const { ignore: b } = e.options, w = (S) => S && S.length > 0;
190
190
  if (!(w(t.created) || w(t.deleted))) {
191
- const T = (h = t.updated) == null ? void 0 : h.some((f) => w(f.bodiesCreated) || w(f.bodiesDeleted) || w(f.bodiesUpdated)), s = (U = t.updated) == null ? void 0 : U.some((f) => f.targetUpdated);
192
- if (b === "BODY_ONLY" && T && !s || b === "TARGET_ONLY" && s && !T)
191
+ const S = (p = t.updated) == null ? void 0 : p.some((g) => w(g.bodiesCreated) || w(g.bodiesDeleted) || w(g.bodiesUpdated)), s = (U = t.updated) == null ? void 0 : U.some((g) => g.targetUpdated);
192
+ if (b === "BODY_ONLY" && S && !s || b === "TARGET_ONLY" && s && !S)
193
193
  return !1;
194
194
  }
195
195
  }
196
196
  if (e.options.annotations) {
197
197
  const b = /* @__PURE__ */ new Set([
198
- ...t.created.map((u) => u.id),
199
- ...t.deleted.map((u) => u.id),
200
- ...t.updated.map(({ oldValue: u }) => u.id)
198
+ ...(t.created || []).map((u) => u.id),
199
+ ...(t.deleted || []).map((u) => u.id),
200
+ ...(t.updated || []).map(({ oldValue: u }) => u.id)
201
201
  ]);
202
202
  return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((u) => b.has(u));
203
203
  } else
204
204
  return !0;
205
205
  }, se = (e, n) => {
206
- const t = new Set((e.created || []).map((s) => s.id)), o = new Set((e.updated || []).map(({ newValue: s }) => s.id)), i = new Set((n.created || []).map((s) => s.id)), h = new Set((n.deleted || []).map((s) => s.id)), U = new Set((n.updated || []).map(({ oldValue: s }) => s.id)), b = new Set((n.updated || []).filter(({ oldValue: s }) => t.has(s.id) || o.has(s.id)).map(({ oldValue: s }) => s.id)), w = [
207
- ...(e.created || []).filter((s) => !h.has(s.id)).map((s) => U.has(s.id) ? n.updated.find(({ oldValue: f }) => f.id === s.id).newValue : s),
206
+ const t = new Set((e.created || []).map((s) => s.id)), o = new Set((e.updated || []).map(({ newValue: s }) => s.id)), i = new Set((n.created || []).map((s) => s.id)), p = new Set((n.deleted || []).map((s) => s.id)), U = new Set((n.updated || []).map(({ oldValue: s }) => s.id)), b = new Set((n.updated || []).filter(({ oldValue: s }) => t.has(s.id) || o.has(s.id)).map(({ oldValue: s }) => s.id)), w = [
207
+ ...(e.created || []).filter((s) => !p.has(s.id)).map((s) => U.has(s.id) ? n.updated.find(({ oldValue: g }) => g.id === s.id).newValue : s),
208
208
  ...n.created || []
209
209
  ], u = [
210
210
  ...(e.deleted || []).filter((s) => !i.has(s.id)),
211
211
  ...(n.deleted || []).filter((s) => !t.has(s.id))
212
- ], T = [
213
- ...(e.updated || []).filter(({ newValue: s }) => !h.has(s.id)).map((s) => {
214
- const { oldValue: f, newValue: y } = s;
212
+ ], S = [
213
+ ...(e.updated || []).filter(({ newValue: s }) => !p.has(s.id)).map((s) => {
214
+ const { oldValue: g, newValue: y } = s;
215
215
  if (U.has(y.id)) {
216
- const A = n.updated.find((L) => L.oldValue.id === y.id).newValue;
217
- return M(f, A);
216
+ const A = n.updated.find((O) => O.oldValue.id === y.id).newValue;
217
+ return M(g, A);
218
218
  } else
219
219
  return s;
220
220
  }),
221
221
  ...(n.updated || []).filter(({ oldValue: s }) => !b.has(s.id))
222
222
  ];
223
- return { created: w, deleted: u, updated: T };
223
+ return { created: w, deleted: u, updated: S };
224
224
  }, ie = (e) => e.id !== void 0, ye = () => {
225
- const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (r, l = {}) => t.push({ onChange: r, options: l }), i = (r) => {
226
- const l = t.findIndex((a) => a.onChange == r);
225
+ const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (d, l = {}) => t.push({ onChange: d, options: l }), i = (d) => {
226
+ const l = t.findIndex((c) => c.onChange == d);
227
227
  l > -1 && t.splice(l, 1);
228
- }, h = (r, l) => {
229
- const a = {
230
- origin: r,
228
+ }, p = (d, l) => {
229
+ const c = {
230
+ origin: d,
231
231
  changes: {
232
232
  created: l.created || [],
233
233
  updated: l.updated || [],
@@ -235,175 +235,175 @@ const oe = (e, n) => {
235
235
  },
236
236
  state: [...e.values()]
237
237
  };
238
- t.forEach((p) => {
239
- oe(p, a) && p.onChange(a);
238
+ t.forEach((f) => {
239
+ oe(f, c) && f.onChange(c);
240
240
  });
241
- }, U = (r, l = O.LOCAL) => {
242
- if (e.get(r.id))
243
- throw Error(`Cannot add annotation ${r.id} - exists already`);
244
- e.set(r.id, r), r.bodies.forEach((p) => n.set(p.id, r.id)), h(l, { created: [r] });
245
- }, b = (r, l) => {
246
- const a = typeof r == "string" ? l : r, p = typeof r == "string" ? r : r.id, v = e.get(p);
241
+ }, U = (d, l = T.LOCAL) => {
242
+ if (e.get(d.id))
243
+ throw Error(`Cannot add annotation ${d.id} - exists already`);
244
+ e.set(d.id, d), d.bodies.forEach((f) => n.set(f.id, d.id)), p(l, { created: [d] });
245
+ }, b = (d, l) => {
246
+ const c = typeof d == "string" ? l : d, f = typeof d == "string" ? d : d.id, v = e.get(f);
247
247
  if (v) {
248
- const D = M(v, a);
249
- return p === a.id ? e.set(p, a) : (e.delete(p), e.set(a.id, a)), v.bodies.forEach((x) => n.delete(x.id)), a.bodies.forEach((x) => n.set(x.id, a.id)), D;
248
+ const D = M(v, c);
249
+ return f === c.id ? e.set(f, c) : (e.delete(f), e.set(c.id, c)), v.bodies.forEach((B) => n.delete(B.id)), c.bodies.forEach((B) => n.set(B.id, c.id)), D;
250
250
  } else
251
- console.warn(`Cannot update annotation ${p} - does not exist`);
252
- }, w = (r, l = O.LOCAL, a = O.LOCAL) => {
253
- const p = ie(l) ? a : l, v = b(r, l);
254
- v && h(p, { updated: [v] });
255
- }, u = (r, l = O.LOCAL) => {
256
- const a = r.reduce((p, v) => {
251
+ console.warn(`Cannot update annotation ${f} - does not exist`);
252
+ }, w = (d, l = T.LOCAL, c = T.LOCAL) => {
253
+ const f = ie(l) ? c : l, v = b(d, l);
254
+ v && p(f, { updated: [v] });
255
+ }, u = (d, l = T.LOCAL) => {
256
+ const c = d.reduce((f, v) => {
257
257
  const D = b(v);
258
- return D ? [...p, D] : p;
258
+ return D ? [...f, D] : f;
259
259
  }, []);
260
- a.length > 0 && h(l, { updated: a });
261
- }, T = (r, l = O.LOCAL) => {
262
- const a = e.get(r.annotation);
263
- if (a) {
264
- const p = {
265
- ...a,
266
- bodies: [...a.bodies, r]
260
+ c.length > 0 && p(l, { updated: c });
261
+ }, S = (d, l = T.LOCAL) => {
262
+ const c = e.get(d.annotation);
263
+ if (c) {
264
+ const f = {
265
+ ...c,
266
+ bodies: [...c.bodies, d]
267
267
  };
268
- e.set(a.id, p), n.set(r.id, p.id), h(l, { updated: [{
269
- oldValue: a,
270
- newValue: p,
271
- bodiesCreated: [r]
268
+ e.set(c.id, f), n.set(d.id, f.id), p(l, { updated: [{
269
+ oldValue: c,
270
+ newValue: f,
271
+ bodiesCreated: [d]
272
272
  }] });
273
273
  } else
274
- console.warn(`Attempt to add body to missing annotation: ${r.annotation}`);
275
- }, s = () => [...e.values()], f = (r = O.LOCAL) => {
274
+ console.warn(`Attempt to add body to missing annotation: ${d.annotation}`);
275
+ }, s = () => [...e.values()], g = (d = T.LOCAL) => {
276
276
  const l = [...e.values()];
277
- e.clear(), n.clear(), h(r, { deleted: l });
278
- }, y = (r, l = !0, a = O.LOCAL) => {
277
+ e.clear(), n.clear(), p(d, { deleted: l });
278
+ }, y = (d, l = !0, c = T.LOCAL) => {
279
279
  if (l) {
280
- const p = [...e.values()];
281
- e.clear(), n.clear(), r.forEach((v) => {
280
+ const f = [...e.values()];
281
+ e.clear(), n.clear(), d.forEach((v) => {
282
282
  e.set(v.id, v), v.bodies.forEach((D) => n.set(D.id, v.id));
283
- }), h(a, { created: r, deleted: p });
283
+ }), p(c, { created: d, deleted: f });
284
284
  } else {
285
- const p = r.reduce((v, D) => {
286
- const x = e.get(D.id);
287
- return x ? [...v, x] : v;
285
+ const f = d.reduce((v, D) => {
286
+ const B = e.get(D.id);
287
+ return B ? [...v, B] : v;
288
288
  }, []);
289
- if (p.length > 0)
290
- throw Error(`Bulk insert would overwrite the following annotations: ${p.map((v) => v.id).join(", ")}`);
291
- r.forEach((v) => {
289
+ if (f.length > 0)
290
+ throw Error(`Bulk insert would overwrite the following annotations: ${f.map((v) => v.id).join(", ")}`);
291
+ d.forEach((v) => {
292
292
  e.set(v.id, v), v.bodies.forEach((D) => n.set(D.id, v.id));
293
- }), h(a, { created: r });
293
+ }), p(c, { created: d });
294
294
  }
295
- }, A = (r) => {
296
- const l = typeof r == "string" ? r : r.id, a = e.get(l);
297
- if (a)
298
- return e.delete(l), a.bodies.forEach((p) => n.delete(p.id)), a;
295
+ }, A = (d) => {
296
+ const l = typeof d == "string" ? d : d.id, c = e.get(l);
297
+ if (c)
298
+ return e.delete(l), c.bodies.forEach((f) => n.delete(f.id)), c;
299
299
  console.warn(`Attempt to delete missing annotation: ${l}`);
300
- }, L = (r, l = O.LOCAL) => {
301
- const a = A(r);
302
- a && h(l, { deleted: [a] });
303
- }, C = (r, l = O.LOCAL) => {
304
- const a = r.reduce((p, v) => {
300
+ }, O = (d, l = T.LOCAL) => {
301
+ const c = A(d);
302
+ c && p(l, { deleted: [c] });
303
+ }, C = (d, l = T.LOCAL) => {
304
+ const c = d.reduce((f, v) => {
305
305
  const D = A(v);
306
- return D ? [...p, D] : p;
306
+ return D ? [...f, D] : f;
307
307
  }, []);
308
- a.length > 0 && h(l, { deleted: a });
309
- }, c = (r, l = O.LOCAL) => {
310
- const a = e.get(r.annotation);
311
- if (a) {
312
- const p = a.bodies.find((v) => v.id === r.id);
313
- if (p) {
314
- n.delete(p.id);
308
+ c.length > 0 && p(l, { deleted: c });
309
+ }, a = (d, l = T.LOCAL) => {
310
+ const c = e.get(d.annotation);
311
+ if (c) {
312
+ const f = c.bodies.find((v) => v.id === d.id);
313
+ if (f) {
314
+ n.delete(f.id);
315
315
  const v = {
316
- ...a,
317
- bodies: a.bodies.filter((x) => x.id !== r.id)
316
+ ...c,
317
+ bodies: c.bodies.filter((B) => B.id !== d.id)
318
318
  };
319
- e.set(a.id, v), h(l, { updated: [{
320
- oldValue: a,
319
+ e.set(c.id, v), p(l, { updated: [{
320
+ oldValue: c,
321
321
  newValue: v,
322
- bodiesDeleted: [p]
322
+ bodiesDeleted: [f]
323
323
  }] });
324
324
  } else
325
- console.warn(`Attempt to delete missing body ${r.id} from annotation ${r.annotation}`);
325
+ console.warn(`Attempt to delete missing body ${d.id} from annotation ${d.annotation}`);
326
326
  } else
327
- console.warn(`Attempt to delete body from missing annotation ${r.annotation}`);
328
- }, m = (r) => {
329
- const l = e.get(r);
327
+ console.warn(`Attempt to delete body from missing annotation ${d.annotation}`);
328
+ }, m = (d) => {
329
+ const l = e.get(d);
330
330
  return l ? { ...l } : void 0;
331
- }, d = (r) => {
332
- const l = n.get(r);
331
+ }, r = (d) => {
332
+ const l = n.get(d);
333
333
  if (l) {
334
- const p = m(l).bodies.find((v) => v.id === r);
335
- if (p)
336
- return p;
337
- console.error(`Store integrity error: body ${r} in index, but not in annotation`);
334
+ const f = m(l).bodies.find((v) => v.id === d);
335
+ if (f)
336
+ return f;
337
+ console.error(`Store integrity error: body ${d} in index, but not in annotation`);
338
338
  } else
339
- console.warn(`Attempt to retrieve missing body: ${r}`);
340
- }, E = (r, l) => {
341
- if (r.annotation !== l.annotation)
339
+ console.warn(`Attempt to retrieve missing body: ${d}`);
340
+ }, E = (d, l) => {
341
+ if (d.annotation !== l.annotation)
342
342
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
343
- const a = e.get(r.annotation);
344
- if (a) {
345
- const p = a.bodies.find((D) => D.id === r.id), v = {
346
- ...a,
347
- bodies: a.bodies.map((D) => D.id === p.id ? l : D)
343
+ const c = e.get(d.annotation);
344
+ if (c) {
345
+ const f = c.bodies.find((D) => D.id === d.id), v = {
346
+ ...c,
347
+ bodies: c.bodies.map((D) => D.id === f.id ? l : D)
348
348
  };
349
- return e.set(a.id, v), p.id !== l.id && (n.delete(p.id), n.set(l.id, v.id)), {
350
- oldValue: a,
349
+ return e.set(c.id, v), f.id !== l.id && (n.delete(f.id), n.set(l.id, v.id)), {
350
+ oldValue: c,
351
351
  newValue: v,
352
- bodiesUpdated: [{ oldBody: p, newBody: l }]
352
+ bodiesUpdated: [{ oldBody: f, newBody: l }]
353
353
  };
354
354
  } else
355
- console.warn(`Attempt to add body to missing annotation ${r.annotation}`);
356
- }, g = (r, l, a = O.LOCAL) => {
357
- const p = E(r, l);
358
- h(a, { updated: [p] });
359
- }, S = (r, l = O.LOCAL) => {
360
- const a = r.map((p) => E({ id: p.id, annotation: p.annotation }, p));
361
- h(l, { updated: a });
362
- }, I = (r) => {
363
- const l = e.get(r.annotation);
355
+ console.warn(`Attempt to add body to missing annotation ${d.annotation}`);
356
+ }, h = (d, l, c = T.LOCAL) => {
357
+ const f = E(d, l);
358
+ f && p(c, { updated: [f] });
359
+ }, L = (d, l = T.LOCAL) => {
360
+ const c = d.map((f) => E({ id: f.id, annotation: f.annotation }, f)).filter(Boolean);
361
+ p(l, { updated: c });
362
+ }, I = (d) => {
363
+ const l = e.get(d.annotation);
364
364
  if (l) {
365
- const a = {
365
+ const c = {
366
366
  ...l,
367
367
  target: {
368
368
  ...l.target,
369
- ...r
369
+ ...d
370
370
  }
371
371
  };
372
- return e.set(l.id, a), {
372
+ return e.set(l.id, c), {
373
373
  oldValue: l,
374
- newValue: a,
374
+ newValue: c,
375
375
  targetUpdated: {
376
376
  oldTarget: l.target,
377
- newTarget: r
377
+ newTarget: d
378
378
  }
379
379
  };
380
380
  } else
381
- console.warn(`Attempt to update target on missing annotation: ${r.annotation}`);
381
+ console.warn(`Attempt to update target on missing annotation: ${d.annotation}`);
382
382
  };
383
383
  return {
384
384
  addAnnotation: U,
385
- addBody: T,
385
+ addBody: S,
386
386
  all: s,
387
387
  bulkAddAnnotation: y,
388
388
  bulkDeleteAnnotation: C,
389
389
  bulkUpdateAnnotation: u,
390
- bulkUpdateBodies: S,
391
- bulkUpdateTargets: (r, l = O.LOCAL) => {
392
- const a = r.map(I).filter((p) => p);
393
- a.length > 0 && h(l, { updated: a });
390
+ bulkUpdateBodies: L,
391
+ bulkUpdateTargets: (d, l = T.LOCAL) => {
392
+ const c = d.map((f) => I(f)).filter(Boolean);
393
+ c.length > 0 && p(l, { updated: c });
394
394
  },
395
- clear: f,
396
- deleteAnnotation: L,
397
- deleteBody: c,
395
+ clear: g,
396
+ deleteAnnotation: O,
397
+ deleteBody: a,
398
398
  getAnnotation: m,
399
- getBody: d,
399
+ getBody: r,
400
400
  observe: o,
401
401
  unobserve: i,
402
402
  updateAnnotation: w,
403
- updateBody: g,
404
- updateTarget: (r, l = O.LOCAL) => {
405
- const a = I(r);
406
- a && h(l, { updated: [a] });
403
+ updateBody: h,
404
+ updateTarget: (d, l = T.LOCAL) => {
405
+ const c = I(d);
406
+ c && p(l, { updated: [c] });
407
407
  }
408
408
  };
409
409
  }, Ue = (e) => ({
@@ -415,14 +415,13 @@ const oe = (e, n) => {
415
415
  });
416
416
  let P = () => ({
417
417
  emit(e, ...n) {
418
- let t = this.events[e] || [];
419
- for (let o = 0, i = t.length; o < i; o++)
420
- t[o](...n);
418
+ for (let t = 0, o = this.events[e] || [], i = o.length; t < i; t++)
419
+ o[t](...n);
421
420
  },
422
421
  events: {},
423
422
  on(e, n) {
424
423
  var t;
425
- return (t = this.events[e]) != null && t.push(n) || (this.events[e] = [n]), () => {
424
+ return ((t = this.events)[e] || (t[e] = [])).push(n), () => {
426
425
  var o;
427
426
  this.events[e] = (o = this.events[e]) == null ? void 0 : o.filter((i) => n !== i);
428
427
  };
@@ -430,39 +429,39 @@ let P = () => ({
430
429
  });
431
430
  const de = 250, Le = (e) => {
432
431
  const n = P(), t = [];
433
- let o = -1, i = !1, h = 0;
434
- const U = (d) => {
432
+ let o = -1, i = !1, p = 0;
433
+ const U = (r) => {
435
434
  if (!i) {
436
- const { changes: E } = d, g = performance.now();
437
- if (g - h > de)
435
+ const { changes: E } = r, h = performance.now();
436
+ if (h - p > de)
438
437
  t.splice(o + 1), t.push(E), o = t.length - 1;
439
438
  else {
440
- const S = t.length - 1;
441
- t[S] = se(t[S], E);
439
+ const L = t.length - 1;
440
+ t[L] = se(t[L], E);
442
441
  }
443
- h = g;
442
+ p = h;
444
443
  }
445
444
  i = !1;
446
445
  };
447
- e.observe(U, { origin: O.LOCAL });
448
- const b = (d) => (d == null ? void 0 : d.length) > 0 && e.bulkDeleteAnnotation(d), w = (d) => (d == null ? void 0 : d.length) > 0 && e.bulkAddAnnotation(d, !1), u = (d) => (d == null ? void 0 : d.length) > 0 && e.bulkUpdateAnnotation(d.map(({ oldValue: E }) => E)), T = (d) => (d == null ? void 0 : d.length) > 0 && e.bulkUpdateAnnotation(d.map(({ newValue: E }) => E)), s = (d) => (d == null ? void 0 : d.length) > 0 && e.bulkAddAnnotation(d, !1), f = (d) => (d == null ? void 0 : d.length) > 0 && e.bulkDeleteAnnotation(d);
446
+ e.observe(U, { origin: T.LOCAL });
447
+ const b = (r) => r && r.length > 0 && e.bulkDeleteAnnotation(r), w = (r) => r && r.length > 0 && e.bulkAddAnnotation(r, !1), u = (r) => r && r.length > 0 && e.bulkUpdateAnnotation(r.map(({ oldValue: E }) => E)), S = (r) => r && r.length > 0 && e.bulkUpdateAnnotation(r.map(({ newValue: E }) => E)), s = (r) => r && r.length > 0 && e.bulkAddAnnotation(r, !1), g = (r) => r && r.length > 0 && e.bulkDeleteAnnotation(r);
449
448
  return {
450
449
  canRedo: () => t.length - 1 > o,
451
450
  canUndo: () => o > -1,
452
451
  destroy: () => e.unobserve(U),
453
- on: (d, E) => n.on(d, E),
452
+ on: (r, E) => n.on(r, E),
454
453
  redo: () => {
455
454
  if (t.length - 1 > o) {
456
455
  i = !0;
457
- const { created: d, updated: E, deleted: g } = t[o + 1];
458
- w(d), T(E), f(g), n.emit("redo", t[o + 1]), o += 1;
456
+ const { created: r, updated: E, deleted: h } = t[o + 1];
457
+ w(r), S(E), g(h), n.emit("redo", t[o + 1]), o += 1;
459
458
  }
460
459
  },
461
460
  undo: () => {
462
461
  if (o > -1) {
463
462
  i = !0;
464
- const { created: d, updated: E, deleted: g } = t[o];
465
- b(d), u(E), s(g), n.emit("undo", t[o]), o -= 1;
463
+ const { created: r, updated: E, deleted: h } = t[o];
464
+ b(r), u(E), s(h), n.emit("undo", t[o]), o -= 1;
466
465
  }
467
466
  }
468
467
  };
@@ -472,158 +471,162 @@ const de = 250, Le = (e) => {
472
471
  subscribe: e,
473
472
  set: n
474
473
  };
475
- }, Te = (e, n, t, o) => {
476
- const { store: i, selection: h, hover: U, viewport: b } = e, w = /* @__PURE__ */ new Map();
477
- let u = [], T, s;
478
- const f = (c, m) => {
479
- w.has(c) ? w.get(c).push(m) : w.set(c, [m]);
480
- }, y = (c, m) => {
481
- const d = w.get(c);
482
- d && d.indexOf(m) > 0 && d.splice(d.indexOf(m), 1);
483
- }, A = (c, m, d) => {
484
- w.has(c) && setTimeout(() => {
485
- w.get(c).forEach((E) => {
474
+ }, Oe = (e, n, t, o) => {
475
+ const { store: i, selection: p, hover: U, viewport: b } = e, w = /* @__PURE__ */ new Map();
476
+ let u = [], S, s;
477
+ const g = (a, m) => {
478
+ w.has(a) ? w.get(a).push(m) : w.set(a, [m]);
479
+ }, y = (a, m) => {
480
+ const r = w.get(a);
481
+ r && r.indexOf(m) > 0 && r.splice(r.indexOf(m), 1);
482
+ }, A = (a, m, r) => {
483
+ w.has(a) && setTimeout(() => {
484
+ w.get(a).forEach((E) => {
486
485
  if (t) {
487
- const g = Array.isArray(m) ? m.map((I) => t.serialize(I)) : t.serialize(m), S = d ? d instanceof PointerEvent ? d : t.serialize(d) : void 0;
488
- E(g, S);
486
+ const h = Array.isArray(m) ? m.map((I) => t.serialize(I)) : t.serialize(m), L = r ? r instanceof PointerEvent ? r : t.serialize(r) : void 0;
487
+ E(h, L);
489
488
  } else
490
- E(m, d);
489
+ E(m, r);
491
490
  });
492
491
  }, 1);
493
- }, L = () => {
494
- const { selected: c } = h, m = c.map(({ id: d }) => i.getAnnotation(d));
495
- m.forEach((d) => {
496
- const E = u.find((g) => g.id === d.id);
497
- (!E || !B(E, d)) && A("updateAnnotation", d, E);
498
- }), u = u.map((d) => {
499
- const E = m.find(({ id: g }) => g === d.id);
500
- return E || d;
492
+ }, O = () => {
493
+ const { selected: a } = p, m = (a || []).map(({ id: r }) => i.getAnnotation(r));
494
+ m.forEach((r) => {
495
+ const E = u.find((h) => h.id === r.id);
496
+ (!E || !x(E, r)) && A("updateAnnotation", r, E);
497
+ }), u = u.map((r) => {
498
+ const E = m.find(({ id: h }) => h === r.id);
499
+ return E || r;
501
500
  });
502
501
  };
503
- h.subscribe(({ selected: c }) => {
504
- if (!(u.length === 0 && c.length === 0)) {
505
- if (u.length === 0 && c.length > 0)
506
- u = c.map(({ id: m }) => i.getAnnotation(m));
507
- else if (u.length > 0 && c.length === 0)
502
+ p.subscribe(({ selected: a }) => {
503
+ if (!(u.length === 0 && a.length === 0)) {
504
+ if (u.length === 0 && a.length > 0)
505
+ u = a.map(({ id: m }) => i.getAnnotation(m));
506
+ else if (u.length > 0 && a.length === 0)
508
507
  u.forEach((m) => {
509
- const d = i.getAnnotation(m.id);
510
- d && !B(d, m) && A("updateAnnotation", d, m);
508
+ const r = i.getAnnotation(m.id);
509
+ r && !x(r, m) && A("updateAnnotation", r, m);
511
510
  }), u = [];
512
511
  else {
513
- const m = new Set(u.map((g) => g.id)), d = new Set(c.map(({ id: g }) => g));
514
- u.filter((g) => !d.has(g.id)).forEach((g) => {
515
- const S = i.getAnnotation(g.id);
516
- S && !B(S, g) && A("updateAnnotation", S, g);
512
+ const m = new Set(u.map((h) => h.id)), r = new Set(a.map(({ id: h }) => h));
513
+ u.filter((h) => !r.has(h.id)).forEach((h) => {
514
+ const L = i.getAnnotation(h.id);
515
+ L && !x(L, h) && A("updateAnnotation", L, h);
517
516
  }), u = [
518
517
  // Remove annotations that were deselected
519
- ...u.filter((g) => d.has(g.id)),
518
+ ...u.filter((h) => r.has(h.id)),
520
519
  // Add editable annotations that were selected
521
- ...c.filter(({ id: g }) => !m.has(g)).map(({ id: g }) => i.getAnnotation(g))
520
+ ...a.filter(({ id: h }) => !m.has(h)).map(({ id: h }) => i.getAnnotation(h))
522
521
  ];
523
522
  }
524
523
  A("selectionChanged", u);
525
524
  }
526
- }), U.subscribe((c) => {
527
- !T && c ? A("mouseEnterAnnotation", i.getAnnotation(c)) : T && !c ? A("mouseLeaveAnnotation", i.getAnnotation(T)) : T && c && (A("mouseLeaveAnnotation", i.getAnnotation(T)), A("mouseEnterAnnotation", i.getAnnotation(c))), T = c;
528
- }), b == null || b.subscribe((c) => A("viewportIntersect", c.map(i.getAnnotation))), i.observe((c) => {
529
- o && (s && clearTimeout(s), s = setTimeout(L, 1e3));
530
- const { created: m, deleted: d } = c.changes;
531
- m.forEach((g) => A("createAnnotation", g)), d.forEach((g) => A("deleteAnnotation", g)), c.changes.updated.filter((g) => [
532
- ...g.bodiesCreated || [],
533
- ...g.bodiesDeleted || [],
534
- ...g.bodiesUpdated || []
535
- ].length > 0).forEach(({ oldValue: g, newValue: S }) => {
536
- const I = u.find((N) => N.id === g.id) || g;
537
- u = u.map((N) => N.id === g.id ? S : N), A("updateAnnotation", S, I);
525
+ }), U.subscribe((a) => {
526
+ !S && a ? A("mouseEnterAnnotation", i.getAnnotation(a)) : S && !a ? A("mouseLeaveAnnotation", i.getAnnotation(S)) : S && a && (A("mouseLeaveAnnotation", i.getAnnotation(S)), A("mouseEnterAnnotation", i.getAnnotation(a))), S = a;
527
+ }), b == null || b.subscribe((a) => A("viewportIntersect", a.map((m) => i.getAnnotation(m)))), i.observe((a) => {
528
+ o && (s && clearTimeout(s), s = setTimeout(O, 1e3));
529
+ const { created: m, deleted: r } = a.changes;
530
+ (m || []).forEach((h) => A("createAnnotation", h)), (r || []).forEach((h) => A("deleteAnnotation", h)), (a.changes.updated || []).filter((h) => [
531
+ ...h.bodiesCreated || [],
532
+ ...h.bodiesDeleted || [],
533
+ ...h.bodiesUpdated || []
534
+ ].length > 0).forEach(({ oldValue: h, newValue: L }) => {
535
+ const I = u.find((N) => N.id === h.id) || h;
536
+ u = u.map((N) => N.id === h.id ? L : N), A("updateAnnotation", L, I);
538
537
  });
539
- }, { origin: O.LOCAL }), i.observe((c) => {
538
+ }, { origin: T.LOCAL }), i.observe((a) => {
540
539
  if (u) {
541
- const m = new Set(u.map((E) => E.id)), d = c.changes.updated.filter(({ newValue: E }) => m.has(E.id)).map(({ newValue: E }) => E);
542
- d.length > 0 && (u = u.map((E) => {
543
- const g = d.find((S) => S.id === E.id);
544
- return g || E;
540
+ const m = new Set(u.map((E) => E.id)), r = (a.changes.updated || []).filter(({ newValue: E }) => m.has(E.id)).map(({ newValue: E }) => E);
541
+ r.length > 0 && (u = u.map((E) => {
542
+ const h = r.find((L) => L.id === E.id);
543
+ return h || E;
545
544
  }));
546
545
  }
547
- }, { origin: O.REMOTE });
548
- const C = (c) => (m) => {
549
- const { created: d, deleted: E, updated: g } = m;
550
- d.forEach((S) => A("createAnnotation", S)), E.forEach((S) => A("deleteAnnotation", S)), c ? g.forEach((S) => A("updateAnnotation", S.oldValue, S.newValue)) : g.forEach((S) => A("updateAnnotation", S.newValue, S.oldValue));
546
+ }, { origin: T.REMOTE });
547
+ const C = (a) => (m) => {
548
+ const { created: r, deleted: E, updated: h } = m;
549
+ (r || []).forEach((L) => A("createAnnotation", L)), (E || []).forEach((L) => A("deleteAnnotation", L)), a ? (h || []).forEach((L) => A("updateAnnotation", L.oldValue, L.newValue)) : (h || []).forEach((L) => A("updateAnnotation", L.newValue, L.oldValue));
551
550
  };
552
- return n.on("undo", C(!0)), n.on("redo", C(!1)), { on: f, off: y, emit: A };
553
- }, Oe = (e) => (n) => n.map((t) => e.serialize(t)), re = (e) => (n) => n.reduce((t, o) => {
554
- const { parsed: i, error: h } = e.parse(o);
555
- return h ? {
551
+ return n.on("undo", C(!0)), n.on("redo", C(!1)), { on: g, off: y, emit: A };
552
+ }, Te = (e) => (n) => n.map((t) => e.serialize(t)), re = (e) => (n) => n.reduce((t, o) => {
553
+ const { parsed: i, error: p } = e.parse(o);
554
+ return p ? {
556
555
  parsed: t.parsed,
557
556
  failed: [...t.failed, o]
558
- } : {
557
+ } : i ? {
559
558
  parsed: [...t.parsed, i],
560
559
  failed: t.failed
560
+ } : {
561
+ ...t
561
562
  };
562
563
  }, { parsed: [], failed: [] }), De = (e, n, t) => {
563
- const { store: o, selection: i } = e, h = (C) => {
564
+ const { store: o, selection: i } = e, p = (C) => {
564
565
  if (t) {
565
- const { parsed: c, error: m } = t.parse(C);
566
- c ? o.addAnnotation(c, O.REMOTE) : console.error(m);
566
+ const { parsed: a, error: m } = t.parse(C);
567
+ a ? o.addAnnotation(a, T.REMOTE) : console.error(m);
567
568
  } else
568
- o.addAnnotation(C, O.REMOTE);
569
+ o.addAnnotation(C, T.REMOTE);
569
570
  }, U = () => i.clear(), b = () => o.clear(), w = (C) => {
570
- const c = o.getAnnotation(C);
571
- return t && c ? t.serialize(c) : c;
572
- }, u = () => t ? o.all().map(t.serialize) : o.all(), T = () => {
571
+ const a = o.getAnnotation(C);
572
+ return t && a ? t.serialize(a) : a;
573
+ }, u = () => t ? o.all().map(t.serialize) : o.all(), S = () => {
573
574
  var m;
574
- const c = (((m = i.selected) == null ? void 0 : m.map((d) => d.id)) || []).map((d) => o.getAnnotation(d));
575
- return t ? c.map(t.serialize) : c;
576
- }, s = (C) => fetch(C).then((c) => c.json()).then((c) => (y(c), c)), f = (C) => {
575
+ const a = (((m = i.selected) == null ? void 0 : m.map((r) => r.id)) || []).map((r) => o.getAnnotation(r)).filter(Boolean);
576
+ return t ? a.map(t.serialize) : a;
577
+ }, s = (C) => fetch(C).then((a) => a.json()).then((a) => (y(a), a)), g = (C) => {
577
578
  if (typeof C == "string") {
578
- const c = o.getAnnotation(C);
579
- return o.deleteAnnotation(C), t ? t.serialize(c) : c;
579
+ const a = o.getAnnotation(C);
580
+ if (o.deleteAnnotation(C), a)
581
+ return t ? t.serialize(a) : a;
580
582
  } else {
581
- const c = t ? t.parse(C).parsed : C;
582
- return o.deleteAnnotation(c), C;
583
+ const a = t ? t.parse(C).parsed : C;
584
+ if (a)
585
+ return o.deleteAnnotation(a), C;
583
586
  }
584
587
  }, y = (C) => {
585
588
  if (t) {
586
- const { parsed: c, failed: m } = re(t)(C);
587
- m.length > 0 && console.warn(`Discarded ${m.length} invalid annotations`, m), o.bulkAddAnnotation(c, !0, O.REMOTE);
589
+ const { parsed: a, failed: m } = re(t)(C);
590
+ m.length > 0 && console.warn(`Discarded ${m.length} invalid annotations`, m), o.bulkAddAnnotation(a, !0, T.REMOTE);
588
591
  } else
589
- o.bulkAddAnnotation(C, !0, O.REMOTE);
592
+ o.bulkAddAnnotation(C, !0, T.REMOTE);
590
593
  }, A = (C) => {
591
594
  C ? i.setSelected(C) : i.clear();
592
- }, L = (C) => {
595
+ }, O = (C) => {
593
596
  if (t) {
594
- const c = t.parse(C).parsed, m = t.serialize(o.getAnnotation(c.id));
595
- return o.updateAnnotation(c), m;
597
+ const a = t.parse(C).parsed, m = t.serialize(o.getAnnotation(a.id));
598
+ return o.updateAnnotation(a), m;
596
599
  } else {
597
- const c = o.getAnnotation(C.id);
598
- return o.updateAnnotation(C), c;
600
+ const a = o.getAnnotation(C.id);
601
+ return o.updateAnnotation(C), a;
599
602
  }
600
603
  };
601
604
  return {
602
- addAnnotation: h,
605
+ addAnnotation: p,
603
606
  cancelSelected: U,
604
607
  canRedo: n.canRedo,
605
608
  canUndo: n.canUndo,
606
609
  clearAnnotations: b,
607
610
  getAnnotationById: w,
608
611
  getAnnotations: u,
609
- getSelected: T,
612
+ getSelected: S,
610
613
  loadAnnotations: s,
611
614
  redo: n.redo,
612
- removeAnnotation: f,
615
+ removeAnnotation: g,
613
616
  setAnnotations: y,
614
617
  setSelected: A,
615
618
  undo: n.undo,
616
- updateAnnotation: L
619
+ updateAnnotation: O
617
620
  };
618
621
  };
619
622
  let ae = (e) => crypto.getRandomValues(new Uint8Array(e)), ce = (e, n, t) => {
620
623
  let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * n / e.length);
621
- return (h = n) => {
624
+ return (p = n) => {
622
625
  let U = "";
623
626
  for (; ; ) {
624
627
  let b = t(i), w = i;
625
628
  for (; w--; )
626
- if (U += e[b[w] & o] || "", U.length === h)
629
+ if (U += e[b[w] & o] || "", U.length === p)
627
630
  return U;
628
631
  }
629
632
  };
@@ -632,27 +635,27 @@ const Re = () => ({ isGuest: !0, id: le("1234567890abcdefghijklmnopqrstuvwxyzABC
632
635
  const n = JSON.stringify(e);
633
636
  let t = 0;
634
637
  for (let o = 0, i = n.length; o < i; o++) {
635
- let h = n.charCodeAt(o);
636
- t = (t << 5) - t + h, t |= 0;
638
+ let p = n.charCodeAt(o);
639
+ t = (t << 5) - t + p, t |= 0;
637
640
  }
638
641
  return `${t}`;
639
- }, pe = (e) => e ? typeof e == "object" ? { ...e } : e : void 0, xe = (e, n) => (Array.isArray(e) ? e : [e]).map((t) => {
640
- const { id: o, type: i, purpose: h, value: U, created: b, creator: w, ...u } = t;
642
+ }, pe = (e) => e ? typeof e == "object" ? { ...e } : e : void 0, Be = (e, n) => (Array.isArray(e) ? e : [e]).map((t) => {
643
+ const { id: o, type: i, purpose: p, value: U, created: b, creator: w, ...u } = t;
641
644
  return {
642
645
  id: o || `temp-${fe(t)}`,
643
646
  annotation: n,
644
647
  type: i,
645
- purpose: h,
648
+ purpose: p,
646
649
  value: U,
647
650
  created: b ? new Date(b) : void 0,
648
651
  creator: pe(w),
649
652
  ...u
650
653
  };
651
- }), Be = (e) => e.map((n) => {
652
- var o;
654
+ }), xe = (e) => e.map((n) => {
655
+ var o, i;
653
656
  const t = { ...n };
654
- return delete t.annotation, (o = t.id) != null && o.startsWith("temp-") && delete t.id, t;
655
- }), he = [
657
+ return delete t.annotation, (o = t.id) != null && o.startsWith("temp-") && delete t.id, { ...t, created: (i = t.created) == null ? void 0 : i.toISOString() };
658
+ }), ge = [
656
659
  "#ff7c00",
657
660
  // orange
658
661
  "#1ac938",
@@ -671,74 +674,74 @@ const Re = () => ({ isGuest: !0, id: le("1234567890abcdefghijklmnopqrstuvwxyzABC
671
674
  // cyan
672
675
  "#023eff"
673
676
  // blue
674
- ], ge = () => {
675
- const e = [...he];
677
+ ], he = () => {
678
+ const e = [...ge];
676
679
  return { assignRandomColor: () => {
677
680
  const o = Math.floor(Math.random() * e.length), i = e[o];
678
681
  return e.splice(o, 1), i;
679
682
  }, releaseColor: (o) => e.push(o) };
680
683
  }, me = () => {
681
- const e = ge();
684
+ const e = he();
682
685
  return { addUser: (o, i) => {
683
- const h = e.assignRandomColor();
686
+ const p = e.assignRandomColor();
684
687
  return {
685
688
  label: i.name || i.id,
686
689
  avatar: i.avatar,
687
- color: h
690
+ color: p
688
691
  };
689
692
  }, removeUser: (o) => e.releaseColor(o.appearance.color) };
690
693
  }, Ae = (e, n) => e.every((t) => e.includes(t)) && n.every((t) => e.includes(t)), Ie = ue(), ke = (e = me()) => {
691
- const n = P(), t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = (s, f) => {
694
+ const n = P(), t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = (s, g) => {
692
695
  if (t.has(s)) {
693
- console.warn("Attempt to add user that is already present", s, f);
696
+ console.warn("Attempt to add user that is already present", s, g);
694
697
  return;
695
698
  }
696
- const y = e.addUser(s, f);
699
+ const y = e.addUser(s, g);
697
700
  t.set(s, {
698
- ...f,
701
+ ...g,
699
702
  presenceKey: s,
700
703
  appearance: y
701
704
  });
702
- }, h = (s) => {
703
- const f = t.get(s);
704
- if (!f) {
705
+ }, p = (s) => {
706
+ const g = t.get(s);
707
+ if (!g) {
705
708
  console.warn("Attempt to remove user that is not present", s);
706
709
  return;
707
710
  }
708
- e.removeUser(f), t.delete(s);
711
+ e.removeUser(g), t.delete(s);
709
712
  }, U = (s) => {
710
- const f = new Set(s.map((L) => L.presenceKey)), y = s.filter(({ presenceKey: L }) => !t.has(L)), A = Array.from(t.values()).filter((L) => !f.has(L.presenceKey));
711
- y.forEach(({ presenceKey: L, user: C }) => i(L, C)), A.forEach((L) => {
712
- const { presenceKey: C } = L;
713
- o.has(C) && n.emit("selectionChange", L, null), h(C);
713
+ const g = new Set(s.map((O) => O.presenceKey)), y = s.filter(({ presenceKey: O }) => !t.has(O)), A = Array.from(t.values()).filter((O) => !g.has(O.presenceKey));
714
+ y.forEach(({ presenceKey: O, user: C }) => i(O, C)), A.forEach((O) => {
715
+ const { presenceKey: C } = O;
716
+ o.has(C) && n.emit("selectionChange", O, null), p(C);
714
717
  }), (y.length > 0 || A.length > 0) && n.emit("presence", u());
715
- }, b = (s, f) => {
718
+ }, b = (s, g) => {
716
719
  const y = t.get(s);
717
720
  if (!y) {
718
721
  console.warn("Activity notification from user that is not present");
719
722
  return;
720
723
  }
721
724
  const A = o.get(s);
722
- (!A || !Ae(A, f)) && (o.set(s, f), n.emit("selectionChange", y, f));
723
- }, w = (s, f) => {
725
+ (!A || !Ae(A, g)) && (o.set(s, g), n.emit("selectionChange", y, g));
726
+ }, w = (s, g) => {
724
727
  const y = t.get(s);
725
728
  if (!y) {
726
729
  console.warn("Selection change for user that is not present", s);
727
730
  return;
728
731
  }
729
- f ? o.set(s, f) : o.delete(s), n.emit("selectionChange", y, f);
732
+ g ? o.set(s, g) : o.delete(s), n.emit("selectionChange", y, g);
730
733
  }, u = () => [...Array.from(t.values())];
731
734
  return {
732
735
  getPresentUsers: u,
733
736
  notifyActivity: b,
734
- on: (s, f) => n.on(s, f),
737
+ on: (s, g) => n.on(s, g),
735
738
  syncUsers: U,
736
739
  updateSelection: w
737
740
  };
738
741
  };
739
742
  export {
740
743
  ne as Ignore,
741
- O as Origin,
744
+ T as Origin,
742
745
  Ie as PRESENCE_KEY,
743
746
  q as PointerSelectAction,
744
747
  Re as createAnonymousGuest,
@@ -746,22 +749,22 @@ export {
746
749
  we as createBody,
747
750
  me as createDefaultAppearenceProvider,
748
751
  be as createHoverState,
749
- Te as createLifecyleObserver,
752
+ Oe as createLifecyleObserver,
750
753
  ke as createPresenceState,
751
754
  ve as createSelectionState,
752
755
  ye as createStore,
753
756
  Le as createUndoStack,
754
757
  Se as createViewportState,
755
- ge as defaultColorProvider,
758
+ he as defaultColorProvider,
756
759
  M as diffAnnotations,
757
760
  Ce as getContributors,
758
761
  se as mergeChanges,
759
762
  G as onPointerSelect,
760
763
  re as parseAll,
761
- xe as parseW3CBodies,
764
+ Be as parseW3CBodies,
762
765
  pe as parseW3CUser,
763
- Oe as serializeAll,
764
- Be as serializeW3CBodies,
766
+ Te as serializeAll,
767
+ xe as serializeW3CBodies,
765
768
  oe as shouldNotify,
766
769
  Ue as toSvelteStore
767
770
  };