jvs-docx-ui 0.0.0-stage → 0.1.0

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 CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # jvs-docx-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 基于 **Vue 3 + TypeScript + Vite + docxjs (`docx-preview`)** 构建的 Word (`.docx`) 文档预览组件库,同时支持 **独立站点部署** 与 **Vue 3 插件 NPM 发布**。
4
+
5
+ ## 1. 开发与构建指令
6
+
7
+ ```bash
8
+ # 安装依赖
9
+ pnpm install
10
+
11
+ # 启动本地开发调试 (支持 0.0.0.0 局域网访问)
12
+ pnpm dev
13
+
14
+ # 构建可独立部署的 Web 应用(产物位于 dist/app)
15
+ pnpm build
16
+
17
+ # 构建可发布的 Vue 3 插件库(产物位于 dist/lib,包含 ES/UMD 与 .d.ts 类型声明)
18
+ pnpm build:lib
19
+ ```
20
+
21
+ ## 2. 作为插件在外部项目中使用
22
+
23
+ ### 全局注册
24
+
25
+ ```ts
26
+ import { createApp } from 'vue'
27
+ import JvsDocxUi from 'jvs-docx-ui'
28
+ import 'jvs-docx-ui/style.css'
29
+ import App from './App.vue'
30
+
31
+ const app = createApp(App)
32
+ app.use(JvsDocxUi)
33
+ app.mount('#app')
34
+ ```
35
+
36
+ ### 按需引入与方法调用
37
+
38
+ ```vue
39
+ <script setup lang="ts">
40
+ import { ref } from 'vue'
41
+ import { JvsDocx, type JvsDocxExpose } from 'jvs-docx-ui'
42
+ import 'jvs-docx-ui/style.css'
43
+
44
+ const docxRef = ref<JvsDocxExpose | null>(null)
45
+
46
+ async function onFileChange(e: Event) {
47
+ const file = (e.target as HTMLInputElement).files?.[0]
48
+ if (file) {
49
+ await docxRef.value?.importDocxFile(file, file.name)
50
+ }
51
+ }
52
+
53
+ async function onExport() {
54
+ await docxRef.value?.exportDocxFile('导出文档.docx', true)
55
+ }
56
+ </script>
57
+
58
+ <template>
59
+ <div style="height: 600px">
60
+ <JvsDocx ref="docxRef" />
61
+ </div>
62
+ </template>
63
+ ```
@@ -0,0 +1,96 @@
1
+ import { ComponentOptionsMixin } from 'vue';
2
+ import { ComponentProvideOptions } from 'vue';
3
+ import { defaultOptions } from 'docx-preview';
4
+ import { DefineComponent } from 'vue';
5
+ import { Options as DocxPreviewOptions } from 'docx-preview';
6
+ import { parseAsync } from 'docx-preview';
7
+ import { Plugin as Plugin_2 } from 'vue';
8
+ import { PublicProps } from 'vue';
9
+ import { renderAsync } from 'docx-preview';
10
+ import { renderDocument } from 'docx-preview';
11
+ import { WordDocument } from 'docx-preview';
12
+
13
+ export { defaultOptions }
14
+
15
+ export declare const DOCX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
16
+
17
+ export declare type DocxInputSource = File | Blob | ArrayBuffer | Uint8Array | string;
18
+
19
+ export { DocxPreviewOptions }
20
+
21
+ /**
22
+ * 触发浏览器下载 .docx Blob
23
+ */
24
+ export declare function downloadDocxBlob(blob: Blob, fileName?: string): void;
25
+
26
+ export declare const JvsDocx: DefineComponent<JvsDocxProps, {
27
+ importDocxFile: (source: DocxInputSource, fileName?: string) => Promise<WordDocument>;
28
+ renderDocx: (source: DocxInputSource, fileName?: string) => Promise<WordDocument>;
29
+ exportDocxFile: (fileName?: string, download?: boolean) => Promise<Blob>;
30
+ clear: () => void;
31
+ getWordDocument: () => WordDocument | null;
32
+ getBlob: () => Blob | null;
33
+ getContainer: () => HTMLElement | null;
34
+ }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
35
+ rendered: (document: any) => any;
36
+ error: (error: Error) => any;
37
+ change: (blob: Blob | null) => any;
38
+ }, string, PublicProps, Readonly<JvsDocxProps> & Readonly<{
39
+ onRendered?: ((document: any) => any) | undefined;
40
+ onError?: ((error: Error) => any) | undefined;
41
+ onChange?: ((blob: Blob | null) => any) | undefined;
42
+ }>, {
43
+ fileContent: DocxInputSource;
44
+ fileUrl: string;
45
+ fileName: string;
46
+ options: Partial<DocxPreviewOptions>;
47
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {
48
+ previewContainerRef: HTMLDivElement;
49
+ }, HTMLDivElement>;
50
+
51
+ export declare interface JvsDocxExpose {
52
+ /** 使用 docxjs 导入并渲染 .docx 文件(支持 File / Blob / ArrayBuffer / Uint8Array / Base64 / URL) */
53
+ importDocxFile: (source: DocxInputSource, fileName?: string) => Promise<WordDocument>;
54
+ /** 使用 docxjs 渲染加载 .docx 文件(importDocxFile 的别名) */
55
+ renderDocx: (source: DocxInputSource, fileName?: string) => Promise<WordDocument>;
56
+ /** 导出当前预览的 .docx 文件 */
57
+ exportDocxFile: (fileName?: string, download?: boolean) => Promise<Blob>;
58
+ /** 清空当前文档预览内容 */
59
+ clear: () => void;
60
+ /** 获取当前 docxjs 解析后的 WordDocument AST 对象 */
61
+ getWordDocument: () => WordDocument | null;
62
+ /** 获取当前文档的原始 Blob 数据 */
63
+ getBlob: () => Blob | null;
64
+ /** 获取预览容器 DOM 节点 */
65
+ getContainer: () => HTMLElement | null;
66
+ }
67
+
68
+ export declare interface JvsDocxProps {
69
+ /** Word (.docx) 文件内容(支持 File / Blob / ArrayBuffer / Uint8Array / Base64 字符串 / URL) */
70
+ fileContent?: DocxInputSource;
71
+ /** 远程或本地 .docx 文件地址 */
72
+ fileUrl?: string;
73
+ /** 默认文档名称(用于导出时默认文件名) */
74
+ fileName?: string;
75
+ /** docxjs (docx-preview) 渲染配置项 */
76
+ options?: Partial<DocxPreviewOptions>;
77
+ }
78
+
79
+ declare const JvsDocxUiPlugin: Plugin_2;
80
+ export { JvsDocxUiPlugin }
81
+ export default JvsDocxUiPlugin;
82
+
83
+ /**
84
+ * 将各种输入源(File / Blob / ArrayBuffer / Uint8Array / Base64 / URL)统一转换为 Blob
85
+ */
86
+ export declare function normalizeDocxSourceToBlob(source: DocxInputSource): Promise<Blob>;
87
+
88
+ export { parseAsync }
89
+
90
+ export { renderAsync }
91
+
92
+ export { renderDocument }
93
+
94
+ export { WordDocument }
95
+
96
+ export { }
@@ -0,0 +1 @@
1
+ .jvs-docx-viewer[data-v-ebacf228]{position:relative;width:100%;height:100%;min-height:360px;background-color:#f1f5f9;overflow:hidden;display:flex;flex-direction:column}.jvs-docx-viewer__styles[data-v-ebacf228]{display:none}.jvs-docx-viewer__container[data-v-ebacf228]{flex:1;width:100%;height:100%;overflow:auto}.jvs-docx-viewer__overlay[data-v-ebacf228]{position:absolute;top:0;right:0;bottom:0;left:0;z-index:5;background-color:#f1f5f9;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:32px;color:#64748b;text-align:center;-webkit-user-select:none;user-select:none}.jvs-docx-viewer__overlay--error[data-v-ebacf228]{color:#ef4444}.jvs-docx-viewer__empty-icon[data-v-ebacf228]{display:flex;align-items:center;justify-content:center;width:76px;height:76px;border-radius:16px;background-color:#e2e8f0;color:#64748b;margin-bottom:16px}.jvs-docx-viewer__state-title[data-v-ebacf228]{margin:0 0 6px;font-size:15px;font-weight:600;color:#334155}.jvs-docx-viewer__overlay--error .jvs-docx-viewer__state-title[data-v-ebacf228]{margin-top:12px;color:#dc2626}.jvs-docx-viewer__state-desc[data-v-ebacf228]{margin:0;font-size:13px;color:#94a3b8;max-width:420px;line-height:1.6}.jvs-docx-viewer__state-text[data-v-ebacf228]{margin:14px 0 0;font-size:13px;color:#64748b}.jvs-docx-viewer__spinner[data-v-ebacf228]{width:32px;height:32px;border:3px solid #cbd5e1;border-top-color:#2563eb;border-radius:50%;animation:jvs-docx-spin-ebacf228 .75s linear infinite}@keyframes jvs-docx-spin-ebacf228{to{transform:rotate(360deg)}}.jvs-docx-viewer__container[data-v-ebacf228] .docx-wrapper{background-color:#f1f5f9;padding:24px 16px 40px;display:flex;flex-direction:column;align-items:center;min-height:100%}.jvs-docx-viewer__container[data-v-ebacf228] .docx-wrapper>section.docx{background-color:#fff;box-shadow:0 4px 16px #0f172a14,0 1px 3px #0f172a0a;border-radius:2px;margin-bottom:20px;padding:72pt 90pt}.jvs-docx-viewer__container[data-v-ebacf228] section.docx p[class*=docx-num-]:before{white-space:pre;margin-right:4pt}.jvs-docx-viewer__container[data-v-ebacf228] section.docx table{max-width:100%}.jvs-docx-viewer__container[data-v-ebacf228] section.docx img{max-width:100%}