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
@@ -5,7 +5,7 @@
5
5
  <UPopover>
6
6
  <UButton icon="i-lucide-menu" variant="ghost" color="neutral" size="xs" data-testid="viewer-menu" />
7
7
  <template #content>
8
- <div class="p-1">
8
+ <div class="p-1 flex flex-col gap-0.5">
9
9
  <UButton
10
10
  icon="i-lucide-download"
11
11
  label="Download"
@@ -16,6 +16,16 @@
16
16
  data-testid="viewer-download"
17
17
  @click="onDownload"
18
18
  />
19
+ <UButton
20
+ :icon="state.shapeDetection.value ? 'i-lucide-square-check-big' : 'i-lucide-square-dashed'"
21
+ :label="state.shapeDetection.value ? 'Disable form field detection' : 'Detect form fields'"
22
+ :variant="state.shapeDetection.value ? 'soft' : 'ghost'"
23
+ :color="state.shapeDetection.value ? 'primary' : 'neutral'"
24
+ size="xs"
25
+ class="w-full justify-start"
26
+ data-testid="viewer-toggle-shape-detection"
27
+ @click="state.shapeDetection.value = !state.shapeDetection.value"
28
+ />
19
29
  </div>
20
30
  </template>
21
31
  </UPopover>
@@ -30,6 +40,16 @@
30
40
 
31
41
  <HandTool />
32
42
  <MarqueeTool />
43
+
44
+ <UButton
45
+ icon="i-lucide-form-input"
46
+ :variant="state.formEditMode.value ? 'soft' : 'ghost'"
47
+ :color="state.formEditMode.value ? 'primary' : 'neutral'"
48
+ size="xs"
49
+ :title="state.formEditMode.value ? 'Exit form-edit mode' : 'Enter form-edit mode'"
50
+ data-testid="form-edit-toggle"
51
+ @click="state.setFormEditMode(!state.formEditMode.value)"
52
+ />
33
53
  </template>
34
54
 
35
55
  <div class="ml-auto flex items-center gap-2">
@@ -45,7 +65,8 @@
45
65
  </div>
46
66
 
47
67
  <div class="justify-self-center">
48
- <DrawingTools :style-version="styleVersion" />
68
+ <FormFieldTools v-if="state.formEditMode.value" />
69
+ <DrawingTools v-else :style-version="styleVersion" />
49
70
  </div>
50
71
 
51
72
  <div class="justify-self-end flex items-center gap-1">
@@ -63,6 +84,7 @@ import ZoomControls from "./tools/ZoomControls.vue";
63
84
  import HandTool from "./tools/HandTool.vue";
64
85
  import MarqueeTool from "./tools/MarqueeTool.vue";
65
86
  import DrawingTools from "./tools/DrawingTools.vue";
87
+ import FormFieldTools from "./tools/FormFieldTools.vue";
66
88
  import ActionTools from "./tools/ActionTools.vue";
67
89
  import PageInfo from "./tools/PageInfo.vue";
68
90
  import SearchTool from "./tools/SearchTool.vue";
@@ -12,6 +12,7 @@
12
12
 
13
13
  <script setup>
14
14
  import { computed } from "vue";
15
+ import { decodeFontName } from "../../annotation/font-style";
15
16
  import { useFormFields } from "../../composables/useFormFields";
16
17
  import { useViewerState } from "../../composables/useViewerState";
