@soomo/react-text-annotator 3.0.0-staging.5 → 3.0.0-staging.51

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 (75) hide show
  1. package/dist/TextAnnotator.d.ts +3 -4
  2. package/dist/TextAnnotator.d.ts.map +1 -1
  3. package/dist/TextAnnotatorPlugin.d.ts +1 -2
  4. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +15 -0
  5. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -0
  6. package/dist/TextAnnotatorPopup/index.d.ts +2 -0
  7. package/dist/TextAnnotatorPopup/index.d.ts.map +1 -0
  8. package/dist/hooks/index.d.ts +2 -0
  9. package/dist/hooks/index.d.ts.map +1 -0
  10. package/dist/hooks/useAnnouncePopupNavigation.d.ts +10 -0
  11. package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +1 -0
  12. package/dist/index.d.ts +7 -9
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/react-text-annotator.css +31 -1
  15. package/dist/react-text-annotator.es.js +11 -8
  16. package/dist/react-text-annotator.es.js.map +1 -1
  17. package/dist/react-text-annotator.es10.js +486 -34
  18. package/dist/react-text-annotator.es10.js.map +1 -1
  19. package/dist/react-text-annotator.es11.js +1406 -822
  20. package/dist/react-text-annotator.es11.js.map +1 -1
  21. package/dist/react-text-annotator.es13.js +241 -2
  22. package/dist/react-text-annotator.es13.js.map +1 -1
  23. package/dist/react-text-annotator.es14.js +560 -105
  24. package/dist/react-text-annotator.es14.js.map +1 -1
  25. package/dist/react-text-annotator.es15.js +54 -299
  26. package/dist/react-text-annotator.es15.js.map +1 -1
  27. package/dist/react-text-annotator.es16.js +38 -51
  28. package/dist/react-text-annotator.es16.js.map +1 -1
  29. package/dist/react-text-annotator.es17.js +2 -20
  30. package/dist/react-text-annotator.es17.js.map +1 -1
  31. package/dist/react-text-annotator.es18.js +34 -0
  32. package/dist/react-text-annotator.es18.js.map +1 -0
  33. package/dist/react-text-annotator.es19.js +901 -0
  34. package/dist/react-text-annotator.es19.js.map +1 -0
  35. package/dist/react-text-annotator.es2.js +2 -2
  36. package/dist/react-text-annotator.es20.js +117 -0
  37. package/dist/react-text-annotator.es20.js.map +1 -0
  38. package/dist/react-text-annotator.es21.js +312 -0
  39. package/dist/react-text-annotator.es21.js.map +1 -0
  40. package/dist/react-text-annotator.es22.js +61 -0
  41. package/dist/react-text-annotator.es22.js.map +1 -0
  42. package/dist/react-text-annotator.es23.js +23 -0
  43. package/dist/react-text-annotator.es23.js.map +1 -0
  44. package/dist/{react-text-annotator.es12.js → react-text-annotator.es24.js} +1 -1
  45. package/dist/react-text-annotator.es24.js.map +1 -0
  46. package/dist/react-text-annotator.es25.js +5 -0
  47. package/dist/react-text-annotator.es25.js.map +1 -0
  48. package/dist/react-text-annotator.es26.js +130 -0
  49. package/dist/react-text-annotator.es26.js.map +1 -0
  50. package/dist/react-text-annotator.es27.js +155 -0
  51. package/dist/react-text-annotator.es27.js.map +1 -0
  52. package/dist/react-text-annotator.es28.js +314 -0
  53. package/dist/react-text-annotator.es28.js.map +1 -0
  54. package/dist/react-text-annotator.es29.js +152 -0
  55. package/dist/react-text-annotator.es29.js.map +1 -0
  56. package/dist/react-text-annotator.es3.js +2 -2
  57. package/dist/react-text-annotator.es30.js +563 -0
  58. package/dist/react-text-annotator.es30.js.map +1 -0
  59. package/dist/react-text-annotator.es4.js +38 -28
  60. package/dist/react-text-annotator.es4.js.map +1 -1
  61. package/dist/react-text-annotator.es5.js +23 -47
  62. package/dist/react-text-annotator.es5.js.map +1 -1
  63. package/dist/react-text-annotator.es6.js +129 -10
  64. package/dist/react-text-annotator.es6.js.map +1 -1
  65. package/dist/react-text-annotator.es7.js +181 -1
  66. package/dist/react-text-annotator.es7.js.map +1 -1
  67. package/dist/react-text-annotator.es8.js +9 -487
  68. package/dist/react-text-annotator.es8.js.map +1 -1
  69. package/dist/tei/TEIAnnotator.d.ts +2 -3
  70. package/package.json +23 -16
  71. package/dist/TextAnnotatorPopup.d.ts +0 -14
  72. package/dist/TextAnnotatorPopup.d.ts.map +0 -1
  73. package/dist/react-text-annotator.es12.js.map +0 -1
  74. package/dist/react-text-annotator.es9.js +0 -5
  75. package/dist/react-text-annotator.es9.js.map +0 -1
