@annotorious/react 3.0.0-rc.2 → 3.0.0-rc.21

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 (76) hide show
  1. package/dist/Annotorious.d.ts +3 -27
  2. package/dist/Annotorious.d.ts.map +1 -1
  3. package/dist/AnnotoriousPlugin.d.ts +7 -6
  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 +33 -34
  8. package/dist/annotorious-react.es.js.map +1 -1
  9. package/dist/annotorious-react.es10.js +29 -2
  10. package/dist/annotorious-react.es10.js.map +1 -1
  11. package/dist/annotorious-react.es11.js +36 -9
  12. package/dist/annotorious-react.es11.js.map +1 -1
  13. package/dist/annotorious-react.es12.js +16 -2
  14. package/dist/annotorious-react.es12.js.map +1 -1
  15. package/dist/annotorious-react.es13.js +6 -3752
  16. package/dist/annotorious-react.es13.js.map +1 -1
  17. package/dist/annotorious-react.es14.js +7 -28
  18. package/dist/annotorious-react.es14.js.map +1 -1
  19. package/dist/annotorious-react.es15.js +152 -35
  20. package/dist/annotorious-react.es15.js.map +1 -1
  21. package/dist/annotorious-react.es16.js +27433 -13
  22. package/dist/annotorious-react.es16.js.map +1 -1
  23. package/dist/annotorious-react.es17.js +32 -4
  24. package/dist/annotorious-react.es17.js.map +1 -1
  25. package/dist/annotorious-react.es18.js +2 -8
  26. package/dist/annotorious-react.es18.js.map +1 -1
  27. package/dist/annotorious-react.es19.js +29 -152
  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 +599 -6
  32. package/dist/annotorious-react.es20.js.map +1 -1
  33. package/dist/annotorious-react.es21.js +2 -2
  34. package/dist/annotorious-react.es22.js +2 -30
  35. package/dist/annotorious-react.es22.js.map +1 -1
  36. package/dist/annotorious-react.es3.js +7 -7
  37. package/dist/annotorious-react.es3.js.map +1 -1
  38. package/dist/annotorious-react.es4.js +8 -8
  39. package/dist/annotorious-react.es4.js.map +1 -1
  40. package/dist/annotorious-react.es5.js +10 -10
  41. package/dist/annotorious-react.es5.js.map +1 -1
  42. package/dist/annotorious-react.es6.js +1 -4
  43. package/dist/annotorious-react.es6.js.map +1 -1
  44. package/dist/annotorious-react.es7.js +1 -4
  45. package/dist/annotorious-react.es7.js.map +1 -1
  46. package/dist/annotorious-react.es8.js +86 -7
  47. package/dist/annotorious-react.es8.js.map +1 -1
  48. package/dist/annotorious-react.es9.js +4241 -2
  49. package/dist/annotorious-react.es9.js.map +1 -1
  50. package/dist/index.d.ts +11 -12
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/openseadragon/OpenSeadragonAnnotator.d.ts.map +1 -1
  53. package/dist/openseadragon/setPosition.d.ts.map +1 -1
  54. package/package.json +16 -8
  55. package/dist/annotorious-react.es23.js +0 -602
  56. package/dist/annotorious-react.es23.js.map +0 -1
  57. package/dist/annotorious-react.es24.js +0 -20611
  58. package/dist/annotorious-react.es24.js.map +0 -1
  59. package/dist/annotorious-react.es25.js +0 -35
  60. package/dist/annotorious-react.es25.js.map +0 -1
  61. package/dist/annotorious-react.es26.js +0 -5
  62. package/dist/annotorious-react.es26.js.map +0 -1
  63. package/dist/annotorious-react.es27.js +0 -5
  64. package/dist/annotorious-react.es27.js.map +0 -1
  65. package/dist/annotorious-react.es28.js +0 -24
  66. package/dist/annotorious-react.es28.js.map +0 -1
  67. package/dist/annotorious-react.es29.js +0 -5
  68. package/dist/annotorious-react.es29.js.map +0 -1
  69. package/dist/annotorious-react.es30.js +0 -20
  70. package/dist/annotorious-react.es30.js.map +0 -1
  71. package/dist/annotorious-react.es31.js +0 -7
  72. package/dist/annotorious-react.es31.js.map +0 -1
  73. package/dist/annotorious-react.es32.js +0 -11
  74. package/dist/annotorious-react.es32.js.map +0 -1
  75. package/dist/annotorious-react.es33.js +0 -10
  76. package/dist/annotorious-react.es33.js.map +0 -1
@@ -1,7 +1,35 @@
1
- import { j as t } from "./annotorious-react.es20.js";
2
- const o = t.Fragment, r = t.jsx;
1
+ import b from "openseadragon";
2
+ const L = (h, x) => {
3
+ const { minX: e, minY: n, maxX: i, maxY: t } = x.target.selector.geometry.bounds, l = h.viewport.imageToViewerElementCoordinates(new b.Point(e, n)), s = h.viewport.imageToViewerElementCoordinates(new b.Point(i, t));
4
+ return {
5
+ x: l.x,
6
+ right: s.x,
7
+ y: l.y,
8
+ bottom: s.y,
9
+ width: s.x - l.x,
10
+ height: s.y - l.y
11
+ };
12
+ }, T = (h, x, e, n = 5) => {
13
+ const i = h.element.getBoundingClientRect(), t = L(h, x), l = t.y - i.y, s = i.right - t.x, w = i.bottom - t.bottom, $ = t.x - i.left, o = e.firstElementChild.getBoundingClientRect(), c = l / o.height, a = s / o.width, g = w / o.height, r = $ / o.width, d = () => {
14
+ e.style.left = `${t.x}px`, e.style.top = `${t.y - n - o.height}px`;
15
+ }, f = () => {
16
+ e.style.left = `${t.right - o.width}px`, e.style.top = `${t.y - n - o.height}px`;
17
+ }, v = () => {
18
+ e.style.left = `${t.x - o.width - n}px`, e.style.top = `${t.y}px`;
19
+ }, B = () => {
20
+ e.style.left = `${t.right + n}px`, e.style.top = `${t.y}px`;
21
+ }, R = () => {
22
+ e.style.left = `${t.x - o.width - n}px`, e.style.top = `${t.bottom - o.height}px`;
23
+ }, C = () => {
24
+ e.style.left = `${t.x + t.width + n}px`, e.style.top = `${t.bottom - o.height}px`;
25
+ }, A = () => {
26
+ e.style.left = `${t.x}px`, e.style.top = `${t.bottom + n}px`;
27
+ }, E = () => {
28
+ e.style.left = `${t.right - o.width}px`, e.style.top = `${t.bottom + n}px`;
29
+ }, m = [c, a, g, r], y = m.indexOf(Math.max(...m));
30
+ y === 0 ? a > r ? d() : f() : y === 1 ? c > g ? C() : B() : y === 2 ? a > r ? A() : E() : c > g ? R() : v();
31
+ };
3
32
  export {
4
- o as Fragment,
5
- r as jsx
33
+ T as setPosition
6
34
  };
