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