Skip to content

Commit

Permalink
Fix figma plugin build
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchas116 committed Apr 27, 2023
1 parent 8f8bbe1 commit 4753ebb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/figma/package.json
Expand Up @@ -5,7 +5,7 @@
"description": "Figma plugin for UIMix",
"license": "MIT",
"scripts": {
"build": "npm run build:ui && npm run build:main",
"build": "npm run tsc && npm run build:ui && npm run build:main",
"build:main": "esbuild plugin-src/code.ts --target=es6 --bundle --outfile=dist/code.js",
"build:ui": "npx vite build --minify esbuild --emptyOutDir=false",
"build:watch": "concurrently -n widget,iframe \"npm run build:main -- --watch\" \"npm run build:ui -- --watch\"",
Expand Down
4 changes: 2 additions & 2 deletions packages/figma/plugin-src/toUIMix/node.ts
Expand Up @@ -75,8 +75,8 @@ async function figmaToMacaron(
name: node.name,
style: {
...getSVGStyle(node, parentLayout, offset),
width: { type: "hug" },
height: { type: "hug" },
width: "hug",
height: "hug",
svgContent: svgText,
},
children: [],
Expand Down
45 changes: 22 additions & 23 deletions packages/figma/plugin-src/toUIMix/style.ts
Expand Up @@ -13,37 +13,37 @@ function getPositionStylePartial(
// TODO: more constraints
if (parentLayout === "NONE") {
style.position = {
x: { type: "start", start: node.x - offset[0] },
y: { type: "start", start: node.y - offset[1] },
left: node.x - offset[0],
top: node.y - offset[1],
};
}
style.width = { type: "fixed", value: node.width };
style.height = { type: "fixed", value: node.height };
style.width = node.width;
style.height = node.height;

if (parentLayout === "VERTICAL") {
if (node.layoutGrow) {
style.height = { type: "fill" };
style.height = { min: 0 };
}
if (node.layoutAlign === "STRETCH") {
style.width = { type: "fill" };
style.width = { min: 0 };
}
} else if (parentLayout === "HORIZONTAL") {
if (node.layoutGrow) {
style.width = { type: "fill" };
style.width = { min: 0 };
}
if (node.layoutAlign === "STRETCH") {
style.height = { type: "fill" };
style.height = { min: 0 };
}
}

if (node.type === "TEXT") {
switch (node.textAutoResize) {
case "WIDTH_AND_HEIGHT":
style.width = { type: "hug" };
style.height = { type: "hug" };
style.width = "hug";
style.height = "hug";
break;
case "HEIGHT":
style.height = { type: "hug" };
style.height = "hug";
break;
case "NONE":
break;
Expand All @@ -68,8 +68,7 @@ async function paintToUIMix(paint: Paint): Promise<Data.SolidFill | undefined> {
switch (paint.type) {
case "SOLID":
return {
type: "solid",
color: rgbaToHex({ ...paint.color, a: paint.opacity }),
solid: rgbaToHex({ ...paint.color, a: paint.opacity }),
};
/* TODO
case "GRADIENT_LINEAR": {
Expand Down Expand Up @@ -158,7 +157,7 @@ async function getFillBorderStylePartial(
}
if (node.strokes.length) {
const border = await paintToUIMix(node.strokes[0]);
if (border?.type === "solid") {
if (border?.solid) {
style.border = border;
}
style.borderTopWidth = node.strokeTopWeight;
Expand Down Expand Up @@ -226,15 +225,15 @@ async function getTextStylePartial(
if (node.lineHeight.unit === "AUTO") {
style.lineHeight = null;
} else if (node.lineHeight.unit === "PERCENT") {
style.lineHeight = [node.lineHeight.value, "%"];
style.lineHeight = `${node.lineHeight.value}%`;
} else {
style.lineHeight = node.lineHeight.value;
}
}

if (node.letterSpacing !== figma.mixed) {
if (node.letterSpacing.unit === "PERCENT") {
style.letterSpacing = [node.letterSpacing.value, "%"];
style.letterSpacing = `${node.letterSpacing.value}%`;
} else {
style.letterSpacing = node.letterSpacing.value;
}
Expand Down Expand Up @@ -279,11 +278,11 @@ async function getTextStylePartial(
case "NONE":
break;
case "HEIGHT":
style.height = { type: "hug" };
style.height = "hug";
break;
case "WIDTH_AND_HEIGHT":
style.width = { type: "hug" };
style.height = { type: "hug" };
style.width = "hug";
style.height = "hug";
break;
}

Expand Down Expand Up @@ -368,17 +367,17 @@ function getLayoutStylePartial(

if (node.layoutMode === "VERTICAL") {
if (node.primaryAxisSizingMode == "AUTO") {
style.height = { type: "hug" };
style.height = "hug";
}
if (node.counterAxisSizingMode == "AUTO") {
style.width = { type: "hug" };
style.width = "hug";
}
} else {
if (node.primaryAxisSizingMode == "AUTO") {
style.width = { type: "hug" };
style.width = "hug";
}
if (node.counterAxisSizingMode == "AUTO") {
style.height = { type: "hug" };
style.height = "hug";
}
}

Expand Down

2 comments on commit 4753ebb

@vercel
Copy link

@vercel vercel bot commented on 4753ebb Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 4753ebb Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.