@pie-lib/math-input-mathlive 1.1.5-beta.14 → 1.1.5-beta.15

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.
@@ -1 +1 @@
1
- {"version":3,"file":"mathlive-instance.js","names":["_debug","_interopRequireDefault","require","_latexBridge","_commonStyles","_longdiv","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","OVERLINE_BAR_MASK","OVERLINE_LIFT","OVERLINE_GAP_CSS","FRAC_BAR_CENTER_CSS","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","fixLongDivisionWhenReady","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';\nimport { fixLongDivisionWhenReady } from './longdiv';\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// MathLive sets the bar of `\\overline{}` lower than the shafts of the ray and line\n// arrows (stretchy accents), and its strut is shorter than theirs, which also\n// shifts the whole field vertically as the font grows. The bar is raised to the\n// shaft height (measured in a live <math-field> at 14-24px), drawn once at the\n// shafts' 0.04em, and the strut matches the arrows' (1.37em).\nconst OVERLINE_BAR_MASK =\n 'url(\"data:image/svg+xml,%3Csvg xmlns=\\'http://www.w3.org/2000/svg\\' viewBox=\\'0 0 100 522\\' preserveAspectRatio=\\'none\\'%3E' +\n '%3Crect y=\\'241\\' width=\\'100\\' height=\\'40\\'/%3E%3C/svg%3E\") 0 0/100% 100% no-repeat';\n\nconst OVERLINE_LIFT = '-0.06em';\n\nconst OVERLINE_GAP_CSS =\n '.ML__latex .overline>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>.overline-line){top:-4.07em !important}' +\n // ...and its bar ~0.03em lower than the arrows' shafts.\n '.ML__latex .overline:has(>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span>span[style*=\"height:0.9em\"])>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>.overline-line){top:-4.1em !important}' +\n // The bar and box move up together as one unit (the live field only; the keypad is fine).\n `.ML__latex .overline{position:relative;top:${OVERLINE_LIFT}}` +\n // An empty slot's box (0.9em tall, against 0.65em for text) ends up ~0.03em higher than in the arrows.\n '.ML__latex .overline>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>span[style*=\"height:0.9em\"]){top:-2.97em !important}' +\n // The bar is a CSS border, which the browser snaps to whole device pixels, so it\n // renders crisper than the arrows' antialiased SVG shafts. Draw it the same way: a\n // mask with the shaft's geometry (y 241-281 of a 522-high box), centred on the\n // bar's own position.\n `.ML__latex .overline .overline-line{position:relative}` +\n `.ML__latex .overline .overline-line:before{content:\"\";display:block;position:absolute;left:0;right:0;top:-0.241em;` +\n `height:0.522em !important;border:0 !important;background:currentColor;` +\n `-webkit-mask:${OVERLINE_BAR_MASK};mask:${OVERLINE_BAR_MASK}}` +\n '.ML__latex .overline .overline-line:after{display:none !important}' +\n '.ML__latex:has(.overline)>.ML__strut{height:1.37em !important}';\n\n// MathLive spaces a fraction's bar for text glyphs, whose ink sits tight against\n// the baseline. An empty slot's box (`▢`) hangs lower than that, so the bar ends\n// up much nearer the denominator's box than the numerator's (measured ~0.28em vs\n// ~0.11em). Dropping the bar 0.08em evens the two gaps. Layout is untouched, so\n// the numerator and denominator keep their positions; filled fractions (`1/2`)\n// only see the bar move a hair.\nconst FRAC_BAR_CENTER_CSS = '.ML__latex .ML__frac-line{position:relative;top:0.08em}';\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 OVERLINE_GAP_CSS +\n FRAC_BAR_CENTER_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 // MathLive misdraws long division (see longdiv.js).\n fixLongDivisionWhenReady(element);\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\":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AAAlJ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAwC,SAAA,GAAAxC,SAAA,MAAG,CAAC,CAAC;EAC/C;EACA;EACA,IAAMoJ,EAAE,GAAGtB,WAAW,CAAC,CAAC,IAAIxB,gBAAgB,CAAC,CAAC;EAE9C,IAAI,CAAC8C,EAAE,IAAI,CAACjB,KAAK,EAAE;IACjB,OAAO,EAAE;EACX;EAEA,IAAI;IACF;IACA;IACA;IACA,OAAOiB,EAAE,CAACI,oBAAoB,CAAC,IAAAC,kCAAqB,EAAC,IAAAC,uBAAU,EAACvB,KAAK,CAAC,CAAC,EAAApI,aAAA;MACrE4J,MAAM,EAAA5J,aAAA,CAAAA,aAAA,KAAOgI,SAAS,CAAC,CAAC,GAAMmB,OAAO,CAACS,MAAM,IAAI,CAAC,CAAC;IAAG,GAClDT,OAAO,CACX,CAAC;EACJ,CAAC,CAAC,OAAO/J,CAAC,EAAE;IACVkC,GAAG,CAAC,0CAA0C,EAAE8G,KAAK,EAAEhJ,CAAC,CAAC6C,OAAO,CAAC;IACjE,OAAO,EAAE;EACX;AACF","ignoreList":[]}
1
+ {"version":3,"file":"mathlive-instance.js","names":["_debug","_interopRequireDefault","require","_latexBridge","_commonStyles","_longdiv","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","OVERLINE_BAR_MASK","OVERLINE_LIFT","OVERLINE_GAP_CSS","FRAC_BAR_CENTER_CSS","FRAC_BAR_FILLED_CSS","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","fixLongDivisionWhenReady","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';\nimport { fixLongDivisionWhenReady } from './longdiv';\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// MathLive sets the bar of `\\overline{}` lower than the shafts of the ray and line\n// arrows (stretchy accents), and its strut is shorter than theirs, which also\n// shifts the whole field vertically as the font grows. The bar is raised to the\n// shaft height (measured in a live <math-field> at 14-24px), drawn once at the\n// shafts' 0.04em, and the strut matches the arrows' (1.37em).\nconst OVERLINE_BAR_MASK =\n 'url(\"data:image/svg+xml,%3Csvg xmlns=\\'http://www.w3.org/2000/svg\\' viewBox=\\'0 0 100 522\\' preserveAspectRatio=\\'none\\'%3E' +\n '%3Crect y=\\'241\\' width=\\'100\\' height=\\'40\\'/%3E%3C/svg%3E\") 0 0/100% 100% no-repeat';\n\nconst OVERLINE_LIFT = '-0.06em';\n\nconst OVERLINE_GAP_CSS =\n '.ML__latex .overline>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>.overline-line){top:-4.07em !important}' +\n // ...and its bar ~0.03em lower than the arrows' shafts.\n '.ML__latex .overline:has(>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span>span[style*=\"height:0.9em\"])>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>.overline-line){top:-4.1em !important}' +\n // The bar and box move up together as one unit (the live field only; the keypad is fine).\n `.ML__latex .overline{position:relative;top:${OVERLINE_LIFT}}` +\n // An empty slot's box (0.9em tall, against 0.65em for text) ends up ~0.03em higher than in the arrows.\n '.ML__latex .overline>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>span[style*=\"height:0.9em\"]){top:-2.97em !important}' +\n // The bar is a CSS border, which the browser snaps to whole device pixels, so it\n // renders crisper than the arrows' antialiased SVG shafts. Draw it the same way: a\n // mask with the shaft's geometry (y 241-281 of a 522-high box), centred on the\n // bar's own position.\n `.ML__latex .overline .overline-line{position:relative}` +\n `.ML__latex .overline .overline-line:before{content:\"\";display:block;position:absolute;left:0;right:0;top:-0.241em;` +\n `height:0.522em !important;border:0 !important;background:currentColor;` +\n `-webkit-mask:${OVERLINE_BAR_MASK};mask:${OVERLINE_BAR_MASK}}` +\n '.ML__latex .overline .overline-line:after{display:none !important}' +\n '.ML__latex:has(.overline)>.ML__strut{height:1.37em !important}';\n\n// An empty slot is a `▢` glyph in a 0.9em-tall box, which hangs lower than the\n// ink of text, so MathLive's bar ends up much nearer the denominator's box than\n// the numerator's (measured at 100px: 24px above the bar, 9px below). Raising the\n// bar 0.025em evens the gaps (measured on screen at authoring size: 1px above, 2px below at -0.075em, so it moves back down). The denominator is the first `.ML__center`\n// (MathLive emits it first); only fractions with an empty denominator are touched,\n// because `▢ over 2` is already balanced and filled fractions are MathLive's own.\nconst FRAC_BAR_CENTER_CSS =\n '.ML__latex .ML__mfrac:has(.ML__vlist>.ML__center:first-child span[style*=\"height:0.9em\"]) .ML__frac-line' +\n '{position:relative;top:-0.025em}';\n\n// A filled fraction (`55/555`) has its bar ~0.075em nearer the numerator's digits\n// than the denominator's (measured at 40px: 8.5px above, 11.5px below); drop it 0.04em.\n// Fractions with an empty slot (a 0.9em-tall box) are handled above.\nconst FRAC_BAR_FILLED_CSS =\n '.ML__latex .ML__mfrac:not(:has(span[style*=\"height:0.9em\"])) .ML__frac-line{position:relative;top:0.04em}';\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 OVERLINE_GAP_CSS +\n FRAC_BAR_CENTER_CSS +\n FRAC_BAR_FILLED_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 // MathLive misdraws long division (see longdiv.js).\n fixLongDivisionWhenReady(element);\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;AACA,IAAAG,QAAA,GAAAH,OAAA;AAAqD,SAAAI,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,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AAI,CAACjB,KAAK,EAAE;IACjB,OAAO,EAAE;EACX;EAEA,IAAI;IACF;IACA;IACA;IACA,OAAOiB,EAAE,CAACI,oBAAoB,CAAC,IAAAC,kCAAqB,EAAC,IAAAC,uBAAU,EAACvB,KAAK,CAAC,CAAC,EAAArI,aAAA;MACrE6J,MAAM,EAAA7J,aAAA,CAAAA,aAAA,KAAOiI,SAAS,CAAC,CAAC,GAAMmB,OAAO,CAACS,MAAM,IAAI,CAAC,CAAC;IAAG,GAClDT,OAAO,CACX,CAAC;EACJ,CAAC,CAAC,OAAOhK,CAAC,EAAE;IACVkC,GAAG,CAAC,0CAA0C,EAAE+G,KAAK,EAAEjJ,CAAC,CAAC6C,OAAO,CAAC;IACjE,OAAO,EAAE;EACX;AACF","ignoreList":[]}
@@ -117,24 +117,33 @@ var placeholderStyles = exports.placeholderStyles = {
117
117
  '& [data-pie-empty]': {
118
118
  opacity: 0.5
119
119
  },
120
+ // A filled fraction (`55/555`): MathLive's bar sits ~0.075em nearer the numerator's
121
+ // digits than the denominator's (measured at 40px: 8.5px above, 11.5px below).
122
+ // Dropping the bar 0.04em evens the two gaps. Fractions with an empty slot have
123
+ // their own drop below, which is more specific and overrides this one.
124
+ '& .ML__mfrac:not(:has([data-pie-empty])) .ML__frac-line': {
125
+ position: 'relative',
126
+ top: '0.04em'
127
+ },
120
128
  // A fraction with an empty slot: MathLive spaces the bar for text, but the
121
- // slot's box is a taller `\rule`, so the bar hugs the numerator's box (~0.2em
122
- // above vs ~0.4em below). Dropping the bar 0.16em (0.13em when the numerator is not an empty slot or follows an `x`) centres it between the two
123
- // boxes. Only the bar moves, not the slots.
129
+ // slot's box is a taller `\rule`, so the bar hugs the numerator's box. Measured
130
+ // at 100px: dropping it 0.14em centres it between two boxes, and 0.13em between
131
+ // a real numerator (`x`, whose ink ends at the baseline) and an empty denominator.
132
+ // Only the bar moves, not the slots. The numerator is the second `.ML__center`
133
+ // (MathLive emits the denominator first).
124
134
  '& .ML__mfrac:has([data-pie-empty]) .ML__frac-line': {
125
135
  position: 'relative',
126
- top: '0.16em'
136
+ top: '0.14em'
127
137
  },
128
- // A real numerator (`x`) is lighter than an empty box and its ink ends at the
129
- // baseline, so the full drop overshoots: it needs a smaller drop. The numerator is
130
- // the second `.ML__center` (MathLive emits the denominator first).
131
138
  '& .ML__mfrac:has([data-pie-empty]):not(:has(.ML__center ~ .ML__center [data-pie-empty])) .ML__frac-line': {
132
139
  top: '0.13em'
133
140
  },
134
- // Same for a mixed number (`x` then the fraction): the leading `x` is a sibling
135
- // of the fraction, which a lone `\frac{}{}` does not have.
141
+ // A mixed number (`x` then the fraction): the leading `x` is a sibling of the
142
+ // fraction, which a lone `\frac{}{}` does not have, and the label's pixel
143
+ // rounding then lands the bar a row lower - so it takes a smaller drop. This
144
+ // also keeps the bar level with the `x`.
136
145
  '& .ML__mfrac:has([data-pie-empty]):not(:only-child) .ML__frac-line': {
137
- top: '0.13em'
146
+ top: '0.1em'
138
147
  },
139
148
  // Segment (`\overline`) vs ray / line (stretchy arrows). Over filled content
140
149
  // MathLive draws the bar ~0.31em below the arrows' shafts, and the bar is
@@ -1 +1 @@
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","PARALLEL_SELECTOR","PARALLEL_FONT_SIZE","parallelStyles","PARALLEL_CSS","supsubStyles","_objectSpread","OVERLINE_BAR_MASK","placeholderStyles","borderBottom","minWidth","opacity","position","top","content","left","right","height","border","background","WebkitMask","mask","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 * Size of the parallel sign (`\\parallel`, tagged `data-pie-macro=\"parallel\"` by\n * `PIE_MACROS`). The legacy editor enlarged it (`updateSpans` set 32px) because\n * the bars read too small next to the letters of `AB ∥ CD`; MathLive draws it at\n * the surrounding size, so it is scaled up here. Not applied to keypad labels.\n */\nconst PARALLEL_SELECTOR = '[data-pie-macro=\"parallel\"]';\nconst PARALLEL_FONT_SIZE = '1.4em';\n\nexport const parallelStyles = {\n [`& ${PARALLEL_SELECTOR}`]: {\n fontSize: PARALLEL_FONT_SIZE,\n },\n};\n\n/** The same rule as a CSS string, for a live mathfield's shadow root. */\nexport const PARALLEL_CSS = `${PARALLEL_SELECTOR}{font-size:${PARALLEL_FONT_SIZE}}`;\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 ...parallelStyles,\n};\n\nconst OVERLINE_BAR_MASK =\n 'url(\"data:image/svg+xml,%3Csvg xmlns=\\'http://www.w3.org/2000/svg\\' viewBox=\\'0 0 100 522\\' preserveAspectRatio=\\'none\\'%3E' +\n '%3Crect y=\\'241\\' width=\\'100\\' height=\\'40\\'/%3E%3C/svg%3E\") 0 0/100% 100% no-repeat';\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 // A fraction with an empty slot: MathLive spaces the bar for text, but the\n // slot's box is a taller `\\rule`, so the bar hugs the numerator's box (~0.2em\n // above vs ~0.4em below). Dropping the bar 0.16em (0.13em when the numerator is not an empty slot or follows an `x`) centres it between the two\n // boxes. Only the bar moves, not the slots.\n '& .ML__mfrac:has([data-pie-empty]) .ML__frac-line': {\n position: 'relative',\n top: '0.16em',\n },\n // A real numerator (`x`) is lighter than an empty box and its ink ends at the\n // baseline, so the full drop overshoots: it needs a smaller drop. The numerator is\n // the second `.ML__center` (MathLive emits the denominator first).\n '& .ML__mfrac:has([data-pie-empty]):not(:has(.ML__center ~ .ML__center [data-pie-empty])) .ML__frac-line': {\n top: '0.13em',\n },\n // Same for a mixed number (`x` then the fraction): the leading `x` is a sibling\n // of the fraction, which a lone `\\frac{}{}` does not have.\n '& .ML__mfrac:has([data-pie-empty]):not(:only-child) .ML__frac-line': {\n top: '0.13em',\n },\n // Segment (`\\overline`) vs ray / line (stretchy arrows). Over filled content\n // MathLive draws the bar ~0.31em below the arrows' shafts, and the bar is\n // `max(1px, 0.04em)` twice (:before + :after) while a shaft is a 0.04em path,\n // so it also renders heavier. Raise it to the shaft height and draw it once at\n // 0.04em. An empty slot (`data-pie-empty`) is already aligned by the struts in\n // `withVisibleEmptySlots`, so it keeps its position. `!important`: the offset is\n // an inline style.\n '& .overline:not(:has([data-pie-empty])) > .ML__vlist-t > .ML__vlist-r > .ML__vlist > span:has(> .overline-line)': {\n top: '-4.07em !important',\n },\n '& .overline .overline-line': {\n position: 'relative',\n },\n // Drawn as a mask with the arrow shaft's geometry (y 241-281 of a 522-high box)\n // instead of a border, which the browser snaps to whole device pixels.\n '& .overline .overline-line:before': {\n content: '\"\"',\n display: 'block',\n position: 'absolute',\n left: 0,\n right: 0,\n top: '-0.241em',\n height: '0.522em !important',\n border: '0 !important',\n background: 'currentColor',\n WebkitMask: OVERLINE_BAR_MASK,\n mask: OVERLINE_BAR_MASK,\n },\n '& .overline .overline-line:after': {\n display: 'none !important',\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,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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,mBAAmB,GAAG,0FAA0F;AACtH,IAAMC,oBAAoB,GAAG,KAAK;AAE3B,IAAMC,eAAe,GAAAN,OAAA,CAAAM,eAAA,OAAAC,gBAAA,sBAAAC,MAAA,CAC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C,oBAAA,GAAArB,aAAA,CAAAA,aAAA,CAAAA,aAAA,CAAAA,aAAA,CAAAA,aAAA,KAC5BjB,kBAAkB,GAClBG,aAAa,GACba,YAAY,GACZG,iBAAiB;EACpB,cAAc,EAAE;IACdT,QAAQ,EAAE,SAAS;IACnB2B,OAAO,EAAE;EACX,CAAC;EACD,6CAA6C,EAAE;IAC7CjC,OAAO,EAAE;EACX,CAAC;EACD,iCAAiC,EAAE;IACjCA,OAAO,EAAE;EACX;AAAC,EACF;AAEM,IAAMmC,oBAAoB,GAAAtC,OAAA,CAAAsC,oBAAA,GAAGJ,sBAAsB;;AAE1D;AACA;AACA;AACA;AAHA,IAAAK,QAAA,GAAAvC,OAAA,cAIe;EACbD,kBAAkB,EAAlBA,kBAAkB;EAClBG,aAAa,EAAbA,aAAa;EACbI,eAAe,EAAfA,eAAe;EACfS,YAAY,EAAZA,YAAY;EACZmB,sBAAsB,EAAtBA,sBAAsB;EACtBhB,iBAAiB,EAAjBA,iBAAiB;EACjBmB,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","PARALLEL_SELECTOR","PARALLEL_FONT_SIZE","parallelStyles","PARALLEL_CSS","supsubStyles","_objectSpread","OVERLINE_BAR_MASK","placeholderStyles","borderBottom","minWidth","opacity","position","top","content","left","right","height","border","background","WebkitMask","mask","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 * Size of the parallel sign (`\\parallel`, tagged `data-pie-macro=\"parallel\"` by\n * `PIE_MACROS`). The legacy editor enlarged it (`updateSpans` set 32px) because\n * the bars read too small next to the letters of `AB ∥ CD`; MathLive draws it at\n * the surrounding size, so it is scaled up here. Not applied to keypad labels.\n */\nconst PARALLEL_SELECTOR = '[data-pie-macro=\"parallel\"]';\nconst PARALLEL_FONT_SIZE = '1.4em';\n\nexport const parallelStyles = {\n [`& ${PARALLEL_SELECTOR}`]: {\n fontSize: PARALLEL_FONT_SIZE,\n },\n};\n\n/** The same rule as a CSS string, for a live mathfield's shadow root. */\nexport const PARALLEL_CSS = `${PARALLEL_SELECTOR}{font-size:${PARALLEL_FONT_SIZE}}`;\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 ...parallelStyles,\n};\n\nconst OVERLINE_BAR_MASK =\n 'url(\"data:image/svg+xml,%3Csvg xmlns=\\'http://www.w3.org/2000/svg\\' viewBox=\\'0 0 100 522\\' preserveAspectRatio=\\'none\\'%3E' +\n '%3Crect y=\\'241\\' width=\\'100\\' height=\\'40\\'/%3E%3C/svg%3E\") 0 0/100% 100% no-repeat';\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 // A filled fraction (`55/555`): MathLive's bar sits ~0.075em nearer the numerator's\n // digits than the denominator's (measured at 40px: 8.5px above, 11.5px below).\n // Dropping the bar 0.04em evens the two gaps. Fractions with an empty slot have\n // their own drop below, which is more specific and overrides this one.\n '& .ML__mfrac:not(:has([data-pie-empty])) .ML__frac-line': {\n position: 'relative',\n top: '0.04em',\n },\n // A fraction with an empty slot: MathLive spaces the bar for text, but the\n // slot's box is a taller `\\rule`, so the bar hugs the numerator's box. Measured\n // at 100px: dropping it 0.14em centres it between two boxes, and 0.13em between\n // a real numerator (`x`, whose ink ends at the baseline) and an empty denominator.\n // Only the bar moves, not the slots. The numerator is the second `.ML__center`\n // (MathLive emits the denominator first).\n '& .ML__mfrac:has([data-pie-empty]) .ML__frac-line': {\n position: 'relative',\n top: '0.14em',\n },\n '& .ML__mfrac:has([data-pie-empty]):not(:has(.ML__center ~ .ML__center [data-pie-empty])) .ML__frac-line': {\n top: '0.13em',\n },\n // A mixed number (`x` then the fraction): the leading `x` is a sibling of the\n // fraction, which a lone `\\frac{}{}` does not have, and the label's pixel\n // rounding then lands the bar a row lower - so it takes a smaller drop. This\n // also keeps the bar level with the `x`.\n '& .ML__mfrac:has([data-pie-empty]):not(:only-child) .ML__frac-line': {\n top: '0.1em',\n },\n // Segment (`\\overline`) vs ray / line (stretchy arrows). Over filled content\n // MathLive draws the bar ~0.31em below the arrows' shafts, and the bar is\n // `max(1px, 0.04em)` twice (:before + :after) while a shaft is a 0.04em path,\n // so it also renders heavier. Raise it to the shaft height and draw it once at\n // 0.04em. An empty slot (`data-pie-empty`) is already aligned by the struts in\n // `withVisibleEmptySlots`, so it keeps its position. `!important`: the offset is\n // an inline style.\n '& .overline:not(:has([data-pie-empty])) > .ML__vlist-t > .ML__vlist-r > .ML__vlist > span:has(> .overline-line)': {\n top: '-4.07em !important',\n },\n '& .overline .overline-line': {\n position: 'relative',\n },\n // Drawn as a mask with the arrow shaft's geometry (y 241-281 of a 522-high box)\n // instead of a border, which the browser snaps to whole device pixels.\n '& .overline .overline-line:before': {\n content: '\"\"',\n display: 'block',\n position: 'absolute',\n left: 0,\n right: 0,\n top: '-0.241em',\n height: '0.522em !important',\n border: '0 !important',\n background: 'currentColor',\n WebkitMask: OVERLINE_BAR_MASK,\n mask: OVERLINE_BAR_MASK,\n },\n '& .overline .overline-line:after': {\n display: 'none !important',\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,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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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eAAe,GACfY,iBAAiB;EACpBiB,WAAW,EAAE,cAAc;EAC3B,cAAc,EAAE;IACd1B,QAAQ,EAAE,SAAS;IACnB2B,OAAO,EAAE;EACX,CAAC;EACD,6CAA6C,EAAE;IAC7CjC,OAAO,EAAE;EACX,CAAC;EACD,iCAAiC,EAAE;IACjCA,OAAO,EAAE;EACX;AAAC,EACF;;AAED;AACO,IAAMkC,oBAAoB,GAAArC,OAAA,CAAAqC,oBAAA,GAAArB,aAAA,CAAAA,aAAA,CAAAA,aAAA,CAAAA,aAAA,CAAAA,aAAA,KAC5BjB,kBAAkB,GAClBG,aAAa,GACba,YAAY,GACZG,iBAAiB;EACpB,cAAc,EAAE;IACdT,QAAQ,EAAE,SAAS;IACnB2B,OAAO,EAAE;EACX,CAAC;EACD,6CAA6C,EAAE;IAC7CjC,OAAO,EAAE;EACX,CAAC;EACD,iCAAiC,EAAE;IACjCA,OAAO,EAAE;EACX;AAAC,EACF;AAEM,IAAMmC,oBAAoB,GAAAtC,OAAA,CAAAsC,oBAAA,GAAGJ,sBAAsB;;AAE1D;AACA;AACA;AACA;AAHA,IAAAK,QAAA,GAAAvC,OAAA,cAIe;EACbD,kBAAkB,EAAlBA,kBAAkB;EAClBG,aAAa,EAAbA,aAAa;EACbI,eAAe,EAAfA,eAAe;EACfS,YAAY,EAAZA,YAAY;EACZmB,sBAAsB,EAAtBA,sBAAsB;EACtBhB,iBAAiB,EAAjBA,iBAAiB;EACjBmB,oBAAoB,EAApBA;AACF,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.1.5-beta.14",
6
+ "version": "1.1.5-beta.15",
7
7
  "description": "MathLive-based math input (drop-in alternative to @pie-lib/math-input)",
8
8
  "main": "lib/index.js",
9
9
  "module": "src/index.jsx",
@@ -75,21 +75,25 @@ const LabelHolder = styled('span', { shouldForwardProp: (prop) => prop !== 'slan
75
75
  '&:has(.ML__mfrac)': {
76
76
  paddingTop: '0.25em',
77
77
  },
78
- // Centre a fraction's bar between its empty slots (see `placeholderStyles`).
78
+ // Centre a fraction's bar between its empty slots. MathLive spaces the bar for
79
+ // text, but a slot is a taller `\rule` box, so the bar hugs the numerator's box.
80
+ // Measured on the real keypad: dropping it 0.07em centres it between two boxes, and 0.08em
81
+ // between a real numerator (`x`, whose ink ends at the baseline) and an empty
82
+ // denominator. Only the bar moves, not the slots. The numerator is the second
83
+ // `.ML__center` (MathLive emits the denominator first).
79
84
  '& .ML__mfrac:has([data-pie-empty]) .ML__frac-line': {
80
85
  position: 'relative',
81
- top: '0.16em',
86
+ top: '0.14em',
82
87
  },
83
- // A real numerator (`x`) is lighter than an empty box and its ink ends at the
84
- // baseline, so the full drop overshoots: it needs a smaller drop. The numerator is
85
- // the second `.ML__center` (MathLive emits the denominator first).
86
88
  '& .ML__mfrac:has([data-pie-empty]):not(:has(.ML__center ~ .ML__center [data-pie-empty])) .ML__frac-line': {
87
89
  top: '0.13em',
88
90
  },
89
- // Same for a mixed number (`x` then the fraction): the leading `x` is a sibling
90
- // of the fraction, which a lone `\frac{}{}` does not have.
91
+ // A mixed number (`x` then the fraction): the leading `x` is a sibling of the
92
+ // fraction, which a lone `\frac{}{}` does not have, and the label's pixel
93
+ // rounding then lands the bar a row lower - so it takes a smaller drop. This
94
+ // also keeps the bar level with the `x`.
91
95
  '& .ML__mfrac:has([data-pie-empty]):not(:only-child) .ML__frac-line': {
92
- top: '0.13em',
96
+ top: '0.1em',
93
97
  },
94
98
  // A readable index on the nth-root key. Carried by the label itself, not only
95
99
  // by the keypad container, so it holds wherever a LatexLabel is mounted.
@@ -266,13 +266,21 @@ const OVERLINE_GAP_CSS =
266
266
  '.ML__latex .overline .overline-line:after{display:none !important}' +
267
267
  '.ML__latex:has(.overline)>.ML__strut{height:1.37em !important}';
268
268
 
269
- // MathLive spaces a fraction's bar for text glyphs, whose ink sits tight against
270
- // the baseline. An empty slot's box (`▢`) hangs lower than that, so the bar ends
271
- // up much nearer the denominator's box than the numerator's (measured ~0.28em vs
272
- // ~0.11em). Dropping the bar 0.08em evens the two gaps. Layout is untouched, so
273
- // the numerator and denominator keep their positions; filled fractions (`1/2`)
274
- // only see the bar move a hair.
275
- const FRAC_BAR_CENTER_CSS = '.ML__latex .ML__frac-line{position:relative;top:0.08em}';
269
+ // An empty slot is a `▢` glyph in a 0.9em-tall box, which hangs lower than the
270
+ // ink of text, so MathLive's bar ends up much nearer the denominator's box than
271
+ // the numerator's (measured at 100px: 24px above the bar, 9px below). Raising the
272
+ // bar 0.025em evens the gaps (measured on screen at authoring size: 1px above, 2px below at -0.075em, so it moves back down). The denominator is the first `.ML__center`
273
+ // (MathLive emits it first); only fractions with an empty denominator are touched,
274
+ // because `▢ over 2` is already balanced and filled fractions are MathLive's own.
275
+ const FRAC_BAR_CENTER_CSS =
276
+ '.ML__latex .ML__mfrac:has(.ML__vlist>.ML__center:first-child span[style*="height:0.9em"]) .ML__frac-line' +
277
+ '{position:relative;top:-0.025em}';
278
+
279
+ // A filled fraction (`55/555`) has its bar ~0.075em nearer the numerator's digits
280
+ // than the denominator's (measured at 40px: 8.5px above, 11.5px below); drop it 0.04em.
281
+ // Fractions with an empty slot (a 0.9em-tall box) are handled above.
282
+ const FRAC_BAR_FILLED_CSS =
283
+ '.ML__latex .ML__mfrac:not(:has(span[style*="height:0.9em"])) .ML__frac-line{position:relative;top:0.04em}';
276
284
 
277
285
  // A live mathfield needs the readable radical index too: `rootIndexStyles` is
278
286
  // written for static markup in the host page, which cannot cross the shadow
@@ -283,6 +291,7 @@ const SHADOW_CSS =
283
291
  PARALLEL_CSS +
284
292
  OVERLINE_GAP_CSS +
285
293
  FRAC_BAR_CENTER_CSS +
294
+ FRAC_BAR_FILLED_CSS +
286
295
  PLACEHOLDER_CARET_CSS;
287
296
 
288
297
  /**
@@ -119,24 +119,33 @@ export const placeholderStyles = {
119
119
  '& [data-pie-empty]': {
120
120
  opacity: 0.5,
121
121
  },
122
+ // A filled fraction (`55/555`): MathLive's bar sits ~0.075em nearer the numerator's
123
+ // digits than the denominator's (measured at 40px: 8.5px above, 11.5px below).
124
+ // Dropping the bar 0.04em evens the two gaps. Fractions with an empty slot have
125
+ // their own drop below, which is more specific and overrides this one.
126
+ '& .ML__mfrac:not(:has([data-pie-empty])) .ML__frac-line': {
127
+ position: 'relative',
128
+ top: '0.04em',
129
+ },
122
130
  // A fraction with an empty slot: MathLive spaces the bar for text, but the
123
- // slot's box is a taller `\rule`, so the bar hugs the numerator's box (~0.2em
124
- // above vs ~0.4em below). Dropping the bar 0.16em (0.13em when the numerator is not an empty slot or follows an `x`) centres it between the two
125
- // boxes. Only the bar moves, not the slots.
131
+ // slot's box is a taller `\rule`, so the bar hugs the numerator's box. Measured
132
+ // at 100px: dropping it 0.14em centres it between two boxes, and 0.13em between
133
+ // a real numerator (`x`, whose ink ends at the baseline) and an empty denominator.
134
+ // Only the bar moves, not the slots. The numerator is the second `.ML__center`
135
+ // (MathLive emits the denominator first).
126
136
  '& .ML__mfrac:has([data-pie-empty]) .ML__frac-line': {
127
137
  position: 'relative',
128
- top: '0.16em',
138
+ top: '0.14em',
129
139
  },
130
- // A real numerator (`x`) is lighter than an empty box and its ink ends at the
131
- // baseline, so the full drop overshoots: it needs a smaller drop. The numerator is
132
- // the second `.ML__center` (MathLive emits the denominator first).
133
140
  '& .ML__mfrac:has([data-pie-empty]):not(:has(.ML__center ~ .ML__center [data-pie-empty])) .ML__frac-line': {
134
141
  top: '0.13em',
135
142
  },
136
- // Same for a mixed number (`x` then the fraction): the leading `x` is a sibling
137
- // of the fraction, which a lone `\frac{}{}` does not have.
143
+ // A mixed number (`x` then the fraction): the leading `x` is a sibling of the
144
+ // fraction, which a lone `\frac{}{}` does not have, and the label's pixel
145
+ // rounding then lands the bar a row lower - so it takes a smaller drop. This
146
+ // also keeps the bar level with the `x`.
138
147
  '& .ML__mfrac:has([data-pie-empty]):not(:only-child) .ML__frac-line': {
139
- top: '0.13em',
148
+ top: '0.1em',
140
149
  },
141
150
  // Segment (`\overline`) vs ray / line (stretchy arrows). Over filled content
142
151
  // MathLive draws the bar ~0.31em below the arrows' shafts, and the bar is