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