fix: close final viewer integration gaps (#5)
This commit is contained in:
@@ -6,13 +6,15 @@ import { is2D, isDwg } from './ext2d';
|
||||
import { parseDxfBuffer } from './parseDxf';
|
||||
import { setDefaultFontUrl } from './slugText';
|
||||
|
||||
export type { CadParseResult } from './dwgParser';
|
||||
|
||||
export type CadInput = {
|
||||
name: string;
|
||||
data: ArrayBuffer | Uint8Array;
|
||||
};
|
||||
|
||||
export type CadLoadSummary = {
|
||||
entityCount: number;
|
||||
};
|
||||
|
||||
export type Viewer2DOptions = {
|
||||
fontUrl?: string;
|
||||
};
|
||||
@@ -26,7 +28,7 @@ export function isCad2DFile(name: string): boolean {
|
||||
return is2D(name);
|
||||
}
|
||||
|
||||
export async function parseCad(input: CadInput): Promise<CadParseResult> {
|
||||
async function parseCad(input: CadInput): Promise<CadParseResult> {
|
||||
const buffer = toArrayBuffer(input.data);
|
||||
if (isDwg(input.name)) return parseDwgBuffer(new Uint8Array(buffer));
|
||||
if (is2D(input.name)) return parseDxfBuffer(buffer);
|
||||
@@ -38,6 +40,16 @@ export async function parseCad(input: CadInput): Promise<CadParseResult> {
|
||||
return parseDxfBuffer(buffer);
|
||||
}
|
||||
|
||||
export async function loadCad(
|
||||
viewer: Pick<Viewer2D, 'load' | 'resize'>,
|
||||
input: CadInput,
|
||||
): Promise<CadLoadSummary> {
|
||||
const result = await parseCad(input);
|
||||
viewer.load(result);
|
||||
viewer.resize();
|
||||
return { entityCount: result.entities?.length ?? 0 };
|
||||
}
|
||||
|
||||
export function createViewer2D(container: HTMLElement, options: Viewer2DOptions = {}): Viewer2D {
|
||||
if (options.fontUrl) setDefaultFontUrl(options.fontUrl);
|
||||
return new Viewer2D(container);
|
||||
|
||||
Reference in New Issue
Block a user