@@ -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,46 +246,13 @@ 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 ->
263− Just (String.join ", " (List.map renderVariant font.variants))
252+ String.join ", " (List.map renderVariant font.variants)
264253
265254 _ ->
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
255+ ""
288256
289257
290258type Property
@@ -372,13 +340,6 @@ type NodeName
372340 | Embedded String String
373341
374342
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−
382343div =
383344 Generic
384345
@@ -387,7 +348,7 @@ type alias Gathered msg =
387348 { node : NodeName
388349 , attributes : List (VirtualDom.Attribute msg)
389350 , styles : List Style
390− , children : NearbyChildren msg
351+ , children : List (VirtualDom.Node msg)
391352 , has : Flag.Field
392353 }
393354
@@ -455,10 +416,7 @@ finalizeNode has node attributes children embedMode parentContext =
455416 Embedded nodeName internal ->
456417 VirtualDom.node nodeName
457418 attributes
458− [ createNode internal
459− [ Html.Attributes.class
460− (classes.any ++ " " ++ classes.single)
461− ]
419+ [ createNode internal [ Html.Attributes.class (classes.any ++ " " ++ classes.single) ]
462420 ]
463421 in
464422 case parentContext of
@@ -535,45 +493,49 @@ finalizeNode has node attributes children embedMode parentContext =
535493
536494
537495embedWith 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
547496 if static then
548− staticRoot opts
549− :: dynamicStyleSheet
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+ )
550505 :: children
551506
552507 else
553− dynamicStyleSheet
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+ )
554515 :: children
555516
556517
557518embedKeyed 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
567519 if static then
568− ( "static-stylesheet", staticRoot opts )
520+ ( "static-stylesheet", staticRoot )
569521 :: ( "dynamic-stylesheet"
570− , dynamicStyleSheet
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
571528 )
572529 :: children
573530
574531 else
575532 ( "dynamic-stylesheet"
576− , dynamicStyleSheet
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
577539 )
578540 :: children
579541
@@ -889,16 +851,7 @@ skippable flag style =
889851 False
890852
891853
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
854+gatherAttrRecursive : String -> NodeName -> Flag.Field -> Transformation -> List Style -> List (VirtualDom.Attribute msg) -> List (VirtualDom.Node msg) -> List (Attribute aligned msg) -> Gathered msg
902855gatherAttrRecursive classes node has transform styles attrs children elementAttrs =
903856 case elementAttrs of
904857 [] ->
@@ -1032,7 +985,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1032985 in
1033986 gatherAttrRecursive (classes ++ " " ++ newClass)
1034987 node
1035− (Flag.merge addToFlags (Flag.add Flag.width has))
988+ (Flag.merge addToFlags has)
1036989 transform
1037990 (newStyles ++ styles)
1038991 attrs
@@ -1053,7 +1006,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
10531006 name =
10541007 "height-px-" ++ val
10551008 in
1056− gatherAttrRecursive (Internal.Style.classes.heightExact ++ " " ++ name ++ " " ++ classes)
1009+ gatherAttrRecursive (name ++ " " ++ classes)
10571010 node
10581011 (Flag.add Flag.height has)
10591012 transform
@@ -1110,7 +1063,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11101063 in
11111064 gatherAttrRecursive (classes ++ " " ++ newClass)
11121065 node
1113− (Flag.merge addToFlags (Flag.add Flag.height has))
1066+ (Flag.merge addToFlags has)
11141067 transform
11151068 (newStyles ++ styles)
11161069 attrs
@@ -1142,15 +1095,20 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11421095 gatherAttrRecursive classes (addNodeName "h6" node) has transform styles attrs children remaining
11431096
11441097 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
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
11541112 has
11551113 transform
11561114 styles
@@ -1185,16 +1143,75 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11851143
11861144 Styled styled ->
11871145 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
11881213 in
1189− gatherAttrRecursive
1190− classes
1191− node
1192− has
1193− transform
1194− newStyles
1195− attrs
1196− (addNearbyElement location elem children)
1197− remaining
1214+ gatherAttrRecursive newClasses node has transform newStyles attrs (nearbyElement :: children) remaining
11981215
11991216 AlignX x ->
12001217 if Flag.present Flag.xAlign has then
@@ -1250,106 +1267,6 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
12501267 remaining
12511268
12521269
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−
13531270renderWidth w =
13541271 case w of
13551272 Px px ->
@@ -1436,7 +1353,7 @@ renderHeight h =
14361353 "height-px-" ++ val
14371354 in
14381355 ( Flag.none
1439− , Internal.Style.classes.heightExact ++ " " ++ name
1356+ , name
14401357 , [ Single name "height" (val ++ "px") ]
14411358 )
14421359
@@ -1459,7 +1376,7 @@ renderHeight h =
14591376 , [ Single
14601377 (Internal.Style.classes.any
14611378 ++ "."
1462− ++ Internal.Style.classes.column
1379+ ++ Internal.Style.classes.row
14631380 ++ " > "
14641381 ++ (Internal.Style.dot <| "height-fill-" ++ String.fromInt portion)
14651382 )
@@ -1478,9 +1395,7 @@ renderHeight h =
14781395 Single
14791396 cls
14801397 "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")
1398+ (String.fromInt minSize ++ "px")
14841399
14851400 ( newFlag, newAttrs, newStyle ) =
14861401 renderHeight len
@@ -1558,7 +1473,7 @@ element : LayoutContext -> NodeName -> List (Attribute aligned msg) -> Children
15581473element context node attributes children =
15591474 attributes
15601475 |> List.reverse
1561− |> gatherAttrRecursive (contextClasses context) node Flag.none untransformed [] [] NoNearbyChildren
1476+ |> gatherAttrRecursive (contextClasses context) node Flag.none untransformed [] [] []
15621477 |> createElement context children
15631478
15641479
@@ -1625,12 +1540,13 @@ createElement context children rendered =
16251540 -- , existingStyles
16261541 -- )
16271542 -- else
1628− ( (if context == asEl then
1629− textElementFill str
1543+ ( textElement
1544+ (if context == asParagraph then
1545+ str
16301546
1631− else
1632− textElement str
1633− )
1547+ else
1548+ str
1549+ )
16341550 :: htmls
16351551 , existingStyles
16361552 )
@@ -1690,11 +1606,8 @@ createElement context children rendered =
16901606 -- )
16911607 -- else
16921608 ( ( key
1693− , if context == asEl then
1694− textElementFill str
1695−
1696− else
1697− textElement str
1609+ , textElement
1610+ str
16981611 )
16991612 :: htmls
17001613 , existingStyles
@@ -1721,8 +1634,13 @@ createElement context children rendered =
17211634 (finalizeNode rendered.has
17221635 rendered.node
17231636 rendered.attributes
1724− (Keyed
1725− (addKeyedChildren "nearby-element-pls" keyed rendered.children)
1637+ (Keyed <|
1638+ keyed
1639+ ++ List.map
1640+ (\x ->
1641+ ( "nearby-elements-pls", x )
1642+ )
1643+ rendered.children
17261644 )
17271645 NoStyleSheet
17281646 )
@@ -1736,7 +1654,13 @@ createElement context children rendered =
17361654 rendered.node
17371655 rendered.attributes
17381656 (Keyed
1739− (addKeyedChildren "nearby-element-pls" keyed rendered.children)
1657+ (keyed
1658+ ++ List.map
1659+ (\x ->
1660+ ( "nearby-elements-pls", x )
1661+ )
1662+ rendered.children
1663+ )
17401664 )
17411665 }
17421666
@@ -1758,7 +1682,7 @@ createElement context children rendered =
17581682 rendered.has
17591683 rendered.node
17601684 rendered.attributes
1761− (Unkeyed (addChildren unkeyed rendered.children))
1685+ (Unkeyed <| unkeyed ++ rendered.children)
17621686 NoStyleSheet
17631687 )
17641688
@@ -1770,42 +1694,10 @@ createElement context children rendered =
17701694 rendered.has
17711695 rendered.node
17721696 rendered.attributes
1773− (Unkeyed (addChildren unkeyed rendered.children))
1697+ (Unkeyed (unkeyed ++ rendered.children))
17741698 }
17751699
17761700
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−
18091701unit =
18101702 0
18111703
@@ -1817,20 +1709,8 @@ defaultOptions =
18171709 }
18181710
18191711
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) ] []
1712+staticRoot =
1713+ VirtualDom.node "style" [] [ VirtualDom.text Internal.Style.rules ]
18341714
18351715
18361716addWhen ifThis x to =
@@ -1948,7 +1828,7 @@ type Spacing
19481828
19491829
19501830type Padding
1951− = Padding String Float Float Float Float
1831+ = Padding String Int Int Int Int
19521832
19531833
19541834extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing )
@@ -2044,44 +1924,35 @@ getHeight attrs =
20441924 Nothing
20451925
20461926
2047−textElementClasses : String
2048−textElementClasses =
2049− classes.any
2050− ++ " "
2051− ++ classes.text
2052− ++ " "
2053− ++ classes.widthContent
2054− ++ " "
2055− ++ classes.heightContent
2056−
2057−
20581927textElement : String -> VirtualDom.Node msg
20591928textElement str =
20601929 Html.div
20611930 [ Html.Attributes.class
2062− textElementClasses
1931+ (String.join " "
1932+ [ classes.any
1933+ , classes.text
1934+ , classes.widthContent
1935+ , classes.heightContent
1936+ ]
1937+ )
20631938 ]
20641939 [ Html.text str ]
20651940
20661941
2067−textElementFillClasses : String
2068−textElementFillClasses =
2069− classes.any
2070− ++ " "
2071− ++ classes.text
2072− ++ " "
2073− ++ classes.widthFill
2074− ++ " "
2075− ++ classes.heightFill
2076−
2077−
20781942textElementFill : String -> VirtualDom.Node msg
20791943textElementFill str =
2080− Html.div
2081− [ Html.Attributes.class
2082− textElementFillClasses
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+ )
20831954 ]
2084− [ Html.text str ]
1955+ [ VirtualDom.text str ]
20851956
20861957
20871958type Children x
@@ -2089,6 +1960,10 @@ type Children x
20891960 | Keyed (List ( String, x ))
20901961
20911962
1963+
1964+-- toHtml : OptionRecord -> Element msg -> VirtualDom.Node msg
1965+
1966+
20921967toHtml mode el =
20931968 case el of
20941969 Unstyled html ->
@@ -2124,7 +1999,8 @@ renderRoot optionList attributes child =
21241999
21252000
21262001type RenderMode
2127− = Layout
2002+ = Viewport
2003+ | Layout
21282004 | NoStaticStyleSheet
21292005 | WithVirtualCss
21302006
@@ -2173,8 +2049,8 @@ rootStyle =
21732049 , SansSerif
21742050 ]
21752051 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))
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))
21782054 , StyleClass Flag.fontSize (FontSize 20)
21792055 , StyleClass Flag.fontFamily <|
21802056 FontFamily (List.foldl renderFontClassName "font-" families)
@@ -2217,38 +2093,9 @@ renderFontClassName font current =
22172093
22182094renderFocusStyle :
22192095 FocusStyle
2220− -> List Style
2096+ -> Style
22212097renderFocusStyle 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− )
2098+ Style (Internal.Style.dot classes.any ++ ":focus .focusable, " ++ Internal.Style.dot classes.any ++ ".focusable:focus")
22522099 (List.filterMap identity
22532100 [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
22542101 , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
@@ -2271,7 +2118,6 @@ renderFocusStyle focus =
22712118 , Just <| Property "outline" "none"
22722119 ]
22732120 )
2274− ]
22752121
22762122
22772123focusDefaultStyle : { backgroundColor : Maybe Color, borderColor : Maybe Color, shadow : Maybe Shadow }
@@ -2283,7 +2129,7 @@ focusDefaultStyle =
22832129 { color =
22842130 Rgba (155 / 255) (203 / 255) 1 1
22852131 , offset = ( 0, 0 )
2286− , blur = 0
2132+ , blur = 3
22872133 , size = 3
22882134 }
22892135 }
@@ -2353,31 +2199,7 @@ optionsToRecord options =
23532199
23542200toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
23552201toStyleSheet 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− []
2202+ VirtualDom.node "style" [] [ VirtualDom.text (toStyleSheetString options styleSheet) ]
23812203
23822204
23832205renderTopLevelValues rules =
@@ -2387,12 +2209,14 @@ renderTopLevelValues rules =
23872209 ImportFont _ url ->
23882210 Just ("@import url('" ++ url ++ "');")
23892211
2390− -- FontWith with ->
2391− -- case with.url of
2392− -- Just x ->
2393− -- Just ("@import url('" ++ x ++ "');")
2394− -- Nothing ->
2395− -- Nothing
2212+ FontWith with ->
2213+ case with.url of
2214+ Just x ->
2215+ Just ("@import url('" ++ x ++ "');")
2216+
2217+ Nothing ->
2218+ Nothing
2219+
23962220 _ ->
23972221 Nothing
23982222
@@ -2463,38 +2287,7 @@ renderNullAdjustmentRule fontToAdjust otherFontName =
24632287 ]
24642288
24652289
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 =
2290+renderFontAdjustmentRule fontToAdjust ( parentAdj, textAdjustment ) otherFontName =
24982291 let
24992292 name =
25002293 if fontToAdjust == otherFontName then
@@ -2504,7 +2297,34 @@ renderFontAdjustmentRule fontToAdjust ( full, capital ) otherFontName =
25042297 otherFontName ++ " ." ++ fontToAdjust
25052298 in
25062299 String.join " "
2507− (fontRule name classes.sizeByCapital capital ++ fontRule name classes.fullSize full)
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+ ]
25082328
25092329
25102330bracket selector rules =
@@ -2517,12 +2337,17 @@ bracket selector rules =
25172337
25182338fontAdjustmentRules converted =
25192339 ( [ ( "display", "block" )
2340+
2341+ -- , ( "line-height", String.fromFloat converted.height )
2342+ -- , ( "font-size", String.fromFloat (1 + converted.height + converted.vertical) ++ "em" )
25202343 ]
25212344 , [ ( "display", "inline-block" )
25222345 , ( "line-height", String.fromFloat converted.height )
25232346 , ( "vertical-align", String.fromFloat converted.vertical ++ "em" )
25242347 , ( "font-size", String.fromFloat converted.size ++ "em" )
25252348 ]
2349+ -- , [ ( "font-size", String.fromFloat converted.size ++ "em" )
2350+ -- ]
25262351 )
25272352
25282353
@@ -2533,17 +2358,10 @@ typefaceAdjustment typefaces =
25332358 Nothing ->
25342359 case face of
25352360 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− )
2361+ Just
2362+ (fontAdjustmentRules
2363+ (.capital (convertAdjustment with.adjustment))
2364+ )
25472365
25482366 _ ->
25492367 found
@@ -2593,492 +2411,482 @@ renderProps force (Property key val) existing =
25932411 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
25942412
25952413
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−
26092414toStyleSheetString : OptionRecord -> List Style -> String
26102415toStyleSheetString options stylesheet =
26112416 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
2417+ renderStyle maybePseudo selector props =
2418+ case maybePseudo of
2419+ Nothing ->
2420+ selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}"
26182421
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
2422+ Just pseudo ->
2423+ case pseudo of
2424+ Hover ->
2425+ case options.hover of
2426+ NoHover ->
2427+ ""
26262428
2429+ ForceHover ->
2430+ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}"
26272431
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}" ]
2432+ AllowHover ->
2433+ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}"
26332434
2634− Just pseudo ->
2635− case pseudo of
2636− Hover ->
2637− case options.hover of
2638− NoHover ->
2639− []
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+ ]
26402468
2641− ForceHover ->
2642− [ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}" ]
2469+ Active ->
2470+ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}"
26432471
2644− AllowHover ->
2645− [ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2472+ renderStyleRule rule maybePseudo =
2473+ case rule of
2474+ Style selector props ->
2475+ renderStyle maybePseudo selector props
26462476
2647− Focus ->
2477+ Shadows name prop ->
2478+ renderStyle
2479+ maybePseudo
2480+ ("." ++ name)
2481+ [ Property "box-shadow" prop
2482+ ]
2483+
2484+ Transparency name transparency ->
26482485 let
2649− renderedProps =
2650− List.foldl (renderProps False) "" props
2486+ opacity =
2487+ (1 - transparency)
2488+ |> min 1
2489+ |> max 0
26512490 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− ]
2735−
2736− Colored class prop color ->
2737− renderStyle options
2738− maybePseudo
2739− ("." ++ class)
2740− [ Property prop (formatColor color)
2741− ]
2742−
2743− SpacingStyle cls x y ->
2744− let
2745− class =
2746− "." ++ cls
2747−
2748− halfX =
2749− String.fromFloat (toFloat x / 2) ++ "px"
2750−
2751− halfY =
2752− String.fromFloat (toFloat y / 2) ++ "px"
2491+ renderStyle
2492+ maybePseudo
2493+ ("." ++ name)
2494+ [ Property "opacity" (String.fromFloat opacity)
2495+ ]
27532496
2754− xPx =
2755− String.fromInt x ++ "px"
2497+ FontSize i ->
2498+ renderStyle
2499+ maybePseudo
2500+ (".font-size-" ++ String.fromInt i)
2501+ [ Property "font-size" (String.fromInt i ++ "px")
2502+ ]
27562503
2757− yPx =
2758− String.fromInt y ++ "px"
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+ ]
27592526
2760− row =
2761− "." ++ Internal.Style.classes.row
2527+ Single class prop val ->
2528+ renderStyle
2529+ maybePseudo
2530+ ("." ++ class)
2531+ [ Property prop val
2532+ ]
27622533
2763− wrappedRow =
2764− "." ++ Internal.Style.classes.wrapped ++ row
2534+ Colored class prop color ->
2535+ renderStyle
2536+ maybePseudo
2537+ ("." ++ class)
2538+ [ Property prop (formatColor color)
2539+ ]
27652540
2766− column =
2767− "." ++ Internal.Style.classes.column
2541+ SpacingStyle cls x y ->
2542+ let
2543+ class =
2544+ "." ++ cls
27682545
2769− page =
2770− "." ++ Internal.Style.classes.page
2546+ halfX =
2547+ String.fromFloat (toFloat x / 2) ++ "px"
27712548
2772− paragraph =
2773− "." ++ Internal.Style.classes.paragraph
2549+ halfY =
2550+ String.fromFloat (toFloat y / 2) ++ "px"
27742551
2775− left =
2776− "." ++ Internal.Style.classes.alignLeft
2552+ xPx =
2553+ String.fromInt x ++ "px"
27772554
2778− right =
2779− "." ++ Internal.Style.classes.alignRight
2555+ yPx =
2556+ String.fromInt y ++ "px"
27802557
2781− any =
2782− "." ++ Internal.Style.classes.any
2558+ row =
2559+ "." ++ Internal.Style.classes.row
27832560
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− ]
2561+ wrappedRow =
2562+ "." ++ Internal.Style.classes.wrapped ++ row
27982563
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− ]
2564+ column =
2565+ "." ++ Internal.Style.classes.column
28192566
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− ]
2567+ page =
2568+ "." ++ Internal.Style.classes.page
28552569
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− ]
2570+ paragraph =
2571+ "." ++ Internal.Style.classes.paragraph
28762572
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− ]
2573+ left =
2574+ "." ++ Internal.Style.classes.alignLeft
28972575
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 ++ ";")
2576+ right =
2577+ "." ++ Internal.Style.classes.alignRight
29782578
2979− rows =
2980− template.rows
2981− |> List.map toGridLength
2982− |> String.join " "
2983− |> (\x -> "grid-template-rows: " ++ x ++ ";")
2579+ any =
2580+ "." ++ Internal.Style.classes.any
29842581
2985− gapX =
2986− "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
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+ ]
29872595
2988− gapY =
2989− "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
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+ ]
29902615
2991− modernGrid =
2992− class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
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+ ]
29932651
2994− supports =
2995− "@supports (display:grid) {" ++ modernGrid ++ "}"
2996− in
2997− [ base
2998− , supports
2999− ]
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+ ]
30002672
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− ++ ";"
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+ )
30272692 ]
30282693
3029− base =
3030− class ++ "{" ++ msPosition ++ "}"
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
30312794
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− ]
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
30452847
3046− modernGrid =
3047− class ++ "{" ++ modernPosition ++ "}"
2848+ PseudoSelector class styles ->
2849+ let
2850+ renderPseudoRule style =
2851+ renderStyleRule style (Just class)
2852+ in
2853+ List.map renderPseudoRule styles
2854+ |> String.join " "
30482855
3049− supports =
3050− "@supports (display:grid) {" ++ modernGrid ++ "}"
3051− in
3052− [ base
3053− , supports
3054− ]
2856+ Transform transform ->
2857+ let
2858+ val =
2859+ transformValue transform
30552860
3056− PseudoSelector class styles ->
3057− let
3058− renderPseudoRule style =
3059− renderStyleRule options style (Just class)
3060− in
3061− List.concatMap renderPseudoRule styles
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+ ]
30622872
3063− Transform transform ->
3064− let
3065− val =
3066− transformValue transform
2873+ _ ->
2874+ ""
30672875
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− ]
2876+ combine style rendered =
2877+ { rules = rendered.rules ++ renderStyleRule style Nothing
2878+ , topLevel =
2879+ case topLevelValue style of
2880+ Nothing ->
2881+ rendered.topLevel
30792882
3080− _ ->
3081− []
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
30822890
30832891
30842892lengthClassName : Length -> String
@@ -3118,12 +2926,12 @@ formatTextShadow shadow =
31182926 ]
31192927
31202928
3121−textShadowClass shadow =
2929+textShadowName shadow =
31222930 String.concat
31232931 [ "txt"
3124− , floatClass (Tuple.first shadow.offset) ++ "px"
3125− , floatClass (Tuple.second shadow.offset) ++ "px"
3126− , floatClass shadow.blur ++ "px"
2932+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2933+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2934+ , String.fromFloat shadow.blur ++ "px"
31272935 , formatColorClass shadow.color
31282936 ]
31292937
@@ -3144,17 +2952,17 @@ formatBoxShadow shadow =
31442952 ]
31452953
31462954
3147−boxShadowClass shadow =
2955+boxShadowName shadow =
31482956 String.concat <|
31492957 [ if shadow.inset then
31502958 "box-inset"
31512959
31522960 else
31532961 "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"
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"
31582966 , formatColorClass shadow.color
31592967 ]
31602968
@@ -3199,17 +3007,6 @@ paddingName top right bottom left =
31993007 ++ String.fromInt left
32003008
32013009
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−
32133010getStyleName : Style -> String
32143011getStyleName style =
32153012 case style of
@@ -3527,16 +3324,16 @@ convertAdjustment adjustment =
35273324 capitalSize =
35283325 1 / (ascender - newBaseline)
35293326
3530− fullSize =
3531− 1 / (ascender - descender)
3532−
35333327 fullVertical =
3534− 1 - ascender
3535−
3536− -- (oldMiddle - newFullMiddle) * 2
3328+ (oldMiddle - newFullMiddle) * 2
35373329 in
35383330 { full =
3539− adjust fullSize (ascender - descender) fullVertical
3331+ { vertical = fullVertical
3332+ , height =
3333+ (ascender - descender)
3334+ - abs fullVertical
3335+ , size = 1.0
3336+ }
35403337 , capital =
35413338 adjust capitalSize (ascender - newBaseline) capitalVertical
35423339 }
@@ -3546,5 +3343,7 @@ adjust size height vertical =
35463343 { vertical = vertical
35473344 , height =
35483345 height / size
3346+
3347+ -- vertical
35493348 , size = size
35503349 }