@witchcraft/layout 1.0.0

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 +123 -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 +140 -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,60 @@
1
+ import { castType } from "@alanscodelog/utils/castType"
2
+ import { keys } from "@alanscodelog/utils/keys"
3
+
4
+ import { getMaxInt } from "../settings.js"
5
+ import type {
6
+ Direction,
7
+ Edge, ExtendedDirection, LayoutFrame
8
+ } from "../types/index.js"
9
+
10
+ export function getResizeLimit<TDir extends ExtendedDirection>(
11
+ edge: Edge,
12
+ touchingFrames: LayoutFrame[],
13
+ dir: TDir,
14
+ amount: number,
15
+ margin: number
16
+ ): TDir extends "horizontal" ? Record<"left" | "right", number> : TDir extends "vertical" ? Record<"up" | "down", number> : number {
17
+ const limits: Partial<Record<Direction, number>> = dir === "horizontal"
18
+ ? { left: -Infinity, right: Infinity }
19
+ : dir === "vertical"
20
+ ? { up: -Infinity, down: Infinity }
21
+ : { [dir]: dir === "up" || dir === "left" ? -Infinity : Infinity }
22
+
23
+ if (amount === 0) {
24
+ throw new Error("Amount cannot be zero.")
25
+ }
26
+ castType<ExtendedDirection>(dir)
27
+
28
+ for (const frame of touchingFrames) {
29
+ if (dir === "vertical" || dir === "up") {
30
+ if (frame.y < edge.startY) {
31
+ limits.up = Math.max(limits[dir]!, frame.y)
32
+ }
33
+ }
34
+ if (dir === "vertical" || dir === "down") {
35
+ if (frame.y >= edge.startY) {
36
+ limits.down = Math.min(limits[dir]!, frame.y + frame.height)
37
+ }
38
+ }
39
+ if (dir === "horizontal" || dir === "left") {
40
+ if (frame.x < edge.startX) {
41
+ limits.left = Math.max(limits[dir]!, frame.x)
42
+ }
43
+ }
44
+ if (dir === "horizontal" || dir === "right") {
45
+ if (frame.x >= edge.startX) {
46
+ limits.right = Math.min(limits[dir]!, frame.x + frame.width)
47
+ }
48
+ }
49
+ }
50
+
51
+ for (const key of keys(limits)) {
52
+ // this happens when we drag window edges
53
+ if (limits[key] === -Infinity) limits[key] = 0
54
+ if (limits[key] === Infinity) limits[key] = getMaxInt()
55
+
56
+ limits[key]! += (dir === "left" || dir === "up" ? margin : -margin)
57
+ }
58
+ if (dir === "horizontal" || dir === "vertical") return limits as any
59
+ return limits[dir] as any
60
+ }
@@ -0,0 +1,28 @@
1
+ import { getMaxInt } from "../settings.js"
2
+ import type { BaseSquare } from "../types/index.js"
3
+
4
+ export function getShapeSquareCss(
5
+ obj: BaseSquare,
6
+ pad?: string
7
+ ): {
8
+ x: string
9
+ y: string
10
+ width: string
11
+ height: string
12
+ } {
13
+ const unscale = getMaxInt() / 100
14
+ const css = {
15
+ x: `${obj.x / unscale}%`,
16
+ y: `${obj.y / unscale}%`,
17
+ width: `${obj.width / unscale}%`,
18
+ height: `${obj.height / unscale}%`
19
+ }
20
+ if (pad) {
21
+ css.width = `calc(${css.width} - (${pad}*2))`
22
+ css.height = `calc(${css.height} - (${pad}*2))`
23
+ css.x = `calc(${css.x} + (${pad}))`
24
+ css.y = `calc(${css.y} + (${pad}))`
25
+ }
26
+
27
+ return css
28
+ }
@@ -0,0 +1,9 @@
1
+ import type { EdgeSide, LayoutFrame } from "../types/index.js"
2
+
3
+ export function getSideTouching(frameA: LayoutFrame, frameB: LayoutFrame): EdgeSide | undefined {
4
+ if (frameA.x + frameA.width === frameB.x) return "right"
5
+ if (frameA.x === frameB.x + frameB.width) return "left"
6
+ if (frameA.y + frameA.height === frameB.y) return "bottom"
7
+ if (frameA.y === frameB.y + frameB.height) return "top"
8
+ return undefined
9
+ }
@@ -0,0 +1,53 @@
1
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
2
+
3
+ import { getMaxInt } from "../settings.js"
4
+ import type {
5
+ Edge,
6
+ EdgeCss } from "../types/index.js"
7
+
8
+ export function getVisualEdgeCss(
9
+ edge: Edge,
10
+ {
11
+ translate = true,
12
+ edgeWidth = `var(--layoutEdgeWidth, 2px)`,
13
+ padLongAxis,
14
+ padShortAxis
15
+ }: {
16
+ translate?: boolean
17
+ edgeWidth?: string
18
+ padLongAxis?: string
19
+ padShortAxis?: string
20
+ } = {}
21
+ ): EdgeCss {
22
+ const dir = getEdgeOrientation(edge)
23
+ const unscale = getMaxInt() / 100
24
+ const w = (edge.endX - edge.startX) / unscale
25
+ const h = (edge.endY - edge.startY) / unscale
26
+ const width = dir === "vertical" ? edgeWidth : `${w}%`
27
+ const height = dir === "horizontal" ? edgeWidth : `${h}%`
28
+
29
+ const x = `${edge.startX / unscale}%`
30
+ const y = `${edge.startY / unscale}%`
31
+
32
+ const xTranslate = dir === "vertical" ? "-50%" : "0"
33
+ const yTranslate = dir === "horizontal" ? "-50%" : "0"
34
+
35
+ const translation = translate ? `translate(${xTranslate}, ${yTranslate})` : ""
36
+ const css = {
37
+ x, y, width, height, translate: translation
38
+ }
39
+
40
+ if (padLongAxis) {
41
+ const axis = dir === "vertical" ? "height" : "width"
42
+ const coord = dir === "vertical" ? "y" : "x"
43
+ css[axis] = `calc(${css[axis]} - (${padLongAxis}*2))`
44
+ css[coord] = `calc(${css[coord]} + (${padLongAxis}))`
45
+ }
46
+ if (padShortAxis) {
47
+ const axis = dir === "vertical" ? "width" : "height"
48
+ const coord = dir === "vertical" ? "x" : "y"
49
+ css[axis] = `calc(${css[axis]} - (${padShortAxis}*2))`
50
+ css[coord] = `calc(${css[coord]} + (${padShortAxis}))`
51
+ }
52
+ return css
53
+ }
@@ -0,0 +1,155 @@
1
+ import { multisplice, MULTISPLICE_ITEM } from "@alanscodelog/utils/multisplice"
2
+
3
+ import { addPointsToIntersection } from "./addPointsToIntersection.js"
4
+ import { assertEdgeSorted } from "./assertEdgeSorted.js"
5
+ import { containsEdge } from "./containsEdge.js"
6
+ import { doEdgesOverlap } from "./doEdgesOverlap.js"
7
+ import { frameToEdges } from "./frameToEdges.js"
8
+ import { frameToPoints } from "./frameToPoints.js"
9
+ import { inRange } from "./inRange.js"
10
+ import { splitEdge } from "./splitEdge.js"
11
+ import { unionEdges } from "./unionEdges.js"
12
+
13
+ import { getMaxInt } from "../settings.js"
14
+ import type {
15
+ Edge,
16
+ Intersections,
17
+ LayoutFrame, Orientation
18
+ } from "../types/index.js"
19
+
20
+ /**
21
+ * Returns the "visual" edges that can be dragged.
22
+ *
23
+ * Visual edges are a combination of all edges shared by frames that must be moved together.
24
+ *
25
+ * For example, if we have two frames A and B, they share the center edge, and the function would return this single edge (unless `includeWindowEdges` is true).
26
+ *
27
+ * ```
28
+ * ┌──┰──┐
29
+ * │A ┃B │ returns ┃
30
+ * └──┸──┘
31
+ * ```
32
+ * Or in this example, we would get two edges:
33
+ * - The one shared by A, B, and C, because no frame edge sharing this edge can without also moving the other frames touching the edge.
34
+ * - The one shared by A and B.
35
+ *```
36
+ * ┌──┰──┐
37
+ * │A ┃C │ ┃
38
+ * ┝━━┫ │ returns ━━ ┃
39
+ * │B ┃ │ ┃
40
+ * └──┸──┘
41
+ * ```
42
+ *
43
+ * And here, we get four edges, because all four can be moved on their own (moving the edge would only affect the two frames sharing that edge).
44
+ *```
45
+ * ┌──┰──┐
46
+ * │A ┃C │ ┃
47
+ * ┝━━╋━━┥ returns ━━ ━━
48
+ * │B ┃D │ ┃
49
+ * └──┸──┘
50
+ * ```
51
+ *
52
+ */
53
+ export function getVisualEdges<T extends boolean = false>(
54
+ frames: LayoutFrame[],
55
+ {
56
+ separateByDir = false as T,
57
+ includeWindowEdges = false
58
+ }: {
59
+ /**
60
+ * Whether the result is separated into horizontal/vertical edges or not.
61
+ *
62
+ * @default false
63
+ */
64
+ separateByDir?: T
65
+ /**
66
+ * Whether to include edges along the window edges.
67
+ *
68
+ * @default false
69
+ */
70
+ includeWindowEdges?: boolean
71
+ } = {}
72
+ ): T extends true ? Record<Orientation, Edge[]> : Edge[] {
73
+ let extVertEdges: Edge[] = []
74
+ let extHorzEdges: Edge[] = []
75
+ const intersections: Intersections = {
76
+ // x: {y: count}
77
+ }
78
+ const max = getMaxInt()
79
+ for (const frame of frames) {
80
+ const frameEdges = frameToEdges(frame)
81
+ addPointsToIntersection(intersections, Object.values(frameToPoints(frame)))
82
+
83
+ secondlabel: for (const edge of Object.values(frameEdges)) {
84
+ const dir = edge === frameEdges.left || edge === frameEdges.right
85
+ ? "vertical"
86
+ : "horizontal"
87
+
88
+ const startKey = dir === "vertical" ? "startX" : "startY"
89
+ const endKey = dir === "vertical" ? "endX" : "endY"
90
+ const arr = dir === "vertical" ? extVertEdges : extHorzEdges
91
+ const indexes = []
92
+ const edges = []
93
+ for (const [i, e] of arr.entries()) {
94
+ if (containsEdge(edge, e, dir)) {
95
+ continue secondlabel
96
+ }
97
+ if (doEdgesOverlap(e, edge, dir)) {
98
+ indexes.push(i)
99
+ edges.push(e)
100
+ }
101
+ }
102
+ if (indexes.length > 0) {
103
+ multisplice(arr, indexes, 1)
104
+ edges.push(edge)
105
+ const newEdge = unionEdges(edges, dir)
106
+ arr.push(newEdge)
107
+ } else if (includeWindowEdges || (edge[startKey] !== 0 && edge[endKey] !== max)) {
108
+ arr.push(edge)
109
+ }
110
+ }
111
+ }
112
+ const changesV: Record<number, Edge[]> = {}
113
+ for (const [i, edge] of extVertEdges.entries()) {
114
+ const possibleIntersections = intersections[edge.startX]
115
+ assertEdgeSorted(edge)
116
+ if (possibleIntersections) {
117
+ const splits = Object.keys(possibleIntersections).filter(_y => {
118
+ const y = Number.parseInt(_y, 10)
119
+ const isIntersection = possibleIntersections[_y as any as number] === 4
120
+ return isIntersection && inRange(y, edge.startY, edge.endY)
121
+ }).map(_ => Number.parseInt(_, 10))
122
+ if (splits.length === 0) continue
123
+ changesV[i] = splitEdge(extVertEdges[i], "vertical", splits)
124
+ }
125
+ }
126
+ extVertEdges = multisplice(
127
+ extVertEdges,
128
+ Object.keys(changesV) as any,
129
+ 1,
130
+ Object.values(changesV) as any,
131
+ { insert: MULTISPLICE_ITEM.MATCH_INDEX }
132
+ ).array.flat()
133
+
134
+ const changesH: Record<number, Edge[]> = {}
135
+ for (const [i, edge] of extHorzEdges.entries()) {
136
+ const splits = Object.keys(intersections)
137
+ .filter(x => intersections[x as any as number][edge.startY] === 4)
138
+ .map(_ => Number.parseInt(_, 10))
139
+ if (splits.length === 0) continue
140
+ changesH[i] = splitEdge(extHorzEdges[i], "horizontal", splits)
141
+ }
142
+ extHorzEdges = multisplice(
143
+ extHorzEdges,
144
+ Object.keys(changesH) as any,
145
+ 1,
146
+ Object.values(changesH) as any,
147
+ { insert: MULTISPLICE_ITEM.MATCH_INDEX }
148
+ ).array.flat()
149
+
150
+ if (separateByDir) {
151
+ return { vertical: extVertEdges, horizontal: extHorzEdges } satisfies Record<Orientation, Edge[]> as any
152
+ }
153
+
154
+ return extVertEdges.concat(extHorzEdges) satisfies Edge[] as any
155
+ }
@@ -0,0 +1,13 @@
1
+ import { getVisualEdgeCss } from "./getVisualEdgeCss.js"
2
+
3
+ import type {
4
+ Edge,
5
+ EdgeCss
6
+ } from "../types/index.js"
7
+
8
+ export function getVisualEdgesCss(
9
+ edges: Edge[],
10
+ opts: Parameters<typeof getVisualEdgeCss>[1] = {}
11
+ ): EdgeCss[] {
12
+ return edges.map(edge => getVisualEdgeCss(edge, opts))
13
+ }
@@ -0,0 +1,28 @@
1
+ import { getFrameConstant } from "./getFrameConstant.js"
2
+ import { getWinByFrameUuid } from "./getWinByFrameUuid.js"
3
+ import { getWindowConstant } from "./getWindowConstant.js"
4
+
5
+ import type {
6
+ AnyUuid, FrameId, Layout,
7
+ LayoutFrame,
8
+ LayoutWindow, WindowId
9
+ } from "../types/index.js"
10
+
11
+ export function getWinAndFrameById<T extends boolean = false>(
12
+ layout: Layout,
13
+ /** winId can be undefined only if frameId is a uuid */
14
+ winId: WindowId | undefined,
15
+ frameId: AnyUuid | FrameId,
16
+ assert: T = false as T
17
+ ): T extends true ? { win: LayoutWindow, frame: LayoutFrame } : { win?: LayoutWindow, frame?: LayoutFrame } {
18
+ let win: LayoutWindow | undefined
19
+ if (winId === undefined) {
20
+ win = getWinByFrameUuid(layout, frameId, assert)
21
+ } else {
22
+ win = layout.windows[getWindowConstant(layout, winId, assert) as any]
23
+ }
24
+
25
+ const maybeFrameId = (win !== undefined ? getFrameConstant(win, frameId, assert) : undefined)
26
+ const frame = win?.frames[maybeFrameId as any]
27
+ return { win, frame } satisfies { win?: LayoutWindow, frame?: LayoutFrame } as any
28
+ }
@@ -0,0 +1,19 @@
1
+ import type { AnyUuid, Layout, LayoutWindow } from "../types/index.js"
2
+ import { LAYOUT_ERROR } from "../types/index.js"
3
+ import { KnownError } from "../utils/KnownError.js"
4
+
5
+ export function getWinByFrameUuid<T extends boolean = false>(
6
+ layout: Layout,
7
+ frameId: AnyUuid,
8
+ assert: T = false as T
9
+ ): T extends true ? LayoutWindow : LayoutWindow | undefined {
10
+ for (const win of Object.values(layout.windows)) {
11
+ if (win.frames[frameId]) {
12
+ return win
13
+ }
14
+ }
15
+ if (assert) {
16
+ throw new KnownError(LAYOUT_ERROR.INVALID_ID, "Could not find window with frame with that id.", { id: frameId })
17
+ }
18
+ return undefined as any
19
+ }
@@ -0,0 +1,12 @@
1
+ import { getWindowConstant } from "./getWindowConstant.js"
2
+
3
+ import type { Layout, LayoutWindow, WindowId } from "../types/index.js"
4
+
5
+ export function getWinById<T extends boolean = false>(
6
+ layout: Layout,
7
+ winId: WindowId,
8
+ assert: T = false as T
9
+ ): T extends true ? LayoutWindow : LayoutWindow | undefined {
10
+ const winId_ = getWindowConstant(layout, winId, assert)
11
+ return layout.windows[winId_ as any]
12
+ }
@@ -0,0 +1,21 @@
1
+ import { assertItemIn } from "./assertItemIn.js"
2
+ import { assertLayoutHasActiveWindow } from "./assertLayoutHasActiveWindow.js"
3
+
4
+ import type { Layout } from "../types/index.js"
5
+
6
+ export function getWindowConstant<T extends boolean = false>(
7
+ layout: Layout,
8
+ constant: "ACTIVE" | string | undefined,
9
+ assert: T = false as T
10
+ ): T extends true ? string : string | undefined {
11
+ switch (constant) {
12
+ case "ACTIVE": {
13
+ if (assert) assertLayoutHasActiveWindow(layout)
14
+ return layout.activeWindow as any
15
+ }
16
+ default: {
17
+ if (assert) assertItemIn(layout.windows, constant)
18
+ return constant as any
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,5 @@
1
+ export function inRange(coord: number, lowerLimit: number, upperLimit: number, inclusive = true): boolean {
2
+ return inclusive
3
+ ? coord >= lowerLimit && coord <= upperLimit
4
+ : coord > lowerLimit && coord < upperLimit
5
+ }
@@ -0,0 +1,64 @@
1
+ /* Autogenerated Index */
2
+
3
+ export { addPointsToIntersection } from "./addPointsToIntersection.js"
4
+ export { assertEdgeSorted } from "./assertEdgeSorted.js"
5
+ export { assertItemIn } from "./assertItemIn.js"
6
+ export { assertItemNotIn } from "./assertItemNotIn.js"
7
+ export { assertLayoutHasActiveWindow } from "./assertLayoutHasActiveWindow.js"
8
+ export { assertValidWinAndFrame } from "./assertValidWinAndFrame.js"
9
+ export { assertValidWinAndFrameIds } from "./assertValidWinAndFrameIds.js"
10
+ export { assertWindowHasActiveFrame } from "./assertWindowHasActiveFrame.js"
11
+ export { clampNumber } from "./clampNumber.js"
12
+ export { cloneFrame } from "./cloneFrame.js"
13
+ export { cloneFrames } from "./cloneFrames.js"
14
+ export { containsEdge } from "./containsEdge.js"
15
+ export { convertLayoutWindowToWorkspace } from "./convertLayoutWindowToWorkspace.js"
16
+ export { copySize } from "./copySize.js"
17
+ export { createEdge } from "./createEdge.js"
18
+ export { dirToOrientation } from "./dirToOrientation.js"
19
+ export { dirToSide } from "./dirToSide.js"
20
+ export { doEdgesOverlap } from "./doEdgesOverlap.js"
21
+ export { doesEdgeContinueEdge } from "./doesEdgeContinueEdge.js"
22
+ export { edgeToPoints } from "./edgeToPoints.js"
23
+ export { findDraggableEdge } from "./findDraggableEdge.js"
24
+ export { findFrameDraggableEdges } from "./findFrameDraggableEdges.js"
25
+ export { frameToEdges } from "./frameToEdges.js"
26
+ export { frameToPoints } from "./frameToPoints.js"
27
+ export { getEdgeOrientation } from "./getEdgeOrientation.js"
28
+ export { getEdgeSharedDirection } from "./getEdgeSharedDirection.js"
29
+ export { getEdgeSide } from "./getEdgeSide.js"
30
+ export { getFrameById } from "./getFrameById.js"
31
+ export { getFrameConstant } from "./getFrameConstant.js"
32
+ export { getIntersections } from "./getIntersections.js"
33
+ export { getIntersectionsCss } from "./getIntersectionsCss.js"
34
+ export { getMoveEdgeInfo } from "./getMoveEdgeInfo.js"
35
+ export { getResizeLimit } from "./getResizeLimit.js"
36
+ export { getShapeSquareCss } from "./getShapeSquareCss.js"
37
+ export { getSideTouching } from "./getSideTouching.js"
38
+ export { getVisualEdgeCss } from "./getVisualEdgeCss.js"
39
+ export { getVisualEdges } from "./getVisualEdges.js"
40
+ export { getVisualEdgesCss } from "./getVisualEdgesCss.js"
41
+ export { getWinAndFrameById } from "./getWinAndFrameById.js"
42
+ export { getWinByFrameUuid } from "./getWinByFrameUuid.js"
43
+ export { getWinById } from "./getWinById.js"
44
+ export { getWindowConstant } from "./getWindowConstant.js"
45
+ export { inRange } from "./inRange.js"
46
+ export { isEdgeEqual } from "./isEdgeEqual.js"
47
+ export { isEdgeParallel } from "./isEdgeParallel.js"
48
+ export { isPointEqual } from "./isPointEqual.js"
49
+ export { isSizeAboveMin } from "./isSizeAboveMin.js"
50
+ export { isSizeEqual } from "./isSizeEqual.js"
51
+ export { isWindowEdge } from "./isWindowEdge.js"
52
+ export { isWindowEdgePoint } from "./isWindowEdgePoint.js"
53
+ export { moveEdge } from "./moveEdge.js"
54
+ export { numberToScaledPercent } from "./numberToScaledPercent.js"
55
+ export { numberToScaledSize } from "./numberToScaledSize.js"
56
+ export { oppositeSide } from "./oppositeSide.js"
57
+ export { resizeByEdge } from "./resizeByEdge.js"
58
+ export { sideToDirection } from "./sideToDirection.js"
59
+ export { sideToOrientation } from "./sideToOrientation.js"
60
+ export { splitEdge } from "./splitEdge.js"
61
+ export { toCoord } from "./toCoord.js"
62
+ export { toId } from "./toId.js"
63
+ export { toWindowCoord } from "./toWindowCoord.js"
64
+ export { unionEdges } from "./unionEdges.js"
@@ -0,0 +1,14 @@
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 isEdgeEqual(edgeA: Edge, edgeB: Edge, orientation?: Orientation): boolean {
7
+ orientation ??= getEdgeOrientation(edgeA)
8
+ if (!isEdgeParallel(edgeA, edgeB)) return false
9
+ if (orientation === "horizontal") {
10
+ return edgeA.startY === edgeB.startY && edgeB.endY === edgeA.endY
11
+ } else {
12
+ return edgeA.startX === edgeB.startX && edgeB.endX === edgeA.endX
13
+ }
14
+ }
@@ -0,0 +1,10 @@
1
+ import { getEdgeSharedDirection } from "./getEdgeSharedDirection.js"
2
+
3
+ import type { Edge, Orientation } from "../types/index.js"
4
+
5
+ export function isEdgeParallel(edgeA: Edge, edgeB: Edge, dir?: Orientation): boolean {
6
+ const sharedDir = getEdgeSharedDirection(edgeA, edgeB)
7
+ if (dir === undefined) return sharedDir !== false
8
+ if (dir === sharedDir) return true
9
+ return false
10
+ }
@@ -0,0 +1,5 @@
1
+ import type { Point } from "../types/index.js"
2
+
3
+ export function isPointEqual(pointA: Point, pointB: Point): boolean {
4
+ return pointA.x === pointB.x && pointA.y === pointB.y
5
+ }
@@ -0,0 +1,8 @@
1
+ import type { Size } from "../types/index.js"
2
+
3
+ export function isSizeAboveMin(
4
+ size: Size,
5
+ min: Size
6
+ ): boolean {
7
+ return size.width >= min.width && size.height >= min.height
8
+ }
@@ -0,0 +1,5 @@
1
+ import type { Size } from "../types/index.js"
2
+
3
+ export function isSizeEqual(sizeA: Size, sizeB: Size): boolean {
4
+ return sizeA.width === sizeB.width && sizeA.height === sizeB.height
5
+ }
@@ -0,0 +1,11 @@
1
+ import { getEdgeOrientation } from "./getEdgeOrientation.js"
2
+
3
+ import { getMaxInt } from "../settings.js"
4
+ import type { Edge, Orientation } from "../types/index.js"
5
+
6
+ export function isWindowEdge(edge: Edge, edgeDirection?: Orientation): boolean {
7
+ edgeDirection ??= getEdgeOrientation(edge)
8
+ const max = getMaxInt()
9
+ return (edgeDirection === "vertical" && (edge.startX === 0 || edge.startX === max))
10
+ || (edgeDirection === "horizontal" && (edge.startY === 0 || edge.startY === max))
11
+ }
@@ -0,0 +1,8 @@
1
+ import { getMaxInt } from "../settings.js"
2
+ import type { Point } from "../types/index.js"
3
+
4
+ export function isWindowEdgePoint(point: Point): boolean {
5
+ const max = getMaxInt()
6
+ return (point.x === 0 || point.x === max)
7
+ || (point.y === 0 || point.y === max)
8
+ }
@@ -0,0 +1,21 @@
1
+ import { getMoveEdgeInfo } from "./getMoveEdgeInfo.js"
2
+ import { resizeByEdge } from "./resizeByEdge.js"
3
+
4
+ import { getMarginSize } from "../settings.js"
5
+ import type {
6
+ Edge, LayoutFrame,
7
+ Point,
8
+ Size
9
+ } from "../types/index.js"
10
+
11
+ export function moveEdge(
12
+ touchingFrames: LayoutFrame[] | undefined,
13
+ edge: Edge | undefined,
14
+ /** Window scaled/snaped position. See {@link toWindowCoord} */
15
+ position: Point,
16
+ margin: Size = getMarginSize()
17
+ ): void {
18
+ if (!edge || !touchingFrames) return
19
+ const { pos, dir, distance } = getMoveEdgeInfo(touchingFrames, edge, position, margin)
20
+ resizeByEdge(touchingFrames, edge, dir, pos, distance)
21
+ }
@@ -0,0 +1,19 @@
1
+ import { snapNumber } from "@alanscodelog/utils/snapNumber"
2
+
3
+ import { getMaxInt } from "../settings.js"
4
+
5
+ /**
6
+ * Given a number (e.g. the x coordinate in px), and the max value it could be (e.g. the max width of it's container in px), returns it's position as a scaled percentage.
7
+ *
8
+ * ```
9
+ * -----------
10
+ * | * |
11
+ * -----------
12
+ * | ^100px
13
+ * ^ 50px
14
+ * // returns 50 / 100 * scale or 50000 (50%)
15
+ * ```
16
+ */
17
+ export function numberToScaledPercent(num: number, max: number, scale: number = getMaxInt()): number {
18
+ return snapNumber((num / max) * scale, 1)
19
+ }
@@ -0,0 +1,28 @@
1
+ import { unreachable } from "@alanscodelog/utils/unreachable"
2
+
3
+ import { numberToScaledPercent } from "./numberToScaledPercent.js"
4
+
5
+ import { getMaxInt } from "../settings.js"
6
+ import type { LayoutWindow, PxSize, Size } from "../types/index.js"
7
+
8
+ export function numberToScaledSize(
9
+ win: LayoutWindow,
10
+ size: PxSize | number,
11
+ scale: number = getMaxInt()
12
+ ): Size {
13
+ const scaledSize = {
14
+ width: numberToScaledPercent(
15
+ typeof size === "number" ? size : size.pxWidth,
16
+ win.pxWidth,
17
+ scale
18
+ ),
19
+ height:
20
+ numberToScaledPercent(
21
+ typeof size === "number" ? size : size.pxHeight,
22
+ win.pxHeight,
23
+ scale
24
+ )
25
+ }
26
+ if (scaledSize.width > scale) unreachable()
27
+ return scaledSize
28
+ }
@@ -0,0 +1,45 @@
1
+ import { unreachable } from "@alanscodelog/utils/unreachable"
2
+
3
+ import type { Direction, EdgeSide,
4
+ ExtendedDirection,
5
+ ExtendedEdgeSide, HasOpposite,
6
+ Point,
7
+ Size
8
+ } from "../types/index.js"
9
+
10
+ export function oppositeSide<
11
+ T extends Direction
12
+ | EdgeSide
13
+ | ExtendedDirection
14
+ | ExtendedEdgeSide
15
+ | keyof Point
16
+ | keyof Size
17
+ >(dir: T): T {
18
+ switch (dir) {
19
+ case "x":
20
+ return "y" satisfies HasOpposite as any
21
+ case "y":
22
+ return "x" satisfies HasOpposite as any
23
+ case "width":
24
+ return "height" satisfies HasOpposite as any
25
+ case "height":
26
+ return "width" satisfies HasOpposite as any
27
+ case "left":
28
+ return "right" satisfies HasOpposite as any
29
+ case "right":
30
+ return "left" satisfies HasOpposite as any
31
+ case "up":
32
+ return "down" satisfies HasOpposite as any
33
+ case "top":
34
+ return "bottom" satisfies HasOpposite as any
35
+ case "bottom":
36
+ return "top" satisfies HasOpposite as any
37
+ case "down":
38
+ return "up" satisfies HasOpposite as any
39
+ case "horizontal":
40
+ return "vertical" satisfies HasOpposite as any
41
+ case "vertical":
42
+ return "horizontal" satisfies HasOpposite as any
43
+ }
44
+ unreachable()
45
+ }