@@ -16,7 +16,6 @@ module Internal.Model exposing
1616 , LayoutContext(..)
1717 , Length(..)
1818 , Location(..)
19− , NearbyChildren(..)
2019 , NodeName(..)
2120 , Option(..)
2221 , OptionRecord
@@ -30,7 +29,6 @@ module Internal.Model exposing
3029 , TransformComponent(..)
3130 , Transformation(..)
3231 , VAlign(..)
33− , Variant(..)
3432 , XYZ
3533 , addNodeName
3634 , addWhen
@@ -42,7 +40,7 @@ module Internal.Model exposing
4240 , asParagraph
4341 , asRow
4442 , asTextColumn
45− , boxShadowClass
43+ , boxShadowName
4644 , columnClass
4745 , composeTransformation
4846 , contextClasses
@@ -79,30 +77,31 @@ module Internal.Model exposing
7977 , onlyStyles
8078 , optionsToRecord
8179 , paddingName
82− , paddingNameFloat
8380 , pageClass
8481 , paragraphClass
8582 , reduceRecursive
8683 , reduceStyles
8784 , reduceStylesRecursive
8885 , removeNever
86+ , renderFocusStyle
87+ -- , renderFont
88+
8989 , renderFontClassName
9090 , renderHeight
9191 , renderRoot
92− , renderVariant
9392 , renderWidth
9493 , rootStyle
9594 , rowClass
9695 , singleClass
9796 , spacingName
97+ , staticRoot
9898 , tag
99− , textShadowClass
99+ , textShadowName
100100 , toHtml
101101 , toStyleSheet
102102 , transformClass
103103 , unstyled
104104 , unwrapDecorations
105− , variantName
106105 )
107106
108107{-| -}
@@ -112,7 +111,7 @@ import Html.Attributes
112111import Html.Keyed
113112import Internal.Flag as Flag exposing (Flag)
114113import Internal.Style exposing (classes, dot)
115−import Json.Encode as Encode
114+import Json.Encode as Json
116115import Set exposing (Set)
117116import VirtualDom
118117
@@ -174,7 +173,7 @@ type Style
174173 | Colored String String Color
175174 | SpacingStyle String Int Int
176175 | BorderWidth String Int Int Int Int
177− | PaddingStyle String Float Float Float Float
176+ | PaddingStyle String Int Int Int Int
178177 | GridTemplateStyle
179178 { spacing : ( Length, Length )
180179 , columns : List Length
@@ -222,71 +221,11 @@ type Font
222221 | ImportFont String String
223222 | FontWith
224223 { name : String
225− , adjustment : Maybe Adjustment
226− , variants : List Variant
224+ , url : Maybe String
225+ , adjustment : Adjustment
227226 }
228227
229228
230−type Variant
231− = VariantActive String
232− | VariantOff String
233− | VariantIndexed String Int
234−
235−
236−renderVariant var =
237− case var of
238− VariantActive name ->
239− "\"" ++ name ++ "\""
240−
241− VariantOff name ->
242− "\"" ++ name ++ "\" 0"
243−
244− VariantIndexed name index ->
245− "\"" ++ name ++ "\" " ++ String.fromInt index
246−
247−
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−
260−renderVariants typeface =
261− case typeface of
262− FontWith font ->
263− Just (String.join ", " (List.map renderVariant font.variants))
264−
265− _ ->
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
288−
289−
290229type Property
291230 = Property String String
292231
@@ -372,13 +311,6 @@ type NodeName
372311 | Embedded String String
373312
374313
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−
382314div =
383315 Generic
384316
@@ -387,7 +319,7 @@ type alias Gathered msg =
387319 { node : NodeName
388320 , attributes : List (VirtualDom.Attribute msg)
389321 , styles : List Style
390− , children : NearbyChildren msg
322+ , children : List (VirtualDom.Node msg)
391323 , has : Flag.Field
392324 }
393325
@@ -455,10 +387,7 @@ finalizeNode has node attributes children embedMode parentContext =
455387 Embedded nodeName internal ->
456388 VirtualDom.node nodeName
457389 attributes
458− [ createNode internal
459− [ Html.Attributes.class
460− (classes.any ++ " " ++ classes.single)
461− ]
390+ [ createNode internal [ Html.Attributes.class (classes.any ++ " " ++ classes.single) ]
462391 ]
463392 in
464393 case parentContext of
@@ -535,45 +464,49 @@ finalizeNode has node attributes children embedMode parentContext =
535464
536465
537466embedWith 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
547467 if static then
548− staticRoot opts
549− :: dynamicStyleSheet
468+ staticRoot
469+ :: (styles
470+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
471+ |> Tuple.second
472+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
473+ -- |> sortedReduce
474+ |> toStyleSheet opts
475+ )
550476 :: children
551477
552478 else
553− dynamicStyleSheet
479+ (styles
480+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
481+ |> Tuple.second
482+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
483+ -- |> sortedReduce
484+ |> toStyleSheet opts
485+ )
554486 :: children
555487
556488
557489embedKeyed 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
567490 if static then
568− ( "static-stylesheet", staticRoot opts )
491+ ( "static-stylesheet", staticRoot )
569492 :: ( "dynamic-stylesheet"
570− , dynamicStyleSheet
493+ , styles
494+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
495+ |> Tuple.second
496+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
497+ -- |> sortedReduce
498+ |> toStyleSheet opts
571499 )
572500 :: children
573501
574502 else
575503 ( "dynamic-stylesheet"
576− , dynamicStyleSheet
504+ , styles
505+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
506+ |> Tuple.second
507+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
508+ -- |> sortedReduce
509+ |> toStyleSheet opts
577510 )
578511 :: children
579512
@@ -889,16 +822,7 @@ skippable flag style =
889822 False
890823
891824
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
825+gatherAttrRecursive : String -> NodeName -> Flag.Field -> Transformation -> List Style -> List (VirtualDom.Attribute msg) -> List (VirtualDom.Node msg) -> List (Attribute aligned msg) -> Gathered msg
902826gatherAttrRecursive classes node has transform styles attrs children elementAttrs =
903827 case elementAttrs of
904828 [] ->
@@ -1032,7 +956,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1032956 in
1033957 gatherAttrRecursive (classes ++ " " ++ newClass)
1034958 node
1035− (Flag.merge addToFlags (Flag.add Flag.width has))
959+ (Flag.merge addToFlags has)
1036960 transform
1037961 (newStyles ++ styles)
1038962 attrs
@@ -1053,7 +977,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1053977 name =
1054978 "height-px-" ++ val
1055979 in
1056− gatherAttrRecursive (Internal.Style.classes.heightExact ++ " " ++ name ++ " " ++ classes)
980+ gatherAttrRecursive (name ++ " " ++ classes)
1057981 node
1058982 (Flag.add Flag.height has)
1059983 transform
@@ -1110,7 +1034,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11101034 in
11111035 gatherAttrRecursive (classes ++ " " ++ newClass)
11121036 node
1113− (Flag.merge addToFlags (Flag.add Flag.height has))
1037+ (Flag.merge addToFlags has)
11141038 transform
11151039 (newStyles ++ styles)
11161040 attrs
@@ -1142,15 +1066,20 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11421066 gatherAttrRecursive classes (addNodeName "h6" node) has transform styles attrs children remaining
11431067
11441068 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
1069+ let
1070+ newNode =
1071+ case node of
1072+ Generic ->
1073+ NodeName "p"
1074+
1075+ NodeName name ->
1076+ NodeName name
1077+
1078+ Embedded x y ->
1079+ Embedded x y
1080+ in
1081+ gatherAttrRecursive classes
1082+ newNode
11541083 has
11551084 transform
11561085 styles
@@ -1185,16 +1114,75 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
11851114
11861115 Styled styled ->
11871116 styles ++ styled.styles
1117+
1118+ nearbyElement =
1119+ Html.div
1120+ [ Html.Attributes.class <|
1121+ case location of
1122+ Above ->
1123+ String.join " "
1124+ [ Internal.Style.classes.nearby
1125+ , Internal.Style.classes.single
1126+ , Internal.Style.classes.above
1127+ ]
1128+
1129+ Below ->
1130+ String.join " "
1131+ [ Internal.Style.classes.nearby
1132+ , Internal.Style.classes.single
1133+ , Internal.Style.classes.below
1134+ ]
1135+
1136+ OnRight ->
1137+ String.join " "
1138+ [ Internal.Style.classes.nearby
1139+ , Internal.Style.classes.single
1140+ , Internal.Style.classes.onRight
1141+ ]
1142+
1143+ OnLeft ->
1144+ String.join " "
1145+ [ Internal.Style.classes.nearby
1146+ , Internal.Style.classes.single
1147+ , Internal.Style.classes.onLeft
1148+ ]
1149+
1150+ InFront ->
1151+ String.join " "
1152+ [ Internal.Style.classes.nearby
1153+ , Internal.Style.classes.single
1154+ , Internal.Style.classes.inFront
1155+ ]
1156+
1157+ Behind ->
1158+ String.join " "
1159+ [ Internal.Style.classes.nearby
1160+ , Internal.Style.classes.single
1161+ , Internal.Style.classes.behind
1162+ ]
1163+ ]
1164+ [ case elem of
1165+ Empty ->
1166+ VirtualDom.text ""
1167+
1168+ Text str ->
1169+ textElement str
1170+
1171+ Unstyled html ->
1172+ html asEl
1173+
1174+ Styled styled ->
1175+ styled.html NoStyleSheet asEl
1176+ ]
1177+
1178+ newClasses =
1179+ if location == Behind then
1180+ Internal.Style.classes.hasBehind ++ " " ++ classes
1181+
1182+ else
1183+ classes
11881184 in
1189− gatherAttrRecursive
1190− classes
1191− node
1192− has
1193− transform
1194− newStyles
1195− attrs
1196− (addNearbyElement location elem children)
1197− remaining
1185+ gatherAttrRecursive newClasses node has transform newStyles attrs (nearbyElement :: children) remaining
11981186
11991187 AlignX x ->
12001188 if Flag.present Flag.xAlign has then
@@ -1250,106 +1238,6 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
12501238 remaining
12511239
12521240
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−
13531241renderWidth w =
13541242 case w of
13551243 Px px ->
@@ -1436,7 +1324,7 @@ renderHeight h =
14361324 "height-px-" ++ val
14371325 in
14381326 ( Flag.none
1439− , Internal.Style.classes.heightExact ++ " " ++ name
1327+ , name
14401328 , [ Single name "height" (val ++ "px") ]
14411329 )
14421330
@@ -1459,7 +1347,7 @@ renderHeight h =
14591347 , [ Single
14601348 (Internal.Style.classes.any
14611349 ++ "."
1462− ++ Internal.Style.classes.column
1350+ ++ Internal.Style.classes.row
14631351 ++ " > "
14641352 ++ (Internal.Style.dot <| "height-fill-" ++ String.fromInt portion)
14651353 )
@@ -1478,9 +1366,7 @@ renderHeight h =
14781366 Single
14791367 cls
14801368 "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")
1369+ (String.fromInt minSize ++ "px")
14841370
14851371 ( newFlag, newAttrs, newStyle ) =
14861372 renderHeight len
@@ -1558,7 +1444,7 @@ element : LayoutContext -> NodeName -> List (Attribute aligned msg) -> Children
15581444element context node attributes children =
15591445 attributes
15601446 |> List.reverse
1561− |> gatherAttrRecursive (contextClasses context) node Flag.none untransformed [] [] NoNearbyChildren
1447+ |> gatherAttrRecursive (contextClasses context) node Flag.none untransformed [] [] []
15621448 |> createElement context children
15631449
15641450
@@ -1625,12 +1511,13 @@ createElement context children rendered =
16251511 -- , existingStyles
16261512 -- )
16271513 -- else
1628− ( (if context == asEl then
1629− textElementFill str
1514+ ( textElement
1515+ (if context == asParagraph then
1516+ str
16301517
1631− else
1632− textElement str
1633− )
1518+ else
1519+ str
1520+ )
16341521 :: htmls
16351522 , existingStyles
16361523 )
@@ -1690,11 +1577,8 @@ createElement context children rendered =
16901577 -- )
16911578 -- else
16921579 ( ( key
1693− , if context == asEl then
1694− textElementFill str
1695−
1696− else
1697− textElement str
1580+ , textElement
1581+ str
16981582 )
16991583 :: htmls
17001584 , existingStyles
@@ -1721,8 +1605,13 @@ createElement context children rendered =
17211605 (finalizeNode rendered.has
17221606 rendered.node
17231607 rendered.attributes
1724− (Keyed
1725− (addKeyedChildren "nearby-element-pls" keyed rendered.children)
1608+ (Keyed <|
1609+ keyed
1610+ ++ List.map
1611+ (\x ->
1612+ ( "nearby-elements-pls", x )
1613+ )
1614+ rendered.children
17261615 )
17271616 NoStyleSheet
17281617 )
@@ -1736,7 +1625,13 @@ createElement context children rendered =
17361625 rendered.node
17371626 rendered.attributes
17381627 (Keyed
1739− (addKeyedChildren "nearby-element-pls" keyed rendered.children)
1628+ (keyed
1629+ ++ List.map
1630+ (\x ->
1631+ ( "nearby-elements-pls", x )
1632+ )
1633+ rendered.children
1634+ )
17401635 )
17411636 }
17421637
@@ -1758,7 +1653,7 @@ createElement context children rendered =
17581653 rendered.has
17591654 rendered.node
17601655 rendered.attributes
1761− (Unkeyed (addChildren unkeyed rendered.children))
1656+ (Unkeyed <| unkeyed ++ rendered.children)
17621657 NoStyleSheet
17631658 )
17641659
@@ -1770,42 +1665,10 @@ createElement context children rendered =
17701665 rendered.has
17711666 rendered.node
17721667 rendered.attributes
1773− (Unkeyed (addChildren unkeyed rendered.children))
1668+ (Unkeyed (unkeyed ++ rendered.children))
17741669 }
17751670
17761671
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−
18091672unit =
18101673 0
18111674
@@ -1817,20 +1680,8 @@ defaultOptions =
18171680 }
18181681
18191682
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) ] []
1683+staticRoot =
1684+ VirtualDom.node "style" [] [ VirtualDom.text Internal.Style.rules ]
18341685
18351686
18361687addWhen ifThis x to =
@@ -1948,7 +1799,7 @@ type Spacing
19481799
19491800
19501801type Padding
1951− = Padding String Float Float Float Float
1802+ = Padding String Int Int Int Int
19521803
19531804
19541805extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing )
@@ -2044,44 +1895,35 @@ getHeight attrs =
20441895 Nothing
20451896
20461897
2047−textElementClasses : String
2048−textElementClasses =
2049− classes.any
2050− ++ " "
2051− ++ classes.text
2052− ++ " "
2053− ++ classes.widthContent
2054− ++ " "
2055− ++ classes.heightContent
2056−
2057−
20581898textElement : String -> VirtualDom.Node msg
20591899textElement str =
20601900 Html.div
20611901 [ Html.Attributes.class
2062− textElementClasses
1902+ (String.join " "
1903+ [ classes.any
1904+ , classes.text
1905+ , classes.widthContent
1906+ , classes.heightContent
1907+ ]
1908+ )
20631909 ]
20641910 [ Html.text str ]
20651911
20661912
2067−textElementFillClasses : String
2068−textElementFillClasses =
2069− classes.any
2070− ++ " "
2071− ++ classes.text
2072− ++ " "
2073− ++ classes.widthFill
2074− ++ " "
2075− ++ classes.heightFill
2076−
2077−
20781913textElementFill : String -> VirtualDom.Node msg
20791914textElementFill str =
2080− Html.div
2081− [ Html.Attributes.class
2082− textElementFillClasses
1915+ VirtualDom.node "div"
1916+ [ VirtualDom.property "className"
1917+ (Json.string <|
1918+ String.join " "
1919+ [ classes.any
1920+ , classes.text
1921+ , classes.widthFill
1922+ , classes.heightFill
1923+ ]
1924+ )
20831925 ]
2084− [ Html.text str ]
1926+ [ VirtualDom.text str ]
20851927
20861928
20871929type Children x
@@ -2089,6 +1931,10 @@ type Children x
20891931 | Keyed (List ( String, x ))
20901932
20911933
1934+
1935+-- toHtml : OptionRecord -> Element msg -> VirtualDom.Node msg
1936+
1937+
20921938toHtml mode el =
20931939 case el of
20941940 Unstyled html ->
@@ -2124,7 +1970,8 @@ renderRoot optionList attributes child =
21241970
21251971
21261972type RenderMode
2127− = Layout
1973+ = Viewport
1974+ | Layout
21281975 | NoStaticStyleSheet
21291976 | WithVirtualCss
21301977
@@ -2173,8 +2020,8 @@ rootStyle =
21732020 , SansSerif
21742021 ]
21752022 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))
2023+ [ StyleClass Flag.bgColor (Colored ("bg-color-" ++ formatColorClass (Rgba 1 1 1 0)) "background-color" (Rgba 1 1 1 0))
2024+ , StyleClass Flag.fontColor (Colored ("font-color-" ++ formatColorClass (Rgba 0 0 0 1)) "color" (Rgba 0 0 0 1))
21782025 , StyleClass Flag.fontSize (FontSize 20)
21792026 , StyleClass Flag.fontFamily <|
21802027 FontFamily (List.foldl renderFontClassName "font-" families)
@@ -2217,38 +2064,9 @@ renderFontClassName font current =
22172064
22182065renderFocusStyle :
22192066 FocusStyle
2220− -> List Style
2067+ -> Style
22212068renderFocusStyle 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− )
2069+ Style (Internal.Style.dot classes.any ++ ":focus .focusable, " ++ Internal.Style.dot classes.any ++ ".focusable:focus")
22522070 (List.filterMap identity
22532071 [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
22542072 , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
@@ -2271,7 +2089,6 @@ renderFocusStyle focus =
22712089 , Just <| Property "outline" "none"
22722090 ]
22732091 )
2274− ]
22752092
22762093
22772094focusDefaultStyle : { backgroundColor : Maybe Color, borderColor : Maybe Color, shadow : Maybe Shadow }
@@ -2283,7 +2100,7 @@ focusDefaultStyle =
22832100 { color =
22842101 Rgba (155 / 255) (203 / 255) 1 1
22852102 , offset = ( 0, 0 )
2286− , blur = 0
2103+ , blur = 3
22872104 , size = 3
22882105 }
22892106 }
@@ -2353,31 +2170,7 @@ optionsToRecord options =
23532170
23542171toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
23552172toStyleSheet 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− []
2173+ VirtualDom.node "style" [] [ VirtualDom.text (toStyleSheetString options styleSheet) ]
23812174
23822175
23832176renderTopLevelValues rules =
@@ -2387,12 +2180,14 @@ renderTopLevelValues rules =
23872180 ImportFont _ url ->
23882181 Just ("@import url('" ++ url ++ "');")
23892182
2390− -- FontWith with ->
2391− -- case with.url of
2392− -- Just x ->
2393− -- Just ("@import url('" ++ x ++ "');")
2394− -- Nothing ->
2395− -- Nothing
2183+ FontWith with ->
2184+ case with.url of
2185+ Just x ->
2186+ Just ("@import url('" ++ x ++ "');")
2187+
2188+ Nothing ->
2189+ Nothing
2190+
23962191 _ ->
23972192 Nothing
23982193
@@ -2463,38 +2258,7 @@ renderNullAdjustmentRule fontToAdjust otherFontName =
24632258 ]
24642259
24652260
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 =
2261+renderFontAdjustmentRule fontToAdjust ( parentAdj, textAdjustment ) otherFontName =
24982262 let
24992263 name =
25002264 if fontToAdjust == otherFontName then
@@ -2504,7 +2268,34 @@ renderFontAdjustmentRule fontToAdjust ( full, capital ) otherFontName =
25042268 otherFontName ++ " ." ++ fontToAdjust
25052269 in
25062270 String.join " "
2507− (fontRule name classes.sizeByCapital capital ++ fontRule name classes.fullSize full)
2271+ [ bracket
2272+ ("."
2273+ ++ name
2274+ ++ "."
2275+ ++ classes.sizeByCapital
2276+ ++ ", "
2277+ ++ "."
2278+ ++ name
2279+ ++ " ."
2280+ ++ classes.sizeByCapital
2281+ )
2282+ parentAdj
2283+ , bracket
2284+ ("."
2285+ ++ name
2286+ ++ "."
2287+ ++ classes.sizeByCapital
2288+ ++ "> ."
2289+ ++ Internal.Style.classes.text
2290+ ++ ", ."
2291+ ++ name
2292+ ++ " ."
2293+ ++ classes.sizeByCapital
2294+ ++ " > ."
2295+ ++ Internal.Style.classes.text
2296+ )
2297+ textAdjustment
2298+ ]
25082299
25092300
25102301bracket selector rules =
@@ -2517,12 +2308,17 @@ bracket selector rules =
25172308
25182309fontAdjustmentRules converted =
25192310 ( [ ( "display", "block" )
2311+
2312+ -- , ( "line-height", String.fromFloat converted.height )
2313+ -- , ( "font-size", String.fromFloat (1 + converted.height + converted.vertical) ++ "em" )
25202314 ]
25212315 , [ ( "display", "inline-block" )
25222316 , ( "line-height", String.fromFloat converted.height )
25232317 , ( "vertical-align", String.fromFloat converted.vertical ++ "em" )
25242318 , ( "font-size", String.fromFloat converted.size ++ "em" )
25252319 ]
2320+ -- , [ ( "font-size", String.fromFloat converted.size ++ "em" )
2321+ -- ]
25262322 )
25272323
25282324
@@ -2533,17 +2329,10 @@ typefaceAdjustment typefaces =
25332329 Nothing ->
25342330 case face of
25352331 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− )
2332+ Just
2333+ (fontAdjustmentRules
2334+ (.capital (convertAdjustment with.adjustment))
2335+ )
25472336
25482337 _ ->
25492338 found
@@ -2593,492 +2382,475 @@ renderProps force (Property key val) existing =
25932382 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
25942383
25952384
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−
26092385toStyleSheetString : OptionRecord -> List Style -> String
26102386toStyleSheetString options stylesheet =
26112387 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
2388+ renderStyle maybePseudo selector props =
2389+ case maybePseudo of
2390+ Nothing ->
2391+ selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}"
26182392
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
2393+ Just pseudo ->
2394+ case pseudo of
2395+ Hover ->
2396+ case options.hover of
2397+ NoHover ->
2398+ ""
26262399
2400+ ForceHover ->
2401+ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}"
26272402
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}" ]
2403+ AllowHover ->
2404+ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}"
26332405
2634− Just pseudo ->
2635− case pseudo of
2636− Hover ->
2637− case options.hover of
2638− NoHover ->
2639− []
2406+ Focus ->
2407+ let
2408+ renderedProps =
2409+ List.foldl (renderProps False) "" props
2410+ in
2411+ String.join "\n"
2412+ [ selector
2413+ ++ "-fs:focus {"
2414+ ++ renderedProps
2415+ ++ "\n}"
2416+ , "."
2417+ ++ classes.any
2418+ ++ ":focus ~ "
2419+ ++ selector
2420+ ++ "-fs:not(.focus) {"
2421+ ++ renderedProps
2422+ ++ "\n}"
2423+ , "."
2424+ ++ classes.any
2425+ ++ ":focus "
2426+ ++ selector
2427+ ++ "-fs {"
2428+ ++ renderedProps
2429+ ++ "\n}"
2430+ , ".focusable-parent:focus ~ "
2431+ ++ "."
2432+ ++ classes.any
2433+ ++ " "
2434+ ++ selector
2435+ ++ "-fs {"
2436+ ++ renderedProps
2437+ ++ "\n}"
2438+ ]
2439+
2440+ Active ->
2441+ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}"
26402442
2641− ForceHover ->
2642− [ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}" ]
2443+ renderStyleRule rule maybePseudo =
2444+ case rule of
2445+ Style selector props ->
2446+ renderStyle maybePseudo selector props
26432447
2644− AllowHover ->
2645− [ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2448+ Shadows name prop ->
2449+ renderStyle
2450+ maybePseudo
2451+ ("." ++ name)
2452+ [ Property "box-shadow" prop
2453+ ]
26462454
2647− Focus ->
2455+ Transparency name transparency ->
26482456 let
2649− renderedProps =
2650− List.foldl (renderProps False) "" props
2457+ opacity =
2458+ (1 - transparency)
2459+ |> min 1
2460+ |> max 0
26512461 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"
2462+ renderStyle
2463+ maybePseudo
2464+ ("." ++ name)
2465+ [ Property "opacity" (String.fromFloat opacity)
2466+ ]
27532467
2754− xPx =
2755− String.fromInt x ++ "px"
2468+ FontSize i ->
2469+ renderStyle
2470+ maybePseudo
2471+ (".font-size-" ++ String.fromInt i)
2472+ [ Property "font-size" (String.fromInt i ++ "px")
2473+ ]
27562474
2757− yPx =
2758− String.fromInt y ++ "px"
2475+ FontFamily name typefaces ->
2476+ let
2477+ families =
2478+ Property "font-family"
2479+ (typefaces
2480+ |> List.map fontName
2481+ |> String.join ", "
2482+ )
2483+ in
2484+ String.join " "
2485+ [ renderStyle
2486+ maybePseudo
2487+ ("." ++ name)
2488+ [ families ]
2489+ ]
27592490
2760− row =
2761− "." ++ Internal.Style.classes.row
2491+ Single class prop val ->
2492+ renderStyle
2493+ maybePseudo
2494+ ("." ++ class)
2495+ [ Property prop val
2496+ ]
27622497
2763− wrappedRow =
2764− "." ++ Internal.Style.classes.wrapped ++ row
2498+ Colored class prop color ->
2499+ renderStyle
2500+ maybePseudo
2501+ ("." ++ class)
2502+ [ Property prop (formatColor color)
2503+ ]
27652504
2766− column =
2767− "." ++ Internal.Style.classes.column
2505+ SpacingStyle cls x y ->
2506+ let
2507+ class =
2508+ "." ++ cls
27682509
2769− page =
2770− "." ++ Internal.Style.classes.page
2510+ halfX =
2511+ String.fromFloat (toFloat x / 2) ++ "px"
27712512
2772− paragraph =
2773− "." ++ Internal.Style.classes.paragraph
2513+ halfY =
2514+ String.fromFloat (toFloat y / 2) ++ "px"
27742515
2775− left =
2776− "." ++ Internal.Style.classes.alignLeft
2516+ xPx =
2517+ String.fromInt x ++ "px"
27772518
2778− right =
2779− "." ++ Internal.Style.classes.alignRight
2519+ yPx =
2520+ String.fromInt y ++ "px"
27802521
2781− any =
2782− "." ++ Internal.Style.classes.any
2522+ row =
2523+ "." ++ Internal.Style.classes.row
27832524
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− ]
2525+ wrappedRow =
2526+ "." ++ Internal.Style.classes.wrapped ++ row
27982527
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− ]
2528+ column =
2529+ "." ++ Internal.Style.classes.column
28192530
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− ]
2531+ page =
2532+ "." ++ Internal.Style.classes.page
28552533
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− ]
2534+ paragraph =
2535+ "." ++ Internal.Style.classes.paragraph
28762536
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− ]
2537+ left =
2538+ "." ++ Internal.Style.classes.alignLeft
28972539
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 ++ ";")
2540+ right =
2541+ "." ++ Internal.Style.classes.alignRight
29782542
2979− rows =
2980− template.rows
2981− |> List.map toGridLength
2982− |> String.join " "
2983− |> (\x -> "grid-template-rows: " ++ x ++ ";")
2543+ any =
2544+ "." ++ Internal.Style.classes.any
29842545
2985− gapX =
2986− "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2546+ single =
2547+ "." ++ Internal.Style.classes.single
2548+ in
2549+ String.concat
2550+ [ renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
2551+
2552+ -- margins don't apply to last element of normal, unwrapped rows
2553+ -- , renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
2554+ -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
2555+ , renderStyle maybePseudo
2556+ (class ++ wrappedRow ++ " > " ++ any)
2557+ [ Property "margin" (halfY ++ " " ++ halfX)
2558+ ]
29872559
2988− gapY =
2989− "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2560+ -- , renderStyle maybePseudo
2561+ -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2562+ -- [ Property "margin-right" "0"
2563+ -- ]
2564+ -- columns
2565+ , renderStyle maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2566+ , renderStyle maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2567+ , renderStyle maybePseudo (class ++ page ++ " > " ++ left) [ Property "margin-right" xPx ]
2568+ , renderStyle maybePseudo (class ++ page ++ " > " ++ right) [ Property "margin-left" xPx ]
2569+ , renderStyle
2570+ maybePseudo
2571+ (class ++ paragraph)
2572+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2573+ ]
2574+ , renderStyle
2575+ maybePseudo
2576+ ("textarea" ++ class)
2577+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2578+ ]
29902579
2991− modernGrid =
2992− class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2580+ -- , renderStyle
2581+ -- maybePseudo
2582+ -- (class ++ paragraph ++ " > " ++ any)
2583+ -- [ Property "margin-right" xPx
2584+ -- , Property "margin-bottom" yPx
2585+ -- ]
2586+ , renderStyle
2587+ maybePseudo
2588+ (class ++ paragraph ++ " > " ++ left)
2589+ [ Property "margin-right" xPx
2590+ ]
2591+ , renderStyle
2592+ maybePseudo
2593+ (class ++ paragraph ++ " > " ++ right)
2594+ [ Property "margin-left" xPx
2595+ ]
2596+ , renderStyle
2597+ maybePseudo
2598+ (class ++ paragraph ++ "::after")
2599+ [ Property "content" "''"
2600+ , Property "display" "block"
2601+ , Property "height" "0"
2602+ , Property "width" "0"
2603+ , Property "margin-top" (String.fromInt (-1 * (y // 2)) ++ "px")
2604+ ]
2605+ , renderStyle
2606+ maybePseudo
2607+ (class ++ paragraph ++ "::before")
2608+ [ Property "content" "''"
2609+ , Property "display" "block"
2610+ , Property "height" "0"
2611+ , Property "width" "0"
2612+ , Property "margin-bottom" (String.fromInt (-1 * (y // 2)) ++ "px")
2613+ ]
2614+ ]
29932615
2994− supports =
2995− "@supports (display:grid) {" ++ modernGrid ++ "}"
2996− in
2997− [ base
2998− , supports
2999− ]
2616+ PaddingStyle cls top right bottom left ->
2617+ let
2618+ class =
2619+ "."
2620+ ++ cls
2621+ in
2622+ renderStyle
2623+ maybePseudo
2624+ class
2625+ [ Property "padding"
2626+ (String.fromInt top
2627+ ++ "px "
2628+ ++ String.fromInt right
2629+ ++ "px "
2630+ ++ String.fromInt bottom
2631+ ++ "px "
2632+ ++ String.fromInt left
2633+ ++ "px"
2634+ )
2635+ ]
30002636
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− ++ ";"
2637+ BorderWidth cls top right bottom left ->
2638+ let
2639+ class =
2640+ "."
2641+ ++ cls
2642+ in
2643+ renderStyle
2644+ maybePseudo
2645+ class
2646+ [ Property "border-width"
2647+ (String.fromInt top
2648+ ++ "px "
2649+ ++ String.fromInt right
2650+ ++ "px "
2651+ ++ String.fromInt bottom
2652+ ++ "px "
2653+ ++ String.fromInt left
2654+ ++ "px"
2655+ )
30272656 ]
30282657
3029− base =
3030− class ++ "{" ++ msPosition ++ "}"
2658+ GridTemplateStyle template ->
2659+ let
2660+ class =
2661+ ".grid-rows-"
2662+ ++ String.join "-" (List.map lengthClassName template.rows)
2663+ ++ "-cols-"
2664+ ++ String.join "-" (List.map lengthClassName template.columns)
2665+ ++ "-space-x-"
2666+ ++ lengthClassName (Tuple.first template.spacing)
2667+ ++ "-space-y-"
2668+ ++ lengthClassName (Tuple.second template.spacing)
2669+
2670+ ySpacing =
2671+ toGridLength (Tuple.second template.spacing)
2672+
2673+ xSpacing =
2674+ toGridLength (Tuple.first template.spacing)
2675+
2676+ toGridLength x =
2677+ toGridLengthHelper Nothing Nothing x
2678+
2679+ toGridLengthHelper minimum maximum x =
2680+ case x of
2681+ Px px ->
2682+ String.fromInt px ++ "px"
2683+
2684+ Content ->
2685+ case ( minimum, maximum ) of
2686+ ( Nothing, Nothing ) ->
2687+ "max-content"
2688+
2689+ ( Just minSize, Nothing ) ->
2690+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2691+
2692+ ( Nothing, Just maxSize ) ->
2693+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2694+
2695+ ( Just minSize, Just maxSize ) ->
2696+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2697+
2698+ Fill i ->
2699+ case ( minimum, maximum ) of
2700+ ( Nothing, Nothing ) ->
2701+ String.fromInt i ++ "fr"
2702+
2703+ ( Just minSize, Nothing ) ->
2704+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2705+
2706+ ( Nothing, Just maxSize ) ->
2707+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2708+
2709+ ( Just minSize, Just maxSize ) ->
2710+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2711+
2712+ Min m len ->
2713+ toGridLengthHelper (Just m) maximum len
2714+
2715+ Max m len ->
2716+ toGridLengthHelper minimum (Just m) len
2717+
2718+ msColumns =
2719+ template.columns
2720+ |> List.map toGridLength
2721+ |> String.join ySpacing
2722+ |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2723+
2724+ msRows =
2725+ template.columns
2726+ |> List.map toGridLength
2727+ |> String.join ySpacing
2728+ |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
2729+
2730+ base =
2731+ class ++ "{" ++ msColumns ++ msRows ++ "}"
2732+
2733+ columns =
2734+ template.columns
2735+ |> List.map toGridLength
2736+ |> String.join " "
2737+ |> (\x -> "grid-template-columns: " ++ x ++ ";")
2738+
2739+ rows =
2740+ template.rows
2741+ |> List.map toGridLength
2742+ |> String.join " "
2743+ |> (\x -> "grid-template-rows: " ++ x ++ ";")
2744+
2745+ gapX =
2746+ "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2747+
2748+ gapY =
2749+ "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2750+
2751+ modernGrid =
2752+ class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2753+
2754+ supports =
2755+ "@supports (display:grid) {" ++ modernGrid ++ "}"
2756+ in
2757+ base ++ supports
30312758
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− ]
2759+ GridPosition position ->
2760+ let
2761+ class =
2762+ ".grid-pos-"
2763+ ++ String.fromInt position.row
2764+ ++ "-"
2765+ ++ String.fromInt position.col
2766+ ++ "-"
2767+ ++ String.fromInt position.width
2768+ ++ "-"
2769+ ++ String.fromInt position.height
2770+
2771+ msPosition =
2772+ String.join " "
2773+ [ "-ms-grid-row: "
2774+ ++ String.fromInt position.row
2775+ ++ ";"
2776+ , "-ms-grid-row-span: "
2777+ ++ String.fromInt position.height
2778+ ++ ";"
2779+ , "-ms-grid-column: "
2780+ ++ String.fromInt position.col
2781+ ++ ";"
2782+ , "-ms-grid-column-span: "
2783+ ++ String.fromInt position.width
2784+ ++ ";"
2785+ ]
2786+
2787+ base =
2788+ class ++ "{" ++ msPosition ++ "}"
2789+
2790+ modernPosition =
2791+ String.join " "
2792+ [ "grid-row: "
2793+ ++ String.fromInt position.row
2794+ ++ " / "
2795+ ++ String.fromInt (position.row + position.height)
2796+ ++ ";"
2797+ , "grid-column: "
2798+ ++ String.fromInt position.col
2799+ ++ " / "
2800+ ++ String.fromInt (position.col + position.width)
2801+ ++ ";"
2802+ ]
2803+
2804+ modernGrid =
2805+ class ++ "{" ++ modernPosition ++ "}"
2806+
2807+ supports =
2808+ "@supports (display:grid) {" ++ modernGrid ++ "}"
2809+ in
2810+ base ++ supports
30452811
3046− modernGrid =
3047− class ++ "{" ++ modernPosition ++ "}"
2812+ PseudoSelector class styles ->
2813+ let
2814+ renderPseudoRule style =
2815+ renderStyleRule style (Just class)
2816+ in
2817+ List.map renderPseudoRule styles
2818+ |> String.join " "
30482819
3049− supports =
3050− "@supports (display:grid) {" ++ modernGrid ++ "}"
3051− in
3052− [ base
3053− , supports
3054− ]
2820+ Transform transform ->
2821+ let
2822+ val =
2823+ transformValue transform
30552824
3056− PseudoSelector class styles ->
3057− let
3058− renderPseudoRule style =
3059− renderStyleRule options style (Just class)
3060− in
3061− List.concatMap renderPseudoRule styles
2825+ class =
2826+ transformClass transform
2827+ in
2828+ case ( class, val ) of
2829+ ( Just cls, Just v ) ->
2830+ renderStyle
2831+ maybePseudo
2832+ ("." ++ cls)
2833+ [ Property "transform"
2834+ v
2835+ ]
30622836
3063− Transform transform ->
3064− let
3065− val =
3066− transformValue transform
2837+ _ ->
2838+ ""
30672839
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− ]
2840+ combine style rendered =
2841+ { rules = rendered.rules ++ renderStyleRule style Nothing
2842+ , topLevel =
2843+ case topLevelValue style of
2844+ Nothing ->
2845+ rendered.topLevel
30792846
3080− _ ->
3081− []
2847+ Just topLevel ->
2848+ topLevel :: rendered.topLevel
2849+ }
2850+ in
2851+ case List.foldl combine { topLevel = [], rules = "" } stylesheet of
2852+ { topLevel, rules } ->
2853+ renderTopLevelValues topLevel ++ rules
30822854
30832855
30842856lengthClassName : Length -> String
@@ -3118,12 +2890,12 @@ formatTextShadow shadow =
31182890 ]
31192891
31202892
3121−textShadowClass shadow =
2893+textShadowName shadow =
31222894 String.concat
31232895 [ "txt"
3124− , floatClass (Tuple.first shadow.offset) ++ "px"
3125− , floatClass (Tuple.second shadow.offset) ++ "px"
3126− , floatClass shadow.blur ++ "px"
2896+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2897+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2898+ , String.fromFloat shadow.blur ++ "px"
31272899 , formatColorClass shadow.color
31282900 ]
31292901
@@ -3144,17 +2916,17 @@ formatBoxShadow shadow =
31442916 ]
31452917
31462918
3147−boxShadowClass shadow =
2919+boxShadowName shadow =
31482920 String.concat <|
31492921 [ if shadow.inset then
31502922 "box-inset"
31512923
31522924 else
31532925 "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"
2926+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2927+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2928+ , String.fromFloat shadow.blur ++ "px"
2929+ , String.fromFloat shadow.size ++ "px"
31582930 , formatColorClass shadow.color
31592931 ]
31602932
@@ -3199,17 +2971,6 @@ paddingName top right bottom left =
31992971 ++ String.fromInt left
32002972
32012973
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−
32132974getStyleName : Style -> String
32142975getStyleName style =
32152976 case style of
@@ -3524,19 +3285,20 @@ convertAdjustment adjustment =
35243285 capitalVertical =
35253286 1 - ascender
35263287
3288+
35273289 capitalSize =
35283290 1 / (ascender - newBaseline)
35293291
3530− fullSize =
3531− 1 / (ascender - descender)
3532−
35333292 fullVertical =
3534− 1 - ascender
3535−
3536− -- (oldMiddle - newFullMiddle) * 2
3293+ (oldMiddle - newFullMiddle) * 2
35373294 in
35383295 { full =
3539− adjust fullSize (ascender - descender) fullVertical
3296+ { vertical = fullVertical
3297+ , height =
3298+ (ascender - descender)
3299+ - abs fullVertical
3300+ , size = 1.0
3301+ }
35403302 , capital =
35413303 adjust capitalSize (ascender - newBaseline) capitalVertical
35423304 }
@@ -3546,5 +3308,7 @@ adjust size height vertical =
35463308 { vertical = vertical
35473309 , height =
35483310 height / size
3311+
3312+ -- vertical
35493313 , size = size
35503314 }