diff --git a/cstyle/transformers/scrollbar/main.go b/cstyle/transformers/scrollbar/main.go
index 668d23a..9bcef3a 100644
--- a/cstyle/transformers/scrollbar/main.go
+++ b/cstyle/transformers/scrollbar/main.go
@@ -36,3 +36 @@ func Init() cstyle.Transformer {
- trackWidth := "14px"
- thumbWidth := "8px"
- thumbMargin := "3px"
+ width := "14px"
@@ -40,3 +38 @@ func Init() cstyle.Transformer {
- trackWidth = "10px"
- thumbWidth = "6px"
- thumbMargin = "2px"
+ width = "10px"
@@ -64,2 +60 @@ func Init() cstyle.Transformer {
- // X scrollbar
- xScrollbar := false
+ // yScrollbar := false
@@ -67 +62,3 @@ func Init() cstyle.Transformer {
- if (n.Style["overflow-x"] == "scroll" || n.Style["overflow-x"] == "auto") && ((n.ScrollWidth > int(c.Width) && n.TagName == "html") || n.ScrollWidth > 0) {
+ // Y scrollbar
+
+ if (n.Style["overflow-y"] == "scroll" || n.Style["overflow-y"] == "auto") && ((n.ScrollHeight > int(c.Height) && n.TagName == "html") || n.ScrollHeight > 0) {
@@ -71,4 +68,4 @@ func Init() cstyle.Transformer {
- scrollbar.Style["bottom"] = "0px"
- scrollbar.Style["left"] = "0"
- scrollbar.Style["width"] = "100%"
- scrollbar.Style["height"] = trackWidth
+ scrollbar.Style["top"] = "0"
+ scrollbar.Style["right"] = "0"
+ scrollbar.Style["width"] = width
+ scrollbar.Style["height"] = "100%"
@@ -76 +73,3 @@ func Init() cstyle.Transformer {
- scrollbar.SetAttribute("direction", "x")
+ scrollbar.SetAttribute("direction", "y")
+
+ thumb := n.CreateElement("grim-thumb")
@@ -78 +76,0 @@ func Init() cstyle.Transformer {
- thumb := n.CreateElement("grim-thumbx")
@@ -80,4 +78,4 @@ func Init() cstyle.Transformer {
- thumb.Style["left"] = strconv.Itoa(n.ScrollLeft) + "px"
- thumb.Style["top"] = thumbMargin
- thumb.Style["height"] = thumbWidth
- thumb.Style["width"] = "20px"
+ thumb.Style["top"] = strconv.Itoa(n.ScrollTop) + "px"
+ thumb.Style["left"] = "0"
+ thumb.Style["width"] = width
+ thumb.Style["height"] = "20px"
@@ -86 +83,0 @@ func Init() cstyle.Transformer {
- thumb.Style["border-radius"] = "10px"
@@ -102 +99,15 @@ func Init() cstyle.Transformer {
- xScrollbar = true
+
+ n.Style["width"] = "calc(" + n.Style["width"] + "-" + width + ")"
+ pr := n.Style["padding-right"]
+ if pr == "" {
+ if n.Style["padding"] != "" {
+ pr = n.Style["padding"]
+ }
+ }
+
+ if pr != "" {
+ n.Style["padding-right"] = "calc(" + pr + "+" + width + ")"
+ } else {
+ n.Style["padding-right"] = width
+ }
+ // yScrollbar = true
@@ -106 +117 @@ func Init() cstyle.Transformer {
- // Y scrollbar
+ // X scrollbar
@@ -108 +119 @@ func Init() cstyle.Transformer {
- if (n.Style["overflow-y"] == "scroll" || n.Style["overflow-y"] == "auto") && ((n.ScrollHeight > int(c.Height) && n.TagName == "html") || n.ScrollHeight > 0) {
+ if (n.Style["overflow-x"] == "scroll" || n.Style["overflow-x"] == "auto") && ((n.ScrollWidth > int(c.Width) && n.TagName == "html") || n.ScrollWidth > 0) {
@@ -112,4 +123,8 @@ func Init() cstyle.Transformer {
- scrollbar.Style["top"] = "0"
- scrollbar.Style["right"] = "0"
- scrollbar.Style["width"] = trackWidth
- scrollbar.Style["height"] = "100%"
+ scrollbar.Style["bottom"] = "0px"
+ scrollbar.Style["left"] = "0"
+ // if yScrollbar {
+ // scrollbar.Style["width"] = "calc(100% - " + width + ")"
+ // } else {
+ scrollbar.Style["width"] = "100%"
+ // }
+ scrollbar.Style["height"] = width
@@ -117,5 +132 @@ func Init() cstyle.Transformer {
- scrollbar.SetAttribute("direction", "y")
-
- if xScrollbar {
- scrollbar.Style["height"] = "calc(100% - " + trackWidth + ")"
- }
+ scrollbar.SetAttribute("direction", "x")
@@ -123 +134 @@ func Init() cstyle.Transformer {
- thumb := n.CreateElement("grim-thumby")
+ thumb := n.CreateElement("grim-thumb")
@@ -126,4 +137,5 @@ func Init() cstyle.Transformer {
- thumb.Style["top"] = strconv.Itoa(n.ScrollTop) + "px"
- thumb.Style["left"] = "0"
- thumb.Style["width"] = thumbWidth
- thumb.Style["height"] = "20px"
+ // thumb.Style["left"] = "10px"
+ thumb.Style["left"] = strconv.Itoa(n.ScrollLeft) + "px"
+ thumb.Style["top"] = "0px"
+ thumb.Style["height"] = width
+ thumb.Style["width"] = "20px"
@@ -132,2 +143,0 @@ func Init() cstyle.Transformer {
- thumb.Style["margin-left"] = thumbMargin
- thumb.Style["border-radius"] = "10px"
@@ -150,13 +159,0 @@ func Init() cstyle.Transformer {
- n.Style["width"] = "calc(" + n.Style["width"] + "-" + trackWidth + ")"
- pr := n.Style["padding-right"]
- if pr == "" {
- if n.Style["padding"] != "" {
- pr = n.Style["padding"]
- }
- }
-
- if pr != "" {
- n.Style["padding-right"] = "calc(" + pr + "+" + trackWidth + ")"
- } else {
- n.Style["padding-right"] = trackWidth
- }
package scrollbar
import (
"grim/cstyle"
"grim/element"
"strconv"
"strings"
)
func Init() cstyle.Transformer {
return cstyle.Transformer{
Selector: func(n *element.Node) bool {
if n.Style["overflow"] != "" || n.Style["overflow-x"] != "" || n.Style["overflow-y"] != "" {
return true
} else {
return false
}
},
Handler: func(n *element.Node, c *cstyle.CSS) *element.Node {
overflowProps := strings.Split(n.Style["overflow"], " ")
if n.Style["overflow-y"] == "" {
val := overflowProps[0]
if len(overflowProps) >= 2 {
val = overflowProps[1]
}
n.Style["overflow-y"] = val
}
if n.Style["overflow-x"] == "" {
n.Style["overflow-x"] = overflowProps[0]
}
if n.Style["position"] == "" {
n.Style["position"] = "relative"
}
trackWidth := "14px"
thumbWidth := "8px"
thumbMargin := "3px"
if n.Style["scrollbar-width"] == "thin" {
trackWidth = "10px"
thumbWidth = "6px"
thumbMargin = "2px"
}
if n.Style["scrollbar-width"] == "none" {
return n
}
splitStr := strings.Split(n.Style["scrollbar-color"], " ")
// Initialize the variables
var backgroundColor, thumbColor string
// Check the length of the split result and assign the values accordingly
if len(splitStr) >= 2 {
backgroundColor = splitStr[1]
thumbColor = splitStr[0]
} else {
backgroundColor = "#fafafa"
thumbColor = "#c7c7c7"
}
// X scrollbar
xScrollbar := false
if (n.Style["overflow-x"] == "scroll" || n.Style["overflow-x"] == "auto") && ((n.ScrollWidth > int(c.Width) && n.TagName == "html") || n.ScrollWidth > 0) {
scrollbar := n.CreateElement("grim-track")
scrollbar.Style["position"] = "absolute"
scrollbar.Style["bottom"] = "0px"
scrollbar.Style["left"] = "0"
scrollbar.Style["width"] = "100%"
scrollbar.Style["height"] = trackWidth
scrollbar.Style["background"] = backgroundColor
scrollbar.SetAttribute("direction", "x")
thumb := n.CreateElement("grim-thumbx")
thumb.Style["position"] = "absolute"
thumb.Style["left"] = strconv.Itoa(n.ScrollLeft) + "px"
thumb.Style["top"] = thumbMargin
thumb.Style["height"] = thumbWidth
thumb.Style["width"] = "20px"
thumb.Style["background"] = thumbColor
thumb.Style["cursor"] = "pointer"
thumb.Style["border-radius"] = "10px"
for k, v := range n.PseudoElements["::-webkit-scrollbar"] {
scrollbar.Style[k] = v
thumb.Style[k] = v
}
for k, v := range n.PseudoElements["::-webkit-scrollbar-track"] {
scrollbar.Style[k] = v
}
for k, v := range n.PseudoElements["::-webkit-scrollbar-thumb"] {
thumb.Style[k] = v
}
scrollbar.AppendChild(&thumb)
xScrollbar = true
n.AppendChild(&scrollbar)
}
// Y scrollbar
if (n.Style["overflow-y"] == "scroll" || n.Style["overflow-y"] == "auto") && ((n.ScrollHeight > int(c.Height) && n.TagName == "html") || n.ScrollHeight > 0) {
scrollbar := n.CreateElement("grim-track")
scrollbar.Style["position"] = "absolute"
scrollbar.Style["top"] = "0"
scrollbar.Style["right"] = "0"
scrollbar.Style["width"] = trackWidth
scrollbar.Style["height"] = "100%"
scrollbar.Style["background"] = backgroundColor
scrollbar.SetAttribute("direction", "y")
if xScrollbar {
scrollbar.Style["height"] = "calc(100% - " + trackWidth + ")"
}
thumb := n.CreateElement("grim-thumby")
thumb.Style["position"] = "absolute"
thumb.Style["top"] = strconv.Itoa(n.ScrollTop) + "px"
thumb.Style["left"] = "0"
thumb.Style["width"] = thumbWidth
thumb.Style["height"] = "20px"
thumb.Style["background"] = thumbColor
thumb.Style["cursor"] = "pointer"
thumb.Style["margin-left"] = thumbMargin
thumb.Style["border-radius"] = "10px"
for k, v := range n.PseudoElements["::-webkit-scrollbar"] {
scrollbar.Style[k] = v
thumb.Style[k] = v
}
for k, v := range n.PseudoElements["::-webkit-scrollbar-track"] {
scrollbar.Style[k] = v
}
for k, v := range n.PseudoElements["::-webkit-scrollbar-thumb"] {
thumb.Style[k] = v
}
scrollbar.AppendChild(&thumb)
n.Style["width"] = "calc(" + n.Style["width"] + "-" + trackWidth + ")"
pr := n.Style["padding-right"]
if pr == "" {
if n.Style["padding"] != "" {
pr = n.Style["padding"]
}
}
if pr != "" {
n.Style["padding-right"] = "calc(" + pr + "+" + trackWidth + ")"
} else {
n.Style["padding-right"] = trackWidth
}
n.AppendChild(&scrollbar)
}
return n
},
}
}