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