@pie-lib/math-input-mathlive 1.1.5-beta.1 → 1.1.5-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/lib/__tests__/composites.test.js +255 -0
  2. package/lib/__tests__/drop-in-compat.test.js +133 -0
  3. package/lib/__tests__/embedded-fonts.test.js +121 -0
  4. package/lib/__tests__/index.test.js +118 -0
  5. package/lib/__tests__/input-imperative.test.js +155 -0
  6. package/lib/__tests__/keypad-label.test.js +231 -0
  7. package/lib/__tests__/keypad-render.test.js +206 -0
  8. package/lib/__tests__/latex-bridge.test.js +386 -0
  9. package/lib/__tests__/mathlive-instance.test.js +419 -0
  10. package/lib/__tests__/mount-race.test.js +218 -0
  11. package/lib/__tests__/static-prompts.test.js +405 -0
  12. package/lib/__tests__/tmp-markup.test.js +26 -0
  13. package/lib/keypad/index.js +36 -12
  14. package/lib/keypad/index.js.map +1 -1
  15. package/lib/latex-bridge.js +159 -4
  16. package/lib/latex-bridge.js.map +1 -1
  17. package/lib/mathlive-instance.js +21 -28
  18. package/lib/mathlive-instance.js.map +1 -1
  19. package/lib/mf/common-styles.js +17 -2
  20. package/lib/mf/common-styles.js.map +1 -1
  21. package/lib/mf/index.js +6 -0
  22. package/lib/mf/index.js.map +1 -1
  23. package/lib/mf/input.js +5 -0
  24. package/lib/mf/input.js.map +1 -1
  25. package/lib/mf/static.js +4 -2
  26. package/lib/mf/static.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/__tests__/composites.test.jsx +220 -0
  29. package/src/__tests__/drop-in-compat.test.jsx +112 -0
  30. package/src/__tests__/index.test.jsx +109 -0
  31. package/src/__tests__/input-imperative.test.jsx +144 -0
  32. package/src/__tests__/keypad-label.test.jsx +284 -0
  33. package/src/__tests__/keypad-render.test.jsx +123 -0
  34. package/src/__tests__/latex-bridge.test.js +389 -0
  35. package/src/__tests__/mathlive-instance.test.js +418 -0
  36. package/src/__tests__/mount-race.test.jsx +142 -0
  37. package/src/__tests__/static-prompts.test.jsx +364 -0
  38. package/src/keypad/index.jsx +18 -3
  39. package/src/latex-bridge.js +171 -4
  40. package/src/mathlive-instance.js +27 -29
  41. package/src/mf/common-styles.js +19 -0
  42. package/src/mf/index.js +2 -0
  43. package/src/mf/input.jsx +5 -0
  44. package/src/mf/static.jsx +4 -1
  45. package/lib/fonts/embedded.js +0 -120
  46. package/lib/fonts/index.js +0 -81
  47. package/lib/fonts/index.js.map +0 -1
  48. package/scripts/generate-embedded-fonts.js +0 -94
  49. package/src/fonts/embedded.js +0 -116
  50. package/src/fonts/index.js +0 -71
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_propTypes","_Button","_IconButton","_styles","_debug","_lodashEs","_renderUi","_keys","_keysLayout","_commonStyles","_mathliveInstance","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","ownKeys","r","Object","keys","getOwnPropertySymbols","filter","getOwnPropertyDescriptor","enumerable","push","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","log","debug","LabelHolder","styled","pointerEvents","textTransform","color","text","display","textAlign","lineHeight","maxWidth","overflow","backgroundColor","keypadEmptyPlaceholder","undefined","opacity","rootIndexStyles","LatexLabel","exports","_React$Component","props","_this","_classCallCheck2","state","markup","latexToMarkup","latex","_inherits2","_createClass2","key","value","_componentDidMount","_asyncToGenerator2","_regenerator","mark","_callee","wrap","_context","prev","next","abrupt","loadMathLive","unmounted","setState","warned","stop","componentDidMount","componentDidUpdate","prevProps","componentWillUnmount","render","createElement","dangerouslySetInnerHTML","__html","React","Component","PropTypes","string","isRequired","createCustomLayout","layoutObj","gridTemplateColumns","concat","columns","gridTemplateRows","rows","gridAutoFlow","KeyPadContainer","commonKeyboardStyles","width","gridRowGap","gridColumnGap","fontFamily","buttonBackground","category","keypadButtonOperator","keypadButton","keypadButtonOperatorHover","keypadButtonHover","StyledButton","Button","_ref","isDelete","isComma","isDot","minWidth","fontSize","borderRadius","StyledLatexButtonWrapper","_ref2","padding","margin","StyledIconButton","IconButton","_ref3","height","KeyPad","_React$Component2","_this2","setKeypadInteraction","onPress","base","extras","flatten","_toConsumableArray2","sortKeys","noDecimal","write","label","keypadRef","createRef","_this$keypadRef","keyPadElement","current","mainContainer","closest","currentToolbar","controlledKeypadMode","mainContainerPosition","getBoundingClientRect","currentToolbarPosition","difference","top","totalHeight","style","addEventListener","handleKeypadInteraction","_this$keypadRef2","removeEventListener","_this3","_this$props","className","baseSet","additionalKeys","layoutForKeyPad","onFocus","mode","noBaseSet","keysWithoutBaseSet","includes","allKeys","flowKeys","shift","Math","floor","ref","join","map","k","index","command","extra","actions","extraProps","onClick","buttonClick","bind","disabled","keyIsNotAllowed","ariaLabel","name","_extends2","Icon","icon","tabIndex","size","bool","array","object","func","oneOfType","number","_default"],"sources":["../../src/keypad/index.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Button from '@mui/material/Button';\nimport IconButton from '@mui/material/IconButton';\nimport { styled } from '@mui/material/styles';\nimport debug from 'debug';\nimport { flatten } from 'lodash-es';\nimport { color } from '@pie-lib/render-ui';\n\nimport { baseSet } from '../keys';\nimport { sortKeys } from './keys-layout';\nimport { commonKeyboardStyles, rootIndexStyles } from '../mf/common-styles';\nimport { loadMathLive, latexToMarkup } from '../mathlive-instance';\n\nconst log = debug('pie-lib:math-input-mathlive:keypad');\n\n/**\n * A LaTeX keypad label.\n *\n * The MathQuill implementation rendered every LaTeX label as its own\n * `MQ.StaticMath` instance. Here each label is static HTML produced once by\n * `convertLatexToMarkup`, so a 40-key keypad no longer creates 40 live math\n * instances.\n */\n// The `color.*()` helpers must be called lazily, inside the styled callback.\n// Evaluating them in a plain object literal runs them at module load, which\n// breaks any consumer that mocks a subset of @pie-lib/render-ui.\nconst LabelHolder = styled('span')(() => ({\n pointerEvents: 'none',\n textTransform: 'none',\n color: color.text(),\n // Deliberately inline-block, NOT inline-flex: MathLive's markup relies on\n // normal inline flow. Making its spans flex items collapses their width, and\n // stretchy accents render an <svg width=\"100%\" preserveAspectRatio=\"none\">\n // that then squeezes into a spike instead of spanning the content.\n display: 'inline-block',\n textAlign: 'center',\n lineHeight: 1,\n // Keep a label from sizing its grid column. `overflow: hidden` also collapses\n // the label's min-content contribution, so a wide accent cannot drag the\n // column across the screen. The svg's own positioning is left to\n // mathlive-static.css (injected by the package) - duplicating it here broke\n // the accent's containing block.\n maxWidth: '100%',\n overflow: 'hidden',\n // Answer-block / empty-slot boxes inside a label.\n '& .ML__placeholder': {\n backgroundColor: color.keypadEmptyPlaceholder ? color.keypadEmptyPlaceholder() : undefined,\n },\n // The stand-in glyph for an empty argument slot (see EMPTY_SLOT). Muted so it\n // reads as \"a slot goes here\" rather than as part of the symbol, matching how\n // MathQuill shaded `.mq-empty`.\n '& [data-pie-empty]': {\n opacity: 0.5,\n },\n // A readable index on the nth-root key. Carried by the label itself, not only\n // by the keypad container, so it holds wherever a LatexLabel is mounted.\n ...rootIndexStyles,\n}));\n\nexport class LatexLabel extends React.Component {\n static propTypes = {\n latex: PropTypes.string.isRequired,\n };\n\n constructor(props) {\n super(props);\n this.state = { markup: latexToMarkup(props.latex) };\n }\n\n async componentDidMount() {\n // MathLive may not have finished loading when the keypad first mounts.\n if (this.state.markup) {\n return;\n }\n\n await loadMathLive();\n\n if (this.unmounted) {\n return;\n }\n\n const markup = latexToMarkup(this.props.latex);\n\n if (markup) {\n this.setState({ markup });\n return;\n }\n\n // Still nothing: the engine is genuinely unavailable (a missing chunk, a\n // blocked request). Keep the raw-latex fallback visible rather than an\n // empty button, and log once so this is diagnosable.\n if (!LatexLabel.warned) {\n LatexLabel.warned = true;\n log('MathLive unavailable - keypad labels are falling back to raw latex');\n }\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.latex !== this.props.latex) {\n this.setState({ markup: latexToMarkup(this.props.latex) });\n }\n }\n\n componentWillUnmount() {\n this.unmounted = true;\n }\n\n render() {\n const { markup } = this.state;\n\n // Fall back to the raw latex so a button is never blank.\n return markup ? (\n // eslint-disable-next-line react/no-danger\n <LabelHolder dangerouslySetInnerHTML={{ __html: markup }} />\n ) : (\n <LabelHolder>{this.props.latex}</LabelHolder>\n );\n }\n}\n\nconst createCustomLayout = (layoutObj) => {\n if (layoutObj) {\n return {\n gridTemplateColumns: `repeat(${layoutObj.columns}, minmax(min-content, 150px))`,\n gridTemplateRows: `repeat(${layoutObj.rows}, minmax(40px, 60px))`,\n gridAutoFlow: 'initial',\n };\n }\n\n return {};\n};\n\nconst KeyPadContainer = styled('div')(() => ({\n ...commonKeyboardStyles,\n width: '100%',\n display: 'grid',\n gridTemplateRows: 'repeat(5, minmax(40px, 60px))',\n gridRowGap: '0px',\n gridColumnGap: '0px',\n gridAutoFlow: 'column',\n '&.character': {\n textTransform: 'initial !important',\n gridTemplateRows: 'repeat(5, minmax(40px, 50px)) !important',\n },\n '&.language': {\n gridTemplateRows: 'repeat(4, minmax(40px, 50px)) !important',\n '& *': {\n fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',\n },\n },\n}));\n\nconst buttonBackground = (category) => ({\n backgroundColor: category === 'operators' ? color.keypadButtonOperator() : color.keypadButton(),\n '&:hover': {\n backgroundColor: category === 'operators' ? color.keypadButtonOperatorHover() : color.keypadButtonHover(),\n },\n});\n\nconst StyledButton = styled(Button)(({ category, isDelete, isComma, isDot }) => ({\n minWidth: 'auto',\n textTransform: 'none',\n fontSize: isComma || isDot ? '200% !important' : '140% !important',\n lineHeight: isComma || isDot ? '100%' : 'normal',\n color: color.text(),\n ...buttonBackground(category),\n borderRadius: 0,\n ...(isDelete && {\n fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',\n }),\n}));\n\nconst StyledLatexButtonWrapper = styled(Button)(({ category }) => ({\n textTransform: 'none',\n padding: 0,\n margin: 0,\n fontSize: '110% !important',\n minWidth: 'auto',\n borderRadius: 0,\n ...buttonBackground(category),\n}));\n\nconst StyledIconButton = styled(IconButton)(({ category }) => ({\n minWidth: 'auto',\n ...buttonBackground(category),\n borderRadius: 0,\n '& .icon': {\n height: '30px',\n },\n}));\n\nexport class KeyPad extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n controlledKeypadMode: PropTypes.bool,\n baseSet: PropTypes.array,\n additionalKeys: PropTypes.array,\n layoutForKeyPad: PropTypes.object,\n onPress: PropTypes.func.isRequired,\n onFocus: PropTypes.func,\n noDecimal: PropTypes.bool,\n setKeypadInteraction: PropTypes.func,\n mode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n };\n\n static defaultProps = {\n baseSet: baseSet,\n noDecimal: false,\n };\n\n constructor(props) {\n super(props);\n this.keypadRef = React.createRef();\n }\n\n componentDidMount() {\n // Ensure MathLive is available for the LaTeX labels.\n loadMathLive();\n\n const keyPadElement = this.keypadRef?.current;\n const mainContainer = keyPadElement?.closest('.main-container');\n const currentToolbar = keyPadElement?.closest('.pie-toolbar');\n\n // need only for math keyboard so we need also controlledKeypadMode\n if (this.props.controlledKeypadMode && mainContainer && currentToolbar) {\n const mainContainerPosition = mainContainer.getBoundingClientRect();\n const currentToolbarPosition = currentToolbar.getBoundingClientRect();\n const difference =\n mainContainerPosition.top +\n mainContainerPosition.height -\n (currentToolbarPosition.top + currentToolbarPosition.height);\n\n if (difference < 0) {\n const totalHeight = mainContainerPosition.height + mainContainerPosition.top - difference;\n\n mainContainer.style.height = `${totalHeight}px`;\n }\n }\n\n if (keyPadElement) {\n keyPadElement.addEventListener('touchstart', this.handleKeypadInteraction, true);\n keyPadElement.addEventListener('mousedown', this.handleKeypadInteraction, true);\n }\n }\n\n componentWillUnmount() {\n const keyPadElement = this.keypadRef?.current;\n\n if (this.props.controlledKeypadMode && keyPadElement) {\n const mainContainer = keyPadElement.closest('.main-container');\n\n if (mainContainer) {\n mainContainer.style.height = 'unset';\n }\n }\n\n if (keyPadElement) {\n keyPadElement.removeEventListener('touchstart', this.handleKeypadInteraction, true);\n keyPadElement.removeEventListener('mousedown', this.handleKeypadInteraction, true);\n }\n }\n\n handleKeypadInteraction = () => {\n if (this.props.setKeypadInteraction) {\n this.props.setKeypadInteraction(true);\n }\n };\n\n buttonClick = (key) => {\n log('[buttonClick]', key);\n this.props.onPress(key);\n };\n\n flowKeys = (base, extras) => flatten([...sortKeys(base), ...sortKeys(extras)]);\n\n keyIsNotAllowed = (key) => {\n const { noDecimal } = this.props;\n\n return !!(((key.write === '.' && key.label === '.') || (key.write === ',' && key.label === ',')) && noDecimal);\n };\n\n render() {\n const { className, baseSet: base, additionalKeys, layoutForKeyPad, onFocus, mode } = this.props;\n\n const noBaseSet = ['non-negative-integers', 'integers', 'decimals', 'fractions', 'item-authoring', 'language'];\n const keysWithoutBaseSet = noBaseSet.includes(mode);\n const allKeys = keysWithoutBaseSet\n ? this.flowKeys([], additionalKeys || [])\n : this.flowKeys(base, additionalKeys || []);\n\n const shift = allKeys.length % 5 ? 1 : 0;\n const style = {\n gridTemplateColumns: `repeat(${Math.floor(allKeys.length / 5) + shift}, minmax(min-content, 150px))`,\n ...createCustomLayout(layoutForKeyPad),\n };\n\n return (\n <KeyPadContainer\n ref={this.keypadRef}\n className={[className, mode].filter(Boolean).join(' ')}\n style={style}\n onFocus={onFocus}\n >\n {allKeys.map((k, index) => {\n if (!k) {\n return <span key={`empty-${index}`} />;\n }\n\n const key = `${k.label || k.latex || k.command}-${index}`;\n const category = !keysWithoutBaseSet ? k.category : undefined;\n const extra = { ...(k.actions || {}), ...(k.extraProps || {}) };\n const onClick = this.buttonClick.bind(this, k);\n const disabled = this.keyIsNotAllowed(k);\n const ariaLabel = k.ariaLabel ? k.ariaLabel : k.name || k.label;\n\n if (k.latex) {\n return (\n <StyledLatexButtonWrapper\n key={key}\n onClick={onClick}\n disabled={disabled}\n category={category}\n aria-label={ariaLabel}\n {...extra}\n >\n <LatexLabel latex={k.latex} />\n </StyledLatexButtonWrapper>\n );\n }\n\n if (k.label) {\n return (\n <StyledButton\n key={key}\n onClick={onClick}\n disabled={disabled}\n category={category}\n isDelete={k.label === '⌫'}\n isComma={k.label === ','}\n isDot={k.label === '.'}\n aria-label={ariaLabel}\n {...extra}\n >\n {k.label}\n </StyledButton>\n );\n }\n\n const Icon = k.icon ? k.icon : 'div';\n\n return (\n <StyledIconButton\n key={key}\n tabIndex={'-1'}\n onClick={onClick}\n disabled={disabled}\n category={category}\n size=\"large\"\n {...extra}\n >\n <Icon className=\"icon\" />\n </StyledIconButton>\n );\n })}\n </KeyPadContainer>\n );\n }\n}\n\nexport default KeyPad;\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AAEA,IAAAQ,KAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AACA,IAAAU,aAAA,GAAAV,OAAA;AACA,IAAAW,iBAAA,GAAAX,OAAA;AAAmE,SAAAY,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,OAAAE,gBAAA,aAAAF,CAAA,OAAAG,2BAAA,aAAAJ,CAAA,EAAAK,yBAAA,KAAAC,OAAA,CAAAC,SAAA,CAAAN,CAAA,EAAAC,CAAA,YAAAC,gBAAA,aAAAH,CAAA,EAAAQ,WAAA,IAAAP,CAAA,CAAAQ,KAAA,CAAAT,CAAA,EAAAE,CAAA;AAAA,SAAAG,0BAAA,cAAAL,CAAA,IAAAU,OAAA,CAAAC,SAAA,CAAAC,OAAA,CA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qBAAS,CAACgH,MAAM;EACjCpE,OAAO,EAAE5C,qBAAS,CAACiH,IAAI,CAAC/G,UAAU;EAClC6E,OAAO,EAAE/E,qBAAS,CAACiH,IAAI;EACvB/D,SAAS,EAAElD,qBAAS,CAAC8G,IAAI;EACzBnE,oBAAoB,EAAE3C,qBAAS,CAACiH,IAAI;EACpCjC,IAAI,EAAEhF,qBAAS,CAACkH,SAAS,CAAC,CAAClH,qBAAS,CAACC,MAAM,EAAED,qBAAS,CAACmH,MAAM,CAAC;AAChE,CAAC;AAAA,IAAAhL,gBAAA,aAZUqG,MAAM,kBAcK;EACpBoC,OAAO,EAAEA,aAAO;EAChB1B,SAAS,EAAE;AACb,CAAC;AAAA,IAAAkE,QAAA,GAAA1J,OAAA,cAiKY8E,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_propTypes","_Button","_IconButton","_styles","_debug","_lodashEs","_renderUi","_keys","_keysLayout","_commonStyles","_mathliveInstance","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","ownKeys","r","Object","keys","getOwnPropertySymbols","filter","getOwnPropertyDescriptor","enumerable","push","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","log","debug","SLANTED_LABELS","SLANT","SLANTED_STROKE","SLANTED_SCALE_Y","LabelHolder","styled","shouldForwardProp","prop","_ref","slanted","transform","concat","WebkitTextStroke","pointerEvents","textTransform","color","text","display","textAlign","lineHeight","maxWidth","overflow","backgroundColor","keypadEmptyPlaceholder","undefined","opacity","rootIndexStyles","LatexLabel","exports","_React$Component","props","_this","_classCallCheck2","state","markup","latexToMarkup","latex","_inherits2","_createClass2","key","value","_componentDidMount","_asyncToGenerator2","_regenerator","mark","_callee","wrap","_context","prev","next","abrupt","loadMathLive","unmounted","setState","warned","stop","componentDidMount","componentDidUpdate","prevProps","componentWillUnmount","render","createElement","includes","dangerouslySetInnerHTML","__html","React","Component","PropTypes","string","isRequired","createCustomLayout","layoutObj","gridTemplateColumns","columns","gridTemplateRows","rows","gridAutoFlow","KeyPadContainer","commonKeyboardStyles","width","gridRowGap","gridColumnGap","fontFamily","buttonBackground","category","keypadButtonOperator","keypadButton","keypadButtonOperatorHover","keypadButtonHover","StyledButton","Button","_ref2","isDelete","isComma","isDot","minWidth","fontSize","borderRadius","StyledLatexButtonWrapper","_ref3","padding","margin","StyledIconButton","IconButton","_ref4","height","KeyPad","_React$Component2","_this2","setKeypadInteraction","onPress","base","extras","flatten","_toConsumableArray2","sortKeys","noDecimal","write","label","keypadRef","createRef","_this$keypadRef","keyPadElement","current","mainContainer","closest","currentToolbar","controlledKeypadMode","mainContainerPosition","getBoundingClientRect","currentToolbarPosition","difference","top","totalHeight","style","addEventListener","handleKeypadInteraction","_this$keypadRef2","removeEventListener","_this3","_this$props","className","baseSet","additionalKeys","layoutForKeyPad","onFocus","mode","noBaseSet","keysWithoutBaseSet","allKeys","flowKeys","shift","Math","floor","ref","join","map","k","index","command","extra","actions","extraProps","onClick","buttonClick","bind","disabled","keyIsNotAllowed","ariaLabel","name","_extends2","Icon","icon","tabIndex","size","bool","array","object","func","oneOfType","number","_default"],"sources":["../../src/keypad/index.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Button from '@mui/material/Button';\nimport IconButton from '@mui/material/IconButton';\nimport { styled } from '@mui/material/styles';\nimport debug from 'debug';\nimport { flatten } from 'lodash-es';\nimport { color } from '@pie-lib/render-ui';\n\nimport { baseSet } from '../keys';\nimport { sortKeys } from './keys-layout';\nimport { commonKeyboardStyles, rootIndexStyles } from '../mf/common-styles';\nimport { loadMathLive, latexToMarkup } from '../mathlive-instance';\n\nconst log = debug('pie-lib:math-input-mathlive:keypad');\n\n/**\n * A LaTeX keypad label.\n *\n * The MathQuill implementation rendered every LaTeX label as its own\n * `MQ.StaticMath` instance. Here each label is static HTML produced once by\n * `convertLatexToMarkup`, so a 40-key keypad no longer creates 40 live math\n * instances.\n */\n// Labels that the legacy keypad drew slanted. MathQuill styled `\\parallel` as\n// italic, which slants the two bars; MathLive draws it upright. A skew is used\n// rather than `font-style: italic` so the slant does not depend on the font\n// having an italic face for this glyph.\nconst SLANTED_LABELS = ['\\\\parallel'];\nconst SLANT = 'skewX(-15deg)';\n// MathLive's `∥` has hairline bars next to the radical sign and the other keys, so\n// they are thickened with a text stroke and stretched a little taller.\nconst SLANTED_STROKE = '0.03em currentColor';\nconst SLANTED_SCALE_Y = 1.25;\n\n// The `color.*()` helpers must be called lazily, inside the styled callback.\n// Evaluating them in a plain object literal runs them at module load, which\n// breaks any consumer that mocks a subset of @pie-lib/render-ui.\nconst LabelHolder = styled('span', { shouldForwardProp: (prop) => prop !== 'slanted' })(({ slanted }) => ({\n ...(slanted && {\n transform: `${SLANT} scaleY(${SLANTED_SCALE_Y})`,\n '& *': { WebkitTextStroke: SLANTED_STROKE },\n }),\n pointerEvents: 'none',\n textTransform: 'none',\n color: color.text(),\n // Deliberately inline-block, NOT inline-flex: MathLive's markup relies on\n // normal inline flow. Making its spans flex items collapses their width, and\n // stretchy accents render an <svg width=\"100%\" preserveAspectRatio=\"none\">\n // that then squeezes into a spike instead of spanning the content.\n display: 'inline-block',\n textAlign: 'center',\n lineHeight: 1,\n // Keep a label from sizing its grid column. `overflow: hidden` also collapses\n // the label's min-content contribution, so a wide accent cannot drag the\n // column across the screen. The svg's own positioning is left to\n // mathlive-static.css (injected by the package) - duplicating it here broke\n // the accent's containing block.\n maxWidth: '100%',\n overflow: 'hidden',\n // Answer-block / empty-slot boxes inside a label.\n '& .ML__placeholder': {\n backgroundColor: color.keypadEmptyPlaceholder ? color.keypadEmptyPlaceholder() : undefined,\n },\n // The stand-in glyph for an empty argument slot (see EMPTY_SLOT). Muted so it\n // reads as \"a slot goes here\" rather than as part of the symbol, matching how\n // MathQuill shaded `.mq-empty`.\n '& [data-pie-empty]': {\n opacity: 0.5,\n },\n // A readable index on the nth-root key. Carried by the label itself, not only\n // by the keypad container, so it holds wherever a LatexLabel is mounted.\n ...rootIndexStyles,\n}));\n\nexport class LatexLabel extends React.Component {\n static propTypes = {\n latex: PropTypes.string.isRequired,\n };\n\n constructor(props) {\n super(props);\n this.state = { markup: latexToMarkup(props.latex) };\n }\n\n async componentDidMount() {\n // MathLive may not have finished loading when the keypad first mounts.\n if (this.state.markup) {\n return;\n }\n\n await loadMathLive();\n\n if (this.unmounted) {\n return;\n }\n\n const markup = latexToMarkup(this.props.latex);\n\n if (markup) {\n this.setState({ markup });\n return;\n }\n\n // Still nothing: the engine is genuinely unavailable (a missing chunk, a\n // blocked request). Keep the raw-latex fallback visible rather than an\n // empty button, and log once so this is diagnosable.\n if (!LatexLabel.warned) {\n LatexLabel.warned = true;\n log('MathLive unavailable - keypad labels are falling back to raw latex');\n }\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.latex !== this.props.latex) {\n this.setState({ markup: latexToMarkup(this.props.latex) });\n }\n }\n\n componentWillUnmount() {\n this.unmounted = true;\n }\n\n render() {\n const { markup } = this.state;\n\n // Fall back to the raw latex so a button is never blank.\n return markup ? (\n // eslint-disable-next-line react/no-danger\n <LabelHolder slanted={SLANTED_LABELS.includes(this.props.latex)} dangerouslySetInnerHTML={{ __html: markup }} />\n ) : (\n <LabelHolder slanted={SLANTED_LABELS.includes(this.props.latex)}>{this.props.latex}</LabelHolder>\n );\n }\n}\n\nconst createCustomLayout = (layoutObj) => {\n if (layoutObj) {\n return {\n gridTemplateColumns: `repeat(${layoutObj.columns}, minmax(min-content, 150px))`,\n gridTemplateRows: `repeat(${layoutObj.rows}, minmax(40px, 60px))`,\n gridAutoFlow: 'initial',\n };\n }\n\n return {};\n};\n\nconst KeyPadContainer = styled('div')(() => ({\n ...commonKeyboardStyles,\n width: '100%',\n display: 'grid',\n gridTemplateRows: 'repeat(5, minmax(40px, 60px))',\n gridRowGap: '0px',\n gridColumnGap: '0px',\n gridAutoFlow: 'column',\n '&.character': {\n textTransform: 'initial !important',\n gridTemplateRows: 'repeat(5, minmax(40px, 50px)) !important',\n },\n '&.language': {\n gridTemplateRows: 'repeat(4, minmax(40px, 50px)) !important',\n '& *': {\n fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',\n },\n },\n}));\n\nconst buttonBackground = (category) => ({\n backgroundColor: category === 'operators' ? color.keypadButtonOperator() : color.keypadButton(),\n '&:hover': {\n backgroundColor: category === 'operators' ? color.keypadButtonOperatorHover() : color.keypadButtonHover(),\n },\n});\n\nconst StyledButton = styled(Button)(({ category, isDelete, isComma, isDot }) => ({\n minWidth: 'auto',\n textTransform: 'none',\n fontSize: isComma || isDot ? '200% !important' : '140% !important',\n lineHeight: isComma || isDot ? '100%' : 'normal',\n color: color.text(),\n ...buttonBackground(category),\n borderRadius: 0,\n ...(isDelete && {\n fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',\n }),\n}));\n\nconst StyledLatexButtonWrapper = styled(Button)(({ category }) => ({\n textTransform: 'none',\n padding: 0,\n margin: 0,\n fontSize: '110% !important',\n minWidth: 'auto',\n borderRadius: 0,\n ...buttonBackground(category),\n}));\n\nconst StyledIconButton = styled(IconButton)(({ category }) => ({\n minWidth: 'auto',\n ...buttonBackground(category),\n borderRadius: 0,\n '& .icon': {\n height: '30px',\n },\n}));\n\nexport class KeyPad extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n controlledKeypadMode: PropTypes.bool,\n baseSet: PropTypes.array,\n additionalKeys: PropTypes.array,\n layoutForKeyPad: PropTypes.object,\n onPress: PropTypes.func.isRequired,\n onFocus: PropTypes.func,\n noDecimal: PropTypes.bool,\n setKeypadInteraction: PropTypes.func,\n mode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n };\n\n static defaultProps = {\n baseSet: baseSet,\n noDecimal: false,\n };\n\n constructor(props) {\n super(props);\n this.keypadRef = React.createRef();\n }\n\n componentDidMount() {\n // Ensure MathLive is available for the LaTeX labels.\n loadMathLive();\n\n const keyPadElement = this.keypadRef?.current;\n const mainContainer = keyPadElement?.closest('.main-container');\n const currentToolbar = keyPadElement?.closest('.pie-toolbar');\n\n // need only for math keyboard so we need also controlledKeypadMode\n if (this.props.controlledKeypadMode && mainContainer && currentToolbar) {\n const mainContainerPosition = mainContainer.getBoundingClientRect();\n const currentToolbarPosition = currentToolbar.getBoundingClientRect();\n const difference =\n mainContainerPosition.top +\n mainContainerPosition.height -\n (currentToolbarPosition.top + currentToolbarPosition.height);\n\n if (difference < 0) {\n const totalHeight = mainContainerPosition.height + mainContainerPosition.top - difference;\n\n mainContainer.style.height = `${totalHeight}px`;\n }\n }\n\n if (keyPadElement) {\n keyPadElement.addEventListener('touchstart', this.handleKeypadInteraction, true);\n keyPadElement.addEventListener('mousedown', this.handleKeypadInteraction, true);\n }\n }\n\n componentWillUnmount() {\n const keyPadElement = this.keypadRef?.current;\n\n if (this.props.controlledKeypadMode && keyPadElement) {\n const mainContainer = keyPadElement.closest('.main-container');\n\n if (mainContainer) {\n mainContainer.style.height = 'unset';\n }\n }\n\n if (keyPadElement) {\n keyPadElement.removeEventListener('touchstart', this.handleKeypadInteraction, true);\n keyPadElement.removeEventListener('mousedown', this.handleKeypadInteraction, true);\n }\n }\n\n handleKeypadInteraction = () => {\n if (this.props.setKeypadInteraction) {\n this.props.setKeypadInteraction(true);\n }\n };\n\n buttonClick = (key) => {\n log('[buttonClick]', key);\n this.props.onPress(key);\n };\n\n flowKeys = (base, extras) => flatten([...sortKeys(base), ...sortKeys(extras)]);\n\n keyIsNotAllowed = (key) => {\n const { noDecimal } = this.props;\n\n return !!(((key.write === '.' && key.label === '.') || (key.write === ',' && key.label === ',')) && noDecimal);\n };\n\n render() {\n const { className, baseSet: base, additionalKeys, layoutForKeyPad, onFocus, mode } = this.props;\n\n const noBaseSet = ['non-negative-integers', 'integers', 'decimals', 'fractions', 'item-authoring', 'language'];\n const keysWithoutBaseSet = noBaseSet.includes(mode);\n const allKeys = keysWithoutBaseSet\n ? this.flowKeys([], additionalKeys || [])\n : this.flowKeys(base, additionalKeys || []);\n\n const shift = allKeys.length % 5 ? 1 : 0;\n const style = {\n gridTemplateColumns: `repeat(${Math.floor(allKeys.length / 5) + shift}, minmax(min-content, 150px))`,\n ...createCustomLayout(layoutForKeyPad),\n };\n\n return (\n <KeyPadContainer\n ref={this.keypadRef}\n className={[className, mode].filter(Boolean).join(' ')}\n style={style}\n onFocus={onFocus}\n >\n {allKeys.map((k, index) => {\n if (!k) {\n return <span key={`empty-${index}`} />;\n }\n\n const key = `${k.label || k.latex || k.command}-${index}`;\n const category = !keysWithoutBaseSet ? k.category : undefined;\n const extra = { ...(k.actions || {}), ...(k.extraProps || {}) };\n const onClick = this.buttonClick.bind(this, k);\n const disabled = this.keyIsNotAllowed(k);\n const ariaLabel = k.ariaLabel ? k.ariaLabel : k.name || k.label;\n\n if (k.latex) {\n return (\n <StyledLatexButtonWrapper\n key={key}\n onClick={onClick}\n disabled={disabled}\n category={category}\n aria-label={ariaLabel}\n {...extra}\n >\n <LatexLabel latex={k.latex} />\n </StyledLatexButtonWrapper>\n );\n }\n\n if (k.label) {\n return (\n <StyledButton\n key={key}\n onClick={onClick}\n disabled={disabled}\n category={category}\n isDelete={k.label === '⌫'}\n isComma={k.label === ','}\n isDot={k.label === '.'}\n aria-label={ariaLabel}\n {...extra}\n >\n {k.label}\n </StyledButton>\n );\n }\n\n const Icon = k.icon ? k.icon : 'div';\n\n return (\n <StyledIconButton\n key={key}\n tabIndex={'-1'}\n onClick={onClick}\n disabled={disabled}\n category={category}\n size=\"large\"\n {...extra}\n >\n <Icon className=\"icon\" />\n </StyledIconButton>\n );\n })}\n </KeyPadContainer>\n );\n }\n}\n\nexport default KeyPad;\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA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4G,IAAI;EACpCjC,OAAO,EAAE3E,qBAAS,CAAC6G,KAAK;EACxBjC,cAAc,EAAE5E,qBAAS,CAAC6G,KAAK;EAC/BhC,eAAe,EAAE7E,qBAAS,CAAC8G,MAAM;EACjCnE,OAAO,EAAE3C,qBAAS,CAAC+G,IAAI,CAAC7G,UAAU;EAClC4E,OAAO,EAAE9E,qBAAS,CAAC+G,IAAI;EACvB9D,SAAS,EAAEjD,qBAAS,CAAC4G,IAAI;EACzBlE,oBAAoB,EAAE1C,qBAAS,CAAC+G,IAAI;EACpChC,IAAI,EAAE/E,qBAAS,CAACgH,SAAS,CAAC,CAAChH,qBAAS,CAACC,MAAM,EAAED,qBAAS,CAACiH,MAAM,CAAC;AAChE,CAAC;AAAA,IAAA1L,gBAAA,aAZUgH,MAAM,kBAcK;EACpBoC,OAAO,EAAEA,aAAO;EAChB1B,SAAS,EAAE;AACb,CAAC;AAAA,IAAAiE,QAAA,GAAAzJ,OAAA,cAiKY8E,MAAM","ignoreList":[]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.withVisibleEmptySlots = exports.toNativeCommands = exports.toMathLive = exports.keyToAction = exports.fromMathLive = exports.fieldIds = exports.NEWLINE_EMBED = exports.KEYSTROKES = exports.DEFAULT_FIELD_ID = exports.COMMANDS_WITH_ARGS = void 0;
6
+ exports.withVisibleEmptySlots = exports.toNativeCommands = exports.toMathLive = exports.toCanonicalCommands = exports.keyToAction = exports.fromMathLive = exports.fieldIds = exports.NEWLINE_EMBED = exports.MATHQUILL_ALIASES = exports.KEYSTROKES = exports.DEFAULT_FIELD_ID = exports.COMMANDS_WITH_ARGS = void 0;
7
7
  /**
8
8
  * LaTeX translation layer between the MathQuill-era content model and MathLive.
9
9
  *
@@ -75,6 +75,35 @@ var DEFAULT_FIELD_ID = exports.DEFAULT_FIELD_ID = 'r1';
75
75
  */
