@annotorious/core 3.0.2 → 3.0.3

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 W = Object.prototype.hasOwnProperty;
2
- function x(e, n) {
2
+ function I(e, n) {
3
3
  var t, o;
4
4
  if (e === n) return !0;
5
5
  if (e && n && (t = e.constructor) === n.constructor) {
@@ -7,13 +7,13 @@ function x(e, n) {
7
7
  if (t === RegExp) return e.toString() === n.toString();
8
8
  if (t === Array) {
9
9
  if ((o = e.length) === n.length)
10
- for (; o-- && x(e[o], n[o]); ) ;
10
+ for (; o-- && I(e[o], n[o]); ) ;
11
11
  return o === -1;
12
12
  }
13
13
  if (!t || typeof e == "object") {
14
14
  o = 0;
15
15
  for (t in e)
16
- if (W.call(e, t) && ++o && !W.call(n, t) || !(t in n) || !x(e[t], n[t])) return !1;
16
+ if (W.call(e, t) && ++o && !W.call(n, t) || !(t in n) || !I(e[t], n[t])) return !1;
17
17
  return Object.keys(n).length === o;
18
18
  }
19
19
  }
@@ -24,19 +24,19 @@ function _() {
24
24
  function Q(e, n) {
25
25
  return e != e ? n == n : e !== n || e && typeof e == "object" || typeof e == "function";
26
26
  }
27
- const I = [];
27
+ const k = [];
28
28
  function j(e, n = _) {
29
29
  let t;
30
30
  const o = /* @__PURE__ */ new Set();
31
31
  function i(b) {
32
32
  if (Q(e, b) && (e = b, t)) {
33
- const y = !I.length;
34
- for (const g of o)
35
- g[1](), I.push(g, e);
33
+ const y = !k.length;
34
+ for (const h of o)
35
+ h[1](), k.push(h, e);
36
36
  if (y) {
37
- for (let g = 0; g < I.length; g += 2)
38
- I[g][0](I[g + 1]);
39
- I.length = 0;
37
+ for (let h = 0; h < k.length; h += 2)
38
+ k[h][0](k[h + 1]);
39
+ k.length = 0;
40
40
  }
41
41
  }
42
42
  }
@@ -44,14 +44,14 @@ function j(e, n = _) {
44
44
  i(b(e));
45
45
  }
46
46
  function w(b, y = _) {
47
- const g = [b, y];
48
- return o.add(g), o.size === 1 && (t = n(i, f) || _), b(e), () => {
49
- o.delete(g), o.size === 0 && t && (t(), t = null);
47
+ const h = [b, y];
48
+ return o.add(h), o.size === 1 && (t = n(i, f) || _), b(e), () => {
49
+ o.delete(h), o.size === 0 && t && (t(), t = null);
50
50
  };
51
51
  }
52
52
  return { set: i, update: f, subscribe: w };
53
53
  }
54
- const Le = (e) => {
54
+ const Se = (e) => {
55
55
  const { subscribe: n, set: t } = j();
56
56
  let o;
57
57
  return n((i) => o = i), e.observe(({ changes: i }) => {
@@ -69,12 +69,12 @@ const Le = (e) => {
69
69
  };
70
70
  };
71
71
  var X = /* @__PURE__ */ ((e) => (e.EDIT = "EDIT", e.SELECT = "SELECT", e.NONE = "NONE", e))(X || {});
72
- const z = { selected: [] }, Se = (e, n) => {
72
+ const z = { selected: [] }, Ue = (e, n) => {
73
73
  const { subscribe: t, set: o } = j(z);
74
74
  let i = n, f = z;
75
75
  t((m) => f = m);
76
76
  const w = () => {
77
- x(f, z) || o(z);
77
+ I(f, z) || o(z);
78
78
  }, b = () => {
79
79
  var m;
80
80
  return ((m = f.selected) == null ? void 0 : m.length) === 0;
@@ -82,14 +82,14 @@ const z = { selected: [] }, Se = (e, n) => {
82
82
  if (b())
83
83
  return !1;
84
84
  const v = typeof m == "string" ? m : m.id;
85
- return f.selected.some((U) => U.id === v);
86
- }, g = (m, v) => {
87
- const U = e.getAnnotation(m);
88
- if (!U) {
85
+ return f.selected.some((L) => L.id === v);
86
+ }, h = (m, v) => {
87
+ const L = e.getAnnotation(m);
88
+ if (!L) {
89
89
  console.warn("Invalid selection: " + m);
90
90
  return;
91
91
  }
92
- switch (q(U, i)) {
92
+ switch (q(L, i)) {
93
93
  case "EDIT":
94
94
  o({ selected: [{ id: m, editable: !0 }], event: v });
95
95
  break;
@@ -99,19 +99,19 @@ const z = { selected: [] }, Se = (e, n) => {
99
99
  default:
100
100
  o({ selected: [], event: v });
101
101
  }
102
- }, L = (m, v) => {
103
- const U = Array.isArray(m) ? m : [m], T = U.map((a) => e.getAnnotation(a)).filter((a) => !!a);
102
+ }, S = (m, v) => {
103
+ const L = Array.isArray(m) ? m : [m], O = L.map((a) => e.getAnnotation(a)).filter((a) => !!a);
104
104
  o({
105
- selected: T.map((a) => {
105
+ selected: O.map((a) => {
106
106
  const u = v === void 0 ? q(a, i) === "EDIT" : v;
107
107
  return { id: a.id, editable: u };
108
108
  })
109
- }), T.length !== U.length && console.warn("Invalid selection", m);
109
+ }), O.length !== L.length && console.warn("Invalid selection", m);
110
110
  }, r = (m) => {
111
111
  if (b())
112
112
  return !1;
113
113
  const { selected: v } = f;
114
- v.some(({ id: T }) => m.includes(T)) && o({ selected: v.filter(({ id: T }) => !m.includes(T)) });
114
+ v.some(({ id: O }) => m.includes(O)) && o({ selected: v.filter(({ id: O }) => !m.includes(O)) });
115
115
  }, E = (m) => i = m;
116
116
  return e.observe(
117
117
  ({ changes: m }) => r((m.deleted || []).map((v) => v.id))
@@ -128,10 +128,10 @@ const z = { selected: [] }, Se = (e, n) => {
128
128
  clear: w,
129
129
  isEmpty: b,
130
130
  isSelected: y,
131
- setSelected: L,
131
+ setSelected: S,
132
132
  setUserSelectAction: E,
133
133
  subscribe: t,
134
- userSelect: g
134
+ userSelect: h
135
135
  };
136
136
  }, q = (e, n) => typeof n == "function" ? n(e) : n || "EDIT";
137
137
  var D = [];
@@ -157,14 +157,14 @@ function H(e, n, t) {
157
157
  var o = e.random || (e.rng || ee)();
158
158
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Z(o);
159
159
  }
160
- const Oe = (e) => {
160
+ const Te = (e) => {
161
161
  const { creator: n, updatedBy: t } = e.target, o = e.bodies.reduce((i, f) => [...i, f.creator, f.updatedBy].filter(Boolean), []);
162
162
  return [
163
163
  n,
164
164
  t,
165
165
  ...o
166
166
  ].filter((i) => i);
167
- }, Te = (e, n, t, o) => ({
167
+ }, Oe = (e, n, t, o) => ({
168
168
  id: H(),
169
169
  annotation: typeof e == "string" ? e : e.id,
170
170
  created: t || /* @__PURE__ */ new Date(),
@@ -178,8 +178,8 @@ const Oe = (e) => {
178
178
  return e.bodies.filter((o) => !t.has(o.id));
179
179
  }, se = (e, n) => n.bodies.map((t) => {
180
180
  const o = e.bodies.find((i) => i.id === t.id);
181
- return { newBody: t, oldBody: o && !x(o, t) ? o : void 0 };
182
- }).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), ie = (e, n) => !x(e.target, n.target), F = (e, n) => {
181
+ return { newBody: t, oldBody: o && !I(o, t) ? o : void 0 };
182
+ }).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), ie = (e, n) => !I(e.target, n.target), F = (e, n) => {
183
183
  const t = ne(e, n), o = oe(e, n), i = se(e, n);
184
184
  return {
185
185
  oldValue: e,
@@ -190,48 +190,48 @@ const Oe = (e) => {
190
190
  targetUpdated: ie(e, n) ? { oldTarget: e.target, newTarget: n.target } : void 0
191
191
  };
192
192
  };
193
- var de = /* @__PURE__ */ ((e) => (e.BODY_ONLY = "BODY_ONLY", e.TARGET_ONLY = "TARGET_ONLY", e))(de || {}), O = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e))(O || {});
193
+ var de = /* @__PURE__ */ ((e) => (e.BODY_ONLY = "BODY_ONLY", e.TARGET_ONLY = "TARGET_ONLY", e))(de || {}), T = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e.SILENT = "SILENT", e))(T || {});
194
194
  const ae = (e, n) => {
195
195
  var f, w;
196
196
  const { changes: t, origin: o } = n;
197
- if (!(!e.options.origin || e.options.origin === o))
197
+ if (!(e.options.origin ? e.options.origin === o : o !== "SILENT"))
198
198
  return !1;
199
199
  if (e.options.ignore) {
200
- const { ignore: b } = e.options, y = (L) => L && L.length > 0;
200
+ const { ignore: b } = e.options, y = (S) => S && S.length > 0;
201
201
  if (!(y(t.created) || y(t.deleted))) {
202
- const L = (f = t.updated) == null ? void 0 : f.some((E) => y(E.bodiesCreated) || y(E.bodiesDeleted) || y(E.bodiesUpdated)), r = (w = t.updated) == null ? void 0 : w.some((E) => E.targetUpdated);
203
- if (b === "BODY_ONLY" && L && !r || b === "TARGET_ONLY" && r && !L)
202
+ const S = (f = t.updated) == null ? void 0 : f.some((E) => y(E.bodiesCreated) || y(E.bodiesDeleted) || y(E.bodiesUpdated)), r = (w = t.updated) == null ? void 0 : w.some((E) => E.targetUpdated);
203
+ if (b === "BODY_ONLY" && S && !r || b === "TARGET_ONLY" && r && !S)
204
204
  return !1;
205
205
  }
206
206
  }
207
207
  if (e.options.annotations) {
208
208
  const b = /* @__PURE__ */ new Set([
209
- ...(t.created || []).map((g) => g.id),
210
- ...(t.deleted || []).map((g) => g.id),
211
- ...(t.updated || []).map(({ oldValue: g }) => g.id)
209
+ ...(t.created || []).map((h) => h.id),
210
+ ...(t.deleted || []).map((h) => h.id),
211
+ ...(t.updated || []).map(({ oldValue: h }) => h.id)
212
212
  ]);
213
- return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((g) => b.has(g));
213
+ return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((h) => b.has(h));
214
214
  } else
215
215
  return !0;
216
216
  }, re = (e, n) => {
217
217
  const t = new Set((e.created || []).map((r) => r.id)), o = new Set((e.updated || []).map(({ newValue: r }) => r.id)), i = new Set((n.created || []).map((r) => r.id)), f = new Set((n.deleted || []).map((r) => r.id)), w = new Set((n.updated || []).map(({ oldValue: r }) => r.id)), b = new Set((n.updated || []).filter(({ oldValue: r }) => t.has(r.id) || o.has(r.id)).map(({ oldValue: r }) => r.id)), y = [
218
218
  ...(e.created || []).filter((r) => !f.has(r.id)).map((r) => w.has(r.id) ? n.updated.find(({ oldValue: E }) => E.id === r.id).newValue : r),
219
219
  ...n.created || []
220
- ], g = [
220
+ ], h = [
221
221
  ...(e.deleted || []).filter((r) => !i.has(r.id)),
222
222
  ...(n.deleted || []).filter((r) => !t.has(r.id))
223
- ], L = [
223
+ ], S = [
224
224
  ...(e.updated || []).filter(({ newValue: r }) => !f.has(r.id)).map((r) => {
225
225
  const { oldValue: E, newValue: m } = r;
226
226
  if (w.has(m.id)) {
227
- const v = n.updated.find((U) => U.oldValue.id === m.id).newValue;
227
+ const v = n.updated.find((L) => L.oldValue.id === m.id).newValue;
228
228
  return F(E, v);
229
229
  } else
230
230
  return r;
231
231
  }),
232
232
  ...(n.updated || []).filter(({ oldValue: r }) => !b.has(r.id))
233
233
  ];
234
- return { created: y, deleted: g, updated: L };
234
+ return { created: y, deleted: h, updated: S };
235
235
  }, V = (e) => {
236
236
  const n = e.id === void 0 ? H() : e.id;
237
237
  return {
@@ -247,7 +247,9 @@ const ae = (e, n) => {
247
247
  }
248
248
  };
249
249
  }, ce = (e) => e.id !== void 0, De = () => {
250
- const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (d, c = {}) => t.push({ onChange: d, options: c }), i = (d) => {
250
+ const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (d, c = {}) => {
251
+ t.push({ onChange: d, options: c });
252
+ }, i = (d) => {
251
253
  const c = t.findIndex((l) => l.onChange == d);
252
254
  c > -1 && t.splice(c, 1);
253
255
  }, f = (d, c) => {
@@ -263,30 +265,30 @@ const ae = (e, n) => {
263
265
  t.forEach((p) => {
264
266
  ae(p, l) && p.onChange(l);
265
267
  });
266
- }, w = (d, c = O.LOCAL) => {
268
+ }, w = (d, c = T.LOCAL) => {
267
269
  if (d.id && e.get(d.id))
268
270
  throw Error(`Cannot add annotation ${d.id} - exists already`);
269
271
  {
270
272
  const p = V(d);
271
- e.set(p.id, p), p.bodies.forEach((S) => n.set(S.id, p.id)), f(c, { created: [p] });
273
+ e.set(p.id, p), p.bodies.forEach((U) => n.set(U.id, p.id)), f(c, { created: [p] });
272
274
  }
273
275
  }, b = (d, c) => {
274
- const l = V(typeof d == "string" ? c : d), p = typeof d == "string" ? d : d.id, S = p && e.get(p);
275
- if (S) {
276
- const C = F(S, l);
277
- return p === l.id ? e.set(p, l) : (e.delete(p), e.set(l.id, l)), S.bodies.forEach((B) => n.delete(B.id)), l.bodies.forEach((B) => n.set(B.id, l.id)), C;
276
+ const l = V(typeof d == "string" ? c : d), p = typeof d == "string" ? d : d.id, U = p && e.get(p);
277
+ if (U) {
278
+ const C = F(U, l);
279
+ return p === l.id ? e.set(p, l) : (e.delete(p), e.set(l.id, l)), U.bodies.forEach((B) => n.delete(B.id)), l.bodies.forEach((B) => n.set(B.id, l.id)), C;
278
280
  } else
279
281
  console.warn(`Cannot update annotation ${p} - does not exist`);
280
- }, y = (d, c = O.LOCAL, l = O.LOCAL) => {
281
- const p = ce(c) ? l : c, S = b(d, c);
282
- S && f(p, { updated: [S] });
283
- }, g = (d, c = O.LOCAL) => {
284
- const l = d.reduce((p, S) => {
285
- const C = b(S);
282
+ }, y = (d, c = T.LOCAL, l = T.LOCAL) => {
283
+ const p = ce(c) ? l : c, U = b(d, c);
284
+ U && f(p, { updated: [U] });
285
+ }, h = (d, c = T.LOCAL) => {
286
+ const l = d.reduce((p, U) => {
287
+ const C = b(U);
286
288
  return C ? [...p, C] : p;
287
289
  }, []);
288
290
  l.length > 0 && f(c, { updated: l });
289
- }, L = (d, c = O.LOCAL) => {
291
+ }, S = (d, c = T.LOCAL) => {
290
292
  const l = e.get(d.annotation);
291
293
  if (l) {
292
294
  const p = {
@@ -300,23 +302,23 @@ const ae = (e, n) => {
300
302
  }] });
301
303
  } else
302
304
  console.warn(`Attempt to add body to missing annotation: ${d.annotation}`);
303
- }, r = () => [...e.values()], E = (d = O.LOCAL) => {
305
+ }, r = () => [...e.values()], E = (d = T.LOCAL) => {
304
306
  const c = [...e.values()];
305
307
  e.clear(), n.clear(), f(d, { deleted: c });
306
- }, m = (d, c = !0, l = O.LOCAL) => {
308
+ }, m = (d, c = !0, l = T.LOCAL) => {
307
309
  const p = d.map(V);
308
310
  if (c) {
309
- const S = [...e.values()];
311
+ const U = [...e.values()];
310
312
  e.clear(), n.clear(), p.forEach((C) => {
311
313
  e.set(C.id, C), C.bodies.forEach((B) => n.set(B.id, C.id));
312
- }), f(l, { created: p, deleted: S });
314
+ }), f(l, { created: p, deleted: U });
313
315
  } else {
314
- const S = d.reduce((C, B) => {
316
+ const U = d.reduce((C, B) => {
315
317
  const P = B.id && e.get(B.id);
316
318
  return P ? [...C, P] : C;
317
319
  }, []);
318
- if (S.length > 0)
319
- throw Error(`Bulk insert would overwrite the following annotations: ${S.map((C) => C.id).join(", ")}`);
320
+ if (U.length > 0)
321
+ throw Error(`Bulk insert would overwrite the following annotations: ${U.map((C) => C.id).join(", ")}`);
320
322
  p.forEach((C) => {
321
323
  e.set(C.id, C), C.bodies.forEach((B) => n.set(B.id, C.id));
322
324
  }), f(l, { created: p });
@@ -326,12 +328,12 @@ const ae = (e, n) => {
326
328
  if (l)
327
329
  return e.delete(c), l.bodies.forEach((p) => n.delete(p.id)), l;
328
330
  console.warn(`Attempt to delete missing annotation: ${c}`);
329
- }, U = (d, c = O.LOCAL) => {
331
+ }, L = (d, c = T.LOCAL) => {
330
332
  const l = v(d);
331
333
  l && f(c, { deleted: [l] });
332
- }, T = (d, c = O.LOCAL) => {
333
- const l = d.reduce((p, S) => {
334
- const C = v(S);
334
+ }, O = (d, c = T.LOCAL) => {
335
+ const l = d.reduce((p, U) => {
336
+ const C = v(U);
335
337
  return C ? [...p, C] : p;
336
338
  }, []);
337
339
  l.length > 0 && f(c, { deleted: l });
@@ -354,19 +356,19 @@ const ae = (e, n) => {
354
356
  console.warn(`Attempt to delete missing body ${d.id} from annotation ${d.annotation}`);
355
357
  } else
356
358
  console.warn(`Attempt to delete body from missing annotation ${d.annotation}`);
357
- }, u = (d, c = O.LOCAL) => {
359
+ }, u = (d, c = T.LOCAL) => {
358
360
  const l = a(d);
359
361
  l && f(c, { updated: [l] });
360
- }, s = (d, c = O.LOCAL) => {
362
+ }, s = (d, c = T.LOCAL) => {
361
363
  const l = d.map((p) => a(p)).filter(Boolean);
362
364
  l.length > 0 && f(c, { updated: l });
363
- }, h = (d) => {
365
+ }, g = (d) => {
364
366
  const c = e.get(d);
365
367
  return c ? { ...c } : void 0;
366
368
  }, A = (d) => {
367
369
  const c = n.get(d);
368
370
  if (c) {
369
- const p = h(c).bodies.find((S) => S.id === d);
371
+ const p = g(c).bodies.find((U) => U.id === d);
370
372
  if (p)
371
373
  return p;
372
374
  console.error(`Store integrity error: body ${d} in index, but not in annotation`);
@@ -377,21 +379,21 @@ const ae = (e, n) => {
377
379
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
378
380
  const l = e.get(d.annotation);
379
381
  if (l) {
380
- const p = l.bodies.find((C) => C.id === d.id), S = {
382
+ const p = l.bodies.find((C) => C.id === d.id), U = {
381
383
  ...l,
382
384
  bodies: l.bodies.map((C) => C.id === p.id ? c : C)
383
385
  };
384
- return e.set(l.id, S), p.id !== c.id && (n.delete(p.id), n.set(c.id, S.id)), {
386
+ return e.set(l.id, U), p.id !== c.id && (n.delete(p.id), n.set(c.id, U.id)), {
385
387
  oldValue: l,
386
- newValue: S,
388
+ newValue: U,
387
389
  bodiesUpdated: [{ oldBody: p, newBody: c }]
388
390
  };
389
391
  } else
390
392
  console.warn(`Attempt to add body to missing annotation ${d.annotation}`);
391
- }, N = (d, c, l = O.LOCAL) => {
393
+ }, N = (d, c, l = T.LOCAL) => {
392
394
  const p = R(d, c);
393
395
  p && f(l, { updated: [p] });
394
- }, k = (d, c = O.LOCAL) => {
396
+ }, x = (d, c = T.LOCAL) => {
395
397
  const l = d.map((p) => R({ id: p.id, annotation: p.annotation }, p)).filter(Boolean);
396
398
  f(c, { updated: l });
397
399
  }, M = (d) => {
@@ -417,27 +419,27 @@ const ae = (e, n) => {
417
419
  };
418
420
  return {
419
421
  addAnnotation: w,
420
- addBody: L,
422
+ addBody: S,
421
423
  all: r,
422
424
  bulkAddAnnotation: m,
423
- bulkDeleteAnnotation: T,
425
+ bulkDeleteAnnotation: O,
424
426
  bulkDeleteBodies: s,
425
- bulkUpdateAnnotation: g,
426
- bulkUpdateBodies: k,
427
- bulkUpdateTargets: (d, c = O.LOCAL) => {
427
+ bulkUpdateAnnotation: h,
428
+ bulkUpdateBodies: x,
429
+ bulkUpdateTargets: (d, c = T.LOCAL) => {
428
430
  const l = d.map((p) => M(p)).filter(Boolean);
429
431
  l.length > 0 && f(c, { updated: l });
430
432
  },
431
433
  clear: E,
432
- deleteAnnotation: U,
434
+ deleteAnnotation: L,
433
435
  deleteBody: u,
434
- getAnnotation: h,
436
+ getAnnotation: g,
435
437
  getBody: A,
436
438
  observe: o,
437
439
  unobserve: i,
438
440
  updateAnnotation: y,
439
441
  updateBody: N,
440
- updateTarget: (d, c = O.LOCAL) => {
442
+ updateTarget: (d, c = T.LOCAL) => {
441
443
  const l = M(d);
442
444
  l && f(c, { updated: [l] });
443
445
  }
@@ -468,127 +470,127 @@ const le = 250, Be = (e) => {
468
470
  let o = -1, i = !1, f = 0;
469
471
  const w = (s) => {
470
472
  if (!i) {
471
- const { changes: h } = s, A = performance.now();
473
+ const { changes: g } = s, A = performance.now();
472
474
  if (A - f > le)
473
- t.splice(o + 1), t.push(h), o = t.length - 1;
475
+ t.splice(o + 1), t.push(g), o = t.length - 1;
474
476
  else {
475
477
  const R = t.length - 1;
476
- t[R] = re(t[R], h);
478
+ t[R] = re(t[R], g);
477
479
  }
478
480
  f = A;
479
481
  }
480
482
  i = !1;
481
483
  };
482
- e.observe(w, { origin: O.LOCAL });
483
- const b = (s) => s && s.length > 0 && e.bulkDeleteAnnotation(s), y = (s) => s && s.length > 0 && e.bulkAddAnnotation(s, !1), g = (s) => s && s.length > 0 && e.bulkUpdateAnnotation(s.map(({ oldValue: h }) => h)), L = (s) => s && s.length > 0 && e.bulkUpdateAnnotation(s.map(({ newValue: h }) => h)), r = (s) => s && s.length > 0 && e.bulkAddAnnotation(s, !1), E = (s) => s && s.length > 0 && e.bulkDeleteAnnotation(s);
484
+ e.observe(w, { origin: T.LOCAL });
485
+ const b = (s) => s && s.length > 0 && e.bulkDeleteAnnotation(s), y = (s) => s && s.length > 0 && e.bulkAddAnnotation(s, !1), h = (s) => s && s.length > 0 && e.bulkUpdateAnnotation(s.map(({ oldValue: g }) => g)), S = (s) => s && s.length > 0 && e.bulkUpdateAnnotation(s.map(({ newValue: g }) => g)), r = (s) => s && s.length > 0 && e.bulkAddAnnotation(s, !1), E = (s) => s && s.length > 0 && e.bulkDeleteAnnotation(s);
484
486
  return {
485
487
  canRedo: () => t.length - 1 > o,
486
488
  canUndo: () => o > -1,
487
489
  destroy: () => e.unobserve(w),
488
- on: (s, h) => n.on(s, h),
490
+ on: (s, g) => n.on(s, g),
489
491
  redo: () => {
490
492
  if (t.length - 1 > o) {
491
493
  i = !0;
492
- const { created: s, updated: h, deleted: A } = t[o + 1];
493
- y(s), L(h), E(A), n.emit("redo", t[o + 1]), o += 1;
494
+ const { created: s, updated: g, deleted: A } = t[o + 1];
495
+ y(s), S(g), E(A), n.emit("redo", t[o + 1]), o += 1;
494
496
  }
495
497
  },
496
498
  undo: () => {
497
499
  if (o > -1) {
498
500
  i = !0;
499
- const { created: s, updated: h, deleted: A } = t[o];
500
- b(s), g(h), r(A), n.emit("undo", t[o]), o -= 1;
501
+ const { created: s, updated: g, deleted: A } = t[o];
502
+ b(s), h(g), r(A), n.emit("undo", t[o]), o -= 1;
501
503
  }
502
504
  }
503
505
  };
504
- }, xe = () => {
506
+ }, Ie = () => {
505
507
  const { subscribe: e, set: n } = j([]);
506
508
  return {
507
509
  subscribe: e,
508
510
  set: n
509
511
  };
510
- }, ke = (e, n, t, o) => {
512
+ }, xe = (e, n, t, o) => {
511
513
  const { store: i, selection: f, hover: w, viewport: b } = e, y = /* @__PURE__ */ new Map();
512
- let g = [], L, r;
514
+ let h = [], S, r;
513
515
  const E = (a, u) => {
514
516
  y.has(a) ? y.get(a).push(u) : y.set(a, [u]);
515
517
  }, m = (a, u) => {
516
518
  const s = y.get(a);
517
519
  if (s) {
518
- const h = s.indexOf(u);
519
- h !== -1 && s.splice(h, 1);
520
+ const g = s.indexOf(u);
521
+ g !== -1 && s.splice(g, 1);
520
522
  }
521
523
  }, v = (a, u, s) => {
522
524
  y.has(a) && setTimeout(() => {
523
- y.get(a).forEach((h) => {
525
+ y.get(a).forEach((g) => {
524
526
  if (t) {
525
527
  const A = Array.isArray(u) ? u.map((N) => t.serialize(N)) : t.serialize(u), R = s ? s instanceof PointerEvent ? s : t.serialize(s) : void 0;
526
- h(A, R);
528
+ g(A, R);
527
529
  } else
528
- h(u, s);
530
+ g(u, s);
529
531
  });
530
532
  }, 1);
531
- }, U = () => {
533
+ }, L = () => {
532
534
  const { selected: a } = f, u = (a || []).map(({ id: s }) => i.getAnnotation(s));
533
535
  u.forEach((s) => {
534
- const h = g.find((A) => A.id === s.id);
535
- (!h || !x(h, s)) && v("updateAnnotation", s, h);
536
- }), g = g.map((s) => {
537
- const h = u.find(({ id: A }) => A === s.id);
538
- return h || s;
536
+ const g = h.find((A) => A.id === s.id);
537
+ (!g || !I(g, s)) && v("updateAnnotation", s, g);
538
+ }), h = h.map((s) => {
539
+ const g = u.find(({ id: A }) => A === s.id);
540
+ return g || s;
539
541
  });
540
542
  };
541
543
  f.subscribe(({ selected: a }) => {
542
- if (!(g.length === 0 && a.length === 0)) {
543
- if (g.length === 0 && a.length > 0)
544
- g = a.map(({ id: u }) => i.getAnnotation(u));
545
- else if (g.length > 0 && a.length === 0)
546
- g.forEach((u) => {
544
+ if (!(h.length === 0 && a.length === 0)) {
545
+ if (h.length === 0 && a.length > 0)
546
+ h = a.map(({ id: u }) => i.getAnnotation(u));
547
+ else if (h.length > 0 && a.length === 0)
548
+ h.forEach((u) => {
547
549
  const s = i.getAnnotation(u.id);
548
- s && !x(s, u) && v("updateAnnotation", s, u);
549
- }), g = [];
550
+ s && !I(s, u) && v("updateAnnotation", s, u);
551
+ }), h = [];
550
552
  else {
551
- const u = new Set(g.map((A) => A.id)), s = new Set(a.map(({ id: A }) => A));
552
- g.filter((A) => !s.has(A.id)).forEach((A) => {
553
+ const u = new Set(h.map((A) => A.id)), s = new Set(a.map(({ id: A }) => A));
554
+ h.filter((A) => !s.has(A.id)).forEach((A) => {
553
555
  const R = i.getAnnotation(A.id);
554
- R && !x(R, A) && v("updateAnnotation", R, A);
555
- }), g = [
556
+ R && !I(R, A) && v("updateAnnotation", R, A);
557
+ }), h = [
556
558
  // Remove annotations that were deselected
557
- ...g.filter((A) => s.has(A.id)),
559
+ ...h.filter((A) => s.has(A.id)),
558
560
  // Add editable annotations that were selected
559
561
  ...a.filter(({ id: A }) => !u.has(A)).map(({ id: A }) => i.getAnnotation(A))
560
562
  ];
561
563
  }
562
- v("selectionChanged", g);
564
+ v("selectionChanged", h);
563
565
  }
564
566
  }), w.subscribe((a) => {
565
- !L && a ? v("mouseEnterAnnotation", i.getAnnotation(a)) : L && !a ? v("mouseLeaveAnnotation", i.getAnnotation(L)) : L && a && (v("mouseLeaveAnnotation", i.getAnnotation(L)), v("mouseEnterAnnotation", i.getAnnotation(a))), L = a;
567
+ !S && a ? v("mouseEnterAnnotation", i.getAnnotation(a)) : S && !a ? v("mouseLeaveAnnotation", i.getAnnotation(S)) : S && a && (v("mouseLeaveAnnotation", i.getAnnotation(S)), v("mouseEnterAnnotation", i.getAnnotation(a))), S = a;
566
568
  }), b == null || b.subscribe((a) => v("viewportIntersect", a.map((u) => i.getAnnotation(u)))), i.observe((a) => {
567
- o && (r && clearTimeout(r), r = setTimeout(U, 1e3));
569
+ o && (r && clearTimeout(r), r = setTimeout(L, 1e3));
568
570
  const { created: u, deleted: s } = a.changes;
569
571
  (u || []).forEach((A) => v("createAnnotation", A)), (s || []).forEach((A) => v("deleteAnnotation", A)), (a.changes.updated || []).filter((A) => [
570
572
  ...A.bodiesCreated || [],
571
573
  ...A.bodiesDeleted || [],
572
574
  ...A.bodiesUpdated || []
573
575
  ].length > 0).forEach(({ oldValue: A, newValue: R }) => {
574
- const N = g.find((k) => k.id === A.id) || A;
575
- g = g.map((k) => k.id === A.id ? R : k), v("updateAnnotation", R, N);
576
+ const N = h.find((x) => x.id === A.id) || A;
577
+ h = h.map((x) => x.id === A.id ? R : x), v("updateAnnotation", R, N);
576
578
  });
577
- }, { origin: O.LOCAL }), i.observe((a) => {
578
- if (g) {
579
- const u = new Set(g.map((h) => h.id)), s = (a.changes.updated || []).filter(({ newValue: h }) => u.has(h.id)).map(({ newValue: h }) => h);
580
- s.length > 0 && (g = g.map((h) => {
581
- const A = s.find((R) => R.id === h.id);
582
- return A || h;
579
+ }, { origin: T.LOCAL }), i.observe((a) => {
580
+ if (h) {
581
+ const u = new Set(h.map((g) => g.id)), s = (a.changes.updated || []).filter(({ newValue: g }) => u.has(g.id)).map(({ newValue: g }) => g);
582
+ s.length > 0 && (h = h.map((g) => {
583
+ const A = s.find((R) => R.id === g.id);
584
+ return A || g;
583
585
  }));
584
586
  }
585
- }, { origin: O.REMOTE });
586
- const T = (a) => (u) => {
587
+ }, { origin: T.REMOTE });
588
+ const O = (a) => (u) => {
587
589
  const { updated: s } = u;
588
- a ? (s || []).forEach((h) => v("updateAnnotation", h.oldValue, h.newValue)) : (s || []).forEach((h) => v("updateAnnotation", h.newValue, h.oldValue));
590
+ a ? (s || []).forEach((g) => v("updateAnnotation", g.oldValue, g.newValue)) : (s || []).forEach((g) => v("updateAnnotation", g.newValue, g.oldValue));
589
591
  };
590
- return n.on("undo", T(!0)), n.on("redo", T(!1)), { on: E, off: m, emit: v };
591
- }, Ie = (e) => (n) => n.map((t) => e.serialize(t)), ue = (e) => (n) => n.reduce((t, o) => {
592
+ return n.on("undo", O(!0)), n.on("redo", O(!1)), { on: E, off: m, emit: v };
593
+ }, ke = (e) => (n) => n.map((t) => e.serialize(t)), ue = (e) => (n) => n.reduce((t, o) => {
592
594
  const { parsed: i, error: f } = e.parse(o);
593
595
  return f ? {
594
596
  parsed: t.parsed,
@@ -603,15 +605,15 @@ const le = 250, Be = (e) => {
603
605
  const { store: o, selection: i } = e, f = (a) => {
604
606
  if (t) {
605
607
  const { parsed: u, error: s } = t.parse(a);
606
- u ? o.addAnnotation(u, O.REMOTE) : console.error(s);
608
+ u ? o.addAnnotation(u, T.REMOTE) : console.error(s);
607
609
  } else
608
- o.addAnnotation(a, O.REMOTE);
610
+ o.addAnnotation(a, T.REMOTE);
609
611
  }, w = () => i.clear(), b = () => o.clear(), y = (a) => {
610
612
  const u = o.getAnnotation(a);
611
613
  return t && u ? t.serialize(u) : u;
612
- }, g = () => t ? o.all().map(t.serialize) : o.all(), L = () => {
614
+ }, h = () => t ? o.all().map(t.serialize) : o.all(), S = () => {
613
615
  var s;
614
- const u = (((s = i.selected) == null ? void 0 : s.map((h) => h.id)) || []).map((h) => o.getAnnotation(h)).filter(Boolean);
616
+ const u = (((s = i.selected) == null ? void 0 : s.map((g) => g.id)) || []).map((g) => o.getAnnotation(g)).filter(Boolean);
615
617
  return t ? u.map(t.serialize) : u;
616
618
  }, r = (a, u = !0) => fetch(a).then((s) => s.json()).then((s) => (m(s, u), s)), E = (a) => {
617
619
  if (typeof a == "string") {
@@ -625,15 +627,15 @@ const le = 250, Be = (e) => {
625
627
  }
626
628
  }, m = (a, u = !0) => {
627
629
  if (t) {
628
- const { parsed: s, failed: h } = ue(t)(a);
629
- h.length > 0 && console.warn(`Discarded ${h.length} invalid annotations`, h), o.bulkAddAnnotation(s, u, O.REMOTE);
630
+ const { parsed: s, failed: g } = ue(t)(a);
631
+ g.length > 0 && console.warn(`Discarded ${g.length} invalid annotations`, g), o.bulkAddAnnotation(s, u, T.REMOTE);
630
632
  } else
631
- o.bulkAddAnnotation(a, u, O.REMOTE);
633
+ o.bulkAddAnnotation(a, u, T.REMOTE);
632
634
  }, v = (a, u) => {
633
635
  a ? i.setSelected(a, u) : i.clear();
634
- }, U = (a) => {
636
+ }, L = (a) => {
635
637
  i.clear(), i.setUserSelectAction(a);
636
- }, T = (a) => {
638
+ }, O = (a) => {
637
639
  if (t) {
638
640
  const u = t.parse(a).parsed, s = t.serialize(o.getAnnotation(u.id));
639
641
  return o.updateAnnotation(u), s;
@@ -649,19 +651,19 @@ const le = 250, Be = (e) => {
649
651
  canUndo: n.canUndo,
650
652
  clearAnnotations: b,
651
653
  getAnnotationById: y,
652
- getAnnotations: g,
653
- getSelected: L,
654
+ getAnnotations: h,
655
+ getSelected: S,
654
656
  loadAnnotations: r,
655
657
  redo: n.redo,
656
658
  removeAnnotation: E,
657
659
  setAnnotations: m,
658
660
  setSelected: v,
659
- setUserSelectAction: U,
661
+ setUserSelectAction: L,
660
662
  undo: n.undo,
661
- updateAnnotation: T
663
+ updateAnnotation: O
662
664
  };
663
665
  }, fe = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
664
- let pe = (e) => crypto.getRandomValues(new Uint8Array(e)), ge = (e, n, t) => {
666
+ let pe = (e) => crypto.getRandomValues(new Uint8Array(e)), he = (e, n, t) => {
665
667
  let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * n / e.length);
666
668
  return (f = n) => {
667
669
  let w = "";
@@ -671,13 +673,13 @@ let pe = (e) => crypto.getRandomValues(new Uint8Array(e)), ge = (e, n, t) => {
671
673
  if (w += e[b[y] & o] || "", w.length === f) return w;
672
674
  }
673
675
  };
674
- }, he = (e, n = 21) => ge(e, n, pe), me = (e = 21) => {
676
+ }, ge = (e, n = 21) => he(e, n, pe), me = (e = 21) => {
675
677
  let n = "", t = crypto.getRandomValues(new Uint8Array(e));
676
678
  for (; e--; )
677
679
  n += fe[t[e] & 63];
678
680
  return n;
679
681
  };
680
- const ze = () => ({ isGuest: !0, id: he("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Ae = (e) => {
682
+ const ze = () => ({ isGuest: !0, id: ge("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Ae = (e) => {
681
683
  const n = JSON.stringify(e);
682
684
  let t = 0;
683
685
  for (let o = 0, i = n.length; o < i; o++) {
@@ -686,17 +688,17 @@ const ze = () => ({ isGuest: !0, id: he("1234567890abcdefghijklmnopqrstuvwxyzABC
686
688
  }
687
689
  return `${t}`;
688
690
  }, be = (e) => e ? typeof e == "object" ? { ...e } : e : void 0, $e = (e, n) => (Array.isArray(e) ? e : [e]).map((t) => {
689
- const { id: o, type: i, purpose: f, value: w, created: b, modified: y, creator: g, ...L } = t;
691
+ const { id: o, type: i, purpose: f, value: w, created: b, modified: y, creator: h, ...S } = t;
690
692
  return {
691
693
  id: o || `temp-${Ae(t)}`,
692
694
  annotation: n,
693
695
  type: i,
694
696
  purpose: f,
695
697
  value: w,
696
- creator: be(g),
698
+ creator: be(h),
697
699
  created: b ? new Date(b) : void 0,
698
700
  updated: y ? new Date(y) : void 0,
699
- ...L
701
+ ...S
700
702
  };
701
703
  }), Ve = (e) => e.map((n) => {
702
704
  var b;
@@ -761,11 +763,11 @@ const ze = () => ({ isGuest: !0, id: he("1234567890abcdefghijklmnopqrstuvwxyzABC
761
763
  }
762
764
  e.removeUser(E), t.delete(r);
763
765
  }, w = (r) => {
764
- const E = new Set(r.map((U) => U.presenceKey)), m = r.filter(({ presenceKey: U }) => !t.has(U)), v = Array.from(t.values()).filter((U) => !E.has(U.presenceKey));
765
- m.forEach(({ presenceKey: U, user: T }) => i(U, T)), v.forEach((U) => {
766
- const { presenceKey: T } = U;
767
- o.has(T) && n.emit("selectionChange", U, null), f(T);
768
- }), (m.length > 0 || v.length > 0) && n.emit("presence", g());
766
+ const E = new Set(r.map((L) => L.presenceKey)), m = r.filter(({ presenceKey: L }) => !t.has(L)), v = Array.from(t.values()).filter((L) => !E.has(L.presenceKey));
767
+ m.forEach(({ presenceKey: L, user: O }) => i(L, O)), v.forEach((L) => {
768
+ const { presenceKey: O } = L;
769
+ o.has(O) && n.emit("selectionChange", L, null), f(O);
770
+ }), (m.length > 0 || v.length > 0) && n.emit("presence", h());
769
771
  }, b = (r, E) => {
770
772
  const m = t.get(r);
771
773
  if (!m) {
@@ -781,9 +783,9 @@ const ze = () => ({ isGuest: !0, id: he("1234567890abcdefghijklmnopqrstuvwxyzABC
781
783
  return;
782
784
  }
783
785
  E ? o.set(r, E) : o.delete(r), n.emit("selectionChange", m, E);
784
- }, g = () => [...Array.from(t.values())];
786
+ }, h = () => [...Array.from(t.values())];
785
787
  return {
786
- getPresentUsers: g,
788
+ getPresentUsers: h,
787
789
  notifyActivity: b,
788
790
  on: (r, E) => n.on(r, E),
789
791
  syncUsers: w,
@@ -792,29 +794,29 @@ const ze = () => ({ isGuest: !0, id: he("1234567890abcdefghijklmnopqrstuvwxyzABC
792
794
  };
793
795
  export {
794
796
  de as Ignore,
795
- O as Origin,
797
+ T as Origin,
796
798
  _e as PRESENCE_KEY,
797
799
  X as UserSelectAction,
798
800
  ze as createAnonymousGuest,
799
801
  Ne as createBaseAnnotator,
800
- Te as createBody,
802
+ Oe as createBody,
801
803
  ye as createDefaultAppearanceProvider,
802
- Le as createHoverState,
803
- ke as createLifecycleObserver,
804
+ Se as createHoverState,
805
+ xe as createLifecycleObserver,
804
806
  Ye as createPresenceState,
805
- Se as createSelectionState,
807
+ Ue as createSelectionState,
806
808
  De as createStore,
807
809
  Be as createUndoStack,
808
- xe as createViewportState,
810
+ Ie as createViewportState,
809
811
  Ee as defaultColorProvider,
810
812
  F as diffAnnotations,
811
- Oe as getContributors,
813
+ Te as getContributors,
812
814
  re as mergeChanges,
813
815
  q as onUserSelect,
814
816
  ue as parseAll,
815
817
  $e as parseW3CBodies,
816
818
  be as parseW3CUser,
817
- Ie as serializeAll,
819
+ ke as serializeAll,
818
820
  Ve as serializeW3CBodies,
819
821
  ae as shouldNotify,
820
822
  Re as toSvelteStore