{"version":3,"file":"useForwardProps.cjs","sources":["../../src/shared/useForwardProps.ts"],"sourcesContent":["import { type MaybeRefOrGetter, camelize, computed, getCurrentInstance, toRef } from 'vue'\n\ninterface PropOptions {\n  type?: any\n  required?: boolean\n  default?: any\n}\n\n/**\n * The `useForwardProps` function in TypeScript takes in a set of props and returns a computed value\n * that combines default props with assigned props from the current instance.\n * @param {T} props - The `props` parameter is an object that represents the props passed to a\n * component.\n * @returns computed value that combines the default props, preserved props, and assigned props.\n */\nexport function useForwardProps<T extends Record<string, any>>(props: MaybeRefOrGetter<T>) {\n  const vm = getCurrentInstance()\n  // Default value for declared props\n  const defaultProps = Object.keys(vm?.type.props ?? {}).reduce((prev, curr) => {\n    const defaultValue = (vm?.type.props[curr] as PropOptions).default\n    if (defaultValue !== undefined)\n      prev[curr as keyof T] = defaultValue\n    return prev\n  }, {} as T)\n\n  const refProps = toRef(props)\n  return computed(() => {\n    const preservedProps = {} as T\n    const assignedProps = vm?.vnode.props ?? {}\n\n    Object.keys(assignedProps).forEach((key) => {\n      preservedProps[camelize(key) as keyof T] = assignedProps[key]\n    })\n\n    // Only return value from the props parameter\n    return Object.keys({ ...defaultProps, ...preservedProps }).reduce((prev, curr) => {\n      if (refProps.value[curr] !== undefined)\n        prev[curr as keyof T] = refProps.value[curr]\n      return prev\n    }, {} as T)\n  })\n}\n"],"names":["getCurrentInstance","toRef","computed","camelize"],"mappings":";;;;AAeO,SAAS,gBAA+C,KAA4B,EAAA;AACzF,EAAA,MAAM,KAAKA,sBAAmB,EAAA;AAE9B,EAAA,MAAM,YAAe,GAAA,MAAA,CAAO,IAAK,CAAA,EAAA,EAAI,IAAK,CAAA,KAAA,IAAS,EAAE,CAAE,CAAA,MAAA,CAAO,CAAC,IAAA,EAAM,IAAS,KAAA;AAC5E,IAAA,MAAM,YAAgB,GAAA,CAAA,EAAA,EAAI,IAAK,CAAA,KAAA,CAAM,IAAI,CAAkB,EAAA,OAAA;AAC3D,IAAA,IAAI,YAAiB,KA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