From 3fdbc6911bf36800cc2120c9e6f614c8d66faaab Mon Sep 17 00:00:00 2001 From: felixindrawan Date: Fri, 14 Jun 2024 14:46:06 -0700 Subject: [PATCH 1/6] refactor: format and rename classes for js sample --- hello-world/es6.html | 173 ++++++++++++++++-------------- hello-world/hello-world.html | 147 ++++++++++++------------- hello-world/read-an-image.html | 118 ++++++++++---------- hello-world/requirejs.html | 189 +++++++++++++++++---------------- 4 files changed, 324 insertions(+), 303 deletions(-) diff --git a/hello-world/es6.html b/hello-world/es6.html index 01317f0c..e2ee9c18 100644 --- a/hello-world/es6.html +++ b/hello-world/es6.html @@ -1,96 +1,105 @@ + + + + + + + Dynamsoft Barcode Reader Sample - Hello World for ES6 (Decode via Camera) + - - - - - - - Dynamsoft Barcode Reader Sample - Hello World for ES6 (Decode via Camera) - + +

Hello World for ES6 (Decode via Camera)

+
+ Results:
+
+ - - - \ No newline at end of file + // Open camera and start scanning single barcode. + await cameraEnhancer.open(); + await cvRouter.startCapturing("ReadSingleBarcode"); + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + })(); + + + diff --git a/hello-world/hello-world.html b/hello-world/hello-world.html index 394bc99f..1440f0e0 100644 --- a/hello-world/hello-world.html +++ b/hello-world/hello-world.html @@ -1,84 +1,89 @@ - - - - - - - Dynamsoft Barcode Reader Sample - Hello World (Decode via Camera) - + + + + + + + Dynamsoft Barcode Reader Sample - Hello World (Decode via Camera) + - -

Hello World (Decode via Camera)

-
- Results:
-
- - + - + // Open camera and start scanning single barcode. + await cameraEnhancer.open(); + await cvRouter.startCapturing("ReadSingleBarcode"); + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + })(); + + diff --git a/hello-world/read-an-image.html b/hello-world/read-an-image.html index 9c90a1a9..cb7655fe 100644 --- a/hello-world/read-an-image.html +++ b/hello-world/read-an-image.html @@ -1,69 +1,73 @@ - - - - - - - Dynamsoft Barcode Reader Sample - Hello World (Read an Image) - + + + + + + + Dynamsoft Barcode Reader Sample - Hello World (Read an Image) + - -

Hello World (Read an Image)

-
- Results:
-
- - + - + if (files.length > 1) { + divResultContainer.innerText += `\n${file.name}:\n`; + } + for (let item of result.items) { + if (item.type !== Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE) { + continue; + } + divResultContainer.innerText += item.text + "\n"; + console.log(item.text); + } + if (!result.items.length) divResultContainer.innerText += "No barcode found\n"; + } + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + }); + + diff --git a/hello-world/requirejs.html b/hello-world/requirejs.html index 68e95224..a70b1a4d 100644 --- a/hello-world/requirejs.html +++ b/hello-world/requirejs.html @@ -1,106 +1,109 @@ + + + + + + + Dynamsoft Barcode Reader Sample - Hello World for RequireJS (Decode via Camera) + + - - - - - - - Dynamsoft Barcode Reader Sample - Hello World for RequireJS (Decode via Camera) - - + +

Hello World for RequireJS (Decode via Camera)

+
+ Results: +
+
+ - - - \ No newline at end of file + // Open camera and start scanning single barcode. + await cameraEnhancer.open(); + await cvRouter.startCapturing("ReadSingleBarcode"); + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + })(); + } + ); + + + From de9cbaf2dbf6bd5a73baead50850d36973aa2068 Mon Sep 17 00:00:00 2001 From: felixindrawan Date: Fri, 14 Jun 2024 15:31:39 -0700 Subject: [PATCH 2/6] update resultContainer and input class name --- hello-world/read-an-image.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hello-world/read-an-image.html b/hello-world/read-an-image.html index cb7655fe..31dc70f6 100644 --- a/hello-world/read-an-image.html +++ b/hello-world/read-an-image.html @@ -11,7 +11,7 @@

Hello World (Read an Image)

-
+
Results:
@@ -32,15 +32,15 @@

