kviewer 0.2.1 → 0.2.2

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 (107) hide show
  1. package/README.md +19 -0
  2. package/dist/module.d.mts +8 -1
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +25 -3
  5. package/dist/runtime/annotation/engine/canvas-resolution.d.ts +7 -0
  6. package/dist/runtime/annotation/engine/canvas-resolution.js +21 -0
  7. package/dist/runtime/annotation/engine/editor/editor.d.ts +5 -0
  8. package/dist/runtime/annotation/engine/editor/editor.js +14 -0
  9. package/dist/runtime/annotation/engine/editor/selector.d.ts +13 -1
  10. package/dist/runtime/annotation/engine/editor/selector.js +60 -8
  11. package/dist/runtime/annotation/engine/painter.d.ts +31 -0
  12. package/dist/runtime/annotation/engine/painter.js +88 -2
  13. package/dist/runtime/annotation/engine/store.js +3 -0
  14. package/dist/runtime/annotation/engine/tools/arrow.js +0 -1
  15. package/dist/runtime/annotation/engine/tools/circle.js +0 -2
  16. package/dist/runtime/annotation/engine/tools/free-highlight.js +0 -2
  17. package/dist/runtime/annotation/engine/tools/freehand.js +0 -2
  18. package/dist/runtime/annotation/engine/tools/rectangle.js +0 -2
  19. package/dist/runtime/annotation/engine/types.d.ts +5 -0
  20. package/dist/runtime/annotation/font-style.d.ts +15 -0
  21. package/dist/runtime/annotation/font-style.js +19 -0
  22. package/dist/runtime/annotation/parsers/extractCheckboxStyles.d.ts +8 -0
  23. package/dist/runtime/annotation/parsers/extractCheckboxStyles.js +24 -1
  24. package/dist/runtime/annotation/pdf-export/annotation-flags.d.ts +8 -0
  25. package/dist/runtime/annotation/pdf-export/annotation-flags.js +5 -0
  26. package/dist/runtime/annotation/pdf-export/export-form-fields.js +3 -1
  27. package/dist/runtime/annotation/pdf-export/export.js +13 -1
  28. package/dist/runtime/annotation/pdf-export/parse_circle.js +3 -0
  29. package/dist/runtime/annotation/pdf-export/parse_freetext.js +31 -19
  30. package/dist/runtime/annotation/pdf-export/parse_highlight.js +3 -0
  31. package/dist/runtime/annotation/pdf-export/parse_ink.js +5 -1
  32. package/dist/runtime/annotation/pdf-export/parse_line.js +5 -1
  33. package/dist/runtime/annotation/pdf-export/parse_polyline.js +5 -1
  34. package/dist/runtime/annotation/pdf-export/parse_square.js +3 -0
  35. package/dist/runtime/annotation/pdf-export/parse_stamp.js +4 -2
  36. package/dist/runtime/annotation/pdf-export/parse_strikeout.js +3 -0
  37. package/dist/runtime/annotation/pdf-export/parse_text.js +3 -0
  38. package/dist/runtime/annotation/pdf-export/parse_underline.js +3 -0
  39. package/dist/runtime/annotation/pdf-export/unicode-font.d.ts +5 -0
  40. package/dist/runtime/annotation/pdf-export/unicode-font.js +31 -0
  41. package/dist/runtime/annotation/pdf-export/winansi.d.ts +17 -0
  42. package/dist/runtime/annotation/pdf-export/winansi.js +77 -0
  43. package/dist/runtime/annotation/pdf-import/decode_circle.js +0 -1
  44. package/dist/runtime/annotation/pdf-import/decode_ink.js +0 -1
  45. package/dist/runtime/annotation/pdf-import/decode_line.js +0 -1
  46. package/dist/runtime/annotation/pdf-import/decode_square.js +0 -1
  47. package/dist/runtime/annotation/pdf-import/extract_stamp_appearance.d.ts +12 -0
  48. package/dist/runtime/annotation/pdf-import/extract_stamp_appearance.js +17 -4
  49. package/dist/runtime/annotation/pdf-import/types.d.ts +2 -0
  50. package/dist/runtime/assets/fonts/LICENSE-LiberationSans +102 -0
  51. package/dist/runtime/assets/fonts/LiberationSans-Regular.ttf +0 -0
  52. package/dist/runtime/assets/kviewer.css +1 -1
  53. package/dist/runtime/components/AnnotationToolbar.vue +6 -4
  54. package/dist/runtime/components/PdfPage.d.vue.ts +16 -0
  55. package/dist/runtime/components/PdfPage.vue +170 -9
  56. package/dist/runtime/components/PdfPage.vue.d.ts +16 -0
  57. package/dist/runtime/components/PerfHud.d.vue.ts +3 -0
  58. package/dist/runtime/components/PerfHud.vue +97 -0
  59. package/dist/runtime/components/PerfHud.vue.d.ts +3 -0
  60. package/dist/runtime/components/ToolButton.vue +4 -1
  61. package/dist/runtime/components/Viewer.d.vue.ts +25 -2
  62. package/dist/runtime/components/Viewer.vue +173 -11
  63. package/dist/runtime/components/Viewer.vue.d.ts +25 -2
  64. package/dist/runtime/components/ViewerBar.d.vue.ts +21 -1
  65. package/dist/runtime/components/ViewerBar.vue +183 -101
  66. package/dist/runtime/components/ViewerBar.vue.d.ts +21 -1
  67. package/dist/runtime/components/ViewerTabs.d.vue.ts +10 -2
  68. package/dist/runtime/components/ViewerTabs.vue +13 -2
  69. package/dist/runtime/components/ViewerTabs.vue.d.ts +10 -2
  70. package/dist/runtime/components/form-fields/FormDropdown.vue +50 -19
  71. package/dist/runtime/components/form-fields/FormSignatureField.vue +4 -2
  72. package/dist/runtime/components/form-fields/FormTextField.vue +7 -18
  73. package/dist/runtime/components/modals/FreeTextModal.vue +6 -4
  74. package/dist/runtime/components/modals/SignatureDrawModal.vue +6 -4
  75. package/dist/runtime/components/panels/PlacedFieldSidebar.vue +67 -50
  76. package/dist/runtime/components/panels/SignaturePicker.vue +6 -4
  77. package/dist/runtime/components/panels/StampPicker.vue +3 -1
  78. package/dist/runtime/components/tools/AnnotationToolButton.d.vue.ts +10 -0
  79. package/dist/runtime/components/tools/AnnotationToolButton.vue +33 -0
  80. package/dist/runtime/components/tools/AnnotationToolButton.vue.d.ts +10 -0
  81. package/dist/runtime/components/tools/MarqueeTool.vue +3 -1
  82. package/dist/runtime/components/tools/PageSettings.vue +13 -11
  83. package/dist/runtime/components/tools/SearchTool.vue +12 -10
  84. package/dist/runtime/components/tools/ToolProperties.vue +7 -5
  85. package/dist/runtime/components/tools/ToolbarMenu.d.vue.ts +9 -0
  86. package/dist/runtime/components/tools/ToolbarMenu.vue +79 -0
  87. package/dist/runtime/components/tools/ToolbarMenu.vue.d.ts +9 -0
  88. package/dist/runtime/components/tools/ZoomControls.vue +17 -9
  89. package/dist/runtime/composables/canvas-limits.d.ts +22 -0
  90. package/dist/runtime/composables/canvas-limits.js +10 -0
  91. package/dist/runtime/composables/useFormFields.d.ts +6 -0
  92. package/dist/runtime/composables/useFormFields.js +28 -0
  93. package/dist/runtime/composables/useInertiaPanzoom.d.ts +10 -0
  94. package/dist/runtime/composables/useInertiaPanzoom.js +57 -10
  95. package/dist/runtime/composables/useKviewerI18n.d.ts +18 -0
  96. package/dist/runtime/composables/useKviewerI18n.js +29 -0
  97. package/dist/runtime/composables/useScriptingManager.d.ts +8 -4
  98. package/dist/runtime/composables/useScriptingManager.js +2 -0
  99. package/dist/runtime/composables/useViewerState.d.ts +4 -0
  100. package/dist/runtime/composables/useViewerState.js +8 -0
  101. package/dist/runtime/i18n/messages.d.ts +252 -0
  102. package/dist/runtime/i18n/messages.js +249 -0
  103. package/dist/runtime/public-types.d.ts +2 -0
  104. package/dist/runtime/toolbar-tools.d.ts +54 -0
  105. package/dist/runtime/toolbar-tools.js +79 -0
  106. package/dist/types.d.mts +1 -1
  107. package/package.json +14 -31
