@embedpdf/plugin-annotation 3.0.0-next.9 → 3.1.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/README.md +129 -0
- package/dist/authoring.cjs +26 -0
- package/dist/authoring.d.cts +2 -0
- package/dist/authoring.d.ts +2 -0
- package/dist/authoring.js +2 -0
- package/dist/contract/host.cjs +19 -0
- package/dist/contract/host.d.cts +3 -0
- package/dist/contract/host.d.ts +3 -0
- package/dist/contract/host.js +3 -0
- package/dist/contract-CimdVhUD.d.cts +1176 -0
- package/dist/contract-DlJK3S9O.cjs +689 -0
- package/dist/contract-DlJK3S9O.cjs.map +1 -0
- package/dist/contract-nPw63clg.js +642 -0
- package/dist/contract-nPw63clg.js.map +1 -0
- package/dist/contract-uV_HOYTW.d.ts +1176 -0
- package/dist/contract.cjs +13 -0
- package/dist/contract.d.cts +2 -0
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +2 -0
- package/dist/host-contract-Br2Nwfm8.d.ts +346 -0
- package/dist/host-contract-Ckl6r4Ch.d.cts +346 -0
- package/dist/host-contract-DP61yEHS.js +52 -0
- package/dist/host-contract-DP61yEHS.js.map +1 -0
- package/dist/host-contract-Os6ryEkJ.cjs +87 -0
- package/dist/host-contract-Os6ryEkJ.cjs.map +1 -0
- package/dist/index.cjs +5468 -419
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -59
- package/dist/index.d.ts +13 -59
- package/dist/index.js +5420 -398
- package/dist/index.js.map +1 -1
- package/package.json +24 -11
- package/dist/capability-2FkTVblD.cjs +0 -2806
- package/dist/capability-2FkTVblD.cjs.map +0 -1
- package/dist/capability-BNMRdnKf.js +0 -2741
- package/dist/capability-BNMRdnKf.js.map +0 -1
- package/dist/internal.cjs +0 -5
- package/dist/internal.d.cts +0 -13
- package/dist/internal.d.ts +0 -13
- package/dist/internal.js +0 -2
- package/dist/types-CvtDbnF5.d.cts +0 -912
- package/dist/types-Dy1RganE.d.ts +0 -912
|
@@ -0,0 +1,642 @@
|
|
|
1
|
+
import { createCapabilityToken, defineState } from "@embedpdf/core";
|
|
2
|
+
import { AnnotationTransfer } from "@embedpdf/engine-core/public";
|
|
3
|
+
import { ANNOTATION_FIELD_NAMES } from "@embedpdf/engine-core/runtime";
|
|
4
|
+
//#region src/token.ts
|
|
5
|
+
/** The package token — created once here; `contract.ts` re-exports it and
|
|
6
|
+
* `host-contract.ts` widens it to the host capability. */
|
|
7
|
+
const AnnotationToken = createCapabilityToken("annotation", {
|
|
8
|
+
hint: `add annotationPlugin() from '@embedpdf/plugin-annotation' to your plugins list`,
|
|
9
|
+
promises: {
|
|
10
|
+
refresh: true,
|
|
11
|
+
create: true,
|
|
12
|
+
createFromSelection: true,
|
|
13
|
+
update: true,
|
|
14
|
+
delete: true,
|
|
15
|
+
reorder: true,
|
|
16
|
+
export: true,
|
|
17
|
+
import: true,
|
|
18
|
+
downloadResource: true,
|
|
19
|
+
"links.set": true,
|
|
20
|
+
"links.clear": true,
|
|
21
|
+
"selection.update": true,
|
|
22
|
+
"selection.updateLink": true,
|
|
23
|
+
"selection.delete": true,
|
|
24
|
+
"selection.rotateBy": true,
|
|
25
|
+
"selection.resetRotation": true,
|
|
26
|
+
"selection.group": true,
|
|
27
|
+
"selection.ungroup": true,
|
|
28
|
+
"draft.finish": true,
|
|
29
|
+
"text.end": true,
|
|
30
|
+
"text.toggleFormat": true,
|
|
31
|
+
"stamps.arm": true,
|
|
32
|
+
"stamps.place": true,
|
|
33
|
+
"comments.reply": true,
|
|
34
|
+
"comments.setText": true,
|
|
35
|
+
"comments.setStatus": true,
|
|
36
|
+
"comments.setMarked": true,
|
|
37
|
+
"comments.delete": true,
|
|
38
|
+
"comments.deleteThread": true
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/state.ts
|
|
43
|
+
/**
|
|
44
|
+
* The selecting page's State table as code: what `useAnnotationState()`
|
|
45
|
+
* returns, and the same fields in every other framework. The annotations
|
|
46
|
+
* themselves are not here: `useAnnotationList()` reads them, so a component
|
|
47
|
+
* that shows the selection doesn't re-render for every change on the page.
|
|
48
|
+
*/
|
|
49
|
+
const annotationState = defineState(AnnotationToken, {
|
|
50
|
+
read: (annotation) => ({
|
|
51
|
+
status: annotation.getStatus(),
|
|
52
|
+
selected: annotation.selection.getSelected(),
|
|
53
|
+
hovered: annotation.getHovered(),
|
|
54
|
+
editing: annotation.text.getEditing()
|
|
55
|
+
}),
|
|
56
|
+
empty: {
|
|
57
|
+
status: "loading",
|
|
58
|
+
selected: [],
|
|
59
|
+
hovered: null,
|
|
60
|
+
editing: null
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/tools/definitions.ts
|
|
65
|
+
/**
|
|
66
|
+
* The tool `stamps.arm` activates — and the only tool an armed payload survives
|
|
67
|
+
* onto (plus the legacy `annotation-stamp` tag, honoured for embedder configs
|
|
68
|
+
* written before the tags were unified). Placement consults the armed payload
|
|
69
|
+
* before the active tool's own `source` spec, so a payload must not outlive
|
|
70
|
+
* its tool onto a sibling stamp preset: an `image` preset's click has to open
|
|
71
|
+
* its own picker, not silently place whatever the stamp panel last armed.
|
|
72
|
+
*/
|
|
73
|
+
const ARMED_STAMP_TOOL_ID = "stamp";
|
|
74
|
+
/** How opaque a ghost paints unless its tool says. */
|
|
75
|
+
const GHOST_OPACITY = .5;
|
|
76
|
+
/** A tool's ghost setting, resolved: `true` is half see-through. */
|
|
77
|
+
const resolveGhost = (ghost) => ghost === true ? { opacity: GHOST_OPACITY } : ghost;
|
|
78
|
+
/**
|
|
79
|
+
* The fields no tool's defaults may set: where the annotation goes (that comes
|
|
80
|
+
* from the drawing), its identity and relationships, and what the engine
|
|
81
|
+
* stamps or keeps by itself.
|
|
82
|
+
*/
|
|
83
|
+
const NOT_DEFAULTS = [
|
|
84
|
+
"ref",
|
|
85
|
+
"page",
|
|
86
|
+
"index",
|
|
87
|
+
"hasAppearance",
|
|
88
|
+
"appearanceState",
|
|
89
|
+
"nm",
|
|
90
|
+
"rect",
|
|
91
|
+
"box",
|
|
92
|
+
"linePoints",
|
|
93
|
+
"vertices",
|
|
94
|
+
"inkList",
|
|
95
|
+
"quadPoints",
|
|
96
|
+
"calloutLine",
|
|
97
|
+
"captionCenter",
|
|
98
|
+
"measure",
|
|
99
|
+
"reply",
|
|
100
|
+
"popup",
|
|
101
|
+
"parent",
|
|
102
|
+
"groupId",
|
|
103
|
+
"author",
|
|
104
|
+
"createdAt",
|
|
105
|
+
"modifiedAt",
|
|
106
|
+
"userId",
|
|
107
|
+
"createdBy",
|
|
108
|
+
"modifiedBy",
|
|
109
|
+
"importedBy",
|
|
110
|
+
"actions"
|
|
111
|
+
];
|
|
112
|
+
const WIDGET_BOX_FIELDS = [
|
|
113
|
+
"color",
|
|
114
|
+
"interiorColor",
|
|
115
|
+
"strokeWidth",
|
|
116
|
+
"borderStyle"
|
|
117
|
+
];
|
|
118
|
+
const WIDGET_TEXT_FIELDS = [
|
|
119
|
+
...WIDGET_BOX_FIELDS,
|
|
120
|
+
"fontFamily",
|
|
121
|
+
"fontSize",
|
|
122
|
+
"fontColor",
|
|
123
|
+
"textAlign"
|
|
124
|
+
];
|
|
125
|
+
/** Every field of an engine kind a tool's defaults may set: any field but the ones above. */
|
|
126
|
+
const draftDefaults = (subtype) => ANNOTATION_FIELD_NAMES[subtype].filter((name) => !NOT_DEFAULTS.includes(name));
|
|
127
|
+
/**
|
|
128
|
+
* The fields each known authoring kind's defaults may set: any field a create
|
|
129
|
+
* from the tool takes besides where it goes, flags and `contents` included.
|
|
130
|
+
* A key outside it stops the app at startup, naming the tool and the field.
|
|
131
|
+
*/
|
|
132
|
+
const TOOL_DEFAULT_FIELDS = {
|
|
133
|
+
square: draftDefaults("square"),
|
|
134
|
+
circle: draftDefaults("circle"),
|
|
135
|
+
line: draftDefaults("line"),
|
|
136
|
+
polygon: draftDefaults("polygon"),
|
|
137
|
+
polyline: draftDefaults("polyline"),
|
|
138
|
+
ink: draftDefaults("ink"),
|
|
139
|
+
"free-text": draftDefaults("free-text"),
|
|
140
|
+
"free-text-callout": draftDefaults("free-text"),
|
|
141
|
+
highlight: draftDefaults("highlight"),
|
|
142
|
+
underline: draftDefaults("underline"),
|
|
143
|
+
strikeout: draftDefaults("strikeout"),
|
|
144
|
+
squiggly: draftDefaults("squiggly"),
|
|
145
|
+
caret: draftDefaults("caret"),
|
|
146
|
+
redact: draftDefaults("redact"),
|
|
147
|
+
stamp: draftDefaults("stamp"),
|
|
148
|
+
link: draftDefaults("link"),
|
|
149
|
+
text: draftDefaults("text"),
|
|
150
|
+
"file-attachment": draftDefaults("file-attachment"),
|
|
151
|
+
"widget-text": WIDGET_TEXT_FIELDS,
|
|
152
|
+
"widget-choice": WIDGET_TEXT_FIELDS,
|
|
153
|
+
"widget-button": WIDGET_TEXT_FIELDS,
|
|
154
|
+
"widget-toggle": WIDGET_BOX_FIELDS,
|
|
155
|
+
"widget-radio": WIDGET_BOX_FIELDS,
|
|
156
|
+
"widget-box": WIDGET_BOX_FIELDS
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* The tools whose line gesture is captured instead of created: the measurement
|
|
160
|
+
* plugin turns the calibrate tool's two points into a scale. A tool that
|
|
161
|
+
* extends one captures too.
|
|
162
|
+
*/
|
|
163
|
+
const CAPTURE_TOOLS = /* @__PURE__ */ new Set(["calibrate"]);
|
|
164
|
+
const DRAW_TAGS = ["annotation-draw", "annotation-edit"];
|
|
165
|
+
/** This viewer's drawing red: shapes, lines and text boxes start in it. */
|
|
166
|
+
const HOUSE_RED = "#e5484d";
|
|
167
|
+
const MARKUP_TAGS = ["text-select", "annotation-edit"];
|
|
168
|
+
/**
|
|
169
|
+
* What one finger does while this annotation tool is active (`Tool.touch`):
|
|
170
|
+
* drag-create tools (shape/ink draw and text-markup select) take it as `'draw'`
|
|
171
|
+
* (a finger draws or marks, two fingers navigate: the drawing-app convention).
|
|
172
|
+
* Click-to-place tools (stamp, note) are `'tap'`: a tap places, and drags keep
|
|
173
|
+
* scrolling. Derived from the gesture tags, so custom registered tools inherit
|
|
174
|
+
* the right behavior. Only annotation-owned tools run through this: the
|
|
175
|
+
* built-in `pointer` tool also enables `text-select`, but the hub registers it.
|
|
176
|
+
*/
|
|
177
|
+
const toolTouchOf = (enables) => enables.has("annotation-draw") || enables.has("text-select") ? "draw" : "tap";
|
|
178
|
+
/**
|
|
179
|
+
* The built-in tools, as data (shapes + lines + ink
|
|
180
|
+
* + free text in the draw channel, text markup + caret behind text selection, and
|
|
181
|
+
* the click-to-place stamp). Order is display-neutral; the toolbar owns layout.
|
|
182
|
+
*/
|
|
183
|
+
const DEFAULT_TOOLS = [
|
|
184
|
+
{
|
|
185
|
+
id: "square",
|
|
186
|
+
subtype: "square",
|
|
187
|
+
cursor: "crosshair",
|
|
188
|
+
enables: DRAW_TAGS,
|
|
189
|
+
defaults: {
|
|
190
|
+
color: HOUSE_RED,
|
|
191
|
+
strokeWidth: 6
|
|
192
|
+
},
|
|
193
|
+
clickCreate: {
|
|
194
|
+
width: 80,
|
|
195
|
+
height: 60
|
|
196
|
+
},
|
|
197
|
+
upright: true
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: "circle",
|
|
201
|
+
subtype: "circle",
|
|
202
|
+
cursor: "crosshair",
|
|
203
|
+
enables: DRAW_TAGS,
|
|
204
|
+
defaults: {
|
|
205
|
+
color: HOUSE_RED,
|
|
206
|
+
strokeWidth: 6
|
|
207
|
+
},
|
|
208
|
+
clickCreate: {
|
|
209
|
+
width: 80,
|
|
210
|
+
height: 60
|
|
211
|
+
},
|
|
212
|
+
upright: true
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
id: "line",
|
|
216
|
+
subtype: "line",
|
|
217
|
+
cursor: "crosshair",
|
|
218
|
+
enables: DRAW_TAGS,
|
|
219
|
+
defaults: {
|
|
220
|
+
color: HOUSE_RED,
|
|
221
|
+
strokeWidth: 6
|
|
222
|
+
},
|
|
223
|
+
clickCreate: { length: 80 },
|
|
224
|
+
upright: true
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
id: "distance",
|
|
228
|
+
extends: "line",
|
|
229
|
+
clickCreate: false,
|
|
230
|
+
defaults: {
|
|
231
|
+
intent: "line-dimension",
|
|
232
|
+
strokeWidth: 1,
|
|
233
|
+
lineEndings: {
|
|
234
|
+
start: "closed-arrow",
|
|
235
|
+
end: "closed-arrow"
|
|
236
|
+
},
|
|
237
|
+
captionEnabled: true,
|
|
238
|
+
captionPosition: "inline",
|
|
239
|
+
leader: {
|
|
240
|
+
length: 12,
|
|
241
|
+
extension: 5,
|
|
242
|
+
offset: 0
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: "calibrate",
|
|
248
|
+
extends: "line",
|
|
249
|
+
enables: ["annotation-draw"],
|
|
250
|
+
defaults: { strokeWidth: 1 },
|
|
251
|
+
clickCreate: false
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: "polygon",
|
|
255
|
+
subtype: "polygon",
|
|
256
|
+
cursor: "crosshair",
|
|
257
|
+
enables: DRAW_TAGS,
|
|
258
|
+
defaults: {
|
|
259
|
+
color: HOUSE_RED,
|
|
260
|
+
strokeWidth: 6
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
id: "polyline",
|
|
265
|
+
subtype: "polyline",
|
|
266
|
+
cursor: "crosshair",
|
|
267
|
+
enables: DRAW_TAGS,
|
|
268
|
+
defaults: {
|
|
269
|
+
color: HOUSE_RED,
|
|
270
|
+
strokeWidth: 6
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
id: "perimeter",
|
|
275
|
+
extends: "polyline",
|
|
276
|
+
defaults: {
|
|
277
|
+
intent: "polyline-dimension",
|
|
278
|
+
strokeWidth: 1,
|
|
279
|
+
lineEndings: {
|
|
280
|
+
start: "none",
|
|
281
|
+
end: "none"
|
|
282
|
+
},
|
|
283
|
+
captionEnabled: true
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
id: "area",
|
|
288
|
+
extends: "polygon",
|
|
289
|
+
defaults: {
|
|
290
|
+
intent: "polygon-dimension",
|
|
291
|
+
strokeWidth: 1,
|
|
292
|
+
captionEnabled: true
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
id: "ink",
|
|
297
|
+
subtype: "ink",
|
|
298
|
+
cursor: "crosshair",
|
|
299
|
+
enables: DRAW_TAGS,
|
|
300
|
+
defaults: {
|
|
301
|
+
color: "#ef4444",
|
|
302
|
+
strokeWidth: 6,
|
|
303
|
+
blendMode: "normal"
|
|
304
|
+
},
|
|
305
|
+
ink: { groupStrokesMs: 800 }
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
id: "ink-highlight",
|
|
309
|
+
extends: "ink",
|
|
310
|
+
defaults: {
|
|
311
|
+
intent: "ink-highlight",
|
|
312
|
+
color: "#ffcd45",
|
|
313
|
+
strokeWidth: 14,
|
|
314
|
+
blendMode: "multiply"
|
|
315
|
+
},
|
|
316
|
+
ink: { straighten: {
|
|
317
|
+
deviationThreshold: .15,
|
|
318
|
+
axisSnapDegrees: 15
|
|
319
|
+
} }
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
id: "free-text",
|
|
323
|
+
subtype: "free-text",
|
|
324
|
+
cursor: "crosshair",
|
|
325
|
+
enables: DRAW_TAGS,
|
|
326
|
+
defaults: {
|
|
327
|
+
color: HOUSE_RED,
|
|
328
|
+
strokeWidth: 2,
|
|
329
|
+
fontColor: "#ef4444"
|
|
330
|
+
},
|
|
331
|
+
upright: true,
|
|
332
|
+
clickCreate: {
|
|
333
|
+
width: 180,
|
|
334
|
+
height: 40,
|
|
335
|
+
anchor: "top-left"
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
id: "free-text-callout",
|
|
340
|
+
subtype: "free-text-callout",
|
|
341
|
+
cursor: "crosshair",
|
|
342
|
+
enables: DRAW_TAGS,
|
|
343
|
+
defaults: {
|
|
344
|
+
color: HOUSE_RED,
|
|
345
|
+
strokeWidth: 6,
|
|
346
|
+
lineEnding: "open-arrow"
|
|
347
|
+
},
|
|
348
|
+
upright: true
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
id: "highlight",
|
|
352
|
+
subtype: "highlight",
|
|
353
|
+
cursor: "default",
|
|
354
|
+
enables: MARKUP_TAGS,
|
|
355
|
+
defaults: {
|
|
356
|
+
color: "#ffe16a",
|
|
357
|
+
blendMode: "multiply"
|
|
358
|
+
},
|
|
359
|
+
selection: { kind: "markup" }
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
id: "redact",
|
|
363
|
+
subtype: "redact",
|
|
364
|
+
cursor: "crosshair",
|
|
365
|
+
enables: [
|
|
366
|
+
"text-select",
|
|
367
|
+
"annotation-draw",
|
|
368
|
+
"annotation-edit"
|
|
369
|
+
],
|
|
370
|
+
defaults: {
|
|
371
|
+
color: "#e44234",
|
|
372
|
+
interiorColor: "#000000",
|
|
373
|
+
fontSize: 14,
|
|
374
|
+
fontColor: "#ffffff",
|
|
375
|
+
opacity: 1
|
|
376
|
+
},
|
|
377
|
+
selection: { kind: "markup" }
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
id: "underline",
|
|
381
|
+
subtype: "underline",
|
|
382
|
+
cursor: "default",
|
|
383
|
+
enables: MARKUP_TAGS,
|
|
384
|
+
defaults: { color: "#ef4444" },
|
|
385
|
+
selection: { kind: "markup" }
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
id: "strikeout",
|
|
389
|
+
subtype: "strikeout",
|
|
390
|
+
cursor: "default",
|
|
391
|
+
enables: MARKUP_TAGS,
|
|
392
|
+
defaults: { color: "#ef4444" },
|
|
393
|
+
selection: { kind: "markup" }
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
id: "squiggly",
|
|
397
|
+
subtype: "squiggly",
|
|
398
|
+
cursor: "default",
|
|
399
|
+
enables: MARKUP_TAGS,
|
|
400
|
+
defaults: { color: "#ef4444" },
|
|
401
|
+
selection: { kind: "markup" }
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
id: "insert-text",
|
|
405
|
+
subtype: "caret",
|
|
406
|
+
fieldsKind: "caret",
|
|
407
|
+
preset: "caret",
|
|
408
|
+
cursor: "default",
|
|
409
|
+
enables: MARKUP_TAGS,
|
|
410
|
+
defaults: { color: "#ef4444" },
|
|
411
|
+
selection: {
|
|
412
|
+
kind: "text-edit",
|
|
413
|
+
operation: "insert"
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
id: "replace-text",
|
|
418
|
+
subtype: "strikeout",
|
|
419
|
+
fieldsKind: "strikeout",
|
|
420
|
+
cursor: "default",
|
|
421
|
+
enables: MARKUP_TAGS,
|
|
422
|
+
defaults: { color: "#ef4444" },
|
|
423
|
+
selection: {
|
|
424
|
+
kind: "text-edit",
|
|
425
|
+
operation: "replace"
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
id: ARMED_STAMP_TOOL_ID,
|
|
430
|
+
subtype: "stamp",
|
|
431
|
+
cursor: "copy",
|
|
432
|
+
enables: ["annotation-place", "annotation-edit"],
|
|
433
|
+
source: {
|
|
434
|
+
kind: "prompt",
|
|
435
|
+
accept: "image/png,image/jpeg,application/pdf"
|
|
436
|
+
},
|
|
437
|
+
upright: true,
|
|
438
|
+
ghost: true
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
id: "link",
|
|
442
|
+
subtype: "link",
|
|
443
|
+
cursor: "crosshair",
|
|
444
|
+
enables: DRAW_TAGS
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
id: "note",
|
|
448
|
+
subtype: "text",
|
|
449
|
+
cursor: "crosshair",
|
|
450
|
+
enables: ["annotation-place", "annotation-edit"],
|
|
451
|
+
defaults: {
|
|
452
|
+
icon: "comment",
|
|
453
|
+
color: "#facc15"
|
|
454
|
+
},
|
|
455
|
+
flags: {
|
|
456
|
+
noZoom: true,
|
|
457
|
+
noRotate: true
|
|
458
|
+
},
|
|
459
|
+
upright: true,
|
|
460
|
+
ghost: true
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
id: "attachment",
|
|
464
|
+
subtype: "file-attachment",
|
|
465
|
+
cursor: "crosshair",
|
|
466
|
+
enables: ["annotation-place", "annotation-edit"],
|
|
467
|
+
source: { kind: "prompt" },
|
|
468
|
+
defaults: {
|
|
469
|
+
icon: "paperclip",
|
|
470
|
+
color: "#facc15"
|
|
471
|
+
},
|
|
472
|
+
flags: {
|
|
473
|
+
noZoom: true,
|
|
474
|
+
noRotate: true
|
|
475
|
+
},
|
|
476
|
+
upright: true,
|
|
477
|
+
ghost: true
|
|
478
|
+
}
|
|
479
|
+
];
|
|
480
|
+
/** Merge two tools' defaults, `right` over `left`, each value whole. */
|
|
481
|
+
function mergeDefaults(left, right) {
|
|
482
|
+
return left && right ? {
|
|
483
|
+
...left,
|
|
484
|
+
...right
|
|
485
|
+
} : right ?? left;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* A tool from `definition`, starting from `base` when it has one: the base's
|
|
489
|
+
* kind, behavior and defaults, with the definition's own fields over them. The
|
|
490
|
+
* base's `meta` stays behind, since it says which button the base is.
|
|
491
|
+
*/
|
|
492
|
+
function toolFrom(definition, base) {
|
|
493
|
+
const subtype = definition.subtype ?? base?.subtype ?? definition.id;
|
|
494
|
+
return {
|
|
495
|
+
id: definition.id,
|
|
496
|
+
subtype,
|
|
497
|
+
preset: definition.preset ?? definition.id,
|
|
498
|
+
fieldsKind: definition.fieldsKind ?? base?.fieldsKind ?? subtype,
|
|
499
|
+
cursor: definition.cursor ?? base?.cursor ?? "crosshair",
|
|
500
|
+
enables: new Set(definition.enables ?? (base ? [...base.enables] : [])),
|
|
501
|
+
defaults: mergeDefaults(base?.defaults, definition.defaults),
|
|
502
|
+
flags: base?.flags || definition.flags ? {
|
|
503
|
+
...base?.flags,
|
|
504
|
+
...definition.flags
|
|
505
|
+
} : void 0,
|
|
506
|
+
source: definition.source ?? base?.source,
|
|
507
|
+
selection: definition.selection ?? base?.selection,
|
|
508
|
+
ink: base?.ink || definition.ink ? {
|
|
509
|
+
...base?.ink,
|
|
510
|
+
...definition.ink
|
|
511
|
+
} : void 0,
|
|
512
|
+
upright: definition.upright ?? base?.upright ?? false,
|
|
513
|
+
clickCreate: definition.clickCreate ?? base?.clickCreate ?? false,
|
|
514
|
+
ghost: resolveGhost(definition.ghost ?? base?.ghost ?? false),
|
|
515
|
+
afterCreate: base?.afterCreate || definition.afterCreate ? {
|
|
516
|
+
...base?.afterCreate,
|
|
517
|
+
...definition.afterCreate
|
|
518
|
+
} : void 0,
|
|
519
|
+
capture: CAPTURE_TOOLS.has(definition.id) || (base?.capture ?? false),
|
|
520
|
+
meta: definition.meta
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
/** `tool` with a change for its id merged over it: the same tool, `meta` included. */
|
|
524
|
+
function changeTool(tool, change) {
|
|
525
|
+
return {
|
|
526
|
+
...toolFrom({
|
|
527
|
+
...change,
|
|
528
|
+
preset: change.preset ?? tool.preset
|
|
529
|
+
}, tool),
|
|
530
|
+
meta: tool.meta || change.meta ? {
|
|
531
|
+
...tool.meta,
|
|
532
|
+
...change.meta
|
|
533
|
+
} : void 0
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function validateDefaults(tool) {
|
|
537
|
+
if (!tool.defaults) return;
|
|
538
|
+
const allowed = TOOL_DEFAULT_FIELDS[tool.subtype];
|
|
539
|
+
if (!allowed) return;
|
|
540
|
+
const keys = new Set(allowed);
|
|
541
|
+
for (const key of Object.keys(tool.defaults)) if (!keys.has(key)) throw new Error(`[annotation] tool '${tool.id}' does not support default '${key}' for '${tool.subtype}'`);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Apply one tool entry to `tools` and return the tool it leaves under its id.
|
|
545
|
+
* An entry with `extends` makes a tool from a copy of that tool as it is now,
|
|
546
|
+
* in place of any tool with its id; an entry whose id is taken changes that
|
|
547
|
+
* tool; any other entry adds one. A copy is a copy: a later change to the tool
|
|
548
|
+
* it came from doesn't reach it.
|
|
549
|
+
*/
|
|
550
|
+
function applyTool(tools, entry) {
|
|
551
|
+
let tool;
|
|
552
|
+
if (entry.extends) {
|
|
553
|
+
const base = tools.get(entry.extends);
|
|
554
|
+
if (!base) throw new Error(`[annotation] tool '${entry.id}' extends '${entry.extends}', which isn't defined before it`);
|
|
555
|
+
tool = toolFrom(entry, base);
|
|
556
|
+
} else {
|
|
557
|
+
const current = tools.get(entry.id);
|
|
558
|
+
tool = current ? changeTool(current, entry) : toolFrom(entry);
|
|
559
|
+
}
|
|
560
|
+
validateDefaults(tool);
|
|
561
|
+
tools.set(tool.id, tool);
|
|
562
|
+
return tool;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* The tool table: {@link DEFAULT_TOOLS}, then `entries`, each applied in order
|
|
566
|
+
* by {@link applyTool}. So a change to a built-in reaches only that built-in, and
|
|
567
|
+
* an entry's `extends` sees the tool as the entries before it left it.
|
|
568
|
+
*/
|
|
569
|
+
function buildToolRegistry(entries = []) {
|
|
570
|
+
const tools = /* @__PURE__ */ new Map();
|
|
571
|
+
for (const entry of [...DEFAULT_TOOLS, ...entries]) applyTool(tools, entry);
|
|
572
|
+
return tools;
|
|
573
|
+
}
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/contract.ts
|
|
576
|
+
/** What the annotation settings are when the app registers none. */
|
|
577
|
+
const ANNOTATION_DEFAULTS = {
|
|
578
|
+
tools: [],
|
|
579
|
+
afterCreate: {
|
|
580
|
+
select: true,
|
|
581
|
+
tool: "stay",
|
|
582
|
+
editText: true
|
|
583
|
+
},
|
|
584
|
+
chrome: {
|
|
585
|
+
accent: null,
|
|
586
|
+
outline: {
|
|
587
|
+
color: null,
|
|
588
|
+
style: "solid",
|
|
589
|
+
width: 1
|
|
590
|
+
},
|
|
591
|
+
handles: {
|
|
592
|
+
shape: "square",
|
|
593
|
+
size: 8,
|
|
594
|
+
hitSize: 24,
|
|
595
|
+
fill: "#ffffff",
|
|
596
|
+
stroke: null
|
|
597
|
+
},
|
|
598
|
+
rotationHandle: {
|
|
599
|
+
enabled: true,
|
|
600
|
+
size: 10,
|
|
601
|
+
hitSize: 24,
|
|
602
|
+
offset: 32,
|
|
603
|
+
stalk: true,
|
|
604
|
+
fill: null,
|
|
605
|
+
stroke: null
|
|
606
|
+
},
|
|
607
|
+
guides: {
|
|
608
|
+
enabled: true,
|
|
609
|
+
color: "#e91e63",
|
|
610
|
+
rotationColor: null,
|
|
611
|
+
style: "solid",
|
|
612
|
+
width: 1.5
|
|
613
|
+
},
|
|
614
|
+
marquee: {
|
|
615
|
+
fill: null,
|
|
616
|
+
stroke: null
|
|
617
|
+
},
|
|
618
|
+
textOutline: null,
|
|
619
|
+
readout: {
|
|
620
|
+
enabled: true,
|
|
621
|
+
background: "rgb(0 0 0 / 0.8)",
|
|
622
|
+
color: "#ffffff"
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
snap: {
|
|
626
|
+
alignment: true,
|
|
627
|
+
alignmentThresholdPx: 6,
|
|
628
|
+
rotation: true,
|
|
629
|
+
rotationAngles: [
|
|
630
|
+
0,
|
|
631
|
+
90,
|
|
632
|
+
180,
|
|
633
|
+
270
|
|
634
|
+
],
|
|
635
|
+
rotationThresholdDeg: 4
|
|
636
|
+
},
|
|
637
|
+
editable: true
|
|
638
|
+
};
|
|
639
|
+
//#endregion
|
|
640
|
+
export { applyTool as a, annotationState as c, DEFAULT_TOOLS as i, AnnotationToken as l, AnnotationTransfer as n, buildToolRegistry as o, ARMED_STAMP_TOOL_ID as r, toolTouchOf as s, ANNOTATION_DEFAULTS as t };
|
|
641
|
+
|
|
642
|
+
//# sourceMappingURL=contract-nPw63clg.js.map
|