@annotorious/react 3.0.0-rc.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/Annotorious.d.ts +11 -40
  2. package/dist/Annotorious.d.ts.map +1 -1
  3. package/dist/AnnotoriousPlugin.d.ts +9 -6
  4. package/dist/AnnotoriousPlugin.d.ts.map +1 -1
  5. package/dist/AnnotoriousPopup.d.ts +2 -2
  6. package/dist/AnnotoriousPopup.d.ts.map +1 -1
  7. package/dist/ImageAnnotator.d.ts +1 -2
  8. package/dist/ImageAnnotator.d.ts.map +1 -1
  9. package/dist/annotorious-react.css +1 -1
  10. package/dist/annotorious-react.es.js +35 -32
  11. package/dist/annotorious-react.es.js.map +1 -1
  12. package/dist/annotorious-react.es10.js +14 -27
  13. package/dist/annotorious-react.es10.js.map +1 -1
  14. package/dist/annotorious-react.es11.js +6 -36
  15. package/dist/annotorious-react.es11.js.map +1 -1
  16. package/dist/annotorious-react.es12.js +8 -16
  17. package/dist/annotorious-react.es12.js.map +1 -1
  18. package/dist/annotorious-react.es13.js +134 -4
  19. package/dist/annotorious-react.es13.js.map +1 -1
  20. package/dist/annotorious-react.es14.js +31 -7
  21. package/dist/annotorious-react.es14.js.map +1 -1
  22. package/dist/annotorious-react.es15.js +2 -153
  23. package/dist/annotorious-react.es15.js.map +1 -1
  24. package/dist/annotorious-react.es16.js +26 -6
  25. package/dist/annotorious-react.es16.js.map +1 -1
  26. package/dist/annotorious-react.es17.js +550 -20652
  27. package/dist/annotorious-react.es17.js.map +1 -1
  28. package/dist/annotorious-react.es18.js +2 -32
  29. package/dist/annotorious-react.es18.js.map +1 -1
  30. package/dist/annotorious-react.es19.js +2 -2
  31. package/dist/annotorious-react.es2.js +87 -68
  32. package/dist/annotorious-react.es2.js.map +1 -1
  33. package/dist/annotorious-react.es3.js +12 -13
  34. package/dist/annotorious-react.es3.js.map +1 -1
  35. package/dist/annotorious-react.es4.js +8 -8
  36. package/dist/annotorious-react.es4.js.map +1 -1
  37. package/dist/annotorious-react.es5.js +19 -20
  38. package/dist/annotorious-react.es5.js.map +1 -1
  39. package/dist/annotorious-react.es8.js +27 -80
  40. package/dist/annotorious-react.es8.js.map +1 -1
  41. package/dist/annotorious-react.es9.js +32 -3921
  42. package/dist/annotorious-react.es9.js.map +1 -1
  43. package/dist/index.d.ts +8 -9
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/openseadragon/OpenSeadragonAnnotator.d.ts +3 -3
  46. package/dist/openseadragon/OpenSeadragonAnnotator.d.ts.map +1 -1
  47. package/dist/openseadragon/OpenSeadragonPopup.d.ts +1 -1
  48. package/dist/openseadragon/OpenSeadragonViewer.d.ts +2 -3
  49. package/dist/openseadragon/OpenSeadragonViewer.d.ts.map +1 -1
  50. package/dist/openseadragon/setPosition.d.ts +1 -1
  51. package/dist/openseadragon/setPosition.d.ts.map +1 -1
  52. package/package.json +14 -11
  53. package/dist/annotorious-react.es20.js +0 -33
  54. package/dist/annotorious-react.es20.js.map +0 -1
  55. package/dist/annotorious-react.es21.js +0 -602
  56. package/dist/annotorious-react.es21.js.map +0 -1
  57. package/dist/annotorious-react.es22.js +0 -5
  58. package/dist/annotorious-react.es22.js.map +0 -1
  59. package/dist/annotorious-react.es23.js +0 -5
  60. package/dist/annotorious-react.es23.js.map +0 -1
  61. package/dist/annotorious-react.es6.js +0 -5
  62. package/dist/annotorious-react.es6.js.map +0 -1
  63. package/dist/annotorious-react.es7.js +0 -5
  64. package/dist/annotorious-react.es7.js.map +0 -1
@@ -1,35 +1,5 @@
1
- import w from "openseadragon";
2
- const L = (i, h) => {
3
- const e = i.element.getBoundingClientRect(), { minX: n, minY: l, maxX: t, maxY: c } = h.target.selector.geometry.bounds, s = i.viewport.imageToViewerElementCoordinates(new w.Point(n, l)), x = i.viewport.imageToViewerElementCoordinates(new w.Point(t, c));
4
- return {
5
- x: s.x + e.x,
6
- right: x.x + e.x,
7
- y: s.y + e.y,
8
- bottom: x.y + e.y,
9
- width: x.x - s.x,
10
- height: x.y - s.y
11
- };
12
- }, T = (i, h, e, n = 5) => {
13
- const l = i.element.getBoundingClientRect(), t = L(i, h), c = t.y - l.y, s = l.right - t.x, x = l.bottom - t.bottom, d = t.x - l.left, o = e.firstElementChild.getBoundingClientRect(), g = c / o.height, y = s / o.width, a = x / o.height, r = d / o.width, $ = () => {
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
- }, B = () => {
18
- e.style.left = `${t.x - o.width - n}px`, e.style.top = `${t.y}px`;
19
- }, v = () => {
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
- }, E = () => {
26
- e.style.left = `${t.x}px`, e.style.top = `${t.bottom + n}px`;
27
- }, A = () => {
28
- e.style.left = `${t.right - o.width}px`, e.style.top = `${t.bottom + n}px`;
29
- }, b = [g, y, a, r], m = b.indexOf(Math.max(...b));
30
- m === 0 ? y > r ? $() : f() : m === 1 ? g > a ? C() : v() : m === 2 ? y > r ? E() : A() : g > a ? R() : B();
31
- };
1
+ var r = {};
32
2
  export {
33
- T as setPosition
3
+ r as __exports
34
4
  };
