diff options
Diffstat (limited to 'ext/js/comm/frame-offset-forwarder.js')
-rw-r--r-- | ext/js/comm/frame-offset-forwarder.js | 16 |
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; } |