@@ -91,12 +91,15 @@ function shouldKeepForeignObjectWidth(style: CSSStyleDeclaration): boolean {
9191 const whiteSpace = style . whiteSpace ;
9292 const flexWrap = style . flexWrap ;
9393 const wordBreak = style . wordBreak ;
94+ const overflowWrap = style . overflowWrap ;
9495
9596 return (
9697 flexWrap === 'wrap' ||
9798 flexWrap === 'wrap-reverse' ||
9899 whiteSpace === 'pre-wrap' ||
100+ whiteSpace === 'pre-line' ||
99101 whiteSpace === 'normal' ||
102+ overflowWrap === 'break-word' ||
100103 wordBreak === 'break-word' ||
101104 wordBreak === 'break-all'
102105 ) ;
@@ -203,27 +206,25 @@ function collectForeignObjectExportAdjustments(svg: SVGSVGElement) {
203206
204207 return Array . from (
205208 svg . querySelectorAll < SVGForeignObjectElement > ( 'foreignObject' ) ,
206- ) . flatMap ( ( fo ) => {
209+ ) . map ( ( fo ) => {
207210 const content = fo . firstElementChild as HTMLElement | null ;
208- if ( ! content ) return [ ] ;
211+ if ( ! content ) return null ;
209212
210213 const parent =
211214 fo . parentElement instanceof SVGGraphicsElement ? fo . parentElement : svg ;
212215 const toParentCoord = createCoordConverter ( svg , parent ) ;
213- if ( ! toParentCoord ) return [ ] ;
214-
215- return [
216- {
217- rootBounds : getFOContentBoundsInSVG ( fo , content , toSVGCoord ) ,
218- localBounds : getFOContentBoundsInSVG ( fo , content , toParentCoord ) ,
219- } satisfies ForeignObjectExportAdjustment ,
220- ] ;
216+ if ( ! toParentCoord ) return null ;
217+
218+ return {
219+ rootBounds : getFOContentBoundsInSVG ( fo , content , toSVGCoord ) ,
220+ localBounds : getFOContentBoundsInSVG ( fo , content , toParentCoord ) ,
221+ } satisfies ForeignObjectExportAdjustment ;
221222 } ) ;
222223}
223224
224225function computeFullViewBox (
225226 svg : SVGSVGElement ,
226- adjustments : ForeignObjectExportAdjustment [ ] ,
227+ adjustments : Array < ForeignObjectExportAdjustment | null > ,
227228) : string | null {
228229 const viewBox = getExportViewBox ( svg ) ;
229230 if ( ! viewBox ) return null ;
@@ -233,7 +234,9 @@ function computeFullViewBox(
233234 let maxX = viewBox . x + viewBox . width ;
234235 let maxY = viewBox . y + viewBox . height ;
235236
236- adjustments . forEach ( ( { rootBounds } ) => {
237+ adjustments . forEach ( ( adjustment ) => {
238+ if ( ! adjustment ) return ;
239+ const { rootBounds } = adjustment ;
237240 const [ left , top , right , bottom ] = rootBounds ;
238241 minX = Math . min ( minX , left ) ;
239242 minY = Math . min ( minY , top ) ;
@@ -258,13 +261,14 @@ function computeFullViewBox(
258261
259262function applyForeignObjectExportAdjustments (
260263 svg : SVGSVGElement ,
261- adjustments : ForeignObjectExportAdjustment [ ] ,
264+ adjustments : Array < ForeignObjectExportAdjustment | null > ,
262265) {
263266 const clonedForeignObjects = Array . from (
264267 svg . querySelectorAll < SVGForeignObjectElement > ( 'foreignObject' ) ,
265268 ) ;
266269
267270 adjustments . forEach ( ( adjustment , index ) => {
271+ if ( ! adjustment ) return ;
268272 const clonedForeignObject = clonedForeignObjects [ index ] ;
269273 if ( ! clonedForeignObject ) return ;
270274
0 commit comments