Compare commits

..

No commits in common. 'master' and 'v0.1' have entirely different histories.
master ... v0.1

@ -1,24 +0,0 @@
# editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[{*.json,*.yml}]
indent_size = 2
[{*.md,*.jade}]
trim_trailing_whitespace = false
[*.svg]
insert_final_newline = false

@ -1,4 +0,0 @@
/build/
/coverage/
/dist/
/node_modules/

@ -1,182 +0,0 @@
---
root: true
env:
es6: true
node: true
parserOptions:
ecmaVersion: 2020
rules:
array-bracket-spacing: [2, never]
arrow-parens: [2, as-needed]
arrow-spacing: 2
block-scoped-var: 2
brace-style: [2, 1tbs, {allowSingleLine: true}]
camelcase: 0
comma-dangle: [2, never]
comma-spacing: [2, {before: false, after: true}]
comma-style: [2, last]
complexity: [1, 16] ###
computed-property-spacing: [2, never]
consistent-return: 2
consistent-this: [2, self]
constructor-super: 2
curly: [2, multi-line]
default-case: 2
dot-location: [2, property]
dot-notation: [2, {allowKeywords: true}]
eol-last: 2
eqeqeq: 2
func-names: 2
func-style: [2, declaration, {allowArrowFunctions: true}]
generator-star-spacing: [2, after]
guard-for-in: 2
handle-callback-err: 2
indent: [2, 4]
key-spacing: [2, {beforeColon: false, afterColon: true}]
keyword-spacing: [2, {before: true, after: true}]
linebreak-style: [2, unix]
max-depth: [1, 4]
max-len: [0, 80, 4]
max-nested-callbacks: [1, 3]
max-params: [1, 16] ###
max-statements: [1, 32] ###
new-cap: 0
new-parens: 2
newline-after-var: 0
no-alert: 2
no-array-constructor: 2
no-bitwise: 2
no-caller: 2
no-catch-shadow: 2
no-class-assign: 2
no-cond-assign: 2
no-console: 0 ###
no-const-assign: 2
no-constant-condition: 1
no-continue: 0
no-control-regex: 2
no-debugger: 2
no-delete-var: 2
no-div-regex: 2
no-dupe-args: 2
no-dupe-class-members: 2
no-dupe-keys: 2
no-duplicate-case: 2
no-else-return: 1
no-empty: 2
no-empty-character-class: 2
no-empty-pattern: 2
no-eq-null: 2
no-eval: 2
no-ex-assign: 2
no-extend-native: 1
no-extra-bind: 2
no-extra-boolean-cast: 2
no-extra-parens: 1
no-extra-semi: 2
no-fallthrough: 2
no-floating-decimal: 2
no-func-assign: 2
no-implicit-coercion: [2, {boolean: false, number: true, string: true}]
no-implied-eval: 2
no-inline-comments: 0
no-inner-declarations: [2, functions]
no-invalid-regexp: 2
no-invalid-this: 2
no-irregular-whitespace: 2
no-iterator: 2
no-label-var: 2
no-labels: 2
no-lone-blocks: 2
no-lonely-if: 2
no-loop-func: 1
no-magic-numbers: 0
no-mixed-requires: [2, false]
no-mixed-spaces-and-tabs: [2, false]
no-multi-spaces: 2
no-multi-str: 2
no-multiple-empty-lines: [2, {max: 4}]
no-native-reassign: 1
no-negated-in-lhs: 2
no-nested-ternary: 0
no-new: 2
no-new-func: 2
no-new-object: 2
no-new-require: 2
no-new-wrappers: 2
no-obj-calls: 2
no-octal: 2
no-octal-escape: 2
no-param-reassign: 0
no-path-concat: 2
no-plusplus: 2
no-process-env: 2
no-process-exit: 2
no-proto: 2
no-redeclare: 2
no-regex-spaces: 2
no-restricted-modules: 2
no-return-assign: 2
no-script-url: 2
no-self-compare: 2
no-sequences: 2
no-shadow: 2
no-shadow-restricted-names: 2
no-spaced-func: 2
no-sparse-arrays: 2
no-sync: 0
no-ternary: 0
no-this-before-super: 2
no-throw-literal: 1
no-trailing-spaces: 2
no-undef: 2
no-undef-init: 2
no-undefined: 0
no-underscore-dangle: 0
no-unexpected-multiline: 2
no-unneeded-ternary: 2
no-unreachable: 2
no-useless-call: 2
no-useless-concat: 2
no-unused-expressions: 2
no-unused-vars: [1, {vars: all, args: after-used}]
no-use-before-define: 2
no-var: 2
no-void: 2
no-warning-comments: [1, {terms: [todo, fixme, xxx], location: start}]
no-with: 2
object-curly-spacing: [2, never]
object-shorthand: [2, always]
one-var: [2, never]
operator-assignment: [2, always]
operator-linebreak: [2, after]
padded-blocks: [2, never]
prefer-arrow-callback: 2
prefer-const: 1
prefer-reflect: 1
prefer-spread: 2
prefer-template: 0 ###
quote-props: [2, as-needed]
quotes: [2, single, avoid-escape]
radix: 2
require-yield: 2
semi: 2
semi-spacing: [2, {before: false, after: true}]
sort-vars: 0
space-before-blocks: [2, always]
space-before-function-paren: [2, {anonymous: always, named: never}]
space-in-parens: [2, never]
space-infix-ops: 2
space-unary-ops: [2, {words: true, nonwords: false}]
spaced-comment: [2, always]
strict: [2, never]
use-isnan: 2
valid-jsdoc: 2
valid-typeof: 2
vars-on-top: 0
wrap-iife: [2, outside]
wrap-regex: 2
yoda: [2, never, {exceptRange: true}]

