@arbidocs/react 0.4.54 → 0.4.56

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