@pie-lib/math-input-mathlive 1.1.5-beta.8 → 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 (202) 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__/input-selection.test.js +0 -103
  81. package/lib/__tests__/keypad-label.test.js +0 -231
  82. package/lib/__tests__/keypad-render.test.js +0 -206
  83. package/lib/__tests__/latex-bridge.test.js +0 -386
  84. package/lib/__tests__/mathlive-instance.test.js +0 -419
  85. package/lib/__tests__/mount-race.test.js +0 -218
  86. package/lib/__tests__/selection.test.js +0 -195
  87. package/lib/__tests__/static-prompts.test.js +0 -405
  88. package/lib/__tests__/tmp-markup.test.js +0 -26
  89. package/lib/horizontal-keypad.js +0 -101
  90. package/lib/horizontal-keypad.js.map +0 -1
  91. package/lib/index.js +0 -143
  92. package/lib/index.js.map +0 -1
  93. package/lib/keypad/index.js +0 -431
  94. package/lib/keypad/index.js.map +0 -1
  95. package/lib/keypad/keys-layout.js +0 -22
  96. package/lib/keypad/keys-layout.js.map +0 -1
  97. package/lib/keys/basic-operators.js +0 -33
  98. package/lib/keys/basic-operators.js.map +0 -1
  99. package/lib/keys/chars.js +0 -12
  100. package/lib/keys/chars.js.map +0 -1
  101. package/lib/keys/comparison.js +0 -39
  102. package/lib/keys/comparison.js.map +0 -1
  103. package/lib/keys/constants.js +0 -37
  104. package/lib/keys/constants.js.map +0 -1
  105. package/lib/keys/digits.js +0 -46
  106. package/lib/keys/digits.js.map +0 -1
  107. package/lib/keys/edit.js +0 -14
  108. package/lib/keys/edit.js.map +0 -1
  109. package/lib/keys/exponent.js +0 -30
  110. package/lib/keys/exponent.js.map +0 -1
  111. package/lib/keys/fractions.js +0 -29
  112. package/lib/keys/fractions.js.map +0 -1
  113. package/lib/keys/geometry.js +0 -143
  114. package/lib/keys/geometry.js.map +0 -1
  115. package/lib/keys/grades.js +0 -259
  116. package/lib/keys/grades.js.map +0 -1
  117. package/lib/keys/index.js +0 -35
  118. package/lib/keys/index.js.map +0 -1
  119. package/lib/keys/log.js +0 -27
  120. package/lib/keys/log.js.map +0 -1
  121. package/lib/keys/logic.js +0 -19
  122. package/lib/keys/logic.js.map +0 -1
  123. package/lib/keys/matrices.js +0 -19
  124. package/lib/keys/matrices.js.map +0 -1
  125. package/lib/keys/misc.js +0 -69
  126. package/lib/keys/misc.js.map +0 -1
  127. package/lib/keys/navigation.js +0 -20
  128. package/lib/keys/navigation.js.map +0 -1
  129. package/lib/keys/operators.js +0 -15
  130. package/lib/keys/operators.js.map +0 -1
  131. package/lib/keys/statistics.js +0 -40
  132. package/lib/keys/statistics.js.map +0 -1
  133. package/lib/keys/sub-sup.js +0 -19
  134. package/lib/keys/sub-sup.js.map +0 -1
  135. package/lib/keys/trigonometry.js +0 -45
  136. package/lib/keys/trigonometry.js.map +0 -1
  137. package/lib/keys/utils.js +0 -87
  138. package/lib/keys/utils.js.map +0 -1
  139. package/lib/keys/vars.js +0 -24
  140. package/lib/keys/vars.js.map +0 -1
  141. package/lib/latex-bridge.js +0 -445
  142. package/lib/latex-bridge.js.map +0 -1
  143. package/lib/math-input.js +0 -143
  144. package/lib/math-input.js.map +0 -1
  145. package/lib/mathlive-instance.js +0 -585
  146. package/lib/mathlive-instance.js.map +0 -1
  147. package/lib/mf/common-styles.js +0 -203
  148. package/lib/mf/common-styles.js.map +0 -1
  149. package/lib/mf/index.js +0 -84
  150. package/lib/mf/index.js.map +0 -1
  151. package/lib/mf/input.js +0 -372
  152. package/lib/mf/input.js.map +0 -1
  153. package/lib/mf/static.js +0 -500
  154. package/lib/mf/static.js.map +0 -1
  155. package/lib/selection.js +0 -148
  156. package/lib/selection.js.map +0 -1
  157. package/src/__tests__/composites.test.jsx +0 -220
  158. package/src/__tests__/drop-in-compat.test.jsx +0 -112
  159. package/src/__tests__/index.test.jsx +0 -109
  160. package/src/__tests__/input-imperative.test.jsx +0 -144
  161. package/src/__tests__/input-selection.test.jsx +0 -64
  162. package/src/__tests__/keypad-label.test.jsx +0 -283
  163. package/src/__tests__/keypad-render.test.jsx +0 -123
  164. package/src/__tests__/latex-bridge.test.js +0 -359
  165. package/src/__tests__/mathlive-instance.test.js +0 -418
  166. package/src/__tests__/mount-race.test.jsx +0 -142
  167. package/src/__tests__/selection.test.js +0 -212
  168. package/src/__tests__/static-prompts.test.jsx +0 -364
  169. package/src/horizontal-keypad.jsx +0 -73
  170. package/src/index.jsx +0 -63
  171. package/src/keypad/index.jsx +0 -386
  172. package/src/keypad/keys-layout.js +0 -16
  173. package/src/keys/basic-operators.js +0 -32
  174. package/src/keys/chars.js +0 -5
  175. package/src/keys/comparison.js +0 -28
  176. package/src/keys/constants.js +0 -35
  177. package/src/keys/digits.js +0 -40
  178. package/src/keys/edit.js +0 -3
  179. package/src/keys/exponent.js +0 -28
  180. package/src/keys/fractions.js +0 -26
  181. package/src/keys/geometry.js +0 -149
  182. package/src/keys/grades.js +0 -367
  183. package/src/keys/index.js +0 -20
  184. package/src/keys/log.js +0 -22
  185. package/src/keys/logic.js +0 -15
  186. package/src/keys/matrices.js +0 -15
  187. package/src/keys/misc.js +0 -71
  188. package/src/keys/navigation.js +0 -8
  189. package/src/keys/operators.js +0 -10
  190. package/src/keys/statistics.js +0 -38
  191. package/src/keys/sub-sup.js +0 -15
  192. package/src/keys/trigonometry.js +0 -15
  193. package/src/keys/utils.js +0 -66
  194. package/src/keys/vars.js +0 -19
  195. package/src/latex-bridge.js +0 -449
  196. package/src/math-input.jsx +0 -115
  197. package/src/mathlive-instance.js +0 -582
  198. package/src/mf/common-styles.js +0 -210
  199. package/src/mf/index.js +0 -30
  200. package/src/mf/input.jsx +0 -328
  201. package/src/mf/static.jsx +0 -479
  202. package/src/selection.js +0 -146
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.superscript = exports.subscript = void 0;
7
- var _utils = require("./utils");
8
- var set = (0, _utils.mkSet)('sub-sup');
9
- var superscript = exports.superscript = set({
10
- name: 'Superscript',
11
- latex: 'x^{}',
12
- command: '^'
13
- });
14
- var subscript = exports.subscript = set({
15
- name: 'Subscript',
16
- latex: 'x_{}',
17
- command: '_'
18
- });
19
- //# sourceMappingURL=sub-sup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sub-sup.js","names":["_utils","require","set","mkSet","superscript","exports","name","latex","command","subscript"],"sources":["../../src/keys/sub-sup.js"],"sourcesContent":["import { mkSet } from './utils';\n\nconst set = mkSet('sub-sup');\n\nexport const superscript = set({\n name: 'Superscript',\n latex: 'x^{}',\n command: '^',\n});\n\nexport const subscript = set({\n name: 'Subscript',\n latex: 'x_{}',\n command: '_',\n});\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAMC,GAAG,GAAG,IAAAC,YAAK,EAAC,SAAS,CAAC;AAErB,IAAMC,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAGF,GAAG,CAAC;EAC7BI,IAAI,EAAE,aAAa;EACnBC,KAAK,EAAE,MAAM;EACbC,OAAO,EAAE;AACX,CAAC,CAAC;AAEK,IAAMC,SAAS,GAAAJ,OAAA,CAAAI,SAAA,GAAGP,GAAG,CAAC;EAC3BI,IAAI,EAAE,WAAW;EACjBC,KAAK,EAAE,MAAM;EACbC,OAAO,EAAE;AACX,CAAC,CAAC","ignoreList":[]}
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.tan = exports.sin = exports.sec = exports.csc = exports.cot = exports.cos = void 0;
7
- var _utils = require("./utils");
8
- var set = (0, _utils.mkSet)('trigonometry');
9
- var sin = exports.sin = set({
10
- name: 'sine',
11
- label: 'sin',
12
- command: '\\sin',
13
- latex: '\\sin'
14
- });
15
- var cos = exports.cos = set({
16
- name: 'cosine',
17
- label: 'cos',
18
- command: '\\cos',
19
- latex: '\\cos'
20
- });
21
- var tan = exports.tan = set({
22
- name: 'tanget',
23
- label: 'tan',
24
- command: '\\tan',
25
- latex: '\\tan'
26
- });
27
- var sec = exports.sec = set({
28
- name: 'secant',
29
- label: 'sec',
30
- command: '\\sec',
31
- latex: '\\sec'
32
- });
33
- var csc = exports.csc = set({
34
- name: 'cosecant',
35
- label: 'csc',
36
- command: '\\csc',
37
- latex: '\\csc'
38
- });
39
- var cot = exports.cot = set({
40
- name: 'cotangent',
41
- label: 'cot',
42
- command: '\\cot',
43
- latex: '\\cot'
44
- });
45
- //# sourceMappingURL=trigonometry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trigonometry.js","names":["_utils","require","set","mkSet","sin","exports","name","label","command","latex","cos","tan","sec","csc","cot"],"sources":["../../src/keys/trigonometry.js"],"sourcesContent":["import { mkSet } from './utils';\n\nconst set = mkSet('trigonometry');\n\nexport const sin = set({ name: 'sine', label: 'sin', command: '\\\\sin', latex: '\\\\sin' });\n\nexport const cos = set({ name: 'cosine', label: 'cos', command: '\\\\cos', latex: '\\\\cos' });\n\nexport const tan = set({ name: 'tanget', label: 'tan', command: '\\\\tan', latex: '\\\\tan' });\n\nexport const sec = set({ name: 'secant', label: 'sec', command: '\\\\sec', latex: '\\\\sec' });\n\nexport const csc = set({ name: 'cosecant', label: 'csc', command: '\\\\csc', latex: '\\\\csc' });\n\nexport const cot = set({ name: 'cotangent', label: 'cot', command: '\\\\cot', latex: '\\\\cot' });\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAMC,GAAG,GAAG,IAAAC,YAAK,EAAC,cAAc,CAAC;AAE1B,IAAMC,GAAG,GAAAC,OAAA,CAAAD,GAAA,GAAGF,GAAG,CAAC;EAAEI,IAAI,EAAE,MAAM;EAAEC,KAAK,EAAE,KAAK;EAAEC,OAAO,EAAE,OAAO;EAAEC,KAAK,EAAE;AAAQ,CAAC,CAAC;AAEjF,IAAMC,GAAG,GAAAL,OAAA,CAAAK,GAAA,GAAGR,GAAG,CAAC;EAAEI,IAAI,EAAE,QAAQ;EAAEC,KAAK,EAAE,KAAK;EAAEC,OAAO,EAAE,OAAO;EAAEC,KAAK,EAAE;AAAQ,CAAC,CAAC;AAEnF,IAAME,GAAG,GAAAN,OAAA,CAAAM,GAAA,GAAGT,GAAG,CAAC;EAAEI,IAAI,EAAE,QAAQ;EAAEC,KAAK,EAAE,KAAK;EAAEC,OAAO,EAAE,OAAO;EAAEC,KAAK,EAAE;AAAQ,CAAC,CAAC;AAEnF,IAAMG,GAAG,GAAAP,OAAA,CAAAO,GAAA,GAAGV,GAAG,CAAC;EAAEI,IAAI,EAAE,QAAQ;EAAEC,KAAK,EAAE,KAAK;EAAEC,OAAO,EAAE,OAAO;EAAEC,KAAK,EAAE;AAAQ,CAAC,CAAC;AAEnF,IAAMI,GAAG,GAAAR,OAAA,CAAAQ,GAAA,GAAGX,GAAG,CAAC;EAAEI,IAAI,EAAE,UAAU;EAAEC,KAAK,EAAE,KAAK;EAAEC,OAAO,EAAE,OAAO;EAAEC,KAAK,EAAE;AAAQ,CAAC,CAAC;AAErF,IAAMK,GAAG,GAAAT,OAAA,CAAAS,GAAA,GAAGZ,GAAG,CAAC;EAAEI,IAAI,EAAE,WAAW;EAAEC,KAAK,EAAE,KAAK;EAAEC,OAAO,EAAE,OAAO;EAAEC,KAAK,EAAE;AAAQ,CAAC,CAAC","ignoreList":[]}
package/lib/keys/utils.js DELETED
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.transformToKeySetStructure = exports.toKey = exports.toArray = exports.mkSet = exports.extendKeySet = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _lodashEs = require("lodash-es");
11
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
- var mkSet = exports.mkSet = function mkSet(category) {
14
- return function (o) {
15
- return _objectSpread(_objectSpread({}, o), {}, {
16
- category: category
17
- });
18
- };
19
- };
20
- var toArray = exports.toArray = function toArray(o) {
21
- return Object.keys(o).map(function (k) {
22
- return o[k];
23
- });
24
- };
25
- var toKey = exports.toKey = function toKey(category) {
26
- return function (v) {
27
- if (typeof v === 'string') {
28
- return {
29
- name: v,
30
- label: v,
31
- category: category,
32
- write: v
33
- };
34
- } else {
35
- return _objectSpread(_objectSpread({}, v), {}, {
36
- category: category
37
- });
38
- }
39
- };
40
- };
41
- var transformToKeySetStructure = exports.transformToKeySetStructure = function transformToKeySetStructure() {
42
- var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
43
- var structure = [];
44
- (0, _lodashEs.times)(5, function () {
45
- return structure.push([]);
46
- });
47
- var ln = data.length;
48
- var i = 0;
49
- var j = 0;
50
- while (j < ln) {
51
- structure[i++].push(data[j++]);
52
- if (i === 5) {
53
- i = 0;
54
- }
55
- }
56
- return structure;
57
- };
58
- var latexAndNameDontExist = function latexAndNameDontExist(base) {
59
- return function (k) {
60
- var flattened = (0, _lodashEs.flatten)(base);
61
- var latexExists = flattened.some(function (b) {
62
- return b.latex === k.latex;
63
- });
64
- var nameExists = flattened.some(function (b) {
65
- return b.name === k.name;
66
- });
67
- return !latexExists && !nameExists;
68
- };
69
- };
70
- var extendKeySet = exports.extendKeySet = function extendKeySet() {
71
- var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
72
- var keySetData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
73
- keySetData = keySetData.filter(latexAndNameDontExist(base));
74
- var _final = [];
75
- (0, _lodashEs.times)(5 - base.length, function () {
76
- return base.push([]);
77
- });
78
- (0, _lodashEs.times)(5, function () {
79
- return _final.push([]);
80
- });
81
- var extra = transformToKeySetStructure(keySetData);
82
- for (var i = 0; i < 5; i++) {
83
- _final[i] = [].concat((0, _toConsumableArray2["default"])(base[i]), (0, _toConsumableArray2["default"])(extra[i]));
84
- }
85
- return _final;
86
- };
87
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","names":["_lodashEs","require","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","mkSet","exports","category","toArray","map","k","toKey","v","name","label","write","transformToKeySetStructure","data","undefined","structure","times","ln","i","j","latexAndNameDontExist","base","flattened","flatten","latexExists","some","b","latex","nameExists","extendKeySet","keySetData","final","extra","concat","_toConsumableArray2"],"sources":["../../src/keys/utils.js"],"sourcesContent":["import { flatten, times } from 'lodash-es';\n\nexport const mkSet = (category) => (o) => ({ ...o, category });\n\nexport const toArray = (o) => Object.keys(o).map((k) => o[k]);\n\nexport const toKey = (category) => (v) => {\n if (typeof v === 'string') {\n return {\n name: v,\n label: v,\n category,\n write: v,\n };\n } else {\n return {\n ...v,\n category,\n };\n }\n};\n\nexport const transformToKeySetStructure = (data = []) => {\n const structure = [];\n\n times(5, () => structure.push([]));\n\n let ln = data.length;\n let i = 0;\n let j = 0;\n\n while (j < ln) {\n structure[i++].push(data[j++]);\n\n if (i === 5) {\n i = 0;\n }\n }\n\n return structure;\n};\n\nconst latexAndNameDontExist = (base) => (k) => {\n const flattened = flatten(base);\n const latexExists = flattened.some((b) => b.latex === k.latex);\n const nameExists = flattened.some((b) => b.name === k.name);\n\n return !latexExists && !nameExists;\n};\n\nexport const extendKeySet = (base = [], keySetData = []) => {\n keySetData = keySetData.filter(latexAndNameDontExist(base));\n\n const final = [];\n\n times(5 - base.length, () => base.push([]));\n times(5, () => final.push([]));\n\n const extra = transformToKeySetStructure(keySetData);\n\n for (let i = 0; i < 5;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C,KAAK,GAAGpB,0BAA0B,CAACkB,UAAU,CAAC;EAEpD,KAAK,IAAIZ,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IAC1Ba,MAAK,CAACb,CAAC,CAAC,MAAAe,MAAA,KAAAC,mBAAA,aAAOb,IAAI,CAACH,CAAC,CAAC,OAAAgB,mBAAA,aAAKF,KAAK,CAACd,CAAC,CAAC,EAAC;EACtC;EAEA,OAAOa,MAAK;AACd,CAAC","ignoreList":[]}
package/lib/keys/vars.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.y = exports.x = exports.theta = void 0;
7
- var _utils = require("./utils");
8
- var set = (0, _utils.mkSet)('vars');
9
- var x = exports.x = set({
10
- name: 'X',
11
- latex: 'x',
12
- write: 'x'
13
- });
14
- var y = exports.y = set({
15
- name: 'Y',
16
- latex: 'y',
17
- write: 'y'
18
- });
19
- var theta = exports.theta = set({
20
- name: 'Theta',
21
- latex: '\\theta',
22
- write: '\\theta'
23
- });
24
- //# sourceMappingURL=vars.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vars.js","names":["_utils","require","set","mkSet","x","exports","name","latex","write","y","theta"],"sources":["../../src/keys/vars.js"],"sourcesContent":["import { mkSet } from './utils';\n\nconst set = mkSet('vars');\n\nexport const x = set({\n name: 'X',\n latex: 'x',\n write: 'x',\n});\nexport const y = set({\n name: 'Y',\n latex: 'y',\n write: 'y',\n});\nexport const theta = set({\n name: 'Theta',\n latex: '\\\\theta',\n write: '\\\\theta',\n});\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAMC,GAAG,GAAG,IAAAC,YAAK,EAAC,MAAM,CAAC;AAElB,IAAMC,CAAC,GAAAC,OAAA,CAAAD,CAAA,GAAGF,GAAG,CAAC;EACnBI,IAAI,EAAE,GAAG;EACTC,KAAK,EAAE,GAAG;EACVC,KAAK,EAAE;AACT,CAAC,CAAC;AACK,IAAMC,CAAC,GAAAJ,OAAA,CAAAI,CAAA,GAAGP,GAAG,CAAC;EACnBI,IAAI,EAAE,GAAG;EACTC,KAAK,EAAE,GAAG;EACVC,KAAK,EAAE;AACT,CAAC,CAAC;AACK,IAAME,KAAK,GAAAL,OAAA,CAAAK,KAAA,GAAGR,GAAG,CAAC;EACvBI,IAAI,EAAE,OAAO;EACbC,KAAK,EAAE,SAAS;EAChBC,KAAK,EAAE;AACT,CAAC,CAAC","ignoreList":[]}
@@ -1,445 +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
-
296
- /**
297
- * Rewrite what MathLive serialises into the form MathQuill stored: alias
298
- * command names, and primes.
299
- *
300
- * @param {string} latex
301
- * @returns {string}
302
- */
303
- var toCanonicalCommands = exports.toCanonicalCommands = function toCanonicalCommands(latex) {
304
- return typeof latex === 'string' ? latex.replace(MATHQUILL_ALIAS_REGEX, function (m) {
305
- return MATHQUILL_ALIASES[m];
306
- }).replace(PRIME_SUPERSCRIPT_REGEX, function (_m, primes) {
307
- return primesToApostrophes(primes);
308
- })
309
- // eslint-disable-next-line quotes
310
- .replace(BARE_DOUBLEPRIME_REGEX, "''") : latex;
311
- };
312
-
313
- /**
314
- * Convert latex out of MathLive back into the stored form, so items authored
315
- * with the MathLive editor remain readable by @pie-lib/math-rendering and by
316
- * the existing MathQuill implementation.
317
- *
318
- * @param {string} latex
319
- * @returns {string}
320
- */
321
- var fromMathLive = exports.fromMathLive = function fromMathLive(latex) {
322
- if (typeof latex !== 'string' || !latex) {
323
- return latex || '';
324
- }
325
- var match = latex.trim().match(DISPLAYLINES_REGEX);
326
- var out = match ? match[1] : latex;
327
-
328
- // `\\` is the line separator inside a multiline environment.
329
- if (out.indexOf('\\\\') !== -1) {
330
- out = out.split(/\s*\\\\\s*/).map(function (s) {
331
- return s.trim();
332
- }).join(NEWLINE_EMBED);
333
- }
334
-
335
- // Answer blocks: \placeholder[id]{x} -> \MathQuillMathField[id]{x}
336
- out = out.replace(PLACEHOLDER_REGEX, function (_m, id, content) {
337
- return "\\MathQuillMathField[".concat(id || DEFAULT_FIELD_ID, "]{").concat(content, "}");
338
- });
339
-
340
- // Unnamed placeholders are MathLive's own representation of an empty slot and
341
- // must not reach storage or MathJax. Unwrap them: keep any content, drop the
342
- // command itself (the surrounding braces are already part of the host latex,
343
- // so re-adding them here would produce `\longdiv{{}}`).
344
- out = out.replace(BARE_PLACEHOLDER_REGEX, function (_m, content) {
345
- return content;
346
- });
347
- out = out.replace(BARE_PLACEHOLDER_NO_ARG_REGEX, '');
348
-
349
- // Store the command MathQuill stored, not the alias - also heals latex that was
350
- // saved with `\\divide` before the keypad resolved it.
351
- return toCanonicalCommands(out);
352
- };
353
-
354
- /**
355
- * MathQuill `cmd()` semantics: commands that take arguments should land the
356
- * cursor inside the first argument. MathLive expresses that with `#?`
357
- * placeholders in the inserted latex.
358
- */
359
- var COMMANDS_WITH_ARGS = exports.COMMANDS_WITH_ARGS = {
360
- // An explicit "blank over blank" key: both slots start empty.
361
- '\\frac': '\\frac{#?}{#?}',
362
- // Division, which must behave like MathQuill's `/`: whatever precedes the
363
- // cursor becomes the numerator and the caret lands in the denominator. `#@`
364
- // is MathLive's token for "the selection, or the item before the cursor" -
365
- // this is exactly the template MathLive binds to the `/` key itself. Using
366
- // `#?` here instead produced an empty fraction and left the typed number
367
- // stranded outside it.
368
- '/': '\\frac{#@}{#?}',
369
- '\\sqrt': '\\sqrt{#?}',
370
- '\\nthroot': '\\sqrt[#?]{#?}',
371
- '\\overline': '\\overline{#?}',
372
- '\\overrightarrow': '\\overrightarrow{#?}',
373
- '\\overleftrightarrow': '\\overleftrightarrow{#?}',
374
- // Native forms, not the pie macros: a macro would not serialise the user's
375
- // typed content back out (see toNativeCommands).
376
- '\\overarc': '\\overparen{#?}',
377
- '\\longdiv': '\\enclose{longdiv}{#?}',
378
- '^': '^{#?}',
379
- _: '_{#?}',
380
- '(': '\\left(#?\\right)',
381
- '[': '\\left[#?\\right]',
382
- '|': '\\left|#?\\right|'
383
- };
384
-
385
- /**
386
- * MathQuill keystroke names -> MathLive command selectors.
387
- */
388
- var KEYSTROKES = exports.KEYSTROKES = {
389
- Left: 'moveToPreviousChar',
390
- Right: 'moveToNextChar',
391
- Backspace: 'deleteBackward',
392
- Delete: 'deleteForward',
393
- Up: 'moveUp',
394
- Down: 'moveDown'
395
- };
396
-
397
- /**
398
- * Translate a keypad key definition into a MathLive action.
399
- *
400
- * Mirrors the precedence in @pie-lib/math-input's MathInput.keypadPress:
401
- * latex (unless a command is present) -> write -> command -> keystroke.
402
- *
403
- * @param {object} key
404
- * @returns {{type: 'insert'|'command', value: string}|undefined}
405
- */
406
- var keyToAction = exports.keyToAction = function keyToAction(key) {
407
- if (!key) {
408
- return undefined;
409
- }
410
- if (key.latex && !key.command) {
411
- return {
412
- type: 'insert',
413
- value: key.latex
414
- };
415
- }
416
- if (key.write) {
417
- return {
418
- type: 'insert',
419
- value: key.write
420
- };
421
- }
422
- if (key.command) {
423
- // Some keys carry an array of commands (e.g. Measured Angle is
424
- // ['m', '\\angle'], log-base-n is ['\\log', '_']). MathQuill's `cmd()`
425
- // applied them in sequence; MathLive inserts one latex string, so expand
426
- // each part and concatenate.
427
- var parts = Array.isArray(key.command) ? key.command : [key.command];
428
- var value = parts.map(function (c) {
429
- return COMMANDS_WITH_ARGS[c] || MATHQUILL_ALIASES[c] || c;
430
- }).join('');
431
- return {
432
- type: 'insert',
433
- value: value
434
- };
435
- }
436
- if (key.keystroke) {
437
- var selector = KEYSTROKES[key.keystroke];
438
- return selector ? {
439
- type: 'command',
440
- value: selector
441
- } : undefined;
442
- }
443
- return undefined;
444
- };
445
- //# sourceMappingURL=latex-bridge.js.map