UNPKG

vscroll

Version:
40 lines 1.46 kB
import { SETTINGS, DEV_SETTINGS, validate, validateOne, VALIDATORS } from '../inputs/index'; export class Settings { constructor(settings, devSettings, instanceIndex) { this.parseInput(settings, SETTINGS); this.parseInput(devSettings, DEV_SETTINGS); this.instanceIndex = instanceIndex; this.initializeDelay = this.getInitializeDelay(); this.viewport = this.getViewport(); // todo: min/max indexes must be ignored if infinite mode is enabled ?? } parseInput(input, props) { const result = validate(input, props); if (!result.isValid) { throw new Error('Invalid settings'); } Object.entries(result.params).forEach(([key, par]) => Object.assign(this, { [key]: par.value })); } getInitializeDelay() { let result = 0; if (this.windowViewport && this.initWindowDelay && !('scrollRestoration' in history)) { result = this.initWindowDelay; } if (this.initDelay > 0) { result = Math.max(result, this.initDelay); } return result; } getViewport() { if (typeof this.viewportElement !== 'function') { return this.viewportElement; } const value = this.viewportElement(); const result = validateOne({ value }, 'value', { validators: [VALIDATORS.ELEMENT] }); if (!result.isValid) { return null; // fallback to default (null) if Function didn't return HTML element synchronously } return result.value; } } //# sourceMappingURL=settings.js.map