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