Hello World (Read an Image)

// Optional. Preload "BarcodeReader" module for reading barcodes. It will save time on the initial decoding by skipping the module loading. Dynamsoft.Core.CoreModule.loadWasm(["DBR"]); - const divResultContainer = document.querySelector("#result-container"); + const resultContainer = document.querySelector("#result-container"); let cvRouter; // an instance of CaptureVisionRouter let pCvRouter; // promise of CaptureVisionRouter - document.querySelector("#ipt-file").addEventListener("change", async function () { + document.querySelector("#input-file").addEventListener("change", async function () { let files = [...this.files]; this.value = ""; - divResultContainer.innerText = ""; + resultContainer.innerText = ""; try { cvRouter = cvRouter || @@ -51,16 +51,16 @@

Hello World (Read an Image)

const result = await cvRouter.capture(file, "ReadBarcodes_SpeedFirst"); if (files.length > 1) { - divResultContainer.innerText += `\n${file.name}:\n`; + resultContainer.innerText += `\n${file.name}:\n`; } for (let item of result.items) { if (item.type !== Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE) { continue; } - divResultContainer.innerText += item.text + "\n"; + resultContainer.innerText += item.text + "\n"; console.log(item.text); } - if (!result.items.length) divResultContainer.innerText += "No barcode found\n"; + if (!result.items.length) resultContainer.innerText += "No barcode found\n"; } } catch (ex) { let errMsg = ex.message || ex; From b934ab317c50d0b2fb359cdffb9570e13e500d41 Mon Sep 17 00:00:00 2001 From: felixindrawan Date: Fri, 14 Jun 2024 15:35:36 -0700 Subject: [PATCH 3/6] fix: change resultContainer to resultsContainer --- hello-world/read-an-image.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hello-world/read-an-image.html b/hello-world/read-an-image.html index 31dc70f6..1785d189 100644 --- a/hello-world/read-an-image.html +++ b/hello-world/read-an-image.html @@ -32,7 +32,7 @@

Hello World (Read an Image)

// Optional. Preload "BarcodeReader" module for reading barcodes. It will save time on the initial decoding by skipping the module loading. Dynamsoft.Core.CoreModule.loadWasm(["DBR"]); - const resultContainer = document.querySelector("#result-container"); + const resultsContainer = document.querySelector("#result-container"); let cvRouter; // an instance of CaptureVisionRouter let pCvRouter; // promise of CaptureVisionRouter @@ -40,7 +40,7 @@

Hello World (Read an Image)

document.querySelector("#input-file").addEventListener("change", async function () { let files = [...this.files]; this.value = ""; - resultContainer.innerText = ""; + resultsContainer.innerText = ""; try { cvRouter = cvRouter || @@ -51,16 +51,16 @@

Hello World (Read an Image)

const result = await cvRouter.capture(file, "ReadBarcodes_SpeedFirst"); if (files.length > 1) { - resultContainer.innerText += `\n${file.name}:\n`; + resultsContainer.innerText += `\n${file.name}:\n`; } for (let item of result.items) { if (item.type !== Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE) { continue; } - resultContainer.innerText += item.text + "\n"; + resultsContainer.innerText += item.text + "\n"; console.log(item.text); } - if (!result.items.length) resultContainer.innerText += "No barcode found\n"; + if (!result.items.length) resultsContainer.innerText += "No barcode found\n"; } } catch (ex) { let errMsg = ex.message || ex; From 86dd76aea228c8e6956acc8d592506393554ee9a Mon Sep 17 00:00:00 2001 From: felixindrawan Date: Fri, 14 Jun 2024 16:03:00 -0700 Subject: [PATCH 4/6] refactor: renamed results class --- hello-world/es6.html | 4 ++-- hello-world/hello-world.html | 4 ++-- hello-world/read-an-image.html | 4 ++-- hello-world/requirejs.html | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hello-world/es6.html b/hello-world/es6.html index e2ee9c18..a5b41a11 100644 --- a/hello-world/es6.html +++ b/hello-world/es6.html @@ -16,7 +16,7 @@

Hello World for ES6 (Decode via Camera)

Results:
-
+
- + // Open camera and start scanning single barcode. + await cameraEnhancer.open(); + await cvRouter.startCapturing("ReadSingleBarcode"); + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + })(); + + diff --git a/hello-world/hello-world.html b/hello-world/hello-world.html index 08cbc4cd..0ff66df4 100644 --- a/hello-world/hello-world.html +++ b/hello-world/hello-world.html @@ -1,89 +1,96 @@ - - - - - - - Dynamsoft Barcode Reader Sample - Hello World (Decode via Camera) - + + + + + + + + Dynamsoft Barcode Reader Sample - Hello World (Decode via Camera) + + - -

Hello World (Decode via Camera)

-
- Results:
-
- - + - + // Open camera and start scanning single barcode. + await cameraEnhancer.open(); + await cvRouter.startCapturing("ReadSingleBarcode"); + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + })(); + + diff --git a/hello-world/read-an-image.html b/hello-world/read-an-image.html index 3f9cbe0a..21ea1824 100644 --- a/hello-world/read-an-image.html +++ b/hello-world/read-an-image.html @@ -1,73 +1,97 @@ - - - - - - - Dynamsoft Barcode Reader Sample - Hello World (Read an Image) - + + + + + + + Dynamsoft Barcode Reader Sample - Hello World (Read an Image) + - -

Hello World (Read an Image)

-
- Results:
-
- - + - + resultsContainer.innerText += item.text + "\n"; + console.log(item.text); + } + if (!result.items.length) + resultsContainer.innerText += "No barcode found\n"; + } + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + }); + + diff --git a/hello-world/requirejs.html b/hello-world/requirejs.html index a5bab1b8..56c8882f 100644 --- a/hello-world/requirejs.html +++ b/hello-world/requirejs.html @@ -1,109 +1,120 @@ - - - - - - - Dynamsoft Barcode Reader Sample - Hello World for RequireJS (Decode via Camera) - - + + + + + + + + Dynamsoft Barcode Reader Sample - Hello World for RequireJS (Decode via + Camera) + + + - -

