@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,59 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LandCanvasPlugin,
|
|
3
|
+
ShapeRendererProps,
|
|
4
|
+
} from "@land/canvas-plugin-api";
|
|
5
|
+
import type { GroupShapeRecord } from "./GroupShapeUtil";
|
|
6
|
+
|
|
7
|
+
interface GroupShapeSvgProps {
|
|
8
|
+
shape: GroupShapeRecord;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function createGroupCanvasPlugin(): LandCanvasPlugin {
|
|
12
|
+
return {
|
|
13
|
+
id: "land.group.react",
|
|
14
|
+
setup(registerShapeRenderer) {
|
|
15
|
+
registerShapeRenderer({
|
|
16
|
+
type: "group",
|
|
17
|
+
component: GroupShapeRenderer,
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function GroupShapeRenderer({
|
|
24
|
+
shape,
|
|
25
|
+
isSelected,
|
|
26
|
+
}: ShapeRendererProps<GroupShapeRecord>) {
|
|
27
|
+
return <GroupShapeSvg shape={shape} isSelected={isSelected} />;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function GroupShapeSvg({
|
|
31
|
+
shape,
|
|
32
|
+
isSelected = false,
|
|
33
|
+
}: GroupShapeSvgProps & { isSelected?: boolean }) {
|
|
34
|
+
const { h, w } = shape.props;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<svg
|
|
38
|
+
width="100%"
|
|
39
|
+
height="100%"
|
|
40
|
+
viewBox={`0 0 ${w} ${h}`}
|
|
41
|
+
style={{ display: "block", overflow: "visible" }}
|
|
42
|
+
shapeRendering="geometricPrecision"
|
|
43
|
+
>
|
|
44
|
+
{isSelected ? (
|
|
45
|
+
<rect
|
|
46
|
+
x={0.5}
|
|
47
|
+
y={0.5}
|
|
48
|
+
width={Math.max(w - 1, 0)}
|
|
49
|
+
height={Math.max(h - 1, 0)}
|
|
50
|
+
fill="none"
|
|
51
|
+
stroke="#64748b"
|
|
52
|
+
strokeDasharray="4 4"
|
|
53
|
+
strokeWidth={1}
|
|
54
|
+
vectorEffect="non-scaling-stroke"
|
|
55
|
+
/>
|
|
56
|
+
) : null}
|
|
57
|
+
</svg>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type LandCorePlugin,
|
|
3
|
+
type ShapeSvgExporter,
|
|
4
|
+
type SvgNode,
|
|
5
|
+
} from "@land/canvas-core";
|
|
6
|
+
import {
|
|
7
|
+
GroupShapeUtil,
|
|
8
|
+
type GroupShapeRecord,
|
|
9
|
+
} from "./GroupShapeUtil";
|
|
10
|
+
|
|
11
|
+
export class GroupShapeSvgExporter
|
|
12
|
+
implements ShapeSvgExporter<GroupShapeRecord>
|
|
13
|
+
{
|
|
14
|
+
readonly type = "group" as const;
|
|
15
|
+
|
|
16
|
+
toSvg(_shape: GroupShapeRecord): SvgNode {
|
|
17
|
+
return {
|
|
18
|
+
tag: "g",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createGroupCorePlugin(): LandCorePlugin {
|
|
24
|
+
return {
|
|
25
|
+
id: "land.group",
|
|
26
|
+
shapeCapabilities: [
|
|
27
|
+
{
|
|
28
|
+
type: "group",
|
|
29
|
+
schemaProps: ["w", "h"],
|
|
30
|
+
reactRenderer: "supported",
|
|
31
|
+
toolbarEntry: "supported",
|
|
32
|
+
notes: [
|
|
33
|
+
"Group is a transparent parent shape. The editor core handles group/ungroup commands, descendant-aware selection transforms, group hit selection bubbling, selected-group child hit selection, descendant export traversal, and child movement through existing parentId queries.",
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
shapeUtils: [new GroupShapeUtil()],
|
|
38
|
+
shapeSvgExporters: [new GroupShapeSvgExporter()],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineLandExtension,
|
|
3
|
+
type LandFeatureBundle,
|
|
4
|
+
} from "@land/canvas-plugin-api";
|
|
5
|
+
import { createGroupCanvasPlugin } from "./canvas";
|
|
6
|
+
import { createGroupCorePlugin } from "./core";
|
|
7
|
+
|
|
8
|
+
export function createGroupFeatureBundle(): LandFeatureBundle {
|
|
9
|
+
return {
|
|
10
|
+
id: "land.group.bundle",
|
|
11
|
+
corePlugins: [createGroupCorePlugin()],
|
|
12
|
+
canvasPlugins: [createGroupCanvasPlugin()],
|
|
13
|
+
shapeTypes: ["group"],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Group = defineLandExtension({
|
|
18
|
+
name: "group",
|
|
19
|
+
createFeature: createGroupFeatureBundle,
|
|
20
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GroupShapeUtil } from "./GroupShapeUtil";
|
|
2
|
+
export type { GroupShapeProps, GroupShapeRecord } from "./GroupShapeUtil";
|
|
3
|
+
export { GroupShapeSvgExporter, createGroupCorePlugin } from "./core";
|
|
4
|
+
export { createGroupCanvasPlugin } from "./canvas";
|
|
5
|
+
export { Group, createGroupFeatureBundle } from "./feature";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
ShapeUtil,
|
|
4
|
+
type AssetId,
|
|
5
|
+
type ShapeSelectionHandleAnchorInput,
|
|
6
|
+
type ShapeSelectionHandleAnchors,
|
|
7
|
+
} from "@land/canvas-core";
|
|
8
|
+
import {
|
|
9
|
+
getImageCropHandleAnchors,
|
|
10
|
+
isImageCropModeForShape,
|
|
11
|
+
normalizeImageShapeCrop,
|
|
12
|
+
} from "./crop";
|
|
13
|
+
import type { ImageShapeProps, ImageShapeRecord } from "./types";
|
|
14
|
+
|
|
15
|
+
function clampNumber(value: unknown, fallback: number): number {
|
|
16
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isAssetId(value: unknown): value is AssetId {
|
|
20
|
+
return typeof value === "string" && value.startsWith("asset:");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class ImageShapeUtil extends ShapeUtil<ImageShapeRecord> {
|
|
24
|
+
readonly type = "image" as const;
|
|
25
|
+
|
|
26
|
+
getDefaultProps(): ImageShapeProps {
|
|
27
|
+
return {
|
|
28
|
+
w: 240,
|
|
29
|
+
h: 180,
|
|
30
|
+
assetId: null,
|
|
31
|
+
crop: null,
|
|
32
|
+
altText: "",
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
validateProps(props: unknown): ImageShapeProps {
|
|
37
|
+
const candidate =
|
|
38
|
+
props && typeof props === "object"
|
|
39
|
+
? (props as Partial<ImageShapeProps>)
|
|
40
|
+
: {};
|
|
41
|
+
const fallback = this.getDefaultProps();
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
w: Math.max(24, clampNumber(candidate.w, fallback.w)),
|
|
45
|
+
h: Math.max(24, clampNumber(candidate.h, fallback.h)),
|
|
46
|
+
assetId: isAssetId(candidate.assetId) ? candidate.assetId : null,
|
|
47
|
+
crop: normalizeImageShapeCrop(candidate.crop),
|
|
48
|
+
altText:
|
|
49
|
+
typeof candidate.altText === "string"
|
|
50
|
+
? candidate.altText
|
|
51
|
+
: fallback.altText,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getBounds(shape: ImageShapeRecord): Box {
|
|
56
|
+
return new Box(shape.x, shape.y, shape.props.w, shape.props.h);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
canEdit(_shape: ImageShapeRecord): boolean {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getSelectionHandleAnchors(
|
|
64
|
+
shape: ImageShapeRecord,
|
|
65
|
+
input: ShapeSelectionHandleAnchorInput,
|
|
66
|
+
): ShapeSelectionHandleAnchors {
|
|
67
|
+
const empty = {
|
|
68
|
+
terminalHandleAnchors: [],
|
|
69
|
+
middleHandleAnchors: [],
|
|
70
|
+
customHandleAnchors: [],
|
|
71
|
+
};
|
|
72
|
+
if (!input.isOnlySelected) {
|
|
73
|
+
return empty;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const session = input.editor.getShapeEditingSession();
|
|
77
|
+
if (
|
|
78
|
+
!session ||
|
|
79
|
+
session.shapeId !== shape.id ||
|
|
80
|
+
!isImageCropModeForShape(shape, session.markId)
|
|
81
|
+
) {
|
|
82
|
+
return empty;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
terminalHandleAnchors: [],
|
|
87
|
+
middleHandleAnchors: [],
|
|
88
|
+
customHandleAnchors: getImageCropHandleAnchors({
|
|
89
|
+
crop: shape.props.crop,
|
|
90
|
+
localToPage: input.editor.computeShapeLocalToPageTransform(shape),
|
|
91
|
+
shape,
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
import type {
|
|
3
|
+
CanvasDomEventGuard,
|
|
4
|
+
LandCanvasPlugin,
|
|
5
|
+
ShapeRendererProps,
|
|
6
|
+
} from "@land/canvas-plugin-api";
|
|
7
|
+
import { Vec } from "@land/canvas-core";
|
|
8
|
+
import {
|
|
9
|
+
getImageCropPlacement,
|
|
10
|
+
isImageCropModeForShape,
|
|
11
|
+
} from "./crop";
|
|
12
|
+
import { isImageShapeRecord, type ImageShapeRecord } from "./types";
|
|
13
|
+
|
|
14
|
+
const imageCropDomEventGuard: CanvasDomEventGuard = {
|
|
15
|
+
id: "land.image.crop.dom-events",
|
|
16
|
+
handle() {
|
|
17
|
+
return "continue";
|
|
18
|
+
},
|
|
19
|
+
getCursor({ clientPoint, editor, element, container }) {
|
|
20
|
+
const shape = getActiveImageCropShape(editor);
|
|
21
|
+
if (!shape) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (element?.closest('[data-selection-custom-handle-type="image.crop"]')) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!clientPoint) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const rect = container.getBoundingClientRect();
|
|
34
|
+
const screenPoint = new Vec(
|
|
35
|
+
clientPoint.x - rect.left,
|
|
36
|
+
clientPoint.y - rect.top,
|
|
37
|
+
);
|
|
38
|
+
const pagePoint = editor.screenToPage(screenPoint);
|
|
39
|
+
if (!isPointInsideImageShape(editor, shape, pagePoint)) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return editor.inputs.state.get().buttons !== 0 ? "grabbing" : "grab";
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function createImageCanvasPlugin(): LandCanvasPlugin {
|
|
48
|
+
return {
|
|
49
|
+
id: "land.image.react",
|
|
50
|
+
domEventGuards: [imageCropDomEventGuard],
|
|
51
|
+
setup(registerShapeRenderer) {
|
|
52
|
+
registerShapeRenderer({
|
|
53
|
+
type: "image",
|
|
54
|
+
component: ImageShapeRenderer,
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function ImageShapeRenderer({
|
|
61
|
+
editor,
|
|
62
|
+
shape,
|
|
63
|
+
shapeEditingSession,
|
|
64
|
+
}: ShapeRendererProps<ImageShapeRecord>) {
|
|
65
|
+
const { altText, assetId, crop, h, w } = shape.props;
|
|
66
|
+
const src = assetId ? editor.resolveAssetUrl(assetId) : null;
|
|
67
|
+
|
|
68
|
+
if (!src) {
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
data-ui="image-shape-missing-asset"
|
|
72
|
+
style={{
|
|
73
|
+
alignItems: "center",
|
|
74
|
+
background: "#f1f5f9",
|
|
75
|
+
border: "1px solid #cbd5e1",
|
|
76
|
+
color: "#64748b",
|
|
77
|
+
display: "flex",
|
|
78
|
+
fontFamily:
|
|
79
|
+
"Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
|
|
80
|
+
fontSize: 12,
|
|
81
|
+
height: h,
|
|
82
|
+
justifyContent: "center",
|
|
83
|
+
overflow: "hidden",
|
|
84
|
+
width: w,
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
Missing image
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const cropPlacement = getImageCropPlacement({
|
|
93
|
+
crop,
|
|
94
|
+
shapeHeight: h,
|
|
95
|
+
shapeWidth: w,
|
|
96
|
+
});
|
|
97
|
+
if (cropPlacement) {
|
|
98
|
+
const isCropMode =
|
|
99
|
+
shapeEditingSession?.shapeId === shape.id &&
|
|
100
|
+
isImageCropModeForShape(shape, shapeEditingSession.markId);
|
|
101
|
+
const cropImageStyle = {
|
|
102
|
+
display: "block",
|
|
103
|
+
height: cropPlacement.imageHeight,
|
|
104
|
+
left: cropPlacement.imageX,
|
|
105
|
+
maxWidth: "none",
|
|
106
|
+
objectFit: "fill",
|
|
107
|
+
pointerEvents: "none",
|
|
108
|
+
position: "absolute",
|
|
109
|
+
top: cropPlacement.imageY,
|
|
110
|
+
userSelect: "none",
|
|
111
|
+
width: cropPlacement.imageWidth,
|
|
112
|
+
} satisfies CSSProperties;
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div
|
|
116
|
+
data-ui="image-shape"
|
|
117
|
+
style={{
|
|
118
|
+
display: "block",
|
|
119
|
+
height: h,
|
|
120
|
+
overflow: isCropMode ? "visible" : "hidden",
|
|
121
|
+
pointerEvents: "none",
|
|
122
|
+
position: "relative",
|
|
123
|
+
userSelect: "none",
|
|
124
|
+
width: w,
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
{isCropMode ? (
|
|
128
|
+
<img
|
|
129
|
+
alt=""
|
|
130
|
+
aria-hidden="true"
|
|
131
|
+
data-ui="image-crop-preview"
|
|
132
|
+
draggable={false}
|
|
133
|
+
src={src}
|
|
134
|
+
style={{
|
|
135
|
+
...cropImageStyle,
|
|
136
|
+
opacity: 0.1,
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
) : null}
|
|
140
|
+
<div
|
|
141
|
+
data-ui="image-crop-window"
|
|
142
|
+
style={{
|
|
143
|
+
height: h,
|
|
144
|
+
overflow: "hidden",
|
|
145
|
+
position: "absolute",
|
|
146
|
+
inset: 0,
|
|
147
|
+
width: w,
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<img
|
|
151
|
+
alt={altText}
|
|
152
|
+
draggable={false}
|
|
153
|
+
src={src}
|
|
154
|
+
style={cropImageStyle}
|
|
155
|
+
/>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<img
|
|
163
|
+
alt={altText}
|
|
164
|
+
data-ui="image-shape"
|
|
165
|
+
draggable={false}
|
|
166
|
+
src={src}
|
|
167
|
+
style={{
|
|
168
|
+
display: "block",
|
|
169
|
+
height: h,
|
|
170
|
+
objectFit: "fill",
|
|
171
|
+
pointerEvents: "none",
|
|
172
|
+
userSelect: "none",
|
|
173
|
+
width: w,
|
|
174
|
+
}}
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function getActiveImageCropShape(
|
|
180
|
+
editor: ShapeRendererProps<ImageShapeRecord>["editor"],
|
|
181
|
+
): ImageShapeRecord | null {
|
|
182
|
+
const [shape] = editor.getSelectedShapes();
|
|
183
|
+
if (!isImageShapeRecord(shape)) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const session = editor.getShapeEditingSession();
|
|
188
|
+
if (
|
|
189
|
+
!session ||
|
|
190
|
+
session.shapeId !== shape.id ||
|
|
191
|
+
!isImageCropModeForShape(shape, session.markId)
|
|
192
|
+
) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return shape;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function isPointInsideImageShape(
|
|
200
|
+
editor: ShapeRendererProps<ImageShapeRecord>["editor"],
|
|
201
|
+
shape: ImageShapeRecord,
|
|
202
|
+
pagePoint: Vec,
|
|
203
|
+
): boolean {
|
|
204
|
+
const pageToLocal = editor.computeShapeLocalToPageTransform(shape).invert();
|
|
205
|
+
const localPoint = pageToLocal.applyToPoint(pagePoint);
|
|
206
|
+
return (
|
|
207
|
+
localPoint.x >= 0 &&
|
|
208
|
+
localPoint.y >= 0 &&
|
|
209
|
+
localPoint.x <= shape.props.w &&
|
|
210
|
+
localPoint.y <= shape.props.h
|
|
211
|
+
);
|
|
212
|
+
}
|