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

Function generateMergedSVG

src/tools/shape-magic/svgRenderers.js:225–266  ·  view source on GitHub ↗
(shapes, bridges, cornerRadii, style, globalRadius, smoothing = 0.6, opts = {})

Source from the content-addressed store, hash-verified

223};
224
225export const generateMergedSVG = (shapes, bridges, cornerRadii, style, globalRadius, smoothing = 0.6, opts = {}) => {
226 const basePad = 10;
227 const userPad = opts.padding ?? 0;
228 const fxPad = effectPadding(style);
229 const padding = basePad + userPad + fxPad;
230
231 const bb = computeShapesBBox(shapes);
232 const width = bb.w + padding * 2;
233 const height = bb.h + padding * 2;
234 const offsetX = -bb.x + padding;
235 const offsetY = -bb.y + padding;
236
237 const drawnBBox = { x: padding, y: padding, w: bb.w, h: bb.h };
238 const fillSpec = getFillSpec(style, drawnBBox, 'merged');
239 const fxSpec = getFxSpec(style, 'merged');
240
241 const shapePaths = shapes
242 .map(s => {
243 const corners = cornersFor(cornerRadii, s.id, globalRadius);
244 return `<path d="${getRoundedRectPath(s.x + offsetX, s.y + offsetY, s.w, s.h, corners)}" />`;
245 })
246 .join('\n ');
247
248 const bridgePaths = bridges
249 .map(b => {
250 return `<path d="${getBridgePathAt(b.x + offsetX, b.y + offsetY, b.r, b.rotation, smoothing)}" />`;
251 })
252 .join('\n ');
253
254 const defs = `${fillDefsString(fillSpec)}${fxFilterString(fxSpec)}`;
255 const bg =
256 style.backgroundEnabled || opts.forceBackground
257 ? `<rect x="0" y="0" width="${width}" height="${height}" fill="${style.backgroundColor}" />\n `
258 : '';
259
260 return `<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" xmlns="http://www.w3.org/2000/svg">
261 ${defs ? `<defs>${defs}</defs>\n ` : ''}${bg}<g fill="${fillSpec.paint}" fill-opacity="${style.opacity ?? 1}"${fxSpec ? ` filter="url(#${fxSpec.id})"` : ''}>
262 ${shapePaths}
263 ${bridgePaths}
264 </g>
265</svg>`;
266};
267
268export const generateMergedClipPathSVG = (shapes, bridges, cornerRadii, style, globalRadius, smoothing = 0.6) => {
269 const padding = 10;

Callers 1

ControlsFunction · 0.90

Calls 9

effectPaddingFunction · 0.85
computeShapesBBoxFunction · 0.85
getFillSpecFunction · 0.85
getFxSpecFunction · 0.85
cornersForFunction · 0.85
getRoundedRectPathFunction · 0.85
getBridgePathAtFunction · 0.85
fillDefsStringFunction · 0.85
fxFilterStringFunction · 0.85

Tested by

no test coverage detected