Types src/content
This commit is contained in:
parent
992b3ac65d
commit
d01db82c0d
62 changed files with 1411 additions and 468 deletions
|
@ -1,6 +1,11 @@
|
|||
import * as dom from 'shared/utils/dom';
|
||||
import * as dom from '../../../shared/utils/dom';
|
||||
|
||||
const hintPosition = (element) => {
|
||||
interface Point {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
const hintPosition = (element: Element): Point => {
|
||||
let { left, top, right, bottom } = dom.viewportRect(element);
|
||||
|
||||
if (element.tagName !== 'AREA') {
|
||||
|
@ -14,17 +19,21 @@ const hintPosition = (element) => {
|
|||
};
|
||||
|
||||
export default class Hint {
|
||||
constructor(target, tag) {
|
||||
if (!(document.body instanceof HTMLElement)) {
|
||||
throw new TypeError('target is not an HTMLElement');
|
||||
private target: HTMLElement;
|
||||
|
||||
private element: HTMLElement;
|
||||
|
||||
constructor(target: HTMLElement, tag: string) {
|
||||
let doc = target.ownerDocument;
|
||||
if (doc === null) {
|
||||
throw new TypeError('ownerDocument is null');
|
||||
}
|
||||
|
||||
this.target = target;
|
||||
|
||||
let doc = target.ownerDocument;
|
||||
let { x, y } = hintPosition(target);
|
||||
let { scrollX, scrollY } = window;
|
||||
|
||||
this.target = target;
|
||||
|
||||
this.element = doc.createElement('span');
|
||||
this.element.className = 'vimvixen-hint';
|
||||
this.element.textContent = tag;
|
||||
|
@ -35,15 +44,19 @@ export default class Hint {
|
|||
doc.body.append(this.element);
|
||||
}
|
||||
|
||||
show() {
|
||||
show(): void {
|
||||
this.element.style.display = 'inline';
|
||||
}
|
||||
|
||||
hide() {
|
||||
hide(): void {
|
||||
this.element.style.display = 'none';
|
||||
}
|
||||
|
||||
remove() {
|
||||
remove(): void {
|
||||
this.element.remove();
|
||||
}
|
||||
|
||||
getTarget(): HTMLElement {
|
||||
return this.target;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue