@annotorious/core 3.7.22 → 3.8.1

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