Skip to content

Commit f6a5c75

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 42c9513 commit f6a5c75

File tree

11 files changed

+550
-516
lines changed

11 files changed

+550
-516
lines changed

apps/debug/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"react-dom": "^19.1.0"
1818
},
1919
"devDependencies": {
20-
"@tailwindcss/postcss": "^4.1.10",
21-
"@types/node": "^22.15.32",
20+
"@tailwindcss/postcss": "^4.1.11",
21+
"@types/node": "^24.0.4",
2222
"@types/react": "^19.1.8",
2323
"@types/react-dom": "^19.1.6",
2424
"eslint-config-custom": "workspace:*",

apps/plugin/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
"clsx": "^2.1.1",
1616
"copy-to-clipboard": "^3.3.3",
1717
"lucide-react": "^0.483.0",
18-
"motion": "^12.18.1",
18+
"motion": "^12.19.1",
1919
"nanoid": "^5.1.5",
2020
"plugin-ui": "workspace:*",
2121
"react": "^19.1.0",
2222
"react-dom": "^19.1.0",
2323
"tailwind-merge": "^3.3.1"
2424
},
2525
"devDependencies": {
26-
"@tailwindcss/postcss": "^4.1.10",
27-
"@types/node": "^22.15.32",
26+
"@tailwindcss/postcss": "^4.1.11",
27+
"@types/node": "^24.0.4",
2828
"@types/react": "^19.1.8",
2929
"@types/react-dom": "^19.1.6",
30-
"@typescript-eslint/eslint-plugin": "^8.34.1",
31-
"@typescript-eslint/parser": "^8.34.1",
32-
"@vitejs/plugin-react": "^4.5.2",
30+
"@typescript-eslint/eslint-plugin": "^8.35.0",
31+
"@typescript-eslint/parser": "^8.35.0",
32+
"@vitejs/plugin-react": "^4.6.0",
3333
"@vitejs/plugin-react-swc": "^3.10.2",
34-
"concurrently": "^9.1.2",
34+
"concurrently": "^9.2.0",
3535
"esbuild": "^0.25.5",
3636
"eslint-config-custom": "workspace:*",
3737
"eslint-plugin-react-hooks": "^5.2.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"devDependencies": {
1313
"eslint": "^9.29.0",
1414
"eslint-config-custom": "workspace:*",
15-
"prettier": "^3.5.3",
15+
"prettier": "^3.6.2",
1616
"turbo": "^2.5.4",
1717
"typescript": "^5.8.3"
1818
}

packages/backend/src/common/images.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,10 @@ const createCanvasImageUrl = (width: number, height: number): string => {
4848
return URL.createObjectURL(file);
4949
};
5050

51-
export const getPlaceholderImage = (w: number, h = -1, useCanvas = false) => {
51+
export const getPlaceholderImage = (w: number, h = -1) => {
5252
const _w = w.toFixed(0);
5353
const _h = (h < 0 ? w : h).toFixed(0);
5454

55-
console.log("useCanvas", useCanvas);
56-
if (useCanvas) {
57-
return createCanvasImageUrl(parseInt(_w), parseInt(_h));
58-
}
59-
6055
return `${PLACEHOLDER_IMAGE_DOMAIN}/${_w}x${_h}`;
6156
};
6257

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ export const flutterAngularGradient = (fill: GradientPaint): string => {
214214
/**
215215
* Convert opacity (0-1) to alpha (0-255)
216216
*/
217-
const opacityToAlpha = (opacity: number): number => {
218-
return Math.round(opacity * 255);
217+
const opacityToAlpha = (opacity: number) => {
218+
return numberToFixedString(opacity);
219219
};
220220

221221
export const flutterColor = (

packages/backend/src/flutter/flutterMain.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from "./builderImpl/flutterAutoLayout";
1616
import { PluginSettings } from "types";
1717
import { addWarning } from "../common/commonConversionWarnings";
18-
import { getPlaceholderImage } from "../common/images";
1918
import { getVisibleNodes } from "../common/nodeVisibility";
2019

2120
let localSettings: PluginSettings;

packages/backend/src/html/htmlMain.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,7 @@ const htmlContainer = async (
617617
) {
618618
imgUrl = (await exportNodeAsBase64PNG(altNode, hasChildren)) ?? "";
619619
} else {
620-
console.log("isPreviewGlobal", isPreviewGlobal);
621-
imgUrl = getPlaceholderImage(node.width, node.height, isPreviewGlobal);
620+
imgUrl = getPlaceholderImage(node.width, node.height);
622621
console.log("imgUrl", imgUrl);
623622
}
624623

packages/plugin-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"react": "^19.1.0",
2020
"react-syntax-highlighter": "^15.6.1",
2121
"tailwind-merge": "^3.3.1",
22-
"tailwindcss": "^4.1.10"
22+
"tailwindcss": "^4.1.11"
2323
},
2424
"devDependencies": {
2525
"eslint": "^9.29.0",

packages/plugin-ui/src/components/Preview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Ruler,
1010
Monitor,
1111
} from "lucide-react";
12-
import { cn } from "../lib/utils";
12+
import { cn, replaceExternalImagesWithCanvas } from "../lib/utils";
1313

1414
// Update the component props to receive state from parent
1515
const Preview: React.FC<{
@@ -184,7 +184,7 @@ const Preview: React.FC<{
184184
transition: "all 0.3s ease",
185185
}}
186186
dangerouslySetInnerHTML={{
187-
__html: htmlPreview.content,
187+
__html: replaceExternalImagesWithCanvas(htmlPreview.content),
188188
}}
189189
/>
190190
</div>

packages/plugin-ui/src/lib/utils.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,39 @@ import { twMerge } from "tailwind-merge";
44
export function cn(...inputs: ClassValue[]) {
55
return twMerge(clsx(inputs));
66
}
7+
8+
const createCanvasImageUrl = (width: number, height: number): string => {
9+
const canvas = document.createElement("canvas");
10+
canvas.width = width;
11+
canvas.height = height;
12+
13+
const ctx = canvas.getContext("2d");
14+
if (!ctx) {
15+
return `https://placehold.co/${width}x${height}`;
16+
}
17+
18+
ctx.fillStyle = "#f5f5f5";
19+
ctx.fillRect(0, 0, width, height);
20+
21+
const fontSize = Math.max(12, Math.floor(width * 0.15));
22+
ctx.font = `bold ${fontSize}px Inter, Arial, Helvetica, sans-serif`;
23+
ctx.fillStyle = "#888888";
24+
25+
const text = `${width} x ${height}`;
26+
const textWidth = ctx.measureText(text).width;
27+
const x = (width - textWidth) / 2;
28+
const y = (height + fontSize) / 2;
29+
30+
ctx.fillText(text, x, y);
31+
32+
return canvas.toDataURL();
33+
};
34+
35+
export function replaceExternalImagesWithCanvas(html: string): string {
36+
return html.replace(
37+
/https:\/\/placehold\.co\/(\d+)x(\d+)/g,
38+
(_match, width, height) => {
39+
return createCanvasImageUrl(parseInt(width), parseInt(height));
40+
}
41+
);
42+
}

0 commit comments

Comments
 (0)