kviewer 0.0.9 → 0.0.11

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 (74) hide show
  1. package/README.md +29 -0
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +19 -0
  4. package/dist/runtime/annotation/checkbox-styles.d.ts +19 -0
  5. package/dist/runtime/annotation/checkbox-styles.js +27 -0
  6. package/dist/runtime/annotation/engine/config.js +44 -0
  7. package/dist/runtime/annotation/engine/editor/editor.d.ts +6 -3
  8. package/dist/runtime/annotation/engine/editor/editor.js +22 -9
  9. package/dist/runtime/annotation/engine/editor/selector.d.ts +9 -1
  10. package/dist/runtime/annotation/engine/editor/selector.js +72 -30
  11. package/dist/runtime/annotation/engine/painter.d.ts +6 -2
  12. package/dist/runtime/annotation/engine/painter.js +42 -5
  13. package/dist/runtime/annotation/engine/tools/form-field.d.ts +24 -0
  14. package/dist/runtime/annotation/engine/tools/form-field.js +117 -0
  15. package/dist/runtime/annotation/engine/types.d.ts +54 -1
  16. package/dist/runtime/annotation/engine/types.js +4 -0
  17. package/dist/runtime/annotation/font-style.d.ts +23 -0
  18. package/dist/runtime/annotation/font-style.js +57 -0
  19. package/dist/runtime/annotation/parsers/extractCheckboxStyles.d.ts +21 -0
  20. package/dist/runtime/annotation/parsers/extractCheckboxStyles.js +75 -0
  21. package/dist/runtime/annotation/parsers/parseFormFields.js +16 -3
  22. package/dist/runtime/annotation/pdf-export/export-form-fields.d.ts +8 -5
  23. package/dist/runtime/annotation/pdf-export/export-form-fields.js +245 -1
  24. package/dist/runtime/annotation/pdf-export/export.d.ts +3 -2
  25. package/dist/runtime/annotation/pdf-export/export.js +9 -2
  26. package/dist/runtime/assets/kviewer.css +1 -1
  27. package/dist/runtime/components/FormFieldLayer.d.vue.ts +5 -0
  28. package/dist/runtime/components/FormFieldLayer.vue +40 -3
  29. package/dist/runtime/components/FormFieldLayer.vue.d.ts +5 -0
  30. package/dist/runtime/components/PdfPage.d.vue.ts +6 -1
  31. package/dist/runtime/components/PdfPage.vue +75 -18
  32. package/dist/runtime/components/PdfPage.vue.d.ts +6 -1
  33. package/dist/runtime/components/ToolButton.d.vue.ts +4 -2
  34. package/dist/runtime/components/ToolButton.vue.d.ts +4 -2
  35. package/dist/runtime/components/Viewer.d.vue.ts +18 -3
  36. package/dist/runtime/components/Viewer.vue +278 -170
  37. package/dist/runtime/components/Viewer.vue.d.ts +18 -3
  38. package/dist/runtime/components/ViewerBar.vue +24 -2
  39. package/dist/runtime/components/form-fields/FormButton.vue +16 -4
  40. package/dist/runtime/components/form-fields/FormCheckbox.vue +31 -15
  41. package/dist/runtime/components/form-fields/FormDropdown.vue +3 -1
  42. package/dist/runtime/components/form-fields/FormFieldWrapper.d.vue.ts +12 -1
  43. package/dist/runtime/components/form-fields/FormFieldWrapper.vue +45 -9
  44. package/dist/runtime/components/form-fields/FormFieldWrapper.vue.d.ts +12 -1
  45. package/dist/runtime/components/form-fields/FormRadioButton.vue +3 -1
  46. package/dist/runtime/components/form-fields/FormSignatureField.vue +2 -1
  47. package/dist/runtime/components/form-fields/FormTextField.vue +47 -7
  48. package/dist/runtime/components/form-fields/PlacedFieldChrome.d.vue.ts +16 -0
  49. package/dist/runtime/components/form-fields/PlacedFieldChrome.vue +131 -0
  50. package/dist/runtime/components/form-fields/PlacedFieldChrome.vue.d.ts +16 -0
  51. package/dist/runtime/components/modals/FreeTextModal.vue +27 -3
  52. package/dist/runtime/components/modals/SignatureDrawModal.vue +70 -15
  53. package/dist/runtime/components/panels/PlacedFieldSidebar.d.vue.ts +3 -0
  54. package/dist/runtime/components/panels/PlacedFieldSidebar.vue +505 -0
  55. package/dist/runtime/components/panels/PlacedFieldSidebar.vue.d.ts +3 -0
  56. package/dist/runtime/components/tools/ActionTools.vue +4 -5
  57. package/dist/runtime/components/tools/FormFieldTools.d.vue.ts +3 -0
  58. package/dist/runtime/components/tools/FormFieldTools.vue +35 -0
  59. package/dist/runtime/components/tools/FormFieldTools.vue.d.ts +3 -0
  60. package/dist/runtime/composables/useAnnotationEngine.d.ts +2 -0
  61. package/dist/runtime/composables/useAnnotationEngine.js +6 -2
  62. package/dist/runtime/composables/useAnnotationHistory.d.ts +1 -0
  63. package/dist/runtime/composables/useAnnotationHistory.js +10 -3
  64. package/dist/runtime/composables/useFormFields.d.ts +29 -2
  65. package/dist/runtime/composables/useFormFields.js +259 -5
  66. package/dist/runtime/composables/useInertiaPanzoom.d.ts +40 -0
  67. package/dist/runtime/composables/useInertiaPanzoom.js +475 -0
  68. package/dist/runtime/composables/usePageVirtualization.d.ts +9 -0
  69. package/dist/runtime/composables/usePageVirtualization.js +34 -3
  70. package/dist/runtime/composables/useViewerSearch.d.ts +1 -0
  71. package/dist/runtime/composables/useViewerSearch.js +15 -5
  72. package/dist/runtime/composables/useViewerState.d.ts +3 -0
  73. package/dist/runtime/composables/useViewerState.js +22 -1
  74. package/package.json +2 -2
