@embedpdf/plugin-annotation 1.2.0 → 1.2.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.
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,7 +2150,6 @@ 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
2154
  textSelection: true
2148
2155
  },
@@ -2158,7 +2165,6 @@ const defaultTools = [
2158
2165
  name: "Underline",
2159
2166
  matchScore: (a) => a.type === PdfAnnotationSubtype.UNDERLINE ? 1 : 0,
2160
2167
  interaction: {
2161
- mode: "underline",
2162
2168
  exclusive: false,
2163
2169
  textSelection: true
2164
2170
  },
@@ -2173,7 +2179,6 @@ const defaultTools = [
2173
2179
  name: "Strikeout",
2174
2180
  matchScore: (a) => a.type === PdfAnnotationSubtype.STRIKEOUT ? 1 : 0,
2175
2181
  interaction: {
2176
- mode: "strikeout",
2177
2182
  exclusive: false,
2178
2183
  textSelection: true
2179
2184
  },
@@ -2188,13 +2193,12 @@ const defaultTools = [
2188
2193
  name: "Squiggly",
2189
2194
  matchScore: (a) => a.type === PdfAnnotationSubtype.SQUIGGLY ? 1 : 0,
2190
2195
  interaction: {
2191
- mode: "squiggly",
2192
2196
  exclusive: false,
2193
2197
  textSelection: true
2194
2198
  },
2195
2199
  defaults: {
2196
2200
  type: PdfAnnotationSubtype.SQUIGGLY,
2197
- color: "#5CC96E",
2201
+ color: "#E44234",
2198
2202
  opacity: 1
2199
2203
  }
2200
2204
  },
@@ -2204,7 +2208,6 @@ const defaultTools = [
2204
2208
  name: "Pen",
2205
2209
  matchScore: (a) => a.type === PdfAnnotationSubtype.INK && a.intent !== "InkHighlight" ? 5 : 0,
2206
2210
  interaction: {
2207
- mode: "ink",
2208
2211
  exclusive: false,
2209
2212
  cursor: "crosshair"
2210
2213
  },
@@ -2220,7 +2223,6 @@ const defaultTools = [
2220
2223
  name: "Ink Highlighter",
2221
2224
  matchScore: (a) => a.type === PdfAnnotationSubtype.INK && a.intent === "InkHighlight" ? 10 : 0,
2222
2225
  interaction: {
2223
- mode: "inkHighlighter",
2224
2226
  exclusive: false,
2225
2227
  cursor: "crosshair"
2226
2228
  },
@@ -2238,7 +2240,7 @@ const defaultTools = [
2238
2240
  id: "circle",
2239
2241
  name: "Circle",
2240
2242
  matchScore: (a) => a.type === PdfAnnotationSubtype.CIRCLE ? 1 : 0,
2241
- interaction: { mode: "circle", exclusive: false, cursor: "crosshair" },
2243
+ interaction: { exclusive: false, cursor: "crosshair" },
2242
2244
  defaults: {
2243
2245
  type: PdfAnnotationSubtype.CIRCLE,
2244
2246
  color: "transparent",
@@ -2256,7 +2258,7 @@ const defaultTools = [
2256
2258
  id: "square",
2257
2259
  name: "Square",
2258
2260
  matchScore: (a) => a.type === PdfAnnotationSubtype.SQUARE ? 1 : 0,
2259
- interaction: { mode: "square", exclusive: false, cursor: "crosshair" },
2261
+ interaction: { exclusive: false, cursor: "crosshair" },
2260
2262
  defaults: {
2261
2263
  type: PdfAnnotationSubtype.SQUARE,
2262
2264
  color: "transparent",
@@ -2274,7 +2276,7 @@ const defaultTools = [
2274
2276
  id: "line",
2275
2277
  name: "Line",
2276
2278
  matchScore: (a) => a.type === PdfAnnotationSubtype.LINE && a.intent !== "LineArrow" ? 5 : 0,
2277
- interaction: { mode: "line", exclusive: false, cursor: "crosshair" },
2279
+ interaction: { exclusive: false, cursor: "crosshair" },
2278
2280
  defaults: {
2279
2281
  type: PdfAnnotationSubtype.LINE,
2280
2282
  color: "transparent",
@@ -2292,7 +2294,7 @@ const defaultTools = [
2292
2294
  id: "lineArrow",
2293
2295
  name: "Arrow",
2294
2296
  matchScore: (a) => a.type === PdfAnnotationSubtype.LINE && a.intent === "LineArrow" ? 10 : 0,
2295
- interaction: { mode: "lineArrow", exclusive: false, cursor: "crosshair" },
2297
+ interaction: { exclusive: false, cursor: "crosshair" },
2296
2298
  defaults: {
2297
2299
  type: PdfAnnotationSubtype.LINE,
2298
2300
  intent: "LineArrow",
@@ -2315,7 +2317,7 @@ const defaultTools = [
2315
2317
  id: "polyline",
2316
2318
  name: "Polyline",
2317
2319
  matchScore: (a) => a.type === PdfAnnotationSubtype.POLYLINE ? 1 : 0,
2318
- interaction: { mode: "polyline", exclusive: false, cursor: "crosshair" },
2320
+ interaction: { exclusive: false, cursor: "crosshair" },
2319
2321
  defaults: {
2320
2322
  type: PdfAnnotationSubtype.POLYLINE,
2321
2323
  color: "transparent",
@@ -2328,7 +2330,7 @@ const defaultTools = [
2328
2330
  id: "polygon",
2329
2331
  name: "Polygon",
2330
2332
  matchScore: (a) => a.type === PdfAnnotationSubtype.POLYGON ? 1 : 0,
2331
- interaction: { mode: "polygon", exclusive: false, cursor: "crosshair" },
2333
+ interaction: { exclusive: false, cursor: "crosshair" },
2332
2334
  defaults: {
2333
2335
  type: PdfAnnotationSubtype.POLYGON,
2334
2336
  color: "transparent",
@@ -2342,7 +2344,7 @@ const defaultTools = [
2342
2344
  id: "freeText",
2343
2345
  name: "Free Text",
2344
2346
  matchScore: (a) => a.type === PdfAnnotationSubtype.FREETEXT ? 1 : 0,
2345
- interaction: { mode: "freeText", exclusive: false, cursor: "crosshair" },
2347
+ interaction: { exclusive: false, cursor: "crosshair" },
2346
2348
  defaults: {
2347
2349
  type: PdfAnnotationSubtype.FREETEXT,
2348
2350
  contents: "Insert text",
@@ -2364,7 +2366,7 @@ const defaultTools = [
2364
2366
  id: "stamp",
2365
2367
  name: "Image",
2366
2368
  matchScore: (a) => a.type === PdfAnnotationSubtype.STAMP ? 1 : 0,
2367
- interaction: { mode: "stamp", exclusive: false, cursor: "copy" },
2369
+ interaction: { exclusive: false, cursor: "copy" },
2368
2370
  defaults: {
2369
2371
  type: PdfAnnotationSubtype.STAMP
2370
2372
  // No imageSrc by default, which tells the UI to open a file picker