|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- "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 CharacterDataUtility_1 = __importDefault(require("./CharacterDataUtility"));
- const NonDocumentChildNodeUtility_1 = __importDefault(require("../child-node/NonDocumentChildNodeUtility"));
- const ChildNodeUtility_1 = __importDefault(require("../child-node/ChildNodeUtility"));
- const MutationRecord_1 = __importDefault(require("../../mutation-observer/MutationRecord"));
- const MutationTypeEnum_1 = __importDefault(require("../../mutation-observer/MutationTypeEnum"));
- /**
- * Character data base class.
- *
- * Reference:
- * https://developer.mozilla.org/en-US/docs/Web/API/CharacterData.
- */
- class CharacterData extends Node_1.default {
- /**
- * Constructor.
- *
- * @param [data] Data.
- */
- constructor(data) {
- super();
- this._data = '';
- if (data) {
- this._data = data;
- }
- }
- /**
- * Returns text content.
- *
- * @returns Text content.
- */
- get length() {
- return this._data.length;
- }
- /**
- * Returns text content.
- *
- * @returns Text content.
- */
- get data() {
- return this._data;
- }
- /**
- * Sets text content.
- *
- * @param textContent Text content.
- */
- set data(data) {
- const oldValue = this._data;
- this._data = data;
- if (this.isConnected) {
- this.ownerDocument['_cacheID']++;
- }
- // MutationObserver
- if (this._observers.length > 0) {
- for (const observer of this._observers) {
- if (observer.options.characterData) {
- const record = new MutationRecord_1.default();
- record.target = this;
- record.type = MutationTypeEnum_1.default.characterData;
- record.oldValue = observer.options.characterDataOldValue ? oldValue : null;
- observer.callback([record]);
- }
- }
- }
- }
- /**
- * Returns text content.
- *
- * @returns Text content.
- */
- get textContent() {
- return this._data;
- }
- /**
- * Sets text content.
- *
- * @param textContent Text content.
- */
- set textContent(textContent) {
- this.data = textContent;
- }
- /**
- * Returns node value.
- *
- * @returns Node value.
- */
- get nodeValue() {
- return this._data;
- }
- /**
- * Sets node value.
- *
- * @param nodeValue Node value.
- */
- set nodeValue(nodeValue) {
- this.textContent = nodeValue;
- }
- /**
- * Previous element sibling.
- *
- * @returns Element.
- */
- get previousElementSibling() {
- return NonDocumentChildNodeUtility_1.default.previousElementSibling(this);
- }
- /**
- * Next element sibling.
- *
- * @returns Element.
- */
- get nextElementSibling() {
- return NonDocumentChildNodeUtility_1.default.nextElementSibling(this);
- }
- /**
- * Appends the given DOMString to the CharacterData.data string; when this method returns, data contains the concatenated DOMString.
- *
- * @param data Data.
- */
- appendData(data) {
- CharacterDataUtility_1.default.appendData(this, data);
- }
- /**
- * Removes the specified amount of characters, starting at the specified offset, from the CharacterData.data string; when this method returns, data contains the shortened DOMString.
- *
- * @param offset Offset.
- * @param count Count.
- */
- deleteData(offset, count) {
- CharacterDataUtility_1.default.deleteData(this, offset, count);
- }
- /**
- * Inserts the specified characters, at the specified offset, in the CharacterData.data string; when this method returns, data contains the modified DOMString.
- *
- * @param offset Offset.
- * @param data Data.
- */
- insertData(offset, data) {
- CharacterDataUtility_1.default.insertData(this, offset, data);
- }
- /**
- * Replaces the specified amount of characters, starting at the specified offset, with the specified DOMString; when this method returns, data contains the modified DOMString.
- *
- * @param offset Offset.
- * @param count Count.
- * @param data Data.
- */
- replaceData(offset, count, data) {
- CharacterDataUtility_1.default.replaceData(this, offset, count, data);
- }
- /**
- * Returns a DOMString containing the part of CharacterData.data of the specified length and starting at the specified offset.
- *
- * @param offset Offset.
- * @param count Count.
- */
- substringData(offset, count) {
- return CharacterDataUtility_1.default.substringData(this, offset, count);
- }
- /**
- * Removes the object from its parent children list.
- */
- remove() {
- ChildNodeUtility_1.default.remove(this);
- }
- /**
- * The Node.replaceWith() method replaces this Node in the children list of its parent with a set of Node or DOMString objects.
- *
- * @param nodes List of Node or DOMString.
- */
- replaceWith(...nodes) {
- ChildNodeUtility_1.default.replaceWith(this, ...nodes);
- }
- /**
- * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode. DOMString objects are inserted as equivalent Text nodes.
- *
- * @param nodes List of Node or DOMString.
- */
- before(...nodes) {
- ChildNodeUtility_1.default.before(this, ...nodes);
- }
- /**
- * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode. DOMString objects are inserted as equivalent Text nodes.
- *
- * @param nodes List of Node or DOMString.
- */
- after(...nodes) {
- ChildNodeUtility_1.default.after(this, ...nodes);
- }
- /**
- * Clones a node.
- *
- * @override
- * @param [deep=false] "true" to clone deep.
- * @returns Cloned node.
- */
- cloneNode(deep = false) {
- const clone = super.cloneNode(deep);
- clone._data = this._data;
- return clone;
- }
- }
- exports.default = CharacterData;
- //# sourceMappingURL=CharacterData.js.map
|