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