{"size": 952, "ext": "js", "max_stars_repo_path": "src/Block.js", "max_stars_repo_name": "bigcommerce/themes-lib-squid", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Block.js", "max_issues_repo_name": "bigcommerce/themes-lib-squid", "max_issues_repo_issues_event_min_datetime": "2021-05-10T12:25:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T12:25:46.000Z", "max_forks_repo_path": "src/Block.js", "max_forks_repo_name": "pixelunion/bc-squid", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 26.4444444444, "max_line_length": 79, "alphanum_fraction": 0.656512605}
/**
 * A layout block.
 *
 * Holds an item's natural size, and layout size.
 *
 * The natural size is calculated by the `getSize` function, and represents the
 * size it naturally takes up.
 *
 * The layout size starts as the natural size, but is then adjusted to make the
 * item fit in the grid.
 */
export default class Block {
  constructor(object, naturalSize, gravity, resistance) {
    this.object = object;

    this.naturalSize = naturalSize;
    this.size = Object.assign({}, this.naturalSize);
    this.gravity = gravity;
    this.resistance = resistance;
  }

  updateSizeForWidth(width) {
    // Don't touch the height
    if (this.resistance === 1) {
      this.size = { width, height: this.naturalSize.height };
    }

    // Resize height based on new width
    else {
      const ratio = width / this.naturalSize.width;
      const height = Math.floor(this.naturalSize.height * ratio);
      this.size = { width, height };
    }
  }
}