Hello World for RequireJS (Decode via Camera)

-
- Results: -
-
- - + // Open camera and start scanning single barcode. + await cameraEnhancer.open(); + await cvRouter.startCapturing("ReadSingleBarcode"); + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + })(); + } + ); + + From df2918c82a1c7d55431413015065ff095514f09e Mon Sep 17 00:00:00 2001 From: felixindrawan Date: Wed, 19 Jun 2024 09:06:58 -0700 Subject: [PATCH 6/6] fix formatter printWidth to 120 --- hello-world/es6.html | 22 +++------ hello-world/hello-world.html | 26 +++-------- hello-world/read-an-image.html | 82 ++++++++++++---------------------- hello-world/requirejs.html | 34 ++++---------- 4 files changed, 47 insertions(+), 117 deletions(-) diff --git a/hello-world/es6.html b/hello-world/es6.html index d8233cfb..a8694690 100644 --- a/hello-world/es6.html +++ b/hello-world/es6.html @@ -3,18 +3,10 @@ - + - - - Dynamsoft Barcode Reader Sample - Hello World for ES6 (Decode via Camera) - + + Dynamsoft Barcode Reader Sample - Hello World for ES6 (Decode via Camera) @@ -62,13 +54,9 @@

Hello World for ES6 (Decode via Camera)

