qrcodedemo/dist/qr-code-utils.umd.js
Michael Mainguy 874f3c4412 Add standalone bundle for qrCodeUtils with all dependencies
- Created vite.standalone.config.js for optimized bundle building
- Added build scripts for standalone bundle generation
- Generated three formats: IIFE (28KB), UMD (28KB), ES Module (61KB)
- Includes all dependencies: qrcode and imagetracer
- Added comprehensive documentation and examples
- Created build script with detailed bundle information
- Added terser for minification optimization
- Fixed package.json dependencies and scripts
2025-08-01 17:17:36 -05:00

3 lines
28 KiB
JavaScript

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).QRCodeUtils={})}(this,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 s,a={};function c(){this.buffer=[],this.length=0}(s=a).L={bit:1},s.M={bit:0},s.Q={bit:3},s.H={bit:2},s.isValid=function(t){return t&&void 0!==t.bit&&t.bit>=0&&t.bit<4},s.from=function(t,e){if(s.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 s.L;case"m":case"medium":return s.M;case"q":case"quartile":return s.Q;case"h":case"high":return s.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++)this.putBit(1==(t>>>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<n-1;e++)i[e]=i[e-1]-o;return i.push(6),i.reverse()},t.getPositions=function(e){const n=[],r=t.getRowColCoords(e),o=r.length;for(let t=0;t<o;t++)for(let e=0;e<o;e++)0===t&&0===e||0===t&&e===o-1||t===o-1&&0===e||n.push([r[t],r[e]]);return n}}(g);var h={};const f=r.getSymbolSize;h.getPositions=function(t){const e=f(t);return[[0,0],[e-7,0],[0,e-7]]};var p={};!function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const e=3,n=3,r=40,o=10;function i(e,n,r){switch(e){case t.Patterns.PATTERN000:return(n+r)%2==0;case t.Patterns.PATTERN001:return n%2==0;case t.Patterns.PATTERN010:return r%3==0;case t.Patterns.PATTERN011:return(n+r)%3==0;case t.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case t.Patterns.PATTERN101:return n*r%2+n*r%3==0;case t.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case t.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}}t.isValid=function(t){return null!=t&&""!==t&&!isNaN(t)&&t>=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,s=null,a=null;for(let c=0;c<n;c++){o=i=0,s=a=null;for(let u=0;u<n;u++){let n=t.get(c,u);n===s?o++:(o>=5&&(r+=e+(o-5)),s=n,o=1),n=t.get(u,c),n===a?i++:(i>=5&&(r+=e+(i-5)),a=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<e-1;n++)for(let o=0;o<e-1;o++){const e=t.get(n,o)+t.get(n,o+1)+t.get(n+1,o)+t.get(n+1,o+1);4!==e&&0!==e||r++}return r*n},t.getPenaltyN3=function(t){const e=t.size;let n=0,o=0,i=0;for(let r=0;r<e;r++){o=i=0;for(let s=0;s<e;s++)o=o<<1&2047|t.get(r,s),s>=10&&(1488===o||93===o)&&n++,i=i<<1&2047|t.get(s,r),s>=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<n;r++)e+=t.data[r];return Math.abs(Math.ceil(100*e/n/5)-10)*o},t.applyMask=function(t,e){const n=e.size;for(let r=0;r<n;r++)for(let o=0;o<n;o++)e.isReserved(o,r)||e.xor(o,r,i(t,o,r))},t.getBestMask=function(e,n){const r=Object.keys(t.Patterns).length;let o=0,i=1/0;for(let s=0;s<r;s++){n(s),t.applyMask(s,e);const r=t.getPenaltyN1(e)+t.getPenaltyN2(e)+t.getPenaltyN3(e)+t.getPenaltyN4(e);t.applyMask(s,e),r<i&&(i=r,o=s)}return o}}(p);var m={};const w=a,y=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],E=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];m.getBlocksCount=function(t,e){switch(e){case w.L:return y[4*(t-1)+0];case w.M:return y[4*(t-1)+1];case w.Q:return y[4*(t-1)+2];case w.H:return y[4*(t-1)+3];default:return}},m.getTotalCodewordsCount=function(t,e){switch(e){case w.L:return E[4*(t-1)+0];case w.M:return E[4*(t-1)+1];case w.Q:return E[4*(t-1)+2];case w.H:return E[4*(t-1)+3];default:return}};var v={},A={};const C=new Uint8Array(512),b=new Uint8Array(256);!function(){let t=1;for(let e=0;e<255;e++)C[e]=t,b[t]=e,t<<=1,256&t&&(t^=285);for(let e=255;e<512;e++)C[e]=C[e-255]}(),A.log=function(t){if(t<1)throw new Error("log("+t+")");return b[t]},A.exp=function(t){return C[t]},A.mul=function(t,e){return 0===t||0===e?0:C[b[t]+b[e]]},function(t){const e=A;t.mul=function(t,n){const r=new Uint8Array(t.length+n.length-1);for(let o=0;o<t.length;o++)for(let i=0;i<n.length;i++)r[o+i]^=e.mul(t[o],n[i]);return r},t.mod=function(t,n){let r=new Uint8Array(t);for(;r.length-n.length>=0;){const t=r[0];for(let i=0;i<n.length;i++)r[i]^=e.mul(n[i],t);let o=0;for(;o<r.length&&0===r[o];)o++;r=r.slice(o)}return r},t.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let o=0;o<n;o++)r=t.mul(r,new Uint8Array([1,e.exp(o)]));return r}}(v);const I=v;function B(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}B.prototype.initialize=function(t){this.degree=t,this.genPoly=I.generateECPolynomial(this.degree)},B.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");const e=new Uint8Array(t.length+this.degree);e.set(t);const n=I.mod(e,this.genPoly),r=this.degree-n.length;if(r>0){const t=new Uint8Array(this.degree);return t.set(n,r),t}return n};var M=B,P={},T={},R={isValid:function(t){return!isNaN(t)&&t>=1&&t<=40}},N={};const F="[0-9]+";let x="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";x=x.replace(/u/g,"\\u");const S="(?:(?![A-Z0-9 $%*+\\-./:]|"+x+")(?:.|[\r\n]))+";N.KANJI=new RegExp(x,"g"),N.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),N.BYTE=new RegExp(S,"g"),N.NUMERIC=new RegExp(F,"g"),N.ALPHANUMERIC=new RegExp("[A-Z $%*+\\-./:]+","g");const L=new RegExp("^"+x+"$"),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=R,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}}}(T),function(t){const e=r,n=m,o=a,i=T,s=R,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 s.isValid(t)?parseInt(t,10):e},t.getCapacity=function(t,r,o){if(!s.isValid(t))throw new Error("Invalid QR Code version");void 0===o&&(o=i.BYTE);const a=8*(e.getSymbolTotalCodewords(t)-n.getTotalCodewordsCount(t,r));if(o===i.MIXED)return a;const c=a-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 s=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,s);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(),s)},t.getEncodedBits=function(t){if(!s.isValid(t)||t<7)throw new Error("Invalid QR Code version");let n=t<<12;for(;e.getBCHDigit(n)-c>=0;)n^=7973<<e.getBCHDigit(n)-c;return t<<12|n}}(P);var k={};const D=r,V=D.getBCHDigit(1335);k.getEncodedBits=function(t,e){const n=t.bit<<3|e;let r=n<<10;for(;D.getBCHDigit(r)-V>=0;)r^=1335<<D.getBCHDigit(r)-V;return 21522^(n<<10|r)};var H={};const J=T;function K(t){this.mode=J.NUMERIC,this.data=t.toString()}K.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)},K.prototype.getLength=function(){return this.data.length},K.prototype.getBitsLength=function(){return K.getBitsLength(this.data.length)},K.prototype.write=function(t){let e,n,r;for(e=0;e+3<=this.data.length;e+=3)n=this.data.substr(e,3),r=parseInt(n,10),t.put(r,10);const o=this.data.length-e;o>0&&(n=this.data.substr(e),r=parseInt(n,10),t.put(r,3*o+1))};var Y=K;const _=T,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=T;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<n;e++)t.put(this.data[e],8)};var q=$;const X=T,W=r;function Z(t){this.mode=X.KANJI,this.data=t}Z.getBitsLength=function(t){return 13*t},Z.prototype.getLength=function(){return this.data.length},Z.prototype.getBitsLength=function(){return Z.getBitsLength(this.data.length)},Z.prototype.write=function(t){let e;for(e=0;e<this.data.length;e++){let n=W.toSJIS(this.data[e]);if(n>=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,s,a,c,u,l,d,g=tt.PriorityQueue.make();for(g.push(e,0);!g.empty();)for(a in s=(i=g.pop()).value,c=i.cost,u=t[s]||{})u.hasOwnProperty(a)&&(l=c+u[a],d=o[a],(void 0===o[a]||d>l)&&(o[a]=l,g.push(a,l),r[a]=s));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=T,n=Y,o=G,i=q,s=et,a=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(a.NUMERIC,e.NUMERIC,t),r=d(a.ALPHANUMERIC,e.ALPHANUMERIC,t);let o,i;c.isKanjiModeEnabled()?(o=d(a.BYTE,e.BYTE,t),i=d(a.KANJI,e.KANJI,t)):(o=d(a.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 s.getBitsLength(t);case e.BYTE:return i.getBitsLength(t)}}function f(t,r){let a;const u=e.getBestModeForData(t);if(a=e.from(r,u),a!==e.BYTE&&a.bit<u.bit)throw new Error('"'+t+'" cannot be encoded with mode '+e.toString(a)+".\n Suggested mode is: "+e.toString(u));switch(a!==e.KANJI||c.isKanjiModeEnabled()||(a=e.BYTE),a){case e.NUMERIC:return new n(t);case e.ALPHANUMERIC:return new o(t);case e.KANJI:return new s(t);case e.BYTE:return new i(t)}}t.fromArray=function(t){return t.reduce(function(t,e){return"string"==typeof e?t.push(f(e,null)):e.data&&t.push(f(e.data,e.mode)),t},[])},t.fromString=function(n,r){const o=function(t){const n=[];for(let r=0;r<t.length;r++){const o=t[r];switch(o.mode){case e.NUMERIC:n.push([o,{data:o.data,mode:e.ALPHANUMERIC,length:o.length},{data:o.data,mode:e.BYTE,length:o.length}]);break;case e.ALPHANUMERIC:n.push([o,{data:o.data,mode:e.BYTE,length:o.length}]);break;case e.KANJI:n.push([o,{data:o.data,mode:e.BYTE,length:l(o.data)}]);break;case e.BYTE:n.push([{data:o.data,mode:e.BYTE,length:l(o.data)}])}}return n}(g(n,c.isKanjiModeEnabled())),i=function(t,n){const r={},o={start:{}};let i=["start"];for(let s=0;s<t.length;s++){const a=t[s],c=[];for(let t=0;t<a.length;t++){const u=a[t],l=""+s+t;c.push(l),r[l]={node:u,lastCount:0},o[l]={};for(let t=0;t<i.length;t++){const s=i[t];r[s]&&r[s].node.mode===u.mode?(o[s][l]=h(r[s].lastCount+u.length,u.mode)-h(r[s].lastCount,u.mode),r[s].lastCount+=u.length):(r[s]&&(r[s].lastCount=u.length),o[s][l]=h(u.length,u.mode)+4+e.getCharCountIndicator(u.mode,n))}}i=c}for(let e=0;e<i.length;e++)o[i[e]].end=0;return{map:o,table:r}}(o,r),s=u.find_path(i.map,"start","end"),a=[];for(let t=1;t<s.length-1;t++)a.push(i.table[s[t]].node);return t.fromArray(function(t){return t.reduce(function(t,e){const n=t.length-1>=0?t[t.length-1]:null;return n&&n.mode===e.mode?(t[t.length-1].data+=e.data,t):(t.push(e),t)},[])}(a))},t.rawSplit=function(e){return t.fromArray(g(e,c.isKanjiModeEnabled()))}}(H);const ot=r,it=a,st=u,at=d,ct=g,ut=h,lt=p,dt=m,gt=M,ht=P,ft=k,pt=T,mt=H;function wt(t,e,n){const r=t.size,o=ft.getEncodedBits(e,n);let i,s;for(i=0;i<15;i++)s=1==(o>>i&1),i<6?t.set(i,8,s,!0):i<8?t.set(i+1,8,s,!0):t.set(r-15+i,8,s,!0),i<8?t.set(8,r-i-1,s,!0):i<9?t.set(8,15-i-1+1,s,!0):t.set(8,15-i-1,s,!0);t.set(r-8,8,1,!0)}function yt(t,e,n){const r=new st;n.forEach(function(e){r.put(e.mode.bit,4),r.put(e.getLength(),pt.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 s=0;s<i;s++)r.put(s%2?17:236,8);return function(t,e,n){const r=ot.getSymbolTotalCodewords(e),o=dt.getTotalCodewordsCount(e,n),i=r-o,s=dt.getBlocksCount(e,n),a=r%s,c=s-a,u=Math.floor(r/s),l=Math.floor(i/s),d=l+1,g=u-l,h=new gt(g);let f=0;const p=new Array(s),m=new Array(s);let w=0;const y=new Uint8Array(t.buffer);for(let b=0;b<s;b++){const t=b<c?l:d;p[b]=y.slice(f,f+t),m[b]=h.encode(p[b]),f+=t,w=Math.max(w,t)}const E=new Uint8Array(r);let v,A,C=0;for(v=0;v<w;v++)for(A=0;A<s;A++)v<p[A].length&&(E[C++]=p[A][v]);for(v=0;v<g;v++)for(A=0;A<s;A++)E[C++]=m[A][v];return E}(r,t,e)}function Et(t,e,n,r){let o;if(Array.isArray(t))o=mt.fromArray(t);else{if("string"!=typeof t)throw new Error("Invalid data");{let r=e;if(!r){const e=mt.rawSplit(t);r=ht.getBestVersionForData(e,n)}o=mt.fromString(t,r||40)}}const i=ht.getBestVersionForData(o,n);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(e){if(e<i)throw new Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+i+".\n")}else e=i;const s=yt(e,n,o),a=ot.getSymbolSize(e),c=new at(a);return function(t,e){const n=t.size,r=ut.getPositions(e);for(let o=0;o<r.length;o++){const e=r[o][0],i=r[o][1];for(let r=-1;r<=7;r++)if(!(e+r<=-1||n<=e+r))for(let o=-1;o<=7;o++)i+o<=-1||n<=i+o||(r>=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<e-8;n++){const e=n%2==0;t.set(n,6,e,!0),t.set(6,n,e,!0)}}(c),function(t,e){const n=ct.getPositions(e);for(let r=0;r<n.length;r++){const e=n[r][0],o=n[r][1];for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)-2===n||2===n||-2===r||2===r||0===n&&0===r?t.set(e+n,o+r,!0,!0):t.set(e+n,o+r,!1,!0)}}(c,e),wt(c,n,0),e>=7&&function(t,e){const n=t.size,r=ht.getEncodedBits(e);let o,i,s;for(let a=0;a<18;a++)o=Math.floor(a/3),i=a%3+n-8-3,s=1==(r>>a&1),t.set(o,i,s,!0),t.set(i,o,s,!0)}(c,e),function(t,e){const n=t.size;let r=-1,o=n-1,i=7,s=0;for(let a=n-1;a>0;a-=2)for(6===a&&a--;;){for(let n=0;n<2;n++)if(!t.isReserved(o,a-n)){let r=!1;s<e.length&&(r=1==(e[s]>>>i&1)),t.set(o,a-n,r),i--,-1===i&&(s++,i=7)}if(o+=r,o<0||n<=o){o-=r,r=-r;break}}}(c,s),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)),Et(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,s=t.getScale(o,r),a=Math.floor((o+2*r.margin)*s),c=r.margin*s,u=[r.color.light,r.color.dark];for(let t=0;t<a;t++)for(let n=0;n<a;n++){let l=4*(t*a+n),d=r.color.light;if(t>=c&&n>=c&&t<a-c&&n<a-c){d=u[i[Math.floor((t-c)/s)*o+Math.floor((n-c)/s)]?1:0]}e[l++]=d.r,e[l++]=d.g,e[l++]=d.b,e[l]=d.a}}}(At),function(t){const e=At;t.render=function(t,n,r){let o=r,i=n;void 0!==o||n&&n.getContext||(o=n,n=void 0),n||(i=function(){try{return document.createElement("canvas")}catch(t){throw new Error("You need to specify a canvas element")}}()),o=e.getOptions(o);const s=e.getImageWidth(t.modules.size,o),a=i.getContext("2d"),c=a.createImageData(s,s);return e.qrToImageData(c.data,t,o),function(t,e,n){t.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=n,e.width=n,e.style.height=n+"px",e.style.width=n+"px"}(a,i,s),a.putImageData(c,0,0),i},t.renderToDataURL=function(e,n,r){let o=r;void 0!==o||n&&n.getContext||(o=n,n=void 0),o||(o={});const i=t.render(e,n,o),s=o.type||"image/png",a=o.rendererOpts||{};return i.toDataURL(s,a.quality)}}(vt);var Ct={};const bt=At;function It(t,e){const n=t.a/255,r=e+'="'+t.hex+'"';return n<1?r+" "+e+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function Bt(t,e,n){let r=t+e;return void 0!==n&&(r+=" "+n),r}Ct.render=function(t,e,n){const r=bt.getOptions(e),o=t.modules.size,i=t.modules.data,s=o+2*r.margin,a=r.color.light.a?"<path "+It(r.color.light,"fill")+' d="M0 0h'+s+"v"+s+'H0z"/>':"",c="<path "+It(r.color.dark,"stroke")+' d="'+function(t,e,n){let r="",o=0,i=!1,s=0;for(let a=0;a<t.length;a++){const c=Math.floor(a%e),u=Math.floor(a/e);c||i||(i=!0),t[a]?(s++,a>0&&c>0&&t[a-1]||(r+=i?Bt("M",c+n,.5+u+n):Bt("m",o,0),o=0,i=!1),c+1<e&&t[a+1]||(r+=Bt("h",s),s=0)):o++}return r}(i,o,r.margin)+'"/>',u='viewBox="0 0 '+s+" "+s+'"',l='<svg xmlns="http://www.w3.org/2000/svg" '+(r.width?'width="'+r.width+'" height="'+r.width+'" ':"")+u+' shape-rendering="crispEdges">'+a+c+"</svg>\n";return"function"==typeof n&&n(null,l),l};const Mt=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then},Pt=n,Tt=vt,Rt=Ct;function Nt(t,e,n,r,o){const i=[].slice.call(arguments,1),s=i.length,a="function"==typeof i[s-1];if(!a&&!Mt())throw new Error("Callback required as last argument");if(!a){if(s<1)throw new Error("Too few arguments provided");return 1===s?(n=e,e=r=void 0):2!==s||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(s){i(s)}})}if(s<2)throw new Error("Too few arguments provided");2===s?(o=n,n=e,e=r=void 0):3===s&&(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,Tt.render),e.toDataURL=Nt.bind(null,Tt.renderToDataURL),e.toString=Nt.bind(null,function(t,e,n){return Rt.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}},xt=(t,e,n,r,o)=>new Promise(i=>{const s=document.createElement("canvas"),a=s.getContext("2d");s.width=t.width,s.height=t.height,a.drawImage(t,0,0);const c=a.getImageData(0,0,s.width,s.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;e<t.height;e+=d)for(let n=0;n<t.width;n+=d){const r=4*(e*t.width+n),i=g[r],s=g[r+1],a=g[r+2];if(g[r+3]>128&&(i>0||s>0||a>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}, ${s}, ${a})`),u.appendChild(t)}}i(u)}),St=async(t,e,n=20)=>new Promise(r=>{const o=new Image;o.onload=()=>{const i=(new DOMParser).parseFromString(t,"image/svg+xml"),s=i.documentElement,a=n/100*33,c=a+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"),s.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",a.toFixed(2)),t.setAttribute("height",a.toFixed(2)),t.setAttribute("href",e),s.appendChild(t),console.log("SVG image element added");const n=new XMLSerializer;r(n.serializeToString(s))}else console.log("Processing bitmap image"),xt(o,a,d,g,i).then(t=>{s.appendChild(t),console.log("Vectorized image group added");const e=new XMLSerializer;r(e.serializeToString(s))}).catch(t=>{console.error("Vectorization failed:",t);const e=new XMLSerializer;r(e.serializeToString(s))})},o.onerror=()=>{console.error("Error loading image for SVG"),r(t)},o.src=e});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 s=new Image,a=new Image;s.onload=()=>{i.drawImage(s,0,0,512,512),a.onload=()=>{const t=n/100*512,e=t+32,s=(512-e)/2,c=(512-e)/2;i.fillStyle="#FFFFFF",i.fillRect(s,c,e,e);const u=s+16,l=c+16;i.drawImage(a,u,l,t,t),r(o.toDataURL("image/png"))},a.onerror=()=>{console.error("Error loading custom image"),r(t)},a.src=e},s.onerror=()=>{console.error("Error loading QR code"),r(t)},s.src=t}),t.addImageToSVG=St,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 St(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=xt,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=qr-code-utils.umd.js.map