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