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