<commit_before>library freecell.view.card;

import "package:polymer/polymer.dart";
import "dart:async";
import "dart:html";
import "dart:math";

import "../deck/deck.dart";
import "../viewmodel/viewmodel.dart";
import "card-coordinator.dart";

@CustomTag("fc-card")
class FcCard extends PolymerElement {
  @published ViewCard card;
  Completer<FcCard> _completer;
  bool isAttached = false;

  static const double _kSettleVelocity = 1.5; // dips per ms
  static const double _kMinSettleDuration = 200.0; // ms
  static const double _kMaxSettleDuration = 500.0; // ms
  static const double _kFlyAwayDuration = 1500.0; // ms

  FcCard.created() : super.created() {
  }

  void attached() {
    isAttached = true;
    _registerCard();
  }

  void _playFlyAway() {
    classes.add("moving fly-away");
    Random random = new Random();
    Rectangle rootRect = document.body.getBoundingClientRect();
    Rectangle rect = card.lastClientRect;
    double endX = rootRect.width + rect.width;
    double endY = rootRect.height + rect.height;
    if (random.nextBool())
      endX *= -1;
    endX /= (random.nextInt(5) + 1);
    style.width = rect.width.toString() + "px";
    style.height = rect.height.toString() + "px";
    style.transform = "translate(${rect.left}px, ${rect.top}px)";
    style.zIndex = "${52 - card.flyAwayOrder}";
    style.marginTop = "0";
    card.animate(this, [{
      "transform": "translate(${rect.left}px, ${rect.top}px)",
    }, {
      "transform": "translate(${endX}px, ${endY}px)",
    }], {
      "duration": _kFlyAwayDuration,
      "delay": card.flyAwayOrder * 75,
      "easing": "ease-out",
      "fill": "both",
    }).then((_) {
      classes.remove("moving");
    });
  }

  void _playMovement() {
    Point displacement = card.updateClientRect(getBoundingClientRect());
    if (displacement == null)
      return;
    double distance = displacement.magnitude;
    if (distance == 0)
      return;
    double duration = min(max(distance / _kSettleVelocity, _kMinSettleDuration), _kMaxSettleDuration);
    classes.addAll(["moving", "glow"]);
    card.animate(this, [{
      "transform": "translate(${-displacement.x}px, ${-displacement.y}px)",
      "zIndex": "10",<commit_msg>Allow one frame to happen before showing the win animation to allow the big raster.<commit_after>library freecell.view.card;

import "package:polymer/polymer.dart";
import "dart:async";
import "dart:html";
import "dart:math";

import "../deck/deck.dart";
import "../viewmodel/viewmodel.dart";
import "card-coordinator.dart";

@CustomTag("fc-card")
class FcCard extends PolymerElement {
  @published ViewCard card;
  Completer<FcCard> _completer;
  bool isAttached = false;

  static const double _kSettleVelocity = 1.5; // dips per ms
  static const double _kMinSettleDuration = 200.0; // ms
  static const double _kMaxSettleDuration = 500.0; // ms
  static const double _kFlyAwayDuration = 1500.0; // ms

  FcCard.created() : super.created() {
  }

  void attached() {
    isAttached = true;
    _registerCard();
  }

  void _playFlyAway() {
    classes.add("moving fly-away");
    Random random = new Random();
    Rectangle rootRect = document.body.getBoundingClientRect();
    Rectangle rect = card.lastClientRect;
    double endX = rootRect.width + rect.width;
    double endY = rootRect.height + rect.height;
    if (random.nextBool())
      endX *= -1;
    endX /= (random.nextInt(5) + 1);
    style.width = rect.width.toString() + "px";
    style.height = rect.height.toString() + "px";
    style.transform = "translate(${rect.left}px, ${rect.top}px)";
    style.zIndex = "${52 - card.flyAwayOrder}";
    style.marginTop = "0";
    async((_) {
      async((_) {
        card.animate(this, [{
          "transform": "translate(${rect.left}px, ${rect.top}px)",
        }, {
          "transform": "translate(${endX}px, ${endY}px)",
        }], {
          "duration": _kFlyAwayDuration,
          "delay": card.flyAwayOrder * 75,
          "easing": "ease-out",
          "fill": "both",
        }).then((_) {
          classes.remove("moving");
        });
      });
    });
  }

  void _playMovement() {
    Point displacement = card.updateClientRect(getBoundingClientRect());
    if (displacement == null)
      return;
    double distance = displacement.magnitude;
    if (distance == 0)
      return;
    double duration = min(max(distance / _kSettleVelocity, _kMinSettleDuration), _kMaxSettleDuration);
    classes.addAll(["moving", "glow"]);
    card.animate(this, [{
      "transform": "translate(${-displacement.x}px, ${-displacement.y}px)",
      "zIndex": "10",
{'fraction_non_alphanumeric': 0.15852594853903185, 'fraction_numerical': 0.0113388573920628, 'mean_word_length': 3.263011152416357, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 5, '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': '316382', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1499, 'n_words': 321}