import { Argument , defineFunction } from './definitions-utils' ; import type { Atom } from '../core/atom-class' ; import { EncloseAtom , EncloseAtomOptions } from '../core-atoms/enclose' ; import { Style } from '../public/core' ; defineFunction ( 'enclose' , '{notation:string}[style:string]{body:auto}' , { createAtom : ( command , args , style ) : Atom => { const options = { strokeColor : 'currentColor' , strokeWidth : '' , strokeStyle : 'solid' , backgroundcolor : 'transparent' , padding : 'auto' , shadow : 'auto' , svgStrokeStyle : undefined , borderStyle : undefined , style , } ; if ( args [ 1 ] ) { const styles = ( args [ 1 ] as string ) . split ( /,(?![^(]*\)(?:(?:[^(]*\)){2})*[^"]*$)/ ) ; for ( const s of styles ) { const shorthand = s . match ( /\s*(\S+)\s+(\S+)\s+(.*)/ ) ; if ( shorthand ) { options . strokeWidth = shorthand [ 1 ] ; options . strokeStyle = shorthand [ 2 ] ; options . strokeColor = shorthand [ 3 ] ; } else { const attribute = s . match ( /\s*([a-z]*)\s*=\s*"(.*)"/ ) ; if ( attribute ) { if ( attribute [ 1 ] === 'mathbackground' ) { options . backgroundcolor = attribute [ 2 ] ; } else if ( attribute [ 1 ] === 'mathcolor' ) { options . strokeColor = attribute [ 2 ] ; } else if ( attribute [ 1 ] === 'padding' ) { options . padding = attribute [ 2 ] ; } else if ( attribute [ 1 ] === 'shadow' ) { options . shadow = attribute [ 2 ] ; } } } } if ( options . strokeStyle === 'dashed' ) { options . svgStrokeStyle = '5,5' ; } else if ( options . strokeStyle === 'dotted' ) { options . svgStrokeStyle = '1,5' ; } } options . borderStyle = `${ options . strokeWidth } ${ options . strokeStyle } ${ options . strokeColor }` ; const notation = { } ; ( ( args [ 0 ] as string ) ?? '' ) . split ( /[, ]/ ) . filter ( ( v ) => v . length > 0 ) . forEach ( ( x ) => { notation [ x . toLowerCase ( ) ] = true ; } ) ; return new EncloseAtom ( command , args [ 2 ] as Atom [ ] , notation , options ) ; } , } ) ; defineFunction ( 'cancel' , '{body:auto}' , { createAtom : ( name , args , style ) : Atom => new EncloseAtom ( name , args [ 0 ] as Atom [ ] , { updiagonalstrike : true } , { strokeColor : 'currentColor' , strokeWidth : '' , strokeStyle : 'solid' , borderStyle : '1px solid currentColor' , backgroundcolor : 'transparent' , padding : 'auto' , shadow : 'auto' , style , } ) , } ) ; defineFunction ( 'bcancel' , '{body:auto}' , { createAtom : ( name , args , style ) : Atom => new EncloseAtom ( name , args [ 0 ] as Atom [ ] , { downdiagonalstrike : true } , { strokeColor : 'currentColor' , strokeWidth : '' , strokeStyle : 'solid' , borderStyle : '1px solid currentColor' , backgroundcolor : 'transparent' , padding : 'auto' , shadow : 'auto' , style , } ) , } ) ; defineFunction ( 'xcancel' , '{body:auto}' , { createAtom : ( name , args , style ) : Atom => new EncloseAtom ( name , args [ 0 ] as Atom [ ] , { updiagonalstrike : true , downdiagonalstrike : true } , { strokeColor : 'currentColor' , strokeWidth : '' , strokeStyle : 'solid' , borderStyle : '1px solid currentColor' , backgroundcolor : 'transparent' , padding : 'auto' , shadow : 'auto' , style , } ) , } ) ;