7
35
  //# sourceMappingURL=annotorious-react.es17.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es17.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"annotorious-react.es17.js","sources":["../src/openseadragon/setPosition.ts"],"sourcesContent":["import { ImageAnnotation } from '@annotorious/annotorious';\nimport OpenSeadragon from 'openseadragon';\n\nconst getAnnotationDomRect = (viewer: OpenSeadragon.Viewer, annotation: ImageAnnotation) => {\n // Annotation bounds (image coordinates)\n const { minX, minY, maxX, maxY } = annotation.target.selector.geometry.bounds;\n\n // Annotation coordinates - viewer element coordinates\n const topLeft = viewer.viewport.imageToViewerElementCoordinates(new OpenSeadragon.Point(minX, minY));\n const bottomRight = viewer.viewport.imageToViewerElementCoordinates(new OpenSeadragon.Point(maxX, maxY));\n\n // Account for viewer element offset\n return {\n x: topLeft.x,\n right: bottomRight.x,\n y: topLeft.y, \n bottom: bottomRight.y,\n width: bottomRight.x - topLeft.x,\n height: bottomRight.y - topLeft.y,\n };\n}\n\nexport const setPosition = (\n viewer: OpenSeadragon.Viewer, \n annotation: ImageAnnotation, \n popup: HTMLElement,\n sideOffset: number = 5\n) => {\n const viewerBounds = viewer.element.getBoundingClientRect();\n const annoBounds = getAnnotationDomRect(viewer, annotation);\n\n // Available space above, right, below, left the annotation in the viewport\n const availableAbove = annoBounds.y - viewerBounds.y;\n const availableRight = viewerBounds.right - annoBounds.x;\n const availableBelow = viewerBounds.bottom - annoBounds.bottom;\n const availableLeft = annoBounds.x - viewerBounds.left;\n\n // Popup element bounds\n const popupBounds = popup.firstElementChild.getBoundingClientRect();\n\n // Eight possible base alignment anchor points\n //\n // topleft topright\n // * *\n // leftdown * |---------------------| * rightdown\n // | |\n // | |\n // | |\n // leftup * |---------------------| * rightup\n // * * \n // bottomleft bottomright\n //\n // We'll position the popup at the cardinal direction\n // with the highest ratio: available space vs. popup size.\n const ratioAbove = availableAbove / popupBounds.height;\n const ratioRight = availableRight / popupBounds.width;\n const ratioBelow = availableBelow / popupBounds.height;\n const ratioLeft = availableLeft / popupBounds.width;\n\n const topleft = () => {\n popup.style.left = `${annoBounds.x}px`;\n popup.style.top = `${annoBounds.y - sideOffset - popupBounds.height}px`;\n }\n\n const topright = () => {\n popup.style.left = `${annoBounds.right - popupBounds.width}px`;\n popup.style.top = `${annoBounds.y - sideOffset - popupBounds.height}px`;\n }\n\n const leftdown = () => {\n popup.style.left = `${annoBounds.x - popupBounds.width - sideOffset}px`;\n popup.style.top = `${annoBounds.y}px`;\n } \n\n const rightdown = () => {\n popup.style.left = `${annoBounds.right + sideOffset}px`;\n popup.style.top = `${annoBounds.y}px`;\n }\n\n const leftup = () => {\n popup.style.left = `${annoBounds.x - popupBounds.width - sideOffset}px`;\n popup.style.top = `${annoBounds.bottom - popupBounds.height}px`;\n }\n\n const rightup = () => {\n popup.style.left = `${annoBounds.x + annoBounds.width + sideOffset}px`;\n popup.style.top = `${annoBounds.bottom - popupBounds.height}px`;\n }\n\n const bottomleft = () => {\n popup.style.left = `${annoBounds.x}px`;\n popup.style.top = `${annoBounds.bottom + sideOffset}px`;\n }\n\n const bottomright = () => {\n popup.style.left = `${annoBounds.right - popupBounds.width}px`;\n popup.style.top = `${annoBounds.bottom + sideOffset}px`;\n }\n\n const ratios = [ratioAbove, ratioRight, ratioBelow, ratioLeft];\n const maxIdx = ratios.indexOf(Math.max(...ratios));\n\n if (maxIdx === 0) {\n // Main orientation: above\n if (ratioRight > ratioLeft)\n topleft();\n else \n topright();\n } else if (maxIdx === 1) {\n // Main orientation: right\n if (ratioAbove > ratioBelow)\n rightup();\n else\n rightdown();\n } else if (maxIdx === 2) {\n // Main orientation: below\n if (ratioRight > ratioLeft)\n bottomleft();\n else\n bottomright();\n } else {\n // Main orientation: left\n if (ratioAbove > ratioBelow)\n leftup();\n else \n leftdown();\n }\n}"],"names":["getAnnotationDomRect","viewer","annotation","minX","minY","maxX","maxY","topLeft","OpenSeadragon","bottomRight","setPosition","popup","sideOffset","viewerBounds","annoBounds","availableAbove","availableRight","availableBelow","availableLeft","popupBounds","ratioAbove","ratioRight","ratioBelow","ratioLeft","topleft","topright","leftdown","rightdown","leftup","rightup","bottomleft","bottomright","ratios","maxIdx"],"mappings":";AAGA,MAAMA,IAAuB,CAACC,GAA8BC,MAAgC;AAEpF,QAAA,EAAE,MAAAC,GAAM,MAAAC,GAAM,MAAAC,GAAM,MAAAC,MAASJ,EAAW,OAAO,SAAS,SAAS,QAGjEK,IAAUN,EAAO,SAAS,gCAAgC,IAAIO,EAAc,MAAML,GAAMC,CAAI,CAAC,GAC7FK,IAAcR,EAAO,SAAS,gCAAgC,IAAIO,EAAc,MAAMH,GAAMC,CAAI,CAAC;AAGhG,SAAA;AAAA,IACL,GAAGC,EAAQ;AAAA,IACX,OAAOE,EAAY;AAAA,IACnB,GAAGF,EAAQ;AAAA,IACX,QAAQE,EAAY;AAAA,IACpB,OAAOA,EAAY,IAAKF,EAAQ;AAAA,IAChC,QAAQE,EAAY,IAAIF,EAAQ;AAAA,EAAA;AAEpC,GAEaG,IAAc,CACzBT,GACAC,GACAS,GACAC,IAAqB,MAClB;AACG,QAAAC,IAAeZ,EAAO,QAAQ,sBAAsB,GACpDa,IAAad,EAAqBC,GAAQC,CAAU,GAGpDa,IAAiBD,EAAW,IAAID,EAAa,GAC7CG,IAAiBH,EAAa,QAAQC,EAAW,GACjDG,IAAiBJ,EAAa,SAASC,EAAW,QAClDI,IAAgBJ,EAAW,IAAID,EAAa,MAG5CM,IAAcR,EAAM,kBAAkB,sBAAsB,GAgB5DS,IAAaL,IAAiBI,EAAY,QAC1CE,IAAaL,IAAiBG,EAAY,OAC1CG,IAAaL,IAAiBE,EAAY,QAC1CI,IAAYL,IAAgBC,EAAY,OAExCK,IAAU,MAAM;AACpB,IAAAb,EAAM,MAAM,OAAO,GAAGG,EAAW,CAAC,MAClCH,EAAM,MAAM,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MAAW,IAETZ,IAAaE,IACPC,MAECC,MACFQ,MAAW,IAEhBb,IAAaE,IACPO,MAEEF,MACHM,MAAW,IAEhBZ,IAAaE,IACJO,MAECC,MAGVX,IAAaE,IACRM,MAEEF;AAEf;"}
@@ -1,11 +1,5 @@
1
- import { useState as c, useRef as n, useEffect as s } from "react";
2
- const m = (e, t) => {
3
- const [u, o] = c(e), r = n();
4
- return s(() => (r.current = setTimeout(() => o(e), t), () => {
5
- clearTimeout(r.current);
6
- }), [e, t]), u;
7
- };
1
+ var e = { exports: {} };
8
2
  export {
9
- m as useDebounce
3
+ e as __module
10
4
  };
11
5
  //# sourceMappingURL=annotorious-react.es18.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es18.js","sources":["../src/useDebounce.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nexport const useDebounce = (value: any, delay: number) => {\n const [debouncedValue, setDebouncedValue] = useState<any>(value);\n\n const timerRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n timerRef.current = \n setTimeout(() => setDebouncedValue(value), delay);\n\n return () => {\n clearTimeout(timerRef.current);\n };\n }, [value, delay]);\n\n return debouncedValue;\n}"],"names":["useDebounce","value","delay","debouncedValue","setDebouncedValue","useState","timerRef","useRef","useEffect"],"mappings":";AAEa,MAAAA,IAAc,CAACC,GAAYC,MAAkB;AACxD,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAcJ,CAAK,GAEzDK,IAAWC;AAEjB,SAAAC,EAAU,OACRF,EAAS,UACP,WAAW,MAAMF,EAAkBH,CAAK,GAAGC,CAAK,GAE3C,MAAM;AACX,iBAAaI,EAAS,OAAO;AAAA,EAAA,IAE9B,CAACL,GAAOC,CAAK,CAAC,GAEVC;AACT;"}