17
18
  const props = defineProps({
@@ -19,12 +20,23 @@ const props = defineProps({
19
20
  });
20
21
  const formFields = useFormFields();
21
22
  const state = useViewerState();
22
- const isReadOnly = computed(() => state.readonly.value || props.field.readOnly);
23
+ const isReadOnly = computed(
24
+ () => state.readonly.value || props.field.readOnly || formFields.isFieldLocked(props.field.id)
25
+ );
26
+ const FONT_BORDER_SIZE = 2;
27
+ const LINE_HEIGHT_FACTOR = 1.35;
28
+ const DEFAULT_FIELD_FONT_SIZE = 9;
23
29
  const buttonStyle = computed(() => {
24
30
  const style = {};
25
- if (props.field.fontSize && props.field.fontSize > 0) {
26
- style.fontSize = `${props.field.fontSize}px`;
27
- }
31
+ const declared = props.field.fontSize && props.field.fontSize > 0 ? props.field.fontSize : DEFAULT_FIELD_FONT_SIZE;
32
+ const rect = props.field.rect;
33
+ const rectHeight = Math.abs(rect[3] - rect[1] - FONT_BORDER_SIZE);
34
+ const computed2 = Math.min(declared, rectHeight / LINE_HEIGHT_FACTOR);
35
+ style.fontSize = `${Math.round(10 * computed2) / 10}px`;
36
+ const fontStyle = decodeFontName(props.field.fontName);
37
+ style.fontFamily = fontStyle.fontFamily;
38
+ if (fontStyle.fontWeight !== "normal") style.fontWeight = fontStyle.fontWeight;
39
+ if (fontStyle.fontStyle !== "normal") style.fontStyle = fontStyle.fontStyle;
28
40
  if (props.field.color && props.field.color.length >= 3) {
29
41
  style.color = `rgb(${props.field.color[0]}, ${props.field.color[1]}, ${props.field.color[2]})`;
30
42
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <!-- Detected shape: custom × icon on transparent background -->
2
+ <!-- Detected shape: lightweight × icon on transparent background -->
3
3
  <div
4
4
  v-if="isDetected"
5
5
  class="kviewer-form-checkbox kviewer-form-checkbox--detected"
@@ -29,20 +29,30 @@
29
29
  </svg>
30
30
  </div>
31
31
 
32
- <!-- Real PDF form field: native checkbox -->
33
- <div v-else class="kviewer-form-checkbox">
34
- <input
35
- type="checkbox"
36
- :checked="isChecked"
37
- :disabled="isReadOnly"
38
- :required="props.field.required"
39
- @change="onChange"
40
- >
32
+ <!-- Real PDF form field: render a custom box that draws the matching
33
+ Unicode glyph for whichever `/MK /CA` style is set (default 'check'
34
+ included). Native HTML checkboxes can't render cross/diamond/star/etc,
35
+ and rendering the default check via the same path keeps the look
36
+ consistent across all styles. -->
37
+ <div
38
+ v-else
39
+ class="kviewer-form-checkbox kviewer-form-checkbox--styled"
40
+ :class="{ 'kviewer-form-checkbox--checked': isChecked }"
41
+ role="checkbox"
42
+ :aria-checked="isChecked"
43
+ :aria-disabled="isReadOnly"
44
+ tabindex="0"
45
+ @click="toggle"
46
+ @keydown.space.prevent="toggle"
47
+ @keydown.enter.prevent="toggle"
48
+ >
49
+ <span v-if="isChecked" class="kviewer-form-checkbox__glyph">{{ styledGlyph }}</span>
41
50
  </div>
42
51
  </template>
43
52
 
44
53
  <script setup>
45
54
  import { computed } from "vue";
55
+ import { CHECKBOX_STYLE_TABLE } from "../../annotation/checkbox-styles";
46
56
  import { useFormFields } from "../../composables/useFormFields";
47
57
  import { useViewerState } from "../../composables/useViewerState";
48
58
  const props = defineProps({
@@ -51,17 +61,23 @@ const props = defineProps({
51
61
  const formFields = useFormFields();
52
62
  const state = useViewerState();
53
63
  const isDetected = computed(() => props.field.shapeType != null);
54
- const isReadOnly = computed(() => state.readonly.value || props.field.readOnly);
64
+ const isReadOnly = computed(
65
+ () => state.readonly.value || props.field.readOnly || formFields.isFieldLocked(props.field.id)
66
+ );
55
67
  const isChecked = computed(() => {
56
68
  const fv = formFields.getFieldValue(props.field.id);
57
69
  return fv?.value === true;
58
70
  });
71
+ const styledGlyph = computed(() => {
72
+ const style = props.field.checkboxStyle ?? "check";
73
+ return CHECKBOX_STYLE_TABLE[style]?.glyph ?? CHECKBOX_STYLE_TABLE.check.glyph;
74
+ });
59
75
  function toggle() {
60
76
  if (isReadOnly.value) return;
61
77
  formFields.setFieldValue(props.field.id, !isChecked.value);
62
78
  }
63
- function onChange(event) {
64
- const target = event.target;
65
- formFields.setFieldValue(props.field.id, target.checked);
66
- }
67
79
  </script>
80
+
81
+ <style>
82
+ .kviewer-form-checkbox--styled{align-items:center;background:#fff;border:1px solid #444;cursor:pointer;display:flex;height:100%;justify-content:center;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:100%}.kviewer-form-checkbox--styled[aria-disabled=true]{cursor:not-allowed;opacity:.6}.kviewer-form-checkbox__glyph{color:#000;font-size:clamp(8px,88cqh,64px);font-variant-emoji:text;line-height:1;pointer-events:none}.kviewer-form-checkbox--styled{container-type:size}
83
+ </style>
@@ -74,7 +74,9 @@ const props = defineProps({
74
74
  });
75
75
  const formFields = useFormFields();
76
76
  const state = useViewerState();
77
- const isReadOnly = computed(() => state.readonly.value || props.field.readOnly);
77
+ const isReadOnly = computed(
78
+ () => state.readonly.value || props.field.readOnly || formFields.isFieldLocked(props.field.id)
79
+ );
78
80
  const datalistId = computed(() => `kviewer-datalist-${props.field.id}`);
79
81
  const listBoxSize = computed(() => {
80
82
  const optCount = props.field.options?.length ?? 0;
@@ -2,7 +2,18 @@ import type { FormFieldDefinition } from '../../annotation/engine/types.js';
2
2
  type __VLS_Props = {
3
3
  field: FormFieldDefinition;
4
4
  pageHeight: number;
5
+ scale: number;
6
+ /** PDF user-space origin (view[0], view[1]). /Rect coords are in
7
+ * default user space; the canvas top-left corresponds to PDF
8
+ * (viewOffsetX, viewOffsetY + pageHeight), so we have to subtract. */
9
+ viewOffsetX?: number;
10
+ viewOffsetY?: number;
11
+ selected: boolean;
5
12
  };
6
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
14
+ select: () => any;
15
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
16
+ onSelect?: (() => any) | undefined;
17
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
18
  declare const _default: typeof __VLS_export;
8
19
  export default _default;
@@ -1,33 +1,65 @@
1
1
  <template>
2
2
  <div
3
3
  class="kviewer-form-field"
4
+ :class="{
5
+ 'kviewer-form-field--editable': showChrome,
6
+ 'kviewer-form-field--placed': isPlaced,
7
+ 'kviewer-form-field--selected': props.selected
8
+ }"
4
9
  :style="positionStyle"
5
10
  >
6
- <FormTextField v-if="props.field.fieldType === 'text'" :field="props.field" />
7
- <FormCheckbox v-else-if="props.field.fieldType === 'checkbox'" :field="props.field" />
8
- <FormRadioButton v-else-if="props.field.fieldType === 'radio'" :field="props.field" />
9
- <FormDropdown v-else-if="props.field.fieldType === 'dropdown'" :field="props.field" />
10
- <FormSignatureField v-else-if="props.field.fieldType === 'signature'" :field="props.field" />
11
- <FormButton v-else-if="props.field.fieldType === 'button'" :field="props.field" />
11
+ <div
12
+ class="kviewer-form-field__body"
13
+ :class="{ 'kviewer-form-field__body--locked': isFormEditMode }"
14
+ >
15
+ <FormTextField v-if="props.field.fieldType === 'text'" :field="props.field" />
16
+ <FormCheckbox v-else-if="props.field.fieldType === 'checkbox'" :field="props.field" />
17
+ <FormRadioButton v-else-if="props.field.fieldType === 'radio'" :field="props.field" />
18
+ <FormDropdown v-else-if="props.field.fieldType === 'dropdown'" :field="props.field" />
19
+ <FormSignatureField v-else-if="props.field.fieldType === 'signature'" :field="props.field" />
20
+ <FormButton v-else-if="props.field.fieldType === 'button'" :field="props.field" />
21
+ </div>
22
+
23
+ <PlacedFieldChrome
24
+ v-if="showChrome"
25
+ :field="props.field"
26
+ :selected="props.selected"
27
+ :scale="props.scale"
28
+ :page-height="props.pageHeight"
29
+ @select="emit('select')"
30
+ />
12
31
  </div>
13
32
  </template>
14
33
 
15
34
  <script setup>
16
35
  import { computed } from "vue";
36
+ import { useViewerState } from "../../composables/useViewerState";
17
37
  import FormTextField from "./FormTextField.vue";
18
38
  import FormCheckbox from "./FormCheckbox.vue";
19
39
  import FormRadioButton from "./FormRadioButton.vue";
20
40
  import FormDropdown from "./FormDropdown.vue";
21
41
  import FormSignatureField from "./FormSignatureField.vue";
22
42
  import FormButton from "./FormButton.vue";
43
+ import PlacedFieldChrome from "./PlacedFieldChrome.vue";
23
44
  const props = defineProps({
24
45
  field: { type: Object, required: true },
25
- pageHeight: { type: Number, required: true }
46
+ pageHeight: { type: Number, required: true },
47
+ scale: { type: Number, required: true },
48
+ viewOffsetX: { type: Number, required: false },
49
+ viewOffsetY: { type: Number, required: false },
50
+ selected: { type: Boolean, required: true }
26
51
  });
52
+ const emit = defineEmits(["select"]);
53
+ const state = useViewerState();
54
+ const isPlaced = computed(() => props.field.origin === "placed");
55
+ const isFormEditMode = computed(() => state.formEditMode.value);
56
+ const showChrome = computed(() => isFormEditMode.value);
27
57
  const positionStyle = computed(() => {
28
58
  const rect = props.field.rect;
29
- const left = rect[0];
30
- const top = props.pageHeight - rect[3];
59
+ const vx = props.viewOffsetX ?? 0;
60
+ const vy = props.viewOffsetY ?? 0;
61
+ const left = rect[0] - vx;
62
+ const top = props.pageHeight + vy - rect[3];
31
63
  const width = rect[2] - rect[0];
32
64
  const height = rect[3] - rect[1];
33
65
  return {
@@ -39,3 +71,7 @@ const positionStyle = computed(() => {
39
71
  };
40
72
  });
41
73
  </script>
74
+
75
+ <style>
76
+ .kviewer-form-field__body{height:100%;width:100%}.kviewer-form-field__body--locked{pointer-events:none}.kviewer-form-field--editable{outline:1px dashed rgba(22,119,255,.45);outline-offset:0}.kviewer-form-field--editable.kviewer-form-field--placed{outline-color:rgba(22,119,255,.75)}.kviewer-form-field--editable.kviewer-form-field--selected{outline:none}
77
+ </style>
@@ -2,7 +2,18 @@ import type { FormFieldDefinition } from '../../annotation/engine/types.js';
2
2
  type __VLS_Props = {
3
3
  field: FormFieldDefinition;
4
4
  pageHeight: number;
5
+ scale: number;
6
+ /** PDF user-space origin (view[0], view[1]). /Rect coords are in
7
+ * default user space; the canvas top-left corresponds to PDF
8
+ * (viewOffsetX, viewOffsetY + pageHeight), so we have to subtract. */
9
+ viewOffsetX?: number;
10
+ viewOffsetY?: number;
11
+ selected: boolean;
5
12
  };
6
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
14
+ select: () => any;
15
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
16
+ onSelect?: (() => any) | undefined;
17
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
18
  declare const _default: typeof __VLS_export;
8
19
  export default _default;
@@ -21,7 +21,9 @@ const props = defineProps({
21
21
  });
22
22
  const formFields = useFormFields();
23
23
  const state = useViewerState();
24
- const isReadOnly = computed(() => state.readonly.value || props.field.readOnly);
24
+ const isReadOnly = computed(
25
+ () => state.readonly.value || props.field.readOnly || formFields.isFieldLocked(props.field.id)
26
+ );
25
27
  const isSelected = computed(() => {
26
28
  const fv = formFields.getFieldValue(props.field.id);
27
29
  if (!fv) return false;
@@ -11,7 +11,7 @@
11
11
  alt="Signature"
12
12
  >
13
13
  <span v-else class="kviewer-form-signature__placeholder">
14
- Click to sign
14
+ {{ props.field.promptText || "Click to sign" }}
15
15
  </span>
16
16
  </div>
17
17
 
@@ -43,6 +43,7 @@ const signatureUrl = computed(() => {
43
43
  const hasSigned = computed(() => !!signatureUrl.value);
44
44
  async function onClickSign() {
45
45
  if (props.field.readOnly || state.readonly.value) return;
46
+ if (formFields.isFieldLocked(props.field.id)) return;
46
47
  if (state.signatures.value.length > 0) {
47
48
  const sig = state.signatures.value[0];
48
49
  if (sig) {
@@ -19,11 +19,13 @@
19
19
  :style="fieldStyle"
20
20
  class="kviewer-form-input"
21
21
  @input="onInput"
22
+ @scroll="onScroll"
22
23
  >
23
24
  </template>
24
25
 
25
26
  <script setup>
26
27
  import { computed } from "vue";
28
+ import { decodeFontName } from "../../annotation/font-style";
27
29
  import { useFormFields } from "../../composables/useFormFields";
28
30
  import { useViewerState } from "../../composables/useViewerState";
29
31
  const props = defineProps({
@@ -31,18 +33,37 @@ const props = defineProps({
31
33
  });
32
34
  const formFields = useFormFields();
33
35
  const state = useViewerState();
34
- const isReadOnly = computed(() => state.readonly.value || props.field.readOnly);
36
+ const isReadOnly = computed(
37
+ () => state.readonly.value || props.field.readOnly || formFields.isFieldLocked(props.field.id)
38
+ );
35
39
  const currentValue = computed(() => {
36
40
  const fv = formFields.getFieldValue(props.field.id);
37
41
  return typeof fv?.value === "string" ? fv.value : "";
38
42
  });
43
+ const FONT_BORDER_SIZE = 2;
44
+ const LINE_HEIGHT_FACTOR = 1.35;
45
+ const DEFAULT_FIELD_FONT_SIZE = 9;
39
46
  const fieldStyle = computed(() => {
40
47
  const style = {};
41
- if (props.field.fontSize && props.field.fontSize > 0) {
42
- style.fontSize = `${props.field.fontSize}px`;
48
+ const declared = props.field.fontSize && props.field.fontSize > 0 ? props.field.fontSize : DEFAULT_FIELD_FONT_SIZE;
49
+ const rect = props.field.rect;
50
+ const rectHeight = Math.abs(rect[3] - rect[1] - FONT_BORDER_SIZE);
51
+ let computed2;
52
+ if (props.field.multiLine) {
53
+ const numberOfLines = Math.max(
54
+ 1,
55
+ Math.round(rectHeight / (LINE_HEIGHT_FACTOR * declared))
56
+ );
57
+ const lineHeight = rectHeight / numberOfLines;
58
+ computed2 = Math.min(declared, lineHeight / LINE_HEIGHT_FACTOR);
43
59
  } else {
44
- style.fontSize = "inherit";
60
+ computed2 = Math.min(declared, rectHeight / LINE_HEIGHT_FACTOR);
45
61
  }
62
+ style.fontSize = `${Math.round(10 * computed2) / 10}px`;
63
+ const fontStyle = decodeFontName(props.field.fontName);
64
+ style.fontFamily = fontStyle.fontFamily;
65
+ if (fontStyle.fontWeight !== "normal") style.fontWeight = fontStyle.fontWeight;
66
+ if (fontStyle.fontStyle !== "normal") style.fontStyle = fontStyle.fontStyle;
46
67
  if (props.field.color && props.field.color.length >= 3) {
47
68
  style.color = `rgb(${props.field.color[0]}, ${props.field.color[1]}, ${props.field.color[2]})`;
48
69
  }
@@ -54,16 +75,35 @@ const fieldStyle = computed(() => {
54
75
  style.textAlign = alignMap[props.field.textAlignment] ?? "left";
55
76
  }
56
77
  if (props.field.comb && props.field.maxLen && props.field.maxLen > 0) {
57
- const rect = props.field.rect;
58
78
  const fieldWidth = rect[2] - rect[0];
59
79
  const cellWidth = fieldWidth / props.field.maxLen;
60
- style.letterSpacing = `${cellWidth - (props.field.fontSize ?? 12) * 0.6}px`;
61
- style.fontFamily = "monospace";
80
+ const charWidth = computed2 * 0.6;
81
+ style.fontFamily = '"Courier New", Courier, monospace';
82
+ style.fontWeight = "700";
83
+ style.textAlign = "left";
84
+ style.letterSpacing = `${cellWidth - charWidth}px`;
85
+ style.paddingLeft = `${Math.max(0, (cellWidth - charWidth) / 2)}px`;
86
+ style.paddingRight = "0";
87
+ style.paddingTop = "0";
88
+ style.paddingBottom = "0";
89
+ style.borderLeftWidth = "0";
90
+ style.backgroundImage = "linear-gradient(to right, rgba(0, 0, 0, 0.55) 1px, transparent 1px)";
91
+ style.backgroundSize = `${100 / props.field.maxLen}% 100%`;
92
+ style.backgroundRepeat = "repeat-x";
93
+ style.borderTop = "1px solid rgba(0, 0, 0, 0.55)";
94
+ style.borderBottom = "1px solid rgba(0, 0, 0, 0.55)";
95
+ style.borderRight = "1px solid rgba(0, 0, 0, 0.55)";
62
96
  }
63
97
  return style;
64
98
  });
65
99
  function onInput(event) {
66
100
  const target = event.target;
67
101
  formFields.setFieldValue(props.field.id, target.value);
102
+ if (props.field.comb) target.scrollLeft = 0;
103
+ }
104
+ function onScroll(event) {
105
+ if (!props.field.comb) return;
106
+ const target = event.target;
107
+ if (target.scrollLeft !== 0) target.scrollLeft = 0;
68
108
  }
69
109
  </script>
@@ -0,0 +1,16 @@
1
+ import type { FormFieldDefinition } from '../../annotation/engine/types.js';
2
+ type __VLS_Props = {
3
+ field: FormFieldDefinition;
4
+ selected: boolean;
5
+ /** CSS pixels per PDF unit for the current page. */
6
+ scale: number;
7
+ /** PDF-space page height (kept for parity; unused here). */
8
+ pageHeight: number;
9
+ };
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
11
+ select: () => any;
12
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
13
+ onSelect?: (() => any) | undefined;
14
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;
@@ -0,0 +1,131 @@
1
+ <template>
2
+ <!-- The whole chrome is the interactive surface in form-edit mode:
3
+ click to select, drag anywhere to move, plus a label bar above and
4
+ eight resize handles when selected. -->
5
+ <div
6
+ ref="rootEl"
7
+ class="kviewer-placed-chrome"
8
+ :class="{ 'kviewer-placed-chrome--selected': selected }"
9
+ :style="{ '--kvw-handle-zoom': handleZoom }"
10
+ @pointerdown.stop="onChromePointerDown"
11
+ @click.stop
12
+ >
13
+ <div
14
+ v-if="selected"
15
+ class="kviewer-placed-chrome__grip"
16
+ :title="field.fieldName"
17
+ >
18
+ <UIcon name="i-lucide-grip-vertical" class="kviewer-placed-chrome__grip-dots" />
19
+ <span class="kviewer-placed-chrome__grip-label">{{ field.fieldName }}</span>
20
+ </div>
21
+
22
+ <template v-if="selected">
23
+ <div
24
+ v-for="h in handles"
25
+ :key="h.name"
26
+ class="kviewer-placed-chrome__handle"
27
+ :class="`kviewer-placed-chrome__handle--${h.name}`"
28
+ :style="{ cursor: h.cursor }"
29
+ @pointerdown.stop="(e) => onHandlePointerDown(e, h.name)"
30
+ />
31
+ </template>
32
+ </div>
33
+ </template>
34
+
35
+ <script setup>
36
+ import { computed, ref } from "vue";
37
+ import { useFormFields } from "../../composables/useFormFields";
38
+ import { useViewerState } from "../../composables/useViewerState";
39
+ const rootEl = ref(null);
40
+ const viewerState = useViewerState();
41
+ const handleZoom = computed(() => {
42
+ const totalZoom = (props.scale || 1) * (viewerState.visualZoom.value || 1);
43
+ return Math.max(0.4, 1 / totalZoom).toFixed(3);
44
+ });
45
+ const props = defineProps({
46
+ field: { type: Object, required: true },
47
+ selected: { type: Boolean, required: true },
48
+ scale: { type: Number, required: true },
49
+ pageHeight: { type: Number, required: true }
50
+ });
51
+ const emit = defineEmits(["select"]);
52
+ const formFields = useFormFields();
53
+ const handles = [
54
+ { name: "n", cursor: "ns-resize" },
55
+ { name: "s", cursor: "ns-resize" },
56
+ { name: "e", cursor: "ew-resize" },
57
+ { name: "w", cursor: "ew-resize" },
58
+ { name: "ne", cursor: "nesw-resize" },
59
+ { name: "nw", cursor: "nwse-resize" },
60
+ { name: "se", cursor: "nwse-resize" },
61
+ { name: "sw", cursor: "nesw-resize" }
62
+ ];
63
+ function effectiveScale() {
64
+ const el = rootEl.value;
65
+ if (!el) return props.scale;
66
+ const rect = el.getBoundingClientRect();
67
+ const pdfWidth = props.field.rect[2] - props.field.rect[0];
68
+ if (pdfWidth <= 0 || rect.width <= 0) return props.scale;
69
+ return rect.width / pdfWidth;
70
+ }
71
+ const DRAG_THRESHOLD_PX = 3;
72
+ function onChromePointerDown(e) {
73
+ const startX = e.clientX;
74
+ const startY = e.clientY;
75
+ const startRect = [...props.field.rect];
76
+ const s = effectiveScale();
77
+ let dragging = false;
78
+ const onMove = (ev) => {
79
+ if (!dragging) {
80
+ const adx = Math.abs(ev.clientX - startX);
81
+ const ady = Math.abs(ev.clientY - startY);
82
+ if (adx < DRAG_THRESHOLD_PX && ady < DRAG_THRESHOLD_PX) return;
83
+ dragging = true;
84
+ }
85
+ const dx = (ev.clientX - startX) / s;
86
+ const dy = (ev.clientY - startY) / s;
87
+ const pdfDy = -dy;
88
+ const next = [
89
+ startRect[0] + dx,
90
+ startRect[1] + pdfDy,
91
+ startRect[2] + dx,
92
+ startRect[3] + pdfDy
93
+ ];
94
+ formFields.updatePlacedField(props.field.id, { rect: next });
95
+ };
96
+ const onUp = () => {
97
+ window.removeEventListener("pointermove", onMove);
98
+ window.removeEventListener("pointerup", onUp);
99
+ if (!dragging) emit("select");
100
+ };
101
+ window.addEventListener("pointermove", onMove);
102
+ window.addEventListener("pointerup", onUp);
103
+ }
104
+ function onHandlePointerDown(e, name) {
105
+ const startX = e.clientX;
106
+ const startY = e.clientY;
107
+ const [sx1, sy1, sx2, sy2] = props.field.rect;
108
+ const s = effectiveScale();
109
+ const onMove = (ev) => {
110
+ const dx = (ev.clientX - startX) / s;
111
+ const dy = (ev.clientY - startY) / s;
112
+ const pdfDy = -dy;
113
+ let x1 = sx1, y1 = sy1, x2 = sx2, y2 = sy2;
114
+ if (name.includes("n")) y2 = Math.max(y1 + 4, sy2 + pdfDy);
115
+ if (name.includes("s")) y1 = Math.min(y2 - 4, sy1 + pdfDy);
116
+ if (name.includes("e")) x2 = Math.max(x1 + 4, sx2 + dx);
117
+ if (name.includes("w")) x1 = Math.min(x2 - 4, sx1 + dx);
118
+ formFields.updatePlacedField(props.field.id, { rect: [x1, y1, x2, y2] });
119
+ };
120
+ const onUp = () => {
121
+ window.removeEventListener("pointermove", onMove);
122
+ window.removeEventListener("pointerup", onUp);
123
+ };
124
+ window.addEventListener("pointermove", onMove);
125
+ window.addEventListener("pointerup", onUp);
126
+ }
127
+ </script>
128
+
129
+ <style>
130
+ .kviewer-placed-chrome{cursor:move;inset:0;pointer-events:auto;position:absolute;touch-action:none}.kviewer-placed-chrome--selected{outline:1.5px dashed #1677ff;outline-offset:0}.kviewer-placed-chrome__grip{align-items:center;background:rgba(22,119,255,.15);border:1px solid rgba(22,119,255,.4);border-radius:calc(3px*var(--kvw-handle-zoom, 1));bottom:calc(100% + 3px*var(--kvw-handle-zoom, 1));color:#1677ff;cursor:move;display:flex;font-size:calc(9px*var(--kvw-handle-zoom, 1));gap:calc(3px*var(--kvw-handle-zoom, 1));height:calc(16px*var(--kvw-handle-zoom, 1));left:0;line-height:1;overflow:hidden;padding:0 calc(6px*var(--kvw-handle-zoom, 1)) 0 calc(2px*var(--kvw-handle-zoom, 1));pointer-events:auto;position:absolute;right:0;touch-action:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.kviewer-placed-chrome__grip-dots{color:#1677ff;flex:0 0 auto;height:calc(10px*var(--kvw-handle-zoom, 1));width:calc(10px*var(--kvw-handle-zoom, 1))}.kviewer-placed-chrome__grip-label{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.kviewer-placed-chrome__handle{background:#fff;border:1px solid #1677ff;border-radius:2px;height:calc(8px*var(--kvw-handle-zoom, 1));pointer-events:auto;position:absolute;touch-action:none;width:calc(8px*var(--kvw-handle-zoom, 1))}.kviewer-placed-chrome__handle:before{content:"";inset:calc(-8px*var(--kvw-handle-zoom, 1));position:absolute}.kviewer-placed-chrome__handle--n{left:50%;top:calc(-4px*var(--kvw-handle-zoom, 1));transform:translateX(-50%)}.kviewer-placed-chrome__handle--s{bottom:calc(-4px*var(--kvw-handle-zoom, 1));left:50%;transform:translateX(-50%)}.kviewer-placed-chrome__handle--e{right:calc(-4px*var(--kvw-handle-zoom, 1));top:50%;transform:translateY(-50%)}.kviewer-placed-chrome__handle--w{left:calc(-4px*var(--kvw-handle-zoom, 1));top:50%;transform:translateY(-50%)}.kviewer-placed-chrome__handle--ne{right:calc(-4px*var(--kvw-handle-zoom, 1));top:calc(-4px*var(--kvw-handle-zoom, 1))}.kviewer-placed-chrome__handle--nw{left:calc(-4px*var(--kvw-handle-zoom, 1));top:calc(-4px*var(--kvw-handle-zoom, 1))}.kviewer-placed-chrome__handle--se{bottom:calc(-4px*var(--kvw-handle-zoom, 1));right:calc(-4px*var(--kvw-handle-zoom, 1))}.kviewer-placed-chrome__handle--sw{bottom:calc(-4px*var(--kvw-handle-zoom, 1));left:calc(-4px*var(--kvw-handle-zoom, 1))}
131
+ </style>
@@ -0,0 +1,16 @@
1
+ import type { FormFieldDefinition } from '../../annotation/engine/types.js';
2
+ type __VLS_Props = {
3
+ field: FormFieldDefinition;
4
+ selected: boolean;
5
+ /** CSS pixels per PDF unit for the current page. */
6
+ scale: number;
7
+ /** PDF-space page height (kept for parity; unused here). */
8
+ pageHeight: number;
9
+ };
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
11
+ select: () => any;
12
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
13
+ onSelect?: (() => any) | undefined;
14
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;