qrious
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -0,1 +1,8 @@ | ||
## Version 3.0.0, 2017.06.01 | ||
* Reduce size of distribution files [#59](https://github.com/neocotic/qrious/issues/59) (**breaking change**) | ||
* Drop support for Node.js < 4 [#74](https://github.com/neocotic/qrious/issues/74) (**breaking change**) | ||
* Remove QRious.DEFAULTS [#77](https://github.com/neocotic/qrious/issues/77) (**breaking change**) | ||
* Rewrite code in ES5 [#81](https://github.com/neocotic/qrious/issues/81) (**breaking change**) | ||
## Version 2.3.0, 2017.05.31 | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "qrious", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "Library for QR code generation using canvas", | ||
@@ -26,2 +26,5 @@ "homepage": "https://github.com/neocotic/qrious", | ||
}, | ||
"dependencies": { | ||
"nevis": "^0.5.0" | ||
}, | ||
"optionalDependencies": { | ||
@@ -31,6 +34,2 @@ "canvas": "^1.6.5" | ||
"devDependencies": { | ||
"babel-eslint": "^7.2.3", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-runtime": "^6.23.0", | ||
"eslint-config-notninja": "^0.1.1", | ||
@@ -43,16 +42,15 @@ "grunt": "^1.0.1", | ||
"grunt-rollup": "^1.0.1", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"load-grunt-tasks": "^3.5.2", | ||
"micromatch": "^2.3.11", | ||
"rollup-plugin-commonjs": "^8.0.2", | ||
"rollup-plugin-node-resolve": "~2.0.0", | ||
"rollup-plugin-uglify": "^1.0.2", | ||
"semver": "^5.3.0" | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-uglify": "^2.0.1" | ||
}, | ||
"browser": "dist/umd/qrious.js", | ||
"main": "dist/cjs/qrious.js", | ||
"module": "src/runtime/node.js", | ||
"jsnext:main": "src/runtime/node.js", | ||
"browser": "dist/qrious.js", | ||
"main": "src/runtime/node.js", | ||
"scripts": { | ||
"build": "grunt build", | ||
"ci": "grunt ci", | ||
"test": "grunt test" | ||
} | ||
} |
@@ -13,2 +13,3 @@ .oooooo. ooooooooo. o8o | ||
[![Build Status](https://img.shields.io/travis/neocotic/qrious/develop.svg?style=flat-square)](https://travis-ci.org/neocotic/qrious) | ||
[![Dependency Status](https://img.shields.io/david/neocotic/qrious.svg?style=flat-square)](https://david-dm.org/neocotic/qrious) | ||
[![Optional Dependency Status](https://img.shields.io/david/optional/neocotic/qrious.svg?style=flat-square)](https://david-dm.org/neocotic/qrious?type=optional) | ||
@@ -42,4 +43,4 @@ [![Dev Dependency Status](https://img.shields.io/david/dev/neocotic/qrious.svg?style=flat-square)](https://david-dm.org/neocotic/qrious?type=dev) | ||
* [Development Version](https://cdn.rawgit.com/neocotic/qrious/master/dist/umd/qrious.js) (123kb - [Source Map](https://cdn.rawgit.com/neocotic/qrious/master/dist/umd/qrious.js.map)) | ||
* [Production Version](https://cdn.rawgit.com/neocotic/qrious/master/dist/umd/qrious.min.js) (37kb - [Source Map](https://cdn.rawgit.com/neocotic/qrious/master/dist/umd/qrious.min.js.map)) | ||
* [Development Version](https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.js) (123kb - [Source Map](https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.js.map)) | ||
* [Production Version](https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.min.js) (37kb - [Source Map](https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.min.js.map)) | ||
@@ -111,13 +112,14 @@ ### Node.js Dependencies | ||
| Field | Type | Description | Default | | ||
| --------------- | ------ | -------------------------------------------------- | ------------- | | ||
| background | String | Background color of the QR code | `"white"` | | ||
| backgroundAlpha | Number | Background alpha of the QR code | `1.0` | | ||
| foreground | String | Foreground color of the QR code | `"black"` | | ||
| foregroundAlpha | Number | Foreground alpha of the QR code | `1.0` | | ||
| level | String | Error correction level of the QR code (L, M, Q, H) | `"L"` | | ||
| mime | String | MIME type used to render the image for the QR code | `"image/png"` | | ||
| padding | Number | Padding for the QR code (pixels) | `null` (auto) | | ||
| size | Number | Size of the QR code (pixels) | `100` | | ||
| value | String | Value encoded within the QR code | `""` | | ||
| Field | Type | Description | Default | Read Only | | ||
| --------------- | ------- | -------------------------------------------------- | ------------- | --------- | | ||
| background | String | Background color of the QR code | `"white"` | No | | ||
| backgroundAlpha | Number | Background alpha of the QR code | `1.0` | No | | ||
| element | Element | Element to render the QR code | `<canvas>` | Yes | | ||
| foreground | String | Foreground color of the QR code | `"black"` | No | | ||
| foregroundAlpha | Number | Foreground alpha of the QR code | `1.0` | No | | ||
| level | String | Error correction level of the QR code (L, M, Q, H) | `"L"` | No | | ||
| mime | String | MIME type used to render the image for the QR code | `"image/png"` | No | | ||
| padding | Number | Padding for the QR code (pixels) | `null` (auto) | No | | ||
| size | Number | Size of the QR code (pixels) | `100` | No | | ||
| value | String | Value encoded within the QR code | `""` | No | | ||
@@ -170,5 +172,6 @@ ``` javascript | ||
You can also pass in an `element` option to the constructor which can be used to generate the QR code using an existing | ||
DOM element. `element` must either be a `<canvas>` element or an `<img>` element which can then be accessed via the | ||
`canvas` or `image` fields on the instance respectively. An element will be created for whichever one isn't provided or | ||
for both if no `element` is specified, which means that they can be appeneded to the document at a later time. | ||
DOM element, which is the only time that you can specify read only options. `element` must either be a `<canvas>` | ||
element or an `<img>` element which can then be accessed via the `canvas` or `image` fields on the instance | ||
respectively. An element will be created for whichever one isn't provided or for both if no `element` is specified, | ||
which means that they can be appended to the document at a later time. | ||
@@ -219,3 +222,3 @@ ``` javascript | ||
QRious.VERSION; | ||
//=> "2.3.0" | ||
//=> "3.0.0" | ||
``` | ||
@@ -222,0 +225,0 @@ |
@@ -20,4 +20,8 @@ /* | ||
'use strict'; | ||
/* eslint no-multi-spaces: "off" */ | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
@@ -27,22 +31,23 @@ * Contains alignment pattern information. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class Alignment { | ||
var Alignment = Nevis.extend(null, { | ||
/** | ||
* Returns the alignment pattern block. | ||
* The alignment pattern block. | ||
* | ||
* @return {number[]} The alignment pattern block. | ||
* @public | ||
* @static | ||
* @type {number[]} | ||
* @memberof Alignment | ||
*/ | ||
static get BLOCK() { | ||
return [ | ||
0, 11, 15, 19, 23, 27, 31, | ||
16, 18, 20, 22, 24, 26, 28, 20, 22, 24, 24, 26, 28, 28, 22, 24, 24, | ||
26, 26, 28, 28, 24, 24, 26, 26, 26, 28, 28, 24, 26, 26, 26, 28, 28 | ||
]; | ||
} | ||
BLOCK: [ | ||
0, 11, 15, 19, 23, 27, 31, | ||
16, 18, 20, 22, 24, 26, 28, 20, 22, 24, 24, 26, 28, 28, 22, 24, 24, | ||
26, 26, 28, 28, 24, 24, 26, 26, 26, 28, 28, 24, 26, 26, 26, 28, 28 | ||
] | ||
} | ||
}); | ||
export default Alignment; | ||
module.exports = Alignment; |
@@ -20,4 +20,8 @@ /* | ||
'use strict'; | ||
/* eslint no-multi-spaces: "off" */ | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
@@ -27,7 +31,9 @@ * Contains error correction information. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class ErrorCorrection { | ||
var ErrorCorrection = Nevis.extend(null, { | ||
/** | ||
* Returns the error correction blocks. | ||
* The error correction blocks. | ||
* | ||
@@ -37,89 +43,86 @@ * There are four elements per version. The first two indicate the number of blocks, then the data width, and finally | ||
* | ||
* @return {number[]} The ECC blocks. | ||
* @public | ||
* @static | ||
* @type {number[]} | ||
* @memberof ErrorCorrection | ||
*/ | ||
static get BLOCKS() { | ||
return [ | ||
1, 0, 19, 7, 1, 0, 16, 10, 1, 0, 13, 13, 1, 0, 9, 17, | ||
1, 0, 34, 10, 1, 0, 28, 16, 1, 0, 22, 22, 1, 0, 16, 28, | ||
1, 0, 55, 15, 1, 0, 44, 26, 2, 0, 17, 18, 2, 0, 13, 22, | ||
1, 0, 80, 20, 2, 0, 32, 18, 2, 0, 24, 26, 4, 0, 9, 16, | ||
1, 0, 108, 26, 2, 0, 43, 24, 2, 2, 15, 18, 2, 2, 11, 22, | ||
2, 0, 68, 18, 4, 0, 27, 16, 4, 0, 19, 24, 4, 0, 15, 28, | ||
2, 0, 78, 20, 4, 0, 31, 18, 2, 4, 14, 18, 4, 1, 13, 26, | ||
2, 0, 97, 24, 2, 2, 38, 22, 4, 2, 18, 22, 4, 2, 14, 26, | ||
2, 0, 116, 30, 3, 2, 36, 22, 4, 4, 16, 20, 4, 4, 12, 24, | ||
2, 2, 68, 18, 4, 1, 43, 26, 6, 2, 19, 24, 6, 2, 15, 28, | ||
4, 0, 81, 20, 1, 4, 50, 30, 4, 4, 22, 28, 3, 8, 12, 24, | ||
2, 2, 92, 24, 6, 2, 36, 22, 4, 6, 20, 26, 7, 4, 14, 28, | ||
4, 0, 107, 26, 8, 1, 37, 22, 8, 4, 20, 24, 12, 4, 11, 22, | ||
3, 1, 115, 30, 4, 5, 40, 24, 11, 5, 16, 20, 11, 5, 12, 24, | ||
5, 1, 87, 22, 5, 5, 41, 24, 5, 7, 24, 30, 11, 7, 12, 24, | ||
5, 1, 98, 24, 7, 3, 45, 28, 15, 2, 19, 24, 3, 13, 15, 30, | ||
1, 5, 107, 28, 10, 1, 46, 28, 1, 15, 22, 28, 2, 17, 14, 28, | ||
5, 1, 120, 30, 9, 4, 43, 26, 17, 1, 22, 28, 2, 19, 14, 28, | ||
3, 4, 113, 28, 3, 11, 44, 26, 17, 4, 21, 26, 9, 16, 13, 26, | ||
3, 5, 107, 28, 3, 13, 41, 26, 15, 5, 24, 30, 15, 10, 15, 28, | ||
4, 4, 116, 28, 17, 0, 42, 26, 17, 6, 22, 28, 19, 6, 16, 30, | ||
2, 7, 111, 28, 17, 0, 46, 28, 7, 16, 24, 30, 34, 0, 13, 24, | ||
4, 5, 121, 30, 4, 14, 47, 28, 11, 14, 24, 30, 16, 14, 15, 30, | ||
6, 4, 117, 30, 6, 14, 45, 28, 11, 16, 24, 30, 30, 2, 16, 30, | ||
8, 4, 106, 26, 8, 13, 47, 28, 7, 22, 24, 30, 22, 13, 15, 30, | ||
10, 2, 114, 28, 19, 4, 46, 28, 28, 6, 22, 28, 33, 4, 16, 30, | ||
8, 4, 122, 30, 22, 3, 45, 28, 8, 26, 23, 30, 12, 28, 15, 30, | ||
3, 10, 117, 30, 3, 23, 45, 28, 4, 31, 24, 30, 11, 31, 15, 30, | ||
7, 7, 116, 30, 21, 7, 45, 28, 1, 37, 23, 30, 19, 26, 15, 30, | ||
5, 10, 115, 30, 19, 10, 47, 28, 15, 25, 24, 30, 23, 25, 15, 30, | ||
13, 3, 115, 30, 2, 29, 46, 28, 42, 1, 24, 30, 23, 28, 15, 30, | ||
17, 0, 115, 30, 10, 23, 46, 28, 10, 35, 24, 30, 19, 35, 15, 30, | ||
17, 1, 115, 30, 14, 21, 46, 28, 29, 19, 24, 30, 11, 46, 15, 30, | ||
13, 6, 115, 30, 14, 23, 46, 28, 44, 7, 24, 30, 59, 1, 16, 30, | ||
12, 7, 121, 30, 12, 26, 47, 28, 39, 14, 24, 30, 22, 41, 15, 30, | ||
6, 14, 121, 30, 6, 34, 47, 28, 46, 10, 24, 30, 2, 64, 15, 30, | ||
17, 4, 122, 30, 29, 14, 46, 28, 49, 10, 24, 30, 24, 46, 15, 30, | ||
4, 18, 122, 30, 13, 32, 46, 28, 48, 14, 24, 30, 42, 32, 15, 30, | ||
20, 4, 117, 30, 40, 7, 47, 28, 43, 22, 24, 30, 10, 67, 15, 30, | ||
19, 6, 118, 30, 18, 31, 47, 28, 34, 34, 24, 30, 20, 61, 15, 30 | ||
]; | ||
} | ||
BLOCKS: [ | ||
1, 0, 19, 7, 1, 0, 16, 10, 1, 0, 13, 13, 1, 0, 9, 17, | ||
1, 0, 34, 10, 1, 0, 28, 16, 1, 0, 22, 22, 1, 0, 16, 28, | ||
1, 0, 55, 15, 1, 0, 44, 26, 2, 0, 17, 18, 2, 0, 13, 22, | ||
1, 0, 80, 20, 2, 0, 32, 18, 2, 0, 24, 26, 4, 0, 9, 16, | ||
1, 0, 108, 26, 2, 0, 43, 24, 2, 2, 15, 18, 2, 2, 11, 22, | ||
2, 0, 68, 18, 4, 0, 27, 16, 4, 0, 19, 24, 4, 0, 15, 28, | ||
2, 0, 78, 20, 4, 0, 31, 18, 2, 4, 14, 18, 4, 1, 13, 26, | ||
2, 0, 97, 24, 2, 2, 38, 22, 4, 2, 18, 22, 4, 2, 14, 26, | ||
2, 0, 116, 30, 3, 2, 36, 22, 4, 4, 16, 20, 4, 4, 12, 24, | ||
2, 2, 68, 18, 4, 1, 43, 26, 6, 2, 19, 24, 6, 2, 15, 28, | ||
4, 0, 81, 20, 1, 4, 50, 30, 4, 4, 22, 28, 3, 8, 12, 24, | ||
2, 2, 92, 24, 6, 2, 36, 22, 4, 6, 20, 26, 7, 4, 14, 28, | ||
4, 0, 107, 26, 8, 1, 37, 22, 8, 4, 20, 24, 12, 4, 11, 22, | ||
3, 1, 115, 30, 4, 5, 40, 24, 11, 5, 16, 20, 11, 5, 12, 24, | ||
5, 1, 87, 22, 5, 5, 41, 24, 5, 7, 24, 30, 11, 7, 12, 24, | ||
5, 1, 98, 24, 7, 3, 45, 28, 15, 2, 19, 24, 3, 13, 15, 30, | ||
1, 5, 107, 28, 10, 1, 46, 28, 1, 15, 22, 28, 2, 17, 14, 28, | ||
5, 1, 120, 30, 9, 4, 43, 26, 17, 1, 22, 28, 2, 19, 14, 28, | ||
3, 4, 113, 28, 3, 11, 44, 26, 17, 4, 21, 26, 9, 16, 13, 26, | ||
3, 5, 107, 28, 3, 13, 41, 26, 15, 5, 24, 30, 15, 10, 15, 28, | ||
4, 4, 116, 28, 17, 0, 42, 26, 17, 6, 22, 28, 19, 6, 16, 30, | ||
2, 7, 111, 28, 17, 0, 46, 28, 7, 16, 24, 30, 34, 0, 13, 24, | ||
4, 5, 121, 30, 4, 14, 47, 28, 11, 14, 24, 30, 16, 14, 15, 30, | ||
6, 4, 117, 30, 6, 14, 45, 28, 11, 16, 24, 30, 30, 2, 16, 30, | ||
8, 4, 106, 26, 8, 13, 47, 28, 7, 22, 24, 30, 22, 13, 15, 30, | ||
10, 2, 114, 28, 19, 4, 46, 28, 28, 6, 22, 28, 33, 4, 16, 30, | ||
8, 4, 122, 30, 22, 3, 45, 28, 8, 26, 23, 30, 12, 28, 15, 30, | ||
3, 10, 117, 30, 3, 23, 45, 28, 4, 31, 24, 30, 11, 31, 15, 30, | ||
7, 7, 116, 30, 21, 7, 45, 28, 1, 37, 23, 30, 19, 26, 15, 30, | ||
5, 10, 115, 30, 19, 10, 47, 28, 15, 25, 24, 30, 23, 25, 15, 30, | ||
13, 3, 115, 30, 2, 29, 46, 28, 42, 1, 24, 30, 23, 28, 15, 30, | ||
17, 0, 115, 30, 10, 23, 46, 28, 10, 35, 24, 30, 19, 35, 15, 30, | ||
17, 1, 115, 30, 14, 21, 46, 28, 29, 19, 24, 30, 11, 46, 15, 30, | ||
13, 6, 115, 30, 14, 23, 46, 28, 44, 7, 24, 30, 59, 1, 16, 30, | ||
12, 7, 121, 30, 12, 26, 47, 28, 39, 14, 24, 30, 22, 41, 15, 30, | ||
6, 14, 121, 30, 6, 34, 47, 28, 46, 10, 24, 30, 2, 64, 15, 30, | ||
17, 4, 122, 30, 29, 14, 46, 28, 49, 10, 24, 30, 24, 46, 15, 30, | ||
4, 18, 122, 30, 13, 32, 46, 28, 48, 14, 24, 30, 42, 32, 15, 30, | ||
20, 4, 117, 30, 40, 7, 47, 28, 43, 22, 24, 30, 10, 67, 15, 30, | ||
19, 6, 118, 30, 18, 31, 47, 28, 34, 34, 24, 30, 20, 61, 15, 30 | ||
], | ||
/** | ||
* Returns the final format bits with mask (level << 3 | mask). | ||
* The final format bits with mask (level << 3 | mask). | ||
* | ||
* @return {number[]} The final format bits. | ||
* @public | ||
* @static | ||
* @type {number[]} | ||
* @memberof ErrorCorrection | ||
*/ | ||
static get FINAL_FORMAT() { | ||
return [ | ||
// L | ||
0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976, | ||
// M | ||
0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0, | ||
// Q | ||
0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed, | ||
// H | ||
0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b | ||
]; | ||
} | ||
FINAL_FORMAT: [ | ||
// L | ||
0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976, | ||
// M | ||
0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0, | ||
// Q | ||
0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed, | ||
// H | ||
0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b | ||
], | ||
/** | ||
* Returns a map of human-readable ECC levels. | ||
* A map of human-readable ECC levels. | ||
* | ||
* @return {Object<string, number>} A ECC level mapping. | ||
* @public | ||
* @static | ||
* @type {Object.<string, number>} | ||
* @memberof ErrorCorrection | ||
*/ | ||
static get LEVELS() { | ||
return { | ||
L: 1, | ||
M: 2, | ||
Q: 3, | ||
H: 4 | ||
}; | ||
LEVELS: { | ||
L: 1, | ||
M: 2, | ||
Q: 3, | ||
H: 4 | ||
} | ||
} | ||
}); | ||
export default ErrorCorrection; | ||
module.exports = ErrorCorrection; |
781
src/Frame.js
@@ -20,157 +20,108 @@ /* | ||
import Alignment from './Alignment'; | ||
import ErrorCorrection from './ErrorCorrection'; | ||
import Galois from './Galois'; | ||
import Version from './Version'; | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
var Alignment = require('./Alignment'); | ||
var ErrorCorrection = require('./ErrorCorrection'); | ||
var Galois = require('./Galois'); | ||
var Version = require('./Version'); | ||
/** | ||
* Generates information for a QR code frame based on a specific value to be encoded. | ||
* | ||
* @param {Frame~Options} options - the options to be used | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class Frame { | ||
var Frame = Nevis.extend(function(options) { | ||
var dataBlock, eccBlock, index, neccBlock1, neccBlock2; | ||
var valueLength = options.value.length; | ||
static _createArray(length) { | ||
const array = []; | ||
this._badness = []; | ||
this._level = ErrorCorrection.LEVELS[options.level]; | ||
this._polynomial = []; | ||
this._value = options.value; | ||
this._version = 0; | ||
this._stringBuffer = []; | ||
for (let i = 0; i < length; i++) { | ||
array[i] = 0; | ||
} | ||
while (this._version < 40) { | ||
this._version++; | ||
return array; | ||
} | ||
index = ((this._level - 1) * 4) + ((this._version - 1) * 16); | ||
static _getMaskBit(x, y) { | ||
let bit; | ||
neccBlock1 = ErrorCorrection.BLOCKS[index++]; | ||
neccBlock2 = ErrorCorrection.BLOCKS[index++]; | ||
dataBlock = ErrorCorrection.BLOCKS[index++]; | ||
eccBlock = ErrorCorrection.BLOCKS[index]; | ||
if (x > y) { | ||
bit = x; | ||
x = y; | ||
y = bit; | ||
} | ||
index = (dataBlock * (neccBlock1 + neccBlock2)) + neccBlock2 - 3 + (this._version <= 9); | ||
bit = y; | ||
bit += y * y; | ||
bit >>= 1; | ||
bit += x; | ||
return bit; | ||
} | ||
static _modN(x) { | ||
while (x >= 255) { | ||
x -= 255; | ||
x = (x >> 8) + (x & 255); | ||
if (valueLength <= index) { | ||
break; | ||
} | ||
return x; | ||
} | ||
// *Badness* coefficients. | ||
static get N1() { | ||
return 3; | ||
} | ||
static get N2() { | ||
return 3; | ||
} | ||
static get N3() { | ||
return 40; | ||
} | ||
static get N4() { | ||
return 10; | ||
} | ||
this._dataBlock = dataBlock; | ||
this._eccBlock = eccBlock; | ||
this._neccBlock1 = neccBlock1; | ||
this._neccBlock2 = neccBlock2; | ||
/** | ||
* Creates an instance of {@link Frame} based on the <code>options</code> provided. | ||
* The data width is based on version. | ||
* | ||
* @param {Frame~Options} options - the options to be used | ||
* @public | ||
* @type {number} | ||
* @memberof Frame# | ||
*/ | ||
constructor(options) { | ||
this._badness = []; | ||
this._level = ErrorCorrection.LEVELS[options.level]; | ||
this._polynomial = []; | ||
this._value = options.value; | ||
this._valueLength = this._value.length; | ||
this._version = 0; | ||
this._stringBuffer = []; | ||
// FIXME: Ensure that it fits instead of being truncated. | ||
var width = this.width = 17 + (4 * this._version); | ||
let dataBlock; | ||
let eccBlock; | ||
let neccBlock1; | ||
let neccBlock2; | ||
/** | ||
* The image buffer. | ||
* | ||
* @public | ||
* @type {number[]} | ||
* @memberof Frame# | ||
*/ | ||
this.buffer = Frame._createArray(width * width); | ||
while (this._version < 40) { | ||
this._version++; | ||
this._ecc = Frame._createArray(dataBlock + ((dataBlock + eccBlock) * (neccBlock1 + neccBlock2)) + neccBlock2); | ||
this._mask = Frame._createArray(((width * (width + 1)) + 1) / 2); | ||
let index = ((this._level - 1) * 4) + ((this._version - 1) * 16); | ||
this._insertFinders(); | ||
this._insertAlignments(); | ||
neccBlock1 = ErrorCorrection.BLOCKS[index++]; | ||
neccBlock2 = ErrorCorrection.BLOCKS[index++]; | ||
dataBlock = ErrorCorrection.BLOCKS[index++]; | ||
eccBlock = ErrorCorrection.BLOCKS[index]; | ||
// Insert single foreground cell. | ||
this.buffer[8 + (width * (width - 8))] = 1; | ||
index = (dataBlock * (neccBlock1 + neccBlock2)) + neccBlock2 - 3 + (this._version <= 9); | ||
this._insertTimingGap(); | ||
this._reverseMask(); | ||
this._insertTimingRowAndColumn(); | ||
this._insertVersion(); | ||
this._syncMask(); | ||
this._convertBitStream(valueLength); | ||
this._calculatePolynomial(); | ||
this._appendEccToData(); | ||
this._interleaveBlocks(); | ||
this._pack(); | ||
this._finish(); | ||
}, { | ||
if (this._valueLength <= index) { | ||
break; | ||
} | ||
} | ||
_addAlignment: function(x, y) { | ||
var i; | ||
var buffer = this.buffer; | ||
var width = this.width; | ||
this._dataBlock = dataBlock; | ||
this._eccBlock = eccBlock; | ||
this._neccBlock1 = neccBlock1; | ||
this._neccBlock2 = neccBlock2; | ||
buffer[x + (width * y)] = 1; | ||
/** | ||
* The data width is based on version. | ||
* | ||
* @public | ||
* @type {number} | ||
*/ | ||
// FIXME: Ensure that it fits instead of being truncated. | ||
this.width = 17 + (4 * this._version); | ||
/** | ||
* The image buffer. | ||
* | ||
* @public | ||
* @type {number[]} | ||
*/ | ||
this.buffer = Frame._createArray(this.width * this.width); | ||
this._ecc = Frame._createArray(this._dataBlock + ((this._dataBlock + this._eccBlock) * | ||
(this._neccBlock1 + this._neccBlock2)) + this._neccBlock2); | ||
this._mask = Frame._createArray(((this.width * (this.width + 1)) + 1) / 2); | ||
this._insertFinders(); | ||
this._insertAlignments(); | ||
// Insert single foreground cell. | ||
this.buffer[8 + (this.width * (this.width - 8))] = 1; | ||
this._insertTimingGap(); | ||
this._reverseMask(); | ||
this._insertTimingRowAndColumn(); | ||
this._insertVersion(); | ||
this._syncMask(); | ||
this._convertBitStream(this._value.length); | ||
this._calculatePolynomial(); | ||
this._appendEccToData(); | ||
this._interleaveBlocks(); | ||
this._pack(); | ||
this._finish(); | ||
} | ||
_addAlignment(x, y) { | ||
this.buffer[x + (this.width * y)] = 1; | ||
for (let i = -2; i < 2; i++) { | ||
this.buffer[x + i + (this.width * (y - 2))] = 1; | ||
this.buffer[x - 2 + (this.width * (y + i + 1))] = 1; | ||
this.buffer[x + 2 + (this.width * (y + i))] = 1; | ||
this.buffer[x + i + 1 + (this.width * (y + 2))] = 1; | ||
for (i = -2; i < 2; i++) { | ||
buffer[x + i + (width * (y - 2))] = 1; | ||
buffer[x - 2 + (width * (y + i + 1))] = 1; | ||
buffer[x + 2 + (width * (y + i))] = 1; | ||
buffer[x + i + 1 + (width * (y + 2))] = 1; | ||
} | ||
for (let i = 0; i < 2; i++) { | ||
for (i = 0; i < 2; i++) { | ||
this._setMask(x - 1, y + i); | ||
@@ -181,56 +132,64 @@ this._setMask(x + 1, y - i); | ||
} | ||
} | ||
}, | ||
_appendData(data, dataLength, ecc, eccLength) { | ||
for (let i = 0; i < eccLength; i++) { | ||
this._stringBuffer[ecc + i] = 0; | ||
_appendData: function(data, dataLength, ecc, eccLength) { | ||
var bit, i, j; | ||
var polynomial = this._polynomial; | ||
var stringBuffer = this._stringBuffer; | ||
for (i = 0; i < eccLength; i++) { | ||
stringBuffer[ecc + i] = 0; | ||
} | ||
for (let i = 0; i < dataLength; i++) { | ||
const bit = Galois.LOG[this._stringBuffer[data + i] ^ this._stringBuffer[ecc]]; | ||
for (i = 0; i < dataLength; i++) { | ||
bit = Galois.LOG[stringBuffer[data + i] ^ stringBuffer[ecc]]; | ||
if (bit !== 255) { | ||
for (let j = 1; j < eccLength; j++) { | ||
this._stringBuffer[ecc + j - 1] = this._stringBuffer[ecc + j] ^ | ||
Galois.EXPONENT[Frame._modN(bit + this._polynomial[eccLength - j])]; | ||
for (j = 1; j < eccLength; j++) { | ||
stringBuffer[ecc + j - 1] = stringBuffer[ecc + j] ^ | ||
Galois.EXPONENT[Frame._modN(bit + polynomial[eccLength - j])]; | ||
} | ||
} else { | ||
for (let j = ecc; j < ecc + eccLength; j++) { | ||
this._stringBuffer[j] = this._stringBuffer[j + 1]; | ||
for (j = ecc; j < ecc + eccLength; j++) { | ||
stringBuffer[j] = stringBuffer[j + 1]; | ||
} | ||
} | ||
this._stringBuffer[ecc + eccLength - 1] = bit === 255 ? 0 | ||
: Galois.EXPONENT[Frame._modN(bit + this._polynomial[0])]; | ||
stringBuffer[ecc + eccLength - 1] = bit === 255 ? 0 : Galois.EXPONENT[Frame._modN(bit + polynomial[0])]; | ||
} | ||
} | ||
}, | ||
_appendEccToData() { | ||
let data = 0; | ||
let ecc = this._calculateMaxLength(); | ||
_appendEccToData: function() { | ||
var i; | ||
var data = 0; | ||
var dataBlock = this._dataBlock; | ||
var ecc = this._calculateMaxLength(); | ||
var eccBlock = this._eccBlock; | ||
for (let i = 0; i < this._neccBlock1; i++) { | ||
this._appendData(data, this._dataBlock, ecc, this._eccBlock); | ||
for (i = 0; i < this._neccBlock1; i++) { | ||
this._appendData(data, dataBlock, ecc, eccBlock); | ||
data += this._dataBlock; | ||
ecc += this._eccBlock; | ||
data += dataBlock; | ||
ecc += eccBlock; | ||
} | ||
for (let i = 0; i < this._neccBlock2; i++) { | ||
this._appendData(data, this._dataBlock + 1, ecc, this._eccBlock); | ||
for (i = 0; i < this._neccBlock2; i++) { | ||
this._appendData(data, dataBlock + 1, ecc, eccBlock); | ||
data += this._dataBlock + 1; | ||
ecc += this._eccBlock; | ||
data += dataBlock + 1; | ||
ecc += eccBlock; | ||
} | ||
} | ||
}, | ||
_applyMask(mask) { | ||
const width = this.width; | ||
_applyMask: function(mask) { | ||
var r3x, r3y, x, y; | ||
var buffer = this.buffer; | ||
var width = this.width; | ||
switch (mask) { | ||
case 0: | ||
for (let y = 0; y < width; y++) { | ||
for (let x = 0; x < width; x++) { | ||
for (y = 0; y < width; y++) { | ||
for (x = 0; x < width; x++) { | ||
if (!((x + y) & 1) && !this._isMasked(x, y)) { | ||
this.buffer[x + (y * width)] ^= 1; | ||
buffer[x + (y * width)] ^= 1; | ||
} | ||
@@ -242,6 +201,6 @@ } | ||
case 1: | ||
for (let y = 0; y < width; y++) { | ||
for (let x = 0; x < width; x++) { | ||
for (y = 0; y < width; y++) { | ||
for (x = 0; x < width; x++) { | ||
if (!(y & 1) && !this._isMasked(x, y)) { | ||
this.buffer[x + (y * width)] ^= 1; | ||
buffer[x + (y * width)] ^= 1; | ||
} | ||
@@ -253,4 +212,4 @@ } | ||
case 2: | ||
for (let y = 0; y < width; y++) { | ||
for (let r3x = 0, x = 0; x < width; x++, r3x++) { | ||
for (y = 0; y < width; y++) { | ||
for (r3x = 0, x = 0; x < width; x++, r3x++) { | ||
if (r3x === 3) { | ||
@@ -261,3 +220,3 @@ r3x = 0; | ||
if (!r3x && !this._isMasked(x, y)) { | ||
this.buffer[x + (y * width)] ^= 1; | ||
buffer[x + (y * width)] ^= 1; | ||
} | ||
@@ -269,3 +228,3 @@ } | ||
case 3: | ||
for (let r3y = 0, y = 0; y < width; y++, r3y++) { | ||
for (r3y = 0, y = 0; y < width; y++, r3y++) { | ||
if (r3y === 3) { | ||
@@ -275,3 +234,3 @@ r3y = 0; | ||
for (let r3x = r3y, x = 0; x < width; x++, r3x++) { | ||
for (r3x = r3y, x = 0; x < width; x++, r3x++) { | ||
if (r3x === 3) { | ||
@@ -282,3 +241,3 @@ r3x = 0; | ||
if (!r3x && !this._isMasked(x, y)) { | ||
this.buffer[x + (y * width)] ^= 1; | ||
buffer[x + (y * width)] ^= 1; | ||
} | ||
@@ -290,4 +249,4 @@ } | ||
case 4: | ||
for (let y = 0; y < width; y++) { | ||
for (let r3x = 0, r3y = (y >> 1) & 1, x = 0; x < width; x++, r3x++) { | ||
for (y = 0; y < width; y++) { | ||
for (r3x = 0, r3y = (y >> 1) & 1, x = 0; x < width; x++, r3x++) { | ||
if (r3x === 3) { | ||
@@ -299,3 +258,3 @@ r3x = 0; | ||
if (!r3y && !this._isMasked(x, y)) { | ||
this.buffer[x + (y * width)] ^= 1; | ||
buffer[x + (y * width)] ^= 1; | ||
} | ||
@@ -307,3 +266,3 @@ } | ||
case 5: | ||
for (let r3y = 0, y = 0; y < width; y++, r3y++) { | ||
for (r3y = 0, y = 0; y < width; y++, r3y++) { | ||
if (r3y === 3) { | ||
@@ -313,3 +272,3 @@ r3y = 0; | ||
for (let r3x = 0, x = 0; x < width; x++, r3x++) { | ||
for (r3x = 0, x = 0; x < width; x++, r3x++) { | ||
if (r3x === 3) { | ||
@@ -320,3 +279,3 @@ r3x = 0; | ||
if (!((x & y & 1) + !(!r3x | !r3y)) && !this._isMasked(x, y)) { | ||
this.buffer[x + (y * width)] ^= 1; | ||
buffer[x + (y * width)] ^= 1; | ||
} | ||
@@ -328,3 +287,3 @@ } | ||
case 6: | ||
for (let r3y = 0, y = 0; y < width; y++, r3y++) { | ||
for (r3y = 0, y = 0; y < width; y++, r3y++) { | ||
if (r3y === 3) { | ||
@@ -334,3 +293,3 @@ r3y = 0; | ||
for (let r3x = 0, x = 0; x < width; x++, r3x++) { | ||
for (r3x = 0, x = 0; x < width; x++, r3x++) { | ||
if (r3x === 3) { | ||
@@ -341,3 +300,3 @@ r3x = 0; | ||
if (!((x & y & 1) + (r3x && r3x === r3y) & 1) && !this._isMasked(x, y)) { | ||
this.buffer[x + (y * width)] ^= 1; | ||
buffer[x + (y * width)] ^= 1; | ||
} | ||
@@ -349,3 +308,3 @@ } | ||
case 7: | ||
for (let r3y = 0, y = 0; y < width; y++, r3y++) { | ||
for (r3y = 0, y = 0; y < width; y++, r3y++) { | ||
if (r3y === 3) { | ||
@@ -355,3 +314,3 @@ r3y = 0; | ||
for (let r3x = 0, x = 0; x < width; x++, r3x++) { | ||
for (r3x = 0, x = 0; x < width; x++, r3x++) { | ||
if (r3x === 3) { | ||
@@ -362,3 +321,3 @@ r3x = 0; | ||
if (!((r3x && r3x === r3y) + (x + y & 1) & 1) && !this._isMasked(x, y)) { | ||
this.buffer[x + (y * width)] ^= 1; | ||
buffer[x + (y * width)] ^= 1; | ||
} | ||
@@ -370,45 +329,52 @@ } | ||
} | ||
} | ||
}, | ||
_calculateMaxLength() { | ||
_calculateMaxLength: function() { | ||
return (this._dataBlock * (this._neccBlock1 + this._neccBlock2)) + this._neccBlock2; | ||
} | ||
}, | ||
_calculatePolynomial() { | ||
this._polynomial[0] = 1; | ||
_calculatePolynomial: function() { | ||
var i, j; | ||
var eccBlock = this._eccBlock; | ||
var polynomial = this._polynomial; | ||
for (let i = 0; i < this._eccBlock; i++) { | ||
this._polynomial[i + 1] = 1; | ||
polynomial[0] = 1; | ||
for (let j = i; j > 0; j--) { | ||
this._polynomial[j] = this._polynomial[j] ? this._polynomial[j - 1] ^ | ||
Galois.EXPONENT[Frame._modN(Galois.LOG[this._polynomial[j]] + i)] : this._polynomial[j - 1]; | ||
for (i = 0; i < eccBlock; i++) { | ||
polynomial[i + 1] = 1; | ||
for (j = i; j > 0; j--) { | ||
polynomial[j] = polynomial[j] ? polynomial[j - 1] ^ | ||
Galois.EXPONENT[Frame._modN(Galois.LOG[polynomial[j]] + i)] : polynomial[j - 1]; | ||
} | ||
this._polynomial[0] = Galois.EXPONENT[Frame._modN(Galois.LOG[this._polynomial[0]] + i)]; | ||
polynomial[0] = Galois.EXPONENT[Frame._modN(Galois.LOG[polynomial[0]] + i)]; | ||
} | ||
// Use logs for generator polynomial to save calculation step. | ||
for (let i = 0; i <= this._eccBlock; i++) { | ||
this._polynomial[i] = Galois.LOG[this._polynomial[i]]; | ||
for (i = 0; i <= eccBlock; i++) { | ||
polynomial[i] = Galois.LOG[polynomial[i]]; | ||
} | ||
} | ||
}, | ||
_checkBadness() { | ||
let bad = 0; | ||
const width = this.width; | ||
_checkBadness: function() { | ||
var b, b1, h, x, y; | ||
var bad = 0; | ||
var badness = this._badness; | ||
var buffer = this.buffer; | ||
var width = this.width; | ||
// Blocks of same colour. | ||
for (let y = 0; y < width - 1; y++) { | ||
for (let x = 0; x < width - 1; x++) { | ||
for (y = 0; y < width - 1; y++) { | ||
for (x = 0; x < width - 1; x++) { | ||
// All foreground colour. | ||
if ((this.buffer[x + (width * y)] && | ||
this.buffer[x + 1 + (width * y)] && | ||
this.buffer[x + (width * (y + 1))] && | ||
this.buffer[x + 1 + (width * (y + 1))]) || | ||
if ((buffer[x + (width * y)] && | ||
buffer[x + 1 + (width * y)] && | ||
buffer[x + (width * (y + 1))] && | ||
buffer[x + 1 + (width * (y + 1))]) || | ||
// All background colour. | ||
!(this.buffer[x + (width * y)] || | ||
this.buffer[x + 1 + (width * y)] || | ||
this.buffer[x + (width * (y + 1))] || | ||
this.buffer[x + 1 + (width * (y + 1))])) { | ||
!(buffer[x + (width * y)] || | ||
buffer[x + 1 + (width * y)] || | ||
buffer[x + (width * (y + 1))] || | ||
buffer[x + 1 + (width * (y + 1))])) { | ||
bad += Frame.N2; | ||
@@ -419,17 +385,17 @@ } | ||
let bw = 0; | ||
var bw = 0; | ||
// X runs. | ||
for (let y = 0; y < width; y++) { | ||
let h = 0; | ||
for (y = 0; y < width; y++) { | ||
h = 0; | ||
this._badness[0] = 0; | ||
badness[0] = 0; | ||
for (let b = 0, x = 0; x < width; x++) { | ||
const b1 = this.buffer[x + (width * y)]; | ||
for (b = 0, x = 0; x < width; x++) { | ||
b1 = buffer[x + (width * y)]; | ||
if (b === b1) { | ||
this._badness[h]++; | ||
badness[h]++; | ||
} else { | ||
this._badness[++h] = 1; | ||
badness[++h] = 1; | ||
} | ||
@@ -448,4 +414,4 @@ | ||
let count = 0; | ||
let big = bw; | ||
var count = 0; | ||
var big = bw; | ||
big += big << 2; | ||
@@ -462,14 +428,14 @@ big <<= 1; | ||
// Y runs. | ||
for (let x = 0; x < width; x++) { | ||
let h = 0; | ||
for (x = 0; x < width; x++) { | ||
h = 0; | ||
this._badness[0] = 0; | ||
badness[0] = 0; | ||
for (let b = 0, y = 0; y < width; y++) { | ||
const b1 = this.buffer[x + (width * y)]; | ||
for (b = 0, y = 0; y < width; y++) { | ||
b1 = buffer[x + (width * y)]; | ||
if (b === b1) { | ||
this._badness[h]++; | ||
badness[h]++; | ||
} else { | ||
this._badness[++h] = 1; | ||
badness[++h] = 1; | ||
} | ||
@@ -484,18 +450,21 @@ | ||
return bad; | ||
} | ||
}, | ||
_convertBitStream(length) { | ||
_convertBitStream: function(length) { | ||
var bit, i; | ||
var ecc = this._ecc; | ||
var version = this._version; | ||
// Convert string to bit stream. 8-bit data to QR-coded 8-bit data (numeric, alphanumeric, or kanji not supported). | ||
for (let i = 0; i < length; i++) { | ||
this._ecc[i] = this._value.charCodeAt(i); | ||
for (i = 0; i < length; i++) { | ||
ecc[i] = this._value.charCodeAt(i); | ||
} | ||
this._stringBuffer = this._ecc.slice(0); | ||
var stringBuffer = this._stringBuffer = ecc.slice(); | ||
var maxLength = this._calculateMaxLength(); | ||
const maxLength = this._calculateMaxLength(); | ||
if (length >= maxLength - 2) { | ||
length = maxLength - 2; | ||
if (this._version > 9) { | ||
if (version > 9) { | ||
length--; | ||
@@ -506,48 +475,50 @@ } | ||
// Shift and re-pack to insert length prefix. | ||
let index = length; | ||
var index = length; | ||
if (this._version > 9) { | ||
this._stringBuffer[index + 2] = 0; | ||
this._stringBuffer[index + 3] = 0; | ||
if (version > 9) { | ||
stringBuffer[index + 2] = 0; | ||
stringBuffer[index + 3] = 0; | ||
while (index--) { | ||
const bit = this._stringBuffer[index]; | ||
bit = stringBuffer[index]; | ||
this._stringBuffer[index + 3] |= 255 & (bit << 4); | ||
this._stringBuffer[index + 2] = bit >> 4; | ||
stringBuffer[index + 3] |= 255 & (bit << 4); | ||
stringBuffer[index + 2] = bit >> 4; | ||
} | ||
this._stringBuffer[2] |= 255 & (length << 4); | ||
this._stringBuffer[1] = length >> 4; | ||
this._stringBuffer[0] = 0x40 | (length >> 12); | ||
stringBuffer[2] |= 255 & (length << 4); | ||
stringBuffer[1] = length >> 4; | ||
stringBuffer[0] = 0x40 | (length >> 12); | ||
} else { | ||
this._stringBuffer[index + 1] = 0; | ||
this._stringBuffer[index + 2] = 0; | ||
stringBuffer[index + 1] = 0; | ||
stringBuffer[index + 2] = 0; | ||
while (index--) { | ||
const bit = this._stringBuffer[index]; | ||
bit = stringBuffer[index]; | ||
this._stringBuffer[index + 2] |= 255 & (bit << 4); | ||
this._stringBuffer[index + 1] = bit >> 4; | ||
stringBuffer[index + 2] |= 255 & (bit << 4); | ||
stringBuffer[index + 1] = bit >> 4; | ||
} | ||
this._stringBuffer[1] |= 255 & (length << 4); | ||
this._stringBuffer[0] = 0x40 | (length >> 4); | ||
stringBuffer[1] |= 255 & (length << 4); | ||
stringBuffer[0] = 0x40 | (length >> 4); | ||
} | ||
// Fill to end with pad pattern. | ||
index = length + 3 - (this._version < 10); | ||
index = length + 3 - (version < 10); | ||
while (index < maxLength) { | ||
this._stringBuffer[index++] = 0xec; | ||
this._stringBuffer[index++] = 0x11; | ||
stringBuffer[index++] = 0xec; | ||
stringBuffer[index++] = 0x11; | ||
} | ||
} | ||
}, | ||
_getBadness(length) { | ||
let badRuns = 0; | ||
_getBadness: function(length) { | ||
var i; | ||
var badRuns = 0; | ||
var badness = this._badness; | ||
for (let i = 0; i <= length; i++) { | ||
if (this._badness[i] >= 5) { | ||
badRuns += Frame.N1 + this._badness[i] - 5; | ||
for (i = 0; i <= length; i++) { | ||
if (badness[i] >= 5) { | ||
badRuns += Frame.N1 + badness[i] - 5; | ||
} | ||
@@ -557,11 +528,11 @@ } | ||
// FBFFFBF as in finder. | ||
for (let i = 3; i < length - 1; i += 2) { | ||
if (this._badness[i - 2] === this._badness[i + 2] && | ||
this._badness[i + 2] === this._badness[i - 1] && | ||
this._badness[i - 1] === this._badness[i + 1] && | ||
this._badness[i - 1] * 3 === this._badness[i] && | ||
for (i = 3; i < length - 1; i += 2) { | ||
if (badness[i - 2] === badness[i + 2] && | ||
badness[i + 2] === badness[i - 1] && | ||
badness[i - 1] === badness[i + 1] && | ||
badness[i - 1] * 3 === badness[i] && | ||
// Background around the foreground pattern? Not part of the specs. | ||
(this._badness[i - 3] === 0 || i + 3 > length || | ||
this._badness[i - 3] * 3 >= this._badness[i] * 4 || | ||
this._badness[i + 3] * 3 >= this._badness[i] * 4)) { | ||
(badness[i - 3] === 0 || i + 3 > length || | ||
badness[i - 3] * 3 >= badness[i] * 4 || | ||
badness[i + 3] * 3 >= badness[i] * 4)) { | ||
badRuns += Frame.N3; | ||
@@ -572,11 +543,11 @@ } | ||
return badRuns; | ||
} | ||
}, | ||
_finish() { | ||
_finish: function() { | ||
// Save pre-mask copy of frame. | ||
this._stringBuffer = this.buffer.slice(0); | ||
this._stringBuffer = this.buffer.slice(); | ||
let bit = 0; | ||
let i; | ||
let mask = 30000; | ||
var currentMask, i; | ||
var bit = 0; | ||
var mask = 30000; | ||
@@ -591,3 +562,3 @@ /* | ||
const currentMask = this._checkBadness(); | ||
currentMask = this._checkBadness(); | ||
@@ -606,3 +577,3 @@ // Is current mask better than previous best? | ||
// Reset for next pass. | ||
this.buffer = this._stringBuffer.slice(0); | ||
this.buffer = this._stringBuffer.slice(); | ||
} | ||
@@ -618,11 +589,14 @@ | ||
var buffer = this.buffer; | ||
var width = this.width; | ||
// Low byte. | ||
for (i = 0; i < 8; i++, mask >>= 1) { | ||
if (mask & 1) { | ||
this.buffer[this.width - 1 - i + (this.width * 8)] = 1; | ||
buffer[width - 1 - i + (width * 8)] = 1; | ||
if (i < 6) { | ||
this.buffer[8 + (this.width * i)] = 1; | ||
buffer[8 + (width * i)] = 1; | ||
} else { | ||
this.buffer[8 + (this.width * (i + 1))] = 1; | ||
buffer[8 + (width * (i + 1))] = 1; | ||
} | ||
@@ -635,50 +609,58 @@ } | ||
if (mask & 1) { | ||
this.buffer[8 + (this.width * (this.width - 7 + i))] = 1; | ||
buffer[8 + (width * (width - 7 + i))] = 1; | ||
if (i) { | ||
this.buffer[6 - i + (this.width * 8)] = 1; | ||
buffer[6 - i + (width * 8)] = 1; | ||
} else { | ||
this.buffer[7 + (this.width * 8)] = 1; | ||
buffer[7 + (width * 8)] = 1; | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
_interleaveBlocks() { | ||
const maxLength = this._calculateMaxLength(); | ||
let i; | ||
let k = 0; | ||
_interleaveBlocks: function() { | ||
var i, j; | ||
var dataBlock = this._dataBlock; | ||
var ecc = this._ecc; | ||
var eccBlock = this._eccBlock; | ||
var k = 0; | ||
var maxLength = this._calculateMaxLength(); | ||
var neccBlock1 = this._neccBlock1; | ||
var neccBlock2 = this._neccBlock2; | ||
var stringBuffer = this._stringBuffer; | ||
for (i = 0; i < this._dataBlock; i++) { | ||
for (let j = 0; j < this._neccBlock1; j++) { | ||
this._ecc[k++] = this._stringBuffer[i + (j * this._dataBlock)]; | ||
for (i = 0; i < dataBlock; i++) { | ||
for (j = 0; j < neccBlock1; j++) { | ||
ecc[k++] = stringBuffer[i + (j * dataBlock)]; | ||
} | ||
for (let j = 0; j < this._neccBlock2; j++) { | ||
this._ecc[k++] = this._stringBuffer[(this._neccBlock1 * this._dataBlock) + i + (j * (this._dataBlock + 1))]; | ||
for (j = 0; j < neccBlock2; j++) { | ||
ecc[k++] = stringBuffer[(neccBlock1 * dataBlock) + i + (j * (dataBlock + 1))]; | ||
} | ||
} | ||
for (let j = 0; j < this._neccBlock2; j++) { | ||
this._ecc[k++] = this._stringBuffer[(this._neccBlock1 * this._dataBlock) + i + (j * (this._dataBlock + 1))]; | ||
for (j = 0; j < neccBlock2; j++) { | ||
ecc[k++] = stringBuffer[(neccBlock1 * dataBlock) + i + (j * (dataBlock + 1))]; | ||
} | ||
for (i = 0; i < this._eccBlock; i++) { | ||
for (let j = 0; j < this._neccBlock1 + this._neccBlock2; j++) { | ||
this._ecc[k++] = this._stringBuffer[maxLength + i + (j * this._eccBlock)]; | ||
for (i = 0; i < eccBlock; i++) { | ||
for (j = 0; j < neccBlock1 + neccBlock2; j++) { | ||
ecc[k++] = stringBuffer[maxLength + i + (j * eccBlock)]; | ||
} | ||
} | ||
this._stringBuffer = this._ecc; | ||
} | ||
this._stringBuffer = ecc; | ||
}, | ||
_insertAlignments() { | ||
const width = this.width; | ||
_insertAlignments: function() { | ||
var i, x, y; | ||
var version = this._version; | ||
var width = this.width; | ||
if (this._version > 1) { | ||
const i = Alignment.BLOCK[this._version]; | ||
let y = width - 7; | ||
if (version > 1) { | ||
i = Alignment.BLOCK[version]; | ||
y = width - 7; | ||
for (;;) { | ||
let x = width - 7; | ||
x = width - 7; | ||
@@ -705,10 +687,12 @@ while (x > i - 3) { | ||
} | ||
} | ||
}, | ||
_insertFinders() { | ||
const width = this.width; | ||
_insertFinders: function() { | ||
var i, j, x, y; | ||
var buffer = this.buffer; | ||
var width = this.width; | ||
for (let i = 0; i < 3; i++) { | ||
let j = 0; | ||
let y = 0; | ||
for (i = 0; i < 3; i++) { | ||
j = 0; | ||
y = 0; | ||
@@ -722,12 +706,12 @@ if (i === 1) { | ||
this.buffer[y + 3 + (width * (j + 3))] = 1; | ||
buffer[y + 3 + (width * (j + 3))] = 1; | ||
for (let x = 0; x < 6; x++) { | ||
this.buffer[y + x + (width * j)] = 1; | ||
this.buffer[y + (width * (j + x + 1))] = 1; | ||
this.buffer[y + 6 + (width * (j + x))] = 1; | ||
this.buffer[y + x + 1 + (width * (j + 6))] = 1; | ||
for (x = 0; x < 6; x++) { | ||
buffer[y + x + (width * j)] = 1; | ||
buffer[y + (width * (j + x + 1))] = 1; | ||
buffer[y + 6 + (width * (j + x))] = 1; | ||
buffer[y + x + 1 + (width * (j + 6))] = 1; | ||
} | ||
for (let x = 1; x < 5; x++) { | ||
for (x = 1; x < 5; x++) { | ||
this._setMask(y + x, j + 1); | ||
@@ -739,15 +723,16 @@ this._setMask(y + 1, j + x + 1); | ||
for (let x = 2; x < 4; x++) { | ||
this.buffer[y + x + (width * (j + 2))] = 1; | ||
this.buffer[y + 2 + (width * (j + x + 1))] = 1; | ||
this.buffer[y + 4 + (width * (j + x))] = 1; | ||
this.buffer[y + x + 1 + (width * (j + 4))] = 1; | ||
for (x = 2; x < 4; x++) { | ||
buffer[y + x + (width * (j + 2))] = 1; | ||
buffer[y + 2 + (width * (j + x + 1))] = 1; | ||
buffer[y + 4 + (width * (j + x))] = 1; | ||
buffer[y + x + 1 + (width * (j + 4))] = 1; | ||
} | ||
} | ||
} | ||
}, | ||
_insertTimingGap() { | ||
const width = this.width; | ||
_insertTimingGap: function() { | ||
var x, y; | ||
var width = this.width; | ||
for (let y = 0; y < 7; y++) { | ||
for (y = 0; y < 7; y++) { | ||
this._setMask(7, y); | ||
@@ -758,3 +743,3 @@ this._setMask(width - 8, y); | ||
for (let x = 0; x < 8; x++) { | ||
for (x = 0; x < 8; x++) { | ||
this._setMask(x, 7); | ||
@@ -764,8 +749,10 @@ this._setMask(x + width - 8, 7); | ||
} | ||
} | ||
}, | ||
_insertTimingRowAndColumn() { | ||
const width = this.width; | ||
_insertTimingRowAndColumn: function() { | ||
var x; | ||
var buffer = this.buffer; | ||
var width = this.width; | ||
for (let x = 0; x < width - 14; x++) { | ||
for (x = 0; x < width - 14; x++) { | ||
if (x & 1) { | ||
@@ -775,20 +762,23 @@ this._setMask(8 + x, 6); | ||
} else { | ||
this.buffer[8 + x + (width * 6)] = 1; | ||
this.buffer[6 + (width * (8 + x))] = 1; | ||
buffer[8 + x + (width * 6)] = 1; | ||
buffer[6 + (width * (8 + x))] = 1; | ||
} | ||
} | ||
} | ||
}, | ||
_insertVersion() { | ||
const width = this.width; | ||
_insertVersion: function() { | ||
var i, j, x, y; | ||
var buffer = this.buffer; | ||
var version = this._version; | ||
var width = this.width; | ||
if (this._version > 6) { | ||
const i = Version.BLOCK[this._version - 7]; | ||
let j = 17; | ||
if (version > 6) { | ||
i = Version.BLOCK[version - 7]; | ||
j = 17; | ||
for (let x = 0; x < 6; x++) { | ||
for (let y = 0; y < 3; y++, j--) { | ||
if (1 & (j > 11 ? this._version >> j - 12 : i >> j)) { | ||
this.buffer[5 - x + (width * (2 - y + width - 11))] = 1; | ||
this.buffer[2 - y + width - 11 + (width * (5 - x))] = 1; | ||
for (x = 0; x < 6; x++) { | ||
for (y = 0; y < 3; y++, j--) { | ||
if (1 & (j > 11 ? version >> j - 12 : i >> j)) { | ||
buffer[5 - x + (width * (2 - y + width - 11))] = 1; | ||
buffer[2 - y + width - 11 + (width * (5 - x))] = 1; | ||
} else { | ||
@@ -801,25 +791,27 @@ this._setMask(5 - x, 2 - y + width - 11); | ||
} | ||
} | ||
}, | ||
_isMasked(x, y) { | ||
const bit = Frame._getMaskBit(x, y); | ||
_isMasked: function(x, y) { | ||
var bit = Frame._getMaskBit(x, y); | ||
return this._mask[bit] === 1; | ||
} | ||
}, | ||
_pack() { | ||
let x = this.width - 1; | ||
let y = this.width - 1; | ||
let k = 1; | ||
let v = 1; | ||
_pack: function() { | ||
var bit, i, j; | ||
var k = 1; | ||
var v = 1; | ||
var width = this.width; | ||
var x = width - 1; | ||
var y = width - 1; | ||
// Interleaved data and ECC codes. | ||
const length = ((this._dataBlock + this._eccBlock) * (this._neccBlock1 + this._neccBlock2)) + this._neccBlock2; | ||
var length = ((this._dataBlock + this._eccBlock) * (this._neccBlock1 + this._neccBlock2)) + this._neccBlock2; | ||
for (let i = 0; i < length; i++) { | ||
let bit = this._stringBuffer[i]; | ||
for (i = 0; i < length; i++) { | ||
bit = this._stringBuffer[i]; | ||
for (let j = 0; j < 8; j++, bit <<= 1) { | ||
for (j = 0; j < 8; j++, bit <<= 1) { | ||
if (0x80 & bit) { | ||
this.buffer[x + (this.width * y)] = 1; | ||
this.buffer[x + (width * y)] = 1; | ||
} | ||
@@ -846,3 +838,3 @@ | ||
} | ||
} else if (y !== this.width - 1) { | ||
} else if (y !== width - 1) { | ||
y++; | ||
@@ -864,12 +856,13 @@ } else { | ||
} | ||
} | ||
}, | ||
_reverseMask() { | ||
const width = this.width; | ||
_reverseMask: function() { | ||
var x, y; | ||
var width = this.width; | ||
for (let x = 0; x < 9; x++) { | ||
for (x = 0; x < 9; x++) { | ||
this._setMask(x, 8); | ||
} | ||
for (let x = 0; x < 8; x++) { | ||
for (x = 0; x < 8; x++) { | ||
this._setMask(x + width - 8, 8); | ||
@@ -879,18 +872,19 @@ this._setMask(8, x); | ||
for (let y = 0; y < 7; y++) { | ||
for (y = 0; y < 7; y++) { | ||
this._setMask(8, y + width - 7); | ||
} | ||
} | ||
}, | ||
_setMask(x, y) { | ||
const bit = Frame._getMaskBit(x, y); | ||
_setMask: function(x, y) { | ||
var bit = Frame._getMaskBit(x, y); | ||
this._mask[bit] = 1; | ||
} | ||
}, | ||
_syncMask() { | ||
const width = this.width; | ||
_syncMask: function() { | ||
var x, y; | ||
var width = this.width; | ||
for (let y = 0; y < width; y++) { | ||
for (let x = 0; x <= y; x++) { | ||
for (y = 0; y < width; y++) { | ||
for (x = 0; x <= y; x++) { | ||
if (this.buffer[x + (width * y)]) { | ||
@@ -903,6 +897,51 @@ this._setMask(x, y); | ||
} | ||
}, { | ||
export default Frame; | ||
_createArray: function(length) { | ||
var i; | ||
var array = []; | ||
for (i = 0; i < length; i++) { | ||
array[i] = 0; | ||
} | ||
return array; | ||
}, | ||
_getMaskBit: function(x, y) { | ||
var bit; | ||
if (x > y) { | ||
bit = x; | ||
x = y; | ||
y = bit; | ||
} | ||
bit = y; | ||
bit += y * y; | ||
bit >>= 1; | ||
bit += x; | ||
return bit; | ||
}, | ||
_modN: function(x) { | ||
while (x >= 255) { | ||
x -= 255; | ||
x = (x >> 8) + (x & 255); | ||
} | ||
return x; | ||
}, | ||
// *Badness* coefficients. | ||
N1: 3, | ||
N2: 3, | ||
N3: 40, | ||
N4: 10 | ||
}); | ||
module.exports = Frame; | ||
/** | ||
@@ -909,0 +948,0 @@ * The options used by {@link Frame}. |
@@ -20,2 +20,6 @@ /* | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
@@ -25,63 +29,63 @@ * Contains Galois field information. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class Galois { | ||
var Galois = Nevis.extend(null, { | ||
/** | ||
* Returns the Galois field exponent table. | ||
* The Galois field exponent table. | ||
* | ||
* @return {number[]} The Galois field exponent table. | ||
* @public | ||
* @static | ||
* @type {number[]} | ||
* @memberof Galois | ||
*/ | ||
static get EXPONENT() { | ||
return [ | ||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26, | ||
0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9, 0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, | ||
0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35, 0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23, | ||
0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1, | ||
0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc, 0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0, | ||
0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f, 0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2, | ||
0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88, 0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce, | ||
0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93, 0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc, | ||
0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9, 0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54, | ||
0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa, 0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73, | ||
0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e, 0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff, | ||
0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4, 0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41, | ||
0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6, | ||
0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef, 0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09, | ||
0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5, 0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16, | ||
0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83, 0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x00 | ||
]; | ||
} | ||
EXPONENT: [ | ||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26, | ||
0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9, 0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, | ||
0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35, 0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23, | ||
0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1, | ||
0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc, 0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0, | ||
0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f, 0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2, | ||
0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88, 0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce, | ||
0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93, 0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc, | ||
0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9, 0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54, | ||
0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa, 0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73, | ||
0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e, 0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff, | ||
0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4, 0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41, | ||
0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6, | ||
0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef, 0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09, | ||
0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5, 0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16, | ||
0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83, 0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x00 | ||
], | ||
/** | ||
* Returns the Galois field log table. | ||
* The Galois field log table. | ||
* | ||
* @return {number[]} The Galois field log table. | ||
* @public | ||
* @static | ||
* @type {number[]} | ||
* @memberof Galois | ||
*/ | ||
static get LOG() { | ||
return [ | ||
0xff, 0x00, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6, 0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b, | ||
0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81, 0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71, | ||
0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21, 0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45, | ||
0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9, 0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6, | ||
0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd, 0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88, | ||
0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd, 0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40, | ||
0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e, 0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d, | ||
0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b, 0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57, | ||
0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d, 0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18, | ||
0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c, 0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e, | ||
0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd, 0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61, | ||
0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e, 0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2, | ||
0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76, 0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6, | ||
0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa, 0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a, | ||
0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51, 0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7, | ||
0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8, 0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf | ||
]; | ||
} | ||
LOG: [ | ||
0xff, 0x00, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6, 0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b, | ||
0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81, 0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71, | ||
0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21, 0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45, | ||
0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9, 0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6, | ||
0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd, 0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88, | ||
0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd, 0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40, | ||
0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e, 0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d, | ||
0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b, 0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57, | ||
0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d, 0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18, | ||
0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c, 0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e, | ||
0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd, 0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61, | ||
0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e, 0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2, | ||
0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76, 0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6, | ||
0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa, 0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a, | ||
0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51, 0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7, | ||
0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8, 0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf | ||
] | ||
} | ||
}); | ||
export default Galois; | ||
module.exports = Galois; |
@@ -20,36 +20,58 @@ /* | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
* Defines an available option while also configuring how values are applied to the target object. | ||
* | ||
* While a value associated with an option can be changed on the target object, the option definition itself is | ||
* immutable. | ||
* Optionally, a default value can be specified as well a value transformer for greater control over how the option | ||
* value is applied. | ||
* | ||
* If no value transformer is specified, then any specified option will be applied directly. All values are maintained | ||
* on the target object itself as a field using the option name prefixed with a single underscore. | ||
* | ||
* When an option is specified as modifiable, the {@link OptionManager} will be required to include a setter for the | ||
* property that is defined on the target object that uses the option name. | ||
* | ||
* @param {string} name - the name to be used | ||
* @param {boolean} [modifiable] - <code>true</code> if the property defined on target objects should include a setter; | ||
* otherwise <code>false</code> | ||
* @param {*} [defaultValue] - the default value to be used | ||
* @param {Option~ValueTransformer} [valueTransformer] - the value transformer to be used | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class Option { | ||
var Option = Nevis.extend(function(name, modifiable, defaultValue, valueTransformer) { | ||
/** | ||
* The name for this {@link Option}. | ||
* | ||
* @public | ||
* @type {string} | ||
* @memberof Option# | ||
*/ | ||
this.name = name; | ||
/** | ||
* Creates a new instance of {@link Option} based on the <code>name</code> provided. | ||
* Whether a setter should be included on the property defined on target objects for this {@link Option}. | ||
* | ||
* Optionally, a <code>defaultValue</code> can be specified as well a <code>valueTransformer</code> and | ||
* <code>fieldNameResolver</code> for greater control over how the option value is applied. | ||
* @public | ||
* @type {boolean} | ||
* @memberof Option# | ||
*/ | ||
this.modifiable = Boolean(modifiable); | ||
/** | ||
* The default value for this {@link Option}. | ||
* | ||
* If no <code>valueTransformer</code> is specified, then any specified option will be applied directly. | ||
* | ||
* If no <code>fieldNameResolver</code> is specified, then the field name will be resolved to <code>name</code> | ||
* prefixed with a single underscore when the option is applied. | ||
* | ||
* @param {string} name - the name to be used | ||
* @param {*} [defaultValue] - the default value to be used | ||
* @param {Option~ValueTransformer} [valueTransformer] - the value transformer to be used | ||
* @param {Option~FieldNameResolver} [fieldNameResolver] - the field name resolver to be used | ||
* @public | ||
* @type {*} | ||
* @memberof Option# | ||
*/ | ||
constructor(name, defaultValue, valueTransformer, fieldNameResolver) { | ||
this._name = name; | ||
this._defaultValue = defaultValue; | ||
this._valueTransformer = valueTransformer; | ||
this._fieldName = typeof fieldNameResolver === 'function' ? fieldNameResolver(this) : `_${name}`; | ||
} | ||
this.defaultValue = defaultValue; | ||
this._valueTransformer = valueTransformer; | ||
}, { | ||
/** | ||
@@ -64,5 +86,6 @@ * Transforms the specified <code>value</code> so that it can be applied for this {@link Option}. | ||
* @public | ||
* @memberof Option# | ||
*/ | ||
transform(value) { | ||
const transformer = this._valueTransformer; | ||
transform: function(value) { | ||
var transformer = this._valueTransformer; | ||
if (typeof transformer === 'function') { | ||
@@ -75,50 +98,7 @@ return transformer(value, this); | ||
/** | ||
* Returns the field name for this {@link Option}. | ||
* | ||
* @return {string} The field name. | ||
* @public | ||
*/ | ||
get fieldName() { | ||
return this._fieldName; | ||
} | ||
}); | ||
/** | ||
* Returns the name for this {@link Option}. | ||
* | ||
* @return {string} The name. | ||
* @public | ||
*/ | ||
get name() { | ||
return this._name; | ||
} | ||
module.exports = Option; | ||
/** | ||
* Returns the default value for this {@link Option}. | ||
* | ||
* @return {*} The default value. | ||
* @public | ||
*/ | ||
get defaultValue() { | ||
return this._defaultValue; | ||
} | ||
} | ||
export default Option; | ||
/** | ||
* Returns the field name to which the specified <code>option</code> is associated on the target object. | ||
* | ||
* The resolved name will be used to identify the field that values for <code>option</code> are to be read from and | ||
* written to. | ||
* | ||
* This function will only called once for <code>option</code>, upon initialization. | ||
* | ||
* @callback Option~FieldNameResolver | ||
* @param {Option} option - the {@link Option} whose field name is to be resolved | ||
* @return {string} The resolved field name for <code>option</code>. | ||
*/ | ||
/** | ||
* Returns a transformed value for the specified <code>value</code> to be applied for the <code>option</code> provided. | ||
@@ -125,0 +105,0 @@ * |
@@ -20,4 +20,8 @@ /* | ||
import Utilities from '../util/Utilities'; | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
var Utilities = require('../util/Utilities'); | ||
/** | ||
@@ -28,57 +32,23 @@ * Manages multiple {@link Option} instances that are intended to be used by multiple implementations. | ||
* | ||
* While a value associated with each option can be changed on the target objects, the manager and the option | ||
* definitions themselves are immutable. | ||
* | ||
* @param {Option[]} options - the options to be used | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class OptionManager { | ||
static _get(option, target) { | ||
return target[option.fieldName]; | ||
} | ||
static _set(option, value, target) { | ||
const fieldName = option.fieldName; | ||
const oldValue = target[fieldName]; | ||
const newValue = option.transform(value != null ? value : option.defaultValue); | ||
target[fieldName] = newValue; | ||
return newValue !== oldValue; | ||
} | ||
var OptionManager = Nevis.extend(function(options) { | ||
/** | ||
* Creates a new instance of {@link OptionManager} for the specified available <code>options</code>. | ||
* The available options for this {@link OptionManager}. | ||
* | ||
* @param {Option[]} options - the options to be used | ||
* @public | ||
* @type {Object.<string, Option>} | ||
* @memberof OptionManager# | ||
*/ | ||
constructor(options) { | ||
this._options = {}; | ||
this.options = {}; | ||
options.forEach((option) => { | ||
this._options[option.name] = option; | ||
}); | ||
} | ||
options.forEach(function(option) { | ||
this.options[option.name] = option; | ||
}, this); | ||
}, { | ||
/** | ||
* Sets the default values for all of the available options on the <code>target</code> object provided. | ||
* | ||
* @param {Object} target - the object on which the default values are to be set for each available option | ||
* @return {void} | ||
* @public | ||
*/ | ||
applyDefaults(target) { | ||
const options = this._options; | ||
for (const name in options) { | ||
if (Utilities.hasOwn(options, name)) { | ||
const option = options[name]; | ||
OptionManager._set(option, option.defaultValue, target); | ||
} | ||
} | ||
} | ||
/** | ||
* Returns whether an option with the specified <code>name</code> is available. | ||
@@ -90,6 +60,7 @@ * | ||
* @public | ||
* @memberof OptionManager# | ||
*/ | ||
exists(name) { | ||
return this._options[name] != null; | ||
} | ||
exists: function(name) { | ||
return this.options[name] != null; | ||
}, | ||
@@ -103,6 +74,7 @@ /** | ||
* @public | ||
* @memberof OptionManager# | ||
*/ | ||
get(name, target) { | ||
return OptionManager._get(this._options[name], target); | ||
} | ||
get: function(name, target) { | ||
return OptionManager._get(this.options[name], target); | ||
}, | ||
@@ -115,8 +87,10 @@ /** | ||
* @public | ||
* @memberof OptionManager# | ||
*/ | ||
getAll(target) { | ||
const options = this._options; | ||
const result = {}; | ||
getAll: function(target) { | ||
var name; | ||
var options = this.options; | ||
var result = {}; | ||
for (const name in options) { | ||
for (name in options) { | ||
if (Utilities.hasOwn(options, name)) { | ||
@@ -128,9 +102,52 @@ result[name] = OptionManager._get(options[name], target); | ||
return result; | ||
} | ||
}, | ||
/** | ||
* Initializes the available options for the <code>target</code> object provided and then applies the initial values | ||
* within the speciifed <code>options</code>. | ||
* | ||
* This method will throw an error if any of the names within <code>options</code> does not match an available option. | ||
* | ||
* This involves setting the default values and defining properties for all of the available options on | ||
* <code>target</code> before finally calling {@link OptionMananger#setAll} with <code>options</code> and | ||
* <code>target</code>. Any options that are configured to be modifiable will have a setter included in their defined | ||
* property that will allow its corresponding value to be modified. | ||
* | ||
* If a change handler is specified, it will be called whenever the value changes on <code>target</code> for a | ||
* modifiable option, but only when done so via the defined property's setter. | ||
* | ||
* @param {Object.<string, *>} options - the name/value pairs of the initial options to be set | ||
* @param {Object} target - the object on which the options are to be initialized | ||
* @param {Function} [changeHandler] - the function to be called whenever the value of an modifiable option changes on | ||
* <code>target</code> | ||
* @return {void} | ||
* @throws {Error} If <code>options</code> contains an invalid option name. | ||
* @public | ||
* @memberof OptionManager# | ||
*/ | ||
init: function(options, target, changeHandler) { | ||
if (typeof changeHandler !== 'function') { | ||
changeHandler = Utilities.noop; | ||
} | ||
var name, option; | ||
for (name in this.options) { | ||
if (Utilities.hasOwn(this.options, name)) { | ||
option = this.options[name]; | ||
OptionManager._set(option, option.defaultValue, target); | ||
OptionManager._createAccessor(option, target, changeHandler); | ||
} | ||
} | ||
this._setAll(options, target, true); | ||
}, | ||
/** | ||
* Sets the value of the option with the specified <code>name</code> on the <code>target</code> object provided to | ||
* <code>value</code>. | ||
* | ||
* This method will throw an error if <code>name</code> does not match an available option. | ||
* This method will throw an error if <code>name</code> does not match an available option or matches an option that | ||
* cannot be modified. | ||
* | ||
@@ -148,14 +165,10 @@ * If <code>value</code> is <code>null</code> and the {@link Option} has a default value configured, then that default | ||
* <code>false</code>. | ||
* @throws {Error} If no {@link Option} is being managed with <code>name</code>. | ||
* @throws {Error} If <code>name</code> is invalid or is for an option that cannot be modified. | ||
* @public | ||
* @memberof OptionManager# | ||
*/ | ||
set(name, value, target) { | ||
const option = this._options[name]; | ||
if (!option) { | ||
throw new Error(`Invalid option: ${name}`); | ||
} | ||
set: function(name, value, target) { | ||
return this._set(name, value, target); | ||
}, | ||
return OptionManager._set(option, value, target); | ||
} | ||
/** | ||
@@ -165,3 +178,4 @@ * Sets all of the specified <code>options</code> on the <code>target</code> object provided to their corresponding | ||
* | ||
* This method will throw an error if any of the names within <code>options</code> does not match an available option. | ||
* This method will throw an error if any of the names within <code>options</code> does not match an available option | ||
* or matches an option that cannot be modified. | ||
* | ||
@@ -179,6 +193,23 @@ * If any value within <code>options</code> is <code>null</code> and the corresponding {@link Option} has a default | ||
* <code>false</code>. | ||
* @throws {Error} If no {@link Option} is being managed with for any of the names within <code>options</code>. | ||
* @throws {Error} If <code>options</code> contains an invalid option name or an option that cannot be modiifed. | ||
* @public | ||
* @memberof OptionManager# | ||
*/ | ||
setAll(options, target) { | ||
setAll: function(options, target) { | ||
return this._setAll(options, target); | ||
}, | ||
_set: function(name, value, target, allowUnmodifiable) { | ||
var option = this.options[name]; | ||
if (!option) { | ||
throw new Error('Invalid option: ' + name); | ||
} | ||
if (!option.modifiable && !allowUnmodifiable) { | ||
throw new Error('Option cannot be modified: ' + name); | ||
} | ||
return OptionManager._set(option, value, target); | ||
}, | ||
_setAll: function(options, target, allowUnmodifiable) { | ||
if (!options) { | ||
@@ -188,6 +219,7 @@ return false; | ||
let changed = false; | ||
var name; | ||
var changed = false; | ||
for (const name in options) { | ||
if (Utilities.hasOwn(options, name) && this.set(name, options[name], target)) { | ||
for (name in options) { | ||
if (Utilities.hasOwn(options, name) && this._set(name, options[name], target, allowUnmodifiable)) { | ||
changed = true; | ||
@@ -200,14 +232,48 @@ } | ||
/** | ||
* Returns a copy of the available options for this {@link OptionManager}. | ||
* | ||
* @return {Option[]} The available options. | ||
* @public | ||
*/ | ||
get options() { | ||
return Object.values(this._options); | ||
}, { | ||
_createAccessor: function(option, target, changeHandler) { | ||
var descriptor = { | ||
get: function() { | ||
return OptionManager._get(option, target); | ||
} | ||
}; | ||
if (option.modifiable) { | ||
descriptor.set = function(value) { | ||
if (OptionManager._set(option, value, target)) { | ||
changeHandler(value, option); | ||
} | ||
}; | ||
} | ||
Object.defineProperty(target, option.name, descriptor); | ||
}, | ||
_get: function(option, target) { | ||
return target['_' + option.name]; | ||
}, | ||
_set: function(option, value, target) { | ||
var fieldName = '_' + option.name; | ||
var oldValue = target[fieldName]; | ||
var newValue = option.transform(value != null ? value : option.defaultValue); | ||
target[fieldName] = newValue; | ||
return newValue !== oldValue; | ||
} | ||
} | ||
}); | ||
export default OptionManager; | ||
module.exports = OptionManager; | ||
/** | ||
* Called whenever the value of a modifiable {@link Option} is changed on a target object via the defined property's | ||
* setter. | ||
* | ||
* @callback OptionManager~ChangeHandler | ||
* @param {*} value - the new value for <code>option</code> on the target object | ||
* @param {Option} option - the modifable {@link Option} whose value has changed on the target object. | ||
* @return {void} | ||
*/ |
@@ -20,23 +20,27 @@ /* | ||
import CanvasRenderer from './renderer/CanvasRenderer'; | ||
import Frame from './Frame'; | ||
import ImageRenderer from './renderer/ImageRenderer'; | ||
import Option from './option/Option'; | ||
import OptionManager from './option/OptionManager'; | ||
import ServiceManager from './service/ServiceManager'; | ||
import Utilities from './util/Utilities'; | ||
'use strict'; | ||
const optionManager = new OptionManager([ | ||
new Option('background', 'white'), | ||
new Option('backgroundAlpha', 1, Utilities.abs), | ||
var Nevis = require('nevis/lite'); | ||
var CanvasRenderer = require('./renderer/CanvasRenderer'); | ||
var Frame = require('./Frame'); | ||
var ImageRenderer = require('./renderer/ImageRenderer'); | ||
var Option = require('./option/Option'); | ||
var OptionManager = require('./option/OptionManager'); | ||
var ServiceManager = require('./service/ServiceManager'); | ||
var Utilities = require('./util/Utilities'); | ||
var optionManager = new OptionManager([ | ||
new Option('background', true, 'white'), | ||
new Option('backgroundAlpha', true, 1, Utilities.abs), | ||
new Option('element'), | ||
new Option('foreground', 'black'), | ||
new Option('foregroundAlpha', 1, Utilities.abs), | ||
new Option('level', 'L', Utilities.toUpperCase), | ||
new Option('mime', 'image/png'), | ||
new Option('padding', null, Utilities.abs), | ||
new Option('size', 100, Utilities.abs), | ||
new Option('value', '') | ||
new Option('foreground', true, 'black'), | ||
new Option('foregroundAlpha', true, 1, Utilities.abs), | ||
new Option('level', true, 'L', Utilities.toUpperCase), | ||
new Option('mime', true, 'image/png'), | ||
new Option('padding', true, null, Utilities.abs), | ||
new Option('size', true, 100, Utilities.abs), | ||
new Option('value', true, '') | ||
]); | ||
const serviceManager = new ServiceManager(); | ||
var serviceManager = new ServiceManager(); | ||
@@ -46,71 +50,23 @@ /** | ||
* | ||
* @param {QRious~Options} [options] - the options to be used | ||
* @throws {Error} If any <code>options</code> are invalid. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class QRious { | ||
var QRious = Nevis.extend(function(options) { | ||
optionManager.init(options, this, this.update.bind(this)); | ||
/** | ||
* Returns the default options for {@link QRious}. | ||
* | ||
* @return {QRious~Options} The default options. | ||
* @deprecated Since 2.3.0 | ||
* @public | ||
* @static | ||
*/ | ||
static get DEFAULTS() { | ||
const result = {}; | ||
var element = optionManager.get('element', this); | ||
var elementService = serviceManager.getService('element'); | ||
var canvas = element && elementService.isCanvas(element) ? element : elementService.createCanvas(); | ||
var image = element && elementService.isImage(element) ? element : elementService.createImage(); | ||
optionManager.options.forEach((option) => { | ||
result[option.name] = option.defaultValue; | ||
}); | ||
this._canvasRenderer = new CanvasRenderer(this, canvas, true); | ||
this._imageRenderer = new ImageRenderer(this, image, image === element); | ||
return result; | ||
} | ||
this.update(); | ||
}, { | ||
/** | ||
* Returns the current version of {@link QRious}. | ||
* | ||
* @return {string} The current version. | ||
* @public | ||
* @static | ||
*/ | ||
static get VERSION() { | ||
return '2.3.0'; | ||
} | ||
/** | ||
* Configures the <code>service</code> provided to be used by all {@link QRious} instances. | ||
* | ||
* @param {Service} service - the {@link Service} to be configured | ||
* @return {void} | ||
* @throws {Error} If a {@link Service} has already been configured with the same name. | ||
* @public | ||
* @static | ||
*/ | ||
static use(service) { | ||
serviceManager.setService(service.getName(), service); | ||
} | ||
/** | ||
* Creates a new instance of {@link QRious} based on the <code>options</code> provided. | ||
* | ||
* @param {QRious~Options} [options] - the options to be used | ||
* @throws {Error} If any <code>options</code> are invalid. | ||
* @public | ||
*/ | ||
constructor(options) { | ||
optionManager.applyDefaults(this); | ||
optionManager.setAll(options, this); | ||
const element = optionManager.get('element', this); | ||
const elementService = serviceManager.getService('element'); | ||
const canvas = element && elementService.isCanvas(element) ? element : elementService.createCanvas(); | ||
const image = element && elementService.isImage(element) ? element : elementService.createImage(); | ||
this._canvasRenderer = new CanvasRenderer(this, canvas, true); | ||
this._imageRenderer = new ImageRenderer(this, image, image === element); | ||
this.update(); | ||
} | ||
/** | ||
* Returns all of the options configured for this {@link QRious}. | ||
@@ -123,6 +79,7 @@ * | ||
* @public | ||
* @memberof QRious# | ||
*/ | ||
get() { | ||
get: function() { | ||
return optionManager.getAll(this); | ||
} | ||
}, | ||
@@ -138,10 +95,11 @@ /** | ||
* @return {void} | ||
* @throws {Error} If any <code>options</code> are invalid. | ||
* @throws {Error} If any <code>options</code> are invalid or cannot be modified. | ||
* @public | ||
* @memberof QRious# | ||
*/ | ||
set(options) { | ||
set: function(options) { | ||
if (optionManager.setAll(options, this)) { | ||
this.update(); | ||
} | ||
} | ||
}, | ||
@@ -154,6 +112,7 @@ /** | ||
* @public | ||
* @memberof QRious# | ||
*/ | ||
toDataURL(mime) { | ||
toDataURL: function(mime) { | ||
return this.canvas.toDataURL(mime || this.mime); | ||
} | ||
}, | ||
@@ -165,5 +124,6 @@ /** | ||
* @protected | ||
* @memberof QRious# | ||
*/ | ||
update() { | ||
const frame = new Frame({ | ||
update: function() { | ||
var frame = new Frame({ | ||
level: this.level, | ||
@@ -177,241 +137,64 @@ value: this.value | ||
/** | ||
* Returns the background color for the QR code. | ||
* | ||
* @return {string} The background color. | ||
* @public | ||
*/ | ||
get background() { | ||
return optionManager.get('background', this); | ||
} | ||
}, { | ||
/** | ||
* Sets the background color for the QR code to <code>background</code> and automatically updates this {@link QRious} | ||
* if the underlying field is changed as a result. | ||
* The current version of {@link QRious}. | ||
* | ||
* @param {string} [background="white"] - the background color to be set | ||
* @public | ||
* @static | ||
* @type {string} | ||
* @memberof QRious | ||
*/ | ||
set background(background) { | ||
if (optionManager.set('background', background, this)) { | ||
this.update(); | ||
} | ||
} | ||
VERSION: '3.0.0', | ||
/** | ||
* Returns the background alpha for the QR code. | ||
* Configures the <code>service</code> provided to be used by all {@link QRious} instances. | ||
* | ||
* @return {number} The background alpha. | ||
* @param {Service} service - the {@link Service} to be configured | ||
* @return {void} | ||
* @throws {Error} If a {@link Service} has already been configured with the same name. | ||
* @public | ||
* @static | ||
* @memberof QRious | ||
*/ | ||
get backgroundAlpha() { | ||
return optionManager.get('backgroundAlpha', this); | ||
use: function(service) { | ||
serviceManager.setService(service.getName(), service); | ||
} | ||
/** | ||
* Sets the background alpha for the QR code to <code>backgroundAlpha</code> and automatically updates this | ||
* {@link QRious} if the underlying field is changed as a result. | ||
* | ||
* @param {number} [backgroundAlpha=1] - the background alpha to be set | ||
* @public | ||
*/ | ||
set backgroundAlpha(backgroundAlpha) { | ||
if (optionManager.set('backgroundAlpha', backgroundAlpha, this)) { | ||
this.update(); | ||
} | ||
} | ||
}); | ||
/** | ||
* Returns the <code>canvas</code> element being used to render the QR code for this {@link QRious}. | ||
* | ||
* @return {*} The <code>canvas</code> element. | ||
* @public | ||
*/ | ||
get canvas() { | ||
return this._canvasRenderer.getElement(); | ||
} | ||
Object.defineProperties(QRious.prototype, { | ||
/** | ||
* Returns the foreground color for the QR code. | ||
* | ||
* @return {string} The foreground color. | ||
* @public | ||
*/ | ||
get foreground() { | ||
return optionManager.get('foreground', this); | ||
} | ||
/** | ||
* Sets the foreground color for the QR code to <code>foreground</code> and automatically updates this {@link QRious} | ||
* if the underlying field is changed as a result. | ||
* | ||
* @param {string} [foreground="black"] - the foreground color to be set | ||
* @public | ||
*/ | ||
set foreground(foreground) { | ||
if (optionManager.set('foreground', foreground, this)) { | ||
this.update(); | ||
canvas: { | ||
/** | ||
* Returns the <code>canvas</code> element being used to render the QR code for this {@link QRious}. | ||
* | ||
* @return {*} The <code>canvas</code> element. | ||
* @public | ||
* @memberof QRious# | ||
* @alias canvas | ||
*/ | ||
get: function() { | ||
return this._canvasRenderer.getElement(); | ||
} | ||
} | ||
}, | ||
/** | ||
* Returns the foreground alpha for the QR code. | ||
* | ||
* @return {number} The foreground alpha. | ||
* @public | ||
*/ | ||
get foregroundAlpha() { | ||
return optionManager.get('foregroundAlpha', this); | ||
} | ||
/** | ||
* Sets the foreground alpha for the QR code to <code>foregroundAlpha</code> and automatically updates this | ||
* {@link QRious} if the underlying field is changed as a result. | ||
* | ||
* @param {number} [foregroundAlpha=1] - the foreground alpha to be set | ||
* @public | ||
*/ | ||
set foregroundAlpha(foregroundAlpha) { | ||
if (optionManager.set('foregroundAlpha', foregroundAlpha, this)) { | ||
this.update(); | ||
image: { | ||
/** | ||
* Returns the <code>img</code> element being used to render the QR code for this {@link QRious}. | ||
* | ||
* @return {*} The <code>img</code> element. | ||
* @public | ||
* @memberof QRious# | ||
* @alias image | ||
*/ | ||
get: function() { | ||
return this._imageRenderer.getElement(); | ||
} | ||
} | ||
/** | ||
* Returns the <code>img</code> element being used to render the QR code for this {@link QRious}. | ||
* | ||
* @return {*} The <code>img</code> element. | ||
* @public | ||
*/ | ||
get image() { | ||
return this._imageRenderer.getElement(); | ||
} | ||
}); | ||
/** | ||
* Returns the error correction level for the QR code. | ||
* | ||
* @return {string} The ECC level. | ||
* @public | ||
*/ | ||
get level() { | ||
return optionManager.get('level', this); | ||
} | ||
module.exports = QRious; | ||
/** | ||
* Sets the error correction level for the QR code to <code>level</code> and automatically updates this {@link QRious} | ||
* if the underlying field is changed as a result. | ||
* | ||
* <code>level</code> will be transformed to upper case to aid mapping to known ECC level blocks. | ||
* | ||
* @param {string} [level="L"] - the ECC level to be set | ||
* @public | ||
*/ | ||
set level(level) { | ||
if (optionManager.set('level', level, this)) { | ||
this.update(); | ||
} | ||
} | ||
/** | ||
* Returns the MIME type for the image rendered for the QR code. | ||
* | ||
* @return {string} The image MIME type. | ||
* @public | ||
*/ | ||
get mime() { | ||
return optionManager.get('mime', this); | ||
} | ||
/** | ||
* Sets the MIME type for the image rendered for the QR code to <code>mime</code> and automatically updates this | ||
* {@link QRious} if the underlying field is changed as a result. | ||
* | ||
* @param {string} [mime="image/png"] - the image MIME type to be set | ||
* @public | ||
*/ | ||
set mime(mime) { | ||
if (optionManager.set('mime', mime, this)) { | ||
this.update(); | ||
} | ||
} | ||
/** | ||
* Returns the padding for the QR code. | ||
* | ||
* @return {number} The padding in pixels. | ||
* @public | ||
*/ | ||
get padding() { | ||
return optionManager.get('padding', this); | ||
} | ||
/** | ||
* Sets the padding for the QR code to <code>padding</code> and automatically updates this {@link QRious} if the | ||
* underlying field is changed as a result. | ||
* | ||
* <code>padding</code> will be transformed to ensure that it is always an absolute positive numbers (e.g. | ||
* <code>-10</code> would become <code>10</code>). | ||
* | ||
* @param {number} [padding] - the padding in pixels to be set | ||
* @public | ||
*/ | ||
set padding(padding) { | ||
if (optionManager.set('padding', padding, this)) { | ||
this.update(); | ||
} | ||
} | ||
/** | ||
* Returns the size of the QR code. | ||
* | ||
* @return {number} The size in pixels. | ||
* @public | ||
*/ | ||
get size() { | ||
return optionManager.get('size', this); | ||
} | ||
/** | ||
* Sets the size of the QR code to <code>size</code> and automatically updates this {@link QRious} if the underlying | ||
* field is changed as a result. | ||
* | ||
* <code>size</code> will be transformed to ensure that it is always an absolute positive numbers (e.g. | ||
* <code>-100</code> would become <code>100</code>). | ||
* | ||
* @param {number} [size=100] - the size in pixels to be set | ||
* @public | ||
*/ | ||
set size(size) { | ||
if (optionManager.set('size', size, this)) { | ||
this.update(); | ||
} | ||
} | ||
/** | ||
* Returns the value of the QR code. | ||
* | ||
* @return {string} The value. | ||
* @public | ||
*/ | ||
get value() { | ||
return optionManager.get('value', this); | ||
} | ||
/** | ||
* Sets the value of the QR code to <code>value</code> and automatically updates this {@link QRious} if the underlying | ||
* field is changed as a result. | ||
* | ||
* @param {string} [value=""] - the value to be set | ||
* @public | ||
*/ | ||
set value(value) { | ||
if (optionManager.set('value', value, this)) { | ||
this.update(); | ||
} | ||
} | ||
} | ||
export default QRious; | ||
/** | ||
@@ -418,0 +201,0 @@ * The options used by {@link QRious}. |
@@ -20,4 +20,6 @@ /* | ||
import Renderer from './Renderer'; | ||
'use strict'; | ||
var Renderer = require('./Renderer'); | ||
/** | ||
@@ -27,5 +29,6 @@ * An implementation of {@link Renderer} for working with <code>canvas</code> elements. | ||
* @public | ||
* @class | ||
* @extends Renderer | ||
*/ | ||
class CanvasRenderer extends Renderer { | ||
var CanvasRenderer = Renderer.extend({ | ||
@@ -35,7 +38,8 @@ /** | ||
*/ | ||
draw(frame) { | ||
const qrious = this.qrious; | ||
const moduleSize = this.getModuleSize(frame); | ||
const offset = this.getOffset(frame); | ||
const context = this.element.getContext('2d'); | ||
draw: function(frame) { | ||
var i, j; | ||
var qrious = this.qrious; | ||
var moduleSize = this.getModuleSize(frame); | ||
var offset = this.getOffset(frame); | ||
var context = this.element.getContext('2d'); | ||
@@ -45,4 +49,4 @@ context.fillStyle = qrious.foreground; | ||
for (let i = 0; i < frame.width; i++) { | ||
for (let j = 0; j < frame.width; j++) { | ||
for (i = 0; i < frame.width; i++) { | ||
for (j = 0; j < frame.width; j++) { | ||
if (frame.buffer[(j * frame.width) + i]) { | ||
@@ -53,3 +57,3 @@ context.fillRect((moduleSize * i) + offset, (moduleSize * j) + offset, moduleSize, moduleSize); | ||
} | ||
} | ||
}, | ||
@@ -59,6 +63,6 @@ /** | ||
*/ | ||
reset() { | ||
const qrious = this.qrious; | ||
const context = this.element.getContext('2d'); | ||
const size = qrious.size; | ||
reset: function() { | ||
var qrious = this.qrious; | ||
var context = this.element.getContext('2d'); | ||
var size = qrious.size; | ||
@@ -70,3 +74,3 @@ context.lineWidth = 1; | ||
context.fillRect(0, 0, size, size); | ||
} | ||
}, | ||
@@ -76,8 +80,10 @@ /** | ||
*/ | ||
resize() { | ||
this.element.width = this.element.height = this.qrious.size; | ||
resize: function() { | ||
var element = this.element; | ||
element.width = element.height = this.qrious.size; | ||
} | ||
} | ||
}); | ||
export default CanvasRenderer; | ||
module.exports = CanvasRenderer; |
@@ -20,4 +20,6 @@ /* | ||
import Renderer from './Renderer'; | ||
'use strict'; | ||
var Renderer = require('./Renderer'); | ||
/** | ||
@@ -30,5 +32,6 @@ * An implementation of {@link Renderer} for working with <code>img</code> elements. | ||
* @public | ||
* @class | ||
* @extends Renderer | ||
*/ | ||
class ImageRenderer extends Renderer { | ||
var ImageRenderer = Renderer.extend({ | ||
@@ -38,5 +41,5 @@ /** | ||
*/ | ||
draw() { | ||
draw: function() { | ||
this.element.src = this.qrious.toDataURL(); | ||
} | ||
}, | ||
@@ -46,5 +49,5 @@ /** | ||
*/ | ||
reset() { | ||
reset: function() { | ||
this.element.src = ''; | ||
} | ||
}, | ||
@@ -54,8 +57,10 @@ /** | ||
*/ | ||
resize() { | ||
this.element.width = this.element.height = this.qrious.size; | ||
resize: function() { | ||
var element = this.element; | ||
element.width = element.height = this.qrious.size; | ||
} | ||
} | ||
}); | ||
export default ImageRenderer; | ||
module.exports = ImageRenderer; |
@@ -20,4 +20,6 @@ /* | ||
import Utilities from '../util/Utilities'; | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
@@ -31,41 +33,39 @@ * Responsible for rendering a QR code {@link Frame} on a specific type of element. | ||
* | ||
* @param {QRious} qrious - the {@link QRious} instance to be used | ||
* @param {*} element - the element onto which the QR code is to be rendered | ||
* @param {boolean} [enabled] - <code>true</code> this {@link Renderer} is enabled; otherwise <code>false</code>. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class Renderer { | ||
var Renderer = Nevis.extend(function(qrious, element, enabled) { | ||
/** | ||
* The {@link QRious} instance. | ||
* | ||
* @protected | ||
* @type {QRious} | ||
* @memberof Renderer# | ||
*/ | ||
this.qrious = qrious; | ||
/** | ||
* Creates a new instance of {@link Renderer} for the <code>qrious</code> instance and <code>element</code> provided. | ||
* The element onto which this {@link Renderer} is rendering the QR code. | ||
* | ||
* @param {QRious} qrious - the {@link QRious} instance to be used | ||
* @param {*} element - the element onto which the QR code is to be rendered | ||
* @param {boolean} [enabled] - <code>true</code> this {@link Renderer} is enabled; otherwise <code>false</code>. | ||
* @public | ||
* @protected | ||
* @type {*} | ||
* @memberof Renderer# | ||
*/ | ||
constructor(qrious, element, enabled) { | ||
/** | ||
* The {@link QRious} instance. | ||
* | ||
* @protected | ||
* @type {QRious} | ||
*/ | ||
this.qrious = qrious; | ||
this.element = element; | ||
this.element.qrious = qrious; | ||
/** | ||
* The element onto which this {@link Renderer} is rendering the QR code. | ||
* | ||
* @protected | ||
* @type {*} | ||
*/ | ||
this.element = element; | ||
this.element.qrious = qrious; | ||
/** | ||
* Whether this {@link Renderer} is enabled. | ||
* | ||
* @protected | ||
* @type {boolean} | ||
* @memberof Renderer# | ||
*/ | ||
this.enabled = Boolean(enabled); | ||
}, { | ||
/** | ||
* Whether this {@link Renderer} is enabled. | ||
* | ||
* @protected | ||
* @type {boolean} | ||
*/ | ||
this.enabled = Boolean(enabled); | ||
} | ||
/** | ||
@@ -79,6 +79,6 @@ * Draws the specified QR code <code>frame</code> on the underlying element. | ||
* @protected | ||
* @abstract | ||
* @memberof Renderer# | ||
*/ | ||
draw(frame) { | ||
Utilities.throwUnimplemented('Renderer', 'draw'); | ||
} | ||
draw: function(frame) {}, | ||
@@ -93,4 +93,5 @@ /** | ||
* @public | ||
* @memberof Renderer# | ||
*/ | ||
getElement() { | ||
getElement: function() { | ||
if (!this.enabled) { | ||
@@ -102,3 +103,3 @@ this.enabled = true; | ||
return this.element; | ||
} | ||
}, | ||
@@ -118,10 +119,11 @@ /** | ||
* @protected | ||
* @memberof Renderer# | ||
*/ | ||
getModuleSize(frame) { | ||
const qrious = this.qrious; | ||
const padding = qrious.padding || 0; | ||
const pixels = Math.floor((qrious.size - (padding * 2)) / frame.width); | ||
getModuleSize: function(frame) { | ||
var qrious = this.qrious; | ||
var padding = qrious.padding || 0; | ||
var pixels = Math.floor((qrious.size - (padding * 2)) / frame.width); | ||
return Math.max(1, pixels); | ||
} | ||
}, | ||
@@ -139,6 +141,7 @@ /** | ||
* @protected | ||
* @memberof Renderer# | ||
*/ | ||
getOffset(frame) { | ||
const qrious = this.qrious; | ||
const padding = qrious.padding; | ||
getOffset: function(frame) { | ||
var qrious = this.qrious; | ||
var padding = qrious.padding; | ||
@@ -149,7 +152,7 @@ if (padding != null) { | ||
const moduleSize = this.getModuleSize(frame); | ||
const offset = Math.floor((qrious.size - (moduleSize * frame.width)) / 2); | ||
var moduleSize = this.getModuleSize(frame); | ||
var offset = Math.floor((qrious.size - (moduleSize * frame.width)) / 2); | ||
return Math.max(0, offset); | ||
} | ||
}, | ||
@@ -162,4 +165,5 @@ /** | ||
* @public | ||
* @memberof Renderer# | ||
*/ | ||
render(frame) { | ||
render: function(frame) { | ||
if (this.enabled) { | ||
@@ -170,3 +174,3 @@ this.resize(); | ||
} | ||
} | ||
}, | ||
@@ -180,6 +184,6 @@ /** | ||
* @protected | ||
* @abstract | ||
* @memberof Renderer# | ||
*/ | ||
reset() { | ||
Utilities.throwUnimplemented('Renderer', 'reset'); | ||
} | ||
reset: function() {}, | ||
@@ -193,9 +197,9 @@ /** | ||
* @protected | ||
* @abstract | ||
* @memberof Renderer# | ||
*/ | ||
resize() { | ||
Utilities.throwUnimplemented('Renderer', 'resize'); | ||
} | ||
resize: function() {} | ||
} | ||
}); | ||
export default Renderer; | ||
module.exports = Renderer; |
@@ -20,7 +20,9 @@ /* | ||
import BrowserElementService from '../service/element/BrowserElementService'; | ||
import QRious from '../QRious'; | ||
'use strict'; | ||
var BrowserElementService = require('../service/element/BrowserElementService'); | ||
var QRious = require('../QRious'); | ||
QRious.use(new BrowserElementService()); | ||
export default QRious; | ||
module.exports = QRious; |
@@ -20,7 +20,9 @@ /* | ||
import NodeElementService from '../service/element/NodeElementService'; | ||
import QRious from '../QRious'; | ||
'use strict'; | ||
var NodeElementService = require('../service/element/NodeElementService'); | ||
var QRious = require('../QRious'); | ||
QRious.use(new NodeElementService()); | ||
export default QRious; | ||
module.exports = QRious; |
@@ -20,4 +20,6 @@ /* | ||
import ElementService from './ElementService'; | ||
'use strict'; | ||
var ElementService = require('./ElementService'); | ||
/** | ||
@@ -27,5 +29,6 @@ * An implementation of {@link ElementService} intended for use within a browser environment. | ||
* @public | ||
* @class | ||
* @extends ElementService | ||
*/ | ||
class BrowserElementService extends ElementService { | ||
var BrowserElementService = ElementService.extend({ | ||
@@ -35,5 +38,5 @@ /** | ||
*/ | ||
createCanvas() { | ||
createCanvas: function() { | ||
return document.createElement('canvas'); | ||
} | ||
}, | ||
@@ -43,5 +46,5 @@ /** | ||
*/ | ||
createImage() { | ||
createImage: function() { | ||
return document.createElement('img'); | ||
} | ||
}, | ||
@@ -51,5 +54,5 @@ /** | ||
*/ | ||
isCanvas(element) { | ||
isCanvas: function(element) { | ||
return element instanceof HTMLCanvasElement; | ||
} | ||
}, | ||
@@ -59,8 +62,8 @@ /** | ||
*/ | ||
isImage(element) { | ||
isImage: function(element) { | ||
return element instanceof HTMLImageElement; | ||
} | ||
} | ||
}); | ||
export default BrowserElementService; | ||
module.exports = BrowserElementService; |
@@ -20,5 +20,6 @@ /* | ||
import Service from '../Service'; | ||
import Utilities from '../../util/Utilities'; | ||
'use strict'; | ||
var Service = require('../Service'); | ||
/** | ||
@@ -28,5 +29,6 @@ * A service for working with elements. | ||
* @public | ||
* @class | ||
* @extends Service | ||
*/ | ||
class ElementService extends Service { | ||
var ElementService = Service.extend({ | ||
@@ -36,8 +38,10 @@ /** | ||
* | ||
* Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic. | ||
* | ||
* @return {*} The newly created canvas element. | ||
* @public | ||
* @abstract | ||
* @memberof ElementService# | ||
*/ | ||
createCanvas() { | ||
Utilities.throwUnimplemented('ElementService', 'createCanvas'); | ||
} | ||
createCanvas: function() {}, | ||
@@ -47,8 +51,10 @@ /** | ||
* | ||
* Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic. | ||
* | ||
* @return {*} The newly created image element. | ||
* @public | ||
* @abstract | ||
* @memberof ElementService# | ||
*/ | ||
createImage() { | ||
Utilities.throwUnimplemented('ElementService', 'createImage'); | ||
} | ||
createImage: function() {}, | ||
@@ -58,5 +64,5 @@ /** | ||
*/ | ||
getName() { | ||
getName: function() { | ||
return 'element'; | ||
} | ||
}, | ||
@@ -66,9 +72,11 @@ /** | ||
* | ||
* Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic. | ||
* | ||
* @param {*} element - the element to be checked | ||
* @return {boolean} <code>true</code> if <code>element</code> is a canvas; otherwise <code>false</code>. | ||
* @public | ||
* @abstract | ||
* @memberof ElementService# | ||
*/ | ||
isCanvas(element) { | ||
Utilities.throwUnimplemented('ElementService', 'isCanvas'); | ||
} | ||
isCanvas: function(element) {}, | ||
@@ -78,12 +86,14 @@ /** | ||
* | ||
* Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic. | ||
* | ||
* @param {*} element - the element to be checked | ||
* @return {boolean} <code>true</code> if <code>element</code> is an image; otherwise <code>false</code>. | ||
* @public | ||
* @abstract | ||
* @memberof ElementService# | ||
*/ | ||
isImage(element) { | ||
Utilities.throwUnimplemented('ElementService', 'isImage'); | ||
} | ||
isImage: function(element) {} | ||
} | ||
}); | ||
export default ElementService; | ||
module.exports = ElementService; |
@@ -20,6 +20,8 @@ /* | ||
import Canvas, { Image } from 'canvas'; | ||
'use strict'; | ||
import ElementService from './ElementService'; | ||
var Canvas = require('canvas'); | ||
var ElementService = require('./ElementService'); | ||
/** | ||
@@ -30,5 +32,6 @@ * An implementation of {@link ElementService} intended for use within a Node.js environment but is only supported when | ||
* @public | ||
* @class | ||
* @extends ElementService | ||
*/ | ||
class NodeElementService extends ElementService { | ||
var NodeElementService = ElementService.extend({ | ||
@@ -38,12 +41,5 @@ /** | ||
*/ | ||
static isSupported() { | ||
return Canvas != null; | ||
} | ||
/** | ||
* @override | ||
*/ | ||
createCanvas() { | ||
createCanvas: function() { | ||
return new Canvas(); | ||
} | ||
}, | ||
@@ -53,5 +49,5 @@ /** | ||
*/ | ||
createImage() { | ||
return new Image(); | ||
} | ||
createImage: function() { | ||
return new Canvas.Image(); | ||
}, | ||
@@ -61,5 +57,5 @@ /** | ||
*/ | ||
isCanvas(element) { | ||
isCanvas: function(element) { | ||
return element instanceof Canvas; | ||
} | ||
}, | ||
@@ -69,8 +65,8 @@ /** | ||
*/ | ||
isImage(element) { | ||
return element instanceof Image; | ||
isImage: function(element) { | ||
return element instanceof Canvas.Image; | ||
} | ||
} | ||
}); | ||
export default NodeElementService; | ||
module.exports = NodeElementService; |
@@ -20,4 +20,6 @@ /* | ||
import Utilities from '../util/Utilities'; | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
@@ -27,4 +29,6 @@ * Defines a service contract that must be met by all implementations. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class Service { | ||
var Service = Nevis.extend({ | ||
@@ -36,9 +40,9 @@ /** | ||
* @public | ||
* @abstract | ||
* @memberof Service# | ||
*/ | ||
getName() { | ||
Utilities.throwUnimplemented('Service', 'getName'); | ||
} | ||
getName: function() {} | ||
} | ||
}); | ||
export default Service; | ||
module.exports = Service; |
@@ -20,2 +20,6 @@ /* | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
@@ -25,15 +29,10 @@ * A basic manager for {@link Service} implementations that are mapped to simple names. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class ServiceManager { | ||
var ServiceManager = Nevis.extend(function() { | ||
this._services = {}; | ||
}, { | ||
/** | ||
* Creates a new instance of {@link ServiceManager}. | ||
* | ||
* @public | ||
*/ | ||
constructor() { | ||
this._services = {}; | ||
} | ||
/** | ||
* Returns the {@link Service} being managed with the specified <code>name</code>. | ||
@@ -45,11 +44,12 @@ * | ||
* @public | ||
* @memberof ServiceManager# | ||
*/ | ||
getService(name) { | ||
const service = this._services[name]; | ||
getService: function(name) { | ||
var service = this._services[name]; | ||
if (!service) { | ||
throw new Error(`Service is not being managed with name: ${name}`); | ||
throw new Error('Service is not being managed with name: ' + name); | ||
} | ||
return service; | ||
} | ||
}, | ||
@@ -65,6 +65,7 @@ /** | ||
* @public | ||
* @memberof ServiceManager# | ||
*/ | ||
setService(name, service) { | ||
setService: function(name, service) { | ||
if (this._services[name]) { | ||
throw new Error(`Service is already managed with name: ${name}`); | ||
throw new Error('Service is already managed with name: ' + name); | ||
} | ||
@@ -77,4 +78,4 @@ | ||
} | ||
}); | ||
export default ServiceManager; | ||
module.exports = ServiceManager; |
@@ -20,2 +20,6 @@ /* | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
@@ -25,4 +29,6 @@ * Contains utility methods that are useful throughout the library. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class Utilities { | ||
var Utilities = Nevis.extend(null, { | ||
@@ -40,6 +46,7 @@ /** | ||
* @static | ||
* @memberof Utilities | ||
*/ | ||
static abs(value) { | ||
abs: function(value) { | ||
return value != null ? Math.abs(value) : null; | ||
} | ||
}, | ||
@@ -55,20 +62,17 @@ /** | ||
* @static | ||
* @memberof Utilities | ||
*/ | ||
static hasOwn(object, name) { | ||
hasOwn: function(object, name) { | ||
return Object.prototype.hasOwnProperty.call(object, name); | ||
} | ||
}, | ||
/** | ||
* Throws an error indicating that the a given method on a specific class has not been implemented. | ||
* A non-operation method that does absolutely nothing. | ||
* | ||
* @param {string} className - the name of the class on which the method has not been implemented | ||
* @param {string} methodName - the name of the method which has not been implemented | ||
* @return {void} | ||
* @throws {Error} The error describing the class method which has not been implemented. | ||
* @public | ||
* @static | ||
* @memberof Utilities | ||
*/ | ||
static throwUnimplemented(className, methodName) { | ||
throw new Error(`"${methodName}" method must be implemented on the ${className} class`); | ||
} | ||
noop: function() {}, | ||
@@ -82,9 +86,10 @@ /** | ||
* @static | ||
* @memberof Utilities | ||
*/ | ||
static toUpperCase(string) { | ||
toUpperCase: function(string) { | ||
return string != null ? string.toUpperCase() : null; | ||
} | ||
} | ||
}); | ||
export default Utilities; | ||
module.exports = Utilities; |
@@ -20,2 +20,6 @@ /* | ||
'use strict'; | ||
var Nevis = require('nevis/lite'); | ||
/** | ||
@@ -25,22 +29,23 @@ * Contains version pattern information. | ||
* @public | ||
* @class | ||
* @extends Nevis | ||
*/ | ||
class Version { | ||
var Version = Nevis.extend(null, { | ||
/** | ||
* Returns the version pattern block. | ||
* The version pattern block. | ||
* | ||
* @return {number[]} The version pattern block. | ||
* @public | ||
* @static | ||
* @type {number[]} | ||
* @memberof Version | ||
*/ | ||
static get BLOCK() { | ||
return [ | ||
0xc94, 0x5bc, 0xa99, 0x4d3, 0xbf6, 0x762, 0x847, 0x60d, 0x928, 0xb78, 0x45d, 0xa17, 0x532, | ||
0x9a6, 0x683, 0x8c9, 0x7ec, 0xec4, 0x1e1, 0xfab, 0x08e, 0xc1a, 0x33f, 0xd75, 0x250, 0x9d5, | ||
0x6f0, 0x8ba, 0x79f, 0xb0b, 0x42e, 0xa64, 0x541, 0xc69 | ||
]; | ||
} | ||
BLOCK: [ | ||
0xc94, 0x5bc, 0xa99, 0x4d3, 0xbf6, 0x762, 0x847, 0x60d, 0x928, 0xb78, 0x45d, 0xa17, 0x532, | ||
0x9a6, 0x683, 0x8c9, 0x7ec, 0xec4, 0x1e1, 0xfab, 0x08e, 0xc1a, 0x33f, 0xd75, 0x250, 0x9d5, | ||
0x6f0, 0x8ba, 0x79f, 0xb0b, 0x42e, 0xa64, 0x541, 0xc69 | ||
] | ||
} | ||
}); | ||
export default Version; | ||
module.exports = Version; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
12
251
437375
3
27
4349
+ Addednevis@^0.5.0
+ Addednevis@0.5.0(transitive)