html5-qrcode
Advanced tools
Comparing version 2.3.3 to 2.3.4
export declare class CameraPermissions { | ||
static hasPermissions(): Promise<boolean>; | ||
private static verifyViaPermissionsQuery; | ||
} |
export declare class CameraPermissions { | ||
static hasPermissions(): Promise<boolean>; | ||
private static verifyViaPermissionsQuery; | ||
} |
@@ -48,11 +48,5 @@ "use strict"; | ||
switch (_a.label) { | ||
case 0: return [4, CameraPermissions.verifyViaPermissionsQuery()]; | ||
case 0: return [4, navigator.mediaDevices.enumerateDevices()]; | ||
case 1: | ||
if (_a.sent()) { | ||
return [2, true]; | ||
} | ||
return [4, navigator.mediaDevices.enumerateDevices()]; | ||
case 2: | ||
devices = _a.sent(); | ||
console.log("devices", devices); | ||
for (_i = 0, devices_1 = devices; _i < devices_1.length; _i++) { | ||
@@ -69,25 +63,2 @@ device = devices_1[_i]; | ||
}; | ||
CameraPermissions.verifyViaPermissionsQuery = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var permissionDescriptor, result, _1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!navigator.permissions) return [3, 4]; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
permissionDescriptor = { name: "camera" }; | ||
return [4, navigator.permissions.query(permissionDescriptor)]; | ||
case 2: | ||
result = _a.sent(); | ||
return [2, result.state === "granted"]; | ||
case 3: | ||
_1 = _a.sent(); | ||
return [2, false]; | ||
case 4: return [2, false]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return CameraPermissions; | ||
@@ -94,0 +65,0 @@ }()); |
@@ -1,11 +0,16 @@ | ||
import { QrcodeResult, Html5QrcodeSupportedFormats, Logger, QrcodeDecoderAsync } from "./core"; | ||
export declare class Html5QrcodeShim implements QrcodeDecoderAsync { | ||
import { QrcodeResult, Html5QrcodeSupportedFormats, Logger, RobustQrcodeDecoderAsync } from "./core"; | ||
export declare class Html5QrcodeShim implements RobustQrcodeDecoderAsync { | ||
private verbose; | ||
private decoder; | ||
private primaryDecoder; | ||
private secondaryDecoder; | ||
private readonly EXECUTIONS_TO_REPORT_PERFORMANCE; | ||
private executions; | ||
private executionResults; | ||
private wasPrimaryDecoderUsedInLastDecode; | ||
constructor(requestedFormats: Array<Html5QrcodeSupportedFormats>, useBarCodeDetectorIfSupported: boolean, verbose: boolean, logger: Logger); | ||
decodeAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
decodeRobustlyAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
private getDecoder; | ||
private possiblyLogPerformance; | ||
possiblyFlushPerformanceReport(): void; | ||
} |
@@ -47,9 +47,11 @@ "use strict"; | ||
this.executionResults = []; | ||
this.wasPrimaryDecoderUsedInLastDecode = false; | ||
this.verbose = verbose; | ||
if (useBarCodeDetectorIfSupported | ||
&& native_bar_code_detector_1.BarcodeDetectorDelegate.isSupported()) { | ||
this.decoder = new native_bar_code_detector_1.BarcodeDetectorDelegate(requestedFormats, verbose, logger); | ||
this.primaryDecoder = new native_bar_code_detector_1.BarcodeDetectorDelegate(requestedFormats, verbose, logger); | ||
this.secondaryDecoder = new zxing_html5_qrcode_decoder_1.ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
} | ||
else { | ||
this.decoder = new zxing_html5_qrcode_decoder_1.ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
this.primaryDecoder = new zxing_html5_qrcode_decoder_1.ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
} | ||
@@ -59,19 +61,14 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var start, executionTime; | ||
var startTime; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
start = performance.now(); | ||
startTime = performance.now(); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, , 3, 4]); | ||
return [4, this.decoder.decodeAsync(canvas)]; | ||
return [4, this.getDecoder().decodeAsync(canvas)]; | ||
case 2: return [2, _a.sent()]; | ||
case 3: | ||
if (this.verbose) { | ||
executionTime = performance.now() - start; | ||
this.executionResults.push(executionTime); | ||
this.executions++; | ||
this.possiblyFlushPerformanceReport(); | ||
} | ||
this.possiblyLogPerformance(startTime); | ||
return [7]; | ||
@@ -83,2 +80,48 @@ case 4: return [2]; | ||
}; | ||
Html5QrcodeShim.prototype.decodeRobustlyAsync = function (canvas) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var startTime, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
startTime = performance.now(); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, 4, 5]); | ||
return [4, this.primaryDecoder.decodeAsync(canvas)]; | ||
case 2: return [2, _a.sent()]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
if (this.secondaryDecoder) { | ||
return [2, this.secondaryDecoder.decodeAsync(canvas)]; | ||
} | ||
throw error_1; | ||
case 4: | ||
this.possiblyLogPerformance(startTime); | ||
return [7]; | ||
case 5: return [2]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Html5QrcodeShim.prototype.getDecoder = function () { | ||
if (!this.secondaryDecoder) { | ||
return this.primaryDecoder; | ||
} | ||
if (this.wasPrimaryDecoderUsedInLastDecode === false) { | ||
this.wasPrimaryDecoderUsedInLastDecode = true; | ||
return this.primaryDecoder; | ||
} | ||
this.wasPrimaryDecoderUsedInLastDecode = false; | ||
return this.secondaryDecoder; | ||
}; | ||
Html5QrcodeShim.prototype.possiblyLogPerformance = function (startTime) { | ||
if (!this.verbose) { | ||
return; | ||
} | ||
var executionTime = performance.now() - startTime; | ||
this.executionResults.push(executionTime); | ||
this.executions++; | ||
this.possiblyFlushPerformanceReport(); | ||
}; | ||
Html5QrcodeShim.prototype.possiblyFlushPerformanceReport = function () { | ||
@@ -85,0 +128,0 @@ if (this.executions < this.EXECUTIONS_TO_REPORT_PERFORMANCE) { |
@@ -87,2 +87,5 @@ export declare enum Html5QrcodeSupportedFormats { | ||
} | ||
export interface RobustQrcodeDecoderAsync extends QrcodeDecoderAsync { | ||
decodeRobustlyAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
} | ||
export interface Logger { | ||
@@ -89,0 +92,0 @@ log(message: string): void; |
@@ -242,2 +242,3 @@ "use strict"; | ||
var $this = this; | ||
$this.showHideScanTypeSwapLink(false); | ||
$this.setHeaderMessage(strings_1.Html5QrcodeScannerStrings.cameraPermissionRequesting()); | ||
@@ -251,2 +252,3 @@ var createPermissionButtonIfNotExists = function () { | ||
$this.persistedDataManager.setHasPermission(true); | ||
$this.showHideScanTypeSwapLink(true); | ||
$this.resetHeaderMessage(); | ||
@@ -270,2 +272,3 @@ if (cameras && cameras.length > 0) { | ||
$this.setHeaderMessage(error, Html5QrcodeScannerStatus.STATUS_WARNING); | ||
$this.showHideScanTypeSwapLink(true); | ||
}); | ||
@@ -334,2 +337,3 @@ }; | ||
} | ||
$this.setHeaderMessage(strings_1.Html5QrcodeScannerStrings.loadingImage()); | ||
$this.html5Qrcode.scanFileV2(file, true) | ||
@@ -394,2 +398,5 @@ .then(function (html5qrcodeResult) { | ||
} | ||
else { | ||
torchButton.updateTorchCapability(cameraCapabilities.torchFeature()); | ||
} | ||
torchButton.show(); | ||
@@ -396,0 +403,0 @@ }; |
@@ -34,2 +34,3 @@ "use strict"; | ||
Constants.FILE_SCAN_MIN_HEIGHT = 300; | ||
Constants.FILE_SCAN_HIDDEN_CANVAS_PADDING = 100; | ||
Constants.MIN_QR_BOX_SIZE = 50; | ||
@@ -308,3 +309,8 @@ Constants.SHADED_LEFT = 1; | ||
} | ||
var hiddenCanvas = _this.createCanvasElement(config.width, config.height); | ||
var padding = Constants.FILE_SCAN_HIDDEN_CANVAS_PADDING; | ||
var hiddenImageWidth = Math.max(inputImage.width, config.width); | ||
var hiddenImageHeight = Math.max(inputImage.height, config.height); | ||
var hiddenCanvasWidth = hiddenImageWidth + 2 * padding; | ||
var hiddenCanvasHeight = hiddenImageHeight + 2 * padding; | ||
var hiddenCanvas = _this.createCanvasElement(hiddenCanvasWidth, hiddenCanvasHeight); | ||
element.appendChild(hiddenCanvas); | ||
@@ -315,7 +321,7 @@ var context = hiddenCanvas.getContext("2d"); | ||
} | ||
context.canvas.width = config.width; | ||
context.canvas.height = config.height; | ||
context.drawImage(inputImage, 0, 0, imageWidth, imageHeight, 0, 0, config.width, config.height); | ||
context.canvas.width = hiddenCanvasWidth; | ||
context.canvas.height = hiddenCanvasHeight; | ||
context.drawImage(inputImage, 0, 0, imageWidth, imageHeight, padding, padding, hiddenImageWidth, hiddenImageHeight); | ||
try { | ||
_this.qrcode.decodeAsync(hiddenCanvas) | ||
_this.qrcode.decodeRobustlyAsync(hiddenCanvas) | ||
.then(function (result) { | ||
@@ -419,15 +425,15 @@ resolve(core_1.Html5QrcodeResultFactory.createFromQrcodeResult(result)); | ||
if (core_1.isNullOrUndefined(config)) { | ||
return false; | ||
return true; | ||
} | ||
if (!core_1.isNullOrUndefined(config.useBarCodeDetectorIfSupported)) { | ||
return config.useBarCodeDetectorIfSupported === true; | ||
return config.useBarCodeDetectorIfSupported !== false; | ||
} | ||
if (core_1.isNullOrUndefined(config.experimentalFeatures)) { | ||
return false; | ||
return true; | ||
} | ||
var experimentalFeatures = config.experimentalFeatures; | ||
if (core_1.isNullOrUndefined(experimentalFeatures.useBarCodeDetectorIfSupported)) { | ||
return false; | ||
return true; | ||
} | ||
return experimentalFeatures.useBarCodeDetectorIfSupported === true; | ||
return experimentalFeatures.useBarCodeDetectorIfSupported !== false; | ||
}; | ||
@@ -434,0 +440,0 @@ Html5Qrcode.prototype.validateQrboxSize = function (viewfinderWidth, viewfinderHeight, internalConfig) { |
@@ -37,2 +37,3 @@ export declare class Html5QrcodeStrings { | ||
static zoom(): string; | ||
static loadingImage(): string; | ||
} | ||
@@ -39,0 +40,0 @@ export declare class LibraryInfoStrings { |
@@ -115,2 +115,5 @@ "use strict"; | ||
}; | ||
Html5QrcodeScannerStrings.loadingImage = function () { | ||
return "Loading image..."; | ||
}; | ||
return Html5QrcodeScannerStrings; | ||
@@ -117,0 +120,0 @@ }()); |
@@ -14,5 +14,7 @@ import { BooleanCameraCapability } from "../../camera/core"; | ||
private readonly torchButton; | ||
private readonly torchController; | ||
private readonly onTorchActionFailureCallback; | ||
private torchController; | ||
private constructor(); | ||
private render; | ||
updateTorchCapability(torchCapability: BooleanCameraCapability): void; | ||
getTorchButton(): HTMLButtonElement; | ||
@@ -19,0 +21,0 @@ hide(): void; |
@@ -106,2 +106,3 @@ "use strict"; | ||
function TorchButton(torchCapability, onTorchActionFailureCallback) { | ||
this.onTorchActionFailureCallback = onTorchActionFailureCallback; | ||
this.torchButton | ||
@@ -138,2 +139,5 @@ = base_1.BaseUiElementFactory.createElement("button", base_1.PublicUiElementIdAndClasses.TORCH_BUTTON_ID); | ||
}; | ||
TorchButton.prototype.updateTorchCapability = function (torchCapability) { | ||
this.torchController = new TorchController(torchCapability, this, this.onTorchActionFailureCallback); | ||
}; | ||
TorchButton.prototype.getTorchButton = function () { | ||
@@ -140,0 +144,0 @@ return this.torchButton; |
@@ -1,11 +0,16 @@ | ||
import { QrcodeResult, Html5QrcodeSupportedFormats, Logger, QrcodeDecoderAsync } from "./core"; | ||
export declare class Html5QrcodeShim implements QrcodeDecoderAsync { | ||
import { QrcodeResult, Html5QrcodeSupportedFormats, Logger, RobustQrcodeDecoderAsync } from "./core"; | ||
export declare class Html5QrcodeShim implements RobustQrcodeDecoderAsync { | ||
private verbose; | ||
private decoder; | ||
private primaryDecoder; | ||
private secondaryDecoder; | ||
private readonly EXECUTIONS_TO_REPORT_PERFORMANCE; | ||
private executions; | ||
private executionResults; | ||
private wasPrimaryDecoderUsedInLastDecode; | ||
constructor(requestedFormats: Array<Html5QrcodeSupportedFormats>, useBarCodeDetectorIfSupported: boolean, verbose: boolean, logger: Logger); | ||
decodeAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
decodeRobustlyAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
private getDecoder; | ||
private possiblyLogPerformance; | ||
possiblyFlushPerformanceReport(): void; | ||
} |
@@ -87,2 +87,5 @@ export declare enum Html5QrcodeSupportedFormats { | ||
} | ||
export interface RobustQrcodeDecoderAsync extends QrcodeDecoderAsync { | ||
decodeRobustlyAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
} | ||
export interface Logger { | ||
@@ -89,0 +92,0 @@ log(message: string): void; |
export declare class CameraPermissions { | ||
static hasPermissions(): Promise<boolean>; | ||
private static verifyViaPermissionsQuery; | ||
} |
@@ -13,7 +13,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (yield CameraPermissions.verifyViaPermissionsQuery()) { | ||
return true; | ||
} | ||
let devices = yield navigator.mediaDevices.enumerateDevices(); | ||
console.log("devices", devices); | ||
for (const device of devices) { | ||
@@ -27,18 +23,3 @@ if (device.kind === "videoinput" && device.label) { | ||
} | ||
static verifyViaPermissionsQuery() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (navigator.permissions) { | ||
try { | ||
let permissionDescriptor = { name: "camera" }; | ||
let result = yield navigator.permissions.query(permissionDescriptor); | ||
return result.state === "granted"; | ||
} | ||
catch (_) { | ||
return false; | ||
} | ||
} | ||
return false; | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=permissions.js.map |
@@ -1,11 +0,16 @@ | ||
import { QrcodeResult, Html5QrcodeSupportedFormats, Logger, QrcodeDecoderAsync } from "./core"; | ||
export declare class Html5QrcodeShim implements QrcodeDecoderAsync { | ||
import { QrcodeResult, Html5QrcodeSupportedFormats, Logger, RobustQrcodeDecoderAsync } from "./core"; | ||
export declare class Html5QrcodeShim implements RobustQrcodeDecoderAsync { | ||
private verbose; | ||
private decoder; | ||
private primaryDecoder; | ||
private secondaryDecoder; | ||
private readonly EXECUTIONS_TO_REPORT_PERFORMANCE; | ||
private executions; | ||
private executionResults; | ||
private wasPrimaryDecoderUsedInLastDecode; | ||
constructor(requestedFormats: Array<Html5QrcodeSupportedFormats>, useBarCodeDetectorIfSupported: boolean, verbose: boolean, logger: Logger); | ||
decodeAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
decodeRobustlyAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
private getDecoder; | ||
private possiblyLogPerformance; | ||
possiblyFlushPerformanceReport(): void; | ||
} |
@@ -17,9 +17,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
this.executionResults = []; | ||
this.wasPrimaryDecoderUsedInLastDecode = false; | ||
this.verbose = verbose; | ||
if (useBarCodeDetectorIfSupported | ||
&& BarcodeDetectorDelegate.isSupported()) { | ||
this.decoder = new BarcodeDetectorDelegate(requestedFormats, verbose, logger); | ||
this.primaryDecoder = new BarcodeDetectorDelegate(requestedFormats, verbose, logger); | ||
this.secondaryDecoder = new ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
} | ||
else { | ||
this.decoder = new ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
this.primaryDecoder = new ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
} | ||
@@ -29,16 +31,48 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let start = performance.now(); | ||
let startTime = performance.now(); | ||
try { | ||
return yield this.decoder.decodeAsync(canvas); | ||
return yield this.getDecoder().decodeAsync(canvas); | ||
} | ||
finally { | ||
if (this.verbose) { | ||
let executionTime = performance.now() - start; | ||
this.executionResults.push(executionTime); | ||
this.executions++; | ||
this.possiblyFlushPerformanceReport(); | ||
this.possiblyLogPerformance(startTime); | ||
} | ||
}); | ||
} | ||
decodeRobustlyAsync(canvas) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let startTime = performance.now(); | ||
try { | ||
return yield this.primaryDecoder.decodeAsync(canvas); | ||
} | ||
catch (error) { | ||
if (this.secondaryDecoder) { | ||
return this.secondaryDecoder.decodeAsync(canvas); | ||
} | ||
throw error; | ||
} | ||
finally { | ||
this.possiblyLogPerformance(startTime); | ||
} | ||
}); | ||
} | ||
getDecoder() { | ||
if (!this.secondaryDecoder) { | ||
return this.primaryDecoder; | ||
} | ||
if (this.wasPrimaryDecoderUsedInLastDecode === false) { | ||
this.wasPrimaryDecoderUsedInLastDecode = true; | ||
return this.primaryDecoder; | ||
} | ||
this.wasPrimaryDecoderUsedInLastDecode = false; | ||
return this.secondaryDecoder; | ||
} | ||
possiblyLogPerformance(startTime) { | ||
if (!this.verbose) { | ||
return; | ||
} | ||
let executionTime = performance.now() - startTime; | ||
this.executionResults.push(executionTime); | ||
this.executions++; | ||
this.possiblyFlushPerformanceReport(); | ||
} | ||
possiblyFlushPerformanceReport() { | ||
@@ -45,0 +79,0 @@ if (this.executions < this.EXECUTIONS_TO_REPORT_PERFORMANCE) { |
@@ -87,2 +87,5 @@ export declare enum Html5QrcodeSupportedFormats { | ||
} | ||
export interface RobustQrcodeDecoderAsync extends QrcodeDecoderAsync { | ||
decodeRobustlyAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
} | ||
export interface Logger { | ||
@@ -89,0 +92,0 @@ log(message: string): void; |
@@ -237,2 +237,3 @@ import { Html5QrcodeConstants, Html5QrcodeScanType, Html5QrcodeErrorFactory, BaseLoggger, isNullOrUndefined, clip, } from "./core"; | ||
const $this = this; | ||
$this.showHideScanTypeSwapLink(false); | ||
$this.setHeaderMessage(Html5QrcodeScannerStrings.cameraPermissionRequesting()); | ||
@@ -246,2 +247,3 @@ const createPermissionButtonIfNotExists = () => { | ||
$this.persistedDataManager.setHasPermission(true); | ||
$this.showHideScanTypeSwapLink(true); | ||
$this.resetHeaderMessage(); | ||
@@ -265,2 +267,3 @@ if (cameras && cameras.length > 0) { | ||
$this.setHeaderMessage(error, Html5QrcodeScannerStatus.STATUS_WARNING); | ||
$this.showHideScanTypeSwapLink(true); | ||
}); | ||
@@ -329,2 +332,3 @@ } | ||
} | ||
$this.setHeaderMessage(Html5QrcodeScannerStrings.loadingImage()); | ||
$this.html5Qrcode.scanFileV2(file, true) | ||
@@ -388,2 +392,5 @@ .then((html5qrcodeResult) => { | ||
} | ||
else { | ||
torchButton.updateTorchCapability(cameraCapabilities.torchFeature()); | ||
} | ||
torchButton.show(); | ||
@@ -390,0 +397,0 @@ }; |
@@ -13,2 +13,3 @@ import { BaseLoggger, Html5QrcodeResultFactory, Html5QrcodeErrorFactory, Html5QrcodeSupportedFormats, isValidHtml5QrcodeSupportedFormats, Html5QrcodeConstants, isNullOrUndefined } from "./core"; | ||
Constants.FILE_SCAN_MIN_HEIGHT = 300; | ||
Constants.FILE_SCAN_HIDDEN_CANVAS_PADDING = 100; | ||
Constants.MIN_QR_BOX_SIZE = 50; | ||
@@ -281,3 +282,8 @@ Constants.SHADED_LEFT = 1; | ||
} | ||
const hiddenCanvas = this.createCanvasElement(config.width, config.height); | ||
let padding = Constants.FILE_SCAN_HIDDEN_CANVAS_PADDING; | ||
let hiddenImageWidth = Math.max(inputImage.width, config.width); | ||
let hiddenImageHeight = Math.max(inputImage.height, config.height); | ||
let hiddenCanvasWidth = hiddenImageWidth + 2 * padding; | ||
let hiddenCanvasHeight = hiddenImageHeight + 2 * padding; | ||
const hiddenCanvas = this.createCanvasElement(hiddenCanvasWidth, hiddenCanvasHeight); | ||
element.appendChild(hiddenCanvas); | ||
@@ -288,7 +294,7 @@ const context = hiddenCanvas.getContext("2d"); | ||
} | ||
context.canvas.width = config.width; | ||
context.canvas.height = config.height; | ||
context.drawImage(inputImage, 0, 0, imageWidth, imageHeight, 0, 0, config.width, config.height); | ||
context.canvas.width = hiddenCanvasWidth; | ||
context.canvas.height = hiddenCanvasHeight; | ||
context.drawImage(inputImage, 0, 0, imageWidth, imageHeight, padding, padding, hiddenImageWidth, hiddenImageHeight); | ||
try { | ||
this.qrcode.decodeAsync(hiddenCanvas) | ||
this.qrcode.decodeRobustlyAsync(hiddenCanvas) | ||
.then((result) => { | ||
@@ -391,15 +397,15 @@ resolve(Html5QrcodeResultFactory.createFromQrcodeResult(result)); | ||
if (isNullOrUndefined(config)) { | ||
return false; | ||
return true; | ||
} | ||
if (!isNullOrUndefined(config.useBarCodeDetectorIfSupported)) { | ||
return config.useBarCodeDetectorIfSupported === true; | ||
return config.useBarCodeDetectorIfSupported !== false; | ||
} | ||
if (isNullOrUndefined(config.experimentalFeatures)) { | ||
return false; | ||
return true; | ||
} | ||
let experimentalFeatures = config.experimentalFeatures; | ||
if (isNullOrUndefined(experimentalFeatures.useBarCodeDetectorIfSupported)) { | ||
return false; | ||
return true; | ||
} | ||
return experimentalFeatures.useBarCodeDetectorIfSupported === true; | ||
return experimentalFeatures.useBarCodeDetectorIfSupported !== false; | ||
} | ||
@@ -406,0 +412,0 @@ validateQrboxSize(viewfinderWidth, viewfinderHeight, internalConfig) { |
@@ -37,2 +37,3 @@ export declare class Html5QrcodeStrings { | ||
static zoom(): string; | ||
static loadingImage(): string; | ||
} | ||
@@ -39,0 +40,0 @@ export declare class LibraryInfoStrings { |
@@ -106,2 +106,5 @@ export class Html5QrcodeStrings { | ||
} | ||
static loadingImage() { | ||
return "Loading image..."; | ||
} | ||
} | ||
@@ -108,0 +111,0 @@ export class LibraryInfoStrings { |
@@ -14,5 +14,7 @@ import { BooleanCameraCapability } from "../../camera/core"; | ||
private readonly torchButton; | ||
private readonly torchController; | ||
private readonly onTorchActionFailureCallback; | ||
private torchController; | ||
private constructor(); | ||
private render; | ||
updateTorchCapability(torchCapability: BooleanCameraCapability): void; | ||
getTorchButton(): HTMLButtonElement; | ||
@@ -19,0 +21,0 @@ hide(): void; |
@@ -63,2 +63,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
constructor(torchCapability, onTorchActionFailureCallback) { | ||
this.onTorchActionFailureCallback = onTorchActionFailureCallback; | ||
this.torchButton | ||
@@ -87,2 +88,5 @@ = BaseUiElementFactory.createElement("button", PublicUiElementIdAndClasses.TORCH_BUTTON_ID); | ||
} | ||
updateTorchCapability(torchCapability) { | ||
this.torchController = new TorchController(torchCapability, this, this.onTorchActionFailureCallback); | ||
} | ||
getTorchButton() { | ||
@@ -89,0 +93,0 @@ return this.torchButton; |
export declare class CameraPermissions { | ||
static hasPermissions(): Promise<boolean>; | ||
private static verifyViaPermissionsQuery; | ||
} |
@@ -45,11 +45,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
switch (_a.label) { | ||
case 0: return [4, CameraPermissions.verifyViaPermissionsQuery()]; | ||
case 0: return [4, navigator.mediaDevices.enumerateDevices()]; | ||
case 1: | ||
if (_a.sent()) { | ||
return [2, true]; | ||
} | ||
return [4, navigator.mediaDevices.enumerateDevices()]; | ||
case 2: | ||
devices = _a.sent(); | ||
console.log("devices", devices); | ||
for (_i = 0, devices_1 = devices; _i < devices_1.length; _i++) { | ||
@@ -66,25 +60,2 @@ device = devices_1[_i]; | ||
}; | ||
CameraPermissions.verifyViaPermissionsQuery = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var permissionDescriptor, result, _1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!navigator.permissions) return [3, 4]; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
permissionDescriptor = { name: "camera" }; | ||
return [4, navigator.permissions.query(permissionDescriptor)]; | ||
case 2: | ||
result = _a.sent(); | ||
return [2, result.state === "granted"]; | ||
case 3: | ||
_1 = _a.sent(); | ||
return [2, false]; | ||
case 4: return [2, false]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return CameraPermissions; | ||
@@ -91,0 +62,0 @@ }()); |
@@ -1,11 +0,16 @@ | ||
import { QrcodeResult, Html5QrcodeSupportedFormats, Logger, QrcodeDecoderAsync } from "./core"; | ||
export declare class Html5QrcodeShim implements QrcodeDecoderAsync { | ||
import { QrcodeResult, Html5QrcodeSupportedFormats, Logger, RobustQrcodeDecoderAsync } from "./core"; | ||
export declare class Html5QrcodeShim implements RobustQrcodeDecoderAsync { | ||
private verbose; | ||
private decoder; | ||
private primaryDecoder; | ||
private secondaryDecoder; | ||
private readonly EXECUTIONS_TO_REPORT_PERFORMANCE; | ||
private executions; | ||
private executionResults; | ||
private wasPrimaryDecoderUsedInLastDecode; | ||
constructor(requestedFormats: Array<Html5QrcodeSupportedFormats>, useBarCodeDetectorIfSupported: boolean, verbose: boolean, logger: Logger); | ||
decodeAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
decodeRobustlyAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
private getDecoder; | ||
private possiblyLogPerformance; | ||
possiblyFlushPerformanceReport(): void; | ||
} |
@@ -44,9 +44,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
this.executionResults = []; | ||
this.wasPrimaryDecoderUsedInLastDecode = false; | ||
this.verbose = verbose; | ||
if (useBarCodeDetectorIfSupported | ||
&& BarcodeDetectorDelegate.isSupported()) { | ||
this.decoder = new BarcodeDetectorDelegate(requestedFormats, verbose, logger); | ||
this.primaryDecoder = new BarcodeDetectorDelegate(requestedFormats, verbose, logger); | ||
this.secondaryDecoder = new ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
} | ||
else { | ||
this.decoder = new ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
this.primaryDecoder = new ZXingHtml5QrcodeDecoder(requestedFormats, verbose, logger); | ||
} | ||
@@ -56,19 +58,14 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var start, executionTime; | ||
var startTime; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
start = performance.now(); | ||
startTime = performance.now(); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, , 3, 4]); | ||
return [4, this.decoder.decodeAsync(canvas)]; | ||
return [4, this.getDecoder().decodeAsync(canvas)]; | ||
case 2: return [2, _a.sent()]; | ||
case 3: | ||
if (this.verbose) { | ||
executionTime = performance.now() - start; | ||
this.executionResults.push(executionTime); | ||
this.executions++; | ||
this.possiblyFlushPerformanceReport(); | ||
} | ||
this.possiblyLogPerformance(startTime); | ||
return [7]; | ||
@@ -80,2 +77,48 @@ case 4: return [2]; | ||
}; | ||
Html5QrcodeShim.prototype.decodeRobustlyAsync = function (canvas) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var startTime, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
startTime = performance.now(); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, 4, 5]); | ||
return [4, this.primaryDecoder.decodeAsync(canvas)]; | ||
case 2: return [2, _a.sent()]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
if (this.secondaryDecoder) { | ||
return [2, this.secondaryDecoder.decodeAsync(canvas)]; | ||
} | ||
throw error_1; | ||
case 4: | ||
this.possiblyLogPerformance(startTime); | ||
return [7]; | ||
case 5: return [2]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Html5QrcodeShim.prototype.getDecoder = function () { | ||
if (!this.secondaryDecoder) { | ||
return this.primaryDecoder; | ||
} | ||
if (this.wasPrimaryDecoderUsedInLastDecode === false) { | ||
this.wasPrimaryDecoderUsedInLastDecode = true; | ||
return this.primaryDecoder; | ||
} | ||
this.wasPrimaryDecoderUsedInLastDecode = false; | ||
return this.secondaryDecoder; | ||
}; | ||
Html5QrcodeShim.prototype.possiblyLogPerformance = function (startTime) { | ||
if (!this.verbose) { | ||
return; | ||
} | ||
var executionTime = performance.now() - startTime; | ||
this.executionResults.push(executionTime); | ||
this.executions++; | ||
this.possiblyFlushPerformanceReport(); | ||
}; | ||
Html5QrcodeShim.prototype.possiblyFlushPerformanceReport = function () { | ||
@@ -82,0 +125,0 @@ if (this.executions < this.EXECUTIONS_TO_REPORT_PERFORMANCE) { |
@@ -87,2 +87,5 @@ export declare enum Html5QrcodeSupportedFormats { | ||
} | ||
export interface RobustQrcodeDecoderAsync extends QrcodeDecoderAsync { | ||
decodeRobustlyAsync(canvas: HTMLCanvasElement): Promise<QrcodeResult>; | ||
} | ||
export interface Logger { | ||
@@ -89,0 +92,0 @@ log(message: string): void; |
@@ -239,2 +239,3 @@ import { Html5QrcodeConstants, Html5QrcodeScanType, Html5QrcodeErrorFactory, BaseLoggger, isNullOrUndefined, clip, } from "./core"; | ||
var $this = this; | ||
$this.showHideScanTypeSwapLink(false); | ||
$this.setHeaderMessage(Html5QrcodeScannerStrings.cameraPermissionRequesting()); | ||
@@ -248,2 +249,3 @@ var createPermissionButtonIfNotExists = function () { | ||
$this.persistedDataManager.setHasPermission(true); | ||
$this.showHideScanTypeSwapLink(true); | ||
$this.resetHeaderMessage(); | ||
@@ -267,2 +269,3 @@ if (cameras && cameras.length > 0) { | ||
$this.setHeaderMessage(error, Html5QrcodeScannerStatus.STATUS_WARNING); | ||
$this.showHideScanTypeSwapLink(true); | ||
}); | ||
@@ -331,2 +334,3 @@ }; | ||
} | ||
$this.setHeaderMessage(Html5QrcodeScannerStrings.loadingImage()); | ||
$this.html5Qrcode.scanFileV2(file, true) | ||
@@ -391,2 +395,5 @@ .then(function (html5qrcodeResult) { | ||
} | ||
else { | ||
torchButton.updateTorchCapability(cameraCapabilities.torchFeature()); | ||
} | ||
torchButton.show(); | ||
@@ -393,0 +400,0 @@ }; |
@@ -31,2 +31,3 @@ var __extends = (this && this.__extends) || (function () { | ||
Constants.FILE_SCAN_MIN_HEIGHT = 300; | ||
Constants.FILE_SCAN_HIDDEN_CANVAS_PADDING = 100; | ||
Constants.MIN_QR_BOX_SIZE = 50; | ||
@@ -305,3 +306,8 @@ Constants.SHADED_LEFT = 1; | ||
} | ||
var hiddenCanvas = _this.createCanvasElement(config.width, config.height); | ||
var padding = Constants.FILE_SCAN_HIDDEN_CANVAS_PADDING; | ||
var hiddenImageWidth = Math.max(inputImage.width, config.width); | ||
var hiddenImageHeight = Math.max(inputImage.height, config.height); | ||
var hiddenCanvasWidth = hiddenImageWidth + 2 * padding; | ||
var hiddenCanvasHeight = hiddenImageHeight + 2 * padding; | ||
var hiddenCanvas = _this.createCanvasElement(hiddenCanvasWidth, hiddenCanvasHeight); | ||
element.appendChild(hiddenCanvas); | ||
@@ -312,7 +318,7 @@ var context = hiddenCanvas.getContext("2d"); | ||
} | ||
context.canvas.width = config.width; | ||
context.canvas.height = config.height; | ||
context.drawImage(inputImage, 0, 0, imageWidth, imageHeight, 0, 0, config.width, config.height); | ||
context.canvas.width = hiddenCanvasWidth; | ||
context.canvas.height = hiddenCanvasHeight; | ||
context.drawImage(inputImage, 0, 0, imageWidth, imageHeight, padding, padding, hiddenImageWidth, hiddenImageHeight); | ||
try { | ||
_this.qrcode.decodeAsync(hiddenCanvas) | ||
_this.qrcode.decodeRobustlyAsync(hiddenCanvas) | ||
.then(function (result) { | ||
@@ -416,15 +422,15 @@ resolve(Html5QrcodeResultFactory.createFromQrcodeResult(result)); | ||
if (isNullOrUndefined(config)) { | ||
return false; | ||
return true; | ||
} | ||
if (!isNullOrUndefined(config.useBarCodeDetectorIfSupported)) { | ||
return config.useBarCodeDetectorIfSupported === true; | ||
return config.useBarCodeDetectorIfSupported !== false; | ||
} | ||
if (isNullOrUndefined(config.experimentalFeatures)) { | ||
return false; | ||
return true; | ||
} | ||
var experimentalFeatures = config.experimentalFeatures; | ||
if (isNullOrUndefined(experimentalFeatures.useBarCodeDetectorIfSupported)) { | ||
return false; | ||
return true; | ||
} | ||
return experimentalFeatures.useBarCodeDetectorIfSupported === true; | ||
return experimentalFeatures.useBarCodeDetectorIfSupported !== false; | ||
}; | ||
@@ -431,0 +437,0 @@ Html5Qrcode.prototype.validateQrboxSize = function (viewfinderWidth, viewfinderHeight, internalConfig) { |
@@ -37,2 +37,3 @@ export declare class Html5QrcodeStrings { | ||
static zoom(): string; | ||
static loadingImage(): string; | ||
} | ||
@@ -39,0 +40,0 @@ export declare class LibraryInfoStrings { |
@@ -112,2 +112,5 @@ var Html5QrcodeStrings = (function () { | ||
}; | ||
Html5QrcodeScannerStrings.loadingImage = function () { | ||
return "Loading image..."; | ||
}; | ||
return Html5QrcodeScannerStrings; | ||
@@ -114,0 +117,0 @@ }()); |
@@ -14,5 +14,7 @@ import { BooleanCameraCapability } from "../../camera/core"; | ||
private readonly torchButton; | ||
private readonly torchController; | ||
private readonly onTorchActionFailureCallback; | ||
private torchController; | ||
private constructor(); | ||
private render; | ||
updateTorchCapability(torchCapability: BooleanCameraCapability): void; | ||
getTorchButton(): HTMLButtonElement; | ||
@@ -19,0 +21,0 @@ hide(): void; |
@@ -103,2 +103,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function TorchButton(torchCapability, onTorchActionFailureCallback) { | ||
this.onTorchActionFailureCallback = onTorchActionFailureCallback; | ||
this.torchButton | ||
@@ -135,2 +136,5 @@ = BaseUiElementFactory.createElement("button", PublicUiElementIdAndClasses.TORCH_BUTTON_ID); | ||
}; | ||
TorchButton.prototype.updateTorchCapability = function (torchCapability) { | ||
this.torchController = new TorchController(torchCapability, this, this.onTorchActionFailureCallback); | ||
}; | ||
TorchButton.prototype.getTorchButton = function () { | ||
@@ -137,0 +141,0 @@ return this.torchButton; |
{ | ||
"name": "html5-qrcode", | ||
"version": "2.3.3", | ||
"version": "2.3.4", | ||
"description": "A cross platform HTML5 QR Code & bar code scanner", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
@@ -448,3 +448,3 @@ # Html5-QRCode | ||
* Set this flag to true, to enable using {@class BarcodeDetector} if | ||
* supported. This is false by default. | ||
* supported. This is true by default. | ||
* | ||
@@ -451,0 +451,0 @@ * Documentations: |
@@ -37,2 +37,3 @@ export declare class Html5QrcodeStrings { | ||
static zoom(): string; | ||
static loadingImage(): string; | ||
} | ||
@@ -39,0 +40,0 @@ export declare class LibraryInfoStrings { |
@@ -14,5 +14,7 @@ import { BooleanCameraCapability } from "../../camera/core"; | ||
private readonly torchButton; | ||
private readonly torchController; | ||
private readonly onTorchActionFailureCallback; | ||
private torchController; | ||
private constructor(); | ||
private render; | ||
updateTorchCapability(torchCapability: BooleanCameraCapability): void; | ||
getTorchButton(): HTMLButtonElement; | ||
@@ -19,0 +21,0 @@ hide(): void; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2413199
36547