@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.
Files changed (263) hide show
  1. package/README.md +145 -0
  2. package/_vendor/canvas-core/bindings/BindingUtil.ts +92 -0
  3. package/_vendor/canvas-core/bindings/BindingUtilRegistry.ts +22 -0
  4. package/_vendor/canvas-core/bindings/arrow/arrowBindingHelpers.ts +52 -0
  5. package/_vendor/canvas-core/contextMenu.ts +85 -0
  6. package/_vendor/canvas-core/editor/Editor.ts +2614 -0
  7. package/_vendor/canvas-core/editor/HistoryManager.ts +83 -0
  8. package/_vendor/canvas-core/editor/StateNode.ts +162 -0
  9. package/_vendor/canvas-core/editor/camera.ts +6 -0
  10. package/_vendor/canvas-core/editor/clipboard.ts +478 -0
  11. package/_vendor/canvas-core/editor/commands.ts +833 -0
  12. package/_vendor/canvas-core/editor/edgeScroll.ts +37 -0
  13. package/_vendor/canvas-core/editor/editorComputedHelpers.ts +257 -0
  14. package/_vendor/canvas-core/editor/editorSelectionTransforms.ts +116 -0
  15. package/_vendor/canvas-core/editor/events.ts +93 -0
  16. package/_vendor/canvas-core/editor/index.ts +12 -0
  17. package/_vendor/canvas-core/editor/interactions.ts +101 -0
  18. package/_vendor/canvas-core/editor/internal.ts +22 -0
  19. package/_vendor/canvas-core/editor/managers/BindingManager.ts +262 -0
  20. package/_vendor/canvas-core/editor/managers/CameraManager.ts +147 -0
  21. package/_vendor/canvas-core/editor/managers/ClipboardManager.ts +32 -0
  22. package/_vendor/canvas-core/editor/managers/DocumentSnapshotManager.ts +256 -0
  23. package/_vendor/canvas-core/editor/managers/InputsManager.ts +319 -0
  24. package/_vendor/canvas-core/editor/managers/InteractionTransientManager.ts +218 -0
  25. package/_vendor/canvas-core/editor/managers/QueryManager.ts +837 -0
  26. package/_vendor/canvas-core/editor/managers/RenderWindowManager.ts +347 -0
  27. package/_vendor/canvas-core/editor/managers/SelectionLayoutManager.ts +196 -0
  28. package/_vendor/canvas-core/editor/managers/SelectionManager.ts +98 -0
  29. package/_vendor/canvas-core/editor/managers/SelectionOverlayManager.ts +308 -0
  30. package/_vendor/canvas-core/editor/managers/ShapeEditingManager.ts +226 -0
  31. package/_vendor/canvas-core/editor/managers/ShapeGeometryManager.ts +162 -0
  32. package/_vendor/canvas-core/editor/managers/ShapeHierarchyManager.ts +797 -0
  33. package/_vendor/canvas-core/editor/managers/SideEffectManager.ts +83 -0
  34. package/_vendor/canvas-core/editor/managers/SnapManager.ts +433 -0
  35. package/_vendor/canvas-core/editor/managers/SnapSnapshotBuilder.ts +430 -0
  36. package/_vendor/canvas-core/editor/managers/SpatialIndexManager.ts +354 -0
  37. package/_vendor/canvas-core/editor/managers/ToolManager.ts +81 -0
  38. package/_vendor/canvas-core/editor/managers/queryState.ts +583 -0
  39. package/_vendor/canvas-core/editor/managers/selectionGeometry.ts +287 -0
  40. package/_vendor/canvas-core/editor/managers/shapeOrder.ts +350 -0
  41. package/_vendor/canvas-core/editor/managers/shapeReparenting.ts +160 -0
  42. package/_vendor/canvas-core/editor/managers/snapCalculations.ts +412 -0
  43. package/_vendor/canvas-core/editor/managers/snapGeometry.ts +202 -0
  44. package/_vendor/canvas-core/editor/managers/snapIndicators.ts +403 -0
  45. package/_vendor/canvas-core/editor/managers/snapTypes.ts +122 -0
  46. package/_vendor/canvas-core/editor/queries/shapeTransforms.ts +171 -0
  47. package/_vendor/canvas-core/editor/renderWindow.ts +439 -0
  48. package/_vendor/canvas-core/editor/resizeGeometry.ts +654 -0
  49. package/_vendor/canvas-core/editor/selection.ts +489 -0
  50. package/_vendor/canvas-core/editor/selectionHandleInteractions.ts +43 -0
  51. package/_vendor/canvas-core/editor/selectionOverlay.ts +567 -0
  52. package/_vendor/canvas-core/exports/integrity.ts +174 -0
  53. package/_vendor/canvas-core/exports/svg.ts +494 -0
  54. package/_vendor/canvas-core/geometry/Box.ts +80 -0
  55. package/_vendor/canvas-core/geometry/Ellipse2d.ts +67 -0
  56. package/_vendor/canvas-core/geometry/Geometry2d.ts +52 -0
  57. package/_vendor/canvas-core/geometry/Mat.ts +92 -0
  58. package/_vendor/canvas-core/geometry/Polyline2d.ts +63 -0
  59. package/_vendor/canvas-core/geometry/Rectangle2d.ts +64 -0
  60. package/_vendor/canvas-core/geometry/Vec.ts +123 -0
  61. package/_vendor/canvas-core/geometry/index.ts +13 -0
  62. package/_vendor/canvas-core/geometry/segments.ts +65 -0
  63. package/_vendor/canvas-core/index.ts +391 -0
  64. package/_vendor/canvas-core/plugins/index.ts +5 -0
  65. package/_vendor/canvas-core/plugins/types.ts +53 -0
  66. package/_vendor/canvas-core/reactivity.ts +16 -0
  67. package/_vendor/canvas-core/schema/records.ts +221 -0
  68. package/_vendor/canvas-core/schema/snapshots.ts +527 -0
  69. package/_vendor/canvas-core/shapes/ShapeUtil.ts +516 -0
  70. package/_vendor/canvas-core/shapes/ShapeUtilRegistry.ts +26 -0
  71. package/_vendor/canvas-core/shapes/capabilities.ts +67 -0
  72. package/_vendor/canvas-core/shapes/types.ts +20 -0
  73. package/_vendor/canvas-core/toolbar.ts +148 -0
  74. package/_vendor/canvas-core/tools/hand/HandTool.ts +75 -0
  75. package/_vendor/canvas-core/tools/index.ts +2 -0
  76. package/_vendor/canvas-core/tools/select/SelectTool.ts +33 -0
  77. package/_vendor/canvas-core/tools/select/selectContainment.ts +104 -0
  78. package/_vendor/canvas-core/tools/select/selectToolHelpers.ts +801 -0
  79. package/_vendor/canvas-core/tools/select/states/BrushingState.ts +145 -0
  80. package/_vendor/canvas-core/tools/select/states/DraggingSelectionHandleInteractionState.ts +116 -0
  81. package/_vendor/canvas-core/tools/select/states/IdleState.ts +159 -0
  82. package/_vendor/canvas-core/tools/select/states/PointingCanvasState.ts +41 -0
  83. package/_vendor/canvas-core/tools/select/states/PointingResizeHandleState.ts +78 -0
  84. package/_vendor/canvas-core/tools/select/states/PointingRotateHandleState.ts +64 -0
  85. package/_vendor/canvas-core/tools/select/states/PointingSelectionHandleInteractionState.ts +34 -0
  86. package/_vendor/canvas-core/tools/select/states/PointingShapeState.ts +140 -0
  87. package/_vendor/canvas-core/tools/select/states/ResizingState.ts +171 -0
  88. package/_vendor/canvas-core/tools/select/states/RotatingState.ts +124 -0
  89. package/_vendor/canvas-core/tools/select/states/SelectStateNode.ts +128 -0
  90. package/_vendor/canvas-core/tools/select/states/TranslatingState.ts +139 -0
  91. package/_vendor/canvas-core/tools/select/states/index.ts +11 -0
  92. package/_vendor/canvas-plugin-api/feature.ts +204 -0
  93. package/_vendor/canvas-plugin-api/index.ts +142 -0
  94. package/_vendor/canvas-product-react/api/apiRegistry.ts +35 -0
  95. package/_vendor/canvas-product-react/api/canvasProductApi.ts +422 -0
  96. package/_vendor/canvas-product-react/api/index.ts +31 -0
  97. package/_vendor/canvas-product-react/capabilities/clipboard/clipboardService.ts +36 -0
  98. package/_vendor/canvas-product-react/capabilities/clipboard/systemClipboard.ts +245 -0
  99. package/_vendor/canvas-product-react/capabilities/context-menu/systemContextMenu.ts +396 -0
  100. package/_vendor/canvas-product-react/capabilities/context-menu/useContextMenuSurface.ts +59 -0
  101. package/_vendor/canvas-product-react/capabilities/export/useSvgExport.ts +156 -0
  102. package/_vendor/canvas-product-react/capabilities/history/useHistoryControls.ts +23 -0
  103. package/_vendor/canvas-product-react/capabilities/pages/usePageControls.ts +41 -0
  104. package/_vendor/canvas-product-react/capabilities/toolbar/systemToolbar.ts +490 -0
  105. package/_vendor/canvas-product-react/capabilities/toolbar/useToolbarSurfaces.ts +92 -0
  106. package/_vendor/canvas-product-react/capabilities/zoom/useZoomControls.ts +27 -0
  107. package/_vendor/canvas-product-react/index.ts +84 -0
  108. package/_vendor/canvas-product-react/persistence/index.ts +18 -0
  109. package/_vendor/canvas-product-react/persistence/localSnapshotPersistence.ts +294 -0
  110. package/_vendor/canvas-product-react/runtime/CanvasProductRoot.tsx +250 -0
  111. package/_vendor/canvas-product-react/runtime/productDefinition.ts +72 -0
  112. package/_vendor/canvas-product-react/runtime/productServices.ts +96 -0
  113. package/_vendor/canvas-react/components/CanvasView.tsx +796 -0
  114. package/_vendor/canvas-react/components/OverlayLayer.tsx +879 -0
  115. package/_vendor/canvas-react/components/PageSpace.tsx +34 -0
  116. package/_vendor/canvas-react/components/ShapeLayer.tsx +428 -0
  117. package/_vendor/canvas-react/components/index.ts +4 -0
  118. package/_vendor/canvas-react/hooks/useEditor.ts +11 -0
  119. package/_vendor/canvas-react/hooks/useValue.ts +14 -0
  120. package/_vendor/canvas-react/host/CanvasRendererRegistryContext.tsx +14 -0
  121. package/_vendor/canvas-react/host/contextMenuRegistry.ts +61 -0
  122. package/_vendor/canvas-react/host/domEventGuards.ts +61 -0
  123. package/_vendor/canvas-react/host/index.ts +38 -0
  124. package/_vendor/canvas-react/host/pluginHost.ts +635 -0
  125. package/_vendor/canvas-react/host/rendererRegistry.tsx +58 -0
  126. package/_vendor/canvas-react/host/toolbarRegistry.ts +100 -0
  127. package/_vendor/canvas-react/index.ts +3 -0
  128. package/_vendor/plugin-arrow/ArrowBindingUtil.ts +239 -0
  129. package/_vendor/plugin-arrow/ArrowShapeUtil.ts +311 -0
  130. package/_vendor/plugin-arrow/ArrowTool.ts +208 -0
  131. package/_vendor/plugin-arrow/arrowGeometry.ts +441 -0
  132. package/_vendor/plugin-arrow/arrowTerminalBindingResolver.ts +253 -0
  133. package/_vendor/plugin-arrow/arrowTerminalCommands.ts +230 -0
  134. package/_vendor/plugin-arrow/canvas.tsx +92 -0
  135. package/_vendor/plugin-arrow/core.ts +409 -0
  136. package/_vendor/plugin-arrow/feature.ts +20 -0
  137. package/_vendor/plugin-arrow/index.ts +28 -0
  138. package/_vendor/plugin-arrow/selectionHandleInteractions.ts +154 -0
  139. package/_vendor/plugin-arrow/types.ts +63 -0
  140. package/_vendor/plugin-draw/DrawShapeRenderer.tsx +60 -0
  141. package/_vendor/plugin-draw/DrawShapeUtil.ts +372 -0
  142. package/_vendor/plugin-draw/DrawTool.ts +444 -0
  143. package/_vendor/plugin-draw/canvas.tsx +24 -0
  144. package/_vendor/plugin-draw/core.ts +515 -0
  145. package/_vendor/plugin-draw/drawGeometry.ts +491 -0
  146. package/_vendor/plugin-draw/drawHitTest.ts +271 -0
  147. package/_vendor/plugin-draw/drawInterpolation.ts +250 -0
  148. package/_vendor/plugin-draw/drawPath.ts +550 -0
  149. package/_vendor/plugin-draw/drawSegments.ts +106 -0
  150. package/_vendor/plugin-draw/drawSelectionTransform.ts +67 -0
  151. package/_vendor/plugin-draw/drawShapeGeometry.ts +307 -0
  152. package/_vendor/plugin-draw/drawStrokeGeometry.ts +454 -0
  153. package/_vendor/plugin-draw/feature.ts +20 -0
  154. package/_vendor/plugin-draw/index.ts +31 -0
  155. package/_vendor/plugin-draw/types.ts +36 -0
  156. package/_vendor/plugin-eraser/EraserTool.ts +297 -0
  157. package/_vendor/plugin-eraser/canvas.tsx +616 -0
  158. package/_vendor/plugin-eraser/core.ts +49 -0
  159. package/_vendor/plugin-eraser/feature.ts +20 -0
  160. package/_vendor/plugin-eraser/index.ts +4 -0
  161. package/_vendor/plugin-frame/FrameShapeUtil.ts +173 -0
  162. package/_vendor/plugin-frame/FrameTool.ts +225 -0
  163. package/_vendor/plugin-frame/canvas.tsx +75 -0
  164. package/_vendor/plugin-frame/core.ts +534 -0
  165. package/_vendor/plugin-frame/feature.ts +20 -0
  166. package/_vendor/plugin-frame/index.ts +6 -0
  167. package/_vendor/plugin-geo/GeoShapeUtil.ts +463 -0
  168. package/_vendor/plugin-geo/GeoTools.ts +247 -0
  169. package/_vendor/plugin-geo/canvas.tsx +90 -0
  170. package/_vendor/plugin-geo/core.ts +495 -0
  171. package/_vendor/plugin-geo/feature.ts +20 -0
  172. package/_vendor/plugin-geo/index.ts +7 -0
  173. package/_vendor/plugin-geo/types.ts +27 -0
  174. package/_vendor/plugin-group/GroupShapeUtil.ts +59 -0
  175. package/_vendor/plugin-group/canvas.tsx +59 -0
  176. package/_vendor/plugin-group/core.ts +40 -0
  177. package/_vendor/plugin-group/feature.ts +20 -0
  178. package/_vendor/plugin-group/index.ts +5 -0
  179. package/_vendor/plugin-image/ImageShapeUtil.ts +95 -0
  180. package/_vendor/plugin-image/canvas.tsx +212 -0
  181. package/_vendor/plugin-image/core.ts +542 -0
  182. package/_vendor/plugin-image/crop.ts +770 -0
  183. package/_vendor/plugin-image/cropInteractions.ts +350 -0
  184. package/_vendor/plugin-image/cropSession.ts +38 -0
  185. package/_vendor/plugin-image/feature.ts +20 -0
  186. package/_vendor/plugin-image/index.ts +29 -0
  187. package/_vendor/plugin-image/types.ts +55 -0
  188. package/_vendor/plugin-image-product-react/ImageImportController.tsx +143 -0
  189. package/_vendor/plugin-image-product-react/imageAssetService.ts +52 -0
  190. package/_vendor/plugin-image-product-react/imageBlobStore.ts +315 -0
  191. package/_vendor/plugin-image-product-react/imageHostActions.ts +438 -0
  192. package/_vendor/plugin-image-product-react/imageProductApi.ts +88 -0
  193. package/_vendor/plugin-image-product-react/imageToolbarHostBridge.ts +48 -0
  194. package/_vendor/plugin-image-product-react/imageToolbarRuntime.ts +21 -0
  195. package/_vendor/plugin-image-product-react/index.ts +60 -0
  196. package/_vendor/plugin-image-product-react/snapshotGuards.ts +33 -0
  197. package/_vendor/plugin-image-product-react/svgImageAssetInliner.ts +54 -0
  198. package/_vendor/plugin-image-product-react/useImageImport.ts +64 -0
  199. package/_vendor/plugin-laser/LaserTool.ts +154 -0
  200. package/_vendor/plugin-laser/canvas.tsx +645 -0
  201. package/_vendor/plugin-laser/core.ts +49 -0
  202. package/_vendor/plugin-laser/feature.ts +20 -0
  203. package/_vendor/plugin-laser/index.ts +4 -0
  204. package/_vendor/plugin-text/ArrowLabelBindingUtil.ts +336 -0
  205. package/_vendor/plugin-text/GeoLabelBindingUtil.ts +391 -0
  206. package/_vendor/plugin-text/TextShapeSvgExporter.ts +101 -0
  207. package/_vendor/plugin-text/TextShapeUtil.ts +284 -0
  208. package/_vendor/plugin-text/TextTool.ts +228 -0
  209. package/_vendor/plugin-text/canvas.tsx +115 -0
  210. package/_vendor/plugin-text/core.ts +422 -0
  211. package/_vendor/plugin-text/feature.ts +20 -0
  212. package/_vendor/plugin-text/host/RichTextEditingBox.tsx +144 -0
  213. package/_vendor/plugin-text/host/RichTextToolbar.tsx +266 -0
  214. package/_vendor/plugin-text/host/TiptapTextEditor.tsx +191 -0
  215. package/_vendor/plugin-text/host/richTextRendering.tsx +49 -0
  216. package/_vendor/plugin-text/host/textDomSelection.ts +93 -0
  217. package/_vendor/plugin-text/host/textEditingBoxStyle.ts +36 -0
  218. package/_vendor/plugin-text/host/textEntryFocus.ts +307 -0
  219. package/_vendor/plugin-text/host/textFontLoader.ts +149 -0
  220. package/_vendor/plugin-text/host/textMeasurement.ts +258 -0
  221. package/_vendor/plugin-text/host/textMeasurementSync.ts +77 -0
  222. package/_vendor/plugin-text/host/textRangeSelection.ts +134 -0
  223. package/_vendor/plugin-text/host/textShapeRendererRuntime.tsx +89 -0
  224. package/_vendor/plugin-text/host/textShapeSync.ts +173 -0
  225. package/_vendor/plugin-text/host/tiptapTextEditorController.ts +148 -0
  226. package/_vendor/plugin-text/index.ts +18 -0
  227. package/_vendor/plugin-text/richTextUtils.ts +259 -0
  228. package/_vendor/plugin-text/textInteractions.ts +366 -0
  229. package/_vendor/plugin-text/textLabelHelpers.ts +235 -0
  230. package/_vendor/plugin-text/textShapeHelpers.ts +123 -0
  231. package/_vendor/plugin-text/textStyle.ts +96 -0
  232. package/_vendor/plugin-text/textTypes.ts +48 -0
  233. package/_vendor/signals/atom.ts +74 -0
  234. package/_vendor/signals/computed.ts +132 -0
  235. package/_vendor/signals/core.ts +130 -0
  236. package/_vendor/signals/effect.ts +117 -0
  237. package/_vendor/signals/index.ts +9 -0
  238. package/_vendor/signals/types.ts +17 -0
  239. package/_vendor/store/Store.ts +171 -0
  240. package/_vendor/store/diff.ts +229 -0
  241. package/_vendor/store/history.ts +177 -0
  242. package/_vendor/store/index.ts +32 -0
  243. package/_vendor/store/types.ts +37 -0
  244. package/api/canvasKitApi.d.ts +29 -0
  245. package/index.css +3 -0
  246. package/index.d.ts +16 -0
  247. package/index.mjs +1 -0
  248. package/internal-modules.d.ts +187 -0
  249. package/package.json +48 -0
  250. package/product/Shell.d.ts +19 -0
  251. package/product/chromeContext.d.ts +70 -0
  252. package/product/createCanvasKitEditor.d.ts +6 -0
  253. package/product/index.d.ts +7 -0
  254. package/product/persistence.d.ts +3 -0
  255. package/product/product.d.ts +22 -0
  256. package/product/useCanvasClipboardShortcuts.d.ts +6 -0
  257. package/product-iyBbEPIs.mjs +4 -0
  258. package/product.mjs +1 -0
  259. package/standard/extensions.d.ts +1 -0
  260. package/standard/index.d.ts +3 -0
  261. package/standard/standardApi.d.ts +91 -0
  262. package/standard-BmrxwqpJ.mjs +44 -0
  263. package/standard.mjs +1 -0
