kviewer 0.0.11 → 0.1.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/dist/module.d.mts +9 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +22 -2
- package/dist/runtime/annotation/engine/painter.d.ts +8 -1
- package/dist/runtime/annotation/engine/painter.js +11 -6
- package/dist/runtime/annotation/engine/tools/form-field.d.ts +6 -0
- package/dist/runtime/annotation/engine/tools/form-field.js +3 -1
- package/dist/runtime/annotation/engine/types.d.ts +64 -0
- package/dist/runtime/annotation/pdf-export/export-form-fields.js +102 -52
- package/dist/runtime/assets/kviewer.css +1 -1
- package/dist/runtime/components/PdfPage.vue +6 -1
- package/dist/runtime/components/Viewer.d.vue.ts +41 -1
- package/dist/runtime/components/Viewer.vue +84 -3
- package/dist/runtime/components/Viewer.vue.d.ts +41 -1
- package/dist/runtime/components/ViewerBar.d.vue.ts +7 -1
- package/dist/runtime/components/ViewerBar.vue +36 -0
- package/dist/runtime/components/ViewerBar.vue.d.ts +7 -1
- package/dist/runtime/components/ViewerTabs.d.vue.ts +29 -6
- package/dist/runtime/components/ViewerTabs.vue +11 -2
- package/dist/runtime/components/ViewerTabs.vue.d.ts +29 -6
- package/dist/runtime/components/form-fields/FormFieldWrapper.vue +10 -2
- package/dist/runtime/components/form-fields/PlacedFieldChrome.vue +1 -1
- package/dist/runtime/composables/useAnnotationEngine.d.ts +1 -0
- package/dist/runtime/composables/useAnnotationEngine.js +2 -1
- package/dist/runtime/composables/useFormFields.d.ts +40 -3
- package/dist/runtime/composables/useFormFields.js +101 -1
- package/dist/runtime/composables/useInertiaPanzoom.js +1 -0
- package/dist/runtime/composables/usePageProxyCache.d.ts +4 -0
- package/dist/runtime/composables/usePageProxyCache.js +4 -1
- package/dist/runtime/composables/useScriptingBridge.d.ts +29 -0
- package/dist/runtime/composables/useScriptingBridge.js +74 -0
- package/dist/runtime/composables/useScriptingManager.d.ts +65 -0
- package/dist/runtime/composables/useScriptingManager.js +123 -0
- package/dist/runtime/embed/bridge-client.d.ts +58 -0
- package/dist/runtime/embed/bridge-client.js +143 -0
- package/dist/runtime/embed/bridge-host.d.ts +59 -0
- package/dist/runtime/embed/bridge-host.js +136 -0
- package/dist/runtime/embed/protocol.d.ts +105 -0
- package/dist/runtime/embed/protocol.js +13 -0
- package/dist/runtime/menu-items.d.ts +34 -0
- package/dist/runtime/menu-items.js +0 -0
- package/dist/runtime/public-types.d.ts +8 -1
- package/dist/runtime/public-types.js +3 -0
- package/dist/types.d.mts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
3
|
+
REQUEST_KIND,
|
|
4
|
+
isEvent,
|
|
5
|
+
isResponse
|
|
6
|
+
} from "./protocol.js";
|
|
7
|
+
let nextRequestId = 0;
|
|
8
|
+
function makeRequestId() {
|
|
9
|
+
nextRequestId += 1;
|
|
10
|
+
return `kvr-${Date.now().toString(36)}-${nextRequestId.toString(36)}`;
|
|
11
|
+
}
|
|
12
|
+
export class KViewerEmbedClient {
|
|
13
|
+
iframe;
|
|
14
|
+
options;
|
|
15
|
+
win;
|
|
16
|
+
allowAny;
|
|
17
|
+
pending = /* @__PURE__ */ new Map();
|
|
18
|
+
handlers = /* @__PURE__ */ new Map();
|
|
19
|
+
disposed = false;
|
|
20
|
+
constructor(iframe, options) {
|
|
21
|
+
this.iframe = iframe;
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.allowAny = options.iframeOrigin === "*";
|
|
24
|
+
const win = options.windowRef ?? (typeof window !== "undefined" ? window : void 0);
|
|
25
|
+
if (!win) {
|
|
26
|
+
throw new Error("KViewerEmbedClient requires a window (browser environment)");
|
|
27
|
+
}
|
|
28
|
+
this.win = win;
|
|
29
|
+
this.win.addEventListener("message", this.handleMessage);
|
|
30
|
+
}
|
|
31
|
+
/** Tear down the message listener and reject any in-flight requests. */
|
|
32
|
+
dispose() {
|
|
33
|
+
if (this.disposed) return;
|
|
34
|
+
this.disposed = true;
|
|
35
|
+
this.win.removeEventListener("message", this.handleMessage);
|
|
36
|
+
const err = new Error("KViewerEmbedClient was disposed");
|
|
37
|
+
for (const { reject } of this.pending.values()) reject(err);
|
|
38
|
+
this.pending.clear();
|
|
39
|
+
this.handlers.clear();
|
|
40
|
+
}
|
|
41
|
+
/** Subscribe to an iframe-emitted event. Returns an unsubscribe fn. */
|
|
42
|
+
on(name, handler) {
|
|
43
|
+
let set = this.handlers.get(name);
|
|
44
|
+
if (!set) {
|
|
45
|
+
set = /* @__PURE__ */ new Set();
|
|
46
|
+
this.handlers.set(name, set);
|
|
47
|
+
}
|
|
48
|
+
set.add(handler);
|
|
49
|
+
return () => {
|
|
50
|
+
set?.delete(handler);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// ── method mirrors ─────────────────────────────────────────────────────
|
|
54
|
+
getAnnotations() {
|
|
55
|
+
return this.call("getAnnotations");
|
|
56
|
+
}
|
|
57
|
+
importAnnotations(annotations, options) {
|
|
58
|
+
return this.call("importAnnotations", annotations, options);
|
|
59
|
+
}
|
|
60
|
+
exportPdf(options) {
|
|
61
|
+
return this.call("exportPdf", options);
|
|
62
|
+
}
|
|
63
|
+
getFormFieldValues() {
|
|
64
|
+
return this.call("getFormFieldValues");
|
|
65
|
+
}
|
|
66
|
+
setFormFieldValue(fieldName, value) {
|
|
67
|
+
return this.call("setFormFieldValue", fieldName, value);
|
|
68
|
+
}
|
|
69
|
+
addFormField(payload) {
|
|
70
|
+
return this.call("addFormField", payload);
|
|
71
|
+
}
|
|
72
|
+
updateFormField(id, patch) {
|
|
73
|
+
return this.call("updateFormField", id, patch);
|
|
74
|
+
}
|
|
75
|
+
removeFormField(id) {
|
|
76
|
+
return this.call("removeFormField", id);
|
|
77
|
+
}
|
|
78
|
+
getFormFields() {
|
|
79
|
+
return this.call("getFormFields");
|
|
80
|
+
}
|
|
81
|
+
getFormEditMode() {
|
|
82
|
+
return this.call("getFormEditMode");
|
|
83
|
+
}
|
|
84
|
+
setFormEditMode(enabled) {
|
|
85
|
+
return this.call("setFormEditMode", enabled);
|
|
86
|
+
}
|
|
87
|
+
toggleFormEditMode() {
|
|
88
|
+
return this.call("toggleFormEditMode");
|
|
89
|
+
}
|
|
90
|
+
// ── internals ──────────────────────────────────────────────────────────
|
|
91
|
+
call(method, ...args) {
|
|
92
|
+
if (this.disposed) {
|
|
93
|
+
return Promise.reject(new Error("KViewerEmbedClient was disposed"));
|
|
94
|
+
}
|
|
95
|
+
const target = this.iframe.contentWindow;
|
|
96
|
+
if (!target) {
|
|
97
|
+
return Promise.reject(new Error("iframe has no contentWindow"));
|
|
98
|
+
}
|
|
99
|
+
const id = makeRequestId();
|
|
100
|
+
const message = {
|
|
101
|
+
kind: REQUEST_KIND,
|
|
102
|
+
v: KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
103
|
+
id,
|
|
104
|
+
method,
|
|
105
|
+
args
|
|
106
|
+
};
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
this.pending.set(id, {
|
|
109
|
+
resolve,
|
|
110
|
+
reject
|
|
111
|
+
});
|
|
112
|
+
target.postMessage(message, this.options.iframeOrigin);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
handleMessage = (event) => {
|
|
116
|
+
if (!this.allowAny && event.origin !== this.options.iframeOrigin) return;
|
|
117
|
+
if (event.source !== this.iframe.contentWindow) return;
|
|
118
|
+
if (isResponse(event.data)) {
|
|
119
|
+
const pending = this.pending.get(event.data.id);
|
|
120
|
+
if (!pending) return;
|
|
121
|
+
this.pending.delete(event.data.id);
|
|
122
|
+
if (event.data.ok) {
|
|
123
|
+
pending.resolve(event.data.result);
|
|
124
|
+
} else {
|
|
125
|
+
const err = new Error(event.data.error.message);
|
|
126
|
+
if (event.data.error.name) err.name = event.data.error.name;
|
|
127
|
+
pending.reject(err);
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (isEvent(event.data)) {
|
|
132
|
+
const set = this.handlers.get(event.data.name);
|
|
133
|
+
if (!set) return;
|
|
134
|
+
for (const handler of set) {
|
|
135
|
+
try {
|
|
136
|
+
handler(event.data.payload);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
console.error("[KViewerEmbedClient] event handler threw:", err);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import type { ExportPdfOptions } from '../annotation/pdf-export/export.js';
|
|
3
|
+
import type { AddFormFieldPayload, FormFieldDefinition, FormFieldValue, IAnnotationStore } from '../annotation/engine/types.js';
|
|
4
|
+
import { type MethodName } from './protocol.js';
|
|
5
|
+
/**
|
|
6
|
+
* Surface the bridge calls on the KViewer template ref. Mirrors the
|
|
7
|
+
* methods defined in `defineExpose` inside Viewer.vue. Kept as a
|
|
8
|
+
* structural type so a real `<KViewer>` ref satisfies it without any
|
|
9
|
+
* extra wiring at the call site.
|
|
10
|
+
*/
|
|
11
|
+
export interface KViewerApi {
|
|
12
|
+
getAnnotations: () => IAnnotationStore[];
|
|
13
|
+
importAnnotations: (annotations: IAnnotationStore[], options?: {
|
|
14
|
+
mode?: 'replace' | 'merge';
|
|
15
|
+
}) => Promise<{
|
|
16
|
+
loaded: number;
|
|
17
|
+
skipped: number;
|
|
18
|
+
}>;
|
|
19
|
+
exportPdf: (options?: ExportPdfOptions) => Promise<Uint8Array>;
|
|
20
|
+
getFormFieldValues: () => FormFieldValue[];
|
|
21
|
+
setFormFieldValue: (fieldName: string, value: string | boolean | string[]) => void;
|
|
22
|
+
addFormField: (payload: AddFormFieldPayload) => FormFieldDefinition;
|
|
23
|
+
updateFormField: (id: string, patch: Partial<FormFieldDefinition>) => void;
|
|
24
|
+
removeFormField: (id: string) => void;
|
|
25
|
+
getFormFields: () => FormFieldDefinition[];
|
|
26
|
+
formEditMode: Ref<boolean>;
|
|
27
|
+
setFormEditMode: (enabled: boolean) => void;
|
|
28
|
+
toggleFormEditMode: () => boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface KViewerEmbedBridgeOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Origin of the parent window that hosts this iframe. Used both as
|
|
33
|
+
* the inbound origin allowlist (anything else is dropped) and as the
|
|
34
|
+
* `targetOrigin` for outbound messages.
|
|
35
|
+
*
|
|
36
|
+
* Pass `'*'` to allow any origin. Demo / development only — there is
|
|
37
|
+
* no origin verification in that mode and `postMessage` will broadcast
|
|
38
|
+
* to whatever window happens to be the parent.
|
|
39
|
+
*/
|
|
40
|
+
parentOrigin: string;
|
|
41
|
+
/**
|
|
42
|
+
* Optional override for the window the host listens on. Defaults to
|
|
43
|
+
* `window`. Useful for tests.
|
|
44
|
+
*/
|
|
45
|
+
windowRef?: Window;
|
|
46
|
+
/**
|
|
47
|
+
* Optional override for the parent window receiver. Defaults to
|
|
48
|
+
* `window.parent`. The bridge falls back to the request's
|
|
49
|
+
* `event.source` for replies, so this is only needed for the unsolicited
|
|
50
|
+
* `ready` and `formEditMode-changed` events.
|
|
51
|
+
*/
|
|
52
|
+
parentWindow?: Window;
|
|
53
|
+
}
|
|
54
|
+
interface BridgeHandle {
|
|
55
|
+
/** Manually tear down listeners. Called automatically on scope dispose. */
|
|
56
|
+
unmount: () => void;
|
|
57
|
+
}
|
|
58
|
+
export declare function useKViewerEmbedBridge(viewerRef: Ref<KViewerApi | null | undefined>, options: KViewerEmbedBridgeOptions): BridgeHandle;
|
|
59
|
+
export type { MethodName };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { onScopeDispose, watch } from "vue";
|
|
2
|
+
import {
|
|
3
|
+
EVENT_KIND,
|
|
4
|
+
KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
5
|
+
RESPONSE_KIND,
|
|
6
|
+
isRequest
|
|
7
|
+
} from "./protocol.js";
|
|
8
|
+
export function useKViewerEmbedBridge(viewerRef, options) {
|
|
9
|
+
const allowAny = options.parentOrigin === "*";
|
|
10
|
+
const winMaybe = options.windowRef ?? (typeof window !== "undefined" ? window : void 0);
|
|
11
|
+
if (!winMaybe) {
|
|
12
|
+
return { unmount: () => {
|
|
13
|
+
} };
|
|
14
|
+
}
|
|
15
|
+
const win = winMaybe;
|
|
16
|
+
const parent = options.parentWindow ?? win.parent;
|
|
17
|
+
function originAllowed(origin) {
|
|
18
|
+
return allowAny || origin === options.parentOrigin;
|
|
19
|
+
}
|
|
20
|
+
function postEvent(name, payload) {
|
|
21
|
+
if (!parent || parent === win) return;
|
|
22
|
+
const message = {
|
|
23
|
+
kind: EVENT_KIND,
|
|
24
|
+
v: KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
25
|
+
name,
|
|
26
|
+
payload
|
|
27
|
+
};
|
|
28
|
+
parent.postMessage(message, options.parentOrigin);
|
|
29
|
+
}
|
|
30
|
+
async function dispatch(req) {
|
|
31
|
+
const viewer = viewerRef.value;
|
|
32
|
+
if (!viewer) {
|
|
33
|
+
throw new Error("KViewer ref is not yet available");
|
|
34
|
+
}
|
|
35
|
+
switch (req.method) {
|
|
36
|
+
case "getAnnotations":
|
|
37
|
+
return viewer.getAnnotations();
|
|
38
|
+
case "importAnnotations": {
|
|
39
|
+
const [annotations, opts] = req.args;
|
|
40
|
+
return viewer.importAnnotations(annotations, opts);
|
|
41
|
+
}
|
|
42
|
+
case "exportPdf": {
|
|
43
|
+
const [opts] = req.args;
|
|
44
|
+
return viewer.exportPdf(opts);
|
|
45
|
+
}
|
|
46
|
+
case "getFormFieldValues":
|
|
47
|
+
return viewer.getFormFieldValues();
|
|
48
|
+
case "setFormFieldValue": {
|
|
49
|
+
const [name, value] = req.args;
|
|
50
|
+
viewer.setFormFieldValue(name, value);
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
case "addFormField": {
|
|
54
|
+
const [payload] = req.args;
|
|
55
|
+
return viewer.addFormField(payload);
|
|
56
|
+
}
|
|
57
|
+
case "updateFormField": {
|
|
58
|
+
const [id, patch] = req.args;
|
|
59
|
+
viewer.updateFormField(id, patch);
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
case "removeFormField": {
|
|
63
|
+
const [id] = req.args;
|
|
64
|
+
viewer.removeFormField(id);
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
case "getFormFields":
|
|
68
|
+
return viewer.getFormFields();
|
|
69
|
+
case "getFormEditMode":
|
|
70
|
+
return viewer.formEditMode.value;
|
|
71
|
+
case "setFormEditMode": {
|
|
72
|
+
const [enabled] = req.args;
|
|
73
|
+
viewer.setFormEditMode(enabled);
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
case "toggleFormEditMode":
|
|
77
|
+
return viewer.toggleFormEditMode();
|
|
78
|
+
default:
|
|
79
|
+
throw new Error(`Unknown KViewer embed method: ${req.method}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function handleMessage(event) {
|
|
83
|
+
if (!originAllowed(event.origin)) return;
|
|
84
|
+
if (!isRequest(event.data)) return;
|
|
85
|
+
const req = event.data;
|
|
86
|
+
let reply;
|
|
87
|
+
try {
|
|
88
|
+
const result = await dispatch(req);
|
|
89
|
+
reply = {
|
|
90
|
+
kind: RESPONSE_KIND,
|
|
91
|
+
v: KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
92
|
+
id: req.id,
|
|
93
|
+
ok: true,
|
|
94
|
+
result
|
|
95
|
+
};
|
|
96
|
+
} catch (err) {
|
|
97
|
+
reply = {
|
|
98
|
+
kind: RESPONSE_KIND,
|
|
99
|
+
v: KVIEWER_EMBED_PROTOCOL_VERSION,
|
|
100
|
+
id: req.id,
|
|
101
|
+
ok: false,
|
|
102
|
+
error: {
|
|
103
|
+
message: err instanceof Error ? err.message : String(err),
|
|
104
|
+
name: err instanceof Error ? err.name : void 0
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const target = event.source ?? parent;
|
|
109
|
+
if (!target) return;
|
|
110
|
+
target.postMessage(reply, event.origin === "" ? options.parentOrigin : event.origin);
|
|
111
|
+
}
|
|
112
|
+
win.addEventListener("message", handleMessage);
|
|
113
|
+
let stopFormEditWatch = null;
|
|
114
|
+
const stopViewerWatch = watch(
|
|
115
|
+
viewerRef,
|
|
116
|
+
(viewer) => {
|
|
117
|
+
stopFormEditWatch?.();
|
|
118
|
+
stopFormEditWatch = null;
|
|
119
|
+
if (!viewer) return;
|
|
120
|
+
postEvent("ready", { protocolVersion: KVIEWER_EMBED_PROTOCOL_VERSION });
|
|
121
|
+
stopFormEditWatch = watch(
|
|
122
|
+
viewer.formEditMode,
|
|
123
|
+
(enabled) => postEvent("formEditMode-changed", { enabled })
|
|
124
|
+
);
|
|
125
|
+
},
|
|
126
|
+
{ immediate: true }
|
|
127
|
+
);
|
|
128
|
+
function unmount() {
|
|
129
|
+
win.removeEventListener("message", handleMessage);
|
|
130
|
+
stopViewerWatch();
|
|
131
|
+
stopFormEditWatch?.();
|
|
132
|
+
stopFormEditWatch = null;
|
|
133
|
+
}
|
|
134
|
+
onScopeDispose(unmount);
|
|
135
|
+
return { unmount };
|
|
136
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ExportPdfOptions } from '../annotation/pdf-export/export.js';
|
|
2
|
+
import type { AddFormFieldPayload, FormFieldDefinition, FormFieldValue, IAnnotationStore } from '../annotation/engine/types.js';
|
|
3
|
+
export declare const KVIEWER_EMBED_PROTOCOL_VERSION = 1;
|
|
4
|
+
export declare const REQUEST_KIND: "kviewer:request";
|
|
5
|
+
export declare const RESPONSE_KIND: "kviewer:response";
|
|
6
|
+
export declare const EVENT_KIND: "kviewer:event";
|
|
7
|
+
export type ImportAnnotationsMode = 'replace' | 'merge';
|
|
8
|
+
export interface MethodSignatures {
|
|
9
|
+
getAnnotations: {
|
|
10
|
+
args: [];
|
|
11
|
+
result: IAnnotationStore[];
|
|
12
|
+
};
|
|
13
|
+
importAnnotations: {
|
|
14
|
+
args: [annotations: IAnnotationStore[], options?: {
|
|
15
|
+
mode?: ImportAnnotationsMode;
|
|
16
|
+
}];
|
|
17
|
+
result: {
|
|
18
|
+
loaded: number;
|
|
19
|
+
skipped: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exportPdf: {
|
|
23
|
+
args: [options?: ExportPdfOptions];
|
|
24
|
+
result: Uint8Array;
|
|
25
|
+
};
|
|
26
|
+
getFormFieldValues: {
|
|
27
|
+
args: [];
|
|
28
|
+
result: FormFieldValue[];
|
|
29
|
+
};
|
|
30
|
+
setFormFieldValue: {
|
|
31
|
+
args: [fieldName: string, value: string | boolean | string[]];
|
|
32
|
+
result: undefined;
|
|
33
|
+
};
|
|
34
|
+
addFormField: {
|
|
35
|
+
args: [payload: AddFormFieldPayload];
|
|
36
|
+
result: FormFieldDefinition;
|
|
37
|
+
};
|
|
38
|
+
updateFormField: {
|
|
39
|
+
args: [id: string, patch: Partial<FormFieldDefinition>];
|
|
40
|
+
result: undefined;
|
|
41
|
+
};
|
|
42
|
+
removeFormField: {
|
|
43
|
+
args: [id: string];
|
|
44
|
+
result: undefined;
|
|
45
|
+
};
|
|
46
|
+
getFormFields: {
|
|
47
|
+
args: [];
|
|
48
|
+
result: FormFieldDefinition[];
|
|
49
|
+
};
|
|
50
|
+
getFormEditMode: {
|
|
51
|
+
args: [];
|
|
52
|
+
result: boolean;
|
|
53
|
+
};
|
|
54
|
+
setFormEditMode: {
|
|
55
|
+
args: [enabled: boolean];
|
|
56
|
+
result: undefined;
|
|
57
|
+
};
|
|
58
|
+
toggleFormEditMode: {
|
|
59
|
+
args: [];
|
|
60
|
+
result: boolean;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export type MethodName = keyof MethodSignatures;
|
|
64
|
+
export interface RequestMessage<M extends MethodName = MethodName> {
|
|
65
|
+
kind: typeof REQUEST_KIND;
|
|
66
|
+
v: typeof KVIEWER_EMBED_PROTOCOL_VERSION;
|
|
67
|
+
id: string;
|
|
68
|
+
method: M;
|
|
69
|
+
args: MethodSignatures[M]['args'];
|
|
70
|
+
}
|
|
71
|
+
export type ResponseMessage<M extends MethodName = MethodName> = {
|
|
72
|
+
kind: typeof RESPONSE_KIND;
|
|
73
|
+
v: typeof KVIEWER_EMBED_PROTOCOL_VERSION;
|
|
74
|
+
id: string;
|
|
75
|
+
ok: true;
|
|
76
|
+
result: MethodSignatures[M]['result'];
|
|
77
|
+
} | {
|
|
78
|
+
kind: typeof RESPONSE_KIND;
|
|
79
|
+
v: typeof KVIEWER_EMBED_PROTOCOL_VERSION;
|
|
80
|
+
id: string;
|
|
81
|
+
ok: false;
|
|
82
|
+
error: {
|
|
83
|
+
message: string;
|
|
84
|
+
name?: string;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export interface EventPayloads {
|
|
88
|
+
ready: {
|
|
89
|
+
protocolVersion: number;
|
|
90
|
+
};
|
|
91
|
+
'formEditMode-changed': {
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export type EventName = keyof EventPayloads;
|
|
96
|
+
export interface EventMessage<E extends EventName = EventName> {
|
|
97
|
+
kind: typeof EVENT_KIND;
|
|
98
|
+
v: typeof KVIEWER_EMBED_PROTOCOL_VERSION;
|
|
99
|
+
name: E;
|
|
100
|
+
payload: EventPayloads[E];
|
|
101
|
+
}
|
|
102
|
+
export type AnyMessage = RequestMessage | ResponseMessage | EventMessage;
|
|
103
|
+
export declare function isRequest(msg: unknown): msg is RequestMessage;
|
|
104
|
+
export declare function isResponse(msg: unknown): msg is ResponseMessage;
|
|
105
|
+
export declare function isEvent(msg: unknown): msg is EventMessage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const KVIEWER_EMBED_PROTOCOL_VERSION = 1;
|
|
2
|
+
export const REQUEST_KIND = "kviewer:request";
|
|
3
|
+
export const RESPONSE_KIND = "kviewer:response";
|
|
4
|
+
export const EVENT_KIND = "kviewer:event";
|
|
5
|
+
export function isRequest(msg) {
|
|
6
|
+
return !!msg && typeof msg === "object" && msg.kind === REQUEST_KIND && msg.v === KVIEWER_EMBED_PROTOCOL_VERSION;
|
|
7
|
+
}
|
|
8
|
+
export function isResponse(msg) {
|
|
9
|
+
return !!msg && typeof msg === "object" && msg.kind === RESPONSE_KIND && msg.v === KVIEWER_EMBED_PROTOCOL_VERSION;
|
|
10
|
+
}
|
|
11
|
+
export function isEvent(msg) {
|
|
12
|
+
return !!msg && typeof msg === "object" && msg.kind === EVENT_KIND && msg.v === KVIEWER_EMBED_PROTOCOL_VERSION;
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** A custom item appended to the viewer's burger menu. Pass an array of
|
|
2
|
+
* these to `<KViewer :menu-items="...">` (or `<KViewerTabs>`) to extend
|
|
3
|
+
* the menu without replacing the built-in entries.
|
|
4
|
+
*
|
|
5
|
+
* Inspired by Nuxt UI's `UNavigationMenu` items pattern, but scoped to
|
|
6
|
+
* the small set of controls a viewer menu needs in practice. */
|
|
7
|
+
export type ViewerMenuItem = ViewerMenuButtonItem | ViewerMenuCheckboxItem | ViewerMenuSeparatorItem;
|
|
8
|
+
export interface ViewerMenuButtonItem {
|
|
9
|
+
type: 'button';
|
|
10
|
+
/** Stable key for Vue list rendering. Keep unique within the array. */
|
|
11
|
+
key: string;
|
|
12
|
+
label: string;
|
|
13
|
+
/** Lucide-style icon name passed through to the underlying UButton. */
|
|
14
|
+
icon?: string;
|
|
15
|
+
/** Fired on click. */
|
|
16
|
+
onSelect: () => void;
|
|
17
|
+
/** Disables the item without removing it. */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ViewerMenuCheckboxItem {
|
|
21
|
+
type: 'checkbox';
|
|
22
|
+
key: string;
|
|
23
|
+
label: string;
|
|
24
|
+
icon?: string;
|
|
25
|
+
/** Current checked state — keep this reactive (Vue will re-render). */
|
|
26
|
+
checked: boolean;
|
|
27
|
+
/** Fired with the new state when the user toggles the item. */
|
|
28
|
+
onUpdate: (checked: boolean) => void;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ViewerMenuSeparatorItem {
|
|
32
|
+
type: 'separator';
|
|
33
|
+
key: string;
|
|
34
|
+
}
|
|
File without changes
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export type { ExportPdfOptions } from './annotation/pdf-export/export.js';
|
|
2
2
|
export type { ViewerTabItem, AddTabOptions } from './components/ViewerTabs.vue.js';
|
|
3
|
-
export type { SignatureData, SignatureHandlers } from './annotation/engine/types.js';
|
|
3
|
+
export type { AddFormFieldPayload, CheckboxStyle, FormFieldDefinition, FormFieldOrigin, FormFieldType, FormFieldValue, SignatureData, SignatureHandlers, } from './annotation/engine/types.js';
|
|
4
4
|
export type { ViewMode } from './composables/viewMode.js';
|
|
5
|
+
export type { KViewerApi, KViewerEmbedBridgeOptions, } from './embed/bridge-host.js';
|
|
6
|
+
export { useKViewerEmbedBridge } from './embed/bridge-host.js';
|
|
7
|
+
export type { KViewerEmbedClientOptions } from './embed/bridge-client.js';
|
|
8
|
+
export { KViewerEmbedClient } from './embed/bridge-client.js';
|
|
9
|
+
export type { EventName as KViewerEmbedEventName, EventPayloads as KViewerEmbedEventPayloads, MethodName as KViewerEmbedMethodName, } from './embed/protocol.js';
|
|
10
|
+
export { KVIEWER_EMBED_PROTOCOL_VERSION } from './embed/protocol.js';
|
|
11
|
+
export type { ViewerMenuItem, ViewerMenuButtonItem, ViewerMenuCheckboxItem, ViewerMenuSeparatorItem, } from './menu-items.js';
|
package/dist/types.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type ExportPdfOptions, type SignatureData, type SignatureHandlers, type ViewMode } from '../dist/runtime/public-types.js'
|
|
1
|
+
export { 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 ViewerMenuButtonItem, type ViewerMenuCheckboxItem, type ViewerMenuItem, type ViewerMenuSeparatorItem, type useKViewerEmbedBridge } from '../dist/runtime/public-types.js'
|
|
2
2
|
|
|
3
3
|
export { default } from './module.mjs'
|
|
4
4
|
|