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