@drghaliasri/butex 5.5.2 → 5.5.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/README.md +73 -3
- package/dist/document.d.mts +6 -5
- package/dist/document.d.ts +6 -5
- package/dist/document.js +171 -24
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +170 -24
- package/dist/document.mjs.map +1 -1
- package/dist/document2.d.mts +21 -6
- package/dist/document2.d.ts +21 -6
- package/dist/document2.js +331 -51
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +330 -51
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.global.js +142 -89
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +142 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +142 -89
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.d.mts +2 -2
- package/dist/react-document.d.ts +2 -2
- package/dist/react-document.js +113 -55
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +113 -55
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2.d.mts +19 -4
- package/dist/react-document2.d.ts +19 -4
- package/dist/react-document2.js +365 -68
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +365 -68
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +99 -35
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +99 -35
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ Peer dependency: `mathjax` ^4.x (aligned with MathJax 4 components). If you use
|
|
|
61
61
|
2. Load BuTeX’s IIFE bundle (`dist/index.global.js` exposes global `BuTeX`).
|
|
62
62
|
3. In `MathJax.startup.ready`, call `BuTeX.registerBuTeX(MathJax)` before `MathJax.startup.defaultReady()`.
|
|
63
63
|
4. Inject styles once: `BuTeX.injectBuTeXStyles()` (or embed `BuTeX.BUTEX_CHROME_CSS` yourself).
|
|
64
|
-
5. When using **SVG** (`tex-svg.js`), call `BuTeX.registerBuTeXSvgTextWrapper(MathJax)` **after** `defaultReady()` so Takween/Diwani text, `\ad`, and Arabic atomic commands (`\arsin`, etc.) render in the preview with the correct fonts. CommonHTML (`tex-chtml.js`) uses the injected CSS classes instead.
|
|
64
|
+
5. When using **SVG** (`tex-svg.js`), call `BuTeX.registerBuTeXSvgTextWrapper(MathJax)` **after** `defaultReady()` so Takween/Diwani/Maghribi text, `\ad`, and Arabic atomic commands (`\arsin`, etc.) render in the preview with the correct fonts. CommonHTML (`tex-chtml.js`) uses the injected CSS classes instead.
|
|
65
65
|
6. Render math with `renderBuTeXMathIsland(tex, options?)` or mount into a host element via `mountBuTeXMathIsland(host, tex, options?)`. Pass `output: 'svg'` when the host loads `tex-svg.js`, or `output: 'chtml'` with `tex-chtml.js`. For raw Arabic TeX that did not come from the editor AST, pass `mirrorOperators: true` to wrap directional operators according to BuTeX's shared operator table. `ButexEditor` picks SVG vs CHTML automatically from the loaded MathJax bundle (`tex2svg` vs `tex2chtml`).
|
|
66
66
|
|
|
67
67
|
Ensure TeX `packages` includes `butex-arabic-math` (use `BUTEX_TEX_PACKAGE` in config when using `{ '[+]': [...] }`).
|
|
@@ -152,7 +152,7 @@ Use this when you want the same editor UX as the demo:
|
|
|
152
152
|
- Optionally pass `buttonElements` (undo/redo/copy/cut/split toggle) for auto button state refresh.
|
|
153
153
|
- Wire your toolbar/actions to runtime methods (`toggleSide`, `insertDelimiterByKind`, `addSup`, `addSub`, `removeSup`, `removeSub`, `deleteStructure`, `performUndo`, `performRedo`, `performCopy`, `performCut`, `performPaste`).
|
|
154
154
|
- Use `onSessionChange(session)` to render external previews (e.g., MathJax pane, status labels).
|
|
155
|
-
- **Imported `MathObject` / `CharObject` for the editor:** document LaTeX preview treats `CharObject.expr` as already-rendered Arabic TeX (e.g. `\text{م}`). When opening an imported equation in `<ButexEditor />` via `mathObjectToEditorSession`, BuTeX unwraps supported LaTeX text/font wrappers into plain glyph `expr` plus editor `characterFont`. Supported patterns: `\text{…}`, `\takween{…}`, `\diwani{…}`, `\butextakween{…}`, `\butexdiwani{…}`, `\butexdiwanioutline{…}`, and nested forms such as `\text{\takween{…}}`. On save, default-font chars stay plain `CharObject` nodes; non-default fonts are stored as font `CommandObject` wrappers so editor round-trip preserves `characterFont`. Upstream converters may still emit wrapped `expr` on import.
|
|
155
|
+
- **Imported `MathObject` / `CharObject` for the editor:** document LaTeX preview treats `CharObject.expr` as already-rendered Arabic TeX (e.g. `\text{م}`). When opening an imported equation in `<ButexEditor />` via `mathObjectToEditorSession`, BuTeX unwraps supported LaTeX text/font wrappers into plain glyph `expr` plus editor `characterFont`. Supported patterns: `\text{…}`, `\takween{…}`, `\diwani{…}`, `\butextakween{…}`, `\butexdiwani{…}`, `\butexdiwanioutline{…}`, `\butexmaghribi{…}`, and nested forms such as `\text{\takween{…}}`. On save, default-font chars stay plain `CharObject` nodes; non-default fonts are stored as font `CommandObject` wrappers so editor round-trip preserves `characterFont`. Upstream converters may still emit wrapped `expr` on import.
|
|
156
156
|
|
|
157
157
|
Minimal browser example:
|
|
158
158
|
|
|
@@ -254,7 +254,11 @@ const latex = document2Latex(documentNode);
|
|
|
254
254
|
const preview = document2Preview(documentNode, 'svg');
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
-
`document2Latex(doc)` emits a **complete Arabic XeLaTeX document** by default (preamble + `\begin{document}` + body + `\end{document}`). Structured and editor-authored Arabic roots serialize with the canonical `\arsqrt`; the bundled preamble also accepts raw legacy `\arabsqrt` with the same optional-index signature. Pass `{ wrapDocument: false }` for body-only blocks. Paragraph blocks export as `\par` followed by the inline content, so prose, citations, and math are not wrapped inside `\paragraph{...}`. Optional `digitsMapping: 'arabicdigits' | 'digits'` controls eastern vs western digit font mapping in the preamble (default `'arabicdigits'`). Pass `{ twocolumn: true }` for `\documentclass[12pt,a4paper,notitlepage,twocolumn]{article}` (title block stays in-column; figures use `\columnwidth`). See [`examples/example-latex-export.tex`](examples/example-latex-export.tex) for a full sample (regenerated by the wrap vitest). Hosts can also call `getArabicXeLatexPreamble()` alone.
|
|
257
|
+
`document2Latex(doc)` emits a **complete Arabic XeLaTeX document** by default (preamble + `\begin{document}` + body + `\end{document}`). Structured and editor-authored Arabic roots serialize with the canonical `\arsqrt`; the bundled preamble also accepts raw legacy `\arabsqrt` with the same optional-index signature. It defines BuTeX font wrappers (`\butextakween`, `\butexdiwani`, `\butexdiwanioutline`, `\butexmaghribi`) and the MathJax-compatible `\butexmirror` bridge. Pass `{ wrapDocument: false }` for body-only blocks. Paragraph blocks export as `\par` followed by the inline content, so prose, citations, and math are not wrapped inside `\paragraph{...}`. Optional `digitsMapping: 'arabicdigits' | 'digits'` controls eastern vs western digit font mapping in the preamble (default `'arabicdigits'`). Pass `{ twocolumn: true }` for `\documentclass[12pt,a4paper,notitlepage,twocolumn]{article}` (title block stays in-column; figures use `\columnwidth`). See [`examples/example-latex-export.tex`](examples/example-latex-export.tex) for a full sample (regenerated by the wrap vitest). Hosts can also call `getArabicXeLatexPreamble()` alone.
|
|
258
|
+
|
|
259
|
+
For XeLaTeX compiler images, install `src/fonts/Almaghribi-Warsh-Quran.otf` as a system font and refresh fontconfig (`fc-cache -f -v`). Verify with `fc-match "Almaghribi Warsh Quran"`; the preamble uses that installed family name.
|
|
260
|
+
|
|
261
|
+
To add another character font, add its metadata to `src/editor/characterFonts.ts` and its browser `@font-face` asset to `src/diwani-font.ts`.
|
|
258
262
|
|
|
259
263
|
Figures and tables always export as centered `figure` / `table` floats. Optional caption/label fields (checkbox-driven in the editor) emit `\caption` / `\label`. Display math stays `\[…\]` unless an equation label is enabled, then export uses `\begin{equation}…\label{…}\end{equation}`. Internal cross-refs use `\ref` / `\eqref` tokens (separate from bibliography `\cite`).
|
|
260
264
|
|
|
@@ -271,6 +275,7 @@ Rules:
|
|
|
271
275
|
- **Per field, not per document.** Each paragraph, heading, and list `item` carries its own `math_objects`.
|
|
272
276
|
- **Tables are the exception:** one flat `math_objects` array lives on the `\begin{tabular}` block and is consumed **row-major** across all cells (each cell takes as many entries as it has spans).
|
|
273
277
|
- **Missing `math_objects`** → the span renders as a non-editable raw math chip from its delimited source.
|
|
278
|
+
- **Mixed raw and structured math** uses `null` placeholders so every detected span still has one positional entry, for example `math_objects: [null, structuredMathObject]`. A labeled raw display span uses a `RawMathObject` positional metadata entry so its label survives without pretending the equation has an editable AST.
|
|
274
279
|
- The browser **does not** parse equation LaTeX bodies into `ChainClass`; structured chains come from `math_objects` (import) or the equation editor (GUI).
|
|
275
280
|
|
|
276
281
|
Paragraph with one inline span:
|
|
@@ -337,6 +342,57 @@ export default function Page() {
|
|
|
337
342
|
}
|
|
338
343
|
```
|
|
339
344
|
|
|
345
|
+
#### Persisting Document Editor v2 state
|
|
346
|
+
|
|
347
|
+
`Document2Node` is the live editor AST. It contains class-backed equation nodes and must not cross an API, database, local-storage, worker, or `JSON.stringify` boundary. Persist the canonical `Document2Json` wire format instead. The backend may store and return that JSON unchanged.
|
|
348
|
+
|
|
349
|
+
Use `onDocumentJsonChange` for a persistence-ready snapshot:
|
|
350
|
+
|
|
351
|
+
```tsx
|
|
352
|
+
'use client';
|
|
353
|
+
|
|
354
|
+
import { useRef } from 'react';
|
|
355
|
+
import { ButexDocumentEditor2 } from '@drghaliasri/butex/react-document2';
|
|
356
|
+
import type { Document2Json } from '@drghaliasri/butex/document2';
|
|
357
|
+
|
|
358
|
+
export function ArticleEditor({ loadedDocument }: { loadedDocument: Document2Json }) {
|
|
359
|
+
const latestDocument = useRef<Document2Json>(loadedDocument);
|
|
360
|
+
|
|
361
|
+
async function saveArticle() {
|
|
362
|
+
await fetch('/api/article', {
|
|
363
|
+
method: 'PUT',
|
|
364
|
+
headers: { 'content-type': 'application/json' },
|
|
365
|
+
body: JSON.stringify({ document: latestDocument.current }),
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<>
|
|
371
|
+
<ButexDocumentEditor2
|
|
372
|
+
initialDocument={loadedDocument}
|
|
373
|
+
editableEquations
|
|
374
|
+
onDocumentJsonChange={(json) => {
|
|
375
|
+
latestDocument.current = json;
|
|
376
|
+
}}
|
|
377
|
+
/>
|
|
378
|
+
<button type="button" onClick={saveArticle}>Save</button>
|
|
379
|
+
</>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
`onDocumentChange` remains available for hosts that need the live AST. Convert it before persistence with `toDocumentJson2`:
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
import { toDocumentJson2 } from '@drghaliasri/butex/document2';
|
|
388
|
+
|
|
389
|
+
onDocumentChange={(node) => {
|
|
390
|
+
latestDocument.current = toDocumentJson2(node);
|
|
391
|
+
}}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Do not call `JSON.stringify(documentNode)` directly. JSON serialization removes `CharNode`, `CommandNode`, and other equation prototypes: the saved TeX source can still render in preview, but the structured equation cannot reopen in the editor. Also do not feed every change callback back into `initialDocument`; that prop is for initial or externally loaded data, and changing it resets the editor state and undo history. Keep the current save snapshot in a ref or separate state that is not passed back as `initialDocument`. Change callbacks run during editing, so debounce network autosaves or save explicitly.
|
|
395
|
+
|
|
340
396
|
Host apps still register BuTeX with MathJax before preview rendering. `uiLocale` selects Arabic (`"ar"`, the default) or English (`"en"`) document-editor chrome and is passed to the embedded equation editor. `documentDirection` independently controls prose inputs and preview flow without creating a second document tree. `equationSide` independently controls whether structured equations open, render, and save from the `"english"` or `"arabic"` side. Set `editableEquations={false}` to show math islands without equation insertion, deletion, or editor access. Set `previewOnly={true}` to render only the read-only document preview with no toolbar, editor panel, or equation drawer. Optional `\includegraphics` `asset_id` is preserved on import; pass `resolveImageUrl={({ assetId, value }) => …})` so preview can load S3/CDN/local assets while plain `value` URLs keep working without a resolver. Document JSON may include root `meta` (`title`, `authors`, structured Hijri `date` `{ day, month, year }` with Arabic month names such as `"محرم"`, `abstract`) plus a `references` catalog (`key`, `authors`, `title`, `year`, `url`, `venue`) and `\cite{key1,key2}` spans in text values. Pass `documentMeta` to seed missing meta fields from the host; JSON keys win when present. The editor always centers a fixed basmala line before the title block and a closing ḥamdala after the body (preview + LaTeX). Hijri date uses day/month/year dropdowns (no calendar conversion; default year 1448). The editor shows numeric cite chips and a bibliography block. RTL preview/chips render reversed labels such as `[٣،٢،١]` (Arabic comma); LTR stays `[1, 2, 3]`. Pass `digitForm` (`western` / `arabicIndic` / `persianIndic`, defaulting from `documentDirection`) or use the toolbar digit control. LaTeX export keeps logical `\cite{…}` key order for XeLaTeX; digit shaping and bidi display in PDF belong in the host preamble (`bidi`/polyglossia + font `Mapping`, see `references/commands.py`). Range compression (`[3–7]`) is not implemented yet. Raw-only equations keep their original source because the browser does not parse raw LaTeX into equation ASTs. Document editor v2 defaults to **`tex-svg.js`**; use `tex-chtml.js` only if you pass `mathOutput="chtml"`.
|
|
341
397
|
|
|
342
398
|
### Styling/theming contract
|
|
@@ -346,6 +402,20 @@ Host apps still register BuTeX with MathJax before preview rendering. `uiLocale`
|
|
|
346
402
|
- Document editor theming is scoped under `.butex-document-widget`. Override `--butex-document-*` variables on that root or an ancestor, especially `--butex-document-bg`, `--butex-document-fg`, `--butex-document-panel`, `--butex-document-border`, `--butex-document-accent`, `--butex-document-preview-bg`, `--butex-document-drawer-bg`, `--butex-document-input-bg`, `--butex-document-table-border`, `--butex-document-math-bg`, and `--butex-document-dev-bg`.
|
|
347
403
|
- Document editor v2 theming is scoped under `.butex-document2-widget`. Override `--butex-document2-*` variables on that root or an ancestor; defaults inherit from the existing `--butex-*` variables where practical, including accent, panel, border, preview, focus, danger/error, and debug colors. The embedded equation editor opens as a centered modal (backdrop + panel); its BuTeX chrome reads the same `--butex-document2-*` tokens via a scoped bridge, so hosts normally theme once on `.butex-document2-widget` without a second equation theme. The built-in editor uses a **sticky compact icon toolbar** (Arabic `نص` formatting icons, heading glyphs, inline `$…$` vs display `\[…\]` math buttons with tooltips, a labeled references menu, and a table size popover), **focus-aware block insertion** after the active block, **↑/↓ block reorder**, **math delete** (chip × and drawer button), **document undo/redo** (toolbar + Ctrl/⌘Z, Ctrl/⌘Shift+Z, Ctrl+Y) via AST snapshots, and theme-tinted block cards. Preview tables use fixed black cell borders; raw `\raw` blocks stay out of preview until dedicated rendering exists.
|
|
348
404
|
|
|
405
|
+
#### Keeping the Document Editor v2 toolbar sticky
|
|
406
|
+
|
|
407
|
+
`<ButexDocumentEditor2 />` injects `style#butex-document2-widget-styles`; its main toolbar ships with `position: sticky`, `top: 0`, and a stacking layer. If a strict CSP blocks injected inline styles, embed `DOCUMENT2_WIDGET_CSS` through the host's approved global stylesheet or nonced style path, after Tailwind Preflight or other resets.
|
|
408
|
+
|
|
409
|
+
Do not override `.butex-document2-widget__toolbar` with `position: static`, `position: fixed`, a lower stacking layer, or an unrelated `top`. Avoid `overflow: auto`, `scroll`, or `hidden` on editor ancestors unless that ancestor is intentionally the constrained vertical scrolling container; sticky positioning follows the nearest such ancestor. `overflow-x: clip` by itself does not require an override. For a fixed application header, keep the toolbar sticky and apply only a scoped offset:
|
|
410
|
+
|
|
411
|
+
```css
|
|
412
|
+
.article-editor .butex-document2-widget__toolbar {
|
|
413
|
+
top: var(--app-header-height, 0px);
|
|
414
|
+
}
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
When diagnosing host CSS, verify that `#butex-document2-widget-styles` exists and that `getComputedStyle(toolbar).position` is `sticky` before adding overrides.
|
|
418
|
+
|
|
349
419
|
## Demo
|
|
350
420
|
|
|
351
421
|
From repo root (after `npm run build`):
|
package/dist/document.d.mts
CHANGED
|
@@ -60,7 +60,7 @@ type DocumentJson = {
|
|
|
60
60
|
type DocumentBlockJson = {
|
|
61
61
|
command: string;
|
|
62
62
|
value?: string;
|
|
63
|
-
math_objects?: MathObjectJson
|
|
63
|
+
math_objects?: Array<MathObjectJson | null>;
|
|
64
64
|
options?: Record<string, string>;
|
|
65
65
|
closing?: string;
|
|
66
66
|
items?: DocumentListItemJson[];
|
|
@@ -69,7 +69,7 @@ type DocumentBlockJson = {
|
|
|
69
69
|
};
|
|
70
70
|
type DocumentListItemJson = {
|
|
71
71
|
value: string;
|
|
72
|
-
math_objects?: MathObjectJson
|
|
72
|
+
math_objects?: Array<MathObjectJson | null>;
|
|
73
73
|
blocks?: DocumentBlockJson[];
|
|
74
74
|
};
|
|
75
75
|
type DocumentCommand = '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph' | '\\begin{itemize}' | '\\begin{enumerate}' | '\\begin{tabular}' | '\\includegraphics' | '\\raw';
|
|
@@ -156,6 +156,7 @@ declare function createImageBlock(value?: string, options?: Record<string, strin
|
|
|
156
156
|
declare function isSupportedDocumentCommand(command: string): command is DocumentCommand;
|
|
157
157
|
|
|
158
158
|
declare function fromMathObjectJson(json: unknown, mode?: DocumentParseMode): MathNode;
|
|
159
|
+
declare function toMathObjectJson(math: MathNode): MathObjectJson;
|
|
159
160
|
declare function renderMathNodeLatex(math: MathNode): string;
|
|
160
161
|
declare function isDisplayMathNode(math: MathNode): boolean;
|
|
161
162
|
|
|
@@ -164,7 +165,7 @@ type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 's
|
|
|
164
165
|
type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
|
|
165
166
|
type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
|
|
166
167
|
type EnvColumnAlignment = 'l' | 'c' | 'r';
|
|
167
|
-
type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline';
|
|
168
|
+
type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline' | 'maghribi';
|
|
168
169
|
type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
|
|
169
170
|
type EditorSyncState = 'synced' | 'diverged';
|
|
170
171
|
type EditorChain = {
|
|
@@ -250,7 +251,7 @@ declare function mathNodeFromEditorSession(session: EditorSession, mathMode?: st
|
|
|
250
251
|
declare function mathSourceFromEditorSession(session: EditorSession, mathMode?: string, closing?: string): string;
|
|
251
252
|
|
|
252
253
|
declare function detectMathSpans(value: string): DetectedMathSpan[];
|
|
253
|
-
declare function buildInlines(value: string, mathObjects?: MathObjectJson
|
|
254
|
+
declare function buildInlines(value: string, mathObjects?: Array<MathObjectJson | null>, mode?: DocumentParseMode): DocumentInline[];
|
|
254
255
|
|
|
255
256
|
declare function renderDocumentLatex(document: DocumentNode): string;
|
|
256
257
|
declare function buildDocumentPreview(document: DocumentNode): DocumentPreview;
|
|
@@ -307,4 +308,4 @@ declare function replaceMathSpanFromEditor(document: DocumentNode, target: Docum
|
|
|
307
308
|
declare function insertMathSpanFromEditor(document: DocumentNode, target: DocumentInlineTarget, insertAt: number, math: MathNode, source?: string): DocumentNode;
|
|
308
309
|
declare function documentInlineText(inlines: DocumentInline[]): string;
|
|
309
310
|
|
|
310
|
-
export { type DetectedMathSpan, type DocumentBlockJson, type DocumentBlockNode, type DocumentCommand, type DocumentInline, type DocumentInlineTarget, type DocumentJson, type DocumentListItemJson, type DocumentMathTarget, type DocumentNode, type DocumentParseMode, type DocumentPreview, type DocumentPreviewMathIsland, type ImageBlockNode, type ListBlockNode, type ListItemNode, type MathInline, type MathNode, type MathObjectJson, type NewDocumentBlockKind, type RawBlockNode, type TableBlockNode, type TextBlockNode, type TextInline, addDocumentBlock, addListItem, addNestedListBlock, addTableColumn, addTableRow, buildDocumentPreview, buildInlines, createDocumentBlock, createEmptyDocument, createImageBlock, createListBlock, createRawBlock, createTableBlock, createTextBlock, detectMathSpans, documentInlineText, fromDocumentJson, fromMathObjectJson, insertMathSpanFromEditor, isDisplayMathNode, isSupportedDocumentCommand, mathNodeFromEditorSession, mathSourceFromEditorSession, moveDocumentBlock, removeDocumentBlock, removeListItem, removeTableColumn, removeTableRow, renderDocumentLatex, renderMathNodeLatex, replaceMathSpanFromEditor, replaceMathSpanSource, updateImageBlock, updateListItemValue, updateRawBlockValue, updateTableCell, updateTableColumns, updateTextBlockValue };
|
|
311
|
+
export { type DetectedMathSpan, type DocumentBlockJson, type DocumentBlockNode, type DocumentCommand, type DocumentInline, type DocumentInlineTarget, type DocumentJson, type DocumentListItemJson, type DocumentMathTarget, type DocumentNode, type DocumentParseMode, type DocumentPreview, type DocumentPreviewMathIsland, type ImageBlockNode, type ListBlockNode, type ListItemNode, type MathInline, type MathNode, type MathObjectJson, type NewDocumentBlockKind, type RawBlockNode, type TableBlockNode, type TextBlockNode, type TextInline, addDocumentBlock, addListItem, addNestedListBlock, addTableColumn, addTableRow, buildDocumentPreview, buildInlines, createDocumentBlock, createEmptyDocument, createImageBlock, createListBlock, createRawBlock, createTableBlock, createTextBlock, detectMathSpans, documentInlineText, fromDocumentJson, fromMathObjectJson, insertMathSpanFromEditor, isDisplayMathNode, isSupportedDocumentCommand, mathNodeFromEditorSession, mathSourceFromEditorSession, moveDocumentBlock, removeDocumentBlock, removeListItem, removeTableColumn, removeTableRow, renderDocumentLatex, renderMathNodeLatex, replaceMathSpanFromEditor, replaceMathSpanSource, toMathObjectJson, updateImageBlock, updateListItemValue, updateRawBlockValue, updateTableCell, updateTableColumns, updateTextBlockValue };
|
package/dist/document.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ type DocumentJson = {
|
|
|
60
60
|
type DocumentBlockJson = {
|
|
61
61
|
command: string;
|
|
62
62
|
value?: string;
|
|
63
|
-
math_objects?: MathObjectJson
|
|
63
|
+
math_objects?: Array<MathObjectJson | null>;
|
|
64
64
|
options?: Record<string, string>;
|
|
65
65
|
closing?: string;
|
|
66
66
|
items?: DocumentListItemJson[];
|
|
@@ -69,7 +69,7 @@ type DocumentBlockJson = {
|
|
|
69
69
|
};
|
|
70
70
|
type DocumentListItemJson = {
|
|
71
71
|
value: string;
|
|
72
|
-
math_objects?: MathObjectJson
|
|
72
|
+
math_objects?: Array<MathObjectJson | null>;
|
|
73
73
|
blocks?: DocumentBlockJson[];
|
|
74
74
|
};
|
|
75
75
|
type DocumentCommand = '\\section' | '\\subsection' | '\\subsubsection' | '\\paragraph' | '\\begin{itemize}' | '\\begin{enumerate}' | '\\begin{tabular}' | '\\includegraphics' | '\\raw';
|
|
@@ -156,6 +156,7 @@ declare function createImageBlock(value?: string, options?: Record<string, strin
|
|
|
156
156
|
declare function isSupportedDocumentCommand(command: string): command is DocumentCommand;
|
|
157
157
|
|
|
158
158
|
declare function fromMathObjectJson(json: unknown, mode?: DocumentParseMode): MathNode;
|
|
159
|
+
declare function toMathObjectJson(math: MathNode): MathObjectJson;
|
|
159
160
|
declare function renderMathNodeLatex(math: MathNode): string;
|
|
160
161
|
declare function isDisplayMathNode(math: MathNode): boolean;
|
|
161
162
|
|
|
@@ -164,7 +165,7 @@ type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'frac' | 's
|
|
|
164
165
|
type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
|
|
165
166
|
type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
|
|
166
167
|
type EnvColumnAlignment = 'l' | 'c' | 'r';
|
|
167
|
-
type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline';
|
|
168
|
+
type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline' | 'maghribi';
|
|
168
169
|
type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
|
|
169
170
|
type EditorSyncState = 'synced' | 'diverged';
|
|
170
171
|
type EditorChain = {
|
|
@@ -250,7 +251,7 @@ declare function mathNodeFromEditorSession(session: EditorSession, mathMode?: st
|
|
|
250
251
|
declare function mathSourceFromEditorSession(session: EditorSession, mathMode?: string, closing?: string): string;
|
|
251
252
|
|
|
252
253
|
declare function detectMathSpans(value: string): DetectedMathSpan[];
|
|
253
|
-
declare function buildInlines(value: string, mathObjects?: MathObjectJson
|
|
254
|
+
declare function buildInlines(value: string, mathObjects?: Array<MathObjectJson | null>, mode?: DocumentParseMode): DocumentInline[];
|
|
254
255
|
|
|
255
256
|
declare function renderDocumentLatex(document: DocumentNode): string;
|
|
256
257
|
declare function buildDocumentPreview(document: DocumentNode): DocumentPreview;
|
|
@@ -307,4 +308,4 @@ declare function replaceMathSpanFromEditor(document: DocumentNode, target: Docum
|
|
|
307
308
|
declare function insertMathSpanFromEditor(document: DocumentNode, target: DocumentInlineTarget, insertAt: number, math: MathNode, source?: string): DocumentNode;
|
|
308
309
|
declare function documentInlineText(inlines: DocumentInline[]): string;
|
|
309
310
|
|
|
310
|
-
export { type DetectedMathSpan, type DocumentBlockJson, type DocumentBlockNode, type DocumentCommand, type DocumentInline, type DocumentInlineTarget, type DocumentJson, type DocumentListItemJson, type DocumentMathTarget, type DocumentNode, type DocumentParseMode, type DocumentPreview, type DocumentPreviewMathIsland, type ImageBlockNode, type ListBlockNode, type ListItemNode, type MathInline, type MathNode, type MathObjectJson, type NewDocumentBlockKind, type RawBlockNode, type TableBlockNode, type TextBlockNode, type TextInline, addDocumentBlock, addListItem, addNestedListBlock, addTableColumn, addTableRow, buildDocumentPreview, buildInlines, createDocumentBlock, createEmptyDocument, createImageBlock, createListBlock, createRawBlock, createTableBlock, createTextBlock, detectMathSpans, documentInlineText, fromDocumentJson, fromMathObjectJson, insertMathSpanFromEditor, isDisplayMathNode, isSupportedDocumentCommand, mathNodeFromEditorSession, mathSourceFromEditorSession, moveDocumentBlock, removeDocumentBlock, removeListItem, removeTableColumn, removeTableRow, renderDocumentLatex, renderMathNodeLatex, replaceMathSpanFromEditor, replaceMathSpanSource, updateImageBlock, updateListItemValue, updateRawBlockValue, updateTableCell, updateTableColumns, updateTextBlockValue };
|
|
311
|
+
export { type DetectedMathSpan, type DocumentBlockJson, type DocumentBlockNode, type DocumentCommand, type DocumentInline, type DocumentInlineTarget, type DocumentJson, type DocumentListItemJson, type DocumentMathTarget, type DocumentNode, type DocumentParseMode, type DocumentPreview, type DocumentPreviewMathIsland, type ImageBlockNode, type ListBlockNode, type ListItemNode, type MathInline, type MathNode, type MathObjectJson, type NewDocumentBlockKind, type RawBlockNode, type TableBlockNode, type TextBlockNode, type TextInline, addDocumentBlock, addListItem, addNestedListBlock, addTableColumn, addTableRow, buildDocumentPreview, buildInlines, createDocumentBlock, createEmptyDocument, createImageBlock, createListBlock, createRawBlock, createTableBlock, createTextBlock, detectMathSpans, documentInlineText, fromDocumentJson, fromMathObjectJson, insertMathSpanFromEditor, isDisplayMathNode, isSupportedDocumentCommand, mathNodeFromEditorSession, mathSourceFromEditorSession, moveDocumentBlock, removeDocumentBlock, removeListItem, removeTableColumn, removeTableRow, renderDocumentLatex, renderMathNodeLatex, replaceMathSpanFromEditor, replaceMathSpanSource, toMathObjectJson, updateImageBlock, updateListItemValue, updateRawBlockValue, updateTableCell, updateTableColumns, updateTextBlockValue };
|