refactor: extract viewer2d workspace package

This commit is contained in:
2026-07-29 09:03:41 +09:00
parent 95fa6a452b
commit 5e10bb1be4
27 changed files with 1588 additions and 704 deletions
+26
View File
@@ -0,0 +1,26 @@
import { readFile } from 'node:fs/promises';
import { describe, expect, it } from 'vitest';
import { isCad2DFile, parseCad } from '@hmwebviewer/viewer2d';
describe('viewer2d package interface', () => {
it('parses the sample DXF through the public package interface', async () => {
const file = await readFile(new URL('../public/samples/simple.dxf', import.meta.url));
const result = await parseCad({
name: 'simple.dxf',
data: file.buffer.slice(file.byteOffset, file.byteOffset + file.byteLength),
});
const entities = result.entities as Array<{ layer?: string; type?: string }>;
expect(isCad2DFile('drawing.DWG')).toBe(true);
expect(isCad2DFile('drawing.dxf')).toBe(true);
expect(isCad2DFile('drawing.pdf')).toBe(false);
expect(entities.map(({ type, layer }) => [type, layer])).toEqual([
['LINE', 'OUTLINE'],
['LINE', 'OUTLINE'],
['LINE', 'OUTLINE'],
['LINE', 'OUTLINE'],
['CIRCLE', '0'],
['TEXT', '0'],
]);
});
});