@pie-lib/math-input-mathlive 1.0.6 → 1.0.9-next.6608

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,5 @@
1
+ Copyright 2019 CoreSpring Inc
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -75,7 +75,7 @@ widget do not port and need a redesign (`mf.getElementInfo()` exposes per-elemen
75
75
  - **Stylesheets: import both, once, in the host app.**
76
76
 
77
77
  ```js
78
- import 'mathlive/fonts.css'; // KaTeX @font-face rules
78
+ import 'mathlive/fonts.css'; // KaTeX @font-face rules
79
79
  import 'mathlive/static.css'; // REQUIRED for convertLatexToMarkup output
80
80
  ```
81
81
 
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.latexForDisplay = exports["default"] = exports.LatexLabel = exports.KeyPad = void 0;
7
+ exports["default"] = exports.LatexLabel = exports.KeyPad = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
@@ -77,37 +77,13 @@ var LabelHolder = (0, _styles.styled)('span')(function () {
77
77
  }
78
78
  };
79
79
  });
80
-
81
- /**
82
- * A visible stand-in for an empty argument slot.
83
- *
84
- * Key latex uses empty groups to show the shape of a command - `\frac{}{}`,
85
- * `\overline{}`, `x^{}`. MathQuill drew those as a shaded box (`.mq-empty`);
86
- * MathLive renders `{}` as nothing at all, so those buttons come out blank.
87
- * `\placeholder{}` is not a substitute: in static markup it renders as a
88
- * non-breaking space (the editable box only exists inside a live mathfield), so
89
- * an actual glyph is required.
90
- *
91
- * Tagged with `pie-empty` so it can be muted via CSS.
92
- */
93
- var EMPTY_SLOT = "\\htmlData{pie-empty=1}{\\unicode{\"25AB}}";
94
- var EMPTY_GROUP_REGEX = /\{\s*\}/g;
95
-
96
- /**
97
- * Display-only: give empty groups something visible.
98
- * Never use this for the value that gets inserted into the field - the key's
99
- * own latex is what gets typed.
100
- */
101
- var latexForDisplay = exports.latexForDisplay = function latexForDisplay(latex) {
102
- return (latex || '').replace(EMPTY_GROUP_REGEX, "{".concat(EMPTY_SLOT, "}"));
103
- };
104
80
  var LatexLabel = exports.LatexLabel = /*#__PURE__*/function (_React$Component) {
105
81
  function LatexLabel(props) {
106
82
  var _this;
107
83
  (0, _classCallCheck2["default"])(this, LatexLabel);
108
84
  _this = _callSuper(this, LatexLabel, [props]);
109
85
  _this.state = {
110
- markup: (0, _mathliveInstance.latexToMarkup)(latexForDisplay(props.latex))
86
+ markup: (0, _mathliveInstance.latexToMarkup)(props.latex)
111
87
  };
112
88
  return _this;
113
89
  }
@@ -135,7 +111,7 @@ var LatexLabel = exports.LatexLabel = /*#__PURE__*/function (_React$Component) {
135
111
  }
136
112
  return _context.abrupt("return");
137
113
  case 3:
138
- markup = (0, _mathliveInstance.latexToMarkup)(latexForDisplay(this.props.latex));
114
+ markup = (0, _mathliveInstance.latexToMarkup)(this.props.latex);
139
115
  if (!markup) {
140
116
  _context.next = 4;
141
117
  break;
@@ -168,7 +144,7 @@ var LatexLabel = exports.LatexLabel = /*#__PURE__*/function (_React$Component) {
168
144
  value: function componentDidUpdate(prevProps) {
169
145
  if (prevProps.latex !== this.props.latex) {
170
146
  this.setState({
171
- markup: (0, _mathliveInstance.latexToMarkup)(latexForDisplay(this.props.latex))
147
+ markup: (0, _mathliveInstance.latexToMarkup)(this.props.latex)
172
148
  });
173
149
  }
174
150
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_propTypes","_Button","_IconButton","_styles","_debug","_lodashEs","_renderUi","_keys","_keysLayout","_commonStyles","_mathliveInstance","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","_callSuper","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","Boolean","prototype","valueOf","call","log","debug","LabelHolder","styled","pointerEvents","textTransform","color","text","display","alignItems","justifyContent","lineHeight","maxWidth","overflow","position","width","backgroundColor","keypadEmptyPlaceholder","undefined","opacity","EMPTY_SLOT","EMPTY_GROUP_REGEX","latexForDisplay","exports","latex","replace","concat","LatexLabel","_React$Component","props","_this","_classCallCheck2","state","markup","latexToMarkup","_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","columns","gridTemplateRows","rows","gridAutoFlow","KeyPadContainer","commonKeyboardStyles","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 } 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 display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n lineHeight: 1,\n // Never let a label size its grid column. Stretchy accents\n // (\\overrightarrow, \\overleftrightarrow, \\overarc) render an <svg> that\n // mathlive-static.css positions absolutely at width:100%; if that stylesheet\n // is missing the svg lays out statically and expands without bound, dragging\n // the whole column across the screen. `overflow: hidden` also collapses the\n // label's min-content contribution, so the grid can't blow out either way.\n maxWidth: '100%',\n overflow: 'hidden',\n '& svg': {\n position: 'absolute',\n width: '100%',\n },\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}));\n\n/**\n * A visible stand-in for an empty argument slot.\n *\n * Key latex uses empty groups to show the shape of a command - `\\frac{}{}`,\n * `\\overline{}`, `x^{}`. MathQuill drew those as a shaded box (`.mq-empty`);\n * MathLive renders `{}` as nothing at all, so those buttons come out blank.\n * `\\placeholder{}` is not a substitute: in static markup it renders as a\n * non-breaking space (the editable box only exists inside a live mathfield), so\n * an actual glyph is required.\n *\n * Tagged with `pie-empty` so it can be muted via CSS.\n */\nconst EMPTY_SLOT = '\\\\htmlData{pie-empty=1}{\\\\unicode{\"25AB}}';\nconst EMPTY_GROUP_REGEX = /\\{\\s*\\}/g;\n\n/**\n * Display-only: give empty groups something visible.\n * Never use this for the value that gets inserted into the field - the key's\n * own latex is what gets typed.\n */\nexport const latexForDisplay = (latex) => (latex || '').replace(EMPTY_GROUP_REGEX, `{${EMPTY_SLOT}}`);\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(latexForDisplay(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(latexForDisplay(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(latexForDisplay(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,OAA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ZUqH,MAAM,kBAcK;EACpBoC,OAAO,EAAEA,aAAO;EAChB1B,SAAS,EAAE;AACb,CAAC;AAAA,IAAAkE,QAAA,GAAA3J,OAAA,cAiKY+E,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_propTypes","_Button","_IconButton","_styles","_debug","_lodashEs","_renderUi","_keys","_keysLayout","_commonStyles","_mathliveInstance","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","_callSuper","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","Boolean","prototype","valueOf","call","log","debug","LabelHolder","styled","pointerEvents","textTransform","color","text","display","alignItems","justifyContent","lineHeight","maxWidth","overflow","position","width","backgroundColor","keypadEmptyPlaceholder","undefined","opacity","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","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 } 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 display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n lineHeight: 1,\n // Never let a label size its grid column. Stretchy accents\n // (\\overrightarrow, \\overleftrightarrow, \\overarc) render an <svg> that\n // mathlive-static.css positions absolutely at width:100%; if that stylesheet\n // is missing the svg lays out statically and expands without bound, dragging\n // the whole column across the screen. `overflow: hidden` also collapses the\n // label's min-content contribution, so the grid can't blow out either way.\n maxWidth: '100%',\n overflow: 'hidden',\n '& svg': {\n position: 'absolute',\n width: '100%',\n },\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}));\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"],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AC;AAChE,CAAC;AAAA,IAAA5L,gBAAA,aAZUiH,MAAM,kBAcK;EACpBoC,OAAO,EAAEA,aAAO;EAChB1B,SAAS,EAAE;AACb,CAAC;AAAA,IAAAkE,QAAA,GAAAzJ,OAAA,cAiKY6E,MAAM","ignoreList":[]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- 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.keyToAction = exports.fromMathLive = exports.fieldIds = exports.NEWLINE_EMBED = 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
  *
@@ -35,9 +35,114 @@ var DISPLAYLINES_REGEX = /^\\displaylines\{([\s\S]*)\}$/;
35
35
  var MQ_FIELD_REGEX = /\\MathQuillMathField\[([^\]]*)\]\{([^{}]*)\}/g;
36
36
  var PLACEHOLDER_REGEX = /\\placeholder\[([^\]]*)\]\{([^{}]*)\}/g;
37
37
 
38
+ /**
39
+ * Unnamed placeholders, which MathLive inserts on its own.
40
+ *
41
+ * Typing a command with empty arguments (`\longdiv{}`, `\frac{}{}`) makes
42
+ * MathLive serialise the empty slots as `\placeholder{}`. That token is
43
+ * MathLive-specific: MathJax - which @pie-lib/math-rendering uses to render
44
+ * prompts and previews - has no such command and renders it as red error text.
45
+ * Stored latex must therefore keep plain empty groups.
46
+ */
47
+ var BARE_PLACEHOLDER_REGEX = /\\placeholder\{([^{}]*)\}/g;
48
+ var BARE_PLACEHOLDER_NO_ARG_REGEX = /\\placeholder(?![[{a-zA-Z])/g;
49
+
38
50
  /** Default id used when stored latex has an unnamed field. */
39
51
  var DEFAULT_FIELD_ID = exports.DEFAULT_FIELD_ID = 'r1';
40
52
 
53
+ /**
54
+ * A visible stand-in for an empty argument slot, used for STATIC rendering only.
55
+ *
56
+ * Stored latex legitimately contains empty groups - `\longdiv{}`, `\frac{}{}`,
57
+ * `x^{}` - to express a command's shape. MathQuill drew those as a shaded box
58
+ * (`.mq-empty`); MathLive renders `{}` as nothing, so `convertLatexToMarkup`
59
+ * output comes out completely blank (not even the surrounding bracket, in the
60
+ * case of `\enclose{longdiv}{}`).
61
+ *
62
+ * `\placeholder{}` is not usable here: in static markup it renders as a
63
+ * non-breaking space, because its editable box only exists inside a live
64
+ * mathfield. So an actual glyph is required.
65
+ *
66
+ * Live mathfields need none of this - MathLive manages empty slots itself.
67
+ */
68
+ var EMPTY_SLOT = "\\htmlData{pie-empty=1}{\\unicode{\"25AB}}";
69
+ var EMPTY_GROUP_REGEX = /\{\s*\}/g;
70
+
71
+ /**
72
+ * Make empty argument slots visible, for static rendering.
73
+ *
74
+ * Display-only: never feed the result to a mathfield or to storage - the
75
+ * original latex is what gets typed and saved.
76
+ *
77
+ * @param {string} latex
78
+ * @returns {string}
79
+ */
80
+ var withVisibleEmptySlots = exports.withVisibleEmptySlots = function withVisibleEmptySlots(latex) {
81
+ return (latex || '').replace(EMPTY_GROUP_REGEX, "{".concat(EMPTY_SLOT, "}"));
82
+ };
83
+
84
+ /**
85
+ * Pie commands that take an argument, and their native MathLive equivalents.
86
+ *
87
+ * These MUST NOT be handled as MathLive macros. A macro is serialised from the
88
+ * arguments it was created with, so text typed inside its expansion never makes
89
+ * it back out: `getValue('latex')` keeps returning `\longdiv{\placeholder{}}`
90
+ * while `getValue('ascii-math')` shows the typed content. Setting
91
+ * `captureSelection: false` lets the cursor in but does not change
92
+ * serialisation.
93
+ *
94
+ * Expanding to native constructs instead gives real, editable atoms that
95
+ * round-trip. All three targets are understood by MathJax too, so stored latex
96
+ * still renders in @pie-lib/math-rendering without a reverse mapping.
97
+ */
98
+ /**
99
+ * Rewrite argument-taking pie commands into native MathLive latex.
100
+ * Applied on the way *into* a mathfield.
101
+ *
102
+ * @param {string} latex
103
+ * @returns {string}
104
+ */
105
+ var toNativeCommands = exports.toNativeCommands = function toNativeCommands(latex) {
106
+ if (typeof latex !== 'string' || !latex) {
107
+ return latex || '';
108
+ }
109
+ var out = latex;
110
+
111
+ // \abs{x} -> \left|x\right| needs brace-aware handling, the rest are prefix
112
+ // swaps.
113
+ out = replaceAbs(out);
114
+ out = out.replace(/\\longdiv\{/g, '\\enclose{longdiv}{');
115
+ out = out.replace(/\\overarc\{/g, '\\overparen{');
116
+ return out;
117
+ };
118
+
119
+ /** `\abs{x}` -> `\left|x\right|`, matching balanced braces. */
120
+ var replaceAbs = function replaceAbs(latex) {
121
+ var out = latex;
122
+ var idx = out.indexOf('\\abs{');
123
+ while (idx !== -1) {
124
+ var open = idx + '\\abs{'.length - 1;
125
+ var depth = 0;
126
+ var close = -1;
127
+ for (var i = open; i < out.length; i++) {
128
+ if (out[i] === '{') depth++;else if (out[i] === '}') {
129
+ depth--;
130
+ if (depth === 0) {
131
+ close = i;
132
+ break;
133
+ }
134
+ }
135
+ }
136
+ if (close === -1) {
137
+ break;
138
+ }
139
+ var inner = out.slice(open + 1, close);
140
+ out = "".concat(out.slice(0, idx), "\\left|").concat(inner, "\\right|").concat(out.slice(close + 1));
141
+ idx = out.indexOf('\\abs{');
142
+ }
143
+ return out;
144
+ };
145
+
41
146
  /**
42
147
  * Ids of the answer blocks in a piece of stored latex, in document order.
43
148
  *
@@ -69,8 +174,12 @@ var toMathLive = exports.toMathLive = function toMathLive(latex) {
69
174
  return latex || '';
70
175
  }
71
176
 
177
+ // Argument-taking pie commands -> native constructs, so their content stays
178
+ // editable and serialises back correctly (see toNativeCommands).
179
+ var out = toNativeCommands(latex);
180
+
72
181
  // Answer blocks: \MathQuillMathField[id]{x} -> \placeholder[id]{x}
73
- var out = latex.replace(MQ_FIELD_REGEX, function (_m, id, content) {
182
+ out = out.replace(MQ_FIELD_REGEX, function (_m, id, content) {
74
183
  return "\\placeholder[".concat(id || DEFAULT_FIELD_ID, "]{").concat(content, "}");
75
184
  });
76
185
 
@@ -107,6 +216,15 @@ var fromMathLive = exports.fromMathLive = function fromMathLive(latex) {
107
216
  out = out.replace(PLACEHOLDER_REGEX, function (_m, id, content) {
108
217
  return "\\MathQuillMathField[".concat(id || DEFAULT_FIELD_ID, "]{").concat(content, "}");
109
218
  });
219
+
220
+ // Unnamed placeholders are MathLive's own representation of an empty slot and
221
+ // must not reach storage or MathJax. Unwrap them: keep any content, drop the
222
+ // command itself (the surrounding braces are already part of the host latex,
223
+ // so re-adding them here would produce `\longdiv{{}}`).
224
+ out = out.replace(BARE_PLACEHOLDER_REGEX, function (_m, content) {
225
+ return content;
226
+ });
227
+ out = out.replace(BARE_PLACEHOLDER_NO_ARG_REGEX, '');
110
228
  return out;
111
229
  };
112
230
 
@@ -123,8 +241,10 @@ var COMMANDS_WITH_ARGS = exports.COMMANDS_WITH_ARGS = {
123
241
  '\\overline': '\\overline{#?}',
124
242
  '\\overrightarrow': '\\overrightarrow{#?}',
125
243
  '\\overleftrightarrow': '\\overleftrightarrow{#?}',
126
- '\\overarc': '\\overarc{#?}',
127
- '\\longdiv': '\\longdiv{#?}',
244
+ // Native forms, not the pie macros: a macro would not serialise the user's
245
+ // typed content back out (see toNativeCommands).
246
+ '\\overarc': '\\overparen{#?}',
247
+ '\\longdiv': '\\enclose{longdiv}{#?}',
128
248
  '^': '^{#?}',
129
249
  _: '_{#?}',
130
250
  '(': '\\left(#?\\right)',
@@ -1 +1 @@
1
- {"version":3,"file":"latex-bridge.js","names":["NEWLINE_EMBED","exports","NEWLINE_EMBED_REGEX","DISPLAYLINES_REGEX","MQ_FIELD_REGEX","PLACEHOLDER_REGEX","DEFAULT_FIELD_ID","fieldIds","latex","out","match","lastIndex","exec","push","toMathLive","replace","_m","id","content","concat","indexOf","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/** Default id used when stored latex has an unnamed field. */\nexport const DEFAULT_FIELD_ID = 'r1';\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 // Answer blocks: \\MathQuillMathField[id]{x} -> \\placeholder[id]{x}\n let out = latex.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 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 '\\\\frac': '\\\\frac{#?}{#?}',\n '/': '\\\\frac{#?}{#?}',\n '\\\\sqrt': '\\\\sqrt{#?}',\n '\\\\nthroot': '\\\\sqrt[#?]{#?}',\n '\\\\overline': '\\\\overline{#?}',\n '\\\\overrightarrow': '\\\\overrightarrow{#?}',\n '\\\\overleftrightarrow': '\\\\overleftrightarrow{#?}',\n '\\\\overarc': '\\\\overarc{#?}',\n '\\\\longdiv': '\\\\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;A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AME,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","withVisibleEmptySlots","latex","replace","concat","toNativeCommands","out","replaceAbs","idx","indexOf","open","length","depth","close","i","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 an actual glyph is required.\n *\n * Live mathfields need none of this - MathLive manages empty slots itself.\n */\nconst EMPTY_SLOT = '\\\\htmlData{pie-empty=1}{\\\\unicode{\"25AB}}';\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\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 '\\\\frac': '\\\\frac{#?}{#?}',\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,IAA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IAAI,EAAE,SAAS;MAAEC,KAAK,EAAEO;IAAS,CAAC,GAAGV,SAAS;EACpE;EAEA,OAAOA,SAAS;AAClB,CAAC","ignoreList":[]}
@@ -98,8 +98,9 @@ var configureFonts = exports.configureFonts = function configureFonts(dir) {
98
98
  * way in the editor and in the static renderer.
99
99
  */
100
100
  var PIE_MACROS = exports.PIE_MACROS = {
101
+ // Argument-less symbols. Atomic is correct here: backspace should remove the
102
+ // whole glyph, and there is nothing to type into.
101
103
  parallelogram: "\\htmlData{pie-macro=parallelogram}{\\unicode{\"25B1}}",
102
- overarc: '\\overparen{#1}',
103
104
  napprox: '\\not\\approx',
104
105
  nsim: '\\not\\sim',
105
106
  ncong: '\\not\\cong',
@@ -108,7 +109,14 @@ var PIE_MACROS = exports.PIE_MACROS = {
108
109
  divide: '\\div',
109
110
  degree: '^{\\circ}',
110
111
  square: "\\unicode{\"25A1}",
111
- longdiv: '\\htmlData{pie-macro=longdiv}{#1}',
112
+ // Argument-taking commands, kept ONLY so previously authored latex still
113
+ // parses and renders. They are never used for editing: MathLive serialises a
114
+ // macro from the arguments it was created with, so text typed inside the
115
+ // expansion never comes back out of `getValue('latex')`. Anything entering a
116
+ // mathfield is rewritten to the native equivalent first - see
117
+ // `toNativeCommands` in latex-bridge.
118
+ longdiv: '\\enclose{longdiv}{#1}',
119
+ overarc: '\\overparen{#1}',
112
120
  abs: '\\left|#1\\right|'
113
121
  };
114
122
 
@@ -376,7 +384,7 @@ function applyStaticMath(element, latex) {
376
384
  });
377
385
  return undefined;
378
386
  }
379
- element.innerHTML = ml.convertLatexToMarkup((0, _latexBridge.toMathLive)(source), {
387
+ element.innerHTML = ml.convertLatexToMarkup((0, _latexBridge.withVisibleEmptySlots)((0, _latexBridge.toMathLive)(source)), {
380
388
  macros: _objectSpread(_objectSpread({}, getMacros()), options.macros || {})
381
389
  });
382
390
  return element;
@@ -399,7 +407,10 @@ function latexToMarkup(latex) {
399
407
  return '';
400
408
  }
401
409
  try {
402
- return ml.convertLatexToMarkup((0, _latexBridge.toMathLive)(latex), _objectSpread({
410
+ // Empty groups render as nothing in static markup, so give them a visible
411
+ // box. This covers every static path: keypad labels, mf.Static in display
412
+ // mode, and applyStaticMath.
413
+ return ml.convertLatexToMarkup((0, _latexBridge.withVisibleEmptySlots)((0, _latexBridge.toMathLive)(latex)), _objectSpread({
403
414
  macros: _objectSpread(_objectSpread({}, getMacros()), options.macros || {})
404
415
  }, options));
405
416
  } catch (e) {