image-clip.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. export const enum ClipPathTypes {
  2. RECT = 'rect',
  3. ELLIPSE = 'ellipse',
  4. POLYGON = 'polygon',
  5. }
  6. export const 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. interface ClipPath {
  16. [key: string]: {
  17. name: string;
  18. type: ClipPathTypes;
  19. style: string;
  20. radius?: string;
  21. createPath?: (width: number, height: number) => string;
  22. };
  23. }
  24. export const CLIPPATHS: ClipPath = {
  25. rect: {
  26. name: '矩形',
  27. type: ClipPathTypes.RECT,
  28. radius: '0',
  29. style: '',
  30. },
  31. rect2: {
  32. name: '矩形2',
  33. type: ClipPathTypes.POLYGON,
  34. style: 'polygon(0% 0%, 80% 0%, 100% 20%, 100% 100%, 0 100%)',
  35. createPath: (width: number, height: number) => {
  36. return `M 0 0 L ${width * 0.8} 0 L ${width} ${height * 0.2} L ${width} ${height} L 0 ${height} Z`;
  37. },
  38. },
  39. rect3: {
  40. name: '矩形3',
  41. type: ClipPathTypes.POLYGON,
  42. style: 'polygon(0% 0%, 80% 0%, 100% 20%, 100% 100%, 20% 100%, 0% 80%)',
  43. createPath: (width: number, height: number) => {
  44. return `M 0 0 L ${width * 0.8} 0 L ${width} ${height * 0.2} L ${width} ${height} L ${width * 0.2} ${height} L 0 ${height * 0.8} Z`;
  45. },
  46. },
  47. roundRect: {
  48. name: '圆角矩形',
  49. type: ClipPathTypes.RECT,
  50. radius: '10px',
  51. style: 'inset(0 round 10px)',
  52. },
  53. ellipse: {
  54. name: '圆形',
  55. type: ClipPathTypes.ELLIPSE,
  56. style: 'ellipse(50% 50% at 50% 50%)',
  57. },
  58. triangle: {
  59. name: '三角形',
  60. type: ClipPathTypes.POLYGON,
  61. style: 'polygon(50% 0%, 0% 100%, 100% 100%)',
  62. createPath: (width: number, height: number) => {
  63. return `M ${width * 0.5} 0 L 0 ${height} L ${width} ${height} Z`;
  64. },
  65. },
  66. triangle2: {
  67. name: '三角形2',
  68. type: ClipPathTypes.POLYGON,
  69. style: 'polygon(50% 100%, 0% 0%, 100% 0%)',
  70. createPath: (width: number, height: number) => {
  71. return `M ${width * 0.5} ${height} L 0 0 L ${width} 0 Z`;
  72. },
  73. },
  74. triangle3: {
  75. name: '三角形3',
  76. type: ClipPathTypes.POLYGON,
  77. style: 'polygon(0% 0%, 0% 100%, 100% 100%)',
  78. createPath: (width: number, height: number) => {
  79. return `M 0 0 L 0 ${height} L ${width} ${height} Z`;
  80. },
  81. },
  82. rhombus: {
  83. name: '菱形',
  84. type: ClipPathTypes.POLYGON,
  85. style: 'polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)',
  86. createPath: (width: number, height: number) => {
  87. return `M ${width * 0.5} 0 L ${width} ${height * 0.5} L ${width * 0.5} ${height} L 0 ${height * 0.5} Z`;
  88. },
  89. },
  90. pentagon: {
  91. name: '五边形',
  92. type: ClipPathTypes.POLYGON,
  93. style: 'polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%)',
  94. createPath: (width: number, height: number) => {
  95. return `M ${width * 0.5} 0 L ${width} ${0.38 * height} L ${0.82 * width} ${height} L ${0.18 * width} ${height} L 0 ${0.38 * height} Z`;
  96. },
  97. },
  98. hexagon: {
  99. name: '六边形',
  100. type: ClipPathTypes.POLYGON,
  101. style: 'polygon(20% 0%, 80% 0%, 100% 50%, 80% 100%, 20% 100%, 0% 50%)',
  102. createPath: (width: number, height: number) => {
  103. return `M ${width * 0.2} 0 L ${width * 0.8} 0 L ${width} ${height * 0.5} L ${width * 0.8} ${height} L ${width * 0.2} ${height} L 0 ${height * 0.5} Z`;
  104. },
  105. },
  106. heptagon: {
  107. name: '七边形',
  108. type: ClipPathTypes.POLYGON,
  109. style: 'polygon(50% 0%, 90% 20%, 100% 60%, 75% 100%, 25% 100%, 0% 60%, 10% 20%)',
  110. createPath: (width: number, height: number) => {
  111. return `M ${width * 0.5} 0 L ${width * 0.9} ${height * 0.2} L ${width} ${height * 0.6} L ${width * 0.75} ${height} L ${width * 0.25} ${height} L 0 ${height * 0.6} L ${width * 0.1} ${height * 0.2} Z`;
  112. },
  113. },
  114. octagon: {
  115. name: '八边形',
  116. type: ClipPathTypes.POLYGON,
  117. style: 'polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%)',
  118. createPath: (width: number, height: number) => {
  119. return `M ${width * 0.3} 0 L ${width * 0.7} 0 L ${width} ${height * 0.3} L ${width} ${height * 0.7} L ${width * 0.7} ${height} L ${width * 0.3} ${height} L 0 ${height * 0.7} L 0 ${height * 0.3} Z`;
  120. },
  121. },
  122. chevron: {
  123. name: 'V形',
  124. type: ClipPathTypes.POLYGON,
  125. style: 'polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 25% 50%, 0% 0%)',
  126. createPath: (width: number, height: number) => {
  127. return `M ${width * 0.75} 0 L ${width} ${height * 0.5} L ${width * 0.75} ${height} L 0 ${height} L ${width * 0.25} ${height * 0.5} L 0 0 Z`;
  128. },
  129. },
  130. point: {
  131. name: '点',
  132. type: ClipPathTypes.POLYGON,
  133. style: 'polygon(0% 0%, 75% 0%, 100% 50%, 75% 100%, 0% 100%)',
  134. createPath: (width: number, height: number) => {
  135. return `M 0 0 L ${width * 0.75} 0 L ${width} ${height * 0.5} L ${width * 0.75} ${height} L 0 ${height} Z`;
  136. },
  137. },
  138. arrow: {
  139. name: '箭头',
  140. type: ClipPathTypes.POLYGON,
  141. style: 'polygon(0% 20%, 60% 20%, 60% 0%, 100% 50%, 60% 100%, 60% 80%, 0% 80%)',
  142. createPath: (width: number, height: number) => {
  143. return `M 0 ${height * 0.2} L ${width * 0.6} ${height * 0.2} L ${width * 0.6} 0 L ${width} ${height * 0.5} L ${width * 0.6} ${height} L ${width * 0.6} ${height * 0.8} L 0 ${height * 0.8} Z`;
  144. },
  145. },
  146. parallelogram: {
  147. name: '平行四边形',
  148. type: ClipPathTypes.POLYGON,
  149. style: 'polygon(30% 0%, 100% 0%, 70% 100%, 0% 100%)',
  150. createPath: (width: number, height: number) => {
  151. return `M ${width * 0.3} 0 L ${width} 0 L ${width * 0.7} ${height} L 0 ${height} Z`;
  152. },
  153. },
  154. parallelogram2: {
  155. name: '平行四边形2',
  156. type: ClipPathTypes.POLYGON,
  157. style: 'polygon(30% 100%, 100% 100%, 70% 0%, 0% 0%)',
  158. createPath: (width: number, height: number) => {
  159. return `M ${width * 0.3} ${height} L ${width} ${height} L ${width * 0.7} 0 L 0 0 Z`;
  160. },
  161. },
  162. trapezoid: {
  163. name: '梯形',
  164. type: ClipPathTypes.POLYGON,
  165. style: 'polygon(25% 0%, 75% 0%, 100% 100%, 0% 100%)',
  166. createPath: (width: number, height: number) => {
  167. return `M ${width * 0.25} 0 L ${width * 0.75} 0 L ${width} ${height} L 0 ${height} Z`;
  168. },
  169. },
  170. trapezoid2: {
  171. name: '梯形2',
  172. type: ClipPathTypes.POLYGON,
  173. style: 'polygon(0% 0%, 100% 0%, 75% 100%, 25% 100%)',
  174. createPath: (width: number, height: number) => {
  175. return `M 0 0 L ${width} 0 L ${width * 0.75} ${height} L ${width * 0.25} ${height} Z`;
  176. },
  177. },
  178. };