MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / getCommonRadius

Function getCommonRadius

packages/backend/src/common/commonRadius.ts:3–49  ·  view source on GitHub ↗
(node: SceneNode)

Source from the content-addressed store, hash-verified

1import { CornerRadius } from "types";
2
3export const getCommonRadius = (node: SceneNode): CornerRadius => {
4 if ("rectangleCornerRadii" in node) {
5 const [topLeft, topRight, bottomRight, bottomLeft] =
6 node.rectangleCornerRadii as any;
7 if (
8 topLeft === topRight &&
9 topLeft === bottomRight &&
10 topLeft === bottomLeft
11 ) {
12 return { all: topLeft };
13 }
14
15 return {
16 topLeft,
17 topRight,
18 bottomRight,
19 bottomLeft,
20 };
21 }
22
23 if (
24 "cornerRadius" in node &&
25 node.cornerRadius !== figma.mixed &&
26 node.cornerRadius
27 ) {
28 return { all: node.cornerRadius };
29 }
30
31 if ("topLeftRadius" in node) {
32 if (
33 node.topLeftRadius === node.topRightRadius &&
34 node.topLeftRadius === node.bottomRightRadius &&
35 node.topLeftRadius === node.bottomLeftRadius
36 ) {
37 return { all: node.topLeftRadius };
38 }
39
40 return {
41 topLeft: node.topLeftRadius,
42 topRight: node.topRightRadius,
43 bottomRight: node.bottomRightRadius,
44 bottomLeft: node.bottomLeftRadius,
45 };
46 }
47
48 return { all: 0 };
49};

Callers 5

generateBorderRadiusFunction · 0.90
tailwindBorderRadiusFunction · 0.90
htmlBorderRadiusFunction · 0.90
swiftuiCornerRadiusFunction · 0.90
composeContainerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected