mathlean-canvas 0.3.3 → 0.3.4
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/dist/MathCanvas/components/icons.d.ts +3 -0
- package/dist/MathCanvas/core/hooks/useCanvasSnapshot.d.ts +3 -2
- package/dist/MathCanvas/core/hooks/useCanvasStageInteractions.d.ts +2 -1
- package/dist/MathCanvas/features/plot/components/PlotControls.d.ts +28 -0
- package/dist/MathCanvas/features/plot/components/PlotLayer.d.ts +30 -0
- package/dist/MathCanvas/features/plot/index.d.ts +2 -0
- package/dist/MathCanvas/features/plot/utils/plotCompiler.d.ts +18 -0
- package/dist/MathCanvas/features/plot/utils/plotModel.d.ts +16 -0
- package/dist/MathCanvas/features/text/hooks/useTextBlockRenderHelpers.d.ts +1 -0
- package/dist/MathCanvas/types.d.ts +23 -1
- package/dist/index.js +57812 -7602
- package/package.json +2 -1
|
@@ -33,6 +33,9 @@ export declare function RenderKatexExpression({ expression, fallback, displayMod
|
|
|
33
33
|
export declare function GraphIcon({ active }: {
|
|
34
34
|
active: boolean;
|
|
35
35
|
}): import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
export declare function PlotIcon({ active }: {
|
|
37
|
+
active: boolean;
|
|
38
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
36
39
|
export declare function MatrixIcon({ active }: {
|
|
37
40
|
active: boolean;
|
|
38
41
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CanvasState, CoordinatePlaneMode, GeoAngle, GeoCircle, GeoHelperSegment, GeoPoint, GeoPolygon, GeoRightAngleMarker, GeoSegment, GraphEdge, GraphNode, MatrixObject, RenderMode, Stroke, TableObject, TextBlock } from "../../types";
|
|
1
|
+
import type { CanvasState, CoordinatePlaneMode, GeoAngle, GeoCircle, GeoHelperSegment, GeoPoint, GeoPolygon, GeoRightAngleMarker, GeoSegment, GraphEdge, GraphNode, MatrixObject, PlotFunction, RenderMode, Stroke, TableObject, TextBlock } from "../../types";
|
|
2
2
|
type UseCanvasSnapshotOptions = {
|
|
3
3
|
blocks: TextBlock[];
|
|
4
4
|
coordinatePlaneMode: CoordinatePlaneMode;
|
|
@@ -13,11 +13,12 @@ type UseCanvasSnapshotOptions = {
|
|
|
13
13
|
graphNodes: GraphNode[];
|
|
14
14
|
matrices: MatrixObject[];
|
|
15
15
|
onStateChange?: (state: CanvasState) => void;
|
|
16
|
+
plots: PlotFunction[];
|
|
16
17
|
renderMode: RenderMode;
|
|
17
18
|
strokes: Stroke[];
|
|
18
19
|
tables: TableObject[];
|
|
19
20
|
};
|
|
20
|
-
export declare function useCanvasSnapshot({ blocks, coordinatePlaneMode, geoAngles, geoCircles, geoHelperSegments, geoPoints, geoPolygons, geoRightAngleMarkers, geoSegments, graphEdges, graphNodes, matrices, onStateChange, renderMode, strokes, tables, }: UseCanvasSnapshotOptions): {
|
|
21
|
+
export declare function useCanvasSnapshot({ blocks, coordinatePlaneMode, geoAngles, geoCircles, geoHelperSegments, geoPoints, geoPolygons, geoRightAngleMarkers, geoSegments, graphEdges, graphNodes, matrices, onStateChange, plots, renderMode, strokes, tables, }: UseCanvasSnapshotOptions): {
|
|
21
22
|
getCanvasState: () => CanvasState;
|
|
22
23
|
};
|
|
23
24
|
export {};
|
|
@@ -40,6 +40,7 @@ type UseCanvasStageInteractionsOptions = {
|
|
|
40
40
|
findMatrixAtPoint: (x: number, y: number) => MatrixObject | null;
|
|
41
41
|
findTableAtPoint: (x: number, y: number) => TableObject | null;
|
|
42
42
|
findTextBlockBlockingCreation: (x: number, y: number) => TextBlock | null;
|
|
43
|
+
findTextBlockNearPoint: (x: number, y: number) => TextBlock | null;
|
|
43
44
|
finishGraphSelectionDrag: () => boolean;
|
|
44
45
|
getDefaultMatrixPosition: (x: number, y: number) => ScenePoint;
|
|
45
46
|
getDefaultTablePosition: (x: number, y: number) => ScenePoint;
|
|
@@ -94,7 +95,7 @@ type UseCanvasStageInteractionsOptions = {
|
|
|
94
95
|
updateEraserPreview: (x: number, y: number) => number;
|
|
95
96
|
updateGraphSelectionDrag: (point: ScenePoint) => boolean;
|
|
96
97
|
};
|
|
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
|
+
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, findTextBlockNearPoint, 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
99
|
handleCanvasActivation: (e: StageActivationEvent) => void;
|
|
99
100
|
handlePointerDown: (e: StagePointerEvent) => void;
|
|
100
101
|
handlePointerMove: (e: StagePointerEvent) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Dispatch, type SetStateAction } from "react";
|
|
2
|
+
import type { MathCanvasTheme, PlotFunction } from "../../../types";
|
|
3
|
+
type PlotControlsProps = {
|
|
4
|
+
colors: MathCanvasTheme;
|
|
5
|
+
editingPlot: PlotFunction | null;
|
|
6
|
+
editingPlotEquationId: string | null;
|
|
7
|
+
editingPlotLatex: string;
|
|
8
|
+
plotColorOptions: readonly string[];
|
|
9
|
+
plotMenuPanel: "actions" | "color" | null;
|
|
10
|
+
copySelectedPlot: (plot: PlotFunction) => Promise<void>;
|
|
11
|
+
createPlotEquation: (plotId: string) => void;
|
|
12
|
+
deletePlotEquation: (plotId: string, equationId: string) => void;
|
|
13
|
+
deleteSelectedPlot: () => void;
|
|
14
|
+
commitPlotEditing: () => boolean;
|
|
15
|
+
pushHistoryState: () => void;
|
|
16
|
+
setEditingPlotEquationId: Dispatch<SetStateAction<string | null>>;
|
|
17
|
+
setEditingPlotId: Dispatch<SetStateAction<string | null>>;
|
|
18
|
+
setEditingPlotLatex: Dispatch<SetStateAction<string>>;
|
|
19
|
+
setPlotMenuPanel: (panel: "actions" | "color" | null) => void;
|
|
20
|
+
setPlots: Dispatch<SetStateAction<PlotFunction[]>>;
|
|
21
|
+
updatePlotEquationColor: (plotId: string, equationId: string, color: string) => void;
|
|
22
|
+
viewport: {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default function PlotControls({ colors, editingPlot, editingPlotEquationId, editingPlotLatex, plotColorOptions, plotMenuPanel, copySelectedPlot, createPlotEquation, deletePlotEquation, deleteSelectedPlot, commitPlotEditing, pushHistoryState, setEditingPlotEquationId, setEditingPlotId, setEditingPlotLatex, setPlotMenuPanel, setPlots, updatePlotEquationColor, viewport, }: PlotControlsProps): import("react/jsx-runtime").JSX.Element | null;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type Konva from "konva";
|
|
2
|
+
import type { MutableRefObject } from "react";
|
|
3
|
+
import type { MathCanvasTheme, PlotFunction, Tool } from "../../../types";
|
|
4
|
+
type PlotLayerProps = {
|
|
5
|
+
plots: PlotFunction[];
|
|
6
|
+
colors: MathCanvasTheme;
|
|
7
|
+
darkMode: boolean;
|
|
8
|
+
size: {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
viewport: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
|
16
|
+
plotNodeRefs: MutableRefObject<Record<string, Konva.Group | null>>;
|
|
17
|
+
selectedPlotId: string | null;
|
|
18
|
+
tool: Tool;
|
|
19
|
+
clearGraphSelection: () => void;
|
|
20
|
+
clearMatrixSelection: () => void;
|
|
21
|
+
clearTableSelection: () => void;
|
|
22
|
+
pushHistoryState: () => void;
|
|
23
|
+
setSelectedBlockId: (id: string | null) => void;
|
|
24
|
+
setSelectedPlotId: (id: string | null) => void;
|
|
25
|
+
openPlotActions: (id: string) => void;
|
|
26
|
+
startPlotEditing: (id: string) => void;
|
|
27
|
+
updatePlot: (id: string, updater: (plot: PlotFunction) => PlotFunction) => void;
|
|
28
|
+
};
|
|
29
|
+
export default function PlotLayer({ plots, colors, darkMode, size, viewport, plotNodeRefs, selectedPlotId, tool, clearGraphSelection, clearMatrixSelection, clearTableSelection, pushHistoryState, setSelectedBlockId, setSelectedPlotId, openPlotActions, startPlotEditing, updatePlot, }: PlotLayerProps): import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MathJsonExpression } from "@cortex-js/compute-engine/math-json";
|
|
2
|
+
export type PlotCompileResult = {
|
|
3
|
+
ok: true;
|
|
4
|
+
latex: string;
|
|
5
|
+
mathJson: MathJsonExpression;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
error: string;
|
|
9
|
+
};
|
|
10
|
+
export type CompiledPlotFunction = {
|
|
11
|
+
kind: "explicit";
|
|
12
|
+
evaluate: (x: number) => number;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "implicit";
|
|
15
|
+
evaluate: (x: number, y: number) => number;
|
|
16
|
+
};
|
|
17
|
+
export declare function compilePlotLatex(latex: string): PlotCompileResult;
|
|
18
|
+
export declare function compilePlotMathJson(mathJson: MathJsonExpression | null): CompiledPlotFunction | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PlotEquation, PlotFunction } from "../../../types";
|
|
2
|
+
export declare const PLOT_EQUATION_ROW_HEIGHT = 42;
|
|
3
|
+
export declare const PLOT_EQUATION_TOP_PADDING = 8;
|
|
4
|
+
export declare const PLOT_EQUATION_BOTTOM_PADDING = 8;
|
|
5
|
+
export declare const PLOT_EQUATION_MIN_HEIGHT = 52;
|
|
6
|
+
export declare const PLOT_EQUATION_PANEL_WIDTH = 190;
|
|
7
|
+
export declare const PLOT_EQUATION_PANEL_MAX_WIDTH = 440;
|
|
8
|
+
export declare const PLOT_EQUATION_PANEL_GAP = 8;
|
|
9
|
+
export declare const PLOT_EQUATION_PANEL_DEFAULT_TOP = 10;
|
|
10
|
+
export declare function getPlotEquations(plot: PlotFunction): PlotEquation[];
|
|
11
|
+
export declare function getPlotEquationAreaHeight(plot: PlotFunction): number;
|
|
12
|
+
export declare function getPlotEquationPanelWidth(plot: PlotFunction): number;
|
|
13
|
+
export declare function getPlotEquationTextWidth(panelWidth: number): number;
|
|
14
|
+
export declare function getPlotEquationRowHeight(equation: PlotEquation, panelWidth: number): number;
|
|
15
|
+
export declare function getPlotEquationRowTop(plot: PlotFunction, index: number): number;
|
|
16
|
+
export declare function normalizePlot(plot: PlotFunction): PlotFunction;
|
|
@@ -10,6 +10,7 @@ type UseTextBlockRenderHelpersOptions = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare function useTextBlockRenderHelpers({ blockHeights, blockWidths, blocks, size, }: UseTextBlockRenderHelpersOptions): {
|
|
12
12
|
findTextBlockBlockingCreation: (x: number, y: number) => TextBlock | null;
|
|
13
|
+
findTextBlockNearPoint: (x: number, y: number) => TextBlock | null;
|
|
13
14
|
getTextMathAxisY: (block: TextBlock) => number | null;
|
|
14
15
|
};
|
|
15
16
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Stage } from "react-konva";
|
|
2
|
-
|
|
2
|
+
import type { MathJsonExpression } from "@cortex-js/compute-engine/math-json";
|
|
3
|
+
export type Tool = "select" | "pan" | "pen" | "eraser" | "text" | "graph" | "plot" | "matrix" | "table" | "geometry";
|
|
3
4
|
export type DrawingTool = "pen" | "eraser";
|
|
4
5
|
export type RenderMode = "plain" | "latex";
|
|
5
6
|
export type GeometryMode = "point" | "segment" | "angle" | "circle" | "label" | "midpoint" | "perpendicular" | "parallel" | "fixed" | "regular" | "rightAngle" | "equalSide";
|
|
@@ -58,6 +59,26 @@ export type GraphEdge = {
|
|
|
58
59
|
targetId: string;
|
|
59
60
|
directed?: boolean;
|
|
60
61
|
};
|
|
62
|
+
export type PlotEquation = {
|
|
63
|
+
id: string;
|
|
64
|
+
latex: string;
|
|
65
|
+
mathJson: MathJsonExpression | null;
|
|
66
|
+
color: string;
|
|
67
|
+
};
|
|
68
|
+
export type PlotFunction = {
|
|
69
|
+
id: string;
|
|
70
|
+
x: number;
|
|
71
|
+
y: number;
|
|
72
|
+
width: number;
|
|
73
|
+
height: number;
|
|
74
|
+
latex: string;
|
|
75
|
+
mathJson: MathJsonExpression | null;
|
|
76
|
+
color: string;
|
|
77
|
+
scale?: number;
|
|
78
|
+
equations?: PlotEquation[];
|
|
79
|
+
equationPanelX?: number;
|
|
80
|
+
equationPanelY?: number;
|
|
81
|
+
};
|
|
61
82
|
export type GraphClipboard = {
|
|
62
83
|
nodes: Array<GraphNode & {
|
|
63
84
|
offsetX: number;
|
|
@@ -174,6 +195,7 @@ export type CanvasState = {
|
|
|
174
195
|
blocks: TextBlock[];
|
|
175
196
|
graphNodes: GraphNode[];
|
|
176
197
|
graphEdges: GraphEdge[];
|
|
198
|
+
plots: PlotFunction[];
|
|
177
199
|
matrices: MatrixObject[];
|
|
178
200
|
tables: TableObject[];
|
|
179
201
|
geoPoints: GeoPoint[];
|