76
76
  var EMPTY_SLOT = '\\htmlData{pie-empty=1}{\\rule{0.55em}{0.55em}}';
77
77
  var EMPTY_GROUP_REGEX = /\{\s*\}/g;
78
+ // The segment key (`\overline{}`). The keypad centres every label in its cell, and
79
+ // a thin bar is a much shorter label than the ray and line keys' stretchy arrows,
80
+ // so by default both its bar and its box sit off from theirs: the bar is lower
81
+ // than the arrows' shafts, and the box higher than theirs. Two zero-width struts
82
+ // fix that, found by rendering the three keys at 14-28px and measuring:
83
+ // - inside the bar, above the box: pushes the bar up to the height of the
84
+ // arrows' shafts (the bar-to-box distance then matches theirs);
85
+ // - before the bar, from the baseline: raises the label's top, which moves the
86
+ // whole label down so the box lands where theirs does.
87
+ var EMPTY_OVERLINE_REGEX = /\\overline\{\s*\}/g;
88
+ var EMPTY_OVERLINE_BAR_STRUT = '\\rule{0em}{0.87em}';
89
+ var EMPTY_OVERLINE_LABEL_STRUT = '\\rule{0em}{1.3em}';
90
+ // Empty delimiter pairs: `\abs{}` is converted to `\left|\right|`, and the
91
+ // parenthesis / bracket keys are `\left(\right)` / `\left[\right]`. None has a
92
+ // `{}` group for the rule above to catch, so they would render as bare fences.
93
+ var EMPTY_FENCE_REGEX = /\\left([([|])\s*\\right([)\]|])/g;
94
+ // The same muted fill as the other slots (`pie-empty`), but a tall rectangle
95
+ // rather than a square. It also sets the fences' height: `\left...\right` stretch
96
+ // to their content, so a taller slot gives taller parentheses.
97
+ //
98
+ // A `\rule` stands on the baseline, but the fences are centred on the math axis
99
+ // (0.25em above it), so an un-lifted box sat high between them. `[-0.25em]`
100
+ // lowers it by (axis - height / 2) = 0.25 - 1 / 2, centring it on the axis.
101
+ //
102
+ // Lowering it alone also shrinks the fences, which size themselves to their
103
+ // content (MathLive switches to short bars). The zero-width `\rule{0em}{1em}`
104
+ // strut keeps the content as tall as before, so the bars keep their height and
105
+ // only the box moves.
106
+ var EMPTY_FENCE_SLOT = '\\rule{0em}{1em}\\htmlData{pie-empty=1}{\\rule[-0.25em]{0.55em}{1em}}';
78
107
 