@@ -0,0 +1,77 @@
1
+ const CP1252_SPECIALS = /* @__PURE__ */ new Map([
2
+ [8364, 128],
3
+ // €
4
+ [8218, 130],
5
+ // ‚
6
+ [402, 131],
7
+ // ƒ
8
+ [8222, 132],
9
+ // „
10
+ [8230, 133],
11
+ // …
12
+ [8224, 134],
13
+ // †
14
+ [8225, 135],
15
+ // ‡
16
+ [710, 136],
17
+ // ˆ
18
+ [8240, 137],
19
+ // ‰
20
+ [352, 138],
21
+ // Š
22
+ [8249, 139],
23
+ // ‹
24
+ [338, 140],
25
+ // Œ
26
+ [381, 142],
27
+ // Ž
28
+ [8216, 145],
29
+ // '
30
+ [8217, 146],
31
+ // '
32
+ [8220, 147],
33
+ // "
34
+ [8221, 148],
35
+ // "
36
+ [8226, 149],
37
+ // •
38
+ [8211, 150],
39
+ // –
40
+ [8212, 151],
41
+ // —
42
+ [732, 152],
43
+ // ˜
44
+ [8482, 153],
45
+ // ™
46
+ [353, 154],
47
+ // š
48
+ [8250, 155],
49
+ // ›
50
+ [339, 156],
51
+ // œ
52
+ [382, 158],
53
+ // ž
54
+ [376, 159]
55
+ // Ÿ
56
+ ]);
57
+ function winAnsiByte(codePoint) {
58
+ if (codePoint <= 127) return codePoint;
59
+ if (codePoint >= 160 && codePoint <= 255) return codePoint;
60
+ return CP1252_SPECIALS.get(codePoint) ?? null;
61
+ }
62
+ export function isWinAnsiEncodable(text) {
63
+ for (const char of text) {
64
+ if (winAnsiByte(char.codePointAt(0)) === null) return false;
65
+ }
66
+ return true;
67
+ }
68
+ export function encodeWinAnsi(text) {
69
+ const bytes = [];
70
+ for (const char of text) {
71
+ bytes.push(
72
+ winAnsiByte(char.codePointAt(0)) ?? 63
73
+ /* ? */
74
+ );
75
+ }
76
+ return new Uint8Array(bytes);
77
+ }
@@ -18,7 +18,6 @@ export function decodeCircleAnnotation(annotation, context) {
18
18
  y: rect.y + rect.height / 2,
19
19
  radiusX: rect.width / 2,
20
20
  radiusY: rect.height / 2,
21
- strokeScaleEnabled: false,
22
21
  strokeWidth,
23
22
  stroke: color
24
23
  }));
