@annotorious/react 3.0.0-rc.20 → 3.0.0-rc.3

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.
Files changed (91) hide show
  1. package/dist/Annotorious.d.ts +28 -3
  2. package/dist/Annotorious.d.ts.map +1 -1
  3. package/dist/AnnotoriousPlugin.d.ts +6 -7
  4. package/dist/AnnotoriousPlugin.d.ts.map +1 -1
  5. package/dist/ImageAnnotator.d.ts.map +1 -1
  6. package/dist/annotorious-react.css +1 -1
  7. package/dist/annotorious-react.es.js +50 -33
  8. package/dist/annotorious-react.es.js.map +1 -1
  9. package/dist/annotorious-react.es10.js +3 -29
  10. package/dist/annotorious-react.es10.js.map +1 -1
  11. package/dist/annotorious-react.es11.js +27 -36
  12. package/dist/annotorious-react.es11.js.map +1 -1
  13. package/dist/annotorious-react.es12.js +20 -16
  14. package/dist/annotorious-react.es12.js.map +1 -1
  15. package/dist/annotorious-react.es13.js +54 -6
  16. package/dist/annotorious-react.es13.js.map +1 -1
  17. package/dist/annotorious-react.es14.js +17 -8
  18. package/dist/annotorious-react.es14.js.map +1 -1
  19. package/dist/annotorious-react.es15.js +21 -152
  20. package/dist/annotorious-react.es15.js.map +1 -1
  21. package/dist/annotorious-react.es16.js +2 -27436
  22. package/dist/annotorious-react.es16.js.map +1 -1
  23. package/dist/annotorious-react.es17.js +2 -32
  24. package/dist/annotorious-react.es17.js.map +1 -1
  25. package/dist/annotorious-react.es18.js +3859 -2
  26. package/dist/annotorious-react.es18.js.map +1 -1
  27. package/dist/annotorious-react.es19.js +29 -30
  28. package/dist/annotorious-react.es19.js.map +1 -1
  29. package/dist/annotorious-react.es2.js +32 -32
  30. package/dist/annotorious-react.es2.js.map +1 -1
  31. package/dist/annotorious-react.es20.js +35 -598
  32. package/dist/annotorious-react.es20.js.map +1 -1
  33. package/dist/annotorious-react.es21.js +16 -2
  34. package/dist/annotorious-react.es21.js.map +1 -1
  35. package/dist/annotorious-react.es22.js +4 -2
  36. package/dist/annotorious-react.es22.js.map +1 -1
  37. package/dist/annotorious-react.es23.js +11 -0
  38. package/dist/annotorious-react.es23.js.map +1 -0
  39. package/dist/annotorious-react.es24.js +156 -0
  40. package/dist/annotorious-react.es24.js.map +1 -0
  41. package/dist/annotorious-react.es25.js +9 -0
  42. package/dist/annotorious-react.es25.js.map +1 -0
  43. package/dist/annotorious-react.es26.js +20665 -0
  44. package/dist/annotorious-react.es26.js.map +1 -0
  45. package/dist/annotorious-react.es27.js +35 -0
  46. package/dist/annotorious-react.es27.js.map +1 -0
  47. package/dist/annotorious-react.es28.js +5 -0
  48. package/dist/annotorious-react.es28.js.map +1 -0
  49. package/dist/annotorious-react.es29.js +33 -0
  50. package/dist/annotorious-react.es29.js.map +1 -0
  51. package/dist/annotorious-react.es3.js +7 -7
  52. package/dist/annotorious-react.es3.js.map +1 -1
  53. package/dist/annotorious-react.es30.js +602 -0
  54. package/dist/annotorious-react.es30.js.map +1 -0
  55. package/dist/annotorious-react.es31.js +5 -0
  56. package/dist/annotorious-react.es31.js.map +1 -0
  57. package/dist/annotorious-react.es32.js +5 -0
  58. package/dist/annotorious-react.es32.js.map +1 -0
  59. package/dist/annotorious-react.es33.js +20 -0
  60. package/dist/annotorious-react.es33.js.map +1 -0
  61. package/dist/annotorious-react.es34.js +30 -0
  62. package/dist/annotorious-react.es34.js.map +1 -0
  63. package/dist/annotorious-react.es35.js +19 -0
  64. package/dist/annotorious-react.es35.js.map +1 -0
  65. package/dist/annotorious-react.es36.js +24 -0
  66. package/dist/annotorious-react.es36.js.map +1 -0
  67. package/dist/annotorious-react.es37.js +19 -0
  68. package/dist/annotorious-react.es37.js.map +1 -0
  69. package/dist/annotorious-react.es38.js +7 -0
  70. package/dist/annotorious-react.es38.js.map +1 -0
  71. package/dist/annotorious-react.es39.js +11 -0
  72. package/dist/annotorious-react.es39.js.map +1 -0
  73. package/dist/annotorious-react.es4.js +8 -8
  74. package/dist/annotorious-react.es4.js.map +1 -1
  75. package/dist/annotorious-react.es40.js +10 -0
  76. package/dist/annotorious-react.es40.js.map +1 -0
  77. package/dist/annotorious-react.es5.js +10 -10
  78. package/dist/annotorious-react.es5.js.map +1 -1
  79. package/dist/annotorious-react.es6.js +4 -1
  80. package/dist/annotorious-react.es6.js.map +1 -1
  81. package/dist/annotorious-react.es7.js +4 -1
  82. package/dist/annotorious-react.es7.js.map +1 -1
  83. package/dist/annotorious-react.es8.js +46 -85
  84. package/dist/annotorious-react.es8.js.map +1 -1
  85. package/dist/annotorious-react.es9.js +10 -4237
  86. package/dist/annotorious-react.es9.js.map +1 -1
  87. package/dist/index.d.ts +10 -12
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/openseadragon/OpenSeadragonAnnotator.d.ts.map +1 -1
  90. package/dist/openseadragon/setPosition.d.ts.map +1 -1
  91. package/package.json +8 -16
