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