@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,409 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
|
|
3
|
+
type LandCorePlugin,
|
|
4
|
+
type ShapeSvgExporter,
|
|
5
|
+
type SvgElementNode,
|
|
6
|
+
type SvgExportContext,
|
|
7
|
+
type SvgNode,
|
|
8
|
+
type ToolbarAction,
|
|
9
|
+
type ToolbarActionValue,
|
|
10
|
+
type ToolbarContribution,
|
|
11
|
+
} from "@land/canvas-core";
|
|
12
|
+
import { ArrowBindingUtil } from "./ArrowBindingUtil";
|
|
13
|
+
import { ArrowShapeUtil } from "./ArrowShapeUtil";
|
|
14
|
+
import { ArrowTool } from "./ArrowTool";
|
|
15
|
+
import { getArrowLocalInfo } from "./arrowGeometry";
|
|
16
|
+
import { resolveArrowTerminalBindingAtPoint } from "./arrowTerminalBindingResolver";
|
|
17
|
+
import { createArrowInteractionHandler } from "./selectionHandleInteractions";
|
|
18
|
+
import type { ArrowShapeRecord } from "./types";
|
|
19
|
+
|
|
20
|
+
export class ArrowShapeSvgExporter
|
|
21
|
+
implements ShapeSvgExporter<ArrowShapeRecord>
|
|
22
|
+
{
|
|
23
|
+
readonly type = "arrow" as const;
|
|
24
|
+
|
|
25
|
+
toSvg(shape: ArrowShapeRecord, context: SvgExportContext): SvgNode {
|
|
26
|
+
const markerStart =
|
|
27
|
+
shape.props.headStart === "arrow"
|
|
28
|
+
? `url(#${context.addDef(createArrowMarker("start", shape.props.stroke))})`
|
|
29
|
+
: undefined;
|
|
30
|
+
const markerEnd =
|
|
31
|
+
shape.props.headEnd === "arrow"
|
|
32
|
+
? `url(#${context.addDef(createArrowMarker("end", shape.props.stroke))})`
|
|
33
|
+
: undefined;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
tag: "path",
|
|
37
|
+
attrs: {
|
|
38
|
+
d: getArrowLocalInfo(shape).path,
|
|
39
|
+
fill: "none",
|
|
40
|
+
stroke: shape.props.stroke,
|
|
41
|
+
"stroke-width": shape.props.strokeWidth,
|
|
42
|
+
"stroke-linecap": "round",
|
|
43
|
+
"stroke-linejoin": "round",
|
|
44
|
+
"marker-start": markerStart,
|
|
45
|
+
"marker-end": markerEnd,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createArrowCorePlugin(): LandCorePlugin {
|
|
52
|
+
return {
|
|
53
|
+
id: "land.arrow",
|
|
54
|
+
shapeCapabilities: [
|
|
55
|
+
{
|
|
56
|
+
type: "arrow",
|
|
57
|
+
schemaProps: [
|
|
58
|
+
"w",
|
|
59
|
+
"h",
|
|
60
|
+
"start",
|
|
61
|
+
"end",
|
|
62
|
+
"bend",
|
|
63
|
+
"stroke",
|
|
64
|
+
"strokeWidth",
|
|
65
|
+
"headStart",
|
|
66
|
+
"headEnd",
|
|
67
|
+
],
|
|
68
|
+
reactRenderer: "supported",
|
|
69
|
+
toolbarEntry: "supported",
|
|
70
|
+
notes: [
|
|
71
|
+
"Binding support lives in arrow binding records, not arrow props.",
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
shapeUtils: [new ArrowShapeUtil()],
|
|
76
|
+
shapeSvgExporters: [new ArrowShapeSvgExporter()],
|
|
77
|
+
bindingUtils: [new ArrowBindingUtil()],
|
|
78
|
+
interactionHandlers: [createArrowInteractionHandler()],
|
|
79
|
+
toolbarActions: [
|
|
80
|
+
createSetArrowStyleToolbarAction("stroke"),
|
|
81
|
+
createSetArrowStyleToolbarAction("strokeWidth"),
|
|
82
|
+
createSetArrowStyleToolbarAction("headStart"),
|
|
83
|
+
createSetArrowStyleToolbarAction("headEnd"),
|
|
84
|
+
createSetArrowDefaultStyleToolbarAction("stroke"),
|
|
85
|
+
createSetArrowDefaultStyleToolbarAction("strokeWidth"),
|
|
86
|
+
createSetArrowDefaultStyleToolbarAction("headStart"),
|
|
87
|
+
createSetArrowDefaultStyleToolbarAction("headEnd"),
|
|
88
|
+
],
|
|
89
|
+
toolbarContributions: [
|
|
90
|
+
createArrowToolToolbarContribution(),
|
|
91
|
+
createArrowDefaultStyleToolbarContribution(),
|
|
92
|
+
createArrowSelectionToolbarContribution(),
|
|
93
|
+
],
|
|
94
|
+
setup(editor) {
|
|
95
|
+
editor.setArrowTerminalBindingResolver(resolveArrowTerminalBindingAtPoint);
|
|
96
|
+
editor.tools.register(
|
|
97
|
+
"arrow",
|
|
98
|
+
(currentEditor) => new ArrowTool(currentEditor),
|
|
99
|
+
{ shortcut: "a" },
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const ARROW_STROKE_SWATCHES = [
|
|
106
|
+
{ value: "#1d4ed8", label: "Blue", color: "#1d4ed8" },
|
|
107
|
+
{ value: "#15803d", label: "Green", color: "#15803d" },
|
|
108
|
+
{ value: "#dc2626", label: "Red", color: "#dc2626" },
|
|
109
|
+
{ value: "#334155", label: "Slate", color: "#334155" },
|
|
110
|
+
] as const;
|
|
111
|
+
|
|
112
|
+
const ARROW_STROKE_WIDTH_OPTIONS = [
|
|
113
|
+
{ value: 1, label: "1" },
|
|
114
|
+
{ value: 2, label: "2" },
|
|
115
|
+
{ value: 4, label: "4" },
|
|
116
|
+
] as const;
|
|
117
|
+
|
|
118
|
+
const ARROW_HEAD_OPTIONS = [
|
|
119
|
+
{ value: "none", label: "None", icon: "minus" },
|
|
120
|
+
{ value: "arrow", label: "Arrow", icon: "arrow-right" },
|
|
121
|
+
] as const satisfies readonly {
|
|
122
|
+
value: ArrowShapeRecord["props"]["headStart"];
|
|
123
|
+
label: string;
|
|
124
|
+
icon: string;
|
|
125
|
+
}[];
|
|
126
|
+
|
|
127
|
+
function createArrowToolToolbarContribution(): ToolbarContribution {
|
|
128
|
+
return {
|
|
129
|
+
id: "arrow.tool-toolbar",
|
|
130
|
+
surface: "tool",
|
|
131
|
+
placement: "chrome",
|
|
132
|
+
order: 40,
|
|
133
|
+
actionIds: [SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID],
|
|
134
|
+
getGroups() {
|
|
135
|
+
return [
|
|
136
|
+
{
|
|
137
|
+
id: "arrow.tools",
|
|
138
|
+
items: [
|
|
139
|
+
{
|
|
140
|
+
kind: "button",
|
|
141
|
+
id: "arrow.tool.arrow",
|
|
142
|
+
actionId: SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
|
|
143
|
+
value: "arrow",
|
|
144
|
+
label: "Arrow",
|
|
145
|
+
shortcut: "A",
|
|
146
|
+
icon: "arrow-right",
|
|
147
|
+
dataUi: "arrow-tool-button",
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function createArrowSelectionToolbarContribution(): ToolbarContribution {
|
|
157
|
+
return {
|
|
158
|
+
id: "arrow.selection-toolbar",
|
|
159
|
+
surface: "selection",
|
|
160
|
+
order: 20,
|
|
161
|
+
actionIds: [
|
|
162
|
+
"arrow.set-stroke",
|
|
163
|
+
"arrow.set-strokeWidth",
|
|
164
|
+
"arrow.set-headStart",
|
|
165
|
+
"arrow.set-headEnd",
|
|
166
|
+
],
|
|
167
|
+
when(context) {
|
|
168
|
+
return context.selection.commonShapeType === "arrow";
|
|
169
|
+
},
|
|
170
|
+
getGroups() {
|
|
171
|
+
return getArrowStyleToolbarGroups({
|
|
172
|
+
strokeActionId: "arrow.set-stroke",
|
|
173
|
+
strokeWidthActionId: "arrow.set-strokeWidth",
|
|
174
|
+
headStartActionId: "arrow.set-headStart",
|
|
175
|
+
headEndActionId: "arrow.set-headEnd",
|
|
176
|
+
dataUiPrefix: "arrow",
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function createArrowDefaultStyleToolbarContribution(): ToolbarContribution {
|
|
183
|
+
return {
|
|
184
|
+
id: "arrow.default-style.tool-toolbar",
|
|
185
|
+
surface: "tool",
|
|
186
|
+
order: 41,
|
|
187
|
+
actionIds: [
|
|
188
|
+
"arrow.default-stroke",
|
|
189
|
+
"arrow.default-strokeWidth",
|
|
190
|
+
"arrow.default-headStart",
|
|
191
|
+
"arrow.default-headEnd",
|
|
192
|
+
],
|
|
193
|
+
when(context) {
|
|
194
|
+
return context.tool.activeToolId === "arrow";
|
|
195
|
+
},
|
|
196
|
+
getGroups() {
|
|
197
|
+
return getArrowStyleToolbarGroups({
|
|
198
|
+
strokeActionId: "arrow.default-stroke",
|
|
199
|
+
strokeWidthActionId: "arrow.default-strokeWidth",
|
|
200
|
+
headStartActionId: "arrow.default-headStart",
|
|
201
|
+
headEndActionId: "arrow.default-headEnd",
|
|
202
|
+
dataUiPrefix: "arrow-default",
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function getArrowStyleToolbarGroups({
|
|
209
|
+
strokeActionId,
|
|
210
|
+
strokeWidthActionId,
|
|
211
|
+
headStartActionId,
|
|
212
|
+
headEndActionId,
|
|
213
|
+
dataUiPrefix,
|
|
214
|
+
}: {
|
|
215
|
+
strokeActionId: string;
|
|
216
|
+
strokeWidthActionId: string;
|
|
217
|
+
headStartActionId: string;
|
|
218
|
+
headEndActionId: string;
|
|
219
|
+
dataUiPrefix: string;
|
|
220
|
+
}) {
|
|
221
|
+
return [
|
|
222
|
+
{
|
|
223
|
+
id: `${dataUiPrefix}.style-stroke`,
|
|
224
|
+
items: [
|
|
225
|
+
{
|
|
226
|
+
kind: "swatches" as const,
|
|
227
|
+
id: `${dataUiPrefix}.stroke`,
|
|
228
|
+
actionId: strokeActionId,
|
|
229
|
+
label: "Stroke",
|
|
230
|
+
options: ARROW_STROKE_SWATCHES.map((option) => ({
|
|
231
|
+
...option,
|
|
232
|
+
dataUi: `${dataUiPrefix}-stroke-${option.label.toLowerCase()}-button`,
|
|
233
|
+
})),
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: `${dataUiPrefix}.style-stroke-width`,
|
|
239
|
+
items: [
|
|
240
|
+
{
|
|
241
|
+
kind: "stepper" as const,
|
|
242
|
+
id: `${dataUiPrefix}.stroke-width`,
|
|
243
|
+
actionId: strokeWidthActionId,
|
|
244
|
+
label: "Stroke width",
|
|
245
|
+
dataUi: `${dataUiPrefix}-stroke-width-control`,
|
|
246
|
+
options: ARROW_STROKE_WIDTH_OPTIONS.map((option) => ({
|
|
247
|
+
...option,
|
|
248
|
+
dataUi: `${dataUiPrefix}-stroke-width-${option.value}-button`,
|
|
249
|
+
})),
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: `${dataUiPrefix}.head-start`,
|
|
255
|
+
items: [
|
|
256
|
+
{
|
|
257
|
+
kind: "segmented" as const,
|
|
258
|
+
id: `${dataUiPrefix}.head-start`,
|
|
259
|
+
actionId: headStartActionId,
|
|
260
|
+
options: ARROW_HEAD_OPTIONS.map((option) => ({
|
|
261
|
+
...option,
|
|
262
|
+
label: `Start head: ${option.label}`,
|
|
263
|
+
dataUi: `${dataUiPrefix}-start-head-${option.value}-button`,
|
|
264
|
+
})),
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: `${dataUiPrefix}.head-end`,
|
|
270
|
+
items: [
|
|
271
|
+
{
|
|
272
|
+
kind: "segmented" as const,
|
|
273
|
+
id: `${dataUiPrefix}.head-end`,
|
|
274
|
+
actionId: headEndActionId,
|
|
275
|
+
options: ARROW_HEAD_OPTIONS.map((option) => ({
|
|
276
|
+
...option,
|
|
277
|
+
label: `End head: ${option.label}`,
|
|
278
|
+
dataUi: `${dataUiPrefix}-end-head-${option.value}-button`,
|
|
279
|
+
})),
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
},
|
|
283
|
+
];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function createSetArrowStyleToolbarAction(
|
|
287
|
+
prop: "stroke" | "strokeWidth" | "headStart" | "headEnd",
|
|
288
|
+
): ToolbarAction<ToolbarActionValue> {
|
|
289
|
+
return {
|
|
290
|
+
id: `arrow.set-${prop}`,
|
|
291
|
+
isVisible(context) {
|
|
292
|
+
return context.selection.commonShapeType === "arrow";
|
|
293
|
+
},
|
|
294
|
+
isEnabled(context) {
|
|
295
|
+
return context.selection.count > 0;
|
|
296
|
+
},
|
|
297
|
+
getValue(context) {
|
|
298
|
+
return getCommonArrowPropValue(context.selection.selectedShapes, prop);
|
|
299
|
+
},
|
|
300
|
+
run({ context, value }) {
|
|
301
|
+
if (!isValidArrowStyleValue(prop, value)) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const updates = context.selection.selectedShapes
|
|
305
|
+
.filter((shape): shape is ArrowShapeRecord => shape.type === "arrow")
|
|
306
|
+
.filter((shape) => !shape.isLocked)
|
|
307
|
+
.map((shape) => ({
|
|
308
|
+
id: shape.id,
|
|
309
|
+
props: {
|
|
310
|
+
[prop]: value,
|
|
311
|
+
},
|
|
312
|
+
}));
|
|
313
|
+
if (updates.length === 0) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
context.editor.commands.updateShapes(updates, { source: "user" });
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function createSetArrowDefaultStyleToolbarAction(
|
|
322
|
+
prop: "stroke" | "strokeWidth" | "headStart" | "headEnd",
|
|
323
|
+
): ToolbarAction<ToolbarActionValue> {
|
|
324
|
+
return {
|
|
325
|
+
id: `arrow.default-${prop}`,
|
|
326
|
+
isVisible(context) {
|
|
327
|
+
return context.tool.activeToolId === "arrow";
|
|
328
|
+
},
|
|
329
|
+
getValue(context) {
|
|
330
|
+
return context.editor.getDefaultShapeProps<ArrowShapeRecord["props"]>(
|
|
331
|
+
"arrow",
|
|
332
|
+
)[prop];
|
|
333
|
+
},
|
|
334
|
+
run({ context, value }) {
|
|
335
|
+
if (!isValidArrowStyleValue(prop, value)) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
context.editor.updateDefaultShapeProps("arrow", { [prop]: value });
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function getCommonArrowPropValue(
|
|
344
|
+
selectedShapes: readonly { type: string; props: object }[],
|
|
345
|
+
prop: "stroke" | "strokeWidth" | "headStart" | "headEnd",
|
|
346
|
+
): ToolbarActionValue {
|
|
347
|
+
let value: ToolbarActionValue | undefined;
|
|
348
|
+
for (const shape of selectedShapes) {
|
|
349
|
+
if (shape.type !== "arrow") {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
const nextValue = (shape.props as ArrowShapeRecord["props"])[prop];
|
|
353
|
+
if (value === undefined) {
|
|
354
|
+
value = nextValue;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (value !== nextValue) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return value ?? null;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function isValidArrowStyleValue(
|
|
365
|
+
prop: "stroke" | "strokeWidth" | "headStart" | "headEnd",
|
|
366
|
+
value: ToolbarActionValue,
|
|
367
|
+
): boolean {
|
|
368
|
+
if (prop === "strokeWidth") {
|
|
369
|
+
return ARROW_STROKE_WIDTH_OPTIONS.some((option) => option.value === value);
|
|
370
|
+
}
|
|
371
|
+
if (prop === "stroke") {
|
|
372
|
+
return ARROW_STROKE_SWATCHES.some((option) => option.value === value);
|
|
373
|
+
}
|
|
374
|
+
return ARROW_HEAD_OPTIONS.some((option) => option.value === value);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function createArrowMarker(
|
|
378
|
+
terminal: "start" | "end",
|
|
379
|
+
stroke: string,
|
|
380
|
+
): SvgElementNode {
|
|
381
|
+
return {
|
|
382
|
+
tag: "marker",
|
|
383
|
+
attrs: {
|
|
384
|
+
markerWidth: 12,
|
|
385
|
+
markerHeight: 12,
|
|
386
|
+
viewBox: "0 0 24 24",
|
|
387
|
+
refX: terminal === "start" ? 2 : 22,
|
|
388
|
+
refY: 12,
|
|
389
|
+
orient: "auto",
|
|
390
|
+
markerUnits: "strokeWidth",
|
|
391
|
+
},
|
|
392
|
+
children: [
|
|
393
|
+
{
|
|
394
|
+
tag: "path",
|
|
395
|
+
attrs: {
|
|
396
|
+
d:
|
|
397
|
+
terminal === "start"
|
|
398
|
+
? "M8.9,8 L2,12 L8.9,16"
|
|
399
|
+
: "M15.1,8 L22,12 L15.1,16",
|
|
400
|
+
fill: "none",
|
|
401
|
+
stroke,
|
|
402
|
+
"stroke-width": 2,
|
|
403
|
+
"stroke-linecap": "round",
|
|
404
|
+
"stroke-linejoin": "round",
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
],
|
|
408
|
+
};
|
|
409
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineLandExtension,
|
|
3
|
+
type LandFeatureBundle,
|
|
4
|
+
} from "@land/canvas-plugin-api";
|
|
5
|
+
import { createArrowCanvasPlugin } from "./canvas";
|
|
6
|
+
import { createArrowCorePlugin } from "./core";
|
|
7
|
+
|
|
8
|
+
export function createArrowFeatureBundle(): LandFeatureBundle {
|
|
9
|
+
return {
|
|
10
|
+
id: "land.arrow.bundle",
|
|
11
|
+
corePlugins: [createArrowCorePlugin()],
|
|
12
|
+
canvasPlugins: [createArrowCanvasPlugin()],
|
|
13
|
+
shapeTypes: ["arrow"],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Arrow = defineLandExtension({
|
|
18
|
+
name: "arrow",
|
|
19
|
+
createFeature: createArrowFeatureBundle,
|
|
20
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { ArrowBindingUtil } from "./ArrowBindingUtil";
|
|
2
|
+
export { ArrowShapeUtil } from "./ArrowShapeUtil";
|
|
3
|
+
export { ArrowTool } from "./ArrowTool";
|
|
4
|
+
export { ArrowShapeSvgExporter, createArrowCorePlugin } from "./core";
|
|
5
|
+
export { createArrowCanvasPlugin } from "./canvas";
|
|
6
|
+
export { Arrow, createArrowFeatureBundle } from "./feature";
|
|
7
|
+
export {
|
|
8
|
+
isArrowBindingRecord,
|
|
9
|
+
isArrowShapeRecord,
|
|
10
|
+
type ArrowBindingProps,
|
|
11
|
+
type ArrowBindingRecord,
|
|
12
|
+
type ArrowPoint,
|
|
13
|
+
type ArrowShapeProps,
|
|
14
|
+
type ArrowShapeRecord,
|
|
15
|
+
type ArrowTerminal,
|
|
16
|
+
} from "./types";
|
|
17
|
+
export {
|
|
18
|
+
resolveArrowBindingPagePoint,
|
|
19
|
+
resolveArrowTerminalBindingAtPoint,
|
|
20
|
+
resolveArrowTerminalBindingAtStartPoint,
|
|
21
|
+
resolveArrowTerminalBindingForArrow,
|
|
22
|
+
} from "./arrowTerminalBindingResolver";
|
|
23
|
+
export { createArrow } from "./arrowTerminalCommands";
|
|
24
|
+
export { getArrowTerminalPagePoint } from "./arrowGeometry";
|
|
25
|
+
export {
|
|
26
|
+
createArrowInteractionHandler,
|
|
27
|
+
createArrowSelectionHandleInteractionHandler,
|
|
28
|
+
} from "./selectionHandleInteractions";
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type HandleSnapMode,
|
|
3
|
+
type LandInteractionHandler,
|
|
4
|
+
type SelectionArrowTerminalHandle,
|
|
5
|
+
type SelectionHandleInteractionHandler,
|
|
6
|
+
type SelectionHandleInteractionSession,
|
|
7
|
+
type ShapeId,
|
|
8
|
+
} from "@land/canvas-core";
|
|
9
|
+
import { applyResolvedArrowTerminalBinding } from "./arrowTerminalCommands";
|
|
10
|
+
import {
|
|
11
|
+
getArrowBendFromMiddlePagePoint,
|
|
12
|
+
getArrowTerminalPagePoint,
|
|
13
|
+
} from "./arrowGeometry";
|
|
14
|
+
import { resolveArrowTerminalBindingForArrow } from "./arrowTerminalBindingResolver";
|
|
15
|
+
import { isArrowShapeRecord } from "./types";
|
|
16
|
+
|
|
17
|
+
const ARROW_BEND_SNAP_DISTANCE_SCREEN = 6;
|
|
18
|
+
const TERMINAL_DRAG_HISTORY_MARK = "select.arrow_terminal_drag";
|
|
19
|
+
const ARROW_MIDDLE_DRAG_HISTORY_MARK = "select.arrow_middle_drag";
|
|
20
|
+
const ARROW_TERMINAL_HANDLE_SNAP_MODE: HandleSnapMode = "point";
|
|
21
|
+
|
|
22
|
+
function getArrowBendWithSnap({
|
|
23
|
+
bend,
|
|
24
|
+
bypassSnap,
|
|
25
|
+
zoom,
|
|
26
|
+
}: {
|
|
27
|
+
bend: number;
|
|
28
|
+
bypassSnap: boolean;
|
|
29
|
+
zoom: number;
|
|
30
|
+
}): number {
|
|
31
|
+
if (bypassSnap) {
|
|
32
|
+
return bend;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return Math.abs(bend) * zoom <= ARROW_BEND_SNAP_DISTANCE_SCREEN ? 0 : bend;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function createArrowTerminalSession({
|
|
39
|
+
handle,
|
|
40
|
+
shapeId,
|
|
41
|
+
terminal,
|
|
42
|
+
}: {
|
|
43
|
+
handle: SelectionArrowTerminalHandle;
|
|
44
|
+
shapeId: ShapeId;
|
|
45
|
+
terminal: "start" | "end";
|
|
46
|
+
}): SelectionHandleInteractionSession {
|
|
47
|
+
return {
|
|
48
|
+
shapeId,
|
|
49
|
+
historyMark: TERMINAL_DRAG_HISTORY_MARK,
|
|
50
|
+
handleSnapMode: ARROW_TERMINAL_HANDLE_SNAP_MODE,
|
|
51
|
+
handleSnapContext: {
|
|
52
|
+
shapeId,
|
|
53
|
+
handle,
|
|
54
|
+
},
|
|
55
|
+
shouldClearBindingPreviewOnExit: true,
|
|
56
|
+
update({ editor: currentEditor, pagePoint, accelKey, source }) {
|
|
57
|
+
const arrow = currentEditor.getShape(shapeId);
|
|
58
|
+
if (!isArrowShapeRecord(arrow)) {
|
|
59
|
+
return { status: "stop", finalPagePoint: null };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const nextBinding = resolveArrowTerminalBindingForArrow(currentEditor, {
|
|
63
|
+
arrow,
|
|
64
|
+
terminal,
|
|
65
|
+
rawPagePoint: pagePoint,
|
|
66
|
+
ignoreTargets: accelKey,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const nextArrow = applyResolvedArrowTerminalBinding(
|
|
70
|
+
currentEditor,
|
|
71
|
+
arrow.id,
|
|
72
|
+
terminal,
|
|
73
|
+
nextBinding,
|
|
74
|
+
source,
|
|
75
|
+
);
|
|
76
|
+
return {
|
|
77
|
+
status: "continue",
|
|
78
|
+
finalPagePoint: nextArrow
|
|
79
|
+
? getArrowTerminalPagePoint(nextArrow, terminal)
|
|
80
|
+
: nextBinding.pagePoint,
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function createArrowMiddleSession({
|
|
87
|
+
shapeId,
|
|
88
|
+
}: {
|
|
89
|
+
shapeId: ShapeId;
|
|
90
|
+
}): SelectionHandleInteractionSession {
|
|
91
|
+
return {
|
|
92
|
+
shapeId,
|
|
93
|
+
historyMark: ARROW_MIDDLE_DRAG_HISTORY_MARK,
|
|
94
|
+
update({ editor, pagePoint, accelKey, source }) {
|
|
95
|
+
const arrow = editor.getShape(shapeId);
|
|
96
|
+
if (!isArrowShapeRecord(arrow)) {
|
|
97
|
+
return "stop";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const bend = getArrowBendWithSnap({
|
|
101
|
+
bend: getArrowBendFromMiddlePagePoint(
|
|
102
|
+
getArrowTerminalPagePoint(arrow, "start"),
|
|
103
|
+
getArrowTerminalPagePoint(arrow, "end"),
|
|
104
|
+
pagePoint,
|
|
105
|
+
),
|
|
106
|
+
bypassSnap: accelKey,
|
|
107
|
+
zoom: editor.cameraZoomSignal.get(),
|
|
108
|
+
});
|
|
109
|
+
editor.commands.updateShapes(
|
|
110
|
+
[
|
|
111
|
+
{
|
|
112
|
+
id: arrow.id,
|
|
113
|
+
props: {
|
|
114
|
+
bend,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
{ source },
|
|
119
|
+
);
|
|
120
|
+
return "continue";
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function createArrowSelectionHandleInteractionHandler(): SelectionHandleInteractionHandler {
|
|
126
|
+
return {
|
|
127
|
+
createSession(editor, { handle, shape }) {
|
|
128
|
+
if (!isArrowShapeRecord(shape)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (handle.kind === "arrow_terminal") {
|
|
133
|
+
return createArrowTerminalSession({
|
|
134
|
+
handle,
|
|
135
|
+
shapeId: shape.id,
|
|
136
|
+
terminal: handle.terminal,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (handle.kind === "arrow_middle") {
|
|
141
|
+
return createArrowMiddleSession({ shapeId: shape.id });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return null;
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function createArrowInteractionHandler(): LandInteractionHandler {
|
|
150
|
+
return {
|
|
151
|
+
id: "land.arrow.interactions",
|
|
152
|
+
selectionHandle: createArrowSelectionHandleInteractionHandler(),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseRecord,
|
|
3
|
+
BindingRecord,
|
|
4
|
+
BindingRecordBase,
|
|
5
|
+
ShapeRecord,
|
|
6
|
+
ShapeRecordBase,
|
|
7
|
+
} from "@land/canvas-core";
|
|
8
|
+
|
|
9
|
+
export interface ArrowPoint {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ArrowTerminal = "start" | "end";
|
|
15
|
+
|
|
16
|
+
export interface ArrowShapeProps {
|
|
17
|
+
w: number;
|
|
18
|
+
h: number;
|
|
19
|
+
start: ArrowPoint;
|
|
20
|
+
end: ArrowPoint;
|
|
21
|
+
bend: number;
|
|
22
|
+
stroke: string;
|
|
23
|
+
strokeWidth: number;
|
|
24
|
+
headStart: "none" | "arrow";
|
|
25
|
+
headEnd: "none" | "arrow";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ArrowShapeRecord
|
|
29
|
+
extends ShapeRecordBase<"arrow", ArrowShapeProps> {
|
|
30
|
+
type: "arrow";
|
|
31
|
+
props: ArrowShapeProps;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ArrowBindingProps {
|
|
35
|
+
terminal: ArrowTerminal;
|
|
36
|
+
normalizedAnchor: ArrowPoint;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ArrowBindingRecord
|
|
40
|
+
extends BindingRecordBase<"arrow", ArrowBindingProps> {
|
|
41
|
+
type: "arrow";
|
|
42
|
+
props: ArrowBindingProps;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function isArrowShapeRecord(
|
|
46
|
+
record: BaseRecord | null | undefined,
|
|
47
|
+
): record is ArrowShapeRecord {
|
|
48
|
+
return (
|
|
49
|
+
!!record &&
|
|
50
|
+
record.typeName === "shape" &&
|
|
51
|
+
(record as ShapeRecord).type === "arrow"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isArrowBindingRecord(
|
|
56
|
+
record: BaseRecord | null | undefined,
|
|
57
|
+
): record is ArrowBindingRecord {
|
|
58
|
+
return (
|
|
59
|
+
!!record &&
|
|
60
|
+
record.typeName === "binding" &&
|
|
61
|
+
(record as BindingRecord).type === "arrow"
|
|
62
|
+
);
|
|
63
|
+
}
|