@@ -1,33 +1,43 @@
1
- import { j as jsxRuntimeExports } from "./react-text-annotator.es6.js";
2
- import { useRef, useContext, useEffect } from "react";
3
- import { AnnotoriousContext } from "@annotorious/react";
4
- import { createTextAnnotator } from "@soomo/text-annotator";
5
- import "./react-text-annotator.es7.js";
6
- const TextAnnotator = (props) => {
7
- const el = useRef(null);
8
- const { className, children, ...opts } = props;
9
- const { anno, setAnno } = useContext(AnnotoriousContext);
1
+ import { useCallback, useLayoutEffect, useMemo, useRef, useEffect } from "react";
2
+ import { useAnnotationStore, useSelection, Origin } from "@annotorious/react";
3
+ import { announce as $319e236875307eab$export$a9b970dcc4ae71a9, destroyAnnouncer as $319e236875307eab$export$d8686216b8b81b2f } from "./react-text-annotator.es15.js";
4
+ import { exhaustiveUniqueRandom } from "./react-text-annotator.es16.js";
5
+ const useAnnouncePopupNavigation = (args) => {
6
+ const {
7
+ message = "Press Tab to move to Notes Dialog",
8
+ idle = 700,
9
+ floatingOpen,
10
+ disabled = false
11
+ } = args;
12
+ const store = useAnnotationStore();
13
+ const { event } = useSelection();
14
+ const uniqueRandom = useCallback(exhaustiveUniqueRandom(1, 1e4), []);
15
+ useLayoutEffect(() => {
16
+ if (disabled || !message) return;
17
+ $319e236875307eab$export$a9b970dcc4ae71a9("", "polite");
18
+ return () => $319e236875307eab$export$d8686216b8b81b2f();
19
+ }, [disabled, message]);
20
+ const announcementSeed = useMemo(() => floatingOpen ? uniqueRandom() : 0, [floatingOpen]);
21
+ const announcePopupNavigation = useCallback(() => {
22
+ const uniqueSpaces = Array.from({ length: announcementSeed }).map(() => " ").join("");
23
+ $319e236875307eab$export$a9b970dcc4ae71a9(`${message} ${uniqueSpaces}`, "polite");
24
+ }, [message, announcementSeed]);
25
+ const idleTimeoutRef = useRef(null);
10
26
  useEffect(() => {
11
- if (!setAnno)
12
- return;
13
- const adapter = typeof opts.adapter === "function" ? opts.adapter(el.current) : opts.adapter;
14
- const anno2 = createTextAnnotator(el.current, { ...opts, adapter });
15
- setAnno(anno2);
16
- return () => anno2.destroy();
17
- }, [setAnno]);
18
- useEffect(() => {
19
- if (!anno)
20
- return;
21
- anno.setStyle(props.style);
22
- }, [anno, props.style]);
23
- useEffect(() => {
24
- if (!anno)
25
- return;
26
- anno.setFilter(props.filter);
27
- }, [anno, props.filter]);
28
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: el, className, children });
27
+ if (disabled || !floatingOpen || !message) return;
28
+ const scheduleIdleAnnouncement = () => {
29
+ clearTimeout(idleTimeoutRef.current);
30
+ idleTimeoutRef.current = setTimeout(announcePopupNavigation, idle);
31
+ };
32
+ scheduleIdleAnnouncement();
33
+ store.observe(scheduleIdleAnnouncement, { origin: Origin.LOCAL });
34
+ return () => {
35
+ clearTimeout(idleTimeoutRef.current);
36
+ store.unobserve(scheduleIdleAnnouncement);
37
+ };
38
+ }, [disabled, floatingOpen, event == null ? void 0 : event.type, message, announcePopupNavigation, store]);
29
39
  };
30
40
  export {
31
- TextAnnotator
41
+ useAnnouncePopupNavigation
32
42
  };
33
43
  //# sourceMappingURL=react-text-annotator.es4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-text-annotator.es4.js","sources":["../src/TextAnnotator.tsx"],"sourcesContent":["import { ReactNode, useContext, useEffect, useRef } from 'react';\nimport { AnnotoriousContext, Filter } from '@annotorious/react';\nimport type { FormatAdapter } from '@annotorious/core';\nimport type { HighlightStyleExpression, TextAnnotation, TextAnnotatorOptions } from '@soomo/text-annotator';\nimport { createTextAnnotator } from '@soomo/text-annotator';\n\nimport '@soomo/text-annotator/dist/text-annotator.css';\n\n\nexport interface TextAnnotatorProps<E extends unknown> extends Omit<TextAnnotatorOptions<E>, 'adapter'> {\n\n children?: ReactNode | JSX.Element;\n\n adapter?: FormatAdapter<TextAnnotation, E> | ((container: HTMLElement) => FormatAdapter<TextAnnotation, E>) | null;\n\n filter?: Filter;\n\n style?: HighlightStyleExpression;\n\n className?: string;\n\n}\n\nexport const TextAnnotator = <E extends unknown>(props: TextAnnotatorProps<E>) => {\n\n const el = useRef<HTMLDivElement>(null);\n\n const { className, children, ...opts } = props;\n\n const { anno, setAnno } = useContext(AnnotoriousContext);\n\n useEffect(() => {\n if (!setAnno) return;\n\n const adapter = typeof opts.adapter === 'function' ? opts.adapter(el.current) : opts.adapter;\n\n const anno = createTextAnnotator(el.current, { ...opts, adapter });\n setAnno(anno);\n\n return () => anno.destroy();\n }, [setAnno]);\n\n useEffect(() => {\n if (!anno) return;\n\n anno.setStyle(props.style);\n }, [anno, props.style]);\n\n useEffect(() => {\n if (!anno) return;\n \n anno.setFilter(props.filter);\n }, [anno, props.filter]);\n\n return (\n <div ref={el} className={className}>\n {children}\n </div>\n )\n\n}\n"],"names":["anno","jsx"],"mappings":";;;;;AAuBa,MAAA,gBAAgB,CAAoB,UAAiC;AAE1E,QAAA,KAAK,OAAuB,IAAI;AAEtC,QAAM,EAAE,WAAW,UAAU,GAAG,SAAS;AAEzC,QAAM,EAAE,MAAM,QAAQ,IAAI,WAAW,kBAAkB;AAEvD,YAAU,MAAM;AACd,QAAI,CAAC;AAAS;AAER,UAAA,UAAU,OAAO,KAAK,YAAY,aAAa,KAAK,QAAQ,GAAG,OAAO,IAAI,KAAK;AAE/EA,UAAAA,QAAO,oBAAoB,GAAG,SAAS,EAAE,GAAG,MAAM,SAAS;AACjE,YAAQA,KAAI;AAEL,WAAA,MAAMA,MAAK;EAAQ,GACzB,CAAC,OAAO,CAAC;AAEZ,YAAU,MAAM;AACd,QAAI,CAAC;AAAM;AAEN,SAAA,SAAS,MAAM,KAAK;AAAA,EACxB,GAAA,CAAC,MAAM,MAAM,KAAK,CAAC;AAEtB,YAAU,MAAM;AACd,QAAI,CAAC;AAAM;AAEN,SAAA,UAAU,MAAM,MAAM;AAAA,EAC1B,GAAA,CAAC,MAAM,MAAM,MAAM,CAAC;AAEvB,SACGC,kCAAAA,IAAA,OAAA,EAAI,KAAK,IAAI,WACX,SACH,CAAA;AAGJ;"}
