Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mebjas committed Nov 16, 2022
2 parents 196a5e5 + 7d3625a commit fde2e3c
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 564 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Version 2.3.1
- Improved support for UPC types - by [Breno1288](https://github.com/Breno1288), forked from PR - [pull#501](https://github.com/mebjas/html5-qrcode/pull/501)
- Fix form submission in Firefox issue - [Discussion#413](https://github.com/mebjas/html5-qrcode/discussions/413#discussioncomment-2124480) by [Joggel72](https://github.com/Joggel72), forked from PR - [pull#431](https://github.com/mebjas/html5-qrcode/pull/431)
- Fix support for UPC-E as called out in several bugs - [parent issue#605](https://github.com/mebjas/html5-qrcode/issues/605)
- Add `willReadFrequently` attribute to canvas context for camera scan as per Google Chrome recommendation.

### Version 2.3.0

- Added support for drag and drop of image in file based scanner.
Expand Down
3 changes: 1 addition & 2 deletions minified/html5-qrcode.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/html5-qrcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,17 @@ export class Html5Qrcode {

const canvasElement = this.createCanvasElement(
qrRegion.width, qrRegion.height);
// Tell user agent that this canvas will be read frequently.
// More info:
// https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently
const contextAttributes: any = { willReadFrequently: true };
// Casting canvas to any, as Microsoft's interface definition hasn't
// caught up with latest definition for 'CanvasRenderingContext2DSettings'.
const context: CanvasRenderingContext2D
= canvasElement.getContext("2d")!;
= (<any>canvasElement).getContext("2d", contextAttributes)!;
context.canvas.width = qrRegion.width;
context.canvas.height = qrRegion.height;

// Insert the canvas
this.element!.append(canvasElement);
if (shouldShadingBeApplied) {
Expand Down
3 changes: 3 additions & 0 deletions src/ui/scanner/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export class BaseUiElementFactory {
let element: Type = <Type>(document.createElement(elementType));
element.id = elementId;
element.classList.add(PublicUiElementIdAndClasses.ALL_ELEMENT_CLASS);
if (elementType === "button") {
element.setAttribute("type", "button");
}
return element;
}
}
2 changes: 2 additions & 0 deletions src/zxing-html5-qrcode-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class ZXingHtml5QrcodeDecoder implements QrcodeDecoderAsync {
const formats = this.createZXingFormats(requestedFormats);
const hints = new Map();
hints.set(ZXing.DecodeHintType.POSSIBLE_FORMATS, formats);
// TODO(minhazav): Make this configurable by developers.
hints.set(ZXing.DecodeHintType.TRY_HARDER, false);
this.hints = hints;
}

Expand Down
20 changes: 18 additions & 2 deletions tests/ui/scanner/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,32 @@ describe("BaseUiElementFactory#createElement()", () => {
it("Creates element with expected ID", () => {
const expectedId = "test-id";
let button = BaseUiElementFactory.createElement<HTMLButtonElement>(
"select", expectedId);
"button", expectedId);
expect(button.id).eq(expectedId);
});

it("Creates element with common class", () => {
let button = BaseUiElementFactory.createElement<HTMLButtonElement>(
"select", "test-id");
"button", "test-id");
let hasClass = button.classList.contains(
PublicUiElementIdAndClasses.ALL_ELEMENT_CLASS);

expect(hasClass).to.be.true;
});

it("Creates button element with button type attribute", () => {
let button = BaseUiElementFactory.createElement<HTMLButtonElement>(
"button", "test-id");
let typeAttributeValue = button.getAttribute("type");

expect(typeAttributeValue).eq("button");
});

it("Creates select element without type attribute", () => {
let select = BaseUiElementFactory.createElement<HTMLSelectElement>(
"select", "test-id");
let typeAttributeValue = select.getAttribute("type");

expect(typeAttributeValue).to.be.null;
});
});
3 changes: 2 additions & 1 deletion third_party/zxing-js.umd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ declare class MultiFormatReader {
}

export declare enum DecodeHintType {
POSSIBLE_FORMATS = 2
POSSIBLE_FORMATS = 2,
TRY_HARDER = 3
}

export declare enum BarcodeFormat {
Expand Down
Loading

0 comments on commit fde2e3c

Please sign in to comment.