@campus-admin/ui 2.0.5 → 2.0.7

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
@@ -173,3 +173,74 @@ The directives are registered automatically by `installUi`, which `createCampusA
173
173
  ### 自定义图标字体(2.0.5)
174
174
 
175
175
  `CaIcon.name` / `IconValue` 接受内置图标名(自动补全)或平台类名,如 `iconfont zxt-setting1`;平台提前加载对应 CSS(`::before` 字符、`@font-face` 字体),大小、颜色继承现有图标。内置名优先,字体未声明或下载失败时默认不显示;可传 `fallback="grid"` 使用内置回退。未传 name 的默认插槽用法保持不变。
176
+
177
+ ## Document viewer (2.0.7)
178
+
179
+ `CaDocViewer` / `<ca-doc-viewer>` reads Markdown, PDF, docx, xlsx/xls/csv and UTF-8 text. `CaDocDialog` / `<ca-doc-dialog>` wraps it in an expandable dialog. Both are exported and registered; platforms access them through core.
180
+
181
+ ```vue
182
+ <ca-doc-viewer :source="markdownText" type="md" filename="notes.md" />
183
+ <ca-doc-viewer source="/files/manual.pdf" filename="manual.pdf"
184
+ :fetch-init="{ headers: { Authorization: `Bearer ${token}` } }" text-layer />
185
+ <ca-doc-dialog v-model="open" :source="fileBlob" filename="report.docx"
186
+ title="Document" :meta="{ Author: 'Campus' }" />
187
+ ```
188
+
189
+ `source` accepts URLs, Blob and ArrayBuffer. Text strings require `type="md"`. Detection uses `filename` or Blob / HTTP Content-Type; explicit `type` accepts `md|pdf|docx|xlsx|csv|txt`. `.xls` maps to spreadsheets; unknown valid UTF-8 files fall back to text. URLs use fetch with `fetchInit`, cancellation on source changes, a 30-second timeout and streaming size checks. No business API is assumed. The server must configure CORS and authentication.
190
+
191
+ Props: `loading`, `error`, `toc=true`, `allowImages=false`, `textLayer=false` (PDF text selection). `maxSize` is a byte count or partial map by type. Defaults: md/txt 2 MiB, csv 10 MiB, docx/xlsx 20 MiB, PDF 50 MiB. Oversized files offer download; remote files download directly through the browser to avoid reading the whole file again.
192
+
193
+ Events: `load({type, filename})`, `error(Error)`, `retry()`, `download({source, filename}, event)`. Call `event.preventDefault()` in the download handler to provide authenticated platform downloads. Slots: `toolbar`, `empty`, `unsupported({type})`. The dialog adds `modelValue`, `title`, `meta: Record<string,string|number>` and forwards viewer props/events/slots. The title button or double-click expands it; preference key: `ca-doc-expanded`. Escape, focus return and scroll locking use the framework dialog.
194
+
195
+ ### Dependencies and bundling
196
+
197
+ Required UI dependencies: markdown-it 15.0.3, markdown-it-anchor 10.1.0, markdown-it-footnote 4.0.0, markdown-it-container 4.0.0, dompurify 3.4.18. Task checkboxes use a small built-in plugin.
198
+
199
+ | Feature | Optional peer (also a framework devDependency) | Version |
200
+ | --- | --- | --- |
201
+ | Highlighting | shiki | 4.6.0 |
202
+ | Math | katex | 0.19.1 |
203
+ | Diagrams | mermaid | 12.3.0 |
204
+ | PDF | pdfjs-dist | 6.5.438 |
205
+ | Word | docx-preview | 0.4.1 |
206
+
207
+ Spreadsheets / CSV use SheetJS CE 0.20.3, installed separately on demand without a peer declaration because this version is unavailable in the npm registry. The five packages above remain optional peers. Install only the formats you need. SheetJS must come from its official release:
208
+
209
+ ```sh
210
+ npm install pdfjs-dist@6.5.438 docx-preview@0.4.1
211
+ npm install https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz
212
+ ```
213
+
214
+ Do not install the outdated xlsx registry release with known vulnerabilities. SheetJS stays in framework devDependencies for tests and demos only. **Install and register each required renderer once at application startup**; installing a package alone does not enable it. The five optional-peer declarations and pinned versions are unchanged. Framework runtime code has no bare imports of optional packages, so applications without them can still build. Import only the formats you installed in your registration module:
215
+
216
+ ```ts
217
+ import { registerDocLoader } from '@campus-admin/core'
218
+
219
+ registerDocLoader('xlsx', () => import('xlsx'))
220
+ registerDocLoader('shiki', () => import('shiki'))
221
+ registerDocLoader('mermaid', () => import('mermaid'))
222
+ registerDocLoader('docx-preview', () => import('docx-preview'))
223
+ registerDocLoader('katex', async () => {
224
+ await import('katex/dist/katex.min.css')
225
+ return import('katex')
226
+ })
227
+ registerDocLoader('pdfjs-dist', async () => {
228
+ const [pdf, worker] = await Promise.all([
229
+ import('pdfjs-dist'), import('pdfjs-dist/build/pdf.worker.min.mjs?url'),
230
+ ])
231
+ pdf.GlobalWorkerOptions.workerSrc = worker.default
232
+ return pdf
233
+ })
234
+ ```
235
+
236
+ `registerDocLoader(name, loader)` accepts the six names above and an async function returning that package's module namespace. Only selected formats invoke their loaders. Missing or rejected loaders show an install/register hint; missing highlighting keeps plain text. Without a registered `xlsx` loader, the viewer also accepts `globalThis.XLSX` (SheetJS 0.20.3); registered loaders take precedence. Registration after an error requires retrying the viewer.
237
+
238
+ The PDF loader configures its worker before returning the module. Vite emits the `?url` worker locally without a CDN; other bundlers must provide an equivalent worker URL. The KaTeX loader imports its CSS. CSP must allow same-origin workers (development may require `worker-src 'self' blob:`).
239
+
240
+ ### Security and limits
241
+
242
+ - Raw Markdown HTML is disabled; DOMPurify sanitizes output. Links allow http/https/mailto and generated document anchors; external links use noopener/noreferrer. Images are off by default, only absolute HTTP(S) images are supported, and enabling them contacts their hosts. Mermaid uses strict mode and KaTeX uses trust=false. Nesting and line budgets limit parser work; enhancements operate on parsed tokens.
243
+ - PDF renders the current page only, cancels obsolete render tasks and limits canvas pixels. It does not execute PDF scripts or render interactive forms. Word uses a sandboxed iframe with a restrictive CSP preventing external resources and active content. Document styles cannot affect the host. Pagination, fonts and layout may differ from Microsoft Word; pages retain paper colors.
244
+ - SheetJS displays text and cached values only, without calculating formulas, loading macros or executing cell HTML. Each sheet initially renders 2000 rows, with a show-more action; limits are 256 columns and 100000 visible cells. Sticky headers, merged cells and sheet switching are supported; this is not an Excel editor or style replica. Office ZIP metadata is checked before parsing for format and expansion budgets; oversized documents should be downloaded to a trusted desktop tool.
245
+ - Legacy `.doc` / `.ppt` requires a platform converter: `converter({blob,filename}): Promise<{blob:Blob,type:string}>`, such as `type: 'pdf'` or a PDF MIME type. Converted files are checked again; download retains the original. No conversion server is included.
246
+ - Preview is not a virus scanner. Upload validation and authorization remain server responsibilities. The demo is in `examples/campus/public/samples/` and `pages/components/data/doc-viewer.vue`.
@@ -0,0 +1,132 @@
1
+ import { t as e } from "./button-CNxlqu0z.js";
2
+ import { o as t, r as n, s as r, t as i } from "./loaders-DAfXYCem.js";
3
+ import { Fragment as a, computed as o, createElementBlock as s, createElementVNode as c, createTextVNode as l, createVNode as u, defineComponent as d, nextTick as f, onBeforeUnmount as p, onMounted as m, openBlock as h, ref as g, renderList as _, shallowRef as v, toDisplayString as y, unref as b, vModelSelect as x, vModelText as S, watch as ee, withCtx as C, withDirectives as w } from "vue";
4
+ // packages/ui/src/components/display/doc-viewer/CaDocPdf.vue?vue&type=script&setup=true&lang.ts
5
+ var T = ["aria-busy"], E = { class: "ca-doc-controls" }, D = ["max"], O = { value: "fit" }, k = ["value"], A = { class: "ca-doc-pdf-scroll" }, j = { class: "ca-doc-pdf-page" }, M = ["aria-label"], N = /*#__PURE__*/ r(/* @__PURE__ */ d({
6
+ __name: "CaDocPdf",
7
+ props: {
8
+ data: {},
9
+ textLayer: { type: Boolean }
10
+ },
11
+ emits: ["load", "error"],
12
+ setup(r, { emit: d }) {
13
+ let N = r, P = d, F = t(), I = g(), L = g(), R = g(), z = v(), B = g(1), V = g("fit"), H = g(600), U = g(!1), W = o(() => z.value?.numPages ?? 1), G = !0, K = 0, q, J, Y, X, Z, Q = !1;
14
+ async function $() {
15
+ let e = ++K;
16
+ if (q?.cancel(), J?.cancel(), z.value && L.value && Z) {
17
+ U.value = !0;
18
+ try {
19
+ let t = await z.value.getPage(B.value);
20
+ if (!G || e !== K) return;
21
+ let r = t.getViewport({ scale: 1 }), i = V.value === "fit" ? Math.min(3, Math.max(1, H.value - 24) / r.width) : Number(V.value), a = t.getViewport({ scale: i }), o = Math.min(devicePixelRatio || 1, 2);
22
+ if (!Number.isFinite(a.width * a.height) || a.width * a.height * o ** 2 > 16e6 || Math.max(a.width, a.height) * o > 8192) throw new n("complex");
23
+ let s = L.value;
24
+ if (s.width = Math.floor(a.width * o), s.height = Math.floor(a.height * o), s.style.width = `${a.width}px`, s.style.height = `${a.height}px`, q = t.render({
25
+ canvas: s,
26
+ viewport: a,
27
+ transform: [
28
+ o,
29
+ 0,
30
+ 0,
31
+ o,
32
+ 0,
33
+ 0
34
+ ]
35
+ }), await q.promise, !G || e !== K) return;
36
+ R.value && (R.value.replaceChildren(), R.value.style.setProperty("--total-scale-factor", String(i * a.userUnit)), R.value.style.width = `${a.width}px`, R.value.style.height = `${a.height}px`, N.textLayer && (J = new Z.TextLayer({
37
+ textContentSource: await t.getTextContent(),
38
+ container: R.value,
39
+ viewport: a
40
+ }), await J.render())), Q || (Q = !0, P("load"));
41
+ } catch (t) {
42
+ G && e === K && t.name !== "RenderingCancelledException" && P("error", t);
43
+ } finally {
44
+ e === K && (U.value = !1);
45
+ }
46
+ }
47
+ }
48
+ return m(async () => {
49
+ Y = new ResizeObserver((e) => {
50
+ H.value = e[0]?.contentRect.width ?? 600;
51
+ }), Y.observe(I.value);
52
+ try {
53
+ if (Z = await i("pdfjs-dist"), !G) return;
54
+ let e = Z.getDocument({
55
+ data: N.data.slice(0),
56
+ enableXfa: !1,
57
+ useSystemFonts: !0
58
+ });
59
+ X = e;
60
+ let t = await e.promise;
61
+ if (!G) {
62
+ await e.destroy();
63
+ return;
64
+ }
65
+ z.value = t, await f(), await $();
66
+ } catch (e) {
67
+ G && P("error", e);
68
+ }
69
+ }), ee([
70
+ B,
71
+ V,
72
+ H,
73
+ () => N.textLayer
74
+ ], $), p(() => {
75
+ G = !1, K++, Y?.disconnect(), q?.cancel(), J?.cancel(), X?.destroy();
76
+ }), (t, n) => (h(), s("div", {
77
+ ref_key: "host",
78
+ ref: I,
79
+ class: "ca-doc-pdf",
80
+ "aria-busy": U.value
81
+ }, [c("div", E, [
82
+ u(b(e), {
83
+ disabled: B.value <= 1,
84
+ onClick: n[0] ||= (e) => B.value--
85
+ }, {
86
+ default: C(() => [l(y(b(F)("campus.doc.previous")), 1)]),
87
+ _: 1
88
+ }, 8, ["disabled"]),
89
+ c("label", null, [l(y(b(F)("campus.doc.page")) + " ", 1), w(c("input", {
90
+ "onUpdate:modelValue": n[1] ||= (e) => B.value = e,
91
+ type: "number",
92
+ min: "1",
93
+ max: W.value,
94
+ onChange: n[2] ||= (e) => B.value = Math.min(W.value, Math.max(1, Number(B.value) || 1))
95
+ }, null, 40, D), [[
96
+ S,
97
+ B.value,
98
+ void 0,
99
+ { number: !0 }
100
+ ]])]),
101
+ c("span", null, "/ " + y(W.value), 1),
102
+ u(b(e), {
103
+ disabled: B.value >= W.value,
104
+ onClick: n[3] ||= (e) => B.value++
105
+ }, {
106
+ default: C(() => [l(y(b(F)("campus.doc.next")), 1)]),
107
+ _: 1
108
+ }, 8, ["disabled"]),
109
+ c("label", null, [l(y(b(F)("campus.doc.zoom")) + " ", 1), w(c("select", { "onUpdate:modelValue": n[4] ||= (e) => V.value = e }, [c("option", O, y(b(F)("campus.doc.fit")), 1), (h(), s(a, null, _([
110
+ .5,
111
+ .75,
112
+ 1,
113
+ 1.25,
114
+ 1.5,
115
+ 2,
116
+ 3
117
+ ], (e) => c("option", {
118
+ key: e,
119
+ value: String(e)
120
+ }, y(e * 100) + "%", 9, k)), 64))], 512), [[x, V.value]])])
121
+ ]), c("div", A, [c("div", j, [c("canvas", {
122
+ ref_key: "canvas",
123
+ ref: L,
124
+ "aria-label": b(F)("campus.doc.page")
125
+ }, null, 8, M), c("div", {
126
+ ref_key: "textHost",
127
+ ref: R,
128
+ class: "ca-doc-text-layer"
129
+ }, null, 512)])])], 8, T));
130
+ }
131
+ }), [["__scopeId", "data-v-032259db"]]);
132
+ export { N as default };
@@ -0,0 +1,52 @@
1
+ import { o as e, r as t, s as n, t as r } from "./loaders-DAfXYCem.js";
2
+ import { createElementBlock as i, defineComponent as a, onBeforeUnmount as o, openBlock as s, ref as c, unref as l } from "vue";
3
+ import u from "dompurify";
4
+ // packages/ui/src/components/display/doc-viewer/CaDocWord.vue?vue&type=script&setup=true&lang.ts
5
+ var d = ["title"], f = "default-src 'none'; img-src data: blob:; font-src data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'", p = /*#__PURE__*/ n(/* @__PURE__ */ a({
6
+ __name: "CaDocWord",
7
+ props: { data: {} },
8
+ emits: ["load", "error"],
9
+ setup(n, { emit: a }) {
10
+ let p = n, m = a, h = c(), g = e(), _ = !0, v = `<!doctype html><html><head><meta http-equiv="Content-Security-Policy" content="${f}"><style>body{margin:0;background:#e8eaed}.docx-wrapper{padding:12px!important}section.docx{max-width:100%;box-sizing:border-box}a{pointer-events:none}</style></head><body></body></html>`;
11
+ async function y() {
12
+ try {
13
+ let e = await r("docx-preview"), n = document.createElement("div"), i = document.createElement("div");
14
+ if (await e.renderAsync(p.data.slice(0), n, i, {
15
+ breakPages: !0,
16
+ useBase64URL: !0,
17
+ renderAltChunks: !1,
18
+ renderComments: !1
19
+ }), !_) return;
20
+ let a = h.value?.contentDocument;
21
+ if (!a?.body) throw new t("renderFailed");
22
+ let o = (e) => u.sanitize(e.innerHTML, {
23
+ RETURN_DOM_FRAGMENT: !0,
24
+ FORCE_BODY: !0,
25
+ ADD_TAGS: ["style"],
26
+ FORBID_TAGS: [
27
+ "script",
28
+ "iframe",
29
+ "object",
30
+ "embed",
31
+ "form"
32
+ ]
33
+ });
34
+ a.body.append(o(i), o(n)), m("load");
35
+ } catch (e) {
36
+ _ && m("error", e);
37
+ }
38
+ }
39
+ return o(() => {
40
+ _ = !1;
41
+ }), (e, t) => (s(), i("iframe", {
42
+ ref_key: "frame",
43
+ ref: h,
44
+ class: "ca-doc-word",
45
+ sandbox: "allow-same-origin",
46
+ title: l(g)("campus.doc.word"),
47
+ srcdoc: v,
48
+ onLoad: y
49
+ }, null, 40, d));
50
+ }
51
+ }), [["__scopeId", "data-v-9d673c1c"]]);
52
+ export { p as default };
@@ -0,0 +1,13 @@
1
+ import { ElButton as e, ElButtonGroup as t } from "element-plus";
2
+ import "element-plus/es/components/button/style/css";
3
+ import "element-plus/es/components/button-group/style/css";
4
+ // packages/ui/src/shared/wrap.ts
5
+ function n(e) {
6
+ return e;
7
+ }
8
+ // packages/ui/src/components/button/index.ts
9
+ var r = n(e), i = n(t), a = {
10
+ CaButton: r,
11
+ CaButtonGroup: i
12
+ };
13
+ export { n as i, i as n, a as r, r as t };
@@ -0,0 +1,24 @@
1
+ import type { DocViewerProps } from './types.js';
2
+ type __VLS_Props = DocViewerProps & {
3
+ modelValue: boolean;
4
+ title?: string;
5
+ meta?: Record<string, string | number>;
6
+ textLayer?: boolean;
7
+ };
8
+ declare var __VLS_29: string, __VLS_30: any;
9
+ type __VLS_Slots = {} & {
10
+ [K in NonNullable<typeof __VLS_29>]?: (props: typeof __VLS_30) => any;
11
+ };
12
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
13
+ "update:modelValue": (value: boolean) => any;
14
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
15
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
16
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
18
+ declare const _default: typeof __VLS_export;
19
+ export default _default;
20
+ type __VLS_WithSlots<T, S> = T & {
21
+ new (): {
22
+ $slots: S;
23
+ };
24
+ };
@@ -0,0 +1,13 @@
1
+ type __VLS_Props = {
2
+ data: ArrayBuffer;
3
+ textLayer?: boolean;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ error: (error: Error) => any;
7
+ load: () => any;
8
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
9
+ onError?: ((error: Error) => any) | undefined;
10
+ onLoad?: (() => any) | undefined;
11
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
@@ -0,0 +1,46 @@
1
+ import { type DocViewerProps, type DocType } from './types.js';
2
+ import './doc-viewer.css';
3
+ type __VLS_Props = DocViewerProps & {
4
+ textLayer?: boolean;
5
+ };
6
+ declare var __VLS_1: {}, __VLS_25: {}, __VLS_27: {
7
+ type: "legacy" | "unsupported";
8
+ };
9
+ type __VLS_Slots = {} & {
10
+ toolbar?: (props: typeof __VLS_1) => any;
11
+ } & {
12
+ empty?: (props: typeof __VLS_25) => any;
13
+ } & {
14
+ unsupported?: (props: typeof __VLS_27) => any;
15
+ };
16
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
17
+ download: (file: {
18
+ source: DocViewerProps["source"];
19
+ filename: string;
20
+ }, event: Event) => any;
21
+ error: (error: Error) => any;
22
+ load: (file: {
23
+ type: DocType;
24
+ filename: string;
25
+ }) => any;
26
+ retry: () => any;
27
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
28
+ onDownload?: ((file: {
29
+ source: DocViewerProps["source"];
30
+ filename: string;
31
+ }, event: Event) => any) | undefined;
32
+ onError?: ((error: Error) => any) | undefined;
33
+ onLoad?: ((file: {
34
+ type: DocType;
35
+ filename: string;
36
+ }) => any) | undefined;
37
+ onRetry?: (() => any) | undefined;
38
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
39
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
40
+ declare const _default: typeof __VLS_export;
41
+ export default _default;
42
+ type __VLS_WithSlots<T, S> = T & {
43
+ new (): {
44
+ $slots: S;
45
+ };
46
+ };
@@ -0,0 +1,12 @@
1
+ type __VLS_Props = {
2
+ data: ArrayBuffer;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
5
+ error: (error: Error) => any;
6
+ load: () => any;
7
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
8
+ onError?: ((error: Error) => any) | undefined;
9
+ onLoad?: (() => any) | undefined;
10
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,4 @@
1
+ export type DocLoaderName = 'xlsx' | 'shiki' | 'katex' | 'mermaid' | 'pdfjs-dist' | 'docx-preview';
2
+ /** 在应用启动时注册;import 由使用方构建器解析,未安装的格式不会进入依赖图。 */
3
+ export declare function registerDocLoader(name: DocLoaderName, loader: () => Promise<unknown>): void;
4
+ export declare function loadDocModule<T>(name: DocLoaderName): Promise<T>;
@@ -0,0 +1,19 @@
1
+ import MarkdownIt from 'markdown-it';
2
+ export interface DocHeading {
3
+ id: string;
4
+ text: string;
5
+ level: number;
6
+ }
7
+ export declare function safeLink(value: string): boolean;
8
+ export declare function createMarkdown(prefix?: string): MarkdownIt;
9
+ export declare function sanitizeMarkdown(html: string, allowImages?: boolean): string;
10
+ export declare function renderMarkdown(source: string, allowImages: boolean, prefix: string): Promise<{
11
+ html: string;
12
+ headings: DocHeading[];
13
+ diagrams: {
14
+ id: string;
15
+ source: string;
16
+ }[];
17
+ warnings: string[];
18
+ }>;
19
+ export declare function sanitizeDiagram(svg: string): string;
@@ -0,0 +1,12 @@
1
+ import type { WorkSheet } from 'xlsx';
2
+ export interface SheetCell {
3
+ text: string;
4
+ colspan: number;
5
+ rowspan: number;
6
+ }
7
+ export declare function sheetGrid(sheet: WorkSheet, limit: number): {
8
+ rows: SheetCell[][];
9
+ shown: number;
10
+ total: number;
11
+ capped: boolean;
12
+ };
@@ -0,0 +1,13 @@
1
+ import { type DocSource, type DocType, type DocViewerProps } from './types.js';
2
+ export declare function detectType(filename?: string, mime?: string): DocType | 'legacy' | 'unsupported';
3
+ export declare function sizeLimit(type: ReturnType<typeof detectType>, max?: DocViewerProps['maxSize']): number;
4
+ export declare function checkSize(size: number, limit: number): void;
5
+ export declare function decodeText(data: ArrayBuffer): string;
6
+ export declare function validateSignature(data: ArrayBuffer, type: DocType): void;
7
+ export declare function readSource(source: DocSource, props: DocViewerProps, signal: AbortSignal): Promise<{
8
+ blob: Blob;
9
+ filename: string;
10
+ type: DocType | "legacy" | "unsupported";
11
+ }>;
12
+ /** 解析 ZIP 中央目录,只检查元数据,不解压;先拒绝伪装格式和压缩炸弹。 */
13
+ export declare function validateArchive(data: ArrayBuffer, type: DocType): void;
@@ -0,0 +1,27 @@
1
+ export type DocType = 'md' | 'pdf' | 'docx' | 'xlsx' | 'csv' | 'txt';
2
+ export type DocSource = string | Blob | ArrayBuffer;
3
+ export type DocConverter = (file: {
4
+ blob: Blob;
5
+ filename: string;
6
+ }) => Promise<{
7
+ blob: Blob;
8
+ type: string;
9
+ }>;
10
+ export interface DocViewerProps {
11
+ source?: DocSource;
12
+ filename?: string;
13
+ type?: DocType;
14
+ loading?: boolean;
15
+ error?: string;
16
+ maxSize?: number | Partial<Record<DocType, number>>;
17
+ toc?: boolean;
18
+ allowImages?: boolean;
19
+ converter?: DocConverter;
20
+ fetchInit?: RequestInit;
21
+ }
22
+ export declare const defaultMaxSize: Record<DocType, number>;
23
+ export declare class DocError extends Error {
24
+ key: string;
25
+ detail: string;
26
+ constructor(key: string, detail?: string);
27
+ }
@@ -33,6 +33,8 @@ import 'element-plus/es/components/segmented/style/css';
33
33
  import 'element-plus/es/components/statistic/style/css';
34
34
  import 'element-plus/es/components/countdown/style/css';
35
35
  import 'element-plus/es/components/check-tag/style/css';
36
+ import CaDocViewer from './doc-viewer/CaDocViewer.vue';
37
+ import CaDocDialog from './doc-viewer/CaDocDialog.vue';
36
38
  import CaStatCard from './stat-card/CaStatCard.vue';
37
39
  import CaStatusTag from './status-tag/CaStatusTag.vue';
38
40
  export declare const CaAvatar: typeof ElAvatar;
@@ -63,7 +65,10 @@ export declare const CaSegmented: typeof ElSegmented;
63
65
  export declare const CaStatistic: typeof ElStatistic;
64
66
  export declare const CaCountdown: typeof ElCountdown;
65
67
  export declare const CaCheckTag: typeof ElCheckTag;
66
- export { CaStatCard, CaStatusTag };
68
+ export { CaStatCard, CaStatusTag, CaDocViewer, CaDocDialog };
69
+ export { registerDocLoader } from './doc-viewer/loaders.js';
70
+ export type { DocLoaderName } from './doc-viewer/loaders.js';
71
+ export type { DocType, DocSource, DocConverter, DocViewerProps } from './doc-viewer/types.js';
67
72
  export type { StatusMap, TagType } from './types.js';
68
73
  export declare const displayComponents: {
69
74
  CaAvatar: typeof CaAvatar;
@@ -94,6 +99,8 @@ export declare const displayComponents: {
94
99
  CaStatistic: typeof CaStatistic;
95
100
  CaCountdown: typeof CaCountdown;
96
101
  CaCheckTag: typeof CaCheckTag;
102
+ CaDocViewer: typeof CaDocViewer;
103
+ CaDocDialog: typeof CaDocDialog;
97
104
  CaStatCard: typeof CaStatCard;
98
105
  CaStatusTag: typeof CaStatusTag;
99
106
  };
@@ -2,7 +2,10 @@ declare var __VLS_7: {};
2
2
  type __VLS_Slots = {} & {
3
3
  default?: (props: typeof __VLS_7) => any;
4
4
  };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
5
+ declare const __VLS_base: import("vue").DefineComponent<{}, {
6
+ open: (index: string) => void | undefined;
7
+ close: (index: string) => void | undefined;
8
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
9
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
10
  declare const _default: typeof __VLS_export;
8
11
  export default _default;