<commit_before>(defvar *attribute-xlat*
  (new "class" "className"))

(defvar *attribute-xlat-rev* (make-hash-table))

(defun make-attribute-xlat ()
  (maphash #'((k v)
		        (= (aref *attribute-xlat-rev* v) k)
		        (= (aref *attribute-xlat-rev* (downcase v)) k))
	   	   *attribute-xlat*))
(make-attribute-xlat)

(defun xlat-attribute (x)
  (aref *attribute-xlat* x))

(defun make-native-element (name doc ns)
  (? (& ns (defined? doc.create-element-n-s))
     (doc.create-element-n-s ns name)
     (doc.create-element name)))

(defun *element (name &optional (attrs nil) (style nil) &key (doc document) (ns nil))
  (aprog1 (make-native-element name doc ns)
	(hash-merge ! caroshi-element.prototype)
    (!.write-attributes attrs)
	(!.set-styles style)))

(defclass (caroshi-element visible-node) ())

(defmember caroshi-element
    append-child
	attributes
	child-nodes
	children
	first-child
	set-attribute get-attribute remove-attribute
	get-elements-by-class-name
	get-elements-by-tag-name
	has-child-nodes
	inner-h-t-m-l
	style
	tag-name
	width height
	offset-width offset-height
	offset-left offset-right
	offset-top offset-bottom
	offset-parent
    owner-document
    query-selector
    query-selector-all
    _caroshi-rotation)

(defmethod caroshi-element child-array ()
  this.child-nodes)

(defmethod caroshi-element child-list ()
  (array-list child-nodes))

(defmethod caroshi-element remove-children ()
  (do-children (x this this)
	(? (element? x)
       (x.remove)
	   (x.remove-without-listeners))))

(defmethod caroshi-element remove-children-without-listeners ()
  (do-children (x this this)
    (x.remove-without-listeners)))

(defmethod caroshi-element add (child)
  (& child
     (append-child child))
  this)

(defmethod caroshi-element add-array (x)
  (assert (array? x) "add-arraxy: array expected")
  (doarray (i x this)
    (add i)))

(defmethod caroshi-element add-list (x)
  (@ (i x this)
    (add i)))

(defmethod caroshi-element add-front (child)
  (& child
	 (? first-child
        (first-child.add-before child)
	    (append-child child)))
  this)

(defmethod caroshi-element move-front ()
  (& this.next-sibling
     (parent-node.add-front this))
  this)

(defmethod caroshi-element move-back ()
  (& this.next-sibling
     (parent-node.add this))
  this)

(defmethod caroshi-element add-element (name attrs)
  (add (new *element name attrs)))

(defmethod caroshi-element add-text (text)
  (add (new *text-node text)))

; XXX last-child-BY-class
(defmethod caroshi-element last-child-of-class (cls)
  (with (elm nil
		 chlds (child-array))
	(doarray (x chlds elm)
	  (& (string== cls (x.get-class))
		 (= elm x)))))

(defmethod caroshi-element read-attribute (name)
  (declare type string name)
  (| (awhen (xlat-attribute name)
       (get-attribute !))
     (get-attribute name)))

(defmethod caroshi-element read-attributes ()
  (let attrs (make-hash-table)
    (doarray (a attributes attrs)
      (= (href attrs (| (aref *attribute-xlat-rev* a.node-name)
			  		    a.node-name))
	     a.node-value))))

(defmethod caroshi-element attributes-alist ()
  (let attrs (make-queue)
    (doarray (a attributes (queue-list attrs))
	    (enqueue attrs (. (| (aref *attribute-xlat-rev* a.node-name)
				  		     a.node-name)
			              a.node-value)))))

(defmethod caroshi-element has-attribute? (name)
  (doarray (a attributes)
	(& (string== a.node-name name)
	   (return t))))

(defmethod caroshi-element attribute-value? (name val)
  (& (has-attribute? name)
     (string== (downcase (read-attribute name))
               (downcase val))))

(defmethod caroshi-element write-attribute (name value)
  (set-attribute name value)
  (awhen (xlat-attribute name)
    (set-attribute ! value))
  value)

(defmethod caroshi-element write-attributes (attrs)
  (maphash #'((k v)
				(write-attribute k v))
           attrs)
  attrs)

(defmethod caroshi-element remove-attributes (attrs)
  (adolist attrs
    (remove-attribute !)))

(defmethod caroshi-element has-name-attribute? ()
  (has-attribute? "name"))

