@embedpdf/plugin-annotation 2.10.1 → 2.11.0
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 +19 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +2 -1
- package/dist/lib/annotation-plugin.d.ts +1 -1
- package/dist/lib/handlers/types.d.ts +17 -5
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/tools/default-tools.d.ts +12 -12
- package/dist/lib/tools/tools-utils.d.ts +9 -9
- package/dist/lib/tools/types.d.ts +1 -1
- package/dist/lib/types.d.ts +5 -4
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +48 -45
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +48 -45
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/types.d.ts +19 -5
- package/dist/shared-preact/components/types.d.ts +19 -5
- package/dist/shared-react/components/types.d.ts +19 -5
- package/dist/svelte/components/annotations/CirclePreview.svelte.d.ts +10 -0
- package/dist/svelte/components/annotations/FreeTextPreview.svelte.d.ts +10 -0
- package/dist/svelte/components/annotations/InkPreview.svelte.d.ts +10 -0
- package/dist/svelte/components/annotations/LinePreview.svelte.d.ts +10 -0
- package/dist/svelte/components/annotations/PolygonPreview.svelte.d.ts +10 -0
- package/dist/svelte/components/annotations/PolylinePreview.svelte.d.ts +10 -0
- package/dist/svelte/components/annotations/SquarePreview.svelte.d.ts +10 -0
- package/dist/svelte/context/types.d.ts +19 -5
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +247 -425
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/components/annotations/circle-preview.vue.d.ts +10 -0
- package/dist/vue/components/annotations/free-text-preview.vue.d.ts +10 -0
- package/dist/vue/components/annotations/ink-preview.vue.d.ts +10 -0
- package/dist/vue/components/annotations/line-preview.vue.d.ts +10 -0
- package/dist/vue/components/annotations/polygon-preview.vue.d.ts +10 -0
- package/dist/vue/components/annotations/polyline-preview.vue.d.ts +10 -0
- package/dist/vue/components/annotations/square-preview.vue.d.ts +10 -0
- package/dist/vue/context/types.d.ts +19 -5
- package/dist/vue/hooks/use-annotation.d.ts +2 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +279 -163
- package/dist/vue/index.js.map +1 -1
- package/package.json +12 -12
package/dist/preact/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createContext, Fragment as Fragment$1 } from "preact";
|
|
|
6
6
|
import { useState, useCallback, useContext, useRef, useEffect, useMemo } from "preact/hooks";
|
|
7
7
|
import { createPortal } from "preact/compat";
|
|
8
8
|
import { usePlugin, useCapability, useDocumentPermissions, useDocumentState } from "@embedpdf/core/preact";
|
|
9
|
-
import { inferRotationCenterFromRects, boundingRectOrEmpty, PdfAnnotationBorderStyle, getContrastStrokeColor, PdfVerticalAlignment, textAlignmentToCss, standardFontCssProperties, ignore, PdfErrorCode, PdfBlendMode,
|
|
9
|
+
import { inferRotationCenterFromRects, boundingRectOrEmpty, PdfAnnotationBorderStyle, getContrastStrokeColor, PdfVerticalAlignment, textAlignmentToCss, standardFontCssProperties, ignore, PdfErrorCode, PdfBlendMode, blendModeToCss, PdfAnnotationSubtype } from "@embedpdf/models";
|
|
10
10
|
import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/preact";
|
|
11
11
|
import { useSelectionCapability } from "@embedpdf/plugin-selection/preact";
|
|
12
12
|
import { useInteractionHandles, useDoublePressProps, CounterRotate } from "@embedpdf/utils/preact";
|
|
@@ -1256,9 +1256,11 @@ function GroupSelectionBox({
|
|
|
1256
1256
|
function createRenderer(entry) {
|
|
1257
1257
|
return {
|
|
1258
1258
|
id: entry.id,
|
|
1259
|
-
matches: (annotation) => entry.matches(annotation),
|
|
1260
|
-
render: (props) => entry.render(props),
|
|
1259
|
+
matches: entry.matches ? (annotation) => entry.matches(annotation) : () => false,
|
|
1260
|
+
render: entry.render ? (props) => entry.render(props) : () => null,
|
|
1261
|
+
matchesPreview: entry.matchesPreview,
|
|
1261
1262
|
renderPreview: entry.renderPreview ? (props) => entry.renderPreview(props) : void 0,
|
|
1263
|
+
previewContainerStyle: entry.previewContainerStyle ? (props) => entry.previewContainerStyle(props) : void 0,
|
|
1262
1264
|
vertexConfig: entry.vertexConfig,
|
|
1263
1265
|
zIndex: entry.zIndex,
|
|
1264
1266
|
defaultBlendMode: entry.defaultBlendMode,
|
|
@@ -2681,6 +2683,7 @@ const builtInRenderers = [
|
|
|
2681
2683
|
createRenderer({
|
|
2682
2684
|
id: "ink",
|
|
2683
2685
|
matches: (a) => a.type === PdfAnnotationSubtype.INK,
|
|
2686
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.INK,
|
|
2684
2687
|
render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
|
|
2685
2688
|
Ink,
|
|
2686
2689
|
{
|
|
@@ -2691,12 +2694,17 @@ const builtInRenderers = [
|
|
|
2691
2694
|
appearanceActive
|
|
2692
2695
|
}
|
|
2693
2696
|
),
|
|
2697
|
+
renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Ink, { isSelected: false, scale, ...data }),
|
|
2698
|
+
previewContainerStyle: ({ data }) => ({
|
|
2699
|
+
mixBlendMode: blendModeToCss(data.blendMode ?? PdfBlendMode.Normal)
|
|
2700
|
+
}),
|
|
2694
2701
|
interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
|
|
2695
2702
|
}),
|
|
2696
2703
|
// --- Shapes ---
|
|
2697
2704
|
createRenderer({
|
|
2698
2705
|
id: "square",
|
|
2699
2706
|
matches: (a) => a.type === PdfAnnotationSubtype.SQUARE,
|
|
2707
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.SQUARE,
|
|
2700
2708
|
render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
|
|
2701
2709
|
Square,
|
|
2702
2710
|
{
|
|
@@ -2707,11 +2715,13 @@ const builtInRenderers = [
|
|
|
2707
2715
|
appearanceActive
|
|
2708
2716
|
}
|
|
2709
2717
|
),
|
|
2718
|
+
renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Square, { isSelected: false, scale, ...data }),
|
|
2710
2719
|
interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
|
|
2711
2720
|
}),
|
|
2712
2721
|
createRenderer({
|
|
2713
2722
|
id: "circle",
|
|
2714
2723
|
matches: (a) => a.type === PdfAnnotationSubtype.CIRCLE,
|
|
2724
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.CIRCLE,
|
|
2715
2725
|
render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
|
|
2716
2726
|
Circle,
|
|
2717
2727
|
{
|
|
@@ -2722,12 +2732,14 @@ const builtInRenderers = [
|
|
|
2722
2732
|
appearanceActive
|
|
2723
2733
|
}
|
|
2724
2734
|
),
|
|
2735
|
+
renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Circle, { isSelected: false, scale, ...data }),
|
|
2725
2736
|
interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
|
|
2726
2737
|
}),
|
|
2727
2738
|
// --- Lines & Vertex-based ---
|
|
2728
2739
|
createRenderer({
|
|
2729
2740
|
id: "line",
|
|
2730
2741
|
matches: (a) => a.type === PdfAnnotationSubtype.LINE,
|
|
2742
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.LINE,
|
|
2731
2743
|
render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
|
|
2732
2744
|
Line,
|
|
2733
2745
|
{
|
|
@@ -2738,6 +2750,7 @@ const builtInRenderers = [
|
|
|
2738
2750
|
appearanceActive
|
|
2739
2751
|
}
|
|
2740
2752
|
) }),
|
|
2753
|
+
renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Line, { isSelected: false, scale, ...data }),
|
|
2741
2754
|
vertexConfig: {
|
|
2742
2755
|
extractVertices: (a) => [a.linePoints.start, a.linePoints.end],
|
|
2743
2756
|
transformAnnotation: (a, v) => ({
|
|
@@ -2750,6 +2763,7 @@ const builtInRenderers = [
|
|
|
2750
2763
|
createRenderer({
|
|
2751
2764
|
id: "polyline",
|
|
2752
2765
|
matches: (a) => a.type === PdfAnnotationSubtype.POLYLINE,
|
|
2766
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.POLYLINE,
|
|
2753
2767
|
render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
|
|
2754
2768
|
Polyline,
|
|
2755
2769
|
{
|
|
@@ -2760,6 +2774,7 @@ const builtInRenderers = [
|
|
|
2760
2774
|
appearanceActive
|
|
2761
2775
|
}
|
|
2762
2776
|
) }),
|
|
2777
|
+
renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Polyline, { isSelected: false, scale, ...data }),
|
|
2763
2778
|
vertexConfig: {
|
|
2764
2779
|
extractVertices: (a) => a.vertices,
|
|
2765
2780
|
transformAnnotation: (a, vertices) => ({ ...a, vertices })
|
|
@@ -2769,6 +2784,7 @@ const builtInRenderers = [
|
|
|
2769
2784
|
createRenderer({
|
|
2770
2785
|
id: "polygon",
|
|
2771
2786
|
matches: (a) => a.type === PdfAnnotationSubtype.POLYGON,
|
|
2787
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.POLYGON,
|
|
2772
2788
|
render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
|
|
2773
2789
|
Polygon,
|
|
2774
2790
|
{
|
|
@@ -2779,6 +2795,7 @@ const builtInRenderers = [
|
|
|
2779
2795
|
appearanceActive
|
|
2780
2796
|
}
|
|
2781
2797
|
) }),
|
|
2798
|
+
renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Polygon, { isSelected: false, scale, ...data }),
|
|
2782
2799
|
vertexConfig: {
|
|
2783
2800
|
extractVertices: (a) => a.vertices,
|
|
2784
2801
|
transformAnnotation: (a, vertices) => ({ ...a, vertices })
|
|
@@ -2883,6 +2900,7 @@ const builtInRenderers = [
|
|
|
2883
2900
|
createRenderer({
|
|
2884
2901
|
id: "freeText",
|
|
2885
2902
|
matches: (a) => a.type === PdfAnnotationSubtype.FREETEXT,
|
|
2903
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.FREETEXT,
|
|
2886
2904
|
render: ({
|
|
2887
2905
|
annotation,
|
|
2888
2906
|
currentObject,
|
|
@@ -2906,6 +2924,17 @@ const builtInRenderers = [
|
|
|
2906
2924
|
appearanceActive
|
|
2907
2925
|
}
|
|
2908
2926
|
),
|
|
2927
|
+
renderPreview: ({ data }) => /* @__PURE__ */ jsx(
|
|
2928
|
+
"div",
|
|
2929
|
+
{
|
|
2930
|
+
style: {
|
|
2931
|
+
width: "100%",
|
|
2932
|
+
height: "100%",
|
|
2933
|
+
border: `1px dashed ${data.fontColor || "#000000"}`,
|
|
2934
|
+
backgroundColor: "transparent"
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
),
|
|
2909
2938
|
interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true },
|
|
2910
2939
|
isDraggable: (toolDraggable, { isEditing }) => toolDraggable && !isEditing,
|
|
2911
2940
|
onDoubleClick: (id, setEditingId) => setEditingId(id)
|
|
@@ -2932,6 +2961,7 @@ const builtInRenderers = [
|
|
|
2932
2961
|
createRenderer({
|
|
2933
2962
|
id: "link",
|
|
2934
2963
|
matches: (a) => a.type === PdfAnnotationSubtype.LINK,
|
|
2964
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.LINK,
|
|
2935
2965
|
render: ({ currentObject, isSelected, scale, onClick }) => /* @__PURE__ */ jsx(
|
|
2936
2966
|
Link,
|
|
2937
2967
|
{
|
|
@@ -3403,8 +3433,13 @@ function TextMarkup({ documentId, pageIndex, scale }) {
|
|
|
3403
3433
|
}
|
|
3404
3434
|
}
|
|
3405
3435
|
function PreviewRenderer({ toolId, preview, scale }) {
|
|
3436
|
+
var _a;
|
|
3406
3437
|
const { bounds } = preview;
|
|
3407
3438
|
const registeredRenderers = useRegisteredRenderers();
|
|
3439
|
+
const allRenderers = useMemo(() => {
|
|
3440
|
+
const externalIds = new Set(registeredRenderers.map((r) => r.id));
|
|
3441
|
+
return [...registeredRenderers, ...builtInRenderers.filter((r) => !externalIds.has(r.id))];
|
|
3442
|
+
}, [registeredRenderers]);
|
|
3408
3443
|
const style = {
|
|
3409
3444
|
position: "absolute",
|
|
3410
3445
|
left: bounds.origin.x * scale,
|
|
@@ -3414,49 +3449,17 @@ function PreviewRenderer({ toolId, preview, scale }) {
|
|
|
3414
3449
|
pointerEvents: "none",
|
|
3415
3450
|
zIndex: 10
|
|
3416
3451
|
};
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
return /* @__PURE__ */ jsx("div", { style, children: /* @__PURE__ */ jsx(Square, { isSelected: false, scale, ...preview.data }) });
|
|
3422
|
-
}
|
|
3423
|
-
if (preview.type === PdfAnnotationSubtype.POLYGON) {
|
|
3424
|
-
return /* @__PURE__ */ jsx("div", { style, children: /* @__PURE__ */ jsx(Polygon, { isSelected: false, scale, ...preview.data }) });
|
|
3425
|
-
}
|
|
3426
|
-
if (preview.type === PdfAnnotationSubtype.POLYLINE) {
|
|
3427
|
-
return /* @__PURE__ */ jsx("div", { style, children: /* @__PURE__ */ jsx(Polyline, { isSelected: false, scale, ...preview.data }) });
|
|
3428
|
-
}
|
|
3429
|
-
if (preview.type === PdfAnnotationSubtype.LINE) {
|
|
3430
|
-
return /* @__PURE__ */ jsx("div", { style, children: /* @__PURE__ */ jsx(Line, { isSelected: false, scale, ...preview.data }) });
|
|
3431
|
-
}
|
|
3432
|
-
if (preview.type === PdfAnnotationSubtype.INK) {
|
|
3433
|
-
return /* @__PURE__ */ jsx(
|
|
3434
|
-
"div",
|
|
3435
|
-
{
|
|
3436
|
-
style: {
|
|
3437
|
-
...style,
|
|
3438
|
-
mixBlendMode: blendModeToCss(preview.data.blendMode ?? PdfBlendMode.Normal)
|
|
3439
|
-
},
|
|
3440
|
-
children: /* @__PURE__ */ jsx(Ink, { isSelected: false, scale, ...preview.data })
|
|
3441
|
-
}
|
|
3442
|
-
);
|
|
3443
|
-
}
|
|
3444
|
-
if (preview.type === PdfAnnotationSubtype.FREETEXT) {
|
|
3445
|
-
return /* @__PURE__ */ jsx("div", { style, children: /* @__PURE__ */ jsx(
|
|
3446
|
-
"div",
|
|
3447
|
-
{
|
|
3448
|
-
style: {
|
|
3449
|
-
width: "100%",
|
|
3450
|
-
height: "100%",
|
|
3451
|
-
border: `1px dashed ${preview.data.fontColor || "#000000"}`,
|
|
3452
|
-
backgroundColor: "transparent"
|
|
3453
|
-
}
|
|
3454
|
-
}
|
|
3455
|
-
) });
|
|
3456
|
-
}
|
|
3457
|
-
const match = registeredRenderers.find((r) => r.id === toolId && r.renderPreview);
|
|
3452
|
+
const match = allRenderers.find((r) => {
|
|
3453
|
+
var _a2;
|
|
3454
|
+
return ((_a2 = r.matchesPreview) == null ? void 0 : _a2.call(r, preview)) && r.renderPreview;
|
|
3455
|
+
}) ?? allRenderers.find((r) => r.id === toolId && r.renderPreview);
|
|
3458
3456
|
if (match == null ? void 0 : match.renderPreview) {
|
|
3459
|
-
|
|
3457
|
+
const containerExtra = (_a = match.previewContainerStyle) == null ? void 0 : _a.call(match, {
|
|
3458
|
+
data: preview.data,
|
|
3459
|
+
bounds: preview.bounds,
|
|
3460
|
+
scale
|
|
3461
|
+
});
|
|
3462
|
+
return /* @__PURE__ */ jsx("div", { style: { ...style, ...containerExtra }, children: match.renderPreview({ data: preview.data, bounds: preview.bounds, scale }) });
|
|
3460
3463
|
}
|
|
3461
3464
|
return null;
|
|
3462
3465
|
}
|