Skip to content

Commit

Permalink
Vendor angular-qrcode library
Browse files Browse the repository at this point in the history
  • Loading branch information
threema-danilo committed Jan 19, 2021
1 parent c8ebebb commit 67e007c
Show file tree
Hide file tree
Showing 13 changed files with 503 additions and 16 deletions.
12 changes: 12 additions & 0 deletions .licenses/qrcode-generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
QR Code Generator for JavaScript - TypeScript Declaration File

Copyright (c) 2016 Kazuhiko Arase

URL: http://www.d-project.com/

Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php

The word 'QR Code' is registered trademark of
DENSO WAVE INCORPORATED
http://www.denso-wave.com/qrcode/faqpatent-e.html
20 changes: 20 additions & 0 deletions LICENSE-3RD-PARTY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,26 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



----------
License for qrcode-generator
----------

QR Code Generator for JavaScript - TypeScript Declaration File

Copyright (c) 2016 Kazuhiko Arase

URL: http://www.d-project.com/

Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php

The word 'QR Code' is registered trademark of
DENSO WAVE INCORPORATED
http://www.denso-wave.com/qrcode/faqpatent-e.html




----------
License for saltyrtc-client
----------
Expand Down
1 change: 0 additions & 1 deletion dist/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ targets=(
webrtc-adapter/out/adapter.js
qrcode-generator/qrcode.js
qrcode-generator/qrcode_UTF8.js
angular-qrcode/angular-qrcode.js
angularjs-scroll-glue/src/scrollglue.js
angular-material/angular-material.min.js
angular-material/angular-material.min.css
Expand Down
3 changes: 2 additions & 1 deletion gather-licenses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LICENSE_FILES=(
'angular-inview' 'public/libs/angular-inview/LICENSE'
'angular-material' 'node_modules/angular-material/LICENSE'
'angular-messages' 'node_modules/angular-messages/LICENSE.md'
'angular-qrcode' 'node_modules/angular-qrcode/LICENCE.txt'
'angular-qrcode' 'public/libs/angular-qrcode/LICENCE.txt'
'angular-route' 'node_modules/angular-route/LICENSE.md'
'angular-sanitize' 'node_modules/angular-sanitize/LICENSE.md'
'angular-translate' 'node_modules/angular-translate/LICENSE'
Expand All @@ -23,6 +23,7 @@ LICENSE_FILES=(
'messageformat' 'node_modules/messageformat/LICENSE'
'msgpack-lite' 'node_modules/msgpack-lite/LICENSE'
'node-sass' 'node_modules/node-sass/LICENSE'
'qrcode-generator' '.licenses/qrcode-generator'
'saltyrtc-client' 'node_modules/@saltyrtc/client/LICENSE.md'
'saltyrtc-task-relayed-data' 'node_modules/@saltyrtc/task-relayed-data/LICENSE.md'
'saltyrtc-task-webrtc' 'node_modules/@saltyrtc/task-webrtc/LICENSE.md'
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ <h1 id="title" aria-label="Threema Web Logo">
<!-- Various libraries -->
<script src="node_modules/qrcode-generator/qrcode.js?v=[[VERSION]]"></script>
<script src="node_modules/qrcode-generator/qrcode_UTF8.js?v=[[VERSION]]"></script>
<script src="node_modules/angular-qrcode/angular-qrcode.js?v=[[VERSION]]"></script>
<script src="libs/angular-qrcode/angular-qrcode.js?v=[[VERSION]]"></script>
<script src="node_modules/angular-material/angular-material.min.js?v=[[VERSION]]"></script>
<script src="node_modules/@uirouter/angularjs/release/angular-ui-router.min.js?v=[[VERSION]]"></script>
<script src="node_modules/angularjs-scroll-glue/src/scrollglue.js?v=[[VERSION]]"></script>
Expand Down
15 changes: 3 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"angular-aria": "^1.8.2",
"angular-material": "=1.1.11",
"angular-messages": "^1.8.2",
"angular-qrcode": "~7.2",
"angular-route": "^1.8.2",
"angular-sanitize": "^1.8.2",
"angular-translate": "~2.18.2",
Expand All @@ -72,6 +71,7 @@
"messageformat": "^2.3.0",
"msgpack-lite": "~0.1.26",
"node-sass": "^5.0.0",
"qrcode-generator": "^1.4.4",
"sdp": "~2.12.0",
"ts-events": "~3.4.0",
"ts-loader": "~6.2.1",
Expand Down
21 changes: 21 additions & 0 deletions public/libs/angular-qrcode/LICENCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Monospaced

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
3 changes: 3 additions & 0 deletions public/libs/angular-qrcode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
angular-qrcode library with changes from pull request 10 applied (commit 84dcf083b12d0a71759091ea849ae982f389848a)

https://github.com/monospaced/angular-qrcode/pull/10
233 changes: 233 additions & 0 deletions public/libs/angular-qrcode/angular-qrcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/*
* angular-qrcode
* (c) 2017 Monospaced http://monospaced.com
* License: MIT
*/

if (typeof module !== 'undefined' &&
typeof exports !== 'undefined' &&
module.exports === exports){
module.exports = 'monospaced.qrcode';
}

angular.module('monospaced.qrcode', [])
.directive('qrcode', ['$window', function($window) {

var canvas2D = !!$window.CanvasRenderingContext2D,
levels = {
'L': 'Low',
'M': 'Medium',
'Q': 'Quartile',
'H': 'High'
},
draw = function(context, qr, modules, tile, color) {
for (var row = 0; row < modules; row++) {
for (var col = 0; col < modules; col++) {
var w = (Math.ceil((col + 1) * tile) - Math.floor(col * tile)),
h = (Math.ceil((row + 1) * tile) - Math.floor(row * tile));

context.fillStyle = qr.isDark(row, col) ? color.foreground : color.background;
context.fillRect(Math.round(col * tile),
Math.round(row * tile), w, h);
}
}
};

return {
restrict: 'E',
template: '<canvas class="qrcode"></canvas>',
link: function(scope, element, attrs) {
var domElement = element[0],
$canvas = element.find('canvas'),
canvas = $canvas[0],
context = canvas2D ? canvas.getContext('2d') : null,
download = 'download' in attrs,
href = attrs.href,
link = download || href ? document.createElement('a') : '',
trim = /^\s+|\s+$/g,
error,
version,
errorCorrectionLevel,
data,
size,
modules,
tile,
qr,
$img,
color = {
foreground: '#000',
background: '#fff'
},
setColor = function(value) {
color.foreground = value || color.foreground;
},
setBackground = function(value) {
color.background = value || color.background;
},
setVersion = function(value) {
version = Math.max(1, Math.min(parseInt(value, 10), 40)) || 5;
},
setErrorCorrectionLevel = function(value) {
errorCorrectionLevel = value in levels ? value : 'M';
},
setData = function(value) {
if (!value) {
return;
}

data = value.replace(trim, '');
qr = qrcode(version, errorCorrectionLevel);
qr.addData(data);

try {
qr.make();
} catch (e) {
var newVersion;
if (version >= 40) {
throw new Error('Data is too long', e);
}
newVersion = version + 1;
setVersion(newVersion);
console.warn('qrcode version is too low and has been incremented to', newVersion)
setData(value);
return;
}

error = false;
modules = qr.getModuleCount();
},
setSize = function(value) {
size = parseInt(value, 10) || modules * 2;
tile = size / modules;
canvas.width = canvas.height = size;
},
render = function() {
if (!qr) {
return;
}

if (error) {
if (link) {
link.removeAttribute('download');
link.title = '';
link.href = '#_';
}
if (!canvas2D) {
domElement.innerHTML = '<img src width="' + size + '"' +
'height="' + size + '"' +
'class="qrcode">';
}
scope.$emit('qrcode:error', error);
return;
}

if (download) {
domElement.download = 'qrcode.png';
domElement.title = 'Download QR code';
}

if (canvas2D) {
draw(context, qr, modules, tile, color);

if (download) {
domElement.href = canvas.toDataURL('image/png');
return;
}
} else {
domElement.innerHTML = qr.createImgTag(tile, 0);
$img = element.find('img');
$img.addClass('qrcode');

if (download) {
domElement.href = $img[0].src;
return;
}
}

if (href) {
domElement.href = href;
}
};

if (link) {
link.className = 'qrcode-link';
$canvas.wrap(link);
domElement = domElement.firstChild;
}

setColor(attrs.color);
setBackground(attrs.background);
setVersion(attrs.version);
setErrorCorrectionLevel(attrs.errorCorrectionLevel);
setSize(attrs.size);

attrs.$observe('version', function(value) {
if (!value) {
return;
}

setVersion(value);
setData(data);
setSize(size);
render();
});

attrs.$observe('errorCorrectionLevel', function(value) {
if (!value) {
return;
}

setErrorCorrectionLevel(value);
setData(data);
setSize(size);
render();
});

attrs.$observe('data', function(value) {
if (!value) {
return;
}

setData(value);
setSize(size);
render();
});

attrs.$observe('size', function(value) {
if (!value) {
return;
}

setSize(value);
render();
});

attrs.$observe('color', function(value) {
if (!value) {
return;
}

setColor(value);
render();
});

attrs.$observe('background', function(value) {
if (!value) {
return;
}

setBackground(value);
render();
});

attrs.$observe('href', function(value) {
if (!value) {
return;
}

href = value;
render();
});
}
};
}]);
15 changes: 15 additions & 0 deletions public/libs/angular-qrcode/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "angular-qrcode",
"version": "7.2.0",
"main": "angular-qrcode.js",
"license" : "MIT",
"ignore": [
"**/.*",
"node_modules",
"components"
],
"dependencies": {
"angular": ">=1.0.6",
"qrcode-generator": "git://github.com/monospaced/bower-qrcode-generator.git#v0.2.0"
}
}
Loading

0 comments on commit 67e007c

Please sign in to comment.