@annotorious/core 3.0.0-rc.19 → 3.0.0-rc.20

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