078b0bee32
Accept DWG and DXF files (up to 24 MB) through the canvas asset picker and drag-and-drop. Conversion runs locally in a browser worker via acad-ts, uploads a sanitized derived SVG, and leaves the source file untouched. DXF covers ASCII and binary drawings; DWG covers AutoCAD R14 through 2018. Rename the image-only upload input/handler to a generic canvas asset flow, add vector-image node detection, tag imported SVGs as vector-image nodes, localize CAD import status/error messages, and switch the Next build to the webpack compiler so the worker bundles correctly. Add a node --test suite covering CAD conversion and vector image helpers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
787 B
TypeScript
31 lines
787 B
TypeScript
import { convertCadBufferToSvg, type CadFormat } from "./cadConversion";
|
|
|
|
type CadWorkerRequest = {
|
|
buffer: ArrayBuffer;
|
|
format: CadFormat;
|
|
};
|
|
|
|
type CadWorkerResponse =
|
|
| { ok: true; svg: string }
|
|
| { ok: false; error: string };
|
|
|
|
type WorkerScope = {
|
|
onmessage: ((event: MessageEvent<CadWorkerRequest>) => void) | null;
|
|
postMessage: (message: CadWorkerResponse) => void;
|
|
};
|
|
|
|
const workerScope = globalThis as unknown as WorkerScope;
|
|
|
|
workerScope.onmessage = (event) => {
|
|
try {
|
|
const { buffer, format } = event.data;
|
|
const svg = convertCadBufferToSvg(buffer, format);
|
|
workerScope.postMessage({ ok: true, svg });
|
|
} catch (error) {
|
|
workerScope.postMessage({
|
|
ok: false,
|
|
error: error instanceof Error ? error.message : String(error)
|
|
});
|
|
}
|
|
};
|