text: /**
   * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
   *
   * @author David Sehnal <david.sehnal@gmail.com>
   * @author Alexander Rose <alexander.rose@weirdbyte.de>
   */
  import { __extends } from "tslib";
  import { Loci } from '../../../mol-model/loci';
  import { ParamDefinition as PD } from '../../../mol-util/param-definition';
  import { PluginBehavior } from '../behavior';
  import { ButtonsType, ModifiersKeys } from '../../../mol-util/input/input-observer';
  import { Binding } from '../../../mol-util/binding';
  import { PluginCommands } from '../../commands';
  import { isCameraAxesLoci } from '../../../mol-canvas3d/helper/camera-helper';
  import { Vec3 } from '../../../mol-math/linear-algebra';
  var B = ButtonsType;
  var M = ModifiersKeys;
  var Trigger = Binding.Trigger;
  var DefaultFocusLociBindings = {
      clickCenterFocus: Binding([
          Trigger(1 /* Primary */, M.create()),
          Trigger(2 /* Secondary */, M.create()),
          Trigger(1 /* Primary */, M.create({ control: true }))
      ], 'Camera center and focus', 'Click element using ${triggers}'),
      clickCenterFocusSelectMode: Binding([
          Trigger(2 /* Secondary */, M.create()),
          Trigger(1 /* Primary */, M.create({ control: true }))
      ], 'Camera center and focus', 'Click element using ${triggers}'),
  };
  var FocusLociParams = {
      minRadius: PD.Numeric(8, { min: 1, max: 50, step: 1 }),
      extraRadius: PD.Numeric(4, { min: 1, max: 50, step: 1 }, { description: 'Value added to the bounding-sphere radius of the Loci' }),
      durationMs: PD.Numeric(250, { min: 0, max: 1000, step: 1 }, { description: 'Camera transition duration' }),
      bindings: PD.Value(DefaultFocusLociBindings, { isHidden: true }),
  };
  export var FocusLoci = PluginBehavior.create({
      name: 'camera-focus-loci',
      category: 'interaction',
      ctor: /** @class */ (function (_super) {
          __extends(class_1, _super);
          function class_1() {
              return _super !== null && _super.apply(this, arguments) || this;
          }
          class_1.prototype.register = function () {
              var _this = this;
              this.subscribeObservable(this.ctx.behaviors.interaction.click, function (_a) {
                  var current = _a.current, button = _a.button, modifiers = _a.modifiers;
                  if (!_this.ctx.canvas3d)
                      return;
                  var binding = _this.ctx.selectionMode
                      ? _this.params.bindings.clickCenterFocusSelectMode
                      : _this.params.bindings.clickCenterFocus;
                  if (Binding.match(binding, button, modifiers)) {
                      if (Loci.isEmpty(current.loci)) {
                          PluginCommands.Camera.Reset(_this.ctx, {});
                          return;
                      }
                      var loci = Loci.normalize(current.loci, _this.ctx.managers.interactivity.props.granularity);
                      _this.ctx.managers.camera.focusLoci(loci, _this.params);
                  }
              });
          };
          return class_1;
      }(PluginBehavior.Handler)),
      params: function () { return FocusLociParams; },
      display: { name: 'Camera Focus Loci on Canvas' }
  });
  export var CameraAxisHelper = PluginBehavior.create({
      name: 'camera-axis-helper',
      category: 'interaction',
      ctor: /** @class */ (function (_super) {
          __extends(class_2, _super);
          function class_2() {
              return _super !== null && _super.apply(this, arguments) || this;
          }
          class_2.prototype.register = function () {
              var _this = this;
              var lastPlane = 0 /* None */;
              var state = 0;
              this.subscribeObservable(this.ctx.behaviors.interaction.click, function (_a) {
                  var current = _a.current;
                  if (!_this.ctx.canvas3d || !isCameraAxesLoci(current.loci))
                      return;
                  var axis = current.loci.elements[0].groupId;
                  if (axis === 0 /* None */) {
                      lastPlane = 0 /* None */;
                      state = 0;
                      return;
                  }
                  var camera = _this.ctx.canvas3d.camera;
                  var dir, up;
                  if (axis >= 1 /* X */ && axis <= 3 /* Z */) {
                      lastPlane = 0 /* None */;
                      state = 0;
                      var d = Vec3.sub(Vec3(), camera.target, camera.position);
                      var c = Vec3.cross(Vec3(), d, camera.up);
                      up = Vec3();
                      up[axis - 1] = 1;
                      dir = Vec3.cross(Vec3(), up, c);
                      if (Vec3.magnitude(dir) === 0)
                          dir = d;
                  }
                  else {
                      if (lastPlane === axis) {
                          state = (state + 1) % 2;
                      }
                      else {
                          lastPlane = axis;
                          state = 0;
                      }
                      if (axis === 4 /* XY */) {
                          up = state ? Vec3.unitX : Vec3.unitY;
                          dir = Vec3.negUnitZ;
                      }
                      else if (axis === 5 /* XZ */) {
                          up = state ? Vec3.unitX : Vec3.unitZ;
                          dir = Vec3.negUnitY;
                      }
                      else {
                          up = state ? Vec3.unitY : Vec3.unitZ;
                          dir = Vec3.negUnitX;
                      }
                  }
                  _this.ctx.canvas3d.requestCameraReset({
                      snapshot: function (scene, camera) { return camera.getInvariantFocus(scene.boundingSphereVisible.center, scene.boundingSphereVisible.radius, up, dir); }
                  });
              });
          };
          return class_2;
      }(PluginBehavior.Handler)),
      params: function () { return ({}); },
      display: { name: 'Camera Axis Helper' }
  });
  //# sourceMappingURL=camera.js.map