@yuzhouu/canvas-kit 0.1.2
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 +145 -0
- package/_vendor/canvas-core/bindings/BindingUtil.ts +92 -0
- package/_vendor/canvas-core/bindings/BindingUtilRegistry.ts +22 -0
- package/_vendor/canvas-core/bindings/arrow/arrowBindingHelpers.ts +52 -0
- package/_vendor/canvas-core/contextMenu.ts +85 -0
- package/_vendor/canvas-core/editor/Editor.ts +2614 -0
- package/_vendor/canvas-core/editor/HistoryManager.ts +83 -0
- package/_vendor/canvas-core/editor/StateNode.ts +162 -0
- package/_vendor/canvas-core/editor/camera.ts +6 -0
- package/_vendor/canvas-core/editor/clipboard.ts +478 -0
- package/_vendor/canvas-core/editor/commands.ts +833 -0
- package/_vendor/canvas-core/editor/edgeScroll.ts +37 -0
- package/_vendor/canvas-core/editor/editorComputedHelpers.ts +257 -0
- package/_vendor/canvas-core/editor/editorSelectionTransforms.ts +116 -0
- package/_vendor/canvas-core/editor/events.ts +93 -0
- package/_vendor/canvas-core/editor/index.ts +12 -0
- package/_vendor/canvas-core/editor/interactions.ts +101 -0
- package/_vendor/canvas-core/editor/internal.ts +22 -0
- package/_vendor/canvas-core/editor/managers/BindingManager.ts +262 -0
- package/_vendor/canvas-core/editor/managers/CameraManager.ts +147 -0
- package/_vendor/canvas-core/editor/managers/ClipboardManager.ts +32 -0
- package/_vendor/canvas-core/editor/managers/DocumentSnapshotManager.ts +256 -0
- package/_vendor/canvas-core/editor/managers/InputsManager.ts +319 -0
- package/_vendor/canvas-core/editor/managers/InteractionTransientManager.ts +218 -0
- package/_vendor/canvas-core/editor/managers/QueryManager.ts +837 -0
- package/_vendor/canvas-core/editor/managers/RenderWindowManager.ts +347 -0
- package/_vendor/canvas-core/editor/managers/SelectionLayoutManager.ts +196 -0
- package/_vendor/canvas-core/editor/managers/SelectionManager.ts +98 -0
- package/_vendor/canvas-core/editor/managers/SelectionOverlayManager.ts +308 -0
- package/_vendor/canvas-core/editor/managers/ShapeEditingManager.ts +226 -0
- package/_vendor/canvas-core/editor/managers/ShapeGeometryManager.ts +162 -0
- package/_vendor/canvas-core/editor/managers/ShapeHierarchyManager.ts +797 -0
- package/_vendor/canvas-core/editor/managers/SideEffectManager.ts +83 -0
- package/_vendor/canvas-core/editor/managers/SnapManager.ts +433 -0
- package/_vendor/canvas-core/editor/managers/SnapSnapshotBuilder.ts +430 -0
- package/_vendor/canvas-core/editor/managers/SpatialIndexManager.ts +354 -0
- package/_vendor/canvas-core/editor/managers/ToolManager.ts +81 -0
- package/_vendor/canvas-core/editor/managers/queryState.ts +583 -0
- package/_vendor/canvas-core/editor/managers/selectionGeometry.ts +287 -0
- package/_vendor/canvas-core/editor/managers/shapeOrder.ts +350 -0
- package/_vendor/canvas-core/editor/managers/shapeReparenting.ts +160 -0
- package/_vendor/canvas-core/editor/managers/snapCalculations.ts +412 -0
- package/_vendor/canvas-core/editor/managers/snapGeometry.ts +202 -0
- package/_vendor/canvas-core/editor/managers/snapIndicators.ts +403 -0
- package/_vendor/canvas-core/editor/managers/snapTypes.ts +122 -0
- package/_vendor/canvas-core/editor/queries/shapeTransforms.ts +171 -0
- package/_vendor/canvas-core/editor/renderWindow.ts +439 -0
- package/_vendor/canvas-core/editor/resizeGeometry.ts +654 -0
- package/_vendor/canvas-core/editor/selection.ts +489 -0
- package/_vendor/canvas-core/editor/selectionHandleInteractions.ts +43 -0
- package/_vendor/canvas-core/editor/selectionOverlay.ts +567 -0
- package/_vendor/canvas-core/exports/integrity.ts +174 -0
- package/_vendor/canvas-core/exports/svg.ts +494 -0
- package/_vendor/canvas-core/geometry/Box.ts +80 -0
- package/_vendor/canvas-core/geometry/Ellipse2d.ts +67 -0
- package/_vendor/canvas-core/geometry/Geometry2d.ts +52 -0
- package/_vendor/canvas-core/geometry/Mat.ts +92 -0
- package/_vendor/canvas-core/geometry/Polyline2d.ts +63 -0
- package/_vendor/canvas-core/geometry/Rectangle2d.ts +64 -0
- package/_vendor/canvas-core/geometry/Vec.ts +123 -0
- package/_vendor/canvas-core/geometry/index.ts +13 -0
- package/_vendor/canvas-core/geometry/segments.ts +65 -0
- package/_vendor/canvas-core/index.ts +391 -0
- package/_vendor/canvas-core/plugins/index.ts +5 -0
- package/_vendor/canvas-core/plugins/types.ts +53 -0
- package/_vendor/canvas-core/reactivity.ts +16 -0
- package/_vendor/canvas-core/schema/records.ts +221 -0
- package/_vendor/canvas-core/schema/snapshots.ts +527 -0
- package/_vendor/canvas-core/shapes/ShapeUtil.ts +516 -0
- package/_vendor/canvas-core/shapes/ShapeUtilRegistry.ts +26 -0
- package/_vendor/canvas-core/shapes/capabilities.ts +67 -0
- package/_vendor/canvas-core/shapes/types.ts +20 -0
- package/_vendor/canvas-core/toolbar.ts +148 -0
- package/_vendor/canvas-core/tools/hand/HandTool.ts +75 -0
- package/_vendor/canvas-core/tools/index.ts +2 -0
- package/_vendor/canvas-core/tools/select/SelectTool.ts +33 -0
- package/_vendor/canvas-core/tools/select/selectContainment.ts +104 -0
- package/_vendor/canvas-core/tools/select/selectToolHelpers.ts +801 -0
- package/_vendor/canvas-core/tools/select/states/BrushingState.ts +145 -0
- package/_vendor/canvas-core/tools/select/states/DraggingSelectionHandleInteractionState.ts +116 -0
- package/_vendor/canvas-core/tools/select/states/IdleState.ts +159 -0
- package/_vendor/canvas-core/tools/select/states/PointingCanvasState.ts +41 -0
- package/_vendor/canvas-core/tools/select/states/PointingResizeHandleState.ts +78 -0
- package/_vendor/canvas-core/tools/select/states/PointingRotateHandleState.ts +64 -0
- package/_vendor/canvas-core/tools/select/states/PointingSelectionHandleInteractionState.ts +34 -0
- package/_vendor/canvas-core/tools/select/states/PointingShapeState.ts +140 -0
- package/_vendor/canvas-core/tools/select/states/ResizingState.ts +171 -0
- package/_vendor/canvas-core/tools/select/states/RotatingState.ts +124 -0
- package/_vendor/canvas-core/tools/select/states/SelectStateNode.ts +128 -0
- package/_vendor/canvas-core/tools/select/states/TranslatingState.ts +139 -0
- package/_vendor/canvas-core/tools/select/states/index.ts +11 -0
- package/_vendor/canvas-plugin-api/feature.ts +204 -0
- package/_vendor/canvas-plugin-api/index.ts +142 -0
- package/_vendor/canvas-product-react/api/apiRegistry.ts +35 -0
- package/_vendor/canvas-product-react/api/canvasProductApi.ts +422 -0
- package/_vendor/canvas-product-react/api/index.ts +31 -0
- package/_vendor/canvas-product-react/capabilities/clipboard/clipboardService.ts +36 -0
- package/_vendor/canvas-product-react/capabilities/clipboard/systemClipboard.ts +245 -0
- package/_vendor/canvas-product-react/capabilities/context-menu/systemContextMenu.ts +396 -0
- package/_vendor/canvas-product-react/capabilities/context-menu/useContextMenuSurface.ts +59 -0
- package/_vendor/canvas-product-react/capabilities/export/useSvgExport.ts +156 -0
- package/_vendor/canvas-product-react/capabilities/history/useHistoryControls.ts +23 -0
- package/_vendor/canvas-product-react/capabilities/pages/usePageControls.ts +41 -0
- package/_vendor/canvas-product-react/capabilities/toolbar/systemToolbar.ts +490 -0
- package/_vendor/canvas-product-react/capabilities/toolbar/useToolbarSurfaces.ts +92 -0
- package/_vendor/canvas-product-react/capabilities/zoom/useZoomControls.ts +27 -0
- package/_vendor/canvas-product-react/index.ts +84 -0
- package/_vendor/canvas-product-react/persistence/index.ts +18 -0
- package/_vendor/canvas-product-react/persistence/localSnapshotPersistence.ts +294 -0
- package/_vendor/canvas-product-react/runtime/CanvasProductRoot.tsx +250 -0
- package/_vendor/canvas-product-react/runtime/productDefinition.ts +72 -0
- package/_vendor/canvas-product-react/runtime/productServices.ts +96 -0
- package/_vendor/canvas-react/components/CanvasView.tsx +796 -0
- package/_vendor/canvas-react/components/OverlayLayer.tsx +879 -0
- package/_vendor/canvas-react/components/PageSpace.tsx +34 -0
- package/_vendor/canvas-react/components/ShapeLayer.tsx +428 -0
- package/_vendor/canvas-react/components/index.ts +4 -0
- package/_vendor/canvas-react/hooks/useEditor.ts +11 -0
- package/_vendor/canvas-react/hooks/useValue.ts +14 -0
- package/_vendor/canvas-react/host/CanvasRendererRegistryContext.tsx +14 -0
- package/_vendor/canvas-react/host/contextMenuRegistry.ts +61 -0
- package/_vendor/canvas-react/host/domEventGuards.ts +61 -0
- package/_vendor/canvas-react/host/index.ts +38 -0
- package/_vendor/canvas-react/host/pluginHost.ts +635 -0
- package/_vendor/canvas-react/host/rendererRegistry.tsx +58 -0
- package/_vendor/canvas-react/host/toolbarRegistry.ts +100 -0
- package/_vendor/canvas-react/index.ts +3 -0
- package/_vendor/plugin-arrow/ArrowBindingUtil.ts +239 -0
- package/_vendor/plugin-arrow/ArrowShapeUtil.ts +311 -0
- package/_vendor/plugin-arrow/ArrowTool.ts +208 -0
- package/_vendor/plugin-arrow/arrowGeometry.ts +441 -0
- package/_vendor/plugin-arrow/arrowTerminalBindingResolver.ts +253 -0
- package/_vendor/plugin-arrow/arrowTerminalCommands.ts +230 -0
- package/_vendor/plugin-arrow/canvas.tsx +92 -0
- package/_vendor/plugin-arrow/core.ts +409 -0
- package/_vendor/plugin-arrow/feature.ts +20 -0
- package/_vendor/plugin-arrow/index.ts +28 -0
- package/_vendor/plugin-arrow/selectionHandleInteractions.ts +154 -0
- package/_vendor/plugin-arrow/types.ts +63 -0
- package/_vendor/plugin-draw/DrawShapeRenderer.tsx +60 -0
- package/_vendor/plugin-draw/DrawShapeUtil.ts +372 -0
- package/_vendor/plugin-draw/DrawTool.ts +444 -0
- package/_vendor/plugin-draw/canvas.tsx +24 -0
- package/_vendor/plugin-draw/core.ts +515 -0
- package/_vendor/plugin-draw/drawGeometry.ts +491 -0
- package/_vendor/plugin-draw/drawHitTest.ts +271 -0
- package/_vendor/plugin-draw/drawInterpolation.ts +250 -0
- package/_vendor/plugin-draw/drawPath.ts +550 -0
- package/_vendor/plugin-draw/drawSegments.ts +106 -0
- package/_vendor/plugin-draw/drawSelectionTransform.ts +67 -0
- package/_vendor/plugin-draw/drawShapeGeometry.ts +307 -0
- package/_vendor/plugin-draw/drawStrokeGeometry.ts +454 -0
- package/_vendor/plugin-draw/feature.ts +20 -0
- package/_vendor/plugin-draw/index.ts +31 -0
- package/_vendor/plugin-draw/types.ts +36 -0
- package/_vendor/plugin-eraser/EraserTool.ts +297 -0
- package/_vendor/plugin-eraser/canvas.tsx +616 -0
- package/_vendor/plugin-eraser/core.ts +49 -0
- package/_vendor/plugin-eraser/feature.ts +20 -0
- package/_vendor/plugin-eraser/index.ts +4 -0
- package/_vendor/plugin-frame/FrameShapeUtil.ts +173 -0
- package/_vendor/plugin-frame/FrameTool.ts +225 -0
- package/_vendor/plugin-frame/canvas.tsx +75 -0
- package/_vendor/plugin-frame/core.ts +534 -0
- package/_vendor/plugin-frame/feature.ts +20 -0
- package/_vendor/plugin-frame/index.ts +6 -0
- package/_vendor/plugin-geo/GeoShapeUtil.ts +463 -0
- package/_vendor/plugin-geo/GeoTools.ts +247 -0
- package/_vendor/plugin-geo/canvas.tsx +90 -0
- package/_vendor/plugin-geo/core.ts +495 -0
- package/_vendor/plugin-geo/feature.ts +20 -0
- package/_vendor/plugin-geo/index.ts +7 -0
- package/_vendor/plugin-geo/types.ts +27 -0
- package/_vendor/plugin-group/GroupShapeUtil.ts +59 -0
- package/_vendor/plugin-group/canvas.tsx +59 -0
- package/_vendor/plugin-group/core.ts +40 -0
- package/_vendor/plugin-group/feature.ts +20 -0
- package/_vendor/plugin-group/index.ts +5 -0
- package/_vendor/plugin-image/ImageShapeUtil.ts +95 -0
- package/_vendor/plugin-image/canvas.tsx +212 -0
- package/_vendor/plugin-image/core.ts +542 -0
- package/_vendor/plugin-image/crop.ts +770 -0
- package/_vendor/plugin-image/cropInteractions.ts +350 -0
- package/_vendor/plugin-image/cropSession.ts +38 -0
- package/_vendor/plugin-image/feature.ts +20 -0
- package/_vendor/plugin-image/index.ts +29 -0
- package/_vendor/plugin-image/types.ts +55 -0
- package/_vendor/plugin-image-product-react/ImageImportController.tsx +143 -0
- package/_vendor/plugin-image-product-react/imageAssetService.ts +52 -0
- package/_vendor/plugin-image-product-react/imageBlobStore.ts +315 -0
- package/_vendor/plugin-image-product-react/imageHostActions.ts +438 -0
- package/_vendor/plugin-image-product-react/imageProductApi.ts +88 -0
- package/_vendor/plugin-image-product-react/imageToolbarHostBridge.ts +48 -0
- package/_vendor/plugin-image-product-react/imageToolbarRuntime.ts +21 -0
- package/_vendor/plugin-image-product-react/index.ts +60 -0
- package/_vendor/plugin-image-product-react/snapshotGuards.ts +33 -0
- package/_vendor/plugin-image-product-react/svgImageAssetInliner.ts +54 -0
- package/_vendor/plugin-image-product-react/useImageImport.ts +64 -0
- package/_vendor/plugin-laser/LaserTool.ts +154 -0
- package/_vendor/plugin-laser/canvas.tsx +645 -0
- package/_vendor/plugin-laser/core.ts +49 -0
- package/_vendor/plugin-laser/feature.ts +20 -0
- package/_vendor/plugin-laser/index.ts +4 -0
- package/_vendor/plugin-text/ArrowLabelBindingUtil.ts +336 -0
- package/_vendor/plugin-text/GeoLabelBindingUtil.ts +391 -0
- package/_vendor/plugin-text/TextShapeSvgExporter.ts +101 -0
- package/_vendor/plugin-text/TextShapeUtil.ts +284 -0
- package/_vendor/plugin-text/TextTool.ts +228 -0
- package/_vendor/plugin-text/canvas.tsx +115 -0
- package/_vendor/plugin-text/core.ts +422 -0
- package/_vendor/plugin-text/feature.ts +20 -0
- package/_vendor/plugin-text/host/RichTextEditingBox.tsx +144 -0
- package/_vendor/plugin-text/host/RichTextToolbar.tsx +266 -0
- package/_vendor/plugin-text/host/TiptapTextEditor.tsx +191 -0
- package/_vendor/plugin-text/host/richTextRendering.tsx +49 -0
- package/_vendor/plugin-text/host/textDomSelection.ts +93 -0
- package/_vendor/plugin-text/host/textEditingBoxStyle.ts +36 -0
- package/_vendor/plugin-text/host/textEntryFocus.ts +307 -0
- package/_vendor/plugin-text/host/textFontLoader.ts +149 -0
- package/_vendor/plugin-text/host/textMeasurement.ts +258 -0
- package/_vendor/plugin-text/host/textMeasurementSync.ts +77 -0
- package/_vendor/plugin-text/host/textRangeSelection.ts +134 -0
- package/_vendor/plugin-text/host/textShapeRendererRuntime.tsx +89 -0
- package/_vendor/plugin-text/host/textShapeSync.ts +173 -0
- package/_vendor/plugin-text/host/tiptapTextEditorController.ts +148 -0
- package/_vendor/plugin-text/index.ts +18 -0
- package/_vendor/plugin-text/richTextUtils.ts +259 -0
- package/_vendor/plugin-text/textInteractions.ts +366 -0
- package/_vendor/plugin-text/textLabelHelpers.ts +235 -0
- package/_vendor/plugin-text/textShapeHelpers.ts +123 -0
- package/_vendor/plugin-text/textStyle.ts +96 -0
- package/_vendor/plugin-text/textTypes.ts +48 -0
- package/_vendor/signals/atom.ts +74 -0
- package/_vendor/signals/computed.ts +132 -0
- package/_vendor/signals/core.ts +130 -0
- package/_vendor/signals/effect.ts +117 -0
- package/_vendor/signals/index.ts +9 -0
- package/_vendor/signals/types.ts +17 -0
- package/_vendor/store/Store.ts +171 -0
- package/_vendor/store/diff.ts +229 -0
- package/_vendor/store/history.ts +177 -0
- package/_vendor/store/index.ts +32 -0
- package/_vendor/store/types.ts +37 -0
- package/api/canvasKitApi.d.ts +29 -0
- package/index.css +3 -0
- package/index.d.ts +16 -0
- package/index.mjs +1 -0
- package/internal-modules.d.ts +187 -0
- package/package.json +48 -0
- package/product/Shell.d.ts +19 -0
- package/product/chromeContext.d.ts +70 -0
- package/product/createCanvasKitEditor.d.ts +6 -0
- package/product/index.d.ts +7 -0
- package/product/persistence.d.ts +3 -0
- package/product/product.d.ts +22 -0
- package/product/useCanvasClipboardShortcuts.d.ts +6 -0
- package/product-iyBbEPIs.mjs +4 -0
- package/product.mjs +1 -0
- package/standard/extensions.d.ts +1 -0
- package/standard/index.d.ts +3 -0
- package/standard/standardApi.d.ts +91 -0
- package/standard-BmrxwqpJ.mjs +44 -0
- package/standard.mjs +1 -0
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
import { Box } from "../geometry/Box";
|
|
2
|
+
import { Vec } from "../geometry/Vec";
|
|
3
|
+
import type { SelectionResizeHandleId } from "./selection";
|
|
4
|
+
|
|
5
|
+
const MIN_SELECTION_RESIZE_SIZE = 1;
|
|
6
|
+
|
|
7
|
+
export interface SelectionResizeBoundsResult {
|
|
8
|
+
bounds: Box;
|
|
9
|
+
scaleX: number;
|
|
10
|
+
scaleY: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface SelectionResizeScalesResult {
|
|
14
|
+
scaleX: number;
|
|
15
|
+
scaleY: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function selectionResizeHandleMovesLeftEdge(
|
|
19
|
+
handleId: SelectionResizeHandleId,
|
|
20
|
+
): boolean {
|
|
21
|
+
return (
|
|
22
|
+
handleId === "top_left" ||
|
|
23
|
+
handleId === "left" ||
|
|
24
|
+
handleId === "bottom_left"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function selectionResizeHandleMovesRightEdge(
|
|
29
|
+
handleId: SelectionResizeHandleId,
|
|
30
|
+
): boolean {
|
|
31
|
+
return (
|
|
32
|
+
handleId === "top_right" ||
|
|
33
|
+
handleId === "right" ||
|
|
34
|
+
handleId === "bottom_right"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function selectionResizeHandleMovesTopEdge(
|
|
39
|
+
handleId: SelectionResizeHandleId,
|
|
40
|
+
): boolean {
|
|
41
|
+
return (
|
|
42
|
+
handleId === "top_left" ||
|
|
43
|
+
handleId === "top" ||
|
|
44
|
+
handleId === "top_right"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function selectionResizeHandleMovesBottomEdge(
|
|
49
|
+
handleId: SelectionResizeHandleId,
|
|
50
|
+
): boolean {
|
|
51
|
+
return (
|
|
52
|
+
handleId === "bottom_left" ||
|
|
53
|
+
handleId === "bottom" ||
|
|
54
|
+
handleId === "bottom_right"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isSelectionResizeCorner(
|
|
59
|
+
handleId: SelectionResizeHandleId,
|
|
60
|
+
): boolean {
|
|
61
|
+
return (
|
|
62
|
+
selectionResizeHandleMovesLeftEdge(handleId) !==
|
|
63
|
+
selectionResizeHandleMovesRightEdge(handleId) &&
|
|
64
|
+
selectionResizeHandleMovesTopEdge(handleId) !==
|
|
65
|
+
selectionResizeHandleMovesBottomEdge(handleId)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getSelectionResizeHandleForScale({
|
|
70
|
+
handleId,
|
|
71
|
+
scaleX,
|
|
72
|
+
scaleY,
|
|
73
|
+
}: {
|
|
74
|
+
handleId: SelectionResizeHandleId;
|
|
75
|
+
scaleX: number;
|
|
76
|
+
scaleY: number;
|
|
77
|
+
}): SelectionResizeHandleId {
|
|
78
|
+
const horizontal = selectionResizeHandleMovesLeftEdge(handleId)
|
|
79
|
+
? scaleX < 0
|
|
80
|
+
? "right"
|
|
81
|
+
: "left"
|
|
82
|
+
: selectionResizeHandleMovesRightEdge(handleId)
|
|
83
|
+
? scaleX < 0
|
|
84
|
+
? "left"
|
|
85
|
+
: "right"
|
|
86
|
+
: null;
|
|
87
|
+
const vertical = selectionResizeHandleMovesTopEdge(handleId)
|
|
88
|
+
? scaleY < 0
|
|
89
|
+
? "bottom"
|
|
90
|
+
: "top"
|
|
91
|
+
: selectionResizeHandleMovesBottomEdge(handleId)
|
|
92
|
+
? scaleY < 0
|
|
93
|
+
? "top"
|
|
94
|
+
: "bottom"
|
|
95
|
+
: null;
|
|
96
|
+
|
|
97
|
+
if (vertical === "top" && horizontal === "left") return "top_left";
|
|
98
|
+
if (vertical === "top" && horizontal === "right") return "top_right";
|
|
99
|
+
if (vertical === "bottom" && horizontal === "right") return "bottom_right";
|
|
100
|
+
if (vertical === "bottom" && horizontal === "left") return "bottom_left";
|
|
101
|
+
if (vertical) return vertical;
|
|
102
|
+
if (horizontal) return horizontal;
|
|
103
|
+
return handleId;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function getSelectionResizeScalesFromBounds({
|
|
107
|
+
startBounds,
|
|
108
|
+
bounds,
|
|
109
|
+
handleId,
|
|
110
|
+
scaleX,
|
|
111
|
+
scaleY,
|
|
112
|
+
isResizingFromCenter = false,
|
|
113
|
+
}: {
|
|
114
|
+
startBounds: Box;
|
|
115
|
+
bounds: Box;
|
|
116
|
+
handleId: SelectionResizeHandleId;
|
|
117
|
+
scaleX?: number;
|
|
118
|
+
scaleY?: number;
|
|
119
|
+
isResizingFromCenter?: boolean;
|
|
120
|
+
}): SelectionResizeScalesResult {
|
|
121
|
+
const scaleXSign = getSelectionResizeScaleSign({
|
|
122
|
+
axis: "x",
|
|
123
|
+
startBounds,
|
|
124
|
+
bounds,
|
|
125
|
+
handleId,
|
|
126
|
+
scale: scaleX,
|
|
127
|
+
isResizingFromCenter,
|
|
128
|
+
});
|
|
129
|
+
const scaleYSign = getSelectionResizeScaleSign({
|
|
130
|
+
axis: "y",
|
|
131
|
+
startBounds,
|
|
132
|
+
bounds,
|
|
133
|
+
handleId,
|
|
134
|
+
scale: scaleY,
|
|
135
|
+
isResizingFromCenter,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
scaleX:
|
|
140
|
+
selectionResizeHandleMovesLeftEdge(handleId) ||
|
|
141
|
+
selectionResizeHandleMovesRightEdge(handleId)
|
|
142
|
+
? scaleXSign *
|
|
143
|
+
(bounds.w / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.w))
|
|
144
|
+
: (scaleX ?? 1),
|
|
145
|
+
scaleY:
|
|
146
|
+
selectionResizeHandleMovesTopEdge(handleId) ||
|
|
147
|
+
selectionResizeHandleMovesBottomEdge(handleId)
|
|
148
|
+
? scaleYSign *
|
|
149
|
+
(bounds.h / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.h))
|
|
150
|
+
: (scaleY ?? 1),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function getSelectionResizeScaleSign({
|
|
155
|
+
axis,
|
|
156
|
+
startBounds,
|
|
157
|
+
bounds,
|
|
158
|
+
handleId,
|
|
159
|
+
scale,
|
|
160
|
+
isResizingFromCenter,
|
|
161
|
+
}: {
|
|
162
|
+
axis: "x" | "y";
|
|
163
|
+
startBounds: Box;
|
|
164
|
+
bounds: Box;
|
|
165
|
+
handleId: SelectionResizeHandleId;
|
|
166
|
+
scale?: number;
|
|
167
|
+
isResizingFromCenter: boolean;
|
|
168
|
+
}): number {
|
|
169
|
+
const fallback = Math.sign(scale ?? 1) || 1;
|
|
170
|
+
if (isResizingFromCenter) {
|
|
171
|
+
return fallback;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (axis === "x") {
|
|
175
|
+
if (selectionResizeHandleMovesLeftEdge(handleId)) {
|
|
176
|
+
return bounds.minX >= startBounds.maxX ? -1 : 1;
|
|
177
|
+
}
|
|
178
|
+
if (selectionResizeHandleMovesRightEdge(handleId)) {
|
|
179
|
+
return bounds.maxX <= startBounds.minX ? -1 : 1;
|
|
180
|
+
}
|
|
181
|
+
return fallback;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (selectionResizeHandleMovesTopEdge(handleId)) {
|
|
185
|
+
return bounds.minY >= startBounds.maxY ? -1 : 1;
|
|
186
|
+
}
|
|
187
|
+
if (selectionResizeHandleMovesBottomEdge(handleId)) {
|
|
188
|
+
return bounds.maxY <= startBounds.minY ? -1 : 1;
|
|
189
|
+
}
|
|
190
|
+
return fallback;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function getAnchoredSelectionResizeLocalBounds({
|
|
194
|
+
requestedBounds,
|
|
195
|
+
handleId,
|
|
196
|
+
actualWidth,
|
|
197
|
+
actualHeight,
|
|
198
|
+
scaleX,
|
|
199
|
+
scaleY,
|
|
200
|
+
isResizingFromCenter,
|
|
201
|
+
}: {
|
|
202
|
+
requestedBounds: Box;
|
|
203
|
+
handleId: SelectionResizeHandleId;
|
|
204
|
+
actualWidth: number;
|
|
205
|
+
actualHeight: number;
|
|
206
|
+
scaleX: number;
|
|
207
|
+
scaleY: number;
|
|
208
|
+
isResizingFromCenter: boolean;
|
|
209
|
+
}): Box {
|
|
210
|
+
const x = isResizingFromCenter
|
|
211
|
+
? requestedBounds.center.x - actualWidth / 2
|
|
212
|
+
: selectionResizeHandleMovesLeftEdge(handleId)
|
|
213
|
+
? scaleX < 0
|
|
214
|
+
? requestedBounds.minX
|
|
215
|
+
: requestedBounds.maxX - actualWidth
|
|
216
|
+
: selectionResizeHandleMovesRightEdge(handleId)
|
|
217
|
+
? scaleX < 0
|
|
218
|
+
? requestedBounds.maxX - actualWidth
|
|
219
|
+
: requestedBounds.minX
|
|
220
|
+
: requestedBounds.center.x - actualWidth / 2;
|
|
221
|
+
const y = isResizingFromCenter
|
|
222
|
+
? requestedBounds.center.y - actualHeight / 2
|
|
223
|
+
: selectionResizeHandleMovesTopEdge(handleId)
|
|
224
|
+
? scaleY < 0
|
|
225
|
+
? requestedBounds.minY
|
|
226
|
+
: requestedBounds.maxY - actualHeight
|
|
227
|
+
: selectionResizeHandleMovesBottomEdge(handleId)
|
|
228
|
+
? scaleY < 0
|
|
229
|
+
? requestedBounds.maxY - actualHeight
|
|
230
|
+
: requestedBounds.minY
|
|
231
|
+
: requestedBounds.center.y - actualHeight / 2;
|
|
232
|
+
|
|
233
|
+
return new Box(x, y, actualWidth, actualHeight);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function getSelectionResizeBounds({
|
|
237
|
+
startBounds,
|
|
238
|
+
handleId,
|
|
239
|
+
pagePoint,
|
|
240
|
+
}: {
|
|
241
|
+
startBounds: Box;
|
|
242
|
+
handleId: SelectionResizeHandleId;
|
|
243
|
+
pagePoint: Vec;
|
|
244
|
+
}): Box {
|
|
245
|
+
return getSelectionResizeBoundsWithScale({
|
|
246
|
+
startBounds,
|
|
247
|
+
handleId,
|
|
248
|
+
pagePoint,
|
|
249
|
+
}).bounds;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function getSelectionResizeBoundsWithScale({
|
|
253
|
+
startBounds,
|
|
254
|
+
handleId,
|
|
255
|
+
pagePoint,
|
|
256
|
+
}: {
|
|
257
|
+
startBounds: Box;
|
|
258
|
+
handleId: SelectionResizeHandleId;
|
|
259
|
+
pagePoint: Vec;
|
|
260
|
+
}): SelectionResizeBoundsResult {
|
|
261
|
+
const startMinX = startBounds.minX;
|
|
262
|
+
const startMaxX = startBounds.maxX;
|
|
263
|
+
const startMinY = startBounds.minY;
|
|
264
|
+
const startMaxY = startBounds.maxY;
|
|
265
|
+
let movingX = selectionResizeHandleMovesLeftEdge(handleId)
|
|
266
|
+
? startMinX
|
|
267
|
+
: startMaxX;
|
|
268
|
+
let anchoredX = selectionResizeHandleMovesLeftEdge(handleId)
|
|
269
|
+
? startMaxX
|
|
270
|
+
: startMinX;
|
|
271
|
+
let movingY = selectionResizeHandleMovesTopEdge(handleId)
|
|
272
|
+
? startMinY
|
|
273
|
+
: startMaxY;
|
|
274
|
+
let anchoredY = selectionResizeHandleMovesTopEdge(handleId)
|
|
275
|
+
? startMaxY
|
|
276
|
+
: startMinY;
|
|
277
|
+
|
|
278
|
+
if (selectionResizeHandleMovesLeftEdge(handleId)) {
|
|
279
|
+
movingX = pagePoint.x;
|
|
280
|
+
} else if (selectionResizeHandleMovesRightEdge(handleId)) {
|
|
281
|
+
movingX = pagePoint.x;
|
|
282
|
+
} else {
|
|
283
|
+
movingX = startMaxX;
|
|
284
|
+
anchoredX = startMinX;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (selectionResizeHandleMovesTopEdge(handleId)) {
|
|
288
|
+
movingY = pagePoint.y;
|
|
289
|
+
} else if (selectionResizeHandleMovesBottomEdge(handleId)) {
|
|
290
|
+
movingY = pagePoint.y;
|
|
291
|
+
} else {
|
|
292
|
+
movingY = startMaxY;
|
|
293
|
+
anchoredY = startMinY;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const rawWidth = movingX - anchoredX;
|
|
297
|
+
const rawHeight = movingY - anchoredY;
|
|
298
|
+
const signedWidth = selectionResizeHandleMovesLeftEdge(handleId)
|
|
299
|
+
? anchoredX - movingX
|
|
300
|
+
: rawWidth;
|
|
301
|
+
const signedHeight = selectionResizeHandleMovesTopEdge(handleId)
|
|
302
|
+
? anchoredY - movingY
|
|
303
|
+
: rawHeight;
|
|
304
|
+
const scaleX =
|
|
305
|
+
selectionResizeHandleMovesLeftEdge(handleId) ||
|
|
306
|
+
selectionResizeHandleMovesRightEdge(handleId)
|
|
307
|
+
? signedWidth / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.w)
|
|
308
|
+
: 1;
|
|
309
|
+
const scaleY =
|
|
310
|
+
selectionResizeHandleMovesTopEdge(handleId) ||
|
|
311
|
+
selectionResizeHandleMovesBottomEdge(handleId)
|
|
312
|
+
? signedHeight / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.h)
|
|
313
|
+
: 1;
|
|
314
|
+
const width = Math.max(MIN_SELECTION_RESIZE_SIZE, Math.abs(rawWidth));
|
|
315
|
+
const height = Math.max(MIN_SELECTION_RESIZE_SIZE, Math.abs(rawHeight));
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
bounds: new Box(
|
|
319
|
+
Math.min(movingX, anchoredX),
|
|
320
|
+
Math.min(movingY, anchoredY),
|
|
321
|
+
width,
|
|
322
|
+
height,
|
|
323
|
+
),
|
|
324
|
+
scaleX,
|
|
325
|
+
scaleY,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function getCenteredSelectionResizeBounds({
|
|
330
|
+
startBounds,
|
|
331
|
+
handleId,
|
|
332
|
+
pagePoint,
|
|
333
|
+
}: {
|
|
334
|
+
startBounds: Box;
|
|
335
|
+
handleId: SelectionResizeHandleId;
|
|
336
|
+
pagePoint: Vec;
|
|
337
|
+
}): Box {
|
|
338
|
+
return getCenteredSelectionResizeBoundsWithScale({
|
|
339
|
+
startBounds,
|
|
340
|
+
handleId,
|
|
341
|
+
pagePoint,
|
|
342
|
+
}).bounds;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export function getCenteredSelectionResizeBoundsWithScale({
|
|
346
|
+
startBounds,
|
|
347
|
+
handleId,
|
|
348
|
+
pagePoint,
|
|
349
|
+
}: {
|
|
350
|
+
startBounds: Box;
|
|
351
|
+
handleId: SelectionResizeHandleId;
|
|
352
|
+
pagePoint: Vec;
|
|
353
|
+
}): SelectionResizeBoundsResult {
|
|
354
|
+
const center = startBounds.center;
|
|
355
|
+
const minHalfSize = MIN_SELECTION_RESIZE_SIZE / 2;
|
|
356
|
+
const rawHalfWidth = pagePoint.x - center.x;
|
|
357
|
+
const rawHalfHeight = pagePoint.y - center.y;
|
|
358
|
+
const halfWidth = Math.max(Math.abs(rawHalfWidth), minHalfSize);
|
|
359
|
+
const halfHeight = Math.max(Math.abs(rawHalfHeight), minHalfSize);
|
|
360
|
+
const scaleX =
|
|
361
|
+
selectionResizeHandleMovesLeftEdge(handleId) ||
|
|
362
|
+
selectionResizeHandleMovesRightEdge(handleId)
|
|
363
|
+
? (rawHalfWidth *
|
|
364
|
+
(selectionResizeHandleMovesLeftEdge(handleId) ? -2 : 2)) /
|
|
365
|
+
Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.w)
|
|
366
|
+
: 1;
|
|
367
|
+
const scaleY =
|
|
368
|
+
selectionResizeHandleMovesTopEdge(handleId) ||
|
|
369
|
+
selectionResizeHandleMovesBottomEdge(handleId)
|
|
370
|
+
? (rawHalfHeight *
|
|
371
|
+
(selectionResizeHandleMovesTopEdge(handleId) ? -2 : 2)) /
|
|
372
|
+
Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.h)
|
|
373
|
+
: 1;
|
|
374
|
+
|
|
375
|
+
switch (handleId) {
|
|
376
|
+
case "top":
|
|
377
|
+
case "bottom":
|
|
378
|
+
return {
|
|
379
|
+
bounds: new Box(
|
|
380
|
+
startBounds.minX,
|
|
381
|
+
center.y - halfHeight,
|
|
382
|
+
startBounds.w,
|
|
383
|
+
halfHeight * 2,
|
|
384
|
+
),
|
|
385
|
+
scaleX,
|
|
386
|
+
scaleY,
|
|
387
|
+
};
|
|
388
|
+
case "left":
|
|
389
|
+
case "right":
|
|
390
|
+
return {
|
|
391
|
+
bounds: new Box(
|
|
392
|
+
center.x - halfWidth,
|
|
393
|
+
startBounds.minY,
|
|
394
|
+
halfWidth * 2,
|
|
395
|
+
startBounds.h,
|
|
396
|
+
),
|
|
397
|
+
scaleX,
|
|
398
|
+
scaleY,
|
|
399
|
+
};
|
|
400
|
+
default:
|
|
401
|
+
return {
|
|
402
|
+
bounds: new Box(
|
|
403
|
+
center.x - halfWidth,
|
|
404
|
+
center.y - halfHeight,
|
|
405
|
+
halfWidth * 2,
|
|
406
|
+
halfHeight * 2,
|
|
407
|
+
),
|
|
408
|
+
scaleX,
|
|
409
|
+
scaleY,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export function getAspectRatioLockedSelectionResizeBounds({
|
|
415
|
+
bounds,
|
|
416
|
+
startBounds,
|
|
417
|
+
handleId,
|
|
418
|
+
aspectRatio,
|
|
419
|
+
isResizingFromCenter,
|
|
420
|
+
}: {
|
|
421
|
+
bounds: Box;
|
|
422
|
+
startBounds: Box;
|
|
423
|
+
handleId: SelectionResizeHandleId;
|
|
424
|
+
aspectRatio: number;
|
|
425
|
+
isResizingFromCenter: boolean;
|
|
426
|
+
}): Box {
|
|
427
|
+
return getAspectRatioLockedSelectionResizeBoundsWithScale({
|
|
428
|
+
bounds,
|
|
429
|
+
startBounds,
|
|
430
|
+
handleId,
|
|
431
|
+
aspectRatio,
|
|
432
|
+
isResizingFromCenter,
|
|
433
|
+
}).bounds;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export function getAspectRatioLockedSelectionResizeBoundsWithScale({
|
|
437
|
+
bounds,
|
|
438
|
+
startBounds,
|
|
439
|
+
handleId,
|
|
440
|
+
aspectRatio,
|
|
441
|
+
isResizingFromCenter,
|
|
442
|
+
scaleX,
|
|
443
|
+
scaleY,
|
|
444
|
+
}: {
|
|
445
|
+
bounds: Box;
|
|
446
|
+
startBounds: Box;
|
|
447
|
+
handleId: SelectionResizeHandleId;
|
|
448
|
+
aspectRatio: number;
|
|
449
|
+
isResizingFromCenter: boolean;
|
|
450
|
+
scaleX?: number;
|
|
451
|
+
scaleY?: number;
|
|
452
|
+
}): SelectionResizeBoundsResult {
|
|
453
|
+
if (aspectRatio <= 0) {
|
|
454
|
+
return {
|
|
455
|
+
bounds,
|
|
456
|
+
scaleX: scaleX ?? bounds.w / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.w),
|
|
457
|
+
scaleY: scaleY ?? bounds.h / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.h),
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
let width = bounds.w;
|
|
462
|
+
let height = bounds.h;
|
|
463
|
+
const scaleXSign = Math.sign(scaleX ?? 1) || 1;
|
|
464
|
+
const scaleYSign = Math.sign(scaleY ?? 1) || 1;
|
|
465
|
+
switch (handleId) {
|
|
466
|
+
case "left":
|
|
467
|
+
case "right":
|
|
468
|
+
height = width / aspectRatio;
|
|
469
|
+
break;
|
|
470
|
+
case "top":
|
|
471
|
+
case "bottom":
|
|
472
|
+
width = height * aspectRatio;
|
|
473
|
+
break;
|
|
474
|
+
default: {
|
|
475
|
+
const widthScale = width / Math.max(1, startBounds.w);
|
|
476
|
+
const heightScale = height / Math.max(1, startBounds.h);
|
|
477
|
+
|
|
478
|
+
if (Math.abs(widthScale) > Math.abs(heightScale)) {
|
|
479
|
+
height = width / aspectRatio;
|
|
480
|
+
} else {
|
|
481
|
+
width = height * aspectRatio;
|
|
482
|
+
}
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (isResizingFromCenter) {
|
|
488
|
+
const center = startBounds.center;
|
|
489
|
+
return {
|
|
490
|
+
bounds: new Box(center.x - width / 2, center.y - height / 2, width, height),
|
|
491
|
+
scaleX: scaleXSign * (width / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.w)),
|
|
492
|
+
scaleY: scaleYSign * (height / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.h)),
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
let nextBounds: Box;
|
|
497
|
+
switch (handleId) {
|
|
498
|
+
case "top_left":
|
|
499
|
+
nextBounds = new Box(
|
|
500
|
+
scaleXSign < 0 ? bounds.minX : bounds.maxX - width,
|
|
501
|
+
scaleYSign < 0 ? bounds.minY : bounds.maxY - height,
|
|
502
|
+
width,
|
|
503
|
+
height,
|
|
504
|
+
);
|
|
505
|
+
break;
|
|
506
|
+
case "top_right":
|
|
507
|
+
nextBounds = new Box(
|
|
508
|
+
scaleXSign < 0 ? bounds.maxX - width : bounds.minX,
|
|
509
|
+
scaleYSign < 0 ? bounds.minY : bounds.maxY - height,
|
|
510
|
+
width,
|
|
511
|
+
height,
|
|
512
|
+
);
|
|
513
|
+
break;
|
|
514
|
+
case "bottom_right":
|
|
515
|
+
nextBounds = new Box(
|
|
516
|
+
scaleXSign < 0 ? bounds.maxX - width : bounds.minX,
|
|
517
|
+
scaleYSign < 0 ? bounds.maxY - height : bounds.minY,
|
|
518
|
+
width,
|
|
519
|
+
height,
|
|
520
|
+
);
|
|
521
|
+
break;
|
|
522
|
+
case "bottom_left":
|
|
523
|
+
nextBounds = new Box(
|
|
524
|
+
scaleXSign < 0 ? bounds.minX : bounds.maxX - width,
|
|
525
|
+
scaleYSign < 0 ? bounds.maxY - height : bounds.minY,
|
|
526
|
+
width,
|
|
527
|
+
height,
|
|
528
|
+
);
|
|
529
|
+
break;
|
|
530
|
+
case "top":
|
|
531
|
+
nextBounds = new Box(
|
|
532
|
+
startBounds.center.x - width / 2,
|
|
533
|
+
scaleYSign < 0 ? startBounds.maxY : startBounds.maxY - height,
|
|
534
|
+
width,
|
|
535
|
+
height,
|
|
536
|
+
);
|
|
537
|
+
break;
|
|
538
|
+
case "right":
|
|
539
|
+
nextBounds = new Box(
|
|
540
|
+
scaleXSign < 0 ? startBounds.minX - width : startBounds.minX,
|
|
541
|
+
startBounds.center.y - height / 2,
|
|
542
|
+
width,
|
|
543
|
+
height,
|
|
544
|
+
);
|
|
545
|
+
break;
|
|
546
|
+
case "bottom":
|
|
547
|
+
nextBounds = new Box(
|
|
548
|
+
startBounds.center.x - width / 2,
|
|
549
|
+
scaleYSign < 0 ? startBounds.minY - height : startBounds.minY,
|
|
550
|
+
width,
|
|
551
|
+
height,
|
|
552
|
+
);
|
|
553
|
+
break;
|
|
554
|
+
case "left":
|
|
555
|
+
nextBounds = new Box(
|
|
556
|
+
scaleXSign < 0 ? startBounds.maxX : startBounds.maxX - width,
|
|
557
|
+
startBounds.center.y - height / 2,
|
|
558
|
+
width,
|
|
559
|
+
height,
|
|
560
|
+
);
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return {
|
|
565
|
+
bounds: nextBounds,
|
|
566
|
+
scaleX: scaleXSign * (width / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.w)),
|
|
567
|
+
scaleY: scaleYSign * (height / Math.max(MIN_SELECTION_RESIZE_SIZE, startBounds.h)),
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export function getConstrainedSelectionResizeBounds({
|
|
572
|
+
startBounds,
|
|
573
|
+
handleId,
|
|
574
|
+
pagePoint,
|
|
575
|
+
isAspectRatioLocked,
|
|
576
|
+
isResizingFromCenter,
|
|
577
|
+
aspectRatio,
|
|
578
|
+
}: {
|
|
579
|
+
startBounds: Box;
|
|
580
|
+
handleId: SelectionResizeHandleId;
|
|
581
|
+
pagePoint: Vec;
|
|
582
|
+
isAspectRatioLocked: boolean;
|
|
583
|
+
isResizingFromCenter: boolean;
|
|
584
|
+
aspectRatio: number;
|
|
585
|
+
}): Box {
|
|
586
|
+
return getConstrainedSelectionResizeBoundsWithScale({
|
|
587
|
+
startBounds,
|
|
588
|
+
handleId,
|
|
589
|
+
pagePoint,
|
|
590
|
+
isAspectRatioLocked,
|
|
591
|
+
isResizingFromCenter,
|
|
592
|
+
aspectRatio,
|
|
593
|
+
}).bounds;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export function getConstrainedSelectionResizeBoundsWithScale({
|
|
597
|
+
startBounds,
|
|
598
|
+
handleId,
|
|
599
|
+
pagePoint,
|
|
600
|
+
isAspectRatioLocked,
|
|
601
|
+
isResizingFromCenter,
|
|
602
|
+
aspectRatio,
|
|
603
|
+
}: {
|
|
604
|
+
startBounds: Box;
|
|
605
|
+
handleId: SelectionResizeHandleId;
|
|
606
|
+
pagePoint: Vec;
|
|
607
|
+
isAspectRatioLocked: boolean;
|
|
608
|
+
isResizingFromCenter: boolean;
|
|
609
|
+
aspectRatio: number;
|
|
610
|
+
}): SelectionResizeBoundsResult {
|
|
611
|
+
const result = isResizingFromCenter
|
|
612
|
+
? getCenteredSelectionResizeBoundsWithScale({
|
|
613
|
+
startBounds,
|
|
614
|
+
handleId,
|
|
615
|
+
pagePoint,
|
|
616
|
+
})
|
|
617
|
+
: getSelectionResizeBoundsWithScale({ startBounds, handleId, pagePoint });
|
|
618
|
+
if (!isAspectRatioLocked) {
|
|
619
|
+
return result;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
return getAspectRatioLockedSelectionResizeBoundsWithScale({
|
|
623
|
+
bounds: result.bounds,
|
|
624
|
+
startBounds,
|
|
625
|
+
handleId,
|
|
626
|
+
aspectRatio,
|
|
627
|
+
isResizingFromCenter,
|
|
628
|
+
scaleX: result.scaleX,
|
|
629
|
+
scaleY: result.scaleY,
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export function normalizeSelectionResizeBoundsFromEdges({
|
|
634
|
+
minX,
|
|
635
|
+
minY,
|
|
636
|
+
maxX,
|
|
637
|
+
maxY,
|
|
638
|
+
}: {
|
|
639
|
+
minX: number;
|
|
640
|
+
minY: number;
|
|
641
|
+
maxX: number;
|
|
642
|
+
maxY: number;
|
|
643
|
+
}): Box {
|
|
644
|
+
const nextMinX = Math.min(minX, maxX);
|
|
645
|
+
const nextMinY = Math.min(minY, maxY);
|
|
646
|
+
const nextMaxX = Math.max(minX, maxX);
|
|
647
|
+
const nextMaxY = Math.max(minY, maxY);
|
|
648
|
+
return new Box(
|
|
649
|
+
nextMinX,
|
|
650
|
+
nextMinY,
|
|
651
|
+
Math.max(1, nextMaxX - nextMinX),
|
|
652
|
+
Math.max(1, nextMaxY - nextMinY),
|
|
653
|
+
);
|
|
654
|
+
}
|