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.
- package/README.md +213 -68
- package/dist/InlineMathLiveField.d.ts +17 -0
- package/dist/MathCanvas/components/CanvasOverlayViewport.d.ts +21 -0
- package/dist/MathCanvas/components/ObjectOverlays.d.ts +36 -0
- package/dist/MathCanvas/components/Toolbar.d.ts +34 -0
- package/dist/MathCanvas/components/icons.d.ts +58 -0
- package/dist/MathCanvas/constants.d.ts +70 -0
- package/dist/MathCanvas/core/hooks/useCanvasEditorFocus.d.ts +32 -0
- package/dist/MathCanvas/core/hooks/useCanvasGlobalActions.d.ts +41 -0
- package/dist/MathCanvas/core/hooks/useCanvasGlobalDragEffects.d.ts +35 -0
- package/dist/MathCanvas/core/hooks/useCanvasHistory.d.ts +13 -0
- package/dist/MathCanvas/core/hooks/useCanvasKeyboardShortcuts.d.ts +76 -0
- package/dist/MathCanvas/core/hooks/useCanvasSnapshot.d.ts +23 -0
- package/dist/MathCanvas/core/hooks/useCanvasStageInteractions.d.ts +103 -0
- package/dist/MathCanvas/core/hooks/useCanvasTransformers.d.ts +28 -0
- package/dist/MathCanvas/core/hooks/useCanvasViewport.d.ts +25 -0
- package/dist/MathCanvas/core/index.d.ts +9 -0
- package/dist/MathCanvas/features/geometry/components/CoordinatePlaneLayer.d.ts +15 -0
- package/dist/MathCanvas/features/geometry/components/GeometryLayer.d.ts +65 -0
- package/dist/MathCanvas/features/geometry/components/GeometryOverlays.d.ts +57 -0
- package/dist/MathCanvas/features/geometry/hooks/useGeometryCanvasActions.d.ts +29 -0
- package/dist/MathCanvas/features/geometry/hooks/useGeometryRenderData.d.ts +60 -0
- package/dist/MathCanvas/features/geometry/hooks/useGeometryState.d.ts +147 -0
- package/dist/MathCanvas/features/geometry/index.d.ts +6 -0
- package/dist/MathCanvas/features/graph/components/GraphLayer.d.ts +39 -0
- package/dist/MathCanvas/features/graph/components/GraphNodeEditor.d.ts +14 -0
- package/dist/MathCanvas/features/graph/hooks/useGraphCanvasActions.d.ts +44 -0
- package/dist/MathCanvas/features/graph/hooks/useGraphState.d.ts +77 -0
- package/dist/MathCanvas/features/graph/index.d.ts +4 -0
- package/dist/MathCanvas/features/grid/components/CellMathEditor.d.ts +17 -0
- package/dist/MathCanvas/features/grid/components/GridObjectOverlays.d.ts +71 -0
- package/dist/MathCanvas/features/grid/components/MatrixBlock.d.ts +20 -0
- package/dist/MathCanvas/features/grid/components/MatrixBrackets.d.ts +6 -0
- package/dist/MathCanvas/features/grid/components/MatrixEditorBlock.d.ts +50 -0
- package/dist/MathCanvas/features/grid/components/MatrixLayer.d.ts +31 -0
- package/dist/MathCanvas/features/grid/components/TableBlock.d.ts +21 -0
- package/dist/MathCanvas/features/grid/components/TableEditorBlock.d.ts +46 -0
- package/dist/MathCanvas/features/grid/hooks/useGridCanvasActions.d.ts +66 -0
- package/dist/MathCanvas/features/grid/hooks/useGridObjectState.d.ts +147 -0
- package/dist/MathCanvas/features/grid/index.d.ts +5 -0
- package/dist/MathCanvas/features/grid/utils/matrixOps.d.ts +36 -0
- package/dist/MathCanvas/features/stroke/components/StrokeLayer.d.ts +8 -0
- package/dist/MathCanvas/features/stroke/hooks/useStrokeState.d.ts +33 -0
- package/dist/MathCanvas/features/stroke/index.d.ts +2 -0
- package/dist/MathCanvas/features/text/components/BlockRenderers.d.ts +24 -0
- package/dist/MathCanvas/features/text/components/InlineMathBubble.d.ts +36 -0
- package/dist/MathCanvas/features/text/components/TextBlockEditor.d.ts +46 -0
- package/dist/MathCanvas/features/text/components/TextBlockMenu.d.ts +25 -0
- package/dist/MathCanvas/features/text/components/TextBlockView.d.ts +22 -0
- package/dist/MathCanvas/features/text/components/TextInteractionLayer.d.ts +29 -0
- package/dist/MathCanvas/features/text/hooks/useTextBlockActions.d.ts +40 -0
- package/dist/MathCanvas/features/text/hooks/useTextBlockEditingActions.d.ts +57 -0
- package/dist/MathCanvas/features/text/hooks/useTextBlockLayoutEffects.d.ts +62 -0
- package/dist/MathCanvas/features/text/hooks/useTextBlockRenderHelpers.d.ts +15 -0
- package/dist/MathCanvas/features/text/hooks/useTextboxResize.d.ts +19 -0
- package/dist/MathCanvas/features/text/index.d.ts +12 -0
- package/dist/MathCanvas/features/text/utils/textLayout.d.ts +33 -0
- package/dist/MathCanvas/types.d.ts +219 -0
- package/dist/MathCanvas/utils/geometryMath.d.ts +13 -0
- package/dist/MathCanvas/utils/graphDirection.d.ts +3 -0
- package/dist/MathCanvas/utils/latex.d.ts +20 -0
- package/dist/MathCanvas.d.ts +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11777 -10143
- package/dist/inlineMathModel.d.ts +26 -0
- package/dist/useInlineMathSession.d.ts +67 -0
- package/package.json +6 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CSSProperties } from "react";
|
|
2
|
+
import type { TextBlock, TextStyleRange, TextboxResizeAnchor } from "../../../types";
|
|
3
|
+
export declare function getBlockFontSize(block?: Pick<TextBlock, "fontSize"> | null): number;
|
|
4
|
+
export declare function normalizeTextStyleRanges(ranges: TextStyleRange[] | undefined, contentLength: number): {
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
id: string;
|
|
8
|
+
bold?: boolean;
|
|
9
|
+
italic?: boolean;
|
|
10
|
+
underline?: boolean;
|
|
11
|
+
color?: string;
|
|
12
|
+
}[];
|
|
13
|
+
export declare function getStyleRangeCss(range: TextStyleRange): CSSProperties;
|
|
14
|
+
export declare function mergeTextRangeStyles(ranges: TextStyleRange[]): CSSProperties;
|
|
15
|
+
export declare function renderStyledText(value: string, absoluteStart: number, ranges: TextStyleRange[], keyPrefix: string): " " | import("react").DetailedReactHTMLElement<{
|
|
16
|
+
key: string;
|
|
17
|
+
style: CSSProperties | undefined;
|
|
18
|
+
}, HTMLElement>[];
|
|
19
|
+
export declare function measureEditorTextWidth(content: string, fontSize?: number): number;
|
|
20
|
+
export declare function measureTextWidth(content: string, fontFamily: string, fontSize?: number): number;
|
|
21
|
+
export declare function clampTextBlockWidth(width: number, maxWidth: number): number;
|
|
22
|
+
export declare function getTextBlockWrapWidth(block: Pick<TextBlock, "width" | "manualWidth">, maxWidth: number): number;
|
|
23
|
+
export declare function getAutoTextBlockWidth(contentWidth: number, maxWidth: number): number;
|
|
24
|
+
export declare function clampTextFontSize(fontSize: number): number;
|
|
25
|
+
export declare function isTextboxSideAnchor(anchor: TextboxResizeAnchor): anchor is "middle-left" | "middle-right";
|
|
26
|
+
export declare function getTextboxResizeCursor(anchor: TextboxResizeAnchor): "ew-resize" | "nesw-resize" | "nwse-resize";
|
|
27
|
+
export declare function shouldTextBlockWrap(block: Pick<TextBlock, "manualWidth" | "width">, maxWidth?: number): boolean;
|
|
28
|
+
export declare function measureMirrorContentBounds(container: HTMLElement): {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
overflowsInline: boolean;
|
|
32
|
+
};
|
|
33
|
+
export declare function canRenderLatex(value: string): boolean;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { Stage } from "react-konva";
|
|
2
|
+
export type Tool = "select" | "pan" | "pen" | "eraser" | "text" | "graph" | "matrix" | "table" | "geometry";
|
|
3
|
+
export type DrawingTool = "pen" | "eraser";
|
|
4
|
+
export type RenderMode = "plain" | "latex";
|
|
5
|
+
export type GeometryMode = "point" | "segment" | "angle" | "circle" | "label" | "midpoint" | "perpendicular" | "parallel" | "fixed" | "regular" | "rightAngle" | "equalSide";
|
|
6
|
+
export type GeometryObjectKind = "point" | "segment" | "polygon" | "angle" | "circle";
|
|
7
|
+
export type GeometryDirection = "left" | "right" | "up" | "down";
|
|
8
|
+
export type GraphDirection = "upLeft" | "up" | "upRight" | "left" | "right" | "downLeft" | "down" | "downRight";
|
|
9
|
+
export type CoordinatePlaneMode = "blank" | "grid" | "plane";
|
|
10
|
+
export type GeometryLabelTarget = {
|
|
11
|
+
kind: "segment" | "angle" | "circle";
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
export type GeometryLabelOffset = {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
};
|
|
18
|
+
export type Stroke = {
|
|
19
|
+
id: string;
|
|
20
|
+
points: number[];
|
|
21
|
+
tool: DrawingTool;
|
|
22
|
+
strokeWidth?: number;
|
|
23
|
+
color?: string;
|
|
24
|
+
};
|
|
25
|
+
export type TextStyleRange = {
|
|
26
|
+
id: string;
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
bold?: boolean;
|
|
30
|
+
italic?: boolean;
|
|
31
|
+
underline?: boolean;
|
|
32
|
+
color?: string;
|
|
33
|
+
};
|
|
34
|
+
export type TextBlock = {
|
|
35
|
+
id: string;
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
content: string;
|
|
41
|
+
renderMode: RenderMode;
|
|
42
|
+
fontSize?: number;
|
|
43
|
+
manualWidth?: boolean;
|
|
44
|
+
styles?: TextStyleRange[];
|
|
45
|
+
};
|
|
46
|
+
export type GraphNode = {
|
|
47
|
+
id: string;
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
label: string;
|
|
53
|
+
shape: "circle";
|
|
54
|
+
};
|
|
55
|
+
export type GraphEdge = {
|
|
56
|
+
id: string;
|
|
57
|
+
sourceId: string;
|
|
58
|
+
targetId: string;
|
|
59
|
+
directed?: boolean;
|
|
60
|
+
};
|
|
61
|
+
export type GraphClipboard = {
|
|
62
|
+
nodes: Array<GraphNode & {
|
|
63
|
+
offsetX: number;
|
|
64
|
+
offsetY: number;
|
|
65
|
+
}>;
|
|
66
|
+
edges: GraphEdge[];
|
|
67
|
+
primaryNodeId: string;
|
|
68
|
+
};
|
|
69
|
+
export type TextboxResizeAnchor = "middle-left" | "middle-right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
70
|
+
export type TextboxResizeDrag = {
|
|
71
|
+
blockId: string;
|
|
72
|
+
anchor: TextboxResizeAnchor;
|
|
73
|
+
startClientX: number;
|
|
74
|
+
startClientY: number;
|
|
75
|
+
startX: number;
|
|
76
|
+
startY: number;
|
|
77
|
+
startWidth: number;
|
|
78
|
+
startHeight: number;
|
|
79
|
+
startFontSize: number;
|
|
80
|
+
didPushHistory: boolean;
|
|
81
|
+
};
|
|
82
|
+
export type MatrixObject = {
|
|
83
|
+
id: string;
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
rows: number;
|
|
87
|
+
cols: number;
|
|
88
|
+
cells: string[][];
|
|
89
|
+
rowSeparators: MatrixSeparator[];
|
|
90
|
+
colSeparators: MatrixSeparator[];
|
|
91
|
+
};
|
|
92
|
+
export type MatrixSeparatorSegment = {
|
|
93
|
+
index: number;
|
|
94
|
+
start: number;
|
|
95
|
+
end: number;
|
|
96
|
+
};
|
|
97
|
+
export type MatrixSeparator = number | MatrixSeparatorSegment;
|
|
98
|
+
export type TableObject = {
|
|
99
|
+
id: string;
|
|
100
|
+
x: number;
|
|
101
|
+
y: number;
|
|
102
|
+
rows: number;
|
|
103
|
+
cols: number;
|
|
104
|
+
cells: string[][];
|
|
105
|
+
};
|
|
106
|
+
export type GeoPoint = {
|
|
107
|
+
id: string;
|
|
108
|
+
x: number;
|
|
109
|
+
y: number;
|
|
110
|
+
label?: string;
|
|
111
|
+
derived?: {
|
|
112
|
+
kind: "midpoint";
|
|
113
|
+
a: string;
|
|
114
|
+
b: string;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
export type GeoSegment = {
|
|
118
|
+
id: string;
|
|
119
|
+
a: string;
|
|
120
|
+
b: string;
|
|
121
|
+
label?: string;
|
|
122
|
+
showLength?: boolean;
|
|
123
|
+
labelOffset?: GeometryLabelOffset;
|
|
124
|
+
equalMarker?: number;
|
|
125
|
+
};
|
|
126
|
+
export type GeoPolygon = {
|
|
127
|
+
id: string;
|
|
128
|
+
pointIds: string[];
|
|
129
|
+
label?: string;
|
|
130
|
+
};
|
|
131
|
+
export type GeoAngle = {
|
|
132
|
+
id: string;
|
|
133
|
+
a: string;
|
|
134
|
+
b: string;
|
|
135
|
+
c: string;
|
|
136
|
+
label?: string;
|
|
137
|
+
showArc?: boolean;
|
|
138
|
+
labelOffset?: GeometryLabelOffset;
|
|
139
|
+
};
|
|
140
|
+
export type GeoCircle = {
|
|
141
|
+
id: string;
|
|
142
|
+
centerId: string;
|
|
143
|
+
radiusPointId?: string;
|
|
144
|
+
radiusValue?: string;
|
|
145
|
+
label?: string;
|
|
146
|
+
labelOffset?: GeometryLabelOffset;
|
|
147
|
+
};
|
|
148
|
+
export type GeoHelperSegment = {
|
|
149
|
+
id: string;
|
|
150
|
+
kind: "perpendicular" | "parallel";
|
|
151
|
+
baseA: string;
|
|
152
|
+
baseB: string;
|
|
153
|
+
through: string;
|
|
154
|
+
length: number;
|
|
155
|
+
};
|
|
156
|
+
export type GeoRightAngleMarker = {
|
|
157
|
+
id: string;
|
|
158
|
+
a: string;
|
|
159
|
+
b: string;
|
|
160
|
+
c: string;
|
|
161
|
+
};
|
|
162
|
+
export type GridSelection = {
|
|
163
|
+
kind: "matrix" | "table";
|
|
164
|
+
id: string;
|
|
165
|
+
startRow: number;
|
|
166
|
+
endRow: number;
|
|
167
|
+
startCol: number;
|
|
168
|
+
endCol: number;
|
|
169
|
+
mode: "cell" | "row" | "column" | "upperTriangle" | "lowerTriangle" | "diagonal" | "antiDiagonal";
|
|
170
|
+
excludedCells?: string[];
|
|
171
|
+
};
|
|
172
|
+
export type CanvasState = {
|
|
173
|
+
strokes: Stroke[];
|
|
174
|
+
blocks: TextBlock[];
|
|
175
|
+
graphNodes: GraphNode[];
|
|
176
|
+
graphEdges: GraphEdge[];
|
|
177
|
+
matrices: MatrixObject[];
|
|
178
|
+
tables: TableObject[];
|
|
179
|
+
geoPoints: GeoPoint[];
|
|
180
|
+
geoSegments: GeoSegment[];
|
|
181
|
+
geoPolygons: GeoPolygon[];
|
|
182
|
+
geoAngles: GeoAngle[];
|
|
183
|
+
geoCircles: GeoCircle[];
|
|
184
|
+
geoHelperSegments: GeoHelperSegment[];
|
|
185
|
+
geoRightAngleMarkers: GeoRightAngleMarker[];
|
|
186
|
+
coordinatePlaneMode: CoordinatePlaneMode;
|
|
187
|
+
renderMode: RenderMode;
|
|
188
|
+
};
|
|
189
|
+
export type StageMouseEvent = Parameters<NonNullable<React.ComponentProps<typeof Stage>["onMouseDown"]>>[0];
|
|
190
|
+
export type StageTouchEvent = Parameters<NonNullable<React.ComponentProps<typeof Stage>["onTouchStart"]>>[0];
|
|
191
|
+
export type StagePointerEvent = StageMouseEvent | StageTouchEvent;
|
|
192
|
+
export type StageClickEvent = Parameters<NonNullable<React.ComponentProps<typeof Stage>["onClick"]>>[0];
|
|
193
|
+
export type StageTapEvent = Parameters<NonNullable<React.ComponentProps<typeof Stage>["onTap"]>>[0];
|
|
194
|
+
export type StageActivationEvent = StageClickEvent | StageTapEvent;
|
|
195
|
+
export type MathCanvasTheme = {
|
|
196
|
+
bg: string;
|
|
197
|
+
bgAlt: string;
|
|
198
|
+
surface: string;
|
|
199
|
+
surfaceHover: string;
|
|
200
|
+
border: string;
|
|
201
|
+
text: string;
|
|
202
|
+
textMuted: string;
|
|
203
|
+
danger: string;
|
|
204
|
+
dangerBorder: string;
|
|
205
|
+
dangerBg: string;
|
|
206
|
+
edge: string;
|
|
207
|
+
edgeActive: string;
|
|
208
|
+
node: string;
|
|
209
|
+
nodeHover: string;
|
|
210
|
+
nodeActive: string;
|
|
211
|
+
eraser: string;
|
|
212
|
+
};
|
|
213
|
+
export type MathCanvasProps = {
|
|
214
|
+
darkMode?: boolean;
|
|
215
|
+
className?: string;
|
|
216
|
+
style?: React.CSSProperties;
|
|
217
|
+
initialState?: CanvasState;
|
|
218
|
+
onStateChange?: (state: CanvasState) => void;
|
|
219
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GeoPoint } from "../types";
|
|
2
|
+
export declare function getPointLabel(index: number): string;
|
|
3
|
+
export declare function distanceToLineSegment(px: number, py: number, ax: number, ay: number, bx: number, by: number): number;
|
|
4
|
+
export declare function getAngleBetweenPoints(a: GeoPoint, b: GeoPoint, c: GeoPoint): {
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
delta: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function buildAngleArcPoints(a: GeoPoint, b: GeoPoint, c: GeoPoint, radius?: number): number[];
|
|
10
|
+
export declare function getAngleLabelPoint(a: GeoPoint, b: GeoPoint, c: GeoPoint, radius?: number): {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function shouldPreferDisplayStyle(expression: string, displayMode: boolean): boolean;
|
|
2
|
+
export declare function getPreferredRenderedLatex(expression: string, displayMode: boolean): string;
|
|
3
|
+
export declare function canRenderLatex(value: string): boolean;
|
|
4
|
+
export declare function parseLatexSegments(content: string): ({
|
|
5
|
+
id: string;
|
|
6
|
+
type: "math";
|
|
7
|
+
value: string;
|
|
8
|
+
fallback: string;
|
|
9
|
+
displayMode: boolean;
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
} | {
|
|
13
|
+
id: string;
|
|
14
|
+
type: "text";
|
|
15
|
+
value: string;
|
|
16
|
+
start: number;
|
|
17
|
+
end: number;
|
|
18
|
+
fallback?: undefined;
|
|
19
|
+
displayMode?: undefined;
|
|
20
|
+
})[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "katex/dist/katex.min.css";
|
|
2
|
+
import "mathlive";
|
|
3
|
+
import "mathlive/fonts.css";
|
|
4
|
+
import "mathlive/static.css";
|
|
5
|
+
export type { CanvasState, MathCanvasProps, GeoPoint, GeoSegment, GeoPolygon, GeoAngle, GeoCircle, GeoHelperSegment, GeoRightAngleMarker, } from "./MathCanvas/types";
|
|
6
|
+
import type { MathCanvasProps } from "./MathCanvas/types";
|
|
7
|
+
export default function MathCanvas({ darkMode, className, style, initialState, onStateChange }: MathCanvasProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/index.d.ts
ADDED