@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.
- 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 +123 -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 +140 -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,120 @@
|
|
|
1
|
+
import { enumFromArray } from "@alanscodelog/utils/enumFromArray";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export * from "../drag/types.js";
|
|
4
|
+
import { getMaxInt } from "../settings.js";
|
|
5
|
+
export const zUuid = z.uuid();
|
|
6
|
+
export const zWindowIdConstants = z.enum(["ACTIVE"]);
|
|
7
|
+
export const zWinId = z.uuid().or(zWindowIdConstants);
|
|
8
|
+
export const zFrameIdConstants = z.enum(["ACTIVE"]);
|
|
9
|
+
export const zFrameId = z.uuid().or(zFrameIdConstants);
|
|
10
|
+
export const zScaledIntPercentage = z.number().int().min(0).max(getMaxInt()).nonnegative();
|
|
11
|
+
const zPx = z.number().int().nonnegative();
|
|
12
|
+
export const zPos = z.object({
|
|
13
|
+
x: zScaledIntPercentage,
|
|
14
|
+
y: zScaledIntPercentage
|
|
15
|
+
});
|
|
16
|
+
export const zSize = z.object({
|
|
17
|
+
width: zScaledIntPercentage,
|
|
18
|
+
height: zScaledIntPercentage
|
|
19
|
+
});
|
|
20
|
+
export const zPoint = z.object({
|
|
21
|
+
x: zScaledIntPercentage,
|
|
22
|
+
y: zScaledIntPercentage
|
|
23
|
+
});
|
|
24
|
+
export const zPxPos = z.object({
|
|
25
|
+
pxX: zPx,
|
|
26
|
+
pxY: zPx
|
|
27
|
+
});
|
|
28
|
+
export const zPxSize = z.object({
|
|
29
|
+
pxWidth: zPx,
|
|
30
|
+
pxHeight: zPx
|
|
31
|
+
});
|
|
32
|
+
export const zEdge = z.object({
|
|
33
|
+
startX: zScaledIntPercentage,
|
|
34
|
+
startY: zScaledIntPercentage,
|
|
35
|
+
endX: zScaledIntPercentage,
|
|
36
|
+
endY: zScaledIntPercentage
|
|
37
|
+
});
|
|
38
|
+
export const zDirection = z.enum(["up", "down", "left", "right"]);
|
|
39
|
+
export const zExtendedDirection = z.union([zDirection, z.enum(["horizontal", "vertical"])]);
|
|
40
|
+
export const zSide = z.enum(["top", "bottom", "left", "right"]);
|
|
41
|
+
export const zOrientation = z.enum(["horizontal", "vertical"]);
|
|
42
|
+
export const zExtendedSide = z.union([zSide, zOrientation]);
|
|
43
|
+
export const zBaseSquare = zSize.extend(zPos.shape);
|
|
44
|
+
export const zLayoutFrame = z.looseObject({
|
|
45
|
+
id: z.uuid()
|
|
46
|
+
}).extend(zBaseSquare.shape);
|
|
47
|
+
export const zLayoutFramePassthrough = zLayoutFrame.passthrough();
|
|
48
|
+
const baseLayoutWindow = z.object({
|
|
49
|
+
id: z.uuid(),
|
|
50
|
+
activeFrame: z.string().optional(),
|
|
51
|
+
frames: z.record(z.string(), zLayoutFrame)
|
|
52
|
+
}).extend(zPxSize.shape).extend(zPxPos.shape);
|
|
53
|
+
export const zLayoutWindow = baseLayoutWindow.strict();
|
|
54
|
+
export const zLayoutWindowPassthrough = baseLayoutWindow;
|
|
55
|
+
const baseWorkspace = zLayoutWindow.pick({ activeFrame: true, frames: true });
|
|
56
|
+
export const zWorkspace = baseWorkspace.strict();
|
|
57
|
+
export const zWorkspacePassthrough = zWorkspace.passthrough();
|
|
58
|
+
const baseLayout = z.looseObject({
|
|
59
|
+
activeWindow: z.string().optional(),
|
|
60
|
+
windows: z.record(z.string(), zLayoutWindow)
|
|
61
|
+
});
|
|
62
|
+
export const zLayout = baseLayout.strict();
|
|
63
|
+
export const zInitializedLayout = zLayout.required({
|
|
64
|
+
activeWindow: true
|
|
65
|
+
}).refine((layout) => {
|
|
66
|
+
if (layout.windows[layout.activeWindow] === void 0) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return zLayoutWindow.safeParse(layout.windows[layout.activeWindow]).success;
|
|
70
|
+
}, { message: "An initialized layout's active window must exist and be valid." });
|
|
71
|
+
export const zSplitDecoShapes = z.object({
|
|
72
|
+
edge: zEdge,
|
|
73
|
+
newFrame: zBaseSquare
|
|
74
|
+
}).strict();
|
|
75
|
+
export const zSplitDeco = z.object({
|
|
76
|
+
id: z.uuid(),
|
|
77
|
+
type: z.literal("split"),
|
|
78
|
+
position: zScaledIntPercentage,
|
|
79
|
+
direction: zDirection,
|
|
80
|
+
shapes: zSplitDecoShapes
|
|
81
|
+
}).strict();
|
|
82
|
+
export const zRawSplitDeco = zSplitDeco.omit({ shapes: true });
|
|
83
|
+
const zCloseDeco = z.object({
|
|
84
|
+
id: z.uuid(),
|
|
85
|
+
type: z.literal("close"),
|
|
86
|
+
force: z.boolean().optional()
|
|
87
|
+
}).strict();
|
|
88
|
+
const zDropDeco = z.object({
|
|
89
|
+
id: z.uuid(),
|
|
90
|
+
type: z.literal("drop"),
|
|
91
|
+
position: zSide.or(z.enum(["center"]))
|
|
92
|
+
}).strict();
|
|
93
|
+
export const zDeco = z.union([
|
|
94
|
+
zSplitDeco,
|
|
95
|
+
zCloseDeco,
|
|
96
|
+
zDropDeco
|
|
97
|
+
]);
|
|
98
|
+
export const LAYOUT_ERROR = enumFromArray([
|
|
99
|
+
"INVALID_ID",
|
|
100
|
+
"ID_ALREADY_EXISTS",
|
|
101
|
+
"CANT_RESIZE",
|
|
102
|
+
"NO_ACTIVE_WINDOW",
|
|
103
|
+
"NO_ACTIVE_FRAME",
|
|
104
|
+
"CANT_CLOSE_NO_DRAG_EDGE",
|
|
105
|
+
"CANT_CLOSE_NEARBY_FRAMES_TOO_SMALL",
|
|
106
|
+
"CANT_CLOSE_SINGLE_FRAME",
|
|
107
|
+
"CANT_SPLIT_FRAME_TOO_SMALL",
|
|
108
|
+
"CANT_CLOSE_WITHOUT_FORCE"
|
|
109
|
+
]);
|
|
110
|
+
export const zWindowCreate = zLayoutWindowPassthrough.partial({ id: true, pxWidth: true, pxHeight: true, pxX: true, pxY: true }).extend({ frames: zLayoutWindow.shape.frames.optional() });
|
|
111
|
+
export const zLayoutCreate = baseLayout.extend({
|
|
112
|
+
windows: zLayout.shape.windows.optional()
|
|
113
|
+
});
|
|
114
|
+
export const zFrameCreate = zLayoutFrame.partial({
|
|
115
|
+
id: true,
|
|
116
|
+
x: true,
|
|
117
|
+
y: true,
|
|
118
|
+
width: true,
|
|
119
|
+
height: true
|
|
120
|
+
});
|
|
File without changes
|
package/dist/types.d.mts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@witchcraft/layout",
|
|
3
|
+
"description": "Headless layout manager.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"main": "./dist/runtime/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/runtime/index.d.ts",
|
|
11
|
+
"import": "./dist/runtime/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./components/*": {
|
|
14
|
+
"types": "./dist/runtime/components/*.vue.d.ts",
|
|
15
|
+
"import": "./dist/runtime/components/*.vue"
|
|
16
|
+
},
|
|
17
|
+
"./types": {
|
|
18
|
+
"types": "./dist/runtime/types/index.d.ts",
|
|
19
|
+
"import": "./dist/runtime/types/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./*": {
|
|
22
|
+
"types": "./dist/runtime/*.d.ts",
|
|
23
|
+
"import": "./dist/runtime/*.js"
|
|
24
|
+
},
|
|
25
|
+
"./nuxt": {
|
|
26
|
+
"types": "./dist/types.d.mts",
|
|
27
|
+
"import": "./dist/module.mjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"//prepare": "echo Needed so that if we pull the package from git it will get built and installed properly.",
|
|
32
|
+
"prepare": "husky && cd playground && pnpm i",
|
|
33
|
+
"build": "nuxt-module-build prepare && nuxt-module-build build && nuxi generate playground",
|
|
34
|
+
"build:only": "nuxt-module-build build",
|
|
35
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
36
|
+
"dev:playground": "nuxi dev playground",
|
|
37
|
+
"//dev:vite": "check everything is working when using vite",
|
|
38
|
+
"dev:vite": "vite --mode development --config vite.dev.config.ts",
|
|
39
|
+
"//dev": "The module needs to be build, not stubbed, for vite's dev to work.",
|
|
40
|
+
"dev": "pnpm dev:vite",
|
|
41
|
+
"lint:eslint": "eslint \"{src,tests,bin}/**/*.{cjs,js,ts}\" \"*.{cjs,js,ts}\" --max-warnings=3 --report-unused-disable-directives",
|
|
42
|
+
"lint:commits": "commitlint --from-last-tag --to HEAD --verbose",
|
|
43
|
+
"lint:imports": "echo disabled madge --circular --extensions ts ./src",
|
|
44
|
+
"lint": "pnpm lint:imports && pnpm lint:eslint && pnpm lint:types",
|
|
45
|
+
"lint:types": "vue-tsc --noEmit && cd playground",
|
|
46
|
+
"coverage": "vitest --coverage",
|
|
47
|
+
"coverage:dev": "vitest --watch --coverage",
|
|
48
|
+
"test": "echo no tests yet",
|
|
49
|
+
"test:watch": "vitest --watch",
|
|
50
|
+
"doc": "typedoc --options typedoc.config.js",
|
|
51
|
+
"doc:watch": "onchange -i \"src/**/*.ts\" \"typedoc.config.cjs\" -- pnpm doc",
|
|
52
|
+
"doc:serve": "http-server docs --port=5001",
|
|
53
|
+
"doc:dev": "concurrently \"pnpm doc:watch\" \"pnpm doc:serve\"",
|
|
54
|
+
"doc:check-invalid": "typedoc --options typedoc.config.cjs --listInvalidSymbolLinks",
|
|
55
|
+
"actions:debug": "act -r -v -j release",
|
|
56
|
+
"gen:exports": "indexit update --ignore **/*.d.ts **.vue src/assets/** -o '${path}.js'"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@alanscodelog/utils": "^6.0.1",
|
|
60
|
+
"@iconify/json": "^2.2.383",
|
|
61
|
+
"es-toolkit": "^1.39.10"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"@witchcraft/nuxt-utils": "^0.2.1",
|
|
65
|
+
"@witchcraft/ui": "^0.2.1"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"@witchcraft/ui": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"@witchcraft/nuxt-utils": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@alanscodelog/commitlint-config": "^3.1.2",
|
|
77
|
+
"@alanscodelog/eslint-config": "^6.3.0",
|
|
78
|
+
"@alanscodelog/semantic-release-config": "^5.0.4",
|
|
79
|
+
"@alanscodelog/tsconfigs": "^6.1.0",
|
|
80
|
+
"@alanscodelog/vite-config": "^0.0.6",
|
|
81
|
+
"@commitlint/cli": "^19.8.1",
|
|
82
|
+
"@nuxt/eslint-config": "^1.9.0",
|
|
83
|
+
"@nuxt/kit": "^4.1.2",
|
|
84
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
85
|
+
"@nuxt/schema": "^4.1.2",
|
|
86
|
+
"@nuxt/types": "^2.18.1",
|
|
87
|
+
"@tailwindcss/vite": "^4.1.12",
|
|
88
|
+
"@types/node": "^24.3.3",
|
|
89
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
90
|
+
"@vitest/coverage-c8": "^0.33.0",
|
|
91
|
+
"@witchcraft/nuxt-utils": "^0.3.2",
|
|
92
|
+
"@witchcraft/ui": "^0.2.1",
|
|
93
|
+
"concurrently": "^9.2.1",
|
|
94
|
+
"cross-env": "^10.0.0",
|
|
95
|
+
"fast-glob": "^3.3.3",
|
|
96
|
+
"http-server": "^14.1.1",
|
|
97
|
+
"husky": "^9.1.7",
|
|
98
|
+
"indexit": "2.1.0-beta.3",
|
|
99
|
+
"madge": "^8.0.0",
|
|
100
|
+
"nuxt": "^4.1.2",
|
|
101
|
+
"onchange": "^7.1.0",
|
|
102
|
+
"semantic-release": "^24.2.8",
|
|
103
|
+
"tailwindcss": "^4.1.12",
|
|
104
|
+
"typedoc": "0.28.12",
|
|
105
|
+
"typescript": "^5.8.3",
|
|
106
|
+
"unplugin-icons": "^22.3.0",
|
|
107
|
+
"unplugin-vue-components": "^29.0.0",
|
|
108
|
+
"uuid": "^13.0.0",
|
|
109
|
+
"vite": "^7.1.5",
|
|
110
|
+
"vitest": "^3.2.4",
|
|
111
|
+
"vue": "^3.5.20",
|
|
112
|
+
"vue-tsc": "^3.0.7",
|
|
113
|
+
"zod": "^4.1.8"
|
|
114
|
+
},
|
|
115
|
+
"author": "Alan <alanscodelog@gmail.com>",
|
|
116
|
+
"repository": "https://github.com/witchcraftjs/layout",
|
|
117
|
+
"license": "MIT",
|
|
118
|
+
"files": [
|
|
119
|
+
"src",
|
|
120
|
+
"dist"
|
|
121
|
+
],
|
|
122
|
+
"release": {
|
|
123
|
+
"extends": [
|
|
124
|
+
"@alanscodelog/semantic-release-config"
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
"commitlint": {
|
|
128
|
+
"extends": [
|
|
129
|
+
"@alanscodelog"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"madge": {
|
|
133
|
+
"detectiveOptions": {
|
|
134
|
+
"ts": {
|
|
135
|
+
"skipTypeImports": true
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"browserslist": "defaults and supports es6-module,maintained node versions",
|
|
140
|
+
"engines": {
|
|
141
|
+
"node": ">=20.0.0"
|
|
142
|
+
},
|
|
143
|
+
"@comments": {
|
|
144
|
+
"scripts": {
|
|
145
|
+
"test:inspect-errors": "For use with my inspect_error utility function from @alanscodelog/utils",
|
|
146
|
+
"prepare": "Needed so that if we pull the package from git it will get built and installed properly.",
|
|
147
|
+
"actions:debug": "For debugging github build action locally with nektos/act. Requires act and docker. Note: Cache will never work locally because of https://github.com/nektos/act/issues/285"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"publishConfig": {
|
|
151
|
+
"access": "public"
|
|
152
|
+
}
|
|
153
|
+
}
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addComponentsDir,
|
|
3
|
+
addTemplate,
|
|
4
|
+
createResolver,
|
|
5
|
+
defineNuxtModule
|
|
6
|
+
} from "@nuxt/kit"
|
|
7
|
+
|
|
8
|
+
export * from "./runtime/index.js"
|
|
9
|
+
|
|
10
|
+
declare module "@nuxt/schema" {
|
|
11
|
+
interface PublicRuntimeConfig {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ModuleOptions {
|
|
16
|
+
debug?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default defineNuxtModule<ModuleOptions>({
|
|
20
|
+
meta: {
|
|
21
|
+
name: "@witchcraft/layout",
|
|
22
|
+
configKey: "witchcraftLayout"
|
|
23
|
+
},
|
|
24
|
+
defaults: {
|
|
25
|
+
debug: false
|
|
26
|
+
},
|
|
27
|
+
async setup(_options, nuxt) {
|
|
28
|
+
const { resolve } = createResolver(import.meta.url)
|
|
29
|
+
// const logger = useLogger(moduleName, { level: options.debug ? 10 : 0 })
|
|
30
|
+
|
|
31
|
+
addComponentsDir({
|
|
32
|
+
path: resolve("runtime/components")
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
addTemplate({
|
|
36
|
+
filename: "witchcraft-layout.css",
|
|
37
|
+
write: true,
|
|
38
|
+
getContents: () => `@source "${resolve("runtime/components")}";`
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
nuxt.options.alias["#witchcraft-layout"] = resolve("runtime")
|
|
42
|
+
}
|
|
43
|
+
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- <div -->
|
|
3
|
+
<!-- v-bind="$attrs" -->
|
|
4
|
+
<!-- class="decos" -->
|
|
5
|
+
<!-- > -->
|
|
6
|
+
<template
|
|
7
|
+
v-for="(deco) of splitDecos"
|
|
8
|
+
:key="deco.id"
|
|
9
|
+
>
|
|
10
|
+
<LayoutShapeSquare
|
|
11
|
+
class="
|
|
12
|
+
deco-split-new-frame
|
|
13
|
+
bg-blue-500/50
|
|
14
|
+
"
|
|
15
|
+
:css="getShapeSquareCss( deco.shapes.newFrame, `var(--layoutEdgeWidth,2px)`)"
|
|
16
|
+
/>
|
|
17
|
+
<LayoutShapeSquare
|
|
18
|
+
class="
|
|
19
|
+
deco-split-edge
|
|
20
|
+
bg-red-500
|
|
21
|
+
"
|
|
22
|
+
:css="getVisualEdgeCss(deco.shapes.edge, {padLongAxis:`var(--layoutEdgeWidth,2px)`})"
|
|
23
|
+
/>
|
|
24
|
+
</template>
|
|
25
|
+
<template
|
|
26
|
+
v-for="deco of closeDecos"
|
|
27
|
+
:key="deco.id"
|
|
28
|
+
>
|
|
29
|
+
<LayoutShapeSquare
|
|
30
|
+
:class="`
|
|
31
|
+
${deco.force ? 'deco-close-force-frame' : 'deco-close-frame'}
|
|
32
|
+
bg-red-500/50
|
|
33
|
+
`"
|
|
34
|
+
:css="getShapeSquareCss( frames[deco.id], `var(--layoutEdgeWidth,2px)`)"
|
|
35
|
+
/>
|
|
36
|
+
</template>
|
|
37
|
+
<!-- </div> -->
|
|
38
|
+
</template>
|
|
39
|
+
<script lang="ts" setup>
|
|
40
|
+
import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
41
|
+
import type { PropType } from "vue"
|
|
42
|
+
import { computed, inject, ref, useAttrs } from "vue"
|
|
43
|
+
|
|
44
|
+
import LayoutShapeSquare from "./LayoutShapeSquare.vue"
|
|
45
|
+
|
|
46
|
+
import { dirToOrientation } from "../helpers/dirToOrientation.js"
|
|
47
|
+
import { getShapeSquareCss } from "../helpers/getShapeSquareCss"
|
|
48
|
+
import { getVisualEdgeCss } from "../helpers/getVisualEdgeCss"
|
|
49
|
+
import { type CloseDeco, type LayoutFrames, type Size, type SplitDeco } from "../types/index.js"
|
|
50
|
+
|
|
51
|
+
const $attrs = useAttrs()
|
|
52
|
+
|
|
53
|
+
const props = withDefaults(defineProps<{
|
|
54
|
+
frames: LayoutFrames
|
|
55
|
+
splitDecos: SplitDeco[]
|
|
56
|
+
closeDecos: CloseDeco[]
|
|
57
|
+
} >(),{
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
</script>
|
|
62
|
+
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<LayoutShapeSquare
|
|
3
|
+
v-if="activeFrame"
|
|
4
|
+
:css="getShapeSquareCss(activeFrame, `var(--layoutEdgeWidth,2px)`)"
|
|
5
|
+
:class="twMerge(`
|
|
6
|
+
active-frame-edge
|
|
7
|
+
pointer-events-none
|
|
8
|
+
z-0
|
|
9
|
+
border-blue-500
|
|
10
|
+
border
|
|
11
|
+
`,
|
|
12
|
+
)"
|
|
13
|
+
/>
|
|
14
|
+
|
|
15
|
+
<template
|
|
16
|
+
v-for="css, i of cssDragEdges"
|
|
17
|
+
:key="i"
|
|
18
|
+
>
|
|
19
|
+
<LayoutShapeSquare
|
|
20
|
+
:css="css.thick"
|
|
21
|
+
:class="twMerge(`
|
|
22
|
+
drag-edge
|
|
23
|
+
z-20
|
|
24
|
+
hover:cursor-pointer
|
|
25
|
+
[&:hover+.edge]:bg-blue-500/50
|
|
26
|
+
`)"
|
|
27
|
+
@pointerdown="emit('dragStart', $event, {edge:edges[i]})"
|
|
28
|
+
/>
|
|
29
|
+
<LayoutShapeSquare
|
|
30
|
+
:css="css.thin"
|
|
31
|
+
:class="twMerge(`
|
|
32
|
+
pointer-events-none
|
|
33
|
+
edge
|
|
34
|
+
`)"
|
|
35
|
+
/>
|
|
36
|
+
</template>
|
|
37
|
+
<LayoutShapeSquare
|
|
38
|
+
:css="css"
|
|
39
|
+
:class="twMerge(`
|
|
40
|
+
grabbed-edge
|
|
41
|
+
z-20
|
|
42
|
+
bg-blue-500/50
|
|
43
|
+
cursor-pointer
|
|
44
|
+
`)"
|
|
45
|
+
v-for="css, i of cssDragEdge"
|
|
46
|
+
:key="i"
|
|
47
|
+
/>
|
|
48
|
+
<template v-for="css, i of cssDragIntersections" :key="i">
|
|
49
|
+
<LayoutShapeSquare
|
|
50
|
+
:css="css.thick"
|
|
51
|
+
:class="twMerge(`
|
|
52
|
+
drag-intersection
|
|
53
|
+
z-30
|
|
54
|
+
rounded-full
|
|
55
|
+
hover:cursor-pointer
|
|
56
|
+
[&:hover+.intersection]:bg-blue-500/50
|
|
57
|
+
`,
|
|
58
|
+
)"
|
|
59
|
+
@pointerdown="emit('dragStart', $event, { intersection:wantedIntersections[i]})"
|
|
60
|
+
/>
|
|
61
|
+
<LayoutShapeSquare
|
|
62
|
+
:css="css.thin"
|
|
63
|
+
:class="twMerge(`
|
|
64
|
+
intersection
|
|
65
|
+
z-30
|
|
66
|
+
rounded-full
|
|
67
|
+
pointer-events-none
|
|
68
|
+
`,
|
|
69
|
+
css.thin._shifted && `w-[7px] h-[7px]`,
|
|
70
|
+
)"
|
|
71
|
+
/>
|
|
72
|
+
</template>
|
|
73
|
+
</template>
|
|
74
|
+
<script lang="ts" setup>
|
|
75
|
+
import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
76
|
+
import { computed,type PropType, ref,useAttrs } from "vue"
|
|
77
|
+
|
|
78
|
+
import LayoutShapeSquare from "./LayoutShapeSquare.vue"
|
|
79
|
+
|
|
80
|
+
import { frameToEdges } from "../helpers/frameToEdges.js"
|
|
81
|
+
import { getIntersectionsCss } from "../helpers/getIntersectionsCss.js"
|
|
82
|
+
import { getShapeSquareCss } from "../helpers/getShapeSquareCss.js"
|
|
83
|
+
import { getVisualEdgesCss } from "../helpers/getVisualEdgesCss.js"
|
|
84
|
+
import { isEdgeEqual } from "../helpers/isEdgeEqual.js"
|
|
85
|
+
import { toWindowCoord } from "../helpers/toWindowCoord.js"
|
|
86
|
+
import {
|
|
87
|
+
type Edge,
|
|
88
|
+
type EdgeCss,
|
|
89
|
+
type IntersectionEntry,
|
|
90
|
+
type LayoutFrame,
|
|
91
|
+
type LayoutWindow,
|
|
92
|
+
type Point,
|
|
93
|
+
} from "../types/index.js"
|
|
94
|
+
const $attrs = useAttrs()
|
|
95
|
+
|
|
96
|
+
const emit = defineEmits<{
|
|
97
|
+
dragStart: [e: PointerEvent, { edge?: Edge, intersection?: IntersectionEntry }]
|
|
98
|
+
}>()
|
|
99
|
+
const props = withDefaults(defineProps< {
|
|
100
|
+
edges: Edge[]
|
|
101
|
+
intersections: IntersectionEntry[]
|
|
102
|
+
/** The owning window, needed so we can correctly scale coordinates. */
|
|
103
|
+
win: LayoutWindow
|
|
104
|
+
/** The active frame, used to render the active edges. Calculate it from the `frames` returned by `useFrames` composable because otherwise it will be the wrong size while dragging. */
|
|
105
|
+
activeFrame?: LayoutFrame
|
|
106
|
+
draggingEdge?: Edge
|
|
107
|
+
draggingIntersection?: IntersectionEntry
|
|
108
|
+
}>(), {
|
|
109
|
+
activeFrame: undefined,
|
|
110
|
+
draggingEdge: undefined,
|
|
111
|
+
draggingIntersection: undefined,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
const activeFrameCssEdges = computed(() => {
|
|
116
|
+
if (!props.activeFrame) return []
|
|
117
|
+
return getVisualEdgesCss(Object.values(frameToEdges(props.activeFrame)), {
|
|
118
|
+
edgeWidth: `var(--layoutEdgeWidth, 2px)`,
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const cssDragEdges = computed(() => {
|
|
123
|
+
const thickEdges = getVisualEdgesCss(
|
|
124
|
+
props.draggingEdge
|
|
125
|
+
? props.edges.filter(_ => !isEdgeEqual(props.draggingEdge!, _))
|
|
126
|
+
: props.edges,
|
|
127
|
+
{
|
|
128
|
+
edgeWidth: `var(--layoutHandleWidth, 8px)`,
|
|
129
|
+
padLongAxis: `var(--layoutEdgeWidth, 2px)`,
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
const thinEdges = getVisualEdgesCss(props.edges, {
|
|
133
|
+
edgeWidth: `var(--layoutEdgeWidth, 2px)`,
|
|
134
|
+
padLongAxis: `(var(--layoutEdgeWidth, 2px) + var(--layoutExtraDragEdgePadding, 0px))`,
|
|
135
|
+
})
|
|
136
|
+
const edges: { thin: EdgeCss, thick: EdgeCss }[] = []
|
|
137
|
+
for (let i = 0; i < thickEdges.length; i++) {
|
|
138
|
+
edges.push({ thin: thinEdges[i], thick: thickEdges[i] })
|
|
139
|
+
}
|
|
140
|
+
return edges
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
const cssDragEdge = computed(() => {
|
|
144
|
+
if (!props.draggingEdge) return []
|
|
145
|
+
return getVisualEdgesCss([props.draggingEdge], {
|
|
146
|
+
edgeWidth: `var(--layoutEdgeWidth, 2px)`,
|
|
147
|
+
padLongAxis: `(var(--layoutEdgeWidth, 2px) + var(--layoutExtraDragEdgePadding, 0px))`,
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
const wantedIntersections = computed(() => props.intersections
|
|
153
|
+
.filter(_ => !_.isWindowEdge && (_.count === 4 || (_.count === 1 && _.sharesEdge)))
|
|
154
|
+
)
|
|
155
|
+
const cssDragIntersections = computed(() => {
|
|
156
|
+
const intersections: {
|
|
157
|
+
thick: ReturnType<typeof getIntersectionsCss>[number]
|
|
158
|
+
thin: ReturnType<typeof getIntersectionsCss>[number]
|
|
159
|
+
}[] = []
|
|
160
|
+
const thick = getIntersectionsCss(wantedIntersections.value, {
|
|
161
|
+
intersectionWidth: `var(--layoutIntersectionWidth, 15px)`,
|
|
162
|
+
})
|
|
163
|
+
const thin = getIntersectionsCss(wantedIntersections.value, {
|
|
164
|
+
})
|
|
165
|
+
for (let i = 0; i < thick.length; i++) {
|
|
166
|
+
intersections.push({ thick: thick[i], thin: thin[i] })
|
|
167
|
+
}
|
|
168
|
+
return intersections
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
</script>
|
|
172
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- @vue-expect-error just let it inherit extra attrs -->
|
|
3
|
+
<!-- overflow-hidden is just in case, if the frame's css is not properly set to h-full, overflow-auto, or the border/padding are too large, we can still get overflows -->
|
|
4
|
+
<LayoutShapeSquare
|
|
5
|
+
tabindex="0"
|
|
6
|
+
:css="getShapeSquareCss(frame)"
|
|
7
|
+
:class="twMerge(`
|
|
8
|
+
frame
|
|
9
|
+
p-[var(--layoutEdgeWidth,_2px)]
|
|
10
|
+
overflow-hidden
|
|
11
|
+
`,
|
|
12
|
+
$attrs.class
|
|
13
|
+
)"
|
|
14
|
+
v-bind="{...$attrs, class: undefined}"
|
|
15
|
+
@focus="emit('focus')"
|
|
16
|
+
>
|
|
17
|
+
<slot>
|
|
18
|
+
<div class="p-2 text-xs bg-neutral-500">
|
|
19
|
+
{{ debugFrame(frame) }}
|
|
20
|
+
</div>
|
|
21
|
+
<div>No slot found for `frame-{{ frame.id }}`. </div>
|
|
22
|
+
</slot>
|
|
23
|
+
</LayoutShapeSquare>
|
|
24
|
+
</template>
|
|
25
|
+
<script lang="ts" setup>
|
|
26
|
+
import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
27
|
+
import { type PropType } from "vue"
|
|
28
|
+
import { useAttrs } from "vue"
|
|
29
|
+
const $attrs = useAttrs()
|
|
30
|
+
|
|
31
|
+
import LayoutShapeSquare from "./LayoutShapeSquare.vue"
|
|
32
|
+
|
|
33
|
+
import { getShapeSquareCss } from "../helpers/getShapeSquareCss"
|
|
34
|
+
import { debugFrame } from "../layout/debugFrame.js"
|
|
35
|
+
import { type LayoutFrame } from "../types/index.js"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{
|
|
39
|
+
/** Documentation #todo */
|
|
40
|
+
(e: "focus"): void
|
|
41
|
+
}>()
|
|
42
|
+
|
|
43
|
+
/* const props = */defineProps({
|
|
44
|
+
frame: { type: Object as PropType<LayoutFrame>, required: true },
|
|
45
|
+
isActiveFrame: { type: Boolean, required: true },
|
|
46
|
+
})
|
|
47
|
+
</script>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:style="`
|
|
4
|
+
--posX:${css.x};
|
|
5
|
+
--posY:${css.y};
|
|
6
|
+
--width:${css.width};
|
|
7
|
+
--height:${css.height};
|
|
8
|
+
${css.translate ? `--translate:${css.translate}`: ``}
|
|
9
|
+
` + style"
|
|
10
|
+
:class="twMerge(`
|
|
11
|
+
absolute
|
|
12
|
+
w-[var(--width)]
|
|
13
|
+
h-[var(--height)]
|
|
14
|
+
top-[var(--posY)]
|
|
15
|
+
left-[var(--posX)]
|
|
16
|
+
`,
|
|
17
|
+
css.translate && `[transform:var(--translate)]`,
|
|
18
|
+
$attrs.class as any
|
|
19
|
+
)"
|
|
20
|
+
v-bind="{...$attrs, class: undefined}"
|
|
21
|
+
>
|
|
22
|
+
<slot/>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
<script setup lang="ts">
|
|
26
|
+
import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
27
|
+
import { type PropType } from "vue"
|
|
28
|
+
import { useAttrs } from "vue"
|
|
29
|
+
|
|
30
|
+
import type { BaseSquareCss } from "../types/index.js"
|
|
31
|
+
const $attrs = useAttrs()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
const props = defineProps({
|
|
35
|
+
style: { type: String, required: false, default: "" },
|
|
36
|
+
css: { type: Object as PropType<BaseSquareCss>, required: true },
|
|
37
|
+
})
|
|
38
|
+
</script>
|