@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,160 @@
|
|
|
1
|
+
import type { ChangeSource } from "@land/store";
|
|
2
|
+
import type {
|
|
3
|
+
PageId,
|
|
4
|
+
ShapeId,
|
|
5
|
+
ShapeParentId,
|
|
6
|
+
ShapeRecord,
|
|
7
|
+
} from "../../schema/records";
|
|
8
|
+
import type {
|
|
9
|
+
Editor,
|
|
10
|
+
ReparentShapePlacementInput,
|
|
11
|
+
ReparentShapePlacementResult,
|
|
12
|
+
} from "../Editor";
|
|
13
|
+
import type { ShapeUpdate } from "../commands";
|
|
14
|
+
|
|
15
|
+
export function canUseShapeParent(
|
|
16
|
+
editor: Editor,
|
|
17
|
+
parentId: ShapeParentId,
|
|
18
|
+
childId?: ShapeId,
|
|
19
|
+
): boolean {
|
|
20
|
+
if (parentId.startsWith("page:")) {
|
|
21
|
+
return !!editor.getPage(parentId as PageId);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const parent = editor.getShape(parentId as ShapeId);
|
|
25
|
+
if (!parent) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (childId) {
|
|
30
|
+
if (parent.id === childId) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (editor.getDescendantShapeIds(childId).includes(parent.id)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return editor.getShapeUtil(parent).canReceiveChildren(parent);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function moveShapesToParentPlacement(
|
|
42
|
+
editor: Editor,
|
|
43
|
+
input: ReparentShapePlacementInput,
|
|
44
|
+
source: ChangeSource = "user",
|
|
45
|
+
): boolean {
|
|
46
|
+
const ids = Array.from(new Set(input.ids));
|
|
47
|
+
if (ids.length === 0) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const shapes = ids
|
|
52
|
+
.map((id) => editor.getShape(id))
|
|
53
|
+
.filter((shape): shape is ShapeRecord => !!shape);
|
|
54
|
+
if (shapes.length !== ids.length) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (
|
|
58
|
+
shapes.some((shape) => shape.isLocked || editor.isShapeHidden(shape.id))
|
|
59
|
+
) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (ids.some((id) => !canUseShapeParent(editor, input.parentId, id))) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return applyParentPlacement(editor, input, ids, shapes, source);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function moveShapesToParentPlacementResult(
|
|
70
|
+
editor: Editor,
|
|
71
|
+
input: ReparentShapePlacementInput,
|
|
72
|
+
source: ChangeSource = "user",
|
|
73
|
+
): ReparentShapePlacementResult {
|
|
74
|
+
const ids = Array.from(new Set(input.ids));
|
|
75
|
+
if (ids.length === 0) {
|
|
76
|
+
return { ok: false, reason: "notFound" };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const shapes = ids
|
|
80
|
+
.map((id) => editor.getShape(id))
|
|
81
|
+
.filter((shape): shape is ShapeRecord => !!shape);
|
|
82
|
+
if (shapes.length !== ids.length) {
|
|
83
|
+
return { ok: false, reason: "notFound" };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (const shape of shapes) {
|
|
87
|
+
if (shape.isLocked) {
|
|
88
|
+
return { ok: false, reason: "locked" };
|
|
89
|
+
}
|
|
90
|
+
if (editor.isShapeHidden(shape.id)) {
|
|
91
|
+
return { ok: false, reason: "hidden" };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const id of ids) {
|
|
96
|
+
const parentId = input.parentId;
|
|
97
|
+
if (!parentId.startsWith("page:")) {
|
|
98
|
+
const parent = editor.getShape(parentId as ShapeId);
|
|
99
|
+
if (!parent) {
|
|
100
|
+
return { ok: false, reason: "invalidParent" };
|
|
101
|
+
}
|
|
102
|
+
if (
|
|
103
|
+
parent.id === id ||
|
|
104
|
+
editor.getDescendantShapeIds(id).includes(parent.id)
|
|
105
|
+
) {
|
|
106
|
+
return { ok: false, reason: "cycle" };
|
|
107
|
+
}
|
|
108
|
+
if (!editor.getShapeUtil(parent).canReceiveChildren(parent)) {
|
|
109
|
+
return { ok: false, reason: "invalidParent" };
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
if (!editor.getPage(parentId as PageId)) {
|
|
113
|
+
return { ok: false, reason: "invalidParent" };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const didMove = applyParentPlacement(editor, input, ids, shapes, source);
|
|
119
|
+
return didMove
|
|
120
|
+
? { ok: true, movedIds: ids }
|
|
121
|
+
: { ok: false, reason: "invalidBeforeId" };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function applyParentPlacement(
|
|
125
|
+
editor: Editor,
|
|
126
|
+
input: ReparentShapePlacementInput,
|
|
127
|
+
ids: readonly ShapeId[],
|
|
128
|
+
shapes: readonly ShapeRecord[],
|
|
129
|
+
source: ChangeSource,
|
|
130
|
+
): boolean {
|
|
131
|
+
const movingIds = new Set(ids);
|
|
132
|
+
const nextSiblings = editor
|
|
133
|
+
.getChildShapes(input.parentId)
|
|
134
|
+
.filter((shape) => !movingIds.has(shape.id));
|
|
135
|
+
|
|
136
|
+
let insertIndex = nextSiblings.length;
|
|
137
|
+
if (input.beforeId) {
|
|
138
|
+
const beforeIndex = nextSiblings.findIndex(
|
|
139
|
+
(shape) => shape.id === input.beforeId,
|
|
140
|
+
);
|
|
141
|
+
if (beforeIndex === -1) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
insertIndex = beforeIndex;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const movingShapes = [...shapes].sort((left, right) =>
|
|
148
|
+
left.index.localeCompare(right.index),
|
|
149
|
+
);
|
|
150
|
+
nextSiblings.splice(insertIndex, 0, ...movingShapes);
|
|
151
|
+
|
|
152
|
+
editor.cancelInteractionForCommand();
|
|
153
|
+
const updates: ShapeUpdate[] = nextSiblings.map((shape, index) => ({
|
|
154
|
+
id: shape.id,
|
|
155
|
+
parentId: input.parentId,
|
|
156
|
+
index: editor.createShapeIndex(index + 1),
|
|
157
|
+
}));
|
|
158
|
+
editor.commands.updateShapes(updates, { source });
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { Box } from "../../geometry/Box";
|
|
2
|
+
import { Vec } from "../../geometry/Vec";
|
|
3
|
+
import type { ShapeId } from "../../schema/records";
|
|
4
|
+
import {
|
|
5
|
+
getAspectRatioLockedSelectionResizeBoundsWithScale,
|
|
6
|
+
getSelectionResizeHandleForScale,
|
|
7
|
+
getSelectionResizeScalesFromBounds,
|
|
8
|
+
normalizeSelectionResizeBoundsFromEdges,
|
|
9
|
+
selectionResizeHandleMovesBottomEdge,
|
|
10
|
+
selectionResizeHandleMovesLeftEdge,
|
|
11
|
+
selectionResizeHandleMovesRightEdge,
|
|
12
|
+
selectionResizeHandleMovesTopEdge,
|
|
13
|
+
} from "../resizeGeometry";
|
|
14
|
+
import type { SelectionResizeHandleId } from "../selection";
|
|
15
|
+
import {
|
|
16
|
+
EPSILON,
|
|
17
|
+
getAxisMax,
|
|
18
|
+
getAxisMin,
|
|
19
|
+
getAxisSize,
|
|
20
|
+
getAxisValue,
|
|
21
|
+
getBreadthRange,
|
|
22
|
+
getRangeIntersection,
|
|
23
|
+
rangesOverlap,
|
|
24
|
+
translateBoundsOnAxis,
|
|
25
|
+
} from "./snapGeometry";
|
|
26
|
+
import type {
|
|
27
|
+
ResizeSnapInput,
|
|
28
|
+
SnapAxis,
|
|
29
|
+
SnapNode,
|
|
30
|
+
SnapPoint,
|
|
31
|
+
} from "./snapTypes";
|
|
32
|
+
|
|
33
|
+
export interface PointSnapPair {
|
|
34
|
+
selectionPoint: Vec;
|
|
35
|
+
candidatePoint: Vec;
|
|
36
|
+
candidateNodeId: ShapeId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PointAxisSnap {
|
|
40
|
+
type: "points";
|
|
41
|
+
nudge: number;
|
|
42
|
+
pairs: PointSnapPair[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface Gap {
|
|
46
|
+
direction: "horizontal" | "vertical";
|
|
47
|
+
startNode: SnapNode;
|
|
48
|
+
endNode: SnapNode;
|
|
49
|
+
length: number;
|
|
50
|
+
breadthIntersection: [number, number];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface GapAxisSnap {
|
|
54
|
+
type: "gaps";
|
|
55
|
+
nudge: number;
|
|
56
|
+
gaps: Gap[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type AxisSnap = PointAxisSnap | GapAxisSnap;
|
|
60
|
+
|
|
61
|
+
export function getPointSnap(
|
|
62
|
+
axis: SnapAxis,
|
|
63
|
+
selectionPoints: Vec[],
|
|
64
|
+
candidatePoints: SnapPoint[],
|
|
65
|
+
threshold: number,
|
|
66
|
+
): PointAxisSnap | null {
|
|
67
|
+
let nearestDistance = threshold + 1;
|
|
68
|
+
let nudge = 0;
|
|
69
|
+
const pairs: PointSnapPair[] = [];
|
|
70
|
+
|
|
71
|
+
for (const selectionPoint of selectionPoints) {
|
|
72
|
+
for (const candidate of candidatePoints) {
|
|
73
|
+
const offset =
|
|
74
|
+
getAxisValue(candidate.point, axis) -
|
|
75
|
+
getAxisValue(selectionPoint, axis);
|
|
76
|
+
const distance = Math.abs(offset);
|
|
77
|
+
if (distance > threshold || distance > nearestDistance + EPSILON) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (distance < nearestDistance - EPSILON) {
|
|
81
|
+
nearestDistance = distance;
|
|
82
|
+
nudge = offset;
|
|
83
|
+
pairs.length = 0;
|
|
84
|
+
} else if (Math.abs(offset - nudge) > EPSILON) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
pairs.push({
|
|
88
|
+
selectionPoint,
|
|
89
|
+
candidatePoint: candidate.point,
|
|
90
|
+
candidateNodeId: candidate.nodeId,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return pairs.length > 0 ? { type: "points", nudge, pairs } : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function getResizeSnapPointsForHandle(
|
|
99
|
+
handleId: SelectionResizeHandleId | "any",
|
|
100
|
+
bounds: Box,
|
|
101
|
+
): Vec[] {
|
|
102
|
+
const points: Vec[] = [];
|
|
103
|
+
|
|
104
|
+
switch (handleId) {
|
|
105
|
+
case "top":
|
|
106
|
+
case "left":
|
|
107
|
+
case "top_left":
|
|
108
|
+
case "any":
|
|
109
|
+
points.push(new Vec(bounds.minX, bounds.minY));
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
switch (handleId) {
|
|
114
|
+
case "top":
|
|
115
|
+
case "right":
|
|
116
|
+
case "top_right":
|
|
117
|
+
case "any":
|
|
118
|
+
points.push(new Vec(bounds.maxX, bounds.minY));
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
switch (handleId) {
|
|
123
|
+
case "bottom":
|
|
124
|
+
case "right":
|
|
125
|
+
case "bottom_right":
|
|
126
|
+
case "any":
|
|
127
|
+
points.push(new Vec(bounds.maxX, bounds.maxY));
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
switch (handleId) {
|
|
132
|
+
case "bottom":
|
|
133
|
+
case "left":
|
|
134
|
+
case "bottom_left":
|
|
135
|
+
case "any":
|
|
136
|
+
points.push(new Vec(bounds.minX, bounds.maxY));
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return points;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function getResizeResultAfterNudge(
|
|
144
|
+
input: ResizeSnapInput,
|
|
145
|
+
nudge: Vec,
|
|
146
|
+
): { bounds: Box; scaleX: number; scaleY: number } {
|
|
147
|
+
const nudgeHandleId = getSelectionResizeHandleForScale({
|
|
148
|
+
handleId: input.handleId,
|
|
149
|
+
scaleX: input.scaleX,
|
|
150
|
+
scaleY: input.scaleY,
|
|
151
|
+
});
|
|
152
|
+
let minX = input.resizedSelectionBounds.minX;
|
|
153
|
+
let maxX = input.resizedSelectionBounds.maxX;
|
|
154
|
+
let minY = input.resizedSelectionBounds.minY;
|
|
155
|
+
let maxY = input.resizedSelectionBounds.maxY;
|
|
156
|
+
|
|
157
|
+
if (input.isResizingFromCenter) {
|
|
158
|
+
if (selectionResizeHandleMovesLeftEdge(nudgeHandleId)) {
|
|
159
|
+
minX += nudge.x;
|
|
160
|
+
maxX -= nudge.x;
|
|
161
|
+
} else if (selectionResizeHandleMovesRightEdge(nudgeHandleId)) {
|
|
162
|
+
minX -= nudge.x;
|
|
163
|
+
maxX += nudge.x;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (selectionResizeHandleMovesTopEdge(nudgeHandleId)) {
|
|
167
|
+
minY += nudge.y;
|
|
168
|
+
maxY -= nudge.y;
|
|
169
|
+
} else if (selectionResizeHandleMovesBottomEdge(nudgeHandleId)) {
|
|
170
|
+
minY -= nudge.y;
|
|
171
|
+
maxY += nudge.y;
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
if (selectionResizeHandleMovesLeftEdge(nudgeHandleId)) {
|
|
175
|
+
minX += nudge.x;
|
|
176
|
+
} else if (selectionResizeHandleMovesRightEdge(nudgeHandleId)) {
|
|
177
|
+
maxX += nudge.x;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (selectionResizeHandleMovesTopEdge(nudgeHandleId)) {
|
|
181
|
+
minY += nudge.y;
|
|
182
|
+
} else if (selectionResizeHandleMovesBottomEdge(nudgeHandleId)) {
|
|
183
|
+
maxY += nudge.y;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const nudgedBounds = normalizeSelectionResizeBoundsFromEdges({
|
|
188
|
+
minX,
|
|
189
|
+
minY,
|
|
190
|
+
maxX,
|
|
191
|
+
maxY,
|
|
192
|
+
});
|
|
193
|
+
if (!input.isAspectRatioLocked) {
|
|
194
|
+
const scales = getSelectionResizeScalesFromBounds({
|
|
195
|
+
startBounds: input.initialSelectionBounds,
|
|
196
|
+
bounds: nudgedBounds,
|
|
197
|
+
handleId: input.handleId,
|
|
198
|
+
scaleX: input.scaleX,
|
|
199
|
+
scaleY: input.scaleY,
|
|
200
|
+
isResizingFromCenter: input.isResizingFromCenter,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
bounds: nudgedBounds,
|
|
205
|
+
scaleX: scales.scaleX,
|
|
206
|
+
scaleY: scales.scaleY,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return getAspectRatioLockedSelectionResizeBoundsWithScale({
|
|
211
|
+
startBounds: input.initialSelectionBounds,
|
|
212
|
+
bounds: nudgedBounds,
|
|
213
|
+
handleId: input.handleId,
|
|
214
|
+
aspectRatio:
|
|
215
|
+
input.initialSelectionBounds.h === 0
|
|
216
|
+
? 1
|
|
217
|
+
: input.initialSelectionBounds.w / input.initialSelectionBounds.h,
|
|
218
|
+
isResizingFromCenter: input.isResizingFromCenter,
|
|
219
|
+
scaleX: input.scaleX,
|
|
220
|
+
scaleY: input.scaleY,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function getResizeBoundsAfterNudge(
|
|
225
|
+
input: ResizeSnapInput,
|
|
226
|
+
nudge: Vec,
|
|
227
|
+
): Box {
|
|
228
|
+
return getResizeResultAfterNudge(input, nudge).bounds;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function collectGaps(nodes: SnapNode[], axis: SnapAxis): Gap[] {
|
|
232
|
+
const direction = axis === "x" ? "horizontal" : "vertical";
|
|
233
|
+
const sorted = [...nodes].sort(
|
|
234
|
+
(left, right) => getAxisMin(left.bounds, axis) - getAxisMin(right.bounds, axis),
|
|
235
|
+
);
|
|
236
|
+
const gaps: Gap[] = [];
|
|
237
|
+
|
|
238
|
+
for (let startIndex = 0; startIndex < sorted.length; startIndex += 1) {
|
|
239
|
+
const startNode = sorted[startIndex];
|
|
240
|
+
if (!startNode) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
for (let endIndex = startIndex + 1; endIndex < sorted.length; endIndex += 1) {
|
|
244
|
+
const endNode = sorted[endIndex];
|
|
245
|
+
if (!endNode) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
const startMax = getAxisMax(startNode.bounds, axis);
|
|
249
|
+
const endMin = getAxisMin(endNode.bounds, axis);
|
|
250
|
+
if (startMax >= endMin) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const breadthIntersection = getRangeIntersection(
|
|
254
|
+
getBreadthRange(startNode.bounds, axis),
|
|
255
|
+
getBreadthRange(endNode.bounds, axis),
|
|
256
|
+
);
|
|
257
|
+
if (!breadthIntersection) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
gaps.push({
|
|
261
|
+
direction,
|
|
262
|
+
startNode,
|
|
263
|
+
endNode,
|
|
264
|
+
length: endMin - startMax,
|
|
265
|
+
breadthIntersection,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return gaps;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function createGap(
|
|
274
|
+
direction: Gap["direction"],
|
|
275
|
+
startNode: SnapNode,
|
|
276
|
+
endNode: SnapNode,
|
|
277
|
+
axis: SnapAxis,
|
|
278
|
+
): Gap | null {
|
|
279
|
+
const breadthIntersection = getRangeIntersection(
|
|
280
|
+
getBreadthRange(startNode.bounds, axis),
|
|
281
|
+
getBreadthRange(endNode.bounds, axis),
|
|
282
|
+
);
|
|
283
|
+
if (!breadthIntersection) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
direction,
|
|
288
|
+
startNode,
|
|
289
|
+
endNode,
|
|
290
|
+
length:
|
|
291
|
+
getAxisMin(endNode.bounds, axis) - getAxisMax(startNode.bounds, axis),
|
|
292
|
+
breadthIntersection,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function getGapSnap(
|
|
297
|
+
axis: SnapAxis,
|
|
298
|
+
selectionBounds: Box,
|
|
299
|
+
visibleGaps: Gap[],
|
|
300
|
+
threshold: number,
|
|
301
|
+
): GapAxisSnap | null {
|
|
302
|
+
const selectionBreadth = getBreadthRange(selectionBounds, axis);
|
|
303
|
+
const selectionSize = getAxisSize(selectionBounds, axis);
|
|
304
|
+
let nearestDistance = threshold + 1;
|
|
305
|
+
let nearest: GapAxisSnap | null = null;
|
|
306
|
+
|
|
307
|
+
const consider = (nudge: number, gaps: Gap[]): void => {
|
|
308
|
+
const distance = Math.abs(nudge);
|
|
309
|
+
if (
|
|
310
|
+
gaps.length === 0 ||
|
|
311
|
+
distance > threshold ||
|
|
312
|
+
distance >= nearestDistance - EPSILON
|
|
313
|
+
) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
nearestDistance = distance;
|
|
317
|
+
nearest = { type: "gaps", nudge, gaps };
|
|
318
|
+
};
|
|
319
|
+
const getSelectionNodeAfterNudge = (nudge: number): SnapNode => ({
|
|
320
|
+
id: "selection",
|
|
321
|
+
bounds: translateBoundsOnAxis(selectionBounds, axis, nudge),
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
for (const gap of visibleGaps) {
|
|
325
|
+
if (
|
|
326
|
+
selectionSize <= gap.length &&
|
|
327
|
+
rangesOverlap(selectionBreadth, gap.breadthIntersection)
|
|
328
|
+
) {
|
|
329
|
+
const targetMin =
|
|
330
|
+
getAxisMax(gap.startNode.bounds, axis) +
|
|
331
|
+
(gap.length - selectionSize) / 2;
|
|
332
|
+
const nudge = targetMin - getAxisMin(selectionBounds, axis);
|
|
333
|
+
const snappedSelectionNode = getSelectionNodeAfterNudge(nudge);
|
|
334
|
+
const before = createGap(
|
|
335
|
+
gap.direction,
|
|
336
|
+
gap.startNode,
|
|
337
|
+
snappedSelectionNode,
|
|
338
|
+
axis,
|
|
339
|
+
);
|
|
340
|
+
const after = createGap(
|
|
341
|
+
gap.direction,
|
|
342
|
+
snappedSelectionNode,
|
|
343
|
+
gap.endNode,
|
|
344
|
+
axis,
|
|
345
|
+
);
|
|
346
|
+
consider(nudge, [before, after].filter((item): item is Gap => item !== null));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const selectionAfterNudge =
|
|
350
|
+
getAxisMax(gap.endNode.bounds, axis) +
|
|
351
|
+
gap.length -
|
|
352
|
+
getAxisMin(selectionBounds, axis);
|
|
353
|
+
const afterSelectionNode = getSelectionNodeAfterNudge(selectionAfterNudge);
|
|
354
|
+
if (
|
|
355
|
+
rangesOverlap(
|
|
356
|
+
getBreadthRange(afterSelectionNode.bounds, axis),
|
|
357
|
+
gap.breadthIntersection,
|
|
358
|
+
)
|
|
359
|
+
) {
|
|
360
|
+
const duplicate = createGap(
|
|
361
|
+
gap.direction,
|
|
362
|
+
gap.endNode,
|
|
363
|
+
afterSelectionNode,
|
|
364
|
+
axis,
|
|
365
|
+
);
|
|
366
|
+
consider(
|
|
367
|
+
selectionAfterNudge,
|
|
368
|
+
duplicate ? [gap, duplicate] : [],
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const selectionBeforeNudge =
|
|
373
|
+
getAxisMin(gap.startNode.bounds, axis) -
|
|
374
|
+
gap.length -
|
|
375
|
+
getAxisMax(selectionBounds, axis);
|
|
376
|
+
const beforeSelectionNode = getSelectionNodeAfterNudge(selectionBeforeNudge);
|
|
377
|
+
if (
|
|
378
|
+
rangesOverlap(
|
|
379
|
+
getBreadthRange(beforeSelectionNode.bounds, axis),
|
|
380
|
+
gap.breadthIntersection,
|
|
381
|
+
)
|
|
382
|
+
) {
|
|
383
|
+
const duplicate = createGap(
|
|
384
|
+
gap.direction,
|
|
385
|
+
beforeSelectionNode,
|
|
386
|
+
gap.startNode,
|
|
387
|
+
axis,
|
|
388
|
+
);
|
|
389
|
+
consider(
|
|
390
|
+
selectionBeforeNudge,
|
|
391
|
+
duplicate ? [duplicate, gap] : [],
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return nearest;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export function chooseAxisSnap(
|
|
400
|
+
pointSnap: PointAxisSnap | null,
|
|
401
|
+
gapSnap: GapAxisSnap | null,
|
|
402
|
+
): AxisSnap | null {
|
|
403
|
+
if (!pointSnap) {
|
|
404
|
+
return gapSnap;
|
|
405
|
+
}
|
|
406
|
+
if (!gapSnap) {
|
|
407
|
+
return pointSnap;
|
|
408
|
+
}
|
|
409
|
+
return Math.abs(pointSnap.nudge) <= Math.abs(gapSnap.nudge)
|
|
410
|
+
? pointSnap
|
|
411
|
+
: gapSnap;
|
|
412
|
+
}
|