@drghaliasri/butex 5.5.2 → 5.5.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 +66 -0
- package/dist/document.d.mts +5 -4
- package/dist/document.d.ts +5 -4
- package/dist/document.js +62 -0
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +61 -0
- package/dist/document.mjs.map +1 -1
- package/dist/document2.d.mts +20 -4
- package/dist/document2.d.ts +20 -4
- package/dist/document2.js +222 -6
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +221 -6
- package/dist/document2.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.map +1 -1
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2.d.mts +18 -3
- package/dist/react-document2.d.ts +18 -3
- package/dist/react-document2.js +247 -7
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +247 -7
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document.mjs
CHANGED
|
@@ -346,6 +346,66 @@ function fromMathObjectJson(json, mode = "english") {
|
|
|
346
346
|
closing: json.closing
|
|
347
347
|
};
|
|
348
348
|
}
|
|
349
|
+
function scriptsToJson(node, path) {
|
|
350
|
+
return {
|
|
351
|
+
...node.superscript ? { superscript: chainToJson(node.superscript, `${path}.superscript`) } : {},
|
|
352
|
+
...node.subscript ? { subscript: chainToJson(node.subscript, `${path}.subscript`) } : {}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function nodeToJson(node, path) {
|
|
356
|
+
const scripts = scriptsToJson(node, path);
|
|
357
|
+
if (node instanceof CharNode || node instanceof NumberNode || node instanceof OperatorNode) {
|
|
358
|
+
return { node_type: node.nodeType, expr: node.expr, ...scripts };
|
|
359
|
+
}
|
|
360
|
+
if (node instanceof DelimiterNode) {
|
|
361
|
+
return {
|
|
362
|
+
node_type: "DelimiterObject",
|
|
363
|
+
left_delim_expr: node.leftDelimExpr,
|
|
364
|
+
inner_expr: chainToJson(node.innerExpr, `${path}.inner_expr`),
|
|
365
|
+
right_delim_expr: node.rightDelimExpr,
|
|
366
|
+
...scripts
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
if (node instanceof CommandNode) {
|
|
370
|
+
return {
|
|
371
|
+
node_type: "CommandObject",
|
|
372
|
+
name: node.name,
|
|
373
|
+
optional_args: node.optionalArgs.map((arg, index) => chainToJson(arg, `${path}.optional_args[${String(index)}]`)),
|
|
374
|
+
mandatory_args: node.mandatoryArgs.map((arg, index) => chainToJson(arg, `${path}.mandatory_args[${String(index)}]`)),
|
|
375
|
+
...scripts
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
if (node instanceof EnvNode) {
|
|
379
|
+
return {
|
|
380
|
+
node_type: "EnvObject",
|
|
381
|
+
opening: node.opening,
|
|
382
|
+
lines: node.lines.map((line, index) => chainToJson(line, `${path}.lines[${String(index)}]`)),
|
|
383
|
+
closing: node.closing,
|
|
384
|
+
...scripts
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
throw new Error(`Unsupported runtime math node at ${path}: ${node.nodeType}`);
|
|
388
|
+
}
|
|
389
|
+
function chainToJson(chain, path) {
|
|
390
|
+
if (!(chain instanceof ChainNode)) {
|
|
391
|
+
throw new Error(`Expected live ChainNode at ${path}`);
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
node_type: "ChainClass",
|
|
395
|
+
chain: chain.chain.map((node, index) => nodeToJson(node, `${path}.chain[${String(index)}]`))
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function toMathObjectJson(math) {
|
|
399
|
+
if (math.nodeType !== "MathObject" || !Array.isArray(math.lines) || math.lines.length === 0) {
|
|
400
|
+
throw new Error("Cannot serialize invalid runtime MathObject");
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
node_type: "MathObject",
|
|
404
|
+
math_mode: math.mathMode,
|
|
405
|
+
lines: math.lines.map((line, index) => chainToJson(line, `$.lines[${String(index)}]`)),
|
|
406
|
+
closing: math.closing
|
|
407
|
+
};
|
|
408
|
+
}
|
|
349
409
|
function renderMathNodeLatex(math) {
|
|
350
410
|
const lines = math.lines.map((line) => line.arabicLatex());
|
|
351
411
|
if (math.mathMode === "$" || math.mathMode === "\\(") {
|
|
@@ -3255,6 +3315,7 @@ export {
|
|
|
3255
3315
|
renderMathNodeLatex,
|
|
3256
3316
|
replaceMathSpanFromEditor,
|
|
3257
3317
|
replaceMathSpanSource,
|
|
3318
|
+
toMathObjectJson,
|
|
3258
3319
|
updateImageBlock,
|
|
3259
3320
|
updateListItemValue,
|
|
3260
3321
|
updateRawBlockValue,
|