{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../packages/hooks/use-attrs/index.ts"],"sourcesContent":["import { computed, getCurrentInstance } from 'vue'\nimport { fromPairs } from 'lodash-unified'\nimport { debugWarn } from '@element-plus/utils'\n\nimport type { ComputedRef } from 'vue'\n\ninterface Params {\n  excludeListeners?: boolean\n  excludeKeys?: ComputedRef<string[]>\n}\n\nconst DEFAULT_EXCLUDE_KEYS = ['class', 'style']\nconst LISTENER_PREFIX = /^on[A-Z]/\n\nexport const useAttrs = (\n  params: Params = {}\n): ComputedRef<Record<string, unknown>> => {\n  const { excludeListeners = false, excludeKeys } = params\n  const allExcludeKeys = computed<string[]>(() => {\n    return (excludeKeys?.value || []).concat(DEFAULT_EXCLUDE_KEYS)\n  })\n\n  const instance = getCurrentInstance()\n  if (!instance) {\n    debugWarn(\n      'use-attrs',\n      'getCurrentInstance() returned null. useAttrs() must be called at the top of a setup function'\n    )\n    return computed(() => ({}))\n  }\n\n  return computed(() =>\n    fromPairs(\n      Object.entries(instance.proxy?.$attrs!).filter(\n        ([key]) =>\n          !allExcludeKeys.value.includes(key) &&\n          !(excludeListeners && LISTENER_PREFIX.test(key))\n      )\n    )\n  )\n}\n"],"mappings":";;;;;AAWA,MAAM,uBAAuB,CAAC,SAAS,QAAQ;AAC/C,MAAM,kBAAkB;AAExB,MAAa,YACX,SAAiB,EAAE,KACsB;CACzC,MAAM,EAAE,mBAAmB,OAAO,gBAAgB;CAClD,MAAM,iBAAiB,eAAyB;AAC9C,UAAQ,aAAa,SAAS,EAAE,EAAE,OAAO,qBAAqB;GAC9D;CAEF,MAAM,WAAW,oBAAoB;AACrC,KAAI,CAAC,UAAU;AACb,YACE,aACA,+FACD;AACD,SAAO,gBAAgB,EAAE,EAAE;;AAG7B,QAAO,eACL,UACE,OAAO,QAAQ,SAAS,OAAO,OAAQ,CAAC,QACrC,CAAC,SACA,CAAC,eAAe,MAAM,SAAS,IAAI,IACnC,EAAE,oBAAoB,gBAAgB,KAAK,IAAI,EAClD,CACF,CACF"}