Rename .js/.jsx to .ts/.tsx
This commit is contained in:
parent
257162e5b6
commit
c60d0e7392
151 changed files with 0 additions and 0 deletions
49
src/content/components/common/hint.ts
Normal file
49
src/content/components/common/hint.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import * as dom from 'shared/utils/dom';
|
||||
|
||||
const hintPosition = (element) => {
|
||||
let { left, top, right, bottom } = dom.viewportRect(element);
|
||||
|
||||
if (element.tagName !== 'AREA') {
|
||||
return { x: left, y: top };
|
||||
}
|
||||
|
||||
return {
|
||||
x: (left + right) / 2,
|
||||
y: (top + bottom) / 2,
|
||||
};
|
||||
};
|
||||
|
||||
export default class Hint {
|
||||
constructor(target, tag) {
|
||||
if (!(document.body instanceof HTMLElement)) {
|
||||
throw new TypeError('target is not an HTMLElement');
|
||||
}
|
||||
|
||||
this.target = target;
|
||||
|
||||
let doc = target.ownerDocument;
|
||||
let { x, y } = hintPosition(target);
|
||||
let { scrollX, scrollY } = window;
|
||||
|
||||
this.element = doc.createElement('span');
|
||||
this.element.className = 'vimvixen-hint';
|
||||
this.element.textContent = tag;
|
||||
this.element.style.left = x + scrollX + 'px';
|
||||
this.element.style.top = y + scrollY + 'px';
|
||||
|
||||
this.show();
|
||||
doc.body.append(this.element);
|
||||
}
|
||||
|
||||
show() {
|
||||
this.element.style.display = 'inline';
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.element.style.display = 'none';
|
||||
}
|
||||
|
||||
remove() {
|
||||
this.element.remove();
|
||||
}
|
||||
}
|
Reference in a new issue