@annotorious/core 3.0.0-rc.28 → 3.0.0-rc.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
var M = Object.prototype.hasOwnProperty;
|
|
2
2
|
function B(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-- && B(e[o], n[o]); )
|
|
14
|
-
;
|
|
10
|
+
for (; o-- && B(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 (M.call(e, t) && ++o && !M.call(n, t) || !(t in n) || !B(e[t], n[t]))
|
|
21
|
-
return !1;
|
|
16
|
+
if (M.call(e, t) && ++o && !M.call(n, t) || !(t in n) || !B(e[t], n[t])) return !1;
|
|
22
17
|
return Object.keys(n).length === o;
|
|
23
18
|
}
|
|
24
19
|
}
|
|
@@ -220,51 +215,51 @@ const ie = (e, n) => {
|
|
|
220
215
|
...(n.updated || []).filter(({ oldValue: s }) => !b.has(s.id))
|
|
221
216
|
];
|
|
222
217
|
return { created: y, deleted: u, updated: U };
|
|
223
|
-
},
|
|
224
|
-
const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (d,
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
}, p = (d,
|
|
218
|
+
}, ae = (e) => e.id !== void 0, Oe = () => {
|
|
219
|
+
const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (d, r = {}) => t.push({ onChange: d, options: r }), i = (d) => {
|
|
220
|
+
const r = t.findIndex((c) => c.onChange == d);
|
|
221
|
+
r > -1 && t.splice(r, 1);
|
|
222
|
+
}, p = (d, r) => {
|
|
228
223
|
const c = {
|
|
229
224
|
origin: d,
|
|
230
225
|
changes: {
|
|
231
|
-
created:
|
|
232
|
-
updated:
|
|
233
|
-
deleted:
|
|
226
|
+
created: r.created || [],
|
|
227
|
+
updated: r.updated || [],
|
|
228
|
+
deleted: r.deleted || []
|
|
234
229
|
},
|
|
235
230
|
state: [...e.values()]
|
|
236
231
|
};
|
|
237
232
|
t.forEach((f) => {
|
|
238
233
|
ie(f, c) && f.onChange(c);
|
|
239
234
|
});
|
|
240
|
-
}, w = (d,
|
|
235
|
+
}, w = (d, r = O.LOCAL) => {
|
|
241
236
|
if (e.get(d.id))
|
|
242
237
|
throw Error(`Cannot add annotation ${d.id} - exists already`);
|
|
243
|
-
e.set(d.id, d), d.bodies.forEach((f) => n.set(f.id, d.id)), p(
|
|
244
|
-
}, b = (d,
|
|
245
|
-
const c = typeof d == "string" ?
|
|
238
|
+
e.set(d.id, d), d.bodies.forEach((f) => n.set(f.id, d.id)), p(r, { created: [d] });
|
|
239
|
+
}, b = (d, r) => {
|
|
240
|
+
const c = typeof d == "string" ? r : d, f = typeof d == "string" ? d : d.id, C = e.get(f);
|
|
246
241
|
if (C) {
|
|
247
242
|
const T = q(C, c);
|
|
248
|
-
return f === c.id ? e.set(f, c) : (e.delete(f), e.set(c.id, c)), C.bodies.forEach((
|
|
243
|
+
return f === c.id ? e.set(f, c) : (e.delete(f), e.set(c.id, c)), C.bodies.forEach((x) => n.delete(x.id)), c.bodies.forEach((x) => n.set(x.id, c.id)), T;
|
|
249
244
|
} else
|
|
250
245
|
console.warn(`Cannot update annotation ${f} - does not exist`);
|
|
251
|
-
}, y = (d,
|
|
252
|
-
const f =
|
|
246
|
+
}, y = (d, r = O.LOCAL, c = O.LOCAL) => {
|
|
247
|
+
const f = ae(r) ? c : r, C = b(d, r);
|
|
253
248
|
C && p(f, { updated: [C] });
|
|
254
|
-
}, u = (d,
|
|
249
|
+
}, u = (d, r = O.LOCAL) => {
|
|
255
250
|
const c = d.reduce((f, C) => {
|
|
256
251
|
const T = b(C);
|
|
257
252
|
return T ? [...f, T] : f;
|
|
258
253
|
}, []);
|
|
259
|
-
c.length > 0 && p(
|
|
260
|
-
}, U = (d,
|
|
254
|
+
c.length > 0 && p(r, { updated: c });
|
|
255
|
+
}, U = (d, r = O.LOCAL) => {
|
|
261
256
|
const c = e.get(d.annotation);
|
|
262
257
|
if (c) {
|
|
263
258
|
const f = {
|
|
264
259
|
...c,
|
|
265
260
|
bodies: [...c.bodies, d]
|
|
266
261
|
};
|
|
267
|
-
e.set(c.id, f), n.set(d.id, f.id), p(
|
|
262
|
+
e.set(c.id, f), n.set(d.id, f.id), p(r, { updated: [{
|
|
268
263
|
oldValue: c,
|
|
269
264
|
newValue: f,
|
|
270
265
|
bodiesCreated: [d]
|
|
@@ -272,18 +267,18 @@ const ie = (e, n) => {
|
|
|
272
267
|
} else
|
|
273
268
|
console.warn(`Attempt to add body to missing annotation: ${d.annotation}`);
|
|
274
269
|
}, s = () => [...e.values()], h = (d = O.LOCAL) => {
|
|
275
|
-
const
|
|
276
|
-
e.clear(), n.clear(), p(d, { deleted:
|
|
277
|
-
}, L = (d,
|
|
278
|
-
if (
|
|
270
|
+
const r = [...e.values()];
|
|
271
|
+
e.clear(), n.clear(), p(d, { deleted: r });
|
|
272
|
+
}, L = (d, r = !0, c = O.LOCAL) => {
|
|
273
|
+
if (r) {
|
|
279
274
|
const f = [...e.values()];
|
|
280
275
|
e.clear(), n.clear(), d.forEach((C) => {
|
|
281
276
|
e.set(C.id, C), C.bodies.forEach((T) => n.set(T.id, C.id));
|
|
282
277
|
}), p(c, { created: d, deleted: f });
|
|
283
278
|
} else {
|
|
284
279
|
const f = d.reduce((C, T) => {
|
|
285
|
-
const
|
|
286
|
-
return
|
|
280
|
+
const x = e.get(T.id);
|
|
281
|
+
return x ? [...C, x] : C;
|
|
287
282
|
}, []);
|
|
288
283
|
if (f.length > 0)
|
|
289
284
|
throw Error(`Bulk insert would overwrite the following annotations: ${f.map((C) => C.id).join(", ")}`);
|
|
@@ -292,31 +287,31 @@ const ie = (e, n) => {
|
|
|
292
287
|
}), p(c, { created: d });
|
|
293
288
|
}
|
|
294
289
|
}, v = (d) => {
|
|
295
|
-
const
|
|
290
|
+
const r = typeof d == "string" ? d : d.id, c = e.get(r);
|
|
296
291
|
if (c)
|
|
297
|
-
return e.delete(
|
|
298
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
299
|
-
}, S = (d,
|
|
292
|
+
return e.delete(r), c.bodies.forEach((f) => n.delete(f.id)), c;
|
|
293
|
+
console.warn(`Attempt to delete missing annotation: ${r}`);
|
|
294
|
+
}, S = (d, r = O.LOCAL) => {
|
|
300
295
|
const c = v(d);
|
|
301
|
-
c && p(
|
|
302
|
-
}, E = (d,
|
|
296
|
+
c && p(r, { deleted: [c] });
|
|
297
|
+
}, E = (d, r = O.LOCAL) => {
|
|
303
298
|
const c = d.reduce((f, C) => {
|
|
304
299
|
const T = v(C);
|
|
305
300
|
return T ? [...f, T] : f;
|
|
306
301
|
}, []);
|
|
307
|
-
c.length > 0 && p(
|
|
302
|
+
c.length > 0 && p(r, { deleted: c });
|
|
308
303
|
}, l = (d) => {
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
311
|
-
const c =
|
|
304
|
+
const r = e.get(d.annotation);
|
|
305
|
+
if (r) {
|
|
306
|
+
const c = r.bodies.find((f) => f.id === d.id);
|
|
312
307
|
if (c) {
|
|
313
308
|
n.delete(c.id);
|
|
314
309
|
const f = {
|
|
315
|
-
...
|
|
316
|
-
bodies:
|
|
310
|
+
...r,
|
|
311
|
+
bodies: r.bodies.filter((T) => T.id !== d.id)
|
|
317
312
|
};
|
|
318
|
-
return e.set(
|
|
319
|
-
oldValue:
|
|
313
|
+
return e.set(r.id, f), {
|
|
314
|
+
oldValue: r,
|
|
320
315
|
newValue: f,
|
|
321
316
|
bodiesDeleted: [c]
|
|
322
317
|
};
|
|
@@ -324,61 +319,61 @@ const ie = (e, n) => {
|
|
|
324
319
|
console.warn(`Attempt to delete missing body ${d.id} from annotation ${d.annotation}`);
|
|
325
320
|
} else
|
|
326
321
|
console.warn(`Attempt to delete body from missing annotation ${d.annotation}`);
|
|
327
|
-
}, g = (d,
|
|
322
|
+
}, g = (d, r = O.LOCAL) => {
|
|
328
323
|
const c = l(d);
|
|
329
|
-
c && p(
|
|
330
|
-
},
|
|
324
|
+
c && p(r, { updated: [c] });
|
|
325
|
+
}, a = (d, r = O.LOCAL) => {
|
|
331
326
|
const c = d.map((f) => l(f)).filter(Boolean);
|
|
332
|
-
c.length > 0 && p(
|
|
333
|
-
}, A = (d) => {
|
|
334
|
-
const a = e.get(d);
|
|
335
|
-
return a ? { ...a } : void 0;
|
|
327
|
+
c.length > 0 && p(r, { updated: c });
|
|
336
328
|
}, m = (d) => {
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
329
|
+
const r = e.get(d);
|
|
330
|
+
return r ? { ...r } : void 0;
|
|
331
|
+
}, A = (d) => {
|
|
332
|
+
const r = n.get(d);
|
|
333
|
+
if (r) {
|
|
334
|
+
const f = m(r).bodies.find((C) => C.id === d);
|
|
340
335
|
if (f)
|
|
341
336
|
return f;
|
|
342
337
|
console.error(`Store integrity error: body ${d} in index, but not in annotation`);
|
|
343
338
|
} else
|
|
344
339
|
console.warn(`Attempt to retrieve missing body: ${d}`);
|
|
345
|
-
}, R = (d,
|
|
346
|
-
if (d.annotation !==
|
|
340
|
+
}, R = (d, r) => {
|
|
341
|
+
if (d.annotation !== r.annotation)
|
|
347
342
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
348
343
|
const c = e.get(d.annotation);
|
|
349
344
|
if (c) {
|
|
350
345
|
const f = c.bodies.find((T) => T.id === d.id), C = {
|
|
351
346
|
...c,
|
|
352
|
-
bodies: c.bodies.map((T) => T.id === f.id ?
|
|
347
|
+
bodies: c.bodies.map((T) => T.id === f.id ? r : T)
|
|
353
348
|
};
|
|
354
|
-
return e.set(c.id, C), f.id !==
|
|
349
|
+
return e.set(c.id, C), f.id !== r.id && (n.delete(f.id), n.set(r.id, C.id)), {
|
|
355
350
|
oldValue: c,
|
|
356
351
|
newValue: C,
|
|
357
|
-
bodiesUpdated: [{ oldBody: f, newBody:
|
|
352
|
+
bodiesUpdated: [{ oldBody: f, newBody: r }]
|
|
358
353
|
};
|
|
359
354
|
} else
|
|
360
355
|
console.warn(`Attempt to add body to missing annotation ${d.annotation}`);
|
|
361
|
-
}, N = (d,
|
|
362
|
-
const f = R(d,
|
|
356
|
+
}, N = (d, r, c = O.LOCAL) => {
|
|
357
|
+
const f = R(d, r);
|
|
363
358
|
f && p(c, { updated: [f] });
|
|
364
|
-
},
|
|
359
|
+
}, I = (d, r = O.LOCAL) => {
|
|
365
360
|
const c = d.map((f) => R({ id: f.id, annotation: f.annotation }, f)).filter(Boolean);
|
|
366
|
-
p(
|
|
361
|
+
p(r, { updated: c });
|
|
367
362
|
}, j = (d) => {
|
|
368
|
-
const
|
|
369
|
-
if (
|
|
363
|
+
const r = e.get(d.annotation);
|
|
364
|
+
if (r) {
|
|
370
365
|
const c = {
|
|
371
|
-
...
|
|
366
|
+
...r,
|
|
372
367
|
target: {
|
|
373
|
-
...
|
|
368
|
+
...r.target,
|
|
374
369
|
...d
|
|
375
370
|
}
|
|
376
371
|
};
|
|
377
|
-
return e.set(
|
|
378
|
-
oldValue:
|
|
372
|
+
return e.set(r.id, c), {
|
|
373
|
+
oldValue: r,
|
|
379
374
|
newValue: c,
|
|
380
375
|
targetUpdated: {
|
|
381
|
-
oldTarget:
|
|
376
|
+
oldTarget: r.target,
|
|
382
377
|
newTarget: d
|
|
383
378
|
}
|
|
384
379
|
};
|
|
@@ -391,25 +386,25 @@ const ie = (e, n) => {
|
|
|
391
386
|
all: s,
|
|
392
387
|
bulkAddAnnotation: L,
|
|
393
388
|
bulkDeleteAnnotation: E,
|
|
394
|
-
bulkDeleteBodies:
|
|
389
|
+
bulkDeleteBodies: a,
|
|
395
390
|
bulkUpdateAnnotation: u,
|
|
396
|
-
bulkUpdateBodies:
|
|
397
|
-
bulkUpdateTargets: (d,
|
|
391
|
+
bulkUpdateBodies: I,
|
|
392
|
+
bulkUpdateTargets: (d, r = O.LOCAL) => {
|
|
398
393
|
const c = d.map((f) => j(f)).filter(Boolean);
|
|
399
|
-
c.length > 0 && p(
|
|
394
|
+
c.length > 0 && p(r, { updated: c });
|
|
400
395
|
},
|
|
401
396
|
clear: h,
|
|
402
397
|
deleteAnnotation: S,
|
|
403
398
|
deleteBody: g,
|
|
404
|
-
getAnnotation:
|
|
405
|
-
getBody:
|
|
399
|
+
getAnnotation: m,
|
|
400
|
+
getBody: A,
|
|
406
401
|
observe: o,
|
|
407
402
|
unobserve: i,
|
|
408
403
|
updateAnnotation: y,
|
|
409
404
|
updateBody: N,
|
|
410
|
-
updateTarget: (d,
|
|
405
|
+
updateTarget: (d, r = O.LOCAL) => {
|
|
411
406
|
const c = j(d);
|
|
412
|
-
c && p(
|
|
407
|
+
c && p(r, { updated: [c] });
|
|
413
408
|
}
|
|
414
409
|
};
|
|
415
410
|
}, Te = (e) => ({
|
|
@@ -433,41 +428,41 @@ let G = () => ({
|
|
|
433
428
|
};
|
|
434
429
|
}
|
|
435
430
|
});
|
|
436
|
-
const
|
|
431
|
+
const re = 250, De = (e) => {
|
|
437
432
|
const n = G(), t = [];
|
|
438
433
|
let o = -1, i = !1, p = 0;
|
|
439
|
-
const w = (
|
|
434
|
+
const w = (a) => {
|
|
440
435
|
if (!i) {
|
|
441
|
-
const { changes:
|
|
442
|
-
if (
|
|
443
|
-
t.splice(o + 1), t.push(
|
|
436
|
+
const { changes: m } = a, A = performance.now();
|
|
437
|
+
if (A - p > re)
|
|
438
|
+
t.splice(o + 1), t.push(m), o = t.length - 1;
|
|
444
439
|
else {
|
|
445
440
|
const R = t.length - 1;
|
|
446
|
-
t[R] = de(t[R],
|
|
441
|
+
t[R] = de(t[R], m);
|
|
447
442
|
}
|
|
448
|
-
p =
|
|
443
|
+
p = A;
|
|
449
444
|
}
|
|
450
445
|
i = !1;
|
|
451
446
|
};
|
|
452
447
|
e.observe(w, { origin: O.LOCAL });
|
|
453
|
-
const b = (
|
|
448
|
+
const b = (a) => a && a.length > 0 && e.bulkDeleteAnnotation(a), y = (a) => a && a.length > 0 && e.bulkAddAnnotation(a, !1), u = (a) => a && a.length > 0 && e.bulkUpdateAnnotation(a.map(({ oldValue: m }) => m)), U = (a) => a && a.length > 0 && e.bulkUpdateAnnotation(a.map(({ newValue: m }) => m)), s = (a) => a && a.length > 0 && e.bulkAddAnnotation(a, !1), h = (a) => a && a.length > 0 && e.bulkDeleteAnnotation(a);
|
|
454
449
|
return {
|
|
455
450
|
canRedo: () => t.length - 1 > o,
|
|
456
451
|
canUndo: () => o > -1,
|
|
457
452
|
destroy: () => e.unobserve(w),
|
|
458
|
-
on: (
|
|
453
|
+
on: (a, m) => n.on(a, m),
|
|
459
454
|
redo: () => {
|
|
460
455
|
if (t.length - 1 > o) {
|
|
461
456
|
i = !0;
|
|
462
|
-
const { created:
|
|
463
|
-
y(
|
|
457
|
+
const { created: a, updated: m, deleted: A } = t[o + 1];
|
|
458
|
+
y(a), U(m), h(A), n.emit("redo", t[o + 1]), o += 1;
|
|
464
459
|
}
|
|
465
460
|
},
|
|
466
461
|
undo: () => {
|
|
467
462
|
if (o > -1) {
|
|
468
463
|
i = !0;
|
|
469
|
-
const { created:
|
|
470
|
-
b(
|
|
464
|
+
const { created: a, updated: m, deleted: A } = t[o];
|
|
465
|
+
b(a), u(m), s(A), n.emit("undo", t[o]), o -= 1;
|
|
471
466
|
}
|
|
472
467
|
}
|
|
473
468
|
};
|
|
@@ -483,26 +478,29 @@ const ae = 250, De = (e) => {
|
|
|
483
478
|
const h = (l, g) => {
|
|
484
479
|
y.has(l) ? y.get(l).push(g) : y.set(l, [g]);
|
|
485
480
|
}, L = (l, g) => {
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
481
|
+
const a = y.get(l);
|
|
482
|
+
if (a) {
|
|
483
|
+
const m = a.indexOf(g);
|
|
484
|
+
m !== -1 && a.splice(m, 1);
|
|
485
|
+
}
|
|
486
|
+
}, v = (l, g, a) => {
|
|
489
487
|
y.has(l) && setTimeout(() => {
|
|
490
|
-
y.get(l).forEach((
|
|
488
|
+
y.get(l).forEach((m) => {
|
|
491
489
|
if (t) {
|
|
492
|
-
const
|
|
493
|
-
A
|
|
490
|
+
const A = Array.isArray(g) ? g.map((N) => t.serialize(N)) : t.serialize(g), R = a ? a instanceof PointerEvent ? a : t.serialize(a) : void 0;
|
|
491
|
+
m(A, R);
|
|
494
492
|
} else
|
|
495
|
-
|
|
493
|
+
m(g, a);
|
|
496
494
|
});
|
|
497
495
|
}, 1);
|
|
498
496
|
}, S = () => {
|
|
499
|
-
const { selected: l } = p, g = (l || []).map(({ id:
|
|
500
|
-
g.forEach((
|
|
501
|
-
const
|
|
502
|
-
(!
|
|
503
|
-
}), u = u.map((
|
|
504
|
-
const
|
|
505
|
-
return
|
|
497
|
+
const { selected: l } = p, g = (l || []).map(({ id: a }) => i.getAnnotation(a));
|
|
498
|
+
g.forEach((a) => {
|
|
499
|
+
const m = u.find((A) => A.id === a.id);
|
|
500
|
+
(!m || !B(m, a)) && v("updateAnnotation", a, m);
|
|
501
|
+
}), u = u.map((a) => {
|
|
502
|
+
const m = g.find(({ id: A }) => A === a.id);
|
|
503
|
+
return m || a;
|
|
506
504
|
});
|
|
507
505
|
};
|
|
508
506
|
p.subscribe(({ selected: l }) => {
|
|
@@ -511,19 +509,19 @@ const ae = 250, De = (e) => {
|
|
|
511
509
|
u = l.map(({ id: g }) => i.getAnnotation(g));
|
|
512
510
|
else if (u.length > 0 && l.length === 0)
|
|
513
511
|
u.forEach((g) => {
|
|
514
|
-
const
|
|
515
|
-
|
|
512
|
+
const a = i.getAnnotation(g.id);
|
|
513
|
+
a && !B(a, g) && v("updateAnnotation", a, g);
|
|
516
514
|
}), u = [];
|
|
517
515
|
else {
|
|
518
|
-
const g = new Set(u.map((
|
|
519
|
-
u.filter((
|
|
520
|
-
const R = i.getAnnotation(
|
|
521
|
-
R && !B(R,
|
|
516
|
+
const g = new Set(u.map((A) => A.id)), a = new Set(l.map(({ id: A }) => A));
|
|
517
|
+
u.filter((A) => !a.has(A.id)).forEach((A) => {
|
|
518
|
+
const R = i.getAnnotation(A.id);
|
|
519
|
+
R && !B(R, A) && v("updateAnnotation", R, A);
|
|
522
520
|
}), u = [
|
|
523
521
|
// Remove annotations that were deselected
|
|
524
|
-
...u.filter((
|
|
522
|
+
...u.filter((A) => a.has(A.id)),
|
|
525
523
|
// Add editable annotations that were selected
|
|
526
|
-
...l.filter(({ id:
|
|
524
|
+
...l.filter(({ id: A }) => !g.has(A)).map(({ id: A }) => i.getAnnotation(A))
|
|
527
525
|
];
|
|
528
526
|
}
|
|
529
527
|
v("selectionChanged", u);
|
|
@@ -532,30 +530,30 @@ const ae = 250, De = (e) => {
|
|
|
532
530
|
!U && l ? v("mouseEnterAnnotation", i.getAnnotation(l)) : U && !l ? v("mouseLeaveAnnotation", i.getAnnotation(U)) : U && l && (v("mouseLeaveAnnotation", i.getAnnotation(U)), v("mouseEnterAnnotation", i.getAnnotation(l))), U = l;
|
|
533
531
|
}), b == null || b.subscribe((l) => v("viewportIntersect", l.map((g) => i.getAnnotation(g)))), i.observe((l) => {
|
|
534
532
|
o && (s && clearTimeout(s), s = setTimeout(S, 1e3));
|
|
535
|
-
const { created: g, deleted:
|
|
536
|
-
(g || []).forEach((
|
|
537
|
-
...
|
|
538
|
-
...
|
|
539
|
-
...
|
|
540
|
-
].length > 0).forEach(({ oldValue:
|
|
541
|
-
const N = u.find((
|
|
542
|
-
u = u.map((
|
|
533
|
+
const { created: g, deleted: a } = l.changes;
|
|
534
|
+
(g || []).forEach((A) => v("createAnnotation", A)), (a || []).forEach((A) => v("deleteAnnotation", A)), (l.changes.updated || []).filter((A) => [
|
|
535
|
+
...A.bodiesCreated || [],
|
|
536
|
+
...A.bodiesDeleted || [],
|
|
537
|
+
...A.bodiesUpdated || []
|
|
538
|
+
].length > 0).forEach(({ oldValue: A, newValue: R }) => {
|
|
539
|
+
const N = u.find((I) => I.id === A.id) || A;
|
|
540
|
+
u = u.map((I) => I.id === A.id ? R : I), v("updateAnnotation", R, N);
|
|
543
541
|
});
|
|
544
542
|
}, { origin: O.LOCAL }), i.observe((l) => {
|
|
545
543
|
if (u) {
|
|
546
|
-
const g = new Set(u.map((
|
|
547
|
-
|
|
548
|
-
const
|
|
549
|
-
return
|
|
544
|
+
const g = new Set(u.map((m) => m.id)), a = (l.changes.updated || []).filter(({ newValue: m }) => g.has(m.id)).map(({ newValue: m }) => m);
|
|
545
|
+
a.length > 0 && (u = u.map((m) => {
|
|
546
|
+
const A = a.find((R) => R.id === m.id);
|
|
547
|
+
return A || m;
|
|
550
548
|
}));
|
|
551
549
|
}
|
|
552
550
|
}, { origin: O.REMOTE });
|
|
553
551
|
const E = (l) => (g) => {
|
|
554
|
-
const { updated:
|
|
555
|
-
l ? (
|
|
552
|
+
const { updated: a } = g;
|
|
553
|
+
l ? (a || []).forEach((m) => v("updateAnnotation", m.oldValue, m.newValue)) : (a || []).forEach((m) => v("updateAnnotation", m.newValue, m.oldValue));
|
|
556
554
|
};
|
|
557
555
|
return n.on("undo", E(!0)), n.on("redo", E(!1)), { on: h, off: L, emit: v };
|
|
558
|
-
},
|
|
556
|
+
}, Ie = (e) => (n) => n.map((t) => e.serialize(t)), ce = (e) => (n) => n.reduce((t, o) => {
|
|
559
557
|
const { parsed: i, error: p } = e.parse(o);
|
|
560
558
|
return p ? {
|
|
561
559
|
parsed: t.parsed,
|
|
@@ -566,7 +564,7 @@ const ae = 250, De = (e) => {
|
|
|
566
564
|
} : {
|
|
567
565
|
...t
|
|
568
566
|
};
|
|
569
|
-
}, { parsed: [], failed: [] }),
|
|
567
|
+
}, { parsed: [], failed: [] }), xe = (e, n, t) => {
|
|
570
568
|
const { store: o, selection: i } = e, p = (E) => {
|
|
571
569
|
if (t) {
|
|
572
570
|
const { parsed: l, error: g } = t.parse(E);
|
|
@@ -578,7 +576,7 @@ const ae = 250, De = (e) => {
|
|
|
578
576
|
return t && l ? t.serialize(l) : l;
|
|
579
577
|
}, u = () => t ? o.all().map(t.serialize) : o.all(), U = () => {
|
|
580
578
|
var g;
|
|
581
|
-
const l = (((g = i.selected) == null ? void 0 : g.map((
|
|
579
|
+
const l = (((g = i.selected) == null ? void 0 : g.map((a) => a.id)) || []).map((a) => o.getAnnotation(a)).filter(Boolean);
|
|
582
580
|
return t ? l.map(t.serialize) : l;
|
|
583
581
|
}, s = (E, l = !0) => fetch(E).then((g) => g.json()).then((g) => (L(g, l), g)), h = (E) => {
|
|
584
582
|
if (typeof E == "string") {
|
|
@@ -592,8 +590,8 @@ const ae = 250, De = (e) => {
|
|
|
592
590
|
}
|
|
593
591
|
}, L = (E, l = !0) => {
|
|
594
592
|
if (t) {
|
|
595
|
-
const { parsed: g, failed:
|
|
596
|
-
|
|
593
|
+
const { parsed: g, failed: a } = ce(t)(E);
|
|
594
|
+
a.length > 0 && console.warn(`Discarded ${a.length} invalid annotations`, a), o.bulkAddAnnotation(g, l, O.REMOTE);
|
|
597
595
|
} else
|
|
598
596
|
o.bulkAddAnnotation(E, l, O.REMOTE);
|
|
599
597
|
}, v = (E, l) => {
|
|
@@ -632,8 +630,7 @@ let ue = (e) => crypto.getRandomValues(new Uint8Array(e)), fe = (e, n, t) => {
|
|
|
632
630
|
for (; ; ) {
|
|
633
631
|
let b = t(i), y = i;
|
|
634
632
|
for (; y--; )
|
|
635
|
-
if (w += e[b[y] & o] || "", w.length === p)
|
|
636
|
-
return w;
|
|
633
|
+
if (w += e[b[y] & o] || "", w.length === p) return w;
|
|
637
634
|
}
|
|
638
635
|
};
|
|
639
636
|
}, pe = (e, n = 21) => fe(e, n, ue), he = (e = 21) => {
|
|
@@ -761,11 +758,11 @@ export {
|
|
|
761
758
|
ze as PRESENCE_KEY,
|
|
762
759
|
F as PointerSelectAction,
|
|
763
760
|
ke as createAnonymousGuest,
|
|
764
|
-
|
|
761
|
+
xe as createBaseAnnotator,
|
|
765
762
|
Se as createBody,
|
|
766
763
|
ve as createDefaultAppearenceProvider,
|
|
767
764
|
Ce as createHoverState,
|
|
768
|
-
Be as
|
|
765
|
+
Be as createLifecycleObserver,
|
|
769
766
|
Ve as createPresenceState,
|
|
770
767
|
Le as createSelectionState,
|
|
771
768
|
Oe as createStore,
|
|
@@ -779,7 +776,7 @@ export {
|
|
|
779
776
|
ce as parseAll,
|
|
780
777
|
Ne as parseW3CBodies,
|
|
781
778
|
me as parseW3CUser,
|
|
782
|
-
|
|
779
|
+
Ie as serializeAll,
|
|
783
780
|
$e as serializeW3CBodies,
|
|
784
781
|
ie as shouldNotify,
|
|
785
782
|
Te as toSvelteStore
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotorious-core.es.js","sources":["../../../node_modules/dequal/lite/index.mjs","../../../node_modules/svelte/src/runtime/internal/utils.js","../../../node_modules/svelte/src/runtime/store/index.js","../src/state/Hover.ts","../src/state/Selection.ts","../../../node_modules/uuid/dist/esm-browser/stringify.js","../../../node_modules/uuid/dist/esm-browser/rng.js","../../../node_modules/uuid/dist/esm-browser/native.js","../../../node_modules/uuid/dist/esm-browser/v4.js","../src/utils/annotationUtils.ts","../src/utils/diffAnnotations.ts","../src/state/StoreObserver.ts","../src/state/Store.ts","../src/state/SvelteStore.ts","../../../node_modules/nanoevents/index.js","../src/state/UndoStack.ts","../src/state/Viewport.ts","../src/lifecycle/Lifecycle.ts","../src/model/FormatAdapter.ts","../src/model/Annotator.ts","../../../node_modules/nanoid/url-alphabet/index.js","../../../node_modules/nanoid/index.browser.js","../src/model/User.ts","../src/model/W3CAnnotation.ts","../src/presence/ColorPalette.ts","../src/presence/AppearanceProvider.ts","../src/presence/PresenceState.ts"],"sourcesContent":["var has = Object.prototype.hasOwnProperty;\n\nexport function dequal(foo, bar) {\n\tvar ctor, len;\n\tif (foo === bar) return true;\n\n\tif (foo && bar && (ctor=foo.constructor) === bar.constructor) {\n\t\tif (ctor === Date) return foo.getTime() === bar.getTime();\n\t\tif (ctor === RegExp) return foo.toString() === bar.toString();\n\n\t\tif (ctor === Array) {\n\t\t\tif ((len=foo.length) === bar.length) {\n\t\t\t\twhile (len-- && dequal(foo[len], bar[len]));\n\t\t\t}\n\t\t\treturn len === -1;\n\t\t}\n\n\t\tif (!ctor || typeof foo === 'object') {\n\t\t\tlen = 0;\n\t\t\tfor (ctor in foo) {\n\t\t\t\tif (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;\n\t\t\t\tif (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;\n\t\t\t}\n\t\t\treturn Object.keys(bar).length === len;\n\t\t}\n\t}\n\n\treturn foo !== foo && bar !== bar;\n}\n","/** @returns {void} */\nexport function noop() {}\n\nexport const identity = (x) => x;\n\n/**\n * @template T\n * @template S\n * @param {T} tar\n * @param {S} src\n * @returns {T & S}\n */\nexport function assign(tar, src) {\n\t// @ts-ignore\n\tfor (const k in src) tar[k] = src[k];\n\treturn /** @type {T & S} */ (tar);\n}\n\n// Adapted from https://github.com/then/is-promise/blob/master/index.js\n// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE\n/**\n * @param {any} value\n * @returns {value is PromiseLike<any>}\n */\nexport function is_promise(value) {\n\treturn (\n\t\t!!value &&\n\t\t(typeof value === 'object' || typeof value === 'function') &&\n\t\ttypeof (/** @type {any} */ (value).then) === 'function'\n\t);\n}\n\n/** @returns {void} */\nexport function add_location(element, file, line, column, char) {\n\telement.__svelte_meta = {\n\t\tloc: { file, line, column, char }\n\t};\n}\n\nexport function run(fn) {\n\treturn fn();\n}\n\nexport function blank_object() {\n\treturn Object.create(null);\n}\n\n/**\n * @param {Function[]} fns\n * @returns {void}\n */\nexport function run_all(fns) {\n\tfns.forEach(run);\n}\n\n/**\n * @param {any} thing\n * @returns {thing is Function}\n */\nexport function is_function(thing) {\n\treturn typeof thing === 'function';\n}\n\n/** @returns {boolean} */\nexport function safe_not_equal(a, b) {\n\treturn a != a ? b == b : a !== b || (a && typeof a === 'object') || typeof a === 'function';\n}\n\nlet src_url_equal_anchor;\n\n/**\n * @param {string} element_src\n * @param {string} url\n * @returns {boolean}\n */\nexport function src_url_equal(element_src, url) {\n\tif (element_src === url) return true;\n\tif (!src_url_equal_anchor) {\n\t\tsrc_url_equal_anchor = document.createElement('a');\n\t}\n\t// This is actually faster than doing URL(..).href\n\tsrc_url_equal_anchor.href = url;\n\treturn element_src === src_url_equal_anchor.href;\n}\n\n/** @param {string} srcset */\nfunction split_srcset(srcset) {\n\treturn srcset.split(',').map((src) => src.trim().split(' ').filter(Boolean));\n}\n\n/**\n * @param {HTMLSourceElement | HTMLImageElement} element_srcset\n * @param {string | undefined | null} srcset\n * @returns {boolean}\n */\nexport function srcset_url_equal(element_srcset, srcset) {\n\tconst element_urls = split_srcset(element_srcset.srcset);\n\tconst urls = split_srcset(srcset || '');\n\n\treturn (\n\t\turls.length === element_urls.length &&\n\t\turls.every(\n\t\t\t([url, width], i) =>\n\t\t\t\twidth === element_urls[i][1] &&\n\t\t\t\t// We need to test both ways because Vite will create an a full URL with\n\t\t\t\t// `new URL(asset, import.meta.url).href` for the client when `base: './'`, and the\n\t\t\t\t// relative URLs inside srcset are not automatically resolved to absolute URLs by\n\t\t\t\t// browsers (in contrast to img.src). This means both SSR and DOM code could\n\t\t\t\t// contain relative or absolute URLs.\n\t\t\t\t(src_url_equal(element_urls[i][0], url) || src_url_equal(url, element_urls[i][0]))\n\t\t)\n\t);\n}\n\n/** @returns {boolean} */\nexport function not_equal(a, b) {\n\treturn a != a ? b == b : a !== b;\n}\n\n/** @returns {boolean} */\nexport function is_empty(obj) {\n\treturn Object.keys(obj).length === 0;\n}\n\n/** @returns {void} */\nexport function validate_store(store, name) {\n\tif (store != null && typeof store.subscribe !== 'function') {\n\t\tthrow new Error(`'${name}' is not a store with a 'subscribe' method`);\n\t}\n}\n\nexport function subscribe(store, ...callbacks) {\n\tif (store == null) {\n\t\tfor (const callback of callbacks) {\n\t\t\tcallback(undefined);\n\t\t}\n\t\treturn noop;\n\t}\n\tconst unsub = store.subscribe(...callbacks);\n\treturn unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;\n}\n\n/**\n * Get the current value from a store by subscribing and immediately unsubscribing.\n *\n * https://svelte.dev/docs/svelte-store#get\n * @template T\n * @param {import('../store/public.js').Readable<T>} store\n * @returns {T}\n */\nexport function get_store_value(store) {\n\tlet value;\n\tsubscribe(store, (_) => (value = _))();\n\treturn value;\n}\n\n/** @returns {void} */\nexport function component_subscribe(component, store, callback) {\n\tcomponent.$$.on_destroy.push(subscribe(store, callback));\n}\n\nexport function create_slot(definition, ctx, $$scope, fn) {\n\tif (definition) {\n\t\tconst slot_ctx = get_slot_context(definition, ctx, $$scope, fn);\n\t\treturn definition[0](slot_ctx);\n\t}\n}\n\nfunction get_slot_context(definition, ctx, $$scope, fn) {\n\treturn definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx;\n}\n\nexport function get_slot_changes(definition, $$scope, dirty, fn) {\n\tif (definition[2] && fn) {\n\t\tconst lets = definition[2](fn(dirty));\n\t\tif ($$scope.dirty === undefined) {\n\t\t\treturn lets;\n\t\t}\n\t\tif (typeof lets === 'object') {\n\t\t\tconst merged = [];\n\t\t\tconst len = Math.max($$scope.dirty.length, lets.length);\n\t\t\tfor (let i = 0; i < len; i += 1) {\n\t\t\t\tmerged[i] = $$scope.dirty[i] | lets[i];\n\t\t\t}\n\t\t\treturn merged;\n\t\t}\n\t\treturn $$scope.dirty | lets;\n\t}\n\treturn $$scope.dirty;\n}\n\n/** @returns {void} */\nexport function update_slot_base(\n\tslot,\n\tslot_definition,\n\tctx,\n\t$$scope,\n\tslot_changes,\n\tget_slot_context_fn\n) {\n\tif (slot_changes) {\n\t\tconst slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);\n\t\tslot.p(slot_context, slot_changes);\n\t}\n}\n\n/** @returns {void} */\nexport function update_slot(\n\tslot,\n\tslot_definition,\n\tctx,\n\t$$scope,\n\tdirty,\n\tget_slot_changes_fn,\n\tget_slot_context_fn\n) {\n\tconst slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn);\n\tupdate_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn);\n}\n\n/** @returns {any[] | -1} */\nexport function get_all_dirty_from_scope($$scope) {\n\tif ($$scope.ctx.length > 32) {\n\t\tconst dirty = [];\n\t\tconst length = $$scope.ctx.length / 32;\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tdirty[i] = -1;\n\t\t}\n\t\treturn dirty;\n\t}\n\treturn -1;\n}\n\n/** @returns {{}} */\nexport function exclude_internal_props(props) {\n\tconst result = {};\n\tfor (const k in props) if (k[0] !== '$') result[k] = props[k];\n\treturn result;\n}\n\n/** @returns {{}} */\nexport function compute_rest_props(props, keys) {\n\tconst rest = {};\n\tkeys = new Set(keys);\n\tfor (const k in props) if (!keys.has(k) && k[0] !== '$') rest[k] = props[k];\n\treturn rest;\n}\n\n/** @returns {{}} */\nexport function compute_slots(slots) {\n\tconst result = {};\n\tfor (const key in slots) {\n\t\tresult[key] = true;\n\t}\n\treturn result;\n}\n\n/** @returns {(this: any, ...args: any[]) => void} */\nexport function once(fn) {\n\tlet ran = false;\n\treturn function (...args) {\n\t\tif (ran) return;\n\t\tran = true;\n\t\tfn.call(this, ...args);\n\t};\n}\n\nexport function null_to_empty(value) {\n\treturn value == null ? '' : value;\n}\n\nexport function set_store_value(store, ret, value) {\n\tstore.set(value);\n\treturn ret;\n}\n\nexport const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);\n\nexport function action_destroyer(action_result) {\n\treturn action_result && is_function(action_result.destroy) ? action_result.destroy : noop;\n}\n\n/** @param {number | string} value\n * @returns {[number, string]}\n */\nexport function split_css_unit(value) {\n\tconst split = typeof value === 'string' && value.match(/^\\s*(-?[\\d.]+)([^\\s]*)\\s*$/);\n\treturn split ? [parseFloat(split[1]), split[2] || 'px'] : [/** @type {number} */ (value), 'px'];\n}\n\nexport const contenteditable_truthy_values = ['', true, 1, 'true', 'contenteditable'];\n","import {\n\trun_all,\n\tsubscribe,\n\tnoop,\n\tsafe_not_equal,\n\tis_function,\n\tget_store_value\n} from '../internal/index.js';\n\nconst subscriber_queue = [];\n\n/**\n * Creates a `Readable` store that allows reading by subscription.\n *\n * https://svelte.dev/docs/svelte-store#readable\n * @template T\n * @param {T} [value] initial value\n * @param {import('./public.js').StartStopNotifier<T>} [start]\n * @returns {import('./public.js').Readable<T>}\n */\nexport function readable(value, start) {\n\treturn {\n\t\tsubscribe: writable(value, start).subscribe\n\t};\n}\n\n/**\n * Create a `Writable` store that allows both updating and reading by subscription.\n *\n * https://svelte.dev/docs/svelte-store#writable\n * @template T\n * @param {T} [value] initial value\n * @param {import('./public.js').StartStopNotifier<T>} [start]\n * @returns {import('./public.js').Writable<T>}\n */\nexport function writable(value, start = noop) {\n\t/** @type {import('./public.js').Unsubscriber} */\n\tlet stop;\n\t/** @type {Set<import('./private.js').SubscribeInvalidateTuple<T>>} */\n\tconst subscribers = new Set();\n\t/** @param {T} new_value\n\t * @returns {void}\n\t */\n\tfunction set(new_value) {\n\t\tif (safe_not_equal(value, new_value)) {\n\t\t\tvalue = new_value;\n\t\t\tif (stop) {\n\t\t\t\t// store is ready\n\t\t\t\tconst run_queue = !subscriber_queue.length;\n\t\t\t\tfor (const subscriber of subscribers) {\n\t\t\t\t\tsubscriber[1]();\n\t\t\t\t\tsubscriber_queue.push(subscriber, value);\n\t\t\t\t}\n\t\t\t\tif (run_queue) {\n\t\t\t\t\tfor (let i = 0; i < subscriber_queue.length; i += 2) {\n\t\t\t\t\t\tsubscriber_queue[i][0](subscriber_queue[i + 1]);\n\t\t\t\t\t}\n\t\t\t\t\tsubscriber_queue.length = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @param {import('./public.js').Updater<T>} fn\n\t * @returns {void}\n\t */\n\tfunction update(fn) {\n\t\tset(fn(value));\n\t}\n\n\t/**\n\t * @param {import('./public.js').Subscriber<T>} run\n\t * @param {import('./private.js').Invalidator<T>} [invalidate]\n\t * @returns {import('./public.js').Unsubscriber}\n\t */\n\tfunction subscribe(run, invalidate = noop) {\n\t\t/** @type {import('./private.js').SubscribeInvalidateTuple<T>} */\n\t\tconst subscriber = [run, invalidate];\n\t\tsubscribers.add(subscriber);\n\t\tif (subscribers.size === 1) {\n\t\t\tstop = start(set, update) || noop;\n\t\t}\n\t\trun(value);\n\t\treturn () => {\n\t\t\tsubscribers.delete(subscriber);\n\t\t\tif (subscribers.size === 0 && stop) {\n\t\t\t\tstop();\n\t\t\t\tstop = null;\n\t\t\t}\n\t\t};\n\t}\n\treturn { set, update, subscribe };\n}\n\n/**\n * Derived value store by synchronizing one or more readable stores and\n * applying an aggregation function over its input values.\n *\n * https://svelte.dev/docs/svelte-store#derived\n * @template {import('./private.js').Stores} S\n * @template T\n * @overload\n * @param {S} stores - input stores\n * @param {(values: import('./private.js').StoresValues<S>, set: (value: T) => void, update: (fn: import('./public.js').Updater<T>) => void) => import('./public.js').Unsubscriber | void} fn - function callback that aggregates the values\n * @param {T} [initial_value] - initial value\n * @returns {import('./public.js').Readable<T>}\n */\n\n/**\n * Derived value store by synchronizing one or more readable stores and\n * applying an aggregation function over its input values.\n *\n * https://svelte.dev/docs/svelte-store#derived\n * @template {import('./private.js').Stores} S\n * @template T\n * @overload\n * @param {S} stores - input stores\n * @param {(values: import('./private.js').StoresValues<S>) => T} fn - function callback that aggregates the values\n * @param {T} [initial_value] - initial value\n * @returns {import('./public.js').Readable<T>}\n */\n\n/**\n * @template {import('./private.js').Stores} S\n * @template T\n * @param {S} stores\n * @param {Function} fn\n * @param {T} [initial_value]\n * @returns {import('./public.js').Readable<T>}\n */\nexport function derived(stores, fn, initial_value) {\n\tconst single = !Array.isArray(stores);\n\t/** @type {Array<import('./public.js').Readable<any>>} */\n\tconst stores_array = single ? [stores] : stores;\n\tif (!stores_array.every(Boolean)) {\n\t\tthrow new Error('derived() expects stores as input, got a falsy value');\n\t}\n\tconst auto = fn.length < 2;\n\treturn readable(initial_value, (set, update) => {\n\t\tlet started = false;\n\t\tconst values = [];\n\t\tlet pending = 0;\n\t\tlet cleanup = noop;\n\t\tconst sync = () => {\n\t\t\tif (pending) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcleanup();\n\t\t\tconst result = fn(single ? values[0] : values, set, update);\n\t\t\tif (auto) {\n\t\t\t\tset(result);\n\t\t\t} else {\n\t\t\t\tcleanup = is_function(result) ? result : noop;\n\t\t\t}\n\t\t};\n\t\tconst unsubscribers = stores_array.map((store, i) =>\n\t\t\tsubscribe(\n\t\t\t\tstore,\n\t\t\t\t(value) => {\n\t\t\t\t\tvalues[i] = value;\n\t\t\t\t\tpending &= ~(1 << i);\n\t\t\t\t\tif (started) {\n\t\t\t\t\t\tsync();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tpending |= 1 << i;\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\t\tstarted = true;\n\t\tsync();\n\t\treturn function stop() {\n\t\t\trun_all(unsubscribers);\n\t\t\tcleanup();\n\t\t\t// We need to set this to false because callbacks can still happen despite having unsubscribed:\n\t\t\t// Callbacks might already be placed in the queue which doesn't know it should no longer\n\t\t\t// invoke this derived store.\n\t\t\tstarted = false;\n\t\t};\n\t});\n}\n\n/**\n * Takes a store and returns a new one derived from the old one that is readable.\n *\n * https://svelte.dev/docs/svelte-store#readonly\n * @template T\n * @param {import('./public.js').Readable<T>} store - store to make readonly\n * @returns {import('./public.js').Readable<T>}\n */\nexport function readonly(store) {\n\treturn {\n\t\tsubscribe: store.subscribe.bind(store)\n\t};\n}\n\nexport { get_store_value as get };\n","import { writable } from 'svelte/store';\nimport type { Annotation } from '../model';\nimport type { Store } from './Store';\n\nexport type HoverState<T extends Annotation> = ReturnType<typeof createHoverState<T>>;\n\nexport const createHoverState = <T extends Annotation>(store: Store<T>) => {\n\n const { subscribe, set } = writable<string | undefined>();\n\n let currentHover: string | undefined;\n\n subscribe(updated => currentHover = updated);\n\n // Track store delete and update events\n store.observe(( { changes }) => { \n if (currentHover) {\n const isDeleted = (changes.deleted || []).some(a => a.id === currentHover);\n if (isDeleted)\n set(undefined);\n \n const updated = (changes.updated || []).find(({ oldValue }) => oldValue.id === currentHover);\n if (updated)\n set(updated.newValue.id);\n }\n });\n\n return { \n get current() { return currentHover },\n subscribe, \n set \n };\n\n}\n","import { writable } from 'svelte/store';\nimport type { Annotation } from '../model';\nimport type { Store } from './Store';\n \nexport type Selection = {\n\n selected: { id: string, editable?: boolean }[],\n\n pointerEvent?: PointerEvent;\n\n}\n\nexport type SelectionState<T extends Annotation> = ReturnType<typeof createSelectionState<T>>;\n\nexport enum PointerSelectAction {\n\n EDIT = 'EDIT', // Make annotation target(s) editable on pointer select\n \n SELECT = 'SELECT', // Just select, but don't make editable\n\n NONE = 'NONE' // Click won't select - annotation is completely inert\n\n}\n\nconst EMPTY: Selection = { selected: [] };\n\nexport const createSelectionState = <T extends Annotation>(\n store: Store<T>,\n selectAction: PointerSelectAction | ((a: T) => PointerSelectAction) = PointerSelectAction.EDIT\n) => {\n const { subscribe, set } = writable<Selection>(EMPTY);\n\n let currentSelection: Selection = EMPTY;\n\n subscribe(updated => currentSelection = updated);\n\n const clear = () => set(EMPTY);\n\n const isEmpty = () => currentSelection.selected?.length === 0;\n\n const isSelected = (annotationOrId: T | string) => {\n if (currentSelection.selected.length === 0)\n return false;\n\n const id = typeof annotationOrId === 'string' ? annotationOrId : annotationOrId.id;\n return currentSelection.selected.some(i => i.id === id);\n }\n\n // TODO enable CTRL select\n const clickSelect = (id: string, pointerEvent: PointerEvent) => {\n const annotation = store.getAnnotation(id);\n if (annotation) {\n const action = onPointerSelect(annotation, selectAction);\n if (action === PointerSelectAction.EDIT)\n set({ selected: [{ id, editable: true }], pointerEvent }); \n else if (action === PointerSelectAction.SELECT)\n set({ selected: [{ id }], pointerEvent }); \n else\n set({ selected: [], pointerEvent });\n } else {\n console.warn('Invalid selection: ' + id);\n }\n }\n\n const setSelected = (idOrIds: string | string[], editable?: boolean) => {\n const ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];\n\n // Remove invalid\n const annotations = \n ids.map(id => store.getAnnotation(id)!).filter(Boolean); \n\n set({ \n selected: annotations.map(annotation => { \n // If editable is not set, use default behavior\n const isEditable = editable === undefined\n ? onPointerSelect(annotation, selectAction) === PointerSelectAction.EDIT\n : editable;\n\n return { id: annotation.id, editable: isEditable }\n })\n });\n \n if (annotations.length !== ids.length)\n console.warn('Invalid selection', idOrIds);\n }\n\n const removeFromSelection = (ids: string[]) => {\n if (currentSelection.selected.length === 0)\n return false;\n\n const { selected } = currentSelection;\n\n // Checks which of the given annotations are actually in the selection\n const toRemove = selected.filter(({ id }) => ids.includes(id))\n\n if (toRemove.length > 0)\n set({ selected: selected.filter(({ id }) => !ids.includes(id)) });\n }\n\n // Track store delete and update events\n store.observe(({ changes }) =>\n removeFromSelection((changes.deleted || []).map(a => a.id)));\n\n return { \n clear, \n clickSelect, \n get selected() { return currentSelection ? [...currentSelection.selected ] : null},\n get pointerEvent() { return currentSelection ? currentSelection.pointerEvent : null },\n isEmpty, \n isSelected, \n setSelected, \n subscribe \n };\n\n}\n\nexport const onPointerSelect = <T extends Annotation>(\n annotation: T, \n action?: PointerSelectAction | ((a: T) => PointerSelectAction)\n): PointerSelectAction => (typeof action === 'function') ?\n (action(annotation) || PointerSelectAction.EDIT) : \n (action || PointerSelectAction.EDIT);\n","import validate from './validate.js';\n\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\nvar byteToHex = [];\nfor (var i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n //\n // Note to future-self: No, you can't remove the `toLowerCase()` call.\n // REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351\n return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n var uuid = unsafeStringify(arr, offset);\n // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;","// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\n\nvar getRandomValues;\nvar rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n return getRandomValues(rnds8);\n}","var randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);\nexport default {\n randomUUID\n};","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n var rnds = options.random || (options.rng || rng)();\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buf) {\n offset = offset || 0;\n for (var i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;","import { v4 as uuidv4 } from 'uuid';\nimport type { Annotation, AnnotationBody } from '../model/Annotation';\nimport type { User } from '../model/User';\n/**\n * Returns all users listed as creators or updaters in any parts of this\n * annotation.\n */\nexport const getContributors = (annotation: Annotation): User[] => {\n const { creator, updatedBy } = annotation.target;\n\n const bodyCollaborators = annotation.bodies.reduce((users, body) => (\n [...users, body.creator, body.updatedBy].filter(Boolean) as User[]\n ), [] as User[]);\n\n return [\n creator,\n updatedBy,\n ...bodyCollaborators\n ].filter(u => u) as User[] // Remove undefined\n}\n\nexport const createBody = (\n annotation: Annotation, \n payload: { [key: string]: any },\n created?: Date,\n creator?: User\n): AnnotationBody => ({\n id: uuidv4(),\n annotation: annotation.id,\n created: created || new Date(),\n creator,\n ...payload\n});","import { dequal } from 'dequal/lite';\nimport type { Update } from '../state/StoreObserver';\nimport type { Annotation } from '../model/Annotation';\n\nconst getAddedBodies = (oldValue: Annotation, newValue: Annotation) => {\n const oldBodyIds = new Set(oldValue.bodies.map(b => b.id));\n return newValue.bodies.filter(b => !oldBodyIds.has(b.id));\n}\n\nconst getRemovedBodies = (oldValue: Annotation, newValue: Annotation) => {\n const newBodyIds = new Set(newValue.bodies.map(b => b.id));\n return oldValue.bodies.filter(b => !newBodyIds.has(b.id));\n}\n\nconst getChangedBodies = (oldValue: Annotation, newValue: Annotation) => \n newValue.bodies\n .map(newBody => {\n const oldBody = oldValue.bodies.find(b => b.id === newBody.id);\n return { newBody, oldBody: oldBody && !dequal(oldBody, newBody) ? oldBody : undefined }\n })\n .filter(({ oldBody }) => oldBody)\n .map(({ oldBody, newBody }) => ({ oldBody: oldBody!, newBody }));\n\nconst hasTargetChanged = (oldValue: Annotation, newValue: Annotation) => \n !dequal(oldValue.target, newValue.target);\n\nexport const diffAnnotations = <T extends Annotation = Annotation>(oldValue: T, newValue: T): Update<T> => {\n const bodiesCreated = getAddedBodies(oldValue, newValue);\n const bodiesDeleted = getRemovedBodies(oldValue, newValue);\n const bodiesUpdated = getChangedBodies(oldValue, newValue);\n\n return {\n oldValue, \n newValue,\n bodiesCreated: bodiesCreated.length > 0 ? bodiesCreated : undefined,\n bodiesDeleted: bodiesDeleted.length > 0 ? bodiesDeleted : undefined,\n bodiesUpdated: bodiesUpdated.length > 0 ? bodiesUpdated : undefined,\n targetUpdated: hasTargetChanged(oldValue, newValue) ? { oldTarget: oldValue.target, newTarget: newValue.target } : undefined\n }\n}","import type { Annotation, AnnotationBody, AnnotationTarget } from '../model/Annotation';\nimport { diffAnnotations } from '../utils';\n\n/** Interface for listening to changes in the annotation store **/\nexport interface StoreObserver<T extends Annotation> { \n\n onChange: { (event: StoreChangeEvent<T>): void };\n\n options: StoreObserveOptions;\n\n}\n\n/** A change event fired when the store state changes **/\nexport interface StoreChangeEvent<T extends Annotation> {\n\n origin: Origin;\n\n changes: ChangeSet<T>;\n\n state: T[];\n\n}\n\nexport interface ChangeSet<T extends Annotation> {\n\n created?: T[];\n\n deleted?: T[];\n\n updated?: Update<T>[];\n\n}\n\nexport interface Update<T extends Annotation> {\n\n oldValue: T;\n\n newValue: T;\n\n bodiesCreated?: AnnotationBody[];\n\n bodiesDeleted?: AnnotationBody[];\n\n bodiesUpdated?: Array<{ oldBody: AnnotationBody, newBody: AnnotationBody }>;\n\n targetUpdated?: { oldTarget: AnnotationTarget, newTarget: AnnotationTarget};\n\n}\n\n/** Options to control which events the observer wants to get notified about **/\nexport interface StoreObserveOptions {\n\n // Observe changes on targets, bodies or both?\n ignore?: Ignore;\n\n // Observe changes on one more specific annotations\n annotations?: string | string[];\n\n // Observer changes only for a specific origin\n origin?: Origin\n\n}\n\n/** Allows the observer to ignore certain event types **/\nexport enum Ignore { \n\n // Don't notify this observer for changes that involve bodies only\n BODY_ONLY = 'BODY_ONLY',\n\n // Don't notify for changes on targets only\n TARGET_ONLY = 'TARGET_ONLY'\n\n}\n\n/** Allows the observer to listen only for events that originated locally or from a remote source **/\nexport enum Origin { \n \n LOCAL = 'LOCAL', \n \n REMOTE = 'REMOTE' \n\n}\n\n/** Tests if this observer should be notified about this event **/\nexport const shouldNotify = <T extends Annotation>(observer: StoreObserver<T>, event: StoreChangeEvent<T>) => {\n const { changes, origin } = event;\n\n const isRelevantOrigin = \n !observer.options.origin || observer.options.origin === origin;\n\n if (!isRelevantOrigin)\n return false;\n\n if (observer.options.ignore) {\n const { ignore } = observer.options;\n\n // Shorthand\n const has = (arg: any[] | undefined) => arg && arg.length > 0;\n\n const hasAnnotationChanges =\n has(changes.created) || has(changes.deleted);\n\n if (!hasAnnotationChanges) {\n const hasBodyChanges =\n changes.updated?.some(u => has(u.bodiesCreated) || has(u.bodiesDeleted) || has(u.bodiesUpdated));\n \n const hasTargetChanges = \n changes.updated?.some(u => u.targetUpdated);\n\n if (ignore === Ignore.BODY_ONLY && hasBodyChanges && !hasTargetChanges)\n return false;\n\n if (ignore === Ignore.TARGET_ONLY && hasTargetChanges && !hasBodyChanges)\n return false;\n }\n }\n\n if (observer.options.annotations) {\n // This observer has a filter set on specific annotations - check affected\n const affectedAnnotations = new Set([\n ...(changes.created || []).map(a => a.id),\n ...(changes.deleted || []).map(a => a.id),\n ...(changes.updated || []).map(({ oldValue }) => oldValue.id)\n ]);\n\n const observed = Array.isArray(observer.options.annotations) ?\n observer.options.annotations : [ observer.options.annotations ];\n\n return Boolean(observed.find(id => affectedAnnotations.has(id)));\n } else {\n return true;\n }\n\n}\n\nexport const mergeChanges = <T extends Annotation>(changes: ChangeSet<T>, toMerge: ChangeSet<T>) => {\n const previouslyCreatedIds = new Set((changes.created || []).map(a => a.id));\n const previouslyUpdatedIds = new Set((changes.updated || []).map(({ newValue })=> newValue.id));\n\n const createdIds = new Set((toMerge.created || []).map(a => a.id));\n const deletedIds = new Set((toMerge.deleted || []).map(a => a.id));\n const updatedIds = new Set((toMerge.updated || []).map(({ oldValue }) => oldValue.id));\n\n // Updates that will be merged into create or previous update events\n const mergeableUpdates = new Set((toMerge.updated || [])\n .filter(({ oldValue }) => previouslyCreatedIds.has(oldValue.id) || previouslyUpdatedIds.has(oldValue.id))\n .map(({ oldValue }) => oldValue.id ));\n\n // * created *\n // - drop created that were then deleted\n // - merge any updates on created\n // - append newly created\n const created = [\n ...(changes.created || [])\n .filter(a => !deletedIds.has(a.id))\n .map(a => updatedIds.has(a.id) \n ? toMerge.updated!.find(({ oldValue }) => oldValue.id === a.id)!.newValue\n : a),\n ...(toMerge.created || [])\n ];\n\n // * deleted *\n // - drop deleted that were later re-created (redo action!)\n // - append newly deleted, but remove any that delete annotations \n // that were created in the same round\n const deleted = [\n ...(changes.deleted || [])\n .filter(a => !createdIds.has(a.id)),\n ...(toMerge.deleted || []) \n .filter(a => !previouslyCreatedIds.has(a.id))\n ] \n\n // * updated *\n // - drop updates on deleted annotations\n // - merge any updates that override previous ones\n // - append new updates, but remove any that were merged\n const updated = [\n ...(changes.updated || [])\n .filter(({ newValue }) => !deletedIds.has(newValue.id))\n .map(update => {\n const { oldValue, newValue } = update;\n if (updatedIds.has(newValue.id)) {\n const updated = toMerge.updated!.find(u => u.oldValue.id === newValue.id)!.newValue;\n return diffAnnotations(oldValue, updated);\n } else {\n return update;\n }\n }),\n ...(toMerge.updated || []).filter(({ oldValue }) => !mergeableUpdates.has(oldValue.id))\n ]\n\n return { created, deleted, updated };\n}","import type { Annotation } from '../model';\nimport { diffAnnotations } from '../utils';\nimport { Origin, shouldNotify, type Update, type ChangeSet } from './StoreObserver';\nimport type { StoreObserver, StoreChangeEvent, StoreObserveOptions } from './StoreObserver';\n\n// Shorthand\ntype AnnotationBodyIdentifier = { id: string, annotation: string }; \n\nexport type Store<T extends Annotation> = ReturnType<typeof createStore<T>>;\n\nconst isAnnotation = <T extends Annotation>(arg: any): arg is T => arg.id !== undefined;\n\nexport const createStore = <T extends Annotation>() => {\n\n const annotationIndex = new Map<string, T>();\n\n const bodyIndex = new Map<string, string>();\n\n const observers: StoreObserver<T>[] = [];\n\n const observe = (onChange: { (event: StoreChangeEvent<T>): void }, options: StoreObserveOptions = {}) =>\n observers.push({ onChange, options });\n\n const unobserve = (onChange: { (event: StoreChangeEvent<T>): void }) => {\n const idx = observers.findIndex(observer => observer.onChange == onChange);\n if (idx > -1)\n observers.splice(idx, 1);\n }\n\n const emit = (origin: Origin, changes: ChangeSet<T>) => {\n const event: StoreChangeEvent<T> = {\n origin,\n changes: {\n created: changes.created || [],\n updated: changes.updated || [],\n deleted: changes.deleted || []\n },\n state: [...annotationIndex.values()]\n };\n\n observers.forEach(observer => {\n if (shouldNotify(observer, event))\n observer.onChange(event);\n });\n }\n\n const addAnnotation = (annotation: T, origin = Origin.LOCAL) => {\n const existing = annotationIndex.get(annotation.id);\n\n if (existing) {\n throw Error(`Cannot add annotation ${annotation.id} - exists already`);\n } else {\n annotationIndex.set(annotation.id, annotation);\n\n annotation.bodies.forEach(b => bodyIndex.set(b.id, annotation.id));\n emit(origin, { created: [annotation] });\n }\n }\n\n const updateOneAnnotation = (arg1: string | T, arg2?: T | Origin) => {\n const updated: T = typeof arg1 === 'string' ? arg2 as T : arg1;\n\n const oldId: string = typeof arg1 === 'string' ? arg1 : arg1.id;\n const oldValue = annotationIndex.get(oldId);\n\n if (oldValue) {\n const update: Update<T> = diffAnnotations(oldValue, updated);\n\n if (oldId === updated.id) {\n annotationIndex.set(oldId, updated);\n } else {\n annotationIndex.delete(oldId);\n annotationIndex.set(updated.id, updated);\n }\n\n oldValue.bodies.forEach(b => bodyIndex.delete(b.id));\n updated.bodies.forEach(b => bodyIndex.set(b.id, updated.id));\n\n return update;\n } else {\n console.warn(`Cannot update annotation ${oldId} - does not exist`);\n }\n }\n \n const updateAnnotation = (arg1: string | T, arg2: T | Origin = Origin.LOCAL, arg3 = Origin.LOCAL) => {\n const origin: Origin = isAnnotation(arg2) ? arg3 : arg2;\n\n const update = updateOneAnnotation(arg1, arg2);\n if (update)\n emit(origin, { updated: [update] })\n }\n\n const bulkUpdateAnnotation = (annotations: T[], origin = Origin.LOCAL) => {\n const updated = annotations.reduce((updated, annotation) => {\n const u = updateOneAnnotation(annotation);\n return u ? [...updated, u] : updated;\n }, [] as Update<T>[]);\n\n if (updated.length > 0)\n emit(origin, { updated });\n }\n\n const addBody = (body: T['bodies'][number], origin = Origin.LOCAL) => {\n const oldValue = annotationIndex.get(body.annotation);\n if (oldValue) {\n const newValue = { \n ...oldValue,\n bodies: [ ...oldValue.bodies, body ]\n };\n\n annotationIndex.set(oldValue.id, newValue);\n\n bodyIndex.set(body.id, newValue.id);\n\n const update: Update<T> = {\n oldValue, newValue, bodiesCreated: [ body ]\n };\n\n emit(origin, { updated: [update] });\n } else {\n console.warn(`Attempt to add body to missing annotation: ${body.annotation}`);\n }\n }\n\n const all = () => [...annotationIndex.values()];\n\n const clear = (origin = Origin.LOCAL) => { \n const all = [...annotationIndex.values()];\n\n annotationIndex.clear();\n bodyIndex.clear();\n\n emit(origin, { deleted: all });\n }\n\n const bulkAddAnnotation = (annotations: T[], replace = true, origin = Origin.LOCAL) => {\n if (replace) {\n // Delete existing first\n const deleted = [...annotationIndex.values()];\n annotationIndex.clear();\n bodyIndex.clear();\n\n annotations.forEach(annotation => {\n annotationIndex.set(annotation.id, annotation);\n annotation.bodies.forEach(b => bodyIndex.set(b.id, annotation.id));\n });\n\n emit(origin, { created: annotations, deleted });\n } else {\n // Don't allow overwriting of existing annotations\n const existing = annotations.reduce((all, next) => {\n const existing = annotationIndex.get(next.id);\n return existing ? [...all, existing ] : all;\n }, [] as T[]);\n\n if (existing.length > 0)\n throw Error(`Bulk insert would overwrite the following annotations: ${existing.map(a => a.id).join(', ')}`);\n\n annotations.forEach(annotation => {\n annotationIndex.set(annotation.id, annotation);\n annotation.bodies.forEach(b => bodyIndex.set(b.id, annotation.id));\n });\n\n emit(origin, { created: annotations });\n }\n }\n\n const deleteOneAnnotation = (annotationOrId: T | string) => {\n const id = typeof annotationOrId === 'string' ? annotationOrId : annotationOrId.id;\n\n const existing = annotationIndex.get(id);\n if (existing) {\n annotationIndex.delete(id);\n existing.bodies.forEach(b => bodyIndex.delete(b.id));\n return existing;\n } else {\n console.warn(`Attempt to delete missing annotation: ${id}`);\n }\n }\n\n const deleteAnnotation = (annotationOrId: T | string, origin = Origin.LOCAL) => {\n const deleted = deleteOneAnnotation(annotationOrId);\n if (deleted)\n emit(origin, { deleted: [ deleted ]});\n }\n\n const bulkDeleteAnnotation = (annotationsOrIds: (T | string)[], origin = Origin.LOCAL) => {\n const deleted = annotationsOrIds.reduce((deleted, arg) => {\n const existing = deleteOneAnnotation(arg);\n return existing ? [...deleted, existing] : deleted;\n }, [] as T[]);\n\n if (deleted.length > 0)\n emit(origin, { deleted });\n }\n\n const deleteOneBody = (body: AnnotationBodyIdentifier) => {\n const oldAnnotation = annotationIndex.get(body.annotation);\n\n if (oldAnnotation) {\n const oldBody = oldAnnotation.bodies.find(b => b.id === body.id);\n\n if (oldBody) {\n bodyIndex.delete(oldBody.id);\n\n const newAnnotation = {\n ...oldAnnotation,\n bodies: oldAnnotation.bodies.filter(b => b.id !== body.id)\n };\n\n annotationIndex.set(oldAnnotation.id, newAnnotation);\n\n const update: Update<T> = {\n oldValue: oldAnnotation, newValue: newAnnotation, bodiesDeleted: [oldBody]\n };\n\n return update;\n } else {\n console.warn(`Attempt to delete missing body ${body.id} from annotation ${body.annotation}`);\n }\n } else {\n console.warn(`Attempt to delete body from missing annotation ${body.annotation}`);\n }\n }\n \n const deleteBody = (body: AnnotationBodyIdentifier, origin = Origin.LOCAL) => {\n const updated = deleteOneBody(body);\n if (updated)\n emit(origin, { updated: [ updated ]});\n }\n\n const bulkDeleteBodies = (bodies: AnnotationBodyIdentifier[], origin = Origin.LOCAL) => {\n const updated = bodies\n .map(b => deleteOneBody(b)!)\n .filter(Boolean);\n\n if (updated.length > 0)\n emit(origin, { updated });\n }\n\n const getAnnotation = (id: string): T | undefined => {\n const a = annotationIndex.get(id);\n return a ? {...a} : undefined;\n }\n\n const getBody = (id: string): T['bodies'][number] | undefined => {\n const annotationId = bodyIndex.get(id);\n if (annotationId) {\n const annotation = getAnnotation(annotationId);\n const body = annotation!.bodies.find(b => b.id === id);\n if (body) {\n return body;\n } else {\n console.error(`Store integrity error: body ${id} in index, but not in annotation`);\n }\n } else {\n console.warn(`Attempt to retrieve missing body: ${id}`);\n }\n }\n\n const updateOneBody = (oldBodyId: AnnotationBodyIdentifier, newBody: T['bodies'][number]) => {\n if (oldBodyId.annotation !== newBody.annotation)\n throw 'Annotation integrity violation: annotation ID must be the same when updating bodies';\n\n const oldAnnotation = annotationIndex.get(oldBodyId.annotation);\n if (oldAnnotation) {\n const oldBody = oldAnnotation.bodies.find(b => b.id === oldBodyId.id)!;\n\n const newAnnotation = { \n ...oldAnnotation,\n bodies: oldAnnotation.bodies.map(b => b.id === oldBody.id ? newBody : b)\n };\n\n annotationIndex.set(oldAnnotation.id, newAnnotation);\n\n if (oldBody.id !== newBody.id) {\n bodyIndex.delete(oldBody.id);\n bodyIndex.set(newBody.id, newAnnotation.id);\n }\n\n return {\n oldValue: oldAnnotation, \n newValue: newAnnotation,\n bodiesUpdated: [{ oldBody, newBody }]\n }\n } else {\n console.warn(`Attempt to add body to missing annotation ${oldBodyId.annotation}`);\n }\n }\n\n const updateBody = (oldBodyId: AnnotationBodyIdentifier, newBody: T['bodies'][number], origin = Origin.LOCAL) => {\n const update = updateOneBody(oldBodyId, newBody);\n if (update)\n emit(origin, { updated: [ update ]} );\n }\n\n const bulkUpdateBodies = (bodies: Array<T['bodies'][number]>, origin = Origin.LOCAL) => {\n const updated = bodies\n .map(b => updateOneBody({ id: b.id, annotation: b.annotation }, b)!)\n .filter(Boolean);\n\n emit(origin, { updated });\n }\n\n const updateOneTarget = (target: T['target']): Update<T> | undefined => {\n const oldValue = annotationIndex.get(target.annotation);\n \n if (oldValue) {\n const newValue = { \n ...oldValue, \n target: {\n ...oldValue.target,\n ...target \n }\n };\n\n annotationIndex.set(oldValue.id, newValue);\n\n return {\n oldValue, newValue, targetUpdated: { \n oldTarget: oldValue.target,\n newTarget: target\n }\n };\n } else {\n console.warn(`Attempt to update target on missing annotation: ${target.annotation}`);\n }\n }\n\n const updateTarget = (target: T['target'], origin = Origin.LOCAL) => {\n const update = updateOneTarget(target);\n if (update)\n emit(origin, { updated: [ update ]} );\n }\n\n const bulkUpdateTargets = (targets: Array<T['target']>, origin = Origin.LOCAL) => {\n const updated = \n targets.map(t => updateOneTarget(t)!).filter(Boolean);\n if (updated.length > 0)\n emit(origin, { updated });\n }\n\n\treturn {\n addAnnotation,\n addBody,\n all,\n bulkAddAnnotation,\n bulkDeleteAnnotation,\n bulkDeleteBodies,\n bulkUpdateAnnotation,\n bulkUpdateBodies,\n bulkUpdateTargets,\n clear,\n deleteAnnotation,\n deleteBody,\n getAnnotation,\n getBody,\n observe,\n unobserve,\n updateAnnotation,\n updateBody,\n updateTarget\n\t};\n\n}\n","import type { Annotation, Annotator, AnnotatorState } from '../model';\nimport type { Store } from './Store';\nimport type { StoreChangeEvent } from './StoreObserver';\n\ntype Subscriber<T extends Annotation> = (annotation: T[]) => void; \n\nexport interface SvelteStore<T extends Annotation> extends Store<T> {\n\n subscribe(onChange: Subscriber<T>): void;\n\n}\n\nexport interface SvelteAnnotatorState<T extends Annotation> extends AnnotatorState<T> {\n\n store: SvelteStore<T>\n\n}\n\nexport interface SvelteAnnotator<T extends Annotation> extends Annotator<T> {\n\n state: SvelteAnnotatorState<T>\n\n}\n\n/** \n * A simple wrapper around the event-based store implementation\n * that adds a Svelte shim, for use with the reactive '$' notation.\n * Other frameworks might not actually need this. But it's pretty\n * convenient for everyone using Svelte, as well as for the\n * basic (Svelte-based) Annotorious standard implementation.\n */\nexport const toSvelteStore = <T extends Annotation>(store: Store<T>): SvelteStore<T> => {\n\n const subscribe = (onChange: Subscriber<T>) => {\n\n // Register a store observer on behalf of the subscriber\n const shim = (event: StoreChangeEvent<T>) => onChange(event.state);\n store.observe(shim);\n\n // Immediately call the subscriber function with the\n // current store value, according to the Svelte contract.\n // https://stackoverflow.com/questions/68220955/how-does-svelte-unsubscribe-actually-work\n onChange(store.all());\n\n // Return the unsubscribe function\n return () => store.unobserve(shim);\n }\n\n return {\n ...store,\n subscribe\n }\n\n}","export let createNanoEvents = () => ({\n emit(event, ...args) {\n for (\n let i = 0,\n callbacks = this.events[event] || [],\n length = callbacks.length;\n i < length;\n i++\n ) {\n callbacks[i](...args)\n }\n },\n events: {},\n on(event, cb) {\n ;(this.events[event] ||= []).push(cb)\n return () => {\n this.events[event] = this.events[event]?.filter(i => cb !== i)\n }\n }\n})\n","import { createNanoEvents, type Unsubscribe } from 'nanoevents';\nimport { v4 as uuidv4 } from 'uuid';\nimport type { Annotation } from '../model';\nimport type { Store } from './Store';\nimport { Origin } from './StoreObserver';\nimport { mergeChanges, type ChangeSet, type StoreChangeEvent, type Update } from './StoreObserver';\n\n// Duration with fast successive changes get merged \n// with the last event in the stack, rather than getting stacked\n// as a new undo/redo step.\nconst DEBOUNCE = 250;\n\nexport interface UndoStack <T extends Annotation> {\n\n canRedo(): boolean;\n\n canUndo(): boolean;\n\n destroy(): void;\n\n on<E extends keyof UndoStackEvents<T>>(event: E, callback: UndoStackEvents<T>[E]): Unsubscribe;\n\n undo(): void;\n\n redo(): void;\n\n}\n\nexport interface UndoStackEvents <T extends Annotation> {\n\n redo(change: ChangeSet<T>): void;\n\n undo(change: ChangeSet<T>): void;\n\n}\n\nexport const createUndoStack = <T extends Annotation>(store: Store<T>): UndoStack<T> => {\n\n const emitter = createNanoEvents<UndoStackEvents<T>>();\n\n const changeStack: ChangeSet<T>[] = [];\n\n let pointer = -1;\n\n let muteEvents = false;\n\n let lastEvent = 0;\n\n const onChange = (event: StoreChangeEvent<T>) => {\n if (!muteEvents) {\n const { changes } = event;\n\n const now = performance.now();\n\n if (now - lastEvent > DEBOUNCE) {\n // Put this change on the stack...\n changeStack.splice(pointer + 1);\n changeStack.push(changes);\n\n // ...and update the pointer\n pointer = changeStack.length - 1;\n } else {\n // Merge this change with the last in the stack\n const last = changeStack.length - 1;\n changeStack[last] = mergeChanges(changeStack[last], changes);\n }\n\n lastEvent = now;\n }\n\n muteEvents = false;\n }\n\n store.observe(onChange, { origin: Origin.LOCAL });\n\n const undoCreated = (created?: T[]) =>\n created && created.length > 0 && store.bulkDeleteAnnotation(created);\n\n const redoCreated = (created?: T[]) =>\n created && created.length > 0 && store.bulkAddAnnotation(created, false);\n\n const undoUpdated = (updated?: Update<T>[]) =>\n updated && updated.length > 0 && store.bulkUpdateAnnotation(updated.map(({ oldValue }) => oldValue));\n \n const redoUpdated = (updated?: Update<T>[]) =>\n updated && updated.length > 0 && store.bulkUpdateAnnotation(updated.map(({ newValue }) => newValue));\n\n const undoDeleted = (deleted?: T[]) => \n deleted && deleted.length > 0 && store.bulkAddAnnotation(deleted, false);\n\n const redoDeleted = (deleted?: T[]) =>\n deleted && deleted.length > 0 && store.bulkDeleteAnnotation(deleted);\n\n const undo = () => {\n if (pointer > -1) {\n muteEvents = true;\n\n const { created, updated, deleted } = changeStack[pointer];\n\n undoCreated(created);\n undoUpdated(updated);\n undoDeleted(deleted);\n\n emitter.emit('undo', changeStack[pointer]);\n\n pointer -= 1;\n }\n }\n\n const canUndo = () => pointer > -1;\n\n const redo = () => {\n if (changeStack.length - 1 > pointer) {\n muteEvents = true;\n\n const { created, updated, deleted } = changeStack[pointer + 1];\n\n redoCreated(created);\n redoUpdated(updated);\n redoDeleted(deleted);\n\n emitter.emit('redo', changeStack[pointer + 1]);\n\n pointer += 1;\n }\n }\n\n const canRedo = () => changeStack.length - 1 > pointer;\n\n const destroy = () => store.unobserve(onChange);\n\n const on = <E extends keyof UndoStackEvents<T>>(event: E, callback: UndoStackEvents<T>[E]) => \n emitter.on(event, callback);\n\n return {\n canRedo,\n canUndo,\n destroy,\n on,\n redo,\n undo\n }\n\n}","import { writable } from 'svelte/store';\n\nexport type ViewportState = ReturnType<typeof createViewportState>;\n\nexport const createViewportState = () => {\n\n const { subscribe, set } = writable<string[]>([]);\n\n return { \n subscribe, \n set\n };\n\n}\n","import { dequal } from 'dequal/lite';\nimport type { Annotation, AnnotatorState, FormatAdapter } from '../model';\nimport { Origin, type ChangeSet, type UndoStack } from '../state';\nimport type { LifecycleEvents } from './LifecycleEvents';\n\nexport type Lifecycle<I extends Annotation, E extends unknown> = \n ReturnType<typeof createLifecyleObserver<I, E>>;\n\nexport const createLifecyleObserver = <I extends Annotation, E extends unknown>(\n state: AnnotatorState<I>,\n undoStack: UndoStack<I>,\n adapter?: FormatAdapter<I, E>,\n autoSave?: boolean\n) => {\n const { store, selection, hover, viewport } = state;\n\n const observers: Map<keyof LifecycleEvents, Function[]> = new Map();\n\n // The currently selected annotations, in the state when they were selected \n let initialSelection: I[] = [];\n\n let currentHover: string | undefined;\n\n let idleTimeout: ReturnType<typeof setTimeout>;\n\n const on = <T extends keyof LifecycleEvents>(event: T, callback: LifecycleEvents<E>[T]) => {\n if (observers.has(event)) {\n observers.get(event)!.push(callback);\n } else {\n observers.set(event, [callback]);\n }\n }\n\n const off = <T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]) => {\n const callbacks = observers.get(event);\n if (callbacks) {\n const idx = callbacks.indexOf(callback);\n if (idx > 0)\n callbacks.splice(callbacks.indexOf(callback), 1);\n }\n }\n\n const emit = (event: keyof LifecycleEvents<E>, arg0: I | I[], arg1?: I | PointerEvent) => {\n if (observers.has(event)) {\n setTimeout(() => {\n observers.get(event)!.forEach(callback => { \n if (adapter) {\n const serialized0 = Array.isArray(arg0) ? \n arg0.map(a => adapter.serialize(a)) : adapter.serialize(arg0);\n \n const serialized1: E | PointerEvent | undefined =\n arg1 ? arg1 instanceof PointerEvent ? arg1 : adapter.serialize(arg1) : undefined;\n\n callback(serialized0 as E & E[], serialized1); \n } else {\n callback(arg0 as E & E[], arg1 as unknown as E); \n }\n });\n }, 1);\n }\n }\n\n const onIdleUpdate = () => {\n const { selected } = selection;\n\n // User idle after activity - fire update events for selected\n // annotations that changed\n const updatedSelected = (selected || []).map(({ id }) => store.getAnnotation(id)!);\n\n updatedSelected.forEach(updated => {\n const initial = initialSelection.find(a => a.id === updated.id);\n if (!initial || !dequal(initial, updated)) {\n emit('updateAnnotation', updated, initial);\n }\n });\n\n initialSelection = initialSelection.map(initial => {\n const updated = updatedSelected.find(({ id }) => id === initial.id);\n return updated ? updated : initial\n });\n }\n\n selection.subscribe(({ selected })=> {\n if (initialSelection.length === 0 && selected.length === 0)\n return;\n\n if (initialSelection.length === 0 && selected.length > 0) {\n // A new selection was made - store the editable annotation as initial state\n initialSelection = selected.map(({ id }) => store.getAnnotation(id)!);\n } else if (initialSelection.length > 0 && selected.length === 0) {\n // Deselect!\n initialSelection.forEach(initial => {\n const updatedState = store.getAnnotation(initial.id); \n \n if (updatedState && !dequal(updatedState, initial)) {\n emit('updateAnnotation', updatedState, initial);\n }\n });\n\n initialSelection = [];\n } else {\n // Changed selection\n const initialIds = new Set(initialSelection.map(a => a.id));\n const selectedIds = new Set(selected.map(({ id }) => id));\n\n // Fire update events for deselected annotations that have changed\n const deselected = initialSelection.filter(a => !selectedIds.has(a.id));\n deselected.forEach(initial => {\n const updatedState = store.getAnnotation(initial.id);\n\n if (updatedState && !dequal(updatedState, initial))\n emit('updateAnnotation', updatedState, initial);\n });\n\n initialSelection = [\n // Remove annotations that were deselected\n ...initialSelection.filter(a => selectedIds.has(a.id)),\n // Add editable annotations that were selected\n ...selected\n .filter(({ id }) => !initialIds.has(id))\n .map(({ id }) => store.getAnnotation(id)!)\n ];\n }\n\n emit('selectionChanged', initialSelection);\n });\n\n hover.subscribe(id => {\n if (!currentHover && id) {\n emit('mouseEnterAnnotation', store.getAnnotation(id)!);\n } else if (currentHover && !id) {\n emit('mouseLeaveAnnotation', store.getAnnotation(currentHover)!);\n } else if (currentHover && id) {\n emit('mouseLeaveAnnotation', store.getAnnotation(currentHover)!);\n emit('mouseEnterAnnotation', store.getAnnotation(id)!);\n }\n\n currentHover = id;\n });\n\n viewport?.subscribe(ids => \n emit('viewportIntersect', ids.map(id => store.getAnnotation(id)!)));\n\n store.observe(event => {\n // autoSave option triggers update events on idleness\n if (autoSave) {\n if (idleTimeout)\n clearTimeout(idleTimeout);\n\n idleTimeout = setTimeout(onIdleUpdate, 1000);\n }\n\n // Local CREATE and DELETE events are applied immediately\n const { created, deleted } = event.changes;\n (created || []).forEach(a => emit('createAnnotation', a));\n (deleted || []).forEach(a => emit('deleteAnnotation', a));\n\n // Updates are only applied immediately if they involve body changes\n const updatesWithBody = (event.changes.updated || []).filter(u => [\n ...(u.bodiesCreated || []),\n ...(u.bodiesDeleted || []),\n ...(u.bodiesUpdated || [])\n ].length > 0);\n\n // Emit an update with the new annototation and the stored initial state\n updatesWithBody.forEach(({ oldValue, newValue }) => {\n const initial = initialSelection.find(a => a.id === oldValue.id) || oldValue;\n\n // Record the update as the new last known state\n initialSelection = initialSelection\n .map(a => a.id === oldValue.id ? newValue : a);\n\n emit('updateAnnotation', newValue, initial);\n });\n }, { origin: Origin.LOCAL });\n\n // Track remote changes - these should update the initial state\n store.observe(event => {\n if (initialSelection) {\n const selectedIds = new Set(initialSelection.map(a => a.id));\n\n const relevantUpdates = (event.changes.updated || [])\n .filter(({ newValue }) => selectedIds.has(newValue.id))\n .map(({ newValue }) => newValue);\n\n if (relevantUpdates.length > 0) {\n initialSelection = initialSelection.map(selected => {\n const updated = relevantUpdates.find(updated => updated.id === selected.id);\n return updated ? updated : selected;\n })\n }\n }\n }, { origin: Origin.REMOTE });\n\n const onUndoOrRedo = (undo: boolean) => (changes: ChangeSet<I>) => {\n // Undo/redo of created/delete will cause lifecycle events automatically,\n // but we need to handle udpates specifically!\n const { updated } = changes;\n\n if (undo)\n (updated || []).forEach(t => emit('updateAnnotation', t.oldValue, t.newValue));\n else\n (updated || []).forEach(t => emit('updateAnnotation', t.newValue, t.oldValue));\n }\n\n undoStack.on('undo', onUndoOrRedo(true));\n undoStack.on('redo', onUndoOrRedo(false));\n\n return { on, off, emit }\n\n}","import type { Annotation } from './Annotation';\n\nexport interface FormatAdapter<A extends Annotation, T extends unknown> {\n\n parse(serialized: T): ParseResult<A>;\n\n serialize(core: A): T;\n\n}\n\nexport interface ParseResult<A extends Annotation> {\n\n parsed?: A;\n \n error?: Error;\n\n}\n\nexport const serializeAll = \n <A extends Annotation, T extends unknown>(adapter: FormatAdapter<A, T>) =>\n (annotations: A[]) => annotations.map(a => adapter.serialize(a));\n\nexport const parseAll = \n <A extends Annotation, T extends unknown>(adapter: FormatAdapter<A, T>) =>\n (serialized: T[]) => serialized.reduce((result, next) => {\n const { parsed, error } = adapter.parse(next);\n \n return error ? {\n parsed: result.parsed,\n failed: [...result.failed, next ]\n } : parsed ? {\n parsed: [...result.parsed, parsed ],\n failed: result.failed\n } : {\n ...result\n }\n }, { parsed: [] as A[], failed: [] as T[]});\n ","import type { Annotation } from './Annotation';\nimport type { User } from './User';\nimport type { PresenceProvider } from '../presence/PresenceProvider';\nimport { Origin, type HoverState, type SelectionState, type Store, type UndoStack, type ViewportState } from '../state';\nimport type { LifecycleEvents } from '../lifecycle/LifecycleEvents';\nimport { parseAll, type FormatAdapter } from './FormatAdapter';\nimport type { DrawingStyleExpression } from './DrawingStyle';\nimport type { Filter } from './Filter';\n\n/**\n * Base annotator interface\n * @template I - internal core data model\n * @template E - external adapted representation\n */\nexport interface Annotator<I extends Annotation = Annotation, E extends unknown = Annotation> {\n\n addAnnotation(annotation: E): void;\n\n cancelSelected(): void;\n\n canRedo(): boolean;\n\n canUndo(): boolean;\n\n clearAnnotations(): void;\n\n destroy(): void;\n\n getAnnotationById(id: string): E | undefined;\n\n getAnnotations(): E[];\n\n getSelected(): E[];\n\n getUser(): User;\n\n loadAnnotations(url: string, replace?: boolean): Promise<E[]>;\n\n redo(): void;\n\n removeAnnotation(arg: E | string): E | undefined;\n\n setAnnotations(annotations: E[], replace?: boolean): void;\n\n setFilter(filter: Filter | undefined): void;\n\n setPresenceProvider?(provider: PresenceProvider): void;\n\n setSelected(arg?: string | string[], editable?: boolean): void;\n\n setStyle(style: DrawingStyleExpression<I> | undefined): void;\n\n setUser(user: User): void;\n\n setVisible(visible: boolean): void;\n\n undo(): void;\n\n updateAnnotation(annotation: E): E;\n \n on<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;\n\n off<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;\n\n state: AnnotatorState<I>;\n\n}\n\nexport interface AnnotatorState<A extends Annotation> {\n\n store: Store<A>;\n\n selection: SelectionState<A>;\n\n hover: HoverState<A>;\n\n viewport: ViewportState;\n\n}\n\nexport const createBaseAnnotator = <I extends Annotation, E extends unknown>(\n state: AnnotatorState<I>, \n undoStack: UndoStack<I>,\n adapter?: FormatAdapter<I, E>\n) => {\n\n const { store, selection } = state;\n\n const addAnnotation = (annotation: E) => {\n if (adapter) {\n const { parsed, error } = adapter.parse(annotation);\n if (parsed) {\n store.addAnnotation(parsed, Origin.REMOTE);\n } else {\n console.error(error);\n }\n } else {\n store.addAnnotation(annotation as unknown as I, Origin.REMOTE);\n }\n }\n\n const cancelSelected = () => selection.clear();\n\n const clearAnnotations = () => store.clear();\n\n const getAnnotationById = (id: string): E | undefined => {\n const annotation = store.getAnnotation(id);\n return (adapter && annotation) ?\n adapter.serialize(annotation) as E : annotation as unknown as E;\n }\n\n const getAnnotations = () =>\n (adapter ? store.all().map(adapter.serialize) : store.all()) as E[];\n\n const getSelected = () => {\n const selectedIds = selection.selected?.map(s => s.id) || [];\n\n const selected = selectedIds.map(id => store.getAnnotation(id)!).filter(Boolean);\n\n return adapter \n ? selected.map(adapter.serialize) \n : selected as unknown as E[];\n }\n\n const loadAnnotations = (url: string, replace = true) =>\n fetch(url)\n .then((response) => response.json())\n .then((annotations) => {\n setAnnotations(annotations, replace);\n return annotations;\n });\n\n const removeAnnotation = (arg: E | string): E | undefined => {\n if (typeof arg === 'string') {\n const annotation = store.getAnnotation(arg);\n store.deleteAnnotation(arg);\n\n if (annotation)\n return adapter ? adapter.serialize(annotation) : annotation as unknown as E;\n } else {\n const annotation = adapter ? adapter.parse(arg).parsed : (arg as unknown as I);\n\n if (annotation) {\n store.deleteAnnotation(annotation);\n return arg;\n }\n }\n }\n\n const setAnnotations = (annotations: E[], replace = true) => {\n if (adapter) {\n const { parsed, failed } = parseAll(adapter)(annotations);\n\n if (failed.length > 0)\n console.warn(`Discarded ${failed.length} invalid annotations`, failed);\n\n store.bulkAddAnnotation(parsed, replace, Origin.REMOTE);\n } else {\n store.bulkAddAnnotation(annotations as unknown as I[], replace, Origin.REMOTE);\n }\n }\n\n const setSelected = (arg?: string | string[], editable?: boolean) => {\n if (arg) {\n selection.setSelected(arg, editable);\n } else {\n selection.clear();\n }\n }\n\n const updateAnnotation = (updated: E): E => {\n if (adapter) {\n const crosswalked = adapter.parse(updated).parsed!;\n const previous = adapter.serialize(store.getAnnotation(crosswalked.id)!);\n store.updateAnnotation(crosswalked);\n return previous;\n } else {\n const previous = store.getAnnotation((updated as unknown as I).id);\n store.updateAnnotation(updated as unknown as I);\n return previous as unknown as E;\n }\n }\n\n // Note that we don't spread the undoStack - it has a .destroy()\n // method that would likely get overwritten by other Annotator implementations\n // if people are not careful.\n return { \n addAnnotation,\n cancelSelected,\n canRedo: undoStack.canRedo,\n canUndo: undoStack.canUndo,\n clearAnnotations,\n getAnnotationById,\n getAnnotations,\n getSelected,\n loadAnnotations,\n redo: undoStack.redo,\n removeAnnotation,\n setAnnotations,\n setSelected,\n undo: undoStack.undo,\n updateAnnotation\n }\n\n}\n","export const urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n","import { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js'\nexport { urlAlphabet } from './url-alphabet/index.js'\nexport let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nexport let customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nexport let customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nexport let nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array(size))\n while (size--) {\n id += scopedUrlAlphabet[bytes[size] & 63]\n }\n return id\n}\n","import { customAlphabet } from 'nanoid';\n\nexport interface User {\n\n id: string;\n\n isGuest?: boolean;\n\n name?: string;\n\n avatar?: string;\n\n}\n\nexport const createAnonymousGuest = () => {\n const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_', 20);\n \n return { isGuest: true, id: nanoid() }\n}","import type { AnnotationBody } from './Annotation';\n\nexport interface W3CAnnotation {\n\n '@context': 'http://www.w3.org/ns/anno.jsonld';\n\n type: 'Annotation';\n\n id: string;\n\n creator?: W3CUser;\n\n created?: string;\n\n modified?: string;\n\n body: W3CAnnotationBody | W3CAnnotationBody[];\n\n target: W3CAnnotationTarget | W3CAnnotationTarget[];\n\n [key: string]: any;\n\n}\n\nexport interface W3CUser {\n\n type?: string;\n\n id: string;\n\n name?: string;\n\n}\n\nexport interface W3CAnnotationBody {\n\n type?: string;\n\n id?: string;\n\n purpose?: string;\n\n value?: string;\n\n source?: string;\n\n creator?: W3CUser;\n\n created?: string;\n\n modified?: string;\n\n}\n\nexport interface W3CAnnotationTarget {\n\n id?: string;\n\n source: string;\n\n selector?: AbstractW3CSelector;\n\n}\n\nexport interface AbstractW3CSelector { }\n\n// https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript\nconst hashCode = (obj: Object): string => {\n const str = JSON.stringify(obj);\n\n let hash = 0;\n\n for (let i = 0, len = str.length; i < len; i++) {\n let chr = str.charCodeAt(i);\n hash = (hash << 5) - hash + chr;\n hash |= 0; // Convert to 32bit integer\n }\n\n return `${hash}`;\n}\n\nexport const parseW3CUser = (user?: any) => user\n ? typeof user === 'object' ? { ...user } : user : undefined;\n\n/**\n * Helper to crosswalk the W3C annotation body to a list of core AnnotationBody objects.\n */\nexport const parseW3CBodies = (\n body: W3CAnnotationBody | W3CAnnotationBody[],\n annotationId: string\n) : AnnotationBody[] => (Array.isArray(body) ? body : [body]).map(body => {\n\n // Exctract properties that conform to the internal model, but keep custom props\n const { id, type, purpose, value, created, modified, creator, ...rest } = body;\n\n // The internal model strictly requires IDs. (Because multi-user scenarios\n // will have problems without them.) In the W3C model, bodys *may* have IDs.\n // We'll create ad-hoc IDs for bodies without IDs, but want to make sure that\n // generating the ID is idempotent: the same body should always get the same ID.\n // This will avoid unexpected results when checking for equality. \n return {\n id: id || `temp-${hashCode(body)}`,\n annotation: annotationId,\n type,\n purpose,\n value,\n creator: parseW3CUser(creator),\n created: created ? new Date(created) : undefined,\n updated: modified ? new Date(modified) : undefined,\n ...rest\n }\n\n});\n\n/** Serialization helper to remove core-specific fields from the annotation body **/\nexport const serializeW3CBodies = (bodies: AnnotationBody[]): W3CAnnotationBody[] =>\n bodies.map(b => {\n const { annotation: _a, created, updated, ...bodyRest } = b;\n\n const w3cBody: W3CAnnotationBody = {\n ...bodyRest,\n created: created?.toISOString(),\n modified: updated?.toISOString()\n }\n if (w3cBody.id?.startsWith('temp-')) {\n delete w3cBody.id;\n }\n\n return w3cBody;\n });\n","// SEABORN_BRIGHT\nexport const DEFAULT_PALETTE: Palette = [\n '#ff7c00', // orange\n '#1ac938', // green\n '#e8000b', // red\n '#8b2be2', // purple\n '#9f4800', // brown\n '#f14cc1', // pink\n '#ffc400', // khaki\n '#00d7ff', // cyan\n '#023eff' // blue\n];\n\nexport type Palette = string[];","import type { User } from '../model/User';\nimport type { Appearance } from './Appearance';\nimport type { PresentUser } from './PresentUser';\nimport { DEFAULT_PALETTE } from './ColorPalette';\n\nexport interface AppearanceProvider {\n\n addUser(presenceKey: string, user: User): Appearance;\n\n removeUser(user: PresentUser): void;\n\n}\n\nexport const defaultColorProvider = () => {\n\n const unassignedColors = [...DEFAULT_PALETTE];\n\n const assignRandomColor = () => {\n const rnd = Math.floor(Math.random() * unassignedColors.length);\n const color = unassignedColors[rnd];\n\n unassignedColors.splice(rnd, 1);\n\n return color;\n }\n\n const releaseColor = (color: string) =>\n unassignedColors.push(color);\n\n return { assignRandomColor, releaseColor };\n\n}\n\nexport const createDefaultAppearenceProvider = () => {\n\n const colorProvider = defaultColorProvider();\n\n const addUser = (presenceKey: string, user: User): Appearance => {\n const color = colorProvider.assignRandomColor();\n\n return {\n label: user.name || user.id,\n avatar: user.avatar,\n color\n };\n }\n\n const removeUser = (user: PresentUser) =>\n colorProvider.releaseColor(user.appearance.color);\n\n return { addUser, removeUser }\n \n}","import { nanoid } from 'nanoid';\nimport { createNanoEvents, type Unsubscribe } from 'nanoevents';\nimport type { User } from '../model/User';\nimport type { PresentUser } from './PresentUser';\nimport type { PresenceEvents } from './PresenceEvents';\nimport { createDefaultAppearenceProvider } from './AppearanceProvider';\nimport type { AppearanceProvider } from './AppearanceProvider';\n\nexport interface PresenceState {\n\n // Get users currently present to this room\n getPresentUsers(): PresentUser[];\n\n // Notify of a given present user's activity on the given annotations\n notifyActivity(presenceKey: string, annotationIds: string[]): void;\n\n // Add a listener for the given presence event\n on<E extends keyof PresenceEvents>(event: E, callback: PresenceEvents[E]): Unsubscribe;\n\n // Initial sync - which users are present under which keys\n syncUsers(state: { presenceKey: string, user: User }[]): void;\n\n // Update the selection state for the given prresent user\n updateSelection(presenceKey: string, selection: string[] | null): void;\n\n}\n\nconst isListEqual = (listA: any[], listB: any[]) => \n listA.every(a => listA.includes(a)) && listB.every(b => listA.includes(b));\n\n// This client's presence key\nexport const PRESENCE_KEY = nanoid();\n\nexport const createPresenceState = (\n appearanceProvider: AppearanceProvider = createDefaultAppearenceProvider()\n): PresenceState => {\n\n const emitter = createNanoEvents<PresenceEvents>();\n\n const presentUsers = new Map<string, PresentUser>();\n\n const selectionStates = new Map<string, string[]>();\n\n const addUser = (presenceKey: string, user: User) => {\n if (presentUsers.has(presenceKey)) {\n console.warn('Attempt to add user that is already present', presenceKey, user);\n return; \n }\n\n const appearance = appearanceProvider.addUser(presenceKey, user);\n\n presentUsers.set(presenceKey, { \n ...user,\n presenceKey,\n appearance\n });\n }\n\n const removeUser = (presenceKey: string) => {\n const user = presentUsers.get(presenceKey);\n if (!user) {\n console.warn('Attempt to remove user that is not present', presenceKey);\n return;\n }\n\n appearanceProvider.removeUser(user);\n\n presentUsers.delete(presenceKey);\n }\n\n const syncUsers = (state: { presenceKey: string, user: User }[]) => {\n // const keys = new Set(others.map(s => s.presenceKey));\n const keys = new Set(state.map(s => s.presenceKey));\n\n // These users need to be added to the presentUsers list\n // const toAdd = others.filter(({ presenceKey }) => !presentUsers.has(presenceKey));\n const toAdd = state.filter(({ presenceKey }) => !presentUsers.has(presenceKey));\n\n // These users need to be dropped from the list\n const toRemove = Array.from(presentUsers.values()).filter(presentUser =>\n !keys.has(presentUser.presenceKey));\n\n toAdd.forEach(({ presenceKey, user }) => addUser(presenceKey, user));\n\n toRemove.forEach(user => {\n const { presenceKey } = user;\n\n // If this user has a selection, fire deselect event\n if (selectionStates.has(presenceKey))\n emitter.emit('selectionChange', user, null);\n\n removeUser(presenceKey)\n });\n\n if (toAdd.length > 0 || toRemove.length > 0)\n emitter.emit('presence', getPresentUsers());\n }\n\n const notifyActivity = (presenceKey: string, annotationIds: string[]) => { \n const user = presentUsers.get(presenceKey);\n \n if (!user) {\n console.warn('Activity notification from user that is not present');\n return;\n }\n\n const currentSelection = selectionStates.get(presenceKey);\n\n // Was there a selection change we might have missed?\n if (!currentSelection || !isListEqual(currentSelection, annotationIds)) {\n selectionStates.set(presenceKey, annotationIds);\n emitter.emit('selectionChange', user, annotationIds);\n }\n }\n\n const updateSelection = (presenceKey: string, selection: string[] | null) => {\n const from = presentUsers.get(presenceKey);\n if (!from) {\n console.warn('Selection change for user that is not present', presenceKey);\n return;\n }\n\n if (selection)\n selectionStates.set(presenceKey, selection);\n else \n selectionStates.delete(presenceKey);\n\n emitter.emit('selectionChange', from, selection);\n }\n\n const getPresentUsers = () =>\n [...Array.from(presentUsers.values())];\n \n const on = <E extends keyof PresenceEvents>(event: E, callback: PresenceEvents[E]) =>\n emitter.on(event, callback);\n\n return {\n getPresentUsers,\n notifyActivity,\n on,\n syncUsers,\n updateSelection\n }\n\n}"],"names":["has","dequal","foo","bar","ctor","len","noop","safe_not_equal","a","b","subscriber_queue","writable","value","start","stop","subscribers","set","new_value","run_queue","subscriber","i","update","fn","subscribe","run","invalidate","createHoverState","store","currentHover","updated","changes","oldValue","PointerSelectAction","EMPTY","createSelectionState","selectAction","currentSelection","clear","isEmpty","_a","isSelected","annotationOrId","id","clickSelect","pointerEvent","annotation","action","onPointerSelect","setSelected","idOrIds","editable","ids","annotations","isEditable","removeFromSelection","selected","byteToHex","unsafeStringify","arr","offset","getRandomValues","rnds8","rng","randomUUID","native","v4","options","buf","rnds","getContributors","creator","updatedBy","bodyCollaborators","users","body","u","createBody","payload","created","uuidv4","getAddedBodies","newValue","oldBodyIds","getRemovedBodies","newBodyIds","getChangedBodies","newBody","oldBody","hasTargetChanged","diffAnnotations","bodiesCreated","bodiesDeleted","bodiesUpdated","Ignore","Origin","shouldNotify","observer","event","_b","origin","ignore","arg","hasBodyChanges","hasTargetChanges","affectedAnnotations","mergeChanges","toMerge","previouslyCreatedIds","previouslyUpdatedIds","createdIds","deletedIds","updatedIds","mergeableUpdates","deleted","isAnnotation","createStore","annotationIndex","bodyIndex","observers","observe","onChange","unobserve","idx","emit","addAnnotation","updateOneAnnotation","arg1","arg2","oldId","updateAnnotation","arg3","bulkUpdateAnnotation","addBody","all","bulkAddAnnotation","replace","existing","next","deleteOneAnnotation","deleteAnnotation","bulkDeleteAnnotation","annotationsOrIds","deleteOneBody","oldAnnotation","newAnnotation","deleteBody","bulkDeleteBodies","bodies","getAnnotation","getBody","annotationId","updateOneBody","oldBodyId","updateBody","bulkUpdateBodies","updateOneTarget","target","targets","t","toSvelteStore","shim","createNanoEvents","args","callbacks","length","cb","DEBOUNCE","createUndoStack","emitter","changeStack","pointer","muteEvents","lastEvent","now","last","undoCreated","redoCreated","undoUpdated","redoUpdated","undoDeleted","redoDeleted","callback","createViewportState","createLifecyleObserver","state","undoStack","adapter","autoSave","selection","hover","viewport","initialSelection","idleTimeout","on","off","arg0","serialized0","serialized1","onIdleUpdate","updatedSelected","initial","updatedState","initialIds","selectedIds","relevantUpdates","onUndoOrRedo","undo","serializeAll","parseAll","serialized","result","parsed","error","createBaseAnnotator","cancelSelected","clearAnnotations","getAnnotationById","getAnnotations","getSelected","s","loadAnnotations","url","response","setAnnotations","removeAnnotation","failed","crosswalked","previous","urlAlphabet","random","bytes","customRandom","alphabet","defaultSize","getRandom","mask","step","size","j","customAlphabet","nanoid","scopedUrlAlphabet","createAnonymousGuest","hashCode","obj","str","hash","chr","parseW3CUser","user","parseW3CBodies","type","purpose","modified","rest","serializeW3CBodies","bodyRest","w3cBody","DEFAULT_PALETTE","defaultColorProvider","unassignedColors","rnd","color","createDefaultAppearenceProvider","colorProvider","presenceKey","isListEqual","listA","listB","PRESENCE_KEY","createPresenceState","appearanceProvider","presentUsers","selectionStates","addUser","appearance","removeUser","syncUsers","keys","toAdd","toRemove","presentUser","getPresentUsers","notifyActivity","annotationIds","updateSelection","from"],"mappings":"AAAA,IAAIA,IAAM,OAAO,UAAU;AAEpB,SAASC,EAAOC,GAAKC,GAAK;AAChC,MAAIC,GAAMC;AACV,MAAIH,MAAQC;AAAK,WAAO;AAExB,MAAID,KAAOC,MAAQC,IAAKF,EAAI,iBAAiBC,EAAI,aAAa;AAC7D,QAAIC,MAAS;AAAM,aAAOF,EAAI,cAAcC,EAAI;AAChD,QAAIC,MAAS;AAAQ,aAAOF,EAAI,eAAeC,EAAI;AAEnD,QAAIC,MAAS,OAAO;AACnB,WAAKC,IAAIH,EAAI,YAAYC,EAAI;AAC5B,eAAOE,OAASJ,EAAOC,EAAIG,CAAG,GAAGF,EAAIE,CAAG,CAAC;AAAE;AAE5C,aAAOA,MAAQ;AAAA,IACf;AAED,QAAI,CAACD,KAAQ,OAAOF,KAAQ,UAAU;AACrC,MAAAG,IAAM;AACN,WAAKD,KAAQF;AAEZ,YADIF,EAAI,KAAKE,GAAKE,CAAI,KAAK,EAAEC,KAAO,CAACL,EAAI,KAAKG,GAAKC,CAAI,KACnD,EAAEA,KAAQD,MAAQ,CAACF,EAAOC,EAAIE,CAAI,GAAGD,EAAIC,CAAI,CAAC;AAAG,iBAAO;AAE7D,aAAO,OAAO,KAAKD,CAAG,EAAE,WAAWE;AAAA,IACnC;AAAA,EACD;AAED,SAAOH,MAAQA,KAAOC,MAAQA;AAC/B;AC3BO,SAASG,IAAO;AAAE;AA+DlB,SAASC,EAAeC,GAAGC,GAAG;AACpC,SAAOD,KAAKA,IAAIC,KAAKA,IAAID,MAAMC,KAAMD,KAAK,OAAOA,KAAM,YAAa,OAAOA,KAAM;AAClF;ACzDA,MAAME,IAAmB,CAAA;AA0BlB,SAASC,EAASC,G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../../node_modules/svelte/src/runtime/internal/utils.js","../../../node_modules/svelte/src/runtime/store/index.js","../src/state/Hover.ts","../src/state/Selection.ts","../../../node_modules/uuid/dist/esm-browser/stringify.js","../../../node_modules/uuid/dist/esm-browser/rng.js","../../../node_modules/uuid/dist/esm-browser/native.js","../../../node_modules/uuid/dist/esm-browser/v4.js","../src/utils/annotationUtils.ts","../src/utils/diffAnnotations.ts","../src/state/StoreObserver.ts","../src/state/Store.ts","../src/state/SvelteStore.ts","../../../node_modules/nanoevents/index.js","../src/state/UndoStack.ts","../src/state/Viewport.ts","../src/lifecycle/Lifecycle.ts","../src/model/FormatAdapter.ts","../src/model/Annotator.ts","../../../node_modules/nanoid/url-alphabet/index.js","../../../node_modules/nanoid/index.browser.js","../src/model/User.ts","../src/model/W3CAnnotation.ts","../src/presence/ColorPalette.ts","../src/presence/AppearanceProvider.ts","../src/presence/PresenceState.ts"],"sourcesContent":["var has = Object.prototype.hasOwnProperty;\n\nexport function dequal(foo, bar) {\n\tvar ctor, len;\n\tif (foo === bar) return true;\n\n\tif (foo && bar && (ctor=foo.constructor) === bar.constructor) {\n\t\tif (ctor === Date) return foo.getTime() === bar.getTime();\n\t\tif (ctor === RegExp) return foo.toString() === bar.toString();\n\n\t\tif (ctor === Array) {\n\t\t\tif ((len=foo.length) === bar.length) {\n\t\t\t\twhile (len-- && dequal(foo[len], bar[len]));\n\t\t\t}\n\t\t\treturn len === -1;\n\t\t}\n\n\t\tif (!ctor || typeof foo === 'object') {\n\t\t\tlen = 0;\n\t\t\tfor (ctor in foo) {\n\t\t\t\tif (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;\n\t\t\t\tif (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;\n\t\t\t}\n\t\t\treturn Object.keys(bar).length === len;\n\t\t}\n\t}\n\n\treturn foo !== foo && bar !== bar;\n}\n","/** @returns {void} */\nexport function noop() {}\n\nexport const identity = (x) => x;\n\n/**\n * @template T\n * @template S\n * @param {T} tar\n * @param {S} src\n * @returns {T & S}\n */\nexport function assign(tar, src) {\n\t// @ts-ignore\n\tfor (const k in src) tar[k] = src[k];\n\treturn /** @type {T & S} */ (tar);\n}\n\n// Adapted from https://github.com/then/is-promise/blob/master/index.js\n// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE\n/**\n * @param {any} value\n * @returns {value is PromiseLike<any>}\n */\nexport function is_promise(value) {\n\treturn (\n\t\t!!value &&\n\t\t(typeof value === 'object' || typeof value === 'function') &&\n\t\ttypeof (/** @type {any} */ (value).then) === 'function'\n\t);\n}\n\n/** @returns {void} */\nexport function add_location(element, file, line, column, char) {\n\telement.__svelte_meta = {\n\t\tloc: { file, line, column, char }\n\t};\n}\n\nexport function run(fn) {\n\treturn fn();\n}\n\nexport function blank_object() {\n\treturn Object.create(null);\n}\n\n/**\n * @param {Function[]} fns\n * @returns {void}\n */\nexport function run_all(fns) {\n\tfns.forEach(run);\n}\n\n/**\n * @param {any} thing\n * @returns {thing is Function}\n */\nexport function is_function(thing) {\n\treturn typeof thing === 'function';\n}\n\n/** @returns {boolean} */\nexport function safe_not_equal(a, b) {\n\treturn a != a ? b == b : a !== b || (a && typeof a === 'object') || typeof a === 'function';\n}\n\nlet src_url_equal_anchor;\n\n/**\n * @param {string} element_src\n * @param {string} url\n * @returns {boolean}\n */\nexport function src_url_equal(element_src, url) {\n\tif (element_src === url) return true;\n\tif (!src_url_equal_anchor) {\n\t\tsrc_url_equal_anchor = document.createElement('a');\n\t}\n\t// This is actually faster than doing URL(..).href\n\tsrc_url_equal_anchor.href = url;\n\treturn element_src === src_url_equal_anchor.href;\n}\n\n/** @param {string} srcset */\nfunction split_srcset(srcset) {\n\treturn srcset.split(',').map((src) => src.trim().split(' ').filter(Boolean));\n}\n\n/**\n * @param {HTMLSourceElement | HTMLImageElement} element_srcset\n * @param {string | undefined | null} srcset\n * @returns {boolean}\n */\nexport function srcset_url_equal(element_srcset, srcset) {\n\tconst element_urls = split_srcset(element_srcset.srcset);\n\tconst urls = split_srcset(srcset || '');\n\n\treturn (\n\t\turls.length === element_urls.length &&\n\t\turls.every(\n\t\t\t([url, width], i) =>\n\t\t\t\twidth === element_urls[i][1] &&\n\t\t\t\t// We need to test both ways because Vite will create an a full URL with\n\t\t\t\t// `new URL(asset, import.meta.url).href` for the client when `base: './'`, and the\n\t\t\t\t// relative URLs inside srcset are not automatically resolved to absolute URLs by\n\t\t\t\t// browsers (in contrast to img.src). This means both SSR and DOM code could\n\t\t\t\t// contain relative or absolute URLs.\n\t\t\t\t(src_url_equal(element_urls[i][0], url) || src_url_equal(url, element_urls[i][0]))\n\t\t)\n\t);\n}\n\n/** @returns {boolean} */\nexport function not_equal(a, b) {\n\treturn a != a ? b == b : a !== b;\n}\n\n/** @returns {boolean} */\nexport function is_empty(obj) {\n\treturn Object.keys(obj).length === 0;\n}\n\n/** @returns {void} */\nexport function validate_store(store, name) {\n\tif (store != null && typeof store.subscribe !== 'function') {\n\t\tthrow new Error(`'${name}' is not a store with a 'subscribe' method`);\n\t}\n}\n\nexport function subscribe(store, ...callbacks) {\n\tif (store == null) {\n\t\tfor (const callback of callbacks) {\n\t\t\tcallback(undefined);\n\t\t}\n\t\treturn noop;\n\t}\n\tconst unsub = store.subscribe(...callbacks);\n\treturn unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;\n}\n\n/**\n * Get the current value from a store by subscribing and immediately unsubscribing.\n *\n * https://svelte.dev/docs/svelte-store#get\n * @template T\n * @param {import('../store/public.js').Readable<T>} store\n * @returns {T}\n */\nexport function get_store_value(store) {\n\tlet value;\n\tsubscribe(store, (_) => (value = _))();\n\treturn value;\n}\n\n/** @returns {void} */\nexport function component_subscribe(component, store, callback) {\n\tcomponent.$$.on_destroy.push(subscribe(store, callback));\n}\n\nexport function create_slot(definition, ctx, $$scope, fn) {\n\tif (definition) {\n\t\tconst slot_ctx = get_slot_context(definition, ctx, $$scope, fn);\n\t\treturn definition[0](slot_ctx);\n\t}\n}\n\nfunction get_slot_context(definition, ctx, $$scope, fn) {\n\treturn definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx;\n}\n\nexport function get_slot_changes(definition, $$scope, dirty, fn) {\n\tif (definition[2] && fn) {\n\t\tconst lets = definition[2](fn(dirty));\n\t\tif ($$scope.dirty === undefined) {\n\t\t\treturn lets;\n\t\t}\n\t\tif (typeof lets === 'object') {\n\t\t\tconst merged = [];\n\t\t\tconst len = Math.max($$scope.dirty.length, lets.length);\n\t\t\tfor (let i = 0; i < len; i += 1) {\n\t\t\t\tmerged[i] = $$scope.dirty[i] | lets[i];\n\t\t\t}\n\t\t\treturn merged;\n\t\t}\n\t\treturn $$scope.dirty | lets;\n\t}\n\treturn $$scope.dirty;\n}\n\n/** @returns {void} */\nexport function update_slot_base(\n\tslot,\n\tslot_definition,\n\tctx,\n\t$$scope,\n\tslot_changes,\n\tget_slot_context_fn\n) {\n\tif (slot_changes) {\n\t\tconst slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);\n\t\tslot.p(slot_context, slot_changes);\n\t}\n}\n\n/** @returns {void} */\nexport function update_slot(\n\tslot,\n\tslot_definition,\n\tctx,\n\t$$scope,\n\tdirty,\n\tget_slot_changes_fn,\n\tget_slot_context_fn\n) {\n\tconst slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn);\n\tupdate_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn);\n}\n\n/** @returns {any[] | -1} */\nexport function get_all_dirty_from_scope($$scope) {\n\tif ($$scope.ctx.length > 32) {\n\t\tconst dirty = [];\n\t\tconst length = $$scope.ctx.length / 32;\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tdirty[i] = -1;\n\t\t}\n\t\treturn dirty;\n\t}\n\treturn -1;\n}\n\n/** @returns {{}} */\nexport function exclude_internal_props(props) {\n\tconst result = {};\n\tfor (const k in props) if (k[0] !== '$') result[k] = props[k];\n\treturn result;\n}\n\n/** @returns {{}} */\nexport function compute_rest_props(props, keys) {\n\tconst rest = {};\n\tkeys = new Set(keys);\n\tfor (const k in props) if (!keys.has(k) && k[0] !== '$') rest[k] = props[k];\n\treturn rest;\n}\n\n/** @returns {{}} */\nexport function compute_slots(slots) {\n\tconst result = {};\n\tfor (const key in slots) {\n\t\tresult[key] = true;\n\t}\n\treturn result;\n}\n\n/** @returns {(this: any, ...args: any[]) => void} */\nexport function once(fn) {\n\tlet ran = false;\n\treturn function (...args) {\n\t\tif (ran) return;\n\t\tran = true;\n\t\tfn.call(this, ...args);\n\t};\n}\n\nexport function null_to_empty(value) {\n\treturn value == null ? '' : value;\n}\n\nexport function set_store_value(store, ret, value) {\n\tstore.set(value);\n\treturn ret;\n}\n\nexport const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);\n\nexport function action_destroyer(action_result) {\n\treturn action_result && is_function(action_result.destroy) ? action_result.destroy : noop;\n}\n\n/** @param {number | string} value\n * @returns {[number, string]}\n */\nexport function split_css_unit(value) {\n\tconst split = typeof value === 'string' && value.match(/^\\s*(-?[\\d.]+)([^\\s]*)\\s*$/);\n\treturn split ? [parseFloat(split[1]), split[2] || 'px'] : [/** @type {number} */ (value), 'px'];\n}\n\nexport const contenteditable_truthy_values = ['', true, 1, 'true', 'contenteditable'];\n","import {\n\trun_all,\n\tsubscribe,\n\tnoop,\n\tsafe_not_equal,\n\tis_function,\n\tget_store_value\n} from '../internal/index.js';\n\nconst subscriber_queue = [];\n\n/**\n * Creates a `Readable` store that allows reading by subscription.\n *\n * https://svelte.dev/docs/svelte-store#readable\n * @template T\n * @param {T} [value] initial value\n * @param {import('./public.js').StartStopNotifier<T>} [start]\n * @returns {import('./public.js').Readable<T>}\n */\nexport function readable(value, start) {\n\treturn {\n\t\tsubscribe: writable(value, start).subscribe\n\t};\n}\n\n/**\n * Create a `Writable` store that allows both updating and reading by subscription.\n *\n * https://svelte.dev/docs/svelte-store#writable\n * @template T\n * @param {T} [value] initial value\n * @param {import('./public.js').StartStopNotifier<T>} [start]\n * @returns {import('./public.js').Writable<T>}\n */\nexport function writable(value, start = noop) {\n\t/** @type {import('./public.js').Unsubscriber} */\n\tlet stop;\n\t/** @type {Set<import('./private.js').SubscribeInvalidateTuple<T>>} */\n\tconst subscribers = new Set();\n\t/** @param {T} new_value\n\t * @returns {void}\n\t */\n\tfunction set(new_value) {\n\t\tif (safe_not_equal(value, new_value)) {\n\t\t\tvalue = new_value;\n\t\t\tif (stop) {\n\t\t\t\t// store is ready\n\t\t\t\tconst run_queue = !subscriber_queue.length;\n\t\t\t\tfor (const subscriber of subscribers) {\n\t\t\t\t\tsubscriber[1]();\n\t\t\t\t\tsubscriber_queue.push(subscriber, value);\n\t\t\t\t}\n\t\t\t\tif (run_queue) {\n\t\t\t\t\tfor (let i = 0; i < subscriber_queue.length; i += 2) {\n\t\t\t\t\t\tsubscriber_queue[i][0](subscriber_queue[i + 1]);\n\t\t\t\t\t}\n\t\t\t\t\tsubscriber_queue.length = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @param {import('./public.js').Updater<T>} fn\n\t * @returns {void}\n\t */\n\tfunction update(fn) {\n\t\tset(fn(value));\n\t}\n\n\t/**\n\t * @param {import('./public.js').Subscriber<T>} run\n\t * @param {import('./private.js').Invalidator<T>} [invalidate]\n\t * @returns {import('./public.js').Unsubscriber}\n\t */\n\tfunction subscribe(run, invalidate = noop) {\n\t\t/** @type {import('./private.js').SubscribeInvalidateTuple<T>} */\n\t\tconst subscriber = [run, invalidate];\n\t\tsubscribers.add(subscriber);\n\t\tif (subscribers.size === 1) {\n\t\t\tstop = start(set, update) || noop;\n\t\t}\n\t\trun(value);\n\t\treturn () => {\n\t\t\tsubscribers.delete(subscriber);\n\t\t\tif (subscribers.size === 0 && stop) {\n\t\t\t\tstop();\n\t\t\t\tstop = null;\n\t\t\t}\n\t\t};\n\t}\n\treturn { set, update, subscribe };\n}\n\n/**\n * Derived value store by synchronizing one or more readable stores and\n * applying an aggregation function over its input values.\n *\n * https://svelte.dev/docs/svelte-store#derived\n * @template {import('./private.js').Stores} S\n * @template T\n * @overload\n * @param {S} stores - input stores\n * @param {(values: import('./private.js').StoresValues<S>, set: (value: T) => void, update: (fn: import('./public.js').Updater<T>) => void) => import('./public.js').Unsubscriber | void} fn - function callback that aggregates the values\n * @param {T} [initial_value] - initial value\n * @returns {import('./public.js').Readable<T>}\n */\n\n/**\n * Derived value store by synchronizing one or more readable stores and\n * applying an aggregation function over its input values.\n *\n * https://svelte.dev/docs/svelte-store#derived\n * @template {import('./private.js').Stores} S\n * @template T\n * @overload\n * @param {S} stores - input stores\n * @param {(values: import('./private.js').StoresValues<S>) => T} fn - function callback that aggregates the values\n * @param {T} [initial_value] - initial value\n * @returns {import('./public.js').Readable<T>}\n */\n\n/**\n * @template {import('./private.js').Stores} S\n * @template T\n * @param {S} stores\n * @param {Function} fn\n * @param {T} [initial_value]\n * @returns {import('./public.js').Readable<T>}\n */\nexport function derived(stores, fn, initial_value) {\n\tconst single = !Array.isArray(stores);\n\t/** @type {Array<import('./public.js').Readable<any>>} */\n\tconst stores_array = single ? [stores] : stores;\n\tif (!stores_array.every(Boolean)) {\n\t\tthrow new Error('derived() expects stores as input, got a falsy value');\n\t}\n\tconst auto = fn.length < 2;\n\treturn readable(initial_value, (set, update) => {\n\t\tlet started = false;\n\t\tconst values = [];\n\t\tlet pending = 0;\n\t\tlet cleanup = noop;\n\t\tconst sync = () => {\n\t\t\tif (pending) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcleanup();\n\t\t\tconst result = fn(single ? values[0] : values, set, update);\n\t\t\tif (auto) {\n\t\t\t\tset(result);\n\t\t\t} else {\n\t\t\t\tcleanup = is_function(result) ? result : noop;\n\t\t\t}\n\t\t};\n\t\tconst unsubscribers = stores_array.map((store, i) =>\n\t\t\tsubscribe(\n\t\t\t\tstore,\n\t\t\t\t(value) => {\n\t\t\t\t\tvalues[i] = value;\n\t\t\t\t\tpending &= ~(1 << i);\n\t\t\t\t\tif (started) {\n\t\t\t\t\t\tsync();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tpending |= 1 << i;\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\t\tstarted = true;\n\t\tsync();\n\t\treturn function stop() {\n\t\t\trun_all(unsubscribers);\n\t\t\tcleanup();\n\t\t\t// We need to set this to false because callbacks can still happen despite having unsubscribed:\n\t\t\t// Callbacks might already be placed in the queue which doesn't know it should no longer\n\t\t\t// invoke this derived store.\n\t\t\tstarted = false;\n\t\t};\n\t});\n}\n\n/**\n * Takes a store and returns a new one derived from the old one that is readable.\n *\n * https://svelte.dev/docs/svelte-store#readonly\n * @template T\n * @param {import('./public.js').Readable<T>} store - store to make readonly\n * @returns {import('./public.js').Readable<T>}\n */\nexport function readonly(store) {\n\treturn {\n\t\tsubscribe: store.subscribe.bind(store)\n\t};\n}\n\nexport { get_store_value as get };\n","import { writable } from 'svelte/store';\nimport type { Annotation } from '../model';\nimport type { Store } from './Store';\n\nexport type HoverState<T extends Annotation> = ReturnType<typeof createHoverState<T>>;\n\nexport const createHoverState = <T extends Annotation>(store: Store<T>) => {\n\n const { subscribe, set } = writable<string | undefined>();\n\n let currentHover: string | undefined;\n\n subscribe(updated => currentHover = updated);\n\n // Track store delete and update events\n store.observe(( { changes }) => { \n if (currentHover) {\n const isDeleted = (changes.deleted || []).some(a => a.id === currentHover);\n if (isDeleted)\n set(undefined);\n \n const updated = (changes.updated || []).find(({ oldValue }) => oldValue.id === currentHover);\n if (updated)\n set(updated.newValue.id);\n }\n });\n\n return { \n get current() { return currentHover },\n subscribe, \n set \n };\n\n}\n","import { writable } from 'svelte/store';\nimport type { Annotation } from '../model';\nimport type { Store } from './Store';\n \nexport type Selection = {\n\n selected: { id: string, editable?: boolean }[],\n\n pointerEvent?: PointerEvent;\n\n}\n\nexport type SelectionState<T extends Annotation> = ReturnType<typeof createSelectionState<T>>;\n\nexport enum PointerSelectAction {\n\n EDIT = 'EDIT', // Make annotation target(s) editable on pointer select\n \n SELECT = 'SELECT', // Just select, but don't make editable\n\n NONE = 'NONE' // Click won't select - annotation is completely inert\n\n}\n\nconst EMPTY: Selection = { selected: [] };\n\nexport const createSelectionState = <T extends Annotation>(\n store: Store<T>,\n selectAction: PointerSelectAction | ((a: T) => PointerSelectAction) = PointerSelectAction.EDIT\n) => {\n const { subscribe, set } = writable<Selection>(EMPTY);\n\n let currentSelection: Selection = EMPTY;\n\n subscribe(updated => currentSelection = updated);\n\n const clear = () => set(EMPTY);\n\n const isEmpty = () => currentSelection.selected?.length === 0;\n\n const isSelected = (annotationOrId: T | string) => {\n if (currentSelection.selected.length === 0)\n return false;\n\n const id = typeof annotationOrId === 'string' ? annotationOrId : annotationOrId.id;\n return currentSelection.selected.some(i => i.id === id);\n }\n\n // TODO enable CTRL select\n const clickSelect = (id: string, pointerEvent: PointerEvent) => {\n const annotation = store.getAnnotation(id);\n if (annotation) {\n const action = onPointerSelect(annotation, selectAction);\n if (action === PointerSelectAction.EDIT)\n set({ selected: [{ id, editable: true }], pointerEvent }); \n else if (action === PointerSelectAction.SELECT)\n set({ selected: [{ id }], pointerEvent }); \n else\n set({ selected: [], pointerEvent });\n } else {\n console.warn('Invalid selection: ' + id);\n }\n }\n\n const setSelected = (idOrIds: string | string[], editable?: boolean) => {\n const ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];\n\n // Remove invalid\n const annotations = \n ids.map(id => store.getAnnotation(id)!).filter(Boolean); \n\n set({ \n selected: annotations.map(annotation => { \n // If editable is not set, use default behavior\n const isEditable = editable === undefined\n ? onPointerSelect(annotation, selectAction) === PointerSelectAction.EDIT\n : editable;\n\n return { id: annotation.id, editable: isEditable }\n })\n });\n \n if (annotations.length !== ids.length)\n console.warn('Invalid selection', idOrIds);\n }\n\n const removeFromSelection = (ids: string[]) => {\n if (currentSelection.selected.length === 0)\n return false;\n\n const { selected } = currentSelection;\n\n // Checks which of the given annotations are actually in the selection\n const toRemove = selected.filter(({ id }) => ids.includes(id))\n\n if (toRemove.length > 0)\n set({ selected: selected.filter(({ id }) => !ids.includes(id)) });\n }\n\n // Track store delete and update events\n store.observe(({ changes }) =>\n removeFromSelection((changes.deleted || []).map(a => a.id)));\n\n return { \n clear, \n clickSelect, \n get selected() { return currentSelection ? [...currentSelection.selected ] : null},\n get pointerEvent() { return currentSelection ? currentSelection.pointerEvent : null },\n isEmpty, \n isSelected, \n setSelected, \n subscribe \n };\n\n}\n\nexport const onPointerSelect = <T extends Annotation>(\n annotation: T, \n action?: PointerSelectAction | ((a: T) => PointerSelectAction)\n): PointerSelectAction => (typeof action === 'function') ?\n (action(annotation) || PointerSelectAction.EDIT) : \n (action || PointerSelectAction.EDIT);\n","import validate from './validate.js';\n\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\nvar byteToHex = [];\nfor (var i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n //\n // Note to future-self: No, you can't remove the `toLowerCase()` call.\n // REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351\n return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n var uuid = unsafeStringify(arr, offset);\n // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;","// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\n\nvar getRandomValues;\nvar rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n return getRandomValues(rnds8);\n}","var randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);\nexport default {\n randomUUID\n};","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n var rnds = options.random || (options.rng || rng)();\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buf) {\n offset = offset || 0;\n for (var i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;","import { v4 as uuidv4 } from 'uuid';\nimport type { Annotation, AnnotationBody } from '../model/Annotation';\nimport type { User } from '../model/User';\n/**\n * Returns all users listed as creators or updaters in any parts of this\n * annotation.\n */\nexport const getContributors = (annotation: Annotation): User[] => {\n const { creator, updatedBy } = annotation.target;\n\n const bodyCollaborators = annotation.bodies.reduce((users, body) => (\n [...users, body.creator, body.updatedBy].filter(Boolean) as User[]\n ), [] as User[]);\n\n return [\n creator,\n updatedBy,\n ...bodyCollaborators\n ].filter(u => u) as User[] // Remove undefined\n}\n\nexport const createBody = (\n annotation: Annotation, \n payload: { [key: string]: any },\n created?: Date,\n creator?: User\n): AnnotationBody => ({\n id: uuidv4(),\n annotation: annotation.id,\n created: created || new Date(),\n creator,\n ...payload\n});","import { dequal } from 'dequal/lite';\nimport type { Update } from '../state/StoreObserver';\nimport type { Annotation } from '../model/Annotation';\n\nconst getAddedBodies = (oldValue: Annotation, newValue: Annotation) => {\n const oldBodyIds = new Set(oldValue.bodies.map(b => b.id));\n return newValue.bodies.filter(b => !oldBodyIds.has(b.id));\n}\n\nconst getRemovedBodies = (oldValue: Annotation, newValue: Annotation) => {\n const newBodyIds = new Set(newValue.bodies.map(b => b.id));\n return oldValue.bodies.filter(b => !newBodyIds.has(b.id));\n}\n\nconst getChangedBodies = (oldValue: Annotation, newValue: Annotation) => \n newValue.bodies\n .map(newBody => {\n const oldBody = oldValue.bodies.find(b => b.id === newBody.id);\n return { newBody, oldBody: oldBody && !dequal(oldBody, newBody) ? oldBody : undefined }\n })\n .filter(({ oldBody }) => oldBody)\n .map(({ oldBody, newBody }) => ({ oldBody: oldBody!, newBody }));\n\nconst hasTargetChanged = (oldValue: Annotation, newValue: Annotation) => \n !dequal(oldValue.target, newValue.target);\n\nexport const diffAnnotations = <T extends Annotation = Annotation>(oldValue: T, newValue: T): Update<T> => {\n const bodiesCreated = getAddedBodies(oldValue, newValue);\n const bodiesDeleted = getRemovedBodies(oldValue, newValue);\n const bodiesUpdated = getChangedBodies(oldValue, newValue);\n\n return {\n oldValue, \n newValue,\n bodiesCreated: bodiesCreated.length > 0 ? bodiesCreated : undefined,\n bodiesDeleted: bodiesDeleted.length > 0 ? bodiesDeleted : undefined,\n bodiesUpdated: bodiesUpdated.length > 0 ? bodiesUpdated : undefined,\n targetUpdated: hasTargetChanged(oldValue, newValue) ? { oldTarget: oldValue.target, newTarget: newValue.target } : undefined\n }\n}","import type { Annotation, AnnotationBody, AnnotationTarget } from '../model/Annotation';\nimport { diffAnnotations } from '../utils';\n\n/** Interface for listening to changes in the annotation store **/\nexport interface StoreObserver<T extends Annotation> { \n\n onChange: { (event: StoreChangeEvent<T>): void };\n\n options: StoreObserveOptions;\n\n}\n\n/** A change event fired when the store state changes **/\nexport interface StoreChangeEvent<T extends Annotation> {\n\n origin: Origin;\n\n changes: ChangeSet<T>;\n\n state: T[];\n\n}\n\nexport interface ChangeSet<T extends Annotation> {\n\n created?: T[];\n\n deleted?: T[];\n\n updated?: Update<T>[];\n\n}\n\nexport interface Update<T extends Annotation> {\n\n oldValue: T;\n\n newValue: T;\n\n bodiesCreated?: AnnotationBody[];\n\n bodiesDeleted?: AnnotationBody[];\n\n bodiesUpdated?: Array<{ oldBody: AnnotationBody, newBody: AnnotationBody }>;\n\n targetUpdated?: { oldTarget: AnnotationTarget, newTarget: AnnotationTarget};\n\n}\n\n/** Options to control which events the observer wants to get notified about **/\nexport interface StoreObserveOptions {\n\n // Observe changes on targets, bodies or both?\n ignore?: Ignore;\n\n // Observe changes on one more specific annotations\n annotations?: string | string[];\n\n // Observer changes only for a specific origin\n origin?: Origin\n\n}\n\n/** Allows the observer to ignore certain event types **/\nexport enum Ignore { \n\n // Don't notify this observer for changes that involve bodies only\n BODY_ONLY = 'BODY_ONLY',\n\n // Don't notify for changes on targets only\n TARGET_ONLY = 'TARGET_ONLY'\n\n}\n\n/** Allows the observer to listen only for events that originated locally or from a remote source **/\nexport enum Origin { \n \n LOCAL = 'LOCAL', \n \n REMOTE = 'REMOTE' \n\n}\n\n/** Tests if this observer should be notified about this event **/\nexport const shouldNotify = <T extends Annotation>(observer: StoreObserver<T>, event: StoreChangeEvent<T>) => {\n const { changes, origin } = event;\n\n const isRelevantOrigin = \n !observer.options.origin || observer.options.origin === origin;\n\n if (!isRelevantOrigin)\n return false;\n\n if (observer.options.ignore) {\n const { ignore } = observer.options;\n\n // Shorthand\n const has = (arg: any[] | undefined) => arg && arg.length > 0;\n\n const hasAnnotationChanges =\n has(changes.created) || has(changes.deleted);\n\n if (!hasAnnotationChanges) {\n const hasBodyChanges =\n changes.updated?.some(u => has(u.bodiesCreated) || has(u.bodiesDeleted) || has(u.bodiesUpdated));\n \n const hasTargetChanges = \n changes.updated?.some(u => u.targetUpdated);\n\n if (ignore === Ignore.BODY_ONLY && hasBodyChanges && !hasTargetChanges)\n return false;\n\n if (ignore === Ignore.TARGET_ONLY && hasTargetChanges && !hasBodyChanges)\n return false;\n }\n }\n\n if (observer.options.annotations) {\n // This observer has a filter set on specific annotations - check affected\n const affectedAnnotations = new Set([\n ...(changes.created || []).map(a => a.id),\n ...(changes.deleted || []).map(a => a.id),\n ...(changes.updated || []).map(({ oldValue }) => oldValue.id)\n ]);\n\n const observed = Array.isArray(observer.options.annotations) ?\n observer.options.annotations : [ observer.options.annotations ];\n\n return Boolean(observed.find(id => affectedAnnotations.has(id)));\n } else {\n return true;\n }\n\n}\n\nexport const mergeChanges = <T extends Annotation>(changes: ChangeSet<T>, toMerge: ChangeSet<T>) => {\n const previouslyCreatedIds = new Set((changes.created || []).map(a => a.id));\n const previouslyUpdatedIds = new Set((changes.updated || []).map(({ newValue })=> newValue.id));\n\n const createdIds = new Set((toMerge.created || []).map(a => a.id));\n const deletedIds = new Set((toMerge.deleted || []).map(a => a.id));\n const updatedIds = new Set((toMerge.updated || []).map(({ oldValue }) => oldValue.id));\n\n // Updates that will be merged into create or previous update events\n const mergeableUpdates = new Set((toMerge.updated || [])\n .filter(({ oldValue }) => previouslyCreatedIds.has(oldValue.id) || previouslyUpdatedIds.has(oldValue.id))\n .map(({ oldValue }) => oldValue.id ));\n\n // * created *\n // - drop created that were then deleted\n // - merge any updates on created\n // - append newly created\n const created = [\n ...(changes.created || [])\n .filter(a => !deletedIds.has(a.id))\n .map(a => updatedIds.has(a.id) \n ? toMerge.updated!.find(({ oldValue }) => oldValue.id === a.id)!.newValue\n : a),\n ...(toMerge.created || [])\n ];\n\n // * deleted *\n // - drop deleted that were later re-created (redo action!)\n // - append newly deleted, but remove any that delete annotations \n // that were created in the same round\n const deleted = [\n ...(changes.deleted || [])\n .filter(a => !createdIds.has(a.id)),\n ...(toMerge.deleted || []) \n .filter(a => !previouslyCreatedIds.has(a.id))\n ] \n\n // * updated *\n // - drop updates on deleted annotations\n // - merge any updates that override previous ones\n // - append new updates, but remove any that were merged\n const updated = [\n ...(changes.updated || [])\n .filter(({ newValue }) => !deletedIds.has(newValue.id))\n .map(update => {\n const { oldValue, newValue } = update;\n if (updatedIds.has(newValue.id)) {\n const updated = toMerge.updated!.find(u => u.oldValue.id === newValue.id)!.newValue;\n return diffAnnotations(oldValue, updated);\n } else {\n return update;\n }\n }),\n ...(toMerge.updated || []).filter(({ oldValue }) => !mergeableUpdates.has(oldValue.id))\n ]\n\n return { created, deleted, updated };\n}","import type { Annotation } from '../model';\nimport { diffAnnotations } from '../utils';\nimport { Origin, shouldNotify, type Update, type ChangeSet } from './StoreObserver';\nimport type { StoreObserver, StoreChangeEvent, StoreObserveOptions } from './StoreObserver';\n\n// Shorthand\ntype AnnotationBodyIdentifier = { id: string, annotation: string }; \n\nexport type Store<T extends Annotation> = ReturnType<typeof createStore<T>>;\n\nconst isAnnotation = <T extends Annotation>(arg: any): arg is T => arg.id !== undefined;\n\nexport const createStore = <T extends Annotation>() => {\n\n const annotationIndex = new Map<string, T>();\n\n const bodyIndex = new Map<string, string>();\n\n const observers: StoreObserver<T>[] = [];\n\n const observe = (onChange: { (event: StoreChangeEvent<T>): void }, options: StoreObserveOptions = {}) =>\n observers.push({ onChange, options });\n\n const unobserve = (onChange: { (event: StoreChangeEvent<T>): void }) => {\n const idx = observers.findIndex(observer => observer.onChange == onChange);\n if (idx > -1)\n observers.splice(idx, 1);\n }\n\n const emit = (origin: Origin, changes: ChangeSet<T>) => {\n const event: StoreChangeEvent<T> = {\n origin,\n changes: {\n created: changes.created || [],\n updated: changes.updated || [],\n deleted: changes.deleted || []\n },\n state: [...annotationIndex.values()]\n };\n\n observers.forEach(observer => {\n if (shouldNotify(observer, event))\n observer.onChange(event);\n });\n }\n\n const addAnnotation = (annotation: T, origin = Origin.LOCAL) => {\n const existing = annotationIndex.get(annotation.id);\n\n if (existing) {\n throw Error(`Cannot add annotation ${annotation.id} - exists already`);\n } else {\n annotationIndex.set(annotation.id, annotation);\n\n annotation.bodies.forEach(b => bodyIndex.set(b.id, annotation.id));\n emit(origin, { created: [annotation] });\n }\n }\n\n const updateOneAnnotation = (arg1: string | T, arg2?: T | Origin) => {\n const updated: T = typeof arg1 === 'string' ? arg2 as T : arg1;\n\n const oldId: string = typeof arg1 === 'string' ? arg1 : arg1.id;\n const oldValue = annotationIndex.get(oldId);\n\n if (oldValue) {\n const update: Update<T> = diffAnnotations(oldValue, updated);\n\n if (oldId === updated.id) {\n annotationIndex.set(oldId, updated);\n } else {\n annotationIndex.delete(oldId);\n annotationIndex.set(updated.id, updated);\n }\n\n oldValue.bodies.forEach(b => bodyIndex.delete(b.id));\n updated.bodies.forEach(b => bodyIndex.set(b.id, updated.id));\n\n return update;\n } else {\n console.warn(`Cannot update annotation ${oldId} - does not exist`);\n }\n }\n \n const updateAnnotation = (arg1: string | T, arg2: T | Origin = Origin.LOCAL, arg3 = Origin.LOCAL) => {\n const origin: Origin = isAnnotation(arg2) ? arg3 : arg2;\n\n const update = updateOneAnnotation(arg1, arg2);\n if (update)\n emit(origin, { updated: [update] })\n }\n\n const bulkUpdateAnnotation = (annotations: T[], origin = Origin.LOCAL) => {\n const updated = annotations.reduce((updated, annotation) => {\n const u = updateOneAnnotation(annotation);\n return u ? [...updated, u] : updated;\n }, [] as Update<T>[]);\n\n if (updated.length > 0)\n emit(origin, { updated });\n }\n\n const addBody = (body: T['bodies'][number], origin = Origin.LOCAL) => {\n const oldValue = annotationIndex.get(body.annotation);\n if (oldValue) {\n const newValue = { \n ...oldValue,\n bodies: [ ...oldValue.bodies, body ]\n };\n\n annotationIndex.set(oldValue.id, newValue);\n\n bodyIndex.set(body.id, newValue.id);\n\n const update: Update<T> = {\n oldValue, newValue, bodiesCreated: [ body ]\n };\n\n emit(origin, { updated: [update] });\n } else {\n console.warn(`Attempt to add body to missing annotation: ${body.annotation}`);\n }\n }\n\n const all = () => [...annotationIndex.values()];\n\n const clear = (origin = Origin.LOCAL) => { \n const all = [...annotationIndex.values()];\n\n annotationIndex.clear();\n bodyIndex.clear();\n\n emit(origin, { deleted: all });\n }\n\n const bulkAddAnnotation = (annotations: T[], replace = true, origin = Origin.LOCAL) => {\n if (replace) {\n // Delete existing first\n const deleted = [...annotationIndex.values()];\n annotationIndex.clear();\n bodyIndex.clear();\n\n annotations.forEach(annotation => {\n annotationIndex.set(annotation.id, annotation);\n annotation.bodies.forEach(b => bodyIndex.set(b.id, annotation.id));\n });\n\n emit(origin, { created: annotations, deleted });\n } else {\n // Don't allow overwriting of existing annotations\n const existing = annotations.reduce((all, next) => {\n const existing = annotationIndex.get(next.id);\n return existing ? [...all, existing ] : all;\n }, [] as T[]);\n\n if (existing.length > 0)\n throw Error(`Bulk insert would overwrite the following annotations: ${existing.map(a => a.id).join(', ')}`);\n\n annotations.forEach(annotation => {\n annotationIndex.set(annotation.id, annotation);\n annotation.bodies.forEach(b => bodyIndex.set(b.id, annotation.id));\n });\n\n emit(origin, { created: annotations });\n }\n }\n\n const deleteOneAnnotation = (annotationOrId: T | string) => {\n const id = typeof annotationOrId === 'string' ? annotationOrId : annotationOrId.id;\n\n const existing = annotationIndex.get(id);\n if (existing) {\n annotationIndex.delete(id);\n existing.bodies.forEach(b => bodyIndex.delete(b.id));\n return existing;\n } else {\n console.warn(`Attempt to delete missing annotation: ${id}`);\n }\n }\n\n const deleteAnnotation = (annotationOrId: T | string, origin = Origin.LOCAL) => {\n const deleted = deleteOneAnnotation(annotationOrId);\n if (deleted)\n emit(origin, { deleted: [ deleted ]});\n }\n\n const bulkDeleteAnnotation = (annotationsOrIds: (T | string)[], origin = Origin.LOCAL) => {\n const deleted = annotationsOrIds.reduce((deleted, arg) => {\n const existing = deleteOneAnnotation(arg);\n return existing ? [...deleted, existing] : deleted;\n }, [] as T[]);\n\n if (deleted.length > 0)\n emit(origin, { deleted });\n }\n\n const deleteOneBody = (body: AnnotationBodyIdentifier) => {\n const oldAnnotation = annotationIndex.get(body.annotation);\n\n if (oldAnnotation) {\n const oldBody = oldAnnotation.bodies.find(b => b.id === body.id);\n\n if (oldBody) {\n bodyIndex.delete(oldBody.id);\n\n const newAnnotation = {\n ...oldAnnotation,\n bodies: oldAnnotation.bodies.filter(b => b.id !== body.id)\n };\n\n annotationIndex.set(oldAnnotation.id, newAnnotation);\n\n const update: Update<T> = {\n oldValue: oldAnnotation, newValue: newAnnotation, bodiesDeleted: [oldBody]\n };\n\n return update;\n } else {\n console.warn(`Attempt to delete missing body ${body.id} from annotation ${body.annotation}`);\n }\n } else {\n console.warn(`Attempt to delete body from missing annotation ${body.annotation}`);\n }\n }\n \n const deleteBody = (body: AnnotationBodyIdentifier, origin = Origin.LOCAL) => {\n const updated = deleteOneBody(body);\n if (updated)\n emit(origin, { updated: [ updated ]});\n }\n\n const bulkDeleteBodies = (bodies: AnnotationBodyIdentifier[], origin = Origin.LOCAL) => {\n const updated = bodies\n .map(b => deleteOneBody(b)!)\n .filter(Boolean);\n\n if (updated.length > 0)\n emit(origin, { updated });\n }\n\n const getAnnotation = (id: string): T | undefined => {\n const a = annotationIndex.get(id);\n return a ? {...a} : undefined;\n }\n\n const getBody = (id: string): T['bodies'][number] | undefined => {\n const annotationId = bodyIndex.get(id);\n if (annotationId) {\n const annotation = getAnnotation(annotationId);\n const body = annotation!.bodies.find(b => b.id === id);\n if (body) {\n return body;\n } else {\n console.error(`Store integrity error: body ${id} in index, but not in annotation`);\n }\n } else {\n console.warn(`Attempt to retrieve missing body: ${id}`);\n }\n }\n\n const updateOneBody = (oldBodyId: AnnotationBodyIdentifier, newBody: T['bodies'][number]) => {\n if (oldBodyId.annotation !== newBody.annotation)\n throw 'Annotation integrity violation: annotation ID must be the same when updating bodies';\n\n const oldAnnotation = annotationIndex.get(oldBodyId.annotation);\n if (oldAnnotation) {\n const oldBody = oldAnnotation.bodies.find(b => b.id === oldBodyId.id)!;\n\n const newAnnotation = { \n ...oldAnnotation,\n bodies: oldAnnotation.bodies.map(b => b.id === oldBody.id ? newBody : b)\n };\n\n annotationIndex.set(oldAnnotation.id, newAnnotation);\n\n if (oldBody.id !== newBody.id) {\n bodyIndex.delete(oldBody.id);\n bodyIndex.set(newBody.id, newAnnotation.id);\n }\n\n return {\n oldValue: oldAnnotation, \n newValue: newAnnotation,\n bodiesUpdated: [{ oldBody, newBody }]\n }\n } else {\n console.warn(`Attempt to add body to missing annotation ${oldBodyId.annotation}`);\n }\n }\n\n const updateBody = (oldBodyId: AnnotationBodyIdentifier, newBody: T['bodies'][number], origin = Origin.LOCAL) => {\n const update = updateOneBody(oldBodyId, newBody);\n if (update)\n emit(origin, { updated: [ update ]} );\n }\n\n const bulkUpdateBodies = (bodies: Array<T['bodies'][number]>, origin = Origin.LOCAL) => {\n const updated = bodies\n .map(b => updateOneBody({ id: b.id, annotation: b.annotation }, b)!)\n .filter(Boolean);\n\n emit(origin, { updated });\n }\n\n const updateOneTarget = (target: T['target']): Update<T> | undefined => {\n const oldValue = annotationIndex.get(target.annotation);\n \n if (oldValue) {\n const newValue = { \n ...oldValue, \n target: {\n ...oldValue.target,\n ...target \n }\n };\n\n annotationIndex.set(oldValue.id, newValue);\n\n return {\n oldValue, newValue, targetUpdated: { \n oldTarget: oldValue.target,\n newTarget: target\n }\n };\n } else {\n console.warn(`Attempt to update target on missing annotation: ${target.annotation}`);\n }\n }\n\n const updateTarget = (target: T['target'], origin = Origin.LOCAL) => {\n const update = updateOneTarget(target);\n if (update)\n emit(origin, { updated: [ update ]} );\n }\n\n const bulkUpdateTargets = (targets: Array<T['target']>, origin = Origin.LOCAL) => {\n const updated = \n targets.map(t => updateOneTarget(t)!).filter(Boolean);\n if (updated.length > 0)\n emit(origin, { updated });\n }\n\n\treturn {\n addAnnotation,\n addBody,\n all,\n bulkAddAnnotation,\n bulkDeleteAnnotation,\n bulkDeleteBodies,\n bulkUpdateAnnotation,\n bulkUpdateBodies,\n bulkUpdateTargets,\n clear,\n deleteAnnotation,\n deleteBody,\n getAnnotation,\n getBody,\n observe,\n unobserve,\n updateAnnotation,\n updateBody,\n updateTarget\n\t};\n\n}\n","import type { Annotation, Annotator, AnnotatorState } from '../model';\nimport type { Store } from './Store';\nimport type { StoreChangeEvent } from './StoreObserver';\n\ntype Subscriber<T extends Annotation> = (annotation: T[]) => void; \n\nexport interface SvelteStore<T extends Annotation> extends Store<T> {\n\n subscribe(onChange: Subscriber<T>): void;\n\n}\n\nexport interface SvelteAnnotatorState<T extends Annotation> extends AnnotatorState<T> {\n\n store: SvelteStore<T>\n\n}\n\nexport interface SvelteAnnotator<T extends Annotation> extends Annotator<T> {\n\n state: SvelteAnnotatorState<T>\n\n}\n\n/** \n * A simple wrapper around the event-based store implementation\n * that adds a Svelte shim, for use with the reactive '$' notation.\n * Other frameworks might not actually need this. But it's pretty\n * convenient for everyone using Svelte, as well as for the\n * basic (Svelte-based) Annotorious standard implementation.\n */\nexport const toSvelteStore = <T extends Annotation>(store: Store<T>): SvelteStore<T> => {\n\n const subscribe = (onChange: Subscriber<T>) => {\n\n // Register a store observer on behalf of the subscriber\n const shim = (event: StoreChangeEvent<T>) => onChange(event.state);\n store.observe(shim);\n\n // Immediately call the subscriber function with the\n // current store value, according to the Svelte contract.\n // https://stackoverflow.com/questions/68220955/how-does-svelte-unsubscribe-actually-work\n onChange(store.all());\n\n // Return the unsubscribe function\n return () => store.unobserve(shim);\n }\n\n return {\n ...store,\n subscribe\n }\n\n}","export let createNanoEvents = () => ({\n emit(event, ...args) {\n for (\n let i = 0,\n callbacks = this.events[event] || [],\n length = callbacks.length;\n i < length;\n i++\n ) {\n callbacks[i](...args)\n }\n },\n events: {},\n on(event, cb) {\n ;(this.events[event] ||= []).push(cb)\n return () => {\n this.events[event] = this.events[event]?.filter(i => cb !== i)\n }\n }\n})\n","import { createNanoEvents, type Unsubscribe } from 'nanoevents';\nimport { v4 as uuidv4 } from 'uuid';\nimport type { Annotation } from '../model';\nimport type { Store } from './Store';\nimport { Origin } from './StoreObserver';\nimport { mergeChanges, type ChangeSet, type StoreChangeEvent, type Update } from './StoreObserver';\n\n// Duration with fast successive changes get merged \n// with the last event in the stack, rather than getting stacked\n// as a new undo/redo step.\nconst DEBOUNCE = 250;\n\nexport interface UndoStack <T extends Annotation> {\n\n canRedo(): boolean;\n\n canUndo(): boolean;\n\n destroy(): void;\n\n on<E extends keyof UndoStackEvents<T>>(event: E, callback: UndoStackEvents<T>[E]): Unsubscribe;\n\n undo(): void;\n\n redo(): void;\n\n}\n\nexport interface UndoStackEvents <T extends Annotation> {\n\n redo(change: ChangeSet<T>): void;\n\n undo(change: ChangeSet<T>): void;\n\n}\n\nexport const createUndoStack = <T extends Annotation>(store: Store<T>): UndoStack<T> => {\n\n const emitter = createNanoEvents<UndoStackEvents<T>>();\n\n const changeStack: ChangeSet<T>[] = [];\n\n let pointer = -1;\n\n let muteEvents = false;\n\n let lastEvent = 0;\n\n const onChange = (event: StoreChangeEvent<T>) => {\n if (!muteEvents) {\n const { changes } = event;\n\n const now = performance.now();\n\n if (now - lastEvent > DEBOUNCE) {\n // Put this change on the stack...\n changeStack.splice(pointer + 1);\n changeStack.push(changes);\n\n // ...and update the pointer\n pointer = changeStack.length - 1;\n } else {\n // Merge this change with the last in the stack\n const last = changeStack.length - 1;\n changeStack[last] = mergeChanges(changeStack[last], changes);\n }\n\n lastEvent = now;\n }\n\n muteEvents = false;\n }\n\n store.observe(onChange, { origin: Origin.LOCAL });\n\n const undoCreated = (created?: T[]) =>\n created && created.length > 0 && store.bulkDeleteAnnotation(created);\n\n const redoCreated = (created?: T[]) =>\n created && created.length > 0 && store.bulkAddAnnotation(created, false);\n\n const undoUpdated = (updated?: Update<T>[]) =>\n updated && updated.length > 0 && store.bulkUpdateAnnotation(updated.map(({ oldValue }) => oldValue));\n \n const redoUpdated = (updated?: Update<T>[]) =>\n updated && updated.length > 0 && store.bulkUpdateAnnotation(updated.map(({ newValue }) => newValue));\n\n const undoDeleted = (deleted?: T[]) => \n deleted && deleted.length > 0 && store.bulkAddAnnotation(deleted, false);\n\n const redoDeleted = (deleted?: T[]) =>\n deleted && deleted.length > 0 && store.bulkDeleteAnnotation(deleted);\n\n const undo = () => {\n if (pointer > -1) {\n muteEvents = true;\n\n const { created, updated, deleted } = changeStack[pointer];\n\n undoCreated(created);\n undoUpdated(updated);\n undoDeleted(deleted);\n\n emitter.emit('undo', changeStack[pointer]);\n\n pointer -= 1;\n }\n }\n\n const canUndo = () => pointer > -1;\n\n const redo = () => {\n if (changeStack.length - 1 > pointer) {\n muteEvents = true;\n\n const { created, updated, deleted } = changeStack[pointer + 1];\n\n redoCreated(created);\n redoUpdated(updated);\n redoDeleted(deleted);\n\n emitter.emit('redo', changeStack[pointer + 1]);\n\n pointer += 1;\n }\n }\n\n const canRedo = () => changeStack.length - 1 > pointer;\n\n const destroy = () => store.unobserve(onChange);\n\n const on = <E extends keyof UndoStackEvents<T>>(event: E, callback: UndoStackEvents<T>[E]) => \n emitter.on(event, callback);\n\n return {\n canRedo,\n canUndo,\n destroy,\n on,\n redo,\n undo\n }\n\n}","import { writable } from 'svelte/store';\n\nexport type ViewportState = ReturnType<typeof createViewportState>;\n\nexport const createViewportState = () => {\n\n const { subscribe, set } = writable<string[]>([]);\n\n return { \n subscribe, \n set\n };\n\n}\n","import { dequal } from 'dequal/lite';\nimport type { Annotation, AnnotatorState, FormatAdapter } from '../model';\nimport { Origin, type ChangeSet, type UndoStack } from '../state';\nimport type { LifecycleEvents } from './LifecycleEvents';\n\nexport type Lifecycle<I extends Annotation, E extends unknown> = \n ReturnType<typeof createLifecycleObserver<I, E>>;\n\nexport const createLifecycleObserver = <I extends Annotation, E extends unknown>(\n state: AnnotatorState<I>,\n undoStack: UndoStack<I>,\n adapter?: FormatAdapter<I, E>,\n autoSave?: boolean\n) => {\n const { store, selection, hover, viewport } = state;\n\n const observers: Map<keyof LifecycleEvents, Function[]> = new Map();\n\n // The currently selected annotations, in the state when they were selected \n let initialSelection: I[] = [];\n\n let currentHover: string | undefined;\n\n let idleTimeout: ReturnType<typeof setTimeout>;\n\n const on = <T extends keyof LifecycleEvents>(event: T, callback: LifecycleEvents<E>[T]) => {\n if (observers.has(event)) {\n observers.get(event)!.push(callback);\n } else {\n observers.set(event, [callback]);\n }\n }\n\n const off = <T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]) => {\n const callbacks = observers.get(event);\n if (callbacks) {\n const idx = callbacks.indexOf(callback);\n if (idx !== -1)\n callbacks.splice(idx, 1);\n }\n }\n\n const emit = (event: keyof LifecycleEvents<E>, arg0: I | I[], arg1?: I | PointerEvent) => {\n if (observers.has(event)) {\n setTimeout(() => {\n observers.get(event)!.forEach(callback => { \n if (adapter) {\n const serialized0 = Array.isArray(arg0) ? \n arg0.map(a => adapter.serialize(a)) : adapter.serialize(arg0);\n \n const serialized1: E | PointerEvent | undefined =\n arg1 ? arg1 instanceof PointerEvent ? arg1 : adapter.serialize(arg1) : undefined;\n\n callback(serialized0 as E & E[], serialized1); \n } else {\n callback(arg0 as E & E[], arg1 as unknown as E); \n }\n });\n }, 1);\n }\n }\n\n const onIdleUpdate = () => {\n const { selected } = selection;\n\n // User idle after activity - fire update events for selected\n // annotations that changed\n const updatedSelected = (selected || []).map(({ id }) => store.getAnnotation(id)!);\n\n updatedSelected.forEach(updated => {\n const initial = initialSelection.find(a => a.id === updated.id);\n if (!initial || !dequal(initial, updated)) {\n emit('updateAnnotation', updated, initial);\n }\n });\n\n initialSelection = initialSelection.map(initial => {\n const updated = updatedSelected.find(({ id }) => id === initial.id);\n return updated ? updated : initial\n });\n }\n\n selection.subscribe(({ selected })=> {\n if (initialSelection.length === 0 && selected.length === 0)\n return;\n\n if (initialSelection.length === 0 && selected.length > 0) {\n // A new selection was made - store the editable annotation as initial state\n initialSelection = selected.map(({ id }) => store.getAnnotation(id)!);\n } else if (initialSelection.length > 0 && selected.length === 0) {\n // Deselect!\n initialSelection.forEach(initial => {\n const updatedState = store.getAnnotation(initial.id); \n \n if (updatedState && !dequal(updatedState, initial)) {\n emit('updateAnnotation', updatedState, initial);\n }\n });\n\n initialSelection = [];\n } else {\n // Changed selection\n const initialIds = new Set(initialSelection.map(a => a.id));\n const selectedIds = new Set(selected.map(({ id }) => id));\n\n // Fire update events for deselected annotations that have changed\n const deselected = initialSelection.filter(a => !selectedIds.has(a.id));\n deselected.forEach(initial => {\n const updatedState = store.getAnnotation(initial.id);\n\n if (updatedState && !dequal(updatedState, initial))\n emit('updateAnnotation', updatedState, initial);\n });\n\n initialSelection = [\n // Remove annotations that were deselected\n ...initialSelection.filter(a => selectedIds.has(a.id)),\n // Add editable annotations that were selected\n ...selected\n .filter(({ id }) => !initialIds.has(id))\n .map(({ id }) => store.getAnnotation(id)!)\n ];\n }\n\n emit('selectionChanged', initialSelection);\n });\n\n hover.subscribe(id => {\n if (!currentHover && id) {\n emit('mouseEnterAnnotation', store.getAnnotation(id)!);\n } else if (currentHover && !id) {\n emit('mouseLeaveAnnotation', store.getAnnotation(currentHover)!);\n } else if (currentHover && id) {\n emit('mouseLeaveAnnotation', store.getAnnotation(currentHover)!);\n emit('mouseEnterAnnotation', store.getAnnotation(id)!);\n }\n\n currentHover = id;\n });\n\n viewport?.subscribe(ids => \n emit('viewportIntersect', ids.map(id => store.getAnnotation(id)!)));\n\n store.observe(event => {\n // autoSave option triggers update events on idleness\n if (autoSave) {\n if (idleTimeout)\n clearTimeout(idleTimeout);\n\n idleTimeout = setTimeout(onIdleUpdate, 1000);\n }\n\n // Local CREATE and DELETE events are applied immediately\n const { created, deleted } = event.changes;\n (created || []).forEach(a => emit('createAnnotation', a));\n (deleted || []).forEach(a => emit('deleteAnnotation', a));\n\n // Updates are only applied immediately if they involve body changes\n const updatesWithBody = (event.changes.updated || []).filter(u => [\n ...(u.bodiesCreated || []),\n ...(u.bodiesDeleted || []),\n ...(u.bodiesUpdated || [])\n ].length > 0);\n\n // Emit an update with the new annototation and the stored initial state\n updatesWithBody.forEach(({ oldValue, newValue }) => {\n const initial = initialSelection.find(a => a.id === oldValue.id) || oldValue;\n\n // Record the update as the new last known state\n initialSelection = initialSelection\n .map(a => a.id === oldValue.id ? newValue : a);\n\n emit('updateAnnotation', newValue, initial);\n });\n }, { origin: Origin.LOCAL });\n\n // Track remote changes - these should update the initial state\n store.observe(event => {\n if (initialSelection) {\n const selectedIds = new Set(initialSelection.map(a => a.id));\n\n const relevantUpdates = (event.changes.updated || [])\n .filter(({ newValue }) => selectedIds.has(newValue.id))\n .map(({ newValue }) => newValue);\n\n if (relevantUpdates.length > 0) {\n initialSelection = initialSelection.map(selected => {\n const updated = relevantUpdates.find(updated => updated.id === selected.id);\n return updated ? updated : selected;\n })\n }\n }\n }, { origin: Origin.REMOTE });\n\n const onUndoOrRedo = (undo: boolean) => (changes: ChangeSet<I>) => {\n // Undo/redo of created/delete will cause lifecycle events automatically,\n // but we need to handle udpates specifically!\n const { updated } = changes;\n\n if (undo)\n (updated || []).forEach(t => emit('updateAnnotation', t.oldValue, t.newValue));\n else\n (updated || []).forEach(t => emit('updateAnnotation', t.newValue, t.oldValue));\n }\n\n undoStack.on('undo', onUndoOrRedo(true));\n undoStack.on('redo', onUndoOrRedo(false));\n\n return { on, off, emit }\n\n}\n","import type { Annotation } from './Annotation';\n\nexport interface FormatAdapter<A extends Annotation, T extends unknown> {\n\n parse(serialized: T): ParseResult<A>;\n\n serialize(core: A): T;\n\n}\n\nexport interface ParseResult<A extends Annotation> {\n\n parsed?: A;\n \n error?: Error;\n\n}\n\nexport const serializeAll = \n <A extends Annotation, T extends unknown>(adapter: FormatAdapter<A, T>) =>\n (annotations: A[]) => annotations.map(a => adapter.serialize(a));\n\nexport const parseAll = \n <A extends Annotation, T extends unknown>(adapter: FormatAdapter<A, T>) =>\n (serialized: T[]) => serialized.reduce((result, next) => {\n const { parsed, error } = adapter.parse(next);\n \n return error ? {\n parsed: result.parsed,\n failed: [...result.failed, next ]\n } : parsed ? {\n parsed: [...result.parsed, parsed ],\n failed: result.failed\n } : {\n ...result\n }\n }, { parsed: [] as A[], failed: [] as T[]});\n ","import type { Annotation } from './Annotation';\nimport type { User } from './User';\nimport type { PresenceProvider } from '../presence/PresenceProvider';\nimport { Origin, type HoverState, type SelectionState, type Store, type UndoStack, type ViewportState } from '../state';\nimport type { LifecycleEvents } from '../lifecycle/LifecycleEvents';\nimport { parseAll, type FormatAdapter } from './FormatAdapter';\nimport type { DrawingStyleExpression } from './DrawingStyle';\nimport type { Filter } from './Filter';\n\n/**\n * Base annotator interface\n * @template I - internal core data model\n * @template E - external adapted representation\n */\nexport interface Annotator<I extends Annotation = Annotation, E extends unknown = Annotation> {\n\n addAnnotation(annotation: E): void;\n\n cancelSelected(): void;\n\n canRedo(): boolean;\n\n canUndo(): boolean;\n\n clearAnnotations(): void;\n\n destroy(): void;\n\n getAnnotationById(id: string): E | undefined;\n\n getAnnotations(): E[];\n\n getSelected(): E[];\n\n getUser(): User;\n\n loadAnnotations(url: string, replace?: boolean): Promise<E[]>;\n\n redo(): void;\n\n removeAnnotation(arg: E | string): E | undefined;\n\n setAnnotations(annotations: E[], replace?: boolean): void;\n\n setFilter(filter: Filter | undefined): void;\n\n setPresenceProvider?(provider: PresenceProvider): void;\n\n setSelected(arg?: string | string[], editable?: boolean): void;\n\n setStyle(style: DrawingStyleExpression<I> | undefined): void;\n\n setUser(user: User): void;\n\n setVisible(visible: boolean): void;\n\n undo(): void;\n\n updateAnnotation(annotation: E): E;\n \n on<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;\n\n off<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;\n\n state: AnnotatorState<I>;\n\n}\n\nexport interface AnnotatorState<A extends Annotation> {\n\n store: Store<A>;\n\n selection: SelectionState<A>;\n\n hover: HoverState<A>;\n\n viewport: ViewportState;\n\n}\n\nexport const createBaseAnnotator = <I extends Annotation, E extends unknown>(\n state: AnnotatorState<I>, \n undoStack: UndoStack<I>,\n adapter?: FormatAdapter<I, E>\n) => {\n\n const { store, selection } = state;\n\n const addAnnotation = (annotation: E) => {\n if (adapter) {\n const { parsed, error } = adapter.parse(annotation);\n if (parsed) {\n store.addAnnotation(parsed, Origin.REMOTE);\n } else {\n console.error(error);\n }\n } else {\n store.addAnnotation(annotation as unknown as I, Origin.REMOTE);\n }\n }\n\n const cancelSelected = () => selection.clear();\n\n const clearAnnotations = () => store.clear();\n\n const getAnnotationById = (id: string): E | undefined => {\n const annotation = store.getAnnotation(id);\n return (adapter && annotation) ?\n adapter.serialize(annotation) as E : annotation as unknown as E;\n }\n\n const getAnnotations = () =>\n (adapter ? store.all().map(adapter.serialize) : store.all()) as E[];\n\n const getSelected = () => {\n const selectedIds = selection.selected?.map(s => s.id) || [];\n\n const selected = selectedIds.map(id => store.getAnnotation(id)!).filter(Boolean);\n\n return adapter \n ? selected.map(adapter.serialize) \n : selected as unknown as E[];\n }\n\n const loadAnnotations = (url: string, replace = true) =>\n fetch(url)\n .then((response) => response.json())\n .then((annotations) => {\n setAnnotations(annotations, replace);\n return annotations;\n });\n\n const removeAnnotation = (arg: E | string): E | undefined => {\n if (typeof arg === 'string') {\n const annotation = store.getAnnotation(arg);\n store.deleteAnnotation(arg);\n\n if (annotation)\n return adapter ? adapter.serialize(annotation) : annotation as unknown as E;\n } else {\n const annotation = adapter ? adapter.parse(arg).parsed : (arg as unknown as I);\n\n if (annotation) {\n store.deleteAnnotation(annotation);\n return arg;\n }\n }\n }\n\n const setAnnotations = (annotations: E[], replace = true) => {\n if (adapter) {\n const { parsed, failed } = parseAll(adapter)(annotations);\n\n if (failed.length > 0)\n console.warn(`Discarded ${failed.length} invalid annotations`, failed);\n\n store.bulkAddAnnotation(parsed, replace, Origin.REMOTE);\n } else {\n store.bulkAddAnnotation(annotations as unknown as I[], replace, Origin.REMOTE);\n }\n }\n\n const setSelected = (arg?: string | string[], editable?: boolean) => {\n if (arg) {\n selection.setSelected(arg, editable);\n } else {\n selection.clear();\n }\n }\n\n const updateAnnotation = (updated: E): E => {\n if (adapter) {\n const crosswalked = adapter.parse(updated).parsed!;\n const previous = adapter.serialize(store.getAnnotation(crosswalked.id)!);\n store.updateAnnotation(crosswalked);\n return previous;\n } else {\n const previous = store.getAnnotation((updated as unknown as I).id);\n store.updateAnnotation(updated as unknown as I);\n return previous as unknown as E;\n }\n }\n\n // Note that we don't spread the undoStack - it has a .destroy()\n // method that would likely get overwritten by other Annotator implementations\n // if people are not careful.\n return { \n addAnnotation,\n cancelSelected,\n canRedo: undoStack.canRedo,\n canUndo: undoStack.canUndo,\n clearAnnotations,\n getAnnotationById,\n getAnnotations,\n getSelected,\n loadAnnotations,\n redo: undoStack.redo,\n removeAnnotation,\n setAnnotations,\n setSelected,\n undo: undoStack.undo,\n updateAnnotation\n }\n\n}\n","export const urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n","import { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js'\nexport { urlAlphabet } from './url-alphabet/index.js'\nexport let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nexport let customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nexport let customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nexport let nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array(size))\n while (size--) {\n id += scopedUrlAlphabet[bytes[size] & 63]\n }\n return id\n}\n","import { customAlphabet } from 'nanoid';\n\nexport interface User {\n\n id: string;\n\n isGuest?: boolean;\n\n name?: string;\n\n avatar?: string;\n\n}\n\nexport const createAnonymousGuest = () => {\n const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_', 20);\n \n return { isGuest: true, id: nanoid() }\n}","import type { AnnotationBody } from './Annotation';\n\nexport interface W3CAnnotation {\n\n '@context': 'http://www.w3.org/ns/anno.jsonld';\n\n type: 'Annotation';\n\n id: string;\n\n creator?: W3CUser;\n\n created?: string;\n\n modified?: string;\n\n body: W3CAnnotationBody | W3CAnnotationBody[];\n\n target: W3CAnnotationTarget | W3CAnnotationTarget[];\n\n [key: string]: any;\n\n}\n\nexport interface W3CUser {\n\n type?: string;\n\n id: string;\n\n name?: string;\n\n}\n\nexport interface W3CAnnotationBody {\n\n type?: string;\n\n id?: string;\n\n purpose?: string;\n\n value?: string;\n\n source?: string;\n\n creator?: W3CUser;\n\n created?: string;\n\n modified?: string;\n\n}\n\nexport interface W3CAnnotationTarget {\n\n id?: string;\n\n source: string;\n\n selector?: AbstractW3CSelector;\n\n}\n\nexport interface AbstractW3CSelector { }\n\n// https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript\nconst hashCode = (obj: Object): string => {\n const str = JSON.stringify(obj);\n\n let hash = 0;\n\n for (let i = 0, len = str.length; i < len; i++) {\n let chr = str.charCodeAt(i);\n hash = (hash << 5) - hash + chr;\n hash |= 0; // Convert to 32bit integer\n }\n\n return `${hash}`;\n}\n\nexport const parseW3CUser = (user?: any) => user\n ? typeof user === 'object' ? { ...user } : user : undefined;\n\n/**\n * Helper to crosswalk the W3C annotation body to a list of core AnnotationBody objects.\n */\nexport const parseW3CBodies = (\n body: W3CAnnotationBody | W3CAnnotationBody[],\n annotationId: string\n) : AnnotationBody[] => (Array.isArray(body) ? body : [body]).map(body => {\n\n // Exctract properties that conform to the internal model, but keep custom props\n const { id, type, purpose, value, created, modified, creator, ...rest } = body;\n\n // The internal model strictly requires IDs. (Because multi-user scenarios\n // will have problems without them.) In the W3C model, bodys *may* have IDs.\n // We'll create ad-hoc IDs for bodies without IDs, but want to make sure that\n // generating the ID is idempotent: the same body should always get the same ID.\n // This will avoid unexpected results when checking for equality. \n return {\n id: id || `temp-${hashCode(body)}`,\n annotation: annotationId,\n type,\n purpose,\n value,\n creator: parseW3CUser(creator),\n created: created ? new Date(created) : undefined,\n updated: modified ? new Date(modified) : undefined,\n ...rest\n }\n\n});\n\n/** Serialization helper to remove core-specific fields from the annotation body **/\nexport const serializeW3CBodies = (bodies: AnnotationBody[]): W3CAnnotationBody[] =>\n bodies.map(b => {\n const { annotation: _a, created, updated, ...bodyRest } = b;\n\n const w3cBody: W3CAnnotationBody = {\n ...bodyRest,\n created: created?.toISOString(),\n modified: updated?.toISOString()\n }\n if (w3cBody.id?.startsWith('temp-')) {\n delete w3cBody.id;\n }\n\n return w3cBody;\n });\n","// SEABORN_BRIGHT\nexport const DEFAULT_PALETTE: Palette = [\n '#ff7c00', // orange\n '#1ac938', // green\n '#e8000b', // red\n '#8b2be2', // purple\n '#9f4800', // brown\n '#f14cc1', // pink\n '#ffc400', // khaki\n '#00d7ff', // cyan\n '#023eff' // blue\n];\n\nexport type Palette = string[];","import type { User } from '../model/User';\nimport type { Appearance } from './Appearance';\nimport type { PresentUser } from './PresentUser';\nimport { DEFAULT_PALETTE } from './ColorPalette';\n\nexport interface AppearanceProvider {\n\n addUser(presenceKey: string, user: User): Appearance;\n\n removeUser(user: PresentUser): void;\n\n}\n\nexport const defaultColorProvider = () => {\n\n const unassignedColors = [...DEFAULT_PALETTE];\n\n const assignRandomColor = () => {\n const rnd = Math.floor(Math.random() * unassignedColors.length);\n const color = unassignedColors[rnd];\n\n unassignedColors.splice(rnd, 1);\n\n return color;\n }\n\n const releaseColor = (color: string) =>\n unassignedColors.push(color);\n\n return { assignRandomColor, releaseColor };\n\n}\n\nexport const createDefaultAppearenceProvider = () => {\n\n const colorProvider = defaultColorProvider();\n\n const addUser = (presenceKey: string, user: User): Appearance => {\n const color = colorProvider.assignRandomColor();\n\n return {\n label: user.name || user.id,\n avatar: user.avatar,\n color\n };\n }\n\n const removeUser = (user: PresentUser) =>\n colorProvider.releaseColor(user.appearance.color);\n\n return { addUser, removeUser }\n \n}","import { nanoid } from 'nanoid';\nimport { createNanoEvents, type Unsubscribe } from 'nanoevents';\nimport type { User } from '../model/User';\nimport type { PresentUser } from './PresentUser';\nimport type { PresenceEvents } from './PresenceEvents';\nimport { createDefaultAppearenceProvider } from './AppearanceProvider';\nimport type { AppearanceProvider } from './AppearanceProvider';\n\nexport interface PresenceState {\n\n // Get users currently present to this room\n getPresentUsers(): PresentUser[];\n\n // Notify of a given present user's activity on the given annotations\n notifyActivity(presenceKey: string, annotationIds: string[]): void;\n\n // Add a listener for the given presence event\n on<E extends keyof PresenceEvents>(event: E, callback: PresenceEvents[E]): Unsubscribe;\n\n // Initial sync - which users are present under which keys\n syncUsers(state: { presenceKey: string, user: User }[]): void;\n\n // Update the selection state for the given prresent user\n updateSelection(presenceKey: string, selection: string[] | null): void;\n\n}\n\nconst isListEqual = (listA: any[], listB: any[]) => \n listA.every(a => listA.includes(a)) && listB.every(b => listA.includes(b));\n\n// This client's presence key\nexport const PRESENCE_KEY = nanoid();\n\nexport const createPresenceState = (\n appearanceProvider: AppearanceProvider = createDefaultAppearenceProvider()\n): PresenceState => {\n\n const emitter = createNanoEvents<PresenceEvents>();\n\n const presentUsers = new Map<string, PresentUser>();\n\n const selectionStates = new Map<string, string[]>();\n\n const addUser = (presenceKey: string, user: User) => {\n if (presentUsers.has(presenceKey)) {\n console.warn('Attempt to add user that is already present', presenceKey, user);\n return; \n }\n\n const appearance = appearanceProvider.addUser(presenceKey, user);\n\n presentUsers.set(presenceKey, { \n ...user,\n presenceKey,\n appearance\n });\n }\n\n const removeUser = (presenceKey: string) => {\n const user = presentUsers.get(presenceKey);\n if (!user) {\n console.warn('Attempt to remove user that is not present', presenceKey);\n return;\n }\n\n appearanceProvider.removeUser(user);\n\n presentUsers.delete(presenceKey);\n }\n\n const syncUsers = (state: { presenceKey: string, user: User }[]) => {\n // const keys = new Set(others.map(s => s.presenceKey));\n const keys = new Set(state.map(s => s.presenceKey));\n\n // These users need to be added to the presentUsers list\n // const toAdd = others.filter(({ presenceKey }) => !presentUsers.has(presenceKey));\n const toAdd = state.filter(({ presenceKey }) => !presentUsers.has(presenceKey));\n\n // These users need to be dropped from the list\n const toRemove = Array.from(presentUsers.values()).filter(presentUser =>\n !keys.has(presentUser.presenceKey));\n\n toAdd.forEach(({ presenceKey, user }) => addUser(presenceKey, user));\n\n toRemove.forEach(user => {\n const { presenceKey } = user;\n\n // If this user has a selection, fire deselect event\n if (selectionStates.has(presenceKey))\n emitter.emit('selectionChange', user, null);\n\n removeUser(presenceKey)\n });\n\n if (toAdd.length > 0 || toRemove.length > 0)\n emitter.emit('presence', getPresentUsers());\n }\n\n const notifyActivity = (presenceKey: string, annotationIds: string[]) => { \n const user = presentUsers.get(presenceKey);\n \n if (!user) {\n console.warn('Activity notification from user that is not present');\n return;\n }\n\n const currentSelection = selectionStates.get(presenceKey);\n\n // Was there a selection change we might have missed?\n if (!currentSelection || !isListEqual(currentSelection, annotationIds)) {\n selectionStates.set(presenceKey, annotationIds);\n emitter.emit('selectionChange', user, annotationIds);\n }\n }\n\n const updateSelection = (presenceKey: string, selection: string[] | null) => {\n const from = presentUsers.get(presenceKey);\n if (!from) {\n console.warn('Selection change for user that is not present', presenceKey);\n return;\n }\n\n if (selection)\n selectionStates.set(presenceKey, selection);\n else \n selectionStates.delete(presenceKey);\n\n emitter.emit('selectionChange', from, selection);\n }\n\n const getPresentUsers = () =>\n [...Array.from(presentUsers.values())];\n \n const on = <E extends keyof PresenceEvents>(event: E, callback: PresenceEvents[E]) =>\n emitter.on(event, callback);\n\n return {\n getPresentUsers,\n notifyActivity,\n on,\n syncUsers,\n updateSelection\n }\n\n}"],"names":["has","dequal","foo","bar","ctor","len","noop","safe_not_equal","a","b","subscriber_queue","writable","value","start","stop","subscribers","set","new_value","run_queue","subscriber","i","update","fn","subscribe","run","invalidate","createHoverState","store","currentHover","updated","changes","oldValue","PointerSelectAction","EMPTY","createSelectionState","selectAction","currentSelection","clear","isEmpty","_a","isSelected","annotationOrId","id","clickSelect","pointerEvent","annotation","action","onPointerSelect","setSelected","idOrIds","editable","ids","annotations","isEditable","removeFromSelection","selected","byteToHex","unsafeStringify","arr","offset","getRandomValues","rnds8","rng","randomUUID","native","v4","options","buf","rnds","getContributors","creator","updatedBy","bodyCollaborators","users","body","u","createBody","payload","created","uuidv4","getAddedBodies","newValue","oldBodyIds","getRemovedBodies","newBodyIds","getChangedBodies","newBody","oldBody","hasTargetChanged","diffAnnotations","bodiesCreated","bodiesDeleted","bodiesUpdated","Ignore","Origin","shouldNotify","observer","event","_b","origin","ignore","arg","hasBodyChanges","hasTargetChanges","affectedAnnotations","mergeChanges","toMerge","previouslyCreatedIds","previouslyUpdatedIds","createdIds","deletedIds","updatedIds","mergeableUpdates","deleted","isAnnotation","createStore","annotationIndex","bodyIndex","observers","observe","onChange","unobserve","idx","emit","addAnnotation","updateOneAnnotation","arg1","arg2","oldId","updateAnnotation","arg3","bulkUpdateAnnotation","addBody","all","bulkAddAnnotation","replace","existing","next","deleteOneAnnotation","deleteAnnotation","bulkDeleteAnnotation","annotationsOrIds","deleteOneBody","oldAnnotation","newAnnotation","deleteBody","bulkDeleteBodies","bodies","getAnnotation","getBody","annotationId","updateOneBody","oldBodyId","updateBody","bulkUpdateBodies","updateOneTarget","target","targets","t","toSvelteStore","shim","createNanoEvents","args","callbacks","length","cb","DEBOUNCE","createUndoStack","emitter","changeStack","pointer","muteEvents","lastEvent","now","last","undoCreated","redoCreated","undoUpdated","redoUpdated","undoDeleted","redoDeleted","callback","createViewportState","createLifecycleObserver","state","undoStack","adapter","autoSave","selection","hover","viewport","initialSelection","idleTimeout","on","off","arg0","serialized0","serialized1","onIdleUpdate","updatedSelected","initial","updatedState","initialIds","selectedIds","relevantUpdates","onUndoOrRedo","undo","serializeAll","parseAll","serialized","result","parsed","error","createBaseAnnotator","cancelSelected","clearAnnotations","getAnnotationById","getAnnotations","getSelected","s","loadAnnotations","url","response","setAnnotations","removeAnnotation","failed","crosswalked","previous","urlAlphabet","random","bytes","customRandom","alphabet","defaultSize","getRandom","mask","step","size","j","customAlphabet","nanoid","scopedUrlAlphabet","createAnonymousGuest","hashCode","obj","str","hash","chr","parseW3CUser","user","parseW3CBodies","type","purpose","modified","rest","serializeW3CBodies","bodyRest","w3cBody","DEFAULT_PALETTE","defaultColorProvider","unassignedColors","rnd","color","createDefaultAppearenceProvider","colorProvider","presenceKey","isListEqual","listA","listB","PRESENCE_KEY","createPresenceState","appearanceProvider","presentUsers","selectionStates","addUser","appearance","removeUser","syncUsers","keys","toAdd","toRemove","presentUser","getPresentUsers","notifyActivity","annotationIds","updateSelection","from"],"mappings":"AAAA,IAAIA,IAAM,OAAO,UAAU;AAEpB,SAASC,EAAOC,GAAKC,GAAK;AAChC,MAAIC,GAAMC;AACV,MAAIH,MAAQC,EAAK,QAAO;AAExB,MAAID,KAAOC,MAAQC,IAAKF,EAAI,iBAAiBC,EAAI,aAAa;AAC7D,QAAIC,MAAS,KAAM,QAAOF,EAAI,cAAcC,EAAI;AAChD,QAAIC,MAAS,OAAQ,QAAOF,EAAI,eAAeC,EAAI;AAEnD,QAAIC,MAAS,OAAO;AACnB,WAAKC,IAAIH,EAAI,YAAYC,EAAI;AAC5B,eAAOE,OAASJ,EAAOC,EAAIG,CAAG,GAAGF,EAAIE,CAAG,CAAC,IAAE;AAE5C,aAAOA,MAAQ;AAAA,IACf;AAED,QAAI,CAACD,KAAQ,OAAOF,KAAQ,UAAU;AACrC,MAAAG,IAAM;AACN,WAAKD,KAAQF;AAEZ,YADIF,EAAI,KAAKE,GAAKE,CAAI,KAAK,EAAEC,KAAO,CAACL,EAAI,KAAKG,GAA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CqF,EAAgB,OAAOR,CAAW,GAE5BjG,EAAA,KAAK,mBAAmBsH,GAAMlG,CAAS;AAAA,EAAA,GAG3C8F,IAAkB,MACtB,CAAC,GAAG,MAAM,KAAKV,EAAa,OAAQ,CAAA,CAAC;AAKhC,SAAA;AAAA,IACL,iBAAAU;AAAA,IACA,gBAAAC;AAAA,IACA,IANS,CAAiC1L,GAAUoF,MACpDb,EAAQ,GAAGvE,GAAOoF,CAAQ;AAAA,IAM1B,WAAAgG;AAAA,IACA,iBAAAQ;AAAA,EAAA;AAGJ;","x_google_ignoreList":[0,1,2,5,6,7,8,14,20,21]}
|
|
@@ -2,8 +2,8 @@ import { Annotation, AnnotatorState, FormatAdapter } from '../model';
|
|
|
2
2
|
import { UndoStack } from '../state';
|
|
3
3
|
import { LifecycleEvents } from './LifecycleEvents';
|
|
4
4
|
|
|
5
|
-
export type Lifecycle<I extends Annotation, E extends unknown> = ReturnType<typeof
|
|
6
|
-
export declare const
|
|
5
|
+
export type Lifecycle<I extends Annotation, E extends unknown> = ReturnType<typeof createLifecycleObserver<I, E>>;
|
|
6
|
+
export declare const createLifecycleObserver: <I extends Annotation, E extends unknown>(state: AnnotatorState<I>, undoStack: UndoStack<I>, adapter?: FormatAdapter<I, E>, autoSave?: boolean) => {
|
|
7
7
|
on: <T extends keyof LifecycleEvents<Annotation>>(event: T, callback: LifecycleEvents<E>[T]) => void;
|
|
8
8
|
off: <T_1 extends keyof LifecycleEvents<E>>(event: T_1, callback: LifecycleEvents<E>[T_1]) => void;
|
|
9
9
|
emit: (event: keyof LifecycleEvents<E>, arg0: I | I[], arg1?: I | PointerEvent) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lifecycle.d.ts","sourceRoot":"","sources":["../../src/lifecycle/Lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,OAAO,IAC3D,UAAU,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"Lifecycle.d.ts","sourceRoot":"","sources":["../../src/lifecycle/Lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,OAAO,IAC3D,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEnD,eAAO,MAAM,uBAAuB,mDAC3B,eAAe,CAAC,CAAC,aACb,UAAU,CAAC,CAAC,YACb,cAAc,CAAC,EAAE,CAAC,CAAC,aAClB,OAAO;6DAakC,CAAC,YAAY,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;;kBAiBjE,MAAM,gBAAgB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,GAAG,YAAY;CAwKtF,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@annotorious/core",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.29",
|
|
4
4
|
"description": "Annotorious core types and functions",
|
|
5
5
|
"author": "Rainer Simon",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"@types/deep-equal": "^1.0.4",
|
|
31
31
|
"@types/uuid": "^9.0.8",
|
|
32
32
|
"svelte": "^4.2.18",
|
|
33
|
-
"svelte-preprocess": "^
|
|
33
|
+
"svelte-preprocess": "^6.0.1",
|
|
34
34
|
"typescript": "^5.4.5",
|
|
35
|
-
"vite": "^5.
|
|
35
|
+
"vite": "^5.3.1",
|
|
36
36
|
"vite-plugin-dts": "^3.9.1",
|
|
37
37
|
"vitest": "^1.6.0"
|
|
38
38
|
},
|