aboutsummaryrefslogtreecommitdiff
path: root/ext/js/comm/frame-offset-forwarder.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/comm/frame-offset-forwarder.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/comm/frame-offset-forwarder.js')
-rw-r--r--ext/js/comm/frame-offset-forwarder.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/js/comm/frame-offset-forwarder.js b/ext/js/comm/frame-offset-forwarder.js
index ef75f1d0..af9bd268 100644
--- a/ext/js/comm/frame-offset-forwarder.js
+++ b/ext/js/comm/frame-offset-forwarder.js
@@ -20,11 +20,19 @@ import {yomitan} from '../yomitan.js';
import {FrameAncestryHandler} from './frame-ancestry-handler.js';
export class FrameOffsetForwarder {
+ /**
+ * @param {number} frameId
+ */
constructor(frameId) {
+ /** @type {number} */
this._frameId = frameId;
+ /** @type {FrameAncestryHandler} */
this._frameAncestryHandler = new FrameAncestryHandler(frameId);
}
+ /**
+ * @returns {void}
+ */
prepare() {
this._frameAncestryHandler.prepare();
yomitan.crossFrame.registerHandlers([
@@ -32,6 +40,9 @@ export class FrameOffsetForwarder {
]);
}
+ /**
+ * @returns {Promise<?[x: number, y: number]>}
+ */
async getOffset() {
if (this._frameAncestryHandler.isRootFrame()) {
return [0, 0];
@@ -41,6 +52,7 @@ export class FrameOffsetForwarder {
const ancestorFrameIds = await this._frameAncestryHandler.getFrameAncestryInfo();
let childFrameId = this._frameId;
+ /** @type {Promise<?import('frame-offset-forwarder').ChildFrameRect>[]} */
const promises = [];
for (const frameId of ancestorFrameIds) {
promises.push(yomitan.crossFrame.invoke(frameId, 'FrameOffsetForwarder.getChildFrameRect', {frameId: childFrameId}));
@@ -64,6 +76,10 @@ export class FrameOffsetForwarder {
// Private
+ /**
+ * @param {{frameId: number}} event
+ * @returns {?import('frame-offset-forwarder').ChildFrameRect}
+ */
_onMessageGetChildFrameRect({frameId}) {
const frameElement = this._frameAncestryHandler.getChildFrameElement(frameId);
if (frameElement === null) { return null; }