 : gadget>word ( gadget -- word )
     [ ] [ pref-dim first ] [ word-break? ] tri <word> ;
 
-TUPLE: line words height ;
+TUPLE: line words height baseline ;
 
 : <line> ( words -- line )
-    dup [ key>> ] map dup pref-dims measure-height line boa ;
+    dup [ key>> ] map dup pref-dims
+    [ measure-height ] [ measure-metrics drop ] 2bi line boa ;
 
 : wrap-paragraph ( paragraph -- wrapped-paragraph )
     [ children>> [ gadget>word ] map ] [ margin>> ] bi
     dup wrap-words [ <line> ] map ;
+
+M: paragraph children<<
+    [ call-next-method ] [ [ wrap-paragraph ] keep wrapped<< ] bi ;
 
 : line-width ( wrapped-line -- n )
     [ break?>> ] trim-tail-slice [ width>> ] map-sum ;

    ] dip '[ _ + layout-word ] 3each ;

M: paragraph layout*
    wrap-paragraph dup line-y-coordinates
    [ layout-line ] 2each ;

M: paragraph baseline
    wrap-paragraph [ f ] [
        first words>>
        [ key>> ] map
        dup [ pref-dim ] map
        measure-metrics drop
    ] if-empty ;

M: paragraph cap-height pack-cap-height ;
    
PRIVATE>

    [ height>> ] map-sum ;

M: paragraph pref-dim*
    wrapped>> [ max-line-width ] [ sum-line-heights ] bi 2array ;

: line-y-coordinates ( wrapped-paragraph -- ys )
    0 [ height>> + ] accumulate nip ;