@@ -7,10 +7,10 @@
7
7
  <template #body>
8
8
  <div class="flex flex-col gap-3">
9
9
  <UTextarea
10
+ ref="textareaRef"
10
11
  v-model="inputValue"
11
12
  placeholder="Start typing..."
12
13
  :rows="3"
13
- autofocus
14
14
  />
15
15
  <div class="flex items-center justify-between">
16
16
  <div class="flex gap-1">
@@ -22,6 +22,7 @@
22
22
  c === currentColor ? 'border-white ring-2 ring-blue-500' : 'border-transparent'
23
23
  "
24
24
  :style="{ backgroundColor: c }"
25
+ @pointerdown="onPreserveFocus"
25
26
  @click="currentColor = c"
26
27
  />
27
28
  </div>
@@ -39,14 +40,19 @@
39
40
  <UButton variant="ghost" color="neutral" @click="cancel">
40
41
  Cancel
41
42
  </UButton>
42
- <UButton :disabled="!inputValue.trim()" @click="submit">OK</UButton>
43
+ <UButton
44
+ :disabled="!inputValue.trim()"
45
+ @click="submit"
46
+ >
47
+ OK
48
+ </UButton>
43
49
  </div>
44
50
  </template>
45
51
  </UModal>
46
52
  </template>
47
53
 
48
54
  <script setup>
49
- import { ref, watch } from "vue";
55
+ import { ref, watch, nextTick } from "vue";
50
56
  import { defaultOptions } from "../../annotation/engine/config";
