index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.genPreviewSwitchStyle = exports.genPreviewOperationsStyle = exports.genImagePreviewStyle = exports.genImageMaskStyle = exports.genBoxStyle = exports.default = void 0;
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. require("../../_util/cssinjs");
  9. var _tinycolor = require("@ctrl/tinycolor");
  10. var _style = require("../../modal/style");
  11. var _motion = require("../../style/motion");
  12. var _internal = require("../../theme/internal");
  13. var _style2 = require("../../style");
  14. const genBoxStyle = position => ({
  15. position: position || 'absolute',
  16. inset: 0
  17. });
  18. exports.genBoxStyle = genBoxStyle;
  19. const genImageMaskStyle = token => {
  20. const {
  21. iconCls,
  22. motionDurationSlow,
  23. paddingXXS,
  24. marginXXS,
  25. prefixCls
  26. } = token;
  27. return {
  28. position: 'absolute',
  29. inset: 0,
  30. display: 'flex',
  31. alignItems: 'center',
  32. justifyContent: 'center',
  33. color: '#fff',
  34. background: new _tinycolor.TinyColor('#000').setAlpha(0.5).toRgbString(),
  35. cursor: 'pointer',
  36. opacity: 0,
  37. transition: `opacity ${motionDurationSlow}`,
  38. [`.${prefixCls}-mask-info`]: (0, _extends2.default)((0, _extends2.default)({}, _style2.textEllipsis), {
  39. padding: `0 ${paddingXXS}px`,
  40. [iconCls]: {
  41. marginInlineEnd: marginXXS,
  42. svg: {
  43. verticalAlign: 'baseline'
  44. }
  45. }
  46. })
  47. };
  48. };
  49. exports.genImageMaskStyle = genImageMaskStyle;
  50. const genPreviewOperationsStyle = token => {
  51. const {
  52. previewCls,
  53. modalMaskBg,
  54. paddingSM,
  55. previewOperationColorDisabled,
  56. motionDurationSlow
  57. } = token;
  58. const operationBg = new _tinycolor.TinyColor(modalMaskBg).setAlpha(0.1);
  59. const operationBgHover = operationBg.clone().setAlpha(0.2);
  60. return {
  61. [`${previewCls}-operations`]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style2.resetComponent)(token)), {
  62. display: 'flex',
  63. flexDirection: 'row-reverse',
  64. alignItems: 'center',
  65. color: token.previewOperationColor,
  66. listStyle: 'none',
  67. background: operationBg.toRgbString(),
  68. pointerEvents: 'auto',
  69. '&-operation': {
  70. marginInlineStart: paddingSM,
  71. padding: paddingSM,
  72. cursor: 'pointer',
  73. transition: `all ${motionDurationSlow}`,
  74. userSelect: 'none',
  75. '&:hover': {
  76. background: operationBgHover.toRgbString()
  77. },
  78. '&-disabled': {
  79. color: previewOperationColorDisabled,
  80. pointerEvents: 'none'
  81. },
  82. '&:last-of-type': {
  83. marginInlineStart: 0
  84. }
  85. },
  86. '&-progress': {
  87. position: 'absolute',
  88. left: {
  89. _skip_check_: true,
  90. value: '50%'
  91. },
  92. transform: 'translateX(-50%)'
  93. },
  94. '&-icon': {
  95. fontSize: token.previewOperationSize
  96. }
  97. })
  98. };
  99. };
  100. exports.genPreviewOperationsStyle = genPreviewOperationsStyle;
  101. const genPreviewSwitchStyle = token => {
  102. const {
  103. modalMaskBg,
  104. iconCls,
  105. previewOperationColorDisabled,
  106. previewCls,
  107. zIndexPopup,
  108. motionDurationSlow
  109. } = token;
  110. const operationBg = new _tinycolor.TinyColor(modalMaskBg).setAlpha(0.1);
  111. const operationBgHover = operationBg.clone().setAlpha(0.2);
  112. return {
  113. [`${previewCls}-switch-left, ${previewCls}-switch-right`]: {
  114. position: 'fixed',
  115. insetBlockStart: '50%',
  116. zIndex: zIndexPopup + 1,
  117. display: 'flex',
  118. alignItems: 'center',
  119. justifyContent: 'center',
  120. width: token.imagePreviewSwitchSize,
  121. height: token.imagePreviewSwitchSize,
  122. marginTop: -token.imagePreviewSwitchSize / 2,
  123. color: token.previewOperationColor,
  124. background: operationBg.toRgbString(),
  125. borderRadius: '50%',
  126. transform: `translateY(-50%)`,
  127. cursor: 'pointer',
  128. transition: `all ${motionDurationSlow}`,
  129. pointerEvents: 'auto',
  130. userSelect: 'none',
  131. '&:hover': {
  132. background: operationBgHover.toRgbString()
  133. },
  134. [`&-disabled`]: {
  135. '&, &:hover': {
  136. color: previewOperationColorDisabled,
  137. background: 'transparent',
  138. cursor: 'not-allowed',
  139. [`> ${iconCls}`]: {
  140. cursor: 'not-allowed'
  141. }
  142. }
  143. },
  144. [`> ${iconCls}`]: {
  145. fontSize: token.previewOperationSize
  146. }
  147. },
  148. [`${previewCls}-switch-left`]: {
  149. insetInlineStart: token.marginSM
  150. },
  151. [`${previewCls}-switch-right`]: {
  152. insetInlineEnd: token.marginSM
  153. }
  154. };
  155. };
  156. exports.genPreviewSwitchStyle = genPreviewSwitchStyle;
  157. const genImagePreviewStyle = token => {
  158. const {
  159. motionEaseOut,
  160. previewCls,
  161. motionDurationSlow,
  162. componentCls
  163. } = token;
  164. return [{
  165. [`${componentCls}-preview-root`]: {
  166. [previewCls]: {
  167. height: '100%',
  168. textAlign: 'center',
  169. pointerEvents: 'none'
  170. },
  171. [`${previewCls}-body`]: (0, _extends2.default)((0, _extends2.default)({}, genBoxStyle()), {
  172. overflow: 'hidden'
  173. }),
  174. [`${previewCls}-img`]: {
  175. maxWidth: '100%',
  176. maxHeight: '100%',
  177. verticalAlign: 'middle',
  178. transform: 'scale3d(1, 1, 1)',
  179. cursor: 'grab',
  180. transition: `transform ${motionDurationSlow} ${motionEaseOut} 0s`,
  181. userSelect: 'none',
  182. pointerEvents: 'auto',
  183. '&-wrapper': (0, _extends2.default)((0, _extends2.default)({}, genBoxStyle()), {
  184. transition: `transform ${motionDurationSlow} ${motionEaseOut} 0s`,
  185. // https://github.com/ant-design/ant-design/issues/39913
  186. // TailwindCSS will reset img default style.
  187. // Let's set back.
  188. display: 'flex',
  189. justifyContent: 'center',
  190. alignItems: 'center',
  191. '&::before': {
  192. display: 'inline-block',
  193. width: 1,
  194. height: '50%',
  195. marginInlineEnd: -1,
  196. content: '""'
  197. }
  198. })
  199. },
  200. [`${previewCls}-moving`]: {
  201. [`${previewCls}-preview-img`]: {
  202. cursor: 'grabbing',
  203. '&-wrapper': {
  204. transitionDuration: '0s'
  205. }
  206. }
  207. }
  208. }
  209. },
  210. // Override
  211. {
  212. [`${componentCls}-preview-root`]: {
  213. [`${previewCls}-wrap`]: {
  214. zIndex: token.zIndexPopup
  215. }
  216. }
  217. },
  218. // Preview operations & switch
  219. {
  220. [`${componentCls}-preview-operations-wrapper`]: {
  221. position: 'fixed',
  222. insetBlockStart: 0,
  223. insetInlineEnd: 0,
  224. zIndex: token.zIndexPopup + 1,
  225. width: '100%'
  226. },
  227. '&': [genPreviewOperationsStyle(token), genPreviewSwitchStyle(token)]
  228. }];
  229. };
  230. exports.genImagePreviewStyle = genImagePreviewStyle;
  231. const genImageStyle = token => {
  232. const {
  233. componentCls
  234. } = token;
  235. return {
  236. // ============================== image ==============================
  237. [componentCls]: {
  238. position: 'relative',
  239. display: 'inline-block',
  240. [`${componentCls}-img`]: {
  241. width: '100%',
  242. height: 'auto',
  243. verticalAlign: 'middle'
  244. },
  245. [`${componentCls}-img-placeholder`]: {
  246. backgroundColor: token.colorBgContainerDisabled,
  247. backgroundImage: "url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTQuNSAyLjVoLTEzQS41LjUgMCAwIDAgMSAzdjEwYS41LjUgMCAwIDAgLjUuNWgxM2EuNS41IDAgMCAwIC41LS41VjNhLjUuNSAwIDAgMC0uNS0uNXpNNS4yODEgNC43NWExIDEgMCAwIDEgMCAyIDEgMSAwIDAgMSAwLTJ6bTguMDMgNi44M2EuMTI3LjEyNyAwIDAgMS0uMDgxLjAzSDIuNzY5YS4xMjUuMTI1IDAgMCAxLS4wOTYtLjIwN2wyLjY2MS0zLjE1NmEuMTI2LjEyNiAwIDAgMSAuMTc3LS4wMTZsLjAxNi4wMTZMNy4wOCAxMC4wOWwyLjQ3LTIuOTNhLjEyNi4xMjYgMCAwIDEgLjE3Ny0uMDE2bC4wMTUuMDE2IDMuNTg4IDQuMjQ0YS4xMjcuMTI3IDAgMCAxLS4wMi4xNzV6IiBmaWxsPSIjOEM4QzhDIiBmaWxsLXJ1bGU9Im5vbnplcm8iLz48L3N2Zz4=')",
  248. backgroundRepeat: 'no-repeat',
  249. backgroundPosition: 'center center',
  250. backgroundSize: '30%'
  251. },
  252. [`${componentCls}-mask`]: (0, _extends2.default)({}, genImageMaskStyle(token)),
  253. [`${componentCls}-mask:hover`]: {
  254. opacity: 1
  255. },
  256. [`${componentCls}-placeholder`]: (0, _extends2.default)({}, genBoxStyle())
  257. }
  258. };
  259. };
  260. const genPreviewMotion = token => {
  261. const {
  262. previewCls
  263. } = token;
  264. return {
  265. [`${previewCls}-root`]: (0, _motion.initZoomMotion)(token, 'zoom'),
  266. [`&`]: (0, _motion.initFadeMotion)(token, true)
  267. };
  268. };
  269. // ============================== Export ==============================
  270. var _default = exports.default = (0, _internal.genComponentStyleHook)('Image', token => {
  271. const previewCls = `${token.componentCls}-preview`;
  272. const imageToken = (0, _internal.mergeToken)(token, {
  273. previewCls,
  274. modalMaskBg: new _tinycolor.TinyColor('#000').setAlpha(0.45).toRgbString(),
  275. imagePreviewSwitchSize: token.controlHeightLG
  276. });
  277. return [genImageStyle(imageToken), genImagePreviewStyle(imageToken), (0, _style.genModalMaskStyle)((0, _internal.mergeToken)(imageToken, {
  278. componentCls: previewCls
  279. })), genPreviewMotion(imageToken)];
  280. }, token => ({
  281. zIndexPopup: token.zIndexPopupBase + 80,
  282. previewOperationColor: new _tinycolor.TinyColor(token.colorTextLightSolid).toRgbString(),
  283. previewOperationColorDisabled: new _tinycolor.TinyColor(token.colorTextLightSolid).setAlpha(0.25).toRgbString(),
  284. previewOperationSize: token.fontSizeIcon * 1.5 // FIXME: fontSizeIconLG
  285. }));