function isBody(el) {
  return el.toString && el.toString() === '[object HTMLBodyElement]'
}
class Biu {
  constructor(text, options) {
    this.text = text
    this.options = options
    this.el = document.createElement('div')
    this.el.className = `biu-instance biu-${options.type}`
    this.el.style.textAlign = this.options.align

    if (this.options.pop) {
      this.el.classList.add('biu-pop')
    }

    if (!isBody(this.options.el)) {
      this.options.el.style.overflow = 'hidden'
      this.options.el.style.position = 'relative'
      this.el.style.position = 'absolute'
    }

    // initial events
    this.events = {}

    // inner element
    this.insert()

    // auto hide animation
    if (this.options.autoHide !== false) {
      this.startTimeout()
    }

    // mouse events
    this.registerEvents()
  }

  insert() {
    // close button
    this.closeButton = document.createElement('div')
    this.closeButton.className = 'biu-close'
    this.closeButton.innerHTML = this.options.closeButton
    this.el.appendChild(this.closeButton)

    // main
    const elMain = document.createElement('div')
    elMain.className = 'biu-main'
    elMain.innerHTML = this.text
    this.el.appendChild(elMain)

    this.options.el.appendChild(this.el)
    setTimeout(() => {
      this.el.classList.add('biu-shown')
    }, 200)
  }

  registerEvents() {
    if (this.options.autoHide !== false) {
      this.events.mouseover = () => {
        clearTimeout(this.timeout)
        this.timeout = null
      }
      this.events.mouseleave = () => this.startTimeout()
      this.el.addEventListener('mouseover', this.events.mouseover, false)
      this.el.addEventListener('mouseleave', this.events.mouseleave, false)
    }

    this.events.hide = () => this.hide()
    this.closeButton.addEventListener('click', this.events.hide, false)
  }

  startTimeout(timeout = this.options.timeout) {
    this.timeout = setTimeout(() => {
      this.hide()
    }, timeout)
  }

  hide() {
    if (!this.el) {
      return
    }

    if (this.options.pop) {
      this.el.style.transform = 'translateX(-50%) translateY(-110%)'
    } else {
      this.el.style.transform = 'translateY(-100%)'
    }
    setTimeout(() => {
      if (this.options.onHidden) {
        this.options.onHidden.call(this)
      }
      this.options.el.removeChild(this.el)
      this.el = null
    }, 300)
  }
}

function biu(text = '', {
  type = 'default',
  timeout = 3000,
  autoHide = true,
  closeButton = '×',
  el = document.body,
  align = 'center',
  pop = false,
  onHidden
} = {}) {
  return new Biu(text, {
    type,
    timeout,
    autoHide,
    closeButton,
    el,
    align,
    pop,
    onHidden
  })
}

export default biu

@@ -757,27 +757,25 @@
 is.startTime
-out
+r
 ()%0A    %7D%0A%0A  
@@ -1442,80 +1442,24 @@
  =%3E 
-%7B%0A        clearTimeout(this.timeout)%0A        this.timeout = null%0A      %7D
+this.stopTimer()
 %0A   
@@ -1506,19 +1506,17 @@
 tartTime
-out
+r
 ()%0A     
@@ -1796,19 +1796,17 @@
 tartTime
-out
+r
 (timeout
@@ -1845,19 +1845,17 @@
 his.time
-out
+r
  = setTi
@@ -1901,24 +1901,130 @@
 timeout)%0A  %7D
+%0A  %0A  stopTimer() %7B%0A    if (this.timer) %7B%0A      clearTimeout(this.timer)%0A      this.timer = null%0A    %7D%0A  %7D
 %0A%0A  hide() %7B
@@ -2399,24 +2399,47 @@
 s.el = null%0A
+      this.stopTimer()%0A
     %7D, 300)%0A

stop timer after element is hidden