{"version":3,"file":"index.cjs","sources":["../src/const.ts","../src/index.ts"],"sourcesContent":["export const pkgName = PKG_NAME;\nexport const pkgVersion = PKG_VERSION;\n","import classNames, { type Argument as ClassName } from 'classnames';\nimport type { CSSProperties, HTMLAttributes } from 'react';\n\nexport * from './const.js';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyObject = Record<keyof any, any>;\ntype NormalProps = {\n  className?: ClassName | undefined;\n  style?: (CSSProperties | Record<string, string | number>) | undefined;\n};\ntype NormalKeys = keyof NormalProps;\n\nexport type Props<P extends AnyObject = AnyObject, E = HTMLAttributes<HTMLElement>> =\n  // html 属性里包含 children、className、style\n  Omit<E, keyof P | NormalKeys> &\n    // 普通属性里包含 className、style\n    Omit<NormalProps, keyof P> &\n    P;\n\ntype NormalRuntimeProps = {\n  className?: string | undefined;\n  style?: CSSProperties | undefined;\n};\nexport type RuntimeProps<P extends AnyObject, D extends Partial<P>> = Omit<P, keyof D | NormalKeys> &\n  Required<Pick<P, keyof D | NormalKeys>> &\n  NormalRuntimeProps;\n\nexport default function useProps<P extends Props, D extends Partial<P>>(props: P, defaults: D): RuntimeProps<P, D> {\n  const target = Object.assign({}, props) as RuntimeProps<P, D>;\n\n  Object.keys(defaults).forEach((key) => {\n    switch (key) {\n      case 'className':\n        // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n        // @ts-ignore\n        target[key] = classNames(defaults[key], props[key]);\n        break;\n\n      case 'style':\n        // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n        // @ts-ignore\n        target[key] = Object.assign({}, defaults[key], props[key]);\n        break;\n\n      default:\n        // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n        // @ts-ignore\n        if (typeof props[key] === 'undefined') target[key] = defaults[key];\n    }\n  });\n\n  return target;\n}\n"],"names":[],"mappings":";;;AAAO,MAAM,UAAU;AAChB,MAAM,aAAa;AC2BF,SAAA,SAAgD,OAAU,UAAiC;AACjH,QAAM,SAAS,OAAO,OAAO,IAAI,KAAK;AAEtC,SAAO,KAAK,QAAQ,EAAE,QAAQ,CAAC,QAAQ;AACrC,YAAQ,KAAK;AAAA,MACX,KAAK;AAGI,eAAA,GAAG,IAAI,WAAW,SAAS,GAAG,GAAG,MAAM,GAAG,CAAC;AAClD;AAAA,MAEF,KAAK;AAGI,eAAA,GAAG,IAAI,OAAO,OAAO,CAAA,GAAI,SAAS,GAAG,GAAG,MAAM,GAAG,CAAC;AACzD;AAAA,MAEF;AAGM,YAAA,OAAO,MAAM,GAAG,MAAM;AAAoB,iBAAA,GAAG,IAAI,SAAS,GAAG;AAAA,IACrE;AAAA,EAAA,CACD;AAEM,SAAA;AACT;;;;"}