qr.dgnum.eu/www/js/qrious.min.js
2024-01-24 20:17:20 +01:00

40 lines
19 KiB
JavaScript

/*
* 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 <http://www.gnu.org/licenses/>.
*
*
* 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;_<a;_++)for(s in n=i[_])(!$||e.call(n,s))&&(x[s]=n[s])}var i=function e(t,i,s,n){var _,a,r,o=this;return"string"!=typeof t&&(n=s,s=i,i=t,t=null),"function"!=typeof i&&(n=s,s=i,i=function(){return o.apply(this,arguments)}),x(!1,i,o,n),i.prototype=(_=o.prototype,a=s,"function"==typeof Object.create?r=Object.create(_):($.prototype=_,r=new $,$.prototype=null),a&&x(!0,r,a),r),i.prototype.constructor=i,i.class_=t||o.class_,i.super_=o,i};function s(){}s.class_="Nevis",s.super_=Object,s.extend=i;var n=s,_=n.extend(function($,e,t){this.qrious=$,this.element=e,this.element.qrious=$,this.enabled=Boolean(t)},{draw:function($){},getElement:function(){return this.enabled||(this.enabled=!0,this.render()),this.element},getModuleSize:function($){var e=this.qrious,t=e.padding||0;return Math.max(1,Math.floor((e.size-2*t)/$.width))},getOffset:function($){var e=this.qrious,t=e.padding;if(null!=t)return t;var x=this.getModuleSize($);return Math.max(0,Math.floor((e.size-x*$.width)/2))},render:function($){this.enabled&&(this.resize(),this.reset(),this.draw($))},reset:function(){},resize:function(){}}),a=_.extend({draw:function($){var e,t,x=this.qrious,i=this.getModuleSize($),s=this.getOffset($),n=this.element.getContext("2d");for(e=0,n.fillStyle=x.foreground,n.globalAlpha=x.foregroundAlpha;e<$.width;e++)for(t=0;t<$.width;t++)$.buffer[t*$.width+e]&&n.fillRect(i*e+s,i*t+s,i,i)},reset:function(){var $=this.qrious,e=this.element.getContext("2d"),t=$.size;e.lineWidth=1,e.clearRect(0,0,t,t),e.fillStyle=$.background,e.globalAlpha=$.backgroundAlpha,e.fillRect(0,0,t,t)},resize:function(){var $=this.element;$.width=$.height=this.qrious.size}}),r=n.extend(null,{BLOCK:[0,11,15,19,23,27,31,16,18,20,22,24,26,28,20,22,24,24,26,28,28,22,24,24,26,26,28,28,24,24,26,26,26,28,28,24,26,26,26,28,28]}),o=n.extend(null,{BLOCKS:[1,0,19,7,1,0,16,10,1,0,13,13,1,0,9,17,1,0,34,10,1,0,28,16,1,0,22,22,1,0,16,28,1,0,55,15,1,0,44,26,2,0,17,18,2,0,13,22,1,0,80,20,2,0,32,18,2,0,24,26,4,0,9,16,1,0,108,26,2,0,43,24,2,2,15,18,2,2,11,22,2,0,68,18,4,0,27,16,4,0,19,24,4,0,15,28,2,0,78,20,4,0,31,18,2,4,14,18,4,1,13,26,2,0,97,24,2,2,38,22,4,2,18,22,4,2,14,26,2,0,116,30,3,2,36,22,4,4,16,20,4,4,12,24,2,2,68,18,4,1,43,26,6,2,19,24,6,2,15,28,4,0,81,20,1,4,50,30,4,4,22,28,3,8,12,24,2,2,92,24,6,2,36,22,4,6,20,26,7,4,14,28,4,0,107,26,8,1,37,22,8,4,20,24,12,4,11,22,3,1,115,30,4,5,40,24,11,5,16,20,11,5,12,24,5,1,87,22,5,5,41,24,5,7,24,30,11,7,12,24,5,1,98,24,7,3,45,28,15,2,19,24,3,13,15,30,1,5,107,28,10,1,46,28,1,15,22,28,2,17,14,28,5,1,120,30,9,4,43,26,17,1,22,28,2,19,14,28,3,4,113,28,3,11,44,26,17,4,21,26,9,16,13,26,3,5,107,28,3,13,41,26,15,5,24,30,15,10,15,28,4,4,116,28,17,0,42,26,17,6,22,28,19,6,16,30,2,7,111,28,17,0,46,28,7,16,24,30,34,0,13,24,4,5,121,30,4,14,47,28,11,14,24,30,16,14,15,30,6,4,117,30,6,14,45,28,11,16,24,30,30,2,16,30,8,4,106,26,8,13,47,28,7,22,24,30,22,13,15,30,10,2,114,28,19,4,46,28,28,6,22,28,33,4,16,30,8,4,122,30,22,3,45,28,8,26,23,30,12,28,15,30,3,10,117,30,3,23,45,28,4,31,24,30,11,31,15,30,7,7,116,30,21,7,45,28,1,37,23,30,19,26,15,30,5,10,115,30,19,10,47,28,15,25,24,30,23,25,15,30,13,3,115,30,2,29,46,28,42,1,24,30,23,28,15,30,17,0,115,30,10,23,46,28,10,35,24,30,19,35,15,30,17,1,115,30,14,21,46,28,29,19,24,30,11,46,15,30,13,6,115,30,14,23,46,28,44,7,24,30,59,1,16,30,12,7,121,30,12,26,47,28,39,14,24,30,22,41,15,30,6,14,121,30,6,34,47,28,46,10,24,30,2,64,15,30,17,4,122,30,29,14,46,28,49,10,24,30,24,46,15,30,4,18,122,30,13,32,46,28,48,14,24,30,42,32,15,30,20,4,117,30,40,7,47,28,43,22,24,30,10,67,15,30,19,6,118,30,18,31,47,28,34,34,24,30,20,61,15,30],FINAL_FORMAT:[30660,29427,32170,30877,26159,25368,27713,26998,21522,20773,24188,23371,17913,16590,20375,19104,13663,12392,16177,14854,9396,8579,11994,11245,5769,5054,7399,6608,1890,597,3340,2107],LEVELS:{L:1,M:2,Q:3,H:4}}),f=n.extend(null,{EXPONENT:[1,2,4,8,16,32,64,128,29,58,116,232,205,135,19,38,76,152,45,90,180,117,234,201,143,3,6,12,24,48,96,192,157,39,78,156,37,74,148,53,106,212,181,119,238,193,159,35,70,140,5,10,20,40,80,160,93,186,105,210,185,111,222,161,95,190,97,194,153,47,94,188,101,202,137,15,30,60,120,240,253,231,211,187,107,214,177,127,254,225,223,163,91,182,113,226,217,175,67,134,17,34,68,136,13,26,52,104,208,189,103,206,129,31,62,124,248,237,199,147,59,118,236,197,151,51,102,204,133,23,46,92,184,109,218,169,79,158,33,66,132,21,42,84,168,77,154,41,82,164,85,170,73,146,57,114,228,213,183,115,230,209,191,99,198,145,63,126,252,229,215,179,123,246,241,255,227,219,171,75,150,49,98,196,149,55,110,220,165,87,174,65,130,25,50,100,200,141,7,14,28,56,112,224,221,167,83,166,81,162,89,178,121,242,249,239,195,155,43,86,172,69,138,9,18,36,72,144,61,122,244,245,247,243,251,235,203,139,11,22,44,88,176,125,250,233,207,131,27,54,108,216,173,71,142,0],LOG:[255,0,1,25,2,50,26,198,3,223,51,238,27,104,199,75,4,100,224,14,52,141,239,129,28,193,105,248,200,8,76,113,5,138,101,47,225,36,15,33,53,147,142,218,240,18,130,69,29,181,194,125,106,39,249,185,201,154,9,120,77,228,114,166,6,191,139,98,102,221,48,253,226,152,37,179,16,145,34,136,54,208,148,206,143,150,219,189,241,210,19,92,131,56,70,64,30,66,182,163,195,72,126,110,107,58,40,84,250,133,186,61,202,94,155,159,10,21,121,43,78,212,229,172,115,243,167,87,7,112,192,247,140,128,99,13,103,74,222,237,49,197,254,24,227,165,153,119,38,184,180,124,17,68,146,217,35,32,137,46,55,63,209,91,149,188,207,205,144,135,151,178,220,252,190,97,242,86,211,171,20,42,93,158,132,60,57,83,71,109,65,162,31,45,67,216,183,123,164,118,196,23,73,236,127,12,111,246,108,161,59,82,41,157,85,170,251,96,134,177,187,204,62,90,203,89,95,176,156,169,160,81,11,245,22,235,122,117,44,215,79,174,213,233,230,231,173,232,116,214,244,234,168,80,88,175]}),c=n.extend(null,{BLOCK:[3220,1468,2713,1235,3062,1890,2119,1549,2344,2936,1117,2583,1330,2470,1667,2249,2028,3780,481,4011,142,3098,831,3445,592,2517,1776,2234,1951,2827,1070,2660,1345,3177]}),h=n.extend(function($){var e,t,x,i,s,n=$.value.length;for(this._badness=[],this._level=o.LEVELS[$.level],this._polynomial=[],this._value=$.value,this._version=0,this._stringBuffer=[];this._version<40&&(this._version++,x=(this._level-1)*4+(this._version-1)*16,i=o.BLOCKS[x++],s=o.BLOCKS[x++],e=o.BLOCKS[x++],t=o.BLOCKS[x],!(n<=(x=e*(i+s)+s-3+(this._version<=9)))););this._dataBlock=e,this._eccBlock=t,this._neccBlock1=i,this._neccBlock2=s;var _=this.width=17+4*this._version;this.buffer=h._createArray(_*_),this._ecc=h._createArray(e+(e+t)*(i+s)+s),this._mask=h._createArray((_*(_+1)+1)/2),this._insertFinders(),this._insertAlignments(),this.buffer[8+_*(_-8)]=1,this._insertTimingGap(),this._reverseMask(),this._insertTimingRowAndColumn(),this._insertVersion(),this._syncMask(),this._convertBitStream(n),this._calculatePolynomial(),this._appendEccToData(),this._interleaveBlocks(),this._pack(),this._finish()},{_addAlignment:function($,e){var t,x=this.buffer,i=this.width;for(t=-2,x[$+i*e]=1;t<2;t++)x[$+t+i*(e-2)]=1,x[$-2+i*(e+t+1)]=1,x[$+2+i*(e+t)]=1,x[$+t+1+i*(e+2)]=1;for(t=0;t<2;t++)this._setMask($-1,e+t),this._setMask($+1,e-t),this._setMask($-t,e-1),this._setMask($+t,e+1)},_appendData:function($,e,t,x){var i,s,n,_=this._polynomial,a=this._stringBuffer;for(s=0;s<x;s++)a[t+s]=0;for(s=0;s<e;s++){if(255!==(i=f.LOG[a[$+s]^a[t]]))for(n=1;n<x;n++)a[t+n-1]=a[t+n]^f.EXPONENT[h._modN(i+_[x-n])];else for(n=t;n<t+x;n++)a[n]=a[n+1];a[t+x-1]=255===i?0:f.EXPONENT[h._modN(i+_[0])]}},_appendEccToData:function(){var $,e=0,t=this._dataBlock,x=this._calculateMaxLength(),i=this._eccBlock;for($=0;$<this._neccBlock1;$++)this._appendData(e,t,x,i),e+=t,x+=i;for($=0;$<this._neccBlock2;$++)this._appendData(e,t+1,x,i),e+=t+1,x+=i},_applyMask:function($){var e,t,x,i,s=this.buffer,n=this.width;switch($){case 0:for(i=0;i<n;i++)for(x=0;x<n;x++)x+i&1||this._isMasked(x,i)||(s[x+i*n]^=1);break;case 1:for(i=0;i<n;i++)for(x=0;x<n;x++)1&i||this._isMasked(x,i)||(s[x+i*n]^=1);break;case 2:for(i=0;i<n;i++)for(e=0,x=0;x<n;x++,e++)3===e&&(e=0),e||this._isMasked(x,i)||(s[x+i*n]^=1);break;case 3:for(t=0,i=0;i<n;i++,t++)for(3===t&&(t=0),e=t,x=0;x<n;x++,e++)3===e&&(e=0),e||this._isMasked(x,i)||(s[x+i*n]^=1);break;case 4:for(i=0;i<n;i++)for(e=0,t=i>>1&1,x=0;x<n;x++,e++)3===e&&(e=0,t=!t),t||this._isMasked(x,i)||(s[x+i*n]^=1);break;case 5:for(t=0,i=0;i<n;i++,t++)for(3===t&&(t=0),e=0,x=0;x<n;x++,e++)3===e&&(e=0),(x&i&1)+!(!e|!t)||this._isMasked(x,i)||(s[x+i*n]^=1);break;case 6:for(t=0,i=0;i<n;i++,t++)for(3===t&&(t=0),e=0,x=0;x<n;x++,e++)3===e&&(e=0),(x&i&1)+(e&&e===t)&1||this._isMasked(x,i)||(s[x+i*n]^=1);break;case 7:for(t=0,i=0;i<n;i++,t++)for(3===t&&(t=0),e=0,x=0;x<n;x++,e++)3===e&&(e=0),(e&&e===t)+(x+i&1)&1||this._isMasked(x,i)||(s[x+i*n]^=1)}},_calculateMaxLength:function(){return this._dataBlock*(this._neccBlock1+this._neccBlock2)+this._neccBlock2},_calculatePolynomial:function(){var $,e,t=this._eccBlock,x=this._polynomial;for($=0,x[0]=1;$<t;$++){for(x[$+1]=1,e=$;e>0;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;i<a-1;i++)for(x=0;x<a-1;x++)(_[x+a*i]&&_[x+1+a*i]&&_[x+a*(i+1)]&&_[x+1+a*(i+1)]||!(_[x+a*i]||_[x+1+a*i]||_[x+a*(i+1)]||_[x+1+a*(i+1)]))&&(s+=h.N2);var r=0;for(i=0;i<a;i++){for($=0,t=0,n[0]=0,x=0;x<a;x++)$===(e=_[x+a*i])?n[t]++:n[++t]=1,r+=($=e)?1:-1;s+=this._getBadness(t)}r<0&&(r=-r);var o=0,f=r;for(f+=f<<2,f<<=1;f>a*a;)f-=a*a,o++;for(s+=o*h.N4,x=0;x<a;x++){for($=0,t=0,n[0]=0,i=0;i<a;i++)$===(e=_[x+a*i])?n[t]++:n[++t]=1,$=e;s+=this._getBadness(t)}return s},_convertBitStream:function($){var e,t,x=this._ecc,i=this._version;for(t=0;t<$;t++)x[t]=this._value.charCodeAt(t);var s=this._stringBuffer=x.slice(),n=this._calculateMaxLength();$>=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);_<n;)s[_++]=236,s[_++]=17},_getBadness:function($){var e,t=0,x=this._badness;for(e=0;e<=$;e++)x[e]>=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())<x&&(x=$,t=e),7!==t);e++)this.buffer=this._stringBuffer.slice();t!==e&&this._applyMask(t),x=o.FINAL_FORMAT[t+(this._level-1<<3)];var i=this.buffer,s=this.width;for(e=0;e<8;e++,x>>=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;$<t;$++){for(e=0;e<_;e++)x[s++]=r[$+e*t];for(e=0;e<a;e++)x[s++]=r[_*t+$+e*(t+1)]}for(e=0;e<a;e++)x[s++]=r[_*t+$+e*(t+1)];for($=0;$<i;$++)for(e=0;e<_+a;e++)x[s++]=r[n+$+e*i];this._stringBuffer=x},_insertAlignments:function(){var $,e,t,x=this._version,i=this.width;if(x>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;$<t-14;$++)1&$?(this._setMask(8+$,6),this._setMask(6,8+$)):(e[8+$+6*t]=1,e[6+t*(8+$)]=1)},_insertVersion:function(){var $,e,t,x,i=this.buffer,s=this._version,n=this.width;if(s>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;e<a;e++)for(t=0,$=this._stringBuffer[e];t<8;t++,$<<=1){128&$&&(this.buffer[n+s*_]=1);do i?n--:(n++,x?0!==_?_--:(x=!x,6==(n-=2)&&(n--,_=9)):_!==s-1?_++:(x=!x,6==(n-=2)&&(n--,_-=8))),i=!i;while(this._isMasked(n,_))}},_reverseMask:function(){var $,e,t=this.width;for($=0;$<9;$++)this._setMask($,8);for($=0;$<8;$++)this._setMask($+t-8,8),this._setMask(8,$);for(e=0;e<7;e++)this._setMask(8,e+t-7)},_setMask:function($,e){var t=h._getMaskBit($,e);this._mask[t]=1},_syncMask:function(){var $,e,t=this.width;for(e=0;e<t;e++)for($=0;$<=e;$++)this.buffer[$+t*e]&&this._setMask($,e)}},{_createArray:function($){var e,t=[];for(e=0;e<$;e++)t[e]=0;return t},_getMaskBit:function($,e){var t;return $>e&&(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});