roundedArrow.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.roundedArrow = void 0;
  6. const roundedArrow = (width, innerRadius, outerRadius, bgColor, boxShadow) => {
  7. const unitWidth = width / 2;
  8. const ax = 0;
  9. const ay = unitWidth;
  10. const bx = outerRadius * 1 / Math.sqrt(2);
  11. const by = unitWidth - outerRadius * (1 - 1 / Math.sqrt(2));
  12. const cx = unitWidth - innerRadius * (1 / Math.sqrt(2));
  13. const cy = outerRadius * (Math.sqrt(2) - 1) + innerRadius * (1 / Math.sqrt(2));
  14. const dx = 2 * unitWidth - cx;
  15. const dy = cy;
  16. const ex = 2 * unitWidth - bx;
  17. const ey = by;
  18. const fx = 2 * unitWidth - ax;
  19. const fy = ay;
  20. const shadowWidth = unitWidth * Math.sqrt(2) + outerRadius * (Math.sqrt(2) - 2);
  21. const polygonOffset = outerRadius * (Math.sqrt(2) - 1);
  22. return {
  23. pointerEvents: 'none',
  24. width,
  25. height: width,
  26. overflow: 'hidden',
  27. '&::after': {
  28. content: '""',
  29. position: 'absolute',
  30. width: shadowWidth,
  31. height: shadowWidth,
  32. bottom: 0,
  33. insetInline: 0,
  34. margin: 'auto',
  35. borderRadius: {
  36. _skip_check_: true,
  37. value: `0 0 ${innerRadius}px 0`
  38. },
  39. transform: 'translateY(50%) rotate(-135deg)',
  40. boxShadow,
  41. zIndex: 0,
  42. background: 'transparent'
  43. },
  44. '&::before': {
  45. position: 'absolute',
  46. bottom: 0,
  47. insetInlineStart: 0,
  48. width,
  49. height: width / 2,
  50. background: bgColor,
  51. clipPath: {
  52. _multi_value_: true,
  53. value: [`polygon(${polygonOffset}px 100%, 50% ${polygonOffset}px, ${2 * unitWidth - polygonOffset}px 100%, ${polygonOffset}px 100%)`, `path('M ${ax} ${ay} A ${outerRadius} ${outerRadius} 0 0 0 ${bx} ${by} L ${cx} ${cy} A ${innerRadius} ${innerRadius} 0 0 1 ${dx} ${dy} L ${ex} ${ey} A ${outerRadius} ${outerRadius} 0 0 0 ${fx} ${fy} Z')`]
  54. },
  55. content: '""'
  56. }
  57. };
  58. };
  59. exports.roundedArrow = roundedArrow;