1
+ {"version":3,"file":"react-text-annotator.es4.js","sources":["../src/hooks/useAnnouncePopupNavigation.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react';\n\nimport { Origin, useAnnotationStore, useSelection } from '@annotorious/react';\nimport type { TextAnnotation } from '@recogito/text-annotator';\nimport { announce, destroyAnnouncer } from '@react-aria/live-announcer';\nimport { exhaustiveUniqueRandom } from 'unique-random';\n\ninterface AnnouncePopupOpeningArgs {\n message?: string;\n idle?: number;\n floatingOpen: boolean;\n floatingFocused?: boolean;\n disabled?: boolean;\n}\n\nexport const useAnnouncePopupNavigation = (args: AnnouncePopupOpeningArgs) => {\n const {\n message = 'Press Tab to move to Notes Dialog',\n idle = 700,\n floatingOpen,\n disabled = false\n } = args;\n\n const store = useAnnotationStore();\n const { event } = useSelection<TextAnnotation>();\n\n // Generate random numbers that do not repeat until the entire 1-10000 range has appeared\n const uniqueRandom = useCallback(exhaustiveUniqueRandom(1, 10000), []);\n\n /**\n * Initialize the `LiveAnnouncer` class and\n * its `polite` announcements live area\n */\n useLayoutEffect(() => {\n if (disabled || !message) return;\n\n announce('', 'polite');\n return () => destroyAnnouncer();\n }, [disabled, message]);\n\n /**\n * Screen reader requires messages to always be unique!\n * Otherwise, the hint will be announced once per page.\n */\n const announcementSeed = useMemo(() => floatingOpen ? uniqueRandom() : 0, [floatingOpen]);\n\n const announcePopupNavigation = useCallback(() => {\n /**\n * To imitate the uniqueness of the announced message\n * w/o mutating it - we can append spaces at the end.\n */\n const uniqueSpaces = Array.from({ length: announcementSeed }).map(() => ' ').join('');\n announce(`${message} ${uniqueSpaces}`, 'polite');\n }, [message, announcementSeed]);\n\n const idleTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n useEffect(() => {\n if (disabled || !floatingOpen || !message) return;\n\n const scheduleIdleAnnouncement = () => {\n clearTimeout(idleTimeoutRef.current);\n idleTimeoutRef.current = setTimeout(announcePopupNavigation, idle);\n };\n\n scheduleIdleAnnouncement();\n store.observe(scheduleIdleAnnouncement, { origin: Origin.LOCAL });\n\n return () => {\n clearTimeout(idleTimeoutRef.current);\n store.unobserve(scheduleIdleAnnouncement);\n };\n }, [disabled, floatingOpen, event?.type, message, announcePopupNavigation, store]);\n\n};\n"],"names":["announce","destroyAnnouncer"],"mappings":";;;;AAea,MAAA,6BAA6B,CAAC,SAAmC;AACtE,QAAA;AAAA,IACJ,UAAU;AAAA,IACV,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,EACT,IAAA;AAEJ,QAAM,QAAQ;AACR,QAAA,EAAE,UAAU;AAGlB,QAAM,eAAe,YAAY,uBAAuB,GAAG,GAAK,GAAG,CAAA,CAAE;AAMrE,kBAAgB,MAAM;AAChB,QAAA,YAAY,CAAC,QAAS;AAE1BA,8CAAS,IAAI,QAAQ;AACrB,WAAO,MAAMC,0CAAiB;AAAA,EAAA,GAC7B,CAAC,UAAU,OAAO,CAAC;AAMhB,QAAA,mBAAmB,QAAQ,MAAM,eAAe,iBAAiB,GAAG,CAAC,YAAY,CAAC;AAElF,QAAA,0BAA0B,YAAY,MAAM;AAKhD,UAAM,eAAe,MAAM,KAAK,EAAE,QAAQ,iBAAA,CAAkB,EAAE,IAAI,MAAM,GAAG,EAAE,KAAK,EAAE;AACpFD,8CAAS,GAAG,OAAO,IAAI,YAAY,IAAI,QAAQ;AAAA,EAAA,GAC9C,CAAC,SAAS,gBAAgB,CAAC;AAExB,QAAA,iBAAiB,OAA6C,IAAI;AAExE,YAAU,MAAM;AACd,QAAI,YAAY,CAAC,gBAAgB,CAAC,QAAS;AAE3C,UAAM,2BAA2B,MAAM;AACrC,mBAAa,eAAe,OAAO;AACpB,qBAAA,UAAU,WAAW,yBAAyB,IAAI;AAAA,IAAA;AAG1C;AACzB,UAAM,QAAQ,0BAA0B,EAAE,QAAQ,OAAO,OAAO;AAEhE,WAAO,MAAM;AACX,mBAAa,eAAe,OAAO;AACnC,YAAM,UAAU,wBAAwB;AAAA,IAAA;AAAA,EAC1C,GACC,CAAC,UAAU,cAAc,+BAAO,MAAM,SAAS,yBAAyB,KAAK,CAAC;AAEnF;"}
@@ -1,53 +1,29 @@
1
- import { j as jsxRuntimeExports } from "./react-text-annotator.es6.js";
2
- import { createPortal } from "react-dom";
3
- import { useRef, useState, useEffect } from "react";
4
- import { useAnnotator, useSelection } from "@annotorious/react";
5
- const TextAnnotatorPopup = (props) => {
1
+ import { j as jsxRuntimeExports } from "./react-text-annotator.es8.js";
2
+ import { useRef, useContext, useEffect } from "react";
3
+ import { AnnotoriousContext } from "@annotorious/react";
4
+ import { createTextAnnotator } from "@soomo/text-annotator";
5
+ /* empty css */
6
+ const TextAnnotator = (props) => {
6
7
  const el = useRef(null);
7
- const r = useAnnotator();
8
- const [open, setOpen] = useState(false);
9
- const { selected, pointerEvent } = useSelection();
8
+ const { className, children, ...opts } = props;
9
+ const { style, filter, user, annotatingEnabled, userSelectAction } = opts;
10
+ const { anno, setAnno } = useContext(AnnotoriousContext);
10
11
  useEffect(() => {
11
- if (pointerEvent) {
12
- if (selected.length > 0 && pointerEvent.type === "pointerup") {
13
- setOpen(true);
14
- } else {
15
- setOpen(false);
16
- }
17
- }
18
- }, [pointerEvent, selected.map((a) => a.annotation.id).join("-")]);
19
- useEffect(() => {
20
- if (!(pointerEvent && open && (r == null ? void 0 : r.element)))
21
- return;
22
- const { left, top } = r.element.getBoundingClientRect();
23
- let x = pointerEvent.clientX - left;
24
- let y = pointerEvent.clientY - top;
25
- const { id } = selected[0].annotation;
26
- const { offsetX, offsetY } = pointerEvent;
27
- const bounds = r.state.store.getAnnotationBounds(id, offsetX, offsetY);
28
- if (bounds) {
29
- x = Math.max(x, bounds.x - left);
30
- x = Math.min(x, bounds.right - left);
31
- }
32
- el.current.style.left = `${x}px`;
33
- el.current.style.top = `${y}px`;
34
- }, [open, pointerEvent, r == null ? void 0 : r.element]);
35
- const onPointerUp = (evt) => evt.stopPropagation();
36
- return open && selected.length > 0 ? createPortal(
37
- /* @__PURE__ */ jsxRuntimeExports.jsx(
38
- "div",
39
- {
40
- ref: el,
41
- className: "a9s-popup r6o-popup not-annotatable",
42
- style: { position: "absolute" },
43
- onPointerUp,
44
- children: props.popup({ selected })
45
- }
46
- ),
47
- r.element
48
- ) : null;
12
+ if (!setAnno) return;
13
+ const adapter = typeof opts.adapter === "function" ? opts.adapter(el.current) : opts.adapter;
14
+ const anno2 = createTextAnnotator(el.current, { ...opts, adapter });
15
+ setAnno(anno2);
16
+ return () => anno2.destroy();
17
+ }, [setAnno]);
18
+ useEffect(() => anno == null ? void 0 : anno.setStyle(style), [anno, style]);
19
+ useEffect(() => anno == null ? void 0 : anno.setFilter(filter), [anno, filter]);
20
+ useEffect(() => anno == null ? void 0 : anno.setFilter(filter), [anno, filter]);
21
+ useEffect(() => anno == null ? void 0 : anno.setUserSelectAction(userSelectAction), [anno, userSelectAction]);
22
+ useEffect(() => anno == null ? void 0 : anno.setUser(user), [anno, user]);
23
+ useEffect(() => anno == null ? void 0 : anno.setAnnotatingEnabled(annotatingEnabled), [anno, annotatingEnabled]);
24
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: el, className, children });
49
25
  };
