imageClip.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. export enum ClipPathTypes {
  2. RECT = 'rect',
  3. ELLIPSE = 'ellipse',
  4. POLYGON = 'polygon',
  5. }
  6. export enum ClipPaths {
  7. RECT = 'rect',
  8. ROUNDRECT = 'roundRect',
  9. ELLIPSE = 'ellipse',
  10. TRIANGLE = 'triangle',
  11. PENTAGON = 'pentagon',
  12. RHOMBUS = 'rhombus',
  13. STAR = 'star',
  14. }
  15. export const CLIPPATHS = {
  16. rect: {
  17. name: '矩形',
  18. type: ClipPathTypes.RECT,
  19. radius: '0',
  20. style: '',
  21. },
  22. roundRect: {
  23. name: '圆角矩形',
  24. type: ClipPathTypes.RECT,
  25. radius: '10%',
  26. style: 'inset(0 0 0 0 round 10% 10% 10% 10%)',
  27. },
  28. ellipse: {
  29. name: '圆形',
  30. type: ClipPathTypes.ELLIPSE,
  31. style: 'ellipse(50% 50% at 50% 50%)',
  32. },
  33. triangle: {
  34. name: '三角形',
  35. type: ClipPathTypes.POLYGON,
  36. style: 'polygon(50% 0%, 0% 100%, 100% 100%)',
  37. createPath: (width: number, height: number) => {
  38. return `M ${width / 2} 0 L 0 ${height} L ${width} ${height} Z`
  39. },
  40. },
  41. pentagon: {
  42. name: '五边形',
  43. type: ClipPathTypes.POLYGON,
  44. style: 'polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%)',
  45. createPath: (width: number, height: number) => {
  46. return `M ${width / 2} 0 L ${width} ${0.38 * height} L ${0.82 * width} ${height} L ${0.18 * width} ${height} L 0 ${0.38 * height} Z`
  47. },
  48. },
  49. rhombus: {
  50. name: '菱形',
  51. type: ClipPathTypes.POLYGON,
  52. style: 'polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)',
  53. createPath: (width: number, height: number) => {
  54. return `M ${width / 2} 0 L ${width} ${height / 2} L ${width / 2} ${height} L 0 ${height / 2} Z`
  55. },
  56. },
  57. }