aboutsummaryrefslogtreecommitdiff
path: root/ext/js/dom/text-source-element.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/dom/text-source-element.js')
-rw-r--r--ext/js/dom/text-source-element.js41
1 files changed, 31 insertions, 10 deletions
diff --git a/ext/js/dom/text-source-element.js b/ext/js/dom/text-source-element.js
index 95534975..fbe89a61 100644
--- a/ext/js/dom/text-source-element.js
+++ b/ext/js/dom/text-source-element.js
@@ -33,16 +33,21 @@ export class TextSourceElement {
* @param {number} endOffset The text end offset position within the full content.
*/
constructor(element, fullContent, startOffset, endOffset) {
+ /** @type {Element} */
this._element = element;
+ /** @type {string} */
this._fullContent = fullContent;
+ /** @type {number} */
this._startOffset = startOffset;
+ /** @type {number} */
this._endOffset = endOffset;
+ /** @type {string} */
this._content = this._fullContent.substring(this._startOffset, this._endOffset);
}
/**
* Gets the type name of this instance.
- * @type {string}
+ * @type {'element'}
*/
get type() {
return 'element';
@@ -147,7 +152,7 @@ export class TextSourceElement {
/**
* Gets writing mode that is used for this element.
* See: https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode.
- * @returns {string} The rects.
+ * @returns {import('document-util').NormalizedWritingMode} The writing mode.
*/
getWritingMode() {
return 'horizontal-tb';
@@ -206,23 +211,39 @@ export class TextSourceElement {
* @returns {string} The content string.
*/
static _getElementContent(element) {
- let content;
+ let content = '';
switch (element.nodeName.toUpperCase()) {
case 'BUTTON':
- content = element.textContent;
+ {
+ const {textContent} = /** @type {HTMLButtonElement} */ (element);
+ if (textContent !== null) {
+ content = textContent;
+ }
+ }
break;
case 'IMG':
- content = element.getAttribute('alt') || '';
+ {
+ const alt = /** @type {HTMLImageElement} */ (element).getAttribute('alt');
+ if (typeof alt === 'string') {
+ content = alt;
+ }
+ }
break;
case 'SELECT':
{
- const {selectedIndex, options} = element;
- const option = (selectedIndex >= 0 && selectedIndex < options.length ? options[selectedIndex] : null);
- content = (option !== null ? option.textContent : '');
+ const {selectedIndex, options} = /** @type {HTMLSelectElement} */ (element);
+ if (selectedIndex >= 0 && selectedIndex < options.length) {
+ const {textContent} = options[selectedIndex];
+ if (textContent !== null) {
+ content = textContent;
+ }
+ }
}
break;
- default:
- content = `${element.value}`;
+ case 'INPUT':
+ {
+ content = /** @type {HTMLInputElement} */ (element).value;
+ }
break;
}