( shapes, bridges, cornerRadii, style, globalRadius, smoothing = 0.6, name = 'MergedShape' )
| 478 | }; |
| 479 | |
| 480 | export const generateReactComponent = ( |
| 481 | shapes, |
| 482 | bridges, |
| 483 | cornerRadii, |
| 484 | style, |
| 485 | globalRadius, |
| 486 | smoothing = 0.6, |
| 487 | name = 'MergedShape' |
| 488 | ) => { |
| 489 | let minX = Infinity, |
| 490 | minY = Infinity, |
| 491 | maxX = -Infinity, |
| 492 | maxY = -Infinity; |
| 493 | shapes.forEach(s => { |
| 494 | minX = Math.min(minX, s.x); |
| 495 | minY = Math.min(minY, s.y); |
| 496 | maxX = Math.max(maxX, s.x + s.w); |
| 497 | maxY = Math.max(maxY, s.y + s.h); |
| 498 | }); |
| 499 | |
| 500 | const width = maxX - minX; |
| 501 | const height = maxY - minY; |
| 502 | |
| 503 | const negativeSpaces = computeNegativeSpaces(shapes, bridges, globalRadius, minX, minY, maxX, maxY); |
| 504 | |
| 505 | const shapeElements = shapes |
| 506 | .map((s, i) => { |
| 507 | const corners = cornersFor(cornerRadii, s.id, globalRadius); |
| 508 | const left = s.x - minX; |
| 509 | const top = s.y - minY; |
| 510 | |
| 511 | return ` {/* Shape ${i + 1} */} |
| 512 | <div |
| 513 | style={{ |
| 514 | position: 'absolute', |
| 515 | left: ${left}, |
| 516 | top: ${top}, |
| 517 | width: ${s.w}, |
| 518 | height: ${s.h}, |
| 519 | backgroundColor: fill, |
| 520 | borderRadius: '${corners.tl}px ${corners.tr}px ${corners.br}px ${corners.bl}px', |
| 521 | }} |
| 522 | > |
| 523 | {/* Add content here */} |
| 524 | </div>`; |
| 525 | }) |
| 526 | .join('\n'); |
| 527 | |
| 528 | const negativeSpaceElements = negativeSpaces |
| 529 | .map((ns, i) => { |
| 530 | const left = ns.x - minX; |
| 531 | const top = ns.y - minY; |
| 532 | |
| 533 | return ` {/* Negative Space ${i + 1} - Content container for empty region */} |
| 534 | <div |
| 535 | style={{ |
| 536 | position: 'absolute', |
| 537 | left: ${left}, |
no test coverage detected