@embedpdf/plugin-annotation 1.0.11 → 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 +2 -693
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -266
- package/dist/index.js +509 -164
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +104 -0
- package/dist/lib/annotation-plugin.d.ts +34 -0
- package/dist/lib/helpers.d.ts +18 -0
- package/dist/lib/index.d.ts +12 -0
- package/dist/lib/manifest.d.ts +4 -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/reducer.d.ts +5 -0
- package/dist/lib/selectors.d.ts +25 -0
- package/dist/lib/types.d.ts +168 -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 +2150 -539
- 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 +2624 -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 +24 -0
- package/dist/shared-preact/components/annotation-layer.d.ts +13 -0
- 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-highlight-paint.d.ts +0 -0
- package/dist/shared-preact/components/annotations/ink-paint.d.ts +18 -0
- package/dist/shared-preact/components/annotations/ink.d.ts +25 -0
- 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 +11 -0
- package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -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/resize-handles.d.ts +9 -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/components/vertex-editor.d.ts +19 -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/hooks/use-drag-resize.d.ts +31 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-preact/patch-ink.d.ts +16 -0
- package/dist/shared-preact/patchers.d.ts +9 -0
- package/dist/shared-preact/types.d.ts +12 -0
- package/dist/shared-preact/vertex-patchers.d.ts +10 -0
- package/dist/shared-react/components/annotation-container.d.ts +24 -0
- package/dist/shared-react/components/annotation-layer.d.ts +13 -0
- 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-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 +25 -0
- 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 +11 -0
- package/dist/shared-react/components/counter-rotate-container.d.ts +32 -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/resize-handles.d.ts +9 -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/components/vertex-editor.d.ts +19 -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/hooks/use-drag-resize.d.ts +31 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/shared-react/patch-ink.d.ts +16 -0
- package/dist/shared-react/patchers.d.ts +9 -0
- package/dist/shared-react/types.d.ts +12 -0
- package/dist/shared-react/vertex-patchers.d.ts +10 -0
- package/package.json +17 -15
- package/dist/index.d.cts +0 -266
- package/dist/preact/index.d.cts +0 -28
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BasePlugin, createBehaviorEmitter, SET_DOCUMENT } from "@embedpdf/core";
|
|
2
|
+
import { PdfAnnotationLineEnding, rectFromPoints, expandRect, rotateAndTranslatePoint, PdfAnnotationSubtype, PdfBlendMode, ignore, PdfTaskHelper, PdfErrorCode, Rotation, AppearanceMode, Task, PdfAnnotationBorderStyle } from "@embedpdf/models";
|
|
3
|
+
const ANNOTATION_PLUGIN_ID = "annotation";
|
|
4
|
+
const manifest = {
|
|
4
5
|
id: ANNOTATION_PLUGIN_ID,
|
|
5
6
|
name: "Annotation Plugin",
|
|
6
7
|
version: "1.0.0",
|
|
@@ -12,104 +13,87 @@ var manifest = {
|
|
|
12
13
|
autoCommit: true
|
|
13
14
|
}
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Rotation,
|
|
30
|
-
AppearanceMode
|
|
31
|
-
} from "@embedpdf/models";
|
|
32
|
-
|
|
33
|
-
// src/lib/actions.ts
|
|
34
|
-
var SET_ANNOTATIONS = "ANNOTATION/SET_ANNOTATIONS";
|
|
35
|
-
var REINDEX_PAGE_ANNOTATIONS = "ANNOTATION/REINDEX_PAGE";
|
|
36
|
-
var SELECT_ANNOTATION = "ANNOTATION/SELECT_ANNOTATION";
|
|
37
|
-
var DESELECT_ANNOTATION = "ANNOTATION/DESELECT_ANNOTATION";
|
|
38
|
-
var SET_ANNOTATION_MODE = "ANNOTATION/SET_ANNOTATION_MODE";
|
|
39
|
-
var UPDATE_TOOL_DEFAULTS = "ANNOTATION/UPDATE_TOOL_DEFAULTS";
|
|
40
|
-
var ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
|
|
41
|
-
var CREATE_ANNOTATION = "ANNOTATION/CREATE_ANNOTATION";
|
|
42
|
-
var PATCH_ANNOTATION = "ANNOTATION/PATCH_ANNOTATION";
|
|
43
|
-
var DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
|
|
44
|
-
var COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
|
|
45
|
-
var STORE_PDF_ID = "ANNOTATION/STORE_PDF_ID";
|
|
46
|
-
var PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
|
|
47
|
-
var setAnnotations = (p) => ({
|
|
16
|
+
const SET_ANNOTATIONS = "ANNOTATION/SET_ANNOTATIONS";
|
|
17
|
+
const REINDEX_PAGE_ANNOTATIONS = "ANNOTATION/REINDEX_PAGE";
|
|
18
|
+
const SELECT_ANNOTATION = "ANNOTATION/SELECT_ANNOTATION";
|
|
19
|
+
const DESELECT_ANNOTATION = "ANNOTATION/DESELECT_ANNOTATION";
|
|
20
|
+
const UPDATE_TOOL_DEFAULTS = "ANNOTATION/UPDATE_TOOL_DEFAULTS";
|
|
21
|
+
const ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
|
|
22
|
+
const CREATE_ANNOTATION = "ANNOTATION/CREATE_ANNOTATION";
|
|
23
|
+
const PATCH_ANNOTATION = "ANNOTATION/PATCH_ANNOTATION";
|
|
24
|
+
const DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
|
|
25
|
+
const COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
|
|
26
|
+
const STORE_PDF_ID = "ANNOTATION/STORE_PDF_ID";
|
|
27
|
+
const PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
|
|
28
|
+
const SET_ACTIVE_VARIANT = "ANNOTATION/SET_ACTIVE_VARIANT";
|
|
29
|
+
const setAnnotations = (p) => ({
|
|
48
30
|
type: SET_ANNOTATIONS,
|
|
49
31
|
payload: p
|
|
50
32
|
});
|
|
51
|
-
|
|
33
|
+
const reindexPageAnnotations = (pageIndex) => ({
|
|
52
34
|
type: REINDEX_PAGE_ANNOTATIONS,
|
|
53
35
|
payload: { pageIndex }
|
|
54
36
|
});
|
|
55
|
-
|
|
37
|
+
const selectAnnotation = (pageIndex, localId) => ({
|
|
56
38
|
type: SELECT_ANNOTATION,
|
|
57
39
|
payload: { pageIndex, localId }
|
|
58
40
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
payload: m
|
|
63
|
-
});
|
|
64
|
-
var updateToolDefaults = (subtype, patch) => ({ type: UPDATE_TOOL_DEFAULTS, payload: { subtype, patch } });
|
|
65
|
-
var addColorPreset = (c) => ({
|
|
41
|
+
const deselectAnnotation = () => ({ type: DESELECT_ANNOTATION });
|
|
42
|
+
const updateToolDefaults = (variantKey, patch) => ({ type: UPDATE_TOOL_DEFAULTS, payload: { variantKey, patch } });
|
|
43
|
+
const addColorPreset = (c) => ({
|
|
66
44
|
type: ADD_COLOR_PRESET,
|
|
67
45
|
payload: c
|
|
68
46
|
});
|
|
69
|
-
|
|
47
|
+
const createAnnotation = (pageIndex, localId, annotation) => ({
|
|
70
48
|
type: CREATE_ANNOTATION,
|
|
71
49
|
payload: { pageIndex, localId, annotation }
|
|
72
50
|
});
|
|
73
|
-
|
|
51
|
+
const patchAnnotation = (pageIndex, localId, patch) => ({
|
|
74
52
|
type: PATCH_ANNOTATION,
|
|
75
53
|
payload: { pageIndex, localId, patch }
|
|
76
54
|
});
|
|
77
|
-
|
|
55
|
+
const deleteAnnotation = (pageIndex, localId) => ({
|
|
78
56
|
type: DELETE_ANNOTATION,
|
|
79
57
|
payload: { pageIndex, localId }
|
|
80
58
|
});
|
|
81
|
-
|
|
82
|
-
|
|
59
|
+
const commitPendingChanges = () => ({ type: COMMIT_PENDING_CHANGES });
|
|
60
|
+
const storePdfId = (uid, pdfId) => ({
|
|
83
61
|
type: STORE_PDF_ID,
|
|
84
62
|
payload: { uid, pdfId }
|
|
85
63
|
});
|
|
86
|
-
|
|
64
|
+
const purgeAnnotation = (uid) => ({
|
|
87
65
|
type: PURGE_ANNOTATION,
|
|
88
66
|
payload: { uid }
|
|
89
67
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
68
|
+
const setActiveVariant = (k) => ({
|
|
69
|
+
type: SET_ACTIVE_VARIANT,
|
|
70
|
+
payload: k
|
|
71
|
+
});
|
|
72
|
+
const makeUid$1 = (pageIndex, localId) => `p${pageIndex}#${localId}`;
|
|
73
|
+
const parseUid = (uid) => {
|
|
94
74
|
const [pg, rest] = uid.slice(1).split("#");
|
|
95
75
|
return { pageIndex: Number(pg), localId: Number(rest) };
|
|
96
76
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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);
|
|
83
|
+
const makeUid = (page, id) => `p${page}#${id}`;
|
|
84
|
+
const getAnnotationsByPageIndex = (s, page) => (s.pages[page] ?? []).map((uid) => s.byUid[uid]);
|
|
85
|
+
const getAnnotations = (s) => {
|
|
102
86
|
const out = {};
|
|
103
87
|
for (const p of Object.keys(s.pages).map(Number)) out[p] = getAnnotationsByPageIndex(s, p);
|
|
104
88
|
return out;
|
|
105
89
|
};
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
const getSelectedAnnotation = (s) => s.selectedUid ? s.byUid[s.selectedUid] : null;
|
|
91
|
+
const getSelectedAnnotationWithPageIndex = (s) => {
|
|
108
92
|
if (!s.selectedUid) return null;
|
|
109
93
|
const { pageIndex, localId } = parseUid(s.selectedUid);
|
|
110
94
|
return { pageIndex, localId, annotation: s.byUid[s.selectedUid].object };
|
|
111
95
|
};
|
|
112
|
-
|
|
96
|
+
const getSelectedAnnotationByPageIndex = (s, pageIndex) => {
|
|
113
97
|
if (!s.selectedUid) return null;
|
|
114
98
|
const pageUids = s.pages[pageIndex] ?? [];
|
|
115
99
|
if (pageUids.includes(s.selectedUid)) {
|
|
@@ -117,33 +101,240 @@ var getSelectedAnnotationByPageIndex = (s, pageIndex) => {
|
|
|
117
101
|
}
|
|
118
102
|
return null;
|
|
119
103
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
104
|
+
const isInAnnotationVariant = (s) => s.activeVariant !== null;
|
|
105
|
+
const getSelectedAnnotationVariant = (s) => s.activeVariant;
|
|
106
|
+
const isAnnotationSelected = (s, page, id) => s.selectedUid === makeUid(page, id);
|
|
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)
|
|
231
|
+
};
|
|
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
|
+
const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
126
319
|
constructor(id, registry, engine, config) {
|
|
127
320
|
super(id, registry);
|
|
128
321
|
this.ANNOTATION_HISTORY_TOPIC = "annotations";
|
|
129
322
|
this.state$ = createBehaviorEmitter();
|
|
130
|
-
|
|
131
|
-
this.
|
|
132
|
-
|
|
133
|
-
this.subtypeByMode = /* @__PURE__ */ new Map();
|
|
134
|
-
this.modeChange$ = createBehaviorEmitter();
|
|
323
|
+
this.modeByVariant = /* @__PURE__ */ new Map();
|
|
324
|
+
this.variantByMode = /* @__PURE__ */ new Map();
|
|
325
|
+
this.activeVariantChange$ = createBehaviorEmitter();
|
|
135
326
|
this.activeTool$ = createBehaviorEmitter({
|
|
136
|
-
|
|
327
|
+
variantKey: null,
|
|
137
328
|
defaults: null
|
|
138
329
|
});
|
|
139
330
|
this.engine = engine;
|
|
140
331
|
this.config = config;
|
|
141
332
|
const selection = registry.getPlugin("selection");
|
|
142
|
-
this.selection = selection
|
|
333
|
+
this.selection = (selection == null ? void 0 : selection.provides()) ?? null;
|
|
143
334
|
const history = registry.getPlugin("history");
|
|
144
|
-
this.history = history
|
|
335
|
+
this.history = (history == null ? void 0 : history.provides()) ?? null;
|
|
145
336
|
const interactionManager = registry.getPlugin("interaction-manager");
|
|
146
|
-
this.interactionManager = interactionManager
|
|
337
|
+
this.interactionManager = (interactionManager == null ? void 0 : interactionManager.provides()) ?? null;
|
|
147
338
|
this.coreStore.onAction(SET_DOCUMENT, (_action, state) => {
|
|
148
339
|
const doc = state.core.document;
|
|
149
340
|
if (doc) {
|
|
@@ -152,48 +343,55 @@ var AnnotationPlugin = class extends BasePlugin {
|
|
|
152
343
|
});
|
|
153
344
|
}
|
|
154
345
|
async initialize() {
|
|
155
|
-
|
|
156
|
-
|
|
346
|
+
var _a, _b, _c;
|
|
347
|
+
for (const [variantKey, defaults] of Object.entries(this.state.toolDefaults)) {
|
|
348
|
+
this.registerTool(variantKey, defaults);
|
|
157
349
|
}
|
|
158
|
-
this.history
|
|
350
|
+
(_a = this.history) == null ? void 0 : _a.onHistoryChange((topic) => {
|
|
159
351
|
if (topic === this.ANNOTATION_HISTORY_TOPIC && this.config.autoCommit !== false) {
|
|
160
352
|
this.commit();
|
|
161
353
|
}
|
|
162
354
|
});
|
|
163
|
-
this.interactionManager
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.
|
|
355
|
+
(_b = this.interactionManager) == null ? void 0 : _b.onModeChange((s) => {
|
|
356
|
+
const newVariant = this.variantByMode.get(s.activeMode) ?? null;
|
|
357
|
+
console.log(newVariant, this.state.activeVariant);
|
|
358
|
+
if (newVariant !== this.state.activeVariant) {
|
|
359
|
+
this.dispatch(setActiveVariant(newVariant));
|
|
360
|
+
this.activeVariantChange$.emit(newVariant);
|
|
168
361
|
}
|
|
169
362
|
});
|
|
170
|
-
this.selection
|
|
171
|
-
|
|
172
|
-
if (!
|
|
363
|
+
(_c = this.selection) == null ? void 0 : _c.onEndSelection(() => {
|
|
364
|
+
var _a2, _b2;
|
|
365
|
+
if (!this.state.activeVariant) return;
|
|
366
|
+
if (!(this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.HIGHLIGHT) || this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.UNDERLINE) || this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.STRIKEOUT) || this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.SQUIGGLY))) {
|
|
173
367
|
return;
|
|
174
368
|
}
|
|
175
|
-
const formattedSelection = this.selection
|
|
369
|
+
const formattedSelection = (_a2 = this.selection) == null ? void 0 : _a2.getFormattedSelection();
|
|
176
370
|
if (!formattedSelection) return;
|
|
177
371
|
for (const selection of formattedSelection) {
|
|
178
372
|
const rect = selection.rect;
|
|
179
373
|
const segmentRects = selection.segmentRects;
|
|
180
|
-
const type = this.state.
|
|
374
|
+
const type = this.state.activeVariant;
|
|
375
|
+
const subtype = this.state.toolDefaults[type].subtype;
|
|
181
376
|
const color = this.state.toolDefaults[type].color;
|
|
182
377
|
const opacity = this.state.toolDefaults[type].opacity;
|
|
378
|
+
const blendMode = this.state.toolDefaults[type].blendMode ?? PdfBlendMode.Normal;
|
|
183
379
|
this.createAnnotation(selection.pageIndex, {
|
|
184
|
-
type,
|
|
380
|
+
type: subtype,
|
|
185
381
|
rect,
|
|
186
382
|
segmentRects,
|
|
187
383
|
color,
|
|
188
384
|
opacity,
|
|
385
|
+
blendMode,
|
|
189
386
|
pageIndex: selection.pageIndex,
|
|
190
387
|
id: Date.now() + Math.random()
|
|
191
388
|
});
|
|
192
389
|
}
|
|
193
|
-
this.selection
|
|
390
|
+
(_b2 = this.selection) == null ? void 0 : _b2.clear();
|
|
194
391
|
});
|
|
195
392
|
}
|
|
196
|
-
registerTool(
|
|
393
|
+
registerTool(variantKey, defaults) {
|
|
394
|
+
var _a, _b;
|
|
197
395
|
const modeId = defaults.interaction.mode;
|
|
198
396
|
const interactionMode = {
|
|
199
397
|
id: modeId,
|
|
@@ -201,12 +399,12 @@ var AnnotationPlugin = class extends BasePlugin {
|
|
|
201
399
|
exclusive: defaults.interaction.exclusive,
|
|
202
400
|
cursor: defaults.interaction.cursor
|
|
203
401
|
};
|
|
204
|
-
this.interactionManager
|
|
402
|
+
(_a = this.interactionManager) == null ? void 0 : _a.registerMode(interactionMode);
|
|
205
403
|
if (defaults.textSelection) {
|
|
206
|
-
this.selection
|
|
404
|
+
(_b = this.selection) == null ? void 0 : _b.enableForMode(modeId);
|
|
207
405
|
}
|
|
208
|
-
this.
|
|
209
|
-
this.
|
|
406
|
+
this.modeByVariant.set(variantKey, modeId);
|
|
407
|
+
this.variantByMode.set(modeId, variantKey);
|
|
210
408
|
}
|
|
211
409
|
buildCapability() {
|
|
212
410
|
return {
|
|
@@ -222,28 +420,38 @@ var AnnotationPlugin = class extends BasePlugin {
|
|
|
222
420
|
deselectAnnotation: () => {
|
|
223
421
|
this.dispatch(deselectAnnotation());
|
|
224
422
|
},
|
|
225
|
-
|
|
226
|
-
return this.state.
|
|
423
|
+
getActiveVariant: () => {
|
|
424
|
+
return this.state.activeVariant;
|
|
227
425
|
},
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
426
|
+
setActiveVariant: (variantKey) => {
|
|
427
|
+
var _a, _b;
|
|
428
|
+
if (variantKey === this.state.activeVariant) return;
|
|
429
|
+
if (variantKey) {
|
|
430
|
+
const mode = this.modeByVariant.get(variantKey);
|
|
431
|
+
if (!mode) throw new Error(`Mode missing for variant ${variantKey}`);
|
|
432
|
+
(_a = this.interactionManager) == null ? void 0 : _a.activate(mode);
|
|
234
433
|
} else {
|
|
235
|
-
this.interactionManager
|
|
434
|
+
(_b = this.interactionManager) == null ? void 0 : _b.activate("default");
|
|
236
435
|
}
|
|
237
436
|
},
|
|
238
|
-
|
|
239
|
-
|
|
437
|
+
getSubtypeAndIntentByVariant: (variantKey) => {
|
|
438
|
+
return parseVariantKey(variantKey);
|
|
439
|
+
},
|
|
440
|
+
getToolDefaults: (variantKey) => {
|
|
441
|
+
const defaults = this.state.toolDefaults[variantKey];
|
|
240
442
|
if (!defaults) {
|
|
241
|
-
throw new Error(`No defaults found for
|
|
443
|
+
throw new Error(`No defaults found for variant: ${variantKey}`);
|
|
242
444
|
}
|
|
243
445
|
return defaults;
|
|
244
446
|
},
|
|
245
|
-
|
|
246
|
-
this.
|
|
447
|
+
getToolDefaultsBySubtypeAndIntent: (subtype, intent) => {
|
|
448
|
+
return getToolDefaultsBySubtypeAndIntent(this.state, subtype, intent);
|
|
449
|
+
},
|
|
450
|
+
getToolDefaultsBySubtype: (subtype) => {
|
|
451
|
+
return getToolDefaultsBySubtypeAndIntent(this.state, subtype);
|
|
452
|
+
},
|
|
453
|
+
setToolDefaults: (variantKey, patch) => {
|
|
454
|
+
this.dispatch(updateToolDefaults(variantKey, patch));
|
|
247
455
|
},
|
|
248
456
|
getColorPresets: () => [...this.state.colorPresets],
|
|
249
457
|
addColorPreset: (color) => this.dispatch(addColorPreset(color)),
|
|
@@ -252,24 +460,24 @@ var AnnotationPlugin = class extends BasePlugin {
|
|
|
252
460
|
deleteAnnotation: (pageIndex, localId) => this.deleteAnnotation(pageIndex, localId),
|
|
253
461
|
renderAnnotation: (options) => this.renderAnnotation(options),
|
|
254
462
|
onStateChange: this.state$.on,
|
|
255
|
-
|
|
463
|
+
onActiveVariantChange: this.activeVariantChange$.on,
|
|
256
464
|
onActiveToolChange: this.activeTool$.on,
|
|
257
465
|
commit: () => this.commit()
|
|
258
466
|
};
|
|
259
467
|
}
|
|
260
468
|
createActiveTool(mode, toolDefaults) {
|
|
261
469
|
if (mode === null) {
|
|
262
|
-
return {
|
|
470
|
+
return { variantKey: null, defaults: null };
|
|
263
471
|
}
|
|
264
|
-
return { mode, defaults: toolDefaults[mode] };
|
|
472
|
+
return { variantKey: mode, defaults: toolDefaults[mode] };
|
|
265
473
|
}
|
|
266
474
|
emitActiveTool(state) {
|
|
267
|
-
const activeTool = this.createActiveTool(state.
|
|
475
|
+
const activeTool = this.createActiveTool(state.activeVariant, state.toolDefaults);
|
|
268
476
|
this.activeTool$.emit(activeTool);
|
|
269
477
|
}
|
|
270
478
|
onStoreUpdated(prev, next) {
|
|
271
479
|
this.state$.emit(next);
|
|
272
|
-
if (prev.
|
|
480
|
+
if (prev.activeVariant !== next.activeVariant || prev.toolDefaults[prev.activeVariant ?? PdfAnnotationSubtype.HIGHLIGHT] !== next.toolDefaults[next.activeVariant ?? PdfAnnotationSubtype.HIGHLIGHT]) {
|
|
273
481
|
this.emitActiveTool(next);
|
|
274
482
|
}
|
|
275
483
|
}
|
|
@@ -337,20 +545,26 @@ var AnnotationPlugin = class extends BasePlugin {
|
|
|
337
545
|
};
|
|
338
546
|
this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
|
|
339
547
|
}
|
|
548
|
+
buildPatch(original, patch) {
|
|
549
|
+
if ("rect" in patch) return patch;
|
|
550
|
+
const merged = { ...original, ...patch };
|
|
551
|
+
return { ...patch, rect: deriveRect(merged) };
|
|
552
|
+
}
|
|
340
553
|
updateAnnotation(pageIndex, localId, patch) {
|
|
554
|
+
const originalObject = this.state.byUid[makeUid$1(pageIndex, localId)].object;
|
|
555
|
+
const finalPatch = this.buildPatch(originalObject, patch);
|
|
341
556
|
if (!this.history) {
|
|
342
|
-
this.dispatch(patchAnnotation(pageIndex, localId,
|
|
557
|
+
this.dispatch(patchAnnotation(pageIndex, localId, finalPatch));
|
|
343
558
|
if (this.config.autoCommit !== false) {
|
|
344
559
|
this.commit();
|
|
345
560
|
}
|
|
346
561
|
return;
|
|
347
562
|
}
|
|
348
|
-
const originalObject = this.state.byUid[makeUid(pageIndex, localId)].object;
|
|
349
563
|
const originalPatch = Object.fromEntries(
|
|
350
564
|
Object.keys(patch).map((key) => [key, originalObject[key]])
|
|
351
565
|
);
|
|
352
566
|
const command = {
|
|
353
|
-
execute: () => this.dispatch(patchAnnotation(pageIndex, localId,
|
|
567
|
+
execute: () => this.dispatch(patchAnnotation(pageIndex, localId, finalPatch)),
|
|
354
568
|
undo: () => this.dispatch(patchAnnotation(pageIndex, localId, originalPatch))
|
|
355
569
|
};
|
|
356
570
|
this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);
|
|
@@ -364,7 +578,7 @@ var AnnotationPlugin = class extends BasePlugin {
|
|
|
364
578
|
}
|
|
365
579
|
return;
|
|
366
580
|
}
|
|
367
|
-
const originalAnnotation = this.state.byUid[makeUid(pageIndex, localId)].object;
|
|
581
|
+
const originalAnnotation = this.state.byUid[makeUid$1(pageIndex, localId)].object;
|
|
368
582
|
const command = {
|
|
369
583
|
execute: () => {
|
|
370
584
|
this.dispatch(deselectAnnotation());
|
|
@@ -441,11 +655,9 @@ var AnnotationPlugin = class extends BasePlugin {
|
|
|
441
655
|
return task;
|
|
442
656
|
}
|
|
443
657
|
};
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
import { PdfAnnotationSubtype as PdfAnnotationSubtype2 } from "@embedpdf/models";
|
|
448
|
-
var DEFAULT_COLORS = [
|
|
658
|
+
_AnnotationPlugin.id = "annotation";
|
|
659
|
+
let AnnotationPlugin = _AnnotationPlugin;
|
|
660
|
+
const DEFAULT_COLORS = [
|
|
449
661
|
"#E44234",
|
|
450
662
|
"#FF8D00",
|
|
451
663
|
"#FFCD45",
|
|
@@ -455,7 +667,7 @@ var DEFAULT_COLORS = [
|
|
|
455
667
|
"#C544CE",
|
|
456
668
|
"#7D2E25"
|
|
457
669
|
];
|
|
458
|
-
|
|
670
|
+
const patchAnno = (state, uid, patch) => {
|
|
459
671
|
const prev = state.byUid[uid];
|
|
460
672
|
if (!prev) return state;
|
|
461
673
|
return {
|
|
@@ -471,54 +683,138 @@ var patchAnno = (state, uid, patch) => {
|
|
|
471
683
|
hasPendingChanges: true
|
|
472
684
|
};
|
|
473
685
|
};
|
|
474
|
-
|
|
686
|
+
const initialState = (cfg) => ({
|
|
475
687
|
pages: {},
|
|
476
688
|
byUid: {},
|
|
477
689
|
selectedUid: null,
|
|
478
|
-
|
|
690
|
+
activeVariant: null,
|
|
479
691
|
toolDefaults: {
|
|
480
|
-
[
|
|
692
|
+
[makeVariantKey(PdfAnnotationSubtype.HIGHLIGHT)]: {
|
|
481
693
|
name: "Highlight",
|
|
694
|
+
subtype: PdfAnnotationSubtype.HIGHLIGHT,
|
|
695
|
+
interaction: { mode: "highlight", exclusive: false },
|
|
696
|
+
textSelection: true,
|
|
482
697
|
color: "#FFCD45",
|
|
483
698
|
opacity: 1,
|
|
484
|
-
|
|
485
|
-
textSelection: true
|
|
699
|
+
blendMode: PdfBlendMode.Multiply
|
|
486
700
|
},
|
|
487
|
-
[
|
|
701
|
+
[makeVariantKey(PdfAnnotationSubtype.UNDERLINE)]: {
|
|
488
702
|
name: "Underline",
|
|
703
|
+
subtype: PdfAnnotationSubtype.UNDERLINE,
|
|
704
|
+
interaction: { mode: "underline", exclusive: false },
|
|
705
|
+
textSelection: true,
|
|
489
706
|
color: "#E44234",
|
|
490
707
|
opacity: 1,
|
|
491
|
-
|
|
492
|
-
textSelection: true
|
|
708
|
+
blendMode: PdfBlendMode.Normal
|
|
493
709
|
},
|
|
494
|
-
[
|
|
710
|
+
[makeVariantKey(PdfAnnotationSubtype.STRIKEOUT)]: {
|
|
495
711
|
name: "Strikeout",
|
|
712
|
+
subtype: PdfAnnotationSubtype.STRIKEOUT,
|
|
713
|
+
interaction: { mode: "strikeout", exclusive: false },
|
|
714
|
+
textSelection: true,
|
|
496
715
|
color: "#E44234",
|
|
497
716
|
opacity: 1,
|
|
498
|
-
|
|
499
|
-
textSelection: true
|
|
717
|
+
blendMode: PdfBlendMode.Normal
|
|
500
718
|
},
|
|
501
|
-
[
|
|
719
|
+
[makeVariantKey(PdfAnnotationSubtype.SQUIGGLY)]: {
|
|
502
720
|
name: "Squiggly",
|
|
721
|
+
subtype: PdfAnnotationSubtype.SQUIGGLY,
|
|
722
|
+
interaction: { mode: "squiggly", exclusive: false },
|
|
723
|
+
textSelection: true,
|
|
503
724
|
color: "#E44234",
|
|
504
725
|
opacity: 1,
|
|
505
|
-
|
|
506
|
-
textSelection: true
|
|
726
|
+
blendMode: PdfBlendMode.Normal
|
|
507
727
|
},
|
|
508
|
-
[
|
|
728
|
+
[makeVariantKey(PdfAnnotationSubtype.INK)]: {
|
|
509
729
|
name: "Ink",
|
|
730
|
+
subtype: PdfAnnotationSubtype.INK,
|
|
731
|
+
interaction: { mode: "ink", exclusive: true, cursor: "crosshair" },
|
|
510
732
|
color: "#E44234",
|
|
511
733
|
opacity: 1,
|
|
512
734
|
strokeWidth: 11,
|
|
513
|
-
|
|
514
|
-
|
|
735
|
+
blendMode: PdfBlendMode.Normal
|
|
736
|
+
},
|
|
737
|
+
[makeVariantKey(PdfAnnotationSubtype.INK, "InkHighlight")]: {
|
|
738
|
+
name: "Ink Highlight",
|
|
739
|
+
subtype: PdfAnnotationSubtype.INK,
|
|
740
|
+
intent: "InkHighlight",
|
|
741
|
+
interaction: { mode: "inkHighlight", exclusive: true, cursor: "crosshair" },
|
|
742
|
+
color: "#E44234",
|
|
743
|
+
opacity: 1,
|
|
744
|
+
strokeWidth: 11,
|
|
745
|
+
blendMode: PdfBlendMode.Multiply
|
|
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
|
|
515
811
|
},
|
|
516
812
|
...cfg.toolDefaults
|
|
517
813
|
},
|
|
518
814
|
colorPresets: cfg.colorPresets ?? DEFAULT_COLORS,
|
|
519
815
|
hasPendingChanges: false
|
|
520
816
|
});
|
|
521
|
-
|
|
817
|
+
const reducer = (state, action) => {
|
|
522
818
|
switch (action.type) {
|
|
523
819
|
/* ───── bulk load from engine ───── */
|
|
524
820
|
case SET_ANNOTATIONS: {
|
|
@@ -530,9 +826,9 @@ var reducer = (state, action) => {
|
|
|
530
826
|
for (const uid of oldUidsOnPage) {
|
|
531
827
|
delete newByUid[uid];
|
|
532
828
|
}
|
|
533
|
-
const newUidsOnPage = list.map((a,
|
|
534
|
-
const localId = Date.now() + Math.random() +
|
|
535
|
-
const uid = makeUid(pageIndex, localId);
|
|
829
|
+
const newUidsOnPage = list.map((a, index2) => {
|
|
830
|
+
const localId = Date.now() + Math.random() + index2;
|
|
831
|
+
const uid = makeUid$1(pageIndex, localId);
|
|
536
832
|
newByUid[uid] = { localId, pdfId: a.id, commitState: "synced", object: a };
|
|
537
833
|
return uid;
|
|
538
834
|
});
|
|
@@ -541,31 +837,33 @@ var reducer = (state, action) => {
|
|
|
541
837
|
return { ...state, pages: newPages, byUid: newByUid };
|
|
542
838
|
}
|
|
543
839
|
/* ───── GUI bits ───── */
|
|
544
|
-
case
|
|
545
|
-
return { ...state,
|
|
840
|
+
case SET_ACTIVE_VARIANT:
|
|
841
|
+
return { ...state, activeVariant: action.payload };
|
|
546
842
|
case SELECT_ANNOTATION:
|
|
547
843
|
return {
|
|
548
844
|
...state,
|
|
549
|
-
selectedUid: makeUid(action.payload.pageIndex, action.payload.localId)
|
|
845
|
+
selectedUid: makeUid$1(action.payload.pageIndex, action.payload.localId)
|
|
550
846
|
};
|
|
551
847
|
case DESELECT_ANNOTATION:
|
|
552
848
|
return { ...state, selectedUid: null };
|
|
553
849
|
case ADD_COLOR_PRESET:
|
|
554
850
|
return state.colorPresets.includes(action.payload) ? state : { ...state, colorPresets: [...state.colorPresets, action.payload] };
|
|
555
851
|
case UPDATE_TOOL_DEFAULTS: {
|
|
556
|
-
const {
|
|
852
|
+
const { variantKey, patch } = action.payload;
|
|
853
|
+
const prev = state.toolDefaults[variantKey];
|
|
854
|
+
if (!prev) return state;
|
|
557
855
|
return {
|
|
558
856
|
...state,
|
|
559
857
|
toolDefaults: {
|
|
560
858
|
...state.toolDefaults,
|
|
561
|
-
[
|
|
859
|
+
[variantKey]: { ...prev, ...patch }
|
|
562
860
|
}
|
|
563
861
|
};
|
|
564
862
|
}
|
|
565
863
|
/* ───── create ───── */
|
|
566
864
|
case CREATE_ANNOTATION: {
|
|
567
865
|
const { pageIndex, localId, annotation } = action.payload;
|
|
568
|
-
const uid = makeUid(pageIndex, localId);
|
|
866
|
+
const uid = makeUid$1(pageIndex, localId);
|
|
569
867
|
return {
|
|
570
868
|
...state,
|
|
571
869
|
pages: { ...state.pages, [pageIndex]: [...state.pages[pageIndex] ?? [], uid] },
|
|
@@ -579,7 +877,7 @@ var reducer = (state, action) => {
|
|
|
579
877
|
/* ───── delete ───── */
|
|
580
878
|
case DELETE_ANNOTATION: {
|
|
581
879
|
const { pageIndex, localId } = action.payload;
|
|
582
|
-
const uid = makeUid(pageIndex, localId);
|
|
880
|
+
const uid = makeUid$1(pageIndex, localId);
|
|
583
881
|
if (!state.byUid[uid]) return state;
|
|
584
882
|
return {
|
|
585
883
|
...state,
|
|
@@ -596,7 +894,7 @@ var reducer = (state, action) => {
|
|
|
596
894
|
}
|
|
597
895
|
/* ───── field edits ───── */
|
|
598
896
|
case PATCH_ANNOTATION: {
|
|
599
|
-
const uid = makeUid(action.payload.pageIndex, action.payload.localId);
|
|
897
|
+
const uid = makeUid$1(action.payload.pageIndex, action.payload.localId);
|
|
600
898
|
return patchAnno(state, uid, action.payload.patch);
|
|
601
899
|
}
|
|
602
900
|
/* ───── commit bookkeeping ───── */
|
|
@@ -617,7 +915,7 @@ var reducer = (state, action) => {
|
|
|
617
915
|
const annosOnPage = uidsOnPage.map((uid) => state.byUid[uid]).filter((ta) => ta && ta.commitState !== "deleted");
|
|
618
916
|
annosOnPage.sort((a, b) => (a.pdfId ?? Infinity) - (b.pdfId ?? Infinity));
|
|
619
917
|
annosOnPage.forEach((ta, newPdfId) => {
|
|
620
|
-
const uid = makeUid(pageIndex, ta.localId);
|
|
918
|
+
const uid = makeUid$1(pageIndex, ta.localId);
|
|
621
919
|
newByUid[uid] = { ...newByUid[uid], pdfId: newPdfId };
|
|
622
920
|
});
|
|
623
921
|
return { ...state, byUid: newByUid };
|
|
@@ -643,9 +941,40 @@ var reducer = (state, action) => {
|
|
|
643
941
|
return state;
|
|
644
942
|
}
|
|
645
943
|
};
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
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
|
+
}
|
|
977
|
+
const AnnotationPluginPackage = {
|
|
649
978
|
manifest,
|
|
650
979
|
create: (registry, engine, config) => new AnnotationPlugin(ANNOTATION_PLUGIN_ID, registry, engine, config),
|
|
651
980
|
reducer,
|
|
@@ -659,10 +988,26 @@ export {
|
|
|
659
988
|
getAnnotationsByPageIndex,
|
|
660
989
|
getSelectedAnnotation,
|
|
661
990
|
getSelectedAnnotationByPageIndex,
|
|
662
|
-
|
|
991
|
+
getSelectedAnnotationVariant,
|
|
663
992
|
getSelectedAnnotationWithPageIndex,
|
|
993
|
+
getToolDefaultsBySubtypeAndIntent,
|
|
664
994
|
isAnnotationSelected,
|
|
665
|
-
|
|
666
|
-
|
|
995
|
+
isCircle,
|
|
996
|
+
isHighlight,
|
|
997
|
+
isInAnnotationVariant,
|
|
998
|
+
isInk,
|
|
999
|
+
isLine,
|
|
1000
|
+
isPolygon,
|
|
1001
|
+
isPolyline,
|
|
1002
|
+
isSquare,
|
|
1003
|
+
isSquiggly,
|
|
1004
|
+
isStrikeout,
|
|
1005
|
+
isTextMarkup,
|
|
1006
|
+
isUnderline,
|
|
1007
|
+
makeVariantKey,
|
|
1008
|
+
manifest,
|
|
1009
|
+
parseVariantKey,
|
|
1010
|
+
index as patching,
|
|
1011
|
+
variantKeyFromAnnotation
|
|
667
1012
|
};
|
|
668
|
-
//# sourceMappingURL=index.js.map
|
|
1013
|
+
//# sourceMappingURL=index.js.map
|