text: "use strict";
  /**
   * Copyright (c) 2020-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>
   */
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.PluginConfigManager = exports.PluginConfig = exports.PluginConfigItem = void 0;
  var structure_1 = require("../mol-model/structure");
  var PluginConfigItem = /** @class */ (function () {
      function PluginConfigItem(key, defaultValue) {
          this.key = key;
          this.defaultValue = defaultValue;
      }
      PluginConfigItem.prototype.toString = function () { return this.key; };
      PluginConfigItem.prototype.valueOf = function () { return this.key; };
      return PluginConfigItem;
  }());
  exports.PluginConfigItem = PluginConfigItem;
  function item(key, defaultValue) { return new PluginConfigItem(key, defaultValue); }
  function preferWebGl1() {
      if (typeof navigator === 'undefined' || typeof window === 'undefined')
          return false;
      // WebGL2 isn't working in MacOS 12.0.1 Safari 15.1 (but is working in Safari tech preview)
      // prefer webgl 1 based on the userAgent substring
      if (navigator.userAgent.indexOf('Version/15.1 Safari') > 0) {
          return true;
      }
      // Check for iOS device which enabled WebGL2 recently but it doesn't seem
      // to be full up to speed yet.
      // adapted from https://stackoverflow.com/questions/9038625/detect-if-device-is-ios
      var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
      var isAppleDevice = navigator.userAgent.includes('Macintosh');
      var isTouchScreen = navigator.maxTouchPoints >= 4; // true for iOS 13 (and hopefully beyond)
      return !window.MSStream && (isIOS || (isAppleDevice && isTouchScreen));
  }
  exports.PluginConfig = {
      item: item,
      General: {
          IsBusyTimeoutMs: item('plugin-config.is-busy-timeout', 750),
          DisableAntialiasing: item('plugin-config.disable-antialiasing', false),
          DisablePreserveDrawingBuffer: item('plugin-config.disable-preserve-drawing-buffer', false),
          PixelScale: item('plugin-config.pixel-scale', 1),
          PickScale: item('plugin-config.pick-scale', 0.25),
          PickPadding: item('plugin-config.pick-padding', 3),
          EnableWboit: item('plugin-config.enable-wboit', true),
          // as of Oct 1 2021, WebGL 2 doesn't work on iOS 15.
          // TODO: check back in a few weeks to see if it was fixed
          PreferWebGl1: item('plugin-config.prefer-webgl1', preferWebGl1()),
      },
      State: {
          DefaultServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'),
          CurrentServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'),
          HistoryCapacity: item('history-capacity.server', 5)
      },
      VolumeStreaming: {
          Enabled: item('volume-streaming.enabled', true),
          DefaultServer: item('volume-streaming.server', 'https://ds.litemol.org'),
          CanStream: item('volume-streaming.can-stream', function (s, plugin) {
              return s.models.length === 1 && structure_1.Model.probablyHasDensityMap(s.models[0]);
          }),
          EmdbHeaderServer: item('volume-streaming.emdb-header-server', 'https://ftp.wwpdb.org/pub/emdb/structures'),
      },
      Viewport: {
          ShowExpand: item('viewer.show-expand-button', true),
          ShowControls: item('viewer.show-controls-button', true),
          ShowSettings: item('viewer.show-settings-button', true),
          ShowSelectionMode: item('viewer.show-selection-model-button', true),
          ShowAnimation: item('viewer.show-animation-button', true),
      },
      Download: {
          DefaultPdbProvider: item('download.default-pdb-provider', 'pdbe'),
          DefaultEmdbProvider: item('download.default-emdb-provider', 'pdbe'),
      },
      Structure: {
          SizeThresholds: item('structure.size-thresholds', structure_1.Structure.DefaultSizeThresholds),
          DefaultRepresentationPresetParams: item('structure.default-representation-preset-params', {})
      }
  };
  var PluginConfigManager = /** @class */ (function () {
      function PluginConfigManager(initial) {
          var _this = this;
          this._config = new Map();
          if (!initial)
              return;
          initial.forEach(function (_a) {
              var k = _a[0], v = _a[1];
              return _this._config.set(k, v);
          });
      }
      PluginConfigManager.prototype.get = function (key) {
          if (!this._config.has(key))
              return key.defaultValue;
          return this._config.get(key);
      };
      PluginConfigManager.prototype.set = function (key, value) {
          this._config.set(key, value);
      };
      PluginConfigManager.prototype.delete = function (key) {
          this._config.delete(key);
      };
      return PluginConfigManager;
  }());
  exports.PluginConfigManager = PluginConfigManager;
  //# sourceMappingURL=config.js.map