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