@@ -16,7 +16,6 @@ module Internal.Model exposing
1616 , LayoutContext(..)
1717 , Length(..)
1818 , Location(..)
19− , NearbyChildren(..)
2019 , NodeName(..)
2120 , Option(..)
2221 , OptionRecord
@@ -42,7 +41,7 @@ module Internal.Model exposing
4241 , asParagraph
4342 , asRow
4443 , asTextColumn
45− , boxShadowClass
44+ , boxShadowName
4645 , columnClass
4746 , composeTransformation
4847 , contextClasses
@@ -79,30 +78,31 @@ module Internal.Model exposing
7978 , onlyStyles
8079 , optionsToRecord
8180 , paddingName
82− , paddingNameFloat
8381 , pageClass
8482 , paragraphClass
8583 , reduceRecursive
8684 , reduceStyles
8785 , reduceStylesRecursive
8886 , removeNever
87+ , renderFocusStyle
88+ -- , renderFont
89+
8990 , renderFontClassName
9091 , renderHeight
9192 , renderRoot
92− , renderVariant
9393 , renderWidth
9494 , rootStyle
9595 , rowClass
9696 , singleClass
9797 , spacingName
98+ , staticRoot
9899 , tag
99− , textShadowClass
100+ , textShadowName
100101 , toHtml
101102 , toStyleSheet
102103 , transformClass
103104 , unstyled
104105 , 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 Encode
115+import Json.Encode as Json
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 Float Float Float Float
177+ | PaddingStyle String Int Int Int Int
178178 | GridTemplateStyle
179179 { spacing : ( Length, Length )
180180 , columns : List Length
@@ -222,7 +222,8 @@ type Font
222222 | ImportFont String String
223223 | FontWith
224224 { name : String
225− , adjustment : Maybe Adjustment
225+ , url : Maybe String
226+ , adjustment : Adjustment
226227 , variants : List Variant
227228 }
228229
@@ -245,18 +246,6 @@ renderVariant var =
245246 "\"" ++ name ++ "\" " ++ String.fromInt index
246247
247248
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−
260249renderVariants typeface =
261250 case typeface of
262251 FontWith font ->
@@ -372,13 +361,6 @@ type NodeName
372361 | Embedded String String
373362
374363
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−
382364div =
383365 Generic
384366
@@ -387,7 +369,7 @@ type alias Gathered msg =
387369 { node : NodeName
388370 , attributes : List (VirtualDom.Attribute msg)
389371 , styles : List Style
390− , children : NearbyChildren msg
372+ , children : List (VirtualDom.Node msg)
391373 , has : Flag.Field
392374 }
393375
@@ -455,10 +437,7 @@ finalizeNode has node attributes children embedMode parentContext =
455437 Embedded nodeName internal ->
456438 VirtualDom.node nodeName
457439 attributes
458− [ createNode internal
459− [ Html.Attributes.class
460− (classes.any ++ " " ++ classes.single)
461− ]
440+ [ createNode internal [ Html.Attributes.class (classes.any ++ " " ++ classes.single) ]
462441 ]
463442 in
464443 case parentContext of
@@ -535,45 +514,49 @@ finalizeNode has node attributes children embedMode parentContext =
535514
536515
537516embedWith 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
547517 if static then
548− staticRoot opts
549− :: dynamicStyleSheet
518+ staticRoot
519+ :: (styles
520+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
521+ |> Tuple.second
522+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
523+ -- |> sortedReduce
524+ |> toStyleSheet opts
525+ )
550526 :: children
551527
552528 else
553− dynamicStyleSheet
529+ (styles
530+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
531+ |> Tuple.second
532+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
533+ -- |> sortedReduce
534+ |> toStyleSheet opts
535+ )
554536 :: children
555537
556538
557539embedKeyed 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
567540 if static then
568− ( "static-stylesheet", staticRoot opts )
541+ ( "static-stylesheet", staticRoot )
569542 :: ( "dynamic-stylesheet"
570− , dynamicStyleSheet
543+ , styles
544+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
545+ |> Tuple.second
546+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
547+ -- |> sortedReduce
548+ |> toStyleSheet opts
571549 )
572550 :: children
573551
574552 else
575553 ( "dynamic-stylesheet"
576− , dynamicStyleSheet
554+ , styles
555+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
556+ |> Tuple.second
557+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
558+ -- |> sortedReduce
559+ |> toStyleSheet opts
577560 )
578561 :: children
579562
@@ -889,16 +872,7 @@ skippable flag style =
889872 False
890873
891874
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
875+gatherAttrRecursive : String -> NodeName -> Flag.Field -> Transformation -> List Style -> List (VirtualDom.Attribute msg) -> List (VirtualDom.Node msg) -> List (Attribute aligned msg) -> Gathered msg
902876gatherAttrRecursive classes node has transform styles attrs children elementAttrs =
903877 case elementAttrs of
904878 [] ->
@@ -1032,7 +1006,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
10321006 in
10331007 gatherAttrRecursive (classes ++ " " ++ newClass)
10341008 node
1035− (Flag.merge addToFlags (Flag.add Flag.width has))
1009+ (Flag.merge addToFlags has)
10361010 transform
10371011 (newStyles ++ styles)
10381012 attrs
@@ -1053,7 +1027,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
10531027 name =
10541028 "height-px-" ++ val
10551029 in
1056− gatherAttrRecursive (Internal.Style.classes.heightExact ++ " " ++ name ++ " " ++ classes)
1030+ gatherAttrRecursive (name ++ " " ++ classes)
10571031 node
10581032 (Flag.add Flag.height has)
10591033 transform
@@ -1110,7 +1084,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11101084 in
11111085 gatherAttrRecursive (classes ++ " " ++ newClass)
11121086 node
1113− (Flag.merge addToFlags (Flag.add Flag.height has))
1087+ (Flag.merge addToFlags has)
11141088 transform
11151089 (newStyles ++ styles)
11161090 attrs
@@ -1142,15 +1116,20 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11421116 gatherAttrRecursive classes (addNodeName "h6" node) has transform styles attrs children remaining
11431117
11441118 Paragraph ->
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
1119+ let
1120+ newNode =
1121+ case node of
1122+ Generic ->
1123+ NodeName "p"
1124+
1125+ NodeName name ->
1126+ NodeName name
1127+
1128+ Embedded x y ->
1129+ Embedded x y
1130+ in
1131+ gatherAttrRecursive classes
1132+ newNode
11541133 has
11551134 transform
11561135 styles
@@ -1185,16 +1164,75 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11851164
11861165 Styled styled ->
11871166 styles ++ styled.styles
1167+
1168+ nearbyElement =
1169+ Html.div
1170+ [ Html.Attributes.class <|
1171+ case location of
1172+ Above ->
1173+ String.join " "
1174+ [ Internal.Style.classes.nearby
1175+ , Internal.Style.classes.single
1176+ , Internal.Style.classes.above
1177+ ]
1178+
1179+ Below ->
1180+ String.join " "
1181+ [ Internal.Style.classes.nearby
1182+ , Internal.Style.classes.single
1183+ , Internal.Style.classes.below
1184+ ]
1185+
1186+ OnRight ->
1187+ String.join " "
1188+ [ Internal.Style.classes.nearby
1189+ , Internal.Style.classes.single
1190+ , Internal.Style.classes.onRight
1191+ ]
1192+
1193+ OnLeft ->
1194+ String.join " "
1195+ [ Internal.Style.classes.nearby
1196+ , Internal.Style.classes.single
1197+ , Internal.Style.classes.onLeft
1198+ ]
1199+
1200+ InFront ->
1201+ String.join " "
1202+ [ Internal.Style.classes.nearby
1203+ , Internal.Style.classes.single
1204+ , Internal.Style.classes.inFront
1205+ ]
1206+
1207+ Behind ->
1208+ String.join " "
1209+ [ Internal.Style.classes.nearby
1210+ , Internal.Style.classes.single
1211+ , Internal.Style.classes.behind
1212+ ]
1213+ ]
1214+ [ case elem of
1215+ Empty ->
1216+ VirtualDom.text ""
1217+
1218+ Text str ->
1219+ textElement str
1220+
1221+ Unstyled html ->
1222+ html asEl
1223+
1224+ Styled styled ->
1225+ styled.html NoStyleSheet asEl
1226+ ]
1227+
1228+ newClasses =
1229+ if location == Behind then
1230+ Internal.Style.classes.hasBehind ++ " " ++ classes
1231+
1232+ else
1233+ classes
11881234 in
1189− gatherAttrRecursive
1190− classes
1191− node
1192− has
1193− transform
1194− newStyles
1195− attrs
1196− (addNearbyElement location elem children)
1197− remaining
1235+ gatherAttrRecursive newClasses node has transform newStyles attrs (nearbyElement :: children) remaining
11981236
11991237 AlignX x ->
12001238 if Flag.present Flag.xAlign has then
@@ -1250,106 +1288,6 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
12501288 remaining
12511289
12521290
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−
13531291renderWidth w =
13541292 case w of
13551293 Px px ->
@@ -1436,7 +1374,7 @@ renderHeight h =
14361374 "height-px-" ++ val
14371375 in
14381376 ( Flag.none
1439− , Internal.Style.classes.heightExact ++ " " ++ name
1377+ , name
14401378 , [ Single name "height" (val ++ "px") ]
14411379 )
14421380
@@ -1459,7 +1397,7 @@ renderHeight h =
14591397 , [ Single
14601398 (Internal.Style.classes.any
14611399 ++ "."
1462− ++ Internal.Style.classes.column
1400+ ++ Internal.Style.classes.row
14631401 ++ " > "
14641402 ++ (Internal.Style.dot <| "height-fill-" ++ String.fromInt portion)
14651403 )
@@ -1478,9 +1416,7 @@ renderHeight h =
14781416 Single
14791417 cls
14801418 "min-height"
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")
1419+ (String.fromInt minSize ++ "px")
14841420
14851421 ( newFlag, newAttrs, newStyle ) =
14861422 renderHeight len
@@ -1558,7 +1494,7 @@ element : LayoutContext -> NodeName -> List (Attribute aligned msg) -> Children
15581494element context node attributes children =
15591495 attributes
15601496 |> List.reverse
1561− |> gatherAttrRecursive (contextClasses context) node Flag.none untransformed [] [] NoNearbyChildren
1497+ |> gatherAttrRecursive (contextClasses context) node Flag.none untransformed [] [] []
15621498 |> createElement context children
15631499
15641500
@@ -1625,12 +1561,13 @@ createElement context children rendered =
16251561 -- , existingStyles
16261562 -- )
16271563 -- else
1628− ( (if context == asEl then
1629− textElementFill str
1564+ ( textElement
1565+ (if context == asParagraph then
1566+ str
16301567
1631− else
1632− textElement str
1633− )
1568+ else
1569+ str
1570+ )
16341571 :: htmls
16351572 , existingStyles
16361573 )
@@ -1690,11 +1627,8 @@ createElement context children rendered =
16901627 -- )
16911628 -- else
16921629 ( ( key
1693− , if context == asEl then
1694− textElementFill str
1695−
1696− else
1697− textElement str
1630+ , textElement
1631+ str
16981632 )
16991633 :: htmls
17001634 , existingStyles
@@ -1721,8 +1655,13 @@ createElement context children rendered =
17211655 (finalizeNode rendered.has
17221656 rendered.node
17231657 rendered.attributes
1724− (Keyed
1725− (addKeyedChildren "nearby-element-pls" keyed rendered.children)
1658+ (Keyed <|
1659+ keyed
1660+ ++ List.map
1661+ (\x ->
1662+ ( "nearby-elements-pls", x )
1663+ )
1664+ rendered.children
17261665 )
17271666 NoStyleSheet
17281667 )
@@ -1736,7 +1675,13 @@ createElement context children rendered =
17361675 rendered.node
17371676 rendered.attributes
17381677 (Keyed
1739− (addKeyedChildren "nearby-element-pls" keyed rendered.children)
1678+ (keyed
1679+ ++ List.map
1680+ (\x ->
1681+ ( "nearby-elements-pls", x )
1682+ )
1683+ rendered.children
1684+ )
17401685 )
17411686 }
17421687
@@ -1758,7 +1703,7 @@ createElement context children rendered =
17581703 rendered.has
17591704 rendered.node
17601705 rendered.attributes
1761− (Unkeyed (addChildren unkeyed rendered.children))
1706+ (Unkeyed <| unkeyed ++ rendered.children)
17621707 NoStyleSheet
17631708 )
17641709
@@ -1770,42 +1715,10 @@ createElement context children rendered =
17701715 rendered.has
17711716 rendered.node
17721717 rendered.attributes
1773− (Unkeyed (addChildren unkeyed rendered.children))
1718+ (Unkeyed (unkeyed ++ rendered.children))
17741719 }
17751720
17761721
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−
18091722unit =
18101723 0
18111724
@@ -1817,20 +1730,8 @@ defaultOptions =
18171730 }
18181731
18191732
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) ] []
1733+staticRoot =
1734+ VirtualDom.node "style" [] [ VirtualDom.text Internal.Style.rules ]
18341735
18351736
18361737addWhen ifThis x to =
@@ -1948,7 +1849,7 @@ type Spacing
19481849
19491850
19501851type Padding
1951− = Padding String Float Float Float Float
1852+ = Padding String Int Int Int Int
19521853
19531854
19541855extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing )
@@ -2044,44 +1945,35 @@ getHeight attrs =
20441945 Nothing
20451946
20461947
2047−textElementClasses : String
2048−textElementClasses =
2049− classes.any
2050− ++ " "
2051− ++ classes.text
2052− ++ " "
2053− ++ classes.widthContent
2054− ++ " "
2055− ++ classes.heightContent
2056−
2057−
20581948textElement : String -> VirtualDom.Node msg
20591949textElement str =
20601950 Html.div
20611951 [ Html.Attributes.class
2062− textElementClasses
1952+ (String.join " "
1953+ [ classes.any
1954+ , classes.text
1955+ , classes.widthContent
1956+ , classes.heightContent
1957+ ]
1958+ )
20631959 ]
20641960 [ Html.text str ]
20651961
20661962
2067−textElementFillClasses : String
2068−textElementFillClasses =
2069− classes.any
2070− ++ " "
2071− ++ classes.text
2072− ++ " "
2073− ++ classes.widthFill
2074− ++ " "
2075− ++ classes.heightFill
2076−
2077−
20781963textElementFill : String -> VirtualDom.Node msg
20791964textElementFill str =
2080− Html.div
2081− [ Html.Attributes.class
2082− textElementFillClasses
1965+ VirtualDom.node "div"
1966+ [ VirtualDom.property "className"
1967+ (Json.string <|
1968+ String.join " "
1969+ [ classes.any
1970+ , classes.text
1971+ , classes.widthFill
1972+ , classes.heightFill
1973+ ]
1974+ )
20831975 ]
2084− [ Html.text str ]
1976+ [ VirtualDom.text str ]
20851977
20861978
20871979type Children x
@@ -2089,6 +1981,10 @@ type Children x
20891981 | Keyed (List ( String, x ))
20901982
20911983
1984+
1985+-- toHtml : OptionRecord -> Element msg -> VirtualDom.Node msg
1986+
1987+
20921988toHtml mode el =
20931989 case el of
20941990 Unstyled html ->
@@ -2124,7 +2020,8 @@ renderRoot optionList attributes child =
21242020
21252021
21262022type RenderMode
2127− = Layout
2023+ = Viewport
2024+ | Layout
21282025 | NoStaticStyleSheet
21292026 | WithVirtualCss
21302027
@@ -2173,8 +2070,8 @@ rootStyle =
21732070 , SansSerif
21742071 ]
21752072 in
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))
2073+ [ StyleClass Flag.bgColor (Colored ("bg-color-" ++ formatColorClass (Rgba 1 1 1 0)) "background-color" (Rgba 1 1 1 0))
2074+ , StyleClass Flag.fontColor (Colored ("font-color-" ++ formatColorClass (Rgba 0 0 0 1)) "color" (Rgba 0 0 0 1))
21782075 , StyleClass Flag.fontSize (FontSize 20)
21792076 , StyleClass Flag.fontFamily <|
21802077 FontFamily (List.foldl renderFontClassName "font-" families)
@@ -2217,38 +2114,9 @@ renderFontClassName font current =
22172114
22182115renderFocusStyle :
22192116 FocusStyle
2220− -> List Style
2117+ -> Style
22212118renderFocusStyle 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− )
2119+ Style (Internal.Style.dot classes.any ++ ":focus .focusable, " ++ Internal.Style.dot classes.any ++ ".focusable:focus")
22522120 (List.filterMap identity
22532121 [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
22542122 , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
@@ -2271,7 +2139,6 @@ renderFocusStyle focus =
22712139 , Just <| Property "outline" "none"
22722140 ]
22732141 )
2274− ]
22752142
22762143
22772144focusDefaultStyle : { backgroundColor : Maybe Color, borderColor : Maybe Color, shadow : Maybe Shadow }
@@ -2283,7 +2150,7 @@ focusDefaultStyle =
22832150 { color =
22842151 Rgba (155 / 255) (203 / 255) 1 1
22852152 , offset = ( 0, 0 )
2286− , blur = 0
2153+ , blur = 3
22872154 , size = 3
22882155 }
22892156 }
@@ -2353,31 +2220,7 @@ optionsToRecord options =
23532220
23542221toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
23552222toStyleSheet 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− []
2223+ VirtualDom.node "style" [] [ VirtualDom.text (toStyleSheetString options styleSheet) ]
23812224
23822225
23832226renderTopLevelValues rules =
@@ -2387,12 +2230,14 @@ renderTopLevelValues rules =
23872230 ImportFont _ url ->
23882231 Just ("@import url('" ++ url ++ "');")
23892232
2390− -- FontWith with ->
2391− -- case with.url of
2392− -- Just x ->
2393− -- Just ("@import url('" ++ x ++ "');")
2394− -- Nothing ->
2395− -- Nothing
2233+ FontWith with ->
2234+ case with.url of
2235+ Just x ->
2236+ Just ("@import url('" ++ x ++ "');")
2237+
2238+ Nothing ->
2239+ Nothing
2240+
23962241 _ ->
23972242 Nothing
23982243
@@ -2463,38 +2308,7 @@ renderNullAdjustmentRule fontToAdjust otherFontName =
24632308 ]
24642309
24652310
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 =
2311+renderFontAdjustmentRule fontToAdjust ( parentAdj, textAdjustment ) otherFontName =
24982312 let
24992313 name =
25002314 if fontToAdjust == otherFontName then
@@ -2504,7 +2318,34 @@ renderFontAdjustmentRule fontToAdjust ( full, capital ) otherFontName =
25042318 otherFontName ++ " ." ++ fontToAdjust
25052319 in
25062320 String.join " "
2507− (fontRule name classes.sizeByCapital capital ++ fontRule name classes.fullSize full)
2321+ [ bracket
2322+ ("."
2323+ ++ name
2324+ ++ "."
2325+ ++ classes.sizeByCapital
2326+ ++ ", "
2327+ ++ "."
2328+ ++ name
2329+ ++ " ."
2330+ ++ classes.sizeByCapital
2331+ )
2332+ parentAdj
2333+ , bracket
2334+ ("."
2335+ ++ name
2336+ ++ "."
2337+ ++ classes.sizeByCapital
2338+ ++ "> ."
2339+ ++ Internal.Style.classes.text
2340+ ++ ", ."
2341+ ++ name
2342+ ++ " ."
2343+ ++ classes.sizeByCapital
2344+ ++ " > ."
2345+ ++ Internal.Style.classes.text
2346+ )
2347+ textAdjustment
2348+ ]
25082349
25092350
25102351bracket selector rules =
@@ -2517,12 +2358,17 @@ bracket selector rules =
25172358
25182359fontAdjustmentRules converted =
25192360 ( [ ( "display", "block" )
2361+
2362+ -- , ( "line-height", String.fromFloat converted.height )
2363+ -- , ( "font-size", String.fromFloat (1 + converted.height + converted.vertical) ++ "em" )
25202364 ]
25212365 , [ ( "display", "inline-block" )
25222366 , ( "line-height", String.fromFloat converted.height )
25232367 , ( "vertical-align", String.fromFloat converted.vertical ++ "em" )
25242368 , ( "font-size", String.fromFloat converted.size ++ "em" )
25252369 ]
2370+ -- , [ ( "font-size", String.fromFloat converted.size ++ "em" )
2371+ -- ]
25262372 )
25272373
25282374
@@ -2533,17 +2379,10 @@ typefaceAdjustment typefaces =
25332379 Nothing ->
25342380 case face of
25352381 FontWith with ->
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− )
2382+ Just
2383+ (fontAdjustmentRules
2384+ (.capital (convertAdjustment with.adjustment))
2385+ )
25472386
25482387 _ ->
25492388 found
@@ -2593,492 +2432,489 @@ renderProps force (Property key val) existing =
25932432 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
25942433
25952434
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−
26092435toStyleSheetString : OptionRecord -> List Style -> String
26102436toStyleSheetString options stylesheet =
26112437 let
2612− combine style rendered =
2613− { rules = rendered.rules ++ renderStyleRule options style Nothing
2614− , topLevel =
2615− case topLevelValue style of
2616− Nothing ->
2617− rendered.topLevel
2438+ renderStyle maybePseudo selector props =
2439+ case maybePseudo of
2440+ Nothing ->
2441+ selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}"
26182442
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
2443+ Just pseudo ->
2444+ case pseudo of
2445+ Hover ->
2446+ case options.hover of
2447+ NoHover ->
2448+ ""
26262449
2450+ ForceHover ->
2451+ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}"
26272452
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}" ]
2453+ AllowHover ->
2454+ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}"
26332455
2634− Just pseudo ->
2635− case pseudo of
2636− Hover ->
2637− case options.hover of
2638− NoHover ->
2639− []
2456+ Focus ->
2457+ let
2458+ renderedProps =
2459+ List.foldl (renderProps False) "" props
2460+ in
2461+ String.join "\n"
2462+ [ selector
2463+ ++ "-fs:focus {"
2464+ ++ renderedProps
2465+ ++ "\n}"
2466+ , "."
2467+ ++ classes.any
2468+ ++ ":focus ~ "
2469+ ++ selector
2470+ ++ "-fs:not(.focus) {"
2471+ ++ renderedProps
2472+ ++ "\n}"
2473+ , "."
2474+ ++ classes.any
2475+ ++ ":focus "
2476+ ++ selector
2477+ ++ "-fs {"
2478+ ++ renderedProps
2479+ ++ "\n}"
2480+ , ".focusable-parent:focus ~ "
2481+ ++ "."
2482+ ++ classes.any
2483+ ++ " "
2484+ ++ selector
2485+ ++ "-fs {"
2486+ ++ renderedProps
2487+ ++ "\n}"
2488+ ]
26402489
2641− ForceHover ->
2642− [ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}" ]
2490+ Active ->
2491+ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}"
26432492
2644− AllowHover ->
2645− [ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2493+ renderStyleRule rule maybePseudo =
2494+ case rule of
2495+ Style selector props ->
2496+ renderStyle maybePseudo selector props
26462497
2647− Focus ->
2498+ Shadows name prop ->
2499+ renderStyle
2500+ maybePseudo
2501+ ("." ++ name)
2502+ [ Property "box-shadow" prop
2503+ ]
2504+
2505+ Transparency name transparency ->
26482506 let
2649− renderedProps =
2650− List.foldl (renderProps False) "" props
2507+ opacity =
2508+ (1 - transparency)
2509+ |> min 1
2510+ |> max 0
26512511 in
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− ]
2663−
2664− Active ->
2665− [ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2666−
2667−
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− ]
2680−
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− ]
2693−
2694− FontSize i ->
2695− renderStyle options
2696− maybePseudo
2697− (".font-size-" ++ String.fromInt i)
2698− [ Property "font-size" (String.fromInt i ++ "px")
2699− ]
2700−
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"
2718−
2719− else
2720− "normal"
2721− )
2722− ]
2723− in
2724− renderStyle options
2725− maybePseudo
2726− ("." ++ name)
2727− families
2728−
2729− Single class prop val ->
2730− renderStyle options
2731− maybePseudo
2732− ("." ++ class)
2733− [ Property prop val
2734− ]
2512+ renderStyle
2513+ maybePseudo
2514+ ("." ++ name)
2515+ [ Property "opacity" (String.fromFloat opacity)
2516+ ]
27352517
2736− Colored class prop color ->
2737− renderStyle options
2738− maybePseudo
2739− ("." ++ class)
2740− [ Property prop (formatColor color)
2741− ]
2518+ FontSize i ->
2519+ renderStyle
2520+ maybePseudo
2521+ (".font-size-" ++ String.fromInt i)
2522+ [ Property "font-size" (String.fromInt i ++ "px")
2523+ ]
27422524
2743− SpacingStyle cls x y ->
2744− let
2745− class =
2746− "." ++ cls
2525+ FontFamily name typefaces ->
2526+ let
2527+ features =
2528+ typefaces
2529+ |> List.filterMap renderVariants
2530+ |> String.join ", "
2531+
2532+ families =
2533+ [ Property "font-family"
2534+ (typefaces
2535+ |> List.map fontName
2536+ |> String.join ", "
2537+ )
2538+ , Property "font-feature-settings" features
2539+ , Property "font-variant"
2540+ (if List.any hasSmallCaps typefaces then
2541+ "small-caps"
27472542
2748− halfX =
2749− String.fromFloat (toFloat x / 2) ++ "px"
2543+ else
2544+ "normal"
2545+ )
2546+ ]
2547+ in
2548+ String.join " "
2549+ [ renderStyle
2550+ maybePseudo
2551+ ("." ++ name)
2552+ families
2553+ ]
27502554
2751− halfY =
2752− String.fromFloat (toFloat y / 2) ++ "px"
2555+ Single class prop val ->
2556+ renderStyle
2557+ maybePseudo
2558+ ("." ++ class)
2559+ [ Property prop val
2560+ ]
27532561
2754− xPx =
2755− String.fromInt x ++ "px"
2562+ Colored class prop color ->
2563+ renderStyle
2564+ maybePseudo
2565+ ("." ++ class)
2566+ [ Property prop (formatColor color)
2567+ ]
27562568
2757− yPx =
2758− String.fromInt y ++ "px"
2569+ SpacingStyle cls x y ->
2570+ let
2571+ class =
2572+ "." ++ cls
27592573
2760− row =
2761− "." ++ Internal.Style.classes.row
2574+ halfX =
2575+ String.fromFloat (toFloat x / 2) ++ "px"
27622576
2763− wrappedRow =
2764− "." ++ Internal.Style.classes.wrapped ++ row
2577+ halfY =
2578+ String.fromFloat (toFloat y / 2) ++ "px"
27652579
2766− column =
2767− "." ++ Internal.Style.classes.column
2580+ xPx =
2581+ String.fromInt x ++ "px"
27682582
2769− page =
2770− "." ++ Internal.Style.classes.page
2583+ yPx =
2584+ String.fromInt y ++ "px"
27712585
2772− paragraph =
2773− "." ++ Internal.Style.classes.paragraph
2586+ row =
2587+ "." ++ Internal.Style.classes.row
27742588
2775− left =
2776− "." ++ Internal.Style.classes.alignLeft
2589+ wrappedRow =
2590+ "." ++ Internal.Style.classes.wrapped ++ row
27772591
2778− right =
2779− "." ++ Internal.Style.classes.alignRight
2592+ column =
2593+ "." ++ Internal.Style.classes.column
27802594
2781− any =
2782− "." ++ Internal.Style.classes.any
2595+ page =
2596+ "." ++ Internal.Style.classes.page
27832597
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− ]
2598+ paragraph =
2599+ "." ++ Internal.Style.classes.paragraph
27982600
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− ]
2601+ left =
2602+ "." ++ Internal.Style.classes.alignLeft
28192603
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− ]
2604+ right =
2605+ "." ++ Internal.Style.classes.alignRight
28552606
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− ]
2607+ any =
2608+ "." ++ Internal.Style.classes.any
28762609
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
2976− |> String.join " "
2977− |> (\x -> "grid-template-columns: " ++ x ++ ";")
2978−
2979− rows =
2980− template.rows
2981− |> List.map toGridLength
2982− |> String.join " "
2983− |> (\x -> "grid-template-rows: " ++ x ++ ";")
2984−
2985− gapX =
2986− "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2610+ single =
2611+ "." ++ Internal.Style.classes.single
2612+ in
2613+ String.concat
2614+ [ renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
2615+
2616+ -- margins don't apply to last element of normal, unwrapped rows
2617+ -- , renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
2618+ -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
2619+ , renderStyle maybePseudo
2620+ (class ++ wrappedRow ++ " > " ++ any)
2621+ [ Property "margin" (halfY ++ " " ++ halfX)
2622+ ]
29872623
2988− gapY =
2989− "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2624+ -- , renderStyle maybePseudo
2625+ -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2626+ -- [ Property "margin-right" "0"
2627+ -- ]
2628+ -- columns
2629+ , renderStyle maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2630+ , renderStyle maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2631+ , renderStyle maybePseudo (class ++ page ++ " > " ++ left) [ Property "margin-right" xPx ]
2632+ , renderStyle maybePseudo (class ++ page ++ " > " ++ right) [ Property "margin-left" xPx ]
2633+ , renderStyle
2634+ maybePseudo
2635+ (class ++ paragraph)
2636+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2637+ ]
2638+ , renderStyle
2639+ maybePseudo
2640+ ("textarea" ++ class)
2641+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2642+ ]
29902643
2991− modernGrid =
2992− class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2644+ -- , renderStyle
2645+ -- maybePseudo
2646+ -- (class ++ paragraph ++ " > " ++ any)
2647+ -- [ Property "margin-right" xPx
2648+ -- , Property "margin-bottom" yPx
2649+ -- ]
2650+ , renderStyle
2651+ maybePseudo
2652+ (class ++ paragraph ++ " > " ++ left)
2653+ [ Property "margin-right" xPx
2654+ ]
2655+ , renderStyle
2656+ maybePseudo
2657+ (class ++ paragraph ++ " > " ++ right)
2658+ [ Property "margin-left" xPx
2659+ ]
2660+ , renderStyle
2661+ maybePseudo
2662+ (class ++ paragraph ++ "::after")
2663+ [ Property "content" "''"
2664+ , Property "display" "block"
2665+ , Property "height" "0"
2666+ , Property "width" "0"
2667+ , Property "margin-top" (String.fromInt (-1 * (y // 2)) ++ "px")
2668+ ]
2669+ , renderStyle
2670+ maybePseudo
2671+ (class ++ paragraph ++ "::before")
2672+ [ Property "content" "''"
2673+ , Property "display" "block"
2674+ , Property "height" "0"
2675+ , Property "width" "0"
2676+ , Property "margin-bottom" (String.fromInt (-1 * (y // 2)) ++ "px")
2677+ ]
2678+ ]
29932679
2994− supports =
2995− "@supports (display:grid) {" ++ modernGrid ++ "}"
2996− in
2997− [ base
2998− , supports
2999− ]
2680+ PaddingStyle cls top right bottom left ->
2681+ let
2682+ class =
2683+ "."
2684+ ++ cls
2685+ in
2686+ renderStyle
2687+ maybePseudo
2688+ class
2689+ [ Property "padding"
2690+ (String.fromInt top
2691+ ++ "px "
2692+ ++ String.fromInt right
2693+ ++ "px "
2694+ ++ String.fromInt bottom
2695+ ++ "px "
2696+ ++ String.fromInt left
2697+ ++ "px"
2698+ )
2699+ ]
30002700
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− ++ ";"
2701+ BorderWidth cls top right bottom left ->
2702+ let
2703+ class =
2704+ "."
2705+ ++ cls
2706+ in
2707+ renderStyle
2708+ maybePseudo
2709+ class
2710+ [ Property "border-width"
2711+ (String.fromInt top
2712+ ++ "px "
2713+ ++ String.fromInt right
2714+ ++ "px "
2715+ ++ String.fromInt bottom
2716+ ++ "px "
2717+ ++ String.fromInt left
2718+ ++ "px"
2719+ )
30272720 ]
30282721
3029− base =
3030− class ++ "{" ++ msPosition ++ "}"
2722+ GridTemplateStyle template ->
2723+ let
2724+ class =
2725+ ".grid-rows-"
2726+ ++ String.join "-" (List.map lengthClassName template.rows)
2727+ ++ "-cols-"
2728+ ++ String.join "-" (List.map lengthClassName template.columns)
2729+ ++ "-space-x-"
2730+ ++ lengthClassName (Tuple.first template.spacing)
2731+ ++ "-space-y-"
2732+ ++ lengthClassName (Tuple.second template.spacing)
2733+
2734+ ySpacing =
2735+ toGridLength (Tuple.second template.spacing)
2736+
2737+ xSpacing =
2738+ toGridLength (Tuple.first template.spacing)
2739+
2740+ toGridLength x =
2741+ toGridLengthHelper Nothing Nothing x
2742+
2743+ toGridLengthHelper minimum maximum x =
2744+ case x of
2745+ Px px ->
2746+ String.fromInt px ++ "px"
2747+
2748+ Content ->
2749+ case ( minimum, maximum ) of
2750+ ( Nothing, Nothing ) ->
2751+ "max-content"
2752+
2753+ ( Just minSize, Nothing ) ->
2754+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2755+
2756+ ( Nothing, Just maxSize ) ->
2757+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2758+
2759+ ( Just minSize, Just maxSize ) ->
2760+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2761+
2762+ Fill i ->
2763+ case ( minimum, maximum ) of
2764+ ( Nothing, Nothing ) ->
2765+ String.fromInt i ++ "fr"
2766+
2767+ ( Just minSize, Nothing ) ->
2768+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2769+
2770+ ( Nothing, Just maxSize ) ->
2771+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2772+
2773+ ( Just minSize, Just maxSize ) ->
2774+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2775+
2776+ Min m len ->
2777+ toGridLengthHelper (Just m) maximum len
2778+
2779+ Max m len ->
2780+ toGridLengthHelper minimum (Just m) len
2781+
2782+ msColumns =
2783+ template.columns
2784+ |> List.map toGridLength
2785+ |> String.join ySpacing
2786+ |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2787+
2788+ msRows =
2789+ template.columns
2790+ |> List.map toGridLength
2791+ |> String.join ySpacing
2792+ |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
2793+
2794+ base =
2795+ class ++ "{" ++ msColumns ++ msRows ++ "}"
2796+
2797+ columns =
2798+ template.columns
2799+ |> List.map toGridLength
2800+ |> String.join " "
2801+ |> (\x -> "grid-template-columns: " ++ x ++ ";")
2802+
2803+ rows =
2804+ template.rows
2805+ |> List.map toGridLength
2806+ |> String.join " "
2807+ |> (\x -> "grid-template-rows: " ++ x ++ ";")
2808+
2809+ gapX =
2810+ "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2811+
2812+ gapY =
2813+ "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2814+
2815+ modernGrid =
2816+ class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2817+
2818+ supports =
2819+ "@supports (display:grid) {" ++ modernGrid ++ "}"
2820+ in
2821+ base ++ supports
30312822
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− ]
2823+ GridPosition position ->
2824+ let
2825+ class =
2826+ ".grid-pos-"
2827+ ++ String.fromInt position.row
2828+ ++ "-"
2829+ ++ String.fromInt position.col
2830+ ++ "-"
2831+ ++ String.fromInt position.width
2832+ ++ "-"
2833+ ++ String.fromInt position.height
2834+
2835+ msPosition =
2836+ String.join " "
2837+ [ "-ms-grid-row: "
2838+ ++ String.fromInt position.row
2839+ ++ ";"
2840+ , "-ms-grid-row-span: "
2841+ ++ String.fromInt position.height
2842+ ++ ";"
2843+ , "-ms-grid-column: "
2844+ ++ String.fromInt position.col
2845+ ++ ";"
2846+ , "-ms-grid-column-span: "
2847+ ++ String.fromInt position.width
2848+ ++ ";"
2849+ ]
2850+
2851+ base =
2852+ class ++ "{" ++ msPosition ++ "}"
2853+
2854+ modernPosition =
2855+ String.join " "
2856+ [ "grid-row: "
2857+ ++ String.fromInt position.row
2858+ ++ " / "
2859+ ++ String.fromInt (position.row + position.height)
2860+ ++ ";"
2861+ , "grid-column: "
2862+ ++ String.fromInt position.col
2863+ ++ " / "
2864+ ++ String.fromInt (position.col + position.width)
2865+ ++ ";"
2866+ ]
2867+
2868+ modernGrid =
2869+ class ++ "{" ++ modernPosition ++ "}"
2870+
2871+ supports =
2872+ "@supports (display:grid) {" ++ modernGrid ++ "}"
2873+ in
2874+ base ++ supports
30452875
3046− modernGrid =
3047− class ++ "{" ++ modernPosition ++ "}"
2876+ PseudoSelector class styles ->
2877+ let
2878+ renderPseudoRule style =
2879+ renderStyleRule style (Just class)
2880+ in
2881+ List.map renderPseudoRule styles
2882+ |> String.join " "
30482883
3049− supports =
3050− "@supports (display:grid) {" ++ modernGrid ++ "}"
3051− in
3052− [ base
3053− , supports
3054− ]
2884+ Transform transform ->
2885+ let
2886+ val =
2887+ transformValue transform
30552888
3056− PseudoSelector class styles ->
3057− let
3058− renderPseudoRule style =
3059− renderStyleRule options style (Just class)
3060− in
3061− List.concatMap renderPseudoRule styles
2889+ class =
2890+ transformClass transform
2891+ in
2892+ case ( class, val ) of
2893+ ( Just cls, Just v ) ->
2894+ renderStyle
2895+ maybePseudo
2896+ ("." ++ cls)
2897+ [ Property "transform"
2898+ v
2899+ ]
30622900
3063− Transform transform ->
3064− let
3065− val =
3066− transformValue transform
2901+ _ ->
2902+ ""
30672903
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− ]
2904+ combine style rendered =
2905+ { rules = rendered.rules ++ renderStyleRule style Nothing
2906+ , topLevel =
2907+ case topLevelValue style of
2908+ Nothing ->
2909+ rendered.topLevel
30792910
3080− _ ->
3081− []
2911+ Just topLevel ->
2912+ topLevel :: rendered.topLevel
2913+ }
2914+ in
2915+ case List.foldl combine { topLevel = [], rules = "" } stylesheet of
2916+ { topLevel, rules } ->
2917+ renderTopLevelValues topLevel ++ rules
30822918
30832919
30842920lengthClassName : Length -> String
@@ -3118,12 +2954,12 @@ formatTextShadow shadow =
31182954 ]
31192955
31202956
3121−textShadowClass shadow =
2957+textShadowName shadow =
31222958 String.concat
31232959 [ "txt"
3124− , floatClass (Tuple.first shadow.offset) ++ "px"
3125− , floatClass (Tuple.second shadow.offset) ++ "px"
3126− , floatClass shadow.blur ++ "px"
2960+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2961+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2962+ , String.fromFloat shadow.blur ++ "px"
31272963 , formatColorClass shadow.color
31282964 ]
31292965
@@ -3144,17 +2980,17 @@ formatBoxShadow shadow =
31442980 ]
31452981
31462982
3147−boxShadowClass shadow =
2983+boxShadowName shadow =
31482984 String.concat <|
31492985 [ if shadow.inset then
31502986 "box-inset"
31512987
31522988 else
31532989 "box-"
3154− , floatClass (Tuple.first shadow.offset) ++ "px"
3155− , floatClass (Tuple.second shadow.offset) ++ "px"
3156− , floatClass shadow.blur ++ "px"
3157− , floatClass shadow.size ++ "px"
2990+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2991+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2992+ , String.fromFloat shadow.blur ++ "px"
2993+ , String.fromFloat shadow.size ++ "px"
31582994 , formatColorClass shadow.color
31592995 ]
31602996
@@ -3199,17 +3035,6 @@ paddingName top right bottom left =
31993035 ++ String.fromInt left
32003036
32013037
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−
32133038getStyleName : Style -> String
32143039getStyleName style =
32153040 case style of
@@ -3527,16 +3352,16 @@ convertAdjustment adjustment =
35273352 capitalSize =
35283353 1 / (ascender - newBaseline)
35293354
3530− fullSize =
3531− 1 / (ascender - descender)
3532−
35333355 fullVertical =
3534− 1 - ascender
3535−
3536− -- (oldMiddle - newFullMiddle) * 2
3356+ (oldMiddle - newFullMiddle) * 2
35373357 in
35383358 { full =
3539− adjust fullSize (ascender - descender) fullVertical
3359+ { vertical = fullVertical
3360+ , height =
3361+ (ascender - descender)
3362+ - abs fullVertical
3363+ , size = 1.0
3364+ }
35403365 , capital =
35413366 adjust capitalSize (ascender - newBaseline) capitalVertical
35423367 }
@@ -3546,5 +3371,7 @@ adjust size height vertical =
35463371 { vertical = vertical
35473372 , height =
35483373 height / size
3374+
3375+ -- vertical
35493376 , size = size
35503377 }