@witchcraft/layout 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/README.md +474 -0
  2. package/dist/module.d.mts +14 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +26 -0
  5. package/dist/runtime/components/LayoutDecos.d.vue.ts +0 -0
  6. package/dist/runtime/components/LayoutDecos.vue +54 -0
  7. package/dist/runtime/components/LayoutDecos.vue.d.ts +0 -0
  8. package/dist/runtime/components/LayoutEdges.d.vue.ts +0 -0
  9. package/dist/runtime/components/LayoutEdges.vue +145 -0
  10. package/dist/runtime/components/LayoutEdges.vue.d.ts +0 -0
  11. package/dist/runtime/components/LayoutFrame.d.vue.ts +0 -0
  12. package/dist/runtime/components/LayoutFrame.vue +41 -0
  13. package/dist/runtime/components/LayoutFrame.vue.d.ts +0 -0
  14. package/dist/runtime/components/LayoutShapeSquare.d.vue.ts +0 -0
  15. package/dist/runtime/components/LayoutShapeSquare.vue +36 -0
  16. package/dist/runtime/components/LayoutShapeSquare.vue.d.ts +0 -0
  17. package/dist/runtime/components/LayoutWindow.d.vue.ts +0 -0
  18. package/dist/runtime/components/LayoutWindow.vue +183 -0
  19. package/dist/runtime/components/LayoutWindow.vue.d.ts +0 -0
  20. package/dist/runtime/composables/useFrames.d.ts +0 -0
  21. package/dist/runtime/composables/useFrames.js +184 -0
  22. package/dist/runtime/demo/App.d.vue.ts +0 -0
  23. package/dist/runtime/demo/App.vue +121 -0
  24. package/dist/runtime/demo/App.vue.d.ts +0 -0
  25. package/dist/runtime/demo/DemoControls.d.vue.ts +0 -0
  26. package/dist/runtime/demo/DemoControls.vue +14 -0
  27. package/dist/runtime/demo/DemoControls.vue.d.ts +0 -0
  28. package/dist/runtime/demo/README.md +1 -0
  29. package/dist/runtime/demo/main.d.ts +0 -0
  30. package/dist/runtime/demo/main.js +4 -0
  31. package/dist/runtime/demo/sharedLayoutInstance.d.ts +0 -0
  32. package/dist/runtime/demo/sharedLayoutInstance.js +5 -0
  33. package/dist/runtime/demo/tailwind.css +1 -0
  34. package/dist/runtime/drag/CloseAction.d.ts +0 -0
  35. package/dist/runtime/drag/CloseAction.js +121 -0
  36. package/dist/runtime/drag/DragActionHandler.d.ts +0 -0
  37. package/dist/runtime/drag/DragActionHandler.js +83 -0
  38. package/dist/runtime/drag/DragDirectionStore.d.ts +0 -0
  39. package/dist/runtime/drag/DragDirectionStore.js +45 -0
  40. package/dist/runtime/drag/SplitAction.d.ts +0 -0
  41. package/dist/runtime/drag/SplitAction.js +110 -0
  42. package/dist/runtime/drag/types.d.ts +0 -0
  43. package/dist/runtime/drag/types.js +0 -0
  44. package/dist/runtime/helpers/addPointsToIntersection.d.ts +0 -0
  45. package/dist/runtime/helpers/addPointsToIntersection.js +7 -0
  46. package/dist/runtime/helpers/assertEdgeSorted.d.ts +0 -0
  47. package/dist/runtime/helpers/assertEdgeSorted.js +7 -0
  48. package/dist/runtime/helpers/assertItemIn.d.ts +0 -0
  49. package/dist/runtime/helpers/assertItemIn.js +8 -0
  50. package/dist/runtime/helpers/assertItemNotIn.d.ts +0 -0
  51. package/dist/runtime/helpers/assertItemNotIn.js +7 -0
  52. package/dist/runtime/helpers/assertLayoutHasActiveWindow.d.ts +0 -0
  53. package/dist/runtime/helpers/assertLayoutHasActiveWindow.js +7 -0
  54. package/dist/runtime/helpers/assertValidWinAndFrame.d.ts +0 -0
  55. package/dist/runtime/helpers/assertValidWinAndFrame.js +5 -0
  56. package/dist/runtime/helpers/assertValidWinAndFrameIds.d.ts +0 -0
  57. package/dist/runtime/helpers/assertValidWinAndFrameIds.js +6 -0
  58. package/dist/runtime/helpers/assertWindowHasActiveFrame.d.ts +0 -0
  59. package/dist/runtime/helpers/assertWindowHasActiveFrame.js +7 -0
  60. package/dist/runtime/helpers/clampNumber.d.ts +0 -0
  61. package/dist/runtime/helpers/clampNumber.js +3 -0
  62. package/dist/runtime/helpers/cloneFrame.d.ts +0 -0
  63. package/dist/runtime/helpers/cloneFrame.js +3 -0
  64. package/dist/runtime/helpers/cloneFrames.d.ts +0 -0
  65. package/dist/runtime/helpers/cloneFrames.js +16 -0
  66. package/dist/runtime/helpers/containsEdge.d.ts +0 -0
  67. package/dist/runtime/helpers/containsEdge.js +13 -0
  68. package/dist/runtime/helpers/convertLayoutWindowToWorkspace.d.ts +0 -0
  69. package/dist/runtime/helpers/convertLayoutWindowToWorkspace.js +10 -0
  70. package/dist/runtime/helpers/copySize.d.ts +0 -0
  71. package/dist/runtime/helpers/copySize.js +5 -0
  72. package/dist/runtime/helpers/createEdge.d.ts +0 -0
  73. package/dist/runtime/helpers/createEdge.js +13 -0
  74. package/dist/runtime/helpers/dirToOrientation.d.ts +0 -0
  75. package/dist/runtime/helpers/dirToOrientation.js +10 -0
  76. package/dist/runtime/helpers/dirToSide.d.ts +0 -0
  77. package/dist/runtime/helpers/dirToSide.js +5 -0
  78. package/dist/runtime/helpers/doEdgesOverlap.d.ts +0 -0
  79. package/dist/runtime/helpers/doEdgesOverlap.js +22 -0
  80. package/dist/runtime/helpers/doesEdgeContinueEdge.d.ts +0 -0
  81. package/dist/runtime/helpers/doesEdgeContinueEdge.js +17 -0
  82. package/dist/runtime/helpers/edgeToPoints.d.ts +0 -0
  83. package/dist/runtime/helpers/edgeToPoints.js +3 -0
  84. package/dist/runtime/helpers/findDraggableEdge.d.ts +0 -0
  85. package/dist/runtime/helpers/findDraggableEdge.js +13 -0
  86. package/dist/runtime/helpers/findFrameDraggableEdges.d.ts +0 -0
  87. package/dist/runtime/helpers/findFrameDraggableEdges.js +18 -0
  88. package/dist/runtime/helpers/frameToEdges.d.ts +0 -0
  89. package/dist/runtime/helpers/frameToEdges.js +21 -0
  90. package/dist/runtime/helpers/frameToPoints.d.ts +0 -0
  91. package/dist/runtime/helpers/frameToPoints.js +7 -0
  92. package/dist/runtime/helpers/getEdgeOrientation.d.ts +0 -0
  93. package/dist/runtime/helpers/getEdgeOrientation.js +4 -0
  94. package/dist/runtime/helpers/getEdgeSharedDirection.d.ts +0 -0
  95. package/dist/runtime/helpers/getEdgeSharedDirection.js +7 -0
  96. package/dist/runtime/helpers/getEdgeSide.d.ts +0 -0
  97. package/dist/runtime/helpers/getEdgeSide.js +16 -0
  98. package/dist/runtime/helpers/getFrameById.d.ts +0 -0
  99. package/dist/runtime/helpers/getFrameById.js +5 -0
  100. package/dist/runtime/helpers/getFrameConstant.d.ts +0 -0
  101. package/dist/runtime/helpers/getFrameConstant.js +15 -0
  102. package/dist/runtime/helpers/getIntersections.d.ts +0 -0
  103. package/dist/runtime/helpers/getIntersections.js +63 -0
  104. package/dist/runtime/helpers/getIntersectionsCss.d.ts +0 -0
  105. package/dist/runtime/helpers/getIntersectionsCss.js +56 -0
  106. package/dist/runtime/helpers/getMoveEdgeInfo.d.ts +0 -0
  107. package/dist/runtime/helpers/getMoveEdgeInfo.js +42 -0
  108. package/dist/runtime/helpers/getResizeLimit.d.ts +0 -0
  109. package/dist/runtime/helpers/getResizeLimit.js +39 -0
  110. package/dist/runtime/helpers/getShapeSquareCss.d.ts +0 -0
  111. package/dist/runtime/helpers/getShapeSquareCss.js +17 -0
  112. package/dist/runtime/helpers/getSideTouching.d.ts +0 -0
  113. package/dist/runtime/helpers/getSideTouching.js +7 -0
  114. package/dist/runtime/helpers/getVisualEdgeCss.d.ts +0 -0
  115. package/dist/runtime/helpers/getVisualEdgeCss.js +40 -0
  116. package/dist/runtime/helpers/getVisualEdges.d.ts +0 -0
  117. package/dist/runtime/helpers/getVisualEdges.js +89 -0
  118. package/dist/runtime/helpers/getVisualEdgesCss.d.ts +0 -0
  119. package/dist/runtime/helpers/getVisualEdgesCss.js +4 -0
  120. package/dist/runtime/helpers/getWinAndFrameById.d.ts +0 -0
  121. package/dist/runtime/helpers/getWinAndFrameById.js +14 -0
  122. package/dist/runtime/helpers/getWinByFrameUuid.d.ts +0 -0
  123. package/dist/runtime/helpers/getWinByFrameUuid.js +13 -0
  124. package/dist/runtime/helpers/getWinById.d.ts +0 -0
  125. package/dist/runtime/helpers/getWinById.js +5 -0
  126. package/dist/runtime/helpers/getWindowConstant.d.ts +0 -0
  127. package/dist/runtime/helpers/getWindowConstant.js +14 -0
  128. package/dist/runtime/helpers/inRange.d.ts +0 -0
  129. package/dist/runtime/helpers/inRange.js +3 -0
  130. package/dist/runtime/helpers/index.d.ts +0 -0
  131. package/dist/runtime/helpers/index.js +62 -0
  132. package/dist/runtime/helpers/isEdgeEqual.d.ts +0 -0
  133. package/dist/runtime/helpers/isEdgeEqual.js +11 -0
  134. package/dist/runtime/helpers/isEdgeParallel.d.ts +0 -0
  135. package/dist/runtime/helpers/isEdgeParallel.js +7 -0
  136. package/dist/runtime/helpers/isPointEqual.d.ts +0 -0
  137. package/dist/runtime/helpers/isPointEqual.js +3 -0
  138. package/dist/runtime/helpers/isSizeAboveMin.d.ts +0 -0
  139. package/dist/runtime/helpers/isSizeAboveMin.js +3 -0
  140. package/dist/runtime/helpers/isSizeEqual.d.ts +0 -0
  141. package/dist/runtime/helpers/isSizeEqual.js +3 -0
  142. package/dist/runtime/helpers/isWindowEdge.d.ts +0 -0
  143. package/dist/runtime/helpers/isWindowEdge.js +7 -0
  144. package/dist/runtime/helpers/isWindowEdgePoint.d.ts +0 -0
  145. package/dist/runtime/helpers/isWindowEdgePoint.js +5 -0
  146. package/dist/runtime/helpers/moveEdge.d.ts +0 -0
  147. package/dist/runtime/helpers/moveEdge.js +8 -0
  148. package/dist/runtime/helpers/numberToScaledPercent.d.ts +0 -0
  149. package/dist/runtime/helpers/numberToScaledPercent.js +5 -0
  150. package/dist/runtime/helpers/numberToScaledSize.d.ts +0 -0
  151. package/dist/runtime/helpers/numberToScaledSize.js +19 -0
  152. package/dist/runtime/helpers/oppositeSide.d.ts +0 -0
  153. package/dist/runtime/helpers/oppositeSide.js +30 -0
  154. package/dist/runtime/helpers/resizeByEdge.d.ts +0 -0
  155. package/dist/runtime/helpers/resizeByEdge.js +29 -0
  156. package/dist/runtime/helpers/sideToDirection.d.ts +0 -0
  157. package/dist/runtime/helpers/sideToDirection.js +11 -0
  158. package/dist/runtime/helpers/sideToOrientation.d.ts +0 -0
  159. package/dist/runtime/helpers/sideToOrientation.js +10 -0
  160. package/dist/runtime/helpers/splitEdge.d.ts +0 -0
  161. package/dist/runtime/helpers/splitEdge.js +20 -0
  162. package/dist/runtime/helpers/toCoord.d.ts +0 -0
  163. package/dist/runtime/helpers/toCoord.js +10 -0
  164. package/dist/runtime/helpers/toId.d.ts +0 -0
  165. package/dist/runtime/helpers/toId.js +4 -0
  166. package/dist/runtime/helpers/toWindowCoord.d.ts +0 -0
  167. package/dist/runtime/helpers/toWindowCoord.js +14 -0
  168. package/dist/runtime/helpers/unionEdges.d.ts +0 -0
  169. package/dist/runtime/helpers/unionEdges.js +8 -0
  170. package/dist/runtime/helpers/updateWindowSizeWithEvent.d.ts +0 -0
  171. package/dist/runtime/helpers/updateWindowSizeWithEvent.js +8 -0
  172. package/dist/runtime/index.d.ts +0 -0
  173. package/dist/runtime/index.js +5 -0
  174. package/dist/runtime/layout/closeFrame.d.ts +0 -0
  175. package/dist/runtime/layout/closeFrame.js +13 -0
  176. package/dist/runtime/layout/closeFrames.d.ts +0 -0
  177. package/dist/runtime/layout/closeFrames.js +8 -0
  178. package/dist/runtime/layout/createSplitDecoEdge.d.ts +0 -0
  179. package/dist/runtime/layout/createSplitDecoEdge.js +24 -0
  180. package/dist/runtime/layout/createSplitDecoFromDrag.d.ts +0 -0
  181. package/dist/runtime/layout/createSplitDecoFromDrag.js +14 -0
  182. package/dist/runtime/layout/debugFrame.d.ts +0 -0
  183. package/dist/runtime/layout/debugFrame.js +4 -0
  184. package/dist/runtime/layout/findFramesTouchingEdge.d.ts +0 -0
  185. package/dist/runtime/layout/findFramesTouchingEdge.js +33 -0
  186. package/dist/runtime/layout/findSafeSplitEdge.d.ts +0 -0
  187. package/dist/runtime/layout/findSafeSplitEdge.js +20 -0
  188. package/dist/runtime/layout/findVisualEdge.d.ts +0 -0
  189. package/dist/runtime/layout/findVisualEdge.js +9 -0
  190. package/dist/runtime/layout/frameCreate.d.ts +0 -0
  191. package/dist/runtime/layout/frameCreate.js +13 -0
  192. package/dist/runtime/layout/frameSplit.d.ts +0 -0
  193. package/dist/runtime/layout/frameSplit.js +9 -0
  194. package/dist/runtime/layout/getCloseFrameInfo.d.ts +0 -0
  195. package/dist/runtime/layout/getCloseFrameInfo.js +103 -0
  196. package/dist/runtime/layout/getFrameSplitInfo.d.ts +0 -0
  197. package/dist/runtime/layout/getFrameSplitInfo.js +40 -0
  198. package/dist/runtime/layout/getFrameTo.d.ts +0 -0
  199. package/dist/runtime/layout/getFrameTo.js +47 -0
  200. package/dist/runtime/layout/index.d.ts +0 -0
  201. package/dist/runtime/layout/index.js +22 -0
  202. package/dist/runtime/layout/isPointInFrame.d.ts +0 -0
  203. package/dist/runtime/layout/isPointInFrame.js +4 -0
  204. package/dist/runtime/layout/layoutAddWindow.d.ts +0 -0
  205. package/dist/runtime/layout/layoutAddWindow.js +4 -0
  206. package/dist/runtime/layout/layoutCreate.d.ts +0 -0
  207. package/dist/runtime/layout/layoutCreate.js +7 -0
  208. package/dist/runtime/layout/layoutRemoveWindow.d.ts +0 -0
  209. package/dist/runtime/layout/layoutRemoveWindow.js +5 -0
  210. package/dist/runtime/layout/resizeFrame.d.ts +0 -0
  211. package/dist/runtime/layout/resizeFrame.js +69 -0
  212. package/dist/runtime/layout/windowAddFrame.d.ts +0 -0
  213. package/dist/runtime/layout/windowAddFrame.js +4 -0
  214. package/dist/runtime/layout/windowCreate.d.ts +0 -0
  215. package/dist/runtime/layout/windowCreate.js +13 -0
  216. package/dist/runtime/layout/windowRemoveFrame.d.ts +0 -0
  217. package/dist/runtime/layout/windowRemoveFrame.js +5 -0
  218. package/dist/runtime/layout/windowSetActiveFrame.d.ts +0 -0
  219. package/dist/runtime/layout/windowSetActiveFrame.js +5 -0
  220. package/dist/runtime/settings.d.ts +0 -0
  221. package/dist/runtime/settings.js +54 -0
  222. package/dist/runtime/types/index.d.ts +0 -0
  223. package/dist/runtime/types/index.js +120 -0
  224. package/dist/runtime/utils/KnownError.d.ts +0 -0
  225. package/dist/runtime/utils/KnownError.js +9 -0
  226. package/dist/types.d.mts +5 -0
  227. package/package.json +153 -0
  228. package/src/module.ts +43 -0
  229. package/src/runtime/components/LayoutDecos.vue +62 -0
  230. package/src/runtime/components/LayoutEdges.vue +172 -0
  231. package/src/runtime/components/LayoutFrame.vue +47 -0
  232. package/src/runtime/components/LayoutShapeSquare.vue +38 -0
  233. package/src/runtime/components/LayoutWindow.vue +223 -0
  234. package/src/runtime/composables/useFrames.ts +251 -0
  235. package/src/runtime/demo/App.vue +139 -0
  236. package/src/runtime/demo/DemoControls.vue +17 -0
  237. package/src/runtime/demo/README.md +1 -0
  238. package/src/runtime/demo/main.ts +9 -0
  239. package/src/runtime/demo/sharedLayoutInstance.ts +7 -0
  240. package/src/runtime/demo/tailwind.css +4 -0
  241. package/src/runtime/drag/CloseAction.ts +158 -0
  242. package/src/runtime/drag/DragActionHandler.ts +146 -0
  243. package/src/runtime/drag/DragDirectionStore.ts +63 -0
  244. package/src/runtime/drag/SplitAction.ts +147 -0
  245. package/src/runtime/drag/types.ts +107 -0
  246. package/src/runtime/helpers/addPointsToIntersection.ts +9 -0
  247. package/src/runtime/helpers/assertEdgeSorted.ts +11 -0
  248. package/src/runtime/helpers/assertItemIn.ts +13 -0
  249. package/src/runtime/helpers/assertItemNotIn.ts +10 -0
  250. package/src/runtime/helpers/assertLayoutHasActiveWindow.ts +9 -0
  251. package/src/runtime/helpers/assertValidWinAndFrame.ts +16 -0
  252. package/src/runtime/helpers/assertValidWinAndFrameIds.ts +9 -0
  253. package/src/runtime/helpers/assertWindowHasActiveFrame.ts +9 -0
  254. package/src/runtime/helpers/clampNumber.ts +9 -0
  255. package/src/runtime/helpers/cloneFrame.ts +5 -0
  256. package/src/runtime/helpers/cloneFrames.ts +20 -0
  257. package/src/runtime/helpers/containsEdge.ts +16 -0
  258. package/src/runtime/helpers/convertLayoutWindowToWorkspace.ts +18 -0
  259. package/src/runtime/helpers/copySize.ts +7 -0
  260. package/src/runtime/helpers/createEdge.ts +19 -0
  261. package/src/runtime/helpers/dirToOrientation.ts +12 -0
  262. package/src/runtime/helpers/dirToSide.ts +7 -0
  263. package/src/runtime/helpers/doEdgesOverlap.ts +25 -0
  264. package/src/runtime/helpers/doesEdgeContinueEdge.ts +20 -0
  265. package/src/runtime/helpers/edgeToPoints.ts +5 -0
  266. package/src/runtime/helpers/findDraggableEdge.ts +24 -0
  267. package/src/runtime/helpers/findFrameDraggableEdges.ts +32 -0
  268. package/src/runtime/helpers/frameToEdges.ts +32 -0
  269. package/src/runtime/helpers/frameToPoints.ts +14 -0
  270. package/src/runtime/helpers/getEdgeOrientation.ts +6 -0
  271. package/src/runtime/helpers/getEdgeSharedDirection.ts +10 -0
  272. package/src/runtime/helpers/getEdgeSide.ts +27 -0
  273. package/src/runtime/helpers/getFrameById.ts +15 -0
  274. package/src/runtime/helpers/getFrameConstant.ts +22 -0
  275. package/src/runtime/helpers/getIntersections.ts +87 -0
  276. package/src/runtime/helpers/getIntersectionsCss.ts +65 -0
  277. package/src/runtime/helpers/getMoveEdgeInfo.ts +69 -0
  278. package/src/runtime/helpers/getResizeLimit.ts +60 -0
  279. package/src/runtime/helpers/getShapeSquareCss.ts +28 -0
  280. package/src/runtime/helpers/getSideTouching.ts +9 -0
  281. package/src/runtime/helpers/getVisualEdgeCss.ts +53 -0
  282. package/src/runtime/helpers/getVisualEdges.ts +155 -0
  283. package/src/runtime/helpers/getVisualEdgesCss.ts +13 -0
  284. package/src/runtime/helpers/getWinAndFrameById.ts +28 -0
  285. package/src/runtime/helpers/getWinByFrameUuid.ts +19 -0
  286. package/src/runtime/helpers/getWinById.ts +12 -0
  287. package/src/runtime/helpers/getWindowConstant.ts +21 -0
  288. package/src/runtime/helpers/inRange.ts +5 -0
  289. package/src/runtime/helpers/index.ts +64 -0
  290. package/src/runtime/helpers/isEdgeEqual.ts +14 -0
  291. package/src/runtime/helpers/isEdgeParallel.ts +10 -0
  292. package/src/runtime/helpers/isPointEqual.ts +5 -0
  293. package/src/runtime/helpers/isSizeAboveMin.ts +8 -0
  294. package/src/runtime/helpers/isSizeEqual.ts +5 -0
  295. package/src/runtime/helpers/isWindowEdge.ts +11 -0
  296. package/src/runtime/helpers/isWindowEdgePoint.ts +8 -0
  297. package/src/runtime/helpers/moveEdge.ts +21 -0
  298. package/src/runtime/helpers/numberToScaledPercent.ts +19 -0
  299. package/src/runtime/helpers/numberToScaledSize.ts +28 -0
  300. package/src/runtime/helpers/oppositeSide.ts +45 -0
  301. package/src/runtime/helpers/resizeByEdge.ts +45 -0
  302. package/src/runtime/helpers/sideToDirection.ts +15 -0
  303. package/src/runtime/helpers/sideToOrientation.ts +12 -0
  304. package/src/runtime/helpers/splitEdge.ts +23 -0
  305. package/src/runtime/helpers/toCoord.ts +13 -0
  306. package/src/runtime/helpers/toId.ts +9 -0
  307. package/src/runtime/helpers/toWindowCoord.ts +23 -0
  308. package/src/runtime/helpers/unionEdges.ts +11 -0
  309. package/src/runtime/helpers/updateWindowSizeWithEvent.ts +10 -0
  310. package/src/runtime/index.ts +5 -0
  311. package/src/runtime/layout/closeFrame.ts +33 -0
  312. package/src/runtime/layout/closeFrames.ts +14 -0
  313. package/src/runtime/layout/createSplitDecoEdge.ts +34 -0
  314. package/src/runtime/layout/createSplitDecoFromDrag.ts +24 -0
  315. package/src/runtime/layout/debugFrame.ts +6 -0
  316. package/src/runtime/layout/findFramesTouchingEdge.ts +92 -0
  317. package/src/runtime/layout/findSafeSplitEdge.ts +39 -0
  318. package/src/runtime/layout/findVisualEdge.ts +11 -0
  319. package/src/runtime/layout/frameCreate.ts +23 -0
  320. package/src/runtime/layout/frameSplit.ts +31 -0
  321. package/src/runtime/layout/getCloseFrameInfo.ts +193 -0
  322. package/src/runtime/layout/getFrameSplitInfo.ts +65 -0
  323. package/src/runtime/layout/getFrameTo.ts +65 -0
  324. package/src/runtime/layout/index.ts +24 -0
  325. package/src/runtime/layout/isPointInFrame.ts +7 -0
  326. package/src/runtime/layout/layoutAddWindow.ts +6 -0
  327. package/src/runtime/layout/layoutCreate.ts +12 -0
  328. package/src/runtime/layout/layoutRemoveWindow.ts +7 -0
  329. package/src/runtime/layout/resizeFrame.ts +106 -0
  330. package/src/runtime/layout/windowAddFrame.ts +10 -0
  331. package/src/runtime/layout/windowCreate.ts +18 -0
  332. package/src/runtime/layout/windowRemoveFrame.ts +7 -0
  333. package/src/runtime/layout/windowSetActiveFrame.ts +7 -0
  334. package/src/runtime/settings.ts +63 -0
  335. package/src/runtime/types/index.ts +293 -0
  336. package/src/runtime/utils/KnownError.ts +24 -0
