mathlean-canvas 0.3.1 → 0.3.3

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 (67) hide show
  1. package/README.md +213 -68
  2. package/dist/InlineMathLiveField.d.ts +17 -0
  3. package/dist/MathCanvas/components/CanvasOverlayViewport.d.ts +21 -0
  4. package/dist/MathCanvas/components/ObjectOverlays.d.ts +36 -0
  5. package/dist/MathCanvas/components/Toolbar.d.ts +34 -0
  6. package/dist/MathCanvas/components/icons.d.ts +58 -0
  7. package/dist/MathCanvas/constants.d.ts +70 -0
  8. package/dist/MathCanvas/core/hooks/useCanvasEditorFocus.d.ts +32 -0
  9. package/dist/MathCanvas/core/hooks/useCanvasGlobalActions.d.ts +41 -0
  10. package/dist/MathCanvas/core/hooks/useCanvasGlobalDragEffects.d.ts +35 -0
  11. package/dist/MathCanvas/core/hooks/useCanvasHistory.d.ts +13 -0
  12. package/dist/MathCanvas/core/hooks/useCanvasKeyboardShortcuts.d.ts +76 -0
  13. package/dist/MathCanvas/core/hooks/useCanvasSnapshot.d.ts +23 -0
  14. package/dist/MathCanvas/core/hooks/useCanvasStageInteractions.d.ts +103 -0
  15. package/dist/MathCanvas/core/hooks/useCanvasTransformers.d.ts +28 -0
  16. package/dist/MathCanvas/core/hooks/useCanvasViewport.d.ts +25 -0
  17. package/dist/MathCanvas/core/index.d.ts +9 -0
  18. package/dist/MathCanvas/features/geometry/components/CoordinatePlaneLayer.d.ts +15 -0
  19. package/dist/MathCanvas/features/geometry/components/GeometryLayer.d.ts +65 -0
  20. package/dist/MathCanvas/features/geometry/components/GeometryOverlays.d.ts +57 -0
  21. package/dist/MathCanvas/features/geometry/hooks/useGeometryCanvasActions.d.ts +29 -0
  22. package/dist/MathCanvas/features/geometry/hooks/useGeometryRenderData.d.ts +60 -0
  23. package/dist/MathCanvas/features/geometry/hooks/useGeometryState.d.ts +147 -0
  24. package/dist/MathCanvas/features/geometry/index.d.ts +6 -0
  25. package/dist/MathCanvas/features/graph/components/GraphLayer.d.ts +39 -0
  26. package/dist/MathCanvas/features/graph/components/GraphNodeEditor.d.ts +14 -0
  27. package/dist/MathCanvas/features/graph/hooks/useGraphCanvasActions.d.ts +44 -0
  28. package/dist/MathCanvas/features/graph/hooks/useGraphState.d.ts +77 -0
  29. package/dist/MathCanvas/features/graph/index.d.ts +4 -0
  30. package/dist/MathCanvas/features/grid/components/CellMathEditor.d.ts +17 -0
  31. package/dist/MathCanvas/features/grid/components/GridObjectOverlays.d.ts +71 -0
  32. package/dist/MathCanvas/features/grid/components/MatrixBlock.d.ts +20 -0
  33. package/dist/MathCanvas/features/grid/components/MatrixBrackets.d.ts +6 -0
  34. package/dist/MathCanvas/features/grid/components/MatrixEditorBlock.d.ts +50 -0
  35. package/dist/MathCanvas/features/grid/components/MatrixLayer.d.ts +31 -0
  36. package/dist/MathCanvas/features/grid/components/TableBlock.d.ts +21 -0
  37. package/dist/MathCanvas/features/grid/components/TableEditorBlock.d.ts +46 -0
  38. package/dist/MathCanvas/features/grid/hooks/useGridCanvasActions.d.ts +66 -0
  39. package/dist/MathCanvas/features/grid/hooks/useGridObjectState.d.ts +147 -0
  40. package/dist/MathCanvas/features/grid/index.d.ts +5 -0
  41. package/dist/MathCanvas/features/grid/utils/matrixOps.d.ts +36 -0
  42. package/dist/MathCanvas/features/stroke/components/StrokeLayer.d.ts +8 -0
  43. package/dist/MathCanvas/features/stroke/hooks/useStrokeState.d.ts +33 -0
  44. package/dist/MathCanvas/features/stroke/index.d.ts +2 -0
  45. package/dist/MathCanvas/features/text/components/BlockRenderers.d.ts +24 -0
  46. package/dist/MathCanvas/features/text/components/InlineMathBubble.d.ts +36 -0
  47. package/dist/MathCanvas/features/text/components/TextBlockEditor.d.ts +46 -0
  48. package/dist/MathCanvas/features/text/components/TextBlockMenu.d.ts +25 -0
  49. package/dist/MathCanvas/features/text/components/TextBlockView.d.ts +22 -0
  50. package/dist/MathCanvas/features/text/components/TextInteractionLayer.d.ts +29 -0
  51. package/dist/MathCanvas/features/text/hooks/useTextBlockActions.d.ts +40 -0
  52. package/dist/MathCanvas/features/text/hooks/useTextBlockEditingActions.d.ts +57 -0
  53. package/dist/MathCanvas/features/text/hooks/useTextBlockLayoutEffects.d.ts +62 -0
  54. package/dist/MathCanvas/features/text/hooks/useTextBlockRenderHelpers.d.ts +15 -0
  55. package/dist/MathCanvas/features/text/hooks/useTextboxResize.d.ts +19 -0
  56. package/dist/MathCanvas/features/text/index.d.ts +12 -0
  57. package/dist/MathCanvas/features/text/utils/textLayout.d.ts +33 -0
  58. package/dist/MathCanvas/types.d.ts +219 -0
  59. package/dist/MathCanvas/utils/geometryMath.d.ts +13 -0
  60. package/dist/MathCanvas/utils/graphDirection.d.ts +3 -0
  61. package/dist/MathCanvas/utils/latex.d.ts +20 -0
  62. package/dist/MathCanvas.d.ts +7 -0
  63. package/dist/index.d.ts +3 -0
  64. package/dist/index.js +11777 -10143
  65. package/dist/inlineMathModel.d.ts +26 -0
  66. package/dist/useInlineMathSession.d.ts +67 -0
  67. package/package.json +6 -2
