@pjaudiomv/qrcode-svg 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/qrcode-svg.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -0
- package/README.md +280 -0
- package/app.js +156 -0
- package/bin/qrcode-svg.js +2 -0
- package/dist/qrcode.min.js +2 -0
- package/examples/ascii.js +15 -0
- package/examples/ascii.txt +26 -0
- package/examples/convert.js +25 -0
- package/examples/index.html +12 -0
- package/examples/output/ascii.txt +26 -0
- package/examples/output/convert.pdf +0 -0
- package/examples/output/convert.png +0 -0
- package/examples/output/sample-1.svg +306 -0
- package/examples/output/sample-2.svg +324 -0
- package/examples/output/sample-3.svg +408 -0
- package/examples/samples.js +38 -0
- package/lib/qrcode.js +1672 -0
- package/minify.js +17 -0
- package/package.json +31 -0
- package/pjaudiomv-qrcode-svg-1.0.0.tgz +0 -0
- package/test/test.js +277 -0
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/qrcode-svg.iml" filepath="$PROJECT_DIR$/.idea/qrcode-svg.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 papnkukn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
## Introduction
|
|
2
|
+
|
|
3
|
+
This library has been written to generate a SVG image of QR Code in Node.js, goals:
|
|
4
|
+
* pure JavaScript
|
|
5
|
+
* no browser requirement
|
|
6
|
+
* no external dependencies
|
|
7
|
+
* generate SVG output
|
|
8
|
+
|
|
9
|
+
## Getting Started
|
|
10
|
+
|
|
11
|
+
Install the package:
|
|
12
|
+
```bash
|
|
13
|
+
npm install @lemaik/qrcode-svg
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Inline example:
|
|
17
|
+
```javascript
|
|
18
|
+
var QRCode = require("@lemaik/qrcode-svg");
|
|
19
|
+
var svg = new QRCode("Hello World!").svg();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
More options:
|
|
23
|
+
```javascript
|
|
24
|
+
var qrcode = new QRCode({
|
|
25
|
+
content: "http://github.com/",
|
|
26
|
+
padding: 4,
|
|
27
|
+
width: 256,
|
|
28
|
+
height: 256,
|
|
29
|
+
color: "#000000",
|
|
30
|
+
background: "#ffffff",
|
|
31
|
+
ecl: "M",
|
|
32
|
+
});
|
|
33
|
+
qrcode.save("sample.svg", function(error) {
|
|
34
|
+
if (error) throw error;
|
|
35
|
+
console.log("Done!");
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Options
|
|
40
|
+
|
|
41
|
+
**List of options:**
|
|
42
|
+
* **content** - QR Code content, the only **required** parameter
|
|
43
|
+
* **padding** - white space padding, `4` modules by default, `0` for no border
|
|
44
|
+
* **width** - QR Code width in pixels
|
|
45
|
+
* **height** - QR Code height in pixels
|
|
46
|
+
* **color** - color of modules (squares), color name or hex string, e.g. `#000000`
|
|
47
|
+
* **background** - color of background, color name or hex string, e.g. `white`
|
|
48
|
+
* **ecl** - error correction level: `L`, `M`, `H`, `Q`
|
|
49
|
+
* **join** - join modules (squares) into one shape, into the SVG `path` element, **recommended** for web and responsive use, default: `false`
|
|
50
|
+
* **predefined** - to create a squares as pattern, then populate the canvas, default: `false`, see the output examples below
|
|
51
|
+
* **pretty** - apply indents and new lines, default: `true`
|
|
52
|
+
* **swap** - swap X and Y modules, only if you have issues with some QR readers, default: `false`
|
|
53
|
+
* **xmlDeclaration** - prepend XML declaration to the SVG document, i.e. `<?xml version="1.0" standalone="yes"?>`, default: `true`
|
|
54
|
+
* **container** - wrapping element, default: `svg`, see below
|
|
55
|
+
|
|
56
|
+
**Container options:**
|
|
57
|
+
* **svg** - populate squares in a SVG document with `width` and `height` attriute, recommended for converting to raster images or PDF where QR Code is being static (exact size)
|
|
58
|
+
* **svg-viewbox** - populate squares in a SVG document with `viewBox` attriute, **recommended** for responsive web pages
|
|
59
|
+
* **g** - put squares in `g` element, useful when you need to put multiple QR Codes in a single SVG document
|
|
60
|
+
* **none** - no wrapper
|
|
61
|
+
|
|
62
|
+
## SVG output
|
|
63
|
+
|
|
64
|
+
### Editable squares
|
|
65
|
+
|
|
66
|
+
This mode is useful for designers to manipulate with particular squares.
|
|
67
|
+
Thus, one can open the QR Code in an editor, select particular modules, move around, change color, etc.
|
|
68
|
+
However, some old SVG viewers may generate minor gaps between the squares - the side effect when rendering an image at certain zoom level.
|
|
69
|
+
|
|
70
|
+
Default options
|
|
71
|
+
```javascript
|
|
72
|
+
var qrcode = new QRCode({
|
|
73
|
+
content: "Pretty Fox",
|
|
74
|
+
join: false,
|
|
75
|
+
predefined: false
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Output with `rect` elements
|
|
80
|
+
```xml
|
|
81
|
+
<?xml version="1.0" standalone="yes"?>
|
|
82
|
+
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="256" height="256">
|
|
83
|
+
<rect x="0" y="0" width="256" height="256" style="fill:#ffffff;shape-rendering:crispEdges;"/>
|
|
84
|
+
<rect x="16" y="16" width="8" height="8" style="fill:#000000;shape-rendering:crispEdges;"/>
|
|
85
|
+
<rect x="24" y="16" width="8" height="8" style="fill:#000000;shape-rendering:crispEdges;"/>
|
|
86
|
+
<rect x="32" y="16" width="8" height="8" style="fill:#000000;shape-rendering:crispEdges;"/>
|
|
87
|
+
...
|
|
88
|
+
</svg>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Responsive web page
|
|
92
|
+
|
|
93
|
+
Squares joined into one `path` shape produce a compact file size, i.e. 4-5x reduced compared with `rect` elements.
|
|
94
|
+
A single `path` element will result in an optimized rendering, thus not producing any minor gaps between the squares.
|
|
95
|
+
Also using the container with `viewBox` attribute may contribute to the responsive scaling on the web.
|
|
96
|
+
|
|
97
|
+
Set `join` to `true`
|
|
98
|
+
```javascript
|
|
99
|
+
var qrcode = new QRCode({
|
|
100
|
+
content: "Pretty Fox",
|
|
101
|
+
join: true,
|
|
102
|
+
container: "svg-viewbox" //Useful but not required
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Output with `path` element
|
|
107
|
+
```xml
|
|
108
|
+
<?xml version="1.0" standalone="yes"?>
|
|
109
|
+
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 256 256">
|
|
110
|
+
<rect x="0" y="0" width="256" height="256" style="fill:beige;shape-rendering:crispEdges;"/>
|
|
111
|
+
<path x="0" y="0" style="fill:blue;shape-rendering:crispEdges;" d="M35.31,35.31 V44.14 H44.14 V35.31 H35.31 Z..." />
|
|
112
|
+
</svg>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Predefined pattern
|
|
116
|
+
|
|
117
|
+
Algorithm defines the square pattern once before populating a canvas. Useful if you want to generate QR Code with candies.
|
|
118
|
+
However, some SVG software and converters do not support `defs` or `use` elements.
|
|
119
|
+
|
|
120
|
+
Set `predefined` to `true`
|
|
121
|
+
```javascript
|
|
122
|
+
var qrcode = new QRCode({
|
|
123
|
+
content: "Pretty Fox",
|
|
124
|
+
predefined: true
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Output with `defs` and `use` elements
|
|
129
|
+
```xml
|
|
130
|
+
<?xml version="1.0" standalone="yes"?>
|
|
131
|
+
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="256" height="256">
|
|
132
|
+
<defs><path id="qrmodule" d="M0 0 h8.827586206896552 v8.827586206896552 H0 z" style="fill:maroon;shape-rendering:crispEdges;" /></defs>
|
|
133
|
+
<rect x="0" y="0" width="256" height="256" style="fill:beige;shape-rendering:crispEdges;"/>
|
|
134
|
+
<use x="35.310344827586206" y="35.310344827586206" href="#qrmodule" />
|
|
135
|
+
<use x="44.13793103448276" y="35.310344827586206" href="#qrmodule" />
|
|
136
|
+
<use x="52.96551724137931" y="35.310344827586206" href="#qrmodule" />
|
|
137
|
+
<use x="61.79310344827586" y="35.310344827586206" href="#qrmodule" />
|
|
138
|
+
<use x="70.62068965517241" y="35.310344827586206" href="#qrmodule" />
|
|
139
|
+
...
|
|
140
|
+
</svg>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Command Line
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
Usage:
|
|
147
|
+
qrcode-svg [options] <content>
|
|
148
|
+
|
|
149
|
+
Options:
|
|
150
|
+
--help Print this message
|
|
151
|
+
--version, -v Print version number
|
|
152
|
+
--padding , -p [value] Offset in number of modules
|
|
153
|
+
--width, -w [px] Image width in pixels
|
|
154
|
+
--height, -h [px] Image height in pixels
|
|
155
|
+
--color, -fg [color] Foreground color, hex or name
|
|
156
|
+
--background [color] Background color, hex or name
|
|
157
|
+
--ecl [value] Error correction level: L, M, H, Q
|
|
158
|
+
--join Join modules into one SVG path, i.e. for crisp rendering
|
|
159
|
+
--predefined Use 'defs' and 'use' elements in SVG, i.e. for compact output
|
|
160
|
+
--no-prettify Avoid indenting and new lines in SVG, i.e. for compact output
|
|
161
|
+
--viewbox Use 'viewBox' instead of 'width' and 'height' attributes
|
|
162
|
+
--swap-fix Swap X and Y modules to fix issues with some QR readers
|
|
163
|
+
--output, -o [file] Output file name
|
|
164
|
+
--force, -f Force overwrite
|
|
165
|
+
|
|
166
|
+
Examples:
|
|
167
|
+
qrcode-svg http://github.com
|
|
168
|
+
qrcode-svg -f -o hello.svg "Hello World"
|
|
169
|
+
qrcode-svg -p 4 -w 256 -h 256 --join --viewbox "Responsive..."
|
|
170
|
+
qrcode-svg --padding 2 --width 120 --height 120 "Little fox..."
|
|
171
|
+
qrcode-svg --color blue --background #ececec "...jumps over"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Usage Scenarios
|
|
175
|
+
|
|
176
|
+
### Convert to other formats
|
|
177
|
+
|
|
178
|
+
Using [html-pdf](https://www.npmjs.com/package/html-pdf) to convert SVG to PDF (or PNG or JPEG)
|
|
179
|
+
```javascript
|
|
180
|
+
var QRCode = require('@lemaik/qrcode-svg');
|
|
181
|
+
var svg = new QRCode('hello').svg();
|
|
182
|
+
...
|
|
183
|
+
var pdf = require('html-pdf');
|
|
184
|
+
pdf.create(svg, { border: 0, type: 'pdf' }).toFile('output.pdf', function(err, res) {
|
|
185
|
+
...
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### ASCII modules
|
|
190
|
+
|
|
191
|
+
QR Code in ASCII to output in a shell
|
|
192
|
+
```javascript
|
|
193
|
+
var QRCode = require('@lemaik/qrcode-svg');
|
|
194
|
+
|
|
195
|
+
var hello = new QRCode("Hello World!");
|
|
196
|
+
var modules = hello.qrcode.modules;
|
|
197
|
+
|
|
198
|
+
var ascii = '';
|
|
199
|
+
var length = modules.length;
|
|
200
|
+
for (var y = 0; y < length; y++) {
|
|
201
|
+
for (var x = 0; x < length; x++) {
|
|
202
|
+
var module = modules[x][y];
|
|
203
|
+
ascii += (module ? 'x' : ' ');
|
|
204
|
+
}
|
|
205
|
+
ascii += '\r\n';
|
|
206
|
+
}
|
|
207
|
+
console.log(ascii);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
xxxxxxx xx x x xxxxxxx
|
|
214
|
+
x x xxxx x x x x
|
|
215
|
+
x xxx x xx xx x x xxx x
|
|
216
|
+
x xxx x xx x xxx x
|
|
217
|
+
x xxx x x x x x xxx x
|
|
218
|
+
x x x xx xx x x
|
|
219
|
+
xxxxxxx x x x x x xxxxxxx
|
|
220
|
+
xx xx
|
|
221
|
+
x x xx x x xx x x
|
|
222
|
+
x x xx x xx x xx x
|
|
223
|
+
x x xx x x x xx xx
|
|
224
|
+
x xx xxx xx x x x x x
|
|
225
|
+
xx xxxx xxxx x
|
|
226
|
+
x x x xx x xx xx x xx xx
|
|
227
|
+
x xx xxxx xxxx
|
|
228
|
+
xx xx x x x x xx x
|
|
229
|
+
xxxx xxxx xxxxxx x
|
|
230
|
+
x x x
|
|
231
|
+
xxxxxxx x xxx x x x x
|
|
232
|
+
x x xxx x xx x x
|
|
233
|
+
x xxx x xxxxxxxxxx
|
|
234
|
+
x xxx x xxxxxxxxx x xx
|
|
235
|
+
x xxx x xxx xx x x x
|
|
236
|
+
x x x x x
|
|
237
|
+
xxxxxxx xxx xxx x x x
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Web browser
|
|
243
|
+
|
|
244
|
+
Use on a HTML page with JavaScript
|
|
245
|
+
```html
|
|
246
|
+
<!DOCTYPE html>
|
|
247
|
+
<html>
|
|
248
|
+
<body>
|
|
249
|
+
<div id="container"></div>
|
|
250
|
+
<script src="dist/qrcode.min.js"></script>
|
|
251
|
+
<script>
|
|
252
|
+
var qrcode = new QRCode({
|
|
253
|
+
content: "Hello World!",
|
|
254
|
+
container: "svg-viewbox", //Responsive use
|
|
255
|
+
join: true //Crisp rendering and 4-5x reduced file size
|
|
256
|
+
});
|
|
257
|
+
var svg = qrcode.svg();
|
|
258
|
+
document.getElementById("container").innerHTML = svg;
|
|
259
|
+
</script>
|
|
260
|
+
</body>
|
|
261
|
+
</html>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Thanks
|
|
265
|
+
|
|
266
|
+
Thanks to [davidshimjs](https://github.com/davidshimjs/qrcodejs) for the base library.
|
|
267
|
+
|
|
268
|
+
Thanks to [Kazuhiko Arase](http://www.d-project.com/) for the original QR Code in JavaScript algorithm.
|
|
269
|
+
|
|
270
|
+
Thanks to all contributors on the GitHub.
|
|
271
|
+
|
|
272
|
+
## Legal notice
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
Licensed under the MIT license:
|
|
276
|
+
http://www.opensource.org/licenses/mit-license.php
|
|
277
|
+
|
|
278
|
+
The word "QR Code" is registered trademark of DENSO WAVE INCORPORATED
|
|
279
|
+
http://www.denso-wave.com/qrcode/faqpatent-e.html
|
|
280
|
+
```
|
package/app.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
var os = require('os');
|
|
2
|
+
var fs = require('fs');
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var QRCode = require("./lib/qrcode.js");
|
|
5
|
+
|
|
6
|
+
//Default configuration
|
|
7
|
+
var config = {
|
|
8
|
+
verbose: process.env.NODE_VERBOSE == "true" || process.env.NODE_VERBOSE == "1"
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//Command line interface
|
|
12
|
+
var args = process.argv.slice(2);
|
|
13
|
+
for (var i = 0; i < args.length; i++) {
|
|
14
|
+
switch (args[i]) {
|
|
15
|
+
case "--help":
|
|
16
|
+
help();
|
|
17
|
+
process.exit(0);
|
|
18
|
+
break;
|
|
19
|
+
|
|
20
|
+
//Padding in number of modules
|
|
21
|
+
case "-p":
|
|
22
|
+
case "--padding":
|
|
23
|
+
config.padding = parseFloat(args[++i]);
|
|
24
|
+
break;
|
|
25
|
+
|
|
26
|
+
//Width in pixels
|
|
27
|
+
case "-w":
|
|
28
|
+
case "--width":
|
|
29
|
+
config.width = parseFloat(args[++i]);
|
|
30
|
+
break;
|
|
31
|
+
|
|
32
|
+
//Height in pixels
|
|
33
|
+
case "-h":
|
|
34
|
+
case "--height":
|
|
35
|
+
config.height = parseFloat(args[++i]);
|
|
36
|
+
break;
|
|
37
|
+
|
|
38
|
+
//Foreground color
|
|
39
|
+
case "-fg":
|
|
40
|
+
case "--color":
|
|
41
|
+
config.color = args[++i];
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
//Background color
|
|
45
|
+
case "-bg":
|
|
46
|
+
case "--background":
|
|
47
|
+
config.background = args[++i];
|
|
48
|
+
break;
|
|
49
|
+
|
|
50
|
+
case "--ecl":
|
|
51
|
+
config.ecl = args[++i];
|
|
52
|
+
break;
|
|
53
|
+
|
|
54
|
+
case "--join":
|
|
55
|
+
config.join = true;
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case "--predefined":
|
|
59
|
+
config.predefined = true;
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case "--viewbox":
|
|
63
|
+
config.container = "svg-viewbox";
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case "--no-prettify":
|
|
67
|
+
config.pretty = false;
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case "--swap-fix":
|
|
71
|
+
config.swap = true;
|
|
72
|
+
break;
|
|
73
|
+
|
|
74
|
+
case "-f":
|
|
75
|
+
case "--force":
|
|
76
|
+
config.force = true;
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case "-o":
|
|
80
|
+
case "--output":
|
|
81
|
+
config.outputFile = args[++i];
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case "-v":
|
|
85
|
+
case "--version":
|
|
86
|
+
console.log(require('./package.json').version);
|
|
87
|
+
process.exit(0);
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
default:
|
|
91
|
+
if (i == args.length - 1) {
|
|
92
|
+
config.content = args[i];
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
console.error("Unknown command line argument: " + args[i]);
|
|
96
|
+
process.exit(2);
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//Prints help message
|
|
103
|
+
function help() {
|
|
104
|
+
console.log("Usage:");
|
|
105
|
+
console.log(" qrcode-svg [options] <content>");
|
|
106
|
+
console.log("");
|
|
107
|
+
console.log("Options:");
|
|
108
|
+
console.log(" --help Print this message");
|
|
109
|
+
console.log(" --version, -v Print version number");
|
|
110
|
+
console.log(" --padding , -p [value] Offset in number of modules");
|
|
111
|
+
console.log(" --width, -w [px] Image width in pixels");
|
|
112
|
+
console.log(" --height, -h [px] Image height in pixels");
|
|
113
|
+
console.log(" --color, -fg [color] Foreground color, hex or name");
|
|
114
|
+
console.log(" --background [color] Background color, hex or name");
|
|
115
|
+
console.log(" --ecl [value] Error correction level: L, M, H, Q");
|
|
116
|
+
console.log(" --join Join modules into one SVG path, i.e. for crisp rendering");
|
|
117
|
+
console.log(" --predefined Use 'defs' and 'use' elements in SVG, i.e. for compact output");
|
|
118
|
+
console.log(" --no-prettify Avoid indenting and new lines in SVG, i.e. for compact output");
|
|
119
|
+
console.log(" --viewbox Use 'viewBox' instead of 'width' and 'height' attributes");
|
|
120
|
+
console.log(" --swap-fix Swap X and Y modules to fix issues with some QR readers");
|
|
121
|
+
console.log(" --output, -o [file] Output file name");
|
|
122
|
+
console.log(" --force, -f Force overwrite");
|
|
123
|
+
console.log("");
|
|
124
|
+
console.log("Examples:");
|
|
125
|
+
console.log(" qrcode-svg http://github.com");
|
|
126
|
+
console.log(" qrcode-svg -f -o hello.svg \"Hello World\"");
|
|
127
|
+
console.log(" qrcode-svg -p 4 -w 256 -h 256 --join --viewbox \"Responsive...\"");
|
|
128
|
+
console.log(" qrcode-svg --padding 2 --width 120 --height 120 \"Little fox...\"");
|
|
129
|
+
console.log(" qrcode-svg --color blue --background #ececec \"...jumps over\"");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (args.length == 0) {
|
|
133
|
+
help();
|
|
134
|
+
process.exit(0);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (typeof config.content != "string" || config.content.length == 0) {
|
|
138
|
+
console.error("Content is missing!");
|
|
139
|
+
process.exit(2);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
var qrcode = new QRCode(config);
|
|
143
|
+
var svg = qrcode.svg();
|
|
144
|
+
|
|
145
|
+
if (typeof config.outputFile == "string" && config.outputFile.length > 0) {
|
|
146
|
+
if (!config.force && fs.existsSync(config.outputFile)) {
|
|
147
|
+
console.error("File already exists: " + config.outputFile);
|
|
148
|
+
process.exit(2);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fs.writeFileSync(config.outputFile, svg);
|
|
152
|
+
console.log("Done!");
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
console.log(svg);
|
|
156
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @lemaik/qrcode-svg v1.2.0 | https://github.com/leMaik/qrcode-svg | MIT license */
|
|
2
|
+
function QR8bitByte(t){this.mode=QRMode.MODE_8BIT_BYTE,this.data=t,this.parsedData=[];for(var e=0,r=this.data.length;e<r;e++){var o=[],i=this.data.charCodeAt(e);i>65536?(o[0]=240|(1835008&i)>>>18,o[1]=128|(258048&i)>>>12,o[2]=128|(4032&i)>>>6,o[3]=128|63&i):i>2048?(o[0]=224|(61440&i)>>>12,o[1]=128|(4032&i)>>>6,o[2]=128|63&i):i>128?(o[0]=192|(1984&i)>>>6,o[1]=128|63&i):o[0]=i,this.parsedData.push(o)}this.parsedData=Array.prototype.concat.apply([],this.parsedData),this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function QRCodeModel(t,e){this.typeNumber=t,this.errorCorrectLevel=e,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}QR8bitByte.prototype={getLength:function(t){return this.parsedData.length},write:function(t){for(var e=0,r=this.parsedData.length;e<r;e++)t.put(this.parsedData[e],8)}},QRCodeModel.prototype={addData:function(t){var e=new QR8bitByte(t);this.dataList.push(e),this.dataCache=null},isDark:function(t,e){if(t<0||this.moduleCount<=t||e<0||this.moduleCount<=e)throw new Error(t+","+e);return this.modules[t][e]},getModuleCount:function(){return this.moduleCount},make:function(){if(this.typeNumber<1){var t=1;for(t=1;t<40;t++){for(var e=QRRSBlock.getRSBlocks(t,this.errorCorrectLevel),r=new QRBitBuffer,o=0,i=0;i<e.length;i++)o+=e[i].dataCount;for(i=0;i<this.dataList.length;i++){var n=this.dataList[i];r.put(n.mode,4),r.put(n.getLength(),QRUtil.getLengthInBits(n.mode,t)),n.write(r)}if(r.getLengthInBits()<=8*o)break}this.typeNumber=t}this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(t,e){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var r=0;r<this.moduleCount;r++){this.modules[r]=new Array(this.moduleCount);for(var o=0;o<this.moduleCount;o++)this.modules[r][o]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(t,e),this.typeNumber>=7&&this.setupTypeNumber(t),null==this.dataCache&&(this.dataCache=QRCodeModel.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,e)},setupPositionProbePattern:function(t,e){for(var r=-1;r<=7;r++)if(!(t+r<=-1||this.moduleCount<=t+r))for(var o=-1;o<=7;o++)e+o<=-1||this.moduleCount<=e+o||(this.modules[t+r][e+o]=0<=r&&r<=6&&(0==o||6==o)||0<=o&&o<=6&&(0==r||6==r)||2<=r&&r<=4&&2<=o&&o<=4)},getBestMaskPattern:function(){for(var t=0,e=0,r=0;r<8;r++){this.makeImpl(!0,r);var o=QRUtil.getLostPoint(this);(0==r||t>o)&&(t=o,e=r)}return e},createMovieClip:function(t,e,r){var o=t.createEmptyMovieClip(e,r);this.make();for(var i=0;i<this.modules.length;i++)for(var n=1*i,a=0;a<this.modules[i].length;a++){var s=1*a;this.modules[i][a]&&(o.beginFill(0,100),o.moveTo(s,n),o.lineTo(s+1,n),o.lineTo(s+1,n+1),o.lineTo(s,n+1),o.endFill())}return o},setupTimingPattern:function(){for(var t=8;t<this.moduleCount-8;t++)null==this.modules[t][6]&&(this.modules[t][6]=t%2==0);for(var e=8;e<this.moduleCount-8;e++)null==this.modules[6][e]&&(this.modules[6][e]=e%2==0)},setupPositionAdjustPattern:function(){for(var t=QRUtil.getPatternPosition(this.typeNumber),e=0;e<t.length;e++)for(var r=0;r<t.length;r++){var o=t[e],i=t[r];if(null==this.modules[o][i])for(var n=-2;n<=2;n++)for(var a=-2;a<=2;a++)this.modules[o+n][i+a]=-2==n||2==n||-2==a||2==a||0==n&&0==a}},setupTypeNumber:function(t){for(var e=QRUtil.getBCHTypeNumber(this.typeNumber),r=0;r<18;r++){var o=!t&&1==(e>>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=o}for(r=0;r<18;r++){o=!t&&1==(e>>r&1);this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=o}},setupTypeInfo:function(t,e){for(var r=this.errorCorrectLevel<<3|e,o=QRUtil.getBCHTypeInfo(r),i=0;i<15;i++){var n=!t&&1==(o>>i&1);i<6?this.modules[i][8]=n:i<8?this.modules[i+1][8]=n:this.modules[this.moduleCount-15+i][8]=n}for(i=0;i<15;i++){n=!t&&1==(o>>i&1);i<8?this.modules[8][this.moduleCount-i-1]=n:i<9?this.modules[8][15-i-1+1]=n:this.modules[8][15-i-1]=n}this.modules[this.moduleCount-8][8]=!t},mapData:function(t,e){for(var r=-1,o=this.moduleCount-1,i=7,n=0,a=this.moduleCount-1;a>0;a-=2)for(6==a&&a--;;){for(var s=0;s<2;s++)if(null==this.modules[o][a-s]){var h=!1;n<t.length&&(h=1==(t[n]>>>i&1)),QRUtil.getMask(e,o,a-s)&&(h=!h),this.modules[o][a-s]=h,-1==--i&&(n++,i=7)}if((o+=r)<0||this.moduleCount<=o){o-=r,r=-r;break}}}},QRCodeModel.PAD0=236,QRCodeModel.PAD1=17,QRCodeModel.createData=function(t,e,r){for(var o=QRRSBlock.getRSBlocks(t,e),i=new QRBitBuffer,n=0;n<r.length;n++){var a=r[n];i.put(a.mode,4),i.put(a.getLength(),QRUtil.getLengthInBits(a.mode,t)),a.write(i)}var s=0;for(n=0;n<o.length;n++)s+=o[n].dataCount;if(i.getLengthInBits()>8*s)throw new Error("code length overflow. ("+i.getLengthInBits()+">"+8*s+")");for(i.getLengthInBits()+4<=8*s&&i.put(0,4);i.getLengthInBits()%8!=0;)i.putBit(!1);for(;!(i.getLengthInBits()>=8*s||(i.put(QRCodeModel.PAD0,8),i.getLengthInBits()>=8*s));)i.put(QRCodeModel.PAD1,8);return QRCodeModel.createBytes(i,o)},QRCodeModel.createBytes=function(t,e){for(var r=0,o=0,i=0,n=new Array(e.length),a=new Array(e.length),s=0;s<e.length;s++){var h=e[s].dataCount,l=e[s].totalCount-h;o=Math.max(o,h),i=Math.max(i,l),n[s]=new Array(h);for(var u=0;u<n[s].length;u++)n[s][u]=255&t.buffer[u+r];r+=h;var g=QRUtil.getErrorCorrectPolynomial(l),d=new QRPolynomial(n[s],g.getLength()-1).mod(g);a[s]=new Array(g.getLength()-1);for(u=0;u<a[s].length;u++){var f=u+d.getLength()-a[s].length;a[s][u]=f>=0?d.get(f):0}}var c=0;for(u=0;u<e.length;u++)c+=e[u].totalCount;var R=new Array(c),p=0;for(u=0;u<o;u++)for(s=0;s<e.length;s++)u<n[s].length&&(R[p++]=n[s][u]);for(u=0;u<i;u++)for(s=0;s<e.length;s++)u<a[s].length&&(R[p++]=a[s][u]);return R};for(var QRMode={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},QRErrorCorrectLevel={L:1,M:0,Q:3,H:2},QRMaskPattern={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},QRUtil={PATTERN_POSITION_TABLE:[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(t){for(var e=t<<10;QRUtil.getBCHDigit(e)-QRUtil.getBCHDigit(QRUtil.G15)>=0;)e^=QRUtil.G15<<QRUtil.getBCHDigit(e)-QRUtil.getBCHDigit(QRUtil.G15);return(t<<10|e)^QRUtil.G15_MASK},getBCHTypeNumber:function(t){for(var e=t<<12;QRUtil.getBCHDigit(e)-QRUtil.getBCHDigit(QRUtil.G18)>=0;)e^=QRUtil.G18<<QRUtil.getBCHDigit(e)-QRUtil.getBCHDigit(QRUtil.G18);return t<<12|e},getBCHDigit:function(t){for(var e=0;0!=t;)e++,t>>>=1;return e},getPatternPosition:function(t){return QRUtil.PATTERN_POSITION_TABLE[t-1]},getMask:function(t,e,r){switch(t){case QRMaskPattern.PATTERN000:return(e+r)%2==0;case QRMaskPattern.PATTERN001:return e%2==0;case QRMaskPattern.PATTERN010:return r%3==0;case QRMaskPattern.PATTERN011:return(e+r)%3==0;case QRMaskPattern.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2==0;case QRMaskPattern.PATTERN101:return e*r%2+e*r%3==0;case QRMaskPattern.PATTERN110:return(e*r%2+e*r%3)%2==0;case QRMaskPattern.PATTERN111:return(e*r%3+(e+r)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}},getErrorCorrectPolynomial:function(t){for(var e=new QRPolynomial([1],0),r=0;r<t;r++)e=e.multiply(new QRPolynomial([1,QRMath.gexp(r)],0));return e},getLengthInBits:function(t,e){if(1<=e&&e<10)switch(t){case QRMode.MODE_NUMBER:return 10;case QRMode.MODE_ALPHA_NUM:return 9;case QRMode.MODE_8BIT_BYTE:case QRMode.MODE_KANJI:return 8;default:throw new Error("mode:"+t)}else if(e<27)switch(t){case QRMode.MODE_NUMBER:return 12;case QRMode.MODE_ALPHA_NUM:return 11;case QRMode.MODE_8BIT_BYTE:return 16;case QRMode.MODE_KANJI:return 10;default:throw new Error("mode:"+t)}else{if(!(e<41))throw new Error("type:"+e);switch(t){case QRMode.MODE_NUMBER:return 14;case QRMode.MODE_ALPHA_NUM:return 13;case QRMode.MODE_8BIT_BYTE:return 16;case QRMode.MODE_KANJI:return 12;default:throw new Error("mode:"+t)}}},getLostPoint:function(t){for(var e=t.getModuleCount(),r=0,o=0;o<e;o++)for(var i=0;i<e;i++){for(var n=0,a=t.isDark(o,i),s=-1;s<=1;s++)if(!(o+s<0||e<=o+s))for(var h=-1;h<=1;h++)i+h<0||e<=i+h||0==s&&0==h||a==t.isDark(o+s,i+h)&&n++;n>5&&(r+=3+n-5)}for(o=0;o<e-1;o++)for(i=0;i<e-1;i++){var l=0;t.isDark(o,i)&&l++,t.isDark(o+1,i)&&l++,t.isDark(o,i+1)&&l++,t.isDark(o+1,i+1)&&l++,0!=l&&4!=l||(r+=3)}for(o=0;o<e;o++)for(i=0;i<e-6;i++)t.isDark(o,i)&&!t.isDark(o,i+1)&&t.isDark(o,i+2)&&t.isDark(o,i+3)&&t.isDark(o,i+4)&&!t.isDark(o,i+5)&&t.isDark(o,i+6)&&(r+=40);for(i=0;i<e;i++)for(o=0;o<e-6;o++)t.isDark(o,i)&&!t.isDark(o+1,i)&&t.isDark(o+2,i)&&t.isDark(o+3,i)&&t.isDark(o+4,i)&&!t.isDark(o+5,i)&&t.isDark(o+6,i)&&(r+=40);var u=0;for(i=0;i<e;i++)for(o=0;o<e;o++)t.isDark(o,i)&&u++;return r+=10*(Math.abs(100*u/e/e-50)/5)}},QRMath={glog:function(t){if(t<1)throw new Error("glog("+t+")");return QRMath.LOG_TABLE[t]},gexp:function(t){for(;t<0;)t+=255;for(;t>=256;)t-=255;return QRMath.EXP_TABLE[t]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},i=0;i<8;i++)QRMath.EXP_TABLE[i]=1<<i;for(i=8;i<256;i++)QRMath.EXP_TABLE[i]=QRMath.EXP_TABLE[i-4]^QRMath.EXP_TABLE[i-5]^QRMath.EXP_TABLE[i-6]^QRMath.EXP_TABLE[i-8];for(i=0;i<255;i++)QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]]=i;function QRPolynomial(t,e){if(null==t.length)throw new Error(t.length+"/"+e);for(var r=0;r<t.length&&0==t[r];)r++;this.num=new Array(t.length-r+e);for(var o=0;o<t.length-r;o++)this.num[o]=t[o+r]}function QRRSBlock(t,e){this.totalCount=t,this.dataCount=e}function QRBitBuffer(){this.buffer=[],this.length=0}QRPolynomial.prototype={get:function(t){return this.num[t]},getLength:function(){return this.num.length},multiply:function(t){for(var e=new Array(this.getLength()+t.getLength()-1),r=0;r<this.getLength();r++)for(var o=0;o<t.getLength();o++)e[r+o]^=QRMath.gexp(QRMath.glog(this.get(r))+QRMath.glog(t.get(o)));return new QRPolynomial(e,0)},mod:function(t){if(this.getLength()-t.getLength()<0)return this;for(var e=QRMath.glog(this.get(0))-QRMath.glog(t.get(0)),r=new Array(this.getLength()),o=0;o<this.getLength();o++)r[o]=this.get(o);for(o=0;o<t.getLength();o++)r[o]^=QRMath.gexp(QRMath.glog(t.get(o))+e);return new QRPolynomial(r,0).mod(t)}},QRRSBlock.RS_BLOCK_TABLE=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],QRRSBlock.getRSBlocks=function(t,e){var r=QRRSBlock.getRsBlockTable(t,e);if(null==r)throw new Error("bad rs block @ typeNumber:"+t+"/errorCorrectLevel:"+e);for(var o=r.length/3,i=[],n=0;n<o;n++)for(var a=r[3*n+0],s=r[3*n+1],h=r[3*n+2],l=0;l<a;l++)i.push(new QRRSBlock(s,h));return i},QRRSBlock.getRsBlockTable=function(t,e){switch(e){case QRErrorCorrectLevel.L:return QRRSBlock.RS_BLOCK_TABLE[4*(t-1)+0];case QRErrorCorrectLevel.M:return QRRSBlock.RS_BLOCK_TABLE[4*(t-1)+1];case QRErrorCorrectLevel.Q:return QRRSBlock.RS_BLOCK_TABLE[4*(t-1)+2];case QRErrorCorrectLevel.H:return QRRSBlock.RS_BLOCK_TABLE[4*(t-1)+3];default:return}},QRBitBuffer.prototype={get:function(t){var e=Math.floor(t/8);return 1==(this.buffer[e]>>>7-t%8&1)},put:function(t,e){for(var r=0;r<e;r++)this.putBit(1==(t>>>e-r-1&1))},getLengthInBits:function(){return this.length},putBit:function(t){var e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}};var QRCodeLimitLength=[[17,14,11,7],[32,26,20,14],[53,42,32,24],[78,62,46,34],[106,84,60,44],[134,106,74,58],[154,122,86,64],[192,152,108,84],[230,180,130,98],[271,213,151,119],[321,251,177,137],[367,287,203,155],[425,331,241,177],[458,362,258,194],[520,412,292,220],[586,450,322,250],[644,504,364,280],[718,560,394,310],[792,624,442,338],[858,666,482,382],[929,711,509,403],[1003,779,565,439],[1091,857,611,461],[1171,911,661,511],[1273,997,715,535],[1367,1059,751,593],[1465,1125,805,625],[1528,1190,868,658],[1628,1264,908,698],[1732,1370,982,742],[1840,1452,1030,790],[1952,1538,1112,842],[2068,1628,1168,898],[2188,1722,1228,958],[2303,1809,1283,983],[2431,1911,1351,1051],[2563,1989,1423,1093],[2699,2099,1499,1139],[2809,2213,1579,1219],[2953,2331,1663,1273]];function QRCode(t){if(this.options={padding:4,width:256,height:256,typeNumber:4,color:"#000000",background:"#ffffff",ecl:"M"},"string"==typeof t&&(t={content:t}),t)for(var e in t)this.options[e]=t[e];if("string"!=typeof this.options.content)throw new Error("Expected 'content' as string!");if(0===this.options.content.length)throw new Error("Expected 'content' to be non-empty!");if(!(this.options.padding>=0))throw new Error("Expected 'padding' value to be non-negative!");if(!(this.options.width>0&&this.options.height>0))throw new Error("Expected 'width' or 'height' value to be higher than zero!");var r=this.options.content,o=function(t,e){for(var r=function(t){var e=encodeURI(t).toString().replace(/\%[0-9a-fA-F]{2}/g,"a");return e.length+(e.length!=t?3:0)}(t),o=1,i=0,n=0,a=QRCodeLimitLength.length;n<=a;n++){var s=QRCodeLimitLength[n];if(!s)throw new Error("Content too long: expected "+i+" but got "+r);switch(e){case"L":i=s[0];break;case"M":i=s[1];break;case"Q":i=s[2];break;case"H":i=s[3];break;default:throw new Error("Unknwon error correction level: "+e)}if(r<=i)break;o++}if(o>QRCodeLimitLength.length)throw new Error("Content too long");return o}(r,this.options.ecl),i=function(t){switch(t){case"L":return QRErrorCorrectLevel.L;case"M":return QRErrorCorrectLevel.M;case"Q":return QRErrorCorrectLevel.Q;case"H":return QRErrorCorrectLevel.H;default:throw new Error("Unknwon error correction level: "+t)}}(this.options.ecl);this.qrcode=new QRCodeModel(o,i),this.qrcode.addData(r),this.qrcode.make()}QRCode.prototype.svg=function(t){var e=this.options||{},r=this.qrcode.modules;void 0===t&&(t={container:e.container||"svg"});for(var o=void 0===e.pretty||!!e.pretty,i=o?" ":"",n=o?"\r\n":"",a=e.width,s=e.height,h=r.length,l=a/(h+2*e.padding),u=s/(h+2*e.padding),g="path-data"==t.container||void 0!==e.join&&!!e.join,d=void 0!==e.swap&&!!e.swap,f=void 0===e.xmlDeclaration||!!e.xmlDeclaration,c=void 0!==e.predefined&&!!e.predefined,R=c?i+'<defs><path id="qrmodule" d="M0 0 h'+u+" v"+l+' H0 z" style="fill:'+e.color+';shape-rendering:crispEdges;" /></defs>'+n:"",p=i+'<rect x="0" y="0" width="'+a+'" height="'+s+'" style="fill:'+e.background+';shape-rendering:crispEdges;"/>'+n,m="",Q="",v=0;v<h;v++)for(var E=0;E<h;E++){if(r[E][v]){var M=E*l+e.padding*l,B=v*u+e.padding*u;if(d){var C=M;M=B,B=C}if(g){var w=l+M,L=u+B;M=Number.isInteger(M)?Number(M):M.toFixed(2),B=Number.isInteger(B)?Number(B):B.toFixed(2),w=Number.isInteger(w)?Number(w):w.toFixed(2),Q+="M"+M+","+B+" V"+(L=Number.isInteger(L)?Number(L):L.toFixed(2))+" H"+w+" V"+B+" H"+M+" Z "}else m+=c?i+'<use x="'+M.toString()+'" y="'+B.toString()+'" href="#qrmodule" />'+n:i+'<rect x="'+M.toString()+'" y="'+B.toString()+'" width="'+l+'" height="'+u+'" style="fill:'+e.color+';shape-rendering:crispEdges;"/>'+n}}g&&(m=i+'<path x="0" y="0" style="fill:'+e.color+';shape-rendering:crispEdges;" d="'+Q+'" />');var T="";switch(t.container){case"svg":f&&(T+='<?xml version="1.0" standalone="yes"?>'+n),T+='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="'+a+'" height="'+s+'">'+n,T+=R+p+m,T+="</svg>";break;case"svg-viewbox":f&&(T+='<?xml version="1.0" standalone="yes"?>'+n),T+='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 '+a+" "+s+'">'+n,T+=R+p+m,T+="</svg>";break;case"g":T+='<g width="'+a+'" height="'+s+'">'+n,T+=R+p+m,T+="</g>";break;case"path-data":T=Q;break;default:T+=(R+p+m).replace(/^\s+/,"")}return T},QRCode.prototype.save=function(t,e){var r=this.svg();"function"!=typeof e&&(e=function(t,e){});try{require("fs").writeFile(t,r,e)}catch(t){e(t)}},"undefined"!=typeof module&&(module.exports=QRCode);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var QRCode = require('../lib/qrcode.js');
|
|
2
|
+
|
|
3
|
+
var hello = new QRCode("Hello World!");
|
|
4
|
+
var modules = hello.qrcode.modules;
|
|
5
|
+
|
|
6
|
+
var ascii = '';
|
|
7
|
+
var length = modules.length;
|
|
8
|
+
for (var y = 0; y < length; y++) {
|
|
9
|
+
for (var x = 0; x < length; x++) {
|
|
10
|
+
var module = modules[x][y];
|
|
11
|
+
ascii += (module ? 'x' : ' ');
|
|
12
|
+
}
|
|
13
|
+
ascii += '\r\n';
|
|
14
|
+
}
|
|
15
|
+
console.log(ascii);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
xxxxxxx xx x x xxxxxxx
|
|
2
|
+
x x xxxx x x x x
|
|
3
|
+
x xxx x xx xx x x xxx x
|
|
4
|
+
x xxx x xx x xxx x
|
|
5
|
+
x xxx x x x x x xxx x
|
|
6
|
+
x x x xx xx x x
|
|
7
|
+
xxxxxxx x x x x x xxxxxxx
|
|
8
|
+
xx xx
|
|
9
|
+
x x xx x x xx x x
|
|
10
|
+
x x xx x xx x xx x
|
|
11
|
+
x x xx x x x xx xx
|
|
12
|
+
x xx xxx xx x x x x x
|
|
13
|
+
xx xxxx xxxx x
|
|
14
|
+
x x x xx x xx xx x xx xx
|
|
15
|
+
x xx xxxx xxxx
|
|
16
|
+
xx xx x x x x xx x
|
|
17
|
+
xxxx xxxx xxxxxx x
|
|
18
|
+
x x x
|
|
19
|
+
xxxxxxx x xxx x x x x
|
|
20
|
+
x x xxx x xx x x
|
|
21
|
+
x xxx x xxxxxxxxxx
|
|
22
|
+
x xxx x xxxxxxxxx x xx
|
|
23
|
+
x xxx x xxx xx x x x
|
|
24
|
+
x x x x x
|
|
25
|
+
xxxxxxx xxx xxx x x x
|
|
26
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var QRCode = require('../lib/qrcode.js');
|
|
2
|
+
|
|
3
|
+
var htmlpdf;
|
|
4
|
+
try {
|
|
5
|
+
htmlpdf = require('html-pdf');
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
console.error("Please run: npm install html-pdf");
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//Generate PNG image
|
|
13
|
+
var svg = new QRCode("Hello from PNG!").svg();
|
|
14
|
+
htmlpdf.create(svg, { border: 0, type: 'png' }).toFile('convert.png', function(err, res) {
|
|
15
|
+
if (err) throw err;
|
|
16
|
+
console.log(res);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
//Generate PDF document
|
|
20
|
+
var svg = new QRCode("Hello from PDF!").svg();
|
|
21
|
+
htmlpdf.create(svg, { border: 0, type: 'pdf' }).toFile('convert.pdf', function(err, res) {
|
|
22
|
+
if (err) throw err;
|
|
23
|
+
console.log(res);
|
|
24
|
+
});
|
|
25
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<body>
|
|
4
|
+
<div id="container"></div>
|
|
5
|
+
<script src="../lib/qrcode.js"></script>
|
|
6
|
+
<script>
|
|
7
|
+
var qrcode = new QRCode({ content: "Hello World!", join: true });
|
|
8
|
+
var svg = qrcode.svg();
|
|
9
|
+
document.getElementById("container").innerHTML = svg;
|
|
10
|
+
</script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
xxxxxxx x xxx xxxxxxx
|
|
2
|
+
x x xxx x x x
|
|
3
|
+
x xxx x x xx x xxx x
|
|
4
|
+
x xxx x x x xx x xxx x
|
|
5
|
+
x xxx x xx xx x xxx x
|
|
6
|
+
x x xx xxx x x x
|
|
7
|
+
xxxxxxx x x x x x xxxxxxx
|
|
8
|
+
xxxx
|
|
9
|
+
x x xx x xxx xx x x x
|
|
10
|
+
xxx xx x x x x xx xx x
|
|
11
|
+
x x xx x x xx x
|
|
12
|
+
x xxxx xxx x x
|
|
13
|
+
xx xx x xx x x x
|
|
14
|
+
x xx x x xx xx xx x
|
|
15
|
+
xx x x x x x xx x
|
|
16
|
+
x x x x x xxx
|
|
17
|
+
xxx xxxx x xxx xxxxxxx x
|
|
18
|
+
xx x x xxx
|
|
19
|
+
xxxxxxx x x xxxxx x x x
|
|
20
|
+
x x xxxx xxx x
|
|
21
|
+
x xxx x xx xxxxxx
|
|
22
|
+
x xxx x x xx x x
|
|
23
|
+
x xxx x xx x x xxxxx
|
|
24
|
+
x x x x xxx
|
|
25
|
+
xxxxxxx xxxxxx xx x x x x
|
|
26
|
+
|
|
Binary file
|
|
Binary file
|