35
5
  //# sourceMappingURL=annotorious-react.es18.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es18.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 const viewerBounds = viewer.element.getBoundingClientRect();\n \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 + viewerBounds.x,\n right: bottomRight.x + viewerBounds.x,\n y: topLeft.y + viewerBounds.y,\n bottom: bottomRight.y + viewerBounds.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","viewerBounds","minX","minY","maxX","maxY","topLeft","OpenSeadragon","bottomRight","setPosition","popup","sideOffset","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;AACpF,QAAAC,IAAeF,EAAO,QAAQ,sBAAsB,GAGpD,EAAE,MAAAG,GAAM,MAAAC,GAAM,MAAAC,GAAM,MAAAC,MAASL,E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};
2
2
  export {
3
- e as __module
3
+ e as __exports
4
4
  };
5
5
  //# sourceMappingURL=annotorious-react.es19.js.map
@@ -1,97 +1,116 @@
1
- import { jsx as U } from "./annotorious-react.es13.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.es14.js";
4
- const o = j({
1
+ import { j as E } from "./annotorious-react.es11.js";
2
+ import { onUserSelect as I } from "@annotorious/core";
3
+ import { useDebounce as _ } from "./annotorious-react.es12.js";
4
+ import { createContext as O, forwardRef as R, useState as b, useImperativeHandle as H, useEffect as V, useContext as a } from "react";
5
+ const c = O({
5
6
  anno: void 0,
6
7
  setAnno: void 0,
7
8
  annotations: [],
8
9
  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(() => {
10
+ }), K = R((t, o) => {
11
+ const [n, i] = b(null), [u, s] = b([]), [d, r] = b({ selected: [] });
12
+ return H(o, () => n), V(() => {
12
13
  if (n) {
13
14
  const { selection: m, store: e } = n.state;
14
- e.all().length > 0 && r(e.all());
15
- const v = (a) => r(() => e.all());
16
- e.observe(v);
17
- let i;
18
- const b = m.subscribe(({ selected: a, pointerEvent: w }) => {
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) => {
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 };
15
+ e.all().length > 0 && s(e.all());
16
+ const f = () => s(() => e.all());
17
+ e.observe(f);
18
+ let l;
19
+ const A = m.subscribe(({ selected: p, ...w }) => {
20
+ l && e.unobserve(l);
21
+ const D = (p || []).map(({ id: v, editable: S }) => ({ annotation: e.getAnnotation(v), editable: S }));
22
+ r({ selected: D, ...w }), l = (v) => {
23
+ const { updated: S } = v.changes;
24
+ r((g) => ({
25
+ ...g,
26
+ selected: g.selected.map(({ annotation: h, editable: x }) => {
27
+ const C = S.find((U) => U.oldValue.id === h.id);
28
+ return C ? { annotation: C.newValue, editable: x } : { annotation: h, editable: x };
27
29
  })
28
30
  }));
29
- }, e.observe(i, { annotations: a.map(({ id: d }) => d) });
31
+ }, e.observe(l, { annotations: p.map(({ id: v }) => v) });
30
32
  });
31
33
  return () => {
32
- e.unobserve(v), b();
34
+ e.unobserve(f), A();
33
35
  };
34
36
  }
35
- }, [n]), /* @__PURE__ */ U(o.Provider, { value: {
37
+ }, [n]), /* @__PURE__ */ E.jsx(c.Provider, { value: {
36
38
  anno: n,
37
- setAnno: u,
38
- annotations: p,
39
- selection: A
39
+ setAnno: i,
40
+ annotations: u,
41
+ selection: d
40
42
  }, children: t.children });
41
- }), F = () => {
42
- const { anno: t } = c(o);
43
+ }), L = () => {
44
+ const { anno: t } = a(c);
43
45
  return t;
44
- }, G = () => {
45
- const { anno: t } = c(o);
46
- return t == null ? void 0 : t.state.store;
47
46
  }, P = () => {
48
- const { annotations: t } = c(o);
47
+ const { anno: t } = a(c);
48
+ return t == null ? void 0 : t.state.store;
49
+ }, k = () => {
50
+ const { annotations: t } = a(c);
49
51
  return t;
50
- }, R = (t) => {
51
- const { annotations: s } = c(o);
52
- return C(s, t);
53
- }, J = (t) => t ? R(t) : P(), K = () => {
54
- const { selection: t } = c(o);
52
+ }, q = (t) => {
53
+ const { annotations: o } = a(c);
54
+ return _(o, t);
55
+ }, M = (t) => t ? q(t) : k(), y = (t, o) => {
56
+ const n = P(), [i, u] = b(
57
+ n == null ? void 0 : n.getAnnotation(t)
58
+ );
59
+ return V(() => {
60
+ if (!n) return;
61
+ const s = (d) => {
62
+ const r = d.changes.updated[0];
63
+ r && u(r.newValue);
64
+ };
65
+ return n.observe(s, { ...o, annotations: t }), () => n.unobserve(s);
66
+ }, []), i;
67
+ }, N = (t, o) => {
68
+ const n = y(t);
69
+ return n ? I(n, o) : void 0;
70
+ }, Q = () => {
71
+ const { selection: t } = a(c);
55
72
  return t;
56
- }, L = () => {
57
- const { anno: t } = c(o);
73
+ }, T = () => {
74
+ const { anno: t } = a(c);
58
75
  return t == null ? void 0 : t.getUser();
59
- }, _ = () => {
60
- const { anno: t } = c(o), [s, n] = f([]);
61
- return h(() => {
76
+ }, j = () => {
77
+ const { anno: t } = a(c), [o, n] = b([]);
78
+ return V(() => {
62
79
  if (t) {
63
- const { store: u, viewport: p } = t.state;
64
- if (!p)
80
+ const { store: i, viewport: u } = t.state;
81
+ if (!u)
65
82
  return;
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) => {
71
- const { updated: v } = e.changes;
72
- n((i) => i.map((b) => {
73
- const a = v.find((w) => w.oldValue.id === b.id);
74
- return a ? a.newValue : b;
83
+ let s;
84
+ const d = u.subscribe((r) => {
85
+ s && i.unobserve(s);
86
+ const m = r.map((e) => i.getAnnotation(e));
87
+ n(m), s = (e) => {
88
+ const { updated: f } = e.changes;
89
+ n((l) => l.map((A) => {
90
+ const p = f.find((w) => w.oldValue.id === A.id);
91
+ return p ? p.newValue : A;
75
92
  }));
76
- }, u.observe(r, { annotations: l });
93
+ }, i.observe(s, { annotations: r });
77
94
  });
78
95
  return () => {
79
- A();
96
+ d();
80
97
  };
81
98
  }
82
- }, [t]), s;
83
- }, k = (t) => {
84
- const s = _();
85
- return C(s, t);
86
- }, M = (t) => t ? k(t) : _();
99
+ }, [t]), o;
100
+ }, z = (t) => {
101
+ const o = j();
102
+ return _(o, t);
103
+ }, W = (t) => t ? z(t) : j();
87
104
  export {
88
- B as Annotorious,
89
- o as AnnotoriousContext,
90
- G as useAnnotationStore,
91
- J as useAnnotations,
92
- F as useAnnotator,
93
- L as useAnnotatorUser,
94
- K as useSelection,
95
- M as useViewportState
105
+ K as Annotorious,
106
+ c as AnnotoriousContext,
107
+ y as useAnnotation,
108
+ N as useAnnotationSelectAction,
109
+ P as useAnnotationStore,
110
+ M as useAnnotations,
111
+ L as useAnnotator,
112
+ T as useAnnotatorUser,
113
+ Q as useSelection,
114
+ W as useViewportState
96
115
  };
97
116
  //# sourceMappingURL=annotorious-react.es2.js.map
@@ -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 '.';\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,C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,EAAU,MAAM;AACd,QAAIR,GAAM;AACR,YAAM,EAAE,OAAAS,GAAO,UAAA4B,MAAarC,EAAK;AAEjC,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 { onUserSelect } from '@annotorious/core';\nimport type { StoreObserveOptions, UserSelectActionExpression} from '@annotorious/core';\nimport { useDebounce } from './useDebounce';\nimport { \n createContext, \n forwardRef, \n type ReactNode, \n useContext, \n useEffect, \n useImperativeHandle, \n useState \n} from 'react';\nimport type {\n Annotation,\n Annotator,\n Selection as CoreSelection,\n Store,\n StoreChangeEvent,\n User\n} from '@annotorious/annotorious';\n\ninterface Selection<T extends Annotation = Annotation> extends Omit<CoreSelection, 'selected'> {\n\n selected: { annotation: T, editable?: boolean }[];\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, ...rest }) => {\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, ...rest });\n\n selectionStoreObserver = event => {\n const { updated } = event.changes;\n\n setSelection((selection) => ({\n ...selection,\n selected: selection.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 useAnnotation = <T extends Annotation>(id: string, options?: Omit<StoreObserveOptions, 'annotations'>) => {\n const store = useAnnotationStore<Store<T>>();\n\n const [annotation, setAnnotation] = useState<T | undefined>(\n store?.getAnnotation(id)\n );\n\n useEffect(() => {\n if (!store) return;\n\n const handleChange = (event: StoreChangeEvent<T>) => {\n const updated = event.changes.updated[0];\n if (updated) {\n setAnnotation(updated.newValue);\n }\n };\n\n store.observe(handleChange, { ...options, annotations: id });\n return () => store.unobserve(handleChange);\n }, []);\n\n return annotation;\n}\n\nexport const useAnnotationSelectAction = <T extends Annotation>(id: string, action: UserSelectActionExpression<T>) => {\n const annotation = useAnnotation(id);\n return annotation ? onUserSelect(annotation, action) : undefined;\n}\n\nexport const useSelection = <T extends Annotation>() => {\n const { selection } = useContext(AnnotoriousContext);\n return selection as Selection<T>;\n}\n\nexport const useAnnotatorUser = (): User => {\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","rest","resolved","id","editable","event","updated","annotation","next","u","jsx","useAnnotator","useContext","useAnnotationStore","_useAnnotations","_useAnnotationsDebounced","debounce","useDebounce","useAnnotations","useAnnotation","options","setAnnotation","handleChange","useAnnotationSelectAction","action","onUserSelect","useSelection","useAnnotatorUser","_useViewportState","inViewport","setInViewport","viewport","viewportStoreObserver","unsubscribeViewport","ids","_useViewportStateDebounced","useViewportState"],"mappings":";;;;AA2BO,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,G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AA;AAAA,MAAA,CAC1D;AAED,aAAO,MAAM;AACS,QAAAD;MAAA;AAAA,IAExB;AAAA,EAAA,GACC,CAAC9C,CAAI,CAAC,GAEF0C;AACT,GAEMM,IAA8B,CAAuBnB,MAAqB;AAC9E,QAAMa,IAAaD;AACZ,SAAAX,EAAYY,GAAYb,CAAQ;AACzC,GAEaoB,IAAoB,CAAuBpB,MACtDA,IAAWmB,EAA8BnB,CAAQ,IAAIY,EAAqB;"}
@@ -1,16 +1,15 @@
1
- import { useEffect as i } from "react";
2
- import { useAnnotator as s } from "./annotorious-react.es2.js";
3
- const m = (t) => {
4
- const { plugin: u, opts: r } = t, n = s();
5
- return i(() => {
6
- if (n) {
7
- const o = u(n, r);
8
- return () => {
9
- o && "unmount" in o && o.unmount();
10
- };
11
- }
12
- }, [n]), null;
13
- };
1
+ import { forwardRef as s, useEffect as c } from "react";
2
+ import { useAnnotator as e } from "./annotorious-react.es2.js";
3
+ const m = s((i, n) => {
4
+ const { plugin: u, opts: r } = i, t = e();
5
+ return c(() => {
6
+ if (!t) return;
7
+ const o = u(t, r);
8
+ return n && (n.current = o), () => {
9
+ o && "unmount" in o && o.unmount(), n && (n.current = null);
10
+ };
11
+ }, [t, u, r, n]), null;
12
+ });
14
13
  export {
15
14
  m as AnnotoriousPlugin
16
15
  };
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es3.js","sources":["../src/AnnotoriousPlugin.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { Annotation, Annotator } from '..';\nimport { useAnnotator } from './Annotorious';\n\nexport interface AnnotoriousPluginProps <I extends Annotation, E extends unknown> {\n\n plugin: (anno: Annotator<I, E>, opts?: Object) => ({ unmount?: () => void }) | void;\n\n opts?: Object;\n\n}\n\nexport const AnnotoriousPlugin = <I extends Annotation = Annotation, E extends unknown = unknown>(props: AnnotoriousPluginProps<I, E>) => {\n const { plugin, opts } = props;\n\n const anno = useAnnotator<Annotator<I, E>>();\n\n useEffect(() => {\n if (anno) {\n const p = plugin(anno, opts);\n\n return () => {\n if (p && 'unmount' in p)\n p.unmount();\n }\n }\n }, [anno]);\n\n return null;\n\n}"],"names":["AnnotoriousPlugin","props","plugin","opts","anno","useAnnotator","useEffect","p"],"mappings":";;AAYa,MAAAA,IAAoB,CAAiEC,MAAwC;AAClI,QAAA,EAAE,QAAAC,GAAQ,MAAAC,EAAS,IAAAF,GAEnBG,IAAOC;AAEb,SAAAC,EAAU,MAAM;AACd,QAAIF,GAAM;AACF,YAAAG,IAAIL,EAAOE,GAAMD,CAAI;AAE3B,aAAO,MAAM;AACX,QAAII,KAAK,aAAaA,KACpBA,EAAE,QAAQ;AAAA,MAAA;AAAA,IAEhB;AAAA,EAAA,GACC,CAACH,CAAI,CAAC,GAEF;AAET;"}
1
+ {"version":3,"file":"annotorious-react.es3.js","sources":["../src/AnnotoriousPlugin.tsx"],"sourcesContent":["import { forwardRef, useEffect } from 'react';\nimport { Annotator } from '@annotorious/annotorious';\nimport { useAnnotator } from './Annotorious';\n\nexport type AnnotatorPlugin<T extends unknown = Annotator<any, unknown>> =\n (anno: T, opts?: Object) => ({ unmount?: () => void }) | void;\n\nexport interface AnnotoriousPluginProps<T extends unknown = Annotator<any, unknown>> {\n\n plugin: AnnotatorPlugin<T>;\n\n opts?: Object;\n\n}\n\ntype PluginReturnType<T> = ReturnType<AnnotatorPlugin<T>>;\n\nexport const AnnotoriousPlugin = forwardRef(<T extends unknown = Annotator<any, unknown>>(\n props: AnnotoriousPluginProps<T>,\n ref: React.MutableRefObject<PluginReturnType<T>>\n) => {\n const { plugin, opts } = props;\n\n const anno = useAnnotator<T>();\n\n useEffect(() => {\n if (!anno) return;\n\n const p = plugin(anno, opts);\n\n if (ref)\n ref.current = p;\n\n return () => {\n if (p && 'unmount' in p) {\n p.unmount();\n }\n\n if (ref)\n ref.current = null;\n }\n }, [anno, plugin, opts, ref]);\n\n return null;\n\n});\n"],"names":["AnnotoriousPlugin","forwardRef","props","ref","plugin","opts","anno","useAnnotator","useEffect","p"],"mappings":";;AAiBO,MAAMA,IAAoBC,EAAW,CAC1CC,GACAC,MACG;AACG,QAAA,EAAE,QAAAC,GAAQ,MAAAC,EAAS,IAAAH,GAEnBI,IAAOC;AAEb,SAAAC,EAAU,MAAM;AACd,QAAI,CAACF,EAAM;AAEL,UAAAG,IAAIL,EAAOE,GAAMD,CAAI;AAEvB,WAAAF,MACFA,EAAI,UAAUM,IAET,MAAM;AACP,MAAAA,KAAK,aAAaA,KACpBA,EAAE,QAAQ,GAGRN,MACFA,EAAI,UAAU;AAAA,IAAA;AAAA,KAEjB,CAACG,GAAMF,GAAQC,GAAMF,CAAG,CAAC,GAErB;AAET,CAAC;"}
@@ -1,19 +1,19 @@
1
- import { jsx as s } from "./annotorious-react.es13.js";
1
+ import { j as e } from "./annotorious-react.es11.js";
2
2
  import { forwardRef as g } from "react";
3
- import { useDraggable as i } from "./annotorious-react.es15.js";
4
- const d = g((r, o) => {
5
- const { children: a, className: t, onDragStart: n, onDragEnd: e } = r;
6
- return i(o, { onDragStart: n, onDragEnd: e, cancel: "button, .no-drag" }), /* @__PURE__ */ s(
3
+ import { useDraggable as i } from "./annotorious-react.es13.js";
4
+ const p = g((r, o) => {
5
+ const { children: t, className: a, onDragStart: s, onDragEnd: n } = r;
6
+ return i(o, { onDragStart: s, onDragEnd: n, cancel: "button, .no-drag" }), /* @__PURE__ */ e.jsx(
7
7
  "div",
8
8
  {
9
9
  ref: o,
10
- className: t,
10
+ className: a,
11
11
  style: { position: "absolute" },
12
- children: a
12
+ children: t
13
13
  }
14
14
  );
15
15
  });
16
16
  export {
17
- d as Draggable
17
+ p as Draggable
18
18
  };
19
19
  //# sourceMappingURL=annotorious-react.es4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es4.js","sources":["../src/AnnotoriousPopup.tsx"],"sourcesContent":["import { forwardRef, ReactNode } from 'react';\nimport { ImageAnnotation } from '.';\nimport { useDraggable } from '@neodrag/react';\n\nexport interface AnnotoriousPopupProps {\n\n selected: { annotation: ImageAnnotation, editable?: boolean }[];\n\n}\n\nexport interface DraggableProps {\n\n children: ReactNode;\n\n className?: string;\n\n onDragStart?(): void;\n\n onDragEnd?(): void;\n\n}\n\nexport const Draggable = forwardRef((props: DraggableProps, ref: React.MutableRefObject<HTMLDivElement>) => {\n\n const { children, className, onDragStart, onDragEnd } = props;\n\n useDraggable(ref, { onDragStart, onDragEnd, cancel: 'button, .no-drag' });\n\n return (\n <div \n ref={ref} \n className={className} \n style={{ position: 'absolute' }}>\n {children}\n </div>\n )\n\n});"],"names":["Draggable","forwardRef","props","ref","children","className","onDragStart","onDragEnd","useDraggable","jsx"],"mappings":";;;AAsBO,MAAMA,IAAYC,EAAW,CAACC,GAAuBC,MAAiD;AAE3G,QAAM,EAAE,UAAAC,GAAU,WAAAC,GAAW,aAAAC,GAAa,WAAAC,MAAcL;AAExDM,SAAAA,EAAaL,GAAK,EAAE,aAAAG,GAAa,WAAAC,GAAW,QAAQ,oBAAoB,GAGtE,gBAAAE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAAN;AAAA,MACA,WAAAE;AAAA,MACA,OAAO,EAAE,UAAU,WAAW;AAAA,MAC7B,UAAAD;AAAA,IAAA;AAAA,EAAA;AAIP,CAAC;"}
1
+ {"version":3,"file":"annotorious-react.es4.js","sources":["../src/AnnotoriousPopup.tsx"],"sourcesContent":["import { forwardRef, ReactNode } from 'react';\nimport { ImageAnnotation } from '@annotorious/annotorious';\nimport { useDraggable } from '@neodrag/react';\n\nexport interface AnnotoriousPopupProps {\n\n selected: { annotation: ImageAnnotation, editable?: boolean }[];\n\n}\n\nexport interface DraggableProps {\n\n children: ReactNode;\n\n className?: string;\n\n onDragStart?(): void;\n\n onDragEnd?(): void;\n\n}\n\nexport const Draggable = forwardRef((props: DraggableProps, ref: React.MutableRefObject<HTMLDivElement>) => {\n\n const { children, className, onDragStart, onDragEnd } = props;\n\n useDraggable(ref, { onDragStart, onDragEnd, cancel: 'button, .no-drag' });\n\n return (\n <div \n ref={ref} \n className={className} \n style={{ position: 'absolute' }}>\n {children}\n </div>\n )\n\n});"],"names":["Draggable","forwardRef","props","ref","children","className","onDragStart","onDragEnd","useDraggable","jsx"],"mappings":";;;AAsBO,MAAMA,IAAYC,EAAW,CAACC,GAAuBC,MAAiD;AAE3G,QAAM,EAAE,UAAAC,GAAU,WAAAC,GAAW,aAAAC,GAAa,WAAAC,MAAcL;AAExDM,SAAAA,EAAaL,GAAK,EAAE,aAAAG,GAAa,WAAAC,GAAW,QAAQ,oBAAoB,GAGtEE,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAAN;AAAA,MACA,WAAAE;AAAA,MACA,OAAO,EAAE,UAAU,WAAW;AAAA,MAC7B,UAAAD;AAAA,IAAA;AAAA,EAAA;AAIP,CAAC;"}
@@ -1,26 +1,25 @@
1
- import { jsx as a, Fragment as g } from "./annotorious-react.es13.js";
2
- import { Children as d, useContext as x, useEffect as e, cloneElement as h } from "react";
3
- import { AnnotoriousContext as u } from "./annotorious-react.es2.js";
4
- import "./annotorious-react.es6.js";
5
- import "./annotorious-react.es7.js";
6
- import "./annotorious-react.es8.js";
7
- import { createImageAnnotator as y } from "./annotorious-react.es9.js";
8
- const L = (t) => {
9
- const { children: n, tool: A, ...i } = t, r = d.only(n), { anno: o, setAnno: l } = x(u), m = (c) => {
10
- if (!o) {
11
- const f = c.target, s = y(f, i);
12
- l(s);
1
+ import { j as n } from "./annotorious-react.es11.js";
2
+ import { Children as u, useContext as x, useEffect as o, cloneElement as A } from "react";
3
+ import { createImageAnnotator as g } from "@annotorious/annotorious";
4
+ import { AnnotoriousContext as d } from "./annotorious-react.es2.js";
5
+ const E = (t) => {
6
+ const { children: i, tool: h, ...l } = t, c = u.only(i), { anno: e, setAnno: r } = x(d), s = (m) => {
7
+ if (!e) {
8
+ const f = m.target, a = g(f, l);
9
+ r(a);
13
10
  }
14
11
  };
15
- return e(() => {
16
- t.tool && o && o.setDrawingTool(t.tool);
17
- }, [t.tool, o]), e(() => {
18
- o && o.setFilter(t.filter);
19
- }, [t.filter]), e(() => {
20
- o && o.setStyle(t.style);
21
- }, [t.style]), /* @__PURE__ */ a(g, { children: h(r, { onLoad: m }) });
12
+ return o(() => {
13
+ t.tool && e && e.setDrawingTool(t.tool);
14
+ }, [t.tool, e]), o(() => {
15
+ e && e.setFilter(t.filter);
16
+ }, [t.filter]), o(() => {
17
+ e && e.setStyle(t.style);
18
+ }, [t.style]), o(() => {
19
+ e && e.setUserSelectAction(t.userSelectAction);
20
+ }, [t.userSelectAction]), /* @__PURE__ */ n.jsx(n.Fragment, { children: A(c, { onLoad: s }) });
22
21
  };
23
22
  export {
24
- L as ImageAnnotator
23
+ E as ImageAnnotator
25
24
  };
26
25
  //# sourceMappingURL=annotorious-react.es5.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es5.js","sources":["../src/ImageAnnotator.tsx"],"sourcesContent":["import { Children, ReactElement, cloneElement, useContext, useEffect } from 'react';\nimport { AnnotoriousOpts, createImageAnnotator } from '.';\nimport type { DrawingStyle, DrawingTool, Filter, ImageAnnotation } from '.';\nimport { AnnotoriousContext } from './Annotorious';\n\nexport interface ImageAnnotatorProps<E extends unknown> extends AnnotoriousOpts<ImageAnnotation, E> {\n\n children: ReactElement<HTMLImageElement>;\n\n filter?: Filter<ImageAnnotation>;\n\n style?: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle);\n\n tool?: DrawingTool\n\n}\n\nexport const ImageAnnotator = <E extends unknown>(props: ImageAnnotatorProps<E>) => {\n\n const { children, tool, ...opts } = props;\n\n const child = Children.only(children);\n\n const { anno, setAnno } = useContext(AnnotoriousContext);\n\n const onLoad = (evt: Event) => {\n if (!anno) {\n const img = evt.target as HTMLImageElement;\n\n const next = createImageAnnotator(img, opts);\n setAnno(next); \n }\n };\n\n useEffect(() => {\n if (props.tool && anno) anno.setDrawingTool(props.tool);\n }, [props.tool, anno]);\n\n useEffect(() => {\n if (anno) anno.setFilter(props.filter);\n }, [props.filter]);\n\n useEffect(() => {\n if (anno) anno.setStyle(props.style);\n }, [props.style]);\n \n return <>{cloneElement(child, { onLoad } as Partial<HTMLImageElement>)}</>\n\n}"],"names":["ImageAnnotator","props","children","tool","opts","child","Children","anno","setAnno","useContext","AnnotoriousContext","onLoad","evt","img","next","createImageAnnotator","useEffect","cloneElement"],"mappings":";;;;;;;AAiBa,MAAAA,IAAiB,CAAoBC,MAAkC;AAElF,QAAM,EAAE,UAAAC,GAAU,MAAAC,GAAM,GAAGC,MAASH,GAE9BI,IAAQC,EAAS,KAAKJ,CAAQ,GAE9B,EAAE,MAAAK,GAAM,SAAAC,EAAQ,IAAIC,EAAWC,CAAkB,GAEjDC,IAAS,CAACC,MAAe;AAC7B,QAAI,CAACL,GAAM;AACT,YAAMM,IAAMD,EAAI,QAEVE,IAAOC,EAAqBF,GAAKT,CAAI;AAC3C,MAAAI,EAAQM,CAAI;AAAA,IACd;AAAA,EAAA;AAGF,SAAAE,EAAU,MAAM;AACd,IAAIf,EAAM,QAAQM,KAAWA,EAAA,eAAeN,EAAM,IAAI;AAAA,EACrD,GAAA,CAACA,EAAM,MAAMM,CAAI,CAAC,GAErBS,EAAU,MAAM;AACV,IAAAT,KAAWA,EAAA,UAAUN,EAAM,MAAM;AAAA,EAAA,GACpC,CAACA,EAAM,MAAM,CAAC,GAEjBe,EAAU,MAAM;AACV,IAAAT,KAAWA,EAAA,SAASN,EAAM,KAAK;AAAA,EAAA,GAClC,CAACA,EAAM,KAAK,CAAC,0BAEN,UAAagB,EAAAZ,GAAO,EAAE,QAAAM,GAAsC,EAAE,CAAA;AAE1E;"}
1
+ {"version":3,"file":"annotorious-react.es5.js","sources":["../src/ImageAnnotator.tsx"],"sourcesContent":["import { Children, ReactElement, cloneElement, useContext, useEffect } from 'react';\nimport { AnnotoriousOpts, createImageAnnotator } from '@annotorious/annotorious';\nimport type { DrawingStyle, DrawingTool, Filter, ImageAnnotation } from '@annotorious/annotorious';\nimport { AnnotoriousContext } from './Annotorious';\n\nexport interface ImageAnnotatorProps<E extends unknown> extends AnnotoriousOpts<ImageAnnotation, E> {\n\n children: ReactElement<HTMLImageElement>;\n\n filter?: Filter<ImageAnnotation>;\n\n style?: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle);\n\n tool?: DrawingTool;\n\n}\n\nexport const ImageAnnotator = <E extends unknown>(props: ImageAnnotatorProps<E>) => {\n\n const { children, tool, ...opts } = props;\n\n const child = Children.only(children);\n\n const { anno, setAnno } = useContext(AnnotoriousContext);\n\n const onLoad = (evt: Event) => {\n if (!anno) {\n const img = evt.target as HTMLImageElement;\n\n const next = createImageAnnotator(img, opts);\n setAnno(next); \n }\n };\n\n useEffect(() => {\n if (props.tool && anno) anno.setDrawingTool(props.tool);\n }, [props.tool, anno]);\n\n useEffect(() => {\n if (anno) anno.setFilter(props.filter);\n }, [props.filter]);\n\n useEffect(() => {\n if (anno) anno.setStyle(props.style);\n }, [props.style]);\n\n useEffect(() => {\n if (anno) anno.setUserSelectAction(props.userSelectAction);\n }, [props.userSelectAction]);\n \n return <>{cloneElement(child, { onLoad } as Partial<HTMLImageElement>)}</>\n\n}\n"],"names":["ImageAnnotator","props","children","tool","opts","child","Children","anno","setAnno","useContext","AnnotoriousContext","onLoad","evt","img","next","createImageAnnotator","useEffect","cloneElement"],"mappings":";;;;AAiBa,MAAAA,IAAiB,CAAoBC,MAAkC;AAElF,QAAM,EAAE,UAAAC,GAAU,MAAAC,GAAM,GAAGC,MAASH,GAE9BI,IAAQC,EAAS,KAAKJ,CAAQ,GAE9B,EAAE,MAAAK,GAAM,SAAAC,EAAQ,IAAIC,EAAWC,CAAkB,GAEjDC,IAAS,CAACC,MAAe;AAC7B,QAAI,CAACL,GAAM;AACT,YAAMM,IAAMD,EAAI,QAEVE,IAAOC,EAAqBF,GAAKT,CAAI;AAC3C,MAAAI,EAAQM,CAAI;AAAA,IACd;AAAA,EAAA;AAGF,SAAAE,EAAU,MAAM;AACd,IAAIf,EAAM,QAAQM,KAAWA,EAAA,eAAeN,EAAM,IAAI;AAAA,EACrD,GAAA,CAACA,EAAM,MAAMM,CAAI,CAAC,GAErBS,EAAU,MAAM;AACd,IAAIT,KAAMA,EAAK,UAAUN,EAAM,MAAM;AAAA,EAAA,GACpC,CAACA,EAAM,MAAM,CAAC,GAEjBe,EAAU,MAAM;AACd,IAAIT,KAAMA,EAAK,SAASN,EAAM,KAAK;AAAA,EAAA,GAClC,CAACA,EAAM,KAAK,CAAC,GAEhBe,EAAU,MAAM;AACd,IAAIT,KAAMA,EAAK,oBAAoBN,EAAM,gBAAgB;AAAA,EAAA,GACxD,CAACA,EAAM,gBAAgB,CAAC,uCAEjB,UAAagB,EAAAZ,GAAO,EAAE,QAAAM,GAAsC,EAAE,CAAA;AAE1E;"}
@@ -1,85 +1,32 @@
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 g() {
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 y(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 U(t, r, e) {
19
- if (i.randomUUID && !r && !t)
20
- return i.randomUUID();
21
- t = t || {};
22
- const a = t.random || (t.rng || g)();
23
- if (a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, r) {
24
- e = e || 0;
25
- for (let n = 0; n < 16; ++n)
26
- r[e + n] = a[n];
27
- return r;
28
- }
29
- return y(a);
30
- }
31
- const b = (t, r, e, a) => ({
32
- id: U(),
33
- annotation: t.id,
34
- created: e || /* @__PURE__ */ new Date(),
35
- creator: a,
36
- ...r
37
- });
38
- var h = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(h || {});
39
- let E = (t) => crypto.getRandomValues(new Uint8Array(t)), C = (t, r, e) => {
40
- let a = (2 << Math.log(t.length - 1) / Math.LN2) - 1, n = -~(1.6 * a * r / t.length);
41
- return (d = r) => {
42
- let s = "";
43
- for (; ; ) {
44
- let l = e(n), u = n;
45
- for (; u--; )
46
- if (s += t[l[u] & a] || "", s.length === d)
47
- return s;
1
+ import { j as c } from "./annotorious-react.es11.js";
2
+ import { createContext as w, useState as u, useContext as a, useEffect as i } from "react";
3
+ import { createOSDAnnotator as g } from "@annotorious/openseadragon";
4
+ import { AnnotoriousContext as m } from "./annotorious-react.es2.js";
5
+ const d = w({ viewer: null, setViewer: null }), S = (e) => {
6
+ const { children: x, tool: r, ...f } = e, [o, s] = u(), { anno: t, setAnno: l } = a(m);
7
+ return i(() => {
8
+ if (o) {
9
+ const n = g(o, f);
10
+ return e.drawingEnabled !== void 0 && n.setDrawingEnabled(e.drawingEnabled), e.filter && n.setFilter(e.filter), e.style && n.setStyle(e.style), e.tool && n.setDrawingTool(e.tool), l(n), () => {
11
+ n.destroy(), l(void 0);
12
+ };
48
13
  }
49
- };
50
- }, D = (t, r = 21) => C(t, r, E), R = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce((r, e) => (e &= 63, e < 36 ? r += e.toString(36) : e < 62 ? r += (e - 26).toString(36).toUpperCase() : e > 62 ? r += "-" : r += "_", r), "");
51
- const A = () => ({ isGuest: !0, id: D("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), O = [
52
- "#ff7c00",
53
- // orange
54
- "#1ac938",
55
- // green
56
- "#e8000b",
57
- // red
58
- "#8b2be2",
59
- // purple
60
- "#9f4800",
61
- // brown
62
- "#f14cc1",
63
- // pink
64
- "#ffc400",
65
- // khaki
66
- "#00d7ff",
67
- // cyan
68
- "#023eff"
69
- // blue
70
- ], I = () => {
71
- const t = [...O];
72
- return { assignRandomColor: () => {
73
- const r = Math.floor(Math.random() * t.length), e = t[r];
74
- return t.splice(r, 1), e;
75
- }, releaseColor: (r) => t.push(r) };
14
+ }, [o]), i(() => {
15
+ t && t.setDrawingEnabled(e.drawingEnabled);
16
+ }, [e.drawingEnabled]), i(() => {
17
+ t && t.setFilter(e.filter);
18
+ }, [e.filter]), i(() => {
19
+ t && t.setStyle(e.style);
20
+ }, [e.style]), i(() => {
21
+ t && t.setDrawingTool(r);
22
+ }, [r]), /* @__PURE__ */ c.jsx(d.Provider, { value: { viewer: o, setViewer: s }, children: e.children });
23
+ }, A = () => {
24
+ const { viewer: e } = a(d);
25
+ return e;
76
26
  };
77
- R();
78
27
  export {
79
- h as Origin,
80
- f as PointerSelectAction,
81
- A as createAnonymousGuest,
82
- b as createBody,
83
- I as defaultColorProvider
28
+ S as OpenSeadragonAnnotator,
29
+ d as OpenSeadragonAnnotatorContext,
30
+ A as useViewer
84
31
  };
85
32
  //# sourceMappingURL=annotorious-react.es8.js.map