{"version":3,"file":"runtime.mjs","sources":["../../../../../../packages/utils/vue/props/runtime.ts"],"sourcesContent":["import { warn } from 'vue'\nimport { fromPairs } from 'lodash-unified'\nimport { isObject } from '../../types'\nimport { hasOwn } from '../../objects'\n\nimport type { PropType } from 'vue'\nimport type {\n  EpProp,\n  EpPropConvert,\n  EpPropFinalized,\n  EpPropInput,\n  EpPropMergeType,\n  IfEpProp,\n  IfNativePropType,\n  NativePropType,\n} from './types'\n\nexport const epPropKey = '__epPropKey'\n\nexport const definePropType = <T>(val: any): PropType<T> => val\n\nexport const isEpProp = (val: unknown): val is EpProp<any, any, any> =>\n  isObject(val) && !!(val as any)[epPropKey]\n\n/**\n * @description Build prop. It can better optimize prop types\n * @description 生成 prop，能更好地优化类型\n * @example\n  // limited options\n  // the type will be PropType<'light' | 'dark'>\n  buildProp({\n    type: String,\n    values: ['light', 'dark'],\n  } as const)\n  * @example\n  // limited options and other types\n  // the type will be PropType<'small' | 'large' | number>\n  buildProp({\n    type: [String, Number],\n    values: ['small', 'large'],\n    validator: (val: unknown): val is number => typeof val === 'number',\n  } as const)\n  @link see more: https://github.com/map-sdk/map-sdk/pull/3341\n */\nexport const buildProp = <\n  Type = never,\n  Value = never,\n  Validator = never,\n  Default extends EpPropMergeType<Type, Value, Validator> = never,\n  Required extends boolean = false\n>(\n  prop: EpPropInput<Type, Value, Validator, Default, Required>,\n  key?: string\n): EpPropFinalized<Type, Value, Validator, Default, Required> => {\n  // filter native prop type and nested prop, e.g `null`, `undefined` (from `buildProps`)\n  if (!isObject(prop) || isEpProp(prop)) return prop as any\n\n  const { values, required, default: defaultValue, type, validator } = prop\n\n  const _validator =\n    values || validator\n      ? (val: unknown) => {\n          let valid = false\n          let allowedValues: unknown[] = []\n\n          if (values) {\n            allowedValues = Array.from(values)\n            if (hasOwn(prop, 'default')) {\n              allowedValues.push(defaultValue)\n            }\n            valid ||= allowedValues.includes(val)\n          }\n          if (validator) valid ||= validator(val)\n\n          if (!valid && allowedValues.length > 0) {\n            const allowValuesText = [...new Set(allowedValues)]\n              .map((value) => JSON.stringify(value))\n              .join(', ')\n            warn(\n              `Invalid prop: validation failed${\n                key ? ` for prop \"${key}\"` : ''\n              }. Expected one of [${allowValuesText}], got value ${JSON.stringify(\n                val\n              )}.`\n            )\n          }\n          return valid\n        }\n      : undefined\n\n  const epProp: any = {\n    type,\n    required: !!required,\n    validator: _validator,\n    [epPropKey]: true,\n  }\n  if (hasOwn(prop, 'default')) epProp.default = defaultValue\n  return epProp\n}\n\nexport const buildProps = <\n  Props extends Record<\n    string,\n    | { [epPropKey]: true }\n    | NativePropType\n    | EpPropInput<any, any, any, any, any>\n  >\n>(\n  props: Props\n): {\n  [K in keyof Props]: IfEpProp<\n    Props[K],\n    Props[K],\n    IfNativePropType<Props[K], Props[K], EpPropConvert<Props[K]>>\n  >\n} =>\n  fromPairs(\n    Object.entries(props).map(([key, option]) => [\n      key,\n      buildProp(option as any, key),\n    ])\n  ) as any\n"],"names":["epPropKey","definePropType","e","isEpProp","l","buildProp","r","values","o","required","d","default","i","type","f","validator","a","s","n","t","p","Array","from","u","push","includes","length","y","Set","map","P","JSON","stringify","join","v","buildProps","m","Object","entries"],"mappings":"2KAAgK,MAACA,EAAU,cAAcC,EAAeC,GAAGA,EAAEC,EAASD,GAAGE,EAAEF,MAAMA,EAAEF,GAAWK,EAAU,CAACH,EAAEI,KAAK,IAAIF,EAAEF,IAAIC,EAASD,GAAG,OAAOA,EAAE,MAAMK,OAAOC,EAAEC,SAASC,EAAEC,QAAQC,EAAEC,KAAKC,EAAEC,UAAUC,GAAGd,EAAEe,EAAE,CAACJ,KAAKC,EAAEL,WAAWC,EAAEK,UAAUP,GAAGQ,EAAEE,IAAI,IAAIC,GAAE,EAAGC,EAAE,GAAG,GAAGZ,IAAIY,EAAEC,MAAMC,KAAKd,GAAGe,EAAErB,EAAE,YAAYkB,EAAEI,KAAKZ,GAAGO,IAAIA,EAAEC,EAAEK,SAASP,KAAKF,IAAIG,IAAIA,EAAEH,EAAEE,MAAMC,GAAGC,EAAEM,OAAO,EAAE,CAAC,MAAMC,EAAE,IAAI,IAAIC,IAAIR,IAAIS,KAAIC,GAAGC,KAAKC,UAAUF,KAAIG,KAAK,MAAMC,EAAE,kCAAkC5B,EAAE,cAAcA,KAAK,wBAAwBqB,iBAAiBI,KAAKC,UAAUd,MAAM,CAAC,OAAOC,QAAG,EAAOnB,CAACA,IAAW,GAAI,OAAOuB,EAAErB,EAAE,aAAae,EAAEN,QAAQC,GAAGK,GAAGkB,EAAWjC,GAAGkC,EAAEC,OAAOC,QAAQpC,GAAG2B,KAAI,EAAEvB,EAAEE,KAAK,CAACF,EAAED,EAAUG,EAAEF"}