try { // Create a `CameraEnhancer` instance for camera control and a `CameraView` instance for UI control. const cameraView = await CameraView.createInstance(); - const cameraEnhancer = await CameraEnhancer.createInstance( - cameraView - ); + const cameraEnhancer = await CameraEnhancer.createInstance(cameraView); // Get default UI and append it to DOM. - document - .querySelector("#camera-view-container") - .append(cameraView.getUIElement()); + document.querySelector("#camera-view-container").append(cameraView.getUIElement()); // Create a `CaptureVisionRouter` instance and set `CameraEnhancer` instance as its image source. const cvRouter = await CaptureVisionRouter.createInstance(); diff --git a/hello-world/hello-world.html b/hello-world/hello-world.html index 0ff66df4..9a566c7c 100644 --- a/hello-world/hello-world.html +++ b/hello-world/hello-world.html @@ -3,18 +3,10 @@ - + - - - Dynamsoft Barcode Reader Sample - Hello World (Decode via Camera) - + + Dynamsoft Barcode Reader Sample - Hello World (Decode via Camera) @@ -28,9 +20,7 @@

Hello World (Decode via Camera)

* To use the library, you need to first specify a license key using the API "initLicense()" as shown below. */ - Dynamsoft.License.LicenseManager.initLicense( - "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" - ); + Dynamsoft.License.LicenseManager.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); /** * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr&package=js to get your own trial license good for 30 days. @@ -48,13 +38,9 @@

Hello World (Decode via Camera)

try { // Create a `CameraEnhancer` instance for camera control and a `CameraView` instance for UI control. const cameraView = await Dynamsoft.DCE.CameraView.createInstance(); - cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance( - cameraView - ); + cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView); // Get default UI and append it to DOM. - document - .querySelector("#camera-view-container") - .append(cameraView.getUIElement()); + document.querySelector("#camera-view-container").append(cameraView.getUIElement()); // Create a `CaptureVisionRouter` instance and set `CameraEnhancer` instance as its image source. cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance(); diff --git a/hello-world/read-an-image.html b/hello-world/read-an-image.html index 21ea1824..6652a1b1 100644 --- a/hello-world/read-an-image.html +++ b/hello-world/read-an-image.html @@ -3,26 +3,15 @@ - + - + Dynamsoft Barcode Reader Sample - Hello World (Read an Image)

Hello World (Read an Image)

-
+
Results:
@@ -31,9 +20,7 @@

Hello World (Read an Image)

* To use the library, you need to first specify a license key using the API "initLicense()" as shown below. */ - Dynamsoft.License.LicenseManager.initLicense( - "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" - ); + Dynamsoft.License.LicenseManager.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); /** * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr&package=js to get your own trial license good for 30 days. @@ -50,48 +37,35 @@

Hello World (Read an Image)

let cvRouter; // an instance of CaptureVisionRouter let pCvRouter; // promise of CaptureVisionRouter - document - .querySelector("#input-file") - .addEventListener("change", async function () { - let files = [...this.files]; - this.value = ""; - resultsContainer.innerText = ""; - try { - cvRouter = - cvRouter || - (await (pCvRouter = - pCvRouter || - Dynamsoft.CVR.CaptureVisionRouter.createInstance())); + document.querySelector("#input-file").addEventListener("change", async function () { + let files = [...this.files]; + this.value = ""; + resultsContainer.innerText = ""; + try { + cvRouter = cvRouter || (await (pCvRouter = pCvRouter || Dynamsoft.CVR.CaptureVisionRouter.createInstance())); - for (let file of files) { - // Decode selected image with 'ReadBarcodes_SpeedFirst' template. - const result = await cvRouter.capture( - file, - "ReadBarcodes_SpeedFirst" - ); + for (let file of files) { + // Decode selected image with 'ReadBarcodes_SpeedFirst' template. + const result = await cvRouter.capture(file, "ReadBarcodes_SpeedFirst"); - if (files.length > 1) { - resultsContainer.innerText += `\n${file.name}:\n`; - } - for (let item of result.items) { - if ( - item.type !== - Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE - ) { - continue; - } - resultsContainer.innerText += item.text + "\n"; - console.log(item.text); + if (files.length > 1) { + resultsContainer.innerText += `\n${file.name}:\n`; + } + for (let item of result.items) { + if (item.type !== Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE) { + continue; } - if (!result.items.length) - resultsContainer.innerText += "No barcode found\n"; + resultsContainer.innerText += item.text + "\n"; + console.log(item.text); } - } catch (ex) { - let errMsg = ex.message || ex; - console.error(errMsg); - alert(errMsg); + if (!result.items.length) resultsContainer.innerText += "No barcode found\n"; } - }); + } catch (ex) { + let errMsg = ex.message || ex; + console.error(errMsg); + alert(errMsg); + } + }); diff --git a/hello-world/requirejs.html b/hello-world/requirejs.html index 56c8882f..573aabed 100644 --- a/hello-world/requirejs.html +++ b/hello-world/requirejs.html @@ -3,19 +3,10 @@ - + - - - Dynamsoft Barcode Reader Sample - Hello World for RequireJS (Decode via - Camera) - + + Dynamsoft Barcode Reader Sample - Hello World for RequireJS (Decode via Camera) @@ -27,9 +18,7 @@

Hello World for RequireJS (Decode via Camera)