@drghaliasri/butex 5.5.1 → 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/dist/document.mjs CHANGED
@@ -164,7 +164,7 @@ var CommandNode = class extends BaseAstNode {
164
164
  arabicLatex() {
165
165
  const sup = this.superscript !== null ? this.superscript.arabicLatex() : "";
166
166
  const sub = this.subscript !== null ? this.subscript.arabicLatex() : "";
167
- const arabicName = this.name === "\\sqrt" ? "\\arabsqrt" : this.name;
167
+ const arabicName = this.name === "\\sqrt" || this.name === "\\arabsqrt" ? "\\arsqrt" : this.name;
168
168
  const content = renderCommandCore({
169
169
  name: arabicName,
170
170
  optionalArgs: this.optionalArgs,
@@ -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 === "\\(") {
@@ -1835,7 +1895,7 @@ function renderNodeArabic(node, options) {
1835
1895
  return arabicScripts(node, content, options);
1836
1896
  }
1837
1897
  if (node.kind === "sqrt" && node.radicand) {
1838
- const content = `\\arabsqrt${optionalRootIndexArabic(node, options)}{${renderChainArabic(node.radicand, options)}}`;
1898
+ const content = `\\arsqrt${optionalRootIndexArabic(node, options)}{${renderChainArabic(node.radicand, options)}}`;
1839
1899
  return arabicScripts(node, content, options);
1840
1900
  }
1841
1901
  if (node.kind === "overset" && node.baseExpr) {
@@ -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,