Sha256: 662de6919c69f1986cf43f9f052e3ba619e0d796a608533e2b3884f25189cafb
Contents?: true
Size: 1.08 KB
Versions: 29
Compression:
Stored size: 1.08 KB
Contents
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.finite = finite; exports.infinite = infinite; /** * Creates the next position for the active item considering a finite list of * items to be rendered on a page. */ function finite({ active, pageSize, total, }) { const middle = Math.floor(pageSize / 2); if (total <= pageSize || active < middle) return active; if (active >= total - middle) return active + pageSize - total; return middle; } /** * Creates the next position for the active item considering an infinitely * looping list of items to be rendered on the page. */ function infinite({ active, lastActive, total, pageSize, pointer, }) { if (total <= pageSize) return active; // Move the position only when the user moves down, and when the // navigation fits within a single page if (lastActive < active && active - lastActive < pageSize) { // Limit it to the middle of the list return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive); } return pointer; }
Version data entries
29 entries across 29 versions & 2 rubygems