{"_id":"@cadview/dwg","name":"@cadview/dwg","dist-tags":{"latest":"0.2.0"},"versions":{"0.2.0":{"name":"@cadview/dwg","version":"0.2.0","description":"DWG file format support for @cadview/core via LibreDWG WASM","license":"GPL-3.0-only","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"sideEffects":false,"peerDependencies":{"@cadview/core":">=0.2.0"},"devDependencies":{"@cadview/core":"workspace:*","@types/node":"^22.0.0","tsup":"^8.0.0","typescript":"^5.7.0","vitest":"^3.0.0"},"scripts":{"build":"tsup","build:wasm":"bash wasm/build.sh","build:all":"tsup && bash wasm/build.sh","dev":"tsup --watch","test":"vitest run","typecheck":"tsc --noEmit"},"keywords":["cad","dwg","dxf","autocad","wasm","libredwg","viewer","converter"],"repository":{"type":"git","url":"git+https://github.com/wiscaksono/cadview.git","directory":"packages/dwg"},"author":{"name":"Wisnu Wicaksono"},"homepage":"https://cadview.wiscaksono.com","gitHead":"b81f32d35423fcc3255588c27e72ac577bf05fcf","_id":"@cadview/dwg@0.2.0","bugs":{"url":"https://github.com/wiscaksono/cadview/issues"},"_nodeVersion":"24.11.0","_npmVersion":"11.6.1","dist":{"integrity":"sha512-1NBmagbhwM4YEXoRieZxGhqOpYv+SmylapYIE6uvaUuvFa4Z0o6SoZfgUlk0QHslrLYK2C6Tw9K+srEOR4ZS9g==","shasum":"d575359a02d4c46fa1c4ca80806861648326bcc9","tarball":"https://registry.npmjs.org/@cadview/dwg/-/dwg-0.2.0.tgz","fileCount":11,"unpackedSize":7209643,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDWOgtludgpgCCFlCatZFGZxjWAIeuizbC1WMTDdqS5sAiB/RpY+ExmHAnimP0zFDQDj/pof1e5Sy2ZGETYShpxgpw=="}]},"_npmUser":{"name":"wiscaksono","email":"wwicaksono96@gmail.com"},"directories":{},"maintainers":[{"name":"wiscaksono","email":"wwicaksono96@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/dwg_0.2.0_1771508784136_0.12751216409503963"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-19T13:46:24.000Z","0.2.0":"2026-02-19T13:46:24.415Z","modified":"2026-02-19T13:46:24.750Z"},"maintainers":[{"name":"wiscaksono","email":"wwicaksono96@gmail.com"}],"description":"DWG file format support for @cadview/core via LibreDWG WASM","homepage":"https://cadview.wiscaksono.com","keywords":["cad","dwg","dxf","autocad","wasm","libredwg","viewer","converter"],"repository":{"type":"git","url":"git+https://github.com/wiscaksono/cadview.git","directory":"packages/dwg"},"author":{"name":"Wisnu Wicaksono"},"bugs":{"url":"https://github.com/wiscaksono/cadview/issues"},"license":"GPL-3.0-only","readme":"# @cadview/dwg\n\nDWG file format support for [@cadview/core](../core) via [LibreDWG](https://github.com/LibreDWG/libredwg) compiled to WebAssembly.\n\nConverts DWG files to DXF entirely in the browser — no server required.\n\n## License\n\n**GPL-3.0-only** — This package uses LibreDWG which is GPL-licensed. Using `@cadview/dwg` in your application makes the combined work subject to GPL-3.0 terms. If you cannot comply with the GPL, do not use this package.\n\n`@cadview/core` and the framework wrappers (`@cadview/react`, `@cadview/svelte`, `@cadview/vue`) remain MIT-licensed and have zero dependency on this package.\n\n## Installation\n\n```bash\nnpm install @cadview/dwg @cadview/core\n```\n\n## Quick Start\n\nRegister the `dwgConverter` with `CadViewer` to automatically handle DWG files alongside DXF:\n\n```ts\nimport { CadViewer } from '@cadview/core';\nimport { dwgConverter } from '@cadview/dwg';\n\nconst viewer = new CadViewer(canvas, {\n  formatConverters: [dwgConverter],\n});\n\n// loadFile() and loadBuffer() now handle both DXF and DWG\nawait viewer.loadFile(file);\n```\n\nWith framework wrappers:\n\n```tsx\n// React\nimport { CadViewer } from '@cadview/react';\nimport { dwgConverter } from '@cadview/dwg';\n\n<CadViewer file={file} formatConverters={[dwgConverter]} />\n```\n\n```svelte\n<!-- Svelte -->\n<script>\n  import { CadViewer } from '@cadview/svelte';\n  import { dwgConverter } from '@cadview/dwg';\n</script>\n\n<CadViewer {file} formatConverters={[dwgConverter]} />\n```\n\n```vue\n<!-- Vue -->\n<script setup>\nimport { CadViewer } from '@cadview/vue';\nimport { dwgConverter } from '@cadview/dwg';\n</script>\n\n<CadViewer :file=\"file\" :format-converters=\"[dwgConverter]\" />\n```\n\n## Standalone Usage\n\nYou can use the conversion functions directly without `CadViewer`:\n\n```ts\nimport { convertDwgToDxf, isDwg, getDwgVersion } from '@cadview/dwg';\nimport { parseDxf } from '@cadview/core';\n\n// Check if a buffer is a DWG file\nconst buffer = await file.arrayBuffer();\nif (isDwg(buffer)) {\n  const version = getDwgVersion(buffer); // e.g. \"AC1032\"\n  const dxfString = await convertDwgToDxf(buffer);\n  const doc = parseDxf(dxfString);\n}\n```\n\n## WASM Preloading\n\nThe LibreDWG WASM module (~2-5 MB) is lazy-loaded on the first DWG conversion. To avoid the delay when the user first opens a DWG file, preload it on app startup:\n\n```ts\nimport { initWasm } from '@cadview/dwg';\n\n// Preload on app startup\ninitWasm();\n\n// Or from a CDN\ninitWasm({ wasmUrl: 'https://cdn.example.com/libredwg.wasm' });\n```\n\n## API\n\n### `dwgConverter: FormatConverter`\n\nPre-configured format converter for use with `CadViewer`'s `formatConverters` option. Detects DWG files by magic bytes and converts via LibreDWG WASM.\n\n### `isDwg(buffer: ArrayBuffer): boolean`\n\nDetect DWG format by checking magic bytes (`AC10` prefix + two ASCII digits). Returns `false` on any error.\n\n### `getDwgVersion(buffer: ArrayBuffer): string | null`\n\nExtract the 6-character DWG version string (e.g. `\"AC1032\"`). Returns `null` for non-DWG buffers.\n\n### `getDwgReleaseName(version: string): string | null`\n\nGet the human-readable AutoCAD release name for a version string (e.g. `\"AC1032\"` → `\"R2018\"`).\n\n### `convertDwgToDxf(buffer: ArrayBuffer, options?: ConvertOptions): Promise<string>`\n\nConvert a DWG buffer to a DXF string. Lazily initializes the WASM module on first call.\n\nOptions:\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `timeout` | `number` | `30000` | Conversion timeout in ms (0 = no timeout) |\n| `wasmUrl` | `string` | — | Custom URL for the `.wasm` file (e.g. CDN) |\n\n### `initWasm(options?: WasmOptions): Promise<void>`\n\nPre-initialize the WASM module. Safe to call multiple times. Automatically retries on failure.\n\n### `isWasmReady(): boolean`\n\nCheck if the WASM module is loaded and ready.\n\n### `DWG_VERSIONS: Record<string, string>`\n\nMap of known DWG version strings to AutoCAD release names:\n\n| Version | Release |\n|---------|---------|\n| AC1009 | R11/R12 |\n| AC1012 | R13 |\n| AC1014 | R14 |\n| AC1015 | R2000 |\n| AC1018 | R2004 |\n| AC1021 | R2007 |\n| AC1024 | R2010 |\n| AC1027 | R2013 |\n| AC1032 | R2018 |\n\nMinimum supported version: **AC1012 (R13)**.\n\n## Building the WASM Module\n\nThe WASM module must be compiled from LibreDWG using Emscripten before DWG conversion will work at runtime.\n\nPrerequisites:\n- [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html) (`emsdk`)\n- Git (for LibreDWG submodule)\n\n```bash\n# Add LibreDWG as a git submodule (one-time)\ngit submodule add https://github.com/LibreDWG/libredwg.git packages/dwg/wasm/libredwg/\n\n# Build the WASM module\npnpm --filter @cadview/dwg build:wasm\n```\n\nThis generates `dist/libredwg.js` and `dist/libredwg.wasm`.\n\n## License\n\nGPL-3.0-only. See [LICENSE](./LICENSE).\n","readmeFilename":"README.md","_rev":"1-2e122298e2b8f4446d70b94f4c17bd28"}