@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.
- package/README.md +474 -0
- package/dist/module.d.mts +14 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +26 -0
- package/dist/runtime/components/LayoutDecos.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutDecos.vue +54 -0
- package/dist/runtime/components/LayoutDecos.vue.d.ts +0 -0
- package/dist/runtime/components/LayoutEdges.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutEdges.vue +145 -0
- package/dist/runtime/components/LayoutEdges.vue.d.ts +0 -0
- package/dist/runtime/components/LayoutFrame.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutFrame.vue +41 -0
- package/dist/runtime/components/LayoutFrame.vue.d.ts +0 -0
- package/dist/runtime/components/LayoutShapeSquare.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutShapeSquare.vue +36 -0
- package/dist/runtime/components/LayoutShapeSquare.vue.d.ts +0 -0
- package/dist/runtime/components/LayoutWindow.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutWindow.vue +183 -0
- package/dist/runtime/components/LayoutWindow.vue.d.ts +0 -0
- package/dist/runtime/composables/useFrames.d.ts +0 -0
- package/dist/runtime/composables/useFrames.js +184 -0
- package/dist/runtime/demo/App.d.vue.ts +0 -0
- package/dist/runtime/demo/App.vue +121 -0
- package/dist/runtime/demo/App.vue.d.ts +0 -0
- package/dist/runtime/demo/DemoControls.d.vue.ts +0 -0
- package/dist/runtime/demo/DemoControls.vue +14 -0
- package/dist/runtime/demo/DemoControls.vue.d.ts +0 -0
- package/dist/runtime/demo/README.md +1 -0
- package/dist/runtime/demo/main.d.ts +0 -0
- package/dist/runtime/demo/main.js +4 -0
- package/dist/runtime/demo/sharedLayoutInstance.d.ts +0 -0
- package/dist/runtime/demo/sharedLayoutInstance.js +5 -0
- package/dist/runtime/demo/tailwind.css +1 -0
- package/dist/runtime/drag/CloseAction.d.ts +0 -0
- package/dist/runtime/drag/CloseAction.js +121 -0
- package/dist/runtime/drag/DragActionHandler.d.ts +0 -0
- package/dist/runtime/drag/DragActionHandler.js +83 -0
- package/dist/runtime/drag/DragDirectionStore.d.ts +0 -0
- package/dist/runtime/drag/DragDirectionStore.js +45 -0
- package/dist/runtime/drag/SplitAction.d.ts +0 -0
- package/dist/runtime/drag/SplitAction.js +110 -0
- package/dist/runtime/drag/types.d.ts +0 -0
- package/dist/runtime/drag/types.js +0 -0
- package/dist/runtime/helpers/addPointsToIntersection.d.ts +0 -0
- package/dist/runtime/helpers/addPointsToIntersection.js +7 -0
- package/dist/runtime/helpers/assertEdgeSorted.d.ts +0 -0
- package/dist/runtime/helpers/assertEdgeSorted.js +7 -0
- package/dist/runtime/helpers/assertItemIn.d.ts +0 -0
- package/dist/runtime/helpers/assertItemIn.js +8 -0
- package/dist/runtime/helpers/assertItemNotIn.d.ts +0 -0
- package/dist/runtime/helpers/assertItemNotIn.js +7 -0
- package/dist/runtime/helpers/assertLayoutHasActiveWindow.d.ts +0 -0
- package/dist/runtime/helpers/assertLayoutHasActiveWindow.js +7 -0
- package/dist/runtime/helpers/assertValidWinAndFrame.d.ts +0 -0
- package/dist/runtime/helpers/assertValidWinAndFrame.js +5 -0
- package/dist/runtime/helpers/assertValidWinAndFrameIds.d.ts +0 -0
- package/dist/runtime/helpers/assertValidWinAndFrameIds.js +6 -0
- package/dist/runtime/helpers/assertWindowHasActiveFrame.d.ts +0 -0
- package/dist/runtime/helpers/assertWindowHasActiveFrame.js +7 -0
- package/dist/runtime/helpers/clampNumber.d.ts +0 -0
- package/dist/runtime/helpers/clampNumber.js +3 -0
- package/dist/runtime/helpers/cloneFrame.d.ts +0 -0
- package/dist/runtime/helpers/cloneFrame.js +3 -0
- package/dist/runtime/helpers/cloneFrames.d.ts +0 -0
- package/dist/runtime/helpers/cloneFrames.js +16 -0
- package/dist/runtime/helpers/containsEdge.d.ts +0 -0
- package/dist/runtime/helpers/containsEdge.js +13 -0
- package/dist/runtime/helpers/convertLayoutWindowToWorkspace.d.ts +0 -0
- package/dist/runtime/helpers/convertLayoutWindowToWorkspace.js +10 -0
- package/dist/runtime/helpers/copySize.d.ts +0 -0
- package/dist/runtime/helpers/copySize.js +5 -0
- package/dist/runtime/helpers/createEdge.d.ts +0 -0
- package/dist/runtime/helpers/createEdge.js +13 -0
- package/dist/runtime/helpers/dirToOrientation.d.ts +0 -0
- package/dist/runtime/helpers/dirToOrientation.js +10 -0
- package/dist/runtime/helpers/dirToSide.d.ts +0 -0
- package/dist/runtime/helpers/dirToSide.js +5 -0
- package/dist/runtime/helpers/doEdgesOverlap.d.ts +0 -0
- package/dist/runtime/helpers/doEdgesOverlap.js +22 -0
- package/dist/runtime/helpers/doesEdgeContinueEdge.d.ts +0 -0
- package/dist/runtime/helpers/doesEdgeContinueEdge.js +17 -0
- package/dist/runtime/helpers/edgeToPoints.d.ts +0 -0
- package/dist/runtime/helpers/edgeToPoints.js +3 -0
- package/dist/runtime/helpers/findDraggableEdge.d.ts +0 -0
- package/dist/runtime/helpers/findDraggableEdge.js +13 -0
- package/dist/runtime/helpers/findFrameDraggableEdges.d.ts +0 -0
- package/dist/runtime/helpers/findFrameDraggableEdges.js +18 -0
- package/dist/runtime/helpers/frameToEdges.d.ts +0 -0
- package/dist/runtime/helpers/frameToEdges.js +21 -0
- package/dist/runtime/helpers/frameToPoints.d.ts +0 -0
- package/dist/runtime/helpers/frameToPoints.js +7 -0
- package/dist/runtime/helpers/getEdgeOrientation.d.ts +0 -0
- package/dist/runtime/helpers/getEdgeOrientation.js +4 -0
- package/dist/runtime/helpers/getEdgeSharedDirection.d.ts +0 -0
- package/dist/runtime/helpers/getEdgeSharedDirection.js +7 -0
- package/dist/runtime/helpers/getEdgeSide.d.ts +0 -0
- package/dist/runtime/helpers/getEdgeSide.js +16 -0
- package/dist/runtime/helpers/getFrameById.d.ts +0 -0
- package/dist/runtime/helpers/getFrameById.js +5 -0
- package/dist/runtime/helpers/getFrameConstant.d.ts +0 -0
- package/dist/runtime/helpers/getFrameConstant.js +15 -0
- package/dist/runtime/helpers/getIntersections.d.ts +0 -0
- package/dist/runtime/helpers/getIntersections.js +63 -0
- package/dist/runtime/helpers/getIntersectionsCss.d.ts +0 -0
- package/dist/runtime/helpers/getIntersectionsCss.js +56 -0
- package/dist/runtime/helpers/getMoveEdgeInfo.d.ts +0 -0
- package/dist/runtime/helpers/getMoveEdgeInfo.js +42 -0
- package/dist/runtime/helpers/getResizeLimit.d.ts +0 -0
- package/dist/runtime/helpers/getResizeLimit.js +39 -0
- package/dist/runtime/helpers/getShapeSquareCss.d.ts +0 -0
- package/dist/runtime/helpers/getShapeSquareCss.js +17 -0
- package/dist/runtime/helpers/getSideTouching.d.ts +0 -0
- package/dist/runtime/helpers/getSideTouching.js +7 -0
- package/dist/runtime/helpers/getVisualEdgeCss.d.ts +0 -0
- package/dist/runtime/helpers/getVisualEdgeCss.js +40 -0
- package/dist/runtime/helpers/getVisualEdges.d.ts +0 -0
- package/dist/runtime/helpers/getVisualEdges.js +89 -0
- package/dist/runtime/helpers/getVisualEdgesCss.d.ts +0 -0
- package/dist/runtime/helpers/getVisualEdgesCss.js +4 -0
- package/dist/runtime/helpers/getWinAndFrameById.d.ts +0 -0
- package/dist/runtime/helpers/getWinAndFrameById.js +14 -0
- package/dist/runtime/helpers/getWinByFrameUuid.d.ts +0 -0
- package/dist/runtime/helpers/getWinByFrameUuid.js +13 -0
- package/dist/runtime/helpers/getWinById.d.ts +0 -0
- package/dist/runtime/helpers/getWinById.js +5 -0
- package/dist/runtime/helpers/getWindowConstant.d.ts +0 -0
- package/dist/runtime/helpers/getWindowConstant.js +14 -0
- package/dist/runtime/helpers/inRange.d.ts +0 -0
- package/dist/runtime/helpers/inRange.js +3 -0
- package/dist/runtime/helpers/index.d.ts +0 -0
- package/dist/runtime/helpers/index.js +62 -0
- package/dist/runtime/helpers/isEdgeEqual.d.ts +0 -0
- package/dist/runtime/helpers/isEdgeEqual.js +11 -0
- package/dist/runtime/helpers/isEdgeParallel.d.ts +0 -0
- package/dist/runtime/helpers/isEdgeParallel.js +7 -0
- package/dist/runtime/helpers/isPointEqual.d.ts +0 -0
- package/dist/runtime/helpers/isPointEqual.js +3 -0
- package/dist/runtime/helpers/isSizeAboveMin.d.ts +0 -0
- package/dist/runtime/helpers/isSizeAboveMin.js +3 -0
- package/dist/runtime/helpers/isSizeEqual.d.ts +0 -0
- package/dist/runtime/helpers/isSizeEqual.js +3 -0
- package/dist/runtime/helpers/isWindowEdge.d.ts +0 -0
- package/dist/runtime/helpers/isWindowEdge.js +7 -0
- package/dist/runtime/helpers/isWindowEdgePoint.d.ts +0 -0
- package/dist/runtime/helpers/isWindowEdgePoint.js +5 -0
- package/dist/runtime/helpers/moveEdge.d.ts +0 -0
- package/dist/runtime/helpers/moveEdge.js +8 -0
- package/dist/runtime/helpers/numberToScaledPercent.d.ts +0 -0
- package/dist/runtime/helpers/numberToScaledPercent.js +5 -0
- package/dist/runtime/helpers/numberToScaledSize.d.ts +0 -0
- package/dist/runtime/helpers/numberToScaledSize.js +19 -0
- package/dist/runtime/helpers/oppositeSide.d.ts +0 -0
- package/dist/runtime/helpers/oppositeSide.js +30 -0
- package/dist/runtime/helpers/resizeByEdge.d.ts +0 -0
- package/dist/runtime/helpers/resizeByEdge.js +29 -0
- package/dist/runtime/helpers/sideToDirection.d.ts +0 -0
- package/dist/runtime/helpers/sideToDirection.js +11 -0
- package/dist/runtime/helpers/sideToOrientation.d.ts +0 -0
- package/dist/runtime/helpers/sideToOrientation.js +10 -0
- package/dist/runtime/helpers/splitEdge.d.ts +0 -0
- package/dist/runtime/helpers/splitEdge.js +20 -0
- package/dist/runtime/helpers/toCoord.d.ts +0 -0
- package/dist/runtime/helpers/toCoord.js +10 -0
- package/dist/runtime/helpers/toId.d.ts +0 -0
- package/dist/runtime/helpers/toId.js +4 -0
- package/dist/runtime/helpers/toWindowCoord.d.ts +0 -0
- package/dist/runtime/helpers/toWindowCoord.js +14 -0
- package/dist/runtime/helpers/unionEdges.d.ts +0 -0
- package/dist/runtime/helpers/unionEdges.js +8 -0
- package/dist/runtime/helpers/updateWindowSizeWithEvent.d.ts +0 -0
- package/dist/runtime/helpers/updateWindowSizeWithEvent.js +8 -0
- package/dist/runtime/index.d.ts +0 -0
- package/dist/runtime/index.js +5 -0
- package/dist/runtime/layout/closeFrame.d.ts +0 -0
- package/dist/runtime/layout/closeFrame.js +13 -0
- package/dist/runtime/layout/closeFrames.d.ts +0 -0
- package/dist/runtime/layout/closeFrames.js +8 -0
- package/dist/runtime/layout/createSplitDecoEdge.d.ts +0 -0
- package/dist/runtime/layout/createSplitDecoEdge.js +24 -0
- package/dist/runtime/layout/createSplitDecoFromDrag.d.ts +0 -0
- package/dist/runtime/layout/createSplitDecoFromDrag.js +14 -0
- package/dist/runtime/layout/debugFrame.d.ts +0 -0
- package/dist/runtime/layout/debugFrame.js +4 -0
- package/dist/runtime/layout/findFramesTouchingEdge.d.ts +0 -0
- package/dist/runtime/layout/findFramesTouchingEdge.js +33 -0
- package/dist/runtime/layout/findSafeSplitEdge.d.ts +0 -0
- package/dist/runtime/layout/findSafeSplitEdge.js +20 -0
- package/dist/runtime/layout/findVisualEdge.d.ts +0 -0
- package/dist/runtime/layout/findVisualEdge.js +9 -0
- package/dist/runtime/layout/frameCreate.d.ts +0 -0
- package/dist/runtime/layout/frameCreate.js +13 -0
- package/dist/runtime/layout/frameSplit.d.ts +0 -0
- package/dist/runtime/layout/frameSplit.js +9 -0
- package/dist/runtime/layout/getCloseFrameInfo.d.ts +0 -0
- package/dist/runtime/layout/getCloseFrameInfo.js +103 -0
- package/dist/runtime/layout/getFrameSplitInfo.d.ts +0 -0
- package/dist/runtime/layout/getFrameSplitInfo.js +40 -0
- package/dist/runtime/layout/getFrameTo.d.ts +0 -0
- package/dist/runtime/layout/getFrameTo.js +47 -0
- package/dist/runtime/layout/index.d.ts +0 -0
- package/dist/runtime/layout/index.js +22 -0
- package/dist/runtime/layout/isPointInFrame.d.ts +0 -0
- package/dist/runtime/layout/isPointInFrame.js +4 -0
- package/dist/runtime/layout/layoutAddWindow.d.ts +0 -0
- package/dist/runtime/layout/layoutAddWindow.js +4 -0
- package/dist/runtime/layout/layoutCreate.d.ts +0 -0
- package/dist/runtime/layout/layoutCreate.js +7 -0
- package/dist/runtime/layout/layoutRemoveWindow.d.ts +0 -0
- package/dist/runtime/layout/layoutRemoveWindow.js +5 -0
- package/dist/runtime/layout/resizeFrame.d.ts +0 -0
- package/dist/runtime/layout/resizeFrame.js +69 -0
- package/dist/runtime/layout/windowAddFrame.d.ts +0 -0
- package/dist/runtime/layout/windowAddFrame.js +4 -0
- package/dist/runtime/layout/windowCreate.d.ts +0 -0
- package/dist/runtime/layout/windowCreate.js +13 -0
- package/dist/runtime/layout/windowRemoveFrame.d.ts +0 -0
- package/dist/runtime/layout/windowRemoveFrame.js +5 -0
- package/dist/runtime/layout/windowSetActiveFrame.d.ts +0 -0
- package/dist/runtime/layout/windowSetActiveFrame.js +5 -0
- package/dist/runtime/settings.d.ts +0 -0
- package/dist/runtime/settings.js +54 -0
- package/dist/runtime/types/index.d.ts +0 -0
- package/dist/runtime/types/index.js +120 -0
- package/dist/runtime/utils/KnownError.d.ts +0 -0
- package/dist/runtime/utils/KnownError.js +9 -0
- package/dist/types.d.mts +5 -0
- package/package.json +153 -0
- package/src/module.ts +43 -0
- package/src/runtime/components/LayoutDecos.vue +62 -0
- package/src/runtime/components/LayoutEdges.vue +172 -0
- package/src/runtime/components/LayoutFrame.vue +47 -0
- package/src/runtime/components/LayoutShapeSquare.vue +38 -0
- package/src/runtime/components/LayoutWindow.vue +223 -0
- package/src/runtime/composables/useFrames.ts +251 -0
- package/src/runtime/demo/App.vue +139 -0
- package/src/runtime/demo/DemoControls.vue +17 -0
- package/src/runtime/demo/README.md +1 -0
- package/src/runtime/demo/main.ts +9 -0
- package/src/runtime/demo/sharedLayoutInstance.ts +7 -0
- package/src/runtime/demo/tailwind.css +4 -0
- package/src/runtime/drag/CloseAction.ts +158 -0
- package/src/runtime/drag/DragActionHandler.ts +146 -0
- package/src/runtime/drag/DragDirectionStore.ts +63 -0
- package/src/runtime/drag/SplitAction.ts +147 -0
- package/src/runtime/drag/types.ts +107 -0
- package/src/runtime/helpers/addPointsToIntersection.ts +9 -0
- package/src/runtime/helpers/assertEdgeSorted.ts +11 -0
- package/src/runtime/helpers/assertItemIn.ts +13 -0
- package/src/runtime/helpers/assertItemNotIn.ts +10 -0
- package/src/runtime/helpers/assertLayoutHasActiveWindow.ts +9 -0
- package/src/runtime/helpers/assertValidWinAndFrame.ts +16 -0
- package/src/runtime/helpers/assertValidWinAndFrameIds.ts +9 -0
- package/src/runtime/helpers/assertWindowHasActiveFrame.ts +9 -0
- package/src/runtime/helpers/clampNumber.ts +9 -0
- package/src/runtime/helpers/cloneFrame.ts +5 -0
- package/src/runtime/helpers/cloneFrames.ts +20 -0
- package/src/runtime/helpers/containsEdge.ts +16 -0
- package/src/runtime/helpers/convertLayoutWindowToWorkspace.ts +18 -0
- package/src/runtime/helpers/copySize.ts +7 -0
- package/src/runtime/helpers/createEdge.ts +19 -0
- package/src/runtime/helpers/dirToOrientation.ts +12 -0
- package/src/runtime/helpers/dirToSide.ts +7 -0
- package/src/runtime/helpers/doEdgesOverlap.ts +25 -0
- package/src/runtime/helpers/doesEdgeContinueEdge.ts +20 -0
- package/src/runtime/helpers/edgeToPoints.ts +5 -0
- package/src/runtime/helpers/findDraggableEdge.ts +24 -0
- package/src/runtime/helpers/findFrameDraggableEdges.ts +32 -0
- package/src/runtime/helpers/frameToEdges.ts +32 -0
- package/src/runtime/helpers/frameToPoints.ts +14 -0
- package/src/runtime/helpers/getEdgeOrientation.ts +6 -0
- package/src/runtime/helpers/getEdgeSharedDirection.ts +10 -0
- package/src/runtime/helpers/getEdgeSide.ts +27 -0
- package/src/runtime/helpers/getFrameById.ts +15 -0
- package/src/runtime/helpers/getFrameConstant.ts +22 -0
- package/src/runtime/helpers/getIntersections.ts +87 -0
- package/src/runtime/helpers/getIntersectionsCss.ts +65 -0
- package/src/runtime/helpers/getMoveEdgeInfo.ts +69 -0
- package/src/runtime/helpers/getResizeLimit.ts +60 -0
- package/src/runtime/helpers/getShapeSquareCss.ts +28 -0
- package/src/runtime/helpers/getSideTouching.ts +9 -0
- package/src/runtime/helpers/getVisualEdgeCss.ts +53 -0
- package/src/runtime/helpers/getVisualEdges.ts +155 -0
- package/src/runtime/helpers/getVisualEdgesCss.ts +13 -0
- package/src/runtime/helpers/getWinAndFrameById.ts +28 -0
- package/src/runtime/helpers/getWinByFrameUuid.ts +19 -0
- package/src/runtime/helpers/getWinById.ts +12 -0
- package/src/runtime/helpers/getWindowConstant.ts +21 -0
- package/src/runtime/helpers/inRange.ts +5 -0
- package/src/runtime/helpers/index.ts +64 -0
- package/src/runtime/helpers/isEdgeEqual.ts +14 -0
- package/src/runtime/helpers/isEdgeParallel.ts +10 -0
- package/src/runtime/helpers/isPointEqual.ts +5 -0
- package/src/runtime/helpers/isSizeAboveMin.ts +8 -0
- package/src/runtime/helpers/isSizeEqual.ts +5 -0
- package/src/runtime/helpers/isWindowEdge.ts +11 -0
- package/src/runtime/helpers/isWindowEdgePoint.ts +8 -0
- package/src/runtime/helpers/moveEdge.ts +21 -0
- package/src/runtime/helpers/numberToScaledPercent.ts +19 -0
- package/src/runtime/helpers/numberToScaledSize.ts +28 -0
- package/src/runtime/helpers/oppositeSide.ts +45 -0
- package/src/runtime/helpers/resizeByEdge.ts +45 -0
- package/src/runtime/helpers/sideToDirection.ts +15 -0
- package/src/runtime/helpers/sideToOrientation.ts +12 -0
- package/src/runtime/helpers/splitEdge.ts +23 -0
- package/src/runtime/helpers/toCoord.ts +13 -0
- package/src/runtime/helpers/toId.ts +9 -0
- package/src/runtime/helpers/toWindowCoord.ts +23 -0
- package/src/runtime/helpers/unionEdges.ts +11 -0
- package/src/runtime/helpers/updateWindowSizeWithEvent.ts +10 -0
- package/src/runtime/index.ts +5 -0
- package/src/runtime/layout/closeFrame.ts +33 -0
- package/src/runtime/layout/closeFrames.ts +14 -0
- package/src/runtime/layout/createSplitDecoEdge.ts +34 -0
- package/src/runtime/layout/createSplitDecoFromDrag.ts +24 -0
- package/src/runtime/layout/debugFrame.ts +6 -0
- package/src/runtime/layout/findFramesTouchingEdge.ts +92 -0
- package/src/runtime/layout/findSafeSplitEdge.ts +39 -0
- package/src/runtime/layout/findVisualEdge.ts +11 -0
- package/src/runtime/layout/frameCreate.ts +23 -0
- package/src/runtime/layout/frameSplit.ts +31 -0
- package/src/runtime/layout/getCloseFrameInfo.ts +193 -0
- package/src/runtime/layout/getFrameSplitInfo.ts +65 -0
- package/src/runtime/layout/getFrameTo.ts +65 -0
- package/src/runtime/layout/index.ts +24 -0
- package/src/runtime/layout/isPointInFrame.ts +7 -0
- package/src/runtime/layout/layoutAddWindow.ts +6 -0
- package/src/runtime/layout/layoutCreate.ts +12 -0
- package/src/runtime/layout/layoutRemoveWindow.ts +7 -0
- package/src/runtime/layout/resizeFrame.ts +106 -0
- package/src/runtime/layout/windowAddFrame.ts +10 -0
- package/src/runtime/layout/windowCreate.ts +18 -0
- package/src/runtime/layout/windowRemoveFrame.ts +7 -0
- package/src/runtime/layout/windowSetActiveFrame.ts +7 -0
- package/src/runtime/settings.ts +63 -0
- package/src/runtime/types/index.ts +293 -0
- 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,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,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,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,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
|
+
}
|