@khanacademy/math-input 26.4.10 → 26.4.12

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.
@@ -34,9 +34,9 @@ declare class MathInput extends React.Component<Props, State> {
34
34
  didTouchOutside: boolean | null | undefined;
35
35
  didScroll: boolean | null | undefined;
36
36
  mathField: any;
37
- recordTouchStartOutside: (arg1: any) => void;
38
- blurOnTouchEndOutside: (arg1: any) => void;
39
- blurOnClickOutside: (arg1: any) => void;
37
+ recordTouchStartOutside: (e: any) => void;
38
+ blurOnTouchEndOutside: (e: any) => void;
39
+ blurOnClickOutside: (e: any) => void;
40
40
  dragListener: any;
41
41
  inputRef: HTMLDivElement | null | undefined;
42
42
  _isMounted: boolean | null | undefined;
@@ -52,7 +52,7 @@ declare class MathInput extends React.Component<Props, State> {
52
52
  _updateInputPadding: () => void;
53
53
  /** Returns the current bounds of the keypadElement */
54
54
  _getKeypadBounds(): DOMRect | null;
55
- _updateCursorHandle: (arg1?: boolean) => void;
55
+ _updateCursorHandle: (animateIntoPosition?: boolean) => void;
56
56
  _hideCursorHandle: () => void;
57
57
  _handleScroll: () => void;
58
58
  blur: () => void;
@@ -81,7 +81,7 @@ declare class MathInput extends React.Component<Props, State> {
81
81
  * sign determines direction.
82
82
  * @returns {boolean} - true if a node was hit, false otherwise.
83
83
  */
84
- _findHitNode: (arg1: ClientRect, arg2: number, arg3: number, arg4: number, arg5: number) => boolean;
84
+ _findHitNode(containerBounds: ClientRect, x: number, y: number, dx: number, dy: number): boolean;
85
85
  /**
86
86
  * Inserts the cursor at the DOM node closest to the given coordinates,
87
87
  * based on hit-tests conducted using #_findHitNode.
@@ -89,40 +89,40 @@ declare class MathInput extends React.Component<Props, State> {
89
89
  * @param {number} x - the x coordinate in the viewport
90
90
  * @param {number} y - the y coordinate in the viewport
91
91
  */
92
- _insertCursorAtClosestNode: (arg1: number, arg2: number) => void;
92
+ _insertCursorAtClosestNode(x: number, y: number): void;
93
93
  handleTouchStart: (e: React.TouchEvent<Element>, keypadActive: KeypadContextType["keypadActive"], setKeypadActive: KeypadContextType["setKeypadActive"]) => void;
94
94
  handleClick: (e: React.MouseEvent, keypadActive: KeypadContextType["keypadActive"], setKeypadActive: KeypadContextType["setKeypadActive"]) => void;
95
- handleTouchMove: (arg1: React.TouchEvent<Element>) => void;
96
- handleTouchEnd: (arg1: React.TouchEvent<Element>) => void;
95
+ handleTouchMove: (e: React.TouchEvent<Element>) => void;
96
+ handleTouchEnd: (e: React.TouchEvent<Element>) => void;
97
97
  /**
98
98
  * When a touch starts in the cursor handle, we track it so as to avoid
99
99
  * handling any touch events ourself.
100
100
  *
101
101
  * @param {TouchEvent} e - the raw touch event from the browser
102
102
  */
103
- onCursorHandleTouchStart: (arg1: React.TouchEvent<HTMLSpanElement>) => void;
104
- _constrainToBound: (arg1: number, arg2: number, arg3: number, arg4: number) => number;
103
+ onCursorHandleTouchStart: (e: React.TouchEvent<HTMLSpanElement>) => void;
104
+ _constrainToBound(value: number, min: number, max: number, friction: number): number;
105
105
  /**
106
106
  * When the user moves the cursor handle update the position of the cursor
107
107
  * and the handle.
108
108
  *
109
109
  * @param {TouchEvent} e - the raw touch event from the browser
110
110
  */
111
- onCursorHandleTouchMove: (arg1: React.TouchEvent<HTMLSpanElement>) => void;
111
+ onCursorHandleTouchMove: (e: React.TouchEvent<HTMLSpanElement>) => void;
112
112
  /**
113
113
  * When the user releases the cursor handle, animate it back into place.
114
114
  *
115
115
  * @param {TouchEvent} e - the raw touch event from the browser
116
116
  */
117
- onCursorHandleTouchEnd: (arg1: React.TouchEvent<HTMLSpanElement>) => void;
117
+ onCursorHandleTouchEnd: (e: React.TouchEvent<HTMLSpanElement>) => void;
118
118
  /**
119
119
  * If the gesture is cancelled mid-drag, simply hide it.
120
120
  *
121
121
  * @param {TouchEvent} e - the raw touch event from the browser
122
122
  */
123
- onCursorHandleTouchCancel: (arg1: React.TouchEvent<HTMLSpanElement>) => void;
124
- domKeyToMathQuillKey: (arg1: string) => string | null | undefined;
125
- handleKeyUp: (arg1: React.KeyboardEvent<HTMLDivElement>) => void;
123
+ onCursorHandleTouchCancel: (e: React.TouchEvent<HTMLSpanElement>) => void;
124
+ domKeyToMathQuillKey: (key: string) => string | null | undefined;
125
+ handleKeyUp: (e: React.KeyboardEvent<HTMLDivElement>) => void;
126
126
  getBorderWidthPx: () => number;
127
127
  getInputInnerPadding: () => {
128
128
  paddingTop: number;
package/dist/es/index.js CHANGED
@@ -17,7 +17,7 @@ import { TransitionGroup } from 'react-transition-group';
17
17
  import { withActionScheduler } from '@khanacademy/wonder-blocks-timing';
18
18
  import PropTypes from 'prop-types';
19
19
 
20
- const libName="@khanacademy/math-input";const libVersion="26.4.10";addLibraryVersionToPerseusDebug(libName,libVersion);
20
+ const libName="@khanacademy/math-input";const libVersion="26.4.12";addLibraryVersionToPerseusDebug(libName,libVersion);
21
21
 
22
22
  function getDefaultExportFromCjs (x) {
23
23
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -1432,7 +1432,7 @@ class MathWrapper{focus(){this.mathField.cursor().show();this.mathField.focus();
1432
1432
 
1433
1433
  const toolbarHeightPx=60;const scrollIntoView=(containerNode,keypadNode)=>{const containerBounds=containerNode.getBoundingClientRect();const containerBottomPx=containerBounds.bottom;const containerTopPx=containerBounds.top;const scrollNode=document.scrollingElement;const desiredMarginPx=16;if(keypadNode){const pageHeightPx=window.innerHeight;const keypadHeightPx=keypadNode.clientHeight;const keypadTopPx=pageHeightPx-(keypadHeightPx+toolbarHeightPx);if(containerBottomPx>keypadTopPx){const scrollOffset=Math.min(containerBottomPx-keypadTopPx+desiredMarginPx,containerTopPx);if(scrollNode){scrollNode.scrollTop+=scrollOffset;}return}}if(scrollNode&&containerTopPx<desiredMarginPx){scrollNode.scrollTop-=containerBounds.height+desiredMarginPx;}};
1434
1434
 
1435
- const constrainingFrictionFactor=.8;class MathInput extends React.Component{componentDidMount(){this._isMounted=true;this.mathField=new MathWrapper(this._mathContainer,this.props.ariaLabel,this.context.strings,this.context.locale,{onCursorMove:cursor=>{this.props.keypadElement?.setCursor(cursor);}});this.mathField.setContent(this.props.value);this._updateInputPadding();this._container=ReactDOM.findDOMNode(this);this._root=this._container.querySelector(".mq-root-block");this._root.addEventListener("scroll",this._handleScroll);const isWithinKeypadBounds=(x,y)=>{const bounds=this._getKeypadBounds();if(!bounds){return false}return bounds.left<=x&&bounds.right>=x&&bounds.top<=y&&bounds.bottom>=y||bounds.bottom<y};this.recordTouchStartOutside=evt=>{if(this.state.focused){if(!this._container.contains(evt.target)){let touchDidStartInOrBelowKeypad=false;if(this.props.keypadElement&&this.props.keypadElement.getDOMNode()){for(let i=0;i<evt.changedTouches.length;i++){const[x,y]=[evt.changedTouches[i].clientX,evt.changedTouches[i].clientY];if(isWithinKeypadBounds(x,y)){touchDidStartInOrBelowKeypad=true;break}}}if(!touchDidStartInOrBelowKeypad){this.didTouchOutside=true;if(this.dragListener){this.dragListener.detach();}this.dragListener=new DragListener(()=>{this.didScroll=true;this.dragListener.detach();},evt);this.dragListener.attach();}}}};this.blurOnTouchEndOutside=evt=>{if(this.state.focused&&this.didTouchOutside&&!this.didScroll){this.blur();this.mathField.blur();this.props.onBlur?.();}this.didTouchOutside=false;this.didScroll=false;if(this.dragListener){this.dragListener.detach();}};this.blurOnClickOutside=evt=>{if(this.state.focused){if(!this._container.contains(evt.target)){if(this.props.keypadElement&&this.props.keypadElement.getDOMNode()){const[x,y]=[evt.clientX,evt.clientY];if(!isWithinKeypadBounds(x,y)){this.blur();this.props.onBlur?.();}}}}};window.addEventListener("touchstart",this.recordTouchStartOutside);window.addEventListener("touchend",this.blurOnTouchEndOutside);window.addEventListener("touchcancel",this.blurOnTouchEndOutside);window.addEventListener("click",this.blurOnClickOutside);}componentDidUpdate(prevProps,prevState){if(this.mathField.getContent()!==this.props.value){this.mathField.setContent(this.props.value);}if(prevState.focused!==this.state.focused){this._updateInputPadding();}}componentWillUnmount(){this._isMounted=false;window.removeEventListener("touchstart",this.recordTouchStartOutside);window.removeEventListener("touchend",this.blurOnTouchEndOutside);window.removeEventListener("touchcancel",this.blurOnTouchEndOutside);window.removeEventListener("click",this.blurOnClickOutside);}_getKeypadBounds(){const keypadNode=this.props.keypadElement?.getDOMNode();if(keypadNode instanceof Element){return keypadNode.getBoundingClientRect()}return null}render(){const{showInputFocusStyle,handle}=this.state;const{style}=this.props;const innerStyle={...inlineStyles.innerContainer,borderWidth:this.getBorderWidthPx(),...showInputFocusStyle?{borderColor:semanticColor.core.border.instructive.default}:{},...style};const ariaLabel=this.context.strings.mathInputBox+" "+this.context.strings.fingerTap;return jsxRuntimeExports.jsx(KeypadContext.Consumer,{children:({keypadActive,setKeypadActive})=>jsxRuntimeExports.jsxs(View,{style:styles$6.input,onTouchStart:e=>{this.handleTouchStart(e,keypadActive,setKeypadActive);},onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd,onClick:e=>{this.handleClick(e,keypadActive,setKeypadActive);},role:"textbox","aria-label":ariaLabel,children:[jsxRuntimeExports.jsx("div",{className:"keypad-input",tabIndex:0,ref:node=>{this.inputRef=node;},onFocus:()=>{this.focus(setKeypadActive);},onBlur:this.blur,onKeyUp:this.handleKeyUp,children:jsxRuntimeExports.jsx("div",{ref:node=>{this._mathContainer=ReactDOM.findDOMNode(node);},style:innerStyle})}),showInputFocusStyle&&handle.visible&&jsxRuntimeExports.jsx(CursorHandle,{...handle,onTouchStart:this.onCursorHandleTouchStart,onTouchMove:this.onCursorHandleTouchMove,onTouchEnd:this.onCursorHandleTouchEnd,onTouchCancel:this.onCursorHandleTouchCancel})]})})}constructor(...args){super(...args),this.state={focused:false,showInputFocusStyle:false,handle:{animateIntoPosition:false,visible:false,x:0,y:0}},this._updateInputPadding=()=>{this._container=ReactDOM.findDOMNode(this);this._root=this._container.querySelector(".mq-root-block");const padding=this.getInputInnerPadding();this._root.style.padding=`${padding.paddingTop}px ${padding.paddingRight}px`+` ${padding.paddingBottom}px ${padding.paddingLeft}px`;this._root.style.fontSize=`${fontSizePt}pt`;},this._updateCursorHandle=animateIntoPosition=>{const containerBounds=this._container.getBoundingClientRect();const cursor=this._container.querySelector(".mq-cursor");const cursorBounds=cursor.getBoundingClientRect();const cursorWidth=cursorBounds.width;const gapBelowCursor=2;const inputInnerPadding=this.getInputInnerPadding();const furthestRightCursorBound=containerBounds.right-cursorWidth-inputInnerPadding.paddingRight;const furthestLeftCursorBound=containerBounds.left+cursorWidth+inputInnerPadding.paddingLeft;let cursorBoundsLeft=cursorBounds.left;if(cursorBounds.left>furthestRightCursorBound){cursorBoundsLeft=furthestRightCursorBound;}else if(cursorBounds.left<furthestLeftCursorBound){cursorBoundsLeft=furthestLeftCursorBound;}this.setState({handle:{visible:true,animateIntoPosition,x:cursorBoundsLeft+cursorWidth/2-containerBounds.left,y:cursorBounds.bottom+gapBelowCursor-containerBounds.top}});},this._hideCursorHandle=()=>{this.setState({handle:{visible:false,x:0,y:0}});},this._handleScroll=()=>{if(this.state.handle.animateIntoPosition!==false){this._hideCursorHandle();}},this.blur=()=>{this.mathField.blur();this.setState({showInputFocusStyle:false,handle:{visible:false}});},this.focus=setKeypadActive=>{this.props.keypadElement?.setKeyHandler(key=>{const cursor=this.mathField.pressKey(key);const hideCursor=()=>{this.setState({handle:{visible:false}});};const value=this.mathField.getContent();if(this.props.value!==value){this.props.onChange(value,hideCursor);}else {hideCursor();}return cursor});this.mathField.focus();this.props?.onFocus();setKeypadActive(true);this.setState({focused:true,showInputFocusStyle:true},()=>{setTimeout(()=>{if(this._isMounted){const maybeKeypadNode=this.props.keypadElement?.getDOMNode();scrollIntoView(this._container,maybeKeypadNode);}});});},this._findHitNode=(containerBounds,x,y,dx,dy)=>{while(y>=containerBounds.top&&y<=containerBounds.bottom){y+=dy;const points=[[x-dx,y],[x,y],[x+dx,y]];const elements=points.map(point=>document.elementFromPoint(...point)).filter(element=>element&&this._root.contains(element)&&(!element.classList.contains("mq-root-block")&&!element.classList.contains("mq-non-leaf")||element.classList.contains("mq-empty")||element.classList.contains("mq-hasCursor")));let hitNode=null;const nonLeafElements=[];let max=0;const counts={};const elementsById={};for(const element of elements){const id=element?.getAttribute("mathquill-command-id");if(id!=null){counts[id]=(counts[id]||0)+1;elementsById[id]=element;}else {nonLeafElements.push(element);}}for(const[id,count]of entries(counts)){if(count>max){max=count;hitNode=elementsById[id];}}if(hitNode==null&&nonLeafElements.length>0){hitNode=nonLeafElements[0];}if(hitNode!==null){this.mathField.setCursorPosition(x,y,hitNode);return true}}return false},this._insertCursorAtClosestNode=(x,y)=>{const cursor=this.mathField.getCursor();if(!this._root.hasChildNodes()){cursor.insAtLeftEnd(this.mathField.mathField.controller().root);return}if(y>this._containerBounds.bottom){y=this._containerBounds.bottom-10;}else if(y<this._containerBounds.top){y=this._containerBounds.top+10;}if(x>this._containerBounds.right){x=this._containerBounds.right-15;}else if(x<this._containerBounds.left){x=this._containerBounds.left+15;}let dy;dy=-8;const dx=5;if(this._findHitNode(this._containerBounds,x,y,dx,dy)){return}y=this._containerBounds.top;dy=8;if(this._findHitNode(this._containerBounds,x,y,dx,dy)){return}const firstChildBounds=this._root.firstChild.getBoundingClientRect();const lastChildBounds=this._root.lastChild.getBoundingClientRect();const left=firstChildBounds.left;const right=lastChildBounds.right;if(Math.abs(x-right)<Math.abs(x-left)){cursor.insAtRightEnd(this.mathField.mathField.controller().root);}else {cursor.insAtLeftEnd(this.mathField.mathField.controller().root);}this.props.keypadElement?.setCursor({context:this.mathField.contextForCursor()});},this.handleTouchStart=(e,keypadActive,setKeypadActive)=>{e.stopPropagation();this._hideCursorHandle();if(this.mathField.getContent()!==""){this._containerBounds=this._container.getBoundingClientRect();const touch=e.changedTouches[0];this._insertCursorAtClosestNode(touch.clientX,touch.clientY);}if(this.state.focused&&!keypadActive){setKeypadActive(true);}if(!this.state.focused){this.focus(setKeypadActive);}this.inputRef?.focus();},this.handleClick=(e,keypadActive,setKeypadActive)=>{e.stopPropagation();this._hideCursorHandle();if(this.mathField.getContent()!==""){this._containerBounds=this._container.getBoundingClientRect();this._insertCursorAtClosestNode(e.clientX,e.clientY);}if(this.state.focused&&!keypadActive){setKeypadActive(true);}if(!this.state.focused){this.focus(setKeypadActive);}this.inputRef?.focus();},this.handleTouchMove=e=>{e.stopPropagation();if(this.mathField.getContent()!==""&&this.state.focused){const touch=e.changedTouches[0];this._insertCursorAtClosestNode(touch.clientX,touch.clientY);}},this.handleTouchEnd=e=>{e.stopPropagation();if(this.mathField.getContent()!==""&&this.state.focused){this._updateCursorHandle();}},this.onCursorHandleTouchStart=e=>{e.stopPropagation();e.preventDefault();this._containerBounds=this._container.getBoundingClientRect();},this._constrainToBound=(value,min,max,friction)=>{if(value<min){return min+(value-min)*friction}else if(value>max){return max+(value-max)*friction}else {return value}},this.onCursorHandleTouchMove=e=>{e.stopPropagation();const x=e.changedTouches[0].clientX;const y=e.changedTouches[0].clientY;const relativeX=x-this._containerBounds.left;const relativeY=y-2*cursorHandleRadiusPx*cursorHandleDistanceMultiplier-this._containerBounds.top;this.setState({handle:{animateIntoPosition:false,visible:true,x:this._constrainToBound(relativeX,0,this._containerBounds.width,constrainingFrictionFactor),y:this._constrainToBound(relativeY,0,this._containerBounds.height,constrainingFrictionFactor)}});const distanceAboveFingerToTrySelecting=22;const adjustedY=y-distanceAboveFingerToTrySelecting;this._insertCursorAtClosestNode(x,adjustedY);},this.onCursorHandleTouchEnd=e=>{e.stopPropagation();this._updateCursorHandle(true);},this.onCursorHandleTouchCancel=e=>{e.stopPropagation();this._updateCursorHandle(true);},this.domKeyToMathQuillKey=key=>{const keyMap={"+":"PLUS","-":"MINUS","*":"TIMES","/":"DIVIDE",".":"DECIMAL","%":"PERCENT","=":"EQUAL",">":"GT","<":"LT","^":"EXP"};if(["0","1","2","3","4","5","6","7","8","9"].includes(key)){return `NUM_${key}`}else if(key==="Backspace"){return "BACKSPACE"}else if(key in keyMap){return keyMap[key]}return null},this.handleKeyUp=event=>{const mathQuillKey=this.domKeyToMathQuillKey(event.key);if(mathQuillKey){this.mathField.pressKey(mathQuillKey);const value=this.mathField.getContent();if(this.props.value!==value){this.mathField.setContent(this.props.value);this.props.onChange(value,()=>{});this._hideCursorHandle();}}},this.getBorderWidthPx=()=>{const normalBorderWidthPx=1;const focusedBorderWidthPx=2;return this.state.focused?focusedBorderWidthPx:normalBorderWidthPx},this.getInputInnerPadding=()=>{const paddingInset=totalDesiredPadding-this.getBorderWidthPx();const symbolaPaddingBottom=3;const symbolaPaddingTop=1;const cursorPadding=2;const padding={paddingTop:paddingInset-symbolaPaddingTop,paddingRight:paddingInset+cursorPadding,paddingBottom:paddingInset-symbolaPaddingBottom,paddingLeft:paddingInset+cursorPadding};return padding};}}MathInput.contextType=MathInputI18nContext;MathInput.defaultProps={style:{},value:""};MathInput.contextType=MathInputI18nContext;const fontSizePt=18;const inputMaxWidth=128;const numeralHeightPx=20;const totalDesiredPadding=12;const minHeightPx=numeralHeightPx+totalDesiredPadding*2;const minWidthPx=64;const styles$6=StyleSheet.create({input:{position:"relative",display:"inline-block",verticalAlign:"middle",maxWidth:inputMaxWidth}});const inlineStyles={innerContainer:{backgroundColor:"white",minHeight:minHeightPx,minWidth:minWidthPx,maxWidth:inputMaxWidth,boxSizing:"border-box",position:"relative",borderStyle:"solid",borderColor:semanticColor.core.border.neutral.default,borderRadius:4,color:semanticColor.core.foreground.neutral.strong}};
1435
+ const constrainingFrictionFactor=.8;class MathInput extends React.Component{componentDidMount(){this._isMounted=true;this.mathField=new MathWrapper(this._mathContainer,this.props.ariaLabel,this.context.strings,this.context.locale,{onCursorMove:cursor=>{this.props.keypadElement?.setCursor(cursor);}});this.mathField.setContent(this.props.value);this._updateInputPadding();this._container=ReactDOM.findDOMNode(this);this._root=this._container.querySelector(".mq-root-block");this._root.addEventListener("scroll",this._handleScroll);const isWithinKeypadBounds=(x,y)=>{const bounds=this._getKeypadBounds();if(!bounds){return false}return bounds.left<=x&&bounds.right>=x&&bounds.top<=y&&bounds.bottom>=y||bounds.bottom<y};this.recordTouchStartOutside=evt=>{if(this.state.focused){if(!this._container.contains(evt.target)){let touchDidStartInOrBelowKeypad=false;if(this.props.keypadElement&&this.props.keypadElement.getDOMNode()){for(let i=0;i<evt.changedTouches.length;i++){const[x,y]=[evt.changedTouches[i].clientX,evt.changedTouches[i].clientY];if(isWithinKeypadBounds(x,y)){touchDidStartInOrBelowKeypad=true;break}}}if(!touchDidStartInOrBelowKeypad){this.didTouchOutside=true;if(this.dragListener){this.dragListener.detach();}this.dragListener=new DragListener(()=>{this.didScroll=true;this.dragListener.detach();},evt);this.dragListener.attach();}}}};this.blurOnTouchEndOutside=evt=>{if(this.state.focused&&this.didTouchOutside&&!this.didScroll){this.blur();this.mathField.blur();this.props.onBlur?.();}this.didTouchOutside=false;this.didScroll=false;if(this.dragListener){this.dragListener.detach();}};this.blurOnClickOutside=evt=>{if(this.state.focused){if(!this._container.contains(evt.target)){if(this.props.keypadElement&&this.props.keypadElement.getDOMNode()){const[x,y]=[evt.clientX,evt.clientY];if(!isWithinKeypadBounds(x,y)){this.blur();this.props.onBlur?.();}}}}};window.addEventListener("touchstart",this.recordTouchStartOutside);window.addEventListener("touchend",this.blurOnTouchEndOutside);window.addEventListener("touchcancel",this.blurOnTouchEndOutside);window.addEventListener("click",this.blurOnClickOutside);}componentDidUpdate(prevProps,prevState){if(this.mathField.getContent()!==this.props.value){this.mathField.setContent(this.props.value);}if(prevState.focused!==this.state.focused){this._updateInputPadding();}}componentWillUnmount(){this._isMounted=false;window.removeEventListener("touchstart",this.recordTouchStartOutside);window.removeEventListener("touchend",this.blurOnTouchEndOutside);window.removeEventListener("touchcancel",this.blurOnTouchEndOutside);window.removeEventListener("click",this.blurOnClickOutside);}_getKeypadBounds(){const keypadNode=this.props.keypadElement?.getDOMNode();if(keypadNode instanceof Element){return keypadNode.getBoundingClientRect()}return null}_findHitNode(containerBounds,x,y,dx,dy){while(y>=containerBounds.top&&y<=containerBounds.bottom){y+=dy;const points=[[x-dx,y],[x,y],[x+dx,y]];const elements=points.map(point=>document.elementFromPoint(...point)).filter(element=>element&&this._root.contains(element)&&(!element.classList.contains("mq-root-block")&&!element.classList.contains("mq-non-leaf")||element.classList.contains("mq-empty")||element.classList.contains("mq-hasCursor")));let hitNode=null;const nonLeafElements=[];let max=0;const counts={};const elementsById={};for(const element of elements){const id=element?.getAttribute("mathquill-command-id");if(id!=null){counts[id]=(counts[id]||0)+1;elementsById[id]=element;}else {nonLeafElements.push(element);}}for(const[id,count]of entries(counts)){if(count>max){max=count;hitNode=elementsById[id];}}if(hitNode==null&&nonLeafElements.length>0){hitNode=nonLeafElements[0];}if(hitNode!==null){this.mathField.setCursorPosition(x,y,hitNode);return true}}return false}_insertCursorAtClosestNode(x,y){const cursor=this.mathField.getCursor();if(!this._root.hasChildNodes()){cursor.insAtLeftEnd(this.mathField.mathField.controller().root);return}if(y>this._containerBounds.bottom){y=this._containerBounds.bottom-10;}else if(y<this._containerBounds.top){y=this._containerBounds.top+10;}if(x>this._containerBounds.right){x=this._containerBounds.right-15;}else if(x<this._containerBounds.left){x=this._containerBounds.left+15;}let dy;dy=-8;const dx=5;if(this._findHitNode(this._containerBounds,x,y,dx,dy)){return}y=this._containerBounds.top;dy=8;if(this._findHitNode(this._containerBounds,x,y,dx,dy)){return}const firstChildBounds=this._root.firstChild.getBoundingClientRect();const lastChildBounds=this._root.lastChild.getBoundingClientRect();const left=firstChildBounds.left;const right=lastChildBounds.right;if(Math.abs(x-right)<Math.abs(x-left)){cursor.insAtRightEnd(this.mathField.mathField.controller().root);}else {cursor.insAtLeftEnd(this.mathField.mathField.controller().root);}this.props.keypadElement?.setCursor({context:this.mathField.contextForCursor()});}_constrainToBound(value,min,max,friction){if(value<min){return min+(value-min)*friction}else if(value>max){return max+(value-max)*friction}else {return value}}render(){const{showInputFocusStyle,handle}=this.state;const{style}=this.props;const innerStyle={...inlineStyles.innerContainer,borderWidth:this.getBorderWidthPx(),...showInputFocusStyle?{borderColor:semanticColor.core.border.instructive.default}:{},...style};const ariaLabel=this.context.strings.mathInputBox+" "+this.context.strings.fingerTap;return jsxRuntimeExports.jsx(KeypadContext.Consumer,{children:({keypadActive,setKeypadActive})=>jsxRuntimeExports.jsxs(View,{style:styles$6.input,onTouchStart:e=>{this.handleTouchStart(e,keypadActive,setKeypadActive);},onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd,onClick:e=>{this.handleClick(e,keypadActive,setKeypadActive);},role:"textbox","aria-label":ariaLabel,children:[jsxRuntimeExports.jsx("div",{className:"keypad-input",tabIndex:0,ref:node=>{this.inputRef=node;},onFocus:()=>{this.focus(setKeypadActive);},onBlur:this.blur,onKeyUp:this.handleKeyUp,children:jsxRuntimeExports.jsx("div",{ref:node=>{this._mathContainer=ReactDOM.findDOMNode(node);},style:innerStyle})}),showInputFocusStyle&&handle.visible&&jsxRuntimeExports.jsx(CursorHandle,{...handle,onTouchStart:this.onCursorHandleTouchStart,onTouchMove:this.onCursorHandleTouchMove,onTouchEnd:this.onCursorHandleTouchEnd,onTouchCancel:this.onCursorHandleTouchCancel})]})})}constructor(...args){super(...args),this.state={focused:false,showInputFocusStyle:false,handle:{animateIntoPosition:false,visible:false,x:0,y:0}},this._updateInputPadding=()=>{this._container=ReactDOM.findDOMNode(this);this._root=this._container.querySelector(".mq-root-block");const padding=this.getInputInnerPadding();this._root.style.padding=`${padding.paddingTop}px ${padding.paddingRight}px`+` ${padding.paddingBottom}px ${padding.paddingLeft}px`;this._root.style.fontSize=`${fontSizePt}pt`;},this._updateCursorHandle=animateIntoPosition=>{const containerBounds=this._container.getBoundingClientRect();const cursor=this._container.querySelector(".mq-cursor");const cursorBounds=cursor.getBoundingClientRect();const cursorWidth=cursorBounds.width;const gapBelowCursor=2;const inputInnerPadding=this.getInputInnerPadding();const furthestRightCursorBound=containerBounds.right-cursorWidth-inputInnerPadding.paddingRight;const furthestLeftCursorBound=containerBounds.left+cursorWidth+inputInnerPadding.paddingLeft;let cursorBoundsLeft=cursorBounds.left;if(cursorBounds.left>furthestRightCursorBound){cursorBoundsLeft=furthestRightCursorBound;}else if(cursorBounds.left<furthestLeftCursorBound){cursorBoundsLeft=furthestLeftCursorBound;}this.setState({handle:{visible:true,animateIntoPosition,x:cursorBoundsLeft+cursorWidth/2-containerBounds.left,y:cursorBounds.bottom+gapBelowCursor-containerBounds.top}});},this._hideCursorHandle=()=>{this.setState({handle:{visible:false,x:0,y:0}});},this._handleScroll=()=>{if(this.state.handle.animateIntoPosition!==false){this._hideCursorHandle();}},this.blur=()=>{this.mathField.blur();this.setState({showInputFocusStyle:false,handle:{visible:false}});},this.focus=setKeypadActive=>{this.props.keypadElement?.setKeyHandler(key=>{const cursor=this.mathField.pressKey(key);const hideCursor=()=>{this.setState({handle:{visible:false}});};const value=this.mathField.getContent();if(this.props.value!==value){this.props.onChange(value,hideCursor);}else {hideCursor();}return cursor});this.mathField.focus();this.props?.onFocus();setKeypadActive(true);this.setState({focused:true,showInputFocusStyle:true},()=>{setTimeout(()=>{if(this._isMounted){const maybeKeypadNode=this.props.keypadElement?.getDOMNode();scrollIntoView(this._container,maybeKeypadNode);}});});},this.handleTouchStart=(e,keypadActive,setKeypadActive)=>{e.stopPropagation();this._hideCursorHandle();if(this.mathField.getContent()!==""){this._containerBounds=this._container.getBoundingClientRect();const touch=e.changedTouches[0];this._insertCursorAtClosestNode(touch.clientX,touch.clientY);}if(this.state.focused&&!keypadActive){setKeypadActive(true);}if(!this.state.focused){this.focus(setKeypadActive);}this.inputRef?.focus();},this.handleClick=(e,keypadActive,setKeypadActive)=>{e.stopPropagation();this._hideCursorHandle();if(this.mathField.getContent()!==""){this._containerBounds=this._container.getBoundingClientRect();this._insertCursorAtClosestNode(e.clientX,e.clientY);}if(this.state.focused&&!keypadActive){setKeypadActive(true);}if(!this.state.focused){this.focus(setKeypadActive);}this.inputRef?.focus();},this.handleTouchMove=e=>{e.stopPropagation();if(this.mathField.getContent()!==""&&this.state.focused){const touch=e.changedTouches[0];this._insertCursorAtClosestNode(touch.clientX,touch.clientY);}},this.handleTouchEnd=e=>{e.stopPropagation();if(this.mathField.getContent()!==""&&this.state.focused){this._updateCursorHandle();}},this.onCursorHandleTouchStart=e=>{e.stopPropagation();e.preventDefault();this._containerBounds=this._container.getBoundingClientRect();},this.onCursorHandleTouchMove=e=>{e.stopPropagation();const x=e.changedTouches[0].clientX;const y=e.changedTouches[0].clientY;const relativeX=x-this._containerBounds.left;const relativeY=y-2*cursorHandleRadiusPx*cursorHandleDistanceMultiplier-this._containerBounds.top;this.setState({handle:{animateIntoPosition:false,visible:true,x:this._constrainToBound(relativeX,0,this._containerBounds.width,constrainingFrictionFactor),y:this._constrainToBound(relativeY,0,this._containerBounds.height,constrainingFrictionFactor)}});const distanceAboveFingerToTrySelecting=22;const adjustedY=y-distanceAboveFingerToTrySelecting;this._insertCursorAtClosestNode(x,adjustedY);},this.onCursorHandleTouchEnd=e=>{e.stopPropagation();this._updateCursorHandle(true);},this.onCursorHandleTouchCancel=e=>{e.stopPropagation();this._updateCursorHandle(true);},this.domKeyToMathQuillKey=key=>{const keyMap={"+":"PLUS","-":"MINUS","*":"TIMES","/":"DIVIDE",".":"DECIMAL","%":"PERCENT","=":"EQUAL",">":"GT","<":"LT","^":"EXP"};if(["0","1","2","3","4","5","6","7","8","9"].includes(key)){return `NUM_${key}`}else if(key==="Backspace"){return "BACKSPACE"}else if(key in keyMap){return keyMap[key]}return null},this.handleKeyUp=e=>{const mathQuillKey=this.domKeyToMathQuillKey(e.key);if(mathQuillKey){this.mathField.pressKey(mathQuillKey);const value=this.mathField.getContent();if(this.props.value!==value){this.mathField.setContent(this.props.value);this.props.onChange(value,()=>{});this._hideCursorHandle();}}},this.getBorderWidthPx=()=>{const normalBorderWidthPx=1;const focusedBorderWidthPx=2;return this.state.focused?focusedBorderWidthPx:normalBorderWidthPx},this.getInputInnerPadding=()=>{const paddingInset=totalDesiredPadding-this.getBorderWidthPx();const symbolaPaddingBottom=3;const symbolaPaddingTop=1;const cursorPadding=2;const padding={paddingTop:paddingInset-symbolaPaddingTop,paddingRight:paddingInset+cursorPadding,paddingBottom:paddingInset-symbolaPaddingBottom,paddingLeft:paddingInset+cursorPadding};return padding};}}MathInput.contextType=MathInputI18nContext;MathInput.defaultProps={style:{},value:""};MathInput.contextType=MathInputI18nContext;const fontSizePt=18;const inputMaxWidth=128;const numeralHeightPx=20;const totalDesiredPadding=12;const minHeightPx=numeralHeightPx+totalDesiredPadding*2;const minWidthPx=64;const styles$6=StyleSheet.create({input:{position:"relative",display:"inline-block",verticalAlign:"middle",maxWidth:inputMaxWidth}});const inlineStyles={innerContainer:{backgroundColor:"white",minHeight:minHeightPx,minWidth:minWidthPx,maxWidth:inputMaxWidth,boxSizing:"border-box",position:"relative",borderStyle:"solid",borderColor:semanticColor.core.border.neutral.default,borderRadius:4,color:semanticColor.core.foreground.neutral.strong}};
1436
1436
 
1437
1437
  const getDefaultOperatorFields=({key,keyType="OPERATOR",ariaLabel=key,data=key})=>({id:key,type:keyType,ariaLabel,icon:{data}});const getDefaultValueFields=({key,keyType="VALUE",ariaLabel=key,data=key})=>({id:key,type:keyType,ariaLabel,icon:{data}});const getDefaultNumberFields=({key,data=key.replace("NUM_",""),keyType="VALUE",ariaLabel=data})=>({id:key,type:keyType,ariaLabel,icon:{data}});const KeyConfigs=strings=>({PLUS:{...getDefaultOperatorFields({key:"PLUS",ariaLabel:strings.plus})},MINUS:{...getDefaultOperatorFields({key:"MINUS",ariaLabel:strings.minus})},NEGATIVE:{...getDefaultOperatorFields({key:"NEGATIVE",ariaLabel:strings.negative})},TIMES:{...getDefaultOperatorFields({key:"TIMES",ariaLabel:strings.times})},DIVIDE:{...getDefaultOperatorFields({key:"DIVIDE",ariaLabel:strings.divide})},DECIMAL:{...getDefaultOperatorFields({key:"DECIMAL",keyType:"VALUE",ariaLabel:strings.decimal})},PERIOD:{...getDefaultOperatorFields({key:"PERIOD",keyType:"VALUE",ariaLabel:"."})},PERCENT:{...getDefaultOperatorFields({key:"PERCENT",ariaLabel:strings.percent})},CDOT:{...getDefaultOperatorFields({key:"CDOT",ariaLabel:strings.cdot})},EQUAL:{...getDefaultOperatorFields({key:"EQUAL",ariaLabel:strings.equalsSign})},NEQ:{...getDefaultOperatorFields({key:"NEQ",ariaLabel:strings.notEqualsSign})},GT:{...getDefaultOperatorFields({key:"GT",ariaLabel:strings.greaterThanSign})},LT:{...getDefaultOperatorFields({key:"LT",ariaLabel:strings.lessThanSign})},GEQ:{...getDefaultOperatorFields({key:"GEQ",ariaLabel:strings.greaterThanOrEqualToSign})},LEQ:{...getDefaultOperatorFields({key:"LEQ",ariaLabel:strings.lessThanOrEqualSign})},FRAC_INCLUSIVE:{...getDefaultOperatorFields({key:"FRAC_INCLUSIVE",ariaLabel:strings.fractionExpressionInNumerator})},FRAC_EXCLUSIVE:{...getDefaultOperatorFields({key:"FRAC_EXCLUSIVE",ariaLabel:strings.fractionExcludingExpression})},FRAC:{...getDefaultOperatorFields({key:"FRAC",ariaLabel:strings.fractionExcludingExpression})},EXP:{...getDefaultOperatorFields({key:"EXP",ariaLabel:strings.customExponent})},EXP_2:{...getDefaultOperatorFields({key:"EXP_2",ariaLabel:strings.square})},EXP_3:{...getDefaultOperatorFields({key:"EXP_3",ariaLabel:strings.cube})},SQRT:{...getDefaultOperatorFields({key:"SQRT",ariaLabel:strings.squareRoot})},CUBE_ROOT:{...getDefaultOperatorFields({key:"CUBE_ROOT",ariaLabel:strings.cubeRoot})},RADICAL:{...getDefaultOperatorFields({key:"RADICAL",ariaLabel:strings.radicalWithCustomRoot})},LEFT_PAREN:{...getDefaultOperatorFields({key:"LEFT_PAREN",ariaLabel:strings.leftParenthesis})},RIGHT_PAREN:{...getDefaultOperatorFields({key:"RIGHT_PAREN",ariaLabel:strings.rightParenthesis})},LN:{...getDefaultOperatorFields({key:"LN",ariaLabel:strings.naturalLog})},LOG:{...getDefaultOperatorFields({key:"LOG",ariaLabel:strings.logBase10})},LOG_N:{...getDefaultOperatorFields({key:"LOG_N",ariaLabel:strings.logCustomBase})},SIN:{...getDefaultOperatorFields({key:"SIN",ariaLabel:strings.sine})},COS:{...getDefaultOperatorFields({key:"COS",ariaLabel:strings.cosine})},TAN:{...getDefaultOperatorFields({key:"TAN",ariaLabel:strings.tangent})},PI:{...getDefaultValueFields({key:"PI",data:"\\pi",ariaLabel:strings.pi})},THETA:{...getDefaultValueFields({key:"THETA",data:"\\theta",ariaLabel:strings.theta})},UP:{...getDefaultOperatorFields({key:"UP",keyType:"INPUT_NAVIGATION",ariaLabel:strings.upArrow})},RIGHT:{...getDefaultOperatorFields({key:"RIGHT",keyType:"INPUT_NAVIGATION",ariaLabel:strings.rightArrow})},DOWN:{...getDefaultOperatorFields({key:"DOWN",keyType:"INPUT_NAVIGATION",ariaLabel:strings.downArrow})},LEFT:{...getDefaultOperatorFields({key:"LEFT",keyType:"INPUT_NAVIGATION",ariaLabel:strings.leftArrow})},JUMP_OUT_PARENTHESES:{...getDefaultOperatorFields({key:"JUMP_OUT_PARENTHESES",keyType:"INPUT_NAVIGATION",ariaLabel:strings.navOutOfParentheses})},JUMP_OUT_EXPONENT:{...getDefaultOperatorFields({key:"JUMP_OUT_EXPONENT",keyType:"INPUT_NAVIGATION",ariaLabel:strings.navOutOfExponent})},JUMP_OUT_BASE:{...getDefaultOperatorFields({key:"JUMP_OUT_BASE",keyType:"INPUT_NAVIGATION",ariaLabel:strings.navOutOfBase})},JUMP_INTO_NUMERATOR:{...getDefaultOperatorFields({key:"JUMP_INTO_NUMERATOR",keyType:"INPUT_NAVIGATION",ariaLabel:strings.navIntoNumerator})},JUMP_OUT_NUMERATOR:{...getDefaultOperatorFields({key:"JUMP_OUT_NUMERATOR",keyType:"INPUT_NAVIGATION",ariaLabel:strings.navOutOfNumeratorIntoDenominator})},JUMP_OUT_DENOMINATOR:{...getDefaultOperatorFields({key:"JUMP_OUT_DENOMINATOR",keyType:"INPUT_NAVIGATION",ariaLabel:strings.navOutOfDenominator})},BACKSPACE:{...getDefaultOperatorFields({key:"BACKSPACE",keyType:"INPUT_NAVIGATION",ariaLabel:strings.delete})},DISMISS:{...getDefaultOperatorFields({key:"DISMISS",keyType:"KEYPAD_NAVIGATION",ariaLabel:strings.dismiss})},NUM_0:{...getDefaultNumberFields({key:"NUM_0"})},NUM_1:{...getDefaultNumberFields({key:"NUM_1"})},NUM_2:{...getDefaultNumberFields({key:"NUM_2"})},NUM_3:{...getDefaultNumberFields({key:"NUM_3"})},NUM_4:{...getDefaultNumberFields({key:"NUM_4"})},NUM_5:{...getDefaultNumberFields({key:"NUM_5"})},NUM_6:{...getDefaultNumberFields({key:"NUM_6"})},NUM_7:{...getDefaultNumberFields({key:"NUM_7"})},NUM_8:{...getDefaultNumberFields({key:"NUM_8"})},NUM_9:{...getDefaultNumberFields({key:"NUM_9"})},A:{...getDefaultValueFields({key:"A"})},B:{...getDefaultValueFields({key:"B"})},C:{...getDefaultValueFields({key:"C"})},D:{...getDefaultValueFields({key:"D"})},E:{...getDefaultValueFields({key:"E"})},F:{...getDefaultValueFields({key:"F"})},G:{...getDefaultValueFields({key:"G"})},H:{...getDefaultValueFields({key:"H"})},I:{...getDefaultValueFields({key:"I"})},J:{...getDefaultValueFields({key:"J"})},K:{...getDefaultValueFields({key:"K"})},L:{...getDefaultValueFields({key:"L"})},M:{...getDefaultValueFields({key:"M"})},N:{...getDefaultValueFields({key:"N"})},O:{...getDefaultValueFields({key:"O"})},P:{...getDefaultValueFields({key:"P"})},Q:{...getDefaultValueFields({key:"Q"})},R:{...getDefaultValueFields({key:"R"})},S:{...getDefaultValueFields({key:"S"})},T:{...getDefaultValueFields({key:"T"})},U:{...getDefaultValueFields({key:"U"})},V:{...getDefaultValueFields({key:"V"})},W:{...getDefaultValueFields({key:"W"})},X:{...getDefaultValueFields({key:"X"})},Y:{...getDefaultValueFields({key:"Y"})},Z:{...getDefaultValueFields({key:"Z"})},a:{...getDefaultValueFields({key:"a"})},b:{...getDefaultValueFields({key:"b"})},c:{...getDefaultValueFields({key:"c"})},d:{...getDefaultValueFields({key:"d"})},e:{...getDefaultValueFields({key:"e"})},f:{...getDefaultValueFields({key:"f"})},g:{...getDefaultValueFields({key:"g"})},h:{...getDefaultValueFields({key:"h"})},i:{...getDefaultValueFields({key:"i"})},j:{...getDefaultValueFields({key:"j"})},k:{...getDefaultValueFields({key:"k"})},l:{...getDefaultValueFields({key:"l"})},m:{...getDefaultValueFields({key:"m"})},n:{...getDefaultValueFields({key:"n"})},o:{...getDefaultValueFields({key:"o"})},p:{...getDefaultValueFields({key:"p"})},q:{...getDefaultValueFields({key:"q"})},r:{...getDefaultValueFields({key:"r"})},s:{...getDefaultValueFields({key:"s"})},t:{...getDefaultValueFields({key:"t"})},u:{...getDefaultValueFields({key:"u"})},v:{...getDefaultValueFields({key:"v"})},w:{...getDefaultValueFields({key:"w"})},x:{...getDefaultValueFields({key:"x"})},y:{...getDefaultValueFields({key:"y"})},z:{...getDefaultValueFields({key:"z"})}});
1438
1438