@@ -16,6 +16,7 @@ module Internal.Model exposing
16 , LayoutContext(..)
16 , LayoutContext(..)
17 , Length(..)
17 , Length(..)
18 , Location(..)
18 , Location(..)
19 , NodeName(..)
20 , NodeName(..)
20 , Option(..)
21 , Option(..)
21 , OptionRecord
22 , OptionRecord
@@ -41,7 +42,7 @@ module Internal.Model exposing
41 , asParagraph
42 , asParagraph
43 , asTextColumn
44 , asTextColumn
44− , boxShadowName
45+ , boxShadowClass
45 , columnClass
46 , columnClass
46 , composeTransformation
47 , composeTransformation
47 , contextClasses
48 , contextClasses
@@ -78,15 +79,13 @@ module Internal.Model exposing
78 , onlyStyles
79 , onlyStyles
79 , optionsToRecord
80 , optionsToRecord
80 , paddingName
81 , paddingName
81 , pageClass
83 , pageClass
82 , paragraphClass
84 , paragraphClass
83 , reduceRecursive
85 , reduceRecursive
84 , reduceStyles
86 , reduceStyles
85 , reduceStylesRecursive
87 , reduceStylesRecursive
86 , removeNever
88 , removeNever
90 , renderFontClassName
89 , renderFontClassName
91 , renderHeight
90 , renderHeight
92 , renderRoot
91 , renderRoot
@@ -96,9 +95,8 @@ module Internal.Model exposing
96 , rowClass
95 , rowClass
97 , singleClass
96 , singleClass
98 , spacingName
97 , spacingName
101− , textShadowName
99+ , textShadowClass
103 , toStyleSheet
101 , toStyleSheet
104 , transformClass
102 , transformClass
@@ -114,7 +112,7 @@ import Html.Attributes
114import Html.Keyed
112import Html.Keyed
115import Internal.Flag as Flag exposing (Flag)
113import Internal.Flag as Flag exposing (Flag)
116import Internal.Style exposing (classes, dot)
114import Internal.Style exposing (classes, dot)
117−import Json.Encode as Json
115+import Json.Encode as Encode
118import Set exposing (Set)
116import Set exposing (Set)
119import VirtualDom
117import VirtualDom
@@ -176,7 +174,7 @@ type Style
176 | Colored String String Color
174 | Colored String String Color
177 | SpacingStyle String Int Int
175 | SpacingStyle String Int Int
178 | BorderWidth String Int Int Int Int
176 | BorderWidth String Int Int Int Int
179− | PaddingStyle String Int Int Int Int
177+ | PaddingStyle String Float Float Float Float
180 | GridTemplateStyle
178 | GridTemplateStyle
181 { spacing : ( Length, Length )
179 { spacing : ( Length, Length )
182 , columns : List Length
180 , columns : List Length
@@ -457,7 +455,10 @@ finalizeNode has node attributes children embedMode parentContext =
457 Embedded nodeName internal ->
455 Embedded nodeName internal ->
458 VirtualDom.node nodeName
456 VirtualDom.node nodeName
459 attributes
457 attributes
458+ [ createNode internal
459+ [ Html.Attributes.class
460− [ createNode internal [ Html.Attributes.class (classes.any ++ " " ++ classes.single) ]
460+ (classes.any ++ " " ++ classes.single)
463 case parentContext of
464 case parentContext of
@@ -534,49 +535,45 @@ finalizeNode has node attributes children embedMode parentContext =
536embedWith static opts styles children =
537embedWith static opts styles children =
541+ |> List.foldl reduceStyles ( Set.empty, renderFocusStyle opts.focus )
543+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
545+ |> toStyleSheet opts
537 if static then
547 if static then
538− staticRoot
548+ staticRoot opts
539− :: (styles
549+ :: dynamicStyleSheet
540− |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
542− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
544− |> toStyleSheet opts
546 :: children
550 :: children
549− (styles
553+ dynamicStyleSheet
550− |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
552− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
554− |> toStyleSheet opts
556 :: children
554 :: children
559embedKeyed static opts styles children =
557embedKeyed static opts styles children =
561+ |> List.foldl reduceStyles ( Set.empty, renderFocusStyle opts.focus )
563+ -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
565+ |> toStyleSheet opts
560 if static then
567 if static then
561− ( "static-stylesheet", staticRoot )
568+ ( "static-stylesheet", staticRoot opts )
562 :: ( "dynamic-stylesheet"
569 :: ( "dynamic-stylesheet"
563− , styles
570+ , dynamicStyleSheet
564− |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
566− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
568− |> toStyleSheet opts
570 :: children
572 :: children
573 ( "dynamic-stylesheet"
575 ( "dynamic-stylesheet"
574− , styles
576+ , dynamicStyleSheet
575− |> List.foldl reduceStyles ( Set.empty, [ renderFocusStyle opts.focus ] )
577− -- |> reduceStylesRecursive Set.empty [ ]) --renderFocusStyle opts.focus ]
579− |> toStyleSheet opts
581 :: children
578 :: children
@@ -1035,7 +1032,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1036 gatherAttrRecursive (classes ++ " " ++ newClass)
1033 gatherAttrRecursive (classes ++ " " ++ newClass)
1038− (Flag.merge addToFlags has)
1035+ (Flag.merge addToFlags (Flag.add Flag.width has))
1039 transform
1036 transform
1040 (newStyles ++ styles)
1037 (newStyles ++ styles)
@@ -1056,7 +1053,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1057 "height-px-" ++ val
1054 "height-px-" ++ val
1059− gatherAttrRecursive (name ++ " " ++ classes)
1056+ gatherAttrRecursive (Internal.Style.classes.heightExact ++ " " ++ name ++ " " ++ classes)
1061 (Flag.add Flag.height has)
1058 (Flag.add Flag.height has)
1062 transform
1059 transform
@@ -1113,7 +1110,7 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1114 gatherAttrRecursive (classes ++ " " ++ newClass)
1111 gatherAttrRecursive (classes ++ " " ++ newClass)
1116− (Flag.merge addToFlags has)
1113+ (Flag.merge addToFlags (Flag.add Flag.height has))
1117 transform
1114 transform
1118 (newStyles ++ styles)
1115 (newStyles ++ styles)
@@ -1145,20 +1142,15 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
1145 gatherAttrRecursive classes (addNodeName "h6" node) has transform styles attrs children remaining
1142 gatherAttrRecursive classes (addNodeName "h6" node) has transform styles attrs children remaining
1147 Paragraph ->
1144 Paragraph ->
1148− let
1145+ -- previously we rendered a <p> tag, though apparently this invalidates the html if it has <div>s inside.
1149− newNode =
1146+ -- Since we can't guaranteee that there are no divs, we need another strategy.
1150− case node of
1147+ -- While it's not documented in many places, there apparently is a paragraph aria role
1151− Generic ->
1148+ -- https://github.com/w3c/aria/blob/11f85f41a5b621fdbe85fc9bcdcd270e653a48ba/common/script/roleInfo.js
1152− NodeName "p"
1149+ -- Though we'll need to wait till it gets released in an official wai-aria spec to use it.
1153−
1150+ -- If it's used at the moment, then Lighthouse complains (likely rightfully) that role paragraph is not recognized.
1160− gatherAttrRecursive classes
1151+ gatherAttrRecursive
1161− newNode
1152+ classes
1163 transform
1155 transform
@@ -1444,7 +1436,7 @@ renderHeight h =
1444 "height-px-" ++ val
1436 "height-px-" ++ val
1446 ( Flag.none
1438 ( Flag.none
1447− , name
1439+ , Internal.Style.classes.heightExact ++ " " ++ name
1448 , [ Single name "height" (val ++ "px") ]
1440 , [ Single name "height" (val ++ "px") ]
@@ -1467,7 +1459,7 @@ renderHeight h =
1467 , [ Single
1459 , [ Single
1468 (Internal.Style.classes.any
1460 (Internal.Style.classes.any
1470− ++ Internal.Style.classes.row
1462+ ++ Internal.Style.classes.column
1471 ++ " > "
1463 ++ " > "
1472 ++ (Internal.Style.dot <| "height-fill-" ++ String.fromInt portion)
1464 ++ (Internal.Style.dot <| "height-fill-" ++ String.fromInt portion)
@@ -1486,7 +1478,9 @@ renderHeight h =
1488 "min-height"
1480 "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.
1489− (String.fromInt minSize ++ "px")
1483+ (String.fromInt minSize ++ "px !important")
1491 ( newFlag, newAttrs, newStyle ) =
1485 ( newFlag, newAttrs, newStyle ) =
1492 renderHeight len
1486 renderHeight len
@@ -1823,8 +1817,20 @@ defaultOptions =
1826−staticRoot =
1820+staticRoot : OptionRecord -> VirtualDom.Node msg
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 ]
1827+ [ 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) ] []
1830addWhen ifThis x to =
1836addWhen ifThis x to =
@@ -1942,7 +1948,7 @@ type Spacing
1944type Padding
1950type Padding
1945− = Padding String Int Int Int Int
1951+ = Padding String Float Float Float Float
1948extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing )
1954extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing )
@@ -2038,34 +2044,44 @@ getHeight attrs =
2047+textElementClasses : String
2048+textElementClasses =
2053+ ++ classes.widthContent
2055+ ++ classes.heightContent
2041textElement : String -> VirtualDom.Node msg
2058textElement : String -> VirtualDom.Node msg
2042textElement str =
2059textElement str =
2043 Html.div
2060 Html.div
2044 [ Html.Attributes.class
2061 [ Html.Attributes.class
2045− (String.join " "
2062+ textElementClasses
2048− , classes.widthContent
2049− , classes.heightContent
2053 [ Html.text str ]
2064 [ Html.text str ]
2067+textElementFillClasses : String
2068+textElementFillClasses =
2073+ ++ classes.widthFill
2075+ ++ classes.heightFill
2056textElementFill : String -> VirtualDom.Node msg
2078textElementFill : String -> VirtualDom.Node msg
2057textElementFill str =
2079textElementFill str =
2058− VirtualDom.node "div"
2080+ Html.div
2059 [ Html.Attributes.class
2081 [ Html.Attributes.class
2060− (String.join " "
2082+ textElementFillClasses
2063− , classes.widthFill
2064− , classes.heightFill
2068− [ VirtualDom.text str ]
2084+ [ Html.text str ]
2071type Children x
2087type Children x
@@ -2073,10 +2089,6 @@ type Children x
2073 | Keyed (List ( String, x ))
2089 | Keyed (List ( String, x ))
2077−-- toHtml : OptionRecord -> Element msg -> VirtualDom.Node msg
2080toHtml mode el =
2092toHtml mode el =
2081 case el of
2093 case el of
2082 Unstyled html ->
2094 Unstyled html ->
@@ -2112,8 +2124,7 @@ renderRoot optionList attributes child =
2114type RenderMode
2126type RenderMode
2116− | Layout
2127+ = Layout
2117 | NoStaticStyleSheet
2128 | NoStaticStyleSheet
2118 | WithVirtualCss
2129 | WithVirtualCss
@@ -2162,8 +2173,8 @@ rootStyle =
2162 , SansSerif
2173 , SansSerif
2165− [ StyleClass Flag.bgColor (Colored ("bg-color-" ++ formatColorClass (Rgba 1 1 1 0)) "background-color" (Rgba 1 1 1 0))
2176+ [ StyleClass Flag.bgColor (Colored ("bg-" ++ formatColorClass (Rgba 1 1 1 0)) "background-color" (Rgba 1 1 1 0))
2166− , StyleClass Flag.fontColor (Colored ("font-color-" ++ formatColorClass (Rgba 0 0 0 1)) "color" (Rgba 0 0 0 1))
2177+ , StyleClass Flag.fontColor (Colored ("fc-" ++ formatColorClass (Rgba 0 0 0 1)) "color" (Rgba 0 0 0 1))
2167 , StyleClass Flag.fontSize (FontSize 20)
2178 , StyleClass Flag.fontSize (FontSize 20)
2168 , StyleClass Flag.fontFamily <|
2179 , StyleClass Flag.fontFamily <|
2169 FontFamily (List.foldl renderFontClassName "font-" families)
2180 FontFamily (List.foldl renderFontClassName "font-" families)
@@ -2206,9 +2217,38 @@ renderFontClassName font current =
2207renderFocusStyle :
2218renderFocusStyle :
2208 FocusStyle
2219 FocusStyle
2209− -> Style
2220+ -> List Style
2210renderFocusStyle focus =
2221renderFocusStyle 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, ")
2211− Style (Internal.Style.dot classes.any ++ ":focus .focusable, " ++ Internal.Style.dot classes.any ++ ".focusable:focus")
2249+ ++ (Internal.Style.dot classes.any ++ ".focusable:focus, ")
2250+ ++ (".ui-slide-bar:focus + " ++ Internal.Style.dot classes.any ++ " .focusable-thumb")
2212 (List.filterMap identity
2252 (List.filterMap identity
2213 [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
2253 [ Maybe.map (\color -> Property "border-color" (formatColor color)) focus.borderColor
2214 , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
2254 , Maybe.map (\color -> Property "background-color" (formatColor color)) focus.backgroundColor
@@ -2231,6 +2271,7 @@ renderFocusStyle focus =
2231 , Just <| Property "outline" "none"
2271 , Just <| Property "outline" "none"
2236focusDefaultStyle : { backgroundColor : Maybe Color, borderColor : Maybe Color, shadow : Maybe Shadow }
2277focusDefaultStyle : { backgroundColor : Maybe Color, borderColor : Maybe Color, shadow : Maybe Shadow }
@@ -2242,7 +2283,7 @@ focusDefaultStyle =
2242 { color =
2283 { color =
2243 Rgba (155 / 255) (203 / 255) 1 1
2284 Rgba (155 / 255) (203 / 255) 1 1
2244 , offset = ( 0, 0 )
2285 , offset = ( 0, 0 )
2245− , blur = 3
2286+ , blur = 0
2246 , size = 3
2287 , size = 3
@@ -2312,7 +2353,31 @@ optionsToRecord options =
2313toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
2354toStyleSheet : OptionRecord -> List Style -> VirtualDom.Node msg
2314toStyleSheet options styleSheet =
2355toStyleSheet 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"
2315− VirtualDom.node "style" [] [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2372+ [ VirtualDom.text (toStyleSheetString options styleSheet) ]
2376+ VirtualDom.node "elm-ui-rules"
2377+ [ VirtualDom.property "rules"
2378+ (encodeStyles options styleSheet)
2318renderTopLevelValues rules =
2383renderTopLevelValues rules =
@@ -2528,489 +2593,492 @@ renderProps force (Property key val) existing =
2528 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
2593 existing ++ "\n " ++ key ++ ": " ++ val ++ ";"
2596+encodeStyles options stylesheet =
2602+ renderStyleRule options style Nothing
2604+ ( getStyleName style, Encode.list Encode.string styled )
2531toStyleSheetString : OptionRecord -> List Style -> String
2609toStyleSheetString : OptionRecord -> List Style -> String
2532toStyleSheetString options stylesheet =
2610toStyleSheetString options stylesheet =
2534− renderStyle maybePseudo selector props =
2612+ combine style rendered =
2535− case maybePseudo of
2613+ { rules = rendered.rules ++ renderStyleRule options style Nothing
2536− Nothing ->
2614+ , topLevel =
2537− selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}"
2615+ case topLevelValue style of
2539− Just pseudo ->
2617+ rendered.topLevel
2542− case options.hover of
2546− ForceHover ->
2619+ Just topLevel ->
2547− selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}"
2620+ topLevel :: rendered.topLevel
2623+ case List.foldl combine { topLevel = [], rules = [] } stylesheet of
2624+ { topLevel, rules } ->
2625+ renderTopLevelValues topLevel ++ String.concat rules
2550− selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}"
2552− Focus ->
2628+renderStyle : OptionRecord -> Maybe PseudoClass -> String -> List Property -> List String
2553− let
2629+renderStyle options maybePseudo selector props =
2554− renderedProps =
2630+ case maybePseudo of
2555− List.foldl (renderProps False) "" props
2632+ [ selector ++ "{" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2566− ++ "-fs:not(.focus) {"
2576− , ".focusable-parent:focus ~ "
2586− Active ->
2634+ Just pseudo ->
2587− selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}"
2635+ case pseudo of
2637+ case options.hover of
2589− renderStyleRule rule maybePseudo =
2641+ ForceHover ->
2590− case rule of
2642+ [ selector ++ "-hv {" ++ List.foldl (renderProps True) "" props ++ "\n}" ]
2591− Style selector props ->
2592− renderStyle maybePseudo selector props
2594− Shadows name prop ->
2644+ AllowHover ->
2595− renderStyle
2645+ [ selector ++ "-hv:hover {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2598− [ Property "box-shadow" prop
2601− Transparency name transparency ->
2647+ Focus ->
2603− opacity =
2649+ renderedProps =
2604− (1 - transparency)
2650+ List.foldl (renderProps False) "" props
2608− renderStyle
2652+ [ selector ++ "-fs:focus {" ++ renderedProps ++ "\n}"
2609− maybePseudo
2653+ , ("." ++ classes.any ++ ":focus " ++ selector ++ "-fs {")
2610− ("." ++ name)
2654+ ++ renderedProps
2611− [ Property "opacity" (String.fromFloat opacity)
2655+ ++ "\n}"
2656+ , (selector ++ "-fs:focus-within {")
2659+ , (".ui-slide-bar:focus + " ++ Internal.Style.dot classes.any ++ " .focusable-thumb" ++ selector ++ "-fs {")
2614− FontSize i ->
2664+ Active ->
2615− renderStyle
2665+ [ selector ++ "-act:active {" ++ List.foldl (renderProps False) "" props ++ "\n}" ]
2617− (".font-size-" ++ String.fromInt i)
2618− [ Property "font-size" (String.fromInt i ++ "px")
2621− FontFamily name typefaces ->
2625− |> List.filterMap renderVariants
2626− |> String.join ", "
2629− [ Property "font-family"
2631− |> List.map fontName
2632− |> String.join ", "
2634− , Property "font-feature-settings" features
2635− , Property "font-variant"
2636− (if List.any hasSmallCaps typefaces then
2639− else
2668+renderStyleRule : OptionRecord -> Style -> Maybe PseudoClass -> List String
2640− "normal"
2669+renderStyleRule options rule maybePseudo =
2641− )
2670+ case rule of
2642− ]
2671+ Style selector props ->
2643− in
2672+ renderStyle options maybePseudo selector props
2644− String.join " "
2673+
2674+ Shadows name prop ->
2645− [ renderStyle
2675+ renderStyle options
2646− maybePseudo
2676+ maybePseudo
2647− ("." ++ name)
2677+ ("." ++ name)
2648− families
2678+ [ Property "box-shadow" prop
2651− Single class prop val ->
2681+ Transparency name transparency ->
2652− renderStyle
2688+ renderStyle options
2653− maybePseudo
2689+ maybePseudo
2654− ("." ++ class)
2690+ ("." ++ name)
2655− [ Property prop val
2691+ [ Property "opacity" (String.fromFloat opacity)
2658− Colored class prop color ->
2694+ FontSize i ->
2659− renderStyle
2695+ renderStyle options
2660− maybePseudo
2696+ maybePseudo
2661− ("." ++ class)
2697+ (".font-size-" ++ String.fromInt i)
2662− [ Property prop (formatColor color)
2698+ [ Property "font-size" (String.fromInt i ++ "px")
2665− SpacingStyle cls x y ->
2701+ FontFamily name typefaces ->
2667− class =
2703+ features =
2668− "." ++ cls
2704+ 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
2671− String.fromFloat (toFloat x / 2) ++ "px"
2720+ "normal"
2724+ renderStyle options
2673− halfY =
2729+ Single class prop val ->
2674− String.fromFloat (toFloat y / 2) ++ "px"
2730+ renderStyle options
2733+ [ Property prop val
2676− xPx =
2736+ Colored class prop color ->
2677− String.fromInt x ++ "px"
2737+ renderStyle options
2740+ [ Property prop (formatColor color)
2679− yPx =
2743+ SpacingStyle cls x y ->
2680− String.fromInt y ++ "px"
2744+ let
2683− "." ++ Internal.Style.classes.row
2749+ String.fromFloat (toFloat x / 2) ++ "px"
2685− wrappedRow =
2751+ halfY =
2686− "." ++ Internal.Style.classes.wrapped ++ row
2752+ String.fromFloat (toFloat y / 2) ++ "px"
2688− column =
2754+ xPx =
2689− "." ++ Internal.Style.classes.column
2755+ String.fromInt x ++ "px"
2692− "." ++ Internal.Style.classes.page
2758+ String.fromInt y ++ "px"
2694− paragraph =
2760+ row =
2695− "." ++ Internal.Style.classes.paragraph
2761+ "." ++ Internal.Style.classes.row
2697− left =
2763+ wrappedRow =
2698− "." ++ Internal.Style.classes.alignLeft
2764+ "." ++ Internal.Style.classes.wrapped ++ row
2700− right =
2766+ column =
2701− "." ++ Internal.Style.classes.alignRight
2767+ "." ++ Internal.Style.classes.column
2704− "." ++ Internal.Style.classes.any
2770+ "." ++ Internal.Style.classes.page
2706− single =
2772+ paragraph =
2707− "." ++ Internal.Style.classes.single
2773+ "." ++ Internal.Style.classes.paragraph
2710− [ renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
2712− -- margins don't apply to last element of normal, unwrapped rows
2713− -- , renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
2714− -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
2715− , renderStyle maybePseudo
2716− (class ++ wrappedRow ++ " > " ++ any)
2717− [ Property "margin" (halfY ++ " " ++ halfX)
2720− -- , renderStyle maybePseudo
2775+ left =
2721− -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2776+ "." ++ Internal.Style.classes.alignLeft
2722− -- [ Property "margin-right" "0"
2725− , renderStyle maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2726− , renderStyle maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2727− , renderStyle maybePseudo (class ++ page ++ " > " ++ left) [ Property "margin-right" xPx ]
2728− , renderStyle maybePseudo (class ++ page ++ " > " ++ right) [ Property "margin-left" xPx ]
2731− (class ++ paragraph)
2732− [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2736− ("textarea" ++ class)
2737− [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2742− -- (class ++ paragraph ++ " > " ++ any)
2743− -- [ Property "margin-right" xPx
2744− -- , Property "margin-bottom" yPx
2748− (class ++ paragraph ++ " > " ++ left)
2749− [ Property "margin-right" xPx
2753− (class ++ paragraph ++ " > " ++ right)
2778+ right =
2754− [ Property "margin-left" xPx
2779+ "." ++ Internal.Style.classes.alignRight
2758− (class ++ paragraph ++ "::after")
2759− [ Property "content" "''"
2760− , Property "display" "block"
2761− , Property "height" "0"
2762− , Property "width" "0"
2763− , Property "margin-top" (String.fromInt (-1 * (y // 2)) ++ "px")
2767− (class ++ paragraph ++ "::before")
2768− [ Property "content" "''"
2769− , Property "display" "block"
2770− , Property "height" "0"
2771− , Property "width" "0"
2772− , Property "margin-bottom" (String.fromInt (-1 * (y // 2)) ++ "px")
2776− PaddingStyle cls top right bottom left ->
2781+ any =
2777− let
2782+ "." ++ Internal.Style.classes.any
2785− [ Property "padding"
2786− (String.fromInt top
2788− ++ String.fromInt right
2790− ++ String.fromInt bottom
2792− ++ String.fromInt left
2797− BorderWidth cls top right bottom left ->
2784+ single =
2798− let
2785+ "." ++ Internal.Style.classes.single
2800− "."
2787+ List.concat
2801− ++ cls
2788+ [ renderStyle options maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
2803− renderStyle
2790+ -- margins don't apply to last element of normal, unwrapped rows
2804− maybePseudo
2791+ -- , renderStyle options maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
2805− class
2792+ -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
2806− [ Property "border-width"
2793+ , renderStyle options
2807− (String.fromInt top
2794+ maybePseudo
2808− ++ "px "
2795+ (class ++ wrappedRow ++ " > " ++ any)
2809− ++ String.fromInt right
2796+ [ Property "margin" (halfY ++ " " ++ halfX)
2811− ++ String.fromInt bottom
2813− ++ String.fromInt left
2818− GridTemplateStyle template ->
2799+ -- , renderStyle options maybePseudo
2819− let
2800+ -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2820− class =
2801+ -- [ Property "margin-right" "0"
2821− ".grid-rows-"
2802+ -- ]
2822− ++ String.join "-" (List.map lengthClassName template.rows)
2803+ -- columns
2823− ++ "-cols-"
2804+ , renderStyle options maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2824− ++ String.join "-" (List.map lengthClassName template.columns)
2805+ , renderStyle options maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
2825− ++ "-space-x-"
2806+ , renderStyle options maybePseudo (class ++ page ++ " > " ++ left) [ Property "margin-right" xPx ]
2826− ++ lengthClassName (Tuple.first template.spacing)
2807+ , renderStyle options maybePseudo (class ++ page ++ " > " ++ right) [ Property "margin-left" xPx ]
2827− ++ "-space-y-"
2808+ , renderStyle options
2828− ++ lengthClassName (Tuple.second template.spacing)
2809+ maybePseudo
2829−
2810+ (class ++ paragraph)
2830− ySpacing =
2811+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2831− toGridLength (Tuple.second template.spacing)
2812+ ]
2832−
2813+ , renderStyle options
2833− xSpacing =
2814+ maybePseudo
2834− toGridLength (Tuple.first template.spacing)
2815+ ("textarea" ++ any ++ class)
2835−
2816+ [ Property "line-height" ("calc(1em + " ++ String.fromInt y ++ "px)")
2836− toGridLength x =
2817+ , Property "height" ("calc(100% + " ++ String.fromInt y ++ "px)")
2837− toGridLengthHelper Nothing Nothing x
2818+ ]
2839− toGridLengthHelper minimum maximum x =
2842− String.fromInt px ++ "px"
2845− case ( minimum, maximum ) of
2846− ( Nothing, Nothing ) ->
2849− ( Just minSize, Nothing ) ->
2850− "minmax(" ++ String.fromInt minSize ++ "px, " ++ "max-content)"
2852− ( Nothing, Just maxSize ) ->
2853− "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2855− ( Just minSize, Just maxSize ) ->
2856− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2859− case ( minimum, maximum ) of
2860− ( Nothing, Nothing ) ->
2861− String.fromInt i ++ "fr"
2863− ( Just minSize, Nothing ) ->
2864− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt i ++ "fr" ++ "fr)"
2866− ( Nothing, Just maxSize ) ->
2867− "minmax(max-content, " ++ String.fromInt maxSize ++ "px)"
2869− ( Just minSize, Just maxSize ) ->
2870− "minmax(" ++ String.fromInt minSize ++ "px, " ++ String.fromInt maxSize ++ "px)"
2873− toGridLengthHelper (Just m) maximum len
2876− toGridLengthHelper minimum (Just m) len
2880− |> List.map toGridLength
2881− |> String.join ySpacing
2882− |> (\x -> "-ms-grid-columns: " ++ x ++ ";")
2886− |> List.map toGridLength
2887− |> String.join ySpacing
2888− |> (\x -> "-ms-grid-rows: " ++ x ++ ";")
2891− class ++ "{" ++ msColumns ++ msRows ++ "}"
2895− |> List.map toGridLength
2897− |> (\x -> "grid-template-columns: " ++ x ++ ";")
2901− |> List.map toGridLength
2903− |> (\x -> "grid-template-rows: " ++ x ++ ";")
2906− "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2909− "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
2912− class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
2915− "@supports (display:grid) {" ++ modernGrid ++ "}"
2919− GridPosition position ->
2820+ -- , renderStyle options
2920− let
2821+ -- maybePseudo
2921− class =
2822+ -- (class ++ paragraph ++ " > " ++ any)
2922− ".grid-pos-"
2823+ -- [ Property "margin-right" xPx
2923− ++ String.fromInt position.row
2824+ -- , Property "margin-bottom" yPx
2925− ++ String.fromInt position.col
2826+ , renderStyle options
2926− ++ "-"
2827+ maybePseudo
2927− ++ String.fromInt position.width
2828+ (class ++ paragraph ++ " > " ++ left)
2928− ++ "-"
2829+ [ Property "margin-right" xPx
2929− ++ String.fromInt position.height
2830+ ]
2930−
2831+ , renderStyle options
2931− msPosition =
2832+ maybePseudo
2932− String.join " "
2833+ (class ++ paragraph ++ " > " ++ right)
2933− [ "-ms-grid-row: "
2834+ [ Property "margin-left" xPx
2934− ++ String.fromInt position.row
2835+ ]
2935− ++ ";"
2836+ , renderStyle options
2936− , "-ms-grid-row-span: "
2837+ maybePseudo
2937− ++ String.fromInt position.height
2838+ (class ++ paragraph ++ "::after")
2938− ++ ";"
2839+ [ Property "content" "''"
2939− , "-ms-grid-column: "
2840+ , Property "display" "block"
2940− ++ String.fromInt position.col
2841+ , Property "height" "0"
2941− ++ ";"
2842+ , Property "width" "0"
2942− , "-ms-grid-column-span: "
2843+ , Property "margin-top" (String.fromInt (-1 * (y // 2)) ++ "px")
2943− ++ String.fromInt position.width
2844+ ]
2944− ++ ";"
2845+ , renderStyle options
2946−
2847+ (class ++ paragraph ++ "::before")
2947− base =
2848+ [ Property "content" "''"
2948− class ++ "{" ++ msPosition ++ "}"
2849+ , Property "display" "block"
2949−
2850+ , Property "height" "0"
2950− modernPosition =
2851+ , Property "width" "0"
2951− String.join " "
2852+ , Property "margin-bottom" (String.fromInt (-1 * (y // 2)) ++ "px")
2952− [ "grid-row: "
2853+ ]
2953− ++ String.fromInt position.row
2854+ ]
2955− ++ String.fromInt (position.row + position.height)
2958− ++ String.fromInt position.col
2960− ++ String.fromInt (position.col + position.width)
2965− class ++ "{" ++ modernPosition ++ "}"
2968− "@supports (display:grid) {" ++ modernGrid ++ "}"
2972− PseudoSelector class styles ->
2856+ PaddingStyle cls top right bottom left ->
2974− renderPseudoRule style =
2858+ class =
2975− renderStyleRule style (Just class)
2859+ "."
2977− List.map renderPseudoRule styles
2861+ in
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 ->
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 ->
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
2978 |> String.join " "
2976 |> String.join " "
2977+ |> (\x -> "grid-template-columns: " ++ x ++ ";")
2980− Transform transform ->
2979+ rows =
2981− let
2980+ template.rows
2982− val =
2981+ |> List.map toGridLength
2983− transformValue transform
2982+ |> String.join " "
2983+ |> (\x -> "grid-template-rows: " ++ x ++ ";")
2985− class =
2985+ gapX =
2986− transformClass transform
2986+ "grid-column-gap:" ++ toGridLength (Tuple.first template.spacing) ++ ";"
2988− case ( class, val ) of
2989− ( Just cls, Just v ) ->
2993− [ Property "transform"
2998− ""
2989+ "grid-row-gap:" ++ toGridLength (Tuple.second template.spacing) ++ ";"
3000− combine style rendered =
2991+ modernGrid =
3001− { rules = rendered.rules ++ renderStyleRule style Nothing
2992+ class ++ "{" ++ columns ++ rows ++ gapX ++ gapY ++ "}"
3003− case topLevelValue style of
3007− Just topLevel ->
2994+ supports =
3008− topLevel :: rendered.topLevel
2995+ "@supports (display:grid) {" ++ modernGrid ++ "}"
3011− case List.foldl combine { topLevel = [], rules = "" } stylesheet of
2998+ , supports
3012− { topLevel, rules } ->
2999+ ]
3013− renderTopLevelValues topLevel ++ rules
3000+
3001+ GridPosition position ->
3005+ ++ String.fromInt position.row
3007+ ++ String.fromInt position.col
3009+ ++ String.fromInt position.width
3011+ ++ String.fromInt position.height
3016+ ++ String.fromInt position.row
3018+ , "-ms-grid-row-span: "
3019+ ++ String.fromInt position.height
3021+ , "-ms-grid-column: "
3022+ ++ String.fromInt position.col
3024+ , "-ms-grid-column-span: "
3025+ ++ String.fromInt position.width
3030+ class ++ "{" ++ msPosition ++ "}"
3035+ ++ String.fromInt position.row
3037+ ++ String.fromInt (position.row + position.height)
3040+ ++ String.fromInt position.col
3042+ ++ String.fromInt (position.col + position.width)
3047+ class ++ "{" ++ modernPosition ++ "}"
3050+ "@supports (display:grid) {" ++ modernGrid ++ "}"
3056+ PseudoSelector class styles ->
3058+ renderPseudoRule style =
3059+ renderStyleRule options style (Just class)
3061+ List.concatMap renderPseudoRule styles
3063+ Transform transform ->
3066+ transformValue transform
3069+ transformClass transform
3071+ case ( class, val ) of
3072+ ( Just cls, Just v ) ->
3073+ renderStyle options
3076+ [ Property "transform"
3016lengthClassName : Length -> String
3084lengthClassName : Length -> String
@@ -3050,12 +3118,12 @@ formatTextShadow shadow =
3053−textShadowName shadow =
3121+textShadowClass shadow =
3054 String.concat
3122 String.concat
3056− , String.fromFloat (Tuple.first shadow.offset) ++ "px"
3124+ , floatClass (Tuple.first shadow.offset) ++ "px"
3057− , String.fromFloat (Tuple.second shadow.offset) ++ "px"
3125+ , floatClass (Tuple.second shadow.offset) ++ "px"
3058− , String.fromFloat shadow.blur ++ "px"
3126+ , floatClass shadow.blur ++ "px"
3059 , formatColorClass shadow.color
3127 , formatColorClass shadow.color
@@ -3076,17 +3144,17 @@ formatBoxShadow shadow =
3079−boxShadowName shadow =
3147+boxShadowClass shadow =
3080 String.concat <|
3148 String.concat <|
3081 [ if shadow.inset then
3149 [ if shadow.inset then
3082 "box-inset"
3150 "box-inset"
3086− , String.fromFloat (Tuple.first shadow.offset) ++ "px"
3154+ , floatClass (Tuple.first shadow.offset) ++ "px"
3087− , String.fromFloat (Tuple.second shadow.offset) ++ "px"
3155+ , floatClass (Tuple.second shadow.offset) ++ "px"
3088− , String.fromFloat shadow.blur ++ "px"
3156+ , floatClass shadow.blur ++ "px"
3089− , String.fromFloat shadow.size ++ "px"
3157+ , floatClass shadow.size ++ "px"
3090 , formatColorClass shadow.color
3158 , formatColorClass shadow.color
@@ -3131,6 +3199,17 @@ paddingName top right bottom left =
3131 ++ String.fromInt left
3199 ++ String.fromInt left
3202+paddingNameFloat top right bottom left =
3206+ ++ floatClass right
3208+ ++ floatClass bottom
3134getStyleName : Style -> String
3213getStyleName : Style -> String
3135getStyleName style =
3214getStyleName style =
3136 case style of
3215 case style of