import { is as u$1 } from "../../util/ModelUtil.mjs";
function u(i, e) {
  var t = null, o = new h();
  i.on("root.set", function(l) {
    var s = l.element, r = e.viewbox(), n = o.get(s);
    if (o.set(t, {
      x: r.x,
      y: r.y,
      zoom: r.scale
    }), t = s, !(u$1(s, "bpmn:Collaboration") && !n)) {
      n = n || { x: 0, y: 0, zoom: 1 };
      var a = (r.x - n.x) * r.scale, f = (r.y - n.y) * r.scale;
      (a !== 0 || f !== 0) && e.scroll({
        dx: a,
        dy: f
      }), n.zoom !== r.scale && e.zoom(n.zoom, { x: 0, y: 0 });
    }
  }), i.on("diagram.clear", function() {
    o.clear(), t = null;
  });
}
u.$inject = ["eventBus", "canvas"];
function h() {
  this._entries = [], this.set = function(i, e) {
    var t = false;
    for (var o in this._entries)
      if (this._entries[o][0] === i) {
        this._entries[o][1] = e, t = true;
        break;
      }
    t || this._entries.push([i, e]);
  }, this.get = function(i) {
    for (var e in this._entries)
      if (this._entries[e][0] === i)
        return this._entries[e][1];
    return null;
  }, this.clear = function() {
    this._entries.length = 0;
  }, this.remove = function(i) {
    var e = -1;
    for (var t in this._entries)
      if (this._entries[t][0] === i) {
        e = t;
        break;
      }
    e !== -1 && this._entries.splice(e, 1);
  };
}
export {
  u as default
};
