@embedpdf/plugin-annotation 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +40 -13
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +2 -1
  6. package/dist/lib/annotation-plugin.d.ts +1 -0
  7. package/dist/lib/helpers.d.ts +2 -1
  8. package/dist/lib/tools/types.d.ts +22 -10
  9. package/dist/lib/types.d.ts +13 -0
  10. package/dist/preact/index.cjs +1 -1
  11. package/dist/preact/index.cjs.map +1 -1
  12. package/dist/preact/index.js +326 -50
  13. package/dist/preact/index.js.map +1 -1
  14. package/dist/react/index.cjs +1 -1
  15. package/dist/react/index.cjs.map +1 -1
  16. package/dist/react/index.js +325 -49
  17. package/dist/react/index.js.map +1 -1
  18. package/dist/shared/components/annotation-container.d.ts +6 -2
  19. package/dist/shared/components/annotation-layer.d.ts +4 -2
  20. package/dist/shared/components/annotations.d.ts +3 -1
  21. package/dist/shared/components/types.d.ts +43 -1
  22. package/dist/shared/context/index.d.ts +1 -0
  23. package/dist/shared/context/renderer-registry.d.ts +21 -0
  24. package/dist/shared/index.d.ts +2 -0
  25. package/dist/shared-preact/components/annotation-container.d.ts +6 -2
  26. package/dist/shared-preact/components/annotation-layer.d.ts +4 -2
  27. package/dist/shared-preact/components/annotations.d.ts +3 -1
  28. package/dist/shared-preact/components/types.d.ts +43 -1
  29. package/dist/shared-preact/context/index.d.ts +1 -0
  30. package/dist/shared-preact/context/renderer-registry.d.ts +21 -0
  31. package/dist/shared-preact/index.d.ts +2 -0
  32. package/dist/shared-react/components/annotation-container.d.ts +6 -2
  33. package/dist/shared-react/components/annotation-layer.d.ts +4 -2
  34. package/dist/shared-react/components/annotations.d.ts +3 -1
  35. package/dist/shared-react/components/types.d.ts +43 -1
  36. package/dist/shared-react/context/index.d.ts +1 -0
  37. package/dist/shared-react/context/renderer-registry.d.ts +21 -0
  38. package/dist/shared-react/index.d.ts +2 -0
  39. package/dist/svelte/components/AnnotationLayer.svelte.d.ts +3 -0
  40. package/dist/svelte/components/Annotations.svelte.d.ts +3 -0
  41. package/dist/svelte/components/RendererRegistryProvider.svelte.d.ts +7 -0
  42. package/dist/svelte/components/index.d.ts +1 -0
  43. package/dist/svelte/context/index.d.ts +2 -0
  44. package/dist/svelte/context/renderer-registry.svelte.d.ts +20 -0
  45. package/dist/svelte/context/types.d.ts +33 -0
  46. package/dist/svelte/index.cjs +1 -1
  47. package/dist/svelte/index.cjs.map +1 -1
  48. package/dist/svelte/index.d.ts +2 -0
  49. package/dist/svelte/index.js +412 -241
  50. package/dist/svelte/index.js.map +1 -1
  51. package/dist/vue/components/annotation-container.vue.d.ts +1 -1
  52. package/dist/vue/components/annotation-layer.vue.d.ts +3 -0
  53. package/dist/vue/components/annotations/free-text.vue.d.ts +1 -1
  54. package/dist/vue/components/annotations/stamp.vue.d.ts +1 -1
  55. package/dist/vue/components/annotations.vue.d.ts +94 -60
  56. package/dist/vue/components/group-selection-box.vue.d.ts +1 -1
  57. package/dist/vue/components/index.d.ts +1 -0
  58. package/dist/vue/components/preview-renderer.vue.d.ts +1 -1
  59. package/dist/vue/components/renderer-registry-provider.vue.d.ts +13 -0
  60. package/dist/vue/context/index.d.ts +2 -0
  61. package/dist/vue/context/renderer-registry.d.ts +26 -0
  62. package/dist/vue/context/types.d.ts +33 -0
  63. package/dist/vue/hooks/use-annotation.d.ts +5 -5
  64. package/dist/vue/index.cjs +1 -1
  65. package/dist/vue/index.cjs.map +1 -1
  66. package/dist/vue/index.d.ts +3 -1
  67. package/dist/vue/index.js +245 -120
  68. package/dist/vue/index.js.map +1 -1
  69. package/dist/vue/types.d.ts +1 -1
  70. package/package.json +10 -10
