Skip to content

Commit

Permalink
Adressed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Utkarsh Chaudhary committed Sep 19, 2024
1 parent 9fa53cb commit 19077ec
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
23 changes: 10 additions & 13 deletions lib/commons/dom/create-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -114,10 +117,7 @@ export default function createGrid(
node = treeWalker.nextNode();
}

if (cache.get('gridSize')) {
return cache.get('gridSize');
}
return constants.gridSize;
return gridSize;
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions lib/commons/dom/get-element-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions lib/commons/dom/get-overflow-hidden-ancestors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cache from '../../core/base/cache';
import memoize from '../../core/utils/memoize';

/**
Expand All @@ -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) {
Expand All @@ -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') ||
Expand Down
6 changes: 3 additions & 3 deletions lib/commons/dom/get-rect-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) || [];
Expand Down
16 changes: 8 additions & 8 deletions lib/commons/dom/get-visible-child-text-rects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -12,29 +11,30 @@ 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) === '') {
return;
}

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 [];
}
/**
Expand Down

0 comments on commit 19077ec

Please sign in to comment.