@zag-js/mutation-observer
Version:
## Installation
1 lines • 1.64 kB
Source Map (JSON)
{"version":3,"sources":["../src/observe-attributes.ts","../src/observe-children.ts"],"sourcesContent":["export type ObserveAttributesCallback = (record: MutationRecord) => void\n\nexport function observeAttributes(node: HTMLElement | null, attributes: string[], fn: ObserveAttributesCallback) {\n if (!node) return\n\n const win = node.ownerDocument.defaultView || window\n\n const obs = new win.MutationObserver((changes) => {\n for (const change of changes) {\n if (change.type === \"attributes\" && change.attributeName && attributes.includes(change.attributeName)) {\n fn(change)\n }\n }\n })\n\n obs.observe(node, { attributes: true, attributeFilter: attributes })\n\n return () => obs.disconnect()\n}\n","export function observeChildren(node: HTMLElement | null, fn: (v: MutationRecord[]) => void) {\n if (!node) return\n\n const win = node.ownerDocument.defaultView || window\n\n const obs = new win.MutationObserver(fn)\n obs.observe(node, { childList: true, subtree: true })\n\n return () => obs.disconnect()\n}\n"],"mappings":";AAEO,SAAS,kBAAkB,MAA0B,YAAsB,IAA+B;AAC/G,MAAI,CAAC;AAAM;AAEX,QAAM,MAAM,KAAK,cAAc,eAAe;AAE9C,QAAM,MAAM,IAAI,IAAI,iBAAiB,CAAC,YAAY;AAChD,eAAW,UAAU,SAAS;AAC5B,UAAI,OAAO,SAAS,gBAAgB,OAAO,iBAAiB,WAAW,SAAS,OAAO,aAAa,GAAG;AACrG,WAAG,MAAM;AAAA,MACX;AAAA,IACF;AAAA,EACF,CAAC;AAED,MAAI,QAAQ,MAAM,EAAE,YAAY,MAAM,iBAAiB,WAAW,CAAC;AAEnE,SAAO,MAAM,IAAI,WAAW;AAC9B;;;AClBO,SAAS,gBAAgB,MAA0B,IAAmC;AAC3F,MAAI,CAAC;AAAM;AAEX,QAAM,MAAM,KAAK,cAAc,eAAe;AAE9C,QAAM,MAAM,IAAI,IAAI,iBAAiB,EAAE;AACvC,MAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,SAAS,KAAK,CAAC;AAEpD,SAAO,MAAM,IAAI,WAAW;AAC9B;","names":[]}