51
57
  const props = defineProps({
52
58
  open: { type: Boolean, required: true },
@@ -55,6 +61,20 @@ const props = defineProps({
55
61
  initialText: { type: String, required: false }
56
62
  });
57
63
  const emit = defineEmits(["update:open", "submit", "cancel"]);
64
+ const textareaRef = ref(null);
65
+ function focusTextarea() {
66
+ const instance = textareaRef.value;
67
+ if (!instance) return;
68
+ const el = instance.inputRef ?? instance.$el?.querySelector?.("textarea") ?? instance;
69
+ if (el && typeof el.focus === "function") {
70
+ el.focus();
71
+ const len = el.value?.length ?? 0;
72
+ try {
73
+ el.setSelectionRange(len, len);
74
+ } catch {
75
+ }
76
+ }
77
+ }
58
78
  const isOpen = ref(props.open);
59
79
  watch(
60
80
  () => props.open,
@@ -64,6 +84,7 @@ watch(
64
84
  inputValue.value = props.initialText ?? "";
65
85
  currentColor.value = props.defaultColor;
66
86
  currentFontSize.value = String(props.defaultFontSize);
87
+ nextTick(() => requestAnimationFrame(() => focusTextarea()));
67
88
  }
68
89
  }
69
90
  );
@@ -86,4 +107,7 @@ function submit() {
86
107
  function cancel() {
87
108
  emit("cancel");
88
109
  }
110
+ function onPreserveFocus(e) {
111
+ if (e.pointerType === "mouse") e.preventDefault();
112
+ }
89
113
  </script>
@@ -1,16 +1,15 @@
1
1
  <template>
2
- <UModal v-model:open="isOpen" title="Draw Signature" :ui="{ content: 'sm:max-w-lg' }">
2
+ <UModal v-model:open="isOpen" title="Draw Signature" :ui="{ content: 'sm:max-w-2xl' }">
3
3
  <template #body>
4
4
  <div class="flex flex-col gap-3">
5
5
  <div
6
- class="border border-default rounded bg-white relative"
7
- :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }"
6
+ ref="canvasWrapEl"
7
+ class="border border-default rounded bg-white relative w-full"
8
+ :style="{ aspectRatio: `${canvasAspect}` }"
8
9
  >
9
10
  <canvas
10
11
  ref="canvasRef"
11
- :width="canvasWidth"
12
- :height="canvasHeight"
13
- class="cursor-crosshair"
12
+ class="cursor-crosshair block w-full h-full"
14
13
  @pointerdown="onPointerDown"
15
14
  @pointermove="onPointerMove"
16
15
  @pointerup="onPointerUp"
@@ -50,7 +49,7 @@
50
49
  </template>
51
50
 
52
51
  <script setup>
53
- import { ref, watch, nextTick } from "vue";
52
+ import { ref, watch, nextTick, onBeforeUnmount } from "vue";
54
53
  import { defaultOptions } from "../../annotation/engine/config";
55
54
  const props = defineProps({
56
55
  open: { type: Boolean, required: true }
@@ -64,21 +63,51 @@ watch(
64
63
  if (v) {
65
64
  hasDrawn.value = false;
66
65
  await nextTick();
66
+ syncCanvasSize();
67
67
  clearCanvas();
68
68
  }
69
69
  }
70
70
  );
71
71
  watch(isOpen, (v) => emit("update:open", v));
72
- const canvasWidth = defaultOptions.signature.WIDTH;
73
- const canvasHeight = defaultOptions.signature.HEIGHT;
72
+ const canvasAspect = `${defaultOptions.signature.WIDTH} / ${defaultOptions.signature.HEIGHT}`;
74
73
  const signatureColors = defaultOptions.signature.COLORS;
75
74
  const canvasRef = ref(null);
75
+ const canvasWrapEl = ref(null);
76
76
  const strokeColor = ref(signatureColors[0]);
77
77
  const hasDrawn = ref(false);
78
78
  let isDrawing = false;
79
+ function syncCanvasSize() {
80
+ const canvas = canvasRef.value;
81
+ const wrap = canvasWrapEl.value;
82
+ if (!canvas || !wrap) return;
83
+ const cssW = Math.round(wrap.clientWidth);
84
+ const cssH = Math.round(wrap.clientHeight);
85
+ if (cssW <= 0 || cssH <= 0) return;
86
+ const dpr = window.devicePixelRatio || 1;
87
+ const targetW = Math.round(cssW * dpr);
88
+ const targetH = Math.round(cssH * dpr);
89
+ if (canvas.width === targetW && canvas.height === targetH) return;
90
+ canvas.width = targetW;
91
+ canvas.height = targetH;
92
+ const ctx = canvas.getContext("2d");
93
+ ctx?.setTransform(dpr, 0, 0, dpr, 0, 0);
94
+ hasDrawn.value = false;
95
+ }
96
+ let resizeObserver = null;
97
+ watch(canvasWrapEl, (el) => {
98
+ resizeObserver?.disconnect();
99
+ resizeObserver = null;
100
+ if (!el || typeof ResizeObserver === "undefined") return;
101
+ resizeObserver = new ResizeObserver(() => syncCanvasSize());
102
+ resizeObserver.observe(el);
103
+ });
104
+ onBeforeUnmount(() => resizeObserver?.disconnect());
79
105
  function getCtx() {
80
106
  return canvasRef.value?.getContext("2d") ?? null;
81
107
  }
108
+ const STROKE_WIDTH = 2.5;
109
+ let lastPoint = null;
110
+ let lastMid = null;
82
111
  function onPointerDown(e) {
83
112
  isDrawing = true;
84
113
  hasDrawn.value = true;
@@ -86,26 +115,52 @@ function onPointerDown(e) {
86
115
  if (!ctx) return;
87
116
  e.target.setPointerCapture(e.pointerId);
88
117
  ctx.strokeStyle = strokeColor.value;
89
- ctx.lineWidth = 2;
118
+ ctx.fillStyle = strokeColor.value;
119
+ ctx.lineWidth = STROKE_WIDTH;
90
120
  ctx.lineCap = "round";
91
121
  ctx.lineJoin = "round";
122
+ const p = { x: e.offsetX, y: e.offsetY };
123
+ lastPoint = p;
124
+ lastMid = p;
92
125
  ctx.beginPath();
93
- ctx.moveTo(e.offsetX, e.offsetY);
126
+ ctx.arc(p.x, p.y, STROKE_WIDTH / 2, 0, Math.PI * 2);
127
+ ctx.fill();
94
128
  }
95
129
  function onPointerMove(e) {
96
- if (!isDrawing) return;
130
+ if (!isDrawing || !lastPoint || !lastMid) return;
97
131
  const ctx = getCtx();
98
132
  if (!ctx) return;
99
- ctx.lineTo(e.offsetX, e.offsetY);
133
+ const p = { x: e.offsetX, y: e.offsetY };
134
+ const mid = { x: (lastPoint.x + p.x) / 2, y: (lastPoint.y + p.y) / 2 };
135
+ ctx.beginPath();
136
+ ctx.moveTo(lastMid.x, lastMid.y);
137
+ ctx.quadraticCurveTo(lastPoint.x, lastPoint.y, mid.x, mid.y);
100
138
  ctx.stroke();
139
+ lastPoint = p;
140
+ lastMid = mid;
101
141
  }
102
142
  function onPointerUp() {
143
+ if (isDrawing && lastPoint && lastMid) {
144
+ const ctx = getCtx();
145
+ if (ctx) {
146
+ ctx.beginPath();
147
+ ctx.moveTo(lastMid.x, lastMid.y);
148
+ ctx.lineTo(lastPoint.x, lastPoint.y);
149
+ ctx.stroke();
150
+ }
151
+ }
103
152
  isDrawing = false;
153
+ lastPoint = null;
154
+ lastMid = null;
104
155
  }
105
156
  function clearCanvas() {
157
+ const canvas = canvasRef.value;
106
158
  const ctx = getCtx();
107
- if (!ctx) return;
108
- ctx.clearRect(0, 0, canvasWidth, canvasHeight);
159
+ if (!canvas || !ctx) return;
160
+ ctx.save();
161
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
162
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
163
+ ctx.restore();
109
164
  hasDrawn.value = false;
110
165
  }
111
166
  function submit() {
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;