@@ -0,0 +1,90 @@
1
+ import type { LandCanvasPlugin, ShapeRendererProps } from "@land/canvas-plugin-api";
2
+ import type { GeoShapeRecord } from "./types";
3
+
4
+ interface GeoShapeSvgProps {
5
+ shape: GeoShapeRecord;
6
+ fill?: string;
7
+ stroke?: string;
8
+ strokeWidth?: number;
9
+ }
10
+
11
+ export function createGeoCanvasPlugin(): LandCanvasPlugin {
12
+ return {
13
+ id: "land.geo.react",
14
+ setup(registerShapeRenderer) {
15
+ registerShapeRenderer({
16
+ type: "geo",
17
+ component: GeoShapeRenderer,
18
+ });
19
+ },
20
+ };
21
+ }
22
+
23
+ function GeoShapeRenderer({
24
+ shape,
25
+ }: ShapeRendererProps<GeoShapeRecord>) {
26
+ return (
27
+ <GeoShapeSvg shape={shape} />
28
+ );
29
+ }
30
+
31
+ export function GeoShapeSvg({
32
+ shape,
33
+ fill = shape.props.fill,
34
+ stroke = shape.props.stroke,
35
+ strokeWidth = shape.props.strokeWidth,
36
+ }: GeoShapeSvgProps) {
37
+ const { geo } = shape.props;
38
+ const inset = strokeWidth / 2;
39
+ const width = Math.max(shape.props.w - strokeWidth, 0);
40
+ const height = Math.max(shape.props.h - strokeWidth, 0);
41
+ const rectangleRadius = Math.min(10, width * 0.12, height * 0.12);
42
+
43
+ const sharedProps = {
44
+ fill,
45
+ stroke,
46
+ strokeWidth,
47
+ strokeLinejoin: "round" as const,
48
+ strokeLinecap: "round" as const,
49
+ };
50
+
51
+ return (
52
+ <svg
53
+ width="100%"
54
+ height="100%"
55
+ viewBox={`0 0 ${shape.props.w} ${shape.props.h}`}
56
+ style={{ display: "block", overflow: "visible" }}
57
+ shapeRendering="geometricPrecision"
58
+ >
59
+ {geo === "ellipse" ? (
60
+ <ellipse
61
+ {...sharedProps}
62
+ cx={shape.props.w / 2}
63
+ cy={shape.props.h / 2}
64
+ rx={width / 2}
65
+ ry={height / 2}
66
+ />
67
+ ) : geo === "diamond" ? (
68
+ <polygon
69
+ {...sharedProps}
70
+ points={[
71
+ `${shape.props.w / 2},${inset}`,
72
+ `${shape.props.w - inset},${shape.props.h / 2}`,
73
+ `${shape.props.w / 2},${shape.props.h - inset}`,
74
+ `${inset},${shape.props.h / 2}`,
75
+ ].join(" ")}
76
+ />
77
+ ) : (
78
+ <rect
79
+ {...sharedProps}
80
+ x={inset}
81
+ y={inset}
82
+ width={width}
83
+ height={height}
84
+ rx={rectangleRadius}
85
+ ry={rectangleRadius}
86
+ />
87
+ )}
88
+ </svg>
89
+ );
90
+ }
@@ -0,0 +1,495 @@
1
+ import {
2
+ SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
3
+ type LandCorePlugin,
4
+ type ShapeRecordBase,
5
+ type ToolbarAction,
6
+ type ToolbarActionValue,
7
+ type ToolbarContribution,
8
+ type ShapeSvgExporter,
9
+ type SvgNode,
10
+ } from "@land/canvas-core";
11
+ import { DiamondTool, EllipseTool, RectangleTool } from "./GeoTools";
12
+ import { GeoShapeUtil } from "./GeoShapeUtil";
13
+ import {
14
+ isGeoShapeRecord,
15
+ type GeoShapeKind,
16
+ type GeoShapeProps,
17
+ type GeoShapeRecord,
18
+ } from "./types";
19
+
20
+ export class GeoShapeSvgExporter implements ShapeSvgExporter<GeoShapeRecord> {
21
+ readonly type = "geo" as const;
22
+
23
+ toSvg(shape: GeoShapeRecord): SvgNode {
24
+ const { geo, fill, stroke, strokeWidth, w, h } = shape.props;
25
+ const inset = strokeWidth / 2;
26
+ const width = Math.max(w - strokeWidth, 0);
27
+ const height = Math.max(h - strokeWidth, 0);
28
+ const sharedAttrs = {
29
+ fill,
30
+ stroke,
31
+ "stroke-width": strokeWidth,
32
+ "stroke-linejoin": "round",
33
+ "stroke-linecap": "round",
34
+ };
35
+
36
+ if (geo === "ellipse") {
37
+ return {
38
+ tag: "ellipse",
39
+ attrs: {
40
+ ...sharedAttrs,
41
+ cx: w / 2,
42
+ cy: h / 2,
43
+ rx: width / 2,
44
+ ry: height / 2,
45
+ },
46
+ };
47
+ }
48
+
49
+ if (geo === "diamond") {
50
+ return {
51
+ tag: "polygon",
52
+ attrs: {
53
+ ...sharedAttrs,
54
+ points: [
55
+ `${formatNumber(w / 2)},${formatNumber(inset)}`,
56
+ `${formatNumber(w - inset)},${formatNumber(h / 2)}`,
57
+ `${formatNumber(w / 2)},${formatNumber(h - inset)}`,
58
+ `${formatNumber(inset)},${formatNumber(h / 2)}`,
59
+ ].join(" "),
60
+ },
61
+ };
62
+ }
63
+
64
+ const radius = Math.min(10, width * 0.12, height * 0.12);
65
+ return {
66
+ tag: "rect",
67
+ attrs: {
68
+ ...sharedAttrs,
69
+ x: inset,
70
+ y: inset,
71
+ width,
72
+ height,
73
+ rx: radius,
74
+ ry: radius,
75
+ },
76
+ };
77
+ }
78
+ }
79
+
80
+ export function createGeoCorePlugin(): LandCorePlugin {
81
+ return {
82
+ id: "land.geo",
83
+ shapeCapabilities: [
84
+ {
85
+ type: "geo",
86
+ schemaProps: ["w", "h", "geo", "fill", "stroke", "strokeWidth"],
87
+ reactRenderer: "supported",
88
+ toolbarEntry: "supported",
89
+ notes: [
90
+ "Toolbar covers rectangle, ellipse, and diamond through geo props.",
91
+ ],
92
+ },
93
+ ],
94
+ shapeUtils: [new GeoShapeUtil()],
95
+ shapeSvgExporters: [new GeoShapeSvgExporter()],
96
+ toolbarActions: [
97
+ createSetGeoKindToolbarAction(),
98
+ createSetGeoStyleToolbarAction("fill"),
99
+ createSetGeoStyleToolbarAction("stroke"),
100
+ createSetGeoStyleToolbarAction("strokeWidth"),
101
+ createSetGeoDefaultStyleToolbarAction("fill"),
102
+ createSetGeoDefaultStyleToolbarAction("stroke"),
103
+ createSetGeoDefaultStyleToolbarAction("strokeWidth"),
104
+ ],
105
+ toolbarContributions: [
106
+ createGeoToolToolbarContribution(),
107
+ createGeoDefaultStyleToolbarContribution(),
108
+ createGeoSelectionToolbarContribution(),
109
+ ],
110
+ setup(editor) {
111
+ editor.tools.register(
112
+ "rectangle",
113
+ (currentEditor) => new RectangleTool(currentEditor),
114
+ { shortcut: "r" },
115
+ );
116
+ editor.tools.register(
117
+ "ellipse",
118
+ (currentEditor) => new EllipseTool(currentEditor),
119
+ { shortcut: "o" },
120
+ );
121
+ editor.tools.register(
122
+ "diamond",
123
+ (currentEditor) => new DiamondTool(currentEditor),
124
+ { shortcut: "d" },
125
+ );
126
+ },
127
+ };
128
+ }
129
+
130
+ const GEO_FILL_SWATCHES = [
131
+ { value: "#dbeafe", label: "Blue", color: "#dbeafe" },
132
+ { value: "#dcfce7", label: "Green", color: "#dcfce7" },
133
+ { value: "#fee2e2", label: "Red", color: "#fee2e2" },
134
+ { value: "#f8fafc", label: "White", color: "#f8fafc" },
135
+ ] as const;
136
+
137
+ const GEO_STROKE_SWATCHES = [
138
+ { value: "#1d4ed8", label: "Blue", color: "#1d4ed8" },
139
+ { value: "#15803d", label: "Green", color: "#15803d" },
140
+ { value: "#dc2626", label: "Red", color: "#dc2626" },
141
+ { value: "#334155", label: "Slate", color: "#334155" },
142
+ ] as const;
143
+
144
+ const GEO_STROKE_WIDTH_OPTIONS = [
145
+ { value: 1, label: "1" },
146
+ { value: 2, label: "2" },
147
+ { value: 4, label: "4" },
148
+ ] as const;
149
+
150
+ function createGeoToolToolbarContribution(): ToolbarContribution {
151
+ return {
152
+ id: "geo.tool-toolbar",
153
+ surface: "tool",
154
+ placement: "chrome",
155
+ order: 20,
156
+ actionIds: [SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID],
157
+ getGroups() {
158
+ return [
159
+ {
160
+ id: "geo.tools",
161
+ items: [
162
+ {
163
+ kind: "button",
164
+ id: "geo.tool.rectangle",
165
+ actionId: SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
166
+ value: "rectangle",
167
+ label: "Rectangle",
168
+ shortcut: "R",
169
+ icon: "square",
170
+ dataUi: "rectangle-tool-button",
171
+ },
172
+ {
173
+ kind: "button",
174
+ id: "geo.tool.ellipse",
175
+ actionId: SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
176
+ value: "ellipse",
177
+ label: "Ellipse",
178
+ shortcut: "O",
179
+ icon: "circle",
180
+ dataUi: "ellipse-tool-button",
181
+ },
182
+ {
183
+ kind: "button",
184
+ id: "geo.tool.diamond",
185
+ actionId: SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
186
+ value: "diamond",
187
+ label: "Diamond",
188
+ shortcut: "D",
189
+ icon: "diamond",
190
+ dataUi: "diamond-tool-button",
191
+ },
192
+ ],
193
+ },
194
+ ];
195
+ },
196
+ };
197
+ }
198
+
199
+ function createSetGeoStyleToolbarAction(
200
+ prop: "fill" | "stroke" | "strokeWidth",
201
+ ): ToolbarAction<ToolbarActionValue> {
202
+ return {
203
+ id: `geo.set-${prop}`,
204
+ isVisible(context) {
205
+ return context.selection.commonShapeType === "geo";
206
+ },
207
+ isEnabled(context) {
208
+ return context.selection.count > 0;
209
+ },
210
+ getValue(context) {
211
+ return getCommonGeoPropValue(context.selection.selectedShapes, prop);
212
+ },
213
+ run({ context, value }) {
214
+ if (!isValidGeoStyleValue(prop, value)) {
215
+ return;
216
+ }
217
+ const updates = context.selection.selectedShapes
218
+ .filter(isGeoShapeRecord)
219
+ .filter((shape) => !shape.isLocked)
220
+ .map((shape) => ({
221
+ id: shape.id,
222
+ props: {
223
+ [prop]: value,
224
+ },
225
+ }));
226
+ if (updates.length === 0) {
227
+ return;
228
+ }
229
+ context.editor.commands.updateShapes(updates, { source: "user" });
230
+ },
231
+ };
232
+ }
233
+
234
+ function createSetGeoDefaultStyleToolbarAction(
235
+ prop: "fill" | "stroke" | "strokeWidth",
236
+ ): ToolbarAction<ToolbarActionValue> {
237
+ return {
238
+ id: `geo.default-${prop}`,
239
+ isVisible(context) {
240
+ return isGeoToolActive(context.tool.activeToolId);
241
+ },
242
+ getValue(context) {
243
+ return context.editor.getDefaultShapeProps<GeoShapeProps>("geo")[prop];
244
+ },
245
+ run({ context, value }) {
246
+ if (!isValidGeoStyleValue(prop, value)) {
247
+ return;
248
+ }
249
+ context.editor.updateDefaultShapeProps("geo", { [prop]: value });
250
+ },
251
+ };
252
+ }
253
+
254
+ function createSetGeoKindToolbarAction(): ToolbarAction<GeoShapeKind | null> {
255
+ return {
256
+ id: "geo.set-kind",
257
+ isVisible(context) {
258
+ return context.selection.commonShapeType === "geo";
259
+ },
260
+ isEnabled(context) {
261
+ return context.selection.count > 0;
262
+ },
263
+ getValue(context) {
264
+ return getCommonGeoShapeKind(context.selection.selectedShapes);
265
+ },
266
+ run({ context, value }) {
267
+ if (
268
+ value !== "rectangle" &&
269
+ value !== "ellipse" &&
270
+ value !== "diamond"
271
+ ) {
272
+ return;
273
+ }
274
+ const updates = context.selection.selectedShapes
275
+ .filter(isGeoShapeRecord)
276
+ .filter((shape) => !shape.isLocked)
277
+ .map((shape) => ({
278
+ id: shape.id,
279
+ props: { geo: value },
280
+ }));
281
+ if (updates.length === 0) {
282
+ return;
283
+ }
284
+ context.editor.commands.updateShapes(updates, { source: "user" });
285
+ },
286
+ };
287
+ }
288
+
289
+ function createGeoDefaultStyleToolbarContribution(): ToolbarContribution {
290
+ return {
291
+ id: "geo.default-style.tool-toolbar",
292
+ surface: "tool",
293
+ order: 21,
294
+ actionIds: [
295
+ "geo.default-fill",
296
+ "geo.default-stroke",
297
+ "geo.default-strokeWidth",
298
+ ],
299
+ when(context) {
300
+ return isGeoToolActive(context.tool.activeToolId);
301
+ },
302
+ getGroups() {
303
+ return getGeoStyleToolbarGroups({
304
+ fillActionId: "geo.default-fill",
305
+ strokeActionId: "geo.default-stroke",
306
+ strokeWidthActionId: "geo.default-strokeWidth",
307
+ dataUiPrefix: "geo-default",
308
+ });
309
+ },
310
+ };
311
+ }
312
+
313
+ function createGeoSelectionToolbarContribution(): ToolbarContribution {
314
+ return {
315
+ id: "geo.selection-toolbar",
316
+ surface: "selection",
317
+ order: 20,
318
+ actionIds: [
319
+ "geo.set-kind",
320
+ "geo.set-fill",
321
+ "geo.set-stroke",
322
+ "geo.set-strokeWidth",
323
+ ],
324
+ when(context) {
325
+ return context.selection.commonShapeType === "geo";
326
+ },
327
+ getGroups() {
328
+ return [
329
+ {
330
+ id: "geo.shape-kind",
331
+ items: [
332
+ {
333
+ kind: "segmented",
334
+ id: "geo.shape-kind",
335
+ actionId: "geo.set-kind",
336
+ options: [
337
+ {
338
+ value: "rectangle",
339
+ label: "Rectangle",
340
+ icon: "square",
341
+ dataUi: "rectangle-shape-button",
342
+ },
343
+ {
344
+ value: "ellipse",
345
+ label: "Ellipse",
346
+ icon: "circle",
347
+ dataUi: "ellipse-shape-button",
348
+ },
349
+ {
350
+ value: "diamond",
351
+ label: "Diamond",
352
+ icon: "diamond",
353
+ dataUi: "diamond-shape-button",
354
+ },
355
+ ],
356
+ },
357
+ ],
358
+ },
359
+ ...getGeoStyleToolbarGroups({
360
+ fillActionId: "geo.set-fill",
361
+ strokeActionId: "geo.set-stroke",
362
+ strokeWidthActionId: "geo.set-strokeWidth",
363
+ dataUiPrefix: "geo",
364
+ }),
365
+ ];
366
+ },
367
+ };
368
+ }
369
+
370
+ function getGeoStyleToolbarGroups({
371
+ fillActionId,
372
+ strokeActionId,
373
+ strokeWidthActionId,
374
+ dataUiPrefix,
375
+ }: {
376
+ fillActionId: string;
377
+ strokeActionId: string;
378
+ strokeWidthActionId: string;
379
+ dataUiPrefix: string;
380
+ }) {
381
+ return [
382
+ {
383
+ id: `${dataUiPrefix}.style-fill`,
384
+ items: [
385
+ {
386
+ kind: "swatches" as const,
387
+ id: `${dataUiPrefix}.fill`,
388
+ actionId: fillActionId,
389
+ label: "Fill",
390
+ options: GEO_FILL_SWATCHES.map((option) => ({
391
+ ...option,
392
+ dataUi: `${dataUiPrefix}-fill-${option.label.toLowerCase()}-button`,
393
+ })),
394
+ },
395
+ ],
396
+ },
397
+ {
398
+ id: `${dataUiPrefix}.style-stroke`,
399
+ items: [
400
+ {
401
+ kind: "swatches" as const,
402
+ id: `${dataUiPrefix}.stroke`,
403
+ actionId: strokeActionId,
404
+ label: "Stroke",
405
+ options: GEO_STROKE_SWATCHES.map((option) => ({
406
+ ...option,
407
+ dataUi: `${dataUiPrefix}-stroke-${option.label.toLowerCase()}-button`,
408
+ })),
409
+ },
410
+ ],
411
+ },
412
+ {
413
+ id: `${dataUiPrefix}.style-stroke-width`,
414
+ items: [
415
+ {
416
+ kind: "stepper" as const,
417
+ id: `${dataUiPrefix}.stroke-width`,
418
+ actionId: strokeWidthActionId,
419
+ label: "Stroke width",
420
+ dataUi: `${dataUiPrefix}-stroke-width-control`,
421
+ options: GEO_STROKE_WIDTH_OPTIONS.map((option) => ({
422
+ ...option,
423
+ dataUi: `${dataUiPrefix}-stroke-width-${option.value}-button`,
424
+ })),
425
+ },
426
+ ],
427
+ },
428
+ ];
429
+ }
430
+
431
+ function getCommonGeoPropValue(
432
+ selectedShapes: readonly ShapeRecordBase[],
433
+ prop: "fill" | "stroke" | "strokeWidth",
434
+ ): ToolbarActionValue {
435
+ let value: ToolbarActionValue | undefined;
436
+ for (const shape of selectedShapes) {
437
+ if (shape.type !== "geo") {
438
+ continue;
439
+ }
440
+ const nextValue = (shape.props as GeoShapeProps)[prop];
441
+ if (value === undefined) {
442
+ value = nextValue;
443
+ continue;
444
+ }
445
+ if (value !== nextValue) {
446
+ return null;
447
+ }
448
+ }
449
+ return value ?? null;
450
+ }
451
+
452
+ function getCommonGeoShapeKind(
453
+ selectedShapes: readonly ShapeRecordBase[],
454
+ ): GeoShapeKind | null {
455
+ let commonKind: GeoShapeKind | null = null;
456
+ for (const shape of selectedShapes) {
457
+ if (!isGeoShapeRecord(shape)) {
458
+ continue;
459
+ }
460
+ if (commonKind === null) {
461
+ commonKind = shape.props.geo;
462
+ continue;
463
+ }
464
+ if (commonKind !== shape.props.geo) {
465
+ return null;
466
+ }
467
+ }
468
+ return commonKind;
469
+ }
470
+
471
+ function isValidGeoStyleValue(
472
+ prop: "fill" | "stroke" | "strokeWidth",
473
+ value: ToolbarActionValue,
474
+ ): boolean {
475
+ if (prop === "strokeWidth") {
476
+ return GEO_STROKE_WIDTH_OPTIONS.some((option) => option.value === value);
477
+ }
478
+ const swatches = prop === "fill" ? GEO_FILL_SWATCHES : GEO_STROKE_SWATCHES;
479
+ return swatches.some((option) => option.value === value);
480
+ }
481
+
482
+ function isGeoToolActive(activeToolId: string): boolean {
483
+ return (
484
+ activeToolId === "rectangle" ||
485
+ activeToolId === "ellipse" ||
486
+ activeToolId === "diamond"
487
+ );
488
+ }
489
+
490
+ function formatNumber(value: number): string {
491
+ if (!Number.isFinite(value)) {
492
+ return "0";
493
+ }
494
+ return Number(value.toFixed(4)).toString();
495
+ }
@@ -0,0 +1,20 @@
1
+ import {
2
+ defineLandExtension,
3
+ type LandFeatureBundle,
4
+ } from "@land/canvas-plugin-api";
5
+ import { createGeoCanvasPlugin } from "./canvas";
6
+ import { createGeoCorePlugin } from "./core";
7
+
8
+ export function createGeoFeatureBundle(): LandFeatureBundle {
9
+ return {
10
+ id: "land.geo.bundle",
11
+ corePlugins: [createGeoCorePlugin()],
12
+ canvasPlugins: [createGeoCanvasPlugin()],
13
+ shapeTypes: ["geo"],
14
+ };
15
+ }
16
+
17
+ export const Geo = defineLandExtension({
18
+ name: "geo",
19
+ createFeature: createGeoFeatureBundle,
20
+ });
@@ -0,0 +1,7 @@
1
+ export { DiamondTool, EllipseTool, RectangleTool } from "./GeoTools";
2
+ export { GeoShapeUtil } from "./GeoShapeUtil";
3
+ export { GeoShapeSvgExporter, createGeoCorePlugin } from "./core";
4
+ export { GeoShapeSvg, createGeoCanvasPlugin } from "./canvas";
5
+ export { Geo, createGeoFeatureBundle } from "./feature";
6
+ export type { GeoShapeKind, GeoShapeProps, GeoShapeRecord } from "./types";
7
+ export { isGeoShapeRecord } from "./types";
@@ -0,0 +1,27 @@
1
+ import {
2
+ isShapeRecord,
3
+ type BaseRecord,
4
+ type ShapeRecordBase,
5
+ } from "@land/canvas-core";
6
+
7
+ export type GeoShapeKind = "rectangle" | "ellipse" | "diamond";
8
+
9
+ export interface GeoShapeProps {
10
+ w: number;
11
+ h: number;
12
+ geo: GeoShapeKind;
13
+ fill: string;
14
+ stroke: string;
15
+ strokeWidth: number;
16
+ }
17
+
18
+ export interface GeoShapeRecord extends ShapeRecordBase<"geo", GeoShapeProps> {
19
+ type: "geo";
20
+ props: GeoShapeProps;
21
+ }
22
+
23
+ export function isGeoShapeRecord(
24
+ record: BaseRecord | null | undefined,
25
+ ): record is GeoShapeRecord {
26
+ return isShapeRecord(record) && record.type === "geo";
27
+ }
@@ -0,0 +1,59 @@
1
+ import {
2
+ Box,
3
+ ShapeUtil,
4
+ type Vec,
5
+ type ShapeRecordBase,
6
+ } from "@land/canvas-core";
7
+
8
+ export interface GroupShapeProps {
9
+ w: number;
10
+ h: number;
11
+ }
12
+
13
+ export type GroupShapeRecord = ShapeRecordBase<"group", GroupShapeProps>;
14
+
15
+ function clampDimension(value: unknown, fallback: number): number {
16
+ return typeof value === "number" && Number.isFinite(value)
17
+ ? Math.max(1, value)
18
+ : fallback;
19
+ }
20
+
21
+ export class GroupShapeUtil extends ShapeUtil<GroupShapeRecord> {
22
+ readonly type = "group" as const;
23
+
24
+ getDefaultProps(): GroupShapeProps {
25
+ return {
26
+ w: 1,
27
+ h: 1,
28
+ };
29
+ }
30
+
31
+ validateProps(props: unknown): GroupShapeProps {
32
+ const candidate =
33
+ props && typeof props === "object"
34
+ ? (props as Partial<GroupShapeProps>)
35
+ : {};
36
+ const fallback = this.getDefaultProps();
37
+
38
+ return {
39
+ w: clampDimension(candidate.w, fallback.w),
40
+ h: clampDimension(candidate.h, fallback.h),
41
+ };
42
+ }
43
+
44
+ getBounds(shape: GroupShapeRecord): Box {
45
+ return new Box(shape.x, shape.y, shape.props.w, shape.props.h);
46
+ }
47
+
48
+ hitTest(_shape: GroupShapeRecord, _positionedPoint: Vec): boolean {
49
+ return false;
50
+ }
51
+
52
+ shouldTransformDescendants(_shape: GroupShapeRecord): boolean {
53
+ return true;
54
+ }
55
+
56
+ canReceiveChildren(_shape: GroupShapeRecord): boolean {
57
+ return true;
58
+ }
59
+ }