Skip to content

Commit

Permalink
Don't override falsy user options; Don't mutate options object
Browse files Browse the repository at this point in the history
  • Loading branch information
bearfriend committed Aug 29, 2023
1 parent c906c79 commit 99d530a
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: false,
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 99d530a

Please sign in to comment.