@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,489 @@
|
|
|
1
|
+
import { Box } from "../geometry/Box";
|
|
2
|
+
import { Vec } from "../geometry/Vec";
|
|
3
|
+
import type { ConnectionTerminal } from "../bindings/arrow/arrowBindingHelpers";
|
|
4
|
+
import type { ShapeId, ShapeRecord } from "../schema/records";
|
|
5
|
+
|
|
6
|
+
export type SelectionResizeHandleId =
|
|
7
|
+
| "top_left"
|
|
8
|
+
| "top"
|
|
9
|
+
| "top_right"
|
|
10
|
+
| "right"
|
|
11
|
+
| "bottom_right"
|
|
12
|
+
| "bottom"
|
|
13
|
+
| "bottom_left"
|
|
14
|
+
| "left";
|
|
15
|
+
|
|
16
|
+
export type SelectionRotateHandleId =
|
|
17
|
+
| "top_left_rotate"
|
|
18
|
+
| "top_right_rotate"
|
|
19
|
+
| "bottom_right_rotate"
|
|
20
|
+
| "bottom_left_rotate";
|
|
21
|
+
|
|
22
|
+
export interface SelectionResizeHandle {
|
|
23
|
+
kind: "resize";
|
|
24
|
+
id: SelectionResizeHandleId;
|
|
25
|
+
point: Vec;
|
|
26
|
+
bounds: Box;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface SelectionRotateHandle {
|
|
30
|
+
kind: "rotate";
|
|
31
|
+
id: SelectionRotateHandleId;
|
|
32
|
+
point: Vec;
|
|
33
|
+
bounds: Box;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SelectionArrowTerminalHandle {
|
|
37
|
+
kind: "arrow_terminal";
|
|
38
|
+
terminal: ConnectionTerminal;
|
|
39
|
+
point: Vec;
|
|
40
|
+
bounds: Box;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SelectionArrowMiddleHandle {
|
|
44
|
+
kind: "arrow_middle";
|
|
45
|
+
point: Vec;
|
|
46
|
+
bounds: Box;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface SelectionCustomHandle {
|
|
50
|
+
kind: "custom";
|
|
51
|
+
type: string;
|
|
52
|
+
id: string;
|
|
53
|
+
point: Vec;
|
|
54
|
+
bounds: Box;
|
|
55
|
+
cursor?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface SelectionResizeHandleAnchor {
|
|
59
|
+
kind: "resize";
|
|
60
|
+
id: SelectionResizeHandleId;
|
|
61
|
+
point: Vec;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface SelectionRotateHandleAnchor {
|
|
65
|
+
kind: "rotate";
|
|
66
|
+
id: SelectionRotateHandleId;
|
|
67
|
+
point: Vec;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface SelectionArrowTerminalHandleAnchor {
|
|
71
|
+
kind: "arrow_terminal";
|
|
72
|
+
terminal: ConnectionTerminal;
|
|
73
|
+
point: Vec;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface SelectionArrowMiddleHandleAnchor {
|
|
77
|
+
kind: "arrow_middle";
|
|
78
|
+
point: Vec;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface SelectionCustomHandleAnchor {
|
|
82
|
+
kind: "custom";
|
|
83
|
+
type: string;
|
|
84
|
+
id: string;
|
|
85
|
+
point: Vec;
|
|
86
|
+
cursor?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface SelectionRotationTransform {
|
|
90
|
+
rotation: number;
|
|
91
|
+
rotationCenter: Vec;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface SelectionFrame extends SelectionRotationTransform {
|
|
95
|
+
bounds: Box;
|
|
96
|
+
hasCompatibleRotation: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface SelectionResizeShapeSnapshot {
|
|
100
|
+
shape: ShapeRecord;
|
|
101
|
+
localBounds: Box;
|
|
102
|
+
rotation: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface SelectionResizePointShapeSnapshot {
|
|
106
|
+
shape: ShapeRecord;
|
|
107
|
+
startLocalPagePoint: Vec;
|
|
108
|
+
endLocalPagePoint: Vec;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface SelectionRotateShapeSnapshot {
|
|
112
|
+
id: ShapeId;
|
|
113
|
+
x: number;
|
|
114
|
+
y: number;
|
|
115
|
+
localBounds: Box;
|
|
116
|
+
rotation: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface SelectionRotatePointShapeSnapshot {
|
|
120
|
+
shape: ShapeRecord;
|
|
121
|
+
startPagePoint: Vec;
|
|
122
|
+
endPagePoint: Vec;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface SelectionResizeSnapshot extends SelectionRotationTransform {
|
|
126
|
+
startBounds: Box;
|
|
127
|
+
aspectRatio: number;
|
|
128
|
+
shapes: SelectionResizeShapeSnapshot[];
|
|
129
|
+
pointShapes: SelectionResizePointShapeSnapshot[];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface SelectionRotateSnapshot {
|
|
133
|
+
center: Vec;
|
|
134
|
+
initialSelectionRotation: number;
|
|
135
|
+
shapes: SelectionRotateShapeSnapshot[];
|
|
136
|
+
pointShapes: SelectionRotatePointShapeSnapshot[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type SelectionMirrorAxis = "horizontal" | "vertical";
|
|
140
|
+
|
|
141
|
+
export type SelectionHandle =
|
|
142
|
+
| SelectionResizeHandle
|
|
143
|
+
| SelectionRotateHandle
|
|
144
|
+
| SelectionArrowTerminalHandle
|
|
145
|
+
| SelectionArrowMiddleHandle
|
|
146
|
+
| SelectionCustomHandle;
|
|
147
|
+
|
|
148
|
+
export interface ArrowBindingPreviewState {
|
|
149
|
+
terminal: ConnectionTerminal;
|
|
150
|
+
targetShapeId: ShapeId;
|
|
151
|
+
resolvedPagePoint: Vec;
|
|
152
|
+
rawPagePoint: Vec;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface PointSnapIndicatorState {
|
|
156
|
+
id: string;
|
|
157
|
+
type: "points";
|
|
158
|
+
axis: "x" | "y";
|
|
159
|
+
line: [Vec, Vec];
|
|
160
|
+
points: Vec[];
|
|
161
|
+
rotation: number;
|
|
162
|
+
rotationCenter: Vec;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface GapSnapIndicatorGapState {
|
|
166
|
+
startEdge: [Vec, Vec];
|
|
167
|
+
endEdge: [Vec, Vec];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface GapSnapIndicatorState {
|
|
171
|
+
id: string;
|
|
172
|
+
type: "gaps";
|
|
173
|
+
direction: "horizontal" | "vertical";
|
|
174
|
+
gaps: GapSnapIndicatorGapState[];
|
|
175
|
+
rotation: number;
|
|
176
|
+
rotationCenter: Vec;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type SnapIndicatorState =
|
|
180
|
+
| PointSnapIndicatorState
|
|
181
|
+
| GapSnapIndicatorState;
|
|
182
|
+
|
|
183
|
+
export interface SelectionOverlayState {
|
|
184
|
+
bounds: Box;
|
|
185
|
+
rotation: number;
|
|
186
|
+
rotationCenter: Vec;
|
|
187
|
+
resizeHandles: SelectionResizeHandle[];
|
|
188
|
+
rotateHandles: SelectionRotateHandle[];
|
|
189
|
+
terminalHandles: SelectionArrowTerminalHandle[];
|
|
190
|
+
middleHandles: SelectionArrowMiddleHandle[];
|
|
191
|
+
customHandles: SelectionCustomHandle[];
|
|
192
|
+
strokeWidth: number;
|
|
193
|
+
cornerRadius: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface SelectionOverlayFrameState {
|
|
197
|
+
bounds: Box;
|
|
198
|
+
rotation: number;
|
|
199
|
+
rotationCenter: Vec;
|
|
200
|
+
strokeWidth: number;
|
|
201
|
+
cornerRadius: number;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface SelectionOverlayFrameGeometryState {
|
|
205
|
+
bounds: Box;
|
|
206
|
+
rotation: number;
|
|
207
|
+
rotationCenter: Vec;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface SelectionOverlayFrameStyleState {
|
|
211
|
+
strokeWidth: number;
|
|
212
|
+
cornerRadius: number;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface SelectionOverlayHandlesState {
|
|
216
|
+
resizeHandles: SelectionResizeHandle[];
|
|
217
|
+
rotateHandles: SelectionRotateHandle[];
|
|
218
|
+
terminalHandles: SelectionArrowTerminalHandle[];
|
|
219
|
+
middleHandles: SelectionArrowMiddleHandle[];
|
|
220
|
+
customHandles: SelectionCustomHandle[];
|
|
221
|
+
strokeWidth: number;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export interface SelectionOverlayHandleAnchorsState {
|
|
225
|
+
resizeHandleAnchors: SelectionResizeHandleAnchor[];
|
|
226
|
+
rotateHandleAnchors: SelectionRotateHandleAnchor[];
|
|
227
|
+
terminalHandleAnchors: SelectionArrowTerminalHandleAnchor[];
|
|
228
|
+
middleHandleAnchors: SelectionArrowMiddleHandleAnchor[];
|
|
229
|
+
customHandleAnchors: SelectionCustomHandleAnchor[];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface SelectionOverlayHandleCountsState {
|
|
233
|
+
resizeHandleCount: number;
|
|
234
|
+
rotateHandleCount: number;
|
|
235
|
+
terminalHandleCount: number;
|
|
236
|
+
middleHandleCount: number;
|
|
237
|
+
customHandleCount: number;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function selectionPagePointToLocalPoint(
|
|
241
|
+
point: Vec,
|
|
242
|
+
transform: SelectionRotationTransform,
|
|
243
|
+
): Vec {
|
|
244
|
+
return transform.rotation === 0
|
|
245
|
+
? point.clone()
|
|
246
|
+
: Vec.RotWith(point, transform.rotationCenter, -transform.rotation);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function selectionLocalPointToPagePoint(
|
|
250
|
+
point: Vec,
|
|
251
|
+
transform: SelectionRotationTransform,
|
|
252
|
+
): Vec {
|
|
253
|
+
return transform.rotation === 0
|
|
254
|
+
? point.clone()
|
|
255
|
+
: Vec.RotWith(point, transform.rotationCenter, transform.rotation);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function rotateSelectionPagePoint(
|
|
259
|
+
point: Vec,
|
|
260
|
+
transform: SelectionRotationTransform,
|
|
261
|
+
): Vec {
|
|
262
|
+
return selectionLocalPointToPagePoint(point, transform);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function mapRange(
|
|
266
|
+
value: number,
|
|
267
|
+
startMin: number,
|
|
268
|
+
startSize: number,
|
|
269
|
+
nextMin: number,
|
|
270
|
+
nextSize: number,
|
|
271
|
+
): number {
|
|
272
|
+
if (startSize === 0) {
|
|
273
|
+
return nextMin;
|
|
274
|
+
}
|
|
275
|
+
return nextMin + ((value - startMin) / startSize) * nextSize;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function mapSelectionLocalPointBetweenBounds({
|
|
279
|
+
point,
|
|
280
|
+
fromBounds,
|
|
281
|
+
toBounds,
|
|
282
|
+
}: {
|
|
283
|
+
point: Vec;
|
|
284
|
+
fromBounds: Box;
|
|
285
|
+
toBounds: Box;
|
|
286
|
+
}): Vec {
|
|
287
|
+
return new Vec(
|
|
288
|
+
mapRange(
|
|
289
|
+
point.x,
|
|
290
|
+
fromBounds.minX,
|
|
291
|
+
fromBounds.w,
|
|
292
|
+
toBounds.minX,
|
|
293
|
+
toBounds.w,
|
|
294
|
+
),
|
|
295
|
+
mapRange(
|
|
296
|
+
point.y,
|
|
297
|
+
fromBounds.minY,
|
|
298
|
+
fromBounds.h,
|
|
299
|
+
toBounds.minY,
|
|
300
|
+
toBounds.h,
|
|
301
|
+
),
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function mapSelectionLocalBoundsBetweenBounds({
|
|
306
|
+
bounds,
|
|
307
|
+
fromBounds,
|
|
308
|
+
toBounds,
|
|
309
|
+
}: {
|
|
310
|
+
bounds: Box;
|
|
311
|
+
fromBounds: Box;
|
|
312
|
+
toBounds: Box;
|
|
313
|
+
}): Box {
|
|
314
|
+
const nextMin = mapSelectionLocalPointBetweenBounds({
|
|
315
|
+
point: new Vec(bounds.minX, bounds.minY),
|
|
316
|
+
fromBounds,
|
|
317
|
+
toBounds,
|
|
318
|
+
});
|
|
319
|
+
const nextMax = mapSelectionLocalPointBetweenBounds({
|
|
320
|
+
point: new Vec(bounds.maxX, bounds.maxY),
|
|
321
|
+
fromBounds,
|
|
322
|
+
toBounds,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
return new Box(
|
|
326
|
+
Math.min(nextMin.x, nextMax.x),
|
|
327
|
+
Math.min(nextMin.y, nextMax.y),
|
|
328
|
+
Math.abs(nextMax.x - nextMin.x),
|
|
329
|
+
Math.abs(nextMax.y - nextMin.y),
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function mirrorSelectionLocalPoint({
|
|
334
|
+
axis,
|
|
335
|
+
bounds,
|
|
336
|
+
point,
|
|
337
|
+
}: {
|
|
338
|
+
axis: SelectionMirrorAxis;
|
|
339
|
+
bounds: Box;
|
|
340
|
+
point: Vec;
|
|
341
|
+
}): Vec {
|
|
342
|
+
return axis === "horizontal"
|
|
343
|
+
? new Vec(bounds.minX + bounds.maxX - point.x, point.y)
|
|
344
|
+
: new Vec(point.x, bounds.minY + bounds.maxY - point.y);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function flipSelectionLocalBounds({
|
|
348
|
+
axis,
|
|
349
|
+
bounds,
|
|
350
|
+
selectionBounds,
|
|
351
|
+
}: {
|
|
352
|
+
axis: SelectionMirrorAxis;
|
|
353
|
+
bounds: Box;
|
|
354
|
+
selectionBounds: Box;
|
|
355
|
+
}): Box {
|
|
356
|
+
return axis === "horizontal"
|
|
357
|
+
? new Box(
|
|
358
|
+
selectionBounds.minX + selectionBounds.maxX - bounds.maxX,
|
|
359
|
+
bounds.minY,
|
|
360
|
+
bounds.w,
|
|
361
|
+
bounds.h,
|
|
362
|
+
)
|
|
363
|
+
: new Box(
|
|
364
|
+
bounds.minX,
|
|
365
|
+
selectionBounds.minY + selectionBounds.maxY - bounds.maxY,
|
|
366
|
+
bounds.w,
|
|
367
|
+
bounds.h,
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function getSelectionLocalBoundsFromPagePoints({
|
|
372
|
+
points,
|
|
373
|
+
transform,
|
|
374
|
+
}: {
|
|
375
|
+
points: readonly Vec[];
|
|
376
|
+
transform: SelectionRotationTransform;
|
|
377
|
+
}): Box | null {
|
|
378
|
+
if (points.length === 0) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
return Box.FromPoints(
|
|
382
|
+
points.map((point) => selectionPagePointToLocalPoint(point, transform)),
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export function getSelectionResizeSnapshot({
|
|
387
|
+
shapes,
|
|
388
|
+
selectionFrame,
|
|
389
|
+
getShapeSelectionResizePageOutlineVertices,
|
|
390
|
+
getShapeSelectionPagePoints,
|
|
391
|
+
}: {
|
|
392
|
+
shapes: ShapeRecord[];
|
|
393
|
+
selectionFrame: SelectionFrame;
|
|
394
|
+
getShapeSelectionResizePageOutlineVertices: (shape: ShapeRecord) => Vec[];
|
|
395
|
+
getShapeSelectionPagePoints: (
|
|
396
|
+
shape: ShapeRecord,
|
|
397
|
+
) => readonly [Vec, Vec] | null;
|
|
398
|
+
}): SelectionResizeSnapshot {
|
|
399
|
+
const transform: SelectionRotationTransform = {
|
|
400
|
+
rotation: selectionFrame.rotation,
|
|
401
|
+
rotationCenter: selectionFrame.rotationCenter,
|
|
402
|
+
};
|
|
403
|
+
const boundsShapes: SelectionResizeShapeSnapshot[] = [];
|
|
404
|
+
const pointShapes: SelectionResizePointShapeSnapshot[] = [];
|
|
405
|
+
|
|
406
|
+
for (const shape of shapes) {
|
|
407
|
+
const pagePoints = getShapeSelectionPagePoints(shape);
|
|
408
|
+
if (pagePoints) {
|
|
409
|
+
pointShapes.push({
|
|
410
|
+
shape,
|
|
411
|
+
startLocalPagePoint: selectionPagePointToLocalPoint(
|
|
412
|
+
pagePoints[0],
|
|
413
|
+
transform,
|
|
414
|
+
),
|
|
415
|
+
endLocalPagePoint: selectionPagePointToLocalPoint(
|
|
416
|
+
pagePoints[1],
|
|
417
|
+
transform,
|
|
418
|
+
),
|
|
419
|
+
});
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
boundsShapes.push({
|
|
424
|
+
shape,
|
|
425
|
+
localBounds: Box.FromPoints(
|
|
426
|
+
getShapeSelectionResizePageOutlineVertices(shape).map((point) =>
|
|
427
|
+
selectionPagePointToLocalPoint(point, transform),
|
|
428
|
+
),
|
|
429
|
+
),
|
|
430
|
+
rotation: shape.rotation,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return {
|
|
435
|
+
startBounds: selectionFrame.bounds.clone(),
|
|
436
|
+
rotation: selectionFrame.rotation,
|
|
437
|
+
rotationCenter: selectionFrame.rotationCenter.clone(),
|
|
438
|
+
aspectRatio:
|
|
439
|
+
selectionFrame.bounds.h === 0
|
|
440
|
+
? 1
|
|
441
|
+
: selectionFrame.bounds.w / selectionFrame.bounds.h,
|
|
442
|
+
shapes: boundsShapes,
|
|
443
|
+
pointShapes,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export function getSelectionRotateSnapshot({
|
|
448
|
+
shapes,
|
|
449
|
+
selectionFrame,
|
|
450
|
+
getShapeLocalBounds,
|
|
451
|
+
getShapeSelectionPagePoints,
|
|
452
|
+
}: {
|
|
453
|
+
shapes: ShapeRecord[];
|
|
454
|
+
selectionFrame: SelectionFrame;
|
|
455
|
+
getShapeLocalBounds: (shape: ShapeRecord) => Box;
|
|
456
|
+
getShapeSelectionPagePoints: (
|
|
457
|
+
shape: ShapeRecord,
|
|
458
|
+
) => readonly [Vec, Vec] | null;
|
|
459
|
+
}): SelectionRotateSnapshot {
|
|
460
|
+
const boundsShapes: SelectionRotateShapeSnapshot[] = [];
|
|
461
|
+
const pointShapes: SelectionRotatePointShapeSnapshot[] = [];
|
|
462
|
+
|
|
463
|
+
for (const shape of shapes) {
|
|
464
|
+
const pagePoints = getShapeSelectionPagePoints(shape);
|
|
465
|
+
if (pagePoints) {
|
|
466
|
+
pointShapes.push({
|
|
467
|
+
shape,
|
|
468
|
+
startPagePoint: pagePoints[0],
|
|
469
|
+
endPagePoint: pagePoints[1],
|
|
470
|
+
});
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
boundsShapes.push({
|
|
475
|
+
id: shape.id,
|
|
476
|
+
x: shape.x,
|
|
477
|
+
y: shape.y,
|
|
478
|
+
localBounds: getShapeLocalBounds(shape),
|
|
479
|
+
rotation: shape.rotation,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return {
|
|
484
|
+
center: selectionFrame.rotationCenter.clone(),
|
|
485
|
+
initialSelectionRotation: selectionFrame.rotation,
|
|
486
|
+
shapes: boundsShapes,
|
|
487
|
+
pointShapes,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Editor } from "./Editor";
|
|
2
|
+
import type { InteractionHandlerRegistry } from "./interactions";
|
|
3
|
+
import type {
|
|
4
|
+
SelectionHandleInteractionHandler,
|
|
5
|
+
SelectionHandleInteractionInput,
|
|
6
|
+
SelectionHandleInteractionSession,
|
|
7
|
+
} from "./interactions";
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
SelectionHandleInteractionHandler,
|
|
11
|
+
SelectionHandleInteractionInput,
|
|
12
|
+
SelectionHandleInteractionSession,
|
|
13
|
+
} from "./interactions";
|
|
14
|
+
|
|
15
|
+
export class SelectionHandleInteractionRegistry {
|
|
16
|
+
private readonly handlers: SelectionHandleInteractionHandler[] = [];
|
|
17
|
+
|
|
18
|
+
constructor(private readonly interactions?: InteractionHandlerRegistry) {}
|
|
19
|
+
|
|
20
|
+
register(handler: SelectionHandleInteractionHandler): void {
|
|
21
|
+
this.handlers.push(handler);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
createSession(
|
|
25
|
+
editor: Editor,
|
|
26
|
+
input: SelectionHandleInteractionInput,
|
|
27
|
+
): SelectionHandleInteractionSession | null {
|
|
28
|
+
const interactionSession =
|
|
29
|
+
this.interactions?.createSelectionHandleSession(editor, input) ?? null;
|
|
30
|
+
if (interactionSession) {
|
|
31
|
+
return interactionSession;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const handler of this.handlers) {
|
|
35
|
+
const session = handler.createSession(editor, input);
|
|
36
|
+
if (session) {
|
|
37
|
+
return session;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|