<commit_before>/**
 * CSSify animations
 * @param {Item} item
 * @param {Array} animations
 * @param {boolean} static
 * @constructor
 */
function CSS(item, animations, static) {
  !document.styleSheets.length && this.createStyleSheet()
  this.stylesheet = document.styleSheets[0]

  this.item = item
  this.runner = item.runner
  this.animations = animations

  this.total = this.runner.duration

  !static && this.style()
}

/**
 * Creates new stylesheet and adds it to HEAD
 */
CSS.prototype.createStyleSheet = function () {
  var style = document.createElement('style')
  document.getElementsByTagName('head')[0].appendChild(style)
}

/**
 * Pauses CSS animation
 */
CSS.prototype.pause = function () {
  this.item.dom.style[_animationProperty + 'PlayState'] = 'paused'
  return this
}

/**
 * Resumes CSS animation
 */
CSS.prototype.resume = function () {
  this.item.dom.style[_animationProperty + 'PlayState'] = 'running'
  return this
}

/**
 * Stops CSS animation
 * parses current transformation matrix
 * extracts values and sets item state
 */
CSS.prototype.stop = function () {
  var computed = getComputedStyle(this.item.dom),
      transform = computed[_transformProperty],
      opacity = computed.opacity,
      style = this.item.dom.style

  style[_animationProperty] = ''
  style[_transitionProperty] = ''

  this.item.state = Matrix.decompose(Matrix.parse(transform))
  this.item.state.opacity = opacity
  this.item.style()

  return this
}


CSS.prototype.handle = function (event) {
  var onEnd = function end() {
        this.stop()
        this.item.dom.removeEventListener(vendor + event, onEnd, false)
      }.bind(this)
  this.item.dom.addEventListener(vendor + event, onEnd, false)
}

/**
 * Applies animations and sets item style
 */
CSS.prototype.style = function () {
  var animation = 'a' + Date.now() + 'r' + Math.floor(Math.random() * 1000)

  if (this.runner.animations[0] instanceof Animation &&
    this.runner.animations.length == 1) { // transition
    var a = this.runner.animations[0]
    a.init()
    this.item.dom.style[_transitionProperty] = a.duration + 'ms' + ' ' + easings.css[a.easeName] + ' ' + a.delay + 'ms'
    a.transform(1)
    this.handle('TransitionEnd')
    this.item.style()
  } else { // animation
    this.stylesheet.insertRule(this.keyframes(animation), 0)
    this.handle('AnimationEnd')
    this.item.dom.style[_animationProperty] = animation + ' ' + this.total + 'ms' + ' ' +
	(this.runner._infinite ? 'infinite' : '') + ' ' + 'forwards'
  }

  this.runner.animations = []
}

/**
 * Generates @keyframes based on animations
 * @param {string} name Animation name
 * @return {string}
 */
CSS.prototype.keyframes = function (name) {
  var time = 0,
      rule = ['@' + _vendor + 'keyframes ' + name + '{']

  for (var i = 0; i < this.runner.animations.length; ++i) {
    var a = this.runner.animations[i],
	aNext = this.runner.animations[i+1]

    a.init()

    if (a instanceof Animation) { // Single
      i === 0 && rule.push(this.frame(0, easings.css[a.easeName]))

      a.delay && rule.push(this.frame(time += a.delay))

      a.transform(1)

      rule.push(this.frame(time += a.duration, aNext && easings.css[aNext.easeName]))<commit_msg>fix indentation<commit_after>/**
 * CSSify animations
 * @param {Item} item
 * @param {Array} animations
 * @param {boolean} static
 * @constructor
 */
function CSS(item, animations, static) {
  !document.styleSheets.length && this.createStyleSheet()
  this.stylesheet = document.styleSheets[0]

  this.item = item
  this.runner = item.runner
  this.animations = animations

  this.total = this.runner.duration

  !static && this.style()
}

/**
 * Creates new stylesheet and adds it to HEAD
 */
CSS.prototype.createStyleSheet = function () {
  var style = document.createElement('style')
  document.getElementsByTagName('head')[0].appendChild(style)
}

/**
 * Pauses CSS animation
 */
CSS.prototype.pause = function () {
  this.item.dom.style[_animationProperty + 'PlayState'] = 'paused'
  return this
}

/**
 * Resumes CSS animation
 */
CSS.prototype.resume = function () {
  this.item.dom.style[_animationProperty + 'PlayState'] = 'running'
  return this
}

/**
 * Stops CSS animation
 * parses current transformation matrix
 * extracts values and sets item state
 */
CSS.prototype.stop = function () {
  var computed = getComputedStyle(this.item.dom),
      transform = computed[_transformProperty],
      opacity = computed.opacity,
      style = this.item.dom.style

  style[_animationProperty] = ''
  style[_transitionProperty] = ''

  this.item.state = Matrix.decompose(Matrix.parse(transform))
  this.item.state.opacity = opacity
  this.item.style()

  return this
}


CSS.prototype.handle = function (event) {
  var onEnd = function end() {
        this.stop()
        this.item.dom.removeEventListener(vendor + event, onEnd, false)
      }.bind(this)
  this.item.dom.addEventListener(vendor + event, onEnd, false)
}

/**
 * Applies animations and sets item style
 */
CSS.prototype.style = function () {
  var animation = 'a' + Date.now() + 'r' + Math.floor(Math.random() * 1000)

  if (this.runner.animations[0] instanceof Animation &&
    this.runner.animations.length == 1) { // transition
    var a = this.runner.animations[0]
    a.init()
    this.item.dom.style[_transitionProperty] = a.duration + 'ms' + ' ' + easings.css[a.easeName] + ' ' + a.delay + 'ms'
    a.transform(1)
    this.handle('TransitionEnd')
    this.item.style()
  } else { // animation
    this.stylesheet.insertRule(this.keyframes(animation), 0)
    this.handle('AnimationEnd')
    this.item.dom.style[_animationProperty] = animation + ' ' + this.total + 'ms' + ' ' +
	(this.runner._infinite ? 'infinite' : '') + ' ' + 'forwards'
  }

  this.runner.animations = []
}

/**
 * Generates @keyframes based on animations
 * @param {string} name Animation name
 * @return {string}
 */
CSS.prototype.keyframes = function (name) {
  var time = 0,
      rule = ['@' + _vendor + 'keyframes ' + name + '{']

  for (var i = 0; i < this.runner.animations.length; ++i) {
    var a = this.runner.animations[i],
        aNext = this.runner.animations[i+1]

    a.init()

    if (a instanceof Animation) { // Single
      i === 0 && rule.push(this.frame(0, easings.css[a.easeName]))

      a.delay && rule.push(this.frame(time += a.delay))

      a.transform(1)

      rule.push(this.frame(time += a.duration, aNext && easings.css[aNext.easeName]))
{'fraction_non_alphanumeric': 0.15439688715953306, 'fraction_numerical': 0.005291828793774319, 'mean_word_length': 3.4225739848589125, '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': '4753750', 'n_tokens_mistral': 2113, 'n_tokens_neox': 2040, 'n_words': 430}