From 012334a8781c523b9b269a270ebd26a8d72d0315 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Tue, 29 Aug 2023 10:26:51 -0400 Subject: [PATCH 1/3] Allow non-nullish falsy option values in reset --- src/browser/reset.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/browser/reset.js b/src/browser/reset.js index 491088ab..8710e8c8 100644 --- a/src/browser/reset.js +++ b/src/browser/reset.js @@ -20,13 +20,13 @@ export function requestMouseReset() { export async function reset(opts) { opts = opts || {}; - opts.lang = opts.lang || DEFAULT_LANG; - opts.mathjax = opts.mathjax || {}; + opts.lang = opts.lang ?? DEFAULT_LANG; + opts.mathjax = opts.mathjax ?? {}; 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; + 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; From 7833b485d36df871b222381c746b92373f006c64 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Tue, 29 Aug 2023 11:54:52 -0400 Subject: [PATCH 2/3] 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; From 01df157acafa64e5fea7be9a01bea3d0ebbdf935 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Tue, 29 Aug 2023 12:08:36 -0400 Subject: [PATCH 3/3] Fix rtl --- src/browser/reset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/reset.js b/src/browser/reset.js index 781c308c..3798d103 100644 --- a/src/browser/reset.js +++ b/src/browser/reset.js @@ -22,7 +22,7 @@ export async function reset(opts = {}) { const defaultOpts = { lang: DEFAULT_LANG, mathjax: {}, - rtl: false, + rtl: !!opts.lang?.startsWith('ar'), viewport: { height: DEFAULT_VIEWPORT_HEIGHT, width: DEFAULT_VIEWPORT_WIDTH