@embedpdf/plugin-annotation 2.3.0 → 2.4.1

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