@@ -80,12 +80,12 @@ module Internal.Model exposing
80 , pageClass
80 , pageClass
81 , paragraphClass
81 , paragraphClass
82 , reduceRecursive
82 , reduceRecursive
83− , reduceRecursiveCalcName
84 , reduceStyles
83 , reduceStyles
85 , reduceStylesRecursive
84 , reduceStylesRecursive
86 , removeNever
85 , removeNever
87− , renderFocusStyle
86+ , renderFocusStyle
88− , renderFont
87+ -- , renderFont
89 , renderFontClassName
89 , renderFontClassName
90 , renderHeight
90 , renderHeight
91 , renderRoot
91 , renderRoot
@@ -93,24 +93,15 @@ module Internal.Model exposing
93 , rootStyle
93 , rootStyle
94 , rowClass
94 , rowClass
95 , singleClass
95 , singleClass
98 , spacingName
96 , spacingName
99 , staticRoot
97 , staticRoot
103 , textShadowName
99 , textShadowName
105 , toStyleSheet
101 , toStyleSheet
106− , toStyleSheetString
107 , transformClass
102 , transformClass
110 , unstyled
103 , unstyled
112 , unwrapDecorations
104 , unwrapDecorations
@@ -213,12 +204,26 @@ type PseudoClass
208+type alias Adjustment =
218 | SansSerif
218 | SansSerif
219 | Monospace
219 | Monospace
220 | Typeface String
220 | Typeface String
221 | ImportFont String String
221 | ImportFont String String
224+ , url : Maybe String
225+ , adjustment : Adjustment
224type Property
229type Property
@@ -1490,34 +1495,32 @@ createElement context children rendered =
1490 -- Maybe we could unpack text elements in a paragraph as well,
1495 -- Maybe we could unpack text elements in a paragraph as well,
1491 -- however, embedded elements that are larger than the line height will overlap with exisitng text.
1496 -- however, embedded elements that are larger than the line height will overlap with exisitng text.
1492 -- I don't think that's what we want.
1497 -- I don't think that's what we want.
1494− context
1499+ -- context
1495− == asEl
1500+ -- == asEl
1496− || context
1501+ -- || context
1497− == asParagraph
1502+ -- == asParagraph
1499− ( VirtualDom.text
1504+ -- ( VirtualDom.text
1500− (if context == asParagraph then
1505+ -- (if context == asParagraph then
1506− :: htmls
1510+ -- :: htmls
1507− , existingStyles
1511+ -- , existingStyles
1511− ( textElement
1514+ ( textElement
1512− (if context == asParagraph then
1515+ (if context == asParagraph then
1522 Empty ->
1525 Empty ->
1523 ( htmls, existingStyles )
1526 ( htmls, existingStyles )
@@ -1559,28 +1562,27 @@ createElement context children rendered =
1559 -- TEXT OPTIMIZATION
1562 -- TEXT OPTIMIZATION
1560 -- You can have raw text if the element is an el, and has `width-content` and `height-content`
1563 -- You can have raw text if the element is an el, and has `width-content` and `height-content`
1561 -- Same if it's a column or row with one child and width-content, height-content
1564 -- Same if it's a column or row with one child and width-content, height-content
1563− context
1566+ -- context
1564− == asEl
1567+ -- == asEl
1565− || context
1568+ -- || context
1566− == asParagraph
1569+ -- == asParagraph
1568− ( ( key
1571+ -- ( ( key
1569− , VirtualDom.text
1572+ -- , VirtualDom.text
1572− :: htmls
1575+ -- :: htmls
1573− , existingStyles
1576+ -- , existingStyles
1577− ( ( key
1579+ ( ( key
1578− , textElement
1580+ , textElement
1581− :: htmls
1583+ :: htmls
1582− , existingStyles
1584+ , existingStyles
1585 Empty ->
1587 Empty ->
1586 ( htmls, existingStyles )
1588 ( htmls, existingStyles )
@@ -2051,6 +2053,12 @@ renderFontClassName font current =
2051 |> String.toLower
2053 |> String.toLower
2052 |> String.words
2054 |> String.words
2053 |> String.join "-"
2055 |> String.join "-"
2057+ FontWith { name } ->
@@ -2160,66 +2168,279 @@ optionsToRecord options =
2163−renderFont : List Font -> String
2171+toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
2164−renderFont families =
2172+toStyleSheet options styleSheet =
2173+ VirtualDom.node "style" [] [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2177+-- case typefaceAdjustment typefaces of
2180+-- Just ( parentAdj, textAdjustment ) ->
2187+-- ++ classes.sizeByCapital
2192+-- ++ classes.sizeByCapital
2200+-- ++ classes.sizeByCapital
2202+-- ++ Internal.Style.classes.text
2206+-- ++ classes.sizeByCapital
2208+-- ++ Internal.Style.classes.text
2212+-- renderTopLevels rule =
2214+-- FontFamily name typefaces ->
2216+-- getImports font =
2218+-- ImportFont _ url ->
2219+-- Just ("@import url('" ++ url ++ "');")
2220+-- FontWith { url } ->
2223+-- Just ("@import url('" ++ x ++ "');")
2230+-- |> List.filterMap getImports
2231+-- |> String.join "\n"
2237+renderTopLevelValues rules =
2166− fontName font =
2239+ withImport font =
2167 case font of
2240 case font of
2168− Serif ->
2241+ ImportFont _ url ->
2169− "serif"
2242+ Just ("@import url('" ++ url ++ "');")
2171− SansSerif ->
2244+ FontWith with ->
2172− "sans-serif"
2245+ case with.url of
2247+ Just ("@import url('" ++ x ++ "');")
2174− Monospace ->
2249+ Nothing ->
2175− "monospace"
2250+ Nothing
2177− Typeface name ->
2252+ _ ->
2178− "\"" ++ name ++ "\""
2253+ Nothing
2180− ImportFont name url ->
2255+ allNames =
2181− "\"" ++ name ++ "\""
2256+ List.map Tuple.first rules
2184− |> List.map fontName
2185− |> String.join ", "
2258+ fontImports ( name, typefaces ) =
2261+ String.join "\n" (List.filterMap withImport typefaces)
2188−toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
2265+ fontAdjustments ( name, typefaces ) =
2189−toStyleSheet options styleSheet =
2266+ case typefaceAdjustment typefaces of
2190− VirtualDom.node "style" [] [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2267+ Nothing ->
2269+ (List.map (renderNullAdjustmentRule name) allNames)
2273+ (List.map (renderFontAdjustmentRule name adjustment) allNames)
2275+ String.join "\n" (List.map fontImports rules)
2276+ ++ String.join "\n" (List.map fontAdjustments rules)
2193−toStyleSheetString : OptionRecord -> List Style -> String
2278+
2194−toStyleSheetString options stylesheet =
2279+renderNullAdjustmentRule fontToAdjust otherFontName =
2196− renderTopLevels rule =
2281+ name =
2197− case rule of
2282+ if fontToAdjust == otherFontName then
2198− FontFamily name typefaces ->
2283+ fontToAdjust
2202− ImportFont _ url ->
2203− Just ("@import url('" ++ url ++ "');")
2206− Nothing
2286+ otherFontName ++ " ." ++ fontToAdjust
2209− |> List.filterMap getImports
2210− |> String.join "\n"
2288+ String.join " "
2211− |> Just
2289+ [ bracket
2293+ ++ classes.sizeByCapital
2298+ ++ classes.sizeByCapital
2300+ [ ( "line-height", "1" )
2306+ ++ classes.sizeByCapital
2308+ ++ Internal.Style.classes.text
2312+ ++ classes.sizeByCapital
2314+ ++ Internal.Style.classes.text
2316+ [ ( "vertical-align", "0" )
2317+ , ( "line-height", "1" )
2216− renderProps force (Property key val) existing =
2322+renderFontAdjustmentRule fontToAdjust ( parentAdj, textAdjustment ) otherFontName =
2217− if force then
2323+ let
2218− existing ++ "\n " ++ key ++ ": " ++ val ++ " !important;"
2324+ name =
2325+ if fontToAdjust == otherFontName then
2221− existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
2329+ otherFontName ++ " ." ++ fontToAdjust
2336+ ++ classes.sizeByCapital
2341+ ++ classes.sizeByCapital
2348+ ++ classes.sizeByCapital
2350+ ++ Internal.Style.classes.text
2354+ ++ classes.sizeByCapital
2356+ ++ Internal.Style.classes.text
2362+bracket selector rules =
2364+ renderPair ( name, val ) =
2365+ name ++ ": " ++ val ++ ";"
2367+ selector ++ " {" ++ String.join "" (List.map renderPair rules) ++ "}"
2370+fontAdjustmentRules converted =
2371+ ( [ ( "display", "block" )
2372+ , ( "line-height", String.fromFloat converted.height )
2374+ , [ ( "display", "inline-block" )
2375+ , ( "line-height", String.fromFloat converted.height )
2376+ , ( "vertical-align", String.fromFloat converted.vertical ++ "em" )
2381+typefaceAdjustment typefaces =
2389+ (fontAdjustmentRules
2390+ (.capital (convertAdjustment with.adjustment))
2415+ "\"" ++ name ++ "\""
2417+ ImportFont name url ->
2418+ "\"" ++ name ++ "\""
2420+ FontWith { name } ->
2421+ "\"" ++ name ++ "\""
2424+topLevelValue rule =
2426+ FontFamily name typefaces ->
2427+ Just ( name, typefaces )
2433+renderProps force (Property key val) existing =
2435+ existing ++ "\n " ++ key ++ ": " ++ val ++ " !important;"
2438+ existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
2441+toStyleSheetString : OptionRecord -> List Style -> String
2442+toStyleSheetString options stylesheet =
2223 renderStyle maybePseudo selector props =
2444 renderStyle maybePseudo selector props =
2224 case maybePseudo of
2445 case maybePseudo of
2225 Nothing ->
2446 Nothing ->
@@ -2308,10 +2529,19 @@ toStyleSheetString options stylesheet =
2310 FontFamily name typefaces ->
2531 FontFamily name typefaces ->
2311− renderStyle
2532+ let
2312− maybePseudo
2533+ families =
2314− [ Property "font-family" (renderFont typefaces)
2534+ Property "font-family"
2536+ |> List.map fontName
2537+ |> String.join ", "
2317 Single class prop val ->
2547 Single class prop val ->
@@ -2659,20 +2889,19 @@ toStyleSheetString options stylesheet =
2661 combine style rendered =
2891 combine style rendered =
2663− | rules = rendered.rules ++ renderStyleRule style Nothing
2892+ { rules = rendered.rules ++ renderStyleRule style Nothing
2664− , topLevel =
2893+ , topLevel =
2665− case renderTopLevels style of
2894+ case topLevelValue style of
2666− Nothing ->
2895+ Nothing ->
2667− rendered.topLevel
2896+ rendered.topLevel
2669− Just topLevel ->
2898+ Just topLevel ->
2670− rendered.topLevel ++ topLevel
2899+ topLevel :: rendered.topLevel
2673− case List.foldl combine { rules = "", topLevel = "" } stylesheet of
2902+ case List.foldl combine { topLevel = [], rules = "" } stylesheet of
2674 { topLevel, rules } ->
2903 { topLevel, rules } ->
2675− topLevel ++ rules
2904+ renderTopLevelValues topLevel ++ rules
2678lengthClassName : Length -> String
2907lengthClassName : Length -> String
@@ -3058,3 +3287,66 @@ onlyStyles attr =
3293+{- Font Adjustments -}
3296+convertAdjustment adjustment =
3312+ ((ascender - newBaseline) / 2) + newBaseline
3315+ ((ascender - descender) / 2) + descender
3318+ [ adjustment.capital
3319+ , adjustment.baseline
3320+ , adjustment.descender
3321+ , adjustment.lowercase
3325+ Maybe.withDefault adjustment.capital (List.maximum lines)
3328+ Maybe.withDefault adjustment.descender (List.minimum lines)
3332+ |> List.filter (\x -> x /= descender)
3334+ |> Maybe.withDefault adjustment.baseline
3337+ (oldMiddle - newCapitalMiddle) * 2
3340+ (oldMiddle - newFullMiddle) * 2
3343+ { vertical = fullVertical
3345+ (ascender - descender)
3349+ { vertical = capitalVertical
3350+ , height = (ascender - newBaseline) - abs capitalVertical