@@ -0,0 +1,76 @@
1
+ import { type Dispatch, type MutableRefObject, type SetStateAction } from "react";
2
+ import { PEN_SIZE_OPTIONS } from "../../constants";
3
+ import type { GeometryLabelTarget, GraphDirection, GridSelection, MatrixObject, TableObject, Tool } from "../../types";
4
+ type PenWidth = (typeof PEN_SIZE_OPTIONS)[number];
5
+ type UseCanvasKeyboardShortcutsOptions = {
6
+ cancelPendingGraphDirectionalCreate: () => void;
7
+ clearGeometryDraft: () => void;
8
+ clearGeometrySelection: () => void;
9
+ clearGridSelectionCells: () => void;
10
+ copySelectedGraphNodes: () => void;
11
+ createConnectedGraphNodeInDirection: (direction: "right") => void;
12
+ cycleSelectedGeometryObject: (direction?: 1 | -1) => void;
13
+ deleteGridSelectionStructure: () => void;
14
+ deleteSelectedGeometry: () => void;
15
+ deleteSelectedGraphEdge: () => void;
16
+ deleteSelectedGraphNode: () => void;
17
+ deleteSelectedMatrix: () => void;
18
+ deleteSelectedTable: () => void;
19
+ editingGraphNodeId: string | null;
20
+ editingMatrixId: string | null;
21
+ editingTableId: string | null;
22
+ fillIdentityMatrix: (id: string) => void;
23
+ getGridSelectionClipboardText: () => string;
24
+ getMatrixById: (id: string | null) => MatrixObject | null;
25
+ getTableById: (id: string | null) => TableObject | null;
26
+ graphCreationArrowKeysRef: MutableRefObject<Set<string>>;
27
+ graphCreationChordActiveRef: MutableRefObject<boolean>;
28
+ gridSelection: GridSelection | null;
29
+ handleRedo: () => void;
30
+ handleUndo: () => void;
31
+ insertGridSelectionStructure: () => void;
32
+ moveGridSelectionStructure: (direction: "up" | "down" | "left" | "right") => void;
33
+ nudgeSelectedGeometry: (dx: number, dy: number) => void;
34
+ nudgeSelectedGraphNode: (dx: number, dy: number) => void;
35
+ pasteGraphClipboard: () => void;
36
+ pasteGridSelectionClipboardText: (text: string) => void;
37
+ penColorOptions: readonly string[];
38
+ pushHistoryState: () => void;
39
+ resizeMatrix: (id: string, rows: number, cols: number) => void;
40
+ resizeTable: (id: string, rows: number, cols: number) => void;
41
+ rotateMatrixClockwise: (id: string) => void;
42
+ rotateMatrixCounterclockwise: (id: string) => void;
43
+ scheduleGraphDirectionalCreate: (direction: GraphDirection) => void;
44
+ selectedAngleId: string | null;
45
+ selectedCircleId: string | null;
46
+ selectedGeometryLabel: GeometryLabelTarget | null;
47
+ selectedGraphEdgeId: string | null;
48
+ selectedGraphNodeId: string | null;
49
+ selectedGraphNodeIds: string[];
50
+ selectedMatrixId: string | null;
51
+ selectedPointId: string | null;
52
+ selectedPolygonId: string | null;
53
+ selectedSegmentId: string | null;
54
+ selectedTableId: string | null;
55
+ setActiveConstructionStartPointId: (id: string | null) => void;
56
+ setArmedSourceNodeId: (id: string | null) => void;
57
+ setCurrentConstructionPathPointIds: (ids: string[]) => void;
58
+ setPenColor: Dispatch<SetStateAction<string>>;
59
+ setPenWidth: Dispatch<SetStateAction<PenWidth>>;
60
+ showPenSizePreviewBriefly: () => void;
61
+ startGeometryLabelEditing: (target: GeometryLabelTarget) => void;
62
+ startGraphEditing: (id: string) => void;
63
+ startMatrixEditing: (id: string) => void;
64
+ startTableEditing: (id: string) => void;
65
+ tool: Tool;
66
+ transformGridSelectionToAntiDiagonal: () => void;
67
+ transformGridSelectionToDiagonal: () => void;
68
+ transformGridSelectionToLowerTriangular: () => void;
69
+ transformGridSelectionToUpperTriangular: () => void;
70
+ transformSelectedMatrixRegion: (transform: "rotateClockwise" | "rotateCounterclockwise" | "transpose") => void;
71
+ transposeMatrix: (id: string) => void;
72
+ traverseConnectedGeoPoint: (direction: "left" | "right" | "up" | "down") => void;
73
+ traverseGraphNeighbor: (direction: "left" | "right" | "up" | "down", extendSelection?: boolean) => void;
74
+ };
75
+ export declare function useCanvasKeyboardShortcuts({ cancelPendingGraphDirectionalCreate, clearGeometryDraft, clearGeometrySelection, clearGridSelectionCells, copySelectedGraphNodes, createConnectedGraphNodeInDirection, cycleSelectedGeometryObject, deleteGridSelectionStructure, deleteSelectedGeometry, deleteSelectedGraphEdge, deleteSelectedGraphNode, deleteSelectedMatrix, deleteSelectedTable, editingGraphNodeId, editingMatrixId, editingTableId, fillIdentityMatrix, getGridSelectionClipboardText, getMatrixById, getTableById, graphCreationArrowKeysRef, graphCreationChordActiveRef, gridSelection, handleRedo, handleUndo, insertGridSelectionStructure, moveGridSelectionStructure, nudgeSelectedGeometry, nudgeSelectedGraphNode, pasteGraphClipboard, pasteGridSelectionClipboardText, penColorOptions, pushHistoryState, resizeMatrix, resizeTable, rotateMatrixClockwise, rotateMatrixCounterclockwise, scheduleGraphDirectionalCreate, selectedAngleId, selectedCircleId, selectedGeometryLabel, selectedGraphEdgeId, selectedGraphNodeId, selectedGraphNodeIds, selectedMatrixId, selectedPointId, selectedPolygonId, selectedSegmentId, selectedTableId, setActiveConstructionStartPointId, setArmedSourceNodeId, setCurrentConstructionPathPointIds, setPenColor, setPenWidth, showPenSizePreviewBriefly, startGeometryLabelEditing, startGraphEditing, startMatrixEditing, startTableEditing, tool, transformGridSelectionToAntiDiagonal, transformGridSelectionToDiagonal, transformGridSelectionToLowerTriangular, transformGridSelectionToUpperTriangular, transformSelectedMatrixRegion, transposeMatrix, traverseConnectedGeoPoint, traverseGraphNeighbor, }: UseCanvasKeyboardShortcutsOptions): void;
76
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { CanvasState, CoordinatePlaneMode, GeoAngle, GeoCircle, GeoHelperSegment, GeoPoint, GeoPolygon, GeoRightAngleMarker, GeoSegment, GraphEdge, GraphNode, MatrixObject, RenderMode, Stroke, TableObject, TextBlock } from "../../types";
2
+ type UseCanvasSnapshotOptions = {
3
+ blocks: TextBlock[];
4
+ coordinatePlaneMode: CoordinatePlaneMode;
5
+ geoAngles: GeoAngle[];
6
+ geoCircles: GeoCircle[];
7
+ geoHelperSegments: GeoHelperSegment[];
8
+ geoPoints: GeoPoint[];
9
+ geoPolygons: GeoPolygon[];
10
+ geoRightAngleMarkers: GeoRightAngleMarker[];
11
+ geoSegments: GeoSegment[];
12
+ graphEdges: GraphEdge[];
13
+ graphNodes: GraphNode[];
14
+ matrices: MatrixObject[];
15
+ onStateChange?: (state: CanvasState) => void;
16
+ renderMode: RenderMode;
17
+ strokes: Stroke[];
18
+ tables: TableObject[];
19
+ };
20
+ export declare function useCanvasSnapshot({ blocks, coordinatePlaneMode, geoAngles, geoCircles, geoHelperSegments, geoPoints, geoPolygons, geoRightAngleMarkers, geoSegments, graphEdges, graphNodes, matrices, onStateChange, renderMode, strokes, tables, }: UseCanvasSnapshotOptions): {
21
+ getCanvasState: () => CanvasState;
22
+ };
23
+ export {};
@@ -0,0 +1,103 @@
1
+ import type { Dispatch, MutableRefObject, SetStateAction } from "react";
2
+ import type Konva from "konva";
3
+ import type { GeoPoint, GeoSegment, GeometryLabelTarget, GeometryMode, GraphNode, MatrixObject, RenderMode, StageActivationEvent, StagePointerEvent, TableObject, TextBlock, Tool } from "../../types";
4
+ type ScenePoint = {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ type SnapPoint = ScenePoint & {
9
+ kind: "point" | "grid" | "midpoint";
10
+ };
11
+ type UseCanvasStageInteractionsOptions = {
12
+ beginGraphSelectionDrag: (point: ScenePoint) => void;
13
+ clearEraserPreview: () => void;
14
+ clearGeometryDraft: () => void;
15
+ clearGeometrySelection: () => void;
16
+ clearGraphSelection: () => void;
17
+ clearMatrixSelection: () => void;
18
+ clearTableSelection: () => void;
19
+ commitEditing: () => void;
20
+ commitGeometryLabelEditing: () => void;
21
+ commitGraphEditing: () => void;
22
+ commitMatrixEditing: () => void;
23
+ commitTableEditing: () => void;
24
+ createGraphNode: (x: number, y: number) => void;
25
+ createId: () => string;
26
+ createMatrix: (x: number, y: number) => void;
27
+ createTable: (x: number, y: number) => void;
28
+ createTextBlock: (x: number, y: number) => void;
29
+ editingBlockId: string | null;
30
+ editingGeometryLabel: GeometryLabelTarget | null;
31
+ editingGraphNodeId: string | null;
32
+ editingMatrixId: string | null;
33
+ editingTableId: string | null;
34
+ eraseAtPointState: (x: number, y: number, radius: number, createId: () => string) => void;
35
+ extendStroke: (x: number, y: number) => void;
36
+ findGeoPointNear: (x: number, y: number) => GeoPoint | null;
37
+ findGeoSegmentNear: (x: number, y: number) => GeoSegment | null;
38
+ findGeometryLabelTargetNear: (x: number, y: number) => GeometryLabelTarget | null;
39
+ findGraphNodeAtPoint: (x: number, y: number) => GraphNode | null;
40
+ findMatrixAtPoint: (x: number, y: number) => MatrixObject | null;
41
+ findTableAtPoint: (x: number, y: number) => TableObject | null;
42
+ findTextBlockBlockingCreation: (x: number, y: number) => TextBlock | null;
43
+ finishGraphSelectionDrag: () => boolean;
44
+ getDefaultMatrixPosition: (x: number, y: number) => ScenePoint;
45
+ getDefaultTablePosition: (x: number, y: number) => ScenePoint;
46
+ getGeoSnap: (x: number, y: number) => SnapPoint;
47
+ getScenePoint: (stage: Konva.Stage | null) => ScenePoint | null;
48
+ geometryMode: GeometryMode;
49
+ handleGeometryCanvasPoint: (x: number, y: number) => void;
50
+ handleGeometryPointChoice: (pointId: string) => void;
51
+ isDrawing: MutableRefObject<boolean>;
52
+ isErasing: MutableRefObject<boolean>;
53
+ isPanning: MutableRefObject<boolean>;
54
+ lastPanPoint: MutableRefObject<ScenePoint | null>;
55
+ penColor: string;
56
+ penWidth: number;
57
+ pushHistoryState: () => void;
58
+ selectedGraphNodeId: string | null;
59
+ selectedMatrixId: string | null;
60
+ selectedPointId: string | null;
61
+ selectedTableId: string | null;
62
+ selectOnlyGeoSegment: (id: string) => void;
63
+ selectOnlyGraphNode: (id: string) => void;
64
+ setArmedSourceNodeId: (id: string | null) => void;
65
+ setGeometryDraftPointIds: (ids: string[]) => void;
66
+ setGeometryPointer: (point: ScenePoint) => void;
67
+ setMatrixLatexPopover: (popover: {
68
+ matrixId: string;
69
+ left: number;
70
+ top: number;
71
+ } | null) => void;
72
+ setRenderMode: Dispatch<SetStateAction<RenderMode>>;
73
+ setSelectedBlockId: Dispatch<SetStateAction<string | null>>;
74
+ setSelectedGraphEdgeId: Dispatch<SetStateAction<string | null>>;
75
+ setSelectedMatrixId: Dispatch<SetStateAction<string | null>>;
76
+ setSelectedTableId: Dispatch<SetStateAction<string | null>>;
77
+ setSnapPreview: (preview: SnapPoint | null) => void;
78
+ setTextBlockMenu: (menu: {
79
+ blockId: string;
80
+ panel: "color" | "format" | null;
81
+ } | null) => void;
82
+ setViewport: Dispatch<SetStateAction<ScenePoint>>;
83
+ skipNextMatrixCreationRef: MutableRefObject<boolean>;
84
+ skipNextTextCreationRef: MutableRefObject<boolean>;
85
+ skipNextTextCreationResetRef: MutableRefObject<number | null>;
86
+ startGeometryLabelEditing: (target: GeometryLabelTarget) => void;
87
+ startGraphEditing: (id: string) => void;
88
+ startMatrixEditing: (id: string) => void;
89
+ startStrokeState: (x: number, y: number, tool: Tool, strokeWidth: number, color: string, createId: () => string) => void;
90
+ startTableEditing: (id: string) => void;
91
+ suppressNextGraphActivationRef: MutableRefObject<boolean>;
92
+ toggleEqualSideMarker: (segmentId: string) => void;
93
+ tool: Tool;
94
+ updateEraserPreview: (x: number, y: number) => number;
95
+ updateGraphSelectionDrag: (point: ScenePoint) => boolean;
96
+ };
97
+ export declare function useCanvasStageInteractions({ beginGraphSelectionDrag, clearEraserPreview, clearGeometryDraft, clearGeometrySelection, clearGraphSelection, clearMatrixSelection, clearTableSelection, commitEditing, commitGeometryLabelEditing, commitGraphEditing, commitMatrixEditing, commitTableEditing, createGraphNode, createId, createMatrix, createTable, createTextBlock, editingBlockId, editingGeometryLabel, editingGraphNodeId, editingMatrixId, editingTableId, eraseAtPointState, extendStroke, findGeoPointNear, findGeoSegmentNear, findGeometryLabelTargetNear, findGraphNodeAtPoint, findMatrixAtPoint, findTableAtPoint, findTextBlockBlockingCreation, finishGraphSelectionDrag, getDefaultMatrixPosition, getDefaultTablePosition, getGeoSnap, getScenePoint, geometryMode, handleGeometryCanvasPoint, handleGeometryPointChoice, isDrawing, isErasing, isPanning, lastPanPoint, penColor, penWidth, pushHistoryState, selectedGraphNodeId, selectedMatrixId, selectedPointId, selectedTableId, selectOnlyGeoSegment, selectOnlyGraphNode, setArmedSourceNodeId, setGeometryDraftPointIds, setGeometryPointer, setMatrixLatexPopover, setRenderMode, setSelectedBlockId, setSelectedGraphEdgeId, setSelectedMatrixId, setSelectedTableId, setSnapPreview, setTextBlockMenu, setViewport, skipNextMatrixCreationRef, skipNextTextCreationRef, skipNextTextCreationResetRef, startGeometryLabelEditing, startGraphEditing, startMatrixEditing, startStrokeState, startTableEditing, suppressNextGraphActivationRef, toggleEqualSideMarker, tool, updateEraserPreview, updateGraphSelectionDrag, }: UseCanvasStageInteractionsOptions): {
98
+ handleCanvasActivation: (e: StageActivationEvent) => void;
99
+ handlePointerDown: (e: StagePointerEvent) => void;
100
+ handlePointerMove: (e: StagePointerEvent) => void;
101
+ handlePointerUp: () => void;
102
+ };
103
+ export {};
@@ -0,0 +1,28 @@
1
+ import { type MutableRefObject } from "react";
2
+ import type Konva from "konva";
3
+ import type { GraphNode, MatrixObject, TableObject, TextBlock, Tool } from "../../types";
4
+ type UseCanvasTransformersOptions = {
5
+ blockHeights: Record<string, number>;
6
+ blockNodeRefs: MutableRefObject<Record<string, Konva.Rect | null>>;
7
+ blockWidths: Record<string, number>;
8
+ blocks: TextBlock[];
9
+ editingBlockId: string | null;
10
+ graphNodeRefs: MutableRefObject<Record<string, Konva.Group | null>>;
11
+ graphNodes: GraphNode[];
12
+ graphTransformerRef: MutableRefObject<Konva.Transformer | null>;
13
+ matrices: MatrixObject[];
14
+ matrixNodeRefs: MutableRefObject<Record<string, Konva.Rect | null>>;
15
+ matrixTransformerRef: MutableRefObject<Konva.Transformer | null>;
16
+ selectedBlockId: string | null;
17
+ selectedGraphNodeId: string | null;
18
+ selectedGraphNodeIds: string[];
19
+ selectedMatrixId: string | null;
20
+ selectedTableId: string | null;
21
+ tables: TableObject[];
22
+ tableNodeRefs: MutableRefObject<Record<string, Konva.Rect | null>>;
23
+ tableTransformerRef: MutableRefObject<Konva.Transformer | null>;
24
+ tool: Tool;
25
+ transformerRef: MutableRefObject<Konva.Transformer | null>;
26
+ };
27
+ export declare function useCanvasTransformers({ blockHeights, blockNodeRefs, blockWidths, blocks, editingBlockId, graphNodeRefs, graphNodes, graphTransformerRef, matrices, matrixNodeRefs, matrixTransformerRef, selectedBlockId, selectedGraphNodeId, selectedGraphNodeIds, selectedMatrixId, selectedTableId, tables, tableNodeRefs, tableTransformerRef, tool, transformerRef, }: UseCanvasTransformersOptions): void;
28
+ export {};
@@ -0,0 +1,25 @@
1
+ import type Konva from "konva";
2
+ export declare function useCanvasViewport(): {
3
+ containerRef: import("react").RefObject<HTMLDivElement | null>;
4
+ getScenePoint: (stage: Konva.Stage | null) => {
5
+ x: number;
6
+ y: number;
7
+ } | null;
8
+ isPanning: import("react").RefObject<boolean>;
9
+ lastPanPoint: import("react").RefObject<{
10
+ x: number;
11
+ y: number;
12
+ } | null>;
13
+ setViewport: import("react").Dispatch<import("react").SetStateAction<{
14
+ x: number;
15
+ y: number;
16
+ }>>;
17
+ size: {
18
+ width: number;
19
+ height: number;
20
+ };
21
+ viewport: {
22
+ x: number;
23
+ y: number;
24
+ };
25
+ };
@@ -0,0 +1,9 @@
1
+ export { useCanvasEditorFocus } from "./hooks/useCanvasEditorFocus";
2
+ export { useCanvasGlobalActions } from "./hooks/useCanvasGlobalActions";
3
+ export { useCanvasGlobalDragEffects } from "./hooks/useCanvasGlobalDragEffects";
4
+ export { useCanvasHistory } from "./hooks/useCanvasHistory";
5
+ export { useCanvasKeyboardShortcuts } from "./hooks/useCanvasKeyboardShortcuts";
6
+ export { useCanvasSnapshot } from "./hooks/useCanvasSnapshot";
7
+ export { useCanvasStageInteractions } from "./hooks/useCanvasStageInteractions";
8
+ export { useCanvasTransformers } from "./hooks/useCanvasTransformers";
9
+ export { useCanvasViewport } from "./hooks/useCanvasViewport";
@@ -0,0 +1,15 @@
1
+ import type { CoordinatePlaneMode, MathCanvasTheme } from "../../../types";
2
+ type CoordinatePlaneLayerProps = {
3
+ coordinatePlaneMode: CoordinatePlaneMode;
4
+ colors: MathCanvasTheme;
5
+ size: {
6
+ width: number;
7
+ height: number;
8
+ };
9
+ viewport: {
10
+ x: number;
11
+ y: number;
12
+ };
13
+ };
14
+ export default function CoordinatePlaneLayer({ coordinatePlaneMode, colors, size, viewport, }: CoordinatePlaneLayerProps): import("react/jsx-runtime").JSX.Element | null;
15
+ export {};
@@ -0,0 +1,65 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ import type { GeoAngle, GeoCircle, GeoHelperSegment, GeoPoint, GeoPolygon, GeoRightAngleMarker, GeoSegment, GeometryLabelTarget, GeometryMode, MathCanvasTheme, Tool } from "../../../types";
3
+ type GeometryPreview = {
4
+ start: {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ end: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ };
13
+ type SnapPreview = {
14
+ x: number;
15
+ y: number;
16
+ kind: "point" | "grid" | "midpoint";
17
+ };
18
+ type GeometryLayerProps = {
19
+ geoPoints: GeoPoint[];
20
+ geoPointMap: Map<string, GeoPoint>;
21
+ geoSegments: GeoSegment[];
22
+ geoPolygons: GeoPolygon[];
23
+ geoAngles: GeoAngle[];
24
+ geoCircles: GeoCircle[];
25
+ geoHelperSegments: GeoHelperSegment[];
26
+ geoRightAngleMarkers: GeoRightAngleMarker[];
27
+ geometryPreview: GeometryPreview | null;
28
+ snapPreview: SnapPreview | null;
29
+ selectedPolygonId: string | null;
30
+ selectedCircleId: string | null;
31
+ selectedSegmentId: string | null;
32
+ selectedAngleId: string | null;
33
+ selectedPointId: string | null;
34
+ hoveredPointId: string | null;
35
+ currentConstructionPathPointIds: string[];
36
+ angleDraftPointIds: string[];
37
+ circleDraftCenterId: string | null;
38
+ tool: Tool;
39
+ geometryMode: GeometryMode;
40
+ colors: MathCanvasTheme;
41
+ darkMode: boolean;
42
+ clearGeometryDraft: () => void;
43
+ clearGeometrySelection: () => void;
44
+ getEqualSideMarkerPoints: (segment: GeoSegment) => number[] | null;
45
+ getHelperSegmentPoints: (helper: GeoHelperSegment) => number[] | null;
46
+ getRightAngleMarkerPoints: (marker: GeoRightAngleMarker) => number[] | null;
47
+ getSegmentPoints: (segment: GeoSegment) => {
48
+ a: GeoPoint;
49
+ b: GeoPoint;
50
+ } | null;
51
+ handleGeometryPointChoice: (pointId: string) => void;
52
+ pushHistoryState: () => void;
53
+ selectOnlyGeoPoint: (id: string) => void;
54
+ selectOnlyGeoSegment: (id: string) => void;
55
+ setGeometryDraftPointIds: Dispatch<SetStateAction<string[]>>;
56
+ setHoveredPointId: Dispatch<SetStateAction<string | null>>;
57
+ setSelectedAngleId: Dispatch<SetStateAction<string | null>>;
58
+ setSelectedCircleId: Dispatch<SetStateAction<string | null>>;
59
+ setSelectedPolygonId: Dispatch<SetStateAction<string | null>>;
60
+ startGeometryLabelEditing: (target: GeometryLabelTarget) => void;
61
+ toggleEqualSideMarker: (segmentId: string) => void;
62
+ updateGeoPoint: (id: string, updater: (point: GeoPoint) => GeoPoint) => void;
63
+ };
64
+ export default function GeometryLayer({ geoPoints, geoPointMap, geoSegments, geoPolygons, geoAngles, geoCircles, geoHelperSegments, geoRightAngleMarkers, geometryPreview, snapPreview, selectedPolygonId, selectedCircleId, selectedSegmentId, selectedAngleId, selectedPointId, hoveredPointId, currentConstructionPathPointIds, angleDraftPointIds, circleDraftCenterId, tool, geometryMode, colors, darkMode, clearGeometryDraft, clearGeometrySelection, getEqualSideMarkerPoints, getHelperSegmentPoints, getRightAngleMarkerPoints, getSegmentPoints, handleGeometryPointChoice, pushHistoryState, selectOnlyGeoPoint, selectOnlyGeoSegment, setGeometryDraftPointIds, setHoveredPointId, setSelectedAngleId, setSelectedCircleId, setSelectedPolygonId, startGeometryLabelEditing, toggleEqualSideMarker, updateGeoPoint, }: GeometryLayerProps): import("react/jsx-runtime").JSX.Element;
65
+ export {};
@@ -0,0 +1,57 @@
1
+ import type { MutableRefObject } from "react";
2
+ import type { GeometryLabelOffset, GeometryLabelTarget, GeometryMode, MathCanvasTheme, Tool } from "../../../types";
3
+ type GeometryLabelOverlay = {
4
+ key: string;
5
+ label: string;
6
+ position: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ target: GeometryLabelTarget;
11
+ };
12
+ type GeometryLabelDragRef = MutableRefObject<{
13
+ target: GeometryLabelTarget;
14
+ startX: number;
15
+ startY: number;
16
+ offset: GeometryLabelOffset;
17
+ didPushHistory: boolean;
18
+ } | null>;
19
+ type GeometryOverlaysProps = {
20
+ colors: MathCanvasTheme;
21
+ tool: Tool;
22
+ geometryMode: GeometryMode;
23
+ viewport: {
24
+ x: number;
25
+ y: number;
26
+ };
27
+ geometryLabelOverlays: GeometryLabelOverlay[];
28
+ editingGeometryLabel: GeometryLabelTarget | null;
29
+ selectedGeometryLabel: GeometryLabelTarget | null;
30
+ editingGeometryLabelPosition: {
31
+ x: number;
32
+ y: number;
33
+ } | null;
34
+ geometryLabelEditorWidth: number;
35
+ geometryLabelInputRef: MutableRefObject<HTMLInputElement | null>;
36
+ geometryLabelValue: string;
37
+ setGeometryLabelValue: (value: string) => void;
38
+ commitGeometryLabelEditing: () => void;
39
+ clearGeometryLabelEditing: () => void;
40
+ isSameGeometryLabelTarget: (a: GeometryLabelTarget | null, b: GeometryLabelTarget | null) => boolean;
41
+ selectGeometryLabel: (target: GeometryLabelTarget) => void;
42
+ startGeometryLabelEditing: (target: GeometryLabelTarget) => void;
43
+ getGeometryLabelOffset: (target: GeometryLabelTarget) => GeometryLabelOffset;
44
+ geometryLabelDragRef: GeometryLabelDragRef;
45
+ fixedLengthStartPoint: {
46
+ x: number;
47
+ y: number;
48
+ } | null;
49
+ fixedLengthInputWidth: number;
50
+ fixedLengthInputRef: MutableRefObject<HTMLInputElement | null>;
51
+ fixedLengthValue: string;
52
+ setFixedLengthValue: (value: string) => void;
53
+ commitFixedLengthSegment: () => void;
54
+ clearGeometryDraft: () => void;
55
+ };
56
+ export default function GeometryOverlays({ colors, tool, geometryMode, viewport, geometryLabelOverlays, editingGeometryLabel, selectedGeometryLabel, editingGeometryLabelPosition, geometryLabelEditorWidth, geometryLabelInputRef, geometryLabelValue, setGeometryLabelValue, commitGeometryLabelEditing, clearGeometryLabelEditing, isSameGeometryLabelTarget, selectGeometryLabel, startGeometryLabelEditing, getGeometryLabelOffset, geometryLabelDragRef, fixedLengthStartPoint, fixedLengthInputWidth, fixedLengthInputRef, fixedLengthValue, setFixedLengthValue, commitFixedLengthSegment, clearGeometryDraft, }: GeometryOverlaysProps): import("react/jsx-runtime").JSX.Element;
57
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ import type { GeometryDirection, GeometryLabelTarget } from "../../../types";
3
+ type UseGeometryCanvasActionsOptions = {
4
+ clearGraphSelection: () => void;
5
+ clearMatrixSelection: () => void;
6
+ clearTableSelection: () => void;
7
+ commitFixedLengthSegmentState: (createId: () => string) => void;
8
+ createId: () => string;
9
+ cycleSelectedGeometryObjectState: (direction?: 1 | -1) => boolean;
10
+ handleGeometryCanvasPointState: (x: number, y: number, createId: () => string) => boolean;
11
+ handleGeometryPointChoiceState: (pointId: string, createId: () => string, shouldPushHistory?: boolean) => boolean;
12
+ selectGeometryLabelState: (target: GeometryLabelTarget) => void;
13
+ selectGeometryObjectState: (kind: "point" | "segment", id: string) => void;
14
+ setSelectedBlockId: Dispatch<SetStateAction<string | null>>;
15
+ startGeometryLabelEditingState: (target: GeometryLabelTarget) => void;
16
+ traverseConnectedGeoPointState: (direction: GeometryDirection) => boolean;
17
+ };
18
+ export declare function useGeometryCanvasActions({ clearGraphSelection, clearMatrixSelection, clearTableSelection, commitFixedLengthSegmentState, createId, cycleSelectedGeometryObjectState, handleGeometryCanvasPointState, handleGeometryPointChoiceState, selectGeometryLabelState, selectGeometryObjectState, setSelectedBlockId, startGeometryLabelEditingState, traverseConnectedGeoPointState, }: UseGeometryCanvasActionsOptions): {
19
+ commitFixedLengthSegment: () => void;
20
+ cycleSelectedGeometryObject: (direction?: 1 | -1) => void;
21
+ handleGeometryCanvasPoint: (x: number, y: number) => void;
22
+ handleGeometryPointChoice: (pointId: string, shouldPushHistory?: boolean) => void;
23
+ selectGeometryLabel: (target: GeometryLabelTarget) => void;
24
+ selectOnlyGeoPoint: (id: string) => void;
25
+ selectOnlyGeoSegment: (id: string) => void;
26
+ startGeometryLabelEditing: (target: GeometryLabelTarget) => void;
27
+ traverseConnectedGeoPoint: (direction: GeometryDirection) => void;
28
+ };
29
+ export {};
@@ -0,0 +1,60 @@
1
+ import type { GeoAngle, GeoCircle, GeoPoint, GeoSegment, GeometryLabelTarget, Tool } from "../../../types";
2
+ type GeometryPoint = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ type UseGeometryRenderDataOptions = {
7
+ currentConstructionPathPointIds: string[];
8
+ editingGeometryLabel: GeometryLabelTarget | null;
9
+ fixedLengthStartPointId: string | null;
10
+ fixedLengthValue: string;
11
+ geoAngles: GeoAngle[];
12
+ geoCircles: GeoCircle[];
13
+ geoPoints: GeoPoint[];
14
+ geoSegments: GeoSegment[];
15
+ geometryLabelValue: string;
16
+ geometryMode: string;
17
+ geometryPointer: GeometryPoint | null;
18
+ getGeoPointById: (id: string | null) => GeoPoint | null;
19
+ getGeometryLabelPosition: (target: GeometryLabelTarget) => GeometryPoint | null;
20
+ getGeometryLabelValue: (target: GeometryLabelTarget) => string;
21
+ selectedPointId: string | null;
22
+ tool: Tool;
23
+ };
24
+ export declare function useGeometryRenderData({ currentConstructionPathPointIds, editingGeometryLabel, fixedLengthStartPointId, fixedLengthValue, geoAngles, geoCircles, geoPoints, geoSegments, geometryLabelValue, geometryMode, geometryPointer, getGeoPointById, getGeometryLabelPosition, getGeometryLabelValue, selectedPointId, tool, }: UseGeometryRenderDataOptions): {
25
+ editingGeometryLabelPosition: GeometryPoint | null;
26
+ fixedLengthInputWidth: number;
27
+ fixedLengthStartPoint: GeoPoint | null;
28
+ geoPointMap: Map<string, GeoPoint>;
29
+ geometryLabelEditorWidth: number;
30
+ geometryLabelOverlays: ({
31
+ key: string;
32
+ label: string;
33
+ position: GeometryPoint;
34
+ target: {
35
+ kind: "segment";
36
+ id: string;
37
+ };
38
+ } | {
39
+ key: string;
40
+ label: string;
41
+ position: GeometryPoint;
42
+ target: {
43
+ kind: "angle";
44
+ id: string;
45
+ };
46
+ } | {
47
+ key: string;
48
+ label: string;
49
+ position: GeometryPoint;
50
+ target: {
51
+ kind: "circle";
52
+ id: string;
53
+ };
54
+ })[];
55
+ geometryPreview: {
56
+ start: GeoPoint;
57
+ end: GeometryPoint;
58
+ } | null;
59
+ };
60
+ export {};
@@ -0,0 +1,147 @@
1
+ import { type MutableRefObject } from "react";
2
+ import type { CanvasState, CoordinatePlaneMode, GeoAngle, GeoCircle, GeoHelperSegment, GeoPoint, GeoPolygon, GeoRightAngleMarker, GeoSegment, GeometryDirection, GeometryObjectKind, GeometryLabelOffset, GeometryLabelTarget, GeometryMode } from "../../../types";
3
+ type UseGeometryStateOptions = {
4
+ initialState?: Pick<CanvasState, "coordinatePlaneMode" | "geoAngles" | "geoCircles" | "geoHelperSegments" | "geoPoints" | "geoPolygons" | "geoRightAngleMarkers" | "geoSegments">;
5
+ pushHistoryStateRef: MutableRefObject<() => void>;
6
+ };
7
+ export declare function useGeometryState({ initialState, pushHistoryStateRef }: UseGeometryStateOptions): {
8
+ activeConstructionStartPointId: string | null;
9
+ angleDraftPointIds: string[];
10
+ circleDraftCenterId: string | null;
11
+ clearGeometryDraft: () => void;
12
+ clearGeometryLabelEditing: () => void;
13
+ clearGeometryLabelValue: (target: GeometryLabelTarget) => void;
14
+ clearGeometrySelection: () => void;
15
+ commitGeometryLabelEditing: () => void;
16
+ commitFixedLengthSegment: (createId: () => string) => boolean;
17
+ coordinatePlaneMode: CoordinatePlaneMode;
18
+ closeGeoPolygonFromPath: (pathPointIds: string[], createId: () => string) => GeoPolygon | null;
19
+ createGeoPointAt: (x: number, y: number, createId: () => string) => GeoPoint;
20
+ createGeoSegment: (a: string, b: string, createId: () => string) => GeoSegment | null;
21
+ createHelperSegment: (kind: GeoHelperSegment["kind"], baseA: string, baseB: string, through: string, createId: () => string) => boolean;
22
+ createMidpointFromPoints: (a: string, b: string, createId: () => string) => boolean;
23
+ createRightAngleMarker: (a: string, b: string, c: string, createId: () => string) => boolean;
24
+ currentConstructionPathPointIds: string[];
25
+ cycleSelectedGeometryObject: (direction?: 1 | -1) => boolean;
26
+ deleteSelectedGeometry: () => boolean;
27
+ editingGeometryLabel: GeometryLabelTarget | null;
28
+ fixedLengthStartPointId: string | null;
29
+ fixedLengthValue: string;
30
+ findGeoCircleNear: (x: number, y: number) => GeoCircle | null;
31
+ findGeoPointNear: (x: number, y: number, radius?: number) => GeoPoint | null;
32
+ findGeoSegmentNear: (x: number, y: number) => GeoSegment | null;
33
+ findGeometryLabelTargetNear: (x: number, y: number) => GeometryLabelTarget | null;
34
+ geoAngles: GeoAngle[];
35
+ geoCircles: GeoCircle[];
36
+ geoHelperSegments: GeoHelperSegment[];
37
+ geoPoints: GeoPoint[];
38
+ geoPolygons: GeoPolygon[];
39
+ geoRightAngleMarkers: GeoRightAngleMarker[];
40
+ geoSegments: GeoSegment[];
41
+ geometryDraftPointIds: string[];
42
+ geometryLabelValue: string;
43
+ geometryMode: GeometryMode;
44
+ geometryPointer: {
45
+ x: number;
46
+ y: number;
47
+ } | null;
48
+ getCircleGeometry: (circle: GeoCircle) => {
49
+ center: GeoPoint;
50
+ radius: number;
51
+ } | null;
52
+ getEqualSideMarkerPoints: (segment: GeoSegment) => number[] | null;
53
+ getGeoPointById: (id: string | null) => GeoPoint | null;
54
+ getGeometryLabelOffset: (target: GeometryLabelTarget) => GeometryLabelOffset;
55
+ getGeometryLabelPosition: (target: GeometryLabelTarget) => {
56
+ x: number;
57
+ y: number;
58
+ } | null;
59
+ getGeometryLabelValue: (target: GeometryLabelTarget) => string;
60
+ getGeoSnap: (x: number, y: number) => {
61
+ x: number;
62
+ y: number;
63
+ pointId: string;
64
+ kind: "point";
65
+ } | {
66
+ kind: "midpoint";
67
+ x: number;
68
+ y: number;
69
+ pointId?: undefined;
70
+ } | {
71
+ kind: "grid";
72
+ x: number;
73
+ y: number;
74
+ pointId?: undefined;
75
+ };
76
+ getHelperSegmentPoints: (helper: GeoHelperSegment) => number[] | null;
77
+ getRightAngleMarkerPoints: (marker: GeoRightAngleMarker) => number[] | null;
78
+ getSegmentPoints: (segment: GeoSegment) => {
79
+ a: GeoPoint;
80
+ b: GeoPoint;
81
+ } | null;
82
+ getSelectedGeometryPointIds: () => string[];
83
+ handleGeometryCanvasPoint: (x: number, y: number, createId: () => string) => boolean;
84
+ handleGeometryPointChoice: (pointId: string, createId: () => string, shouldPushHistory?: boolean) => boolean;
85
+ hoveredPointId: string | null;
86
+ ensureGeoPointAt: (x: number, y: number, createId: () => string) => GeoPoint;
87
+ isSameGeometryLabelTarget: (a: GeometryLabelTarget | null, b: GeometryLabelTarget | null) => boolean;
88
+ nudgeSelectedGeometryLabel: (dx: number, dy: number) => void;
89
+ nudgeSelectedGeometry: (dx: number, dy: number) => boolean;
90
+ regularPolygonCenterId: string | null;
91
+ regularPolygonSides: number;
92
+ selectedAngleId: string | null;
93
+ selectedCircleId: string | null;
94
+ selectedGeometryLabel: GeometryLabelTarget | null;
95
+ selectedPointId: string | null;
96
+ selectedPolygonId: string | null;
97
+ selectedSegmentId: string | null;
98
+ selectGeometryLabel: (target: GeometryLabelTarget) => void;
99
+ selectGeometryObject: (kind: GeometryObjectKind, id: string) => void;
100
+ setActiveConstructionStartPointId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
101
+ setAngleDraftPointIds: import("react").Dispatch<import("react").SetStateAction<string[]>>;
102
+ setCircleDraftCenterId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
103
+ setCoordinatePlaneMode: import("react").Dispatch<import("react").SetStateAction<CoordinatePlaneMode>>;
104
+ setCurrentConstructionPathPointIds: import("react").Dispatch<import("react").SetStateAction<string[]>>;
105
+ setEditingGeometryLabel: import("react").Dispatch<import("react").SetStateAction<GeometryLabelTarget | null>>;
106
+ setFixedLengthStartPointId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
107
+ setFixedLengthValue: import("react").Dispatch<import("react").SetStateAction<string>>;
108
+ setGeoAngles: import("react").Dispatch<import("react").SetStateAction<GeoAngle[]>>;
109
+ setGeoCircles: import("react").Dispatch<import("react").SetStateAction<GeoCircle[]>>;
110
+ setGeoHelperSegments: import("react").Dispatch<import("react").SetStateAction<GeoHelperSegment[]>>;
111
+ setGeoPoints: import("react").Dispatch<import("react").SetStateAction<GeoPoint[]>>;
112
+ setGeoPolygons: import("react").Dispatch<import("react").SetStateAction<GeoPolygon[]>>;
113
+ setGeoRightAngleMarkers: import("react").Dispatch<import("react").SetStateAction<GeoRightAngleMarker[]>>;
114
+ setGeoSegments: import("react").Dispatch<import("react").SetStateAction<GeoSegment[]>>;
115
+ setGeometryDraftPointIds: import("react").Dispatch<import("react").SetStateAction<string[]>>;
116
+ setGeometryLabelValue: import("react").Dispatch<import("react").SetStateAction<string>>;
117
+ setGeometryMode: import("react").Dispatch<import("react").SetStateAction<GeometryMode>>;
118
+ setGeometryPointer: import("react").Dispatch<import("react").SetStateAction<{
119
+ x: number;
120
+ y: number;
121
+ } | null>>;
122
+ setHoveredPointId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
123
+ setRegularPolygonCenterId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
124
+ setRegularPolygonSides: import("react").Dispatch<import("react").SetStateAction<number>>;
125
+ setSelectedAngleId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
126
+ setSelectedCircleId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
127
+ setSelectedGeometryLabel: import("react").Dispatch<import("react").SetStateAction<GeometryLabelTarget | null>>;
128
+ setSelectedPointId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
129
+ setSelectedPolygonId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
130
+ setSelectedSegmentId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
131
+ setSnapPreview: import("react").Dispatch<import("react").SetStateAction<{
132
+ x: number;
133
+ y: number;
134
+ kind: "point" | "grid" | "midpoint";
135
+ } | null>>;
136
+ snapPreview: {
137
+ x: number;
138
+ y: number;
139
+ kind: "point" | "grid" | "midpoint";
140
+ } | null;
141
+ startGeometryLabelEditing: (target: GeometryLabelTarget) => void;
142
+ toggleEqualSideMarker: (segmentId: string) => void;
143
+ traverseConnectedGeoPoint: (direction: GeometryDirection) => boolean;
144
+ updateGeoPoint: (id: string, updater: (point: GeoPoint) => GeoPoint) => void;
145
+ updateGeometryLabelOffset: (target: GeometryLabelTarget, offset: GeometryLabelOffset) => void;
146
+ };
147
+ export {};