var QRCodeUtils=function(t){"use strict";var e={},n={},r={};let o;const i=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];r.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return 4*t+17},r.getSymbolTotalCodewords=function(t){return i[t]},r.getBCHDigit=function(t){let e=0;for(;0!==t;)e++,t>>>=1;return e},r.setToSJISFunction=function(t){if("function"!=typeof t)throw new Error('"toSJISFunc" is not a valid function.');o=t},r.isKanjiModeEnabled=function(){return void 0!==o},r.toSJIS=function(t){return o(t)};var a,s={};function c(){this.buffer=[],this.length=0}(a=s).L={bit:1},a.M={bit:0},a.Q={bit:3},a.H={bit:2},a.isValid=function(t){return t&&void 0!==t.bit&&t.bit>=0&&t.bit<4},a.from=function(t,e){if(a.isValid(t))return t;try{return function(t){if("string"!=typeof t)throw new Error("Param is not a string");switch(t.toLowerCase()){case"l":case"low":return a.L;case"m":case"medium":return a.M;case"q":case"quartile":return a.Q;case"h":case"high":return a.H;default:throw new Error("Unknown EC Level: "+t)}}(t)}catch(n){return e}},c.prototype={get:function(t){const e=Math.floor(t/8);return 1==(this.buffer[e]>>>7-t%8&1)},put:function(t,e){for(let n=0;n>>e-n-1&1))},getLengthInBits:function(){return this.length},putBit:function(t){const e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}};var u=c;function l(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}l.prototype.set=function(t,e,n,r){const o=t*this.size+e;this.data[o]=n,r&&(this.reservedBit[o]=!0)},l.prototype.get=function(t,e){return this.data[t*this.size+e]},l.prototype.xor=function(t,e,n){this.data[t*this.size+e]^=n},l.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]};var d=l,g={};!function(t){const e=r.getSymbolSize;t.getRowColCoords=function(t){if(1===t)return[];const n=Math.floor(t/7)+2,r=e(t),o=145===r?26:2*Math.ceil((r-13)/(2*n-2)),i=[r-7];for(let e=1;e=0&&t<=7},t.from=function(e){return t.isValid(e)?parseInt(e,10):void 0},t.getPenaltyN1=function(t){const n=t.size;let r=0,o=0,i=0,a=null,s=null;for(let c=0;c=5&&(r+=e+(o-5)),a=n,o=1),n=t.get(u,c),n===s?i++:(i>=5&&(r+=e+(i-5)),s=n,i=1)}o>=5&&(r+=e+(o-5)),i>=5&&(r+=e+(i-5))}return r},t.getPenaltyN2=function(t){const e=t.size;let r=0;for(let n=0;n=10&&(1488===o||93===o)&&n++,i=i<<1&2047|t.get(a,r),a>=10&&(1488===i||93===i)&&n++}return n*r},t.getPenaltyN4=function(t){let e=0;const n=t.data.length;for(let r=0;r=0;){const t=r[0];for(let i=0;i0){const t=new Uint8Array(this.degree);return t.set(n,r),t}return n};var M=B,P={},R={},T={isValid:function(t){return!isNaN(t)&&t>=1&&t<=40}},N={};const F="[0-9]+";let S="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";S=S.replace(/u/g,"\\u");const x="(?:(?![A-Z0-9 $%*+\\-./:]|"+S+")(?:.|[\r\n]))+";N.KANJI=new RegExp(S,"g"),N.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),N.BYTE=new RegExp(x,"g"),N.NUMERIC=new RegExp(F,"g"),N.ALPHANUMERIC=new RegExp("[A-Z $%*+\\-./:]+","g");const L=new RegExp("^"+S+"$"),U=new RegExp("^"+F+"$"),z=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");N.testKanji=function(t){return L.test(t)},N.testNumeric=function(t){return U.test(t)},N.testAlphanumeric=function(t){return z.test(t)},function(t){const e=T,n=N;t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(t,n){if(!t.ccBits)throw new Error("Invalid mode: "+t);if(!e.isValid(n))throw new Error("Invalid version: "+n);return n>=1&&n<10?t.ccBits[0]:n<27?t.ccBits[1]:t.ccBits[2]},t.getBestModeForData=function(e){return n.testNumeric(e)?t.NUMERIC:n.testAlphanumeric(e)?t.ALPHANUMERIC:n.testKanji(e)?t.KANJI:t.BYTE},t.toString=function(t){if(t&&t.id)return t.id;throw new Error("Invalid mode")},t.isValid=function(t){return t&&t.bit&&t.ccBits},t.from=function(e,n){if(t.isValid(e))return e;try{return function(e){if("string"!=typeof e)throw new Error("Param is not a string");switch(e.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+e)}}(e)}catch(r){return n}}}(R),function(t){const e=r,n=p,o=s,i=R,a=T,c=e.getBCHDigit(7973);function u(t,e){return i.getCharCountIndicator(t,e)+4}function l(t,e){let n=0;return t.forEach(function(t){const r=u(t.mode,e);n+=r+t.getBitsLength()}),n}t.from=function(t,e){return a.isValid(t)?parseInt(t,10):e},t.getCapacity=function(t,r,o){if(!a.isValid(t))throw new Error("Invalid QR Code version");void 0===o&&(o=i.BYTE);const s=8*(e.getSymbolTotalCodewords(t)-n.getTotalCodewordsCount(t,r));if(o===i.MIXED)return s;const c=s-u(o,t);switch(o){case i.NUMERIC:return Math.floor(c/10*3);case i.ALPHANUMERIC:return Math.floor(c/11*2);case i.KANJI:return Math.floor(c/13);case i.BYTE:default:return Math.floor(c/8)}},t.getBestVersionForData=function(e,n){let r;const a=o.from(n,o.M);if(Array.isArray(e)){if(e.length>1)return function(e,n){for(let r=1;r<=40;r++)if(l(e,r)<=t.getCapacity(r,n,i.MIXED))return r}(e,a);if(0===e.length)return 1;r=e[0]}else r=e;return function(e,n,r){for(let o=1;o<=40;o++)if(n<=t.getCapacity(o,r,e))return o}(r.mode,r.getLength(),a)},t.getEncodedBits=function(t){if(!a.isValid(t)||t<7)throw new Error("Invalid QR Code version");let n=t<<12;for(;e.getBCHDigit(n)-c>=0;)n^=7973<=0;)r^=1335<0&&(n=this.data.substr(e),r=parseInt(n,10),t.put(r,3*o+1))};var Y=K;const _=R,Q=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function j(t){this.mode=_.ALPHANUMERIC,this.data=t}j.getBitsLength=function(t){return 11*Math.floor(t/2)+t%2*6},j.prototype.getLength=function(){return this.data.length},j.prototype.getBitsLength=function(){return j.getBitsLength(this.data.length)},j.prototype.write=function(t){let e;for(e=0;e+2<=this.data.length;e+=2){let n=45*Q.indexOf(this.data[e]);n+=Q.indexOf(this.data[e+1]),t.put(n,11)}this.data.length%2&&t.put(Q.indexOf(this.data[e]),6)};var G=j;const O=R;function $(t){this.mode=O.BYTE,this.data="string"==typeof t?(new TextEncoder).encode(t):new Uint8Array(t)}$.getBitsLength=function(t){return 8*t},$.prototype.getLength=function(){return this.data.length},$.prototype.getBitsLength=function(){return $.getBitsLength(this.data.length)},$.prototype.write=function(t){for(let e=0,n=this.data.length;e=33088&&n<=40956)n-=33088;else{if(!(n>=57408&&n<=60351))throw new Error("Invalid SJIS character: "+this.data[e]+"\nMake sure your charset is UTF-8");n-=49472}n=192*(n>>>8&255)+(255&n),t.put(n,13)}};var tt,et=Z,nt={exports:{}};nt.exports=tt={single_source_shortest_paths:function(t,e,n){var r={},o={};o[e]=0;var i,a,s,c,u,l,d,g=tt.PriorityQueue.make();for(g.push(e,0);!g.empty();)for(s in a=(i=g.pop()).value,c=i.cost,u=t[a]||{})u.hasOwnProperty(s)&&(l=c+u[s],d=o[s],(void 0===o[s]||d>l)&&(o[s]=l,g.push(s,l),r[s]=a));if(void 0!==n&&void 0===o[n]){var h=["Could not find a path from ",e," to ",n,"."].join("");throw new Error(h)}return r},extract_shortest_path_from_predecessor_list:function(t,e){for(var n=[],r=e;r;)n.push(r),t[r],r=t[r];return n.reverse(),n},find_path:function(t,e,n){var r=tt.single_source_shortest_paths(t,e,n);return tt.extract_shortest_path_from_predecessor_list(r,n)},PriorityQueue:{make:function(t){var e,n=tt.PriorityQueue,r={};for(e in t=t||{},n)n.hasOwnProperty(e)&&(r[e]=n[e]);return r.queue=[],r.sorter=t.sorter||n.default_sorter,r},default_sorter:function(t,e){return t.cost-e.cost},push:function(t,e){var n={value:t,cost:e};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};var rt=nt.exports;!function(t){const e=R,n=Y,o=G,i=q,a=et,s=N,c=r,u=rt;function l(t){return unescape(encodeURIComponent(t)).length}function d(t,e,n){const r=[];let o;for(;null!==(o=t.exec(n));)r.push({data:o[0],index:o.index,mode:e,length:o[0].length});return r}function g(t){const n=d(s.NUMERIC,e.NUMERIC,t),r=d(s.ALPHANUMERIC,e.ALPHANUMERIC,t);let o,i;c.isKanjiModeEnabled()?(o=d(s.BYTE,e.BYTE,t),i=d(s.KANJI,e.KANJI,t)):(o=d(s.BYTE_KANJI,e.BYTE,t),i=[]);return n.concat(r,o,i).sort(function(t,e){return t.index-e.index}).map(function(t){return{data:t.data,mode:t.mode,length:t.length}})}function h(t,r){switch(r){case e.NUMERIC:return n.getBitsLength(t);case e.ALPHANUMERIC:return o.getBitsLength(t);case e.KANJI:return a.getBitsLength(t);case e.BYTE:return i.getBitsLength(t)}}function f(t,r){let s;const u=e.getBestModeForData(t);if(s=e.from(r,u),s!==e.BYTE&&s.bit=0?t[t.length-1]:null;return n&&n.mode===e.mode?(t[t.length-1].data+=e.data,t):(t.push(e),t)},[])}(s))},t.rawSplit=function(e){return t.fromArray(g(e,c.isKanjiModeEnabled()))}}(H);const ot=r,it=s,at=u,st=d,ct=g,ut=h,lt=m,dt=p,gt=M,ht=P,ft=k,mt=R,pt=H;function wt(t,e,n){const r=t.size,o=ft.getEncodedBits(e,n);let i,a;for(i=0;i<15;i++)a=1==(o>>i&1),i<6?t.set(i,8,a,!0):i<8?t.set(i+1,8,a,!0):t.set(r-15+i,8,a,!0),i<8?t.set(8,r-i-1,a,!0):i<9?t.set(8,15-i-1+1,a,!0):t.set(8,15-i-1,a,!0);t.set(r-8,8,1,!0)}function Et(t,e,n){const r=new at;n.forEach(function(e){r.put(e.mode.bit,4),r.put(e.getLength(),mt.getCharCountIndicator(e.mode,t)),e.write(r)});const o=8*(ot.getSymbolTotalCodewords(t)-dt.getTotalCodewordsCount(t,e));for(r.getLengthInBits()+4<=o&&r.put(0,4);r.getLengthInBits()%8!=0;)r.putBit(0);const i=(o-r.getLengthInBits())/8;for(let a=0;a=0&&r<=6&&(0===o||6===o)||o>=0&&o<=6&&(0===r||6===r)||r>=2&&r<=4&&o>=2&&o<=4?t.set(e+r,i+o,!0,!0):t.set(e+r,i+o,!1,!0))}}(c,e),function(t){const e=t.size;for(let n=8;n=7&&function(t,e){const n=t.size,r=ht.getEncodedBits(e);let o,i,a;for(let s=0;s<18;s++)o=Math.floor(s/3),i=s%3+n-8-3,a=1==(r>>s&1),t.set(o,i,a,!0),t.set(i,o,a,!0)}(c,e),function(t,e){const n=t.size;let r=-1,o=n-1,i=7,a=0;for(let s=n-1;s>0;s-=2)for(6===s&&s--;;){for(let n=0;n<2;n++)if(!t.isReserved(o,s-n)){let r=!1;a>>i&1)),t.set(o,s-n,r),i--,-1===i&&(a++,i=7)}if(o+=r,o<0||n<=o){o-=r,r=-r;break}}}(c,a),isNaN(r)&&(r=lt.getBestMask(c,wt.bind(null,c,n))),lt.applyMask(r,c),wt(c,n,r),{modules:c,version:e,errorCorrectionLevel:n,maskPattern:r,segments:o}}n.create=function(t,e){if(void 0===t||""===t)throw new Error("No input text");let n,r,o=it.M;return void 0!==e&&(o=it.from(e.errorCorrectionLevel,it.M),n=ht.from(e.version),r=lt.from(e.maskPattern),e.toSJISFunc&&ot.setToSJISFunction(e.toSJISFunc)),yt(t,n,o,r)};var vt={},At={};!function(t){function e(t){if("number"==typeof t&&(t=t.toString()),"string"!=typeof t)throw new Error("Color should be defined as hex string");let e=t.slice().replace("#","").split("");if(e.length<3||5===e.length||e.length>8)throw new Error("Invalid hex color: "+t);3!==e.length&&4!==e.length||(e=Array.prototype.concat.apply([],e.map(function(t){return[t,t]}))),6===e.length&&e.push("F","F");const n=parseInt(e.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:255&n,hex:"#"+e.slice(0,6).join("")}}t.getOptions=function(t){t||(t={}),t.color||(t.color={});const n=void 0===t.margin||null===t.margin||t.margin<0?4:t.margin,r=t.width&&t.width>=21?t.width:void 0,o=t.scale||4;return{width:r,scale:r?4:o,margin:n,color:{dark:e(t.color.dark||"#000000ff"),light:e(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}},t.getScale=function(t,e){return e.width&&e.width>=t+2*e.margin?e.width/(t+2*e.margin):e.scale},t.getImageWidth=function(e,n){const r=t.getScale(e,n);return Math.floor((e+2*n.margin)*r)},t.qrToImageData=function(e,n,r){const o=n.modules.size,i=n.modules.data,a=t.getScale(o,r),s=Math.floor((o+2*r.margin)*a),c=r.margin*a,u=[r.color.light,r.color.dark];for(let t=0;t=c&&n>=c&&t':"",c="0&&c>0&&t[s-1]||(r+=i?Bt("M",c+n,.5+u+n):Bt("m",o,0),o=0,i=!1),c+1',u='viewBox="0 0 '+a+" "+a+'"',l=''+s+c+"\n";return"function"==typeof n&&n(null,l),l};const Mt=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then},Pt=n,Rt=vt,Tt=Ct;function Nt(t,e,n,r,o){const i=[].slice.call(arguments,1),a=i.length,s="function"==typeof i[a-1];if(!s&&!Mt())throw new Error("Callback required as last argument");if(!s){if(a<1)throw new Error("Too few arguments provided");return 1===a?(n=e,e=r=void 0):2!==a||e.getContext||(r=n,n=e,e=void 0),new Promise(function(o,i){try{const i=Pt.create(n,r);o(t(i,e,r))}catch(a){i(a)}})}if(a<2)throw new Error("Too few arguments provided");2===a?(o=n,n=e,e=r=void 0):3===a&&(e.getContext&&void 0===o?(o=r,r=void 0):(o=r,r=n,n=e,e=void 0));try{const i=Pt.create(n,r);o(null,t(i,e,r))}catch(c){o(c)}}e.create=Pt.create,e.toCanvas=Nt.bind(null,Rt.render),e.toDataURL=Nt.bind(null,Rt.renderToDataURL),e.toString=Nt.bind(null,function(t,e,n){return Tt.render(t,n)});const Ft=async(t,n="#000000",r="#FFFFFF")=>{try{return await e.toString(t,{type:"svg",width:512,margin:2,errorCorrectionLevel:"H",color:{dark:n,light:r}})}catch(o){return console.error("Error generating SVG QR code:",o),null}},St=(t,e,n,r,o)=>new Promise(i=>{const a=document.createElement("canvas"),s=a.getContext("2d");a.width=t.width,a.height=t.height,s.drawImage(t,0,0);const c=s.getImageData(0,0,a.width,a.height),u=o.createElementNS("http://www.w3.org/2000/svg","g"),l=e/Math.max(t.width,t.height);u.setAttribute("transform",`translate(${n.toFixed(2)}, ${r.toFixed(2)}) scale(${l.toFixed(4)})`);const d=Math.max(1,Math.floor(Math.min(t.width,t.height)/32)),g=c.data;for(let e=0;e128&&(i>0||a>0||s>0)){const t=o.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("x",n.toFixed(2)),t.setAttribute("y",e.toFixed(2)),t.setAttribute("width",d.toFixed(2)),t.setAttribute("height",d.toFixed(2)),t.setAttribute("fill",`rgb(${i}, ${a}, ${s})`),u.appendChild(t)}}i(u)}),xt=async(t,e,n=20)=>new Promise(r=>{const o=new Image;o.onload=()=>{const i=(new DOMParser).parseFromString(t,"image/svg+xml"),a=i.documentElement,s=n/100*33,c=s+4,u=(33-c)/2,l=(33-c)/2,d=u+2,g=l+2,h=i.createElementNS("http://www.w3.org/2000/svg","rect");if(h.setAttribute("x",u.toFixed(2)),h.setAttribute("y",l.toFixed(2)),h.setAttribute("width",c.toFixed(2)),h.setAttribute("height",c.toFixed(2)),h.setAttribute("fill","#FFFFFF"),a.appendChild(h),e.startsWith("data:image/svg+xml")){console.log("Processing SVG image");const t=i.createElementNS("http://www.w3.org/2000/svg","image");t.setAttribute("x",d.toFixed(2)),t.setAttribute("y",g.toFixed(2)),t.setAttribute("width",s.toFixed(2)),t.setAttribute("height",s.toFixed(2)),t.setAttribute("href",e),a.appendChild(t),console.log("SVG image element added");const n=new XMLSerializer;r(n.serializeToString(a))}else console.log("Processing bitmap image"),St(o,s,d,g,i).then(t=>{a.appendChild(t),console.log("Vectorized image group added");const e=new XMLSerializer;r(e.serializeToString(a))}).catch(t=>{console.error("Vectorization failed:",t);const e=new XMLSerializer;r(e.serializeToString(a))})},o.onerror=()=>{console.error("Error loading image for SVG"),r(t)},o.src=e});return t.addImageToQRCode=async(t,e,n=20)=>new Promise(r=>{const o=document.createElement("canvas"),i=o.getContext("2d");o.width=512,o.height=512;const a=new Image,s=new Image;a.onload=()=>{i.drawImage(a,0,0,512,512),s.onload=()=>{const t=n/100*512,e=t+32,a=(512-e)/2,c=(512-e)/2;i.fillStyle="#FFFFFF",i.fillRect(a,c,e,e);const u=a+16,l=c+16;i.drawImage(s,u,l,t,t),r(o.toDataURL("image/png"))},s.onerror=()=>{console.error("Error loading custom image"),r(t)},s.src=e},a.onerror=()=>{console.error("Error loading QR code"),r(t)},a.src=t}),t.addImageToSVG=xt,t.downloadSVG=(t,e="qrcode.svg")=>{if(!t)return void console.error("No SVG content to download");const n=new Blob([t],{type:"image/svg+xml"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)},t.fileToDataURL=t=>new Promise((e,n)=>{const r=new FileReader;r.onload=()=>e(r.result),r.onerror=n,r.readAsDataURL(t)}),t.generateCompleteSVGQRCode=async(t,e=null,n=20,r="#000000",o="#FFFFFF")=>{try{const i=await Ft(t,r,o);if(!i)return null;if(e){console.log("Adding custom image to SVG...");const t=await xt(i,e,n);return console.log("SVG with image generated"),t}return i}catch(i){return console.error("Error generating complete SVG QR code:",i),null}},t.generateQRCode=async(t,n="#000000",r="#FFFFFF")=>{try{return await e.toDataURL(t,{color:{dark:n,light:r},width:512,margin:2,errorCorrectionLevel:"H"})}catch(o){return console.error("Error generating QR code:",o),null}},t.generateSVGQRCode=Ft,t.validateImageFile=(t,e=2097152)=>["image/jpeg","image/png","image/gif","image/webp","image/svg+xml"].includes(t.type)?t.size>e?{success:!1,error:`File size must be less than ${Math.round(e/1024/1024)}MB`}:{success:!0}:{success:!1,error:"Please select a valid image file (JPEG, PNG, GIF, WebP, or SVG)"},t.vectorizeBitmap=St,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({}); //# sourceMappingURL=qr-code-utils.iife.js.map