PromoCursed/node_modules/.cache/babel-loader/43279a7d7a72e0e3806eee307ed0f3a2fbded67bf5f0ccc0b811c8e47d8d32ee.json

1 line
23 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"\"use client\";\n\nvar __rest = this && this.__rest || function (s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];\n }\n return t;\n};\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport ResizeObserver from 'rc-resize-observer';\nimport { composeRef } from \"rc-util/es/ref\";\nimport { responsiveArray } from '../_util/responsiveObserver';\nimport { devUseWarning } from '../_util/warning';\nimport { ConfigContext } from '../config-provider';\nimport useCSSVarCls from '../config-provider/hooks/useCSSVarCls';\nimport useSize from '../config-provider/hooks/useSize';\nimport useBreakpoint from '../grid/hooks/useBreakpoint';\nimport AvatarContext from './AvatarContext';\nimport useStyle from './style';\nconst InternalAvatar = (props, ref) => {\n const [scale, setScale] = React.useState(1);\n const [mounted, setMounted] = React.useState(false);\n const [isImgExist, setIsImgExist] = React.useState(true);\n const avatarNodeRef = React.useRef(null);\n const avatarChildrenRef = React.useRef(null);\n const avatarNodeMergedRef = composeRef(ref, avatarNodeRef);\n const {\n getPrefixCls,\n avatar\n } = React.useContext(ConfigContext);\n const avatarCtx = React.useContext(AvatarContext);\n const setScaleParam = () => {\n if (!avatarChildrenRef.current || !avatarNodeRef.current) {\n return;\n }\n const childrenWidth = avatarChildrenRef.current.offsetWidth; // offsetWidth avoid affecting be transform scale\n const nodeWidth = avatarNodeRef.current.offsetWidth;\n // denominator is 0 is no meaning\n if (childrenWidth !== 0 && nodeWidth !== 0) {\n const {\n gap = 4\n } = props;\n if (gap * 2 < nodeWidth) {\n setScale(nodeWidth - gap * 2 < childrenWidth ? (nodeWidth - gap * 2) / childrenWidth : 1);\n }\n }\n };\n React.useEffect(() => {\n setMounted(true);\n }, []);\n React.useEffect(() => {\n setIsImgExist(true);\n setScale(1);\n }, [props.src]);\n React.useEffect(setScaleParam, [props.gap]);\n const handleImgLoadError = () => {\n const {\n onError\n } = props;\n const errorFlag = onError === null || onError === void 0 ? void 0 : onError();\n if (errorFlag !== false) {\n setIsImgExist(false);\n }\n };\n const {\n prefixCls: customizePrefixCls,\n shape,\n size: customSize,\n src,\n srcSet,\n icon,\n className,\n rootClassName,\n alt,\n draggable,\n children,\n crossOrigin\n } = props,\n others = __rest(props, [\"prefixCls\", \"shape\", \"size\", \"src\", \"srcSet\", \"icon\", \"className\", \"rootClassName\", \"alt\", \"draggable\", \"children\", \"crossOrigin\"]);\n const size = useSize(ctxSize => {\n var _a, _b;\n return (_b = (_a = customSize !== null && customSize !== void 0 ? customSize : avatarCtx === null || avatarCtx === void 0 ? void 0 : avatarCtx.size) !== null && _a !== void 0 ? _a : ctxSize) !== null && _b !== void 0 ? _b : 'default';\n });\n const needResponsive = Object.keys(typeof size === 'object' ? size || {} : {}).some(key => ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].includes(key));\n const screens = useBreakpoint(needResponsive);\n const responsiveSizeStyle = React.useMemo(() => {\n if (typeof size !== 'object') {\n return {};\n }\n const currentBreakpoint = responsiveArray.find(screen => screens[screen]);\n const currentSize = size[currentBreakpoint];\n return currentSize ? {\n width: currentSize,\n height: currentSize,\n fontSize: currentSize && (icon || children) ? currentSize / 2 : 18\n } : {};\n }, [screens, size]);\n if (process.env.NODE_ENV !== 'production') {\n const warning = devUseWarning('Avatar');\n process.en