1 |
- {"version":3,"file":"bindProps.mjs","names":["eventName","isOn","handlers","WeakMap","bindProps","el","props","Object","keys","forEach","k","name","handler","get","v","n","fn","removeEventListener","delete","some","addEventListener","_handler","Set","add","has","set","removeAttribute","setAttribute","unbindProps"],"sources":["../../src/util/bindProps.ts"],"sourcesContent":["// Utilities\nimport { eventName, isOn } from '@/util/helpers'\n\nconst handlers = new WeakMap<HTMLElement, Set<[string, () => void]>>()\n\nexport function bindProps (el: HTMLElement, props: Record<string, any>) {\n Object.keys(props).forEach(k => {\n if (isOn(k)) {\n const name = eventName(k)\n const handler = handlers.get(el)\n if (props[k] == null) {\n handler?.forEach(v => {\n const [n, fn] = v\n if (n === name) {\n el.removeEventListener(name, fn)\n handler.delete(v)\n }\n })\n } else if (!handler || ![...handler]?.some(v => v[0] === name && v[1] === props[k])) {\n el.addEventListener(name, props[k])\n const _handler = handler || new Set()\n _handler.add([name, props[k]])\n if (!handlers.has(el)) handlers.set(el, _handler)\n }\n } else {\n if (props[k] == null) {\n el.removeAttribute(k)\n } else {\n el.setAttribute(k, props[k])\n }\n }\n })\n}\n\nexport function unbindProps (el: HTMLElement, props: Record<string, any>) {\n Object.keys(props).forEach(k => {\n if (isOn(k)) {\n const name = eventName(k)\n const handler = handlers.get(el)\n handler?.forEach(v => {\n const [n, fn] = v\n if (n === name) {\n el.removeEventListener(name, fn)\n handler.delete(v)\n }\n })\n } else {\n el.removeAttribute(k)\n }\n })\n}\n"],"mappings":"AAAA;AAAA,SACSA,SAAS,EAAEC,IAAI;AAExB,MAAMC,QAAQ,GAAG,IAAIC,OAAO,EAA0C;AAEtE,OAAO,SAASC,SAASA,CAAEC,EAAe,EAAEC,KAA0B,EAAE;EACtEC,MAAM,CAACC,IAAI,CAACF,KAAK,CAAC,CAACG,OAAO,CAACC,CAAC,IAAI;IAC9B,IAAIT,IAAI,CAACS,CAAC,CAAC,EAAE;MACX,MAAMC,IAAI,GAAGX,SAAS,CAACU,CAAC,CAAC;MACzB,MAAME,OA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