@pie-lib/math-input-mathlive 1.1.5-beta.9 → 2.0.1-next.20261107131445

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.
Files changed (195) hide show
  1. package/README.md +84 -109
  2. package/dist/_virtual/_rolldown/runtime.js +11 -0
  3. package/dist/horizontal-keypad.d.ts +22 -0
  4. package/dist/horizontal-keypad.js +54 -0
  5. package/dist/index.d.ts +20 -0
  6. package/dist/index.js +12 -0
  7. package/dist/keypad/index.d.ts +40 -0
  8. package/dist/keypad/index.js +245 -0
  9. package/dist/keypad/keys-layout.d.ts +7 -0
  10. package/dist/keypad/keys-layout.js +5 -0
  11. package/dist/keys/basic-operators.d.ts +5 -0
  12. package/dist/keys/basic-operators.js +30 -0
  13. package/dist/keys/chars.d.ts +5 -0
  14. package/dist/keys/comparison.d.ts +4 -0
  15. package/dist/keys/comparison.js +32 -0
  16. package/dist/keys/constants.d.ts +4 -0
  17. package/dist/keys/constants.js +35 -0
  18. package/dist/keys/digits.d.ts +15 -0
  19. package/dist/keys/digits.js +34 -0
  20. package/dist/keys/edit.d.ts +6 -0
  21. package/dist/keys/edit.js +9 -0
  22. package/dist/keys/exponent.d.ts +4 -0
  23. package/dist/keys/exponent.js +28 -0
  24. package/dist/keys/fractions.d.ts +3 -0
  25. package/dist/keys/fractions.js +27 -0
  26. package/dist/keys/geometry.d.ts +23 -0
  27. package/dist/keys/geometry.js +127 -0
  28. package/dist/keys/grades.d.ts +9 -0
  29. package/dist/keys/grades.js +414 -0
  30. package/dist/keys/index.d.ts +6 -0
  31. package/dist/keys/index.js +50 -0
  32. package/dist/keys/log.d.ts +3 -0
  33. package/dist/keys/log.js +25 -0
  34. package/dist/keys/logic.d.ts +2 -0
  35. package/dist/keys/logic.js +13 -0
  36. package/dist/keys/matrices.d.ts +2 -0
  37. package/dist/keys/matrices.js +17 -0
  38. package/dist/keys/misc.d.ts +10 -0
  39. package/dist/keys/misc.js +60 -0
  40. package/dist/keys/navigation.d.ts +2 -0
  41. package/dist/keys/navigation.js +13 -0
  42. package/dist/keys/operators.d.ts +1 -0
  43. package/dist/keys/operators.js +11 -0
  44. package/dist/keys/statistics.d.ts +5 -0
  45. package/dist/keys/statistics.js +38 -0
  46. package/dist/keys/sub-sup.d.ts +2 -0
  47. package/dist/keys/sub-sup.js +17 -0
  48. package/dist/keys/trigonometry.d.ts +6 -0
  49. package/dist/keys/trigonometry.js +43 -0
  50. package/dist/keys/utils.d.ts +5 -0
  51. package/dist/keys/utils.js +24 -0
  52. package/dist/keys/vars.d.ts +3 -0
  53. package/dist/keys/vars.js +22 -0
  54. package/dist/latex-bridge.d.ts +197 -0
  55. package/dist/latex-bridge.js +210 -0
  56. package/dist/longdiv.d.ts +24 -0
  57. package/dist/longdiv.js +43 -0
  58. package/dist/math-input.d.ts +26 -0
  59. package/dist/math-input.js +74 -0
  60. package/dist/mathlive-instance.d.ts +221 -0
  61. package/dist/mathlive-instance.js +159 -0
  62. package/dist/mf/common-styles.d.ts +594 -0
  63. package/dist/mf/common-styles.js +80 -0
  64. package/dist/mf/field-label.d.ts +16 -0
  65. package/dist/mf/field-label.js +13 -0
  66. package/dist/mf/index.d.ts +4 -0
  67. package/dist/mf/index.js +21 -0
  68. package/dist/mf/input.d.ts +94 -0
  69. package/dist/mf/input.js +127 -0
  70. package/dist/mf/static.d.ts +143 -0
  71. package/dist/mf/static.js +230 -0
  72. package/dist/selection.d.ts +43 -0
  73. package/dist/selection.js +39 -0
  74. package/package.json +32 -18
  75. package/lib/__tests__/composites.test.js +0 -255
  76. package/lib/__tests__/drop-in-compat.test.js +0 -133
  77. package/lib/__tests__/embedded-fonts.test.js +0 -121
  78. package/lib/__tests__/index.test.js +0 -118
  79. package/lib/__tests__/input-imperative.test.js +0 -155
  80. package/lib/__tests__/keypad-label.test.js +0 -231
  81. package/lib/__tests__/keypad-render.test.js +0 -206
  82. package/lib/__tests__/latex-bridge.test.js +0 -386
  83. package/lib/__tests__/mathlive-instance.test.js +0 -419
  84. package/lib/__tests__/mount-race.test.js +0 -218
  85. package/lib/__tests__/static-prompts.test.js +0 -405
  86. package/lib/__tests__/tmp-markup.test.js +0 -26
  87. package/lib/horizontal-keypad.js +0 -101
  88. package/lib/horizontal-keypad.js.map +0 -1
  89. package/lib/index.js +0 -143
  90. package/lib/index.js.map +0 -1
  91. package/lib/keypad/index.js +0 -431
  92. package/lib/keypad/index.js.map +0 -1
  93. package/lib/keypad/keys-layout.js +0 -22
  94. package/lib/keypad/keys-layout.js.map +0 -1
  95. package/lib/keys/basic-operators.js +0 -33
  96. package/lib/keys/basic-operators.js.map +0 -1
  97. package/lib/keys/chars.js +0 -12
  98. package/lib/keys/chars.js.map +0 -1
  99. package/lib/keys/comparison.js +0 -39
  100. package/lib/keys/comparison.js.map +0 -1
  101. package/lib/keys/constants.js +0 -37
  102. package/lib/keys/constants.js.map +0 -1
  103. package/lib/keys/digits.js +0 -46
  104. package/lib/keys/digits.js.map +0 -1
  105. package/lib/keys/edit.js +0 -14
  106. package/lib/keys/edit.js.map +0 -1
  107. package/lib/keys/exponent.js +0 -30
  108. package/lib/keys/exponent.js.map +0 -1
  109. package/lib/keys/fractions.js +0 -29
  110. package/lib/keys/fractions.js.map +0 -1
  111. package/lib/keys/geometry.js +0 -143
  112. package/lib/keys/geometry.js.map +0 -1
  113. package/lib/keys/grades.js +0 -259
  114. package/lib/keys/grades.js.map +0 -1
  115. package/lib/keys/index.js +0 -35
  116. package/lib/keys/index.js.map +0 -1
  117. package/lib/keys/log.js +0 -27
  118. package/lib/keys/log.js.map +0 -1
  119. package/lib/keys/logic.js +0 -19
  120. package/lib/keys/logic.js.map +0 -1
  121. package/lib/keys/matrices.js +0 -19
  122. package/lib/keys/matrices.js.map +0 -1
  123. package/lib/keys/misc.js +0 -69
  124. package/lib/keys/misc.js.map +0 -1
  125. package/lib/keys/navigation.js +0 -20
  126. package/lib/keys/navigation.js.map +0 -1
  127. package/lib/keys/operators.js +0 -15
  128. package/lib/keys/operators.js.map +0 -1
  129. package/lib/keys/statistics.js +0 -40
  130. package/lib/keys/statistics.js.map +0 -1
  131. package/lib/keys/sub-sup.js +0 -19
  132. package/lib/keys/sub-sup.js.map +0 -1
  133. package/lib/keys/trigonometry.js +0 -45
  134. package/lib/keys/trigonometry.js.map +0 -1
  135. package/lib/keys/utils.js +0 -87
  136. package/lib/keys/utils.js.map +0 -1
  137. package/lib/keys/vars.js +0 -24
  138. package/lib/keys/vars.js.map +0 -1
  139. package/lib/latex-bridge.js +0 -508
  140. package/lib/latex-bridge.js.map +0 -1
  141. package/lib/math-input.js +0 -143
  142. package/lib/math-input.js.map +0 -1
  143. package/lib/mathlive-instance.js +0 -585
  144. package/lib/mathlive-instance.js.map +0 -1
  145. package/lib/mf/common-styles.js +0 -203
  146. package/lib/mf/common-styles.js.map +0 -1
  147. package/lib/mf/index.js +0 -84
  148. package/lib/mf/index.js.map +0 -1
  149. package/lib/mf/input.js +0 -364
  150. package/lib/mf/input.js.map +0 -1
  151. package/lib/mf/static.js +0 -500
  152. package/lib/mf/static.js.map +0 -1
  153. package/src/__tests__/composites.test.jsx +0 -220
  154. package/src/__tests__/drop-in-compat.test.jsx +0 -112
  155. package/src/__tests__/index.test.jsx +0 -109
  156. package/src/__tests__/input-imperative.test.jsx +0 -144
  157. package/src/__tests__/keypad-label.test.jsx +0 -283
  158. package/src/__tests__/keypad-render.test.jsx +0 -123
  159. package/src/__tests__/latex-bridge.test.js +0 -389
  160. package/src/__tests__/mathlive-instance.test.js +0 -418
  161. package/src/__tests__/mount-race.test.jsx +0 -142
  162. package/src/__tests__/static-prompts.test.jsx +0 -364
  163. package/src/horizontal-keypad.jsx +0 -73
  164. package/src/index.jsx +0 -63
  165. package/src/keypad/index.jsx +0 -386
  166. package/src/keypad/keys-layout.js +0 -16
  167. package/src/keys/basic-operators.js +0 -32
  168. package/src/keys/chars.js +0 -5
  169. package/src/keys/comparison.js +0 -28
  170. package/src/keys/constants.js +0 -35
  171. package/src/keys/digits.js +0 -40
  172. package/src/keys/edit.js +0 -3
  173. package/src/keys/exponent.js +0 -28
  174. package/src/keys/fractions.js +0 -26
  175. package/src/keys/geometry.js +0 -149
  176. package/src/keys/grades.js +0 -367
  177. package/src/keys/index.js +0 -20
  178. package/src/keys/log.js +0 -22
  179. package/src/keys/logic.js +0 -15
  180. package/src/keys/matrices.js +0 -15
  181. package/src/keys/misc.js +0 -71
  182. package/src/keys/navigation.js +0 -8
  183. package/src/keys/operators.js +0 -10
  184. package/src/keys/statistics.js +0 -38
  185. package/src/keys/sub-sup.js +0 -15
  186. package/src/keys/trigonometry.js +0 -15
  187. package/src/keys/utils.js +0 -66
  188. package/src/keys/vars.js +0 -19
  189. package/src/latex-bridge.js +0 -524
  190. package/src/math-input.jsx +0 -115
  191. package/src/mathlive-instance.js +0 -582
  192. package/src/mf/common-styles.js +0 -210
  193. package/src/mf/index.js +0 -30
  194. package/src/mf/input.jsx +0 -319
  195. package/src/mf/static.jsx +0 -479
