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