@maqiuyao/dxf-viewer 0.2.4 → 0.2.6
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.
|
@@ -53,6 +53,11 @@ export interface ModelConfig {
|
|
|
53
53
|
* Source url of the model
|
|
54
54
|
*/
|
|
55
55
|
src: string;
|
|
56
|
+
/**
|
|
57
|
+
* 下载 src 时附带的自定义 HTTP 请求头,如 { Authorization: "Bearer xxx" }。
|
|
58
|
+
* 未指定时使用 viewer.setRequestHeaders() 设置的全局默认请求头。
|
|
59
|
+
*/
|
|
60
|
+
headers?: Record<string, string>;
|
|
56
61
|
/**
|
|
57
62
|
* Used to distinguish format, because it may be hard to know the format by src!
|
|
58
63
|
* @internal
|
|
@@ -190,6 +190,10 @@ export interface DxfLoaderConfig {
|
|
|
190
190
|
* File encoding, can be used by dxf. Common encoding include "UTF-8", "gb2312", etc.
|
|
191
191
|
*/
|
|
192
192
|
encoding?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Custom HTTP request headers (e.g. auth token) attached when downloading the dxf file.
|
|
195
|
+
*/
|
|
196
|
+
requestHeaders?: Record<string, string>;
|
|
193
197
|
/**
|
|
194
198
|
* Apply this color to everything in this model.
|
|
195
199
|
* Color value between 0 and 1.
|
|
@@ -307,11 +311,6 @@ export declare class DxfLoader extends THREE.Loader {
|
|
|
307
311
|
*/
|
|
308
312
|
private entityHandlesWithRenderOrder;
|
|
309
313
|
private addViewport;
|
|
310
|
-
/**
|
|
311
|
-
* 说明:该静态属性在 bundle 中只被读取、从未被赋值(原始拼写可能有误),
|
|
312
|
-
* 运行时恒为 undefined;此处按原样保留。
|
|
313
|
-
*/
|
|
314
|
-
private static readonly REQUWSTHEADER?;
|
|
315
314
|
/**
|
|
316
315
|
* 说明:以下静态字段在 bundle 中于类定义之后统一赋值,此处以字段初始化器的形式等价还原。
|
|
317
316
|
*/
|
|
@@ -46,6 +46,48 @@ export interface PdfData {
|
|
|
46
46
|
layersAndThreejsObjects?: Record<string, THREE.Object3D[]>;
|
|
47
47
|
loadedEntityCount: number;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for {@link Viewer2d.print}.
|
|
51
|
+
*/
|
|
52
|
+
export interface PrintOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Print area.
|
|
55
|
+
* - "view": print the current viewport as-is.
|
|
56
|
+
* - "extents": temporarily fit the whole drawing to the view, then print.
|
|
57
|
+
* @default "view"
|
|
58
|
+
*/
|
|
59
|
+
area?: "view" | "extents";
|
|
60
|
+
/**
|
|
61
|
+
* Paper size for the @page rule.
|
|
62
|
+
* @default "A4"
|
|
63
|
+
*/
|
|
64
|
+
paperSize?: "A4" | "A3" | "A2" | "A1" | "A0" | "Letter";
|
|
65
|
+
/**
|
|
66
|
+
* Page orientation. "auto" picks landscape when the image is wider than tall.
|
|
67
|
+
* @default "auto"
|
|
68
|
+
*/
|
|
69
|
+
orientation?: "auto" | "landscape" | "portrait";
|
|
70
|
+
/**
|
|
71
|
+
* Invert colors so the dark CAD background becomes white with dark lines (saves toner).
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
invertColors?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Scale the image to fit within the page. When false, the image fills the page width.
|
|
77
|
+
* @default true
|
|
78
|
+
*/
|
|
79
|
+
fitToPage?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Page margin in millimeters.
|
|
82
|
+
* @default 10
|
|
83
|
+
*/
|
|
84
|
+
margins?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Document title shown in the print dialog.
|
|
87
|
+
* @default "图纸"
|
|
88
|
+
*/
|
|
89
|
+
title?: string;
|
|
90
|
+
}
|
|
49
91
|
/**
|
|
50
92
|
* @internal
|
|
51
93
|
*/
|
|
@@ -175,6 +217,10 @@ export declare class Viewer2d extends BaseViewer {
|
|
|
175
217
|
private clickHighlightList?;
|
|
176
218
|
/** 是否启用点击实体高亮,默认关闭 */
|
|
177
219
|
private _enableClickHighlight;
|
|
220
|
+
/** 全局默认请求头(如认证 token),loadModel 未显式传 headers 时使用 */
|
|
221
|
+
private requestHeaders?;
|
|
222
|
+
/** 打印截图进行中:临时强制显示所有图符/文字,避免低缩放时被"视觉过小"逻辑隐藏 */
|
|
223
|
+
private _printCaptureMode;
|
|
178
224
|
constructor(viewerCfg: Viewer2dConfig);
|
|
179
225
|
get camera(): THREE.OrthographicCamera;
|
|
180
226
|
private setupDefaultEvents;
|
|
@@ -205,6 +251,16 @@ export declare class Viewer2d extends BaseViewer {
|
|
|
205
251
|
* 清除实体点击高亮。
|
|
206
252
|
*/
|
|
207
253
|
clearClickHighlight(): void;
|
|
254
|
+
/**
|
|
255
|
+
* 设置后续所有 loadModel 下载 src 时附带的默认 HTTP 请求头(如认证 token)。
|
|
256
|
+
* 传入 undefined 可清除。按次在 modelCfg.headers 中指定的请求头优先级更高。
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* viewer.setRequestHeaders({ Authorization: "Bearer " + token });
|
|
260
|
+
* await viewer.loadModel({ modelId: "a", src: "https://host/a.dxf" });
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
setRequestHeaders(headers: Record<string, string> | undefined): void;
|
|
208
264
|
protected handleMouseClick(e: EventInfo): void;
|
|
209
265
|
private setDefaultBackground;
|
|
210
266
|
/**
|
|
@@ -388,6 +444,43 @@ export declare class Viewer2d extends BaseViewer {
|
|
|
388
444
|
clearTextHighlight(): void;
|
|
389
445
|
zoomIn(step?: number): void;
|
|
390
446
|
zoomOut(step?: number): void;
|
|
447
|
+
/**
|
|
448
|
+
* @description {en} Prints the drawing. Captures the current viewport (or the whole drawing
|
|
449
|
+
* for area "extents") as an image, composites the overlay layer, and opens the browser
|
|
450
|
+
* print dialog via a hidden iframe with @page rules for the chosen paper size.
|
|
451
|
+
* @description {zh} 打印图纸。截取当前视图(area 为 "extents" 时先临时缩放至全图)渲染画面,
|
|
452
|
+
* 叠加标注层,通过隐藏 iframe 的 @page 规则按所选纸张调用浏览器打印对话框。
|
|
453
|
+
* @example
|
|
454
|
+
* ```typescript
|
|
455
|
+
* await viewer.print({ area: "extents", paperSize: "A3", invertColors: true });
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
print(options?: PrintOptions): Promise<void>;
|
|
459
|
+
/**
|
|
460
|
+
* Renders the scene (optionally fitted to the whole drawing) at high resolution and
|
|
461
|
+
* returns a PNG data URL with the WebGL canvas and the overlay canvas composited.
|
|
462
|
+
* For "extents", the result is cropped to the drawing's bounding box so the paper
|
|
463
|
+
* area is filled by the drawing itself (no letterbox margins). Camera/renderer state is restored.
|
|
464
|
+
*/
|
|
465
|
+
private capturePrintImage;
|
|
466
|
+
/**
|
|
467
|
+
* Converts a dark-background CAD render to a white-background image for printing
|
|
468
|
+
* WITHOUT shifting hues: each pixel's HSL lightness is flipped (blue stays blue,
|
|
469
|
+
* cyan stays cyan) and darkened for paper contrast; dark background pixels are
|
|
470
|
+
* crushed to pure white; a color-carrying dilation thickens 1px hairlines and
|
|
471
|
+
* solidizes anti-aliased edges. Operates in-place on the canvas.
|
|
472
|
+
*/
|
|
473
|
+
private invertForPrint;
|
|
474
|
+
/**
|
|
475
|
+
* Crops a canvas (rendered by the current orthographic top-down camera) to a world-space box.
|
|
476
|
+
* Returns a PNG data URL, or undefined if the box is degenerate/out of view.
|
|
477
|
+
*/
|
|
478
|
+
private cropCanvasToBox;
|
|
479
|
+
/**
|
|
480
|
+
* Opens the browser print dialog with the image laid out on the selected paper size,
|
|
481
|
+
* via an offscreen hidden iframe (so the host page's own styles never leak into print).
|
|
482
|
+
*/
|
|
483
|
+
private printImageInIframe;
|
|
391
484
|
/**
|
|
392
485
|
* @description {en} Gets dxf layers.
|
|
393
486
|
* @description {zh} 获取dxf图层。
|