<commit_before>import Tween from './Tween';
import { now, nextId } from './core';

class Timeline extends Tween {
  constructor(params) {
    super();
    this._totalDuration = 0;
    this._startTime = now();
    this._tweens = {};
    this._elapsed = 0;
    this._id = nextId();
    this._labels = {};
    this._defaultParams = params;

    return this;
  }
  setLabel(name, value) {
    this._labels[name] = this.parsePosition(0, value, 0);
    return this;
  }
  parsePosition(startTime, input, total) {
    let position = startTime + total;

    if (typeof input === "string") {

      for (let label in this._labels) {

        if (input.indexOf(label) === 0) {

          let inp = input.split(label)[1];

          if (inp.length === 0 || (inp[0] === '+' || inp[0] === '-')) {

            position = this._labels[label] + startTime;
            input = input.replace(label, '');

          }

        }

      }

      if (input.indexOf('+') === 0 || input.indexOf('-') === 0) {

        position += parseFloat(input);

      }

    } else if (typeof input === "number") {

      position += input;

    }

    return position;
  }
  map(fn) {
    for (let tween in this._tweens) {
      fn(this._tweens[tween]);
    }
    return this;
  }
  add(tween, position) {

	if (typeof tween === "object" && !(tween instanceof Tween)) {

		tween = new Tween(tween.from, tweens)

	}

    let {
      _defaultParams,
      _totalDuration
    } = this;

    if (_defaultParams) {
      for (let method in _defaultParams) {
        tween[method](_defaultParams[method]);
      }
    }

    tween._startTime = this.parsePosition(0, position, _totalDuration);
	tween._startTime += now();
    this._totalDuration = Math.max(_totalDuration, tween._duration + tween._startTime);
    this._tweens[tween.id] = tween;
    return this;
  }
  easing(easing) {
    return this.map(tween => tween.easing(easing));
  }
  interpolation(interpolation) {
    return this.map(tween => tween.interpolation(interpolation));
  }
  update(time) {
    let {
      _tweens,
      _totalDuration,
      _repeatDelayTime,
      _reverseDelayTime,
      _startTime,
      _reversed,
      _yoyo,
      _repeat
    } = this;

    if (time < _startTime) {

      return true;

    }

    let elapsed = Math.min(1, Math.max(0, (time - _startTime) / _totalDuration));
    elapsed = _reversed ? 1 - elapsed : elapsed;
    this._elapsed = elapsed;

    let timing = time - _startTime;
    timing = _reversed ? _totalDuration - timing : timing;

    for (let tween in _tweens) {
      if (_tweens[tween].update(timing)) {
        continue;
      } else {
        delete this._tweens[tween];
      }
    }

    this.emit('update', elapsed);

    if (elapsed === 1 || (_reversed && elapsed === 0)) {

      if (_repeat) {

        if (isFinite(_repeat)) {
          this._repeat--;
        }

        // Reassign starting values, restart by making startTime = now
        this.emit(_reversed ? 'reverse' : 'repeat');

        if (_yoyo) {
          this._reversed = !_reversed;
        }

        if (!_reversed && _repeatDelayTime) {
          this._startTime += _totalDuration + _repeatDelayTime;<commit_msg>fix(Timeline#repeat): fix Timeline repeat and other tweens-list related issue<commit_after>import Tween from './Tween';
import { now, nextId } from './core';

class Timeline extends Tween {
  constructor(params) {
    super();
    this._totalDuration = 0;
    this._startTime = now();
    this._tweens = {};
    this._elapsed = 0;
    this._id = nextId();
    this._labels = {};
    this._defaultParams = params;

    return this;
  }
  setLabel(name, value) {
    this._labels[name] = this.parsePosition(0, value, 0);
    return this;
  }
  parsePosition(startTime, input, total) {
    let position = startTime + total;

    if (typeof input === "string") {

      for (let label in this._labels) {

        if (input.indexOf(label) === 0) {

          let inp = input.split(label)[1];

          if (inp.length === 0 || (inp[0] === '+' || inp[0] === '-')) {

            position = this._labels[label] + startTime;
            input = input.replace(label, '');

          }

        }

      }

      if (input.indexOf('+') === 0 || input.indexOf('-') === 0) {

        position += parseFloat(input);

      }

    } else if (typeof input === "number") {

      position += input;

    }

    return position;
  }
  map(fn) {
    for (let tween in this._tweens) {
      fn(this._tweens[tween]);
    }
    return this;
  }
  add(tween, position) {

	if (typeof tween === "object" && !(tween instanceof Tween)) {

		tween = new Tween(tween.from, tweens)

	}

    let {
      _defaultParams,
      _totalDuration
    } = this;

    if (_defaultParams) {
      for (let method in _defaultParams) {
        tween[method](_defaultParams[method]);
      }
    }

    tween._startTime = this.parsePosition(0, position, _totalDuration);
	tween._startTime += now();
    this._totalDuration = Math.max(_totalDuration, tween._duration + tween._startTime);
    this._tweens[tween.id] = tween;
    return this;
  }
  restart () {
	this._startTime += now();

	add(this);

	return this.emit('restart');
  }
  easing(easing) {
    return this.map(tween => tween.easing(easing));
  }
  interpolation(interpolation) {
    return this.map(tween => tween.interpolation(interpolation));
  }
  update(time) {
    let {
      _tweens,
      _totalDuration,
      _repeatDelayTime,
      _reverseDelayTime,
      _startTime,
      _reversed,
      _yoyo,
      _repeat
    } = this;

    if (time < _startTime) {

      return true;

    }

    let elapsed = Math.min(1, Math.max(0, (time - _startTime) / _totalDuration));
    elapsed = _reversed ? 1 - elapsed : elapsed;
    this._elapsed = elapsed;

    let timing = time - _startTime;
    let _timing = _reversed ? _totalDuration - timing : timing;

    for (let tween in _tweens) {
      if (_tweens[tween].update(_timing)) {
        continue;
      }
    }

    this.emit('update', elapsed, timing);

    if (elapsed === 1 || (_reversed && elapsed === 0)) {

      if (_repeat) {

        if (isFinite(_repeat)) {
          this._repeat--;
        }

        // Reassign starting values, restart by making startTime = now
        this.emit(_reversed ? 'reverse' : 'repeat');

        if (_yoyo) {
          this._reversed = !_reversed;
        }

        if (!_reversed && _repeatDelayTime) {
          this._startTime += _totalDuration + _repeatDelayTime;
{'fraction_non_alphanumeric': 0.14259173246632606, 'fraction_numerical': 0.005263972751199876, 'mean_word_length': 2.287531806615776, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2090048', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2090, 'n_words': 462}