@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
package/dist/index.js CHANGED
@@ -192,7 +192,8 @@ const inkHandlerFactory = {
192
192
  ...tool.defaults,
193
193
  strokeWidth: tool.defaults.strokeWidth ?? 1,
194
194
  color: tool.defaults.color ?? "#000000",
195
- opacity: tool.defaults.opacity ?? 1
195
+ opacity: tool.defaults.opacity ?? 1,
196
+ flags: tool.defaults.flags ?? ["print"]
196
197
  };
197
198
  };
198
199
  const getPreview = () => {
@@ -249,7 +250,6 @@ const inkHandlerFactory = {
249
250
  inkList: strokes,
250
251
  rect,
251
252
  type: PdfAnnotationSubtype.INK,
252
- flags: ["print"],
253
253
  pageIndex: context.pageIndex,
254
254
  id: uuidV4(),
255
255
  created: /* @__PURE__ */ new Date()
@@ -330,7 +330,8 @@ const freeTextHandlerFactory = {
330
330
  backgroundColor: tool.defaults.backgroundColor ?? "transparent",
331
331
  textAlign: tool.defaults.textAlign ?? PdfTextAlignment.Left,
332
332
  verticalAlign: tool.defaults.verticalAlign ?? PdfVerticalAlignment.Top,
333
- contents: tool.defaults.contents ?? "Insert text here"
333
+ contents: tool.defaults.contents ?? "Insert text here",
334
+ flags: tool.defaults.flags ?? ["print"]
334
335
  };
335
336
  };
336
337
  const clickDetector = useClickDetector({
@@ -356,7 +357,6 @@ const freeTextHandlerFactory = {
356
357
  contents,
357
358
  type: PdfAnnotationSubtype.FREETEXT,
358
359
  rect,
359
- flags: ["print"],
360
360
  pageIndex,
361
361
  id: uuidV4(),
362
362
  created: /* @__PURE__ */ new Date()
@@ -424,7 +424,6 @@ const freeTextHandlerFactory = {
424
424
  ...defaults,
425
425
  type: PdfAnnotationSubtype.FREETEXT,
426
426
  rect,
427
- flags: ["print"],
428
427
  pageIndex: context.pageIndex,
429
428
  id: uuidV4(),
430
429
  created: /* @__PURE__ */ new Date()
@@ -665,7 +664,8 @@ const lineHandlerFactory = {
665
664
  opacity: tool.defaults.opacity ?? 1,
666
665
  strokeStyle: tool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID,
667
666
  strokeDashArray: tool.defaults.strokeDashArray ?? [],
668
- strokeColor: tool.defaults.strokeColor ?? "#000000"
667
+ strokeColor: tool.defaults.strokeColor ?? "#000000",
668
+ flags: tool.defaults.flags ?? ["print"]
669
669
  };
670
670
  };
671
671
  const clickDetector = useClickDetector({
@@ -696,7 +696,6 @@ const lineHandlerFactory = {
696
696
  linePoints: { start, end },
697
697
  pageIndex,
698
698
  id: uuidV4(),
699
- flags: ["print"],
700
699
  created: /* @__PURE__ */ new Date(),
701
700
  type: PdfAnnotationSubtype.LINE
702
701
  });
@@ -812,7 +811,8 @@ const polylineHandlerFactory = {
812
811
  opacity: tool.defaults.opacity ?? 1,
813
812
  strokeColor: tool.defaults.strokeColor ?? "#000000",
814
813
  strokeStyle: tool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID,
815
- strokeDashArray: tool.defaults.strokeDashArray ?? []
814
+ strokeDashArray: tool.defaults.strokeDashArray ?? [],
815
+ flags: tool.defaults.flags ?? ["print"]
816
816
  };
817
817
  };
818
818
  const commitPolyline = () => {
@@ -830,7 +830,6 @@ const polylineHandlerFactory = {
830
830
  vertices,
831
831
  rect,
832
832
  type: PdfAnnotationSubtype.POLYLINE,
833
- flags: ["print"],
834
833
  pageIndex: context.pageIndex,
835
834
  id: uuidV4(),
836
835
  created: /* @__PURE__ */ new Date()
@@ -922,7 +921,8 @@ const polygonHandlerFactory = {
922
921
  strokeWidth: tool.defaults.strokeWidth ?? 1,
923
922
  strokeColor: tool.defaults.strokeColor ?? "#000000",
924
923
  strokeStyle: tool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID,
925
- strokeDashArray: tool.defaults.strokeDashArray ?? []
924
+ strokeDashArray: tool.defaults.strokeDashArray ?? [],
925
+ flags: tool.defaults.flags ?? ["print"]
926
926
  };
927
927
  };
928
928
  const commitPolygon = () => {
@@ -936,7 +936,6 @@ const polygonHandlerFactory = {
936
936
  vertices,
937
937
  rect,
938
938
  type: PdfAnnotationSubtype.POLYGON,
939
- flags: ["print"],
940
939
  pageIndex: context.pageIndex,
941
940
  id: uuidV4(),
942
941
  created: /* @__PURE__ */ new Date()
@@ -1013,6 +1012,7 @@ const squareHandlerFactory = {
1013
1012
  if (!tool) return null;
1014
1013
  return {
1015
1014
  ...tool.defaults,
1015
+ flags: tool.defaults.flags ?? ["print"],
1016
1016
  strokeWidth: tool.defaults.strokeWidth ?? 2,
1017
1017
  strokeColor: tool.defaults.strokeColor ?? "#000000",
1018
1018
  strokeStyle: tool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID,
@@ -1043,7 +1043,6 @@ const squareHandlerFactory = {
1043
1043
  const anno = {
1044
1044
  ...defaults,
1045
1045
  type: PdfAnnotationSubtype.SQUARE,
1046
- flags: ["print"],
1047
1046
  created: /* @__PURE__ */ new Date(),
1048
1047
  id: uuidV4(),
1049
1048
  pageIndex,
@@ -1109,7 +1108,6 @@ const squareHandlerFactory = {
1109
1108
  const anno = {
1110
1109
  ...defaults2,
1111
1110
  type: PdfAnnotationSubtype.SQUARE,
1112
- flags: ["print"],
1113
1111
  created: /* @__PURE__ */ new Date(),
1114
1112
  id: uuidV4(),
1115
1113
  pageIndex,
@@ -1159,14 +1157,15 @@ const stampHandlerFactory = {
1159
1157
  size: { width, height }
1160
1158
  };
1161
1159
  const anno = {
1160
+ ...tool.defaults,
1162
1161
  rect,
1163
1162
  type: PdfAnnotationSubtype.STAMP,
1164
- icon: PdfAnnotationIcon.Draft,
1165
- subject: "Stamp",
1163
+ icon: tool.defaults.icon ?? PdfAnnotationIcon.Draft,
1164
+ subject: tool.defaults.subject ?? "Stamp",
1165
+ flags: tool.defaults.flags ?? ["print"],
1166
1166
  pageIndex: context.pageIndex,
1167
1167
  id: uuidV4(),
1168
- created: /* @__PURE__ */ new Date(),
1169
- flags: ["print"]
1168
+ created: /* @__PURE__ */ new Date()
1170
1169
  };
1171
1170
  onCommit(anno, { imageData });
1172
1171
  };
@@ -1217,7 +1216,8 @@ const circleHandlerFactory = {
1217
1216
  strokeStyle: tool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID,
1218
1217
  strokeDashArray: tool.defaults.strokeDashArray ?? [],
1219
1218
  color: tool.defaults.color ?? "#000000",
1220
- opacity: tool.defaults.opacity ?? 1
1219
+ opacity: tool.defaults.opacity ?? 1,
1220
+ flags: tool.defaults.flags ?? ["print"]
1221
1221
  };
1222
1222
  };
1223
1223
  const clickDetector = useClickDetector({
@@ -1242,7 +1242,6 @@ const circleHandlerFactory = {
1242
1242
  const anno = {
1243
1243
  ...defaults,
1244
1244
  type: PdfAnnotationSubtype.CIRCLE,
1245
- flags: ["print"],
1246
1245
  created: /* @__PURE__ */ new Date(),
1247
1246
  id: uuidV4(),
1248
1247
  pageIndex,
@@ -1705,7 +1704,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
1705
1704
  });
1706
1705
  (_b = this.interactionManager) == null ? void 0 : _b.onModeChange((s) => {
1707
1706
  var _a2;
1708
- const newToolId = ((_a2 = this.state.tools.find((t) => t.interaction.mode === s.activeMode)) == null ? void 0 : _a2.id) ?? null;
1707
+ const newToolId = ((_a2 = this.state.tools.find((t) => (t.interaction.mode ?? t.id) === s.activeMode)) == null ? void 0 : _a2.id) ?? null;
1709
1708
  if (newToolId !== this.state.activeToolId) {
1710
1709
  this.dispatch(setActiveToolId(newToolId));
1711
1710
  }
@@ -1745,13 +1744,13 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
1745
1744
  registerInteractionForTool(tool) {
1746
1745
  var _a, _b;
1747
1746
  (_a = this.interactionManager) == null ? void 0 : _a.registerMode({
1748
- id: tool.interaction.mode,
1747
+ id: tool.interaction.mode ?? tool.id,
1749
1748
  scope: "page",
1750
1749
  exclusive: tool.interaction.exclusive,
1751
1750
  cursor: tool.interaction.cursor
1752
1751
  });
1753
1752
  if (tool.interaction.textSelection) {
1754
- (_b = this.selection) == null ? void 0 : _b.enableForMode(tool.interaction.mode);
1753
+ (_b = this.selection) == null ? void 0 : _b.enableForMode(tool.interaction.mode ?? tool.id);
1755
1754
  }
1756
1755
  }
1757
1756
  buildCapability() {
@@ -1833,7 +1832,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
1833
1832
  getTool: () => this.state.tools.find((t) => t.id === tool.id)
1834
1833
  };
1835
1834
  const unregister = this.interactionManager.registerHandlers({
1836
- modeId: tool.interaction.mode,
1835
+ modeId: tool.interaction.mode ?? tool.id,
1837
1836
  handlers: factory.create(context),
1838
1837
  pageIndex
1839
1838
  });
@@ -1906,16 +1905,20 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
1906
1905
  }
1907
1906
  createAnnotation(pageIndex, annotation, ctx) {
1908
1907
  const id = annotation.id;
1908
+ const newAnnotation = {
1909
+ ...annotation,
1910
+ author: annotation.author ?? this.config.annotationAuthor
1911
+ };
1909
1912
  const execute = () => {
1910
- this.dispatch(
1911
- createAnnotation(pageIndex, {
1912
- ...annotation,
1913
- author: annotation.author ?? this.config.annotationAuthor,
1914
- flags: ["print"]
1915
- })
1916
- );
1913
+ this.dispatch(createAnnotation(pageIndex, newAnnotation));
1917
1914
  if (ctx) this.pendingContexts.set(id, ctx);
1918
- this.events$.emit({ type: "create", annotation, pageIndex, ctx, committed: false });
1915
+ this.events$.emit({
1916
+ type: "create",
1917
+ annotation: newAnnotation,
1918
+ pageIndex,
1919
+ ctx,
1920
+ committed: false
1921
+ });
1919
1922
  };
1920
1923
  if (!this.history) {
1921
1924
  execute();
@@ -1928,7 +1931,12 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
1928
1931
  this.pendingContexts.delete(id);
1929
1932
  this.dispatch(deselectAnnotation());
1930
1933
  this.dispatch(deleteAnnotation(pageIndex, id));
1931
- this.events$.emit({ type: "delete", annotation, pageIndex, committed: false });
1934
+ this.events$.emit({
1935
+ type: "delete",
1936
+ annotation: newAnnotation,
1937
+ pageIndex,
1938
+ committed: false
1939
+ });
1932
1940
  }
1933
1941
  };
1934
1942
  this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
@@ -2026,7 +2034,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
2026
2034
  if (toolId === this.state.activeToolId) return;
2027
2035
  const tool = this.state.tools.find((t) => t.id === toolId);
2028
2036
  if (tool) {
2029
- (_a = this.interactionManager) == null ? void 0 : _a.activate(tool.interaction.mode);
2037
+ (_a = this.interactionManager) == null ? void 0 : _a.activate(tool.interaction.mode ?? tool.id);
2030
2038
  } else {
2031
2039
  (_b = this.interactionManager) == null ? void 0 : _b.activateDefaultMode();
2032
2040
  }
@@ -2142,9 +2150,10 @@ const defaultTools = [
2142
2150
  name: "Highlight",
2143
2151
  matchScore: (a) => a.type === PdfAnnotationSubtype.HIGHLIGHT ? 1 : 0,
2144
2152
  interaction: {
2145
- mode: "highlight",
2146
2153
  exclusive: false,
2147
- textSelection: true
2154
+ textSelection: true,
2155
+ isDraggable: false,
2156
+ isResizable: false
2148
2157
  },
2149
2158
  defaults: {
2150
2159
  type: PdfAnnotationSubtype.HIGHLIGHT,
@@ -2158,9 +2167,10 @@ const defaultTools = [
2158
2167
  name: "Underline",
2159
2168
  matchScore: (a) => a.type === PdfAnnotationSubtype.UNDERLINE ? 1 : 0,
2160
2169
  interaction: {
2161
- mode: "underline",
2162
2170
  exclusive: false,
2163
- textSelection: true
2171
+ textSelection: true,
2172
+ isDraggable: false,
2173
+ isResizable: false
2164
2174
  },
2165
2175
  defaults: {
2166
2176
  type: PdfAnnotationSubtype.UNDERLINE,
@@ -2173,7 +2183,6 @@ const defaultTools = [
2173
2183
  name: "Strikeout",
2174
2184
  matchScore: (a) => a.type === PdfAnnotationSubtype.STRIKEOUT ? 1 : 0,
2175
2185
  interaction: {
2176
- mode: "strikeout",
2177
2186
  exclusive: false,
2178
2187
  textSelection: true
2179
2188
  },
@@ -2188,13 +2197,14 @@ const defaultTools = [
2188
2197
  name: "Squiggly",
2189
2198
  matchScore: (a) => a.type === PdfAnnotationSubtype.SQUIGGLY ? 1 : 0,
2190
2199
  interaction: {
2191
- mode: "squiggly",
2192
2200
  exclusive: false,
2193
- textSelection: true
2201
+ textSelection: true,
2202
+ isDraggable: false,
2203
+ isResizable: false
2194
2204
  },
2195
2205
  defaults: {
2196
2206
  type: PdfAnnotationSubtype.SQUIGGLY,
2197
- color: "#5CC96E",
2207
+ color: "#E44234",
2198
2208
  opacity: 1
2199
2209
  }
2200
2210
  },
@@ -2204,9 +2214,11 @@ const defaultTools = [
2204
2214
  name: "Pen",
2205
2215
  matchScore: (a) => a.type === PdfAnnotationSubtype.INK && a.intent !== "InkHighlight" ? 5 : 0,
2206
2216
  interaction: {
2207
- mode: "ink",
2208
2217
  exclusive: false,
2209
- cursor: "crosshair"
2218
+ cursor: "crosshair",
2219
+ isDraggable: true,
2220
+ isResizable: true,
2221
+ lockAspectRatio: false
2210
2222
  },
2211
2223
  defaults: {
2212
2224
  type: PdfAnnotationSubtype.INK,
@@ -2220,9 +2232,11 @@ const defaultTools = [
2220
2232
  name: "Ink Highlighter",
2221
2233
  matchScore: (a) => a.type === PdfAnnotationSubtype.INK && a.intent === "InkHighlight" ? 10 : 0,
2222
2234
  interaction: {
2223
- mode: "inkHighlighter",
2224
2235
  exclusive: false,
2225
- cursor: "crosshair"
2236
+ cursor: "crosshair",
2237
+ isDraggable: true,
2238
+ isResizable: true,
2239
+ lockAspectRatio: false
2226
2240
  },
2227
2241
  defaults: {
2228
2242
  type: PdfAnnotationSubtype.INK,
@@ -2238,7 +2252,13 @@ const defaultTools = [
2238
2252
  id: "circle",
2239
2253
  name: "Circle",
2240
2254
  matchScore: (a) => a.type === PdfAnnotationSubtype.CIRCLE ? 1 : 0,
2241
- interaction: { mode: "circle", exclusive: false, cursor: "crosshair" },
2255
+ interaction: {
2256
+ exclusive: false,
2257
+ cursor: "crosshair",
2258
+ isDraggable: true,
2259
+ isResizable: true,
2260
+ lockAspectRatio: false
2261
+ },
2242
2262
  defaults: {
2243
2263
  type: PdfAnnotationSubtype.CIRCLE,
2244
2264
  color: "transparent",
@@ -2256,7 +2276,13 @@ const defaultTools = [
2256
2276
  id: "square",
2257
2277
  name: "Square",
2258
2278
  matchScore: (a) => a.type === PdfAnnotationSubtype.SQUARE ? 1 : 0,
2259
- interaction: { mode: "square", exclusive: false, cursor: "crosshair" },
2279
+ interaction: {
2280
+ exclusive: false,
2281
+ cursor: "crosshair",
2282
+ isDraggable: true,
2283
+ isResizable: true,
2284
+ lockAspectRatio: false
2285
+ },
2260
2286
  defaults: {
2261
2287
  type: PdfAnnotationSubtype.SQUARE,
2262
2288
  color: "transparent",
@@ -2274,7 +2300,13 @@ const defaultTools = [
2274
2300
  id: "line",
2275
2301
  name: "Line",
2276
2302
  matchScore: (a) => a.type === PdfAnnotationSubtype.LINE && a.intent !== "LineArrow" ? 5 : 0,
2277
- interaction: { mode: "line", exclusive: false, cursor: "crosshair" },
2303
+ interaction: {
2304
+ exclusive: false,
2305
+ cursor: "crosshair",
2306
+ isDraggable: true,
2307
+ isResizable: false,
2308
+ lockAspectRatio: false
2309
+ },
2278
2310
  defaults: {
2279
2311
  type: PdfAnnotationSubtype.LINE,
2280
2312
  color: "transparent",
@@ -2292,7 +2324,13 @@ const defaultTools = [
2292
2324
  id: "lineArrow",
2293
2325
  name: "Arrow",
2294
2326
  matchScore: (a) => a.type === PdfAnnotationSubtype.LINE && a.intent === "LineArrow" ? 10 : 0,
2295
- interaction: { mode: "lineArrow", exclusive: false, cursor: "crosshair" },
2327
+ interaction: {
2328
+ exclusive: false,
2329
+ cursor: "crosshair",
2330
+ isDraggable: true,
2331
+ isResizable: false,
2332
+ lockAspectRatio: false
2333
+ },
2296
2334
  defaults: {
2297
2335
  type: PdfAnnotationSubtype.LINE,
2298
2336
  intent: "LineArrow",
@@ -2315,7 +2353,13 @@ const defaultTools = [
2315
2353
  id: "polyline",
2316
2354
  name: "Polyline",
2317
2355
  matchScore: (a) => a.type === PdfAnnotationSubtype.POLYLINE ? 1 : 0,
2318
- interaction: { mode: "polyline", exclusive: false, cursor: "crosshair" },
2356
+ interaction: {
2357
+ exclusive: false,
2358
+ cursor: "crosshair",
2359
+ isDraggable: true,
2360
+ isResizable: false,
2361
+ lockAspectRatio: false
2362
+ },
2319
2363
  defaults: {
2320
2364
  type: PdfAnnotationSubtype.POLYLINE,
2321
2365
  color: "transparent",
@@ -2328,7 +2372,13 @@ const defaultTools = [
2328
2372
  id: "polygon",
2329
2373
  name: "Polygon",
2330
2374
  matchScore: (a) => a.type === PdfAnnotationSubtype.POLYGON ? 1 : 0,
2331
- interaction: { mode: "polygon", exclusive: false, cursor: "crosshair" },
2375
+ interaction: {
2376
+ exclusive: false,
2377
+ cursor: "crosshair",
2378
+ isDraggable: true,
2379
+ isResizable: false,
2380
+ lockAspectRatio: false
2381
+ },
2332
2382
  defaults: {
2333
2383
  type: PdfAnnotationSubtype.POLYGON,
2334
2384
  color: "transparent",
@@ -2342,7 +2392,13 @@ const defaultTools = [
2342
2392
  id: "freeText",
2343
2393
  name: "Free Text",
2344
2394
  matchScore: (a) => a.type === PdfAnnotationSubtype.FREETEXT ? 1 : 0,
2345
- interaction: { mode: "freeText", exclusive: false, cursor: "crosshair" },
2395
+ interaction: {
2396
+ exclusive: false,
2397
+ cursor: "crosshair",
2398
+ isDraggable: true,
2399
+ isResizable: true,
2400
+ lockAspectRatio: false
2401
+ },
2346
2402
  defaults: {
2347
2403
  type: PdfAnnotationSubtype.FREETEXT,
2348
2404
  contents: "Insert text",
@@ -2364,7 +2420,13 @@ const defaultTools = [
2364
2420
  id: "stamp",
2365
2421
  name: "Image",
2366
2422
  matchScore: (a) => a.type === PdfAnnotationSubtype.STAMP ? 1 : 0,
2367
- interaction: { mode: "stamp", exclusive: false, cursor: "copy" },
2423
+ interaction: {
2424
+ exclusive: false,
2425
+ cursor: "copy",
2426
+ isDraggable: true,
2427
+ isResizable: true,
2428
+ lockAspectRatio: true
2429
+ },
2368
2430
  defaults: {
2369
2431
  type: PdfAnnotationSubtype.STAMP
2370
2432
  // No imageSrc by default, which tells the UI to open a file picker