{"version":3,"sources":["src/utils/descendants-observer.ts"],"names":["DescendantsObserver","[object Object]","nodeName","func","this","addedNodes","nodeTreatment","mutationObserver","MutationObserver","observerCallback","bind","target","options","childList","observe","disconnect","nodeDescendants","forEach","descendant","type","length","node","toLowerCase","push"],"mappings":"MAAaA,EAWXC,YAAYC,EAAkBC,GAC5BC,KAAKC,WAAa,GAElBD,KAAKF,SAAWA,EAChBE,KAAKE,cAAgBH,EAErBC,KAAKG,iBAAmB,IAAIC,iBAAiBJ,KAAKK,iBAAiBC,KAAKN,OAQ1EH,QAAQU,EAAcC,GACpB,IAAKA,EAAQC,UAAW,CACtBD,EAAQC,UAAY,KAEtBT,KAAKG,iBAAiBO,QAAQH,EAAQC,GAMxCX,aACEG,KAAKG,iBAAiBQ,aAMhBd,iBAAiBe,GACvBA,EAAgBC,SAASC,IACvB,GAAIA,EAAWC,OAAS,aAAeD,EAAWb,WAAWe,OAAQ,CACnEF,EAAWb,WAAWY,SAASI,IAC7B,GAAIA,EAAKnB,SAASoB,gBAAkBlB,KAAKF,SAAU,CACjDE,KAAKC,WAAWkB,KAAKF,WAM7BjB,KAAKE,cAAcF,KAAKC","sourcesContent":["export class DescendantsObserver {\n addedNodes: Array;\n nodeName: string;\n nodeTreatment: (array: Array) => void;\n mutationObserver: MutationObserver;\n\n /**\n * Creates the Mutation Observer that observes a NodeName and aplies the function (func) on them.\n * @param nodeName Node name reference that the observer is going to collect\n * @param func Function that is going to be applied on the added nodes\n */\n constructor(nodeName: string, func: (array: Array) => void) {\n this.addedNodes = [];\n\n this.nodeName = nodeName;\n this.nodeTreatment = func;\n\n this.mutationObserver = new MutationObserver(this.observerCallback.bind(this));\n }\n\n /**\n * Sets the Mutation Observer to observe a specific Node with the options given.\n * @param target A DOM Node to watch for changes\n * @param options An object providing options that describe which DOM mutations should be reported to mutationObserver's callback\n */\n observe(target: Node, options: MutationObserverInit): void {\n if (!options.childList) {\n options.childList = true;\n }\n this.mutationObserver.observe(target, options);\n }\n\n /**\n * Disconnect's the Mutation Observer\n */\n disconnect(): void {\n this.mutationObserver.disconnect();\n }\n\n /**\n * Mutation observer callback function\n */\n private observerCallback(nodeDescendants: Array) {\n nodeDescendants.forEach((descendant) => {\n if (descendant.type === 'childList' && descendant.addedNodes.length) {\n descendant.addedNodes.forEach((node) => {\n if (node.nodeName.toLowerCase() === this.nodeName) {\n this.addedNodes.push(node);\n }\n });\n }\n });\n\n this.nodeTreatment(this.addedNodes);\n }\n}\n"]}