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