(function(S,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@barcode-bakery/barcode-common")):typeof define=="function"&&define.amd?define(["exports","@barcode-bakery/barcode-common"],l):(S=typeof globalThis<"u"?globalThis:S||self,l(S["barcode-bakery-qrcode"]={},S["barcode-bakery-common"]))})(this,function(S,l){"use strict";var x=Object.defineProperty;var _=(S,l,T)=>l in S?x(S,l,{enumerable:!0,configurable:!0,writable:!0,value:T}):S[l]=T;var f=(S,l,T)=>(_(S,typeof l!="symbol"?l+"":l,T),T);const E=class E extends l.BCGBarcode2D{constructor(){super();f(this,"data",null);f(this,"errorLevel",1);f(this,"size",E.Size.Full);f(this,"quietZone",!0);f(this,"mirror",!1);f(this,"mask",-1);f(this,"qrSize",-1);f(this,"qrMicro",!1);f(this,"symbolNumber",0);f(this,"symbolTotal",0);f(this,"symbolData",null);f(this,"fnc1",E.Fnc1.None);f(this,"fnc1Id",null);f(this,"acceptECI",!1);f(this,"symbols",[new H(1,!0,36,[20,0,0,0],[[1],[0],[0],[0]]),new V(2,!0,80,[40,32,0,0],[[1],[1],[0],[0]]),new O(3,!0,132,[84,68,0,0],[[1],[1],[0],[0]]),new Y(4,!0,192,[128,112,80,0],[[1],[1],[1],[0]]),new k(1,!1,208,[152,128,104,72],[[1],[1],[1],[1]]),new k(2,!1,359,[272,224,176,128],[[1],[1],[1],[1]]),new k(3,!1,567,[440,352,272,208],[[1],[1],[2],[2]]),new k(4,!1,807,[640,512,384,288],[[1],[2],[2],[4]]),new k(5,!1,1079,[864,688,496,368],[[1],[2],[2,2],[2,2]]),new k(6,!1,1383,[1088,864,608,480],[[2],[4],[4],[4]]),new k(7,!1,1568,[1248,992,704,528],[[2],[4],[2,4],[4,1]]),new k(8,!1,1936,[1552,1232,880,688],[[2],[2,2],[4,2],[4,2]]),new k(9,!1,2336,[1856,1456,1056,800],[[2],[3,2],[4,4],[4,4]]),new N(10,!1,2768,[2192,1728,1232,976],[[2,2],[4,1],[6,2],[6,2]]),new N(11,!1,3232,[2592,2032,1440,1120],[[4],[1,4],[4,4],[3,8]]),new N(12,!1,3728,[2960,2320,1648,1264],[[2,2],[6,2],[4,6],[7,4]]),new N(13,!1,4256,[3424,2672,1952,1440],[[4],[8,1],[8,4],[12,4]]),new N(14,!1,4651,[3688,2920,2088,1576],[[3,1],[4,5],[11,5],[11,5]]),new N(15,!1,5243,[4184,3320,2360,1784],[[5,1],[5,5],[5,7],[11,7]]),new N(16,!1,5867,[4712,3624,2600,2024],[[5,1],[7,3],[15,2],[3,13]]),new N(17,!1,6523,[5176,4056,2936,2264],[[1,5],[10,1],[1,15],[2,17]]),new N(18,!1,7211,[5768,4504,3176,2504],[[5,1],[9,4],[17,1],[2,19]]),new N(19,!1,7931,[6360,5016,3560,2728],[[3,4],[3,11],[17,4],[9,16]]),new N(20,!1,8683,[6888,5352,3880,3080],[[3,5],[3,13],[15,5],[15,10]]),new N(21,!1,9252,[7456,5712,4096,3248],[[4,4],[17],[17,6],[19,6]]),new N(22,!1,10068,[8048,6256,4544,3536],[[2,7],[17],[7,16],[34]]),new N(23,!1,10916,[8752,6880,4912,3712],[[4,5],[4,14],[11,14],[16,14]]),new N(24,!1,11796,[9392,7312,5312,4112],[[6,4],[6,14],[11,16],[30,2]]),new N(25,!1,12708,[10208,8e3,5744,4304],[[8,4],[8,13],[7,22],[22,13]]),new N(26,!1,13652,[10960,8496,6032,4768],[[10,2],[19,4],[28,6],[33,4]]),new A(27,!1,14628,[11744,9024,6464,5024],[[8,4],[22,3],[8,26],[12,28]]),new A(28,!1,15371,[12248,9544,6968,5288],[[3,10],[3,23],[4,31],[11,31]]),new A(29,!1,16411,[13048,10136,7288,5608],[[7,7],[21,7],[1,37],[19,26]]),new A(30,!1,17483,[13880,10984,7880,5960],[[5,10],[19,10],[15,25],[23,25]]),new A(31,!1,18587,[14744,11640,8264,6344],[[13,3],[2,29],[42,1],[23,28]]),new A(32,!1,19723,[15640,12328,8920,6760],[[17],[10,23],[10,35],[19,35]]),new A(33,!1,20891,[16568,13048,9368,7208],[[17,1],[14,21],[29,19],[11,46]]),new A(34,!1,22091,[17528,13800,9848,7688],[[13,6],[14,23],[44,7],[59,1]]),new A(35,!1,23008,[18448,14496,10288,7888],[[12,7],[12,26],[39,14],[22,41]]),new A(36,!1,24272,[19472,15312,10832,8432],[[6,14],[6,34],[46,10],[2,64]]),new A(37,!1,25568,[20528,15936,11408,8768],[[17,4],[29,14],[49,10],[24,46]]),new A(38,!1,26896,[21616,16816,12016,9136],[[4,18],[13,32],[48,14],[42,32]]),new A(39,!1,28256,[22496,17728,12656,9776],[[20,4],[40,7],[43,22],[10,67]]),new A(40,!1,29648,[23648,18672,13328,10208],[[19,6],[18,31],[34,34],[20,61]])]);f(this,"symbol",null);f(this,"hasECI",!1);f(this,"alignmentPatterns",[[],[],[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]]);f(this,"logTable",[-255,255,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]);f(this,"aLogTable",[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,1]);f(this,"aLogRS",{2:[3,2],5:[31,198,63,147,116],6:[248,1,218,32,227,38],7:[127,122,154,164,11,68,117],8:[255,11,81,54,239,173,200,24],10:[216,194,159,111,199,94,95,113,157,193],13:[137,73,227,17,177,17,52,13,46,43,83,132,120],14:[14,54,114,70,174,151,43,158,195,127,166,210,234,163],15:[29,196,111,163,112,74,10,105,105,139,132,151,32,134,26],16:[59,13,104,189,68,209,30,8,163,65,41,229,98,50,36,59],17:[119,66,83,120,119,22,197,83,249,41,143,134,85,53,125,99,79],18:[239,251,183,113,149,175,199,215,240,220,73,82,173,75,32,67,217,146],20:[152,185,240,5,111,99,6,220,112,150,69,36,187,22,228,198,121,121,165,174],22:[89,179,131,176,182,244,19,189,69,40,28,137,29,123,67,253,86,218,230,26,145,245],24:[122,118,169,70,178,237,216,102,115,150,229,73,130,72,61,43,206,1,237,247,127,217,144,117],26:[246,51,183,4,136,98,199,152,77,56,206,24,145,40,209,117,233,42,135,68,70,144,146,77,43,94],28:[252,9,28,13,18,251,208,150,103,174,100,41,167,12,247,56,117,119,233,127,181,100,121,147,176,74,58,197],30:[212,246,77,73,195,192,75,98,5,70,103,177,22,217,138,51,181,246,72,25,18,46,228,74,216,195,11,106,130,150],32:[116,64,52,174,54,126,16,194,162,33,33,157,176,197,225,12,59,55,253,228,148,47,179,185,24,138,253,20,142,55,172,88],34:[206,60,154,113,6,117,208,90,26,113,31,25,177,132,99,51,105,183,122,22,43,136,93,94,62,111,196,23,126,135,67,222,23,10],36:[28,196,67,76,123,192,207,251,185,73,124,1,126,73,31,27,11,104,45,161,43,74,127,89,26,219,59,137,118,200,237,216,31,243,96,59],40:[210,248,240,209,173,67,133,167,133,209,131,186,99,93,235,52,40,6,220,241,72,13,215,128,255,156,49,62,254,212,35,99,51,218,101,180,247,40,156,38],42:[108,136,69,244,3,45,158,245,1,8,105,176,69,65,103,107,244,29,165,52,217,41,38,92,66,78,34,9,53,34,242,14,139,142,56,197,179,191,50,237,5,217],44:[174,128,111,118,188,207,47,160,252,165,225,125,65,3,101,197,58,77,19,131,2,11,238,120,84,222,18,102,199,62,153,99,20,50,155,41,221,229,74,46,31,68,202,49],46:[129,113,254,129,71,18,112,124,220,134,225,32,80,31,23,238,105,76,169,195,229,178,37,2,16,217,185,88,202,13,251,29,54,233,147,241,20,3,213,18,119,112,9,90,211,38],48:[61,3,200,46,178,154,185,143,216,223,53,68,44,111,171,161,159,197,124,45,69,206,169,230,98,167,104,83,226,85,59,149,163,117,131,228,132,11,65,232,113,144,107,5,99,53,78,208],50:[247,51,213,209,198,58,199,159,162,134,224,25,156,8,162,206,100,176,224,36,159,135,157,230,102,162,46,230,176,239,176,15,60,181,87,157,31,190,151,47,61,62,235,255,151,215,239,247,109,167],52:[248,5,177,110,5,172,216,225,130,159,177,204,151,90,149,243,170,239,234,19,210,77,74,176,224,218,142,225,174,113,210,190,151,31,17,243,235,118,234,30,177,175,53,176,28,172,34,39,22,142,248,10],54:[196,6,56,127,89,69,31,117,159,190,193,5,11,149,54,36,68,105,162,43,189,145,6,226,149,130,20,233,156,142,11,255,123,240,197,3,236,119,59,208,239,253,133,56,235,29,146,210,34,192,7,30,192,228],56:[52,59,104,213,198,195,129,248,4,163,27,99,37,56,112,122,64,168,142,114,169,81,215,162,205,66,204,42,98,54,219,241,174,24,116,214,22,149,34,151,73,83,217,201,99,111,12,200,131,170,57,112,166,180,111,116],58:[211,248,6,131,97,12,222,104,173,98,28,55,235,160,216,176,89,168,57,139,227,21,130,27,73,54,83,214,71,42,190,145,51,201,143,96,236,44,249,64,23,43,48,77,204,218,83,233,237,48,212,161,115,42,243,51,82,197],60:[104,132,6,205,58,21,125,141,72,141,86,193,178,34,86,59,24,49,204,64,17,131,4,167,7,186,124,86,34,189,230,211,74,148,11,140,230,162,118,177,232,151,96,49,107,3,50,127,190,68,174,172,94,12,162,76,225,128,39,44],62:[190,112,31,67,188,9,27,199,249,113,1,236,74,201,4,61,105,118,128,26,169,120,125,199,94,30,9,225,101,5,94,206,50,152,121,102,49,156,69,237,235,232,122,164,41,197,242,106,124,64,28,17,6,207,98,43,204,239,37,110,103,52],64:[193,10,255,58,128,183,115,140,153,147,91,197,219,221,220,142,28,120,21,164,147,6,204,40,230,182,14,121,48,143,77,228,81,85,43,162,16,195,163,35,149,154,35,132,100,100,51,176,11,161,134,208,132,244,176,192,221,232,171,125,155,228,242,245],66:[32,199,138,150,79,79,191,10,159,237,135,239,231,152,66,131,141,179,226,246,190,158,171,153,206,226,34,212,101,249,229,141,226,128,238,57,60,206,203,106,118,84,161,127,253,71,44,102,155,60,78,247,52,5,252,211,30,154,194,52,179,3,184,182,193,26],68:[131,115,9,39,18,182,60,94,223,230,157,142,119,85,107,34,174,167,109,20,185,112,145,172,224,170,182,107,38,107,71,246,230,225,144,20,14,175,226,245,20,219,212,51,158,88,63,36,199,4,80,157,211,239,255,7,119,11,235,12,34,149,204,8,32,29,99,11]});f(this,"formatErrorCodeMicro",[17477,16754,20011,19228,21934,20633,24512,23287,26515,25252,28157,26826,30328,29519,31766,31009,1758,1001,3248,2439,5941,4610,7515,6252,9480,8255,12134,10833,13539,12756,16013,15290]);f(this,"formatErrorCodeFull",[21522,20773,24188,23371,17913,16590,20375,19104,30660,29427,32170,30877,26159,25368,27713,26998,5769,5054,7399,6608,1890,597,3340,2107,13663,12392,16177,14854,9396,8579,11994,11245]);f(this,"versionErrorCode",[0,0,0,0,0,0,0,31892,34236,39577,42195,48118,51042,55367,58893,63784,68472,70749,76311,79154,84390,87683,92361,96236,102084,102881,110507,110734,117786,119615,126325,127568,133589,136944,141498,145311,150283,152622,158308,161089,167017]);f(this,"errorCorrectionBinaryIndicator",[1,0,3,2]);f(this,"errorCode",{L:0,M:1,Q:2,H:3});this.setScale(4)}parse(e){if(e.length===0)throw new l.BCGParseException("qrcode","Provide data to parse.");let s;if({value:s,text:e}=this.getSequence(e),s!==null){const i=this.createBinaryStream(e,s);this.setData(i)}}draw(e){if(this.data===null)throw new Error;if(this.symbol===null)throw new l.BCGDrawException("Undefined symbol");const t=this.quietZone?this.symbol.micro?4:8:0,s=B.getSize(this.symbol);this.quietZone&&super.drawFilledRectangle(e,0,0,s+t-1,s+t-1,l.BCGBarcode.COLOR_BG);for(let i=0;i3)throw new l.BCGArgumentException("The error level must be between 0 and 3.","level");this.errorLevel=e}}setSize(e){this.size=e}setFNC1(e,t=null){if(this.fnc1=e,this.fnc1===E.Fnc1.AIM){const s=(t==null?void 0:t.toString())||"",i=parseInt(s||"",10);if((s==null?void 0:s.length)===1&&s.toLowerCase()[0]>="a"&&s.toLowerCase()[0]<="z"||!isNaN(i)&&i>=0&&i<=99)this.fnc1Id=s;else throw new l.BCGArgumentException("In FNC1 AIM mode, you need to provide to the fnc1Id one letter or a number between 0 and 99.","fnc1Id")}else this.fnc1Id=null}setStructuredAppend(e,t=0,s=null){if(t===0)return this.symbolNumber=0,this.symbolTotal=0,this.symbolData=null,!0;if(e<=0)throw new l.BCGArgumentException("The symbol number must be equal or bigger than 1.","symbolNumber");if(e>t)throw new l.BCGArgumentException("The symbol number must be equal or lower than the symbol total.","symbolNumber");if(t>16)throw new l.BCGArgumentException("The symbol total must be equal or lower than 16.","symbolTotal");return this.symbolNumber=e,this.symbolTotal=t,this.symbolData=s,!0}setAcceptECI(e){this.acceptECI=e}setQuietZone(e){this.quietZone=e}setMirror(e){this.mirror=e}setMask(e){if(e<-1||e>7)throw new l.BCGArgumentException("The mask number must be between 0 and 7. You can set -1 for automatic.","mask");this.mask=e}setQRSize(e,t=!1){this.qrMicro=t;const s=this.qrMicro?4:40;if(e<-1||e===0||e>s)throw new l.BCGArgumentException("The QR size number must be between 1 and 4 for Micro mode, or between 1 and 40 for Full mode. You can set -1 for automatic.","qrSize");this.qrSize=e}drawPixel(e,t,s,i){if(this.symbol===null)throw new Error;const n=this.quietZone?this.symbol.micro?2:4:0;super.drawPixel(e,t+n,s+n,i)}drawFilledRectangle(e,t,s,i,n,r){if(this.symbol===null)throw new Error;const h=this.quietZone?this.symbol.micro?2:4:0;super.drawFilledRectangle(e,t+h,s+h,i+h,n+h,r)}static prod(e,t,s,i){return e===0||t===0?0:i[(s[e]+s[t])%(E._GF-1)]}static assembleFromBlocks(e,t,s,i){let n,r;i===0?(n=l.Utility.arraySum(t),r=0):(n=t[0],r=t[1]);const h=[],c=l.Utility.arraySum(t);for(let u=0;u=7){const t=B.getSize(this.symbol)-11;if(e)for(let s=0;s<6;s++)for(let i=0;i<3;i++)this.data[i+t][s].set(!1,!0),this.data[s][i+t].set(!1,!0);else{const s=this.versionErrorCode[this.symbol.version];for(let i=0;i<6;i++)for(let n=0;n<3;n++){const r=1<=8;t--,r++){const h=1<n&&(e-=2,t--,s=!0)),e===6&&!this.symbol.micro&&e--,r===null&&({value:r,x:e,y:t,up:s,left:i}=this.getBitPosition(e,t,s,i,n)),{value:r,x:e,y:t,up:s,left:i}}applyMasking(){if(this.symbol===null)throw new Error;if(this.data===null)throw new Error;const e=J.getMaskClass(this.symbol,this.mask);this.data=e.getMaskData(this.data),this.mask=e.getMaskId()}setData(e){if(this.symbol===null)throw new Error;const t=B.getSize(this.symbol);this.data=[];for(let s=0;s6&&e[6]!=="B"&&(t[1]="A",e.length>7&&e[7]!=="B"&&(t[2]="A"))),s=l.Utility.safeSubstring(e,0,3),s.length===3&&s.indexOf("B")===-1&&(t[5]="A",e.length>3&&e[3]!=="B"&&(t[6]="A"))):e[0]==="N"&&(l.Utility.safeSubstring(e,0,7)==="NNNNNNN"&&(t[0]="N",e.length>7&&e[7]==="N"&&(t[1]="N",e.length>8&&e[8]==="N"&&(t[2]="N"))),e.indexOf("B")===-1?(t[4]=t[5]=t[6]="A",s=l.Utility.safeSubstring(e,0,3),s.length===3&&s==="NNN"&&(t[4]="N",e.length>3&&e[3]==="N"&&(t[5]="N",e.length>4&&e[4]==="N"&&(t[6]="N")))):(s=l.Utility.safeSubstring(e,0,2),s.length===2&&s==="NN"&&(t[5]="N",e.length>2&&e[2]==="N"&&(t[6]="N"))),s=l.Utility.safeSubstring(e,0,4),s.length===4&&s.indexOf("B")===-1&&(t[0]=t[0]!=="N"?"A":"N",t[1]=t[1]!=="N"?"A":"N",e.length>4&&e[4]!=="B"&&(t[2]="A"))),t}getSequence(e){var b;let t="",s=e.length;for(let o=0;o0)m===1?(t+="E"+e.substring(o+1,o+1+6),o+=6):(e=e.substring(0,o)+e.substring(o+1),s--,t+="B");else if(this.isCharNumeric(e[o]))t+="N";else if(this.isCharAlphanumeric(e[o]))t+="A";else if(this.isCharByte(e[o]))t+="B";else if(this.isCharKanji(e[o]))t+="K";else throw new l.BCGParseException("qrcode","The character "+e[o]+" is not supported.")}const i=t.length,n=99999,r=[13,15,17,1,3,4,5],h=[9,12,13,n,n,n,n],c=[11,15,16,n,n,3,4],w=[6,7,8,n,n,2,3],u=[];for(let o=0;o<7;o++){const m=o>=3;let g=[],d="\0",p={B:0,A:0,N:0,K:0,E:0};for(let y=0;yy+1?t[y+1]:"\0"):l.Utility.safeSubstring(t,y+1,w[o])===l.Utility.strRepeat("N",w[o])&&(d="N",{seq:g,counter:p}=this.addSequence(o,d,w[o],m,g,p),y+=w[o],d=t.length>y+1?t[y+1]:"\0"):d==="A"?t[y+1]==="K"?d="K":t[y+1]==="E"?(y++,{value:d,i:y,seq:g,counter:p}=this.addESequence(o,m,t,y,g,p)):t[y+1]==="B"?d="B":l.Utility.safeSubstring(t,y+1,r[o])===l.Utility.strRepeat("N",r[o])&&(d="N",{seq:g,counter:p}=this.addSequence(o,d,r[o],m,g,p),y+=r[o],d=t.length>y+1?t[y+1]:"\0"):d==="N"?t[y+1]==="K"?d="K":t[y+1]==="E"?(y++,{value:d,i:y,seq:g,counter:p}=this.addESequence(o,m,t,y,g,p)):t[y+1]==="B"?d="B":t[y+1]==="A"&&(d="A"):d==="K"&&(d=this.findStartingSequence(l.Utility.safeSubstring(t,y+1))[o]);u[o]=g}for(let o=3;o<7;o++){let m=!1;const g=((b=u[o])==null?void 0:b.length)??0;for(let d=0;di&&s[i]==="E";){({seq:n,counter:r}=this.addSequence(e,"E",1,t,n,r));const h=parseInt(l.Utility.safeSubstring(s,i+1,6),10);n[n.length-1].amount=h,i+=7}return s.length>i?{value:this.findStartingSequence(s.substring(i))[e],i,seq:n,counter:r}:{value:"\0",i,seq:n,counter:r}}addSequence(e,t,s,i,n,r){const h={B:[255,65535,65535],A:[511,2047,8191],N:[1023,4095,16383],K:[255,1023,4095],E:[1,1,1]};r[t]===0&&(r={B:0,A:0,N:0,K:0,E:0},n.push(new $(t)));const c=i?s:Math.min(s,h[t][e]-r[t]);return c>0&&(n[n.length-1].amount+=c,r[t]+=c),s>c&&(r[t]=0,{seq:n,counter:r}=this.addSequence(e,t,s-c,i,n,r)),{seq:n,counter:r}}isEscapedCharacter(e,t){if(this.acceptECI&&e[t]==="\\"){const s=l.Utility.safeSubstring(e,t+1,6);if(s.length===6&&l.Utility.isNumeric(s))return 1;if(e.length>t+1&&e[t+1]==="\\")return 2;throw new l.BCGParseException("qrcode","Incorrect ECI code detected. ECI code must contain a backslash followed by 6 digits or double the backslash to write one backslash.")}return 0}isCharNumeric(e){const t=e.charCodeAt(0);return t>=48&&t<=57}isCharAlphanumeric(e,t=!1){const s=e.charCodeAt(0),i=this.isCharNumeric(e),n=s>=65&&s<=90||s===32||s===36||s===37||s===42||s===43||s===45||s===46||s===47||s===58;return!t&&(n||i)||t&&n&&!i}isCharByte(e,t=!1){const s=e.charCodeAt(0);return!t&&s>=0&&s<=255||t&&!this.isCharAlphanumeric(e)}isCharKanji(e,t=!1){return!1}getKanjiValue(e){return 0}isLowKanji(e){return e>=33088&&e<=40956}calculateBits(e){const t=[10,12,14,3,4,5,6],s=[9,11,13,0,3,4,5],i=[8,16,16,0,0,4,5],n=[8,10,12,0,0,3,4],r=[4,4,4,0,1,2,3],h=e.length,c=Array(h).fill(0);for(let u=0;u0&&(w+=20),this.fnc1===E.Fnc1.GS1&&(w+=4),this.fnc1===E.Fnc1.AIM&&(w+=12),w>0)for(let u=0;u<3;u++)c[u]+=w;return c}findSymbolIndex(e,t){return t?e-1:e+3}findPerfectSymbolRange(e,t,s,i){if(i>0){const n=this.findSymbolIndex(t,s);for(let r=this.findSymbolIndex(e,s);r<=n;r++){const h=this.symbols[r];if(i<=h.data[this.errorLevel]&&(i===h.data[this.errorLevel]||i+3<=h.data[this.errorLevel]))return h}}return null}findPerfectSymbol(e){if(this.symbol=null,this.qrSize===-1){if(this.symbolNumber===0&&this.fnc1===E.Fnc1.None&&!this.hasECI&&(this.size===E.Size.Smallest||this.size===E.Size.Micro)){for(let t=0;t<4;t++)if(this.symbol=this.findPerfectSymbolRange(t+1,t+1,!0,e[t+3]),this.symbol!==null)return t+3}if(this.size===E.Size.Smallest||this.size===E.Size.Full){if(this.symbol=this.findPerfectSymbolRange(1,9,!1,e[0]),this.symbol!==null)return 0;if(this.symbol=this.findPerfectSymbolRange(10,26,!1,e[1]),this.symbol!==null)return 1;if(this.symbol=this.findPerfectSymbolRange(27,40,!1,e[2]),this.symbol!==null)return 2}}else{const t=this.findSymbolIndex(this.qrSize,this.qrMicro);let s;this.qrMicro?s=this.qrSize+2:s=this.qrSize<=40?this.qrSize<=26?this.qrSize<=9?0:1:2:-1;const i=this.symbols[t],n=i.data[this.errorLevel]-e[s];if(i!==null&&e[s]>0&&(e[s]===i.data[this.errorLevel]||e[s]=i.getCodeTerminator().length))&&(this.symbol=i),this.symbol!==null)return s}throw new l.BCGParseException("qrcode","No barcode can fit the data you provided. Accept bigger barcodes or change your data.")}createBinaryStream(e,t){const s=this.calculateBits(t),i=this.findPerfectSymbol(s),n=t[i];return this.encode(e,n)}encodeStructuredAppend(){var e;if(this.symbol===null)throw new Error;if(this.symbolNumber>0&&this.symbol instanceof v)throw new l.BCGParseException("qrcode","A Micro QRCode cannot contain a structured append. Make sure to allow Full mode or don't use structured append.");if(this.symbolNumber>0){let t=this.symbol.getCodeStructuredAppend();t+=l.Utility.decbin(this.symbolNumber-1,4),t+=l.Utility.decbin(this.symbolTotal-1,4);let s=0;const i=((e=this.symbolData)==null?void 0:e.length)??0;for(let n=0;n0&&t[0].sequence==="E"){if(this.symbol instanceof v)throw new l.BCGParseException("qrcode","A Micro QRCode cannot contain a ECI code. Make sure to allow Full mode or don't use ECI.");{e=e.substring(7);const s=t[0].amount;return t.splice(0,1),{value:this.encodeECI(s),text:e,realSeq:t}}}else return{value:"",text:e,realSeq:t}}encode(e,t){if(this.symbol===null)throw new Error;let s=this.encodeStructuredAppend();s+=this.encodeFNC1(E.Fnc1.GS1);let i;({value:i,text:e}=this.encodeFirstECI(e,t)),s+=i,s+=this.encodeFNC1(E.Fnc1.AIM);let n=(t==null?void 0:t.length)??0,r=0;for(let d=0;d>8),z+=String.fromCharCode(Z&255),y--}else z+=G;j++}s+=this.encodeByte(z)}else p==="K"&&(s+=this.encodeKanji(e.substring(r,r+y)));r+=y}const h=this.symbol.getCodeTerminator().substring(0,Math.min(this.symbol.data[this.errorLevel]-s.length,this.symbol.getCodeTerminator().length));s+=h;const c=(8-s.length%8)%8;s+=l.Utility.strRepeat("0",c);const w=["11101100","00010001"];n=Math.ceil((this.symbol.data[this.errorLevel]-s.length)/8);for(let d=0;d=1?s=l.Utility.safeSubstring(s,0,-8)+"0000":s=l.Utility.safeSubstring(s,0,-4));const u=l.Utility.stringSplit(s,8),b=Math.floor((this.symbol.bits-this.symbol.data[this.errorLevel])/8),o=this.computeError(u,b),m=this.assemble(u,o),g=this.symbol.bits%8;return g>0&&m.push(l.Utility.strRepeat("0",g)),m}computeError(e,t){if(this.symbol===null)throw new Error;const s=this.symbol.blocks[this.errorLevel],i=l.Utility.arraySum(s),r=Math.floor(Math.floor(this.symbol.data[this.errorLevel]/8)/i),h=Math.floor(this.symbol.data[this.errorLevel]/8)%i===0?0:r+1;let c=Math.floor(t/i),w=[],u=0;for(let o=0;o1)for(let o=0;o0&&(r++,h=0);const c=E.assembleFromBlocks(e,s,r,h),u=Math.floor(Math.floor((this.symbol.bits-this.symbol.data[this.errorLevel])/8)/i),b=Math.floor((this.symbol.bits-this.symbol.data[this.errorLevel])/8)%i===0?0:u+1,o=E.assembleFromBlocks(t,s,u,b);return c.concat(o)}encodeKanji(e){if(this.symbol===null)throw new Error;let t="";const s=e.length;for(let n=0;n>8)*192+(c&255);t+=l.Utility.decbin(u,13)}const i=this.symbol.getBANK();return this.symbol.getCodeKanji()+l.Utility.decbin(e.length,i.K)+t}encodeByte(e){if(this.symbol===null)throw new Error;let t="";const s=e.length;for(let n=0;nr+1){const c=t.indexOf(e[r+1]);s+=l.Utility.decbin(h*45+c,11)}else s+=l.Utility.decbin(h,6)}const n=this.symbol.getBANK();return this.symbol.getCodeAlphanumeric()+l.Utility.decbin(e.length,n.A)+s}encodeNumeric(e){if(this.symbol===null)throw new Error;let t="";const s=l.Utility.stringSplit(e,3),i=s.length;for(let r=0;rt%2===0,(e,t)=>(Math.floor(t/2)+Math.floor(e/3))%2===0,(e,t)=>(t*e%2+t*e%3)%2===0,(e,t)=>((t+e)%2+t*e%3)%2===0])}getMaskConditions(){return this.maskConditions}applyMaskConditions(e){const t=B.getSize(this.qrInfo),s=4,i=Array(s).fill(0);for(let r=0;rc){const w=h;h=c,c=w}i[r]=h*16+c}let n=0;for(let r=1;ri[n]&&(n=r);return n}}class W extends J{constructor(e,t){super(e,t);f(this,"maskConditions",[(e,t)=>(e+t)%2===0,(e,t)=>t%2===0,(e,t)=>e%3===0,(e,t)=>(t+e)%3===0,(e,t)=>(Math.floor(t/2)+Math.floor(e/3))%2===0,(e,t)=>t*e%2+t*e%3===0,(e,t)=>(t*e%2+t*e%3)%2===0,(e,t)=>((t+e)%2+t*e%3)%2===0])}getMaskConditions(){return this.maskConditions}applyMaskConditions(e){const t=B.getSize(this.qrInfo),s=8,i=new X,n=Array(s).fill(3),r=Array(s).fill(0),h=Array(s).fill(0),c=Array(s).fill(0);for(let b=0;b5&&(n[b]+=d-5),p=e[b][g][y].pixel,d=1);d>5&&(n[b]+=d-5)}for(let g=0;g5&&(n[b]+=d-5),p=e[b][y][g].pixel,d=1);d>5&&(n[b]+=d-5)}const m=Math.abs(Math.floor((o/(t*t)*100-50)/5));c[b]=10*m}const w=Array(s).fill(0);for(let b=0;b{(a=>{a[a.Smallest=0]="Smallest",a[a.Micro=1]="Micro",a[a.Full=2]="Full"})(I.Size||(I.Size={})),(a=>{a[a.None=0]="None",a[a.GS1=1]="GS1",a[a.AIM=2]="AIM"})(I.Fnc1||(I.Fnc1={}))})(T||(T={})),S.BCGqrcode=T,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});