@@ -0,0 +1,9 @@
1
+ import { assertItemIn } from "./assertItemIn.js"
2
+
3
+ import type { FrameId, LayoutWindows, WindowId } from "../types/index.js"
4
+
5
+ export function assertValidWinAndFrameIds(windows: LayoutWindows, winId?: WindowId, frameId?: FrameId): void {
6
+ assertItemIn(windows, winId)
7
+ const win = windows[winId]
8
+ assertItemIn(win.frames, frameId)
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { LayoutWindow } from "../types/index.js"
2
+ import { LAYOUT_ERROR } from "../types/index.js"
3
+ import { KnownError } from "../utils/KnownError.js"
4
+
5
+ export function assertWindowHasActiveFrame(win: LayoutWindow): asserts win is Omit<LayoutWindow, "activeFrame"> & { activeFrame: NonNullable<LayoutWindow["activeFrame"]> } {
6
+ if (win.activeFrame === undefined) {
7
+ throw new KnownError(LAYOUT_ERROR.NO_ACTIVE_WINDOW, "Layout has no active window.", {})
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ // todo move to utils
2
+
3
+ export function clampNumber(
4
+ num: number,
5
+ lowerLimit: number,
6
+ upperLimit: number
7
+ ): number {
8
+ return num <= lowerLimit ? lowerLimit : num >= upperLimit ? upperLimit : num
9
+ }
@@ -0,0 +1,5 @@
1
+ import type { LayoutFrame } from "../types/index.js"
2
+
3
+ export function cloneFrame(frame: LayoutFrame): LayoutFrame {
4
+ return { ...frame }
5
+ }
@@ -0,0 +1,20 @@
1
+ import { isArray } from "@alanscodelog/utils/isArray"
2
+
3
+ import { cloneFrame } from "./cloneFrame.js"
4
+
5
+ import type { LayoutFrame } from "../types/index.js"
6
+
7
+ export function cloneFrames<T extends Record<string, LayoutFrame> | LayoutFrame[]>(frames: T): T {
8
+ const framesIsArray = isArray(frames)
9
+ const clone: any = framesIsArray ? [] : {}
10
+ if (framesIsArray) {
11
+ for (const frame of frames) {
12
+ clone.push(cloneFrame(frame))
13
+ }
14
+ } else {
15
+ for (const id of Object.keys(frames)) {
16
+ clone[id] = cloneFrame(frames[id]!)
17
+ }
18
+ }
19
+ return clone
20
+ }
@@ -0,0 +1,16 @@
1
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
2
+ import { isEdgeParallel } from "./isEdgeParallel.js"
3
+
4
+ import type { Edge, Orientation } from "../types/index.js"
5
+
6
+ export function containsEdge(edge: Edge, limitEdge: Edge, dir?: Orientation): boolean {
7
+ dir ??= getEdgeOrientation(edge)
8
+ if (!isEdgeParallel(edge, limitEdge)) return false
9
+ if (dir === "horizontal") {
10
+ if (limitEdge.startY !== edge.startY) return false
11
+ return limitEdge.startX <= edge.startX && edge.endX <= limitEdge.endX
12
+ } else {
13
+ if (limitEdge.startX !== edge.startX) return false
14
+ return limitEdge.startY <= edge.startY && edge.endY <= limitEdge.endY
15
+ }
16
+ }
@@ -0,0 +1,18 @@
1
+ import { cloneDeep } from "es-toolkit"
2
+
3
+ import type {
4
+ LayoutWindow,
5
+ Workspace
6
+ } from "../types/index.js"
7
+
8
+ export function convertLayoutWindowToWorkspace(layout: LayoutWindow | Workspace): Workspace {
9
+ // clone to avoid accidental property removal issues
10
+ // cast to be able to delete the properties
11
+ const l = cloneDeep(layout) as Partial<LayoutWindow>
12
+ delete l.id
13
+ delete l.pxHeight
14
+ delete l.pxWidth
15
+ delete l.pxX
16
+ delete l.pxY
17
+ return l as Workspace
18
+ }
@@ -0,0 +1,7 @@
1
+ import type { Size } from "../types/index.js"
2
+
3
+ export function copySize<TFrom extends Size, TTo extends Size>(from: TFrom, to: TTo): TTo {
4
+ to.width = from.width
5
+ to.height = from.height
6
+ return from as any
7
+ }
@@ -0,0 +1,19 @@
1
+ import type { Edge } from "../types/index.js"
2
+
3
+ /**
4
+ * Ensures the edge given is sorted (start < end coordinates). Mutates given edge if it's not.
5
+ */
6
+
7
+ export function createEdge(edge: Edge): Edge {
8
+ if (edge.startX > edge.endX) {
9
+ const end = edge.endX
10
+ edge.endX = edge.startX
11
+ edge.startX = end
12
+ }
13
+ if (edge.startY > edge.endY) {
14
+ const end = edge.endY
15
+ edge.endY = edge.startY
16
+ edge.startY = end
17
+ }
18
+ return edge
19
+ }
@@ -0,0 +1,12 @@
1
+ import type { Direction, Orientation } from "../types/index.js"
2
+
3
+ export function dirToOrientation(dir: Direction): Orientation {
4
+ switch (dir) {
5
+ case "left":
6
+ case "right":
7
+ return "horizontal"
8
+ case "up":
9
+ case "down":
10
+ return "vertical"
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ import type { Direction, EdgeSide } from "../types/index.js"
2
+
3
+ export function dirToSide<T extends Direction>(dir: T): T extends "up" ? "top" : T extends "down" ? "bottom" : T extends "left" | "right" ? T : EdgeSide {
4
+ if (dir === "up") return "top" satisfies EdgeSide as any
5
+ if (dir === "down") return "bottom" satisfies EdgeSide as any
6
+ return dir satisfies EdgeSide as any
7
+ }
@@ -0,0 +1,25 @@
1
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
2
+ import { inRange } from "./inRange.js"
3
+ import { isEdgeParallel } from "./isEdgeParallel.js"
4
+
5
+ import type { Edge, Orientation } from "../types/index.js"
6
+
7
+ export function doEdgesOverlap(edgeA: Edge, edgeB: Edge, dir?: Orientation): boolean {
8
+ dir ??= getEdgeOrientation(edgeA)
9
+ if (!isEdgeParallel(edgeA, edgeB)) return false
10
+ if (dir === "horizontal") {
11
+ if (edgeA.startY !== edgeB.startY) return false
12
+ const leftMost = edgeA.startX <= edgeB.startX ? edgeA : edgeB
13
+ const rightMost = edgeB === leftMost ? edgeA : edgeB
14
+ const startOverlaps = inRange(leftMost.endX, rightMost.startX, rightMost.endX)
15
+ const endOverlaps = inRange(rightMost.startX, leftMost.startX, leftMost.endX)
16
+ return startOverlaps || endOverlaps
17
+ } else {
18
+ if (edgeA.startX !== edgeB.startX) return false
19
+ const topMost = edgeA.startY <= edgeB.startY ? edgeA : edgeB
20
+ const bottomMost = edgeB === topMost ? edgeA : edgeB
21
+ const startOverlaps = inRange(topMost.endY, bottomMost.startY, bottomMost.endY)
22
+ const endOverlaps = inRange(bottomMost.startY, topMost.startY, topMost.endY)
23
+ return startOverlaps || endOverlaps
24
+ }
25
+ }
@@ -0,0 +1,20 @@
1
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
2
+ import { isEdgeParallel } from "./isEdgeParallel.js"
3
+
4
+ import type { Edge, Orientation } from "../types/index.js"
5
+
6
+ export function doesEdgeContinueEdge(edgeA: Edge, edgeB: Edge, dir?: Orientation): boolean {
7
+ dir ??= getEdgeOrientation(edgeA)
8
+ if (!isEdgeParallel(edgeA, edgeB)) return false
9
+ if (dir === "horizontal") {
10
+ if (edgeA.startY !== edgeB.startY) return false
11
+ const leftMost = edgeA.startX <= edgeB.startX ? edgeA : edgeB
12
+ const rightMost = edgeB === leftMost ? edgeA : edgeB
13
+ return leftMost.endX === rightMost.startX
14
+ } else {
15
+ if (edgeA.startX !== edgeB.startX) return false
16
+ const topMost = edgeA.startY <= edgeB.startY ? edgeA : edgeB
17
+ const bottomMost = edgeB === topMost ? edgeA : edgeB
18
+ return topMost.endY === bottomMost.startY
19
+ }
20
+ }
@@ -0,0 +1,5 @@
1
+ import type { Edge, Point } from "../types/index.js"
2
+
3
+ export function edgeToPoints(edge: Edge): Point[] {
4
+ return [{ x: edge.startX, y: edge.startY }, { x: edge.endX, y: edge.endY }]
5
+ }
@@ -0,0 +1,24 @@
1
+ import { containsEdge } from "./containsEdge.js"
2
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
3
+ import { isEdgeEqual } from "./isEdgeEqual.js"
4
+
5
+ import type { Edge, Orientation } from "../types/index.js"
6
+
7
+ export function findDraggableEdge(
8
+ edge: Edge,
9
+ edges: Edge[],
10
+ /** Whether the edge must match exactly and does not "contain/touch" another frame. */
11
+ exact: boolean = true,
12
+ edgeOrientation?: Orientation
13
+ ): Edge | undefined {
14
+ edgeOrientation ??= getEdgeOrientation(edge)
15
+ for (const otherEdge of edges) {
16
+ const didFindEdge = exact
17
+ ? isEdgeEqual(edge, otherEdge, edgeOrientation)
18
+ : containsEdge(edge, otherEdge, edgeOrientation)
19
+ if (didFindEdge) {
20
+ return otherEdge
21
+ }
22
+ }
23
+ return undefined
24
+ }
@@ -0,0 +1,32 @@
1
+ import { findDraggableEdge } from "./findDraggableEdge.js"
2
+ import { frameToEdges } from "./frameToEdges.js"
3
+ import { isWindowEdge } from "./isWindowEdge.js"
4
+ import { sideToOrientation } from "./sideToOrientation.js"
5
+
6
+ import type {
7
+ Edge,
8
+ EdgeSide, LayoutFrame
9
+ } from "../types/index.js"
10
+
11
+ export function findFrameDraggableEdges(
12
+ frame: LayoutFrame,
13
+ edges: Edge[],
14
+ /** See {@link findDraggableEdge} */
15
+ exact: boolean = true,
16
+ sides: EdgeSide[] = ["left", "right", "top", "bottom"]
17
+ ): { edge: Edge, side: EdgeSide }[] | undefined {
18
+ const frameEdges = frameToEdges(frame)
19
+ const res = []
20
+ for (const side of sides) {
21
+ const edge = frameEdges[side]
22
+ const edgeDirection = sideToOrientation(side)
23
+ const isWinEdge = isWindowEdge(edge, edgeDirection)
24
+
25
+ if (isWinEdge) continue
26
+ const maybeEdge = findDraggableEdge(edge, edges, exact, edgeDirection)
27
+
28
+ if (maybeEdge) res.push({ edge: maybeEdge, side })
29
+ }
30
+ if (res.length > 0) return res
31
+ return undefined
32
+ }
@@ -0,0 +1,32 @@
1
+ import { frameToPoints } from "./frameToPoints.js"
2
+
3
+ import type { Edge, EdgeSide, LayoutFrame } from "../types/index.js"
4
+
5
+ export function frameToEdges(frame: LayoutFrame, sides?: EdgeSide[]): Record<EdgeSide, Edge> {
6
+ const { tl, tr, bl, br } = frameToPoints(frame)
7
+ // no need for createEdge, we can assure they're sorted
8
+ // by always starting on the top/left and ending on the bottom/right
9
+ const right = { startX: tr.x, startY: tr.y, endX: br.x, endY: br.y }
10
+ const left = { startX: tl.x, startY: tl.y, endX: bl.x, endY: bl.y }
11
+ const bottom = { startX: bl.x, startY: bl.y, endX: br.x, endY: br.y }
12
+ const top = { startX: tl.x, startY: tl.y, endX: tr.x, endY: tr.y }
13
+ if (sides) {
14
+ const res: Record<EdgeSide, Edge> = {} as any
15
+ for (const side of sides) {
16
+ res[side] = side === "right"
17
+ ? right
18
+ : side === "left"
19
+ ? left
20
+ : side === "bottom"
21
+ ? bottom
22
+ : top
23
+ }
24
+ return res
25
+ }
26
+ return {
27
+ right,
28
+ left,
29
+ bottom,
30
+ top
31
+ }
32
+ }
@@ -0,0 +1,14 @@
1
+ import type { LayoutFrame } from "../types/index.js"
2
+
3
+ export function frameToPoints(frame: LayoutFrame): {
4
+ tl: { x: number, y: number }
5
+ tr: { x: number, y: number }
6
+ bl: { x: number, y: number }
7
+ br: { x: number, y: number }
8
+ } {
9
+ const tl = { x: frame.x, y: frame.y }
10
+ const tr = { x: frame.x + frame.width, y: frame.y }
11
+ const bl = { x: frame.x, y: frame.y + frame.height }
12
+ const br = { x: frame.x + frame.width, y: frame.y + frame.height }
13
+ return { tl, tr, bl, br }
14
+ }
@@ -0,0 +1,6 @@
1
+ import type { Edge, Orientation } from "../types/index.js"
2
+
3
+ export function getEdgeOrientation(edge: Edge): Orientation {
4
+ if (edge.startX === edge.endX) return "vertical"
5
+ return "horizontal"
6
+ }
@@ -0,0 +1,10 @@
1
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
2
+
3
+ import type { Edge } from "../types/index.js"
4
+
5
+ export function getEdgeSharedDirection(edgeA: Edge, edgeB: Edge): false | "horizontal" | "vertical" {
6
+ const edgeDirectionA = getEdgeOrientation(edgeA)
7
+ const edgeDirectionB = getEdgeOrientation(edgeB)
8
+ if (edgeDirectionA !== edgeDirectionB) return false
9
+ return edgeDirectionA
10
+ }
@@ -0,0 +1,27 @@
1
+ import { unreachable } from "@alanscodelog/utils/unreachable"
2
+
3
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
4
+
5
+ import type {
6
+ Edge,
7
+ EdgeSide, LayoutFrame
8
+ } from "../types/index.js"
9
+
10
+ export function getEdgeSide<T extends boolean = false>(
11
+ frame: LayoutFrame,
12
+ edge: Edge,
13
+ allowNone: T = false as T
14
+ ): EdgeSide | (T extends true ? undefined : never) {
15
+ const edgeDir = getEdgeOrientation(edge)
16
+ if (edgeDir === "horizontal") {
17
+ if (edge.startY === frame.y) return "top"
18
+ else if (edge.startY === frame.y + frame.height) return "bottom"
19
+ } else if (edgeDir === "vertical") {
20
+ if (edge.startX === frame.x) return "left"
21
+ else if (edge.startX === frame.x + frame.width) return "right"
22
+ }
23
+ if (!allowNone) {
24
+ unreachable()
25
+ }
26
+ return undefined as any
27
+ }
@@ -0,0 +1,15 @@
1
+ import { getFrameConstant } from "./getFrameConstant.js"
2
+
3
+ import type {
4
+ FrameId, LayoutFrame,
5
+ LayoutWindow
6
+ } from "../types/index.js"
7
+
8
+ export function getFrameById<T extends boolean = false>(
9
+ win: LayoutWindow,
10
+ frameId: FrameId,
11
+ assert: T = false as T
12
+ ): T extends true ? LayoutFrame : LayoutFrame | undefined {
13
+ const frameId_ = getFrameConstant(win, frameId, assert)
14
+ return win.frames[frameId_ as any]
15
+ }
@@ -0,0 +1,22 @@
1
+ import { assertItemIn } from "./assertItemIn.js"
2
+ import { assertWindowHasActiveFrame } from "./assertWindowHasActiveFrame.js"
3
+
4
+ import type { LayoutWindow } from "../types/index.js"
5
+
6
+ export function getFrameConstant<T extends boolean = false>(
7
+ win: LayoutWindow,
8
+ constant: "ACTIVE" | string,
9
+ assert: T = false as T
10
+ ): T extends true ? string : string | undefined {
11
+ switch (constant) {
12
+ case "ACTIVE": {
13
+ if (assert) assertWindowHasActiveFrame(win)
14
+ return win.activeFrame as any
15
+ }
16
+ // todo sides
17
+ default: {
18
+ if (assert) assertItemIn(win.frames, constant)
19
+ return constant as any
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,87 @@
1
+ import { castType } from "@alanscodelog/utils"
2
+ import { keys } from "@alanscodelog/utils/keys"
3
+
4
+ import { addPointsToIntersection } from "./addPointsToIntersection.js"
5
+ import { edgeToPoints } from "./edgeToPoints.js"
6
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
7
+ import { inRange } from "./inRange.js"
8
+
9
+ import { getMaxInt } from "../settings.js"
10
+ import type {
11
+ Edge, IntersectionEntry,
12
+ Orientation,
13
+ Point
14
+ } from "../types/index.js"
15
+
16
+ export function getIntersections(
17
+ visualEdges: Edge[]
18
+ ): IntersectionEntry[] {
19
+ type Intersections = Record<number, Record<number, number>>
20
+ const intersections: Intersections = {
21
+ // x: {y: count}
22
+ }
23
+ for (const edge of visualEdges) {
24
+ addPointsToIntersection(intersections, Object.values(edgeToPoints(edge)))
25
+ }
26
+
27
+ const points: IntersectionEntry[] = []
28
+ const maxInt = getMaxInt()
29
+ for (const x of keys(intersections)) {
30
+ for (const y of keys(intersections[x])) {
31
+ // careful, x and y are really strings
32
+ castType<string>(x)
33
+ castType<string>(y)
34
+ const xInt = Number.parseInt(x, 10)
35
+ const yInt = Number.parseInt(y, 10)
36
+ const isWindowEdge = xInt === 0 || yInt === 0 || xInt === maxInt || yInt === maxInt
37
+ const sharedEdges = findEdgesTouchingPoint(visualEdges, {
38
+ x: xInt,
39
+ y: yInt
40
+ })
41
+ points.push({
42
+ point: { x: xInt, y: yInt },
43
+ count: intersections[x][y],
44
+ sharesEdge: sharedEdges.horizontal.length > 0 || sharedEdges.vertical.length > 0,
45
+ sharedEdges,
46
+
47
+ isWindowEdge
48
+
49
+ })
50
+ }
51
+ }
52
+ return points
53
+ }
54
+
55
+ function findEdgesTouchingPoint(
56
+ edges: Edge[],
57
+ point: Point,
58
+ {
59
+ firstOnly = false,
60
+ orientation: direction = undefined,
61
+ inclusive = true
62
+ }: {
63
+ orientation?: Orientation
64
+ firstOnly?: boolean
65
+ inclusive?: boolean
66
+ } = {}
67
+ ): { horizontal: Edge[], vertical: Edge[] } {
68
+ const edgesContainingPoint: { horizontal: Edge[], vertical: Edge[] } = {
69
+ horizontal: [],
70
+ vertical: []
71
+ }
72
+ for (const edge of edges) {
73
+ const orientation = getEdgeOrientation(edge)
74
+ if (orientation === "horizontal" && (!direction || direction === "horizontal")) {
75
+ if (edge.startY === point.y && inRange(point.x, edge.startX, edge.endX, inclusive)) {
76
+ edgesContainingPoint.horizontal.push(edge)
77
+ if (firstOnly) break
78
+ }
79
+ } else if (!direction || direction === "vertical") {
80
+ if (edge.startX === point.x && inRange(point.y, edge.startY, edge.endY, inclusive)) {
81
+ edgesContainingPoint.vertical.push(edge)
82
+ if (firstOnly) break
83
+ }
84
+ }
85
+ }
86
+ return edgesContainingPoint
87
+ }
@@ -0,0 +1,65 @@
1
+ import { getMaxInt } from "../settings.js"
2
+ import type {
3
+ IntersectionEntry, PointCss
4
+ } from "../types/index.js"
5
+
6
+ export function getIntersectionsCss(entries: IntersectionEntry[],
7
+ {
8
+ intersectionWidth = `var(--layoutIntersectionWidth, 8px)`,
9
+ /** How much to shift the intersections by when it's not on a four corner intersection. Otherwise it tends to look ugly because it overlaps one of the frame edges, this shifts it away from it. */
10
+ shiftAmount = `var(--layoutIntersectionShiftAmount, 2px)`
11
+ }: {
12
+ intersectionWidth?: string
13
+ shiftAmount?: string
14
+ } = {}
15
+ ): (PointCss & { _shifted?: true }) [] {
16
+ const unscale = getMaxInt() / 100
17
+ return entries.map(entry => {
18
+ const point = entry.point
19
+ const css = {
20
+ x: `${point.x / unscale}%`,
21
+ y: `${point.y / unscale}%`,
22
+ width: intersectionWidth,
23
+ height: intersectionWidth,
24
+ translate: `translate(-50%, -50%)`
25
+ }
26
+ if (shiftAmount) {
27
+ const shift = getIntersectionShift(entry)
28
+ if (shift.includes("left")) {
29
+ css.x = `calc(${css.x} + ${shiftAmount})`
30
+ } else if (shift.includes("right")) {
31
+ css.x = `calc(${css.x} - ${shiftAmount})`
32
+ }
33
+ if (shift.includes("top")) {
34
+ css.y = `calc(${css.y} + ${shiftAmount})`
35
+ } else if (shift.includes("bottom")) {
36
+ css.y = `calc(${css.y} - ${shiftAmount})`
37
+ }
38
+ if (shift !== "") {
39
+ ;(css as any)._shifted = true
40
+ }
41
+ }
42
+ return css
43
+ })
44
+ }
45
+
46
+ function getIntersectionShift(intersection: IntersectionEntry): string {
47
+ let shift = ""
48
+ if (intersection.sharedEdges.horizontal.length === 1) {
49
+ const edge = intersection.sharedEdges.horizontal[0]
50
+ if (edge.endX === intersection.point.x) {
51
+ shift += "right"
52
+ } else if (edge.startX === intersection.point.x) {
53
+ shift += "left"
54
+ }
55
+ }
56
+ if (intersection.sharedEdges.vertical.length === 1) {
57
+ const edge = intersection.sharedEdges.vertical[0]
58
+ if (edge.endY === intersection.point.y) {
59
+ shift += "bottom"
60
+ } else if (edge.startY === intersection.point.y) {
61
+ shift += "top"
62
+ }
63
+ }
64
+ return shift
65
+ }
@@ -0,0 +1,69 @@
1
+ import { clampNumber } from "./clampNumber.js"
2
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
3
+ import { getResizeLimit } from "./getResizeLimit.js"
4
+
5
+ import { getMarginSize } from "../settings.js"
6
+ import type {
7
+ Direction,
8
+ Edge, LayoutFrame,
9
+ Point,
10
+ Size } from "../types/index.js"
11
+
12
+ export function getMoveEdgeInfo(
13
+ touchingFrames: LayoutFrame[],
14
+ edge: Edge,
15
+ /** Window scaled/snaped position. See {@link toWindowCoord} */
16
+ position: Point,
17
+ margin: Size = getMarginSize(),
18
+ clamp = true
19
+ ): {
20
+ x: number
21
+ y: number
22
+ dir: Direction
23
+ isPassedLimit: boolean
24
+ pos: number
25
+ distance: number
26
+ } {
27
+ const { x: posX, y: posY } = position
28
+
29
+ const edgeDirection = getEdgeOrientation(edge)
30
+ const dir = edgeDirection === "horizontal"
31
+ ? (posY < edge.startY ? "up" : "down")
32
+ : (posX < edge.startX ? "left" : "right")
33
+
34
+ const edgePos = edgeDirection === "vertical" ? edge.startX : edge.startY
35
+ const cursorPos = edgeDirection === "vertical" ? posX : posY
36
+ const amount = Math.abs(cursorPos - edgePos)
37
+ if (amount === 0) {
38
+ return {
39
+ x: posX,
40
+ y: posY,
41
+ dir,
42
+ isPassedLimit: false,
43
+ pos: edgePos,
44
+ distance: 0
45
+ }
46
+ }
47
+ const limitInDir = getResizeLimit(edge, touchingFrames, dir, amount,
48
+ edgeDirection === "vertical" ? margin.width : margin.height
49
+ )
50
+
51
+ const distanceToLimit = Math.abs(edgePos - limitInDir)
52
+ const isPassedLimit = amount > distanceToLimit
53
+ const reverseClamp = (dir === "right" || dir === "down")
54
+ const pos = clamp
55
+ ? reverseClamp
56
+ ? clampNumber(cursorPos, -Infinity, limitInDir)
57
+ : clampNumber(cursorPos, limitInDir, Infinity)
58
+ : cursorPos
59
+ const distance = Math.abs(pos - edgePos)
60
+
61
+ return {
62
+ x: posX,
63
+ y: posY,
64
+ dir,
65
+ isPassedLimit,
66
+ pos,
67
+ distance
68
+ }
69
+ }