@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,293 @@
|
|
|
1
|
+
import type { EnumLike } from "@alanscodelog/utils"
|
|
2
|
+
import { enumFromArray } from "@alanscodelog/utils/enumFromArray"
|
|
3
|
+
import { z } from "zod"
|
|
4
|
+
|
|
5
|
+
export * from "../drag/types.js"
|
|
6
|
+
|
|
7
|
+
import { getMaxInt } from "../settings.js"
|
|
8
|
+
|
|
9
|
+
export const zUuid = z.uuid()
|
|
10
|
+
export type AnyUuid = z.infer<typeof zUuid>
|
|
11
|
+
|
|
12
|
+
export const zWindowIdConstants = z.enum(["ACTIVE"])
|
|
13
|
+
export const zWinId = z.uuid().or(zWindowIdConstants)
|
|
14
|
+
export type WindowId = z.infer<typeof zWinId>
|
|
15
|
+
|
|
16
|
+
export const zFrameIdConstants = z.enum(["ACTIVE"])
|
|
17
|
+
export const zFrameId = z.uuid().or(zFrameIdConstants)
|
|
18
|
+
export type FrameId = z.infer<typeof zFrameId>
|
|
19
|
+
|
|
20
|
+
export const zScaledIntPercentage = z.number()
|
|
21
|
+
.int()
|
|
22
|
+
.min(0)
|
|
23
|
+
.max(getMaxInt())
|
|
24
|
+
.nonnegative()
|
|
25
|
+
|
|
26
|
+
const zPx = z.number()
|
|
27
|
+
.int()
|
|
28
|
+
.nonnegative()
|
|
29
|
+
|
|
30
|
+
export const zPos = z.object({
|
|
31
|
+
x: zScaledIntPercentage,
|
|
32
|
+
y: zScaledIntPercentage
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export type Pos = z.infer<typeof zPos>
|
|
36
|
+
|
|
37
|
+
export const zSize = z.object({
|
|
38
|
+
width: zScaledIntPercentage,
|
|
39
|
+
height: zScaledIntPercentage
|
|
40
|
+
})
|
|
41
|
+
export type Size = z.infer<typeof zSize>
|
|
42
|
+
|
|
43
|
+
export const zPoint = z.object({
|
|
44
|
+
x: zScaledIntPercentage,
|
|
45
|
+
y: zScaledIntPercentage
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export type Point = z.infer<typeof zPoint>
|
|
49
|
+
|
|
50
|
+
export const zPxPos = z.object({
|
|
51
|
+
pxX: zPx,
|
|
52
|
+
pxY: zPx
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
export type PxPos = z.infer<typeof zPxPos>
|
|
56
|
+
|
|
57
|
+
export const zPxSize = z.object({
|
|
58
|
+
pxWidth: zPx,
|
|
59
|
+
pxHeight: zPx
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
export type PxSize = z.infer<typeof zPxSize>
|
|
63
|
+
|
|
64
|
+
export const zEdge = z.object({
|
|
65
|
+
startX: zScaledIntPercentage,
|
|
66
|
+
startY: zScaledIntPercentage,
|
|
67
|
+
endX: zScaledIntPercentage,
|
|
68
|
+
endY: zScaledIntPercentage
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
export type Edge = z.infer<typeof zEdge>
|
|
72
|
+
|
|
73
|
+
export const zDirection = z.enum(["up", "down", "left", "right"] as const)
|
|
74
|
+
export const zExtendedDirection = z.union([zDirection, z.enum(["horizontal", "vertical"])])
|
|
75
|
+
export const zSide = z.enum(["top", "bottom", "left", "right"] as const)
|
|
76
|
+
export const zOrientation = z.enum(["horizontal", "vertical"])
|
|
77
|
+
export const zExtendedSide = z.union([zSide, zOrientation])
|
|
78
|
+
|
|
79
|
+
export type Direction = z.infer<typeof zDirection>
|
|
80
|
+
export type ExtendedDirection = z.infer<typeof zExtendedDirection>
|
|
81
|
+
export type Orientation = z.infer<typeof zOrientation>
|
|
82
|
+
|
|
83
|
+
export type EdgeSide = z.infer<typeof zSide>
|
|
84
|
+
export type ExtendedEdgeSide = z.infer<typeof zExtendedSide>
|
|
85
|
+
|
|
86
|
+
export const zBaseSquare = zSize.extend(zPos.shape)
|
|
87
|
+
export type BaseSquare = z.infer<typeof zBaseSquare>
|
|
88
|
+
export type BaseSquareCss = {
|
|
89
|
+
x: string
|
|
90
|
+
y: string
|
|
91
|
+
width: string
|
|
92
|
+
height: string
|
|
93
|
+
translate?: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type EdgeCss = BaseSquareCss & {
|
|
97
|
+
translate: string
|
|
98
|
+
}
|
|
99
|
+
export type PointCss = BaseSquareCss & {
|
|
100
|
+
translate: string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type Intersections = Record<number, Record<number, number>>
|
|
104
|
+
|
|
105
|
+
export type IntersectionEntry = {
|
|
106
|
+
point: Point
|
|
107
|
+
count: number
|
|
108
|
+
sharesEdge: boolean
|
|
109
|
+
sharedEdges: { horizontal: Edge[], vertical: Edge[] }
|
|
110
|
+
isWindowEdge: boolean
|
|
111
|
+
}
|
|
112
|
+
export const zLayoutFrame = z.looseObject({
|
|
113
|
+
id: z.uuid()
|
|
114
|
+
}).extend(zBaseSquare.shape)
|
|
115
|
+
|
|
116
|
+
export const zLayoutFramePassthrough = zLayoutFrame.passthrough()
|
|
117
|
+
|
|
118
|
+
export interface Register {
|
|
119
|
+
}
|
|
120
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
121
|
+
export type ExtendedLayoutFrame = Register extends { ExtendedLayoutFrame: infer T } ? T : unknown
|
|
122
|
+
export type ExtendedLayoutWindow = Register extends { ExtendedLayoutWindow: infer T } ? T : unknown
|
|
123
|
+
export type ExtendedLayout = Register extends { ExtendedLayout: infer T } ? T : unknown
|
|
124
|
+
export type ExtendedWorkspace = Register extends { ExtendedWorkspace: infer T } ? T : unknown
|
|
125
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
126
|
+
|
|
127
|
+
export type BaseLayoutFrame = Size & Pos & { id: FrameId }
|
|
128
|
+
export type LayoutFrame = ExtendedLayoutFrame & BaseLayoutFrame
|
|
129
|
+
export type LayoutFrames = Record<string, LayoutFrame>
|
|
130
|
+
|
|
131
|
+
const baseLayoutWindow = z.object({
|
|
132
|
+
id: z.uuid(),
|
|
133
|
+
activeFrame: z.string().optional(),
|
|
134
|
+
frames: z.record(z.string(), zLayoutFrame)
|
|
135
|
+
}).extend(zPxSize.shape)
|
|
136
|
+
.extend(zPxPos.shape)
|
|
137
|
+
|
|
138
|
+
export const zLayoutWindow = baseLayoutWindow.strict()
|
|
139
|
+
export const zLayoutWindowPassthrough = baseLayoutWindow
|
|
140
|
+
// types are re-declared so that if they are extended, the types are still correct
|
|
141
|
+
|
|
142
|
+
export type BaseLayoutWindow = {
|
|
143
|
+
id: WindowId
|
|
144
|
+
activeFrame?: string
|
|
145
|
+
frames: LayoutFrames
|
|
146
|
+
pxWidth: number
|
|
147
|
+
pxHeight: number
|
|
148
|
+
pxX: number
|
|
149
|
+
pxY: number
|
|
150
|
+
}
|
|
151
|
+
export type LayoutWindow = ExtendedLayoutWindow & BaseLayoutWindow
|
|
152
|
+
export type LayoutWindows = Record<string, LayoutWindow>
|
|
153
|
+
|
|
154
|
+
const baseWorkspace = zLayoutWindow.pick({ activeFrame: true, frames: true })
|
|
155
|
+
export const zWorkspace = baseWorkspace.strict()
|
|
156
|
+
export const zWorkspacePassthrough = zWorkspace.passthrough()
|
|
157
|
+
|
|
158
|
+
export type Workspace = Pick<LayoutWindow, "activeFrame" | "frames"> & ExtendedWorkspace
|
|
159
|
+
|
|
160
|
+
const baseLayout = z.looseObject({
|
|
161
|
+
activeWindow: z.string().optional(),
|
|
162
|
+
windows: z.record(z.string(), zLayoutWindow)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
export const zLayout = baseLayout.strict()
|
|
166
|
+
|
|
167
|
+
export const zInitializedLayout = zLayout.required({
|
|
168
|
+
activeWindow: true
|
|
169
|
+
})
|
|
170
|
+
.refine(layout => {
|
|
171
|
+
if (layout.windows[layout.activeWindow] === undefined) {
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
return zLayoutWindow.safeParse(layout.windows[layout.activeWindow]).success
|
|
175
|
+
}, { message: "An initialized layout's active window must exist and be valid." })
|
|
176
|
+
|
|
177
|
+
export type Layout = ExtendedLayout & {
|
|
178
|
+
activeWindow?: string
|
|
179
|
+
windows: LayoutWindows
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const zSplitDecoShapes = z.object({
|
|
183
|
+
edge: zEdge,
|
|
184
|
+
newFrame: zBaseSquare
|
|
185
|
+
}).strict()
|
|
186
|
+
|
|
187
|
+
export type SplitDecoShapes = z.infer<typeof zSplitDecoShapes>
|
|
188
|
+
export const zSplitDeco = z.object({
|
|
189
|
+
id: z.uuid(),
|
|
190
|
+
type: z.literal("split"),
|
|
191
|
+
position: zScaledIntPercentage,
|
|
192
|
+
direction: zDirection,
|
|
193
|
+
shapes: zSplitDecoShapes
|
|
194
|
+
}).strict()
|
|
195
|
+
export const zRawSplitDeco = zSplitDeco.omit({ shapes: true })
|
|
196
|
+
export type RawSplitDeco = z.infer<typeof zRawSplitDeco>
|
|
197
|
+
export type SplitDeco = z.infer<typeof zSplitDeco>
|
|
198
|
+
|
|
199
|
+
const zCloseDeco = z.object({
|
|
200
|
+
id: z.uuid(),
|
|
201
|
+
type: z.literal("close"),
|
|
202
|
+
force: z.boolean().optional()
|
|
203
|
+
}).strict()
|
|
204
|
+
export type CloseDeco = z.infer<typeof zCloseDeco>
|
|
205
|
+
|
|
206
|
+
const zDropDeco = z.object({
|
|
207
|
+
id: z.uuid(),
|
|
208
|
+
type: z.literal("drop"),
|
|
209
|
+
position: zSide.or(z.enum(["center"]))
|
|
210
|
+
}).strict()
|
|
211
|
+
|
|
212
|
+
export type DropDeco = z.infer<typeof zDropDeco>
|
|
213
|
+
|
|
214
|
+
export const zDeco = z.union([
|
|
215
|
+
zSplitDeco,
|
|
216
|
+
zCloseDeco,
|
|
217
|
+
zDropDeco
|
|
218
|
+
])
|
|
219
|
+
|
|
220
|
+
export type Deco = z.infer<typeof zDeco>
|
|
221
|
+
|
|
222
|
+
export const LAYOUT_ERROR = enumFromArray([
|
|
223
|
+
"INVALID_ID",
|
|
224
|
+
"ID_ALREADY_EXISTS",
|
|
225
|
+
"CANT_RESIZE",
|
|
226
|
+
"NO_ACTIVE_WINDOW",
|
|
227
|
+
"NO_ACTIVE_FRAME",
|
|
228
|
+
"CANT_CLOSE_NO_DRAG_EDGE",
|
|
229
|
+
"CANT_CLOSE_NEARBY_FRAMES_TOO_SMALL",
|
|
230
|
+
"CANT_CLOSE_SINGLE_FRAME",
|
|
231
|
+
"CANT_SPLIT_FRAME_TOO_SMALL",
|
|
232
|
+
"CANT_CLOSE_WITHOUT_FORCE"
|
|
233
|
+
])
|
|
234
|
+
|
|
235
|
+
export type LayoutError = EnumLike<typeof LAYOUT_ERROR>
|
|
236
|
+
|
|
237
|
+
export type AllErrors = LayoutError
|
|
238
|
+
|
|
239
|
+
export type ErrorInfo<T extends AllErrors> = AllErrorsInfo[T] extends undefined ? never : AllErrorsInfo[T]
|
|
240
|
+
|
|
241
|
+
type AllErrorsInfo = {
|
|
242
|
+
[LAYOUT_ERROR.INVALID_ID]: {
|
|
243
|
+
id: string | undefined
|
|
244
|
+
}
|
|
245
|
+
[LAYOUT_ERROR.ID_ALREADY_EXISTS]: {
|
|
246
|
+
id: string | undefined
|
|
247
|
+
}
|
|
248
|
+
[LAYOUT_ERROR.CANT_RESIZE]: {
|
|
249
|
+
size: Size
|
|
250
|
+
}
|
|
251
|
+
[LAYOUT_ERROR.NO_ACTIVE_WINDOW]: Record<string, never>
|
|
252
|
+
[LAYOUT_ERROR.NO_ACTIVE_FRAME]: Record<string, never>
|
|
253
|
+
[LAYOUT_ERROR.CANT_CLOSE_NO_DRAG_EDGE]: {
|
|
254
|
+
frame: LayoutFrame
|
|
255
|
+
}
|
|
256
|
+
[LAYOUT_ERROR.CANT_CLOSE_NEARBY_FRAMES_TOO_SMALL]: {
|
|
257
|
+
frame: LayoutFrame
|
|
258
|
+
nearbyFrames: LayoutFrame[]
|
|
259
|
+
minSize: Size
|
|
260
|
+
}
|
|
261
|
+
[LAYOUT_ERROR.CANT_CLOSE_SINGLE_FRAME]: {
|
|
262
|
+
frame: LayoutFrame
|
|
263
|
+
}
|
|
264
|
+
[LAYOUT_ERROR.CANT_SPLIT_FRAME_TOO_SMALL]: {
|
|
265
|
+
frame: LayoutFrame
|
|
266
|
+
newSize: number
|
|
267
|
+
minSize: number
|
|
268
|
+
}
|
|
269
|
+
[LAYOUT_ERROR.CANT_CLOSE_WITHOUT_FORCE]: {
|
|
270
|
+
frame: LayoutFrame
|
|
271
|
+
framesRequiredToBeDeleted: LayoutFrame[]
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// todo rename to toOpposite
|
|
276
|
+
export type HasOpposite = Direction | EdgeSide | ExtendedDirection | ExtendedEdgeSide | keyof Point | keyof Size
|
|
277
|
+
|
|
278
|
+
export const zWindowCreate = zLayoutWindowPassthrough
|
|
279
|
+
.partial({ id: true, pxWidth: true, pxHeight: true, pxX: true, pxY: true })
|
|
280
|
+
.extend({ frames: zLayoutWindow.shape.frames.optional() })
|
|
281
|
+
|
|
282
|
+
export const zLayoutCreate = baseLayout
|
|
283
|
+
.extend({
|
|
284
|
+
windows: zLayout.shape.windows.optional()
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
export const zFrameCreate = zLayoutFrame.partial({
|
|
288
|
+
id: true,
|
|
289
|
+
x: true,
|
|
290
|
+
y: true,
|
|
291
|
+
width: true,
|
|
292
|
+
height: true
|
|
293
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AllErrors, ErrorInfo } from "../types/index.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a known error that extends the base Error with some extra information.
|
|
5
|
+
* All the variables used to create the error message are stored in it's info property so we can easily re-craft error messages for users.
|
|
6
|
+
*/
|
|
7
|
+
export class KnownError<
|
|
8
|
+
T extends AllErrors = AllErrors,
|
|
9
|
+
TInfo extends ErrorInfo<T> = ErrorInfo<T>
|
|
10
|
+
> extends Error {
|
|
11
|
+
code: T
|
|
12
|
+
|
|
13
|
+
info: TInfo
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
code: T,
|
|
17
|
+
str: string,
|
|
18
|
+
info: TInfo
|
|
19
|
+
) {
|
|
20
|
+
super(str)
|
|
21
|
+
this.code = code
|
|
22
|
+
this.info = info
|
|
23
|
+
}
|
|
24
|
+
}
|