<commit_before>//deps includes.js

// HeadlessView manages the ChunkView, y-axis labels, animations, and lazy loading.
// It does not concern itself with drawing the content.
function HeadlessView(config) {
  EventEmitter.call(this);

  this._config = config;

  this._width = 0;
  this._height = 0;

  this._chunkView = null;
  this._steadyState = new InstantaneousState(null, new window.scrollerjs.State(0, 0, 0), 0);

  this._animate = false;
  this._animating = false;
  this._animationStartState = null;
  this._animationCurrentState = null;

  this._needsLeftmostChunk = false;
  this._loadingLeftmostChunk = false;
  this._requestedLeftmostChunkLength = 0;

  this._needsCurrentChunk = false;
  this._loadingCurrentChunk = false;
  this._requestedCurrentChunkRange = null;

  this._registerDataSourceEvents();
  this._registerViewEvents();
  this._registerVisualStyleEvents();

  this._boundAnimationFrame = this._handleAnimationFrame.bind(this);
  this._boundAnimationEnd = this._handleAnimationEnd.bind(this);
}

// LEFTMOST_BUFFER is the number of extra pixels worth of data to load
// for the leftmost chunk.
HeadlessView.LEFTMOST_BUFFER = 2000;

// CURRENT_BUFFER is the number of pixels to the left and right of the
// current chunk to load.
HeadlessView.CURRENT_BUFFER = 2000;

// MIN_CURRENT_BUFFER is the minimum number of pixels to the left or right
// of the current chunk before it should be proactively reloaded.
HeadlessView.MIN_CURRENT_BUFFER = 1000;

// SMALL_GAP_WIDTH is used to close "gaps" to the left and right of the current
// chunk.
// If the chunk view would be within SMALL_GAP_WIDTH of the left or right of the
// content, it will be extended to go all the way.
HeadlessView.SMALL_GAP_WIDTH = 100;

HeadlessView.LEFTMOST_CHUNK = 0;
HeadlessView.CURRENT_CHUNK = 1;

HeadlessView.NEED_CHANGE_NONE = 0;
HeadlessView.NEED_CHANGE_RANGE = 1;
HeadlessView.NEED_CHANGE_FLIP = 2;

HeadlessView.prototype = Object.create(EventEmitter.prototype);

// layout updates the state based on a new width and height.
HeadlessView.prototype.layout = function(w, h) {
  w = Math.ceil(w);
  h = Math.ceil(h);
  if (this._width === w && this._height === h) {
    return;
  }

  this._width = w;
  this._height = h;

  if (this._animating) {
    this._cancelAnimation();
  }

  this._updateScrollStateForWidthChange();
  this._updateYLabels();
  this._updateLeftmostLabels();
  this._satisfyNeeds(this._updateNeeds());
};

// dispose removes any registered event listeners.
HeadlessView.prototype.dispose = function() {
  this._deregisterDataSourceEvents();
  this._deregisterViewEvents();
  this._deregisterVisualStyleEvents();
  if (this._animating) {
    this._cancelAnimation();
  }
};

// setScrolledPixels updates the scroll state and may trigger a complex chain of events.
HeadlessView.prototype.setScrolledPixels = function(p) {
  // TODO: update the scroll state.
  // TODO: recompute the y-axis labels.
  // TODO: trigger potential reloads for the leftmost chunk and the content chunk.
};

// getAnimate returns the animate flag.
// See setAnimate() for more.
HeadlessView.prototype.getAnimate = function() {
  return this._animate;
};

// setAnimate updates the animate flag.
// The animate flag is used to determine whether or not the current
// ChunkView should animate data source changes.
HeadlessView.prototype.setAnimate = function(flag) {
  this._animate = flag;
};

// chunkView returns the current ChunkView.
// This may be null if no content can be shown, but that is not guaranteed.
HeadlessView.prototype.chunkView = function() {
  return this._chunkView;
};

// instantaneousState returns the InstantaneousState of this view.
// This may be null if no content can be shown, but that is not guaranteed.
HeadlessView.prototype.instantaneousState = function() {
  if (!this._animating) {
    return this._steadyState;
  } else {
    return this._animationCurrentState;
  }
};
<commit_msg>ylcv: drafted HeadlessView.setScrolledPixels()<commit_after>//deps includes.js

