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