{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-attrs/index.ts"],"sourcesContent":["import { getCurrentInstance, computed } from 'vue'\r\nimport fromPairs from 'lodash/fromPairs'\r\nimport { debugWarn } from '@sgui-plus/utils/error'\r\n\r\nimport type { ComputedRef } from 'vue'\r\n\r\ninterface Params {\r\n  excludeListeners?: boolean\r\n  excludeKeys?: string[]\r\n}\r\n\r\nconst DEFAULT_EXCLUDE_KEYS = ['class', 'style']\r\nconst LISTENER_PREFIX = /^on[A-Z]/\r\n\r\nexport const useAttrs = (\r\n  params: Params = {}\r\n): ComputedRef<Record<string, unknown>> => {\r\n  const { excludeListeners = false, excludeKeys = [] } = params\r\n  const allExcludeKeys = excludeKeys.concat(DEFAULT_EXCLUDE_KEYS)\r\n\r\n  const instance = getCurrentInstance()\r\n  if (!instance) {\r\n    debugWarn(\r\n      'use-attrs',\r\n      'getCurrentInstance() returned null. useAttrs() must be called at the top of a setup function'\r\n    )\r\n    return computed(() => ({}))\r\n  }\r\n\r\n  return computed(() =>\r\n    fromPairs(\r\n      Object.entries(instance.proxy?.$attrs!).filter(\r\n        ([key]) =>\r\n          !allExcludeKeys.includes(key) &&\r\n          !(excludeListeners && LISTENER_PREFIX.test(key))\r\n      )\r\n    )\r\n  )\r\n}\r\n"],"names":[],"mappings":";;;;AAGA,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAChD,MAAM,eAAe,GAAG,UAAU,CAAC;AACvB,MAAC,QAAQ,GAAG,CAAC,MAAM,GAAG,EAAE,KAAK;AACzC,EAAE,MAAM,EAAE,gBAAgB,GAAG,KAAK,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;AAChE,EAAE,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAClE,EAAE,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;AACxC,EAAE,IAAI,CAAC,QAAQ,EAAE;AACjB,IAAI,SAAS,CAAC,WAAW,EAAE,8FAA8F,CAAC,CAAC;AAC3H,IAAI,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAChC,GAAG;AACH,EAAE,OAAO,QAAQ,CAAC,MAAM;AACxB,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,OAAO,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,gBAAgB,IAAI,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9L,GAAG,CAAC,CAAC;AACL;;;;"}