2022-03-22 14:11:30 +08:00
|
|
|
// deps-lint-skip-all
|
2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-03-22 14:11:30 +08:00
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2022-05-09 22:20:07 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../_util/theme';
|
|
|
|
import { genComponentStyleHook, mergeToken, resetComponent } from '../../_util/theme';
|
2022-03-22 14:11:30 +08:00
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
export interface ImageToken extends FullToken<'Image'> {
|
2022-03-22 14:11:30 +08:00
|
|
|
previewPrefixCls: string;
|
|
|
|
imageSizeBase: number;
|
|
|
|
marginXXS: number;
|
|
|
|
imageBg: string;
|
|
|
|
imageColor: string;
|
|
|
|
imagePreviewOperationDisabledColor: string;
|
|
|
|
imageMaskFontSize: number;
|
|
|
|
iconPrefixClsFontSize: number;
|
|
|
|
imagePreviewOperationSize: number;
|
|
|
|
imageFontSizeBase: number;
|
|
|
|
switchLeft: number;
|
|
|
|
switchRight: number;
|
|
|
|
switchWidth: number;
|
|
|
|
switchHeight: number;
|
|
|
|
switchMarginTop: number;
|
|
|
|
width1px: number;
|
|
|
|
modalMaskBg: string;
|
|
|
|
zIndexImage: number;
|
|
|
|
zIndexModalMask: number;
|
|
|
|
motionEaseOut: string;
|
|
|
|
white: string;
|
|
|
|
black: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type PositionType = 'static' | 'relative' | 'fixed' | 'absolute' | 'sticky' | undefined;
|
|
|
|
|
|
|
|
export const genBoxStyle = (position?: PositionType): CSSObject => ({
|
|
|
|
position: position || 'absolute',
|
|
|
|
inset: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const genImageMaskStyle = (token: ImageToken): CSSObject => {
|
2022-04-08 18:05:50 +08:00
|
|
|
const { iconCls, white, black, motionDurationSlow, paddingXXS, marginXXS, prefixCls } = token;
|
2022-03-22 14:11:30 +08:00
|
|
|
return {
|
|
|
|
position: 'absolute',
|
|
|
|
inset: 0,
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
color: white,
|
|
|
|
background: new TinyColor(black).setAlpha(0.5).toRgbString(), // FIXME: hard code in v4
|
|
|
|
cursor: 'pointer',
|
|
|
|
opacity: 0,
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `opacity ${motionDurationSlow}`,
|
2022-03-22 14:11:30 +08:00
|
|
|
|
|
|
|
[`.${prefixCls}-mask-info`]: {
|
2022-03-29 13:56:19 +08:00
|
|
|
padding: `0 ${paddingXXS}px`,
|
2022-03-22 14:11:30 +08:00
|
|
|
overflow: 'hidden',
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textOverflow: 'ellipsis',
|
2022-04-08 18:05:50 +08:00
|
|
|
[iconCls]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
marginInlineEnd: marginXXS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const genPreviewOperationsStyle = (token: ImageToken): CSSObject => {
|
|
|
|
const {
|
|
|
|
black,
|
|
|
|
modalMaskBg,
|
|
|
|
paddingSM,
|
|
|
|
imagePreviewOperationDisabledColor,
|
|
|
|
imagePreviewOperationSize,
|
|
|
|
previewPrefixCls,
|
|
|
|
} = token;
|
|
|
|
return {
|
|
|
|
...resetComponent(token),
|
|
|
|
position: 'absolute',
|
|
|
|
insetBlockStart: 0,
|
|
|
|
insetInlineEnd: 0,
|
|
|
|
zIndex: 1,
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row-reverse',
|
|
|
|
alignItems: 'center',
|
|
|
|
width: '100%',
|
|
|
|
color: black,
|
|
|
|
listStyle: 'none',
|
|
|
|
background: new TinyColor(modalMaskBg).setAlpha(0.1).toRgbString(), // FIXME: hard code
|
|
|
|
pointerEvents: 'auto',
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-operations-operation`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
marginInlineStart: paddingSM,
|
|
|
|
padding: paddingSM,
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
|
|
|
'&-disabled': {
|
|
|
|
color: imagePreviewOperationDisabledColor,
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:last-of-type': {
|
|
|
|
marginInlineStart: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-20 11:30:55 +08:00
|
|
|
[`${previewPrefixCls}-progress`]: {
|
|
|
|
position: 'absolute',
|
2022-04-20 11:48:38 +08:00
|
|
|
left: { _skip_check_: true, value: '50%' },
|
2022-04-20 11:30:55 +08:00
|
|
|
transform: 'translateX(-50%)',
|
|
|
|
},
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-icon`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
fontSize: imagePreviewOperationSize,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export const genPreviewSwitchStyle = (token: ImageToken): CSSObject => {
|
|
|
|
const {
|
|
|
|
black,
|
|
|
|
modalMaskBg,
|
2022-04-08 18:05:50 +08:00
|
|
|
iconCls,
|
2022-03-22 14:11:30 +08:00
|
|
|
imagePreviewOperationDisabledColor,
|
|
|
|
previewPrefixCls,
|
|
|
|
switchWidth,
|
|
|
|
switchRight,
|
|
|
|
switchHeight,
|
|
|
|
switchMarginTop,
|
|
|
|
iconPrefixClsFontSize,
|
|
|
|
} = token;
|
|
|
|
return {
|
|
|
|
position: 'absolute',
|
|
|
|
insetBlockStart: '50%',
|
|
|
|
insetInlineEnd: switchRight,
|
|
|
|
zIndex: 1,
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
width: switchWidth,
|
|
|
|
height: switchHeight,
|
|
|
|
marginTop: switchMarginTop,
|
|
|
|
color: black,
|
|
|
|
background: new TinyColor(modalMaskBg).setAlpha(0.1).toRgbString(), // FIXME: hard code in v4
|
|
|
|
borderRadius: '50%',
|
|
|
|
cursor: 'pointer',
|
|
|
|
pointerEvents: 'auto',
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-disabled`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
color: imagePreviewOperationDisabledColor,
|
|
|
|
cursor: 'not-allowed',
|
2022-04-08 18:05:50 +08:00
|
|
|
[`> ${iconCls}`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 18:05:50 +08:00
|
|
|
[`> ${iconCls}`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
fontSize: iconPrefixClsFontSize,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const genImagePreviewStyle = (token: ImageToken): CSSObject => {
|
2022-03-22 20:02:04 +08:00
|
|
|
const { motionEaseOut, previewPrefixCls, switchRight, switchLeft, width1px, motionDurationSlow } =
|
|
|
|
token;
|
2022-03-22 14:11:30 +08:00
|
|
|
return {
|
|
|
|
height: '100%',
|
|
|
|
textAlign: 'center',
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-body`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
...genBoxStyle(),
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-img`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
maxWidth: '100%',
|
|
|
|
maxHeight: '100%',
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
transform: 'scale3d(1, 1, 1)',
|
|
|
|
cursor: 'grab',
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `transform ${motionDurationSlow} ${motionEaseOut} 0s`,
|
2022-03-22 14:11:30 +08:00
|
|
|
userSelect: 'none',
|
|
|
|
pointerEvents: 'auto',
|
|
|
|
|
|
|
|
'&-wrapper': {
|
|
|
|
...genBoxStyle(),
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `transform ${motionDurationSlow} ${motionEaseOut} 0s`,
|
2022-03-22 14:11:30 +08:00
|
|
|
|
|
|
|
'&::before': {
|
|
|
|
display: 'inline-block',
|
|
|
|
width: width1px,
|
|
|
|
height: '50%',
|
|
|
|
marginInlineEnd: -width1px,
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-moving`]: {
|
|
|
|
[`${previewPrefixCls}-preview-img`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
cursor: 'grabbing',
|
|
|
|
|
|
|
|
'&-wrapper': {
|
|
|
|
transitionDuration: '0s',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-operations`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
...genPreviewOperationsStyle(token),
|
|
|
|
},
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-switch-left, ${previewPrefixCls}-switch-right`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
...genPreviewSwitchStyle(token),
|
|
|
|
},
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-switch-left`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
insetInlineStart: switchLeft,
|
|
|
|
},
|
|
|
|
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-switch-right`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
insetInlineEnd: switchRight,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const genImageStyle: GenerateStyle<ImageToken> = (token: ImageToken) => {
|
|
|
|
const {
|
|
|
|
prefixCls,
|
|
|
|
zIndexModalMask,
|
|
|
|
modalMaskBg,
|
|
|
|
previewPrefixCls,
|
|
|
|
imageBg,
|
|
|
|
zIndexImage,
|
2022-03-22 20:02:04 +08:00
|
|
|
motionDurationSlow,
|
2022-03-22 14:11:30 +08:00
|
|
|
} = token;
|
|
|
|
return {
|
|
|
|
// ============================== image ==============================
|
|
|
|
[`.${prefixCls}`]: {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'inline-block',
|
|
|
|
[`.${prefixCls}-img`]: {
|
|
|
|
width: '100%',
|
|
|
|
height: 'auto',
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
},
|
|
|
|
[`.${prefixCls}-img-placeholder`]: {
|
|
|
|
backgroundColor: imageBg,
|
|
|
|
backgroundImage:
|
|
|
|
"url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTQuNSAyLjVoLTEzQS41LjUgMCAwIDAgMSAzdjEwYS41LjUgMCAwIDAgLjUuNWgxM2EuNS41IDAgMCAwIC41LS41VjNhLjUuNSAwIDAgMC0uNS0uNXpNNS4yODEgNC43NWExIDEgMCAwIDEgMCAyIDEgMSAwIDAgMSAwLTJ6bTguMDMgNi44M2EuMTI3LjEyNyAwIDAgMS0uMDgxLjAzSDIuNzY5YS4xMjUuMTI1IDAgMCAxLS4wOTYtLjIwN2wyLjY2MS0zLjE1NmEuMTI2LjEyNiAwIDAgMSAuMTc3LS4wMTZsLjAxNi4wMTZMNy4wOCAxMC4wOWwyLjQ3LTIuOTNhLjEyNi4xMjYgMCAwIDEgLjE3Ny0uMDE2bC4wMTUuMDE2IDMuNTg4IDQuMjQ0YS4xMjcuMTI3IDAgMCAxLS4wMi4xNzV6IiBmaWxsPSIjOEM4QzhDIiBmaWxsLXJ1bGU9Im5vbnplcm8iLz48L3N2Zz4=')",
|
|
|
|
backgroundRepeat: 'no-repeat',
|
|
|
|
backgroundPosition: 'center center',
|
|
|
|
backgroundSize: '30%',
|
|
|
|
},
|
|
|
|
[`.${prefixCls}-mask`]: {
|
|
|
|
...genImageMaskStyle(token),
|
|
|
|
},
|
|
|
|
[`.${prefixCls}-mask:hover`]: {
|
|
|
|
opacity: 1,
|
|
|
|
},
|
|
|
|
[`.${prefixCls}-placeholder`]: {
|
|
|
|
...genBoxStyle(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// ============================== preview ==============================
|
|
|
|
pointerEvents: 'none',
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}.${prefixCls}-zoom-enter, ${previewPrefixCls}.${prefixCls}zoom-appear`]: {
|
|
|
|
transform: 'none',
|
|
|
|
opacity: 0,
|
|
|
|
animationDuration: motionDurationSlow,
|
|
|
|
userSelect: 'none', // https://github.com/ant-design/ant-design/issues/11777
|
|
|
|
},
|
|
|
|
[`${previewPrefixCls}-root`]: {
|
|
|
|
[`${previewPrefixCls}-mask`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
...genBoxStyle('fixed'),
|
|
|
|
zIndex: zIndexModalMask,
|
|
|
|
height: '100%',
|
|
|
|
backgroundColor: modalMaskBg,
|
|
|
|
|
|
|
|
'&-hidden': {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}-wrap`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
...genBoxStyle('fixed'),
|
|
|
|
overflow: 'auto',
|
|
|
|
outline: 0,
|
|
|
|
WebkitOverflowScrolling: 'touch',
|
|
|
|
zIndex: zIndexImage,
|
2022-04-08 18:05:50 +08:00
|
|
|
[`${previewPrefixCls}`]: {
|
2022-03-22 14:11:30 +08:00
|
|
|
...genImagePreviewStyle(token),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-04-21 02:06:22 +08:00
|
|
|
export default genComponentStyleHook('Image', token => {
|
2022-04-11 16:04:00 +08:00
|
|
|
const imageToken = mergeToken<ImageToken>(token, {
|
2022-04-08 18:05:50 +08:00
|
|
|
previewPrefixCls: `${token.componentCls}-preview`,
|
2022-03-22 14:11:30 +08:00
|
|
|
|
|
|
|
white: '#fff', // FIXME: hard code
|
|
|
|
black: '#000', // FIXME: hard code
|
|
|
|
imageSizeBase: 48, // FIXME: hard code in v4
|
|
|
|
imageFontSizeBase: 24, // FIXME: hard code in v4
|
|
|
|
imageBg: '#f5f5f5', // FIXME: hard code in v4
|
|
|
|
imageColor: '#fff', // FIXME: hard code in v4
|
|
|
|
imageMaskFontSize: 16, // FIXME: hard code in v4
|
|
|
|
imagePreviewOperationSize: 18, // FIXME: hard code in v4
|
|
|
|
iconPrefixClsFontSize: 18, // FIXME: hard code in v4
|
|
|
|
switchWidth: 44, // FIXME: hard code in v4
|
|
|
|
switchHeight: 44, // FIXME: hard code in v4
|
|
|
|
switchRight: 10, // FIXME: hard code in v4
|
|
|
|
switchLeft: 10, // FIXME: hard code in v4
|
|
|
|
switchMarginTop: -22, // FIXME: hard code in v4
|
|
|
|
width1px: 1, // FIXME: hard code in v4
|
|
|
|
imagePreviewOperationDisabledColor: new TinyColor('#000').setAlpha(0.25).toRgbString(), // FIXME: hard code in v4
|
|
|
|
modalMaskBg: new TinyColor('#000').setAlpha(0.45).toRgbString(), // FIXME: hard code in v4
|
|
|
|
zIndexImage: 1080, // FIXME: hard code in v4
|
|
|
|
zIndexModalMask: 1000, // FIXME: hard code in v4
|
|
|
|
motionEaseOut: 'cubic-bezier(0.215, 0.61, 0.355, 1)', // FIXME: hard code in v4
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-03-22 14:11:30 +08:00
|
|
|
|
2022-04-21 02:06:22 +08:00
|
|
|
return [genImageStyle(imageToken)];
|
2022-04-08 18:05:50 +08:00
|
|
|
});
|