mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Add helpful DOM commands
This commit is contained in:
parent
b49be04730
commit
238ba8013f
1 changed files with 19 additions and 7 deletions
|
@ -689,7 +689,7 @@ export function simulateClick(target: HTMLElement) {
|
|||
}
|
||||
|
||||
/** Recursively resolves an active shadow DOM element. */
|
||||
export function deepestShadowRoot(sr: ShadowRoot|null): ShadowRoot|null {
|
||||
export function deepestShadowRoot(sr: ShadowRoot | null): ShadowRoot | null {
|
||||
if (sr === null) return sr
|
||||
let shadowRoot = sr
|
||||
while (shadowRoot.activeElement.shadowRoot != null) {
|
||||
|
@ -698,3 +698,15 @@ export function deepestShadowRoot(sr: ShadowRoot|null): ShadowRoot|null {
|
|||
return shadowRoot
|
||||
}
|
||||
|
||||
export function getElementCentre(el) {
|
||||
const pos = el.getBoundingClientRect()
|
||||
return { x: 0.5 * (pos.left + pos.right), y: 0.5 * (pos.top + pos.bottom) }
|
||||
}
|
||||
|
||||
export function getAbsolutePosition(el) {
|
||||
const pos = getElementCentre(el)
|
||||
return {
|
||||
x: pos.x + (window as any).mozInnerScreenX,
|
||||
y: pos.y + (window as any).mozInnerScreenY,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue