|
1 | | -import { isFrame, isLayout, isRectangle } from "~/utils/identity.js"; |
| 1 | +import { isInAutoLayoutFlow, isFrame, isLayout, isRectangle } from "~/utils/identity.js"; |
2 | 2 | import type { |
3 | 3 | Node as FigmaDocumentNode, |
4 | 4 | HasFramePropertiesTrait, |
5 | 5 | HasLayoutTrait, |
6 | 6 | } from "@figma/rest-api-spec"; |
7 | | -import { generateCSSShorthand } from "~/utils/common.js"; |
| 7 | +import { generateCSSShorthand, pixelRound } from "~/utils/common.js"; |
8 | 8 |
|
9 | 9 | export interface SimplifiedLayout { |
10 | 10 | mode: "none" | "row" | "column"; |
@@ -208,17 +208,17 @@ function buildSimplifiedLayoutValues( |
208 | 208 |
|
209 | 209 | // Only include positioning-related properties if parent layout isn't flex or if the node is absolute |
210 | 210 | if ( |
211 | | - isFrame(parent) && |
212 | 211 | // If parent is a frame but not an AutoLayout, or if the node is absolute, include positioning-related properties |
213 | | - (!parent.layoutMode || parent.layoutMode === "NONE" || n.layoutPositioning === "ABSOLUTE") |
| 212 | + isFrame(parent) && |
| 213 | + !isInAutoLayoutFlow(n, parent) |
214 | 214 | ) { |
215 | 215 | if (n.layoutPositioning === "ABSOLUTE") { |
216 | 216 | layoutValues.position = "absolute"; |
217 | 217 | } |
218 | 218 | if (n.absoluteBoundingBox && parent.absoluteBoundingBox) { |
219 | 219 | layoutValues.locationRelativeToParent = { |
220 | | - x: n.absoluteBoundingBox.x - parent.absoluteBoundingBox.x, |
221 | | - y: n.absoluteBoundingBox.y - parent.absoluteBoundingBox.y, |
| 220 | + x: pixelRound(n.absoluteBoundingBox.x - parent.absoluteBoundingBox.x), |
| 221 | + y: pixelRound(n.absoluteBoundingBox.y - parent.absoluteBoundingBox.y), |
222 | 222 | }; |
223 | 223 | } |
224 | 224 | } |
@@ -255,6 +255,12 @@ function buildSimplifiedLayoutValues( |
255 | 255 | } |
256 | 256 |
|
257 | 257 | if (Object.keys(dimensions).length > 0) { |
| 258 | + if (dimensions.width) { |
| 259 | + dimensions.width = pixelRound(dimensions.width); |
| 260 | + } |
| 261 | + if (dimensions.height) { |
| 262 | + dimensions.height = pixelRound(dimensions.height); |
| 263 | + } |
258 | 264 | layoutValues.dimensions = dimensions; |
259 | 265 | } |
260 | 266 | } |
|
0 commit comments