<commit_before>'use strict'
var Event = require('vigour-js/lib/event')
var Property = require('../property')
var Element = require('../element')
var test = /\$vp/
var cnt = 0

function render (node, event, player) {
  let exec = this.exec
  console.log('exec?', this.key, node._ready)
  if (exec) {
    // node fix
    if (node._ready) {// || player.ready.val === true) {
      exec.apply(this, arguments)
    }
  }
}

var VideoProperty = new Property({
  // on: {
  //   data () {}
  // },
  inject: [
    require('vigour-js/lib/operator/type'),
    require('vigour-js/lib/observable/is')
  ],
  define: {
    render
  },
  properties: {
    exec (val) {
      this.define({
        exec: val
      })
    }
  },
  ChildConstructor: 'Constructor'
}).Constructor

var Player = new Element({
  properties: {
    options: true,
    _interval: true,
    _timeouts: {
      val: {}
    },
    ready: new Property({
      on: {
        data () { }
      },
      render (node, event, player) {
        var val = this.val
        node._ready = val === true || false
        if (val === true) {
          player.each(function (prop, key) {
          }, function (prop, key) {
            if (prop && prop.exec && key !== 'ready') {
              prop.exec(node, event, player)
            }
          })
        }
      }
    })
  },
  ChildConstructor: VideoProperty,
  define: {
    isProgress (event) {
      return test.test(event.stamp)
    },
    toggle () {
      this.play.origin.set(!this.play.val)
    },
    getNodeDelete (block, blocknode, hashed) {
      for (var id in this._timeouts) {
        clearTimeout(this._timeouts[id])
        this._timeouts[id] = null
      }
      if (this._interval) {
        clearInterval(this._interval)
        this._interval = null
      }
      this.dispose && this.dispose()
      this.ready.clearContextUp()
      this.ready.val = false

      Element.prototype.getNodeDelete.apply(this, arguments)
    },
    timeout (id, fn, time) {
      if (typeof id === 'function') {
        time = fn
        fn = id
      }
      if (this._timeouts[id]) {
        clearTimeout(this._timeouts[id])
        this._timeouts[id] = null
      }
      let player = this
      let store = player.storeContext()
      this._timeouts[id] = setTimeout(function () {
        player.applyContext(store)
        fn(player)
        // player.clearContextUp()
      }, time)
    }
  },
  // ready: false,
  time: {
    on: {
      data () {
        // console.log('TIME???', this.val)
      }
    }
  },
  // src: {
  //   // $type: 'string'
  // },
  play: {
    $type: 'boolean',
    exec (node, e, player) {
      if (this.val) {
        if (!player._interval) {
          let store = player.storeContext()
          player._interval = setInterval(function () {
            player.applyContext(store)
            let stamp = '$vp' + (cnt++)
            let event = new Event(
              'data',
              stamp
            )
            let time = player.getTime()
            // let buffer = player.getBuffer()
            player.time.origin.set(time, event)//, event)
            event.trigger()
            player.clearContextUp()
            // player.buffer.origin.set(buffer, event)
          }, 500)
        }
      } else {
        if (player._interval) {
          clearInterval(player._interval)
          player._interval = null
        }
      }
    }
  },
  duration: {
    $type: 'number'
  },
  volume: {
    $type: { range: [ 0, 1 ] },
    on: {
      data () {}
    }
  },
  mute: {
    $type: 'boolean'
  },
  fullscreen: {
    $type: 'boolean'
  },
  buffer: {
    $type: { range: [ 0, 1 ] }
  },
  ad: {
    src: {
      $type: 'string'
    },
    play: {<commit_msg>player fixes<commit_after>'use strict'
var Event = require('vigour-js/lib/event')
var Property = require('../property')
var Element = require('../element')
var test = /\$vp/
var cnt = 0

function render (node, event, player) {
  let exec = this.exec
  if (exec) {
    // node fix
    if (player.ready.val === true) {// || player.ready.val === true) {
      exec.apply(this, arguments)
    }
  }
}

var VideoProperty = new Property({
  inject: [
    require('vigour-js/lib/operator/type'),
    require('vigour-js/lib/observable/is')
  ],
  define: {
    render,
    set (val, event) {
      let type = typeof val
      if (type === 'boolean' || type === 'number' || type === 'string') {
        if (val !== this._input) {
          console.log(this.key, ':', val)
          this._input = val
          if (event === void 0) {
            this._on.data.execInternal(this, event = new Event('data'))
            event.trigger()
          } else {
            this._on.data.execInternal(this, event)
          }
        }
      } else {
        Property.prototype.set.apply(this, arguments)
      }
    }
  },
  properties: {
    exec (val) {
      this.define({
        exec: val
      })
    }
  },
  ChildConstructor: 'Constructor'
}).Constructor

var Player = new Element({
  properties: {
    options: true,
    _interval: true,
    _timeouts: {
      val: {}
    }
  },
  ChildConstructor: VideoProperty,
  define: {
    isProgress (event) {
      return test.test(event.stamp)
    },
    toggle () {
      this.play.origin.set(!this.play.val)
    },
    getNodeDelete (block, blocknode, hashed) {
      for (var id in this._timeouts) {
        clearTimeout(this._timeouts[id])
        this._timeouts[id] = null
      }
      if (this._interval) {
        clearInterval(this._interval)
        this._interval = null
      }
      this.dispose()

      // clean up all values
      // here

      Element.prototype.getNodeDelete.apply(this, arguments)
    },
    timeout (id, fn, time) {
      if (typeof id === 'function') {
        time = fn
        fn = id
      }
      if (this._timeouts[id]) {
        clearTimeout(this._timeouts[id])
        this._timeouts[id] = null
      }
      let player = this
      let store = player.storeContext()
      this._timeouts[id] = setTimeout(function () {
        player.applyContext(store)
        fn(player)
      }, time)
    }
  },
  time: {},
  ready: {
    val: false,
    render (node, event, player) {
      var val = this.val
      console.log('ready:', val)
      if (val === true) {
        player.each(function (prop, key) {
        }, function (prop, key) {
          if (prop && prop.exec && key !== 'ready') {
            prop.exec(node, event, player)
          }
        })
      }
    }
  },
  play: {
    exec (node, e, player) {
      if (this.val) {
        if (!player._interval) {
          let store = player.storeContext()
          player._interval = setInterval(function () {
            player.applyContext(store)
            let stamp = '$vp' + (cnt++)
            let event = new Event(
              'data',
              stamp
            )
            let time = player.getTime()
            if (time) {
              console.log('set time:', time)
              player.time.origin.set(time, event)//, event)
              event.trigger()
              player.clearContextUp()
            }
            // let buffer = player.getBuffer()
            // player.buffer.origin.set(buffer, event)
          }, 500)
        }
      } else {
        if (player._interval) {
          clearInterval(player._interval)
          player._interval = null
        }
      }
    }
  },
  duration: 0,
  volume: {
    $type: { range: [ 0, 1 ] },
    val: 1
  },
  mute: {
    $type: 'boolean',
    val: false
  },
  fullscreen: {
    $type: 'boolean',
    val: false
  },
  buffer: {
    $type: { range: [ 0, 1 ] },
    val: 0
  },
  ad: {
    src: {
      $type: 'string'
    },
    play: {
{'fraction_non_alphanumeric': 0.1517601043024772, 'fraction_numerical': 0.002607561929595828, 'mean_word_length': 1.6653926337734537, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7015571', 'n_tokens_mistral': 2450, 'n_tokens_neox': 2429, 'n_words': 522}