(defmethod caroshi-element has-name? (x)
  (member (downcase (get-name)) (@ #'downcase (ensure-list x)) :test #'string==))

(defmethod caroshi-element get-name ()
  (read-attribute "name"))

(defmethod caroshi-element set-name (x)
  (write-attribute "name" x))

(defmethod caroshi-element class? (x)
  (!? (read-attribute "class")
      (let c (+ " " ! " ")
        (adolist ((ensure-list x))
          (& (< -1 (c.index-of (+ " " ! " ")))
             (return t))))))

(defmethod caroshi-element get-class ()
  (read-attribute "class"))<commit_msg>HAS-NAME-ATTRIBUTE? has been removed.<commit_after>(defvar *attribute-xlat*
  (new "class" "className"))

(defvar *attribute-xlat-rev* (make-hash-table))

(defun make-attribute-xlat ()
  (maphash #'((k v)
		        (= (aref *attribute-xlat-rev* v) k)
		        (= (aref *attribute-xlat-rev* (downcase v)) k))
	   	   *attribute-xlat*))
(make-attribute-xlat)

(defun xlat-attribute (x)
  (aref *attribute-xlat* x))

(defun make-native-element (name doc ns)
  (? (& ns (defined? doc.create-element-n-s))
     (doc.create-element-n-s ns name)
     (doc.create-element name)))

(defun *element (name &optional (attrs nil) (style nil) &key (doc document) (ns nil))
  (aprog1 (make-native-element name doc ns)
	(hash-merge ! caroshi-element.prototype)
    (!.write-attributes attrs)
	(!.set-styles style)))

(defclass (caroshi-element visible-node) ())

(defmember caroshi-element
    append-child
	attributes
	child-nodes
	children
	first-child
	set-attribute get-attribute remove-attribute
	get-elements-by-class-name
	get-elements-by-tag-name
	has-child-nodes
	inner-h-t-m-l
	style
	tag-name
	width height
	offset-width offset-height
	offset-left offset-right
	offset-top offset-bottom
	offset-parent
    owner-document
    query-selector
    query-selector-all
    _caroshi-rotation)

(defmethod caroshi-element child-array ()
  this.child-nodes)

(defmethod caroshi-element child-list ()
  (array-list child-nodes))

(defmethod caroshi-element remove-children ()
  (do-children (x this this)
	(? (element? x)
       (x.remove)
	   (x.remove-without-listeners))))

(defmethod caroshi-element remove-children-without-listeners ()
  (do-children (x this this)
    (x.remove-without-listeners)))

(defmethod caroshi-element add (child)
  (& child
     (append-child child))
  this)

(defmethod caroshi-element add-array (x)
  (assert (array? x) "add-arraxy: array expected")
  (doarray (i x this)
    (add i)))

(defmethod caroshi-element add-list (x)
  (@ (i x this)
    (add i)))

(defmethod caroshi-element add-front (child)
  (& child
	 (? first-child
        (first-child.add-before child)
	    (append-child child)))
  this)

(defmethod caroshi-element move-front ()
  (& this.next-sibling
     (parent-node.add-front this))
  this)

(defmethod caroshi-element move-back ()
  (& this.next-sibling
     (parent-node.add this))
  this)

(defmethod caroshi-element add-element (name attrs)
  (add (new *element name attrs)))

(defmethod caroshi-element add-text (text)
  (add (new *text-node text)))

; XXX last-child-BY-class
(defmethod caroshi-element last-child-of-class (cls)
  (with (elm nil
		 chlds (child-array))
	(doarray (x chlds elm)
	  (& (string== cls (x.get-class))
		 (= elm x)))))

(defmethod caroshi-element read-attribute (name)
  (declare type string name)
  (| (awhen (xlat-attribute name)
       (get-attribute !))
     (get-attribute name)))

(defmethod caroshi-element read-attributes ()
  (let attrs (make-hash-table)
    (doarray (a attributes attrs)
      (= (href attrs (| (aref *attribute-xlat-rev* a.node-name)
			  		    a.node-name))
	     a.node-value))))

(defmethod caroshi-element attributes-alist ()
  (let attrs (make-queue)
    (doarray (a attributes (queue-list attrs))
	    (enqueue attrs (. (| (aref *attribute-xlat-rev* a.node-name)
				  		     a.node-name)
			              a.node-value)))))

(defmethod caroshi-element has-attribute? (name)
  (doarray (a attributes)
	(& (string== a.node-name name)
	   (return t))))

(defmethod caroshi-element attribute-value? (name val)
  (& (has-attribute? name)
     (string== (downcase (read-attribute name))
               (downcase val))))

(defmethod caroshi-element write-attribute (name value)
  (set-attribute name value)
  (awhen (xlat-attribute name)
    (set-attribute ! value))
  value)

(defmethod caroshi-element write-attributes (attrs)
  (maphash #'((k v)
				(write-attribute k v))
           attrs)
  attrs)

(defmethod caroshi-element remove-attributes (attrs)
  (adolist attrs
    (remove-attribute !)))

(defmethod caroshi-element has-name? (x)
  (member (downcase (get-name)) (@ #'downcase (ensure-list x)) :test #'string==))

(defmethod caroshi-element get-name ()
  (read-attribute "name"))

(defmethod caroshi-element set-name (x)
  (write-attribute "name" x))

(defmethod caroshi-element class? (x)
  (!? (read-attribute "class")
      (let c (+ " " ! " ")
        (adolist ((ensure-list x))
          (& (< -1 (c.index-of (+ " " ! " ")))
             (return t))))))

(defmethod caroshi-element get-class ()
  (read-attribute "class"))
{'fraction_non_alphanumeric': 0.15670825125848106, 'fraction_numerical': 0.0004377325454147516, 'mean_word_length': 3.3027306967984935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3131790', 'n_tokens_mistral': 3256, 'n_tokens_neox': 3206, 'n_words': 755}