'use strict'; var solidJs = require('solid-js'); var utils = require('@solid-primitives/utils'); // src/index.ts function createMutationObserver(initial, b, c) { let defaultOptions, callback; const isSupported = typeof window !== "undefined" && "MutationObserver" in window; if (typeof b === "function") { defaultOptions = {}; callback = b; } else { defaultOptions = b; callback = c; } const instance = isSupported ? new MutationObserver(callback) : void 0; const add = (el, options) => instance?.observe(el, utils.access(options) ?? defaultOptions); const start = () => { utils.asArray(utils.access(initial)).forEach((item) => { item instanceof Node ? add(item, defaultOptions) : add(item[0], item[1]); }); }; const stop = () => instance?.disconnect(); solidJs.onMount(start); solidJs.onCleanup(stop); return [ add, { start, stop, instance, isSupported } ]; } exports.mutationObserver = (target, props) => { const [config, cb] = props(); const [add] = createMutationObserver([], cb); add(target, config); }; exports.createMutationObserver = createMutationObserver;