feat(core): add intrinsic asset dimensions

This commit is contained in:
syntaxbullet
2026-07-03 16:14:00 +02:00
parent a3b4a4a1b0
commit 97c3d3b7ae
3 changed files with 75 additions and 8 deletions

View File

@@ -6,14 +6,25 @@ const document: ImageDocument = {
id: "d1",
name: "Test",
version: 1,
assets: [],
assets: [{ id: "asset-1", name: "Image", mimeType: "image/png", source: "asset://image", intrinsicSize: { w: 200, h: 100 } }],
artboards: [
{
id: "a1",
name: "Artboard",
bounds: { x: 0, y: 0, w: 100, h: 80 },
backgroundColor: "transparent",
layers: [],
layers: [
{
id: "l1",
type: "image",
name: "Image Layer",
visible: true,
locked: false,
opacity: 1,
assetId: "asset-1",
transform: { position: { x: 10, y: 20 }, scale: { x: 0.5, y: 2 }, rotation: 0 },
},
],
},
],
};
@@ -27,6 +38,17 @@ describe("transform targets", () => {
expect(resolveTransformTargetBounds(document, { type: "artboard", id: "a1" })).toEqual({ x: 0, y: 0, w: 100, h: 80 });
});
test("resolves image layer bounds from intrinsic asset dimensions", () => {
expect(resolveTransformTargetBounds(document, { type: "layer", id: "l1" })).toEqual({ x: 10, y: 20, w: 100, h: 200 });
});
test("applies image layer bounds to transform", () => {
const next = applyTransformTargetBounds(document, { type: "layer", id: "l1" }, { x: 30, y: 40, w: 400, h: 50 });
const layer = next.artboards[0]?.layers[0];
expect(layer?.transform).toEqual({ position: { x: 30, y: 40 }, scale: { x: 2, y: 0.5 }, rotation: 0 });
});
test("applies artboard bounds", () => {
const next = applyTransformTargetBounds(document, { type: "artboard", id: "a1" }, { x: 10, y: 20, w: 200, h: 160 });
expect(next.artboards[0]?.bounds).toEqual({ x: 10, y: 20, w: 200, h: 160 });