@@ -1,8 +1,9 @@
1
- import { usePlugin, useCapability, useDocumentPermissions, useDocumentState } from "@embedpdf/core/react";
2
- import { AnnotationPlugin, initialDocumentState, patching, getAnnotationsByPageIndex, getSelectedAnnotationIds, isInk, isSquare, isCircle, isUnderline, isStrikeout, isSquiggly, isHighlight, isLine, isPolyline, isPolygon, isFreeText, isStamp, isLink } from "@embedpdf/plugin-annotation";
1
+ import { createPluginPackage } from "@embedpdf/core";
2
+ import { AnnotationPlugin, initialDocumentState, patching, getAnnotationsByPageIndex, getSelectedAnnotationIds, resolveInteractionProp, isInk, isSquare, isCircle, isUnderline, isStrikeout, isSquiggly, isHighlight, isLine, isPolyline, isPolygon, isFreeText, isStamp, isLink, AnnotationPluginPackage as AnnotationPluginPackage$1 } from "@embedpdf/plugin-annotation";
3
3
  export * from "@embedpdf/plugin-annotation";
4
- import { useState, useEffect, useRef, useMemo, useCallback, useLayoutEffect, Fragment as Fragment$1 } from "react";
5
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
4
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
+ import { createContext, useState, useCallback, useContext, useRef, useEffect, useMemo, useLayoutEffect, Fragment as Fragment$1 } from "react";
6
+ import { usePlugin, useCapability, useDocumentPermissions, useDocumentState } from "@embedpdf/core/react";
6
7
  import { boundingRectOrEmpty, PdfAnnotationBorderStyle, textAlignmentToCss, standardFontCss, PdfVerticalAlignment, ignore, PdfErrorCode, blendModeToCss, PdfBlendMode, PdfAnnotationSubtype, Rotation } from "@embedpdf/models";
7
8
  import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/react";
8
9
  import { useSelectionCapability } from "@embedpdf/plugin-selection/react";
@@ -10,6 +11,33 @@ import { useInteractionHandles, useDoublePressProps, CounterRotate } from "@embe
10
11
  const suppressContentEditableWarningProps = {
11
12
  suppressContentEditableWarning: true
12
13
  };
14
+ const RegisterContext = createContext(null);
15
+ const RenderersContext = createContext([]);
16
+ function AnnotationRendererProvider({ children }) {
17
+ const [renderers, setRenderers] = useState([]);
18
+ const register = useCallback((entries) => {
19
+ setRenderers((prev) => {
20
+ const ids = new Set(entries.map((e) => e.id));
21
+ return [...prev.filter((r) => !ids.has(r.id)), ...entries];
22
+ });
23
+ return () => setRenderers((prev) => prev.filter((r) => !entries.some((e) => e.id === r.id)));
24
+ }, []);
25
+ return /* @__PURE__ */ jsx(RegisterContext.Provider, { value: register, children: /* @__PURE__ */ jsx(RenderersContext.Provider, { value: renderers, children }) });
26
+ }
27
+ function useRegisterRenderers(renderers) {
28
+ const register = useContext(RegisterContext);
29
+ const renderersRef = useRef(renderers);
30
+ useEffect(() => {
31
+ if (!register) return;
32
+ return register(renderersRef.current);
33
+ }, [register]);
34
+ }
35
+ function useRegisteredRenderers() {
36
+ return useContext(RenderersContext);
37
+ }
38
+ function useRendererRegistry() {
39
+ return useContext(RegisterContext);
40
+ }
13
41
  const useAnnotationPlugin = () => usePlugin(AnnotationPlugin.id);
14
42
  const useAnnotationCapability = () => useCapability(AnnotationPlugin.id);
