@annotorious/core 3.8.2 → 3.8.4
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
1
|
var G = Object.prototype.hasOwnProperty;
|
|
2
|
-
function
|
|
2
|
+
function Y(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 $(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-- &&
|
|
10
|
+
for (; o-- && Y(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) ||
|
|
16
|
+
if (G.call(e, n) && ++o && !G.call(t, n) || !(n in t) || !Y(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
22
|
const X = Symbol("clean");
|
|
23
|
-
let
|
|
24
|
-
const
|
|
23
|
+
let x = [], k = 0;
|
|
24
|
+
const P = 4, Z = 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 z = 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 =
|
|
35
|
-
|
|
34
|
+
for (let f = k + P; f < x.length; )
|
|
35
|
+
x[f] === o ? x.splice(f, P) : f += P;
|
|
36
36
|
let s = t.indexOf(o);
|
|
37
37
|
~s && (t.splice(s, 1), --n.lc || n.off());
|
|
38
38
|
};
|
|
39
39
|
},
|
|
40
40
|
notify(o, s) {
|
|
41
41
|
Z.epoch++;
|
|
42
|
-
let f = !
|
|
42
|
+
let f = !x.length;
|
|
43
43
|
for (let A of t)
|
|
44
|
-
|
|
44
|
+
x.push(A, n.value, o, s);
|
|
45
45
|
if (f) {
|
|
46
|
-
for (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
for (k = 0; k < x.length; k += P)
|
|
47
|
+
x[k](
|
|
48
|
+
x[k + 1],
|
|
49
|
+
x[k + 2],
|
|
50
|
+
x[k + 3]
|
|
51
51
|
);
|
|
52
|
-
|
|
52
|
+
x.length = 0;
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
/* It will be called on last listener unsubscribing.
|
|
@@ -87,20 +87,20 @@ const z = 4, Z = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = {
|
|
|
87
87
|
};
|
|
88
88
|
};
|
|
89
89
|
var F = /* @__PURE__ */ ((e) => (e.EDIT = "EDIT", e.SELECT = "SELECT", e.NONE = "NONE", e))(F || {});
|
|
90
|
-
const
|
|
91
|
-
const o = /* @__PURE__ */ M(
|
|
90
|
+
const z = { selected: [] }, Re = (e, t, n) => {
|
|
91
|
+
const o = /* @__PURE__ */ M(z);
|
|
92
92
|
let s = t;
|
|
93
93
|
const f = () => {
|
|
94
|
-
|
|
94
|
+
Y(o.get(), z) || o.set(z);
|
|
95
95
|
}, A = () => {
|
|
96
96
|
var g;
|
|
97
97
|
return ((g = o.get().selected) == null ? void 0 : g.length) === 0;
|
|
98
|
-
},
|
|
98
|
+
}, C = (g) => {
|
|
99
99
|
if (A())
|
|
100
100
|
return !1;
|
|
101
|
-
const
|
|
102
|
-
return o.get().selected.some((L) => L.id ===
|
|
103
|
-
},
|
|
101
|
+
const E = typeof g == "string" ? g : g.id;
|
|
102
|
+
return o.get().selected.some((L) => L.id === E);
|
|
103
|
+
}, w = (g, E) => {
|
|
104
104
|
let L;
|
|
105
105
|
if (Array.isArray(g)) {
|
|
106
106
|
if (L = g.map((i) => e.getAnnotation(i)).filter(Boolean), L.length < g.length) {
|
|
@@ -115,29 +115,29 @@ const P = { selected: [] }, Be = (e, t, n) => {
|
|
|
115
115
|
}
|
|
116
116
|
L = [i];
|
|
117
117
|
}
|
|
118
|
-
const
|
|
119
|
-
const h =
|
|
118
|
+
const R = L.reduce((i, u) => {
|
|
119
|
+
const h = b(u);
|
|
120
120
|
return h === "EDIT" ? [...i, { id: u.id, editable: !0 }] : h === "SELECT" ? [...i, { id: u.id }] : i;
|
|
121
121
|
}, []);
|
|
122
|
-
o.set({ selected:
|
|
123
|
-
}, m = (g,
|
|
124
|
-
const L = Array.isArray(g) ? g : [g],
|
|
122
|
+
o.set({ selected: R, event: E });
|
|
123
|
+
}, m = (g, E) => {
|
|
124
|
+
const L = Array.isArray(g) ? g : [g], R = L.map((i) => e.getAnnotation(i)).filter((i) => !!i);
|
|
125
125
|
o.set({
|
|
126
|
-
selected:
|
|
127
|
-
const u =
|
|
126
|
+
selected: R.map((i) => {
|
|
127
|
+
const u = E === void 0 ? b(i) === "EDIT" : E;
|
|
128
128
|
return { id: i.id, editable: u };
|
|
129
129
|
})
|
|
130
|
-
}),
|
|
130
|
+
}), R.length !== L.length && console.warn("Invalid selection", g);
|
|
131
131
|
}, T = (g) => {
|
|
132
132
|
if (A())
|
|
133
133
|
return !1;
|
|
134
|
-
const { selected:
|
|
135
|
-
|
|
134
|
+
const { selected: E } = o.get();
|
|
135
|
+
E.some(({ id: R }) => g.includes(R)) && o.set({ selected: E.filter(({ id: R }) => !g.includes(R)) });
|
|
136
136
|
}, l = (g) => {
|
|
137
|
-
s = g, m(o.get().selected.map(({ id:
|
|
138
|
-
},
|
|
137
|
+
s = g, m(o.get().selected.map(({ id: E }) => E));
|
|
138
|
+
}, b = (g) => K(g, s, n);
|
|
139
139
|
return e.observe(
|
|
140
|
-
({ changes: g }) => T((g.deleted || []).map((
|
|
140
|
+
({ changes: g }) => T((g.deleted || []).map((E) => E.id))
|
|
141
141
|
), {
|
|
142
142
|
get event() {
|
|
143
143
|
const g = o.get();
|
|
@@ -151,22 +151,22 @@ const P = { selected: [] }, Be = (e, t, n) => {
|
|
|
151
151
|
return s;
|
|
152
152
|
},
|
|
153
153
|
clear: f,
|
|
154
|
-
evalSelectAction:
|
|
154
|
+
evalSelectAction: b,
|
|
155
155
|
isEmpty: A,
|
|
156
|
-
isSelected:
|
|
156
|
+
isSelected: C,
|
|
157
157
|
setSelected: m,
|
|
158
158
|
setUserSelectAction: l,
|
|
159
159
|
subscribe: o.subscribe.bind(o),
|
|
160
|
-
userSelect:
|
|
160
|
+
userSelect: w
|
|
161
161
|
};
|
|
162
162
|
}, K = (e, t, n) => {
|
|
163
163
|
const o = n ? n.serialize(e) : e;
|
|
164
164
|
return typeof t == "function" ? t(o) : t || "EDIT";
|
|
165
|
-
},
|
|
165
|
+
}, D = [];
|
|
166
166
|
for (let e = 0; e < 256; ++e)
|
|
167
|
-
|
|
167
|
+
D.push((e + 256).toString(16).slice(1));
|
|
168
168
|
function ee(e, t = 0) {
|
|
169
|
-
return (
|
|
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();
|
|
170
170
|
}
|
|
171
171
|
const te = new Uint8Array(16);
|
|
172
172
|
function ne() {
|
|
@@ -183,7 +183,7 @@ function oe(e, t, n) {
|
|
|
183
183
|
throw new Error("Random bytes length must be >= 16");
|
|
184
184
|
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, ee(o);
|
|
185
185
|
}
|
|
186
|
-
const
|
|
186
|
+
const Be = (e) => {
|
|
187
187
|
const { creator: t, updatedBy: n } = e.target, o = e.bodies.reduce((s, f) => [...s, f.creator, f.updatedBy].filter(Boolean), []);
|
|
188
188
|
return [
|
|
189
189
|
t,
|
|
@@ -200,7 +200,7 @@ const De = (e) => {
|
|
|
200
200
|
bodies: (e.bodies || []).map(t),
|
|
201
201
|
target: t(e.target)
|
|
202
202
|
};
|
|
203
|
-
},
|
|
203
|
+
}, De = (e, t, n, o) => ({
|
|
204
204
|
id: H(),
|
|
205
205
|
annotation: typeof e == "string" ? e : e.id,
|
|
206
206
|
created: n || /* @__PURE__ */ new Date(),
|
|
@@ -214,8 +214,8 @@ const De = (e) => {
|
|
|
214
214
|
return e.bodies.filter((o) => !n.has(o.id));
|
|
215
215
|
}, de = (e, t) => t.bodies.map((n) => {
|
|
216
216
|
const o = e.bodies.find((s) => s.id === n.id);
|
|
217
|
-
return { newBody: n, oldBody: o &&
|
|
218
|
-
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), re = (e, t) =>
|
|
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
219
|
const n = se(e, t), o = ie(e, t), s = de(e, t);
|
|
220
220
|
return {
|
|
221
221
|
oldValue: e,
|
|
@@ -233,42 +233,42 @@ const ce = (e, 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:
|
|
237
|
-
if (!(
|
|
238
|
-
const T = (f = n.updated) == null ? void 0 : f.some((
|
|
239
|
-
if (
|
|
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)
|
|
240
240
|
return !1;
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
if (e.options.annotations) {
|
|
244
|
-
const
|
|
244
|
+
const C = /* @__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) =>
|
|
249
|
+
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((m) => C.has(m));
|
|
250
250
|
} else
|
|
251
251
|
return !0;
|
|
252
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)),
|
|
254
|
-
...(e.created || []).filter((l) => !f.has(l.id)).map((l) => A.has(l.id) ? t.updated.find(({ oldValue:
|
|
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),
|
|
255
255
|
...t.created || []
|
|
256
256
|
], m = [
|
|
257
257
|
...(e.deleted || []).filter((l) => !s.has(l.id)),
|
|
258
258
|
...(t.deleted || []).filter((l) => !n.has(l.id))
|
|
259
259
|
], T = [
|
|
260
260
|
...(e.updated || []).filter(({ newValue: l }) => !f.has(l.id)).map((l) => {
|
|
261
|
-
const { oldValue:
|
|
261
|
+
const { oldValue: b, newValue: g } = l;
|
|
262
262
|
if (A.has(g.id)) {
|
|
263
|
-
const
|
|
264
|
-
return W(
|
|
263
|
+
const E = t.updated.find((L) => L.oldValue.id === g.id).newValue;
|
|
264
|
+
return W(b, E);
|
|
265
265
|
} else
|
|
266
266
|
return l;
|
|
267
267
|
}),
|
|
268
|
-
...(t.updated || []).filter(({ oldValue: l }) => !
|
|
268
|
+
...(t.updated || []).filter(({ oldValue: l }) => !C.has(l.id))
|
|
269
269
|
];
|
|
270
|
-
return { created:
|
|
271
|
-
},
|
|
270
|
+
return { created: w, deleted: m, updated: T };
|
|
271
|
+
}, $ = (e) => {
|
|
272
272
|
const t = e.id === void 0 ? H() : e.id;
|
|
273
273
|
return {
|
|
274
274
|
...e,
|
|
@@ -282,7 +282,7 @@ const ce = (e, t) => {
|
|
|
282
282
|
annotation: t
|
|
283
283
|
}
|
|
284
284
|
};
|
|
285
|
-
}, ue = (e) => e.id !== void 0,
|
|
285
|
+
}, ue = (e) => e.id !== void 0, Ne = () => {
|
|
286
286
|
const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = [], o = (d, r = {}) => {
|
|
287
287
|
n.push({ onChange: d, options: r });
|
|
288
288
|
}, s = (d) => {
|
|
@@ -305,33 +305,33 @@ const ce = (e, t) => {
|
|
|
305
305
|
if (d.id && e.get(d.id))
|
|
306
306
|
throw Error(`Cannot add annotation ${d.id} - exists already`);
|
|
307
307
|
{
|
|
308
|
-
const p =
|
|
309
|
-
e.set(p.id, p), p.bodies.forEach((
|
|
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
310
|
}
|
|
311
|
-
},
|
|
312
|
-
const c =
|
|
313
|
-
if (
|
|
314
|
-
const
|
|
315
|
-
return p === c.id ? e.set(p, c) : (e.delete(p), e.set(c.id, c)),
|
|
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;
|
|
316
316
|
} else
|
|
317
317
|
console.warn(`Cannot update annotation ${p} - does not exist`);
|
|
318
|
-
},
|
|
319
|
-
const p = ue(r) ? c : r,
|
|
320
|
-
|
|
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
321
|
}, m = (d, r = O.LOCAL) => {
|
|
322
|
-
!!e.get(d.id) ?
|
|
322
|
+
!!e.get(d.id) ? w(d, r) : A(d, r);
|
|
323
323
|
}, T = (d, r = O.LOCAL) => {
|
|
324
|
-
const c = d.reduce((p,
|
|
325
|
-
const
|
|
326
|
-
return
|
|
324
|
+
const c = d.reduce((p, S) => {
|
|
325
|
+
const U = C(S);
|
|
326
|
+
return U ? [...p, U] : p;
|
|
327
327
|
}, []);
|
|
328
328
|
c.length > 0 && f(r, { updated: c });
|
|
329
329
|
}, l = (d, r = O.LOCAL) => {
|
|
330
|
-
const c = d.map(
|
|
331
|
-
p.forEach((
|
|
332
|
-
e.set(
|
|
333
|
-
}), f(r, { created: p, updated:
|
|
334
|
-
},
|
|
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
335
|
const c = e.get(d.annotation);
|
|
336
336
|
if (c) {
|
|
337
337
|
const p = {
|
|
@@ -345,39 +345,39 @@ const ce = (e, t) => {
|
|
|
345
345
|
}] });
|
|
346
346
|
} else
|
|
347
347
|
console.warn(`Attempt to add body to missing annotation: ${d.annotation}`);
|
|
348
|
-
}, g = () => [...e.values()],
|
|
348
|
+
}, g = () => [...e.values()], E = (d = O.LOCAL) => {
|
|
349
349
|
const r = [...e.values()];
|
|
350
350
|
e.clear(), t.clear(), f(d, { deleted: r });
|
|
351
351
|
}, L = (d, r = !0, c = O.LOCAL) => {
|
|
352
|
-
const p = d.map(
|
|
352
|
+
const p = d.map($);
|
|
353
353
|
if (r) {
|
|
354
|
-
const
|
|
355
|
-
e.clear(), t.clear(), p.forEach((
|
|
356
|
-
e.set(
|
|
357
|
-
}), f(c, { created: p, deleted:
|
|
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
358
|
} else {
|
|
359
|
-
const
|
|
360
|
-
const
|
|
361
|
-
return
|
|
359
|
+
const S = d.reduce((U, B) => {
|
|
360
|
+
const _ = B.id && e.get(B.id);
|
|
361
|
+
return _ ? [...U, _] : U;
|
|
362
362
|
}, []);
|
|
363
|
-
if (
|
|
364
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${
|
|
365
|
-
p.forEach((
|
|
366
|
-
e.set(
|
|
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
367
|
}), f(c, { created: p });
|
|
368
368
|
}
|
|
369
|
-
},
|
|
369
|
+
}, R = (d) => {
|
|
370
370
|
const r = typeof d == "string" ? d : d.id, c = e.get(r);
|
|
371
371
|
if (c)
|
|
372
372
|
return e.delete(r), c.bodies.forEach((p) => t.delete(p.id)), c;
|
|
373
373
|
console.warn(`Attempt to delete missing annotation: ${r}`);
|
|
374
374
|
}, i = (d, r = O.LOCAL) => {
|
|
375
|
-
const c =
|
|
375
|
+
const c = R(d);
|
|
376
376
|
c && f(r, { deleted: [c] });
|
|
377
377
|
}, u = (d, r = O.LOCAL) => {
|
|
378
|
-
const c = d.reduce((p,
|
|
379
|
-
const
|
|
380
|
-
return
|
|
378
|
+
const c = d.reduce((p, S) => {
|
|
379
|
+
const U = R(S);
|
|
380
|
+
return U ? [...p, U] : p;
|
|
381
381
|
}, []);
|
|
382
382
|
c.length > 0 && f(r, { deleted: c });
|
|
383
383
|
}, h = (d) => {
|
|
@@ -388,7 +388,7 @@ const ce = (e, t) => {
|
|
|
388
388
|
t.delete(c.id);
|
|
389
389
|
const p = {
|
|
390
390
|
...r,
|
|
391
|
-
bodies: r.bodies.filter((
|
|
391
|
+
bodies: r.bodies.filter((U) => U.id !== d.id)
|
|
392
392
|
};
|
|
393
393
|
return e.set(r.id, p), {
|
|
394
394
|
oldValue: r,
|
|
@@ -399,45 +399,45 @@ const ce = (e, t) => {
|
|
|
399
399
|
console.warn(`Attempt to delete missing body ${d.id} from annotation ${d.annotation}`);
|
|
400
400
|
} else
|
|
401
401
|
console.warn(`Attempt to delete body from missing annotation ${d.annotation}`);
|
|
402
|
-
},
|
|
402
|
+
}, v = (d, r = O.LOCAL) => {
|
|
403
403
|
const c = h(d);
|
|
404
404
|
c && f(r, { updated: [c] });
|
|
405
405
|
}, a = (d, r = O.LOCAL) => {
|
|
406
406
|
const c = d.map((p) => h(p)).filter(Boolean);
|
|
407
407
|
c.length > 0 && f(r, { updated: c });
|
|
408
|
-
},
|
|
408
|
+
}, y = (d) => {
|
|
409
409
|
const r = e.get(d);
|
|
410
410
|
return r ? { ...r } : void 0;
|
|
411
|
-
},
|
|
411
|
+
}, N = (d) => {
|
|
412
412
|
const r = t.get(d);
|
|
413
413
|
if (r) {
|
|
414
|
-
const p =
|
|
414
|
+
const p = y(r).bodies.find((S) => S.id === d);
|
|
415
415
|
if (p)
|
|
416
416
|
return p;
|
|
417
417
|
console.error(`Store integrity error: body ${d} in index, but not in annotation`);
|
|
418
418
|
} else
|
|
419
419
|
console.warn(`Attempt to retrieve missing body: ${d}`);
|
|
420
|
-
},
|
|
420
|
+
}, I = (d, r) => {
|
|
421
421
|
if (d.annotation !== r.annotation)
|
|
422
422
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
423
423
|
const c = e.get(d.annotation);
|
|
424
424
|
if (c) {
|
|
425
|
-
const p = c.bodies.find((
|
|
425
|
+
const p = c.bodies.find((U) => U.id === d.id), S = {
|
|
426
426
|
...c,
|
|
427
|
-
bodies: c.bodies.map((
|
|
427
|
+
bodies: c.bodies.map((U) => U.id === p.id ? r : U)
|
|
428
428
|
};
|
|
429
|
-
return e.set(c.id,
|
|
429
|
+
return e.set(c.id, S), p.id !== r.id && (t.delete(p.id), t.set(r.id, S.id)), {
|
|
430
430
|
oldValue: c,
|
|
431
|
-
newValue:
|
|
431
|
+
newValue: S,
|
|
432
432
|
bodiesUpdated: [{ oldBody: p, newBody: r }]
|
|
433
433
|
};
|
|
434
434
|
} else
|
|
435
435
|
console.warn(`Attempt to add body to missing annotation ${d.annotation}`);
|
|
436
436
|
}, Q = (d, r, c = O.LOCAL) => {
|
|
437
|
-
const p =
|
|
437
|
+
const p = I(d, r);
|
|
438
438
|
p && f(c, { updated: [p] });
|
|
439
439
|
}, J = (d, r = O.LOCAL) => {
|
|
440
|
-
const c = d.map((p) =>
|
|
440
|
+
const c = d.map((p) => I({ id: p.id, annotation: p.annotation }, p)).filter(Boolean);
|
|
441
441
|
f(r, { updated: c });
|
|
442
442
|
}, j = (d) => {
|
|
443
443
|
const r = e.get(d.annotation);
|
|
@@ -462,7 +462,7 @@ const ce = (e, t) => {
|
|
|
462
462
|
};
|
|
463
463
|
return {
|
|
464
464
|
addAnnotation: A,
|
|
465
|
-
addBody:
|
|
465
|
+
addBody: b,
|
|
466
466
|
all: g,
|
|
467
467
|
bulkAddAnnotations: L,
|
|
468
468
|
bulkDeleteAnnotations: u,
|
|
@@ -474,14 +474,14 @@ const ce = (e, t) => {
|
|
|
474
474
|
c.length > 0 && f(r, { updated: c });
|
|
475
475
|
},
|
|
476
476
|
bulkUpsertAnnotations: l,
|
|
477
|
-
clear:
|
|
477
|
+
clear: E,
|
|
478
478
|
deleteAnnotation: i,
|
|
479
|
-
deleteBody:
|
|
480
|
-
getAnnotation:
|
|
481
|
-
getBody:
|
|
479
|
+
deleteBody: v,
|
|
480
|
+
getAnnotation: y,
|
|
481
|
+
getBody: N,
|
|
482
482
|
observe: o,
|
|
483
483
|
unobserve: s,
|
|
484
|
-
updateAnnotation:
|
|
484
|
+
updateAnnotation: w,
|
|
485
485
|
updateBody: Q,
|
|
486
486
|
updateTarget: (d, r = O.LOCAL) => {
|
|
487
487
|
const c = j(d);
|
|
@@ -504,80 +504,80 @@ let q = () => ({
|
|
|
504
504
|
};
|
|
505
505
|
}
|
|
506
506
|
});
|
|
507
|
-
const fe = 250,
|
|
507
|
+
const fe = 250, xe = (e, t) => {
|
|
508
508
|
const n = q(), o = (t == null ? void 0 : t.changes) || [];
|
|
509
509
|
let s = t ? t.pointer : -1, f = !1, A = 0;
|
|
510
|
-
const
|
|
510
|
+
const C = (a) => {
|
|
511
511
|
if (!f) {
|
|
512
|
-
const { changes:
|
|
513
|
-
if (
|
|
514
|
-
o.splice(s + 1), o.push(
|
|
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;
|
|
515
515
|
else {
|
|
516
|
-
const
|
|
517
|
-
o[
|
|
516
|
+
const I = o.length - 1;
|
|
517
|
+
o[I] = le(o[I], y);
|
|
518
518
|
}
|
|
519
|
-
A =
|
|
519
|
+
A = N;
|
|
520
520
|
}
|
|
521
521
|
f = !1;
|
|
522
522
|
};
|
|
523
|
-
e.observe(
|
|
524
|
-
const
|
|
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);
|
|
525
525
|
return {
|
|
526
526
|
canRedo: () => o.length - 1 > s,
|
|
527
527
|
canUndo: () => s > -1,
|
|
528
|
-
destroy: () => e.unobserve(
|
|
528
|
+
destroy: () => e.unobserve(C),
|
|
529
529
|
getHistory: () => ({ changes: [...o], pointer: s }),
|
|
530
|
-
on: (a,
|
|
530
|
+
on: (a, y) => n.on(a, y),
|
|
531
531
|
redo: () => {
|
|
532
532
|
if (o.length - 1 > s) {
|
|
533
533
|
f = !0;
|
|
534
|
-
const { created: a, updated:
|
|
535
|
-
m(a), l(
|
|
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;
|
|
536
536
|
}
|
|
537
537
|
},
|
|
538
538
|
undo: () => {
|
|
539
539
|
if (s > -1) {
|
|
540
540
|
f = !0;
|
|
541
|
-
const { created: a, updated:
|
|
542
|
-
|
|
541
|
+
const { created: a, updated: y, deleted: N } = o[s];
|
|
542
|
+
w(a), T(y), b(N), n.emit("undo", o[s]), s -= 1;
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
};
|
|
546
|
-
},
|
|
546
|
+
}, Ie = () => {
|
|
547
547
|
const e = /* @__PURE__ */ M([]);
|
|
548
548
|
return {
|
|
549
549
|
subscribe: e.subscribe.bind(e),
|
|
550
550
|
set: e.set.bind(e)
|
|
551
551
|
};
|
|
552
|
-
},
|
|
553
|
-
const { hover: s, selection: f, store: A, viewport:
|
|
552
|
+
}, _e = (e, t, n, o) => {
|
|
553
|
+
const { hover: s, selection: f, store: A, viewport: C } = e, w = /* @__PURE__ */ new Map();
|
|
554
554
|
let m = [], T, l;
|
|
555
|
-
const
|
|
556
|
-
|
|
555
|
+
const b = (i, u) => {
|
|
556
|
+
w.has(i) ? w.get(i).push(u) : w.set(i, [u]);
|
|
557
557
|
}, g = (i, u) => {
|
|
558
|
-
const h =
|
|
558
|
+
const h = w.get(i);
|
|
559
559
|
if (h) {
|
|
560
|
-
const
|
|
561
|
-
|
|
560
|
+
const v = h.indexOf(u);
|
|
561
|
+
v !== -1 && h.splice(v, 1);
|
|
562
562
|
}
|
|
563
|
-
},
|
|
564
|
-
|
|
565
|
-
|
|
563
|
+
}, E = (i, u, h) => {
|
|
564
|
+
w.has(i) && setTimeout(() => {
|
|
565
|
+
w.get(i).forEach((v) => {
|
|
566
566
|
if (n) {
|
|
567
|
-
const a = Array.isArray(u) ? u.map((
|
|
568
|
-
|
|
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);
|
|
569
569
|
} else
|
|
570
|
-
|
|
570
|
+
v(u, h);
|
|
571
571
|
});
|
|
572
572
|
}, 1);
|
|
573
573
|
}, L = () => {
|
|
574
574
|
const { selected: i } = f, u = (i || []).map(({ id: h }) => A.getAnnotation(h));
|
|
575
575
|
u.forEach((h) => {
|
|
576
|
-
const
|
|
577
|
-
(!
|
|
576
|
+
const v = m.find((a) => a.id === h.id);
|
|
577
|
+
(!v || !Y(v, h)) && E("updateAnnotation", h, v);
|
|
578
578
|
}), m = m.map((h) => {
|
|
579
|
-
const
|
|
580
|
-
return
|
|
579
|
+
const v = u.find(({ id: a }) => a === h.id);
|
|
580
|
+
return v || h;
|
|
581
581
|
});
|
|
582
582
|
};
|
|
583
583
|
f.subscribe(({ selected: i }) => {
|
|
@@ -587,13 +587,13 @@ const fe = 250, Ne = (e, t) => {
|
|
|
587
587
|
else if (m.length > 0 && i.length === 0)
|
|
588
588
|
m.forEach((u) => {
|
|
589
589
|
const h = A.getAnnotation(u.id);
|
|
590
|
-
h &&
|
|
590
|
+
h && !Y(h, u) && E("updateAnnotation", h, u);
|
|
591
591
|
}), m = [];
|
|
592
592
|
else {
|
|
593
593
|
const u = new Set(m.map((a) => a.id)), h = new Set(i.map(({ id: a }) => a));
|
|
594
594
|
m.filter((a) => !h.has(a.id)).forEach((a) => {
|
|
595
|
-
const
|
|
596
|
-
|
|
595
|
+
const y = A.getAnnotation(a.id);
|
|
596
|
+
y && !Y(y, a) && E("updateAnnotation", y, a);
|
|
597
597
|
}), m = [
|
|
598
598
|
// Remove annotations that were deselected
|
|
599
599
|
...m.filter((a) => h.has(a.id)),
|
|
@@ -601,36 +601,36 @@ const fe = 250, Ne = (e, t) => {
|
|
|
601
601
|
...i.filter(({ id: a }) => !u.has(a)).map(({ id: a }) => A.getAnnotation(a))
|
|
602
602
|
];
|
|
603
603
|
}
|
|
604
|
-
|
|
604
|
+
E("selectionChanged", m);
|
|
605
605
|
}
|
|
606
606
|
}), s.subscribe((i) => {
|
|
607
|
-
!T && i ?
|
|
608
|
-
}),
|
|
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
609
|
o && (l && clearTimeout(l), l = setTimeout(L, 1e3));
|
|
610
610
|
const { created: u, deleted: h } = i.changes;
|
|
611
|
-
(u || []).forEach((a) =>
|
|
611
|
+
(u || []).forEach((a) => E("createAnnotation", a)), (h || []).forEach((a) => E("deleteAnnotation", a)), (i.changes.updated || []).filter((a) => [
|
|
612
612
|
...a.bodiesCreated || [],
|
|
613
613
|
...a.bodiesDeleted || [],
|
|
614
614
|
...a.bodiesUpdated || []
|
|
615
|
-
].length > 0).forEach(({ oldValue: a, newValue:
|
|
616
|
-
const
|
|
617
|
-
m = m.map((
|
|
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);
|
|
618
618
|
});
|
|
619
619
|
}, { origin: O.LOCAL }), A.observe((i) => {
|
|
620
620
|
if (m) {
|
|
621
|
-
const u = new Set(m.map((
|
|
622
|
-
h.length > 0 && (m = m.map((
|
|
623
|
-
const a = h.find((
|
|
624
|
-
return a ||
|
|
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;
|
|
625
625
|
}));
|
|
626
626
|
}
|
|
627
627
|
}, { origin: O.REMOTE });
|
|
628
|
-
const
|
|
628
|
+
const R = (i) => (u) => {
|
|
629
629
|
const { updated: h } = u;
|
|
630
|
-
i ? (h || []).forEach((
|
|
630
|
+
i ? (h || []).forEach((v) => E("updateAnnotation", v.oldValue, v.newValue)) : (h || []).forEach((v) => E("updateAnnotation", v.newValue, v.oldValue));
|
|
631
631
|
};
|
|
632
|
-
return t.on("undo",
|
|
633
|
-
},
|
|
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
634
|
const { parsed: s, error: f } = e.parse(o);
|
|
635
635
|
return f ? {
|
|
636
636
|
parsed: n.parsed,
|
|
@@ -641,21 +641,21 @@ const fe = 250, Ne = (e, t) => {
|
|
|
641
641
|
} : {
|
|
642
642
|
...n
|
|
643
643
|
};
|
|
644
|
-
}, { parsed: [], failed: [] }),
|
|
644
|
+
}, { parsed: [], failed: [] }), Ye = (e, t, n) => {
|
|
645
645
|
const { store: o, selection: s } = e, f = (i) => {
|
|
646
646
|
if (n) {
|
|
647
647
|
const { parsed: u, error: h } = n.parse(i);
|
|
648
648
|
u ? o.addAnnotation(u, O.REMOTE) : console.error(h);
|
|
649
649
|
} else
|
|
650
650
|
o.addAnnotation(V(i), O.REMOTE);
|
|
651
|
-
}, A = () => s.clear(),
|
|
651
|
+
}, A = () => s.clear(), C = () => o.clear(), w = (i) => {
|
|
652
652
|
const u = o.getAnnotation(i);
|
|
653
653
|
return n && u ? n.serialize(u) : u;
|
|
654
654
|
}, m = () => n ? o.all().map(n.serialize) : o.all(), T = () => {
|
|
655
655
|
var h;
|
|
656
|
-
const u = (((h = s.selected) == null ? void 0 : h.map((
|
|
656
|
+
const u = (((h = s.selected) == null ? void 0 : h.map((v) => v.id)) || []).map((v) => o.getAnnotation(v)).filter(Boolean);
|
|
657
657
|
return n ? u.map(n.serialize) : u;
|
|
658
|
-
}, l = (i, u = !0) => fetch(i).then((h) => h.json()).then((h) => (g(h, u), h)),
|
|
658
|
+
}, l = (i, u = !0) => fetch(i).then((h) => h.json()).then((h) => (g(h, u), h)), b = (i) => {
|
|
659
659
|
if (typeof i == "string") {
|
|
660
660
|
const u = o.getAnnotation(i);
|
|
661
661
|
if (o.deleteAnnotation(i), u)
|
|
@@ -667,15 +667,15 @@ const fe = 250, Ne = (e, t) => {
|
|
|
667
667
|
}
|
|
668
668
|
}, g = (i, u = !0) => {
|
|
669
669
|
if (n) {
|
|
670
|
-
const h = n.parseAll || pe(n), { parsed:
|
|
671
|
-
a.length > 0 && console.warn(`Discarded ${a.length} invalid annotations`, a), o.bulkAddAnnotations(
|
|
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);
|
|
672
672
|
} else
|
|
673
673
|
o.bulkAddAnnotations(i.map(V), u, O.REMOTE);
|
|
674
|
-
},
|
|
674
|
+
}, E = (i, u) => {
|
|
675
675
|
i ? s.setSelected(i, u) : s.clear();
|
|
676
676
|
}, L = (i) => {
|
|
677
677
|
s.setUserSelectAction(i);
|
|
678
|
-
},
|
|
678
|
+
}, R = (i) => {
|
|
679
679
|
if (n) {
|
|
680
680
|
const u = n.parse(i).parsed, h = n.serialize(o.getAnnotation(u.id));
|
|
681
681
|
return o.updateAnnotation(u), h;
|
|
@@ -689,21 +689,21 @@ const fe = 250, Ne = (e, t) => {
|
|
|
689
689
|
cancelSelected: A,
|
|
690
690
|
canRedo: t.canRedo,
|
|
691
691
|
canUndo: t.canUndo,
|
|
692
|
-
clearAnnotations:
|
|
693
|
-
getAnnotationById:
|
|
692
|
+
clearAnnotations: C,
|
|
693
|
+
getAnnotationById: w,
|
|
694
694
|
getAnnotations: m,
|
|
695
695
|
getHistory: t.getHistory,
|
|
696
696
|
getSelected: T,
|
|
697
697
|
loadAnnotations: l,
|
|
698
698
|
redo: t.redo,
|
|
699
|
-
removeAnnotation:
|
|
699
|
+
removeAnnotation: b,
|
|
700
700
|
setAnnotations: g,
|
|
701
|
-
setSelected:
|
|
701
|
+
setSelected: E,
|
|
702
702
|
setUserSelectAction: L,
|
|
703
703
|
undo: t.undo,
|
|
704
|
-
updateAnnotation:
|
|
704
|
+
updateAnnotation: R
|
|
705
705
|
};
|
|
706
|
-
},
|
|
706
|
+
}, $e = (e, t, n) => typeof t == "function" ? t(e, n) : t, Pe = (e, t) => typeof e != "function" && typeof t != "function" ? {
|
|
707
707
|
...e || {},
|
|
708
708
|
...t || {}
|
|
709
709
|
} : (n, o) => {
|
|
@@ -719,11 +719,11 @@ let ge = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", he
|
|
|
719
719
|
let f = e.length - 1;
|
|
720
720
|
return (A = t) => {
|
|
721
721
|
if (!A) return "";
|
|
722
|
-
let
|
|
722
|
+
let C = "";
|
|
723
723
|
for (; ; ) {
|
|
724
|
-
let
|
|
724
|
+
let w = n(A), m = A;
|
|
725
725
|
for (; m--; )
|
|
726
|
-
if (
|
|
726
|
+
if (C += e[w[m] & f], C.length >= A) return C;
|
|
727
727
|
}
|
|
728
728
|
};
|
|
729
729
|
}
|
|
@@ -732,19 +732,19 @@ let ge = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", he
|
|
|
732
732
|
if (!f) return "";
|
|
733
733
|
let A = "";
|
|
734
734
|
for (; ; ) {
|
|
735
|
-
let
|
|
736
|
-
for (;
|
|
737
|
-
if (w
|
|
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
738
|
return A;
|
|
739
739
|
}
|
|
740
740
|
};
|
|
741
|
-
}, me = (e, t = 21) => Ae(e, t | 0, he),
|
|
741
|
+
}, me = (e, t = 21) => Ae(e, t | 0, he), Ee = (e = 21) => {
|
|
742
742
|
let t = "", n = crypto.getRandomValues(new Uint8Array(e |= 0));
|
|
743
743
|
for (; e--; )
|
|
744
744
|
t += ge[n[e] & 63];
|
|
745
745
|
return t;
|
|
746
746
|
};
|
|
747
|
-
const
|
|
747
|
+
const ze = () => ({ isGuest: !0, id: me("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), be = (e) => {
|
|
748
748
|
const t = JSON.stringify(e);
|
|
749
749
|
let n = 0;
|
|
750
750
|
for (let o = 0, s = t.length; o < s; o++) {
|
|
@@ -752,28 +752,28 @@ const Pe = () => ({ isGuest: !0, id: me("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
752
752
|
n = (n << 5) - n + f, n |= 0;
|
|
753
753
|
}
|
|
754
754
|
return `${n}`;
|
|
755
|
-
},
|
|
756
|
-
const { id: o, type: s, purpose: f, value: A, created:
|
|
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;
|
|
757
757
|
return {
|
|
758
|
-
id: o || `temp-${
|
|
758
|
+
id: o || `temp-${be(n)}`,
|
|
759
759
|
annotation: t,
|
|
760
760
|
type: s,
|
|
761
761
|
purpose: f,
|
|
762
762
|
value: A,
|
|
763
|
-
creator:
|
|
764
|
-
created:
|
|
765
|
-
updated:
|
|
763
|
+
creator: ve(m),
|
|
764
|
+
created: C ? new Date(C) : void 0,
|
|
765
|
+
updated: w ? new Date(w) : void 0,
|
|
766
766
|
...T
|
|
767
767
|
};
|
|
768
768
|
}), Me = (e) => e.map((t) => {
|
|
769
|
-
var
|
|
769
|
+
var C;
|
|
770
770
|
const { annotation: n, created: o, updated: s, ...f } = t, A = {
|
|
771
771
|
...f,
|
|
772
772
|
created: o == null ? void 0 : o.toISOString(),
|
|
773
773
|
modified: s == null ? void 0 : s.toISOString()
|
|
774
774
|
};
|
|
775
|
-
return (
|
|
776
|
-
}), je = (e) => "@context" in e && "creator" in e && "body" in e,
|
|
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 = [
|
|
777
777
|
"#ff7c00",
|
|
778
778
|
// orange
|
|
779
779
|
"#1ac938",
|
|
@@ -792,14 +792,14 @@ const Pe = () => ({ isGuest: !0, id: me("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
792
792
|
// cyan
|
|
793
793
|
"#023eff"
|
|
794
794
|
// blue
|
|
795
|
-
],
|
|
796
|
-
const e = [...
|
|
795
|
+
], we = () => {
|
|
796
|
+
const e = [...Ce];
|
|
797
797
|
return { assignRandomColor: () => {
|
|
798
798
|
const o = Math.floor(Math.random() * e.length), s = e[o];
|
|
799
799
|
return e.splice(o, 1), s;
|
|
800
800
|
}, releaseColor: (o) => e.push(o) };
|
|
801
801
|
}, Le = () => {
|
|
802
|
-
const e =
|
|
802
|
+
const e = we();
|
|
803
803
|
return { addUser: (o, s) => {
|
|
804
804
|
const f = e.assignRandomColor();
|
|
805
805
|
return {
|
|
@@ -808,53 +808,55 @@ const Pe = () => ({ isGuest: !0, id: me("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
808
808
|
color: f
|
|
809
809
|
};
|
|
810
810
|
}, removeUser: (o) => e.releaseColor(o.appearance.color) };
|
|
811
|
-
},
|
|
812
|
-
|
|
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) => {
|
|
813
815
|
if (n.has(l)) {
|
|
814
|
-
console.warn("Attempt to add user that is already present", l,
|
|
816
|
+
console.warn("Attempt to add user that is already present", l, b);
|
|
815
817
|
return;
|
|
816
818
|
}
|
|
817
|
-
const g = e.addUser(l,
|
|
819
|
+
const g = e.addUser(l, b);
|
|
818
820
|
n.set(l, {
|
|
819
|
-
...
|
|
821
|
+
...b,
|
|
820
822
|
presenceKey: l,
|
|
821
823
|
appearance: g
|
|
822
824
|
});
|
|
823
825
|
}, f = (l) => {
|
|
824
|
-
const
|
|
825
|
-
if (!
|
|
826
|
+
const b = n.get(l);
|
|
827
|
+
if (!b) {
|
|
826
828
|
console.warn("Attempt to remove user that is not present", l);
|
|
827
829
|
return;
|
|
828
830
|
}
|
|
829
|
-
e.removeUser(
|
|
831
|
+
e.removeUser(b), n.delete(l);
|
|
830
832
|
}, A = (l) => {
|
|
831
|
-
const
|
|
832
|
-
g.forEach(({ presenceKey: L, user:
|
|
833
|
-
const { presenceKey:
|
|
834
|
-
o.has(
|
|
835
|
-
}), (g.length > 0 ||
|
|
836
|
-
},
|
|
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);
|
|
837
|
+
}), (g.length > 0 || E.length > 0) && t.emit("presence", m());
|
|
838
|
+
}, C = (l, b) => {
|
|
837
839
|
const g = n.get(l);
|
|
838
840
|
if (!g) {
|
|
839
841
|
console.warn("Activity notification from user that is not present");
|
|
840
842
|
return;
|
|
841
843
|
}
|
|
842
|
-
const
|
|
843
|
-
(!
|
|
844
|
-
},
|
|
844
|
+
const E = o.get(l);
|
|
845
|
+
(!E || !Ue(E, b)) && (o.set(l, b), t.emit("selectionChange", g, b));
|
|
846
|
+
}, w = (l, b) => {
|
|
845
847
|
const g = n.get(l);
|
|
846
848
|
if (!g) {
|
|
847
849
|
console.warn("Selection change for user that is not present", l);
|
|
848
850
|
return;
|
|
849
851
|
}
|
|
850
|
-
|
|
852
|
+
b ? o.set(l, b) : o.delete(l), t.emit("selectionChange", g, b);
|
|
851
853
|
}, m = () => [...Array.from(n.values())];
|
|
852
854
|
return {
|
|
853
855
|
getPresentUsers: m,
|
|
854
|
-
notifyActivity:
|
|
855
|
-
on: (l,
|
|
856
|
+
notifyActivity: C,
|
|
857
|
+
on: (l, b) => t.on(l, b),
|
|
856
858
|
syncUsers: A,
|
|
857
|
-
updateSelection:
|
|
859
|
+
updateSelection: w
|
|
858
860
|
};
|
|
859
861
|
};
|
|
860
862
|
export {
|
|
@@ -862,30 +864,30 @@ export {
|
|
|
862
864
|
O as Origin,
|
|
863
865
|
Ge as PRESENCE_KEY,
|
|
864
866
|
F as UserSelectAction,
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
867
|
+
Pe as chainStyles,
|
|
868
|
+
$e as computeStyle,
|
|
869
|
+
ze as createAnonymousGuest,
|
|
870
|
+
Ye as createBaseAnnotator,
|
|
871
|
+
De as createBody,
|
|
870
872
|
Le as createDefaultAppearanceProvider,
|
|
871
873
|
Oe as createHoverState,
|
|
872
|
-
|
|
874
|
+
_e as createLifecycleObserver,
|
|
873
875
|
He as createPresenceState,
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
876
|
+
Re as createSelectionState,
|
|
877
|
+
Ne as createStore,
|
|
878
|
+
xe as createUndoStack,
|
|
879
|
+
Ie as createViewportState,
|
|
880
|
+
we as defaultColorProvider,
|
|
879
881
|
W as diffAnnotations,
|
|
880
|
-
|
|
882
|
+
Be as getContributors,
|
|
881
883
|
je as isW3CAnnotation,
|
|
882
884
|
le as mergeChanges,
|
|
883
885
|
K as onUserSelect,
|
|
884
886
|
pe as parseAll,
|
|
885
887
|
Ve as parseW3CBodies,
|
|
886
|
-
|
|
888
|
+
ve as parseW3CUser,
|
|
887
889
|
V as reviveDates,
|
|
888
|
-
|
|
890
|
+
ke as serializeAll,
|
|
889
891
|
Me as serializeW3CBodies,
|
|
890
892
|
ce as shouldNotify
|
|
891
893
|
};
|