50
26
  export {
51
- TextAnnotatorPopup
27
+ TextAnnotator
52
28
  };
53
29
  //# sourceMappingURL=react-text-annotator.es5.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-text-annotator.es5.js","sources":["../src/TextAnnotatorPopup.tsx"],"sourcesContent":["import { createPortal } from 'react-dom';\nimport { ReactNode, useEffect, useRef, useState } from 'react';\nimport { TextAnnotator, TextAnnotation, TextAnnotatorState } from '@soomo/text-annotator';\nimport { useAnnotator, useSelection } from '@annotorious/react';\n\nexport interface TextAnnotatorPopupProps {\n\n selected: { annotation: TextAnnotation, editable?: boolean }[];\n\n}\n\nexport interface TextAnnotatorPopupContainerProps {\n\n popup(props: TextAnnotatorPopupProps): ReactNode | JSX.Element;\n\n}\n\nexport const TextAnnotatorPopup = (props: TextAnnotatorPopupContainerProps) => {\n\n const el = useRef<HTMLDivElement>(null);\n\n const r = useAnnotator<TextAnnotator>();\n\n const [open, setOpen] = useState(false);\n\n const { selected, pointerEvent } = useSelection<TextAnnotation>();\n\n useEffect(() => {\n // Ignore all selection changes except those\n // accompanied by a pointer event.\n if (pointerEvent) {\n if (selected.length > 0 && pointerEvent.type === 'pointerup') {\n setOpen(true);\n } else {\n setOpen(false);\n }\n }\n }, [pointerEvent, selected.map(a => a.annotation.id).join('-')]);\n\n useEffect(() => {\n if (!(pointerEvent && open && r?.element))\n return;\n\n const { left, top } = r.element.getBoundingClientRect();\n let x = pointerEvent.clientX - left;\n let y = pointerEvent.clientY - top;\n\n const { id } = selected[0].annotation;\n const { offsetX, offsetY } = pointerEvent;\n const bounds = (r.state as TextAnnotatorState).store.getAnnotationBounds(id, offsetX, offsetY);\n \n if (bounds) {\n x = Math.max(x, bounds.x - left);\n x = Math.min(x, bounds.right - left);\n }\n\n el.current.style.left = `${x}px`;\n el.current.style.top = `${y}px`;\n }, [open, pointerEvent, r?.element]);\n\n const onPointerUp = (evt: React.PointerEvent<HTMLDivElement>) =>\n evt.stopPropagation();\n \n return (open && selected.length > 0) ? createPortal(\n <div \n ref={el}\n className=\"a9s-popup r6o-popup not-annotatable\"\n style={{ position: 'absolute' }}\n onPointerUp={onPointerUp}>\n\n {props.popup({ selected })}\n \n </div>, r.element\n ) : null;\n\n}\n"],"names":["jsx"],"mappings":";;;;AAiBa,MAAA,qBAAqB,CAAC,UAA4C;AAEvE,QAAA,KAAK,OAAuB,IAAI;AAEtC,QAAM,IAAI;AAEV,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AAEtC,QAAM,EAAE,UAAU,aAAa,IAAI,aAA6B;AA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extAnnotator.tsx"],"sourcesContent":["import { ReactNode, useContext, useEffect, useRef } from 'react';\nimport { AnnotoriousContext, Filter } from '@annotorious/react';\nimport type { FormatAdapter } from '@annotorious/core';\nimport type { HighlightStyleExpression, TextAnnotation, TextAnnotatorOptions } from '@soomo/text-annotator';\nimport { createTextAnnotator } from '@soomo/text-annotator';\n\nimport '@soomo/text-annotator/dist/text-annotator.css';\n\n\nexport interface TextAnnotatorProps<E extends unknown> extends Omit<TextAnnotatorOptions<E>, 'adapter'> {\n\n children?: ReactNode | JSX.Element;\n\n adapter?: FormatAdapter<TextAnnotation, E> | ((container: HTMLElement) => FormatAdapter<TextAnnotation, E>) | null;\n\n filter?: Filter;\n\n style?: HighlightStyleExpression;\n\n className?: string;\n\n}\n\nexport const TextAnnotator = <E extends unknown>(props: TextAnnotatorProps<E>) => {\n\n const el = useRef<HTMLDivElement>(null);\n\n const { className, children, ...opts } = props;\n const { style, filter, user, annotatingEnabled, userSelectAction } = opts;\n\n const { anno, setAnno } = useContext(AnnotoriousContext);\n\n useEffect(() => {\n if (!setAnno) return;\n\n const adapter = typeof opts.adapter === 'function' ? opts.adapter(el.current) : opts.adapter;\n\n const anno = createTextAnnotator(el.current, { ...opts, adapter });\n setAnno(anno);\n\n return () => anno.destroy();\n }, [setAnno]);\n\n useEffect(() => anno?.setStyle(style), [anno, style]);\n\n useEffect(() => anno?.setFilter(filter), [anno, filter]);\n\n useEffect(() => anno?.setFilter(filter), [anno, filter]);\n\n useEffect(() => anno?.setUserSelectAction(userSelectAction), [anno, userSelectAction]);\n\n useEffect(() => anno?.setUser(user), [anno, user]);\n\n useEffect(() => anno?.setAnnotatingEnabled(annotatingEnabled), [anno, annotatingEnabled]);\n\n return (\n <div ref={el} className={className}>\n {children}\n </div>\n );\n\n};\n"],"names":["anno","jsx"],"mappings":";;;;;AAuBa,MAAA,gBAAgB,CAAoB,UAAiC;AAE1E,QAAA,KAAK,OAAuB,IAAI;AAEtC,QAAM,EAAE,WAAW,UAAU,GAAG,SAAS;AACzC,QAAM,EAAE,OAAO,QAAQ,MAAM,mBAAmB,iBAAqB,IAAA;AAErE,QAAM,EAAE,MAAM,QAAQ,IAAI,WAAW,kBAAkB;AAEvD,YAAU,MAAM;AACd,QAAI,CAAC,QAAS;AAER,UAAA,UAAU,OAAO,KAAK,YAAY,aAAa,KAAK,QAAQ,GAAG,OAAO,IAAI,KAAK;AAE/EA,UAAAA,QAAO,oBAAoB,GAAG,SAAS,EAAE,GAAG,MAAM,SAAS;AACjE,YAAQA,KAAI;AAEL,WAAA,MAAMA,MAAK;EAAQ,GACzB,CAAC,OAAO,CAAC;AAEF,YAAA,MAAM,6BAAM,SAAS,QAAQ,CAAC,MAAM,KAAK,CAAC;AAE1C,YAAA,MAAM,6BAAM,UAAU,SAAS,CAAC,MAAM,MAAM,CAAC;AAE7C,YAAA,MAAM,6BAAM,UAAU,SAAS,CAAC,MAAM,MAAM,CAAC;AAE7C,YAAA,MAAM,6BAAM,oBAAoB,mBAAmB,CAAC,MAAM,gBAAgB,CAAC;AAE3E,YAAA,MAAM,6BAAM,QAAQ,OAAO,CAAC,MAAM,IAAI,CAAC;AAEvC,YAAA,MAAM,6BAAM,qBAAqB,oBAAoB,CAAC,MAAM,iBAAiB,CAAC;AAExF,SACGC,kCAAAA,IAAA,OAAA,EAAI,KAAK,IAAI,WACX,SACH,CAAA;AAGJ;"}
