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

Function generateCSSClipPath

src/tools/shape-magic/svgRenderers.js:309–336  ·  view source on GitHub ↗
(shapes, bridges, cornerRadii, globalRadius, smoothing = 0.6)

Source from the content-addressed store, hash-verified

307};
308
309export const generateCSSClipPath = (shapes, bridges, cornerRadii, globalRadius, smoothing = 0.6) => {
310 const padding = 10;
311 const bb = computeShapesBBox(shapes);
312 const width = bb.w + padding * 2;
313 const height = bb.h + padding * 2;
314 const offsetX = -bb.x + padding;
315 const offsetY = -bb.y + padding;
316
317 const allPaths = [];
318
319 shapes.forEach(s => {
320 const corners = cornersFor(cornerRadii, s.id, globalRadius);
321 allPaths.push(getRoundedRectPath(s.x + offsetX, s.y + offsetY, s.w, s.h, corners));
322 });
323
324 bridges.forEach(b => {
325 allPaths.push(getBridgePathAt(b.x + offsetX, b.y + offsetY, b.r, b.rotation, smoothing));
326 });
327
328 const combinedPath = allPaths.join(' ').replace(/\s+/g, ' ').trim();
329
330 return `/* Container dimensions: ${Math.round(width)}px × ${Math.round(height)}px */
331.clipped-element {
332 clip-path: path('${combinedPath}');
333 width: ${Math.round(width)}px;
334 height: ${Math.round(height)}px;
335}`;
336};
337
338const computeNegativeSpaces = (shapes, bridges, globalRadius, minX, minY, maxX, maxY) => {
339 const negativeSpaces = [];

Callers 1

ControlsFunction · 0.90

Calls 4

computeShapesBBoxFunction · 0.85
cornersForFunction · 0.85
getRoundedRectPathFunction · 0.85
getBridgePathAtFunction · 0.85

Tested by

no test coverage detected