@@ -1,508 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.withVisibleEmptySlots = exports.toNativeCommands = exports.toMathLive = exports.toCanonicalCommands = exports.keyToAction = exports.fromMathLive = exports.fieldIds = exports.NEWLINE_EMBED = exports.MATHQUILL_ALIASES = exports.KEYSTROKES = exports.DEFAULT_FIELD_ID = exports.COMMANDS_WITH_ARGS = void 0;
7
- /**
8
- * LaTeX translation layer between the MathQuill-era content model and MathLive.
9
- *
10
- * Two independent concerns live here:
11
- *
12
- * 1. Newlines. MathQuill had no line break, so pie-lib registered a custom
13
- * `newLine` embed that serialises to `\embed{newLine}[]`. MathLive has no
14
- * embed system but supports real multiline environments, so we translate
15
- * `\embed{newLine}[]` <-> `\\` inside `\displaylines{}`.
16
- *
17
- * Authored content keeps its `\embed{newLine}[]` on-disk form (that is what
18
- * @pie-lib/math-rendering already normalises for MathJax), so each renderer
19
- * normalises at its own boundary and stored items stay compatible.
20
- *
21
- * 2. Keypad key -> MathLive action. MathQuill keys carry `write`/`command`/
22
- * `keystroke` built for `mf.write()` / `mf.cmd()` / `mf.keystroke()`.
23
- * MathLive has `insert()` and `executeCommand()` instead.
24
- */
25
-
26
- var NEWLINE_EMBED = exports.NEWLINE_EMBED = '\\embed{newLine}[]';
27
- var NEWLINE_EMBED_REGEX = /\\embed\{newLine\}\[\]/g;
28
- var DISPLAYLINES_REGEX = /^\\displaylines\{([\s\S]*)\}$/;
29
-
30
- /**
31
- * MathQuill's editable sub-field syntax, e.g. `\MathQuillMathField[r1]{}`.
32
- * These are the answer blocks in templated math items; MathLive expresses the
33
- * same idea as `\placeholder[id]{}` and reads them back via the prompts API.
34
- */
35
- var MQ_FIELD_REGEX = /\\MathQuillMathField\[([^\]]*)\]\{([^{}]*)\}/g;
36
- var PLACEHOLDER_REGEX = /\\placeholder\[([^\]]*)\]\{([^{}]*)\}/g;
37
-
38
- /**
39
- * Unnamed placeholders, which MathLive inserts on its own.
40
- *
41
- * Typing a command with empty arguments (`\longdiv{}`, `\frac{}{}`) makes
42
- * MathLive serialise the empty slots as `\placeholder{}`. That token is
43
- * MathLive-specific: MathJax - which @pie-lib/math-rendering uses to render
44
- * prompts and previews - has no such command and renders it as red error text.
45
- * Stored latex must therefore keep plain empty groups.
46
- */
47
- var BARE_PLACEHOLDER_REGEX = /\\placeholder\{([^{}]*)\}/g;
48
- var BARE_PLACEHOLDER_NO_ARG_REGEX = /\\placeholder(?![[{a-zA-Z])/g;
49
-
50
- /** Default id used when stored latex has an unnamed field. */
51
- var DEFAULT_FIELD_ID = exports.DEFAULT_FIELD_ID = 'r1';
52
-
53
- /**
54
- * A visible stand-in for an empty argument slot, used for STATIC rendering only.
55
- *
56
- * Stored latex legitimately contains empty groups - `\longdiv{}`, `\frac{}{}`,
57
- * `x^{}` - to express a command's shape. MathQuill drew those as a shaded box
58
- * (`.mq-empty`); MathLive renders `{}` as nothing, so `convertLatexToMarkup`
59
- * output comes out completely blank (not even the surrounding bracket, in the
60
- * case of `\enclose{longdiv}{}`).
61
- *
62
- * `\placeholder{}` is not usable here: in static markup it renders as a
63
- * non-breaking space, because its editable box only exists inside a live
64
- * mathfield. So something with real width is required.
65
- *
66
- * It must be a `\rule`, not a unicode glyph. A glyph's width comes from font
67
- * metrics, and U+25AB is not in the KaTeX fonts - the browser substitutes a
68
- * wider fallback while MathLive still sizes surrounding accents from its own
69
- * metrics. That left stretchy accents (`\overarc`, `\overleftrightarrow`)
70
- * visibly narrower than the box they were meant to span. A rule carries an
71
- * explicit em width, so accents size correctly - and a filled box is closer to
72
- * MathQuill's `.mq-empty` anyway.
73
- *
74
- * Live mathfields need none of this - MathLive manages empty slots itself.
75
- */
76
- var EMPTY_SLOT = '\\htmlData{pie-empty=1}{\\rule{0.55em}{0.55em}}';
77
- var EMPTY_GROUP_REGEX = /\{\s*\}/g;
78
- // The segment key (`\overline{}`). A bar is a thin accent, so its label is shorter
79
- // than the ray and line keys' stretchy arrows. The keypad centres every label
80
- // in its cell, so the bar's box ended up ~0.17em higher than theirs.
81
- var EMPTY_OVERLINE_REGEX = /\\overline\{\s*\}/g;
82
- var EMPTY_OVERLINE_STRUT = '\\rule{0em}{1.08em}';
83
- // Empty delimiter pairs: `\abs{}` is converted to `\left|\right|`, and the
84
- // parenthesis / bracket keys are `\left(\right)` / `\left[\right]`. None has a
85
- // `{}` group for the rule above to catch, so they would render as bare fences.
86
- var EMPTY_FENCE_REGEX = /\\left([([|])\s*\\right([)\]|])/g;
87
- // The same muted fill as the other slots (`pie-empty`), but a tall rectangle
88
- // rather than a square. It also sets the fences' height: `\left...\right` stretch
89
- // to their content, so a taller slot gives taller parentheses.
90
- //
91
- // A `\rule` stands on the baseline, but the fences are centred on the math axis
92
- // (0.25em above it), so an un-lifted box sat high between them. `[-0.25em]`
93
- // lowers it by (axis - height / 2) = 0.25 - 1 / 2, centring it on the axis.
94
- //
95
- // Lowering it alone also shrinks the fences, which size themselves to their
96
- // content (MathLive switches to short bars). The zero-width `\rule{0em}{1em}`
97
- // strut keeps the content as tall as before, so the bars keep their height and
98
- // only the box moves.
99
- var EMPTY_FENCE_SLOT = '\\rule{0em}{1em}\\htmlData{pie-empty=1}{\\rule[-0.25em]{0.55em}{1em}}';
100
-
101
- /**
102
- * Make empty argument slots visible, for static rendering.
103
- *
104
- * Display-only: never feed the result to a mathfield or to storage - the
105
- * original latex is what gets typed and saved.
106
- *
107
- * @param {string} latex
108
- * @returns {string}
109
- */
110
- var withVisibleEmptySlots = exports.withVisibleEmptySlots = function withVisibleEmptySlots(latex) {
111
- return (latex || '').replace(EMPTY_OVERLINE_REGEX, "\\overline{".concat(EMPTY_OVERLINE_STRUT).concat(EMPTY_SLOT, "}")).replace(EMPTY_GROUP_REGEX, "{".concat(EMPTY_SLOT, "}")).replace(EMPTY_FENCE_REGEX, function (_m, open, close) {
112
- return "\\left".concat(open).concat(EMPTY_FENCE_SLOT, "\\right").concat(close);
113
- });
114
- };
115
-
116
- /**
117
- * Pie commands that take an argument, and their native MathLive equivalents.
118
- *
119
- * These MUST NOT be handled as MathLive macros. A macro is serialised from the
120
- * arguments it was created with, so text typed inside its expansion never makes
121
- * it back out: `getValue('latex')` keeps returning `\longdiv{\placeholder{}}`
122
- * while `getValue('ascii-math')` shows the typed content. Setting
123
- * `captureSelection: false` lets the cursor in but does not change
124
- * serialisation.
125
- *
126
- * Expanding to native constructs instead gives real, editable atoms that
127
- * round-trip. All three targets are understood by MathJax too, so stored latex
128
- * still renders in @pie-lib/math-rendering without a reverse mapping.
129
- */
130
- /**
131
- * Rewrite argument-taking pie commands into native MathLive latex.
132
- * Applied on the way *into* a mathfield.
133
- *
134
- * @param {string} latex
135
- * @returns {string}
136
- */
137
- var toNativeCommands = exports.toNativeCommands = function toNativeCommands(latex) {
138
- if (typeof latex !== 'string' || !latex) {
139
- return latex || '';
140
- }
141
- var out = latex;
142
-
143
- // \abs{x} -> \left|x\right| needs brace-aware handling, the rest are prefix
144
- // swaps.
145
- out = replaceAbs(out);
146
- out = out.replace(/\\longdiv\{/g, '\\enclose{longdiv}{');
147
- out = out.replace(/\\overarc\{/g, '\\overparen{');
148
- out = escapeBareComments(out);
149
- return out;
150
- };
151
-
152
- /**
153
- * Escape an unescaped `%`.
154
- *
155
- * In real LaTeX `%` starts a comment, so MathLive discards it *and everything
156
- * after it*: `50%` renders as `50`, and `x%y` as just `x`. MathQuill had no
157
- * such notion - it treated `%` as a symbol - so latex from anywhere outside the
158
- * keypad may still carry a bare one.
159
- *
160
- * Only a `%` preceded by an even number of backslashes is bare: `\%` is already
161
- * escaped, while the `%` in `\\%` (a line break, then a comment) is not.
162
- *
163
- * @param {string} latex
164
- * @returns {string}
165
- */
166
- var escapeBareComments = function escapeBareComments(latex) {
167
- if (latex.indexOf('%') === -1) {
168
- return latex;
169
- }
170
- var out = '';
171
- // Consecutive backslashes immediately before the current character.
172
- var backslashes = 0;
173
- for (var i = 0; i < latex.length; i++) {
174
- var ch = latex[i];
175
- out += ch === '%' && backslashes % 2 === 0 ? '\\%' : ch;
176
- backslashes = ch === '\\' ? backslashes + 1 : 0;
177
- }
178
- return out;
179
- };
180
-
181
- /** `\abs{x}` -> `\left|x\right|`, matching balanced braces. */
182
- var replaceAbs = function replaceAbs(latex) {
183
- var out = latex;
184
- var idx = out.indexOf('\\abs{');
185
- while (idx !== -1) {
186
- var open = idx + '\\abs{'.length - 1;
187
- var depth = 0;
188
- var close = -1;
189
- for (var i = open; i < out.length; i++) {
190
- if (out[i] === '{') depth++;else if (out[i] === '}') {
191
- depth--;
192
- if (depth === 0) {
193
- close = i;
194
- break;
195
- }
196
- }
197
- }
198
- if (close === -1) {
199
- break;
200
- }
201
- var inner = out.slice(open + 1, close);
202
- out = "".concat(out.slice(0, idx), "\\left|").concat(inner, "\\right|").concat(out.slice(close + 1));
203
- idx = out.indexOf('\\abs{');
204
- }
205
- return out;
206
- };
207
-
208
- /**
209
- * Ids of the answer blocks in a piece of stored latex, in document order.
210
- *
211
- * @param {string} latex
212
- * @returns {string[]}
213
- */
214
- var fieldIds = exports.fieldIds = function fieldIds(latex) {
215
- if (typeof latex !== 'string') {
216
- return [];
217
- }
218
- var out = [];
219
- var match;
220
- MQ_FIELD_REGEX.lastIndex = 0;
221
- while ((match = MQ_FIELD_REGEX.exec(latex)) !== null) {
222
- out.push(match[1] || DEFAULT_FIELD_ID);
223
- }
224
- return out;
225
- };
226
-
227
- /**
228
- * Convert stored latex (which may contain `\embed{newLine}[]`) into latex that
229
- * MathLive can parse and render as multiple lines.
230
- *
231
- * @param {string} latex
232
- * @returns {string}
233
- */
234
- var toMathLive = exports.toMathLive = function toMathLive(latex) {
235
- if (typeof latex !== 'string' || !latex) {
236
- return latex || '';
237
- }
238
-
239
- // Argument-taking pie commands -> native constructs, so their content stays
240
- // editable and serialises back correctly (see toNativeCommands).
241
- var out = toNativeCommands(latex);
242
-
243
- // Answer blocks: \MathQuillMathField[id]{x} -> \placeholder[id]{x}
244
- out = out.replace(MQ_FIELD_REGEX, function (_m, id, content) {
245
- return "\\placeholder[".concat(id || DEFAULT_FIELD_ID, "]{").concat(content, "}");
246
- });
247
-
248
- // Newlines: \embed{newLine}[] -> a multiline environment
249
- if (out.indexOf(NEWLINE_EMBED) !== -1) {
250
- out = "\\displaylines{".concat(out.split(NEWLINE_EMBED_REGEX).join(' \\\\ '), "}");
251
- }
252
- return out;
253
- };
254
-
255
- /**
256
- * Keypad command names that MathQuill treated as ALIASES of a different command.
257
- *
258
- * MathQuill registered `\\divide` as another name for `\\div` (and
259
- * `\\perpendicular` for `\\perp`), so pressing the key stored the real command.
260
- * MathLive only knows these names through `PIE_MACROS`, and serialises a macro
261
- * under its own name - so `\\divide` reached storage verbatim, where MathJax
262
- * (@pie-lib/math-rendering) has no such command and renders it as red text.
263
- *
264
- * Every other keypad command already matches what MathQuill stored (`\\degree`,
265
- * `\\nsim`, `\\ncong`, `\\nparallel`, `\\square`, `\\napprox`,
266
- * `\\parallelogram`), and MathJax understands those.
267
- */
268
- var MATHQUILL_ALIASES = exports.MATHQUILL_ALIASES = {
269
- '\\divide': '\\div',
270
- '\\perpendicular': '\\perp'
271
- };
272
-
273
- // Whole command names only: `\\divideontimes` is a real AMS symbol.
274
- var MATHQUILL_ALIAS_REGEX = /\\(divide|perpendicular)(?![a-zA-Z])/g;
275
-
276
- /**
277
- * Primes. MathLive turns a prime that follows a base into a superscript atom and
278
- * serialises it as `^{\\prime}`, or `^{\\doubleprime}` for the keypad's double
279
- * prime key (`5''` comes back out as `5^{\\doubleprime}`). MathJax has no
280
- * `\\doubleprime`, and two adjacent `^{\\prime}` groups - what typing `'` twice
281
- * produces - are a "double exponent" error. MathQuill stored plain apostrophes,
282
- * which both MathJax and MathLive read as primes, so store those.
283
- *
284
- * Only a superscript made of primes alone is rewritten: `x^{\\prime 2}` keeps
285
- * its group, since it holds more than primes.
286
- */
287
- var PRIME_SUPERSCRIPT_REGEX = /\^\{((?:\s*\\(?:prime|doubleprime)(?![a-zA-Z]))+)\s*\}/g;
288
- var BARE_DOUBLEPRIME_REGEX = /\\doubleprime(?![a-zA-Z])/g;
289
- var primesToApostrophes = function primesToApostrophes(primes) {
290
- return (
291
- // eslint-disable-next-line quotes
292
- "'".repeat((primes.match(/\\prime(?![a-zA-Z])/g) || []).length + 2 * (primes.match(BARE_DOUBLEPRIME_REGEX) || []).length)
293
- );
294
- };
295
- var BARE_PRIME_COMMAND_REGEX = /^\\(doubleprime|prime)(?![a-zA-Z])/;
296
-
297
- /**
298
- * Primes that are *not* in a superscript.
299
- *
300
- * MathLive emits bare `\prime` / `\doubleprime` for a `′` or `″` typed or pasted
301
- * as a character (`5′6″` serialises as `5\prime6\doubleprime`). A bare `\prime`
302
- * is a full-size glyph in MathJax, while `''` is a superscript, so storing
303
- * `5\prime6''` drew the single prime visibly larger than each stroke of the
304
- * double prime. Both become apostrophes, the superscript primes MathQuill
305
- * stored, so they always match.
306
- *
307
- * Inside a script (`x^{\prime 2}`, `x^\prime`) a prime is already a
308
- * superscript, and an apostrophe there would mean something else, so
309
- * `\prime` is kept and `\doubleprime` (unknown to MathJax) becomes
310
- * `\prime\prime`.
311
- *
312
- * @param {string} latex
313
- * @returns {string}
314
- */
315
- var barePrimesToApostrophes = function barePrimesToApostrophes(latex) {
316
- if (latex.indexOf('prime') === -1) {
317
- return latex;
318
- }
319
-
320
- // One entry per open brace: is that group a super/subscript?
321
- var groups = [];
322
- var out = '';
323
- var i = 0;
324
- while (i < latex.length) {
325
- var ch = latex[i];
326
- if (ch === '\\') {
327
- var match = latex.slice(i).match(BARE_PRIME_COMMAND_REGEX);
328
- if (match) {
329
- var isDouble = match[1] === 'doubleprime';
330
- // `x^\prime`: the command is itself the script.
331
- var isScriptArgument = /[\^_]\s*$/.test(out);
332
- var inScript = isScriptArgument || groups.indexOf(true) !== -1;
333
- if (inScript) {
334
- out += isDouble ? '\\prime\\prime' : '\\prime';
335
- } else {
336
- // eslint-disable-next-line quotes
337
- out += isDouble ? "''" : "'";
338
- }
339
- i += match[0].length;
340
- continue;
341
- }
342
-
343
- // Copy any other command, or an escaped character such as `\{`, whole.
344
- var command = latex.slice(i).match(/^\\(?:[a-zA-Z]+|.)/);
345
- var text = command ? command[0] : ch;
346
- out += text;
347
- i += text.length;
348
- continue;
349
- }
350
- if (ch === '{') {
351
- groups.push(/[\^_]\s*$/.test(out));
352
- } else if (ch === '}') {
353
- groups.pop();
354
- }
355
- out += ch;
356
- i += 1;
357
- }
358
- return out;
359
- };
360
-
361
- /**
362
- * Rewrite what MathLive serialises into the form MathQuill stored: alias
363
- * command names, and primes.
364
- *
365
- * @param {string} latex
366
- * @returns {string}
367
- */
368
- var toCanonicalCommands = exports.toCanonicalCommands = function toCanonicalCommands(latex) {
369
- return typeof latex === 'string' ? barePrimesToApostrophes(latex.replace(MATHQUILL_ALIAS_REGEX, function (m) {
370
- return MATHQUILL_ALIASES[m];
371
- }).replace(PRIME_SUPERSCRIPT_REGEX, function (_m, primes) {
372
- return primesToApostrophes(primes);
373
- })) : latex;
374
- };
375
-
376
- /**
377
- * Convert latex out of MathLive back into the stored form, so items authored
378
- * with the MathLive editor remain readable by @pie-lib/math-rendering and by
379
- * the existing MathQuill implementation.
380
- *
381
- * @param {string} latex
382
- * @returns {string}
383
- */
384
- var fromMathLive = exports.fromMathLive = function fromMathLive(latex) {
385
- if (typeof latex !== 'string' || !latex) {
386
- return latex || '';
387
- }
388
- var match = latex.trim().match(DISPLAYLINES_REGEX);
389
- var out = match ? match[1] : latex;
390
-
391
- // `\\` is the line separator inside a multiline environment.
392
- if (out.indexOf('\\\\') !== -1) {
393
- out = out.split(/\s*\\\\\s*/).map(function (s) {
394
- return s.trim();
395
- }).join(NEWLINE_EMBED);
396
- }
397
-
398
- // Answer blocks: \placeholder[id]{x} -> \MathQuillMathField[id]{x}
399
- out = out.replace(PLACEHOLDER_REGEX, function (_m, id, content) {
400
- return "\\MathQuillMathField[".concat(id || DEFAULT_FIELD_ID, "]{").concat(content, "}");
401
- });
402
-
403
- // Unnamed placeholders are MathLive's own representation of an empty slot and
404
- // must not reach storage or MathJax. Unwrap them: keep any content, drop the
405
- // command itself (the surrounding braces are already part of the host latex,
406
- // so re-adding them here would produce `\longdiv{{}}`).
407
- out = out.replace(BARE_PLACEHOLDER_REGEX, function (_m, content) {
408
- return content;
409
- });
410
- out = out.replace(BARE_PLACEHOLDER_NO_ARG_REGEX, '');
411
-
412
- // Store the command MathQuill stored, not the alias - also heals latex that was
413
- // saved with `\\divide` before the keypad resolved it.
414
- return toCanonicalCommands(out);
415
- };
416
-
417
- /**
418
- * MathQuill `cmd()` semantics: commands that take arguments should land the
419
- * cursor inside the first argument. MathLive expresses that with `#?`
420
- * placeholders in the inserted latex.
421
- */
422
- var COMMANDS_WITH_ARGS = exports.COMMANDS_WITH_ARGS = {
423
- // An explicit "blank over blank" key: both slots start empty.
424
- '\\frac': '\\frac{#?}{#?}',
425
- // Division, which must behave like MathQuill's `/`: whatever precedes the
426
- // cursor becomes the numerator and the caret lands in the denominator. `#@`
427
- // is MathLive's token for "the selection, or the item before the cursor" -
428
- // this is exactly the template MathLive binds to the `/` key itself. Using
429
- // `#?` here instead produced an empty fraction and left the typed number
430
- // stranded outside it.
431
- '/': '\\frac{#@}{#?}',
432
- '\\sqrt': '\\sqrt{#?}',
433
- '\\nthroot': '\\sqrt[#?]{#?}',
434
- '\\overline': '\\overline{#?}',
435
- '\\overrightarrow': '\\overrightarrow{#?}',
436
- '\\overleftrightarrow': '\\overleftrightarrow{#?}',
437
- // Native forms, not the pie macros: a macro would not serialise the user's
438
- // typed content back out (see toNativeCommands).
439
- '\\overarc': '\\overparen{#?}',
440
- '\\longdiv': '\\enclose{longdiv}{#?}',
441
- '^': '^{#?}',
442
- _: '_{#?}',
443
- '(': '\\left(#?\\right)',
444
- '[': '\\left[#?\\right]',
445
- '|': '\\left|#?\\right|'
446
- };
447
-
448
- /**
449
- * MathQuill keystroke names -> MathLive command selectors.
450
- */
451
- var KEYSTROKES = exports.KEYSTROKES = {
452
- Left: 'moveToPreviousChar',
453
- Right: 'moveToNextChar',
454
- Backspace: 'deleteBackward',
455
- Delete: 'deleteForward',
456
- Up: 'moveUp',
457
- Down: 'moveDown'
458
- };
459
-
460
- /**
461
- * Translate a keypad key definition into a MathLive action.
462
- *
463
- * Mirrors the precedence in @pie-lib/math-input's MathInput.keypadPress:
464
- * latex (unless a command is present) -> write -> command -> keystroke.
465
- *
466
- * @param {object} key
467
- * @returns {{type: 'insert'|'command', value: string}|undefined}
468
- */
469
- var keyToAction = exports.keyToAction = function keyToAction(key) {
470
- if (!key) {
471
- return undefined;
472
- }
473
- if (key.latex && !key.command) {
474
- return {
475
- type: 'insert',
476
- value: key.latex
477
- };
478
- }
479
- if (key.write) {
480
- return {
481
- type: 'insert',
482
- value: key.write
483
- };
484
- }
485
- if (key.command) {
486
- // Some keys carry an array of commands (e.g. Measured Angle is
487
- // ['m', '\\angle'], log-base-n is ['\\log', '_']). MathQuill's `cmd()`
488
- // applied them in sequence; MathLive inserts one latex string, so expand
489
- // each part and concatenate.
490
- var parts = Array.isArray(key.command) ? key.command : [key.command];
491
- var value = parts.map(function (c) {
492
- return COMMANDS_WITH_ARGS[c] || MATHQUILL_ALIASES[c] || c;
493
- }).join('');
494
- return {
495
- type: 'insert',
496
- value: value
497
- };
498
- }
499
- if (key.keystroke) {
500
- var selector = KEYSTROKES[key.keystroke];
501
- return selector ? {
502
- type: 'command',
503
- value: selector
504
- } : undefined;
505
- }
506
- return undefined;
507
- };
508
- //# sourceMappingURL=latex-bridge.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"latex-bridge.js","names":["NEWLINE_EMBED","exports","NEWLINE_EMBED_REGEX","DISPLAYLINES_REGEX","MQ_FIELD_REGEX","PLACEHOLDER_REGEX","BARE_PLACEHOLDER_REGEX","BARE_PLACEHOLDER_NO_ARG_REGEX","DEFAULT_FIELD_ID","EMPTY_SLOT","EMPTY_GROUP_REGEX","EMPTY_OVERLINE_REGEX","EMPTY_OVERLINE_STRUT","EMPTY_FENCE_REGEX","EMPTY_FENCE_SLOT","withVisibleEmptySlots","latex","replace","concat","_m","open","close","toNativeCommands","out","replaceAbs","escapeBareComments","indexOf","backslashes","i","length","ch","idx","depth","inner","slice","fieldIds","match","lastIndex","exec","push","toMathLive","id","content","split","join","MATHQUILL_ALIASES","MATHQUILL_ALIAS_REGEX","PRIME_SUPERSCRIPT_REGEX","BARE_DOUBLEPRIME_REGEX","primesToApostrophes","primes","repeat","BARE_PRIME_COMMAND_REGEX","barePrimesToApostrophes","groups","isDouble","isScriptArgument","test","inScript","command","text","pop","toCanonicalCommands","m","fromMathLive","trim","map","s","COMMANDS_WITH_ARGS","_","KEYSTROKES","Left","Right","Backspace","Delete","Up","Down","keyToAction","key","undefined","type","value","write","parts","Array","isArray","c","keystroke","selector"],"sources":["../src/latex-bridge.js"],"sourcesContent":["/**\n * LaTeX translation layer between the MathQuill-era content model and MathLive.\n *\n * Two independent concerns live here:\n *\n * 1. Newlines. MathQuill had no line break, so pie-lib registered a custom\n * `newLine` embed that serialises to `\\embed{newLine}[]`. MathLive has no\n * embed system but supports real multiline environments, so we translate\n * `\\embed{newLine}[]` <-> `\\\\` inside `\\displaylines{}`.\n *\n * Authored content keeps its `\\embed{newLine}[]` on-disk form (that is what\n * @pie-lib/math-rendering already normalises for MathJax), so each renderer\n * normalises at its own boundary and stored items stay compatible.\n *\n * 2. Keypad key -> MathLive action. MathQuill keys carry `write`/`command`/\n * `keystroke` built for `mf.write()` / `mf.cmd()` / `mf.keystroke()`.\n * MathLive has `insert()` and `executeCommand()` instead.\n */\n\nexport const NEWLINE_EMBED = '\\\\embed{newLine}[]';\nconst NEWLINE_EMBED_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst DISPLAYLINES_REGEX = /^\\\\displaylines\\{([\\s\\S]*)\\}$/;\n\n/**\n * MathQuill's editable sub-field syntax, e.g. `\\MathQuillMathField[r1]{}`.\n * These are the answer blocks in templated math items; MathLive expresses the\n * same idea as `\\placeholder[id]{}` and reads them back via the prompts API.\n */\nconst MQ_FIELD_REGEX = /\\\\MathQuillMathField\\[([^\\]]*)\\]\\{([^{}]*)\\}/g;\nconst PLACEHOLDER_REGEX = /\\\\placeholder\\[([^\\]]*)\\]\\{([^{}]*)\\}/g;\n\n/**\n * Unnamed placeholders, which MathLive inserts on its own.\n *\n * Typing a command with empty arguments (`\\longdiv{}`, `\\frac{}{}`) makes\n * MathLive serialise the empty slots as `\\placeholder{}`. That token is\n * MathLive-specific: MathJax - which @pie-lib/math-rendering uses to render\n * prompts and previews - has no such command and renders it as red error text.\n * Stored latex must therefore keep plain empty groups.\n */\nconst BARE_PLACEHOLDER_REGEX = /\\\\placeholder\\{([^{}]*)\\}/g;\nconst BARE_PLACEHOLDER_NO_ARG_REGEX = /\\\\placeholder(?![[{a-zA-Z])/g;\n\n/** Default id used when stored latex has an unnamed field. */\nexport const DEFAULT_FIELD_ID = 'r1';\n\n/**\n * A visible stand-in for an empty argument slot, used for STATIC rendering only.\n *\n * Stored latex legitimately contains empty groups - `\\longdiv{}`, `\\frac{}{}`,\n * `x^{}` - to express a command's shape. MathQuill drew those as a shaded box\n * (`.mq-empty`); MathLive renders `{}` as nothing, so `convertLatexToMarkup`\n * output comes out completely blank (not even the surrounding bracket, in the\n * case of `\\enclose{longdiv}{}`).\n *\n * `\\placeholder{}` is not usable here: in static markup it renders as a\n * non-breaking space, because its editable box only exists inside a live\n * mathfield. So something with real width is required.\n *\n * It must be a `\\rule`, not a unicode glyph. A glyph's width comes from font\n * metrics, and U+25AB is not in the KaTeX fonts - the browser substitutes a\n * wider fallback while MathLive still sizes surrounding accents from its own\n * metrics. That left stretchy accents (`\\overarc`, `\\overleftrightarrow`)\n * visibly narrower than the box they were meant to span. A rule carries an\n * explicit em width, so accents size correctly - and a filled box is closer to\n * MathQuill's `.mq-empty` anyway.\n *\n * Live mathfields need none of this - MathLive manages empty slots itself.\n */\nconst EMPTY_SLOT = '\\\\htmlData{pie-empty=1}{\\\\rule{0.55em}{0.55em}}';\nconst EMPTY_GROUP_REGEX = /\\{\\s*\\}/g;\n// The segment key (`\\overline{}`). A bar is a thin accent, so its label is shorter\n// than the ray and line keys' stretchy arrows. The keypad centres every label\n// in its cell, so the bar's box ended up ~0.17em higher than theirs.\nconst EMPTY_OVERLINE_REGEX = /\\\\overline\\{\\s*\\}/g;\nconst EMPTY_OVERLINE_STRUT = '\\\\rule{0em}{1.08em}';\n// Empty delimiter pairs: `\\abs{}` is converted to `\\left|\\right|`, and the\n// parenthesis / bracket keys are `\\left(\\right)` / `\\left[\\right]`. None has a\n// `{}` group for the rule above to catch, so they would render as bare fences.\nconst EMPTY_FENCE_REGEX = /\\\\left([([|])\\s*\\\\right([)\\]|])/g;\n// The same muted fill as the other slots (`pie-empty`), but a tall rectangle\n// rather than a square. It also sets the fences' height: `\\left...\\right` stretch\n// to their content, so a taller slot gives taller parentheses.\n//\n// A `\\rule` stands on the baseline, but the fences are centred on the math axis\n// (0.25em above it), so an un-lifted box sat high between them. `[-0.25em]`\n// lowers it by (axis - height / 2) = 0.25 - 1 / 2, centring it on the axis.\n//\n// Lowering it alone also shrinks the fences, which size themselves to their\n// content (MathLive switches to short bars). The zero-width `\\rule{0em}{1em}`\n// strut keeps the content as tall as before, so the bars keep their height and\n// only the box moves.\nconst EMPTY_FENCE_SLOT = '\\\\rule{0em}{1em}\\\\htmlData{pie-empty=1}{\\\\rule[-0.25em]{0.55em}{1em}}';\n\n/**\n * Make empty argument slots visible, for static rendering.\n *\n * Display-only: never feed the result to a mathfield or to storage - the\n * original latex is what gets typed and saved.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const withVisibleEmptySlots = (latex) =>\n (latex || '')\n .replace(EMPTY_OVERLINE_REGEX, `\\\\overline{${EMPTY_OVERLINE_STRUT}${EMPTY_SLOT}}`)\n .replace(EMPTY_GROUP_REGEX, `{${EMPTY_SLOT}}`)\n .replace(EMPTY_FENCE_REGEX, (_m, open, close) => `\\\\left${open}${EMPTY_FENCE_SLOT}\\\\right${close}`);\n\n/**\n * Pie commands that take an argument, and their native MathLive equivalents.\n *\n * These MUST NOT be handled as MathLive macros. A macro is serialised from the\n * arguments it was created with, so text typed inside its expansion never makes\n * it back out: `getValue('latex')` keeps returning `\\longdiv{\\placeholder{}}`\n * while `getValue('ascii-math')` shows the typed content. Setting\n * `captureSelection: false` lets the cursor in but does not change\n * serialisation.\n *\n * Expanding to native constructs instead gives real, editable atoms that\n * round-trip. All three targets are understood by MathJax too, so stored latex\n * still renders in @pie-lib/math-rendering without a reverse mapping.\n */\n/**\n * Rewrite argument-taking pie commands into native MathLive latex.\n * Applied on the way *into* a mathfield.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const toNativeCommands = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n let out = latex;\n\n // \\abs{x} -> \\left|x\\right| needs brace-aware handling, the rest are prefix\n // swaps.\n out = replaceAbs(out);\n out = out.replace(/\\\\longdiv\\{/g, '\\\\enclose{longdiv}{');\n out = out.replace(/\\\\overarc\\{/g, '\\\\overparen{');\n out = escapeBareComments(out);\n\n return out;\n};\n\n/**\n * Escape an unescaped `%`.\n *\n * In real LaTeX `%` starts a comment, so MathLive discards it *and everything\n * after it*: `50%` renders as `50`, and `x%y` as just `x`. MathQuill had no\n * such notion - it treated `%` as a symbol - so latex from anywhere outside the\n * keypad may still carry a bare one.\n *\n * Only a `%` preceded by an even number of backslashes is bare: `\\%` is already\n * escaped, while the `%` in `\\\\%` (a line break, then a comment) is not.\n *\n * @param {string} latex\n * @returns {string}\n */\nconst escapeBareComments = (latex) => {\n if (latex.indexOf('%') === -1) {\n return latex;\n }\n\n let out = '';\n // Consecutive backslashes immediately before the current character.\n let backslashes = 0;\n\n for (let i = 0; i < latex.length; i++) {\n const ch = latex[i];\n\n out += ch === '%' && backslashes % 2 === 0 ? '\\\\%' : ch;\n backslashes = ch === '\\\\' ? backslashes + 1 : 0;\n }\n\n return out;\n};\n\n/** `\\abs{x}` -> `\\left|x\\right|`, matching balanced braces. */\nconst replaceAbs = (latex) => {\n let out = latex;\n let idx = out.indexOf('\\\\abs{');\n\n while (idx !== -1) {\n const open = idx + '\\\\abs{'.length - 1;\n let depth = 0;\n let close = -1;\n\n for (let i = open; i < out.length; i++) {\n if (out[i] === '{') depth++;\n else if (out[i] === '}') {\n depth--;\n if (depth === 0) {\n close = i;\n break;\n }\n }\n }\n\n if (close === -1) {\n break;\n }\n\n const inner = out.slice(open + 1, close);\n\n out = `${out.slice(0, idx)}\\\\left|${inner}\\\\right|${out.slice(close + 1)}`;\n idx = out.indexOf('\\\\abs{');\n }\n\n return out;\n};\n\n/**\n * Ids of the answer blocks in a piece of stored latex, in document order.\n *\n * @param {string} latex\n * @returns {string[]}\n */\nexport const fieldIds = (latex) => {\n if (typeof latex !== 'string') {\n return [];\n }\n\n const out = [];\n let match;\n\n MQ_FIELD_REGEX.lastIndex = 0;\n\n while ((match = MQ_FIELD_REGEX.exec(latex)) !== null) {\n out.push(match[1] || DEFAULT_FIELD_ID);\n }\n\n return out;\n};\n\n/**\n * Convert stored latex (which may contain `\\embed{newLine}[]`) into latex that\n * MathLive can parse and render as multiple lines.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const toMathLive = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n // Argument-taking pie commands -> native constructs, so their content stays\n // editable and serialises back correctly (see toNativeCommands).\n let out = toNativeCommands(latex);\n\n // Answer blocks: \\MathQuillMathField[id]{x} -> \\placeholder[id]{x}\n out = out.replace(MQ_FIELD_REGEX, (_m, id, content) => `\\\\placeholder[${id || DEFAULT_FIELD_ID}]{${content}}`);\n\n // Newlines: \\embed{newLine}[] -> a multiline environment\n if (out.indexOf(NEWLINE_EMBED) !== -1) {\n out = `\\\\displaylines{${out.split(NEWLINE_EMBED_REGEX).join(' \\\\\\\\ ')}}`;\n }\n\n return out;\n};\n\n/**\n * Keypad command names that MathQuill treated as ALIASES of a different command.\n *\n * MathQuill registered `\\\\divide` as another name for `\\\\div` (and\n * `\\\\perpendicular` for `\\\\perp`), so pressing the key stored the real command.\n * MathLive only knows these names through `PIE_MACROS`, and serialises a macro\n * under its own name - so `\\\\divide` reached storage verbatim, where MathJax\n * (@pie-lib/math-rendering) has no such command and renders it as red text.\n *\n * Every other keypad command already matches what MathQuill stored (`\\\\degree`,\n * `\\\\nsim`, `\\\\ncong`, `\\\\nparallel`, `\\\\square`, `\\\\napprox`,\n * `\\\\parallelogram`), and MathJax understands those.\n */\nconst MATHQUILL_ALIASES = {\n '\\\\divide': '\\\\div',\n '\\\\perpendicular': '\\\\perp',\n};\n\n// Whole command names only: `\\\\divideontimes` is a real AMS symbol.\nconst MATHQUILL_ALIAS_REGEX = /\\\\(divide|perpendicular)(?![a-zA-Z])/g;\n\n/**\n * Primes. MathLive turns a prime that follows a base into a superscript atom and\n * serialises it as `^{\\\\prime}`, or `^{\\\\doubleprime}` for the keypad's double\n * prime key (`5''` comes back out as `5^{\\\\doubleprime}`). MathJax has no\n * `\\\\doubleprime`, and two adjacent `^{\\\\prime}` groups - what typing `'` twice\n * produces - are a \"double exponent\" error. MathQuill stored plain apostrophes,\n * which both MathJax and MathLive read as primes, so store those.\n *\n * Only a superscript made of primes alone is rewritten: `x^{\\\\prime 2}` keeps\n * its group, since it holds more than primes.\n */\nconst PRIME_SUPERSCRIPT_REGEX = /\\^\\{((?:\\s*\\\\(?:prime|doubleprime)(?![a-zA-Z]))+)\\s*\\}/g;\nconst BARE_DOUBLEPRIME_REGEX = /\\\\doubleprime(?![a-zA-Z])/g;\n\nconst primesToApostrophes = (primes) =>\n // eslint-disable-next-line quotes\n \"'\".repeat(\n (primes.match(/\\\\prime(?![a-zA-Z])/g) || []).length + 2 * (primes.match(BARE_DOUBLEPRIME_REGEX) || []).length,\n );\n\nconst BARE_PRIME_COMMAND_REGEX = /^\\\\(doubleprime|prime)(?![a-zA-Z])/;\n\n/**\n * Primes that are *not* in a superscript.\n *\n * MathLive emits bare `\\prime` / `\\doubleprime` for a `′` or `″` typed or pasted\n * as a character (`5′6″` serialises as `5\\prime6\\doubleprime`). A bare `\\prime`\n * is a full-size glyph in MathJax, while `''` is a superscript, so storing\n * `5\\prime6''` drew the single prime visibly larger than each stroke of the\n * double prime. Both become apostrophes, the superscript primes MathQuill\n * stored, so they always match.\n *\n * Inside a script (`x^{\\prime 2}`, `x^\\prime`) a prime is already a\n * superscript, and an apostrophe there would mean something else, so\n * `\\prime` is kept and `\\doubleprime` (unknown to MathJax) becomes\n * `\\prime\\prime`.\n *\n * @param {string} latex\n * @returns {string}\n */\nconst barePrimesToApostrophes = (latex) => {\n if (latex.indexOf('prime') === -1) {\n return latex;\n }\n\n // One entry per open brace: is that group a super/subscript?\n const groups = [];\n let out = '';\n let i = 0;\n\n while (i < latex.length) {\n const ch = latex[i];\n\n if (ch === '\\\\') {\n const match = latex.slice(i).match(BARE_PRIME_COMMAND_REGEX);\n\n if (match) {\n const isDouble = match[1] === 'doubleprime';\n // `x^\\prime`: the command is itself the script.\n const isScriptArgument = /[\\^_]\\s*$/.test(out);\n const inScript = isScriptArgument || groups.indexOf(true) !== -1;\n\n if (inScript) {\n out += isDouble ? '\\\\prime\\\\prime' : '\\\\prime';\n } else {\n // eslint-disable-next-line quotes\n out += isDouble ? \"''\" : \"'\";\n }\n\n i += match[0].length;\n continue;\n }\n\n // Copy any other command, or an escaped character such as `\\{`, whole.\n const command = latex.slice(i).match(/^\\\\(?:[a-zA-Z]+|.)/);\n const text = command ? command[0] : ch;\n\n out += text;\n i += text.length;\n continue;\n }\n\n if (ch === '{') {\n groups.push(/[\\^_]\\s*$/.test(out));\n } else if (ch === '}') {\n groups.pop();\n }\n\n out += ch;\n i += 1;\n }\n\n return out;\n};\n\n/**\n * Rewrite what MathLive serialises into the form MathQuill stored: alias\n * command names, and primes.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const toCanonicalCommands = (latex) =>\n typeof latex === 'string'\n ? barePrimesToApostrophes(\n latex\n .replace(MATHQUILL_ALIAS_REGEX, (m) => MATHQUILL_ALIASES[m])\n .replace(PRIME_SUPERSCRIPT_REGEX, (_m, primes) => primesToApostrophes(primes)),\n )\n : latex;\n\n/**\n * Convert latex out of MathLive back into the stored form, so items authored\n * with the MathLive editor remain readable by @pie-lib/math-rendering and by\n * the existing MathQuill implementation.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const fromMathLive = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n const match = latex.trim().match(DISPLAYLINES_REGEX);\n let out = match ? match[1] : latex;\n\n // `\\\\` is the line separator inside a multiline environment.\n if (out.indexOf('\\\\\\\\') !== -1) {\n out = out\n .split(/\\s*\\\\\\\\\\s*/)\n .map((s) => s.trim())\n .join(NEWLINE_EMBED);\n }\n\n // Answer blocks: \\placeholder[id]{x} -> \\MathQuillMathField[id]{x}\n out = out.replace(\n PLACEHOLDER_REGEX,\n (_m, id, content) => `\\\\MathQuillMathField[${id || DEFAULT_FIELD_ID}]{${content}}`,\n );\n\n // Unnamed placeholders are MathLive's own representation of an empty slot and\n // must not reach storage or MathJax. Unwrap them: keep any content, drop the\n // command itself (the surrounding braces are already part of the host latex,\n // so re-adding them here would produce `\\longdiv{{}}`).\n out = out.replace(BARE_PLACEHOLDER_REGEX, (_m, content) => content);\n out = out.replace(BARE_PLACEHOLDER_NO_ARG_REGEX, '');\n\n // Store the command MathQuill stored, not the alias - also heals latex that was\n // saved with `\\\\divide` before the keypad resolved it.\n return toCanonicalCommands(out);\n};\n\n/**\n * MathQuill `cmd()` semantics: commands that take arguments should land the\n * cursor inside the first argument. MathLive expresses that with `#?`\n * placeholders in the inserted latex.\n */\nconst COMMANDS_WITH_ARGS = {\n // An explicit \"blank over blank\" key: both slots start empty.\n '\\\\frac': '\\\\frac{#?}{#?}',\n // Division, which must behave like MathQuill's `/`: whatever precedes the\n // cursor becomes the numerator and the caret lands in the denominator. `#@`\n // is MathLive's token for \"the selection, or the item before the cursor\" -\n // this is exactly the template MathLive binds to the `/` key itself. Using\n // `#?` here instead produced an empty fraction and left the typed number\n // stranded outside it.\n '/': '\\\\frac{#@}{#?}',\n '\\\\sqrt': '\\\\sqrt{#?}',\n '\\\\nthroot': '\\\\sqrt[#?]{#?}',\n '\\\\overline': '\\\\overline{#?}',\n '\\\\overrightarrow': '\\\\overrightarrow{#?}',\n '\\\\overleftrightarrow': '\\\\overleftrightarrow{#?}',\n // Native forms, not the pie macros: a macro would not serialise the user's\n // typed content back out (see toNativeCommands).\n '\\\\overarc': '\\\\overparen{#?}',\n '\\\\longdiv': '\\\\enclose{longdiv}{#?}',\n '^': '^{#?}',\n _: '_{#?}',\n '(': '\\\\left(#?\\\\right)',\n '[': '\\\\left[#?\\\\right]',\n '|': '\\\\left|#?\\\\right|',\n};\n\n/**\n * MathQuill keystroke names -> MathLive command selectors.\n */\nconst KEYSTROKES = {\n Left: 'moveToPreviousChar',\n Right: 'moveToNextChar',\n Backspace: 'deleteBackward',\n Delete: 'deleteForward',\n Up: 'moveUp',\n Down: 'moveDown',\n};\n\n/**\n * Translate a keypad key definition into a MathLive action.\n *\n * Mirrors the precedence in @pie-lib/math-input's MathInput.keypadPress:\n * latex (unless a command is present) -> write -> command -> keystroke.\n *\n * @param {object} key\n * @returns {{type: 'insert'|'command', value: string}|undefined}\n */\nexport const keyToAction = (key) => {\n if (!key) {\n return undefined;\n }\n\n if (key.latex && !key.command) {\n return { type: 'insert', value: key.latex };\n }\n\n if (key.write) {\n return { type: 'insert', value: key.write };\n }\n\n if (key.command) {\n // Some keys carry an array of commands (e.g. Measured Angle is\n // ['m', '\\\\angle'], log-base-n is ['\\\\log', '_']). MathQuill's `cmd()`\n // applied them in sequence; MathLive inserts one latex string, so expand\n // each part and concatenate.\n const parts = Array.isArray(key.command) ? key.command : [key.command];\n const value = parts.map((c) => COMMANDS_WITH_ARGS[c] || MATHQUILL_ALIASES[c] || c).join('');\n\n return { type: 'insert', value };\n }\n\n if (key.keystroke) {\n const selector = KEYSTROKES[key.keystroke];\n\n return selector ? { type: 'command', value: selector } : undefined;\n }\n\n return undefined;\n};\n\nexport { COMMANDS_WITH_ARGS, KEYSTROKES, MATHQUILL_ALIASES };\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,IAAMA,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,oBAAoB;AACjD,IAAME,mBAAmB,GAAG,yBAAyB;AACrD,IAAMC,kBAAkB,GAAG,+BAA+B;;AAE1D;AACA;AACA;AACA;AACA;AACA,IAAMC,cAAc,GAAG,+CAA+C;AACtE,IAAMC,iBAAiB,GAAG,wCAAwC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,sBAAsB,GAAG,4BAA4B;AAC3D,IAAMC,6BAA6B,GAAG,8BAA8B;;AAEpE;AACO,IAAMC,gBAAgB,GAAAP,OAAA,CAAAO,gBAAA,GAAG,IAAI;;AA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