@arbidocs/react 0.4.55 → 0.4.57

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.
Files changed (49) hide show
  1. package/dist/PdfViewer-bQH9yxFg.d.cts +55 -0
  2. package/dist/PdfViewer-bQH9yxFg.d.ts +55 -0
  3. package/dist/annotations/freeze/index.cjs +748 -0
  4. package/dist/annotations/freeze/index.cjs.map +1 -0
  5. package/dist/annotations/freeze/index.d.cts +199 -0
  6. package/dist/annotations/freeze/index.d.ts +199 -0
  7. package/dist/annotations/freeze/index.js +738 -0
  8. package/dist/annotations/freeze/index.js.map +1 -0
  9. package/dist/annotations/index.cjs +1756 -0
  10. package/dist/annotations/index.cjs.map +1 -0
  11. package/dist/annotations/index.d.cts +291 -0
  12. package/dist/annotations/index.d.ts +291 -0
  13. package/dist/annotations/index.js +1690 -0
  14. package/dist/annotations/index.js.map +1 -0
  15. package/dist/artifacts/index.cjs +16 -16
  16. package/dist/artifacts/index.js +5 -5
  17. package/dist/chunk-BGDE4DP5.cjs +192 -0
  18. package/dist/chunk-BGDE4DP5.cjs.map +1 -0
  19. package/dist/{chunk-MS7VH2BY.js → chunk-CVN7MAGQ.js} +6 -146
  20. package/dist/chunk-CVN7MAGQ.js.map +1 -0
  21. package/dist/chunk-JWXIRUWN.js +183 -0
  22. package/dist/chunk-JWXIRUWN.js.map +1 -0
  23. package/dist/chunk-QS3Q5542.js +151 -0
  24. package/dist/chunk-QS3Q5542.js.map +1 -0
  25. package/dist/{chunk-RI3BZQWD.cjs → chunk-R6V6YHPD.cjs} +3 -3
  26. package/dist/{chunk-RI3BZQWD.cjs.map → chunk-R6V6YHPD.cjs.map} +1 -1
  27. package/dist/{chunk-LOESXNVT.cjs → chunk-X3F5ABY2.cjs} +5 -158
  28. package/dist/chunk-X3F5ABY2.cjs.map +1 -0
  29. package/dist/chunk-XDCRWZF2.cjs +185 -0
  30. package/dist/chunk-XDCRWZF2.cjs.map +1 -0
  31. package/dist/{chunk-GT6KN3DV.js → chunk-XKGTZ3H6.js} +3 -3
  32. package/dist/{chunk-GT6KN3DV.js.map → chunk-XKGTZ3H6.js.map} +1 -1
  33. package/dist/index.cjs +475 -474
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.js +11 -9
  36. package/dist/index.js.map +1 -1
  37. package/dist/model-DzQxhMMz.d.cts +102 -0
  38. package/dist/model-DzQxhMMz.d.ts +102 -0
  39. package/dist/ui/index.cjs +186 -185
  40. package/dist/ui/index.js +3 -2
  41. package/dist/viewers/index.cjs +61 -52
  42. package/dist/viewers/index.cjs.map +1 -1
  43. package/dist/viewers/index.d.cts +3 -43
  44. package/dist/viewers/index.d.ts +3 -43
  45. package/dist/viewers/index.js +61 -52
  46. package/dist/viewers/index.js.map +1 -1
  47. package/package.json +31 -9
  48. package/dist/chunk-LOESXNVT.cjs.map +0 -1
  49. package/dist/chunk-MS7VH2BY.js.map +0 -1
