From 5580ebb713fa85391f813955845d0ca96f30c7c1 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Fri, 3 Nov 2023 14:02:43 +0700 Subject: [PATCH 1/3] fix(web): restores compat with older Android devices --- android/KMEA/app/src/main/assets/keyboard.html | 1 + .../KMEA/app/src/main/assets/other-polyfills.js | 17 +++++++++++++++++ .../main/java/com/keyman/engine/KMManager.java | 2 ++ .../engine/configuration/paddedZoneSource.ts | 12 ++++++------ .../engine/configuration/viewportZoneSource.ts | 12 ++++++------ 5 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 android/KMEA/app/src/main/assets/other-polyfills.js diff --git a/android/KMEA/app/src/main/assets/keyboard.html b/android/KMEA/app/src/main/assets/keyboard.html index b11a21124ec..34d8e5c4c29 100644 --- a/android/KMEA/app/src/main/assets/keyboard.html +++ b/android/KMEA/app/src/main/assets/keyboard.html @@ -15,6 +15,7 @@ polyfill. --> + diff --git a/android/KMEA/app/src/main/assets/other-polyfills.js b/android/KMEA/app/src/main/assets/other-polyfills.js new file mode 100644 index 00000000000..1bd1960e58e --- /dev/null +++ b/android/KMEA/app/src/main/assets/other-polyfills.js @@ -0,0 +1,17 @@ +// Needed by the KMW's gesture engine until Chrome 61. +var DOMRect = DOMRect || function (x, y, width, height) { + this.x = this.left = x; + this.y = this.top = y; + this.width = width; + this.height = height; + this.bottom = y + height; + this.right = x + width; +}; + +// https://stackoverflow.com/questions/53308396/how-to-polyfill-array-prototype-includes-for-ie8 +if(!Array.prototype.includes){ + //or use Object.defineProperty + Array.prototype.includes = function(search){ + return !!~this.indexOf(search); + } +} diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index cbcb28053a1..eee43592f3b 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -281,6 +281,7 @@ public String toString() { protected static final String KMFilename_KmwGlobeHintCss = "globe-hint.css"; protected static final String KMFilename_Osk_Ttf_Font = "keymanweb-osk.ttf"; protected static final String KMFilename_JSPolyfill = "es6-shim.min.js"; + protected static final String KMFilename_JSPolyfill2 = "other-polyfills.js"; // Deprecated by KeyboardController.KMFilename_Installed_KeyboardsList public static final String KMFilename_KeyboardsList = "keyboards_list.dat"; @@ -812,6 +813,7 @@ private static void copyAssets(Context context) { // Copy default keyboard font copyAsset(context, KMDefault_KeyboardFont, "", true); copyAsset(context, KMFilename_JSPolyfill, "", true); + copyAsset(context, KMFilename_JSPolyfill2, "", true); // Keyboard packages directory File packagesDir = new File(getPackagesDir()); diff --git a/common/web/gesture-recognizer/src/engine/configuration/paddedZoneSource.ts b/common/web/gesture-recognizer/src/engine/configuration/paddedZoneSource.ts index fa9cfd37e11..794c74665d8 100644 --- a/common/web/gesture-recognizer/src/engine/configuration/paddedZoneSource.ts +++ b/common/web/gesture-recognizer/src/engine/configuration/paddedZoneSource.ts @@ -125,11 +125,11 @@ export class PaddedZoneSource implements RecognitionZoneSource { getBoundingClientRect(): DOMRect { const rootZone = this.root.getBoundingClientRect(); - return DOMRect.fromRect({ - x: rootZone.x + this.edgePadding.x, - y: rootZone.y + this.edgePadding.y, - width: rootZone.width - this.edgePadding.w, - height: rootZone.height - this.edgePadding.h - }); + return new DOMRect( + /*x:*/ rootZone.x + this.edgePadding.x, + /*y:*/ rootZone.y + this.edgePadding.y, + /*width:*/ rootZone.width - this.edgePadding.w, + /*height:*/ rootZone.height - this.edgePadding.h + ); } } \ No newline at end of file diff --git a/common/web/gesture-recognizer/src/engine/configuration/viewportZoneSource.ts b/common/web/gesture-recognizer/src/engine/configuration/viewportZoneSource.ts index c558a2aaf78..57f277d42a6 100644 --- a/common/web/gesture-recognizer/src/engine/configuration/viewportZoneSource.ts +++ b/common/web/gesture-recognizer/src/engine/configuration/viewportZoneSource.ts @@ -5,11 +5,11 @@ export class ViewportZoneSource implements RecognitionZoneSource { getBoundingClientRect(): DOMRect { // Viewport dimension detection is based on https://stackoverflow.com/a/8876069. - return DOMRect.fromRect({ - y: 0, - x: 0, - width: Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0), - height: Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0) - }); + return new DOMRect( + /*x:*/ 0, + /*y:*/ 0, + /*width:*/ Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0), + /*height:*/ Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0) + ); } } \ No newline at end of file From 52897769e41e60586161cc79d24f641a4a5abbe7 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Mon, 6 Nov 2023 15:13:08 +0700 Subject: [PATCH 2/3] fix(web): fixes #9561 - disables esbuild's keepNames setting --- common/web/lm-worker/build-bundler.js | 1 + common/web/lm-worker/build-wrap-and-minify.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common/web/lm-worker/build-bundler.js b/common/web/lm-worker/build-bundler.js index 1c4045d5e29..42881f38310 100644 --- a/common/web/lm-worker/build-bundler.js +++ b/common/web/lm-worker/build-bundler.js @@ -51,6 +51,7 @@ await esbuild.build(embeddedWorkerBuildOptions); const minifiedProfilingOptions = { ...embeddedWorkerBuildOptions, minify: true, + keepNames: false, // Do NOT enable - will break under Android 5.0 / Chrome 35 environments! metafile: true, write: false // don't actually write the file. } diff --git a/common/web/lm-worker/build-wrap-and-minify.js b/common/web/lm-worker/build-wrap-and-minify.js index 1572238b7a8..08e2127062b 100644 --- a/common/web/lm-worker/build-wrap-and-minify.js +++ b/common/web/lm-worker/build-wrap-and-minify.js @@ -34,7 +34,7 @@ if(MINIFY) { sourcemap: 'external', sourcesContent: DEBUG, minify: true, - keepNames: true, + keepNames: false, // Do NOT enable - will break under Android 5.0 / Chrome 35 environments! target: 'es5', outfile: `build/lib/worker-main.polyfilled.min.js` }); From 3ea4a6019610c14e0321dc0b76325406a98ebd41 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Tue, 7 Nov 2023 09:18:40 +0700 Subject: [PATCH 3/3] docs(web): doc of min Chrome version for keepNames --- common/web/lm-worker/build-bundler.js | 4 +++- common/web/lm-worker/build-wrap-and-minify.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/web/lm-worker/build-bundler.js b/common/web/lm-worker/build-bundler.js index 42881f38310..0066c05c296 100644 --- a/common/web/lm-worker/build-bundler.js +++ b/common/web/lm-worker/build-bundler.js @@ -51,7 +51,9 @@ await esbuild.build(embeddedWorkerBuildOptions); const minifiedProfilingOptions = { ...embeddedWorkerBuildOptions, minify: true, - keepNames: false, // Do NOT enable - will break under Android 5.0 / Chrome 35 environments! + // Do NOT enable - will break under Android 5.0 / Chrome 35 environments, likely through Chrome 42. + // https://caniuse.com/mdn-javascript_builtins_function_name_configurable_true + keepNames: false, metafile: true, write: false // don't actually write the file. } diff --git a/common/web/lm-worker/build-wrap-and-minify.js b/common/web/lm-worker/build-wrap-and-minify.js index 08e2127062b..07032e539b2 100644 --- a/common/web/lm-worker/build-wrap-and-minify.js +++ b/common/web/lm-worker/build-wrap-and-minify.js @@ -34,7 +34,9 @@ if(MINIFY) { sourcemap: 'external', sourcesContent: DEBUG, minify: true, - keepNames: false, // Do NOT enable - will break under Android 5.0 / Chrome 35 environments! + // Do NOT enable - will break under Android 5.0 / Chrome 35 environments, likely through Chrome 42. + // https://caniuse.com/mdn-javascript_builtins_function_name_configurable_true + keepNames: false, target: 'es5', outfile: `build/lib/worker-main.polyfilled.min.js` });