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