28
.gitignore vendored

@ -1,5 +1,23 @@
/build/
/coverage/
/local/
/node_modules/
/npm-debug.log
# Build files and folders to ignore
build
release
# Local
local.makefile
build.local.xml
*.sublime-*
.ant-targets*
# Numerous always-ignore extensions
*.ant-targets-build.xml
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
*.sass-cache

@ -0,0 +1,19 @@
Copyright (c) 2012 Lars Jung, http://larsjung.de
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.

@ -1,42 +1,14 @@
# jQuery.qrcode
[![license][license-img]][github] [![web][web-img]][web] [![github][github-img]][github]
* Website with download, docs and demo: <http://larsjung.de/qrcode>
* Sources: <http://github.com/lrsjng/jQuery.qrcode>
jQuery plugin to dynamically generate QR codes. Uses [QR Code Generator][qrcode] (MIT).
There is a newer lib named [kjua][kjua] that works in all modern browsers
with crisp codes on all devices.
jQuery.qrcode is provided under the terms of the [MIT License](http://github.com/lrsjng/jQuery.qrcode/blob/master/LICENSE.txt).
Uses [QR Code Generator](http://www.d-project.com/qrcode/index.html) (MIT). Kudos to [jquery.qrcode.js](http://github.com/jeromeetienne/jquery-qrcode) (MIT).
## License
The MIT License (MIT)
## Changelog
Copyright (c) 2020 Lars Jung (https://larsjung.de)
### v0.1 - *2012-07-01*
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.
[web]: https://larsjung.de/qrcode/
[github]: https://github.com/lrsjng/jquery-qrcode
[license-img]: https://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square
[web-img]: https://img.shields.io/badge/web-larsjung.de/jquery--qrcode-a0a060.svg?style=flat-square
[github-img]: https://img.shields.io/badge/github-lrsjng/jquery--qrcode-a0a060.svg?style=flat-square
[qrcode]: https://github.com/kazuhikoarase/qrcode-generator
[kjua]: https://larsjung.de/kjua/
* Initial release

@ -0,0 +1,16 @@
# project
project.name = jquery.qrcode
project.version = 0.1
# src
src.dir = src
# build
build.dir = build
release.dir = release
# tools
tool.wepp = wepp
tool.docco = docco
tool.jshint = jshint

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<project
name="jQuery.qrcode"
basedir="."
default="release"
>
<target name="init">
<property file="build.properties" />
<tstamp><format property="build.stamp" pattern="yyyy-MM-dd-HHmmss" /></tstamp>
<property name="build.label" value="${project.name} ${project.version} b${build.stamp}" />
<echo>Build: ${build.label}</echo>
</target>
<target name="clean" depends="init">
<delete dir="${build.dir}" />
<delete dir="${release.dir}" />
</target>
<target name="build" depends="clean">
<mkdir dir="${build.dir}" />
<copy todir="${build.dir}">
<fileset dir="${src.dir}" />
<fileset file="LICENSE.txt" />
<fileset file="README.md" />
</copy>
<replace dir="${build.dir}">
<replacefilter token="%BUILD%" value="${build.label}" />
<replacefilter token="%BUILD_NAME%" value="${project.name}" />
<replacefilter token="%BUILD_VERSION%" value="${project.version}" />
<replacefilter token="%BUILD_STAMP%" value="${build.stamp}" />
</replace>
<!-- qrcode -->
<wepp file="${build.dir}/jquery.qrcode.js" tofile="${build.dir}/jquery.qrcode-${project.version}.js" />
<wepp-min file="${build.dir}/jquery.qrcode.js" tofile="${build.dir}/jquery.qrcode-${project.version}.min.js" />
<delete file="${build.dir}/qrcode.js" />
<delete file="${build.dir}/jquery.qrcode.js" />
<!-- docs -->
<docco dir="${build.dir}" files="jquery.qrcode-${project.version}.js" />
</target>
<target name="release" depends="build">
<mkdir dir="${release.dir}" />
<zip destfile="${release.dir}/${project.name}-${project.version}.zip" basedir="${build.dir}" />
</target>
<target name="jshint" depends="init">
<exec executable="${tool.jshint}">
<arg line="${src.dir}/jquery.qrcode.js" />
<arg line="--config jshint.json" />
<arg line="--show-non-errors" />
</exec>
</target>
<macrodef name="wepp-args">
<attribute name="args" default="" />
<sequential>
<exec executable="${tool.wepp}" failonerror="true">
<arg line="@{args}" />
</exec>
</sequential>
</macrodef>
<macrodef name="wepp">
<attribute name="file" />
<attribute name="tofile" />
<sequential>
<wepp-args args="--nc --inFile '@{file}' --outFile '@{toFile}'" />
</sequential>
</macrodef>
<macrodef name="wepp-min">
<attribute name="file" />
<attribute name="tofile" />
<sequential>
<wepp-args args="--zs --inFile '@{file}' --outFile '@{toFile}'" />
</sequential>
</macrodef>
<macrodef name="wepp-dir">
<attribute name="dir" />
<attribute name="todir" />
<sequential>
<wepp-args args="--nc --inDir '@{dir}' --outDir '@{todir}'" />
<delete dir="@{todir}/inc" >
<fileset dir="." includes="@{todir}/**/*.less" />
</delete>
</sequential>
</macrodef>
<macrodef name="wepp-dir-min">
<attribute name="dir" />
<attribute name="todir" />
<sequential>
<wepp-args args="--inDir '@{dir}' --outDir '@{todir}'" />
<delete dir="@{todir}/inc" >
<fileset dir="." includes="@{todir}/**/*.less" />
</delete>
</sequential>
</macrodef>
<macrodef name="docco">
<attribute name="dir" />
<attribute name="files" />
<sequential>
<exec executable="${tool.docco}" dir="@{dir}" failonerror="true">
<arg line="@{files}" />
</exec>
</sequential>
</macrodef>
</project>

2817
dist/jquery-qrcode.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -1,66 +0,0 @@
const {resolve, join} = require('path');
const {ghu, pug, jszip, mapfn, read, remove, webpack, uglify, wrap, write} = require('ghu');
const overwrite = arg => write(arg, {overwrite: true});
const NAME = 'jquery-qrcode';
const ROOT = resolve(__dirname);
const SRC = join(ROOT, 'src');
const BUILD = join(ROOT, 'build');
const DIST = join(ROOT, 'dist');
ghu.defaults('release');
ghu.before(runtime => {
runtime.pkg = Object.assign({}, require('./package.json'));
runtime.comment = `${runtime.pkg.name} v${runtime.pkg.version} - ${runtime.pkg.homepage}`;
runtime.commentJs = `/*! ${runtime.comment} */\n`;
console.log(runtime.comment);
});
ghu.task('clean', () => {
return remove(`${BUILD}, ${DIST}`);
});
ghu.task('build:scripts', runtime => {
return read(`${SRC}/${NAME}.js`)
.then(webpack(webpack.cfg_umd(NAME, [SRC])))
.then(wrap(runtime.commentJs))
.then(overwrite(`${DIST}/${NAME}.js`))
.then(overwrite(`${BUILD}/${NAME}-${runtime.pkg.version}.js`))
.then(uglify())
.then(wrap(runtime.commentJs))
.then(overwrite(`${DIST}/${NAME}.min.js`))
.then(overwrite(`${BUILD}/${NAME}-${runtime.pkg.version}.min.js`));
});
ghu.task('build:other', runtime => {
return Promise.all([
read(`${ROOT}/*.md`)
.then(overwrite(mapfn.p(ROOT, BUILD))),
read(`${SRC}/demo/*.pug`)
.then(pug({pkg: runtime.pkg}))
.then(overwrite(mapfn.p(SRC, BUILD).s('.pug', ''))),
read(`${SRC}/demo/*.js`)
.then(webpack(webpack.cfg([SRC])))
.then(uglify())
.then(wrap(runtime.commentJs))
.then(overwrite(mapfn.p(SRC, BUILD))),
read(`${SRC}/demo/*, !**/*.pug, !**/*.js`)
.then(overwrite(mapfn.p(SRC, BUILD))),
read(`${ROOT}/node_modules/jquery/dist/jquery.min.js`)
.then(overwrite(`${BUILD}/demo/jquery.min.js`))
]);
});
ghu.task('build', ['build:scripts', 'build:other']);
ghu.task('zip', ['build'], runtime => {
return read(`${BUILD}/**/*`)
.then(jszip({dir: BUILD, level: 9}))
.then(overwrite(`${BUILD}/${NAME}-${runtime.pkg.version}.zip`));
});
ghu.task('release', ['clean', 'zip']);

@ -0,0 +1,21 @@
{
// Enforcing Options
"bitwise": true,
"curly": true,
"eqeqeq": true,
"forin": true,
"latedef": true,
"newcap": true,
"noempty": true,
"plusplus": true,
"trailing": true,
"undef": true,
// Environments
"browser": true,
// Globals
"predef": [
"jQuery", "qrcode"
]
}

5805
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,26 +0,0 @@
{
"name": "jquery-qrcode",
"title": "jQuery.qrcode",
"version": "0.18.0",
"description": "Generate QR codes dynamically.",
"homepage": "https://larsjung.de/jquery-qrcode/",
"author": "Lars Jung <lrsjng@gmail.com> (https://larsjung.de)",
"license": "MIT",
"scripts": {
"lint": "eslint .",
"build": "node ghu release",
"precommit": "npm run -s lint && npm run -s build"
},
"repository": {
"type": "git",
"url": "https://github.com/lrsjng/jquery-qrcode.git"
},
"devDependencies": {
"@babel/core": "7.10.5",
"@babel/preset-env": "7.10.4",
"eslint": "7.5.0",
"ghu": "0.26.0",
"jquery": "3.5.1",
"qrcode-generator": "1.4.4"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

@ -1,80 +0,0 @@
doctype html
html(lang='en')
head
meta(charset='utf-8')
title #{pkg.title} #{pkg.version} Demo
meta(name='description', content=`Demo for ${pkg.title} (${pkg.homepage}).`)
meta(name='viewport', content='width=device-width, initial-scale=1')
link(href='styles.css', rel='stylesheet')
link(href='//fonts.googleapis.com/css2?family=Ubuntu+Mono:wght@400;700&display=swap' rel='stylesheet')
script(src='jquery.min.js')
script(src=`../jquery-qrcode-${pkg.version}.js`)
script(src='scripts.js')
body
div#container
div.control.left
a#banner(href=pkg.homepage) #{pkg.title} #{pkg.version}
hr
label(for='render') RENDER MODE
select#render
option(value='canvas', selected='selected') canvas
option(value='image') image
option(value='div') div
hr
label(for='size') SIZE:
input#size(type='range', value='400', min='100', max='1000', step='50')
label(for='fill') FILL
input#fill(type='color', value='#333333')
label(for='background') BACKGROUND
input#background(type='color', value='#ffffff')
label(for='text') CONTENT
textarea#text #{pkg.homepage}
hr
label(for='minversion') MIN VERSION:
input#minversion(type='range', value='6', min='1', max='10', step='1')
label(for='eclevel') ERROR CORRECTION LEVEL
select#eclevel
option(value='L') L - Low (7%)
option(value='M') M - Medium (15%)
option(value='Q') Q - Quartile (25%)
option(value='H', selected='selected') H - High (30%)
label(for='quiet') QUIET ZONE:
input#quiet(type='range', value='1', min='0', max='4', step='1')
label(for='radius') CORNER RADIUS:
input#radius(type='range', value='50', min='0', max='50', step='10')
div.control.right
label(for='mode') MODE
select#mode
option(value='0') 0 - Normal
option(value='1') 1 - Label-Strip
option(value='2', selected='selected') 2 - Label-Box
option(value='3') 3 - Image-Strip
option(value='4') 4 - Image-Box
hr
label(for='msize') SIZE:
input#msize(type='range', value='11', min='0', max='40', step='1')
label(for='mposx') POS X:
input#mposx(type='range', value='50', min='0', max='100', step='1')
label(for='mposy') POS Y:
input#mposy(type='range', value='50', min='0', max='100', step='1')
hr
label(for='label') LABEL
input#label(type='text', value=pkg.title)
label(for='font') FONT NAME
input#font(type='text', value='Ubuntu Mono')
label(for='fontcolor') FONT COLOR
input#fontcolor(type='color', value='#ff9818')
hr
label(for='image') IMAGE
input#image(type='file')
img#img-buffer(src='dummy.png')

@ -1,81 +0,0 @@
const WIN = global.window;
const JQ = WIN.jQuery;
const GUI_VALUE_PAIRS = [
['size', 'px'],
['minversion', ''],
['quiet', ' modules'],
['radius', '%'],
['msize', '%'],
['mposx', '%'],
['mposy', '%']
];
const update_gui = () => {
JQ.each(GUI_VALUE_PAIRS, (idx, pair) => {
const $label = JQ('label[for="' + pair[0] + '"]');
$label.text($label.text().replace(/:.*/, ': ' + JQ('#' + pair[0]).val() + pair[1]));
});
};
const update_qrcode = () => {
const options = {
render: JQ('#render').val(),
ecLevel: JQ('#eclevel').val(),
minVersion: parseInt(JQ('#minversion').val(), 10),
fill: JQ('#fill').val(),
background: JQ('#background').val(),
text: JQ('#text').val(),
size: parseInt(JQ('#size').val(), 10),
radius: parseInt(JQ('#radius').val(), 10) * 0.01,
quiet: parseInt(JQ('#quiet').val(), 10),
mode: parseInt(JQ('#mode').val(), 10),
mSize: parseInt(JQ('#msize').val(), 10) * 0.01,
mPosX: parseInt(JQ('#mposx').val(), 10) * 0.01,
mPosY: parseInt(JQ('#mposy').val(), 10) * 0.01,
label: JQ('#label').val(),
fontname: JQ('#font').val(),
fontcolor: JQ('#fontcolor').val(),
image: JQ('#img-buffer')[0]
};
// options.fill = JQ('#img-buffer')[0];
// options.fill = 'rgba(255,0,0,0.5)';
// options.background = JQ('#img-buffer')[0];
// options.background = 'rgba(255,0,0,0.5)';
JQ('#container').empty().qrcode(options);
};
const update = () => {
update_gui();
update_qrcode();
};
const on_img_input = () => {
const input = JQ('#image')[0];
if (input.files && input.files[0]) {
const reader = new WIN.FileReader();
reader.onload = event => {
JQ('#img-buffer').attr('src', event.target.result);
JQ('#mode').val('4');
setTimeout(update, 250);
};
reader.readAsDataURL(input.files[0]);
}
};
const init = () => {
JQ('#image').on('change', on_img_input);
JQ('input, textarea, select').on('input change', update);
JQ(WIN).on('load', update);
update();
};
JQ(init);

@ -1,108 +0,0 @@
* {
margin: 0;
padding: 0;
}
body {
font-family: 'Ubuntu Mono', 'monospace';
text-align: center;
background: repeat url('back.png');
}
#banner {
display: block;
text-decoration: none;
color: rgb(29, 119, 194);
padding: 12px 0 0;
text-align: center;
}
#banner:hover {
color: #333;
}
#container {
display: inline-block;
margin: 20px auto;
box-shadow: 0 0 16px rgba(0,0,0,0.5);
-webkit-print-color-adjust: exact;
}
#container > * {
display: block;
}
.control {
position: absolute;
background-color: #f8f8f8;
top: 0;
width: 190px;
box-shadow: 0 0 32px rgba(0,0,0,0.5);
overflow: hidden;
text-align: left;
}
.control.left {
left: 0;
}
.control.right {
right: 0;
}
hr {
margin: 12px 0 0;
padding: 0;
border: none;
height: 1px;
background-color: rgba(0,0,0,0.1);
}
label {
display: block;
font-size: 12px;
color: #555;
padding: 12px 4px 4px 4px;
}
input, textarea, select {
font-family: 'Ubuntu Mono', 'monospace';
display: block;
background-color: #fff;
margin: 2px;
padding: 0 2px;
border: 1px solid #ddd;
width: 180px;
height: 22px;
}
#text {
height: 48px;
}
#img-buffer {
display: none;
}
input[type='range'] {
-webkit-appearance: none;
cursor: pointer;
}
input::-webkit-slider-thumb {
-webkit-appearance: none;
width: 16px;
height: 16px;
border-radius: 3px;
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #aaa), color-stop(1, #aaa));
}
@media print {
#container {
box-shadow: none;
}
.control {
display: none;
}
}