@@ -20,7 +20,6 @@ export function decodeInkAnnotation(annotation, context) {
20
20
  if (points.length < 4) continue;
21
21
  group.add(new Konva.Line({
22
22
  points,
23
- strokeScaleEnabled: false,
24
23
  stroke: color,
25
24
  strokeWidth,
26
25
  opacity,
@@ -21,7 +21,6 @@ export function decodeLineAnnotation(annotation, context) {
21
21
  const group = createGhostGroup(annotation.id);
22
22
  group.add(new Konva.Arrow({
23
23
  points,
24
- strokeScaleEnabled: false,
25
24
  stroke: color,
26
25
  fill: color,
27
26
  strokeWidth,
@@ -19,7 +19,6 @@ export function decodeSquareAnnotation(annotation, context) {
19
19
  y: rect.y,
20
20
  width: rect.width,
21
21
  height: rect.height,
22
- strokeScaleEnabled: false,
23
22
  stroke: color,
24
23
  strokeWidth,
25
24
  fill: isFilled ? color : void 0,
@@ -4,6 +4,9 @@ import { type RawPdfAnnotation, type StampAppearance } from './types.js';
4
4
  export interface StampExtractionOptions {
5
5
  scale?: number;
6
6
  diffThreshold?: number;
7
+ /** Skip annotations whose appearance changes no pixels instead of
8
+ * falling back to the raw crop (which would capture page content). */
9
+ skipEmptyDiff?: boolean;
7
10
  }
8
11
  export interface PixelBounds {
9
12
  x: number;
@@ -22,3 +25,12 @@ export declare function applyMaskOrFallback(annotated: Uint8ClampedArray, mask:
22
25
  usedMask: boolean;
23
26
  };
24
27
  export declare function extractStampAppearancesForPage(page: PDFPageProxy, pageTransform: PageTransform, annotations: RawPdfAnnotation[], options?: StampExtractionOptions): Promise<Map<string, StampAppearance>>;
28
+ /**
29
+ * Extract the rendered appearance of signature widgets on a page. The
30
+ * page canvas renders with annotations disabled, so a signature stamp
31
+ * already present in the source PDF is invisible behind the interactive
32
+ * form layer without this. Widgets whose appearance draws nothing (e.g.
33
+ * unsigned fields with an empty `/AP`) are skipped — callers decide
34
+ * which fields are actually signed via the AcroForm `/V` side-channel.
35
+ */
36
+ export declare function extractSignedSignatureAppearancesForPage(page: PDFPageProxy, pageTransform: PageTransform, annotations: RawPdfAnnotation[], options?: StampExtractionOptions): Promise<Map<string, StampAppearance>>;
@@ -95,11 +95,23 @@ async function renderPageToCanvas(page, canvas, annotationMode, scale) {
95
95
  await task.promise;
96
96
  }
97
97
  export async function extractStampAppearancesForPage(page, pageTransform, annotations, options = {}) {
98
- const appearances = /* @__PURE__ */ new Map();
99
98
  const stampAnnotations = annotations.filter(
100
99
  (annotation) => annotation.annotationType === PdfjsAnnotationType.STAMP && typeof annotation.id === "string"
101
100
  );
102
- if (stampAnnotations.length === 0) return appearances;
101
+ return extractAppearancesForAnnotations(page, pageTransform, stampAnnotations, options);
102
+ }
103
+ export async function extractSignedSignatureAppearancesForPage(page, pageTransform, annotations, options = {}) {
104
+ const signedWidgets = annotations.filter(
105
+ (annotation) => annotation.annotationType === PdfjsAnnotationType.WIDGET && typeof annotation.id === "string" && annotation.fieldType === "Sig"
106
+ );
107
+ return extractAppearancesForAnnotations(page, pageTransform, signedWidgets, {
108
+ ...options,
109
+ skipEmptyDiff: true
110
+ });
111
+ }
112
+ async function extractAppearancesForAnnotations(page, pageTransform, targetAnnotations, options = {}) {
113
+ const appearances = /* @__PURE__ */ new Map();
114
+ if (targetAnnotations.length === 0) return appearances;
103
115
  const scale = options.scale ?? DEFAULT_RENDER_SCALE;
104
116
  const diffThreshold = options.diffThreshold ?? DEFAULT_DIFF_THRESHOLD;
105
117
  const viewport = page.getViewport({ scale });
@@ -118,7 +130,7 @@ export async function extractStampAppearancesForPage(page, pageTransform, annota
118
130
  const baseContext = baseCanvas.getContext("2d", { willReadFrequently: true });
119
131
  const annotatedContext = annotatedCanvas.getContext("2d", { willReadFrequently: true });
120
132
  if (!baseContext || !annotatedContext) return appearances;
121
- for (const annotation of stampAnnotations) {
133
+ for (const annotation of targetAnnotations) {
122
134
  try {
123
135
  const id = annotation.id;
124
136
  const bounds = stampRectToPixelBounds(
@@ -138,7 +150,8 @@ export async function extractStampAppearancesForPage(page, pageTransform, annota
138
150
  bounds.height,
139
151
  diffThreshold
140
152
  );
141
- const { data: maskedData } = applyMaskOrFallback(annotatedData.data, mask);
153
+ const { data: maskedData, usedMask } = applyMaskOrFallback(annotatedData.data, mask);
154
+ if (!usedMask && options.skipEmptyDiff) continue;
142
155
  const outputCanvas = createCanvas(bounds.width, bounds.height);
143
156
  if (!outputCanvas) continue;
144
157
  const outputContext = outputCanvas.getContext("2d");
@@ -29,6 +29,8 @@ export interface RawPdfAnnotation {
29
29
  modificationDate?: unknown;
30
30
  inReplyTo?: unknown;
31
31
  quadPoints?: unknown;
32
+ fieldType?: unknown;
33
+ fieldValue?: unknown;
32
34
  defaultAppearanceData?: unknown;
33
35
  inkLists?: unknown;
34
36
  lineCoordinates?: unknown;
@@ -0,0 +1,102 @@
1
+ Digitized data copyright (c) 2010 Google Corporation
2
+ with Reserved Font Arimo, Tinos and Cousine.
3
+ Copyright (c) 2012 Red Hat, Inc.
4
+ with Reserved Font Name Liberation.
5
+
6
+ This Font Software is licensed under the SIL Open Font License,
7
+ Version 1.1.
8
+
9
+ This license is copied below, and is also available with a FAQ at:
10
+ http://scripts.sil.org/OFL
11
+
12
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
13
+
14
+ PREAMBLE The goals of the Open Font License (OFL) are to stimulate
15
+ worldwide development of collaborative font projects, to support the font
16
+ creation efforts of academic and linguistic communities, and to provide
17
+ a free and open framework in which fonts may be shared and improved in
18
+ partnership with others.
19
+
20
+ The OFL allows the licensed fonts to be used, studied, modified and
21
+ redistributed freely as long as they are not sold by themselves.
22
+ The fonts, including any derivative works, can be bundled, embedded,
23
+ redistributed and/or sold with any software provided that any reserved
24
+ names are not used by derivative works. The fonts and derivatives,
25
+ however, cannot be released under any other type of license. The
26
+ requirement for fonts to remain under this license does not apply to
27
+ any document created using the fonts or their derivatives.
28
+
29
+
30
+
31
+ DEFINITIONS
32
+ "Font Software" refers to the set of files released by the Copyright
33
+ Holder(s) under this license and clearly marked as such.
34
+ This may include source files, build scripts and documentation.
35
+
36
+ "Reserved Font Name" refers to any names specified as such after the
37
+ copyright statement(s).
38
+
39
+ "Original Version" refers to the collection of Font Software components
40
+ as distributed by the Copyright Holder(s).
41
+
42
+ "Modified Version" refers to any derivative made by adding to, deleting,
43
+ or substituting ? in part or in whole ?
44
+ any of the components of the Original Version, by changing formats or
45
+ by porting the Font Software to a new environment.
46
+
47
+ "Author" refers to any designer, engineer, programmer, technical writer
48
+ or other person who contributed to the Font Software.
49
+
50
+
51
+ PERMISSION & CONDITIONS
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining a
54
+ copy of the Font Software, to use, study, copy, merge, embed, modify,
55
+ redistribute, and sell modified and unmodified copies of the Font
56
+ Software, subject to the following conditions:
57
+
58
+ 1) Neither the Font Software nor any of its individual components,in
59
+ Original or Modified Versions, may be sold by itself.
60
+
61
+ 2) Original or Modified Versions of the Font Software may be bundled,
62
+ redistributed and/or sold with any software, provided that each copy
63
+ contains the above copyright notice and this license. These can be
64
+ included either as stand-alone text files, human-readable headers or
65
+ in the appropriate machine-readable metadata fields within text or
66
+ binary files as long as those fields can be easily viewed by the user.
67
+
68
+ 3) No Modified Version of the Font Software may use the Reserved Font
69
+ Name(s) unless explicit written permission is granted by the
70
+ corresponding Copyright Holder. This restriction only applies to the
71
+ primary font name as presented to the users.
72
+
73
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
74
+ Software shall not be used to promote, endorse or advertise any
75
+ Modified Version, except to acknowledge the contribution(s) of the
76
+ Copyright Holder(s) and the Author(s) or with their explicit written
77
+ permission.
78
+
79
+ 5) The Font Software, modified or unmodified, in part or in whole, must
80
+ be distributed entirely under this license, and must not be distributed
81
+ under any other license. The requirement for fonts to remain under
82
+ this license does not apply to any document created using the Font
83
+ Software.
84
+
85
+
86
+
87
+ TERMINATION
88
+ This license becomes null and void if any of the above conditions are not met.
89
+
90
+
91
+
92
+ DISCLAIMER
93
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
94
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
95
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
96
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
97
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
98
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
99
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
100
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
101
+ DEALINGS IN THE FONT SOFTWARE.
102
+
@@ -1 +1 @@
1
- .kviewer-text-layer{left:0;line-height:1;overflow:hidden;position:absolute;top:0;-webkit-user-select:none;-moz-user-select:none;user-select:none;z-index:1}.kviewer-text-layer--interactive{cursor:text;-webkit-user-select:text;-moz-user-select:text;user-select:text}.KViewer_is_painting.KViewer_painting_type_12 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_12 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_13 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_13 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_5 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_5 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_6 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_6 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_7 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_7 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_8 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_8 .kviewer-annotation-layer *{cursor:crosshair!important}.KViewer_is_painting.KViewer_painting_type_4 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_4 .kviewer-annotation-layer *{cursor:text!important}.KViewer_is_painting.KViewer_painting_type_11 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_11 .kviewer-annotation-layer *{cursor:crosshair!important}.KViewer_selector_hover{cursor:pointer!important}.kviewer-form-layer{left:0;overflow:hidden;position:absolute;top:0}.kviewer-form-field{box-sizing:border-box;position:absolute}.kviewer-form-input{background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 14%,transparent);border:1px solid transparent;box-sizing:border-box;color:#000;display:block;font-family:-apple-system,BlinkMacSystemFont,Helvetica Neue,Helvetica,Arial,sans-serif;font-weight:500;height:100%;line-height:normal;margin:0;outline:none;padding:1px 2px;resize:none;width:100%;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility;vertical-align:top}.kviewer-form-input:hover{background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 22%,transparent);border-color:rgba(0,0,0,.2)}.kviewer-form-input:focus{background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 28%,transparent);border-color:var(--kvw-field-color,var(--color-primary,#3b82f6));outline:2px solid var(--kvw-field-color,var(--color-primary,#3b82f6))}.kviewer-form-select{-webkit-appearance:auto;-moz-appearance:auto;appearance:auto;cursor:pointer}.kviewer-form-listbox{overflow-y:auto;padding:0}.kviewer-form-listbox option{padding:1px 3px}.kviewer-form-editable-combo{height:100%;position:relative;width:100%}.kviewer-form-editable-combo input{height:100%;width:100%}.kviewer-form-checkbox,.kviewer-form-radio{align-items:center;background:#fff;box-sizing:border-box;cursor:pointer;display:flex;height:100%;justify-content:center;width:100%}.kviewer-form-checkbox input,.kviewer-form-radio input{accent-color:var(--kvw-field-color,var(--color-primary,#3b82f6));cursor:pointer;height:80%;margin:0;max-height:18px;max-width:18px;width:80%}.kviewer-form-checkbox--detected{background:transparent}.kviewer-form-checkbox--circle{border-radius:50%}.kviewer-form-checkbox__icon{color:#1a1a1a;height:65%;width:65%}.kviewer-form-checkbox--circle .kviewer-form-checkbox__icon{height:50%;width:50%}.kviewer-form-radio input{accent-color:var(--kvw-field-color,var(--color-primary,#3b82f6));cursor:pointer;height:80%;margin:0;max-height:18px;max-width:18px;width:80%}.kviewer-form-button{align-items:center;background:#c8c8c8;border:1px solid rgba(0,0,0,.35);box-sizing:border-box;color:#000;cursor:pointer;display:flex;font-family:inherit;font-weight:700;height:100%;justify-content:center;line-height:1;padding:0 6px;text-align:center;width:100%;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.kviewer-form-button:hover{background:#bdbdbd}.kviewer-form-button:active{background:#b0b0b0}.kviewer-form-signature{align-items:center;background:rgba(255,255,200,.15);border:1px dashed rgba(0,0,0,.2);cursor:pointer;display:flex;height:100%;justify-content:center;width:100%}.kviewer-form-signature:hover{background:color-mix(in srgb,var(--kvw-field-color,#3b82f6) 8%,transparent);border-color:var(--kvw-field-color,var(--color-primary,#3b82f6))}.kviewer-form-signature--filled{background:transparent;border-color:transparent;border-style:solid}.kviewer-form-signature__preview{max-height:100%;max-width:100%;-o-object-fit:contain;object-fit:contain}.kviewer-form-signature__placeholder{color:rgba(0,0,0,.4);font-size:10px;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}
1
+ .kviewer-text-layer{left:0;line-height:1;overflow:hidden;position:absolute;top:0;-webkit-user-select:none;-moz-user-select:none;user-select:none;z-index:1}.kviewer-text-layer--interactive{cursor:text;-webkit-user-select:text;-moz-user-select:text;user-select:text}.KViewer_is_painting.KViewer_painting_type_12 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_12 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_13 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_13 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_5 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_5 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_6 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_6 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_7 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_7 .kviewer-annotation-layer *,.KViewer_is_painting.KViewer_painting_type_8 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_8 .kviewer-annotation-layer *{cursor:crosshair!important}.KViewer_is_painting.KViewer_painting_type_4 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_4 .kviewer-annotation-layer *{cursor:text!important}.KViewer_is_painting.KViewer_painting_type_11 .kviewer-annotation-layer,.KViewer_is_painting.KViewer_painting_type_11 .kviewer-annotation-layer *{cursor:crosshair!important}.KViewer_selector_hover{cursor:pointer!important}.kviewer-form-layer{left:0;overflow:hidden;position:absolute;top:0}.kviewer-form-field{box-sizing:border-box;position:absolute}.kviewer-form-input{background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 14%,transparent);border:1px solid transparent;box-sizing:border-box;color:#000;display:block;font-family:-apple-system,BlinkMacSystemFont,Helvetica Neue,Helvetica,Arial,sans-serif;font-weight:500;height:100%;line-height:normal;margin:0;outline:none;padding:1px 2px;resize:none;width:100%;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility;vertical-align:top}.kviewer-form-input:hover{background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 22%,transparent);border-color:rgba(0,0,0,.2)}.kviewer-form-input:focus{background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 28%,transparent);border-color:var(--kvw-field-color,var(--color-primary,#3b82f6));outline:2px solid var(--kvw-field-color,var(--color-primary,#3b82f6))}.kviewer-form-uselect{align-items:center;background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 14%,transparent);border:1px solid transparent;border-radius:0;box-sizing:border-box;color:#000;cursor:pointer;display:flex;height:100%;line-height:1;padding:0 11px 0 2px;width:100%}.kviewer-form-uselect:hover{background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 22%,transparent);border-color:rgba(0,0,0,.2)}.kviewer-form-uselect:focus-visible{background-color:color-mix(in srgb,var(--kvw-field-color,#1677ff) 28%,transparent);outline:2px solid var(--kvw-field-color,var(--color-primary,#3b82f6));outline-offset:-2px}.kviewer-form-uselect:disabled{cursor:default}.kviewer-form-listbox{overflow-y:auto;padding:0}.kviewer-form-listbox option{padding:1px 3px}.kviewer-form-editable-combo{height:100%;position:relative;width:100%}.kviewer-form-editable-combo input{height:100%;width:100%}.kviewer-form-checkbox,.kviewer-form-radio{align-items:center;background:#fff;box-sizing:border-box;cursor:pointer;display:flex;height:100%;justify-content:center;width:100%}.kviewer-form-checkbox input,.kviewer-form-radio input{accent-color:var(--kvw-field-color,var(--color-primary,#3b82f6));cursor:pointer;height:80%;margin:0;max-height:18px;max-width:18px;width:80%}.kviewer-form-checkbox--detected{background:transparent}.kviewer-form-checkbox--circle{border-radius:50%}.kviewer-form-checkbox__icon{color:#1a1a1a;height:65%;width:65%}.kviewer-form-checkbox--circle .kviewer-form-checkbox__icon{height:50%;width:50%}.kviewer-form-radio input{accent-color:var(--kvw-field-color,var(--color-primary,#3b82f6));cursor:pointer;height:80%;margin:0;max-height:18px;max-width:18px;width:80%}.kviewer-form-button{align-items:center;background:#c8c8c8;border:1px solid rgba(0,0,0,.35);box-sizing:border-box;color:#000;cursor:pointer;display:flex;font-family:inherit;font-weight:700;height:100%;justify-content:center;line-height:1;padding:0 6px;text-align:center;width:100%;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.kviewer-form-button:hover{background:#bdbdbd}.kviewer-form-button:active{background:#b0b0b0}.kviewer-form-signature{align-items:center;background:rgba(255,255,200,.15);border:1px dashed rgba(0,0,0,.2);cursor:pointer;display:flex;height:100%;justify-content:center;width:100%}.kviewer-form-signature:hover{background:color-mix(in srgb,var(--kvw-field-color,#3b82f6) 8%,transparent);border-color:var(--kvw-field-color,var(--color-primary,#3b82f6))}.kviewer-form-signature--filled{background:transparent;border-color:transparent;border-style:solid}.kviewer-form-signature__preview{max-height:100%;max-width:100%;-o-object-fit:contain;object-fit:contain}.kviewer-form-signature__placeholder{color:rgba(0,0,0,.4);font-size:10px;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}
@@ -9,7 +9,7 @@
9
9
  <UPopover v-if="hasColorEdit && !isMultiSelect">
10
10
  <button
11
11
  class="flex items-center justify-center w-7 h-7 rounded-md hover:bg-default cursor-pointer"
12
- title="Color"
12
+ :title="t('color')"
13
13
  >
14
14
  <UIcon name="i-lucide-palette" class="text-sm text-muted" />
15
15
  </button>
@@ -41,14 +41,14 @@
41
41
 
42
42
  <!-- Selection count badge for multi-select -->
43
43
  <span v-if="isMultiSelect" class="text-xs text-muted px-1.5">
44
- {{ state.selectedAnnotations.value.length }} selected
44
+ {{ t("selectedCount", { count: state.selectedAnnotations.value.length }) }}
45
45
  </span>
46
46
 
47
47
  <!-- Edit text (free text only) -->
48
48
  <button
49
49
  v-if="isFreeText"
50
50
  class="flex items-center justify-center w-7 h-7 rounded-md hover:bg-default cursor-pointer"
51
- title="Edit text"
51
+ :title="t('editText')"
52
52
  data-testid="annotation-edit-text"
53
53
  @click="onEditText"
54
54
  >
@@ -58,7 +58,7 @@
58
58
  <!-- Delete -->
59
59
  <button
60
60
  class="flex items-center justify-center w-7 h-7 rounded-md hover:bg-default cursor-pointer"
61
- title="Delete"
61
+ :title="t('delete')"
62
62
  data-testid="annotation-delete"
63
63
  @click="onDelete"
64
64
  >
@@ -71,9 +71,11 @@
71
71
  <script setup>
72
72
  import { computed } from "vue";
73
73
  import { useViewerState } from "../composables/useViewerState";
74
+ import { useKviewerI18n } from "../composables/useKviewerI18n";
74
75
  import { defaultOptions, annotationDefinitions } from "../annotation/engine/config";
75
76
  import { AnnotationType } from "../annotation/engine/types";
76
77
  const state = useViewerState();
78
+ const { t } = useKviewerI18n();
77
79
  const colors = defaultOptions.colors;
78
80
  const isMultiSelect = computed(() => state.selectedAnnotations.value.length > 1);
79
81
  const hasSelection = computed(
@@ -6,9 +6,25 @@ type __VLS_Props = {
6
6
  /** Canvas internal resolution multiplier (CSS size unchanged).
7
7
  * Used by panzoom to sharpen the PDF when visually zoomed in. */
8
8
  renderQuality?: number;
9
+ /** Visible region of this page in page-CSS coordinates (already
10
+ * includes margin), supplied by the viewer's panzoom. Drives the
11
+ * viewport-window raster at high zoom. Null = unknown/inapplicable
12
+ * (e.g. rotated pages), full-page rendering only. */
13
+ viewWindow?: {
14
+ x: number;
15
+ y: number;
16
+ width: number;
17
+ height: number;
18
+ } | null;
9
19
  };
10
20
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
11
21
  renderQuality: number;
22
+ viewWindow: {
23
+ x: number;
24
+ y: number;
25
+ width: number;
26
+ height: number;
27
+ } | null;
12
28
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
29
  declare const _default: typeof __VLS_export;
14
30
  export default _default;
@@ -16,6 +16,15 @@
16
16
  ref="canvasRef"
17
17
  :style="{ display: 'block', width: cssWidth + 'px', height: cssHeight + 'px' }"
18
18
  />
19
+ <!-- Crisp viewport-window raster: when the full page would blow the
20
+ canvas budget at high zoom, the base canvas above is only a
21
+ low-res fallback and this canvas renders just the visible region
22
+ (plus margin) at full resolution. -->
23
+ <canvas
24
+ v-show="windowCanvasVisible"
25
+ ref="windowCanvasRef"
26
+ :style="windowCanvasStyle"
27
+ />
19
28
  <div
20
29
  ref="textLayerRef"
21
30
  class="kviewer-text-layer textLayer"
@@ -33,6 +42,16 @@
33
42
  :pointer-events="formFieldPointerEvents"
34
43
  :z-index="formFieldZIndex"
35
44
  />
45
+ <!-- transform: translateZ(0) isolates the Konva canvases in their own
46
+ compositing layer: per-frame canvas updates during annotation
47
+ drags then only re-upload the (budget-capped) Konva texture
48
+ instead of triggering an iPadOS re-rasterization of the subtree
49
+ containing the much larger PDF canvases. -->
50
+ <!-- overflow: hidden — between a zoom commit and the async Konva
51
+ re-init the old (differently sized) stage briefly overflows this
52
+ div; unclipped it inflates the zoom wrapper's scrollHeight and
53
+ the panzoom clamps against phantom bounds, leaving the page
54
+ resting out of position. -->
36
55
  <div
37
56
  ref="annotationRef"
38
57
  class="kviewer-annotation-layer"
@@ -43,7 +62,9 @@
43
62
  width: cssWidth + 'px',
44
63
  height: cssHeight + 'px',
45
64
  zIndex: 3,
46
- pointerEvents: annotationPointerEvents
65
+ pointerEvents: annotationPointerEvents,
66
+ transform: 'translateZ(0)',
67
+ overflow: 'hidden'
47
68
  }"
48
69
  />
49
70
  </div>
@@ -58,21 +79,35 @@ import { usePageProxyCache } from "../composables/usePageProxyCache";
58
79
  import { useFormFields } from "../composables/useFormFields";
59
80
  import { useShapeDetection } from "../composables/useShapeDetection";
60
81
  import { AnnotationType } from "../annotation/engine/types";
82
+ import { isIPad } from "../annotation/engine/input-device";
83
+ import { extractSignedSignatureAppearancesForPage } from "../annotation/pdf-import/extract_stamp_appearance";
84
+ import { pageTransformFromProxy } from "../annotation/pdf-import/transform";
85
+ import {
86
+ clampRenderScale,
87
+ DEFAULT_MAX_CANVAS_PIXELS,
88
+ IOS_MAX_CANVAS_PIXELS
89
+ } from "../composables/canvas-limits";
61
90
  import FormFieldLayer from "./FormFieldLayer.vue";
62
91
  const PDFJS_ANNOTATION_MODE_DISABLE = 0;
63
92
  const props = defineProps({
64
93
  pageNumber: { type: Number, required: true },
65
94
  pageMeta: { type: Object, required: true },
66
95
  scale: { type: Number, required: true },
67
- renderQuality: { type: Number, required: false, default: 1 }
96
+ renderQuality: { type: Number, required: false, default: 1 },
97
+ viewWindow: { type: [Object, null], required: false, default: null }
68
98
  });
69
99
  const canvasRef = ref(null);
100
+ const windowCanvasRef = ref(null);
101
+ const windowCanvasVisible = ref(false);
102
+ const windowCanvasStyle = ref({});
70
103
  const textLayerRef = ref(null);
71
104
  const annotationRef = ref(null);
72
105
  const runtimeConfig = useRuntimeConfig();
73
106
  const minRenderPixelRatio = Number(
74
107
  runtimeConfig.public.kviewer?.minRenderPixelRatio ?? 2
75
108
  );
109
+ const isAppleMobile = typeof navigator !== "undefined" && (isIPad() || /iPhone|iPod/.test(navigator.userAgent));
110
+ const maxCanvasPixels = isAppleMobile ? IOS_MAX_CANVAS_PIXELS : DEFAULT_MAX_CANVAS_PIXELS;
76
111
  const state = useViewerState();
77
112
  const search = useViewerSearch();
78
113
  const proxyCache = usePageProxyCache();
@@ -80,6 +115,11 @@ const formFields = useFormFields();
80
115
  const shapeDetection = useShapeDetection();
81
116
  const pageProxy = shallowRef(null);
82
117
  let currentRenderTask = null;
118
+ let windowRenderTask = null;
119
+ let windowed = false;
120
+ let renderedWindowKey = null;
121
+ const FALLBACK_MAX_CANVAS_PIXELS = 4e6;
122
+ const WINDOW_MAX_CANVAS_PIXELS = 8e6;
83
123
  let textLayer = null;
84
124
  const baseWidth = props.pageMeta.width;
85
125
  const baseHeight = props.pageMeta.height;
@@ -109,8 +149,8 @@ onMounted(async () => {
109
149
  await renderTextLayer();
110
150
  initKonva();
111
151
  if (pageProxy.value) {
112
- const rawAnnotations = await pageProxy.value.getAnnotations();
113
- formFields.parsePageFields(props.pageNumber, rawAnnotations);
152
+ rawPageAnnotations = await pageProxy.value.getAnnotations();
153
+ formFields.parsePageFields(props.pageNumber, rawPageAnnotations);
114
154
  }
115
155
  if (state.shapeDetection.value && pageProxy.value) {
116
156
  const viewport = pageProxy.value.getViewport({ scale: props.scale });
@@ -129,6 +169,27 @@ onMounted(async () => {
129
169
  }
130
170
  }
131
171
  });
172
+ let rawPageAnnotations = null;
173
+ const attemptedSignatureSeedIds = /* @__PURE__ */ new Set();
174
+ const pendingSignedSignatureKey = computed(() => formFields.getFieldsForPage(props.pageNumber).filter((def) => def.fieldType === "signature" && def.signedInSource && formFields.getFieldValue(def.id)?.value === "").map((def) => def.id).join(","));
175
+ watch(pendingSignedSignatureKey, (key) => {
176
+ if (key !== "") void seedSignedSignatureAppearances();
177
+ });
178
+ async function seedSignedSignatureAppearances() {
179
+ if (!pageProxy.value || !rawPageAnnotations) return;
180
+ const pending = formFields.getFieldsForPage(props.pageNumber).filter((def) => def.fieldType === "signature" && def.signedInSource && formFields.getFieldValue(def.id)?.value === "" && !attemptedSignatureSeedIds.has(def.id));
181
+ if (pending.length === 0) return;
182
+ for (const def of pending) attemptedSignatureSeedIds.add(def.id);
183
+ const appearances = await extractSignedSignatureAppearancesForPage(
184
+ pageProxy.value,
185
+ pageTransformFromProxy(pageProxy.value),
186
+ rawPageAnnotations
187
+ );
188
+ for (const def of pending) {
189
+ const appearance = appearances.get(def.id);
190
+ if (appearance) formFields.setFieldValue(def.id, appearance.dataUrl);
191
+ }
192
+ }
132
193
  watch(
133
194
  () => state.shapeDetection.value,
134
195
  async (enabled) => {
@@ -151,10 +212,22 @@ watch(
151
212
  );
152
213
  watch(
153
214
  () => props.scale,
154
- async () => {
215
+ async (newScale, oldScale) => {
155
216
  if (!pageProxy.value) return;
217
+ if (windowCanvasVisible.value && oldScale && newScale !== oldScale) {
218
+ const r = newScale / oldScale;
219
+ const s = windowCanvasStyle.value;
220
+ windowCanvasStyle.value = {
221
+ ...s,
222
+ left: Number.parseFloat(s.left ?? "0") * r + "px",
223
+ top: Number.parseFloat(s.top ?? "0") * r + "px",
224
+ width: Number.parseFloat(s.width ?? "0") * r + "px",
225
+ height: Number.parseFloat(s.height ?? "0") * r + "px"
226
+ };
227
+ renderedWindowKey = null;
228
+ }
156
229
  shapeDetection.clearShapeCache(props.pageNumber);
157
- await renderCanvas();
230
+ await renderCanvas({ doubleBuffer: true });
158
231
  updateTextLayer();
159
232
  if (state.painter.value) {
160
233
  state.painter.value.destroyCanvasForPage(props.pageNumber);
@@ -183,9 +256,16 @@ async function renderCanvas(opts) {
183
256
  }
184
257
  const dpr = Math.max(window.devicePixelRatio || 1, minRenderPixelRatio);
185
258
  const quality = props.renderQuality ?? 1;
186
- const viewport = proxy.getViewport({
187
- scale: props.scale * quality * dpr
188
- });
259
+ const desiredScale = props.scale * quality * dpr;
260
+ const fullScale = clampRenderScale(desiredScale, baseWidth, baseHeight, maxCanvasPixels);
261
+ windowed = fullScale < desiredScale * 0.999;
262
+ const renderScale = windowed ? clampRenderScale(
263
+ desiredScale,
264
+ baseWidth,
265
+ baseHeight,
266
+ Math.min(FALLBACK_MAX_CANVAS_PIXELS, maxCanvasPixels)
267
+ ) : fullScale;
268
+ const viewport = proxy.getViewport({ scale: renderScale });
189
269
  if (opts?.doubleBuffer) {
190
270
  const tmp = document.createElement("canvas");
191
271
  tmp.width = viewport.width;
@@ -225,7 +305,84 @@ async function renderCanvas(opts) {
225
305
  currentRenderTask = null;
226
306
  }
227
307
  }
308
+ if (windowed) {
309
+ void renderWindowCanvas();
310
+ } else {
311
+ hideWindowCanvas();
312
+ }
313
+ }
314
+ function hideWindowCanvas() {
315
+ windowCanvasVisible.value = false;
316
+ renderedWindowKey = null;
317
+ const c = windowCanvasRef.value;
318
+ if (c && c.width > 0) {
319
+ c.width = 0;
320
+ c.height = 0;
321
+ }
228
322
  }
323
+ async function renderWindowCanvas() {
324
+ const proxy = pageProxy.value;
325
+ const canvas = windowCanvasRef.value;
326
+ const win = props.viewWindow;
327
+ if (!proxy || !canvas || !win || !windowed) return;
328
+ const x = Math.max(0, Math.min(win.x, cssWidth.value));
329
+ const y = Math.max(0, Math.min(win.y, cssHeight.value));
330
+ const w = Math.min(win.x + win.width, cssWidth.value) - x;
331
+ const h = Math.min(win.y + win.height, cssHeight.value) - y;
332
+ if (w <= 0 || h <= 0) return;
333
+ const key = [x, y, w, h, props.scale].map((n) => Math.round(n)).join(",");
334
+ if (key === renderedWindowKey && windowCanvasVisible.value) return;
335
+ const dpr = window.devicePixelRatio || 1;
336
+ const renderScale = clampRenderScale(
337
+ props.scale * dpr,
338
+ w / props.scale,
339
+ h / props.scale,
340
+ Math.min(WINDOW_MAX_CANVAS_PIXELS, maxCanvasPixels)
341
+ );
342
+ const k = renderScale / props.scale;
343
+ const viewport = proxy.getViewport({ scale: renderScale });
344
+ windowRenderTask?.cancel();
345
+ await currentRenderTask?.promise.catch(() => {
346
+ });
347
+ const tmp = document.createElement("canvas");
348
+ tmp.width = Math.floor(w * k);
349
+ tmp.height = Math.floor(h * k);
350
+ try {
351
+ windowRenderTask = proxy.render({
352
+ canvasContext: tmp.getContext("2d"),
353
+ viewport,
354
+ transform: [1, 0, 0, 1, -x * k, -y * k],
355
+ annotationMode: PDFJS_ANNOTATION_MODE_DISABLE
356
+ });
357
+ await windowRenderTask.promise;
358
+ canvas.width = tmp.width;
359
+ canvas.height = tmp.height;
360
+ canvas.getContext("2d").drawImage(tmp, 0, 0);
361
+ windowCanvasStyle.value = {
362
+ position: "absolute",
363
+ left: x + "px",
364
+ top: y + "px",
365
+ width: w + "px",
366
+ height: h + "px"
367
+ };
368
+ windowCanvasVisible.value = true;
369
+ renderedWindowKey = key;
370
+ } catch (e) {
371
+ if (e instanceof Error && e.message?.includes("Rendering cancelled")) return;
372
+ console.warn("[KViewer] Window render failed:", e);
373
+ } finally {
374
+ windowRenderTask = null;
375
+ tmp.width = 0;
376
+ tmp.height = 0;
377
+ }
378
+ }
379
+ watch(
380
+ () => props.viewWindow,
381
+ (win) => {
382
+ if (windowed) void renderWindowCanvas();
383
+ state.painter.value?.setStageWindow(props.pageNumber, win ?? null);
384
+ }
385
+ );
229
386
  function initKonva() {
230
387
  if (!annotationRef.value || !state.painter.value) return;
231
388
  state.painter.value.initCanvasForPage(
@@ -235,6 +392,9 @@ function initKonva() {
235
392
  baseHeight,
236
393
  props.scale
237
394
  );
395
+ if (props.viewWindow) {
396
+ state.painter.value.setStageWindow(props.pageNumber, props.viewWindow);
397
+ }
238
398
  }
239
399
  async function renderTextLayer() {
240
400
  const container = textLayerRef.value;
@@ -279,6 +439,7 @@ function updateTextLayer() {
279
439
  }
280
440
  onBeforeUnmount(() => {
281
441
  currentRenderTask?.cancel();
442
+ windowRenderTask?.cancel();
282
443
  textLayer?.cancel();
283
444
  textLayer = null;
284
445
  search.unregisterPageLayer(props.pageNumber);