11import { solve , solveBatch , type Result } from './solve' ;
22import { addBuiltinFunctions , type ComputeFunction } from './functions' ;
3- import { renderTokensAsHTML } from './render/html' ;
3+ import { renderTokensAsHTML , HTMLRenderOptions } from './render/html' ;
44import { tokenize } from './lexer' ;
5- import { renderTokensAsLaTeX } from './render/latex' ;
5+ import { renderTokensAsLaTeX , LaTeXRenderOptions } from './render/latex' ;
66
77type Preferences = {
88 fractionDigits : number ;
99 precision : number ;
1010 angles : 'rad' | 'deg' ;
11- [ k : string ] : string | number ;
1211} ;
1312
1413export type Context = {
@@ -19,10 +18,10 @@ export type Context = {
1918} ;
2019
2120export interface ContextAPI extends Context {
22- solve : ( code : string ) => Result ;
23- solveBatch : ( code : string ) => Result [ ] ;
24- renderAsHTML : ( code : string ) => string ;
25- renderAsLaTeX : ( code : string ) => string ;
21+ solve ( code : string ) : Result ;
22+ solveBatch ( code : string ) : Result [ ] ;
23+ renderAsHTML ( code : string , options ?: Partial < HTMLRenderOptions > ) : string ;
24+ renderAsLaTeX ( code : string , options ?: Partial < LaTeXRenderOptions > ) : string ;
2625}
2726
2827export type ContextOptions = {
@@ -58,8 +57,10 @@ export function createContext(
5857
5958 if ( options ?. preferences ) {
6059 for ( const k in ctx . preferences ) {
61- const v = options . preferences [ k ] ;
62- if ( v ) ctx . preferences [ k ] = v ;
60+ const v = ( options . preferences as Record < string , string | number > ) [
61+ k
62+ ] ;
63+ if ( v ) ( ctx . preferences as Record < string , string | number > ) [ k ] = v ;
6364 }
6465 }
6566
@@ -79,10 +80,17 @@ export function createContext(
7980
8081 return {
8182 ...ctx ,
82- solve : ( code : string ) => solve ( ctx , code ) ,
83- solveBatch : ( code : string ) => solveBatch ( ctx , code ) ,
84- renderAsHTML : ( code : string ) => renderTokensAsHTML ( tokenize ( ctx , code ) ) ,
85- renderAsLaTeX : ( code : string ) =>
86- renderTokensAsLaTeX ( tokenize ( ctx , code ) )
83+ solve ( code : string ) {
84+ return solve ( ctx , code ) ;
85+ } ,
86+ solveBatch ( code : string ) {
87+ return solveBatch ( ctx , code ) ;
88+ } ,
89+ renderAsHTML ( code : string , options ?: HTMLRenderOptions ) {
90+ return renderTokensAsHTML ( tokenize ( ctx , code ) , options ) ;
91+ } ,
92+ renderAsLaTeX ( code : string , options ?: LaTeXRenderOptions ) {
93+ return renderTokensAsLaTeX ( tokenize ( ctx , code ) , options ) ;
94+ }
8795 } ;
8896}
0 commit comments