select.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import { IconRotate } from "@/assets/icons";
  2. import { CompToolbars } from "@/modules/editor/objects/Toolbars";
  3. import { css } from "@linaria/core";
  4. import { defineComponent, onMounted, onUnmounted, ref , nextTick} from "vue";
  5. import { useEditor } from "../../../..";
  6. export const SelectTransfer = defineComponent({
  7. setup() {
  8. const editor = useEditor();
  9. const { controls } = editor;
  10. const { selectCtrl } = controls;
  11. const { transferStyle } = selectCtrl;
  12. const selectRectRef = ref();
  13. const rotateRef = ref();
  14. const rotateRef2 = ref();
  15. const rotateRef3 = ref();
  16. const scaleBottomrightRef = ref();
  17. const scaleBottomLeftRef = ref();
  18. const scaleTopLeftRef = ref();
  19. const scaleTopRightRef = ref();
  20. const scaleRightRef = ref();
  21. const scaleLeftRef = ref();
  22. const scaleTopRef = ref();
  23. const scaleBottomRef = ref();
  24. onMounted(()=>{
  25. nextTick(()=>{
  26. selectRectRef.value.editable = "move";
  27. rotateRef.value.editable = "rotate";
  28. rotateRef2.value.editable = "rotate";
  29. rotateRef3.value.editable = "rotate";
  30. scaleBottomrightRef.value.editable = "scaleBottomright";
  31. scaleBottomLeftRef.value.editable = "scaleBottomleft";
  32. scaleTopLeftRef.value.editable = "scaleTopleft";
  33. scaleTopRightRef.value.editable = "scaleTopright";
  34. scaleRightRef.value.editable = "scaleright"
  35. scaleLeftRef.value.editable = "scaleleft"
  36. scaleTopRef.value.editable = "scaletop"
  37. scaleBottomRef.value.editable = "scalebottom"
  38. })
  39. })
  40. return () => {
  41. return (
  42. (
  43. <div
  44. class={["absolute transfer z-1001",transferStyle.showGizmo? showgizmo:hideGizmo]}
  45. >
  46. <div class="">
  47. {/* {toolbarOpts.map((item) => {
  48. return item.getVisible.call(editor, comp) ? (
  49. <item.component
  50. class="p-4px"
  51. value={item.getValue?.(comp)}
  52. onClick={() => item.onClick.call(editor, comp)}
  53. />
  54. ) : null;
  55. })} */}
  56. </div>
  57. <div
  58. class={["absolute", selctRectStyle]}
  59. ref={selectRectRef}
  60. style={{
  61. width: transferStyle.width + "px",
  62. height: transferStyle.height + "px",
  63. transform: transferStyle.matrix,
  64. transformOrigin: `0 0`,
  65. }}
  66. >
  67. <div
  68. class={borderStyle}
  69. />
  70. <>
  71. <div
  72. class={[resizeStyle, scaleBottomRightStyle]}
  73. style={{transform: transferStyle.matrixInvert}}
  74. ref={scaleBottomrightRef}
  75. />
  76. <div
  77. class={[resizeStyle, scaleBottomLeftStyle]}
  78. style={{transform: transferStyle.matrixInvert}}
  79. ref={scaleBottomLeftRef}
  80. />
  81. <div
  82. class={[resizeStyle, scaleTopLeftStyle]}
  83. style={{transform: transferStyle.matrixInvert}}
  84. ref={scaleTopLeftRef}
  85. />
  86. <div
  87. class={[resizeStyle, scaleTopRightStyle ]}
  88. style={{transform: transferStyle.matrixInvert}}
  89. ref={scaleTopRightRef}
  90. />
  91. <div class={transformBtnsStyle} ref={rotateRef3}>
  92. <div class={transBtnStyle} ref={rotateRef} style={{transform: transferStyle.matrixInvert}} >
  93. <IconRotate ref={rotateRef2} />
  94. </div>
  95. </div>
  96. <div
  97. class={[resizeHeightBtnCls, scaleTopCls]}
  98. ref={scaleTopRef}
  99. />
  100. <div
  101. class={ [resizeHeightBtnCls, scaleBottomCls]}
  102. ref={scaleBottomRef}
  103. />
  104. <div
  105. class={ [resizeWidthBtnCls, scaleRightCls]}
  106. ref={scaleRightRef}
  107. />
  108. <div
  109. class={ [resizeWidthBtnCls, scaleLeftCls]}
  110. ref={scaleLeftRef}
  111. />
  112. </>
  113. </div>
  114. </div>
  115. )
  116. );
  117. };
  118. },
  119. });
  120. const selctRectStyle = css`
  121. pointer-events: none;
  122. `
  123. const showgizmo = css`
  124. display: block;
  125. left: 0;
  126. top: 0;
  127. /* pointer-events: none; */
  128. `
  129. const hideGizmo = css`
  130. display: none;
  131. `
  132. const borderStyle = css`
  133. position: absolute;
  134. top: 0;
  135. left: 0;
  136. width: 100%;
  137. height: 100%;
  138. outline: 2px solid @inf-primary-color;
  139. pointer-events: none;
  140. z-index: 999;
  141. `;
  142. const resizeStyle = css`
  143. position: absolute;
  144. width: 16px;
  145. height: 16px;
  146. border-radius: 50%;
  147. background-color: #fff;
  148. z-index: 999;
  149. transform: translate(50%, 50%);
  150. pointer-events: auto;
  151. box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.2);
  152. cursor: nwse-resize;
  153. &:hover {
  154. border-color: @inf-primary-color;
  155. }
  156. `;
  157. const scaleBottomRightStyle = css`
  158. bottom: -8px;
  159. right: -8px;
  160. `
  161. const scaleBottomLeftStyle = css`
  162. bottom: -8px;
  163. left: -8px;
  164. `
  165. const scaleTopLeftStyle = css`
  166. top: -8px;
  167. left: -8px;
  168. `
  169. const scaleTopRightStyle = css`
  170. top: -8px;
  171. right: -8px;
  172. `
  173. const transformBtnsStyle = css`
  174. @apply space-x-10px whitespace-nowrap;
  175. position: absolute;
  176. bottom: 0;
  177. left: 50%;
  178. font-size: 16px;
  179. z-index: 999;
  180. transform: translate(-50%, 50px);
  181. pointer-events: auto;
  182. `;
  183. const transBtnStyle = css`
  184. display: inline-block;
  185. width: 36px;
  186. height: 36px;
  187. border-radius: 50%;
  188. background-color: #fff;
  189. text-align: center;
  190. line-height: 36px;
  191. font-size: 20px;
  192. color: #333;
  193. @apply shadow cursor-move;
  194. &:hover {
  195. color: #fff;
  196. background-color: @inf-primary-color;
  197. }
  198. `;
  199. const toolbarStyle = css`
  200. @apply bg-white shadow rounded space-x-4px p-4px whitespace-nowrap;
  201. position: absolute;
  202. top: 0;
  203. left: 50%;
  204. transform: translate(-50%, -60px);
  205. z-index: 999;
  206. `;
  207. const resizeHeightBtnCls = css`
  208. position: absolute;
  209. width: 30px;
  210. height: 8px;
  211. border-radius: 4px;
  212. left: 50%;
  213. transform: translate(-50%, -4px);
  214. pointer-events: auto;
  215. cursor: ns-resize;
  216. background: rgba(255, 255, 255, 0.3);
  217. &:hover {
  218. background: @inf-primary-color;
  219. }
  220. @apply shadow;
  221. z-index: 999;
  222. `;
  223. const scaleTopCls = css`
  224. top: 0;
  225. transform: translate(-50%, -4px);
  226. `;
  227. const scaleBottomCls = css`
  228. bottom: 0;
  229. transform: translate(-50%, 4px);
  230. `;
  231. const resizeWidthBtnCls = css`
  232. position: absolute;
  233. width: 8px;
  234. height: 30px;
  235. border-radius: 4px;
  236. pointer-events: auto;
  237. cursor: ew-resize;
  238. background: rgba(255, 255, 255, 0.3);
  239. &:hover {
  240. background: @inf-primary-color;
  241. }
  242. @apply shadow;
  243. z-index: 999;
  244. `;
  245. const scaleRightCls = css`
  246. right: 0;
  247. top: 50%;
  248. transform: translate(4px, -50%);
  249. `;
  250. const scaleLeftCls = css`
  251. left: 0;
  252. top: 50%;
  253. transform: translate(-4px, -50%);
  254. `;