Diff
diff --git a/cstyle/plugins/position/main.go b/cstyle/plugins/position/main.go
index 3770baf..744759f 100644
--- a/cstyle/plugins/position/main.go
+++ b/cstyle/plugins/position/main.go
@@ -15,7 +15,4 @@ func Init() cstyle.Plugin {
- Handler: func(n *element.Node, state *map[string]element.State) {
- s := *state
- self := s[n.Properties.Id]
- parent := s[n.Parent.Properties.Id]
-
- width, height := self.Width, self.Height
- x, y := self.X, self.Y
+ Handler: func(n *element.Node) {
+ styleMap := n.Style
+ width, height := n.Properties.Computed["width"], n.Properties.Computed["height"]
+ x, y := n.Properties.X, n.Properties.Y
@@ -27,6 +24,5 @@ func Init() cstyle.Plugin {
- if n.Style["position"] == "absolute" {
- bas := utils.GetPositionOffsetNode(n)
- base := s[bas.Properties.Id]
- if n.Style["top"] != "" {
- v, _ := utils.ConvertToPixels(n.Style["top"], self.EM, parent.Width)
- y = v + base.Y
+ if styleMap["position"] == "absolute" {
+ base := utils.GetPositionOffsetNode(n)
+ if styleMap["top"] != "" {
+ v, _ := utils.ConvertToPixels(styleMap["top"], float32(n.Properties.EM), n.Parent.Properties.Computed["width"])
+ y = v + base.Properties.Y
@@ -35,3 +31,3 @@ func Init() cstyle.Plugin {
- if n.Style["left"] != "" {
- v, _ := utils.ConvertToPixels(n.Style["left"], self.EM, parent.Width)
- x = v + base.X
+ if styleMap["left"] != "" {
+ v, _ := utils.ConvertToPixels(styleMap["left"], float32(n.Properties.EM), n.Parent.Properties.Computed["width"])
+ x = v + base.Properties.X
@@ -40,3 +36,3 @@ func Init() cstyle.Plugin {
- if n.Style["right"] != "" {
- v, _ := utils.ConvertToPixels(n.Style["right"], self.EM, parent.Width)
- x = (base.Width - width) - v
+ if styleMap["right"] != "" {
+ v, _ := utils.ConvertToPixels(styleMap["right"], float32(n.Properties.EM), n.Parent.Properties.Computed["width"])
+ x = (base.Properties.Computed["width"] - width) - v
@@ -45,3 +41,3 @@ func Init() cstyle.Plugin {
- if n.Style["bottom"] != "" {
- v, _ := utils.ConvertToPixels(n.Style["bottom"], self.EM, parent.Width)
- y = (base.Height - height) - v
+ if styleMap["bottom"] != "" {
+ v, _ := utils.ConvertToPixels(styleMap["bottom"], float32(n.Properties.EM), n.Parent.Properties.Computed["width"])
+ y = (base.Properties.Computed["height"] - height) - v
@@ -54,5 +50,4 @@ func Init() cstyle.Plugin {
- sib := n.Parent.Children[i-1]
- sibling := s[sib.Properties.Id]
- if n.Style["display"] == "inline" {
- if sib.Style["display"] == "inline" {
- y = sibling.Y
+ sibling := n.Parent.Children[i-1]
+ if styleMap["display"] == "inline" {
+ if sibling.Style["display"] == "inline" {
+ y = sibling.Properties.Y
@@ -60 +55 @@ func Init() cstyle.Plugin {
- y = sibling.Y + sibling.Height
+ y = sibling.Properties.Y + sibling.Properties.Computed["height"]
@@ -63 +58 @@ func Init() cstyle.Plugin {
- y = sibling.Y + sibling.Height
+ y = sibling.Properties.Y + sibling.Properties.Computed["height"]
@@ -67,5 +62,4 @@ func Init() cstyle.Plugin {
- } else if n.Style["display"] != "inline" {
- mc := utils.GetMP(v, "margin")
- pc := utils.GetMP(v, "padding")
- vState := s[v.Properties.Id]
- y += mc.Top + mc.Bottom + pc.Top + pc.Bottom + vState.Height
+ } else if styleMap["display"] != "inline" {
+ mc := utils.GetMP(*n, "margin")
+ p := utils.GetMP(*n, "padding")
+ y += mc.Top + mc.Bottom + p.Top + p.Bottom + v.Properties.Computed["height"]
@@ -93,4 +87,4 @@ func Init() cstyle.Plugin {
- self.X = x
- self.Y = y
- self.Width = width
- self.Height = height
+ n.Properties.X = x
+ n.Properties.Y = y
+ n.Properties.Computed["width"] = width
+ n.Properties.Computed["height"] = height