digi-mathchem-editor 1.0.26 → 1.0.27
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 +70 -104
- package/dist/digi-mathchem-editor.es.js +6461 -2569
- package/dist/digi-mathchem-editor.umd.js +94 -9
- package/dist/style.css +1 -1
- package/package.json +7 -11
package/README.md
CHANGED
|
@@ -1,133 +1,99 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Digi Math & Chem Vanilla Editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Standalone Vanilla JavaScript, HTML, and CSS custom Math and Chemistry formula editor using MathLive.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
- **Zero React Dependency**: Framework agnostic, works in Plain HTML, Angular, Vue, Svelte, or React.
|
|
7
|
+
- **Zero CKEditor Dependency**: Standalone modal editor and clickable formula widgets anywhere in your app.
|
|
8
|
+
- **MathLive Powered**: Fast, accurate LaTeX and chemistry formula rendering.
|
|
9
|
+
- **Full Symbol Palettes**: Fractions, roots, matrices, calculus, Greek symbols, and chemistry bonds/arrows.
|
|
10
|
+
- **Special Characters Modal**: Unicode symbol selector with search.
|
|
11
|
+
- **Clickable Math Widget**: Renders formulas beautifully as interactive badges that open the editor on click.
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
npm install anees-mathchem-editor
|
|
9
|
-
```
|
|
13
|
+
---
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
npm install anees-mathchem-editor mathlive @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons @fortawesome/react-fontawesome
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```jsx
|
|
18
|
-
import React, { useState } from 'react';
|
|
19
|
-
import { CustomMathEditor } from 'anees-mathchem-editor';
|
|
20
|
-
import 'anees-mathchem-editor/dist/style.css'; // Don't forget to import the styles!
|
|
21
|
-
|
|
22
|
-
function App() {
|
|
23
|
-
const [isEditorOpen, setIsEditorOpen] = useState(false);
|
|
24
|
-
const [mode, setMode] = useState('math'); // 'math' or 'chem'
|
|
25
|
-
|
|
26
|
-
const handleInsert = (latex) => {
|
|
27
|
-
console.log("Inserted LaTeX:", latex);
|
|
28
|
-
// Handle the inserted latex formula...
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div>
|
|
33
|
-
<button onClick={() => { setMode('math'); setIsEditorOpen(true); }}>
|
|
34
|
-
Open Math Editor
|
|
35
|
-
</button>
|
|
36
|
-
<button onClick={() => { setMode('chem'); setIsEditorOpen(true); }}>
|
|
37
|
-
Open Chemistry Editor
|
|
38
|
-
</button>
|
|
39
|
-
|
|
40
|
-
<CustomMathEditor
|
|
41
|
-
isOpen={isEditorOpen}
|
|
42
|
-
mode={mode}
|
|
43
|
-
initialValue=""
|
|
44
|
-
onInsert={handleInsert}
|
|
45
|
-
onClose={() => setIsEditorOpen(false)}
|
|
46
|
-
/>
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
15
|
+
## Installation
|
|
50
16
|
|
|
51
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npm install digi-mathchem-editor
|
|
52
19
|
```
|
|
53
20
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- `isOpen` (boolean): Controls the visibility of the editor popup.
|
|
57
|
-
- `mode` (string): Either `'math'` or `'chem'`.
|
|
58
|
-
- `initialValue` (string): Optional initial LaTeX value for the editor.
|
|
59
|
-
- `onInsert` (function): Callback function triggered when the user clicks the insert button. Receives the `latex` string as an argument.
|
|
60
|
-
- `onClose` (function): Callback function triggered when the user closes the editor.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
21
|
+
---
|
|
64
22
|
|
|
23
|
+
## Usage in Plain HTML / JavaScript
|
|
65
24
|
|
|
25
|
+
```html
|
|
26
|
+
<link rel="stylesheet" href="node_modules/digi-mathchem-editor/dist/style.css">
|
|
27
|
+
<script type="module">
|
|
28
|
+
import { DigiMathChemEditor, createMathWidget } from 'digi-mathchem-editor';
|
|
66
29
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
30
|
+
// 1. Standalone Popup Editor
|
|
31
|
+
const editor = new DigiMathChemEditor({
|
|
32
|
+
mode: 'math', // or 'chem'
|
|
33
|
+
onInsert: (latex) => {
|
|
34
|
+
console.log('Inserted LaTeX:', latex);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
document.getElementById('openBtn').addEventListener('click', () => {
|
|
39
|
+
editor.open('\\frac{1}{2}');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 2. Clickable Formula Widget
|
|
43
|
+
createMathWidget({
|
|
44
|
+
container: document.getElementById('formula-badge'),
|
|
45
|
+
latex: 'E = mc^2',
|
|
46
|
+
onUpdate: (newLatex) => console.log('Updated formula:', newLatex)
|
|
47
|
+
});
|
|
48
|
+
</script>
|
|
75
49
|
```
|
|
76
50
|
|
|
77
|
-
|
|
78
|
-
npm install anees-mathchem-editor react react-dom mathlive @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons @fortawesome/react-fontawesome
|
|
51
|
+
---
|
|
79
52
|
|
|
80
|
-
|
|
53
|
+
## Usage in Angular
|
|
81
54
|
|
|
82
|
-
|
|
55
|
+
### 1. Include CSS in `angular.json` or `styles.scss`
|
|
56
|
+
```scss
|
|
57
|
+
@import 'digi-mathchem-editor/dist/style.css';
|
|
58
|
+
```
|
|
83
59
|
|
|
60
|
+
### 2. Use in Component (`.ts`)
|
|
84
61
|
```typescript
|
|
85
|
-
import { Component,
|
|
86
|
-
import
|
|
87
|
-
import { createRoot } from 'react-dom/client';
|
|
88
|
-
import { CustomMathEditor } from 'anees-mathchem-editor';
|
|
89
|
-
// Import the styles in your styles.scss or component
|
|
90
|
-
import 'anees-mathchem-editor/dist/style.css';
|
|
62
|
+
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
63
|
+
import { DigiMathChemEditor } from 'digi-mathchem-editor';
|
|
91
64
|
|
|
92
65
|
@Component({
|
|
93
|
-
selector: 'app-math-
|
|
94
|
-
template:
|
|
95
|
-
|
|
66
|
+
selector: 'app-math-demo',
|
|
67
|
+
template: `
|
|
68
|
+
<button (click)="openEditor()">Open Editor</button>
|
|
69
|
+
<p>LaTeX: {{ currentLatex }}</p>
|
|
70
|
+
`
|
|
96
71
|
})
|
|
97
|
-
export class
|
|
98
|
-
|
|
99
|
-
|
|
72
|
+
export class MathDemoComponent implements OnInit, OnDestroy {
|
|
73
|
+
editor: any;
|
|
74
|
+
currentLatex: string = '\\frac{a}{b}';
|
|
100
75
|
|
|
101
76
|
ngOnInit() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
77
|
+
this.editor = new DigiMathChemEditor({
|
|
78
|
+
onInsert: (latex: string) => {
|
|
79
|
+
this.currentLatex = latex;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
105
82
|
}
|
|
106
83
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (this.root) {
|
|
110
|
-
this.root.unmount();
|
|
111
|
-
}
|
|
84
|
+
openEditor() {
|
|
85
|
+
this.editor.open(this.currentLatex);
|
|
112
86
|
}
|
|
113
87
|
|
|
114
|
-
|
|
115
|
-
this.
|
|
116
|
-
React.createElement(CustomMathEditor, {
|
|
117
|
-
isOpen: true,
|
|
118
|
-
mode: 'math',
|
|
119
|
-
initialValue: '',
|
|
120
|
-
onInsert: (latex: string) => {
|
|
121
|
-
console.log("Formula inserted:", latex);
|
|
122
|
-
// Handle logic...
|
|
123
|
-
},
|
|
124
|
-
onClose: () => {
|
|
125
|
-
console.log("Editor closed");
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
);
|
|
88
|
+
ngOnDestroy() {
|
|
89
|
+
this.editor?.destroy();
|
|
129
90
|
}
|
|
130
91
|
}
|
|
131
92
|
```
|
|
132
93
|
|
|
133
|
-
|
|
94
|
+
|
|
95
|
+
### When someone clones your project from Git:
|
|
96
|
+
|
|
97
|
+
They receive package.json.
|
|
98
|
+
They run npm install ➔ This creates node_modules and package-lock.json.
|
|
99
|
+
They run npm run build ➔ This creates the dist/ folder.
|