UNPKG

vscroll

Version:
80 lines 2.93 kB
import { __read, __spreadArray } from "tslib"; import { Paddings } from './paddings'; import { Direction } from '../inputs/index'; var Viewport = /** @class */ (function () { function Viewport(settings, routines, state, logger) { this.settings = settings; this.routines = routines; this.state = state; this.logger = logger; this.paddings = new Paddings(this.routines, settings); } Viewport.prototype.reset = function (startIndex) { this.setOffset(); this.paddings.reset(this.getSize(), startIndex, this.offset); this.scrollPosition = this.paddings.backward.size || 0; this.state.scroll.reset(); }; Viewport.prototype.setPosition = function (value) { var oldPosition = this.scrollPosition; if (oldPosition === value) { this.logger.log(function () { return ['setting scroll position at', value, '[cancelled]']; }); return value; } this.routines.setScrollPosition(value); var position = this.scrollPosition; this.logger.log(function () { return __spreadArray([ 'setting scroll position at', position ], __read((position !== value ? ["(".concat(value, ")")] : [])), false); }); return position; }; Object.defineProperty(Viewport.prototype, "scrollPosition", { get: function () { return this.routines.getScrollPosition(); }, set: function (value) { this.setPosition(value); }, enumerable: false, configurable: true }); Viewport.prototype.getSize = function () { return this.routines.getViewportSize(); }; Viewport.prototype.getScrollableSize = function () { return this.routines.getScrollerSize(); }; Viewport.prototype.getMaxScrollPosition = function () { return this.getScrollableSize() - this.getSize(); }; Viewport.prototype.getBufferPadding = function () { return this.getSize() * this.settings.padding; }; Viewport.prototype.getEdge = function (direction) { return this.routines.getViewportEdge(direction); }; Viewport.prototype.setOffset = function () { this.offset = this.routines.getOffset(); }; Viewport.prototype.findItemElementById = function (id) { return this.routines.findItemElement(id); }; Viewport.prototype.getEdgeVisibleItem = function (items, direction) { var bwd = direction === Direction.backward; var opposite = bwd ? Direction.forward : Direction.backward; var viewportEdge = this.getEdge(direction); var item, diff = 0; for (var i = bwd ? 0 : items.length - 1; bwd ? i <= items.length - 1 : i >= 0; i += bwd ? 1 : -1) { var itemEdge = this.routines.getEdge(items[i].element, opposite); diff = itemEdge - viewportEdge; if (bwd && diff > 0 || !bwd && diff < 0) { item = items[i]; break; } } return { item: item, index: item ? item.$index : NaN, diff: diff }; }; return Viewport; }()); export { Viewport }; //# sourceMappingURL=viewport.js.map