From f6e384789ba64a25ae4e319b5588ff107dbfe647 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Tue, 21 Nov 2023 13:04:26 +0700 Subject: [PATCH] fix(web): DRYing it out re: app/browser's version --- web/src/app/browser/src/languageMenu.ts | 4 +- .../app/browser/src/utils/getViewportScale.ts | 42 ------------------- web/src/app/browser/src/utils/index.ts | 2 +- web/src/engine/osk/src/index.ts | 2 + 4 files changed, 5 insertions(+), 45 deletions(-) delete mode 100644 web/src/app/browser/src/utils/getViewportScale.ts diff --git a/web/src/app/browser/src/languageMenu.ts b/web/src/app/browser/src/languageMenu.ts index 5a0953ec472..65294704b47 100644 --- a/web/src/app/browser/src/languageMenu.ts +++ b/web/src/app/browser/src/languageMenu.ts @@ -216,7 +216,7 @@ export class LanguageMenu { if(device.OS == 'ios') { if(device.formFactor == 'phone') { barWidth=(landscapeView() ? 36 : 0); - maxHeight=(window.innerHeight-barWidth-16)*util.getViewportScale(); + maxHeight=(window.innerHeight-barWidth-16)*util.getViewportScale(device.formFactor); } else if(device.formFactor == 'tablet') { barWidth=(landscapeView() ? 16 : 0); maxHeight=(maxHeight-barWidth); @@ -316,7 +316,7 @@ export class LanguageMenu { langs.sort(); // Get current scale factor (reciprocal of viewport scale) - var scale=Math.round(100/util.getViewportScale())/100; + var scale=Math.round(100/util.getViewportScale(device.formFactor))/100; var dx,lgBar,i,kb,activeLanguageIndex=-1; for(k=0; k viewportWidth) { - return 1; - } - - // Get the orientation corrected screen width - var screenWidth = screen.width; - if(this.landscapeView()) { - // Take larger of the two dimensions - if(screen.width < screen.height) { - screenWidth = screen.height; - } - } else { - // Take smaller of the two dimensions - if(screen.width > screen.height) { - screenWidth = screen.height; - } - } - // Calculate viewport scale - return Math.round(100*screenWidth / viewportWidth)/100; - } catch(ex) { - return 1; - } -} diff --git a/web/src/app/browser/src/utils/index.ts b/web/src/app/browser/src/utils/index.ts index d4decbd0026..ce193e88beb 100644 --- a/web/src/app/browser/src/utils/index.ts +++ b/web/src/app/browser/src/utils/index.ts @@ -1,5 +1,5 @@ export { AlertHost } from './alertHost.js'; export { _CreateElement } from './createElement.js'; export { getStyleValue } from './getStyleValue.js'; -export { getViewportScale } from './getViewportScale.js'; +export { getViewportScale } from 'keyman/engine/osk'; export { whenDocumentReady } from './documentReady.js'; \ No newline at end of file diff --git a/web/src/engine/osk/src/index.ts b/web/src/engine/osk/src/index.ts index 1340424583c..fd363dd123b 100644 --- a/web/src/engine/osk/src/index.ts +++ b/web/src/engine/osk/src/index.ts @@ -20,6 +20,8 @@ export { type OSKKeySpec } from './keyboard-layout/oskKey.js'; export { type default as InputEventCoordinate } from './input/inputEventCoordinate.js'; export { type default as EmbeddedGestureConfig } from './config/embeddedGestureConfig.js'; +export { getViewportScale } from './screenUtils.js'; + export { default as Activator, StaticActivator } from './views/activator.js'; export { default as SimpleActivator } from './views/simpleActivator.js'; export { default as TwoStateActivator } from './views/twoStateActivator.js';