Skip to content

Commit a4f66c5

Browse files
author
Sebi Nemeth
committed
fix attempt
1 parent c188016 commit a4f66c5

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

dist/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,20 @@ class LiveTranslatorManager {
262262
}
263263
if (badges.length) {
264264
let position = { top: 0, left: 0 };
265-
if (node instanceof Text) {
266-
const clientRect = getBoundingClientRect(node);
267-
position.top = clientRect.top + window.scrollY;
268-
position.left = clientRect.left + window.screenX;
265+
try {
266+
if (node instanceof Text) {
267+
const clientRect = getBoundingClientRect(node);
268+
position.top = clientRect.top + window.scrollY;
269+
position.left = clientRect.left + window.screenX;
270+
}
271+
else {
272+
const clientRect = node.getClientRects()[0];
273+
position.top = clientRect.top + clientRect.height - 10 + window.scrollY;
274+
position.left = clientRect.left + window.screenX;
275+
}
269276
}
270-
else {
271-
const clientRect = node.getClientRects()[0];
272-
position.top = clientRect.top + clientRect.height - 10 + window.scrollY;
273-
position.left = clientRect.left + window.screenX;
277+
catch (error) {
278+
console.error(error, node, node.tagName);
274279
}
275280
const container = document.createElement('span');
276281
container.classList.add('live-translator-badge-container');

src/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,19 @@ class LiveTranslatorManager {
308308

309309
if (badges.length) {
310310
let position = { top: 0, left: 0}
311-
if (node instanceof Text) {
312-
const clientRect = getBoundingClientRect(node)
313-
position.top = clientRect.top + window.scrollY
314-
position.left = clientRect.left + window.screenX
315-
} else {
316-
const clientRect = node.getClientRects()[0]
317-
position.top = clientRect.top + clientRect.height - 10 + window.scrollY
318-
position.left = clientRect.left + window.screenX
311+
try {
312+
if (node instanceof Text) {
313+
const clientRect = getBoundingClientRect(node)
314+
position.top = clientRect.top + window.scrollY
315+
position.left = clientRect.left + window.screenX
316+
} else {
317+
const clientRect = node.getClientRects()[0]
318+
position.top = clientRect.top + clientRect.height - 10 + window.scrollY
319+
position.left = clientRect.left + window.screenX
320+
}
321+
} catch (error) {
322+
console.error(error, node, node.tagName);
323+
319324
}
320325
const container = document.createElement('span')
321326
container.classList.add('live-translator-badge-container')

0 commit comments

Comments
 (0)