kviewer 0.3.1 → 0.3.3
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/dist/module.d.mts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +19 -15
- package/dist/runtime/annotation/engine/editor/editor.js +10 -12
- package/dist/runtime/annotation/engine/editor/selector.js +3 -1
- package/dist/runtime/annotation/engine/tools/arrow.js +24 -14
- package/dist/runtime/annotation/engine/tools/circle.js +24 -13
- package/dist/runtime/annotation/engine/tools/cloud.js +27 -18
- package/dist/runtime/annotation/engine/tools/free-highlight.js +24 -15
- package/dist/runtime/annotation/engine/tools/freehand.js +21 -12
- package/dist/runtime/annotation/engine/tools/highlight.d.ts +2 -0
- package/dist/runtime/annotation/engine/tools/highlight.js +20 -10
- package/dist/runtime/annotation/engine/tools/note.js +3 -1
- package/dist/runtime/annotation/engine/tools/rectangle.js +19 -8
- package/dist/runtime/annotation/engine/tools/signature.js +2 -1
- package/dist/runtime/annotation/engine/tools/stamp.js +2 -1
- package/dist/runtime/annotation/engine/utils.js +2 -1
- package/dist/runtime/annotation/pdf-export/download.js +1 -1
- package/dist/runtime/annotation/pdf-export/export-form-fields.js +20 -12
- package/dist/runtime/annotation/pdf-export/export.js +1 -1
- package/dist/runtime/annotation/pdf-export/parse_polyline.js +5 -1
- package/dist/runtime/annotation/pdf-export/parse_stamp.js +4 -4
- package/dist/runtime/annotation/pdf-export/print.d.ts +12 -0
- package/dist/runtime/annotation/pdf-export/print.js +63 -0
- package/dist/runtime/annotation/pdf-export/unicode-font.js +1 -4
- package/dist/runtime/annotation/pdf-import/decode_stamp.js +3 -2
- package/dist/runtime/annotation/pdf-import/extract_stamp_appearance.js +1 -1
- package/dist/runtime/annotation/pdf-import/utils.js +1 -1
- package/dist/runtime/components/FormFieldLayer.d.vue.ts +1 -1
- package/dist/runtime/components/FormFieldLayer.vue.d.ts +1 -1
- package/dist/runtime/components/PdfPage.vue +3 -3
- package/dist/runtime/components/Viewer.d.vue.ts +10 -1
- package/dist/runtime/components/Viewer.vue +24 -2
- package/dist/runtime/components/Viewer.vue.d.ts +10 -1
- package/dist/runtime/components/ViewerTabs.vue +1 -1
- package/dist/runtime/components/panels/SignaturePicker.vue +8 -2
- package/dist/runtime/components/tools/ToolbarMenu.vue +17 -0
- package/dist/runtime/composables/useScriptingManager.d.ts +5 -0
- package/dist/runtime/composables/useScriptingManager.js +6 -0
- package/dist/runtime/composables/useSearchIndex.js +1 -1
- package/dist/runtime/composables/useViewerState.d.ts +2 -0
- package/dist/runtime/composables/useViewerState.js +8 -0
- package/dist/runtime/embed/bridge-client.d.ts +4 -0
- package/dist/runtime/embed/bridge-client.js +6 -0
- package/dist/runtime/embed/bridge-host.d.ts +11 -2
- package/dist/runtime/embed/bridge-host.js +104 -30
- package/dist/runtime/embed/protocol.d.ts +17 -0
- package/dist/runtime/embed/protocol.js +1 -0
- package/dist/runtime/i18n/messages.d.ts +2 -0
- package/dist/runtime/i18n/messages.js +2 -0
- package/dist/runtime/imports.d.ts +19 -0
- package/dist/runtime/public-types.d.ts +2 -2
- package/dist/runtime/public-types.js +4 -1
- package/dist/types.d.mts +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<UPopover>
|
|
2
|
+
<UPopover v-model:open="popoverOpen">
|
|
3
3
|
<button
|
|
4
4
|
class="relative flex items-center justify-center w-8 h-8 rounded-md transition-colors cursor-pointer"
|
|
5
5
|
:class="isActive ? 'bg-default text-highlighted' : 'text-muted hover:bg-default/50 hover:text-highlighted'"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
color="neutral"
|
|
44
44
|
size="xs"
|
|
45
45
|
block
|
|
46
|
-
@click="
|
|
46
|
+
@click="openDrawModal"
|
|
47
47
|
>
|
|
48
48
|
{{ t("addSignature") }}
|
|
49
49
|
</UButton>
|
|
@@ -69,10 +69,16 @@ import SignatureDrawModal from "../modals/SignatureDrawModal.vue";
|
|
|
69
69
|
const state = useViewerState();
|
|
70
70
|
const { t } = useKviewerI18n();
|
|
71
71
|
const drawModalOpen = ref(false);
|
|
72
|
+
const popoverOpen = ref(false);
|
|
72
73
|
const isActive = computed(() => state.activeTool.value === AnnotationType.SIGNATURE);
|
|
73
74
|
function selectSignature(sig) {
|
|
74
75
|
state.activeSignature.value = sig;
|
|
75
76
|
state.selectTool(AnnotationType.SIGNATURE, sig.imageUrl);
|
|
77
|
+
popoverOpen.value = false;
|
|
78
|
+
}
|
|
79
|
+
function openDrawModal() {
|
|
80
|
+
popoverOpen.value = false;
|
|
81
|
+
drawModalOpen.value = true;
|
|
76
82
|
}
|
|
77
83
|
async function onDrawSubmit(imageUrl) {
|
|
78
84
|
drawModalOpen.value = false;
|
|
@@ -13,6 +13,16 @@
|
|
|
13
13
|
data-testid="viewer-download"
|
|
14
14
|
@click="onDownload"
|
|
15
15
|
/>
|
|
16
|
+
<UButton
|
|
17
|
+
icon="i-lucide-printer"
|
|
18
|
+
:label="t('print')"
|
|
19
|
+
variant="ghost"
|
|
20
|
+
color="neutral"
|
|
21
|
+
size="xs"
|
|
22
|
+
class="w-full justify-start"
|
|
23
|
+
data-testid="viewer-print"
|
|
24
|
+
@click="onPrint"
|
|
25
|
+
/>
|
|
16
26
|
<UButton
|
|
17
27
|
:icon="state.shapeDetection.value ? 'i-lucide-square-check-big' : 'i-lucide-square-dashed'"
|
|
18
28
|
:label="state.shapeDetection.value ? t('disableFormFieldDetection') : t('detectFormFields')"
|
|
@@ -76,4 +86,11 @@ async function onDownload() {
|
|
|
76
86
|
console.error("Failed to export PDF from menu action", error);
|
|
77
87
|
}
|
|
78
88
|
}
|
|
89
|
+
async function onPrint() {
|
|
90
|
+
try {
|
|
91
|
+
await state.printPdf();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("Failed to print PDF from menu action", error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
79
96
|
</script>
|
|
@@ -44,6 +44,11 @@ export interface ScriptingManager {
|
|
|
44
44
|
* PageOpen action can fire (the manager's `updatefromsandbox` /
|
|
45
45
|
* pagerendered handling in pdf_viewer.mjs). */
|
|
46
46
|
notifyPageRendered: (pageNumber: number) => void;
|
|
47
|
+
/** Run the document's `WillPrint` action and wait for the sandbox to
|
|
48
|
+
* finish it (scripts may adjust field values before printing). */
|
|
49
|
+
dispatchWillPrint: () => Promise<void>;
|
|
50
|
+
/** Fire the document's `DidPrint` action. */
|
|
51
|
+
dispatchDidPrint: () => Promise<void>;
|
|
47
52
|
/** Bind a document to the sandbox. Safe to call repeatedly — pass
|
|
48
53
|
* null to detach (e.g. before swapping documents). */
|
|
49
54
|
setDocument: (pdfDoc: PDFDocumentProxy | null) => Promise<void>;
|
|
@@ -104,6 +104,12 @@ export async function createScriptingManager(deps) {
|
|
|
104
104
|
notifyPageRendered(pageNumber) {
|
|
105
105
|
eventBus.dispatch("pagerendered", { source: window, pageNumber });
|
|
106
106
|
},
|
|
107
|
+
async dispatchWillPrint() {
|
|
108
|
+
await manager.dispatchWillPrint();
|
|
109
|
+
},
|
|
110
|
+
async dispatchDidPrint() {
|
|
111
|
+
await manager.dispatchDidPrint();
|
|
112
|
+
},
|
|
107
113
|
async setDocument(pdfDoc) {
|
|
108
114
|
await manager.setDocument(pdfDoc);
|
|
109
115
|
},
|
|
@@ -15,7 +15,7 @@ export function createSearchIndex() {
|
|
|
15
15
|
includeMarkedContent: false,
|
|
16
16
|
disableNormalization: false
|
|
17
17
|
});
|
|
18
|
-
return content.items.
|
|
18
|
+
return content.items.map((item) => "str" in item ? item.str : "").join("");
|
|
19
19
|
}
|
|
20
20
|
async function buildIndex(doc) {
|
|
21
21
|
destroyed = false;
|
|
@@ -54,6 +54,7 @@ export interface ViewerState {
|
|
|
54
54
|
setStylusMode: (enabled: boolean) => void;
|
|
55
55
|
scrollToPage: (pageNumber: number) => void;
|
|
56
56
|
downloadPdf: () => Promise<void>;
|
|
57
|
+
printPdf: () => Promise<void>;
|
|
57
58
|
history: AnnotationHistory;
|
|
58
59
|
readonly: Ref<boolean>;
|
|
59
60
|
shapeDetection: Ref<boolean>;
|
|
@@ -66,6 +67,7 @@ export interface ViewerStateProvider {
|
|
|
66
67
|
state: ViewerState;
|
|
67
68
|
setScrollToPageFn: (fn: (pageNumber: number) => void) => void;
|
|
68
69
|
setDownloadPdfFn: (fn: () => Promise<void>) => void;
|
|
70
|
+
setPrintPdfFn: (fn: () => Promise<void>) => void;
|
|
69
71
|
/** Register how custom-scale changes are applied. The Viewer registers a
|
|
70
72
|
* position-preserving commit (zoom about the viewport centre); without
|
|
71
73
|
* one, setScale falls back to a plain scale write. */
|
|
@@ -152,12 +152,16 @@ export function provideViewerState() {
|
|
|
152
152
|
}
|
|
153
153
|
let _scrollToPageFn = null;
|
|
154
154
|
let _downloadPdfFn = null;
|
|
155
|
+
let _printPdfFn = null;
|
|
155
156
|
function scrollToPage(pageNumber) {
|
|
156
157
|
_scrollToPageFn?.(pageNumber);
|
|
157
158
|
}
|
|
158
159
|
async function downloadPdf() {
|
|
159
160
|
await _downloadPdfFn?.();
|
|
160
161
|
}
|
|
162
|
+
async function printPdf() {
|
|
163
|
+
await _printPdfFn?.();
|
|
164
|
+
}
|
|
161
165
|
const history = createAnnotationHistory(annotations, painter);
|
|
162
166
|
const state = {
|
|
163
167
|
scale,
|
|
@@ -200,6 +204,7 @@ export function provideViewerState() {
|
|
|
200
204
|
setStylusMode,
|
|
201
205
|
scrollToPage,
|
|
202
206
|
downloadPdf,
|
|
207
|
+
printPdf,
|
|
203
208
|
history,
|
|
204
209
|
readonly,
|
|
205
210
|
shapeDetection: shapeDetectionEnabled,
|
|
@@ -217,6 +222,9 @@ export function provideViewerState() {
|
|
|
217
222
|
setDownloadPdfFn(fn) {
|
|
218
223
|
_downloadPdfFn = fn;
|
|
219
224
|
},
|
|
225
|
+
setPrintPdfFn(fn) {
|
|
226
|
+
_printPdfFn = fn;
|
|
227
|
+
},
|
|
220
228
|
setApplyScaleFn(fn) {
|
|
221
229
|
_applyScaleFn = fn;
|
|
222
230
|
}
|
|
@@ -44,6 +44,10 @@ export declare class KViewerEmbedClient {
|
|
|
44
44
|
skipped: number;
|
|
45
45
|
}>;
|
|
46
46
|
exportPdf(options?: ExportPdfOptions): Promise<Uint8Array>;
|
|
47
|
+
/** Open the viewer's print dialog on the exported (vector) PDF —
|
|
48
|
+
* annotations and form values included, at full print quality.
|
|
49
|
+
* Resolves once the dialog is up, not when printing finishes. */
|
|
50
|
+
printPdf(options?: Omit<ExportPdfOptions, 'download' | 'fileName'>): Promise<void>;
|
|
47
51
|
getFormFieldValues(): Promise<FormFieldValue[]>;
|
|
48
52
|
setFormFieldValue(fieldName: string, value: string | boolean | string[]): Promise<void>;
|
|
49
53
|
addFormField(payload: AddFormFieldPayload): Promise<FormFieldDefinition>;
|
|
@@ -60,6 +60,12 @@ export class KViewerEmbedClient {
|
|
|
60
60
|
exportPdf(options) {
|
|
61
61
|
return this.call("exportPdf", options);
|
|
62
62
|
}
|
|
63
|
+
/** Open the viewer's print dialog on the exported (vector) PDF —
|
|
64
|
+
* annotations and form values included, at full print quality.
|
|
65
|
+
* Resolves once the dialog is up, not when printing finishes. */
|
|
66
|
+
printPdf(options) {
|
|
67
|
+
return this.call("printPdf", options);
|
|
68
|
+
}
|
|
63
69
|
getFormFieldValues() {
|
|
64
70
|
return this.call("getFormFieldValues");
|
|
65
71
|
}
|
|
@@ -17,6 +17,7 @@ export interface KViewerApi {
|
|
|
17
17
|
skipped: number;
|
|
18
18
|
}>;
|
|
19
19
|
exportPdf: (options?: ExportPdfOptions) => Promise<Uint8Array>;
|
|
20
|
+
printPdf: (options?: ExportPdfOptions) => Promise<void>;
|
|
20
21
|
getFormFieldValues: () => FormFieldValue[];
|
|
21
22
|
setFormFieldValue: (fieldName: string, value: string | boolean | string[]) => void;
|
|
22
23
|
addFormField: (payload: AddFormFieldPayload) => FormFieldDefinition;
|
|
@@ -32,13 +33,21 @@ export interface KViewerApi {
|
|
|
32
33
|
allSigned: boolean;
|
|
33
34
|
fields: SignatureFieldStatus[];
|
|
34
35
|
}) => void) => () => void;
|
|
35
|
-
formEditMode: Ref<boolean>;
|
|
36
|
+
formEditMode: boolean | Ref<boolean>;
|
|
36
37
|
setFormEditMode: (enabled: boolean) => void;
|
|
37
38
|
toggleFormEditMode: () => boolean;
|
|
38
39
|
allPagesRead: () => boolean;
|
|
39
40
|
getViewedPages: () => number[];
|
|
40
41
|
resetViewedPages: () => void;
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* What the bridge actually requires of a host. Every capability is
|
|
45
|
+
* optional so an embedding application can hand over an adapter exposing
|
|
46
|
+
* only the parts it uses — a real `<KViewer>` ref satisfies this too.
|
|
47
|
+
* Unimplemented methods surface as an `UNSUPPORTED_METHOD_ERROR_NAME`
|
|
48
|
+
* response instead of breaking initialization.
|
|
49
|
+
*/
|
|
50
|
+
export type KViewerHostApi = Partial<KViewerApi>;
|
|
42
51
|
export interface KViewerEmbedBridgeOptions {
|
|
43
52
|
/**
|
|
44
53
|
* Origin of the parent window that hosts this iframe. Used both as
|
|
@@ -67,5 +76,5 @@ interface BridgeHandle {
|
|
|
67
76
|
/** Manually tear down listeners. Called automatically on scope dispose. */
|
|
68
77
|
unmount: () => void;
|
|
69
78
|
}
|
|
70
|
-
export declare function useKViewerEmbedBridge(viewerRef: Ref<
|
|
79
|
+
export declare function useKViewerEmbedBridge(viewerRef: Ref<KViewerHostApi | null | undefined>, options: KViewerEmbedBridgeOptions): BridgeHandle;
|
|
71
80
|
export type { MethodName };
|
|
@@ -1,10 +1,44 @@
|
|
|
1
|
-
import { onScopeDispose, watch } from "vue";
|
|
1
|
+
import { onScopeDispose, unref, watch } from "vue";
|
|
2
2
|
import {
|
|
3
3
|
EVENT_KIND,
|
|
4
4
|
KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
5
5
|
RESPONSE_KIND,
|
|
6
|
+
UNSUPPORTED_METHOD_ERROR_NAME,
|
|
6
7
|
isRequest
|
|
7
8
|
} from "./protocol.js";
|
|
9
|
+
const METHOD_REQUIREMENT = {
|
|
10
|
+
getAnnotations: "getAnnotations",
|
|
11
|
+
importAnnotations: "importAnnotations",
|
|
12
|
+
exportPdf: "exportPdf",
|
|
13
|
+
printPdf: "printPdf",
|
|
14
|
+
getFormFieldValues: "getFormFieldValues",
|
|
15
|
+
setFormFieldValue: "setFormFieldValue",
|
|
16
|
+
addFormField: "addFormField",
|
|
17
|
+
updateFormField: "updateFormField",
|
|
18
|
+
removeFormField: "removeFormField",
|
|
19
|
+
getFormFields: "getFormFields",
|
|
20
|
+
setFieldDefaults: "setFieldDefaults",
|
|
21
|
+
setClickToSign: "setClickToSign",
|
|
22
|
+
getSignedStatus: "getSignedStatus",
|
|
23
|
+
getSignatureFieldStatus: "getSignatureFieldStatus",
|
|
24
|
+
getFormEditMode: "formEditMode",
|
|
25
|
+
setFormEditMode: "setFormEditMode",
|
|
26
|
+
toggleFormEditMode: "toggleFormEditMode",
|
|
27
|
+
allPagesRead: "allPagesRead",
|
|
28
|
+
getViewedPages: "getViewedPages",
|
|
29
|
+
resetViewedPages: "resetViewedPages"
|
|
30
|
+
};
|
|
31
|
+
const ALL_METHODS = Object.keys(METHOD_REQUIREMENT);
|
|
32
|
+
function supportsMethod(viewer, method) {
|
|
33
|
+
const member = METHOD_REQUIREMENT[method];
|
|
34
|
+
if (!member) return false;
|
|
35
|
+
return member === "formEditMode" ? viewer.formEditMode !== void 0 : typeof viewer[member] === "function";
|
|
36
|
+
}
|
|
37
|
+
function unsupportedMethodError(method) {
|
|
38
|
+
const err = new Error(`KViewer embed host does not implement "${method}"`);
|
|
39
|
+
err.name = UNSUPPORTED_METHOD_ERROR_NAME;
|
|
40
|
+
return err;
|
|
41
|
+
}
|
|
8
42
|
export function useKViewerEmbedBridge(viewerRef, options) {
|
|
9
43
|
const allowAny = options.parentOrigin === "*";
|
|
10
44
|
const winMaybe = options.windowRef ?? (typeof window !== "undefined" ? window : void 0);
|
|
@@ -28,10 +62,17 @@ export function useKViewerEmbedBridge(viewerRef, options) {
|
|
|
28
62
|
parent.postMessage(message, options.parentOrigin);
|
|
29
63
|
}
|
|
30
64
|
async function dispatch(req) {
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
65
|
+
const host = viewerRef.value;
|
|
66
|
+
if (!host) {
|
|
33
67
|
throw new Error("KViewer ref is not yet available");
|
|
34
68
|
}
|
|
69
|
+
if (!(req.method in METHOD_REQUIREMENT)) {
|
|
70
|
+
throw new Error(`Unknown KViewer embed method: ${req.method}`);
|
|
71
|
+
}
|
|
72
|
+
if (!supportsMethod(host, req.method)) {
|
|
73
|
+
throw unsupportedMethodError(req.method);
|
|
74
|
+
}
|
|
75
|
+
const viewer = host;
|
|
35
76
|
switch (req.method) {
|
|
36
77
|
case "getAnnotations":
|
|
37
78
|
return viewer.getAnnotations();
|
|
@@ -43,6 +84,11 @@ export function useKViewerEmbedBridge(viewerRef, options) {
|
|
|
43
84
|
const [opts] = req.args;
|
|
44
85
|
return viewer.exportPdf(opts);
|
|
45
86
|
}
|
|
87
|
+
case "printPdf": {
|
|
88
|
+
const [opts] = req.args;
|
|
89
|
+
await viewer.printPdf(opts);
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
46
92
|
case "getFormFieldValues":
|
|
47
93
|
return viewer.getFormFieldValues();
|
|
48
94
|
case "setFormFieldValue": {
|
|
@@ -81,7 +127,7 @@ export function useKViewerEmbedBridge(viewerRef, options) {
|
|
|
81
127
|
case "getSignatureFieldStatus":
|
|
82
128
|
return viewer.getSignatureFieldStatus();
|
|
83
129
|
case "getFormEditMode":
|
|
84
|
-
return viewer.formEditMode
|
|
130
|
+
return unref(viewer.formEditMode);
|
|
85
131
|
case "setFormEditMode": {
|
|
86
132
|
const [enabled] = req.args;
|
|
87
133
|
viewer.setFormEditMode(enabled);
|
|
@@ -138,32 +184,60 @@ export function useKViewerEmbedBridge(viewerRef, options) {
|
|
|
138
184
|
for (const stop of stopViewerStateWatches) stop();
|
|
139
185
|
stopViewerStateWatches = [];
|
|
140
186
|
if (!viewer) return;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
)
|
|
166
|
-
|
|
187
|
+
const events = ["ready"];
|
|
188
|
+
if (viewer.formEditMode !== void 0) {
|
|
189
|
+
events.push("formEditMode-changed");
|
|
190
|
+
stopViewerStateWatches.push(
|
|
191
|
+
watch(
|
|
192
|
+
() => unref(viewer.formEditMode),
|
|
193
|
+
(enabled) => postEvent("formEditMode-changed", { enabled: enabled ?? false })
|
|
194
|
+
)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (typeof viewer.onFieldPlaced === "function") {
|
|
198
|
+
events.push("field-placed");
|
|
199
|
+
stopViewerStateWatches.push(
|
|
200
|
+
viewer.onFieldPlaced(
|
|
201
|
+
(field) => postEvent("field-placed", { field })
|
|
202
|
+
)
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
if (typeof viewer.onSignedStatusChanged === "function") {
|
|
206
|
+
events.push("signedStatus-changed");
|
|
207
|
+
stopViewerStateWatches.push(
|
|
208
|
+
viewer.onSignedStatusChanged(
|
|
209
|
+
(payload) => postEvent("signedStatus-changed", payload)
|
|
210
|
+
)
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (typeof viewer.allPagesRead === "function") {
|
|
214
|
+
events.push("all-pages-read");
|
|
215
|
+
stopViewerStateWatches.push(
|
|
216
|
+
watch(
|
|
217
|
+
() => viewer.allPagesRead?.() ?? false,
|
|
218
|
+
(read, prev) => {
|
|
219
|
+
if (read && !prev) postEvent("all-pages-read", {});
|
|
220
|
+
}
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (typeof viewer.getViewedPages === "function") {
|
|
225
|
+
events.push("viewedPages-changed");
|
|
226
|
+
stopViewerStateWatches.push(
|
|
227
|
+
watch(
|
|
228
|
+
() => viewer.getViewedPages?.() ?? [],
|
|
229
|
+
(pages) => postEvent("viewedPages-changed", {
|
|
230
|
+
pages,
|
|
231
|
+
allRead: viewer.allPagesRead?.() ?? false
|
|
232
|
+
})
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
postEvent("ready", {
|
|
237
|
+
protocolVersion: KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
238
|
+
methods: ALL_METHODS.filter((method) => supportsMethod(viewer, method)),
|
|
239
|
+
events
|
|
240
|
+
});
|
|
167
241
|
},
|
|
168
242
|
{ immediate: true }
|
|
169
243
|
);
|
|
@@ -4,6 +4,12 @@ export declare const KVIEWER_EMBED_PROTOCOL_VERSION = 1;
|
|
|
4
4
|
export declare const REQUEST_KIND: "kviewer:request";
|
|
5
5
|
export declare const RESPONSE_KIND: "kviewer:response";
|
|
6
6
|
export declare const EVENT_KIND: "kviewer:event";
|
|
7
|
+
/**
|
|
8
|
+
* `error.name` on a response rejected because the embedding host's viewer
|
|
9
|
+
* adapter does not implement the requested method. Lets a parent tell a
|
|
10
|
+
* missing capability apart from a genuine failure inside the viewer.
|
|
11
|
+
*/
|
|
12
|
+
export declare const UNSUPPORTED_METHOD_ERROR_NAME = "KViewerUnsupportedMethodError";
|
|
7
13
|
export type ImportAnnotationsMode = 'replace' | 'merge';
|
|
8
14
|
export interface MethodSignatures {
|
|
9
15
|
getAnnotations: {
|
|
@@ -23,6 +29,10 @@ export interface MethodSignatures {
|
|
|
23
29
|
args: [options?: ExportPdfOptions];
|
|
24
30
|
result: Uint8Array;
|
|
25
31
|
};
|
|
32
|
+
printPdf: {
|
|
33
|
+
args: [options?: Omit<ExportPdfOptions, 'download' | 'fileName'>];
|
|
34
|
+
result: undefined;
|
|
35
|
+
};
|
|
26
36
|
getFormFieldValues: {
|
|
27
37
|
args: [];
|
|
28
38
|
result: FormFieldValue[];
|
|
@@ -115,6 +125,13 @@ export type ResponseMessage<M extends MethodName = MethodName> = {
|
|
|
115
125
|
export interface EventPayloads {
|
|
116
126
|
ready: {
|
|
117
127
|
protocolVersion: number;
|
|
128
|
+
/** Methods the host's viewer adapter implements. Absent on hosts
|
|
129
|
+
* predating capability discovery, where the full API was mandatory —
|
|
130
|
+
* treat `undefined` as "assume everything". */
|
|
131
|
+
methods?: MethodName[];
|
|
132
|
+
/** Events the host actually subscribed to. Same `undefined` caveat as
|
|
133
|
+
* `methods`. */
|
|
134
|
+
events?: EventName[];
|
|
118
135
|
};
|
|
119
136
|
'formEditMode-changed': {
|
|
120
137
|
enabled: boolean;
|
|
@@ -2,6 +2,7 @@ export const KVIEWER_EMBED_PROTOCOL_VERSION = 1;
|
|
|
2
2
|
export const REQUEST_KIND = "kviewer:request";
|
|
3
3
|
export const RESPONSE_KIND = "kviewer:response";
|
|
4
4
|
export const EVENT_KIND = "kviewer:event";
|
|
5
|
+
export const UNSUPPORTED_METHOD_ERROR_NAME = "KViewerUnsupportedMethodError";
|
|
5
6
|
export function isRequest(msg) {
|
|
6
7
|
return !!msg && typeof msg === "object" && msg.kind === REQUEST_KIND && msg.v === KVIEWER_EMBED_PROTOCOL_VERSION;
|
|
7
8
|
}
|
|
@@ -15,6 +15,7 @@ export declare const messages: {
|
|
|
15
15
|
readonly clear: "Clear";
|
|
16
16
|
readonly delete: "Delete";
|
|
17
17
|
readonly download: "Download";
|
|
18
|
+
readonly print: "Print";
|
|
18
19
|
readonly search: "Search";
|
|
19
20
|
readonly marqueeSelect: "Marquee select";
|
|
20
21
|
readonly eraser: "Eraser";
|
|
@@ -141,6 +142,7 @@ export declare const messages: {
|
|
|
141
142
|
readonly clear: "Leeren";
|
|
142
143
|
readonly delete: "Löschen";
|
|
143
144
|
readonly download: "Herunterladen";
|
|
145
|
+
readonly print: "Drucken";
|
|
144
146
|
readonly search: "Suchen";
|
|
145
147
|
readonly marqueeSelect: "Mehrfachauswahl";
|
|
146
148
|
readonly eraser: "Radierer";
|
|
@@ -7,6 +7,7 @@ export const messages = {
|
|
|
7
7
|
clear: "Clear",
|
|
8
8
|
delete: "Delete",
|
|
9
9
|
download: "Download",
|
|
10
|
+
print: "Print",
|
|
10
11
|
// Toolbar
|
|
11
12
|
search: "Search",
|
|
12
13
|
marqueeSelect: "Marquee select",
|
|
@@ -140,6 +141,7 @@ export const messages = {
|
|
|
140
141
|
clear: "Leeren",
|
|
141
142
|
delete: "L\xF6schen",
|
|
142
143
|
download: "Herunterladen",
|
|
144
|
+
print: "Drucken",
|
|
143
145
|
search: "Suchen",
|
|
144
146
|
marqueeSelect: "Mehrfachauswahl",
|
|
145
147
|
eraser: "Radierer",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare module '*?url' {
|
|
2
|
+
const url: string;
|
|
3
|
+
export default url;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module 'pngjs' {
|
|
7
|
+
export class PNG {
|
|
8
|
+
constructor(options?: { width?: number; height?: number });
|
|
9
|
+
|
|
10
|
+
static sync: {
|
|
11
|
+
read(data: Buffer): PNG;
|
|
12
|
+
write(image: PNG): Buffer;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
data: Buffer;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -3,11 +3,11 @@ export type { ViewerTabItem, AddTabOptions } from './components/ViewerTabs.vue.j
|
|
|
3
3
|
export type { AddFormFieldPayload, CheckboxStyle, FormFieldDefinition, FormFieldOrigin, FormFieldType, FormFieldValue, PlacedFieldDefaultProps, PlacedFieldDefaults, SignatureData, SignatureFieldStatus, SignatureHandlers, } from './annotation/engine/types.js';
|
|
4
4
|
export type { ViewMode } from './composables/viewMode.js';
|
|
5
5
|
export type { ViewerState, ActiveTool } from './composables/useViewerState.js';
|
|
6
|
-
export type { KViewerApi, KViewerEmbedBridgeOptions, } from './embed/bridge-host.js';
|
|
6
|
+
export type { KViewerApi, KViewerHostApi, KViewerEmbedBridgeOptions, } from './embed/bridge-host.js';
|
|
7
7
|
export { useKViewerEmbedBridge } from './embed/bridge-host.js';
|
|
8
8
|
export type { KViewerEmbedClientOptions } from './embed/bridge-client.js';
|
|
9
9
|
export { KViewerEmbedClient } from './embed/bridge-client.js';
|
|
10
10
|
export type { EventName as KViewerEmbedEventName, EventPayloads as KViewerEmbedEventPayloads, MethodName as KViewerEmbedMethodName, } from './embed/protocol.js';
|
|
11
|
-
export { KVIEWER_EMBED_PROTOCOL_VERSION } from './embed/protocol.js';
|
|
11
|
+
export { KVIEWER_EMBED_PROTOCOL_VERSION, UNSUPPORTED_METHOD_ERROR_NAME as KVIEWER_EMBED_UNSUPPORTED_METHOD_ERROR_NAME, } from './embed/protocol.js';
|
|
12
12
|
export type { ViewerMenuItem, ViewerMenuButtonItem, ViewerMenuCheckboxItem, ViewerMenuSeparatorItem, } from './menu-items.js';
|
|
13
13
|
export type { ViewerToolId, ViewerTopToolId, ViewerBottomToolId, ViewerLayoutToolId, ViewerToolEntry, ViewerToolSlot, } from './toolbar-tools.js';
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { useKViewerEmbedBridge } from "./embed/bridge-host.js";
|
|
2
2
|
export { KViewerEmbedClient } from "./embed/bridge-client.js";
|
|
3
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
5
|
+
UNSUPPORTED_METHOD_ERROR_NAME as KVIEWER_EMBED_UNSUPPORTED_METHOD_ERROR_NAME
|
|
6
|
+
} from "./embed/protocol.js";
|
package/dist/types.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type ActiveTool, type AddFormFieldPayload, type CheckboxStyle, type ExportPdfOptions, type FormFieldDefinition, type FormFieldOrigin, type FormFieldType, type FormFieldValue, type KVIEWER_EMBED_PROTOCOL_VERSION, type KViewerApi, type KViewerEmbedBridgeOptions, type KViewerEmbedClient, type KViewerEmbedClientOptions, type KViewerEmbedEventName, type KViewerEmbedEventPayloads, type KViewerEmbedMethodName, type SignatureData, type SignatureHandlers, type ViewMode, type ViewerBottomToolId, type ViewerLayoutToolId, type ViewerMenuButtonItem, type ViewerMenuCheckboxItem, type ViewerMenuItem, type ViewerMenuSeparatorItem, type ViewerState, type ViewerToolEntry, type ViewerToolId, type ViewerToolSlot, type ViewerTopToolId, type useKViewerEmbedBridge } from '../dist/runtime/public-types.js'
|
|
1
|
+
export { type ActiveTool, type AddFormFieldPayload, type CheckboxStyle, type ExportPdfOptions, type FormFieldDefinition, type FormFieldOrigin, type FormFieldType, type FormFieldValue, type KVIEWER_EMBED_PROTOCOL_VERSION, type KVIEWER_EMBED_UNSUPPORTED_METHOD_ERROR_NAME, type KViewerApi, type KViewerEmbedBridgeOptions, type KViewerEmbedClient, type KViewerEmbedClientOptions, type KViewerEmbedEventName, type KViewerEmbedEventPayloads, type KViewerEmbedMethodName, type KViewerHostApi, type PlacedFieldDefaults, type SignatureData, type SignatureFieldStatus, type SignatureHandlers, type ViewMode, type ViewerBottomToolId, type ViewerLayoutToolId, type ViewerMenuButtonItem, type ViewerMenuCheckboxItem, type ViewerMenuItem, type ViewerMenuSeparatorItem, type ViewerState, type ViewerToolEntry, type ViewerToolId, type ViewerToolSlot, type ViewerTopToolId, type useKViewerEmbedBridge } from '../dist/runtime/public-types.js'
|
|
2
2
|
|
|
3
3
|
export { default } from './module.mjs'
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kviewer",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Kabema PDF Editor",
|
|
5
5
|
"repository": "kabema/kviewer",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"lint": "eslint .",
|
|
66
66
|
"test": "vitest run --exclude '**/e2e/**'",
|
|
67
67
|
"test:watch": "vitest watch",
|
|
68
|
-
"test:types": "vue-tsc --noEmit &&
|
|
68
|
+
"test:types": "pnpm run dev:prepare && pnpm --dir docs exec nuxt prepare && vue-tsc --noEmit && pnpm --dir playground exec vue-tsc --noEmit && pnpm --dir docs exec vue-tsc --noEmit",
|
|
69
69
|
"test:e2e": "playwright test",
|
|
70
70
|
"test:e2e:ui": "playwright test --ui"
|
|
71
71
|
}
|