@annotorious/core 3.8.4 → 3.8.5

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