Skip to content

Commit 5bbb116

Browse files
committed
fix: handle edge cases
1 parent e6ec53e commit 5bbb116

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/block-components/image/get-shape-css.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ export const getShapeCSS = ( shape, shapeFlipX, shapeFlipY, shapeStretch ) => {
4040
const scaleY = shapeFlipY ? -1 : 1
4141

4242
// Extract viewBox to compute translate offset
43-
const viewBoxMatch = svgString.match( /viewBox="([^"]+)"/ )
44-
const [ _minX, _minY, width, height ] = viewBoxMatch
45-
? viewBoxMatch[ 1 ].split( ' ' ).map( Number )
46-
: [ 0, 0, 100, 100 ]
43+
const viewBoxMatch = svgString.match( /viewBox=["']([^"']+)["']/ )
44+
const [ minX, minY, width, height ] = viewBoxMatch
45+
? viewBoxMatch[ 1 ].trim().split( /[\s,]+/ ).map( Number ) : [ 0, 0, 100, 100 ]
4746

48-
const translateX = shapeFlipX ? width : 0
49-
const translateY = shapeFlipY ? height : 0
47+
const translateX = shapeFlipX ? width + ( 2 * minX ) : 0
48+
const translateY = shapeFlipY ? height + ( 2 * minY ) : 0
5049

5150
// SVG transform are applied right to left
5251
// Scale first (flip) and translate (reposition to view)

0 commit comments

Comments
 (0)