@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,585 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.MATH_MODE_SPACE = void 0;
9
- Object.defineProperty(exports, "NEWLINE_EMBED", {
10
- enumerable: true,
11
- get: function get() {
12
- return _latexBridge.NEWLINE_EMBED;
13
- }
14
- });
15
- exports.applyShadowStyles = exports.__setMathLiveForTest = exports.__resetEmbeds = exports.PLACEHOLDER_CARET_CLASS = exports.PIE_MACROS = void 0;
16
- exports.applyStaticMath = applyStaticMath;
17
- exports.getMathLive = exports.getMacros = exports.configureFonts = void 0;
18
- exports.latexToMarkup = latexToMarkup;
19
- exports.loadMathLiveSync = exports.loadMathLive = void 0;
20
- exports.registerEmbed = registerEmbed;
21
- exports.trackPlaceholderCaret = exports.registeredEmbeds = void 0;
22
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
23
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
24
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
25
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
26
- var _debug = _interopRequireDefault(require("debug"));
27
- var _latexBridge = require("./latex-bridge");
28
- var _commonStyles = require("./mf/common-styles");
29
- 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; }
30
- 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; }
31
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
32
- var log = (0, _debug["default"])('pie-lib:math-input-mathlive:instance');
33
-
34
- /**
35
- * MathLive bootstrap + compatibility shims for @pie-lib/math-input's public API.
36
- *
37
- * MathLive is loaded lazily and only in the browser: the editor bundle is
38
- * ~227KB gzip and registers custom elements, so it must never run during SSR.
39
- */
40
-
41
- var mathlive;
42
-
43
- /**
44
- * Where the KaTeX woff2 fonts are served from, as configured by the host app.
45
- * `undefined` means "not configured"; `null` means "explicitly disabled".
46
- */
47
- var fontsDirectory;
48
-
49
- /**
50
- * Turn a fonts path into a fully-qualified URL.
51
- *
52
- * MathLive's default `fontsDirectory` is the relative `'./fonts/'`, which it
53
- * resolves against its own script URL. Under a bundler (webpack/Next) that
54
- * script URL is empty, so `new URL('./fonts/', '')` throws
55
- * "Failed to construct 'URL': Invalid base URL" from `loadFonts`.
56
- * Resolving against `document.baseURI` avoids that entirely and honours any
57
- * <base href> / asset prefix the host app uses.
58
- */
59
- var absoluteFontsDirectory = function absoluteFontsDirectory(dir) {
60
- if (!dir) {
61
- return dir;
62
- }
63
-
64
- // Already absolute (http://, https://, //cdn...) - MathLive handles these.
65
- if (/^(?:[a-z+]+:)?\/\//i.test(dir)) {
66
- return dir;
67
- }
68
- try {
69
- return new URL(dir, document.baseURI).href;
70
- } catch (e) {
71
- log('could not resolve fontsDirectory "%s": %s', dir, e && e.message);
72
- return null;
73
- }
74
- };
75
-
76
- /**
77
- * Version-pinned CDN fallback for the KaTeX fonts.
78
- *
79
- * Some symbols are composed from Private Use Area glyphs that exist only in
80
- * those fonts: `\\neq` is U+E020 (a negation slash) overlapped on `=`, and
81
- * `\\nsim` / `\\ncong` work the same way. With no fonts the browser substitutes
82
- * an arbitrary glyph for U+E020, so those keys render as garbage rather than
83
- * simply falling back to a plainer face.
84
- *
85
- * The version comes from MathLive itself, so the fonts always match the engine.
86
- * Hosts that would rather not depend on a third party should serve the fonts and
87
- * call `configureFonts('/their/path')`, or pass `null` to opt out.
88
- */
89
- var FALLBACK_MATHLIVE_VERSION = '0.110.0';
90
- var cdnFontsDirectory = function cdnFontsDirectory() {
91
- var version = mathlive && mathlive.version && mathlive.version.mathlive || FALLBACK_MATHLIVE_VERSION;
92
-
93
- // NOTE: `/fonts`, not `/dist/fonts` - the published package root holds them.
94
- return "https://unpkg.com/mathlive@".concat(version, "/fonts");
95
- };
96
-
97
- /**
98
- * Tell the package where the MathLive fonts are served from.
99
- *
100
- * Call before `loadMathLive()`.
101
- *
102
- * - a path/URL: served by you, no third-party request
103
- * - `null`: skip font loading; note `\\neq`, `\\nsim` and `\\ncong` then
104
- * render incorrectly, being built from Private Use Area glyphs
105
- * - not called: falls back to a version-pinned CDN
106
- *
107
- * The fonts ship inside the `mathlive` package (`node_modules/mathlive/fonts`)
108
- * ready to copy into whatever the host app serves statically.
109
- *
110
- * @param {string|null} [dir]
111
- */
112
- var configureFonts = exports.configureFonts = function configureFonts(dir) {
113
- fontsDirectory = dir;
114
- if (mathlive) {
115
- mathlive.MathfieldElement.fontsDirectory = dir === undefined ? cdnFontsDirectory() : absoluteFontsDirectory(dir);
116
- }
117
- };
118
-
119
- /**
120
- * What the spacebar inserts in math mode.
121
- *
122
- * MathLive's `mathModeSpace` defaults to an empty string, which makes the
123
- * spacebar a no-op - users cannot type a space at all. `\\ ` (a LaTeX control
124
- * space) is what MathQuill serialised spaces as, so existing content and the
125
- * MathJax renderer in @pie-lib/math-rendering both already understand it.
126
- *
127
- * A literal " " is not usable: LaTeX skips raw whitespace.
128
- */
129
- var MATH_MODE_SPACE = exports.MATH_MODE_SPACE = '\\ ';
130
-
131
- /**
132
- * Custom macros for the pie-specific commands that the MathQuill fork
133
- * understood but stock LaTeX does not.
134
- *
135
- * Kept deliberately in sync with the MathJax macros in
136
- * @pie-lib/math-rendering (`render-math.js`) so the same latex renders the same
137
- * way in the editor and in the static renderer.
138
- */
139
- var PIE_MACROS = exports.PIE_MACROS = {
140
- // Argument-less symbols. Atomic is correct here: backspace should remove the
141
- // whole glyph, and there is nothing to type into.
142
- parallelogram: "\\htmlData{pie-macro=parallelogram}{\\unicode{\"25B1}}",
143
- // Same glyph as the built-in `\\parallel` (U+2225), tagged so it can be sized -
144
- // see `parallelStyles`.
145
- parallel: "\\htmlData{pie-macro=parallel}{\\unicode{\"2225}}",
146
- napprox: '\\not\\approx',
147
- nsim: '\\not\\sim',
148
- ncong: '\\not\\cong',
149
- nparallel: '\\not\\parallel',
150
- perpendicular: '\\perp',
151
- divide: '\\div',
152
- degree: '^{\\circ}',
153
- square: "\\unicode{\"25A1}",
154
- // Argument-taking commands, kept ONLY so previously authored latex still
155
- // parses and renders. They are never used for editing: MathLive serialises a
156
- // macro from the arguments it was created with, so text typed inside the
157
- // expansion never comes back out of `getValue('latex')`. Anything entering a
158
- // mathfield is rewritten to the native equivalent first - see
159
- // `toNativeCommands` in latex-bridge.
160
- longdiv: '\\enclose{longdiv}{#1}',
161
- overarc: '\\overparen{#1}',
162
- abs: '\\left|#1\\right|'
163
- };
164
-
165
- /**
166
- * Registry for `registerEmbed`.
167
- *
168
- * MathLive has no embed plugin system, so an embed is expressed as a macro that
169
- * expands to real LaTeX. `\htmlData{embed=<name>}` tags the rendered output so
170
- * consumers can target it with CSS exactly as they targeted the old
171
- * `htmlString` markup.
172
- *
173
- * Known embeds map to native constructs:
174
- * - `newLine` -> structural, handled by latex-bridge (`\displaylines` + `\\`)
175
- * - `answerBlock`-> `\placeholder{}` (interactive, read via the prompts API)
176
- *
177
- * @type {Map<string, {factory: Function, latex: string}>}
178
- */
179
- var embeds = new Map();
180
- var KNOWN_EMBED_LATEX = {
181
- // newLine is structural: it is translated by latex-bridge before it ever
182
- // reaches MathLive, so the macro only needs to be harmless.
183
- newLine: '',
184
- answerBlock: '\\placeholder{}'
185
- };
186
- var loadWarned = false;
187
-
188
- /** Apply post-load configuration exactly once. */
189
- var configureLoaded = function configureLoaded() {
190
- // Always replace MathLive's relative `'./fonts/'` default: it throws
191
- // "Invalid base URL" when bundled. Use the host's copy if one was configured,
192
- // otherwise the version-pinned CDN.
193
- if (fontsDirectory === undefined) {
194
- log('no fontsDirectory configured - falling back to the CDN (%s). ' + 'Serve the fonts yourself and call configureFonts("/path/to/fonts") to avoid the network request, ' + 'or configureFonts(null) to opt out.', cdnFontsDirectory());
195
- }
196
- mathlive.MathfieldElement.fontsDirectory = fontsDirectory === undefined ? cdnFontsDirectory() : absoluteFontsDirectory(fontsDirectory);
197
- injectCoreStylesheet();
198
- };
199
-
200
- /**
201
- * CSS that has to live *inside* a mathfield's shadow root.
202
- *
203
- * A live `<math-field>` renders in shadow DOM (`attachShadow({mode:'open'})`),
204
- * so nothing in the host page's stylesheets reaches it. The stretchy-accent
205
- * problem therefore needs fixing twice: once for static markup (see
206
- * `placeholderStyles`) and once here for the editor.
207
- *
208
- * MathLive centres an accent with `margin-left: <half the content width>` as an
209
- * inline style. For a stretchy accent that also shrinks its containing block
210
- * (`.ML__center` is position:relative), so the arc ends up half-width and offset
211
- * - visibly failing to span the text underneath.
212
- *
213
- * `:has(.ML__stretchy)` keeps the fix to stretchy accents; single-glyph accents
214
- * (`\hat{x}`, `\vec{x}`) still need their centring offset.
215
- */
216
- /**
217
- * Marker put on the host `<math-field>` while a `\placeholder{}` is selected,
218
- * so the caret rules below apply to a placeholder and nothing else.
219
- */
220
- var PLACEHOLDER_CARET_CLASS = exports.PLACEHOLDER_CARET_CLASS = 'pie-caret-in-placeholder';
221
-
222
- /** What MathLive serialises a `#?` slot as. */
223
- var PLACEHOLDER_LATEX = '\\placeholder{}';
224
-
225
- /**
226
- * A blinking caret inside a selected placeholder box.
227
- *
228
- * A keypad key such as `\frac` inserts `\frac{#?}{#?}`. MathLive turns each
229
- * `#?` into a `\placeholder{}` atom and *selects* the first one. That atom is a
230
- * leaf - the offsets around it are "before" and "after", there is no position
231
- * inside it - so MathLive renders **no caret element at all** and shows only
232
- * the selection highlight. The box therefore looked focused (blue) but dead,
233
- * where MathQuill used to blink a cursor inside its empty box.
234
- *
235
- * So the caret is drawn here. `:not(:has(.ML__selected))` picks the innermost
236
- * selected element (MathLive puts the class on a wrapper *and* the glyph span,
237
- * which would otherwise give two carets), and the `ML__caret-blink` keyframes
238
- * plus `--_caret-color` are MathLive's own, already in this shadow root.
239
- *
240
- * Typing still replaces the whole placeholder, which for an empty box is
241
- * indistinguishable from inserting at the caret.
242
- */
243
- var PLACEHOLDER_CARET_CSS = [":host(.".concat(PLACEHOLDER_CARET_CLASS, ") .ML__selected:not(:has(.ML__selected)){position:relative}"), ":host(.".concat(PLACEHOLDER_CARET_CLASS, ") .ML__selected:not(:has(.ML__selected))::after{"), 'content:"";position:absolute;left:50%;top:12%;height:76%;', 'border-right:2px solid var(--_caret-color, currentColor);', 'animation:ML__caret-blink 1.05s step-end forwards infinite}'].join('');
244
-
245
- // A live mathfield needs the readable radical index too: `rootIndexStyles` is
246
- // written for static markup in the host page, which cannot cross the shadow
247
- // boundary.
248
- var SHADOW_CSS = '.ML__latex .ML__center:has(.ML__stretchy){margin-left:0 !important}' + _commonStyles.ROOT_INDEX_CSS + _commonStyles.PARALLEL_CSS + PLACEHOLDER_CARET_CSS;
249
-
250
- /**
251
- * Keep {@link PLACEHOLDER_CARET_CLASS} in step with the selection.
252
- *
253
- * Gating on the class is what keeps the caret specific to placeholders: an
254
- * ordinary selection (`x+1`) must not sprout one. MathLive fires
255
- * `selection-change` for every caret move, including the one that lands on the
256
- * placeholder straight after an insert.
257
- *
258
- * @param {HTMLElement} mathField
259
- * @returns {function|undefined} teardown, to call on unmount
260
- */
261
- var trackPlaceholderCaret = exports.trackPlaceholderCaret = function trackPlaceholderCaret(mathField) {
262
- if (!mathField || typeof mathField.addEventListener !== 'function') {
263
- return undefined;
264
- }
265
- var update = function update() {
266
- var selected = '';
267
- try {
268
- // A collapsed selection already has a real MathLive caret.
269
- if (!mathField.selectionIsCollapsed && mathField.selection) {
270
- selected = mathField.getValue(mathField.selection, 'latex');
271
- }
272
- } catch (e) {
273
- log('could not read the selection: %s', e && e.message);
274
- }
275
- if (mathField.classList) {
276
- mathField.classList.toggle(PLACEHOLDER_CARET_CLASS, selected === PLACEHOLDER_LATEX);
277
- }
278
- };
279
- mathField.addEventListener('selection-change', update);
280
- update();
281
- return function () {
282
- return mathField.removeEventListener('selection-change', update);
283
- };
284
- };
285
-
286
- /**
287
- * Apply {@link SHADOW_CSS} inside a mathfield's shadow root.
288
- *
289
- * Uses `adoptedStyleSheets` when available (which is how MathLive loads its own
290
- * stylesheets) and falls back to appending a <style> node.
291
- *
292
- * @param {HTMLElement} mathField
293
- */
294
- var applyShadowStyles = exports.applyShadowStyles = function applyShadowStyles(mathField) {
295
- var root = mathField && mathField.shadowRoot;
296
- if (!root) {
297
- return;
298
- }
299
- try {
300
- if ('adoptedStyleSheets' in root && typeof CSSStyleSheet !== 'undefined') {
301
- // Do not re-add on a re-render.
302
- if (root.__pieAccentSheet) {
303
- return;
304
- }
305
- var sheet = new CSSStyleSheet();
306
- sheet.replaceSync(SHADOW_CSS);
307
- root.adoptedStyleSheets = [].concat((0, _toConsumableArray2["default"])(root.adoptedStyleSheets), [sheet]);
308
- root.__pieAccentSheet = sheet;
309
- return;
310
- }
311
- if (!root.querySelector('style[data-pie-accent]')) {
312
- var style = document.createElement('style');
313
- style.setAttribute('data-pie-accent', '');
314
- style.textContent = SHADOW_CSS;
315
- root.appendChild(style);
316
- }
317
- } catch (e) {
318
- log('could not apply shadow styles to the mathfield: %s', e && e.message);
319
- }
320
- };
321
-
322
- /**
323
- * Ensure MathLive's "core" stylesheet is in the document.
324
- *
325
- * `convertLatexToMarkup` - which renders keypad labels and static math - does
326
- * NOT inject it, while `renderMathInElement` and live mathfields do. Without it
327
- * the generated markup is unstyled: glyphs misalign and the <svg> used by
328
- * stretchy accents lays out statically at an unbounded width.
329
- *
330
- * Hosts that can import CSS should `import 'mathlive/static.css'`. For bundles
331
- * that cannot handle CSS imports (pie-elements ships JS-only web components),
332
- * this triggers MathLive's own injection against a detached element, so the
333
- * styles come from MathLive itself rather than being duplicated here.
334
- */
335
- var injectCoreStylesheet = function injectCoreStylesheet() {
336
- if (typeof document === 'undefined' || !mathlive || !mathlive.renderMathInElement) {
337
- return;
338
- }
339
- try {
340
- mathlive.renderMathInElement(document.createElement('span'));
341
- } catch (e) {
342
- log('could not trigger MathLive core stylesheet injection: %s', e && e.message);
343
- }
344
- };
345
-
346
- /**
347
- * Load MathLive synchronously when the bundler allows it.
348
- *
349
- * `require` keeps MathLive inside the host's bundle. An `import()` would make
350
- * webpack emit a separate chunk, and a deployment that does not serve that
351
- * chunk fails with a 404 at runtime - leaving every mathfield and keypad label
352
- * blank with no obvious cause. Being in the main bundle also makes the engine
353
- * available on first render, so callers that run synchronously (applyStaticMath,
354
- * keypad labels) work without a second pass.
355
- *
356
- * Returns undefined during SSR or if the module is genuinely unavailable.
357
- *
358
- * @returns {object|undefined}
359
- */
360
- var loadMathLiveSync = exports.loadMathLiveSync = function loadMathLiveSync() {
361
- if (typeof window === 'undefined') {
362
- return undefined;
363
- }
364
- if (!mathlive) {
365
- try {
366
- // eslint-disable-next-line global-require
367
- mathlive = require('mathlive');
368
- configureLoaded();
369
- } catch (e) {
370
- log('synchronous MathLive load unavailable: %s', e && e.message);
371
- return undefined;
372
- }
373
- }
374
- return mathlive;
375
- };
376
-
377
- /**
378
- * Load MathLive. Prefers the synchronous path; falls back to a dynamic import.
379
- * Resolves to undefined during SSR.
380
- *
381
- * @returns {Promise<object|undefined>}
382
- */
383
- var loadMathLive = exports.loadMathLive = /*#__PURE__*/function () {
384
- var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
385
- var _t;
386
- return _regenerator["default"].wrap(function (_context) {
387
- while (1) switch (_context.prev = _context.next) {
388
- case 0:
389
- if (!(typeof window === 'undefined')) {
390
- _context.next = 1;
391
- break;
392
- }
393
- return _context.abrupt("return", undefined);
394
- case 1:
395
- if (!mathlive) {
396
- _context.next = 2;
397
- break;
398
- }
399
- return _context.abrupt("return", mathlive);
400
- case 2:
401
- if (!loadMathLiveSync()) {
402
- _context.next = 3;
403
- break;
404
- }
405
- return _context.abrupt("return", mathlive);
406
- case 3:
407
- _context.prev = 3;
408
- _context.next = 4;
409
- return Promise.resolve().then(function () {
410
- return _interopRequireWildcard(require('mathlive'));
411
- });
412
- case 4:
413
- mathlive = _context.sent;
414
- configureLoaded();
415
- _context.next = 6;
416
- break;
417
- case 5:
418
- _context.prev = 5;
419
- _t = _context["catch"](3);
420
- // Surface this once: a silent failure here renders every field and keypad
421
- // label blank, which is very hard to trace back to a module load.
422
- // Skipped under test, where jsdom cannot load the browser build.
423
- if (!loadWarned && process.env.NODE_ENV !== 'test') {
424
- loadWarned = true;
425
- // eslint-disable-next-line no-console
426
- console.warn('[@pie-lib/math-input-mathlive] MathLive could not be loaded; math input will not render. ' + 'If this is a bundling issue, ensure "mathlive" is resolvable from the host bundle. Cause: ' + (_t && _t.message));
427
- }
428
- return _context.abrupt("return", undefined);
429
- case 6:
430
- return _context.abrupt("return", mathlive);
431
- case 7:
432
- case "end":
433
- return _context.stop();
434
- }
435
- }, _callee, null, [[3, 5]]);
436
- }));
437
- return function loadMathLive() {
438
- return _ref.apply(this, arguments);
439
- };
440
- }();
441
-
442
- /**
443
- * Synchronous accessor for an already-loaded MathLive.
444
- * @returns {object|undefined}
445
- */
446
- var getMathLive = exports.getMathLive = function getMathLive() {
447
- return mathlive;
448
- };
449
-
450
- /**
451
- * The macro dictionary to hand to a mathfield: pie macros plus anything
452
- * registered through `registerEmbed`.
453
- *
454
- * @returns {object}
455
- */
456
- var getMacros = exports.getMacros = function getMacros() {
457
- var out = _objectSpread({}, PIE_MACROS);
458
- embeds.forEach(function (_ref2, name) {
459
- var latex = _ref2.latex;
460
- out[name] = "\\htmlData{embed=".concat(name, "}{").concat(latex, "}");
461
- });
462
- return out;
463
- };
464
-
465
- /**
466
- * Register an embed. API-compatible with @pie-lib/math-input's `registerEmbed`
467
- * so existing callers do not change.
468
- *
469
- * MathQuill's factory returns `{ htmlString, text, latex }`. Only the
470
- * declarative parts survive: `latex` round-trips through a macro and the
471
- * styling hook becomes a `data-embed` attribute. Arbitrary DOM injection via
472
- * `htmlString` has no MathLive equivalent and is ignored.
473
- *
474
- * @param {string} name
475
- * @param {Function} factory
476
- */
477
- function registerEmbed(name, factory) {
478
- if (!name || typeof factory !== 'function') {
479
- return;
480
- }
481
- var definition = {};
482
- try {
483
- definition = factory() || {};
484
- } catch (e) {
485
- log('embed factory threw for "%s": %s', name, e.message);
486
- }
487
- var latex = Object.prototype.hasOwnProperty.call(KNOWN_EMBED_LATEX, name) ? KNOWN_EMBED_LATEX[name] : definition.mathliveLatex || '\\placeholder{}';
488
- if (!Object.prototype.hasOwnProperty.call(KNOWN_EMBED_LATEX, name) && !definition.mathliveLatex) {
489
- // Unknown third-party embed: degrade instead of throwing. `htmlString`
490
- // cannot be reproduced, so it renders as an editable slot.
491
- log('embed "%s" is not natively supported by MathLive; rendering as a placeholder. ' + 'Provide `mathliveLatex` in the factory result to control this.', name);
492
- }
493
- embeds.set(name, {
494
- factory: factory,
495
- latex: latex
496
- });
497
- }
498
-
499
- /**
500
- * Embeds registered so far. Exposed for tests/diagnostics.
501
- * @returns {string[]}
502
- */
503
- var registeredEmbeds = exports.registeredEmbeds = function registeredEmbeds() {
504
- return Array.from(embeds.keys());
505
- };
506
-
507
- /** Reset the embed registry. Test helper. */
508
- var __resetEmbeds = exports.__resetEmbeds = function __resetEmbeds() {
509
- return embeds.clear();
510
- };
511
-
512
- /** Inject a stub MathLive instance. Test helper. */
513
- var __setMathLiveForTest = exports.__setMathLiveForTest = function __setMathLiveForTest(stub) {
514
- mathlive = stub;
515
- };
516
-
517
- /**
518
- * Render static math into an element. API-compatible with
519
- * @pie-lib/math-input's `applyStaticMath`.
520
- *
521
- * Callers written against MathQuill invoke this synchronously from lifecycle
522
- * methods, where MathLive (a dynamic import) may not have loaded yet. Rather
523
- * than silently rendering nothing, this kicks off the load and re-applies once
524
- * the engine is ready, so the element fills in on the next tick.
525
- *
526
- * @param {HTMLElement} element
527
- * @param {string} [latex] assigned to the element before rendering
528
- * @param {object} [options] `{ macros }` overrides
529
- * @returns {HTMLElement|undefined} the element, or undefined if deferred
530
- */
531
- function applyStaticMath(element, latex) {
532
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
533
- if (!element || typeof window === 'undefined') {
534
- return undefined;
535
- }
536
-
537
- // Capture the source now: if we defer, the element's textContent may have
538
- // been overwritten by the time MathLive is ready.
539
- var source = latex === undefined || latex === null ? element.textContent : latex;
540
- var ml = getMathLive() || loadMathLiveSync();
541
- if (!ml) {
542
- log('applyStaticMath called before MathLive loaded - deferring until it is ready');
543
- loadMathLive().then(function (loaded) {
544
- // The element may have been unmounted while loading.
545
- if (loaded && element.isConnected !== false) {
546
- applyStaticMath(element, source, options);
547
- }
548
- });
549
- return undefined;
550
- }
551
- element.innerHTML = ml.convertLatexToMarkup((0, _latexBridge.withVisibleEmptySlots)((0, _latexBridge.toMathLive)(source)), {
552
- macros: _objectSpread(_objectSpread({}, getMacros()), options.macros || {})
553
- });
554
- return element;
555
- }
556
-
557
- /**
558
- * Convert latex to markup using the pie macro set. Used for keypad labels and
559
- * any read-only rendering that does not need a live mathfield.
560
- *
561
- * @param {string} latex
562
- * @param {object} [options]
563
- * @returns {string} HTML markup, or '' if MathLive is not loaded
564
- */
565
- function latexToMarkup(latex) {
566
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
567
- // Try the synchronous load so the very first render can produce markup
568
- // instead of falling back to raw latex.
569
- var ml = getMathLive() || loadMathLiveSync();
570
- if (!ml || !latex) {
571
- return '';
572
- }
573
- try {
574
- // Empty groups render as nothing in static markup, so give them a visible
575
- // box. This covers every static path: keypad labels, mf.Static in display
576
- // mode, and applyStaticMath.
577
- return ml.convertLatexToMarkup((0, _latexBridge.withVisibleEmptySlots)((0, _latexBridge.toMathLive)(latex)), _objectSpread({
578
- macros: _objectSpread(_objectSpread({}, getMacros()), options.macros || {})
579
- }, options));
580
- } catch (e) {
581
- log('convertLatexToMarkup failed for "%s": %s', latex, e.message);
582
- return '';
583
- }
584
- }
585
- //# sourceMappingURL=mathlive-instance.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mathlive-instance.js","names":["_debug","_interopRequireDefault","require","_latexBridge","_commonStyles","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","_interopRequireWildcard","WeakMap","n","__esModule","i","f","__proto__","_typeof","has","get","set","_t2","hasOwnProperty","call","log","debug","mathlive","fontsDirectory","absoluteFontsDirectory","dir","test","URL","document","baseURI","href","message","FALLBACK_MATHLIVE_VERSION","cdnFontsDirectory","version","concat","configureFonts","exports","MathfieldElement","undefined","MATH_MODE_SPACE","PIE_MACROS","parallelogram","parallel","napprox","nsim","ncong","nparallel","perpendicular","divide","degree","square","longdiv","overarc","abs","embeds","Map","KNOWN_EMBED_LATEX","newLine","answerBlock","loadWarned","configureLoaded","injectCoreStylesheet","PLACEHOLDER_CARET_CLASS","PLACEHOLDER_LATEX","PLACEHOLDER_CARET_CSS","join","SHADOW_CSS","ROOT_INDEX_CSS","PARALLEL_CSS","trackPlaceholderCaret","mathField","addEventListener","update","selected","selectionIsCollapsed","selection","getValue","classList","toggle","removeEventListener","applyShadowStyles","root","shadowRoot","CSSStyleSheet","__pieAccentSheet","sheet","replaceSync","adoptedStyleSheets","_toConsumableArray2","querySelector","style","createElement","setAttribute","textContent","appendChild","renderMathInElement","loadMathLiveSync","window","loadMathLive","_ref","_asyncToGenerator2","_regenerator","mark","_callee","_t","wrap","_context","prev","next","abrupt","Promise","resolve","then","sent","process","env","NODE_ENV","console","warn","stop","getMathLive","getMacros","out","_ref2","name","latex","registerEmbed","factory","definition","prototype","mathliveLatex","registeredEmbeds","Array","from","__resetEmbeds","clear","__setMathLiveForTest","stub","applyStaticMath","element","options","source","ml","loaded","isConnected","innerHTML","convertLatexToMarkup","withVisibleEmptySlots","toMathLive","macros","latexToMarkup"],"sources":["../src/mathlive-instance.js"],"sourcesContent":["import debug from 'debug';\nimport { NEWLINE_EMBED, toMathLive, withVisibleEmptySlots } from './latex-bridge';\nimport { ROOT_INDEX_CSS, PARALLEL_CSS } from './mf/common-styles';\n\nconst log = debug('pie-lib:math-input-mathlive:instance');\n\n/**\n * MathLive bootstrap + compatibility shims for @pie-lib/math-input's public API.\n *\n * MathLive is loaded lazily and only in the browser: the editor bundle is\n * ~227KB gzip and registers custom elements, so it must never run during SSR.\n */\n\nlet mathlive;\n\n/**\n * Where the KaTeX woff2 fonts are served from, as configured by the host app.\n * `undefined` means \"not configured\"; `null` means \"explicitly disabled\".\n */\nlet fontsDirectory;\n\n/**\n * Turn a fonts path into a fully-qualified URL.\n *\n * MathLive's default `fontsDirectory` is the relative `'./fonts/'`, which it\n * resolves against its own script URL. Under a bundler (webpack/Next) that\n * script URL is empty, so `new URL('./fonts/', '')` throws\n * \"Failed to construct 'URL': Invalid base URL\" from `loadFonts`.\n * Resolving against `document.baseURI` avoids that entirely and honours any\n * <base href> / asset prefix the host app uses.\n */\nconst absoluteFontsDirectory = (dir) => {\n if (!dir) {\n return dir;\n }\n\n // Already absolute (http://, https://, //cdn...) - MathLive handles these.\n if (/^(?:[a-z+]+:)?\\/\\//i.test(dir)) {\n return dir;\n }\n\n try {\n return new URL(dir, document.baseURI).href;\n } catch (e) {\n log('could not resolve fontsDirectory \"%s\": %s', dir, e && e.message);\n return null;\n }\n};\n\n/**\n * Version-pinned CDN fallback for the KaTeX fonts.\n *\n * Some symbols are composed from Private Use Area glyphs that exist only in\n * those fonts: `\\\\neq` is U+E020 (a negation slash) overlapped on `=`, and\n * `\\\\nsim` / `\\\\ncong` work the same way. With no fonts the browser substitutes\n * an arbitrary glyph for U+E020, so those keys render as garbage rather than\n * simply falling back to a plainer face.\n *\n * The version comes from MathLive itself, so the fonts always match the engine.\n * Hosts that would rather not depend on a third party should serve the fonts and\n * call `configureFonts('/their/path')`, or pass `null` to opt out.\n */\nconst FALLBACK_MATHLIVE_VERSION = '0.110.0';\n\nconst cdnFontsDirectory = () => {\n const version = (mathlive && mathlive.version && mathlive.version.mathlive) || FALLBACK_MATHLIVE_VERSION;\n\n // NOTE: `/fonts`, not `/dist/fonts` - the published package root holds them.\n return `https://unpkg.com/mathlive@${version}/fonts`;\n};\n\n/**\n * Tell the package where the MathLive fonts are served from.\n *\n * Call before `loadMathLive()`.\n *\n * - a path/URL: served by you, no third-party request\n * - `null`: skip font loading; note `\\\\neq`, `\\\\nsim` and `\\\\ncong` then\n * render incorrectly, being built from Private Use Area glyphs\n * - not called: falls back to a version-pinned CDN\n *\n * The fonts ship inside the `mathlive` package (`node_modules/mathlive/fonts`)\n * ready to copy into whatever the host app serves statically.\n *\n * @param {string|null} [dir]\n */\nexport const configureFonts = (dir) => {\n fontsDirectory = dir;\n\n if (mathlive) {\n mathlive.MathfieldElement.fontsDirectory = dir === undefined ? cdnFontsDirectory() : absoluteFontsDirectory(dir);\n }\n};\n\n/**\n * What the spacebar inserts in math mode.\n *\n * MathLive's `mathModeSpace` defaults to an empty string, which makes the\n * spacebar a no-op - users cannot type a space at all. `\\\\ ` (a LaTeX control\n * space) is what MathQuill serialised spaces as, so existing content and the\n * MathJax renderer in @pie-lib/math-rendering both already understand it.\n *\n * A literal \" \" is not usable: LaTeX skips raw whitespace.\n */\nexport const MATH_MODE_SPACE = '\\\\ ';\n\n/**\n * Custom macros for the pie-specific commands that the MathQuill fork\n * understood but stock LaTeX does not.\n *\n * Kept deliberately in sync with the MathJax macros in\n * @pie-lib/math-rendering (`render-math.js`) so the same latex renders the same\n * way in the editor and in the static renderer.\n */\nexport const PIE_MACROS = {\n // Argument-less symbols. Atomic is correct here: backspace should remove the\n // whole glyph, and there is nothing to type into.\n parallelogram: '\\\\htmlData{pie-macro=parallelogram}{\\\\unicode{\"25B1}}',\n // Same glyph as the built-in `\\\\parallel` (U+2225), tagged so it can be sized -\n // see `parallelStyles`.\n parallel: '\\\\htmlData{pie-macro=parallel}{\\\\unicode{\"2225}}',\n napprox: '\\\\not\\\\approx',\n nsim: '\\\\not\\\\sim',\n ncong: '\\\\not\\\\cong',\n nparallel: '\\\\not\\\\parallel',\n perpendicular: '\\\\perp',\n divide: '\\\\div',\n degree: '^{\\\\circ}',\n square: '\\\\unicode{\"25A1}',\n\n // Argument-taking commands, kept ONLY so previously authored latex still\n // parses and renders. They are never used for editing: MathLive serialises a\n // macro from the arguments it was created with, so text typed inside the\n // expansion never comes back out of `getValue('latex')`. Anything entering a\n // mathfield is rewritten to the native equivalent first - see\n // `toNativeCommands` in latex-bridge.\n longdiv: '\\\\enclose{longdiv}{#1}',\n overarc: '\\\\overparen{#1}',\n abs: '\\\\left|#1\\\\right|',\n};\n\n/**\n * Registry for `registerEmbed`.\n *\n * MathLive has no embed plugin system, so an embed is expressed as a macro that\n * expands to real LaTeX. `\\htmlData{embed=<name>}` tags the rendered output so\n * consumers can target it with CSS exactly as they targeted the old\n * `htmlString` markup.\n *\n * Known embeds map to native constructs:\n * - `newLine` -> structural, handled by latex-bridge (`\\displaylines` + `\\\\`)\n * - `answerBlock`-> `\\placeholder{}` (interactive, read via the prompts API)\n *\n * @type {Map<string, {factory: Function, latex: string}>}\n */\nconst embeds = new Map();\n\nconst KNOWN_EMBED_LATEX = {\n // newLine is structural: it is translated by latex-bridge before it ever\n // reaches MathLive, so the macro only needs to be harmless.\n newLine: '',\n answerBlock: '\\\\placeholder{}',\n};\n\nlet loadWarned = false;\n\n/** Apply post-load configuration exactly once. */\nconst configureLoaded = () => {\n // Always replace MathLive's relative `'./fonts/'` default: it throws\n // \"Invalid base URL\" when bundled. Use the host's copy if one was configured,\n // otherwise the version-pinned CDN.\n if (fontsDirectory === undefined) {\n log(\n 'no fontsDirectory configured - falling back to the CDN (%s). ' +\n 'Serve the fonts yourself and call configureFonts(\"/path/to/fonts\") to avoid the network request, ' +\n 'or configureFonts(null) to opt out.',\n cdnFontsDirectory(),\n );\n }\n\n mathlive.MathfieldElement.fontsDirectory =\n fontsDirectory === undefined ? cdnFontsDirectory() : absoluteFontsDirectory(fontsDirectory);\n\n injectCoreStylesheet();\n};\n\n/**\n * CSS that has to live *inside* a mathfield's shadow root.\n *\n * A live `<math-field>` renders in shadow DOM (`attachShadow({mode:'open'})`),\n * so nothing in the host page's stylesheets reaches it. The stretchy-accent\n * problem therefore needs fixing twice: once for static markup (see\n * `placeholderStyles`) and once here for the editor.\n *\n * MathLive centres an accent with `margin-left: <half the content width>` as an\n * inline style. For a stretchy accent that also shrinks its containing block\n * (`.ML__center` is position:relative), so the arc ends up half-width and offset\n * - visibly failing to span the text underneath.\n *\n * `:has(.ML__stretchy)` keeps the fix to stretchy accents; single-glyph accents\n * (`\\hat{x}`, `\\vec{x}`) still need their centring offset.\n */\n/**\n * Marker put on the host `<math-field>` while a `\\placeholder{}` is selected,\n * so the caret rules below apply to a placeholder and nothing else.\n */\nexport const PLACEHOLDER_CARET_CLASS = 'pie-caret-in-placeholder';\n\n/** What MathLive serialises a `#?` slot as. */\nconst PLACEHOLDER_LATEX = '\\\\placeholder{}';\n\n/**\n * A blinking caret inside a selected placeholder box.\n *\n * A keypad key such as `\\frac` inserts `\\frac{#?}{#?}`. MathLive turns each\n * `#?` into a `\\placeholder{}` atom and *selects* the first one. That atom is a\n * leaf - the offsets around it are \"before\" and \"after\", there is no position\n * inside it - so MathLive renders **no caret element at all** and shows only\n * the selection highlight. The box therefore looked focused (blue) but dead,\n * where MathQuill used to blink a cursor inside its empty box.\n *\n * So the caret is drawn here. `:not(:has(.ML__selected))` picks the innermost\n * selected element (MathLive puts the class on a wrapper *and* the glyph span,\n * which would otherwise give two carets), and the `ML__caret-blink` keyframes\n * plus `--_caret-color` are MathLive's own, already in this shadow root.\n *\n * Typing still replaces the whole placeholder, which for an empty box is\n * indistinguishable from inserting at the caret.\n */\nconst PLACEHOLDER_CARET_CSS = [\n `:host(.${PLACEHOLDER_CARET_CLASS}) .ML__selected:not(:has(.ML__selected)){position:relative}`,\n `:host(.${PLACEHOLDER_CARET_CLASS}) .ML__selected:not(:has(.ML__selected))::after{`,\n 'content:\"\";position:absolute;left:50%;top:12%;height:76%;',\n 'border-right:2px solid var(--_caret-color, currentColor);',\n 'animation:ML__caret-blink 1.05s step-end forwards infinite}',\n].join('');\n\n// A live mathfield needs the readable radical index too: `rootIndexStyles` is\n// written for static markup in the host page, which cannot cross the shadow\n// boundary.\nconst SHADOW_CSS =\n '.ML__latex .ML__center:has(.ML__stretchy){margin-left:0 !important}' +\n ROOT_INDEX_CSS +\n PARALLEL_CSS +\n PLACEHOLDER_CARET_CSS;\n\n/**\n * Keep {@link PLACEHOLDER_CARET_CLASS} in step with the selection.\n *\n * Gating on the class is what keeps the caret specific to placeholders: an\n * ordinary selection (`x+1`) must not sprout one. MathLive fires\n * `selection-change` for every caret move, including the one that lands on the\n * placeholder straight after an insert.\n *\n * @param {HTMLElement} mathField\n * @returns {function|undefined} teardown, to call on unmount\n */\nexport const trackPlaceholderCaret = (mathField) => {\n if (!mathField || typeof mathField.addEventListener !== 'function') {\n return undefined;\n }\n\n const update = () => {\n let selected = '';\n\n try {\n // A collapsed selection already has a real MathLive caret.\n if (!mathField.selectionIsCollapsed && mathField.selection) {\n selected = mathField.getValue(mathField.selection, 'latex');\n }\n } catch (e) {\n log('could not read the selection: %s', e && e.message);\n }\n\n if (mathField.classList) {\n mathField.classList.toggle(PLACEHOLDER_CARET_CLASS, selected === PLACEHOLDER_LATEX);\n }\n };\n\n mathField.addEventListener('selection-change', update);\n update();\n\n return () => mathField.removeEventListener('selection-change', update);\n};\n\n/**\n * Apply {@link SHADOW_CSS} inside a mathfield's shadow root.\n *\n * Uses `adoptedStyleSheets` when available (which is how MathLive loads its own\n * stylesheets) and falls back to appending a <style> node.\n *\n * @param {HTMLElement} mathField\n */\nexport const applyShadowStyles = (mathField) => {\n const root = mathField && mathField.shadowRoot;\n\n if (!root) {\n return;\n }\n\n try {\n if ('adoptedStyleSheets' in root && typeof CSSStyleSheet !== 'undefined') {\n // Do not re-add on a re-render.\n if (root.__pieAccentSheet) {\n return;\n }\n\n const sheet = new CSSStyleSheet();\n\n sheet.replaceSync(SHADOW_CSS);\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];\n root.__pieAccentSheet = sheet;\n\n return;\n }\n\n if (!root.querySelector('style[data-pie-accent]')) {\n const style = document.createElement('style');\n\n style.setAttribute('data-pie-accent', '');\n style.textContent = SHADOW_CSS;\n root.appendChild(style);\n }\n } catch (e) {\n log('could not apply shadow styles to the mathfield: %s', e && e.message);\n }\n};\n\n/**\n * Ensure MathLive's \"core\" stylesheet is in the document.\n *\n * `convertLatexToMarkup` - which renders keypad labels and static math - does\n * NOT inject it, while `renderMathInElement` and live mathfields do. Without it\n * the generated markup is unstyled: glyphs misalign and the <svg> used by\n * stretchy accents lays out statically at an unbounded width.\n *\n * Hosts that can import CSS should `import 'mathlive/static.css'`. For bundles\n * that cannot handle CSS imports (pie-elements ships JS-only web components),\n * this triggers MathLive's own injection against a detached element, so the\n * styles come from MathLive itself rather than being duplicated here.\n */\nconst injectCoreStylesheet = () => {\n if (typeof document === 'undefined' || !mathlive || !mathlive.renderMathInElement) {\n return;\n }\n\n try {\n mathlive.renderMathInElement(document.createElement('span'));\n } catch (e) {\n log('could not trigger MathLive core stylesheet injection: %s', e && e.message);\n }\n};\n\n/**\n * Load MathLive synchronously when the bundler allows it.\n *\n * `require` keeps MathLive inside the host's bundle. An `import()` would make\n * webpack emit a separate chunk, and a deployment that does not serve that\n * chunk fails with a 404 at runtime - leaving every mathfield and keypad label\n * blank with no obvious cause. Being in the main bundle also makes the engine\n * available on first render, so callers that run synchronously (applyStaticMath,\n * keypad labels) work without a second pass.\n *\n * Returns undefined during SSR or if the module is genuinely unavailable.\n *\n * @returns {object|undefined}\n */\nexport const loadMathLiveSync = () => {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n if (!mathlive) {\n try {\n // eslint-disable-next-line global-require\n mathlive = require('mathlive');\n configureLoaded();\n } catch (e) {\n log('synchronous MathLive load unavailable: %s', e && e.message);\n return undefined;\n }\n }\n\n return mathlive;\n};\n\n/**\n * Load MathLive. Prefers the synchronous path; falls back to a dynamic import.\n * Resolves to undefined during SSR.\n *\n * @returns {Promise<object|undefined>}\n */\nexport const loadMathLive = async () => {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n if (mathlive) {\n return mathlive;\n }\n\n if (loadMathLiveSync()) {\n return mathlive;\n }\n\n try {\n mathlive = await import('mathlive');\n configureLoaded();\n } catch (e) {\n // Surface this once: a silent failure here renders every field and keypad\n // label blank, which is very hard to trace back to a module load.\n // Skipped under test, where jsdom cannot load the browser build.\n if (!loadWarned && process.env.NODE_ENV !== 'test') {\n loadWarned = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[@pie-lib/math-input-mathlive] MathLive could not be loaded; math input will not render. ' +\n 'If this is a bundling issue, ensure \"mathlive\" is resolvable from the host bundle. Cause: ' +\n (e && e.message),\n );\n }\n\n return undefined;\n }\n\n return mathlive;\n};\n\n/**\n * Synchronous accessor for an already-loaded MathLive.\n * @returns {object|undefined}\n */\nexport const getMathLive = () => mathlive;\n\n/**\n * The macro dictionary to hand to a mathfield: pie macros plus anything\n * registered through `registerEmbed`.\n *\n * @returns {object}\n */\nexport const getMacros = () => {\n const out = { ...PIE_MACROS };\n\n embeds.forEach(({ latex }, name) => {\n out[name] = `\\\\htmlData{embed=${name}}{${latex}}`;\n });\n\n return out;\n};\n\n/**\n * Register an embed. API-compatible with @pie-lib/math-input's `registerEmbed`\n * so existing callers do not change.\n *\n * MathQuill's factory returns `{ htmlString, text, latex }`. Only the\n * declarative parts survive: `latex` round-trips through a macro and the\n * styling hook becomes a `data-embed` attribute. Arbitrary DOM injection via\n * `htmlString` has no MathLive equivalent and is ignored.\n *\n * @param {string} name\n * @param {Function} factory\n */\nexport function registerEmbed(name, factory) {\n if (!name || typeof factory !== 'function') {\n return;\n }\n\n let definition = {};\n\n try {\n definition = factory() || {};\n } catch (e) {\n log('embed factory threw for \"%s\": %s', name, e.message);\n }\n\n const latex = Object.prototype.hasOwnProperty.call(KNOWN_EMBED_LATEX, name)\n ? KNOWN_EMBED_LATEX[name]\n : definition.mathliveLatex || '\\\\placeholder{}';\n\n if (!Object.prototype.hasOwnProperty.call(KNOWN_EMBED_LATEX, name) && !definition.mathliveLatex) {\n // Unknown third-party embed: degrade instead of throwing. `htmlString`\n // cannot be reproduced, so it renders as an editable slot.\n log(\n 'embed \"%s\" is not natively supported by MathLive; rendering as a placeholder. ' +\n 'Provide `mathliveLatex` in the factory result to control this.',\n name,\n );\n }\n\n embeds.set(name, { factory, latex });\n}\n\n/**\n * Embeds registered so far. Exposed for tests/diagnostics.\n * @returns {string[]}\n */\nexport const registeredEmbeds = () => Array.from(embeds.keys());\n\n/** Reset the embed registry. Test helper. */\nexport const __resetEmbeds = () => embeds.clear();\n\n/** Inject a stub MathLive instance. Test helper. */\nexport const __setMathLiveForTest = (stub) => {\n mathlive = stub;\n};\n\n/**\n * Render static math into an element. API-compatible with\n * @pie-lib/math-input's `applyStaticMath`.\n *\n * Callers written against MathQuill invoke this synchronously from lifecycle\n * methods, where MathLive (a dynamic import) may not have loaded yet. Rather\n * than silently rendering nothing, this kicks off the load and re-applies once\n * the engine is ready, so the element fills in on the next tick.\n *\n * @param {HTMLElement} element\n * @param {string} [latex] assigned to the element before rendering\n * @param {object} [options] `{ macros }` overrides\n * @returns {HTMLElement|undefined} the element, or undefined if deferred\n */\nexport function applyStaticMath(element, latex, options = {}) {\n if (!element || typeof window === 'undefined') {\n return undefined;\n }\n\n // Capture the source now: if we defer, the element's textContent may have\n // been overwritten by the time MathLive is ready.\n const source = latex === undefined || latex === null ? element.textContent : latex;\n const ml = getMathLive() || loadMathLiveSync();\n\n if (!ml) {\n log('applyStaticMath called before MathLive loaded - deferring until it is ready');\n\n loadMathLive().then((loaded) => {\n // The element may have been unmounted while loading.\n if (loaded && element.isConnected !== false) {\n applyStaticMath(element, source, options);\n }\n });\n\n return undefined;\n }\n\n element.innerHTML = ml.convertLatexToMarkup(withVisibleEmptySlots(toMathLive(source)), {\n macros: { ...getMacros(), ...(options.macros || {}) },\n });\n\n return element;\n}\n\n/**\n * Convert latex to markup using the pie macro set. Used for keypad labels and\n * any read-only rendering that does not need a live mathfield.\n *\n * @param {string} latex\n * @param {object} [options]\n * @returns {string} HTML markup, or '' if MathLive is not loaded\n */\nexport function latexToMarkup(latex, options = {}) {\n // Try the synchronous load so the very first render can produce markup\n // instead of falling back to raw latex.\n const ml = getMathLive() || loadMathLiveSync();\n\n if (!ml || !latex) {\n return '';\n }\n\n try {\n // Empty groups render as nothing in static markup, so give them a visible\n // box. This covers every static path: keypad labels, mf.Static in display\n // mode, and applyStaticMath.\n return ml.convertLatexToMarkup(withVisibleEmptySlots(toMathLive(latex)), {\n macros: { ...getMacros(), ...(options.macros || {}) },\n ...options,\n });\n } catch (e) {\n log('convertLatexToMarkup failed for \"%s\": %s', latex, e.message);\n return '';\n }\n}\n\nexport { NEWLINE_EMBED };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAAkE,SAAAG,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,Y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