From b3fd09dbb4e56f8caf5a1f584eb1bbc04060a8e1 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 25 Jul 2020 20:13:47 +0200 Subject: [PATCH] Update. --- dist/kjua.min.js | 4 ++-- package-lock.json | 2 +- package.json | 2 +- src/demo/index.html.pug | 9 ++++----- src/demo/styles.css | 11 ++++++----- src/kjua.js | 10 +++++++++- src/lib/create_canvas_qrcode.js | 8 ++++---- src/lib/create_svg_qrcode.js | 10 +++++----- src/lib/dom.js | 8 +++++--- 9 files changed, 37 insertions(+), 27 deletions(-) diff --git a/dist/kjua.min.js b/dist/kjua.min.js index 1fabeee..bd1f484 100644 --- a/dist/kjua.min.js +++ b/dist/kjua.min.js @@ -1,2 +1,2 @@ -/*! kjua v0.8.0 - https://larsjung.de/kjua/ */ -!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("kjua",[],r):"object"==typeof exports?exports.kjua=r():t.kjua=r()}("undefined"!=typeof self?self:this,function(){return n={},o.m=e=[function(t,r,e){var n=e(1),o=e(2),i=e(4),a=e(8);t.exports=function(t){var r=Object.assign({},n,t),e=o(r.text,r.ecLevel,r.minVersion,r.quiet);return"svg"===r.render?a(e,r):i(e,r,"image"===r.render)}},function(t,r){t.exports={render:"image",crisp:!0,minVersion:1,ecLevel:"L",size:200,ratio:null,fill:"#333",back:"#fff",text:"no text",rounded:0,quiet:0,mode:"plain",mSize:30,mPosX:50,mPosY:50,label:"no label",fontname:"sans",fontcolor:"#333",image:null}},function(t,r,e){function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var f=/code length overflow/i,l=e(3);l.stringToBytes=l.stringToBytesFuncs["UTF-8"];t.exports=function(t,r,e,n){var o,i=3>e&1);c[Math.floor(e/3)][e%3+s-8-3]=n}for(e=0;e<18;e+=1){n=!t&&1==(r>>e&1);c[e%3+s-8-3][Math.floor(e/3)]=n}},d=function(t,r){for(var e=f<<3|r,n=m.getBCHTypeInfo(e),o=0;o<15;o+=1){var i=!t&&1==(n>>o&1);o<6?c[o][8]=i:o<8?c[o+1][8]=i:c[s-15+o][8]=i}for(o=0;o<15;o+=1){i=!t&&1==(n>>o&1);o<8?c[8][s-o-1]=i:o<9?c[8][15-o-1+1]=i:c[8][15-o-1]=i}c[s-8][8]=!t},v=function(t,r){for(var e=-1,n=s-1,o=7,i=0,a=m.getMaskFunction(r),u=s-1;0>>o&1)),a(n,u-l)&&(f=!f),c[n][u-l]=f,-1==--o&&(i+=1,o=7))}if((n+=e)<0||s<=n){n-=e,e=-e;break}}},p=function(t,r,e){for(var n=S.getRSBlocks(t,r),o=M(),i=0;i8*u)throw"code length overflow. ("+o.getLengthInBits()+">"+8*u+")";for(o.getLengthInBits()+4<=8*u&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(!1);for(;!(o.getLengthInBits()>=8*u||(o.put(236,8),o.getLengthInBits()>=8*u));)o.put(17,8);return function(t,r){for(var e=0,n=0,o=0,i=new Array(r.length),a=new Array(r.length),u=0;u',e+="";for(var n=0;n";for(var o=0;o';e+=""}return e+="",e+=""},h.createSvgTag=function(t,r,e,n){var o={};"object"==typeof arguments[0]&&(t=(o=arguments[0]).cellSize,r=o.margin,e=o.alt,n=o.title),t=t||2,r=void 0===r?4*t:r,(e="string"==typeof e?{text:e}:e||{}).text=e.text||null,e.id=e.text?e.id||"qrcode-description":null,(n="string"==typeof n?{text:n}:n||{}).text=n.text||null,n.id=n.text?n.id||"qrcode-title":null;var i,a,u,f=h.getModuleCount()*t+2*r,l="",c="l"+t+",0 0,"+t+" -"+t+",0 0,-"+t+"z ";for(l+=''+w(n.text)+"":"",l+=e.text?''+w(e.text)+"":"",l+='',l+='":r+=">";break;case"&":r+="&";break;case'"':r+=""";break;default:r+=n}}return r};return h.createASCII=function(t,r){if((t=t||1)<2)return function(t){t=void 0===t?2:t;for(var r,e,n,o,i=+h.getModuleCount()+2*t,a=t,u=i-t,f={"██":"█","█ ":"▀"," █":"▄"," ":" "},l={"██":"▀","█ ":"▀"," █":" "," ":" "},c="",s=0;s>>8),r.push(255&n)):r.push(a)}return r}};var r,t,a=1,u=2,o=4,f=8,y={L:1,M:0,Q:3,H:2},e=0,n=1,l=2,c=3,s=4,g=5,h=6,d=7,m=(r=[[],[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]],(t={}).getBCHTypeInfo=function(t){for(var r=t<<10;0<=v(r)-v(1335);)r^=1335<>>=1;return r}var p=function(){for(var r=new Array(256),e=new Array(256),t=0;t<8;t+=1)r[t]=1<>>8)},writeBytes:function(t,r,e){r=r||0,e=e||t.length;for(var n=0;n>>o-6),o-=6},t.flush=function(){if(0>>r!=0)throw"length over";for(;8<=u+r;)a.writeByte(255&(t<>>=8-u,u=f=0;f|=t<>>7-t%8&1)},put:function(t,r){for(var e=0;e>>r-e-1&1))},getLengthInBits:function(){return n},putBit:function(t){var r=Math.floor(n/8);e.length<=r&&e.push(0),t&&(e[r]|=128>>>n%8),n+=1}};return o},A=function(t){var r=a,n=t,e={getMode:function(){return r},getLength:function(t){return n.length},write:function(t){for(var r=n,e=0;e+2>>8&255)+(255&n),t.put(n,13),e+=2}if(e=e.length){if(0==i)return-1;throw"unexpected end of file./"+i}var t=e.charAt(n);if(n+=1,"="==t)return i=0,-1;t.match(/^\s$/)||(o=o<<6|a(t.charCodeAt(0)),i+=6)}var r=o>>>i-8&255;return i-=8,r}},a=function(t){if(65<=t&&t<=90)return t-65;if(97<=t&&t<=122)return t-97+26;if(48<=t&&t<=57)return t-48+52;if(43==t)return 62;if(47==t)return 63;throw"c:"+t};return r},P=function(t,r,e){for(var n=k(t,r),o=0;o>6,128|63&n):n<55296||57344<=n?r.push(224|n>>12,128|n>>6&63,128|63&n):(e++,n=65536+((1023&n)<<10|1023&t.charCodeAt(e)),r.push(240|n>>18,128|n>>12&63,128|n>>6&63,128|63&n))}return r}(t)},o=[],void 0===(i="function"==typeof(n=function(){return a})?n.apply(r,o):n)||(t.exports=i)},function(t,r,e){function l(t,r,e,n,o,i){t.is_dark(o,i)&&r.rect(i*n,o*n,n,n)}function a(t,r,e){var n,o;n=r,(o=e).back&&(n.fillStyle=o.back,n.fillRect(0,0,o.size,o.size)),function(t,r,e){if(t){var n=0>e&1);l[Math.floor(e/3)][e%3+s-8-3]=n}for(e=0;e<18;e+=1){n=!t&&1==(r>>e&1);l[e%3+s-8-3][Math.floor(e/3)]=n}},d=function(t,r){for(var e=f<<3|r,n=m.getBCHTypeInfo(e),o=0;o<15;o+=1){var i=!t&&1==(n>>o&1);o<6?l[o][8]=i:o<8?l[o+1][8]=i:l[s-15+o][8]=i}for(o=0;o<15;o+=1){i=!t&&1==(n>>o&1);o<8?l[8][s-o-1]=i:o<9?l[8][15-o-1+1]=i:l[8][15-o-1]=i}l[s-8][8]=!t},v=function(t,r){for(var e=-1,n=s-1,o=7,i=0,a=m.getMaskFunction(r),u=s-1;0>>o&1)),a(n,u-c)&&(f=!f),l[n][u-c]=f,-1==--o&&(i+=1,o=7))}if((n+=e)<0||s<=n){n-=e,e=-e;break}}},p=function(t,r,e){for(var n=S.getRSBlocks(t,r),o=M(),i=0;i8*u)throw"code length overflow. ("+o.getLengthInBits()+">"+8*u+")";for(o.getLengthInBits()+4<=8*u&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(!1);for(;!(o.getLengthInBits()>=8*u||(o.put(236,8),o.getLengthInBits()>=8*u));)o.put(17,8);return function(t,r){for(var e=0,n=0,o=0,i=new Array(r.length),a=new Array(r.length),u=0;u',e+="";for(var n=0;n";for(var o=0;o';e+=""}return e+="",e+=""},h.createSvgTag=function(t,r,e,n){var o={};"object"==typeof arguments[0]&&(t=(o=arguments[0]).cellSize,r=o.margin,e=o.alt,n=o.title),t=t||2,r=void 0===r?4*t:r,(e="string"==typeof e?{text:e}:e||{}).text=e.text||null,e.id=e.text?e.id||"qrcode-description":null,(n="string"==typeof n?{text:n}:n||{}).text=n.text||null,n.id=n.text?n.id||"qrcode-title":null;var i,a,u,f=h.getModuleCount()*t+2*r,c="",l="l"+t+",0 0,"+t+" -"+t+",0 0,-"+t+"z ";for(c+=''+y(n.text)+"":"",c+=e.text?''+y(e.text)+"":"",c+='',c+='":r+=">";break;case"&":r+="&";break;case'"':r+=""";break;default:r+=n}}return r};return h.createASCII=function(t,r){if((t=t||1)<2)return function(t){t=void 0===t?2:t;for(var r,e,n,o,i=+h.getModuleCount()+2*t,a=t,u=i-t,f={"██":"█","█ ":"▀"," █":"▄"," ":" "},c={"██":"▀","█ ":"▀"," █":" "," ":" "},l="",s=0;s>>8),r.push(255&n)):r.push(a)}return r}};var r,t,a=1,u=2,o=4,f=8,w={L:1,M:0,Q:3,H:2},e=0,n=1,c=2,l=3,s=4,g=5,h=6,d=7,m=(r=[[],[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]],(t={}).getBCHTypeInfo=function(t){for(var r=t<<10;0<=v(r)-v(1335);)r^=1335<>>=1;return r}var p=function(){for(var r=new Array(256),e=new Array(256),t=0;t<8;t+=1)r[t]=1<>>8)},writeBytes:function(t,r,e){r=r||0,e=e||t.length;for(var n=0;n>>o-6),o-=6},t.flush=function(){if(0>>r!=0)throw"length over";for(;8<=u+r;)a.writeByte(255&(t<>>=8-u,u=f=0;f|=t<>>7-t%8&1)},put:function(t,r){for(var e=0;e>>r-e-1&1))},getLengthInBits:function(){return n},putBit:function(t){var r=Math.floor(n/8);e.length<=r&&e.push(0),t&&(e[r]|=128>>>n%8),n+=1}};return o},A=function(t){var r=a,n=t,e={getMode:function(){return r},getLength:function(t){return n.length},write:function(t){for(var r=n,e=0;e+2>>8&255)+(255&n),t.put(n,13),e+=2}if(e=e.length){if(0==i)return-1;throw"unexpected end of file./"+i}var t=e.charAt(n);if(n+=1,"="==t)return i=0,-1;t.match(/^\s$/)||(o=o<<6|a(t.charCodeAt(0)),i+=6)}var r=o>>>i-8&255;return i-=8,r}},a=function(t){if(65<=t&&t<=90)return t-65;if(97<=t&&t<=122)return t-97+26;if(48<=t&&t<=57)return t-48+52;if(43==t)return 62;if(47==t)return 63;throw"c:"+t};return r},P=function(t,r,e){for(var n=k(t,r),o=0;o>6,128|63&n):n<55296||57344<=n?r.push(224|n>>12,128|n>>6&63,128|63&n):(e++,n=65536+((1023&n)<<10|1023&t.charCodeAt(e)),r.push(240|n>>18,128|n>>12&63,128|n>>6&63,128|63&n))}return r}(t)},o=[],void 0===(i="function"==typeof(n=function(){return a})?n.apply(r,o):n)||(t.exports=i)},function(t,r,e){function c(t,r,e,n,o,i){t.is_dark(o,i)&&r.rect(i*n,o*n,n,n)}function a(t,r,e){var n,o;n=r,(o=e).back&&(n.fillStyle=o.back,n.fillRect(0,0,o.size,o.size)),function(t,r,e){if(t){var n=0 (https://larsjung.de)", diff --git a/src/demo/index.html.pug b/src/demo/index.html.pug index 082343c..a508fb4 100644 --- a/src/demo/index.html.pug +++ b/src/demo/index.html.pug @@ -2,11 +2,10 @@ doctype html html(lang='en') head meta(charset='utf-8') - meta(http-equiv='x-ua-compatible', content='ie=edge') title #{pkg.name} #{pkg.version} · Demo meta(name='description', content=`demo for ${pkg.name} (${pkg.homepage})`) meta(name='viewport', content='width=device-width, initial-scale=1') - link(href='//fonts.googleapis.com/css?family=Ubuntu', rel='stylesheet') + link(href='//fonts.googleapis.com/css2?family=Ubuntu+Mono:wght@400;700&display=swap' rel='stylesheet') link(href='styles.css', rel='stylesheet') script(src=`../${pkg.name}-${pkg.version}.min.js`) script(src='scripts.js') @@ -35,7 +34,7 @@ html(lang='en') input#fill(type='color', value='#333333') label(for='back') BACK input#back(type='color', value='#ffffff') - label(for='text') CONTENT + label(for='text') TEXT textarea#text #{pkg.homepage} hr @@ -61,7 +60,7 @@ html(lang='en') hr label(for='msize') SIZE: - input#msize(type='range', value='30', min='0', max='40', step='1') + input#msize(type='range', value='20', 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: @@ -71,7 +70,7 @@ html(lang='en') label(for='label') LABEL input#label(type='text', value=pkg.name) label(for='font') FONT NAME - input#font(type='text', value='Ubuntu') + input#font(type='text', value='Ubuntu Mono') label(for='fontcolor') FONT COLOR input#fontcolor(type='color', value='#ff9818') diff --git a/src/demo/styles.css b/src/demo/styles.css index 71c742f..150fe4d 100644 --- a/src/demo/styles.css +++ b/src/demo/styles.css @@ -4,7 +4,7 @@ } body { - font-family: 'Ubuntu', 'Arial', 'sans'; + font-family: 'Ubuntu Mono', 'monospace'; text-align: center; background: repeat url('back.png'); } @@ -59,13 +59,14 @@ hr { } label { - font-size: 10px; - color: #aaa; - padding: 12px 4px 0 4px; + display: block; + font-size: 12px; + color: #555; + padding: 12px 4px 4px 4px; } input, textarea, select { - font-family: 'Ubuntu', 'Arial', 'sans'; + font-family: 'Ubuntu Mono', 'monospace'; display: block; background-color: #fff; margin: 2px; diff --git a/src/kjua.js b/src/kjua.js index cb1c3ed..06acc83 100644 --- a/src/kjua.js +++ b/src/kjua.js @@ -3,7 +3,7 @@ const qrcode = require('./lib/qrcode'); const create_canvas_qrcode = require('./lib/create_canvas_qrcode'); const create_svg_qrcode = require('./lib/create_svg_qrcode'); -module.exports = options => { +const kjua = options => { const settings = Object.assign({}, defaults, options); const qr = qrcode(settings.text, settings.ecLevel, settings.minVersion, settings.quiet); @@ -12,3 +12,11 @@ module.exports = options => { } return create_canvas_qrcode(qr, settings, settings.render === 'image'); }; + +module.exports = kjua; + +/* eslint-disable */ try { + jQuery.fn.kjua = function (options) { + return this.each((idx, el) => el.appendChild(kjua(options))); + }; +} catch (e) {} /* eslint-enable */ diff --git a/src/lib/create_canvas_qrcode.js b/src/lib/create_canvas_qrcode.js index d92866a..5ccc170 100644 --- a/src/lib/create_canvas_qrcode.js +++ b/src/lib/create_canvas_qrcode.js @@ -1,4 +1,4 @@ -const {create_canvas, canvas_to_img, dpr} = require('./dom'); +const dom = require('./dom'); const draw_module_rounded = require('./draw_rounded'); const draw_mode = require('./draw_mode'); @@ -49,13 +49,13 @@ const draw = (qr, ctx, settings) => { }; const create_canvas_qrcode = (qr, settings, as_image) => { - const ratio = settings.ratio || dpr; - const canvas = create_canvas(settings.size, ratio); + const ratio = settings.ratio || dom.dpr; + const canvas = dom.create_canvas(settings.size, ratio); const context = canvas.getContext('2d'); context.scale(ratio, ratio); draw(qr, context, settings); - return as_image ? canvas_to_img(canvas) : canvas; + return as_image ? dom.canvas_to_img(canvas) : canvas; }; module.exports = create_canvas_qrcode; diff --git a/src/lib/create_svg_qrcode.js b/src/lib/create_svg_qrcode.js index 6563215..7a1d7ab 100644 --- a/src/lib/create_svg_qrcode.js +++ b/src/lib/create_svg_qrcode.js @@ -1,4 +1,4 @@ -const {create_svg_el, get_attr} = require('./dom'); +const {SVG_NS, get_attr, create_svg_el} = require('./dom'); const create_draw_ctx = ctx => { const rnd = x => Math.round(x * 10) / 10; @@ -116,9 +116,9 @@ const add_label = (el, settings) => { const size = settings.size; const font = 'bold ' + settings.mSize * 0.01 * size + 'px ' + settings.fontname; - const {create_canvas, dpr} = require('./dom'); - const ratio = settings.ratio || dpr; - const ctx = create_canvas(size, ratio).getContext('2d'); + const dom = require('./dom'); + const ratio = settings.ratio || dom.dpr; + const ctx = dom.create_canvas(size, ratio).getContext('2d'); ctx.strokeStyle = settings.back; ctx.lineWidth = settings.mSize * 0.01 * size * 0.1; ctx.fillStyle = settings.fontcolor; @@ -176,7 +176,7 @@ const create_svg_qrcode = (qr, settings) => { const mode = settings.mode; const svg_el = create_svg_el('svg', { - xmlns: 'http://www.w3.org/2000/svg', + xmlns: SVG_NS, width: size, height: size, viewBox: `0 0 ${size} ${size}` diff --git a/src/lib/dom.js b/src/lib/dom.js index 5d6bd5e..d53f82f 100644 --- a/src/lib/dom.js +++ b/src/lib/dom.js @@ -38,9 +38,11 @@ const canvas_to_img = canvas => { }; module.exports = { - create_svg_el, + dpr, + SVG_NS, get_attr, + create_el, + create_svg_el, create_canvas, - canvas_to_img, - dpr + canvas_to_img };