index.js 10 KB

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