Skip to content

Commit

Permalink
Version 2.1.5
Browse files Browse the repository at this point in the history
### Changelog

 - Changed behavior from throwing error in case `qrbox.width` or `qrbox` is larger
    than the width of the root element. In such cases the dimension will automatically
    be truncated to the size of root element and will throw a warning based on verbosity
    settings. This should address [issue#357](#357)
  • Loading branch information
mebjas committed Dec 20, 2021
1 parent fe2cc33 commit 4616fca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Version 2.1.5

- Changed behavior from throwing error in case `qrbox.width` or `qrbox` is larger
than the width of the root element. In such cases the dimension will automatically
be truncated to the size of root element and will throw a warning based on verbosity
settings. This should address [issue#357](https://github.com/mebjas/html5-qrcode/issues/357)

### Version 2.1.4

#### Huge thanks to [Ben Richardson](https://github.com/ben-gy) for one time sponsorship!!
Expand Down
2 changes: 1 addition & 1 deletion minified/html5-qrcode.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html5-qrcode",
"version": "2.1.4",
"version": "2.1.5",
"description": "A cross platform HTML5 QR Code & bar code scanner",
"main": "./cjs/index.js",
"module": "./esm/index.js",
Expand Down
24 changes: 18 additions & 6 deletions src/html5-qrcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ export class Html5Qrcode {
*/
private validateQrboxSize(
internalConfig: InternalHtml5QrcodeConfig,
rootElementWidth: Number) {
rootElementWidth: number) {
const qrboxSize = internalConfig.qrbox!;
this.validateQrboxConfig(qrboxSize);
let qrDimensions = this.toQrdimensions(qrboxSize);
Expand All @@ -980,16 +980,28 @@ export class Html5Qrcode {
}
};

const validateAgainstRootElementSize = (size: number) => {
if (size > rootElementWidth) {
throw "'config.qrbox' dimensions values should not be greater "
+ "than the width of the HTML element.";
/**
* The 'config.qrbox.width' shall be overriden if it's larger than the
* width of the root element.
*
* Based on the verbosity settings, this will be logged to the logger.
*
* @param configWidth the width of qrbox set by users in the config.
*/
const correctWidthBasedOnRootElementSize = (configWidth: number) => {
if (configWidth > rootElementWidth) {
this.logger.warn("`qrbox.width` or `qrbox` is larger than the"
+ " width of the root element. The width will be truncated"
+ " to the width of root element.");
configWidth = rootElementWidth;
}
return configWidth;
};

validateMinSize(qrDimensions.width);
validateMinSize(qrDimensions.height);
validateAgainstRootElementSize(qrDimensions.width);
qrDimensions.width = correctWidthBasedOnRootElementSize(
qrDimensions.width);
// Note: In this case if the height of the qrboxSize turns out to be
// greater than the height of the root element (which should later be
// based on the aspect ratio of the camera stream), it would be silently
Expand Down

0 comments on commit 4616fca

Please sign in to comment.