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 CHANGED
@@ -1,133 +1,99 @@
1
- # anees-mathchem-editor
1
+ # Digi Math & Chem Vanilla Editor
2
2
 
3
- A standalone custom Math and Chemistry editor package. It provides an intuitive UI for rendering Math and Chemistry formulas using MathLive.
3
+ Standalone Vanilla JavaScript, HTML, and CSS custom Math and Chemistry formula editor using MathLive.
4
4
 
5
- ## Installation
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
- ```bash
8
- npm install anees-mathchem-editor
9
- ```
13
+ ---
10
14
 
11
- ```bash
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
- export default App;
17
+ ```bash
18
+ npm install digi-mathchem-editor
52
19
  ```
53
20
 
54
- ## Props
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
- ## Using in Angular
69
-
70
- Since `anees-mathchem-editor` is a React component, you can use it in Angular by rendering it dynamically into an Angular element using `react` and `react-dom`.
71
-
72
- **1. Install React dependencies:**
73
- ```bash
74
- npm install react react-dom
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
- ```bash
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
- **2. Create an Angular wrapper component:**
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, ElementRef, OnInit, OnDestroy, ViewChild, ViewEncapsulation } from '@angular/core';
86
- import * as React from 'react';
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-editor-wrapper',
94
- template: \`<div #editorContainer></div>\`,
95
- encapsulation: ViewEncapsulation.None
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 MathEditorWrapperComponent implements OnInit, OnDestroy {
98
- @ViewChild('editorContainer', { static: true }) editorContainer!: ElementRef;
99
- private root: any;
72
+ export class MathDemoComponent implements OnInit, OnDestroy {
73
+ editor: any;
74
+ currentLatex: string = '\\frac{a}{b}';
100
75
 
101
76
  ngOnInit() {
102
- // Create a React root
103
- this.root = createRoot(this.editorContainer.nativeElement);
104
- this.renderReactComponent();
77
+ this.editor = new DigiMathChemEditor({
78
+ onInsert: (latex: string) => {
79
+ this.currentLatex = latex;
80
+ }
81
+ });
105
82
  }
106
83
 
107
- ngOnDestroy() {
108
- // Clean up React tree when Angular component is destroyed
109
- if (this.root) {
110
- this.root.unmount();
111
- }
84
+ openEditor() {
85
+ this.editor.open(this.currentLatex);
112
86
  }
113
87
 
114
- renderReactComponent() {
115
- this.root.render(
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
- This method mounts the React component securely inside your Angular view, allowing them to coexist and pass data smoothly.
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.