<commit_before>import { createEvent/*, nextFrame*/, fireLazyload } from '../../utils'

const TRANSITION_TIME = 200

// trigger scroll event frequency.
// const scrollDam = 16

export default {
  methods: {
    // get standard index
    normalizeIndex (index) {
      const newIndex = (index + this.frameCount) % this.frameCount
      return Math.min(Math.max(newIndex, 0), this.frameCount - 1)
    },

    slideTo (index) {
      const newIndex = this.normalizeIndex(index)
      const inner = this.$refs.inner
      const step = this._cells.length <= 1 ? 0 : this.currentIndex - index
      this.innerOffset += Math.sign(step) * this.wrapperWidth
      if (inner) {
        // const match = (inner.style.transform || inner.style.webkitTransform).match(/(\d+)px/)
        // const currentOffset = parseFloat(match[1])
        // TODO: will-change | set styles together
        inner.style.webkitTransition = `-webkit-transform .2s ease-in-out`
        inner.style.transition = `transform .2s ease-in-out`
        inner.style.webkitTransform = `translate3d(${this.innerOffset}px, 0, 0)`
        inner.style.transform = `translate3d(${this.innerOffset}px, 0, 0)`
        setTimeout(() => {
          inner.style.webkitTransition = ''
          inner.style.transition = ''
        }, TRANSITION_TIME)
      }
      // TODO: emit scroll event.
      // nextFrame()

      if (newIndex !== this.currentIndex) {
        this.currentIndex = newIndex
        // replace $el with { attr, style } is a legacy usage. Is it necessary to
        // do this ? Or just tell devers to use inline functions to access attrs ?
        this.$emit('change', createEvent(this.$el, 'change', {
          index: this.currentIndex
        }))
        setTimeout(() => { this.reorder() }, TRANSITION_TIME)
      }
    },

    reorder () {
      this.$nextTick(() => {
        if (this._cells.length <= 1) {
          return
        }

        const prevIndex = this.normalizeIndex(this.currentIndex - 1)
        const nextIndex = this.normalizeIndex(this.currentIndex + 1)
        let prevElm = this._cells[prevIndex].elm
        const nextElm = this._cells[nextIndex].elm
        const currentElm = this._cells[this.currentIndex].elm

        const removeClone = (clone) => {
          if (clone) {
            setTimeout(() => {
              clone.parentElement.removeChild(clone)
            }, this.interval > TRANSITION_TIME ? this.interval : TRANSITION_TIME)
          }
        }

        // clone prevCell if there are only tow slides.
        if (this._cells.length === 2) {
          this._clonePrev = prevElm.cloneNode(true)
          this._clonePrev.classList.add('weex-slide-clone-prev')
          prevElm.parentElement.insertBefore(this._clonePrev, currentElm)
          removeClone(this._clonePrev)
          if (!this._prevFired) {
            fireLazyload(this._clonePrev, true)<commit_msg>* [html5] fix 2 slides for slider.<commit_after>import { createEvent/*, nextFrame*/, fireLazyload } from '../../utils'

const TRANSITION_TIME = 200

// trigger scroll event frequency.
// const scrollDam = 16

export default {
  methods: {
    // get standard index
    normalizeIndex (index) {
      const newIndex = (index + this.frameCount) % this.frameCount
      return Math.min(Math.max(newIndex, 0), this.frameCount - 1)
    },

    slideTo (index) {
      const newIndex = this.normalizeIndex(index)
      const inner = this.$refs.inner
      const step = this._cells.length <= 1 ? 0 : this.currentIndex - index
      this.innerOffset += Math.sign(step) * this.wrapperWidth
      if (inner) {
        // const match = (inner.style.transform || inner.style.webkitTransform).match(/(\d+)px/)
        // const currentOffset = parseFloat(match[1])
        // TODO: will-change | set styles together
        inner.style.webkitTransition = `-webkit-transform .2s ease-in-out`
        inner.style.transition = `transform .2s ease-in-out`
        inner.style.webkitTransform = `translate3d(${this.innerOffset}px, 0, 0)`
        inner.style.transform = `translate3d(${this.innerOffset}px, 0, 0)`
        setTimeout(() => {
          inner.style.webkitTransition = ''
          inner.style.transition = ''
        }, TRANSITION_TIME)
      }
      // TODO: emit scroll event.
      // nextFrame()

      if (newIndex !== this.currentIndex) {
        this.currentIndex = newIndex
        // replace $el with { attr, style } is a legacy usage. Is it necessary to
        // do this ? Or just tell devers to use inline functions to access attrs ?
        this.$emit('change', createEvent(this.$el, 'change', {
          index: this.currentIndex
        }))
        setTimeout(() => { this.reorder() }, TRANSITION_TIME)
      }
    },

    reorder () {
      const removeClone = (clone, prevElm) => {
        // switch current page.
        const curTransform = `translate3d(${-this.innerOffset}px, 0, 0)`
        prevElm.style.transform = curTransform
        prevElm.style.webkitTransform = curTransform
        // remove clone node.
        clone && clone.parentElement.removeChild(clone)
      }

      this.$nextTick(() => {
        if (this._cells.length <= 1) {
          return
        }

        const lastPrev = this._prevElm
        const prevIndex = this.normalizeIndex(this.currentIndex - 1)
        const nextIndex = this.normalizeIndex(this.currentIndex + 1)
        let prevElm = this._prevElm = this._cells[prevIndex].elm
        const nextElm = this._cells[nextIndex].elm
        const currentElm = this._cells[this.currentIndex].elm

        // clone prevCell if there are only tow slides.
        if (this._cells.length === 2) {
          this._clonePrev && removeClone(this._clonePrev, lastPrev)
          this._clonePrev = prevElm.cloneNode(true)
          this._clonePrev.classList.add('weex-slide-clone-prev')
          prevElm.parentElement.insertBefore(this._clonePrev, currentElm)
          if (!this._prevFired) {
            fireLazyload(this._clonePrev, true)
{'fraction_non_alphanumeric': 0.12491616364855801, 'fraction_numerical': 0.008215962441314555, 'mean_word_length': 2.3249721293199554, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '4895338', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1718, 'n_words': 391}