@annotorious/react 3.0.0-rc.6 → 3.0.0-rc.7

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 (74) hide show
  1. package/dist/annotorious-react.es.js +23 -44
  2. package/dist/annotorious-react.es.js.map +1 -1
  3. package/dist/annotorious-react.es10.js +29 -3
  4. package/dist/annotorious-react.es10.js.map +1 -1
  5. package/dist/annotorious-react.es11.js +36 -27
  6. package/dist/annotorious-react.es11.js.map +1 -1
  7. package/dist/annotorious-react.es12.js +16 -20
  8. package/dist/annotorious-react.es12.js.map +1 -1
  9. package/dist/annotorious-react.es13.js +4 -54
  10. package/dist/annotorious-react.es13.js.map +1 -1
  11. package/dist/annotorious-react.es14.js +8 -17
  12. package/dist/annotorious-react.es14.js.map +1 -1
  13. package/dist/annotorious-react.es15.js +152 -21
  14. package/dist/annotorious-react.es15.js.map +1 -1
  15. package/dist/annotorious-react.es16.js +6 -2
  16. package/dist/annotorious-react.es16.js.map +1 -1
  17. package/dist/annotorious-react.es17.js +2 -2
  18. package/dist/annotorious-react.es17.js.map +1 -1
  19. package/dist/annotorious-react.es18.js +29 -3925
  20. package/dist/annotorious-react.es18.js.map +1 -1
  21. package/dist/annotorious-react.es19.js +597 -27
  22. package/dist/annotorious-react.es19.js.map +1 -1
  23. package/dist/annotorious-react.es2.js +2 -2
  24. package/dist/annotorious-react.es20.js +20707 -33
  25. package/dist/annotorious-react.es20.js.map +1 -1
  26. package/dist/annotorious-react.es21.js +32 -16
  27. package/dist/annotorious-react.es21.js.map +1 -1
  28. package/dist/annotorious-react.es22.js +2 -4
  29. package/dist/annotorious-react.es22.js.map +1 -1
  30. package/dist/annotorious-react.es23.js +2 -8
  31. package/dist/annotorious-react.es23.js.map +1 -1
  32. package/dist/annotorious-react.es4.js +2 -2
  33. package/dist/annotorious-react.es5.js +2 -2
  34. package/dist/annotorious-react.es8.js +21 -58
  35. package/dist/annotorious-react.es8.js.map +1 -1
  36. package/dist/annotorious-react.es9.js +3924 -10
  37. package/dist/annotorious-react.es9.js.map +1 -1
  38. package/dist/index.d.ts +3 -6
  39. package/dist/index.d.ts.map +1 -1
  40. package/package.json +1 -2
  41. package/dist/annotorious-react.es24.js +0 -156
  42. package/dist/annotorious-react.es24.js.map +0 -1
  43. package/dist/annotorious-react.es25.js +0 -9
  44. package/dist/annotorious-react.es25.js.map +0 -1
  45. package/dist/annotorious-react.es26.js +0 -5
  46. package/dist/annotorious-react.es26.js.map +0 -1
  47. package/dist/annotorious-react.es27.js +0 -33
  48. package/dist/annotorious-react.es27.js.map +0 -1
  49. package/dist/annotorious-react.es28.js +0 -602
  50. package/dist/annotorious-react.es28.js.map +0 -1
  51. package/dist/annotorious-react.es29.js +0 -20133
  52. package/dist/annotorious-react.es29.js.map +0 -1
  53. package/dist/annotorious-react.es30.js +0 -35
  54. package/dist/annotorious-react.es30.js.map +0 -1
  55. package/dist/annotorious-react.es31.js +0 -5
  56. package/dist/annotorious-react.es31.js.map +0 -1
  57. package/dist/annotorious-react.es32.js +0 -5
  58. package/dist/annotorious-react.es32.js.map +0 -1
  59. package/dist/annotorious-react.es33.js +0 -19
  60. package/dist/annotorious-react.es33.js.map +0 -1
  61. package/dist/annotorious-react.es34.js +0 -20
  62. package/dist/annotorious-react.es34.js.map +0 -1
  63. package/dist/annotorious-react.es35.js +0 -30
  64. package/dist/annotorious-react.es35.js.map +0 -1
  65. package/dist/annotorious-react.es36.js +0 -24
  66. package/dist/annotorious-react.es36.js.map +0 -1
  67. package/dist/annotorious-react.es37.js +0 -19
  68. package/dist/annotorious-react.es37.js.map +0 -1
  69. package/dist/annotorious-react.es38.js +0 -7
  70. package/dist/annotorious-react.es38.js.map +0 -1
  71. package/dist/annotorious-react.es39.js +0 -11
  72. package/dist/annotorious-react.es39.js.map +0 -1
  73. package/dist/annotorious-react.es40.js +0 -10
  74. package/dist/annotorious-react.es40.js.map +0 -1
@@ -1,55 +1,34 @@
1
- import { Annotorious as n, AnnotoriousContext as a, useAnnotationStore as p, useAnnotations as i, useAnnotator as m, useAnnotatorUser as s, useSelection as f, useViewportState as x } from "./annotorious-react.es2.js";
2
- import { AnnotoriousPlugin as A } from "./annotorious-react.es3.js";
3
- import { Draggable as c } from "./annotorious-react.es4.js";
4
- import { ImageAnnotator as g } from "./annotorious-react.es5.js";
1
+ import { Annotorious as n, AnnotoriousContext as a, useAnnotationStore as p, useAnnotations as i, useAnnotator as m, useAnnotatorUser as s, useSelection as u, useViewportState as A } from "./annotorious-react.es2.js";
2
+ import { AnnotoriousPlugin as f } from "./annotorious-react.es3.js";
3
+ import { Draggable as S } from "./annotorious-react.es4.js";
4
+ import { ImageAnnotator as l } from "./annotorious-react.es5.js";
5
5
  import "./annotorious-react.es6.js";
6
6
  import "./annotorious-react.es7.js";
7
- import { createBaseAnnotator as C } from "./annotorious-react.es8.js";
8
- import { parseAll as B, serializeAll as E } from "./annotorious-react.es9.js";
9
- import { createAnonymousGuest as w } from "./annotorious-react.es10.js";
10
- import { parseW3CBodies as V, serializeW3CBodies as W } from "./annotorious-react.es11.js";
11
- import { createDefaultAppearenceProvider as v, defaultColorProvider as z } from "./annotorious-react.es12.js";
12
- import { PRESENCE_KEY as I, createPresenceState as h } from "./annotorious-react.es13.js";
13
- import { createBody as G, getContributors as K } from "./annotorious-react.es14.js";
14
- import { diffAnnotations as R } from "./annotorious-react.es15.js";
15
- import { PointerSelectAction as U } from "./annotorious-react.es16.js";
16
- import { Origin as _ } from "./annotorious-react.es17.js";
17
- import { ShapeType as k, W3CImageFormat as q } from "./annotorious-react.es18.js";
18
- import { OpenSeadragonAnnotator as J, useViewer as L } from "./annotorious-react.es19.js";
19
- import { OpenSeadragonPopup as Q } from "./annotorious-react.es20.js";
20
- import { OpenSeadragonViewer as Z } from "./annotorious-react.es21.js";
7
+ import { Origin as d, PointerSelectAction as w, createAnonymousGuest as P } from "./annotorious-react.es8.js";
8
+ import { ShapeType as y, W3CImageFormat as C } from "./annotorious-react.es9.js";
9
+ import { OpenSeadragonAnnotator as b, useViewer as h } from "./annotorious-react.es10.js";
10
+ import { OpenSeadragonPopup as F } from "./annotorious-react.es11.js";
11
+ import { OpenSeadragonViewer as T } from "./annotorious-react.es12.js";
21
12
  export {
22
13
  n as Annotorious,
23
14
  a as AnnotoriousContext,
24
- A as AnnotoriousPlugin,
25
- c as Draggable,
26
- g as ImageAnnotator,
27
- J as OpenSeadragonAnnotator,
28
- Q as OpenSeadragonPopup,
29
- Z as OpenSeadragonViewer,
30
- _ as Origin,
31
- I as PRESENCE_KEY,
32
- U as PointerSelectAction,
33
- k as ShapeType,
34
- q as W3CImageFormat,
35
- w as createAnonymousGuest,
36
- C as createBaseAnnotator,
37
- G as createBody,
38
- v as createDefaultAppearenceProvider,
39
- h as createPresenceState,
40
- z as defaultColorProvider,
41
- R as diffAnnotations,
42
- K as getContributors,
43
- B as parseAll,
44
- V as parseW3CBodies,
45
- E as serializeAll,
46
- W as serializeW3CBodies,
15
+ f as AnnotoriousPlugin,
16
+ S as Draggable,
17
+ l as ImageAnnotator,
18
+ b as OpenSeadragonAnnotator,
19
+ F as OpenSeadragonPopup,
20
+ T as OpenSeadragonViewer,
21
+ d as Origin,
22
+ w as PointerSelectAction,
23
+ y as ShapeType,
24
+ C as W3CImageFormat,
25
+ P as createAnonymousGuest,
47
26
  p as useAnnotationStore,
48
27
  i as useAnnotations,
49
28
  m as useAnnotator,
50
29
  s as useAnnotatorUser,
51
- f as useSelection,
52
- L as useViewer,
53
- x as useViewportState
30
+ u as useSelection,
31
+ h as useViewer,
32
+ A as useViewportState
54
33
  };
