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