@drghaliasri/butex 7.1.4 → 7.2.0
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.d.mts +1 -2
- package/dist/document.d.ts +1 -2
- package/dist/document.js +55 -0
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +55 -0
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +297 -4
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +1 -1
- package/dist/document2.d.ts +1 -1
- package/dist/document2.js +66 -0
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +66 -0
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +129 -2
- package/dist/index.d.ts +129 -2
- package/dist/index.global.js +98 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +77 -0
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +77 -0
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2-preview.js +61 -0
- package/dist/react-document2-preview.js.map +1 -1
- package/dist/react-document2-preview.mjs +61 -0
- package/dist/react-document2-preview.mjs.map +1 -1
- package/dist/react-document2.d.mts +1 -1
- package/dist/react-document2.d.ts +1 -1
- package/dist/react-document2.js +118 -0
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +118 -0
- 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 +77 -0
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +77 -0
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document2-cli.js
CHANGED
|
@@ -2635,6 +2635,38 @@ function atomicOperatorCommandSpec(id) {
|
|
|
2635
2635
|
return Object.prototype.hasOwnProperty.call(ATOMIC_OPERATOR_COMMANDS, id) ? ATOMIC_OPERATOR_COMMANDS[id] : null;
|
|
2636
2636
|
}
|
|
2637
2637
|
|
|
2638
|
+
// src/editor/standardCommands.ts
|
|
2639
|
+
var STANDARD_COMMANDS = {
|
|
2640
|
+
"\\alpha": { tex: "\\alpha", label: "\u03B1", title: "alpha" },
|
|
2641
|
+
"\\beta": { tex: "\\beta", label: "\u03B2", title: "beta" },
|
|
2642
|
+
"\\gamma": { tex: "\\gamma", label: "\u03B3", title: "gamma" },
|
|
2643
|
+
"\\delta": { tex: "\\delta", label: "\u03B4", title: "delta" },
|
|
2644
|
+
"\\epsilon": { tex: "\\epsilon", label: "\u03B5", title: "epsilon" },
|
|
2645
|
+
"\\eta": { tex: "\\eta", label: "\u03B7", title: "eta" },
|
|
2646
|
+
"\\theta": { tex: "\\theta", label: "\u03B8", title: "theta" },
|
|
2647
|
+
"\\lambda": { tex: "\\lambda", label: "\u03BB", title: "lambda" },
|
|
2648
|
+
"\\mu": { tex: "\\mu", label: "\u03BC", title: "mu" },
|
|
2649
|
+
"\\rho": { tex: "\\rho", label: "\u03C1", title: "rho" },
|
|
2650
|
+
"\\sigma": { tex: "\\sigma", label: "\u03C3", title: "sigma" },
|
|
2651
|
+
"\\tau": { tex: "\\tau", label: "\u03C4", title: "tau" },
|
|
2652
|
+
"\\phi": { tex: "\\phi", label: "\u03C6", title: "phi" },
|
|
2653
|
+
"\\chi": { tex: "\\chi", label: "\u03C7", title: "chi" },
|
|
2654
|
+
"\\psi": { tex: "\\psi", label: "\u03C8", title: "psi" },
|
|
2655
|
+
"\\omega": { tex: "\\omega", label: "\u03C9", title: "omega" },
|
|
2656
|
+
"\\zeta": { tex: "\\zeta", label: "\u03B6", title: "zeta" },
|
|
2657
|
+
"\\nabla": { tex: "\\nabla", label: "\u2207", title: "nabla" },
|
|
2658
|
+
"\\Delta": { tex: "\\Delta", label: "\u0394", title: "Delta" },
|
|
2659
|
+
"\\partial": { tex: "\\partial", label: "\u2202", title: "partial derivative" },
|
|
2660
|
+
"\\Longleftrightarrow": { tex: "\\Longleftrightarrow", label: "\u27FA", title: "long equivalence arrow" },
|
|
2661
|
+
"\\backslash": { tex: "\\backslash", label: "\u2216", title: "reverse solidus" }
|
|
2662
|
+
};
|
|
2663
|
+
function standardCommandSpec(tex) {
|
|
2664
|
+
return Object.prototype.hasOwnProperty.call(STANDARD_COMMANDS, tex) ? STANDARD_COMMANDS[tex] : null;
|
|
2665
|
+
}
|
|
2666
|
+
function isStandardCommandTex(tex) {
|
|
2667
|
+
return standardCommandSpec(tex) !== null;
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2638
2670
|
// src/editor/factory.ts
|
|
2639
2671
|
var nextId2 = 1;
|
|
2640
2672
|
function makeId(prefix) {
|
|
@@ -3042,6 +3074,9 @@ function renderNodeEnglish(node, options) {
|
|
|
3042
3074
|
const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3043
3075
|
return `${body}${latinScripts(node, options)}`;
|
|
3044
3076
|
}
|
|
3077
|
+
if (node.kind === "standardCommand") {
|
|
3078
|
+
return `${node.expr}${latinScripts(node, options)}`;
|
|
3079
|
+
}
|
|
3045
3080
|
if (node.kind === "char") {
|
|
3046
3081
|
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
3047
3082
|
}
|
|
@@ -3090,6 +3125,9 @@ function renderNodeArabic(node, options) {
|
|
|
3090
3125
|
const content = spec?.mirror ? `\\butexmirror{${tex}}` : tex;
|
|
3091
3126
|
return arabicScripts(node, content, options);
|
|
3092
3127
|
}
|
|
3128
|
+
if (node.kind === "standardCommand") {
|
|
3129
|
+
return arabicScripts(node, node.expr, options);
|
|
3130
|
+
}
|
|
3093
3131
|
if (node.kind === "char") {
|
|
3094
3132
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3095
3133
|
const content = renderCharContent(node, options);
|
|
@@ -3615,6 +3653,19 @@ var ATOMIC_OPERATOR_COMMAND_CSS = `
|
|
|
3615
3653
|
}
|
|
3616
3654
|
`.trim();
|
|
3617
3655
|
|
|
3656
|
+
// src/editor/display/standardCommand.ts
|
|
3657
|
+
var STANDARD_COMMAND_CSS = `
|
|
3658
|
+
.standard-command {
|
|
3659
|
+
display: inline-flex;
|
|
3660
|
+
align-items: center;
|
|
3661
|
+
justify-content: center;
|
|
3662
|
+
min-width: 0.9em;
|
|
3663
|
+
font-family: "Cambria Math", "Times New Roman", serif;
|
|
3664
|
+
font-size: 1.05em;
|
|
3665
|
+
line-height: 1;
|
|
3666
|
+
}
|
|
3667
|
+
`.trim();
|
|
3668
|
+
|
|
3618
3669
|
// src/editor/styles.ts
|
|
3619
3670
|
var CHARACTER_FONT_CSS = NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.cssClass && font.browserFontStack).map((font) => `.${font.cssClass} {
|
|
3620
3671
|
font-family: ${font.browserFontStack};
|
|
@@ -3824,6 +3875,8 @@ ${MATRIX_ENV_CSS}
|
|
|
3824
3875
|
${ATOMIC_COMMAND_CSS}
|
|
3825
3876
|
|
|
3826
3877
|
${ATOMIC_OPERATOR_COMMAND_CSS}
|
|
3878
|
+
|
|
3879
|
+
${STANDARD_COMMAND_CSS}
|
|
3827
3880
|
`.trim();
|
|
3828
3881
|
|
|
3829
3882
|
// src/document/normalizeCharImport.ts
|
|
@@ -3901,6 +3954,14 @@ var COMMAND_FONT_MAP = Object.fromEntries([
|
|
|
3901
3954
|
var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
|
|
3902
3955
|
NON_DEFAULT_CHARACTER_FONT_SPECS.map((font) => [font.id, font.macro])
|
|
3903
3956
|
);
|
|
3957
|
+
function charEditorNodeToAstNode(node) {
|
|
3958
|
+
const font = node.characterFont ?? "default";
|
|
3959
|
+
const charNode = new CharNode(node.expr);
|
|
3960
|
+
if (font === "default") {
|
|
3961
|
+
return charNode;
|
|
3962
|
+
}
|
|
3963
|
+
return new CommandNode(CHAR_FONT_EXPORT_TEX[font], [], [new ChainNode([charNode])]);
|
|
3964
|
+
}
|
|
3904
3965
|
function commandIdForTex(tex) {
|
|
3905
3966
|
for (const spec of Object.values(ATOMIC_COMMANDS)) {
|
|
3906
3967
|
const renderTex = spec.arabicRenderTex;
|
|
@@ -4155,6 +4216,14 @@ function commandToEditorNode(node) {
|
|
|
4155
4216
|
}
|
|
4156
4217
|
return { editable: true, node: atomicOperator };
|
|
4157
4218
|
}
|
|
4219
|
+
if (isStandardCommandTex(node.name) && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4220
|
+
const standard = createEditorNode("standardCommand", node.name);
|
|
4221
|
+
const scripts = attachScripts(node, standard);
|
|
4222
|
+
if (scripts) {
|
|
4223
|
+
return scripts;
|
|
4224
|
+
}
|
|
4225
|
+
return { editable: true, node: standard };
|
|
4226
|
+
}
|
|
4158
4227
|
const textLike = charFromTextLikeCommand(node);
|
|
4159
4228
|
if (textLike) {
|
|
4160
4229
|
return textLike;
|
|
@@ -4268,6 +4337,192 @@ function mathObjectToEditorSession(math) {
|
|
|
4268
4337
|
session.sync = buildInitialSyncMap(session.englishTree, session.arabicTree);
|
|
4269
4338
|
return { editable: true, session: cloneEditorSession(session) };
|
|
4270
4339
|
}
|
|
4340
|
+
function attachAstScripts(editorNode, astNode) {
|
|
4341
|
+
if (editorNode.superscript) {
|
|
4342
|
+
const sup = editorChainToAstChain(editorNode.superscript);
|
|
4343
|
+
if (!sup.ok) {
|
|
4344
|
+
return sup;
|
|
4345
|
+
}
|
|
4346
|
+
astNode.superscript = sup.chain;
|
|
4347
|
+
}
|
|
4348
|
+
if (editorNode.subscript) {
|
|
4349
|
+
const sub = editorChainToAstChain(editorNode.subscript);
|
|
4350
|
+
if (!sub.ok) {
|
|
4351
|
+
return sub;
|
|
4352
|
+
}
|
|
4353
|
+
astNode.subscript = sub.chain;
|
|
4354
|
+
}
|
|
4355
|
+
return null;
|
|
4356
|
+
}
|
|
4357
|
+
function editorEnvOpening(node) {
|
|
4358
|
+
const envName = node.envName ?? node.matrixStyle;
|
|
4359
|
+
if (!envName) {
|
|
4360
|
+
return null;
|
|
4361
|
+
}
|
|
4362
|
+
if (envName === "array") {
|
|
4363
|
+
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows?.[0]?.length ?? 0).join("") || "c";
|
|
4364
|
+
return { opening: `\\begin{array}{${spec}}`, closing: "\\end{array}" };
|
|
4365
|
+
}
|
|
4366
|
+
return { opening: `\\begin{${envName}}`, closing: `\\end{${envName}}` };
|
|
4367
|
+
}
|
|
4368
|
+
function editorEnvToAstNode(node) {
|
|
4369
|
+
const wrapper = editorEnvOpening(node);
|
|
4370
|
+
if (!wrapper || !node.matrixRows) {
|
|
4371
|
+
return { ok: false, reason: "\u0628\u064A\u0626\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627" };
|
|
4372
|
+
}
|
|
4373
|
+
const lines = [];
|
|
4374
|
+
for (const row of node.matrixRows) {
|
|
4375
|
+
const lineNodes = [];
|
|
4376
|
+
for (let columnIndex = 0; columnIndex < row.length; columnIndex += 1) {
|
|
4377
|
+
if (columnIndex > 0) {
|
|
4378
|
+
lineNodes.push(new OperatorNode("&"));
|
|
4379
|
+
}
|
|
4380
|
+
const cell = editorChainToAstChain(row[columnIndex]);
|
|
4381
|
+
if (!cell.ok) {
|
|
4382
|
+
return cell;
|
|
4383
|
+
}
|
|
4384
|
+
lineNodes.push(...cell.chain.chain);
|
|
4385
|
+
}
|
|
4386
|
+
lines.push(new ChainNode(lineNodes));
|
|
4387
|
+
}
|
|
4388
|
+
const env = new EnvNode(wrapper.opening, lines, wrapper.closing);
|
|
4389
|
+
const scripts = attachAstScripts(node, env);
|
|
4390
|
+
return scripts ?? { ok: true, node: env };
|
|
4391
|
+
}
|
|
4392
|
+
function accentChainForExport(accent) {
|
|
4393
|
+
if (!accent) {
|
|
4394
|
+
return { ok: true, chain: new ChainNode([]) };
|
|
4395
|
+
}
|
|
4396
|
+
return editorChainToAstChain(accent);
|
|
4397
|
+
}
|
|
4398
|
+
function nodeFromAccentBase(command, accent, base) {
|
|
4399
|
+
if (accent.chain.length > 0) {
|
|
4400
|
+
return new CommandNode(command, [], [accent, base]);
|
|
4401
|
+
}
|
|
4402
|
+
if (base.chain.length === 1) {
|
|
4403
|
+
return base.chain[0];
|
|
4404
|
+
}
|
|
4405
|
+
return new DelimiterNode("", base, "");
|
|
4406
|
+
}
|
|
4407
|
+
function editorNodeToAstNode(node) {
|
|
4408
|
+
let astNode;
|
|
4409
|
+
if (node.kind === "char") {
|
|
4410
|
+
astNode = charEditorNodeToAstNode(node);
|
|
4411
|
+
} else if (node.kind === "number") {
|
|
4412
|
+
astNode = new NumberNode(node.expr);
|
|
4413
|
+
} else if (node.kind === "operator") {
|
|
4414
|
+
astNode = new OperatorNode(node.expr);
|
|
4415
|
+
} else if (node.kind === "delimiter" && node.innerExpr) {
|
|
4416
|
+
const inner = editorChainToAstChain(node.innerExpr);
|
|
4417
|
+
if (!inner.ok) {
|
|
4418
|
+
return inner;
|
|
4419
|
+
}
|
|
4420
|
+
astNode = new DelimiterNode(node.leftDelimExpr, inner.chain, node.rightDelimExpr);
|
|
4421
|
+
} else if (node.kind === "frac" && node.numerator && node.denominator) {
|
|
4422
|
+
const numerator = editorChainToAstChain(node.numerator);
|
|
4423
|
+
const denominator = editorChainToAstChain(node.denominator);
|
|
4424
|
+
if (!numerator.ok) {
|
|
4425
|
+
return numerator;
|
|
4426
|
+
}
|
|
4427
|
+
if (!denominator.ok) {
|
|
4428
|
+
return denominator;
|
|
4429
|
+
}
|
|
4430
|
+
astNode = new CommandNode("\\frac", [], [numerator.chain, denominator.chain]);
|
|
4431
|
+
} else if (node.kind === "sqrt" && node.radicand) {
|
|
4432
|
+
const radicand = editorChainToAstChain(node.radicand);
|
|
4433
|
+
if (!radicand.ok) {
|
|
4434
|
+
return radicand;
|
|
4435
|
+
}
|
|
4436
|
+
const optionalArgs = [];
|
|
4437
|
+
if (node.rootIndex && node.rootIndex.nodes.length > 0) {
|
|
4438
|
+
const rootIndex = editorChainToAstChain(node.rootIndex);
|
|
4439
|
+
if (!rootIndex.ok) {
|
|
4440
|
+
return rootIndex;
|
|
4441
|
+
}
|
|
4442
|
+
optionalArgs.push(rootIndex.chain);
|
|
4443
|
+
}
|
|
4444
|
+
astNode = new CommandNode("\\sqrt", optionalArgs, [radicand.chain]);
|
|
4445
|
+
} else if (node.kind === "overset" && node.baseExpr) {
|
|
4446
|
+
const accent = accentChainForExport(node.overExpr);
|
|
4447
|
+
if (!accent.ok) {
|
|
4448
|
+
return accent;
|
|
4449
|
+
}
|
|
4450
|
+
const baseExpr = editorChainToAstChain(node.baseExpr);
|
|
4451
|
+
if (!baseExpr.ok) {
|
|
4452
|
+
return baseExpr;
|
|
4453
|
+
}
|
|
4454
|
+
astNode = nodeFromAccentBase("\\overset", accent.chain, baseExpr.chain);
|
|
4455
|
+
} else if (node.kind === "underset" && node.baseExpr) {
|
|
4456
|
+
const accent = accentChainForExport(node.underExpr);
|
|
4457
|
+
if (!accent.ok) {
|
|
4458
|
+
return accent;
|
|
4459
|
+
}
|
|
4460
|
+
const baseExpr = editorChainToAstChain(node.baseExpr);
|
|
4461
|
+
if (!baseExpr.ok) {
|
|
4462
|
+
return baseExpr;
|
|
4463
|
+
}
|
|
4464
|
+
astNode = nodeFromAccentBase("\\underset", accent.chain, baseExpr.chain);
|
|
4465
|
+
} else if (node.kind === "accent" && node.baseExpr) {
|
|
4466
|
+
const tex = accentCommandSpec(node.expr)?.englishTex;
|
|
4467
|
+
if (!tex) {
|
|
4468
|
+
return { ok: false, reason: `\u0644\u0643\u0646\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4469
|
+
}
|
|
4470
|
+
const baseExpr = editorChainToAstChain(node.baseExpr);
|
|
4471
|
+
if (!baseExpr.ok) {
|
|
4472
|
+
return baseExpr;
|
|
4473
|
+
}
|
|
4474
|
+
astNode = new CommandNode(tex, [], [baseExpr.chain]);
|
|
4475
|
+
} else if (node.kind === "atomicCommand") {
|
|
4476
|
+
const tex = atomicCommandSpec(node.expr)?.englishTex;
|
|
4477
|
+
if (!tex) {
|
|
4478
|
+
return { ok: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4479
|
+
}
|
|
4480
|
+
astNode = new CommandNode(tex);
|
|
4481
|
+
} else if (node.kind === "atomicOperatorCommand") {
|
|
4482
|
+
const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
|
|
4483
|
+
if (!tex) {
|
|
4484
|
+
return { ok: false, reason: `\u0631\u0645\u0632 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4485
|
+
}
|
|
4486
|
+
astNode = new CommandNode(tex);
|
|
4487
|
+
} else if (node.kind === "standardCommand") {
|
|
4488
|
+
if (!isStandardCommandTex(node.expr)) {
|
|
4489
|
+
return { ok: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u0642\u064A\u0627\u0633\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4490
|
+
}
|
|
4491
|
+
astNode = new CommandNode(node.expr);
|
|
4492
|
+
} else if (node.kind === "env") {
|
|
4493
|
+
return editorEnvToAstNode(node);
|
|
4494
|
+
} else {
|
|
4495
|
+
return { ok: false, reason: `\u0639\u0642\u062F\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.kind}` };
|
|
4496
|
+
}
|
|
4497
|
+
const scripts = attachAstScripts(node, astNode);
|
|
4498
|
+
return scripts ?? { ok: true, node: astNode };
|
|
4499
|
+
}
|
|
4500
|
+
function editorChainToAstChain(chain) {
|
|
4501
|
+
const nodes = [];
|
|
4502
|
+
for (const editorNode of chain.nodes) {
|
|
4503
|
+
const converted = editorNodeToAstNode(editorNode);
|
|
4504
|
+
if (!converted.ok) {
|
|
4505
|
+
return converted;
|
|
4506
|
+
}
|
|
4507
|
+
nodes.push(converted.node);
|
|
4508
|
+
}
|
|
4509
|
+
return { ok: true, chain: new ChainNode(nodes) };
|
|
4510
|
+
}
|
|
4511
|
+
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
4512
|
+
const converted = editorChainToAstChain(session.englishTree);
|
|
4513
|
+
if (!converted.ok) {
|
|
4514
|
+
return converted;
|
|
4515
|
+
}
|
|
4516
|
+
return {
|
|
4517
|
+
ok: true,
|
|
4518
|
+
math: {
|
|
4519
|
+
nodeType: "MathObject",
|
|
4520
|
+
mathMode,
|
|
4521
|
+
lines: [converted.chain],
|
|
4522
|
+
closing
|
|
4523
|
+
}
|
|
4524
|
+
};
|
|
4525
|
+
}
|
|
4271
4526
|
|
|
4272
4527
|
// src/document2/jsonCommandTypes.ts
|
|
4273
4528
|
var Document2CommandError = class extends Error {
|
|
@@ -6991,6 +7246,35 @@ function diagnoseMathObject(mathObject) {
|
|
|
6991
7246
|
};
|
|
6992
7247
|
}
|
|
6993
7248
|
|
|
7249
|
+
// src/document2-cli/mathProjection.ts
|
|
7250
|
+
function sourceMode2(value) {
|
|
7251
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value) && value.source_side === "arabic") {
|
|
7252
|
+
return "arabic";
|
|
7253
|
+
}
|
|
7254
|
+
return "english";
|
|
7255
|
+
}
|
|
7256
|
+
function projectMathObjectToEnglish(mathObject) {
|
|
7257
|
+
let math;
|
|
7258
|
+
try {
|
|
7259
|
+
math = fromMathObjectJson(mathObject, sourceMode2(mathObject));
|
|
7260
|
+
} catch {
|
|
7261
|
+
throw new Document2CommandError("invalid_inline_token", "MathObject JSON is invalid");
|
|
7262
|
+
}
|
|
7263
|
+
const sessionResult = mathObjectToEditorSession(math);
|
|
7264
|
+
if (!sessionResult.editable) {
|
|
7265
|
+
throw new Document2CommandError("unsupported_inline_content", sessionResult.reason);
|
|
7266
|
+
}
|
|
7267
|
+
const projected = mathNodeFromEditorSession(
|
|
7268
|
+
sessionResult.session,
|
|
7269
|
+
math.mathMode,
|
|
7270
|
+
math.closing
|
|
7271
|
+
);
|
|
7272
|
+
if (!projected.ok) {
|
|
7273
|
+
throw new Document2CommandError("unsupported_inline_content", projected.reason);
|
|
7274
|
+
}
|
|
7275
|
+
return toMathObjectJson(projected.math);
|
|
7276
|
+
}
|
|
7277
|
+
|
|
6994
7278
|
// src/document2-cli/protocol.ts
|
|
6995
7279
|
var Document2WorkerProtocolError = class extends Error {
|
|
6996
7280
|
code;
|
|
@@ -7013,11 +7297,11 @@ function parseDocument2WorkerRequest(value) {
|
|
|
7013
7297
|
}
|
|
7014
7298
|
return { action: "diff", before: value.before, after: value.after };
|
|
7015
7299
|
}
|
|
7016
|
-
if (value.action === "diagnose_math_object") {
|
|
7300
|
+
if (value.action === "diagnose_math_object" || value.action === "project_math_object_english") {
|
|
7017
7301
|
if (!("math_object" in value)) {
|
|
7018
|
-
throw new Document2WorkerProtocolError("invalid_request",
|
|
7302
|
+
throw new Document2WorkerProtocolError("invalid_request", `${value.action} requires math_object`);
|
|
7019
7303
|
}
|
|
7020
|
-
return { action:
|
|
7304
|
+
return { action: value.action, math_object: value.math_object };
|
|
7021
7305
|
}
|
|
7022
7306
|
if (!("document" in value)) {
|
|
7023
7307
|
throw new Document2WorkerProtocolError("invalid_request", "Worker request requires a document");
|
|
@@ -7129,6 +7413,12 @@ function executeDocument2WorkerRequest(input) {
|
|
|
7129
7413
|
if (request.action === "diagnose_math_object") {
|
|
7130
7414
|
return { ok: true, math_diagnostic: diagnoseMathObject(request.math_object) };
|
|
7131
7415
|
}
|
|
7416
|
+
if (request.action === "project_math_object_english") {
|
|
7417
|
+
return {
|
|
7418
|
+
ok: true,
|
|
7419
|
+
english_math_object: projectMathObjectToEnglish(request.math_object)
|
|
7420
|
+
};
|
|
7421
|
+
}
|
|
7132
7422
|
if (request.action === "normalize") {
|
|
7133
7423
|
return { ok: true, document: normalizeDocument(request.document) };
|
|
7134
7424
|
}
|
|
@@ -7312,6 +7602,9 @@ function actionForPath(pathname) {
|
|
|
7312
7602
|
if (pathname === "/v1/document2/diagnostics/math-object") {
|
|
7313
7603
|
return "diagnose_math_object";
|
|
7314
7604
|
}
|
|
7605
|
+
if (pathname === "/v1/document2/math-object/english") {
|
|
7606
|
+
return "project_math_object_english";
|
|
7607
|
+
}
|
|
7315
7608
|
return null;
|
|
7316
7609
|
}
|
|
7317
7610
|
function defaultLogger(entry) {
|
|
@@ -7354,7 +7647,7 @@ function createDocument2HttpServer(options) {
|
|
|
7354
7647
|
if (typeof body !== "object" || body === null || Array.isArray(body)) {
|
|
7355
7648
|
throw new Document2WorkerProtocolError("invalid_request", "Request body must be an object");
|
|
7356
7649
|
}
|
|
7357
|
-
const responseBody =
|
|
7650
|
+
const responseBody = executeDocument2WorkerRequest({ ...body, action });
|
|
7358
7651
|
status = 200;
|
|
7359
7652
|
sendJson(response, status, responseBody);
|
|
7360
7653
|
} catch (error) {
|