UNPKG

vevet

Version:

Vevet is a JavaScript library for creative development that simplifies crafting rich interactions like split text animations, carousels, marquees, preloading, and more.

80 lines 2.9 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.SnapInterval = void 0; var isFiniteNumber_1 = require("../../../../internal/isFiniteNumber"); var SnapLogic_1 = require("../SnapLogic"); var SnapInterval = /** @class */ (function (_super) { __extends(SnapInterval, _super); function SnapInterval(snap) { var _this = _super.call(this, snap) || this; snap.on('update', function () { return _this._handleUpdate(); }, { protected: true }); _this.addDestructor(function () { _this._clearInterval(); }); return _this; } Object.defineProperty(SnapInterval.prototype, "allowInterval", { get: function () { var snap = this.snap; if (snap.isSwiping || snap.hasInteria || snap.isTransitioning || snap.isInterpolating || !(0, isFiniteNumber_1.isFiniteNumber)(snap.props.interval)) { return false; } return true; }, enumerable: false, configurable: true }); /** Handle Snap update */ SnapInterval.prototype._handleUpdate = function () { var _this = this; var snap = this.snap; if (!this.allowInterval) { this._clearInterval(); return; } if (!this._interval) { this._interval = setInterval(function () { _this._handleInterval(); }, snap.props.interval); } }; /** Handle interval action */ SnapInterval.prototype._handleInterval = function () { var snap = this.snap; if (snap.props.intervalDirection === 'prev') { snap.prev(); } else { snap.next(); } }; /** Clear interval */ SnapInterval.prototype._clearInterval = function () { if (this._interval) { clearInterval(this._interval); this._interval = undefined; } }; return SnapInterval; }(SnapLogic_1.SnapLogic)); exports.SnapInterval = SnapInterval; //# sourceMappingURL=index.js.map