@@ -1,91 +1,52 @@
1
- var f = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(f || {});
2
- let c;
3
- const p = new Uint8Array(16);
4
- function y() {
5
- if (!c && (c = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !c))
6
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
7
- return c(p);
8
- }
9
- const o = [];
10
- for (let t = 0; t < 256; ++t)
11
- o.push((t + 256).toString(16).slice(1));
12
- function g(t, r = 0) {
13
- return o[t[r + 0]] + o[t[r + 1]] + o[t[r + 2]] + o[t[r + 3]] + "-" + o[t[r + 4]] + o[t[r + 5]] + "-" + o[t[r + 6]] + o[t[r + 7]] + "-" + o[t[r + 8]] + o[t[r + 9]] + "-" + o[t[r + 10]] + o[t[r + 11]] + o[t[r + 12]] + o[t[r + 13]] + o[t[r + 14]] + o[t[r + 15]];
14
- }
15
- const m = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), i = {
16
- randomUUID: m
17
- };
18
- function E(t, r, e) {
19
- if (i.randomUUID && !r && !t)
20
- return i.randomUUID();
21
- t = t || {};
22
- const n = t.random || (t.rng || y)();
23
- if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, r) {
24
- e = e || 0;
25
- for (let a = 0; a < 16; ++a)
26
- r[e + a] = n[a];
27
- return r;
28
- }
29
- return g(n);
30
- }
31
- const A = (t, r, e, n) => ({
32
- id: E(),
33
- annotation: t.id,
34
- created: e || /* @__PURE__ */ new Date(),
35
- creator: n,
36
- ...r
37
- });
38
- var U = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(U || {});
39
- const h = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
40
- let D = (t) => crypto.getRandomValues(new Uint8Array(t)), C = (t, r, e) => {
41
- let n = (2 << Math.log(t.length - 1) / Math.LN2) - 1, a = -~(1.6 * n * r / t.length);
42
- return (l = r) => {
43
- let s = "";
44
- for (; ; ) {
45
- let d = e(a), u = a;
46
- for (; u--; )
47
- if (s += t[d[u] & n] || "", s.length === l)
48
- return s;
1
+ import { Origin as s } from "./annotorious-react.es17.js";
2
+ import { parseAll as m } from "./annotorious-react.es9.js";
3
+ const O = (t, l, i) => {
4
+ const A = (o) => {
5
+ if (i) {
6
+ const { parsed: n, error: e } = i.parse(o);
7
+ n ? t.addAnnotation(n, s.REMOTE) : console.error(e);
8
+ } else
9
+ t.addAnnotation(o, s.REMOTE);
10
+ }, r = () => t.clear(), a = (o) => {
11
+ const n = t.getAnnotation(o);
12
+ return i && n ? i.serialize(n) : n;
13
+ }, u = () => i ? t.all().map(i.serialize) : t.all(), d = (o) => fetch(o).then((n) => n.json()).then((n) => (c(n), n)), f = (o) => {
14
+ if (typeof o == "string") {
15
+ const n = t.getAnnotation(o);
16
+ return t.deleteAnnotation(o), i ? i.serialize(n) : n;
17
+ } else {
18
+ const n = i ? i.parse(o).parsed : o;
19
+ return t.deleteAnnotation(n), o;
20
+ }
21
+ }, c = (o) => {
22
+ if (i) {
23
+ const { parsed: n, failed: e } = m(i)(o);
24
+ e.length > 0 && console.warn(`Discarded ${e.length} invalid annotations`, e), t.bulkAddAnnotation(n, !0, s.REMOTE);
25
+ } else
26
+ t.bulkAddAnnotation(o, !0, s.REMOTE);
27
+ }, E = (o) => {
28
+ if (i) {
29
+ const n = i.parse(o).parsed, e = i.serialize(t.getAnnotation(n.id));
30
+ return t.updateAnnotation(n), e;
31
+ } else {
32
+ const n = t.getAnnotation(o.id);
33
+ return t.updateAnnotation(o), n;
49
34
  }
50
35
  };
51
- }, O = (t, r = 21) => C(t, r, D), R = (t = 21) => {
52
- let r = "", e = crypto.getRandomValues(new Uint8Array(t));
53
- for (; t--; )
54
- r += h[e[t] & 63];
55
- return r;
56
- };
57
- const I = () => ({ isGuest: !0, id: O("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), w = [
58
- "#ff7c00",
59
- // orange
60
- "#1ac938",
61
- // green
62
- "#e8000b",
63
- // red
64
- "#8b2be2",
65
- // purple
66
- "#9f4800",
67
- // brown
68
- "#f14cc1",
69
- // pink
70
- "#ffc400",
71
- // khaki
72
- "#00d7ff",
73
- // cyan
74
- "#023eff"
75
- // blue
76
- ], L = () => {
77
- const t = [...w];
78
- return { assignRandomColor: () => {
79
- const r = Math.floor(Math.random() * t.length), e = t[r];
80
- return t.splice(r, 1), e;
81
- }, releaseColor: (r) => t.push(r) };
36
+ return {
37
+ addAnnotation: A,
38
+ clearAnnotations: r,
39
+ getAnnotationById: a,
40
+ getAnnotations: u,
41
+ loadAnnotations: d,
42
+ redo: l.redo,
43
+ removeAnnotation: f,
44
+ setAnnotations: c,
45
+ undo: l.undo,
46
+ updateAnnotation: E
47
+ };
82
48
  };
83
- R();
84
49
  export {
85
- U as Origin,
86
- f as PointerSelectAction,
87
- I as createAnonymousGuest,
88
- A as createBody,
89
- L as defaultColorProvider
50
+ O as createBaseAnnotator
90
51
  };
91
52
  //# sourceMappingURL=annotorious-react.es8.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es8.js","sources":["../../annotorious-core/dist/annotorious-core.es.js"],"sourcesContent":["var _ = Object.prototype.hasOwnProperty;\nfunction x(e, n) {\n var t, o;\n if (e === n)\n return !0;\n if (e && n && (t = e.constructor) === n.constructor) {\n if (t === Date)\n return e.getTime() === n.getTime();\n if (t === RegExp)\n return e.toString() === n.toString();\n if (t === Array) {\n if ((o = e.length) === n.length)\n for (; o-- && x(e[o], n[o]); )\n ;\n return o === -1;\n }\n if (!t || typeof e == \"object\") {\n o = 0;\n for (t in e)\n if (_.call(e, t) && ++o && !_.call(n, t) || !(t in n) || !x(e[t], n[t]))\n return !1;\n return Object.keys(n).length === o;\n }\n }\n return e !== e && n !== n;\n}\nfunction z() {\n}\nfunction W(e, n) {\n return e != e ? n == n : e !== n || e && typeof e == \"object\" || typeof e == \"function\";\n}\nconst k = [];\nfunction Y(e, n = z) {\n let t;\n const o = /* @__PURE__ */ new Set();\n function i(E) {\n if (W(e, E) && (e = E, t)) {\n const w = !k.length;\n for (const u of o)\n u[1](), k.push(u, e);\n if (w) {\n for (let u = 0; u < k.length; u += 2)\n k[u][0](k[u + 1]);\n k.length = 0;\n }\n }\n }\n function p(E) {\n i(E(e));\n }\n function U(E, w = z) {\n const u = [E, w];\n return o.add(u), o.size === 1 && (t = n(i, p) || z), E(e), () => {\n o.delete(u), o.size === 0 && t && (t(), t = null);\n };\n }\n return { set: i, update: p, subscribe: U };\n}\nconst ve = (e) => {\n const { subscribe: n, set: t } = Y();\n let o;\n return n((i) => o = i), e.observe(({ changes: i }) => {\n if (o) {\n (i.deleted || []).some((E) => E.id === o) && t(void 0);\n const U = (i.updated || []).find(({ oldValue: E }) => E.id === o);\n U && t(U.newValue.id);\n }\n }), {\n get current() {\n return o;\n },\n subscribe: n,\n set: t\n };\n};\nvar q = /* @__PURE__ */ ((e) => (e.EDIT = \"EDIT\", e.SELECT = \"SELECT\", e.NONE = \"NONE\", e))(q || {});\nconst V = { selected: [] }, ye = (e, n = \"EDIT\") => {\n const { subscribe: t, set: o } = Y(V);\n let i = V;\n t((s) => i = s);\n const p = () => o(V), U = () => {\n var s;\n return ((s = i.selected) == null ? void 0 : s.length) === 0;\n }, E = (s) => {\n if (i.selected.length === 0)\n return !1;\n const h = typeof s == \"string\" ? s : s.id;\n return i.selected.some((C) => C.id === h);\n }, w = (s, h) => {\n const C = e.getAnnotation(s);\n if (C) {\n const b = G(C, n);\n o(b === \"EDIT\" ? { selected: [{ id: s, editable: !0 }], pointerEvent: h } : b === \"SELECT\" ? { selected: [{ id: s }], pointerEvent: h } : { selected: [], pointerEvent: h });\n } else\n console.warn(\"Invalid selection: \" + s);\n }, u = (s, h = !0) => {\n const C = Array.isArray(s) ? s : [s], b = C.map((S) => e.getAnnotation(S)).filter(Boolean);\n o({ selected: b.map(({ id: S }) => ({ id: S, editable: h })) }), b.length !== C.length && console.warn(\"Invalid selection\", s);\n }, L = (s) => {\n if (i.selected.length === 0)\n return !1;\n const { selected: h } = i;\n h.filter(({ id: b }) => s.includes(b)).length > 0 && o({ selected: h.filter(({ id: b }) => !s.includes(b)) });\n };\n return e.observe(({ changes: s }) => L((s.deleted || []).map((h) => h.id))), {\n clear: p,\n clickSelect: w,\n get selected() {\n return i ? [...i.selected] : null;\n },\n get pointerEvent() {\n return i ? i.pointerEvent : null;\n },\n isEmpty: U,\n isSelected: E,\n setSelected: u,\n subscribe: t\n };\n}, G = (e, n) => typeof n == \"function\" ? n(e) || \"EDIT\" : n || \"EDIT\";\nlet $;\nconst H = new Uint8Array(16);\nfunction F() {\n if (!$ && ($ = typeof crypto < \"u\" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !$))\n throw new Error(\"crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported\");\n return $(H);\n}\nconst D = [];\nfor (let e = 0; e < 256; ++e)\n D.push((e + 256).toString(16).slice(1));\nfunction J(e, n = 0) {\n return D[e[n + 0]] + D[e[n + 1]] + D[e[n + 2]] + D[e[n + 3]] + \"-\" + D[e[n + 4]] + D[e[n + 5]] + \"-\" + D[e[n + 6]] + D[e[n + 7]] + \"-\" + D[e[n + 8]] + D[e[n + 9]] + \"-\" + D[e[n + 10]] + D[e[n + 11]] + D[e[n + 12]] + D[e[n + 13]] + D[e[n + 14]] + D[e[n + 15]];\n}\nconst Q = typeof crypto < \"u\" && crypto.randomUUID && crypto.randomUUID.bind(crypto), j = {\n randomUUID: Q\n};\nfunction X(e, n, t) {\n if (j.randomUUID && !n && !e)\n return j.randomUUID();\n e = e || {};\n const o = e.random || (e.rng || F)();\n if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, n) {\n t = t || 0;\n for (let i = 0; i < 16; ++i)\n n[t + i] = o[i];\n return n;\n }\n return J(o);\n}\nconst we = (e) => {\n const { creator: n, updatedBy: t } = e.target, o = e.bodies.reduce((i, p) => [...i, p.creator, p.updatedBy].filter(Boolean), []);\n return [\n n,\n t,\n ...o\n ].filter((i) => i);\n}, Ce = (e, n, t, o) => ({\n id: X(),\n annotation: e.id,\n created: t || /* @__PURE__ */ new Date(),\n creator: o,\n ...n\n}), Z = (e, n) => {\n const t = new Set(e.bodies.map((o) => o.id));\n return n.bodies.filter((o) => !t.has(o.id));\n}, K = (e, n) => {\n const t = new Set(n.bodies.map((o) => o.id));\n return e.bodies.filter((o) => !t.has(o.id));\n}, ee = (e, n) => n.bodies.map((t) => {\n const o = e.bodies.find((i) => i.id === t.id);\n return { newBody: t, oldBody: o && !x(o, t) ? o : void 0 };\n}).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), te = (e, n) => !x(e.target, n.target), M = (e, n) => {\n const t = Z(e, n), o = K(e, n), i = ee(e, n);\n return {\n oldValue: e,\n newValue: n,\n bodiesCreated: t.length > 0 ? t : void 0,\n bodiesDeleted: o.length > 0 ? o : void 0,\n bodiesUpdated: i.length > 0 ? i : void 0,\n targetUpdated: te(e, n) ? { oldTarget: e.target, newTarget: n.target } : void 0\n };\n};\nvar ne = /* @__PURE__ */ ((e) => (e.BODY_ONLY = \"BODY_ONLY\", e.TARGET_ONLY = \"TARGET_ONLY\", e))(ne || {}), O = /* @__PURE__ */ ((e) => (e.LOCAL = \"LOCAL\", e.REMOTE = \"REMOTE\", e))(O || {});\nconst oe = (e, n) => {\n var p, U;\n const { changes: t, origin: o } = n;\n if (!(!e.options.origin || e.options.origin === o))\n return !1;\n if (e.options.ignore) {\n const { ignore: E } = e.options, w = (L) => L && L.length > 0;\n if (!(w(t.created) || w(t.deleted))) {\n const L = (p = t.updated) == null ? void 0 : p.some((h) => w(h.bodiesCreated) || w(h.bodiesDeleted) || w(h.bodiesUpdated)), s = (U = t.updated) == null ? void 0 : U.some((h) => h.targetUpdated);\n if (E === \"BODY_ONLY\" && L && !s || E === \"TARGET_ONLY\" && s && !L)\n return !1;\n }\n }\n if (e.options.annotations) {\n const E = /* @__PURE__ */ new Set([\n ...(t.created || []).map((u) => u.id),\n ...(t.deleted || []).map((u) => u.id),\n ...(t.updated || []).map(({ oldValue: u }) => u.id)\n ]);\n return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((u) => E.has(u));\n } else\n return !0;\n}, se = (e, n) => {\n const t = new Set((e.created || []).map((s) => s.id)), o = new Set((e.updated || []).map(({ newValue: s }) => s.id)), i = new Set((n.created || []).map((s) => s.id)), p = new Set((n.deleted || []).map((s) => s.id)), U = new Set((n.updated || []).map(({ oldValue: s }) => s.id)), E = new Set((n.updated || []).filter(({ oldValue: s }) => t.has(s.id) || o.has(s.id)).map(({ oldValue: s }) => s.id)), w = [\n ...(e.created || []).filter((s) => !p.has(s.id)).map((s) => U.has(s.id) ? n.updated.find(({ oldValue: h }) => h.id === s.id).newValue : s),\n ...n.created || []\n ], u = [\n ...(e.deleted || []).filter((s) => !i.has(s.id)),\n ...(n.deleted || []).filter((s) => !t.has(s.id))\n ], L = [\n ...(e.updated || []).filter(({ newValue: s }) => !p.has(s.id)).map((s) => {\n const { oldValue: h, newValue: C } = s;\n if (U.has(C.id)) {\n const b = n.updated.find((S) => S.oldValue.id === C.id).newValue;\n return M(h, b);\n } else\n return s;\n }),\n ...(n.updated || []).filter(({ oldValue: s }) => !E.has(s.id))\n ];\n return { created: w, deleted: u, updated: L };\n}, ie = (e) => e.id !== void 0, Ue = () => {\n const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (d, l = {}) => t.push({ onChange: d, options: l }), i = (d) => {\n const l = t.findIndex((a) => a.onChange == d);\n l > -1 && t.splice(l, 1);\n }, p = (d, l) => {\n const a = {\n origin: d,\n changes: {\n created: l.created || [],\n updated: l.updated || [],\n deleted: l.deleted || []\n },\n state: [...e.values()]\n };\n t.forEach((f) => {\n oe(f, a) && f.onChange(a);\n });\n }, U = (d, l = O.LOCAL) => {\n if (e.get(d.id))\n throw Error(`Cannot add annotation ${d.id} - exists already`);\n e.set(d.id, d), d.bodies.forEach((f) => n.set(f.id, d.id)), p(l, { created: [d] });\n }, E = (d, l) => {\n const a = typeof d == \"string\" ? l : d, f = typeof d == \"string\" ? d : d.id, v = e.get(f);\n if (v) {\n const T = M(v, a);\n return f === a.id ? e.set(f, a) : (e.delete(f), e.set(a.id, a)), v.bodies.forEach((B) => n.delete(B.id)), a.bodies.forEach((B) => n.set(B.id, a.id)), T;\n } else\n console.warn(`Cannot update annotation ${f} - does not exist`);\n }, w = (d, l = O.LOCAL, a = O.LOCAL) => {\n const f = ie(l) ? a : l, v = E(d, l);\n v && p(f, { updated: [v] });\n }, u = (d, l = O.LOCAL) => {\n const a = d.reduce((f, v) => {\n const T = E(v);\n return T ? [...f, T] : f;\n }, []);\n a.length > 0 && p(l, { updated: a });\n }, L = (d, l = O.LOCAL) => {\n const a = e.get(d.annotation);\n if (a) {\n const f = {\n ...a,\n bodies: [...a.bodies, d]\n };\n e.set(a.id, f), n.set(d.id, f.id), p(l, { updated: [{\n oldValue: a,\n newValue: f,\n bodiesCreated: [d]\n }] });\n } else\n console.warn(`Attempt to add body to missing annotation: ${d.annotation}`);\n }, s = () => [...e.values()], h = (d = O.LOCAL) => {\n const l = [...e.values()];\n e.clear(), n.clear(), p(d, { deleted: l });\n }, C = (d, l = !0, a = O.LOCAL) => {\n if (l) {\n const f = [...e.values()];\n e.clear(), n.clear(), d.forEach((v) => {\n e.set(v.id, v), v.bodies.forEach((T) => n.set(T.id, v.id));\n }), p(a, { created: d, deleted: f });\n } else {\n const f = d.reduce((v, T) => {\n const B = e.get(T.id);\n return B ? [...v, B] : v;\n }, []);\n if (f.length > 0)\n throw Error(`Bulk insert would overwrite the following annotations: ${f.map((v) => v.id).join(\", \")}`);\n d.forEach((v) => {\n e.set(v.id, v), v.bodies.forEach((T) => n.set(T.id, v.id));\n }), p(a, { created: d });\n }\n }, b = (d) => {\n const l = typeof d == \"string\" ? d : d.id, a = e.get(l);\n if (a)\n return e.delete(l), a.bodies.forEach((f) => n.delete(f.id)), a;\n console.warn(`Attempt to delete missing annotation: ${l}`);\n }, S = (d, l = O.LOCAL) => {\n const a = b(d);\n a && p(l, { deleted: [a] });\n }, y = (d, l = O.LOCAL) => {\n const a = d.reduce((f, v) => {\n const T = b(v);\n return T ? [...f, T] : f;\n }, []);\n a.length > 0 && p(l, { deleted: a });\n }, c = (d, l = O.LOCAL) => {\n const a = e.get(d.annotation);\n if (a) {\n const f = a.bodies.find((v) => v.id === d.id);\n if (f) {\n n.delete(f.id);\n const v = {\n ...a,\n bodies: a.bodies.filter((B) => B.id !== d.id)\n };\n e.set(a.id, v), p(l, { updated: [{\n oldValue: a,\n newValue: v,\n bodiesDeleted: [f]\n }] });\n } else\n console.warn(`Attempt to delete missing body ${d.id} from annotation ${d.annotation}`);\n } else\n console.warn(`Attempt to delete body from missing annotation ${d.annotation}`);\n }, g = (d) => {\n const l = e.get(d);\n return l ? { ...l } : void 0;\n }, r = (d) => {\n const l = n.get(d);\n if (l) {\n const f = g(l).bodies.find((v) => v.id === d);\n if (f)\n return f;\n console.error(`Store integrity error: body ${d} in index, but not in annotation`);\n } else\n console.warn(`Attempt to retrieve missing body: ${d}`);\n }, A = (d, l) => {\n if (d.annotation !== l.annotation)\n throw \"Annotation integrity violation: annotation ID must be the same when updating bodies\";\n const a = e.get(d.annotation);\n if (a) {\n const f = a.bodies.find((T) => T.id === d.id), v = {\n ...a,\n bodies: a.bodies.map((T) => T.id === f.id ? l : T)\n };\n return e.set(a.id, v), f.id !== l.id && (n.delete(f.id), n.set(l.id, v.id)), {\n oldValue: a,\n newValue: v,\n bodiesUpdated: [{ oldBody: f, newBody: l }]\n };\n } else\n console.warn(`Attempt to add body to missing annotation ${d.annotation}`);\n }, m = (d, l, a = O.LOCAL) => {\n const f = A(d, l);\n f && p(a, { updated: [f] });\n }, R = (d, l = O.LOCAL) => {\n const a = d.map((f) => A({ id: f.id, annotation: f.annotation }, f)).filter(Boolean);\n p(l, { updated: a });\n }, I = (d) => {\n const l = e.get(d.annotation);\n if (l) {\n const a = {\n ...l,\n target: {\n ...l.target,\n ...d\n }\n };\n return e.set(l.id, a), {\n oldValue: l,\n newValue: a,\n targetUpdated: {\n oldTarget: l.target,\n newTarget: d\n }\n };\n } else\n console.warn(`Attempt to update target on missing annotation: ${d.annotation}`);\n };\n return {\n addAnnotation: U,\n addBody: L,\n all: s,\n bulkAddAnnotation: C,\n bulkDeleteAnnotation: y,\n bulkUpdateAnnotation: u,\n bulkUpdateBodies: R,\n bulkUpdateTargets: (d, l = O.LOCAL) => {\n const a = d.map((f) => I(f)).filter(Boolean);\n a.length > 0 && p(l, { updated: a });\n },\n clear: h,\n deleteAnnotation: S,\n deleteBody: c,\n getAnnotation: g,\n getBody: r,\n observe: o,\n unobserve: i,\n updateAnnotation: w,\n updateBody: m,\n updateTarget: (d, l = O.LOCAL) => {\n const a = I(d);\n a && p(l, { updated: [a] });\n }\n };\n}, Le = (e) => ({\n ...e,\n subscribe: (t) => {\n const o = (i) => t(i.state);\n return e.observe(o), t(e.all()), () => e.unobserve(o);\n }\n});\nlet P = () => ({\n emit(e, ...n) {\n for (let t = 0, o = this.events[e] || [], i = o.length; t < i; t++)\n o[t](...n);\n },\n events: {},\n on(e, n) {\n var t;\n return ((t = this.events)[e] || (t[e] = [])).push(n), () => {\n var o;\n this.events[e] = (o = this.events[e]) == null ? void 0 : o.filter((i) => n !== i);\n };\n }\n});\nconst de = 250, Se = (e) => {\n const n = P(), t = [];\n let o = -1, i = !1, p = 0;\n const U = (r) => {\n if (!i) {\n const { changes: A } = r, m = performance.now();\n if (m - p > de)\n t.splice(o + 1), t.push(A), o = t.length - 1;\n else {\n const R = t.length - 1;\n t[R] = se(t[R], A);\n }\n p = m;\n }\n i = !1;\n };\n e.observe(U, { origin: O.LOCAL });\n const E = (r) => r && r.length > 0 && e.bulkDeleteAnnotation(r), w = (r) => r && r.length > 0 && e.bulkAddAnnotation(r, !1), u = (r) => r && r.length > 0 && e.bulkUpdateAnnotation(r.map(({ oldValue: A }) => A)), L = (r) => r && r.length > 0 && e.bulkUpdateAnnotation(r.map(({ newValue: A }) => A)), s = (r) => r && r.length > 0 && e.bulkAddAnnotation(r, !1), h = (r) => r && r.length > 0 && e.bulkDeleteAnnotation(r);\n return {\n canRedo: () => t.length - 1 > o,\n canUndo: () => o > -1,\n destroy: () => e.unobserve(U),\n on: (r, A) => n.on(r, A),\n redo: () => {\n if (t.length - 1 > o) {\n i = !0;\n const { created: r, updated: A, deleted: m } = t[o + 1];\n w(r), L(A), h(m), n.emit(\"redo\", t[o + 1]), o += 1;\n }\n },\n undo: () => {\n if (o > -1) {\n i = !0;\n const { created: r, updated: A, deleted: m } = t[o];\n E(r), u(A), s(m), n.emit(\"undo\", t[o]), o -= 1;\n }\n }\n };\n}, Oe = () => {\n const { subscribe: e, set: n } = Y([]);\n return {\n subscribe: e,\n set: n\n };\n}, Te = (e, n, t, o) => {\n const { store: i, selection: p, hover: U, viewport: E } = e, w = /* @__PURE__ */ new Map();\n let u = [], L, s;\n const h = (c, g) => {\n w.has(c) ? w.get(c).push(g) : w.set(c, [g]);\n }, C = (c, g) => {\n const r = w.get(c);\n r && r.indexOf(g) > 0 && r.splice(r.indexOf(g), 1);\n }, b = (c, g, r) => {\n w.has(c) && setTimeout(() => {\n w.get(c).forEach((A) => {\n if (t) {\n const m = Array.isArray(g) ? g.map((I) => t.serialize(I)) : t.serialize(g), R = r ? r instanceof PointerEvent ? r : t.serialize(r) : void 0;\n A(m, R);\n } else\n A(g, r);\n });\n }, 1);\n }, S = () => {\n const { selected: c } = p, g = (c || []).map(({ id: r }) => i.getAnnotation(r));\n g.forEach((r) => {\n const A = u.find((m) => m.id === r.id);\n (!A || !x(A, r)) && b(\"updateAnnotation\", r, A);\n }), u = u.map((r) => {\n const A = g.find(({ id: m }) => m === r.id);\n return A || r;\n });\n };\n p.subscribe(({ selected: c }) => {\n if (!(u.length === 0 && c.length === 0)) {\n if (u.length === 0 && c.length > 0)\n u = c.map(({ id: g }) => i.getAnnotation(g));\n else if (u.length > 0 && c.length === 0)\n u.forEach((g) => {\n const r = i.getAnnotation(g.id);\n r && !x(r, g) && b(\"updateAnnotation\", r, g);\n }), u = [];\n else {\n const g = new Set(u.map((m) => m.id)), r = new Set(c.map(({ id: m }) => m));\n u.filter((m) => !r.has(m.id)).forEach((m) => {\n const R = i.getAnnotation(m.id);\n R && !x(R, m) && b(\"updateAnnotation\", R, m);\n }), u = [\n // Remove annotations that were deselected\n ...u.filter((m) => r.has(m.id)),\n // Add editable annotations that were selected\n ...c.filter(({ id: m }) => !g.has(m)).map(({ id: m }) => i.getAnnotation(m))\n ];\n }\n b(\"selectionChanged\", u);\n }\n }), U.subscribe((c) => {\n !L && c ? b(\"mouseEnterAnnotation\", i.getAnnotation(c)) : L && !c ? b(\"mouseLeaveAnnotation\", i.getAnnotation(L)) : L && c && (b(\"mouseLeaveAnnotation\", i.getAnnotation(L)), b(\"mouseEnterAnnotation\", i.getAnnotation(c))), L = c;\n }), E == null || E.subscribe((c) => b(\"viewportIntersect\", c.map((g) => i.getAnnotation(g)))), i.observe((c) => {\n o && (s && clearTimeout(s), s = setTimeout(S, 1e3));\n const { created: g, deleted: r } = c.changes;\n (g || []).forEach((m) => b(\"createAnnotation\", m)), (r || []).forEach((m) => b(\"deleteAnnotation\", m)), (c.changes.updated || []).filter((m) => [\n ...m.bodiesCreated || [],\n ...m.bodiesDeleted || [],\n ...m.bodiesUpdated || []\n ].length > 0).forEach(({ oldValue: m, newValue: R }) => {\n const I = u.find((N) => N.id === m.id) || m;\n u = u.map((N) => N.id === m.id ? R : N), b(\"updateAnnotation\", R, I);\n });\n }, { origin: O.LOCAL }), i.observe((c) => {\n if (u) {\n const g = new Set(u.map((A) => A.id)), r = (c.changes.updated || []).filter(({ newValue: A }) => g.has(A.id)).map(({ newValue: A }) => A);\n r.length > 0 && (u = u.map((A) => {\n const m = r.find((R) => R.id === A.id);\n return m || A;\n }));\n }\n }, { origin: O.REMOTE });\n const y = (c) => (g) => {\n const { updated: r } = g;\n c ? (r || []).forEach((A) => b(\"updateAnnotation\", A.oldValue, A.newValue)) : (r || []).forEach((A) => b(\"updateAnnotation\", A.newValue, A.oldValue));\n };\n return n.on(\"undo\", y(!0)), n.on(\"redo\", y(!1)), { on: h, off: C, emit: b };\n}, De = (e) => (n) => n.map((t) => e.serialize(t)), re = (e) => (n) => n.reduce((t, o) => {\n const { parsed: i, error: p } = e.parse(o);\n return p ? {\n parsed: t.parsed,\n failed: [...t.failed, o]\n } : i ? {\n parsed: [...t.parsed, i],\n failed: t.failed\n } : {\n ...t\n };\n}, { parsed: [], failed: [] }), Re = (e, n, t) => {\n const { store: o, selection: i } = e, p = (y) => {\n if (t) {\n const { parsed: c, error: g } = t.parse(y);\n c ? o.addAnnotation(c, O.REMOTE) : console.error(g);\n } else\n o.addAnnotation(y, O.REMOTE);\n }, U = () => i.clear(), E = () => o.clear(), w = (y) => {\n const c = o.getAnnotation(y);\n return t && c ? t.serialize(c) : c;\n }, u = () => t ? o.all().map(t.serialize) : o.all(), L = () => {\n var g;\n const c = (((g = i.selected) == null ? void 0 : g.map((r) => r.id)) || []).map((r) => o.getAnnotation(r)).filter(Boolean);\n return t ? c.map(t.serialize) : c;\n }, s = (y, c = !0) => fetch(y).then((g) => g.json()).then((g) => (C(g, c), g)), h = (y) => {\n if (typeof y == \"string\") {\n const c = o.getAnnotation(y);\n if (o.deleteAnnotation(y), c)\n return t ? t.serialize(c) : c;\n } else {\n const c = t ? t.parse(y).parsed : y;\n if (c)\n return o.deleteAnnotation(c), y;\n }\n }, C = (y, c = !0) => {\n if (t) {\n const { parsed: g, failed: r } = re(t)(y);\n r.length > 0 && console.warn(`Discarded ${r.length} invalid annotations`, r), o.bulkAddAnnotation(g, c, O.REMOTE);\n } else\n o.bulkAddAnnotation(y, c, O.REMOTE);\n }, b = (y) => {\n y ? i.setSelected(y) : i.clear();\n }, S = (y) => {\n if (t) {\n const c = t.parse(y).parsed, g = t.serialize(o.getAnnotation(c.id));\n return o.updateAnnotation(c), g;\n } else {\n const c = o.getAnnotation(y.id);\n return o.updateAnnotation(y), c;\n }\n };\n return {\n addAnnotation: p,\n cancelSelected: U,\n canRedo: n.canRedo,\n canUndo: n.canUndo,\n clearAnnotations: E,\n getAnnotationById: w,\n getAnnotations: u,\n getSelected: L,\n loadAnnotations: s,\n redo: n.redo,\n removeAnnotation: h,\n setAnnotations: C,\n setSelected: b,\n undo: n.undo,\n updateAnnotation: S\n };\n}, ae = \"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict\";\nlet ce = (e) => crypto.getRandomValues(new Uint8Array(e)), le = (e, n, t) => {\n let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * n / e.length);\n return (p = n) => {\n let U = \"\";\n for (; ; ) {\n let E = t(i), w = i;\n for (; w--; )\n if (U += e[E[w] & o] || \"\", U.length === p)\n return U;\n }\n };\n}, ue = (e, n = 21) => le(e, n, ce), fe = (e = 21) => {\n let n = \"\", t = crypto.getRandomValues(new Uint8Array(e));\n for (; e--; )\n n += ae[t[e] & 63];\n return n;\n};\nconst Be = () => ({ isGuest: !0, id: ue(\"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\", 20)() }), pe = (e) => {\n const n = JSON.stringify(e);\n let t = 0;\n for (let o = 0, i = n.length; o < i; o++) {\n let p = n.charCodeAt(o);\n t = (t << 5) - t + p, t |= 0;\n }\n return `${t}`;\n}, he = (e) => e ? typeof e == \"object\" ? { ...e } : e : void 0, xe = (e, n) => (Array.isArray(e) ? e : [e]).map((t) => {\n const { id: o, type: i, purpose: p, value: U, created: E, creator: w, ...u } = t;\n return {\n id: o || `temp-${pe(t)}`,\n annotation: n,\n type: i,\n purpose: p,\n value: U,\n created: E ? new Date(E) : void 0,\n creator: he(w),\n ...u\n };\n}), Ie = (e) => e.map((n) => {\n var o, i;\n const t = { ...n };\n return delete t.annotation, (o = t.id) != null && o.startsWith(\"temp-\") && delete t.id, { ...t, created: (i = t.created) == null ? void 0 : i.toISOString() };\n}), ge = [\n \"#ff7c00\",\n // orange\n \"#1ac938\",\n // green\n \"#e8000b\",\n // red\n \"#8b2be2\",\n // purple\n \"#9f4800\",\n // brown\n \"#f14cc1\",\n // pink\n \"#ffc400\",\n // khaki\n \"#00d7ff\",\n // cyan\n \"#023eff\"\n // blue\n], me = () => {\n const e = [...ge];\n return { assignRandomColor: () => {\n const o = Math.floor(Math.random() * e.length), i = e[o];\n return e.splice(o, 1), i;\n }, releaseColor: (o) => e.push(o) };\n}, Ae = () => {\n const e = me();\n return { addUser: (o, i) => {\n const p = e.assignRandomColor();\n return {\n label: i.name || i.id,\n avatar: i.avatar,\n color: p\n };\n }, removeUser: (o) => e.releaseColor(o.appearance.color) };\n}, be = (e, n) => e.every((t) => e.includes(t)) && n.every((t) => e.includes(t)), ke = fe(), Ne = (e = Ae()) => {\n const n = P(), t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = (s, h) => {\n if (t.has(s)) {\n console.warn(\"Attempt to add user that is already present\", s, h);\n return;\n }\n const C = e.addUser(s, h);\n t.set(s, {\n ...h,\n presenceKey: s,\n appearance: C\n });\n }, p = (s) => {\n const h = t.get(s);\n if (!h) {\n console.warn(\"Attempt to remove user that is not present\", s);\n return;\n }\n e.removeUser(h), t.delete(s);\n }, U = (s) => {\n const h = new Set(s.map((S) => S.presenceKey)), C = s.filter(({ presenceKey: S }) => !t.has(S)), b = Array.from(t.values()).filter((S) => !h.has(S.presenceKey));\n C.forEach(({ presenceKey: S, user: y }) => i(S, y)), b.forEach((S) => {\n const { presenceKey: y } = S;\n o.has(y) && n.emit(\"selectionChange\", S, null), p(y);\n }), (C.length > 0 || b.length > 0) && n.emit(\"presence\", u());\n }, E = (s, h) => {\n const C = t.get(s);\n if (!C) {\n console.warn(\"Activity notification from user that is not present\");\n return;\n }\n const b = o.get(s);\n (!b || !be(b, h)) && (o.set(s, h), n.emit(\"selectionChange\", C, h));\n }, w = (s, h) => {\n const C = t.get(s);\n if (!C) {\n console.warn(\"Selection change for user that is not present\", s);\n return;\n }\n h ? o.set(s, h) : o.delete(s), n.emit(\"selectionChange\", C, h);\n }, u = () => [...Array.from(t.values())];\n return {\n getPresentUsers: u,\n notifyActivity: E,\n on: (s, h) => n.on(s, h),\n syncUsers: U,\n updateSelection: w\n };\n};\nexport {\n ne as Ignore,\n O as Origin,\n ke as PRESENCE_KEY,\n q as PointerSelectAction,\n Be as createAnonymousGuest,\n Re as createBaseAnnotator,\n Ce as createBody,\n Ae as createDefaultAppearenceProvider,\n ve as createHoverState,\n Te as createLifecyleObserver,\n Ne as createPresenceState,\n ye as createSelectionState,\n Ue as createStore,\n Se as createUndoStack,\n Oe as createViewportState,\n me as defaultColorProvider,\n M as diffAnnotations,\n we as getContributors,\n se as mergeChanges,\n G as onPointerSelect,\n re as parseAll,\n xe as parseW3CBodies,\n he as parseW3CUser,\n De as serializeAll,\n Ie as serializeW3CBodies,\n oe as shouldNotify,\n Le as toSvelteStore\n};\n//# sourceMappingURL=annotorious-core.es.js.map\n"],"names":["q","e","$","H","F","D","J","n","Q","j","X","t","o","i","Ce","O","ae","ce","le","p","U","E","w","ue","fe","Be","ge","me"],"mappings":"AA2EG,IAACA,IAAqB,kBAACC,OAAOA,EAAE,OAAO,QAAQA,EAAE,SAAS,UAAUA,EAAE,OAAO,QAAQA,IAAID,KAAK,EAAE;AA4CnG,IAAIE;AACJ,MAAMC,IAAI,IAAI,WAAW,EAAE;AAC3B,SAASC,IAAI;AACX,MAAI,CAACF,MAAMA,IAAI,OAAO,SAAS,OAAO,OAAO,mBAAmB,OAAO,gBAAgB,KAAK,MAAM,GAAG,CAACA;AACpG,UAAM,IAAI,MAAM,0GAA0G;AAC5H,SAAOA,EAAEC,CAAC;AACZ;AACA,MAAME,IAAI,CAAA;AACV,SAASJ,IAAI,GAAGA,IAAI,KAAK,EAAEA;AACzB,EAAAI,EAAE,MAAMJ,IAAI,KAAK,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AACxC,SAASK,EAAEL,GAAGM,IAAI,GAAG;AACnB,SAAOF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAI,MAAMF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAI,MAAMF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAI,MAAMF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAI,MAAMF,EAAEJ,EAAEM,IAAI,EAAE,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,EAAE,CAAC,IAAIF,E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AO,GAAGY,IAAI,CAAC,EAAE,MAAMD,IAAIL,IAAIN,EAAE;AAC7E,SAAO,CAACkB,IAAIZ,MAAM;AAChB,QAAIa,IAAI;AACR,eAAW;AACT,UAAIC,IAAIV,EAAEE,CAAC,GAAGS,IAAIT;AAClB,aAAOS;AACL,YAAIF,KAAKnB,EAAEoB,EAAEC,CAAC,IAAIV,CAAC,KAAK,IAAIQ,EAAE,WAAWD;AACvC,iBAAOC;AAAA,IACZ;AAAA,EACL;AACA,GAAGG,IAAK,CAACtB,GAAGM,IAAI,OAAOW,EAAGjB,GAAGM,GAAGU,CAAE,GAAGO,IAAK,CAACvB,IAAI,OAAO;AACpD,MAAIM,IAAI,IAAII,IAAI,OAAO,gBAAgB,IAAI,WAAWV,CAAC,CAAC;AACxD,SAAOA;AACL,IAAAM,KAAKS,EAAGL,EAAEV,CAAC,IAAI,EAAE;AACnB,SAAOM;AACT;AACK,MAACkB,IAAK,OAAO,EAAE,SAAS,IAAI,IAAIF,EAAG,mEAAmE,EAAE,EAAC,MAwB1GG,IAAK;AAAA,EACP;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAEF,GAAGC,IAAK,MAAM;AACZ,QAAM1B,IAAI,CAAC,GAAGyB,CAAE;AAChB,SAAO,EAAE,mBAAmB,MAAM;AAChC,UAAMd,IAAI,KAAK,MAAM,KAAK,OAAM,IAAKX,EAAE,MAAM,GAAGY,IAAIZ,EAAEW,CAAC;AACvD,WAAOX,EAAE,OAAOW,GAAG,CAAC,GAAGC;AAAA,EAC3B,GAAK,cAAc,CAACD,MAAMX,EAAE,KAAKW,CAAC;AAClC;AAUuFY,EAAI;"}
1
+ {"version":3,"file":"annotorious-react.es8.js","sources":["../../annotorious-core/src/model/Annotator.ts"],"sourcesContent":["import type { Annotation } from './Annotation';\nimport type { User } from './User';\nimport type { PresenceProvider } from '../presence';\nimport { Origin, type HoverState, type SelectionState, type Store, type UndoStack, type ViewportState } from '../state';\nimport type { LifecycleEvents } from '../lifecycle';\nimport { parseAll, type FormatAdapter } from './FormatAdapter';\nimport type { DrawingStyle } from './DrawingStyle';\nimport type { Filter } from './Filter';\n\n/**\n * Base annotator interface.\n * I ... internal core data model \n * E ... external adapted representation\n */\nexport interface Annotator<I extends Annotation = Annotation, E extends unknown = Annotation> {\n\n addAnnotation(annotation: E): void;\n\n clearAnnotations(): void;\n\n destroy(): void;\n\n getAnnotationById(id: string): E | undefined;\n\n getAnnotations(): E[];\n\n getUser(): User;\n\n loadAnnotations(url: string): Promise<E[]>;\n\n redo(): void;\n\n removeAnnotation(arg: E | string): E;\n\n setAnnotations(annotations: E[]): void;\n\n setFilter(filter: Filter): void;\n\n setPresenceProvider?(provider: PresenceProvider): void;\n\n setSelected(arg?: string | string[]): void;\n\n setStyle(arg: DrawingStyle | ((annotation: I) => DrawingStyle) | undefined): void;\n\n setUser(user: User): 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 store: Store<I>, \n undoStack: UndoStack,\n adapter?: FormatAdapter<I, E>\n) => {\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 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 loadAnnotations = (url: string) =>\n fetch(url)\n .then((response) => response.json())\n .then((annotations) => {\n setAnnotations(annotations);\n return annotations;\n });\n\n const removeAnnotation = (arg: E | string): E => {\n if (typeof arg === 'string') {\n const annotation = store.getAnnotation(arg);\n store.deleteAnnotation(arg);\n\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 store.deleteAnnotation(annotation);\n return arg;\n }\n }\n\n const setAnnotations = (annotations: E[]) => {\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, true, Origin.REMOTE);\n } else {\n store.bulkAddAnnotation(annotations as unknown as I[], true, Origin.REMOTE);\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 return { \n addAnnotation,\n clearAnnotations,\n getAnnotationById,\n getAnnotations,\n loadAnnotations,\n redo: undoStack.redo,\n removeAnnotation,\n setAnnotations,\n undo: undoStack.undo,\n updateAnnotation\n }\n\n}"],"names":["createBaseAnnotator","store","undoStack","adapter","addAnnotation","annotation","parsed","error","Origin","clearAnnotations","getAnnotationById","id","getAnnotations","loadAnnotations","url","response","annotations","setAnnotations","removeAnnotation","arg","failed","parseAll","updateAnnotation","updated","crosswalked","previous"],"mappings":";;AAsEO,MAAMA,IAAsB,CACj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