/*!
 * better-scroll / wheel
 * (c) 2016-2023 ustbhuangyi
 * Released under the MIT License.
 */
var u = typeof window < "u", p = u && navigator.userAgent.toLowerCase();
p && p.indexOf("android") > 0;
(function() {
  if (typeof p == "string") {
    var o = /os (\d\d?_\d(_\d)?)/, e = o.exec(p);
    if (!e)
      return !1;
    var t = e[1].split("_").map(function(r) {
      return parseInt(r, 10);
    });
    return t[0] === 13 && t[1] >= 4;
  }
  return !1;
})();
var T = !1;
if (u) {
  var w = "test-passive";
  try {
    var y = {};
    Object.defineProperty(y, "passive", {
      get: function() {
        T = !0;
      }
    }), window.addEventListener(w, function() {
    }, y);
  } catch {
  }
}
var x = function(o, e) {
  for (var t in e)
    o[t] = e[t];
  return o;
}, g = u && document.createElement("div").style, d = function() {
  if (!u)
    return !1;
  for (var o = [
    {
      key: "standard",
      value: "transform"
    },
    {
      key: "webkit",
      value: "webkitTransform"
    },
    {
      key: "Moz",
      value: "MozTransform"
    },
    {
      key: "O",
      value: "OTransform"
    },
    {
      key: "ms",
      value: "msTransform"
    }
  ], e = 0, t = o; e < t.length; e++) {
    var r = t[e];
    if (g[r.value] !== void 0)
      return r.key;
  }
  return !1;
}();
function l(o) {
  return d === !1 ? o : d === "standard" ? o === "transitionEnd" ? "transitionend" : o : d + o.charAt(0).toUpperCase() + o.substr(1);
}
d && d !== "standard" && "" + d.toLowerCase();
var I = l("transform"), S = l("transition");
u && l("perspective") in g;
var v = {
  transform: I,
  transition: S,
  transitionTimingFunction: l("transitionTimingFunction"),
  transitionDuration: l("transitionDuration"),
  transitionDelay: l("transitionDelay"),
  transformOrigin: l("transformOrigin"),
  transitionEnd: l("transitionEnd"),
  transitionProperty: l("transitionProperty")
};
function f(o, e) {
  var t = new RegExp("(^|\\s)" + e + "(\\s|$)");
  return t.test(o.className);
}
function b(o) {
  return Array.prototype.slice.call(o, 0);
}
var D = {
  // easeOutQuint
  swipe: {
    style: "cubic-bezier(0.23, 1, 0.32, 1)",
    fn: function(o) {
      return 1 + --o * o * o * o * o;
    }
  },
  // easeOutQuard
  swipeBounce: {
    style: "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
    fn: function(o) {
      return o * (2 - o);
    }
  },
  // easeOutQuart
  bounce: {
    style: "cubic-bezier(0.165, 0.84, 0.44, 1)",
    fn: function(o) {
      return 1 - --o * o * o * o;
    }
  }
}, C = "plugins.wheel", N = [
  {
    key: "wheelTo",
    name: "wheelTo"
  },
  {
    key: "getSelectedIndex",
    name: "getSelectedIndex"
  },
  {
    key: "restorePosition",
    name: "restorePosition"
  }
], P = N.map(function(o) {
  return {
    key: o.key,
    sourceKey: C + "." + o.name
  };
}), k = "wheelIndexChanged", A = {
  rate: 4
}, B = (
  /** @class */
  function() {
    function o(e) {
      this.scroll = e, this.init();
    }
    return o.prototype.init = function() {
      this.handleBScroll(), this.handleOptions(), this.handleHooks(), this.refreshBoundary(), this.setSelectedIndex(this.options.selectedIndex);
    }, o.prototype.handleBScroll = function() {
      this.scroll.proxy(P), this.scroll.registerType([k]);
    }, o.prototype.handleOptions = function() {
      var e = this.scroll.options.wheel === !0 ? {} : this.scroll.options.wheel, t = {
        wheelWrapperClass: "wheel-scroll",
        wheelItemClass: "wheel-item",
        rotate: 25,
        adjustTime: 400,
        selectedIndex: 0,
        wheelDisabledItemClass: "wheel-disabled-item"
      };
      this.options = x(t, e);
    }, o.prototype.handleHooks = function() {
      var e = this, t = this.scroll, r = this.scroll.scroller, i = r.actionsHandler, h = r.scrollBehaviorX, s = r.scrollBehaviorY, a = r.animater, m = r.content;
      t.on(t.eventTypes.scrollEnd, function(n) {
        var c = e.findNearestValidWheel(n.y).index;
        if (r.animater.forceStopped && !e.isAdjustingPosition)
          return e.target = e.items[c], !0;
        e.setSelectedIndex(c), e.isAdjustingPosition && (e.isAdjustingPosition = !1);
      }), this.scroll.hooks.on(this.scroll.hooks.eventTypes.refresh, function(n) {
        n !== m && (m = n, e.setSelectedIndex(e.options.selectedIndex, !0)), e.rotateX(e.scroll.y), e.wheelTo(e.selectedIndex, 0);
      }), this.scroll.hooks.on(this.scroll.hooks.eventTypes.beforeInitialScrollTo, function(n) {
        n.x = 0, n.y = -(e.selectedIndex * e.itemHeight);
      }), r.hooks.on(r.hooks.eventTypes.checkClick, function() {
        var n = b(e.items).indexOf(e.target);
        return n === -1 || e.wheelTo(n, e.options.adjustTime, D.swipe), !0;
      }), r.hooks.on(r.hooks.eventTypes.scrollTo, function(n) {
        n.y = e.findNearestValidWheel(n.y).y;
      }), r.hooks.on(r.hooks.eventTypes.minDistanceScroll, function() {
        var n = r.animater;
        n.forceStopped === !0 && (n.forceStopped = !1);
      }), r.hooks.on(r.hooks.eventTypes.scrollToElement, function(n, c) {
        if (f(n, e.options.wheelItemClass))
          c.top = e.findNearestValidWheel(c.top).y;
        else
          return !0;
      }), i.hooks.on(i.hooks.eventTypes.beforeStart, function(n) {
        e.target = n.target;
      }), h.hooks.on(h.hooks.eventTypes.computeBoundary, function(n) {
        n.maxScrollPos = 0, n.minScrollPos = 0;
      }), s.hooks.on(s.hooks.eventTypes.computeBoundary, function(n) {
        e.items = e.scroll.scroller.content.children, e.checkWheelAllDisabled(), e.itemHeight = e.items.length > 0 ? s.contentSize / e.items.length : 0, n.maxScrollPos = -e.itemHeight * (e.items.length - 1), n.minScrollPos = 0;
      }), s.hooks.on(s.hooks.eventTypes.momentum, function(n) {
        n.rate = A.rate, n.destination = e.findNearestValidWheel(n.destination).y;
      }), s.hooks.on(s.hooks.eventTypes.end, function(n) {
        var c = e.findNearestValidWheel(s.currentPos);
        n.destination = c.y, n.duration = e.options.adjustTime;
      }), a.hooks.on(a.hooks.eventTypes.time, function(n) {
        e.transitionDuration(n);
      }), a.hooks.on(a.hooks.eventTypes.timeFunction, function(n) {
        e.timeFunction(n);
      }), a.hooks.on(a.hooks.eventTypes.callStop, function() {
        var n = e.findNearestValidWheel(e.scroll.y).index;
        e.isAdjustingPosition = !0, e.wheelTo(n, 0);
      }), a.translater.hooks.on(a.translater.hooks.eventTypes.translate, function(n) {
        e.rotateX(n.y);
      });
    }, o.prototype.refreshBoundary = function() {
      var e = this.scroll.scroller, t = e.scrollBehaviorX, r = e.scrollBehaviorY, i = e.content;
      t.refresh(i), r.refresh(i);
    }, o.prototype.setSelectedIndex = function(e, t) {
      t === void 0 && (t = !1);
      var r = this.selectedIndex;
      this.selectedIndex = e, r !== e && !t && this.scroll.trigger(k, e);
    }, o.prototype.getSelectedIndex = function() {
      return this.selectedIndex;
    }, o.prototype.wheelTo = function(e, t, r) {
      e === void 0 && (e = 0), t === void 0 && (t = 0);
      var i = -e * this.itemHeight;
      this.scroll.scrollTo(0, i, t, r);
    }, o.prototype.restorePosition = function() {
      var e = this.scroll.pending;
      if (e) {
        var t = this.getSelectedIndex();
        this.scroll.scroller.animater.clearTimer(), this.wheelTo(t, 0);
      }
    }, o.prototype.transitionDuration = function(e) {
      for (var t = 0; t < this.items.length; t++)
        this.items[t].style[v.transitionDuration] = e + "ms";
    }, o.prototype.timeFunction = function(e) {
      for (var t = 0; t < this.items.length; t++)
        this.items[t].style[v.transitionTimingFunction] = e;
    }, o.prototype.rotateX = function(e) {
      for (var t = this.options.rotate, r = t === void 0 ? 25 : t, i = 0; i < this.items.length; i++) {
        var h = r * (e / this.itemHeight + i), s = h.toFixed(3);
        this.items[i].style[v.transform] = "rotateX(" + s + "deg)";
      }
    }, o.prototype.findNearestValidWheel = function(e) {
      e = e > 0 ? 0 : e < this.scroll.maxScrollY ? this.scroll.maxScrollY : e;
      for (var t = Math.abs(Math.round(-e / this.itemHeight)), r = t, i = this.items, h = this.options.wheelDisabledItemClass; t >= 0 && f(i[t], h); )
        t--;
      if (t < 0)
        for (t = r; t <= i.length - 1 && f(i[t], h); )
          t++;
      return t === i.length && (t = r), {
        index: this.wheelItemsAllDisabled ? -1 : t,
        y: -t * this.itemHeight
      };
    }, o.prototype.checkWheelAllDisabled = function() {
      var e = this.options.wheelDisabledItemClass, t = this.items;
      this.wheelItemsAllDisabled = !0;
      for (var r = 0; r < t.length; r++)
        if (!f(t[r], e)) {
          this.wheelItemsAllDisabled = !1;
          break;
        }
    }, o.pluginName = "wheel", o;
  }()
);
export {
  B as default
};
