about summary refs log tree commit diff stats
path: root/src/css/cascade.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-29 20:26:48 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-29 23:24:34 +0200
commit83d119903270acc85110c291fe0b7a4d967a9052 (patch)
treeaa9bdc680744fb2622486b84d6d5332af5d6498e /src/css/cascade.nim
parent070e1e181f0efbd1aa4d760daa17fe2ad8e976e4 (diff)
downloadchawan-83d119903270acc85110c291fe0b7a4d967a9052.tar.gz
css: hash attribute names
Diffstat (limited to 'src/css/cascade.nim')
-rw-r--r--src/css/cascade.nim25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index a3039f15..8a8d8c44 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -1,6 +1,6 @@
 import std/algorithm
 import std/options
-import std/strutils
+import std/tables
 
 import chame/tags
 import css/cssparser
@@ -95,8 +95,27 @@ proc calcRule(tosorts: var ToSorts; styledNode: StyledNode; rule: CSSRuleDef) =
 
 func calcRules(styledNode: StyledNode; sheet: CSSStylesheet): RuleList =
   var tosorts: ToSorts
-  let elem = Element(styledNode.node)
-  for rule in sheet.genRules(elem.localName, elem.id, elem.classList.toks):
+  let element = Element(styledNode.node)
+  var rules: seq[CSSRuleDef] = @[]
+  sheet.tagTable.withValue(element.localName, v):
+    for rule in v[]:
+      rules.add(rule)
+  if element.id != CAtomNull:
+    sheet.idTable.withValue(element.id, v):
+      for rule in v[]:
+        rules.add(rule)
+  for class in element.classList.toks:
+    sheet.classTable.withValue(class, v):
+      for rule in v[]:
+        rules.add(rule)
+  for attr in element.attrs:
+    sheet.attrTable.withValue(attr.qualifiedName, v):
+      for rule in v[]:
+        rules.add(rule)
+  for rule in sheet.generalList:
+    rules.add(rule)
+  rules.sort(ruleDefCmp, order = Ascending)
+  for rule in rules:
     tosorts.calcRule(styledNode, rule)
   for i in PseudoElem:
     tosorts[i].sort((proc(x, y: (int, CSSRuleDef)): int =