/* * QRious v4.0.2 * Copyright (C) 2017 Alasdair Mercer * Copyright (C) 2010 Tom Zerucha * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * * Copyright (C) 2017 Alasdair Mercer, !ninja * * 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. */ !function($,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):$.QRious=e()}(this,function(){"use strict";var $=function(){},e=Object.prototype.hasOwnProperty,t=Array.prototype.slice;function x($,x,i){i=t.call(arguments,2);for(var s,n,_=0,a=i.length;_>1&1,x=0;x0;e--)x[e]=x[e]?x[e-1]^f.EXPONENT[h._modN(f.LOG[x[e]]+$)]:x[e-1];x[0]=f.EXPONENT[h._modN(f.LOG[x[0]]+$)]}for($=0;$<=t;$++)x[$]=f.LOG[x[$]]},_checkBadness:function(){var $,e,t,x,i,s=0,n=this._badness,_=this.buffer,a=this.width;for(i=0;ia*a;)f-=a*a,o++;for(s+=o*h.N4,x=0;x=n-2&&($=n-2,i>9&&$--);var _=$;if(i>9){for(s[_+2]=0,s[_+3]=0;_--;)e=s[_],s[_+3]|=255&e<<4,s[_+2]=e>>4;s[2]|=255&$<<4,s[1]=$>>4,s[0]=64|$>>12}else{for(s[_+1]=0,s[_+2]=0;_--;)e=s[_],s[_+2]|=255&e<<4,s[_+1]=e>>4;s[1]|=255&$<<4,s[0]=64|$>>4}for(_=$+3-(i<10);_=5&&(t+=h.N1+x[e]-5);for(e=3;e<$-1;e+=2)x[e-2]===x[e+2]&&x[e+2]===x[e-1]&&x[e-1]===x[e+1]&&3*x[e-1]===x[e]&&(0===x[e-3]||e+3>$||3*x[e-3]>=4*x[e]||3*x[e+3]>=4*x[e])&&(t+=h.N3);return t},_finish:function(){this._stringBuffer=this.buffer.slice();var $,e,t=0,x=3e4;for(e=0;e<8&&(this._applyMask(e),($=this._checkBadness())>=1)1&x&&(i[s-1-e+8*s]=1,e<6?i[8+s*e]=1:i[8+s*(e+1)]=1);for(e=0;e<7;e++,x>>=1)1&x&&(i[8+s*(s-7+e)]=1,e?i[6-e+8*s]=1:i[7+8*s]=1)},_interleaveBlocks:function(){var $,e,t=this._dataBlock,x=this._ecc,i=this._eccBlock,s=0,n=this._calculateMaxLength(),_=this._neccBlock1,a=this._neccBlock2,r=this._stringBuffer;for($=0;$1)for($=r.BLOCK[x],t=i-7;;){for(e=i-7;e>$-3&&(this._addAlignment(e,t),!(e<$));)e-=$;if(t<=$+9)break;t-=$,this._addAlignment(6,t),this._addAlignment(t,6)}},_insertFinders:function(){var $,e,t,x,i=this.buffer,s=this.width;for($=0;$<3;$++){for(e=0,x=0,1===$&&(e=s-7),2===$&&(x=s-7),i[x+3+s*(e+3)]=1,t=0;t<6;t++)i[x+t+s*e]=1,i[x+s*(e+t+1)]=1,i[x+6+s*(e+t)]=1,i[x+t+1+s*(e+6)]=1;for(t=1;t<5;t++)this._setMask(x+t,e+1),this._setMask(x+1,e+t+1),this._setMask(x+5,e+t),this._setMask(x+t+1,e+5);for(t=2;t<4;t++)i[x+t+s*(e+2)]=1,i[x+2+s*(e+t+1)]=1,i[x+4+s*(e+t)]=1,i[x+t+1+s*(e+4)]=1}},_insertTimingGap:function(){var $,e,t=this.width;for(e=0;e<7;e++)this._setMask(7,e),this._setMask(t-8,e),this._setMask(7,e+t-7);for($=0;$<8;$++)this._setMask($,7),this._setMask($+t-8,7),this._setMask($,t-8)},_insertTimingRowAndColumn:function(){var $,e=this.buffer,t=this.width;for($=0;$6)for(t=0,$=c.BLOCK[s-7],e=17;t<6;t++)for(x=0;x<3;x++,e--)1&(e>11?s>>e-12:$>>e)?(i[5-t+n*(2-x+n-11)]=1,i[2-x+n-11+n*(5-t)]=1):(this._setMask(5-t,2-x+n-11),this._setMask(2-x+n-11,5-t))},_isMasked:function($,e){var t=h._getMaskBit($,e);return 1===this._mask[t]},_pack:function(){var $,e,t,x=1,i=1,s=this.width,n=s-1,_=s-1,a=(this._dataBlock+this._eccBlock)*(this._neccBlock1+this._neccBlock2)+this._neccBlock2;for(e=0;ee&&(t=$,$=e,e=t),t=e,t+=e*e,t>>=1,t+=$},_modN:function($){for(;$>=255;)$-=255,$=($>>8)+(255&$);return $},N1:3,N2:3,N3:40,N4:10}),u=h,d=_.extend({draw:function(){this.element.src=this.qrious.toDataURL()},reset:function(){this.element.src=""},resize:function(){var $=this.element;$.width=$.height=this.qrious.size}}),l=n.extend(function($,e,t,x){this.name=$,this.modifiable=Boolean(e),this.defaultValue=t,this._valueTransformer=x},{transform:function($){var e=this._valueTransformer;return"function"==typeof e?e($,this):$}}),b=n.extend(null,{abs:function($){return null!=$?Math.abs($):null},hasOwn:function($,e){return Object.prototype.hasOwnProperty.call($,e)},noop:function(){},toUpperCase:function($){return null!=$?$.toUpperCase():null}}),v=n.extend(function($){this.options={},$.forEach(function($){this.options[$.name]=$},this)},{exists:function($){return null!=this.options[$]},get:function($,e){return v._get(this.options[$],e)},getAll:function($){var e,t=this.options,x={};for(e in t)b.hasOwn(t,e)&&(x[e]=v._get(t[e],$));return x},init:function($,e,t){var x,i;for(x in"function"!=typeof t&&(t=b.noop),this.options)b.hasOwn(this.options,x)&&(i=this.options[x],v._set(i,i.defaultValue,e),v._createAccessor(i,e,t));this._setAll($,e,!0)},set:function($,e,t){return this._set($,e,t)},setAll:function($,e){return this._setAll($,e)},_set:function($,e,t,x){var i=this.options[$];if(!i)throw Error("Invalid option: "+$);if(!i.modifiable&&!x)throw Error("Option cannot be modified: "+$);return v._set(i,e,t)},_setAll:function($,e,t){if(!$)return!1;var x,i=!1;for(x in $)b.hasOwn($,x)&&this._set(x,$[x],e,t)&&(i=!0);return i}},{_createAccessor:function($,e,t){var x={get:function(){return v._get($,e)}};$.modifiable&&(x.set=function(x){v._set($,x,e)&&t(x,$)}),Object.defineProperty(e,$.name,x)},_get:function($,e){return e["_"+$.name]},_set:function($,e,t){var x="_"+$.name,i=t[x],s=$.transform(null!=e?e:$.defaultValue);return t[x]=s,s!==i}}),p=n.extend(function(){this._services={}},{getService:function($){var e=this._services[$];if(!e)throw Error("Service is not being managed with name: "+$);return e},setService:function($,e){if(this._services[$])throw Error("Service is already managed with name: "+$);e&&(this._services[$]=e)}}),g=new v([new l("background",!0,"white"),new l("backgroundAlpha",!0,1,b.abs),new l("element"),new l("foreground",!0,"black"),new l("foregroundAlpha",!0,1,b.abs),new l("level",!0,"L",b.toUpperCase),new l("mime",!0,"image/png"),new l("padding",!0,null,b.abs),new l("size",!0,100,b.abs),new l("value",!0,"")]),k=new p,m=n.extend(function($){g.init($,this,this.update.bind(this));var e=g.get("element",this),t=k.getService("element"),x=e&&t.isCanvas(e)?e:t.createCanvas(),i=e&&t.isImage(e)?e:t.createImage();this._canvasRenderer=new a(this,x,!0),this._imageRenderer=new d(this,i,i===e),this.update()},{get:function(){return g.getAll(this)},set:function($){g.setAll($,this)&&this.update()},toDataURL:function($){return this.canvas.toDataURL($||this.mime)},update:function(){var $=new u({level:this.level,value:this.value});this._canvasRenderer.render($),this._imageRenderer.render($)}},{use:function($){k.setService($.getName(),$)}});Object.defineProperties(m.prototype,{canvas:{get:function(){return this._canvasRenderer.getElement()}},image:{get:function(){return this._imageRenderer.getElement()}}});var w,M,B=m,y=n.extend({getName:function(){}}).extend({createCanvas:function(){},createImage:function(){},getName:function(){return"element"},isCanvas:function($){},isImage:function($){}}).extend({createCanvas:function(){return document.createElement("canvas")},createImage:function(){return document.createElement("img")},isCanvas:function($){return $ instanceof HTMLCanvasElement},isImage:function($){return $ instanceof HTMLImageElement}});return B.use(new y),B});