@embedpdf/plugin-annotation 1.0.12 → 1.0.14
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.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +391 -31
- package/dist/index.js.map +1 -1
- package/dist/lib/annotation-plugin.d.ts +1 -0
- package/dist/lib/helpers.d.ts +24 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/patching/derived-rect.d.ts +2 -0
- package/dist/lib/patching/index.d.ts +4 -0
- package/dist/lib/patching/line-ending-handlers.d.ts +20 -0
- package/dist/lib/patching/line-endings.d.ts +13 -0
- package/dist/lib/patching/patch-utils.d.ts +7 -0
- package/dist/lib/selectors.d.ts +17 -5
- package/dist/lib/types.d.ts +97 -12
- package/dist/preact/adapter.d.ts +6 -1
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +2348 -447
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +6 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +2347 -446
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/annotation-container.d.ts +14 -8
- package/dist/shared-preact/components/annotation-layer.d.ts +3 -1
- package/dist/shared-preact/components/annotations/circle-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/circle.d.ts +29 -0
- package/dist/shared-preact/components/annotations/free-text-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/free-text.d.ts +13 -0
- package/dist/shared-preact/components/annotations/ink-paint.d.ts +2 -1
- package/dist/shared-preact/components/annotations/ink.d.ts +3 -1
- package/dist/shared-preact/components/annotations/line-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/line.d.ts +33 -0
- package/dist/shared-preact/components/annotations/polygon-paint.d.ts +9 -0
- package/dist/shared-preact/components/annotations/polygon.d.ts +17 -0
- package/dist/shared-preact/components/annotations/polyline-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/polyline.d.ts +17 -0
- package/dist/shared-preact/components/annotations/square-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/square.d.ts +29 -0
- package/dist/shared-preact/components/annotations.d.ts +4 -0
- package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -0
- package/dist/shared-preact/components/resize-handles.d.ts +9 -0
- package/dist/shared-preact/components/vertex-editor.d.ts +19 -0
- package/dist/shared-preact/hooks/use-drag-resize.d.ts +31 -0
- package/dist/shared-preact/{resize-ink.d.ts → patch-ink.d.ts} +3 -4
- package/dist/shared-preact/patchers.d.ts +9 -0
- package/dist/shared-preact/types.d.ts +11 -0
- package/dist/shared-preact/vertex-patchers.d.ts +10 -0
- package/dist/shared-react/components/annotation-container.d.ts +14 -8
- package/dist/shared-react/components/annotation-layer.d.ts +3 -1
- package/dist/shared-react/components/annotations/circle-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/circle.d.ts +29 -0
- package/dist/shared-react/components/annotations/free-text-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/free-text.d.ts +13 -0
- package/dist/shared-react/components/annotations/ink.d.ts +3 -1
- package/dist/shared-react/components/annotations/line-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/line.d.ts +33 -0
- package/dist/shared-react/components/annotations/polygon-paint.d.ts +9 -0
- package/dist/shared-react/components/annotations/polygon.d.ts +17 -0
- package/dist/shared-react/components/annotations/polyline-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/polyline.d.ts +17 -0
- package/dist/shared-react/components/annotations/square-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/square.d.ts +29 -0
- package/dist/shared-react/components/annotations.d.ts +4 -0
- package/dist/shared-react/components/counter-rotate-container.d.ts +32 -0
- package/dist/shared-react/components/resize-handles.d.ts +9 -0
- package/dist/shared-react/components/vertex-editor.d.ts +19 -0
- package/dist/shared-react/hooks/use-drag-resize.d.ts +31 -0
- package/dist/shared-react/{resize-ink.d.ts → patch-ink.d.ts} +3 -4
- package/dist/shared-react/patchers.d.ts +9 -0
- package/dist/shared-react/types.d.ts +11 -0
- package/dist/shared-react/vertex-patchers.d.ts +10 -0
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BasePlugin, createBehaviorEmitter, SET_DOCUMENT } from "@embedpdf/core";
|
|
2
|
-
import { PdfAnnotationSubtype, PdfBlendMode, ignore, PdfTaskHelper, PdfErrorCode, Rotation, AppearanceMode, Task } from "@embedpdf/models";
|
|
2
|
+
import { PdfAnnotationLineEnding, rectFromPoints, expandRect, rotateAndTranslatePoint, PdfAnnotationSubtype, PdfBlendMode, ignore, PdfTaskHelper, PdfErrorCode, Rotation, AppearanceMode, Task, PdfVerticalAlignment, PdfTextAlignment, PdfStandardFont, PdfAnnotationBorderStyle } from "@embedpdf/models";
|
|
3
3
|
const ANNOTATION_PLUGIN_ID = "annotation";
|
|
4
4
|
const manifest = {
|
|
5
5
|
id: ANNOTATION_PLUGIN_ID,
|
|
@@ -74,6 +74,12 @@ const parseUid = (uid) => {
|
|
|
74
74
|
const [pg, rest] = uid.slice(1).split("#");
|
|
75
75
|
return { pageIndex: Number(pg), localId: Number(rest) };
|
|
76
76
|
};
|
|
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);
|
|
77
83
|
const makeUid = (page, id) => `p${page}#${id}`;
|
|
78
84
|
const getAnnotationsByPageIndex = (s, page) => (s.pages[page] ?? []).map((uid) => s.byUid[uid]);
|
|
79
85
|
const getAnnotations = (s) => {
|
|
@@ -98,12 +104,268 @@ const getSelectedAnnotationByPageIndex = (s, pageIndex) => {
|
|
|
98
104
|
const isInAnnotationVariant = (s) => s.activeVariant !== null;
|
|
99
105
|
const getSelectedAnnotationVariant = (s) => s.activeVariant;
|
|
100
106
|
const isAnnotationSelected = (s, page, id) => s.selectedUid === makeUid(page, id);
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
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)
|
|
105
231
|
};
|
|
106
|
-
const
|
|
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
|
+
function isInk(a) {
|
|
319
|
+
return a.object.type === PdfAnnotationSubtype.INK;
|
|
320
|
+
}
|
|
321
|
+
function isCircle(a) {
|
|
322
|
+
return a.object.type === PdfAnnotationSubtype.CIRCLE;
|
|
323
|
+
}
|
|
324
|
+
function isPolygon(a) {
|
|
325
|
+
return a.object.type === PdfAnnotationSubtype.POLYGON;
|
|
326
|
+
}
|
|
327
|
+
function isSquare(a) {
|
|
328
|
+
return a.object.type === PdfAnnotationSubtype.SQUARE;
|
|
329
|
+
}
|
|
330
|
+
function isLine(a) {
|
|
331
|
+
return a.object.type === PdfAnnotationSubtype.LINE;
|
|
332
|
+
}
|
|
333
|
+
function isPolyline(a) {
|
|
334
|
+
return a.object.type === PdfAnnotationSubtype.POLYLINE;
|
|
335
|
+
}
|
|
336
|
+
function isHighlight(a) {
|
|
337
|
+
return a.object.type === PdfAnnotationSubtype.HIGHLIGHT;
|
|
338
|
+
}
|
|
339
|
+
function isUnderline(a) {
|
|
340
|
+
return a.object.type === PdfAnnotationSubtype.UNDERLINE;
|
|
341
|
+
}
|
|
342
|
+
function isStrikeout(a) {
|
|
343
|
+
return a.object.type === PdfAnnotationSubtype.STRIKEOUT;
|
|
344
|
+
}
|
|
345
|
+
function isSquiggly(a) {
|
|
346
|
+
return a.object.type === PdfAnnotationSubtype.SQUIGGLY;
|
|
347
|
+
}
|
|
348
|
+
function isTextMarkup(a) {
|
|
349
|
+
return isHighlight(a) || isUnderline(a) || isStrikeout(a) || isSquiggly(a);
|
|
350
|
+
}
|
|
351
|
+
function isFreeText(a) {
|
|
352
|
+
return a.object.type === PdfAnnotationSubtype.FREETEXT;
|
|
353
|
+
}
|
|
354
|
+
function isHighlightDefaults(defaults) {
|
|
355
|
+
return defaults.subtype === PdfAnnotationSubtype.HIGHLIGHT;
|
|
356
|
+
}
|
|
357
|
+
function isUnderlineDefaults(defaults) {
|
|
358
|
+
return defaults.subtype === PdfAnnotationSubtype.UNDERLINE;
|
|
359
|
+
}
|
|
360
|
+
function isStrikeoutDefaults(defaults) {
|
|
361
|
+
return defaults.subtype === PdfAnnotationSubtype.STRIKEOUT;
|
|
362
|
+
}
|
|
363
|
+
function isSquigglyDefaults(defaults) {
|
|
364
|
+
return defaults.subtype === PdfAnnotationSubtype.SQUIGGLY;
|
|
365
|
+
}
|
|
366
|
+
function isTextMarkupDefaults(defaults) {
|
|
367
|
+
return isHighlightDefaults(defaults) || isUnderlineDefaults(defaults) || isStrikeoutDefaults(defaults) || isSquigglyDefaults(defaults);
|
|
368
|
+
}
|
|
107
369
|
const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
108
370
|
constructor(id, registry, engine, config) {
|
|
109
371
|
super(id, registry);
|
|
@@ -152,19 +414,17 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
152
414
|
(_c = this.selection) == null ? void 0 : _c.onEndSelection(() => {
|
|
153
415
|
var _a2, _b2;
|
|
154
416
|
if (!this.state.activeVariant) return;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
417
|
+
const defaults = this.state.toolDefaults[this.state.activeVariant];
|
|
418
|
+
if (!defaults || !isTextMarkupDefaults(defaults)) return;
|
|
158
419
|
const formattedSelection = (_a2 = this.selection) == null ? void 0 : _a2.getFormattedSelection();
|
|
159
420
|
if (!formattedSelection) return;
|
|
160
421
|
for (const selection of formattedSelection) {
|
|
161
422
|
const rect = selection.rect;
|
|
162
423
|
const segmentRects = selection.segmentRects;
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
const blendMode = this.state.toolDefaults[type].blendMode ?? PdfBlendMode.Normal;
|
|
424
|
+
const subtype = defaults.subtype;
|
|
425
|
+
const color = defaults.color;
|
|
426
|
+
const opacity = defaults.opacity;
|
|
427
|
+
const blendMode = defaults.blendMode ?? PdfBlendMode.Normal;
|
|
168
428
|
this.createAnnotation(selection.pageIndex, {
|
|
169
429
|
type: subtype,
|
|
170
430
|
rect,
|
|
@@ -223,6 +483,9 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
223
483
|
(_b = this.interactionManager) == null ? void 0 : _b.activate("default");
|
|
224
484
|
}
|
|
225
485
|
},
|
|
486
|
+
getSubtypeAndIntentByVariant: (variantKey) => {
|
|
487
|
+
return parseVariantKey(variantKey);
|
|
488
|
+
},
|
|
226
489
|
getToolDefaults: (variantKey) => {
|
|
227
490
|
const defaults = this.state.toolDefaults[variantKey];
|
|
228
491
|
if (!defaults) {
|
|
@@ -231,19 +494,10 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
231
494
|
return defaults;
|
|
232
495
|
},
|
|
233
496
|
getToolDefaultsBySubtypeAndIntent: (subtype, intent) => {
|
|
234
|
-
|
|
235
|
-
const defaults = this.state.toolDefaults[variantKey];
|
|
236
|
-
if (!defaults) {
|
|
237
|
-
throw new Error(`No defaults found for variant: ${variantKey}`);
|
|
238
|
-
}
|
|
239
|
-
return defaults;
|
|
497
|
+
return getToolDefaultsBySubtypeAndIntent(this.state, subtype, intent);
|
|
240
498
|
},
|
|
241
499
|
getToolDefaultsBySubtype: (subtype) => {
|
|
242
|
-
|
|
243
|
-
if (!defaults) {
|
|
244
|
-
throw new Error(`No defaults found for subtype: ${subtype}`);
|
|
245
|
-
}
|
|
246
|
-
return defaults;
|
|
500
|
+
return getToolDefaultsBySubtypeAndIntent(this.state, subtype);
|
|
247
501
|
},
|
|
248
502
|
setToolDefaults: (variantKey, patch) => {
|
|
249
503
|
this.dispatch(updateToolDefaults(variantKey, patch));
|
|
@@ -340,20 +594,26 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
340
594
|
};
|
|
341
595
|
this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
|
|
342
596
|
}
|
|
597
|
+
buildPatch(original, patch) {
|
|
598
|
+
if ("rect" in patch) return patch;
|
|
599
|
+
const merged = { ...original, ...patch };
|
|
600
|
+
return { ...patch, rect: deriveRect(merged) };
|
|
601
|
+
}
|
|
343
602
|
updateAnnotation(pageIndex, localId, patch) {
|
|
603
|
+
const originalObject = this.state.byUid[makeUid$1(pageIndex, localId)].object;
|
|
604
|
+
const finalPatch = this.buildPatch(originalObject, patch);
|
|
344
605
|
if (!this.history) {
|
|
345
|
-
this.dispatch(patchAnnotation(pageIndex, localId,
|
|
606
|
+
this.dispatch(patchAnnotation(pageIndex, localId, finalPatch));
|
|
346
607
|
if (this.config.autoCommit !== false) {
|
|
347
608
|
this.commit();
|
|
348
609
|
}
|
|
349
610
|
return;
|
|
350
611
|
}
|
|
351
|
-
const originalObject = this.state.byUid[makeUid$1(pageIndex, localId)].object;
|
|
352
612
|
const originalPatch = Object.fromEntries(
|
|
353
613
|
Object.keys(patch).map((key) => [key, originalObject[key]])
|
|
354
614
|
);
|
|
355
615
|
const command = {
|
|
356
|
-
execute: () => this.dispatch(patchAnnotation(pageIndex, localId,
|
|
616
|
+
execute: () => this.dispatch(patchAnnotation(pageIndex, localId, finalPatch)),
|
|
357
617
|
undo: () => this.dispatch(patchAnnotation(pageIndex, localId, originalPatch))
|
|
358
618
|
};
|
|
359
619
|
this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
|
|
@@ -454,7 +714,9 @@ const DEFAULT_COLORS = [
|
|
|
454
714
|
"#25D2D1",
|
|
455
715
|
"#597CE2",
|
|
456
716
|
"#C544CE",
|
|
457
|
-
"#7D2E25"
|
|
717
|
+
"#7D2E25",
|
|
718
|
+
"#000000",
|
|
719
|
+
"#FFFFFF"
|
|
458
720
|
];
|
|
459
721
|
const patchAnno = (state, uid, patch) => {
|
|
460
722
|
const prev = state.byUid[uid];
|
|
@@ -526,12 +788,91 @@ const initialState = (cfg) => ({
|
|
|
526
788
|
[makeVariantKey(PdfAnnotationSubtype.INK, "InkHighlight")]: {
|
|
527
789
|
name: "Ink Highlight",
|
|
528
790
|
subtype: PdfAnnotationSubtype.INK,
|
|
791
|
+
intent: "InkHighlight",
|
|
529
792
|
interaction: { mode: "inkHighlight", exclusive: true, cursor: "crosshair" },
|
|
530
793
|
color: "#E44234",
|
|
531
794
|
opacity: 1,
|
|
532
795
|
strokeWidth: 11,
|
|
533
796
|
blendMode: PdfBlendMode.Multiply
|
|
534
797
|
},
|
|
798
|
+
[makeVariantKey(PdfAnnotationSubtype.CIRCLE)]: {
|
|
799
|
+
name: "Circle",
|
|
800
|
+
subtype: PdfAnnotationSubtype.CIRCLE,
|
|
801
|
+
interaction: { mode: "circle", exclusive: true, cursor: "crosshair" },
|
|
802
|
+
color: "transparent",
|
|
803
|
+
opacity: 1,
|
|
804
|
+
strokeWidth: 4,
|
|
805
|
+
strokeColor: "#E44234",
|
|
806
|
+
strokeStyle: PdfAnnotationBorderStyle.SOLID
|
|
807
|
+
},
|
|
808
|
+
[makeVariantKey(PdfAnnotationSubtype.SQUARE)]: {
|
|
809
|
+
name: "Square",
|
|
810
|
+
subtype: PdfAnnotationSubtype.SQUARE,
|
|
811
|
+
interaction: { mode: "square", exclusive: true, cursor: "crosshair" },
|
|
812
|
+
color: "transparent",
|
|
813
|
+
opacity: 1,
|
|
814
|
+
strokeWidth: 4,
|
|
815
|
+
strokeColor: "#E44234",
|
|
816
|
+
strokeStyle: PdfAnnotationBorderStyle.SOLID
|
|
817
|
+
},
|
|
818
|
+
[makeVariantKey(PdfAnnotationSubtype.LINE)]: {
|
|
819
|
+
name: "Line",
|
|
820
|
+
subtype: PdfAnnotationSubtype.LINE,
|
|
821
|
+
interaction: { mode: "line", exclusive: true, cursor: "crosshair" },
|
|
822
|
+
color: "transparent",
|
|
823
|
+
opacity: 1,
|
|
824
|
+
strokeWidth: 4,
|
|
825
|
+
strokeColor: "#E44234",
|
|
826
|
+
strokeStyle: PdfAnnotationBorderStyle.SOLID
|
|
827
|
+
},
|
|
828
|
+
[makeVariantKey(PdfAnnotationSubtype.LINE, "LineArrow")]: {
|
|
829
|
+
name: "Line Arrow",
|
|
830
|
+
subtype: PdfAnnotationSubtype.LINE,
|
|
831
|
+
interaction: { mode: "lineArrow", exclusive: true, cursor: "crosshair" },
|
|
832
|
+
color: "transparent",
|
|
833
|
+
intent: "LineArrow",
|
|
834
|
+
opacity: 1,
|
|
835
|
+
strokeWidth: 4,
|
|
836
|
+
strokeColor: "#E44234",
|
|
837
|
+
strokeStyle: PdfAnnotationBorderStyle.SOLID,
|
|
838
|
+
lineEndings: {
|
|
839
|
+
start: PdfAnnotationLineEnding.None,
|
|
840
|
+
end: PdfAnnotationLineEnding.OpenArrow
|
|
841
|
+
}
|
|
842
|
+
},
|
|
843
|
+
[makeVariantKey(PdfAnnotationSubtype.POLYLINE)]: {
|
|
844
|
+
name: "Polyline",
|
|
845
|
+
subtype: PdfAnnotationSubtype.POLYLINE,
|
|
846
|
+
interaction: { mode: "polyline", exclusive: true, cursor: "crosshair" },
|
|
847
|
+
color: "transparent",
|
|
848
|
+
opacity: 1,
|
|
849
|
+
strokeWidth: 4,
|
|
850
|
+
strokeColor: "#E44234",
|
|
851
|
+
strokeStyle: PdfAnnotationBorderStyle.SOLID
|
|
852
|
+
},
|
|
853
|
+
[makeVariantKey(PdfAnnotationSubtype.POLYGON)]: {
|
|
854
|
+
name: "Polygon",
|
|
855
|
+
subtype: PdfAnnotationSubtype.POLYGON,
|
|
856
|
+
interaction: { mode: "polygon", exclusive: true, cursor: "crosshair" },
|
|
857
|
+
color: "transparent",
|
|
858
|
+
opacity: 1,
|
|
859
|
+
strokeWidth: 4,
|
|
860
|
+
strokeColor: "#E44234",
|
|
861
|
+
strokeStyle: PdfAnnotationBorderStyle.SOLID
|
|
862
|
+
},
|
|
863
|
+
[makeVariantKey(PdfAnnotationSubtype.FREETEXT)]: {
|
|
864
|
+
name: "Free Text",
|
|
865
|
+
subtype: PdfAnnotationSubtype.FREETEXT,
|
|
866
|
+
interaction: { mode: "freeText", exclusive: true, cursor: "crosshair" },
|
|
867
|
+
backgroundColor: "transparent",
|
|
868
|
+
opacity: 1,
|
|
869
|
+
fontSize: 14,
|
|
870
|
+
fontColor: "#E44234",
|
|
871
|
+
content: "Insert text here",
|
|
872
|
+
fontFamily: PdfStandardFont.Helvetica,
|
|
873
|
+
textAlign: PdfTextAlignment.Left,
|
|
874
|
+
verticalAlign: PdfVerticalAlignment.Top
|
|
875
|
+
},
|
|
535
876
|
...cfg.toolDefaults
|
|
536
877
|
},
|
|
537
878
|
colorPresets: cfg.colorPresets ?? DEFAULT_COLORS,
|
|
@@ -549,8 +890,8 @@ const reducer = (state, action) => {
|
|
|
549
890
|
for (const uid of oldUidsOnPage) {
|
|
550
891
|
delete newByUid[uid];
|
|
551
892
|
}
|
|
552
|
-
const newUidsOnPage = list.map((a,
|
|
553
|
-
const localId = Date.now() + Math.random() +
|
|
893
|
+
const newUidsOnPage = list.map((a, index2) => {
|
|
894
|
+
const localId = Date.now() + Math.random() + index2;
|
|
554
895
|
const uid = makeUid$1(pageIndex, localId);
|
|
555
896
|
newByUid[uid] = { localId, pdfId: a.id, commitState: "synced", object: a };
|
|
556
897
|
return uid;
|
|
@@ -680,11 +1021,30 @@ export {
|
|
|
680
1021
|
getSelectedAnnotationByPageIndex,
|
|
681
1022
|
getSelectedAnnotationVariant,
|
|
682
1023
|
getSelectedAnnotationWithPageIndex,
|
|
1024
|
+
getToolDefaultsBySubtypeAndIntent,
|
|
683
1025
|
isAnnotationSelected,
|
|
1026
|
+
isCircle,
|
|
1027
|
+
isFreeText,
|
|
1028
|
+
isHighlight,
|
|
1029
|
+
isHighlightDefaults,
|
|
684
1030
|
isInAnnotationVariant,
|
|
1031
|
+
isInk,
|
|
1032
|
+
isLine,
|
|
1033
|
+
isPolygon,
|
|
1034
|
+
isPolyline,
|
|
1035
|
+
isSquare,
|
|
1036
|
+
isSquiggly,
|
|
1037
|
+
isSquigglyDefaults,
|
|
1038
|
+
isStrikeout,
|
|
1039
|
+
isStrikeoutDefaults,
|
|
1040
|
+
isTextMarkup,
|
|
1041
|
+
isTextMarkupDefaults,
|
|
1042
|
+
isUnderline,
|
|
1043
|
+
isUnderlineDefaults,
|
|
685
1044
|
makeVariantKey,
|
|
686
1045
|
manifest,
|
|
687
1046
|
parseVariantKey,
|
|
1047
|
+
index as patching,
|
|
688
1048
|
variantKeyFromAnnotation
|
|
689
1049
|
};
|
|
690
1050
|
//# sourceMappingURL=index.js.map
|