8e1506e4c4
Rasterize imported SVG/CAD sources to a transparent WebP render texture and carry it as an optional renderContent alongside the original content through the domain node, snapshot normalization, and reference images. Add canvasNodeRenderContent and prefer it for artboard, layer, generated-file, and project thumbnail previews while keeping content as the crop/download/ model-reference source. Generalize the SVG rasterizer with a render purpose and add upload/reference coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { uploadPreparedCanvasImportAsset } from "../src/ui/lib/canvasImportUpload.ts";
|
|
|
|
test("commits source and transparent render texture only after both uploads succeed", async () => {
|
|
const source = { name: "drawing.svg" };
|
|
const render = { name: "drawing.render.webp" };
|
|
const uploaded = await uploadPreparedCanvasImportAsset(
|
|
{ file: source, renderFile: render },
|
|
async (file) => `https://assets.example/${file.name}`,
|
|
async () => {
|
|
throw new Error("cleanup should not run");
|
|
}
|
|
);
|
|
|
|
assert.deepEqual(uploaded, {
|
|
content: "https://assets.example/drawing.svg",
|
|
renderContent: "https://assets.example/drawing.render.webp"
|
|
});
|
|
});
|
|
|
|
test("removes a partial source upload when the render texture upload fails", async () => {
|
|
const cleaned = [];
|
|
await assert.rejects(
|
|
uploadPreparedCanvasImportAsset(
|
|
{ file: { name: "drawing.svg" }, renderFile: { name: "drawing.render.webp" } },
|
|
async (file) => {
|
|
if (file.name.endsWith(".webp")) throw new Error("preview upload failed");
|
|
return "https://assets.example/drawing.svg";
|
|
},
|
|
async (url) => cleaned.push(url)
|
|
),
|
|
/preview upload failed/
|
|
);
|
|
|
|
assert.deepEqual(cleaned, ["https://assets.example/drawing.svg"]);
|
|
});
|