@@ -1,13 +1,132 @@
1
- import { __module as jsxRuntime } from "./react-text-annotator.es9.js";
2
- import { __require as requireReactJsxRuntime_production_min } from "./react-text-annotator.es10.js";
3
- import { __require as requireReactJsxRuntime_development } from "./react-text-annotator.es11.js";
4
- if (process.env.NODE_ENV === "production") {
5
- jsxRuntime.exports = requireReactJsxRuntime_production_min();
6
- } else {
7
- jsxRuntime.exports = requireReactJsxRuntime_development();
8
- }
9
- var jsxRuntimeExports = jsxRuntime.exports;
1
+ import { j as jsxRuntimeExports } from "./react-text-annotator.es8.js";
2
+ import { useState, useEffect, useCallback } from "react";
3
+ import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager } from "./react-text-annotator.es11.js";
4
+ import { useAnnotator, useSelection } from "@annotorious/react";
5
+ import { denormalizeRectWithOffset, toDomRectList } from "@soomo/text-annotator";
6
+ import { useAnnouncePopupNavigation } from "./react-text-annotator.es4.js";
7
+ /* empty css */
8
+ import { offset, inline, flip, shift } from "./react-text-annotator.es13.js";
9
+ import { autoUpdate } from "./react-text-annotator.es14.js";
10
+ const TextAnnotatorPopup = (props) => {
11
+ var _a;
12
+ const { popup, popupNavigationMessage } = props;
13
+ const r = useAnnotator();
14
+ const { selected, event } = useSelection();
15
+ const annotation = (_a = selected[0]) == null ? void 0 : _a.annotation;
16
+ const [isOpen, setOpen] = useState((selected == null ? void 0 : selected.length) > 0);
17
+ const handleClose = () => r == null ? void 0 : r.cancelSelected();
18
+ const [isFloatingFocused, setFloatingFocused] = useState(false);
19
+ const handleFloatingFocus = () => setFloatingFocused(true);
20
+ const handleFloatingBlur = () => setFloatingFocused(false);
21
+ useEffect(() => {
22
+ if (!isOpen) handleFloatingBlur();
23
+ }, [isOpen, handleFloatingBlur]);
24
+ const { refs, floatingStyles, update, context } = useFloating({
25
+ placement: "top",
26
+ open: isOpen,
27
+ onOpenChange: (open, _event, reason) => {
28
+ setOpen(open);
29
+ if (!open) {
30
+ if (reason === "escape-key" || reason === "focus-out") {
31
+ handleClose();
32
+ }
33
+ }
34
+ },
35
+ middleware: [
36
+ offset(10),
37
+ inline(),
38
+ flip(),
39
+ shift({ mainAxis: false, crossAxis: true, padding: 10 })
40
+ ],
41
+ whileElementsMounted: autoUpdate
42
+ });
43
+ const dismiss = useDismiss(context);
44
+ const role = useRole(context, { role: "dialog" });
45
+ const { getFloatingProps } = useInteractions([dismiss, role]);
46
+ const selectedKey = selected.map((a) => a.annotation.id).join("-");
47
+ useEffect(() => {
48
+ if (selected.length > 0 && event) {
49
+ setOpen(event.type === "pointerup" || event.type === "keydown");
50
+ }
51
+ }, [selectedKey, event]);
52
+ useEffect(() => {
53
+ if (selected.length === 0 && isOpen) {
54
+ setOpen(false);
55
+ }
56
+ }, [isOpen, selectedKey]);
57
+ useEffect(() => {
58
+ if (!r) return;
59
+ if (isOpen && (annotation == null ? void 0 : annotation.id)) {
60
+ refs.setPositionReference({
61
+ getBoundingClientRect: () => denormalizeRectWithOffset(
62
+ r.state.store.getAnnotationBounds(annotation.id),
63
+ r.element.getBoundingClientRect()
64
+ ),
65
+ getClientRects: () => {
66
+ const rects = r.state.store.getAnnotationRects(annotation.id);
67
+ const denormalizedRects = rects.map(
68
+ (rect) => denormalizeRectWithOffset(rect, r.element.getBoundingClientRect())
69
+ );
70
+ return toDomRectList(denormalizedRects);
71
+ }
72
+ });
73
+ } else {
74
+ refs.setPositionReference(null);
75
+ }
76
+ }, [isOpen, annotation == null ? void 0 : annotation.id, annotation == null ? void 0 : annotation.target, r]);
77
+ const getStopEventsPropagationProps = useCallback(
78
+ () => ({ onPointerUp: (event2) => event2.stopPropagation() }),
79
+ []
80
+ );
81
+ useEffect(() => {
82
+ const config = { attributes: true, childList: true, subtree: true };
83
+ const mutationObserver = new MutationObserver(() => update());
84
+ mutationObserver.observe(document.body, config);
85
+ window.document.addEventListener("scroll", update, true);
86
+ return () => {
87
+ mutationObserver.disconnect();
88
+ window.document.removeEventListener("scroll", update, true);
89
+ };
90
+ }, [update]);
91
+ useAnnouncePopupNavigation({
92
+ disabled: isFloatingFocused,
93
+ floatingOpen: isOpen,
94
+ message: popupNavigationMessage
95
+ });
96
+ return isOpen && selected.length > 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingPortal, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
97
+ FloatingFocusManager,
98
+ {
99
+ context,
100
+ modal: false,
101
+ closeOnFocusOut: true,
102
+ initialFocus: (
103
+ /**
104
+ * Don't shift focus to the floating element
105
+ * when the selection performed with the keyboard
106
+ */
107
+ (event == null ? void 0 : event.type) === "keydown" ? -1 : 0
108
+ ),
109
+ returnFocus: false,
110
+ children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
111
+ "div",
112
+ {
113
+ className: "annotation-popup text-annotation-popup not-annotatable",
114
+ ref: refs.setFloating,
115
+ style: floatingStyles,
116
+ onFocus: handleFloatingFocus,
117
+ onBlur: handleFloatingBlur,
118
+ ...getFloatingProps(),
119
+ ...getStopEventsPropagationProps(),
120
+ children: [
121
+ popup({ selected }),
122
+ /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "popup-close-message", onClick: handleClose, children: "This dialog closes when you leave it." })
123
+ ]
124
+ }
125
+ )
126
+ }
127
+ ) }) : null;
128
+ };
10
129
  export {
11
- jsxRuntimeExports as j
130
+ TextAnnotatorPopup
12
131
  };
