var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _MutationObserver_callback, _MutationObserver_listeners, _MutationObserver_window; import DOMException from '../exception/DOMException.js'; import * as PropertySymbol from '../PropertySymbol.js'; import MutationListener from './MutationListener.js'; /** * The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. * * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver */ class MutationObserver { /** * Constructor. * * @param callback Callback. */ constructor(callback) { _MutationObserver_callback.set(this, void 0); _MutationObserver_listeners.set(this, []); _MutationObserver_window.set(this, null); __classPrivateFieldSet(this, _MutationObserver_callback, callback, "f"); } /** * Starts observing. * * @param target Target. * @param options Options. */ observe(target, options) { if (!target) { throw new DOMException(`Failed to execute 'observe' on 'MutationObserver': The first parameter "target" should be of type "Node".`); } if (!options || (!options.childList && !options.attributes && !options.characterData)) { throw new DOMException(`Failed to execute 'observe' on 'MutationObserver': The options object must set at least one of 'attributes', 'characterData', or 'childList' to true.`); } if (!__classPrivateFieldGet(this, _MutationObserver_window, "f")) { __classPrivateFieldSet(this, _MutationObserver_window, target[PropertySymbol.ownerDocument] ? target[PropertySymbol.ownerDocument][PropertySymbol.ownerWindow] : target[PropertySymbol.ownerWindow], "f"); } // Makes sure that attribute names are lower case. // TODO: Is this correct? options = Object.assign({}, options, { attributeFilter: options.attributeFilter ? options.attributeFilter.map((name) => name.toLowerCase()) : null }); /** * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe#reusing_mutationobservers */ for (const listener of __classPrivateFieldGet(this, _MutationObserver_listeners, "f")) { if (listener.target === target) { listener.options = options; return; } } const listener = new MutationListener({ window: __classPrivateFieldGet(this, _MutationObserver_window, "f"), options, callback: __classPrivateFieldGet(this, _MutationObserver_callback, "f").bind(this), observer: this, target }); __classPrivateFieldGet(this, _MutationObserver_listeners, "f").push(listener); // Stores all observers on the window object, so that they can be disconnected when the window is closed. __classPrivateFieldGet(this, _MutationObserver_window, "f")[PropertySymbol.mutationObservers].push(this); // Starts observing target node. target[PropertySymbol.observe](listener); } /** * Disconnects. */ disconnect() { if (__classPrivateFieldGet(this, _MutationObserver_listeners, "f").length === 0) { return; } const mutationObservers = __classPrivateFieldGet(this, _MutationObserver_window, "f")[PropertySymbol.mutationObservers]; const index = mutationObservers.indexOf(this); if (index !== -1) { mutationObservers.splice(index, 1); } for (const listener of __classPrivateFieldGet(this, _MutationObserver_listeners, "f")) { listener.target[PropertySymbol.unobserve](listener); listener.destroy(); } __classPrivateFieldSet(this, _MutationObserver_listeners, [], "f"); } /** * Returns a list of all matching DOM changes that have been detected but not yet processed by the observer's callback function, leaving the mutation queue empty. * * @returns Records. */ takeRecords() { let records = []; for (const listener of __classPrivateFieldGet(this, _MutationObserver_listeners, "f")) { records = records.concat(listener.takeRecords()); } return records; } } _MutationObserver_callback = new WeakMap(), _MutationObserver_listeners = new WeakMap(), _MutationObserver_window = new WeakMap(); export default MutationObserver; //# sourceMappingURL=MutationObserver.js.map