|
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- const Node_1 = __importDefault(require("../node/Node"));
- const CharacterData_1 = __importDefault(require("../character-data/CharacterData"));
- const DOMException_1 = __importDefault(require("../../exception/DOMException"));
- const DOMExceptionNameEnum_1 = __importDefault(require("../../exception/DOMExceptionNameEnum"));
- /**
- * Text node.
- */
- class Text extends CharacterData_1.default {
- constructor() {
- super(...arguments);
- this.nodeType = Node_1.default.TEXT_NODE;
- }
- /**
- * Node name.
- *
- * @returns Node name.
- */
- get nodeName() {
- return '#text';
- }
- /**
- * Breaks the Text node into two nodes at the specified offset, keeping both nodes in the tree as siblings.
- *
- * @see https://dom.spec.whatwg.org/#dom-text-splittext
- * @see https://dom.spec.whatwg.org/#dom-text-splittext
- * @param offset Offset.
- * @returns New text node.
- */
- splitText(offset) {
- const length = this._data.length;
- if (offset > length) {
- new DOMException_1.default('The index is not in the allowed range.', DOMExceptionNameEnum_1.default.indexSizeError);
- }
- const count = length - offset;
- const newData = this.substringData(offset, count);
- const newNode = this.ownerDocument.createTextNode(newData);
- if (this.parentNode !== null) {
- this.parentNode.insertBefore(newNode, this.nextSibling);
- }
- this.replaceData(offset, count, '');
- return newNode;
- }
- /**
- * Converts to string.
- *
- * @returns String.
- */
- toString() {
- return '[object Text]';
- }
- /**
- * Clones a node.
- *
- * @override
- * @param [deep=false] "true" to clone deep.
- * @returns Cloned node.
- */
- cloneNode(deep = false) {
- return super.cloneNode(deep);
- }
- }
- exports.default = Text;
- //# sourceMappingURL=Text.js.map
|