@annotorious/core 3.0.0-rc.22 → 3.0.0-rc.24

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