feat(security,ui): self-host React deps, Tailwind, fonts; strict CSP; local QR; better selection state
Replace CDN React/ReactDOM/Babel with local libs; remove Babel and inline scripts Build Tailwind locally, add safelist; switch to assets/tailwind.css Self-host Font Awesome and Inter (CSS + woff2); remove external font CDNs Implement strict CSP (no unsafe-inline/eval; scripts/styles/fonts from self) Extract inline handlers; move PWA scripts to external files Add local QR code generation (qrcode lib) and remove api.qrserver.com Improve SessionTypeSelector visual selection (highlighted background and ring) Keep PWA working with service worker and offline assets Refs: CSP hardening, offline-first, no external dependencies
This commit is contained in:
770
node_modules/qrcode/README.md
generated
vendored
Normal file
770
node_modules/qrcode/README.md
generated
vendored
Normal file
@@ -0,0 +1,770 @@
|
||||
# node-qrcode
|
||||
> QR code/2d barcode generator.
|
||||
|
||||
[](http://travis-ci.org/soldair/node-qrcode)
|
||||
[](https://www.npmjs.com/package/qrcode)
|
||||
[](https://www.npmjs.com/package/qrcode)
|
||||
[](https://github.com/soldair/node-qrcode/blob/master/license)
|
||||
|
||||
- [Highlights](#highlights)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Error correction level](#error-correction-level)
|
||||
- [QR Code capacity](#qr-code-capacity)
|
||||
- [Encoding Modes](#encoding-modes)
|
||||
- [Binary data](#binary-data)
|
||||
- [Multibyte characters](#multibyte-characters)
|
||||
- [API](#api)
|
||||
- [GS1 QR Codes](#gs1-qr-codes)
|
||||
- [Credits](#credits)
|
||||
- [License](#license)
|
||||
|
||||
## Highlights
|
||||
- Works on server and client (and react native with svg)
|
||||
- CLI utility
|
||||
- Save QR code as image
|
||||
- Support for Numeric, Alphanumeric, Kanji and Byte mode
|
||||
- Support for mixed modes
|
||||
- Support for chinese, cyrillic, greek and japanese characters
|
||||
- Support for multibyte characters (like emojis :smile:)
|
||||
- Auto generates optimized segments for best data compression and smallest QR Code size
|
||||
- App agnostic readability, QR Codes by definition are app agnostic
|
||||
|
||||
## Installation
|
||||
Inside your project folder do:
|
||||
|
||||
```shell
|
||||
npm install --save qrcode
|
||||
```
|
||||
|
||||
or, install it globally to use `qrcode` from the command line to save qrcode images or generate ones you can view in your terminal.
|
||||
|
||||
```shell
|
||||
npm install -g qrcode
|
||||
```
|
||||
|
||||
## Usage
|
||||
### CLI
|
||||
|
||||
```
|
||||
Usage: qrcode [options] <input string>
|
||||
|
||||
QR Code options:
|
||||
-v, --qversion QR Code symbol version (1 - 40) [number]
|
||||
-e, --error Error correction level [choices: "L", "M", "Q", "H"]
|
||||
-m, --mask Mask pattern (0 - 7) [number]
|
||||
|
||||
Renderer options:
|
||||
-t, --type Output type [choices: "png", "svg", "utf8"]
|
||||
-w, --width Image width (px) [number]
|
||||
-s, --scale Scale factor [number]
|
||||
-q, --qzone Quiet zone size [number]
|
||||
-l, --lightcolor Light RGBA hex color
|
||||
-d, --darkcolor Dark RGBA hex color
|
||||
--small Output smaller QR code to terminal [boolean]
|
||||
|
||||
Options:
|
||||
-o, --output Output file
|
||||
-h, --help Show help [boolean]
|
||||
--version Show version number [boolean]
|
||||
|
||||
Examples:
|
||||
qrcode "some text" Draw in terminal window
|
||||
qrcode -o out.png "some text" Save as png image
|
||||
qrcode -d F00 -o out.png "some text" Use red as foreground color
|
||||
```
|
||||
If not specified, output type is guessed from file extension.<br>
|
||||
Recognized extensions are `png`, `svg` and `txt`.
|
||||
|
||||
### Browser
|
||||
`node-qrcode` can be used in browser through module bundlers like [Browserify](https://github.com/substack/node-browserify) and [Webpack](https://github.com/webpack/webpack) or by including the precompiled bundle present in `build/` folder.
|
||||
|
||||
#### Module bundlers
|
||||
```html
|
||||
<!-- index.html -->
|
||||
<html>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<script src="bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```javascript
|
||||
// index.js -> bundle.js
|
||||
var QRCode = require('qrcode')
|
||||
var canvas = document.getElementById('canvas')
|
||||
|
||||
QRCode.toCanvas(canvas, 'sample text', function (error) {
|
||||
if (error) console.error(error)
|
||||
console.log('success!');
|
||||
})
|
||||
```
|
||||
|
||||
#### Precompiled bundle
|
||||
```html
|
||||
<canvas id="canvas"></canvas>
|
||||
|
||||
<script src="/build/qrcode.js"></script>
|
||||
<script>
|
||||
QRCode.toCanvas(document.getElementById('canvas'), 'sample text', function (error) {
|
||||
if (error) console.error(error)
|
||||
console.log('success!');
|
||||
})
|
||||
</script>
|
||||
```
|
||||
|
||||
If you install through `npm`, precompiled files will be available in `node_modules/qrcode/build/` folder.
|
||||
|
||||
The precompiled bundle have support for [Internet Explorer 10+, Safari 5.1+, and all evergreen browsers](https://browserl.ist/?q=defaults%2C+IE+%3E%3D+10%2C+Safari+%3E%3D+5.1).
|
||||
|
||||
### NodeJS
|
||||
Require the module `qrcode`
|
||||
|
||||
```javascript
|
||||
var QRCode = require('qrcode')
|
||||
|
||||
QRCode.toDataURL('I am a pony!', function (err, url) {
|
||||
console.log(url)
|
||||
})
|
||||
```
|
||||
|
||||
render a qrcode for the terminal
|
||||
```js
|
||||
var QRCode = require('qrcode')
|
||||
|
||||
QRCode.toString('I am a pony!',{type:'terminal'}, function (err, url) {
|
||||
console.log(url)
|
||||
})
|
||||
```
|
||||
|
||||
### ES6/ES7
|
||||
Promises and Async/Await can be used in place of callback function.
|
||||
|
||||
```javascript
|
||||
import QRCode from 'qrcode'
|
||||
|
||||
// With promises
|
||||
QRCode.toDataURL('I am a pony!')
|
||||
.then(url => {
|
||||
console.log(url)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
|
||||
// With async/await
|
||||
const generateQR = async text => {
|
||||
try {
|
||||
console.log(await QRCode.toDataURL(text))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Error correction level
|
||||
Error correction capability allows to successfully scan a QR Code even if the symbol is dirty or damaged.
|
||||
Four levels are available to choose according to the operating environment.
|
||||
|
||||
Higher levels offer a better error resistance but reduce the symbol's capacity.<br>
|
||||
If the chances that the QR Code symbol may be corrupted are low (for example if it is showed through a monitor)
|
||||
is possible to safely use a low error level such as `Low` or `Medium`.
|
||||
|
||||
Possible levels are shown below:
|
||||
|
||||
| Level | Error resistance |
|
||||
|------------------|:----------------:|
|
||||
| **L** (Low) | **~7%** |
|
||||
| **M** (Medium) | **~15%** |
|
||||
| **Q** (Quartile) | **~25%** |
|
||||
| **H** (High) | **~30%** |
|
||||
|
||||
The percentage indicates the maximum amount of damaged surface after which the symbol becomes unreadable.
|
||||
|
||||
Error level can be set through `options.errorCorrectionLevel` property.<br>
|
||||
If not specified, the default value is `M`.
|
||||
|
||||
```javascript
|
||||
QRCode.toDataURL('some text', { errorCorrectionLevel: 'H' }, function (err, url) {
|
||||
console.log(url)
|
||||
})
|
||||
```
|
||||
|
||||
## QR Code capacity
|
||||
Capacity depends on symbol version and error correction level. Also encoding modes may influence the amount of storable data.
|
||||
|
||||
The QR Code versions range from version **1** to version **40**.<br>
|
||||
Each version has a different number of modules (black and white dots), which define the symbol's size.
|
||||
For version 1 they are `21x21`, for version 2 `25x25` e so on.
|
||||
Higher is the version, more are the storable data, and of course bigger will be the QR Code symbol.
|
||||
|
||||
The table below shows the maximum number of storable characters in each encoding mode and for each error correction level.
|
||||
|
||||
| Mode | L | M | Q | H |
|
||||
|--------------|------|------|------|------|
|
||||
| Numeric | 7089 | 5596 | 3993 | 3057 |
|
||||
| Alphanumeric | 4296 | 3391 | 2420 | 1852 |
|
||||
| Byte | 2953 | 2331 | 1663 | 1273 |
|
||||
| Kanji | 1817 | 1435 | 1024 | 784 |
|
||||
|
||||
**Note:** Maximum characters number can be different when using [Mixed modes](#mixed-modes).
|
||||
|
||||
QR Code version can be set through `options.version` property.<br>
|
||||
If no version is specified, the more suitable value will be used. Unless a specific version is required, this option is not needed.
|
||||
|
||||
```javascript
|
||||
QRCode.toDataURL('some text', { version: 2 }, function (err, url) {
|
||||
console.log(url)
|
||||
})
|
||||
```
|
||||
|
||||
## Encoding modes
|
||||
Modes can be used to encode a string in a more efficient way.<br>
|
||||
A mode may be more suitable than others depending on the string content.
|
||||
A list of supported modes are shown in the table below:
|
||||
|
||||
| Mode | Characters | Compression |
|
||||
|--------------|-----------------------------------------------------------|-------------------------------------------|
|
||||
| Numeric | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | 3 characters are represented by 10 bits |
|
||||
| Alphanumeric | 0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, : | 2 characters are represented by 11 bits |
|
||||
| Kanji | Characters from the Shift JIS system based on JIS X 0208 | 2 kanji are represented by 13 bits |
|
||||
| Byte | Characters from the ISO/IEC 8859-1 character set | Each characters are represented by 8 bits |
|
||||
|
||||
Choose the right mode may be tricky if the input text is unknown.<br>
|
||||
In these cases **Byte** mode is the best choice since all characters can be encoded with it. (See [Multibyte characters](#multibyte-characters))<br>
|
||||
However, if the QR Code reader supports mixed modes, using [Auto mode](#auto-mode) may produce better results.
|
||||
|
||||
### Mixed modes
|
||||
Mixed modes are also possible. A QR code can be generated from a series of segments having different encoding modes to optimize the data compression.<br>
|
||||
However, switching from a mode to another has a cost which may lead to a worst result if it's not taken into account.
|
||||
See [Manual mode](#manual-mode) for an example of how to specify segments with different encoding modes.
|
||||
|
||||
### Auto mode
|
||||
By **default**, automatic mode selection is used.<br>
|
||||
The input string is automatically splitted in various segments optimized to produce the shortest possible bitstream using mixed modes.<br>
|
||||
This is the preferred way to generate the QR Code.
|
||||
|
||||
For example, the string **ABCDE12345678?A1A** will be splitted in 3 segments with the following modes:
|
||||
|
||||
| Segment | Mode |
|
||||
|----------|--------------|
|
||||
| ABCDE | Alphanumeric |
|
||||
| 12345678 | Numeric |
|
||||
| ?A1A | Byte |
|
||||
|
||||
Any other combinations of segments and modes will result in a longer bitstream.<br>
|
||||
If you need to keep the QR Code size small, this mode will produce the best results.
|
||||
|
||||
### Manual mode
|
||||
If auto mode doesn't work for you or you have specific needs, is also possible to manually specify each segment with the relative mode.
|
||||
In this way no segment optimizations will be applied under the hood.<br>
|
||||
Segments list can be passed as an array of object:
|
||||
|
||||
```javascript
|
||||
var QRCode = require('qrcode')
|
||||
|
||||
var segs = [
|
||||
{ data: 'ABCDEFG', mode: 'alphanumeric' },
|
||||
{ data: '0123456', mode: 'numeric' }
|
||||
]
|
||||
|
||||
QRCode.toDataURL(segs, function (err, url) {
|
||||
console.log(url)
|
||||
})
|
||||
```
|
||||
|
||||
### Kanji mode
|
||||
With kanji mode is possible to encode characters from the Shift JIS system in an optimized way.<br>
|
||||
Unfortunately, there isn't a way to calculate a Shifted JIS values from, for example, a character encoded in UTF-8, for this reason a conversion table from the input characters to the SJIS values is needed.<br>
|
||||
This table is not included by default in the bundle to keep the size as small as possible.
|
||||
|
||||
If your application requires kanji support, you will need to pass a function that will take care of converting the input characters to appropriate values.
|
||||
|
||||
An helper method is provided by the lib through an optional file that you can include as shown in the example below.
|
||||
|
||||
**Note:** Support for Kanji mode is only needed if you want to benefit of the data compression, otherwise is still possible to encode kanji using Byte mode (See [Multibyte characters](#multibyte-characters)).
|
||||
|
||||
```javascript
|
||||
var QRCode = require('qrcode')
|
||||
var toSJIS = require('qrcode/helper/to-sjis')
|
||||
|
||||
QRCode.toDataURL(kanjiString, { toSJISFunc: toSJIS }, function (err, url) {
|
||||
console.log(url)
|
||||
})
|
||||
```
|
||||
|
||||
With precompiled bundle:
|
||||
|
||||
```html
|
||||
<canvas id="canvas"></canvas>
|
||||
|
||||
<script src="/build/qrcode.min.js"></script>
|
||||
<script src="/build/qrcode.tosjis.min.js"></script>
|
||||
<script>
|
||||
QRCode.toCanvas(document.getElementById('canvas'),
|
||||
'sample text', { toSJISFunc: QRCode.toSJIS }, function (error) {
|
||||
if (error) console.error(error)
|
||||
console.log('success!')
|
||||
})
|
||||
</script>
|
||||
```
|
||||
|
||||
## Binary data
|
||||
QR Codes can hold arbitrary byte-based binary data. If you attempt to create a binary QR Code by first converting the data to a JavaScript string, it will fail to encode propery because string encoding adds additional bytes. Instead, you must pass a [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) or compatible array, or a Node [Buffer](https://nodejs.org/api/buffer.html), as follows:
|
||||
|
||||
```javascript
|
||||
// Regular array example
|
||||
// WARNING: Element values will be clamped to 0-255 even if your data contains higher values.
|
||||
const QRCode = require('qrcode')
|
||||
QRCode.toFile(
|
||||
'foo.png',
|
||||
[{ data: [253,254,255], mode: 'byte' }],
|
||||
...options...,
|
||||
...callback...
|
||||
)
|
||||
```
|
||||
|
||||
```javascript
|
||||
// Uint8ClampedArray example
|
||||
const QRCode = require('qrcode')
|
||||
|
||||
QRCode.toFile(
|
||||
'foo.png',
|
||||
[{ data: new Uint8ClampedArray([253,254,255]), mode: 'byte' }],
|
||||
...options...,
|
||||
...callback...
|
||||
)
|
||||
```
|
||||
|
||||
```javascript
|
||||
// Node Buffer example
|
||||
// WARNING: Element values will be clamped to 0-255 even if your data contains higher values.
|
||||
const QRCode = require('qrcode')
|
||||
|
||||
QRCode.toFile(
|
||||
'foo.png',
|
||||
[{ data: Buffer.from([253,254,255]), mode: 'byte' }],
|
||||
...options...,
|
||||
...callback...
|
||||
)
|
||||
```
|
||||
|
||||
TypeScript users: if you are using [@types/qrcode](https://www.npmjs.com/package/@types/qrcode), you will need to add a `// @ts-ignore` above the data segment because it expects `data: string`.
|
||||
|
||||
## Multibyte characters
|
||||
Support for multibyte characters isn't present in the initial QR Code standard, but is possible to encode UTF-8 characters in Byte mode.
|
||||
|
||||
QR Codes provide a way to specify a different type of character set through ECI (Extended Channel Interpretation), but it's not fully implemented in this lib yet.
|
||||
|
||||
Most QR Code readers, however, are able to recognize multibyte characters even without ECI.
|
||||
|
||||
Note that a single Kanji/Kana or Emoji can take up to 4 bytes.
|
||||
|
||||
## API
|
||||
Browser:
|
||||
- [create()](#createtext-options)
|
||||
- [toCanvas()](#tocanvascanvaselement-text-options-cberror)
|
||||
- [toDataURL()](#todataurltext-options-cberror-url)
|
||||
- [toString()](#tostringtext-options-cberror-string)
|
||||
|
||||
Server:
|
||||
- [create()](#createtext-options)
|
||||
- [toCanvas()](#tocanvascanvas-text-options-cberror)
|
||||
- [toDataURL()](#todataurltext-options-cberror-url-1)
|
||||
- [toString()](#tostringtext-options-cberror-string-1)
|
||||
- [toFile()](#tofilepath-text-options-cberror)
|
||||
- [toFileStream()](#tofilestreamstream-text-options)
|
||||
|
||||
### Browser API
|
||||
#### `create(text, [options])`
|
||||
Creates QR Code symbol and returns a qrcode object.
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
See [QR Code options](#qr-code-options).
|
||||
|
||||
##### `returns`
|
||||
Type: `Object`
|
||||
|
||||
```javascript
|
||||
// QRCode object
|
||||
{
|
||||
modules, // Bitmatrix class with modules data
|
||||
version, // Calculated QR Code version
|
||||
errorCorrectionLevel, // Error Correction Level
|
||||
maskPattern, // Calculated Mask pattern
|
||||
segments // Generated segments
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
#### `toCanvas(canvasElement, text, [options], [cb(error)])`
|
||||
#### `toCanvas(text, [options], [cb(error, canvas)])`
|
||||
Draws qr code symbol to canvas.<br>
|
||||
If `canvasElement` is omitted a new canvas is returned.
|
||||
|
||||
##### `canvasElement`
|
||||
Type: `DOMElement`
|
||||
|
||||
Canvas where to draw QR Code.
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
See [Options](#options).
|
||||
|
||||
##### `cb`
|
||||
Type: `Function`
|
||||
|
||||
Callback function called on finish.
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
QRCode.toCanvas('text', { errorCorrectionLevel: 'H' }, function (err, canvas) {
|
||||
if (err) throw err
|
||||
|
||||
var container = document.getElementById('container')
|
||||
container.appendChild(canvas)
|
||||
})
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
#### `toDataURL(text, [options], [cb(error, url)])`
|
||||
#### `toDataURL(canvasElement, text, [options], [cb(error, url)])`
|
||||
Returns a Data URI containing a representation of the QR Code image.<br>
|
||||
If provided, `canvasElement` will be used as canvas to generate the data URI.
|
||||
|
||||
##### `canvasElement`
|
||||
Type: `DOMElement`
|
||||
|
||||
Canvas where to draw QR Code.
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
- ###### `type`
|
||||
Type: `String`<br>
|
||||
Default: `image/png`
|
||||
|
||||
Data URI format.<br>
|
||||
Possible values are: `image/png`, `image/jpeg`, `image/webp`.<br>
|
||||
|
||||
- ###### `rendererOpts.quality`
|
||||
Type: `Number`<br>
|
||||
Default: `0.92`
|
||||
|
||||
A Number between `0` and `1` indicating image quality if the requested type is `image/jpeg` or `image/webp`.
|
||||
|
||||
See [Options](#options) for other settings.
|
||||
|
||||
##### `cb`
|
||||
Type: `Function`
|
||||
|
||||
Callback function called on finish.
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
var opts = {
|
||||
errorCorrectionLevel: 'H',
|
||||
type: 'image/jpeg',
|
||||
quality: 0.3,
|
||||
margin: 1,
|
||||
color: {
|
||||
dark:"#010599FF",
|
||||
light:"#FFBF60FF"
|
||||
}
|
||||
}
|
||||
|
||||
QRCode.toDataURL('text', opts, function (err, url) {
|
||||
if (err) throw err
|
||||
|
||||
var img = document.getElementById('image')
|
||||
img.src = url
|
||||
})
|
||||
```
|
||||
<br>
|
||||
|
||||
#### `toString(text, [options], [cb(error, string)])`
|
||||
|
||||
Returns a string representation of the QR Code.<br>
|
||||
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
- ###### `type`
|
||||
Type: `String`<br>
|
||||
Default: `utf8`
|
||||
|
||||
Output format.<br>
|
||||
Possible values are: `terminal`,`utf8`, and `svg`.
|
||||
|
||||
See [Options](#options) for other settings.
|
||||
|
||||
##### `cb`
|
||||
Type: `Function`
|
||||
|
||||
Callback function called on finish.
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
QRCode.toString('http://www.google.com', function (err, string) {
|
||||
if (err) throw err
|
||||
console.log(string)
|
||||
})
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
### Server API
|
||||
#### `create(text, [options])`
|
||||
See [create](#createtext-options).
|
||||
|
||||
<br>
|
||||
|
||||
#### `toCanvas(canvas, text, [options], [cb(error)])`
|
||||
Draws qr code symbol to [node canvas](https://github.com/Automattic/node-canvas).
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
See [Options](#options).
|
||||
|
||||
##### `cb`
|
||||
Type: `Function`
|
||||
|
||||
Callback function called on finish.
|
||||
|
||||
<br>
|
||||
|
||||
#### `toDataURL(text, [options], [cb(error, url)])`
|
||||
Returns a Data URI containing a representation of the QR Code image.<br>
|
||||
Only works with `image/png` type for now.
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
See [Options](#options) for other settings.
|
||||
|
||||
##### `cb`
|
||||
Type: `Function`
|
||||
|
||||
Callback function called on finish.
|
||||
|
||||
<br>
|
||||
|
||||
#### `toString(text, [options], [cb(error, string)])`
|
||||
Returns a string representation of the QR Code.<br>
|
||||
If choosen output format is `svg` it will returns a string containing xml code.
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
- ###### `type`
|
||||
Type: `String`<br>
|
||||
Default: `utf8`
|
||||
|
||||
Output format.<br>
|
||||
Possible values are: `utf8`, `svg`, `terminal`.
|
||||
|
||||
See [Options](#options) for other settings.
|
||||
|
||||
##### `cb`
|
||||
Type: `Function`
|
||||
|
||||
Callback function called on finish.
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
QRCode.toString('http://www.google.com', function (err, string) {
|
||||
if (err) throw err
|
||||
console.log(string)
|
||||
})
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
#### `toFile(path, text, [options], [cb(error)])`
|
||||
Saves QR Code to image file.<br>
|
||||
If `options.type` is not specified, the format will be guessed from file extension.<br>
|
||||
Recognized extensions are `png`, `svg`, `txt`.
|
||||
|
||||
##### `path`
|
||||
Type: `String`
|
||||
|
||||
Path where to save the file.
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
- ###### `type`
|
||||
Type: `String`<br>
|
||||
Default: `png`
|
||||
|
||||
Output format.<br>
|
||||
Possible values are: `png`, `svg`, `utf8`.
|
||||
|
||||
- ###### `rendererOpts.deflateLevel` **(png only)**
|
||||
Type: `Number`<br>
|
||||
Default: `9`
|
||||
|
||||
Compression level for deflate.
|
||||
|
||||
- ###### `rendererOpts.deflateStrategy` **(png only)**
|
||||
Type: `Number`<br>
|
||||
Default: `3`
|
||||
|
||||
Compression strategy for deflate.
|
||||
|
||||
See [Options](#options) for other settings.
|
||||
|
||||
##### `cb`
|
||||
Type: `Function`
|
||||
|
||||
Callback function called on finish.
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
QRCode.toFile('path/to/filename.png', 'Some text', {
|
||||
color: {
|
||||
dark: '#00F', // Blue dots
|
||||
light: '#0000' // Transparent background
|
||||
}
|
||||
}, function (err) {
|
||||
if (err) throw err
|
||||
console.log('done')
|
||||
})
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
#### `toFileStream(stream, text, [options])`
|
||||
Writes QR Code image to stream. Only works with `png` format for now.
|
||||
|
||||
##### `stream`
|
||||
Type: `stream.Writable`
|
||||
|
||||
Node stream.
|
||||
|
||||
##### `text`
|
||||
Type: `String|Array`
|
||||
|
||||
Text to encode or a list of objects describing segments.
|
||||
|
||||
##### `options`
|
||||
See [Options](#options).
|
||||
|
||||
<br>
|
||||
|
||||
### Options
|
||||
|
||||
#### QR Code options
|
||||
##### `version`
|
||||
Type: `Number`<br>
|
||||
|
||||
QR Code version. If not specified the more suitable value will be calculated.
|
||||
|
||||
##### `errorCorrectionLevel`
|
||||
Type: `String`<br>
|
||||
Default: `M`
|
||||
|
||||
Error correction level.<br>
|
||||
Possible values are `low, medium, quartile, high` or `L, M, Q, H`.
|
||||
|
||||
##### `maskPattern`
|
||||
Type: `Number`<br>
|
||||
|
||||
Mask pattern used to mask the symbol.<br>
|
||||
Possible values are `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`.<br>
|
||||
If not specified the more suitable value will be calculated.
|
||||
|
||||
##### `toSJISFunc`
|
||||
Type: `Function`<br>
|
||||
|
||||
Helper function used internally to convert a kanji to its Shift JIS value.<br>
|
||||
Provide this function if you need support for Kanji mode.
|
||||
|
||||
#### Renderers options
|
||||
##### `margin`
|
||||
Type: `Number`<br>
|
||||
Default: `4`
|
||||
|
||||
Define how much wide the quiet zone should be.
|
||||
|
||||
##### `scale`
|
||||
Type: `Number`<br>
|
||||
Default: `4`
|
||||
|
||||
Scale factor. A value of `1` means 1px per modules (black dots).
|
||||
|
||||
##### `small`
|
||||
Type: `Boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Relevant only for terminal renderer. Outputs smaller QR code.
|
||||
|
||||
##### `width`
|
||||
Type: `Number`<br>
|
||||
|
||||
Forces a specific width for the output image.<br>
|
||||
If width is too small to contain the qr symbol, this option will be ignored.<br>
|
||||
Takes precedence over `scale`.
|
||||
|
||||
##### `color.dark`
|
||||
Type: `String`<br>
|
||||
Default: `#000000ff`
|
||||
|
||||
Color of dark module. Value must be in hex format (RGBA).<br>
|
||||
Note: dark color should always be darker than `color.light`.
|
||||
|
||||
##### `color.light`
|
||||
Type: `String`<br>
|
||||
Default: `#ffffffff`
|
||||
|
||||
Color of light module. Value must be in hex format (RGBA).<br>
|
||||
|
||||
<br>
|
||||
|
||||
## GS1 QR Codes
|
||||
There was a real good discussion here about them. but in short any qrcode generator will make gs1 compatible qrcodes, but what defines a gs1 qrcode is a header with metadata that describes your gs1 information.
|
||||
|
||||
https://github.com/soldair/node-qrcode/issues/45
|
||||
|
||||
|
||||
## Credits
|
||||
This lib is based on "QRCode for JavaScript" which Kazuhiko Arase thankfully MIT licensed.
|
||||
|
||||
## License
|
||||
[MIT](https://github.com/soldair/node-qrcode/blob/master/license)
|
||||
|
||||
The word "QR Code" is registered trademark of:<br>
|
||||
DENSO WAVE INCORPORATED
|
||||
159
node_modules/qrcode/bin/qrcode
generated
vendored
Normal file
159
node_modules/qrcode/bin/qrcode
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
#!/usr/bin/env node
|
||||
var yargs = require('yargs')
|
||||
var qr = require('../lib')
|
||||
|
||||
function save (file, text, options) {
|
||||
qr.toFile(file, text, options, function (err, data) {
|
||||
if (err) {
|
||||
console.error('Error:', err.message)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log('saved qrcode to: ' + file + '\n')
|
||||
})
|
||||
}
|
||||
|
||||
function print (text, options) {
|
||||
options.type = 'terminal'
|
||||
qr.toString(text, options, function (err, text) {
|
||||
if (err) {
|
||||
console.error('Error:', err.message)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log(text)
|
||||
})
|
||||
}
|
||||
|
||||
function parseOptions (args) {
|
||||
return {
|
||||
version: args.qversion,
|
||||
errorCorrectionLevel: args.error,
|
||||
type: args.type,
|
||||
small: !!args.small,
|
||||
inverse: !!args.inverse,
|
||||
maskPattern: args.mask,
|
||||
margin: args.qzone,
|
||||
width: args.width,
|
||||
scale: args.scale,
|
||||
color: {
|
||||
light: args.lightcolor,
|
||||
dark: args.darkcolor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function processInputs (text, opts) {
|
||||
if (!text.length) {
|
||||
yargs.showHelp()
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (opts.output) {
|
||||
save(opts.output, text, parseOptions(opts))
|
||||
} else {
|
||||
print(text, parseOptions(opts))
|
||||
}
|
||||
}
|
||||
|
||||
var argv = yargs
|
||||
.detectLocale(false)
|
||||
.usage('Usage: $0 [options] <input string>')
|
||||
.option('v', {
|
||||
alias: 'qversion',
|
||||
description: 'QR Code symbol version (1 - 40)',
|
||||
group: 'QR Code options:',
|
||||
type: 'number'
|
||||
})
|
||||
.option('e', {
|
||||
alias: 'error',
|
||||
description: 'Error correction level',
|
||||
choices: ['L', 'M', 'Q', 'H'],
|
||||
group: 'QR Code options:'
|
||||
})
|
||||
.option('m', {
|
||||
alias: 'mask',
|
||||
description: 'Mask pattern (0 - 7)',
|
||||
group: 'QR Code options:',
|
||||
type: 'number'
|
||||
})
|
||||
.option('t', {
|
||||
alias: 'type',
|
||||
description: 'Output type',
|
||||
choices: ['png', 'svg', 'utf8'],
|
||||
implies: 'output',
|
||||
group: 'Renderer options:'
|
||||
})
|
||||
.option('i', {
|
||||
alias: 'inverse',
|
||||
type: 'boolean',
|
||||
description: 'Invert colors',
|
||||
group: 'Renderer options:'
|
||||
})
|
||||
.option('w', {
|
||||
alias: 'width',
|
||||
description: 'Image width (px)',
|
||||
conflicts: 'scale',
|
||||
group: 'Renderer options:',
|
||||
type: 'number'
|
||||
})
|
||||
.option('s', {
|
||||
alias: 'scale',
|
||||
description: 'Scale factor',
|
||||
conflicts: 'width',
|
||||
group: 'Renderer options:',
|
||||
type: 'number'
|
||||
})
|
||||
.option('q', {
|
||||
alias: 'qzone',
|
||||
description: 'Quiet zone size',
|
||||
group: 'Renderer options:',
|
||||
type: 'number'
|
||||
})
|
||||
.option('l', {
|
||||
alias: 'lightcolor',
|
||||
description: 'Light RGBA hex color',
|
||||
group: 'Renderer options:'
|
||||
})
|
||||
.option('d', {
|
||||
alias: 'darkcolor',
|
||||
description: 'Dark RGBA hex color',
|
||||
group: 'Renderer options:'
|
||||
})
|
||||
.option('small', {
|
||||
type: 'boolean',
|
||||
description: 'Output smaller QR code to terminal',
|
||||
conflicts: 'type',
|
||||
group: 'Renderer options:'
|
||||
})
|
||||
.option('o', {
|
||||
alias: 'output',
|
||||
description: 'Output file'
|
||||
})
|
||||
.help('h')
|
||||
.alias('h', 'help')
|
||||
.version()
|
||||
.example('$0 "some text"', 'Draw in terminal window')
|
||||
.example('$0 -o out.png "some text"', 'Save as png image')
|
||||
.example('$0 -d F00 -o out.png "some text"', 'Use red as foreground color')
|
||||
.parserConfiguration({'parse-numbers': false})
|
||||
.argv
|
||||
|
||||
if (process.stdin.isTTY) {
|
||||
processInputs(argv._.join(' '), argv)
|
||||
} else {
|
||||
var text = ''
|
||||
process.stdin.setEncoding('utf8')
|
||||
process.stdin.on('readable', function () {
|
||||
var chunk = process.stdin.read()
|
||||
if (chunk !== null) {
|
||||
text += chunk
|
||||
}
|
||||
})
|
||||
|
||||
process.stdin.on('end', function () {
|
||||
// this process can be run as a command outside of a tty so if there was no
|
||||
// data on stdin read from argv
|
||||
processInputs(text.length?text:argv._.join(' '), argv)
|
||||
})
|
||||
}
|
||||
2
node_modules/qrcode/helper/to-sjis-browser.js
generated
vendored
Normal file
2
node_modules/qrcode/helper/to-sjis-browser.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/* global QRCode */
|
||||
QRCode.toSJIS = require('./to-sjis')
|
||||
105
node_modules/qrcode/helper/to-sjis.js
generated
vendored
Normal file
105
node_modules/qrcode/helper/to-sjis.js
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
const SJIS_UTF8 = [
|
||||
[0x8140, ' 、。,.・:;?!゛゜´`¨^ ̄_ヽヾゝゞ〃仝々〆〇ー―‐/\~∥|…‥‘’“”()〔〕[]{}〈〉《》「」『』【】+-±×'],
|
||||
[0x8180, '÷=≠<>≦≧∞∴♂♀°′″℃'],
|
||||
[0x818f, '¥$¢£%#&*@§☆★○●◎◇◆□■△▲▽▼'],
|
||||
[0x81a6, '※〒→←↑↓〓'],
|
||||
[0x81b8, '∈∋⊆⊇⊂⊃∪∩'],
|
||||
[0x81c8, '∧∨¬⇒⇔∀∃'],
|
||||
[0x81da, '∠⊥⌒∂∇≡≒≪≫√∽∝∵∫∬'],
|
||||
[0x81f0, 'ʼn♯♭♪†‡¶'],
|
||||
[0x824f, '0123456789'],
|
||||
[0x8260, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'],
|
||||
[0x8281, 'abcdefghijklmnopqrstuvwxyz'],
|
||||
[0x829f, 'ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをん'],
|
||||
[0x8340, 'ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミ'],
|
||||
[0x8380, 'ムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ'],
|
||||
[0x839f, 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ'],
|
||||
[0x83bf, 'αβγδεζηθικλμνξοπρστυφχψω'],
|
||||
[0x8440, 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'],
|
||||
[0x8470, 'абвгдеёжзийклмн'],
|
||||
[0x8480, 'опрстуфхцчшщъыьэюя'],
|
||||
[0x8780, '〝〟'],
|
||||
[0x889f, '亜唖娃阿哀愛挨姶逢葵茜穐悪握渥旭葦芦鯵梓圧斡扱宛姐虻飴絢綾鮎或粟袷安庵按暗案闇鞍杏以伊位依偉囲夷委威尉惟意慰易椅為畏異移維緯胃萎衣'],
|
||||
[0x88e0, '謂違遺医井亥域育郁磯一壱溢逸稲茨芋鰯允印咽員因姻引飲淫胤蔭'],
|
||||
[0x8940, '院陰隠韻吋右宇烏羽迂雨卯鵜窺丑碓臼渦嘘唄欝蔚鰻姥厩浦瓜閏噂云運雲荏餌叡営嬰影映曳栄永泳洩瑛盈穎頴英衛詠鋭液疫益駅悦謁越閲榎厭円'],
|
||||
[0x8980, '園堰奄宴延怨掩援沿演炎焔煙燕猿縁艶苑薗遠鉛鴛塩於汚甥凹央奥往応押旺横欧殴王翁襖鴬鴎黄岡沖荻億屋憶臆桶牡乙俺卸恩温穏音下化仮何伽価佳加可嘉夏嫁家寡科暇果架歌河火珂禍禾稼箇花苛茄荷華菓蝦課嘩貨迦過霞蚊俄峨我牙画臥芽蛾賀雅餓駕介会解回塊壊廻快怪悔恢懐戒拐改'],
|
||||
[0x8a40, '魁晦械海灰界皆絵芥蟹開階貝凱劾外咳害崖慨概涯碍蓋街該鎧骸浬馨蛙垣柿蛎鈎劃嚇各廓拡撹格核殻獲確穫覚角赫較郭閣隔革学岳楽額顎掛笠樫'],
|
||||
[0x8a80, '橿梶鰍潟割喝恰括活渇滑葛褐轄且鰹叶椛樺鞄株兜竃蒲釜鎌噛鴨栢茅萱粥刈苅瓦乾侃冠寒刊勘勧巻喚堪姦完官寛干幹患感慣憾換敢柑桓棺款歓汗漢澗潅環甘監看竿管簡緩缶翰肝艦莞観諌貫還鑑間閑関陥韓館舘丸含岸巌玩癌眼岩翫贋雁頑顔願企伎危喜器基奇嬉寄岐希幾忌揮机旗既期棋棄'],
|
||||
[0x8b40, '機帰毅気汽畿祈季稀紀徽規記貴起軌輝飢騎鬼亀偽儀妓宜戯技擬欺犠疑祇義蟻誼議掬菊鞠吉吃喫桔橘詰砧杵黍却客脚虐逆丘久仇休及吸宮弓急救'],
|
||||
[0x8b80, '朽求汲泣灸球究窮笈級糾給旧牛去居巨拒拠挙渠虚許距鋸漁禦魚亨享京供侠僑兇競共凶協匡卿叫喬境峡強彊怯恐恭挟教橋況狂狭矯胸脅興蕎郷鏡響饗驚仰凝尭暁業局曲極玉桐粁僅勤均巾錦斤欣欽琴禁禽筋緊芹菌衿襟謹近金吟銀九倶句区狗玖矩苦躯駆駈駒具愚虞喰空偶寓遇隅串櫛釧屑屈'],
|
||||
[0x8c40, '掘窟沓靴轡窪熊隈粂栗繰桑鍬勲君薫訓群軍郡卦袈祁係傾刑兄啓圭珪型契形径恵慶慧憩掲携敬景桂渓畦稽系経継繋罫茎荊蛍計詣警軽頚鶏芸迎鯨'],
|
||||
[0x8c80, '劇戟撃激隙桁傑欠決潔穴結血訣月件倹倦健兼券剣喧圏堅嫌建憲懸拳捲検権牽犬献研硯絹県肩見謙賢軒遣鍵険顕験鹸元原厳幻弦減源玄現絃舷言諺限乎個古呼固姑孤己庫弧戸故枯湖狐糊袴股胡菰虎誇跨鈷雇顧鼓五互伍午呉吾娯後御悟梧檎瑚碁語誤護醐乞鯉交佼侯候倖光公功効勾厚口向'],
|
||||
[0x8d40, '后喉坑垢好孔孝宏工巧巷幸広庚康弘恒慌抗拘控攻昂晃更杭校梗構江洪浩港溝甲皇硬稿糠紅紘絞綱耕考肯肱腔膏航荒行衡講貢購郊酵鉱砿鋼閤降'],
|
||||
[0x8d80, '項香高鴻剛劫号合壕拷濠豪轟麹克刻告国穀酷鵠黒獄漉腰甑忽惚骨狛込此頃今困坤墾婚恨懇昏昆根梱混痕紺艮魂些佐叉唆嵯左差査沙瑳砂詐鎖裟坐座挫債催再最哉塞妻宰彩才採栽歳済災采犀砕砦祭斎細菜裁載際剤在材罪財冴坂阪堺榊肴咲崎埼碕鷺作削咋搾昨朔柵窄策索錯桜鮭笹匙冊刷'],
|
||||
[0x8e40, '察拶撮擦札殺薩雑皐鯖捌錆鮫皿晒三傘参山惨撒散桟燦珊産算纂蚕讃賛酸餐斬暫残仕仔伺使刺司史嗣四士始姉姿子屍市師志思指支孜斯施旨枝止'],
|
||||
[0x8e80, '死氏獅祉私糸紙紫肢脂至視詞詩試誌諮資賜雌飼歯事似侍児字寺慈持時次滋治爾璽痔磁示而耳自蒔辞汐鹿式識鴫竺軸宍雫七叱執失嫉室悉湿漆疾質実蔀篠偲柴芝屡蕊縞舎写射捨赦斜煮社紗者謝車遮蛇邪借勺尺杓灼爵酌釈錫若寂弱惹主取守手朱殊狩珠種腫趣酒首儒受呪寿授樹綬需囚収周'],
|
||||
[0x8f40, '宗就州修愁拾洲秀秋終繍習臭舟蒐衆襲讐蹴輯週酋酬集醜什住充十従戎柔汁渋獣縦重銃叔夙宿淑祝縮粛塾熟出術述俊峻春瞬竣舜駿准循旬楯殉淳'],
|
||||
[0x8f80, '準潤盾純巡遵醇順処初所暑曙渚庶緒署書薯藷諸助叙女序徐恕鋤除傷償勝匠升召哨商唱嘗奨妾娼宵将小少尚庄床廠彰承抄招掌捷昇昌昭晶松梢樟樵沼消渉湘焼焦照症省硝礁祥称章笑粧紹肖菖蒋蕉衝裳訟証詔詳象賞醤鉦鍾鐘障鞘上丈丞乗冗剰城場壌嬢常情擾条杖浄状畳穣蒸譲醸錠嘱埴飾'],
|
||||
[0x9040, '拭植殖燭織職色触食蝕辱尻伸信侵唇娠寝審心慎振新晋森榛浸深申疹真神秦紳臣芯薪親診身辛進針震人仁刃塵壬尋甚尽腎訊迅陣靭笥諏須酢図厨'],
|
||||
[0x9080, '逗吹垂帥推水炊睡粋翠衰遂酔錐錘随瑞髄崇嵩数枢趨雛据杉椙菅頗雀裾澄摺寸世瀬畝是凄制勢姓征性成政整星晴棲栖正清牲生盛精聖声製西誠誓請逝醒青静斉税脆隻席惜戚斥昔析石積籍績脊責赤跡蹟碩切拙接摂折設窃節説雪絶舌蝉仙先千占宣専尖川戦扇撰栓栴泉浅洗染潜煎煽旋穿箭線'],
|
||||
[0x9140, '繊羨腺舛船薦詮賎践選遷銭銑閃鮮前善漸然全禅繕膳糎噌塑岨措曾曽楚狙疏疎礎祖租粗素組蘇訴阻遡鼠僧創双叢倉喪壮奏爽宋層匝惣想捜掃挿掻'],
|
||||
[0x9180, '操早曹巣槍槽漕燥争痩相窓糟総綜聡草荘葬蒼藻装走送遭鎗霜騒像増憎臓蔵贈造促側則即息捉束測足速俗属賊族続卒袖其揃存孫尊損村遜他多太汰詑唾堕妥惰打柁舵楕陀駄騨体堆対耐岱帯待怠態戴替泰滞胎腿苔袋貸退逮隊黛鯛代台大第醍題鷹滝瀧卓啄宅托択拓沢濯琢託鐸濁諾茸凧蛸只'],
|
||||
[0x9240, '叩但達辰奪脱巽竪辿棚谷狸鱈樽誰丹単嘆坦担探旦歎淡湛炭短端箪綻耽胆蛋誕鍛団壇弾断暖檀段男談値知地弛恥智池痴稚置致蜘遅馳築畜竹筑蓄'],
|
||||
[0x9280, '逐秩窒茶嫡着中仲宙忠抽昼柱注虫衷註酎鋳駐樗瀦猪苧著貯丁兆凋喋寵帖帳庁弔張彫徴懲挑暢朝潮牒町眺聴脹腸蝶調諜超跳銚長頂鳥勅捗直朕沈珍賃鎮陳津墜椎槌追鎚痛通塚栂掴槻佃漬柘辻蔦綴鍔椿潰坪壷嬬紬爪吊釣鶴亭低停偵剃貞呈堤定帝底庭廷弟悌抵挺提梯汀碇禎程締艇訂諦蹄逓'],
|
||||
[0x9340, '邸鄭釘鼎泥摘擢敵滴的笛適鏑溺哲徹撤轍迭鉄典填天展店添纏甜貼転顛点伝殿澱田電兎吐堵塗妬屠徒斗杜渡登菟賭途都鍍砥砺努度土奴怒倒党冬'],
|
||||
[0x9380, '凍刀唐塔塘套宕島嶋悼投搭東桃梼棟盗淘湯涛灯燈当痘祷等答筒糖統到董蕩藤討謄豆踏逃透鐙陶頭騰闘働動同堂導憧撞洞瞳童胴萄道銅峠鴇匿得徳涜特督禿篤毒独読栃橡凸突椴届鳶苫寅酉瀞噸屯惇敦沌豚遁頓呑曇鈍奈那内乍凪薙謎灘捺鍋楢馴縄畷南楠軟難汝二尼弐迩匂賑肉虹廿日乳入'],
|
||||
[0x9440, '如尿韮任妊忍認濡禰祢寧葱猫熱年念捻撚燃粘乃廼之埜嚢悩濃納能脳膿農覗蚤巴把播覇杷波派琶破婆罵芭馬俳廃拝排敗杯盃牌背肺輩配倍培媒梅'],
|
||||
[0x9480, '楳煤狽買売賠陪這蝿秤矧萩伯剥博拍柏泊白箔粕舶薄迫曝漠爆縛莫駁麦函箱硲箸肇筈櫨幡肌畑畠八鉢溌発醗髪伐罰抜筏閥鳩噺塙蛤隼伴判半反叛帆搬斑板氾汎版犯班畔繁般藩販範釆煩頒飯挽晩番盤磐蕃蛮匪卑否妃庇彼悲扉批披斐比泌疲皮碑秘緋罷肥被誹費避非飛樋簸備尾微枇毘琵眉美'],
|
||||
[0x9540, '鼻柊稗匹疋髭彦膝菱肘弼必畢筆逼桧姫媛紐百謬俵彪標氷漂瓢票表評豹廟描病秒苗錨鋲蒜蛭鰭品彬斌浜瀕貧賓頻敏瓶不付埠夫婦富冨布府怖扶敷'],
|
||||
[0x9580, '斧普浮父符腐膚芙譜負賦赴阜附侮撫武舞葡蕪部封楓風葺蕗伏副復幅服福腹複覆淵弗払沸仏物鮒分吻噴墳憤扮焚奮粉糞紛雰文聞丙併兵塀幣平弊柄並蔽閉陛米頁僻壁癖碧別瞥蔑箆偏変片篇編辺返遍便勉娩弁鞭保舗鋪圃捕歩甫補輔穂募墓慕戊暮母簿菩倣俸包呆報奉宝峰峯崩庖抱捧放方朋'],
|
||||
[0x9640, '法泡烹砲縫胞芳萌蓬蜂褒訪豊邦鋒飽鳳鵬乏亡傍剖坊妨帽忘忙房暴望某棒冒紡肪膨謀貌貿鉾防吠頬北僕卜墨撲朴牧睦穆釦勃没殆堀幌奔本翻凡盆'],
|
||||
[0x9680, '摩磨魔麻埋妹昧枚毎哩槙幕膜枕鮪柾鱒桝亦俣又抹末沫迄侭繭麿万慢満漫蔓味未魅巳箕岬密蜜湊蓑稔脈妙粍民眠務夢無牟矛霧鵡椋婿娘冥名命明盟迷銘鳴姪牝滅免棉綿緬面麺摸模茂妄孟毛猛盲網耗蒙儲木黙目杢勿餅尤戻籾貰問悶紋門匁也冶夜爺耶野弥矢厄役約薬訳躍靖柳薮鑓愉愈油癒'],
|
||||
[0x9740, '諭輸唯佑優勇友宥幽悠憂揖有柚湧涌猶猷由祐裕誘遊邑郵雄融夕予余与誉輿預傭幼妖容庸揚揺擁曜楊様洋溶熔用窯羊耀葉蓉要謡踊遥陽養慾抑欲'],
|
||||
[0x9780, '沃浴翌翼淀羅螺裸来莱頼雷洛絡落酪乱卵嵐欄濫藍蘭覧利吏履李梨理璃痢裏裡里離陸律率立葎掠略劉流溜琉留硫粒隆竜龍侶慮旅虜了亮僚両凌寮料梁涼猟療瞭稜糧良諒遼量陵領力緑倫厘林淋燐琳臨輪隣鱗麟瑠塁涙累類令伶例冷励嶺怜玲礼苓鈴隷零霊麗齢暦歴列劣烈裂廉恋憐漣煉簾練聯'],
|
||||
[0x9840, '蓮連錬呂魯櫓炉賂路露労婁廊弄朗楼榔浪漏牢狼篭老聾蝋郎六麓禄肋録論倭和話歪賄脇惑枠鷲亙亘鰐詫藁蕨椀湾碗腕'],
|
||||
[0x989f, '弌丐丕个丱丶丼丿乂乖乘亂亅豫亊舒弍于亞亟亠亢亰亳亶从仍仄仆仂仗仞仭仟价伉佚估佛佝佗佇佶侈侏侘佻佩佰侑佯來侖儘俔俟俎俘俛俑俚俐俤俥倚倨倔倪倥倅伜俶倡倩倬俾俯們倆偃假會偕偐偈做偖偬偸傀傚傅傴傲'],
|
||||
[0x9940, '僉僊傳僂僖僞僥僭僣僮價僵儉儁儂儖儕儔儚儡儺儷儼儻儿兀兒兌兔兢竸兩兪兮冀冂囘册冉冏冑冓冕冖冤冦冢冩冪冫决冱冲冰况冽凅凉凛几處凩凭'],
|
||||
[0x9980, '凰凵凾刄刋刔刎刧刪刮刳刹剏剄剋剌剞剔剪剴剩剳剿剽劍劔劒剱劈劑辨辧劬劭劼劵勁勍勗勞勣勦飭勠勳勵勸勹匆匈甸匍匐匏匕匚匣匯匱匳匸區卆卅丗卉卍凖卞卩卮夘卻卷厂厖厠厦厥厮厰厶參簒雙叟曼燮叮叨叭叺吁吽呀听吭吼吮吶吩吝呎咏呵咎呟呱呷呰咒呻咀呶咄咐咆哇咢咸咥咬哄哈咨'],
|
||||
[0x9a40, '咫哂咤咾咼哘哥哦唏唔哽哮哭哺哢唹啀啣啌售啜啅啖啗唸唳啝喙喀咯喊喟啻啾喘喞單啼喃喩喇喨嗚嗅嗟嗄嗜嗤嗔嘔嗷嘖嗾嗽嘛嗹噎噐營嘴嘶嘲嘸'],
|
||||
[0x9a80, '噫噤嘯噬噪嚆嚀嚊嚠嚔嚏嚥嚮嚶嚴囂嚼囁囃囀囈囎囑囓囗囮囹圀囿圄圉圈國圍圓團圖嗇圜圦圷圸坎圻址坏坩埀垈坡坿垉垓垠垳垤垪垰埃埆埔埒埓堊埖埣堋堙堝塲堡塢塋塰毀塒堽塹墅墹墟墫墺壞墻墸墮壅壓壑壗壙壘壥壜壤壟壯壺壹壻壼壽夂夊夐夛梦夥夬夭夲夸夾竒奕奐奎奚奘奢奠奧奬奩'],
|
||||
[0x9b40, '奸妁妝佞侫妣妲姆姨姜妍姙姚娥娟娑娜娉娚婀婬婉娵娶婢婪媚媼媾嫋嫂媽嫣嫗嫦嫩嫖嫺嫻嬌嬋嬖嬲嫐嬪嬶嬾孃孅孀孑孕孚孛孥孩孰孳孵學斈孺宀'],
|
||||
[0x9b80, '它宦宸寃寇寉寔寐寤實寢寞寥寫寰寶寳尅將專對尓尠尢尨尸尹屁屆屎屓屐屏孱屬屮乢屶屹岌岑岔妛岫岻岶岼岷峅岾峇峙峩峽峺峭嶌峪崋崕崗嵜崟崛崑崔崢崚崙崘嵌嵒嵎嵋嵬嵳嵶嶇嶄嶂嶢嶝嶬嶮嶽嶐嶷嶼巉巍巓巒巖巛巫已巵帋帚帙帑帛帶帷幄幃幀幎幗幔幟幢幤幇幵并幺麼广庠廁廂廈廐廏'],
|
||||
[0x9c40, '廖廣廝廚廛廢廡廨廩廬廱廳廰廴廸廾弃弉彝彜弋弑弖弩弭弸彁彈彌彎弯彑彖彗彙彡彭彳彷徃徂彿徊很徑徇從徙徘徠徨徭徼忖忻忤忸忱忝悳忿怡恠'],
|
||||
[0x9c80, '怙怐怩怎怱怛怕怫怦怏怺恚恁恪恷恟恊恆恍恣恃恤恂恬恫恙悁悍惧悃悚悄悛悖悗悒悧悋惡悸惠惓悴忰悽惆悵惘慍愕愆惶惷愀惴惺愃愡惻惱愍愎慇愾愨愧慊愿愼愬愴愽慂慄慳慷慘慙慚慫慴慯慥慱慟慝慓慵憙憖憇憬憔憚憊憑憫憮懌懊應懷懈懃懆憺懋罹懍懦懣懶懺懴懿懽懼懾戀戈戉戍戌戔戛'],
|
||||
[0x9d40, '戞戡截戮戰戲戳扁扎扞扣扛扠扨扼抂抉找抒抓抖拔抃抔拗拑抻拏拿拆擔拈拜拌拊拂拇抛拉挌拮拱挧挂挈拯拵捐挾捍搜捏掖掎掀掫捶掣掏掉掟掵捫'],
|
||||
[0x9d80, '捩掾揩揀揆揣揉插揶揄搖搴搆搓搦搶攝搗搨搏摧摯摶摎攪撕撓撥撩撈撼據擒擅擇撻擘擂擱擧舉擠擡抬擣擯攬擶擴擲擺攀擽攘攜攅攤攣攫攴攵攷收攸畋效敖敕敍敘敞敝敲數斂斃變斛斟斫斷旃旆旁旄旌旒旛旙无旡旱杲昊昃旻杳昵昶昴昜晏晄晉晁晞晝晤晧晨晟晢晰暃暈暎暉暄暘暝曁暹曉暾暼'],
|
||||
[0x9e40, '曄暸曖曚曠昿曦曩曰曵曷朏朖朞朦朧霸朮朿朶杁朸朷杆杞杠杙杣杤枉杰枩杼杪枌枋枦枡枅枷柯枴柬枳柩枸柤柞柝柢柮枹柎柆柧檜栞框栩桀桍栲桎'],
|
||||
[0x9e80, '梳栫桙档桷桿梟梏梭梔條梛梃檮梹桴梵梠梺椏梍桾椁棊椈棘椢椦棡椌棍棔棧棕椶椒椄棗棣椥棹棠棯椨椪椚椣椡棆楹楷楜楸楫楔楾楮椹楴椽楙椰楡楞楝榁楪榲榮槐榿槁槓榾槎寨槊槝榻槃榧樮榑榠榜榕榴槞槨樂樛槿權槹槲槧樅榱樞槭樔槫樊樒櫁樣樓橄樌橲樶橸橇橢橙橦橈樸樢檐檍檠檄檢檣'],
|
||||
[0x9f40, '檗蘗檻櫃櫂檸檳檬櫞櫑櫟檪櫚櫪櫻欅蘖櫺欒欖鬱欟欸欷盜欹飮歇歃歉歐歙歔歛歟歡歸歹歿殀殄殃殍殘殕殞殤殪殫殯殲殱殳殷殼毆毋毓毟毬毫毳毯'],
|
||||
[0x9f80, '麾氈氓气氛氤氣汞汕汢汪沂沍沚沁沛汾汨汳沒沐泄泱泓沽泗泅泝沮沱沾沺泛泯泙泪洟衍洶洫洽洸洙洵洳洒洌浣涓浤浚浹浙涎涕濤涅淹渕渊涵淇淦涸淆淬淞淌淨淒淅淺淙淤淕淪淮渭湮渮渙湲湟渾渣湫渫湶湍渟湃渺湎渤滿渝游溂溪溘滉溷滓溽溯滄溲滔滕溏溥滂溟潁漑灌滬滸滾漿滲漱滯漲滌'],
|
||||
[0xe040, '漾漓滷澆潺潸澁澀潯潛濳潭澂潼潘澎澑濂潦澳澣澡澤澹濆澪濟濕濬濔濘濱濮濛瀉瀋濺瀑瀁瀏濾瀛瀚潴瀝瀘瀟瀰瀾瀲灑灣炙炒炯烱炬炸炳炮烟烋烝'],
|
||||
[0xe080, '烙焉烽焜焙煥煕熈煦煢煌煖煬熏燻熄熕熨熬燗熹熾燒燉燔燎燠燬燧燵燼燹燿爍爐爛爨爭爬爰爲爻爼爿牀牆牋牘牴牾犂犁犇犒犖犢犧犹犲狃狆狄狎狒狢狠狡狹狷倏猗猊猜猖猝猴猯猩猥猾獎獏默獗獪獨獰獸獵獻獺珈玳珎玻珀珥珮珞璢琅瑯琥珸琲琺瑕琿瑟瑙瑁瑜瑩瑰瑣瑪瑶瑾璋璞璧瓊瓏瓔珱'],
|
||||
[0xe140, '瓠瓣瓧瓩瓮瓲瓰瓱瓸瓷甄甃甅甌甎甍甕甓甞甦甬甼畄畍畊畉畛畆畚畩畤畧畫畭畸當疆疇畴疊疉疂疔疚疝疥疣痂疳痃疵疽疸疼疱痍痊痒痙痣痞痾痿'],
|
||||
[0xe180, '痼瘁痰痺痲痳瘋瘍瘉瘟瘧瘠瘡瘢瘤瘴瘰瘻癇癈癆癜癘癡癢癨癩癪癧癬癰癲癶癸發皀皃皈皋皎皖皓皙皚皰皴皸皹皺盂盍盖盒盞盡盥盧盪蘯盻眈眇眄眩眤眞眥眦眛眷眸睇睚睨睫睛睥睿睾睹瞎瞋瞑瞠瞞瞰瞶瞹瞿瞼瞽瞻矇矍矗矚矜矣矮矼砌砒礦砠礪硅碎硴碆硼碚碌碣碵碪碯磑磆磋磔碾碼磅磊磬'],
|
||||
[0xe240, '磧磚磽磴礇礒礑礙礬礫祀祠祗祟祚祕祓祺祿禊禝禧齋禪禮禳禹禺秉秕秧秬秡秣稈稍稘稙稠稟禀稱稻稾稷穃穗穉穡穢穩龝穰穹穽窈窗窕窘窖窩竈窰'],
|
||||
[0xe280, '窶竅竄窿邃竇竊竍竏竕竓站竚竝竡竢竦竭竰笂笏笊笆笳笘笙笞笵笨笶筐筺笄筍笋筌筅筵筥筴筧筰筱筬筮箝箘箟箍箜箚箋箒箏筝箙篋篁篌篏箴篆篝篩簑簔篦篥籠簀簇簓篳篷簗簍篶簣簧簪簟簷簫簽籌籃籔籏籀籐籘籟籤籖籥籬籵粃粐粤粭粢粫粡粨粳粲粱粮粹粽糀糅糂糘糒糜糢鬻糯糲糴糶糺紆'],
|
||||
[0xe340, '紂紜紕紊絅絋紮紲紿紵絆絳絖絎絲絨絮絏絣經綉絛綏絽綛綺綮綣綵緇綽綫總綢綯緜綸綟綰緘緝緤緞緻緲緡縅縊縣縡縒縱縟縉縋縢繆繦縻縵縹繃縷'],
|
||||
[0xe380, '縲縺繧繝繖繞繙繚繹繪繩繼繻纃緕繽辮繿纈纉續纒纐纓纔纖纎纛纜缸缺罅罌罍罎罐网罕罔罘罟罠罨罩罧罸羂羆羃羈羇羌羔羞羝羚羣羯羲羹羮羶羸譱翅翆翊翕翔翡翦翩翳翹飜耆耄耋耒耘耙耜耡耨耿耻聊聆聒聘聚聟聢聨聳聲聰聶聹聽聿肄肆肅肛肓肚肭冐肬胛胥胙胝胄胚胖脉胯胱脛脩脣脯腋'],
|
||||
[0xe440, '隋腆脾腓腑胼腱腮腥腦腴膃膈膊膀膂膠膕膤膣腟膓膩膰膵膾膸膽臀臂膺臉臍臑臙臘臈臚臟臠臧臺臻臾舁舂舅與舊舍舐舖舩舫舸舳艀艙艘艝艚艟艤'],
|
||||
[0xe480, '艢艨艪艫舮艱艷艸艾芍芒芫芟芻芬苡苣苟苒苴苳苺莓范苻苹苞茆苜茉苙茵茴茖茲茱荀茹荐荅茯茫茗茘莅莚莪莟莢莖茣莎莇莊荼莵荳荵莠莉莨菴萓菫菎菽萃菘萋菁菷萇菠菲萍萢萠莽萸蔆菻葭萪萼蕚蒄葷葫蒭葮蒂葩葆萬葯葹萵蓊葢蒹蒿蒟蓙蓍蒻蓚蓐蓁蓆蓖蒡蔡蓿蓴蔗蔘蔬蔟蔕蔔蓼蕀蕣蕘蕈'],
|
||||
[0xe540, '蕁蘂蕋蕕薀薤薈薑薊薨蕭薔薛藪薇薜蕷蕾薐藉薺藏薹藐藕藝藥藜藹蘊蘓蘋藾藺蘆蘢蘚蘰蘿虍乕虔號虧虱蚓蚣蚩蚪蚋蚌蚶蚯蛄蛆蚰蛉蠣蚫蛔蛞蛩蛬'],
|
||||
[0xe580, '蛟蛛蛯蜒蜆蜈蜀蜃蛻蜑蜉蜍蛹蜊蜴蜿蜷蜻蜥蜩蜚蝠蝟蝸蝌蝎蝴蝗蝨蝮蝙蝓蝣蝪蠅螢螟螂螯蟋螽蟀蟐雖螫蟄螳蟇蟆螻蟯蟲蟠蠏蠍蟾蟶蟷蠎蟒蠑蠖蠕蠢蠡蠱蠶蠹蠧蠻衄衂衒衙衞衢衫袁衾袞衵衽袵衲袂袗袒袮袙袢袍袤袰袿袱裃裄裔裘裙裝裹褂裼裴裨裲褄褌褊褓襃褞褥褪褫襁襄褻褶褸襌褝襠襞'],
|
||||
[0xe640, '襦襤襭襪襯襴襷襾覃覈覊覓覘覡覩覦覬覯覲覺覽覿觀觚觜觝觧觴觸訃訖訐訌訛訝訥訶詁詛詒詆詈詼詭詬詢誅誂誄誨誡誑誥誦誚誣諄諍諂諚諫諳諧'],
|
||||
[0xe680, '諤諱謔諠諢諷諞諛謌謇謚諡謖謐謗謠謳鞫謦謫謾謨譁譌譏譎證譖譛譚譫譟譬譯譴譽讀讌讎讒讓讖讙讚谺豁谿豈豌豎豐豕豢豬豸豺貂貉貅貊貍貎貔豼貘戝貭貪貽貲貳貮貶賈賁賤賣賚賽賺賻贄贅贊贇贏贍贐齎贓賍贔贖赧赭赱赳趁趙跂趾趺跏跚跖跌跛跋跪跫跟跣跼踈踉跿踝踞踐踟蹂踵踰踴蹊'],
|
||||
[0xe740, '蹇蹉蹌蹐蹈蹙蹤蹠踪蹣蹕蹶蹲蹼躁躇躅躄躋躊躓躑躔躙躪躡躬躰軆躱躾軅軈軋軛軣軼軻軫軾輊輅輕輒輙輓輜輟輛輌輦輳輻輹轅轂輾轌轉轆轎轗轜'],
|
||||
[0xe780, '轢轣轤辜辟辣辭辯辷迚迥迢迪迯邇迴逅迹迺逑逕逡逍逞逖逋逧逶逵逹迸遏遐遑遒逎遉逾遖遘遞遨遯遶隨遲邂遽邁邀邊邉邏邨邯邱邵郢郤扈郛鄂鄒鄙鄲鄰酊酖酘酣酥酩酳酲醋醉醂醢醫醯醪醵醴醺釀釁釉釋釐釖釟釡釛釼釵釶鈞釿鈔鈬鈕鈑鉞鉗鉅鉉鉤鉈銕鈿鉋鉐銜銖銓銛鉚鋏銹銷鋩錏鋺鍄錮'],
|
||||
[0xe840, '錙錢錚錣錺錵錻鍜鍠鍼鍮鍖鎰鎬鎭鎔鎹鏖鏗鏨鏥鏘鏃鏝鏐鏈鏤鐚鐔鐓鐃鐇鐐鐶鐫鐵鐡鐺鑁鑒鑄鑛鑠鑢鑞鑪鈩鑰鑵鑷鑽鑚鑼鑾钁鑿閂閇閊閔閖閘閙'],
|
||||
[0xe880, '閠閨閧閭閼閻閹閾闊濶闃闍闌闕闔闖關闡闥闢阡阨阮阯陂陌陏陋陷陜陞陝陟陦陲陬隍隘隕隗險隧隱隲隰隴隶隸隹雎雋雉雍襍雜霍雕雹霄霆霈霓霎霑霏霖霙霤霪霰霹霽霾靄靆靈靂靉靜靠靤靦靨勒靫靱靹鞅靼鞁靺鞆鞋鞏鞐鞜鞨鞦鞣鞳鞴韃韆韈韋韜韭齏韲竟韶韵頏頌頸頤頡頷頽顆顏顋顫顯顰'],
|
||||
[0xe940, '顱顴顳颪颯颱颶飄飃飆飩飫餃餉餒餔餘餡餝餞餤餠餬餮餽餾饂饉饅饐饋饑饒饌饕馗馘馥馭馮馼駟駛駝駘駑駭駮駱駲駻駸騁騏騅駢騙騫騷驅驂驀驃'],
|
||||
[0xe980, '騾驕驍驛驗驟驢驥驤驩驫驪骭骰骼髀髏髑髓體髞髟髢髣髦髯髫髮髴髱髷髻鬆鬘鬚鬟鬢鬣鬥鬧鬨鬩鬪鬮鬯鬲魄魃魏魍魎魑魘魴鮓鮃鮑鮖鮗鮟鮠鮨鮴鯀鯊鮹鯆鯏鯑鯒鯣鯢鯤鯔鯡鰺鯲鯱鯰鰕鰔鰉鰓鰌鰆鰈鰒鰊鰄鰮鰛鰥鰤鰡鰰鱇鰲鱆鰾鱚鱠鱧鱶鱸鳧鳬鳰鴉鴈鳫鴃鴆鴪鴦鶯鴣鴟鵄鴕鴒鵁鴿鴾鵆鵈'],
|
||||
[0xea40, '鵝鵞鵤鵑鵐鵙鵲鶉鶇鶫鵯鵺鶚鶤鶩鶲鷄鷁鶻鶸鶺鷆鷏鷂鷙鷓鷸鷦鷭鷯鷽鸚鸛鸞鹵鹹鹽麁麈麋麌麒麕麑麝麥麩麸麪麭靡黌黎黏黐黔黜點黝黠黥黨黯'],
|
||||
[0xea80, '黴黶黷黹黻黼黽鼇鼈皷鼕鼡鼬鼾齊齒齔齣齟齠齡齦齧齬齪齷齲齶龕龜龠堯槇遙瑤凜熙']
|
||||
]
|
||||
|
||||
module.exports = function toSJIS (utf8Char) {
|
||||
if (!utf8Char || utf8Char === '') return
|
||||
|
||||
for (let i = 0; i < SJIS_UTF8.length; i++) {
|
||||
const kanji = SJIS_UTF8[i][1]
|
||||
|
||||
const posIndex = kanji.indexOf(utf8Char)
|
||||
if (posIndex >= 0) {
|
||||
return SJIS_UTF8[i][0] + posIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
76
node_modules/qrcode/lib/browser.js
generated
vendored
Normal file
76
node_modules/qrcode/lib/browser.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
|
||||
const canPromise = require('./can-promise')
|
||||
|
||||
const QRCode = require('./core/qrcode')
|
||||
const CanvasRenderer = require('./renderer/canvas')
|
||||
const SvgRenderer = require('./renderer/svg-tag.js')
|
||||
|
||||
function renderCanvas (renderFunc, canvas, text, opts, cb) {
|
||||
const args = [].slice.call(arguments, 1)
|
||||
const argsNum = args.length
|
||||
const isLastArgCb = typeof args[argsNum - 1] === 'function'
|
||||
|
||||
if (!isLastArgCb && !canPromise()) {
|
||||
throw new Error('Callback required as last argument')
|
||||
}
|
||||
|
||||
if (isLastArgCb) {
|
||||
if (argsNum < 2) {
|
||||
throw new Error('Too few arguments provided')
|
||||
}
|
||||
|
||||
if (argsNum === 2) {
|
||||
cb = text
|
||||
text = canvas
|
||||
canvas = opts = undefined
|
||||
} else if (argsNum === 3) {
|
||||
if (canvas.getContext && typeof cb === 'undefined') {
|
||||
cb = opts
|
||||
opts = undefined
|
||||
} else {
|
||||
cb = opts
|
||||
opts = text
|
||||
text = canvas
|
||||
canvas = undefined
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (argsNum < 1) {
|
||||
throw new Error('Too few arguments provided')
|
||||
}
|
||||
|
||||
if (argsNum === 1) {
|
||||
text = canvas
|
||||
canvas = opts = undefined
|
||||
} else if (argsNum === 2 && !canvas.getContext) {
|
||||
opts = text
|
||||
text = canvas
|
||||
canvas = undefined
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
const data = QRCode.create(text, opts)
|
||||
resolve(renderFunc(data, canvas, opts))
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
const data = QRCode.create(text, opts)
|
||||
cb(null, renderFunc(data, canvas, opts))
|
||||
} catch (e) {
|
||||
cb(e)
|
||||
}
|
||||
}
|
||||
|
||||
exports.create = QRCode.create
|
||||
exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render)
|
||||
exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL)
|
||||
|
||||
// only svg for now.
|
||||
exports.toString = renderCanvas.bind(null, function (data, _, opts) {
|
||||
return SvgRenderer.render(data, opts)
|
||||
})
|
||||
7
node_modules/qrcode/lib/can-promise.js
generated
vendored
Normal file
7
node_modules/qrcode/lib/can-promise.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// can-promise has a crash in some versions of react native that dont have
|
||||
// standard global objects
|
||||
// https://github.com/soldair/node-qrcode/issues/157
|
||||
|
||||
module.exports = function () {
|
||||
return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
|
||||
}
|
||||
83
node_modules/qrcode/lib/core/alignment-pattern.js
generated
vendored
Normal file
83
node_modules/qrcode/lib/core/alignment-pattern.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Alignment pattern are fixed reference pattern in defined positions
|
||||
* in a matrix symbology, which enables the decode software to re-synchronise
|
||||
* the coordinate mapping of the image modules in the event of moderate amounts
|
||||
* of distortion of the image.
|
||||
*
|
||||
* Alignment patterns are present only in QR Code symbols of version 2 or larger
|
||||
* and their number depends on the symbol version.
|
||||
*/
|
||||
|
||||
const getSymbolSize = require('./utils').getSymbolSize
|
||||
|
||||
/**
|
||||
* Calculate the row/column coordinates of the center module of each alignment pattern
|
||||
* for the specified QR Code version.
|
||||
*
|
||||
* The alignment patterns are positioned symmetrically on either side of the diagonal
|
||||
* running from the top left corner of the symbol to the bottom right corner.
|
||||
*
|
||||
* Since positions are simmetrical only half of the coordinates are returned.
|
||||
* Each item of the array will represent in turn the x and y coordinate.
|
||||
* @see {@link getPositions}
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Array} Array of coordinate
|
||||
*/
|
||||
exports.getRowColCoords = function getRowColCoords (version) {
|
||||
if (version === 1) return []
|
||||
|
||||
const posCount = Math.floor(version / 7) + 2
|
||||
const size = getSymbolSize(version)
|
||||
const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2
|
||||
const positions = [size - 7] // Last coord is always (size - 7)
|
||||
|
||||
for (let i = 1; i < posCount - 1; i++) {
|
||||
positions[i] = positions[i - 1] - intervals
|
||||
}
|
||||
|
||||
positions.push(6) // First coord is always 6
|
||||
|
||||
return positions.reverse()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the positions of each alignment pattern.
|
||||
* Each array's element represent the center point of the pattern as (x, y) coordinates
|
||||
*
|
||||
* Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
|
||||
* and filtering out the items that overlaps with finder pattern
|
||||
*
|
||||
* @example
|
||||
* For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
|
||||
* The alignment patterns, therefore, are to be centered on (row, column)
|
||||
* positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
|
||||
* Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
|
||||
* and are not therefore used for alignment patterns.
|
||||
*
|
||||
* let pos = getPositions(7)
|
||||
* // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Array} Array of coordinates
|
||||
*/
|
||||
exports.getPositions = function getPositions (version) {
|
||||
const coords = []
|
||||
const pos = exports.getRowColCoords(version)
|
||||
const posLength = pos.length
|
||||
|
||||
for (let i = 0; i < posLength; i++) {
|
||||
for (let j = 0; j < posLength; j++) {
|
||||
// Skip if position is occupied by finder patterns
|
||||
if ((i === 0 && j === 0) || // top-left
|
||||
(i === 0 && j === posLength - 1) || // bottom-left
|
||||
(i === posLength - 1 && j === 0)) { // top-right
|
||||
continue
|
||||
}
|
||||
|
||||
coords.push([pos[i], pos[j]])
|
||||
}
|
||||
}
|
||||
|
||||
return coords
|
||||
}
|
||||
59
node_modules/qrcode/lib/core/alphanumeric-data.js
generated
vendored
Normal file
59
node_modules/qrcode/lib/core/alphanumeric-data.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
const Mode = require('./mode')
|
||||
|
||||
/**
|
||||
* Array of characters available in alphanumeric mode
|
||||
*
|
||||
* As per QR Code specification, to each character
|
||||
* is assigned a value from 0 to 44 which in this case coincides
|
||||
* with the array index
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
const ALPHA_NUM_CHARS = [
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
' ', '$', '%', '*', '+', '-', '.', '/', ':'
|
||||
]
|
||||
|
||||
function AlphanumericData (data) {
|
||||
this.mode = Mode.ALPHANUMERIC
|
||||
this.data = data
|
||||
}
|
||||
|
||||
AlphanumericData.getBitsLength = function getBitsLength (length) {
|
||||
return 11 * Math.floor(length / 2) + 6 * (length % 2)
|
||||
}
|
||||
|
||||
AlphanumericData.prototype.getLength = function getLength () {
|
||||
return this.data.length
|
||||
}
|
||||
|
||||
AlphanumericData.prototype.getBitsLength = function getBitsLength () {
|
||||
return AlphanumericData.getBitsLength(this.data.length)
|
||||
}
|
||||
|
||||
AlphanumericData.prototype.write = function write (bitBuffer) {
|
||||
let i
|
||||
|
||||
// Input data characters are divided into groups of two characters
|
||||
// and encoded as 11-bit binary codes.
|
||||
for (i = 0; i + 2 <= this.data.length; i += 2) {
|
||||
// The character value of the first character is multiplied by 45
|
||||
let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45
|
||||
|
||||
// The character value of the second digit is added to the product
|
||||
value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1])
|
||||
|
||||
// The sum is then stored as 11-bit binary number
|
||||
bitBuffer.put(value, 11)
|
||||
}
|
||||
|
||||
// If the number of input data characters is not a multiple of two,
|
||||
// the character value of the final character is encoded as a 6-bit binary number.
|
||||
if (this.data.length % 2) {
|
||||
bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AlphanumericData
|
||||
37
node_modules/qrcode/lib/core/bit-buffer.js
generated
vendored
Normal file
37
node_modules/qrcode/lib/core/bit-buffer.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
function BitBuffer () {
|
||||
this.buffer = []
|
||||
this.length = 0
|
||||
}
|
||||
|
||||
BitBuffer.prototype = {
|
||||
|
||||
get: function (index) {
|
||||
const bufIndex = Math.floor(index / 8)
|
||||
return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
|
||||
},
|
||||
|
||||
put: function (num, length) {
|
||||
for (let i = 0; i < length; i++) {
|
||||
this.putBit(((num >>> (length - i - 1)) & 1) === 1)
|
||||
}
|
||||
},
|
||||
|
||||
getLengthInBits: function () {
|
||||
return this.length
|
||||
},
|
||||
|
||||
putBit: function (bit) {
|
||||
const bufIndex = Math.floor(this.length / 8)
|
||||
if (this.buffer.length <= bufIndex) {
|
||||
this.buffer.push(0)
|
||||
}
|
||||
|
||||
if (bit) {
|
||||
this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))
|
||||
}
|
||||
|
||||
this.length++
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BitBuffer
|
||||
65
node_modules/qrcode/lib/core/bit-matrix.js
generated
vendored
Normal file
65
node_modules/qrcode/lib/core/bit-matrix.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Helper class to handle QR Code symbol modules
|
||||
*
|
||||
* @param {Number} size Symbol size
|
||||
*/
|
||||
function BitMatrix (size) {
|
||||
if (!size || size < 1) {
|
||||
throw new Error('BitMatrix size must be defined and greater than 0')
|
||||
}
|
||||
|
||||
this.size = size
|
||||
this.data = new Uint8Array(size * size)
|
||||
this.reservedBit = new Uint8Array(size * size)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bit value at specified location
|
||||
* If reserved flag is set, this bit will be ignored during masking process
|
||||
*
|
||||
* @param {Number} row
|
||||
* @param {Number} col
|
||||
* @param {Boolean} value
|
||||
* @param {Boolean} reserved
|
||||
*/
|
||||
BitMatrix.prototype.set = function (row, col, value, reserved) {
|
||||
const index = row * this.size + col
|
||||
this.data[index] = value
|
||||
if (reserved) this.reservedBit[index] = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns bit value at specified location
|
||||
*
|
||||
* @param {Number} row
|
||||
* @param {Number} col
|
||||
* @return {Boolean}
|
||||
*/
|
||||
BitMatrix.prototype.get = function (row, col) {
|
||||
return this.data[row * this.size + col]
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies xor operator at specified location
|
||||
* (used during masking process)
|
||||
*
|
||||
* @param {Number} row
|
||||
* @param {Number} col
|
||||
* @param {Boolean} value
|
||||
*/
|
||||
BitMatrix.prototype.xor = function (row, col, value) {
|
||||
this.data[row * this.size + col] ^= value
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if bit at specified location is reserved
|
||||
*
|
||||
* @param {Number} row
|
||||
* @param {Number} col
|
||||
* @return {Boolean}
|
||||
*/
|
||||
BitMatrix.prototype.isReserved = function (row, col) {
|
||||
return this.reservedBit[row * this.size + col]
|
||||
}
|
||||
|
||||
module.exports = BitMatrix
|
||||
30
node_modules/qrcode/lib/core/byte-data.js
generated
vendored
Normal file
30
node_modules/qrcode/lib/core/byte-data.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
const Mode = require('./mode')
|
||||
|
||||
function ByteData (data) {
|
||||
this.mode = Mode.BYTE
|
||||
if (typeof (data) === 'string') {
|
||||
this.data = new TextEncoder().encode(data)
|
||||
} else {
|
||||
this.data = new Uint8Array(data)
|
||||
}
|
||||
}
|
||||
|
||||
ByteData.getBitsLength = function getBitsLength (length) {
|
||||
return length * 8
|
||||
}
|
||||
|
||||
ByteData.prototype.getLength = function getLength () {
|
||||
return this.data.length
|
||||
}
|
||||
|
||||
ByteData.prototype.getBitsLength = function getBitsLength () {
|
||||
return ByteData.getBitsLength(this.data.length)
|
||||
}
|
||||
|
||||
ByteData.prototype.write = function (bitBuffer) {
|
||||
for (let i = 0, l = this.data.length; i < l; i++) {
|
||||
bitBuffer.put(this.data[i], 8)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ByteData
|
||||
135
node_modules/qrcode/lib/core/error-correction-code.js
generated
vendored
Normal file
135
node_modules/qrcode/lib/core/error-correction-code.js
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
const ECLevel = require('./error-correction-level')
|
||||
|
||||
const EC_BLOCKS_TABLE = [
|
||||
// L M Q H
|
||||
1, 1, 1, 1,
|
||||
1, 1, 1, 1,
|
||||
1, 1, 2, 2,
|
||||
1, 2, 2, 4,
|
||||
1, 2, 4, 4,
|
||||
2, 4, 4, 4,
|
||||
2, 4, 6, 5,
|
||||
2, 4, 6, 6,
|
||||
2, 5, 8, 8,
|
||||
4, 5, 8, 8,
|
||||
4, 5, 8, 11,
|
||||
4, 8, 10, 11,
|
||||
4, 9, 12, 16,
|
||||
4, 9, 16, 16,
|
||||
6, 10, 12, 18,
|
||||
6, 10, 17, 16,
|
||||
6, 11, 16, 19,
|
||||
6, 13, 18, 21,
|
||||
7, 14, 21, 25,
|
||||
8, 16, 20, 25,
|
||||
8, 17, 23, 25,
|
||||
9, 17, 23, 34,
|
||||
9, 18, 25, 30,
|
||||
10, 20, 27, 32,
|
||||
12, 21, 29, 35,
|
||||
12, 23, 34, 37,
|
||||
12, 25, 34, 40,
|
||||
13, 26, 35, 42,
|
||||
14, 28, 38, 45,
|
||||
15, 29, 40, 48,
|
||||
16, 31, 43, 51,
|
||||
17, 33, 45, 54,
|
||||
18, 35, 48, 57,
|
||||
19, 37, 51, 60,
|
||||
19, 38, 53, 63,
|
||||
20, 40, 56, 66,
|
||||
21, 43, 59, 70,
|
||||
22, 45, 62, 74,
|
||||
24, 47, 65, 77,
|
||||
25, 49, 68, 81
|
||||
]
|
||||
|
||||
const EC_CODEWORDS_TABLE = [
|
||||
// L M Q H
|
||||
7, 10, 13, 17,
|
||||
10, 16, 22, 28,
|
||||
15, 26, 36, 44,
|
||||
20, 36, 52, 64,
|
||||
26, 48, 72, 88,
|
||||
36, 64, 96, 112,
|
||||
40, 72, 108, 130,
|
||||
48, 88, 132, 156,
|
||||
60, 110, 160, 192,
|
||||
72, 130, 192, 224,
|
||||
80, 150, 224, 264,
|
||||
96, 176, 260, 308,
|
||||
104, 198, 288, 352,
|
||||
120, 216, 320, 384,
|
||||
132, 240, 360, 432,
|
||||
144, 280, 408, 480,
|
||||
168, 308, 448, 532,
|
||||
180, 338, 504, 588,
|
||||
196, 364, 546, 650,
|
||||
224, 416, 600, 700,
|
||||
224, 442, 644, 750,
|
||||
252, 476, 690, 816,
|
||||
270, 504, 750, 900,
|
||||
300, 560, 810, 960,
|
||||
312, 588, 870, 1050,
|
||||
336, 644, 952, 1110,
|
||||
360, 700, 1020, 1200,
|
||||
390, 728, 1050, 1260,
|
||||
420, 784, 1140, 1350,
|
||||
450, 812, 1200, 1440,
|
||||
480, 868, 1290, 1530,
|
||||
510, 924, 1350, 1620,
|
||||
540, 980, 1440, 1710,
|
||||
570, 1036, 1530, 1800,
|
||||
570, 1064, 1590, 1890,
|
||||
600, 1120, 1680, 1980,
|
||||
630, 1204, 1770, 2100,
|
||||
660, 1260, 1860, 2220,
|
||||
720, 1316, 1950, 2310,
|
||||
750, 1372, 2040, 2430
|
||||
]
|
||||
|
||||
/**
|
||||
* Returns the number of error correction block that the QR Code should contain
|
||||
* for the specified version and error correction level.
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @param {Number} errorCorrectionLevel Error correction level
|
||||
* @return {Number} Number of error correction blocks
|
||||
*/
|
||||
exports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {
|
||||
switch (errorCorrectionLevel) {
|
||||
case ECLevel.L:
|
||||
return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
|
||||
case ECLevel.M:
|
||||
return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
|
||||
case ECLevel.Q:
|
||||
return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
|
||||
case ECLevel.H:
|
||||
return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of error correction codewords to use for the specified
|
||||
* version and error correction level.
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @param {Number} errorCorrectionLevel Error correction level
|
||||
* @return {Number} Number of error correction codewords
|
||||
*/
|
||||
exports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {
|
||||
switch (errorCorrectionLevel) {
|
||||
case ECLevel.L:
|
||||
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
|
||||
case ECLevel.M:
|
||||
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
|
||||
case ECLevel.Q:
|
||||
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
|
||||
case ECLevel.H:
|
||||
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
50
node_modules/qrcode/lib/core/error-correction-level.js
generated
vendored
Normal file
50
node_modules/qrcode/lib/core/error-correction-level.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
exports.L = { bit: 1 }
|
||||
exports.M = { bit: 0 }
|
||||
exports.Q = { bit: 3 }
|
||||
exports.H = { bit: 2 }
|
||||
|
||||
function fromString (string) {
|
||||
if (typeof string !== 'string') {
|
||||
throw new Error('Param is not a string')
|
||||
}
|
||||
|
||||
const lcStr = string.toLowerCase()
|
||||
|
||||
switch (lcStr) {
|
||||
case 'l':
|
||||
case 'low':
|
||||
return exports.L
|
||||
|
||||
case 'm':
|
||||
case 'medium':
|
||||
return exports.M
|
||||
|
||||
case 'q':
|
||||
case 'quartile':
|
||||
return exports.Q
|
||||
|
||||
case 'h':
|
||||
case 'high':
|
||||
return exports.H
|
||||
|
||||
default:
|
||||
throw new Error('Unknown EC Level: ' + string)
|
||||
}
|
||||
}
|
||||
|
||||
exports.isValid = function isValid (level) {
|
||||
return level && typeof level.bit !== 'undefined' &&
|
||||
level.bit >= 0 && level.bit < 4
|
||||
}
|
||||
|
||||
exports.from = function from (value, defaultValue) {
|
||||
if (exports.isValid(value)) {
|
||||
return value
|
||||
}
|
||||
|
||||
try {
|
||||
return fromString(value)
|
||||
} catch (e) {
|
||||
return defaultValue
|
||||
}
|
||||
}
|
||||
22
node_modules/qrcode/lib/core/finder-pattern.js
generated
vendored
Normal file
22
node_modules/qrcode/lib/core/finder-pattern.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
const getSymbolSize = require('./utils').getSymbolSize
|
||||
const FINDER_PATTERN_SIZE = 7
|
||||
|
||||
/**
|
||||
* Returns an array containing the positions of each finder pattern.
|
||||
* Each array's element represent the top-left point of the pattern as (x, y) coordinates
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Array} Array of coordinates
|
||||
*/
|
||||
exports.getPositions = function getPositions (version) {
|
||||
const size = getSymbolSize(version)
|
||||
|
||||
return [
|
||||
// top-left
|
||||
[0, 0],
|
||||
// top-right
|
||||
[size - FINDER_PATTERN_SIZE, 0],
|
||||
// bottom-left
|
||||
[0, size - FINDER_PATTERN_SIZE]
|
||||
]
|
||||
}
|
||||
29
node_modules/qrcode/lib/core/format-info.js
generated
vendored
Normal file
29
node_modules/qrcode/lib/core/format-info.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
const Utils = require('./utils')
|
||||
|
||||
const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)
|
||||
const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)
|
||||
const G15_BCH = Utils.getBCHDigit(G15)
|
||||
|
||||
/**
|
||||
* Returns format information with relative error correction bits
|
||||
*
|
||||
* The format information is a 15-bit sequence containing 5 data bits,
|
||||
* with 10 error correction bits calculated using the (15, 5) BCH code.
|
||||
*
|
||||
* @param {Number} errorCorrectionLevel Error correction level
|
||||
* @param {Number} mask Mask pattern
|
||||
* @return {Number} Encoded format information bits
|
||||
*/
|
||||
exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
|
||||
const data = ((errorCorrectionLevel.bit << 3) | mask)
|
||||
let d = data << 10
|
||||
|
||||
while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
|
||||
d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH))
|
||||
}
|
||||
|
||||
// xor final data with mask pattern in order to ensure that
|
||||
// no combination of Error Correction Level and data mask pattern
|
||||
// will result in an all-zero data string
|
||||
return ((data << 10) | d) ^ G15_MASK
|
||||
}
|
||||
69
node_modules/qrcode/lib/core/galois-field.js
generated
vendored
Normal file
69
node_modules/qrcode/lib/core/galois-field.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
const EXP_TABLE = new Uint8Array(512)
|
||||
const LOG_TABLE = new Uint8Array(256)
|
||||
/**
|
||||
* Precompute the log and anti-log tables for faster computation later
|
||||
*
|
||||
* For each possible value in the galois field 2^8, we will pre-compute
|
||||
* the logarithm and anti-logarithm (exponential) of this value
|
||||
*
|
||||
* ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
|
||||
*/
|
||||
;(function initTables () {
|
||||
let x = 1
|
||||
for (let i = 0; i < 255; i++) {
|
||||
EXP_TABLE[i] = x
|
||||
LOG_TABLE[x] = i
|
||||
|
||||
x <<= 1 // multiply by 2
|
||||
|
||||
// The QR code specification says to use byte-wise modulo 100011101 arithmetic.
|
||||
// This means that when a number is 256 or larger, it should be XORed with 0x11D.
|
||||
if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
|
||||
x ^= 0x11D
|
||||
}
|
||||
}
|
||||
|
||||
// Optimization: double the size of the anti-log table so that we don't need to mod 255 to
|
||||
// stay inside the bounds (because we will mainly use this table for the multiplication of
|
||||
// two GF numbers, no more).
|
||||
// @see {@link mul}
|
||||
for (let i = 255; i < 512; i++) {
|
||||
EXP_TABLE[i] = EXP_TABLE[i - 255]
|
||||
}
|
||||
}())
|
||||
|
||||
/**
|
||||
* Returns log value of n inside Galois Field
|
||||
*
|
||||
* @param {Number} n
|
||||
* @return {Number}
|
||||
*/
|
||||
exports.log = function log (n) {
|
||||
if (n < 1) throw new Error('log(' + n + ')')
|
||||
return LOG_TABLE[n]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns anti-log value of n inside Galois Field
|
||||
*
|
||||
* @param {Number} n
|
||||
* @return {Number}
|
||||
*/
|
||||
exports.exp = function exp (n) {
|
||||
return EXP_TABLE[n]
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies two number inside Galois Field
|
||||
*
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @return {Number}
|
||||
*/
|
||||
exports.mul = function mul (x, y) {
|
||||
if (x === 0 || y === 0) return 0
|
||||
|
||||
// should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
|
||||
// @see {@link initTables}
|
||||
return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
|
||||
}
|
||||
54
node_modules/qrcode/lib/core/kanji-data.js
generated
vendored
Normal file
54
node_modules/qrcode/lib/core/kanji-data.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
const Mode = require('./mode')
|
||||
const Utils = require('./utils')
|
||||
|
||||
function KanjiData (data) {
|
||||
this.mode = Mode.KANJI
|
||||
this.data = data
|
||||
}
|
||||
|
||||
KanjiData.getBitsLength = function getBitsLength (length) {
|
||||
return length * 13
|
||||
}
|
||||
|
||||
KanjiData.prototype.getLength = function getLength () {
|
||||
return this.data.length
|
||||
}
|
||||
|
||||
KanjiData.prototype.getBitsLength = function getBitsLength () {
|
||||
return KanjiData.getBitsLength(this.data.length)
|
||||
}
|
||||
|
||||
KanjiData.prototype.write = function (bitBuffer) {
|
||||
let i
|
||||
|
||||
// In the Shift JIS system, Kanji characters are represented by a two byte combination.
|
||||
// These byte values are shifted from the JIS X 0208 values.
|
||||
// JIS X 0208 gives details of the shift coded representation.
|
||||
for (i = 0; i < this.data.length; i++) {
|
||||
let value = Utils.toSJIS(this.data[i])
|
||||
|
||||
// For characters with Shift JIS values from 0x8140 to 0x9FFC:
|
||||
if (value >= 0x8140 && value <= 0x9FFC) {
|
||||
// Subtract 0x8140 from Shift JIS value
|
||||
value -= 0x8140
|
||||
|
||||
// For characters with Shift JIS values from 0xE040 to 0xEBBF
|
||||
} else if (value >= 0xE040 && value <= 0xEBBF) {
|
||||
// Subtract 0xC140 from Shift JIS value
|
||||
value -= 0xC140
|
||||
} else {
|
||||
throw new Error(
|
||||
'Invalid SJIS character: ' + this.data[i] + '\n' +
|
||||
'Make sure your charset is UTF-8')
|
||||
}
|
||||
|
||||
// Multiply most significant byte of result by 0xC0
|
||||
// and add least significant byte to product
|
||||
value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff)
|
||||
|
||||
// Convert result to a 13-bit binary string
|
||||
bitBuffer.put(value, 13)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = KanjiData
|
||||
234
node_modules/qrcode/lib/core/mask-pattern.js
generated
vendored
Normal file
234
node_modules/qrcode/lib/core/mask-pattern.js
generated
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Data mask pattern reference
|
||||
* @type {Object}
|
||||
*/
|
||||
exports.Patterns = {
|
||||
PATTERN000: 0,
|
||||
PATTERN001: 1,
|
||||
PATTERN010: 2,
|
||||
PATTERN011: 3,
|
||||
PATTERN100: 4,
|
||||
PATTERN101: 5,
|
||||
PATTERN110: 6,
|
||||
PATTERN111: 7
|
||||
}
|
||||
|
||||
/**
|
||||
* Weighted penalty scores for the undesirable features
|
||||
* @type {Object}
|
||||
*/
|
||||
const PenaltyScores = {
|
||||
N1: 3,
|
||||
N2: 3,
|
||||
N3: 40,
|
||||
N4: 10
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mask pattern value is valid
|
||||
*
|
||||
* @param {Number} mask Mask pattern
|
||||
* @return {Boolean} true if valid, false otherwise
|
||||
*/
|
||||
exports.isValid = function isValid (mask) {
|
||||
return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mask pattern from a value.
|
||||
* If value is not valid, returns undefined
|
||||
*
|
||||
* @param {Number|String} value Mask pattern value
|
||||
* @return {Number} Valid mask pattern or undefined
|
||||
*/
|
||||
exports.from = function from (value) {
|
||||
return exports.isValid(value) ? parseInt(value, 10) : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Find adjacent modules in row/column with the same color
|
||||
* and assign a penalty value.
|
||||
*
|
||||
* Points: N1 + i
|
||||
* i is the amount by which the number of adjacent modules of the same color exceeds 5
|
||||
*/
|
||||
exports.getPenaltyN1 = function getPenaltyN1 (data) {
|
||||
const size = data.size
|
||||
let points = 0
|
||||
let sameCountCol = 0
|
||||
let sameCountRow = 0
|
||||
let lastCol = null
|
||||
let lastRow = null
|
||||
|
||||
for (let row = 0; row < size; row++) {
|
||||
sameCountCol = sameCountRow = 0
|
||||
lastCol = lastRow = null
|
||||
|
||||
for (let col = 0; col < size; col++) {
|
||||
let module = data.get(row, col)
|
||||
if (module === lastCol) {
|
||||
sameCountCol++
|
||||
} else {
|
||||
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)
|
||||
lastCol = module
|
||||
sameCountCol = 1
|
||||
}
|
||||
|
||||
module = data.get(col, row)
|
||||
if (module === lastRow) {
|
||||
sameCountRow++
|
||||
} else {
|
||||
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)
|
||||
lastRow = module
|
||||
sameCountRow = 1
|
||||
}
|
||||
}
|
||||
|
||||
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)
|
||||
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)
|
||||
}
|
||||
|
||||
return points
|
||||
}
|
||||
|
||||
/**
|
||||
* Find 2x2 blocks with the same color and assign a penalty value
|
||||
*
|
||||
* Points: N2 * (m - 1) * (n - 1)
|
||||
*/
|
||||
exports.getPenaltyN2 = function getPenaltyN2 (data) {
|
||||
const size = data.size
|
||||
let points = 0
|
||||
|
||||
for (let row = 0; row < size - 1; row++) {
|
||||
for (let col = 0; col < size - 1; col++) {
|
||||
const last = data.get(row, col) +
|
||||
data.get(row, col + 1) +
|
||||
data.get(row + 1, col) +
|
||||
data.get(row + 1, col + 1)
|
||||
|
||||
if (last === 4 || last === 0) points++
|
||||
}
|
||||
}
|
||||
|
||||
return points * PenaltyScores.N2
|
||||
}
|
||||
|
||||
/**
|
||||
* Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
|
||||
* preceded or followed by light area 4 modules wide
|
||||
*
|
||||
* Points: N3 * number of pattern found
|
||||
*/
|
||||
exports.getPenaltyN3 = function getPenaltyN3 (data) {
|
||||
const size = data.size
|
||||
let points = 0
|
||||
let bitsCol = 0
|
||||
let bitsRow = 0
|
||||
|
||||
for (let row = 0; row < size; row++) {
|
||||
bitsCol = bitsRow = 0
|
||||
for (let col = 0; col < size; col++) {
|
||||
bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col)
|
||||
if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++
|
||||
|
||||
bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row)
|
||||
if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++
|
||||
}
|
||||
}
|
||||
|
||||
return points * PenaltyScores.N3
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate proportion of dark modules in entire symbol
|
||||
*
|
||||
* Points: N4 * k
|
||||
*
|
||||
* k is the rating of the deviation of the proportion of dark modules
|
||||
* in the symbol from 50% in steps of 5%
|
||||
*/
|
||||
exports.getPenaltyN4 = function getPenaltyN4 (data) {
|
||||
let darkCount = 0
|
||||
const modulesCount = data.data.length
|
||||
|
||||
for (let i = 0; i < modulesCount; i++) darkCount += data.data[i]
|
||||
|
||||
const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10)
|
||||
|
||||
return k * PenaltyScores.N4
|
||||
}
|
||||
|
||||
/**
|
||||
* Return mask value at given position
|
||||
*
|
||||
* @param {Number} maskPattern Pattern reference value
|
||||
* @param {Number} i Row
|
||||
* @param {Number} j Column
|
||||
* @return {Boolean} Mask value
|
||||
*/
|
||||
function getMaskAt (maskPattern, i, j) {
|
||||
switch (maskPattern) {
|
||||
case exports.Patterns.PATTERN000: return (i + j) % 2 === 0
|
||||
case exports.Patterns.PATTERN001: return i % 2 === 0
|
||||
case exports.Patterns.PATTERN010: return j % 3 === 0
|
||||
case exports.Patterns.PATTERN011: return (i + j) % 3 === 0
|
||||
case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
|
||||
case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
|
||||
case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
|
||||
case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
|
||||
|
||||
default: throw new Error('bad maskPattern:' + maskPattern)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a mask pattern to a BitMatrix
|
||||
*
|
||||
* @param {Number} pattern Pattern reference number
|
||||
* @param {BitMatrix} data BitMatrix data
|
||||
*/
|
||||
exports.applyMask = function applyMask (pattern, data) {
|
||||
const size = data.size
|
||||
|
||||
for (let col = 0; col < size; col++) {
|
||||
for (let row = 0; row < size; row++) {
|
||||
if (data.isReserved(row, col)) continue
|
||||
data.xor(row, col, getMaskAt(pattern, row, col))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the best mask pattern for data
|
||||
*
|
||||
* @param {BitMatrix} data
|
||||
* @return {Number} Mask pattern reference number
|
||||
*/
|
||||
exports.getBestMask = function getBestMask (data, setupFormatFunc) {
|
||||
const numPatterns = Object.keys(exports.Patterns).length
|
||||
let bestPattern = 0
|
||||
let lowerPenalty = Infinity
|
||||
|
||||
for (let p = 0; p < numPatterns; p++) {
|
||||
setupFormatFunc(p)
|
||||
exports.applyMask(p, data)
|
||||
|
||||
// Calculate penalty
|
||||
const penalty =
|
||||
exports.getPenaltyN1(data) +
|
||||
exports.getPenaltyN2(data) +
|
||||
exports.getPenaltyN3(data) +
|
||||
exports.getPenaltyN4(data)
|
||||
|
||||
// Undo previously applied mask
|
||||
exports.applyMask(p, data)
|
||||
|
||||
if (penalty < lowerPenalty) {
|
||||
lowerPenalty = penalty
|
||||
bestPattern = p
|
||||
}
|
||||
}
|
||||
|
||||
return bestPattern
|
||||
}
|
||||
167
node_modules/qrcode/lib/core/mode.js
generated
vendored
Normal file
167
node_modules/qrcode/lib/core/mode.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
const VersionCheck = require('./version-check')
|
||||
const Regex = require('./regex')
|
||||
|
||||
/**
|
||||
* Numeric mode encodes data from the decimal digit set (0 - 9)
|
||||
* (byte values 30HEX to 39HEX).
|
||||
* Normally, 3 data characters are represented by 10 bits.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
exports.NUMERIC = {
|
||||
id: 'Numeric',
|
||||
bit: 1 << 0,
|
||||
ccBits: [10, 12, 14]
|
||||
}
|
||||
|
||||
/**
|
||||
* Alphanumeric mode encodes data from a set of 45 characters,
|
||||
* i.e. 10 numeric digits (0 - 9),
|
||||
* 26 alphabetic characters (A - Z),
|
||||
* and 9 symbols (SP, $, %, *, +, -, ., /, :).
|
||||
* Normally, two input characters are represented by 11 bits.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
exports.ALPHANUMERIC = {
|
||||
id: 'Alphanumeric',
|
||||
bit: 1 << 1,
|
||||
ccBits: [9, 11, 13]
|
||||
}
|
||||
|
||||
/**
|
||||
* In byte mode, data is encoded at 8 bits per character.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
exports.BYTE = {
|
||||
id: 'Byte',
|
||||
bit: 1 << 2,
|
||||
ccBits: [8, 16, 16]
|
||||
}
|
||||
|
||||
/**
|
||||
* The Kanji mode efficiently encodes Kanji characters in accordance with
|
||||
* the Shift JIS system based on JIS X 0208.
|
||||
* The Shift JIS values are shifted from the JIS X 0208 values.
|
||||
* JIS X 0208 gives details of the shift coded representation.
|
||||
* Each two-byte character value is compacted to a 13-bit binary codeword.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
exports.KANJI = {
|
||||
id: 'Kanji',
|
||||
bit: 1 << 3,
|
||||
ccBits: [8, 10, 12]
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixed mode will contain a sequences of data in a combination of any of
|
||||
* the modes described above
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
exports.MIXED = {
|
||||
bit: -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bits needed to store the data length
|
||||
* according to QR Code specifications.
|
||||
*
|
||||
* @param {Mode} mode Data mode
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Number} Number of bits
|
||||
*/
|
||||
exports.getCharCountIndicator = function getCharCountIndicator (mode, version) {
|
||||
if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
|
||||
|
||||
if (!VersionCheck.isValid(version)) {
|
||||
throw new Error('Invalid version: ' + version)
|
||||
}
|
||||
|
||||
if (version >= 1 && version < 10) return mode.ccBits[0]
|
||||
else if (version < 27) return mode.ccBits[1]
|
||||
return mode.ccBits[2]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most efficient mode to store the specified data
|
||||
*
|
||||
* @param {String} dataStr Input data string
|
||||
* @return {Mode} Best mode
|
||||
*/
|
||||
exports.getBestModeForData = function getBestModeForData (dataStr) {
|
||||
if (Regex.testNumeric(dataStr)) return exports.NUMERIC
|
||||
else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC
|
||||
else if (Regex.testKanji(dataStr)) return exports.KANJI
|
||||
else return exports.BYTE
|
||||
}
|
||||
|
||||
/**
|
||||
* Return mode name as string
|
||||
*
|
||||
* @param {Mode} mode Mode object
|
||||
* @returns {String} Mode name
|
||||
*/
|
||||
exports.toString = function toString (mode) {
|
||||
if (mode && mode.id) return mode.id
|
||||
throw new Error('Invalid mode')
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if input param is a valid mode object
|
||||
*
|
||||
* @param {Mode} mode Mode object
|
||||
* @returns {Boolean} True if valid mode, false otherwise
|
||||
*/
|
||||
exports.isValid = function isValid (mode) {
|
||||
return mode && mode.bit && mode.ccBits
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode object from its name
|
||||
*
|
||||
* @param {String} string Mode name
|
||||
* @returns {Mode} Mode object
|
||||
*/
|
||||
function fromString (string) {
|
||||
if (typeof string !== 'string') {
|
||||
throw new Error('Param is not a string')
|
||||
}
|
||||
|
||||
const lcStr = string.toLowerCase()
|
||||
|
||||
switch (lcStr) {
|
||||
case 'numeric':
|
||||
return exports.NUMERIC
|
||||
case 'alphanumeric':
|
||||
return exports.ALPHANUMERIC
|
||||
case 'kanji':
|
||||
return exports.KANJI
|
||||
case 'byte':
|
||||
return exports.BYTE
|
||||
default:
|
||||
throw new Error('Unknown mode: ' + string)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mode from a value.
|
||||
* If value is not a valid mode, returns defaultValue
|
||||
*
|
||||
* @param {Mode|String} value Encoding mode
|
||||
* @param {Mode} defaultValue Fallback value
|
||||
* @return {Mode} Encoding mode
|
||||
*/
|
||||
exports.from = function from (value, defaultValue) {
|
||||
if (exports.isValid(value)) {
|
||||
return value
|
||||
}
|
||||
|
||||
try {
|
||||
return fromString(value)
|
||||
} catch (e) {
|
||||
return defaultValue
|
||||
}
|
||||
}
|
||||
43
node_modules/qrcode/lib/core/numeric-data.js
generated
vendored
Normal file
43
node_modules/qrcode/lib/core/numeric-data.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
const Mode = require('./mode')
|
||||
|
||||
function NumericData (data) {
|
||||
this.mode = Mode.NUMERIC
|
||||
this.data = data.toString()
|
||||
}
|
||||
|
||||
NumericData.getBitsLength = function getBitsLength (length) {
|
||||
return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
|
||||
}
|
||||
|
||||
NumericData.prototype.getLength = function getLength () {
|
||||
return this.data.length
|
||||
}
|
||||
|
||||
NumericData.prototype.getBitsLength = function getBitsLength () {
|
||||
return NumericData.getBitsLength(this.data.length)
|
||||
}
|
||||
|
||||
NumericData.prototype.write = function write (bitBuffer) {
|
||||
let i, group, value
|
||||
|
||||
// The input data string is divided into groups of three digits,
|
||||
// and each group is converted to its 10-bit binary equivalent.
|
||||
for (i = 0; i + 3 <= this.data.length; i += 3) {
|
||||
group = this.data.substr(i, 3)
|
||||
value = parseInt(group, 10)
|
||||
|
||||
bitBuffer.put(value, 10)
|
||||
}
|
||||
|
||||
// If the number of input digits is not an exact multiple of three,
|
||||
// the final one or two digits are converted to 4 or 7 bits respectively.
|
||||
const remainingNum = this.data.length - i
|
||||
if (remainingNum > 0) {
|
||||
group = this.data.substr(i)
|
||||
value = parseInt(group, 10)
|
||||
|
||||
bitBuffer.put(value, remainingNum * 3 + 1)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NumericData
|
||||
62
node_modules/qrcode/lib/core/polynomial.js
generated
vendored
Normal file
62
node_modules/qrcode/lib/core/polynomial.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
const GF = require('./galois-field')
|
||||
|
||||
/**
|
||||
* Multiplies two polynomials inside Galois Field
|
||||
*
|
||||
* @param {Uint8Array} p1 Polynomial
|
||||
* @param {Uint8Array} p2 Polynomial
|
||||
* @return {Uint8Array} Product of p1 and p2
|
||||
*/
|
||||
exports.mul = function mul (p1, p2) {
|
||||
const coeff = new Uint8Array(p1.length + p2.length - 1)
|
||||
|
||||
for (let i = 0; i < p1.length; i++) {
|
||||
for (let j = 0; j < p2.length; j++) {
|
||||
coeff[i + j] ^= GF.mul(p1[i], p2[j])
|
||||
}
|
||||
}
|
||||
|
||||
return coeff
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the remainder of polynomials division
|
||||
*
|
||||
* @param {Uint8Array} divident Polynomial
|
||||
* @param {Uint8Array} divisor Polynomial
|
||||
* @return {Uint8Array} Remainder
|
||||
*/
|
||||
exports.mod = function mod (divident, divisor) {
|
||||
let result = new Uint8Array(divident)
|
||||
|
||||
while ((result.length - divisor.length) >= 0) {
|
||||
const coeff = result[0]
|
||||
|
||||
for (let i = 0; i < divisor.length; i++) {
|
||||
result[i] ^= GF.mul(divisor[i], coeff)
|
||||
}
|
||||
|
||||
// remove all zeros from buffer head
|
||||
let offset = 0
|
||||
while (offset < result.length && result[offset] === 0) offset++
|
||||
result = result.slice(offset)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an irreducible generator polynomial of specified degree
|
||||
* (used by Reed-Solomon encoder)
|
||||
*
|
||||
* @param {Number} degree Degree of the generator polynomial
|
||||
* @return {Uint8Array} Buffer containing polynomial coefficients
|
||||
*/
|
||||
exports.generateECPolynomial = function generateECPolynomial (degree) {
|
||||
let poly = new Uint8Array([1])
|
||||
for (let i = 0; i < degree; i++) {
|
||||
poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]))
|
||||
}
|
||||
|
||||
return poly
|
||||
}
|
||||
495
node_modules/qrcode/lib/core/qrcode.js
generated
vendored
Normal file
495
node_modules/qrcode/lib/core/qrcode.js
generated
vendored
Normal file
@@ -0,0 +1,495 @@
|
||||
const Utils = require('./utils')
|
||||
const ECLevel = require('./error-correction-level')
|
||||
const BitBuffer = require('./bit-buffer')
|
||||
const BitMatrix = require('./bit-matrix')
|
||||
const AlignmentPattern = require('./alignment-pattern')
|
||||
const FinderPattern = require('./finder-pattern')
|
||||
const MaskPattern = require('./mask-pattern')
|
||||
const ECCode = require('./error-correction-code')
|
||||
const ReedSolomonEncoder = require('./reed-solomon-encoder')
|
||||
const Version = require('./version')
|
||||
const FormatInfo = require('./format-info')
|
||||
const Mode = require('./mode')
|
||||
const Segments = require('./segments')
|
||||
|
||||
/**
|
||||
* QRCode for JavaScript
|
||||
*
|
||||
* modified by Ryan Day for nodejs support
|
||||
* Copyright (c) 2011 Ryan Day
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
//---------------------------------------------------------------------
|
||||
// QRCode for JavaScript
|
||||
//
|
||||
// Copyright (c) 2009 Kazuhiko Arase
|
||||
//
|
||||
// URL: http://www.d-project.com/
|
||||
//
|
||||
// Licensed under the MIT license:
|
||||
// http://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
// The word "QR Code" is registered trademark of
|
||||
// DENSO WAVE INCORPORATED
|
||||
// http://www.denso-wave.com/qrcode/faqpatent-e.html
|
||||
//
|
||||
//---------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add finder patterns bits to matrix
|
||||
*
|
||||
* @param {BitMatrix} matrix Modules matrix
|
||||
* @param {Number} version QR Code version
|
||||
*/
|
||||
function setupFinderPattern (matrix, version) {
|
||||
const size = matrix.size
|
||||
const pos = FinderPattern.getPositions(version)
|
||||
|
||||
for (let i = 0; i < pos.length; i++) {
|
||||
const row = pos[i][0]
|
||||
const col = pos[i][1]
|
||||
|
||||
for (let r = -1; r <= 7; r++) {
|
||||
if (row + r <= -1 || size <= row + r) continue
|
||||
|
||||
for (let c = -1; c <= 7; c++) {
|
||||
if (col + c <= -1 || size <= col + c) continue
|
||||
|
||||
if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
|
||||
(c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
|
||||
(r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
|
||||
matrix.set(row + r, col + c, true, true)
|
||||
} else {
|
||||
matrix.set(row + r, col + c, false, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add timing pattern bits to matrix
|
||||
*
|
||||
* Note: this function must be called before {@link setupAlignmentPattern}
|
||||
*
|
||||
* @param {BitMatrix} matrix Modules matrix
|
||||
*/
|
||||
function setupTimingPattern (matrix) {
|
||||
const size = matrix.size
|
||||
|
||||
for (let r = 8; r < size - 8; r++) {
|
||||
const value = r % 2 === 0
|
||||
matrix.set(r, 6, value, true)
|
||||
matrix.set(6, r, value, true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add alignment patterns bits to matrix
|
||||
*
|
||||
* Note: this function must be called after {@link setupTimingPattern}
|
||||
*
|
||||
* @param {BitMatrix} matrix Modules matrix
|
||||
* @param {Number} version QR Code version
|
||||
*/
|
||||
function setupAlignmentPattern (matrix, version) {
|
||||
const pos = AlignmentPattern.getPositions(version)
|
||||
|
||||
for (let i = 0; i < pos.length; i++) {
|
||||
const row = pos[i][0]
|
||||
const col = pos[i][1]
|
||||
|
||||
for (let r = -2; r <= 2; r++) {
|
||||
for (let c = -2; c <= 2; c++) {
|
||||
if (r === -2 || r === 2 || c === -2 || c === 2 ||
|
||||
(r === 0 && c === 0)) {
|
||||
matrix.set(row + r, col + c, true, true)
|
||||
} else {
|
||||
matrix.set(row + r, col + c, false, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add version info bits to matrix
|
||||
*
|
||||
* @param {BitMatrix} matrix Modules matrix
|
||||
* @param {Number} version QR Code version
|
||||
*/
|
||||
function setupVersionInfo (matrix, version) {
|
||||
const size = matrix.size
|
||||
const bits = Version.getEncodedBits(version)
|
||||
let row, col, mod
|
||||
|
||||
for (let i = 0; i < 18; i++) {
|
||||
row = Math.floor(i / 3)
|
||||
col = i % 3 + size - 8 - 3
|
||||
mod = ((bits >> i) & 1) === 1
|
||||
|
||||
matrix.set(row, col, mod, true)
|
||||
matrix.set(col, row, mod, true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add format info bits to matrix
|
||||
*
|
||||
* @param {BitMatrix} matrix Modules matrix
|
||||
* @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
|
||||
* @param {Number} maskPattern Mask pattern reference value
|
||||
*/
|
||||
function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
|
||||
const size = matrix.size
|
||||
const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern)
|
||||
let i, mod
|
||||
|
||||
for (i = 0; i < 15; i++) {
|
||||
mod = ((bits >> i) & 1) === 1
|
||||
|
||||
// vertical
|
||||
if (i < 6) {
|
||||
matrix.set(i, 8, mod, true)
|
||||
} else if (i < 8) {
|
||||
matrix.set(i + 1, 8, mod, true)
|
||||
} else {
|
||||
matrix.set(size - 15 + i, 8, mod, true)
|
||||
}
|
||||
|
||||
// horizontal
|
||||
if (i < 8) {
|
||||
matrix.set(8, size - i - 1, mod, true)
|
||||
} else if (i < 9) {
|
||||
matrix.set(8, 15 - i - 1 + 1, mod, true)
|
||||
} else {
|
||||
matrix.set(8, 15 - i - 1, mod, true)
|
||||
}
|
||||
}
|
||||
|
||||
// fixed module
|
||||
matrix.set(size - 8, 8, 1, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add encoded data bits to matrix
|
||||
*
|
||||
* @param {BitMatrix} matrix Modules matrix
|
||||
* @param {Uint8Array} data Data codewords
|
||||
*/
|
||||
function setupData (matrix, data) {
|
||||
const size = matrix.size
|
||||
let inc = -1
|
||||
let row = size - 1
|
||||
let bitIndex = 7
|
||||
let byteIndex = 0
|
||||
|
||||
for (let col = size - 1; col > 0; col -= 2) {
|
||||
if (col === 6) col--
|
||||
|
||||
while (true) {
|
||||
for (let c = 0; c < 2; c++) {
|
||||
if (!matrix.isReserved(row, col - c)) {
|
||||
let dark = false
|
||||
|
||||
if (byteIndex < data.length) {
|
||||
dark = (((data[byteIndex] >>> bitIndex) & 1) === 1)
|
||||
}
|
||||
|
||||
matrix.set(row, col - c, dark)
|
||||
bitIndex--
|
||||
|
||||
if (bitIndex === -1) {
|
||||
byteIndex++
|
||||
bitIndex = 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
row += inc
|
||||
|
||||
if (row < 0 || size <= row) {
|
||||
row -= inc
|
||||
inc = -inc
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create encoded codewords from data input
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
|
||||
* @param {ByteData} data Data input
|
||||
* @return {Uint8Array} Buffer containing encoded codewords
|
||||
*/
|
||||
function createData (version, errorCorrectionLevel, segments) {
|
||||
// Prepare data buffer
|
||||
const buffer = new BitBuffer()
|
||||
|
||||
segments.forEach(function (data) {
|
||||
// prefix data with mode indicator (4 bits)
|
||||
buffer.put(data.mode.bit, 4)
|
||||
|
||||
// Prefix data with character count indicator.
|
||||
// The character count indicator is a string of bits that represents the
|
||||
// number of characters that are being encoded.
|
||||
// The character count indicator must be placed after the mode indicator
|
||||
// and must be a certain number of bits long, depending on the QR version
|
||||
// and data mode
|
||||
// @see {@link Mode.getCharCountIndicator}.
|
||||
buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version))
|
||||
|
||||
// add binary data sequence to buffer
|
||||
data.write(buffer)
|
||||
})
|
||||
|
||||
// Calculate required number of bits
|
||||
const totalCodewords = Utils.getSymbolTotalCodewords(version)
|
||||
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
|
||||
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8
|
||||
|
||||
// Add a terminator.
|
||||
// If the bit string is shorter than the total number of required bits,
|
||||
// a terminator of up to four 0s must be added to the right side of the string.
|
||||
// If the bit string is more than four bits shorter than the required number of bits,
|
||||
// add four 0s to the end.
|
||||
if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
|
||||
buffer.put(0, 4)
|
||||
}
|
||||
|
||||
// If the bit string is fewer than four bits shorter, add only the number of 0s that
|
||||
// are needed to reach the required number of bits.
|
||||
|
||||
// After adding the terminator, if the number of bits in the string is not a multiple of 8,
|
||||
// pad the string on the right with 0s to make the string's length a multiple of 8.
|
||||
while (buffer.getLengthInBits() % 8 !== 0) {
|
||||
buffer.putBit(0)
|
||||
}
|
||||
|
||||
// Add pad bytes if the string is still shorter than the total number of required bits.
|
||||
// Extend the buffer to fill the data capacity of the symbol corresponding to
|
||||
// the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
|
||||
// and 00010001 (0x11) alternately.
|
||||
const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8
|
||||
for (let i = 0; i < remainingByte; i++) {
|
||||
buffer.put(i % 2 ? 0x11 : 0xEC, 8)
|
||||
}
|
||||
|
||||
return createCodewords(buffer, version, errorCorrectionLevel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode input data with Reed-Solomon and return codewords with
|
||||
* relative error correction bits
|
||||
*
|
||||
* @param {BitBuffer} bitBuffer Data to encode
|
||||
* @param {Number} version QR Code version
|
||||
* @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
|
||||
* @return {Uint8Array} Buffer containing encoded codewords
|
||||
*/
|
||||
function createCodewords (bitBuffer, version, errorCorrectionLevel) {
|
||||
// Total codewords for this QR code version (Data + Error correction)
|
||||
const totalCodewords = Utils.getSymbolTotalCodewords(version)
|
||||
|
||||
// Total number of error correction codewords
|
||||
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
|
||||
|
||||
// Total number of data codewords
|
||||
const dataTotalCodewords = totalCodewords - ecTotalCodewords
|
||||
|
||||
// Total number of blocks
|
||||
const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel)
|
||||
|
||||
// Calculate how many blocks each group should contain
|
||||
const blocksInGroup2 = totalCodewords % ecTotalBlocks
|
||||
const blocksInGroup1 = ecTotalBlocks - blocksInGroup2
|
||||
|
||||
const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks)
|
||||
|
||||
const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks)
|
||||
const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1
|
||||
|
||||
// Number of EC codewords is the same for both groups
|
||||
const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1
|
||||
|
||||
// Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
|
||||
const rs = new ReedSolomonEncoder(ecCount)
|
||||
|
||||
let offset = 0
|
||||
const dcData = new Array(ecTotalBlocks)
|
||||
const ecData = new Array(ecTotalBlocks)
|
||||
let maxDataSize = 0
|
||||
const buffer = new Uint8Array(bitBuffer.buffer)
|
||||
|
||||
// Divide the buffer into the required number of blocks
|
||||
for (let b = 0; b < ecTotalBlocks; b++) {
|
||||
const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2
|
||||
|
||||
// extract a block of data from buffer
|
||||
dcData[b] = buffer.slice(offset, offset + dataSize)
|
||||
|
||||
// Calculate EC codewords for this data block
|
||||
ecData[b] = rs.encode(dcData[b])
|
||||
|
||||
offset += dataSize
|
||||
maxDataSize = Math.max(maxDataSize, dataSize)
|
||||
}
|
||||
|
||||
// Create final data
|
||||
// Interleave the data and error correction codewords from each block
|
||||
const data = new Uint8Array(totalCodewords)
|
||||
let index = 0
|
||||
let i, r
|
||||
|
||||
// Add data codewords
|
||||
for (i = 0; i < maxDataSize; i++) {
|
||||
for (r = 0; r < ecTotalBlocks; r++) {
|
||||
if (i < dcData[r].length) {
|
||||
data[index++] = dcData[r][i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apped EC codewords
|
||||
for (i = 0; i < ecCount; i++) {
|
||||
for (r = 0; r < ecTotalBlocks; r++) {
|
||||
data[index++] = ecData[r][i]
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Build QR Code symbol
|
||||
*
|
||||
* @param {String} data Input string
|
||||
* @param {Number} version QR Code version
|
||||
* @param {ErrorCorretionLevel} errorCorrectionLevel Error level
|
||||
* @param {MaskPattern} maskPattern Mask pattern
|
||||
* @return {Object} Object containing symbol data
|
||||
*/
|
||||
function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
|
||||
let segments
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
segments = Segments.fromArray(data)
|
||||
} else if (typeof data === 'string') {
|
||||
let estimatedVersion = version
|
||||
|
||||
if (!estimatedVersion) {
|
||||
const rawSegments = Segments.rawSplit(data)
|
||||
|
||||
// Estimate best version that can contain raw splitted segments
|
||||
estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel)
|
||||
}
|
||||
|
||||
// Build optimized segments
|
||||
// If estimated version is undefined, try with the highest version
|
||||
segments = Segments.fromString(data, estimatedVersion || 40)
|
||||
} else {
|
||||
throw new Error('Invalid data')
|
||||
}
|
||||
|
||||
// Get the min version that can contain data
|
||||
const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel)
|
||||
|
||||
// If no version is found, data cannot be stored
|
||||
if (!bestVersion) {
|
||||
throw new Error('The amount of data is too big to be stored in a QR Code')
|
||||
}
|
||||
|
||||
// If not specified, use min version as default
|
||||
if (!version) {
|
||||
version = bestVersion
|
||||
|
||||
// Check if the specified version can contain the data
|
||||
} else if (version < bestVersion) {
|
||||
throw new Error('\n' +
|
||||
'The chosen QR Code version cannot contain this amount of data.\n' +
|
||||
'Minimum version required to store current data is: ' + bestVersion + '.\n'
|
||||
)
|
||||
}
|
||||
|
||||
const dataBits = createData(version, errorCorrectionLevel, segments)
|
||||
|
||||
// Allocate matrix buffer
|
||||
const moduleCount = Utils.getSymbolSize(version)
|
||||
const modules = new BitMatrix(moduleCount)
|
||||
|
||||
// Add function modules
|
||||
setupFinderPattern(modules, version)
|
||||
setupTimingPattern(modules)
|
||||
setupAlignmentPattern(modules, version)
|
||||
|
||||
// Add temporary dummy bits for format info just to set them as reserved.
|
||||
// This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
|
||||
// since the masking operation must be performed only on the encoding region.
|
||||
// These blocks will be replaced with correct values later in code.
|
||||
setupFormatInfo(modules, errorCorrectionLevel, 0)
|
||||
|
||||
if (version >= 7) {
|
||||
setupVersionInfo(modules, version)
|
||||
}
|
||||
|
||||
// Add data codewords
|
||||
setupData(modules, dataBits)
|
||||
|
||||
if (isNaN(maskPattern)) {
|
||||
// Find best mask pattern
|
||||
maskPattern = MaskPattern.getBestMask(modules,
|
||||
setupFormatInfo.bind(null, modules, errorCorrectionLevel))
|
||||
}
|
||||
|
||||
// Apply mask pattern
|
||||
MaskPattern.applyMask(maskPattern, modules)
|
||||
|
||||
// Replace format info bits with correct values
|
||||
setupFormatInfo(modules, errorCorrectionLevel, maskPattern)
|
||||
|
||||
return {
|
||||
modules: modules,
|
||||
version: version,
|
||||
errorCorrectionLevel: errorCorrectionLevel,
|
||||
maskPattern: maskPattern,
|
||||
segments: segments
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* QR Code
|
||||
*
|
||||
* @param {String | Array} data Input data
|
||||
* @param {Object} options Optional configurations
|
||||
* @param {Number} options.version QR Code version
|
||||
* @param {String} options.errorCorrectionLevel Error correction level
|
||||
* @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
|
||||
*/
|
||||
exports.create = function create (data, options) {
|
||||
if (typeof data === 'undefined' || data === '') {
|
||||
throw new Error('No input text')
|
||||
}
|
||||
|
||||
let errorCorrectionLevel = ECLevel.M
|
||||
let version
|
||||
let mask
|
||||
|
||||
if (typeof options !== 'undefined') {
|
||||
// Use higher error correction level as default
|
||||
errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M)
|
||||
version = Version.from(options.version)
|
||||
mask = MaskPattern.from(options.maskPattern)
|
||||
|
||||
if (options.toSJISFunc) {
|
||||
Utils.setToSJISFunction(options.toSJISFunc)
|
||||
}
|
||||
}
|
||||
|
||||
return createSymbol(data, version, errorCorrectionLevel, mask)
|
||||
}
|
||||
56
node_modules/qrcode/lib/core/reed-solomon-encoder.js
generated
vendored
Normal file
56
node_modules/qrcode/lib/core/reed-solomon-encoder.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
const Polynomial = require('./polynomial')
|
||||
|
||||
function ReedSolomonEncoder (degree) {
|
||||
this.genPoly = undefined
|
||||
this.degree = degree
|
||||
|
||||
if (this.degree) this.initialize(this.degree)
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the encoder.
|
||||
* The input param should correspond to the number of error correction codewords.
|
||||
*
|
||||
* @param {Number} degree
|
||||
*/
|
||||
ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
|
||||
// create an irreducible generator polynomial
|
||||
this.degree = degree
|
||||
this.genPoly = Polynomial.generateECPolynomial(this.degree)
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a chunk of data
|
||||
*
|
||||
* @param {Uint8Array} data Buffer containing input data
|
||||
* @return {Uint8Array} Buffer containing encoded data
|
||||
*/
|
||||
ReedSolomonEncoder.prototype.encode = function encode (data) {
|
||||
if (!this.genPoly) {
|
||||
throw new Error('Encoder not initialized')
|
||||
}
|
||||
|
||||
// Calculate EC for this data block
|
||||
// extends data size to data+genPoly size
|
||||
const paddedData = new Uint8Array(data.length + this.degree)
|
||||
paddedData.set(data)
|
||||
|
||||
// The error correction codewords are the remainder after dividing the data codewords
|
||||
// by a generator polynomial
|
||||
const remainder = Polynomial.mod(paddedData, this.genPoly)
|
||||
|
||||
// return EC data blocks (last n byte, where n is the degree of genPoly)
|
||||
// If coefficients number in remainder are less than genPoly degree,
|
||||
// pad with 0s to the left to reach the needed number of coefficients
|
||||
const start = this.degree - remainder.length
|
||||
if (start > 0) {
|
||||
const buff = new Uint8Array(this.degree)
|
||||
buff.set(remainder, start)
|
||||
|
||||
return buff
|
||||
}
|
||||
|
||||
return remainder
|
||||
}
|
||||
|
||||
module.exports = ReedSolomonEncoder
|
||||
31
node_modules/qrcode/lib/core/regex.js
generated
vendored
Normal file
31
node_modules/qrcode/lib/core/regex.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
const numeric = '[0-9]+'
|
||||
const alphanumeric = '[A-Z $%*+\\-./:]+'
|
||||
let kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
|
||||
'[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
|
||||
'[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
|
||||
'[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'
|
||||
kanji = kanji.replace(/u/g, '\\u')
|
||||
|
||||
const byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+'
|
||||
|
||||
exports.KANJI = new RegExp(kanji, 'g')
|
||||
exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g')
|
||||
exports.BYTE = new RegExp(byte, 'g')
|
||||
exports.NUMERIC = new RegExp(numeric, 'g')
|
||||
exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g')
|
||||
|
||||
const TEST_KANJI = new RegExp('^' + kanji + '$')
|
||||
const TEST_NUMERIC = new RegExp('^' + numeric + '$')
|
||||
const TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$')
|
||||
|
||||
exports.testKanji = function testKanji (str) {
|
||||
return TEST_KANJI.test(str)
|
||||
}
|
||||
|
||||
exports.testNumeric = function testNumeric (str) {
|
||||
return TEST_NUMERIC.test(str)
|
||||
}
|
||||
|
||||
exports.testAlphanumeric = function testAlphanumeric (str) {
|
||||
return TEST_ALPHANUMERIC.test(str)
|
||||
}
|
||||
330
node_modules/qrcode/lib/core/segments.js
generated
vendored
Normal file
330
node_modules/qrcode/lib/core/segments.js
generated
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
const Mode = require('./mode')
|
||||
const NumericData = require('./numeric-data')
|
||||
const AlphanumericData = require('./alphanumeric-data')
|
||||
const ByteData = require('./byte-data')
|
||||
const KanjiData = require('./kanji-data')
|
||||
const Regex = require('./regex')
|
||||
const Utils = require('./utils')
|
||||
const dijkstra = require('dijkstrajs')
|
||||
|
||||
/**
|
||||
* Returns UTF8 byte length
|
||||
*
|
||||
* @param {String} str Input string
|
||||
* @return {Number} Number of byte
|
||||
*/
|
||||
function getStringByteLength (str) {
|
||||
return unescape(encodeURIComponent(str)).length
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of segments of the specified mode
|
||||
* from a string
|
||||
*
|
||||
* @param {Mode} mode Segment mode
|
||||
* @param {String} str String to process
|
||||
* @return {Array} Array of object with segments data
|
||||
*/
|
||||
function getSegments (regex, mode, str) {
|
||||
const segments = []
|
||||
let result
|
||||
|
||||
while ((result = regex.exec(str)) !== null) {
|
||||
segments.push({
|
||||
data: result[0],
|
||||
index: result.index,
|
||||
mode: mode,
|
||||
length: result[0].length
|
||||
})
|
||||
}
|
||||
|
||||
return segments
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a series of segments with the appropriate
|
||||
* modes from a string
|
||||
*
|
||||
* @param {String} dataStr Input string
|
||||
* @return {Array} Array of object with segments data
|
||||
*/
|
||||
function getSegmentsFromString (dataStr) {
|
||||
const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr)
|
||||
const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr)
|
||||
let byteSegs
|
||||
let kanjiSegs
|
||||
|
||||
if (Utils.isKanjiModeEnabled()) {
|
||||
byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr)
|
||||
kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr)
|
||||
} else {
|
||||
byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr)
|
||||
kanjiSegs = []
|
||||
}
|
||||
|
||||
const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs)
|
||||
|
||||
return segs
|
||||
.sort(function (s1, s2) {
|
||||
return s1.index - s2.index
|
||||
})
|
||||
.map(function (obj) {
|
||||
return {
|
||||
data: obj.data,
|
||||
mode: obj.mode,
|
||||
length: obj.length
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how many bits are needed to encode a string of
|
||||
* specified length with the specified mode
|
||||
*
|
||||
* @param {Number} length String length
|
||||
* @param {Mode} mode Segment mode
|
||||
* @return {Number} Bit length
|
||||
*/
|
||||
function getSegmentBitsLength (length, mode) {
|
||||
switch (mode) {
|
||||
case Mode.NUMERIC:
|
||||
return NumericData.getBitsLength(length)
|
||||
case Mode.ALPHANUMERIC:
|
||||
return AlphanumericData.getBitsLength(length)
|
||||
case Mode.KANJI:
|
||||
return KanjiData.getBitsLength(length)
|
||||
case Mode.BYTE:
|
||||
return ByteData.getBitsLength(length)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges adjacent segments which have the same mode
|
||||
*
|
||||
* @param {Array} segs Array of object with segments data
|
||||
* @return {Array} Array of object with segments data
|
||||
*/
|
||||
function mergeSegments (segs) {
|
||||
return segs.reduce(function (acc, curr) {
|
||||
const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null
|
||||
if (prevSeg && prevSeg.mode === curr.mode) {
|
||||
acc[acc.length - 1].data += curr.data
|
||||
return acc
|
||||
}
|
||||
|
||||
acc.push(curr)
|
||||
return acc
|
||||
}, [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of all possible nodes combination which
|
||||
* will be used to build a segments graph.
|
||||
*
|
||||
* Nodes are divided by groups. Each group will contain a list of all the modes
|
||||
* in which is possible to encode the given text.
|
||||
*
|
||||
* For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
|
||||
* The group for '12345' will contain then 3 objects, one for each
|
||||
* possible encoding mode.
|
||||
*
|
||||
* Each node represents a possible segment.
|
||||
*
|
||||
* @param {Array} segs Array of object with segments data
|
||||
* @return {Array} Array of object with segments data
|
||||
*/
|
||||
function buildNodes (segs) {
|
||||
const nodes = []
|
||||
for (let i = 0; i < segs.length; i++) {
|
||||
const seg = segs[i]
|
||||
|
||||
switch (seg.mode) {
|
||||
case Mode.NUMERIC:
|
||||
nodes.push([seg,
|
||||
{ data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
|
||||
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
||||
])
|
||||
break
|
||||
case Mode.ALPHANUMERIC:
|
||||
nodes.push([seg,
|
||||
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
||||
])
|
||||
break
|
||||
case Mode.KANJI:
|
||||
nodes.push([seg,
|
||||
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
||||
])
|
||||
break
|
||||
case Mode.BYTE:
|
||||
nodes.push([
|
||||
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
return nodes
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a graph from a list of nodes.
|
||||
* All segments in each node group will be connected with all the segments of
|
||||
* the next group and so on.
|
||||
*
|
||||
* At each connection will be assigned a weight depending on the
|
||||
* segment's byte length.
|
||||
*
|
||||
* @param {Array} nodes Array of object with segments data
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Object} Graph of all possible segments
|
||||
*/
|
||||
function buildGraph (nodes, version) {
|
||||
const table = {}
|
||||
const graph = { start: {} }
|
||||
let prevNodeIds = ['start']
|
||||
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const nodeGroup = nodes[i]
|
||||
const currentNodeIds = []
|
||||
|
||||
for (let j = 0; j < nodeGroup.length; j++) {
|
||||
const node = nodeGroup[j]
|
||||
const key = '' + i + j
|
||||
|
||||
currentNodeIds.push(key)
|
||||
table[key] = { node: node, lastCount: 0 }
|
||||
graph[key] = {}
|
||||
|
||||
for (let n = 0; n < prevNodeIds.length; n++) {
|
||||
const prevNodeId = prevNodeIds[n]
|
||||
|
||||
if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
|
||||
graph[prevNodeId][key] =
|
||||
getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
|
||||
getSegmentBitsLength(table[prevNodeId].lastCount, node.mode)
|
||||
|
||||
table[prevNodeId].lastCount += node.length
|
||||
} else {
|
||||
if (table[prevNodeId]) table[prevNodeId].lastCount = node.length
|
||||
|
||||
graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
|
||||
4 + Mode.getCharCountIndicator(node.mode, version) // switch cost
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prevNodeIds = currentNodeIds
|
||||
}
|
||||
|
||||
for (let n = 0; n < prevNodeIds.length; n++) {
|
||||
graph[prevNodeIds[n]].end = 0
|
||||
}
|
||||
|
||||
return { map: graph, table: table }
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a segment from a specified data and mode.
|
||||
* If a mode is not specified, the more suitable will be used.
|
||||
*
|
||||
* @param {String} data Input data
|
||||
* @param {Mode | String} modesHint Data mode
|
||||
* @return {Segment} Segment
|
||||
*/
|
||||
function buildSingleSegment (data, modesHint) {
|
||||
let mode
|
||||
const bestMode = Mode.getBestModeForData(data)
|
||||
|
||||
mode = Mode.from(modesHint, bestMode)
|
||||
|
||||
// Make sure data can be encoded
|
||||
if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
|
||||
throw new Error('"' + data + '"' +
|
||||
' cannot be encoded with mode ' + Mode.toString(mode) +
|
||||
'.\n Suggested mode is: ' + Mode.toString(bestMode))
|
||||
}
|
||||
|
||||
// Use Mode.BYTE if Kanji support is disabled
|
||||
if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
|
||||
mode = Mode.BYTE
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case Mode.NUMERIC:
|
||||
return new NumericData(data)
|
||||
|
||||
case Mode.ALPHANUMERIC:
|
||||
return new AlphanumericData(data)
|
||||
|
||||
case Mode.KANJI:
|
||||
return new KanjiData(data)
|
||||
|
||||
case Mode.BYTE:
|
||||
return new ByteData(data)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list of segments from an array.
|
||||
* Array can contain Strings or Objects with segment's info.
|
||||
*
|
||||
* For each item which is a string, will be generated a segment with the given
|
||||
* string and the more appropriate encoding mode.
|
||||
*
|
||||
* For each item which is an object, will be generated a segment with the given
|
||||
* data and mode.
|
||||
* Objects must contain at least the property "data".
|
||||
* If property "mode" is not present, the more suitable mode will be used.
|
||||
*
|
||||
* @param {Array} array Array of objects with segments data
|
||||
* @return {Array} Array of Segments
|
||||
*/
|
||||
exports.fromArray = function fromArray (array) {
|
||||
return array.reduce(function (acc, seg) {
|
||||
if (typeof seg === 'string') {
|
||||
acc.push(buildSingleSegment(seg, null))
|
||||
} else if (seg.data) {
|
||||
acc.push(buildSingleSegment(seg.data, seg.mode))
|
||||
}
|
||||
|
||||
return acc
|
||||
}, [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an optimized sequence of segments from a string,
|
||||
* which will produce the shortest possible bitstream.
|
||||
*
|
||||
* @param {String} data Input string
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Array} Array of segments
|
||||
*/
|
||||
exports.fromString = function fromString (data, version) {
|
||||
const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled())
|
||||
|
||||
const nodes = buildNodes(segs)
|
||||
const graph = buildGraph(nodes, version)
|
||||
const path = dijkstra.find_path(graph.map, 'start', 'end')
|
||||
|
||||
const optimizedSegs = []
|
||||
for (let i = 1; i < path.length - 1; i++) {
|
||||
optimizedSegs.push(graph.table[path[i]].node)
|
||||
}
|
||||
|
||||
return exports.fromArray(mergeSegments(optimizedSegs))
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string in various segments with the modes which
|
||||
* best represent their content.
|
||||
* The produced segments are far from being optimized.
|
||||
* The output of this function is only used to estimate a QR Code version
|
||||
* which may contain the data.
|
||||
*
|
||||
* @param {string} data Input string
|
||||
* @return {Array} Array of segments
|
||||
*/
|
||||
exports.rawSplit = function rawSplit (data) {
|
||||
return exports.fromArray(
|
||||
getSegmentsFromString(data, Utils.isKanjiModeEnabled())
|
||||
)
|
||||
}
|
||||
63
node_modules/qrcode/lib/core/utils.js
generated
vendored
Normal file
63
node_modules/qrcode/lib/core/utils.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
let toSJISFunction
|
||||
const CODEWORDS_COUNT = [
|
||||
0, // Not used
|
||||
26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
|
||||
404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
|
||||
1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
|
||||
2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
|
||||
]
|
||||
|
||||
/**
|
||||
* Returns the QR Code size for the specified version
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Number} size of QR code
|
||||
*/
|
||||
exports.getSymbolSize = function getSymbolSize (version) {
|
||||
if (!version) throw new Error('"version" cannot be null or undefined')
|
||||
if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
|
||||
return version * 4 + 17
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of codewords used to store data and EC information.
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Number} Data length in bits
|
||||
*/
|
||||
exports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
|
||||
return CODEWORDS_COUNT[version]
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode data with Bose-Chaudhuri-Hocquenghem
|
||||
*
|
||||
* @param {Number} data Value to encode
|
||||
* @return {Number} Encoded value
|
||||
*/
|
||||
exports.getBCHDigit = function (data) {
|
||||
let digit = 0
|
||||
|
||||
while (data !== 0) {
|
||||
digit++
|
||||
data >>>= 1
|
||||
}
|
||||
|
||||
return digit
|
||||
}
|
||||
|
||||
exports.setToSJISFunction = function setToSJISFunction (f) {
|
||||
if (typeof f !== 'function') {
|
||||
throw new Error('"toSJISFunc" is not a valid function.')
|
||||
}
|
||||
|
||||
toSJISFunction = f
|
||||
}
|
||||
|
||||
exports.isKanjiModeEnabled = function () {
|
||||
return typeof toSJISFunction !== 'undefined'
|
||||
}
|
||||
|
||||
exports.toSJIS = function toSJIS (kanji) {
|
||||
return toSJISFunction(kanji)
|
||||
}
|
||||
9
node_modules/qrcode/lib/core/version-check.js
generated
vendored
Normal file
9
node_modules/qrcode/lib/core/version-check.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Check if QR Code version is valid
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Boolean} true if valid version, false otherwise
|
||||
*/
|
||||
exports.isValid = function isValid (version) {
|
||||
return !isNaN(version) && version >= 1 && version <= 40
|
||||
}
|
||||
163
node_modules/qrcode/lib/core/version.js
generated
vendored
Normal file
163
node_modules/qrcode/lib/core/version.js
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
const Utils = require('./utils')
|
||||
const ECCode = require('./error-correction-code')
|
||||
const ECLevel = require('./error-correction-level')
|
||||
const Mode = require('./mode')
|
||||
const VersionCheck = require('./version-check')
|
||||
|
||||
// Generator polynomial used to encode version information
|
||||
const G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0)
|
||||
const G18_BCH = Utils.getBCHDigit(G18)
|
||||
|
||||
function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
|
||||
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
||||
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
|
||||
return currentVersion
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
function getReservedBitsCount (mode, version) {
|
||||
// Character count indicator + mode indicator bits
|
||||
return Mode.getCharCountIndicator(mode, version) + 4
|
||||
}
|
||||
|
||||
function getTotalBitsFromDataArray (segments, version) {
|
||||
let totalBits = 0
|
||||
|
||||
segments.forEach(function (data) {
|
||||
const reservedBits = getReservedBitsCount(data.mode, version)
|
||||
totalBits += reservedBits + data.getBitsLength()
|
||||
})
|
||||
|
||||
return totalBits
|
||||
}
|
||||
|
||||
function getBestVersionForMixedData (segments, errorCorrectionLevel) {
|
||||
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
||||
const length = getTotalBitsFromDataArray(segments, currentVersion)
|
||||
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
|
||||
return currentVersion
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns version number from a value.
|
||||
* If value is not a valid version, returns defaultValue
|
||||
*
|
||||
* @param {Number|String} value QR Code version
|
||||
* @param {Number} defaultValue Fallback value
|
||||
* @return {Number} QR Code version number
|
||||
*/
|
||||
exports.from = function from (value, defaultValue) {
|
||||
if (VersionCheck.isValid(value)) {
|
||||
return parseInt(value, 10)
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how much data can be stored with the specified QR code version
|
||||
* and error correction level
|
||||
*
|
||||
* @param {Number} version QR Code version (1-40)
|
||||
* @param {Number} errorCorrectionLevel Error correction level
|
||||
* @param {Mode} mode Data mode
|
||||
* @return {Number} Quantity of storable data
|
||||
*/
|
||||
exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
|
||||
if (!VersionCheck.isValid(version)) {
|
||||
throw new Error('Invalid QR Code version')
|
||||
}
|
||||
|
||||
// Use Byte mode as default
|
||||
if (typeof mode === 'undefined') mode = Mode.BYTE
|
||||
|
||||
// Total codewords for this QR code version (Data + Error correction)
|
||||
const totalCodewords = Utils.getSymbolTotalCodewords(version)
|
||||
|
||||
// Total number of error correction codewords
|
||||
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
|
||||
|
||||
// Total number of data codewords
|
||||
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8
|
||||
|
||||
if (mode === Mode.MIXED) return dataTotalCodewordsBits
|
||||
|
||||
const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version)
|
||||
|
||||
// Return max number of storable codewords
|
||||
switch (mode) {
|
||||
case Mode.NUMERIC:
|
||||
return Math.floor((usableBits / 10) * 3)
|
||||
|
||||
case Mode.ALPHANUMERIC:
|
||||
return Math.floor((usableBits / 11) * 2)
|
||||
|
||||
case Mode.KANJI:
|
||||
return Math.floor(usableBits / 13)
|
||||
|
||||
case Mode.BYTE:
|
||||
default:
|
||||
return Math.floor(usableBits / 8)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum version needed to contain the amount of data
|
||||
*
|
||||
* @param {Segment} data Segment of data
|
||||
* @param {Number} [errorCorrectionLevel=H] Error correction level
|
||||
* @param {Mode} mode Data mode
|
||||
* @return {Number} QR Code version
|
||||
*/
|
||||
exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
|
||||
let seg
|
||||
|
||||
const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M)
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
if (data.length > 1) {
|
||||
return getBestVersionForMixedData(data, ecl)
|
||||
}
|
||||
|
||||
if (data.length === 0) {
|
||||
return 1
|
||||
}
|
||||
|
||||
seg = data[0]
|
||||
} else {
|
||||
seg = data
|
||||
}
|
||||
|
||||
return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns version information with relative error correction bits
|
||||
*
|
||||
* The version information is included in QR Code symbols of version 7 or larger.
|
||||
* It consists of an 18-bit sequence containing 6 data bits,
|
||||
* with 12 error correction bits calculated using the (18, 6) Golay code.
|
||||
*
|
||||
* @param {Number} version QR Code version
|
||||
* @return {Number} Encoded version info bits
|
||||
*/
|
||||
exports.getEncodedBits = function getEncodedBits (version) {
|
||||
if (!VersionCheck.isValid(version) || version < 7) {
|
||||
throw new Error('Invalid QR Code version')
|
||||
}
|
||||
|
||||
let d = version << 12
|
||||
|
||||
while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
|
||||
d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH))
|
||||
}
|
||||
|
||||
return (version << 12) | d
|
||||
}
|
||||
12
node_modules/qrcode/lib/index.js
generated
vendored
Normal file
12
node_modules/qrcode/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
*copyright Ryan Day 2012
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* this is the main server side application file for node-qrcode.
|
||||
* these exports use serverside canvas api methods for file IO and buffers
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = require('./server')
|
||||
63
node_modules/qrcode/lib/renderer/canvas.js
generated
vendored
Normal file
63
node_modules/qrcode/lib/renderer/canvas.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
const Utils = require('./utils')
|
||||
|
||||
function clearCanvas (ctx, canvas, size) {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
||||
|
||||
if (!canvas.style) canvas.style = {}
|
||||
canvas.height = size
|
||||
canvas.width = size
|
||||
canvas.style.height = size + 'px'
|
||||
canvas.style.width = size + 'px'
|
||||
}
|
||||
|
||||
function getCanvasElement () {
|
||||
try {
|
||||
return document.createElement('canvas')
|
||||
} catch (e) {
|
||||
throw new Error('You need to specify a canvas element')
|
||||
}
|
||||
}
|
||||
|
||||
exports.render = function render (qrData, canvas, options) {
|
||||
let opts = options
|
||||
let canvasEl = canvas
|
||||
|
||||
if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
|
||||
opts = canvas
|
||||
canvas = undefined
|
||||
}
|
||||
|
||||
if (!canvas) {
|
||||
canvasEl = getCanvasElement()
|
||||
}
|
||||
|
||||
opts = Utils.getOptions(opts)
|
||||
const size = Utils.getImageWidth(qrData.modules.size, opts)
|
||||
|
||||
const ctx = canvasEl.getContext('2d')
|
||||
const image = ctx.createImageData(size, size)
|
||||
Utils.qrToImageData(image.data, qrData, opts)
|
||||
|
||||
clearCanvas(ctx, canvasEl, size)
|
||||
ctx.putImageData(image, 0, 0)
|
||||
|
||||
return canvasEl
|
||||
}
|
||||
|
||||
exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
|
||||
let opts = options
|
||||
|
||||
if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
|
||||
opts = canvas
|
||||
canvas = undefined
|
||||
}
|
||||
|
||||
if (!opts) opts = {}
|
||||
|
||||
const canvasEl = exports.render(qrData, canvas, opts)
|
||||
|
||||
const type = opts.type || 'image/png'
|
||||
const rendererOpts = opts.rendererOpts || {}
|
||||
|
||||
return canvasEl.toDataURL(type, rendererOpts.quality)
|
||||
}
|
||||
78
node_modules/qrcode/lib/renderer/png.js
generated
vendored
Normal file
78
node_modules/qrcode/lib/renderer/png.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
const fs = require('fs')
|
||||
const PNG = require('pngjs').PNG
|
||||
const Utils = require('./utils')
|
||||
|
||||
exports.render = function render (qrData, options) {
|
||||
const opts = Utils.getOptions(options)
|
||||
const pngOpts = opts.rendererOpts
|
||||
const size = Utils.getImageWidth(qrData.modules.size, opts)
|
||||
|
||||
pngOpts.width = size
|
||||
pngOpts.height = size
|
||||
|
||||
const pngImage = new PNG(pngOpts)
|
||||
Utils.qrToImageData(pngImage.data, qrData, opts)
|
||||
|
||||
return pngImage
|
||||
}
|
||||
|
||||
exports.renderToDataURL = function renderToDataURL (qrData, options, cb) {
|
||||
if (typeof cb === 'undefined') {
|
||||
cb = options
|
||||
options = undefined
|
||||
}
|
||||
|
||||
exports.renderToBuffer(qrData, options, function (err, output) {
|
||||
if (err) cb(err)
|
||||
let url = 'data:image/png;base64,'
|
||||
url += output.toString('base64')
|
||||
cb(null, url)
|
||||
})
|
||||
}
|
||||
|
||||
exports.renderToBuffer = function renderToBuffer (qrData, options, cb) {
|
||||
if (typeof cb === 'undefined') {
|
||||
cb = options
|
||||
options = undefined
|
||||
}
|
||||
|
||||
const png = exports.render(qrData, options)
|
||||
const buffer = []
|
||||
|
||||
png.on('error', cb)
|
||||
|
||||
png.on('data', function (data) {
|
||||
buffer.push(data)
|
||||
})
|
||||
|
||||
png.on('end', function () {
|
||||
cb(null, Buffer.concat(buffer))
|
||||
})
|
||||
|
||||
png.pack()
|
||||
}
|
||||
|
||||
exports.renderToFile = function renderToFile (path, qrData, options, cb) {
|
||||
if (typeof cb === 'undefined') {
|
||||
cb = options
|
||||
options = undefined
|
||||
}
|
||||
|
||||
let called = false
|
||||
const done = (...args) => {
|
||||
if (called) return
|
||||
called = true
|
||||
cb.apply(null, args)
|
||||
}
|
||||
const stream = fs.createWriteStream(path)
|
||||
|
||||
stream.on('error', done)
|
||||
stream.on('close', done)
|
||||
|
||||
exports.renderToFileStream(stream, qrData, options)
|
||||
}
|
||||
|
||||
exports.renderToFileStream = function renderToFileStream (stream, qrData, options) {
|
||||
const png = exports.render(qrData, options)
|
||||
png.pack().pipe(stream)
|
||||
}
|
||||
81
node_modules/qrcode/lib/renderer/svg-tag.js
generated
vendored
Normal file
81
node_modules/qrcode/lib/renderer/svg-tag.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
const Utils = require('./utils')
|
||||
|
||||
function getColorAttrib (color, attrib) {
|
||||
const alpha = color.a / 255
|
||||
const str = attrib + '="' + color.hex + '"'
|
||||
|
||||
return alpha < 1
|
||||
? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
|
||||
: str
|
||||
}
|
||||
|
||||
function svgCmd (cmd, x, y) {
|
||||
let str = cmd + x
|
||||
if (typeof y !== 'undefined') str += ' ' + y
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
function qrToPath (data, size, margin) {
|
||||
let path = ''
|
||||
let moveBy = 0
|
||||
let newRow = false
|
||||
let lineLength = 0
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const col = Math.floor(i % size)
|
||||
const row = Math.floor(i / size)
|
||||
|
||||
if (!col && !newRow) newRow = true
|
||||
|
||||
if (data[i]) {
|
||||
lineLength++
|
||||
|
||||
if (!(i > 0 && col > 0 && data[i - 1])) {
|
||||
path += newRow
|
||||
? svgCmd('M', col + margin, 0.5 + row + margin)
|
||||
: svgCmd('m', moveBy, 0)
|
||||
|
||||
moveBy = 0
|
||||
newRow = false
|
||||
}
|
||||
|
||||
if (!(col + 1 < size && data[i + 1])) {
|
||||
path += svgCmd('h', lineLength)
|
||||
lineLength = 0
|
||||
}
|
||||
} else {
|
||||
moveBy++
|
||||
}
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
exports.render = function render (qrData, options, cb) {
|
||||
const opts = Utils.getOptions(options)
|
||||
const size = qrData.modules.size
|
||||
const data = qrData.modules.data
|
||||
const qrcodesize = size + opts.margin * 2
|
||||
|
||||
const bg = !opts.color.light.a
|
||||
? ''
|
||||
: '<path ' + getColorAttrib(opts.color.light, 'fill') +
|
||||
' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>'
|
||||
|
||||
const path =
|
||||
'<path ' + getColorAttrib(opts.color.dark, 'stroke') +
|
||||
' d="' + qrToPath(data, size, opts.margin) + '"/>'
|
||||
|
||||
const viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"'
|
||||
|
||||
const width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" '
|
||||
|
||||
const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n'
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
cb(null, svgTag)
|
||||
}
|
||||
|
||||
return svgTag
|
||||
}
|
||||
19
node_modules/qrcode/lib/renderer/svg.js
generated
vendored
Normal file
19
node_modules/qrcode/lib/renderer/svg.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
const svgTagRenderer = require('./svg-tag')
|
||||
|
||||
exports.render = svgTagRenderer.render
|
||||
|
||||
exports.renderToFile = function renderToFile (path, qrData, options, cb) {
|
||||
if (typeof cb === 'undefined') {
|
||||
cb = options
|
||||
options = undefined
|
||||
}
|
||||
|
||||
const fs = require('fs')
|
||||
const svgTag = exports.render(qrData, options)
|
||||
|
||||
const xmlStr = '<?xml version="1.0" encoding="utf-8"?>' +
|
||||
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' +
|
||||
svgTag
|
||||
|
||||
fs.writeFile(path, xmlStr, cb)
|
||||
}
|
||||
9
node_modules/qrcode/lib/renderer/terminal.js
generated
vendored
Normal file
9
node_modules/qrcode/lib/renderer/terminal.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
const big = require('./terminal/terminal')
|
||||
const small = require('./terminal/terminal-small')
|
||||
|
||||
exports.render = function (qrData, options, cb) {
|
||||
if (options && options.small) {
|
||||
return small.render(qrData, options, cb)
|
||||
}
|
||||
return big.render(qrData, options, cb)
|
||||
}
|
||||
85
node_modules/qrcode/lib/renderer/terminal/terminal-small.js
generated
vendored
Normal file
85
node_modules/qrcode/lib/renderer/terminal/terminal-small.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
const backgroundWhite = '\x1b[47m'
|
||||
const backgroundBlack = '\x1b[40m'
|
||||
const foregroundWhite = '\x1b[37m'
|
||||
const foregroundBlack = '\x1b[30m'
|
||||
const reset = '\x1b[0m'
|
||||
const lineSetupNormal = backgroundWhite + foregroundBlack // setup colors
|
||||
const lineSetupInverse = backgroundBlack + foregroundWhite // setup colors
|
||||
|
||||
const createPalette = function (lineSetup, foregroundWhite, foregroundBlack) {
|
||||
return {
|
||||
// 1 ... white, 2 ... black, 0 ... transparent (default)
|
||||
|
||||
'00': reset + ' ' + lineSetup,
|
||||
'01': reset + foregroundWhite + '▄' + lineSetup,
|
||||
'02': reset + foregroundBlack + '▄' + lineSetup,
|
||||
10: reset + foregroundWhite + '▀' + lineSetup,
|
||||
11: ' ',
|
||||
12: '▄',
|
||||
20: reset + foregroundBlack + '▀' + lineSetup,
|
||||
21: '▀',
|
||||
22: '█'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns code for QR pixel
|
||||
* @param {boolean[][]} modules
|
||||
* @param {number} size
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @return {'0' | '1' | '2'}
|
||||
*/
|
||||
const mkCodePixel = function (modules, size, x, y) {
|
||||
const sizePlus = size + 1
|
||||
if ((x >= sizePlus) || (y >= sizePlus) || (y < -1) || (x < -1)) return '0'
|
||||
if ((x >= size) || (y >= size) || (y < 0) || (x < 0)) return '1'
|
||||
const idx = (y * size) + x
|
||||
return modules[idx] ? '2' : '1'
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns code for four QR pixels. Suitable as key in palette.
|
||||
* @param {boolean[][]} modules
|
||||
* @param {number} size
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @return {keyof palette}
|
||||
*/
|
||||
const mkCode = function (modules, size, x, y) {
|
||||
return (
|
||||
mkCodePixel(modules, size, x, y) +
|
||||
mkCodePixel(modules, size, x, y + 1)
|
||||
)
|
||||
}
|
||||
|
||||
exports.render = function (qrData, options, cb) {
|
||||
const size = qrData.modules.size
|
||||
const data = qrData.modules.data
|
||||
|
||||
const inverse = !!(options && options.inverse)
|
||||
const lineSetup = options && options.inverse ? lineSetupInverse : lineSetupNormal
|
||||
const white = inverse ? foregroundBlack : foregroundWhite
|
||||
const black = inverse ? foregroundWhite : foregroundBlack
|
||||
|
||||
const palette = createPalette(lineSetup, white, black)
|
||||
const newLine = reset + '\n' + lineSetup
|
||||
|
||||
let output = lineSetup // setup colors
|
||||
|
||||
for (let y = -1; y < size + 1; y += 2) {
|
||||
for (let x = -1; x < size; x++) {
|
||||
output += palette[mkCode(data, size, x, y)]
|
||||
}
|
||||
|
||||
output += palette[mkCode(data, size, size, y)] + newLine
|
||||
}
|
||||
|
||||
output += reset
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
cb(null, output)
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
49
node_modules/qrcode/lib/renderer/terminal/terminal.js
generated
vendored
Normal file
49
node_modules/qrcode/lib/renderer/terminal/terminal.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
// let Utils = require('./utils')
|
||||
|
||||
exports.render = function (qrData, options, cb) {
|
||||
const size = qrData.modules.size
|
||||
const data = qrData.modules.data
|
||||
|
||||
// let opts = Utils.getOptions(options)
|
||||
|
||||
// use same scheme as https://github.com/gtanner/qrcode-terminal because it actually works! =)
|
||||
const black = '\x1b[40m \x1b[0m'
|
||||
const white = '\x1b[47m \x1b[0m'
|
||||
|
||||
let output = ''
|
||||
const hMargin = Array(size + 3).join(white)
|
||||
const vMargin = Array(2).join(white)
|
||||
|
||||
output += hMargin + '\n'
|
||||
for (let i = 0; i < size; ++i) {
|
||||
output += white
|
||||
for (let j = 0; j < size; j++) {
|
||||
// let topModule = data[i * size + j]
|
||||
// let bottomModule = data[(i + 1) * size + j]
|
||||
|
||||
output += data[i * size + j] ? black : white// getBlockChar(topModule, bottomModule)
|
||||
}
|
||||
// output += white+'\n'
|
||||
output += vMargin + '\n'
|
||||
}
|
||||
|
||||
output += hMargin + '\n'
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
cb(null, output)
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
/*
|
||||
exports.renderToFile = function renderToFile (path, qrData, options, cb) {
|
||||
if (typeof cb === 'undefined') {
|
||||
cb = options
|
||||
options = undefined
|
||||
}
|
||||
|
||||
let fs = require('fs')
|
||||
let utf8 = exports.render(qrData, options)
|
||||
fs.writeFile(path, utf8, cb)
|
||||
}
|
||||
*/
|
||||
71
node_modules/qrcode/lib/renderer/utf8.js
generated
vendored
Normal file
71
node_modules/qrcode/lib/renderer/utf8.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
const Utils = require('./utils')
|
||||
|
||||
const BLOCK_CHAR = {
|
||||
WW: ' ',
|
||||
WB: '▄',
|
||||
BB: '█',
|
||||
BW: '▀'
|
||||
}
|
||||
|
||||
const INVERTED_BLOCK_CHAR = {
|
||||
BB: ' ',
|
||||
BW: '▄',
|
||||
WW: '█',
|
||||
WB: '▀'
|
||||
}
|
||||
|
||||
function getBlockChar (top, bottom, blocks) {
|
||||
if (top && bottom) return blocks.BB
|
||||
if (top && !bottom) return blocks.BW
|
||||
if (!top && bottom) return blocks.WB
|
||||
return blocks.WW
|
||||
}
|
||||
|
||||
exports.render = function (qrData, options, cb) {
|
||||
const opts = Utils.getOptions(options)
|
||||
let blocks = BLOCK_CHAR
|
||||
if (opts.color.dark.hex === '#ffffff' || opts.color.light.hex === '#000000') {
|
||||
blocks = INVERTED_BLOCK_CHAR
|
||||
}
|
||||
|
||||
const size = qrData.modules.size
|
||||
const data = qrData.modules.data
|
||||
|
||||
let output = ''
|
||||
let hMargin = Array(size + (opts.margin * 2) + 1).join(blocks.WW)
|
||||
hMargin = Array((opts.margin / 2) + 1).join(hMargin + '\n')
|
||||
|
||||
const vMargin = Array(opts.margin + 1).join(blocks.WW)
|
||||
|
||||
output += hMargin
|
||||
for (let i = 0; i < size; i += 2) {
|
||||
output += vMargin
|
||||
for (let j = 0; j < size; j++) {
|
||||
const topModule = data[i * size + j]
|
||||
const bottomModule = data[(i + 1) * size + j]
|
||||
|
||||
output += getBlockChar(topModule, bottomModule, blocks)
|
||||
}
|
||||
|
||||
output += vMargin + '\n'
|
||||
}
|
||||
|
||||
output += hMargin.slice(0, -1)
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
cb(null, output)
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
exports.renderToFile = function renderToFile (path, qrData, options, cb) {
|
||||
if (typeof cb === 'undefined') {
|
||||
cb = options
|
||||
options = undefined
|
||||
}
|
||||
|
||||
const fs = require('fs')
|
||||
const utf8 = exports.render(qrData, options)
|
||||
fs.writeFile(path, utf8, cb)
|
||||
}
|
||||
99
node_modules/qrcode/lib/renderer/utils.js
generated
vendored
Normal file
99
node_modules/qrcode/lib/renderer/utils.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
function hex2rgba (hex) {
|
||||
if (typeof hex === 'number') {
|
||||
hex = hex.toString()
|
||||
}
|
||||
|
||||
if (typeof hex !== 'string') {
|
||||
throw new Error('Color should be defined as hex string')
|
||||
}
|
||||
|
||||
let hexCode = hex.slice().replace('#', '').split('')
|
||||
if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
|
||||
throw new Error('Invalid hex color: ' + hex)
|
||||
}
|
||||
|
||||
// Convert from short to long form (fff -> ffffff)
|
||||
if (hexCode.length === 3 || hexCode.length === 4) {
|
||||
hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
|
||||
return [c, c]
|
||||
}))
|
||||
}
|
||||
|
||||
// Add default alpha value
|
||||
if (hexCode.length === 6) hexCode.push('F', 'F')
|
||||
|
||||
const hexValue = parseInt(hexCode.join(''), 16)
|
||||
|
||||
return {
|
||||
r: (hexValue >> 24) & 255,
|
||||
g: (hexValue >> 16) & 255,
|
||||
b: (hexValue >> 8) & 255,
|
||||
a: hexValue & 255,
|
||||
hex: '#' + hexCode.slice(0, 6).join('')
|
||||
}
|
||||
}
|
||||
|
||||
exports.getOptions = function getOptions (options) {
|
||||
if (!options) options = {}
|
||||
if (!options.color) options.color = {}
|
||||
|
||||
const margin = typeof options.margin === 'undefined' ||
|
||||
options.margin === null ||
|
||||
options.margin < 0
|
||||
? 4
|
||||
: options.margin
|
||||
|
||||
const width = options.width && options.width >= 21 ? options.width : undefined
|
||||
const scale = options.scale || 4
|
||||
|
||||
return {
|
||||
width: width,
|
||||
scale: width ? 4 : scale,
|
||||
margin: margin,
|
||||
color: {
|
||||
dark: hex2rgba(options.color.dark || '#000000ff'),
|
||||
light: hex2rgba(options.color.light || '#ffffffff')
|
||||
},
|
||||
type: options.type,
|
||||
rendererOpts: options.rendererOpts || {}
|
||||
}
|
||||
}
|
||||
|
||||
exports.getScale = function getScale (qrSize, opts) {
|
||||
return opts.width && opts.width >= qrSize + opts.margin * 2
|
||||
? opts.width / (qrSize + opts.margin * 2)
|
||||
: opts.scale
|
||||
}
|
||||
|
||||
exports.getImageWidth = function getImageWidth (qrSize, opts) {
|
||||
const scale = exports.getScale(qrSize, opts)
|
||||
return Math.floor((qrSize + opts.margin * 2) * scale)
|
||||
}
|
||||
|
||||
exports.qrToImageData = function qrToImageData (imgData, qr, opts) {
|
||||
const size = qr.modules.size
|
||||
const data = qr.modules.data
|
||||
const scale = exports.getScale(size, opts)
|
||||
const symbolSize = Math.floor((size + opts.margin * 2) * scale)
|
||||
const scaledMargin = opts.margin * scale
|
||||
const palette = [opts.color.light, opts.color.dark]
|
||||
|
||||
for (let i = 0; i < symbolSize; i++) {
|
||||
for (let j = 0; j < symbolSize; j++) {
|
||||
let posDst = (i * symbolSize + j) * 4
|
||||
let pxColor = opts.color.light
|
||||
|
||||
if (i >= scaledMargin && j >= scaledMargin &&
|
||||
i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
|
||||
const iSrc = Math.floor((i - scaledMargin) / scale)
|
||||
const jSrc = Math.floor((j - scaledMargin) / scale)
|
||||
pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]
|
||||
}
|
||||
|
||||
imgData[posDst++] = pxColor.r
|
||||
imgData[posDst++] = pxColor.g
|
||||
imgData[posDst++] = pxColor.b
|
||||
imgData[posDst] = pxColor.a
|
||||
}
|
||||
}
|
||||
}
|
||||
138
node_modules/qrcode/lib/server.js
generated
vendored
Normal file
138
node_modules/qrcode/lib/server.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
const canPromise = require('./can-promise')
|
||||
const QRCode = require('./core/qrcode')
|
||||
const PngRenderer = require('./renderer/png')
|
||||
const Utf8Renderer = require('./renderer/utf8')
|
||||
const TerminalRenderer = require('./renderer/terminal')
|
||||
const SvgRenderer = require('./renderer/svg')
|
||||
|
||||
function checkParams (text, opts, cb) {
|
||||
if (typeof text === 'undefined') {
|
||||
throw new Error('String required as first argument')
|
||||
}
|
||||
|
||||
if (typeof cb === 'undefined') {
|
||||
cb = opts
|
||||
opts = {}
|
||||
}
|
||||
|
||||
if (typeof cb !== 'function') {
|
||||
if (!canPromise()) {
|
||||
throw new Error('Callback required as last argument')
|
||||
} else {
|
||||
opts = cb || {}
|
||||
cb = null
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
opts: opts,
|
||||
cb: cb
|
||||
}
|
||||
}
|
||||
|
||||
function getTypeFromFilename (path) {
|
||||
return path.slice((path.lastIndexOf('.') - 1 >>> 0) + 2).toLowerCase()
|
||||
}
|
||||
|
||||
function getRendererFromType (type) {
|
||||
switch (type) {
|
||||
case 'svg':
|
||||
return SvgRenderer
|
||||
|
||||
case 'txt':
|
||||
case 'utf8':
|
||||
return Utf8Renderer
|
||||
|
||||
case 'png':
|
||||
case 'image/png':
|
||||
default:
|
||||
return PngRenderer
|
||||
}
|
||||
}
|
||||
|
||||
function getStringRendererFromType (type) {
|
||||
switch (type) {
|
||||
case 'svg':
|
||||
return SvgRenderer
|
||||
|
||||
case 'terminal':
|
||||
return TerminalRenderer
|
||||
|
||||
case 'utf8':
|
||||
default:
|
||||
return Utf8Renderer
|
||||
}
|
||||
}
|
||||
|
||||
function render (renderFunc, text, params) {
|
||||
if (!params.cb) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
const data = QRCode.create(text, params.opts)
|
||||
return renderFunc(data, params.opts, function (err, data) {
|
||||
return err ? reject(err) : resolve(data)
|
||||
})
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
const data = QRCode.create(text, params.opts)
|
||||
return renderFunc(data, params.opts, params.cb)
|
||||
} catch (e) {
|
||||
params.cb(e)
|
||||
}
|
||||
}
|
||||
|
||||
exports.create = QRCode.create
|
||||
|
||||
exports.toCanvas = require('./browser').toCanvas
|
||||
|
||||
exports.toString = function toString (text, opts, cb) {
|
||||
const params = checkParams(text, opts, cb)
|
||||
const type = params.opts ? params.opts.type : undefined
|
||||
const renderer = getStringRendererFromType(type)
|
||||
return render(renderer.render, text, params)
|
||||
}
|
||||
|
||||
exports.toDataURL = function toDataURL (text, opts, cb) {
|
||||
const params = checkParams(text, opts, cb)
|
||||
const renderer = getRendererFromType(params.opts.type)
|
||||
return render(renderer.renderToDataURL, text, params)
|
||||
}
|
||||
|
||||
exports.toBuffer = function toBuffer (text, opts, cb) {
|
||||
const params = checkParams(text, opts, cb)
|
||||
const renderer = getRendererFromType(params.opts.type)
|
||||
return render(renderer.renderToBuffer, text, params)
|
||||
}
|
||||
|
||||
exports.toFile = function toFile (path, text, opts, cb) {
|
||||
if (typeof path !== 'string' || !(typeof text === 'string' || typeof text === 'object')) {
|
||||
throw new Error('Invalid argument')
|
||||
}
|
||||
|
||||
if ((arguments.length < 3) && !canPromise()) {
|
||||
throw new Error('Too few arguments provided')
|
||||
}
|
||||
|
||||
const params = checkParams(text, opts, cb)
|
||||
const type = params.opts.type || getTypeFromFilename(path)
|
||||
const renderer = getRendererFromType(type)
|
||||
const renderToFile = renderer.renderToFile.bind(null, path)
|
||||
|
||||
return render(renderToFile, text, params)
|
||||
}
|
||||
|
||||
exports.toFileStream = function toFileStream (stream, text, opts) {
|
||||
if (arguments.length < 2) {
|
||||
throw new Error('Too few arguments provided')
|
||||
}
|
||||
|
||||
const params = checkParams(text, opts, stream.emit.bind(stream, 'error'))
|
||||
const renderer = getRendererFromType('png') // Only png support for now
|
||||
const renderToFileStream = renderer.renderToFileStream.bind(null, stream)
|
||||
render(renderToFileStream, text, params)
|
||||
}
|
||||
10
node_modules/qrcode/license
generated
vendored
Normal file
10
node_modules/qrcode/license
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Ryan Day
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
77
node_modules/qrcode/package.json
generated
vendored
Normal file
77
node_modules/qrcode/package.json
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"name": "qrcode",
|
||||
"description": "QRCode / 2d Barcode api with both server side and client side support using canvas",
|
||||
"version": "1.5.4",
|
||||
"author": "Ryan Day <soldair@gmail.com>",
|
||||
"contributors": [
|
||||
"Vincenzo Greco <greco.vincenzo@gmail.com>",
|
||||
"Linus Unnebäck <linus@folkdatorn.se>"
|
||||
],
|
||||
"keywords": [
|
||||
"qr",
|
||||
"code",
|
||||
"canvas",
|
||||
"qrcode"
|
||||
],
|
||||
"main": "./lib/index.js",
|
||||
"browser": {
|
||||
"./lib/index.js": "./lib/browser.js",
|
||||
"fs": false
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"build",
|
||||
"lib",
|
||||
"helper"
|
||||
],
|
||||
"homepage": "http://github.com/soldair/node-qrcode",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"lint": "standard",
|
||||
"pretest": "npm run lint",
|
||||
"test": "node --throw-deprecation test.js",
|
||||
"build": "rollup -c",
|
||||
"prepublish": "npm run build",
|
||||
"browser": "node examples/clientsideserver.js"
|
||||
},
|
||||
"bin": {
|
||||
"qrcode": "./bin/qrcode"
|
||||
},
|
||||
"dependencies": {
|
||||
"dijkstrajs": "^1.0.1",
|
||||
"pngjs": "^5.0.0",
|
||||
"yargs": "^15.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.9.0",
|
||||
"@babel/preset-env": "^7.9.5",
|
||||
"@rollup/plugin-commonjs": "^11.1.0",
|
||||
"@rollup/plugin-node-resolve": "^7.1.3",
|
||||
"browserify": "^16.5.1",
|
||||
"canvas": "^2.8.0",
|
||||
"canvasutil": "0.0.4",
|
||||
"colors": "^1.4.0",
|
||||
"express": "^4.17.1",
|
||||
"htmlparser2": "^4.1.0",
|
||||
"rollup": "^2.6.1",
|
||||
"rollup-plugin-babel": "^4.4.0",
|
||||
"rollup-plugin-terser": "^5.3.0",
|
||||
"sinon": "^9.0.2",
|
||||
"standard": "^16.0.4",
|
||||
"tap": "^16.2.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/soldair/node-qrcode.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"build/",
|
||||
"examples/vendors/",
|
||||
"lib/core/regex.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user