flappa-doormal 2.11.3 → 2.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1512,20 +1512,6 @@ const hasExcludedPageInRange = (excludeSet, pageIds, fromIdx, toIdx) => {
1512
1512
  return false;
1513
1513
  };
1514
1514
  /**
1515
- * Finds the position of the next page content within remaining content.
1516
- * Returns -1 if not found.
1517
- *
1518
- * @param remainingContent - Content to search in
1519
- * @param nextPageData - Normalized data for the next page
1520
- * @returns Position of next page content, or -1 if not found
1521
- */
1522
- const findNextPagePosition = (remainingContent, nextPageData) => {
1523
- const searchPrefix = nextPageData.content.trim().slice(0, Math.min(30, nextPageData.length));
1524
- if (searchPrefix.length === 0) return -1;
1525
- const pos = remainingContent.indexOf(searchPrefix);
1526
- return pos > 0 ? pos : -1;
1527
- };
1528
- /**
1529
1515
  * Finds matches within a window and returns the selected position based on preference.
1530
1516
  *
1531
1517
  * @param windowContent - Content to search
@@ -1553,16 +1539,13 @@ const findPatternBreakPosition = (windowContent, regex, prefer) => {
1553
1539
  * Returns break position or -1 if no valid position found.
1554
1540
  */
1555
1541
  const handlePageBoundaryBreak = (remainingContent, windowEndIdx, windowEndPosition, toIdx, pageIds, normalizedPages) => {
1556
- const nextPageIdx = windowEndIdx + 1;
1557
- if (nextPageIdx <= toIdx) {
1558
- const nextPageData = normalizedPages.get(pageIds[nextPageIdx]);
1559
- if (nextPageData) {
1560
- const pos = findNextPagePosition(remainingContent, nextPageData);
1561
- const tolerance = Math.max(2e3, windowEndPosition * .5);
1562
- if (pos > 0 && Math.abs(pos - windowEndPosition) <= tolerance) return Math.min(pos, windowEndPosition, remainingContent.length);
1563
- }
1542
+ const targetPos = Math.min(windowEndPosition, remainingContent.length);
1543
+ if (targetPos < remainingContent.length) {
1544
+ const safePos = findSafeBreakPosition(remainingContent, targetPos);
1545
+ if (safePos !== -1) return safePos;
1546
+ return adjustForSurrogate(remainingContent, targetPos);
1564
1547
  }
1565
- return Math.min(windowEndPosition, remainingContent.length);
1548
+ return targetPos;
1566
1549
  };
1567
1550
  /**
1568
1551
  * Tries to find a break position within the current window using breakpoint patterns.
@@ -1766,7 +1749,7 @@ const findBreakOffsetForWindow = (remainingContent, currentFromIdx, windowEndIdx
1766
1749
  breakpointIndex: patternMatch.breakpointIndex,
1767
1750
  breakpointRule: patternMatch.rule
1768
1751
  };
1769
- if (maxContentLength && windowEndPosition === maxContentLength) {
1752
+ if (windowEndPosition < remainingContent.length) {
1770
1753
  const safeOffset = findSafeBreakPosition(remainingContent, windowEndPosition);
1771
1754
  if (safeOffset !== -1) return { breakOffset: safeOffset };
1772
1755
  return { breakOffset: adjustForSurrogate(remainingContent, windowEndPosition) };