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