@@ -0,0 +1,1690 @@
1
+ import { Button, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '../chunk-QS3Q5542.js';
2
+ import { cn } from '../chunk-SN5YV6FF.js';
3
+ import { parseAnnotation, parseLayer, emptyLayer, clampRect, isEffectiveRedaction } from '../chunk-JWXIRUWN.js';
4
+ export { AnnotationLayerError, LAYER_SCHEMA_VERSION, annotationRects, clampRect, emptyLayer, isEffectiveRedaction, parseAnnotation, parseLayer } from '../chunk-JWXIRUWN.js';
5
+ import { useState, useRef, useCallback, useEffect, useMemo, useLayoutEffect } from 'react';
6
+ import { MessageSquare, Check, X, RotateCcw, Trash2, Send, Undo2, Redo2, Snowflake, MousePointer2, Highlighter, Square, Stamp, ScanText, EyeOff } from 'lucide-react';
7
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
8
+
9
+ // src/annotations/state.ts
10
+ var HISTORY_LIMIT = 200;
11
+ function createHistory(layer) {
12
+ return { present: layer, past: [], future: [] };
13
+ }
14
+ function reduceLayer(layer, action) {
15
+ switch (action.type) {
16
+ case "replaceAll":
17
+ return action.layer;
18
+ case "add": {
19
+ const annotation = parseAnnotation(action.annotation);
20
+ if (layer.annotations.some((a) => a.id === annotation.id)) {
21
+ throw new Error(`annotation ${annotation.id} already exists`);
22
+ }
23
+ return {
24
+ ...layer,
25
+ annotations: [...layer.annotations, annotation],
26
+ updatedAt: annotation.updatedAt
27
+ };
28
+ }
29
+ case "addMany": {
30
+ let next = layer;
31
+ for (const annotation of action.annotations)
32
+ next = reduceLayer(next, { type: "add", annotation });
33
+ return next;
34
+ }
35
+ case "update": {
36
+ const found = layer.annotations.find((a) => a.id === action.id);
37
+ if (!found) return layer;
38
+ const next = parseAnnotation({
39
+ ...found,
40
+ ...action.patch,
41
+ id: found.id,
42
+ kind: found.kind,
43
+ page: found.page,
44
+ createdAt: found.createdAt,
45
+ updatedAt: action.now
46
+ });
47
+ return replace(layer, next, action.now);
48
+ }
49
+ case "remove": {
50
+ if (!layer.annotations.some((a) => a.id === action.id)) return layer;
51
+ return {
52
+ ...layer,
53
+ annotations: layer.annotations.filter((a) => a.id !== action.id),
54
+ updatedAt: action.now
55
+ };
56
+ }
57
+ case "setRedactionStatus": {
58
+ const ids = new Set(action.ids);
59
+ let changed = false;
60
+ const annotations = layer.annotations.map((a) => {
61
+ if (a.kind !== "redaction" || !ids.has(a.id) || a.status === action.status) return a;
62
+ changed = true;
63
+ return { ...a, status: action.status, updatedAt: action.now };
64
+ });
65
+ return changed ? { ...layer, annotations, updatedAt: action.now } : layer;
66
+ }
67
+ case "reply": {
68
+ const found = layer.annotations.find((a) => a.id === action.id);
69
+ if (!found || found.kind !== "comment") return layer;
70
+ const next = parseAnnotation({
71
+ ...found,
72
+ replies: [...found.replies, action.reply],
73
+ updatedAt: action.now
74
+ });
75
+ return replace(layer, next, action.now);
76
+ }
77
+ case "resolve": {
78
+ const found = layer.annotations.find((a) => a.id === action.id);
79
+ if (!found || found.kind !== "comment" || found.resolved === action.resolved) return layer;
80
+ return replace(
81
+ layer,
82
+ { ...found, resolved: action.resolved, updatedAt: action.now },
83
+ action.now
84
+ );
85
+ }
86
+ }
87
+ }
88
+ function replace(layer, next, now) {
89
+ return {
90
+ ...layer,
91
+ annotations: layer.annotations.map((a) => a.id === next.id ? next : a),
92
+ updatedAt: now
93
+ };
94
+ }
95
+ function applyAction(history, action) {
96
+ const present = reduceLayer(history.present, action);
97
+ if (present === history.present) return history;
98
+ const past = [...history.past, history.present];
99
+ return {
100
+ present,
101
+ past: past.length > HISTORY_LIMIT ? past.slice(past.length - HISTORY_LIMIT) : past,
102
+ future: []
103
+ };
104
+ }
105
+ function undo(history) {
106
+ const previous = history.past[history.past.length - 1];
107
+ if (!previous) return history;
108
+ return {
109
+ present: previous,
110
+ past: history.past.slice(0, -1),
111
+ future: [history.present, ...history.future]
112
+ };
113
+ }
114
+ function redo(history) {
115
+ const [next, ...rest] = history.future;
116
+ if (!next) return history;
117
+ return { present: next, past: [...history.past, history.present], future: rest };
118
+ }
119
+ var canUndo = (h) => h.past.length > 0;
120
+ var canRedo = (h) => h.future.length > 0;
121
+ function annotationsOnPage(layer, page) {
122
+ return layer.annotations.filter((a) => a.page === page);
123
+ }
124
+ function pendingRedactions(layer) {
125
+ return layer.annotations.filter((a) => a.kind === "redaction" && a.status === "pending");
126
+ }
127
+
128
+ // src/annotations/store.ts
129
+ function createMemoryStore(now = () => (/* @__PURE__ */ new Date()).toISOString()) {
130
+ const layers = /* @__PURE__ */ new Map();
131
+ return {
132
+ async load(documentId) {
133
+ const raw = layers.get(documentId);
134
+ return raw ? parseLayer(JSON.parse(raw)) : emptyLayer(documentId, now());
135
+ },
136
+ async save(layer) {
137
+ layers.set(layer.documentId, JSON.stringify(parseLayer(layer)));
138
+ }
139
+ };
140
+ }
141
+ var STORAGE_PREFIX = "arbi:annotations:";
142
+ function createLocalStorageStore(storage = safeLocalStorage(), now = () => (/* @__PURE__ */ new Date()).toISOString()) {
143
+ return {
144
+ async load(documentId) {
145
+ try {
146
+ const raw = storage?.getItem(STORAGE_PREFIX + documentId);
147
+ if (raw) return parseLayer(JSON.parse(raw));
148
+ } catch {
149
+ }
150
+ return emptyLayer(documentId, now());
151
+ },
152
+ async save(layer) {
153
+ if (!storage) throw new Error("storage is not available");
154
+ storage.setItem(STORAGE_PREFIX + layer.documentId, JSON.stringify(parseLayer(layer)));
155
+ }
156
+ };
157
+ }
158
+ function safeLocalStorage() {
159
+ try {
160
+ return typeof localStorage === "undefined" ? void 0 : localStorage;
161
+ } catch {
162
+ return void 0;
163
+ }
164
+ }
165
+
166
+ // src/annotations/geometry.ts
167
+ var MIN_MARK_FRACTION = 4e-3;
168
+ function toNorm(r, page) {
169
+ if (!(page.width > 0) || !(page.height > 0)) throw new RangeError("page size must be positive");
170
+ const x1 = Math.min(r.x, r.x + r.width);
171
+ const y1 = Math.min(r.y, r.y + r.height);
172
+ const x2 = Math.max(r.x, r.x + r.width);
173
+ const y2 = Math.max(r.y, r.y + r.height);
174
+ const cx1 = Math.min(Math.max(x1, 0), page.width);
175
+ const cy1 = Math.min(Math.max(y1, 0), page.height);
176
+ const cx2 = Math.min(Math.max(x2, 0), page.width);
177
+ const cy2 = Math.min(Math.max(y2, 0), page.height);
178
+ return clampRect({
179
+ x: cx1 / page.width,
180
+ y: cy1 / page.height,
181
+ w: (cx2 - cx1) / page.width,
182
+ h: (cy2 - cy1) / page.height
183
+ });
184
+ }
185
+ function toPixels(r, page) {
186
+ return {
187
+ x: r.x * page.width,
188
+ y: r.y * page.height,
189
+ width: r.w * page.width,
190
+ height: r.h * page.height
191
+ };
192
+ }
193
+ function dragToNorm(a, b, page) {
194
+ return toNorm({ x: a.x, y: a.y, width: b.x - a.x, height: b.y - a.y }, page);
195
+ }
196
+ function isTooSmall(r) {
197
+ return r.w < MIN_MARK_FRACTION || r.h < MIN_MARK_FRACTION;
198
+ }
199
+ function containsPoint(r, x, y) {
200
+ return x >= r.x && x <= r.x + r.w && y >= r.y && y <= r.y + r.h;
201
+ }
202
+ var EPS = 1e-9;
203
+ function intersects(a, b) {
204
+ return a.x + EPS < b.x + b.w && b.x + EPS < a.x + a.w && a.y + EPS < b.y + b.h && b.y + EPS < a.y + a.h;
205
+ }
206
+ function mergeLineRects(input, gap = 2) {
207
+ const rects = input.filter((r) => r.width > 0 && r.height > 0).map((r) => ({ ...r })).sort((a, b) => a.y - b.y || a.x - b.x);
208
+ const lines = [];
209
+ for (const r of rects) {
210
+ const mid = r.y + r.height / 2;
211
+ const line = lines.find((l) => {
212
+ const ref = l[0];
213
+ return mid >= ref.y && mid <= ref.y + ref.height;
214
+ });
215
+ if (line) line.push(r);
216
+ else lines.push([r]);
217
+ }
218
+ const out = [];
219
+ for (const line of lines) {
220
+ line.sort((a, b) => a.x - b.x);
221
+ let cur = { ...line[0] };
222
+ for (const r of line.slice(1)) {
223
+ if (r.x <= cur.x + cur.width + gap) {
224
+ const right = Math.max(cur.x + cur.width, r.x + r.width);
225
+ const top = Math.min(cur.y, r.y);
226
+ const bottom = Math.max(cur.y + cur.height, r.y + r.height);
227
+ cur = { x: cur.x, y: top, width: right - cur.x, height: bottom - top };
228
+ } else {
229
+ out.push(cur);
230
+ cur = { ...r };
231
+ }
232
+ }
233
+ out.push(cur);
234
+ }
235
+ return out.sort((a, b) => a.y - b.y || a.x - b.x);
236
+ }
237
+
238
+ // src/annotations/controller.ts
239
+ var DRAW_TOOLS = ["box", "comment", "stamp", "redact-area"];
240
+ var TEXT_TOOLS = ["highlight", "redact-text"];
241
+ var DEFAULT_SETTINGS = {
242
+ colors: { highlight: "#ffe066", box: "#e03131", stamp: "#c92a2a" },
243
+ stampLabel: "CONFIDENTIAL",
244
+ redactionReason: "Privileged",
245
+ strokeWidth: 2
246
+ };
247
+ var HIGHLIGHT_COLORS = ["#ffe066", "#8ce99a", "#74c0fc", "#ffa8a8", "#eebefa"];
248
+ var MARK_COLORS = ["#e03131", "#1c7ed6", "#2f9e44", "#f08c00", "#000000"];
249
+ var STAMP_PRESETS = ["CONFIDENTIAL", "DRAFT", "APPROVED", "FILED", "PRIVILEGED", "COPY"];
250
+ var REDACTION_REASONS = [
251
+ "Privileged",
252
+ "Confidential",
253
+ "Personal data",
254
+ "Commercial",
255
+ "Irrelevant"
256
+ ];
257
+ var AUTOSAVE_MS = 600;
258
+ var defaultNow = () => (/* @__PURE__ */ new Date()).toISOString();
259
+ var defaultId = () => globalThis.crypto.randomUUID();
260
+ function useAnnotationLayer({
261
+ documentId,
262
+ store,
263
+ author,
264
+ autosaveMs = AUTOSAVE_MS,
265
+ now = defaultNow,
266
+ makeId = defaultId
267
+ }) {
268
+ const [history, setHistory] = useState(
269
+ () => createHistory(emptyLayer(documentId, now()))
270
+ );
271
+ const [savedLayer, setSavedLayer] = useState(null);
272
+ const [status, setStatus] = useState("loading");
273
+ const [error, setError] = useState(null);
274
+ const [saving, setSaving] = useState(false);
275
+ const [tool, setToolState] = useState("select");
276
+ const [settings, setSettingsState] = useState(DEFAULT_SETTINGS);
277
+ const [selectedId, setSelectedId] = useState(null);
278
+ const historyRef = useRef(history);
279
+ const savedRef = useRef(null);
280
+ const timerRef = useRef(void 0);
281
+ const docRef = useRef(documentId);
282
+ const storeRef = useRef(store);
283
+ storeRef.current = store;
284
+ const nowRef = useRef(now);
285
+ nowRef.current = now;
286
+ const idRef = useRef(makeId);
287
+ idRef.current = makeId;
288
+ const commit = useCallback((next) => {
289
+ historyRef.current = next;
290
+ setHistory(next);
291
+ }, []);
292
+ useEffect(() => {
293
+ docRef.current = documentId;
294
+ let cancelled = false;
295
+ setStatus("loading");
296
+ setError(null);
297
+ setSelectedId(null);
298
+ setSavedLayer(null);
299
+ savedRef.current = null;
300
+ commit(createHistory(emptyLayer(documentId, nowRef.current())));
301
+ storeRef.current.load(documentId).then((layer) => {
302
+ if (cancelled) return;
303
+ savedRef.current = layer;
304
+ setSavedLayer(layer);
305
+ commit(createHistory(layer));
306
+ setStatus("ready");
307
+ }).catch((e) => {
308
+ if (cancelled) return;
309
+ setError(e instanceof Error ? e.message : "The annotations could not be loaded");
310
+ setStatus("error");
311
+ });
312
+ return () => {
313
+ cancelled = true;
314
+ clearTimeout(timerRef.current);
315
+ const layer = historyRef.current.present;
316
+ if (savedRef.current !== null && layer !== savedRef.current && layer.documentId === documentId) {
317
+ storeRef.current.save(layer).catch((e) => console.error("Annotations could not be saved", e));
318
+ }
319
+ };
320
+ }, [documentId, commit]);
321
+ const save = useCallback(async () => {
322
+ clearTimeout(timerRef.current);
323
+ const layer = historyRef.current.present;
324
+ if (layer === savedRef.current) return;
325
+ setSaving(true);
326
+ try {
327
+ await storeRef.current.save(layer);
328
+ if (layer.documentId === docRef.current) {
329
+ savedRef.current = layer;
330
+ setSavedLayer(layer);
331
+ setError(null);
332
+ }
333
+ } catch (e) {
334
+ setError(e instanceof Error ? e.message : "The annotations could not be saved");
335
+ } finally {
336
+ setSaving(false);
337
+ }
338
+ }, []);
339
+ const present = history.present;
340
+ const dirty = status === "ready" && present !== savedLayer;
341
+ useEffect(() => {
342
+ if (!dirty) return;
343
+ timerRef.current = setTimeout(() => void save(), autosaveMs);
344
+ return () => clearTimeout(timerRef.current);
345
+ }, [dirty, present, autosaveMs, save]);
346
+ useEffect(() => {
347
+ const flush = () => void save();
348
+ const onVisibility = () => {
349
+ if (document.visibilityState === "hidden") flush();
350
+ };
351
+ window.addEventListener("pagehide", flush);
352
+ document.addEventListener("visibilitychange", onVisibility);
353
+ return () => {
354
+ window.removeEventListener("pagehide", flush);
355
+ document.removeEventListener("visibilitychange", onVisibility);
356
+ };
357
+ }, [save]);
358
+ const dispatch = useCallback(
359
+ (action) => {
360
+ try {
361
+ commit(applyAction(historyRef.current, action));
362
+ setError(null);
363
+ return true;
364
+ } catch (e) {
365
+ setError(e instanceof Error ? e.message : "The change was rejected");
366
+ return false;
367
+ }
368
+ },
369
+ [commit]
370
+ );
371
+ const stamp = useCallback(
372
+ (mark) => {
373
+ const t = nowRef.current();
374
+ return { ...mark, id: idRef.current(), author, createdAt: t, updatedAt: t };
375
+ },
376
+ [author]
377
+ );
378
+ const controller = useMemo(() => {
379
+ const exists = (id) => id !== null && present.annotations.some((a) => a.id === id) ? id : null;
380
+ return {
381
+ layer: present,
382
+ status,
383
+ error,
384
+ saving,
385
+ dirty,
386
+ author,
387
+ tool,
388
+ setTool: (next) => {
389
+ setToolState(next);
390
+ if (next !== "select") setSelectedId(null);
391
+ },
392
+ settings,
393
+ setSettings: (patch) => setSettingsState((s) => ({ ...s, ...patch, colors: { ...s.colors, ...patch.colors } })),
394
+ selectedId: exists(selectedId),
395
+ select: setSelectedId,
396
+ add: (mark) => {
397
+ const annotation = stamp(mark);
398
+ return dispatch({ type: "add", annotation }) ? annotation.id : null;
399
+ },
400
+ addMany: (marks) => {
401
+ const annotations = marks.map(stamp);
402
+ return dispatch({ type: "addMany", annotations }) ? annotations.map((a) => a.id) : [];
403
+ },
404
+ update: (id, patch) => void dispatch({ type: "update", id, patch, now: nowRef.current() }),
405
+ remove: (id) => void dispatch({ type: "remove", id, now: nowRef.current() }),
406
+ setRedactionStatus: (ids, next) => void dispatch({ type: "setRedactionStatus", ids, status: next, now: nowRef.current() }),
407
+ reply: (id, body) => {
408
+ const t = nowRef.current();
409
+ void dispatch({
410
+ type: "reply",
411
+ id,
412
+ reply: { id: idRef.current(), author, createdAt: t, body },
413
+ now: t
414
+ });
415
+ },
416
+ resolve: (id, resolved) => void dispatch({ type: "resolve", id, resolved, now: nowRef.current() }),
417
+ undo: () => commit(undo(historyRef.current)),
418
+ redo: () => commit(redo(historyRef.current)),
419
+ canUndo: canUndo(history),
420
+ canRedo: canRedo(history),
421
+ flush: save
422
+ };
423
+ }, [
424
+ present,
425
+ history,
426
+ status,
427
+ error,
428
+ saving,
429
+ dirty,
430
+ author,
431
+ tool,
432
+ settings,
433
+ selectedId,
434
+ stamp,
435
+ dispatch,
436
+ commit,
437
+ save
438
+ ]);
439
+ return controller;
440
+ }
441
+
442
+ // src/annotations/selection-marks.ts
443
+ var MIN_RECT_PX = 1;
444
+ function selectionToPageMarks(pages) {
445
+ const out = [];
446
+ for (const p of pages) {
447
+ if (!(p.box.width > 0) || !(p.box.height > 0)) continue;
448
+ const local = p.rects.filter((r) => r.width >= MIN_RECT_PX && r.height >= MIN_RECT_PX).map((r) => ({ x: r.x - p.box.x, y: r.y - p.box.y, width: r.width, height: r.height })).filter(
449
+ (r) => r.x + r.width > 0 && r.y + r.height > 0 && r.x < p.box.width && r.y < p.box.height
450
+ );
451
+ const lines = mergeLineRects(local);
452
+ if (lines.length === 0) continue;
453
+ out.push({
454
+ page: p.page,
455
+ rects: lines.map((r) => toNorm(r, { width: p.box.width, height: p.box.height })),
456
+ text: p.text.replace(/\s+/g, " ").trim()
457
+ });
458
+ }
459
+ return out;
460
+ }
461
+ var PAGE_ATTRIBUTE = "data-annotation-page";
462
+ var toPixelRect = (r) => ({
463
+ x: r.left,
464
+ y: r.top,
465
+ width: r.width,
466
+ height: r.height
467
+ });
468
+ function clipRange(range, container) {
469
+ if (!range.intersectsNode(container)) return null;
470
+ const bounds = document.createRange();
471
+ bounds.selectNodeContents(container);
472
+ const clipped = range.cloneRange();
473
+ if (clipped.compareBoundaryPoints(Range.START_TO_START, bounds) < 0) {
474
+ clipped.setStart(bounds.startContainer, bounds.startOffset);
475
+ }
476
+ if (clipped.compareBoundaryPoints(Range.END_TO_END, bounds) > 0) {
477
+ clipped.setEnd(bounds.endContainer, bounds.endOffset);
478
+ }
479
+ return clipped;
480
+ }
481
+ function readSelection(selection, root = document) {
482
+ if (selection.rangeCount === 0 || selection.isCollapsed) return [];
483
+ const range = selection.getRangeAt(0);
484
+ const pages = [];
485
+ root.querySelectorAll(`[${PAGE_ATTRIBUTE}]`).forEach((overlay) => {
486
+ const page = Number(overlay.getAttribute(PAGE_ATTRIBUTE));
487
+ const container = overlay.parentElement;
488
+ if (!container || !Number.isInteger(page)) return;
489
+ const clipped = clipRange(range, container);
490
+ if (!clipped) return;
491
+ pages.push({
492
+ page,
493
+ box: toPixelRect(overlay.getBoundingClientRect()),
494
+ rects: Array.from(clipped.getClientRects(), toPixelRect),
495
+ text: clipped.toString()
496
+ });
497
+ });
498
+ return pages;
499
+ }
500
+
501
+ // src/annotations/useTextSelectionMarks.ts
502
+ var PAGE_SELECTOR = "[data-page-number]";
503
+ var TOUCH_SETTLE_MS = 700;
504
+ var MOUSE_SETTLE_MS = 60;
505
+ var STABLE_CHECKS = 2;
506
+ var MAX_SETTLE_ROUNDS = 10;
507
+ function useTextSelectionMarks(controller) {
508
+ const latest = useRef(controller);
509
+ latest.current = controller;
510
+ useEffect(() => {
511
+ let startedOnPage = false;
512
+ let touchSelecting = false;
513
+ let settleTimer;
514
+ const settleTimers = /* @__PURE__ */ new Set();
515
+ const markSelection = () => {
516
+ const c = latest.current;
517
+ const selection = window.getSelection();
518
+ if (!selection || !TEXT_TOOLS.includes(c.tool)) return false;
519
+ const pages = selectionToPageMarks(readSelection(selection));
520
+ if (pages.length === 0) return false;
521
+ const marks = pages.map(
522
+ (p) => c.tool === "highlight" ? {
523
+ kind: "highlight",
524
+ page: p.page,
525
+ rects: p.rects,
526
+ color: c.settings.colors.highlight,
527
+ text: p.text
528
+ } : {
529
+ kind: "redaction",
530
+ page: p.page,
531
+ rects: p.rects,
532
+ reason: c.settings.redactionReason,
533
+ text: p.text,
534
+ status: "pending"
535
+ }
536
+ );
537
+ if (c.addMany(marks).length === 0) return false;
538
+ selection.removeAllRanges();
539
+ return true;
540
+ };
541
+ const onDown = (e) => {
542
+ startedOnPage = e.target instanceof Element && e.target.closest(PAGE_SELECTOR) !== null;
543
+ touchSelecting = startedOnPage && e.pointerType === "touch";
544
+ };
545
+ const onUp = () => {
546
+ if (!startedOnPage || !TEXT_TOOLS.includes(latest.current.tool)) return;
547
+ startedOnPage = false;
548
+ let last = window.getSelection()?.toString() ?? "";
549
+ let stable = 0;
550
+ let rounds = 0;
551
+ const check = () => {
552
+ const now = window.getSelection()?.toString() ?? "";
553
+ if (now === last) stable++;
554
+ else {
555
+ last = now;
556
+ stable = 0;
557
+ }
558
+ if (stable >= STABLE_CHECKS || ++rounds >= MAX_SETTLE_ROUNDS) {
559
+ if (markSelection()) touchSelecting = false;
560
+ return;
561
+ }
562
+ settleTimers.add(setTimeout(check, MOUSE_SETTLE_MS));
563
+ };
564
+ settleTimers.add(setTimeout(check, MOUSE_SETTLE_MS));
565
+ };
566
+ const onSelectionChange = () => {
567
+ if (!touchSelecting || !TEXT_TOOLS.includes(latest.current.tool)) return;
568
+ clearTimeout(settleTimer);
569
+ settleTimer = setTimeout(() => {
570
+ if (markSelection()) touchSelecting = false;
571
+ }, TOUCH_SETTLE_MS);
572
+ };
573
+ document.addEventListener("pointerdown", onDown, true);
574
+ document.addEventListener("pointerup", onUp, true);
575
+ document.addEventListener("selectionchange", onSelectionChange);
576
+ return () => {
577
+ clearTimeout(settleTimer);
578
+ settleTimers.forEach(clearTimeout);
579
+ document.removeEventListener("pointerdown", onDown, true);
580
+ document.removeEventListener("pointerup", onUp, true);
581
+ document.removeEventListener("selectionchange", onSelectionChange);
582
+ };
583
+ }, []);
584
+ }
585
+
586
+ // src/annotations/overlay-geometry.ts
587
+ var MIN_MARK = 0.01;
588
+ function singleRect(a) {
589
+ if (a.kind === "box" || a.kind === "stamp" || a.kind === "comment") return a.rect;
590
+ if (a.kind === "redaction" && a.rects.length === 1) return a.rects[0];
591
+ return null;
592
+ }
593
+ var patchForRect = (a, rect) => a.kind === "redaction" ? { rects: [rect] } : { rect };
594
+ function dragRect(origin, mode, dx, dy) {
595
+ if (mode === "move") {
596
+ return {
597
+ ...origin,
598
+ x: Math.min(Math.max(origin.x + dx, 0), 1 - origin.w),
599
+ y: Math.min(Math.max(origin.y + dy, 0), 1 - origin.h)
600
+ };
601
+ }
602
+ let left = origin.x;
603
+ let right = origin.x + origin.w;
604
+ let top = origin.y;
605
+ let bottom = origin.y + origin.h;
606
+ if (mode.includes("w")) left += dx;
607
+ else right += dx;
608
+ if (mode.includes("n")) top += dy;
609
+ else bottom += dy;
610
+ const x1 = Math.min(Math.max(Math.min(left, right), 0), 1);
611
+ const x2 = Math.min(Math.max(Math.max(left, right), 0), 1);
612
+ const y1 = Math.min(Math.max(Math.min(top, bottom), 0), 1);
613
+ const y2 = Math.min(Math.max(Math.max(top, bottom), 0), 1);
614
+ return clampRect({
615
+ x: x1,
616
+ y: y1,
617
+ w: Math.max(x2 - x1, MIN_MARK),
618
+ h: Math.max(y2 - y1, MIN_MARK)
619
+ });
620
+ }
621
+ var FALLBACK_PAGE_WIDTH_PT = 612;
622
+ var COMMENT_ICON_PX = 24;
623
+ var DEFAULT_STAMP = { w: 0.32, h: 0.06 };
624
+ var MOVE_THRESHOLD_PX = 3;
625
+ function useElementSize(ref) {
626
+ const [size, setSize] = useState({ width: 0, height: 0 });
627
+ useLayoutEffect(() => {
628
+ const el = ref.current;
629
+ if (!el) return;
630
+ const measure = () => {
631
+ const r = el.getBoundingClientRect();
632
+ setSize(
633
+ (prev) => prev.width === r.width && prev.height === r.height ? prev : { width: r.width, height: r.height }
634
+ );
635
+ };
636
+ measure();
637
+ const observer = new ResizeObserver(measure);
638
+ observer.observe(el);
639
+ return () => observer.disconnect();
640
+ }, [ref]);
641
+ return size;
642
+ }
643
+ function useHasTextLayer(ref) {
644
+ const [hasText, setHasText] = useState(false);
645
+ useLayoutEffect(() => {
646
+ const container = ref.current?.parentElement;
647
+ if (!container) return;
648
+ const check = () => setHasText(container.querySelector(".textLayer span") !== null);
649
+ check();
650
+ const observer = new MutationObserver(check);
651
+ observer.observe(container, { childList: true, subtree: true });
652
+ return () => observer.disconnect();
653
+ }, [ref]);
654
+ return hasText;
655
+ }
656
+ var pct = (n) => `${n * 100}%`;
657
+ var rectStyle = (r) => ({
658
+ left: pct(r.x),
659
+ top: pct(r.y),
660
+ width: pct(r.w),
661
+ height: pct(r.h)
662
+ });
663
+ function AnnotationPageOverlay({
664
+ controller,
665
+ pageNumber,
666
+ pageWidthPt
667
+ }) {
668
+ const rootRef = useRef(null);
669
+ const size = useElementSize(rootRef);
670
+ const pxPerPt = size.width / (pageWidthPt ?? FALLBACK_PAGE_WIDTH_PT);
671
+ const { tool, selectedId, settings } = controller;
672
+ const [draft, setDraft] = useState(null);
673
+ const [drag, setDrag] = useState(null);
674
+ const [openComment, setOpenComment] = useState(null);
675
+ const marks = controller.layer.annotations.filter((a) => a.page === pageNumber);
676
+ const hasText = useHasTextLayer(rootRef);
677
+ const drawing = DRAW_TOOLS.includes(tool) || TEXT_TOOLS.includes(tool) && !hasText;
678
+ useEffect(() => {
679
+ if (openComment && selectedId !== openComment) setOpenComment(null);
680
+ }, [selectedId, openComment]);
681
+ const local = useCallback((e) => {
682
+ const r = rootRef.current.getBoundingClientRect();
683
+ return { x: e.clientX - r.left, y: e.clientY - r.top };
684
+ }, []);
685
+ const pageSize = () => {
686
+ const r = rootRef.current.getBoundingClientRect();
687
+ return { width: r.width, height: r.height };
688
+ };
689
+ const finishDraft = useCallback(
690
+ (a, b) => {
691
+ const page = pageSize();
692
+ const rect = dragToNorm(a, b, page);
693
+ if (tool === "box") {
694
+ if (isTooSmall(rect)) return;
695
+ controller.add({
696
+ kind: "box",
697
+ page: pageNumber,
698
+ rect,
699
+ color: settings.colors.box,
700
+ strokeWidth: settings.strokeWidth
701
+ });
702
+ } else if (tool === "highlight") {
703
+ if (isTooSmall(rect)) return;
704
+ controller.add({
705
+ kind: "highlight",
706
+ page: pageNumber,
707
+ rects: [rect],
708
+ color: settings.colors.highlight
709
+ });
710
+ } else if (tool === "redact-area" || tool === "redact-text") {
711
+ if (isTooSmall(rect)) return;
712
+ controller.add({
713
+ kind: "redaction",
714
+ page: pageNumber,
715
+ rects: [rect],
716
+ reason: settings.redactionReason,
717
+ status: "pending"
718
+ });
719
+ } else if (tool === "stamp") {
720
+ const placed = isTooSmall(rect) ? clampRect({
721
+ x: a.x / page.width - DEFAULT_STAMP.w / 2,
722
+ y: a.y / page.height - DEFAULT_STAMP.h / 2,
723
+ ...DEFAULT_STAMP
724
+ }) : rect;
725
+ controller.add({
726
+ kind: "stamp",
727
+ page: pageNumber,
728
+ rect: placed,
729
+ label: settings.stampLabel,
730
+ color: settings.colors.stamp
731
+ });
732
+ } else if (tool === "comment") {
733
+ const anchor = clampRect({
734
+ x: a.x / page.width,
735
+ y: a.y / page.height,
736
+ w: COMMENT_ICON_PX / page.width,
737
+ h: COMMENT_ICON_PX / page.height
738
+ });
739
+ const id = controller.add({
740
+ kind: "comment",
741
+ page: pageNumber,
742
+ rect: anchor,
743
+ body: "",
744
+ replies: [],
745
+ resolved: false
746
+ });
747
+ if (id) {
748
+ controller.setTool("select");
749
+ controller.select(id);
750
+ setOpenComment(id);
751
+ }
752
+ }
753
+ },
754
+ [controller, tool, settings, pageNumber]
755
+ );
756
+ const onRootPointerDown = (e) => {
757
+ if (!drawing || e.button !== 0 || e.target !== e.currentTarget) return;
758
+ e.currentTarget.setPointerCapture(e.pointerId);
759
+ const p = local(e);
760
+ setDraft({ a: p, b: p });
761
+ };
762
+ const onRootPointerMove = (e) => {
763
+ if (draft) setDraft({ a: draft.a, b: local(e) });
764
+ };
765
+ const onRootPointerUp = (e) => {
766
+ if (!draft) return;
767
+ const b = local(e);
768
+ const a = draft.a;
769
+ setDraft(null);
770
+ finishDraft(a, b);
771
+ };
772
+ const beginDrag = (e, a, mode) => {
773
+ const origin = singleRect(a);
774
+ if (!origin || e.button !== 0) return;
775
+ e.stopPropagation();
776
+ e.currentTarget.setPointerCapture(e.pointerId);
777
+ setDrag({
778
+ id: a.id,
779
+ mode,
780
+ startX: e.clientX,
781
+ startY: e.clientY,
782
+ origin,
783
+ rect: origin,
784
+ moved: false
785
+ });
786
+ };
787
+ const moveDrag = (e) => {
788
+ if (!drag) return;
789
+ const page = pageSize();
790
+ const dxPx = e.clientX - drag.startX;
791
+ const dyPx = e.clientY - drag.startY;
792
+ const moved = drag.moved || Math.hypot(dxPx, dyPx) > MOVE_THRESHOLD_PX;
793
+ if (!moved) return;
794
+ setDrag({
795
+ ...drag,
796
+ moved: true,
797
+ rect: dragRect(drag.origin, drag.mode, dxPx / page.width, dyPx / page.height)
798
+ });
799
+ };
800
+ const endDrag = (a) => {
801
+ if (!drag) return;
802
+ if (drag.moved) controller.update(a.id, patchForRect(a, drag.rect));
803
+ setDrag(null);
804
+ };
805
+ const interactive = (a) => tool === "select" || tool === "comment" && a.kind === "comment";
806
+ const selected = marks.find((a) => a.id === selectedId);
807
+ return /* @__PURE__ */ jsxs(
808
+ "div",
809
+ {
810
+ ref: rootRef,
811
+ ...{ [PAGE_ATTRIBUTE]: pageNumber },
812
+ "data-testid": `annotation-overlay-${pageNumber}`,
813
+ className: cn(
814
+ "absolute inset-0 z-10 select-none overflow-hidden",
815
+ drawing && "cursor-crosshair"
816
+ ),
817
+ style: {
818
+ pointerEvents: drawing ? "auto" : "none",
819
+ touchAction: drawing ? "none" : void 0
820
+ },
821
+ onPointerDown: onRootPointerDown,
822
+ onPointerMove: onRootPointerMove,
823
+ onPointerUp: onRootPointerUp,
824
+ onPointerCancel: () => setDraft(null),
825
+ children: [
826
+ marks.map((a) => /* @__PURE__ */ jsx(
827
+ MarkView,
828
+ {
829
+ annotation: a,
830
+ rectOverride: drag?.id === a.id ? drag.rect : void 0,
831
+ pxPerPt,
832
+ width: size.width,
833
+ height: size.height,
834
+ selected: a.id === selectedId,
835
+ interactive: interactive(a),
836
+ onPointerDown: (e) => {
837
+ if (!interactive(a)) return;
838
+ e.stopPropagation();
839
+ controller.select(a.id);
840
+ if (a.kind === "comment") setOpenComment(a.id);
841
+ beginDrag(e, a, "move");
842
+ },
843
+ onPointerMove: moveDrag,
844
+ onPointerUp: () => endDrag(a),
845
+ onActivate: () => {
846
+ controller.select(a.id);
847
+ if (a.kind === "comment") setOpenComment(a.id);
848
+ },
849
+ onDelete: () => controller.remove(a.id)
850
+ },
851
+ a.id
852
+ )),
853
+ selected && tool === "select" && singleRect(selected) && /* @__PURE__ */ jsx(
854
+ Handles,
855
+ {
856
+ rect: drag?.id === selected.id ? drag.rect : singleRect(selected),
857
+ onPointerDown: (e, mode) => beginDrag(e, selected, mode),
858
+ onPointerMove: moveDrag,
859
+ onPointerUp: () => endDrag(selected)
860
+ }
861
+ ),
862
+ selected && tool === "select" && /* @__PURE__ */ jsx(
863
+ ActionBar,
864
+ {
865
+ annotation: selected,
866
+ controller,
867
+ rect: drag?.id === selected.id ? drag.rect : firstRect(selected)
868
+ }
869
+ ),
870
+ draft && /* @__PURE__ */ jsx(Draft, { draft, tool }),
871
+ openComment && selected?.kind === "comment" && selected.id === openComment && /* @__PURE__ */ jsx(
872
+ CommentPopover,
873
+ {
874
+ annotation: selected,
875
+ controller,
876
+ onClose: () => {
877
+ setOpenComment(null);
878
+ controller.select(null);
879
+ }
880
+ }
881
+ )
882
+ ]
883
+ }
884
+ );
885
+ }
886
+ var firstRect = (a) => a.kind === "highlight" || a.kind === "redaction" ? a.rects[0] : a.rect;
887
+ function MarkView(props) {
888
+ const { annotation: a, rectOverride, pxPerPt, width, height, selected, interactive } = props;
889
+ const handlers = {
890
+ onPointerDown: props.onPointerDown,
891
+ onPointerMove: props.onPointerMove,
892
+ onPointerUp: props.onPointerUp,
893
+ onPointerCancel: props.onPointerUp,
894
+ onKeyDown: (e) => {
895
+ if (e.key === "Enter") props.onActivate();
896
+ if (e.key === "Delete" || e.key === "Backspace") {
897
+ e.preventDefault();
898
+ props.onDelete();
899
+ }
900
+ }
901
+ };
902
+ const base = (label) => ({
903
+ "data-testid": `annotation-mark-${a.id}`,
904
+ "data-kind": a.kind,
905
+ "data-selected": selected ? "true" : void 0,
906
+ role: "button",
907
+ tabIndex: interactive ? 0 : -1,
908
+ "aria-label": label,
909
+ ...handlers
910
+ });
911
+ const ring = selected ? "outline outline-2 outline-offset-2 outline-primary" : "";
912
+ const events = interactive ? "auto" : "none";
913
+ const dragsByTouch = selected && singleRect(a) !== null;
914
+ const cursor = interactive ? singleRect(a) ? "move" : "pointer" : void 0;
915
+ if (a.kind === "highlight") {
916
+ return /* @__PURE__ */ jsx(Fragment, { children: a.rects.map((r, i) => /* @__PURE__ */ jsx(
917
+ "div",
918
+ {
919
+ ...i === 0 ? base(`Highlight: ${a.text ?? ""}`) : {},
920
+ className: cn("absolute rounded-sm", i === 0 && ring),
921
+ style: {
922
+ ...rectStyle(r),
923
+ background: a.color,
924
+ mixBlendMode: "multiply",
925
+ opacity: 0.7,
926
+ pointerEvents: events,
927
+ touchAction: dragsByTouch ? "none" : void 0,
928
+ cursor
929
+ }
930
+ },
931
+ i
932
+ )) });
933
+ }
934
+ if (a.kind === "box") {
935
+ const r = rectOverride ?? a.rect;
936
+ return /* @__PURE__ */ jsx(
937
+ "div",
938
+ {
939
+ ...base("Box"),
940
+ className: cn("absolute", ring),
941
+ style: {
942
+ ...rectStyle(r),
943
+ border: `${a.strokeWidth * pxPerPt}px solid ${a.color}`,
944
+ pointerEvents: events,
945
+ touchAction: dragsByTouch ? "none" : void 0,
946
+ cursor,
947
+ boxSizing: "border-box"
948
+ }
949
+ }
950
+ );
951
+ }
952
+ if (a.kind === "stamp") {
953
+ const r = rectOverride ?? a.rect;
954
+ const fontPx = Math.max(
955
+ 6,
956
+ Math.min(r.h * height * 0.6, r.w * width * 0.9 / Math.max(1, a.label.length * 0.7))
957
+ );
958
+ return /* @__PURE__ */ jsx(
959
+ "div",
960
+ {
961
+ ...base(`Stamp: ${a.label}`),
962
+ className: cn("absolute flex items-center justify-center font-bold uppercase", ring),
963
+ style: {
964
+ ...rectStyle(r),
965
+ border: `${2 * pxPerPt}px solid ${a.color}`,
966
+ color: a.color,
967
+ fontSize: fontPx,
968
+ lineHeight: 1,
969
+ pointerEvents: events,
970
+ touchAction: dragsByTouch ? "none" : void 0,
971
+ cursor,
972
+ boxSizing: "border-box",
973
+ fontFamily: "Helvetica, Arial, sans-serif"
974
+ },
975
+ children: a.label
976
+ }
977
+ );
978
+ }
979
+ if (a.kind === "comment") {
980
+ const r = rectOverride ?? a.rect;
981
+ return /* @__PURE__ */ jsxs(
982
+ "button",
983
+ {
984
+ type: "button",
985
+ ...base(`Comment: ${a.body || "empty"}`),
986
+ className: cn(
987
+ "absolute flex items-center justify-center rounded-md border border-amber-700/60 bg-amber-300 text-amber-900 shadow-sm",
988
+ a.resolved && "opacity-50",
989
+ ring
990
+ ),
991
+ style: {
992
+ left: pct(r.x),
993
+ top: pct(r.y),
994
+ width: COMMENT_ICON_PX,
995
+ height: COMMENT_ICON_PX,
996
+ pointerEvents: events,
997
+ touchAction: dragsByTouch ? "none" : void 0,
998
+ cursor
999
+ },
1000
+ children: [
1001
+ /* @__PURE__ */ jsx(MessageSquare, { size: 14 }),
1002
+ a.replies.length > 0 && /* @__PURE__ */ jsx("span", { className: "absolute -right-1 -top-1 rounded-full bg-amber-900 px-1 text-[9px] leading-3 text-white", children: a.replies.length })
1003
+ ]
1004
+ }
1005
+ );
1006
+ }
1007
+ return /* @__PURE__ */ jsx(RedactionView, { ...props, annotation: a, ring, cursor, base });
1008
+ }
1009
+ function RedactionView({
1010
+ annotation: a,
1011
+ rectOverride,
1012
+ interactive,
1013
+ selected,
1014
+ ring,
1015
+ cursor,
1016
+ base
1017
+ }) {
1018
+ const events = interactive ? "auto" : "none";
1019
+ const dragsByTouch = selected && singleRect(a) !== null;
1020
+ const rects = rectOverride ? [rectOverride] : a.rects;
1021
+ const approved = a.status === "approved";
1022
+ const rejected = a.status === "rejected";
1023
+ return /* @__PURE__ */ jsx(Fragment, { children: rects.map((r, i) => /* @__PURE__ */ jsx(
1024
+ "div",
1025
+ {
1026
+ ...i === 0 ? base(`Redaction (${a.status}): ${a.reason}`) : {},
1027
+ "data-status": i === 0 ? a.status : void 0,
1028
+ className: cn(
1029
+ "absolute flex items-center justify-center overflow-hidden text-[10px] leading-none",
1030
+ i === 0 && ring
1031
+ ),
1032
+ style: {
1033
+ ...rectStyle(r),
1034
+ pointerEvents: events,
1035
+ touchAction: dragsByTouch ? "none" : void 0,
1036
+ cursor,
1037
+ boxSizing: "border-box",
1038
+ ...approved ? { background: "#000", color: "#fff" } : rejected ? { border: "1px dotted #868e96", opacity: 0.6 } : {
1039
+ background: "rgba(224,49,49,0.18)",
1040
+ border: "2px dashed #e03131",
1041
+ color: "#c92a2a"
1042
+ }
1043
+ },
1044
+ children: i === 0 && !rejected && /* @__PURE__ */ jsx("span", { className: "truncate px-1", children: a.reason })
1045
+ },
1046
+ i
1047
+ )) });
1048
+ }
1049
+ function Draft({ draft, tool }) {
1050
+ const x = Math.min(draft.a.x, draft.b.x);
1051
+ const y = Math.min(draft.a.y, draft.b.y);
1052
+ const w = Math.abs(draft.b.x - draft.a.x);
1053
+ const h = Math.abs(draft.b.y - draft.a.y);
1054
+ const redact = tool === "redact-area" || tool === "redact-text";
1055
+ return /* @__PURE__ */ jsx(
1056
+ "div",
1057
+ {
1058
+ "data-testid": "annotation-draft",
1059
+ className: "pointer-events-none absolute",
1060
+ style: {
1061
+ left: x,
1062
+ top: y,
1063
+ width: w,
1064
+ height: h,
1065
+ border: redact ? "2px dashed #e03131" : "2px solid #1c7ed6",
1066
+ background: redact ? "rgba(224,49,49,0.18)" : "rgba(28,126,214,0.08)"
1067
+ }
1068
+ }
1069
+ );
1070
+ }
1071
+ var HANDLES = [
1072
+ { mode: "nw", style: { left: 0, top: 0 }, cursor: "nwse-resize" },
1073
+ { mode: "ne", style: { left: "100%", top: 0 }, cursor: "nesw-resize" },
1074
+ { mode: "sw", style: { left: 0, top: "100%" }, cursor: "nesw-resize" },
1075
+ { mode: "se", style: { left: "100%", top: "100%" }, cursor: "nwse-resize" }
1076
+ ];
1077
+ function Handles({
1078
+ rect,
1079
+ onPointerDown,
1080
+ onPointerMove,
1081
+ onPointerUp
1082
+ }) {
1083
+ return /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute", style: rectStyle(rect), children: HANDLES.map((h) => (
1084
+ // The visible dot is small; the element a finger or pointer hits is a larger transparent
1085
+ // square around it (44px on touch screens, the usual minimum target).
1086
+ /* @__PURE__ */ jsx(
1087
+ "div",
1088
+ {
1089
+ "data-testid": `annotation-handle-${h.mode}`,
1090
+ className: "pointer-events-auto absolute flex h-6 w-6 -translate-x-1/2 -translate-y-1/2 items-center justify-center pointer-coarse:h-11 pointer-coarse:w-11",
1091
+ style: { ...h.style, cursor: h.cursor, touchAction: "none" },
1092
+ onPointerDown: (e) => onPointerDown(e, h.mode),
1093
+ onPointerMove,
1094
+ onPointerUp,
1095
+ onPointerCancel: onPointerUp,
1096
+ children: /* @__PURE__ */ jsx("span", { className: "pointer-events-none h-3 w-3 rounded-full border-2 border-primary bg-background" })
1097
+ },
1098
+ h.mode
1099
+ )
1100
+ )) });
1101
+ }
1102
+ var ACTION = "inline-flex h-7 w-7 items-center justify-center rounded text-foreground hover:bg-muted";
1103
+ function ActionBar({
1104
+ annotation: a,
1105
+ controller,
1106
+ rect
1107
+ }) {
1108
+ const above = rect.y > 0.05;
1109
+ return /* @__PURE__ */ jsxs(
1110
+ "div",
1111
+ {
1112
+ "data-testid": "annotation-actions",
1113
+ className: "pointer-events-auto absolute z-20 flex gap-0.5 rounded-md border border-border bg-background p-0.5 shadow-md",
1114
+ style: {
1115
+ left: pct(rect.x),
1116
+ top: above ? `calc(${pct(rect.y)} - 36px)` : `calc(${pct(rect.y + rect.h)} + 6px)`
1117
+ },
1118
+ onPointerDown: (e) => e.stopPropagation(),
1119
+ children: [
1120
+ a.kind === "redaction" && a.status !== "approved" && /* @__PURE__ */ jsx(
1121
+ "button",
1122
+ {
1123
+ type: "button",
1124
+ className: ACTION,
1125
+ title: "Approve redaction",
1126
+ "aria-label": "Approve redaction",
1127
+ "data-testid": "annotation-action-approve",
1128
+ onClick: () => controller.setRedactionStatus([a.id], "approved"),
1129
+ children: /* @__PURE__ */ jsx(Check, { size: 15 })
1130
+ }
1131
+ ),
1132
+ a.kind === "redaction" && a.status !== "rejected" && /* @__PURE__ */ jsx(
1133
+ "button",
1134
+ {
1135
+ type: "button",
1136
+ className: ACTION,
1137
+ title: "Reject redaction (leave visible)",
1138
+ "aria-label": "Reject redaction",
1139
+ "data-testid": "annotation-action-reject",
1140
+ onClick: () => controller.setRedactionStatus([a.id], "rejected"),
1141
+ children: /* @__PURE__ */ jsx(X, { size: 15 })
1142
+ }
1143
+ ),
1144
+ a.kind === "redaction" && a.status !== "pending" && /* @__PURE__ */ jsx(
1145
+ "button",
1146
+ {
1147
+ type: "button",
1148
+ className: ACTION,
1149
+ title: "Back to pending",
1150
+ "aria-label": "Mark pending",
1151
+ "data-testid": "annotation-action-pending",
1152
+ onClick: () => controller.setRedactionStatus([a.id], "pending"),
1153
+ children: /* @__PURE__ */ jsx(RotateCcw, { size: 15 })
1154
+ }
1155
+ ),
1156
+ /* @__PURE__ */ jsx(
1157
+ "button",
1158
+ {
1159
+ type: "button",
1160
+ className: ACTION,
1161
+ title: "Delete",
1162
+ "aria-label": "Delete annotation",
1163
+ "data-testid": "annotation-action-delete",
1164
+ onClick: () => controller.remove(a.id),
1165
+ children: /* @__PURE__ */ jsx(Trash2, { size: 15 })
1166
+ }
1167
+ )
1168
+ ]
1169
+ }
1170
+ );
1171
+ }
1172
+ function CommentPopover({
1173
+ annotation: a,
1174
+ controller,
1175
+ onClose
1176
+ }) {
1177
+ const [body, setBody] = useState(a.body);
1178
+ const [reply, setReply] = useState("");
1179
+ const mine = a.author === controller.author;
1180
+ useEffect(() => setBody(a.body), [a.body]);
1181
+ const commitBody = () => {
1182
+ if (mine && body !== a.body) controller.update(a.id, { body });
1183
+ };
1184
+ const close = () => {
1185
+ commitBody();
1186
+ if (body.trim() === "" && a.replies.length === 0) controller.remove(a.id);
1187
+ onClose();
1188
+ };
1189
+ const sendReply = () => {
1190
+ const text = reply.trim();
1191
+ if (!text) return;
1192
+ commitBody();
1193
+ controller.reply(a.id, text);
1194
+ setReply("");
1195
+ };
1196
+ const onRight = a.rect.x > 0.6;
1197
+ return /* @__PURE__ */ jsxs(
1198
+ "div",
1199
+ {
1200
+ "data-testid": "annotation-comment-popover",
1201
+ className: "pointer-events-auto absolute z-30 w-64 rounded-lg border border-border bg-background p-3 text-sm shadow-lg",
1202
+ style: {
1203
+ top: pct(a.rect.y),
1204
+ ...onRight ? { right: `calc(${pct(1 - a.rect.x)} + 8px)` } : { left: `calc(${pct(a.rect.x)} + ${COMMENT_ICON_PX + 8}px)` }
1205
+ },
1206
+ onPointerDown: (e) => e.stopPropagation(),
1207
+ children: [
1208
+ /* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center justify-between gap-2 text-xs text-muted-foreground", children: [
1209
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
1210
+ a.author,
1211
+ " \xB7 ",
1212
+ new Date(a.createdAt).toLocaleString()
1213
+ ] }),
1214
+ /* @__PURE__ */ jsx(
1215
+ "button",
1216
+ {
1217
+ type: "button",
1218
+ "aria-label": "Close comment",
1219
+ "data-testid": "annotation-comment-close",
1220
+ className: ACTION,
1221
+ onClick: close,
1222
+ children: /* @__PURE__ */ jsx(X, { size: 14 })
1223
+ }
1224
+ )
1225
+ ] }),
1226
+ /* @__PURE__ */ jsx(
1227
+ "textarea",
1228
+ {
1229
+ autoFocus: a.body === "",
1230
+ "data-testid": "annotation-comment-body",
1231
+ className: "min-h-16 w-full resize-y rounded-md border border-input bg-background p-2 text-sm",
1232
+ placeholder: "Add a comment",
1233
+ value: body,
1234
+ readOnly: !mine,
1235
+ onChange: (e) => setBody(e.target.value),
1236
+ onBlur: commitBody,
1237
+ onKeyDown: (e) => {
1238
+ if (e.key === "Escape") close();
1239
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
1240
+ commitBody();
1241
+ onClose();
1242
+ }
1243
+ }
1244
+ }
1245
+ ),
1246
+ a.replies.length > 0 && /* @__PURE__ */ jsx(
1247
+ "ul",
1248
+ {
1249
+ className: "mt-2 max-h-40 space-y-2 overflow-y-auto",
1250
+ "data-testid": "annotation-comment-replies",
1251
+ children: a.replies.map((r) => /* @__PURE__ */ jsxs("li", { className: "rounded-md bg-muted p-2", children: [
1252
+ /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground", children: r.author }),
1253
+ /* @__PURE__ */ jsx("div", { className: "whitespace-pre-wrap break-words", children: r.body })
1254
+ ] }, r.id))
1255
+ }
1256
+ ),
1257
+ /* @__PURE__ */ jsxs("div", { className: "mt-2 flex gap-1", children: [
1258
+ /* @__PURE__ */ jsx(
1259
+ "input",
1260
+ {
1261
+ "data-testid": "annotation-comment-reply",
1262
+ className: "h-8 min-w-0 flex-1 rounded-md border border-input bg-background px-2 text-sm",
1263
+ placeholder: "Reply",
1264
+ value: reply,
1265
+ onChange: (e) => setReply(e.target.value),
1266
+ onKeyDown: (e) => {
1267
+ if (e.key === "Enter") {
1268
+ e.preventDefault();
1269
+ sendReply();
1270
+ }
1271
+ }
1272
+ }
1273
+ ),
1274
+ /* @__PURE__ */ jsx(
1275
+ "button",
1276
+ {
1277
+ type: "button",
1278
+ "aria-label": "Send reply",
1279
+ "data-testid": "annotation-comment-send",
1280
+ className: ACTION,
1281
+ onClick: sendReply,
1282
+ children: /* @__PURE__ */ jsx(Send, { size: 14 })
1283
+ }
1284
+ )
1285
+ ] }),
1286
+ /* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-center justify-between", children: [
1287
+ /* @__PURE__ */ jsx(
1288
+ "button",
1289
+ {
1290
+ type: "button",
1291
+ "data-testid": "annotation-comment-resolve",
1292
+ className: "text-xs text-primary hover:underline",
1293
+ onClick: () => controller.resolve(a.id, !a.resolved),
1294
+ children: a.resolved ? "Reopen" : "Resolve"
1295
+ }
1296
+ ),
1297
+ /* @__PURE__ */ jsx(
1298
+ "button",
1299
+ {
1300
+ type: "button",
1301
+ "data-testid": "annotation-comment-delete",
1302
+ className: "text-xs text-destructive hover:underline",
1303
+ onClick: () => {
1304
+ controller.remove(a.id);
1305
+ onClose();
1306
+ },
1307
+ children: "Delete"
1308
+ }
1309
+ )
1310
+ ] })
1311
+ ]
1312
+ }
1313
+ );
1314
+ }
1315
+ var isEditable = (el) => el instanceof HTMLElement && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName));
1316
+ function useAnnotationShortcuts(controller, enabled = true) {
1317
+ useEffect(() => {
1318
+ if (!enabled) return;
1319
+ const onKey = (e) => {
1320
+ if (isEditable(e.target)) return;
1321
+ const mod = e.metaKey || e.ctrlKey;
1322
+ if (mod && e.key.toLowerCase() === "z") {
1323
+ e.preventDefault();
1324
+ if (e.shiftKey) controller.redo();
1325
+ else controller.undo();
1326
+ } else if (mod && e.key.toLowerCase() === "y") {
1327
+ e.preventDefault();
1328
+ controller.redo();
1329
+ } else if ((e.key === "Delete" || e.key === "Backspace") && controller.selectedId) {
1330
+ e.preventDefault();
1331
+ controller.remove(controller.selectedId);
1332
+ } else if (e.key === "Escape") {
1333
+ controller.select(null);
1334
+ controller.setTool("select");
1335
+ }
1336
+ };
1337
+ document.addEventListener("keydown", onKey);
1338
+ return () => document.removeEventListener("keydown", onKey);
1339
+ }, [controller, enabled]);
1340
+ }
1341
+ var TOOLS = [
1342
+ { tool: "select", label: "Select", icon: /* @__PURE__ */ jsx(MousePointer2, { size: 16 }) },
1343
+ { tool: "highlight", label: "Highlight", icon: /* @__PURE__ */ jsx(Highlighter, { size: 16 }) },
1344
+ { tool: "box", label: "Box", icon: /* @__PURE__ */ jsx(Square, { size: 16 }) },
1345
+ { tool: "comment", label: "Comment", icon: /* @__PURE__ */ jsx(MessageSquare, { size: 16 }) },
1346
+ { tool: "stamp", label: "Stamp", icon: /* @__PURE__ */ jsx(Stamp, { size: 16 }) },
1347
+ { tool: "redact-text", label: "Redact text", icon: /* @__PURE__ */ jsx(ScanText, { size: 16 }) },
1348
+ { tool: "redact-area", label: "Redact area", icon: /* @__PURE__ */ jsx(EyeOff, { size: 16 }) }
1349
+ ];
1350
+ function Swatches({
1351
+ colors,
1352
+ value,
1353
+ onChange,
1354
+ label
1355
+ }) {
1356
+ return /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", role: "group", "aria-label": label, children: colors.map((c) => /* @__PURE__ */ jsx(
1357
+ "button",
1358
+ {
1359
+ type: "button",
1360
+ "aria-label": `${label} ${c}`,
1361
+ "aria-pressed": c === value,
1362
+ "data-testid": `annotation-color-${c.slice(1)}`,
1363
+ className: cn(
1364
+ "h-5 w-5 rounded-full border border-border",
1365
+ c === value && "ring-2 ring-primary ring-offset-1"
1366
+ ),
1367
+ style: { background: c },
1368
+ onClick: () => onChange(c)
1369
+ },
1370
+ c
1371
+ )) });
1372
+ }
1373
+ function AnnotationToolbar({ controller, onFreeze, className }) {
1374
+ useTextSelectionMarks(controller);
1375
+ useAnnotationShortcuts(controller);
1376
+ const { tool, settings } = controller;
1377
+ const pending = pendingRedactions(controller.layer);
1378
+ const redactionCount = controller.layer.annotations.filter((a) => a.kind === "redaction").length;
1379
+ const colored = tool === "highlight" || tool === "box" || tool === "stamp";
1380
+ const status = controller.error ? "Not saved" : controller.saving ? "Saving\u2026" : controller.dirty ? "Unsaved changes" : "Saved";
1381
+ return /* @__PURE__ */ jsxs(
1382
+ "div",
1383
+ {
1384
+ role: "toolbar",
1385
+ "aria-label": "Annotation tools",
1386
+ "data-testid": "annotation-toolbar",
1387
+ className: cn(
1388
+ "flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-border bg-background px-3 py-2",
1389
+ className
1390
+ ),
1391
+ children: [
1392
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", role: "group", "aria-label": "Tool", children: TOOLS.map(({ tool: t, label, icon }) => /* @__PURE__ */ jsx(
1393
+ Button,
1394
+ {
1395
+ type: "button",
1396
+ size: "icon",
1397
+ variant: tool === t ? "default" : "ghost",
1398
+ title: label,
1399
+ "aria-label": label,
1400
+ "aria-pressed": tool === t,
1401
+ "data-testid": `annotation-tool-${t}`,
1402
+ onClick: () => controller.setTool(t),
1403
+ children: icon
1404
+ },
1405
+ t
1406
+ )) }),
1407
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", role: "group", "aria-label": "History", children: [
1408
+ /* @__PURE__ */ jsx(
1409
+ Button,
1410
+ {
1411
+ type: "button",
1412
+ size: "icon",
1413
+ variant: "ghost",
1414
+ title: "Undo",
1415
+ "aria-label": "Undo",
1416
+ "data-testid": "annotation-undo",
1417
+ disabled: !controller.canUndo,
1418
+ onClick: controller.undo,
1419
+ children: /* @__PURE__ */ jsx(Undo2, { size: 16 })
1420
+ }
1421
+ ),
1422
+ /* @__PURE__ */ jsx(
1423
+ Button,
1424
+ {
1425
+ type: "button",
1426
+ size: "icon",
1427
+ variant: "ghost",
1428
+ title: "Redo",
1429
+ "aria-label": "Redo",
1430
+ "data-testid": "annotation-redo",
1431
+ disabled: !controller.canRedo,
1432
+ onClick: controller.redo,
1433
+ children: /* @__PURE__ */ jsx(Redo2, { size: 16 })
1434
+ }
1435
+ )
1436
+ ] }),
1437
+ colored && /* @__PURE__ */ jsx(
1438
+ Swatches,
1439
+ {
1440
+ label: "Colour",
1441
+ colors: tool === "highlight" ? HIGHLIGHT_COLORS : MARK_COLORS,
1442
+ value: settings.colors[tool],
1443
+ onChange: (c) => controller.setSettings({ colors: { ...settings.colors, [tool]: c } })
1444
+ }
1445
+ ),
1446
+ tool === "stamp" && /* @__PURE__ */ jsxs(Fragment, { children: [
1447
+ /* @__PURE__ */ jsx(
1448
+ "input",
1449
+ {
1450
+ list: "annotation-stamp-presets",
1451
+ "aria-label": "Stamp text",
1452
+ "data-testid": "annotation-stamp-label",
1453
+ className: "h-8 w-40 rounded-md border border-input bg-background px-2 text-sm",
1454
+ value: settings.stampLabel,
1455
+ maxLength: 40,
1456
+ onChange: (e) => controller.setSettings({ stampLabel: e.target.value })
1457
+ }
1458
+ ),
1459
+ /* @__PURE__ */ jsx("datalist", { id: "annotation-stamp-presets", children: STAMP_PRESETS.map((s) => /* @__PURE__ */ jsx("option", { value: s }, s)) })
1460
+ ] }),
1461
+ (tool === "redact-text" || tool === "redact-area") && /* @__PURE__ */ jsxs(Fragment, { children: [
1462
+ /* @__PURE__ */ jsx(
1463
+ "input",
1464
+ {
1465
+ list: "annotation-redaction-reasons",
1466
+ "aria-label": "Redaction reason",
1467
+ "data-testid": "annotation-redaction-reason",
1468
+ className: "h-8 w-44 rounded-md border border-input bg-background px-2 text-sm",
1469
+ value: settings.redactionReason,
1470
+ maxLength: 80,
1471
+ onChange: (e) => controller.setSettings({ redactionReason: e.target.value })
1472
+ }
1473
+ ),
1474
+ /* @__PURE__ */ jsx("datalist", { id: "annotation-redaction-reasons", children: REDACTION_REASONS.map((r) => /* @__PURE__ */ jsx("option", { value: r }, r)) })
1475
+ ] }),
1476
+ redactionCount > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm", "data-testid": "annotation-review", children: [
1477
+ /* @__PURE__ */ jsxs("span", { className: "rounded-md bg-muted px-2 py-1", "data-testid": "annotation-pending-count", children: [
1478
+ pending.length,
1479
+ " pending"
1480
+ ] }),
1481
+ /* @__PURE__ */ jsx(
1482
+ Button,
1483
+ {
1484
+ type: "button",
1485
+ size: "sm",
1486
+ variant: "outline",
1487
+ disabled: pending.length === 0,
1488
+ "data-testid": "annotation-approve-all",
1489
+ onClick: () => controller.setRedactionStatus(
1490
+ pending.map((a) => a.id),
1491
+ "approved"
1492
+ ),
1493
+ children: "Approve all"
1494
+ }
1495
+ ),
1496
+ /* @__PURE__ */ jsx(
1497
+ Button,
1498
+ {
1499
+ type: "button",
1500
+ size: "sm",
1501
+ variant: "outline",
1502
+ disabled: pending.length === 0,
1503
+ "data-testid": "annotation-reject-all",
1504
+ onClick: () => controller.setRedactionStatus(
1505
+ pending.map((a) => a.id),
1506
+ "rejected"
1507
+ ),
1508
+ children: "Reject all"
1509
+ }
1510
+ )
1511
+ ] }),
1512
+ /* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-3 text-xs text-muted-foreground", children: [
1513
+ /* @__PURE__ */ jsx(
1514
+ "span",
1515
+ {
1516
+ "data-testid": "annotation-status",
1517
+ role: "status",
1518
+ className: cn(controller.error && "text-destructive"),
1519
+ title: controller.error ?? void 0,
1520
+ children: status
1521
+ }
1522
+ ),
1523
+ onFreeze && /* @__PURE__ */ jsxs(Button, { type: "button", size: "sm", "data-testid": "annotation-freeze", onClick: onFreeze, children: [
1524
+ /* @__PURE__ */ jsx(Snowflake, { size: 14 }),
1525
+ "Freeze copy"
1526
+ ] })
1527
+ ] })
1528
+ ]
1529
+ }
1530
+ );
1531
+ }
1532
+ var KIND_LABELS = {
1533
+ highlight: "highlights",
1534
+ box: "boxes",
1535
+ comment: "comments",
1536
+ stamp: "stamps",
1537
+ redaction: "redactions"
1538
+ };
1539
+ function FreezeDialog({
1540
+ open,
1541
+ onOpenChange,
1542
+ controller,
1543
+ onConfirm,
1544
+ busy,
1545
+ progress,
1546
+ error
1547
+ }) {
1548
+ const [mode, setMode] = useState("vector");
1549
+ const [comments, setComments] = useState("omit");
1550
+ const [burnPending, setBurnPending] = useState(false);
1551
+ const marks = controller.layer.annotations;
1552
+ const redactions = marks.filter(isEffectiveRedaction);
1553
+ const pending = pendingRedactions(controller.layer);
1554
+ const forced = redactions.length > 0;
1555
+ const effectiveMode = forced ? "image" : mode;
1556
+ const blocked = pending.length > 0 && !burnPending;
1557
+ const counts = Object.keys(KIND_LABELS).map(
1558
+ (k) => [
1559
+ k,
1560
+ marks.filter((a) => a.kind === k && (k !== "redaction" || isEffectiveRedaction(a))).length
1561
+ ]
1562
+ ).filter(([, n]) => n > 0);
1563
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: (next) => !busy && onOpenChange(next), children: /* @__PURE__ */ jsxs(DialogContent, { "data-testid": "freeze-dialog", children: [
1564
+ /* @__PURE__ */ jsxs(DialogHeader, { children: [
1565
+ /* @__PURE__ */ jsx(DialogTitle, { children: "Freeze a copy" }),
1566
+ /* @__PURE__ */ jsx(DialogDescription, { children: "Creates a new document with your annotations built in. The original is never changed." })
1567
+ ] }),
1568
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", "data-testid": "freeze-summary", children: counts.length === 0 ? "No annotations yet." : counts.map(([k, n]) => `${n} ${KIND_LABELS[k]}`).join(", ") }),
1569
+ /* @__PURE__ */ jsxs("fieldset", { className: "space-y-2 text-sm", disabled: busy, children: [
1570
+ /* @__PURE__ */ jsx("legend", { className: "mb-1 font-medium", children: "Format" }),
1571
+ /* @__PURE__ */ jsxs("label", { className: "flex items-start gap-2", children: [
1572
+ /* @__PURE__ */ jsx(
1573
+ "input",
1574
+ {
1575
+ type: "radio",
1576
+ name: "freeze-mode",
1577
+ "data-testid": "freeze-mode-vector",
1578
+ checked: effectiveMode === "vector",
1579
+ disabled: forced,
1580
+ onChange: () => setMode("vector")
1581
+ }
1582
+ ),
1583
+ /* @__PURE__ */ jsxs("span", { children: [
1584
+ "Keep text",
1585
+ /* @__PURE__ */ jsx("span", { className: "block text-xs text-muted-foreground", children: "Searchable, smaller. Not available when there are redactions." })
1586
+ ] })
1587
+ ] }),
1588
+ /* @__PURE__ */ jsxs("label", { className: "flex items-start gap-2", children: [
1589
+ /* @__PURE__ */ jsx(
1590
+ "input",
1591
+ {
1592
+ type: "radio",
1593
+ name: "freeze-mode",
1594
+ "data-testid": "freeze-mode-image",
1595
+ checked: effectiveMode === "image",
1596
+ onChange: () => setMode("image")
1597
+ }
1598
+ ),
1599
+ /* @__PURE__ */ jsxs("span", { children: [
1600
+ "Image only",
1601
+ /* @__PURE__ */ jsx("span", { className: "block text-xs text-muted-foreground", children: "Every page becomes a picture. Nothing is left behind a redaction." })
1602
+ ] })
1603
+ ] }),
1604
+ forced && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", "data-testid": "freeze-forced-note", children: "Image only is required because this document has redactions." })
1605
+ ] }),
1606
+ /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2 text-sm", children: [
1607
+ "Comments",
1608
+ /* @__PURE__ */ jsxs(
1609
+ "select",
1610
+ {
1611
+ "data-testid": "freeze-comments",
1612
+ className: "h-8 rounded-md border border-input bg-background px-2",
1613
+ value: comments,
1614
+ disabled: busy,
1615
+ onChange: (e) => setComments(e.target.value),
1616
+ children: [
1617
+ /* @__PURE__ */ jsx("option", { value: "omit", children: "Leave out" }),
1618
+ /* @__PURE__ */ jsx("option", { value: "markers", children: "Numbered markers" }),
1619
+ /* @__PURE__ */ jsx("option", { value: "appendix", children: "Markers and a listing" })
1620
+ ]
1621
+ }
1622
+ )
1623
+ ] }),
1624
+ forced && comments !== "omit" && marks.some((a) => a.kind === "comment") && /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", "data-testid": "freeze-comment-warning", children: "Comments are copied as written and may repeat text you have redacted." }),
1625
+ pending.length > 0 && /* @__PURE__ */ jsxs(
1626
+ "label",
1627
+ {
1628
+ className: "flex items-start gap-2 rounded-md border border-border p-2 text-sm",
1629
+ "data-testid": "freeze-pending",
1630
+ children: [
1631
+ /* @__PURE__ */ jsx(
1632
+ "input",
1633
+ {
1634
+ type: "checkbox",
1635
+ "data-testid": "freeze-burn-pending",
1636
+ checked: burnPending,
1637
+ disabled: busy,
1638
+ onChange: (e) => setBurnPending(e.target.checked)
1639
+ }
1640
+ ),
1641
+ /* @__PURE__ */ jsxs("span", { children: [
1642
+ pending.length,
1643
+ " redaction",
1644
+ pending.length === 1 ? " has" : "s have",
1645
+ " not been reviewed",
1646
+ /* @__PURE__ */ jsx("span", { className: "block text-xs text-muted-foreground", children: "Tick to redact them as well, or approve or reject them first." })
1647
+ ] })
1648
+ ]
1649
+ }
1650
+ ),
1651
+ busy && progress && /* @__PURE__ */ jsxs("p", { className: "text-sm", role: "status", "data-testid": "freeze-progress", children: [
1652
+ "Page ",
1653
+ progress.done,
1654
+ " of ",
1655
+ progress.total,
1656
+ "\u2026"
1657
+ ] }),
1658
+ error && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", role: "alert", "data-testid": "freeze-error", children: error }),
1659
+ /* @__PURE__ */ jsxs(DialogFooter, { children: [
1660
+ /* @__PURE__ */ jsx(
1661
+ Button,
1662
+ {
1663
+ type: "button",
1664
+ variant: "outline",
1665
+ disabled: busy,
1666
+ onClick: () => onOpenChange(false),
1667
+ children: "Cancel"
1668
+ }
1669
+ ),
1670
+ /* @__PURE__ */ jsx(
1671
+ Button,
1672
+ {
1673
+ type: "button",
1674
+ "data-testid": "freeze-confirm",
1675
+ disabled: busy || blocked,
1676
+ onClick: () => onConfirm({
1677
+ mode: effectiveMode,
1678
+ comments,
1679
+ pendingRedactions: burnPending ? "burn" : "error"
1680
+ }),
1681
+ children: busy ? "Freezing\u2026" : "Freeze"
1682
+ }
1683
+ )
1684
+ ] })
1685
+ ] }) });
1686
+ }
1687
+
1688
+ export { AnnotationPageOverlay, AnnotationToolbar, DEFAULT_SETTINGS, FreezeDialog, HIGHLIGHT_COLORS, MARK_COLORS, REDACTION_REASONS, STAMP_PRESETS, annotationsOnPage, applyAction, canRedo, canUndo, containsPoint, createHistory, createLocalStorageStore, createMemoryStore, dragRect, dragToNorm, intersects, isTooSmall, mergeLineRects, patchForRect, pendingRedactions, readSelection, redo, reduceLayer, selectionToPageMarks, singleRect, toNorm, toPixels, undo, useAnnotationLayer, useAnnotationShortcuts, useTextSelectionMarks };
1689
+ //# sourceMappingURL=index.js.map
1690
+ //# sourceMappingURL=index.js.map