@@ -16,7 +16,6 @@ module Internal.Model exposing
16 , LayoutContext(..)
16 , LayoutContext(..)
17 , Length(..)
17 , Length(..)
18 , Location(..)
18 , Location(..)
20 , NodeName(..)
19 , NodeName(..)
21 , Option(..)
20 , Option(..)
22 , OptionRecord
21 , OptionRecord
@@ -42,7 +41,7 @@ module Internal.Model exposing
42 , asParagraph
41 , asParagraph
44 , asTextColumn
43 , asTextColumn
45− , boxShadowClass
44+ , boxShadowName
46 , columnClass
45 , columnClass
47 , composeTransformation
46 , composeTransformation
48 , contextClasses
47 , contextClasses
@@ -79,30 +78,31 @@ module Internal.Model exposing
79 , onlyStyles
78 , onlyStyles
80 , optionsToRecord
79 , optionsToRecord
81 , paddingName
80 , paddingName
83 , pageClass
81 , pageClass
84 , paragraphClass
82 , paragraphClass
85 , reduceRecursive
83 , reduceRecursive
86 , reduceStyles
84 , reduceStyles
87 , reduceStylesRecursive
85 , reduceStylesRecursive
88 , removeNever
86 , removeNever
89 , renderFontClassName
90 , renderFontClassName
90 , renderHeight
91 , renderHeight
91 , renderRoot
92 , renderRoot
93 , renderWidth
93 , renderWidth
94 , rootStyle
94 , rootStyle
95 , rowClass
95 , rowClass
96 , singleClass
96 , singleClass
97 , spacingName
97 , spacingName
99− , textShadowClass
100+ , textShadowName
101 , toStyleSheet
102 , toStyleSheet
102 , transformClass
103 , transformClass
103 , unstyled
104 , unstyled
104 , unwrapDecorations
105 , unwrapDecorations
@@ -112,7 +112,7 @@ import Html.Attributes
112import Html.Keyed
112import Html.Keyed
113import Internal.Flag as Flag exposing (Flag)
113import Internal.Flag as Flag exposing (Flag)
114import Internal.Style exposing (classes, dot)
114import Internal.Style exposing (classes, dot)
115−import Json.Encode as Encode
115+import Json.Encode as Json
116import Set exposing (Set)
116import Set exposing (Set)
117import VirtualDom
117import VirtualDom
@@ -174,7 +174,7 @@ type Style
174 | Colored String String Color
174 | Colored String String Color
175 | SpacingStyle String Int Int
175 | SpacingStyle String Int Int
176 | BorderWidth String Int Int Int Int
176 | BorderWidth String Int Int Int Int
177− | PaddingStyle String Float Float Float Float
177+ | PaddingStyle String Int Int Int Int
178 | GridTemplateStyle
178 | GridTemplateStyle
179 { spacing : ( Length, Length )
179 { spacing : ( Length, Length )
180 , columns : List Length
180 , columns : List Length
@@ -222,7 +222,8 @@ type Font
222 | ImportFont String String
222 | ImportFont String String
223 | FontWith
223 | FontWith
224 { name : String
224 { name : String
225+ , url : Maybe String
225− , adjustment : Maybe Adjustment
226+ , adjustment : Adjustment
226 , variants : List Variant
227 , variants : List Variant
@@ -245,18 +246,6 @@ renderVariant var =
245 "\"" ++ name ++ "\" " ++ String.fromInt index
246 "\"" ++ name ++ "\" " ++ String.fromInt index
250− VariantActive name ->
256− VariantIndexed name index ->
257− name ++ "-" ++ String.fromInt index
260renderVariants typeface =
249renderVariants typeface =
261 case typeface of
250 case typeface of
262 FontWith font ->
251 FontWith font ->
@@ -455,10 +444,7 @@ finalizeNode has node attributes children embedMode parentContext =
455 Embedded nodeName internal ->
444 Embedded nodeName internal ->
456 VirtualDom.node nodeName
445 VirtualDom.node nodeName
457 attributes
446 attributes
458− [ createNode internal
459− [ Html.Attributes.class
460− (classes.any ++ " " ++ classes.single)
447+ [ createNode internal [ Html.Attributes.class (classes.any ++ " " ++ classes.single) ]
464 case parentContext of
450 case parentContext of
@@ -535,45 +521,49 @@ finalizeNode has node attributes children embedMode parentContext =
537embedWith static opts styles children =
523embedWith static opts styles children =
541− |> List.foldl reduceStyles ( Set.empty, renderFocusStyle opts.focus )
543− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
545− |> toStyleSheet opts
547 if static then
524 if static then
548− staticRoot opts
525+ staticRoot
549− :: dynamicStyleSheet
526+ :: (styles
527+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
529+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
531+ |> toStyleSheet opts
550 :: children
533 :: children
553− dynamicStyleSheet
536+ (styles
537+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
539+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
541+ |> toStyleSheet opts
554 :: children
543 :: children
557embedKeyed static opts styles children =
546embedKeyed static opts styles children =
561− |> List.foldl reduceStyles ( Set.empty, renderFocusStyle opts.focus )
563− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
565− |> toStyleSheet opts
567 if static then
547 if static then
568− ( "static-stylesheet", staticRoot opts )
548+ ( "static-stylesheet", staticRoot )
569 :: ( "dynamic-stylesheet"
549 :: ( "dynamic-stylesheet"
570− , dynamicStyleSheet
550+ , styles
551+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
553+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
555+ |> toStyleSheet opts
572 :: children
557 :: children
575 ( "dynamic-stylesheet"
560 ( "dynamic-stylesheet"
576− , dynamicStyleSheet
561+ , styles
562+ |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
564+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
566+ |> toStyleSheet opts
578 :: children
568 :: children
@@ -1032,7 +1022,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1033 gatherAttrRecursive (classes ++ " " ++ newClass)
1023 gatherAttrRecursive (classes ++ " " ++ newClass)
1035− (Flag.merge addToFlags (Flag.add Flag.width has))
1025+ (Flag.merge addToFlags has)
1036 transform
1026 transform
1037 (newStyles ++ styles)
1027 (newStyles ++ styles)
@@ -1053,7 +1043,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1054 "height-px-" ++ val
1044 "height-px-" ++ val
1056− gatherAttrRecursive (Internal.Style.classes.heightExact ++ " " ++ name ++ " " ++ classes)
1046+ gatherAttrRecursive (name ++ " " ++ classes)
1058 (Flag.add Flag.height has)
1048 (Flag.add Flag.height has)
1059 transform
1049 transform
@@ -1110,7 +1100,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1111 gatherAttrRecursive (classes ++ " " ++ newClass)
1101 gatherAttrRecursive (classes ++ " " ++ newClass)
1113− (Flag.merge addToFlags (Flag.add Flag.height has))
1103+ (Flag.merge addToFlags has)
1114 transform
1104 transform
1115 (newStyles ++ styles)
1105 (newStyles ++ styles)
@@ -1142,15 +1132,20 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1142 gatherAttrRecursive classes (addNodeName "h6" node) has transform styles attrs children remaining
1132 gatherAttrRecursive classes (addNodeName "h6" node) has transform styles attrs children remaining
1144 Paragraph ->
1134 Paragraph ->
1145− -- previously we rendered a <p> tag, though apparently this invalidates the html if it has <div>s inside.
1135+ let
1146− -- Since we can't guaranteee that there are no divs, we need another strategy.
1136+ newNode =
1147− -- While it's not documented in many places, there apparently is a paragraph aria role
1137+ case node of
1148− -- https://github.com/w3c/aria/blob/11f85f41a5b621fdbe85fc9bcdcd270e653a48ba/common/script/roleInfo.js
1138+ Generic ->
1149− -- Though we'll need to wait till it gets released in an official wai-aria spec to use it.
1139+ NodeName "p"
1150− -- If it's used at the moment, then Lighthouse complains (likely rightfully) that role paragraph is not recognized.
1140+
1151− gatherAttrRecursive
1147+ gatherAttrRecursive classes
1152− classes
1148+ newNode
1155 transform
1150 transform
@@ -1436,7 +1431,7 @@ renderHeight h =
1436 "height-px-" ++ val
1431 "height-px-" ++ val
1438 ( Flag.none
1433 ( Flag.none
1439− , Internal.Style.classes.heightExact ++ " " ++ name
1434+ , name
1440 , [ Single name "height" (val ++ "px") ]
1435 , [ Single name "height" (val ++ "px") ]
@@ -1459,7 +1454,7 @@ renderHeight h =
1459 , [ Single
1454 , [ Single
1460 (Internal.Style.classes.any
1455 (Internal.Style.classes.any
1462− ++ Internal.Style.classes.column
1457+ ++ Internal.Style.classes.row
1463 ++ " > "
1458 ++ " > "
1464 ++ (Internal.Style.dot <| "height-fill-" ++ String.fromInt portion)
1459 ++ (Internal.Style.dot <| "height-fill-" ++ String.fromInt portion)
@@ -1478,9 +1473,7 @@ renderHeight h =
1480 "min-height"
1475 "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")
1476+ (String.fromInt minSize ++ "px")
1485 ( newFlag, newAttrs, newStyle ) =
1478 ( newFlag, newAttrs, newStyle ) =
1486 renderHeight len
1479 renderHeight len
@@ -1817,20 +1810,8 @@ defaultOptions =
1820−staticRoot : OptionRecord -> VirtualDom.Node msg
1813+staticRoot =
1824− -- wrap the style node in a div to prevent `Dark Reader` from blowin up the dom.
1825− VirtualDom.node "div"
1827− [ VirtualDom.node "style" [] [ VirtualDom.text Internal.Style.rules ] ]
1814+ VirtualDom.node "style" [] [ VirtualDom.text Internal.Style.rules ]
1829− NoStaticStyleSheet ->
1833− VirtualDom.node "elm-ui-static-rules" [ VirtualDom.property "rules" (Encode.string Internal.Style.rules) ] []
1836addWhen ifThis x to =
1817addWhen ifThis x to =
@@ -1948,7 +1929,7 @@ type Spacing
1950type Padding
1931type Padding
1951− = Padding String Float Float Float Float
1932+ = Padding String Int Int Int Int
1954extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing )
1935extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing )
@@ -2044,44 +2025,34 @@ getHeight attrs =
2047−textElementClasses : String
2048−textElementClasses =
2053− ++ classes.widthContent
2055− ++ classes.heightContent
2058textElement : String -> VirtualDom.Node msg
2028textElement : String -> VirtualDom.Node msg
2059textElement str =
2029textElement str =
2060 Html.div
2030 Html.div
2061 [ Html.Attributes.class
2031 [ Html.Attributes.class
2062− textElementClasses
2032+ (String.join " "
2035+ , classes.widthContent
2036+ , classes.heightContent
2064 [ Html.text str ]
2040 [ Html.text str ]
2067−textElementFillClasses : String
2068−textElementFillClasses =
2073− ++ classes.widthFill
2075− ++ classes.heightFill
2078textElementFill : String -> VirtualDom.Node msg
2043textElementFill : String -> VirtualDom.Node msg
2079textElementFill str =
2044textElementFill str =
2080− Html.div
2045+ VirtualDom.node "div"
2081 [ Html.Attributes.class
2046 [ Html.Attributes.class
2082− textElementFillClasses
2047+ (String.join " "
2050+ , classes.widthFill
2051+ , classes.heightFill
2084− [ Html.text str ]
2055+ [ VirtualDom.text str ]
2087type Children x
2058type Children x
@@ -2089,6 +2060,10 @@ type Children x
2089 | Keyed (List ( String, x ))
2060 | Keyed (List ( String, x ))
2064+-- toHtml : OptionRecord -> Element msg -> VirtualDom.Node msg
2092toHtml mode el =
2067toHtml mode el =
2093 case el of
2068 case el of
2094 Unstyled html ->
2069 Unstyled html ->
@@ -2124,7 +2099,8 @@ renderRoot optionList attributes child =
2126type RenderMode
2101type RenderMode
2127− = Layout
2103+ | Layout
2128 | NoStaticStyleSheet
2104 | NoStaticStyleSheet
2129 | WithVirtualCss
2105 | WithVirtualCss
@@ -2173,8 +2149,8 @@ rootStyle =
2173 , SansSerif
2149 , SansSerif
2176− [ StyleClass Flag.bgColor (Colored ("bg-" ++ formatColorClass (Rgba 1 1 1 0)) "background-color" (Rgba 1 1 1 0))
2152+ [ StyleClass Flag.bgColor (Colored ("bg-color-" ++ 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))
2153+ , StyleClass Flag.fontColor (Colored ("font-color-" ++ formatColorClass (Rgba 0 0 0 1)) "color" (Rgba 0 0 0 1))
2178 , StyleClass Flag.fontSize (FontSize 20)
2154 , StyleClass Flag.fontSize (FontSize 20)
2179 , StyleClass Flag.fontFamily <|
2155 , StyleClass Flag.fontFamily <|
2180 FontFamily (List.foldl renderFontClassName "font-" families)
2156 FontFamily (List.foldl renderFontClassName "font-" families)
@@ -2217,38 +2193,9 @@ renderFontClassName font current =
2218renderFocusStyle :
2194renderFocusStyle :
2219 FocusStyle
2195 FocusStyle
2220− -> List Style
2196+ -> Style
2221renderFocusStyle focus =
2197renderFocusStyle 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
2228− Property "box-shadow"
2230− { color = shadow.color
2233− |> Tuple.mapFirst toFloat
2234− |> Tuple.mapSecond toFloat
2237− toFloat shadow.blur
2239− toFloat shadow.size
2244− , Just <| Property "outline" "none"
2248− ((Internal.Style.dot classes.any ++ ":focus .focusable, ")
2249− ++ (Internal.Style.dot classes.any ++ ".focusable:focus, ")
2198+ Style (Internal.Style.dot classes.any ++ ":focus .focusable, " ++ Internal.Style.dot classes.any ++ ".focusable:focus")
2250− ++ (".ui-slide-bar:focus + " ++ Internal.Style.dot classes.any ++ " .focusable-thumb")
2252 (List.filterMap identity
2199 (List.filterMap identity
2253 [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
2200 [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
2254 , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
2201 , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
@@ -2271,7 +2218,6 @@ renderFocusStyle focus =
2271 , Just <| Property "outline" "none"
2218 , Just <| Property "outline" "none"
2277focusDefaultStyle : { backgroundColor : Maybe Color, borderColor : Maybe Color, shadow : Maybe Shadow }
2223focusDefaultStyle : { backgroundColor : Maybe Color, borderColor : Maybe Color, shadow : Maybe Shadow }
@@ -2283,7 +2229,7 @@ focusDefaultStyle =
2283 { color =
2229 { color =
2284 Rgba (155 / 255) (203 / 255) 1 1
2230 Rgba (155 / 255) (203 / 255) 1 1
2285 , offset = ( 0, 0 )
2231 , offset = ( 0, 0 )
2286− , blur = 0
2232+ , blur = 3
2287 , size = 3
2233 , size = 3
@@ -2353,31 +2299,7 @@ optionsToRecord options =
2354toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
2300toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
2355toStyleSheet options styleSheet =
2301toStyleSheet options styleSheet =
2356− case options.mode of
2358− -- wrap the style node in a div to prevent `Dark Reader` from blowin up the dom.
2359− VirtualDom.node "div"
2361− [ VirtualDom.node "style"
2363− [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2366− NoStaticStyleSheet ->
2367− -- wrap the style node in a div to prevent `Dark Reader` from blowin up the dom.
2368− VirtualDom.node "div"
2370− [ VirtualDom.node "style"
2372− [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2302+ VirtualDom.node "style" [] [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2376− VirtualDom.node "elm-ui-rules"
2377− [ VirtualDom.property "rules"
2378− (encodeStyles options styleSheet)
2383renderTopLevelValues rules =
2305renderTopLevelValues rules =
@@ -2387,12 +2309,14 @@ renderTopLevelValues rules =
2387 ImportFont _ url ->
2309 ImportFont _ url ->
2388 Just ("@import url('" ++ url ++ "');")
2310 Just ("@import url('" ++ url ++ "');")
2390− -- FontWith with ->
2312+ FontWith with ->
2391− -- case with.url of
2313+ case with.url of
2392− -- Just x ->
2314+ Just x ->
2393− -- Just ("@import url('" ++ x ++ "');")
2315+ Just ("@import url('" ++ x ++ "');")
2394− -- Nothing ->
2317+ Nothing ->
2395− -- Nothing
2318+ Nothing
@@ -2533,17 +2457,12 @@ typefaceAdjustment typefaces =
2533 Nothing ->
2457 Nothing ->
2534 case face of
2458 case face of
2535 FontWith with ->
2459 FontWith with ->
2536− case with.adjustment of
2460+ Just
2542− ( fontAdjustmentRules
2461+ ( fontAdjustmentRules
2543− (.full (convertAdjustment adjustment))
2462+ (.full (convertAdjustment with.adjustment))
2544− , fontAdjustmentRules
2463+ , fontAdjustmentRules
2545− (.capital (convertAdjustment adjustment))
2464+ (.capital (convertAdjustment with.adjustment))
@@ -2593,492 +2512,489 @@ renderProps force (Property key val) existing =
2593 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
2512 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
2596−encodeStyles options stylesheet =
2602− renderStyleRule options style Nothing
2604− ( getStyleName style, Encode.list Encode.string styled )
2609toStyleSheetString : OptionRecord -> List Style -> String
2515toStyleSheetString : OptionRecord -> List Style -> String
2610toStyleSheetString options stylesheet =
2516toStyleSheetString options stylesheet =
2612− combine style rendered =
2518+ renderStyle maybePseudo selector props =
2613− { rules = rendered.rules ++ renderStyleRule options style Nothing
2519+ case maybePseudo of
2615− case topLevelValue style of
2616− Nothing ->
2520+ Nothing ->
2617− rendered.topLevel
2521+ selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}"
2619− Just topLevel ->
2523+ Just pseudo ->
2620− topLevel :: rendered.topLevel
2524+ case pseudo of
2622− in
2526+ case options.hover of
2623− case List.foldl combine { topLevel = [], rules = [] } stylesheet of
2527+ NoHover ->
2624− { topLevel, rules } ->
2528+ ""
2625− renderTopLevelValues topLevel ++ String.concat rules
2531+ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}"
2628−renderStyle : OptionRecord -> Maybe PseudoClass -> String -> List Property -> List String
2533+ AllowHover ->
2629−renderStyle options maybePseudo selector props =
2630− case maybePseudo of
2632− [ selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2534+ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}"
2634− Just pseudo ->
2536+ Focus ->
2635− case pseudo of
2537+ let
2636− Hover ->
2538+ renderedProps =
2637− case options.hover of
2539+ List.foldl (renderProps False) "" props
2550+ ++ "-fs:not(.focus) {"
2560+ , ".focusable-parent:focus ~ "
2641− ForceHover ->
2570+ Active ->
2642− [ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}" ]
2571+ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}"
2573+ renderStyleRule rule maybePseudo =
2575+ Style selector props ->
2576+ renderStyle maybePseudo selector props
2644− AllowHover ->
2578+ Shadows name prop ->
2645− [ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2579+ renderStyle
2582+ [ Property "box-shadow" prop
2647− Focus ->
2585+ Transparency name transparency ->
2649− renderedProps =
2587+ opacity =
2650− List.foldl (renderProps False) "" props
2588+ (1 - transparency)
2652− [ selector ++ "-fs:focus {" ++ renderedProps ++ "\n}"
2592+ renderStyle
2653− , ("." ++ classes.any ++ ":focus " ++ selector ++ "-fs {")
2593+ maybePseudo
2656− , (selector ++ "-fs:focus-within {")
2659− , (".ui-slide-bar:focus + " ++ Internal.Style.dot classes.any ++ " .focusable-thumb" ++ selector ++ "-fs {")
2665− [ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2668−renderStyleRule : OptionRecord -> Style -> Maybe PseudoClass -> List String
2669−renderStyleRule options rule maybePseudo =
2671− Style selector props ->
2672− renderStyle options maybePseudo selector props
2674− Shadows name prop ->
2675− renderStyle options
2677− ("." ++ name)
2594+ ("." ++ name)
2678− [ Property "box-shadow" prop
2681− Transparency name transparency ->
2688− renderStyle options
2691− [ Property "opacity" (String.fromFloat opacity)
2595+ [ Property "opacity" (String.fromFloat opacity)
2695− renderStyle options
2697− (".font-size-" ++ String.fromInt i)
2698− [ Property "font-size" (String.fromInt i ++ "px")
2701− FontFamily name typefaces ->
2705− |> List.filterMap renderVariants
2706− |> String.join ", "
2709− [ Property "font-family"
2711− |> List.map fontName
2712− |> String.join ", "
2714− , Property "font-feature-settings" features
2715− , Property "font-variant"
2716− (if List.any hasSmallCaps typefaces then
2724− renderStyle options
2729− Single class prop val ->
2730− renderStyle options
2733− [ Property prop val
2736− Colored class prop color ->
2737− renderStyle options
2740− [ Property prop (formatColor color)
2743− SpacingStyle cls x y ->
2749− String.fromFloat (toFloat x / 2) ++ "px"
2751− halfY =
2598+ FontSize i ->
2752− String.fromFloat (toFloat y / 2) ++ "px"
2599+ renderStyle
2601+ (".font-size-" ++ String.fromInt i)
2602+ [ Property "font-size" (String.fromInt i ++ "px")
2754− xPx =
2605+ FontFamily name typefaces ->
2609+ |> List.filterMap renderVariants
2755− String.fromInt x ++ "px"
2610+ |> String.join ", "
2613+ [ Property "font-family"
2615+ |> List.map fontName
2616+ |> String.join ", "
2618+ , Property "font-feature-settings" features
2619+ , Property "font-variant"
2620+ (if List.any hasSmallCaps typefaces then
2758− String.fromInt y ++ "px"
2628+ String.join " "
2760− row =
2635+ Single class prop val ->
2761− "." ++ Internal.Style.classes.row
2636+ renderStyle
2639+ [ Property prop val
2763− wrappedRow =
2642+ Colored class prop color ->
2764− "." ++ Internal.Style.classes.wrapped ++ row
2643+ renderStyle
2646+ [ Property prop (formatColor color)
2766− column =
2649+ SpacingStyle cls x y ->
2767− "." ++ Internal.Style.classes.column
2650+ let
2769− page =
2654+ halfX =
2770− "." ++ Internal.Style.classes.page
2655+ String.fromFloat (toFloat x / 2) ++ "px"
2772− paragraph =
2657+ halfY =
2773− "." ++ Internal.Style.classes.paragraph
2658+ String.fromFloat (toFloat y / 2) ++ "px"
2776− "." ++ Internal.Style.classes.alignLeft
2661+ String.fromInt x ++ "px"
2779− "." ++ Internal.Style.classes.alignRight
2664+ String.fromInt y ++ "px"
2782− "." ++ Internal.Style.classes.any
2667+ "." ++ Internal.Style.classes.row
2784− single =
2669+ wrappedRow =
2785− "." ++ Internal.Style.classes.single
2670+ "." ++ Internal.Style.classes.wrapped ++ row
2788− [ renderStyle options maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
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
2795− (class ++ wrappedRow ++ " > " ++ any)
2796− [ Property "margin" (halfY ++ " " ++ halfX)
2799− -- , renderStyle options maybePseudo
2672+ column =
2800− -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2673+ "." ++ Internal.Style.classes.column
2801− -- [ Property "margin-right" "0"
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
2810− (class ++ paragraph)
2811− [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2813− , renderStyle options
2815− ("textarea" ++ any ++ class)
2816− [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2817− , Property "height" ("calc(100% + " ++ String.fromInt y ++ "px)")
2820− -- , renderStyle options
2675+ page =
2821− -- maybePseudo
2676+ "." ++ Internal.Style.classes.page
2822− -- (class ++ paragraph ++ " > " ++ any)
2823− -- [ Property "margin-right" xPx
2824− -- , Property "margin-bottom" yPx
2826− , renderStyle options
2828− (class ++ paragraph ++ " > " ++ left)
2829− [ Property "margin-right" xPx
2831− , renderStyle options
2833− (class ++ paragraph ++ " > " ++ right)
2834− [ Property "margin-left" xPx
2836− , renderStyle options
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")
2845− , renderStyle options
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")
2856− PaddingStyle cls top right bottom left ->
2678+ paragraph =
2857− let
2679+ "." ++ Internal.Style.classes.paragraph
2862− renderStyle options
2865− [ Property "padding"
2866− (String.fromFloat top
2868− ++ String.fromFloat right
2870− ++ String.fromFloat bottom
2872− ++ String.fromFloat left
2877− BorderWidth cls top right bottom left ->
2681+ left =
2878− let
2682+ "." ++ Internal.Style.classes.alignLeft
2883− renderStyle options
2886− [ Property "border-width"
2887− (String.fromInt top
2889− ++ String.fromInt right
2891− ++ String.fromInt bottom
2893− ++ String.fromInt left
2898− GridTemplateStyle template ->
2684+ right =
2899− let
2685+ "." ++ Internal.Style.classes.alignRight
2902− ++ String.join "-" (List.map lengthClassName template.rows)
2904− ++ String.join "-" (List.map lengthClassName template.columns)
2906− ++ lengthClassName (Tuple.first template.spacing)
2908− ++ lengthClassName (Tuple.second template.spacing)
2911− toGridLength (Tuple.second template.spacing)
2914− toGridLength (Tuple.first template.spacing)
2917− toGridLengthHelper Nothing Nothing x
2919− toGridLengthHelper minimum maximum x =
2922− String.fromInt px ++ "px"
2925− case ( minimum, maximum ) of
2926− ( Nothing, Nothing ) ->
2929− ( Just minSize, Nothing ) ->
2930− "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2932− ( Nothing, Just maxSize ) ->
2933− "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2935− ( Just minSize, Just maxSize ) ->
2936− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2939− case ( minimum, maximum ) of
2940− ( Nothing, Nothing ) ->
2941− String.fromInt i ++ "fr"
2943− ( Just minSize, Nothing ) ->
2944− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2946− ( Nothing, Just maxSize ) ->
2947− "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2949− ( Just minSize, Just maxSize ) ->
2950− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2953− toGridLengthHelper (Just m) maximum len
2956− toGridLengthHelper minimum (Just m) len
2960− |> List.map toGridLength
2961− |> String.join ySpacing
2962− |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2966− |> List.map toGridLength
2967− |> String.join ySpacing
2968− |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
2971− class ++ "{" ++ msColumns ++ msRows ++ "}"
2975− |> List.map toGridLength
2977− |> (\x -> "grid-template-columns: " ++ x ++ ";")
2980− template.rows
2688+ "." ++ Internal.Style.classes.any
2981− |> List.map toGridLength
2983− |> (\x -> "grid-template-rows: " ++ x ++ ";")
2985− gapX =
2690+ single =
2986− "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2691+ "." ++ Internal.Style.classes.single
2694+ [ renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
2696+ -- margins don't apply to last element of normal, unwrapped rows
2697+ -- , renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
2698+ -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
2699+ , renderStyle maybePseudo
2700+ (class ++ wrappedRow ++ " > " ++ any)
2701+ [ Property "margin" (halfY ++ " " ++ halfX)
2988− gapY =
2704+ -- , renderStyle maybePseudo
2989− "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2705+ -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2706+ -- [ Property "margin-right" "0"
2709+ , renderStyle maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2710+ , renderStyle maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2711+ , renderStyle maybePseudo (class ++ page ++ " > " ++ left) [ Property "margin-right" xPx ]
2712+ , renderStyle maybePseudo (class ++ page ++ " > " ++ right) [ Property "margin-left" xPx ]
2715+ (class ++ paragraph)
2716+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2720+ ("textarea" ++ class)
2721+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2991− modernGrid =
2724+ -- , renderStyle
2992− class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2725+ -- maybePseudo
2726+ -- (class ++ paragraph ++ " > " ++ any)
2727+ -- [ Property "margin-right" xPx
2728+ -- , Property "margin-bottom" yPx
2732+ (class ++ paragraph ++ " > " ++ left)
2733+ [ Property "margin-right" xPx
2737+ (class ++ paragraph ++ " > " ++ right)
2738+ [ Property "margin-left" xPx
2742+ (class ++ paragraph ++ "::after")
2743+ [ Property "content" "''"
2744+ , Property "display" "block"
2745+ , Property "height" "0"
2746+ , Property "width" "0"
2747+ , Property "margin-top" (String.fromInt (-1 * (y // 2)) ++ "px")
2751+ (class ++ paragraph ++ "::before")
2752+ [ Property "content" "''"
2753+ , Property "display" "block"
2754+ , Property "height" "0"
2755+ , Property "width" "0"
2756+ , Property "margin-bottom" (String.fromInt (-1 * (y // 2)) ++ "px")
2994− supports =
2760+ PaddingStyle cls top right bottom left ->
2995− "@supports (display:grid) {" ++ modernGrid ++ "}"
2761+ let
2997− [ base
2766+ renderStyle
2998− , supports
2767+ maybePseudo
2769+ [ Property "padding"
2770+ (String.fromInt top
2772+ ++ String.fromInt right
2774+ ++ String.fromInt bottom
2776+ ++ String.fromInt left
3001− GridPosition position ->
2781+ BorderWidth cls top right bottom left ->
3003− class =
2783+ class =
3004− ".grid-pos-"
2784+ "."
3005− ++ String.fromInt position.row
2785+ ++ cls
3007− ++ String.fromInt position.col
2787+ renderStyle
3008− ++ "-"
2788+ maybePseudo
3009− ++ String.fromInt position.width
2789+ class
3010− ++ "-"
2790+ [ Property "border-width"
3011− ++ String.fromInt position.height
3016− ++ String.fromInt position.row
2791+ (String.fromInt top
3017− ++ ";"
2792+ ++ "px "
3018− , "-ms-grid-row-span: "
3019− ++ String.fromInt position.height
2793+ ++ String.fromInt right
3020− ++ ";"
2794+ ++ "px "
3021− , "-ms-grid-column: "
3022− ++ String.fromInt position.col
2795+ ++ String.fromInt bottom
3023− ++ ";"
2796+ ++ "px "
3024− , "-ms-grid-column-span: "
3025− ++ String.fromInt position.width
2797+ ++ String.fromInt left
3026− ++ ";"
2798+ ++ "px"
2802+ GridTemplateStyle template ->
2806+ ++ String.join "-" (List.map lengthClassName template.rows)
2808+ ++ String.join "-" (List.map lengthClassName template.columns)
2810+ ++ lengthClassName (Tuple.first template.spacing)
2812+ ++ lengthClassName (Tuple.second template.spacing)
2815+ toGridLength (Tuple.second template.spacing)
2818+ toGridLength (Tuple.first template.spacing)
2821+ toGridLengthHelper Nothing Nothing x
2823+ toGridLengthHelper minimum maximum x =
2826+ String.fromInt px ++ "px"
2829+ case ( minimum, maximum ) of
2830+ ( Nothing, Nothing ) ->
2833+ ( Just minSize, Nothing ) ->
2834+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2836+ ( Nothing, Just maxSize ) ->
2837+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2839+ ( Just minSize, Just maxSize ) ->
2840+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2843+ case ( minimum, maximum ) of
2844+ ( Nothing, Nothing ) ->
2845+ String.fromInt i ++ "fr"
2847+ ( Just minSize, Nothing ) ->
2848+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2850+ ( Nothing, Just maxSize ) ->
2851+ "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2853+ ( Just minSize, Just maxSize ) ->
2854+ "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2857+ toGridLengthHelper (Just m) maximum len
2860+ toGridLengthHelper minimum (Just m) len
2864+ |> List.map toGridLength
2865+ |> String.join ySpacing
2866+ |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2870+ |> List.map toGridLength
2871+ |> String.join ySpacing
2872+ |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
3030− class ++ "{" ++ msPosition ++ "}"
2875+ class ++ "{" ++ msColumns ++ msRows ++ "}"
2879+ |> List.map toGridLength
2881+ |> (\x -> "grid-template-columns: " ++ x ++ ";")
2885+ |> List.map toGridLength
2887+ |> (\x -> "grid-template-rows: " ++ x ++ ";")
2890+ "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2893+ "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2896+ class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2899+ "@supports (display:grid) {" ++ modernGrid ++ "}"
2903+ GridPosition position ->
2907+ ++ String.fromInt position.row
2909+ ++ String.fromInt position.col
2911+ ++ String.fromInt position.width
2913+ ++ String.fromInt position.height
2918+ ++ String.fromInt position.row
2920+ , "-ms-grid-row-span: "
2921+ ++ String.fromInt position.height
2923+ , "-ms-grid-column: "
2924+ ++ String.fromInt position.col
2926+ , "-ms-grid-column-span: "
2927+ ++ String.fromInt position.width
2932+ class ++ "{" ++ msPosition ++ "}"
3032− modernPosition =
2934+ modernPosition =
3033− String.join " "
2935+ String.join " "
3034− [ "grid-row: "
2936+ [ "grid-row: "
3035− ++ String.fromInt position.row
2937+ ++ String.fromInt position.row
3036− ++ " / "
2938+ ++ " / "
3037− ++ String.fromInt (position.row + position.height)
2939+ ++ String.fromInt (position.row + position.height)
3039− , "grid-column: "
2941+ , "grid-column: "
3040− ++ String.fromInt position.col
2942+ ++ String.fromInt position.col
3041− ++ " / "
2943+ ++ " / "
3042− ++ String.fromInt (position.col + position.width)
2944+ ++ String.fromInt (position.col + position.width)
2949+ class ++ "{" ++ modernPosition ++ "}"
2952+ "@supports (display:grid) {" ++ modernGrid ++ "}"
3046− modernGrid =
2956+ PseudoSelector class styles ->
3047− class ++ "{" ++ modernPosition ++ "}"
2957+ let
2958+ renderPseudoRule style =
2959+ renderStyleRule style (Just class)
2961+ List.map renderPseudoRule styles
3049− supports =
2964+ Transform transform ->
3050− "@supports (display:grid) {" ++ modernGrid ++ "}"
2965+ let
3052− [ base
2967+ transformValue transform
3056− PseudoSelector class styles ->
2969+ class =
3057− let
2970+ transformClass transform
3058− renderPseudoRule style =
3059− renderStyleRule options style (Just class)
3061− List.concatMap renderPseudoRule styles
2972+ case ( class, val ) of
2973+ ( Just cls, Just v ) ->
2977+ [ Property "transform"
3063− Transform transform ->
2981+ _ ->
3066− transformValue transform
3068− class =
2984+ combine style rendered =
3069− transformClass transform
2985+ { rules = rendered.rules ++ renderStyleRule style Nothing
3070− in
2986+ , topLevel =
3071− case ( class, val ) of
2987+ case topLevelValue style of
3072− ( Just cls, Just v ) ->
2988+ Nothing ->
3073− renderStyle options
2989+ rendered.topLevel
3076− [ Property "transform"
3080− _ ->
2991+ Just topLevel ->
3081− []
2992+ topLevel :: rendered.topLevel
2995+ case List.foldl combine { topLevel = [], rules = "" } stylesheet of
2996+ { topLevel, rules } ->
2997+ renderTopLevelValues topLevel ++ rules
3084lengthClassName : Length -> String
3000lengthClassName : Length -> String
@@ -3118,12 +3034,12 @@ formatTextShadow shadow =
3121−textShadowClass shadow =
3037+textShadowName shadow =
3122 String.concat
3038 String.concat
3124− , floatClass (Tuple.first shadow.offset) ++ "px"
3040+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
3125− , floatClass (Tuple.second shadow.offset) ++ "px"
3041+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
3126− , floatClass shadow.blur ++ "px"
3042+ , String.fromFloat shadow.blur ++ "px"
3127 , formatColorClass shadow.color
3043 , formatColorClass shadow.color
@@ -3144,17 +3060,17 @@ formatBoxShadow shadow =
3147−boxShadowClass shadow =
3063+boxShadowName shadow =
3148 String.concat <|
3064 String.concat <|
3149 [ if shadow.inset then
3065 [ if shadow.inset then
3150 "box-inset"
3066 "box-inset"
3154− , floatClass (Tuple.first shadow.offset) ++ "px"
3070+ , String.fromFloat (Tuple.first shadow.offset) ++ "px"
3155− , floatClass (Tuple.second shadow.offset) ++ "px"
3071+ , String.fromFloat (Tuple.second shadow.offset) ++ "px"
3156− , floatClass shadow.blur ++ "px"
3072+ , String.fromFloat shadow.blur ++ "px"
3157− , floatClass shadow.size ++ "px"
3073+ , String.fromFloat shadow.size ++ "px"
3158 , formatColorClass shadow.color
3074 , formatColorClass shadow.color
@@ -3199,17 +3115,6 @@ paddingName top right bottom left =
3199 ++ String.fromInt left
3115 ++ String.fromInt left
3202−paddingNameFloat top right bottom left =
3206− ++ floatClass right
3208− ++ floatClass bottom
3213getStyleName : Style -> String
3118getStyleName : Style -> String
3214getStyleName style =
3119getStyleName style =
3215 case style of
3120 case style of