Skip to content

Commit bfa2da4

Browse files
committed
No more optimize layout
1 parent 80a2f65 commit bfa2da4

18 files changed

Lines changed: 61 additions & 181 deletions

File tree

apps/plugin/plugin-src/code.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ let userPluginSettings: PluginSettings;
1919

2020
export const defaultPluginSettings: PluginSettings = {
2121
framework: "HTML",
22-
optimizeLayout: true,
2322
showLayerNames: false,
2423
useOldPluginVersion2025: false,
2524
responsiveRoot: false,

packages/backend/src/code.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,12 @@ function adjustChildrenOrder(node: any) {
163163
*/
164164
const processNodePair = async (
165165
jsonNode: any,
166+
figmaNode: SceneNode,
166167
settings: PluginSettings,
167168
parentNode?: any,
168169
) => {
169170
if (!jsonNode.id) return;
170171

171-
const figmaNode = await figma.getNodeByIdAsync(jsonNode.id);
172-
173-
if (!figmaNode) {
174-
return;
175-
}
176-
177172
// Set parent reference if parent is provided
178173
if (parentNode) {
179174
jsonNode.parent = parentNode;
@@ -357,7 +352,12 @@ const processNodePair = async (
357352
// );
358353

359354
for (let i = 0; i < jsonNode.children.length; i++) {
360-
await processNodePair(jsonNode.children[i], settings, jsonNode);
355+
await processNodePair(
356+
jsonNode.children[i],
357+
figmaNode.children[i],
358+
settings,
359+
jsonNode,
360+
);
361361
}
362362

363363
if (
@@ -409,7 +409,7 @@ export const nodesToJSON = async (
409409
// Now process each top-level node pair (JSON node + Figma node)
410410
const processNodesStart = Date.now();
411411
for (let i = 0; i < nodes.length; i++) {
412-
await processNodePair(nodeJson[i], settings);
412+
await processNodePair(nodeJson[i], nodes[i], settings);
413413
}
414414
console.log(
415415
`[benchmark][inside nodesToJSON] Process node pairs: ${Date.now() - processNodesStart}ms`,

packages/backend/src/common/commonChildrenOrder.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/backend/src/common/commonPosition.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ export const getCommonPositionValue = (
1414
};
1515
};
1616

17-
export const commonIsAbsolutePosition = (
18-
node: SceneNode,
19-
optimizeLayout: boolean,
20-
) => {
17+
export const commonIsAbsolutePosition = (node: SceneNode) => {
2118
if ("layoutPositioning" in node && node.layoutPositioning === "ABSOLUTE") {
2219
return true;
2320
}

packages/backend/src/flutter/builderImpl/flutterSize.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ import { numberToFixedString } from "../../common/numToAutoFixed";
33

44
// Used in tests.
55
export const flutterSizeWH = (node: SceneNode): string => {
6-
const fSize = flutterSize(node, false);
6+
const fSize = flutterSize(node);
77
const size = fSize.width + fSize.height;
88
return size;
99
};
1010

1111
export const flutterSize = (
1212
node: SceneNode,
13-
optimizeLayout: boolean,
14-
): { width: string; height: string; isExpanded: boolean; constraints: Record<string, string> } => {
13+
): {
14+
width: string;
15+
height: string;
16+
isExpanded: boolean;
17+
constraints: Record<string, string>;
18+
} => {
1519
const size = nodeSize(node);
1620
let isExpanded: boolean = false;
1721

18-
const nodeParent =
19-
(node.parent && optimizeLayout && "inferredAutoLayout" in node.parent
20-
? node.parent.inferredAutoLayout
21-
: null) ?? node.parent;
22+
const nodeParent = node.parent;
2223

2324
// this cast will always be true, since nodeWidthHeight was called with false to relative.
2425
let propWidth = "";
@@ -55,19 +56,19 @@ export const flutterSize = (
5556

5657
// Handle min/max constraints
5758
const constraints: Record<string, string> = {};
58-
59+
5960
if (node.minWidth !== undefined && node.minWidth !== null) {
6061
constraints.minWidth = numberToFixedString(node.minWidth);
6162
}
62-
63+
6364
if (node.maxWidth !== undefined && node.maxWidth !== null) {
6465
constraints.maxWidth = numberToFixedString(node.maxWidth);
6566
}
66-
67+
6768
if (node.minHeight !== undefined && node.minHeight !== null) {
6869
constraints.minHeight = numberToFixedString(node.minHeight);
6970
}
70-
71+
7172
if (node.maxHeight !== undefined && node.maxHeight !== null) {
7273
constraints.maxHeight = numberToFixedString(node.maxHeight);
7374
}

packages/backend/src/flutter/flutterContainer.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import { numberToFixedString } from "../common/numToAutoFixed";
1414
import { getCommonRadius } from "../common/commonRadius";
1515
import { commonStroke } from "../common/commonStroke";
1616

17-
export const flutterContainer = (
18-
node: SceneNode,
19-
child: string,
20-
optimizeLayout: boolean,
21-
): string => {
17+
export const flutterContainer = (node: SceneNode, child: string): string => {
2218
// ignore the view when size is zero or less
2319
// while technically it shouldn't get less than 0, due to rounding errors,
2420
// it can get to values like: -0.000004196293048153166
@@ -28,10 +24,7 @@ export const flutterContainer = (
2824

2925
// ignore for Groups
3026
const propBoxDecoration = getDecoration(node);
31-
const { width, height, isExpanded, constraints } = flutterSize(
32-
node,
33-
optimizeLayout,
34-
);
27+
const { width, height, isExpanded, constraints } = flutterSize(node);
3528

3629
const clipBehavior =
3730
"clipsContent" in node && node.clipsContent === true
@@ -43,9 +36,7 @@ export const flutterContainer = (
4336
// [propPadding] will be "padding: const EdgeInsets.symmetric(...)" or ""
4437
let propPadding = "";
4538
if ("paddingLeft" in node) {
46-
propPadding = flutterPadding(
47-
(optimizeLayout ? node.inferredAutoLayout : null) ?? node,
48-
);
39+
propPadding = flutterPadding(node);
4940
}
5041

5142
let result: string;

packages/backend/src/flutter/flutterDefaultBuilder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export class FlutterDefaultBuilder {
1818
this.child = optChild;
1919
}
2020

21-
createContainer(node: SceneNode, optimizeLayout: boolean): this {
22-
this.child = flutterContainer(node, this.child, optimizeLayout);
21+
createContainer(node: SceneNode): this {
22+
this.child = flutterContainer(node, this.child);
2323
return this;
2424
}
2525

@@ -34,8 +34,8 @@ export class FlutterDefaultBuilder {
3434
return this;
3535
}
3636

37-
position(node: SceneNode, optimizeLayout: boolean): this {
38-
if (commonIsAbsolutePosition(node, optimizeLayout)) {
37+
position(node: SceneNode): this {
38+
if (commonIsAbsolutePosition(node)) {
3939
const { x, y } = getCommonPositionValue(node);
4040
this.child = generateWidgetCode("Positioned", {
4141
left: x,

packages/backend/src/flutter/flutterMain.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
getCrossAxisAlignment,
1212
getMainAxisAlignment,
1313
} from "./builderImpl/flutterAutoLayout";
14-
import { commonSortChildrenWhenInferredAutoLayout } from "../common/commonChildrenOrder";
1514
import { PluginSettings } from "types";
1615
import { addWarning } from "../common/commonConversionWarnings";
1716
import { getPlaceholderImage } from "../common/images";
@@ -152,9 +151,9 @@ const flutterContainer = (node: SceneNode, child: string): string => {
152151
}
153152

154153
const builder = new FlutterDefaultBuilder(propChild)
155-
.createContainer(node, localSettings.optimizeLayout)
154+
.createContainer(node)
156155
.blendAttr(node)
157-
.position(node, localSettings.optimizeLayout);
156+
.position(node);
158157

159158
return builder.child;
160159
};
@@ -163,24 +162,15 @@ const flutterText = (node: TextNode): string => {
163162
const builder = new FlutterTextBuilder().createText(node);
164163
previousExecutionCache.push(builder.child);
165164

166-
return builder
167-
.blendAttr(node)
168-
.textAutoSize(node)
169-
.position(node, localSettings.optimizeLayout).child;
165+
return builder.blendAttr(node).textAutoSize(node).position(node).child;
170166
};
171167

172168
const flutterFrame = (
173169
node: SceneNode & BaseFrameMixin & MinimalBlendMixin,
174170
): string => {
175-
// Sort children according to layout direction
176-
const sortedChildren = commonSortChildrenWhenInferredAutoLayout(
177-
node,
178-
localSettings.optimizeLayout,
179-
);
180-
181171
// Check if any direct children need absolute positioning
182-
const hasAbsoluteChildren = sortedChildren.some(
183-
(child) => (child as any).layoutPositioning === "ABSOLUTE",
172+
const hasAbsoluteChildren = node.children.some(
173+
(child: any) => (child as any).layoutPositioning === "ABSOLUTE",
184174
);
185175

186176
// Add warning if we need to use Stack due to absolute positioning
@@ -209,7 +199,7 @@ const flutterFrame = (
209199
const rowColumn = makeRowColumn(node, children);
210200
return flutterContainer(node, rowColumn);
211201
} else {
212-
if (localSettings.optimizeLayout && node.inferredAutoLayout) {
202+
if (node.inferredAutoLayout) {
213203
const rowColumn = makeRowColumn(node.inferredAutoLayout, children);
214204
return flutterContainer(node, rowColumn);
215205
}

packages/backend/src/html/builderImpl/htmlSize.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { isPreviewGlobal } from "../htmlMain";
55
export const htmlSizePartial = (
66
node: SceneNode,
77
isJsx: boolean,
8-
optimizeLayout: boolean,
98
): { width: string; height: string; constraints: string[] } => {
109
if (isPreviewGlobal && node.parent === undefined) {
1110
return {
@@ -16,10 +15,7 @@ export const htmlSizePartial = (
1615
}
1716

1817
const size = nodeSize(node);
19-
const nodeParent =
20-
(node.parent && optimizeLayout && "inferredAutoLayout" in node.parent
21-
? node.parent.inferredAutoLayout
22-
: null) ?? node.parent;
18+
const nodeParent = node.parent;
2319

2420
let w = "";
2521
if (typeof size.width === "number") {

packages/backend/src/html/htmlDefaultBuilder.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ export class HtmlDefaultBuilder {
5858
return this.settings.htmlGenerationMode === "jsx";
5959
}
6060

61-
get optimizeLayout() {
62-
return this.settings.optimizeLayout;
63-
}
64-
6561
get exportCSS() {
6662
return this.settings.htmlGenerationMode === "svelte";
6763
}
@@ -260,8 +256,8 @@ export class HtmlDefaultBuilder {
260256
}
261257

262258
position(): this {
263-
const { node, optimizeLayout, isJSX } = this;
264-
const isAbsolutePosition = commonIsAbsolutePosition(node, optimizeLayout);
259+
const { node, isJSX } = this;
260+
const isAbsolutePosition = commonIsAbsolutePosition(node);
265261
if (isAbsolutePosition) {
266262
const { x, y } = getCommonPositionValue(node);
267263

@@ -273,10 +269,7 @@ export class HtmlDefaultBuilder {
273269
} else {
274270
if (
275271
node.type === "GROUP" ||
276-
("layoutMode" in node &&
277-
((optimizeLayout ? node.inferredAutoLayout : null) ?? node)
278-
?.layoutMode === "NONE") ||
279-
(node as any).isRelative
272+
("layoutMode" in node && (node as any).isRelative)
280273
) {
281274
this.addStyles(formatWithJSX("position", isJSX, "relative"));
282275
}
@@ -356,7 +349,6 @@ export class HtmlDefaultBuilder {
356349
const { width, height, constraints } = htmlSizePartial(
357350
node,
358351
settings.htmlGenerationMode === "jsx",
359-
settings.optimizeLayout,
360352
);
361353

362354
if (node.type === "TEXT") {
@@ -384,14 +376,9 @@ export class HtmlDefaultBuilder {
384376
}
385377

386378
autoLayoutPadding(): this {
387-
const { node, isJSX, optimizeLayout } = this;
379+
const { node, isJSX } = this;
388380
if ("paddingLeft" in node) {
389-
this.addStyles(
390-
...htmlPadding(
391-
(optimizeLayout ? (node as any).inferredAutoLayout : null) ?? node,
392-
isJSX,
393-
),
394-
);
381+
this.addStyles(...htmlPadding(node, isJSX));
395382
}
396383
return this;
397384
}

0 commit comments

Comments
 (0)