UNPKG

@sahabaplus/mushaf-engine

Version:

TypeScript implementation of a Quran Mushaf navigation engine

122 lines (121 loc) 5.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NavigationResult = void 0; /** * Comprehensive result of a navigation operation in the Quran * * This class contains the primary verse reached through navigation, * as well as optional information about any overflow conditions or boundary * verses (last verse of page or sura) encountered during navigation. */ class NavigationResult { /** * Create a new NavigationResult with all possible parameters * * @param verse - The verse reached through navigation * @param overflow - Optional information about overflow if navigation exceeded boundaries * @param endOfPage - Optional information about the last verse of the page if encountered * @param endOfSura - Optional information about the last verse of the sura if encountered * @param distanceMoved - The actual distance moved during navigation in lines */ constructor(verse, overflow, endOfPage, endOfSura, distanceMoved = 0) { this.verse = verse; this.overflow = overflow; this.endOfPage = endOfPage; this.endOfSura = endOfSura; this.distanceMoved = distanceMoved; // Calculate remaining distance const remainingDistance = overflow ? overflow.overflowedVerse.lines - overflow.overflowLines : 0.0; this.remainingDistance = Math.round(remainingDistance * 100) / 100; } /** * Create a new NavigationResult for a normal navigation with no boundary conditions * * @param verse - The verse reached through navigation * @param distanceMoved - The actual distance moved during navigation in lines * @returns A new NavigationResult instance with only the target verse and no boundary information */ static newNormal(verse, distanceMoved) { return new NavigationResult(verse, undefined, undefined, undefined, distanceMoved); } /** * Create a new NavigationResult for a navigation that includes overflow * * @param verse - The verse reached through navigation * @param overflow - Information about overflow during navigation * @param distanceMoved - The actual distance moved during navigation in lines * @returns A new NavigationResult instance with the target verse and overflow information */ static newOverflowed(verse, overflow, distanceMoved) { return new NavigationResult(verse, overflow, undefined, undefined, distanceMoved); } /** * Create a new NavigationResult that reached the last verse of a page * * @param verse - The verse reached through navigation * @param lastOfPage - Information about the last verse of the page * @param distanceMoved - The actual distance moved during navigation in lines * @returns A new NavigationResult instance with the target verse and last-of-page information */ static newPageBoundary(verse, lastOfPage, distanceMoved) { return new NavigationResult(verse, undefined, lastOfPage, undefined, distanceMoved); } /** * Create a new NavigationResult that reached the last verse of a sura * * @param verse - The verse reached through navigation * @param lastOfSura - Information about the last verse of the sura * @param distanceMoved - The actual distance moved during navigation in lines * @returns A new NavigationResult instance with the target verse and last-of-sura information */ static newSuraBoundary(verse, lastOfSura, distanceMoved) { return new NavigationResult(verse, undefined, undefined, lastOfSura, distanceMoved); } /** * Check if this navigation result encountered any boundaries * * @returns true if the navigation hit the last verse of page, sura, or had an overflow */ hasBoundaries() { return this.overflow !== undefined || this.endOfPage !== undefined || this.endOfSura !== undefined; } /** * Check if this navigation result encountered an overflow condition * * @returns true if the navigation exceeded available boundaries */ hasOverflow() { return this.overflow !== undefined; } /** * Get the total overflow lines if any exist * * @returns The number of overflow lines, or 0.0 if no overflow occurred */ overflowLines() { return this.overflow ? this.overflow.overflowLines : 0.0; } /** * Create a string representation of the navigation result */ toString() { let result = `Target verse: ${this.verse}\n`; result += `Distance Moved: ${this.distanceMoved}\n`; result += `Remaining Distance: ${this.remainingDistance}\n`; if (this.overflow) { result += `Overflow: ${this.overflow}\n`; } if (this.endOfPage) { result += `End of page: ${this.endOfPage}\n`; } if (this.endOfSura) { result += `End of sura: ${this.endOfSura}\n`; } return result; } } exports.NavigationResult = NavigationResult;