13
132
  //# sourceMappingURL=react-text-annotator.es6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-text-annotator.es6.js","sources":["../../../node_modules/react/jsx-runtime.js"],"sourcesContent":["'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-jsx-runtime.production.min.js');\n} else {\n module.exports = require('./cjs/react-jsx-runtime.development.js');\n}\n"],"names":["jsxRuntimeModule","require$$0","require$$1"],"mappings":";;;AAEA,IAAI,QAAQ,IAAI,aAAa,cAAc;AACzCA,aAAA,UAAiBC;AACnB,OAAO;AACLD,aAAA,UAAiBE;AACnB;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"react-text-annotator.es6.js","sources":["../src/TextAnnotatorPopup/TextAnnotatorPopup.tsx"],"sourcesContent":["import React, { FC, PointerEvent, ReactNode, useCallback, useEffect, useState } from 'react';\nimport {\n autoUpdate,\n flip,\n FloatingFocusManager,\n FloatingPortal,\n inline,\n offset,\n shift,\n useDismiss,\n useFloating,\n useInteractions,\n useRole\n} from '@floating-ui/react';\n\nimport { useAnnotator, useSelection } from '@annotorious/react';\nimport {\n denormalizeRectWithOffset,\n toDomRectList,\n type TextAnnotation,\n type TextAnnotator,\n} from '@soomo/text-annotator';\n\nimport { useAnnouncePopupNavigation } from '../hooks';\nimport './TextAnnotatorPopup.css';\n\ninterface TextAnnotationPopupProps {\n\n popupNavigationMessage?: string;\n\n popup(props: TextAnnotatorPopupProps): ReactNode;\n\n}\n\nexport interface TextAnnotatorPopupProps {\n\n selected: { annotation: TextAnnotation, editable?: boolean }[];\n\n}\n\nexport const TextAnnotatorPopup: FC<TextAnnotationPopupProps> = (props) => {\n\n const { popup, popupNavigationMessage } = props;\n\n const r = useAnnotator<TextAnnotator>();\n\n const { selected, event } = useSelection<TextAnnotation>();\n const annotation = selected[0]?.annotation;\n\n const [isOpen, setOpen] = useState(selected?.length > 0);\n const handleClose = () => r?.cancelSelected();\n\n const [isFloatingFocused, setFloatingFocused] = useState(false);\n const handleFloatingFocus = () => setFloatingFocused(true);\n const handleFloatingBlur = () => setFloatingFocused(false);\n useEffect(() => {\n if (!isOpen) handleFloatingBlur();\n }, [isOpen, handleFloatingBlur]);\n\n const { refs, floatingStyles, update, context } = useFloating({\n placement: 'top',\n open: isOpen,\n onOpenChange: (open, _event, reason) => {\n setOpen(open);\n\n if (!open) {\n if (reason === 'escape-key' || reason === 'focus-out') {\n handleClose();\n }\n }\n },\n middleware: [\n offset(10),\n inline(),\n flip(),\n shift({ mainAxis: false, crossAxis: true, padding: 10 })\n ],\n whileElementsMounted: autoUpdate\n });\n\n const dismiss = useDismiss(context);\n const role = useRole(context, { role: 'dialog' });\n const { getFloatingProps } = useInteractions([dismiss, role]);\n\n const selectedKey = selected.map(a => a.annotation.id).join('-');\n useEffect(() => {\n // Ignore all selection changes except those accompanied by a user event.\n if (selected.length > 0 && event) {\n setOpen(event.type === 'pointerup' || event.type === 'keydown');\n }\n }, [selectedKey, event]);\n\n useEffect(() => {\n // Close the popup if the selection is cleared\n if (selected.length === 0 && isOpen) {\n setOpen(false);\n }\n }, [isOpen, selectedKey]);\n\n useEffect(() => {\n if (!r) return;\n\n if (isOpen && annotation?.id) {\n refs.setPositionReference({\n getBoundingClientRect: () => denormalizeRectWithOffset(\n r.state.store.getAnnotationBounds(annotation.id),\n r.element.getBoundingClientRect()\n ),\n getClientRects: () => {\n const rects = r.state.store.getAnnotationRects(annotation.id);\n const denormalizedRects = rects.map(\n rect => denormalizeRectWithOffset(rect, r.element.getBoundingClientRect())\n );\n return toDomRectList(denormalizedRects);\n }\n });\n } else {\n // Don't leave the reference depending on the previously selected annotation\n refs.setPositionReference(null);\n }\n }, [isOpen, annotation?.id, annotation?.target, r]);\n\n // Prevent text-annotator from handling the irrelevant events triggered from the popup\n const getStopEventsPropagationProps = useCallback(\n () => ({ onPointerUp: (event: PointerEvent<HTMLDivElement>) => event.stopPropagation() }),\n []\n );\n\n useEffect(() => {\n const config: MutationObserverInit = { attributes: true, childList: true, subtree: true };\n\n const mutationObserver = new MutationObserver(() => update());\n mutationObserver.observe(document.body, config);\n\n window.document.addEventListener('scroll', update, true);\n\n return () => {\n mutationObserver.disconnect();\n window.document.removeEventListener('scroll', update, true);\n };\n }, [update]);\n\n /**\n * Announce the navigation hint only on the keyboard selection,\n * because the focus isn't shifted to the popup automatically then\n */\n useAnnouncePopupNavigation({\n disabled: isFloatingFocused,\n floatingOpen: isOpen,\n message: popupNavigationMessage,\n });\n\n return isOpen && selected.length > 0 ? (\n <FloatingPortal>\n <FloatingFocusManager\n context={context}\n modal={false}\n closeOnFocusOut={true}\n initialFocus={\n /**\n * Don't shift focus to the floating element\n * when the selection performed with the keyboard\n */\n event?.type === 'keydown' ? -1 : 0\n }\n returnFocus={false}\n >\n <div\n className=\"annotation-popup text-annotation-popup not-annotatable\"\n ref={refs.setFloating}\n style={floatingStyles}\n onFocus={handleFloatingFocus}\n onBlur={handleFloatingBlur}\n {...getFloatingProps()}\n {...getStopEventsPropagationProps()}>\n {popup({ selected })}\n\n {/* It lets keyboard/sr users to know that the dialog closes when they focus out of it */}\n <button className=\"popup-close-message\" onClick={handleClose}>\n This dialog closes when you leave it.\n </button>\n </div>\n </FloatingFocusManager>\n </FloatingPortal>\n ) : null;\n\n};\n"],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AQ,IAAI;AAAA,IAAA;AAAA,EAC5D,GACC,CAAC,MAAM,CAAC;AAMgB,6BAAA;AAAA,IACzB,UAAU;AAAA,IACV,cAAc;AAAA,IACd,SAAS;AAAA,EAAA,CACV;AAED,SAAO,UAAU,SAAS,SAAS,0CAChC,gBACC,EAAA,UAAAC,kCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,OAAO;AAAA,MACP,iBAAiB;AAAA,MACjB;AAAA;AAAA;AAAA;AAAA;AAAA,SAKE,+BAAO,UAAS,YAAY,KAAK;AAAA;AAAA,MAEnC,aAAa;AAAA,MAEb,UAAAC,kCAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAU;AAAA,UACV,KAAK,KAAK;AAAA,UACV,OAAO;AAAA,UACP,SAAS;AAAA,UACT,QAAQ;AAAA,UACP,GAAG,iBAAiB;AAAA,UACpB,GAAG,8BAA8B;AAAA,UACjC,UAAA;AAAA,YAAM,MAAA,EAAE,UAAU;AAAA,kDAGlB,UAAO,EAAA,WAAU,uBAAsB,SAAS,aAAa,UAE9D,yCAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAAA,EAEJ,CAAA,IACE;AAEN;"}
