From 7833b485d36df871b222381c746b92373f006c64 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Tue, 29 Aug 2023 11:54:52 -0400 Subject: [PATCH] Don't override falsy user options; Don't mutate options object --- src/browser/reset.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/browser/reset.js b/src/browser/reset.js index 8710e8c8..781c308c 100644 --- a/src/browser/reset.js +++ b/src/browser/reset.js @@ -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;