From ca36a3433210d7605af7837f2872afb1f8422562 Mon Sep 17 00:00:00 2001 From: tams sokari Date: Wed, 1 Nov 2023 19:34:03 +0100 Subject: [PATCH] refactor: make hasMoreThanNColors a top level function --- packages/components/smart-camera-web.js | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/components/smart-camera-web.js b/packages/components/smart-camera-web.js index 1848f3ff..3a47b05f 100644 --- a/packages/components/smart-camera-web.js +++ b/packages/components/smart-camera-web.js @@ -1185,18 +1185,16 @@ class PoweredBySmileId extends HTMLElement { } } -class SmileIdCanvas { - static hasMoreThanNColors(data, n = 16) { - const colors = new Set(); - for (let i = 0; i < Math.min(data.length, 10000); i += 4) { - // eslint-disable-next-line no-bitwise - colors.add((data[i] << 16) | (data[i + 1] << 8) | data[i + 2]); - if (colors.size > n) { - return true; - } - } - return false; - } +function hasMoreThanNColors(data, n = 16) { + const colors = new Set(); + for (let i = 0; i < Math.min(data.length, 10000); i += 4) { + // eslint-disable-next-line no-bitwise + colors.add((data[i] << 16) | (data[i + 1] << 8) | data[i + 2]); + if (colors.size > n) { + return true; + } + } + return false; } window.customElements.define('powered-by-smile-id', PoweredBySmileId); @@ -1600,9 +1598,9 @@ class SmartCameraWeb extends HTMLElement { if (!disableImageTests) { const imageData = context.getImageData(0, 0, canvas.width, canvas.height); - const hasManyColors = SmileIdCanvas.hasMoreThanNColors(imageData.data); + const hasEnoughColors = hasMoreThanNColors(imageData.data); - if (hasManyColors) { + if (hasEnoughColors) { return context; } this.selectSelfie.disabled = true;