<commit_before>
{Event} = require './event'


class Element

  constructor: (nodeType, args...) ->
    @_ = node = document.createElement nodeType
    for arg in args
      if (typeof arg) == 'string'
        node.className = arg
      
      else if arg instanceof Array
        for kid in arg
          if (typeof kid) == 'string'
            node.appendChild document.createTextNode kid
          else
            node.appendChild kid._
      
      else
        for own k of arg
          node[k] = "" + arg[k]
  
  appendChildren: (arr) ->
    for x in arr
      @appendChild x
  
  appendChild: (x) ->
    @_.appendChild x._
  
  removeChildren: () ->
    x = @_.lastChild
    while x
      @_.removeChild x
      x = @_.lastChild
  
  setChildren: (arr) ->
    @removeChildren()
    for x in arr
      @appendChild x
  
  setChild: (x) ->
    @setChildren [x]
  
  prependChild: (x) ->
    if @_.childNodes.length == 0
      @_.appendChild x._
    else
    @_.insertBefore x._, @_.firstChild
  
  insertBefore: (kid, existingKid) ->
    @_.insertBefore kid._, existingKid._
  
  appendToBody: () ->
    document.body.appendChild @_
  
  appendToHead: () ->
    document.getElementsByTagName("head")[0].appendChild @_
  
  appendTo: (x) ->
    x._.appendChild @_
  
  prependTo: (x) ->
    x.prependChild @
  
  remove: () ->
    @_.parentNode.removeChild @_
  
  setTextChild: (text) ->
    @removeChildren()
    @_.appendChild document.createTextNode text
  
  setOpacity: (fraction) ->
    percent = Math.round(100 * fraction)
    @setStyles {
      opacity: fraction
      filter: "alpha(opacity=#{percent})"
      '-ms-filter': "progid:DXImageTransform.Microsoft.Alpha(opacity=#{percent})"
    }
  
  setStyles: (d) ->
    for own k, v of d
      @._.style[k] = v
  
  setPos: (r) ->
    @setStyles {<commit_msg>Element#remove check if the element has parent. (Fixes #5)<commit_after>
{Event} = require './event'


class Element

  constructor: (nodeType, args...) ->
    @_ = node = document.createElement nodeType
    for arg in args
      if (typeof arg) == 'string'
        node.className = arg
      
      else if arg instanceof Array
        for kid in arg
          if (typeof kid) == 'string'
            node.appendChild document.createTextNode kid
          else
            node.appendChild kid._
      
      else
        for own k of arg
          node[k] = "" + arg[k]
  
  appendChildren: (arr) ->
    for x in arr
      @appendChild x
  
  appendChild: (x) ->
    @_.appendChild x._
  
  removeChildren: () ->
    x = @_.lastChild
    while x
      @_.removeChild x
      x = @_.lastChild
  
  setChildren: (arr) ->
    @removeChildren()
    for x in arr
      @appendChild x
  
  setChild: (x) ->
    @setChildren [x]
  
  prependChild: (x) ->
    if @_.childNodes.length == 0
      @_.appendChild x._
    else
    @_.insertBefore x._, @_.firstChild
  
  insertBefore: (kid, existingKid) ->
    @_.insertBefore kid._, existingKid._
  
  appendToBody: () ->
    document.body.appendChild @_
  
  appendToHead: () ->
    document.getElementsByTagName("head")[0].appendChild @_
  
  appendTo: (x) ->
    x._.appendChild @_
  
  prependTo: (x) ->
    x.prependChild @
  
  remove: () ->
    @_.parentNode?.removeChild @_
  
  setTextChild: (text) ->
    @removeChildren()
    @_.appendChild document.createTextNode text
  
  setOpacity: (fraction) ->
    percent = Math.round(100 * fraction)
    @setStyles {
      opacity: fraction
      filter: "alpha(opacity=#{percent})"
      '-ms-filter': "progid:DXImageTransform.Microsoft.Alpha(opacity=#{percent})"
    }
  
  setStyles: (d) ->
    for own k, v of d
      @._.style[k] = v
  
  setPos: (r) ->
    @setStyles {
{'fraction_non_alphanumeric': 0.1305525460455038, 'fraction_numerical': 0.002979414951245937, 'mean_word_length': 2.0672757475083055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '5172980', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1206, 'n_words': 294}