@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
@@ -0,0 +1,17 @@
1
+ import { __exportAll as e } from "../_virtual/_rolldown/runtime.js";
2
+ import { mkSet as t } from "./utils.js";
3
+ //#region src/keys/sub-sup.ts
4
+ var n = /* @__PURE__ */ e({
5
+ subscript: () => a,
6
+ superscript: () => i
7
+ }), r = t("sub-sup"), i = r({
8
+ name: "Superscript",
9
+ latex: "x^{}",
10
+ command: "^"
11
+ }), a = r({
12
+ name: "Subscript",
13
+ latex: "x_{}",
14
+ command: "_"
15
+ });
16
+ //#endregion
17
+ export { n as sub_sup_exports, a as subscript, i as superscript };
@@ -0,0 +1,6 @@
1
+ export declare const sin: any;
2
+ export declare const cos: any;
3
+ export declare const tan: any;
4
+ export declare const sec: any;
5
+ export declare const csc: any;
6
+ export declare const cot: any;
@@ -0,0 +1,43 @@
1
+ import { __exportAll as e } from "../_virtual/_rolldown/runtime.js";
2
+ import { mkSet as t } from "./utils.js";
3
+ //#region src/keys/trigonometry.ts
4
+ var n = /* @__PURE__ */ e({
5
+ cos: () => a,
6
+ cot: () => l,
7
+ csc: () => c,
8
+ sec: () => s,
9
+ sin: () => i,
10
+ tan: () => o
11
+ }), r = t("trigonometry"), i = r({
12
+ name: "sine",
13
+ label: "sin",
14
+ command: "\\sin",
15
+ latex: "\\sin"
16
+ }), a = r({
17
+ name: "cosine",
18
+ label: "cos",
19
+ command: "\\cos",
20
+ latex: "\\cos"
21
+ }), o = r({
22
+ name: "tanget",
23
+ label: "tan",
24
+ command: "\\tan",
25
+ latex: "\\tan"
26
+ }), s = r({
27
+ name: "secant",
28
+ label: "sec",
29
+ command: "\\sec",
30
+ latex: "\\sec"
31
+ }), c = r({
32
+ name: "cosecant",
33
+ label: "csc",
34
+ command: "\\csc",
35
+ latex: "\\csc"
36
+ }), l = r({
37
+ name: "cotangent",
38
+ label: "cot",
39
+ command: "\\cot",
40
+ latex: "\\cot"
41
+ });
42
+ //#endregion
43
+ export { a as cos, l as cot, c as csc, s as sec, i as sin, o as tan, n as trigonometry_exports };
@@ -0,0 +1,5 @@
1
+ export declare const mkSet: (category: any) => (o: any) => any;
2
+ export declare const toArray: (o: any) => any[];
3
+ export declare const toKey: (category: any) => (v: any) => any;
4
+ export declare const transformToKeySetStructure: (data?: never[]) => any[];
5
+ export declare const extendKeySet: (base?: never[], keySetData?: never[]) => any[][];
@@ -0,0 +1,24 @@
1
+ import { flatten as e, times as t } from "@pie-element/shared-lodash";
2
+ //#region src/keys/utils.ts
3
+ var n = (e) => (t) => ({
4
+ ...t,
5
+ category: e
6
+ }), r = (e = []) => {
7
+ let n = [];
8
+ t(5, () => n.push([]));
9
+ let r = e.length, i = 0, a = 0;
10
+ for (; a < r;) n[i++].push(e[a++]), i === 5 && (i = 0);
11
+ return n;
12
+ }, i = (t) => (n) => {
13
+ let r = e(t), i = r.some((e) => e.latex === n.latex), a = r.some((e) => e.name === n.name);
14
+ return !i && !a;
15
+ }, a = (e = [], n = []) => {
16
+ n = n.filter(i(e));
17
+ let a = [];
18
+ t(5 - e.length, () => e.push([])), t(5, () => a.push([]));
19
+ let o = r(n);
20
+ for (let t = 0; t < 5; t++) a[t] = [...e[t], ...o[t]];
21
+ return a;
22
+ };
23
+ //#endregion
24
+ export { a as extendKeySet, n as mkSet, r as transformToKeySetStructure };
@@ -0,0 +1,3 @@
1
+ export declare const x: any;
2
+ export declare const y: any;
3
+ export declare const theta: any;
@@ -0,0 +1,22 @@
1
+ import { __exportAll as e } from "../_virtual/_rolldown/runtime.js";
2
+ import { mkSet as t } from "./utils.js";
3
+ //#region src/keys/vars.ts
4
+ var n = /* @__PURE__ */ e({
5
+ theta: () => o,
6
+ x: () => i,
7
+ y: () => a
8
+ }), r = t("vars"), i = r({
9
+ name: "X",
10
+ latex: "x",
11
+ write: "x"
12
+ }), a = r({
13
+ name: "Y",
14
+ latex: "y",
15
+ write: "y"
16
+ }), o = r({
17
+ name: "Theta",
18
+ latex: "\\theta",
19
+ write: "\\theta"
20
+ });
21
+ //#endregion
22
+ export { o as theta, n as vars_exports, i as x, a as y };
@@ -0,0 +1,197 @@
1
+ /**
2
+ * LaTeX translation layer between the MathQuill-era content model and MathLive.
3
+ *
4
+ * Two independent concerns live here:
5
+ *
6
+ * 1. Newlines. MathQuill had no line break, so pie-lib registered a custom
7
+ * `newLine` embed that serialises to `\embed{newLine}[]`. MathLive has no
8
+ * embed system but supports real multiline environments, so we translate
9
+ * `\embed{newLine}[]` <-> `\\` inside `\displaylines{}`.
10
+ *
11
+ * Authored content keeps its `\embed{newLine}[]` on-disk form (that is what
12
+ * @pie-lib/math-rendering already normalises for MathJax), so each renderer
13
+ * normalises at its own boundary and stored items stay compatible.
14
+ *
15
+ * 2. Keypad key -> MathLive action. MathQuill keys carry `write`/`command`/
16
+ * `keystroke` built for `mf.write()` / `mf.cmd()` / `mf.keystroke()`.
17
+ * MathLive has `insert()` and `executeCommand()` instead.
18
+ */
19
+ export declare const NEWLINE_EMBED = "\\embed{newLine}[]";
20
+ /**
21
+ * Static latex for a filled response area: the answer inside the same box a
22
+ * `\answerBlock` draws, tagged `data-answer-block` with the response id.
23
+ *
24
+ * This replaces MathQuill's pattern of rendering an empty embed and then
25
+ * running `applyStaticMath` on a span inside it, which has no equivalent in
26
+ * MathLive's markup.
27
+ *
28
+ * @param {string} id response id, e.g. `r1`
29
+ * @param {string} [answer] stored latex of the answer
30
+ * @returns {string}
31
+ */
32
+ export declare const answerBlockLatex: (id: any, answer: any) => string;
33
+ /** Default id used when stored latex has an unnamed field. */
34
+ export declare const DEFAULT_FIELD_ID = "r1";
35
+ /**
36
+ * Make empty argument slots visible, for static rendering.
37
+ *
38
+ * Display-only: never feed the result to a mathfield or to storage - the
39
+ * original latex is what gets typed and saved.
40
+ *
41
+ * @param {string} latex
42
+ * @returns {string}
43
+ */
44
+ export declare const withVisibleEmptySlots: (latex: any) => any;
45
+ /**
46
+ * Pie commands that take an argument, and their native MathLive equivalents.
47
+ *
48
+ * These MUST NOT be handled as MathLive macros. A macro is serialised from the
49
+ * arguments it was created with, so text typed inside its expansion never makes
50
+ * it back out: `getValue('latex')` keeps returning `\longdiv{\placeholder{}}`
51
+ * while `getValue('ascii-math')` shows the typed content. Setting
52
+ * `captureSelection: false` lets the cursor in but does not change
53
+ * serialisation.
54
+ *
55
+ * Expanding to native constructs instead gives real, editable atoms that
56
+ * round-trip. All three targets are understood by MathJax too, so stored latex
57
+ * still renders in @pie-lib/math-rendering without a reverse mapping.
58
+ */
59
+ /**
60
+ * Rewrite argument-taking pie commands into native MathLive latex.
61
+ * Applied on the way *into* a mathfield.
62
+ *
63
+ * @param {string} latex
64
+ * @returns {string}
65
+ */
66
+ export declare const toNativeCommands: (latex: any) => any;
67
+ /**
68
+ * Ids of the answer blocks in a piece of stored latex, in document order.
69
+ *
70
+ * @param {string} latex
71
+ * @returns {string[]}
72
+ */
73
+ export declare const fieldIds: (latex: any) => any[];
74
+ /**
75
+ * The answer in each answer block of stored latex, keyed by id.
76
+ *
77
+ * @param {string} latex
78
+ * @returns {Record<string, string>}
79
+ */
80
+ export declare const fieldValues: (latex: any) => {};
81
+ /**
82
+ * Stored latex with every answer block emptied: what stays the same while a
83
+ * student types.
84
+ *
85
+ * @param {string} latex
86
+ * @returns {string}
87
+ */
88
+ export declare const fieldTemplate: (latex: any) => any;
89
+ /**
90
+ * Stored latex with each answer block holding `values[id]`. Everything outside
91
+ * the blocks is kept exactly as stored, so it round-trips unchanged.
92
+ *
93
+ * @param {string} latex
94
+ * @param {Record<string, string>} values
95
+ * @returns {string}
96
+ */
97
+ export declare const fillFields: (latex: any, values: any) => string;
98
+ /**
99
+ * Latex for a text alternative: the same expression without the display-only
100
+ * markup that MathLive's MathML and speech conversions drop with its content.
101
+ *
102
+ * - `\htmlData{...}{x}` keeps `x`, and `\boxed{x}` keeps `x`;
103
+ * - an answer block's "R" label goes, as it is decoration;
104
+ * - an empty response area reads as a blank.
105
+ *
106
+ * @param {string} latex MathLive latex, after `toMathLive`
107
+ * @returns {string}
108
+ */
109
+ export declare const toAccessibleLatex: (latex: any) => any;
110
+ /**
111
+ * Convert stored latex (which may contain `\embed{newLine}[]`) into latex that
112
+ * MathLive can parse and render as multiple lines.
113
+ *
114
+ * @param {string} latex
115
+ * @returns {string}
116
+ */
117
+ export declare const toMathLive: (latex: any) => any;
118
+ /**
119
+ * Keypad command names that MathQuill treated as ALIASES of a different command.
120
+ *
121
+ * MathQuill registered `\\divide` as another name for `\\div` (and
122
+ * `\\perpendicular` for `\\perp`), so pressing the key stored the real command.
123
+ * MathLive only knows these names through `PIE_MACROS`, and serialises a macro
124
+ * under its own name - so `\\divide` reached storage verbatim, where MathJax
125
+ * (@pie-lib/math-rendering) has no such command and renders it as red text.
126
+ *
127
+ * Every other keypad command already matches what MathQuill stored (`\\degree`,
128
+ * `\\nsim`, `\\ncong`, `\\nparallel`, `\\square`, `\\napprox`,
129
+ * `\\parallelogram`), and MathJax understands those.
130
+ */
131
+ declare const MATHQUILL_ALIASES: {
132
+ '\\divide': string;
133
+ '\\perpendicular': string;
134
+ };
135
+ /**
136
+ * Rewrite what MathLive serialises into the form MathQuill stored: alias
137
+ * command names, and primes.
138
+ *
139
+ * @param {string} latex
140
+ * @returns {string}
141
+ */
142
+ export declare const toCanonicalCommands: (latex: any) => any;
143
+ /**
144
+ * Convert latex out of MathLive back into the stored form, so items authored
145
+ * with the MathLive editor remain readable by @pie-lib/math-rendering and by
146
+ * the existing MathQuill implementation.
147
+ *
148
+ * @param {string} latex
149
+ * @returns {string}
150
+ */
151
+ export declare const fromMathLive: (latex: any) => any;
152
+ /**
153
+ * MathQuill `cmd()` semantics: commands that take arguments should land the
154
+ * cursor inside the first argument. MathLive expresses that with `#?`
155
+ * placeholders in the inserted latex.
156
+ */
157
+ declare const COMMANDS_WITH_ARGS: {
158
+ '\\frac': string;
159
+ '/': string;
160
+ '\\sqrt': string;
161
+ '\\nthroot': string;
162
+ '\\overline': string;
163
+ '\\overrightarrow': string;
164
+ '\\overleftrightarrow': string;
165
+ '\\overarc': string;
166
+ '\\longdiv': string;
167
+ '^': string;
168
+ _: string;
169
+ '(': string;
170
+ '[': string;
171
+ '|': string;
172
+ };
173
+ /**
174
+ * MathQuill keystroke names -> MathLive command selectors.
175
+ */
176
+ declare const KEYSTROKES: {
177
+ Left: string;
178
+ Right: string;
179
+ Backspace: string;
180
+ Delete: string;
181
+ Up: string;
182
+ Down: string;
183
+ };
184
+ /**
185
+ * Translate a keypad key definition into a MathLive action.
186
+ *
187
+ * Mirrors the precedence in @pie-lib/math-input's MathInput.keypadPress:
188
+ * latex (unless a command is present) -> write -> command -> keystroke.
189
+ *
190
+ * @param {object} key
191
+ * @returns {{type: 'insert'|'command', value: string}|undefined}
192
+ */
193
+ export declare const keyToAction: (key: any) => {
194
+ type: string;
195
+ value: any;
196
+ } | undefined;
197
+ export { COMMANDS_WITH_ARGS, KEYSTROKES, MATHQUILL_ALIASES };
@@ -0,0 +1,210 @@
1
+ //#region src/latex-bridge.ts
2
+ var e = "\\embed{newLine}[]", t = /^\\displaylines\{([\s\S]*)\}$/, n = "\\MathQuillMathField", r = (e, t) => {
3
+ let n = 0;
4
+ for (let r = t; r < e.length; r++) {
5
+ let t = e[r];
6
+ if (t === "\\") r += 1;
7
+ else if (t === "{") n += 1;
8
+ else if (t === "}" && (--n, n === 0)) return r;
9
+ }
10
+ return -1;
11
+ }, i = (e, t, n) => {
12
+ let i = RegExp(`${t.replace(/\\/g, "\\\\")}\\[([^\\]]*)\\]\\{`, "g"), a = "", o = 0, s;
13
+ for (; (s = i.exec(e)) !== null;) {
14
+ let t = s.index + s[0].length - 1, c = r(e, t);
15
+ if (c === -1) break;
16
+ a += e.slice(o, s.index) + n(s[1], e.slice(t + 1, c)), o = c + 1, i.lastIndex = o;
17
+ }
18
+ return a + e.slice(o);
19
+ }, a = (e, t) => {
20
+ let n = [], r = 0, i = 0, a = 0;
21
+ for (; a < e.length;) {
22
+ if (r === 0 && e.startsWith(t, a)) {
23
+ n.push(e.slice(i, a)), a += t.length, i = a;
24
+ continue;
25
+ }
26
+ let o = e[a];
27
+ if (o === "\\") {
28
+ let t = e.slice(a).match(/^\\(?:[a-zA-Z]+|.)/), n = t ? t[0] : o;
29
+ n === "\\begin" ? r += 1 : n === "\\end" && --r, a += n.length;
30
+ } else o === "{" ? r += 1 : o === "}" && --r, a += 1;
31
+ }
32
+ return n.push(e.slice(i)), n;
33
+ }, o = (t) => {
34
+ if (t.indexOf("\\embed{newLine}[]") === -1) return t;
35
+ let n = "", i = 0;
36
+ for (; i < t.length;) {
37
+ let s = t[i];
38
+ if (s === "\\") n += t.slice(i, i + 2), i += 2;
39
+ else {
40
+ if (s === "{") {
41
+ let s = r(t, i);
42
+ if (s !== -1) {
43
+ let r = a(o(t.slice(i + 1, s)), e);
44
+ n += `{${r.length > 1 ? `\\begin{array}{l}${r.join(" \\\\ ")}\\end{array}` : r[0]}}`, i = s + 1;
45
+ continue;
46
+ }
47
+ }
48
+ n += s, i += 1;
49
+ }
50
+ }
51
+ return n;
52
+ }, s = (e) => {
53
+ if (e.indexOf("$") === -1) return e;
54
+ let t = "";
55
+ for (let n = 0; n < e.length; n++) e[n] === "\\" ? (t += e.slice(n, n + 2), n += 1) : t += e[n] === "$" ? "\\$" : e[n];
56
+ return t;
57
+ }, c = /\\placeholder\{([^{}]*)\}/g, l = /\\placeholder(?![[{a-zA-Z])/g, u = /\\embed\{answerBlock\}\[([^\]]*)\]/g, d = /\\answerBlock\{([^{}]*)\}/g, f = (t, n) => {
58
+ let r = n ? a(n, e) : [];
59
+ return `\\htmlData{answer-block=${t}}{\\boxed{\\htmlData{answer-block-index=${t}}{\\textsf{R}}\\enspace ${r.length > 1 ? `\\begin{array}{l}${r.join(" \\\\ ")}\\end{array}` : n || "\\phantom{0}"}}}`;
60
+ }, p = "\\htmlData{pie-empty=1}{\\rule{0.55em}{0.55em}}", m = /\{\s*\}/g, h = /_\{\s*\}/g, g = /\^\{\s*\}/g, _ = "\\htmlData{pie-empty=1}{\\rule[-0.4em]{0.55em}{0.95em}}", v = "\\rule[-0.5em]{0em}{0.5em}", y = "\\htmlData{pie-empty=1}{\\rule[-0.1em]{0.55em}{0.95em}}", b = /\\overline\{\s*\}/g, x = "\\rule{0em}{0.87em}", S = "\\rule{0em}{1.3em}", C = /\\left([([|])\s*\\right([)\]|])/g, w = "\\rule{0em}{1em}\\htmlData{pie-empty=1}{\\rule[-0.25em]{0.55em}{1em}}", T = (e) => (e || "").replace(b, `${S}\\overline{${x}${p}}`).replace(h, `_{${_}}${v}`).replace(g, `^{${y}}`).replace(m, `{${p}}`).replace(C, (e, t, n) => `\\left${t}${w}\\right${n}`), E = (e) => {
61
+ if (typeof e != "string" || !e) return e || "";
62
+ let t = e;
63
+ return t = O(t), t = t.replace(/\\longdiv\{/g, "\\enclose{longdiv}{"), t = t.replace(/\\overarc\{/g, "\\overparen{"), t = D(t), t;
64
+ }, D = (e) => {
65
+ if (e.indexOf("%") === -1) return e;
66
+ let t = "", n = 0;
67
+ for (let r = 0; r < e.length; r++) {
68
+ let i = e[r];
69
+ t += i === "%" && n % 2 == 0 ? "\\%" : i, n = i === "\\" ? n + 1 : 0;
70
+ }
71
+ return t;
72
+ }, O = (e) => {
73
+ let t = e, n = t.indexOf("\\abs{");
74
+ for (; n !== -1;) {
75
+ let e = n + 5 - 1, r = 0, i = -1;
76
+ for (let n = e; n < t.length; n++) if (t[n] === "{") r++;
77
+ else if (t[n] === "}" && (r--, r === 0)) {
78
+ i = n;
79
+ break;
80
+ }
81
+ if (i === -1) break;
82
+ let a = t.slice(e + 1, i);
83
+ t = `${t.slice(0, n)}\\left|${a}\\right|${t.slice(i + 1)}`, n = t.indexOf("\\abs{");
84
+ }
85
+ return t;
86
+ }, k = (e) => {
87
+ if (typeof e != "string") return [];
88
+ let t = [];
89
+ return i(e, n, (e) => (t.push(e || "r1"), "")), t;
90
+ }, A = (e) => {
91
+ let t = {};
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, r) => {
94
+ let i = e || "r1";
95
+ return `${n}[${i}]{${t[i] === void 0 ? r : t[i]}}`;
96
+ }), N = (e) => {
97
+ if (typeof e != "string" || !e) return e || "";
98
+ let t = (e, t, n) => {
99
+ let i = e, a = i.indexOf(t);
100
+ for (; a !== -1;) {
101
+ let e = a + t.length, o = i[e] === "{" ? r(i, e) : -1;
102
+ if (o === -1) {
103
+ a = i.indexOf(t, a + t.length);
104
+ continue;
105
+ }
106
+ let s = n(i, e, o);
107
+ i = i.slice(0, a) + s.text + i.slice(s.end), a = i.indexOf(t, a);
108
+ }
109
+ return i;
110
+ }, n = e.replace(d, "\\square");
111
+ return n = t(n, "\\htmlData", (e, t, n) => {
112
+ let i = e.slice(t + 1, n), a = n + 1, o = e[a] === "{" ? r(e, a) : -1;
113
+ if (o === -1) return {
114
+ text: "",
115
+ end: n + 1
116
+ };
117
+ if (/^answer-block-index=/.test(i)) {
118
+ let t = e.slice(o + 1).match(/^\s*\\enspace\s*/);
119
+ return {
120
+ text: "",
121
+ end: o + 1 + (t ? t[0].length : 0)
122
+ };
123
+ }
124
+ return {
125
+ text: `{${e.slice(a + 1, o)}}`,
126
+ end: o + 1
127
+ };
128
+ }), t(n, "\\boxed", (e, t, n) => ({
129
+ text: `{${e.slice(t + 1, n)}}`,
130
+ end: n + 1
131
+ }));
132
+ }, P = (t) => {
133
+ if (typeof t != "string" || !t) return t || "";
134
+ let r = E(t);
135
+ if (r = i(r, n, (e, t) => `\\placeholder[${e || "r1"}]{${t}}`), r = r.replace(u, (e, t) => `\\answerBlock{${t}}`), r = s(r), r = o(r), r.indexOf("\\embed{newLine}[]") !== -1) {
136
+ let t = a(r, e);
137
+ t.length > 1 && (r = `\\displaylines{${t.join(" \\\\ ")}}`);
138
+ }
139
+ return r;
140
+ }, F = {
141
+ "\\divide": "\\div",
142
+ "\\perpendicular": "\\perp"
143
+ }, I = /\\(divide|perpendicular)(?![a-zA-Z])/g, L = /\^\{((?:\s*\\(?:prime|doubleprime)(?![a-zA-Z]))+)\s*\}/g, R = /\\doubleprime(?![a-zA-Z])/g, z = (e) => "'".repeat((e.match(/\\prime(?![a-zA-Z])/g) || []).length + 2 * (e.match(R) || []).length), B = /^\\(doubleprime|prime)(?![a-zA-Z])/, V = (e) => {
144
+ if (e.indexOf("prime") === -1) return e;
145
+ let t = [], n = "", r = 0;
146
+ for (; r < e.length;) {
147
+ let i = e[r];
148
+ if (i === "\\") {
149
+ let a = e.slice(r).match(B);
150
+ if (a) {
151
+ let e = a[1] === "doubleprime";
152
+ /[\^_]\s*$/.test(n) || t.indexOf(!0) !== -1 ? n += e ? "\\prime\\prime" : "\\prime" : n += e ? "''" : "'", r += a[0].length;
153
+ continue;
154
+ }
155
+ let o = e.slice(r).match(/^\\(?:[a-zA-Z]+|.)/), s = o ? o[0] : i;
156
+ n += s, r += s.length;
157
+ } else i === "{" ? t.push(/[\^_]\s*$/.test(n)) : i === "}" && t.pop(), n += i, r += 1;
158
+ }
159
+ return n;
160
+ }, H = (e) => typeof e == "string" ? V(e.replace(I, (e) => F[e]).replace(L, (e, t) => z(t))) : e, U = (n) => {
161
+ if (typeof n != "string" || !n) return n || "";
162
+ 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
+ }, W = {
165
+ "\\frac": "\\frac{#?}{#?}",
166
+ "/": "\\frac{#@}{#?}",
167
+ "\\sqrt": "\\sqrt{#?}",
168
+ "\\nthroot": "\\sqrt[#?]{#?}",
169
+ "\\overline": "\\overline{#?}",
170
+ "\\overrightarrow": "\\overrightarrow{#?}",
171
+ "\\overleftrightarrow": "\\overleftrightarrow{#?}",
172
+ "\\overarc": "\\overparen{#?}",
173
+ "\\longdiv": "\\enclose{longdiv}{#?}",
174
+ "^": "^{#?}",
175
+ _: "_{#?}",
176
+ "(": "\\left(#?\\right)",
177
+ "[": "\\left[#?\\right]",
178
+ "|": "\\left|#?\\right|"
179
+ }, G = {
180
+ Left: "moveToPreviousChar",
181
+ Right: "moveToNextChar",
182
+ Backspace: "deleteBackward",
183
+ Delete: "deleteForward",
184
+ Up: "moveUp",
185
+ Down: "moveDown"
186
+ }, K = (e) => {
187
+ if (e) {
188
+ if (e.latex && !e.command) return {
189
+ type: "insert",
190
+ value: e.latex
191
+ };
192
+ if (e.write) return {
193
+ type: "insert",
194
+ value: e.write
195
+ };
196
+ if (e.command) return {
197
+ type: "insert",
198
+ value: (Array.isArray(e.command) ? e.command : [e.command]).map((e) => W[e] || F[e] || e).join("")
199
+ };
200
+ if (e.keystroke) {
201
+ let t = G[e.keystroke];
202
+ return t ? {
203
+ type: "command",
204
+ value: t
205
+ } : void 0;
206
+ }
207
+ }
208
+ };
209
+ //#endregion
210
+ export { W as COMMANDS_WITH_ARGS, G as KEYSTROKES, F as MATHQUILL_ALIASES, e as NEWLINE_EMBED, f as answerBlockLatex, k as fieldIds, j as fieldTemplate, A as fieldValues, M as fillFields, U as fromMathLive, K as keyToAction, N as toAccessibleLatex, H as toCanonicalCommands, P as toMathLive, E as toNativeCommands, T as withVisibleEmptySlots };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Correct every long division under `root`.
3
+ *
4
+ * @param {ParentNode} root a mathfield's shadow root, or an element holding
5
+ * static MathLive markup
6
+ * @returns {number} how many were corrected
7
+ */
8
+ export declare const fixLongDivision: (root: any) => number;
9
+ /**
10
+ * Correct static markup now, and again once web fonts have loaded: the bar's
11
+ * end is measured, and glyph widths change when the math fonts arrive.
12
+ *
13
+ * @param {Element} element
14
+ */
15
+ export declare const fixLongDivisionWhenReady: (element: any) => void;
16
+ /**
17
+ * Keep a live mathfield's long divisions corrected. MathLive rebuilds its shadow
18
+ * DOM on every render (each keystroke, a resize, the fonts loading), which
19
+ * discards the corrections, so they are reapplied whenever it does.
20
+ *
21
+ * @param {HTMLElement} mathField a MathLive `<math-field>`
22
+ * @returns {function|undefined} teardown, to call on unmount
23
+ */
24
+ export declare const trackLongDivision: (mathField: any) => (() => void) | undefined;
@@ -0,0 +1,43 @@
1
+ import e from "debug";
2
+ //#region src/longdiv.ts
3
+ var t = e("pie-lib:math-input-mathlive:longdiv"), n = (e, t) => {
4
+ let n = RegExp(`(?:^|;)\\s*${t}:\\s*(-?[\\d.]+)em`).exec(e || "");
5
+ return n ? parseFloat(n[1]) : 0;
6
+ }, r = (e, t) => e && Array.from(e.children || []).find((e) => e.tagName.toLowerCase() === t), i = (e) => {
7
+ let t = -Infinity;
8
+ return e.querySelectorAll("*").forEach((e) => {
9
+ if (e.children.length || e.classList && e.classList.contains("ML__caret")) return;
10
+ let n = e.getBoundingClientRect();
11
+ n.width > 0 && (t = Math.max(t, n.right));
12
+ }), t;
13
+ }, a = (e) => {
14
+ if (!e || typeof e.querySelectorAll != "function") return 0;
15
+ let a = 0;
16
+ return e.querySelectorAll(".ML__notation").forEach((e) => {
17
+ try {
18
+ let t = r(e, "svg"), o = r(t, "line");
19
+ if (!o || !r(t, "path")) return;
20
+ let s = e.nextElementSibling, c = s && s.getAttribute("style"), l = n(c, "width"), u = n(c, "margin-left"), d = n(c, "top"), f = (t.getAttribute("viewBox") || "").trim().split(/\s+/).map(Number), p = parseFloat(o.getAttribute("x1"));
21
+ if (!l || f.length !== 4 || Number.isNaN(p)) return;
22
+ e.style.width = `calc(${f[2]}em + 1px)`, d && e.parentElement && (s.style.top = "0", e.parentElement.style.paddingTop = `${d}em`);
23
+ let m = p + u + l, h = t.getBoundingClientRect(), g = i(s);
24
+ h.width > 0 && Number.isFinite(g) && (m = (g - h.left) * (f[2] / h.width)), o.setAttribute("x2", String(m)), a += 1;
25
+ } catch (e) {
26
+ t("could not correct a long division: %s", e && e.message);
27
+ }
28
+ }), a;
29
+ }, o = (e) => {
30
+ a(e), typeof document < "u" && document.fonts && document.fonts.ready && document.fonts.ready.then(() => a(e)).catch(() => {});
31
+ }, s = (e) => {
32
+ let t = e && e.shadowRoot;
33
+ if (!t) return;
34
+ let n = () => a(t);
35
+ if (n(), typeof MutationObserver > "u") return () => {};
36
+ let r = new MutationObserver(n);
37
+ return r.observe(t, {
38
+ childList: !0,
39
+ subtree: !0
40
+ }), () => r.disconnect();
41
+ };
42
+ //#endregion
43
+ export { a as fixLongDivision, o as fixLongDivisionWhenReady, s as trackLongDivision };
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ /**
4
+ * MathLive-backed equivalent of @pie-lib/math-input's `MathInput`.
5
+ * Same props (`keyset`, `latex`, `onChange`, `displayMode`).
6
+ */
7
+ export declare class MathInput extends React.Component {
8
+ static propTypes: {
9
+ className: PropTypes.Requireable<string>;
10
+ keyset: PropTypes.Requireable<any[]>;
11
+ displayMode: PropTypes.Requireable<string>;
12
+ latex: PropTypes.Requireable<string>;
13
+ onChange: PropTypes.Requireable<(...args: any[]) => any>;
14
+ };
15
+ static defaultProps: {
16
+ keyset: never[];
17
+ displayMode: string;
18
+ };
19
+ constructor(props: any);
20
+ keypadPress: (key: any) => void;
21
+ inputFocus: () => void;
22
+ inputBlur: () => void;
23
+ changeLatex: (l: any) => void;
24
+ render(): React.JSX.Element;
25
+ }
26
+ export default MathInput;