@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,253 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Vec,
|
|
3
|
+
pagePointToShapePositionedPoint,
|
|
4
|
+
positionedShapePointToPagePoint,
|
|
5
|
+
type ArrowBindingPreviewState,
|
|
6
|
+
type ArrowBindingTargetInput,
|
|
7
|
+
type Editor,
|
|
8
|
+
type ResolvedArrowTerminalBinding,
|
|
9
|
+
type ShapeId,
|
|
10
|
+
type ShapeRecord,
|
|
11
|
+
} from "@land/canvas-core";
|
|
12
|
+
import {
|
|
13
|
+
getArrowTerminalPagePoint,
|
|
14
|
+
getOppositeArrowTerminal,
|
|
15
|
+
} from "./arrowGeometry";
|
|
16
|
+
import {
|
|
17
|
+
isArrowShapeRecord,
|
|
18
|
+
type ArrowPoint,
|
|
19
|
+
type ArrowShapeRecord,
|
|
20
|
+
} from "./types";
|
|
21
|
+
|
|
22
|
+
interface ArrowBindingTargetCandidate {
|
|
23
|
+
targetShape: ShapeRecord;
|
|
24
|
+
normalizedAnchor: ArrowPoint;
|
|
25
|
+
resolvedPagePoint: Vec;
|
|
26
|
+
rawPagePoint: Vec;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function clampUnit(value: number): number {
|
|
30
|
+
return Math.max(0, Math.min(1, value));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getNormalizedAnchorPositionedPoint(
|
|
34
|
+
editor: Editor,
|
|
35
|
+
target: ShapeRecord,
|
|
36
|
+
normalizedAnchor: ArrowPoint,
|
|
37
|
+
): Vec {
|
|
38
|
+
const bounds = editor.computeShapeBounds(target);
|
|
39
|
+
return new Vec(
|
|
40
|
+
bounds.minX + bounds.w * normalizedAnchor.x,
|
|
41
|
+
bounds.minY + bounds.h * normalizedAnchor.y,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function resolveTargetBoundaryPoint(
|
|
46
|
+
editor: Editor,
|
|
47
|
+
target: ShapeRecord,
|
|
48
|
+
rawAnchorPagePoint: Vec,
|
|
49
|
+
oppositePagePoint: Vec,
|
|
50
|
+
): Vec {
|
|
51
|
+
const util = editor.getShapeUtil(target);
|
|
52
|
+
return util.resolveBindingPoint(target, {
|
|
53
|
+
rawPagePoint: rawAnchorPagePoint,
|
|
54
|
+
oppositePagePoint,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function canBindArrowToShape(
|
|
59
|
+
shape: ShapeRecord | undefined,
|
|
60
|
+
): shape is ShapeRecord {
|
|
61
|
+
return !!shape && !isArrowShapeRecord(shape);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getArrowBindingNormalizedAnchor(
|
|
65
|
+
editor: Editor,
|
|
66
|
+
target: ShapeRecord,
|
|
67
|
+
rawPagePoint: Vec,
|
|
68
|
+
): ArrowPoint {
|
|
69
|
+
const util = editor.getShapeUtil(target);
|
|
70
|
+
const positionedPoint = pagePointToShapePositionedPoint(
|
|
71
|
+
target,
|
|
72
|
+
rawPagePoint,
|
|
73
|
+
util,
|
|
74
|
+
);
|
|
75
|
+
const bounds = editor.computeShapeBounds(target);
|
|
76
|
+
const normalizedX =
|
|
77
|
+
bounds.w <= 1e-6
|
|
78
|
+
? 0.5
|
|
79
|
+
: (positionedPoint.x - bounds.minX) / bounds.w;
|
|
80
|
+
const normalizedY =
|
|
81
|
+
bounds.h <= 1e-6
|
|
82
|
+
? 0.5
|
|
83
|
+
: (positionedPoint.y - bounds.minY) / bounds.h;
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
x: clampUnit(normalizedX),
|
|
87
|
+
y: clampUnit(normalizedY),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function resolveArrowBindingPagePoint(
|
|
92
|
+
editor: Editor,
|
|
93
|
+
target: ShapeRecord,
|
|
94
|
+
normalizedAnchor: ArrowPoint,
|
|
95
|
+
oppositePagePoint: Vec,
|
|
96
|
+
): Vec {
|
|
97
|
+
const util = editor.getShapeUtil(target);
|
|
98
|
+
const rawAnchorPagePoint = positionedShapePointToPagePoint(
|
|
99
|
+
target,
|
|
100
|
+
getNormalizedAnchorPositionedPoint(editor, target, normalizedAnchor),
|
|
101
|
+
util,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return resolveTargetBoundaryPoint(
|
|
105
|
+
editor,
|
|
106
|
+
target,
|
|
107
|
+
rawAnchorPagePoint,
|
|
108
|
+
oppositePagePoint,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getArrowBindingTargetAtPoint(
|
|
113
|
+
editor: Editor,
|
|
114
|
+
rawPagePoint: Vec,
|
|
115
|
+
oppositePagePoint: Vec,
|
|
116
|
+
options?: { excludeShapeId?: ShapeId },
|
|
117
|
+
): ArrowBindingTargetCandidate | null {
|
|
118
|
+
const target = editor.spatialIndex.getShapeAtPoint(rawPagePoint, {
|
|
119
|
+
filter: (candidate) =>
|
|
120
|
+
candidate.id !== options?.excludeShapeId &&
|
|
121
|
+
canBindArrowToShape(candidate),
|
|
122
|
+
});
|
|
123
|
+
if (!target) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const normalizedAnchor = getArrowBindingNormalizedAnchor(
|
|
128
|
+
editor,
|
|
129
|
+
target,
|
|
130
|
+
rawPagePoint,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
targetShape: target,
|
|
135
|
+
normalizedAnchor,
|
|
136
|
+
resolvedPagePoint: resolveArrowBindingPagePoint(
|
|
137
|
+
editor,
|
|
138
|
+
target,
|
|
139
|
+
normalizedAnchor,
|
|
140
|
+
oppositePagePoint,
|
|
141
|
+
),
|
|
142
|
+
rawPagePoint: rawPagePoint.clone(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function resolveArrowTerminalBindingAtPoint(
|
|
147
|
+
editor: Editor,
|
|
148
|
+
{
|
|
149
|
+
terminal,
|
|
150
|
+
rawPagePoint,
|
|
151
|
+
oppositePagePoint,
|
|
152
|
+
excludeShapeId,
|
|
153
|
+
ignoreTargets = false,
|
|
154
|
+
}: {
|
|
155
|
+
terminal: "start" | "end";
|
|
156
|
+
rawPagePoint: Vec;
|
|
157
|
+
oppositePagePoint: Vec;
|
|
158
|
+
excludeShapeId?: ShapeId;
|
|
159
|
+
ignoreTargets?: boolean;
|
|
160
|
+
},
|
|
161
|
+
): ResolvedArrowTerminalBinding {
|
|
162
|
+
if (ignoreTargets) {
|
|
163
|
+
return {
|
|
164
|
+
pagePoint: rawPagePoint.clone(),
|
|
165
|
+
binding: null,
|
|
166
|
+
preview: null,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const candidate = getArrowBindingTargetAtPoint(
|
|
171
|
+
editor,
|
|
172
|
+
rawPagePoint,
|
|
173
|
+
oppositePagePoint,
|
|
174
|
+
{ excludeShapeId },
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
pagePoint: candidate?.resolvedPagePoint ?? rawPagePoint.clone(),
|
|
179
|
+
binding: getArrowBindingTargetInput(candidate),
|
|
180
|
+
preview: getArrowBindingPreview(terminal, candidate),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function resolveArrowTerminalBindingAtStartPoint(
|
|
185
|
+
editor: Editor,
|
|
186
|
+
{
|
|
187
|
+
terminal,
|
|
188
|
+
rawPagePoint,
|
|
189
|
+
ignoreTargets = false,
|
|
190
|
+
}: {
|
|
191
|
+
terminal: "start" | "end";
|
|
192
|
+
rawPagePoint: Vec;
|
|
193
|
+
ignoreTargets?: boolean;
|
|
194
|
+
},
|
|
195
|
+
): ResolvedArrowTerminalBinding {
|
|
196
|
+
return resolveArrowTerminalBindingAtPoint(editor, {
|
|
197
|
+
terminal,
|
|
198
|
+
rawPagePoint,
|
|
199
|
+
oppositePagePoint: rawPagePoint.add(new Vec(1, 0)),
|
|
200
|
+
ignoreTargets,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function resolveArrowTerminalBindingForArrow(
|
|
205
|
+
editor: Editor,
|
|
206
|
+
{
|
|
207
|
+
arrow,
|
|
208
|
+
terminal,
|
|
209
|
+
rawPagePoint,
|
|
210
|
+
ignoreTargets = false,
|
|
211
|
+
}: {
|
|
212
|
+
arrow: ArrowShapeRecord;
|
|
213
|
+
terminal: "start" | "end";
|
|
214
|
+
rawPagePoint: Vec;
|
|
215
|
+
ignoreTargets?: boolean;
|
|
216
|
+
},
|
|
217
|
+
): ResolvedArrowTerminalBinding {
|
|
218
|
+
return resolveArrowTerminalBindingAtPoint(editor, {
|
|
219
|
+
terminal,
|
|
220
|
+
rawPagePoint,
|
|
221
|
+
oppositePagePoint: getArrowTerminalPagePoint(
|
|
222
|
+
arrow,
|
|
223
|
+
getOppositeArrowTerminal(terminal),
|
|
224
|
+
),
|
|
225
|
+
excludeShapeId: arrow.id,
|
|
226
|
+
ignoreTargets,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function getArrowBindingTargetInput(
|
|
231
|
+
candidate: ArrowBindingTargetCandidate | null,
|
|
232
|
+
): ArrowBindingTargetInput | null {
|
|
233
|
+
return candidate
|
|
234
|
+
? {
|
|
235
|
+
targetShapeId: candidate.targetShape.id,
|
|
236
|
+
normalizedAnchor: candidate.normalizedAnchor,
|
|
237
|
+
}
|
|
238
|
+
: null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function getArrowBindingPreview(
|
|
242
|
+
terminal: "start" | "end",
|
|
243
|
+
candidate: ArrowBindingTargetCandidate | null,
|
|
244
|
+
): ArrowBindingPreviewState | null {
|
|
245
|
+
return candidate
|
|
246
|
+
? {
|
|
247
|
+
terminal,
|
|
248
|
+
targetShapeId: candidate.targetShape.id,
|
|
249
|
+
rawPagePoint: candidate.rawPagePoint,
|
|
250
|
+
resolvedPagePoint: candidate.resolvedPagePoint,
|
|
251
|
+
}
|
|
252
|
+
: null;
|
|
253
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Vec,
|
|
3
|
+
type ChangeSource,
|
|
4
|
+
type Editor,
|
|
5
|
+
type PageId,
|
|
6
|
+
type ResolvedArrowTerminalBinding,
|
|
7
|
+
type ShapeId,
|
|
8
|
+
type ArrowBindingTargetInput,
|
|
9
|
+
} from "@land/canvas-core";
|
|
10
|
+
import { setArrowTerminalPagePoint, withArrowPagePoints } from "./arrowGeometry";
|
|
11
|
+
import {
|
|
12
|
+
isArrowBindingRecord,
|
|
13
|
+
isArrowShapeRecord,
|
|
14
|
+
type ArrowShapeRecord,
|
|
15
|
+
type ArrowShapeProps,
|
|
16
|
+
type ArrowTerminal,
|
|
17
|
+
} from "./types";
|
|
18
|
+
|
|
19
|
+
export interface CreateArrowInput {
|
|
20
|
+
startPagePoint: Vec;
|
|
21
|
+
endPagePoint: Vec;
|
|
22
|
+
startBinding?: ArrowBindingTargetInput | null;
|
|
23
|
+
endBinding?: ArrowBindingTargetInput | null;
|
|
24
|
+
props?: Partial<ArrowShapeProps>;
|
|
25
|
+
parentId?: PageId;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createArrow(
|
|
29
|
+
editor: Editor,
|
|
30
|
+
input: CreateArrowInput,
|
|
31
|
+
source: ChangeSource = "user",
|
|
32
|
+
): ArrowShapeRecord {
|
|
33
|
+
const [createdShape] = editor.commands.createShapes(
|
|
34
|
+
[
|
|
35
|
+
{
|
|
36
|
+
type: "arrow",
|
|
37
|
+
x: input.startPagePoint.x,
|
|
38
|
+
y: input.startPagePoint.y,
|
|
39
|
+
parentId: input.parentId,
|
|
40
|
+
props: input.props,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
{ source },
|
|
44
|
+
);
|
|
45
|
+
if (!isArrowShapeRecord(createdShape)) {
|
|
46
|
+
throw new Error("Failed to create arrow shape");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const normalizedArrow = withArrowPagePoints(
|
|
50
|
+
createdShape,
|
|
51
|
+
input.startPagePoint,
|
|
52
|
+
input.endPagePoint,
|
|
53
|
+
);
|
|
54
|
+
editor.commands.updateShapes(
|
|
55
|
+
[
|
|
56
|
+
{
|
|
57
|
+
id: createdShape.id,
|
|
58
|
+
x: normalizedArrow.x,
|
|
59
|
+
y: normalizedArrow.y,
|
|
60
|
+
rotation: normalizedArrow.rotation,
|
|
61
|
+
scaleX: normalizedArrow.scaleX,
|
|
62
|
+
scaleY: normalizedArrow.scaleY,
|
|
63
|
+
props: { ...normalizedArrow.props },
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
{ source },
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (input.startBinding) {
|
|
70
|
+
editor.commands.createBinding(
|
|
71
|
+
{
|
|
72
|
+
type: "arrow",
|
|
73
|
+
fromId: normalizedArrow.id,
|
|
74
|
+
toId: input.startBinding.targetShapeId,
|
|
75
|
+
props: {
|
|
76
|
+
terminal: "start",
|
|
77
|
+
normalizedAnchor: input.startBinding.normalizedAnchor,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{ source },
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (input.endBinding) {
|
|
85
|
+
editor.commands.createBinding(
|
|
86
|
+
{
|
|
87
|
+
type: "arrow",
|
|
88
|
+
fromId: normalizedArrow.id,
|
|
89
|
+
toId: input.endBinding.targetShapeId,
|
|
90
|
+
props: {
|
|
91
|
+
terminal: "end",
|
|
92
|
+
normalizedAnchor: input.endBinding.normalizedAnchor,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{ source },
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const created = editor.getShape(normalizedArrow.id);
|
|
100
|
+
if (!isArrowShapeRecord(created)) {
|
|
101
|
+
throw new Error("Failed to create arrow shape");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return created;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function applyResolvedArrowTerminalBinding(
|
|
108
|
+
editor: Editor,
|
|
109
|
+
shapeId: ShapeId | null,
|
|
110
|
+
terminal: ArrowTerminal,
|
|
111
|
+
resolvedBinding: ResolvedArrowTerminalBinding,
|
|
112
|
+
source: ChangeSource = "user",
|
|
113
|
+
): ArrowShapeRecord | null {
|
|
114
|
+
if (!shapeId) {
|
|
115
|
+
editor.setBindingPreview(resolvedBinding.preview);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let nextArrow: ArrowShapeRecord | null = null;
|
|
120
|
+
|
|
121
|
+
nextArrow = updateArrowTerminal(
|
|
122
|
+
editor,
|
|
123
|
+
{
|
|
124
|
+
shapeId,
|
|
125
|
+
terminal,
|
|
126
|
+
pagePoint: resolvedBinding.pagePoint,
|
|
127
|
+
binding: resolvedBinding.binding,
|
|
128
|
+
},
|
|
129
|
+
source,
|
|
130
|
+
);
|
|
131
|
+
editor.setBindingPreview(resolvedBinding.preview);
|
|
132
|
+
|
|
133
|
+
return nextArrow;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function updateArrowTerminal(
|
|
137
|
+
editor: Editor,
|
|
138
|
+
input: {
|
|
139
|
+
shapeId: ShapeId;
|
|
140
|
+
terminal: ArrowTerminal;
|
|
141
|
+
pagePoint: Vec;
|
|
142
|
+
binding?: ArrowBindingTargetInput | null;
|
|
143
|
+
},
|
|
144
|
+
source: ChangeSource,
|
|
145
|
+
): ArrowShapeRecord | null {
|
|
146
|
+
const current = editor.getShape(input.shapeId);
|
|
147
|
+
if (!isArrowShapeRecord(current)) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const freeArrow = setArrowTerminalPagePoint(
|
|
152
|
+
current,
|
|
153
|
+
input.terminal,
|
|
154
|
+
input.pagePoint,
|
|
155
|
+
);
|
|
156
|
+
editor.commands.updateShapes(
|
|
157
|
+
[
|
|
158
|
+
{
|
|
159
|
+
id: current.id,
|
|
160
|
+
x: freeArrow.x,
|
|
161
|
+
y: freeArrow.y,
|
|
162
|
+
rotation: freeArrow.rotation,
|
|
163
|
+
scaleX: freeArrow.scaleX,
|
|
164
|
+
scaleY: freeArrow.scaleY,
|
|
165
|
+
props: { ...freeArrow.props },
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
{ source },
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const existingBinding =
|
|
172
|
+
editor.bindings
|
|
173
|
+
.getBindingsFromShape(current.id)
|
|
174
|
+
.find(
|
|
175
|
+
(binding) =>
|
|
176
|
+
isArrowBindingRecord(binding) &&
|
|
177
|
+
binding.props.terminal === input.terminal,
|
|
178
|
+
) ?? null;
|
|
179
|
+
|
|
180
|
+
if (input.binding) {
|
|
181
|
+
if (isArrowBindingRecord(existingBinding)) {
|
|
182
|
+
editor.commands.updateBinding(
|
|
183
|
+
{
|
|
184
|
+
id: existingBinding.id,
|
|
185
|
+
toId: input.binding.targetShapeId,
|
|
186
|
+
props: {
|
|
187
|
+
terminal: input.terminal,
|
|
188
|
+
normalizedAnchor: input.binding.normalizedAnchor,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
{ source },
|
|
192
|
+
);
|
|
193
|
+
} else {
|
|
194
|
+
if (existingBinding) {
|
|
195
|
+
editor.commands.deleteBinding(existingBinding.id, { source });
|
|
196
|
+
}
|
|
197
|
+
editor.commands.createBinding(
|
|
198
|
+
{
|
|
199
|
+
type: "arrow",
|
|
200
|
+
fromId: current.id,
|
|
201
|
+
toId: input.binding.targetShapeId,
|
|
202
|
+
props: {
|
|
203
|
+
terminal: input.terminal,
|
|
204
|
+
normalizedAnchor: input.binding.normalizedAnchor,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
{ source },
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
} else if (existingBinding) {
|
|
211
|
+
editor.commands.deleteBinding(existingBinding.id, { source });
|
|
212
|
+
editor.commands.updateShapes(
|
|
213
|
+
[
|
|
214
|
+
{
|
|
215
|
+
id: current.id,
|
|
216
|
+
x: freeArrow.x,
|
|
217
|
+
y: freeArrow.y,
|
|
218
|
+
rotation: freeArrow.rotation,
|
|
219
|
+
scaleX: freeArrow.scaleX,
|
|
220
|
+
scaleY: freeArrow.scaleY,
|
|
221
|
+
props: { ...freeArrow.props },
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
{ source },
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const updated = editor.getShape(current.id);
|
|
229
|
+
return isArrowShapeRecord(updated) ? updated : freeArrow;
|
|
230
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { LandCanvasPlugin, ShapeRendererProps } from "@land/canvas-plugin-api";
|
|
2
|
+
import { getArrowLocalInfo } from "./arrowGeometry";
|
|
3
|
+
import type { ArrowShapeRecord } from "./types";
|
|
4
|
+
|
|
5
|
+
export function createArrowCanvasPlugin(): LandCanvasPlugin {
|
|
6
|
+
return {
|
|
7
|
+
id: "land.arrow.react",
|
|
8
|
+
setup(registerShapeRenderer) {
|
|
9
|
+
registerShapeRenderer({
|
|
10
|
+
type: "arrow",
|
|
11
|
+
component: ArrowShapeRenderer,
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function ArrowShapeRenderer({
|
|
18
|
+
shape,
|
|
19
|
+
isSelected,
|
|
20
|
+
}: ShapeRendererProps<ArrowShapeRecord>) {
|
|
21
|
+
const markerIdBase = shape.id.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
22
|
+
const startMarkerId = `arrow-head-start-${markerIdBase}`;
|
|
23
|
+
const endMarkerId = `arrow-head-end-${markerIdBase}`;
|
|
24
|
+
const arrowInfo = getArrowLocalInfo(shape);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<svg
|
|
28
|
+
width="100%"
|
|
29
|
+
height="100%"
|
|
30
|
+
viewBox={`0 0 ${shape.props.w} ${shape.props.h}`}
|
|
31
|
+
overflow="visible"
|
|
32
|
+
>
|
|
33
|
+
<defs>
|
|
34
|
+
<marker
|
|
35
|
+
id={startMarkerId}
|
|
36
|
+
markerWidth="12"
|
|
37
|
+
markerHeight="12"
|
|
38
|
+
viewBox="0 0 24 24"
|
|
39
|
+
refX="2"
|
|
40
|
+
refY="12"
|
|
41
|
+
orient="auto"
|
|
42
|
+
markerUnits="strokeWidth"
|
|
43
|
+
>
|
|
44
|
+
<path
|
|
45
|
+
d="M8.9,8 L2,12 L8.9,16"
|
|
46
|
+
fill="none"
|
|
47
|
+
stroke={shape.props.stroke}
|
|
48
|
+
strokeWidth="2"
|
|
49
|
+
strokeLinecap="round"
|
|
50
|
+
strokeLinejoin="round"
|
|
51
|
+
/>
|
|
52
|
+
</marker>
|
|
53
|
+
<marker
|
|
54
|
+
id={endMarkerId}
|
|
55
|
+
markerWidth="12"
|
|
56
|
+
markerHeight="12"
|
|
57
|
+
viewBox="0 0 24 24"
|
|
58
|
+
refX="22"
|
|
59
|
+
refY="12"
|
|
60
|
+
orient="auto"
|
|
61
|
+
markerUnits="strokeWidth"
|
|
62
|
+
>
|
|
63
|
+
<path
|
|
64
|
+
d="M15.1,8 L22,12 L15.1,16"
|
|
65
|
+
fill="none"
|
|
66
|
+
stroke={shape.props.stroke}
|
|
67
|
+
strokeWidth="2"
|
|
68
|
+
strokeLinecap="round"
|
|
69
|
+
strokeLinejoin="round"
|
|
70
|
+
/>
|
|
71
|
+
</marker>
|
|
72
|
+
</defs>
|
|
73
|
+
<path
|
|
74
|
+
d={arrowInfo.path}
|
|
75
|
+
fill="none"
|
|
76
|
+
stroke={shape.props.stroke}
|
|
77
|
+
strokeWidth={shape.props.strokeWidth}
|
|
78
|
+
strokeLinecap="round"
|
|
79
|
+
strokeLinejoin="round"
|
|
80
|
+
markerStart={
|
|
81
|
+
shape.props.headStart === "arrow"
|
|
82
|
+
? `url(#${startMarkerId})`
|
|
83
|
+
: undefined
|
|
84
|
+
}
|
|
85
|
+
markerEnd={
|
|
86
|
+
shape.props.headEnd === "arrow" ? `url(#${endMarkerId})` : undefined
|
|
87
|
+
}
|
|
88
|
+
opacity={isSelected ? 0.92 : 1}
|
|
89
|
+
/>
|
|
90
|
+
</svg>
|
|
91
|
+
);
|
|
92
|
+
}
|