@@ -1,2 +1,182 @@
1
-
1
+ const Dt = "not-annotatable", X = `.${Dt}`, mt = (t) => {
2
+ const e = t.cloneContents();
3
+ return e.querySelectorAll(X).forEach((n) => n.remove()), e;
4
+ }, re = (t, e, n = 10, o) => {
5
+ const i = e, r = document.createRange();
6
+ r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
7
+ const s = mt(r).textContent, a = document.createRange();
8
+ a.setStart(t.endContainer, t.endOffset), i === document.body ? a.setEnd(i, i.childNodes.length) : a.setEndAfter(i);
9
+ const u = mt(a).textContent;
10
+ return {
11
+ prefix: s.substring(s.length - n),
12
+ suffix: u.substring(0, n)
13
+ };
14
+ };
15
+ var V = [];
16
+ for (var dt = 0; dt < 256; ++dt)
17
+ V.push((dt + 256).toString(16).slice(1));
18
+ function Oe(t, e = 0) {
19
+ return (V[t[e + 0]] + V[t[e + 1]] + V[t[e + 2]] + V[t[e + 3]] + "-" + V[t[e + 4]] + V[t[e + 5]] + "-" + V[t[e + 6]] + V[t[e + 7]] + "-" + V[t[e + 8]] + V[t[e + 9]] + "-" + V[t[e + 10]] + V[t[e + 11]] + V[t[e + 12]] + V[t[e + 13]] + V[t[e + 14]] + V[t[e + 15]]).toLowerCase();
20
+ }
21
+ var Z, Ie = new Uint8Array(16);
22
+ function Ve() {
23
+ if (!Z && (Z = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Z))
24
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
25
+ return Z(Ie);
26
+ }
27
+ var Ue = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
28
+ const Ot = {
29
+ randomUUID: Ue
30
+ };
31
+ function Pt(t, e, n) {
32
+ if (Ot.randomUUID && !e && !t)
33
+ return Ot.randomUUID();
34
+ t = t || {};
35
+ var o = t.random || (t.rng || Ve)();
36
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Oe(o);
37
+ }
38
+ var U = [];
39
+ for (var ht = 0; ht < 256; ++ht)
40
+ U.push((ht + 256).toString(16).slice(1));
41
+ typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
42
+ const sn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
43
+ let dn = (t = 21) => {
44
+ let e = "", n = crypto.getRandomValues(new Uint8Array(t));
45
+ for (; t--; )
46
+ e += sn[n[t] & 63];
47
+ return e;
48
+ };
49
+ const hn = (t) => {
50
+ const e = JSON.stringify(t);
51
+ let n = 0;
52
+ for (let o = 0, i = e.length; o < i; o++) {
53
+ let r = e.charCodeAt(o);
54
+ n = (n << 5) - n + r, n |= 0;
55
+ }
56
+ return `${n}`;
57
+ }, jt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, fn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
58
+ const { id: o, type: i, purpose: r, value: s, created: a, modified: u, creator: h, ...p } = n;
59
+ return {
60
+ id: o || `temp-${hn(n)}`,
61
+ annotation: e,
62
+ type: i,
63
+ purpose: r,
64
+ value: s,
65
+ creator: jt(h),
66
+ created: a ? new Date(a) : void 0,
67
+ updated: u ? new Date(u) : void 0,
68
+ ...p
69
+ };
70
+ }), gn = (t) => t.map((e) => {
71
+ var n;
72
+ const { annotation: o, created: i, updated: r, ...s } = e, a = {
73
+ ...s,
74
+ created: i == null ? void 0 : i.toISOString(),
75
+ modified: r == null ? void 0 : r.toISOString()
76
+ };
77
+ return (n = a.id) != null && n.startsWith("temp-") && delete a.id, a;
78
+ });
79
+ dn();
80
+ const kn = (t, e) => ({
81
+ parse: (n) => bn(n),
82
+ serialize: (n) => vn(n, t, e)
83
+ }), pn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, mn = (t) => {
84
+ const {
85
+ id: e,
86
+ creator: n,
87
+ created: o,
88
+ modified: i,
89
+ target: r
90
+ } = t, s = Array.isArray(r) ? r : [r], a = {
91
+ creator: jt(n),
92
+ created: o ? new Date(o) : void 0,
93
+ updated: i ? new Date(i) : void 0,
94
+ annotation: e,
95
+ selector: []
96
+ };
97
+ for (const u of s) {
98
+ const p = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((d, f) => {
99
+ switch (f.type) {
100
+ case "TextQuoteSelector":
101
+ d.quote = f.exact;
102
+ break;
103
+ case "TextPositionSelector":
104
+ d.start = f.start, d.end = f.end;
105
+ break;
106
+ }
107
+ return d;
108
+ }, {});
109
+ if (pn(p))
110
+ a.selector.push({ id: u.id, ...p });
111
+ else {
112
+ const d = [
113
+ p.start ? void 0 : "TextPositionSelector",
114
+ p.quote ? void 0 : "TextQuoteSelector"
115
+ ].filter(Boolean);
116
+ return { error: Error(`Missing selector types: ${d.join(" and ")} for annotation: ${t.id}`) };
117
+ }
118
+ }
119
+ return { parsed: a };
120
+ }, bn = (t) => {
121
+ const e = t.id || Pt(), {
122
+ creator: n,
123
+ created: o,
124
+ modified: i,
125
+ body: r,
126
+ ...s
127
+ } = t, a = fn(r, e), u = mn(t);
128
+ return "error" in u ? { error: u.error } : {
129
+ parsed: {
130
+ ...s,
131
+ id: e,
132
+ bodies: a,
133
+ target: u.parsed
134
+ }
135
+ };
136
+ }, vn = (t, e, n) => {
137
+ const { bodies: o, target: i, ...r } = t, {
138
+ selector: s,
139
+ creator: a,
140
+ created: u,
141
+ updated: h,
142
+ ...p
143
+ } = i, d = s.map((f) => {
144
+ const { quote: g, start: A, end: y, range: m } = f, { prefix: l, suffix: c } = re(m, n), b = [{
145
+ type: "TextQuoteSelector",
146
+ exact: g,
147
+ prefix: l,
148
+ suffix: c
149
+ }, {
150
+ type: "TextPositionSelector",
151
+ start: A,
152
+ end: y
153
+ }];
154
+ return {
155
+ ...p,
156
+ id: f.id,
157
+ source: e,
158
+ selector: b
159
+ };
160
+ });
161
+ return {
162
+ ...r,
163
+ "@context": "http://www.w3.org/ns/anno.jsonld",
164
+ id: t.id,
165
+ type: "Annotation",
166
+ body: gn(t.bodies),
167
+ creator: a,
168
+ created: u == null ? void 0 : u.toISOString(),
169
+ modified: h == null ? void 0 : h.toISOString(),
170
+ target: d
171
+ };
172
+ };
173
+ export {
174
+ Dt as NOT_ANNOTATABLE_CLASS,
175
+ X as NOT_ANNOTATABLE_SELECTOR,
176
+ kn as W3CTextFormat,
177
+ re as getQuoteContext,
178
+ mt as getRangeAnnotatableContents,
179
+ bn as parseW3CTextAnnotation,
180
+ vn as serializeW3CTextAnnotation
181
+ };
2
182
  //# sourceMappingURL=react-text-annotator.es7.js.map