(shapes, bridges, cornerRadii, style, globalRadius, smoothing = 0.6)
| 266 | }; |
| 267 | |
| 268 | export const generateMergedClipPathSVG = (shapes, bridges, cornerRadii, style, globalRadius, smoothing = 0.6) => { |
| 269 | const padding = 10; |
| 270 | const bb = computeShapesBBox(shapes); |
| 271 | const width = bb.w + padding * 2; |
| 272 | const height = bb.h + padding * 2; |
| 273 | const offsetX = -bb.x + padding; |
| 274 | const offsetY = -bb.y + padding; |
| 275 | |
| 276 | const allPaths = []; |
| 277 | |
| 278 | shapes.forEach(s => { |
| 279 | const corners = cornersFor(cornerRadii, s.id, globalRadius); |
| 280 | allPaths.push(getRoundedRectPath(s.x + offsetX, s.y + offsetY, s.w, s.h, corners)); |
| 281 | }); |
| 282 | |
| 283 | bridges.forEach(b => { |
| 284 | allPaths.push(getBridgePathAt(b.x + offsetX, b.y + offsetY, b.r, b.rotation, smoothing)); |
| 285 | }); |
| 286 | |
| 287 | const combinedPath = allPaths.join(' '); |
| 288 | const fillSpec = getFillSpec(style, { x: padding, y: padding, w: bb.w, h: bb.h }, 'clip'); |
| 289 | const defs = fillDefsString(fillSpec); |
| 290 | |
| 291 | return `<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" xmlns="http://www.w3.org/2000/svg"> |
| 292 | <defs> |
| 293 | <clipPath id="merged-shape-clip"> |
| 294 | <path d="${combinedPath}" fill-rule="nonzero" /> |
| 295 | </clipPath> |
| 296 | ${defs} |
| 297 | </defs> |
| 298 | |
| 299 | <!-- The merged shape - use as mask for images/videos --> |
| 300 | <path d="${combinedPath}" fill="${fillSpec.paint}" fill-rule="nonzero" /> |
| 301 | |
| 302 | <!-- Example: Clipped content container --> |
| 303 | <!-- <g clip-path="url(#merged-shape-clip)"> |
| 304 | <image href="your-image.jpg" x="0" y="0" width="${width}" height="${height}" preserveAspectRatio="xMidYMid slice" /> |
| 305 | </g> --> |
| 306 | </svg>`; |
| 307 | }; |
| 308 | |
| 309 | export const generateCSSClipPath = (shapes, bridges, cornerRadii, globalRadius, smoothing = 0.6) => { |
| 310 | const padding = 10; |
no test coverage detected