Diff
diff --git a/cstyle/main.go b/cstyle/main.go
index de38720..e7d5532 100644
--- a/cstyle/main.go
+++ b/cstyle/main.go
@@ -2,0 +3,5 @@ package cstyle
+// package aui/goldie
+// https://pkg.go.dev/automated.sh/goldie
+// https://pkg.go.dev/automated.sh/aui
+// https://pkg.go.dev/automated.sh/oat
+
@@ -13 +17,0 @@ import (
- "strconv"
@@ -60 +63,0 @@ var inheritedProps = []string{
- "text-decoration",
@@ -101,4 +104,2 @@ func (c *CSS) GetStyles(n element.Node) map[string]string {
- // This is different than node.Style
- // temp1 = CSS
- // temp1.style == CSSStyleDeclaration {0: 'color', accentColor: '', additiveSymbols: '', alignContent: '', alignItems: '', alignSelf: '', …}
- // temp1.getAttribute("style") == 'color:#a6e22e'
+ // !ISSUE: why is this needed, the "attribute" is n.Style that should be mapped during init
+ // + when a user adds a style via the style attirbute it will just be in the .Style prop...
@@ -109,8 +109,0 @@ func (c *CSS) GetStyles(n element.Node) map[string]string {
- if n.Parent != nil {
- if styles["z-index"] == "" && n.Parent.Style["z-index"] != "" {
- z, _ := strconv.Atoi(n.Parent.Style["z-index"])
- z += 1
- styles["z-index"] = strconv.Itoa(z)
- }
- }
-
@@ -133 +126 @@ func CheckNode(n *element.Node, state *map[string]element.State) {
- fmt.Printf("X: %v, Y: %v, Z: %v\n", self.X, self.Y, self.Z)
+ fmt.Printf("X: %v, Y: %v\n", self.X, self.Y)
@@ -135 +128 @@ func CheckNode(n *element.Node, state *map[string]element.State) {
- fmt.Printf("Styles: %v\n", self.Style)
+ fmt.Printf("Styles: %v\n", n.Style)
@@ -149,0 +143 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
+ n.Style = c.GetStyles(*n)
@@ -154,5 +148,2 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- // !ISSUE: BREAKING
- self.Style = c.GetStyles(*n)
-
- self.Background = color.Parse(self.Style, "background")
- self.Border, _ = CompleteBorder(self.Style, self, parent)
+ self.Background = color.Parse(n.Style, "background")
+ self.Border, _ = CompleteBorder(n.Style)
@@ -160 +151 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- fs, _ := utils.ConvertToPixels(self.Style["font-size"], parent.EM, parent.Width)
+ fs, _ := utils.ConvertToPixels(n.Style["font-size"], parent.EM, parent.Width)
@@ -163 +154 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["display"] == "none" {
+ if n.Style["display"] == "none" {
@@ -171,17 +162 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["width"] == "" && self.Style["display"] == "block" {
- self.Style["width"] = "100%"
- }
-
- // Set Z index value to be sorted in window
- if self.Style["z-index"] != "" {
- z, _ := strconv.Atoi(self.Style["z-index"])
- self.Z = float32(z)
- }
-
- if parent.Z > 0 {
- self.Z = parent.Z + 1
- }
-
- (*state)[n.Properties.Id] = self
-
- wh := utils.GetWH(*n, state)
+ wh := utils.GetWH(*n)
@@ -195,2 +170,2 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- m := utils.GetMP(*n, wh, state, "margin")
- p := utils.GetMP(*n, wh, state, "padding")
+ m := utils.GetMP(*n, "margin")
+ p := utils.GetMP(*n, "padding")
@@ -201,2 +176,2 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["position"] == "absolute" {
- bas := utils.GetPositionOffsetNode(n, state)
+ if n.Style["position"] == "absolute" {
+ bas := utils.GetPositionOffsetNode(n)
@@ -204,2 +179,2 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["top"] != "" {
- v, _ := utils.ConvertToPixels(self.Style["top"], self.EM, parent.Width)
+ if n.Style["top"] != "" {
+ v, _ := utils.ConvertToPixels(n.Style["top"], self.EM, parent.Width)
@@ -209,2 +184,2 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["left"] != "" {
- v, _ := utils.ConvertToPixels(self.Style["left"], self.EM, parent.Width)
+ if n.Style["left"] != "" {
+ v, _ := utils.ConvertToPixels(n.Style["left"], self.EM, parent.Width)
@@ -214,2 +189,2 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["right"] != "" {
- v, _ := utils.ConvertToPixels(self.Style["right"], self.EM, parent.Width)
+ if n.Style["right"] != "" {
+ v, _ := utils.ConvertToPixels(n.Style["right"], self.EM, parent.Width)
@@ -219,2 +194,2 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["bottom"] != "" {
- v, _ := utils.ConvertToPixels(self.Style["bottom"], self.EM, parent.Width)
+ if n.Style["bottom"] != "" {
+ v, _ := utils.ConvertToPixels(n.Style["bottom"], self.EM, parent.Width)
@@ -224 +198,0 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
-
@@ -225,0 +200 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
+ // !ISSUE: Blue square goes under a absoulutly positioned element when it should pass through
@@ -227,16 +202,9 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- vState := s[v.Properties.Id]
- if vState.Style["position"] != "absolute" {
- if v.Properties.Id == n.Properties.Id {
- if i-1 > 0 {
- sib := n.Parent.Children[i-1]
- sibling := s[sib.Properties.Id]
- if sibling.Style["position"] != "absolute" {
- if self.Style["display"] == "inline" {
- if sibling.Style["display"] == "inline" {
- y = sibling.Y
- } else {
- y = sibling.Y + sibling.Height
- }
- } else {
- y = sibling.Y + sibling.Height
- }
+ if v.Properties.Id == n.Properties.Id {
+ if i-1 > 0 {
+ sib := n.Parent.Children[i-1]
+ sibling := s[sib.Properties.Id]
+ if n.Style["display"] == "inline" {
+ if sib.Style["display"] == "inline" {
+ y = sibling.Y
+ } else {
+ y = sibling.Y + sibling.Height
@@ -244 +212,2 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
-
+ } else {
+ y = sibling.Y + sibling.Height
@@ -246,4 +214,0 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- break
- } else if self.Style["display"] != "inline" {
- vState := s[v.Properties.Id]
- y += vState.Margin.Top + vState.Margin.Bottom + vState.Padding.Top + vState.Padding.Bottom + vState.Height + (vState.Border.Width * 2)
@@ -250,0 +216,4 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
+ break
+ } else if n.Style["display"] != "inline" {
+ vState := s[v.Properties.Id]
+ y += vState.Margin.Top + vState.Margin.Bottom + vState.Padding.Top + vState.Padding.Bottom + vState.Height
@@ -252 +220,0 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
-
@@ -272,0 +241 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
+ // fmt.Println(n.InnerText, len(n.Children))
@@ -276 +245 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- self.Height = height
+ self.Height = height + self.Padding.Bottom
@@ -282 +250,0 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- // !ISSUE: Doesn't break the h1 element for some reason
@@ -284 +252 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["display"] == "inline" {
+ if n.Style["display"] == "inline" {
@@ -309,4 +277,4 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style["height"] == "" {
- if cState.Style["position"] != "absolute" && cState.Y+cState.Height > childYOffset {
- childYOffset = cState.Y + cState.Height
- self.Height = (cState.Y - self.Y) + cState.Height
+ if n.Style["height"] == "" {
+ if n.Children[i].Style["position"] != "absolute" && cState.Y > childYOffset {
+ childYOffset = cState.Y
+ self.Height += cState.Height
@@ -318,0 +287 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
+ // fmt.Println(n.TagName, self.Width, v.TagName, cState.Width)
@@ -326,23 +294,0 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- // !ISSUE: Align Text
- // if n.Style["text-align"] == "center" {
- // minX := float32(9e15)
- // maxXW := float32(0)
- // fmt.Println(n.Properties.Id, len(n.Children))
- // for _, v := range n.Children {
- // cState := (*state)[v.Properties.Id]
- // if cState.X < minX {
- // minX = cState.X
- // }
- // if (cState.X + cState.Width) > maxXW {
- // maxXW = cState.X + cState.Width
- // }
- // }
- // for _, v := range n.Children {
- // cState := (*state)[v.Properties.Id]
- // cState.X += (self.Width - (maxXW - minX)) / 2
- // (*state)[v.Properties.Id] = cState
- // }
- // }
-
- // (*state)[n.Properties.Id] = self
-
@@ -357 +303 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- if self.Style[name] != value && !(value == "*") {
+ if n.Style[name] != value && !(value == "*") {
@@ -362 +307,0 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
- // !ISSUE: Might save memory by making a state map tree and passing that instead of the node it's self
@@ -378 +323 @@ func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State)
-func CompleteBorder(cssProperties map[string]string, self, parent element.State) (element.Border, error) {
+func parseBorderShorthand(borderShorthand string) (element.Border, error) {
@@ -380 +325 @@ func CompleteBorder(cssProperties map[string]string, self, parent element.State)
- borderComponents := strings.Fields(cssProperties["border"])
+ borderComponents := strings.Fields(borderShorthand)
@@ -403,2 +347,0 @@ func CompleteBorder(cssProperties map[string]string, self, parent element.State)
- w, _ := utils.ConvertToPixels(width, self.EM, parent.Width)
-
@@ -406 +349 @@ func CompleteBorder(cssProperties map[string]string, self, parent element.State)
- Width: w,
+ Width: width,
@@ -409 +352 @@ func CompleteBorder(cssProperties map[string]string, self, parent element.State)
- Radius: cssProperties["border-radius"],
+ Radius: "", // Default radius
@@ -415,0 +359,7 @@ func CompleteBorder(cssProperties map[string]string, self, parent element.State)
+func CompleteBorder(cssProperties map[string]string) (element.Border, error) {
+ border, err := parseBorderShorthand(cssProperties["border"])
+ border.Radius = cssProperties["border-radius"]
+
+ return border, err
+}
+
@@ -425 +375 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- if self.Style["font-weight"] == "bold" {
+ if n.Style["font-weight"] == "bold" {
@@ -429 +379 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- if self.Style["font-style"] == "italic" {
+ if n.Style["font-style"] == "italic" {
@@ -434 +384 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- f, _ := font.LoadFont(self.Style["font-family"], int(self.EM), bold, italic)
+ f, _ := font.LoadFont(n.Style["font-family"], int(self.EM), bold, italic)
@@ -438,3 +388,3 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- letterSpacing, _ := utils.ConvertToPixels(self.Style["letter-spacing"], self.EM, parent.Width)
- wordSpacing, _ := utils.ConvertToPixels(self.Style["word-spacing"], self.EM, parent.Width)
- lineHeight, _ := utils.ConvertToPixels(self.Style["line-height"], self.EM, parent.Width)
+ letterSpacing, _ := utils.ConvertToPixels(n.Style["letter-spacing"], self.EM, parent.Width)
+ wordSpacing, _ := utils.ConvertToPixels(n.Style["word-spacing"], self.EM, parent.Width)
+ lineHeight, _ := utils.ConvertToPixels(n.Style["line-height"], self.EM, parent.Width)
@@ -450 +400 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- if self.Style["word-wrap"] == "break-word" {
+ if n.Style["word-wrap"] == "break-word" {
@@ -454 +404 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- if self.Style["text-wrap"] == "wrap" || self.Style["text-wrap"] == "balance" {
+ if n.Style["text-wrap"] == "wrap" || n.Style["text-wrap"] == "balance" {
@@ -460,2 +410,2 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- if self.Style["text-decoration-thickness"] == "auto" || self.Style["text-decoration-thickness"] == "" {
- dt = self.EM / 7
+ if n.Style["text-decoration-thickness"] == "auto" || n.Style["text-decoration-thickness"] == "" {
+ dt = 3
@@ -463 +413 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- dt, _ = utils.ConvertToPixels(self.Style["text-decoration-thickness"], self.EM, parent.Width)
+ dt, _ = utils.ConvertToPixels(n.Style["text-decoration-thickness"], self.EM, parent.Width)
@@ -466 +416 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- col := color.Parse(self.Style, "font")
+ col := color.Parse(n.Style, "font")
@@ -471,2 +421,2 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- text.DecorationColor = color.Parse(self.Style, "decoration")
- text.Align = self.Style["text-align"]
+ text.DecorationColor = color.Parse(n.Style, "decoration")
+ text.Align = n.Style["text-align"]
@@ -476 +426 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- text.WhiteSpace = self.Style["white-space"]
+ text.WhiteSpace = n.Style["white-space"]
@@ -478,3 +428,3 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- text.Overlined = self.Style["text-decoration"] == "overline"
- text.Underlined = self.Style["text-decoration"] == "underline"
- text.LineThrough = self.Style["text-decoration"] == "linethrough"
+ text.Overlined = n.Style["text-decoration"] == "overline"
+ text.Underlined = n.Style["text-decoration"] == "underline"
+ text.LineThrough = n.Style["text-decoration"] == "linethrough"
@@ -485 +435 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- if self.Style["word-spacing"] == "" {
+ if n.Style["word-spacing"] == "" {
@@ -490,0 +441,2 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
+ // self.Text.Width = int(width)
+ self.Width = float32(width)
@@ -492 +444 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- if self.Style["height"] == "" {
+ if n.Style["height"] == "" {
@@ -496,4 +447,0 @@ func genTextNode(n *element.Node, state *map[string]element.State) element.State
- if self.Style["width"] == "" {
- self.Width = float32(width)
- }
-