@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,534 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
|
|
3
|
+
type ContextMenuContribution,
|
|
4
|
+
type LandCorePlugin,
|
|
5
|
+
type ShapeSvgExporter,
|
|
6
|
+
type SvgNode,
|
|
7
|
+
type ShapeId,
|
|
8
|
+
type ToolbarAction,
|
|
9
|
+
type ToolbarActionValue,
|
|
10
|
+
type ToolbarContribution,
|
|
11
|
+
} from "@land/canvas-core";
|
|
12
|
+
import { FrameTool } from "./FrameTool";
|
|
13
|
+
import {
|
|
14
|
+
FrameShapeUtil,
|
|
15
|
+
type FrameShapeProps,
|
|
16
|
+
type FrameShapeRecord,
|
|
17
|
+
} from "./FrameShapeUtil";
|
|
18
|
+
|
|
19
|
+
export class FrameShapeSvgExporter
|
|
20
|
+
implements ShapeSvgExporter<FrameShapeRecord>
|
|
21
|
+
{
|
|
22
|
+
readonly type = "frame" as const;
|
|
23
|
+
|
|
24
|
+
toSvg(shape: FrameShapeRecord): SvgNode {
|
|
25
|
+
const { fill, stroke, strokeWidth, w, h, name } = shape.props;
|
|
26
|
+
const inset = strokeWidth / 2;
|
|
27
|
+
const width = Math.max(w - strokeWidth, 0);
|
|
28
|
+
const height = Math.max(h - strokeWidth, 0);
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
tag: "g",
|
|
32
|
+
children: [
|
|
33
|
+
{
|
|
34
|
+
tag: "rect",
|
|
35
|
+
attrs: {
|
|
36
|
+
x: inset,
|
|
37
|
+
y: inset,
|
|
38
|
+
width,
|
|
39
|
+
height,
|
|
40
|
+
fill,
|
|
41
|
+
stroke,
|
|
42
|
+
"stroke-width": strokeWidth,
|
|
43
|
+
"stroke-linejoin": "round",
|
|
44
|
+
"stroke-linecap": "round",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
tag: "text",
|
|
49
|
+
attrs: {
|
|
50
|
+
x: 12,
|
|
51
|
+
y: 18,
|
|
52
|
+
fill: stroke,
|
|
53
|
+
"font-family":
|
|
54
|
+
"Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
|
|
55
|
+
"font-size": 12,
|
|
56
|
+
"font-weight": 600,
|
|
57
|
+
},
|
|
58
|
+
children: [name],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createFrameCorePlugin(): LandCorePlugin {
|
|
66
|
+
return {
|
|
67
|
+
id: "land.frame",
|
|
68
|
+
shapeCapabilities: [
|
|
69
|
+
{
|
|
70
|
+
type: "frame",
|
|
71
|
+
schemaProps: ["w", "h", "name", "fill", "stroke", "strokeWidth"],
|
|
72
|
+
reactRenderer: "supported",
|
|
73
|
+
toolbarEntry: "supported",
|
|
74
|
+
notes: [
|
|
75
|
+
"Frame renderer, SVG exporter, creation tool, selected-frame style toolbar, selected-child order badge, and minimal single-child sibling reorder controls live in the frame plugin package. ParentId-based child query, child-index ordering, containing-parent query, clipped query bounds, point-in-clip checks, host clipping, select-drag containment, export descendant traversal, and clipped child export have preflights. Richer hover/drag reorder UI remains deferred.",
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
shapeUtils: [new FrameShapeUtil()],
|
|
80
|
+
shapeSvgExporters: [new FrameShapeSvgExporter()],
|
|
81
|
+
toolbarActions: [
|
|
82
|
+
createSetFrameStyleToolbarAction("fill"),
|
|
83
|
+
createSetFrameStyleToolbarAction("stroke"),
|
|
84
|
+
createSetFrameStyleToolbarAction("strokeWidth"),
|
|
85
|
+
createSetFrameDefaultStyleToolbarAction("fill"),
|
|
86
|
+
createSetFrameDefaultStyleToolbarAction("stroke"),
|
|
87
|
+
createSetFrameDefaultStyleToolbarAction("strokeWidth"),
|
|
88
|
+
createRenameFrameToolbarAction(),
|
|
89
|
+
createFrameChildMoveToolbarAction("backward"),
|
|
90
|
+
createFrameChildMoveToolbarAction("forward"),
|
|
91
|
+
],
|
|
92
|
+
toolbarContributions: [
|
|
93
|
+
createFrameToolToolbarContribution(),
|
|
94
|
+
createFrameDefaultStyleToolbarContribution(),
|
|
95
|
+
createFrameSelectionToolbarContribution(),
|
|
96
|
+
createFrameChildOrderToolbarContribution(),
|
|
97
|
+
],
|
|
98
|
+
contextMenuContributions: [createFrameChildOrderContextMenuContribution()],
|
|
99
|
+
setup(editor) {
|
|
100
|
+
editor.tools.register(
|
|
101
|
+
"frame",
|
|
102
|
+
(currentEditor) => new FrameTool(currentEditor),
|
|
103
|
+
{ shortcut: "f" },
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function createFrameChildOrderContextMenuContribution(): ContextMenuContribution {
|
|
110
|
+
return {
|
|
111
|
+
id: "frame.child-order.context-menu",
|
|
112
|
+
target: "selection",
|
|
113
|
+
order: 40,
|
|
114
|
+
actionIds: ["frame.child-order.backward", "frame.child-order.forward"],
|
|
115
|
+
when(context) {
|
|
116
|
+
return getSelectedParentType(context) === "frame";
|
|
117
|
+
},
|
|
118
|
+
getSections(context) {
|
|
119
|
+
const state = context.editor.getSelectionSiblingOrderState();
|
|
120
|
+
return [
|
|
121
|
+
{
|
|
122
|
+
id: "frame.child-order-context-menu",
|
|
123
|
+
title: "Frame child",
|
|
124
|
+
items: [
|
|
125
|
+
...(state
|
|
126
|
+
? [
|
|
127
|
+
{
|
|
128
|
+
kind: "badge" as const,
|
|
129
|
+
id: "frame.child-order-status",
|
|
130
|
+
label: `${state.index + 1} / ${state.count}`,
|
|
131
|
+
dataUi: "context-menu-frame-child-order-status",
|
|
132
|
+
},
|
|
133
|
+
]
|
|
134
|
+
: []),
|
|
135
|
+
{
|
|
136
|
+
kind: "command",
|
|
137
|
+
id: "frame.child-order.forward",
|
|
138
|
+
actionId: "frame.child-order.forward",
|
|
139
|
+
label: "Bring forward",
|
|
140
|
+
icon: "move-up",
|
|
141
|
+
dataUi: "context-menu-frame-child-bring-forward-button",
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
kind: "command",
|
|
145
|
+
id: "frame.child-order.backward",
|
|
146
|
+
actionId: "frame.child-order.backward",
|
|
147
|
+
label: "Send backward",
|
|
148
|
+
icon: "move-down",
|
|
149
|
+
dataUi: "context-menu-frame-child-send-backward-button",
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const FRAME_FILL_SWATCHES = [
|
|
159
|
+
{ value: "transparent", label: "None", color: "transparent" },
|
|
160
|
+
{ value: "#eff6ff", label: "Blue", color: "#eff6ff" },
|
|
161
|
+
{ value: "#f0fdf4", label: "Green", color: "#f0fdf4" },
|
|
162
|
+
{ value: "#fff7ed", label: "Amber", color: "#fff7ed" },
|
|
163
|
+
] as const;
|
|
164
|
+
|
|
165
|
+
const FRAME_STROKE_SWATCHES = [
|
|
166
|
+
{ value: "#94a3b8", label: "Slate", color: "#94a3b8" },
|
|
167
|
+
{ value: "#2563eb", label: "Blue", color: "#2563eb" },
|
|
168
|
+
{ value: "#16a34a", label: "Green", color: "#16a34a" },
|
|
169
|
+
{ value: "#ea580c", label: "Orange", color: "#ea580c" },
|
|
170
|
+
] as const;
|
|
171
|
+
|
|
172
|
+
const FRAME_STROKE_WIDTH_OPTIONS = [
|
|
173
|
+
{ value: 1, label: "1" },
|
|
174
|
+
{ value: 2, label: "2" },
|
|
175
|
+
{ value: 4, label: "4" },
|
|
176
|
+
] as const;
|
|
177
|
+
|
|
178
|
+
function createFrameToolToolbarContribution(): ToolbarContribution {
|
|
179
|
+
return {
|
|
180
|
+
id: "frame.tool-toolbar",
|
|
181
|
+
surface: "tool",
|
|
182
|
+
placement: "chrome",
|
|
183
|
+
order: 60,
|
|
184
|
+
actionIds: [SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID],
|
|
185
|
+
getGroups() {
|
|
186
|
+
return [
|
|
187
|
+
{
|
|
188
|
+
id: "frame.tools",
|
|
189
|
+
items: [
|
|
190
|
+
{
|
|
191
|
+
kind: "button",
|
|
192
|
+
id: "frame.tool.frame",
|
|
193
|
+
actionId: SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
|
|
194
|
+
value: "frame",
|
|
195
|
+
label: "Frame",
|
|
196
|
+
shortcut: "F",
|
|
197
|
+
icon: "square",
|
|
198
|
+
dataUi: "frame-tool-button",
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
];
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function createSetFrameStyleToolbarAction(
|
|
208
|
+
prop: "fill" | "stroke" | "strokeWidth",
|
|
209
|
+
): ToolbarAction<ToolbarActionValue> {
|
|
210
|
+
return {
|
|
211
|
+
id: `frame.set-${prop}`,
|
|
212
|
+
isVisible(context) {
|
|
213
|
+
return context.selection.commonShapeType === "frame";
|
|
214
|
+
},
|
|
215
|
+
isEnabled(context) {
|
|
216
|
+
return context.selection.count > 0;
|
|
217
|
+
},
|
|
218
|
+
getValue(context) {
|
|
219
|
+
return getCommonFramePropValue(context.selection.selectedShapes, prop);
|
|
220
|
+
},
|
|
221
|
+
run({ context, value }) {
|
|
222
|
+
if (!isValidFrameStyleValue(prop, value)) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const updates = context.selection.selectedShapes
|
|
226
|
+
.filter((shape): shape is FrameShapeRecord => shape.type === "frame")
|
|
227
|
+
.filter((shape) => !shape.isLocked)
|
|
228
|
+
.map((shape) => ({
|
|
229
|
+
id: shape.id,
|
|
230
|
+
props: {
|
|
231
|
+
[prop]: value,
|
|
232
|
+
},
|
|
233
|
+
}));
|
|
234
|
+
if (updates.length === 0) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
context.editor.commands.updateShapes(updates, { source: "user" });
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function createSetFrameDefaultStyleToolbarAction(
|
|
243
|
+
prop: "fill" | "stroke" | "strokeWidth",
|
|
244
|
+
): ToolbarAction<ToolbarActionValue> {
|
|
245
|
+
return {
|
|
246
|
+
id: `frame.default-${prop}`,
|
|
247
|
+
isVisible(context) {
|
|
248
|
+
return context.tool.activeToolId === "frame";
|
|
249
|
+
},
|
|
250
|
+
getValue(context) {
|
|
251
|
+
return context.editor.getDefaultShapeProps<FrameShapeProps>("frame")[prop];
|
|
252
|
+
},
|
|
253
|
+
run({ context, value }) {
|
|
254
|
+
if (!isValidFrameStyleValue(prop, value)) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
context.editor.updateDefaultShapeProps("frame", { [prop]: value });
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function createRenameFrameToolbarAction(): ToolbarAction<string | null> {
|
|
263
|
+
return {
|
|
264
|
+
id: "frame.rename",
|
|
265
|
+
isVisible(context) {
|
|
266
|
+
return (
|
|
267
|
+
context.selection.count === 1 &&
|
|
268
|
+
context.selection.singleShapeType === "frame"
|
|
269
|
+
);
|
|
270
|
+
},
|
|
271
|
+
isEnabled(context) {
|
|
272
|
+
const [shape] = context.selection.selectedShapes;
|
|
273
|
+
return shape?.type === "frame" && !shape.isLocked;
|
|
274
|
+
},
|
|
275
|
+
getValue(context) {
|
|
276
|
+
const [shape] = context.selection.selectedShapes;
|
|
277
|
+
return shape?.type === "frame"
|
|
278
|
+
? (shape.props as FrameShapeProps).name
|
|
279
|
+
: null;
|
|
280
|
+
},
|
|
281
|
+
run({ context, value }) {
|
|
282
|
+
const [shape] = context.selection.selectedShapes;
|
|
283
|
+
if (shape?.type !== "frame" || typeof value !== "string") {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
context.editor.commands.updateShapes(
|
|
287
|
+
[
|
|
288
|
+
{
|
|
289
|
+
id: shape.id,
|
|
290
|
+
props: { name: value },
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
{ source: "user" },
|
|
294
|
+
);
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function createFrameDefaultStyleToolbarContribution(): ToolbarContribution {
|
|
300
|
+
return {
|
|
301
|
+
id: "frame.default-style.tool-toolbar",
|
|
302
|
+
surface: "tool",
|
|
303
|
+
order: 61,
|
|
304
|
+
actionIds: [
|
|
305
|
+
"frame.default-fill",
|
|
306
|
+
"frame.default-stroke",
|
|
307
|
+
"frame.default-strokeWidth",
|
|
308
|
+
],
|
|
309
|
+
when(context) {
|
|
310
|
+
return context.tool.activeToolId === "frame";
|
|
311
|
+
},
|
|
312
|
+
getGroups() {
|
|
313
|
+
return getFrameStyleToolbarGroups({
|
|
314
|
+
fillActionId: "frame.default-fill",
|
|
315
|
+
strokeActionId: "frame.default-stroke",
|
|
316
|
+
strokeWidthActionId: "frame.default-strokeWidth",
|
|
317
|
+
dataUiPrefix: "frame-default",
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function createFrameSelectionToolbarContribution(): ToolbarContribution {
|
|
324
|
+
return {
|
|
325
|
+
id: "frame.selection-toolbar",
|
|
326
|
+
surface: "selection",
|
|
327
|
+
order: 20,
|
|
328
|
+
actionIds: [
|
|
329
|
+
"frame.set-fill",
|
|
330
|
+
"frame.set-stroke",
|
|
331
|
+
"frame.set-strokeWidth",
|
|
332
|
+
"frame.rename",
|
|
333
|
+
],
|
|
334
|
+
when(context) {
|
|
335
|
+
return context.selection.commonShapeType === "frame";
|
|
336
|
+
},
|
|
337
|
+
getGroups(context) {
|
|
338
|
+
return [
|
|
339
|
+
...(context.selection.count === 1
|
|
340
|
+
? [
|
|
341
|
+
{
|
|
342
|
+
id: "frame.name",
|
|
343
|
+
items: [
|
|
344
|
+
{
|
|
345
|
+
kind: "text-input" as const,
|
|
346
|
+
id: "frame.name",
|
|
347
|
+
actionId: "frame.rename",
|
|
348
|
+
label: "Frame name",
|
|
349
|
+
placeholder: "Frame",
|
|
350
|
+
dataUi: "frame-name-input",
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
},
|
|
354
|
+
]
|
|
355
|
+
: []),
|
|
356
|
+
...getFrameStyleToolbarGroups({
|
|
357
|
+
fillActionId: "frame.set-fill",
|
|
358
|
+
strokeActionId: "frame.set-stroke",
|
|
359
|
+
strokeWidthActionId: "frame.set-strokeWidth",
|
|
360
|
+
dataUiPrefix: "frame",
|
|
361
|
+
}),
|
|
362
|
+
];
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function getFrameStyleToolbarGroups({
|
|
368
|
+
fillActionId,
|
|
369
|
+
strokeActionId,
|
|
370
|
+
strokeWidthActionId,
|
|
371
|
+
dataUiPrefix,
|
|
372
|
+
}: {
|
|
373
|
+
fillActionId: string;
|
|
374
|
+
strokeActionId: string;
|
|
375
|
+
strokeWidthActionId: string;
|
|
376
|
+
dataUiPrefix: string;
|
|
377
|
+
}) {
|
|
378
|
+
return [
|
|
379
|
+
{
|
|
380
|
+
id: `${dataUiPrefix}.style-fill`,
|
|
381
|
+
items: [
|
|
382
|
+
{
|
|
383
|
+
kind: "swatches" as const,
|
|
384
|
+
id: `${dataUiPrefix}.fill`,
|
|
385
|
+
actionId: fillActionId,
|
|
386
|
+
label: "Fill",
|
|
387
|
+
options: FRAME_FILL_SWATCHES.map((option) => ({
|
|
388
|
+
...option,
|
|
389
|
+
dataUi: `${dataUiPrefix}-fill-${option.label.toLowerCase()}-button`,
|
|
390
|
+
})),
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
id: `${dataUiPrefix}.style-stroke`,
|
|
396
|
+
items: [
|
|
397
|
+
{
|
|
398
|
+
kind: "swatches" as const,
|
|
399
|
+
id: `${dataUiPrefix}.stroke`,
|
|
400
|
+
actionId: strokeActionId,
|
|
401
|
+
label: "Stroke",
|
|
402
|
+
options: FRAME_STROKE_SWATCHES.map((option) => ({
|
|
403
|
+
...option,
|
|
404
|
+
dataUi: `${dataUiPrefix}-stroke-${option.label.toLowerCase()}-button`,
|
|
405
|
+
})),
|
|
406
|
+
},
|
|
407
|
+
],
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
id: `${dataUiPrefix}.style-stroke-width`,
|
|
411
|
+
items: [
|
|
412
|
+
{
|
|
413
|
+
kind: "stepper" as const,
|
|
414
|
+
id: `${dataUiPrefix}.stroke-width`,
|
|
415
|
+
actionId: strokeWidthActionId,
|
|
416
|
+
label: "Stroke width",
|
|
417
|
+
dataUi: `${dataUiPrefix}-stroke-width-control`,
|
|
418
|
+
options: FRAME_STROKE_WIDTH_OPTIONS.map((option) => ({
|
|
419
|
+
...option,
|
|
420
|
+
dataUi: `${dataUiPrefix}-stroke-width-${option.value}-button`,
|
|
421
|
+
})),
|
|
422
|
+
},
|
|
423
|
+
],
|
|
424
|
+
},
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function createFrameChildMoveToolbarAction(
|
|
429
|
+
direction: "backward" | "forward",
|
|
430
|
+
): ToolbarAction<null> {
|
|
431
|
+
return {
|
|
432
|
+
id: `frame.child-order.${direction}`,
|
|
433
|
+
isVisible(context) {
|
|
434
|
+
return getSelectedParentType(context) === "frame";
|
|
435
|
+
},
|
|
436
|
+
isEnabled(context) {
|
|
437
|
+
return context.editor.canMoveSelectionWithinParent(direction);
|
|
438
|
+
},
|
|
439
|
+
run({ context }) {
|
|
440
|
+
context.editor.moveSelectionWithinParent(direction, "user");
|
|
441
|
+
},
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function createFrameChildOrderToolbarContribution(): ToolbarContribution {
|
|
446
|
+
return {
|
|
447
|
+
id: "frame.child-order.selection-toolbar",
|
|
448
|
+
surface: "selection",
|
|
449
|
+
order: 30,
|
|
450
|
+
actionIds: ["frame.child-order.backward", "frame.child-order.forward"],
|
|
451
|
+
when(context) {
|
|
452
|
+
return getSelectedParentType(context) === "frame";
|
|
453
|
+
},
|
|
454
|
+
getGroups(context) {
|
|
455
|
+
const state = context.editor.getSelectionSiblingOrderState();
|
|
456
|
+
return [
|
|
457
|
+
{
|
|
458
|
+
id: "frame.child-order",
|
|
459
|
+
items: [
|
|
460
|
+
...(state
|
|
461
|
+
? [
|
|
462
|
+
{
|
|
463
|
+
kind: "badge" as const,
|
|
464
|
+
id: "frame.child-order-status",
|
|
465
|
+
label: `${state.index + 1} / ${state.count}`,
|
|
466
|
+
dataUi: "frame-child-order-status",
|
|
467
|
+
},
|
|
468
|
+
]
|
|
469
|
+
: []),
|
|
470
|
+
{
|
|
471
|
+
kind: "button",
|
|
472
|
+
id: "frame.child-order.backward",
|
|
473
|
+
actionId: "frame.child-order.backward",
|
|
474
|
+
label: "Send backward",
|
|
475
|
+
icon: "move-down",
|
|
476
|
+
dataUi: "frame-child-send-backward-button",
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
kind: "button",
|
|
480
|
+
id: "frame.child-order.forward",
|
|
481
|
+
actionId: "frame.child-order.forward",
|
|
482
|
+
label: "Bring forward",
|
|
483
|
+
icon: "move-up",
|
|
484
|
+
dataUi: "frame-child-bring-forward-button",
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
},
|
|
488
|
+
];
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function getCommonFramePropValue(
|
|
494
|
+
selectedShapes: readonly { type: string; props: object }[],
|
|
495
|
+
prop: "fill" | "stroke" | "strokeWidth",
|
|
496
|
+
): ToolbarActionValue {
|
|
497
|
+
let value: ToolbarActionValue | undefined;
|
|
498
|
+
for (const shape of selectedShapes) {
|
|
499
|
+
if (shape.type !== "frame") {
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const nextValue = (shape.props as FrameShapeProps)[prop];
|
|
503
|
+
if (value === undefined) {
|
|
504
|
+
value = nextValue;
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (value !== nextValue) {
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return value ?? null;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function isValidFrameStyleValue(
|
|
515
|
+
prop: "fill" | "stroke" | "strokeWidth",
|
|
516
|
+
value: ToolbarActionValue,
|
|
517
|
+
): boolean {
|
|
518
|
+
if (prop === "strokeWidth") {
|
|
519
|
+
return FRAME_STROKE_WIDTH_OPTIONS.some((option) => option.value === value);
|
|
520
|
+
}
|
|
521
|
+
const swatches =
|
|
522
|
+
prop === "fill" ? FRAME_FILL_SWATCHES : FRAME_STROKE_SWATCHES;
|
|
523
|
+
return swatches.some((option) => option.value === value);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function getSelectedParentType(
|
|
527
|
+
context: Parameters<NonNullable<ToolbarContribution["when"]>>[0],
|
|
528
|
+
): string | null {
|
|
529
|
+
const [shape] = context.selection.selectedShapes;
|
|
530
|
+
if (context.selection.count !== 1 || !shape?.parentId.startsWith("shape:")) {
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
return context.editor.getShape(shape.parentId as ShapeId)?.type ?? null;
|
|
534
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineLandExtension,
|
|
3
|
+
type LandFeatureBundle,
|
|
4
|
+
} from "@land/canvas-plugin-api";
|
|
5
|
+
import { createFrameCanvasPlugin } from "./canvas";
|
|
6
|
+
import { createFrameCorePlugin } from "./core";
|
|
7
|
+
|
|
8
|
+
export function createFrameFeatureBundle(): LandFeatureBundle {
|
|
9
|
+
return {
|
|
10
|
+
id: "land.frame.bundle",
|
|
11
|
+
corePlugins: [createFrameCorePlugin()],
|
|
12
|
+
canvasPlugins: [createFrameCanvasPlugin()],
|
|
13
|
+
shapeTypes: ["frame"],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Frame = defineLandExtension({
|
|
18
|
+
name: "frame",
|
|
19
|
+
createFeature: createFrameFeatureBundle,
|
|
20
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { FrameShapeUtil } from "./FrameShapeUtil";
|
|
2
|
+
export type { FrameShapeProps, FrameShapeRecord } from "./FrameShapeUtil";
|
|
3
|
+
export { FrameTool } from "./FrameTool";
|
|
4
|
+
export { FrameShapeSvgExporter, createFrameCorePlugin } from "./core";
|
|
5
|
+
export { createFrameCanvasPlugin } from "./canvas";
|
|
6
|
+
export { Frame, createFrameFeatureBundle } from "./feature";
|