Mask.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { resolveDirective as _resolveDirective, Fragment as _Fragment, createVNode as _createVNode } from "vue";
  3. import { defineComponent } from 'vue';
  4. import classNames from '../_util/classNames';
  5. import useId from '../_util/hooks/useId';
  6. import Portal from '../_util/PortalWrapper';
  7. import { someType, objectType, booleanType } from '../_util/type';
  8. const COVER_PROPS = {
  9. fill: 'transparent',
  10. 'pointer-events': 'auto'
  11. };
  12. const Mask = defineComponent({
  13. name: 'TourMask',
  14. props: {
  15. prefixCls: {
  16. type: String
  17. },
  18. pos: objectType(),
  19. rootClassName: {
  20. type: String
  21. },
  22. showMask: booleanType(),
  23. fill: {
  24. type: String,
  25. default: 'rgba(0,0,0,0.5)'
  26. },
  27. open: booleanType(),
  28. animated: someType([Boolean, Object]),
  29. zIndex: {
  30. type: Number
  31. }
  32. },
  33. setup(props, _ref) {
  34. let {
  35. attrs
  36. } = _ref;
  37. const id = useId();
  38. return () => {
  39. const {
  40. prefixCls,
  41. open,
  42. rootClassName,
  43. pos,
  44. showMask,
  45. fill,
  46. animated,
  47. zIndex
  48. } = props;
  49. const maskId = `${prefixCls}-mask-${id}`;
  50. const mergedAnimated = typeof animated === 'object' ? animated === null || animated === void 0 ? void 0 : animated.placeholder : animated;
  51. return _createVNode(Portal, {
  52. "visible": open,
  53. "autoLock": true
  54. }, {
  55. default: () => open && _createVNode("div", _objectSpread(_objectSpread({}, attrs), {}, {
  56. "class": classNames(`${prefixCls}-mask`, rootClassName, attrs.class),
  57. "style": [{
  58. position: 'fixed',
  59. left: 0,
  60. right: 0,
  61. top: 0,
  62. bottom: 0,
  63. zIndex,
  64. pointerEvents: 'none'
  65. }, attrs.style]
  66. }), [showMask ? _createVNode("svg", {
  67. "style": {
  68. width: '100%',
  69. height: '100%'
  70. }
  71. }, [_createVNode("defs", null, [_createVNode("mask", {
  72. "id": maskId
  73. }, [_createVNode("rect", {
  74. "x": "0",
  75. "y": "0",
  76. "width": "100vw",
  77. "height": "100vh",
  78. "fill": "white"
  79. }, null), pos && _createVNode("rect", {
  80. "x": pos.left,
  81. "y": pos.top,
  82. "rx": pos.radius,
  83. "width": pos.width,
  84. "height": pos.height,
  85. "fill": "black",
  86. "class": mergedAnimated ? `${prefixCls}-placeholder-animated` : ''
  87. }, null)])]), _createVNode("rect", {
  88. "x": "0",
  89. "y": "0",
  90. "width": "100%",
  91. "height": "100%",
  92. "fill": fill,
  93. "mask": `url(#${maskId})`
  94. }, null), pos && _createVNode(_Fragment, null, [_createVNode("rect", _objectSpread(_objectSpread({}, COVER_PROPS), {}, {
  95. "x": "0",
  96. "y": "0",
  97. "width": "100%",
  98. "height": pos.top
  99. }), null), _createVNode("rect", _objectSpread(_objectSpread({}, COVER_PROPS), {}, {
  100. "x": "0",
  101. "y": "0",
  102. "width": pos.left,
  103. "height": "100%"
  104. }), null), _createVNode("rect", _objectSpread(_objectSpread({}, COVER_PROPS), {}, {
  105. "x": "0",
  106. "y": pos.top + pos.height,
  107. "width": "100%",
  108. "height": `calc(100vh - ${pos.top + pos.height}px)`
  109. }), null), _createVNode("rect", _objectSpread(_objectSpread({}, COVER_PROPS), {}, {
  110. "x": pos.left + pos.width,
  111. "y": "0",
  112. "width": `calc(100vw - ${pos.left + pos.width}px)`,
  113. "height": "100%"
  114. }), null)])]) : null])
  115. });
  116. };
  117. }
  118. });
  119. export default Mask;