@@ -104,6 +104,7 @@ export const SPACE: StringMap = {
104104 * Padding and border data from the style attribute
105105 */
106106export type StyleData = {
107+ margin : [ number , number , number , number ] ;
107108 padding : [ number , number , number , number ] ;
108109 border : {
109110 width : [ number , number , number , number ] ;
@@ -596,9 +597,10 @@ export class CommonWrapper<
596597 if ( ! this . styleData ) return bbox ;
597598 const padding = this . styleData . padding ;
598599 const border = this . styleData . border ?. width || [ 0 , 0 , 0 , 0 ] ;
600+ const margin = this . styleData . margin || [ 0 , 0 , 0 , 0 ] ;
599601 const obox = bbox . copy ( ) ;
600602 for ( const [ , i , side ] of BBox . boxSides ) {
601- ( obox as any ) [ side ] += padding [ i ] + border [ i ] ;
603+ ( obox as any ) [ side ] += padding [ i ] + border [ i ] + margin [ i ] ;
602604 }
603605 return obox ;
604606 }
@@ -748,7 +750,9 @@ export class CommonWrapper<
748750 if ( ! this . styleData ) return ;
749751 const border = this . styleData . border ;
750752 const padding = this . styleData . padding ;
751- bbox . w += ( border ?. width ?. [ 3 ] || 0 ) + ( padding ?. [ 3 ] || 0 ) ;
753+ const margin = this . styleData . margin ;
754+ bbox . w +=
755+ ( border ?. width ?. [ 3 ] || 0 ) + ( padding ?. [ 3 ] || 0 ) + ( margin ?. [ 3 ] || 0 ) ;
752756 }
753757
754758 /**
@@ -758,8 +762,11 @@ export class CommonWrapper<
758762 if ( ! this . styleData ) return ;
759763 const border = this . styleData . border ;
760764 const padding = this . styleData . padding ;
761- bbox . h += ( border ?. width ?. [ 0 ] || 0 ) + ( padding ?. [ 0 ] || 0 ) ;
762- bbox . d += ( border ?. width ?. [ 2 ] || 0 ) + ( padding ?. [ 2 ] || 0 ) ;
765+ const margin = this . styleData . margin ;
766+ bbox . h +=
767+ ( border ?. width ?. [ 0 ] || 0 ) + ( padding ?. [ 0 ] || 0 ) + ( margin ?. [ 0 ] || 0 ) ;
768+ bbox . d +=
769+ ( border ?. width ?. [ 2 ] || 0 ) + ( padding ?. [ 2 ] || 0 ) + ( margin ?. [ 2 ] || 0 ) ;
763770 }
764771
765772 /**
@@ -769,7 +776,9 @@ export class CommonWrapper<
769776 if ( ! this . styleData ) return ;
770777 const border = this . styleData . border ;
771778 const padding = this . styleData . padding ;
772- bbox . w += ( border ?. width ?. [ 1 ] || 0 ) + ( padding ?. [ 1 ] || 0 ) ;
779+ const margin = this . styleData . margin ;
780+ bbox . w +=
781+ ( border ?. width ?. [ 1 ] || 0 ) + ( padding ?. [ 1 ] || 0 ) + ( margin ?. [ 1 ] || 0 ) ;
773782 }
774783
775784 /**
@@ -875,11 +884,13 @@ export class CommonWrapper<
875884 protected getStyleData ( ) {
876885 if ( ! this . styles ) return ;
877886 const padding = Array ( 4 ) . fill ( 0 ) ;
887+ const margin = Array ( 4 ) . fill ( 0 ) ;
878888 const width = Array ( 4 ) . fill ( 0 ) ;
879889 const style = Array ( 4 ) ;
880890 const color = Array ( 4 ) ;
881891 let hasPadding = false ;
882892 let hasBorder = false ;
893+ let hasMargin = false ;
883894 for ( const [ name , i ] of BBox . boxSides ) {
884895 const key = 'border' + name ;
885896 const w = this . styles . get ( key + 'Width' ) ;
@@ -894,11 +905,17 @@ export class CommonWrapper<
894905 hasPadding = true ;
895906 padding [ i ] = Math . max ( 0 , this . length2em ( p , 1 ) ) ;
896907 }
908+ const m = this . styles . get ( 'margin' + name ) ;
909+ if ( m ) {
910+ hasMargin = true ;
911+ margin [ i ] = this . length2em ( m , 1 ) ;
912+ }
897913 }
898914 this . styleData =
899- hasPadding || hasBorder
915+ hasPadding || hasBorder || hasMargin
900916 ? ( {
901917 padding,
918+ margin,
902919 border : hasBorder ? { width, style, color } : null ,
903920 } as StyleData )
904921 : null ;
0 commit comments