You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import {TEXT_NODE} from '../shared/constants.js';
|
|
import {VALUE} from '../shared/symbols.js';
|
|
import {escape} from '../shared/text-escaper.js';
|
|
|
|
import {CharacterData} from './character-data.js';
|
|
|
|
/**
|
|
* @implements globalThis.Text
|
|
*/
|
|
export class Text extends CharacterData {
|
|
constructor(ownerDocument, data = '') {
|
|
super(ownerDocument, '#text', TEXT_NODE, data);
|
|
}
|
|
|
|
get wholeText() {
|
|
const text = [];
|
|
let {previousSibling, nextSibling} = this;
|
|
while (previousSibling) {
|
|
if (previousSibling.nodeType === TEXT_NODE)
|
|
text.unshift(previousSibling[VALUE]);
|
|
else
|
|
break;
|
|
previousSibling = previousSibling.previousSibling;
|
|
}
|
|
text.push(this[VALUE]);
|
|
while (nextSibling) {
|
|
if (nextSibling.nodeType === TEXT_NODE)
|
|
text.push(nextSibling[VALUE]);
|
|
else
|
|
break;
|
|
nextSibling = nextSibling.nextSibling;
|
|
}
|
|
return text.join('');
|
|
}
|
|
|
|
cloneNode() {
|
|
const {ownerDocument, [VALUE]: data} = this;
|
|
return new Text(ownerDocument, data);
|
|
}
|
|
|
|
toString() { return escape(this[VALUE]); }
|
|
}
|