@annotorious/core 3.4.6 → 3.5.0

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 W = Object.prototype.hasOwnProperty;
1
+ var M = Object.prototype.hasOwnProperty;
2
2
  function N(e, t) {
3
3
  var n, o;
4
4
  if (e === t) return !0;
@@ -13,7 +13,7 @@ function N(e, t) {
13
13
  if (!n || typeof e == "object") {
14
14
  o = 0;
15
15
  for (n in e)
16
- if (W.call(e, n) && ++o && !W.call(t, n) || !(n in t) || !N(e[n], t[n])) return !1;
16
+ if (M.call(e, n) && ++o && !M.call(t, n) || !(n in t) || !N(e[n], t[n])) return !1;
17
17
  return Object.keys(t).length === o;
18
18
  }
19
19
  }
@@ -21,15 +21,15 @@ function N(e, t) {
21
21
  }
22
22
  function _() {
23
23
  }
24
- function F(e, t) {
24
+ function Z(e, t) {
25
25
  return e != e ? t == t : e !== t || e && typeof e == "object" || typeof e == "function";
26
26
  }
27
27
  const z = [];
28
- function H(e, t = _) {
28
+ function P(e, t = _) {
29
29
  let n;
30
30
  const o = /* @__PURE__ */ new Set();
31
31
  function s(v) {
32
- if (F(e, v) && (e = v, n)) {
32
+ if (Z(e, v) && (e = v, n)) {
33
33
  const E = !z.length;
34
34
  for (const h of o)
35
35
  h[1](), z.push(h, e);
@@ -40,19 +40,19 @@ function H(e, t = _) {
40
40
  }
41
41
  }
42
42
  }
43
- function p(v) {
43
+ function g(v) {
44
44
  s(v(e));
45
45
  }
46
46
  function m(v, E = _) {
47
47
  const h = [v, E];
48
- return o.add(h), o.size === 1 && (n = t(s, p) || _), v(e), () => {
48
+ return o.add(h), o.size === 1 && (n = t(s, g) || _), v(e), () => {
49
49
  o.delete(h), o.size === 0 && n && (n(), n = null);
50
50
  };
51
51
  }
52
- return { set: s, update: p, subscribe: m };
52
+ return { set: s, update: g, subscribe: m };
53
53
  }
54
54
  const Oe = (e) => {
55
- const { subscribe: t, set: n } = H();
55
+ const { subscribe: t, set: n } = P();
56
56
  let o;
57
57
  return t((s) => o = s), e.observe(({ changes: s }) => {
58
58
  if (o) {
@@ -68,10 +68,10 @@ const Oe = (e) => {
68
68
  set: n
69
69
  };
70
70
  };
71
- var K = /* @__PURE__ */ ((e) => (e.EDIT = "EDIT", e.SELECT = "SELECT", e.NONE = "NONE", e))(K || {});
71
+ var F = /* @__PURE__ */ ((e) => (e.EDIT = "EDIT", e.SELECT = "SELECT", e.NONE = "NONE", e))(F || {});
72
72
  const V = { selected: [] }, De = (e, t, n) => {
73
- const { subscribe: o, set: s } = H(V);
74
- let p = t, m = V;
73
+ const { subscribe: o, set: s } = P(V);
74
+ let g = t, m = V;
75
75
  o((A) => m = A);
76
76
  const v = () => {
77
77
  N(m, V) || s(V);
@@ -99,7 +99,7 @@ const V = { selected: [] }, De = (e, t, n) => {
99
99
  c = [f];
100
100
  }
101
101
  const u = c.reduce((f, b) => {
102
- const d = Y(b, p, n);
102
+ const d = C(b);
103
103
  return d === "EDIT" ? [...f, { id: b.id, editable: !0 }] : d === "SELECT" ? [...f, { id: b.id }] : f;
104
104
  }, []);
105
105
  s({ selected: u, event: L });
@@ -107,7 +107,7 @@ const V = { selected: [] }, De = (e, t, n) => {
107
107
  const c = Array.isArray(A) ? A : [A], u = c.map((f) => e.getAnnotation(f)).filter((f) => !!f);
108
108
  s({
109
109
  selected: u.map((f) => {
110
- const b = L === void 0 ? Y(f, p, n) === "EDIT" : L;
110
+ const b = L === void 0 ? C(f) === "EDIT" : L;
111
111
  return { id: f.id, editable: b };
112
112
  })
113
113
  }), u.length !== c.length && console.warn("Invalid selection", A);
@@ -117,8 +117,8 @@ const V = { selected: [] }, De = (e, t, n) => {
117
117
  const { selected: L } = m;
118
118
  L.some(({ id: u }) => A.includes(u)) && s({ selected: L.filter(({ id: u }) => !A.includes(u)) });
119
119
  }, D = (A) => {
120
- p = A, a(m.selected.map(({ id: L }) => L));
121
- }, y = (A) => Y(A, p, n);
120
+ g = A, a(m.selected.map(({ id: L }) => L));
121
+ }, C = (A) => K(A, g, n);
122
122
  return e.observe(
123
123
  ({ changes: A }) => w((A.deleted || []).map((L) => L.id))
124
124
  ), {
@@ -129,10 +129,10 @@ const V = { selected: [] }, De = (e, t, n) => {
129
129
  return m ? [...m.selected] : null;
130
130
  },
131
131
  get userSelectAction() {
132
- return p;
132
+ return g;
133
133
  },
134
134
  clear: v,
135
- evalSelectAction: y,
135
+ evalSelectAction: C,
136
136
  isEmpty: E,
137
137
  isSelected: h,
138
138
  setSelected: a,
@@ -140,7 +140,7 @@ const V = { selected: [] }, De = (e, t, n) => {
140
140
  subscribe: o,
141
141
  userSelect: T
142
142
  };
143
- }, Y = (e, t, n) => {
143
+ }, K = (e, t, n) => {
144
144
  const o = n ? n.serialize(e) : e;
145
145
  return typeof t == "function" ? t(o) : t || "EDIT";
146
146
  }, R = [];
@@ -149,21 +149,21 @@ for (let e = 0; e < 256; ++e)
149
149
  function ee(e, t = 0) {
150
150
  return (R[e[t + 0]] + R[e[t + 1]] + R[e[t + 2]] + R[e[t + 3]] + "-" + R[e[t + 4]] + R[e[t + 5]] + "-" + R[e[t + 6]] + R[e[t + 7]] + "-" + R[e[t + 8]] + R[e[t + 9]] + "-" + R[e[t + 10]] + R[e[t + 11]] + R[e[t + 12]] + R[e[t + 13]] + R[e[t + 14]] + R[e[t + 15]]).toLowerCase();
151
151
  }
152
- let j;
152
+ let Y;
153
153
  const te = new Uint8Array(16);
154
154
  function ne() {
155
- if (!j) {
155
+ if (!Y) {
156
156
  if (typeof crypto > "u" || !crypto.getRandomValues)
157
157
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
158
- j = crypto.getRandomValues.bind(crypto);
158
+ Y = crypto.getRandomValues.bind(crypto);
159
159
  }
160
- return j(te);
160
+ return Y(te);
161
161
  }
162
- const oe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), q = { randomUUID: oe };
163
- function G(e, t, n) {
162
+ const oe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), W = { randomUUID: oe };
163
+ function q(e, t, n) {
164
164
  var s;
165
- if (q.randomUUID && !e)
166
- return q.randomUUID();
165
+ if (W.randomUUID && !e)
166
+ return W.randomUUID();
167
167
  e = e || {};
168
168
  const o = e.random ?? ((s = e.rng) == null ? void 0 : s.call(e)) ?? ne();
169
169
  if (o.length < 16)
@@ -171,13 +171,13 @@ function G(e, t, n) {
171
171
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, ee(o);
172
172
  }
173
173
  const Be = (e) => {
174
- const { creator: t, updatedBy: n } = e.target, o = e.bodies.reduce((s, p) => [...s, p.creator, p.updatedBy].filter(Boolean), []);
174
+ const { creator: t, updatedBy: n } = e.target, o = e.bodies.reduce((s, g) => [...s, g.creator, g.updatedBy].filter(Boolean), []);
175
175
  return [
176
176
  t,
177
177
  n,
178
178
  ...o
179
179
  ].filter((s) => s);
180
- }, P = (e) => {
180
+ }, j = (e) => {
181
181
  const t = (n) => {
182
182
  const o = { ...n };
183
183
  return n.created && typeof n.created == "string" && (o.created = new Date(n.created)), n.updated && typeof n.updated == "string" && (o.updated = new Date(n.updated)), o;
@@ -188,7 +188,7 @@ const Be = (e) => {
188
188
  target: t(e.target)
189
189
  };
190
190
  }, Re = (e, t, n, o) => ({
191
- id: G(),
191
+ id: q(),
192
192
  annotation: typeof e == "string" ? e : e.id,
193
193
  created: n || /* @__PURE__ */ new Date(),
194
194
  creator: o,
@@ -202,7 +202,7 @@ const Be = (e) => {
202
202
  }, de = (e, t) => t.bodies.map((n) => {
203
203
  const o = e.bodies.find((s) => s.id === n.id);
204
204
  return { newBody: n, oldBody: o && !N(o, n) ? o : void 0 };
205
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), re = (e, t) => !N(e.target, t.target), J = (e, t) => {
205
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), re = (e, t) => !N(e.target, t.target), G = (e, t) => {
206
206
  const n = se(e, t), o = ie(e, t), s = de(e, t);
207
207
  return {
208
208
  oldValue: e,
@@ -215,14 +215,14 @@ const Be = (e) => {
215
215
  };
216
216
  var ce = /* @__PURE__ */ ((e) => (e.BODY_ONLY = "BODY_ONLY", e.TARGET_ONLY = "TARGET_ONLY", e))(ce || {}), O = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e.SILENT = "SILENT", e))(O || {});
217
217
  const ae = (e, t) => {
218
- var p, m;
218
+ var g, m;
219
219
  const { changes: n, origin: o } = t;
220
220
  if (!(e.options.origin ? e.options.origin === o : o !== "SILENT"))
221
221
  return !1;
222
222
  if (e.options.ignore) {
223
223
  const { ignore: v } = e.options, E = (T) => T && T.length > 0;
224
224
  if (!(E(n.created) || E(n.deleted))) {
225
- const T = (p = n.updated) == null ? void 0 : p.some((w) => E(w.bodiesCreated) || E(w.bodiesDeleted) || E(w.bodiesUpdated)), a = (m = n.updated) == null ? void 0 : m.some((w) => w.targetUpdated);
225
+ const T = (g = n.updated) == null ? void 0 : g.some((w) => E(w.bodiesCreated) || E(w.bodiesDeleted) || E(w.bodiesUpdated)), a = (m = n.updated) == null ? void 0 : m.some((w) => w.targetUpdated);
226
226
  if (v === "BODY_ONLY" && T && !a || v === "TARGET_ONLY" && a && !T)
227
227
  return !1;
228
228
  }
@@ -237,18 +237,18 @@ const ae = (e, t) => {
237
237
  } else
238
238
  return !0;
239
239
  }, le = (e, t) => {
240
- const n = new Set((e.created || []).map((a) => a.id)), o = new Set((e.updated || []).map(({ newValue: a }) => a.id)), s = new Set((t.created || []).map((a) => a.id)), p = new Set((t.deleted || []).map((a) => a.id)), m = new Set((t.updated || []).map(({ oldValue: a }) => a.id)), v = new Set((t.updated || []).filter(({ oldValue: a }) => n.has(a.id) || o.has(a.id)).map(({ oldValue: a }) => a.id)), E = [
241
- ...(e.created || []).filter((a) => !p.has(a.id)).map((a) => m.has(a.id) ? t.updated.find(({ oldValue: w }) => w.id === a.id).newValue : a),
240
+ const n = new Set((e.created || []).map((a) => a.id)), o = new Set((e.updated || []).map(({ newValue: a }) => a.id)), s = new Set((t.created || []).map((a) => a.id)), g = new Set((t.deleted || []).map((a) => a.id)), m = new Set((t.updated || []).map(({ oldValue: a }) => a.id)), v = new Set((t.updated || []).filter(({ oldValue: a }) => n.has(a.id) || o.has(a.id)).map(({ oldValue: a }) => a.id)), E = [
241
+ ...(e.created || []).filter((a) => !g.has(a.id)).map((a) => m.has(a.id) ? t.updated.find(({ oldValue: w }) => w.id === a.id).newValue : a),
242
242
  ...t.created || []
243
243
  ], h = [
244
244
  ...(e.deleted || []).filter((a) => !s.has(a.id)),
245
245
  ...(t.deleted || []).filter((a) => !n.has(a.id))
246
246
  ], T = [
247
- ...(e.updated || []).filter(({ newValue: a }) => !p.has(a.id)).map((a) => {
247
+ ...(e.updated || []).filter(({ newValue: a }) => !g.has(a.id)).map((a) => {
248
248
  const { oldValue: w, newValue: D } = a;
249
249
  if (m.has(D.id)) {
250
- const y = t.updated.find((A) => A.oldValue.id === D.id).newValue;
251
- return J(w, y);
250
+ const C = t.updated.find((A) => A.oldValue.id === D.id).newValue;
251
+ return G(w, C);
252
252
  } else
253
253
  return a;
254
254
  }),
@@ -256,7 +256,7 @@ const ae = (e, t) => {
256
256
  ];
257
257
  return { created: E, deleted: h, updated: T };
258
258
  }, $ = (e) => {
259
- const t = e.id === void 0 ? G() : e.id;
259
+ const t = e.id === void 0 ? q() : e.id;
260
260
  return {
261
261
  ...e,
262
262
  id: t,
@@ -275,7 +275,7 @@ const ae = (e, t) => {
275
275
  }, s = (i) => {
276
276
  const r = n.findIndex((l) => l.onChange == i);
277
277
  r > -1 && n.splice(r, 1);
278
- }, p = (i, r) => {
278
+ }, g = (i, r) => {
279
279
  const l = {
280
280
  origin: i,
281
281
  changes: {
@@ -285,101 +285,101 @@ const ae = (e, t) => {
285
285
  },
286
286
  state: [...e.values()]
287
287
  };
288
- n.forEach((g) => {
289
- ae(g, l) && g.onChange(l);
288
+ n.forEach((p) => {
289
+ ae(p, l) && p.onChange(l);
290
290
  });
291
291
  }, m = (i, r = O.LOCAL) => {
292
292
  if (i.id && e.get(i.id))
293
293
  throw Error(`Cannot add annotation ${i.id} - exists already`);
294
294
  {
295
- const g = $(i);
296
- e.set(g.id, g), g.bodies.forEach((U) => t.set(U.id, g.id)), p(r, { created: [g] });
295
+ const p = $(i);
296
+ e.set(p.id, p), p.bodies.forEach((U) => t.set(U.id, p.id)), g(r, { created: [p] });
297
297
  }
298
298
  }, v = (i, r) => {
299
- const l = $(typeof i == "string" ? r : i), g = typeof i == "string" ? i : i.id, U = g && e.get(g);
299
+ const l = $(typeof i == "string" ? r : i), p = typeof i == "string" ? i : i.id, U = p && e.get(p);
300
300
  if (U) {
301
- const C = J(U, l);
302
- return g === l.id ? e.set(g, l) : (e.delete(g), e.set(l.id, l)), U.bodies.forEach((B) => t.delete(B.id)), l.bodies.forEach((B) => t.set(B.id, l.id)), C;
301
+ const y = G(U, l);
302
+ return p === l.id ? e.set(p, l) : (e.delete(p), e.set(l.id, l)), U.bodies.forEach((B) => t.delete(B.id)), l.bodies.forEach((B) => t.set(B.id, l.id)), y;
303
303
  } else
304
- console.warn(`Cannot update annotation ${g} - does not exist`);
304
+ console.warn(`Cannot update annotation ${p} - does not exist`);
305
305
  }, E = (i, r = O.LOCAL, l = O.LOCAL) => {
306
- const g = ue(r) ? l : r, U = v(i, r);
307
- U && p(g, { updated: [U] });
306
+ const p = ue(r) ? l : r, U = v(i, r);
307
+ U && g(p, { updated: [U] });
308
308
  }, h = (i, r = O.LOCAL) => {
309
309
  !!e.get(i.id) ? E(i, r) : m(i, r);
310
310
  }, T = (i, r = O.LOCAL) => {
311
- const l = i.reduce((g, U) => {
312
- const C = v(U);
313
- return C ? [...g, C] : g;
311
+ const l = i.reduce((p, U) => {
312
+ const y = v(U);
313
+ return y ? [...p, y] : p;
314
314
  }, []);
315
- l.length > 0 && p(r, { updated: l });
315
+ l.length > 0 && g(r, { updated: l });
316
316
  }, a = (i, r = O.LOCAL) => {
317
- const l = i.map($), { toAdd: g, toUpdate: U } = l.reduce((B, I) => e.get(I.id) ? { ...B, toUpdate: [...B.toUpdate, I] } : { ...B, toAdd: [...B.toAdd, I] }, { toAdd: [], toUpdate: [] }), C = U.map((B) => v(B, r)).filter(Boolean);
318
- g.forEach((B) => {
317
+ const l = i.map($), { toAdd: p, toUpdate: U } = l.reduce((B, I) => e.get(I.id) ? { ...B, toUpdate: [...B.toUpdate, I] } : { ...B, toAdd: [...B.toAdd, I] }, { toAdd: [], toUpdate: [] }), y = U.map((B) => v(B, r)).filter(Boolean);
318
+ p.forEach((B) => {
319
319
  e.set(B.id, B), B.bodies.forEach((I) => t.set(I.id, B.id));
320
- }), p(r, { created: g, updated: C });
320
+ }), g(r, { created: p, updated: y });
321
321
  }, w = (i, r = O.LOCAL) => {
322
322
  const l = e.get(i.annotation);
323
323
  if (l) {
324
- const g = {
324
+ const p = {
325
325
  ...l,
326
326
  bodies: [...l.bodies, i]
327
327
  };
328
- e.set(l.id, g), t.set(i.id, g.id), p(r, { updated: [{
328
+ e.set(l.id, p), t.set(i.id, p.id), g(r, { updated: [{
329
329
  oldValue: l,
330
- newValue: g,
330
+ newValue: p,
331
331
  bodiesCreated: [i]
332
332
  }] });
333
333
  } else
334
334
  console.warn(`Attempt to add body to missing annotation: ${i.annotation}`);
335
- }, D = () => [...e.values()], y = (i = O.LOCAL) => {
335
+ }, D = () => [...e.values()], C = (i = O.LOCAL) => {
336
336
  const r = [...e.values()];
337
- e.clear(), t.clear(), p(i, { deleted: r });
337
+ e.clear(), t.clear(), g(i, { deleted: r });
338
338
  }, A = (i, r = !0, l = O.LOCAL) => {
339
- const g = i.map($);
339
+ const p = i.map($);
340
340
  if (r) {
341
341
  const U = [...e.values()];
342
- e.clear(), t.clear(), g.forEach((C) => {
343
- e.set(C.id, C), C.bodies.forEach((B) => t.set(B.id, C.id));
344
- }), p(l, { created: g, deleted: U });
342
+ e.clear(), t.clear(), p.forEach((y) => {
343
+ e.set(y.id, y), y.bodies.forEach((B) => t.set(B.id, y.id));
344
+ }), g(l, { created: p, deleted: U });
345
345
  } else {
346
- const U = i.reduce((C, B) => {
346
+ const U = i.reduce((y, B) => {
347
347
  const I = B.id && e.get(B.id);
348
- return I ? [...C, I] : C;
348
+ return I ? [...y, I] : y;
349
349
  }, []);
350
350
  if (U.length > 0)
351
- throw Error(`Bulk insert would overwrite the following annotations: ${U.map((C) => C.id).join(", ")}`);
352
- g.forEach((C) => {
353
- e.set(C.id, C), C.bodies.forEach((B) => t.set(B.id, C.id));
354
- }), p(l, { created: g });
351
+ throw Error(`Bulk insert would overwrite the following annotations: ${U.map((y) => y.id).join(", ")}`);
352
+ p.forEach((y) => {
353
+ e.set(y.id, y), y.bodies.forEach((B) => t.set(B.id, y.id));
354
+ }), g(l, { created: p });
355
355
  }
356
356
  }, L = (i) => {
357
357
  const r = typeof i == "string" ? i : i.id, l = e.get(r);
358
358
  if (l)
359
- return e.delete(r), l.bodies.forEach((g) => t.delete(g.id)), l;
359
+ return e.delete(r), l.bodies.forEach((p) => t.delete(p.id)), l;
360
360
  console.warn(`Attempt to delete missing annotation: ${r}`);
361
361
  }, c = (i, r = O.LOCAL) => {
362
362
  const l = L(i);
363
- l && p(r, { deleted: [l] });
363
+ l && g(r, { deleted: [l] });
364
364
  }, u = (i, r = O.LOCAL) => {
365
- const l = i.reduce((g, U) => {
366
- const C = L(U);
367
- return C ? [...g, C] : g;
365
+ const l = i.reduce((p, U) => {
366
+ const y = L(U);
367
+ return y ? [...p, y] : p;
368
368
  }, []);
369
- l.length > 0 && p(r, { deleted: l });
369
+ l.length > 0 && g(r, { deleted: l });
370
370
  }, f = (i) => {
371
371
  const r = e.get(i.annotation);
372
372
  if (r) {
373
- const l = r.bodies.find((g) => g.id === i.id);
373
+ const l = r.bodies.find((p) => p.id === i.id);
374
374
  if (l) {
375
375
  t.delete(l.id);
376
- const g = {
376
+ const p = {
377
377
  ...r,
378
- bodies: r.bodies.filter((C) => C.id !== i.id)
378
+ bodies: r.bodies.filter((y) => y.id !== i.id)
379
379
  };
380
- return e.set(r.id, g), {
380
+ return e.set(r.id, p), {
381
381
  oldValue: r,
382
- newValue: g,
382
+ newValue: p,
383
383
  bodiesDeleted: [l]
384
384
  };
385
385
  } else
@@ -388,19 +388,19 @@ const ae = (e, t) => {
388
388
  console.warn(`Attempt to delete body from missing annotation ${i.annotation}`);
389
389
  }, b = (i, r = O.LOCAL) => {
390
390
  const l = f(i);
391
- l && p(r, { updated: [l] });
391
+ l && g(r, { updated: [l] });
392
392
  }, d = (i, r = O.LOCAL) => {
393
- const l = i.map((g) => f(g)).filter(Boolean);
394
- l.length > 0 && p(r, { updated: l });
393
+ const l = i.map((p) => f(p)).filter(Boolean);
394
+ l.length > 0 && g(r, { updated: l });
395
395
  }, S = (i) => {
396
396
  const r = e.get(i);
397
397
  return r ? { ...r } : void 0;
398
398
  }, x = (i) => {
399
399
  const r = t.get(i);
400
400
  if (r) {
401
- const g = S(r).bodies.find((U) => U.id === i);
402
- if (g)
403
- return g;
401
+ const p = S(r).bodies.find((U) => U.id === i);
402
+ if (p)
403
+ return p;
404
404
  console.error(`Store integrity error: body ${i} in index, but not in annotation`);
405
405
  } else
406
406
  console.warn(`Attempt to retrieve missing body: ${i}`);
@@ -409,24 +409,24 @@ const ae = (e, t) => {
409
409
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
410
410
  const l = e.get(i.annotation);
411
411
  if (l) {
412
- const g = l.bodies.find((C) => C.id === i.id), U = {
412
+ const p = l.bodies.find((y) => y.id === i.id), U = {
413
413
  ...l,
414
- bodies: l.bodies.map((C) => C.id === g.id ? r : C)
414
+ bodies: l.bodies.map((y) => y.id === p.id ? r : y)
415
415
  };
416
- return e.set(l.id, U), g.id !== r.id && (t.delete(g.id), t.set(r.id, U.id)), {
416
+ return e.set(l.id, U), p.id !== r.id && (t.delete(p.id), t.set(r.id, U.id)), {
417
417
  oldValue: l,
418
418
  newValue: U,
419
- bodiesUpdated: [{ oldBody: g, newBody: r }]
419
+ bodiesUpdated: [{ oldBody: p, newBody: r }]
420
420
  };
421
421
  } else
422
422
  console.warn(`Attempt to add body to missing annotation ${i.annotation}`);
423
- }, X = (i, r, l = O.LOCAL) => {
424
- const g = k(i, r);
425
- g && p(l, { updated: [g] });
426
- }, Z = (i, r = O.LOCAL) => {
427
- const l = i.map((g) => k({ id: g.id, annotation: g.annotation }, g)).filter(Boolean);
428
- p(r, { updated: l });
429
- }, M = (i) => {
423
+ }, Q = (i, r, l = O.LOCAL) => {
424
+ const p = k(i, r);
425
+ p && g(l, { updated: [p] });
426
+ }, X = (i, r = O.LOCAL) => {
427
+ const l = i.map((p) => k({ id: p.id, annotation: p.annotation }, p)).filter(Boolean);
428
+ g(r, { updated: l });
429
+ }, H = (i) => {
430
430
  const r = e.get(i.annotation);
431
431
  if (r) {
432
432
  const l = {
@@ -455,13 +455,13 @@ const ae = (e, t) => {
455
455
  bulkDeleteAnnotations: u,
456
456
  bulkDeleteBodies: d,
457
457
  bulkUpdateAnnotations: T,
458
- bulkUpdateBodies: Z,
458
+ bulkUpdateBodies: X,
459
459
  bulkUpdateTargets: (i, r = O.LOCAL) => {
460
- const l = i.map((g) => M(g)).filter(Boolean);
461
- l.length > 0 && p(r, { updated: l });
460
+ const l = i.map((p) => H(p)).filter(Boolean);
461
+ l.length > 0 && g(r, { updated: l });
462
462
  },
463
463
  bulkUpsertAnnotations: a,
464
- clear: y,
464
+ clear: C,
465
465
  deleteAnnotation: c,
466
466
  deleteBody: b,
467
467
  getAnnotation: S,
@@ -469,10 +469,10 @@ const ae = (e, t) => {
469
469
  observe: o,
470
470
  unobserve: s,
471
471
  updateAnnotation: E,
472
- updateBody: X,
472
+ updateBody: Q,
473
473
  updateTarget: (i, r = O.LOCAL) => {
474
- const l = M(i);
475
- l && p(r, { updated: [l] });
474
+ const l = H(i);
475
+ l && g(r, { updated: [l] });
476
476
  },
477
477
  upsertAnnotation: h
478
478
  };
@@ -483,7 +483,7 @@ const ae = (e, t) => {
483
483
  return e.observe(o), n(e.all()), () => e.unobserve(o);
484
484
  }
485
485
  });
486
- let Q = () => ({
486
+ let J = () => ({
487
487
  emit(e, ...t) {
488
488
  for (let n = this.events[e] || [], o = 0, s = n.length; o < s; o++)
489
489
  n[o](...t);
@@ -498,10 +498,10 @@ let Q = () => ({
498
498
  }
499
499
  });
500
500
  const fe = 250, Ie = (e, t) => {
501
- const n = Q(), o = (t == null ? void 0 : t.changes) || [];
502
- let s = t ? t.pointer : -1, p = !1, m = 0;
501
+ const n = J(), o = (t == null ? void 0 : t.changes) || [];
502
+ let s = t ? t.pointer : -1, g = !1, m = 0;
503
503
  const v = (d) => {
504
- if (!p) {
504
+ if (!g) {
505
505
  const { changes: S } = d, x = performance.now();
506
506
  if (x - m > fe)
507
507
  o.splice(s + 1), o.push(S), s = o.length - 1;
@@ -511,7 +511,7 @@ const fe = 250, Ie = (e, t) => {
511
511
  }
512
512
  m = x;
513
513
  }
514
- p = !1;
514
+ g = !1;
515
515
  };
516
516
  e.observe(v, { origin: O.LOCAL });
517
517
  const E = (d) => d && d.length > 0 && e.bulkDeleteAnnotations(d), h = (d) => d && d.length > 0 && e.bulkAddAnnotations(d, !1), T = (d) => d && d.length > 0 && e.bulkUpdateAnnotations(d.map(({ oldValue: S }) => S)), a = (d) => d && d.length > 0 && e.bulkUpdateAnnotations(d.map(({ newValue: S }) => S)), w = (d) => d && d.length > 0 && e.bulkAddAnnotations(d, !1), D = (d) => d && d.length > 0 && e.bulkDeleteAnnotations(d);
@@ -523,27 +523,27 @@ const fe = 250, Ie = (e, t) => {
523
523
  on: (d, S) => n.on(d, S),
524
524
  redo: () => {
525
525
  if (o.length - 1 > s) {
526
- p = !0;
526
+ g = !0;
527
527
  const { created: d, updated: S, deleted: x } = o[s + 1];
528
528
  h(d), a(S), D(x), n.emit("redo", o[s + 1]), s += 1;
529
529
  }
530
530
  },
531
531
  undo: () => {
532
532
  if (s > -1) {
533
- p = !0;
533
+ g = !0;
534
534
  const { created: d, updated: S, deleted: x } = o[s];
535
535
  E(d), T(S), w(x), n.emit("undo", o[s]), s -= 1;
536
536
  }
537
537
  }
538
538
  };
539
539
  }, Ne = () => {
540
- const { subscribe: e, set: t } = H([]);
540
+ const { subscribe: e, set: t } = P([]);
541
541
  return {
542
542
  subscribe: e,
543
543
  set: t
544
544
  };
545
545
  }, ze = (e, t, n, o) => {
546
- const { hover: s, selection: p, store: m, viewport: v } = e, E = /* @__PURE__ */ new Map();
546
+ const { hover: s, selection: g, store: m, viewport: v } = e, E = /* @__PURE__ */ new Map();
547
547
  let h = [], T, a;
548
548
  const w = (c, u) => {
549
549
  E.has(c) ? E.get(c).push(u) : E.set(c, [u]);
@@ -553,7 +553,7 @@ const fe = 250, Ie = (e, t) => {
553
553
  const b = f.indexOf(u);
554
554
  b !== -1 && f.splice(b, 1);
555
555
  }
556
- }, y = (c, u, f) => {
556
+ }, C = (c, u, f) => {
557
557
  E.has(c) && setTimeout(() => {
558
558
  E.get(c).forEach((b) => {
559
559
  if (n) {
@@ -564,29 +564,29 @@ const fe = 250, Ie = (e, t) => {
564
564
  });
565
565
  }, 1);
566
566
  }, A = () => {
567
- const { selected: c } = p, u = (c || []).map(({ id: f }) => m.getAnnotation(f));
567
+ const { selected: c } = g, u = (c || []).map(({ id: f }) => m.getAnnotation(f));
568
568
  u.forEach((f) => {
569
569
  const b = h.find((d) => d.id === f.id);
570
- (!b || !N(b, f)) && y("updateAnnotation", f, b);
570
+ (!b || !N(b, f)) && C("updateAnnotation", f, b);
571
571
  }), h = h.map((f) => {
572
572
  const b = u.find(({ id: d }) => d === f.id);
573
573
  return b || f;
574
574
  });
575
575
  };
576
- p.subscribe(({ selected: c }) => {
576
+ g.subscribe(({ selected: c }) => {
577
577
  if (!(h.length === 0 && c.length === 0)) {
578
578
  if (h.length === 0 && c.length > 0)
579
579
  h = c.map(({ id: u }) => m.getAnnotation(u));
580
580
  else if (h.length > 0 && c.length === 0)
581
581
  h.forEach((u) => {
582
582
  const f = m.getAnnotation(u.id);
583
- f && !N(f, u) && y("updateAnnotation", f, u);
583
+ f && !N(f, u) && C("updateAnnotation", f, u);
584
584
  }), h = [];
585
585
  else {
586
586
  const u = new Set(h.map((d) => d.id)), f = new Set(c.map(({ id: d }) => d));
587
587
  h.filter((d) => !f.has(d.id)).forEach((d) => {
588
588
  const S = m.getAnnotation(d.id);
589
- S && !N(S, d) && y("updateAnnotation", S, d);
589
+ S && !N(S, d) && C("updateAnnotation", S, d);
590
590
  }), h = [
591
591
  // Remove annotations that were deselected
592
592
  ...h.filter((d) => f.has(d.id)),
@@ -594,20 +594,20 @@ const fe = 250, Ie = (e, t) => {
594
594
  ...c.filter(({ id: d }) => !u.has(d)).map(({ id: d }) => m.getAnnotation(d))
595
595
  ];
596
596
  }
597
- y("selectionChanged", h);
597
+ C("selectionChanged", h);
598
598
  }
599
599
  }), s.subscribe((c) => {
600
- !T && c ? y("mouseEnterAnnotation", m.getAnnotation(c)) : T && !c ? y("mouseLeaveAnnotation", m.getAnnotation(T)) : T && c && (y("mouseLeaveAnnotation", m.getAnnotation(T)), y("mouseEnterAnnotation", m.getAnnotation(c))), T = c;
601
- }), v == null || v.subscribe((c) => y("viewportIntersect", c.map((u) => m.getAnnotation(u)))), m.observe((c) => {
600
+ !T && c ? C("mouseEnterAnnotation", m.getAnnotation(c)) : T && !c ? C("mouseLeaveAnnotation", m.getAnnotation(T)) : T && c && (C("mouseLeaveAnnotation", m.getAnnotation(T)), C("mouseEnterAnnotation", m.getAnnotation(c))), T = c;
601
+ }), v == null || v.subscribe((c) => C("viewportIntersect", c.map((u) => m.getAnnotation(u)))), m.observe((c) => {
602
602
  o && (a && clearTimeout(a), a = setTimeout(A, 1e3));
603
603
  const { created: u, deleted: f } = c.changes;
604
- (u || []).forEach((d) => y("createAnnotation", d)), (f || []).forEach((d) => y("deleteAnnotation", d)), (c.changes.updated || []).filter((d) => [
604
+ (u || []).forEach((d) => C("createAnnotation", d)), (f || []).forEach((d) => C("deleteAnnotation", d)), (c.changes.updated || []).filter((d) => [
605
605
  ...d.bodiesCreated || [],
606
606
  ...d.bodiesDeleted || [],
607
607
  ...d.bodiesUpdated || []
608
608
  ].length > 0).forEach(({ oldValue: d, newValue: S }) => {
609
609
  const x = h.find((k) => k.id === d.id) || d;
610
- h = h.map((k) => k.id === d.id ? S : k), y("updateAnnotation", S, x);
610
+ h = h.map((k) => k.id === d.id ? S : k), C("updateAnnotation", S, x);
611
611
  });
612
612
  }, { origin: O.LOCAL }), m.observe((c) => {
613
613
  if (h) {
@@ -620,12 +620,12 @@ const fe = 250, Ie = (e, t) => {
620
620
  }, { origin: O.REMOTE });
621
621
  const L = (c) => (u) => {
622
622
  const { updated: f } = u;
623
- c ? (f || []).forEach((b) => y("updateAnnotation", b.oldValue, b.newValue)) : (f || []).forEach((b) => y("updateAnnotation", b.newValue, b.oldValue));
623
+ c ? (f || []).forEach((b) => C("updateAnnotation", b.oldValue, b.newValue)) : (f || []).forEach((b) => C("updateAnnotation", b.newValue, b.oldValue));
624
624
  };
625
- return t.on("undo", L(!0)), t.on("redo", L(!1)), { on: w, off: D, emit: y };
625
+ return t.on("undo", L(!0)), t.on("redo", L(!1)), { on: w, off: D, emit: C };
626
626
  }, $e = (e) => (t) => t.map((n) => e.serialize(n)), pe = (e) => (t) => t.reduce((n, o) => {
627
- const { parsed: s, error: p } = e.parse(o);
628
- return p ? {
627
+ const { parsed: s, error: g } = e.parse(o);
628
+ return g ? {
629
629
  parsed: n.parsed,
630
630
  failed: [...n.failed, o]
631
631
  } : s ? {
@@ -635,12 +635,12 @@ const fe = 250, Ie = (e, t) => {
635
635
  ...n
636
636
  };
637
637
  }, { parsed: [], failed: [] }), Ve = (e, t, n) => {
638
- const { store: o, selection: s } = e, p = (c) => {
638
+ const { store: o, selection: s } = e, g = (c) => {
639
639
  if (n) {
640
640
  const { parsed: u, error: f } = n.parse(c);
641
641
  u ? o.addAnnotation(u, O.REMOTE) : console.error(f);
642
642
  } else
643
- o.addAnnotation(P(c), O.REMOTE);
643
+ o.addAnnotation(j(c), O.REMOTE);
644
644
  }, m = () => s.clear(), v = () => o.clear(), E = (c) => {
645
645
  const u = o.getAnnotation(c);
646
646
  return n && u ? n.serialize(u) : u;
@@ -663,8 +663,8 @@ const fe = 250, Ie = (e, t) => {
663
663
  const f = n.parseAll || pe(n), { parsed: b, failed: d } = f(c);
664
664
  d.length > 0 && console.warn(`Discarded ${d.length} invalid annotations`, d), o.bulkAddAnnotations(b, u, O.REMOTE);
665
665
  } else
666
- o.bulkAddAnnotations(c.map(P), u, O.REMOTE);
667
- }, y = (c, u) => {
666
+ o.bulkAddAnnotations(c.map(j), u, O.REMOTE);
667
+ }, C = (c, u) => {
668
668
  c ? s.setSelected(c, u) : s.clear();
669
669
  }, A = (c) => {
670
670
  s.clear(), s.setUserSelectAction(c);
@@ -674,11 +674,11 @@ const fe = 250, Ie = (e, t) => {
674
674
  return o.updateAnnotation(u), f;
675
675
  } else {
676
676
  const u = o.getAnnotation(c.id);
677
- return o.updateAnnotation(P(c)), u;
677
+ return o.updateAnnotation(j(c)), u;
678
678
  }
679
679
  };
680
680
  return {
681
- addAnnotation: p,
681
+ addAnnotation: g,
682
682
  cancelSelected: m,
683
683
  canRedo: t.canRedo,
684
684
  canUndo: t.canUndo,
@@ -691,7 +691,7 @@ const fe = 250, Ie = (e, t) => {
691
691
  redo: t.redo,
692
692
  removeAnnotation: w,
693
693
  setAnnotations: D,
694
- setSelected: y,
694
+ setSelected: C,
695
695
  setUserSelectAction: A,
696
696
  undo: t.undo,
697
697
  updateAnnotation: L
@@ -700,20 +700,20 @@ const fe = 250, Ie = (e, t) => {
700
700
  ...e || {},
701
701
  ...t || {}
702
702
  } : (n, o) => {
703
- const s = typeof e == "function" ? e(n, o) : e, p = typeof t == "function" ? t(n, o) : t;
703
+ const s = typeof e == "function" ? e(n, o) : e, g = typeof t == "function" ? t(n, o) : t;
704
704
  return {
705
705
  ...s || {},
706
- ...p || {}
706
+ ...g || {}
707
707
  };
708
708
  }, ge = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
709
709
  let he = (e) => crypto.getRandomValues(new Uint8Array(e)), me = (e, t, n) => {
710
710
  let o = (2 << Math.log2(e.length - 1)) - 1, s = -~(1.6 * o * t / e.length);
711
- return (p = t) => {
711
+ return (g = t) => {
712
712
  let m = "";
713
713
  for (; ; ) {
714
714
  let v = n(s), E = s | 0;
715
715
  for (; E--; )
716
- if (m += e[v[E] & o] || "", m.length >= p) return m;
716
+ if (m += e[v[E] & o] || "", m.length >= g) return m;
717
717
  }
718
718
  };
719
719
  }, Ae = (e, t = 21) => me(e, t | 0, he), be = (e = 21) => {
@@ -726,17 +726,17 @@ const je = () => ({ isGuest: !0, id: Ae("1234567890abcdefghijklmnopqrstuvwxyzABC
726
726
  const t = JSON.stringify(e);
727
727
  let n = 0;
728
728
  for (let o = 0, s = t.length; o < s; o++) {
729
- let p = t.charCodeAt(o);
730
- n = (n << 5) - n + p, n |= 0;
729
+ let g = t.charCodeAt(o);
730
+ n = (n << 5) - n + g, n |= 0;
731
731
  }
732
732
  return `${n}`;
733
733
  }, Ee = (e) => e ? typeof e == "object" ? { ...e } : e : void 0, Pe = (e, t) => (Array.isArray(e) ? e : [e]).map((n) => {
734
- const { id: o, type: s, purpose: p, value: m, created: v, modified: E, creator: h, ...T } = n;
734
+ const { id: o, type: s, purpose: g, value: m, created: v, modified: E, creator: h, ...T } = n;
735
735
  return {
736
736
  id: o || `temp-${ve(n)}`,
737
737
  annotation: t,
738
738
  type: s,
739
- purpose: p,
739
+ purpose: g,
740
740
  value: m,
741
741
  creator: Ee(h),
742
742
  created: v ? new Date(v) : void 0,
@@ -745,13 +745,13 @@ const je = () => ({ isGuest: !0, id: Ae("1234567890abcdefghijklmnopqrstuvwxyzABC
745
745
  };
746
746
  }), He = (e) => e.map((t) => {
747
747
  var v;
748
- const { annotation: n, created: o, updated: s, ...p } = t, m = {
749
- ...p,
748
+ const { annotation: n, created: o, updated: s, ...g } = t, m = {
749
+ ...g,
750
750
  created: o == null ? void 0 : o.toISOString(),
751
751
  modified: s == null ? void 0 : s.toISOString()
752
752
  };
753
753
  return (v = m.id) != null && v.startsWith("temp-") && delete m.id, m;
754
- }), we = [
754
+ }), Me = (e) => "@context" in e && "creator" in e && "body" in e, we = [
755
755
  "#ff7c00",
756
756
  // orange
757
757
  "#1ac938",
@@ -779,15 +779,15 @@ const je = () => ({ isGuest: !0, id: Ae("1234567890abcdefghijklmnopqrstuvwxyzABC
779
779
  }, ye = () => {
780
780
  const e = Ce();
781
781
  return { addUser: (o, s) => {
782
- const p = e.assignRandomColor();
782
+ const g = e.assignRandomColor();
783
783
  return {
784
784
  label: s.name || s.id,
785
785
  avatar: s.avatar,
786
- color: p
786
+ color: g
787
787
  };
788
788
  }, removeUser: (o) => e.releaseColor(o.appearance.color) };
789
- }, Le = (e, t) => e.every((n) => e.includes(n)) && t.every((n) => e.includes(n)), Me = be(), We = (e = ye()) => {
790
- const t = Q(), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = (a, w) => {
789
+ }, Le = (e, t) => e.every((n) => e.includes(n)) && t.every((n) => e.includes(n)), We = be(), qe = (e = ye()) => {
790
+ const t = J(), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = (a, w) => {
791
791
  if (n.has(a)) {
792
792
  console.warn("Attempt to add user that is already present", a, w);
793
793
  return;
@@ -798,7 +798,7 @@ const je = () => ({ isGuest: !0, id: Ae("1234567890abcdefghijklmnopqrstuvwxyzABC
798
798
  presenceKey: a,
799
799
  appearance: D
800
800
  });
801
- }, p = (a) => {
801
+ }, g = (a) => {
802
802
  const w = n.get(a);
803
803
  if (!w) {
804
804
  console.warn("Attempt to remove user that is not present", a);
@@ -806,19 +806,19 @@ const je = () => ({ isGuest: !0, id: Ae("1234567890abcdefghijklmnopqrstuvwxyzABC
806
806
  }
807
807
  e.removeUser(w), n.delete(a);
808
808
  }, m = (a) => {
809
- const w = new Set(a.map((A) => A.presenceKey)), D = a.filter(({ presenceKey: A }) => !n.has(A)), y = Array.from(n.values()).filter((A) => !w.has(A.presenceKey));
810
- D.forEach(({ presenceKey: A, user: L }) => s(A, L)), y.forEach((A) => {
809
+ const w = new Set(a.map((A) => A.presenceKey)), D = a.filter(({ presenceKey: A }) => !n.has(A)), C = Array.from(n.values()).filter((A) => !w.has(A.presenceKey));
810
+ D.forEach(({ presenceKey: A, user: L }) => s(A, L)), C.forEach((A) => {
811
811
  const { presenceKey: L } = A;
812
- o.has(L) && t.emit("selectionChange", A, null), p(L);
813
- }), (D.length > 0 || y.length > 0) && t.emit("presence", h());
812
+ o.has(L) && t.emit("selectionChange", A, null), g(L);
813
+ }), (D.length > 0 || C.length > 0) && t.emit("presence", h());
814
814
  }, v = (a, w) => {
815
815
  const D = n.get(a);
816
816
  if (!D) {
817
817
  console.warn("Activity notification from user that is not present");
818
818
  return;
819
819
  }
820
- const y = o.get(a);
821
- (!y || !Le(y, w)) && (o.set(a, w), t.emit("selectionChange", D, w));
820
+ const C = o.get(a);
821
+ (!C || !Le(C, w)) && (o.set(a, w), t.emit("selectionChange", D, w));
822
822
  }, E = (a, w) => {
823
823
  const D = n.get(a);
824
824
  if (!D) {
@@ -838,8 +838,8 @@ const je = () => ({ isGuest: !0, id: Ae("1234567890abcdefghijklmnopqrstuvwxyzABC
838
838
  export {
839
839
  ce as Ignore,
840
840
  O as Origin,
841
- Me as PRESENCE_KEY,
842
- K as UserSelectAction,
841
+ We as PRESENCE_KEY,
842
+ F as UserSelectAction,
843
843
  Ye as chainStyles,
844
844
  _e as computeStyle,
845
845
  je as createAnonymousGuest,
@@ -848,20 +848,21 @@ export {
848
848
  ye as createDefaultAppearanceProvider,
849
849
  Oe as createHoverState,
850
850
  ze as createLifecycleObserver,
851
- We as createPresenceState,
851
+ qe as createPresenceState,
852
852
  De as createSelectionState,
853
853
  xe as createStore,
854
854
  Ie as createUndoStack,
855
855
  Ne as createViewportState,
856
856
  Ce as defaultColorProvider,
857
- J as diffAnnotations,
857
+ G as diffAnnotations,
858
858
  Be as getContributors,
859
+ Me as isW3CAnnotation,
859
860
  le as mergeChanges,
860
- Y as onUserSelect,
861
+ K as onUserSelect,
861
862
  pe as parseAll,
862
863
  Pe as parseW3CBodies,
863
864
  Ee as parseW3CUser,
864
- P as reviveDates,
865
+ j as reviveDates,
865
866
  $e as serializeAll,
866
867
  He as serializeW3CBodies,
867
868
  ae as shouldNotify,