@file-viewer/renderer-cad 2.1.1 → 2.1.3
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/cad.js +21 -18
- package/package.json +2 -2
package/dist/cad.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CadViewer, } from '@flyfish-dev/cad-viewer';
|
|
2
2
|
import { resolveFileViewerCadAssetUrls } from '@file-viewer/core/assets';
|
|
3
|
-
import { createFileViewerZoomChangeEmitter, registerFileViewerZoomProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
3
|
+
import { createFileViewerTranslator, resolveFileViewerLocale, createFileViewerZoomChangeEmitter, registerFileViewerZoomProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
4
4
|
const CAD_WORKER_TIMEOUT = 120000;
|
|
5
5
|
const cadStyle = `
|
|
6
6
|
.cad-shell{display:flex;height:100%;min-height:100%;flex-direction:column;background:#f5f7fb;color:#142335}
|
|
@@ -107,11 +107,11 @@ const collectLayers = (result) => {
|
|
|
107
107
|
.map(([name, layer]) => ({ ...layer, name }))
|
|
108
108
|
.sort((left, right) => left.name.localeCompare(right.name));
|
|
109
109
|
};
|
|
110
|
-
const formatNumber = (value) => {
|
|
110
|
+
const formatNumber = (value, locale = 'zh-CN') => {
|
|
111
111
|
if (!Number.isFinite(value)) {
|
|
112
112
|
return '0';
|
|
113
113
|
}
|
|
114
|
-
return new Intl.NumberFormat(
|
|
114
|
+
return new Intl.NumberFormat(locale).format(Math.round(value || 0));
|
|
115
115
|
};
|
|
116
116
|
const getCadDocumentBaseUrl = (target) => {
|
|
117
117
|
var _a;
|
|
@@ -121,8 +121,10 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
121
121
|
var _a;
|
|
122
122
|
const normalizedType = normalizeType(type);
|
|
123
123
|
const options = ((_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.cad) || {};
|
|
124
|
+
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
125
|
+
const locale = resolveFileViewerLocale(context === null || context === void 0 ? void 0 : context.options);
|
|
124
126
|
let status = 'loading';
|
|
125
|
-
let progressMessage = '
|
|
127
|
+
let progressMessage = t('cad.state.loadingViewer');
|
|
126
128
|
let errorMessage = '';
|
|
127
129
|
let loadResult = null;
|
|
128
130
|
let renderStats = null;
|
|
@@ -137,7 +139,7 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
137
139
|
shell.dataset.viewerZoomProvider = 'cad';
|
|
138
140
|
const toolbar = createElement('div', 'cad-toolbar');
|
|
139
141
|
const tools = createElement('div', 'cad-tools');
|
|
140
|
-
const fitButton = createElement('button', undefined, '
|
|
142
|
+
const fitButton = createElement('button', undefined, t('cad.toolbar.fit'));
|
|
141
143
|
const zoomOutButton = createElement('button', undefined, '-');
|
|
142
144
|
const zoomText = createElement('span', 'cad-zoom', '100%');
|
|
143
145
|
const zoomInButton = createElement('button', undefined, '+');
|
|
@@ -147,8 +149,9 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
147
149
|
[fitButton, zoomOutButton, zoomInButton].forEach(button => {
|
|
148
150
|
button.type = 'button';
|
|
149
151
|
});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
fitButton.title = t('cad.toolbar.fit');
|
|
153
|
+
zoomOutButton.title = t('cad.toolbar.zoomOut');
|
|
154
|
+
zoomInButton.title = t('cad.toolbar.zoomIn');
|
|
152
155
|
tools.append(fitButton, zoomOutButton, zoomText, zoomInButton);
|
|
153
156
|
meta.append(typeMeta, backendMeta);
|
|
154
157
|
toolbar.append(tools, meta);
|
|
@@ -156,8 +159,8 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
156
159
|
const layersPanel = createElement('aside', 'cad-layers');
|
|
157
160
|
layersPanel.hidden = true;
|
|
158
161
|
const layersHead = createElement('div', 'cad-layers-head');
|
|
159
|
-
const layersCount = createElement('span', undefined, '0
|
|
160
|
-
layersHead.append(createElement('strong', undefined, '
|
|
162
|
+
const layersCount = createElement('span', undefined, t('cad.layers.count', { count: 0 }));
|
|
163
|
+
layersHead.append(createElement('strong', undefined, t('cad.layers.title')), layersCount);
|
|
161
164
|
const layersList = createElement('div', 'cad-layers-list');
|
|
162
165
|
layersPanel.append(layersHead, layersList);
|
|
163
166
|
const canvasWrap = createElement('div', 'cad-canvas-wrap');
|
|
@@ -167,7 +170,7 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
167
170
|
const state = createElement('div', 'cad-state', progressMessage);
|
|
168
171
|
canvasWrap.append(stage, state);
|
|
169
172
|
const inspector = createElement('aside', 'cad-inspector');
|
|
170
|
-
const inspectorTitle = createElement('strong', undefined, '
|
|
173
|
+
const inspectorTitle = createElement('strong', undefined, t('cad.inspector.title'));
|
|
171
174
|
const inspectorList = createElement('dl');
|
|
172
175
|
const warningText = createElement('p', 'cad-warning');
|
|
173
176
|
warningText.hidden = true;
|
|
@@ -201,10 +204,10 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
201
204
|
const syncInspector = () => {
|
|
202
205
|
const summary = loadResult === null || loadResult === void 0 ? void 0 : loadResult.summary;
|
|
203
206
|
const rows = [
|
|
204
|
-
['
|
|
205
|
-
['
|
|
206
|
-
['
|
|
207
|
-
['
|
|
207
|
+
[t('cad.inspector.entities'), formatNumber(summary === null || summary === void 0 ? void 0 : summary.entityCount, locale)],
|
|
208
|
+
[t('cad.inspector.blocks'), formatNumber(summary === null || summary === void 0 ? void 0 : summary.blockCount, locale)],
|
|
209
|
+
[t('cad.inspector.pages'), formatNumber(summary === null || summary === void 0 ? void 0 : summary.pageCount, locale)],
|
|
210
|
+
[t('cad.inspector.drawn'), formatNumber(renderStats === null || renderStats === void 0 ? void 0 : renderStats.drawn, locale)],
|
|
208
211
|
];
|
|
209
212
|
inspectorList.replaceChildren(...rows.map(([label, value]) => {
|
|
210
213
|
const row = createElement('div');
|
|
@@ -216,7 +219,7 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
216
219
|
warningText.hidden = !warning;
|
|
217
220
|
};
|
|
218
221
|
const syncLayers = () => {
|
|
219
|
-
layersCount.textContent =
|
|
222
|
+
layersCount.textContent = t('cad.layers.count', { count: layers.length });
|
|
220
223
|
layersPanel.hidden = layers.length === 0;
|
|
221
224
|
body.classList.toggle('without-layers', layers.length === 0);
|
|
222
225
|
layersList.replaceChildren(...layers.map(layer => {
|
|
@@ -362,7 +365,7 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
362
365
|
syncUi();
|
|
363
366
|
},
|
|
364
367
|
onError: error => {
|
|
365
|
-
errorMessage = error.message || '
|
|
368
|
+
errorMessage = error.message || t('cad.error.parseFailed');
|
|
366
369
|
syncState();
|
|
367
370
|
},
|
|
368
371
|
});
|
|
@@ -375,7 +378,7 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
375
378
|
};
|
|
376
379
|
const loadCad = async () => {
|
|
377
380
|
status = 'loading';
|
|
378
|
-
progressMessage = '
|
|
381
|
+
progressMessage = t('cad.state.parsing');
|
|
379
382
|
errorMessage = '';
|
|
380
383
|
loadResult = null;
|
|
381
384
|
renderStats = null;
|
|
@@ -416,7 +419,7 @@ export default async function renderCad(buffer, target, type = 'dxf', context) {
|
|
|
416
419
|
}
|
|
417
420
|
console.error(reason);
|
|
418
421
|
status = 'error';
|
|
419
|
-
errorMessage = reason instanceof Error ? reason.message : '
|
|
422
|
+
errorMessage = reason instanceof Error ? reason.message : t('cad.error.parseFailed');
|
|
420
423
|
syncUi();
|
|
421
424
|
}
|
|
422
425
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-cad",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone CAD renderer plugin for Flyfish File Viewer powered by @flyfish-dev/cad-viewer.",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"LICENSE"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@file-viewer/core": "^2.1.
|
|
59
|
+
"@file-viewer/core": "^2.1.3",
|
|
60
60
|
"@flyfish-dev/cad-viewer": "^0.6.4"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|