streamCard.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import { css } from "@linaria/core";
  2. import { defineComponent, onMounted, onUnmounted } from "vue";
  3. import { useEditor } from "../../../..";
  4. import { IconMove, IconClear, IconAdd, IconResizeY } from "@/assets/icons";
  5. import { TransferCtrl } from "@/modules/editor/controllers/TransferCtrl";
  6. export const StreamCardTransfer = defineComponent({
  7. setup() {
  8. const editor = useEditor();
  9. const { store, helper } = editor;
  10. const streamCardTransferCtrl = new TransferCtrl(editor);
  11. onMounted(() => {
  12. const pageEl = helper.findRootComp()?.$el;
  13. if (pageEl) {
  14. streamCardTransferCtrl.currComp = store.currStreamCard;
  15. streamCardTransferCtrl.pageEl = pageEl.firstChild as any;
  16. streamCardTransferCtrl.compEl = streamCardTransferCtrl.currComp.$el;
  17. streamCardTransferCtrl.observe();
  18. }
  19. });
  20. onUnmounted(() => {
  21. streamCardTransferCtrl.destroy();
  22. });
  23. return () => {
  24. const transferStyle = streamCardTransferCtrl.transferStyle;
  25. return (
  26. transferStyle.width && (
  27. <div
  28. class="transfer absolute"
  29. style={{
  30. top: transferStyle.top,
  31. left: transferStyle.left,
  32. width: transferStyle.width,
  33. }}
  34. >
  35. <div
  36. class={borderStyle}
  37. style={{
  38. width: transferStyle.width,
  39. height: transferStyle.height,
  40. }}
  41. />
  42. <div
  43. class={resizeHeightBtnCls}
  44. style={{ top: transferStyle.height }}
  45. onMousedown={(e) => {
  46. e.stopPropagation();
  47. streamCardTransferCtrl.mousedown(e, "resizeY", store.currStreamCard)
  48. }
  49. }
  50. >
  51. <IconResizeY />
  52. </div>
  53. {/* <div class={hudStyle}>
  54. <IconMove class="draganchor" />
  55. <IconClear />
  56. <IconAdd />
  57. </div> */}
  58. </div>
  59. )
  60. );
  61. };
  62. },
  63. });
  64. const borderStyle = css`
  65. position: absolute;
  66. top: 0;
  67. left: 0;
  68. width: 100%;
  69. height: 100%;
  70. outline: 2px solid @inf-primary-color;
  71. pointer-events: none;
  72. z-index: 999;
  73. box-shadow: 0 0 0 3000px rgba(0, 0, 0, 0.4);
  74. `;
  75. const hudStyle = css`
  76. position: absolute;
  77. top: 0px;
  78. left: -46px;
  79. background-color: white;
  80. flex-direction: column;
  81. color: black;
  82. display: flex;
  83. font-size: 12px;
  84. width: 28px;
  85. align-items: center;
  86. border-radius: 4px;
  87. .inficon {
  88. padding: 8px;
  89. }
  90. z-index: 1000;
  91. `;
  92. const resizeStyle = css`
  93. position: absolute;
  94. bottom: 0;
  95. right: 0;
  96. width: 16px;
  97. height: 16px;
  98. border-radius: 50%;
  99. background-color: #fff;
  100. z-index: 999;
  101. transform: translate(50%, 50%);
  102. box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.2);
  103. cursor: nwse-resize;
  104. &:hover {
  105. border-color: @inf-primary-color;
  106. }
  107. `;
  108. const transformBtnsStyle = css`
  109. @apply space-x-10px whitespace-nowrap;
  110. position: absolute;
  111. bottom: 0;
  112. left: 50%;
  113. font-size: 16px;
  114. z-index: 999;
  115. transform: translate(-50%, 50px);
  116. `;
  117. const transBtnStyle = css`
  118. display: inline-block;
  119. width: 36px;
  120. height: 36px;
  121. border-radius: 50%;
  122. background-color: #fff;
  123. text-align: center;
  124. line-height: 36px;
  125. font-size: 20px;
  126. color: #333;
  127. @apply shadow cursor-move;
  128. &:hover {
  129. color: #fff;
  130. background-color: @inf-primary-color;
  131. }
  132. `;
  133. const toolbarStyle = css`
  134. @apply bg-white shadow rounded space-x-4px p-4px whitespace-nowrap;
  135. position: absolute;
  136. top: 0;
  137. left: 50%;
  138. transform: translate(-50%, -40px);
  139. z-index: 999;
  140. `;
  141. const resizeHeightBtnCls = css`
  142. position: absolute;
  143. width: 30px;
  144. height: 8px;
  145. border-radius: 4px;
  146. left: 50%;
  147. transform: translate(-50%, -4px);
  148. cursor: ns-resize;
  149. background: rgba(255, 255, 255, 0.3);
  150. &:hover {
  151. background: @inf-primary-color;
  152. }
  153. @apply shadow;
  154. z-index: 999;
  155. display: flex;
  156. justify-content: center;
  157. .inficon {
  158. font-size: 20px;
  159. position: relative;
  160. top: -6px;
  161. }
  162. `;
  163. const resizeWidthBtnCls = css`
  164. position: absolute;
  165. width: 8px;
  166. height: 30px;
  167. border-radius: 4px;
  168. right: 0;
  169. transform: translate(4px, -50%);
  170. cursor: ew-resize;
  171. background: rgba(255, 255, 255, 0.3);
  172. &:hover {
  173. background: @inf-primary-color;
  174. }
  175. @apply shadow;
  176. z-index: 999;
  177. `;