@pie-lib/math-input-mathlive 1.1.4 → 1.1.5-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/lib/keypad/index.js +15 -17
- package/lib/keypad/index.js.map +1 -1
- package/lib/keys/geometry.js +7 -4
- package/lib/keys/geometry.js.map +1 -1
- package/lib/keys/misc.js +9 -2
- package/lib/keys/misc.js.map +1 -1
- package/lib/latex-bridge.js +48 -3
- package/lib/latex-bridge.js.map +1 -1
- package/lib/mathlive-instance.js +173 -12
- package/lib/mathlive-instance.js.map +1 -1
- package/lib/mf/common-styles.js +74 -10
- package/lib/mf/common-styles.js.map +1 -1
- package/lib/mf/index.js +6 -0
- package/lib/mf/index.js.map +1 -1
- package/lib/mf/input.js +29 -5
- package/lib/mf/input.js.map +1 -1
- package/lib/mf/static.js +105 -7
- package/lib/mf/static.js.map +1 -1
- package/package.json +3 -4
- package/src/keypad/index.jsx +15 -14
- package/src/keys/geometry.js +7 -2
- package/src/keys/misc.js +8 -2
- package/src/latex-bridge.js +52 -3
- package/src/mathlive-instance.js +190 -11
- package/src/mf/common-styles.js +78 -8
- package/src/mf/index.js +2 -0
- package/src/mf/input.jsx +37 -5
- package/src/mf/static.jsx +121 -6
- package/CHANGELOG.md +0 -30
- package/LICENSE.md +0 -5
- package/src/__tests__/drop-in-compat.test.jsx +0 -112
- package/src/__tests__/index.test.jsx +0 -109
- package/src/__tests__/input-imperative.test.jsx +0 -144
- package/src/__tests__/keypad-label.test.jsx +0 -57
- package/src/__tests__/latex-bridge.test.js +0 -230
- package/src/__tests__/mathlive-instance.test.js +0 -181
package/lib/mathlive-instance.js
CHANGED
|
@@ -5,24 +5,27 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
exports.MATH_MODE_SPACE = void 0;
|
|
8
9
|
Object.defineProperty(exports, "NEWLINE_EMBED", {
|
|
9
10
|
enumerable: true,
|
|
10
11
|
get: function get() {
|
|
11
12
|
return _latexBridge.NEWLINE_EMBED;
|
|
12
13
|
}
|
|
13
14
|
});
|
|
14
|
-
exports.__setMathLiveForTest = exports.__resetEmbeds = exports.PIE_MACROS = void 0;
|
|
15
|
+
exports.applyShadowStyles = exports.__setMathLiveForTest = exports.__resetEmbeds = exports.PLACEHOLDER_CARET_CLASS = exports.PIE_MACROS = void 0;
|
|
15
16
|
exports.applyStaticMath = applyStaticMath;
|
|
16
17
|
exports.getMathLive = exports.getMacros = exports.configureFonts = void 0;
|
|
17
18
|
exports.latexToMarkup = latexToMarkup;
|
|
18
19
|
exports.loadMathLiveSync = exports.loadMathLive = void 0;
|
|
19
20
|
exports.registerEmbed = registerEmbed;
|
|
20
|
-
exports.registeredEmbeds = void 0;
|
|
21
|
+
exports.trackPlaceholderCaret = exports.registeredEmbeds = void 0;
|
|
21
22
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
22
23
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
24
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
25
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
24
26
|
var _debug = _interopRequireDefault(require("debug"));
|
|
25
27
|
var _latexBridge = require("./latex-bridge");
|
|
28
|
+
var _commonStyles = require("./mf/common-styles");
|
|
26
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; }
|
|
27
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; }
|
|
28
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); }
|
|
@@ -70,25 +73,61 @@ var absoluteFontsDirectory = function absoluteFontsDirectory(dir) {
|
|
|
70
73
|
}
|
|
71
74
|
};
|
|
72
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
|
+
|
|
73
97
|
/**
|
|
74
98
|
* Tell the package where the MathLive fonts are served from.
|
|
75
99
|
*
|
|
76
|
-
* Call before `loadMathLive()`.
|
|
77
|
-
*
|
|
78
|
-
*
|
|
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
|
|
79
106
|
*
|
|
80
107
|
* The fonts ship inside the `mathlive` package (`node_modules/mathlive/fonts`)
|
|
81
|
-
*
|
|
108
|
+
* ready to copy into whatever the host app serves statically.
|
|
82
109
|
*
|
|
83
|
-
* @param {string|null} dir
|
|
110
|
+
* @param {string|null} [dir]
|
|
84
111
|
*/
|
|
85
112
|
var configureFonts = exports.configureFonts = function configureFonts(dir) {
|
|
86
113
|
fontsDirectory = dir;
|
|
87
114
|
if (mathlive) {
|
|
88
|
-
mathlive.MathfieldElement.fontsDirectory = absoluteFontsDirectory(dir);
|
|
115
|
+
mathlive.MathfieldElement.fontsDirectory = dir === undefined ? cdnFontsDirectory() : absoluteFontsDirectory(dir);
|
|
89
116
|
}
|
|
90
117
|
};
|
|
91
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
|
+
|
|
92
131
|
/**
|
|
93
132
|
* Custom macros for the pie-specific commands that the MathQuill fork
|
|
94
133
|
* understood but stock LaTeX does not.
|
|
@@ -146,15 +185,137 @@ var loadWarned = false;
|
|
|
146
185
|
/** Apply post-load configuration exactly once. */
|
|
147
186
|
var configureLoaded = function configureLoaded() {
|
|
148
187
|
// Always replace MathLive's relative `'./fonts/'` default: it throws
|
|
149
|
-
// "Invalid base URL" when bundled.
|
|
150
|
-
//
|
|
188
|
+
// "Invalid base URL" when bundled. Use the host's copy if one was configured,
|
|
189
|
+
// otherwise the version-pinned CDN.
|
|
151
190
|
if (fontsDirectory === undefined) {
|
|
152
|
-
log('no fontsDirectory configured -
|
|
191
|
+
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());
|
|
153
192
|
}
|
|
154
|
-
mathlive.MathfieldElement.fontsDirectory = fontsDirectory === undefined ?
|
|
193
|
+
mathlive.MathfieldElement.fontsDirectory = fontsDirectory === undefined ? cdnFontsDirectory() : absoluteFontsDirectory(fontsDirectory);
|
|
155
194
|
injectCoreStylesheet();
|
|
156
195
|
};
|
|
157
196
|
|
|
197
|
+
/**
|
|
198
|
+
* CSS that has to live *inside* a mathfield's shadow root.
|
|
199
|
+
*
|
|
200
|
+
* A live `<math-field>` renders in shadow DOM (`attachShadow({mode:'open'})`),
|
|
201
|
+
* so nothing in the host page's stylesheets reaches it. The stretchy-accent
|
|
202
|
+
* problem therefore needs fixing twice: once for static markup (see
|
|
203
|
+
* `placeholderStyles`) and once here for the editor.
|
|
204
|
+
*
|
|
205
|
+
* MathLive centres an accent with `margin-left: <half the content width>` as an
|
|
206
|
+
* inline style. For a stretchy accent that also shrinks its containing block
|
|
207
|
+
* (`.ML__center` is position:relative), so the arc ends up half-width and offset
|
|
208
|
+
* - visibly failing to span the text underneath.
|
|
209
|
+
*
|
|
210
|
+
* `:has(.ML__stretchy)` keeps the fix to stretchy accents; single-glyph accents
|
|
211
|
+
* (`\hat{x}`, `\vec{x}`) still need their centring offset.
|
|
212
|
+
*/
|
|
213
|
+
/**
|
|
214
|
+
* Marker put on the host `<math-field>` while a `\placeholder{}` is selected,
|
|
215
|
+
* so the caret rules below apply to a placeholder and nothing else.
|
|
216
|
+
*/
|
|
217
|
+
var PLACEHOLDER_CARET_CLASS = exports.PLACEHOLDER_CARET_CLASS = 'pie-caret-in-placeholder';
|
|
218
|
+
|
|
219
|
+
/** What MathLive serialises a `#?` slot as. */
|
|
220
|
+
var PLACEHOLDER_LATEX = '\\placeholder{}';
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* A blinking caret inside a selected placeholder box.
|
|
224
|
+
*
|
|
225
|
+
* A keypad key such as `\frac` inserts `\frac{#?}{#?}`. MathLive turns each
|
|
226
|
+
* `#?` into a `\placeholder{}` atom and *selects* the first one. That atom is a
|
|
227
|
+
* leaf - the offsets around it are "before" and "after", there is no position
|
|
228
|
+
* inside it - so MathLive renders **no caret element at all** and shows only
|
|
229
|
+
* the selection highlight. The box therefore looked focused (blue) but dead,
|
|
230
|
+
* where MathQuill used to blink a cursor inside its empty box.
|
|
231
|
+
*
|
|
232
|
+
* So the caret is drawn here. `:not(:has(.ML__selected))` picks the innermost
|
|
233
|
+
* selected element (MathLive puts the class on a wrapper *and* the glyph span,
|
|
234
|
+
* which would otherwise give two carets), and the `ML__caret-blink` keyframes
|
|
235
|
+
* plus `--_caret-color` are MathLive's own, already in this shadow root.
|
|
236
|
+
*
|
|
237
|
+
* Typing still replaces the whole placeholder, which for an empty box is
|
|
238
|
+
* indistinguishable from inserting at the caret.
|
|
239
|
+
*/
|
|
240
|
+
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('');
|
|
241
|
+
|
|
242
|
+
// A live mathfield needs the readable radical index too: `rootIndexStyles` is
|
|
243
|
+
// written for static markup in the host page, which cannot cross the shadow
|
|
244
|
+
// boundary.
|
|
245
|
+
var SHADOW_CSS = '.ML__latex .ML__center:has(.ML__stretchy){margin-left:0 !important}' + _commonStyles.ROOT_INDEX_CSS + PLACEHOLDER_CARET_CSS;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Keep {@link PLACEHOLDER_CARET_CLASS} in step with the selection.
|
|
249
|
+
*
|
|
250
|
+
* Gating on the class is what keeps the caret specific to placeholders: an
|
|
251
|
+
* ordinary selection (`x+1`) must not sprout one. MathLive fires
|
|
252
|
+
* `selection-change` for every caret move, including the one that lands on the
|
|
253
|
+
* placeholder straight after an insert.
|
|
254
|
+
*
|
|
255
|
+
* @param {HTMLElement} mathField
|
|
256
|
+
* @returns {function|undefined} teardown, to call on unmount
|
|
257
|
+
*/
|
|
258
|
+
var trackPlaceholderCaret = exports.trackPlaceholderCaret = function trackPlaceholderCaret(mathField) {
|
|
259
|
+
if (!mathField || typeof mathField.addEventListener !== 'function') {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
var update = function update() {
|
|
263
|
+
var selected = '';
|
|
264
|
+
try {
|
|
265
|
+
// A collapsed selection already has a real MathLive caret.
|
|
266
|
+
if (!mathField.selectionIsCollapsed && mathField.selection) {
|
|
267
|
+
selected = mathField.getValue(mathField.selection, 'latex');
|
|
268
|
+
}
|
|
269
|
+
} catch (e) {
|
|
270
|
+
log('could not read the selection: %s', e && e.message);
|
|
271
|
+
}
|
|
272
|
+
if (mathField.classList) {
|
|
273
|
+
mathField.classList.toggle(PLACEHOLDER_CARET_CLASS, selected === PLACEHOLDER_LATEX);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
mathField.addEventListener('selection-change', update);
|
|
277
|
+
update();
|
|
278
|
+
return function () {
|
|
279
|
+
return mathField.removeEventListener('selection-change', update);
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Apply {@link SHADOW_CSS} inside a mathfield's shadow root.
|
|
285
|
+
*
|
|
286
|
+
* Uses `adoptedStyleSheets` when available (which is how MathLive loads its own
|
|
287
|
+
* stylesheets) and falls back to appending a <style> node.
|
|
288
|
+
*
|
|
289
|
+
* @param {HTMLElement} mathField
|
|
290
|
+
*/
|
|
291
|
+
var applyShadowStyles = exports.applyShadowStyles = function applyShadowStyles(mathField) {
|
|
292
|
+
var root = mathField && mathField.shadowRoot;
|
|
293
|
+
if (!root) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
if ('adoptedStyleSheets' in root && typeof CSSStyleSheet !== 'undefined') {
|
|
298
|
+
// Do not re-add on a re-render.
|
|
299
|
+
if (root.__pieAccentSheet) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
var sheet = new CSSStyleSheet();
|
|
303
|
+
sheet.replaceSync(SHADOW_CSS);
|
|
304
|
+
root.adoptedStyleSheets = [].concat((0, _toConsumableArray2["default"])(root.adoptedStyleSheets), [sheet]);
|
|
305
|
+
root.__pieAccentSheet = sheet;
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (!root.querySelector('style[data-pie-accent]')) {
|
|
309
|
+
var style = document.createElement('style');
|
|
310
|
+
style.setAttribute('data-pie-accent', '');
|
|
311
|
+
style.textContent = SHADOW_CSS;
|
|
312
|
+
root.appendChild(style);
|
|
313
|
+
}
|
|
314
|
+
} catch (e) {
|
|
315
|
+
log('could not apply shadow styles to the mathfield: %s', e && e.message);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
158
319
|
/**
|
|
159
320
|
* Ensure MathLive's "core" stylesheet is in the document.
|
|
160
321
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mathlive-instance.js","names":["_debug","_interopRequireDefault","require","_latexBridge","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","configureFonts","exports","MathfieldElement","PIE_MACROS","parallelogram","napprox","nsim","ncong","nparallel","perpendicular","divide","degree","square","longdiv","overarc","abs","embeds","Map","KNOWN_EMBED_LATEX","newLine","answerBlock","loadWarned","configureLoaded","undefined","injectCoreStylesheet","renderMathInElement","createElement","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","concat","registerEmbed","factory","definition","prototype","mathliveLatex","registeredEmbeds","Array","from","__resetEmbeds","clear","__setMathLiveForTest","stub","applyStaticMath","element","options","source","textContent","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';\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 * Tell the package where the MathLive fonts are served from.\n *\n * Call before `loadMathLive()`. Accepts an absolute URL, a root-relative path\n * (`/mathlive-fonts`) or a relative one; pass `null` to skip font loading and\n * fall back to system fonts.\n *\n * The fonts ship inside the `mathlive` package (`node_modules/mathlive/fonts`)\n * and must be copied 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 = absoluteFontsDirectory(dir);\n }\n};\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 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. Either point at the host app's copy or\n // disable font loading, both of which are safe.\n if (fontsDirectory === undefined) {\n log(\n 'no fontsDirectory configured - MathLive will use fallback fonts. ' +\n 'Call configureFonts(\"/path/to/fonts\") with a copy of node_modules/mathlive/fonts to enable them.',\n );\n }\n\n mathlive.MathfieldElement.fontsDirectory =\n fontsDirectory === undefined ? null : absoluteFontsDirectory(fontsDirectory);\n\n injectCoreStylesheet();\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;AAAkF,SAAAE,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,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,aAAAhB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAE,MAAA,CAAAc,yBAAA,GAAAd,MAAA,CAAAe,gBAAA,CAAAlB,CAAA,EAAAG,MAAA,CAAAc,yBAAA,CAAAf,CAAA,KAAAH,OAAA,CAAAI,MAA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pD,CAAC,CAAC;EAEF,OAAOX,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASY,aAAaA,CAAC3B,KAAK,EAAgB;EAAA,IAAdgB,OAAO,GAAAzG,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAwD,SAAA,GAAAxD,SAAA,MAAG,CAAC,CAAC;EAC/C;EACA;EACA,IAAM4G,EAAE,GAAGxB,WAAW,CAAC,CAAC,IAAIxB,gBAAgB,CAAC,CAAC;EAE9C,IAAI,CAACgD,EAAE,IAAI,CAACnB,KAAK,EAAE;IACjB,OAAO,EAAE;EACX;EAEA,IAAI;IACF;IACA;IACA;IACA,OAAOmB,EAAE,CAACI,oBAAoB,CAAC,IAAAC,kCAAqB,EAAC,IAAAC,uBAAU,EAACzB,KAAK,CAAC,CAAC,EAAA1F,aAAA;MACrEoH,MAAM,EAAApH,aAAA,CAAAA,aAAA,KAAOsF,SAAS,CAAC,CAAC,GAAMoB,OAAO,CAACU,MAAM,IAAI,CAAC,CAAC;IAAG,GAClDV,OAAO,CACX,CAAC;EACJ,CAAC,CAAC,OAAOtH,CAAC,EAAE;IACVkC,GAAG,CAAC,0CAA0C,EAAEoE,KAAK,EAAEtG,CAAC,CAAC6C,OAAO,CAAC;IACjE,OAAO,EAAE;EACX;AACF","ignoreList":[]}
|
|
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","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","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 } 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 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}' + ROOT_INDEX_CSS + 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 };\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,OAAO,EAAE;EACX;AACF","ignoreList":[]}
|
package/lib/mf/common-styles.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.supsubStyles = exports.placeholderStyles = exports.longdivStyles = exports["default"] = exports.commonMqKeyboardStyles = exports.commonMqFontStyles = exports.commonMathLiveStyles = exports.commonKeyboardStyles = void 0;
|
|
7
|
+
exports.supsubStyles = exports.rootIndexStyles = exports.placeholderStyles = exports.longdivStyles = exports["default"] = exports.commonMqKeyboardStyles = exports.commonMqFontStyles = exports.commonMathLiveStyles = exports.commonKeyboardStyles = exports.ROOT_INDEX_CSS = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
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; }
|
|
10
10
|
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; }
|
|
@@ -23,7 +23,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
23
23
|
* Most are intentionally near-empty: MathLive sizes scripts, radicals and
|
|
24
24
|
* fences correctly on its own, so the MathQuill-era corrections are not needed.
|
|
25
25
|
* They stay as documented extension points rather than being deleted, so the
|
|
26
|
-
* destructuring above keeps working.
|
|
26
|
+
* destructuring above keeps working. The exception is the radical index, which
|
|
27
|
+
* MathLive sizes to TeX metrics that read too small here - see
|
|
28
|
+
* `rootIndexStyles`.
|
|
27
29
|
*/
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -50,10 +52,42 @@ var longdivStyles = exports.longdivStyles = {
|
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
+
* How the index of a radical is sized.
|
|
56
|
+
*
|
|
57
|
+
* MathLive follows TeX and sets the index of `\sqrt[n]{x}` in scriptscriptstyle,
|
|
58
|
+
* which it emits as an inline `font-size: 50%` on the span wrapping the index's
|
|
59
|
+
* glyphs. At authoring sizes that leaves the index - on the nth-root key, and in
|
|
60
|
+
* any radical the author types - too small to read next to the radicand, so it is
|
|
61
|
+
* scaled up to 80% - 1.6x what MathLive asks for.
|
|
62
|
+
*
|
|
63
|
+
* Only that innermost span is resized. `.ML__sqrt-index` itself keeps its font
|
|
64
|
+
* size on purpose: the vlist inside it tucks the index into the radical's crook
|
|
65
|
+
* with em-based `top`/`height` offsets, and scaling those lifts the index clear
|
|
66
|
+
* of the radical instead of just enlarging it.
|
|
67
|
+
*
|
|
68
|
+
* The child chain is spelled out so that nothing nested deeper inside the index
|
|
69
|
+
* (a fraction's numerator, another radical) is caught by the same rule, and
|
|
70
|
+
* `!important` is required because the 50% is an INLINE style.
|
|
71
|
+
*/
|
|
72
|
+
var ROOT_INDEX_SELECTOR = '.ML__sqrt-index > .ML__vlist-t > .ML__vlist-r > .ML__vlist > span > [style*="font-size"]';
|
|
73
|
+
var ROOT_INDEX_FONT_SIZE = '80%';
|
|
74
|
+
var rootIndexStyles = exports.rootIndexStyles = (0, _defineProperty2["default"])({}, "& ".concat(ROOT_INDEX_SELECTOR), {
|
|
75
|
+
fontSize: "".concat(ROOT_INDEX_FONT_SIZE, " !important")
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The same rule as a CSS string, for a live mathfield's shadow root - see
|
|
80
|
+
* `SHADOW_CSS` in mathlive-instance.js. Static markup is styled by
|
|
81
|
+
* {@link rootIndexStyles}.
|
|
82
|
+
*/
|
|
83
|
+
var ROOT_INDEX_CSS = exports.ROOT_INDEX_CSS = "".concat(ROOT_INDEX_SELECTOR, "{font-size:").concat(ROOT_INDEX_FONT_SIZE, " !important}");
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Superscript/subscript sizing. MathLive follows TeX metrics for scripts, so the
|
|
87
|
+
* MathQuill-era corrections are gone; the radical index is the one place where a
|
|
88
|
+
* TeX-correct size reads too small in the authoring UI.
|
|
55
89
|
*/
|
|
56
|
-
var supsubStyles = exports.supsubStyles = {};
|
|
90
|
+
var supsubStyles = exports.supsubStyles = _objectSpread({}, rootIndexStyles);
|
|
57
91
|
|
|
58
92
|
/** Empty placeholder boxes (answer blocks / open slots). */
|
|
59
93
|
var placeholderStyles = exports.placeholderStyles = {
|
|
@@ -67,12 +101,41 @@ var placeholderStyles = exports.placeholderStyles = {
|
|
|
67
101
|
'& [data-pie-empty]': {
|
|
68
102
|
opacity: 0.5
|
|
69
103
|
},
|
|
70
|
-
// Stretchy accents
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
|
|
104
|
+
// Stretchy accents (\overarc, \overleftrightarrow, \overrightarrow) render an
|
|
105
|
+
// <svg width="100%" preserveAspectRatio="none"> inside a `.ML__stretchy`. That
|
|
106
|
+
// span is absolutely positioned, so its immediate wrapper computes to 0px and
|
|
107
|
+
// the width has to resolve against a *positioned* ancestor. Pin that to
|
|
108
|
+
// `.ML__base`, whose width already equals the accent's content (measured:
|
|
109
|
+
// 9.85px for a 0.56em slot), so the arc spans exactly its content.
|
|
110
|
+
//
|
|
111
|
+
// Do NOT write a bare `& svg` rule instead: MathLive's own rule is
|
|
112
|
+
// descendant-scoped (`.ML__latex .ML__stretchy svg`), and a global one
|
|
113
|
+
// re-parents every svg in the subtree.
|
|
114
|
+
'& .ML__base': {
|
|
115
|
+
position: 'relative'
|
|
116
|
+
},
|
|
117
|
+
'& .ML__stretchy': {
|
|
74
118
|
position: 'absolute',
|
|
119
|
+
left: 0,
|
|
75
120
|
width: '100%'
|
|
121
|
+
},
|
|
122
|
+
// MathLive centres an accent by shifting it right half the content width -
|
|
123
|
+
// `margin-left: 0.28em` for a 0.56em slot - which assumes a glyph with its own
|
|
124
|
+
// side bearings. Over a synthetic empty slot it just pushes the arc right.
|
|
125
|
+
//
|
|
126
|
+
// `!important` is required: MathLive writes this as an INLINE style
|
|
127
|
+
// (`style="top:-3.4em;margin-left:0.28em"`), which a class cannot override.
|
|
128
|
+
//
|
|
129
|
+
// It also fixes the width. `.ML__center` is the stretchy's containing block
|
|
130
|
+
// (MathLive gives `.ML__vlist > span` position:relative), and its width is the
|
|
131
|
+
// base minus that margin - measured 9.85px - 4.93px = 4.93px, exactly half,
|
|
132
|
+
// which is why the arc came out half-width AND offset right.
|
|
133
|
+
//
|
|
134
|
+
// Scoped with `:has(.ML__stretchy)`: only stretchy accents are affected.
|
|
135
|
+
// A single-glyph accent (`\hat{x}`, `\vec{x}`) genuinely needs its centring
|
|
136
|
+
// offset, and must keep it.
|
|
137
|
+
'& .ML__center:has(.ML__stretchy)': {
|
|
138
|
+
marginLeft: '0 !important'
|
|
76
139
|
}
|
|
77
140
|
};
|
|
78
141
|
|
|
@@ -80,7 +143,7 @@ var placeholderStyles = exports.placeholderStyles = {
|
|
|
80
143
|
* Styling for the on-screen keyboard and any container rendering math labels.
|
|
81
144
|
* Also hides MathLive's own affordances, since pie supplies its own keypad.
|
|
82
145
|
*/
|
|
83
|
-
var commonMqKeyboardStyles = exports.commonMqKeyboardStyles = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, commonMqFontStyles), longdivStyles), placeholderStyles), {}, {
|
|
146
|
+
var commonMqKeyboardStyles = exports.commonMqKeyboardStyles = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, commonMqFontStyles), longdivStyles), rootIndexStyles), placeholderStyles), {}, {
|
|
84
147
|
touchAction: 'manipulation',
|
|
85
148
|
'& math-field': {
|
|
86
149
|
fontSize: 'inherit',
|
|
@@ -116,6 +179,7 @@ var commonKeyboardStyles = exports.commonKeyboardStyles = commonMqKeyboardStyles
|
|
|
116
179
|
var _default = exports["default"] = {
|
|
117
180
|
commonMqFontStyles: commonMqFontStyles,
|
|
118
181
|
longdivStyles: longdivStyles,
|
|
182
|
+
rootIndexStyles: rootIndexStyles,
|
|
119
183
|
supsubStyles: supsubStyles,
|
|
120
184
|
commonMqKeyboardStyles: commonMqKeyboardStyles,
|
|
121
185
|
placeholderStyles: placeholderStyles,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-styles.js","names":["commonMqFontStyles","exports","fontFamily","longdivStyles","display","supsubStyles","placeholderStyles","borderBottom","minWidth","opacity","position","width","commonMqKeyboardStyles","_objectSpread","touchAction","fontSize","outline","commonMathLiveStyles","commonKeyboardStyles","_default"],"sources":["../../src/mf/common-styles.js"],"sourcesContent":["/**\n * Shared MathLive styling.\n *\n * Replaces @pie-lib/math-input's `common-mq-styles.js`. That file was built\n * around MathQuill's `.mq-*` class names, none of which exist in MathLive\n * output, so the selectors here target MathLive's own structure instead.\n *\n * The four named groups are kept because consumers destructure them:\n *\n * const { commonMqFontStyles, commonMqKeyboardStyles, longdivStyles, supsubStyles }\n * = mq.CommonMqStyles; // math-toolbar/src/editor-and-pad.jsx, math-preview.jsx\n *\n * Most are intentionally near-empty: MathLive sizes scripts, radicals and\n * fences correctly on its own, so the MathQuill-era corrections are not needed.\n * They stay as documented extension points rather than being deleted, so the\n * destructuring above keeps working.\n */\n\n/**\n * Font styling. MathQuill needed explicit MathJax font families to match the\n * static renderer; MathLive ships the KaTeX fonts it renders with, so this only\n * smooths rendering and lets the host override the family.\n */\nexport const commonMqFontStyles = {\n '-webkit-font-smoothing': 'antialiased',\n '& math-field': {\n fontFamily: 'inherit',\n },\n};\n\n/**\n * Long division. The MathQuill fork drew this with nested `.mq-longdiv-*`\n * elements that needed manual offsets; here it comes from the `\\longdiv` macro\n * (see `PIE_MACROS`), tagged with `data-pie-macro=\"longdiv\"`.\n */\nexport const longdivStyles = {\n '& [data-pie-macro=\"longdiv\"]': {\n display: 'inline-flex',\n },\n};\n\n/**\n * Superscript/subscript sizing. MathLive follows TeX metrics, so no overrides\n * are required.\n */\nexport const supsubStyles = {};\n\n/** Empty placeholder boxes (answer blocks / open slots). */\nexport const placeholderStyles = {\n '& .ML__placeholder': {\n borderBottom: '1px solid currentColor',\n minWidth: '1em',\n },\n // Stand-in glyph for an empty argument slot in STATIC math (see\n // `withVisibleEmptySlots`). Muted so it reads as \"a slot goes here\" rather\n // than as part of the symbol, matching how MathQuill shaded `.mq-empty`.\n '& [data-pie-empty]': {\n opacity: 0.5,\n },\n // Stretchy accents render an <svg>; mathlive-static.css positions it\n // absolutely at width:100%. Repeated here so static math cannot blow out its\n // container if that stylesheet is missing.\n '& svg': {\n position: 'absolute',\n width: '100%',\n },\n};\n\n/**\n * Styling for the on-screen keyboard and any container rendering math labels.\n * Also hides MathLive's own affordances, since pie supplies its own keypad.\n */\nexport const commonMqKeyboardStyles = {\n ...commonMqFontStyles,\n ...longdivStyles,\n ...placeholderStyles,\n touchAction: 'manipulation',\n '& math-field': {\n fontSize: 'inherit',\n outline: 'none',\n },\n '& math-field::part(virtual-keyboard-toggle)': {\n display: 'none',\n },\n '& math-field::part(menu-toggle)': {\n display: 'none',\n },\n};\n\n/** Everything combined - the common case for a container of math. */\nexport const commonMathLiveStyles = {\n ...commonMqFontStyles,\n ...longdivStyles,\n ...supsubStyles,\n ...placeholderStyles,\n '& math-field': {\n fontSize: 'inherit',\n outline: 'none',\n },\n '& math-field::part(virtual-keyboard-toggle)': {\n display: 'none',\n },\n '& math-field::part(menu-toggle)': {\n display: 'none',\n },\n};\n\nexport const commonKeyboardStyles = commonMqKeyboardStyles;\n\n/**\n * Default export mirrors @pie-lib/math-input's `CommonMqStyles` object so\n * existing destructuring keeps working.\n */\nexport default {\n commonMqFontStyles,\n longdivStyles,\n supsubStyles,\n commonMqKeyboardStyles,\n placeholderStyles,\n commonMathLiveStyles,\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,IAAMA,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAG;EAChC,wBAAwB,EAAE,aAAa;EACvC,cAAc,EAAE;IACdE,UAAU,EAAE;EACd;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACO,IAAMC,aAAa,GAAAF,OAAA,CAAAE,aAAA,GAAG;EAC3B,8BAA8B,EAAE;IAC9BC,OAAO,EAAE;EACX;AACF,CAAC;;AAED;AACA;AACA;AACA;AACO,IAAMC,YAAY,GAAAJ,OAAA,CAAAI,YAAA,GAAG,CAAC,CAAC;;AAE9B;AACO,IAAMC,iBAAiB,GAAAL,OAAA,CAAAK,iBAAA,GAAG;EAC/B,oBAAoB,EAAE;IACpBC,YAAY,EAAE,wBAAwB;IACtCC,QAAQ,EAAE;EACZ,CAAC;EACD;EACA;EACA;EACA,oBAAoB,EAAE;IACpBC,OAAO,EAAE;EACX,CAAC;EACD;EACA;EACA;EACA,OAAO,EAAE;IACPC,QAAQ,EAAE,UAAU;IACpBC,KAAK,EAAE;EACT;AACF,CAAC;;AAED;AACA;AACA;AACA;AACO,IAAMC,sBAAsB,GAAAX,OAAA,CAAAW,sBAAA,GAAAC,aAAA,CAAAA,aAAA,CAAAA,aAAA,CAAAA,aAAA,KAC9Bb,kBAAkB,GAClBG,aAAa,GACbG,iBAAiB;EACpBQ,WAAW,EAAE,cAAc;EAC3B,cAAc,EAAE;IACdC,QAAQ,EAAE,SAAS;IACnBC,OAAO,EAAE;EACX,CAAC;EACD,6CAA6C,EAAE;IAC7CZ,OAAO,EAAE;EACX,CAAC;EACD,iCAAiC,EAAE;IACjCA,OAAO,EAAE;EACX;AAAC,EACF;;AAED;AACO,IAAMa,oBAAoB,GAAAhB,OAAA,CAAAgB,oBAAA,GAAAJ,aAAA,CAAAA,aAAA,CAAAA,aAAA,CAAAA,aAAA,CAAAA,aAAA,KAC5Bb,kBAAkB,GAClBG,aAAa,GACbE,YAAY,GACZC,iBAAiB;EACpB,cAAc,EAAE;IACdS,QAAQ,EAAE,SAAS;IACnBC,OAAO,EAAE;EACX,CAAC;EACD,6CAA6C,EAAE;IAC7CZ,OAAO,EAAE;EACX,CAAC;EACD,iCAAiC,EAAE;IACjCA,OAAO,EAAE;EACX;AAAC,EACF;AAEM,IAAMc,oBAAoB,GAAAjB,OAAA,CAAAiB,oBAAA,GAAGN,sBAAsB;;AAE1D;AACA;AACA;AACA;AAHA,IAAAO,QAAA,GAAAlB,OAAA,cAIe;EACbD,kBAAkB,EAAlBA,kBAAkB;EAClBG,aAAa,EAAbA,aAAa;EACbE,YAAY,EAAZA,YAAY;EACZO,sBAAsB,EAAtBA,sBAAsB;EACtBN,iBAAiB,EAAjBA,iBAAiB;EACjBW,oBAAoB,EAApBA;AACF,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"common-styles.js","names":["commonMqFontStyles","exports","fontFamily","longdivStyles","display","ROOT_INDEX_SELECTOR","ROOT_INDEX_FONT_SIZE","rootIndexStyles","_defineProperty2","concat","fontSize","ROOT_INDEX_CSS","supsubStyles","_objectSpread","placeholderStyles","borderBottom","minWidth","opacity","position","left","width","marginLeft","commonMqKeyboardStyles","touchAction","outline","commonMathLiveStyles","commonKeyboardStyles","_default"],"sources":["../../src/mf/common-styles.js"],"sourcesContent":["/**\n * Shared MathLive styling.\n *\n * Replaces @pie-lib/math-input's `common-mq-styles.js`. That file was built\n * around MathQuill's `.mq-*` class names, none of which exist in MathLive\n * output, so the selectors here target MathLive's own structure instead.\n *\n * The four named groups are kept because consumers destructure them:\n *\n * const { commonMqFontStyles, commonMqKeyboardStyles, longdivStyles, supsubStyles }\n * = mq.CommonMqStyles; // math-toolbar/src/editor-and-pad.jsx, math-preview.jsx\n *\n * Most are intentionally near-empty: MathLive sizes scripts, radicals and\n * fences correctly on its own, so the MathQuill-era corrections are not needed.\n * They stay as documented extension points rather than being deleted, so the\n * destructuring above keeps working. The exception is the radical index, which\n * MathLive sizes to TeX metrics that read too small here - see\n * `rootIndexStyles`.\n */\n\n/**\n * Font styling. MathQuill needed explicit MathJax font families to match the\n * static renderer; MathLive ships the KaTeX fonts it renders with, so this only\n * smooths rendering and lets the host override the family.\n */\nexport const commonMqFontStyles = {\n '-webkit-font-smoothing': 'antialiased',\n '& math-field': {\n fontFamily: 'inherit',\n },\n};\n\n/**\n * Long division. The MathQuill fork drew this with nested `.mq-longdiv-*`\n * elements that needed manual offsets; here it comes from the `\\longdiv` macro\n * (see `PIE_MACROS`), tagged with `data-pie-macro=\"longdiv\"`.\n */\nexport const longdivStyles = {\n '& [data-pie-macro=\"longdiv\"]': {\n display: 'inline-flex',\n },\n};\n\n/**\n * How the index of a radical is sized.\n *\n * MathLive follows TeX and sets the index of `\\sqrt[n]{x}` in scriptscriptstyle,\n * which it emits as an inline `font-size: 50%` on the span wrapping the index's\n * glyphs. At authoring sizes that leaves the index - on the nth-root key, and in\n * any radical the author types - too small to read next to the radicand, so it is\n * scaled up to 80% - 1.6x what MathLive asks for.\n *\n * Only that innermost span is resized. `.ML__sqrt-index` itself keeps its font\n * size on purpose: the vlist inside it tucks the index into the radical's crook\n * with em-based `top`/`height` offsets, and scaling those lifts the index clear\n * of the radical instead of just enlarging it.\n *\n * The child chain is spelled out so that nothing nested deeper inside the index\n * (a fraction's numerator, another radical) is caught by the same rule, and\n * `!important` is required because the 50% is an INLINE style.\n */\nconst ROOT_INDEX_SELECTOR = '.ML__sqrt-index > .ML__vlist-t > .ML__vlist-r > .ML__vlist > span > [style*=\"font-size\"]';\nconst ROOT_INDEX_FONT_SIZE = '80%';\n\nexport const rootIndexStyles = {\n [`& ${ROOT_INDEX_SELECTOR}`]: {\n fontSize: `${ROOT_INDEX_FONT_SIZE} !important`,\n },\n};\n\n/**\n * The same rule as a CSS string, for a live mathfield's shadow root - see\n * `SHADOW_CSS` in mathlive-instance.js. Static markup is styled by\n * {@link rootIndexStyles}.\n */\nexport const ROOT_INDEX_CSS = `${ROOT_INDEX_SELECTOR}{font-size:${ROOT_INDEX_FONT_SIZE} !important}`;\n\n/**\n * Superscript/subscript sizing. MathLive follows TeX metrics for scripts, so the\n * MathQuill-era corrections are gone; the radical index is the one place where a\n * TeX-correct size reads too small in the authoring UI.\n */\nexport const supsubStyles = {\n ...rootIndexStyles,\n};\n\n/** Empty placeholder boxes (answer blocks / open slots). */\nexport const placeholderStyles = {\n '& .ML__placeholder': {\n borderBottom: '1px solid currentColor',\n minWidth: '1em',\n },\n // Stand-in glyph for an empty argument slot in STATIC math (see\n // `withVisibleEmptySlots`). Muted so it reads as \"a slot goes here\" rather\n // than as part of the symbol, matching how MathQuill shaded `.mq-empty`.\n '& [data-pie-empty]': {\n opacity: 0.5,\n },\n // Stretchy accents (\\overarc, \\overleftrightarrow, \\overrightarrow) render an\n // <svg width=\"100%\" preserveAspectRatio=\"none\"> inside a `.ML__stretchy`. That\n // span is absolutely positioned, so its immediate wrapper computes to 0px and\n // the width has to resolve against a *positioned* ancestor. Pin that to\n // `.ML__base`, whose width already equals the accent's content (measured:\n // 9.85px for a 0.56em slot), so the arc spans exactly its content.\n //\n // Do NOT write a bare `& svg` rule instead: MathLive's own rule is\n // descendant-scoped (`.ML__latex .ML__stretchy svg`), and a global one\n // re-parents every svg in the subtree.\n '& .ML__base': {\n position: 'relative',\n },\n '& .ML__stretchy': {\n position: 'absolute',\n left: 0,\n width: '100%',\n },\n // MathLive centres an accent by shifting it right half the content width -\n // `margin-left: 0.28em` for a 0.56em slot - which assumes a glyph with its own\n // side bearings. Over a synthetic empty slot it just pushes the arc right.\n //\n // `!important` is required: MathLive writes this as an INLINE style\n // (`style=\"top:-3.4em;margin-left:0.28em\"`), which a class cannot override.\n //\n // It also fixes the width. `.ML__center` is the stretchy's containing block\n // (MathLive gives `.ML__vlist > span` position:relative), and its width is the\n // base minus that margin - measured 9.85px - 4.93px = 4.93px, exactly half,\n // which is why the arc came out half-width AND offset right.\n //\n // Scoped with `:has(.ML__stretchy)`: only stretchy accents are affected.\n // A single-glyph accent (`\\hat{x}`, `\\vec{x}`) genuinely needs its centring\n // offset, and must keep it.\n '& .ML__center:has(.ML__stretchy)': {\n marginLeft: '0 !important',\n },\n};\n\n/**\n * Styling for the on-screen keyboard and any container rendering math labels.\n * Also hides MathLive's own affordances, since pie supplies its own keypad.\n */\nexport const commonMqKeyboardStyles = {\n ...commonMqFontStyles,\n ...longdivStyles,\n ...rootIndexStyles,\n ...placeholderStyles,\n touchAction: 'manipulation',\n '& math-field': {\n fontSize: 'inherit',\n outline: 'none',\n },\n '& math-field::part(virtual-keyboard-toggle)': {\n display: 'none',\n },\n '& math-field::part(menu-toggle)': {\n display: 'none',\n },\n};\n\n/** Everything combined - the common case for a container of math. */\nexport const commonMathLiveStyles = {\n ...commonMqFontStyles,\n ...longdivStyles,\n ...supsubStyles,\n ...placeholderStyles,\n '& math-field': {\n fontSize: 'inherit',\n outline: 'none',\n },\n '& math-field::part(virtual-keyboard-toggle)': {\n display: 'none',\n },\n '& math-field::part(menu-toggle)': {\n display: 'none',\n },\n};\n\nexport const commonKeyboardStyles = commonMqKeyboardStyles;\n\n/**\n * Default export mirrors @pie-lib/math-input's `CommonMqStyles` object so\n * existing destructuring keeps working.\n */\nexport default {\n commonMqFontStyles,\n longdivStyles,\n rootIndexStyles,\n supsubStyles,\n commonMqKeyboardStyles,\n placeholderStyles,\n commonMathLiveStyles,\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,IAAMA,kBAAkB,GAAA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|
@@ -59,6 +59,12 @@ Object.defineProperty(exports, "placeholderStyles", {
|
|
|
59
59
|
return _commonStyles.placeholderStyles;
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
+
Object.defineProperty(exports, "rootIndexStyles", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function get() {
|
|
65
|
+
return _commonStyles.rootIndexStyles;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
62
68
|
Object.defineProperty(exports, "supsubStyles", {
|
|
63
69
|
enumerable: true,
|
|
64
70
|
get: function get() {
|
package/lib/mf/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_input","_interopRequireDefault","require","_static","_commonStyles","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor"],"sources":["../../src/mf/index.js"],"sourcesContent":["import Input from './input';\nimport Static from './static';\nimport CommonMqStyles, {\n commonMathLiveStyles,\n commonKeyboardStyles,\n commonMqFontStyles,\n commonMqKeyboardStyles,\n longdivStyles,\n supsubStyles,\n placeholderStyles,\n} from './common-styles';\n\nexport {\n Input,\n Static,\n // Same object shape as @pie-lib/math-input's `mq.CommonMqStyles`, so\n // `const { commonMqFontStyles, ... } = mq.CommonMqStyles` keeps working.\n CommonMqStyles,\n commonMathLiveStyles,\n commonKeyboardStyles,\n commonMqFontStyles,\n commonMqKeyboardStyles,\n longdivStyles,\n supsubStyles,\n placeholderStyles,\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_input","_interopRequireDefault","require","_static","_commonStyles","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor"],"sources":["../../src/mf/index.js"],"sourcesContent":["import Input from './input';\nimport Static from './static';\nimport CommonMqStyles, {\n commonMathLiveStyles,\n commonKeyboardStyles,\n commonMqFontStyles,\n commonMqKeyboardStyles,\n longdivStyles,\n rootIndexStyles,\n supsubStyles,\n placeholderStyles,\n} from './common-styles';\n\nexport {\n Input,\n Static,\n // Same object shape as @pie-lib/math-input's `mq.CommonMqStyles`, so\n // `const { commonMqFontStyles, ... } = mq.CommonMqStyles` keeps working.\n CommonMqStyles,\n commonMathLiveStyles,\n commonKeyboardStyles,\n commonMqFontStyles,\n commonMqKeyboardStyles,\n longdivStyles,\n rootIndexStyles,\n supsubStyles,\n placeholderStyles,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,aAAA,GAAAC,uBAAA,CAAAH,OAAA;AASyB,SAAAG,wBAAAC,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAH,uBAAA,YAAAA,wBAAAC,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,mBAAAT,CAAA,iBAAAA,CAAA,gBAAAU,OAAA,CAAAV,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,cAAAM,EAAA,IAAAd,CAAA,gBAAAc,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,EAAA,OAAAP,CAAA,IAA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