@annotorious/core 3.0.5 → 3.0.7
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 +419 -405
- 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/model/DrawingStyle.d.ts +15 -0
- package/dist/model/DrawingStyle.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
|
@@ -21,44 +21,44 @@ function I(e, n) {
|
|
|
21
21
|
}
|
|
22
22
|
function _() {
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function Z(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 (
|
|
33
|
-
const w = !
|
|
31
|
+
function d(v) {
|
|
32
|
+
if (Z(e, v) && (e = v, t)) {
|
|
33
|
+
const w = !x.length;
|
|
34
34
|
for (const g of o)
|
|
35
|
-
g[1](),
|
|
35
|
+
g[1](), x.push(g, e);
|
|
36
36
|
if (w) {
|
|
37
|
-
for (let g = 0; g <
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
for (let g = 0; g < x.length; g += 2)
|
|
38
|
+
x[g][0](x[g + 1]);
|
|
39
|
+
x.length = 0;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
43
|
+
function p(v) {
|
|
44
|
+
d(v(e));
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
const g = [
|
|
48
|
-
return o.add(g), o.size === 1 && (t = n(
|
|
46
|
+
function m(v, w = _) {
|
|
47
|
+
const g = [v, w];
|
|
48
|
+
return o.add(g), o.size === 1 && (t = n(d, p) || _), v(e), () => {
|
|
49
49
|
o.delete(g), o.size === 0 && t && (t(), t = null);
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
return { set:
|
|
52
|
+
return { set: d, update: p, 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((d) => o = d), e.observe(({ changes: d }) => {
|
|
58
58
|
if (o) {
|
|
59
|
-
(
|
|
60
|
-
const
|
|
61
|
-
|
|
59
|
+
(d.deleted || []).some((v) => v.id === o) && t(void 0);
|
|
60
|
+
const m = (d.updated || []).find(({ oldValue: v }) => v.id === o);
|
|
61
|
+
m && t(m.newValue.id);
|
|
62
62
|
}
|
|
63
63
|
}), {
|
|
64
64
|
get current() {
|
|
@@ -68,72 +68,75 @@ const Ue = (e) => {
|
|
|
68
68
|
set: t
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
-
var
|
|
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 (
|
|
71
|
+
var F = /* @__PURE__ */ ((e) => (e.EDIT = "EDIT", e.SELECT = "SELECT", e.NONE = "NONE", e))(F || {});
|
|
72
|
+
const z = { selected: [] }, Te = (e, n, t) => {
|
|
73
|
+
const { subscribe: o, set: d } = M(z);
|
|
74
|
+
let p = n, m = z;
|
|
75
|
+
o((h) => m = h);
|
|
76
|
+
const v = () => {
|
|
77
|
+
I(m, z) || d(z);
|
|
78
|
+
}, w = () => {
|
|
79
|
+
var h;
|
|
80
|
+
return ((h = m.selected) == null ? void 0 : h.length) === 0;
|
|
81
|
+
}, g = (h) => {
|
|
82
|
+
if (w())
|
|
83
83
|
return !1;
|
|
84
|
-
const
|
|
85
|
-
return
|
|
86
|
-
},
|
|
87
|
-
const
|
|
88
|
-
if (!
|
|
89
|
-
console.warn("Invalid selection: " +
|
|
84
|
+
const C = typeof h == "string" ? h : h.id;
|
|
85
|
+
return m.selected.some((O) => O.id === C);
|
|
86
|
+
}, L = (h, C) => {
|
|
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, p, t)) {
|
|
93
93
|
case "EDIT":
|
|
94
|
-
|
|
94
|
+
d({ selected: [{ id: h, editable: !0 }], event: C });
|
|
95
95
|
break;
|
|
96
96
|
case "SELECT":
|
|
97
|
-
|
|
97
|
+
d({ selected: [{ id: h }], event: C });
|
|
98
98
|
break;
|
|
99
99
|
default:
|
|
100
|
-
|
|
100
|
+
d({ selected: [], event: C });
|
|
101
101
|
}
|
|
102
|
-
},
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
selected:
|
|
106
|
-
const
|
|
107
|
-
return { id:
|
|
102
|
+
}, a = (h, C) => {
|
|
103
|
+
const O = Array.isArray(h) ? h : [h], r = O.map((u) => e.getAnnotation(u)).filter((u) => !!u);
|
|
104
|
+
d({
|
|
105
|
+
selected: r.map((u) => {
|
|
106
|
+
const s = C === void 0 ? G(u, p, t) === "EDIT" : C;
|
|
107
|
+
return { id: u.id, editable: s };
|
|
108
108
|
})
|
|
109
|
-
}),
|
|
110
|
-
},
|
|
111
|
-
if (
|
|
109
|
+
}), r.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: C } = m;
|
|
114
|
+
C.some(({ id: r }) => h.includes(r)) && d({ selected: C.filter(({ id: r }) => !h.includes(r)) });
|
|
115
|
+
}, U = (h) => p = h;
|
|
116
116
|
return e.observe(
|
|
117
|
-
({ changes:
|
|
117
|
+
({ changes: h }) => E((h.deleted || []).map((C) => C.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 p;
|
|
127
127
|
},
|
|
128
|
-
clear:
|
|
129
|
-
isEmpty:
|
|
130
|
-
isSelected:
|
|
131
|
-
setSelected:
|
|
132
|
-
setUserSelectAction:
|
|
133
|
-
subscribe:
|
|
134
|
-
userSelect:
|
|
128
|
+
clear: v,
|
|
129
|
+
isEmpty: w,
|
|
130
|
+
isSelected: g,
|
|
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));
|
|
@@ -150,7 +153,7 @@ var ne = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(cryp
|
|
|
150
153
|
const H = {
|
|
151
154
|
randomUUID: ne
|
|
152
155
|
};
|
|
153
|
-
function
|
|
156
|
+
function J(e, n, t) {
|
|
154
157
|
if (H.randomUUID && !n && !e)
|
|
155
158
|
return H.randomUUID();
|
|
156
159
|
e = e || {};
|
|
@@ -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((d, p) => [...d, p.creator, p.updatedBy].filter(Boolean), []);
|
|
162
165
|
return [
|
|
163
166
|
n,
|
|
164
167
|
t,
|
|
165
168
|
...o
|
|
166
|
-
].filter((
|
|
169
|
+
].filter((d) => d);
|
|
167
170
|
}, j = (e) => {
|
|
168
171
|
const n = (t) => {
|
|
169
172
|
const o = { ...t };
|
|
@@ -175,7 +178,7 @@ const Oe = (e) => {
|
|
|
175
178
|
target: n(e.target)
|
|
176
179
|
};
|
|
177
180
|
}, De = (e, n, t, o) => ({
|
|
178
|
-
id:
|
|
181
|
+
id: J(),
|
|
179
182
|
annotation: typeof e == "string" ? e : e.id,
|
|
180
183
|
created: t || /* @__PURE__ */ new Date(),
|
|
181
184
|
creator: o,
|
|
@@ -187,63 +190,63 @@ 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((d) => d.id === t.id);
|
|
191
194
|
return { newBody: t, oldBody: o && !I(o, t) ? o : void 0 };
|
|
192
|
-
}).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), de = (e, n) => !I(e.target, n.target),
|
|
193
|
-
const t = oe(e, n), o = se(e, n),
|
|
195
|
+
}).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), de = (e, n) => !I(e.target, n.target), Q = (e, n) => {
|
|
196
|
+
const t = oe(e, n), o = se(e, n), d = 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: d.length > 0 ? d : 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 p, 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 = (p = t.updated) == null ? void 0 : p.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
|
|
221
|
+
const v = /* @__PURE__ */ new Set([
|
|
219
222
|
...(t.created || []).map((g) => g.id),
|
|
220
223
|
...(t.deleted || []).map((g) => g.id),
|
|
221
224
|
...(t.updated || []).map(({ oldValue: g }) => g.id)
|
|
222
225
|
]);
|
|
223
|
-
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((g) =>
|
|
226
|
+
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((g) => v.has(g));
|
|
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)), d = new Set((n.created || []).map((a) => a.id)), p = 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) => !p.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
233
|
], g = [
|
|
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
|
|
234
|
+
...(e.deleted || []).filter((a) => !d.has(a.id)),
|
|
235
|
+
...(n.deleted || []).filter((a) => !t.has(a.id))
|
|
236
|
+
], L = [
|
|
237
|
+
...(e.updated || []).filter(({ newValue: a }) => !p.has(a.id)).map((a) => {
|
|
238
|
+
const { oldValue: E, newValue: U } = a;
|
|
239
|
+
if (m.has(U.id)) {
|
|
240
|
+
const h = n.updated.find((C) => C.oldValue.id === U.id).newValue;
|
|
241
|
+
return Q(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: g, updated:
|
|
247
|
+
return { created: w, deleted: g, updated: L };
|
|
245
248
|
}, V = (e) => {
|
|
246
|
-
const n = e.id === void 0 ?
|
|
249
|
+
const n = e.id === void 0 ? J() : e.id;
|
|
247
250
|
return {
|
|
248
251
|
...e,
|
|
249
252
|
id: n,
|
|
@@ -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
|
+
}, d = (i) => {
|
|
266
|
+
const c = t.findIndex((l) => l.onChange == i);
|
|
264
267
|
c > -1 && t.splice(c, 1);
|
|
265
|
-
},
|
|
268
|
+
}, p = (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)), p(c, { created: [f] });
|
|
284
287
|
}
|
|
285
|
-
},
|
|
286
|
-
const l = V(typeof
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
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 y = Q(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)), y;
|
|
290
293
|
} else
|
|
291
|
-
console.warn(`Cannot update annotation ${
|
|
292
|
-
}, w = (
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
}, g = (
|
|
296
|
-
const l =
|
|
297
|
-
const
|
|
298
|
-
return
|
|
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 && p(f, { updated: [S] });
|
|
298
|
+
}, g = (i, c = T.LOCAL) => {
|
|
299
|
+
const l = i.reduce((f, S) => {
|
|
300
|
+
const y = v(S);
|
|
301
|
+
return y ? [...f, y] : f;
|
|
299
302
|
}, []);
|
|
300
|
-
l.length > 0 &&
|
|
301
|
-
},
|
|
302
|
-
const l = e.get(
|
|
303
|
+
l.length > 0 && p(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), p(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(), p(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(),
|
|
323
|
-
e.set(
|
|
324
|
-
}),
|
|
324
|
+
const S = [...e.values()];
|
|
325
|
+
e.clear(), n.clear(), f.forEach((y) => {
|
|
326
|
+
e.set(y.id, y), y.bodies.forEach((B) => n.set(B.id, y.id));
|
|
327
|
+
}), p(l, { created: f, deleted: S });
|
|
325
328
|
} else {
|
|
326
|
-
const
|
|
329
|
+
const S = i.reduce((y, B) => {
|
|
327
330
|
const W = B.id && e.get(B.id);
|
|
328
|
-
return W ? [...
|
|
331
|
+
return W ? [...y, W] : y;
|
|
329
332
|
}, []);
|
|
330
|
-
if (
|
|
331
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${
|
|
332
|
-
|
|
333
|
-
e.set(
|
|
334
|
-
}),
|
|
333
|
+
if (S.length > 0)
|
|
334
|
+
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((y) => y.id).join(", ")}`);
|
|
335
|
+
f.forEach((y) => {
|
|
336
|
+
e.set(y.id, y), y.bodies.forEach((B) => n.set(B.id, y.id));
|
|
337
|
+
}), p(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
|
|
347
|
-
return
|
|
344
|
+
}, C = (i, c = T.LOCAL) => {
|
|
345
|
+
const l = h(i);
|
|
346
|
+
l && p(c, { deleted: [l] });
|
|
347
|
+
}, O = (i, c = T.LOCAL) => {
|
|
348
|
+
const l = i.reduce((f, S) => {
|
|
349
|
+
const y = h(S);
|
|
350
|
+
return y ? [...f, y] : f;
|
|
348
351
|
}, []);
|
|
349
|
-
l.length > 0 &&
|
|
350
|
-
},
|
|
351
|
-
const c = e.get(
|
|
352
|
+
l.length > 0 && p(c, { deleted: l });
|
|
353
|
+
}, r = (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((
|
|
361
|
+
bodies: c.bodies.filter((y) => y.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 = r(i);
|
|
374
|
+
l && p(c, { updated: [l] });
|
|
375
|
+
}, s = (i, c = T.LOCAL) => {
|
|
376
|
+
const l = i.map((f) => r(f)).filter(Boolean);
|
|
377
|
+
l.length > 0 && p(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((y) => y.id === i.id), S = {
|
|
393
396
|
...l,
|
|
394
|
-
bodies: l.bodies.map((
|
|
397
|
+
bodies: l.bodies.map((y) => y.id === f.id ? c : y)
|
|
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 && p(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
|
+
p(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
440
|
bulkUpdateAnnotation: g,
|
|
438
|
-
bulkUpdateBodies:
|
|
439
|
-
bulkUpdateTargets: (
|
|
440
|
-
const l =
|
|
441
|
-
l.length > 0 &&
|
|
441
|
+
bulkUpdateBodies: k,
|
|
442
|
+
bulkUpdateTargets: (i, c = T.LOCAL) => {
|
|
443
|
+
const l = i.map((f) => P(f)).filter(Boolean);
|
|
444
|
+
l.length > 0 && p(c, { updated: l });
|
|
442
445
|
},
|
|
443
446
|
clear: E,
|
|
444
|
-
deleteAnnotation:
|
|
447
|
+
deleteAnnotation: C,
|
|
445
448
|
deleteBody: u,
|
|
446
|
-
getAnnotation:
|
|
447
|
-
getBody:
|
|
449
|
+
getAnnotation: A,
|
|
450
|
+
getBody: b,
|
|
448
451
|
observe: o,
|
|
449
|
-
unobserve:
|
|
452
|
+
unobserve: d,
|
|
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 && p(c, { updated: [l] });
|
|
455
458
|
}
|
|
456
459
|
};
|
|
457
460
|
}, Be = (e) => ({
|
|
458
461
|
...e,
|
|
459
462
|
subscribe: (t) => {
|
|
460
|
-
const o = (
|
|
463
|
+
const o = (d) => t(d.state);
|
|
461
464
|
return e.observe(o), t(e.all()), () => e.unobserve(o);
|
|
462
465
|
}
|
|
463
466
|
});
|
|
464
|
-
let
|
|
467
|
+
let X = () => ({
|
|
465
468
|
emit(e, ...n) {
|
|
466
|
-
for (let t = 0, o = this.events[e] || [],
|
|
469
|
+
for (let t = 0, o = this.events[e] || [], d = o.length; t < d; t++)
|
|
467
470
|
o[t](...n);
|
|
468
471
|
},
|
|
469
472
|
events: {},
|
|
@@ -471,216 +474,225 @@ 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((d) => n !== d);
|
|
475
478
|
};
|
|
476
479
|
}
|
|
477
480
|
});
|
|
478
481
|
const ue = 250, Ie = (e) => {
|
|
479
|
-
const n =
|
|
480
|
-
let o = -1,
|
|
481
|
-
const
|
|
482
|
-
if (!
|
|
483
|
-
const { changes:
|
|
484
|
-
if (
|
|
485
|
-
t.splice(o + 1), t.push(
|
|
482
|
+
const n = X(), t = [];
|
|
483
|
+
let o = -1, d = !1, p = 0;
|
|
484
|
+
const m = (s) => {
|
|
485
|
+
if (!d) {
|
|
486
|
+
const { changes: A } = s, b = performance.now();
|
|
487
|
+
if (b - p > 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
|
+
p = b;
|
|
491
494
|
}
|
|
492
|
-
|
|
495
|
+
d = !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), g = (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
|
+
d = !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
|
+
d = !0;
|
|
514
|
+
const { created: s, updated: A, deleted: b } = t[o];
|
|
515
|
+
v(s), g(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 g = [],
|
|
525
|
-
const E = (
|
|
526
|
-
w.has(
|
|
527
|
-
},
|
|
528
|
-
const s = w.get(
|
|
525
|
+
}, xe = (e, n, t, o) => {
|
|
526
|
+
const { hover: d, selection: p, store: m, viewport: v } = e, w = /* @__PURE__ */ new Map();
|
|
527
|
+
let g = [], L, a;
|
|
528
|
+
const E = (r, u) => {
|
|
529
|
+
w.has(r) ? w.get(r).push(u) : w.set(r, [u]);
|
|
530
|
+
}, U = (r, u) => {
|
|
531
|
+
const s = w.get(r);
|
|
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 = (r, u, s) => {
|
|
537
|
+
w.has(r) && setTimeout(() => {
|
|
538
|
+
w.get(r).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
|
+
}, C = () => {
|
|
547
|
+
const { selected: r } = p, u = (r || []).map(({ id: s }) => m.getAnnotation(s));
|
|
545
548
|
u.forEach((s) => {
|
|
546
|
-
const
|
|
547
|
-
(!
|
|
549
|
+
const A = g.find((b) => b.id === s.id);
|
|
550
|
+
(!A || !I(A, s)) && h("updateAnnotation", s, A);
|
|
548
551
|
}), g = g.map((s) => {
|
|
549
|
-
const
|
|
550
|
-
return
|
|
552
|
+
const A = u.find(({ id: b }) => b === s.id);
|
|
553
|
+
return A || s;
|
|
551
554
|
});
|
|
552
555
|
};
|
|
553
|
-
|
|
554
|
-
if (!(g.length === 0 &&
|
|
555
|
-
if (g.length === 0 &&
|
|
556
|
-
g =
|
|
557
|
-
else if (g.length > 0 &&
|
|
556
|
+
p.subscribe(({ selected: r }) => {
|
|
557
|
+
if (!(g.length === 0 && r.length === 0)) {
|
|
558
|
+
if (g.length === 0 && r.length > 0)
|
|
559
|
+
g = r.map(({ id: u }) => m.getAnnotation(u));
|
|
560
|
+
else if (g.length > 0 && r.length === 0)
|
|
558
561
|
g.forEach((u) => {
|
|
559
|
-
const s =
|
|
560
|
-
s && !I(s, u) &&
|
|
562
|
+
const s = m.getAnnotation(u.id);
|
|
563
|
+
s && !I(s, u) && h("updateAnnotation", s, u);
|
|
561
564
|
}), g = [];
|
|
562
565
|
else {
|
|
563
|
-
const u = new Set(g.map((
|
|
564
|
-
g.filter((
|
|
565
|
-
const R =
|
|
566
|
-
R && !I(R,
|
|
566
|
+
const u = new Set(g.map((b) => b.id)), s = new Set(r.map(({ id: b }) => b));
|
|
567
|
+
g.filter((b) => !s.has(b.id)).forEach((b) => {
|
|
568
|
+
const R = m.getAnnotation(b.id);
|
|
569
|
+
R && !I(R, b) && h("updateAnnotation", R, b);
|
|
567
570
|
}), g = [
|
|
568
571
|
// Remove annotations that were deselected
|
|
569
|
-
...g.filter((
|
|
572
|
+
...g.filter((b) => s.has(b.id)),
|
|
570
573
|
// Add editable annotations that were selected
|
|
571
|
-
...
|
|
574
|
+
...r.filter(({ id: b }) => !u.has(b)).map(({ id: b }) => m.getAnnotation(b))
|
|
572
575
|
];
|
|
573
576
|
}
|
|
574
|
-
|
|
577
|
+
h("selectionChanged", g);
|
|
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 = g.find((
|
|
587
|
-
g = g.map((
|
|
579
|
+
}), d.subscribe((r) => {
|
|
580
|
+
!L && r ? h("mouseEnterAnnotation", m.getAnnotation(r)) : L && !r ? h("mouseLeaveAnnotation", m.getAnnotation(L)) : L && r && (h("mouseLeaveAnnotation", m.getAnnotation(L)), h("mouseEnterAnnotation", m.getAnnotation(r))), L = r;
|
|
581
|
+
}), v == null || v.subscribe((r) => h("viewportIntersect", r.map((u) => m.getAnnotation(u)))), m.observe((r) => {
|
|
582
|
+
o && (a && clearTimeout(a), a = setTimeout(C, 1e3));
|
|
583
|
+
const { created: u, deleted: s } = r.changes;
|
|
584
|
+
(u || []).forEach((b) => h("createAnnotation", b)), (s || []).forEach((b) => h("deleteAnnotation", b)), (r.changes.updated || []).filter((b) => [
|
|
585
|
+
...b.bodiesCreated || [],
|
|
586
|
+
...b.bodiesDeleted || [],
|
|
587
|
+
...b.bodiesUpdated || []
|
|
588
|
+
].length > 0).forEach(({ oldValue: b, newValue: R }) => {
|
|
589
|
+
const N = g.find((k) => k.id === b.id) || b;
|
|
590
|
+
g = g.map((k) => k.id === b.id ? R : k), h("updateAnnotation", R, N);
|
|
588
591
|
});
|
|
589
|
-
}, { origin: T.LOCAL }),
|
|
592
|
+
}, { origin: T.LOCAL }), m.observe((r) => {
|
|
590
593
|
if (g) {
|
|
591
|
-
const u = new Set(g.map((
|
|
592
|
-
s.length > 0 && (g = g.map((
|
|
593
|
-
const
|
|
594
|
-
return
|
|
594
|
+
const u = new Set(g.map((A) => A.id)), s = (r.changes.updated || []).filter(({ newValue: A }) => u.has(A.id)).map(({ newValue: A }) => A);
|
|
595
|
+
s.length > 0 && (g = g.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 = (r) => (u) => {
|
|
599
602
|
const { updated: s } = u;
|
|
600
|
-
|
|
603
|
+
r ? (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: d, error: p } = e.parse(o);
|
|
608
|
+
return p ? {
|
|
606
609
|
parsed: t.parsed,
|
|
607
610
|
failed: [...t.failed, o]
|
|
608
|
-
} :
|
|
609
|
-
parsed: [...t.parsed,
|
|
611
|
+
} : d ? {
|
|
612
|
+
parsed: [...t.parsed, d],
|
|
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: d } = e, p = (r) => {
|
|
616
619
|
if (t) {
|
|
617
|
-
const { parsed: u, error: s } = t.parse(
|
|
620
|
+
const { parsed: u, error: s } = t.parse(r);
|
|
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(r), T.REMOTE);
|
|
624
|
+
}, m = () => d.clear(), v = () => o.clear(), w = (r) => {
|
|
625
|
+
const u = o.getAnnotation(r);
|
|
623
626
|
return t && u ? t.serialize(u) : u;
|
|
624
|
-
}, g = () => t ? o.all().map(t.serialize) : o.all(),
|
|
627
|
+
}, g = () => t ? o.all().map(t.serialize) : o.all(), L = () => {
|
|
625
628
|
var s;
|
|
626
|
-
const u = (((s =
|
|
629
|
+
const u = (((s = d.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 = (r, u = !0) => fetch(r).then((s) => s.json()).then((s) => (U(s, u), s)), E = (r) => {
|
|
632
|
+
if (typeof r == "string") {
|
|
633
|
+
const u = o.getAnnotation(r);
|
|
634
|
+
if (o.deleteAnnotation(r), u)
|
|
632
635
|
return t ? t.serialize(u) : u;
|
|
633
636
|
} else {
|
|
634
|
-
const u = t ? t.parse(
|
|
637
|
+
const u = t ? t.parse(r).parsed : r;
|
|
635
638
|
if (u)
|
|
636
|
-
return o.deleteAnnotation(u),
|
|
639
|
+
return o.deleteAnnotation(u), r;
|
|
637
640
|
}
|
|
638
|
-
},
|
|
641
|
+
}, U = (r, 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(r);
|
|
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(r.map(j), u, T.REMOTE);
|
|
647
|
+
}, h = (r, u) => {
|
|
648
|
+
r ? d.setSelected(r, u) : d.clear();
|
|
649
|
+
}, C = (r) => {
|
|
650
|
+
d.clear(), d.setUserSelectAction(r);
|
|
651
|
+
}, O = (r) => {
|
|
649
652
|
if (t) {
|
|
650
|
-
const u = t.parse(
|
|
653
|
+
const u = t.parse(r).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(r.id);
|
|
657
|
+
return o.updateAnnotation(j(r)), u;
|
|
655
658
|
}
|
|
656
659
|
};
|
|
657
660
|
return {
|
|
658
|
-
addAnnotation:
|
|
659
|
-
cancelSelected:
|
|
661
|
+
addAnnotation: p,
|
|
662
|
+
cancelSelected: m,
|
|
660
663
|
canRedo: n.canRedo,
|
|
661
664
|
canUndo: n.canUndo,
|
|
662
|
-
clearAnnotations:
|
|
665
|
+
clearAnnotations: v,
|
|
663
666
|
getAnnotationById: w,
|
|
664
667
|
getAnnotations: g,
|
|
665
|
-
getSelected:
|
|
666
|
-
loadAnnotations:
|
|
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: C,
|
|
672
675
|
undo: n.undo,
|
|
673
676
|
updateAnnotation: O
|
|
674
677
|
};
|
|
678
|
+
}, $e = (e, n, t) => typeof n == "function" ? n(e, t) : n, Ve = (e, n) => typeof e != "function" && typeof n != "function" ? {
|
|
679
|
+
...e || {},
|
|
680
|
+
...n || {}
|
|
681
|
+
} : (t, o) => {
|
|
682
|
+
const d = typeof e == "function" ? e(t, o) : e, p = typeof n == "function" ? n(t, o) : n;
|
|
683
|
+
return {
|
|
684
|
+
...d || {},
|
|
685
|
+
...p || {}
|
|
686
|
+
};
|
|
675
687
|
}, pe = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
676
688
|
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
|
|
689
|
+
let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, d = -~(1.6 * o * n / e.length);
|
|
690
|
+
return (p = n) => {
|
|
691
|
+
let m = "";
|
|
680
692
|
for (; ; ) {
|
|
681
|
-
let
|
|
693
|
+
let v = t(d), w = d;
|
|
682
694
|
for (; w--; )
|
|
683
|
-
if (
|
|
695
|
+
if (m += e[v[w] & o] || "", m.length === p) return m;
|
|
684
696
|
}
|
|
685
697
|
};
|
|
686
698
|
}, me = (e, n = 21) => he(e, n, ge), Ae = (e = 21) => {
|
|
@@ -689,35 +701,35 @@ let ge = (e) => crypto.getRandomValues(new Uint8Array(e)), he = (e, n, t) => {
|
|
|
689
701
|
n += pe[t[e] & 63];
|
|
690
702
|
return n;
|
|
691
703
|
};
|
|
692
|
-
const
|
|
704
|
+
const _e = () => ({ isGuest: !0, id: me("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), be = (e) => {
|
|
693
705
|
const n = JSON.stringify(e);
|
|
694
706
|
let t = 0;
|
|
695
|
-
for (let o = 0,
|
|
696
|
-
let
|
|
697
|
-
t = (t << 5) - t +
|
|
707
|
+
for (let o = 0, d = n.length; o < d; o++) {
|
|
708
|
+
let p = n.charCodeAt(o);
|
|
709
|
+
t = (t << 5) - t + p, t |= 0;
|
|
698
710
|
}
|
|
699
711
|
return `${t}`;
|
|
700
|
-
}, ve = (e) => e ? typeof e == "object" ? { ...e } : e : void 0,
|
|
701
|
-
const { id: o, type:
|
|
712
|
+
}, ve = (e) => e ? typeof e == "object" ? { ...e } : e : void 0, Ye = (e, n) => (Array.isArray(e) ? e : [e]).map((t) => {
|
|
713
|
+
const { id: o, type: d, purpose: p, value: m, created: v, modified: w, creator: g, ...L } = t;
|
|
702
714
|
return {
|
|
703
715
|
id: o || `temp-${be(t)}`,
|
|
704
716
|
annotation: n,
|
|
705
|
-
type:
|
|
706
|
-
purpose:
|
|
707
|
-
value:
|
|
717
|
+
type: d,
|
|
718
|
+
purpose: p,
|
|
719
|
+
value: m,
|
|
708
720
|
creator: ve(g),
|
|
709
|
-
created:
|
|
721
|
+
created: v ? new Date(v) : void 0,
|
|
710
722
|
updated: w ? new Date(w) : void 0,
|
|
711
|
-
...
|
|
723
|
+
...L
|
|
712
724
|
};
|
|
713
|
-
}),
|
|
714
|
-
var
|
|
715
|
-
const { annotation: t, created: o, updated:
|
|
716
|
-
...
|
|
725
|
+
}), je = (e) => e.map((n) => {
|
|
726
|
+
var v;
|
|
727
|
+
const { annotation: t, created: o, updated: d, ...p } = n, m = {
|
|
728
|
+
...p,
|
|
717
729
|
created: o == null ? void 0 : o.toISOString(),
|
|
718
|
-
modified:
|
|
730
|
+
modified: d == null ? void 0 : d.toISOString()
|
|
719
731
|
};
|
|
720
|
-
return (
|
|
732
|
+
return (v = m.id) != null && v.startsWith("temp-") && delete m.id, m;
|
|
721
733
|
}), Ee = [
|
|
722
734
|
"#ff7c00",
|
|
723
735
|
// orange
|
|
@@ -740,96 +752,98 @@ const $e = () => ({ isGuest: !0, id: me("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
740
752
|
], we = () => {
|
|
741
753
|
const e = [...Ee];
|
|
742
754
|
return { assignRandomColor: () => {
|
|
743
|
-
const o = Math.floor(Math.random() * e.length),
|
|
744
|
-
return e.splice(o, 1),
|
|
755
|
+
const o = Math.floor(Math.random() * e.length), d = e[o];
|
|
756
|
+
return e.splice(o, 1), d;
|
|
745
757
|
}, releaseColor: (o) => e.push(o) };
|
|
746
|
-
},
|
|
758
|
+
}, Ce = () => {
|
|
747
759
|
const e = we();
|
|
748
|
-
return { addUser: (o,
|
|
749
|
-
const
|
|
760
|
+
return { addUser: (o, d) => {
|
|
761
|
+
const p = e.assignRandomColor();
|
|
750
762
|
return {
|
|
751
|
-
label:
|
|
752
|
-
avatar:
|
|
753
|
-
color:
|
|
763
|
+
label: d.name || d.id,
|
|
764
|
+
avatar: d.avatar,
|
|
765
|
+
color: p
|
|
754
766
|
};
|
|
755
767
|
}, removeUser: (o) => e.releaseColor(o.appearance.color) };
|
|
756
|
-
},
|
|
757
|
-
const n =
|
|
758
|
-
if (t.has(
|
|
759
|
-
console.warn("Attempt to add user that is already present",
|
|
768
|
+
}, ye = (e, n) => e.every((t) => e.includes(t)) && n.every((t) => e.includes(t)), Me = Ae(), Pe = (e = Ce()) => {
|
|
769
|
+
const n = X(), t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), d = (a, E) => {
|
|
770
|
+
if (t.has(a)) {
|
|
771
|
+
console.warn("Attempt to add user that is already present", a, E);
|
|
760
772
|
return;
|
|
761
773
|
}
|
|
762
|
-
const
|
|
763
|
-
t.set(
|
|
774
|
+
const U = e.addUser(a, E);
|
|
775
|
+
t.set(a, {
|
|
764
776
|
...E,
|
|
765
|
-
presenceKey:
|
|
766
|
-
appearance:
|
|
777
|
+
presenceKey: a,
|
|
778
|
+
appearance: U
|
|
767
779
|
});
|
|
768
|
-
},
|
|
769
|
-
const E = t.get(
|
|
780
|
+
}, p = (a) => {
|
|
781
|
+
const E = t.get(a);
|
|
770
782
|
if (!E) {
|
|
771
|
-
console.warn("Attempt to remove user that is not present",
|
|
783
|
+
console.warn("Attempt to remove user that is not present", a);
|
|
772
784
|
return;
|
|
773
785
|
}
|
|
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 (!
|
|
786
|
+
e.removeUser(E), t.delete(a);
|
|
787
|
+
}, m = (a) => {
|
|
788
|
+
const E = new Set(a.map((C) => C.presenceKey)), U = a.filter(({ presenceKey: C }) => !t.has(C)), h = Array.from(t.values()).filter((C) => !E.has(C.presenceKey));
|
|
789
|
+
U.forEach(({ presenceKey: C, user: O }) => d(C, O)), h.forEach((C) => {
|
|
790
|
+
const { presenceKey: O } = C;
|
|
791
|
+
o.has(O) && n.emit("selectionChange", C, null), p(O);
|
|
792
|
+
}), (U.length > 0 || h.length > 0) && n.emit("presence", g());
|
|
793
|
+
}, v = (a, E) => {
|
|
794
|
+
const U = t.get(a);
|
|
795
|
+
if (!U) {
|
|
784
796
|
console.warn("Activity notification from user that is not present");
|
|
785
797
|
return;
|
|
786
798
|
}
|
|
787
|
-
const
|
|
788
|
-
(!
|
|
789
|
-
}, w = (
|
|
790
|
-
const
|
|
791
|
-
if (!
|
|
792
|
-
console.warn("Selection change for user that is not present",
|
|
799
|
+
const h = o.get(a);
|
|
800
|
+
(!h || !ye(h, E)) && (o.set(a, E), n.emit("selectionChange", U, E));
|
|
801
|
+
}, w = (a, E) => {
|
|
802
|
+
const U = t.get(a);
|
|
803
|
+
if (!U) {
|
|
804
|
+
console.warn("Selection change for user that is not present", a);
|
|
793
805
|
return;
|
|
794
806
|
}
|
|
795
|
-
E ? o.set(
|
|
807
|
+
E ? o.set(a, E) : o.delete(a), n.emit("selectionChange", U, E);
|
|
796
808
|
}, g = () => [...Array.from(t.values())];
|
|
797
809
|
return {
|
|
798
810
|
getPresentUsers: g,
|
|
799
|
-
notifyActivity:
|
|
800
|
-
on: (
|
|
801
|
-
syncUsers:
|
|
811
|
+
notifyActivity: v,
|
|
812
|
+
on: (a, E) => n.on(a, E),
|
|
813
|
+
syncUsers: m,
|
|
802
814
|
updateSelection: w
|
|
803
815
|
};
|
|
804
816
|
};
|
|
805
817
|
export {
|
|
806
|
-
|
|
818
|
+
re as Ignore,
|
|
807
819
|
T as Origin,
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
820
|
+
Me as PRESENCE_KEY,
|
|
821
|
+
F as UserSelectAction,
|
|
822
|
+
Ve as chainStyles,
|
|
823
|
+
$e as computeStyle,
|
|
824
|
+
_e as createAnonymousGuest,
|
|
811
825
|
ze as createBaseAnnotator,
|
|
812
826
|
De as createBody,
|
|
813
|
-
|
|
827
|
+
Ce as createDefaultAppearanceProvider,
|
|
814
828
|
Ue as createHoverState,
|
|
815
|
-
|
|
816
|
-
|
|
829
|
+
xe as createLifecycleObserver,
|
|
830
|
+
Pe as createPresenceState,
|
|
817
831
|
Te as createSelectionState,
|
|
818
832
|
Re as createStore,
|
|
819
833
|
Ie as createUndoStack,
|
|
820
|
-
|
|
834
|
+
ke as createViewportState,
|
|
821
835
|
we as defaultColorProvider,
|
|
822
|
-
|
|
836
|
+
Q as diffAnnotations,
|
|
823
837
|
Oe as getContributors,
|
|
824
838
|
ce as mergeChanges,
|
|
825
839
|
G as onUserSelect,
|
|
826
840
|
fe as parseAll,
|
|
827
|
-
|
|
841
|
+
Ye as parseW3CBodies,
|
|
828
842
|
ve as parseW3CUser,
|
|
829
843
|
j as reviveDates,
|
|
830
844
|
Ne as serializeAll,
|
|
831
|
-
|
|
832
|
-
|
|
845
|
+
je as serializeW3CBodies,
|
|
846
|
+
ae as shouldNotify,
|
|
833
847
|
Be as toSvelteStore
|
|
834
848
|
};
|
|
835
849
|
//# sourceMappingURL=annotorious-core.es.js.map
|