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