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