ndf-viewer 0.0.0-stage → 0.0.1

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 (26) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +43 -2
  3. package/fesm2022/ndf-viewer-ndf-viewer-BAgO2ogB.mjs +102155 -0
  4. package/fesm2022/ndf-viewer-ndf-viewer-BAgO2ogB.mjs.map +1 -0
  5. package/fesm2022/ndf-viewer-pdf-content-edit-layer.component-BxGxvp4E.mjs +568 -0
  6. package/fesm2022/ndf-viewer-pdf-content-edit-layer.component-BxGxvp4E.mjs.map +1 -0
  7. package/fesm2022/ndf-viewer-pdf-form-builder-layer.component-bex5lE7H.mjs +345 -0
  8. package/fesm2022/ndf-viewer-pdf-form-builder-layer.component-bex5lE7H.mjs.map +1 -0
  9. package/fesm2022/ndf-viewer-pdf-form-layer.component-ALGQuDgp.mjs +135 -0
  10. package/fesm2022/ndf-viewer-pdf-form-layer.component-ALGQuDgp.mjs.map +1 -0
  11. package/fesm2022/ndf-viewer-pdf-measurement-layer.component-BYqtHqCw.mjs +522 -0
  12. package/fesm2022/ndf-viewer-pdf-measurement-layer.component-BYqtHqCw.mjs.map +1 -0
  13. package/fesm2022/ndf-viewer-pdf-pki-signature-layer.component-XsYMaROO.mjs +180 -0
  14. package/fesm2022/ndf-viewer-pdf-pki-signature-layer.component-XsYMaROO.mjs.map +1 -0
  15. package/fesm2022/ndf-viewer-pdf-redaction-layer.component-DbByg7KL.mjs +213 -0
  16. package/fesm2022/ndf-viewer-pdf-redaction-layer.component-DbByg7KL.mjs.map +1 -0
  17. package/fesm2022/ndf-viewer-pdf-signature-layer.component-BvcSi9rU.mjs +243 -0
  18. package/fesm2022/ndf-viewer-pdf-signature-layer.component-BvcSi9rU.mjs.map +1 -0
  19. package/fesm2022/ndf-viewer-pdf-video-layer.component-DSFsrClZ.mjs +149 -0
  20. package/fesm2022/ndf-viewer-pdf-video-layer.component-DSFsrClZ.mjs.map +1 -0
  21. package/fesm2022/ndf-viewer-pdf-xfa-layer.component-Dm27EJgs.mjs +58 -0
  22. package/fesm2022/ndf-viewer-pdf-xfa-layer.component-Dm27EJgs.mjs.map +1 -0
  23. package/fesm2022/ndf-viewer.mjs +2 -0
  24. package/fesm2022/ndf-viewer.mjs.map +1 -0
  25. package/package.json +32 -3
  26. package/types/ndf-viewer.d.ts +14289 -0
