@annotorious/react 3.0.0-rc.14 → 3.0.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Annotorious.d.ts +8 -0
- package/dist/Annotorious.d.ts.map +1 -1
- package/dist/annotorious-react.es.js +29 -21
- package/dist/annotorious-react.es.js.map +1 -1
- package/dist/annotorious-react.es10.js +35 -7
- package/dist/annotorious-react.es10.js.map +1 -1
- package/dist/annotorious-react.es11.js +15 -152
- package/dist/annotorious-react.es11.js.map +1 -1
- package/dist/annotorious-react.es12.js +4 -6
- package/dist/annotorious-react.es12.js.map +1 -1
- package/dist/annotorious-react.es13.js +8 -2
- package/dist/annotorious-react.es13.js.map +1 -1
- package/dist/annotorious-react.es14.js +152 -29
- package/dist/annotorious-react.es14.js.map +1 -1
- package/dist/annotorious-react.es15.js +6 -599
- package/dist/annotorious-react.es15.js.map +1 -1
- package/dist/annotorious-react.es16.js +2 -2
- package/dist/annotorious-react.es17.js +30 -2
- package/dist/annotorious-react.es17.js.map +1 -1
- package/dist/annotorious-react.es18.js +602 -0
- package/dist/annotorious-react.es18.js.map +1 -0
- package/dist/annotorious-react.es19.js +21012 -0
- package/dist/annotorious-react.es19.js.map +1 -0
- package/dist/annotorious-react.es2.js +42 -41
- package/dist/annotorious-react.es2.js.map +1 -1
- package/dist/annotorious-react.es20.js +35 -0
- package/dist/annotorious-react.es20.js.map +1 -0
- package/dist/annotorious-react.es21.js +5 -0
- package/dist/annotorious-react.es21.js.map +1 -0
- package/dist/annotorious-react.es22.js +5 -0
- package/dist/annotorious-react.es22.js.map +1 -0
- package/dist/annotorious-react.es4.js +2 -2
- package/dist/annotorious-react.es5.js +1 -1
- package/dist/annotorious-react.es9.js +33 -4
- package/dist/annotorious-react.es9.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/openseadragon/OpenSeadragonAnnotator.d.ts.map +1 -1
- package/dist/openseadragon/annotorious-react-osd.es2.js +17 -17
- package/dist/openseadragon/annotorious-react-osd.es2.js.map +1 -1
- package/dist/openseadragon/annotorious-react-osd.es7.js +29 -28
- package/dist/openseadragon/annotorious-react-osd.es7.js.map +1 -1
- package/package.json +1 -12
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { jsx as U } from "./annotorious-react.
|
|
2
|
-
import { createContext as j, forwardRef as E, useState as f, useImperativeHandle as H, useEffect as h, useContext as
|
|
3
|
-
import { useDebounce as C } from "./annotorious-react.
|
|
4
|
-
const
|
|
1
|
+
import { jsx as U } from "./annotorious-react.es12.js";
|
|
2
|
+
import { createContext as j, forwardRef as E, useState as f, useImperativeHandle as H, useEffect as h, useContext as s } from "react";
|
|
3
|
+
import { useDebounce as C } from "./annotorious-react.es13.js";
|
|
4
|
+
const n = j({
|
|
5
5
|
anno: void 0,
|
|
6
6
|
setAnno: void 0,
|
|
7
7
|
annotations: [],
|
|
8
8
|
selection: { selected: [] }
|
|
9
|
-
}), B = E((t,
|
|
10
|
-
const [
|
|
11
|
-
return H(
|
|
12
|
-
if (
|
|
13
|
-
const { selection: m, store: e } =
|
|
14
|
-
e.all().length > 0 &&
|
|
15
|
-
const v = (a) =>
|
|
9
|
+
}), B = E((t, r) => {
|
|
10
|
+
const [o, u] = f(null), [p, c] = f([]), [A, l] = f({ selected: [] });
|
|
11
|
+
return H(r, () => o), h(() => {
|
|
12
|
+
if (o) {
|
|
13
|
+
const { selection: m, store: e } = o.state;
|
|
14
|
+
e.all().length > 0 && c(e.all());
|
|
15
|
+
const v = (a) => c(() => e.all());
|
|
16
16
|
e.observe(v);
|
|
17
17
|
let i;
|
|
18
18
|
const b = m.subscribe(({ selected: a, pointerEvent: w }) => {
|
|
@@ -32,66 +32,67 @@ const o = j({
|
|
|
32
32
|
e.unobserve(v), b();
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
}, [
|
|
36
|
-
anno:
|
|
35
|
+
}, [o]), /* @__PURE__ */ U(n.Provider, { value: {
|
|
36
|
+
anno: o,
|
|
37
37
|
setAnno: u,
|
|
38
38
|
annotations: p,
|
|
39
39
|
selection: A
|
|
40
40
|
}, children: t.children });
|
|
41
|
-
}), F = () => {
|
|
42
|
-
const { anno: t } =
|
|
41
|
+
}), F = () => s(n), G = () => {
|
|
42
|
+
const { anno: t } = s(n);
|
|
43
43
|
return t;
|
|
44
|
-
},
|
|
45
|
-
const { anno: t } =
|
|
44
|
+
}, J = () => {
|
|
45
|
+
const { anno: t } = s(n);
|
|
46
46
|
return t == null ? void 0 : t.state.store;
|
|
47
47
|
}, P = () => {
|
|
48
|
-
const { annotations: t } =
|
|
48
|
+
const { annotations: t } = s(n);
|
|
49
49
|
return t;
|
|
50
50
|
}, R = (t) => {
|
|
51
|
-
const { annotations:
|
|
52
|
-
return C(
|
|
53
|
-
},
|
|
54
|
-
const { selection: t } =
|
|
51
|
+
const { annotations: r } = s(n);
|
|
52
|
+
return C(r, t);
|
|
53
|
+
}, K = (t) => t ? R(t) : P(), L = () => {
|
|
54
|
+
const { selection: t } = s(n);
|
|
55
55
|
return t;
|
|
56
|
-
},
|
|
57
|
-
const { anno: t } =
|
|
56
|
+
}, M = () => {
|
|
57
|
+
const { anno: t } = s(n);
|
|
58
58
|
return t == null ? void 0 : t.getUser();
|
|
59
59
|
}, _ = () => {
|
|
60
|
-
const { anno: t } =
|
|
60
|
+
const { anno: t } = s(n), [r, o] = f([]);
|
|
61
61
|
return h(() => {
|
|
62
62
|
if (t) {
|
|
63
63
|
const { store: u, viewport: p } = t.state;
|
|
64
64
|
if (!p)
|
|
65
65
|
return;
|
|
66
|
-
let
|
|
66
|
+
let c;
|
|
67
67
|
const A = p.subscribe((l) => {
|
|
68
|
-
|
|
68
|
+
c && u.unobserve(c);
|
|
69
69
|
const m = l.map((e) => u.getAnnotation(e));
|
|
70
|
-
|
|
70
|
+
o(m), c = (e) => {
|
|
71
71
|
const { updated: v } = e.changes;
|
|
72
|
-
|
|
72
|
+
o((i) => i.map((b) => {
|
|
73
73
|
const a = v.find((w) => w.oldValue.id === b.id);
|
|
74
74
|
return a ? a.newValue : b;
|
|
75
75
|
}));
|
|
76
|
-
}, u.observe(
|
|
76
|
+
}, u.observe(c, { annotations: l });
|
|
77
77
|
});
|
|
78
78
|
return () => {
|
|
79
79
|
A();
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
}, [t]),
|
|
82
|
+
}, [t]), r;
|
|
83
83
|
}, k = (t) => {
|
|
84
|
-
const
|
|
85
|
-
return C(
|
|
86
|
-
},
|
|
84
|
+
const r = _();
|
|
85
|
+
return C(r, t);
|
|
86
|
+
}, N = (t) => t ? k(t) : _();
|
|
87
87
|
export {
|
|
88
88
|
B as Annotorious,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
n as AnnotoriousContext,
|
|
90
|
+
J as useAnnotationStore,
|
|
91
|
+
K as useAnnotations,
|
|
92
|
+
G as useAnnotator,
|
|
93
|
+
F as useAnnotatorState,
|
|
94
|
+
M as useAnnotatorUser,
|
|
95
|
+
L as useSelection,
|
|
96
|
+
N as useViewportState
|
|
96
97
|
};
|
|
97
98
|
//# 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 '@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 = (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","
|
|
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 = (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 useAnnotatorState = () => useContext(AnnotoriousContext);\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","useAnnotatorState","useContext","useAnnotator","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,GAA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CAAa,IAAInC,EAAc,CAAE,CAAA;AAEpD,SAAAM,EAAU,MAAM;AACd,QAAIR,GAAM;AACR,YAAM,EAAE,OAAAS,GAAO,UAAA6B,MAAatC,EAAK;AAEjC,UAAI,CAACsC;AACH;AAIE,UAAAC;AAEE,YAAAC,IAAsBF,EAAS,UAAU,CAAOG,MAAA;AAChD,QAAAF,KACF9B,EAAM,UAAU8B,CAAqB;AAEvC,cAAMvB,IAAWyB,EAAI,IAAI,OAAMhC,EAAM,cAAcQ,CAAE,CAAC;AACtD,QAAAoB,EAAcrB,CAAQ,GAEtBuB,IAAwB,CAAS5B,MAAA;AACzB,gBAAA,EAAE,SAAAQ,EAAQ,IAAIR,EAAM;AAEZ,UAAA0B,EAAA,CAAAlC,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,QAAQ8B,GAAuB,EAAE,aAAaE,EAAK,CAAA;AAAA,MAAA,CAC1D;AAED,aAAO,MAAM;AACS,QAAAD;MAAA;AAAA,IAExB;AAAA,EAAA,GACC,CAACxC,CAAI,CAAC,GAEFoC;AACT,GAEMM,IAA8B,CAAuBZ,MAAqB;AAC9E,QAAMM,IAAaD;AACZ,SAAAJ,EAAYK,GAAYN,CAAQ;AACzC,GAEaa,IAAoB,CAAuBb,MACtDA,IAAWY,EAA8BZ,CAAQ,IAAIK,EAAqB;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}, 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
|
+
}, 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 ? A() : E() : g > a ? R() : B();
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
T as setPosition
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=annotorious-react.es20.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotorious-react.es20.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,EAAW,OAAO,SAAS,SAAS,QAGjEM,IAAUP,EAAO,SAAS,gCAAgC,IAAIQ,EAAc,MAAML,GAAMC,CAAI,CAAC,GAC7FK,IAAcT,EAAO,SAAS,gCAAgC,IAAIQ,EAAc,MAAMH,GAAMC,CAAI,CAAC;AAGhG,SAAA;AAAA,IACL,GAAGC,EAAQ,IAAIL,EAAa;AAAA,IAC5B,OAAOO,EAAY,IAAIP,EAAa;AAAA,IACpC,GAAGK,EAAQ,IAAIL,EAAa;AAAA,IAC5B,QAAQO,EAAY,IAAIP,EAAa;AAAA,IACrC,OAAOO,EAAY,IAAIF,EAAQ;AAAA,IAC/B,QAAQE,EAAY,IAAIF,EAAQ;AAAA,EAAA;AAEpC,GAEaG,IAAc,CACzBV,GACAC,GACAU,GACAC,IAAqB,MAClB;AACG,QAAAV,IAAeF,EAAO,QAAQ,sBAAsB,GACpDa,IAAad,EAAqBC,GAAQC,CAAU,GAGpDa,IAAiBD,EAAW,IAAIX,EAAa,GAC7Ca,IAAiBb,EAAa,QAAQW,EAAW,GACjDG,IAAiBd,EAAa,SAASW,EAAW,QAClDI,IAAgBJ,EAAW,IAAIX,EAAa,MAG5CgB,IAAcP,EAAM,kBAAkB,sBAAsB,GAgB5DQ,IAAaL,IAAiBI,EAAY,QAC1CE,IAAaL,IAAiBG,EAAY,OAC1CG,IAAaL,IAAiBE,EAAY,QAC1CI,IAAYL,IAAgBC,EAAY,OAExCK,IAAU,MAAM;AACpB,IAAAZ,EAAM,MAAM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AK,IAAI,GAAGA,CAAM,CAAC;AAEjD,EAAIC,MAAW,IAETZ,IAAaE,IACPC,MAECC,MACFQ,MAAW,IAEhBb,IAAaE,IACPO,MAEEF,MACHM,MAAW,IAEhBZ,IAAaE,IACJO,MAECC,MAGVX,IAAaE,IACRM,MAEEF;AAEf;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotorious-react.es21.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotorious-react.es22.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as s } from "./annotorious-react.
|
|
1
|
+
import { jsx as s } from "./annotorious-react.es12.js";
|
|
2
2
|
import { forwardRef as g } from "react";
|
|
3
|
-
import { useDraggable as i } from "./annotorious-react.
|
|
3
|
+
import { useDraggable as i } from "./annotorious-react.es14.js";
|
|
4
4
|
const d = g((r, o) => {
|
|
5
5
|
const { children: a, className: t, onDragStart: n, onDragEnd: e } = r;
|
|
6
6
|
return i(o, { onDragStart: n, onDragEnd: e, cancel: "button, .no-drag" }), /* @__PURE__ */ s(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as a, Fragment as g } from "./annotorious-react.
|
|
1
|
+
import { jsx as a, Fragment as g } from "./annotorious-react.es12.js";
|
|
2
2
|
import { Children as d, useContext as x, useEffect as e, cloneElement as h } from "react";
|
|
3
3
|
import { createImageAnnotator as u } from "@annotorious/annotorious";
|
|
4
4
|
import { AnnotoriousContext as y } from "./annotorious-react.es2.js";
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { jsx as f } from "./annotorious-react.es12.js";
|
|
2
|
+
import { createContext as d, useState as m, useEffect as n, useContext as w } from "react";
|
|
3
|
+
import { createOSDAnnotator as u } from "./annotorious-react.es19.js";
|
|
4
|
+
import { useAnnotatorState as g } from "./annotorious-react.es2.js";
|
|
5
|
+
import "./annotorious-react.es6.js";
|
|
6
|
+
import "./annotorious-react.es7.js";
|
|
7
|
+
import "./annotorious-react.es8.js";
|
|
8
|
+
import "@annotorious/annotorious";
|
|
9
|
+
const l = d({ viewer: null, setViewer: null }), C = (t) => {
|
|
10
|
+
const { children: v, tool: a, ...s } = t, [o, c] = m(), { anno: e, setAnno: i } = g();
|
|
11
|
+
return n(() => {
|
|
12
|
+
if (o) {
|
|
13
|
+
const r = u(o, s);
|
|
14
|
+
return console.log(r, i), t.tool && r.setDrawingTool(t.tool), i(r), () => {
|
|
15
|
+
r.destroy(), i(void 0);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}, [o]), n(() => {
|
|
19
|
+
e && e.setDrawingTool(a);
|
|
20
|
+
}, [a]), n(() => {
|
|
21
|
+
e && e.setDrawingEnabled(t.drawingEnabled);
|
|
22
|
+
}, [t.drawingEnabled]), n(() => {
|
|
23
|
+
e && e.setFilter(t.filter);
|
|
24
|
+
}, [t.filter]), n(() => {
|
|
25
|
+
e && e.setStyle(t.style);
|
|
26
|
+
}, [t.style]), /* @__PURE__ */ f(l.Provider, { value: { viewer: o, setViewer: c }, children: t.children });
|
|
27
|
+
}, O = () => {
|
|
28
|
+
const { viewer: t } = w(l);
|
|
29
|
+
return t;
|
|
30
|
+
};
|
|
3
31
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
32
|
+
C as OpenSeadragonAnnotator,
|
|
33
|
+
l as OpenSeadragonAnnotatorContext,
|
|
34
|
+
O as useViewer
|
|
6
35
|
};
|
|
7
36
|
//# sourceMappingURL=annotorious-react.es9.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotorious-react.es9.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"annotorious-react.es9.js","sources":["../src/openseadragon/OpenSeadragonAnnotator.tsx"],"sourcesContent":["import { createContext, ReactNode, useContext, useEffect, useState } from 'react';\nimport OpenSeadragon from 'openseadragon';\nimport { createOSDAnnotator } from '@annotorious/openseadragon';\nimport { AnnotoriousOpts, DrawingStyle, Filter, ImageAnnotation } from '@annotorious/annotorious';\nimport { useAnnotatorState } from '..';\n\nexport const OpenSeadragonAnnotatorContext = createContext<{ \n viewer: OpenSeadragon.Viewer,\n setViewer(viewer: OpenSeadragon.Viewer): void\n}>({ viewer: null, setViewer: null });\n\nexport type OpenSeadragonAnnotatorProps<E extends unknown> = AnnotoriousOpts<ImageAnnotation, E> & {\n\n children?: ReactNode;\n\n drawingEnabled?: boolean;\n\n filter?: Filter<ImageAnnotation>;\n\n style?: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle);\n\n tool?: string | null;\n\n}\n\nexport const OpenSeadragonAnnotator = <E extends unknown>(props: OpenSeadragonAnnotatorProps<E>) => {\n\n const { children, tool, ...opts } = props;\n\n const [viewer, setViewer] = useState<OpenSeadragon.Viewer>();\n\n const { anno, setAnno } = useAnnotatorState();\n\n useEffect(() => {\n if (viewer) {\n const anno = createOSDAnnotator<E>(viewer, opts);\n\n console.log(anno, setAnno);\n\n if (props.tool)\n anno.setDrawingTool(props.tool);\n\n setAnno(anno);\n\n return () => {\n anno.destroy();\n setAnno(undefined);\n }\n }\n }, [viewer]);\n\n useEffect(() => {\n if (anno) anno.setDrawingTool(tool);\n }, [tool]);\n\n useEffect(() => {\n if (anno) anno.setDrawingEnabled(props.drawingEnabled);\n }, [props.drawingEnabled]);\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 (\n <OpenSeadragonAnnotatorContext.Provider value={{ viewer, setViewer }}>\n {props.children}\n </OpenSeadragonAnnotatorContext.Provider>\n )\n\n}\n\nexport const useViewer = () => {\n const { viewer } = useContext(OpenSeadragonAnnotatorContext);\n return viewer;\n}"],"names":["OpenSeadragonAnnotatorContext","createContext","OpenSeadragonAnnotator","props","children","tool","opts","viewer","setViewer","useState","anno","setAnno","useAnnotatorState","useEffect","createOSDAnnotator","jsx","useViewer","useContext"],"mappings":";;;;;;;;AAMO,MAAMA,IAAgCC,EAG1C,EAAE,QAAQ,MAAM,WAAW,MAAM,GAgBvBC,IAAyB,CAAoBC,MAA0C;AAElG,QAAM,EAAE,UAAAC,GAAU,MAAAC,GAAM,GAAGC,MAASH,GAE9B,CAACI,GAAQC,CAAS,IAAIC,EAA+B,GAErD,EAAE,MAAAC,GAAM,SAAAC,EAAQ,IAAIC,EAAkB;AAE5C,SAAAC,EAAU,MAAM;AACd,QAAIN,GAAQ;AACJG,YAAAA,IAAOI,EAAsBP,GAAQD,CAAI;AAEvC,qBAAA,IAAII,GAAMC,CAAO,GAErBR,EAAM,QACRO,EAAK,eAAeP,EAAM,IAAI,GAEhCQ,EAAQD,CAAI,GAEL,MAAM;AACXA,QAAAA,EAAK,QAAQ,GACbC,EAAQ,MAAS;AAAA,MAAA;AAAA,IAErB;AAAA,EAAA,GACC,CAACJ,CAAM,CAAC,GAEXM,EAAU,MAAM;AACV,IAAAH,KAAMA,EAAK,eAAeL,CAAI;AAAA,EAAA,GACjC,CAACA,CAAI,CAAC,GAETQ,EAAU,MAAM;AACV,IAAAH,KAAWA,EAAA,kBAAkBP,EAAM,cAAc;AAAA,EAAA,GACpD,CAACA,EAAM,cAAc,CAAC,GAEzBU,EAAU,MAAM;AACV,IAAAH,KAAWA,EAAA,UAAUP,EAAM,MAAM;AAAA,EAAA,GACpC,CAACA,EAAM,MAAM,CAAC,GAEjBU,EAAU,MAAM;AACV,IAAAH,KAAWA,EAAA,SAASP,EAAM,KAAK;AAAA,EAAA,GAClC,CAACA,EAAM,KAAK,CAAC,GAGd,gBAAAY,EAACf,EAA8B,UAA9B,EAAuC,OAAO,EAAE,QAAAO,GAAQ,WAAAC,EACtD,GAAA,UAAAL,EAAM,SACT,CAAA;AAGJ,GAEaa,IAAY,MAAM;AAC7B,QAAM,EAAE,QAAAT,EAAA,IAAWU,EAAWjB,CAA6B;AACpD,SAAAO;AACT;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './Annotorious';
|
|
|
2
2
|
export * from './AnnotoriousPlugin';
|
|
3
3
|
export * from './AnnotoriousPopup';
|
|
4
4
|
export * from './ImageAnnotator';
|
|
5
|
+
export * from './openseadragon';
|
|
5
6
|
export type { Annotation, AnnotationBody, AnnotationTarget, Annotator, AnnotatorState, Appearance, AppearanceProvider, Color, DrawingStyle, Filter, FormatAdapter, HoverState, LifecycleEvents, ParseResult, PresentUser, Purpose, Selection, SelectionState, Store, StoreChangeEvent, StoreObserver, User, W3CAnnotation, W3CAnnotationBody, W3CAnnotationTarget, W3CSelector } from '@annotorious/core';
|
|
6
7
|
import { createAnonymousGuest as _createAnonymousGuest, createBody as _createBody, defaultColorProvider as _defaultColorProvider, Origin as _Origin, PointerSelectAction as _PointerSelectAction } from '@annotorious/core';
|
|
7
8
|
export { _createAnonymousGuest as createAnonymousGuest };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC;AAGhC,OAAO,0CAA0C,CAAC;AAClD,OAAO,0DAA0D,CAAC;AAGlE,YAAY,EACV,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,KAAK,EACL,YAAY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sources":["../../src/openseadragon/OpenSeadragonAnnotator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAmC,MAAM,OAAO,CAAC;AAClF,OAAO,aAAa,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGlG,eAAO,MAAM,6BAA6B;YAChC,cAAc,MAAM;sBACV,cAAc,MAAM,GAAG,IAAI;EACV,CAAC;AAEtC,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,OAAO,IAAI,eAAe,CAAC,eAAe,EAAE,CAAC,CAAC,GAAG;IAEjG,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,MAAM,CAAC,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC;IAEjC,KAAK,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,UAAU,EAAE,eAAe,KAAK,YAAY,CAAC,CAAC;IAEvE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAEtB,CAAA;AAED,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"OpenSeadragonAnnotator.d.ts","sourceRoot":"","sources":["../../src/openseadragon/OpenSeadragonAnnotator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAmC,MAAM,OAAO,CAAC;AAClF,OAAO,aAAa,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGlG,eAAO,MAAM,6BAA6B;YAChC,cAAc,MAAM;sBACV,cAAc,MAAM,GAAG,IAAI;EACV,CAAC;AAEtC,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,OAAO,IAAI,eAAe,CAAC,eAAe,EAAE,CAAC,CAAC,GAAG;IAEjG,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,MAAM,CAAC,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC;IAEjC,KAAK,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,UAAU,EAAE,eAAe,KAAK,YAAY,CAAC,CAAC;IAEvE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAEtB,CAAA;AAED,eAAO,MAAM,sBAAsB,uGAgDlC,CAAA;AAED,eAAO,MAAM,SAAS,4BAGrB,CAAA"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { createOSDAnnotator as
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
6
|
-
const { children: v, tool:
|
|
1
|
+
import { jsx as f } from "./annotorious-react-osd.es5.js";
|
|
2
|
+
import { createContext as d, useState as w, useEffect as n, useContext as u } from "react";
|
|
3
|
+
import { createOSDAnnotator as g } from "./annotorious-react-osd.es6.js";
|
|
4
|
+
import { useAnnotatorState as m } from "./annotorious-react-osd.es7.js";
|
|
5
|
+
const l = d({ viewer: null, setViewer: null }), D = (e) => {
|
|
6
|
+
const { children: v, tool: a, ...s } = e, [o, c] = w(), { anno: t, setAnno: i } = m();
|
|
7
7
|
return n(() => {
|
|
8
8
|
if (o) {
|
|
9
|
-
const r =
|
|
10
|
-
return e.tool && r.setDrawingTool(e.tool),
|
|
11
|
-
r.destroy(),
|
|
9
|
+
const r = g(o, s);
|
|
10
|
+
return console.log(r, i), e.tool && r.setDrawingTool(e.tool), i(r), () => {
|
|
11
|
+
r.destroy(), i(void 0);
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
}, [o]), n(() => {
|
|
15
|
-
t && t.setDrawingTool(
|
|
16
|
-
}, [
|
|
15
|
+
t && t.setDrawingTool(a);
|
|
16
|
+
}, [a]), n(() => {
|
|
17
17
|
t && t.setDrawingEnabled(e.drawingEnabled);
|
|
18
18
|
}, [e.drawingEnabled]), n(() => {
|
|
19
19
|
t && t.setFilter(e.filter);
|
|
20
20
|
}, [e.filter]), n(() => {
|
|
21
21
|
t && t.setStyle(e.style);
|
|
22
|
-
}, [e.style]), /* @__PURE__ */
|
|
23
|
-
},
|
|
24
|
-
const { viewer: e } = l
|
|
22
|
+
}, [e.style]), /* @__PURE__ */ f(l.Provider, { value: { viewer: o, setViewer: c }, children: e.children });
|
|
23
|
+
}, E = () => {
|
|
24
|
+
const { viewer: e } = u(l);
|
|
25
25
|
return e;
|
|
26
26
|
};
|
|
27
27
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
D as OpenSeadragonAnnotator,
|
|
29
|
+
l as OpenSeadragonAnnotatorContext,
|
|
30
|
+
E as useViewer
|
|
31
31
|
};
|
|
32
32
|
//# sourceMappingURL=annotorious-react-osd.es2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotorious-react-osd.es2.js","sources":["../../src/openseadragon/OpenSeadragonAnnotator.tsx"],"sourcesContent":["import { createContext, ReactNode, useContext, useEffect, useState } from 'react';\nimport OpenSeadragon from 'openseadragon';\nimport { createOSDAnnotator } from '@annotorious/openseadragon';\nimport { AnnotoriousOpts, DrawingStyle, Filter, ImageAnnotation } from '@annotorious/annotorious';\nimport {
|
|
1
|
+
{"version":3,"file":"annotorious-react-osd.es2.js","sources":["../../src/openseadragon/OpenSeadragonAnnotator.tsx"],"sourcesContent":["import { createContext, ReactNode, useContext, useEffect, useState } from 'react';\nimport OpenSeadragon from 'openseadragon';\nimport { createOSDAnnotator } from '@annotorious/openseadragon';\nimport { AnnotoriousOpts, DrawingStyle, Filter, ImageAnnotation } from '@annotorious/annotorious';\nimport { useAnnotatorState } from '..';\n\nexport const OpenSeadragonAnnotatorContext = createContext<{ \n viewer: OpenSeadragon.Viewer,\n setViewer(viewer: OpenSeadragon.Viewer): void\n}>({ viewer: null, setViewer: null });\n\nexport type OpenSeadragonAnnotatorProps<E extends unknown> = AnnotoriousOpts<ImageAnnotation, E> & {\n\n children?: ReactNode;\n\n drawingEnabled?: boolean;\n\n filter?: Filter<ImageAnnotation>;\n\n style?: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle);\n\n tool?: string | null;\n\n}\n\nexport const OpenSeadragonAnnotator = <E extends unknown>(props: OpenSeadragonAnnotatorProps<E>) => {\n\n const { children, tool, ...opts } = props;\n\n const [viewer, setViewer] = useState<OpenSeadragon.Viewer>();\n\n const { anno, setAnno } = useAnnotatorState();\n\n useEffect(() => {\n if (viewer) {\n const anno = createOSDAnnotator<E>(viewer, opts);\n\n console.log(anno, setAnno);\n\n if (props.tool)\n anno.setDrawingTool(props.tool);\n\n setAnno(anno);\n\n return () => {\n anno.destroy();\n setAnno(undefined);\n }\n }\n }, [viewer]);\n\n useEffect(() => {\n if (anno) anno.setDrawingTool(tool);\n }, [tool]);\n\n useEffect(() => {\n if (anno) anno.setDrawingEnabled(props.drawingEnabled);\n }, [props.drawingEnabled]);\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 (\n <OpenSeadragonAnnotatorContext.Provider value={{ viewer, setViewer }}>\n {props.children}\n </OpenSeadragonAnnotatorContext.Provider>\n )\n\n}\n\nexport const useViewer = () => {\n const { viewer } = useContext(OpenSeadragonAnnotatorContext);\n return viewer;\n}"],"names":["OpenSeadragonAnnotatorContext","createContext","OpenSeadragonAnnotator","props","children","tool","opts","viewer","setViewer","useState","anno","setAnno","useAnnotatorState","useEffect","createOSDAnnotator","jsx","useViewer","useContext"],"mappings":";;;;AAMO,MAAMA,IAAgCC,EAG1C,EAAE,QAAQ,MAAM,WAAW,MAAM,GAgBvBC,IAAyB,CAAoBC,MAA0C;AAElG,QAAM,EAAE,UAAAC,GAAU,MAAAC,GAAM,GAAGC,MAASH,GAE9B,CAACI,GAAQC,CAAS,IAAIC,EAA+B,GAErD,EAAE,MAAAC,GAAM,SAAAC,EAAQ,IAAIC,EAAkB;AAE5C,SAAAC,EAAU,MAAM;AACd,QAAIN,GAAQ;AACJG,YAAAA,IAAOI,EAAsBP,GAAQD,CAAI;AAEvC,qBAAA,IAAII,GAAMC,CAAO,GAErBR,EAAM,QACRO,EAAK,eAAeP,EAAM,IAAI,GAEhCQ,EAAQD,CAAI,GAEL,MAAM;AACXA,QAAAA,EAAK,QAAQ,GACbC,EAAQ,MAAS;AAAA,MAAA;AAAA,IAErB;AAAA,EAAA,GACC,CAACJ,CAAM,CAAC,GAEXM,EAAU,MAAM;AACV,IAAAH,KAAMA,EAAK,eAAeL,CAAI;AAAA,EAAA,GACjC,CAACA,CAAI,CAAC,GAETQ,EAAU,MAAM;AACV,IAAAH,KAAWA,EAAA,kBAAkBP,EAAM,cAAc;AAAA,EAAA,GACpD,CAACA,EAAM,cAAc,CAAC,GAEzBU,EAAU,MAAM;AACV,IAAAH,KAAWA,EAAA,UAAUP,EAAM,MAAM;AAAA,EAAA,GACpC,CAACA,EAAM,MAAM,CAAC,GAEjBU,EAAU,MAAM;AACV,IAAAH,KAAWA,EAAA,SAASP,EAAM,KAAK;AAAA,EAAA,GAClC,CAACA,EAAM,KAAK,CAAC,GAGd,gBAAAY,EAACf,EAA8B,UAA9B,EAAuC,OAAO,EAAE,QAAAO,GAAQ,WAAAC,EACtD,GAAA,UAAAL,EAAM,SACT,CAAA;AAGJ,GAEaa,IAAY,MAAM;AAC7B,QAAM,EAAE,QAAAT,EAAA,IAAWU,EAAWjB,CAA6B;AACpD,SAAAO;AACT;"}
|
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
1
|
+
import { jsx as E } from "./annotorious-react-osd.es5.js";
|
|
2
|
+
import { createContext as H, forwardRef as I, useState as a, useImperativeHandle as O, useEffect as P, useContext as m } from "react";
|
|
3
|
+
const i = H({
|
|
4
4
|
anno: void 0,
|
|
5
5
|
setAnno: void 0,
|
|
6
6
|
annotations: [],
|
|
7
7
|
selection: { selected: [] }
|
|
8
8
|
});
|
|
9
|
-
|
|
10
|
-
const [
|
|
11
|
-
return
|
|
12
|
-
if (
|
|
13
|
-
const { selection: h, store: e } =
|
|
9
|
+
I((s, p) => {
|
|
10
|
+
const [t, S] = a(null), [x, l] = a([]), [A, u] = a({ selected: [] });
|
|
11
|
+
return O(p, () => t), P(() => {
|
|
12
|
+
if (t) {
|
|
13
|
+
const { selection: h, store: e } = t.state;
|
|
14
14
|
e.all().length > 0 && l(e.all());
|
|
15
|
-
const
|
|
16
|
-
e.observe(
|
|
15
|
+
const d = (r) => l(() => e.all());
|
|
16
|
+
e.observe(d);
|
|
17
17
|
let o;
|
|
18
|
-
const
|
|
18
|
+
const g = h.subscribe(({ selected: r, pointerEvent: C }) => {
|
|
19
19
|
o && e.unobserve(o);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const { updated: c } =
|
|
23
|
-
|
|
24
|
-
selected:
|
|
25
|
-
const
|
|
26
|
-
return
|
|
20
|
+
const w = (r || []).map(({ id: n, editable: c }) => ({ annotation: e.getAnnotation(n), editable: c }));
|
|
21
|
+
u({ selected: w, pointerEvent: C }), o = (n) => {
|
|
22
|
+
const { updated: c } = n.changes;
|
|
23
|
+
u(({ selected: V }) => ({
|
|
24
|
+
selected: V.map(({ annotation: v, editable: f }) => {
|
|
25
|
+
const b = c.find((j) => j.oldValue.id === v.id);
|
|
26
|
+
return b ? { annotation: b.newValue, editable: f } : { annotation: v, editable: f };
|
|
27
27
|
})
|
|
28
28
|
}));
|
|
29
|
-
}, e.observe(o, { annotations: r.map(({ id:
|
|
29
|
+
}, e.observe(o, { annotations: r.map(({ id: n }) => n) });
|
|
30
30
|
});
|
|
31
31
|
return () => {
|
|
32
|
-
e.unobserve(
|
|
32
|
+
e.unobserve(d), g();
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
}, [
|
|
36
|
-
anno:
|
|
37
|
-
setAnno:
|
|
35
|
+
}, [t]), /* @__PURE__ */ E(i.Provider, { value: {
|
|
36
|
+
anno: t,
|
|
37
|
+
setAnno: S,
|
|
38
38
|
annotations: x,
|
|
39
|
-
selection:
|
|
39
|
+
selection: A
|
|
40
40
|
}, children: s.children });
|
|
41
41
|
});
|
|
42
|
-
const q = () => {
|
|
43
|
-
const { selection: s } =
|
|
42
|
+
const q = () => m(i), y = () => {
|
|
43
|
+
const { selection: s } = m(i);
|
|
44
44
|
return s;
|
|
45
45
|
};
|
|
46
46
|
export {
|
|
47
|
-
|
|
48
|
-
q as
|
|
47
|
+
i as AnnotoriousContext,
|
|
48
|
+
q as useAnnotatorState,
|
|
49
|
+
y as useSelection
|
|
49
50
|
};
|
|
50
51
|
//# sourceMappingURL=annotorious-react-osd.es7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotorious-react-osd.es7.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 = (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","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","
|
|
1
|
+
{"version":3,"file":"annotorious-react-osd.es7.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 = (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 useAnnotatorState = () => useContext(AnnotoriousContext);\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","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","useAnnotatorState","useContext","useSelection"],"mappings":";;AAyBO,MAAMA,IAAqBC,EAAc;AAAA,EAE9C,MAAM;AAAA,EAEN,SAAS;AAAA,EAET,aAAa,CAAC;AAAA,EAEd,WAAW,EAAE,UAAU,GAAG;AAE5B,CAAC;AAE0BC,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,CAACC,MACrBP,EAAe,MAAMK,EAAM,KAAK;AAElC,MAAAA,EAAM,QAAQC,CAAa;AAIvB,UAAAE;AA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oB,EAAW9B,CAAkB;AAC5C,SAAAU;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@annotorious/react",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.15",
|
|
4
4
|
"description": "Annotorious React bindings",
|
|
5
5
|
"author": "Rainer Simon",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -21,19 +21,8 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/annotorious-react.es.js"
|
|
23
23
|
},
|
|
24
|
-
"./openseadragon": {
|
|
25
|
-
"types": "./dist/openseadragon/index.d.ts",
|
|
26
|
-
"import": "./dist/openseadragon/annotorious-react-osd.es.js"
|
|
27
|
-
},
|
|
28
24
|
"./annotorious-react.css": "./dist/annotorious-react.css"
|
|
29
25
|
},
|
|
30
|
-
"typesVersions": {
|
|
31
|
-
"*": {
|
|
32
|
-
"openseadragon": [
|
|
33
|
-
"./dist/openseadragon/index.d.ts"
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
26
|
"devDependencies": {
|
|
38
27
|
"@types/react": "^18.2.15",
|
|
39
28
|
"@types/react-dom": "^18.2.7",
|