MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / getRoundedRectPath

Function getRoundedRectPath

src/tools/shape-magic/svgRenderers.js:65–88  ·  view source on GitHub ↗
(x, y, w, h, corners)

Source from the content-addressed store, hash-verified

63};
64
65export const getRoundedRectPath = (x, y, w, h, corners) => {
66 const { tl, tr, br, bl } = corners;
67
68 const maxR = Math.min(w / 2, h / 2);
69 const rtl = Math.min(tl, maxR);
70 const rtr = Math.min(tr, maxR);
71 const rbr = Math.min(br, maxR);
72 const rbl = Math.min(bl, maxR);
73
74 return `
75 M ${x + rtl} ${y}
76 L ${x + w - rtr} ${y}
77 ${rtr > 0 ? `A ${rtr} ${rtr} 0 0 1 ${x + w} ${y + rtr}` : `L ${x + w} ${y}`}
78 L ${x + w} ${y + h - rbr}
79 ${rbr > 0 ? `A ${rbr} ${rbr} 0 0 1 ${x + w - rbr} ${y + h}` : `L ${x + w} ${y + h}`}
80 L ${x + bl} ${y + h}
81 ${rbl > 0 ? `A ${rbl} ${rbl} 0 0 1 ${x} ${y + h - rbl}` : `L ${x} ${y + h}`}
82 L ${x} ${y + rtl}
83 ${rtl > 0 ? `A ${rtl} ${rtl} 0 0 1 ${x + rtl} ${y}` : `L ${x} ${y}`}
84 Z
85 `
86 .trim()
87 .replace(/\s+/g, ' ');
88};
89
90const cornersFor = (cornerRadii, id, globalRadius) =>
91 cornerRadii[id] || { tl: globalRadius, tr: globalRadius, br: globalRadius, bl: globalRadius };

Callers 5

Canvas.jsxFile · 0.90
PresetTileFunction · 0.90
generateMergedSVGFunction · 0.85
generateCSSClipPathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected