@annotorious/core 3.8.0 → 3.8.2

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