@ibiz-template-plugin/ibiz-file-previewer 0.0.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.
Files changed (37) hide show
  1. package/README.md +37 -0
  2. package/dist/index.cjs +1 -0
  3. package/dist/index.es.js +26625 -0
  4. package/dist/index.umd.js +1 -0
  5. package/dist/style.css +51 -0
  6. package/dist/types/component/file-preview-item/file-preview-image-group/file-preview-image-group.d.ts +34 -0
  7. package/dist/types/component/file-preview-item/file-preview-image-group/image-page/image-page.d.ts +38 -0
  8. package/dist/types/component/file-preview-item/file-preview-image-group/thumbnail-panel/thumbnail-panel.d.ts +28 -0
  9. package/dist/types/component/file-preview-item/file-preview-img/file-preview-img.d.ts +19 -0
  10. package/dist/types/component/file-preview-item/file-preview-json/file-preview-json.d.ts +18 -0
  11. package/dist/types/component/file-preview-item/file-preview-md/file-preview-md.d.ts +20 -0
  12. package/dist/types/component/file-preview-item/file-preview-text/file-preview-text.d.ts +18 -0
  13. package/dist/types/component/file-preview-item/file-preview-unknown/file-preview-unkown.d.ts +17 -0
  14. package/dist/types/component/file-preview-item/file-preview-xml/file-preview-xml.d.ts +18 -0
  15. package/dist/types/component/file-preview-shell/file-preview-shell.d.ts +24 -0
  16. package/dist/types/const/action-type.d.ts +6 -0
  17. package/dist/types/const/constant.d.ts +6 -0
  18. package/dist/types/const/file-type.d.ts +34 -0
  19. package/dist/types/controller/file-preview-image-controller.d.ts +18 -0
  20. package/dist/types/controller/file-preview-image-group-controller.d.ts +16 -0
  21. package/dist/types/controller/file-preview-item-controller.d.ts +37 -0
  22. package/dist/types/controller/file-preview-item-dispatcher.d.ts +31 -0
  23. package/dist/types/controller/file-preview-md-controller.d.ts +10 -0
  24. package/dist/types/controller/file-preview-shell-controller.d.ts +77 -0
  25. package/dist/types/controller/file-preview-text-controller.d.ts +11 -0
  26. package/dist/types/controller/index.d.ts +4 -0
  27. package/dist/types/hook/index.d.ts +1 -0
  28. package/dist/types/hook/use-teleport-with-delay.d.ts +8 -0
  29. package/dist/types/icon/index.d.ts +9 -0
  30. package/dist/types/index.d.ts +3 -0
  31. package/dist/types/interface/i-file-preview-item-controller.d.ts +91 -0
  32. package/dist/types/interface/i-file-preview-shell-controller.d.ts +59 -0
  33. package/dist/types/interface/i-file-previewer-option.d.ts +94 -0
  34. package/dist/types/interface/index.d.ts +3 -0
  35. package/dist/types/util/index.d.ts +1 -0
  36. package/dist/types/util/util.d.ts +13 -0
  37. package/package.json +43 -0
