about summary refs log tree commit diff stats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-11-09 23:20:13 +0100
committerbptato <nincsnevem662@gmail.com>2021-11-09 23:20:13 +0100
commite6f7cc72ba3343fb81c4f8196446c58eca59191e (patch)
tree8a107227a391b998ad59bba6fceac49899805c35 /src/css
parent355290ea8c9e51cf622ff1abf5f6fa626ca40565 (diff)
downloadchawan-e6f7cc72ba3343fb81c4f8196446c58eca59191e.tar.gz
It's broken but it could be worse
Diffstat (limited to 'src/css')
-rw-r--r--src/css/parser.nim15
-rw-r--r--src/css/selector.nim3
-rw-r--r--src/css/style.nim56
3 files changed, 23 insertions, 51 deletions
diff --git a/src/css/parser.nim b/src/css/parser.nim
index fac1bce8..25a0e21d 100644
--- a/src/css/parser.nim
+++ b/src/css/parser.nim
@@ -132,7 +132,7 @@ proc reconsume(state: var CSSTokenizerState) =
 func peek(state: CSSTokenizerState, i: int): Rune =
   return state.buf[state.at + i]
 
-proc has(state: var CSSTokenizerState, i: int): bool =
+proc has(state: var CSSTokenizerState, i: int = 0): bool =
   if state.at + i >= state.buf.len and not state.stream.atEnd():
     state.buf &= state.stream.readLine().toRunes() & Rune('\n')
   return state.at + i < state.buf.len
@@ -143,11 +143,6 @@ func curr(state: CSSTokenizerState): Rune =
 proc isValidEscape*(state: var CSSTokenizerState): bool =
   return state.has(1) and state.curr() == Rune('\\') and state.peek(1) != Rune('\n')
 
-proc has(state: var CSSTokenizerState): bool =
-  if state.at >= state.buf.len and not state.stream.atEnd():
-    state.buf &= state.stream.readLine().toRunes() & Rune('\n')
-  return state.at < state.buf.len
-
 proc startsWithIdentifier*(state: var CSSTokenizerState): bool =
   if not state.has():
     return false
@@ -345,16 +340,16 @@ proc consumeIdentLikeToken(state: var CSSTokenizerState): CSSToken =
   return CSSToken(tokenType: CSS_IDENT_TOKEN, value: s)
 
 proc consumeComments(state: var CSSTokenizerState) =
-  if state.has(2) and state.peek(1) == Rune('/') and state.peek(2) == Rune('*'):
+  if state.has(1) and state.curr() == Rune('/') and state.peek(1) == Rune('*'):
     discard state.consume()
     discard state.consume()
-    while state.has(2) and not (state.peek(1) == Rune('*') and state.peek(2) == Rune('/')):
+    while state.has(1) and not (state.curr() == Rune('*') and state.peek(1) == Rune('/')):
       discard state.consume()
 
-    if state.has(2):
-      discard state.consume()
     if state.has(1):
       discard state.consume()
+    if state.has():
+      discard state.consume()
 
 proc consumeToken(state: var CSSTokenizerState): CSSToken =
   state.consumeComments()
diff --git a/src/css/selector.nim b/src/css/selector.nim
index d381e618..0ec1ac27 100644
--- a/src/css/selector.nim
+++ b/src/css/selector.nim
@@ -13,6 +13,9 @@ type
     QUERY_TYPE, QUERY_CLASS, QUERY_ATTR, QUERY_DELIM, QUERY_VALUE,
     QUERY_PSEUDO, QUERY_PSELEM
 
+  PseudoElem* = enum
+    PSEUDO_NONE, PSEUDO_BEFORE, PSEUDO_AFTER
+
   SelectorParser = object
     selectors: seq[SelectorList]
     query: QueryMode
diff --git a/src/css/style.nim b/src/css/style.nim
index 6d6935d3..5f426e58 100644
--- a/src/css/style.nim
+++ b/src/css/style.nim
@@ -12,34 +12,6 @@ type
     unit*: CSSUnit
     auto*: bool
 
-  CSS2Properties* = ref object
-    rawtext*: string
-    fmttext*: seq[string]
-    x*: int
-    y*: int
-    ex*: int
-    ey*: int
-    width*: int
-    height*: int
-    hidden*: bool
-    before*: CSS2Properties
-    after*: CSS2Properties
-    margintop*: CSSLength
-    marginbottom*: CSSLength
-    marginleft*: CSSLength
-    marginright*: CSSLength
-    centered*: bool
-    display*: DisplayType
-    bold*: bool
-    fontStyle*: CSSFontStyle
-    underscore*: bool
-    islink*: bool
-    selected*: bool
-    indent*: int
-    color*: CSSColor
-    position*: CSSPosition
-    content*: seq[Rune]
-
   CSSValues* = array[low(CSSRuleType)..high(CSSRuleType), CSSComputedValue]
 
   CSSColor* = tuple[r: uint8, g: uint8, b: uint8, a: uint8]
@@ -59,6 +31,8 @@ type
       content*: seq[Rune]
     of VALUE_NONE: discard
 
+  CSSComputedValues* = array[low(CSSRuleType)..high(CSSRuleType), CSSComputedValue]
+
   CSSSpecifiedValue* = object of CSSComputedValue
     hasGlobalValue: bool
     globalValue: CSSGlobalValueType
@@ -79,7 +53,7 @@ const ValueTypes = {
 func getValueType*(rule: CSSRuleType): CSSValueType =
   return ValueTypes[rule]
 
-func cells(l: CSSLength): int =
+func cells*(l: CSSLength): int =
   case l.unit
   of UNIT_EM:
     return int(l.num)
@@ -214,18 +188,18 @@ func cssLength(d: CSSDeclaration): CSSLength =
 
   return CSSLength(num: 0, unit: UNIT_EM)
 
-func hasColor*(style: CSS2Properties): bool =
-  return style.color.r != 0 or style.color.b != 0 or style.color.g != 0 or style.color.a != 0
-
-func termColor*(style: CSS2Properties): ForegroundColor =
-  if style.color.r > 120:
-    return fgRed
-  elif style.color.b > 120:
-    return fgBlue
-  elif style.color.g > 120:
-    return fgGreen
-  else:
-    return fgWhite
+#func hasColor*(style: CSS2Properties): bool =
+#  return style.color.r != 0 or style.color.b != 0 or style.color.g != 0 or style.color.a != 0
+#
+#func termColor*(style: CSS2Properties): ForegroundColor =
+#  if style.color.r > 120:
+#    return fgRed
+#  elif style.color.b > 120:
+#    return fgBlue
+#  elif style.color.g > 120:
+#    return fgGreen
+#  else:
+#    return fgWhite
 
 func isToken(d: CSSDeclaration): bool = d.value.len > 0 and d.value[0] of CSSToken
 func getToken(d: CSSDeclaration): CSSToken = (CSSToken)d.value[0]