             [goog.dom.classes :as gclasses]
             [goog.style :as gstyle]))
 
-;; From Weavejester's Hiccup.
-(def ^{:doc "Regular expression that parses a CSS-style id and class from a tag name."}
-  re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?")
-
+;; Regular expression that parses a CSS-style id and class from a tag name. From Weavejester's Hiccup.
+(def re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?")
+
+;;Namespace URIs
 (def xmlns {:xhtml "http://www.w3.org/1999/xhtml"
             :svg "http://www.w3.org/2000/svg"})
 
+;;Common SVG tags; DOM node creation fn checks this set to infer element namespace (so users don't have to write things like [:svg:rect]).
 (def svg-tags #{:svg :g :rect :circle :clipPath :path :line :polygon :polyline :text :textPath})
 
-(defn dom-element? [x]
+
+(defn dom-element?
+  "Live DOM elements have JavaScript nodeName defined."
+  [x]
   (not (undefined? (.-nodeName x))))
 
-(defn node-type [node]
+(defn node-type
+  "Check node type; used as a dispatch fn."
+  [node]
   (cond
    (vector? node)      :hiccup   ;;Hiccup vector
    (map? node)         :chiccup  ;;Hiccup map representation

                                                                  {:id (or id nil)
                                                                   :class (if class (string/replace class #"\." " "))}))
                                   map-attrs        (first content)]
                               
                               (let [[attr raw-children] (if (map? map-attrs)
                                                                [(merge tag-attrs map-attrs) (next content)]
                                                                [tag-attrs content])
                                     ;;Explode children seqs in place
                                     children (mapcat #(if (and (not (vector? %)) (seq? %))
                                                         (map canonicalize %)

(defn create-elem [nsp tag]
  (.createElementNS js/document nsp (name tag)))

(defn build-dom-elem
  "Build live DOM element from hiccup vector, hiccup map, or string."
  [el]
  (match [el]
         [(s :when string?)] (gdom/createTextNode s)
         [(v :when vector?)] (recur (canonicalize v))
