@@ -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,68 @@ 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) ]
2174+
2175+
2176+
2177+-- case typefaceAdjustment typefaces of
2178+-- Nothing ->
2179+-- ""
2180+-- Just ( parentAdj, textAdjustment ) ->
2181+-- String.join " "
2182+-- [ renderStyle
2183+-- maybePseudo
2184+-- ("."
2185+-- ++ name
2186+-- ++ "."
2187+-- ++ classes.sizeByCapital
2188+-- ++ ", "
2189+-- ++ "."
2190+-- ++ name
2191+-- ++ " ."
2192+-- ++ classes.sizeByCapital
2193+-- )
2194+-- parentAdj
2195+-- , renderStyle
2196+-- maybePseudo
2197+-- ("."
2198+-- ++ name
2199+-- ++ "."
2200+-- ++ classes.sizeByCapital
2201+-- ++ "> ."
2202+-- ++ Internal.Style.classes.text
2203+-- ++ ", ."
2204+-- ++ name
2205+-- ++ " ."
2206+-- ++ classes.sizeByCapital
2207+-- ++ " > ."
2208+-- ++ Internal.Style.classes.text
2209+-- )
2210+-- textAdjustment
2211+-- ]
2212+-- renderTopLevels rule =
2213+-- case rule of
2214+-- FontFamily name typefaces ->
2215+-- let
2216+-- getImports font =
2217+-- case font of
2218+-- ImportFont _ url ->
2219+-- Just ("@import url('" ++ url ++ "');")
2220+-- FontWith { url } ->
2221+-- case url of
2222+-- Just x ->
2223+-- Just ("@import url('" ++ x ++ "');")
2224+-- Nothing ->
2225+-- Nothing
2226+-- _ ->
2227+-- Nothing
2228+-- in
2229+-- typefaces
2230+-- |> List.filterMap getImports
2231+-- |> String.join "\n"
2232+-- |> Just
2233+-- _ ->
2234+-- Nothing
23812235
23822236
23832237renderTopLevelValues rules =
@@ -2387,12 +2241,14 @@ renderTopLevelValues rules =
23872241 ImportFont _ url ->
23882242 Just ("@import url('" ++ url ++ "');")
23892243
2390− -- FontWith with ->
2391− -- case with.url of
2392− -- Just x ->
2393− -- Just ("@import url('" ++ x ++ "');")
2394− -- Nothing ->
2395− -- Nothing
2244+ FontWith with ->
2245+ case with.url of
2246+ Just x ->
2247+ Just ("@import url('" ++ x ++ "');")
2248+
2249+ Nothing ->
2250+ Nothing
2251+
23962252 _ ->
23972253 Nothing
23982254
@@ -2463,38 +2319,7 @@ renderNullAdjustmentRule fontToAdjust otherFontName =
24632319 ]
24642320
24652321
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 =
2322+renderFontAdjustmentRule fontToAdjust ( parentAdj, textAdjustment ) otherFontName =
24982323 let
24992324 name =
25002325 if fontToAdjust == otherFontName then
@@ -2504,7 +2329,34 @@ renderFontAdjustmentRule fontToAdjust ( full, capital ) otherFontName =
25042329 otherFontName ++ " ." ++ fontToAdjust
25052330 in
25062331 String.join " "
2507− (fontRule name classes.sizeByCapital capital ++ fontRule name classes.fullSize full)
2332+ [ bracket
2333+ ("."
2334+ ++ name
2335+ ++ "."
2336+ ++ classes.sizeByCapital
2337+ ++ ", "
2338+ ++ "."
2339+ ++ name
2340+ ++ " ."
2341+ ++ classes.sizeByCapital
2342+ )
2343+ parentAdj
2344+ , bracket
2345+ ("."
2346+ ++ name
2347+ ++ "."
2348+ ++ classes.sizeByCapital
2349+ ++ "> ."
2350+ ++ Internal.Style.classes.text
2351+ ++ ", ."
2352+ ++ name
2353+ ++ " ."
2354+ ++ classes.sizeByCapital
2355+ ++ " > ."
2356+ ++ Internal.Style.classes.text
2357+ )
2358+ textAdjustment
2359+ ]
25082360
25092361
25102362bracket selector rules =
@@ -2517,11 +2369,11 @@ bracket selector rules =
25172369
25182370fontAdjustmentRules converted =
25192371 ( [ ( "display", "block" )
2372+ , ( "line-height", String.fromFloat converted.height )
25202373 ]
25212374 , [ ( "display", "inline-block" )
25222375 , ( "line-height", String.fromFloat converted.height )
25232376 , ( "vertical-align", String.fromFloat converted.vertical ++ "em" )
2524− , ( "font-size", String.fromFloat converted.size ++ "em" )
25252377 ]
25262378 )
25272379
@@ -2533,17 +2385,10 @@ typefaceAdjustment typefaces =
25332385 Nothing ->
25342386 case face of
25352387 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− )
2388+ Just
2389+ (fontAdjustmentRules
2390+ (.capital (convertAdjustment with.adjustment))
2391+ )
25472392
25482393 _ ->
25492394 found
@@ -2593,492 +2438,475 @@ renderProps force (Property key val) existing =
25932438 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
25942439
25952440
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−
26092441toStyleSheetString : OptionRecord -> List Style -> String
26102442toStyleSheetString options stylesheet =
26112443 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
2444+ renderStyle maybePseudo selector props =
2445+ case maybePseudo of
2446+ Nothing ->
2447+ selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}"
26182448
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
2449+ Just pseudo ->
2450+ case pseudo of
2451+ Hover ->
2452+ case options.hover of
2453+ NoHover ->
2454+ ""
26262455
2456+ ForceHover ->
2457+ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}"
26272458
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}" ]
2459+ AllowHover ->
2460+ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}"
26332461
2634− Just pseudo ->
2635− case pseudo of
2636− Hover ->
2637− case options.hover of
2638− NoHover ->
2639− []
2462+ Focus ->
2463+ let
2464+ renderedProps =
2465+ List.foldl (renderProps False) "" props
2466+ in
2467+ String.join "\n"
2468+ [ selector
2469+ ++ "-fs:focus {"
2470+ ++ renderedProps
2471+ ++ "\n}"
2472+ , "."
2473+ ++ classes.any
2474+ ++ ":focus ~ "
2475+ ++ selector
2476+ ++ "-fs:not(.focus) {"
2477+ ++ renderedProps
2478+ ++ "\n}"
2479+ , "."
2480+ ++ classes.any
2481+ ++ ":focus "
2482+ ++ selector
2483+ ++ "-fs {"
2484+ ++ renderedProps
2485+ ++ "\n}"
2486+ , ".focusable-parent:focus ~ "
2487+ ++ "."
2488+ ++ classes.any
2489+ ++ " "
2490+ ++ selector
2491+ ++ "-fs {"
2492+ ++ renderedProps
2493+ ++ "\n}"
2494+ ]
26402495
2641− ForceHover ->
2642− [ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}" ]
2496+ Active ->
2497+ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}"
26432498
2644− AllowHover ->
2645− [ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2499+ renderStyleRule rule maybePseudo =
2500+ case rule of
2501+ Style selector props ->
2502+ renderStyle maybePseudo selector props
26462503
2647− Focus ->
2504+ Shadows name prop ->
2505+ renderStyle
2506+ maybePseudo
2507+ ("." ++ name)
2508+ [ Property "box-shadow" prop
2509+ ]
2510+
2511+ Transparency name transparency ->
26482512 let
2649− renderedProps =
2650− List.foldl (renderProps False) "" props
2513+ opacity =
2514+ (1 - transparency)
2515+ |> min 1
2516+ |> max 0
26512517 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− ]
2518+ renderStyle
2519+ maybePseudo
2520+ ("." ++ name)
2521+ [ Property "opacity" (String.fromFloat opacity)
2522+ ]
27352523
2736− Colored class prop color ->
2737− renderStyle options
2738− maybePseudo
2739− ("." ++ class)
2740− [ Property prop (formatColor color)
2741− ]
2524+ FontSize i ->
2525+ renderStyle
2526+ maybePseudo
2527+ (".font-size-" ++ String.fromInt i)
2528+ [ Property "font-size" (String.fromInt i ++ "px")
2529+ ]
27422530
2743− SpacingStyle cls x y ->
2744− let
2745− class =
2746− "." ++ cls
2531+ FontFamily name typefaces ->
2532+ let
2533+ families =
2534+ Property "font-family"
2535+ (typefaces
2536+ |> List.map fontName
2537+ |> String.join ", "
2538+ )
2539+ in
2540+ String.join " "
2541+ [ renderStyle
2542+ maybePseudo
2543+ ("." ++ name)
2544+ [ families ]
2545+ ]
27472546
2748− halfX =
2749− String.fromFloat (toFloat x / 2) ++ "px"
2547+ Single class prop val ->
2548+ renderStyle
2549+ maybePseudo
2550+ ("." ++ class)
2551+ [ Property prop val
2552+ ]
27502553
2751− halfY =
2752− String.fromFloat (toFloat y / 2) ++ "px"
2554+ Colored class prop color ->
2555+ renderStyle
2556+ maybePseudo
2557+ ("." ++ class)
2558+ [ Property prop (formatColor color)
2559+ ]
27532560
2754− xPx =
2755− String.fromInt x ++ "px"
2561+ SpacingStyle cls x y ->
2562+ let
2563+ class =
2564+ "." ++ cls
27562565
2757− yPx =
2758− String.fromInt y ++ "px"
2566+ halfX =
2567+ String.fromFloat (toFloat x / 2) ++ "px"
27592568
2760− row =
2761− "." ++ Internal.Style.classes.row
2569+ halfY =
2570+ String.fromFloat (toFloat y / 2) ++ "px"
27622571
2763− wrappedRow =
2764− "." ++ Internal.Style.classes.wrapped ++ row
2572+ xPx =
2573+ String.fromInt x ++ "px"
27652574
2766− column =
2767− "." ++ Internal.Style.classes.column
2575+ yPx =
2576+ String.fromInt y ++ "px"
27682577
2769− page =
2770− "." ++ Internal.Style.classes.page
2578+ row =
2579+ "." ++ Internal.Style.classes.row
27712580
2772− paragraph =
2773− "." ++ Internal.Style.classes.paragraph
2581+ wrappedRow =
2582+ "." ++ Internal.Style.classes.wrapped ++ row
27742583
2775− left =
2776− "." ++ Internal.Style.classes.alignLeft
2584+ column =
2585+ "." ++ Internal.Style.classes.column
27772586
2778− right =
2779− "." ++ Internal.Style.classes.alignRight
2587+ page =
2588+ "." ++ Internal.Style.classes.page
27802589
2781− any =
2782− "." ++ Internal.Style.classes.any
2590+ paragraph =
2591+ "." ++ Internal.Style.classes.paragraph
27832592
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− ]
2593+ left =
2594+ "." ++ Internal.Style.classes.alignLeft
27982595
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− ]
2596+ right =
2597+ "." ++ Internal.Style.classes.alignRight
28192598
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− ]
2599+ any =
2600+ "." ++ Internal.Style.classes.any
28552601
2856− PaddingStyle cls top right bottom left ->
2857− let
2858− class =
2859− "."
2860− ++ cls
2861− in
2862− renderStyle options
2863− maybePseudo
2864− class
2865− [ Property "padding"
2866− (String.fromFloat top
2867− ++ "px "
2868− ++ String.fromFloat right
2869− ++ "px "
2870− ++ String.fromFloat bottom
2871− ++ "px "
2872− ++ String.fromFloat left
2873− ++ "px"
2874− )
2875− ]
2876−
2877− BorderWidth cls top right bottom left ->
2878− let
2879− class =
2880− "."
2881− ++ cls
2882− in
2883− renderStyle options
2884− maybePseudo
2885− class
2886− [ Property "border-width"
2887− (String.fromInt top
2888− ++ "px "
2889− ++ String.fromInt right
2890− ++ "px "
2891− ++ String.fromInt bottom
2892− ++ "px "
2893− ++ String.fromInt left
2894− ++ "px"
2895− )
2896− ]
2897−
2898− GridTemplateStyle template ->
2899− let
2900− class =
2901− ".grid-rows-"
2902− ++ String.join "-" (List.map lengthClassName template.rows)
2903− ++ "-cols-"
2904− ++ String.join "-" (List.map lengthClassName template.columns)
2905− ++ "-space-x-"
2906− ++ lengthClassName (Tuple.first template.spacing)
2907− ++ "-space-y-"
2908− ++ lengthClassName (Tuple.second template.spacing)
2909−
2910− ySpacing =
2911− toGridLength (Tuple.second template.spacing)
2912−
2913− xSpacing =
2914− toGridLength (Tuple.first template.spacing)
2915−
2916− toGridLength x =
2917− toGridLengthHelper Nothing Nothing x
2918−
2919− toGridLengthHelper minimum maximum x =
2920− case x of
2921− Px px ->
2922− String.fromInt px ++ "px"
2923−
2924− Content ->
2925− case ( minimum, maximum ) of
2926− ( Nothing, Nothing ) ->
2927− "max-content"
2928−
2929− ( Just minSize, Nothing ) ->
2930− "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2931−
2932− ( Nothing, Just maxSize ) ->
2933− "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2934−
2935− ( Just minSize, Just maxSize ) ->
2936− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2937−
2938− Fill i ->
2939− case ( minimum, maximum ) of
2940− ( Nothing, Nothing ) ->
2941− String.fromInt i ++ "fr"
2942−
2943− ( Just minSize, Nothing ) ->
2944− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2945−
2946− ( Nothing, Just maxSize ) ->
2947− "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2948−
2949− ( Just minSize, Just maxSize ) ->
2950− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2951−
2952− Min m len ->
2953− toGridLengthHelper (Just m) maximum len
2954−
2955− Max m len ->
2956− toGridLengthHelper minimum (Just m) len
2957−
2958− msColumns =
2959− template.columns
2960− |> List.map toGridLength
2961− |> String.join ySpacing
2962− |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2963−
2964− msRows =
2965− template.columns
2966− |> List.map toGridLength
2967− |> String.join ySpacing
2968− |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
2969−
2970− base =
2971− class ++ "{" ++ msColumns ++ msRows ++ "}"
2972−
2973− columns =
2974− template.columns
2975− |> List.map toGridLength
2976− |> String.join " "
2977− |> (\x -> "grid-template-columns: " ++ x ++ ";")
2978−
2979− rows =
2980− template.rows
2981− |> List.map toGridLength
2982− |> String.join " "
2983− |> (\x -> "grid-template-rows: " ++ x ++ ";")
2984−
2985− gapX =
2986− "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2602+ single =
2603+ "." ++ Internal.Style.classes.single
2604+ in
2605+ String.concat
2606+ [ renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
2607+
2608+ -- margins don't apply to last element of normal, unwrapped rows
2609+ -- , renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
2610+ -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
2611+ , renderStyle maybePseudo
2612+ (class ++ wrappedRow ++ " > " ++ any)
2613+ [ Property "margin" (halfY ++ " " ++ halfX)
2614+ ]
29872615
2988− gapY =
2989− "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2616+ -- , renderStyle maybePseudo
2617+ -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2618+ -- [ Property "margin-right" "0"
2619+ -- ]
2620+ -- columns
2621+ , renderStyle maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2622+ , renderStyle maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2623+ , renderStyle maybePseudo (class ++ page ++ " > " ++ left) [ Property "margin-right" xPx ]
2624+ , renderStyle maybePseudo (class ++ page ++ " > " ++ right) [ Property "margin-left" xPx ]
2625+ , renderStyle
2626+ maybePseudo
2627+ (class ++ paragraph)
2628+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2629+ ]
2630+ , renderStyle
2631+ maybePseudo
2632+ ("textarea" ++ class)
2633+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2634+ ]
29902635
2991− modernGrid =
2992− class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2636+ -- , renderStyle
2637+ -- maybePseudo
2638+ -- (class ++ paragraph ++ " > " ++ any)
2639+ -- [ Property "margin-right" xPx
2640+ -- , Property "margin-bottom" yPx
2641+ -- ]
2642+ , renderStyle
2643+ maybePseudo
2644+ (class ++ paragraph ++ " > " ++ left)
2645+ [ Property "margin-right" xPx
2646+ ]
2647+ , renderStyle
2648+ maybePseudo
2649+ (class ++ paragraph ++ " > " ++ right)
2650+ [ Property "margin-left" xPx
2651+ ]
2652+ , renderStyle
2653+ maybePseudo
2654+ (class ++ paragraph ++ "::after")
2655+ [ Property "content" "''"
2656+ , Property "display" "block"
2657+ , Property "height" "0"
2658+ , Property "width" "0"
2659+ , Property "margin-top" (String.fromInt (-1 * (y // 2)) ++ "px")
2660+ ]
2661+ , renderStyle
2662+ maybePseudo
2663+ (class ++ paragraph ++ "::before")
2664+ [ Property "content" "''"
2665+ , Property "display" "block"
2666+ , Property "height" "0"
2667+ , Property "width" "0"
2668+ , Property "margin-bottom" (String.fromInt (-1 * (y // 2)) ++ "px")
2669+ ]
2670+ ]
29932671
2994− supports =
2995− "@supports (display:grid) {" ++ modernGrid ++ "}"
2996− in
2997− [ base
2998− , supports
2999− ]
2672+ PaddingStyle cls top right bottom left ->
2673+ let
2674+ class =
2675+ "."
2676+ ++ cls
2677+ in
2678+ renderStyle
2679+ maybePseudo
2680+ class
2681+ [ Property "padding"
2682+ (String.fromInt top
2683+ ++ "px "
2684+ ++ String.fromInt right
2685+ ++ "px "
2686+ ++ String.fromInt bottom
2687+ ++ "px "
2688+ ++ String.fromInt left
2689+ ++ "px"
2690+ )
2691+ ]
30002692
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− ++ ";"
2693+ BorderWidth cls top right bottom left ->
2694+ let
2695+ class =
2696+ "."
2697+ ++ cls
2698+ in
2699+ renderStyle
2700+ maybePseudo
2701+ class
2702+ [ Property "border-width"
2703+ (String.fromInt top
2704+ ++ "px "
2705+ ++ String.fromInt right
2706+ ++ "px "
2707+ ++ String.fromInt bottom
2708+ ++ "px "
2709+ ++ String.fromInt left
2710+ ++ "px"
2711+ )
30272712 ]
30282713
3029− base =
3030− class ++ "{" ++ msPosition ++ "}"
2714+ GridTemplateStyle template ->
2715+ let
2716+ class =
2717+ ".grid-rows-"
2718+ ++ String.join "-" (List.map lengthClassName template.rows)
2719+ ++ "-cols-"
2720+ ++ String.join "-" (List.map lengthClassName template.columns)
2721+ ++ "-space-x-"
2722+ ++ lengthClassName (Tuple.first template.spacing)
2723+ ++ "-space-y-"
2724+ ++ lengthClassName (Tuple.second template.spacing)
2725+
2726+ ySpacing =
2727+ toGridLength (Tuple.second template.spacing)
2728+
2729+ xSpacing =
2730+ toGridLength (Tuple.first template.spacing)
2731+
2732+ toGridLength x =
2733+ toGridLengthHelper Nothing Nothing x
2734+
2735+ toGridLengthHelper minimum maximum x =
2736+ case x of
2737+ Px px ->
2738+ String.fromInt px ++ "px"
2739+
2740+ Content ->
2741+ case ( minimum, maximum ) of
2742+ ( Nothing, Nothing ) ->
2743+ "max-content"
2744+
2745+ ( Just minSize, Nothing ) ->
2746+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2747+
2748+ ( Nothing, Just maxSize ) ->
2749+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2750+
2751+ ( Just minSize, Just maxSize ) ->
2752+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2753+
2754+ Fill i ->
2755+ case ( minimum, maximum ) of
2756+ ( Nothing, Nothing ) ->
2757+ String.fromInt i ++ "fr"
2758+
2759+ ( Just minSize, Nothing ) ->
2760+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2761+
2762+ ( Nothing, Just maxSize ) ->
2763+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2764+
2765+ ( Just minSize, Just maxSize ) ->
2766+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2767+
2768+ Min m len ->
2769+ toGridLengthHelper (Just m) maximum len
2770+
2771+ Max m len ->
2772+ toGridLengthHelper minimum (Just m) len
2773+
2774+ msColumns =
2775+ template.columns
2776+ |> List.map toGridLength
2777+ |> String.join ySpacing
2778+ |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2779+
2780+ msRows =
2781+ template.columns
2782+ |> List.map toGridLength
2783+ |> String.join ySpacing
2784+ |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
2785+
2786+ base =
2787+ class ++ "{" ++ msColumns ++ msRows ++ "}"
2788+
2789+ columns =
2790+ template.columns
2791+ |> List.map toGridLength
2792+ |> String.join " "
2793+ |> (\x -> "grid-template-columns: " ++ x ++ ";")
2794+
2795+ rows =
2796+ template.rows
2797+ |> List.map toGridLength
2798+ |> String.join " "
2799+ |> (\x -> "grid-template-rows: " ++ x ++ ";")
2800+
2801+ gapX =
2802+ "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2803+
2804+ gapY =
2805+ "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2806+
2807+ modernGrid =
2808+ class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2809+
2810+ supports =
2811+ "@supports (display:grid) {" ++ modernGrid ++ "}"
2812+ in
2813+ base ++ supports
30312814
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− ]
2815+ GridPosition position ->
2816+ let
2817+ class =
2818+ ".grid-pos-"
2819+ ++ String.fromInt position.row
2820+ ++ "-"
2821+ ++ String.fromInt position.col
2822+ ++ "-"
2823+ ++ String.fromInt position.width
2824+ ++ "-"
2825+ ++ String.fromInt position.height
2826+
2827+ msPosition =
2828+ String.join " "
2829+ [ "-ms-grid-row: "
2830+ ++ String.fromInt position.row
2831+ ++ ";"
2832+ , "-ms-grid-row-span: "
2833+ ++ String.fromInt position.height
2834+ ++ ";"
2835+ , "-ms-grid-column: "
2836+ ++ String.fromInt position.col
2837+ ++ ";"
2838+ , "-ms-grid-column-span: "
2839+ ++ String.fromInt position.width
2840+ ++ ";"
2841+ ]
2842+
2843+ base =
2844+ class ++ "{" ++ msPosition ++ "}"
2845+
2846+ modernPosition =
2847+ String.join " "
2848+ [ "grid-row: "
2849+ ++ String.fromInt position.row
2850+ ++ " / "
2851+ ++ String.fromInt (position.row + position.height)
2852+ ++ ";"
2853+ , "grid-column: "
2854+ ++ String.fromInt position.col
2855+ ++ " / "
2856+ ++ String.fromInt (position.col + position.width)
2857+ ++ ";"
2858+ ]
2859+
2860+ modernGrid =
2861+ class ++ "{" ++ modernPosition ++ "}"
2862+
2863+ supports =
2864+ "@supports (display:grid) {" ++ modernGrid ++ "}"
2865+ in
2866+ base ++ supports
30452867
3046− modernGrid =
3047− class ++ "{" ++ modernPosition ++ "}"
2868+ PseudoSelector class styles ->
2869+ let
2870+ renderPseudoRule style =
2871+ renderStyleRule style (Just class)
2872+ in
2873+ List.map renderPseudoRule styles
2874+ |> String.join " "
30482875
3049− supports =
3050− "@supports (display:grid) {" ++ modernGrid ++ "}"
3051− in
3052− [ base
3053− , supports
3054− ]
2876+ Transform transform ->
2877+ let
2878+ val =
2879+ transformValue transform
30552880
3056− PseudoSelector class styles ->
3057− let
3058− renderPseudoRule style =
3059− renderStyleRule options style (Just class)
3060− in
3061− List.concatMap renderPseudoRule styles
2881+ class =
2882+ transformClass transform
2883+ in
2884+ case ( class, val ) of
2885+ ( Just cls, Just v ) ->
2886+ renderStyle
2887+ maybePseudo
2888+ ("." ++ cls)
2889+ [ Property "transform"
2890+ v
2891+ ]
30622892
3063− Transform transform ->
3064− let
3065− val =
3066− transformValue transform
2893+ _ ->
2894+ ""
30672895
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− ]
2896+ combine style rendered =
2897+ { rules = rendered.rules ++ renderStyleRule style Nothing
2898+ , topLevel =
2899+ case topLevelValue style of
2900+ Nothing ->
2901+ rendered.topLevel
30792902
3080− _ ->
3081− []
2903+ Just topLevel ->
2904+ topLevel :: rendered.topLevel
2905+ }
2906+ in
2907+ case List.foldl combine { topLevel = [], rules = "" } stylesheet of
2908+ { topLevel, rules } ->
2909+ renderTopLevelValues topLevel ++ rules
30822910
30832911
30842912lengthClassName : Length -> String
@@ -3118,12 +2946,12 @@ formatTextShadow shadow =
31182946 ]
31192947
31202948
3121−textShadowClass shadow =
2949+textShadowName shadow =
31222950 String.concat
31232951 [ "txt"
3124− , floatClass (Tuple.first shadow.offset) ++ "px"
3125− , floatClass (Tuple.second shadow.offset) ++ "px"
3126− , floatClass shadow.blur ++ "px"
2952+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2953+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2954+ , String.fromFloat shadow.blur ++ "px"
31272955 , formatColorClass shadow.color
31282956 ]
31292957
@@ -3144,17 +2972,17 @@ formatBoxShadow shadow =
31442972 ]
31452973
31462974
3147−boxShadowClass shadow =
2975+boxShadowName shadow =
31482976 String.concat <|
31492977 [ if shadow.inset then
31502978 "box-inset"
31512979
31522980 else
31532981 "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"
2982+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
2983+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
2984+ , String.fromFloat shadow.blur ++ "px"
2985+ , String.fromFloat shadow.size ++ "px"
31582986 , formatColorClass shadow.color
31592987 ]
31602988
@@ -3199,17 +3027,6 @@ paddingName top right bottom left =
31993027 ++ String.fromInt left
32003028
32013029
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−
32133030getStyleName : Style -> String
32143031getStyleName style =
32153032 case style of
@@ -3522,29 +3339,19 @@ convertAdjustment adjustment =
35223339 |> Maybe.withDefault adjustment.baseline
35233340
35243341 capitalVertical =
3525− 1 - ascender
3526−
3527− capitalSize =
3528− 1 / (ascender - newBaseline)
3529−
3530− fullSize =
3531− 1 / (ascender - descender)
3342+ (oldMiddle - newCapitalMiddle) * 2
35323343
35333344 fullVertical =
3534− 1 - ascender
3535−
3536− -- (oldMiddle - newFullMiddle) * 2
3345+ (oldMiddle - newFullMiddle) * 2
35373346 in
35383347 { full =
3539− adjust fullSize (ascender - descender) fullVertical
3348+ { vertical = fullVertical
3349+ , height =
3350+ (ascender - descender)
3351+ - abs fullVertical
3352+ }
35403353 , capital =
3541− adjust capitalSize (ascender - newBaseline) capitalVertical
3542− }
3543−
3544−
3545−adjust size height vertical =
3546− { vertical = vertical
3547− , height =
3548− height / size
3549− , size = size
3354+ { vertical = capitalVertical
3355+ , height = (ascender - newBaseline) - abs capitalVertical
3356+ }
35503357 }