Skip to content

Commit 0ead9aa

Browse files
committed
Merged migrate-to-qrious into master
2 parents 2620232 + 18332b3 commit 0ead9aa

8 files changed

Lines changed: 178 additions & 99 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
node_modules/
2+
.npmrc

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
[![npm version](https://badge.fury.io/js/angular2-qrcode.svg)](https://badge.fury.io/js/angular2-qrcode)
22
# angular2-qrcode
3-
angular2-qrcode is a component that you can easily integrate into your project. It relies on [qrcode-generator](https://github.com/kazuhikoarase/qrcode-generator) to generate QR Codes.
3+
angular2-qrcode is a component that you can easily integrate into your project. It relies on [qrious](https://github.com/neocotic/qrious) to generate QR Codes.
4+
5+
## Breaking Changes for 2.0.0
6+
7+
`data` has been replaced with `value`. For those that don't need the new features of `2.0.0`, just keep using `1.0.5`. No change will be needed unless you upgrade.
8+
9+
The `type` field has also been removed.
410

511
## Install
612

@@ -27,7 +33,7 @@ import { QRCodeModule } from 'angular2-qrcode';
2733
In component template:
2834
```
2935
<div>
30-
<qr-code [data]="'All QR Code data goes here!'" [size]="150"></qr-code>
36+
<qr-code [value]="'All QR Code data goes here!'" [size]="150"></qr-code>
3137
</div>
3238
```
3339

@@ -42,7 +48,7 @@ import {QRCodeComponent} from 'angular2-qrcode';
4248
directives: [QRCodeComponent],
4349
template: `
4450
<div>
45-
<qr-code [data]="'All QR Code data goes here!'" [size]="150"></qr-code>
51+
<qr-code [value]="'All QR Code data goes here!'" [size]="150"></qr-code>
4652
</div>
4753
`
4854
})
@@ -52,14 +58,16 @@ import {QRCodeComponent} from 'angular2-qrcode';
5258

5359
| Attribute | Type | Default | Description |
5460
| ------------- |-------------| -----|------------|
55-
| data | String | '' | Your data string |
56-
| size | Number | 128 | This is the height/width of your QR Code component |
57-
| level | String | 'M' | QR Correction level ('L', 'M', 'Q', 'H') |
58-
| type | Number | 4 | Buffer size for data string
59-
60-
## Note
61-
62-
If you have `code length overflow` errors, you need to increase the `[type]` value to increase the buffer for your data string.
61+
| value | String | '' | Your data string |
62+
| size | Number | 100 | This is the height/width of your QR Code component |
63+
| level | String | 'L' | QR Correction level ('L', 'M', 'Q', 'H') |
64+
| background | String | 'white' | The color for the background |
65+
| backgroundAlpha | Number | 1.0 | The opacity of the background |
66+
| foreground | String | 'black' | The color for the foreground |
67+
| foregroundAlpha | Number | 1.0 | The opacity of the foreground |
68+
| mime | String | 'image/png' | The mime type for the output image |
69+
| padding | Number | null | The padding around the QR Code |
70+
| canvas | Boolean | false | Will output a canvas element if true |
6371

6472
## License
6573
MIT License

angular2-qrcode.d.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import { ElementRef, OnChanges, SimpleChanges } from '@angular/core';
22
export declare class QRCodeComponent implements OnChanges {
33
private elementRef;
44
ngOnChanges(changes: SimpleChanges): void;
5-
data: string;
6-
size: number;
7-
type: number;
5+
background: string;
6+
backgroundAlpha: number;
7+
foreground: string;
8+
foregroundAlpha: number;
89
level: string;
10+
mime: string;
11+
padding: number;
12+
size: number;
13+
value: string;
14+
canvas: boolean;
915
constructor(elementRef: ElementRef);
1016
generate(): void;
1117
}

angular2-qrcode.js

Lines changed: 97 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular2-qrcode.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular2-qrcode.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,66 @@ import {
66
OnChanges,
77
SimpleChanges
88
} from '@angular/core';
9-
import * as qrcode from "qrcode-generator";
9+
import * as QRious from 'qrious';
1010

1111
@Component({
1212
moduleId: 'module.id',
1313
selector: 'qr-code',
14-
template: ''
14+
template: ``
1515
})
1616
export class QRCodeComponent implements OnChanges {
1717
ngOnChanges(changes: SimpleChanges): void {
18-
if ('data' in changes) {
18+
if ('background' in changes ||
19+
'backgroundAlpha' in changes ||
20+
'foreground' in changes ||
21+
'foregroundAlpha' in changes ||
22+
'level' in changes ||
23+
'mime' in changes ||
24+
'padding' in changes ||
25+
'size' in changes ||
26+
'value' in changes ||
27+
'canvas' in changes) {
1928
this.generate();
2029
}
2130
}
31+
32+
@Input() background: string = 'white';
33+
@Input() backgroundAlpha: number = 1.0;
34+
@Input() foreground: string = 'black';
35+
@Input() foregroundAlpha: number = 1.0;
36+
@Input() level: string = 'L';
37+
@Input() mime: string = 'image/png';
38+
@Input() padding: number = null;
39+
@Input() size: number = 100;
40+
@Input() value: string = '';
2241

23-
@Input() data: string = '';
24-
@Input() size: number = 128;
25-
@Input() type: number = 4;
26-
@Input() level: string = 'M';
42+
@Input() canvas: boolean = false;
2743

2844

2945
constructor(private elementRef: ElementRef) {
3046
}
3147

3248
generate() {
3349
try {
34-
let qr = qrcode(this.type, this.level);
35-
qr.addData(this.data);
36-
qr.make();
37-
38-
let imgTagString = qr.createImgTag(this.type, 0);
3950
let el: HTMLElement = this.elementRef.nativeElement;
40-
el.innerHTML = imgTagString;
41-
let imgTagObject: HTMLImageElement = <HTMLImageElement> el.firstElementChild;
42-
imgTagObject.width = this.size;
43-
imgTagObject.height = this.size;
51+
el.innerHTML = '';
52+
let qr = new QRious({
53+
background: this.background,
54+
backgroundAlpha: this.backgroundAlpha,
55+
foreground: this.foreground,
56+
foregroundAlpha: this.foregroundAlpha,
57+
level: this.level,
58+
mime: this.mime,
59+
padding: this.padding,
60+
size: this.size,
61+
value: this.value
62+
});
63+
64+
if (this.canvas) {
65+
el.appendChild(qr.canvas);
66+
} else {
67+
el.appendChild(qr.image);
68+
}
4469
} catch (e) {
4570
console.error(`Could not generate QR Code: ${e.message}`);
4671
}

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "angular2-qrcode",
3-
"version": "1.0.5",
3+
"version": "2.0.0",
44
"description": "An Angular 2 component that generates a QR Code.",
55
"main": "angular2-qrcode.js",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/SuperiorJT/angular2-qrcode.git"
99
},
10-
"scripts": { },
10+
"scripts": {},
1111
"keywords": [
1212
"qrcode",
1313
"qr",
@@ -17,8 +17,14 @@
1717
"2",
1818
"ng2"
1919
],
20+
"files": [
21+
"angular2-qrcode.d.ts",
22+
"angular2-qrcode.js",
23+
"angular2-qrcode.js.map",
24+
"README.md"
25+
],
2026
"dependencies": {
21-
"qrcode-generator": "^1.0.0"
27+
"qrious": "^2.2.0"
2228
},
2329
"peerDependencies": {
2430
"@angular/core": "^2.0.0"

qrcode-generator.d.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)