@@ -16,6 +16,7 @@ module Internal.Model exposing
1616 , LayoutContext(..)
1717 , Length(..)
1818 , Location(..)
19+ , NearbyChildren(..)
1920 , NodeName(..)
2021 , Option(..)
2122 , OptionRecord
@@ -41,7 +42,7 @@ module Internal.Model exposing
4142 , asParagraph
4243 , asRow
4344 , asTextColumn
44− , boxShadowName
45+ , boxShadowClass
4546 , columnClass
4647 , composeTransformation
4748 , contextClasses
@@ -78,31 +79,30 @@ module Internal.Model exposing
7879 , onlyStyles
7980 , optionsToRecord
8081 , paddingName
82+ , paddingNameFloat
8183 , pageClass
8284 , paragraphClass
8385 , reduceRecursive
8486 , reduceStyles
8587 , reduceStylesRecursive
8688 , removeNever
87− , renderFocusStyle
88− -- , renderFont
89−
9089 , renderFontClassName
9190 , renderHeight
9291 , renderRoot
92+ , renderVariant
9393 , renderWidth
9494 , rootStyle
9595 , rowClass
9696 , singleClass
9797 , spacingName
98− , staticRoot
9998 , tag
100− , textShadowName
99+ , textShadowClass
101100 , toHtml
102101 , toStyleSheet
103102 , transformClass
104103 , unstyled
105104 , unwrapDecorations
105+ , variantName
106106 )
107107
108108{-| -}
@@ -112,7 +112,7 @@ import Html.Attributes
112112import Html.Keyed
113113import Internal.Flag as Flag exposing (Flag)
114114import Internal.Style exposing (classes, dot)
115−import Json.Encode as Json
115+import Json.Encode as Encode
116116import Set exposing (Set)
117117import VirtualDom
118118
@@ -174,7 +174,7 @@ type Style
174174 | Colored String String Color
175175 | SpacingStyle String Int Int
176176 | BorderWidth String Int Int Int Int
177− | PaddingStyle String Int Int Int Int
177+ | PaddingStyle String Float Float Float Float
178178 | GridTemplateStyle
179179 { spacing : ( Length, Length )
180180 , columns : List Length
@@ -222,8 +222,7 @@ type Font
222222 | ImportFont String String
223223 | FontWith
224224 { name : String
225− , url : Maybe String
226− , adjustment : Adjustment
225+ , adjustment : Maybe Adjustment
227226 , variants : List Variant
228227 }
229228
@@ -246,13 +245,46 @@ renderVariant var =
246245 "\"" ++ name ++ "\" " ++ String.fromInt index
247246
248247
248+variantName var =
249+ case var of
250+ VariantActive name ->
251+ name
252+
253+ VariantOff name ->
254+ name ++ "-0"
255+
256+ VariantIndexed name index ->
257+ name ++ "-" ++ String.fromInt index
258+
259+
249260renderVariants typeface =
250261 case typeface of
251262 FontWith font ->
252− String.join ", " (List.map renderVariant font.variants)
263+ Just (String.join ", " (List.map renderVariant font.variants))
253264
254265 _ ->
255− ""
266+ Nothing
267+
268+
269+isSmallCaps var =
270+ case var of
271+ VariantActive name ->
272+ name == "smcp"
273+
274+ VariantOff name ->
275+ False
276+
277+ VariantIndexed name index ->
278+ name == "smcp" && index == 1
279+
280+
281+hasSmallCaps typeface =
282+ case typeface of
283+ FontWith font ->
284+ List.any isSmallCaps font.variants
285+
286+ _ ->
287+ False
256288
257289
258290type Property
@@ -340,6 +372,13 @@ type NodeName
340372 | Embedded String String
341373
342374
375+type NearbyChildren msg
376+ = NoNearbyChildren
377+ | ChildrenBehind (List (Html.Html msg))
378+ | ChildrenInFront (List (Html.Html msg))
379+ | ChildrenBehindAndInFront (List (Html.Html msg)) (List (Html.Html msg))
380+
381+
343382div =
344383 Generic
345384
@@ -348,7 +387,7 @@ type alias Gathered msg =
348387 { node : NodeName
349388 , attributes : List (VirtualDom.Attribute msg)
350389 , styles : List Style
351− , children : List (VirtualDom.Node msg)
390+ , children : NearbyChildren msg
352391 , has : Flag.Field
353392 }
354393
@@ -416,7 +455,10 @@ finalizeNode has node attributes children embedMode parentContext =
416455 Embedded nodeName internal ->
417456 VirtualDom.node nodeName
418457 attributes
419− [ createNode internal [ Html.Attributes.class (classes.any ++ " " ++ classes.single) ]
458+ [ createNode internal
459+ [ Html.Attributes.class
460+ (classes.any ++ " " ++ classes.single)
461+ ]
420462 ]
421463 in
422464 case parentContext of
@@ -493,49 +535,45 @@ finalizeNode has node attributes children embedMode parentContext =
493535
494536
495537embedWith static opts styles children =
538+ let
539+ dynamicStyleSheet =
540+ styles
541+ |> List.foldl reduceStyles ( Set.empty, renderFocusStyle opts.focus )
542+ |> Tuple.second
543+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
544+ -- |> sortedReduce
545+ |> toStyleSheet opts
546+ in
496547 if static then
497− staticRoot
498− :: (styles
499− |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
500− |> Tuple.second
501− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
502− -- |> sortedReduce
503− |> toStyleSheet opts
504− )
548+ staticRoot opts
549+ :: dynamicStyleSheet
505550 :: children
506551
507552 else
508− (styles
509− |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
510− |> Tuple.second
511− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
512− -- |> sortedReduce
513− |> toStyleSheet opts
514− )
553+ dynamicStyleSheet
515554 :: children
516555
517556
518557embedKeyed static opts styles children =
558+ let
559+ dynamicStyleSheet =
560+ styles
561+ |> List.foldl reduceStyles ( Set.empty, renderFocusStyle opts.focus )
562+ |> Tuple.second
563+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
564+ -- |> sortedReduce
565+ |> toStyleSheet opts
566+ in
519567 if static then
520− ( "static-stylesheet", staticRoot )
568+ ( "static-stylesheet", staticRoot opts )
521569 :: ( "dynamic-stylesheet"
522− , styles
523− |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
524− |> Tuple.second
525− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
526− -- |> sortedReduce
527− |> toStyleSheet opts
570+ , dynamicStyleSheet
528571 )
529572 :: children
530573
531574 else
532575 ( "dynamic-stylesheet"
533− , styles
534− |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
535− |> Tuple.second
536− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
537− -- |> sortedReduce
538− |> toStyleSheet opts
576+ , dynamicStyleSheet
539577 )
540578 :: children
541579
@@ -851,7 +889,16 @@ skippable flag style =
851889 False
852890
853891
854−gatherAttrRecursive : String -> NodeName -> Flag.Field -> Transformation -> List Style -> List (VirtualDom.Attribute msg) -> List (VirtualDom.Node msg) -> List (Attribute aligned msg) -> Gathered msg
892+gatherAttrRecursive :
893+ String
894+ -> NodeName
895+ -> Flag.Field
896+ -> Transformation
897+ -> List Style
898+ -> List (VirtualDom.Attribute msg)
899+ -> NearbyChildren msg
900+ -> List (Attribute aligned msg)
901+ -> Gathered msg
855902gatherAttrRecursive classes node has transform styles attrs children elementAttrs =
856903 case elementAttrs of
857904 [] ->
@@ -985,7 +1032,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
9851032 in
9861033 gatherAttrRecursive (classes ++ " " ++ newClass)
9871034 node
988− (Flag.merge addToFlags has)
1035+ (Flag.merge addToFlags (Flag.add Flag.width has))
9891036 transform
9901037 (newStyles ++ styles)
9911038 attrs
@@ -1006,7 +1053,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
10061053 name =
10071054 "height-px-" ++ val
10081055 in
1009− gatherAttrRecursive (name ++ " " ++ classes)
1056+ gatherAttrRecursive (Internal.Style.classes.heightExact ++ " " ++ name ++ " " ++ classes)
10101057 node
10111058 (Flag.add Flag.height has)
10121059 transform
@@ -1063,7 +1110,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
10631110 in
10641111 gatherAttrRecursive (classes ++ " " ++ newClass)
10651112 node
1066− (Flag.merge addToFlags has)
1113+ (Flag.merge addToFlags (Flag.add Flag.height has))
10671114 transform
10681115 (newStyles ++ styles)
10691116 attrs
@@ -1095,20 +1142,15 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
10951142 gatherAttrRecursive classes (addNodeName "h6" node) has transform styles attrs children remaining
10961143
10971144 Paragraph ->
1098− let
1099− newNode =
1100− case node of
1101− Generic ->
1102− NodeName "p"
1103−
1104− NodeName name ->
1105− NodeName name
1106−
1107− Embedded x y ->
1108− Embedded x y
1109− in
1110− gatherAttrRecursive classes
1111− newNode
1145+ -- previously we rendered a <p> tag, though apparently this invalidates the html if it has <div>s inside.
1146+ -- Since we can't guaranteee that there are no divs, we need another strategy.
1147+ -- While it's not documented in many places, there apparently is a paragraph aria role
1148+ -- https://github.com/w3c/aria/blob/11f85f41a5b621fdbe85fc9bcdcd270e653a48ba/common/script/roleInfo.js
1149+ -- Though we'll need to wait till it gets released in an official wai-aria spec to use it.
1150+ -- If it's used at the moment, then Lighthouse complains (likely rightfully) that role paragraph is not recognized.
1151+ gatherAttrRecursive
1152+ classes
1153+ node
11121154 has
11131155 transform
11141156 styles
@@ -1143,75 +1185,16 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11431185
11441186 Styled styled ->
11451187 styles ++ styled.styles
1146−
1147− nearbyElement =
1148− Html.div
1149− [ Html.Attributes.class <|
1150− case location of
1151− Above ->
1152− String.join " "
1153− [ Internal.Style.classes.nearby
1154− , Internal.Style.classes.single
1155− , Internal.Style.classes.above
1156− ]
1157−
1158− Below ->
1159− String.join " "
1160− [ Internal.Style.classes.nearby
1161− , Internal.Style.classes.single
1162− , Internal.Style.classes.below
1163− ]
1164−
1165− OnRight ->
1166− String.join " "
1167− [ Internal.Style.classes.nearby
1168− , Internal.Style.classes.single
1169− , Internal.Style.classes.onRight
1170− ]
1171−
1172− OnLeft ->
1173− String.join " "
1174− [ Internal.Style.classes.nearby
1175− , Internal.Style.classes.single
1176− , Internal.Style.classes.onLeft
1177− ]
1178−
1179− InFront ->
1180− String.join " "
1181− [ Internal.Style.classes.nearby
1182− , Internal.Style.classes.single
1183− , Internal.Style.classes.inFront
1184− ]
1185−
1186− Behind ->
1187− String.join " "
1188− [ Internal.Style.classes.nearby
1189− , Internal.Style.classes.single
1190− , Internal.Style.classes.behind
1191− ]
1192− ]
1193− [ case elem of
1194− Empty ->
1195− VirtualDom.text ""
1196−
1197− Text str ->
1198− textElement str
1199−
1200− Unstyled html ->
1201− html asEl
1202−
1203− Styled styled ->
1204− styled.html NoStyleSheet asEl
1205− ]
1206−
1207− newClasses =
1208− if location == Behind then
1209− Internal.Style.classes.hasBehind ++ " " ++ classes
1210−
1211− else
1212− classes
12131188 in
1214− gatherAttrRecursive newClasses node has transform newStyles attrs (nearbyElement :: children) remaining
1189+ gatherAttrRecursive
1190+ classes
1191+ node
1192+ has
1193+ transform
1194+ newStyles
1195+ attrs
1196+ (addNearbyElement location elem children)
1197+ remaining
12151198
12161199 AlignX x ->
12171200 if Flag.present Flag.xAlign has then
@@ -1267,6 +1250,106 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
12671250 remaining
12681251
12691252
1253+addNearbyElement location elem existing =
1254+ let
1255+ nearby =
1256+ nearbyElement location elem
1257+ in
1258+ case existing of
1259+ NoNearbyChildren ->
1260+ case location of
1261+ Behind ->
1262+ ChildrenBehind [ nearby ]
1263+
1264+ _ ->
1265+ ChildrenInFront [ nearby ]
1266+
1267+ ChildrenBehind existingBehind ->
1268+ case location of
1269+ Behind ->
1270+ ChildrenBehind (nearby :: existingBehind)
1271+
1272+ _ ->
1273+ ChildrenBehindAndInFront existingBehind [ nearby ]
1274+
1275+ ChildrenInFront existingInFront ->
1276+ case location of
1277+ Behind ->
1278+ ChildrenBehindAndInFront [ nearby ] existingInFront
1279+
1280+ _ ->
1281+ ChildrenInFront (nearby :: existingInFront)
1282+
1283+ ChildrenBehindAndInFront existingBehind existingInFront ->
1284+ case location of
1285+ Behind ->
1286+ ChildrenBehindAndInFront (nearby :: existingBehind) existingInFront
1287+
1288+ _ ->
1289+ ChildrenBehindAndInFront existingBehind (nearby :: existingInFront)
1290+
1291+
1292+nearbyElement location elem =
1293+ Html.div
1294+ [ Html.Attributes.class <|
1295+ case location of
1296+ Above ->
1297+ String.join " "
1298+ [ Internal.Style.classes.nearby
1299+ , Internal.Style.classes.single
1300+ , Internal.Style.classes.above
1301+ ]
1302+
1303+ Below ->
1304+ String.join " "
1305+ [ Internal.Style.classes.nearby
1306+ , Internal.Style.classes.single
1307+ , Internal.Style.classes.below
1308+ ]
1309+
1310+ OnRight ->
1311+ String.join " "
1312+ [ Internal.Style.classes.nearby
1313+ , Internal.Style.classes.single
1314+ , Internal.Style.classes.onRight
1315+ ]
1316+
1317+ OnLeft ->
1318+ String.join " "
1319+ [ Internal.Style.classes.nearby
1320+ , Internal.Style.classes.single
1321+ , Internal.Style.classes.onLeft
1322+ ]
1323+
1324+ InFront ->
1325+ String.join " "
1326+ [ Internal.Style.classes.nearby
1327+ , Internal.Style.classes.single
1328+ , Internal.Style.classes.inFront
1329+ ]
1330+
1331+ Behind ->
1332+ String.join " "
1333+ [ Internal.Style.classes.nearby
1334+ , Internal.Style.classes.single
1335+ , Internal.Style.classes.behind
1336+ ]
1337+ ]
1338+ [ case elem of
1339+ Empty ->
1340+ VirtualDom.text ""
1341+
1342+ Text str ->
1343+ textElement str
1344+
1345+ Unstyled html ->
1346+ html asEl
1347+
1348+ Styled styled ->
1349+ styled.html NoStyleSheet asEl
1350+ ]
1351+
1352+
12701353renderWidth w =
12711354 case w of
12721355 Px px ->
@@ -1353,7 +1436,7 @@ renderHeight h =
13531436 "height-px-" ++ val
13541437 in
13551438 ( Flag.none
1356− , name
1439+ , Internal.Style.classes.heightExact ++ " " ++ name
13571440 , [ Single name "height" (val ++ "px") ]
13581441 )
13591442
@@ -1376,7 +1459,7 @@ renderHeight h =
13761459 , [ Single
13771460 (Internal.Style.classes.any
13781461 ++ "."
1379− ++ Internal.Style.classes.row
1462+ ++ Internal.Style.classes.column
13801463 ++ " > "
13811464 ++ (Internal.Style.dot <| "height-fill-" ++ String.fromInt portion)
13821465 )
@@ -1395,7 +1478,9 @@ renderHeight h =
13951478 Single
13961479 cls
13971480 "min-height"
1398− (String.fromInt minSize ++ "px")
1481+ -- This needs to be !important because we're using `min-height: min-content`
1482+ -- to correct for safari's incorrect implementation of flexbox.
1483+ (String.fromInt minSize ++ "px !important")
13991484
14001485 ( newFlag, newAttrs, newStyle ) =
14011486 renderHeight len
@@ -1473,7 +1558,7 @@ element : LayoutContext -> NodeName -> List (Attribute aligned msg) -> Children
14731558element context node attributes children =
14741559 attributes
14751560 |> List.reverse
1476− |> gatherAttrRecursive (contextClasses context) node Flag.none untransformed [] [] []
1561+ |> gatherAttrRecursive (contextClasses context) node Flag.none untransformed [] [] NoNearbyChildren
14771562 |> createElement context children
14781563
14791564
@@ -1540,13 +1625,12 @@ createElement context children rendered =
15401625 -- , existingStyles
15411626 -- )
15421627 -- else
1543− ( textElement
1544− (if context == asParagraph then
1545− str
1628+ ( (if context == asEl then
1629+ textElementFill str
15461630
1547− else
1548− str
1549− )
1631+ else
1632+ textElement str
1633+ )
15501634 :: htmls
15511635 , existingStyles
15521636 )
@@ -1606,8 +1690,11 @@ createElement context children rendered =
16061690 -- )
16071691 -- else
16081692 ( ( key
1609− , textElement
1610− str
1693+ , if context == asEl then
1694+ textElementFill str
1695+
1696+ else
1697+ textElement str
16111698 )
16121699 :: htmls
16131700 , existingStyles
@@ -1634,13 +1721,8 @@ createElement context children rendered =
16341721 (finalizeNode rendered.has
16351722 rendered.node
16361723 rendered.attributes
1637− (Keyed <|
1638− keyed
1639− ++ List.map
1640− (\x ->
1641− ( "nearby-elements-pls", x )
1642− )
1643− rendered.children
1724+ (Keyed
1725+ (addKeyedChildren "nearby-element-pls" keyed rendered.children)
16441726 )
16451727 NoStyleSheet
16461728 )
@@ -1654,13 +1736,7 @@ createElement context children rendered =
16541736 rendered.node
16551737 rendered.attributes
16561738 (Keyed
1657− (keyed
1658− ++ List.map
1659− (\x ->
1660− ( "nearby-elements-pls", x )
1661− )
1662− rendered.children
1663− )
1739+ (addKeyedChildren "nearby-element-pls" keyed rendered.children)
16641740 )
16651741 }
16661742
@@ -1682,7 +1758,7 @@ createElement context children rendered =
16821758 rendered.has
16831759 rendered.node
16841760 rendered.attributes
1685− (Unkeyed <| unkeyed ++ rendered.children)
1761+ (Unkeyed (addChildren unkeyed rendered.children))
16861762 NoStyleSheet
16871763 )
16881764
@@ -1694,10 +1770,42 @@ createElement context children rendered =
16941770 rendered.has
16951771 rendered.node
16961772 rendered.attributes
1697− (Unkeyed (unkeyed ++ rendered.children))
1773+ (Unkeyed (addChildren unkeyed rendered.children))
16981774 }
16991775
17001776
1777+addChildren existing nearbyChildren =
1778+ case nearbyChildren of
1779+ NoNearbyChildren ->
1780+ existing
1781+
1782+ ChildrenBehind behind ->
1783+ behind ++ existing
1784+
1785+ ChildrenInFront inFront ->
1786+ existing ++ inFront
1787+
1788+ ChildrenBehindAndInFront behind inFront ->
1789+ behind ++ existing ++ inFront
1790+
1791+
1792+addKeyedChildren key existing nearbyChildren =
1793+ case nearbyChildren of
1794+ NoNearbyChildren ->
1795+ existing
1796+
1797+ ChildrenBehind behind ->
1798+ List.map (\x -> ( key, x )) behind ++ existing
1799+
1800+ ChildrenInFront inFront ->
1801+ existing ++ List.map (\x -> ( key, x )) inFront
1802+
1803+ ChildrenBehindAndInFront behind inFront ->
1804+ List.map (\x -> ( key, x )) behind
1805+ ++ existing
1806+ ++ List.map (\x -> ( key, x )) inFront
1807+
1808+
17011809unit =
17021810 0
17031811
@@ -1709,8 +1817,20 @@ defaultOptions =
17091817 }
17101818
17111819
1712−staticRoot =
1713− VirtualDom.node "style" [] [ VirtualDom.text Internal.Style.rules ]
1820+staticRoot : OptionRecord -> VirtualDom.Node msg
1821+staticRoot opts =
1822+ case opts.mode of
1823+ Layout ->
1824+ -- wrap the style node in a div to prevent `Dark Reader` from blowin up the dom.
1825+ VirtualDom.node "div"
1826+ []
1827+ [ VirtualDom.node "style" [] [ VirtualDom.text Internal.Style.rules ] ]
1828+
1829+ NoStaticStyleSheet ->
1830+ VirtualDom.text ""
1831+
1832+ WithVirtualCss ->
1833+ VirtualDom.node "elm-ui-static-rules" [ VirtualDom.property "rules" (Encode.string Internal.Style.rules) ] []
17141834
17151835
17161836addWhen ifThis x to =
@@ -1828,7 +1948,7 @@ type Spacing
18281948
18291949
18301950type Padding
1831− = Padding String Int Int Int Int
1951+ = Padding String Float Float Float Float
18321952
18331953
18341954extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing )
@@ -1924,35 +2044,44 @@ getHeight attrs =
19242044 Nothing
19252045
19262046
2047+textElementClasses : String
2048+textElementClasses =
2049+ classes.any
2050+ ++ " "
2051+ ++ classes.text
2052+ ++ " "
2053+ ++ classes.widthContent
2054+ ++ " "
2055+ ++ classes.heightContent
2056+
2057+
19272058textElement : String -> VirtualDom.Node msg
19282059textElement str =
19292060 Html.div
19302061 [ Html.Attributes.class
1931− (String.join " "
1932− [ classes.any
1933− , classes.text
1934− , classes.widthContent
1935− , classes.heightContent
1936− ]
1937− )
2062+ textElementClasses
19382063 ]
19392064 [ Html.text str ]
19402065
19412066
2067+textElementFillClasses : String
2068+textElementFillClasses =
2069+ classes.any
2070+ ++ " "
2071+ ++ classes.text
2072+ ++ " "
2073+ ++ classes.widthFill
2074+ ++ " "
2075+ ++ classes.heightFill
2076+
2077+
19422078textElementFill : String -> VirtualDom.Node msg
19432079textElementFill str =
1944− VirtualDom.node "div"
1945− [ VirtualDom.property "className"
1946− (Json.string <|
1947− String.join " "
1948− [ classes.any
1949− , classes.text
1950− , classes.widthFill
1951− , classes.heightFill
1952− ]
1953− )
2080+ Html.div
2081+ [ Html.Attributes.class
2082+ textElementFillClasses
19542083 ]
1955− [ VirtualDom.text str ]
2084+ [ Html.text str ]
19562085
19572086
19582087type Children x
@@ -1960,10 +2089,6 @@ type Children x
19602089 | Keyed (List ( String, x ))
19612090
19622091
1963−
1964−-- toHtml : OptionRecord -> Element msg -> VirtualDom.Node msg
1965−
1966−
19672092toHtml mode el =
19682093 case el of
19692094 Unstyled html ->
@@ -1999,8 +2124,7 @@ renderRoot optionList attributes child =
19992124
20002125
20012126type RenderMode
2002− = Viewport
2003− | Layout
2127+ = Layout
20042128 | NoStaticStyleSheet
20052129 | WithVirtualCss
20062130
@@ -2049,8 +2173,8 @@ rootStyle =
20492173 , SansSerif
20502174 ]
20512175 in
2052− [ StyleClass Flag.bgColor (Colored ("bg-color-" ++ formatColorClass (Rgba 1 1 1 0)) "background-color" (Rgba 1 1 1 0))
2053− , StyleClass Flag.fontColor (Colored ("font-color-" ++ formatColorClass (Rgba 0 0 0 1)) "color" (Rgba 0 0 0 1))
2176+ [ StyleClass Flag.bgColor (Colored ("bg-" ++ formatColorClass (Rgba 1 1 1 0)) "background-color" (Rgba 1 1 1 0))
2177+ , StyleClass Flag.fontColor (Colored ("fc-" ++ formatColorClass (Rgba 0 0 0 1)) "color" (Rgba 0 0 0 1))
20542178 , StyleClass Flag.fontSize (FontSize 20)
20552179 , StyleClass Flag.fontFamily <|
20562180 FontFamily (List.foldl renderFontClassName "font-" families)
@@ -2093,9 +2217,38 @@ renderFontClassName font current =
20932217
20942218renderFocusStyle :
20952219 FocusStyle
2096− -> Style
2220+ -> List Style
20972221renderFocusStyle focus =
2098− Style (Internal.Style.dot classes.any ++ ":focus .focusable, " ++ Internal.Style.dot classes.any ++ ".focusable:focus")
2222+ [ Style (Internal.Style.dot classes.focusedWithin ++ ":focus-within")
2223+ (List.filterMap identity
2224+ [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
2225+ , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
2226+ , Maybe.map
2227+ (\shadow ->
2228+ Property "box-shadow"
2229+ (formatBoxShadow
2230+ { color = shadow.color
2231+ , offset =
2232+ shadow.offset
2233+ |> Tuple.mapFirst toFloat
2234+ |> Tuple.mapSecond toFloat
2235+ , inset = False
2236+ , blur =
2237+ toFloat shadow.blur
2238+ , size =
2239+ toFloat shadow.size
2240+ }
2241+ )
2242+ )
2243+ focus.shadow
2244+ , Just <| Property "outline" "none"
2245+ ]
2246+ )
2247+ , Style
2248+ ((Internal.Style.dot classes.any ++ ":focus .focusable, ")
2249+ ++ (Internal.Style.dot classes.any ++ ".focusable:focus, ")
2250+ ++ (".ui-slide-bar:focus + " ++ Internal.Style.dot classes.any ++ " .focusable-thumb")
2251+ )
20992252 (List.filterMap identity
21002253 [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
21012254 , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
@@ -2118,6 +2271,7 @@ renderFocusStyle focus =
21182271 , Just <| Property "outline" "none"
21192272 ]
21202273 )
2274+ ]
21212275
21222276
21232277focusDefaultStyle : { backgroundColor : Maybe Color, borderColor : Maybe Color, shadow : Maybe Shadow }
@@ -2129,7 +2283,7 @@ focusDefaultStyle =
21292283 { color =
21302284 Rgba (155 / 255) (203 / 255) 1 1
21312285 , offset = ( 0, 0 )
2132− , blur = 3
2286+ , blur = 0
21332287 , size = 3
21342288 }
21352289 }
@@ -2199,7 +2353,31 @@ optionsToRecord options =
21992353
22002354toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
22012355toStyleSheet options styleSheet =
2202− VirtualDom.node "style" [] [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2356+ case options.mode of
2357+ Layout ->
2358+ -- wrap the style node in a div to prevent `Dark Reader` from blowin up the dom.
2359+ VirtualDom.node "div"
2360+ []
2361+ [ VirtualDom.node "style"
2362+ []
2363+ [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2364+ ]
2365+
2366+ NoStaticStyleSheet ->
2367+ -- wrap the style node in a div to prevent `Dark Reader` from blowin up the dom.
2368+ VirtualDom.node "div"
2369+ []
2370+ [ VirtualDom.node "style"
2371+ []
2372+ [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2373+ ]
2374+
2375+ WithVirtualCss ->
2376+ VirtualDom.node "elm-ui-rules"
2377+ [ VirtualDom.property "rules"
2378+ (encodeStyles options styleSheet)
2379+ ]
2380+ []
22032381
22042382
22052383renderTopLevelValues rules =
@@ -2209,14 +2387,12 @@ renderTopLevelValues rules =
22092387 ImportFont _ url ->
22102388 Just ("@import url('" ++ url ++ "');")
22112389
2212− FontWith with ->
2213− case with.url of
2214− Just x ->
2215− Just ("@import url('" ++ x ++ "');")
2216−
2217− Nothing ->
2218− Nothing
2219−
2390+ -- FontWith with ->
2391+ -- case with.url of
2392+ -- Just x ->
2393+ -- Just ("@import url('" ++ x ++ "');")
2394+ -- Nothing ->
2395+ -- Nothing
22202396 _ ->
22212397 Nothing
22222398
@@ -2287,7 +2463,38 @@ renderNullAdjustmentRule fontToAdjust otherFontName =
22872463 ]
22882464
22892465
2290−renderFontAdjustmentRule fontToAdjust ( parentAdj, textAdjustment ) otherFontName =
2466+fontRule name modifier ( parentAdj, textAdjustment ) =
2467+ [ bracket
2468+ ("."
2469+ ++ name
2470+ ++ "."
2471+ ++ modifier
2472+ ++ ", "
2473+ ++ "."
2474+ ++ name
2475+ ++ " ."
2476+ ++ modifier
2477+ )
2478+ parentAdj
2479+ , bracket
2480+ ("."
2481+ ++ name
2482+ ++ "."
2483+ ++ modifier
2484+ ++ "> ."
2485+ ++ Internal.Style.classes.text
2486+ ++ ", ."
2487+ ++ name
2488+ ++ " ."
2489+ ++ modifier
2490+ ++ " > ."
2491+ ++ Internal.Style.classes.text
2492+ )
2493+ textAdjustment
2494+ ]
2495+
2496+
2497+renderFontAdjustmentRule fontToAdjust ( full, capital ) otherFontName =
22912498 let
22922499 name =
22932500 if fontToAdjust == otherFontName then
@@ -2297,34 +2504,7 @@ renderFontAdjustmentRule fontToAdjust ( parentAdj, textAdjustment ) otherFontNam
22972504 otherFontName ++ " ." ++ fontToAdjust
22982505 in
22992506 String.join " "
2300− [ bracket
2301− ("."
2302− ++ name
2303− ++ "."
2304− ++ classes.sizeByCapital
2305− ++ ", "
2306− ++ "."
2307− ++ name
2308− ++ " ."
2309− ++ classes.sizeByCapital
2310− )
2311− parentAdj
2312− , bracket
2313− ("."
2314− ++ name
2315− ++ "."
2316− ++ classes.sizeByCapital
2317− ++ "> ."
2318− ++ Internal.Style.classes.text
2319− ++ ", ."
2320− ++ name
2321− ++ " ."
2322− ++ classes.sizeByCapital
2323− ++ " > ."
2324− ++ Internal.Style.classes.text
2325− )
2326− textAdjustment
2327− ]
2507+ (fontRule name classes.sizeByCapital capital ++ fontRule name classes.fullSize full)
23282508
23292509
23302510bracket selector rules =
@@ -2337,17 +2517,12 @@ bracket selector rules =
23372517
23382518fontAdjustmentRules converted =
23392519 ( [ ( "display", "block" )
2340−
2341− -- , ( "line-height", String.fromFloat converted.height )
2342− -- , ( "font-size", String.fromFloat (1 + converted.height + converted.vertical) ++ "em" )
23432520 ]
23442521 , [ ( "display", "inline-block" )
23452522 , ( "line-height", String.fromFloat converted.height )
23462523 , ( "vertical-align", String.fromFloat converted.vertical ++ "em" )
23472524 , ( "font-size", String.fromFloat converted.size ++ "em" )
23482525 ]
2349− -- , [ ( "font-size", String.fromFloat converted.size ++ "em" )
2350− -- ]
23512526 )
23522527
23532528
@@ -2358,10 +2533,17 @@ typefaceAdjustment typefaces =
23582533 Nothing ->
23592534 case face of
23602535 FontWith with ->
2361− Just
2362− (fontAdjustmentRules
2363− (.capital (convertAdjustment with.adjustment))
2364− )
2536+ case with.adjustment of
2537+ Nothing ->
2538+ found
2539+
2540+ Just adjustment ->
2541+ Just
2542+ ( fontAdjustmentRules
2543+ (.full (convertAdjustment adjustment))
2544+ , fontAdjustmentRules
2545+ (.capital (convertAdjustment adjustment))
2546+ )
23652547
23662548 _ ->
23672549 found
@@ -2411,482 +2593,492 @@ renderProps force (Property key val) existing =
24112593 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
24122594
24132595
2596+encodeStyles options stylesheet =
2597+ stylesheet
2598+ |> List.map
2599+ (\style ->
2600+ let
2601+ styled =
2602+ renderStyleRule options style Nothing
2603+ in
2604+ ( getStyleName style, Encode.list Encode.string styled )
2605+ )
2606+ |> Encode.object
2607+
2608+
24142609toStyleSheetString : OptionRecord -> List Style -> String
24152610toStyleSheetString options stylesheet =
24162611 let
2417− renderStyle maybePseudo selector props =
2418− case maybePseudo of
2419− Nothing ->
2420− selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}"
2421−
2422− Just pseudo ->
2423− case pseudo of
2424− Hover ->
2425− case options.hover of
2426− NoHover ->
2427− ""
2612+ combine style rendered =
2613+ { rules = rendered.rules ++ renderStyleRule options style Nothing
2614+ , topLevel =
2615+ case topLevelValue style of
2616+ Nothing ->
2617+ rendered.topLevel
24282618
2429− ForceHover ->
2430− selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}"
2619+ Just topLevel ->
2620+ topLevel :: rendered.topLevel
2621+ }
2622+ in
2623+ case List.foldl combine { topLevel = [], rules = [] } stylesheet of
2624+ { topLevel, rules } ->
2625+ renderTopLevelValues topLevel ++ String.concat rules
24312626
2432− AllowHover ->
2433− selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}"
24342627
2435− Focus ->
2436− let
2437− renderedProps =
2438− List.foldl (renderProps False) "" props
2439− in
2440− String.join "\n"
2441− [ selector
2442− ++ "-fs:focus {"
2443− ++ renderedProps
2444− ++ "\n}"
2445− , "."
2446− ++ classes.any
2447− ++ ":focus ~ "
2448− ++ selector
2449− ++ "-fs:not(.focus) {"
2450− ++ renderedProps
2451− ++ "\n}"
2452− , "."
2453− ++ classes.any
2454− ++ ":focus "
2455− ++ selector
2456− ++ "-fs {"
2457− ++ renderedProps
2458− ++ "\n}"
2459− , ".focusable-parent:focus ~ "
2460− ++ "."
2461− ++ classes.any
2462− ++ " "
2463− ++ selector
2464− ++ "-fs {"
2465− ++ renderedProps
2466− ++ "\n}"
2467− ]
2628+renderStyle : OptionRecord -> Maybe PseudoClass -> String -> List Property -> List String
2629+renderStyle options maybePseudo selector props =
2630+ case maybePseudo of
2631+ Nothing ->
2632+ [ selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
24682633
2469− Active ->
2470− selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}"
2634+ Just pseudo ->
2635+ case pseudo of
2636+ Hover ->
2637+ case options.hover of
2638+ NoHover ->
2639+ []
24712640
2472− renderStyleRule rule maybePseudo =
2473− case rule of
2474− Style selector props ->
2475− renderStyle maybePseudo selector props
2641+ ForceHover ->
2642+ [ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}" ]
24762643
2477− Shadows name prop ->
2478− renderStyle
2479− maybePseudo
2480− ("." ++ name)
2481− [ Property "box-shadow" prop
2482− ]
2644+ AllowHover ->
2645+ [ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
24832646
2484− Transparency name transparency ->
2647+ Focus ->
24852648 let
2486− opacity =
2487− (1 - transparency)
2488− |> min 1
2489− |> max 0
2649+ renderedProps =
2650+ List.foldl (renderProps False) "" props
24902651 in
2491− renderStyle
2492− maybePseudo
2493− ("." ++ name)
2494− [ Property "opacity" (String.fromFloat opacity)
2495− ]
2652+ [ selector ++ "-fs:focus {" ++ renderedProps ++ "\n}"
2653+ , ("." ++ classes.any ++ ":focus " ++ selector ++ "-fs {")
2654+ ++ renderedProps
2655+ ++ "\n}"
2656+ , (selector ++ "-fs:focus-within {")
2657+ ++ renderedProps
2658+ ++ "\n}"
2659+ , (".ui-slide-bar:focus + " ++ Internal.Style.dot classes.any ++ " .focusable-thumb" ++ selector ++ "-fs {")
2660+ ++ renderedProps
2661+ ++ "\n}"
2662+ ]
24962663
2497− FontSize i ->
2498− renderStyle
2499− maybePseudo
2500− (".font-size-" ++ String.fromInt i)
2501− [ Property "font-size" (String.fromInt i ++ "px")
2502− ]
2664+ Active ->
2665+ [ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
25032666
2504− FontFamily name typefaces ->
2505− let
2506− features =
2507− typefaces
2508− |> List.map renderVariants
2509− |> String.join ", "
2510−
2511− families =
2512− [ Property "font-family"
2513− (typefaces
2514− |> List.map fontName
2515− |> String.join ", "
2516− )
2517− , Property "font-feature-settings" features
2518− ]
2519− in
2520− String.join " "
2521− [ renderStyle
2522− maybePseudo
2523− ("." ++ name)
2524− families
2525− ]
25262667
2527− Single class prop val ->
2528− renderStyle
2529− maybePseudo
2530− ("." ++ class)
2531− [ Property prop val
2532− ]
2668+renderStyleRule : OptionRecord -> Style -> Maybe PseudoClass -> List String
2669+renderStyleRule options rule maybePseudo =
2670+ case rule of
2671+ Style selector props ->
2672+ renderStyle options maybePseudo selector props
2673+
2674+ Shadows name prop ->
2675+ renderStyle options
2676+ maybePseudo
2677+ ("." ++ name)
2678+ [ Property "box-shadow" prop
2679+ ]
25332680
2534− Colored class prop color ->
2535− renderStyle
2536− maybePseudo
2537− ("." ++ class)
2538− [ Property prop (formatColor color)
2539− ]
2681+ Transparency name transparency ->
2682+ let
2683+ opacity =
2684+ (1 - transparency)
2685+ |> min 1
2686+ |> max 0
2687+ in
2688+ renderStyle options
2689+ maybePseudo
2690+ ("." ++ name)
2691+ [ Property "opacity" (String.fromFloat opacity)
2692+ ]
25402693
2541− SpacingStyle cls x y ->
2542− let
2543− class =
2544− "." ++ cls
2694+ FontSize i ->
2695+ renderStyle options
2696+ maybePseudo
2697+ (".font-size-" ++ String.fromInt i)
2698+ [ Property "font-size" (String.fromInt i ++ "px")
2699+ ]
25452700
2546− halfX =
2547− String.fromFloat (toFloat x / 2) ++ "px"
2701+ FontFamily name typefaces ->
2702+ let
2703+ features =
2704+ typefaces
2705+ |> List.filterMap renderVariants
2706+ |> String.join ", "
2707+
2708+ families =
2709+ [ Property "font-family"
2710+ (typefaces
2711+ |> List.map fontName
2712+ |> String.join ", "
2713+ )
2714+ , Property "font-feature-settings" features
2715+ , Property "font-variant"
2716+ (if List.any hasSmallCaps typefaces then
2717+ "small-caps"
25482718
2549− halfY =
2550− String.fromFloat (toFloat y / 2) ++ "px"
2719+ else
2720+ "normal"
2721+ )
2722+ ]
2723+ in
2724+ renderStyle options
2725+ maybePseudo
2726+ ("." ++ name)
2727+ families
25512728
2552− xPx =
2553− String.fromInt x ++ "px"
2729+ Single class prop val ->
2730+ renderStyle options
2731+ maybePseudo
2732+ ("." ++ class)
2733+ [ Property prop val
2734+ ]
25542735
2555− yPx =
2556− String.fromInt y ++ "px"
2736+ Colored class prop color ->
2737+ renderStyle options
2738+ maybePseudo
2739+ ("." ++ class)
2740+ [ Property prop (formatColor color)
2741+ ]
25572742
2558− row =
2559− "." ++ Internal.Style.classes.row
2743+ SpacingStyle cls x y ->
2744+ let
2745+ class =
2746+ "." ++ cls
25602747
2561− wrappedRow =
2562− "." ++ Internal.Style.classes.wrapped ++ row
2748+ halfX =
2749+ String.fromFloat (toFloat x / 2) ++ "px"
25632750
2564− column =
2565− "." ++ Internal.Style.classes.column
2751+ halfY =
2752+ String.fromFloat (toFloat y / 2) ++ "px"
25662753
2567− page =
2568− "." ++ Internal.Style.classes.page
2754+ xPx =
2755+ String.fromInt x ++ "px"
25692756
2570− paragraph =
2571− "." ++ Internal.Style.classes.paragraph
2757+ yPx =
2758+ String.fromInt y ++ "px"
25722759
2573− left =
2574− "." ++ Internal.Style.classes.alignLeft
2760+ row =
2761+ "." ++ Internal.Style.classes.row
25752762
2576− right =
2577− "." ++ Internal.Style.classes.alignRight
2763+ wrappedRow =
2764+ "." ++ Internal.Style.classes.wrapped ++ row
25782765
2579− any =
2580− "." ++ Internal.Style.classes.any
2766+ column =
2767+ "." ++ Internal.Style.classes.column
25812768
2582− single =
2583− "." ++ Internal.Style.classes.single
2584− in
2585− String.concat
2586− [ renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
2587−
2588− -- margins don't apply to last element of normal, unwrapped rows
2589− -- , renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
2590− -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
2591− , renderStyle maybePseudo
2592− (class ++ wrappedRow ++ " > " ++ any)
2593− [ Property "margin" (halfY ++ " " ++ halfX)
2594− ]
2769+ page =
2770+ "." ++ Internal.Style.classes.page
25952771
2596− -- , renderStyle maybePseudo
2597− -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2598− -- [ Property "margin-right" "0"
2599− -- ]
2600− -- columns
2601− , renderStyle maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2602− , renderStyle maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2603− , renderStyle maybePseudo (class ++ page ++ " > " ++ left) [ Property "margin-right" xPx ]
2604− , renderStyle maybePseudo (class ++ page ++ " > " ++ right) [ Property "margin-left" xPx ]
2605− , renderStyle
2606− maybePseudo
2607− (class ++ paragraph)
2608− [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2609− ]
2610− , renderStyle
2611− maybePseudo
2612− ("textarea" ++ class)
2613− [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2614− ]
2772+ paragraph =
2773+ "." ++ Internal.Style.classes.paragraph
26152774
2616− -- , renderStyle
2617− -- maybePseudo
2618− -- (class ++ paragraph ++ " > " ++ any)
2619− -- [ Property "margin-right" xPx
2620− -- , Property "margin-bottom" yPx
2621− -- ]
2622− , renderStyle
2623− maybePseudo
2624− (class ++ paragraph ++ " > " ++ left)
2625− [ Property "margin-right" xPx
2626− ]
2627− , renderStyle
2628− maybePseudo
2629− (class ++ paragraph ++ " > " ++ right)
2630− [ Property "margin-left" xPx
2631− ]
2632− , renderStyle
2633− maybePseudo
2634− (class ++ paragraph ++ "::after")
2635− [ Property "content" "''"
2636− , Property "display" "block"
2637− , Property "height" "0"
2638− , Property "width" "0"
2639− , Property "margin-top" (String.fromInt (-1 * (y // 2)) ++ "px")
2640− ]
2641− , renderStyle
2642− maybePseudo
2643− (class ++ paragraph ++ "::before")
2644− [ Property "content" "''"
2645− , Property "display" "block"
2646− , Property "height" "0"
2647− , Property "width" "0"
2648− , Property "margin-bottom" (String.fromInt (-1 * (y // 2)) ++ "px")
2649− ]
2650− ]
2775+ left =
2776+ "." ++ Internal.Style.classes.alignLeft
26512777
2652− PaddingStyle cls top right bottom left ->
2653− let
2654− class =
2655− "."
2656− ++ cls
2657− in
2658− renderStyle
2659− maybePseudo
2660− class
2661− [ Property "padding"
2662− (String.fromInt top
2663− ++ "px "
2664− ++ String.fromInt right
2665− ++ "px "
2666− ++ String.fromInt bottom
2667− ++ "px "
2668− ++ String.fromInt left
2669− ++ "px"
2670− )
2671− ]
2778+ right =
2779+ "." ++ Internal.Style.classes.alignRight
26722780
2673− BorderWidth cls top right bottom left ->
2674− let
2675− class =
2676− "."
2677− ++ cls
2678− in
2679− renderStyle
2680− maybePseudo
2681− class
2682− [ Property "border-width"
2683− (String.fromInt top
2684− ++ "px "
2685− ++ String.fromInt right
2686− ++ "px "
2687− ++ String.fromInt bottom
2688− ++ "px "
2689− ++ String.fromInt left
2690− ++ "px"
2691− )
2692− ]
2781+ any =
2782+ "." ++ Internal.Style.classes.any
26932783
2694− GridTemplateStyle template ->
2695− let
2696− class =
2697− ".grid-rows-"
2698− ++ String.join "-" (List.map lengthClassName template.rows)
2699− ++ "-cols-"
2700− ++ String.join "-" (List.map lengthClassName template.columns)
2701− ++ "-space-x-"
2702− ++ lengthClassName (Tuple.first template.spacing)
2703− ++ "-space-y-"
2704− ++ lengthClassName (Tuple.second template.spacing)
2705−
2706− ySpacing =
2707− toGridLength (Tuple.second template.spacing)
2708−
2709− xSpacing =
2710− toGridLength (Tuple.first template.spacing)
2711−
2712− toGridLength x =
2713− toGridLengthHelper Nothing Nothing x
2714−
2715− toGridLengthHelper minimum maximum x =
2716− case x of
2717− Px px ->
2718− String.fromInt px ++ "px"
2719−
2720− Content ->
2721− case ( minimum, maximum ) of
2722− ( Nothing, Nothing ) ->
2723− "max-content"
2724−
2725− ( Just minSize, Nothing ) ->
2726− "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2727−
2728− ( Nothing, Just maxSize ) ->
2729− "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2730−
2731− ( Just minSize, Just maxSize ) ->
2732− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2733−
2734− Fill i ->
2735− case ( minimum, maximum ) of
2736− ( Nothing, Nothing ) ->
2737− String.fromInt i ++ "fr"
2738−
2739− ( Just minSize, Nothing ) ->
2740− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2741−
2742− ( Nothing, Just maxSize ) ->
2743− "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2744−
2745− ( Just minSize, Just maxSize ) ->
2746− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2747−
2748− Min m len ->
2749− toGridLengthHelper (Just m) maximum len
2750−
2751− Max m len ->
2752− toGridLengthHelper minimum (Just m) len
2753−
2754− msColumns =
2755− template.columns
2756− |> List.map toGridLength
2757− |> String.join ySpacing
2758− |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2759−
2760− msRows =
2761− template.columns
2762− |> List.map toGridLength
2763− |> String.join ySpacing
2764− |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
2765−
2766− base =
2767− class ++ "{" ++ msColumns ++ msRows ++ "}"
2768−
2769− columns =
2770− template.columns
2771− |> List.map toGridLength
2772− |> String.join " "
2773− |> (\x -> "grid-template-columns: " ++ x ++ ";")
2774−
2775− rows =
2776− template.rows
2777− |> List.map toGridLength
2778− |> String.join " "
2779− |> (\x -> "grid-template-rows: " ++ x ++ ";")
2780−
2781− gapX =
2782− "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2783−
2784− gapY =
2785− "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2786−
2787− modernGrid =
2788− class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2789−
2790− supports =
2791− "@supports (display:grid) {" ++ modernGrid ++ "}"
2792− in
2793− base ++ supports
2784+ single =
2785+ "." ++ Internal.Style.classes.single
2786+ in
2787+ List.concat
2788+ [ renderStyle options maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
2789+
2790+ -- margins don't apply to last element of normal, unwrapped rows
2791+ -- , renderStyle options maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
2792+ -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
2793+ , renderStyle options
2794+ maybePseudo
2795+ (class ++ wrappedRow ++ " > " ++ any)
2796+ [ Property "margin" (halfY ++ " " ++ halfX)
2797+ ]
27942798
2795− GridPosition position ->
2796− let
2797− class =
2798− ".grid-pos-"
2799− ++ String.fromInt position.row
2800− ++ "-"
2801− ++ String.fromInt position.col
2802− ++ "-"
2803− ++ String.fromInt position.width
2804− ++ "-"
2805− ++ String.fromInt position.height
2806−
2807− msPosition =
2808− String.join " "
2809− [ "-ms-grid-row: "
2810− ++ String.fromInt position.row
2811− ++ ";"
2812− , "-ms-grid-row-span: "
2813− ++ String.fromInt position.height
2814− ++ ";"
2815− , "-ms-grid-column: "
2816− ++ String.fromInt position.col
2817− ++ ";"
2818− , "-ms-grid-column-span: "
2819− ++ String.fromInt position.width
2820− ++ ";"
2821− ]
2822−
2823− base =
2824− class ++ "{" ++ msPosition ++ "}"
2825−
2826− modernPosition =
2827− String.join " "
2828− [ "grid-row: "
2829− ++ String.fromInt position.row
2830− ++ " / "
2831− ++ String.fromInt (position.row + position.height)
2832− ++ ";"
2833− , "grid-column: "
2834− ++ String.fromInt position.col
2835− ++ " / "
2836− ++ String.fromInt (position.col + position.width)
2837− ++ ";"
2838− ]
2839−
2840− modernGrid =
2841− class ++ "{" ++ modernPosition ++ "}"
2842−
2843− supports =
2844− "@supports (display:grid) {" ++ modernGrid ++ "}"
2845− in
2846− base ++ supports
2799+ -- , renderStyle options maybePseudo
2800+ -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2801+ -- [ Property "margin-right" "0"
2802+ -- ]
2803+ -- columns
2804+ , renderStyle options maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2805+ , renderStyle options maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2806+ , renderStyle options maybePseudo (class ++ page ++ " > " ++ left) [ Property "margin-right" xPx ]
2807+ , renderStyle options maybePseudo (class ++ page ++ " > " ++ right) [ Property "margin-left" xPx ]
2808+ , renderStyle options
2809+ maybePseudo
2810+ (class ++ paragraph)
2811+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2812+ ]
2813+ , renderStyle options
2814+ maybePseudo
2815+ ("textarea" ++ any ++ class)
2816+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2817+ , Property "height" ("calc(100% + " ++ String.fromInt y ++ "px)")
2818+ ]
28472819
2848− PseudoSelector class styles ->
2849− let
2850− renderPseudoRule style =
2851− renderStyleRule style (Just class)
2852− in
2853− List.map renderPseudoRule styles
2820+ -- , renderStyle options
2821+ -- maybePseudo
2822+ -- (class ++ paragraph ++ " > " ++ any)
2823+ -- [ Property "margin-right" xPx
2824+ -- , Property "margin-bottom" yPx
2825+ -- ]
2826+ , renderStyle options
2827+ maybePseudo
2828+ (class ++ paragraph ++ " > " ++ left)
2829+ [ Property "margin-right" xPx
2830+ ]
2831+ , renderStyle options
2832+ maybePseudo
2833+ (class ++ paragraph ++ " > " ++ right)
2834+ [ Property "margin-left" xPx
2835+ ]
2836+ , renderStyle options
2837+ maybePseudo
2838+ (class ++ paragraph ++ "::after")
2839+ [ Property "content" "''"
2840+ , Property "display" "block"
2841+ , Property "height" "0"
2842+ , Property "width" "0"
2843+ , Property "margin-top" (String.fromInt (-1 * (y // 2)) ++ "px")
2844+ ]
2845+ , renderStyle options
2846+ maybePseudo
2847+ (class ++ paragraph ++ "::before")
2848+ [ Property "content" "''"
2849+ , Property "display" "block"
2850+ , Property "height" "0"
2851+ , Property "width" "0"
2852+ , Property "margin-bottom" (String.fromInt (-1 * (y // 2)) ++ "px")
2853+ ]
2854+ ]
2855+
2856+ PaddingStyle cls top right bottom left ->
2857+ let
2858+ class =
2859+ "."
2860+ ++ cls
2861+ in
2862+ renderStyle options
2863+ maybePseudo
2864+ class
2865+ [ Property "padding"
2866+ (String.fromFloat top
2867+ ++ "px "
2868+ ++ String.fromFloat right
2869+ ++ "px "
2870+ ++ String.fromFloat bottom
2871+ ++ "px "
2872+ ++ String.fromFloat left
2873+ ++ "px"
2874+ )
2875+ ]
2876+
2877+ BorderWidth cls top right bottom left ->
2878+ let
2879+ class =
2880+ "."
2881+ ++ cls
2882+ in
2883+ renderStyle options
2884+ maybePseudo
2885+ class
2886+ [ Property "border-width"
2887+ (String.fromInt top
2888+ ++ "px "
2889+ ++ String.fromInt right
2890+ ++ "px "
2891+ ++ String.fromInt bottom
2892+ ++ "px "
2893+ ++ String.fromInt left
2894+ ++ "px"
2895+ )
2896+ ]
2897+
2898+ GridTemplateStyle template ->
2899+ let
2900+ class =
2901+ ".grid-rows-"
2902+ ++ String.join "-" (List.map lengthClassName template.rows)
2903+ ++ "-cols-"
2904+ ++ String.join "-" (List.map lengthClassName template.columns)
2905+ ++ "-space-x-"
2906+ ++ lengthClassName (Tuple.first template.spacing)
2907+ ++ "-space-y-"
2908+ ++ lengthClassName (Tuple.second template.spacing)
2909+
2910+ ySpacing =
2911+ toGridLength (Tuple.second template.spacing)
2912+
2913+ xSpacing =
2914+ toGridLength (Tuple.first template.spacing)
2915+
2916+ toGridLength x =
2917+ toGridLengthHelper Nothing Nothing x
2918+
2919+ toGridLengthHelper minimum maximum x =
2920+ case x of
2921+ Px px ->
2922+ String.fromInt px ++ "px"
2923+
2924+ Content ->
2925+ case ( minimum, maximum ) of
2926+ ( Nothing, Nothing ) ->
2927+ "max-content"
2928+
2929+ ( Just minSize, Nothing ) ->
2930+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2931+
2932+ ( Nothing, Just maxSize ) ->
2933+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2934+
2935+ ( Just minSize, Just maxSize ) ->
2936+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2937+
2938+ Fill i ->
2939+ case ( minimum, maximum ) of
2940+ ( Nothing, Nothing ) ->
2941+ String.fromInt i ++ "fr"
2942+
2943+ ( Just minSize, Nothing ) ->
2944+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2945+
2946+ ( Nothing, Just maxSize ) ->
2947+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2948+
2949+ ( Just minSize, Just maxSize ) ->
2950+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2951+
2952+ Min m len ->
2953+ toGridLengthHelper (Just m) maximum len
2954+
2955+ Max m len ->
2956+ toGridLengthHelper minimum (Just m) len
2957+
2958+ msColumns =
2959+ template.columns
2960+ |> List.map toGridLength
2961+ |> String.join ySpacing
2962+ |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2963+
2964+ msRows =
2965+ template.columns
2966+ |> List.map toGridLength
2967+ |> String.join ySpacing
2968+ |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
2969+
2970+ base =
2971+ class ++ "{" ++ msColumns ++ msRows ++ "}"
2972+
2973+ columns =
2974+ template.columns
2975+ |> List.map toGridLength
28542976 |> String.join " "
2977+ |> (\x -> "grid-template-columns: " ++ x ++ ";")
28552978
2856− Transform transform ->
2857− let
2858− val =
2859− transformValue transform
2979+ rows =
2980+ template.rows
2981+ |> List.map toGridLength
2982+ |> String.join " "
2983+ |> (\x -> "grid-template-rows: " ++ x ++ ";")
28602984
2861− class =
2862− transformClass transform
2863− in
2864− case ( class, val ) of
2865− ( Just cls, Just v ) ->
2866− renderStyle
2867− maybePseudo
2868− ("." ++ cls)
2869− [ Property "transform"
2870− v
2871− ]
2985+ gapX =
2986+ "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
28722987
2873− _ ->
2874− ""
2988+ gapY =
2989+ "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
28752990
2876− combine style rendered =
2877− { rules = rendered.rules ++ renderStyleRule style Nothing
2878− , topLevel =
2879− case topLevelValue style of
2880− Nothing ->
2881− rendered.topLevel
2991+ modernGrid =
2992+ class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
28822993
2883− Just topLevel ->
2884− topLevel :: rendered.topLevel
2885− }
2886− in
2887− case List.foldl combine { topLevel = [], rules = "" } stylesheet of
2888− { topLevel, rules } ->
2889− renderTopLevelValues topLevel ++ rules
2994+ supports =
2995+ "@supports (display:grid) {" ++ modernGrid ++ "}"
2996+ in
2997+ [ base
2998+ , supports
2999+ ]
3000+
3001+ GridPosition position ->
3002+ let
3003+ class =
3004+ ".grid-pos-"
3005+ ++ String.fromInt position.row
3006+ ++ "-"
3007+ ++ String.fromInt position.col
3008+ ++ "-"
3009+ ++ String.fromInt position.width
3010+ ++ "-"
3011+ ++ String.fromInt position.height
3012+
3013+ msPosition =
3014+ String.join " "
3015+ [ "-ms-grid-row: "
3016+ ++ String.fromInt position.row
3017+ ++ ";"
3018+ , "-ms-grid-row-span: "
3019+ ++ String.fromInt position.height
3020+ ++ ";"
3021+ , "-ms-grid-column: "
3022+ ++ String.fromInt position.col
3023+ ++ ";"
3024+ , "-ms-grid-column-span: "
3025+ ++ String.fromInt position.width
3026+ ++ ";"
3027+ ]
3028+
3029+ base =
3030+ class ++ "{" ++ msPosition ++ "}"
3031+
3032+ modernPosition =
3033+ String.join " "
3034+ [ "grid-row: "
3035+ ++ String.fromInt position.row
3036+ ++ " / "
3037+ ++ String.fromInt (position.row + position.height)
3038+ ++ ";"
3039+ , "grid-column: "
3040+ ++ String.fromInt position.col
3041+ ++ " / "
3042+ ++ String.fromInt (position.col + position.width)
3043+ ++ ";"
3044+ ]
3045+
3046+ modernGrid =
3047+ class ++ "{" ++ modernPosition ++ "}"
3048+
3049+ supports =
3050+ "@supports (display:grid) {" ++ modernGrid ++ "}"
3051+ in
3052+ [ base
3053+ , supports
3054+ ]
3055+
3056+ PseudoSelector class styles ->
3057+ let
3058+ renderPseudoRule style =
3059+ renderStyleRule options style (Just class)
3060+ in
3061+ List.concatMap renderPseudoRule styles
3062+
3063+ Transform transform ->
3064+ let
3065+ val =
3066+ transformValue transform
3067+
3068+ class =
3069+ transformClass transform
3070+ in
3071+ case ( class, val ) of
3072+ ( Just cls, Just v ) ->
3073+ renderStyle options
3074+ maybePseudo
3075+ ("." ++ cls)
3076+ [ Property "transform"
3077+ v
3078+ ]
3079+
3080+ _ ->
3081+ []
28903082
28913083
28923084lengthClassName : Length -> String
@@ -2926,12 +3118,12 @@ formatTextShadow shadow =
29263118 ]
29273119
29283120
2929−textShadowName shadow =
3121+textShadowClass shadow =
29303122 String.concat
29313123 [ "txt"
2932− , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2933− , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2934− , String.fromFloat shadow.blur ++ "px"
3124+ , floatClass (Tuple.first shadow.offset) ++ "px"
3125+ , floatClass (Tuple.second shadow.offset) ++ "px"
3126+ , floatClass shadow.blur ++ "px"
29353127 , formatColorClass shadow.color
29363128 ]
29373129
@@ -2952,17 +3144,17 @@ formatBoxShadow shadow =
29523144 ]
29533145
29543146
2955−boxShadowName shadow =
3147+boxShadowClass shadow =
29563148 String.concat <|
29573149 [ if shadow.inset then
29583150 "box-inset"
29593151
29603152 else
29613153 "box-"
2962− , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2963− , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2964− , String.fromFloat shadow.blur ++ "px"
2965− , String.fromFloat shadow.size ++ "px"
3154+ , floatClass (Tuple.first shadow.offset) ++ "px"
3155+ , floatClass (Tuple.second shadow.offset) ++ "px"
3156+ , floatClass shadow.blur ++ "px"
3157+ , floatClass shadow.size ++ "px"
29663158 , formatColorClass shadow.color
29673159 ]
29683160
@@ -3007,6 +3199,17 @@ paddingName top right bottom left =
30073199 ++ String.fromInt left
30083200
30093201
3202+paddingNameFloat top right bottom left =
3203+ "pad-"
3204+ ++ floatClass top
3205+ ++ "-"
3206+ ++ floatClass right
3207+ ++ "-"
3208+ ++ floatClass bottom
3209+ ++ "-"
3210+ ++ floatClass left
3211+
3212+
30103213getStyleName : Style -> String
30113214getStyleName style =
30123215 case style of
@@ -3324,16 +3527,16 @@ convertAdjustment adjustment =
33243527 capitalSize =
33253528 1 / (ascender - newBaseline)
33263529
3530+ fullSize =
3531+ 1 / (ascender - descender)
3532+
33273533 fullVertical =
3328− (oldMiddle - newFullMiddle) * 2
3534+ 1 - ascender
3535+
3536+ -- (oldMiddle - newFullMiddle) * 2
33293537 in
33303538 { full =
3331− { vertical = fullVertical
3332− , height =
3333− (ascender - descender)
3334− - abs fullVertical
3335− , size = 1.0
3336− }
3539+ adjust fullSize (ascender - descender) fullVertical
33373540 , capital =
33383541 adjust capitalSize (ascender - newBaseline) capitalVertical
33393542 }
@@ -3343,7 +3546,5 @@ adjust size height vertical =
33433546 { vertical = vertical
33443547 , height =
33453548 height / size
3346−
3347− -- vertical
33483549 , size = size
33493550 }