@embedpdf/plugin-annotation 1.2.0 → 1.3.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 (31) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +115 -53
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/tools/default-tools.d.ts +42 -14
  6. package/dist/lib/tools/types.d.ts +5 -1
  7. package/dist/preact/index.cjs +1 -1
  8. package/dist/preact/index.cjs.map +1 -1
  9. package/dist/preact/index.js +78 -41
  10. package/dist/preact/index.js.map +1 -1
  11. package/dist/react/index.cjs +1 -1
  12. package/dist/react/index.cjs.map +1 -1
  13. package/dist/react/index.js +78 -41
  14. package/dist/react/index.js.map +1 -1
  15. package/dist/shared-preact/components/annotation-container.d.ts +4 -2
  16. package/dist/shared-preact/components/annotation-layer.d.ts +5 -2
  17. package/dist/shared-preact/components/annotations.d.ts +3 -1
  18. package/dist/shared-preact/components/text-markup/highlight.d.ts +3 -3
  19. package/dist/shared-preact/components/text-markup/squiggly.d.ts +3 -3
  20. package/dist/shared-preact/components/text-markup/strikeout.d.ts +3 -3
  21. package/dist/shared-preact/components/text-markup/underline.d.ts +3 -3
  22. package/dist/shared-preact/types.d.ts +17 -0
  23. package/dist/shared-react/components/annotation-container.d.ts +4 -2
  24. package/dist/shared-react/components/annotation-layer.d.ts +5 -2
  25. package/dist/shared-react/components/annotations.d.ts +3 -1
  26. package/dist/shared-react/components/text-markup/highlight.d.ts +3 -3
  27. package/dist/shared-react/components/text-markup/squiggly.d.ts +3 -3
  28. package/dist/shared-react/components/text-markup/strikeout.d.ts +3 -3
  29. package/dist/shared-react/components/text-markup/underline.d.ts +3 -3
  30. package/dist/shared-react/types.d.ts +17 -0
  31. package/package.json +12 -11