415
src/jquery-qrcode.js vendored

@ -1,415 +0,0 @@
const WIN = window; // eslint-disable-line
const JQ = WIN.jQuery;
const is_img_el = x => x && typeof x.tagName === 'string' && x.tagName.toUpperCase() === 'IMG';
// Wrapper for the original QR code generator.
const create_qrcode = (text, level, version, quiet) => {
const qr = {};
const qr_gen = require('qrcode-generator');
qr_gen.stringToBytes = qr_gen.stringToBytesFuncs['UTF-8'];
const vqr = qr_gen(version, level);
vqr.addData(text);
vqr.make();
quiet = quiet || 0;
const module_count = vqr.getModuleCount();
const quiet_module_count = module_count + 2 * quiet;
const is_dark = (row, col) => {
row -= quiet;
col -= quiet;
return row >= 0 && row < module_count && col >= 0 && col < module_count && vqr.isDark(row, col);
};
const add_blank = (l, t, r, b) => {
const prev_is_dark = qr.is_dark;
const module_size = 1 / quiet_module_count;
qr.is_dark = (row, col) => {
const ml = col * module_size;
const mt = row * module_size;
const mr = ml + module_size;
const mb = mt + module_size;
return prev_is_dark(row, col) && (l > mr || ml > r || t > mb || mt > b);
};
};
qr.text = text;
qr.level = level;
qr.version = version;
qr.module_count = quiet_module_count;
qr.is_dark = is_dark;
qr.add_blank = add_blank;
return qr;
};
// Returns a minimal QR code for the given text starting with version `min_ver`.
// Returns `undefined` if `text` is too long to be encoded in `max_ver`.
const create_min_qrcode = (text, level, min_ver, max_ver, quiet) => {
min_ver = Math.max(1, min_ver || 1);
max_ver = Math.min(40, max_ver || 40);
for (let ver = min_ver; ver <= max_ver; ver += 1) {
try {
return create_qrcode(text, level, ver, quiet);
} catch (err) {/* empty */}
}
return undefined;
};
const draw_background_label = (qr, ctx, settings) => {
const size = settings.size;
const font = 'bold ' + settings.mSize * size + 'px ' + settings.fontname;
const tmp_ctx = JQ('<canvas/>')[0].getContext('2d');
tmp_ctx.font = font;
const w = tmp_ctx.measureText(settings.label).width;
const sh = settings.mSize;
const sw = w / size;
const sl = (1 - sw) * settings.mPosX;
const st = (1 - sh) * settings.mPosY;
const sr = sl + sw;
const sb = st + sh;
const pad = 0.01;
if (settings.mode === 1) {
// Strip
qr.add_blank(0, st - pad, size, sb + pad);
} else {
// Box
qr.add_blank(sl - pad, st - pad, sr + pad, sb + pad);
}
ctx.fillStyle = settings.fontcolor;
ctx.font = font;
ctx.fillText(settings.label, sl * size, st * size + 0.75 * settings.mSize * size);
};
const draw_background_img = (qr, ctx, settings) => {
const size = settings.size;
const w = settings.image.naturalWidth || 1;
const h = settings.image.naturalHeight || 1;
const sh = settings.mSize;
const sw = sh * w / h;
const sl = (1 - sw) * settings.mPosX;
const st = (1 - sh) * settings.mPosY;
const sr = sl + sw;
const sb = st + sh;
const pad = 0.01;
if (settings.mode === 3) {
// Strip
qr.add_blank(0, st - pad, size, sb + pad);
} else {
// Box
qr.add_blank(sl - pad, st - pad, sr + pad, sb + pad);
}
ctx.drawImage(settings.image, sl * size, st * size, sw * size, sh * size);
};
const draw_background = (qr, ctx, settings) => {
if (is_img_el(settings.background)) {
ctx.drawImage(settings.background, 0, 0, settings.size, settings.size);
} else if (settings.background) {
ctx.fillStyle = settings.background;
ctx.fillRect(settings.left, settings.top, settings.size, settings.size);
}
const mode = settings.mode;
if (mode === 1 || mode === 2) {
draw_background_label(qr, ctx, settings);
} else if (is_img_el(settings.image) && (mode === 3 || mode === 4)) {
draw_background_img(qr, ctx, settings);
}
};
const draw_modules_default = (qr, ctx, settings, left, top, width, row, col) => {
if (qr.is_dark(row, col)) {
ctx.r(left, top, width, width);
}
};
const draw_modules_rounded_dark = (ctx, l, t, r, b, rad, nw, ne, se, sw) => {
if (nw) {
ctx.m(l + rad, t);
} else {
ctx.m(l, t);
}
if (ne) {
ctx.l(r - rad, t).a(r, t, r, b, rad);
} else {
ctx.l(r, t);
}
if (se) {
ctx.l(r, b - rad).a(r, b, l, b, rad);
} else {
ctx.l(r, b);
}
if (sw) {
ctx.l(l + rad, b).a(l, b, l, t, rad);
} else {
ctx.l(l, b);
}
if (nw) {
ctx.l(l, t + rad).a(l, t, r, t, rad);
} else {
ctx.l(l, t);
}
};
const draw_modules_rounded_light = (ctx, l, t, r, b, rad, nw, ne, se, sw) => {
if (nw) {
ctx.m(l + rad, t).l(l, t).l(l, t + rad).a(l, t, l + rad, t, rad);
}
if (ne) {
ctx.m(r - rad, t).l(r, t).l(r, t + rad).a(r, t, r - rad, t, rad);
}
if (se) {
ctx.m(r - rad, b).l(r, b).l(r, b - rad).a(r, b, r - rad, b, rad);
}
if (sw) {
ctx.m(l + rad, b).l(l, b).l(l, b - rad).a(l, b, l + rad, b, rad);
}
};
const draw_modules_rounded = (qr, ctx, settings, left, top, width, row, col) => {
const right = left + width;
const bottom = top + width;
const rad = settings.radius * width;
const row_n = row - 1;
const row_s = row + 1;
const col_w = col - 1;
const col_e = col + 1;
const is_dark = qr.is_dark;
const d_center = is_dark(row, col);
const d_nw = is_dark(row_n, col_w);
const d_n = is_dark(row_n, col);
const d_ne = is_dark(row_n, col_e);
const d_e = is_dark(row, col_e);
const d_se = is_dark(row_s, col_e);
const d_s = is_dark(row_s, col);
const d_sw = is_dark(row_s, col_w);
const d_w = is_dark(row, col_w);
if (d_center) {
draw_modules_rounded_dark(ctx, left, top, right, bottom, rad, !d_n && !d_w, !d_n && !d_e, !d_s && !d_e, !d_s && !d_w);
} else {
draw_modules_rounded_light(ctx, left, top, right, bottom, rad, d_n && d_w && d_nw, d_n && d_e && d_ne, d_s && d_e && d_se, d_s && d_w && d_sw);
}
};
const draw_modules = (qr, ctx, settings) => {
const module_count = qr.module_count;
const module_size = settings.size / module_count;
let fn = draw_modules_default;
if (settings.radius > 0 && settings.radius <= 0.5) {
fn = draw_modules_rounded;
}
const draw_ctx = {
m(x, y) {ctx.moveTo(x, y); return draw_ctx;},
l(x, y) {ctx.lineTo(x, y); return draw_ctx;},
a(...args) {ctx.arcTo(...args); return draw_ctx;},
r(...args) {ctx.rect(...args); return draw_ctx;}
};
ctx.beginPath();
for (let row = 0; row < module_count; row += 1) {
for (let col = 0; col < module_count; col += 1) {
const l = settings.left + col * module_size;
const t = settings.top + row * module_size;
const w = module_size;
fn(qr, draw_ctx, settings, l, t, w, row, col);
}
}
if (is_img_el(settings.fill)) {
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.lineWidth = 2;
ctx.stroke();
const prev = ctx.globalCompositeOperation;
ctx.globalCompositeOperation = 'destination-out';
ctx.fill();
ctx.globalCompositeOperation = prev;
ctx.clip();
ctx.drawImage(settings.fill, 0, 0, settings.size, settings.size);
ctx.restore();
} else {
ctx.fillStyle = settings.fill;
ctx.fill();
}
};
// Draws QR code to the given `canvas` and returns it.
const draw_on_canvas = (canvas, settings) => {
const qr = create_min_qrcode(settings.text, settings.ecLevel, settings.minVersion, settings.maxVersion, settings.quiet);
if (!qr) {
return null;
}
const $canvas = JQ(canvas).data('qrcode', qr);
const ctx = $canvas[0].getContext('2d');
draw_background(qr, ctx, settings);
draw_modules(qr, ctx, settings);
return $canvas;
};
// Returns a `canvas` element representing the QR code for the given settings.
const create_canvas = settings => {
const $canvas = JQ('<canvas/>').attr('width', settings.size).attr('height', settings.size);
return draw_on_canvas($canvas, settings);
};
// Returns an `image` element representing the QR code for the given settings.
const create_img = settings => {
return JQ('<img/>').attr('src', create_canvas(settings)[0].toDataURL('image/png'));
};
// Returns a `div` element representing the QR code for the given settings.
const create_div = settings => {
const qr = create_min_qrcode(settings.text, settings.ecLevel, settings.minVersion, settings.maxVersion, settings.quiet);
if (!qr) {
return null;
}
// some shortcuts to improve compression
const settings_size = settings.size;
const settings_bgColor = settings.background;
const math_floor = Math.floor;
const module_count = qr.module_count;
const module_size = math_floor(settings_size / module_count);
const offset = math_floor(0.5 * (settings_size - module_size * module_count));
const container_css = {
position: 'relative',
left: 0,
top: 0,
padding: 0,
margin: 0,
width: settings_size,
height: settings_size
};
const dark_css = {
position: 'absolute',
padding: 0,
margin: 0,
width: module_size,
height: module_size,
'background-color': settings.fill
};
const $div = JQ('<div/>').data('qrcode', qr).css(container_css);
if (settings_bgColor) {
$div.css('background-color', settings_bgColor);
}
for (let row = 0; row < module_count; row += 1) {
for (let col = 0; col < module_count; col += 1) {
if (qr.is_dark(row, col)) {
JQ('<div/>')
.css(dark_css)
.css({
left: offset + col * module_size,
top: offset + row * module_size
})
.appendTo($div);
}
}
}
return $div;
};
const create_html = settings => {
if (settings.render === 'canvas') {
return create_canvas(settings);
} else if (settings.render === 'image') {
return create_img(settings);
}
return create_div(settings);
};
const DEFAULTS = {
// render method: `'canvas'`, `'image'` or `'div'`
render: 'canvas',
// version range somewhere in 1 .. 40
minVersion: 1,
maxVersion: 40,
// error correction level: `'L'`, `'M'`, `'Q'` or `'H'`
ecLevel: 'L',
// offset in pixel if drawn onto existing canvas
left: 0,
top: 0,
// size in pixel
size: 200,
// code color or image element
fill: '#000',
// background color or image element, `null` for transparent background
background: '#fff',
// content
text: 'no text',
// corner radius relative to module width: 0.0 .. 0.5
radius: 0,
// quiet zone in modules
quiet: 0,
// modes
// 0: normal
// 1: label strip
// 2: label box
// 3: image strip
// 4: image box
mode: 0,
mSize: 0.1,
mPosX: 0.5,
mPosY: 0.5,
label: 'no label',
fontname: 'sans',
fontcolor: '#000',
image: null
};
JQ.fn.qrcode = module.exports = function main(options) {
const settings = JQ.extend({}, DEFAULTS, options);
return this.each((idx, el) => {
if (el.nodeName.toLowerCase() === 'canvas') {
draw_on_canvas(el, settings);
} else {
JQ(el).append(create_html(settings));
}
});
};

