Skip to content

Commit

Permalink
feat: Allow falsy reset options (#153)
Browse files Browse the repository at this point in the history
* Allow non-nullish falsy option values in reset

* Don't override falsy user options; Don't mutate options object

* Fix rtl
  • Loading branch information
bearfriend authored Aug 30, 2023
1 parent 6a9ade7 commit a1259d1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/browser/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ export function requestMouseReset() {
shouldResetMouse = true;
}

export async function reset(opts) {
export async function reset(opts = {}) {

opts = opts || {};
opts.lang = opts.lang || DEFAULT_LANG;
opts.mathjax = opts.mathjax || {};
const defaultOpts = {
lang: DEFAULT_LANG,
mathjax: {},
rtl: !!opts.lang?.startsWith('ar'),
viewport: {
height: DEFAULT_VIEWPORT_HEIGHT,
width: DEFAULT_VIEWPORT_WIDTH
}
};

opts = { ...defaultOpts, ...opts };
opts.viewport = { ...defaultOpts.viewport, ...opts.viewport };
opts.mathjax.renderLatex = (typeof opts.mathjax.renderLatex === 'boolean') ? opts.mathjax.renderLatex : DEFAULT_MATHJAX_RENDER_LATEX;
opts.rtl = opts.lang.startsWith('ar') || !!opts.rtl;
opts.viewport = opts.viewport || {};
opts.viewport.height = opts.viewport.height || DEFAULT_VIEWPORT_HEIGHT;
opts.viewport.width = opts.viewport.width || DEFAULT_VIEWPORT_WIDTH;

let awaitNextFrame = false;

Expand Down

0 comments on commit a1259d1

Please sign in to comment.