79
108
  /**
80
109
  * Make empty argument slots visible, for static rendering.
@@ -86,7 +115,9 @@ var EMPTY_GROUP_REGEX = /\{\s*\}/g;
86
115
  * @returns {string}
87
116
  */
88
117
  var withVisibleEmptySlots = exports.withVisibleEmptySlots = function withVisibleEmptySlots(latex) {
89
- return (latex || '').replace(EMPTY_GROUP_REGEX, "{".concat(EMPTY_SLOT, "}"));
118
+ return (latex || '').replace(EMPTY_OVERLINE_REGEX, "".concat(EMPTY_OVERLINE_LABEL_STRUT, "\\overline{").concat(EMPTY_OVERLINE_BAR_STRUT).concat(EMPTY_SLOT, "}")).replace(EMPTY_GROUP_REGEX, "{".concat(EMPTY_SLOT, "}")).replace(EMPTY_FENCE_REGEX, function (_m, open, close) {
119
+ return "\\left".concat(open).concat(EMPTY_FENCE_SLOT, "\\right").concat(close);
120
+ });
90
121
  };
91
122
 
92
123
  /**
@@ -228,6 +259,127 @@ var toMathLive = exports.toMathLive = function toMathLive(latex) {
228
259
  return out;
229
260
  };
230
261
 
262
+ /**
263
+ * Keypad command names that MathQuill treated as ALIASES of a different command.
264
+ *
265
+ * MathQuill registered `\\divide` as another name for `\\div` (and
266
+ * `\\perpendicular` for `\\perp`), so pressing the key stored the real command.
267
+ * MathLive only knows these names through `PIE_MACROS`, and serialises a macro
268
+ * under its own name - so `\\divide` reached storage verbatim, where MathJax
269
+ * (@pie-lib/math-rendering) has no such command and renders it as red text.
270
+ *
271
+ * Every other keypad command already matches what MathQuill stored (`\\degree`,
272
+ * `\\nsim`, `\\ncong`, `\\nparallel`, `\\square`, `\\napprox`,
273
+ * `\\parallelogram`), and MathJax understands those.
274
+ */
275
+ var MATHQUILL_ALIASES = exports.MATHQUILL_ALIASES = {
276
+ '\\divide': '\\div',
277
+ '\\perpendicular': '\\perp'
278
+ };
279
+
280
+ // Whole command names only: `\\divideontimes` is a real AMS symbol.
281
+ var MATHQUILL_ALIAS_REGEX = /\\(divide|perpendicular)(?![a-zA-Z])/g;
282
+
283
+ /**
284
+ * Primes. MathLive turns a prime that follows a base into a superscript atom and
285
+ * serialises it as `^{\\prime}`, or `^{\\doubleprime}` for the keypad's double
286
+ * prime key (`5''` comes back out as `5^{\\doubleprime}`). MathJax has no
287
+ * `\\doubleprime`, and two adjacent `^{\\prime}` groups - what typing `'` twice
288
+ * produces - are a "double exponent" error. MathQuill stored plain apostrophes,
289
+ * which both MathJax and MathLive read as primes, so store those.
290
+ *
291
+ * Only a superscript made of primes alone is rewritten: `x^{\\prime 2}` keeps
292
+ * its group, since it holds more than primes.
293
+ */
294
+ var PRIME_SUPERSCRIPT_REGEX = /\^\{((?:\s*\\(?:prime|doubleprime)(?![a-zA-Z]))+)\s*\}/g;
295
+ var BARE_DOUBLEPRIME_REGEX = /\\doubleprime(?![a-zA-Z])/g;
296
+ var primesToApostrophes = function primesToApostrophes(primes) {
297
+ return (
298
+ // eslint-disable-next-line quotes
299
+ "'".repeat((primes.match(/\\prime(?![a-zA-Z])/g) || []).length + 2 * (primes.match(BARE_DOUBLEPRIME_REGEX) || []).length)
300
+ );
301
+ };
302
+ var BARE_PRIME_COMMAND_REGEX = /^\\(doubleprime|prime)(?![a-zA-Z])/;
303
+
304
+ /**
305
+ * Primes that are *not* in a superscript.
306
+ *
307
+ * MathLive emits bare `\prime` / `\doubleprime` for a `′` or `″` typed or pasted
308
+ * as a character (`5′6″` serialises as `5\prime6\doubleprime`). A bare `\prime`
309
+ * is a full-size glyph in MathJax, while `''` is a superscript, so storing
310
+ * `5\prime6''` drew the single prime visibly larger than each stroke of the
311
+ * double prime. Both become apostrophes, the superscript primes MathQuill
312
+ * stored, so they always match.
313
+ *
314
+ * Inside a script (`x^{\prime 2}`, `x^\prime`) a prime is already a
315
+ * superscript, and an apostrophe there would mean something else, so
316
+ * `\prime` is kept and `\doubleprime` (unknown to MathJax) becomes
317
+ * `\prime\prime`.
318
+ *
319
+ * @param {string} latex
320
+ * @returns {string}
321
+ */
322
+ var barePrimesToApostrophes = function barePrimesToApostrophes(latex) {
323
+ if (latex.indexOf('prime') === -1) {
324
+ return latex;
325
+ }
326
+
327
+ // One entry per open brace: is that group a super/subscript?
328
+ var groups = [];
329
+ var out = '';
330
+ var i = 0;
331
+ while (i < latex.length) {
332
+ var ch = latex[i];
333
+ if (ch === '\\') {
334
+ var match = latex.slice(i).match(BARE_PRIME_COMMAND_REGEX);
335
+ if (match) {
336
+ var isDouble = match[1] === 'doubleprime';
337
+ // `x^\prime`: the command is itself the script.
338
+ var isScriptArgument = /[\^_]\s*$/.test(out);
339
+ var inScript = isScriptArgument || groups.indexOf(true) !== -1;
340
+ if (inScript) {
341
+ out += isDouble ? '\\prime\\prime' : '\\prime';
342
+ } else {
343
+ // eslint-disable-next-line quotes
344
+ out += isDouble ? "''" : "'";
345
+ }
346
+ i += match[0].length;
347
+ continue;
348
+ }
349
+
350
+ // Copy any other command, or an escaped character such as `\{`, whole.
351
+ var command = latex.slice(i).match(/^\\(?:[a-zA-Z]+|.)/);
352
+ var text = command ? command[0] : ch;
353
+ out += text;
354
+ i += text.length;
355
+ continue;
356
+ }
357
+ if (ch === '{') {
358
+ groups.push(/[\^_]\s*$/.test(out));
359
+ } else if (ch === '}') {
360
+ groups.pop();
361
+ }
362
+ out += ch;
363
+ i += 1;
364
+ }
365
+ return out;
366
+ };
367
+
368
+ /**
369
+ * Rewrite what MathLive serialises into the form MathQuill stored: alias
370
+ * command names, and primes.
371
+ *
372
+ * @param {string} latex
373
+ * @returns {string}
374
+ */
375
+ var toCanonicalCommands = exports.toCanonicalCommands = function toCanonicalCommands(latex) {
376
+ return typeof latex === 'string' ? barePrimesToApostrophes(latex.replace(MATHQUILL_ALIAS_REGEX, function (m) {
377
+ return MATHQUILL_ALIASES[m];
378
+ }).replace(PRIME_SUPERSCRIPT_REGEX, function (_m, primes) {
379
+ return primesToApostrophes(primes);
380
+ })) : latex;
381
+ };
382
+
231
383
  /**
232
384
  * Convert latex out of MathLive back into the stored form, so items authored
233
385
  * with the MathLive editor remain readable by @pie-lib/math-rendering and by
@@ -263,7 +415,10 @@ var fromMathLive = exports.fromMathLive = function fromMathLive(latex) {
263
415
  return content;
264
416
  });
265
417
  out = out.replace(BARE_PLACEHOLDER_NO_ARG_REGEX, '');
266
- return out;
418
+
419
+ // Store the command MathQuill stored, not the alias - also heals latex that was
420
+ // saved with `\\divide` before the keypad resolved it.
421
+ return toCanonicalCommands(out);
267
422
  };
268
423
 
269
424
  /**
@@ -341,7 +496,7 @@ var keyToAction = exports.keyToAction = function keyToAction(key) {
341
496
  // each part and concatenate.
342
497
  var parts = Array.isArray(key.command) ? key.command : [key.command];
343
498
  var value = parts.map(function (c) {
344
- return COMMANDS_WITH_ARGS[c] || c;
499
+ return COMMANDS_WITH_ARGS[c] || MATHQUILL_ALIASES[c] || c;
345
500
  }).join('');
346
501
  return {
347
502
  type: 'insert',
@@ -1 +1 @@
1
- {"version":3,"file":"latex-bridge.js","names":["NEWLINE_EMBED","exports","NEWLINE_EMBED_REGEX","DISPLAYLINES_REGEX","MQ_FIELD_REGEX","PLACEHOLDER_REGEX","BARE_PLACEHOLDER_REGEX","BARE_PLACEHOLDER_NO_ARG_REGEX","DEFAULT_FIELD_ID","EMPTY_SLOT","EMPTY_GROUP_REGEX","withVisibleEmptySlots","latex","replace","concat","toNativeCommands","out","replaceAbs","escapeBareComments","indexOf","backslashes","i","length","ch","idx","open","depth","close","inner","slice","fieldIds","match","lastIndex","exec","push","toMathLive","_m","id","content","split","join","fromMathLive","trim","map","s","COMMANDS_WITH_ARGS","_","KEYSTROKES","Left","Right","Backspace","Delete","Up","Down","keyToAction","key","undefined","command","type","value","write","parts","Array","isArray","c","keystroke","selector"],"sources":["../src/latex-bridge.js"],"sourcesContent":["/**\n * LaTeX translation layer between the MathQuill-era content model and MathLive.\n *\n * Two independent concerns live here:\n *\n * 1. Newlines. MathQuill had no line break, so pie-lib registered a custom\n * `newLine` embed that serialises to `\\embed{newLine}[]`. MathLive has no\n * embed system but supports real multiline environments, so we translate\n * `\\embed{newLine}[]` <-> `\\\\` inside `\\displaylines{}`.\n *\n * Authored content keeps its `\\embed{newLine}[]` on-disk form (that is what\n * @pie-lib/math-rendering already normalises for MathJax), so each renderer\n * normalises at its own boundary and stored items stay compatible.\n *\n * 2. Keypad key -> MathLive action. MathQuill keys carry `write`/`command`/\n * `keystroke` built for `mf.write()` / `mf.cmd()` / `mf.keystroke()`.\n * MathLive has `insert()` and `executeCommand()` instead.\n */\n\nexport const NEWLINE_EMBED = '\\\\embed{newLine}[]';\nconst NEWLINE_EMBED_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst DISPLAYLINES_REGEX = /^\\\\displaylines\\{([\\s\\S]*)\\}$/;\n\n/**\n * MathQuill's editable sub-field syntax, e.g. `\\MathQuillMathField[r1]{}`.\n * These are the answer blocks in templated math items; MathLive expresses the\n * same idea as `\\placeholder[id]{}` and reads them back via the prompts API.\n */\nconst MQ_FIELD_REGEX = /\\\\MathQuillMathField\\[([^\\]]*)\\]\\{([^{}]*)\\}/g;\nconst PLACEHOLDER_REGEX = /\\\\placeholder\\[([^\\]]*)\\]\\{([^{}]*)\\}/g;\n\n/**\n * Unnamed placeholders, which MathLive inserts on its own.\n *\n * Typing a command with empty arguments (`\\longdiv{}`, `\\frac{}{}`) makes\n * MathLive serialise the empty slots as `\\placeholder{}`. That token is\n * MathLive-specific: MathJax - which @pie-lib/math-rendering uses to render\n * prompts and previews - has no such command and renders it as red error text.\n * Stored latex must therefore keep plain empty groups.\n */\nconst BARE_PLACEHOLDER_REGEX = /\\\\placeholder\\{([^{}]*)\\}/g;\nconst BARE_PLACEHOLDER_NO_ARG_REGEX = /\\\\placeholder(?![[{a-zA-Z])/g;\n\n/** Default id used when stored latex has an unnamed field. */\nexport const DEFAULT_FIELD_ID = 'r1';\n\n/**\n * A visible stand-in for an empty argument slot, used for STATIC rendering only.\n *\n * Stored latex legitimately contains empty groups - `\\longdiv{}`, `\\frac{}{}`,\n * `x^{}` - to express a command's shape. MathQuill drew those as a shaded box\n * (`.mq-empty`); MathLive renders `{}` as nothing, so `convertLatexToMarkup`\n * output comes out completely blank (not even the surrounding bracket, in the\n * case of `\\enclose{longdiv}{}`).\n *\n * `\\placeholder{}` is not usable here: in static markup it renders as a\n * non-breaking space, because its editable box only exists inside a live\n * mathfield. So something with real width is required.\n *\n * It must be a `\\rule`, not a unicode glyph. A glyph's width comes from font\n * metrics, and U+25AB is not in the KaTeX fonts - the browser substitutes a\n * wider fallback while MathLive still sizes surrounding accents from its own\n * metrics. That left stretchy accents (`\\overarc`, `\\overleftrightarrow`)\n * visibly narrower than the box they were meant to span. A rule carries an\n * explicit em width, so accents size correctly - and a filled box is closer to\n * MathQuill's `.mq-empty` anyway.\n *\n * Live mathfields need none of this - MathLive manages empty slots itself.\n */\nconst EMPTY_SLOT = '\\\\htmlData{pie-empty=1}{\\\\rule{0.55em}{0.55em}}';\nconst EMPTY_GROUP_REGEX = /\\{\\s*\\}/g;\n\n/**\n * Make empty argument slots visible, for static rendering.\n *\n * Display-only: never feed the result to a mathfield or to storage - the\n * original latex is what gets typed and saved.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const withVisibleEmptySlots = (latex) => (latex || '').replace(EMPTY_GROUP_REGEX, `{${EMPTY_SLOT}}`);\n\n/**\n * Pie commands that take an argument, and their native MathLive equivalents.\n *\n * These MUST NOT be handled as MathLive macros. A macro is serialised from the\n * arguments it was created with, so text typed inside its expansion never makes\n * it back out: `getValue('latex')` keeps returning `\\longdiv{\\placeholder{}}`\n * while `getValue('ascii-math')` shows the typed content. Setting\n * `captureSelection: false` lets the cursor in but does not change\n * serialisation.\n *\n * Expanding to native constructs instead gives real, editable atoms that\n * round-trip. All three targets are understood by MathJax too, so stored latex\n * still renders in @pie-lib/math-rendering without a reverse mapping.\n */\n/**\n * Rewrite argument-taking pie commands into native MathLive latex.\n * Applied on the way *into* a mathfield.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const toNativeCommands = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n let out = latex;\n\n // \\abs{x} -> \\left|x\\right| needs brace-aware handling, the rest are prefix\n // swaps.\n out = replaceAbs(out);\n out = out.replace(/\\\\longdiv\\{/g, '\\\\enclose{longdiv}{');\n out = out.replace(/\\\\overarc\\{/g, '\\\\overparen{');\n out = escapeBareComments(out);\n\n return out;\n};\n\n/**\n * Escape an unescaped `%`.\n *\n * In real LaTeX `%` starts a comment, so MathLive discards it *and everything\n * after it*: `50%` renders as `50`, and `x%y` as just `x`. MathQuill had no\n * such notion - it treated `%` as a symbol - so latex from anywhere outside the\n * keypad may still carry a bare one.\n *\n * Only a `%` preceded by an even number of backslashes is bare: `\\%` is already\n * escaped, while the `%` in `\\\\%` (a line break, then a comment) is not.\n *\n * @param {string} latex\n * @returns {string}\n */\nconst escapeBareComments = (latex) => {\n if (latex.indexOf('%') === -1) {\n return latex;\n }\n\n let out = '';\n // Consecutive backslashes immediately before the current character.\n let backslashes = 0;\n\n for (let i = 0; i < latex.length; i++) {\n const ch = latex[i];\n\n out += ch === '%' && backslashes % 2 === 0 ? '\\\\%' : ch;\n backslashes = ch === '\\\\' ? backslashes + 1 : 0;\n }\n\n return out;\n};\n\n/** `\\abs{x}` -> `\\left|x\\right|`, matching balanced braces. */\nconst replaceAbs = (latex) => {\n let out = latex;\n let idx = out.indexOf('\\\\abs{');\n\n while (idx !== -1) {\n const open = idx + '\\\\abs{'.length - 1;\n let depth = 0;\n let close = -1;\n\n for (let i = open; i < out.length; i++) {\n if (out[i] === '{') depth++;\n else if (out[i] === '}') {\n depth--;\n if (depth === 0) {\n close = i;\n break;\n }\n }\n }\n\n if (close === -1) {\n break;\n }\n\n const inner = out.slice(open + 1, close);\n\n out = `${out.slice(0, idx)}\\\\left|${inner}\\\\right|${out.slice(close + 1)}`;\n idx = out.indexOf('\\\\abs{');\n }\n\n return out;\n};\n\n/**\n * Ids of the answer blocks in a piece of stored latex, in document order.\n *\n * @param {string} latex\n * @returns {string[]}\n */\nexport const fieldIds = (latex) => {\n if (typeof latex !== 'string') {\n return [];\n }\n\n const out = [];\n let match;\n\n MQ_FIELD_REGEX.lastIndex = 0;\n\n while ((match = MQ_FIELD_REGEX.exec(latex)) !== null) {\n out.push(match[1] || DEFAULT_FIELD_ID);\n }\n\n return out;\n};\n\n/**\n * Convert stored latex (which may contain `\\embed{newLine}[]`) into latex that\n * MathLive can parse and render as multiple lines.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const toMathLive = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n // Argument-taking pie commands -> native constructs, so their content stays\n // editable and serialises back correctly (see toNativeCommands).\n let out = toNativeCommands(latex);\n\n // Answer blocks: \\MathQuillMathField[id]{x} -> \\placeholder[id]{x}\n out = out.replace(MQ_FIELD_REGEX, (_m, id, content) => `\\\\placeholder[${id || DEFAULT_FIELD_ID}]{${content}}`);\n\n // Newlines: \\embed{newLine}[] -> a multiline environment\n if (out.indexOf(NEWLINE_EMBED) !== -1) {\n out = `\\\\displaylines{${out.split(NEWLINE_EMBED_REGEX).join(' \\\\\\\\ ')}}`;\n }\n\n return out;\n};\n\n/**\n * Convert latex out of MathLive back into the stored form, so items authored\n * with the MathLive editor remain readable by @pie-lib/math-rendering and by\n * the existing MathQuill implementation.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const fromMathLive = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n const match = latex.trim().match(DISPLAYLINES_REGEX);\n let out = match ? match[1] : latex;\n\n // `\\\\` is the line separator inside a multiline environment.\n if (out.indexOf('\\\\\\\\') !== -1) {\n out = out\n .split(/\\s*\\\\\\\\\\s*/)\n .map((s) => s.trim())\n .join(NEWLINE_EMBED);\n }\n\n // Answer blocks: \\placeholder[id]{x} -> \\MathQuillMathField[id]{x}\n out = out.replace(\n PLACEHOLDER_REGEX,\n (_m, id, content) => `\\\\MathQuillMathField[${id || DEFAULT_FIELD_ID}]{${content}}`,\n );\n\n // Unnamed placeholders are MathLive's own representation of an empty slot and\n // must not reach storage or MathJax. Unwrap them: keep any content, drop the\n // command itself (the surrounding braces are already part of the host latex,\n // so re-adding them here would produce `\\longdiv{{}}`).\n out = out.replace(BARE_PLACEHOLDER_REGEX, (_m, content) => content);\n out = out.replace(BARE_PLACEHOLDER_NO_ARG_REGEX, '');\n\n return out;\n};\n\n/**\n * MathQuill `cmd()` semantics: commands that take arguments should land the\n * cursor inside the first argument. MathLive expresses that with `#?`\n * placeholders in the inserted latex.\n */\nconst COMMANDS_WITH_ARGS = {\n // An explicit \"blank over blank\" key: both slots start empty.\n '\\\\frac': '\\\\frac{#?}{#?}',\n // Division, which must behave like MathQuill's `/`: whatever precedes the\n // cursor becomes the numerator and the caret lands in the denominator. `#@`\n // is MathLive's token for \"the selection, or the item before the cursor\" -\n // this is exactly the template MathLive binds to the `/` key itself. Using\n // `#?` here instead produced an empty fraction and left the typed number\n // stranded outside it.\n '/': '\\\\frac{#@}{#?}',\n '\\\\sqrt': '\\\\sqrt{#?}',\n '\\\\nthroot': '\\\\sqrt[#?]{#?}',\n '\\\\overline': '\\\\overline{#?}',\n '\\\\overrightarrow': '\\\\overrightarrow{#?}',\n '\\\\overleftrightarrow': '\\\\overleftrightarrow{#?}',\n // Native forms, not the pie macros: a macro would not serialise the user's\n // typed content back out (see toNativeCommands).\n '\\\\overarc': '\\\\overparen{#?}',\n '\\\\longdiv': '\\\\enclose{longdiv}{#?}',\n '^': '^{#?}',\n _: '_{#?}',\n '(': '\\\\left(#?\\\\right)',\n '[': '\\\\left[#?\\\\right]',\n '|': '\\\\left|#?\\\\right|',\n};\n\n/**\n * MathQuill keystroke names -> MathLive command selectors.\n */\nconst KEYSTROKES = {\n Left: 'moveToPreviousChar',\n Right: 'moveToNextChar',\n Backspace: 'deleteBackward',\n Delete: 'deleteForward',\n Up: 'moveUp',\n Down: 'moveDown',\n};\n\n/**\n * Translate a keypad key definition into a MathLive action.\n *\n * Mirrors the precedence in @pie-lib/math-input's MathInput.keypadPress:\n * latex (unless a command is present) -> write -> command -> keystroke.\n *\n * @param {object} key\n * @returns {{type: 'insert'|'command', value: string}|undefined}\n */\nexport const keyToAction = (key) => {\n if (!key) {\n return undefined;\n }\n\n if (key.latex && !key.command) {\n return { type: 'insert', value: key.latex };\n }\n\n if (key.write) {\n return { type: 'insert', value: key.write };\n }\n\n if (key.command) {\n // Some keys carry an array of commands (e.g. Measured Angle is\n // ['m', '\\\\angle'], log-base-n is ['\\\\log', '_']). MathQuill's `cmd()`\n // applied them in sequence; MathLive inserts one latex string, so expand\n // each part and concatenate.\n const parts = Array.isArray(key.command) ? key.command : [key.command];\n const value = parts.map((c) => COMMANDS_WITH_ARGS[c] || c).join('');\n\n return { type: 'insert', value };\n }\n\n if (key.keystroke) {\n const selector = KEYSTROKES[key.keystroke];\n\n return selector ? { type: 'command', value: selector } : undefined;\n }\n\n return undefined;\n};\n\nexport { COMMANDS_WITH_ARGS, KEYSTROKES };\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,IAAMA,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,oBAAoB;AACjD,IAAME,mBAAmB,GAAG,yBAAyB;AACrD,IAAMC,kBAAkB,GAAG,+BAA+B;;AAE1D;AACA;AACA;AACA;AACA;AACA,IAAMC,cAAc,GAAG,+CAA+C;AACtE,IAAMC,iBAAiB,GAAG,wCAAwC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,sBAAsB,GAAG,4BAA4B;AAC3D,IAAMC,6BAA6B,GAAG,8BAA8B;;AAEpE;AACO,IAAMC,gBAAgB,GAAAP,OAAA,CAAAO,gBAAA,GAAG,IAAI;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,UAAU,GAAG,iDAAiD;AACpE,IAAMC,iBA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7C;EAEA,IAAIL,GAAG,CAACE,OAAO,EAAE;IACf;IACA;IACA;IACA;IACA,IAAMI,KAAK,GAAGC,KAAK,CAACC,OAAO,CAACR,GAAG,CAACE,OAAO,CAAC,GAAGF,GAAG,CAACE,OAAO,GAAG,CAACF,GAAG,CAACE,OAAO,CAAC;IACtE,IAAME,KAAK,GAAGE,KAAK,CAAClB,GAAG,CAAC,UAACqB,CAAC;MAAA,OAAKnB,kBAAkB,CAACmB,CAAC,CAAC,IAAIA,CAAC;IAAA,EAAC,CAACxB,IAAI,CAAC,EAAE,CAAC;IAEnE,OAAO;MAAEkB,IAAI,EAAE,QAAQ;MAAEC,KAAK,EAALA;IAAM,CAAC;EAClC;EAEA,IAAIJ,GAAG,CAACU,SAAS,EAAE;IACjB,IAAMC,QAAQ,GAAGnB,UAAU,CAACQ,GAAG,CAACU,SAAS,CAAC;IAE1C,OAAOC,QAAQ,GAAG;MAAER,IAAI,EAAE,SAAS;MAAEC,KAAK,EAAEO;IAAS,CAAC,GAAGV,SAAS;EACpE;EAEA,OAAOA,SAAS;AAClB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"latex-bridge.js","names":["NEWLINE_EMBED","exports","NEWLINE_EMBED_REGEX","DISPLAYLINES_REGEX","MQ_FIELD_REGEX","PLACEHOLDER_REGEX","BARE_PLACEHOLDER_REGEX","BARE_PLACEHOLDER_NO_ARG_REGEX","DEFAULT_FIELD_ID","EMPTY_SLOT","EMPTY_GROUP_REGEX","EMPTY_OVERLINE_REGEX","EMPTY_OVERLINE_BAR_STRUT","EMPTY_OVERLINE_LABEL_STRUT","EMPTY_FENCE_REGEX","EMPTY_FENCE_SLOT","withVisibleEmptySlots","latex","replace","concat","_m","open","close","toNativeCommands","out","replaceAbs","escapeBareComments","indexOf","backslashes","i","length","ch","idx","depth","inner","slice","fieldIds","match","lastIndex","exec","push","toMathLive","id","content","split","join","MATHQUILL_ALIASES","MATHQUILL_ALIAS_REGEX","PRIME_SUPERSCRIPT_REGEX","BARE_DOUBLEPRIME_REGEX","primesToApostrophes","primes","repeat","BARE_PRIME_COMMAND_REGEX","barePrimesToApostrophes","groups","isDouble","isScriptArgument","test","inScript","command","text","pop","toCanonicalCommands","m","fromMathLive","trim","map","s","COMMANDS_WITH_ARGS","_","KEYSTROKES","Left","Right","Backspace","Delete","Up","Down","keyToAction","key","undefined","type","value","write","parts","Array","isArray","c","keystroke","selector"],"sources":["../src/latex-bridge.js"],"sourcesContent":["/**\n * LaTeX translation layer between the MathQuill-era content model and MathLive.\n *\n * Two independent concerns live here:\n *\n * 1. Newlines. MathQuill had no line break, so pie-lib registered a custom\n * `newLine` embed that serialises to `\\embed{newLine}[]`. MathLive has no\n * embed system but supports real multiline environments, so we translate\n * `\\embed{newLine}[]` <-> `\\\\` inside `\\displaylines{}`.\n *\n * Authored content keeps its `\\embed{newLine}[]` on-disk form (that is what\n * @pie-lib/math-rendering already normalises for MathJax), so each renderer\n * normalises at its own boundary and stored items stay compatible.\n *\n * 2. Keypad key -> MathLive action. MathQuill keys carry `write`/`command`/\n * `keystroke` built for `mf.write()` / `mf.cmd()` / `mf.keystroke()`.\n * MathLive has `insert()` and `executeCommand()` instead.\n */\n\nexport const NEWLINE_EMBED = '\\\\embed{newLine}[]';\nconst NEWLINE_EMBED_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst DISPLAYLINES_REGEX = /^\\\\displaylines\\{([\\s\\S]*)\\}$/;\n\n/**\n * MathQuill's editable sub-field syntax, e.g. `\\MathQuillMathField[r1]{}`.\n * These are the answer blocks in templated math items; MathLive expresses the\n * same idea as `\\placeholder[id]{}` and reads them back via the prompts API.\n */\nconst MQ_FIELD_REGEX = /\\\\MathQuillMathField\\[([^\\]]*)\\]\\{([^{}]*)\\}/g;\nconst PLACEHOLDER_REGEX = /\\\\placeholder\\[([^\\]]*)\\]\\{([^{}]*)\\}/g;\n\n/**\n * Unnamed placeholders, which MathLive inserts on its own.\n *\n * Typing a command with empty arguments (`\\longdiv{}`, `\\frac{}{}`) makes\n * MathLive serialise the empty slots as `\\placeholder{}`. That token is\n * MathLive-specific: MathJax - which @pie-lib/math-rendering uses to render\n * prompts and previews - has no such command and renders it as red error text.\n * Stored latex must therefore keep plain empty groups.\n */\nconst BARE_PLACEHOLDER_REGEX = /\\\\placeholder\\{([^{}]*)\\}/g;\nconst BARE_PLACEHOLDER_NO_ARG_REGEX = /\\\\placeholder(?![[{a-zA-Z])/g;\n\n/** Default id used when stored latex has an unnamed field. */\nexport const DEFAULT_FIELD_ID = 'r1';\n\n/**\n * A visible stand-in for an empty argument slot, used for STATIC rendering only.\n *\n * Stored latex legitimately contains empty groups - `\\longdiv{}`, `\\frac{}{}`,\n * `x^{}` - to express a command's shape. MathQuill drew those as a shaded box\n * (`.mq-empty`); MathLive renders `{}` as nothing, so `convertLatexToMarkup`\n * output comes out completely blank (not even the surrounding bracket, in the\n * case of `\\enclose{longdiv}{}`).\n *\n * `\\placeholder{}` is not usable here: in static markup it renders as a\n * non-breaking space, because its editable box only exists inside a live\n * mathfield. So something with real width is required.\n *\n * It must be a `\\rule`, not a unicode glyph. A glyph's width comes from font\n * metrics, and U+25AB is not in the KaTeX fonts - the browser substitutes a\n * wider fallback while MathLive still sizes surrounding accents from its own\n * metrics. That left stretchy accents (`\\overarc`, `\\overleftrightarrow`)\n * visibly narrower than the box they were meant to span. A rule carries an\n * explicit em width, so accents size correctly - and a filled box is closer to\n * MathQuill's `.mq-empty` anyway.\n *\n * Live mathfields need none of this - MathLive manages empty slots itself.\n */\nconst EMPTY_SLOT = '\\\\htmlData{pie-empty=1}{\\\\rule{0.55em}{0.55em}}';\nconst EMPTY_GROUP_REGEX = /\\{\\s*\\}/g;\n// The segment key (`\\overline{}`). The keypad centres every label in its cell, and\n// a thin bar is a much shorter label than the ray and line keys' stretchy arrows,\n// so by default both its bar and its box sit off from theirs: the bar is lower\n// than the arrows' shafts, and the box higher than theirs. Two zero-width struts\n// fix that, found by rendering the three keys at 14-28px and measuring:\n// - inside the bar, above the box: pushes the bar up to the height of the\n// arrows' shafts (the bar-to-box distance then matches theirs);\n// - before the bar, from the baseline: raises the label's top, which moves the\n// whole label down so the box lands where theirs does.\nconst EMPTY_OVERLINE_REGEX = /\\\\overline\\{\\s*\\}/g;\nconst EMPTY_OVERLINE_BAR_STRUT = '\\\\rule{0em}{0.87em}';\nconst EMPTY_OVERLINE_LABEL_STRUT = '\\\\rule{0em}{1.3em}';\n// Empty delimiter pairs: `\\abs{}` is converted to `\\left|\\right|`, and the\n// parenthesis / bracket keys are `\\left(\\right)` / `\\left[\\right]`. None has a\n// `{}` group for the rule above to catch, so they would render as bare fences.\nconst EMPTY_FENCE_REGEX = /\\\\left([([|])\\s*\\\\right([)\\]|])/g;\n// The same muted fill as the other slots (`pie-empty`), but a tall rectangle\n// rather than a square. It also sets the fences' height: `\\left...\\right` stretch\n// to their content, so a taller slot gives taller parentheses.\n//\n// A `\\rule` stands on the baseline, but the fences are centred on the math axis\n// (0.25em above it), so an un-lifted box sat high between them. `[-0.25em]`\n// lowers it by (axis - height / 2) = 0.25 - 1 / 2, centring it on the axis.\n//\n// Lowering it alone also shrinks the fences, which size themselves to their\n// content (MathLive switches to short bars). The zero-width `\\rule{0em}{1em}`\n// strut keeps the content as tall as before, so the bars keep their height and\n// only the box moves.\nconst EMPTY_FENCE_SLOT = '\\\\rule{0em}{1em}\\\\htmlData{pie-empty=1}{\\\\rule[-0.25em]{0.55em}{1em}}';\n\n/**\n * Make empty argument slots visible, for static rendering.\n *\n * Display-only: never feed the result to a mathfield or to storage - the\n * original latex is what gets typed and saved.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const withVisibleEmptySlots = (latex) =>\n (latex || '')\n .replace(EMPTY_OVERLINE_REGEX, `${EMPTY_OVERLINE_LABEL_STRUT}\\\\overline{${EMPTY_OVERLINE_BAR_STRUT}${EMPTY_SLOT}}`)\n .replace(EMPTY_GROUP_REGEX, `{${EMPTY_SLOT}}`)\n .replace(EMPTY_FENCE_REGEX, (_m, open, close) => `\\\\left${open}${EMPTY_FENCE_SLOT}\\\\right${close}`);\n\n/**\n * Pie commands that take an argument, and their native MathLive equivalents.\n *\n * These MUST NOT be handled as MathLive macros. A macro is serialised from the\n * arguments it was created with, so text typed inside its expansion never makes\n * it back out: `getValue('latex')` keeps returning `\\longdiv{\\placeholder{}}`\n * while `getValue('ascii-math')` shows the typed content. Setting\n * `captureSelection: false` lets the cursor in but does not change\n * serialisation.\n *\n * Expanding to native constructs instead gives real, editable atoms that\n * round-trip. All three targets are understood by MathJax too, so stored latex\n * still renders in @pie-lib/math-rendering without a reverse mapping.\n */\n/**\n * Rewrite argument-taking pie commands into native MathLive latex.\n * Applied on the way *into* a mathfield.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const toNativeCommands = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n let out = latex;\n\n // \\abs{x} -> \\left|x\\right| needs brace-aware handling, the rest are prefix\n // swaps.\n out = replaceAbs(out);\n out = out.replace(/\\\\longdiv\\{/g, '\\\\enclose{longdiv}{');\n out = out.replace(/\\\\overarc\\{/g, '\\\\overparen{');\n out = escapeBareComments(out);\n\n return out;\n};\n\n/**\n * Escape an unescaped `%`.\n *\n * In real LaTeX `%` starts a comment, so MathLive discards it *and everything\n * after it*: `50%` renders as `50`, and `x%y` as just `x`. MathQuill had no\n * such notion - it treated `%` as a symbol - so latex from anywhere outside the\n * keypad may still carry a bare one.\n *\n * Only a `%` preceded by an even number of backslashes is bare: `\\%` is already\n * escaped, while the `%` in `\\\\%` (a line break, then a comment) is not.\n *\n * @param {string} latex\n * @returns {string}\n */\nconst escapeBareComments = (latex) => {\n if (latex.indexOf('%') === -1) {\n return latex;\n }\n\n let out = '';\n // Consecutive backslashes immediately before the current character.\n let backslashes = 0;\n\n for (let i = 0; i < latex.length; i++) {\n const ch = latex[i];\n\n out += ch === '%' && backslashes % 2 === 0 ? '\\\\%' : ch;\n backslashes = ch === '\\\\' ? backslashes + 1 : 0;\n }\n\n return out;\n};\n\n/** `\\abs{x}` -> `\\left|x\\right|`, matching balanced braces. */\nconst replaceAbs = (latex) => {\n let out = latex;\n let idx = out.indexOf('\\\\abs{');\n\n while (idx !== -1) {\n const open = idx + '\\\\abs{'.length - 1;\n let depth = 0;\n let close = -1;\n\n for (let i = open; i < out.length; i++) {\n if (out[i] === '{') depth++;\n else if (out[i] === '}') {\n depth--;\n if (depth === 0) {\n close = i;\n break;\n }\n }\n }\n\n if (close === -1) {\n break;\n }\n\n const inner = out.slice(open + 1, close);\n\n out = `${out.slice(0, idx)}\\\\left|${inner}\\\\right|${out.slice(close + 1)}`;\n idx = out.indexOf('\\\\abs{');\n }\n\n return out;\n};\n\n/**\n * Ids of the answer blocks in a piece of stored latex, in document order.\n *\n * @param {string} latex\n * @returns {string[]}\n */\nexport const fieldIds = (latex) => {\n if (typeof latex !== 'string') {\n return [];\n }\n\n const out = [];\n let match;\n\n MQ_FIELD_REGEX.lastIndex = 0;\n\n while ((match = MQ_FIELD_REGEX.exec(latex)) !== null) {\n out.push(match[1] || DEFAULT_FIELD_ID);\n }\n\n return out;\n};\n\n/**\n * Convert stored latex (which may contain `\\embed{newLine}[]`) into latex that\n * MathLive can parse and render as multiple lines.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const toMathLive = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n // Argument-taking pie commands -> native constructs, so their content stays\n // editable and serialises back correctly (see toNativeCommands).\n let out = toNativeCommands(latex);\n\n // Answer blocks: \\MathQuillMathField[id]{x} -> \\placeholder[id]{x}\n out = out.replace(MQ_FIELD_REGEX, (_m, id, content) => `\\\\placeholder[${id || DEFAULT_FIELD_ID}]{${content}}`);\n\n // Newlines: \\embed{newLine}[] -> a multiline environment\n if (out.indexOf(NEWLINE_EMBED) !== -1) {\n out = `\\\\displaylines{${out.split(NEWLINE_EMBED_REGEX).join(' \\\\\\\\ ')}}`;\n }\n\n return out;\n};\n\n/**\n * Keypad command names that MathQuill treated as ALIASES of a different command.\n *\n * MathQuill registered `\\\\divide` as another name for `\\\\div` (and\n * `\\\\perpendicular` for `\\\\perp`), so pressing the key stored the real command.\n * MathLive only knows these names through `PIE_MACROS`, and serialises a macro\n * under its own name - so `\\\\divide` reached storage verbatim, where MathJax\n * (@pie-lib/math-rendering) has no such command and renders it as red text.\n *\n * Every other keypad command already matches what MathQuill stored (`\\\\degree`,\n * `\\\\nsim`, `\\\\ncong`, `\\\\nparallel`, `\\\\square`, `\\\\napprox`,\n * `\\\\parallelogram`), and MathJax understands those.\n */\nconst MATHQUILL_ALIASES = {\n '\\\\divide': '\\\\div',\n '\\\\perpendicular': '\\\\perp',\n};\n\n// Whole command names only: `\\\\divideontimes` is a real AMS symbol.\nconst MATHQUILL_ALIAS_REGEX = /\\\\(divide|perpendicular)(?![a-zA-Z])/g;\n\n/**\n * Primes. MathLive turns a prime that follows a base into a superscript atom and\n * serialises it as `^{\\\\prime}`, or `^{\\\\doubleprime}` for the keypad's double\n * prime key (`5''` comes back out as `5^{\\\\doubleprime}`). MathJax has no\n * `\\\\doubleprime`, and two adjacent `^{\\\\prime}` groups - what typing `'` twice\n * produces - are a \"double exponent\" error. MathQuill stored plain apostrophes,\n * which both MathJax and MathLive read as primes, so store those.\n *\n * Only a superscript made of primes alone is rewritten: `x^{\\\\prime 2}` keeps\n * its group, since it holds more than primes.\n */\nconst PRIME_SUPERSCRIPT_REGEX = /\\^\\{((?:\\s*\\\\(?:prime|doubleprime)(?![a-zA-Z]))+)\\s*\\}/g;\nconst BARE_DOUBLEPRIME_REGEX = /\\\\doubleprime(?![a-zA-Z])/g;\n\nconst primesToApostrophes = (primes) =>\n // eslint-disable-next-line quotes\n \"'\".repeat(\n (primes.match(/\\\\prime(?![a-zA-Z])/g) || []).length + 2 * (primes.match(BARE_DOUBLEPRIME_REGEX) || []).length,\n );\n\nconst BARE_PRIME_COMMAND_REGEX = /^\\\\(doubleprime|prime)(?![a-zA-Z])/;\n\n/**\n * Primes that are *not* in a superscript.\n *\n * MathLive emits bare `\\prime` / `\\doubleprime` for a `′` or `″` typed or pasted\n * as a character (`5′6″` serialises as `5\\prime6\\doubleprime`). A bare `\\prime`\n * is a full-size glyph in MathJax, while `''` is a superscript, so storing\n * `5\\prime6''` drew the single prime visibly larger than each stroke of the\n * double prime. Both become apostrophes, the superscript primes MathQuill\n * stored, so they always match.\n *\n * Inside a script (`x^{\\prime 2}`, `x^\\prime`) a prime is already a\n * superscript, and an apostrophe there would mean something else, so\n * `\\prime` is kept and `\\doubleprime` (unknown to MathJax) becomes\n * `\\prime\\prime`.\n *\n * @param {string} latex\n * @returns {string}\n */\nconst barePrimesToApostrophes = (latex) => {\n if (latex.indexOf('prime') === -1) {\n return latex;\n }\n\n // One entry per open brace: is that group a super/subscript?\n const groups = [];\n let out = '';\n let i = 0;\n\n while (i < latex.length) {\n const ch = latex[i];\n\n if (ch === '\\\\') {\n const match = latex.slice(i).match(BARE_PRIME_COMMAND_REGEX);\n\n if (match) {\n const isDouble = match[1] === 'doubleprime';\n // `x^\\prime`: the command is itself the script.\n const isScriptArgument = /[\\^_]\\s*$/.test(out);\n const inScript = isScriptArgument || groups.indexOf(true) !== -1;\n\n if (inScript) {\n out += isDouble ? '\\\\prime\\\\prime' : '\\\\prime';\n } else {\n // eslint-disable-next-line quotes\n out += isDouble ? \"''\" : \"'\";\n }\n\n i += match[0].length;\n continue;\n }\n\n // Copy any other command, or an escaped character such as `\\{`, whole.\n const command = latex.slice(i).match(/^\\\\(?:[a-zA-Z]+|.)/);\n const text = command ? command[0] : ch;\n\n out += text;\n i += text.length;\n continue;\n }\n\n if (ch === '{') {\n groups.push(/[\\^_]\\s*$/.test(out));\n } else if (ch === '}') {\n groups.pop();\n }\n\n out += ch;\n i += 1;\n }\n\n return out;\n};\n\n/**\n * Rewrite what MathLive serialises into the form MathQuill stored: alias\n * command names, and primes.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const toCanonicalCommands = (latex) =>\n typeof latex === 'string'\n ? barePrimesToApostrophes(\n latex\n .replace(MATHQUILL_ALIAS_REGEX, (m) => MATHQUILL_ALIASES[m])\n .replace(PRIME_SUPERSCRIPT_REGEX, (_m, primes) => primesToApostrophes(primes)),\n )\n : latex;\n\n/**\n * Convert latex out of MathLive back into the stored form, so items authored\n * with the MathLive editor remain readable by @pie-lib/math-rendering and by\n * the existing MathQuill implementation.\n *\n * @param {string} latex\n * @returns {string}\n */\nexport const fromMathLive = (latex) => {\n if (typeof latex !== 'string' || !latex) {\n return latex || '';\n }\n\n const match = latex.trim().match(DISPLAYLINES_REGEX);\n let out = match ? match[1] : latex;\n\n // `\\\\` is the line separator inside a multiline environment.\n if (out.indexOf('\\\\\\\\') !== -1) {\n out = out\n .split(/\\s*\\\\\\\\\\s*/)\n .map((s) => s.trim())\n .join(NEWLINE_EMBED);\n }\n\n // Answer blocks: \\placeholder[id]{x} -> \\MathQuillMathField[id]{x}\n out = out.replace(\n PLACEHOLDER_REGEX,\n (_m, id, content) => `\\\\MathQuillMathField[${id || DEFAULT_FIELD_ID}]{${content}}`,\n );\n\n // Unnamed placeholders are MathLive's own representation of an empty slot and\n // must not reach storage or MathJax. Unwrap them: keep any content, drop the\n // command itself (the surrounding braces are already part of the host latex,\n // so re-adding them here would produce `\\longdiv{{}}`).\n out = out.replace(BARE_PLACEHOLDER_REGEX, (_m, content) => content);\n out = out.replace(BARE_PLACEHOLDER_NO_ARG_REGEX, '');\n\n // Store the command MathQuill stored, not the alias - also heals latex that was\n // saved with `\\\\divide` before the keypad resolved it.\n return toCanonicalCommands(out);\n};\n\n/**\n * MathQuill `cmd()` semantics: commands that take arguments should land the\n * cursor inside the first argument. MathLive expresses that with `#?`\n * placeholders in the inserted latex.\n */\nconst COMMANDS_WITH_ARGS = {\n // An explicit \"blank over blank\" key: both slots start empty.\n '\\\\frac': '\\\\frac{#?}{#?}',\n // Division, which must behave like MathQuill's `/`: whatever precedes the\n // cursor becomes the numerator and the caret lands in the denominator. `#@`\n // is MathLive's token for \"the selection, or the item before the cursor\" -\n // this is exactly the template MathLive binds to the `/` key itself. Using\n // `#?` here instead produced an empty fraction and left the typed number\n // stranded outside it.\n '/': '\\\\frac{#@}{#?}',\n '\\\\sqrt': '\\\\sqrt{#?}',\n '\\\\nthroot': '\\\\sqrt[#?]{#?}',\n '\\\\overline': '\\\\overline{#?}',\n '\\\\overrightarrow': '\\\\overrightarrow{#?}',\n '\\\\overleftrightarrow': '\\\\overleftrightarrow{#?}',\n // Native forms, not the pie macros: a macro would not serialise the user's\n // typed content back out (see toNativeCommands).\n '\\\\overarc': '\\\\overparen{#?}',\n '\\\\longdiv': '\\\\enclose{longdiv}{#?}',\n '^': '^{#?}',\n _: '_{#?}',\n '(': '\\\\left(#?\\\\right)',\n '[': '\\\\left[#?\\\\right]',\n '|': '\\\\left|#?\\\\right|',\n};\n\n/**\n * MathQuill keystroke names -> MathLive command selectors.\n */\nconst KEYSTROKES = {\n Left: 'moveToPreviousChar',\n Right: 'moveToNextChar',\n Backspace: 'deleteBackward',\n Delete: 'deleteForward',\n Up: 'moveUp',\n Down: 'moveDown',\n};\n\n/**\n * Translate a keypad key definition into a MathLive action.\n *\n * Mirrors the precedence in @pie-lib/math-input's MathInput.keypadPress:\n * latex (unless a command is present) -> write -> command -> keystroke.\n *\n * @param {object} key\n * @returns {{type: 'insert'|'command', value: string}|undefined}\n */\nexport const keyToAction = (key) => {\n if (!key) {\n return undefined;\n }\n\n if (key.latex && !key.command) {\n return { type: 'insert', value: key.latex };\n }\n\n if (key.write) {\n return { type: 'insert', value: key.write };\n }\n\n if (key.command) {\n // Some keys carry an array of commands (e.g. Measured Angle is\n // ['m', '\\\\angle'], log-base-n is ['\\\\log', '_']). MathQuill's `cmd()`\n // applied them in sequence; MathLive inserts one latex string, so expand\n // each part and concatenate.\n const parts = Array.isArray(key.command) ? key.command : [key.command];\n const value = parts.map((c) => COMMANDS_WITH_ARGS[c] || MATHQUILL_ALIASES[c] || c).join('');\n\n return { type: 'insert', value };\n }\n\n if (key.keystroke) {\n const selector = KEYSTROKES[key.keystroke];\n\n return selector ? { type: 'command', value: selector } : undefined;\n }\n\n return undefined;\n};\n\nexport { COMMANDS_WITH_ARGS, KEYSTROKES, MATHQUILL_ALIASES };\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,IAAMA,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,oBAAoB;AACjD,IAAME,mBAAmB,GAAG,yBAAyB;AACrD,IAAMC,kBAAkB,GAAG,+BAA+B;;AAE1D;AACA;AACA;AACA;AACA;AACA,IAAMC,cAAc,GAAG,+CAA+C;AACtE,IAAMC,iBAAiB,GAAG,wCAAwC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,sBAAsB,GAAG,4BAA4B;AAC3D,IAAMC,6BAA6B,GAAG,8BAA8B;;AAEpE;AACO,IAAMC,gBAAgB,GAAAP,OAAA,CAAAO,gBAAA,GAAG,IAAI;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,UAAU,GAAG,iDAAiD;AACpE,IAAMC,iBAAiB,GAAG,UAAU;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,oBAAoB,GAAG,oBAAoB;AACjD,IAAMC,wBAAwB,GAAG,qBAAqB;AACtD,IAAMC,0BAA0B,GAAG,oBAAoB;AACvD;AACA;AACA;AACA,IAAMC,iBAAiB,GAAG,kCAAkC;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,gBAAgB,GAAG,uEAAuE;;AAEhG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,qBAAqB,GAAAf,OAAA,CAAAe,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;EAEA,OAAOA,SAAS;AAClB,CAAC","ignoreList":[]}
@@ -25,7 +25,6 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
25
25
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
26
26
  var _debug = _interopRequireDefault(require("debug"));
27
27
  var _latexBridge = require("./latex-bridge");
28
- var _fonts = require("./fonts");
29
28
  var _commonStyles = require("./mf/common-styles");
30
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; }
31
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; }
@@ -75,7 +74,7 @@ var absoluteFontsDirectory = function absoluteFontsDirectory(dir) {
75
74
  };
76
75
 
77
76
  /**
78
- * Last-resort CDN for the KaTeX fonts.
77
+ * Version-pinned CDN fallback for the KaTeX fonts.
79
78
  *
80
79
  * Some symbols are composed from Private Use Area glyphs that exist only in
81
80
  * those fonts: `\\neq` is U+E020 (a negation slash) overlapped on `=`, and
@@ -83,10 +82,9 @@ var absoluteFontsDirectory = function absoluteFontsDirectory(dir) {
83
82
  * an arbitrary glyph for U+E020, so those keys render as garbage rather than
84
83
  * simply falling back to a plainer face.
85
84
  *
86
- * The fonts normally come from inside this package (see `./fonts`), so this URL
87
- * is only reached on a browser without the FontFace API, where MathLive has to
88
- * fetch the woff2 files itself. The version comes from MathLive, so the fonts
89
- * always match the engine.
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.
90
88
  */
91
89
  var FALLBACK_MATHLIVE_VERSION = '0.110.0';
92
90
  var cdnFontsDirectory = function cdnFontsDirectory() {
@@ -99,17 +97,15 @@ var cdnFontsDirectory = function cdnFontsDirectory() {
99
97
  /**
100
98
  * Tell the package where the MathLive fonts are served from.
101
99
  *
102
- * Optional: by default the fonts come from inside this package (see `./fonts`),
103
- * so nothing has to be served or configured. Call this before `loadMathLive()`
104
- * to point MathLive at your own copy instead - worth doing if the host already
105
- * serves the KaTeX woff2 files and would rather not carry them twice.
100
+ * Call before `loadMathLive()`.
106
101
  *
107
- * - a path/URL: served by you; the embedded fonts are not registered
108
- * - `null`: skip font loading entirely; note `\\neq`, `\\nsim` and `\\ncong`
109
- * then render incorrectly, being built from Private Use Area
110
- * glyphs that only these fonts have
111
- * - not called: the embedded fonts, with the CDN as a fallback for browsers
112
- * without the FontFace API
102
+ * - a path/URL: served by you, no third-party request
103
+ * - `null`: skip font loading; note `\\neq`, `\\nsim` and `\\ncong` then
104
+ * render incorrectly, being built from Private Use Area glyphs
105
+ * - not called: falls back to a version-pinned CDN
106
+ *
107
+ * The fonts ship inside the `mathlive` package (`node_modules/mathlive/fonts`)
108
+ * ready to copy into whatever the host app serves statically.
113
109
  *
114
110
  * @param {string|null} [dir]
115
111
  */
@@ -144,6 +140,9 @@ var PIE_MACROS = exports.PIE_MACROS = {
144
140
  // Argument-less symbols. Atomic is correct here: backspace should remove the
145
141
  // whole glyph, and there is nothing to type into.
146
142
  parallelogram: "\\htmlData{pie-macro=parallelogram}{\\unicode{\"25B1}}",
143
+ // Same glyph as the built-in `\\parallel` (U+2225), tagged so it can be sized -
144
+ // see `parallelStyles`.
145
+ parallel: "\\htmlData{pie-macro=parallel}{\\unicode{\"2225}}",
147
146
  napprox: '\\not\\approx',
148
147
  nsim: '\\not\\sim',
149
148
  ncong: '\\not\\cong',
@@ -188,18 +187,12 @@ var loadWarned = false;
188
187
 
189
188
  /** Apply post-load configuration exactly once. */
190
189
  var configureLoaded = function configureLoaded() {
191
- // No host path configured: use the fonts that ship inside this package. Once
192
- // they are in `document.fonts`, MathLive's own loader short-circuits and never
193
- // requests a woff2 - so math renders offline and under a CSP that allows no
194
- // font origin at all.
195
- if (fontsDirectory === undefined && !(0, _fonts.registerEmbeddedFonts)()) {
196
- log('embedded fonts unavailable (no FontFace API) - falling back to the CDN (%s). ' + 'Serve the fonts yourself and call configureFonts("/path/to/fonts") to avoid the network request.', cdnFontsDirectory());
197
- }
198
-
199
190
  // Always replace MathLive's relative `'./fonts/'` default: it throws
200
- // "Invalid base URL" when bundled. The host's copy if one was configured,
201
- // otherwise the CDN, which is now only reached if the embedded fonts could not
202
- // be registered.
191
+ // "Invalid base URL" when bundled. Use the host's copy if one was configured,
192
+ // otherwise the version-pinned CDN.
193
+ if (fontsDirectory === undefined) {
194
+ log('no fontsDirectory configured - falling back to the CDN (%s). ' + 'Serve the fonts yourself and call configureFonts("/path/to/fonts") to avoid the network request, ' + 'or configureFonts(null) to opt out.', cdnFontsDirectory());
195
+ }
203
196
  mathlive.MathfieldElement.fontsDirectory = fontsDirectory === undefined ? cdnFontsDirectory() : absoluteFontsDirectory(fontsDirectory);
204
197
  injectCoreStylesheet();
205
198
  };
@@ -252,7 +245,7 @@ var PLACEHOLDER_CARET_CSS = [":host(.".concat(PLACEHOLDER_CARET_CLASS, ") .ML__s
252
245
  // A live mathfield needs the readable radical index too: `rootIndexStyles` is
253
246
  // written for static markup in the host page, which cannot cross the shadow
254
247
  // boundary.
255
- var SHADOW_CSS = '.ML__latex .ML__center:has(.ML__stretchy){margin-left:0 !important}' + _commonStyles.ROOT_INDEX_CSS + PLACEHOLDER_CARET_CSS;
248
+ var SHADOW_CSS = '.ML__latex .ML__center:has(.ML__stretchy){margin-left:0 !important}' + _commonStyles.ROOT_INDEX_CSS + _commonStyles.PARALLEL_CSS + PLACEHOLDER_CARET_CSS;
256
249
 
257
250
  /**
258
251
  * Keep {@link PLACEHOLDER_CARET_CLASS} in step with the selection.