feat(canvas): produce and consume transparent renderContent textures

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>
This commit is contained in:
2026-07-16 20:46:12 +08:00
parent ee2c52bbc6
commit 8e1506e4c4
12 changed files with 137 additions and 21 deletions
@@ -0,0 +1,38 @@
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"]);
});