From 19077ec4e674d8edaea4240f39e7206d63b3e87a Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Thu, 19 Sep 2024 08:06:13 +0530 Subject: [PATCH] Adressed issue --- lib/commons/dom/create-grid.js | 23 ++++++++----------- lib/commons/dom/get-element-stack.js | 17 ++++++++++++-- .../dom/get-overflow-hidden-ancestors.js | 5 ++-- lib/commons/dom/get-rect-stack.js | 6 ++--- .../dom/get-visible-child-text-rects.js | 16 ++++++------- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/commons/dom/create-grid.js b/lib/commons/dom/create-grid.js index bcaa86b1..919e2773 100644 --- a/lib/commons/dom/create-grid.js +++ b/lib/commons/dom/create-grid.js @@ -14,6 +14,7 @@ const DEFAULT_LEVEL = 0.1; const FLOAT_LEVEL = 0.2; const POSITION_LEVEL = 0.3; let nodeIndex = 0; +let gridSize = constants.gridSize; /** * Setup the 2d grid and add every element to it, even elements not @@ -23,14 +24,16 @@ let nodeIndex = 0; export default function createGrid( root = document.body, rootGrid, - parentVNode = null + parentVNode = null, + ruleData = null ) { + if (ruleData && ruleData.ruleId && ruleData.gridSize) { + gridSize = ruleData.gridSize; + } + // Prevent multiple calls per run if (cache.get('gridCreated') && !parentVNode) { - if (cache.get('gridSize')) { - return cache.get('gridSize'); - } - return constants.gridSize; + return gridSize; } cache.set('gridCreated', true); @@ -114,10 +117,7 @@ export default function createGrid( node = treeWalker.nextNode(); } - if (cache.get('gridSize')) { - return cache.get('gridSize'); - } - return constants.gridSize; + return gridSize; } /** @@ -437,10 +437,7 @@ class Grid { * @returns {number} */ toGridIndex(num) { - if (cache.get('gridSize')) { - return Math.floor(num / cache.get('gridSize')); - } - return Math.floor(num / constants.gridSize); + return Math.floor(num / gridSize); } /** diff --git a/lib/commons/dom/get-element-stack.js b/lib/commons/dom/get-element-stack.js index 6aeebd4a..bdb256aa 100644 --- a/lib/commons/dom/get-element-stack.js +++ b/lib/commons/dom/get-element-stack.js @@ -9,8 +9,21 @@ import createGrid from './create-grid'; * @param {Node} node * @return {Node[]} */ -function getElementStack(node, isCoordsPassed = false, x, y) { - createGrid(); +function getElementStack( + node, + ruleId = null, + isCoordsPassed = false, + x = null, + y = null +) { + if (ruleId === 'zoom-text-overlap-viewport') { + createGrid(document.body, null, null, { + ruleId, + gridSize: 500 + }); + } else { + createGrid(); + } const vNode = getNodeFromTree(node); const grid = vNode._grid; diff --git a/lib/commons/dom/get-overflow-hidden-ancestors.js b/lib/commons/dom/get-overflow-hidden-ancestors.js index 78c7e262..a3b7ee11 100644 --- a/lib/commons/dom/get-overflow-hidden-ancestors.js +++ b/lib/commons/dom/get-overflow-hidden-ancestors.js @@ -1,4 +1,3 @@ -import cache from '../../core/base/cache'; import memoize from '../../core/utils/memoize'; /** @@ -9,7 +8,7 @@ import memoize from '../../core/utils/memoize'; * @returns {VirtualNode[]} */ const getOverflowHiddenAncestors = memoize( - function getOverflowHiddenAncestorsMemoized(vNode) { + function getOverflowHiddenAncestorsMemoized(vNode, ruleId = null) { const ancestors = []; if (!vNode) { @@ -18,7 +17,7 @@ const getOverflowHiddenAncestors = memoize( const overflow = vNode.getComputedStylePropertyValue('overflow'); - if (cache.get('200%ZoomRule')) { + if (ruleId && ruleId === 'zoom-text-overlap-viewport') { if ( overflow.includes('hidden') || overflow.includes('clip') || diff --git a/lib/commons/dom/get-rect-stack.js b/lib/commons/dom/get-rect-stack.js index e0a3c564..7af8b9eb 100644 --- a/lib/commons/dom/get-rect-stack.js +++ b/lib/commons/dom/get-rect-stack.js @@ -5,9 +5,9 @@ export function getRectStack( grid, rect, recursed = false, - isCoordsPassed, - x, - y + isCoordsPassed = false, + x = null, + y = null ) { const center = getRectCenter(rect); const gridCell = grid.getCellFromPoint(center) || []; diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index cd778b74..9204d29d 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -2,7 +2,6 @@ import { getNodeFromTree, memoize } from '../../core/utils'; import { sanitize } from '../text'; import { getIntersectionRect, getRectCenter, isPointInRect } from '../math'; import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors'; -import cache from '../../core/base/cache'; /** * Get the visible text client rects of a node. @@ -12,11 +11,11 @@ import cache from '../../core/base/cache'; * @param {Element} node */ const getVisibleChildTextRects = memoize( - function getVisibleChildTextRectsMemoized(node) { + function getVisibleChildTextRectsMemoized(node, ruleId = null) { const vNode = getNodeFromTree(node); const nodeRect = vNode.boundingClientRect; const clientRects = []; - const overflowHiddenNodes = getOverflowHiddenAncestors(vNode); + const overflowHiddenNodes = getOverflowHiddenAncestors(vNode, ruleId); node.childNodes.forEach(textNode => { if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') { @@ -24,17 +23,18 @@ const getVisibleChildTextRects = memoize( } const contentRects = getContentRects(textNode); - if ( - isOutsideNodeBounds(contentRects, nodeRect) && - !cache.get('200%ZoomRule') - ) { + if (isOutsideNodeBounds(contentRects, nodeRect) && !ruleId) { return; } clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); }); - if (clientRects.length <= 0 && cache.get('200%ZoomRule')) { + if ( + clientRects.length <= 0 && + ruleId && + ruleId === 'zoom-text-overlap-viewport' + ) { return []; } /**