diff --git a/qrcode.js b/qrcode.js index 5507c15..2bf574e 100644 --- a/qrcode.js +++ b/qrcode.js @@ -8,7 +8,7 @@ * @see http://www.d-project.com/ * @see http://jeromeetienne.github.com/jquery-qrcode/ */ -var QRCode; +let QRCode; (function () { //--------------------------------------------------------------------- @@ -32,9 +32,9 @@ var QRCode; this.parsedData = []; // Added to support UTF-8 Characters - for (var i = 0, l = this.data.length; i < l; i++) { - var byteArray = []; - var code = this.data.charCodeAt(i); + for (let i = 0, l = this.data.length; i < l; i++) { + let byteArray = []; + let code = this.data.charCodeAt(i); if (code > 0x10000) { byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18); @@ -69,7 +69,7 @@ var QRCode; return this.parsedData.length; }, write: function (buffer) { - for (var i = 0, l = this.parsedData.length; i < l; i++) { + for (let i = 0, l = this.parsedData.length; i < l; i++) { buffer.put(this.parsedData[i], 8); } } @@ -114,9 +114,9 @@ var QRCode; buffer.put(QRCodeModel.PAD1,8);} return QRCodeModel.createBytes(buffer,rsBlocks);};QRCodeModel.createBytes=function(buffer,rsBlocks){var offset=0;var maxDcCount=0;var maxEcCount=0;var dcdata=new Array(rsBlocks.length);var ecdata=new Array(rsBlocks.length);for(var r=0;r=0)?modPoly.get(modIndex):0;}} - var totalCodeCount=0;for(var i=0;i=0){d^=(QRUtil.G15<<(QRUtil.getBCHDigit(d)-QRUtil.getBCHDigit(QRUtil.G15)));} return((data<<10)|d)^QRUtil.G15_MASK;},getBCHTypeNumber:function(data){var d=data<<12;while(QRUtil.getBCHDigit(d)-QRUtil.getBCHDigit(QRUtil.G18)>=0){d^=(QRUtil.G18<<(QRUtil.getBCHDigit(d)-QRUtil.getBCHDigit(QRUtil.G18)));} return(data<<12)|d;},getBCHDigit:function(data){var digit=0;while(data!=0){digit++;data>>>=1;} @@ -126,30 +126,30 @@ var QRCode; if(r==0&&c==0){continue;} if(dark==qrCode.isDark(row+r,col+c)){sameCount++;}}} if(sameCount>5){lostPoint+=(3+sameCount-5);}}} - for(var row=0;row=256){n-=255;} return QRMath.EXP_TABLE[n];},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)};for(var i=0;i<8;i++){QRMath.EXP_TABLE[i]=1<>>(7-index%8))&1)==1;},put:function(num,length){for(var i=0;i>>(length-i-1))&1)==1);}},getLengthInBits:function(){return this.length;},putBit:function(bit){var bufIndex=Math.floor(this.length/8);if(this.buffer.length<=bufIndex){this.buffer.push(0);} + QRBitBuffer.prototype={get:function(index){let bufIndex=Math.floor(index/8);return((this.buffer[bufIndex]>>>(7-index%8))&1)==1;},put:function(num,length){for(var i=0;i>>(length-i-1))&1)==1);}},getLengthInBits:function(){return this.length;},putBit:function(bit){var bufIndex=Math.floor(this.length/8);if(this.buffer.length<=bufIndex){this.buffer.push(0);} if(bit){this.buffer[bufIndex]|=(0x80>>>(this.length%8));} - this.length++;}};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]]; + this.length++;}};let 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 _isSupportCanvas() { return typeof CanvasRenderingContext2D != "undefined"; @@ -157,12 +157,12 @@ var QRCode; // android 2.x doesn't support Data-URI spec function _getAndroid() { - var android = false; - var sAgent = navigator.userAgent; + let android = false; + let sAgent = navigator.userAgent; if (/android/i.test(sAgent)) { // android android = true; - var aMat = sAgent.toString().match(/android ([0-9]\.[0-9])/i); + let aMat = sAgent.toString().match(/android ([0-9]\.[0-9])/i); if (aMat && aMat[1]) { android = parseFloat(aMat[1]); @@ -172,40 +172,40 @@ var QRCode; return android; } - var svgDrawer = (function() { + let svgDrawer = (function() { - var Drawing = function (el, htOption) { + let Drawing = function (el, htOption) { this._el = el; this._htOption = htOption; }; Drawing.prototype.draw = function (oQRCode) { - var _htOption = this._htOption; - var _el = this._el; - var nCount = oQRCode.getModuleCount(); - var nWidth = Math.floor(_htOption.width / nCount); - var nHeight = Math.floor(_htOption.height / nCount); + let _htOption = this._htOption; + let _el = this._el; + let nCount = oQRCode.getModuleCount(); + let nWidth = Math.floor(_htOption.width / nCount); + let nHeight = Math.floor(_htOption.height / nCount); this.clear(); function makeSVG(tag, attrs) { - var el = document.createElementNS('http://www.w3.org/2000/svg', tag); - for (var k in attrs) + let el = document.createElementNS('http://www.w3.org/2000/svg', tag); + for (let k in attrs) if (attrs.hasOwnProperty(k)) el.setAttribute(k, attrs[k]); return el; } - var svg = makeSVG("svg" , {'viewBox': '0 0 ' + String(nCount) + " " + String(nCount), 'width': '100%', 'height': '100%', 'fill': _htOption.colorLight}); + let svg = makeSVG("svg" , {'viewBox': '0 0 ' + String(nCount) + " " + String(nCount), 'width': '100%', 'height': '100%', 'fill': _htOption.colorLight}); svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink"); _el.appendChild(svg); svg.appendChild(makeSVG("rect", {"fill": _htOption.colorLight, "width": "100%", "height": "100%"})); svg.appendChild(makeSVG("rect", {"fill": _htOption.colorDark, "width": "1", "height": "1", "id": "template"})); - for (var row = 0; row < nCount; row++) { - for (var col = 0; col < nCount; col++) { + for (let row = 0; row < nCount; row++) { + for (let col = 0; col < nCount; col++) { if (oQRCode.isDark(row, col)) { - var child = makeSVG("use", {"x": String(col), "y": String(row)}); + let child = makeSVG("use", {"x": String(col), "y": String(row)}); child.setAttributeNS("http://www.w3.org/1999/xlink", "href", "#template") svg.appendChild(child); } @@ -219,11 +219,11 @@ var QRCode; return Drawing; })(); - var useSVG = document.documentElement.tagName.toLowerCase() === "svg"; + let useSVG = document.documentElement.tagName.toLowerCase() === "svg"; // Drawing in DOM by using Table tag - var Drawing = useSVG ? svgDrawer : !_isSupportCanvas() ? (function () { - var Drawing = function (el, htOption) { + let Drawing = useSVG ? svgDrawer : !_isSupportCanvas() ? (function () { + let Drawing = function (el, htOption) { this._el = el; this._htOption = htOption; }; @@ -234,17 +234,17 @@ var QRCode; * @param {QRCode} oQRCode */ Drawing.prototype.draw = function (oQRCode) { - var _htOption = this._htOption; - var _el = this._el; - var nCount = oQRCode.getModuleCount(); - var nWidth = Math.floor(_htOption.width / nCount); - var nHeight = Math.floor(_htOption.height / nCount); - var aHTML = ['']; + let _htOption = this._htOption; + let _el = this._el; + let nCount = oQRCode.getModuleCount(); + let nWidth = Math.floor(_htOption.width / nCount); + let nHeight = Math.floor(_htOption.height / nCount); + let aHTML = ['
']; - for (var row = 0; row < nCount; row++) { + for (let row = 0; row < nCount; row++) { aHTML.push(''); - for (var col = 0; col < nCount; col++) { + for (let col = 0; col < nCount; col++) { aHTML.push(''); } @@ -255,9 +255,9 @@ var QRCode; _el.innerHTML = aHTML.join(''); // Fix the margin values as real size. - var elTable = _el.childNodes[0]; - var nLeftMarginTable = (_htOption.width - elTable.offsetWidth) / 2; - var nTopMarginTable = (_htOption.height - elTable.offsetHeight) / 2; + let elTable = _el.childNodes[0]; + let nLeftMarginTable = (_htOption.width - elTable.offsetWidth) / 2; + let nTopMarginTable = (_htOption.height - elTable.offsetHeight) / 2; if (nLeftMarginTable > 0 && nTopMarginTable > 0) { elTable.style.margin = nTopMarginTable + "px " + nLeftMarginTable + "px"; @@ -282,8 +282,8 @@ var QRCode; // Android 2.1 bug workaround // http://code.google.com/p/android/issues/detail?id=5141 if (this._android && this._android <= 2.1) { - var factor = 1 / window.devicePixelRatio; - var drawImage = CanvasRenderingContext2D.prototype.drawImage; + let factor = 1 / window.devicePixelRatio; + let drawImage = CanvasRenderingContext2D.prototype.drawImage; CanvasRenderingContext2D.prototype.drawImage = function (image, sx, sy, sw, sh, dx, dy, dw, dh) { if (("nodeName" in image) && /img/i.test(image.nodeName)) { for (var i = arguments.length - 1; i >= 1; i--) {