Skip to content

Commit 0321742

Browse files
committed
should properly align text when there is no whitespace with text-wrap: balance
1 parent 1c9e463 commit 0321742

3 files changed

+36
-1
lines changed

src/text.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export default async function* buildTextNodes(
401401
// When doing `text-wrap: balance`, we reflow the text multiple times
402402
// using binary search to find the best width.
403403
// https://www.w3.org/TR/css-text-4/#valdef-text-wrap-balance
404-
if (textWrap === 'balance') {
404+
if (textWrap === 'balance' && content.includes(' ')) {
405405
let l = width / 2
406406
let r = width
407407
let m: number = width

test/text-wrap.test.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,39 @@ describe('text-wrap', () => {
5454

5555
expect(toImage(svg, 100)).toMatchImageSnapshot()
5656
})
57+
58+
it('should properly align text when there is no whitespace with text-wrap: balance', async () => {
59+
const svg = await satori(
60+
<div
61+
style={{
62+
display: 'flex',
63+
flexDirection: 'column',
64+
alignItems: 'center',
65+
width: 100,
66+
height: 100,
67+
fontSize: 18,
68+
color: 'red',
69+
background: 'green',
70+
}}
71+
>
72+
<span
73+
style={{
74+
background: 'blue',
75+
// @ts-ignore: This isn't a valid CSS property supported by browsers yet.
76+
textWrap: 'balance',
77+
}}
78+
>
79+
Playground
80+
</span>
81+
<span style={{ background: 'yellow' }}>Playground</span>
82+
</div>,
83+
{
84+
width: 100,
85+
height: 100,
86+
fonts,
87+
}
88+
)
89+
90+
expect(toImage(svg, 100)).toMatchImageSnapshot()
91+
})
5792
})

0 commit comments

Comments
 (0)