@arbidocs/react 0.4.55 → 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 (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 +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 +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,291 @@
1
+ import { A as Annotation, e as RedactionStatus, d as CommentReply, b as AnnotationLayer, N as NormRect } from '../model-DzQxhMMz.js';
2
+ export { a as AnnotationKind, c as AnnotationLayerError, B as BoxAnnotation, C as CommentAnnotation, H as HighlightAnnotation, L as LAYER_SCHEMA_VERSION, R as RedactionAnnotation, S as StampAnnotation, f as annotationRects, g as clampRect, h as emptyLayer, i as isEffectiveRedaction, p as parseAnnotation, j as parseLayer } from '../model-DzQxhMMz.js';
3
+ import * as React from 'react';
4
+
5
+ /**
6
+ * Pure state for an annotation layer: actions, a reducer and undo/redo history.
7
+ *
8
+ * No clock and no randomness in here. Callers pass ids and timestamps in, so the reducer is
9
+ * deterministic, trivially testable, and an agent can replay the same actions a person makes.
10
+ */
11
+
12
+ /** Fields a caller may change on any mark. Identity (`id`, `kind`, `page`) is fixed. */
13
+ type PatchOf<A> = A extends Annotation ? Partial<Omit<A, 'id' | 'kind' | 'page' | 'createdAt'>> : never;
14
+ type AnnotationPatch = PatchOf<Annotation>;
15
+ type AnnotationAction = {
16
+ type: 'add';
17
+ annotation: Annotation;
18
+ } | {
19
+ type: 'addMany';
20
+ annotations: Annotation[];
21
+ } | {
22
+ type: 'update';
23
+ id: string;
24
+ patch: AnnotationPatch;
25
+ now: string;
26
+ } | {
27
+ type: 'remove';
28
+ id: string;
29
+ now: string;
30
+ } | {
31
+ type: 'setRedactionStatus';
32
+ ids: string[];
33
+ status: RedactionStatus;
34
+ now: string;
35
+ } | {
36
+ type: 'reply';
37
+ id: string;
38
+ reply: CommentReply;
39
+ now: string;
40
+ } | {
41
+ type: 'resolve';
42
+ id: string;
43
+ resolved: boolean;
44
+ now: string;
45
+ } | {
46
+ type: 'replaceAll';
47
+ layer: AnnotationLayer;
48
+ };
49
+ interface LayerHistory {
50
+ present: AnnotationLayer;
51
+ past: AnnotationLayer[];
52
+ future: AnnotationLayer[];
53
+ }
54
+ declare function createHistory(layer: AnnotationLayer): LayerHistory;
55
+ /** Apply one action to a layer. Returns the same object when nothing changed. */
56
+ declare function reduceLayer(layer: AnnotationLayer, action: AnnotationAction): AnnotationLayer;
57
+ /** Apply an action and record it for undo. A no-op action leaves history untouched. */
58
+ declare function applyAction(history: LayerHistory, action: AnnotationAction): LayerHistory;
59
+ declare function undo(history: LayerHistory): LayerHistory;
60
+ declare function redo(history: LayerHistory): LayerHistory;
61
+ declare const canUndo: (h: LayerHistory) => boolean;
62
+ declare const canRedo: (h: LayerHistory) => boolean;
63
+ declare function annotationsOnPage(layer: AnnotationLayer, page: number): Annotation[];
64
+ declare function pendingRedactions(layer: AnnotationLayer): Annotation[];
65
+
66
+ /**
67
+ * Where a layer is kept. The layer is data about a document, not part of it, so the host decides
68
+ * (backend API, IndexedDB, a file). This package ships an in-memory store and a localStorage
69
+ * store; both validate on load because stored JSON is untrusted.
70
+ */
71
+
72
+ interface AnnotationStore {
73
+ /** The saved layer, or an empty one for a document that has none yet. */
74
+ load(documentId: string): Promise<AnnotationLayer>;
75
+ save(layer: AnnotationLayer): Promise<void>;
76
+ }
77
+ declare function createMemoryStore(now?: () => string): AnnotationStore;
78
+ /**
79
+ * Per-browser store. Storage can be absent, full or blocked (private windows), so every access is
80
+ * guarded. A saved layer that no longer validates is ignored rather than crashing the viewer.
81
+ */
82
+ declare function createLocalStorageStore(storage?: Pick<Storage, 'getItem' | 'setItem'> | undefined, now?: () => string): AnnotationStore;
83
+
84
+ /**
85
+ * Geometry helpers: pixels <-> fractions of the displayed page, and turning a text selection's
86
+ * many client rects into tidy line boxes.
87
+ */
88
+
89
+ interface PixelRect {
90
+ x: number;
91
+ y: number;
92
+ width: number;
93
+ height: number;
94
+ }
95
+ interface PixelSize {
96
+ width: number;
97
+ height: number;
98
+ }
99
+ declare function toNorm(r: PixelRect, page: PixelSize): NormRect;
100
+ declare function toPixels(r: NormRect, page: PixelSize): PixelRect;
101
+ /** A drag from `a` to `b` (any direction), as a normalised rectangle. */
102
+ declare function dragToNorm(a: {
103
+ x: number;
104
+ y: number;
105
+ }, b: {
106
+ x: number;
107
+ y: number;
108
+ }, page: PixelSize): NormRect;
109
+ declare function isTooSmall(r: NormRect): boolean;
110
+ declare function containsPoint(r: NormRect, x: number, y: number): boolean;
111
+ declare function intersects(a: NormRect, b: NormRect): boolean;
112
+ /**
113
+ * Collapse a selection's client rects into one box per text line. Browsers return a rect per
114
+ * text node or span, often overlapping and with sub-pixel gaps; merging rects that share a line
115
+ * and touch (or nearly touch) horizontally gives a clean, even highlight. Rects that sit on
116
+ * different lines are left alone. Input is in the page's pixel space.
117
+ */
118
+ declare function mergeLineRects(input: PixelRect[], gap?: number): PixelRect[];
119
+
120
+ /**
121
+ * The contract between the annotation state (`useAnnotationLayer`) and the UI that draws it
122
+ * (`AnnotationPageOverlay`, `AnnotationToolbar`). Components take a controller as a prop and hold
123
+ * no annotation state of their own beyond transient drags.
124
+ */
125
+
126
+ type AnnotationTool = 'select' | 'highlight' | 'box' | 'comment' | 'stamp' | 'redact-area' | 'redact-text';
127
+ /** Tools that colour what they make. */
128
+ type ColoredTool = 'highlight' | 'box' | 'stamp';
129
+ interface ToolSettings {
130
+ colors: Record<ColoredTool, string>;
131
+ stampLabel: string;
132
+ redactionReason: string;
133
+ /** Box outline width in points. */
134
+ strokeWidth: number;
135
+ }
136
+ declare const DEFAULT_SETTINGS: ToolSettings;
137
+ declare const HIGHLIGHT_COLORS: string[];
138
+ declare const MARK_COLORS: string[];
139
+ declare const STAMP_PRESETS: string[];
140
+ declare const REDACTION_REASONS: string[];
141
+ /** A mark as the UI describes it: identity, author and timestamps are added by the controller. */
142
+ type NewMark = Annotation extends infer A ? A extends Annotation ? Omit<A, 'id' | 'author' | 'createdAt' | 'updatedAt'> : never : never;
143
+ type LayerStatus = 'loading' | 'ready' | 'error';
144
+ interface AnnotationController {
145
+ layer: AnnotationLayer;
146
+ status: LayerStatus;
147
+ /** The last load, save or validation failure, for the UI to show. */
148
+ error: string | null;
149
+ saving: boolean;
150
+ /** True when edits have not reached the store yet. */
151
+ dirty: boolean;
152
+ author: string;
153
+ tool: AnnotationTool;
154
+ setTool(tool: AnnotationTool): void;
155
+ settings: ToolSettings;
156
+ setSettings(patch: Partial<ToolSettings>): void;
157
+ selectedId: string | null;
158
+ select(id: string | null): void;
159
+ add(mark: NewMark): string | null;
160
+ /** Add several marks as ONE undo step (e.g. a selection spanning pages). */
161
+ addMany(marks: NewMark[]): string[];
162
+ update(id: string, patch: AnnotationPatch): void;
163
+ remove(id: string): void;
164
+ setRedactionStatus(ids: string[], status: RedactionStatus): void;
165
+ reply(id: string, body: string): void;
166
+ resolve(id: string, resolved: boolean): void;
167
+ undo(): void;
168
+ redo(): void;
169
+ canUndo: boolean;
170
+ canRedo: boolean;
171
+ /** Write to the store now (before leaving the page). */
172
+ flush(): Promise<void>;
173
+ }
174
+
175
+ /**
176
+ * Annotation state for one document: loads its layer from a store, applies edits through the pure
177
+ * reducer (so undo/redo is exact), and saves back after a short pause.
178
+ *
179
+ * Edits are applied from a ref, not inside a React state updater, so a mark that fails validation
180
+ * is reported through `error` instead of throwing during render.
181
+ */
182
+
183
+ interface UseAnnotationLayerOptions {
184
+ documentId: string;
185
+ store: AnnotationStore;
186
+ /** Display name recorded as the author of new marks. */
187
+ author: string;
188
+ autosaveMs?: number;
189
+ now?: () => string;
190
+ makeId?: () => string;
191
+ }
192
+ declare function useAnnotationLayer({ documentId, store, author, autosaveMs, now, makeId, }: UseAnnotationLayerOptions): AnnotationController;
193
+
194
+ /**
195
+ * Turns a text selection made on the page into marks while the highlight or redact-text tool is
196
+ * active. Only a selection that STARTED on a page counts: otherwise text left selected from an
197
+ * earlier gesture would be marked the moment the user clicked a toolbar button.
198
+ *
199
+ * With a mouse the gesture is press, drag, release, so the release marks the selection. A touch
200
+ * selection is different: the user long-presses a word, then drags the handles, and the browser
201
+ * may cancel the pointer instead of releasing it. So for touch the selection is marked once it has
202
+ * stopped changing for a moment. The marks are undoable, and redactions stay pending until reviewed.
203
+ */
204
+
205
+ declare function useTextSelectionMarks(controller: AnnotationController): void;
206
+
207
+ /**
208
+ * Turn a text selection into marks. The browser selects over pdf.js's text layer; each page's
209
+ * share of the selection becomes one mark of normalised line boxes (page-relative, zoom-proof).
210
+ *
211
+ * `selectionToPageMarks` is pure so it can be tested without a layout engine; `readSelection`
212
+ * is the thin DOM side that measures a real selection.
213
+ */
214
+
215
+ /** One page's slice of a selection, in client (viewport) coordinates. */
216
+ interface PageSelection {
217
+ page: number;
218
+ /** The page's box on screen. */
219
+ box: PixelRect;
220
+ /** Client rects of the selected text on this page. */
221
+ rects: PixelRect[];
222
+ text: string;
223
+ }
224
+ interface PageTextMark {
225
+ page: number;
226
+ rects: NormRect[];
227
+ text: string;
228
+ }
229
+ declare function selectionToPageMarks(pages: PageSelection[]): PageTextMark[];
230
+ /** Read the live selection as per-page slices, using the overlays in `root` to find the pages. */
231
+ declare function readSelection(selection: Selection, root?: ParentNode): PageSelection[];
232
+
233
+ interface AnnotationPageOverlayProps {
234
+ controller: AnnotationController;
235
+ pageNumber: number;
236
+ /** Page width in PDF points, to size strokes like an export. Defaults to US Letter. */
237
+ pageWidthPt?: number;
238
+ }
239
+ declare function AnnotationPageOverlay({ controller, pageNumber, pageWidthPt, }: AnnotationPageOverlayProps): React.JSX.Element;
240
+
241
+ /**
242
+ * Pure geometry for moving and resizing a single-rectangle mark. Kept out of the component file so
243
+ * it can be tested and reused without a renderer.
244
+ */
245
+
246
+ type DragMode = 'move' | 'nw' | 'ne' | 'sw' | 'se';
247
+ /** The single rectangle of a mark that can be moved and resized, or null for multi-rect marks. */
248
+ declare function singleRect(a: Annotation): NormRect | null;
249
+ declare const patchForRect: (a: Annotation, rect: NormRect) => {
250
+ rects: NormRect[];
251
+ rect?: undefined;
252
+ } | {
253
+ rect: NormRect;
254
+ rects?: undefined;
255
+ };
256
+ /** Move or resize `origin` by a pointer delta given as fractions of the page. */
257
+ declare function dragRect(origin: NormRect, mode: DragMode, dx: number, dy: number): NormRect;
258
+
259
+ interface AnnotationToolbarProps {
260
+ controller: AnnotationController;
261
+ /** Show a Freeze button; the host opens its freeze dialog. */
262
+ onFreeze?: () => void;
263
+ className?: string;
264
+ }
265
+ declare function AnnotationToolbar({ controller, onFreeze, className }: AnnotationToolbarProps): React.JSX.Element;
266
+
267
+ /** Delete, Escape, undo and redo for the annotation layer. */
268
+
269
+ /** Delete, Escape, undo and redo, ignoring keystrokes meant for a text field. */
270
+ declare function useAnnotationShortcuts(controller: AnnotationController, enabled?: boolean): void;
271
+
272
+ interface FreezeChoices {
273
+ mode: 'vector' | 'image';
274
+ comments: 'omit' | 'markers' | 'appendix';
275
+ pendingRedactions: 'error' | 'burn';
276
+ }
277
+ interface FreezeDialogProps {
278
+ open: boolean;
279
+ onOpenChange: (open: boolean) => void;
280
+ controller: AnnotationController;
281
+ onConfirm: (choices: FreezeChoices) => void;
282
+ busy?: boolean;
283
+ progress?: {
284
+ done: number;
285
+ total: number;
286
+ } | null;
287
+ error?: string | null;
288
+ }
289
+ declare function FreezeDialog({ open, onOpenChange, controller, onConfirm, busy, progress, error, }: FreezeDialogProps): React.JSX.Element;
290
+
291
+ export { Annotation, type AnnotationAction, type AnnotationController, AnnotationLayer, AnnotationPageOverlay, type AnnotationPageOverlayProps, type AnnotationPatch, type AnnotationStore, type AnnotationTool, AnnotationToolbar, type AnnotationToolbarProps, CommentReply, DEFAULT_SETTINGS, type DragMode, type FreezeChoices, FreezeDialog, type FreezeDialogProps, HIGHLIGHT_COLORS, type LayerHistory, type LayerStatus, MARK_COLORS, type NewMark, NormRect, type PageSelection, type PageTextMark, type PixelRect, type PixelSize, REDACTION_REASONS, RedactionStatus, STAMP_PRESETS, type ToolSettings, type UseAnnotationLayerOptions, 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 };