1
+ {"version":3,"file":"annotorious-react.es18.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,156 +1,33 @@
1
- import { useRef as ge, useState as ae, useEffect as ie } from "react";
2
- var O = { dragStart: !0 }, he = (e, t = {}) => {
3
- let o, c, { bounds: l, axis: m = "both", gpuAcceleration: f = !0, legacyTranslate: B = !0, transform: M, applyUserSelectHack: N = !0, disabled: R = !1, ignoreMultitouch: $ = !1, recomputeBounds: b = O, grid: H, position: u, cancel: D, handle: E, defaultClass: S = "neodrag", defaultClassDragging: i = "neodrag-dragging", defaultClassDragged: g = "neodrag-dragged", defaultPosition: W = { x: 0, y: 0 }, onDragStart: ce, onDrag: le, onDragEnd: ue } = t, X = !1, x = 0, A = 0, L = 0, T = 0, j = 0, z = 0, { x: Y, y: q } = u ? { x: (u == null ? void 0 : u.x) ?? 0, y: (u == null ? void 0 : u.y) ?? 0 } : W;
4
- I(Y, q);
5
- let y, C, P, F, _, ee = "", fe = !!u;
6
- b = { ...O, ...b };
7
- const G = document.body.style, v = e.classList;
8
- function I(n = x, a = A) {
9
- if (!M) {
10
- if (B) {
11
- let d = `${+n}px, ${+a}px`;
12
- return k(e, "transform", f ? `translate3d(${d}, 0)` : `translate(${d})`);
13
- }
14
- return k(e, "translate", `${+n}px ${+a}px ${f ? "1px" : ""}`);
15
- }
16
- const s = M({ offsetX: n, offsetY: a, rootNode: e });
17
- Q(s) && k(e, "transform", s);
18
- }
19
- const J = (n, a) => {
20
- const s = { offsetX: x, offsetY: A, rootNode: e, currentNode: _ };
21
- e.dispatchEvent(new CustomEvent(n, { detail: s })), a == null || a(s);
22
- }, K = addEventListener;
23
- K("pointerdown", re, !1), K("pointerup", te, !1), K("pointermove", oe, !1), k(e, "touch-action", "none");
24
- const ne = () => {
25
- let n = e.offsetWidth / C.width;
26
- return isNaN(n) && (n = 1), n;
27
- };
28
- function re(n) {
29
- if (R || n.button === 2 || $ && !n.isPrimary)
30
- return;
31
- if (b.dragStart && (y = V(l, e)), Q(E) && Q(D) && E === D)
32
- throw new Error("`handle` selector can't be same as `cancel` selector");
33
- if (v.add(S), P = function(r, p) {
34
- if (!r)
35
- return [p];
36
- if (Z(r))
37
- return [r];
38
- if (Array.isArray(r))
39
- return r;
40
- const w = p.querySelectorAll(r);
41
- if (w === null)
42
- throw new Error("Selector passed for `handle` option should be child of the element on which the action is applied");
43
- return Array.from(w.values());
44
- }(E, e), F = function(r, p) {
45
- if (!r)
46
- return [];
47
- if (Z(r))
48
- return [r];
49
- if (Array.isArray(r))
50
- return r;
51
- const w = p.querySelectorAll(r);
52
- if (w === null)
53
- throw new Error("Selector passed for `cancel` option should be child of the element on which the action is applied");
54
- return Array.from(w.values());
55
- }(D, e), o = /(both|x)/.test(m), c = /(both|y)/.test(m), de(F, P))
56
- throw new Error("Element being dragged can't be a child of the element on which `cancel` is applied");
57
- const a = n.composedPath()[0];
58
- if (!P.some((r) => {
59
- var p;
60
- return r.contains(a) || ((p = r.shadowRoot) == null ? void 0 : p.contains(a));
61
- }) || de(F, [a]))
62
- return;
63
- _ = P.length === 1 ? e : P.find((r) => r.contains(a)), X = !0, C = e.getBoundingClientRect(), N && (ee = G.userSelect, G.userSelect = "none"), J("neodrag:start", ce);
64
- const { clientX: s, clientY: d } = n, h = ne();
65
- o && (L = s - Y / h), c && (T = d - q / h), y && (j = s - C.left, z = d - C.top);
66
- }
67
- function te() {
68
- X && (b.dragEnd && (y = V(l, e)), v.remove(i), v.add(g), N && (G.userSelect = ee), J("neodrag:end", ue), o && (L = x), c && (T = A), X = !1);
69
- }
70
- function oe(n) {
71
- if (!X)
72
- return;
73
- b.drag && (y = V(l, e)), v.add(i), n.preventDefault(), C = e.getBoundingClientRect();
74
- let a = n.clientX, s = n.clientY;
75
- const d = ne();
76
- if (y) {
77
- const h = { left: y.left + j, top: y.top + z, right: y.right + j - C.width, bottom: y.bottom + z - C.height };
78
- a = se(a, h.left, h.right), s = se(s, h.top, h.bottom);
79
- }
80
- if (Array.isArray(H)) {
81
- let [h, r] = H;
82
- if (isNaN(+h) || h < 0)
83
- throw new Error("1st argument of `grid` must be a valid positive number");
84
- if (isNaN(+r) || r < 0)
85
- throw new Error("2nd argument of `grid` must be a valid positive number");
86
- let p = a - L, w = s - T;
87
- [p, w] = pe([h / d, r / d], p, w), a = L + p, s = T + w;
88
- }
89
- o && (x = Math.round((a - L) * d)), c && (A = Math.round((s - T) * d)), Y = x, q = A, J("neodrag", le), I();
90
- }
91
- return { destroy: () => {
92
- const n = removeEventListener;
93
- n("pointerdown", re, !1), n("pointerup", te, !1), n("pointermove", oe, !1);
94
- }, update: (n) => {
95
- var s, d;
96
- m = n.axis || "both", R = n.disabled ?? !1, $ = n.ignoreMultitouch ?? !1, E = n.handle, l = n.bounds, b = n.recomputeBounds ?? O, D = n.cancel, N = n.applyUserSelectHack ?? !0, H = n.grid, f = n.gpuAcceleration ?? !0, B = n.legacyTranslate ?? !0, M = n.transform;
97
- const a = v.contains(g);
98
- v.remove(S, g), S = n.defaultClass ?? "neodrag", i = n.defaultClassDragging ?? "neodrag-dragging", g = n.defaultClassDragged ?? "neodrag-dragged", v.add(S), a && v.add(g), fe && (Y = x = ((s = n.position) == null ? void 0 : s.x) ?? x, q = A = ((d = n.position) == null ? void 0 : d.y) ?? A, I());
99
- } };
100
- }, se = (e, t, o) => Math.min(Math.max(e, t), o), Q = (e) => typeof e == "string", pe = ([e, t], o, c) => {
101
- const l = (m, f) => f === 0 ? 0 : Math.ceil(m / f) * f;
102
- return [l(o, e), l(c, t)];
103
- }, de = (e, t) => e.some((o) => t.some((c) => o.contains(c)));
104
- function V(e, t) {
105
- if (e === void 0)
106
- return;
107
- if (Z(e))
108
- return e.getBoundingClientRect();
109
- if (typeof e == "object") {
110
- const { top: c = 0, left: l = 0, right: m = 0, bottom: f = 0 } = e;
111
- return { top: c, right: window.innerWidth - m, bottom: window.innerHeight - f, left: l };
112
- }
113
- if (e === "parent")
114
- return t.parentNode.getBoundingClientRect();
115
- const o = document.querySelector(e);
116
- if (o === null)
117
- throw new Error("The selector provided for bound doesn't exists in the document.");
118
- return o.getBoundingClientRect();
119
- }
120
- var k = (e, t, o) => e.style.setProperty(t, o), Z = (e) => e instanceof HTMLElement;
121
- function U(e) {
122
- return e == null || typeof e == "string" || e instanceof HTMLElement ? e : "current" in e ? e.current : Array.isArray(e) ? e.map((t) => t instanceof HTMLElement ? t : t.current) : void 0;
123
- }
124
- function ye(e, t = {}) {
125
- const o = ge(), [c, l] = ae(!1), [m, f] = ae();
126
- let { onDragStart: B, onDrag: M, onDragEnd: N, handle: R, cancel: $ } = t, b = U(R), H = U($);
127
- function u(i, g) {
128
- f(i), g == null || g(i);
129
- }
130
- function D(i) {
131
- l(!0), u(i, B);
132
- }
133
- function E(i) {
134
- u(i, M);
135
- }
136
- function S(i) {
137
- l(!1), u(i, N);
138
- }
139
- return ie(() => {
140
- if (typeof window > "u")
141
- return;
142
- const i = e.current;
143
- if (!i)
144
- return;
145
- ({ onDragStart: B, onDrag: M, onDragEnd: N } = t);
146
- const { update: g, destroy: W } = he(i, { ...t, handle: b, cancel: H, onDragStart: D, onDrag: E, onDragEnd: S });
147
- return o.current = g, W;
148
- }, []), ie(() => {
149
- var i;
150
- (i = o.current) == null || i.call(o, { ...t, handle: U(R), cancel: U($), onDragStart: D, onDrag: E, onDragEnd: S });
151
- }, [t]), { isDragging: c, dragState: m };
1
+ import { __exports as t } from "./annotorious-react.es21.js";
2
+ import R from "react";
3
+ /**
4
+ * @license React
5
+ * react-jsx-runtime.production.min.js
6
+ *
7
+ * Copyright (c) Facebook, Inc. and its affiliates.
8
+ *
9
+ * This source code is licensed under the MIT license found in the
10
+ * LICENSE file in the root directory of this source tree.
11
+ */
12
+ var p;
13
+ function v() {
14
+ if (p)
15
+ return t;
16
+ p = 1;
17
+ var s = R, m = Symbol.for("react.element"), l = Symbol.for("react.fragment"), c = Object.prototype.hasOwnProperty, d = s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, y = { key: !0, ref: !0, __self: !0, __source: !0 };
18
+ function i(o, r, u) {
19
+ var e, n = {}, _ = null, f = null;
20
+ u !== void 0 && (_ = "" + u), r.key !== void 0 && (_ = "" + r.key), r.ref !== void 0 && (f = r.ref);
21
+ for (e in r)
22
+ c.call(r, e) && !y.hasOwnProperty(e) && (n[e] = r[e]);
23
+ if (o && o.defaultProps)
24
+ for (e in r = o.defaultProps, r)
25
+ n[e] === void 0 && (n[e] = r[e]);
26
+ return { $$typeof: m, type: o, key: _, ref: f, props: n, _owner: d.current };
27
+ }
28
+ return t.Fragment = l, t.jsx = i, t.jsxs = i, t;
152
29
  }
153
30
  export {
154
- ye as useDraggable
31
+ v as __require
155
32
  };
156
33
  //# sourceMappingURL=annotorious-react.es19.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es19.js","sources":["../../../node_modules/@neodrag/react/dist/min/index.js"],"sourcesContent":["import{useRef as t,useState as e,useEffect as n}from\"react\";var r={dragStart:!0},o=(t,e={})=>{let n,o,{bounds:f,axis:g=\"both\",gpuAcceleration:h=!0,legacyTranslate:p=!0,transform:m,applyUserSelectHack:y=!0,disabled:w=!1,ignoreMultitouch:b=!1,recomputeBounds:v=r,grid:D,position:E,cancel:S,handle:x,defaultClass:A=\"neodrag\",defaultClassDragging:C=\"neodrag-dragging\",defaultClassDragged:M=\"neodrag-dragged\",defaultPosition:N={x:0,y:0},onDragStart:B,onDrag:$,onDragEnd:H}=e,L=!1,R=0,T=0,P=0,X=0,Y=0,q=0,{x:k,y:U}=E?{x:E?.x??0,y:E?.y??0}:N;Q(k,U);let W,j,z,F,G,I=\"\",J=!!E;v={...r,...v};const K=document.body.style,O=t.classList;function Q(e=R,n=T){if(!m){if(p){let r=`${+e}px, ${+n}px`;return l(t,\"transform\",h?`translate3d(${r}, 0)`:`translate(${r})`)}return l(t,\"translate\",`${+e}px ${+n}px ${h?\"1px\":\"\"}`)}const r=m({offsetX:e,offsetY:n,rootNode:t});i(r)&&l(t,\"transform\",r)}const V=(e,n)=>{const r={offsetX:R,offsetY:T,rootNode:t,currentNode:G};t.dispatchEvent(new CustomEvent(e,{detail:r})),n?.(r)};const Z=addEventListener;Z(\"pointerdown\",tt,!1),Z(\"pointerup\",et,!1),Z(\"pointermove\",nt,!1),l(t,\"touch-action\",\"none\");const _=()=>{let e=t.offsetWidth/j.width;return isNaN(e)&&(e=1),e};function tt(e){if(w)return;if(2===e.button)return;if(b&&!e.isPrimary)return;if(v.dragStart&&(W=c(f,t)),i(x)&&i(S)&&x===S)throw new Error(\"`handle` selector can't be same as `cancel` selector\");if(O.add(A),z=function(t,e){if(!t)return[e];if(u(t))return[t];if(Array.isArray(t))return t;const n=e.querySelectorAll(t);if(null===n)throw new Error(\"Selector passed for `handle` option should be child of the element on which the action is applied\");return Array.from(n.values())}(x,t),F=function(t,e){if(!t)return[];if(u(t))return[t];if(Array.isArray(t))return t;const n=e.querySelectorAll(t);if(null===n)throw new Error(\"Selector passed for `cancel` option should be child of the element on which the action is applied\");return Array.from(n.values())}(S,t),n=/(both|x)/.test(g),o=/(both|y)/.test(g),d(F,z))throw new Error(\"Element being dragged can't be a child of the element on which `cancel` is applied\");const r=e.composedPath()[0];if(!z.some((t=>t.contains(r)||t.shadowRoot?.contains(r)))||d(F,[r]))return;G=1===z.length?t:z.find((t=>t.contains(r))),L=!0,j=t.getBoundingClientRect(),y&&(I=K.userSelect,K.userSelect=\"none\"),V(\"neodrag:start\",B);const{clientX:a,clientY:s}=e,l=_();n&&(P=a-k/l),o&&(X=s-U/l),W&&(Y=a-j.left,q=s-j.top)}function et(){L&&(v.dragEnd&&(W=c(f,t)),O.remove(C),O.add(M),y&&(K.userSelect=I),V(\"neodrag:end\",H),n&&(P=R),o&&(X=T),L=!1)}function nt(e){if(!L)return;v.drag&&(W=c(f,t)),O.add(C),e.preventDefault(),j=t.getBoundingClientRect();let r=e.clientX,i=e.clientY;const d=_();if(W){const t={left:W.left+Y,top:W.top+q,right:W.right+Y-j.width,bottom:W.bottom+q-j.height};r=a(r,t.left,t.right),i=a(i,t.top,t.bottom)}if(Array.isArray(D)){let[t,e]=D;if(isNaN(+t)||t<0)throw new Error(\"1st argument of `grid` must be a valid positive number\");if(isNaN(+e)||e<0)throw new Error(\"2nd argument of `grid` must be a valid positive number\");let n=r-P,o=i-X;[n,o]=s([t/d,e/d],n,o),r=P+n,i=X+o}n&&(R=Math.round((r-P)*d)),o&&(T=Math.round((i-X)*d)),k=R,U=T,V(\"neodrag\",$),Q()}return{destroy:()=>{const t=removeEventListener;t(\"pointerdown\",tt,!1),t(\"pointerup\",et,!1),t(\"pointermove\",nt,!1)},update:t=>{g=t.axis||\"both\",w=t.disabled??!1,b=t.ignoreMultitouch??!1,x=t.handle,f=t.bounds,v=t.recomputeBounds??r,S=t.cancel,y=t.applyUserSelectHack??!0,D=t.grid,h=t.gpuAcceleration??!0,p=t.legacyTranslate??!0,m=t.transform;const e=O.contains(M);O.remove(A,M),A=t.defaultClass??\"neodrag\",C=t.defaultClassDragging??\"neodrag-dragging\",M=t.defaultClassDragged??\"neodrag-dragged\",O.add(A),e&&O.add(M),J&&(k=R=t.position?.x??R,U=T=t.position?.y??T,Q())}}},a=(t,e,n)=>Math.min(Math.max(t,e),n),i=t=>\"string\"==typeof t,s=([t,e],n,r)=>{const o=(t,e)=>0===e?0:Math.ceil(t/e)*e;return[o(n,t),o(r,e)]};var d=(t,e)=>t.some((t=>e.some((e=>t.contains(e)))));function c(t,e){if(void 0===t)return;if(u(t))return t.getBoundingClientRect();if(\"object\"==typeof t){const{top:e=0,left:n=0,right:r=0,bottom:o=0}=t;return{top:e,right:window.innerWidth-r,bottom:window.innerHeight-o,left:n}}if(\"parent\"===t)return e.parentNode.getBoundingClientRect();const n=document.querySelector(t);if(null===n)throw new Error(\"The selector provided for bound doesn't exists in the document.\");return n.getBoundingClientRect()}var l=(t,e,n)=>t.style.setProperty(e,n),u=t=>t instanceof HTMLElement;function f(t){return null==t||\"string\"==typeof t||t instanceof HTMLElement?t:\"current\"in t?t.current:Array.isArray(t)?t.map((t=>t instanceof HTMLElement?t:t.current)):void 0}function g(r,a={}){const i=t(),[s,d]=e(!1),[c,l]=e();let{onDragStart:u,onDrag:g,onDragEnd:h,handle:p,cancel:m}=a,y=f(p),w=f(m);function b(t,e){l(t),e?.(t)}function v(t){d(!0),b(t,u)}function D(t){b(t,g)}function E(t){d(!1),b(t,h)}return n((()=>{if(\"undefined\"==typeof window)return;const t=r.current;if(!t)return;({onDragStart:u,onDrag:g,onDragEnd:h}=a);const{update:e,destroy:n}=o(t,{...a,handle:y,cancel:w,onDragStart:v,onDrag:D,onDragEnd:E});return i.current=e,n}),[]),n((()=>{i.current?.({...a,handle:f(p),cancel:f(m),onDragStart:v,onDrag:D,onDragEnd:E})}),[a]),{isDragging:s,dragState:c}}export{g as useDraggable};"],"names":["r","o","t","e","n","f","g","h","p","m","y","w","b","v","D","E","S","x","A","C","M","N","B","$","H","L","R","T","P","X","Y","q","k","U","Q","W","j","z","G","I","J","K","O","l","i","V","Z","tt","et","nt","_","c","u","d","_a","a","s","_b"],"mappings":";AAA4D,IAAIA,IAAE,EAAC,WAAU,GAAE,GAAEC,KAAE,CAACC,GAAEC,IAAE,CAAE,MAAG;AAAC,MAAIC,GAAEH,GAAE,EAAC,QAAOI,GAAE,MAAKC,IAAE,QAAO,iBAAgBC,IAAE,IAAG,iBAAgBC,IAAE,IAAG,WAAUC,GAAE,qBAAoBC,IAAE,IAAG,UAASC,IAAE,IAAG,kBAAiBC,IAAE,IAAG,iBAAgBC,IAAEb,GAAE,MAAKc,GAAE,UAASC,GAAE,QAAOC,GAAE,QAAOC,GAAE,cAAaC,IAAE,WAAU,sBAAqBC,IAAE,oBAAmB,qBAAoBC,IAAE,mBAAkB,iBAAgBC,IAAE,EAAC,GAAE,GAAE,GAAE,EAAC,GAAE,aAAYC,IAAE,QAAOC,IAAE,WAAUC,GAAC,IAAErB,GAAEsB,IAAE,IAAGC,IAAE,GAAEC,IAAE,GAAEC,IAAE,GAAEC,IAAE,GAAEC,IAAE,GAAEC,IAAE,GAAE,EAAC,GAAEC,GAAE,GAAEC,EAAC,IAAElB,IAAE,EAAC,IAAEA,KAAA,gBAAAA,EAAG,MAA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AAU,EAAEV,GAAEI,CAAC;AAAA,EAAC;AAAC,WAASS,EAAEb,GAAE;AAAC,IAAAmD,EAAE,EAAE,GAAEzC,EAAEV,GAAEK,CAAC;AAAA,EAAC;AAAC,SAAOH,GAAG,MAAI;AAAC,QAAgB,OAAO,SAApB;AAA2B;AAAO,UAAMF,IAAEF,EAAE;AAAQ,QAAG,CAACE;AAAE;AAAO,KAAC,EAAC,aAAYkD,GAAE,QAAO9C,GAAE,WAAUC,EAAC,IAAEgD;AAAG,UAAK,EAAC,QAAOpD,GAAE,SAAQC,EAAC,IAAEH,GAAEC,GAAE,EAAC,GAAGqD,GAAE,QAAO7C,GAAE,QAAOC,GAAE,aAAYE,GAAE,QAAOC,GAAE,WAAUC,EAAC,CAAC;AAAE,WAAO6B,EAAE,UAAQzC,GAAEC;AAAA,EAAC,GAAG,CAAA,CAAE,GAAEA,GAAG,MAAI;;AAAC,KAAAkD,IAAAV,EAAE,YAAF,QAAAU,EAAA,KAAAV,GAAY,EAAC,GAAGW,GAAE,QAAOlD,EAAEG,CAAC,GAAE,QAAOH,EAAEI,CAAC,GAAE,aAAYI,GAAE,QAAOC,GAAE,WAAUC,EAAC;AAAA,EAAE,GAAG,CAACwC,CAAC,CAAC,GAAE,EAAC,YAAWC,GAAE,WAAUL,EAAC;AAAC;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"annotorious-react.es19.js","sources":["../../../node_modules/react/cjs/react-jsx-runtime.production.min.js"],"sourcesContent":["/**\n * @license React\n * react-jsx-runtime.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';var f=require(\"react\"),k=Symbol.for(\"react.element\"),l=Symbol.for(\"react.fragment\"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};\nfunction q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=\"\"+g);void 0!==a.key&&(e=\"\"+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}exports.Fragment=l;exports.jsx=q;exports.jsxs=q;\n"],"names":["f","require$$0","k","m","n","p","q","c","a","g","b","d","e","h","reactJsxRuntime_production_min"],"mappings":";;;;;;;;;;;;;;;;AASa,MAAIA,IAAEC,GAAiBC,IAAE,OAAO,IAAI,eAAe,GAAE,IAAE,OAAO,IAAI,gBAAgB,GAAEC,IAAE,OAAO,UAAU,gBAAeC,IAAEJ,EAAE,mDAAmD,mBAAkBK,IAAE,EAAC,KAAI,IAAG,KAAI,IAAG,QAAO,IAAG,UAAS,GAAE;AAClP,WAASC,EAAEC,GAAEC,GAAEC,GAAE;AAAC,QAAIC,GAAEC,IAAE,IAAGC,IAAE,MAAKC,IAAE;AAAK,IAASJ,MAAT,WAAaG,IAAE,KAAGH,IAAYD,EAAE,QAAX,WAAiBI,IAAE,KAAGJ,EAAE,MAAcA,EAAE,QAAX,WAAiBK,IAAEL,EAAE;AAAK,SAAIE,KAAKF;AAAE,MAAAL,EAAE,KAAKK,GAAEE,CAAC,KAAG,CAACL,EAAE,eAAeK,CAAC,MAAIC,EAAED,CAAC,IAAEF,EAAEE,CAAC;AAAG,QAAGH,KAAGA,EAAE;AAAa,WAAIG,KAAKF,IAAED,EAAE,cAAaC;AAAE,QAASG,EAAED,CAAC,MAAZ,WAAgBC,EAAED,CAAC,IAAEF,EAAEE,CAAC;AAAG,WAAM,EAAC,UAASR,GAAE,MAAKK,GAAE,KAAIK,GAAE,KAAIC,GAAE,OAAMF,GAAE,QAAOP,EAAE,QAAO;AAAA,EAAC;AAAC,SAAAU,aAAiB,GAAEA,EAAW,MAACR,GAAEQ,EAAA,OAAaR;;","x_google_ignoreList":[0]}
@@ -1,42 +1,42 @@
1
- import { jsx as U } from "./annotorious-react.es17.js";
2
- import { createContext as j, forwardRef as E, useState as f, useImperativeHandle as H, useEffect as h, useContext as c } from "react";
3
- import { useDebounce as C } from "./annotorious-react.es18.js";
4
- const o = j({
1
+ import { j as I } from "./annotorious-react.es13.js";
2
+ import { createContext as O, forwardRef as R, useState as f, useImperativeHandle as U, useEffect as h, useContext as c } from "react";
3
+ import { useDebounce as C } from "./annotorious-react.es14.js";
4
+ const o = O({
5
5
  anno: void 0,
6
6
  setAnno: void 0,
7
7
  annotations: [],
8
8
  selection: { selected: [] }
9
- }), B = E((t, s) => {
10
- const [n, u] = f(null), [p, r] = f([]), [A, l] = f({ selected: [] });
11
- return H(s, () => n), h(() => {
9
+ }), B = R((t, s) => {
10
+ const [n, a] = f(null), [p, r] = f([]), [m, u] = f({ selected: [] });
11
+ return U(s, () => n), h(() => {
12
12
  if (n) {
13
- const { selection: m, store: e } = n.state;
13
+ const { selection: A, store: e } = n.state;
14
14
  e.all().length > 0 && r(e.all());
15
- const v = (a) => r(() => e.all());
15
+ const v = () => r(() => e.all());
16
16
  e.observe(v);
17
17
  let i;
18
- const b = m.subscribe(({ selected: a, pointerEvent: w }) => {
18
+ const b = A.subscribe(({ selected: l, pointerEvent: w }) => {
19
19
  i && e.unobserve(i);
20
- const D = (a || []).map(({ id: d, editable: S }) => ({ annotation: e.getAnnotation(d), editable: S }));
21
- l({ selected: D, pointerEvent: w }), i = (d) => {
20
+ const j = (l || []).map(({ id: d, editable: S }) => ({ annotation: e.getAnnotation(d), editable: S }));
21
+ u({ selected: j, pointerEvent: w }), i = (d) => {
22
22
  const { updated: S } = d.changes;
23
- l(({ selected: I }) => ({
24
- selected: I.map(({ annotation: V, editable: g }) => {
25
- const x = S.find((O) => O.oldValue.id === V.id);
26
- return x ? { annotation: x.newValue, editable: g } : { annotation: V, editable: g };
23
+ u(({ selected: D }) => ({
24
+ selected: D.map(({ annotation: V, editable: x }) => {
25
+ const g = S.find((E) => E.oldValue.id === V.id);
26
+ return g ? { annotation: g.newValue, editable: x } : { annotation: V, editable: x };
27
27
  })
28
28
  }));
29
- }, e.observe(i, { annotations: a.map(({ id: d }) => d) });
29
+ }, e.observe(i, { annotations: l.map(({ id: d }) => d) });
30
30
  });
31
31
  return () => {
32
32
  e.unobserve(v), b();
33
33
  };
34
34
  }
35
- }, [n]), /* @__PURE__ */ U(o.Provider, { value: {
35
+ }, [n]), /* @__PURE__ */ I.jsx(o.Provider, { value: {
36
36
  anno: n,
37
- setAnno: u,
37
+ setAnno: a,
38
38
  annotations: p,
39
- selection: A
39
+ selection: m
40
40
  }, children: t.children });
41
41
  }), F = () => {
42
42
  const { anno: t } = c(o);
@@ -44,13 +44,13 @@ const o = j({
44
44
  }, G = () => {
45
45
  const { anno: t } = c(o);
46
46
  return t == null ? void 0 : t.state.store;
47
- }, P = () => {
47
+ }, H = () => {
48
48
  const { annotations: t } = c(o);
49
49
  return t;
50
- }, R = (t) => {
50
+ }, P = (t) => {
51
51
  const { annotations: s } = c(o);
52
52
  return C(s, t);
53
- }, J = (t) => t ? R(t) : P(), K = () => {
53
+ }, J = (t) => t ? P(t) : H(), K = () => {
54
54
  const { selection: t } = c(o);
55
55
  return t;
56
56
  }, L = () => {
@@ -60,23 +60,23 @@ const o = j({
60
60
  const { anno: t } = c(o), [s, n] = f([]);
61
61
  return h(() => {
62
62
  if (t) {
63
- const { store: u, viewport: p } = t.state;
63
+ const { store: a, viewport: p } = t.state;
64
64
  if (!p)
65
65
  return;
66
66
  let r;
67
- const A = p.subscribe((l) => {
68
- r && u.unobserve(r);
69
- const m = l.map((e) => u.getAnnotation(e));
70
- n(m), r = (e) => {
67
+ const m = p.subscribe((u) => {
68
+ r && a.unobserve(r);
69
+ const A = u.map((e) => a.getAnnotation(e));
70
+ n(A), r = (e) => {
71
71
  const { updated: v } = e.changes;
72
72
  n((i) => i.map((b) => {
73
- const a = v.find((w) => w.oldValue.id === b.id);
74
- return a ? a.newValue : b;
73
+ const l = v.find((w) => w.oldValue.id === b.id);
74
+ return l ? l.newValue : b;
75
75
  }));
76
- }, u.observe(r, { annotations: l });
76
+ }, a.observe(r, { annotations: u });
77
77
  });
78
78
  return () => {
79
- A();
79
+ m();
80
80
  };
81
81
  }
82
82
  }, [t]), s;
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es2.js","sources":["../src/Annotorious.tsx"],"sourcesContent":["import { createContext, forwardRef, ReactNode} from 'react';\nimport { useContext, useEffect, useImperativeHandle, useState } from 'react';\nimport { Annotation, Annotator, Store, StoreChangeEvent } from '@annotorious/core';\nimport { useDebounce } from './useDebounce';\n\ninterface Selection<T extends Annotation = Annotation> {\n\n selected: { annotation: T, editable?: boolean }[];\n\n pointerEvent?: PointerEvent;\n\n}\n\nexport interface AnnotoriousContextState {\n\n anno: Annotator;\n\n setAnno(anno: Annotator<Annotation, unknown>): void;\n\n annotations: Annotation[];\n\n selection: Selection;\n\n}\n\nexport const AnnotoriousContext = createContext({ \n\n anno: undefined, \n\n setAnno: undefined, \n\n annotations: [], \n\n selection: { selected: [] }\n\n});\n\nexport const Annotorious = forwardRef<Annotator, { children: ReactNode }>((props: { children: ReactNode }, ref) => {\n\n const [anno, setAnno] = useState<Annotator>(null);\n\n const [annotations, setAnnotations] = useState<Annotation[]>([]);\n\n const [selection, setSelection] = useState<Selection>({ selected: [] });\n\n useImperativeHandle(ref, () => anno);\n\n useEffect(() => {\n if (anno) {\n const { selection, store } = anno.state;\n\n // Components below <Annotorious /> may have\n // loaded annotations into the store already! \n if (store.all().length > 0)\n setAnnotations(store.all());\n\n // Keeps annotations in sync with a React state,\n // so clients can render components the usual React way.\n const onStoreChange = (event: StoreChangeEvent<Annotation>) =>\n setAnnotations(() => store.all());\n\n store.observe(onStoreChange);\n\n // Keep selection in sync with a react state, and resolve them\n // from IDs to annotations automatically, for convenience\n let selectionStoreObserver: (event: StoreChangeEvent<Annotation>) => void;\n\n const unsubscribeSelection = selection.subscribe(({ selected, pointerEvent }) => {\n if (selectionStoreObserver) \n store.unobserve(selectionStoreObserver);\n\n const resolved = (selected || [])\n .map(({ id, editable }) => ({ annotation: store.getAnnotation(id), editable }));\n\n setSelection({ selected: resolved, pointerEvent });\n\n selectionStoreObserver = event => {\n const { updated } = event.changes;\n\n setSelection(({ selected }) => ({\n selected: selected.map(({ annotation, editable }) => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? { annotation: next.newValue, editable } : { annotation, editable };\n })\n }));\n }\n\n store.observe(selectionStoreObserver, { annotations: selected.map(({ id }) => id) });\n });\n\n return () => {\n store.unobserve(onStoreChange);\n unsubscribeSelection();\n }\n }\n }, [anno]);\n\n return (\n <AnnotoriousContext.Provider value={{ \n anno, \n setAnno,\n annotations, \n selection \n }}>\n {props.children}\n </AnnotoriousContext.Provider>\n )\n\n});\n\nexport const useAnnotator = <T extends Annotator<any, unknown>>() => {\n const { anno } = useContext(AnnotoriousContext);\n return anno as T;\n}\n\nexport const useAnnotationStore = <T extends Store<Annotation>>() => {\n const { anno } = useContext(AnnotoriousContext);\n return anno?.state.store as T | undefined;\n}\n\nconst _useAnnotations = <T extends Annotation>() => {\n const { annotations } = useContext(AnnotoriousContext);\n return annotations as T[];\n}\n\nconst _useAnnotationsDebouced = <T extends Annotation>(debounce: number) => {\n const { annotations } = useContext(AnnotoriousContext);\n return useDebounce(annotations, debounce) as T[];\n}\n\nexport const useAnnotations = <T extends Annotation>(debounce?: number) =>\n debounce ? _useAnnotationsDebouced<T>(debounce) : _useAnnotations<T>();\n\nexport const useSelection = <T extends Annotation>() => {\n const { selection } = useContext(AnnotoriousContext);\n return selection as Selection<T>;\n}\n\nexport const useAnnotatorUser = () => {\n const { anno } = useContext(AnnotoriousContext);\n return anno?.getUser();\n}\n\nconst _useViewportState = <T extends Annotation>() => {\n const { anno } = useContext(AnnotoriousContext);\n\n const [inViewport, setInViewport] = useState<T[]>([]);\n\n useEffect(() => {\n if (anno) {\n const { store, viewport} = anno.state;\n\n if (!viewport)\n return;\n\n // Keep viewport annotations in sync with a react state, and resolve them\n // from IDs to annotations automatically, for convenience\n let viewportStoreObserver: (event: StoreChangeEvent<T>) => void;\n\n const unsubscribeViewport = viewport.subscribe(ids => {\n if (viewportStoreObserver) \n store.unobserve(viewportStoreObserver);\n\n const resolved = ids.map(id => store.getAnnotation(id)) as T[];\n setInViewport(resolved);\n\n viewportStoreObserver = event => {\n const { updated } = event.changes;\n\n setInViewport(annotations => annotations.map(annotation => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? next.newValue : annotation;\n }));\n }\n\n store.observe(viewportStoreObserver, { annotations: ids });\n });\n\n return () => {\n unsubscribeViewport();\n }\n }\n }, [anno]);\n\n return inViewport;\n}\n\nconst _useViewportStateDebounced = <T extends Annotation>(debounce: number) => {\n const inViewport = _useViewportState();\n return useDebounce(inViewport, debounce) as T[];\n}\n\nexport const useViewportState = <T extends Annotation>(debounce?: number) =>\n debounce ? _useViewportStateDebounced<T>(debounce) : _useViewportState<T>();\n"],"names":["AnnotoriousContext","createContext","Annotorious","forwardRef","props","ref","anno","setAnno","useState","annotations","setAnnotations","selection","setSelection","useImperativeHandle","useEffect","store","onStoreChange","event","selectionStoreObserver","unsubscribeSelection","selected","pointerEvent","resolved","id","editable","updated","annotation","next","u","jsx","useAnnotator","useContext","useAnnotationStore","_useAnnotations","_useAnnotationsDebouced","debounce","useDebounce","useAnnotations","useSelection","useAnnotatorUser","_useViewportState","inViewport","setInViewport","viewport","viewportStoreObserver","unsubscribeViewport","ids","_useViewportStateDebounced","useViewportState"],"mappings":";;;AAyBO,MAAMA,IAAqBC,EAAc;AAAA,EAE9C,MAAM;AAAA,EAEN,SAAS;AAAA,EAET,aAAa,CAAC;AAAA,EAEd,WAAW,EAAE,UAAU,GAAG;AAE5B,CAAC,GAEYC,IAAcC,EAA+C,CAACC,GAAgCC,MAAQ;AAEjH,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAA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d,QAAIR,GAAM;AACR,YAAM,EAAE,OAAAS,GAAO,UAAA4B,MAAYrC,EAAK;AAEhC,UAAI,CAACqC;AACH;AAIE,UAAAC;AAEE,YAAAC,IAAsBF,EAAS,UAAU,CAAOG,MAAA;AAChD,QAAAF,KACF7B,EAAM,UAAU6B,CAAqB;AAEvC,cAAMtB,IAAWwB,EAAI,IAAI,OAAM/B,EAAM,cAAcQ,CAAE,CAAC;AACtD,QAAAmB,EAAcpB,CAAQ,GAEtBsB,IAAwB,CAAS3B,MAAA;AACzB,gBAAA,EAAE,SAAAQ,EAAQ,IAAIR,EAAM;AAEZ,UAAAyB,EAAA,CAAAjC,MAAeA,EAAY,IAAI,CAAciB,MAAA;AACnD,kBAAAC,IAAOF,EAAQ,KAAK,CAAAG,MAAKA,EAAE,SAAS,OAAOF,EAAW,EAAE;AACvD,mBAAAC,IAAOA,EAAK,WAAWD;AAAA,UAC/B,CAAA,CAAC;AAAA,QAAA,GAGJX,EAAM,QAAQ6B,GAAuB,EAAE,aAAaE,EAAK,CAAA;AAAA,MAAA,CAC1D;AAED,aAAO,MAAM;AACS,QAAAD;MAAA;AAAA,IAExB;AAAA,EAAA,GACC,CAACvC,CAAI,CAAC,GAEFmC;AACT,GAEMM,IAA8B,CAAuBZ,MAAqB;AAC9E,QAAMM,IAAaD;AACZ,SAAAJ,EAAYK,GAAYN,CAAQ;AACzC,GAEaa,IAAoB,CAAuBb,MACtDA,IAAWY,EAA8BZ,CAAQ,IAAIK,EAAqB;"}
1
+ {"version":3,"file":"annotorious-react.es2.js","sources":["../src/Annotorious.tsx"],"sourcesContent":["import { createContext, forwardRef, ReactNode} from 'react';\nimport { useContext, useEffect, useImperativeHandle, useState } from 'react';\nimport { Annotation, Annotator, Store, StoreChangeEvent } from '@annotorious/annotorious';\nimport { useDebounce } from './useDebounce';\n\ninterface Selection<T extends Annotation = Annotation> {\n\n selected: { annotation: T, editable?: boolean }[];\n\n pointerEvent?: PointerEvent;\n\n}\n\nexport interface AnnotoriousContextState {\n\n anno: Annotator;\n\n setAnno(anno: Annotator<Annotation, unknown>): void;\n\n annotations: Annotation[];\n\n selection: Selection;\n\n}\n\nexport const AnnotoriousContext = createContext({ \n\n anno: undefined, \n\n setAnno: undefined, \n\n annotations: [], \n\n selection: { selected: [] }\n\n});\n\nexport const Annotorious = forwardRef<Annotator, { children: ReactNode }>((props: { children: ReactNode }, ref) => {\n\n const [anno, setAnno] = useState<Annotator>(null);\n\n const [annotations, setAnnotations] = useState<Annotation[]>([]);\n\n const [selection, setSelection] = useState<Selection>({ selected: [] });\n\n useImperativeHandle(ref, () => anno);\n\n useEffect(() => {\n if (anno) {\n const { selection, store } = anno.state;\n\n // Components below <Annotorious /> may have\n // loaded annotations into the store already! \n if (store.all().length > 0)\n setAnnotations(store.all());\n\n // Keeps annotations in sync with a React state,\n // so clients can render components the usual React way.\n const onStoreChange = () => setAnnotations(() => store.all());\n\n store.observe(onStoreChange);\n\n // Keep selection in sync with a react state, and resolve them\n // from IDs to annotations automatically, for convenience\n let selectionStoreObserver: (event: StoreChangeEvent<Annotation>) => void;\n\n const unsubscribeSelection = selection.subscribe(({ selected, pointerEvent }) => {\n if (selectionStoreObserver) \n store.unobserve(selectionStoreObserver);\n\n const resolved = (selected || [])\n .map(({ id, editable }) => ({ annotation: store.getAnnotation(id), editable }));\n\n setSelection({ selected: resolved, pointerEvent });\n\n selectionStoreObserver = event => {\n const { updated } = event.changes;\n\n setSelection(({ selected }) => ({\n selected: selected.map(({ annotation, editable }) => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? { annotation: next.newValue, editable } : { annotation, editable };\n })\n }));\n }\n\n store.observe(selectionStoreObserver, { annotations: selected.map(({ id }) => id) });\n });\n\n return () => {\n store.unobserve(onStoreChange);\n unsubscribeSelection();\n }\n }\n }, [anno]);\n\n return (\n <AnnotoriousContext.Provider value={{ \n anno, \n setAnno,\n annotations, \n selection \n }}>\n {props.children}\n </AnnotoriousContext.Provider>\n )\n\n});\n\nexport const useAnnotator = <T extends unknown = Annotator<any, unknown>>() => {\n const { anno } = useContext(AnnotoriousContext);\n return anno as T;\n}\n\nexport const useAnnotationStore = <T extends unknown = Store<Annotation>>() => {\n const { anno } = useContext(AnnotoriousContext);\n return anno?.state.store as T | undefined;\n}\n\nconst _useAnnotations = <T extends Annotation>() => {\n const { annotations } = useContext(AnnotoriousContext);\n return annotations as T[];\n}\n\nconst _useAnnotationsDebounced = <T extends Annotation>(debounce: number) => {\n const { annotations } = useContext(AnnotoriousContext);\n return useDebounce(annotations, debounce) as T[];\n}\n\nexport const useAnnotations = <T extends Annotation>(debounce?: number) =>\n debounce ? _useAnnotationsDebounced<T>(debounce) : _useAnnotations<T>();\n\nexport const useSelection = <T extends Annotation>() => {\n const { selection } = useContext(AnnotoriousContext);\n return selection as Selection<T>;\n}\n\nexport const useAnnotatorUser = () => {\n const { anno } = useContext(AnnotoriousContext);\n return anno?.getUser();\n}\n\nconst _useViewportState = <T extends Annotation>() => {\n const { anno } = useContext(AnnotoriousContext);\n\n const [inViewport, setInViewport] = useState<T[]>([]);\n\n useEffect(() => {\n if (anno) {\n const { store, viewport } = anno.state;\n\n if (!viewport)\n return;\n\n // Keep viewport annotations in sync with a react state, and resolve them\n // from IDs to annotations automatically, for convenience\n let viewportStoreObserver: (event: StoreChangeEvent<T>) => void;\n\n const unsubscribeViewport = viewport.subscribe(ids => {\n if (viewportStoreObserver) \n store.unobserve(viewportStoreObserver);\n\n const resolved = ids.map(id => store.getAnnotation(id)) as T[];\n setInViewport(resolved);\n\n viewportStoreObserver = event => {\n const { updated } = event.changes;\n\n setInViewport(annotations => annotations.map(annotation => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? next.newValue : annotation;\n }));\n }\n\n store.observe(viewportStoreObserver, { annotations: ids });\n });\n\n return () => {\n unsubscribeViewport();\n }\n }\n }, [anno]);\n\n return inViewport;\n}\n\nconst _useViewportStateDebounced = <T extends Annotation>(debounce: number) => {\n const inViewport = _useViewportState();\n return useDebounce(inViewport, debounce) as T[];\n}\n\nexport const useViewportState = <T extends Annotation>(debounce?: number) =>\n debounce ? _useViewportStateDebounced<T>(debounce) : _useViewportState<T>();\n"],"names":["AnnotoriousContext","createContext","Annotorious","forwardRef","props","ref","anno","setAnno","useState","annotations","setAnnotations","selection","setSelection","useImperativeHandle","useEffect","store","onStoreChange","selectionStoreObserver","unsubscribeSelection","selected","pointerEvent","resolved","id","editable","event","updated","annotation","next","u","jsx","useAnnotator","useContext","useAnnotationStore","_useAnnotations","_useAnnotationsDebounced","debounce","useDebounce","useAnnotations","useSelection","useAnnotatorUser","_useViewportState","inViewport","setInViewport","viewport","viewportStoreObserver","unsubscribeViewport","ids","_useViewportStateDebounced","useViewportState"],"mappings":";;;AAyBO,MAAMA,IAAqBC,EAAc;AAAA,EAE9C,MAAM;AAAA,EAEN,SAAS;AAAA,EAET,aAAa,CAAC;AAAA,EAEd,WAAW,EAAE,UAAU,GAAG;AAE5B,CAAC,GAEYC,IAAcC,EAA+C,CAACC,GAAgCC,MAAQ;AAEjH,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAoB,IAAI,GAE1C,CAACC,GAAaC,CAAc,IAAIF,EAAuB,CAAE,CAAA,GAEzD,CAACG,GAAWC,CAAY,IAAIJ,EAAoB,EAAE,UAAU,CAAC,EAAA,CAAG;AAElD,SAAAK,EAAAR,GAAK,MAAMC,CAAI,GAEnCQ,EAAU,MAAM;AACd,QAAIR,GAAM;AACR,YAAM,EAAE,WAAAK,GAAW,OAAAI,EAAA,IAAUT,EAAK;AAI9B,MAAAS,EAAM,MAAM,SAAS,KACRL,EAAAK,EAAM,KAAK;AAI5B,YAAMC,IAAgB,MAAMN,EAAe,MAAMK,EAAM,IAAK,CAAA;AAE5D,MAAAA,EAAM,QAAQC,CAAa;AAIvB,UAAAC;AAEJ,YAAMC,IAAuBP,EAAU,UAAU,CAAC,EAAE,UAAAQ,GAAU,cAAAC,QAAmB;AAC3E,QAAAH,KACFF,EAAM,UAAU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