@pie-lib/math-input-mathlive 2.0.1-next.20261110080000 → 2.0.1-next.20261112103425
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/latex-bridge.d.ts +22 -0
- package/dist/latex-bridge.js +80 -11
- package/dist/mf/static.d.ts +7 -1
- package/dist/mf/static.js +5 -5
- package/package.json +3 -3
package/dist/latex-bridge.d.ts
CHANGED
|
@@ -95,6 +95,18 @@ export declare const fieldTemplate: (latex: any) => any;
|
|
|
95
95
|
* @returns {string}
|
|
96
96
|
*/
|
|
97
97
|
export declare const fillFields: (latex: any, values: any) => string;
|
|
98
|
+
/**
|
|
99
|
+
* Stored latex with each answer block replaced by its answer, `values[id]`, and
|
|
100
|
+
* no `\MathQuillMathField` wrapper left around it: `x=\MathQuillMathField[r1]{}`
|
|
101
|
+
* with `{ r1: '2' }` gives `x=2`. This is what MathQuill's `latex()` returned for
|
|
102
|
+
* a static field, since a MathQuillMathField serialised as its content only,
|
|
103
|
+
* and it is the form math-inline scores in Advanced Multi.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} latex
|
|
106
|
+
* @param {Record<string, string>} values
|
|
107
|
+
* @returns {string}
|
|
108
|
+
*/
|
|
109
|
+
export declare const inlineFields: (latex: any, values: any) => string;
|
|
98
110
|
/**
|
|
99
111
|
* Latex for a text alternative: the same expression without the display-only
|
|
100
112
|
* markup that MathLive's MathML and speech conversions drop with its content.
|
|
@@ -140,6 +152,16 @@ declare const MATHQUILL_ALIASES: {
|
|
|
140
152
|
* @returns {string}
|
|
141
153
|
*/
|
|
142
154
|
export declare const toCanonicalCommands: (latex: any) => any;
|
|
155
|
+
/**
|
|
156
|
+
* Put braces around every argument of the commands in `BRACED_ARGUMENT_COUNT`:
|
|
157
|
+
* `\frac12` -> `\frac{1}{2}`, `2\frac34` -> `2\frac{3}{4}`, `\sqrt2` ->
|
|
158
|
+
* `\sqrt{2}`, at any depth. Latex whose arguments are already braced comes back
|
|
159
|
+
* unchanged, whitespace included.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} latex
|
|
162
|
+
* @returns {string}
|
|
163
|
+
*/
|
|
164
|
+
export declare const braceArguments: (latex: any) => any;
|
|
143
165
|
/**
|
|
144
166
|
* Convert latex out of MathLive back into the stored form, so items authored
|
|
145
167
|
* with the MathLive editor remain readable by @pie-lib/math-rendering and by
|
package/dist/latex-bridge.js
CHANGED
|
@@ -90,9 +90,9 @@ var e = "\\embed{newLine}[]", t = /^\\displaylines\{([\s\S]*)\}$/, n = "\\MathQu
|
|
|
90
90
|
}, A = (e) => {
|
|
91
91
|
let t = {};
|
|
92
92
|
return typeof e == "string" && i(e, n, (e, n) => (t[e || "r1"] = n, "")), t;
|
|
93
|
-
}, j = (e) => typeof e == "string" ? i(e, n, (e) => `${n}[${e || "r1"}]{}`) : e, M = (e, t) => i(e, n, (e,
|
|
94
|
-
let
|
|
95
|
-
return
|
|
93
|
+
}, j = (e) => typeof e == "string" ? i(e, n, (e) => `${n}[${e || "r1"}]{}`) : e, M = (e, t) => i(e, n, (e, n) => {
|
|
94
|
+
let r = e || "r1";
|
|
95
|
+
return t[r] === void 0 ? n : t[r];
|
|
96
96
|
}), N = (e) => {
|
|
97
97
|
if (typeof e != "string" || !e) return e || "";
|
|
98
98
|
let t = (e, t, n) => {
|
|
@@ -157,11 +157,80 @@ var e = "\\embed{newLine}[]", t = /^\\displaylines\{([\s\S]*)\}$/, n = "\\MathQu
|
|
|
157
157
|
} else i === "{" ? t.push(/[\^_]\s*$/.test(n)) : i === "}" && t.pop(), n += i, r += 1;
|
|
158
158
|
}
|
|
159
159
|
return n;
|
|
160
|
-
}, H = (e) => typeof e == "string" ? V(e.replace(I, (e) => F[e]).replace(L, (e, t) => z(t))) : e, U =
|
|
160
|
+
}, H = (e) => typeof e == "string" ? V(e.replace(I, (e) => F[e]).replace(L, (e, t) => z(t))) : e, U = {
|
|
161
|
+
"\\frac": 2,
|
|
162
|
+
"\\dfrac": 2,
|
|
163
|
+
"\\tfrac": 2,
|
|
164
|
+
"\\cfrac": 2,
|
|
165
|
+
"\\binom": 2,
|
|
166
|
+
"\\dbinom": 2,
|
|
167
|
+
"\\tbinom": 2,
|
|
168
|
+
"\\sqrt": 1,
|
|
169
|
+
"\\overline": 1,
|
|
170
|
+
"\\underline": 1,
|
|
171
|
+
"\\overrightarrow": 1,
|
|
172
|
+
"\\overleftrightarrow": 1,
|
|
173
|
+
"\\overparen": 1,
|
|
174
|
+
"\\vec": 1,
|
|
175
|
+
"\\hat": 1,
|
|
176
|
+
"\\bar": 1
|
|
177
|
+
}, W = /^\\(?:[a-zA-Z]+|.)/, G = (e, t) => {
|
|
178
|
+
let n = 0;
|
|
179
|
+
for (let r = t + 1; r < e.length; r++) {
|
|
180
|
+
let t = e[r];
|
|
181
|
+
if (t === "\\") r += 1;
|
|
182
|
+
else if (t === "{") n += 1;
|
|
183
|
+
else if (t === "}") --n;
|
|
184
|
+
else if (t === "]" && n === 0) return r;
|
|
185
|
+
}
|
|
186
|
+
return -1;
|
|
187
|
+
}, K = (e, t) => {
|
|
188
|
+
let n = e[t];
|
|
189
|
+
if (n === "{") {
|
|
190
|
+
let n = r(e, t);
|
|
191
|
+
return n === -1 ? void 0 : {
|
|
192
|
+
content: e.slice(t + 1, n),
|
|
193
|
+
end: n + 1
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return n !== void 0 && /^[0-9a-zA-Z]$/.test(n) ? {
|
|
197
|
+
content: n,
|
|
198
|
+
end: t + 1
|
|
199
|
+
} : void 0;
|
|
200
|
+
}, q = (e) => {
|
|
201
|
+
if (typeof e != "string" || e.indexOf("\\") === -1) return e;
|
|
202
|
+
let t = "", n = 0;
|
|
203
|
+
for (; n < e.length;) {
|
|
204
|
+
if (e[n] !== "\\") {
|
|
205
|
+
t += e[n], n += 1;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
let r = e.slice(n).match(W), i = r ? r[0] : "\\";
|
|
209
|
+
t += i, n += i.length;
|
|
210
|
+
let a = U[i];
|
|
211
|
+
if (!a) continue;
|
|
212
|
+
let o = () => {
|
|
213
|
+
let r = n;
|
|
214
|
+
for (; e[n] === " ";) n += 1;
|
|
215
|
+
t += e.slice(r, n);
|
|
216
|
+
};
|
|
217
|
+
if (i === "\\sqrt" && (o(), e[n] === "[")) {
|
|
218
|
+
let r = G(e, n);
|
|
219
|
+
r !== -1 && (t += `[${q(e.slice(n + 1, r))}]`, n = r + 1);
|
|
220
|
+
}
|
|
221
|
+
for (let r = 0; r < a; r++) {
|
|
222
|
+
o();
|
|
223
|
+
let r = K(e, n);
|
|
224
|
+
if (!r) break;
|
|
225
|
+
t += `{${q(r.content)}}`, n = r.end;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return t;
|
|
229
|
+
}, J = (n) => {
|
|
161
230
|
if (typeof n != "string" || !n) return n || "";
|
|
162
231
|
let r = n.trim().match(t), o = n;
|
|
163
|
-
return r && (o = a(r[1], "\\\\").map((e) => e.trim()).join(e)), o = i(o, "\\placeholder", (e, t) => `\\MathQuillMathField[${e || "r1"}]{${t}}`), o = o.replace(d, (e, t) => `\\embed{answerBlock}[${t}]`), o = o.replace(c, (e, t) => t), o = o.replace(l, ""), H(o);
|
|
164
|
-
},
|
|
232
|
+
return r && (o = a(r[1], "\\\\").map((e) => e.trim()).join(e)), o = i(o, "\\placeholder", (e, t) => `\\MathQuillMathField[${e || "r1"}]{${t}}`), o = o.replace(d, (e, t) => `\\embed{answerBlock}[${t}]`), o = o.replace(c, (e, t) => t), o = o.replace(l, ""), o = q(o), H(o);
|
|
233
|
+
}, Y = {
|
|
165
234
|
"\\frac": "\\frac{#?}{#?}",
|
|
166
235
|
"/": "\\frac{#@}{#?}",
|
|
167
236
|
"\\sqrt": "\\sqrt{#?}",
|
|
@@ -176,14 +245,14 @@ var e = "\\embed{newLine}[]", t = /^\\displaylines\{([\s\S]*)\}$/, n = "\\MathQu
|
|
|
176
245
|
"(": "\\left(#?\\right)",
|
|
177
246
|
"[": "\\left[#?\\right]",
|
|
178
247
|
"|": "\\left|#?\\right|"
|
|
179
|
-
},
|
|
248
|
+
}, X = {
|
|
180
249
|
Left: "moveToPreviousChar",
|
|
181
250
|
Right: "moveToNextChar",
|
|
182
251
|
Backspace: "deleteBackward",
|
|
183
252
|
Delete: "deleteForward",
|
|
184
253
|
Up: "moveUp",
|
|
185
254
|
Down: "moveDown"
|
|
186
|
-
},
|
|
255
|
+
}, Z = (e) => {
|
|
187
256
|
if (e) {
|
|
188
257
|
if (e.latex && !e.command) return {
|
|
189
258
|
type: "insert",
|
|
@@ -195,10 +264,10 @@ var e = "\\embed{newLine}[]", t = /^\\displaylines\{([\s\S]*)\}$/, n = "\\MathQu
|
|
|
195
264
|
};
|
|
196
265
|
if (e.command) return {
|
|
197
266
|
type: "insert",
|
|
198
|
-
value: (Array.isArray(e.command) ? e.command : [e.command]).map((e) =>
|
|
267
|
+
value: (Array.isArray(e.command) ? e.command : [e.command]).map((e) => Y[e] || F[e] || e).join("")
|
|
199
268
|
};
|
|
200
269
|
if (e.keystroke) {
|
|
201
|
-
let t =
|
|
270
|
+
let t = X[e.keystroke];
|
|
202
271
|
return t ? {
|
|
203
272
|
type: "command",
|
|
204
273
|
value: t
|
|
@@ -206,4 +275,4 @@ var e = "\\embed{newLine}[]", t = /^\\displaylines\{([\s\S]*)\}$/, n = "\\MathQu
|
|
|
206
275
|
}
|
|
207
276
|
}
|
|
208
277
|
};
|
|
209
|
-
export {
|
|
278
|
+
export { Y as COMMANDS_WITH_ARGS, X as KEYSTROKES, F as MATHQUILL_ALIASES, e as NEWLINE_EMBED, f as answerBlockLatex, q as braceArguments, k as fieldIds, j as fieldTemplate, A as fieldValues, J as fromMathLive, M as inlineFields, Z as keyToAction, N as toAccessibleLatex, H as toCanonicalCommands, P as toMathLive, E as toNativeCommands, T as withVisibleEmptySlots };
|
package/dist/mf/static.d.ts
CHANGED
|
@@ -79,7 +79,13 @@ export default class Static extends React.Component {
|
|
|
79
79
|
renderMarkup(): void;
|
|
80
80
|
/** MathQuill's `innerFields` equivalent, keyed by prompt id. */
|
|
81
81
|
values(): {};
|
|
82
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* The whole expression with the current answers in place, as MathQuill's
|
|
84
|
+
* `mathField.latex()` returned it: an answer block serialises as its answer
|
|
85
|
+
* alone, with no `\MathQuillMathField` wrapper. math-inline stores this as
|
|
86
|
+
* `completeAnswer` and scores it in Advanced Multi, so a wrapper left in would
|
|
87
|
+
* make every answer wrong.
|
|
88
|
+
*/
|
|
83
89
|
latex(): string;
|
|
84
90
|
/** Put the selection inside prompt `id`, unless it is there already, so edits land in it. */
|
|
85
91
|
selectPrompt(id: any): void;
|
package/dist/mf/static.js
CHANGED
|
@@ -2,7 +2,7 @@ import { applyShadowStyles as e, createMathField as t, latexToMarkup as n, latex
|
|
|
2
2
|
import { fixLongDivisionWhenReady as o, trackLongDivision as s } from "../longdiv.js";
|
|
3
3
|
import { keepCaretWhileKeypadFocused as c } from "./inactive-caret.js";
|
|
4
4
|
import { describeMathField as l, labelMathField as u } from "./field-label.js";
|
|
5
|
-
import { KEYSTROKES as d, fieldIds as f, fieldTemplate as p, fieldValues as m,
|
|
5
|
+
import { KEYSTROKES as d, fieldIds as f, fieldTemplate as p, fieldValues as m, fromMathLive as h, inlineFields as g, keyToAction as _, toMathLive as v } from "../latex-bridge.js";
|
|
6
6
|
import { parallelStyles as y, placeholderStyles as b, rootIndexStyles as x } from "./common-styles.js";
|
|
7
7
|
import S from "react";
|
|
8
8
|
import C from "prop-types";
|
|
@@ -64,7 +64,7 @@ var D = T("pie-lib:math-input-mathlive:static"), O = "position:absolute;width:1p
|
|
|
64
64
|
let e = m(this.props.latex);
|
|
65
65
|
Object.keys(e).forEach((t) => {
|
|
66
66
|
let n = e[t];
|
|
67
|
-
n !== this.promptValues[t] && n !==
|
|
67
|
+
n !== this.promptValues[t] && n !== h(this.mathField.getPromptValue(t)) && (this.mathField.setPromptValue(t, v(n), {}), this.promptValues[t] = n);
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
componentWillUnmount() {
|
|
@@ -112,11 +112,11 @@ var D = T("pie-lib:math-input-mathlive:static"), O = "position:absolute;width:1p
|
|
|
112
112
|
if (!this.mathField) return {};
|
|
113
113
|
let e = {};
|
|
114
114
|
return (this.mathField.getPrompts() || []).forEach((t) => {
|
|
115
|
-
e[t] =
|
|
115
|
+
e[t] = h(this.mathField.getPromptValue(t));
|
|
116
116
|
}), e;
|
|
117
117
|
}
|
|
118
118
|
latex() {
|
|
119
|
-
return this.mathField ?
|
|
119
|
+
return this.mathField ? g(this.props.latex, this.values()) : "";
|
|
120
120
|
}
|
|
121
121
|
selectPrompt(e) {
|
|
122
122
|
this.promptContaining(this.mathField.position) !== e && this.focusPrompt(e);
|
|
@@ -146,7 +146,7 @@ var D = T("pie-lib:math-input-mathlive:static"), O = "position:absolute;width:1p
|
|
|
146
146
|
this.mathField && (this.mathField.focus(), this.selectPrompt(e));
|
|
147
147
|
},
|
|
148
148
|
el: () => this.mathField,
|
|
149
|
-
latex: (t) => this.mathField ? t === void 0 ?
|
|
149
|
+
latex: (t) => this.mathField ? t === void 0 ? h(this.mathField.getPromptValue(e)) : (this.mathField.setPromptValue(e, v(t), {}), t) : ""
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
get innerFields() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/math-input-mathlive",
|
|
3
|
-
"version": "2.0.1-next.
|
|
3
|
+
"version": "2.0.1-next.20261112103425",
|
|
4
4
|
"description": "MathLive-based math input (drop-in alternative to @pie-lib/math-input)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"mathlive": "0.110.0",
|
|
18
18
|
"prop-types": "^15.7.2",
|
|
19
19
|
"@pie-element/shared-lodash": "0.1.4-next.20261110072702",
|
|
20
|
-
"@pie-lib/render-ui": "8.0.8-next.
|
|
21
|
-
"@pie-element/shared-i18n": "0.1.3-next.
|
|
20
|
+
"@pie-lib/render-ui": "8.0.8-next.20261110124518",
|
|
21
|
+
"@pie-element/shared-i18n": "0.1.3-next.20261110124518"
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"main": "./dist/index.js",
|