@cadview/core 0.2.0 → 0.3.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.
- package/dist/index.cjs +321 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -3
- package/dist/index.d.ts +77 -3
- package/dist/index.js +321 -14
- package/dist/index.js.map +1 -1
- package/package.json +25 -12
package/dist/index.d.cts
CHANGED
|
@@ -301,6 +301,50 @@ interface ThemeConfig {
|
|
|
301
301
|
}
|
|
302
302
|
declare const THEMES: Record<Theme, ThemeConfig>;
|
|
303
303
|
|
|
304
|
+
interface RenderStats {
|
|
305
|
+
entitiesDrawn: number;
|
|
306
|
+
entitiesSkipped: number;
|
|
307
|
+
drawCalls: number;
|
|
308
|
+
byType: Record<string, number>;
|
|
309
|
+
}
|
|
310
|
+
interface DebugOptions {
|
|
311
|
+
showFps?: boolean;
|
|
312
|
+
showRenderStats?: boolean;
|
|
313
|
+
showDocumentInfo?: boolean;
|
|
314
|
+
showTimings?: boolean;
|
|
315
|
+
showCamera?: boolean;
|
|
316
|
+
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
317
|
+
}
|
|
318
|
+
interface DebugStats {
|
|
319
|
+
fps: number;
|
|
320
|
+
frameTime: number;
|
|
321
|
+
renderStats: RenderStats;
|
|
322
|
+
entityCount: number;
|
|
323
|
+
layerCount: number;
|
|
324
|
+
visibleLayerCount: number;
|
|
325
|
+
blockCount: number;
|
|
326
|
+
parseTime: number;
|
|
327
|
+
spatialIndexBuildTime: number;
|
|
328
|
+
totalLoadTime: number;
|
|
329
|
+
zoom: number;
|
|
330
|
+
pixelSize: number;
|
|
331
|
+
viewportBounds: {
|
|
332
|
+
minX: number;
|
|
333
|
+
minY: number;
|
|
334
|
+
maxX: number;
|
|
335
|
+
maxY: number;
|
|
336
|
+
};
|
|
337
|
+
fileName: string | null;
|
|
338
|
+
fileSize: number;
|
|
339
|
+
dxfVersion: string | null;
|
|
340
|
+
}
|
|
341
|
+
type ResolvedDebugOptions = Required<DebugOptions>;
|
|
342
|
+
/**
|
|
343
|
+
* Render a debug overlay panel on the canvas in screen space.
|
|
344
|
+
* Follows the same pattern as renderMeasureOverlay — resets transform to screen space.
|
|
345
|
+
*/
|
|
346
|
+
declare function renderDebugOverlay(ctx: CanvasRenderingContext2D, stats: DebugStats, theme: Theme, options: ResolvedDebugOptions, canvasWidth: number, canvasHeight: number): void;
|
|
347
|
+
|
|
304
348
|
/**
|
|
305
349
|
* Resolve the display color for an entity.
|
|
306
350
|
*
|
|
@@ -325,12 +369,12 @@ declare class CanvasRenderer {
|
|
|
325
369
|
getWidth(): number;
|
|
326
370
|
getHeight(): number;
|
|
327
371
|
updateSize(): void;
|
|
328
|
-
render(doc: DxfDocument, vt: ViewTransform, theme: Theme, visibleLayers: Set<string>, selectedEntityIndex: number):
|
|
372
|
+
render(doc: DxfDocument, vt: ViewTransform, theme: Theme, visibleLayers: Set<string>, selectedEntityIndex: number): RenderStats;
|
|
329
373
|
renderEmpty(theme: Theme): void;
|
|
330
374
|
destroy(): void;
|
|
331
375
|
}
|
|
332
376
|
|
|
333
|
-
declare function drawEntity(ctx: CanvasRenderingContext2D, entity: DxfEntity, doc: DxfDocument, vt: ViewTransform, theme: Theme, pixelSize: number): void;
|
|
377
|
+
declare function drawEntity(ctx: CanvasRenderingContext2D, entity: DxfEntity, doc: DxfDocument, vt: ViewTransform, theme: Theme, pixelSize: number, stats?: RenderStats): void;
|
|
334
378
|
|
|
335
379
|
interface SelectEvent {
|
|
336
380
|
entity: DxfEntity;
|
|
@@ -387,6 +431,11 @@ interface CadViewerOptions {
|
|
|
387
431
|
initialTool?: Tool;
|
|
388
432
|
/** Format converters for non-DXF file formats (e.g. DWG via @cadview/dwg). */
|
|
389
433
|
formatConverters?: FormatConverter[];
|
|
434
|
+
/**
|
|
435
|
+
* Enable a debug overlay showing FPS, render stats, document info, timing, and camera data.
|
|
436
|
+
* Pass `true` for defaults, or an object for granular control.
|
|
437
|
+
*/
|
|
438
|
+
debug?: boolean | DebugOptions;
|
|
390
439
|
}
|
|
391
440
|
declare class CadViewer {
|
|
392
441
|
private canvas;
|
|
@@ -408,6 +457,18 @@ declare class CadViewer {
|
|
|
408
457
|
private loadGeneration;
|
|
409
458
|
private mouseScreenX;
|
|
410
459
|
private mouseScreenY;
|
|
460
|
+
private debugEnabled;
|
|
461
|
+
private debugOptions;
|
|
462
|
+
private lastRenderStats;
|
|
463
|
+
private lastDebugStats;
|
|
464
|
+
private frameTimestamps;
|
|
465
|
+
private lastDoRenderTime;
|
|
466
|
+
private lastFrameTime;
|
|
467
|
+
private parseTime;
|
|
468
|
+
private spatialIndexBuildTime;
|
|
469
|
+
private loadedFileName;
|
|
470
|
+
private loadedFileSize;
|
|
471
|
+
private debugRafId;
|
|
411
472
|
constructor(canvas: HTMLCanvasElement, options?: CadViewerOptions);
|
|
412
473
|
/**
|
|
413
474
|
* Throws if the viewer has been destroyed.
|
|
@@ -475,6 +536,19 @@ declare class CadViewer {
|
|
|
475
536
|
/** @internal */
|
|
476
537
|
requestRender(): void;
|
|
477
538
|
private doRender;
|
|
539
|
+
/**
|
|
540
|
+
* Enable or disable the debug overlay.
|
|
541
|
+
* Pass `true` for defaults, `false` to disable, or an object for granular control.
|
|
542
|
+
*/
|
|
543
|
+
setDebug(debug: boolean | DebugOptions): void;
|
|
544
|
+
private startDebugLoop;
|
|
545
|
+
private stopDebugLoop;
|
|
546
|
+
/**
|
|
547
|
+
* Get the latest debug stats snapshot, or null if debug mode is off.
|
|
548
|
+
*/
|
|
549
|
+
getDebugStats(): DebugStats | null;
|
|
550
|
+
private buildDebugStats;
|
|
551
|
+
private computeViewportBounds;
|
|
478
552
|
/** @internal */
|
|
479
553
|
handlePan(dx: number, dy: number): void;
|
|
480
554
|
/** @internal */
|
|
@@ -563,4 +637,4 @@ interface BBox {
|
|
|
563
637
|
declare function computeEntitiesBounds(entities: DxfEntity[]): BBox | null;
|
|
564
638
|
declare function computeEntityBBox(entity: DxfEntity): BBox | null;
|
|
565
639
|
|
|
566
|
-
export { type BBox, CadViewer, type CadViewerEventMap, type CadViewerOptions, Camera, CanvasRenderer, type DxfArcEntity, type DxfAttrib, type DxfBlock, type DxfCircleEntity, type DxfDimensionEntity, type DxfDocument, type DxfEllipseEntity, type DxfEntity, type DxfEntityBase, type DxfHatchBoundaryPath, type DxfHatchEdge, type DxfHatchEntity, type DxfHeader, type DxfInsertEntity, type DxfLayer, type DxfLineEntity, type DxfLineType, type DxfLwPolylineEntity, type DxfLwPolylineVertex, type DxfMTextEntity, DxfParseError, type DxfPointEntity, type DxfPolylineEntity, type DxfSplineEntity, type DxfStyle, type DxfTextEntity, EventEmitter, type FormatConverter, LayerManager, type MeasureEvent, type MeasureState, MeasureTool, type Point2D, type Point3D, type SelectEvent, type SnapResult, type SnapType, SpatialIndex, THEMES, type Theme, type ThemeConfig, type Tool, type ViewTransform, aciToDisplayColor, aciToHex, applyTransform, computeEntitiesBounds, computeEntityBBox, drawEntity, findSnaps, fitToView, hitTest, parseDxf, renderMeasureOverlay, resolveEntityColor, screenToWorld, trueColorToHex, worldToScreen, zoomAtPoint };
|
|
640
|
+
export { type BBox, CadViewer, type CadViewerEventMap, type CadViewerOptions, Camera, CanvasRenderer, type DebugOptions, type DebugStats, type DxfArcEntity, type DxfAttrib, type DxfBlock, type DxfCircleEntity, type DxfDimensionEntity, type DxfDocument, type DxfEllipseEntity, type DxfEntity, type DxfEntityBase, type DxfHatchBoundaryPath, type DxfHatchEdge, type DxfHatchEntity, type DxfHeader, type DxfInsertEntity, type DxfLayer, type DxfLineEntity, type DxfLineType, type DxfLwPolylineEntity, type DxfLwPolylineVertex, type DxfMTextEntity, DxfParseError, type DxfPointEntity, type DxfPolylineEntity, type DxfSplineEntity, type DxfStyle, type DxfTextEntity, EventEmitter, type FormatConverter, LayerManager, type MeasureEvent, type MeasureState, MeasureTool, type Point2D, type Point3D, type RenderStats, type SelectEvent, type SnapResult, type SnapType, SpatialIndex, THEMES, type Theme, type ThemeConfig, type Tool, type ViewTransform, aciToDisplayColor, aciToHex, applyTransform, computeEntitiesBounds, computeEntityBBox, drawEntity, findSnaps, fitToView, hitTest, parseDxf, renderDebugOverlay, renderMeasureOverlay, resolveEntityColor, screenToWorld, trueColorToHex, worldToScreen, zoomAtPoint };
|
package/dist/index.d.ts
CHANGED
|
@@ -301,6 +301,50 @@ interface ThemeConfig {
|
|
|
301
301
|
}
|
|
302
302
|
declare const THEMES: Record<Theme, ThemeConfig>;
|
|
303
303
|
|
|
304
|
+
interface RenderStats {
|
|
305
|
+
entitiesDrawn: number;
|
|
306
|
+
entitiesSkipped: number;
|
|
307
|
+
drawCalls: number;
|
|
308
|
+
byType: Record<string, number>;
|
|
309
|
+
}
|
|
310
|
+
interface DebugOptions {
|
|
311
|
+
showFps?: boolean;
|
|
312
|
+
showRenderStats?: boolean;
|
|
313
|
+
showDocumentInfo?: boolean;
|
|
314
|
+
showTimings?: boolean;
|
|
315
|
+
showCamera?: boolean;
|
|
316
|
+
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
317
|
+
}
|
|
318
|
+
interface DebugStats {
|
|
319
|
+
fps: number;
|
|
320
|
+
frameTime: number;
|
|
321
|
+
renderStats: RenderStats;
|
|
322
|
+
entityCount: number;
|
|
323
|
+
layerCount: number;
|
|
324
|
+
visibleLayerCount: number;
|
|
325
|
+
blockCount: number;
|
|
326
|
+
parseTime: number;
|
|
327
|
+
spatialIndexBuildTime: number;
|
|
328
|
+
totalLoadTime: number;
|
|
329
|
+
zoom: number;
|
|
330
|
+
pixelSize: number;
|
|
331
|
+
viewportBounds: {
|
|
332
|
+
minX: number;
|
|
333
|
+
minY: number;
|
|
334
|
+
maxX: number;
|
|
335
|
+
maxY: number;
|
|
336
|
+
};
|
|
337
|
+
fileName: string | null;
|
|
338
|
+
fileSize: number;
|
|
339
|
+
dxfVersion: string | null;
|
|
340
|
+
}
|
|
341
|
+
type ResolvedDebugOptions = Required<DebugOptions>;
|
|
342
|
+
/**
|
|
343
|
+
* Render a debug overlay panel on the canvas in screen space.
|
|
344
|
+
* Follows the same pattern as renderMeasureOverlay — resets transform to screen space.
|
|
345
|
+
*/
|
|
346
|
+
declare function renderDebugOverlay(ctx: CanvasRenderingContext2D, stats: DebugStats, theme: Theme, options: ResolvedDebugOptions, canvasWidth: number, canvasHeight: number): void;
|
|
347
|
+
|
|
304
348
|
/**
|
|
305
349
|
* Resolve the display color for an entity.
|
|
306
350
|
*
|
|
@@ -325,12 +369,12 @@ declare class CanvasRenderer {
|
|
|
325
369
|
getWidth(): number;
|
|
326
370
|
getHeight(): number;
|
|
327
371
|
updateSize(): void;
|
|
328
|
-
render(doc: DxfDocument, vt: ViewTransform, theme: Theme, visibleLayers: Set<string>, selectedEntityIndex: number):
|
|
372
|
+
render(doc: DxfDocument, vt: ViewTransform, theme: Theme, visibleLayers: Set<string>, selectedEntityIndex: number): RenderStats;
|
|
329
373
|
renderEmpty(theme: Theme): void;
|
|
330
374
|
destroy(): void;
|
|
331
375
|
}
|
|
332
376
|
|
|
333
|
-
declare function drawEntity(ctx: CanvasRenderingContext2D, entity: DxfEntity, doc: DxfDocument, vt: ViewTransform, theme: Theme, pixelSize: number): void;
|
|
377
|
+
declare function drawEntity(ctx: CanvasRenderingContext2D, entity: DxfEntity, doc: DxfDocument, vt: ViewTransform, theme: Theme, pixelSize: number, stats?: RenderStats): void;
|
|
334
378
|
|
|
335
379
|
interface SelectEvent {
|
|
336
380
|
entity: DxfEntity;
|
|
@@ -387,6 +431,11 @@ interface CadViewerOptions {
|
|
|
387
431
|
initialTool?: Tool;
|
|
388
432
|
/** Format converters for non-DXF file formats (e.g. DWG via @cadview/dwg). */
|
|
389
433
|
formatConverters?: FormatConverter[];
|
|
434
|
+
/**
|
|
435
|
+
* Enable a debug overlay showing FPS, render stats, document info, timing, and camera data.
|
|
436
|
+
* Pass `true` for defaults, or an object for granular control.
|
|
437
|
+
*/
|
|
438
|
+
debug?: boolean | DebugOptions;
|
|
390
439
|
}
|
|
391
440
|
declare class CadViewer {
|
|
392
441
|
private canvas;
|
|
@@ -408,6 +457,18 @@ declare class CadViewer {
|
|
|
408
457
|
private loadGeneration;
|
|
409
458
|
private mouseScreenX;
|
|
410
459
|
private mouseScreenY;
|
|
460
|
+
private debugEnabled;
|
|
461
|
+
private debugOptions;
|
|
462
|
+
private lastRenderStats;
|
|
463
|
+
private lastDebugStats;
|
|
464
|
+
private frameTimestamps;
|
|
465
|
+
private lastDoRenderTime;
|
|
466
|
+
private lastFrameTime;
|
|
467
|
+
private parseTime;
|
|
468
|
+
private spatialIndexBuildTime;
|
|
469
|
+
private loadedFileName;
|
|
470
|
+
private loadedFileSize;
|
|
471
|
+
private debugRafId;
|
|
411
472
|
constructor(canvas: HTMLCanvasElement, options?: CadViewerOptions);
|
|
412
473
|
/**
|
|
413
474
|
* Throws if the viewer has been destroyed.
|
|
@@ -475,6 +536,19 @@ declare class CadViewer {
|
|
|
475
536
|
/** @internal */
|
|
476
537
|
requestRender(): void;
|
|
477
538
|
private doRender;
|
|
539
|
+
/**
|
|
540
|
+
* Enable or disable the debug overlay.
|
|
541
|
+
* Pass `true` for defaults, `false` to disable, or an object for granular control.
|
|
542
|
+
*/
|
|
543
|
+
setDebug(debug: boolean | DebugOptions): void;
|
|
544
|
+
private startDebugLoop;
|
|
545
|
+
private stopDebugLoop;
|
|
546
|
+
/**
|
|
547
|
+
* Get the latest debug stats snapshot, or null if debug mode is off.
|
|
548
|
+
*/
|
|
549
|
+
getDebugStats(): DebugStats | null;
|
|
550
|
+
private buildDebugStats;
|
|
551
|
+
private computeViewportBounds;
|
|
478
552
|
/** @internal */
|
|
479
553
|
handlePan(dx: number, dy: number): void;
|
|
480
554
|
/** @internal */
|
|
@@ -563,4 +637,4 @@ interface BBox {
|
|
|
563
637
|
declare function computeEntitiesBounds(entities: DxfEntity[]): BBox | null;
|
|
564
638
|
declare function computeEntityBBox(entity: DxfEntity): BBox | null;
|
|
565
639
|
|
|
566
|
-
export { type BBox, CadViewer, type CadViewerEventMap, type CadViewerOptions, Camera, CanvasRenderer, type DxfArcEntity, type DxfAttrib, type DxfBlock, type DxfCircleEntity, type DxfDimensionEntity, type DxfDocument, type DxfEllipseEntity, type DxfEntity, type DxfEntityBase, type DxfHatchBoundaryPath, type DxfHatchEdge, type DxfHatchEntity, type DxfHeader, type DxfInsertEntity, type DxfLayer, type DxfLineEntity, type DxfLineType, type DxfLwPolylineEntity, type DxfLwPolylineVertex, type DxfMTextEntity, DxfParseError, type DxfPointEntity, type DxfPolylineEntity, type DxfSplineEntity, type DxfStyle, type DxfTextEntity, EventEmitter, type FormatConverter, LayerManager, type MeasureEvent, type MeasureState, MeasureTool, type Point2D, type Point3D, type SelectEvent, type SnapResult, type SnapType, SpatialIndex, THEMES, type Theme, type ThemeConfig, type Tool, type ViewTransform, aciToDisplayColor, aciToHex, applyTransform, computeEntitiesBounds, computeEntityBBox, drawEntity, findSnaps, fitToView, hitTest, parseDxf, renderMeasureOverlay, resolveEntityColor, screenToWorld, trueColorToHex, worldToScreen, zoomAtPoint };
|
|
640
|
+
export { type BBox, CadViewer, type CadViewerEventMap, type CadViewerOptions, Camera, CanvasRenderer, type DebugOptions, type DebugStats, type DxfArcEntity, type DxfAttrib, type DxfBlock, type DxfCircleEntity, type DxfDimensionEntity, type DxfDocument, type DxfEllipseEntity, type DxfEntity, type DxfEntityBase, type DxfHatchBoundaryPath, type DxfHatchEdge, type DxfHatchEntity, type DxfHeader, type DxfInsertEntity, type DxfLayer, type DxfLineEntity, type DxfLineType, type DxfLwPolylineEntity, type DxfLwPolylineVertex, type DxfMTextEntity, DxfParseError, type DxfPointEntity, type DxfPolylineEntity, type DxfSplineEntity, type DxfStyle, type DxfTextEntity, EventEmitter, type FormatConverter, LayerManager, type MeasureEvent, type MeasureState, MeasureTool, type Point2D, type Point3D, type RenderStats, type SelectEvent, type SnapResult, type SnapType, SpatialIndex, THEMES, type Theme, type ThemeConfig, type Tool, type ViewTransform, aciToDisplayColor, aciToHex, applyTransform, computeEntitiesBounds, computeEntityBBox, drawEntity, findSnaps, fitToView, hitTest, parseDxf, renderDebugOverlay, renderMeasureOverlay, resolveEntityColor, screenToWorld, trueColorToHex, worldToScreen, zoomAtPoint };
|