@embedpdf/plugin-annotation 1.0.11 → 1.0.13

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 (109) hide show
  1. package/dist/index.cjs +2 -693
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -266
  4. package/dist/index.js +509 -164
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/actions.d.ts +104 -0
  7. package/dist/lib/annotation-plugin.d.ts +34 -0
  8. package/dist/lib/helpers.d.ts +18 -0
  9. package/dist/lib/index.d.ts +12 -0
  10. package/dist/lib/manifest.d.ts +4 -0
  11. package/dist/lib/patching/derived-rect.d.ts +2 -0
  12. package/dist/lib/patching/index.d.ts +4 -0
  13. package/dist/lib/patching/line-ending-handlers.d.ts +20 -0
  14. package/dist/lib/patching/line-endings.d.ts +13 -0
  15. package/dist/lib/patching/patch-utils.d.ts +7 -0
  16. package/dist/lib/reducer.d.ts +5 -0
  17. package/dist/lib/selectors.d.ts +25 -0
  18. package/dist/lib/types.d.ts +168 -0
  19. package/dist/lib/utils.d.ts +11 -0
  20. package/dist/lib/variant-key.d.ts +8 -0
  21. package/dist/preact/adapter.d.ts +8 -0
  22. package/dist/preact/core.d.ts +1 -0
  23. package/dist/preact/index.cjs +2 -1038
  24. package/dist/preact/index.cjs.map +1 -1
  25. package/dist/preact/index.d.ts +1 -28
  26. package/dist/preact/index.js +2150 -539
  27. package/dist/preact/index.js.map +1 -1
  28. package/dist/preact/interaction-manager.d.ts +1 -0
  29. package/dist/preact/selection.d.ts +1 -0
  30. package/dist/react/adapter.d.ts +2 -0
  31. package/dist/react/core.d.ts +1 -0
  32. package/dist/react/index.cjs +2 -0
  33. package/dist/react/index.cjs.map +1 -0
  34. package/dist/react/index.d.ts +1 -0
  35. package/dist/react/index.js +2624 -0
  36. package/dist/react/index.js.map +1 -0
  37. package/dist/react/interaction-manager.d.ts +1 -0
  38. package/dist/react/selection.d.ts +1 -0
  39. package/dist/shared-preact/components/annotation-container.d.ts +24 -0
  40. package/dist/shared-preact/components/annotation-layer.d.ts +13 -0
  41. package/dist/shared-preact/components/annotations/circle-paint.d.ts +10 -0
  42. package/dist/shared-preact/components/annotations/circle.d.ts +29 -0
  43. package/dist/shared-preact/components/annotations/ink-highlight-paint.d.ts +0 -0
  44. package/dist/shared-preact/components/annotations/ink-paint.d.ts +18 -0
  45. package/dist/shared-preact/components/annotations/ink.d.ts +25 -0
  46. package/dist/shared-preact/components/annotations/line-paint.d.ts +10 -0
  47. package/dist/shared-preact/components/annotations/line.d.ts +33 -0
  48. package/dist/shared-preact/components/annotations/polygon-paint.d.ts +9 -0
  49. package/dist/shared-preact/components/annotations/polygon.d.ts +17 -0
  50. package/dist/shared-preact/components/annotations/polyline-paint.d.ts +10 -0
  51. package/dist/shared-preact/components/annotations/polyline.d.ts +17 -0
  52. package/dist/shared-preact/components/annotations/square-paint.d.ts +10 -0
  53. package/dist/shared-preact/components/annotations/square.d.ts +29 -0
  54. package/dist/shared-preact/components/annotations.d.ts +11 -0
  55. package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -0
  56. package/dist/shared-preact/components/index.d.ts +1 -0
  57. package/dist/shared-preact/components/render-annotation.d.ts +11 -0
  58. package/dist/shared-preact/components/resize-handles.d.ts +9 -0
  59. package/dist/shared-preact/components/text-markup/highlight.d.ts +13 -0
  60. package/dist/shared-preact/components/text-markup/squiggly.d.ts +13 -0
  61. package/dist/shared-preact/components/text-markup/strikeout.d.ts +13 -0
  62. package/dist/shared-preact/components/text-markup/underline.d.ts +13 -0
  63. package/dist/shared-preact/components/text-markup.d.ts +6 -0
  64. package/dist/shared-preact/components/vertex-editor.d.ts +19 -0
  65. package/dist/shared-preact/hooks/index.d.ts +1 -0
  66. package/dist/shared-preact/hooks/use-annotation.d.ts +11 -0
  67. package/dist/shared-preact/hooks/use-drag-resize.d.ts +31 -0
  68. package/dist/shared-preact/index.d.ts +2 -0
  69. package/dist/shared-preact/patch-ink.d.ts +16 -0
  70. package/dist/shared-preact/patchers.d.ts +9 -0
  71. package/dist/shared-preact/types.d.ts +12 -0
  72. package/dist/shared-preact/vertex-patchers.d.ts +10 -0
  73. package/dist/shared-react/components/annotation-container.d.ts +24 -0
  74. package/dist/shared-react/components/annotation-layer.d.ts +13 -0
  75. package/dist/shared-react/components/annotations/circle-paint.d.ts +10 -0
  76. package/dist/shared-react/components/annotations/circle.d.ts +29 -0
  77. package/dist/shared-react/components/annotations/ink-highlight-paint.d.ts +0 -0
  78. package/dist/shared-react/components/annotations/ink-paint.d.ts +17 -0
  79. package/dist/shared-react/components/annotations/ink.d.ts +25 -0
  80. package/dist/shared-react/components/annotations/line-paint.d.ts +10 -0
  81. package/dist/shared-react/components/annotations/line.d.ts +33 -0
  82. package/dist/shared-react/components/annotations/polygon-paint.d.ts +9 -0
  83. package/dist/shared-react/components/annotations/polygon.d.ts +17 -0
  84. package/dist/shared-react/components/annotations/polyline-paint.d.ts +10 -0
  85. package/dist/shared-react/components/annotations/polyline.d.ts +17 -0
  86. package/dist/shared-react/components/annotations/square-paint.d.ts +10 -0
  87. package/dist/shared-react/components/annotations/square.d.ts +29 -0
  88. package/dist/shared-react/components/annotations.d.ts +11 -0
  89. package/dist/shared-react/components/counter-rotate-container.d.ts +32 -0
  90. package/dist/shared-react/components/index.d.ts +1 -0
  91. package/dist/shared-react/components/render-annotation.d.ts +11 -0
  92. package/dist/shared-react/components/resize-handles.d.ts +9 -0
  93. package/dist/shared-react/components/text-markup/highlight.d.ts +13 -0
  94. package/dist/shared-react/components/text-markup/squiggly.d.ts +13 -0
  95. package/dist/shared-react/components/text-markup/strikeout.d.ts +13 -0
  96. package/dist/shared-react/components/text-markup/underline.d.ts +13 -0
  97. package/dist/shared-react/components/text-markup.d.ts +6 -0
  98. package/dist/shared-react/components/vertex-editor.d.ts +19 -0
  99. package/dist/shared-react/hooks/index.d.ts +1 -0
  100. package/dist/shared-react/hooks/use-annotation.d.ts +11 -0
  101. package/dist/shared-react/hooks/use-drag-resize.d.ts +31 -0
  102. package/dist/shared-react/index.d.ts +2 -0
  103. package/dist/shared-react/patch-ink.d.ts +16 -0
  104. package/dist/shared-react/patchers.d.ts +9 -0
  105. package/dist/shared-react/types.d.ts +12 -0
  106. package/dist/shared-react/vertex-patchers.d.ts +10 -0
  107. package/package.json +17 -15
  108. package/dist/index.d.cts +0 -266
  109. package/dist/preact/index.d.cts +0 -28
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- // src/lib/manifest.ts
2
- var ANNOTATION_PLUGIN_ID = "annotation";
3
- var manifest = {
1
+ import { BasePlugin, createBehaviorEmitter, SET_DOCUMENT } from "@embedpdf/core";
2
+ import { PdfAnnotationLineEnding, rectFromPoints, expandRect, rotateAndTranslatePoint, PdfAnnotationSubtype, PdfBlendMode, ignore, PdfTaskHelper, PdfErrorCode, Rotation, AppearanceMode, Task, PdfAnnotationBorderStyle } from "@embedpdf/models";
3
+ const ANNOTATION_PLUGIN_ID = "annotation";
4
+ const manifest = {
4
5
  id: ANNOTATION_PLUGIN_ID,
5
6
  name: "Annotation Plugin",
6
7
  version: "1.0.0",
@@ -12,104 +13,87 @@ var manifest = {
12
13
  autoCommit: true
13
14
  }
14
15
  };
15
-
16
- // src/lib/annotation-plugin.ts
17
- import {
18
- BasePlugin,
19
- createBehaviorEmitter,
20
- enumEntries,
21
- SET_DOCUMENT
22
- } from "@embedpdf/core";
23
- import {
24
- ignore,
25
- Task,
26
- PdfAnnotationSubtype,
27
- PdfTaskHelper,
28
- PdfErrorCode,
29
- Rotation,
30
- AppearanceMode
31
- } from "@embedpdf/models";
32
-
33
- // src/lib/actions.ts
34
- var SET_ANNOTATIONS = "ANNOTATION/SET_ANNOTATIONS";
35
- var REINDEX_PAGE_ANNOTATIONS = "ANNOTATION/REINDEX_PAGE";
36
- var SELECT_ANNOTATION = "ANNOTATION/SELECT_ANNOTATION";
37
- var DESELECT_ANNOTATION = "ANNOTATION/DESELECT_ANNOTATION";
38
- var SET_ANNOTATION_MODE = "ANNOTATION/SET_ANNOTATION_MODE";
39
- var UPDATE_TOOL_DEFAULTS = "ANNOTATION/UPDATE_TOOL_DEFAULTS";
40
- var ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
41
- var CREATE_ANNOTATION = "ANNOTATION/CREATE_ANNOTATION";
42
- var PATCH_ANNOTATION = "ANNOTATION/PATCH_ANNOTATION";
43
- var DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
44
- var COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
45
- var STORE_PDF_ID = "ANNOTATION/STORE_PDF_ID";
46
- var PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
47
- var setAnnotations = (p) => ({
16
+ const SET_ANNOTATIONS = "ANNOTATION/SET_ANNOTATIONS";
17
+ const REINDEX_PAGE_ANNOTATIONS = "ANNOTATION/REINDEX_PAGE";
18
+ const SELECT_ANNOTATION = "ANNOTATION/SELECT_ANNOTATION";
19
+ const DESELECT_ANNOTATION = "ANNOTATION/DESELECT_ANNOTATION";
20
+ const UPDATE_TOOL_DEFAULTS = "ANNOTATION/UPDATE_TOOL_DEFAULTS";
21
+ const ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
22
+ const CREATE_ANNOTATION = "ANNOTATION/CREATE_ANNOTATION";
23
+ const PATCH_ANNOTATION = "ANNOTATION/PATCH_ANNOTATION";
24
+ const DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
25
+ const COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
26
+ const STORE_PDF_ID = "ANNOTATION/STORE_PDF_ID";
27
+ const PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
28
+ const SET_ACTIVE_VARIANT = "ANNOTATION/SET_ACTIVE_VARIANT";
29
+ const setAnnotations = (p) => ({
48
30
  type: SET_ANNOTATIONS,
49
31
  payload: p
50
32
  });
51
- var reindexPageAnnotations = (pageIndex) => ({
33
+ const reindexPageAnnotations = (pageIndex) => ({
52
34
  type: REINDEX_PAGE_ANNOTATIONS,
53
35
  payload: { pageIndex }
54
36
  });
55
- var selectAnnotation = (pageIndex, localId) => ({
37
+ const selectAnnotation = (pageIndex, localId) => ({
56
38
  type: SELECT_ANNOTATION,
57
39
  payload: { pageIndex, localId }
58
40
  });
59
- var deselectAnnotation = () => ({ type: DESELECT_ANNOTATION });
60
- var setAnnotationMode = (m) => ({
61
- type: SET_ANNOTATION_MODE,
62
- payload: m
63
- });
64
- var updateToolDefaults = (subtype, patch) => ({ type: UPDATE_TOOL_DEFAULTS, payload: { subtype, patch } });
65
- var addColorPreset = (c) => ({
41
+ const deselectAnnotation = () => ({ type: DESELECT_ANNOTATION });
42
+ const updateToolDefaults = (variantKey, patch) => ({ type: UPDATE_TOOL_DEFAULTS, payload: { variantKey, patch } });
43
+ const addColorPreset = (c) => ({
66
44
  type: ADD_COLOR_PRESET,
67
45
  payload: c
68
46
  });
69
- var createAnnotation = (pageIndex, localId, annotation) => ({
47
+ const createAnnotation = (pageIndex, localId, annotation) => ({
70
48
  type: CREATE_ANNOTATION,
71
49
  payload: { pageIndex, localId, annotation }
72
50
  });
73
- var patchAnnotation = (pageIndex, localId, patch) => ({
51
+ const patchAnnotation = (pageIndex, localId, patch) => ({
74
52
  type: PATCH_ANNOTATION,
75
53
  payload: { pageIndex, localId, patch }
76
54
  });
77
- var deleteAnnotation = (pageIndex, localId) => ({
55
+ const deleteAnnotation = (pageIndex, localId) => ({
78
56
  type: DELETE_ANNOTATION,
79
57
  payload: { pageIndex, localId }
80
58
  });
81
- var commitPendingChanges = () => ({ type: COMMIT_PENDING_CHANGES });
82
- var storePdfId = (uid, pdfId) => ({
59
+ const commitPendingChanges = () => ({ type: COMMIT_PENDING_CHANGES });
60
+ const storePdfId = (uid, pdfId) => ({
83
61
  type: STORE_PDF_ID,
84
62
  payload: { uid, pdfId }
85
63
  });
86
- var purgeAnnotation = (uid) => ({
64
+ const purgeAnnotation = (uid) => ({
87
65
  type: PURGE_ANNOTATION,
88
66
  payload: { uid }
89
67
  });
90
-
91
- // src/lib/utils.ts
92
- var makeUid = (pageIndex, localId) => `p${pageIndex}#${localId}`;
93
- var parseUid = (uid) => {
68
+ const setActiveVariant = (k) => ({
69
+ type: SET_ACTIVE_VARIANT,
70
+ payload: k
71
+ });
72
+ const makeUid$1 = (pageIndex, localId) => `p${pageIndex}#${localId}`;
73
+ const parseUid = (uid) => {
94
74
  const [pg, rest] = uid.slice(1).split("#");
95
75
  return { pageIndex: Number(pg), localId: Number(rest) };
96
76
  };
97
-
98
- // src/lib/selectors.ts
99
- var makeUid2 = (page, id) => `p${page}#${id}`;
100
- var getAnnotationsByPageIndex = (s, page) => (s.pages[page] ?? []).map((uid) => s.byUid[uid]);
101
- var getAnnotations = (s) => {
77
+ const makeVariantKey = (subtype, intent) => intent ? `${subtype}#${intent}` : `${subtype}`;
78
+ const parseVariantKey = (key) => {
79
+ const [subStr, intent] = key.split("#");
80
+ return { subtype: Number(subStr), intent };
81
+ };
82
+ const variantKeyFromAnnotation = (a) => makeVariantKey(a.type, a.intent);
83
+ const makeUid = (page, id) => `p${page}#${id}`;
84
+ const getAnnotationsByPageIndex = (s, page) => (s.pages[page] ?? []).map((uid) => s.byUid[uid]);
85
+ const getAnnotations = (s) => {
102
86
  const out = {};
103
87
  for (const p of Object.keys(s.pages).map(Number)) out[p] = getAnnotationsByPageIndex(s, p);
104
88
  return out;
105
89
  };
106
- var getSelectedAnnotation = (s) => s.selectedUid ? s.byUid[s.selectedUid] : null;
107
- var getSelectedAnnotationWithPageIndex = (s) => {
90
+ const getSelectedAnnotation = (s) => s.selectedUid ? s.byUid[s.selectedUid] : null;
91
+ const getSelectedAnnotationWithPageIndex = (s) => {
108
92
  if (!s.selectedUid) return null;
109
93
  const { pageIndex, localId } = parseUid(s.selectedUid);
110
94
  return { pageIndex, localId, annotation: s.byUid[s.selectedUid].object };
111
95
  };
112
- var getSelectedAnnotationByPageIndex = (s, pageIndex) => {
96
+ const getSelectedAnnotationByPageIndex = (s, pageIndex) => {
113
97
  if (!s.selectedUid) return null;
114
98
  const pageUids = s.pages[pageIndex] ?? [];
115
99
  if (pageUids.includes(s.selectedUid)) {
@@ -117,33 +101,240 @@ var getSelectedAnnotationByPageIndex = (s, pageIndex) => {
117
101
  }
118
102
  return null;
119
103
  };
120
- var isInAnnotationMode = (s) => s.annotationMode !== null;
121
- var getSelectedAnnotationMode = (s) => s.annotationMode;
122
- var isAnnotationSelected = (s, page, id) => s.selectedUid === makeUid2(page, id);
123
-
124
- // src/lib/annotation-plugin.ts
125
- var AnnotationPlugin = class extends BasePlugin {
104
+ const isInAnnotationVariant = (s) => s.activeVariant !== null;
105
+ const getSelectedAnnotationVariant = (s) => s.activeVariant;
106
+ const isAnnotationSelected = (s, page, id) => s.selectedUid === makeUid(page, id);
107
+ function getToolDefaultsBySubtypeAndIntent(state, subtype, intent) {
108
+ const variantKey = makeVariantKey(subtype, intent ?? void 0);
109
+ const fallbackKey = makeVariantKey(subtype);
110
+ const defaults = state.toolDefaults[variantKey] ?? state.toolDefaults[fallbackKey];
111
+ if (!defaults) {
112
+ throw new Error(
113
+ `No tool defaults found for subtype ${subtype}${intent ? ` and intent ${intent}` : ""}`
114
+ );
115
+ }
116
+ return defaults;
117
+ }
118
+ function createArrowHandler(isClosed) {
119
+ const calculateGeometry = (sw) => {
120
+ const len = sw * 9;
121
+ const a = Math.PI / 6;
122
+ return {
123
+ x: -len * Math.cos(a),
124
+ y: len * Math.sin(a)
125
+ };
126
+ };
127
+ return {
128
+ getSvgPath: (sw) => {
129
+ const { x, y } = calculateGeometry(sw);
130
+ return isClosed ? `M 0 0 L ${x} ${y} L ${x} ${-y} Z` : `M ${x} ${y} L 0 0 L ${x} ${-y}`;
131
+ },
132
+ getLocalPoints: (sw) => {
133
+ const { x, y } = calculateGeometry(sw);
134
+ return [
135
+ { x: 0, y: 0 },
136
+ { x, y },
137
+ { x, y: -y }
138
+ ];
139
+ },
140
+ getRotation: (segmentAngle) => segmentAngle,
141
+ filled: isClosed
142
+ };
143
+ }
144
+ function createLineHandler(lengthFactor, rotationFn) {
145
+ const getHalfLength = (sw) => sw * lengthFactor / 2;
146
+ return {
147
+ getSvgPath: (sw) => {
148
+ const l = getHalfLength(sw);
149
+ return `M ${-l} 0 L ${l} 0`;
150
+ },
151
+ getLocalPoints: (sw) => {
152
+ const l = getHalfLength(sw);
153
+ return [
154
+ { x: -l, y: 0 },
155
+ { x: l, y: 0 }
156
+ ];
157
+ },
158
+ getRotation: rotationFn,
159
+ filled: false
160
+ };
161
+ }
162
+ const OpenArrowHandler = createArrowHandler(false);
163
+ const ClosedArrowHandler = createArrowHandler(true);
164
+ const LINE_ENDING_HANDLERS = {
165
+ [PdfAnnotationLineEnding.OpenArrow]: OpenArrowHandler,
166
+ [PdfAnnotationLineEnding.ClosedArrow]: ClosedArrowHandler,
167
+ [PdfAnnotationLineEnding.ROpenArrow]: {
168
+ ...OpenArrowHandler,
169
+ getRotation: (segmentAngle) => segmentAngle + Math.PI
170
+ },
171
+ [PdfAnnotationLineEnding.RClosedArrow]: {
172
+ ...ClosedArrowHandler,
173
+ getRotation: (segmentAngle) => segmentAngle + Math.PI
174
+ },
175
+ [PdfAnnotationLineEnding.Circle]: {
176
+ getSvgPath: (sw) => {
177
+ const r = sw * 5 / 2;
178
+ return `M ${r} 0 A ${r} ${r} 0 1 1 ${-r} 0 A ${r} ${r} 0 1 1 ${r} 0`;
179
+ },
180
+ getLocalPoints: (sw) => {
181
+ const r = sw * 5 / 2;
182
+ return [
183
+ { x: -r, y: -r },
184
+ { x: r, y: r }
185
+ ];
186
+ },
187
+ getRotation: () => 0,
188
+ filled: true
189
+ },
190
+ [PdfAnnotationLineEnding.Square]: {
191
+ getSvgPath: (sw) => {
192
+ const h = sw * 6 / 2;
193
+ return `M ${-h} ${-h} L ${h} ${-h} L ${h} ${h} L ${-h} ${h} Z`;
194
+ },
195
+ getLocalPoints: (sw) => {
196
+ const h = sw * 6 / 2;
197
+ return [
198
+ { x: -h, y: -h },
199
+ // TL
200
+ { x: h, y: -h },
201
+ // TR
202
+ { x: h, y: h },
203
+ // BR
204
+ { x: -h, y: h }
205
+ // BL
206
+ ];
207
+ },
208
+ getRotation: (segmentAngle) => segmentAngle,
209
+ // keep your new orientation
210
+ filled: true
211
+ },
212
+ [PdfAnnotationLineEnding.Diamond]: {
213
+ getSvgPath: (sw) => {
214
+ const h = sw * 6 / 2;
215
+ return `M 0 ${-h} L ${h} 0 L 0 ${h} L ${-h} 0 Z`;
216
+ },
217
+ getLocalPoints: (sw) => {
218
+ const h = sw * 6 / 2;
219
+ return [
220
+ { x: 0, y: -h },
221
+ { x: h, y: 0 },
222
+ { x: 0, y: h },
223
+ { x: -h, y: 0 }
224
+ ];
225
+ },
226
+ getRotation: (segmentAngle) => segmentAngle,
227
+ filled: true
228
+ },
229
+ [PdfAnnotationLineEnding.Butt]: createLineHandler(6, (angle) => angle + Math.PI / 2),
230
+ [PdfAnnotationLineEnding.Slash]: createLineHandler(18, (angle) => angle + Math.PI / 1.5)
231
+ };
232
+ const EXTRA_PADDING = 1.2;
233
+ function lineRectWithEndings(vertices, strokeWidth, endings) {
234
+ if (!vertices || vertices.length === 0) {
235
+ return { origin: { x: 0, y: 0 }, size: { width: 0, height: 0 } };
236
+ }
237
+ const allPoints = [...vertices];
238
+ const toAngle = (a, b) => Math.atan2(b.y - a.y, b.x - a.x);
239
+ const processEnding = (endingType, tipPos, segmentAngle) => {
240
+ if (!endingType) return;
241
+ const handler = LINE_ENDING_HANDLERS[endingType];
242
+ if (!handler) return;
243
+ const localPts = handler.getLocalPoints(strokeWidth);
244
+ const rotationAngle = handler.getRotation(segmentAngle);
245
+ const transformedPts = localPts.map((p) => rotateAndTranslatePoint(p, rotationAngle, tipPos));
246
+ allPoints.push(...transformedPts);
247
+ };
248
+ if (vertices.length >= 2) {
249
+ const startAngle = toAngle(vertices[1], vertices[0]);
250
+ processEnding(endings == null ? void 0 : endings.start, vertices[0], startAngle);
251
+ const lastIdx = vertices.length - 1;
252
+ const endAngle = toAngle(vertices[lastIdx - 1], vertices[lastIdx]);
253
+ processEnding(endings == null ? void 0 : endings.end, vertices[lastIdx], endAngle);
254
+ }
255
+ if (allPoints.length <= 1) {
256
+ const point = vertices[0] || { x: 0, y: 0 };
257
+ const pad2 = strokeWidth;
258
+ return {
259
+ origin: { x: point.x - pad2, y: point.y - pad2 },
260
+ size: { width: pad2 * 2, height: pad2 * 2 }
261
+ };
262
+ }
263
+ const baseRect = rectFromPoints(allPoints);
264
+ const pad = strokeWidth / 2 + EXTRA_PADDING * strokeWidth;
265
+ return expandRect(baseRect, pad);
266
+ }
267
+ const vertsRect = (verts, sw) => expandRect(rectFromPoints(verts), sw / 2);
268
+ function deriveRect(a) {
269
+ switch (a.type) {
270
+ /* mark‑ups already carry their real rect */
271
+ case PdfAnnotationSubtype.HIGHLIGHT:
272
+ case PdfAnnotationSubtype.UNDERLINE:
273
+ case PdfAnnotationSubtype.STRIKEOUT:
274
+ case PdfAnnotationSubtype.SQUIGGLY:
275
+ case PdfAnnotationSubtype.SQUARE:
276
+ case PdfAnnotationSubtype.CIRCLE:
277
+ return a.rect;
278
+ /* ink */
279
+ case PdfAnnotationSubtype.INK: {
280
+ const pts = a.inkList.flatMap((s) => s.points);
281
+ return vertsRect(pts, a.strokeWidth);
282
+ }
283
+ /* one‑segment */
284
+ case PdfAnnotationSubtype.LINE:
285
+ return lineRectWithEndings(
286
+ [a.linePoints.start, a.linePoints.end],
287
+ a.strokeWidth,
288
+ a.lineEndings
289
+ );
290
+ /* multi‑segment */
291
+ case PdfAnnotationSubtype.POLYLINE:
292
+ return lineRectWithEndings(a.vertices, a.strokeWidth, a.lineEndings);
293
+ case PdfAnnotationSubtype.POLYGON:
294
+ return vertsRect(a.vertices, a.strokeWidth);
295
+ default:
296
+ return a.rect;
297
+ }
298
+ }
299
+ function createEnding(ending, strokeWidth, rad, px, py) {
300
+ if (!ending) return null;
301
+ const handler = LINE_ENDING_HANDLERS[ending];
302
+ if (!handler) return null;
303
+ const toDeg = (r) => r * 180 / Math.PI;
304
+ const rotationAngle = handler.getRotation(rad);
305
+ return {
306
+ d: handler.getSvgPath(strokeWidth),
307
+ transform: `translate(${px} ${py}) rotate(${toDeg(rotationAngle)})`,
308
+ filled: handler.filled
309
+ };
310
+ }
311
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
312
+ __proto__: null,
313
+ LINE_ENDING_HANDLERS,
314
+ createEnding,
315
+ deriveRect,
316
+ lineRectWithEndings
317
+ }, Symbol.toStringTag, { value: "Module" }));
318
+ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
126
319
  constructor(id, registry, engine, config) {
127
320
  super(id, registry);
128
321
  this.ANNOTATION_HISTORY_TOPIC = "annotations";
129
322
  this.state$ = createBehaviorEmitter();
130
- /** Map <subtype> <modeId>. Filled once in `initialize()`. */
131
- this.modeBySubtype = /* @__PURE__ */ new Map();
132
- /** The inverse map for quick lookup in onModeChange(). */
133
- this.subtypeByMode = /* @__PURE__ */ new Map();
134
- this.modeChange$ = createBehaviorEmitter();
323
+ this.modeByVariant = /* @__PURE__ */ new Map();
324
+ this.variantByMode = /* @__PURE__ */ new Map();
325
+ this.activeVariantChange$ = createBehaviorEmitter();
135
326
  this.activeTool$ = createBehaviorEmitter({
136
- mode: null,
327
+ variantKey: null,
137
328
  defaults: null
138
329
  });
139
330
  this.engine = engine;
140
331
  this.config = config;
141
332
  const selection = registry.getPlugin("selection");
142
- this.selection = selection?.provides() ?? null;
333
+ this.selection = (selection == null ? void 0 : selection.provides()) ?? null;
143
334
  const history = registry.getPlugin("history");
144
- this.history = history?.provides() ?? null;
335
+ this.history = (history == null ? void 0 : history.provides()) ?? null;
145
336
  const interactionManager = registry.getPlugin("interaction-manager");
146
- this.interactionManager = interactionManager?.provides() ?? null;
337
+ this.interactionManager = (interactionManager == null ? void 0 : interactionManager.provides()) ?? null;
147
338
  this.coreStore.onAction(SET_DOCUMENT, (_action, state) => {
148
339
  const doc = state.core.document;
149
340
  if (doc) {
@@ -152,48 +343,55 @@ var AnnotationPlugin = class extends BasePlugin {
152
343
  });
153
344
  }
154
345
  async initialize() {
155
- for (const [subtype, defaults] of enumEntries(this.state.toolDefaults)) {
156
- this.registerTool(subtype, defaults);
346
+ var _a, _b, _c;
347
+ for (const [variantKey, defaults] of Object.entries(this.state.toolDefaults)) {
348
+ this.registerTool(variantKey, defaults);
157
349
  }
158
- this.history?.onHistoryChange((topic) => {
350
+ (_a = this.history) == null ? void 0 : _a.onHistoryChange((topic) => {
159
351
  if (topic === this.ANNOTATION_HISTORY_TOPIC && this.config.autoCommit !== false) {
160
352
  this.commit();
161
353
  }
162
354
  });
163
- this.interactionManager?.onModeChange((s) => {
164
- const newSubtype = this.subtypeByMode.get(s.activeMode) ?? null;
165
- if (newSubtype !== this.state.annotationMode) {
166
- this.dispatch(setAnnotationMode(newSubtype));
167
- this.modeChange$.emit(newSubtype);
355
+ (_b = this.interactionManager) == null ? void 0 : _b.onModeChange((s) => {
356
+ const newVariant = this.variantByMode.get(s.activeMode) ?? null;
357
+ console.log(newVariant, this.state.activeVariant);
358
+ if (newVariant !== this.state.activeVariant) {
359
+ this.dispatch(setActiveVariant(newVariant));
360
+ this.activeVariantChange$.emit(newVariant);
168
361
  }
169
362
  });
170
- this.selection?.onEndSelection(() => {
171
- if (!this.state.annotationMode) return;
172
- if (!(this.state.annotationMode === PdfAnnotationSubtype.HIGHLIGHT || this.state.annotationMode === PdfAnnotationSubtype.UNDERLINE || this.state.annotationMode === PdfAnnotationSubtype.STRIKEOUT || this.state.annotationMode === PdfAnnotationSubtype.SQUIGGLY)) {
363
+ (_c = this.selection) == null ? void 0 : _c.onEndSelection(() => {
364
+ var _a2, _b2;
365
+ if (!this.state.activeVariant) return;
366
+ if (!(this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.HIGHLIGHT) || this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.UNDERLINE) || this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.STRIKEOUT) || this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.SQUIGGLY))) {
173
367
  return;
174
368
  }
175
- const formattedSelection = this.selection?.getFormattedSelection();
369
+ const formattedSelection = (_a2 = this.selection) == null ? void 0 : _a2.getFormattedSelection();
176
370
  if (!formattedSelection) return;
177
371
  for (const selection of formattedSelection) {
178
372
  const rect = selection.rect;
179
373
  const segmentRects = selection.segmentRects;
180
- const type = this.state.annotationMode;
374
+ const type = this.state.activeVariant;
375
+ const subtype = this.state.toolDefaults[type].subtype;
181
376
  const color = this.state.toolDefaults[type].color;
182
377
  const opacity = this.state.toolDefaults[type].opacity;
378
+ const blendMode = this.state.toolDefaults[type].blendMode ?? PdfBlendMode.Normal;
183
379
  this.createAnnotation(selection.pageIndex, {
184
- type,
380
+ type: subtype,
185
381
  rect,
186
382
  segmentRects,
187
383
  color,
188
384
  opacity,
385
+ blendMode,
189
386
  pageIndex: selection.pageIndex,
190
387
  id: Date.now() + Math.random()
191
388
  });
192
389
  }
193
- this.selection?.clear();
390
+ (_b2 = this.selection) == null ? void 0 : _b2.clear();
194
391
  });
195
392
  }
196
- registerTool(subtype, defaults) {
393
+ registerTool(variantKey, defaults) {
394
+ var _a, _b;
197
395
  const modeId = defaults.interaction.mode;
198
396
  const interactionMode = {
199
397
  id: modeId,
@@ -201,12 +399,12 @@ var AnnotationPlugin = class extends BasePlugin {
201
399
  exclusive: defaults.interaction.exclusive,
202
400
  cursor: defaults.interaction.cursor
203
401
  };
204
- this.interactionManager?.registerMode(interactionMode);
402
+ (_a = this.interactionManager) == null ? void 0 : _a.registerMode(interactionMode);
205
403
  if (defaults.textSelection) {
206
- this.selection?.enableForMode(modeId);
404
+ (_b = this.selection) == null ? void 0 : _b.enableForMode(modeId);
207
405
  }
208
- this.modeBySubtype.set(subtype, modeId);
209
- this.subtypeByMode.set(modeId, subtype);
406
+ this.modeByVariant.set(variantKey, modeId);
407
+ this.variantByMode.set(modeId, variantKey);
210
408
  }
211
409
  buildCapability() {
212
410
  return {
@@ -222,28 +420,38 @@ var AnnotationPlugin = class extends BasePlugin {
222
420
  deselectAnnotation: () => {
223
421
  this.dispatch(deselectAnnotation());
224
422
  },
225
- getAnnotationMode: () => {
226
- return this.state.annotationMode;
423
+ getActiveVariant: () => {
424
+ return this.state.activeVariant;
227
425
  },
228
- setAnnotationMode: (subtype) => {
229
- if (subtype === this.state.annotationMode) return;
230
- if (subtype) {
231
- const mode = this.modeBySubtype.get(subtype);
232
- if (!mode) throw new Error(`Mode missing for subtype ${subtype}`);
233
- this.interactionManager?.activate(mode);
426
+ setActiveVariant: (variantKey) => {
427
+ var _a, _b;
428
+ if (variantKey === this.state.activeVariant) return;
429
+ if (variantKey) {
430
+ const mode = this.modeByVariant.get(variantKey);
431
+ if (!mode) throw new Error(`Mode missing for variant ${variantKey}`);
432
+ (_a = this.interactionManager) == null ? void 0 : _a.activate(mode);
234
433
  } else {
235
- this.interactionManager?.activate("default");
434
+ (_b = this.interactionManager) == null ? void 0 : _b.activate("default");
236
435
  }
237
436
  },
238
- getToolDefaults: (subtype) => {
239
- const defaults = this.state.toolDefaults[subtype];
437
+ getSubtypeAndIntentByVariant: (variantKey) => {
438
+ return parseVariantKey(variantKey);
439
+ },
440
+ getToolDefaults: (variantKey) => {
441
+ const defaults = this.state.toolDefaults[variantKey];
240
442
  if (!defaults) {
241
- throw new Error(`No defaults found for subtype: ${subtype}`);
443
+ throw new Error(`No defaults found for variant: ${variantKey}`);
242
444
  }
243
445
  return defaults;
244
446
  },
245
- setToolDefaults: (subtype, patch) => {
246
- this.dispatch(updateToolDefaults(subtype, patch));
447
+ getToolDefaultsBySubtypeAndIntent: (subtype, intent) => {
448
+ return getToolDefaultsBySubtypeAndIntent(this.state, subtype, intent);
449
+ },
450
+ getToolDefaultsBySubtype: (subtype) => {
451
+ return getToolDefaultsBySubtypeAndIntent(this.state, subtype);
452
+ },
453
+ setToolDefaults: (variantKey, patch) => {
454
+ this.dispatch(updateToolDefaults(variantKey, patch));
247
455
  },
248
456
  getColorPresets: () => [...this.state.colorPresets],
249
457
  addColorPreset: (color) => this.dispatch(addColorPreset(color)),
@@ -252,24 +460,24 @@ var AnnotationPlugin = class extends BasePlugin {
252
460
  deleteAnnotation: (pageIndex, localId) => this.deleteAnnotation(pageIndex, localId),
253
461
  renderAnnotation: (options) => this.renderAnnotation(options),
254
462
  onStateChange: this.state$.on,
255
- onModeChange: this.modeChange$.on,
463
+ onActiveVariantChange: this.activeVariantChange$.on,
256
464
  onActiveToolChange: this.activeTool$.on,
257
465
  commit: () => this.commit()
258
466
  };
259
467
  }
260
468
  createActiveTool(mode, toolDefaults) {
261
469
  if (mode === null) {
262
- return { mode: null, defaults: null };
470
+ return { variantKey: null, defaults: null };
263
471
  }
264
- return { mode, defaults: toolDefaults[mode] };
472
+ return { variantKey: mode, defaults: toolDefaults[mode] };
265
473
  }
266
474
  emitActiveTool(state) {
267
- const activeTool = this.createActiveTool(state.annotationMode, state.toolDefaults);
475
+ const activeTool = this.createActiveTool(state.activeVariant, state.toolDefaults);
268
476
  this.activeTool$.emit(activeTool);
269
477
  }
270
478
  onStoreUpdated(prev, next) {
271
479
  this.state$.emit(next);
272
- if (prev.annotationMode !== next.annotationMode || prev.toolDefaults[prev.annotationMode ?? PdfAnnotationSubtype.HIGHLIGHT] !== next.toolDefaults[next.annotationMode ?? PdfAnnotationSubtype.HIGHLIGHT]) {
480
+ if (prev.activeVariant !== next.activeVariant || prev.toolDefaults[prev.activeVariant ?? PdfAnnotationSubtype.HIGHLIGHT] !== next.toolDefaults[next.activeVariant ?? PdfAnnotationSubtype.HIGHLIGHT]) {
273
481
  this.emitActiveTool(next);
274
482
  }
275
483
  }
@@ -337,20 +545,26 @@ var AnnotationPlugin = class extends BasePlugin {
337
545
  };
338
546
  this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
339
547
  }
548
+ buildPatch(original, patch) {
549
+ if ("rect" in patch) return patch;
550
+ const merged = { ...original, ...patch };
551
+ return { ...patch, rect: deriveRect(merged) };
552
+ }
340
553
  updateAnnotation(pageIndex, localId, patch) {
554
+ const originalObject = this.state.byUid[makeUid$1(pageIndex, localId)].object;
555
+ const finalPatch = this.buildPatch(originalObject, patch);
341
556
  if (!this.history) {
342
- this.dispatch(patchAnnotation(pageIndex, localId, patch));
557
+ this.dispatch(patchAnnotation(pageIndex, localId, finalPatch));
343
558
  if (this.config.autoCommit !== false) {
344
559
  this.commit();
345
560
  }
346
561
  return;
347
562
  }
348
- const originalObject = this.state.byUid[makeUid(pageIndex, localId)].object;
349
563
  const originalPatch = Object.fromEntries(
350
564
  Object.keys(patch).map((key) => [key, originalObject[key]])
351
565
  );
352
566
  const command = {
353
- execute: () => this.dispatch(patchAnnotation(pageIndex, localId, patch)),
567
+ execute: () => this.dispatch(patchAnnotation(pageIndex, localId, finalPatch)),
354
568
  undo: () => this.dispatch(patchAnnotation(pageIndex, localId, originalPatch))
355
569
  };
356
570
  this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
@@ -364,7 +578,7 @@ var AnnotationPlugin = class extends BasePlugin {
364
578
  }
365
579
  return;
366
580
  }
367
- const originalAnnotation = this.state.byUid[makeUid(pageIndex, localId)].object;
581
+ const originalAnnotation = this.state.byUid[makeUid$1(pageIndex, localId)].object;
368
582
  const command = {
369
583
  execute: () => {
370
584
  this.dispatch(deselectAnnotation());
@@ -441,11 +655,9 @@ var AnnotationPlugin = class extends BasePlugin {
441
655
  return task;
442
656
  }
443
657
  };
444
- AnnotationPlugin.id = "annotation";
445
-
446
- // src/lib/reducer.ts
447
- import { PdfAnnotationSubtype as PdfAnnotationSubtype2 } from "@embedpdf/models";
448
- var DEFAULT_COLORS = [
658
+ _AnnotationPlugin.id = "annotation";
659
+ let AnnotationPlugin = _AnnotationPlugin;
660
+ const DEFAULT_COLORS = [
449
661
  "#E44234",
450
662
  "#FF8D00",
451
663
  "#FFCD45",
@@ -455,7 +667,7 @@ var DEFAULT_COLORS = [
455
667
  "#C544CE",
456
668
  "#7D2E25"
457
669
  ];
458
- var patchAnno = (state, uid, patch) => {
670
+ const patchAnno = (state, uid, patch) => {
459
671
  const prev = state.byUid[uid];
460
672
  if (!prev) return state;
461
673
  return {
@@ -471,54 +683,138 @@ var patchAnno = (state, uid, patch) => {
471
683
  hasPendingChanges: true
472
684
  };
473
685
  };
474
- var initialState = (cfg) => ({
686
+ const initialState = (cfg) => ({
475
687
  pages: {},
476
688
  byUid: {},
477
689
  selectedUid: null,
478
- annotationMode: null,
690
+ activeVariant: null,
479
691
  toolDefaults: {
480
- [PdfAnnotationSubtype2.HIGHLIGHT]: {
692
+ [makeVariantKey(PdfAnnotationSubtype.HIGHLIGHT)]: {
481
693
  name: "Highlight",
694
+ subtype: PdfAnnotationSubtype.HIGHLIGHT,
695
+ interaction: { mode: "highlight", exclusive: false },
696
+ textSelection: true,
482
697
  color: "#FFCD45",
483
698
  opacity: 1,
484
- interaction: { mode: "highlight", exclusive: false },
485
- textSelection: true
699
+ blendMode: PdfBlendMode.Multiply
486
700
  },
487
- [PdfAnnotationSubtype2.UNDERLINE]: {
701
+ [makeVariantKey(PdfAnnotationSubtype.UNDERLINE)]: {
488
702
  name: "Underline",
703
+ subtype: PdfAnnotationSubtype.UNDERLINE,
704
+ interaction: { mode: "underline", exclusive: false },
705
+ textSelection: true,
489
706
  color: "#E44234",
490
707
  opacity: 1,
491
- interaction: { mode: "underline", exclusive: false },
492
- textSelection: true
708
+ blendMode: PdfBlendMode.Normal
493
709
  },
494
- [PdfAnnotationSubtype2.STRIKEOUT]: {
710
+ [makeVariantKey(PdfAnnotationSubtype.STRIKEOUT)]: {
495
711
  name: "Strikeout",
712
+ subtype: PdfAnnotationSubtype.STRIKEOUT,
713
+ interaction: { mode: "strikeout", exclusive: false },
714
+ textSelection: true,
496
715
  color: "#E44234",
497
716
  opacity: 1,
498
- interaction: { mode: "strikeout", exclusive: false },
499
- textSelection: true
717
+ blendMode: PdfBlendMode.Normal
500
718
  },
501
- [PdfAnnotationSubtype2.SQUIGGLY]: {
719
+ [makeVariantKey(PdfAnnotationSubtype.SQUIGGLY)]: {
502
720
  name: "Squiggly",
721
+ subtype: PdfAnnotationSubtype.SQUIGGLY,
722
+ interaction: { mode: "squiggly", exclusive: false },
723
+ textSelection: true,
503
724
  color: "#E44234",
504
725
  opacity: 1,
505
- interaction: { mode: "squiggly", exclusive: false },
506
- textSelection: true
726
+ blendMode: PdfBlendMode.Normal
507
727
  },
508
- [PdfAnnotationSubtype2.INK]: {
728
+ [makeVariantKey(PdfAnnotationSubtype.INK)]: {
509
729
  name: "Ink",
730
+ subtype: PdfAnnotationSubtype.INK,
731
+ interaction: { mode: "ink", exclusive: true, cursor: "crosshair" },
510
732
  color: "#E44234",
511
733
  opacity: 1,
512
734
  strokeWidth: 11,
513
- interaction: { mode: "ink", exclusive: true, cursor: "crosshair" },
514
- textSelection: false
735
+ blendMode: PdfBlendMode.Normal
736
+ },
737
+ [makeVariantKey(PdfAnnotationSubtype.INK, "InkHighlight")]: {
738
+ name: "Ink Highlight",
739
+ subtype: PdfAnnotationSubtype.INK,
740
+ intent: "InkHighlight",
741
+ interaction: { mode: "inkHighlight", exclusive: true, cursor: "crosshair" },
742
+ color: "#E44234",
743
+ opacity: 1,
744
+ strokeWidth: 11,
745
+ blendMode: PdfBlendMode.Multiply
746
+ },
747
+ [makeVariantKey(PdfAnnotationSubtype.CIRCLE)]: {
748
+ name: "Circle",
749
+ subtype: PdfAnnotationSubtype.CIRCLE,
750
+ interaction: { mode: "circle", exclusive: true, cursor: "crosshair" },
751
+ color: "transparent",
752
+ opacity: 1,
753
+ strokeWidth: 4,
754
+ strokeColor: "#E44234",
755
+ strokeStyle: PdfAnnotationBorderStyle.SOLID
756
+ },
757
+ [makeVariantKey(PdfAnnotationSubtype.SQUARE)]: {
758
+ name: "Square",
759
+ subtype: PdfAnnotationSubtype.SQUARE,
760
+ interaction: { mode: "square", exclusive: true, cursor: "crosshair" },
761
+ color: "transparent",
762
+ opacity: 1,
763
+ strokeWidth: 4,
764
+ strokeColor: "#E44234",
765
+ strokeStyle: PdfAnnotationBorderStyle.SOLID
766
+ },
767
+ [makeVariantKey(PdfAnnotationSubtype.LINE)]: {
768
+ name: "Line",
769
+ subtype: PdfAnnotationSubtype.LINE,
770
+ interaction: { mode: "line", exclusive: true, cursor: "crosshair" },
771
+ color: "transparent",
772
+ opacity: 1,
773
+ strokeWidth: 4,
774
+ strokeColor: "#E44234",
775
+ strokeStyle: PdfAnnotationBorderStyle.SOLID
776
+ },
777
+ [makeVariantKey(PdfAnnotationSubtype.LINE, "LineArrow")]: {
778
+ name: "Line Arrow",
779
+ subtype: PdfAnnotationSubtype.LINE,
780
+ interaction: { mode: "lineArrow", exclusive: true, cursor: "crosshair" },
781
+ color: "transparent",
782
+ intent: "LineArrow",
783
+ opacity: 1,
784
+ strokeWidth: 4,
785
+ strokeColor: "#E44234",
786
+ strokeStyle: PdfAnnotationBorderStyle.SOLID,
787
+ lineEndings: {
788
+ start: PdfAnnotationLineEnding.None,
789
+ end: PdfAnnotationLineEnding.OpenArrow
790
+ }
791
+ },
792
+ [makeVariantKey(PdfAnnotationSubtype.POLYLINE)]: {
793
+ name: "Polyline",
794
+ subtype: PdfAnnotationSubtype.POLYLINE,
795
+ interaction: { mode: "polyline", exclusive: true, cursor: "crosshair" },
796
+ color: "transparent",
797
+ opacity: 1,
798
+ strokeWidth: 4,
799
+ strokeColor: "#E44234",
800
+ strokeStyle: PdfAnnotationBorderStyle.SOLID
801
+ },
802
+ [makeVariantKey(PdfAnnotationSubtype.POLYGON)]: {
803
+ name: "Polygon",
804
+ subtype: PdfAnnotationSubtype.POLYGON,
805
+ interaction: { mode: "polygon", exclusive: true, cursor: "crosshair" },
806
+ color: "transparent",
807
+ opacity: 1,
808
+ strokeWidth: 4,
809
+ strokeColor: "#E44234",
810
+ strokeStyle: PdfAnnotationBorderStyle.SOLID
515
811
  },
516
812
  ...cfg.toolDefaults
517
813
  },
518
814
  colorPresets: cfg.colorPresets ?? DEFAULT_COLORS,
519
815
  hasPendingChanges: false
520
816
  });
521
- var reducer = (state, action) => {
817
+ const reducer = (state, action) => {
522
818
  switch (action.type) {
523
819
  /* ───── bulk load from engine ───── */
524
820
  case SET_ANNOTATIONS: {
@@ -530,9 +826,9 @@ var reducer = (state, action) => {
530
826
  for (const uid of oldUidsOnPage) {
531
827
  delete newByUid[uid];
532
828
  }
533
- const newUidsOnPage = list.map((a, index) => {
534
- const localId = Date.now() + Math.random() + index;
535
- const uid = makeUid(pageIndex, localId);
829
+ const newUidsOnPage = list.map((a, index2) => {
830
+ const localId = Date.now() + Math.random() + index2;
831
+ const uid = makeUid$1(pageIndex, localId);
536
832
  newByUid[uid] = { localId, pdfId: a.id, commitState: "synced", object: a };
537
833
  return uid;
538
834
  });
@@ -541,31 +837,33 @@ var reducer = (state, action) => {
541
837
  return { ...state, pages: newPages, byUid: newByUid };
542
838
  }
543
839
  /* ───── GUI bits ───── */
544
- case SET_ANNOTATION_MODE:
545
- return { ...state, annotationMode: action.payload };
840
+ case SET_ACTIVE_VARIANT:
841
+ return { ...state, activeVariant: action.payload };
546
842
  case SELECT_ANNOTATION:
547
843
  return {
548
844
  ...state,
549
- selectedUid: makeUid(action.payload.pageIndex, action.payload.localId)
845
+ selectedUid: makeUid$1(action.payload.pageIndex, action.payload.localId)
550
846
  };
551
847
  case DESELECT_ANNOTATION:
552
848
  return { ...state, selectedUid: null };
553
849
  case ADD_COLOR_PRESET:
554
850
  return state.colorPresets.includes(action.payload) ? state : { ...state, colorPresets: [...state.colorPresets, action.payload] };
555
851
  case UPDATE_TOOL_DEFAULTS: {
556
- const { subtype, patch } = action.payload;
852
+ const { variantKey, patch } = action.payload;
853
+ const prev = state.toolDefaults[variantKey];
854
+ if (!prev) return state;
557
855
  return {
558
856
  ...state,
559
857
  toolDefaults: {
560
858
  ...state.toolDefaults,
561
- [subtype]: { ...state.toolDefaults[subtype], ...patch }
859
+ [variantKey]: { ...prev, ...patch }
562
860
  }
563
861
  };
564
862
  }
565
863
  /* ───── create ───── */
566
864
  case CREATE_ANNOTATION: {
567
865
  const { pageIndex, localId, annotation } = action.payload;
568
- const uid = makeUid(pageIndex, localId);
866
+ const uid = makeUid$1(pageIndex, localId);
569
867
  return {
570
868
  ...state,
571
869
  pages: { ...state.pages, [pageIndex]: [...state.pages[pageIndex] ?? [], uid] },
@@ -579,7 +877,7 @@ var reducer = (state, action) => {
579
877
  /* ───── delete ───── */
580
878
  case DELETE_ANNOTATION: {
581
879
  const { pageIndex, localId } = action.payload;
582
- const uid = makeUid(pageIndex, localId);
880
+ const uid = makeUid$1(pageIndex, localId);
583
881
  if (!state.byUid[uid]) return state;
584
882
  return {
585
883
  ...state,
@@ -596,7 +894,7 @@ var reducer = (state, action) => {
596
894
  }
597
895
  /* ───── field edits ───── */
598
896
  case PATCH_ANNOTATION: {
599
- const uid = makeUid(action.payload.pageIndex, action.payload.localId);
897
+ const uid = makeUid$1(action.payload.pageIndex, action.payload.localId);
600
898
  return patchAnno(state, uid, action.payload.patch);
601
899
  }
602
900
  /* ───── commit bookkeeping ───── */
@@ -617,7 +915,7 @@ var reducer = (state, action) => {
617
915
  const annosOnPage = uidsOnPage.map((uid) => state.byUid[uid]).filter((ta) => ta && ta.commitState !== "deleted");
618
916
  annosOnPage.sort((a, b) => (a.pdfId ?? Infinity) - (b.pdfId ?? Infinity));
619
917
  annosOnPage.forEach((ta, newPdfId) => {
620
- const uid = makeUid(pageIndex, ta.localId);
918
+ const uid = makeUid$1(pageIndex, ta.localId);
621
919
  newByUid[uid] = { ...newByUid[uid], pdfId: newPdfId };
622
920
  });
623
921
  return { ...state, byUid: newByUid };
@@ -643,9 +941,40 @@ var reducer = (state, action) => {
643
941
  return state;
644
942
  }
645
943
  };
646
-
647
- // src/lib/index.ts
648
- var AnnotationPluginPackage = {
944
+ function isInk(a) {
945
+ return a.object.type === PdfAnnotationSubtype.INK;
946
+ }
947
+ function isCircle(a) {
948
+ return a.object.type === PdfAnnotationSubtype.CIRCLE;
949
+ }
950
+ function isPolygon(a) {
951
+ return a.object.type === PdfAnnotationSubtype.POLYGON;
952
+ }
953
+ function isSquare(a) {
954
+ return a.object.type === PdfAnnotationSubtype.SQUARE;
955
+ }
956
+ function isLine(a) {
957
+ return a.object.type === PdfAnnotationSubtype.LINE;
958
+ }
959
+ function isPolyline(a) {
960
+ return a.object.type === PdfAnnotationSubtype.POLYLINE;
961
+ }
962
+ function isTextMarkup(a) {
963
+ return a.object.type === PdfAnnotationSubtype.HIGHLIGHT || a.object.type === PdfAnnotationSubtype.UNDERLINE || a.object.type === PdfAnnotationSubtype.STRIKEOUT || a.object.type === PdfAnnotationSubtype.SQUIGGLY;
964
+ }
965
+ function isHighlight(a) {
966
+ return a.object.type === PdfAnnotationSubtype.HIGHLIGHT;
967
+ }
968
+ function isUnderline(a) {
969
+ return a.object.type === PdfAnnotationSubtype.UNDERLINE;
970
+ }
971
+ function isStrikeout(a) {
972
+ return a.object.type === PdfAnnotationSubtype.STRIKEOUT;
973
+ }
974
+ function isSquiggly(a) {
975
+ return a.object.type === PdfAnnotationSubtype.SQUIGGLY;
976
+ }
977
+ const AnnotationPluginPackage = {
649
978
  manifest,
650
979
  create: (registry, engine, config) => new AnnotationPlugin(ANNOTATION_PLUGIN_ID, registry, engine, config),
651
980
  reducer,
@@ -659,10 +988,26 @@ export {
659
988
  getAnnotationsByPageIndex,
660
989
  getSelectedAnnotation,
661
990
  getSelectedAnnotationByPageIndex,
662
- getSelectedAnnotationMode,
991
+ getSelectedAnnotationVariant,
663
992
  getSelectedAnnotationWithPageIndex,
993
+ getToolDefaultsBySubtypeAndIntent,
664
994
  isAnnotationSelected,
665
- isInAnnotationMode,
666
- manifest
995
+ isCircle,
996
+ isHighlight,
997
+ isInAnnotationVariant,
998
+ isInk,
999
+ isLine,
1000
+ isPolygon,
1001
+ isPolyline,
1002
+ isSquare,
1003
+ isSquiggly,
1004
+ isStrikeout,
1005
+ isTextMarkup,
1006
+ isUnderline,
1007
+ makeVariantKey,
1008
+ manifest,
1009
+ parseVariantKey,
1010
+ index as patching,
1011
+ variantKeyFromAnnotation
667
1012
  };
668
- //# sourceMappingURL=index.js.map
1013
+ //# sourceMappingURL=index.js.map