@embedpdf/plugin-annotation 1.0.11 → 1.0.12
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 +2 -693
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -266
- package/dist/index.js +180 -158
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +104 -0
- package/dist/lib/annotation-plugin.d.ts +33 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/lib/selectors.d.ts +13 -0
- package/dist/lib/types.d.ts +121 -0
- package/dist/lib/utils.d.ts +11 -0
- package/dist/lib/variant-key.d.ts +8 -0
- package/dist/preact/adapter.d.ts +8 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -1038
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -28
- package/dist/preact/index.js +126 -156
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/interaction-manager.d.ts +1 -0
- package/dist/preact/selection.d.ts +1 -0
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +983 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/interaction-manager.d.ts +1 -0
- package/dist/react/selection.d.ts +1 -0
- package/dist/shared-preact/components/annotation-container.d.ts +19 -0
- package/dist/shared-preact/components/annotation-layer.d.ts +11 -0
- package/dist/shared-preact/components/annotations/ink-highlight-paint.d.ts +0 -0
- package/dist/shared-preact/components/annotations/ink-paint.d.ts +17 -0
- package/dist/shared-preact/components/annotations/ink.d.ts +23 -0
- package/dist/shared-preact/components/annotations.d.ts +7 -0
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/render-annotation.d.ts +11 -0
- package/dist/shared-preact/components/text-markup/highlight.d.ts +13 -0
- package/dist/shared-preact/components/text-markup/squiggly.d.ts +13 -0
- package/dist/shared-preact/components/text-markup/strikeout.d.ts +13 -0
- package/dist/shared-preact/components/text-markup/underline.d.ts +13 -0
- package/dist/shared-preact/components/text-markup.d.ts +6 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-annotation.d.ts +11 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-preact/resize-ink.d.ts +17 -0
- package/dist/shared-preact/types.d.ts +1 -0
- package/dist/shared-react/components/annotation-container.d.ts +19 -0
- package/dist/shared-react/components/annotation-layer.d.ts +11 -0
- package/dist/shared-react/components/annotations/ink-highlight-paint.d.ts +0 -0
- package/dist/shared-react/components/annotations/ink-paint.d.ts +17 -0
- package/dist/shared-react/components/annotations/ink.d.ts +23 -0
- package/dist/shared-react/components/annotations.d.ts +7 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/render-annotation.d.ts +11 -0
- package/dist/shared-react/components/text-markup/highlight.d.ts +13 -0
- package/dist/shared-react/components/text-markup/squiggly.d.ts +13 -0
- package/dist/shared-react/components/text-markup/strikeout.d.ts +13 -0
- package/dist/shared-react/components/text-markup/underline.d.ts +13 -0
- package/dist/shared-react/components/text-markup.d.ts +6 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-annotation.d.ts +11 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/shared-react/resize-ink.d.ts +17 -0
- package/dist/shared-react/types.d.ts +1 -0
- package/package.json +17 -15
- package/dist/index.d.cts +0 -266
- package/dist/preact/index.d.cts +0 -28
package/dist/preact/index.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
var useAnnotationCapability = () => useCapability(AnnotationPlugin.id);
|
|
6
|
-
|
|
7
|
-
// src/preact/components/annotations.tsx
|
|
8
|
-
import { PdfAnnotationSubtype as PdfAnnotationSubtype2 } from "@embedpdf/models";
|
|
1
|
+
import { usePlugin, useCapability } from "@embedpdf/core/preact";
|
|
2
|
+
import { AnnotationPlugin, getAnnotationsByPageIndex, getSelectedAnnotationByPageIndex, makeVariantKey } from "@embedpdf/plugin-annotation";
|
|
3
|
+
import { jsxs, Fragment, jsx } from "preact/jsx-runtime";
|
|
4
|
+
import { restoreOffset, PdfAnnotationSubtype, blendModeToCss, PdfBlendMode } from "@embedpdf/models";
|
|
9
5
|
import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/preact";
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// src/preact/components/annotation-container.tsx
|
|
17
|
-
import { useEffect, useRef, useState } from "preact/hooks";
|
|
18
|
-
import { restoreOffset } from "@embedpdf/models";
|
|
19
|
-
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
6
|
+
import "preact";
|
|
7
|
+
import { useRef, useState, useEffect, useMemo, useCallback } from "preact/hooks";
|
|
8
|
+
import { useSelectionCapability } from "@embedpdf/plugin-selection/preact";
|
|
9
|
+
const useAnnotationPlugin = () => usePlugin(AnnotationPlugin.id);
|
|
10
|
+
const useAnnotationCapability = () => useCapability(AnnotationPlugin.id);
|
|
20
11
|
function AnnotationContainer({
|
|
21
12
|
scale,
|
|
22
13
|
pageIndex,
|
|
@@ -44,6 +35,7 @@ function AnnotationContainer({
|
|
|
44
35
|
setPreviewObject(null);
|
|
45
36
|
}, [trackedAnnotation]);
|
|
46
37
|
const handlePointerDown = (e) => {
|
|
38
|
+
var _a;
|
|
47
39
|
if (!isSelected) return;
|
|
48
40
|
e.stopPropagation();
|
|
49
41
|
e.preventDefault();
|
|
@@ -58,7 +50,7 @@ function AnnotationContainer({
|
|
|
58
50
|
}
|
|
59
51
|
setStartPos({ x: e.clientX, y: e.clientY });
|
|
60
52
|
setStartRect(currentRect);
|
|
61
|
-
ref.current
|
|
53
|
+
(_a = ref.current) == null ? void 0 : _a.setPointerCapture(e.pointerId);
|
|
62
54
|
};
|
|
63
55
|
const handlePointerMove = (e) => {
|
|
64
56
|
if (dragState === "idle" || !startPos || !startRect) return;
|
|
@@ -101,11 +93,12 @@ function AnnotationContainer({
|
|
|
101
93
|
setPreviewObject(previewPatch);
|
|
102
94
|
};
|
|
103
95
|
const handlePointerUp = (e) => {
|
|
96
|
+
var _a;
|
|
104
97
|
if (dragState === "idle") return;
|
|
105
98
|
const usedDirection = resizeDirection || "bottom-right";
|
|
106
99
|
setDragState("idle");
|
|
107
100
|
setResizeDirection(null);
|
|
108
|
-
ref.current
|
|
101
|
+
(_a = ref.current) == null ? void 0 : _a.releasePointerCapture(e.pointerId);
|
|
109
102
|
if (annotationProvides && trackedAnnotation) {
|
|
110
103
|
let patch = { rect: currentRect };
|
|
111
104
|
if (computeResizePatch && usedDirection) {
|
|
@@ -214,9 +207,6 @@ function AnnotationContainer({
|
|
|
214
207
|
}
|
|
215
208
|
);
|
|
216
209
|
}
|
|
217
|
-
|
|
218
|
-
// src/preact/components/text-markup/highlight.tsx
|
|
219
|
-
import { Fragment as Fragment2, jsx as jsx2 } from "preact/jsx-runtime";
|
|
220
210
|
function Highlight({
|
|
221
211
|
color = "#FFFF00",
|
|
222
212
|
opacity = 0.5,
|
|
@@ -227,7 +217,7 @@ function Highlight({
|
|
|
227
217
|
style,
|
|
228
218
|
...props
|
|
229
219
|
}) {
|
|
230
|
-
return /* @__PURE__ */
|
|
220
|
+
return /* @__PURE__ */ jsx(Fragment, { children: rects.map((b, i) => /* @__PURE__ */ jsx(
|
|
231
221
|
"div",
|
|
232
222
|
{
|
|
233
223
|
onMouseDown: onClick,
|
|
@@ -241,7 +231,7 @@ function Highlight({
|
|
|
241
231
|
opacity,
|
|
242
232
|
pointerEvents: onClick ? "auto" : "none",
|
|
243
233
|
cursor: onClick ? "pointer" : "default",
|
|
244
|
-
zIndex: onClick ? 1 :
|
|
234
|
+
zIndex: onClick ? 1 : void 0,
|
|
245
235
|
...style
|
|
246
236
|
},
|
|
247
237
|
...props
|
|
@@ -249,9 +239,6 @@ function Highlight({
|
|
|
249
239
|
i
|
|
250
240
|
)) });
|
|
251
241
|
}
|
|
252
|
-
|
|
253
|
-
// src/preact/components/text-markup/underline.tsx
|
|
254
|
-
import { Fragment as Fragment3, jsx as jsx3 } from "preact/jsx-runtime";
|
|
255
242
|
function Underline({
|
|
256
243
|
color = "#FFFF00",
|
|
257
244
|
opacity = 0.5,
|
|
@@ -263,7 +250,7 @@ function Underline({
|
|
|
263
250
|
...props
|
|
264
251
|
}) {
|
|
265
252
|
const thickness = 2 * scale;
|
|
266
|
-
return /* @__PURE__ */
|
|
253
|
+
return /* @__PURE__ */ jsx(Fragment, { children: rects.map((r, i) => /* @__PURE__ */ jsx(
|
|
267
254
|
"div",
|
|
268
255
|
{
|
|
269
256
|
onMouseDown: onClick,
|
|
@@ -280,7 +267,7 @@ function Underline({
|
|
|
280
267
|
...style
|
|
281
268
|
},
|
|
282
269
|
...props,
|
|
283
|
-
children: /* @__PURE__ */
|
|
270
|
+
children: /* @__PURE__ */ jsx(
|
|
284
271
|
"div",
|
|
285
272
|
{
|
|
286
273
|
style: {
|
|
@@ -299,9 +286,6 @@ function Underline({
|
|
|
299
286
|
i
|
|
300
287
|
)) });
|
|
301
288
|
}
|
|
302
|
-
|
|
303
|
-
// src/preact/components/text-markup/strikeout.tsx
|
|
304
|
-
import { Fragment as Fragment4, jsx as jsx4 } from "preact/jsx-runtime";
|
|
305
289
|
function Strikeout({
|
|
306
290
|
color = "#FFFF00",
|
|
307
291
|
opacity = 0.5,
|
|
@@ -313,7 +297,7 @@ function Strikeout({
|
|
|
313
297
|
...props
|
|
314
298
|
}) {
|
|
315
299
|
const thickness = 2 * scale;
|
|
316
|
-
return /* @__PURE__ */
|
|
300
|
+
return /* @__PURE__ */ jsx(Fragment, { children: rects.map((r, i) => /* @__PURE__ */ jsx(
|
|
317
301
|
"div",
|
|
318
302
|
{
|
|
319
303
|
onMouseDown: onClick,
|
|
@@ -330,7 +314,7 @@ function Strikeout({
|
|
|
330
314
|
...style
|
|
331
315
|
},
|
|
332
316
|
...props,
|
|
333
|
-
children: /* @__PURE__ */
|
|
317
|
+
children: /* @__PURE__ */ jsx(
|
|
334
318
|
"div",
|
|
335
319
|
{
|
|
336
320
|
style: {
|
|
@@ -350,9 +334,6 @@ function Strikeout({
|
|
|
350
334
|
i
|
|
351
335
|
)) });
|
|
352
336
|
}
|
|
353
|
-
|
|
354
|
-
// src/preact/components/text-markup/squiggly.tsx
|
|
355
|
-
import { Fragment as Fragment5, jsx as jsx5 } from "preact/jsx-runtime";
|
|
356
337
|
function Squiggly({
|
|
357
338
|
color = "#FFFF00",
|
|
358
339
|
opacity = 0.5,
|
|
@@ -370,7 +351,7 @@ function Squiggly({
|
|
|
370
351
|
fill="none" stroke="${color}" stroke-width="${amplitude}" stroke-linecap="round"/>
|
|
371
352
|
</svg>`;
|
|
372
353
|
const svgDataUri = `url("data:image/svg+xml;utf8,${encodeURIComponent(svg)}")`;
|
|
373
|
-
return /* @__PURE__ */
|
|
354
|
+
return /* @__PURE__ */ jsx(Fragment, { children: rects.map((r, i) => /* @__PURE__ */ jsx(
|
|
374
355
|
"div",
|
|
375
356
|
{
|
|
376
357
|
onMouseDown: onClick,
|
|
@@ -387,7 +368,7 @@ function Squiggly({
|
|
|
387
368
|
...style
|
|
388
369
|
},
|
|
389
370
|
...props,
|
|
390
|
-
children: /* @__PURE__ */
|
|
371
|
+
children: /* @__PURE__ */ jsx(
|
|
391
372
|
"div",
|
|
392
373
|
{
|
|
393
374
|
style: {
|
|
@@ -408,10 +389,6 @@ function Squiggly({
|
|
|
408
389
|
i
|
|
409
390
|
)) });
|
|
410
391
|
}
|
|
411
|
-
|
|
412
|
-
// src/preact/components/annotations/ink.tsx
|
|
413
|
-
import { useMemo } from "preact/hooks";
|
|
414
|
-
import { jsx as jsx6 } from "preact/jsx-runtime";
|
|
415
392
|
function Ink({
|
|
416
393
|
color = "#000000",
|
|
417
394
|
opacity = 1,
|
|
@@ -434,7 +411,7 @@ function Ink({
|
|
|
434
411
|
}, [inkList, rect]);
|
|
435
412
|
const width = rect.size.width * scale;
|
|
436
413
|
const height = rect.size.height * scale;
|
|
437
|
-
return /* @__PURE__ */
|
|
414
|
+
return /* @__PURE__ */ jsx(
|
|
438
415
|
"svg",
|
|
439
416
|
{
|
|
440
417
|
style: {
|
|
@@ -447,7 +424,7 @@ function Ink({
|
|
|
447
424
|
width,
|
|
448
425
|
height,
|
|
449
426
|
viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
|
|
450
|
-
children: paths.map((d, i) => /* @__PURE__ */
|
|
427
|
+
children: paths.map((d, i) => /* @__PURE__ */ jsx(
|
|
451
428
|
"path",
|
|
452
429
|
{
|
|
453
430
|
d,
|
|
@@ -468,14 +445,6 @@ function Ink({
|
|
|
468
445
|
}
|
|
469
446
|
);
|
|
470
447
|
}
|
|
471
|
-
|
|
472
|
-
// src/preact/components/annotations.tsx
|
|
473
|
-
import { useSelectionCapability } from "@embedpdf/plugin-selection/preact";
|
|
474
|
-
|
|
475
|
-
// src/shared/resize-ink.ts
|
|
476
|
-
import {
|
|
477
|
-
PdfAnnotationSubtype
|
|
478
|
-
} from "@embedpdf/models";
|
|
479
448
|
function resizeInkAnnotation(original, newRect, direction, uniform = false) {
|
|
480
449
|
if (original.type !== PdfAnnotationSubtype.INK) {
|
|
481
450
|
throw new Error("resizeInkAnnotation: original is not an ink annotation");
|
|
@@ -518,17 +487,14 @@ function resizeInkAnnotation(original, newRect, direction, uniform = false) {
|
|
|
518
487
|
strokeWidth: newStrokeWidth
|
|
519
488
|
};
|
|
520
489
|
}
|
|
521
|
-
|
|
522
|
-
// src/preact/components/annotations.tsx
|
|
523
|
-
import { Fragment as Fragment6, jsx as jsx7 } from "preact/jsx-runtime";
|
|
524
490
|
function Annotations(annotationsProps) {
|
|
525
491
|
const { pageIndex, scale } = annotationsProps;
|
|
526
492
|
const { provides: annotationProvides } = useAnnotationCapability();
|
|
527
493
|
const { provides: selectionProvides } = useSelectionCapability();
|
|
528
|
-
const [annotations, setAnnotations] =
|
|
494
|
+
const [annotations, setAnnotations] = useState([]);
|
|
529
495
|
const { register } = usePointerHandlers({ pageIndex });
|
|
530
|
-
const [selectionState, setSelectionState] =
|
|
531
|
-
|
|
496
|
+
const [selectionState, setSelectionState] = useState(null);
|
|
497
|
+
useEffect(() => {
|
|
532
498
|
if (annotationProvides) {
|
|
533
499
|
annotationProvides.onStateChange((state) => {
|
|
534
500
|
setAnnotations(getAnnotationsByPageIndex(state, pageIndex));
|
|
@@ -536,7 +502,7 @@ function Annotations(annotationsProps) {
|
|
|
536
502
|
});
|
|
537
503
|
}
|
|
538
504
|
}, [annotationProvides]);
|
|
539
|
-
const handlers =
|
|
505
|
+
const handlers = useMemo(
|
|
540
506
|
() => ({
|
|
541
507
|
onPointerDown: (_, pe) => {
|
|
542
508
|
if (pe.target === pe.currentTarget && annotationProvides) {
|
|
@@ -556,23 +522,25 @@ function Annotations(annotationsProps) {
|
|
|
556
522
|
},
|
|
557
523
|
[annotationProvides, selectionProvides, pageIndex]
|
|
558
524
|
);
|
|
559
|
-
|
|
525
|
+
useEffect(() => {
|
|
560
526
|
return register(handlers);
|
|
561
527
|
}, [register, handlers]);
|
|
562
|
-
return /* @__PURE__ */
|
|
563
|
-
const isSelected = selectionState
|
|
528
|
+
return /* @__PURE__ */ jsx(Fragment, { children: annotations.map((annotation) => {
|
|
529
|
+
const isSelected = (selectionState == null ? void 0 : selectionState.localId) === annotation.localId;
|
|
564
530
|
switch (annotation.object.type) {
|
|
565
|
-
case
|
|
566
|
-
return /* @__PURE__ */
|
|
531
|
+
case PdfAnnotationSubtype.UNDERLINE:
|
|
532
|
+
return /* @__PURE__ */ jsx(
|
|
567
533
|
AnnotationContainer,
|
|
568
534
|
{
|
|
569
535
|
trackedAnnotation: annotation,
|
|
570
536
|
isSelected,
|
|
571
537
|
isDraggable: false,
|
|
572
538
|
isResizable: false,
|
|
573
|
-
style: {
|
|
539
|
+
style: {
|
|
540
|
+
mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
|
|
541
|
+
},
|
|
574
542
|
...annotationsProps,
|
|
575
|
-
children: /* @__PURE__ */
|
|
543
|
+
children: /* @__PURE__ */ jsx(
|
|
576
544
|
Underline,
|
|
577
545
|
{
|
|
578
546
|
rect: annotation.object.rect,
|
|
@@ -586,17 +554,19 @@ function Annotations(annotationsProps) {
|
|
|
586
554
|
},
|
|
587
555
|
annotation.localId
|
|
588
556
|
);
|
|
589
|
-
case
|
|
590
|
-
return /* @__PURE__ */
|
|
557
|
+
case PdfAnnotationSubtype.STRIKEOUT:
|
|
558
|
+
return /* @__PURE__ */ jsx(
|
|
591
559
|
AnnotationContainer,
|
|
592
560
|
{
|
|
593
561
|
trackedAnnotation: annotation,
|
|
594
562
|
isSelected,
|
|
595
563
|
isDraggable: false,
|
|
596
564
|
isResizable: false,
|
|
597
|
-
style: {
|
|
565
|
+
style: {
|
|
566
|
+
mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
|
|
567
|
+
},
|
|
598
568
|
...annotationsProps,
|
|
599
|
-
children: /* @__PURE__ */
|
|
569
|
+
children: /* @__PURE__ */ jsx(
|
|
600
570
|
Strikeout,
|
|
601
571
|
{
|
|
602
572
|
rect: annotation.object.rect,
|
|
@@ -610,17 +580,19 @@ function Annotations(annotationsProps) {
|
|
|
610
580
|
},
|
|
611
581
|
annotation.localId
|
|
612
582
|
);
|
|
613
|
-
case
|
|
614
|
-
return /* @__PURE__ */
|
|
583
|
+
case PdfAnnotationSubtype.SQUIGGLY:
|
|
584
|
+
return /* @__PURE__ */ jsx(
|
|
615
585
|
AnnotationContainer,
|
|
616
586
|
{
|
|
617
587
|
trackedAnnotation: annotation,
|
|
618
588
|
isSelected,
|
|
619
589
|
isDraggable: false,
|
|
620
590
|
isResizable: false,
|
|
621
|
-
style: {
|
|
591
|
+
style: {
|
|
592
|
+
mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
|
|
593
|
+
},
|
|
622
594
|
...annotationsProps,
|
|
623
|
-
children: /* @__PURE__ */
|
|
595
|
+
children: /* @__PURE__ */ jsx(
|
|
624
596
|
Squiggly,
|
|
625
597
|
{
|
|
626
598
|
color: annotation.object.color,
|
|
@@ -634,17 +606,21 @@ function Annotations(annotationsProps) {
|
|
|
634
606
|
},
|
|
635
607
|
annotation.localId
|
|
636
608
|
);
|
|
637
|
-
case
|
|
638
|
-
return /* @__PURE__ */
|
|
609
|
+
case PdfAnnotationSubtype.HIGHLIGHT:
|
|
610
|
+
return /* @__PURE__ */ jsx(
|
|
639
611
|
AnnotationContainer,
|
|
640
612
|
{
|
|
641
613
|
trackedAnnotation: annotation,
|
|
642
614
|
isSelected,
|
|
643
615
|
isDraggable: false,
|
|
644
616
|
isResizable: false,
|
|
645
|
-
style: {
|
|
617
|
+
style: {
|
|
618
|
+
mixBlendMode: blendModeToCss(
|
|
619
|
+
annotation.object.blendMode ?? PdfBlendMode.Multiply
|
|
620
|
+
)
|
|
621
|
+
},
|
|
646
622
|
...annotationsProps,
|
|
647
|
-
children: /* @__PURE__ */
|
|
623
|
+
children: /* @__PURE__ */ jsx(
|
|
648
624
|
Highlight,
|
|
649
625
|
{
|
|
650
626
|
color: annotation.object.color,
|
|
@@ -658,16 +634,19 @@ function Annotations(annotationsProps) {
|
|
|
658
634
|
},
|
|
659
635
|
annotation.localId
|
|
660
636
|
);
|
|
661
|
-
case
|
|
662
|
-
return /* @__PURE__ */
|
|
637
|
+
case PdfAnnotationSubtype.INK:
|
|
638
|
+
return /* @__PURE__ */ jsx(
|
|
663
639
|
AnnotationContainer,
|
|
664
640
|
{
|
|
665
641
|
isSelected,
|
|
666
642
|
trackedAnnotation: annotation,
|
|
667
643
|
outlineOffset: 6,
|
|
668
644
|
computeResizePatch: resizeInkAnnotation,
|
|
645
|
+
style: {
|
|
646
|
+
mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
|
|
647
|
+
},
|
|
669
648
|
...annotationsProps,
|
|
670
|
-
children: (obj) => /* @__PURE__ */
|
|
649
|
+
children: (obj) => /* @__PURE__ */ jsx(
|
|
671
650
|
Ink,
|
|
672
651
|
{
|
|
673
652
|
color: obj.color,
|
|
@@ -687,19 +666,14 @@ function Annotations(annotationsProps) {
|
|
|
687
666
|
}
|
|
688
667
|
}) });
|
|
689
668
|
}
|
|
690
|
-
|
|
691
|
-
// src/preact/components/text-markup.tsx
|
|
692
|
-
import { PdfAnnotationSubtype as PdfAnnotationSubtype3 } from "@embedpdf/models";
|
|
693
|
-
import { useSelectionCapability as useSelectionCapability2 } from "@embedpdf/plugin-selection/preact";
|
|
694
|
-
import { useEffect as useEffect3, useState as useState3 } from "preact/hooks";
|
|
695
|
-
import { jsx as jsx8 } from "preact/jsx-runtime";
|
|
696
669
|
function TextMarkup({ pageIndex, scale }) {
|
|
697
|
-
|
|
670
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
671
|
+
const { provides: selectionProvides } = useSelectionCapability();
|
|
698
672
|
const { provides: annotationProvides } = useAnnotationCapability();
|
|
699
|
-
const [rects, setRects] =
|
|
700
|
-
const [boundingRect, setBoundingRect] =
|
|
701
|
-
const [activeTool, setActiveTool] =
|
|
702
|
-
|
|
673
|
+
const [rects, setRects] = useState([]);
|
|
674
|
+
const [boundingRect, setBoundingRect] = useState(null);
|
|
675
|
+
const [activeTool, setActiveTool] = useState({ variantKey: null, defaults: null });
|
|
676
|
+
useEffect(() => {
|
|
703
677
|
if (!selectionProvides) return;
|
|
704
678
|
const off = selectionProvides.onSelectionChange(() => {
|
|
705
679
|
setRects(selectionProvides.getHighlightRectsForPage(pageIndex));
|
|
@@ -707,91 +681,91 @@ function TextMarkup({ pageIndex, scale }) {
|
|
|
707
681
|
});
|
|
708
682
|
return off;
|
|
709
683
|
}, [selectionProvides, pageIndex]);
|
|
710
|
-
|
|
684
|
+
useEffect(() => {
|
|
711
685
|
if (!annotationProvides) return;
|
|
712
686
|
const off = annotationProvides.onActiveToolChange(setActiveTool);
|
|
713
687
|
return off;
|
|
714
688
|
}, [annotationProvides]);
|
|
715
689
|
if (!boundingRect) return null;
|
|
716
|
-
switch (activeTool.
|
|
717
|
-
case
|
|
718
|
-
return /* @__PURE__ */
|
|
690
|
+
switch (activeTool.variantKey) {
|
|
691
|
+
case makeVariantKey(PdfAnnotationSubtype.UNDERLINE):
|
|
692
|
+
return /* @__PURE__ */ jsx(
|
|
719
693
|
"div",
|
|
720
694
|
{
|
|
721
695
|
style: {
|
|
722
|
-
mixBlendMode:
|
|
696
|
+
mixBlendMode: blendModeToCss(((_a = activeTool.defaults) == null ? void 0 : _a.blendMode) ?? PdfBlendMode.Normal),
|
|
723
697
|
pointerEvents: "none",
|
|
724
698
|
position: "absolute",
|
|
725
699
|
inset: 0
|
|
726
700
|
},
|
|
727
|
-
children: /* @__PURE__ */
|
|
701
|
+
children: /* @__PURE__ */ jsx(
|
|
728
702
|
Underline,
|
|
729
703
|
{
|
|
730
|
-
color: activeTool.defaults
|
|
731
|
-
opacity: activeTool.defaults
|
|
704
|
+
color: (_b = activeTool.defaults) == null ? void 0 : _b.color,
|
|
705
|
+
opacity: (_c = activeTool.defaults) == null ? void 0 : _c.opacity,
|
|
732
706
|
rects,
|
|
733
707
|
scale
|
|
734
708
|
}
|
|
735
709
|
)
|
|
736
710
|
}
|
|
737
711
|
);
|
|
738
|
-
case
|
|
739
|
-
return /* @__PURE__ */
|
|
712
|
+
case makeVariantKey(PdfAnnotationSubtype.HIGHLIGHT):
|
|
713
|
+
return /* @__PURE__ */ jsx(
|
|
740
714
|
"div",
|
|
741
715
|
{
|
|
742
716
|
style: {
|
|
743
|
-
mixBlendMode:
|
|
717
|
+
mixBlendMode: blendModeToCss(((_d = activeTool.defaults) == null ? void 0 : _d.blendMode) ?? PdfBlendMode.Multiply),
|
|
744
718
|
pointerEvents: "none",
|
|
745
719
|
position: "absolute",
|
|
746
720
|
inset: 0
|
|
747
721
|
},
|
|
748
|
-
children: /* @__PURE__ */
|
|
722
|
+
children: /* @__PURE__ */ jsx(
|
|
749
723
|
Highlight,
|
|
750
724
|
{
|
|
751
|
-
color: activeTool.defaults
|
|
752
|
-
opacity: activeTool.defaults
|
|
725
|
+
color: (_e = activeTool.defaults) == null ? void 0 : _e.color,
|
|
726
|
+
opacity: (_f = activeTool.defaults) == null ? void 0 : _f.opacity,
|
|
753
727
|
rects,
|
|
754
728
|
scale
|
|
755
729
|
}
|
|
756
730
|
)
|
|
757
731
|
}
|
|
758
732
|
);
|
|
759
|
-
case
|
|
760
|
-
return /* @__PURE__ */
|
|
733
|
+
case makeVariantKey(PdfAnnotationSubtype.STRIKEOUT):
|
|
734
|
+
return /* @__PURE__ */ jsx(
|
|
761
735
|
"div",
|
|
762
736
|
{
|
|
763
737
|
style: {
|
|
764
|
-
mixBlendMode:
|
|
738
|
+
mixBlendMode: blendModeToCss(((_g = activeTool.defaults) == null ? void 0 : _g.blendMode) ?? PdfBlendMode.Normal),
|
|
765
739
|
pointerEvents: "none",
|
|
766
740
|
position: "absolute",
|
|
767
741
|
inset: 0
|
|
768
742
|
},
|
|
769
|
-
children: /* @__PURE__ */
|
|
743
|
+
children: /* @__PURE__ */ jsx(
|
|
770
744
|
Strikeout,
|
|
771
745
|
{
|
|
772
|
-
color: activeTool.defaults
|
|
773
|
-
opacity: activeTool.defaults
|
|
746
|
+
color: (_h = activeTool.defaults) == null ? void 0 : _h.color,
|
|
747
|
+
opacity: (_i = activeTool.defaults) == null ? void 0 : _i.opacity,
|
|
774
748
|
rects,
|
|
775
749
|
scale
|
|
776
750
|
}
|
|
777
751
|
)
|
|
778
752
|
}
|
|
779
753
|
);
|
|
780
|
-
case
|
|
781
|
-
return /* @__PURE__ */
|
|
754
|
+
case makeVariantKey(PdfAnnotationSubtype.SQUIGGLY):
|
|
755
|
+
return /* @__PURE__ */ jsx(
|
|
782
756
|
"div",
|
|
783
757
|
{
|
|
784
758
|
style: {
|
|
785
|
-
mixBlendMode:
|
|
759
|
+
mixBlendMode: blendModeToCss(((_j = activeTool.defaults) == null ? void 0 : _j.blendMode) ?? PdfBlendMode.Normal),
|
|
786
760
|
pointerEvents: "none",
|
|
787
761
|
position: "absolute",
|
|
788
762
|
inset: 0
|
|
789
763
|
},
|
|
790
|
-
children: /* @__PURE__ */
|
|
764
|
+
children: /* @__PURE__ */ jsx(
|
|
791
765
|
Squiggly,
|
|
792
766
|
{
|
|
793
|
-
color: activeTool.defaults
|
|
794
|
-
opacity: activeTool.defaults
|
|
767
|
+
color: (_k = activeTool.defaults) == null ? void 0 : _k.color,
|
|
768
|
+
opacity: (_l = activeTool.defaults) == null ? void 0 : _l.opacity,
|
|
795
769
|
rects,
|
|
796
770
|
scale
|
|
797
771
|
}
|
|
@@ -802,35 +776,32 @@ function TextMarkup({ pageIndex, scale }) {
|
|
|
802
776
|
return null;
|
|
803
777
|
}
|
|
804
778
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
import { usePointerHandlers as usePointerHandlers2 } from "@embedpdf/plugin-interaction-manager/preact";
|
|
809
|
-
import { PdfAnnotationSubtype as PdfAnnotationSubtype4 } from "@embedpdf/models";
|
|
810
|
-
import { jsx as jsx9 } from "preact/jsx-runtime";
|
|
811
|
-
var MAX_STROKE_WIDTH = 30;
|
|
812
|
-
var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
779
|
+
const MAX_STROKE_WIDTH = 30;
|
|
780
|
+
const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
781
|
+
var _a, _b, _c;
|
|
813
782
|
const { provides: annotationProvides } = useAnnotationCapability();
|
|
814
|
-
const [activeTool, setActiveTool] =
|
|
815
|
-
|
|
783
|
+
const [activeTool, setActiveTool] = useState({ variantKey: null, defaults: null });
|
|
784
|
+
useEffect(() => {
|
|
816
785
|
if (!annotationProvides) return;
|
|
817
786
|
const off = annotationProvides.onActiveToolChange(setActiveTool);
|
|
818
787
|
return off;
|
|
819
788
|
}, [annotationProvides]);
|
|
820
|
-
if (activeTool.
|
|
821
|
-
|
|
822
|
-
const
|
|
823
|
-
const
|
|
824
|
-
const
|
|
789
|
+
if (!activeTool.defaults) return null;
|
|
790
|
+
if (activeTool.defaults.subtype !== PdfAnnotationSubtype.INK) return null;
|
|
791
|
+
const toolColor = ((_a = activeTool.defaults) == null ? void 0 : _a.color) ?? "#000000";
|
|
792
|
+
const toolOpacity = ((_b = activeTool.defaults) == null ? void 0 : _b.opacity) ?? 1;
|
|
793
|
+
const toolStrokeWidth = ((_c = activeTool.defaults) == null ? void 0 : _c.strokeWidth) ?? 2;
|
|
794
|
+
const { register } = usePointerHandlers({ modeId: "ink", pageIndex });
|
|
825
795
|
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
826
|
-
const [currentStrokes, setCurrentStrokes] =
|
|
827
|
-
const [isDrawing, setIsDrawing] =
|
|
828
|
-
const timerRef =
|
|
796
|
+
const [currentStrokes, setCurrentStrokes] = useState([]);
|
|
797
|
+
const [isDrawing, setIsDrawing] = useState(false);
|
|
798
|
+
const timerRef = useRef(null);
|
|
829
799
|
const pageWidthPDF = pageWidth / scale;
|
|
830
800
|
const pageHeightPDF = pageHeight / scale;
|
|
831
|
-
const handlers =
|
|
801
|
+
const handlers = useMemo(
|
|
832
802
|
() => ({
|
|
833
803
|
onPointerDown: (pos, evt) => {
|
|
804
|
+
var _a2, _b2;
|
|
834
805
|
const curX = clamp(pos.x, 0, pageWidthPDF);
|
|
835
806
|
const curY = clamp(pos.y, 0, pageHeightPDF);
|
|
836
807
|
setIsDrawing(true);
|
|
@@ -841,7 +812,7 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
841
812
|
} else {
|
|
842
813
|
setCurrentStrokes([{ points: [{ x: curX, y: curY }] }]);
|
|
843
814
|
}
|
|
844
|
-
evt.target
|
|
815
|
+
(_b2 = (_a2 = evt.target) == null ? void 0 : _a2.setPointerCapture) == null ? void 0 : _b2.call(_a2, evt.pointerId);
|
|
845
816
|
},
|
|
846
817
|
onPointerMove: (pos) => {
|
|
847
818
|
if (!isDrawing) return;
|
|
@@ -855,8 +826,9 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
855
826
|
});
|
|
856
827
|
},
|
|
857
828
|
onPointerUp: (_, evt) => {
|
|
829
|
+
var _a2, _b2;
|
|
858
830
|
setIsDrawing(false);
|
|
859
|
-
evt.target
|
|
831
|
+
(_b2 = (_a2 = evt.target) == null ? void 0 : _a2.releasePointerCapture) == null ? void 0 : _b2.call(_a2, evt.pointerId);
|
|
860
832
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
861
833
|
timerRef.current = setTimeout(() => {
|
|
862
834
|
if (currentStrokes.length && annotationProvides) {
|
|
@@ -877,7 +849,7 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
877
849
|
size: { width: rectMaxX - rectMinX, height: rectMaxY - rectMinY }
|
|
878
850
|
};
|
|
879
851
|
const anno = {
|
|
880
|
-
type:
|
|
852
|
+
type: PdfAnnotationSubtype.INK,
|
|
881
853
|
rect,
|
|
882
854
|
inkList: currentStrokes,
|
|
883
855
|
color: toolColor,
|
|
@@ -887,7 +859,7 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
887
859
|
id: Date.now() + Math.random()
|
|
888
860
|
};
|
|
889
861
|
annotationProvides.createAnnotation(pageIndex, anno);
|
|
890
|
-
annotationProvides.
|
|
862
|
+
annotationProvides.setActiveVariant(null);
|
|
891
863
|
annotationProvides.selectAnnotation(pageIndex, anno.id);
|
|
892
864
|
}
|
|
893
865
|
setCurrentStrokes([]);
|
|
@@ -895,8 +867,9 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
895
867
|
}, 3e3);
|
|
896
868
|
},
|
|
897
869
|
onPointerCancel: (_, evt) => {
|
|
870
|
+
var _a2, _b2;
|
|
898
871
|
setIsDrawing(false);
|
|
899
|
-
evt.target
|
|
872
|
+
(_b2 = (_a2 = evt.target) == null ? void 0 : _a2.releasePointerCapture) == null ? void 0 : _b2.call(_a2, evt.pointerId);
|
|
900
873
|
setCurrentStrokes([]);
|
|
901
874
|
if (timerRef.current) {
|
|
902
875
|
clearTimeout(timerRef.current);
|
|
@@ -916,11 +889,11 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
916
889
|
isDrawing
|
|
917
890
|
]
|
|
918
891
|
);
|
|
919
|
-
|
|
892
|
+
useEffect(() => {
|
|
920
893
|
if (!register) return;
|
|
921
894
|
return register(handlers);
|
|
922
895
|
}, [register, handlers]);
|
|
923
|
-
|
|
896
|
+
useEffect(() => {
|
|
924
897
|
return () => {
|
|
925
898
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
926
899
|
};
|
|
@@ -948,7 +921,7 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
948
921
|
});
|
|
949
922
|
return d.trim();
|
|
950
923
|
});
|
|
951
|
-
return /* @__PURE__ */
|
|
924
|
+
return /* @__PURE__ */ jsx(
|
|
952
925
|
"svg",
|
|
953
926
|
{
|
|
954
927
|
style: {
|
|
@@ -963,7 +936,7 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
963
936
|
width: dw * scale,
|
|
964
937
|
height: dh * scale,
|
|
965
938
|
viewBox: `0 0 ${dw} ${dh}`,
|
|
966
|
-
children: paths.map((d, i) => /* @__PURE__ */
|
|
939
|
+
children: paths.map((d, i) => /* @__PURE__ */ jsx(
|
|
967
940
|
"path",
|
|
968
941
|
{
|
|
969
942
|
d,
|
|
@@ -979,9 +952,6 @@ var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
979
952
|
}
|
|
980
953
|
);
|
|
981
954
|
};
|
|
982
|
-
|
|
983
|
-
// src/preact/components/annotation-layer.tsx
|
|
984
|
-
import { jsx as jsx10, jsxs as jsxs2 } from "preact/jsx-runtime";
|
|
985
955
|
function AnnotationLayer({
|
|
986
956
|
pageIndex,
|
|
987
957
|
scale,
|
|
@@ -991,7 +961,7 @@ function AnnotationLayer({
|
|
|
991
961
|
style,
|
|
992
962
|
...props
|
|
993
963
|
}) {
|
|
994
|
-
return /* @__PURE__ */
|
|
964
|
+
return /* @__PURE__ */ jsxs(
|
|
995
965
|
"div",
|
|
996
966
|
{
|
|
997
967
|
style: {
|
|
@@ -999,9 +969,9 @@ function AnnotationLayer({
|
|
|
999
969
|
},
|
|
1000
970
|
...props,
|
|
1001
971
|
children: [
|
|
1002
|
-
/* @__PURE__ */
|
|
1003
|
-
/* @__PURE__ */
|
|
1004
|
-
/* @__PURE__ */
|
|
972
|
+
/* @__PURE__ */ jsx(Annotations, { pageIndex, scale, rotation }),
|
|
973
|
+
/* @__PURE__ */ jsx(TextMarkup, { pageIndex, scale }),
|
|
974
|
+
/* @__PURE__ */ jsx(InkPaint, { pageIndex, scale, pageWidth, pageHeight })
|
|
1005
975
|
]
|
|
1006
976
|
}
|
|
1007
977
|
);
|
|
@@ -1011,4 +981,4 @@ export {
|
|
|
1011
981
|
useAnnotationCapability,
|
|
1012
982
|
useAnnotationPlugin
|
|
1013
983
|
};
|
|
1014
|
-
//# sourceMappingURL=index.js.map
|
|
984
|
+
//# sourceMappingURL=index.js.map
|