@@ -0,0 +1,568 @@
1
+ import * as i0 from '@angular/core';
2
+ import { input, output, viewChild, inject, ChangeDetectorRef, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import { z as readContentEditEditorText, A as writeContentEditEditorText, B as paragraphInlineEditorDirection, C as effectiveImageRectangle, D as paragraphEditRectangle, E as effectiveParagraphRectangle, F as contentEditTextDirection, G as inlineTextEditorShellStyle, H as textInlineEditorStyle, I as textEditCoverStyle, J as paragraphHighlightStyle, K as imageHighlightStyle, L as imageRectMoved, M as imageEditCoverStyle, N as editedOverlayStyle, O as inlineTextEditorMoveBarStyle, P as paragraphTextDirection, Q as contentEditMoveBarStyle, R as paragraphInlineEditorText, S as paragraphPrimaryEditText, T as contentEditHandleLayerStyle, k as clientToPagePoint, U as hitTestContentEditTarget, V as paragraphInlineEditorCommitText, t as translateRectangle, o as resizeRectangle, W as CONTENT_EDIT_HANDLE_SIZE_PX } from './ndf-viewer-ndf-viewer-BAgO2ogB.mjs';
4
+
5
+ const DRAG_THRESHOLD_PX = 4;
6
+ class PdfContentEditLayerComponent {
7
+ pageNumber = input.required(...(ngDevMode ? [{ debugName: "pageNumber" }] : /* istanbul ignore next */ []));
8
+ layout = input.required(...(ngDevMode ? [{ debugName: "layout" }] : /* istanbul ignore next */ []));
9
+ paragraphs = input([], ...(ngDevMode ? [{ debugName: "paragraphs" }] : /* istanbul ignore next */ []));
10
+ images = input([], ...(ngDevMode ? [{ debugName: "images" }] : /* istanbul ignore next */ []));
11
+ edits = input([], ...(ngDevMode ? [{ debugName: "edits" }] : /* istanbul ignore next */ []));
12
+ selectedId = input(null, ...(ngDevMode ? [{ debugName: "selectedId" }] : /* istanbul ignore next */ []));
13
+ editorEnabled = input(false, ...(ngDevMode ? [{ debugName: "editorEnabled" }] : /* istanbul ignore next */ []));
14
+ activeTool = input('select', ...(ngDevMode ? [{ debugName: "activeTool" }] : /* istanbul ignore next */ []));
15
+ contentEditState = input(null, ...(ngDevMode ? [{ debugName: "contentEditState" }] : /* istanbul ignore next */ []));
16
+ draftTargetId = input(null, ...(ngDevMode ? [{ debugName: "draftTargetId" }] : /* istanbul ignore next */ []));
17
+ draftText = input('', ...(ngDevMode ? [{ debugName: "draftText" }] : /* istanbul ignore next */ []));
18
+ layerChange = output();
19
+ textEditRequest = output();
20
+ imageSelected = output();
21
+ commitRequest = output();
22
+ /** Inline typing on the page — host updates draft / can apply. */
23
+ inlineTextChange = output();
24
+ /** Commit text typed on the page (blur / Enter). */
25
+ inlineTextCommit = output();
26
+ resizeHandles = [
27
+ 'nw',
28
+ 'n',
29
+ 'ne',
30
+ 'e',
31
+ 'se',
32
+ 's',
33
+ 'sw',
34
+ 'w',
35
+ ];
36
+ layerRef = viewChild('layer', ...(ngDevMode ? [{ debugName: "layerRef" }] : /* istanbul ignore next */ []));
37
+ inlineEditorRef = viewChild('inlineEditor', ...(ngDevMode ? [{ debugName: "inlineEditorRef" }] : /* istanbul ignore next */ []));
38
+ changeDetector = inject(ChangeDetectorRef);
39
+ dragMode = 'none';
40
+ dragTargetId = null;
41
+ dragHandle = null;
42
+ /**
43
+ * Drag origin in CLIENT pixels. Deltas are computed from client movement and
44
+ * scaled to page units, so the gesture stays correct even if the page
45
+ * scrolls under the pointer mid-drag (e.g. Chrome scroll anchoring when the
46
+ * side panel expands on selection).
47
+ */
48
+ dragStartClient = { x: 0, y: 0 };
49
+ dragStartRect = null;
50
+ dragStartLocalPoint = { x: 0, y: 0 };
51
+ focusInlineAfterRender = false;
52
+ lastFocusedId = null;
53
+ /** Set when Ctrl+Enter / Escape already handled the editor, so the following blur is a no-op. */
54
+ skipBlurCommit = false;
55
+ ngAfterViewChecked() {
56
+ const paragraph = this.selectedParagraph();
57
+ if (!paragraph) {
58
+ this.lastFocusedId = null;
59
+ return;
60
+ }
61
+ const editor = this.inlineEditorRef()?.nativeElement;
62
+ if (!editor) {
63
+ return;
64
+ }
65
+ if (this.lastFocusedId !== paragraph.id || document.activeElement !== editor) {
66
+ const next = this.inlineEditorText(paragraph);
67
+ if (readContentEditEditorText(editor) !== next) {
68
+ writeContentEditEditorText(editor, next);
69
+ }
70
+ }
71
+ if (!this.focusInlineAfterRender) {
72
+ return;
73
+ }
74
+ this.focusInlineAfterRender = false;
75
+ if (this.lastFocusedId === paragraph.id && document.activeElement === editor) {
76
+ return;
77
+ }
78
+ this.lastFocusedId = paragraph.id;
79
+ editor.focus();
80
+ const caretAtStart = paragraphInlineEditorDirection(paragraph) === 'rtl';
81
+ const range = document.createRange();
82
+ range.selectNodeContents(editor);
83
+ range.collapse(caretAtStart);
84
+ const selection = window.getSelection();
85
+ selection?.removeAllRanges();
86
+ selection?.addRange(range);
87
+ }
88
+ pageParagraphs() {
89
+ return this.paragraphs().filter((paragraph) => paragraph.pageNumber === this.pageNumber());
90
+ }
91
+ pageImages() {
92
+ return this.images().filter((image) => image.pageNumber === this.pageNumber());
93
+ }
94
+ pageEdits() {
95
+ return this.edits().filter((edit) => edit.pageNumber === this.pageNumber());
96
+ }
97
+ isSelected(id) {
98
+ return this.selectedId() === id;
99
+ }
100
+ showTextTargets() {
101
+ const tool = this.activeTool();
102
+ return tool === 'select' || tool === 'edit-text';
103
+ }
104
+ /** Hide scan overlays while the inline editor is open — avoids cluttering the page. */
105
+ showParagraphHighlights() {
106
+ return this.showTextTargets() && !(this.editorEnabled() && this.selectedParagraph());
107
+ }
108
+ showImageTargets() {
109
+ const tool = this.activeTool();
110
+ return tool === 'select' || tool === 'edit-image';
111
+ }
112
+ canResizeSelectedImage() {
113
+ return ((this.activeTool() === 'edit-image' || this.activeTool() === 'select') &&
114
+ !!this.selectedImage());
115
+ }
116
+ selectedImage() {
117
+ const id = this.selectedId();
118
+ if (!id) {
119
+ return null;
120
+ }
121
+ return this.pageImages().find((image) => image.id === id) ?? null;
122
+ }
123
+ selectedParagraph() {
124
+ const id = this.selectedId();
125
+ if (!id) {
126
+ return null;
127
+ }
128
+ return this.pageParagraphs().find((paragraph) => paragraph.id === id) ?? null;
129
+ }
130
+ imageDisplayRect(image) {
131
+ return effectiveImageRectangle(image, this.edits());
132
+ }
133
+ paragraphDisplayRect(paragraph) {
134
+ if (this.isSelected(paragraph.id) && this.editorEnabled()) {
135
+ return paragraphEditRectangle(paragraph);
136
+ }
137
+ return effectiveParagraphRectangle(paragraph, this.edits());
138
+ }
139
+ textReplaceEdit(paragraph) {
140
+ return (this.edits().find((edit) => edit.targetId === paragraph.id &&
141
+ edit.kind === 'text-replace' &&
142
+ edit.newText !== undefined) ?? null);
143
+ }
144
+ /** Show saved replacement text on-page while preview PDF reload is pending. */
145
+ showTextEditPreview(paragraph) {
146
+ if (this.isSelected(paragraph.id) && this.editorEnabled()) {
147
+ return false;
148
+ }
149
+ return this.textReplaceEdit(paragraph) !== null;
150
+ }
151
+ textPreviewContent(paragraph) {
152
+ return this.textReplaceEdit(paragraph).newText ?? '';
153
+ }
154
+ textPreviewDirection(paragraph) {
155
+ return contentEditTextDirection(this.textPreviewContent(paragraph));
156
+ }
157
+ textEditPreviewShellStyle(paragraph) {
158
+ const edit = this.textReplaceEdit(paragraph);
159
+ const rect = edit.newRectangle ?? paragraphEditRectangle(paragraph);
160
+ return inlineTextEditorShellStyle(rect, this.layout(), this.textPreviewDirection(paragraph), {
161
+ includeMoveBar: false,
162
+ });
163
+ }
164
+ textEditPreviewFieldStyle(paragraph) {
165
+ const edit = this.textReplaceEdit(paragraph);
166
+ const text = this.textPreviewContent(paragraph);
167
+ const rect = edit.newRectangle ?? paragraphEditRectangle(paragraph);
168
+ return {
169
+ ...textInlineEditorStyle(rect, this.layout(), {
170
+ text,
171
+ fontSize: edit.fontSize ?? paragraph.fontSize,
172
+ direction: this.textPreviewDirection(paragraph),
173
+ }),
174
+ border: this.isSelected(paragraph.id)
175
+ ? '2px solid #2563eb'
176
+ : '1px solid rgba(37, 99, 235, 0.35)',
177
+ pointerEvents: 'none',
178
+ };
179
+ }
180
+ textEditPreviewCoverStyle(paragraph) {
181
+ const edit = this.textReplaceEdit(paragraph);
182
+ const paint = edit.newRectangle ?? paragraphEditRectangle(paragraph);
183
+ return textEditCoverStyle(paint, this.layout(), edit.originalRectangle);
184
+ }
185
+ paragraphStyle(paragraph) {
186
+ const display = { ...paragraph, rectangle: this.paragraphDisplayRect(paragraph) };
187
+ return paragraphHighlightStyle(display, this.layout(), this.isSelected(paragraph.id));
188
+ }
189
+ imageStyle(image) {
190
+ const display = { ...image, rectangle: this.imageDisplayRect(image) };
191
+ return imageHighlightStyle(display, this.layout(), this.isSelected(image.id));
192
+ }
193
+ imageCoverStyle(image) {
194
+ const display = this.imageDisplayRect(image);
195
+ if (!imageRectMoved(image.rectangle, display)) {
196
+ return null;
197
+ }
198
+ return imageEditCoverStyle(image.rectangle, this.layout());
199
+ }
200
+ showEditOverlay(edit) {
201
+ if (edit.kind === 'text-replace' || edit.kind === 'text-delete') {
202
+ return false;
203
+ }
204
+ if (edit.kind === 'image-move' ||
205
+ edit.kind === 'image-resize' ||
206
+ edit.kind === 'image-replace') {
207
+ return false;
208
+ }
209
+ return true;
210
+ }
211
+ editOverlayStyle(edit) {
212
+ return editedOverlayStyle(edit, this.layout());
213
+ }
214
+ inlineEditorShellStyle(paragraph) {
215
+ return inlineTextEditorShellStyle(this.paragraphDisplayRect(paragraph), this.layout(), paragraphInlineEditorDirection(paragraph));
216
+ }
217
+ inlineEditorMoveBarStyle() {
218
+ return inlineTextEditorMoveBarStyle();
219
+ }
220
+ inlineEditorStyle(paragraph) {
221
+ const text = this.inlineEditorText(paragraph);
222
+ const direction = paragraphInlineEditorDirection(paragraph);
223
+ return {
224
+ ...textInlineEditorStyle(this.paragraphDisplayRect(paragraph), this.layout(), {
225
+ text,
226
+ fontSize: paragraph.fontSize,
227
+ direction,
228
+ }),
229
+ cursor: 'text',
230
+ };
231
+ }
232
+ textCoverStyle(paragraph) {
233
+ return textEditCoverStyle(paragraph.rectangle, this.layout());
234
+ }
235
+ paragraphDirection(paragraph) {
236
+ return paragraphInlineEditorDirection(paragraph);
237
+ }
238
+ paragraphLang(paragraph) {
239
+ return paragraphTextDirection(paragraph) === 'rtl' ? 'ar' : undefined;
240
+ }
241
+ imageMoveBarStyle(image) {
242
+ const style = contentEditMoveBarStyle(this.imageDisplayRect(image), this.layout());
243
+ return { ...style, backgroundColor: '#059669' };
244
+ }
245
+ inlineEditorText(paragraph) {
246
+ const logical = this.inlineEditorLogicalText(paragraph);
247
+ return paragraphInlineEditorText(paragraph, logical);
248
+ }
249
+ inlineEditorLogicalText(paragraph) {
250
+ if (this.draftTargetId() === paragraph.id) {
251
+ return this.draftText();
252
+ }
253
+ const edit = this.edits().find((entry) => entry.targetId === paragraph.id);
254
+ if (edit?.newText !== undefined) {
255
+ return edit.newText;
256
+ }
257
+ return paragraphPrimaryEditText(paragraph);
258
+ }
259
+ effectiveParagraphText(paragraph) {
260
+ const edit = this.edits().find((entry) => entry.targetId === paragraph.id);
261
+ return edit?.newText ?? paragraph.text;
262
+ }
263
+ handleStyle(image, handle) {
264
+ return contentEditHandleLayerStyle(this.imageDisplayRect(image), handle, this.layout());
265
+ }
266
+ layerCursor() {
267
+ const tool = this.activeTool();
268
+ if (tool === 'edit-text') {
269
+ return 'text';
270
+ }
271
+ if (tool === 'edit-image') {
272
+ return 'move';
273
+ }
274
+ return 'default';
275
+ }
276
+ onPointerDown(event) {
277
+ if (!this.editorEnabled() || event.button !== 0) {
278
+ return;
279
+ }
280
+ const target = event.target;
281
+ if (target?.closest('.pdf-content-edit-layer__inline-editor')) {
282
+ // Let the contenteditable receive the caret — do not capture.
283
+ return;
284
+ }
285
+ const state = this.contentEditState();
286
+ const layer = this.layerRef()?.nativeElement;
287
+ if (!state || !layer) {
288
+ return;
289
+ }
290
+ event.preventDefault();
291
+ event.stopPropagation();
292
+ layer.setPointerCapture(event.pointerId);
293
+ const point = clientToPagePoint(event.clientX, event.clientY, layer, this.layout());
294
+ this.dragStartClient = { x: event.clientX, y: event.clientY };
295
+ if (target?.closest('.pdf-content-edit-layer__move-bar--text')) {
296
+ const paragraph = this.selectedParagraph();
297
+ if (paragraph) {
298
+ this.beginPendingTextMove(paragraph);
299
+ }
300
+ return;
301
+ }
302
+ if (target?.closest('.pdf-content-edit-layer__move-bar--image')) {
303
+ const image = this.selectedImage();
304
+ if (image) {
305
+ this.beginPendingImageMove(image);
306
+ }
307
+ return;
308
+ }
309
+ const selectedImage = this.selectedImage();
310
+ if (selectedImage && this.canResizeSelectedImage()) {
311
+ const handle = this.hitTestHandle(event.clientX, event.clientY, selectedImage, layer);
312
+ if (handle) {
313
+ this.beginHandleDrag(selectedImage, handle, point);
314
+ return;
315
+ }
316
+ }
317
+ const paragraphs = this.showTextTargets()
318
+ ? this.pageParagraphs().map((paragraph) => ({
319
+ ...paragraph,
320
+ rectangle: this.paragraphDisplayRect(paragraph),
321
+ }))
322
+ : [];
323
+ const images = this.showImageTargets()
324
+ ? this.pageImages().map((image) => ({
325
+ ...image,
326
+ rectangle: this.imageDisplayRect(image),
327
+ }))
328
+ : [];
329
+ const hit = hitTestContentEditTarget(paragraphs, images, this.pageNumber(), point.x, point.y, this.selectedId());
330
+ if (hit?.kind === 'image') {
331
+ const image = this.images().find((entry) => entry.id === hit.id);
332
+ if (image) {
333
+ state.select(image.id);
334
+ this.beginPendingImageMove(image);
335
+ this.emitChange(state, 'edit-image');
336
+ this.imageSelected.emit(image);
337
+ }
338
+ return;
339
+ }
340
+ if (hit?.kind === 'paragraph') {
341
+ const paragraph = this.paragraphs().find((entry) => entry.id === hit.id);
342
+ if (paragraph) {
343
+ state.select(paragraph.id);
344
+ this.focusInlineAfterRender = true;
345
+ this.emitChange(state, 'edit-text');
346
+ this.textEditRequest.emit({ paragraph });
347
+ // Allow drag-to-move from the box if user starts dragging (pending).
348
+ this.beginPendingTextMove(paragraph);
349
+ }
350
+ return;
351
+ }
352
+ state.select(null);
353
+ this.emitChange(state);
354
+ }
355
+ onInlineInput(event, paragraph) {
356
+ const display = readContentEditEditorText(event.target);
357
+ const text = paragraphInlineEditorCommitText(paragraph, display);
358
+ this.inlineTextChange.emit({ targetId: paragraph.id, text });
359
+ }
360
+ onInlineKeydown(event, paragraph) {
361
+ if (event.key === 'Escape') {
362
+ event.preventDefault();
363
+ const editor = event.target;
364
+ writeContentEditEditorText(editor, paragraphInlineEditorText(paragraph));
365
+ this.inlineTextChange.emit({ targetId: paragraph.id, text: paragraph.text });
366
+ this.skipBlurCommit = true;
367
+ editor.blur();
368
+ return;
369
+ }
370
+ if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
371
+ event.preventDefault();
372
+ const display = readContentEditEditorText(event.target);
373
+ const text = paragraphInlineEditorCommitText(paragraph, display);
374
+ this.inlineTextCommit.emit({ paragraph, text });
375
+ this.skipBlurCommit = true;
376
+ event.target.blur();
377
+ }
378
+ }
379
+ onInlineBlur(event, paragraph) {
380
+ if (this.skipBlurCommit) {
381
+ this.skipBlurCommit = false;
382
+ return;
383
+ }
384
+ const display = readContentEditEditorText(event.target);
385
+ const text = paragraphInlineEditorCommitText(paragraph, display);
386
+ if (text !== this.effectiveParagraphText(paragraph)) {
387
+ this.inlineTextCommit.emit({ paragraph, text });
388
+ }
389
+ }
390
+ onPointerMove(event) {
391
+ const layer = this.layerRef()?.nativeElement;
392
+ const state = this.contentEditState();
393
+ if (!layer || !state || this.dragMode === 'none') {
394
+ return;
395
+ }
396
+ // Client-pixel deltas scaled to page units: immune to page scroll during drag.
397
+ const clientDx = event.clientX - this.dragStartClient.x;
398
+ const clientDy = event.clientY - this.dragStartClient.y;
399
+ const dx = clientDx * (this.layout().pageWidth / Math.max(layer.clientWidth, 1));
400
+ const dy = -clientDy * (this.layout().pageHeight / Math.max(layer.clientHeight, 1));
401
+ if (this.dragMode === 'pending-move-image' || this.dragMode === 'pending-move-text') {
402
+ if (Math.hypot(clientDx, clientDy) < DRAG_THRESHOLD_PX || !this.dragTargetId) {
403
+ return;
404
+ }
405
+ if (this.dragMode === 'pending-move-image') {
406
+ const image = this.images().find((entry) => entry.id === this.dragTargetId);
407
+ if (image) {
408
+ this.beginImageMove(image);
409
+ }
410
+ }
411
+ else {
412
+ const paragraph = this.paragraphs().find((entry) => entry.id === this.dragTargetId);
413
+ if (paragraph) {
414
+ this.beginTextMove(paragraph);
415
+ }
416
+ }
417
+ }
418
+ if (!this.dragTargetId || !this.dragStartRect) {
419
+ return;
420
+ }
421
+ if (this.dragMode === 'move-image') {
422
+ const image = this.images().find((entry) => entry.id === this.dragTargetId);
423
+ if (!image) {
424
+ return;
425
+ }
426
+ state.moveOrResizeImage(image, this.clampToPage(translateRectangle(this.dragStartRect, dx, dy)), 'image-move');
427
+ this.emitChange(state, 'edit-image');
428
+ return;
429
+ }
430
+ if (this.dragMode === 'move-text') {
431
+ const paragraph = this.paragraphs().find((entry) => entry.id === this.dragTargetId);
432
+ if (!paragraph) {
433
+ return;
434
+ }
435
+ const text = this.draftTargetId() === paragraph.id
436
+ ? this.draftText()
437
+ : (this.edits().find((edit) => edit.targetId === paragraph.id)?.newText ??
438
+ paragraph.text);
439
+ state.moveText(paragraph, this.clampToPage(translateRectangle(this.dragStartRect, dx, dy)), text);
440
+ this.emitChange(state, 'edit-text');
441
+ return;
442
+ }
443
+ if (this.dragMode === 'resize' && this.dragHandle) {
444
+ const image = this.images().find((entry) => entry.id === this.dragTargetId);
445
+ if (!image) {
446
+ return;
447
+ }
448
+ const layout = this.layout();
449
+ const point = {
450
+ x: Math.min(Math.max(this.dragStartLocalPoint.x + dx, 0), layout.pageWidth),
451
+ y: Math.min(Math.max(this.dragStartLocalPoint.y + dy, 0), layout.pageHeight),
452
+ };
453
+ state.moveOrResizeImage(image, resizeRectangle(this.dragStartRect, this.dragHandle, this.dragStartLocalPoint, point), 'image-resize');
454
+ this.emitChange(state, 'edit-image');
455
+ }
456
+ }
457
+ onPointerUp(event) {
458
+ const layer = this.layerRef()?.nativeElement;
459
+ if (layer?.hasPointerCapture(event.pointerId)) {
460
+ layer.releasePointerCapture(event.pointerId);
461
+ }
462
+ const dragMode = this.dragMode;
463
+ const dragTargetId = this.dragTargetId;
464
+ const dragStartRect = this.dragStartRect;
465
+ this.resetDrag();
466
+ const shouldCommit = dragMode === 'move-image' || dragMode === 'move-text' || dragMode === 'resize';
467
+ if (!shouldCommit) {
468
+ return;
469
+ }
470
+ const state = this.contentEditState();
471
+ if (state && dragTargetId && dragStartRect) {
472
+ const pending = state.list().find((edit) => edit.targetId === dragTargetId);
473
+ const nextRect = pending?.newRectangle;
474
+ if (nextRect && !imageRectMoved(dragStartRect, nextRect, 0.5)) {
475
+ if (pending) {
476
+ state.remove(pending.id);
477
+ this.emitChange(state);
478
+ }
479
+ return;
480
+ }
481
+ }
482
+ this.commitRequest.emit();
483
+ }
484
+ /** Keep a dragged rectangle fully on the page. */
485
+ clampToPage(rect) {
486
+ const layout = this.layout();
487
+ let dx = 0;
488
+ let dy = 0;
489
+ if (rect.left < 0) {
490
+ dx = -rect.left;
491
+ }
492
+ else if (rect.right > layout.pageWidth) {
493
+ dx = layout.pageWidth - rect.right;
494
+ }
495
+ if (rect.bottom < 0) {
496
+ dy = -rect.bottom;
497
+ }
498
+ else if (rect.top > layout.pageHeight) {
499
+ dy = layout.pageHeight - rect.top;
500
+ }
501
+ return dx === 0 && dy === 0 ? rect : translateRectangle(rect, dx, dy);
502
+ }
503
+ hitTestHandle(clientX, clientY, image, layer) {
504
+ const rect = this.imageDisplayRect(image);
505
+ const bounds = layer.getBoundingClientRect();
506
+ const half = CONTENT_EDIT_HANDLE_SIZE_PX / 2;
507
+ for (const handle of this.resizeHandles) {
508
+ const style = contentEditHandleLayerStyle(rect, handle, this.layout());
509
+ const hx = bounds.left + Number.parseFloat(style['left'] ?? '0') + half;
510
+ const hy = bounds.top + Number.parseFloat(style['top'] ?? '0') + half;
511
+ if (Math.hypot(clientX - hx, clientY - hy) <= CONTENT_EDIT_HANDLE_SIZE_PX) {
512
+ return handle;
513
+ }
514
+ }
515
+ return null;
516
+ }
517
+ beginPendingImageMove(image) {
518
+ this.dragMode = 'pending-move-image';
519
+ this.dragTargetId = image.id;
520
+ this.dragStartRect = this.imageDisplayRect(image);
521
+ }
522
+ beginPendingTextMove(paragraph) {
523
+ this.dragMode = 'pending-move-text';
524
+ this.dragTargetId = paragraph.id;
525
+ this.dragStartRect = this.paragraphDisplayRect(paragraph);
526
+ }
527
+ beginImageMove(image) {
528
+ this.dragMode = 'move-image';
529
+ this.dragTargetId = image.id;
530
+ this.dragStartRect = this.imageDisplayRect(image);
531
+ }
532
+ beginTextMove(paragraph) {
533
+ this.dragMode = 'move-text';
534
+ this.dragTargetId = paragraph.id;
535
+ this.dragStartRect = this.paragraphDisplayRect(paragraph);
536
+ }
537
+ beginHandleDrag(image, handle, point) {
538
+ this.dragMode = 'resize';
539
+ this.dragTargetId = image.id;
540
+ this.dragHandle = handle;
541
+ this.dragStartRect = this.imageDisplayRect(image);
542
+ this.dragStartLocalPoint = point;
543
+ }
544
+ resetDrag() {
545
+ this.dragMode = 'none';
546
+ this.dragTargetId = null;
547
+ this.dragHandle = null;
548
+ this.dragStartRect = null;
549
+ this.dragStartLocalPoint = { x: 0, y: 0 };
550
+ this.changeDetector.markForCheck();
551
+ }
552
+ emitChange(state, preferredTool) {
553
+ this.layerChange.emit({
554
+ selectedId: state.getSelectedId(),
555
+ edits: state.list(),
556
+ preferredTool,
557
+ });
558
+ }
559
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: PdfContentEditLayerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
560
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.17", type: PdfContentEditLayerComponent, isStandalone: true, selector: "pdf-content-edit-layer", inputs: { pageNumber: { classPropertyName: "pageNumber", publicName: "pageNumber", isSignal: true, isRequired: true, transformFunction: null }, layout: { classPropertyName: "layout", publicName: "layout", isSignal: true, isRequired: true, transformFunction: null }, paragraphs: { classPropertyName: "paragraphs", publicName: "paragraphs", isSignal: true, isRequired: false, transformFunction: null }, images: { classPropertyName: "images", publicName: "images", isSignal: true, isRequired: false, transformFunction: null }, edits: { classPropertyName: "edits", publicName: "edits", isSignal: true, isRequired: false, transformFunction: null }, selectedId: { classPropertyName: "selectedId", publicName: "selectedId", isSignal: true, isRequired: false, transformFunction: null }, editorEnabled: { classPropertyName: "editorEnabled", publicName: "editorEnabled", isSignal: true, isRequired: false, transformFunction: null }, activeTool: { classPropertyName: "activeTool", publicName: "activeTool", isSignal: true, isRequired: false, transformFunction: null }, contentEditState: { classPropertyName: "contentEditState", publicName: "contentEditState", isSignal: true, isRequired: false, transformFunction: null }, draftTargetId: { classPropertyName: "draftTargetId", publicName: "draftTargetId", isSignal: true, isRequired: false, transformFunction: null }, draftText: { classPropertyName: "draftText", publicName: "draftText", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { layerChange: "layerChange", textEditRequest: "textEditRequest", imageSelected: "imageSelected", commitRequest: "commitRequest", inlineTextChange: "inlineTextChange", inlineTextCommit: "inlineTextCommit" }, viewQueries: [{ propertyName: "layerRef", first: true, predicate: ["layer"], descendants: true, isSignal: true }, { propertyName: "inlineEditorRef", first: true, predicate: ["inlineEditor"], descendants: true, isSignal: true }], ngImport: i0, template: "<div\n #layer\n class=\"pdf-content-edit-layer\"\n [style.width.px]=\"layout().cssWidth\"\n [style.height.px]=\"layout().cssHeight\"\n [style.cursor]=\"layerCursor()\"\n (pointerdown)=\"onPointerDown($event)\"\n (pointermove)=\"onPointerMove($event)\"\n (pointerup)=\"onPointerUp($event)\"\n (pointercancel)=\"onPointerUp($event)\"\n>\n @if (showParagraphHighlights()) {\n @for (paragraph of pageParagraphs(); track paragraph.id) {\n @if (!isSelected(paragraph.id)) {\n <div class=\"pdf-content-edit-layer__paragraph\" [style]=\"paragraphStyle(paragraph)\"></div>\n }\n }\n }\n\n @if (showImageTargets()) {\n @for (image of pageImages(); track image.id) {\n @if (imageCoverStyle(image); as cover) {\n <div class=\"pdf-content-edit-layer__image-cover\" [style]=\"cover\"></div>\n }\n <div class=\"pdf-content-edit-layer__image\" [style]=\"imageStyle(image)\"></div>\n }\n }\n\n @for (edit of pageEdits(); track edit.id) {\n @if (showEditOverlay(edit)) {\n <div class=\"pdf-content-edit-layer__overlay\" [style]=\"editOverlayStyle(edit)\"></div>\n }\n }\n\n @for (paragraph of pageParagraphs(); track paragraph.id) {\n @if (showTextEditPreview(paragraph)) {\n <div\n class=\"pdf-content-edit-layer__text-cover\"\n [style]=\"textEditPreviewCoverStyle(paragraph)\"\n ></div>\n <div\n class=\"pdf-content-edit-layer__inline-shell\"\n [style]=\"textEditPreviewShellStyle(paragraph)\"\n >\n <div\n class=\"pdf-content-edit-layer__text-preview\"\n [class.pdf-content-edit-layer__text-preview--rtl]=\"\n textPreviewDirection(paragraph) === 'rtl'\n \"\n [style]=\"textEditPreviewFieldStyle(paragraph)\"\n [attr.dir]=\"textPreviewDirection(paragraph)\"\n [attr.lang]=\"textPreviewDirection(paragraph) === 'rtl' ? 'ar' : null\"\n >\n {{ textPreviewContent(paragraph) }}\n </div>\n </div>\n }\n }\n\n @if (editorEnabled() && selectedParagraph(); as paragraph) {\n <div class=\"pdf-content-edit-layer__text-cover\" [style]=\"textCoverStyle(paragraph)\"></div>\n <div class=\"pdf-content-edit-layer__inline-shell\" [style]=\"inlineEditorShellStyle(paragraph)\">\n <div\n class=\"pdf-content-edit-layer__move-bar pdf-content-edit-layer__move-bar--text\"\n [style]=\"inlineEditorMoveBarStyle()\"\n title=\"Drag to move text\"\n >\n Move\n </div>\n <div\n #inlineEditor\n class=\"pdf-content-edit-layer__inline-editor\"\n [class.pdf-content-edit-layer__inline-editor--rtl]=\"paragraphDirection(paragraph) === 'rtl'\"\n [style]=\"inlineEditorStyle(paragraph)\"\n contenteditable=\"true\"\n [attr.dir]=\"paragraphDirection(paragraph)\"\n [attr.lang]=\"paragraphLang(paragraph)\"\n spellcheck=\"false\"\n role=\"textbox\"\n [attr.aria-label]=\"'Edit text on page ' + paragraph.pageNumber\"\n (pointerdown)=\"$event.stopPropagation()\"\n (input)=\"onInlineInput($event, paragraph)\"\n (keydown)=\"onInlineKeydown($event, paragraph)\"\n (blur)=\"onInlineBlur($event, paragraph)\"\n ></div>\n </div>\n }\n\n @if (editorEnabled() && selectedImage(); as image) {\n <div\n class=\"pdf-content-edit-layer__move-bar pdf-content-edit-layer__move-bar--image\"\n [style]=\"imageMoveBarStyle(image)\"\n title=\"Drag to move image\"\n >\n Move\n </div>\n }\n\n @if (editorEnabled() && canResizeSelectedImage()) {\n @if (selectedImage(); as image) {\n @for (handle of resizeHandles; track handle) {\n <div class=\"pdf-content-edit-layer__handle\" [style]=\"handleStyle(image, handle)\"></div>\n }\n }\n }\n</div>\n", styles: [".pdf-content-edit-layer{position:absolute;inset:0;z-index:5;touch-action:none}.pdf-content-edit-layer__paragraph,.pdf-content-edit-layer__image,.pdf-content-edit-layer__overlay,.pdf-content-edit-layer__image-cover,.pdf-content-edit-layer__text-preview,.pdf-content-edit-layer__text-cover,.pdf-content-edit-layer__inline-editor,.pdf-content-edit-layer__move-bar{position:absolute;box-sizing:border-box}.pdf-content-edit-layer__overlay{pointer-events:none}.pdf-content-edit-layer__paragraph{pointer-events:auto;cursor:text}.pdf-content-edit-layer__image{pointer-events:auto;cursor:move}.pdf-content-edit-layer__image-cover,.pdf-content-edit-layer__text-cover,.pdf-content-edit-layer__text-preview{pointer-events:none;color-scheme:light}.pdf-content-edit-layer__inline-shell .pdf-content-edit-layer__text-preview{margin-top:0}.pdf-content-edit-layer__text-preview--rtl{direction:rtl;text-align:right;unicode-bidi:plaintext}.pdf-content-edit-layer__inline-shell{position:absolute;box-sizing:border-box}.pdf-content-edit-layer__inline-editor{pointer-events:auto;overflow:hidden;white-space:pre;overflow-wrap:normal;word-break:keep-all;caret-color:#111;color-scheme:light;z-index:6}.pdf-content-edit-layer__inline-editor--rtl{direction:rtl;text-align:right;unicode-bidi:plaintext}.pdf-content-edit-layer__inline-editor:focus{box-shadow:0 0 0 2px #2563eb59}.pdf-content-edit-layer__move-bar{display:flex;align-items:center;justify-content:center;color:#fff;font-size:10px;font-weight:600;letter-spacing:.02em;-webkit-user-select:none;user-select:none;pointer-events:auto}.pdf-content-edit-layer__handle{position:absolute;box-sizing:border-box;background:#059669;border:2px solid #fff;border-radius:3px;box-shadow:0 0 0 1px #059669e6;z-index:6;pointer-events:auto}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
561
+ }
562
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: PdfContentEditLayerComponent, decorators: [{
563
+ type: Component,
564
+ args: [{ selector: 'pdf-content-edit-layer', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, template: "<div\n #layer\n class=\"pdf-content-edit-layer\"\n [style.width.px]=\"layout().cssWidth\"\n [style.height.px]=\"layout().cssHeight\"\n [style.cursor]=\"layerCursor()\"\n (pointerdown)=\"onPointerDown($event)\"\n (pointermove)=\"onPointerMove($event)\"\n (pointerup)=\"onPointerUp($event)\"\n (pointercancel)=\"onPointerUp($event)\"\n>\n @if (showParagraphHighlights()) {\n @for (paragraph of pageParagraphs(); track paragraph.id) {\n @if (!isSelected(paragraph.id)) {\n <div class=\"pdf-content-edit-layer__paragraph\" [style]=\"paragraphStyle(paragraph)\"></div>\n }\n }\n }\n\n @if (showImageTargets()) {\n @for (image of pageImages(); track image.id) {\n @if (imageCoverStyle(image); as cover) {\n <div class=\"pdf-content-edit-layer__image-cover\" [style]=\"cover\"></div>\n }\n <div class=\"pdf-content-edit-layer__image\" [style]=\"imageStyle(image)\"></div>\n }\n }\n\n @for (edit of pageEdits(); track edit.id) {\n @if (showEditOverlay(edit)) {\n <div class=\"pdf-content-edit-layer__overlay\" [style]=\"editOverlayStyle(edit)\"></div>\n }\n }\n\n @for (paragraph of pageParagraphs(); track paragraph.id) {\n @if (showTextEditPreview(paragraph)) {\n <div\n class=\"pdf-content-edit-layer__text-cover\"\n [style]=\"textEditPreviewCoverStyle(paragraph)\"\n ></div>\n <div\n class=\"pdf-content-edit-layer__inline-shell\"\n [style]=\"textEditPreviewShellStyle(paragraph)\"\n >\n <div\n class=\"pdf-content-edit-layer__text-preview\"\n [class.pdf-content-edit-layer__text-preview--rtl]=\"\n textPreviewDirection(paragraph) === 'rtl'\n \"\n [style]=\"textEditPreviewFieldStyle(paragraph)\"\n [attr.dir]=\"textPreviewDirection(paragraph)\"\n [attr.lang]=\"textPreviewDirection(paragraph) === 'rtl' ? 'ar' : null\"\n >\n {{ textPreviewContent(paragraph) }}\n </div>\n </div>\n }\n }\n\n @if (editorEnabled() && selectedParagraph(); as paragraph) {\n <div class=\"pdf-content-edit-layer__text-cover\" [style]=\"textCoverStyle(paragraph)\"></div>\n <div class=\"pdf-content-edit-layer__inline-shell\" [style]=\"inlineEditorShellStyle(paragraph)\">\n <div\n class=\"pdf-content-edit-layer__move-bar pdf-content-edit-layer__move-bar--text\"\n [style]=\"inlineEditorMoveBarStyle()\"\n title=\"Drag to move text\"\n >\n Move\n </div>\n <div\n #inlineEditor\n class=\"pdf-content-edit-layer__inline-editor\"\n [class.pdf-content-edit-layer__inline-editor--rtl]=\"paragraphDirection(paragraph) === 'rtl'\"\n [style]=\"inlineEditorStyle(paragraph)\"\n contenteditable=\"true\"\n [attr.dir]=\"paragraphDirection(paragraph)\"\n [attr.lang]=\"paragraphLang(paragraph)\"\n spellcheck=\"false\"\n role=\"textbox\"\n [attr.aria-label]=\"'Edit text on page ' + paragraph.pageNumber\"\n (pointerdown)=\"$event.stopPropagation()\"\n (input)=\"onInlineInput($event, paragraph)\"\n (keydown)=\"onInlineKeydown($event, paragraph)\"\n (blur)=\"onInlineBlur($event, paragraph)\"\n ></div>\n </div>\n }\n\n @if (editorEnabled() && selectedImage(); as image) {\n <div\n class=\"pdf-content-edit-layer__move-bar pdf-content-edit-layer__move-bar--image\"\n [style]=\"imageMoveBarStyle(image)\"\n title=\"Drag to move image\"\n >\n Move\n </div>\n }\n\n @if (editorEnabled() && canResizeSelectedImage()) {\n @if (selectedImage(); as image) {\n @for (handle of resizeHandles; track handle) {\n <div class=\"pdf-content-edit-layer__handle\" [style]=\"handleStyle(image, handle)\"></div>\n }\n }\n }\n</div>\n", styles: [".pdf-content-edit-layer{position:absolute;inset:0;z-index:5;touch-action:none}.pdf-content-edit-layer__paragraph,.pdf-content-edit-layer__image,.pdf-content-edit-layer__overlay,.pdf-content-edit-layer__image-cover,.pdf-content-edit-layer__text-preview,.pdf-content-edit-layer__text-cover,.pdf-content-edit-layer__inline-editor,.pdf-content-edit-layer__move-bar{position:absolute;box-sizing:border-box}.pdf-content-edit-layer__overlay{pointer-events:none}.pdf-content-edit-layer__paragraph{pointer-events:auto;cursor:text}.pdf-content-edit-layer__image{pointer-events:auto;cursor:move}.pdf-content-edit-layer__image-cover,.pdf-content-edit-layer__text-cover,.pdf-content-edit-layer__text-preview{pointer-events:none;color-scheme:light}.pdf-content-edit-layer__inline-shell .pdf-content-edit-layer__text-preview{margin-top:0}.pdf-content-edit-layer__text-preview--rtl{direction:rtl;text-align:right;unicode-bidi:plaintext}.pdf-content-edit-layer__inline-shell{position:absolute;box-sizing:border-box}.pdf-content-edit-layer__inline-editor{pointer-events:auto;overflow:hidden;white-space:pre;overflow-wrap:normal;word-break:keep-all;caret-color:#111;color-scheme:light;z-index:6}.pdf-content-edit-layer__inline-editor--rtl{direction:rtl;text-align:right;unicode-bidi:plaintext}.pdf-content-edit-layer__inline-editor:focus{box-shadow:0 0 0 2px #2563eb59}.pdf-content-edit-layer__move-bar{display:flex;align-items:center;justify-content:center;color:#fff;font-size:10px;font-weight:600;letter-spacing:.02em;-webkit-user-select:none;user-select:none;pointer-events:auto}.pdf-content-edit-layer__handle{position:absolute;box-sizing:border-box;background:#059669;border:2px solid #fff;border-radius:3px;box-shadow:0 0 0 1px #059669e6;z-index:6;pointer-events:auto}\n"] }]
565
+ }], propDecorators: { pageNumber: [{ type: i0.Input, args: [{ isSignal: true, alias: "pageNumber", required: true }] }], layout: [{ type: i0.Input, args: [{ isSignal: true, alias: "layout", required: true }] }], paragraphs: [{ type: i0.Input, args: [{ isSignal: true, alias: "paragraphs", required: false }] }], images: [{ type: i0.Input, args: [{ isSignal: true, alias: "images", required: false }] }], edits: [{ type: i0.Input, args: [{ isSignal: true, alias: "edits", required: false }] }], selectedId: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedId", required: false }] }], editorEnabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "editorEnabled", required: false }] }], activeTool: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeTool", required: false }] }], contentEditState: [{ type: i0.Input, args: [{ isSignal: true, alias: "contentEditState", required: false }] }], draftTargetId: [{ type: i0.Input, args: [{ isSignal: true, alias: "draftTargetId", required: false }] }], draftText: [{ type: i0.Input, args: [{ isSignal: true, alias: "draftText", required: false }] }], layerChange: [{ type: i0.Output, args: ["layerChange"] }], textEditRequest: [{ type: i0.Output, args: ["textEditRequest"] }], imageSelected: [{ type: i0.Output, args: ["imageSelected"] }], commitRequest: [{ type: i0.Output, args: ["commitRequest"] }], inlineTextChange: [{ type: i0.Output, args: ["inlineTextChange"] }], inlineTextCommit: [{ type: i0.Output, args: ["inlineTextCommit"] }], layerRef: [{ type: i0.ViewChild, args: ['layer', { isSignal: true }] }], inlineEditorRef: [{ type: i0.ViewChild, args: ['inlineEditor', { isSignal: true }] }] } });
566
+
567
+ export { PdfContentEditLayerComponent };
568
+ //# sourceMappingURL=ndf-viewer-pdf-content-edit-layer.component-BxGxvp4E.mjs.map