// HeadlessView manages the ChunkView, y-axis labels, animations, and lazy loading.
// It does not concern itself with drawing the content.
function HeadlessView(config) {
  EventEmitter.call(this);

  this._config = config;

  this._width = 0;
  this._height = 0;

  this._chunkView = null;
  this._steadyState = new InstantaneousState(null, new window.scrollerjs.State(0, 0, 0), 0);

  this._animate = false;
  this._animating = false;
  this._animationStartState = null;
  this._animationCurrentState = null;

  this._needsLeftmostChunk = false;
  this._loadingLeftmostChunk = false;
  this._requestedLeftmostChunkLength = 0;

  this._needsCurrentChunk = false;
  this._loadingCurrentChunk = false;
  this._requestedCurrentChunkRange = null;

  this._registerDataSourceEvents();
  this._registerViewEvents();
  this._registerVisualStyleEvents();

  this._boundAnimationFrame = this._handleAnimationFrame.bind(this);
  this._boundAnimationEnd = this._handleAnimationEnd.bind(this);
}

// LEFTMOST_BUFFER is the number of extra pixels worth of data to load
// for the leftmost chunk.
HeadlessView.LEFTMOST_BUFFER = 2000;

// CURRENT_BUFFER is the number of pixels to the left and right of the
// current chunk to load.
HeadlessView.CURRENT_BUFFER = 2000;

// MIN_CURRENT_BUFFER is the minimum number of pixels to the left or right
// of the current chunk before it should be proactively reloaded.
HeadlessView.MIN_CURRENT_BUFFER = 1000;

// SMALL_GAP_WIDTH is used to close "gaps" to the left and right of the current
// chunk.
// If the chunk view would be within SMALL_GAP_WIDTH of the left or right of the
// content, it will be extended to go all the way.
HeadlessView.SMALL_GAP_WIDTH = 100;

HeadlessView.LEFTMOST_CHUNK = 0;
HeadlessView.CURRENT_CHUNK = 1;

HeadlessView.NEED_CHANGE_NONE = 0;
HeadlessView.NEED_CHANGE_RANGE = 1;
HeadlessView.NEED_CHANGE_FLIP = 2;

HeadlessView.prototype = Object.create(EventEmitter.prototype);

// layout updates the state based on a new width and height.
HeadlessView.prototype.layout = function(w, h) {
  w = Math.ceil(w);
  h = Math.ceil(h);
  if (this._width === w && this._height === h) {
    return;
  }

  this._width = w;
  this._height = h;

  if (this._animating) {
    this._cancelAnimation();
  }

  this._updateScrollStateForWidthChange();
  this._updateYLabels();
  this._updateLeftmostLabels();
  this._satisfyNeeds(this._updateNeeds());
};

// dispose removes any registered event listeners.
HeadlessView.prototype.dispose = function() {
  this._deregisterDataSourceEvents();
  this._deregisterViewEvents();
  this._deregisterVisualStyleEvents();
  if (this._animating) {
    this._cancelAnimation();
  }
};

// setScrolledPixels updates the scroll state and may trigger a complex chain of events.
HeadlessView.prototype.setScrolledPixels = function(p) {
  assert(this._steadyState !== null);

  if (this._animating) {
    this._cancelAnimation();
  }

  var s = this._steadyState.getScrollState();
  var newS = new window.scrollerjs.State(s.getTotalPixels(), s.getVisiblePixels(), p);
  this._steadState = this._steadyState.copyWithScrollState(newS);

  this._updateYLabels();
  this._satisfyNeeds(this._updateCurrentChunkNeeds());
};

// getAnimate returns the animate flag.
// See setAnimate() for more.
HeadlessView.prototype.getAnimate = function() {
  return this._animate;
};

// setAnimate updates the animate flag.
// The animate flag is used to determine whether or not the current
// ChunkView should animate data source changes.
HeadlessView.prototype.setAnimate = function(flag) {
  this._animate = flag;
};

// chunkView returns the current ChunkView.
// This may be null if no content can be shown, but that is not guaranteed.
HeadlessView.prototype.chunkView = function() {
  return this._chunkView;
};

// instantaneousState returns the InstantaneousState of this view.
// This may be null if no content can be shown, but that is not guaranteed.
HeadlessView.prototype.instantaneousState = function() {
  if (!this._animating) {
    return this._steadyState;
  } else {
    return this._animationCurrentState;
  }
};

{'fraction_non_alphanumeric': 0.09826946847960445, 'fraction_numerical': 0.006674907292954265, 'mean_word_length': 4.271009771986971, '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': '4007350', 'n_tokens_mistral': 2525, 'n_tokens_neox': 2412, 'n_words': 724}