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