@embedpdf/plugin-annotation 1.2.1 → 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 +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
@@ -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
  }
@@ -1098,15 +1108,18 @@ function Annotations(annotationsProps) {
1098
1108
  return /* @__PURE__ */ jsx(Fragment, { children: annotations.map((annotation) => {
1099
1109
  const isSelected = (selectionState == null ? void 0 : selectionState.object.id) === annotation.object.id;
1100
1110
  const isEditing = editingId === annotation.object.id;
1111
+ const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(annotation.object);
1101
1112
  if (isInk(annotation)) {
1102
1113
  return /* @__PURE__ */ jsx(
1103
1114
  AnnotationContainer,
1104
1115
  {
1105
1116
  trackedAnnotation: annotation,
1106
1117
  isSelected,
1107
- isDraggable: true,
1108
- 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,
1109
1121
  selectionMenu,
1122
+ onSelect: (e) => handleClick(e, annotation),
1110
1123
  style: {
1111
1124
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1112
1125
  },
@@ -1130,9 +1143,11 @@ function Annotations(annotationsProps) {
1130
1143
  {
1131
1144
  trackedAnnotation: annotation,
1132
1145
  isSelected,
1133
- isDraggable: true,
1134
- 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,
1135
1149
  selectionMenu,
1150
+ onSelect: (e) => handleClick(e, annotation),
1136
1151
  style: {
1137
1152
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1138
1153
  },
@@ -1156,9 +1171,11 @@ function Annotations(annotationsProps) {
1156
1171
  {
1157
1172
  trackedAnnotation: annotation,
1158
1173
  isSelected,
1159
- isDraggable: true,
1160
- 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,
1161
1177
  selectionMenu,
1178
+ onSelect: (e) => handleClick(e, annotation),
1162
1179
  style: {
1163
1180
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1164
1181
  },
@@ -1182,9 +1199,11 @@ function Annotations(annotationsProps) {
1182
1199
  {
1183
1200
  trackedAnnotation: annotation,
1184
1201
  isSelected,
1185
- isDraggable: false,
1186
- 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,
1187
1205
  selectionMenu,
1206
+ onSelect: (e) => handleClick(e, annotation),
1188
1207
  zIndex: 0,
1189
1208
  style: {
1190
1209
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
@@ -1201,9 +1220,11 @@ function Annotations(annotationsProps) {
1201
1220
  {
1202
1221
  trackedAnnotation: annotation,
1203
1222
  isSelected,
1204
- isDraggable: false,
1205
- 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,
1206
1226
  selectionMenu,
1227
+ onSelect: (e) => handleClick(e, annotation),
1207
1228
  zIndex: 0,
1208
1229
  style: {
1209
1230
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
@@ -1220,9 +1241,11 @@ function Annotations(annotationsProps) {
1220
1241
  {
1221
1242
  trackedAnnotation: annotation,
1222
1243
  isSelected,
1223
- isDraggable: false,
1224
- 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,
1225
1247
  selectionMenu,
1248
+ onSelect: (e) => handleClick(e, annotation),
1226
1249
  zIndex: 0,
1227
1250
  style: {
1228
1251
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
@@ -1239,9 +1262,11 @@ function Annotations(annotationsProps) {
1239
1262
  {
1240
1263
  trackedAnnotation: annotation,
1241
1264
  isSelected,
1242
- isDraggable: false,
1243
- 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,
1244
1268
  selectionMenu,
1269
+ onSelect: (e) => handleClick(e, annotation),
1245
1270
  zIndex: 0,
1246
1271
  style: {
1247
1272
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Multiply)
@@ -1258,9 +1283,11 @@ function Annotations(annotationsProps) {
1258
1283
  {
1259
1284
  trackedAnnotation: annotation,
1260
1285
  isSelected,
1261
- isDraggable: true,
1262
- 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,
1263
1289
  selectionMenu,
1290
+ onSelect: (e) => handleClick(e, annotation),
1264
1291
  vertexConfig: {
1265
1292
  extractVertices: (annotation2) => [
1266
1293
  annotation2.linePoints.start,
@@ -1299,9 +1326,11 @@ function Annotations(annotationsProps) {
1299
1326
  {
1300
1327
  trackedAnnotation: annotation,
1301
1328
  isSelected,
1302
- isDraggable: true,
1303
- 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,
1304
1332
  selectionMenu,
1333
+ onSelect: (e) => handleClick(e, annotation),
1305
1334
  vertexConfig: {
1306
1335
  extractVertices: (annotation2) => annotation2.vertices,
1307
1336
  transformAnnotation: (annotation2, vertices) => {
@@ -1334,9 +1363,11 @@ function Annotations(annotationsProps) {
1334
1363
  {
1335
1364
  trackedAnnotation: annotation,
1336
1365
  isSelected,
1337
- isDraggable: true,
1338
- 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,
1339
1369
  selectionMenu,
1370
+ onSelect: (e) => handleClick(e, annotation),
1340
1371
  vertexConfig: {
1341
1372
  extractVertices: (annotation2) => annotation2.vertices,
1342
1373
  transformAnnotation: (annotation2, vertices) => {
@@ -1369,9 +1400,11 @@ function Annotations(annotationsProps) {
1369
1400
  {
1370
1401
  trackedAnnotation: annotation,
1371
1402
  isSelected,
1372
- isDraggable: !isEditing,
1373
- 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,
1374
1406
  selectionMenu,
1407
+ onSelect: (e) => handleClick(e, annotation),
1375
1408
  style: {
1376
1409
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1377
1410
  },
@@ -1404,10 +1437,11 @@ function Annotations(annotationsProps) {
1404
1437
  {
1405
1438
  trackedAnnotation: annotation,
1406
1439
  isSelected,
1407
- isDraggable: true,
1408
- 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,
1409
1443
  selectionMenu,
1410
- lockAspectRatio: true,
1444
+ onSelect: (e) => handleClick(e, annotation),
1411
1445
  style: {
1412
1446
  mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
1413
1447
  },
@@ -1665,6 +1699,7 @@ function AnnotationLayer({
1665
1699
  pageHeight,
1666
1700
  rotation,
1667
1701
  selectionOutlineColor,
1702
+ customAnnotationRenderer,
1668
1703
  ...props
1669
1704
  }) {
1670
1705
  return /* @__PURE__ */ jsxs(
@@ -1686,7 +1721,8 @@ function AnnotationLayer({
1686
1721
  pageHeight,
1687
1722
  resizeUI,
1688
1723
  vertexUI,
1689
- selectionOutlineColor
1724
+ selectionOutlineColor,
1725
+ customAnnotationRenderer
1690
1726
  }
1691
1727
  ),
1692
1728
  /* @__PURE__ */ jsx(TextMarkup, { pageIndex, scale }),