@embedpdf/plugin-annotation 1.0.12 → 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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +345 -22
- package/dist/index.js.map +1 -1
- package/dist/lib/annotation-plugin.d.ts +1 -0
- package/dist/lib/helpers.d.ts +18 -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 +55 -8
- package/dist/preact/adapter.d.ts +1 -1
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +2062 -421
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +2061 -420
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/annotation-container.d.ts +12 -7
- 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/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 +12 -7
- 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/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, 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,217 @@ 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" }));
|
|
107
318
|
const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
108
319
|
constructor(id, registry, engine, config) {
|
|
109
320
|
super(id, registry);
|
|
@@ -223,6 +434,9 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
223
434
|
(_b = this.interactionManager) == null ? void 0 : _b.activate("default");
|
|
224
435
|
}
|
|
225
436
|
},
|
|
437
|
+
getSubtypeAndIntentByVariant: (variantKey) => {
|
|
438
|
+
return parseVariantKey(variantKey);
|
|
439
|
+
},
|
|
226
440
|
getToolDefaults: (variantKey) => {
|
|
227
441
|
const defaults = this.state.toolDefaults[variantKey];
|
|
228
442
|
if (!defaults) {
|
|
@@ -231,19 +445,10 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
231
445
|
return defaults;
|
|
232
446
|
},
|
|
233
447
|
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;
|
|
448
|
+
return getToolDefaultsBySubtypeAndIntent(this.state, subtype, intent);
|
|
240
449
|
},
|
|
241
450
|
getToolDefaultsBySubtype: (subtype) => {
|
|
242
|
-
|
|
243
|
-
if (!defaults) {
|
|
244
|
-
throw new Error(`No defaults found for subtype: ${subtype}`);
|
|
245
|
-
}
|
|
246
|
-
return defaults;
|
|
451
|
+
return getToolDefaultsBySubtypeAndIntent(this.state, subtype);
|
|
247
452
|
},
|
|
248
453
|
setToolDefaults: (variantKey, patch) => {
|
|
249
454
|
this.dispatch(updateToolDefaults(variantKey, patch));
|
|
@@ -340,20 +545,26 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
340
545
|
};
|
|
341
546
|
this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
|
|
342
547
|
}
|
|
548
|
+
buildPatch(original, patch) {
|
|
549
|
+
if ("rect" in patch) return patch;
|
|
550
|
+
const merged = { ...original, ...patch };
|
|
551
|
+
return { ...patch, rect: deriveRect(merged) };
|
|
552
|
+
}
|
|
343
553
|
updateAnnotation(pageIndex, localId, patch) {
|
|
554
|
+
const originalObject = this.state.byUid[makeUid$1(pageIndex, localId)].object;
|
|
555
|
+
const finalPatch = this.buildPatch(originalObject, patch);
|
|
344
556
|
if (!this.history) {
|
|
345
|
-
this.dispatch(patchAnnotation(pageIndex, localId,
|
|
557
|
+
this.dispatch(patchAnnotation(pageIndex, localId, finalPatch));
|
|
346
558
|
if (this.config.autoCommit !== false) {
|
|
347
559
|
this.commit();
|
|
348
560
|
}
|
|
349
561
|
return;
|
|
350
562
|
}
|
|
351
|
-
const originalObject = this.state.byUid[makeUid$1(pageIndex, localId)].object;
|
|
352
563
|
const originalPatch = Object.fromEntries(
|
|
353
564
|
Object.keys(patch).map((key) => [key, originalObject[key]])
|
|
354
565
|
);
|
|
355
566
|
const command = {
|
|
356
|
-
execute: () => this.dispatch(patchAnnotation(pageIndex, localId,
|
|
567
|
+
execute: () => this.dispatch(patchAnnotation(pageIndex, localId, finalPatch)),
|
|
357
568
|
undo: () => this.dispatch(patchAnnotation(pageIndex, localId, originalPatch))
|
|
358
569
|
};
|
|
359
570
|
this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
|
|
@@ -526,12 +737,78 @@ const initialState = (cfg) => ({
|
|
|
526
737
|
[makeVariantKey(PdfAnnotationSubtype.INK, "InkHighlight")]: {
|
|
527
738
|
name: "Ink Highlight",
|
|
528
739
|
subtype: PdfAnnotationSubtype.INK,
|
|
740
|
+
intent: "InkHighlight",
|
|
529
741
|
interaction: { mode: "inkHighlight", exclusive: true, cursor: "crosshair" },
|
|
530
742
|
color: "#E44234",
|
|
531
743
|
opacity: 1,
|
|
532
744
|
strokeWidth: 11,
|
|
533
745
|
blendMode: PdfBlendMode.Multiply
|
|
534
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
|
|
811
|
+
},
|
|
535
812
|
...cfg.toolDefaults
|
|
536
813
|
},
|
|
537
814
|
colorPresets: cfg.colorPresets ?? DEFAULT_COLORS,
|
|
@@ -549,8 +826,8 @@ const reducer = (state, action) => {
|
|
|
549
826
|
for (const uid of oldUidsOnPage) {
|
|
550
827
|
delete newByUid[uid];
|
|
551
828
|
}
|
|
552
|
-
const newUidsOnPage = list.map((a,
|
|
553
|
-
const localId = Date.now() + Math.random() +
|
|
829
|
+
const newUidsOnPage = list.map((a, index2) => {
|
|
830
|
+
const localId = Date.now() + Math.random() + index2;
|
|
554
831
|
const uid = makeUid$1(pageIndex, localId);
|
|
555
832
|
newByUid[uid] = { localId, pdfId: a.id, commitState: "synced", object: a };
|
|
556
833
|
return uid;
|
|
@@ -664,6 +941,39 @@ const reducer = (state, action) => {
|
|
|
664
941
|
return state;
|
|
665
942
|
}
|
|
666
943
|
};
|
|
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
|
+
}
|
|
667
977
|
const AnnotationPluginPackage = {
|
|
668
978
|
manifest,
|
|
669
979
|
create: (registry, engine, config) => new AnnotationPlugin(ANNOTATION_PLUGIN_ID, registry, engine, config),
|
|
@@ -680,11 +990,24 @@ export {
|
|
|
680
990
|
getSelectedAnnotationByPageIndex,
|
|
681
991
|
getSelectedAnnotationVariant,
|
|
682
992
|
getSelectedAnnotationWithPageIndex,
|
|
993
|
+
getToolDefaultsBySubtypeAndIntent,
|
|
683
994
|
isAnnotationSelected,
|
|
995
|
+
isCircle,
|
|
996
|
+
isHighlight,
|
|
684
997
|
isInAnnotationVariant,
|
|
998
|
+
isInk,
|
|
999
|
+
isLine,
|
|
1000
|
+
isPolygon,
|
|
1001
|
+
isPolyline,
|
|
1002
|
+
isSquare,
|
|
1003
|
+
isSquiggly,
|
|
1004
|
+
isStrikeout,
|
|
1005
|
+
isTextMarkup,
|
|
1006
|
+
isUnderline,
|
|
685
1007
|
makeVariantKey,
|
|
686
1008
|
manifest,
|
|
687
1009
|
parseVariantKey,
|
|
1010
|
+
index as patching,
|
|
688
1011
|
variantKeyFromAnnotation
|
|
689
1012
|
};
|
|
690
1013
|
//# sourceMappingURL=index.js.map
|