{"version":3,"sources":["../src/utils/merge-props.ts","../src/sv.ts"],"names":["mergeProps","defaultProps","props","omitKeys","merged","k","sv","config","base","variants","compoundVariants","defaultVariants","result","mergedProps","key","styleValue","compound","matches","value","propValue","sv_default"],"mappings":"sEAAO,SAASA,EACdC,CAAAA,CACAC,CAAAA,CACAC,EACyB,CACzB,IAAMC,EAAkC,CAAE,GAAGH,CAAa,CAAA,CAE1D,GAAIC,CAAAA,CACF,IAAA,IAAWG,KAAKH,CAAAA,CACVA,CAAAA,CAAMG,CAAC,CAAA,GAAM,MAAA,GAAc,CAACF,CAAAA,EAAY,CAACA,CAAAA,CAAS,QAAA,CAASE,CAAC,CAAA,CAAA,GAC9DD,CAAAA,CAAOC,CAAC,CAAA,CAAIH,CAAAA,CAAMG,CAAC,CAAA,CAAA,CAKzB,OAAOD,CACT,KCoCaE,CAAAA,CAA6BC,CAAAA,EAAW,CACnD,GAAM,CAAE,IAAA,CAAAC,CAAAA,CAAM,SAAAC,CAAAA,CAAU,gBAAA,CAAAC,EAAkB,eAAA,CAAAC,CAAgB,EAAIJ,CAAAA,CAE9D,OAAKE,CAAAA,CAIGP,CAAAA,EAAU,CAChB,IAAMU,CAAAA,CAAwB,CAAE,GAAGJ,CAAK,EAElCK,CAAAA,CAAcb,CAAAA,CAAWW,CAAAA,CAAiBT,CAAAA,CAAO,CAAC,OAAO,CAAC,EAEhE,IAAA,IAAWY,CAAAA,IAAOD,EAAa,CAC7B,IAAME,CAAAA,CAAaN,CAAAA,CAASK,CAAG,CAAA,GAAID,CAAAA,CAAYC,CAAG,CAAW,CAAA,CACzDC,GACF,MAAA,CAAO,MAAA,CAAOH,CAAAA,CAAQG,CAAU,EAEpC,CAEA,GAAIL,EACF,IAAA,IAAS,CAAA,CAAI,EAAG,CAAA,CAAIA,CAAAA,CAAiB,MAAA,CAAQ,CAAA,EAAA,CAAK,CAChD,IAAMM,CAAAA,CAAWN,EAAiB,CAAC,CAAA,CAC/BO,EAAU,IAAA,CACd,IAAA,IAAWH,CAAAA,IAAOE,CAAAA,CAAU,CAC1B,GAAIF,CAAAA,GAAQ,QAAS,SACrB,IAAMI,EAAQF,CAAAA,CAASF,CAA4B,CAAA,CAC7CK,CAAAA,CAAYN,EAAYC,CAAG,CAAA,CACjC,GAAI,KAAA,CAAM,OAAA,CAAQI,CAAK,CAAA,CAAI,CAACA,CAAAA,CAAM,QAAA,CAASC,CAAS,CAAA,CAAID,CAAAA,GAAUC,EAAW,CAC3EF,CAAAA,CAAU,MACV,KACF,CACF,CACIA,CAAAA,EAAWD,EAAS,KAAA,EACtB,MAAA,CAAO,OAAOJ,CAAAA,CAAQI,CAAAA,CAAS,KAAK,EAExC,CAGF,OAAId,CAAAA,EAAO,OACT,MAAA,CAAO,MAAA,CAAOU,EAAQV,CAAAA,CAAM,KAAK,EAG5BU,CACT,CAAA,CAvCUV,CAAAA,GAAW,CAAE,GAAGM,CAAAA,CAAM,GAAGN,GAAO,KAAM,CAAA,CAwClD,EAEOkB,CAAAA,CAAQd","file":"sv.cjs","sourcesContent":["export function mergeProps<T extends Record<string, unknown>, P extends Record<string, unknown>>(\n  defaultProps: T | undefined,\n  props: P | undefined,\n  omitKeys?: (keyof P)[]\n): Record<string, unknown> {\n  const merged: Record<string, unknown> = { ...defaultProps }\n\n  if (props) {\n    for (const k in props) {\n      if (props[k] !== undefined && (!omitKeys || !omitKeys.includes(k))) {\n        merged[k] = props[k]\n      }\n    }\n  }\n\n  return merged\n}\n","import { CssProperties, ObjectKeyArrayPicker, ObjectKeyPicker } from './utils/types'\nimport { mergeProps } from './utils/merge-props'\n\nexport type StyleVariantRecord = Record<string, Record<string, CssProperties>>\n\nexport type StyleVariantExtendProps = { style: CssProperties }\n\nexport interface StyleVariantDefinition<T extends StyleVariantRecord | undefined> {\n  base?: CssProperties\n  variants?: T\n  compoundVariants?: (ObjectKeyArrayPicker<T> & StyleVariantExtendProps)[]\n  defaultVariants?: ObjectKeyPicker<T>\n}\n\nexport type StyleVariantFnProps<T extends StyleVariantRecord | undefined> = T extends undefined\n  ? Partial<StyleVariantExtendProps>\n  : ObjectKeyPicker<T> & Partial<StyleVariantExtendProps>\n\nexport type StyleVariantFn<T extends StyleVariantRecord | undefined> = (props?: StyleVariantFnProps<T>) => CssProperties\n\nexport type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(\n  config: StyleVariantDefinition<T>\n) => StyleVariantFn<T>\n\n/**\n * Creates a style variant function based on the provided configuration.\n *\n * @template T - The type of the style variant record.\n * @param {StyleVariantDefinition<T>} config - The configuration object for style variants.\n * @returns {StyleVariantFn<T>} A function that takes props and returns the computed CSS properties.\n *\n * @example\n * ```typescript\n *\n * const makeStyle = sv({\n *   base: { color: 'black' },\n *   variants: {\n *     size: {\n *       small: { fontSize: '12px' },\n *       large: { fontSize: '24px' }\n *     }\n *   },\n *   compoundVariants: [\n *     { size: 'large', style: { fontWeight: 'bold' } }\n *   ],\n *   defaultVariants: { size: 'small' }\n * });\n *\n * const style = makeStyle({ size: 'large' });\n * // style = { color: 'black', fontSize: '24px', fontWeight: 'bold' }\n * ```\n */\nexport const sv: StyleVariantCreatorFn = (config) => {\n  const { base, variants, compoundVariants, defaultVariants } = config\n\n  if (!variants) {\n    return (props) => ({ ...base, ...props?.style })\n  }\n\n  return (props) => {\n    const result: CssProperties = { ...base }\n\n    const mergedProps = mergeProps(defaultVariants, props, ['style'])\n\n    for (const key in mergedProps) {\n      const styleValue = variants[key]?.[mergedProps[key] as string]\n      if (styleValue) {\n        Object.assign(result, styleValue)\n      }\n    }\n\n    if (compoundVariants) {\n      for (let i = 0; i < compoundVariants.length; i++) {\n        const compound = compoundVariants[i]\n        let matches = true\n        for (const key in compound) {\n          if (key === 'style') continue\n          const value = compound[key as keyof typeof compound]\n          const propValue = mergedProps[key]\n          if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n            matches = false\n            break\n          }\n        }\n        if (matches && compound.style) {\n          Object.assign(result, compound.style)\n        }\n      }\n    }\n\n    if (props?.style) {\n      Object.assign(result, props.style)\n    }\n\n    return result\n  }\n}\n\nexport default sv\n"]}