55
34
  //# sourceMappingURL=annotorious-react.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"annotorious-react.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -1,6 +1,32 @@
1
- import { customAlphabet as t } from "./annotorious-react.es33.js";
2
- const e = () => ({ isGuest: !0, id: t("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() });
1
+ import { jsx as d } from "./annotorious-react.es13.js";
2
+ import { createContext as u, useState as w, useContext as l, useEffect as n } from "react";
3
+ import { createOSDAnnotator as m } from "./annotorious-react.es20.js";
4
+ import { AnnotoriousContext as g } from "./annotorious-react.es2.js";
5
+ const s = u({ viewer: null, setViewer: null }), y = (e) => {
6
+ const { children: v, tool: i, ...c } = e, [o, f] = w(), { anno: t, setAnno: a } = l(g);
7
+ return n(() => {
8
+ if (o) {
9
+ const r = m(o, c);
10
+ return e.tool && r.setDrawingTool(e.tool), a(r), () => {
11
+ r.destroy(), a(void 0);
12
+ };
13
+ }
14
+ }, [o]), n(() => {
15
+ t && t.setDrawingTool(i);
16
+ }, [i]), n(() => {
17
+ t && t.setDrawingEnabled(e.drawingEnabled);
18
+ }, [e.drawingEnabled]), n(() => {
19
+ t && t.setFilter(e.filter);
20
+ }, [e.filter]), n(() => {
21
+ t && t.setStyle(e.style);
22
+ }, [e.style]), /* @__PURE__ */ d(s.Provider, { value: { viewer: o, setViewer: f }, children: e.children });
23
+ }, C = () => {
24
+ const { viewer: e } = l(s);
25
+ return e;
26
+ };
3
27
  export {
4
- e as createAnonymousGuest
28
+ y as OpenSeadragonAnnotator,
29
+ s as OpenSeadragonAnnotatorContext,
30
+ C as useViewer
5
31
  };
6
32
  //# sourceMappingURL=annotorious-react.es10.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es10.js","sources":["../../annotorious-core/src/model/User.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid';\n\nexport interface User {\n\n id: string;\n\n isGuest?: boolean;\n\n name?: string;\n\n avatar?: string;\n\n}\n\nexport const createAnonymousGuest = () => {\n const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_', 20);\n \n return { isGuest: true, id: nanoid() }\n}"],"names":["createAnonymousGuest","customAlphabet"],"mappings":";AAcO,MAAMA,IAAuB,OAG3B,EAAE,SAAS,IAAM,IAFTC,EAAe,mEAAmE,EAAE,EAE9D,EAAA;"}
1
+ {"version":3,"file":"annotorious-react.es10.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 { AnnotoriousContext } from '../Annotorious';\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 } = useContext(AnnotoriousContext);\n\n useEffect(() => {\n if (viewer) {\n const anno = createOSDAnnotator<E>(viewer, opts);\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","useContext","AnnotoriousContext","useEffect","createOSDAnnotator","jsx","useViewer"],"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,EAAWC,CAAkB;AAEvD,SAAAC,EAAU,MAAM;AACd,QAAIP,GAAQ;AACJG,YAAAA,IAAOK,EAAsBR,GAAQD,CAAI;AAE/C,aAAIH,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,GAEXO,EAAU,MAAM;AACV,IAAAJ,KAAMA,EAAK,eAAeL,CAAI;AAAA,EAAA,GACjC,CAACA,CAAI,CAAC,GAETS,EAAU,MAAM;AACV,IAAAJ,KAAWA,EAAA,kBAAkBP,EAAM,cAAc;AAAA,EAAA,GACpD,CAACA,EAAM,cAAc,CAAC,GAEzBW,EAAU,MAAM;AACV,IAAAJ,KAAWA,EAAA,UAAUP,EAAM,MAAM;AAAA,EAAA,GACpC,CAACA,EAAM,MAAM,CAAC,GAEjBW,EAAU,MAAM;AACV,IAAAJ,KAAWA,EAAA,SAASP,EAAM,KAAK;AAAA,EAAA,GAClC,CAACA,EAAM,KAAK,CAAC,GAGd,gBAAAa,EAAChB,EAA8B,UAA9B,EAAuC,OAAO,EAAE,QAAAO,GAAQ,WAAAC,EACtD,GAAA,UAAAL,EAAM,SACT,CAAA;AAGJ,GAEac,IAAY,MAAM;AAC7B,QAAM,EAAE,QAAAV,EAAA,IAAWK,EAAWZ,CAA6B;AACpD,SAAAO;AACT;"}
@@ -1,30 +1,39 @@
1
- const d = (r) => {
2
- const o = JSON.stringify(r);
3
- let t = 0;
4
- for (let e = 0, a = o.length; e < a; e++) {
5
- let n = o.charCodeAt(e);
6
- t = (t << 5) - t + n, t |= 0;
7
- }
8
- return `${t}`;
9
- }, l = (r, o) => (Array.isArray(r) ? r : [r]).map((t) => {
10
- const { id: e, type: a, purpose: n, value: i, created: c, creator: s, ...p } = t;
11
- return {
12
- id: e || `temp-${d(t)}`,
13
- annotation: o,
14
- type: a,
15
- purpose: n,
16
- value: i,
17
- created: c,
18
- creator: s ? typeof s == "object" ? { ...s } : s : void 0,
19
- ...p
20
- };
21
- }), h = (r) => r.map((o) => {
22
- var e;
23
- const t = { ...o };
24
- return delete t.annotation, (e = t.id) != null && e.startsWith("temp-") && delete t.id, t;
25
- });
1
+ import { jsx as v } from "./annotorious-react.es13.js";
2
+ import { useRef as w, useState as d, useEffect as c } from "react";
3
+ import { Draggable as S } from "./annotorious-react.es4.js";
4
+ import { useViewer as x } from "./annotorious-react.es10.js";
5
+ import { useSelection as D } from "./annotorious-react.es2.js";
6
+ import { setPosition as I } from "./annotorious-react.es21.js";
7
+ const q = (u) => {
8
+ const n = w(null), o = x(), { selected: t } = D(), [l, f] = d([]), [s, i] = d(!1), m = () => i(!0), p = () => {
9
+ const e = t[0].annotation;
10
+ I(o, e, n.current);
11
+ }, g = (e, r) => e.every((a) => r.includes(a)) && r.every((a) => e.includes(a));
12
+ return c(() => {
13
+ const e = t.map(({ annotation: r }) => r.id);
14
+ g(l, e) || (i(!1), f(e));
15
+ }, [t]), c(() => {
16
+ if (!n.current)
17
+ return;
18
+ s || p();
19
+ const e = () => {
20
+ s || p();
21
+ };
22
+ return o.addHandler("update-viewport", e), () => {
23
+ o.removeHandler("update-viewport", e);
24
+ };
25
+ }, [t, s]), t.length > 0 ? /* @__PURE__ */ v(
26
+ S,
27
+ {
28
+ ref: n,
29
+ className: "a9s-popup a9s-osd-popup",
30
+ onDragStart: m,
31
+ children: u.popup({ viewer: o, selected: t })
32
+ },
33
+ t.map(({ annotation: e }) => e.id).join("-")
34
+ ) : null;
35
+ };
26
36
  export {
27
- l as parseW3CBodies,
28
- h as serializeW3CBodies
37
+ q as OpenSeadragonPopup
29
38
  };
30
39
  //# sourceMappingURL=annotorious-react.es11.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es11.js","sources":["../../annotorious-core/src/model/W3CAnnotation.ts"],"sourcesContent":["import type { AnnotationBody } from './Annotation';\n\nexport interface W3CAnnotation {\n\n '@context': 'http://www.w3.org/ns/anno.jsonld';\n\n type: 'Annotation';\n\n id: string;\n\n body: W3CAnnotationBody | W3CAnnotationBody[]\n\n target: W3CAnnotationTarget | W3CAnnotationTarget[];\n\n [key: string]: any;\n\n}\n\nexport interface W3CAnnotationBody {\n\n id?: string;\n\n type?: string;\n\n purpose?: string;\n\n value?: string;\n\n source?: string;\n\n created?: Date;\n\n creator?: {\n\n type?: string;\n\n id: string;\n\n name?: string;\n\n };\n\n}\n\nexport interface W3CAnnotationTarget {\n\n source: string;\n\n selector?: W3CSelector | W3CSelector[];\n\n}\n\nexport interface W3CSelector {\n\n type: string;\n\n conformsTo?: string;\n\n value: string;\n}\n\n// https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript\nconst hashCode = (obj: Object): string => {\n const str = JSON.stringify(obj);\n\n let hash = 0;\n\n for (let i = 0, len = str.length; i < len; i++) {\n let chr = str.charCodeAt(i);\n hash = (hash << 5) - hash + chr;\n hash |= 0; // Convert to 32bit integer\n }\n\n return `${hash}`;\n}\n\n/**\n * Helper to crosswalk the W3C annotation body to a list of core AnnotationBody objects.\n */\nexport const parseW3CBodies = (\n body: W3CAnnotationBody | W3CAnnotationBody[], \n annotationId: string\n): AnnotationBody[] => (Array.isArray(body) ? body : [body]).map(body => {\n\n // Exctract properties that conform to the internal model, but keep custom props\n const { id, type, purpose, value, created, creator, ...rest } = body;\n\n // The internal model strictly requires IDs. (Because multi-user scenarios\n // will have problems without them.) In the W3C model, bodys *may* have IDs.\n // We'll create ad-hoc IDs for bodies without IDs, but want to make sure that\n // generating the ID is idempotent: the same body should always get the same ID.\n // This will avoid unexpected results when checking for equality. \n return {\n id: id || `temp-${hashCode(body)}`,\n annotation: annotationId,\n type,\n purpose,\n value,\n created,\n creator: creator ? \n typeof creator === 'object' ? { ...creator }: creator :\n undefined,\n ...rest\n }\n\n});\n\n/** Serialization helper to remove core-specific fields from the annotation body **/\nexport const serializeW3CBodies = (bodies: AnnotationBody[]): W3CAnnotationBody[] => \n bodies.map(b => {\n const w3c = { ...b };\n delete w3c.annotation;\n\n if (w3c.id?.startsWith('temp-'))\n delete w3c.id;\n \n return w3c;\n });"],"names":["hashCode","obj","str","hash","i","len","chr","parseW3CBodies","body","annotationId","id","type","purpose","value","created","creator","rest","serializeW3CBodies","bodies","b","_a","w3c"],"mappings":"AA8DA,MAAMA,IAAW,CAACC,MAAwB;AAClC,QAAAC,IAAM,KAAK,UAAUD,CAAG;AAE9B,MAAIE,IAAO;AAEX,WAASC,IAAI,GAAGC,IAAMH,EAAI,QAAQE,IAAIC,GAAKD,KAAK;AACxC,QAAAE,IAAMJ,EAAI,WAAWE,CAAC;AAClB,IAAAD,KAAAA,KAAQ,KAAKA,IAAOG,GACpBH,KAAA;AAAA,EACZ;AAEA,SAAO,GAAGA,CAAI;AAChB,GAKaI,IAAiB,CAC5BC,GACAC,OACsB,MAAM,QAAQD,CAAI,IAAIA,IAAO,CAACA,CAAI,GAAG,IAAI,CAAAA,MAAQ;AAGjE,QAAA,EAAE,IAAAE,GAAI,MAAAC,GAAM,SAAAC,GAAS,OAAAC,GAAO,SAAAC,GAAS,SAAAC,GAAS,GAAGC,EAASR,IAAAA;AAOzD,SAAA;AAAA,IACL,IAAIE,KAAM,QAAQV,EAASQ,CAAI,CAAC;AAAA,IAChC,YAAYC;AAAA,IACZ,MAAAE;AAAA,IACA,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,SAASC,IACP,OAAOA,KAAY,WAAW,EAAE,GAAGA,EAAQ,IAAGA,IAC9C;AAAA,IACF,GAAGC;AAAA,EAAA;AAGP,CAAC,GAGYC,IAAqB,CAACC,MACjCA,EAAO,IAAI,CAAKC,MAAA;AA/ClB,MAAAC;AAgDU,QAAAC,IAAM,EAAE,GAAGF;AACjB,gBAAOE,EAAI,aAEPD,IAAAC,EAAI,OAAJ,QAAAD,EAAQ,WAAW,YACrB,OAAOC,EAAI,IAENA;AACT,CAAC;"}
1
+ {"version":3,"file":"annotorious-react.es11.js","sources":["../src/openseadragon/OpenSeadragonPopup.tsx"],"sourcesContent":["import { ReactNode, useEffect, useRef, useState } from 'react';\nimport { ImageAnnotation } from '@annotorious/annotorious';\nimport OpenSeadragon from 'openseadragon';\nimport { AnnotoriousPopupProps, Draggable } from '../AnnotoriousPopup';\nimport { useViewer } from './OpenSeadragonAnnotator';\nimport { useSelection } from '../Annotorious';\nimport { setPosition } from './setPosition';\n\nexport type OpenSeadragonPopupProps = AnnotoriousPopupProps & {\n\n viewer: OpenSeadragon.Viewer\n\n}\n\nexport type OpenSeadragonPopupContainerProps = {\n\n popup(props: OpenSeadragonPopupProps): ReactNode\n\n}\n\nexport const OpenSeadragonPopup = (props: OpenSeadragonPopupContainerProps) => {\n\n const el = useRef<HTMLDivElement>(null);\n\n const viewer = useViewer();\n\n const { selected } = useSelection<ImageAnnotation>();\n\n const [selectedIds, setSelectedIds] = useState<string[]>([]);\n\n const [dragged, setDragged] = useState(false);\n\n const onDragStart = () => setDragged(true);\n\n const updatePosition = () => {\n // Note: this popup only supports a single selection\n const annotation = selected[0].annotation;\n setPosition(viewer, annotation, el.current);\n }\n\n const equal = (a: string[], b: string[]) => \n a.every(str => b.includes(str)) && b.every(str => a.includes(str));\n\n useEffect(() => {\n // Reset drag flag if selected IDs have changed\n const nextIds = selected.map(({ annotation }) => annotation.id);\n\n if (!equal(selectedIds, nextIds)) {\n setDragged(false);\n setSelectedIds(nextIds);\n }\n }, [selected]);\n\n useEffect(() => {\n if (!el.current) return;\n\n if (!dragged) updatePosition();\n\n const onUpdateViewport = () => {\n if (!dragged) updatePosition();\n }\n\n viewer.addHandler('update-viewport', onUpdateViewport);\n\n return () => {\n viewer.removeHandler('update-viewport', onUpdateViewport);\n }\n }, [selected, dragged]);\n \n return selected.length > 0 ? (\n <Draggable \n ref={el} \n key={selected.map(({ annotation }) => annotation.id).join('-')} \n className=\"a9s-popup a9s-osd-popup\" \n onDragStart={onDragStart}>\n\n {props.popup({ viewer, selected })}\n \n </Draggable>\n ) : null;\n\n}"],"names":["OpenSeadragonPopup","props","el","useRef","viewer","useViewer","selected","useSelection","selectedIds","setSelectedIds","useState","dragged","setDragged","onDragStart","updatePosition","annotation","setPosition","equal","a","b","str","useEffect","nextIds","onUpdateViewport","jsx","Draggable"],"mappings":";;;;;;AAoBa,MAAAA,IAAqB,CAACC,MAA4C;AAEvE,QAAAC,IAAKC,EAAuB,IAAI,GAEhCC,IAASC,KAET,EAAE,UAAAC,MAAaC,KAEf,CAACC,GAAaC,CAAc,IAAIC,EAAmB,CAAE,CAAA,GAErD,CAACC,GAASC,CAAU,IAAIF,EAAS,EAAK,GAEtCG,IAAc,MAAMD,EAAW,EAAI,GAEnCE,IAAiB,MAAM;AAErB,UAAAC,IAAaT,EAAS,CAAC,EAAE;AACnB,IAAAU,EAAAZ,GAAQW,GAAYb,EAAG,OAAO;AAAA,EAAA,GAGtCe,IAAQ,CAACC,GAAaC,MAC1BD,EAAE,MAAM,OAAOC,EAAE,SAASC,CAAG,CAAC,KAAKD,EAAE,MAAM,OAAOD,EAAE,SAASE,CAAG,CAAC;AAEnE,SAAAC,EAAU,MAAM;AAER,UAAAC,IAAUhB,EAAS,IAAI,CAAC,EAAE,YAAAS,QAAiBA,EAAW,EAAE;AAE9D,IAAKE,EAAMT,GAAac,CAAO,MAC7BV,EAAW,EAAK,GAChBH,EAAea,CAAO;AAAA,EACxB,GACC,CAAChB,CAAQ,CAAC,GAEbe,EAAU,MAAM;AACd,QAAI,CAACnB,EAAG;AAAS;AAEjB,IAAKS,KAAwBG;AAE7B,UAAMS,IAAmB,MAAM;AAC7B,MAAKZ,KAAwBG;IAAA;AAGxB,WAAAV,EAAA,WAAW,mBAAmBmB,CAAgB,GAE9C,MAAM;AACJ,MAAAnB,EAAA,cAAc,mBAAmBmB,CAAgB;AAAA,IAAA;AAAA,EAC1D,GACC,CAACjB,GAAUK,CAAO,CAAC,GAEfL,EAAS,SAAS,IACvB,gBAAAkB;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,KAAKvB;AAAA,MAEL,WAAU;AAAA,MACV,aAAAW;AAAA,MAEC,UAAMZ,EAAA,MAAM,EAAE,QAAAG,GAAQ,UAAAE,GAAU;AAAA,IAAA;AAAA,IAJ5BA,EAAS,IAAI,CAAC,EAAE,YAAAS,EAAA,MAAiBA,EAAW,EAAE,EAAE,KAAK,GAAG;AAAA,EAO7D,IAAA;AAEN;"}
@@ -1,23 +1,19 @@
1
- import { DEFAULT_PALETTE as t } from "./annotorious-react.es36.js";
2
- const l = () => {
3
- const o = [...t];
4
- return { assignRandomColor: () => {
5
- const r = Math.floor(Math.random() * o.length), e = o[r];
6
- return o.splice(r, 1), e;
7
- }, releaseColor: (r) => o.push(r) };
8
- }, d = () => {
9
- const o = l();
10
- return { addUser: (r, e) => {
11
- const s = o.assignRandomColor();
12
- return {
13
- label: e.name || e.id,
14
- avatar: e.avatar,
15
- color: s
16
- };
17
- }, removeUser: (r) => o.releaseColor(r.appearance.color) };
18
- };
1
+ import { jsx as m } from "./annotorious-react.es13.js";
2
+ import { forwardRef as a, useRef as c, useContext as p, useEffect as u, useImperativeHandle as d } from "react";
3
+ import l from "openseadragon";
4
+ import { OpenSeadragonAnnotatorContext as v } from "./annotorious-react.es10.js";
5
+ const S = a((n, i) => {
6
+ const { className: s, options: t } = n, r = c(null), { viewer: f, setViewer: e } = p(v);
7
+ return u(() => {
8
+ if (r.current) {
9
+ const o = l({ ...t, element: r.current });
10
+ return e && e(o), () => {
11
+ o.destroy(), e && e(void 0);
12
+ };
13
+ }
14
+ }, [JSON.stringify(t)]), d(i, () => f), /* @__PURE__ */ m("div", { className: s, ref: r });
15
+ });
19
16
  export {
20
- d as createDefaultAppearenceProvider,
21
- l as defaultColorProvider
17
+ S as OpenSeadragonViewer
22
18
  };
23
19
  //# sourceMappingURL=annotorious-react.es12.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es12.js","sources":["../../annotorious-core/src/presence/AppearanceProvider.ts"],"sourcesContent":["import type { User } from '../model';\nimport type { Appearance } from './Appearance';\nimport type { PresentUser } from './PresentUser';\nimport { DEFAULT_PALETTE } from './ColorPalette';\n\nexport interface AppearanceProvider {\n\n addUser(presenceKey: string, user: User): Appearance;\n\n removeUser(user: PresentUser): void;\n\n}\n\nexport const defaultColorProvider = () => {\n\n const unassignedColors = [...DEFAULT_PALETTE];\n\n const assignRandomColor = () => {\n const rnd = Math.floor(Math.random() * unassignedColors.length);\n const color = unassignedColors[rnd];\n\n unassignedColors.splice(rnd, 1);\n\n return color;\n }\n\n const releaseColor = (color: string) =>\n unassignedColors.push(color);\n\n return { assignRandomColor, releaseColor };\n\n}\n\nexport const createDefaultAppearenceProvider = () => {\n\n const colorProvider = defaultColorProvider();\n\n const addUser = (presenceKey: string, user: User): Appearance => {\n const color = colorProvider.assignRandomColor();\n\n return {\n label: user.name || user.id,\n avatar: user.avatar,\n color\n };\n }\n\n const removeUser = (user: PresentUser) =>\n colorProvider.releaseColor(user.appearance.color);\n\n return { addUser, removeUser }\n \n}"],"names":["defaultColorProvider","unassignedColors","DEFAULT_PALETTE","rnd","color","createDefaultAppearenceProvider","colorProvider","presenceKey","user"],"mappings":";AAaO,MAAMA,IAAuB,MAAM;AAElC,QAAAC,IAAmB,CAAC,GAAGC,CAAe;AAcrC,SAAA,EAAE,mBAZiB,MAAM;AAC9B,UAAMC,IAAM,KAAK,MAAM,KAAK,WAAWF,EAAiB,MAAM,GACxDG,IAAQH,EAAiBE,CAAG;AAEjB,WAAAF,EAAA,OAAOE,GAAK,CAAC,GAEvBC;AAAA,EAAA,GAMmB,cAHP,CAACA,MACpBH,EAAiB,KAAKG,CAAK;AAI/B,GAEaC,IAAkC,MAAM;AAEnD,QAAMC,IAAgBN;AAef,SAAA,EAAE,SAbO,CAACO,GAAqBC,MAA2B;AACzD,UAAAJ,IAAQE,EAAc;AAErB,WAAA;AAAA,MACL,OAAOE,EAAK,QAAQA,EAAK;AAAA,MACzB,QAAQA,EAAK;AAAA,MACb,OAAAJ;AAAA,IAAA;AAAA,EACF,GAMgB,YAHC,CAACI,MAClBF,EAAc,aAAaE,EAAK,WAAW,KAAK;AAIpD;"}
1
+ {"version":3,"file":"annotorious-react.es12.js","sources":["../src/openseadragon/OpenSeadragonViewer.tsx"],"sourcesContent":["import { forwardRef, useContext, useEffect, useImperativeHandle, useRef } from 'react';\nimport OpenSeadragon from 'openseadragon';\nimport { OpenSeadragonAnnotatorContext } from './OpenSeadragonAnnotator';\n\nexport interface OpenSeadragonViewerProps {\n\n className?: string;\n\n options: OpenSeadragon.Options;\n\n}\n\nexport const OpenSeadragonViewer = forwardRef<OpenSeadragon.Viewer, OpenSeadragonViewerProps>((props: OpenSeadragonViewerProps, ref) => {\n\n const { className, options } = props;\n\n const element = useRef<HTMLDivElement>(null);\n\n const { viewer, setViewer } = useContext(OpenSeadragonAnnotatorContext);\n\n useEffect(() => { \n if (element.current) {\n const v = OpenSeadragon({...options, element: element.current });\n\n // Checking for setViewer is just a convenience so we can\n // use this component also without an OpenSeadragonAnnotator\n if (setViewer)\n setViewer(v);\n\n return () => {\n v.destroy();\n\n if (setViewer) \n setViewer(undefined);\n }\n }\n }, [JSON.stringify(options)]);\n\n useImperativeHandle(ref, () => viewer);\n\n return (\n <div className={className} ref={element} />\n );\n\n});"],"names":["OpenSeadragonViewer","forwardRef","props","ref","className","options","element","useRef","viewer","setViewer","useContext","OpenSeadragonAnnotatorContext","useEffect","v","OpenSeadragon","useImperativeHandle","jsx"],"mappings":";;;;AAYO,MAAMA,IAAsBC,EAA2D,CAACC,GAAiCC,MAAQ;AAEhI,QAAA,EAAE,WAAAC,GAAW,SAAAC,EAAY,IAAAH,GAEzBI,IAAUC,EAAuB,IAAI,GAErC,EAAE,QAAAC,GAAQ,WAAAC,EAAU,IAAIC,EAAWC,CAA6B;AAEtE,SAAAC,EAAU,MAAM;AACd,QAAIN,EAAQ,SAAS;AACb,YAAAO,IAAIC,EAAc,EAAC,GAAGT,GAAS,SAASC,EAAQ,SAAS;AAI3D,aAAAG,KACFA,EAAUI,CAAC,GAEN,MAAM;AACX,QAAAA,EAAE,QAAQ,GAENJ,KACFA,EAAU,MAAS;AAAA,MAAA;AAAA,IAEzB;AAAA,KACC,CAAC,KAAK,UAAUJ,CAAO,CAAC,CAAC,GAERU,EAAAZ,GAAK,MAAMK,CAAM,GAGlC,gBAAAQ,EAAA,OAAA,EAAI,WAAAZ,GAAsB,KAAKE,EAAS,CAAA;AAG7C,CAAC;"}
@@ -1,57 +1,7 @@
1
- import { nanoid as v } from "./annotorious-react.es33.js";
2
- import { createNanoEvents as p } from "./annotorious-react.es37.js";
3
- import { createDefaultAppearenceProvider as E } from "./annotorious-react.es12.js";
4
- const w = (c, r) => c.every((o) => c.includes(o)) && r.every((o) => c.includes(o)), P = v(), y = (c = E()) => {
5
- const r = p(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), m = (t, e) => {
6
- if (o.has(t)) {
7
- console.warn("Attempt to add user that is already present", t, e);
8
- return;
9
- }
10
- const n = c.addUser(t, e);
11
- o.set(t, {
12
- ...e,
13
- presenceKey: t,
14
- appearance: n
15
- });
16
- }, u = (t) => {
17
- const e = o.get(t);
18
- if (!e) {
19
- console.warn("Attempt to remove user that is not present", t);
20
- return;
21
- }
22
- c.removeUser(e), o.delete(t);
23
- }, h = (t) => {
24
- const e = new Set(t.map((s) => s.presenceKey)), n = t.filter(({ presenceKey: s }) => !o.has(s)), i = Array.from(o.values()).filter((s) => !e.has(s.presenceKey));
25
- n.forEach(({ presenceKey: s, user: f }) => m(s, f)), i.forEach((s) => {
26
- const { presenceKey: f } = s;
27
- a.has(f) && r.emit("selectionChange", s, null), u(f);
28
- }), (n.length > 0 || i.length > 0) && r.emit("presence", l());
29
- }, d = (t, e) => {
30
- const n = o.get(t);
31
- if (!n) {
32
- console.warn("Activity notification from user that is not present");
33
- return;
34
- }
35
- const i = a.get(t);
36
- (!i || !w(i, e)) && (a.set(t, e), r.emit("selectionChange", n, e));
37
- }, g = (t, e) => {
38
- const n = o.get(t);
39
- if (!n) {
40
- console.warn("Selection change for user that is not present", t);
41
- return;
42
- }
43
- e ? a.set(t, e) : a.delete(t), r.emit("selectionChange", n, e);
44
- }, l = () => [...Array.from(o.values())];
45
- return {
46
- getPresentUsers: l,
47
- notifyActivity: d,
48
- on: (t, e) => r.on(t, e),
49
- syncUsers: h,
50
- updateSelection: g
51
- };
52
- };
1
+ import { j as t } from "./annotorious-react.es16.js";
2
+ const o = t.Fragment, r = t.jsx;
53
3
  export {
54
- P as PRESENCE_KEY,
55
- y as createPresenceState
4
+ o as Fragment,
5
+ r as jsx
56
6
  };
57
7
  //# sourceMappingURL=annotorious-react.es13.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es13.js","sources":["../../annotorious-core/src/presence/PresenceState.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport { createNanoEvents, type Unsubscribe } from 'nanoevents';\nimport type { User } from '../model';\nimport type { PresentUser } from './PresentUser';\nimport type { PresenceEvents } from './PresenceEvents';\nimport { createDefaultAppearenceProvider } from './AppearanceProvider';\nimport type { AppearanceProvider } from './AppearanceProvider';\n\nexport interface PresenceState {\n\n // Get users currently present to this room\n getPresentUsers(): PresentUser[];\n\n // Notify of a given present user's activity on the given annotations\n notifyActivity(presenceKey: string, annotationIds: string[]): void;\n\n // Add a listener for the given presence event\n on<E extends keyof PresenceEvents>(event: E, callback: PresenceEvents[E]): Unsubscribe;\n\n // Initial sync - which users are present under which keys\n syncUsers(state: { presenceKey: string, user: User }[]): void;\n\n // Update the selection state for the given prresent user\n updateSelection(presenceKey: string, selection: string[] | null): void;\n\n}\n\nconst isListEqual = (listA: any[], listB: any[]) => \n listA.every(a => listA.includes(a)) && listB.every(b => listA.includes(b));\n\n// This client's presence key\nexport const PRESENCE_KEY = nanoid();\n\nexport const createPresenceState = (\n appearanceProvider: AppearanceProvider = createDefaultAppearenceProvider()\n): PresenceState => {\n\n const emitter = createNanoEvents<PresenceEvents>();\n\n const presentUsers = new Map<string, PresentUser>();\n\n const selectionStates = new Map<string, string[]>();\n\n const addUser = (presenceKey: string, user: User) => {\n if (presentUsers.has(presenceKey)) {\n console.warn('Attempt to add user that is already present', presenceKey, user);\n return; \n }\n\n const appearance = appearanceProvider.addUser(presenceKey, user);\n\n presentUsers.set(presenceKey, { \n ...user,\n presenceKey,\n appearance\n });\n }\n\n const removeUser = (presenceKey: string) => {\n const user = presentUsers.get(presenceKey);\n if (!user) {\n console.warn('Attempt to remove user that is not present', presenceKey);\n return;\n }\n\n appearanceProvider.removeUser(user);\n\n presentUsers.delete(presenceKey);\n }\n\n const syncUsers = (state: { presenceKey: string, user: User }[]) => {\n // const keys = new Set(others.map(s => s.presenceKey));\n const keys = new Set(state.map(s => s.presenceKey));\n\n // These users need to be added to the presentUsers list\n // const toAdd = others.filter(({ presenceKey }) => !presentUsers.has(presenceKey));\n const toAdd = state.filter(({ presenceKey }) => !presentUsers.has(presenceKey));\n\n // These users need to be dropped from the list\n const toRemove = Array.from(presentUsers.values()).filter(presentUser =>\n !keys.has(presentUser.presenceKey));\n\n toAdd.forEach(({ presenceKey, user }) => addUser(presenceKey, user));\n\n toRemove.forEach(user => {\n const { presenceKey } = user;\n\n // If this user has a selection, fire deselect event\n if (selectionStates.has(presenceKey))\n emitter.emit('selectionChange', user, null);\n\n removeUser(presenceKey)\n });\n\n if (toAdd.length > 0 || toRemove.length > 0)\n emitter.emit('presence', getPresentUsers());\n }\n\n const notifyActivity = (presenceKey: string, annotationIds: string[]) => { \n const user = presentUsers.get(presenceKey);\n \n if (!user) {\n console.warn('Activity notification from user that is not present');\n return;\n }\n\n const currentSelection = selectionStates.get(presenceKey);\n\n // Was there a selection change we might have missed?\n if (!currentSelection || !isListEqual(currentSelection, annotationIds)) {\n selectionStates.set(presenceKey, annotationIds);\n emitter.emit('selectionChange', user, annotationIds);\n }\n }\n\n const updateSelection = (presenceKey: string, selection: string[] | null) => {\n const from = presentUsers.get(presenceKey);\n if (!from) {\n console.warn('Selection change for user that is not present', presenceKey);\n return;\n }\n\n if (selection)\n selectionStates.set(presenceKey, selection);\n else \n selectionStates.delete(presenceKey);\n\n emitter.emit('selectionChange', from, selection);\n }\n\n const getPresentUsers = () =>\n [...Array.from(presentUsers.values())];\n \n const on = <E extends keyof PresenceEvents>(event: E, callback: PresenceEvents[E]) =>\n emitter.on(event, callback);\n\n return {\n getPresentUsers,\n notifyActivity,\n on,\n syncUsers,\n updateSelection\n }\n\n}"],"names":["isListEqual","listA","listB","a","b","PRESENCE_KEY","nanoid","createPresenceState","appearanceProvider","createDefaultAppearenceProvider","emitter","createNanoEvents","presentUsers","selectionStates","addUser","presenceKey","user","appearance","removeUser","syncUsers","state","keys","toAdd","toRemove","presentUser","getPresentUsers","notifyActivity","annotationIds","currentSelection","updateSelection","selection","from","event","callback"],"mappings":";;;AA2BA,MAAMA,IAAc,CAACC,GAAcC,MACjCD,EAAM,MAAM,OAAKA,EAAM,SAASE,CAAC,CAAC,KAAKD,EAAM,MAAM,OAAKD,EAAM,SAASG,CAAC,CAAC,GAG9DC,IAAeC,EAAO,GAEtBC,IAAsB,CACjCC,IAAyCC,QACvB;AAElB,QAAMC,IAAUC,KAEVC,wBAAmB,OAEnBC,wBAAsB,OAEtBC,IAAU,CAACC,GAAqBC,MAAe;AAC/C,QAAAJ,EAAa,IAAIG,CAAW,GAAG;AACzB,cAAA,KAAK,+CAA+CA,GAAaC,CAAI;AAC7E;AAAA,IACF;AAEA,UAAMC,IAAaT,EAAmB,QAAQO,GAAaC,CAAI;AAE/D,IAAAJ,EAAa,IAAIG,GAAa;AAAA,MAC5B,GAAGC;AAAA,MACH,aAAAD;AAAA,MACA,YAAAE;AAAA,IAAA,CACD;AAAA,EAAA,GAGGC,IAAa,CAACH,MAAwB;AACpC,UAAAC,IAAOJ,EAAa,IAAIG,CAAW;AACzC,QAAI,CAACC,GAAM;AACD,cAAA,KAAK,8CAA8CD,CAAW;AACtE;AAAA,IACF;AAEA,IAAAP,EAAmB,WAAWQ,CAAI,GAElCJ,EAAa,OAAOG,CAAW;AAAA,EAAA,GAG3BI,IAAY,CAACC,MAAiD;AAE5D,UAAAC,IAAO,IAAI,IAAID,EAAM,IAAI,CAAK,MAAA,EAAE,WAAW,CAAC,GAI5CE,IAAQF,EAAM,OAAO,CAAC,EAAE,aAAAL,QAAkB,CAACH,EAAa,IAAIG,CAAW,CAAC,GAGxEQ,IAAW,MAAM,KAAKX,EAAa,OAAQ,CAAA,EAAE,OAAO,CAAAY,MACxD,CAACH,EAAK,IAAIG,EAAY,WAAW,CAAC;AAE9B,IAAAF,EAAA,QAAQ,CAAC,EAAE,aAAAP,GAAa,MAAAC,EAAW,MAAAF,EAAQC,GAAaC,CAAI,CAAC,GAEnEO,EAAS,QAAQ,CAAQP,MAAA;AACjB,YAAA,EAAE,aAAAD,EAAgB,IAAAC;AAGpB,MAAAH,EAAgB,IAAIE,CAAW,KACzBL,EAAA,KAAK,mBAAmBM,GAAM,IAAI,GAE5CE,EAAWH,CAAW;AAAA,IAAA,CACvB,IAEGO,EAAM,SAAS,KAAKC,EAAS,SAAS,MAChCb,EAAA,KAAK,YAAYe,EAAiB,CAAA;AAAA,EAAA,GAGxCC,IAAiB,CAACX,GAAqBY,MAA4B;AACjE,UAAAX,IAAOJ,EAAa,IAAIG,CAAW;AAEzC,QAAI,CAACC,GAAM;AACT,cAAQ,KAAK,qDAAqD;AAClE;AAAA,IACF;AAEM,UAAAY,IAAmBf,EAAgB,IAAIE,CAAW;AAGxD,KAAI,CAACa,KAAoB,CAAC5B,EAAY4B,GAAkBD,CAAa,OACnDd,EAAA,IAAIE,GAAaY,CAAa,GACtCjB,EAAA,KAAK,mBAAmBM,GAAMW,CAAa;AAAA,EACrD,GAGIE,IAAkB,CAACd,GAAqBe,MAA+B;AACrE,UAAAC,IAAOnB,EAAa,IAAIG,CAAW;AACzC,QAAI,CAACgB,GAAM;AACD,cAAA,KAAK,iDAAiDhB,CAAW;AACzE;AAAA,IACF;AAEI,IAAAe,IACcjB,EAAA,IAAIE,GAAae,CAAS,IAE1CjB,EAAgB,OAAOE,CAAW,GAE5BL,EAAA,KAAK,mBAAmBqB,GAAMD,CAAS;AAAA,EAAA,GAG3CL,IAAkB,MACtB,CAAC,GAAG,MAAM,KAAKb,EAAa,OAAQ,CAAA,CAAC;AAKhC,SAAA;AAAA,IACL,iBAAAa;AAAA,IACA,gBAAAC;AAAA,IACA,IANS,CAAiCM,GAAUC,MACpDvB,EAAQ,GAAGsB,GAAOC,CAAQ;AAAA,IAM1B,WAAAd;AAAA,IACA,iBAAAU;AAAA,EAAA;AAGJ;"}
1
+ {"version":3,"file":"annotorious-react.es13.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,20 +1,11 @@
1
- import c from "./annotorious-react.es34.js";
2
- const s = (t) => {
3
- const { creator: e, updatedBy: r } = t.target, o = t.bodies.reduce((a, d) => [...a, d.creator, d.updatedBy], []);
4
- return [
5
- e,
6
- r,
7
- ...o
8
- ].filter((a) => a);
9
- }, i = (t, e, r, o) => ({
10
- id: c(),
11
- annotation: t.id,
12
- created: r || /* @__PURE__ */ new Date(),
13
- creator: o,
14
- ...e
15
- });
1
+ import { useState as c, useRef as n, useEffect as s } from "react";
2
+ const m = (e, t) => {
3
+ const [u, o] = c(e), r = n();
4
+ return s(() => (r.current = setTimeout(() => o(e), t), () => {
5
+ clearTimeout(r.current);
6
+ }), [e, t]), u;
7
+ };
16
8
  export {
17
- i as createBody,
18
- s as getContributors
9
+ m as useDebounce
19
10
  };
20
11
  //# sourceMappingURL=annotorious-react.es14.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es14.js","sources":["../../annotorious-core/src/utils/annotationUtils.ts"],"sourcesContent":["import { v4 as uuidv4 } from 'uuid';\nimport type { Annotation, AnnotationBody, User } from '../model';\n\n/**\n * Returns all users listed as creators or updaters in any parts of this\n * annotation.\n */\nexport const getContributors = (annotation: Annotation): User[] => {\n const { creator, updatedBy } = annotation.target;\n\n const bodyCollaborators = annotation.bodies.reduce((users, body) => (\n [...users, body.creator, body.updatedBy]\n ), [] as User[]);\n\n return [\n creator,\n updatedBy,\n ...bodyCollaborators\n ].filter(u => u); // Remove undefined\n}\n\nexport const createBody = (\n annotation: Annotation, \n payload: { [key: string]: any },\n created?: Date,\n creator?: User\n): AnnotationBody => ({\n id: uuidv4(),\n annotation: annotation.id,\n created: created || new Date(),\n creator,\n ...payload\n});"],"names":["getContributors","annotation","creator","updatedBy","bodyCollaborators","users","body","u","createBody","payload","created","uuidv4"],"mappings":";AAOa,MAAAA,IAAkB,CAACC,MAAmC;AACjE,QAAM,EAAE,SAAAC,GAAS,WAAAC,MAAcF,EAAW,QAEpCG,IAAoBH,EAAW,OAAO,OAAO,CAACI,GAAOC,MACzD,CAAC,GAAGD,GAAOC,EAAK,SAASA,EAAK,SAAS,GACtC,CAAA,CAAY;AAER,SAAA;AAAA,IACLJ;AAAA,IACAC;AAAA,IACA,GAAGC;AAAA,EACL,EAAE,OAAO,CAAAG,MAAKA,CAAC;AACjB,GAEaC,IAAa,CACxBP,GACAQ,GACAC,GACAR,OACoB;AAAA,EACpB,IAAIS,EAAO;AAAA,EACX,YAAYV,EAAW;AAAA,EACvB,SAASS,KAAW,oBAAI,KAAK;AAAA,EAC7B,SAAAR;AAAA,EACA,GAAGO;AACL;"}
1
+ {"version":3,"file":"annotorious-react.es14.js","sources":["../src/useDebounce.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nexport const useDebounce = (value: any, delay: number) => {\n const [debouncedValue, setDebouncedValue] = useState<any>(value);\n\n const timerRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n timerRef.current = \n setTimeout(() => setDebouncedValue(value), delay);\n\n return () => {\n clearTimeout(timerRef.current);\n };\n }, [value, delay]);\n\n return debouncedValue;\n}"],"names":["useDebounce","value","delay","debouncedValue","setDebouncedValue","useState","timerRef","useRef","useEffect"],"mappings":";AAEa,MAAAA,IAAc,CAACC,GAAYC,MAAkB;AACxD,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAcJ,CAAK,GAEzDK,IAAWC;AAEjB,SAAAC,EAAU,OACRF,EAAS,UACP,WAAW,MAAMF,EAAkBH,CAAK,GAAGC,CAAK,GAE3C,MAAM;AACX,iBAAaI,EAAS,OAAO;AAAA,EAAA,IAE9B,CAACL,GAAOC,CAAK,CAAC,GAEVC;AACT;"}
@@ -1,25 +1,156 @@
1
- import { dequal as s } from "./annotorious-react.es35.js";
2
- const r = (t, d) => {
3
- const o = new Set(t.bodies.map((e) => e.id));
4
- return d.bodies.filter((e) => !o.has(e.id));
5
- }, n = (t, d) => {
6
- const o = new Set(d.bodies.map((e) => e.id));
7
- return t.bodies.filter((e) => !o.has(e.id));
8
- }, g = (t, d) => d.bodies.map((o) => {
9
- const e = t.bodies.find((i) => i.id === o.id);
10
- return { newBody: o, oldBody: e && !s(e, o) ? e : void 0 };
11
- }).filter(({ oldBody: o }) => o), a = (t, d) => !s(t.target, d.target), c = (t, d) => {
12
- const o = r(t, d), e = n(t, d), i = g(t, d);
13
- return {
14
- oldValue: t,
15
- newValue: d,
16
- bodiesCreated: o.length > 0 ? o : void 0,
17
- bodiesDeleted: e.length > 0 ? e : void 0,
18
- bodiesUpdated: i.length > 0 ? i : void 0,
19
- targetUpdated: a(t, d) ? { oldTarget: t.target, newTarget: d.target } : void 0
1
+ import { useRef as ge, useState as ae, useEffect as ie } from "react";
2
+ var O = { dragStart: !0 }, he = (e, t = {}) => {
3
+ let o, c, { bounds: l, axis: m = "both", gpuAcceleration: f = !0, legacyTranslate: B = !0, transform: M, applyUserSelectHack: N = !0, disabled: R = !1, ignoreMultitouch: $ = !1, recomputeBounds: b = O, grid: H, position: u, cancel: D, handle: E, defaultClass: S = "neodrag", defaultClassDragging: i = "neodrag-dragging", defaultClassDragged: g = "neodrag-dragged", defaultPosition: W = { x: 0, y: 0 }, onDragStart: ce, onDrag: le, onDragEnd: ue } = t, X = !1, x = 0, A = 0, L = 0, T = 0, j = 0, z = 0, { x: Y, y: q } = u ? { x: (u == null ? void 0 : u.x) ?? 0, y: (u == null ? void 0 : u.y) ?? 0 } : W;
4
+ I(Y, q);
5
+ let y, C, P, F, _, ee = "", fe = !!u;
6
+ b = { ...O, ...b };
7
+ const G = document.body.style, v = e.classList;
8
+ function I(n = x, a = A) {
9
+ if (!M) {
10
+ if (B) {
11
+ let d = `${+n}px, ${+a}px`;
12
+ return k(e, "transform", f ? `translate3d(${d}, 0)` : `translate(${d})`);
13
+ }
14
+ return k(e, "translate", `${+n}px ${+a}px ${f ? "1px" : ""}`);
15
+ }
16
+ const s = M({ offsetX: n, offsetY: a, rootNode: e });
17
+ Q(s) && k(e, "transform", s);
18
+ }
19
+ const J = (n, a) => {
20
+ const s = { offsetX: x, offsetY: A, rootNode: e, currentNode: _ };
21
+ e.dispatchEvent(new CustomEvent(n, { detail: s })), a == null || a(s);
22
+ }, K = addEventListener;
23
+ K("pointerdown", re, !1), K("pointerup", te, !1), K("pointermove", oe, !1), k(e, "touch-action", "none");
24
+ const ne = () => {
25
+ let n = e.offsetWidth / C.width;
26
+ return isNaN(n) && (n = 1), n;
20
27
  };
21
- };
28
+ function re(n) {
29
+ if (R || n.button === 2 || $ && !n.isPrimary)
30
+ return;
31
+ if (b.dragStart && (y = V(l, e)), Q(E) && Q(D) && E === D)
32
+ throw new Error("`handle` selector can't be same as `cancel` selector");
33
+ if (v.add(S), P = function(r, p) {
34
+ if (!r)
35
+ return [p];
36
+ if (Z(r))
37
+ return [r];
38
+ if (Array.isArray(r))
39
+ return r;
40
+ const w = p.querySelectorAll(r);
41
+ if (w === null)
42
+ throw new Error("Selector passed for `handle` option should be child of the element on which the action is applied");
43
+ return Array.from(w.values());
44
+ }(E, e), F = function(r, p) {
45
+ if (!r)
46
+ return [];
47
+ if (Z(r))
48
+ return [r];
49
+ if (Array.isArray(r))
50
+ return r;
51
+ const w = p.querySelectorAll(r);
52
+ if (w === null)
53
+ throw new Error("Selector passed for `cancel` option should be child of the element on which the action is applied");
54
+ return Array.from(w.values());
55
+ }(D, e), o = /(both|x)/.test(m), c = /(both|y)/.test(m), de(F, P))
56
+ throw new Error("Element being dragged can't be a child of the element on which `cancel` is applied");
57
+ const a = n.composedPath()[0];
58
+ if (!P.some((r) => {
59
+ var p;
60
+ return r.contains(a) || ((p = r.shadowRoot) == null ? void 0 : p.contains(a));
61
+ }) || de(F, [a]))
62
+ return;
63
+ _ = P.length === 1 ? e : P.find((r) => r.contains(a)), X = !0, C = e.getBoundingClientRect(), N && (ee = G.userSelect, G.userSelect = "none"), J("neodrag:start", ce);
64
+ const { clientX: s, clientY: d } = n, h = ne();
65
+ o && (L = s - Y / h), c && (T = d - q / h), y && (j = s - C.left, z = d - C.top);
66
+ }
67
+ function te() {
68
+ X && (b.dragEnd && (y = V(l, e)), v.remove(i), v.add(g), N && (G.userSelect = ee), J("neodrag:end", ue), o && (L = x), c && (T = A), X = !1);
69
+ }
70
+ function oe(n) {
71
+ if (!X)
72
+ return;
73
+ b.drag && (y = V(l, e)), v.add(i), n.preventDefault(), C = e.getBoundingClientRect();
74
+ let a = n.clientX, s = n.clientY;
75
+ const d = ne();
76
+ if (y) {
77
+ const h = { left: y.left + j, top: y.top + z, right: y.right + j - C.width, bottom: y.bottom + z - C.height };
78
+ a = se(a, h.left, h.right), s = se(s, h.top, h.bottom);
79
+ }
80
+ if (Array.isArray(H)) {
81
+ let [h, r] = H;
82
+ if (isNaN(+h) || h < 0)
83
+ throw new Error("1st argument of `grid` must be a valid positive number");
84
+ if (isNaN(+r) || r < 0)
85
+ throw new Error("2nd argument of `grid` must be a valid positive number");
86
+ let p = a - L, w = s - T;
87
+ [p, w] = pe([h / d, r / d], p, w), a = L + p, s = T + w;
88
+ }
89
+ o && (x = Math.round((a - L) * d)), c && (A = Math.round((s - T) * d)), Y = x, q = A, J("neodrag", le), I();
90
+ }
91
+ return { destroy: () => {
92
+ const n = removeEventListener;
93
+ n("pointerdown", re, !1), n("pointerup", te, !1), n("pointermove", oe, !1);
94
+ }, update: (n) => {
95
+ var s, d;
96
+ m = n.axis || "both", R = n.disabled ?? !1, $ = n.ignoreMultitouch ?? !1, E = n.handle, l = n.bounds, b = n.recomputeBounds ?? O, D = n.cancel, N = n.applyUserSelectHack ?? !0, H = n.grid, f = n.gpuAcceleration ?? !0, B = n.legacyTranslate ?? !0, M = n.transform;
97
+ const a = v.contains(g);
98
+ v.remove(S, g), S = n.defaultClass ?? "neodrag", i = n.defaultClassDragging ?? "neodrag-dragging", g = n.defaultClassDragged ?? "neodrag-dragged", v.add(S), a && v.add(g), fe && (Y = x = ((s = n.position) == null ? void 0 : s.x) ?? x, q = A = ((d = n.position) == null ? void 0 : d.y) ?? A, I());
99
+ } };
100
+ }, se = (e, t, o) => Math.min(Math.max(e, t), o), Q = (e) => typeof e == "string", pe = ([e, t], o, c) => {
101
+ const l = (m, f) => f === 0 ? 0 : Math.ceil(m / f) * f;
102
+ return [l(o, e), l(c, t)];
103
+ }, de = (e, t) => e.some((o) => t.some((c) => o.contains(c)));
104
+ function V(e, t) {
105
+ if (e === void 0)
106
+ return;
107
+ if (Z(e))
108
+ return e.getBoundingClientRect();
109
+ if (typeof e == "object") {
110
+ const { top: c = 0, left: l = 0, right: m = 0, bottom: f = 0 } = e;
111
+ return { top: c, right: window.innerWidth - m, bottom: window.innerHeight - f, left: l };
112
+ }
113
+ if (e === "parent")
114
+ return t.parentNode.getBoundingClientRect();
115
+ const o = document.querySelector(e);
116
+ if (o === null)
117
+ throw new Error("The selector provided for bound doesn't exists in the document.");
118
+ return o.getBoundingClientRect();
119
+ }
120
+ var k = (e, t, o) => e.style.setProperty(t, o), Z = (e) => e instanceof HTMLElement;
121
+ function U(e) {
122
+ return e == null || typeof e == "string" || e instanceof HTMLElement ? e : "current" in e ? e.current : Array.isArray(e) ? e.map((t) => t instanceof HTMLElement ? t : t.current) : void 0;
123
+ }
124
+ function ye(e, t = {}) {
125
+ const o = ge(), [c, l] = ae(!1), [m, f] = ae();
126
+ let { onDragStart: B, onDrag: M, onDragEnd: N, handle: R, cancel: $ } = t, b = U(R), H = U($);
127
+ function u(i, g) {
128
+ f(i), g == null || g(i);
129
+ }
130
+ function D(i) {
131
+ l(!0), u(i, B);
132
+ }
133
+ function E(i) {
134
+ u(i, M);
135
+ }
136
+ function S(i) {
137
+ l(!1), u(i, N);
138
+ }
139
+ return ie(() => {
140
+ if (typeof window > "u")
141
+ return;
142
+ const i = e.current;
143
+ if (!i)
144
+ return;
145
+ ({ onDragStart: B, onDrag: M, onDragEnd: N } = t);
146
+ const { update: g, destroy: W } = he(i, { ...t, handle: b, cancel: H, onDragStart: D, onDrag: E, onDragEnd: S });
147
+ return o.current = g, W;
148
+ }, []), ie(() => {
149
+ var i;
150
+ (i = o.current) == null || i.call(o, { ...t, handle: U(R), cancel: U($), onDragStart: D, onDrag: E, onDragEnd: S });
151
+ }, [t]), { isDragging: c, dragState: m };
152
+ }
22
153
  export {
23
- c as diffAnnotations
154
+ ye as useDraggable
24
155
  };
25
156
  //# sourceMappingURL=annotorious-react.es15.js.map