kviewer 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.
- package/README.md +134 -0
- package/dist/module.d.mts +15 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +26 -0
- package/dist/runtime/annotation/engine/config.d.ts +52 -0
- package/dist/runtime/annotation/engine/config.js +283 -0
- package/dist/runtime/annotation/engine/const.d.ts +6 -0
- package/dist/runtime/annotation/engine/const.js +7 -0
- package/dist/runtime/annotation/engine/cursor-preview.d.ts +2 -0
- package/dist/runtime/annotation/engine/cursor-preview.js +88 -0
- package/dist/runtime/annotation/engine/editor/editor.d.ts +69 -0
- package/dist/runtime/annotation/engine/editor/editor.js +233 -0
- package/dist/runtime/annotation/engine/editor/selector.d.ts +74 -0
- package/dist/runtime/annotation/engine/editor/selector.js +594 -0
- package/dist/runtime/annotation/engine/import-normalize.d.ts +5 -0
- package/dist/runtime/annotation/engine/import-normalize.js +99 -0
- package/dist/runtime/annotation/engine/input-device.d.ts +53 -0
- package/dist/runtime/annotation/engine/input-device.js +64 -0
- package/dist/runtime/annotation/engine/painter.d.ts +97 -0
- package/dist/runtime/annotation/engine/painter.js +591 -0
- package/dist/runtime/annotation/engine/store.d.ts +11 -0
- package/dist/runtime/annotation/engine/store.js +47 -0
- package/dist/runtime/annotation/engine/tools/arrow.d.ts +22 -0
- package/dist/runtime/annotation/engine/tools/arrow.js +126 -0
- package/dist/runtime/annotation/engine/tools/circle.d.ts +45 -0
- package/dist/runtime/annotation/engine/tools/circle.js +148 -0
- package/dist/runtime/annotation/engine/tools/cloud.d.ts +50 -0
- package/dist/runtime/annotation/engine/tools/cloud.js +244 -0
- package/dist/runtime/annotation/engine/tools/free-highlight.d.ts +43 -0
- package/dist/runtime/annotation/engine/tools/free-highlight.js +165 -0
- package/dist/runtime/annotation/engine/tools/free-text.d.ts +27 -0
- package/dist/runtime/annotation/engine/tools/free-text.js +114 -0
- package/dist/runtime/annotation/engine/tools/freehand.d.ts +44 -0
- package/dist/runtime/annotation/engine/tools/freehand.js +151 -0
- package/dist/runtime/annotation/engine/tools/highlight.d.ts +87 -0
- package/dist/runtime/annotation/engine/tools/highlight.js +215 -0
- package/dist/runtime/annotation/engine/tools/note.d.ts +9 -0
- package/dist/runtime/annotation/engine/tools/note.js +34 -0
- package/dist/runtime/annotation/engine/tools/rectangle.d.ts +45 -0
- package/dist/runtime/annotation/engine/tools/rectangle.js +142 -0
- package/dist/runtime/annotation/engine/tools/signature.d.ts +16 -0
- package/dist/runtime/annotation/engine/tools/signature.js +74 -0
- package/dist/runtime/annotation/engine/tools/stamp.d.ts +18 -0
- package/dist/runtime/annotation/engine/tools/stamp.js +94 -0
- package/dist/runtime/annotation/engine/types.d.ts +170 -0
- package/dist/runtime/annotation/engine/types.js +67 -0
- package/dist/runtime/annotation/engine/utils.d.ts +40 -0
- package/dist/runtime/annotation/engine/utils.js +257 -0
- package/dist/runtime/annotation/parsers/parseFormFields.d.ts +9 -0
- package/dist/runtime/annotation/parsers/parseFormFields.js +101 -0
- package/dist/runtime/annotation/pdf-export/download.d.ts +1 -0
- package/dist/runtime/annotation/pdf-export/download.js +10 -0
- package/dist/runtime/annotation/pdf-export/export-form-fields.d.ts +9 -0
- package/dist/runtime/annotation/pdf-export/export-form-fields.js +90 -0
- package/dist/runtime/annotation/pdf-export/export.d.ts +15 -0
- package/dist/runtime/annotation/pdf-export/export.js +145 -0
- package/dist/runtime/annotation/pdf-export/parse.d.ts +10 -0
- package/dist/runtime/annotation/pdf-export/parse.js +19 -0
- package/dist/runtime/annotation/pdf-export/parse_circle.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_circle.js +41 -0
- package/dist/runtime/annotation/pdf-export/parse_freetext.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_freetext.js +54 -0
- package/dist/runtime/annotation/pdf-export/parse_highlight.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_highlight.js +134 -0
- package/dist/runtime/annotation/pdf-export/parse_ink.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_ink.js +124 -0
- package/dist/runtime/annotation/pdf-export/parse_line.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_line.js +71 -0
- package/dist/runtime/annotation/pdf-export/parse_polyline.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_polyline.js +93 -0
- package/dist/runtime/annotation/pdf-export/parse_square.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_square.js +41 -0
- package/dist/runtime/annotation/pdf-export/parse_stamp.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_stamp.js +195 -0
- package/dist/runtime/annotation/pdf-export/parse_strikeout.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_strikeout.js +59 -0
- package/dist/runtime/annotation/pdf-export/parse_text.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_text.js +42 -0
- package/dist/runtime/annotation/pdf-export/parse_underline.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_underline.js +59 -0
- package/dist/runtime/assets/kviewer.css +1 -0
- package/dist/runtime/components/AnnotationToolbar.d.vue.ts +3 -0
- package/dist/runtime/components/AnnotationToolbar.vue +125 -0
- package/dist/runtime/components/AnnotationToolbar.vue.d.ts +3 -0
- package/dist/runtime/components/FloatingPageIndicator.d.vue.ts +6 -0
- package/dist/runtime/components/FloatingPageIndicator.vue +93 -0
- package/dist/runtime/components/FloatingPageIndicator.vue.d.ts +6 -0
- package/dist/runtime/components/FormFieldLayer.d.vue.ts +11 -0
- package/dist/runtime/components/FormFieldLayer.vue +40 -0
- package/dist/runtime/components/FormFieldLayer.vue.d.ts +11 -0
- package/dist/runtime/components/PdfPage.d.vue.ts +9 -0
- package/dist/runtime/components/PdfPage.vue +199 -0
- package/dist/runtime/components/PdfPage.vue.d.ts +9 -0
- package/dist/runtime/components/ToolButton.d.vue.ts +13 -0
- package/dist/runtime/components/ToolButton.vue +26 -0
- package/dist/runtime/components/ToolButton.vue.d.ts +13 -0
- package/dist/runtime/components/Toolbar.d.vue.ts +3 -0
- package/dist/runtime/components/Toolbar.vue +11 -0
- package/dist/runtime/components/Toolbar.vue.d.ts +3 -0
- package/dist/runtime/components/Viewer.d.vue.ts +45 -0
- package/dist/runtime/components/Viewer.vue +617 -0
- package/dist/runtime/components/Viewer.vue.d.ts +45 -0
- package/dist/runtime/components/ViewerBar.d.vue.ts +3 -0
- package/dist/runtime/components/ViewerBar.vue +91 -0
- package/dist/runtime/components/ViewerBar.vue.d.ts +3 -0
- package/dist/runtime/components/ViewerTabs.d.vue.ts +381 -0
- package/dist/runtime/components/ViewerTabs.vue +171 -0
- package/dist/runtime/components/ViewerTabs.vue.d.ts +381 -0
- package/dist/runtime/components/form-fields/FormButton.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormButton.vue +39 -0
- package/dist/runtime/components/form-fields/FormButton.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormCheckbox.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormCheckbox.vue +28 -0
- package/dist/runtime/components/form-fields/FormCheckbox.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormDropdown.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormDropdown.vue +112 -0
- package/dist/runtime/components/form-fields/FormDropdown.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.d.vue.ts +8 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.vue +41 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.vue.d.ts +8 -0
- package/dist/runtime/components/form-fields/FormRadioButton.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormRadioButton.vue +30 -0
- package/dist/runtime/components/form-fields/FormRadioButton.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormSignatureField.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormSignatureField.vue +54 -0
- package/dist/runtime/components/form-fields/FormSignatureField.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormTextField.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormTextField.vue +66 -0
- package/dist/runtime/components/form-fields/FormTextField.vue.d.ts +7 -0
- package/dist/runtime/components/modals/FreeTextModal.d.vue.ts +25 -0
- package/dist/runtime/components/modals/FreeTextModal.vue +89 -0
- package/dist/runtime/components/modals/FreeTextModal.vue.d.ts +25 -0
- package/dist/runtime/components/modals/SignatureDrawModal.d.vue.ts +14 -0
- package/dist/runtime/components/modals/SignatureDrawModal.vue +120 -0
- package/dist/runtime/components/modals/SignatureDrawModal.vue.d.ts +14 -0
- package/dist/runtime/components/panels/SignaturePicker.d.vue.ts +3 -0
- package/dist/runtime/components/panels/SignaturePicker.vue +85 -0
- package/dist/runtime/components/panels/SignaturePicker.vue.d.ts +3 -0
- package/dist/runtime/components/panels/StampPicker.d.vue.ts +3 -0
- package/dist/runtime/components/panels/StampPicker.vue +46 -0
- package/dist/runtime/components/panels/StampPicker.vue.d.ts +3 -0
- package/dist/runtime/components/tools/ActionTools.d.vue.ts +3 -0
- package/dist/runtime/components/tools/ActionTools.vue +32 -0
- package/dist/runtime/components/tools/ActionTools.vue.d.ts +3 -0
- package/dist/runtime/components/tools/DrawingTools.d.vue.ts +6 -0
- package/dist/runtime/components/tools/DrawingTools.vue +57 -0
- package/dist/runtime/components/tools/DrawingTools.vue.d.ts +6 -0
- package/dist/runtime/components/tools/HandTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/HandTool.vue +14 -0
- package/dist/runtime/components/tools/HandTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/MarqueeTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/MarqueeTool.vue +15 -0
- package/dist/runtime/components/tools/MarqueeTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/PageInfo.d.vue.ts +3 -0
- package/dist/runtime/components/tools/PageInfo.vue +10 -0
- package/dist/runtime/components/tools/PageInfo.vue.d.ts +3 -0
- package/dist/runtime/components/tools/PageSettings.d.vue.ts +3 -0
- package/dist/runtime/components/tools/PageSettings.vue +92 -0
- package/dist/runtime/components/tools/PageSettings.vue.d.ts +3 -0
- package/dist/runtime/components/tools/SearchTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/SearchTool.vue +149 -0
- package/dist/runtime/components/tools/SearchTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/ToolProperties.d.vue.ts +7 -0
- package/dist/runtime/components/tools/ToolProperties.vue +174 -0
- package/dist/runtime/components/tools/ToolProperties.vue.d.ts +7 -0
- package/dist/runtime/components/tools/ZoomControls.d.vue.ts +3 -0
- package/dist/runtime/components/tools/ZoomControls.vue +59 -0
- package/dist/runtime/components/tools/ZoomControls.vue.d.ts +3 -0
- package/dist/runtime/composables/search-utils.d.ts +20 -0
- package/dist/runtime/composables/search-utils.js +55 -0
- package/dist/runtime/composables/useAnnotationEngine.d.ts +7 -0
- package/dist/runtime/composables/useAnnotationEngine.js +70 -0
- package/dist/runtime/composables/useAnnotationHistory.d.ts +12 -0
- package/dist/runtime/composables/useAnnotationHistory.js +69 -0
- package/dist/runtime/composables/useFormFields.d.ts +26 -0
- package/dist/runtime/composables/useFormFields.js +112 -0
- package/dist/runtime/composables/usePageProxyCache.d.ts +8 -0
- package/dist/runtime/composables/usePageProxyCache.js +73 -0
- package/dist/runtime/composables/usePageSettings.d.ts +16 -0
- package/dist/runtime/composables/usePageSettings.js +66 -0
- package/dist/runtime/composables/usePageVirtualization.d.ts +19 -0
- package/dist/runtime/composables/usePageVirtualization.js +203 -0
- package/dist/runtime/composables/useSearchIndex.d.ts +11 -0
- package/dist/runtime/composables/useSearchIndex.js +71 -0
- package/dist/runtime/composables/useViewerSearch.d.ts +32 -0
- package/dist/runtime/composables/useViewerSearch.js +418 -0
- package/dist/runtime/composables/useViewerState.d.ts +62 -0
- package/dist/runtime/composables/useViewerState.js +189 -0
- package/dist/runtime/composables/viewMode.d.ts +11 -0
- package/dist/runtime/composables/viewMode.js +19 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.js +3 -0
- package/dist/runtime/public-types.d.ts +2 -0
- package/dist/runtime/public-types.js +0 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/types.d.mts +5 -0
- package/package.json +64 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex items-center gap-2 px-2 py-1 rounded-md border border-default bg-default/60 lg:min-w-64">
|
|
3
|
+
<template v-if="supportsProperties">
|
|
4
|
+
<!-- ── Desktop: inline color buttons + slider (md and above) ── -->
|
|
5
|
+
<div class="hidden lg:flex items-center gap-1">
|
|
6
|
+
<button
|
|
7
|
+
v-for="color in colors"
|
|
8
|
+
:key="color"
|
|
9
|
+
class="w-4 h-4 rounded-full border-2 cursor-pointer transition-transform hover:scale-110"
|
|
10
|
+
:class="color === currentColor ? 'border-white ring-1 ring-primary' : 'border-transparent'"
|
|
11
|
+
:style="{ backgroundColor: color }"
|
|
12
|
+
:title="`Color: ${color}`"
|
|
13
|
+
@click="setColor(color)"
|
|
14
|
+
/>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<div
|
|
18
|
+
v-if="activeType === AnnotationType.FREEHAND"
|
|
19
|
+
class="hidden lg:flex items-center gap-2 min-w-40"
|
|
20
|
+
>
|
|
21
|
+
<UIcon name="i-lucide-minus" class="text-[10px] text-muted" />
|
|
22
|
+
<USlider
|
|
23
|
+
:model-value="freehandStrokeWidth"
|
|
24
|
+
:min="1"
|
|
25
|
+
:max="24"
|
|
26
|
+
:step="1"
|
|
27
|
+
size="sm"
|
|
28
|
+
class="w-28"
|
|
29
|
+
@update:model-value="setFreehandSize"
|
|
30
|
+
/>
|
|
31
|
+
<UIcon name="i-lucide-plus" class="text-[10px] text-muted" />
|
|
32
|
+
<span class="w-9 text-[11px] text-muted text-right tabular-nums">
|
|
33
|
+
{{ freehandStrokeWidth }}px
|
|
34
|
+
</span>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<!-- ── Mobile: two popover buttons (below md) ── -->
|
|
38
|
+
<div class="flex lg:hidden items-center gap-1">
|
|
39
|
+
<!-- Color popover -->
|
|
40
|
+
<UPopover v-model:open="colorPopoverOpen">
|
|
41
|
+
<button
|
|
42
|
+
class="flex items-center justify-center w-7 h-7 rounded-md hover:bg-default cursor-pointer"
|
|
43
|
+
title="Color"
|
|
44
|
+
>
|
|
45
|
+
<span
|
|
46
|
+
class="w-4 h-4 rounded-full border border-white/30"
|
|
47
|
+
:style="{ backgroundColor: currentColor ?? colors[0] }"
|
|
48
|
+
/>
|
|
49
|
+
</button>
|
|
50
|
+
<template #content>
|
|
51
|
+
<div class="p-3">
|
|
52
|
+
<div class="grid grid-cols-4 gap-1.5">
|
|
53
|
+
<button
|
|
54
|
+
v-for="color in colors"
|
|
55
|
+
:key="color"
|
|
56
|
+
class="w-7 h-7 rounded-full border-2 cursor-pointer transition-transform hover:scale-110"
|
|
57
|
+
:class="color === currentColor ? 'border-white ring-2 ring-primary' : 'border-transparent'"
|
|
58
|
+
:style="{ backgroundColor: color }"
|
|
59
|
+
@click="setColorAndClose(color)"
|
|
60
|
+
/>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
</UPopover>
|
|
65
|
+
|
|
66
|
+
<!-- Stroke width popover (freehand only) -->
|
|
67
|
+
<UPopover v-if="activeType === AnnotationType.FREEHAND">
|
|
68
|
+
<button
|
|
69
|
+
class="flex items-center justify-center h-7 px-1.5 gap-0.5 rounded-md hover:bg-default cursor-pointer"
|
|
70
|
+
title="Stroke width"
|
|
71
|
+
>
|
|
72
|
+
<UIcon name="i-lucide-pencil" class="text-sm text-muted" />
|
|
73
|
+
<span class="text-[10px] text-muted tabular-nums">{{ freehandStrokeWidth }}</span>
|
|
74
|
+
</button>
|
|
75
|
+
<template #content>
|
|
76
|
+
<div class="p-3 flex items-center gap-3">
|
|
77
|
+
<button
|
|
78
|
+
class="flex items-center justify-center w-8 h-8 rounded-md hover:bg-default cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed"
|
|
79
|
+
:disabled="freehandStrokeWidth <= 1"
|
|
80
|
+
title="Decrease stroke width"
|
|
81
|
+
@click="decrementStrokeWidth"
|
|
82
|
+
>
|
|
83
|
+
<UIcon name="i-lucide-minus" class="text-sm" />
|
|
84
|
+
</button>
|
|
85
|
+
<span class="w-9 text-center text-sm tabular-nums">
|
|
86
|
+
{{ freehandStrokeWidth }}px
|
|
87
|
+
</span>
|
|
88
|
+
<button
|
|
89
|
+
class="flex items-center justify-center w-8 h-8 rounded-md hover:bg-default cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed"
|
|
90
|
+
:disabled="freehandStrokeWidth >= 24"
|
|
91
|
+
title="Increase stroke width"
|
|
92
|
+
@click="incrementStrokeWidth"
|
|
93
|
+
>
|
|
94
|
+
<UIcon name="i-lucide-plus" class="text-sm" />
|
|
95
|
+
</button>
|
|
96
|
+
</div>
|
|
97
|
+
</template>
|
|
98
|
+
</UPopover>
|
|
99
|
+
</div>
|
|
100
|
+
</template>
|
|
101
|
+
|
|
102
|
+
<template v-else>
|
|
103
|
+
<div class="flex items-center gap-1.5 text-xs text-muted">
|
|
104
|
+
<UIcon name="i-lucide-sliders-horizontal" class="text-sm" />
|
|
105
|
+
<span>No properties</span>
|
|
106
|
+
</div>
|
|
107
|
+
</template>
|
|
108
|
+
</div>
|
|
109
|
+
</template>
|
|
110
|
+
|
|
111
|
+
<script setup>
|
|
112
|
+
import { computed, ref } from "vue";
|
|
113
|
+
import { defaultOptions, annotationDefinitions } from "../../annotation/engine/config";
|
|
114
|
+
import { AnnotationType } from "../../annotation/engine/types";
|
|
115
|
+
import { useViewerState } from "../../composables/useViewerState";
|
|
116
|
+
const emit = defineEmits(["styleUpdated"]);
|
|
117
|
+
const state = useViewerState();
|
|
118
|
+
const colors = defaultOptions.colors;
|
|
119
|
+
const styleVersion = ref(0);
|
|
120
|
+
const colorPopoverOpen = ref(false);
|
|
121
|
+
const activeType = computed(() => {
|
|
122
|
+
return typeof state.activeTool.value === "number" ? state.activeTool.value : null;
|
|
123
|
+
});
|
|
124
|
+
const supportsProperties = computed(
|
|
125
|
+
() => activeType.value === AnnotationType.FREEHAND || activeType.value === AnnotationType.FREE_HIGHLIGHT || activeType.value === AnnotationType.RECTANGLE
|
|
126
|
+
);
|
|
127
|
+
const activeDef = computed(() => {
|
|
128
|
+
if (!supportsProperties.value || activeType.value === null) return null;
|
|
129
|
+
styleVersion.value;
|
|
130
|
+
return getDef(activeType.value);
|
|
131
|
+
});
|
|
132
|
+
const currentColor = computed(() => {
|
|
133
|
+
styleVersion.value;
|
|
134
|
+
if (activeType.value === null) return null;
|
|
135
|
+
const def = getDef(activeType.value);
|
|
136
|
+
return def?.style?.color ?? null;
|
|
137
|
+
});
|
|
138
|
+
const freehandStrokeWidth = computed(() => {
|
|
139
|
+
styleVersion.value;
|
|
140
|
+
const def = getDef(AnnotationType.FREEHAND);
|
|
141
|
+
return def?.style?.strokeWidth ?? defaultOptions.setting.STROKE_WIDTH;
|
|
142
|
+
});
|
|
143
|
+
function getDef(type) {
|
|
144
|
+
return annotationDefinitions.find((d) => d.type === type);
|
|
145
|
+
}
|
|
146
|
+
function setColor(color) {
|
|
147
|
+
if (!supportsProperties.value) return;
|
|
148
|
+
const def = activeDef.value;
|
|
149
|
+
if (!def) return;
|
|
150
|
+
def.style = { ...def.style ?? {}, color };
|
|
151
|
+
styleVersion.value++;
|
|
152
|
+
emit("styleUpdated");
|
|
153
|
+
}
|
|
154
|
+
function setColorAndClose(color) {
|
|
155
|
+
setColor(color);
|
|
156
|
+
colorPopoverOpen.value = false;
|
|
157
|
+
}
|
|
158
|
+
function setFreehandSize(value) {
|
|
159
|
+
const raw = Array.isArray(value) ? value[0] : value;
|
|
160
|
+
if (raw === void 0) return;
|
|
161
|
+
const def = getDef(AnnotationType.FREEHAND);
|
|
162
|
+
if (!def) return;
|
|
163
|
+
const strokeWidth = Math.min(24, Math.max(1, Math.round(raw)));
|
|
164
|
+
def.style = { ...def.style ?? {}, strokeWidth };
|
|
165
|
+
styleVersion.value++;
|
|
166
|
+
emit("styleUpdated");
|
|
167
|
+
}
|
|
168
|
+
function incrementStrokeWidth() {
|
|
169
|
+
if (freehandStrokeWidth.value < 24) setFreehandSize(freehandStrokeWidth.value + 1);
|
|
170
|
+
}
|
|
171
|
+
function decrementStrokeWidth() {
|
|
172
|
+
if (freehandStrokeWidth.value > 1) setFreehandSize(freehandStrokeWidth.value - 1);
|
|
173
|
+
}
|
|
174
|
+
</script>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
2
|
+
styleUpdated: () => any;
|
|
3
|
+
}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
|
|
4
|
+
onStyleUpdated?: (() => any) | undefined;
|
|
5
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
6
|
+
declare const _default: typeof __VLS_export;
|
|
7
|
+
export default _default;
|
|
@@ -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;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex items-center gap-1">
|
|
3
|
+
<USelect
|
|
4
|
+
:items="zoomItems"
|
|
5
|
+
:model-value="currentZoomValue"
|
|
6
|
+
variant="ghost"
|
|
7
|
+
color="neutral"
|
|
8
|
+
size="xs"
|
|
9
|
+
class="w-24"
|
|
10
|
+
@update:model-value="onZoomChange"
|
|
11
|
+
/>
|
|
12
|
+
<UButton
|
|
13
|
+
icon="i-lucide-minus"
|
|
14
|
+
variant="ghost"
|
|
15
|
+
color="neutral"
|
|
16
|
+
size="xs"
|
|
17
|
+
@click="state.zoomOut"
|
|
18
|
+
/>
|
|
19
|
+
<UButton
|
|
20
|
+
icon="i-lucide-plus"
|
|
21
|
+
variant="ghost"
|
|
22
|
+
color="neutral"
|
|
23
|
+
size="xs"
|
|
24
|
+
@click="state.zoomIn"
|
|
25
|
+
/>
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script setup>
|
|
30
|
+
import { computed } from "vue";
|
|
31
|
+
import { useViewerState } from "../../composables/useViewerState";
|
|
32
|
+
const state = useViewerState();
|
|
33
|
+
const fitModeItems = [
|
|
34
|
+
{ label: "Fit Width", value: "fit-width" },
|
|
35
|
+
{ label: "Fit Page", value: "fit-page" }
|
|
36
|
+
];
|
|
37
|
+
const scaleItems = computed(
|
|
38
|
+
() => state.scaleOptions.map((s) => ({
|
|
39
|
+
label: `${Math.round(s * 100)}%`,
|
|
40
|
+
value: `scale:${s}`
|
|
41
|
+
}))
|
|
42
|
+
);
|
|
43
|
+
const zoomItems = computed(() => [
|
|
44
|
+
...fitModeItems,
|
|
45
|
+
{ label: "---", value: "_separator", disabled: true },
|
|
46
|
+
...scaleItems.value
|
|
47
|
+
]);
|
|
48
|
+
const currentZoomValue = computed(() => {
|
|
49
|
+
if (state.fitMode.value !== "custom") return state.fitMode.value;
|
|
50
|
+
return `scale:${state.scale.value}`;
|
|
51
|
+
});
|
|
52
|
+
function onZoomChange(value) {
|
|
53
|
+
if (value.startsWith("scale:")) {
|
|
54
|
+
state.setScale(Number(value.slice(6)));
|
|
55
|
+
} else if (value !== "_separator") {
|
|
56
|
+
state.setFitMode(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
</script>
|
|
@@ -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;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface SearchMatch {
|
|
2
|
+
index: number;
|
|
3
|
+
length: number;
|
|
4
|
+
}
|
|
5
|
+
export interface SearchOptions {
|
|
6
|
+
matchCase: boolean;
|
|
7
|
+
wholeWord: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface FlattenedMatch {
|
|
10
|
+
pageNumber: number;
|
|
11
|
+
matchIndex: number;
|
|
12
|
+
}
|
|
13
|
+
export interface RenderRange {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function findMatchesInText(text: string, query: string, options: SearchOptions): SearchMatch[];
|
|
18
|
+
export declare function flattenMatchesByPage(pageNumbers: number[], matchesByPage: Map<number, SearchMatch[]>): FlattenedMatch[];
|
|
19
|
+
export declare function stepMatchIndex(currentIndex: number, totalMatches: number, previous: boolean): number;
|
|
20
|
+
export declare function getRenderRange(totalMatchesInPage: number, highlightAll: boolean, isSelectedPage: boolean, selectedMatchIndex: number): RenderRange | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function isWordCharacter(char) {
|
|
2
|
+
if (!char) return false;
|
|
3
|
+
return /[\p{L}\p{N}_]/u.test(char);
|
|
4
|
+
}
|
|
5
|
+
function hasWholeWordBoundary(text, start, length) {
|
|
6
|
+
const before = start > 0 ? text[start - 1] : void 0;
|
|
7
|
+
const after = start + length < text.length ? text[start + length] : void 0;
|
|
8
|
+
return !isWordCharacter(before) && !isWordCharacter(after);
|
|
9
|
+
}
|
|
10
|
+
export function findMatchesInText(text, query, options) {
|
|
11
|
+
if (!query) return [];
|
|
12
|
+
const normalizedText = options.matchCase ? text : text.toLocaleLowerCase();
|
|
13
|
+
const normalizedQuery = options.matchCase ? query : query.toLocaleLowerCase();
|
|
14
|
+
const matches = [];
|
|
15
|
+
let fromIndex = 0;
|
|
16
|
+
while (fromIndex <= normalizedText.length - normalizedQuery.length) {
|
|
17
|
+
const index = normalizedText.indexOf(normalizedQuery, fromIndex);
|
|
18
|
+
if (index === -1) break;
|
|
19
|
+
if (!options.wholeWord || hasWholeWordBoundary(normalizedText, index, normalizedQuery.length)) {
|
|
20
|
+
matches.push({ index, length: normalizedQuery.length });
|
|
21
|
+
}
|
|
22
|
+
fromIndex = index + Math.max(1, normalizedQuery.length);
|
|
23
|
+
}
|
|
24
|
+
return matches;
|
|
25
|
+
}
|
|
26
|
+
export function flattenMatchesByPage(pageNumbers, matchesByPage) {
|
|
27
|
+
const flattened = [];
|
|
28
|
+
for (const pageNumber of pageNumbers) {
|
|
29
|
+
const pageMatches = matchesByPage.get(pageNumber) ?? [];
|
|
30
|
+
for (let matchIndex = 0; matchIndex < pageMatches.length; matchIndex++) {
|
|
31
|
+
flattened.push({ pageNumber, matchIndex });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return flattened;
|
|
35
|
+
}
|
|
36
|
+
export function stepMatchIndex(currentIndex, totalMatches, previous) {
|
|
37
|
+
if (totalMatches <= 0) return -1;
|
|
38
|
+
if (currentIndex < 0 || currentIndex >= totalMatches) {
|
|
39
|
+
return previous ? totalMatches - 1 : 0;
|
|
40
|
+
}
|
|
41
|
+
if (previous) {
|
|
42
|
+
return currentIndex === 0 ? totalMatches - 1 : currentIndex - 1;
|
|
43
|
+
}
|
|
44
|
+
return currentIndex === totalMatches - 1 ? 0 : currentIndex + 1;
|
|
45
|
+
}
|
|
46
|
+
export function getRenderRange(totalMatchesInPage, highlightAll, isSelectedPage, selectedMatchIndex) {
|
|
47
|
+
if (totalMatchesInPage <= 0) return null;
|
|
48
|
+
if (highlightAll) {
|
|
49
|
+
return { start: 0, end: totalMatchesInPage };
|
|
50
|
+
}
|
|
51
|
+
if (!isSelectedPage || selectedMatchIndex < 0 || selectedMatchIndex >= totalMatchesInPage) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return { start: selectedMatchIndex, end: selectedMatchIndex + 1 };
|
|
55
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Painter, type PainterCallbacks } from '../annotation/engine/painter.js';
|
|
2
|
+
import type { ViewerState } from './useViewerState.js';
|
|
3
|
+
export declare function createAnnotationEngine(viewerState: ViewerState, options: {
|
|
4
|
+
userName?: string;
|
|
5
|
+
onRequestTextInput: PainterCallbacks['onRequestTextInput'];
|
|
6
|
+
onRequestDeleteConfirm?: PainterCallbacks['onRequestDeleteConfirm'];
|
|
7
|
+
}): Painter;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { triggerRef } from "vue";
|
|
2
|
+
import { Painter } from "../annotation/engine/painter.js";
|
|
3
|
+
import {
|
|
4
|
+
AnnotationType
|
|
5
|
+
} from "../annotation/engine/types.js";
|
|
6
|
+
export function createAnnotationEngine(viewerState, options) {
|
|
7
|
+
const callbacks = {
|
|
8
|
+
setDefaultMode: () => {
|
|
9
|
+
const tool = viewerState.activeTool.value;
|
|
10
|
+
if (tool === AnnotationType.STAMP || tool === AnnotationType.SIGNATURE) return;
|
|
11
|
+
viewerState.selectTool("hand");
|
|
12
|
+
},
|
|
13
|
+
forceReset: () => {
|
|
14
|
+
viewerState.selectTool("hand");
|
|
15
|
+
},
|
|
16
|
+
onStoreAdd: (annotationStore, isOriginal, _currentAnnotation) => {
|
|
17
|
+
viewerState.annotations.value.set(annotationStore.id, annotationStore);
|
|
18
|
+
triggerRef(viewerState.annotations);
|
|
19
|
+
if (!isOriginal) {
|
|
20
|
+
viewerState.history.commit();
|
|
21
|
+
if (annotationStore.type === AnnotationType.FREETEXT) {
|
|
22
|
+
viewerState.painter.value?.selectAnnotation(annotationStore.id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
onStoreDelete: (id) => {
|
|
27
|
+
viewerState.annotations.value.delete(id);
|
|
28
|
+
triggerRef(viewerState.annotations);
|
|
29
|
+
if (viewerState.selectedAnnotation.value?.id === id) {
|
|
30
|
+
viewerState.selectedAnnotation.value = null;
|
|
31
|
+
viewerState.selectionRect.value = null;
|
|
32
|
+
}
|
|
33
|
+
viewerState.history.commit();
|
|
34
|
+
},
|
|
35
|
+
onAnnotationSelected: (annotationStore, _isClick, selectorRect) => {
|
|
36
|
+
viewerState.selectedAnnotation.value = annotationStore;
|
|
37
|
+
viewerState.selectedAnnotations.value = [annotationStore];
|
|
38
|
+
viewerState.selectionRect.value = selectorRect;
|
|
39
|
+
},
|
|
40
|
+
onMultiSelected: (annotationStores, combinedRect) => {
|
|
41
|
+
viewerState.selectedAnnotation.value = null;
|
|
42
|
+
viewerState.selectedAnnotations.value = annotationStores;
|
|
43
|
+
viewerState.selectionRect.value = combinedRect;
|
|
44
|
+
viewerState.activeTool.value = "hand";
|
|
45
|
+
},
|
|
46
|
+
onAnnotationChange: (annotationStore) => {
|
|
47
|
+
viewerState.annotations.value.set(annotationStore.id, annotationStore);
|
|
48
|
+
triggerRef(viewerState.annotations);
|
|
49
|
+
},
|
|
50
|
+
onAnnotationChanging: () => {
|
|
51
|
+
viewerState.selectionRect.value = null;
|
|
52
|
+
},
|
|
53
|
+
onAnnotationChanged: (annotationStore, selectorRect) => {
|
|
54
|
+
viewerState.annotations.value.set(annotationStore.id, annotationStore);
|
|
55
|
+
triggerRef(viewerState.annotations);
|
|
56
|
+
viewerState.selectedAnnotation.value = annotationStore;
|
|
57
|
+
viewerState.selectionRect.value = selectorRect;
|
|
58
|
+
viewerState.history.commit();
|
|
59
|
+
},
|
|
60
|
+
onRequestTextInput: options.onRequestTextInput,
|
|
61
|
+
onRequestDeleteConfirm: options.onRequestDeleteConfirm
|
|
62
|
+
};
|
|
63
|
+
const painter = new Painter({
|
|
64
|
+
userName: options.userName ?? "User",
|
|
65
|
+
callbacks,
|
|
66
|
+
getStylusModeEnabled: () => viewerState.stylusMode.value
|
|
67
|
+
});
|
|
68
|
+
viewerState.painter.value = painter;
|
|
69
|
+
return painter;
|
|
70
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ComputedRef, type ShallowRef } from 'vue';
|
|
2
|
+
import type { Painter } from '../annotation/engine/painter.js';
|
|
3
|
+
import type { IAnnotationStore } from '../annotation/engine/types.js';
|
|
4
|
+
export interface AnnotationHistory {
|
|
5
|
+
commit: () => void;
|
|
6
|
+
undo: () => void;
|
|
7
|
+
redo: () => void;
|
|
8
|
+
reset: () => void;
|
|
9
|
+
canUndo: ComputedRef<boolean>;
|
|
10
|
+
canRedo: ComputedRef<boolean>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createAnnotationHistory(annotations: ShallowRef<Map<string, IAnnotationStore>>, painter: ShallowRef<Painter | null>): AnnotationHistory;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ref, computed, triggerRef } from "vue";
|
|
2
|
+
const MAX_HISTORY = 50;
|
|
3
|
+
function cloneAnnotations(map) {
|
|
4
|
+
return Array.from(map.values()).map((a) => ({ ...a, comments: [...a.comments] }));
|
|
5
|
+
}
|
|
6
|
+
export function createAnnotationHistory(annotations, painter) {
|
|
7
|
+
const undoStack = ref([]);
|
|
8
|
+
const redoStack = ref([]);
|
|
9
|
+
const canUndo = computed(() => undoStack.value.length > 0);
|
|
10
|
+
const canRedo = computed(() => redoStack.value.length > 0);
|
|
11
|
+
function commit() {
|
|
12
|
+
const snapshot = cloneAnnotations(annotations.value);
|
|
13
|
+
undoStack.value.push(snapshot);
|
|
14
|
+
if (undoStack.value.length > MAX_HISTORY) {
|
|
15
|
+
undoStack.value.shift();
|
|
16
|
+
}
|
|
17
|
+
redoStack.value = [];
|
|
18
|
+
}
|
|
19
|
+
function restoreSnapshot(target) {
|
|
20
|
+
const p = painter.value;
|
|
21
|
+
if (!p) return;
|
|
22
|
+
const currentMap = /* @__PURE__ */ new Map();
|
|
23
|
+
for (const a of p.getData()) {
|
|
24
|
+
currentMap.set(a.id, a);
|
|
25
|
+
}
|
|
26
|
+
const targetMap = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const a of target) {
|
|
28
|
+
targetMap.set(a.id, a);
|
|
29
|
+
}
|
|
30
|
+
for (const id of currentMap.keys()) {
|
|
31
|
+
if (!targetMap.has(id)) {
|
|
32
|
+
p.delete(id, false);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const ann of target) {
|
|
36
|
+
if (!currentMap.has(ann.id)) {
|
|
37
|
+
p.reAddAnnotation(ann);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const ann of target) {
|
|
41
|
+
const current = currentMap.get(ann.id);
|
|
42
|
+
if (current && current.konvaString !== ann.konvaString) {
|
|
43
|
+
p.delete(ann.id, false);
|
|
44
|
+
p.reAddAnnotation(ann);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
annotations.value = targetMap;
|
|
48
|
+
triggerRef(annotations);
|
|
49
|
+
}
|
|
50
|
+
function undo() {
|
|
51
|
+
if (!canUndo.value) return;
|
|
52
|
+
const currentSnapshot = cloneAnnotations(annotations.value);
|
|
53
|
+
redoStack.value.push(currentSnapshot);
|
|
54
|
+
const target = undoStack.value.pop();
|
|
55
|
+
restoreSnapshot(target);
|
|
56
|
+
}
|
|
57
|
+
function redo() {
|
|
58
|
+
if (!canRedo.value) return;
|
|
59
|
+
const currentSnapshot = cloneAnnotations(annotations.value);
|
|
60
|
+
undoStack.value.push(currentSnapshot);
|
|
61
|
+
const target = redoStack.value.pop();
|
|
62
|
+
restoreSnapshot(target);
|
|
63
|
+
}
|
|
64
|
+
function reset() {
|
|
65
|
+
undoStack.value = [];
|
|
66
|
+
redoStack.value = [];
|
|
67
|
+
}
|
|
68
|
+
return { commit, undo, redo, reset, canUndo, canRedo };
|
|
69
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ShallowRef } from 'vue';
|
|
2
|
+
import type { FormFieldDefinition, FormFieldValue } from '../annotation/engine/types.js';
|
|
3
|
+
export interface FormFieldsState {
|
|
4
|
+
/** Field definitions grouped by page number */
|
|
5
|
+
fieldDefinitions: ShallowRef<Map<number, FormFieldDefinition[]>>;
|
|
6
|
+
/** Field values keyed by field id */
|
|
7
|
+
fieldValues: ShallowRef<Map<string, FormFieldValue>>;
|
|
8
|
+
/** Parse form fields from raw pdf.js annotations for a page (idempotent) */
|
|
9
|
+
parsePageFields: (pageNumber: number, rawAnnotations: unknown[]) => void;
|
|
10
|
+
/** Set a field value by field id */
|
|
11
|
+
setFieldValue: (fieldId: string, value: string | boolean | string[]) => void;
|
|
12
|
+
/** Get a field value by field id */
|
|
13
|
+
getFieldValue: (fieldId: string) => FormFieldValue | undefined;
|
|
14
|
+
/** Get field definitions for a page */
|
|
15
|
+
getFieldsForPage: (pageNumber: number) => FormFieldDefinition[];
|
|
16
|
+
/** Get all field values (for export) */
|
|
17
|
+
getAllFieldValues: () => FormFieldValue[];
|
|
18
|
+
/** Set a field value by field name (public API for programmatic fill) */
|
|
19
|
+
setFieldValueByName: (fieldName: string, value: string | boolean | string[]) => void;
|
|
20
|
+
/** Reset all field values to their defaults (keeps definitions) */
|
|
21
|
+
resetValues: () => void;
|
|
22
|
+
/** Clear all values and definitions (for document change) */
|
|
23
|
+
reset: () => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function provideFormFields(): FormFieldsState;
|
|
26
|
+
export declare function useFormFields(): FormFieldsState;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
shallowRef,
|
|
3
|
+
triggerRef,
|
|
4
|
+
provide,
|
|
5
|
+
inject
|
|
6
|
+
} from "vue";
|
|
7
|
+
import { parseFormFields } from "../annotation/parsers/parseFormFields.js";
|
|
8
|
+
const FORM_FIELDS_KEY = Symbol("kviewer-form-fields");
|
|
9
|
+
export function provideFormFields() {
|
|
10
|
+
const fieldDefinitions = shallowRef(/* @__PURE__ */ new Map());
|
|
11
|
+
const fieldValues = shallowRef(/* @__PURE__ */ new Map());
|
|
12
|
+
function parsePageFields(pageNumber, rawAnnotations) {
|
|
13
|
+
if (fieldDefinitions.value.has(pageNumber)) return;
|
|
14
|
+
const defs = parseFormFields(rawAnnotations, pageNumber);
|
|
15
|
+
if (defs.length === 0) return;
|
|
16
|
+
fieldDefinitions.value.set(pageNumber, defs);
|
|
17
|
+
triggerRef(fieldDefinitions);
|
|
18
|
+
for (const def of defs) {
|
|
19
|
+
if (fieldValues.value.has(def.id)) continue;
|
|
20
|
+
fieldValues.value.set(def.id, {
|
|
21
|
+
fieldId: def.id,
|
|
22
|
+
fieldName: def.fieldName,
|
|
23
|
+
fieldType: def.fieldType,
|
|
24
|
+
value: getDefaultValue(def)
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
triggerRef(fieldValues);
|
|
28
|
+
}
|
|
29
|
+
function setFieldValue(fieldId, value) {
|
|
30
|
+
const existing = fieldValues.value.get(fieldId);
|
|
31
|
+
if (!existing) return;
|
|
32
|
+
existing.value = value;
|
|
33
|
+
if (existing.fieldType === "radio" && typeof value === "string" && value !== "") {
|
|
34
|
+
const fieldName = existing.fieldName;
|
|
35
|
+
for (const [id, fv] of fieldValues.value.entries()) {
|
|
36
|
+
if (id !== fieldId && fv.fieldName === fieldName && fv.fieldType === "radio") {
|
|
37
|
+
fv.value = "";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
triggerRef(fieldValues);
|
|
42
|
+
}
|
|
43
|
+
function getFieldValue(fieldId) {
|
|
44
|
+
return fieldValues.value.get(fieldId);
|
|
45
|
+
}
|
|
46
|
+
function getFieldsForPage(pageNumber) {
|
|
47
|
+
return fieldDefinitions.value.get(pageNumber) ?? [];
|
|
48
|
+
}
|
|
49
|
+
function getAllFieldValues() {
|
|
50
|
+
return Array.from(fieldValues.value.values());
|
|
51
|
+
}
|
|
52
|
+
function setFieldValueByName(fieldName, value) {
|
|
53
|
+
for (const [, fv] of fieldValues.value.entries()) {
|
|
54
|
+
if (fv.fieldName === fieldName) {
|
|
55
|
+
fv.value = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
triggerRef(fieldValues);
|
|
59
|
+
}
|
|
60
|
+
function getDefaultValue(def) {
|
|
61
|
+
if (def.fieldType === "checkbox") {
|
|
62
|
+
return def.defaultValue != null && def.defaultValue !== "Off" && def.defaultValue !== "";
|
|
63
|
+
}
|
|
64
|
+
if (def.fieldType === "radio") {
|
|
65
|
+
return def.defaultValue ?? "";
|
|
66
|
+
}
|
|
67
|
+
if (def.fieldType === "text" || def.fieldType === "dropdown") {
|
|
68
|
+
return def.defaultValue ?? "";
|
|
69
|
+
}
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
72
|
+
function resetValues() {
|
|
73
|
+
for (const [, defs] of fieldDefinitions.value.entries()) {
|
|
74
|
+
for (const def of defs) {
|
|
75
|
+
const fv = fieldValues.value.get(def.id);
|
|
76
|
+
if (fv) {
|
|
77
|
+
fv.value = getDefaultValue(def);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
triggerRef(fieldValues);
|
|
82
|
+
}
|
|
83
|
+
function reset() {
|
|
84
|
+
fieldDefinitions.value = /* @__PURE__ */ new Map();
|
|
85
|
+
fieldValues.value = /* @__PURE__ */ new Map();
|
|
86
|
+
triggerRef(fieldDefinitions);
|
|
87
|
+
triggerRef(fieldValues);
|
|
88
|
+
}
|
|
89
|
+
const state = {
|
|
90
|
+
fieldDefinitions,
|
|
91
|
+
fieldValues,
|
|
92
|
+
parsePageFields,
|
|
93
|
+
setFieldValue,
|
|
94
|
+
getFieldValue,
|
|
95
|
+
getFieldsForPage,
|
|
96
|
+
getAllFieldValues,
|
|
97
|
+
setFieldValueByName,
|
|
98
|
+
resetValues,
|
|
99
|
+
reset
|
|
100
|
+
};
|
|
101
|
+
provide(FORM_FIELDS_KEY, state);
|
|
102
|
+
return state;
|
|
103
|
+
}
|
|
104
|
+
export function useFormFields() {
|
|
105
|
+
const state = inject(FORM_FIELDS_KEY);
|
|
106
|
+
if (!state) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
"useFormFields() must be used inside a <KViewer> component"
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return state;
|
|
112
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
|
|
2
|
+
export interface PageProxyCache {
|
|
3
|
+
setDocument: (doc: PDFDocumentProxy) => void;
|
|
4
|
+
getPage: (pageNumber: number) => Promise<PDFPageProxy>;
|
|
5
|
+
clear: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function createPageProxyCache(maxSize?: number): PageProxyCache;
|
|
8
|
+
export declare function usePageProxyCache(): PageProxyCache;
|