@ -0,0 +1,162 @@
/*! jQuery.qrcode %BUILD_VERSION% - //larsjung.de/qrcode - MIT License */
// Uses [QR Code Generator](http://www.d-project.com/qrcode/index.html) (MIT), appended to the end of this file.
// Kudos to [jquery.qrcode.js](http://github.com/jeromeetienne/jquery-qrcode) (MIT).
(function ($) {
'use strict';
// Wrapper for the original QR code generator.
var createQr = function (typeNumber, correctLevel, text) {
// qrcode is the single public function that will be defined by the `QR Code Generator`
// at the end of the file.
var qr = qrcode(typeNumber, correctLevel);
qr.addData(text);
qr.make();
return qr;
},
// Returns a minimal QR code for the given text. Returns `null` if `text`
// is to long to be encoded. At the moment it should work with up to 271 characters.
createBestQr = function (text) {
for (var type = 2; type <= 10; type += 1) {
try {
return createQr(type, 'L', text);
} catch (err) {}
}
return null;
},
// Returns a `canvas` element representing the QR code for the given settings.
createCanvas = function (settings) {
var qr = createBestQr(settings.text),
$canvas = $('<canvas/>').attr('width', settings.width).attr('height', settings.height),
ctx = $canvas[0].getContext('2d');
if (settings.bgColor) {
ctx.fillStyle = settings.bgColor;
ctx.fillRect(0, 0, settings.width, settings.height);
}
if (qr) {
var moduleCount = qr.getModuleCount(),
moduleWidth = settings.width / moduleCount,
moduleHeight = settings.height / moduleCount,
row, col;
ctx.beginPath();
for (row = 0; row < moduleCount; row += 1) {
for (col = 0; col < moduleCount; col += 1) {
if (qr.isDark(row, col)) {
ctx.rect(col * moduleWidth, row * moduleHeight, moduleWidth, moduleHeight);
}
}
}
ctx.fillStyle = settings.color;
ctx.fill();
}
return $canvas;
},
// Returns a `div` element representing the QR code for the given settings.
createDiv = function (settings) {
var qr = createBestQr(settings.text),
$div = $('<div/>').css({
position: 'relative',
left: 0,
top: 0,
padding: 0,
margin: 0,
width: settings.width,
height: settings.height
});
if (settings.bgColor) {
$div.css('background-color', settings.bgColor);
}
if (qr) {
var moduleCount = qr.getModuleCount(),
moduleWidth = Math.floor(settings.width / moduleCount),
moduleHeight = Math.floor(settings.height / moduleCount),
offsetLeft = Math.floor(0.5 * (settings.width - moduleWidth * moduleCount)),
offsetTop = Math.floor(0.5 * (settings.height - moduleHeight * moduleCount)),
row, col;
for (row = 0; row < moduleCount; row += 1) {
for (col = 0; col < moduleCount; col += 1) {
if (qr.isDark(row, col)) {
$('<div/>')
.css({
left: offsetLeft + col * moduleWidth,
top: offsetTop + row * moduleHeight
})
.appendTo($div);
}
}
}
$div.children()
.css({
position: 'absolute',
padding: 0,
margin: 0,
width: moduleWidth,
height: moduleHeight,
'background-color': settings.color
});
}
return $div;
},
// Plugin
// ======
// Default settings
// ----------------
defaults = {
// render method: `'canvas'` or `'div'`
render: 'canvas',
// width and height in pixel
width: 256,
height: 256,
// code color
color: '#000',
// background color, `null` for transparent background
bgColor: null,
// the encoded text
text: 'no text'
};
// Register the plugin
// -------------------
$.fn.qrcode = function(options) {
var settings = $.extend({}, defaults, options);
return this.each(function () {
$(this).append(settings.render === 'canvas' ? createCanvas(settings) : createDiv(settings));
});
};
// jQuery.qrcode plug in code ends here
// QR Code Generator
// =================
// @include "qrcode.js"
}(jQuery));

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save