@@ -29,10 +29,12 @@ function AnnotationContainer({
29
29
  selectionMenu,
30
30
  outlineOffset = 1,
31
31
  onDoubleClick,
32
+ onSelect,
32
33
  zIndex = 1,
33
34
  resizeUI,
34
35
  vertexUI,
35
36
  selectionOutlineColor = "#007ACC",
37
+ customAnnotationRenderer,
36
38
  ...props
37
39
  }) {
38
40
  const [preview, setPreview] = useState(trackedAnnotation.object);
@@ -121,7 +123,22 @@ function AnnotationContainer({
121
123
  },
122
124
  ...props,
123
125
  children: [
124
- typeof children === "function" ? children(currentObject) : children,
126
+ (() => {
127
+ const customRender = customAnnotationRenderer == null ? void 0 : customAnnotationRenderer({
128
+ annotation: currentObject,
129
+ isSelected,
130
+ scale,
131
+ rotation,
132
+ pageWidth,
133
+ pageHeight,
134
+ pageIndex,
135
+ onSelect
136
+ });
137
+ if (customRender !== null && customRender !== void 0) {
138
+ return customRender;
139
+ }
140
+ return typeof children === "function" ? children(currentObject) : children;
141
+ })(),
125
142
  isSelected && isResizable && resize.map(
126
143
  ({ key, ...hProps }) => (resizeUI == null ? void 0 : resizeUI.component) ? resizeUI.component({
127
144
  key,
@@ -184,8 +201,7 @@ function Highlight({
184
201
  rect,
185
202
  scale,
186
203
  onClick,
187
- style,
188
- ...props
204
+ style
189
205
  }) {
190
206
  return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((b, i) => /* @__PURE__ */ jsx(
191
207
  "div",
@@ -204,8 +220,7 @@ function Highlight({
204
220
  cursor: onClick ? "pointer" : "default",
205
221
  zIndex: onClick ? 1 : void 0,
206
222
  ...style
207
- },
208
- ...props
223
+ }
209
224
  },
210
225
  i
211
226
  )) });
@@ -217,8 +232,7 @@ function Underline({
217
232
  rect,
218
233
  scale,
219
234
  onClick,
220
- style,
221
- ...props
235
+ style
222
236
  }) {
223
237
  const thickness = 2 * scale;
224
238
  return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
@@ -238,7 +252,6 @@ function Underline({
238
252
  zIndex: onClick ? 1 : 0,
239
253
  ...style
240
254
  },
241
- ...props,
242
255
  children: /* @__PURE__ */ jsx(
243
256
  "div",
244
257
  {
@@ -265,8 +278,7 @@ function Strikeout({
265
278
  rect,
266
279
  scale,
267
280
  onClick,
268
- style,
269
- ...props
281
+ style
270
282
  }) {
271
283
  const thickness = 2 * scale;
272
284
  return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
@@ -286,7 +298,6 @@ function Strikeout({
286
298
  zIndex: onClick ? 1 : 0,
287
299
  ...style
288
300
  },
289
- ...props,
290
301
  children: /* @__PURE__ */ jsx(
291
302
  "div",
292
303
  {
@@ -314,8 +325,7 @@ function Squiggly({
314
325
  rect,
315
326
  scale,
316
327
  onClick,
317
- style,
318
- ...props
328
+ style
319
329
  }) {
320
330
  const amplitude = 2 * scale;
321
331
  const period = 6 * scale;
@@ -341,7 +351,6 @@ function Squiggly({
341
351
  zIndex: onClick ? 1 : 0,
342
352
  ...style
343
353
  },
344
- ...props,
345
354
  children: /* @__PURE__ */ jsx(
346
355
  "div",
347
356
  {
@@ -1022,6 +1031,7 @@ function RenderAnnotation({
1022
1031
  style: {
1023
1032
  width: "100%",
1024
1033
  height: "100%",
1034
+ display: "block",
1025
1035
  ...style || {}
1026
1036
  }
1027
1037
  }
@@ -1036,7 +1046,8 @@ function Stamp({ isSelected, annotation, pageIndex, scale, onClick }) {
1036
1046
  width: "100%",
1037
1047
  height: "100%",
1038
1048
  zIndex: 2,
1039
- pointerEvents: isSelected ? "none" : "auto"
1049
+ pointerEvents: isSelected ? "none" : "auto",
1050
+ cursor: "pointer"
1040
1051
  },
1041
1052
  onPointerDown: onClick,
1042
1053
  onTouchStart: onClick,
@@ -1097,15 +1108,18 @@ function Annotations(annotationsProps) {
1097
1108
  return /* @__PURE__ */ jsx(Fragment, { children: annotations.map((annotation) => {
1098
1109
  const isSelected = (selectionState == null ? void 0 : selectionState.object.id) === annotation.object.id;
1099
1110
  const isEditing = editingId === annotation.object.id;
1111
+ const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(annotation.object);
1100
1112
  if (isInk(annotation)) {
1101
1113
  return /* @__PURE__ */ jsx(
1102
1114
  AnnotationContainer,
1103
1115
  {
1104
1116
  trackedAnnotation: annotation,
1105
1117
  isSelected,
1106
- isDraggable: true,
1107
- isResizable: true,
1118
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1119
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1120
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1108
1121
  selectionMenu,
1122
+ onSelect: (e) => handleClick(e, annotation),
1109
1123
  style: {
1110
1124
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1111
1125
  },
@@ -1129,9 +1143,11 @@ function Annotations(annotationsProps) {
1129
1143
  {
1130
1144
  trackedAnnotation: annotation,
1131
1145
  isSelected,
1132
- isDraggable: true,
1133
- isResizable: true,
1146
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1147
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1148
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1134
1149
  selectionMenu,
1150
+ onSelect: (e) => handleClick(e, annotation),
1135
1151
  style: {
1136
1152
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1137
1153
  },
@@ -1155,9 +1171,11 @@ function Annotations(annotationsProps) {
1155
1171
  {
1156
1172
  trackedAnnotation: annotation,
1157
1173
  isSelected,
1158
- isDraggable: true,
1159
- isResizable: true,
1174
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1175
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1176
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1160
1177
  selectionMenu,
1178
+ onSelect: (e) => handleClick(e, annotation),
1161
1179
  style: {
1162
1180
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1163
1181
  },
@@ -1181,9 +1199,11 @@ function Annotations(annotationsProps) {
1181
1199
  {
1182
1200
  trackedAnnotation: annotation,
1183
1201
  isSelected,
1184
- isDraggable: false,
1185
- isResizable: false,
1202
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? false,
1203
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1204
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1186
1205
  selectionMenu,
1206
+ onSelect: (e) => handleClick(e, annotation),
1187
1207
  zIndex: 0,
1188
1208
  style: {
1189
1209
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
@@ -1200,9 +1220,11 @@ function Annotations(annotationsProps) {
1200
1220
  {
1201
1221
  trackedAnnotation: annotation,
1202
1222
  isSelected,
1203
- isDraggable: false,
1204
- isResizable: false,
1223
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? false,
1224
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1225
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1205
1226
  selectionMenu,
1227
+ onSelect: (e) => handleClick(e, annotation),
1206
1228
  zIndex: 0,
1207
1229
  style: {
1208
1230
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
@@ -1219,9 +1241,11 @@ function Annotations(annotationsProps) {
1219
1241
  {
1220
1242
  trackedAnnotation: annotation,
1221
1243
  isSelected,
1222
- isDraggable: false,
1223
- isResizable: false,
1244
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? false,
1245
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1246
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1224
1247
  selectionMenu,
1248
+ onSelect: (e) => handleClick(e, annotation),
1225
1249
  zIndex: 0,
1226
1250
  style: {
1227
1251
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
@@ -1238,9 +1262,11 @@ function Annotations(annotationsProps) {
1238
1262
  {
1239
1263
  trackedAnnotation: annotation,
1240
1264
  isSelected,
1241
- isDraggable: false,
1242
- isResizable: false,
1265
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? false,
1266
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1267
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1243
1268
  selectionMenu,
1269
+ onSelect: (e) => handleClick(e, annotation),
1244
1270
  zIndex: 0,
1245
1271
  style: {
1246
1272
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Multiply)
@@ -1257,9 +1283,11 @@ function Annotations(annotationsProps) {
1257
1283
  {
1258
1284
  trackedAnnotation: annotation,
1259
1285
  isSelected,
1260
- isDraggable: true,
1261
- isResizable: false,
1286
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1287
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1288
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1262
1289
  selectionMenu,
1290
+ onSelect: (e) => handleClick(e, annotation),
1263
1291
  vertexConfig: {
1264
1292
  extractVertices: (annotation2) => [
1265
1293
  annotation2.linePoints.start,
@@ -1298,9 +1326,11 @@ function Annotations(annotationsProps) {
1298
1326
  {
1299
1327
  trackedAnnotation: annotation,
1300
1328
  isSelected,
1301
- isDraggable: true,
1302
- isResizable: false,
1329
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1330
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1331
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1303
1332
  selectionMenu,
1333
+ onSelect: (e) => handleClick(e, annotation),
1304
1334
  vertexConfig: {
1305
1335
  extractVertices: (annotation2) => annotation2.vertices,
1306
1336
  transformAnnotation: (annotation2, vertices) => {
@@ -1333,9 +1363,11 @@ function Annotations(annotationsProps) {
1333
1363
  {
1334
1364
  trackedAnnotation: annotation,
1335
1365
  isSelected,
1336
- isDraggable: true,
1337
- isResizable: false,
1366
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1367
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? false,
1368
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1338
1369
  selectionMenu,
1370
+ onSelect: (e) => handleClick(e, annotation),
1339
1371
  vertexConfig: {
1340
1372
  extractVertices: (annotation2) => annotation2.vertices,
1341
1373
  transformAnnotation: (annotation2, vertices) => {
@@ -1368,9 +1400,11 @@ function Annotations(annotationsProps) {
1368
1400
  {
1369
1401
  trackedAnnotation: annotation,
1370
1402
  isSelected,
1371
- isDraggable: !isEditing,
1372
- isResizable: true,
1403
+ isDraggable: ((tool == null ? void 0 : tool.interaction.isDraggable) ?? true) && !isEditing,
1404
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1405
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1373
1406
  selectionMenu,
1407
+ onSelect: (e) => handleClick(e, annotation),
1374
1408
  style: {
1375
1409
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1376
1410
  },
@@ -1403,10 +1437,11 @@ function Annotations(annotationsProps) {
1403
1437
  {
1404
1438
  trackedAnnotation: annotation,
1405
1439
  isSelected,
1406
- isDraggable: true,
1407
- isResizable: true,
1440
+ isDraggable: (tool == null ? void 0 : tool.interaction.isDraggable) ?? true,
1441
+ isResizable: (tool == null ? void 0 : tool.interaction.isResizable) ?? true,
1442
+ lockAspectRatio: (tool == null ? void 0 : tool.interaction.lockAspectRatio) ?? false,
1408
1443
  selectionMenu,
1409
- lockAspectRatio: true,
1444
+ onSelect: (e) => handleClick(e, annotation),
1410
1445
  style: {
1411
1446
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1412
1447
  },
@@ -1664,6 +1699,7 @@ function AnnotationLayer({
1664
1699
  pageHeight,
1665
1700
  rotation,
1666
1701
  selectionOutlineColor,
1702
+ customAnnotationRenderer,
1667
1703
  ...props
1668
1704
  }) {
1669
1705
  return /* @__PURE__ */ jsxs(
@@ -1685,7 +1721,8 @@ function AnnotationLayer({
1685
1721
  pageHeight,
1686
1722
  resizeUI,
1687
1723
  vertexUI,
1688
- selectionOutlineColor
1724
+ selectionOutlineColor,
1725
+ customAnnotationRenderer
1689
1726
  }
1690
1727
  ),
1691
1728
  /* @__PURE__ */ jsx(TextMarkup, { pageIndex, scale }),