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