15
43
  const useAnnotation = (documentId) => {
@@ -56,6 +84,9 @@ function AnnotationContainer({
56
84
  vertexUI,
57
85
  selectionOutlineColor = "#007ACC",
58
86
  customAnnotationRenderer,
87
+ // Destructure props that shouldn't be passed to DOM elements
88
+ groupSelectionMenu: _groupSelectionMenu,
89
+ annotationRenderers: _annotationRenderers,
59
90
  ...props
60
91
  }) {
61
92
  const [preview, setPreview] = useState(trackedAnnotation.object);
@@ -310,9 +341,12 @@ function GroupSelectionBox({
310
341
  groupSelectionMenu
311
342
  }) {
312
343
  const { plugin } = useAnnotationPlugin();
344
+ const { canModifyAnnotations } = useDocumentPermissions(documentId);
313
345
  const gestureBaseRef = useRef(null);
314
346
  const isDraggingRef = useRef(false);
315
347
  const isResizingRef = useRef(false);
348
+ const effectiveIsDraggable = canModifyAnnotations && isDraggable;
349
+ const effectiveIsResizable = canModifyAnnotations && isResizable;
316
350
  const groupBox = useMemo(() => {
317
351
  const rects = selectedAnnotations.map((ta) => ta.object.rect);
318
352
  return boundingRectOrEmpty(rects);
@@ -331,7 +365,7 @@ function GroupSelectionBox({
331
365
  const transformType = event.transformData.type;
332
366
  const isMove = transformType === "move";
333
367
  const isResize = transformType === "resize";
334
- if (isMove && !isDraggable) return;
368
+ if (isMove && !effectiveIsDraggable) return;
335
369
  if (event.state === "start") {
336
370
  gestureBaseRef.current = groupBox;
337
371
  if (isMove) {
@@ -380,7 +414,15 @@ function GroupSelectionBox({
380
414
  }
381
415
  }
382
416
  },
383
- [plugin, documentId, pageWidth, pageHeight, groupBox, isDraggable, selectedAnnotations]
417
+ [
418
+ plugin,
419
+ documentId,
420
+ pageWidth,
421
+ pageHeight,
422
+ groupBox,
423
+ effectiveIsDraggable,
424
+ selectedAnnotations
425
+ ]
384
426
  );
385
427
  const HANDLE_COLOR = (resizeUI == null ? void 0 : resizeUI.color) ?? "#007ACC";
386
428
  const HANDLE_SIZE = (resizeUI == null ? void 0 : resizeUI.size) ?? 12;
@@ -418,7 +460,7 @@ function GroupSelectionBox({
418
460
  /* @__PURE__ */ jsx(
419
461
  "div",
420
462
  {
421
- ...isDraggable ? dragProps : {
463
+ ...effectiveIsDraggable ? dragProps : {
422
464
  onPointerDown: (e) => e.stopPropagation()
423
465
  },
424
466
  style: {
@@ -429,11 +471,11 @@ function GroupSelectionBox({
429
471
  height: previewGroupBox.size.height * scale,
430
472
  outline: `2px dashed ${selectionOutlineColor}`,
431
473
  outlineOffset: outlineOffset - 1,
432
- cursor: isDraggable ? "move" : "default",
474
+ cursor: effectiveIsDraggable ? "move" : "default",
433
475
  touchAction: "none",
434
476
  zIndex
435
477
  },
436
- children: isResizable && resize.map(
478
+ children: effectiveIsResizable && resize.map(
437
479
  ({ key, ...hProps }) => (resizeUI == null ? void 0 : resizeUI.component) ? resizeUI.component({
438
480
  key,
439
481
  ...hProps,
@@ -1539,14 +1581,34 @@ function Annotations(annotationsProps) {
1539
1581
  if (selectedAnnotationsOnPage.length < 2) return false;
1540
1582
  return selectedAnnotationsOnPage.every((ta) => {
1541
1583
  const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(ta.object);
1542
- return (tool == null ? void 0 : tool.interaction.isGroupDraggable) ?? (tool == null ? void 0 : tool.interaction.isDraggable) ?? true;
1584
+ const groupDraggable = resolveInteractionProp(
1585
+ tool == null ? void 0 : tool.interaction.isGroupDraggable,
1586
+ ta.object,
1587
+ true
1588
+ );
1589
+ const singleDraggable = resolveInteractionProp(
1590
+ tool == null ? void 0 : tool.interaction.isDraggable,
1591
+ ta.object,
1592
+ true
1593
+ );
1594
+ return (tool == null ? void 0 : tool.interaction.isGroupDraggable) !== void 0 ? groupDraggable : singleDraggable;
1543
1595
  });
1544
1596
  }, [selectedAnnotationsOnPage, annotationProvides]);
1545
1597
  const areAllSelectedResizable = useMemo(() => {
1546
1598
  if (selectedAnnotationsOnPage.length < 2) return false;
1547
1599
  return selectedAnnotationsOnPage.every((ta) => {
1548
1600
  const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(ta.object);
1549
- return (tool == null ? void 0 : tool.interaction.isGroupResizable) ?? (tool == null ? void 0 : tool.interaction.isResizable) ?? true;
1601
+ const groupResizable = resolveInteractionProp(
1602
+ tool == null ? void 0 : tool.interaction.isGroupResizable,
1603
+ ta.object,
1604
+ true
1605
+ );
1606
+ const singleResizable = resolveInteractionProp(
1607
+ tool == null ? void 0 : tool.interaction.isResizable,
1608
+ ta.object,
1609
+ true
1610
+ );
1611
+ return (tool == null ? void 0 : tool.interaction.isGroupResizable) !== void 0 ? groupResizable : singleResizable;
1550
1612
  });
1551
1613
  }, [selectedAnnotationsOnPage, annotationProvides]);
1552
1614
  const allSelectedOnSamePage = useMemo(() => {
@@ -1559,6 +1621,47 @@ function Annotations(annotationsProps) {
1559
1621
  const isSelected = allSelectedIds.includes(annotation.object.id);
1560
1622
  const isEditing = editingId === annotation.object.id;
1561
1623
  const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(annotation.object);
1624
+ for (const renderer of annotationsProps.annotationRenderers ?? []) {
1625
+ const element = renderer.tryRender(annotation, {
1626
+ isSelected,
1627
+ scale,
1628
+ pageIndex,
1629
+ onClick: (e) => handleClick(e, annotation)
1630
+ });
1631
+ if (element) {
1632
+ return /* @__PURE__ */ jsx(
1633
+ AnnotationContainer,
1634
+ {
1635
+ trackedAnnotation: annotation,
1636
+ isSelected,
1637
+ isMultiSelected,
1638
+ isDraggable: resolveInteractionProp(
1639
+ tool == null ? void 0 : tool.interaction.isDraggable,
1640
+ annotation.object,
1641
+ false
1642
+ ),
1643
+ isResizable: resolveInteractionProp(
1644
+ tool == null ? void 0 : tool.interaction.isResizable,
1645
+ annotation.object,
1646
+ false
1647
+ ),
1648
+ lockAspectRatio: resolveInteractionProp(
1649
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1650
+ annotation.object,
1651
+ false
1652
+ ),
1653
+ selectionMenu,
1654
+ onSelect: (e) => handleClick(e, annotation),
1655
+ style: {
1656
+ mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1657
+ },
1658
+ ...annotationsProps,
1659
+ children: () => element
1660
+ },
1661
+ annotation.object.id
1662
+ );
1663
+ }
1664
+ }
1562
1665
  if (isInk(annotation)) {
1563
1666
  return /* @__PURE__ */ jsx(
1564
1667
  AnnotationContainer,
@@ -1566,9 +1669,21 @@ function Annotations(annotationsProps) {
1566
1669
  trackedAnnotation: annotation,
1567
1670
  isSelected,
1568
1671
  isMultiSelected,
1569
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1570
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1571
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1672
+ isDraggable: resolveInteractionProp(
1673
+ tool == null ? void 0 : tool.interaction.isDraggable,
1674
+ annotation.object,
1675
+ true
1676
+ ),
1677
+ isResizable: resolveInteractionProp(
1678
+ tool == null ? void 0 : tool.interaction.isResizable,
1679
+ annotation.object,
1680
+ true
1681
+ ),
1682
+ lockAspectRatio: resolveInteractionProp(
1683
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1684
+ annotation.object,
1685
+ false
1686
+ ),
1572
1687
  selectionMenu,
1573
1688
  onSelect: (e) => handleClick(e, annotation),
1574
1689
  style: {
@@ -1595,9 +1710,21 @@ function Annotations(annotationsProps) {
1595
1710
  trackedAnnotation: annotation,
1596
1711
  isSelected,
1597
1712
  isMultiSelected,
1598
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1599
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1600
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1713
+ isDraggable: resolveInteractionProp(
1714
+ tool == null ? void 0 : tool.interaction.isDraggable,
1715
+ annotation.object,
1716
+ true
1717
+ ),
1718
+ isResizable: resolveInteractionProp(
1719
+ tool == null ? void 0 : tool.interaction.isResizable,
1720
+ annotation.object,
1721
+ true
1722
+ ),
1723
+ lockAspectRatio: resolveInteractionProp(
1724
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1725
+ annotation.object,
1726
+ false
1727
+ ),
1601
1728
  selectionMenu,
1602
1729
  onSelect: (e) => handleClick(e, annotation),
1603
1730
  style: {
@@ -1624,9 +1751,21 @@ function Annotations(annotationsProps) {
1624
1751
  trackedAnnotation: annotation,
1625
1752
  isSelected,
1626
1753
  isMultiSelected,
1627
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1628
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1629
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1754
+ isDraggable: resolveInteractionProp(
1755
+ tool == null ? void 0 : tool.interaction.isDraggable,
1756
+ annotation.object,
1757
+ true
1758
+ ),
1759
+ isResizable: resolveInteractionProp(
1760
+ tool == null ? void 0 : tool.interaction.isResizable,
1761
+ annotation.object,
1762
+ true
1763
+ ),
1764
+ lockAspectRatio: resolveInteractionProp(
1765
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1766
+ annotation.object,
1767
+ false
1768
+ ),
1630
1769
  selectionMenu,
1631
1770
  onSelect: (e) => handleClick(e, annotation),
1632
1771
  style: {
@@ -1653,9 +1792,21 @@ function Annotations(annotationsProps) {
1653
1792
  trackedAnnotation: annotation,
1654
1793
  isSelected,
1655
1794
  isMultiSelected,
1656
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? false,
1657
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1658
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1795
+ isDraggable: resolveInteractionProp(
1796
+ tool == null ? void 0 : tool.interaction.isDraggable,
1797
+ annotation.object,
1798
+ false
1799
+ ),
1800
+ isResizable: resolveInteractionProp(
1801
+ tool == null ? void 0 : tool.interaction.isResizable,
1802
+ annotation.object,
1803
+ false
1804
+ ),
1805
+ lockAspectRatio: resolveInteractionProp(
1806
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1807
+ annotation.object,
1808
+ false
1809
+ ),
1659
1810
  selectionMenu,
1660
1811
  onSelect: (e) => handleClick(e, annotation),
1661
1812
  zIndex: 0,
@@ -1675,9 +1826,21 @@ function Annotations(annotationsProps) {
1675
1826
  trackedAnnotation: annotation,
1676
1827
  isSelected,
1677
1828
  isMultiSelected,
1678
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? false,
1679
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1680
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1829
+ isDraggable: resolveInteractionProp(
1830
+ tool == null ? void 0 : tool.interaction.isDraggable,
1831
+ annotation.object,
1832
+ false
1833
+ ),
1834
+ isResizable: resolveInteractionProp(
1835
+ tool == null ? void 0 : tool.interaction.isResizable,
1836
+ annotation.object,
1837
+ false
1838
+ ),
1839
+ lockAspectRatio: resolveInteractionProp(
1840
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1841
+ annotation.object,
1842
+ false
1843
+ ),
1681
1844
  selectionMenu,
1682
1845
  onSelect: (e) => handleClick(e, annotation),
1683
1846
  zIndex: 0,
@@ -1697,9 +1860,21 @@ function Annotations(annotationsProps) {
1697
1860
  trackedAnnotation: annotation,
1698
1861
  isSelected,
1699
1862
  isMultiSelected,
1700
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? false,
1701
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1702
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1863
+ isDraggable: resolveInteractionProp(
1864
+ tool == null ? void 0 : tool.interaction.isDraggable,
1865
+ annotation.object,
1866
+ false
1867
+ ),
1868
+ isResizable: resolveInteractionProp(
1869
+ tool == null ? void 0 : tool.interaction.isResizable,
1870
+ annotation.object,
1871
+ false
1872
+ ),
1873
+ lockAspectRatio: resolveInteractionProp(
1874
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1875
+ annotation.object,
1876
+ false
1877
+ ),
1703
1878
  selectionMenu,
1704
1879
  onSelect: (e) => handleClick(e, annotation),
1705
1880
  zIndex: 0,
@@ -1719,9 +1894,21 @@ function Annotations(annotationsProps) {
1719
1894
  trackedAnnotation: annotation,
1720
1895
  isSelected,
1721
1896
  isMultiSelected,
1722
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? false,
1723
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1724
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1897
+ isDraggable: resolveInteractionProp(
1898
+ tool == null ? void 0 : tool.interaction.isDraggable,
1899
+ annotation.object,
1900
+ false
1901
+ ),
1902
+ isResizable: resolveInteractionProp(
1903
+ tool == null ? void 0 : tool.interaction.isResizable,
1904
+ annotation.object,
1905
+ false
1906
+ ),
1907
+ lockAspectRatio: resolveInteractionProp(
1908
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1909
+ annotation.object,
1910
+ false
1911
+ ),
1725
1912
  selectionMenu,
1726
1913
  onSelect: (e) => handleClick(e, annotation),
1727
1914
  zIndex: 0,
@@ -1741,9 +1928,21 @@ function Annotations(annotationsProps) {
1741
1928
  trackedAnnotation: annotation,
1742
1929
  isSelected,
1743
1930
  isMultiSelected,
1744
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1745
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1746
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1931
+ isDraggable: resolveInteractionProp(
1932
+ tool == null ? void 0 : tool.interaction.isDraggable,
1933
+ annotation.object,
1934
+ true
1935
+ ),
1936
+ isResizable: resolveInteractionProp(
1937
+ tool == null ? void 0 : tool.interaction.isResizable,
1938
+ annotation.object,
1939
+ false
1940
+ ),
1941
+ lockAspectRatio: resolveInteractionProp(
1942
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1943
+ annotation.object,
1944
+ false
1945
+ ),
1747
1946
  selectionMenu,
1748
1947
  onSelect: (e) => handleClick(e, annotation),
1749
1948
  vertexConfig: {
@@ -1785,9 +1984,21 @@ function Annotations(annotationsProps) {
1785
1984
  trackedAnnotation: annotation,
1786
1985
  isSelected,
1787
1986
  isMultiSelected,
1788
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1789
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1790
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1987
+ isDraggable: resolveInteractionProp(
1988
+ tool == null ? void 0 : tool.interaction.isDraggable,
1989
+ annotation.object,
1990
+ true
1991
+ ),
1992
+ isResizable: resolveInteractionProp(
1993
+ tool == null ? void 0 : tool.interaction.isResizable,
1994
+ annotation.object,
1995
+ false
1996
+ ),
1997
+ lockAspectRatio: resolveInteractionProp(
1998
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
1999
+ annotation.object,
2000
+ false
2001
+ ),
1791
2002
  selectionMenu,
1792
2003
  onSelect: (e) => handleClick(e, annotation),
1793
2004
  vertexConfig: {
@@ -1823,9 +2034,21 @@ function Annotations(annotationsProps) {
1823
2034
  trackedAnnotation: annotation,
1824
2035
  isSelected,
1825
2036
  isMultiSelected,
1826
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1827
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1828
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
2037
+ isDraggable: resolveInteractionProp(
2038
+ tool == null ? void 0 : tool.interaction.isDraggable,
2039
+ annotation.object,
2040
+ true
2041
+ ),
2042
+ isResizable: resolveInteractionProp(
2043
+ tool == null ? void 0 : tool.interaction.isResizable,
2044
+ annotation.object,
2045
+ false
2046
+ ),
2047
+ lockAspectRatio: resolveInteractionProp(
2048
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
2049
+ annotation.object,
2050
+ false
2051
+ ),
1829
2052
  selectionMenu,
1830
2053
  onSelect: (e) => handleClick(e, annotation),
1831
2054
  vertexConfig: {
@@ -1861,9 +2084,17 @@ function Annotations(annotationsProps) {
1861
2084
  trackedAnnotation: annotation,
1862
2085
  isSelected,
1863
2086
  isMultiSelected,
1864
- isDraggable: ((tool == null ? void 0 : tool.interaction.isDraggable) ?? true) && !isEditing,
1865
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1866
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
2087
+ isDraggable: resolveInteractionProp(tool == null ? void 0 : tool.interaction.isDraggable, annotation.object, true) && !isEditing,
2088
+ isResizable: resolveInteractionProp(
2089
+ tool == null ? void 0 : tool.interaction.isResizable,
2090
+ annotation.object,
2091
+ true
2092
+ ),
2093
+ lockAspectRatio: resolveInteractionProp(
2094
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
2095
+ annotation.object,
2096
+ false
2097
+ ),
1867
2098
  selectionMenu,
1868
2099
  onSelect: (e) => handleClick(e, annotation),
1869
2100
  style: {
@@ -1899,9 +2130,21 @@ function Annotations(annotationsProps) {
1899
2130
  trackedAnnotation: annotation,
1900
2131
  isSelected,
1901
2132
  isMultiSelected,
1902
- isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1903
- isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1904
- lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
2133
+ isDraggable: resolveInteractionProp(
2134
+ tool == null ? void 0 : tool.interaction.isDraggable,
2135
+ annotation.object,
2136
+ true
2137
+ ),
2138
+ isResizable: resolveInteractionProp(
2139
+ tool == null ? void 0 : tool.interaction.isResizable,
2140
+ annotation.object,
2141
+ true
2142
+ ),
2143
+ lockAspectRatio: resolveInteractionProp(
2144
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
2145
+ annotation.object,
2146
+ false
2147
+ ),
1905
2148
  selectionMenu,
1906
2149
  onSelect: (e) => handleClick(e, annotation),
1907
2150
  style: {
@@ -2208,6 +2451,7 @@ function AnnotationLayer({
2208
2451
  vertexUI,
2209
2452
  selectionOutlineColor,
2210
2453
  customAnnotationRenderer,
2454
+ annotationRenderers,
2211
2455
  ...props
2212
2456
  }) {
2213
2457
  var _a, _b, _c, _d;
@@ -2215,6 +2459,16 @@ function AnnotationLayer({
2215
2459
  const page = (_b = (_a = documentState == null ? void 0 : documentState.document) == null ? void 0 : _a.pages) == null ? void 0 : _b[pageIndex];
2216
2460
  const width = ((_c = page == null ? void 0 : page.size) == null ? void 0 : _c.width) ?? 0;
2217
2461
  const height = ((_d = page == null ? void 0 : page.size) == null ? void 0 : _d.height) ?? 0;
2462
+ const contextRenderers = useRegisteredRenderers();
2463
+ const allRenderers = useMemo(() => {
2464
+ const merged = [...contextRenderers];
2465
+ for (const renderer of annotationRenderers ?? []) {
2466
+ const idx = merged.findIndex((r) => r.id === renderer.id);
2467
+ if (idx >= 0) merged[idx] = renderer;
2468
+ else merged.push(renderer);
2469
+ }
2470
+ return merged;
2471
+ }, [contextRenderers, annotationRenderers]);
2218
2472
  const actualScale = useMemo(() => {
2219
2473
  if (overrideScale !== void 0) return overrideScale;
2220
2474
  return (documentState == null ? void 0 : documentState.scale) ?? 1;
@@ -2245,7 +2499,8 @@ function AnnotationLayer({
2245
2499
  resizeUI,
2246
2500
  vertexUI,
2247
2501
  selectionOutlineColor,
2248
- customAnnotationRenderer
2502
+ customAnnotationRenderer,
2503
+ annotationRenderers: allRenderers
2249
2504
  }
2250
2505
  ),
2251
2506
  /* @__PURE__ */ jsx(TextMarkup, { documentId, pageIndex, scale: actualScale }),
@@ -2254,11 +2509,32 @@ function AnnotationLayer({
2254
2509
  }
2255
2510
  );
2256
2511
  }
2512
+ function createRenderer(entry) {
2513
+ return {
2514
+ id: entry.id,
2515
+ tryRender: (annotation, props) => {
2516
+ if (entry.matches(annotation.object)) {
2517
+ return entry.render({
2518
+ ...props,
2519
+ annotation
2520
+ });
2521
+ }
2522
+ return null;
2523
+ }
2524
+ };
2525
+ }
2526
+ const AnnotationPluginPackage = createPluginPackage(AnnotationPluginPackage$1).addWrapper(AnnotationRendererProvider).build();
2257
2527
  export {
2258
2528
  AnnotationLayer,
2529
+ AnnotationPluginPackage,
2530
+ AnnotationRendererProvider,
2259
2531
  GroupSelectionBox,
2532
+ createRenderer,
2260
2533
  useAnnotation,
2261
2534
  useAnnotationCapability,
2262
- useAnnotationPlugin
2535
+ useAnnotationPlugin,
2536
+ useRegisterRenderers,
2537
+ useRegisteredRenderers,
2538
+ useRendererRegistry
2263
2539
  };
2264
2540
  //# sourceMappingURL=index.js.map