System.register(['reactive-jsx', 'src/components/widgets/lively-morph.js', 'src/client/graphics.js'], function (_export, _context) {
  "use strict";

  var _addSourceLocation, Morph, pt;

  return {
    setters: [function (_reactiveJsx) {
      _addSourceLocation = _reactiveJsx.addSourceLocation;
    }, function (_srcComponentsWidgetsLivelyMorphJs) {
      Morph = _srcComponentsWidgetsLivelyMorphJs.default;
    }, function (_srcClientGraphicsJs) {
      pt = _srcClientGraphicsJs.pt;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_components_demo_lively_ball_js = _recorder_._src_components_demo_lively_ball_js || {};
      Object.defineProperty(_recorder_._src_components_demo_lively_ball_js, 'Morph', {
        get() {
          return Morph;
        },

        set(thisIsVererySecretVariableName) {
          Morph = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_demo_lively_ball_js, 'pt', {
        get() {
          return pt;
        },

        set(thisIsVererySecretVariableName) {
          pt = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      class LivelyBall extends Morph {

        async initialize() {
          this.a = this.a || -1;
          this.v = this.b || 0;
          this.s = this.s || 300;
          this.step();
          this.path = this.path || [];
        }

        simulate(t) {
          this.v = this.v + this.a * t;
          this.s = this.s + this.v * t;
          if (this.s < 0) {
            this.s = 0;
            this.v = this.v * -0.9;
          }
        }

        render(t) {
          // console.log("A")
          var p = pt(20, lively.getExtent(this.parentElement).y - this.s - lively.getExtent(this).y);
          lively.setPosition(this, p);
          p.x = (this.lastTime - this.startTime) * 0.01;
          this.path.push(p);
        }

        step() {
          if (!lively.isInBody(this)) return;
          // console.log("B")
          var time = Date.now();
          if (this.lastTime) {
            var t = (time - this.lastTime) * 0.01;
            this.simulate(t);
            this.render();
          } else {
            this.startTime = time;
          }
          window.requestAnimationFrame(() => this.step());
          this.lastTime = time;
        }

        // LivelyBall.livelyExample(document.body)
        static async livelyExample(parent) {
          var container = _addSourceLocation(document.createElement("div"), {
            file: 'https://lively-kernel.org/lively4/lively4-petrinet/src/components/demo/lively-ball.js',
            end: {
              column: 49,
              line: 51
            },
            start: {
              column: 20,
              line: 51
            }
          });
          container.style.position = "absolute";
          container.style.backgroundColor = "lightgray";
          // container.innerHTML = "<button id='reset'>reset</button>"
          lively.setExtent(container, pt(150, 400));
          var ball = this.create();
          await lively.components.openIn(container, ball);
          ball.livelyExample
          // container.querySelector("#reset").addEventListener("click", () => { 
          //   ball.s = 200;
          //   ball.v = 0;
          //   ball.path = [];
          //   ball.livelyExample()
          // })
          ();if (parent) parent.appendChild(container);
          return container;
        }

        static create() {
          return _addSourceLocation(document.createElement("lively-ball"), {
            file: 'https://lively-kernel.org/lively4/lively4-petrinet/src/components/demo/lively-ball.js',
            end: {
              column: 48,
              line: 70
            },
            start: {
              column: 11,
              line: 70
            }
          });
        }

        livelyExample() {
          lively.setExtent(this, pt(30, 30));

          var div = _addSourceLocation(document.createElement("div"), {
            file: 'https://lively-kernel.org/lively4/lively4-petrinet/src/components/demo/lively-ball.js',
            end: {
              column: 43,
              line: 76
            },
            start: {
              column: 14,
              line: 76
            }
          });
          div.id = "log";
          this.parentElement.appendChild(div);
        }

        livelyMigrate(other) {
          this.a = other.a;
          this.s = other.s;
          this.v = other.v;
        }

      }

      _export('default', LivelyBall);

      Object.defineProperty(_recorder_._src_components_demo_lively_ball_js, 'LivelyBall', {
        get() {
          return LivelyBall;
        },

        set(thisIsVererySecretVariableName) {
          _export('default', LivelyBall = thisIsVererySecretVariableName);

          return true;
        },

        enumerable: true,
        configurable: true
      });
    }
  };
});