@@ -0,0 +1,77 @@
1
+ import { Ref } from 'vue';
2
+ import { IFilePreviewerOption, IFilePreviewShellController, IFilePreviewerData, IFilePreviewShellState } from '../interface';
3
+ /**
4
+ * 文件预览器控制器
5
+ */
6
+ export declare class FilePreviewShellController implements IFilePreviewShellController {
7
+ private options;
8
+ /**
9
+ * 当前 Vue 应用
10
+ */
11
+ private currentApp;
12
+ /**
13
+ * 文件预览器状态对象
14
+ */
15
+ state: Ref<IFilePreviewShellState>;
16
+ /**
17
+ * 构造函数
18
+ * @param options
19
+ */
20
+ constructor(options: IFilePreviewerOption);
21
+ /**
22
+ * 解析参数
23
+ */
24
+ private parseParams;
25
+ /**
26
+ * 解析引擎类型
27
+ */
28
+ private parseEngineType;
29
+ /**
30
+ * 解析预览项
31
+ * @param data
32
+ */
33
+ private parsePreviewItem;
34
+ /**
35
+ * 挂载组件实例
36
+ */
37
+ private mountComponent;
38
+ /**
39
+ * 销毁组件实例
40
+ */
41
+ private destroyComponent;
42
+ /**
43
+ * 更新视图
44
+ * @param data
45
+ */
46
+ updateView(data: IFilePreviewerData): Promise<void>;
47
+ /**
48
+ * 获取内容
49
+ * @returns
50
+ */
51
+ getOptions(): IFilePreviewerOption;
52
+ /**
53
+ * 获取状态
54
+ * @returns
55
+ */
56
+ getState(): IFilePreviewShellState;
57
+ /**
58
+ * 下载原始文件
59
+ * @param event
60
+ */
61
+ downloadOriginal(event: MouseEvent): Promise<void>;
62
+ /**
63
+ * 复制文本内容
64
+ * @param event
65
+ */
66
+ copyTextContent(event: MouseEvent): Promise<void>;
67
+ /**
68
+ * 导出为PDF
69
+ * @param event
70
+ */
71
+ exportToPdf(event: MouseEvent): Promise<void>;
72
+ /**
73
+ * 导出为MD
74
+ * @param event
75
+ */
76
+ exportToMd(event: MouseEvent): Promise<void>;
77
+ }
@@ -0,0 +1,11 @@
1
+ import { IFilePreviewItemState } from '../interface';
2
+ import { FilePreviewItemController } from './file-preview-item-controller';
3
+ /**
4
+ * 文本类预览控制器
5
+ */
6
+ export declare class FilePreviewTextController<S extends IFilePreviewItemState = IFilePreviewItemState> extends FilePreviewItemController<S> {
7
+ /**
8
+ * 获取内容
9
+ */
10
+ getContent(): Promise<string | object>;
11
+ }
@@ -0,0 +1,4 @@
1
+ export { FilePreviewShellController } from './file-preview-shell-controller';
2
+ export { FilePreviewTextController } from './file-preview-text-controller';
3
+ export { FilePreviewImageController } from './file-preview-image-controller';
4
+ export { FilePreviewImageGroupController } from './file-preview-image-group-controller';
@@ -0,0 +1 @@
1
+ export { useTeleportWithDelay } from './use-teleport-with-delay';
@@ -0,0 +1,8 @@
1
+ import { Ref } from 'vue';
2
+ /**
3
+ * 延迟渲染 Teleport 内容的 Hook
4
+ * 解决目标元素未准备好的问题
5
+ */
6
+ export declare const useTeleportWithDelay: () => {
7
+ shouldRender: Ref<boolean>;
8
+ };
@@ -0,0 +1,9 @@
1
+ import { JSX } from "vue/jsx-runtime";
2
+ export declare const ZoomOutSvg: () => JSX.Element;
3
+ export declare const ZoomInSvg: () => JSX.Element;
4
+ export declare const DownLoadSvg: () => JSX.Element;
5
+ export declare const ClockwiseSvg: () => JSX.Element;
6
+ export declare const CounterClockwiseSvg: () => JSX.Element;
7
+ export declare const ThumbnailSvg: () => JSX.Element;
8
+ export declare const UpPageSvg: () => JSX.Element;
9
+ export declare const DownPageSvg: () => JSX.Element;
@@ -0,0 +1,3 @@
1
+ export { FilePreviewShellController } from './controller';
2
+ export type { IFilePreviewerData, IFilePreviewerOption } from './interface';
3
+ export { ActionType } from './const/action-type';
@@ -0,0 +1,91 @@
1
+ import { IFilePreviewShellController } from './i-file-preview-shell-controller';
2
+ /**
3
+ * 文件预览项状态
4
+ */
5
+ export interface IFilePreviewItemState {
6
+ /**
7
+ * 文件内容
8
+ */
9
+ content: string | object;
10
+ /**
11
+ * 放大倍数
12
+ */
13
+ scale: number;
14
+ /**
15
+ * 主题
16
+ */
17
+ theme: 'light' | 'dark';
18
+ }
19
+ /**
20
+ * 文件预览图片状态
21
+ */
22
+ export interface IFilePreviewImageState extends IFilePreviewItemState {
23
+ /**
24
+ * 旋转角度
25
+ */
26
+ rotate: number;
27
+ }
28
+ /**
29
+ * 文件预览图片组状态
30
+ */
31
+ export interface IFilePreviewImageGroupState extends IFilePreviewItemState {
32
+ /**
33
+ * 缩略图面板是否显示
34
+ */
35
+ showThumbnailPanel: boolean;
36
+ /**
37
+ * 当前页码
38
+ */
39
+ currentPage: number;
40
+ /**
41
+ * 图片组列表
42
+ */
43
+ items: {
44
+ description: string;
45
+ image_url: string;
46
+ index: number;
47
+ }[];
48
+ /**
49
+ * 总数
50
+ */
51
+ total: number;
52
+ }
53
+ /**
54
+ * 文件预览初始化参数
55
+ */
56
+ export interface IInitializeParam {
57
+ /**
58
+ * 主题
59
+ */
60
+ theme: 'light' | 'dark';
61
+ }
62
+ /**
63
+ * 文件预览控制器
64
+ */
65
+ export interface IFilePreviewItemController {
66
+ /**
67
+ * 状态
68
+ */
69
+ state: Record<string, any>;
70
+ /**
71
+ * 初始化
72
+ * @param param 初始化参数
73
+ */
74
+ initialize(param: IInitializeParam): Promise<void>;
75
+ /**
76
+ * 获取内容
77
+ */
78
+ getContent(): Promise<string | object>;
79
+ /**
80
+ * 缩小预览
81
+ */
82
+ zoomOutPreview(event: MouseEvent): void;
83
+ /**
84
+ * 放大预览
85
+ */
86
+ zoomInPreview(event: MouseEvent): void;
87
+ }
88
+ /**
89
+ * 文件预览构造函数
90
+ */
91
+ export type IFilePreviewItemConstructor = (filePreviewShell: IFilePreviewShellController) => IFilePreviewItemController;
@@ -0,0 +1,59 @@
1
+ import { Component } from 'vue';
2
+ import { IFilePreviewerData, IFilePreviewerOption } from './i-file-previewer-option';
3
+ import { IFilePreviewItemController } from './i-file-preview-item-controller';
4
+ import { EngineType } from '../const/file-type';
5
+ /**
6
+ * 文件预览壳状态
7
+ */
8
+ export interface IFilePreviewShellState {
9
+ /**
10
+ * 文件ID
11
+ */
12
+ fileId: string;
13
+ /**
14
+ * 文件名称
15
+ */
16
+ fileName: string;
17
+ /**
18
+ * 文件类型
19
+ */
20
+ fileType: string;
21
+ /**
22
+ * 文件分类
23
+ */
24
+ fileCat: string;
25
+ /**
26
+ * 预览组件
27
+ */
28
+ preViewComp: Component | undefined;
29
+ /**
30
+ * 预览控制器
31
+ */
32
+ preViewController: IFilePreviewItemController | undefined;
33
+ /**
34
+ * 主题
35
+ */
36
+ theme: 'light' | 'dark';
37
+ /**
38
+ * 引擎类型
39
+ */
40
+ engineType: EngineType;
41
+ }
42
+ /**
43
+ * 文件预览壳控制器接口
44
+ */
45
+ export interface IFilePreviewShellController {
46
+ /**
47
+ * 更新视图
48
+ * @param data
49
+ */
50
+ updateView(data: IFilePreviewerData): Promise<void>;
51
+ /**
52
+ * 获取预览壳配置项
53
+ */
54
+ getOptions(): IFilePreviewerOption;
55
+ /**
56
+ * 获取预览器状态
57
+ */
58
+ getState(): IFilePreviewShellState;
59
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * 文件预览组件配置项 - 通过 URL 预览
3
+ */
4
+ interface IFilePreviewerDataWithURL {
5
+ /**
6
+ * 预览文件ID
7
+ */
8
+ id?: string;
9
+ /**
10
+ * 预览文件名称
11
+ */
12
+ name?: string;
13
+ /**
14
+ * 预览文件分类
15
+ */
16
+ cat?: string;
17
+ /**
18
+ * 预览文件URL
19
+ */
20
+ url: string;
21
+ }
22
+ /**
23
+ * 文件预览组件配置项 - 通过 ID 预览,当使用ID时,name是必需的
24
+ */
25
+ interface IFilePreviewerDataWithID {
26
+ /**
27
+ * 预览文件ID
28
+ */
29
+ id: string;
30
+ /**
31
+ * 预览文件名称
32
+ */
33
+ name: string;
34
+ /**
35
+ * 预览文件分类
36
+ */
37
+ cat: string;
38
+ /**
39
+ * 预览文件URL
40
+ */
41
+ url?: string;
42
+ }
43
+ /**
44
+ * 定义通用属性接口
45
+ */
46
+ export interface IFilePreviewerOption {
47
+ /**
48
+ * 主题
49
+ */
50
+ theme?: 'light' | 'dark';
51
+ /**
52
+ * 挂载点
53
+ */
54
+ selector: string;
55
+ /**
56
+ * 获取文件内容
57
+ * @param id 标识
58
+ * @param type 类型
59
+ * @param cat 分类
60
+ */
61
+ getContent(id: string, type: string, cat: string): Promise<string | object | undefined>;
62
+ /**
63
+ * 获取文件路径
64
+ * @param id
65
+ * @param cat
66
+ * @returns
67
+ */
68
+ getUrl: (id: string, cat: string) => Promise<string>;
69
+ /**
70
+ * 上传文件至oss
71
+ * @param file
72
+ */
73
+ upLoadFileToOss(url: string): Promise<{
74
+ id: string;
75
+ name: string;
76
+ cat: string;
77
+ } | undefined>;
78
+ /**
79
+ * 下载文件
80
+ * @param id
81
+ * @param cat
82
+ */
83
+ downLoadFile(id: string, name: string, cat: string): Promise<void>;
84
+ /**
85
+ * 文件操作成功
86
+ * @param type
87
+ */
88
+ actionSuccessCallBack(type: string): Promise<void>;
89
+ }
90
+ /**
91
+ * 文件预览组件配置项
92
+ */
93
+ export type IFilePreviewerData = IFilePreviewerDataWithURL | IFilePreviewerDataWithID;
94
+ export {};
@@ -0,0 +1,3 @@
1
+ export type { IFilePreviewerData, IFilePreviewerOption, } from './i-file-previewer-option';
2
+ export type { IFilePreviewShellState, IFilePreviewShellController, } from './i-file-preview-shell-controller';
3
+ export type { IInitializeParam, IFilePreviewItemState, IFilePreviewImageState, IFilePreviewImageGroupState, IFilePreviewItemController, IFilePreviewItemConstructor, } from './i-file-preview-item-controller';
@@ -0,0 +1 @@
1
+ export { fileNameToFileType, throttle } from './util';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 文件名转为文件类型
3
+ * @param fileName
4
+ * @returns
5
+ */
6
+ export declare const fileNameToFileType: (fileName: string) => string;
7
+ /**
8
+ * 节流函数
9
+ * @param func
10
+ * @param wait
11
+ * @returns
12
+ */
13
+ export declare const throttle: <T extends (...args: any[]) => any>(func: T, wait: number) => ((...args: Parameters<T>) => void);
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@ibiz-template-plugin/ibiz-file-previewer",
3
+ "version": "0.0.0",
4
+ "description": "iBiz文件预览器",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.es.js",
7
+ "browser": "./dist/index.umd.js",
8
+ "types": "./dist/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.es.js",
12
+ "require": "./dist/index.cjs",
13
+ "browser": "./dist/index.umd.js",
14
+ "types": "./dist/types/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "dev": "vite build --watch",
22
+ "build": "vite build && tsc --emitDeclarationOnly",
23
+ "publish:npm": "npm run build && npm publish --access public --registry=https://registry.npmjs.org/"
24
+ },
25
+ "keywords": [],
26
+ "author": "iBizLab",
27
+ "license": "MIT",
28
+ "devDependencies": {
29
+ "@types/turndown": "^5.0.6",
30
+ "@vitejs/plugin-vue": "^4.5.2",
31
+ "@vitejs/plugin-vue-jsx": "^3.1.0",
32
+ "sass": "^1.69.5",
33
+ "terser": "^5.44.1",
34
+ "typescript": "^5.3.3",
35
+ "vite": "^5.0.11"
36
+ },
37
+ "dependencies": {
38
+ "highlight.js": "11.11.1",
39
+ "turndown": "7.2.2",
40
+ "vditor": "3.11.2",
41
+ "vue": "^3.3.8"
42
+ }
43
+ }