@spacecorexdev/core 0.0.4 → 0.0.5
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/package.json +2 -36
- package/src/api/_base.ts +243 -0
- package/src/api/index.ts +17 -0
- package/src/api/project.ts +1345 -0
- package/src/api/user.ts +1174 -0
- package/src/contract.ts +50 -0
- package/src/hooks/index.ts +2 -0
- package/{dist/hooks/index.js → src/hooks/useLongPress.ts} +53 -49
- package/src/hooks/useOnlineStatus.ts +22 -0
- package/src/index.ts +14 -0
- package/src/types/id.ts +2 -0
- package/src/types/index.ts +5 -0
- package/src/types/project/base.ts +63 -0
- package/src/types/project/contract.ts +79 -0
- package/src/types/project/contractStatus.tsx +15 -0
- package/src/types/project/index.ts +5 -0
- package/src/types/project/member.ts +46 -0
- package/src/types/project/progress.ts +43 -0
- package/src/types/projectRole.ts +17 -0
- package/src/types/theme.ts +1 -0
- package/src/types/user/index.ts +1 -0
- package/src/types/user/role.ts +7 -0
- package/src/ui/CommentTimeline/index.tsx +330 -0
- package/src/ui/FileManager/FileContextMenu.tsx +628 -0
- package/src/ui/FileManager/FileGridView.tsx +529 -0
- package/src/ui/FileManager/FileTableView.tsx +405 -0
- package/src/ui/FileManager/FileToolbar.tsx +119 -0
- package/src/ui/FileManager/FileVersionHistoryModal.tsx +175 -0
- package/src/ui/FileManager/MoveCopyToProjectModal.tsx +119 -0
- package/src/ui/FileManager/ShareToWechatModal.tsx +419 -0
- package/src/ui/FileManager/hooks/useFileManagerActions.ts +2532 -0
- package/src/ui/FileManager/hooks/useFileManagerState.ts +419 -0
- package/src/ui/FileManager/index.tsx +580 -0
- package/src/ui/FileManager/projectFileManagerApi.ts +57 -0
- package/src/ui/FileManager/types.ts +184 -0
- package/src/ui/FileManager/utils/fileDeltaWorker.ts +193 -0
- package/src/ui/FileManager/utils/fileTree.ts +178 -0
- package/src/ui/FileManager/utils/fileUpload.ts +714 -0
- package/src/ui/FileManager/utils/fileUtils.ts +65 -0
- package/src/ui/InvoiceRecordsList/index.tsx +813 -0
- package/src/ui/MyFileSelectorModal.tsx +261 -0
- package/src/ui/ProjectSelector/index.tsx +472 -0
- package/src/ui/ProjectSelector/projectCache.ts +40 -0
- package/src/ui/RoleSelector/index.tsx +473 -0
- package/src/ui/RoleSelector/roleCache.ts +40 -0
- package/src/ui/UIAlert.tsx +399 -0
- package/src/ui/UIAlertExample.tsx +129 -0
- package/src/ui/UIConfirm.tsx +335 -0
- package/src/ui/UIConfirmExample.tsx +165 -0
- package/src/ui/UIDatePicker.tsx +146 -0
- package/src/ui/UIDateRangePicker.tsx +38 -0
- package/src/ui/UIFilePreview/ExcelEditor/index.tsx +617 -0
- package/src/ui/UIFilePreview/ExcelEditor/types.ts +24 -0
- package/src/ui/UIFilePreview/ExportDropdown.css +85 -0
- package/src/ui/UIFilePreview/ExportDropdown.tsx +109 -0
- package/src/ui/UIFilePreview/IndexedDBUtils.ts +564 -0
- package/src/ui/UIFilePreview/MarkdownEditor/exportMarkdownPdf.ts +576 -0
- package/src/ui/UIFilePreview/MarkdownEditor/index.tsx +677 -0
- package/src/ui/UIFilePreview/MarkdownEditor/markdownEditor.css +1005 -0
- package/src/ui/UIFilePreview/MarkdownEditor/types.ts +15 -0
- package/src/ui/UIFilePreview/PPTXEditor/index.tsx +602 -0
- package/src/ui/UIFilePreview/RichDocEditor/exportRDocMarkdown.ts +77 -0
- package/src/ui/UIFilePreview/RichDocEditor/exportRDocPdf.ts +374 -0
- package/src/ui/UIFilePreview/RichDocEditor/index.tsx +730 -0
- package/src/ui/UIFilePreview/RichDocEditor/richdoc-editor.css +59 -0
- package/src/ui/UIFilePreview/UIFilePreview.tsx +611 -0
- package/src/ui/UIFilePreview/WordEditor/index.tsx +3933 -0
- package/src/ui/UIFilePreview/WordEditor/style.ts +1213 -0
- package/src/ui/UIFilePreview/WordEditor/word-editor.css +999 -0
- package/src/ui/UIFilePreview/filePreview.css +193 -0
- package/src/ui/UIFilePreview/filetypes/archive.tsx +66 -0
- package/src/ui/UIFilePreview/filetypes/cad.tsx +287 -0
- package/src/ui/UIFilePreview/filetypes/excel.tsx +355 -0
- package/src/ui/UIFilePreview/filetypes/image.tsx +20 -0
- package/src/ui/UIFilePreview/filetypes/imageLoader.ts +63 -0
- package/src/ui/UIFilePreview/filetypes/pdf.tsx +156 -0
- package/src/ui/UIFilePreview/filetypes/ppt.tsx +535 -0
- package/src/ui/UIFilePreview/filetypes/pptExportPdf.ts +523 -0
- package/src/ui/UIFilePreview/filetypes/video.tsx +482 -0
- package/src/ui/UIFilePreview/filetypes/word.tsx +245 -0
- package/src/ui/UIFilePreview/filetypes/wordExportMarkdown.ts +86 -0
- package/src/ui/UIFilePreview/filetypes/wordExportPdf.tsx +427 -0
- package/src/ui/UIFilePreview/index.ts +35 -0
- package/src/ui/UIFilePreview/pdfPagination.ts +143 -0
- package/src/ui/UIFilePreview/previewUtils.tsx +531 -0
- package/src/ui/UIFileUpload.tsx +382 -0
- package/src/ui/UIImageUpload.tsx +195 -0
- package/src/ui/UILoading.tsx +255 -0
- package/src/ui/UILoadingExample.tsx +139 -0
- package/src/ui/UISelect.tsx +105 -0
- package/src/ui/UIToast.tsx +381 -0
- package/src/ui/UIToastExample.tsx +69 -0
- package/src/ui/UIToastSingle.tsx +279 -0
- package/src/ui/UIViewToggle.tsx +64 -0
- package/src/ui/UserSelector/index.tsx +583 -0
- package/src/ui/index.ts +84 -0
- package/src/ui/upload/image.ts +135 -0
- package/src/ui/upload/index.ts +73 -0
- package/src/ui/upload/submitFile.ts +106 -0
- package/src/ui/upload/submitForm.ts +124 -0
- package/src/ui/upload/upload.err.ts +15 -0
- package/src/ui/upload/upload.ts +250 -0
- package/src/utils/CacheDepartmentInfo.ts +372 -0
- package/src/utils/CacheFileContent.ts +315 -0
- package/src/utils/CachePermissionInfo.ts +235 -0
- package/src/utils/CacheRoleInfo.ts +303 -0
- package/src/utils/CacheUserInfo.ts +818 -0
- package/src/utils/CacheViewToggleInfo.ts +182 -0
- package/src/utils/MessageContentUtils.ts +268 -0
- package/src/utils/clipboard.ts +70 -0
- package/src/utils/companyEmail.ts +19 -0
- package/src/utils/forbidDebugger.ts +59 -0
- package/src/utils/formatters.ts +94 -0
- package/src/utils/htmlUtils.tsx +59 -0
- package/src/utils/index.ts +18 -0
- package/src/utils/keyboard.ts +114 -0
- package/src/utils/mammothApi.ts +16 -0
- package/src/utils/polyfills.ts +928 -0
- package/src/utils/regex.ts +14 -0
- package/src/utils/storage.ts +95 -0
- package/src/utils/workerBootstrap.ts +87 -0
- package/dist/api/index.js +0 -1553
- package/dist/contract.js +0 -5
- package/dist/index.js +0 -4492
- package/dist/types/index.js +0 -49
- package/dist/ui/index.css +0 -1876
- package/dist/ui/index.js +0 -22245
- package/dist/utils/index.js +0 -4296
- /package/{dist → src}/styles/ant-modal.css +0 -0
- /package/{dist → src}/styles/ant-spin.css +0 -0
- /package/{dist → src}/styles/ant-table.css +0 -0
- /package/{dist → src}/styles/index.css +0 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
.pptx-preview-wrapper .pptx-preview-slide-wrapper {
|
|
2
|
+
border-bottom: 1px solid rgb(var(--color-border));
|
|
3
|
+
margin: 0 !important;
|
|
4
|
+
/* padding-top: 10px !important;
|
|
5
|
+
padding-bottom: 10px !important; */
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.pptx-preview-wrapper .pptx-preview-slide-wrapper .slide-master-wrapper,
|
|
9
|
+
.pptx-preview-wrapper .pptx-preview-slide-wrapper .slide-layout-wrapper,
|
|
10
|
+
.pptx-preview-wrapper .pptx-preview-slide-wrapper .slide-wrapper {
|
|
11
|
+
right: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.pptx-preview-wrapper .pptx-preview-slide-wrapper table {
|
|
15
|
+
width: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.ant-modal-root .ant-modal-wrap .ant-modal.ant-modal-fullscreen.ant-modal-ppt .ant-modal-content {
|
|
19
|
+
min-height: 100vh !important;
|
|
20
|
+
margin-bottom: 0 !important;
|
|
21
|
+
padding-top: 0 !important;
|
|
22
|
+
padding-left: 0 !important;
|
|
23
|
+
padding-right: 0 !important;
|
|
24
|
+
padding-bottom: 0 !important;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.ant-modal-root .ant-modal-wrap .ant-modal.ant-modal-fullscreen.ant-modal-ppt .ant-modal-content .ant-modal-body {
|
|
28
|
+
min-height: 100vh !important;
|
|
29
|
+
background: rgb(var(--color-black));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.ant-modal-root .ant-modal-wrap .ant-modal.ant-modal-fullscreen.ant-modal-ppt .ant-modal-content .ant-modal-body>div {
|
|
33
|
+
background: rgb(var(--color-black)) !important;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.ant-modal-root .ant-modal-wrap .ant-modal.ant-modal-fullscreen.ant-modal-ppt .ant-modal-content .ant-modal-close {
|
|
37
|
+
color: rgb(var(--color-gray-300));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.ant-modal-root .ant-modal-wrap .ant-modal.ant-modal-fullscreen.ant-modal-ppt .ant-modal-content .ant-modal-close:hover {
|
|
41
|
+
color: rgb(var(--color-white));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.ant-modal-root .ant-modal-wrap .ant-modal.ant-modal-fullscreen .ant-modal-content .ant-modal-close {
|
|
45
|
+
position: fixed;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.docx-preview {
|
|
49
|
+
justify-self: center;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.ui-file-preview-archive {
|
|
53
|
+
width: 100%;
|
|
54
|
+
height: 100dvh;
|
|
55
|
+
min-height: 0;
|
|
56
|
+
background: rgb(var(--color-surface));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.ui-file-preview-pdf {
|
|
60
|
+
width: 100%;
|
|
61
|
+
height: 100dvh;
|
|
62
|
+
min-height: 0;
|
|
63
|
+
background: rgb(var(--color-surface));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/* ==========================================================================
|
|
68
|
+
PDF 预览文本选择修复
|
|
69
|
+
PDF.js 默认禁用了文本选择高亮,且 .enablePermissions 模式下完全禁用,
|
|
70
|
+
这里用最高优先级的覆盖确保文本可以被选择并看到选中高亮。
|
|
71
|
+
========================================================================== */
|
|
72
|
+
|
|
73
|
+
/* 1) 文本层提升到画布之上,确保鼠标事件落在文本层而非 canvas 上 */
|
|
74
|
+
.ui-file-preview-pdf .pdfViewer .page .textLayer {
|
|
75
|
+
z-index: 2 !important;
|
|
76
|
+
pointer-events: auto !important;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* 2) 强制文本层内的所有 span 均可选择,覆盖权限禁用规则 */
|
|
80
|
+
.ui-file-preview-pdf .pdfViewer .textLayer span,
|
|
81
|
+
.ui-file-preview-pdf .pdfViewer .textLayer br,
|
|
82
|
+
.ui-file-preview-pdf .pdfViewer.enablePermissions .textLayer span {
|
|
83
|
+
-webkit-user-select: text !important;
|
|
84
|
+
-moz-user-select: text !important;
|
|
85
|
+
user-select: text !important;
|
|
86
|
+
cursor: text !important;
|
|
87
|
+
pointer-events: auto !important;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* 3) 恢复选择高亮的默认颜色,否则 ::selection 背景透明看不到选中内容 */
|
|
91
|
+
.ui-file-preview-pdf .pdfViewer .textLayer ::selection,
|
|
92
|
+
.ui-file-preview-pdf .pdfViewer .textLayer span::selection,
|
|
93
|
+
.ui-file-preview-pdf .pdfViewer .textLayer br::selection {
|
|
94
|
+
background: AccentColor !important;
|
|
95
|
+
background: highlight !important;
|
|
96
|
+
}
|
|
97
|
+
.ui-file-preview-pdf .pdfViewer .textLayer ::-moz-selection,
|
|
98
|
+
.ui-file-preview-pdf .pdfViewer .textLayer span::-moz-selection,
|
|
99
|
+
.ui-file-preview-pdf .pdfViewer .textLayer br::-moz-selection {
|
|
100
|
+
background: highlight !important;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* 4) 文本层本身也要允许选择,防止父级 user-select 级联覆盖 */
|
|
104
|
+
.ui-file-preview-pdf .pdfViewer,
|
|
105
|
+
.ui-file-preview-pdf .pdfViewer .page,
|
|
106
|
+
.ui-file-preview-pdf .pdfViewer .textLayer {
|
|
107
|
+
-webkit-user-select: text !important;
|
|
108
|
+
-moz-user-select: text !important;
|
|
109
|
+
user-select: text !important;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
.ui-file-preview-word {
|
|
114
|
+
width: 100%;
|
|
115
|
+
height: 100vh;
|
|
116
|
+
min-height: 0;
|
|
117
|
+
background: rgb(var(--color-surface));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.ui-file-preview-excel {
|
|
121
|
+
width: 100%;
|
|
122
|
+
height: 100vh;
|
|
123
|
+
min-height: 0;
|
|
124
|
+
background: #ffffff;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.ui-file-preview-excel .e-virt-table-canvas {
|
|
128
|
+
background: #ffffff;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.ui-file-preview-cad .cad-toolbar {
|
|
132
|
+
padding-right: 50px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.ui-file-preview-ebook {
|
|
136
|
+
width: 100%;
|
|
137
|
+
height: 100dvh;
|
|
138
|
+
min-height: 0;
|
|
139
|
+
/* 纸张色背景:暖白偏黄,模拟实体书纸张观感 */
|
|
140
|
+
background: #f5ecd9;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@media (min-width: 720px) {
|
|
144
|
+
.ui-file-preview-ebook .epub-actions {
|
|
145
|
+
margin-right: 35px;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.ui-file-preview-ebook .file-viewer,
|
|
150
|
+
.ui-file-preview-ebook .file-viewer * {
|
|
151
|
+
max-width: none;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.ui-file-preview-ebook .epub-viewer {
|
|
155
|
+
width: 100% !important;
|
|
156
|
+
height: 100% !important;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.ui-file-preview-ebook .epub-container {
|
|
160
|
+
max-width: 100% !important;
|
|
161
|
+
width: 100% !important;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.ui-file-preview-ebook .epub-stage-wrap {
|
|
165
|
+
padding-left: 0;
|
|
166
|
+
padding-right: 0;
|
|
167
|
+
padding-bottom: 0;
|
|
168
|
+
padding-top: 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* ==========================================================================
|
|
172
|
+
电子书阅读区样式
|
|
173
|
+
epubjs 使用 flow:scrolled + manager:continuous 模式,自行管理 iframe
|
|
174
|
+
高度与内部滚动。不要覆盖 iframe/epub-container 的 height,否则会破坏
|
|
175
|
+
epubjs 的翻页(next/prev)与视图计算。
|
|
176
|
+
========================================================================== */
|
|
177
|
+
.ui-file-preview-ebook .epub-toolbar,
|
|
178
|
+
.ui-file-preview-ebook .epub-icon-button,
|
|
179
|
+
.ui-file-preview-ebook .epub-button {
|
|
180
|
+
background: #f5ecd9 !important;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.ui-file-preview-ebook .epub-toc {
|
|
184
|
+
background: #f2deb4 !important;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.ui-file-preview-ebook .epub-stage {
|
|
188
|
+
/* 内容区用纸张色,与外层背景一致 */
|
|
189
|
+
background: #f5ecd9 !important;
|
|
190
|
+
box-shadow: none !important;
|
|
191
|
+
/* 允许触摸惯性滚动(移动端) */
|
|
192
|
+
touch-action: pan-y;
|
|
193
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { FileViewer } from '@file-viewer/react';
|
|
3
|
+
import { archiveRenderer } from '@file-viewer/renderer-archive';
|
|
4
|
+
import { pdfRenderer } from '@file-viewer/renderer-pdf';
|
|
5
|
+
import { wordRenderer } from '@file-viewer/renderer-word';
|
|
6
|
+
import { spreadsheetRenderer } from '@file-viewer/renderer-spreadsheet';
|
|
7
|
+
import { textRenderer } from '@file-viewer/renderer-text';
|
|
8
|
+
import { withPolyfillWorkerBootstrap } from '../../../utils/workerBootstrap';
|
|
9
|
+
|
|
10
|
+
interface ArchivePreviewProps {
|
|
11
|
+
file: File | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ArchivePreview: React.FC<ArchivePreviewProps> = ({ file }) => {
|
|
15
|
+
const renderers = [
|
|
16
|
+
archiveRenderer,
|
|
17
|
+
spreadsheetRenderer,
|
|
18
|
+
wordRenderer,
|
|
19
|
+
pdfRenderer,
|
|
20
|
+
textRenderer,
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const options = useMemo(() => ({
|
|
24
|
+
locale: 'zh-CN',
|
|
25
|
+
rendererMode: 'extend' as const,
|
|
26
|
+
renderers: renderers as any,
|
|
27
|
+
theme: 'light' as const,
|
|
28
|
+
toolbar: {
|
|
29
|
+
position: 'bottom-right' as const,
|
|
30
|
+
download: false,
|
|
31
|
+
print: false,
|
|
32
|
+
exportHtml: false,
|
|
33
|
+
},
|
|
34
|
+
archive: {
|
|
35
|
+
workerUrl: withPolyfillWorkerBootstrap('/vendor/libarchive/worker-bundle.js'),
|
|
36
|
+
cache: true,
|
|
37
|
+
workerTimeoutMs: 30000,
|
|
38
|
+
maxArchiveSize: 320 * 1024 * 1024,
|
|
39
|
+
maxEntryPreviewSize: 64 * 1024 * 1024,
|
|
40
|
+
},
|
|
41
|
+
spreadsheet: {
|
|
42
|
+
worker: false,
|
|
43
|
+
},
|
|
44
|
+
}), []);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div className="ui-file-preview-archive" style={{ position: 'relative', minHeight: '100vh' }}>
|
|
48
|
+
<style>
|
|
49
|
+
{`.ui-file-preview-archive .archive-head .archive-sidebar-toggle {
|
|
50
|
+
display: none !important;
|
|
51
|
+
}
|
|
52
|
+
.ui-file-preview-archive .fv-root,
|
|
53
|
+
.ui-file-preview-archive .fv-container {
|
|
54
|
+
padding-right: 50px !important;
|
|
55
|
+
}`}
|
|
56
|
+
</style>
|
|
57
|
+
{file ? (
|
|
58
|
+
<FileViewer
|
|
59
|
+
file={file}
|
|
60
|
+
name={file.name}
|
|
61
|
+
options={options}
|
|
62
|
+
/>
|
|
63
|
+
) : null}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState, useRef } from 'react';
|
|
2
|
+
import { FileViewer, type FileViewerHandle } from '@file-viewer/react';
|
|
3
|
+
import type { FileViewerZoomState } from '@file-viewer/core';
|
|
4
|
+
import { engineeringRenderers } from '@file-viewer/preset-engineering';
|
|
5
|
+
import { withPolyfillModuleWorkerBootstrap } from '../../../utils/workerBootstrap';
|
|
6
|
+
|
|
7
|
+
export interface CadPreviewProps {
|
|
8
|
+
file: File | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const CadPreview: React.FC<CadPreviewProps> = ({ file }) => {
|
|
12
|
+
const [buffer, setBuffer] = useState<ArrayBuffer | null>(null);
|
|
13
|
+
const [cssScale, setCssScale] = useState(1);
|
|
14
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
15
|
+
const viewerRef = useRef<FileViewerHandle | null>(null);
|
|
16
|
+
const initialDistanceRef = useRef(0);
|
|
17
|
+
const baseZoomRef = useRef(1);
|
|
18
|
+
const rafIdRef = useRef<number | null>(null);
|
|
19
|
+
const pendingScaleRef = useRef(1);
|
|
20
|
+
const isPinchingRef = useRef(false);
|
|
21
|
+
const lastTouchCountRef = useRef(0);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (file) {
|
|
25
|
+
const reader = new FileReader();
|
|
26
|
+
reader.onload = (e) => {
|
|
27
|
+
setBuffer(e.target?.result as ArrayBuffer);
|
|
28
|
+
};
|
|
29
|
+
reader.readAsArrayBuffer(file);
|
|
30
|
+
} else {
|
|
31
|
+
setBuffer(null);
|
|
32
|
+
}
|
|
33
|
+
}, [file]);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
// 保存原始 viewport 设置
|
|
37
|
+
const viewportMeta = document.querySelector('meta[name="viewport"]');
|
|
38
|
+
const originalContent = viewportMeta?.getAttribute('content') || '';
|
|
39
|
+
|
|
40
|
+
// 禁用页面缩放
|
|
41
|
+
if (viewportMeta) {
|
|
42
|
+
viewportMeta.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 全局阻止双指缩放到整个页面
|
|
46
|
+
const handleGlobalTouchStart = (e: TouchEvent) => {
|
|
47
|
+
if (e.touches.length === 2) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const handleGlobalGestureStart = (e: Event) => {
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleGlobalGestureChange = (e: Event) => {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
document.addEventListener('touchstart', handleGlobalTouchStart, { passive: false, capture: true });
|
|
61
|
+
document.addEventListener('gesturestart', handleGlobalGestureStart);
|
|
62
|
+
document.addEventListener('gesturechange', handleGlobalGestureChange);
|
|
63
|
+
|
|
64
|
+
return () => {
|
|
65
|
+
// 恢复原始 viewport 设置
|
|
66
|
+
if (viewportMeta) {
|
|
67
|
+
viewportMeta.setAttribute('content', originalContent);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
document.removeEventListener('touchstart', handleGlobalTouchStart, { capture: true });
|
|
71
|
+
document.removeEventListener('gesturestart', handleGlobalGestureStart);
|
|
72
|
+
document.removeEventListener('gesturechange', handleGlobalGestureChange);
|
|
73
|
+
};
|
|
74
|
+
}, []);
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const container = containerRef.current;
|
|
78
|
+
if (!container) return;
|
|
79
|
+
|
|
80
|
+
const restoreTouchAction = () => {
|
|
81
|
+
container.style.touchAction = 'pan-x pan-y';
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const syncZoomToCad = () => {
|
|
85
|
+
const finalScale = pendingScaleRef.current;
|
|
86
|
+
const baseScale = baseZoomRef.current;
|
|
87
|
+
const ratio = finalScale / baseScale;
|
|
88
|
+
|
|
89
|
+
if (Math.abs(ratio - 1) < 0.05) return;
|
|
90
|
+
|
|
91
|
+
const steps = Math.round(Math.log(ratio) / Math.log(1.15));
|
|
92
|
+
const absSteps = Math.min(Math.abs(steps), 10);
|
|
93
|
+
|
|
94
|
+
if (steps > 0) {
|
|
95
|
+
for (let i = 0; i < absSteps; i++) {
|
|
96
|
+
viewerRef.current?.zoomIn?.();
|
|
97
|
+
}
|
|
98
|
+
} else if (steps < 0) {
|
|
99
|
+
for (let i = 0; i < absSteps; i++) {
|
|
100
|
+
viewerRef.current?.zoomOut?.();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const handleTouchStart = (e: TouchEvent) => {
|
|
106
|
+
const touchCount = e.touches.length;
|
|
107
|
+
|
|
108
|
+
if (touchCount === 2 && !isPinchingRef.current) {
|
|
109
|
+
const dx = e.touches[0].clientX - e.touches[1].clientX;
|
|
110
|
+
const dy = e.touches[0].clientY - e.touches[1].clientY;
|
|
111
|
+
initialDistanceRef.current = Math.sqrt(dx * dx + dy * dy);
|
|
112
|
+
|
|
113
|
+
const zoomState = viewerRef.current?.getZoomState?.();
|
|
114
|
+
baseZoomRef.current = zoomState?.scale || 1;
|
|
115
|
+
pendingScaleRef.current = baseZoomRef.current;
|
|
116
|
+
setCssScale(1);
|
|
117
|
+
isPinchingRef.current = true;
|
|
118
|
+
|
|
119
|
+
container.style.touchAction = 'none';
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
e.stopPropagation();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
lastTouchCountRef.current = touchCount;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const handleTouchMove = (e: TouchEvent) => {
|
|
128
|
+
const touchCount = e.touches.length;
|
|
129
|
+
|
|
130
|
+
if (touchCount === 2 && isPinchingRef.current) {
|
|
131
|
+
const dx = e.touches[0].clientX - e.touches[1].clientX;
|
|
132
|
+
const dy = e.touches[0].clientY - e.touches[1].clientY;
|
|
133
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
134
|
+
|
|
135
|
+
if (initialDistanceRef.current > 0) {
|
|
136
|
+
const targetScale = baseZoomRef.current * (distance / initialDistanceRef.current);
|
|
137
|
+
pendingScaleRef.current = targetScale;
|
|
138
|
+
|
|
139
|
+
if (rafIdRef.current === null) {
|
|
140
|
+
rafIdRef.current = requestAnimationFrame(() => {
|
|
141
|
+
rafIdRef.current = null;
|
|
142
|
+
setCssScale(pendingScaleRef.current / baseZoomRef.current);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
e.stopPropagation();
|
|
149
|
+
} else if (touchCount < 2 && isPinchingRef.current) {
|
|
150
|
+
isPinchingRef.current = false;
|
|
151
|
+
syncZoomToCad();
|
|
152
|
+
|
|
153
|
+
if (rafIdRef.current !== null) {
|
|
154
|
+
cancelAnimationFrame(rafIdRef.current);
|
|
155
|
+
rafIdRef.current = null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setTimeout(() => {
|
|
159
|
+
setCssScale(1);
|
|
160
|
+
restoreTouchAction();
|
|
161
|
+
}, 100);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
lastTouchCountRef.current = touchCount;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const handleTouchEnd = (e: TouchEvent) => {
|
|
168
|
+
const touchCount = e.touches.length;
|
|
169
|
+
|
|
170
|
+
if (isPinchingRef.current && touchCount < 2) {
|
|
171
|
+
isPinchingRef.current = false;
|
|
172
|
+
syncZoomToCad();
|
|
173
|
+
|
|
174
|
+
if (rafIdRef.current !== null) {
|
|
175
|
+
cancelAnimationFrame(rafIdRef.current);
|
|
176
|
+
rafIdRef.current = null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
setTimeout(() => {
|
|
180
|
+
setCssScale(1);
|
|
181
|
+
restoreTouchAction();
|
|
182
|
+
}, 100);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (touchCount === 0) {
|
|
186
|
+
initialDistanceRef.current = 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
lastTouchCountRef.current = touchCount;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const handleTouchCancel = () => {
|
|
193
|
+
isPinchingRef.current = false;
|
|
194
|
+
initialDistanceRef.current = 0;
|
|
195
|
+
if (rafIdRef.current !== null) {
|
|
196
|
+
cancelAnimationFrame(rafIdRef.current);
|
|
197
|
+
rafIdRef.current = null;
|
|
198
|
+
}
|
|
199
|
+
setCssScale(1);
|
|
200
|
+
restoreTouchAction();
|
|
201
|
+
lastTouchCountRef.current = 0;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
container.addEventListener('touchstart', handleTouchStart, { passive: false, capture: true });
|
|
205
|
+
container.addEventListener('touchmove', handleTouchMove, { passive: false, capture: true });
|
|
206
|
+
container.addEventListener('touchend', handleTouchEnd, { passive: false, capture: true });
|
|
207
|
+
container.addEventListener('touchcancel', handleTouchCancel, { passive: false, capture: true });
|
|
208
|
+
|
|
209
|
+
return () => {
|
|
210
|
+
container.removeEventListener('touchstart', handleTouchStart, { capture: true });
|
|
211
|
+
container.removeEventListener('touchmove', handleTouchMove, { capture: true });
|
|
212
|
+
container.removeEventListener('touchend', handleTouchEnd, { capture: true });
|
|
213
|
+
container.removeEventListener('touchcancel', handleTouchCancel, { capture: true });
|
|
214
|
+
|
|
215
|
+
if (rafIdRef.current !== null) {
|
|
216
|
+
cancelAnimationFrame(rafIdRef.current);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}, [buffer]);
|
|
220
|
+
|
|
221
|
+
const options = useMemo(() => ({
|
|
222
|
+
locale: 'zh-CN',
|
|
223
|
+
rendererMode: 'replace' as const,
|
|
224
|
+
renderers: engineeringRenderers,
|
|
225
|
+
theme: 'dark' as const,
|
|
226
|
+
toolbar: {
|
|
227
|
+
position: 'bottom-right' as const,
|
|
228
|
+
download: false,
|
|
229
|
+
print: false,
|
|
230
|
+
exportHtml: false,
|
|
231
|
+
},
|
|
232
|
+
cad: {
|
|
233
|
+
// @flyfish-dev/cad-viewer 固定以 { type: 'module' } 启动 worker,必须用 module 版引导(ESM import 注入 polyfills)
|
|
234
|
+
workerUrl: withPolyfillModuleWorkerBootstrap('/wasm/cad/dwg-worker.js'),
|
|
235
|
+
wasmPath: '/wasm/cad/',
|
|
236
|
+
dwfWasmUrl: '/wasm/cad/dwfv-render.wasm',
|
|
237
|
+
// 黑色画布(类 AutoCAD 模型空间);foreground 配合 adaptive 对比度保证图元/文字在黑底上可读
|
|
238
|
+
canvasOptions: {
|
|
239
|
+
background: '#000000',
|
|
240
|
+
foreground: '#ffffff',
|
|
241
|
+
},
|
|
242
|
+
dwfBackground: '#000000',
|
|
243
|
+
},
|
|
244
|
+
}), []);
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<div
|
|
248
|
+
ref={containerRef}
|
|
249
|
+
className="ui-file-preview-cad"
|
|
250
|
+
style={{
|
|
251
|
+
width: '100%',
|
|
252
|
+
height: '100vh',
|
|
253
|
+
minHeight: '600px',
|
|
254
|
+
touchAction: 'pan-x pan-y',
|
|
255
|
+
overflow: 'hidden',
|
|
256
|
+
userSelect: 'none',
|
|
257
|
+
WebkitUserSelect: 'none'
|
|
258
|
+
}}
|
|
259
|
+
>
|
|
260
|
+
{buffer && file ? (
|
|
261
|
+
<div
|
|
262
|
+
style={{
|
|
263
|
+
width: '100%',
|
|
264
|
+
height: '100%',
|
|
265
|
+
transform: `scale(${cssScale})`,
|
|
266
|
+
transformOrigin: 'center center',
|
|
267
|
+
transition: cssScale === 1 ? 'transform 0.1s ease-out' : 'none',
|
|
268
|
+
willChange: 'transform'
|
|
269
|
+
}}
|
|
270
|
+
>
|
|
271
|
+
<FileViewer
|
|
272
|
+
ref={(handleRef) => {
|
|
273
|
+
viewerRef.current = handleRef;
|
|
274
|
+
}}
|
|
275
|
+
buffer={buffer}
|
|
276
|
+
filename={file.name}
|
|
277
|
+
name={file.name}
|
|
278
|
+
type="dwg"
|
|
279
|
+
size={file.size}
|
|
280
|
+
options={options}
|
|
281
|
+
style={{ width: '100%', height: '100%' }}
|
|
282
|
+
/>
|
|
283
|
+
</div>
|
|
284
|
+
) : null}
|
|
285
|
+
</div>
|
|
286
|
+
);
|
|
287
|
+
};
|