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,26 @@
|
|
|
1
|
+
export type InlineMathTextAtom = {
|
|
2
|
+
id: string;
|
|
3
|
+
type: "text";
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
export type InlineMathTokenAtom = {
|
|
7
|
+
id: string;
|
|
8
|
+
type: "math";
|
|
9
|
+
value: string;
|
|
10
|
+
displayMode: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type InlineMathAtom = InlineMathTextAtom | InlineMathTokenAtom;
|
|
13
|
+
export type InlineMathAtomRange = InlineMathAtom & {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
contentStart?: number;
|
|
17
|
+
contentEnd?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function normalizeInlineMathAtoms(atoms: InlineMathAtom[]): InlineMathAtom[];
|
|
20
|
+
export declare function parseInlineMathAtoms(content: string): InlineMathAtom[];
|
|
21
|
+
export declare function parseInlineMathAtomsWithRanges(content: string): InlineMathAtomRange[];
|
|
22
|
+
export declare function serializeInlineMathAtoms(atoms: InlineMathAtom[]): string;
|
|
23
|
+
export declare function insertInlineMathAtom(atoms: InlineMathAtom[], textAtomId: string, offset: number, createId: () => string): {
|
|
24
|
+
atoms: InlineMathAtom[];
|
|
25
|
+
insertedMathAtomId: string | null;
|
|
26
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type Dispatch, type RefObject, type SetStateAction } from "react";
|
|
2
|
+
import type { MathfieldElement } from "mathlive";
|
|
3
|
+
import { type InlineMathAtom } from "./inlineMathModel";
|
|
4
|
+
type RenderMode = "plain" | "latex";
|
|
5
|
+
type InlineMathEditingBlock = {
|
|
6
|
+
id: string;
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
renderMode: RenderMode;
|
|
10
|
+
};
|
|
11
|
+
export type ActiveInlineMathSession = {
|
|
12
|
+
atomId: string;
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
displayMode: boolean;
|
|
16
|
+
tailAfter?: string;
|
|
17
|
+
};
|
|
18
|
+
export type InlineMathPreview = {
|
|
19
|
+
expression: string;
|
|
20
|
+
fallback: string;
|
|
21
|
+
caretOffset?: number;
|
|
22
|
+
start?: number;
|
|
23
|
+
end?: number;
|
|
24
|
+
contentEnd?: number;
|
|
25
|
+
left: number;
|
|
26
|
+
top: number;
|
|
27
|
+
} | null;
|
|
28
|
+
type UseInlineMathSessionArgs = {
|
|
29
|
+
blocks: InlineMathEditingBlock[];
|
|
30
|
+
editingBlockId: string | null;
|
|
31
|
+
editingValue: string;
|
|
32
|
+
editingSelection: number;
|
|
33
|
+
editingInlineMathAtoms: InlineMathAtom[];
|
|
34
|
+
renderMode: RenderMode;
|
|
35
|
+
setEditingValue: Dispatch<SetStateAction<string>>;
|
|
36
|
+
setEditingSelection: Dispatch<SetStateAction<number>>;
|
|
37
|
+
setEditingInlineMathAtoms: Dispatch<SetStateAction<InlineMathAtom[]>>;
|
|
38
|
+
textareaRef: RefObject<HTMLTextAreaElement | null>;
|
|
39
|
+
inlineMathFieldRef: RefObject<MathfieldElement | null>;
|
|
40
|
+
createId: () => string;
|
|
41
|
+
latexPreviewMargin: number;
|
|
42
|
+
};
|
|
43
|
+
export declare function applyInlineMathSessionResolvedContent(content: string, session: ActiveInlineMathSession | null, latex: string): string;
|
|
44
|
+
export declare function getInlineMathSessionEffectiveLatex(content: string, session: ActiveInlineMathSession | null): string;
|
|
45
|
+
export declare function safeGetMathfieldLatex(field: MathfieldElement | null | undefined, fallback?: string): string | null;
|
|
46
|
+
export declare function useInlineMathSession({ blocks, editingBlockId, editingValue, editingSelection, editingInlineMathAtoms, renderMode, setEditingValue, setEditingSelection, setEditingInlineMathAtoms, textareaRef, inlineMathFieldRef, createId, latexPreviewMargin, }: UseInlineMathSessionArgs): {
|
|
47
|
+
activeInlineMathAtomId: string | null;
|
|
48
|
+
activeInlineMathDraft: string;
|
|
49
|
+
activeInlineMathSession: ActiveInlineMathSession | null;
|
|
50
|
+
activeInlineMathSessionRef: RefObject<ActiveInlineMathSession | null>;
|
|
51
|
+
editingDisplayValue: string;
|
|
52
|
+
inlineMathEditorMode: "mathlive" | "fallback";
|
|
53
|
+
isOpeningInlineMathSessionRef: RefObject<boolean>;
|
|
54
|
+
latexPreview: InlineMathPreview;
|
|
55
|
+
markInlineMathEditorReady: () => void;
|
|
56
|
+
handleInlineMathLatexChange: (latex: string) => void;
|
|
57
|
+
setActiveInlineMathDraft: Dispatch<SetStateAction<string>>;
|
|
58
|
+
activateInlineMathFallback: (fallbackLatex?: string) => void;
|
|
59
|
+
resetInlineMathState: () => void;
|
|
60
|
+
insertInlineMathAtSelection: (start: number, end: number) => void;
|
|
61
|
+
reopenInlineMathSessionAtBoundary: (direction: "before" | "after") => boolean;
|
|
62
|
+
commitActiveInlineMathDraft: () => void;
|
|
63
|
+
exitActiveInlineMathDraft: (direction: "before" | "after") => void;
|
|
64
|
+
cancelActiveInlineMathDraft: () => void;
|
|
65
|
+
getResolvedEditingValue: () => string;
|
|
66
|
+
};
|
|
67
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mathlean-canvas",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "git+https://github.com/KingArth0r/mathlean-canvas.git"
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
"homepage": "https://github.com/KingArth0r/mathlean-canvas#readme",
|
|
16
17
|
"exports": {
|
|
17
18
|
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
18
20
|
"import": "./dist/index.js"
|
|
19
21
|
}
|
|
20
22
|
},
|
|
@@ -28,7 +30,7 @@
|
|
|
28
30
|
],
|
|
29
31
|
"scripts": {
|
|
30
32
|
"dev": "vite",
|
|
31
|
-
"build": "tsc -b && vite build",
|
|
33
|
+
"build": "tsc -b && vite build && tsc -p tsconfig.types.json",
|
|
32
34
|
"build:demo": "vite build --mode demo",
|
|
33
35
|
"lint": "eslint .",
|
|
34
36
|
"preview": "vite preview --mode demo",
|
|
@@ -56,6 +58,8 @@
|
|
|
56
58
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
57
59
|
"eslint-plugin-react-refresh": "^0.5.2",
|
|
58
60
|
"globals": "^17.4.0",
|
|
61
|
+
"html2canvas": "^1.4.1",
|
|
62
|
+
"jspdf": "^4.2.1",
|
|
59
63
|
"typescript": "~5.9.3",
|
|
60
64
|
"typescript-eslint": "^8.57.0",
|
|
61
65
|
"vite": "^8.0.1"
|