Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/visual-track/src/lower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ function sampleElements(
xPx: layer.source.extent.widthPx / 2,
yPx: layer.source.extent.heightPx / 2,
}, layer.mapping);
// Layers are absolutely positioned inside the bordered frame element, so CSS places them from
// its padding edge. The mapping is already inset by the border; measure from that edge too.
const border = clip.treatment.border?.widthPx ?? 0;
const originX = clip.frame.xPx + border;
const originY = clip.frame.yPx + border;
const sampling = `${layer.id}:sampling`;
const appearance = `${layer.id}:appearance`;
const mapping = `${layer.id}:mapping`;
Expand All @@ -136,7 +141,7 @@ function sampleElements(
{ name: "left", value: 0 },
{ name: "position", value: "absolute" },
{ name: "top", value: 0 },
{ name: "transform-origin", value: `${px(sourceCenter.xPx - clip.frame.xPx)} ${px(sourceCenter.yPx - clip.frame.yPx)}` },
{ name: "transform-origin", value: `${px(sourceCenter.xPx - originX)} ${px(sourceCenter.yPx - originY)}` },
{ name: "width", value: "100%" },
],
...(() => {
Expand All @@ -148,15 +153,15 @@ function sampleElements(
};
})(),
};
const localTx = layer.mapping.tx - clip.frame.xPx;
const localTy = layer.mapping.ty - clip.frame.yPx;
const localTx = layer.mapping.tx - originX;
const localTy = layer.mapping.ty - originY;
const corners = [
{ xPx: 0, yPx: 0 },
{ xPx: layer.source.extent.widthPx, yPx: 0 },
{ xPx: layer.source.extent.widthPx, yPx: layer.source.extent.heightPx },
{ xPx: 0, yPx: layer.source.extent.heightPx },
].map((point) => mapSpatialPoint(point, layer.mapping))
.map((point) => `${px(point.xPx - clip.frame.xPx)} ${px(point.yPx - clip.frame.yPx)}`);
.map((point) => `${px(point.xPx - originX)} ${px(point.yPx - originY)}`);
const appearanceStyle: VisualStyleDeclaration[] = [
{ name: "filter", value: filter(layer) },
{ name: "height", value: "100%" },
Expand Down
5 changes: 3 additions & 2 deletions packages/visual-track/test/visual-track.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ test("a Clip keeps ordered Paint/sample layers, two-frame fit and frame treatmen
{ name: "left", value: 0 },
{ name: "position", value: "absolute" },
{ name: "top", value: 0 },
{ name: "transform-origin", value: "200px 150px" },
// Layers sit inside the frame's 2px border, so their local origin is the padding edge.
{ name: "transform-origin", value: "198px 148px" },
{ name: "width", value: "100%" },
]);
const mapping = elements.find((element) => element.id === "content:mapping");
Expand All @@ -246,7 +247,7 @@ test("a Clip keeps ordered Paint/sample layers, two-frame fit and frame treatmen
{ name: "left", value: 0 },
{ name: "position", value: "absolute" },
{ name: "top", value: 0 },
{ name: "transform", value: "matrix(0.345,0,0,0.345,62,12)" },
{ name: "transform", value: "matrix(0.345,0,0,0.345,60,10)" },
{ name: "transform-origin", value: "0 0" },
{ name: "width", value: "800px" },
]);
Expand Down