@qr-styled/browser 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +7 -7
- package/dist/bundle.js.map +3 -3
- package/dist/lib/renderers/ModuleRenderer.d.ts +8 -0
- package/dist/lib/renderers/ModuleRenderer.js +83 -4
- package/dist/lib/renderers/SVGRenderer.d.ts +4 -0
- package/dist/lib/renderers/SVGRenderer.js +34 -1
- package/dist/lib/utils/types.d.ts +7 -0
- package/dist/lib/utils/types.js +6 -1
- package/dist/lib/utils/validators.js +4 -1
- package/package.json +2 -2
package/dist/bundle.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
]))+`;M.KANJI=new RegExp(
|
|
3
|
-
Make sure your charset is UTF-8`);t=(t>>>8&255)*192+(t&255),n.put(t,13)}};
|
|
4
|
-
Suggested mode is: `+m.toString(r));switch(t===m.KANJI&&!se.isKanjiModeEnabled()&&(t=m.BYTE),t){case m.NUMERIC:return new
|
|
1
|
+
var tn=Object.create;var Ge=Object.defineProperty;var nn=Object.getOwnPropertyDescriptor;var rn=Object.getOwnPropertyNames;var on=Object.getPrototypeOf,sn=Object.prototype.hasOwnProperty;var w=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var an=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of rn(e))!sn.call(n,o)&&o!==t&&Ge(n,o,{get:()=>e[o],enumerable:!(r=nn(e,o))||r.enumerable});return n};var un=(n,e,t)=>(t=n!=null?tn(on(n)):{},an(e||!n||!n.__esModule?Ge(t,"default",{value:n,enumerable:!0}):t,n));var Ye=w((sr,je)=>{je.exports=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}});var P=w(v=>{var me,ln=[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];v.getSymbolSize=function(e){if(!e)throw new Error('"version" cannot be null or undefined');if(e<1||e>40)throw new Error('"version" should be in range from 1 to 40');return e*4+17};v.getSymbolTotalCodewords=function(e){return ln[e]};v.getBCHDigit=function(n){let e=0;for(;n!==0;)e++,n>>>=1;return e};v.setToSJISFunction=function(e){if(typeof e!="function")throw new Error('"toSJISFunc" is not a valid function.');me=e};v.isKanjiModeEnabled=function(){return typeof me<"u"};v.toSJIS=function(e){return me(e)}});var Z=w(x=>{x.L={bit:1};x.M={bit:0};x.Q={bit:3};x.H={bit:2};function cn(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return x.L;case"m":case"medium":return x.M;case"q":case"quartile":return x.Q;case"h":case"high":return x.H;default:throw new Error("Unknown EC Level: "+n)}}x.isValid=function(e){return e&&typeof e.bit<"u"&&e.bit>=0&&e.bit<4};x.from=function(e,t){if(x.isValid(e))return e;try{return cn(e)}catch{return t}}});var We=w((lr,Je)=>{function Ke(){this.buffer=[],this.length=0}Ke.prototype={get:function(n){let e=Math.floor(n/8);return(this.buffer[e]>>>7-n%8&1)===1},put:function(n,e){for(let t=0;t<e;t++)this.putBit((n>>>e-t-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(n){let e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),n&&(this.buffer[e]|=128>>>this.length%8),this.length++}};Je.exports=Ke});var Ze=w((cr,Xe)=>{function z(n){if(!n||n<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=n,this.data=new Uint8Array(n*n),this.reservedBit=new Uint8Array(n*n)}z.prototype.set=function(n,e,t,r){let o=n*this.size+e;this.data[o]=t,r&&(this.reservedBit[o]=!0)};z.prototype.get=function(n,e){return this.data[n*this.size+e]};z.prototype.xor=function(n,e,t){this.data[n*this.size+e]^=t};z.prototype.isReserved=function(n,e){return this.reservedBit[n*this.size+e]};Xe.exports=z});var et=w(ee=>{var dn=P().getSymbolSize;ee.getRowColCoords=function(e){if(e===1)return[];let t=Math.floor(e/7)+2,r=dn(e),o=r===145?26:Math.ceil((r-13)/(2*t-2))*2,i=[r-7];for(let s=1;s<t-1;s++)i[s]=i[s-1]-o;return i.push(6),i.reverse()};ee.getPositions=function(e){let t=[],r=ee.getRowColCoords(e),o=r.length;for(let i=0;i<o;i++)for(let s=0;s<o;s++)i===0&&s===0||i===0&&s===o-1||i===o-1&&s===0||t.push([r[i],r[s]]);return t}});var rt=w(nt=>{var fn=P().getSymbolSize,tt=7;nt.getPositions=function(e){let t=fn(e);return[[0,0],[t-tt,0],[0,t-tt]]}});var ot=w(y=>{y.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var q={N1:3,N2:3,N3:40,N4:10};y.isValid=function(e){return e!=null&&e!==""&&!isNaN(e)&&e>=0&&e<=7};y.from=function(e){return y.isValid(e)?parseInt(e,10):void 0};y.getPenaltyN1=function(e){let t=e.size,r=0,o=0,i=0,s=null,a=null;for(let u=0;u<t;u++){o=i=0,s=a=null;for(let l=0;l<t;l++){let c=e.get(u,l);c===s?o++:(o>=5&&(r+=q.N1+(o-5)),s=c,o=1),c=e.get(l,u),c===a?i++:(i>=5&&(r+=q.N1+(i-5)),a=c,i=1)}o>=5&&(r+=q.N1+(o-5)),i>=5&&(r+=q.N1+(i-5))}return r};y.getPenaltyN2=function(e){let t=e.size,r=0;for(let o=0;o<t-1;o++)for(let i=0;i<t-1;i++){let s=e.get(o,i)+e.get(o,i+1)+e.get(o+1,i)+e.get(o+1,i+1);(s===4||s===0)&&r++}return r*q.N2};y.getPenaltyN3=function(e){let t=e.size,r=0,o=0,i=0;for(let s=0;s<t;s++){o=i=0;for(let a=0;a<t;a++)o=o<<1&2047|e.get(s,a),a>=10&&(o===1488||o===93)&&r++,i=i<<1&2047|e.get(a,s),a>=10&&(i===1488||i===93)&&r++}return r*q.N3};y.getPenaltyN4=function(e){let t=0,r=e.data.length;for(let i=0;i<r;i++)t+=e.data[i];return Math.abs(Math.ceil(t*100/r/5)-10)*q.N4};function gn(n,e,t){switch(n){case y.Patterns.PATTERN000:return(e+t)%2===0;case y.Patterns.PATTERN001:return e%2===0;case y.Patterns.PATTERN010:return t%3===0;case y.Patterns.PATTERN011:return(e+t)%3===0;case y.Patterns.PATTERN100:return(Math.floor(e/2)+Math.floor(t/3))%2===0;case y.Patterns.PATTERN101:return e*t%2+e*t%3===0;case y.Patterns.PATTERN110:return(e*t%2+e*t%3)%2===0;case y.Patterns.PATTERN111:return(e*t%3+(e+t)%2)%2===0;default:throw new Error("bad maskPattern:"+n)}}y.applyMask=function(e,t){let r=t.size;for(let o=0;o<r;o++)for(let i=0;i<r;i++)t.isReserved(i,o)||t.xor(i,o,gn(e,i,o))};y.getBestMask=function(e,t){let r=Object.keys(y.Patterns).length,o=0,i=1/0;for(let s=0;s<r;s++){t(s),y.applyMask(s,e);let a=y.getPenaltyN1(e)+y.getPenaltyN2(e)+y.getPenaltyN3(e)+y.getPenaltyN4(e);y.applyMask(s,e),a<i&&(i=a,o=s)}return o}});var ye=w(we=>{var A=Z(),te=[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],ne=[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];we.getBlocksCount=function(e,t){switch(t){case A.L:return te[(e-1)*4+0];case A.M:return te[(e-1)*4+1];case A.Q:return te[(e-1)*4+2];case A.H:return te[(e-1)*4+3];default:return}};we.getTotalCodewordsCount=function(e,t){switch(t){case A.L:return ne[(e-1)*4+0];case A.M:return ne[(e-1)*4+1];case A.Q:return ne[(e-1)*4+2];case A.H:return ne[(e-1)*4+3];default:return}}});var it=w(oe=>{var G=new Uint8Array(512),re=new Uint8Array(256);(function(){let e=1;for(let t=0;t<255;t++)G[t]=e,re[e]=t,e<<=1,e&256&&(e^=285);for(let t=255;t<512;t++)G[t]=G[t-255]})();oe.log=function(e){if(e<1)throw new Error("log("+e+")");return re[e]};oe.exp=function(e){return G[e]};oe.mul=function(e,t){return e===0||t===0?0:G[re[e]+re[t]]}});var st=w(j=>{var Ce=it();j.mul=function(e,t){let r=new Uint8Array(e.length+t.length-1);for(let o=0;o<e.length;o++)for(let i=0;i<t.length;i++)r[o+i]^=Ce.mul(e[o],t[i]);return r};j.mod=function(e,t){let r=new Uint8Array(e);for(;r.length-t.length>=0;){let o=r[0];for(let s=0;s<t.length;s++)r[s]^=Ce.mul(t[s],o);let i=0;for(;i<r.length&&r[i]===0;)i++;r=r.slice(i)}return r};j.generateECPolynomial=function(e){let t=new Uint8Array([1]);for(let r=0;r<e;r++)t=j.mul(t,new Uint8Array([1,Ce.exp(r)]));return t}});var lt=w((wr,ut)=>{var at=st();function Ee(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}Ee.prototype.initialize=function(e){this.degree=e,this.genPoly=at.generateECPolynomial(this.degree)};Ee.prototype.encode=function(e){if(!this.genPoly)throw new Error("Encoder not initialized");let t=new Uint8Array(e.length+this.degree);t.set(e);let r=at.mod(t,this.genPoly),o=this.degree-r.length;if(o>0){let i=new Uint8Array(this.degree);return i.set(r,o),i}return r};ut.exports=Ee});var Re=w(ct=>{ct.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}});var be=w(M=>{var dt="[0-9]+",hn="[A-Z $%*+\\-./:]+",Y="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Y=Y.replace(/u/g,"\\u");var pn="(?:(?![A-Z0-9 $%*+\\-./:]|"+Y+`)(?:.|[\r
|
|
2
|
+
]))+`;M.KANJI=new RegExp(Y,"g");M.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");M.BYTE=new RegExp(pn,"g");M.NUMERIC=new RegExp(dt,"g");M.ALPHANUMERIC=new RegExp(hn,"g");var mn=new RegExp("^"+Y+"$"),wn=new RegExp("^"+dt+"$"),yn=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");M.testKanji=function(e){return mn.test(e)};M.testNumeric=function(e){return wn.test(e)};M.testAlphanumeric=function(e){return yn.test(e)}});var L=w(C=>{var Cn=Re(),Te=be();C.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]};C.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]};C.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]};C.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]};C.MIXED={bit:-1};C.getCharCountIndicator=function(e,t){if(!e.ccBits)throw new Error("Invalid mode: "+e);if(!Cn.isValid(t))throw new Error("Invalid version: "+t);return t>=1&&t<10?e.ccBits[0]:t<27?e.ccBits[1]:e.ccBits[2]};C.getBestModeForData=function(e){return Te.testNumeric(e)?C.NUMERIC:Te.testAlphanumeric(e)?C.ALPHANUMERIC:Te.testKanji(e)?C.KANJI:C.BYTE};C.toString=function(e){if(e&&e.id)return e.id;throw new Error("Invalid mode")};C.isValid=function(e){return e&&e.bit&&e.ccBits};function En(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"numeric":return C.NUMERIC;case"alphanumeric":return C.ALPHANUMERIC;case"kanji":return C.KANJI;case"byte":return C.BYTE;default:throw new Error("Unknown mode: "+n)}}C.from=function(e,t){if(C.isValid(e))return e;try{return En(e)}catch{return t}}});var mt=w(O=>{var ie=P(),Rn=ye(),ft=Z(),I=L(),Se=Re(),ht=7973,gt=ie.getBCHDigit(ht);function bn(n,e,t){for(let r=1;r<=40;r++)if(e<=O.getCapacity(r,t,n))return r}function pt(n,e){return I.getCharCountIndicator(n,e)+4}function Tn(n,e){let t=0;return n.forEach(function(r){let o=pt(r.mode,e);t+=o+r.getBitsLength()}),t}function Sn(n,e){for(let t=1;t<=40;t++)if(Tn(n,t)<=O.getCapacity(t,e,I.MIXED))return t}O.from=function(e,t){return Se.isValid(e)?parseInt(e,10):t};O.getCapacity=function(e,t,r){if(!Se.isValid(e))throw new Error("Invalid QR Code version");typeof r>"u"&&(r=I.BYTE);let o=ie.getSymbolTotalCodewords(e),i=Rn.getTotalCodewordsCount(e,t),s=(o-i)*8;if(r===I.MIXED)return s;let a=s-pt(r,e);switch(r){case I.NUMERIC:return Math.floor(a/10*3);case I.ALPHANUMERIC:return Math.floor(a/11*2);case I.KANJI:return Math.floor(a/13);case I.BYTE:default:return Math.floor(a/8)}};O.getBestVersionForData=function(e,t){let r,o=ft.from(t,ft.M);if(Array.isArray(e)){if(e.length>1)return Sn(e,o);if(e.length===0)return 1;r=e[0]}else r=e;return bn(r.mode,r.getLength(),o)};O.getEncodedBits=function(e){if(!Se.isValid(e)||e<7)throw new Error("Invalid QR Code version");let t=e<<12;for(;ie.getBCHDigit(t)-gt>=0;)t^=ht<<ie.getBCHDigit(t)-gt;return e<<12|t}});var Et=w(Ct=>{var xe=P(),yt=1335,xn=21522,wt=xe.getBCHDigit(yt);Ct.getEncodedBits=function(e,t){let r=e.bit<<3|t,o=r<<10;for(;xe.getBCHDigit(o)-wt>=0;)o^=yt<<xe.getBCHDigit(o)-wt;return(r<<10|o)^xn}});var bt=w((Tr,Rt)=>{var Bn=L();function $(n){this.mode=Bn.NUMERIC,this.data=n.toString()}$.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)};$.prototype.getLength=function(){return this.data.length};$.prototype.getBitsLength=function(){return $.getBitsLength(this.data.length)};$.prototype.write=function(e){let t,r,o;for(t=0;t+3<=this.data.length;t+=3)r=this.data.substr(t,3),o=parseInt(r,10),e.put(o,10);let i=this.data.length-t;i>0&&(r=this.data.substr(t),o=parseInt(r,10),e.put(o,i*3+1))};Rt.exports=$});var St=w((Sr,Tt)=>{var Mn=L(),Be=["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 U(n){this.mode=Mn.ALPHANUMERIC,this.data=n}U.getBitsLength=function(e){return 11*Math.floor(e/2)+6*(e%2)};U.prototype.getLength=function(){return this.data.length};U.prototype.getBitsLength=function(){return U.getBitsLength(this.data.length)};U.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let r=Be.indexOf(this.data[t])*45;r+=Be.indexOf(this.data[t+1]),e.put(r,11)}this.data.length%2&&e.put(Be.indexOf(this.data[t]),6)};Tt.exports=U});var Bt=w((xr,xt)=>{var Pn=L();function Q(n){this.mode=Pn.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}Q.getBitsLength=function(e){return e*8};Q.prototype.getLength=function(){return this.data.length};Q.prototype.getBitsLength=function(){return Q.getBitsLength(this.data.length)};Q.prototype.write=function(n){for(let e=0,t=this.data.length;e<t;e++)n.put(this.data[e],8)};xt.exports=Q});var Pt=w((Br,Mt)=>{var An=L(),Ln=P();function k(n){this.mode=An.KANJI,this.data=n}k.getBitsLength=function(e){return e*13};k.prototype.getLength=function(){return this.data.length};k.prototype.getBitsLength=function(){return k.getBitsLength(this.data.length)};k.prototype.write=function(n){let e;for(e=0;e<this.data.length;e++){let t=Ln.toSJIS(this.data[e]);if(t>=33088&&t<=40956)t-=33088;else if(t>=57408&&t<=60351)t-=49472;else throw new Error("Invalid SJIS character: "+this.data[e]+`
|
|
3
|
+
Make sure your charset is UTF-8`);t=(t>>>8&255)*192+(t&255),n.put(t,13)}};Mt.exports=k});var At=w((Mr,Me)=>{"use strict";var K={single_source_shortest_paths:function(n,e,t){var r={},o={};o[e]=0;var i=K.PriorityQueue.make();i.push(e,0);for(var s,a,u,l,c,f,d,g,p;!i.empty();){s=i.pop(),a=s.value,l=s.cost,c=n[a]||{};for(u in c)c.hasOwnProperty(u)&&(f=c[u],d=l+f,g=o[u],p=typeof o[u]>"u",(p||g>d)&&(o[u]=d,i.push(u,d),r[u]=a))}if(typeof t<"u"&&typeof o[t]>"u"){var h=["Could not find a path from ",e," to ",t,"."].join("");throw new Error(h)}return r},extract_shortest_path_from_predecessor_list:function(n,e){for(var t=[],r=e,o;r;)t.push(r),o=n[r],r=n[r];return t.reverse(),t},find_path:function(n,e,t){var r=K.single_source_shortest_paths(n,e,t);return K.extract_shortest_path_from_predecessor_list(r,t)},PriorityQueue:{make:function(n){var e=K.PriorityQueue,t={},r;n=n||{};for(r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t.queue=[],t.sorter=n.sorter||e.default_sorter,t},default_sorter:function(n,e){return n.cost-e.cost},push:function(n,e){var t={value:n,cost:e};this.queue.push(t),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};typeof Me<"u"&&(Me.exports=K)});var _t=w(V=>{var m=L(),Dt=bt(),Nt=St(),vt=Bt(),qt=Pt(),J=be(),se=P(),In=At();function Lt(n){return unescape(encodeURIComponent(n)).length}function W(n,e,t){let r=[],o;for(;(o=n.exec(t))!==null;)r.push({data:o[0],index:o.index,mode:e,length:o[0].length});return r}function Ot(n){let e=W(J.NUMERIC,m.NUMERIC,n),t=W(J.ALPHANUMERIC,m.ALPHANUMERIC,n),r,o;return se.isKanjiModeEnabled()?(r=W(J.BYTE,m.BYTE,n),o=W(J.KANJI,m.KANJI,n)):(r=W(J.BYTE_KANJI,m.BYTE,n),o=[]),e.concat(t,r,o).sort(function(s,a){return s.index-a.index}).map(function(s){return{data:s.data,mode:s.mode,length:s.length}})}function Pe(n,e){switch(e){case m.NUMERIC:return Dt.getBitsLength(n);case m.ALPHANUMERIC:return Nt.getBitsLength(n);case m.KANJI:return qt.getBitsLength(n);case m.BYTE:return vt.getBitsLength(n)}}function Dn(n){return n.reduce(function(e,t){let r=e.length-1>=0?e[e.length-1]:null;return r&&r.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}function Nn(n){let e=[];for(let t=0;t<n.length;t++){let r=n[t];switch(r.mode){case m.NUMERIC:e.push([r,{data:r.data,mode:m.ALPHANUMERIC,length:r.length},{data:r.data,mode:m.BYTE,length:r.length}]);break;case m.ALPHANUMERIC:e.push([r,{data:r.data,mode:m.BYTE,length:r.length}]);break;case m.KANJI:e.push([r,{data:r.data,mode:m.BYTE,length:Lt(r.data)}]);break;case m.BYTE:e.push([{data:r.data,mode:m.BYTE,length:Lt(r.data)}])}}return e}function vn(n,e){let t={},r={start:{}},o=["start"];for(let i=0;i<n.length;i++){let s=n[i],a=[];for(let u=0;u<s.length;u++){let l=s[u],c=""+i+u;a.push(c),t[c]={node:l,lastCount:0},r[c]={};for(let f=0;f<o.length;f++){let d=o[f];t[d]&&t[d].node.mode===l.mode?(r[d][c]=Pe(t[d].lastCount+l.length,l.mode)-Pe(t[d].lastCount,l.mode),t[d].lastCount+=l.length):(t[d]&&(t[d].lastCount=l.length),r[d][c]=Pe(l.length,l.mode)+4+m.getCharCountIndicator(l.mode,e))}}o=a}for(let i=0;i<o.length;i++)r[o[i]].end=0;return{map:r,table:t}}function It(n,e){let t,r=m.getBestModeForData(n);if(t=m.from(e,r),t!==m.BYTE&&t.bit<r.bit)throw new Error('"'+n+'" cannot be encoded with mode '+m.toString(t)+`.
|
|
4
|
+
Suggested mode is: `+m.toString(r));switch(t===m.KANJI&&!se.isKanjiModeEnabled()&&(t=m.BYTE),t){case m.NUMERIC:return new Dt(n);case m.ALPHANUMERIC:return new Nt(n);case m.KANJI:return new qt(n);case m.BYTE:return new vt(n)}}V.fromArray=function(e){return e.reduce(function(t,r){return typeof r=="string"?t.push(It(r,null)):r.data&&t.push(It(r.data,r.mode)),t},[])};V.fromString=function(e,t){let r=Ot(e,se.isKanjiModeEnabled()),o=Nn(r),i=vn(o,t),s=In.find_path(i.map,"start","end"),a=[];for(let u=1;u<s.length-1;u++)a.push(i.table[s[u]].node);return V.fromArray(Dn(a))};V.rawSplit=function(e){return V.fromArray(Ot(e,se.isKanjiModeEnabled()))}});var $t=w(Ft=>{var ue=P(),Ae=Z(),qn=We(),On=Ze(),_n=et(),Fn=rt(),De=ot(),Ne=ye(),$n=lt(),ae=mt(),Un=Et(),Qn=L(),Le=_t();function kn(n,e){let t=n.size,r=Fn.getPositions(e);for(let o=0;o<r.length;o++){let i=r[o][0],s=r[o][1];for(let a=-1;a<=7;a++)if(!(i+a<=-1||t<=i+a))for(let u=-1;u<=7;u++)s+u<=-1||t<=s+u||(a>=0&&a<=6&&(u===0||u===6)||u>=0&&u<=6&&(a===0||a===6)||a>=2&&a<=4&&u>=2&&u<=4?n.set(i+a,s+u,!0,!0):n.set(i+a,s+u,!1,!0))}}function Vn(n){let e=n.size;for(let t=8;t<e-8;t++){let r=t%2===0;n.set(t,6,r,!0),n.set(6,t,r,!0)}}function Hn(n,e){let t=_n.getPositions(e);for(let r=0;r<t.length;r++){let o=t[r][0],i=t[r][1];for(let s=-2;s<=2;s++)for(let a=-2;a<=2;a++)s===-2||s===2||a===-2||a===2||s===0&&a===0?n.set(o+s,i+a,!0,!0):n.set(o+s,i+a,!1,!0)}}function zn(n,e){let t=n.size,r=ae.getEncodedBits(e),o,i,s;for(let a=0;a<18;a++)o=Math.floor(a/3),i=a%3+t-8-3,s=(r>>a&1)===1,n.set(o,i,s,!0),n.set(i,o,s,!0)}function Ie(n,e,t){let r=n.size,o=Un.getEncodedBits(e,t),i,s;for(i=0;i<15;i++)s=(o>>i&1)===1,i<6?n.set(i,8,s,!0):i<8?n.set(i+1,8,s,!0):n.set(r-15+i,8,s,!0),i<8?n.set(8,r-i-1,s,!0):i<9?n.set(8,15-i-1+1,s,!0):n.set(8,15-i-1,s,!0);n.set(r-8,8,1,!0)}function Gn(n,e){let t=n.size,r=-1,o=t-1,i=7,s=0;for(let a=t-1;a>0;a-=2)for(a===6&&a--;;){for(let u=0;u<2;u++)if(!n.isReserved(o,a-u)){let l=!1;s<e.length&&(l=(e[s]>>>i&1)===1),n.set(o,a-u,l),i--,i===-1&&(s++,i=7)}if(o+=r,o<0||t<=o){o-=r,r=-r;break}}}function jn(n,e,t){let r=new qn;t.forEach(function(u){r.put(u.mode.bit,4),r.put(u.getLength(),Qn.getCharCountIndicator(u.mode,n)),u.write(r)});let o=ue.getSymbolTotalCodewords(n),i=Ne.getTotalCodewordsCount(n,e),s=(o-i)*8;for(r.getLengthInBits()+4<=s&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);let a=(s-r.getLengthInBits())/8;for(let u=0;u<a;u++)r.put(u%2?17:236,8);return Yn(r,n,e)}function Yn(n,e,t){let r=ue.getSymbolTotalCodewords(e),o=Ne.getTotalCodewordsCount(e,t),i=r-o,s=Ne.getBlocksCount(e,t),a=r%s,u=s-a,l=Math.floor(r/s),c=Math.floor(i/s),f=c+1,d=l-c,g=new $n(d),p=0,h=new Array(s),E=new Array(s),b=0,B=new Uint8Array(n.buffer);for(let S=0;S<s;S++){let N=S<u?c:f;h[S]=B.slice(p,p+N),E[S]=g.encode(h[S]),p+=N,b=Math.max(b,N)}let D=new Uint8Array(r),F=0,R,T;for(R=0;R<b;R++)for(T=0;T<s;T++)R<h[T].length&&(D[F++]=h[T][R]);for(R=0;R<d;R++)for(T=0;T<s;T++)D[F++]=E[T][R];return D}function Kn(n,e,t,r){let o;if(Array.isArray(n))o=Le.fromArray(n);else if(typeof n=="string"){let l=e;if(!l){let c=Le.rawSplit(n);l=ae.getBestVersionForData(c,t)}o=Le.fromString(n,l||40)}else throw new Error("Invalid data");let i=ae.getBestVersionForData(o,t);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(!e)e=i;else if(e<i)throw new Error(`
|
|
5
5
|
The chosen QR Code version cannot contain this amount of data.
|
|
6
6
|
Minimum version required to store current data is: `+i+`.
|
|
7
|
-
`);let s=
|
|
8
|
-
`;return typeof r=="function"&&r(null,d),d}});var zt=p(W=>{var Zn=Ge(),Oe=Ft(),Vt=Ut(),er=$t();function Fe(n,e,t,r,o){let i=[].slice.call(arguments,1),s=i.length,a=typeof i[s-1]=="function";if(!a&&!Zn())throw new Error("Callback required as last argument");if(a){if(s<2)throw new Error("Too few arguments provided");s===2?(o=t,t=e,e=r=void 0):s===3&&(e.getContext&&typeof o>"u"?(o=r,r=void 0):(o=r,r=t,t=e,e=void 0))}else{if(s<1)throw new Error("Too few arguments provided");return s===1?(t=e,e=r=void 0):s===2&&!e.getContext&&(r=t,t=e,e=void 0),new Promise(function(u,l){try{let c=Oe.create(t,r);u(n(c,e,r))}catch(c){l(c)}})}try{let u=Oe.create(t,r);o(null,n(u,e,r))}catch(u){o(u)}}W.create=Oe.create;W.toCanvas=Fe.bind(null,Vt.render);W.toDataURL=Fe.bind(null,Vt.renderToDataURL);W.toString=Fe.bind(null,function(n,e,t){return er.render(n,t)})});var Ve=an(zt(),1);var ce=class{constructor(e,t){this.ctx=e,this.options=t}render(){let{size:e,cornerRadius:t,backgroundColor:r}=this.options,o=this.ctx;o.fillStyle=r,o.beginPath(),o.moveTo(t,0),o.arcTo(e,0,e,e,t),o.arcTo(e,e,0,e,t),o.arcTo(0,e,0,0,t),o.arcTo(0,0,e,0,t),o.closePath(),o.fill()}applyClipping(){let{size:e,cornerRadius:t}=this.options,r=this.ctx;r.save(),r.beginPath(),r.moveTo(t,0),r.arcTo(e,0,e,e,t),r.arcTo(e,e,0,e,t),r.arcTo(0,e,0,0,t),r.arcTo(0,0,e,0,t),r.closePath(),r.clip()}restoreClipping(){this.ctx.restore()}};var de=class{constructor(e,t){this.ctx=e,this.options=t}createGradient(){let{size:e,gradientColors:t,gradientAngle:r}=this.options,o=this.ctx,i=t.split(",").map(g=>g.trim()),s=r*Math.PI/180,a=e/2,u=e/2,l=Math.sqrt(e*e+e*e)/2,c=a-Math.cos(s)*l,f=u-Math.sin(s)*l,d=a+Math.cos(s)*l,h=u+Math.sin(s)*l,w=o.createLinearGradient(c,f,d,h);return i.forEach((g,R)=>{let E=R/(i.length-1);w.addColorStop(E,g)}),w}getFillStyle(){let{gradient:e,foregroundColor:t}=this.options;return e?this.createGradient():t}};var fe=class{constructor(e,t,r){this.ctx=e,this.modules=t,this.options=r}hasModule(e,t){let{moduleCount:r}=this.options;return e<0||e>=r||t<0||t>=r?!1:this.modules.get(e,t)===1}isPartOfEye(e,t){let{moduleCount:r}=this.options;return e<7&&t<7||e<7&&t>=r-7||e>=r-7&&t<7}render(e){let{rounded:t}=this.options;this.ctx.fillStyle=e,t?this.renderRoundedModules():this.renderSquareModules()}renderRoundedModules(){let{moduleCount:e,moduleSize:t,padding:r,moduleRadius:o,eyeColor:i,eyeRadius:s}=this.options,a=this.ctx,u=a.fillStyle;for(let l=0;l<e;l++)for(let c=0;c<e;c++)if(this.modules.get(l,c)){let f=r+c*t,d=r+l*t,h=this.isPartOfEye(l,c);h&&i?a.fillStyle=i:a.fillStyle=u;let w=h&&s!==void 0&&s>0?t*s:t*o,g=this.hasModule(l-1,c),R=this.hasModule(l,c+1),E=this.hasModule(l+1,c),k=this.hasModule(l,c-1),$=!g&&!k,X=!g&&!R,T=!E&&!R,S=!E&&!k,B=.5,V=g?B:0,Wt=R?B:0,Xt=E?B:0,Zt=k?B:0;this.drawRoundedModule(f,d,t,w,{roundTL:$,roundTR:X,roundBR:T,roundBL:S},{extendTop:V,extendRight:Wt,extendBottom:Xt,extendLeft:Zt})}}drawRoundedModule(e,t,r,o,i,s){let a=this.ctx,{roundTL:u,roundTR:l,roundBR:c,roundBL:f}=i,{extendTop:d,extendRight:h,extendBottom:w,extendLeft:g}=s;a.beginPath(),u?a.moveTo(e+o-g,t-d):a.moveTo(e-g,t-d),l?(a.lineTo(e+r-o+h,t-d),a.quadraticCurveTo(e+r+h,t-d,e+r+h,t+o-d)):a.lineTo(e+r+h,t-d),c?(a.lineTo(e+r+h,t+r-o+w),a.quadraticCurveTo(e+r+h,t+r+w,e+r-o+h,t+r+w)):a.lineTo(e+r+h,t+r+w),f?(a.lineTo(e+o-g,t+r+w),a.quadraticCurveTo(e-g,t+r+w,e-g,t+r-o+w)):a.lineTo(e-g,t+r+w),u?(a.lineTo(e-g,t+o-d),a.quadraticCurveTo(e-g,t-d,e+o-g,t-d)):a.lineTo(e-g,t-d),a.closePath(),a.fill()}renderSquareModules(){let{moduleCount:e,moduleSize:t,padding:r,eyeColor:o}=this.options,i=this.ctx,s=i.fillStyle;for(let a=0;a<e;a++)for(let u=0;u<e;u++)if(this.modules.get(a,u)){let l=r+u*t,c=r+a*t;this.isPartOfEye(a,u)&&o?i.fillStyle=o:i.fillStyle=s,i.fillRect(l,c,t,t)}}};var ge=class{constructor(e,t){this.ctx=e,this.options=t}async render(e){if(!e)return;let t;typeof e=="string"?t=await this.loadImage(e):t=e;let{size:r,logoPadding:o}=this.options,i=r*.25,s=i+o,a=r/2,u=r/2;this.drawLogoBackground(a,u,s),this.drawLogoWithShadow(t,a,u,i)}loadImage(e){return new Promise((t,r)=>{let o=new Image;o.crossOrigin="anonymous",o.onload=()=>t(o),o.onerror=r,o.src=e})}drawLogoBackground(e,t,r){let{logoShape:o,logoRadius:i,backgroundColor:s}=this.options,a=this.ctx;if(a.fillStyle=s,o==="circle")a.beginPath(),a.arc(e,t,r/2,0,Math.PI*2),a.fill();else{let u=e-r/2,l=t-r/2;a.beginPath(),a.moveTo(u+i,l),a.arcTo(u+r,l,u+r,l+r,i),a.arcTo(u+r,l+r,u,l+r,i),a.arcTo(u,l+r,u,l,i),a.arcTo(u,l,u+r,l,i),a.closePath(),a.fill()}}drawLogoWithShadow(e,t,r,o){let i=this.ctx;i.shadowColor="rgba(0, 0, 0, 0.15)",i.shadowBlur=12,i.shadowOffsetX=0,i.shadowOffsetY=2;let s=t-o/2,a=r-o/2;i.drawImage(e,s,a,o,o),i.shadowColor="transparent",i.shadowBlur=0}};var he=class{constructor(e,t,r){this.qrData=e,this.options=t,this.size=r}generate(){let{size:e,backgroundColor:t,foregroundColor:r,moduleRadius:o,eyeColor:i,eyeRadius:s}=this.options,u=this.qrData.modules.size,l=e/u,c='<?xml version="1.0" encoding="UTF-8"?>';c+=`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${e}" viewBox="0 0 ${e} ${e}">`,c+=`<rect width="${e}" height="${e}" fill="${t}"/>`,c+=`<g fill="${r}">`;for(let f=0;f<u;f++)for(let d=0;d<u;d++)if(this.hasModule(d,f)){let h=d*l,w=f*l,g=this.isPartOfEye(d,f,u),R=g&&i?i:r,E=g&&s?s*l:o*l;E>0?c+=`<rect x="${h}" y="${w}" width="${l}" height="${l}" rx="${E}" fill="${R}"/>`:c+=`<rect x="${h}" y="${w}" width="${l}" height="${l}" fill="${R}"/>`}return c+="</g>",c+="</svg>",c}hasModule(e,t){let r=this.qrData.modules;return e<0||e>=r.size||t<0||t>=r.size?!1:r.data[t*r.size+e]===1}isPartOfEye(e,t,r){return e<7&&t<7||e>=r-7&&t<7||e<7&&t>=r-7}};var _e={type:"text",size:600,margin:4,padding:40,foregroundColor:"#000000",logo:"",logoSize:120,rounded:!0,moduleRadius:.35,logoPadding:10,logoShape:"circle",logoBackgroundColor:"#ffffff",logoRadius:20,gradient:!1,gradientColors:"#FEDA75,#FA7E1E,#D62976,#962FBF,#4F5BD5",gradientAngle:45,cornerRadius:60,backgroundColor:"#ffffff",errorCorrectionLevel:"H",eyeColor:"",eyeRadius:0},Ue=["circle","square"],Qe=["L","M","Q","H"];function ke(n){if(!n.url&&!n.data)throw new Error("URL, text content, or structured data is required");if(n.type&&n.type!=="url"&&n.type!=="text"&&!n.data)throw new Error(`Structured data is required for type '${n.type}'`);if(n.size&&(n.size<100||n.size>5e3))throw new Error("Size must be between 100 and 5000 pixels");if(n.margin!==void 0&&(n.margin<0||n.margin>10))throw new Error("Margin must be between 0 and 10 modules");if(n.moduleRadius!==void 0&&(n.moduleRadius<0||n.moduleRadius>.5))throw new Error("Module radius must be between 0.0 and 0.5");if(n.eyeRadius!==void 0&&(n.eyeRadius<0||n.eyeRadius>.5))throw new Error("Eye radius must be between 0.0 and 0.5");if(n.gradientAngle&&(n.gradientAngle<0||n.gradientAngle>360))throw new Error("Gradient angle must be between 0 and 360 degrees");if(n.logoShape&&!Ue.includes(n.logoShape))throw new Error(`Logo shape must be one of: ${Ue.join(", ")}`);if(n.logoSize&&(n.logoSize<50||n.logoSize>500))throw new Error("Logo size must be between 50 and 500 pixels");if(n.errorCorrectionLevel&&!Qe.includes(n.errorCorrectionLevel))throw new Error(`Error correction level must be one of: ${Qe.join(", ")}`);let e=n.foregroundColor||n.color;if(e&&!/^#([0-9A-F]{3}){1,2}$/i.test(e))throw new Error("Color must be in hex format (e.g., #000000)");if(n.eyeColor&&!/^#([0-9A-F]{3}){1,2}$/i.test(n.eyeColor))throw new Error("Eye color must be in hex format (e.g., #000000)");if(n.backgroundColor&&!/^#([0-9A-F]{3}){1,2}$/i.test(n.backgroundColor))throw new Error("Background color must be in hex format (e.g., #ffffff)");if(n.logoBackgroundColor&&!/^#([0-9A-F]{3}){1,2}$/i.test(n.logoBackgroundColor))throw new Error("Logo background color must be in hex format (e.g., #ffffff)");if(n.gradientColors&&n.gradientColors.split(",").map(r=>r.trim()).forEach(r=>{if(!/^#([0-9A-F]{3}){1,2}$/i.test(r))throw new Error(`Invalid gradient color: ${r}. Must be in hex format`)}),n.data&&n.type)switch(n.type){case"vcard":{let t=n.data;if(!t.firstName&&!t.lastName)throw new Error("vCard requires at least a first name or last name")}break;case"wifi":if(!n.data.ssid)throw new Error("WiFi QR code requires SSID");break;case"email":if(!n.data.email)throw new Error("Email QR code requires email address");break;case"sms":if(!n.data.phone)throw new Error("SMS QR code requires phone number");break;case"geo":{let t=n.data;if(t.latitude===void 0||t.longitude===void 0)throw new Error("Geo QR code requires latitude and longitude")}break}}function $e(n,e){return{...e,...n}}function Ht(n){let e=["BEGIN:VCARD","VERSION:3.0"];if(n.firstName||n.lastName){let t=`${n.lastName||""};${n.firstName||""};;;`;e.push(`N:${t}`),e.push(`FN:${[n.firstName,n.lastName].filter(Boolean).join(" ")}`)}if(n.organization&&e.push(`ORG:${n.organization}`),n.title&&e.push(`TITLE:${n.title}`),n.phone&&e.push(`TEL:${n.phone}`),n.email&&e.push(`EMAIL:${n.email}`),n.url&&e.push(`URL:${n.url}`),n.address||n.city||n.state||n.zip||n.country){let t=`;;${n.address||""};${n.city||""};${n.state||""};${n.zip||""};${n.country||""}`;e.push(`ADR:${t}`)}return e.push("END:VCARD"),e.join(`
|
|
9
|
-
`)}function
|
|
7
|
+
`);let s=jn(e,t,o),a=ue.getSymbolSize(e),u=new On(a);return kn(u,e),Vn(u),Hn(u,e),Ie(u,t,0),e>=7&&zn(u,e),Gn(u,s),isNaN(r)&&(r=De.getBestMask(u,Ie.bind(null,u,t))),De.applyMask(r,u),Ie(u,t,r),{modules:u,version:e,errorCorrectionLevel:t,maskPattern:r,segments:o}}Ft.create=function(e,t){if(typeof e>"u"||e==="")throw new Error("No input text");let r=Ae.M,o,i;return typeof t<"u"&&(r=Ae.from(t.errorCorrectionLevel,Ae.M),o=ae.from(t.version),i=De.from(t.maskPattern),t.toSJISFunc&&ue.setToSJISFunction(t.toSJISFunc)),Kn(e,o,r,i)}});var ve=w(_=>{function Ut(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let e=n.slice().replace("#","").split("");if(e.length<3||e.length===5||e.length>8)throw new Error("Invalid hex color: "+n);(e.length===3||e.length===4)&&(e=Array.prototype.concat.apply([],e.map(function(r){return[r,r]}))),e.length===6&&e.push("F","F");let t=parseInt(e.join(""),16);return{r:t>>24&255,g:t>>16&255,b:t>>8&255,a:t&255,hex:"#"+e.slice(0,6).join("")}}_.getOptions=function(e){e||(e={}),e.color||(e.color={});let t=typeof e.margin>"u"||e.margin===null||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,o=e.scale||4;return{width:r,scale:r?4:o,margin:t,color:{dark:Ut(e.color.dark||"#000000ff"),light:Ut(e.color.light||"#ffffffff")},type:e.type,rendererOpts:e.rendererOpts||{}}};_.getScale=function(e,t){return t.width&&t.width>=e+t.margin*2?t.width/(e+t.margin*2):t.scale};_.getImageWidth=function(e,t){let r=_.getScale(e,t);return Math.floor((e+t.margin*2)*r)};_.qrToImageData=function(e,t,r){let o=t.modules.size,i=t.modules.data,s=_.getScale(o,r),a=Math.floor((o+r.margin*2)*s),u=r.margin*s,l=[r.color.light,r.color.dark];for(let c=0;c<a;c++)for(let f=0;f<a;f++){let d=(c*a+f)*4,g=r.color.light;if(c>=u&&f>=u&&c<a-u&&f<a-u){let p=Math.floor((c-u)/s),h=Math.floor((f-u)/s);g=l[i[p*o+h]?1:0]}e[d++]=g.r,e[d++]=g.g,e[d++]=g.b,e[d]=g.a}}});var Qt=w(le=>{var qe=ve();function Jn(n,e,t){n.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=t,e.width=t,e.style.height=t+"px",e.style.width=t+"px"}function Wn(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}le.render=function(e,t,r){let o=r,i=t;typeof o>"u"&&(!t||!t.getContext)&&(o=t,t=void 0),t||(i=Wn()),o=qe.getOptions(o);let s=qe.getImageWidth(e.modules.size,o),a=i.getContext("2d"),u=a.createImageData(s,s);return qe.qrToImageData(u.data,e,o),Jn(a,i,s),a.putImageData(u,0,0),i};le.renderToDataURL=function(e,t,r){let o=r;typeof o>"u"&&(!t||!t.getContext)&&(o=t,t=void 0),o||(o={});let i=le.render(e,t,o),s=o.type||"image/png",a=o.rendererOpts||{};return i.toDataURL(s,a.quality)}});var Ht=w(Vt=>{var Xn=ve();function kt(n,e){let t=n.a/255,r=e+'="'+n.hex+'"';return t<1?r+" "+e+'-opacity="'+t.toFixed(2).slice(1)+'"':r}function Oe(n,e,t){let r=n+e;return typeof t<"u"&&(r+=" "+t),r}function Zn(n,e,t){let r="",o=0,i=!1,s=0;for(let a=0;a<n.length;a++){let u=Math.floor(a%e),l=Math.floor(a/e);!u&&!i&&(i=!0),n[a]?(s++,a>0&&u>0&&n[a-1]||(r+=i?Oe("M",u+t,.5+l+t):Oe("m",o,0),o=0,i=!1),u+1<e&&n[a+1]||(r+=Oe("h",s),s=0)):o++}return r}Vt.render=function(e,t,r){let o=Xn.getOptions(t),i=e.modules.size,s=e.modules.data,a=i+o.margin*2,u=o.color.light.a?"<path "+kt(o.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",l="<path "+kt(o.color.dark,"stroke")+' d="'+Zn(s,i,o.margin)+'"/>',c='viewBox="0 0 '+a+" "+a+'"',d='<svg xmlns="http://www.w3.org/2000/svg" '+(o.width?'width="'+o.width+'" height="'+o.width+'" ':"")+c+' shape-rendering="crispEdges">'+u+l+`</svg>
|
|
8
|
+
`;return typeof r=="function"&&r(null,d),d}});var Gt=w(X=>{var er=Ye(),_e=$t(),zt=Qt(),tr=Ht();function Fe(n,e,t,r,o){let i=[].slice.call(arguments,1),s=i.length,a=typeof i[s-1]=="function";if(!a&&!er())throw new Error("Callback required as last argument");if(a){if(s<2)throw new Error("Too few arguments provided");s===2?(o=t,t=e,e=r=void 0):s===3&&(e.getContext&&typeof o>"u"?(o=r,r=void 0):(o=r,r=t,t=e,e=void 0))}else{if(s<1)throw new Error("Too few arguments provided");return s===1?(t=e,e=r=void 0):s===2&&!e.getContext&&(r=t,t=e,e=void 0),new Promise(function(u,l){try{let c=_e.create(t,r);u(n(c,e,r))}catch(c){l(c)}})}try{let u=_e.create(t,r);o(null,n(u,e,r))}catch(u){o(u)}}X.create=_e.create;X.toCanvas=Fe.bind(null,zt.render);X.toDataURL=Fe.bind(null,zt.renderToDataURL);X.toString=Fe.bind(null,function(n,e,t){return tr.render(n,t)})});var ze=un(Gt(),1);var ce=class{constructor(e,t){this.ctx=e,this.options=t}render(){let{size:e,cornerRadius:t,backgroundColor:r}=this.options,o=this.ctx;o.fillStyle=r,o.beginPath(),o.moveTo(t,0),o.arcTo(e,0,e,e,t),o.arcTo(e,e,0,e,t),o.arcTo(0,e,0,0,t),o.arcTo(0,0,e,0,t),o.closePath(),o.fill()}applyClipping(){let{size:e,cornerRadius:t}=this.options,r=this.ctx;r.save(),r.beginPath(),r.moveTo(t,0),r.arcTo(e,0,e,e,t),r.arcTo(e,e,0,e,t),r.arcTo(0,e,0,0,t),r.arcTo(0,0,e,0,t),r.closePath(),r.clip()}restoreClipping(){this.ctx.restore()}};var de=class{constructor(e,t){this.ctx=e,this.options=t}createGradient(){let{size:e,gradientColors:t,gradientAngle:r}=this.options,o=this.ctx,i=t.split(",").map(h=>h.trim()),s=r*Math.PI/180,a=e/2,u=e/2,l=Math.sqrt(e*e+e*e)/2,c=a-Math.cos(s)*l,f=u-Math.sin(s)*l,d=a+Math.cos(s)*l,g=u+Math.sin(s)*l,p=o.createLinearGradient(c,f,d,g);return i.forEach((h,E)=>{let b=E/(i.length-1);p.addColorStop(b,h)}),p}getFillStyle(){let{gradient:e,foregroundColor:t}=this.options;return e?this.createGradient():t}};var fe=class{constructor(e,t,r){this.ctx=e,this.modules=t,this.options=r}hasModule(e,t){let{moduleCount:r}=this.options;return e<0||e>=r||t<0||t>=r?!1:this.modules.get(e,t)===1}isPartOfEye(e,t){let{moduleCount:r}=this.options;return e<7&&t<7||e<7&&t>=r-7||e>=r-7&&t<7}render(e){let{rounded:t,eyeShape:r}=this.options;this.ctx.fillStyle=e,r==="circle"?(this.renderModulesExcludingEyes(e,t),this.renderCircularEyes()):t?this.renderRoundedModules():this.renderSquareModules()}renderModulesExcludingEyes(e,t){let{moduleCount:r,moduleSize:o,padding:i,moduleRadius:s}=this.options,a=this.ctx;a.fillStyle=e;for(let u=0;u<r;u++)for(let l=0;l<r;l++)if(!this.isPartOfEye(u,l)&&this.modules.get(u,l)){let c=i+l*o,f=i+u*o;if(t){let d=o*s,g=this.hasModule(u-1,l),p=this.hasModule(u,l+1),h=this.hasModule(u+1,l),E=this.hasModule(u,l-1),b=!g&&!E,B=!g&&!p,D=!h&&!p,F=!h&&!E,R=.5,T=g?R:0,S=p?R:0,N=h?R:0,pe=E?R:0;this.drawRoundedModule(c,f,o,d,{roundTL:b,roundTR:B,roundBR:D,roundBL:F},{extendTop:T,extendRight:S,extendBottom:N,extendLeft:pe})}else a.fillRect(c,f,o,o)}}renderCircularEyes(){let{moduleCount:e,moduleSize:t,padding:r,eyeColor:o,backgroundColor:i}=this.options,s=this.ctx;[{row:3,col:3},{row:3,col:e-4},{row:e-4,col:3}].forEach(({row:u,col:l})=>{let c=r+l*t,f=r+u*t;s.fillStyle=o||s.fillStyle,s.beginPath(),s.arc(c,f,t*3.5,0,Math.PI*2),s.fill(),s.fillStyle=i,s.beginPath(),s.arc(c,f,t*2.5,0,Math.PI*2),s.fill(),s.fillStyle=o||s.fillStyle,s.beginPath(),s.arc(c,f,t*1.5,0,Math.PI*2),s.fill()})}renderRoundedModules(){let{moduleCount:e,moduleSize:t,padding:r,moduleRadius:o,eyeColor:i,eyeRadius:s}=this.options,a=this.ctx,u=a.fillStyle;for(let l=0;l<e;l++)for(let c=0;c<e;c++)if(this.modules.get(l,c)){let f=r+c*t,d=r+l*t,g=this.isPartOfEye(l,c);g&&i?a.fillStyle=i:a.fillStyle=u;let p=g&&s!==void 0&&s>0?t*s:t*o,h=this.hasModule(l-1,c),E=this.hasModule(l,c+1),b=this.hasModule(l+1,c),B=this.hasModule(l,c-1),D=!h&&!B,F=!h&&!E,R=!b&&!E,T=!b&&!B,S=.5,N=h?S:0,pe=E?S:0,Zt=b?S:0,en=B?S:0;this.drawRoundedModule(f,d,t,p,{roundTL:D,roundTR:F,roundBR:R,roundBL:T},{extendTop:N,extendRight:pe,extendBottom:Zt,extendLeft:en})}}drawRoundedModule(e,t,r,o,i,s){let a=this.ctx,{roundTL:u,roundTR:l,roundBR:c,roundBL:f}=i,{extendTop:d,extendRight:g,extendBottom:p,extendLeft:h}=s;a.beginPath(),u?a.moveTo(e+o-h,t-d):a.moveTo(e-h,t-d),l?(a.lineTo(e+r-o+g,t-d),a.quadraticCurveTo(e+r+g,t-d,e+r+g,t+o-d)):a.lineTo(e+r+g,t-d),c?(a.lineTo(e+r+g,t+r-o+p),a.quadraticCurveTo(e+r+g,t+r+p,e+r-o+g,t+r+p)):a.lineTo(e+r+g,t+r+p),f?(a.lineTo(e+o-h,t+r+p),a.quadraticCurveTo(e-h,t+r+p,e-h,t+r-o+p)):a.lineTo(e-h,t+r+p),u?(a.lineTo(e-h,t+o-d),a.quadraticCurveTo(e-h,t-d,e+o-h,t-d)):a.lineTo(e-h,t-d),a.closePath(),a.fill()}renderSquareModules(){let{moduleCount:e,moduleSize:t,padding:r,eyeColor:o}=this.options,i=this.ctx,s=i.fillStyle;for(let a=0;a<e;a++)for(let u=0;u<e;u++)if(this.modules.get(a,u)){let l=r+u*t,c=r+a*t;this.isPartOfEye(a,u)&&o?i.fillStyle=o:i.fillStyle=s,i.fillRect(l,c,t,t)}}};var ge=class{constructor(e,t){this.ctx=e,this.options=t}async render(e){if(!e)return;let t;typeof e=="string"?t=await this.loadImage(e):t=e;let{size:r,logoPadding:o}=this.options,i=r*.25,s=i+o,a=r/2,u=r/2;this.drawLogoBackground(a,u,s),this.drawLogoWithShadow(t,a,u,i)}loadImage(e){return new Promise((t,r)=>{let o=new Image;o.crossOrigin="anonymous",o.onload=()=>t(o),o.onerror=r,o.src=e})}drawLogoBackground(e,t,r){let{logoShape:o,logoRadius:i,backgroundColor:s}=this.options,a=this.ctx;if(a.fillStyle=s,o==="circle")a.beginPath(),a.arc(e,t,r/2,0,Math.PI*2),a.fill();else{let u=e-r/2,l=t-r/2;a.beginPath(),a.moveTo(u+i,l),a.arcTo(u+r,l,u+r,l+r,i),a.arcTo(u+r,l+r,u,l+r,i),a.arcTo(u,l+r,u,l,i),a.arcTo(u,l,u+r,l,i),a.closePath(),a.fill()}}drawLogoWithShadow(e,t,r,o){let i=this.ctx;i.shadowColor="rgba(0, 0, 0, 0.15)",i.shadowBlur=12,i.shadowOffsetX=0,i.shadowOffsetY=2;let s=t-o/2,a=r-o/2;i.drawImage(e,s,a,o,o),i.shadowColor="transparent",i.shadowBlur=0}};var he=class{constructor(e,t,r){this.qrData=e,this.options=t,this.size=r}generate(){let{size:e,backgroundColor:t,foregroundColor:r,moduleRadius:o,eyeColor:i,eyeRadius:s,eyeShape:a}=this.options,l=this.qrData.modules.size,c=e/l,f='<?xml version="1.0" encoding="UTF-8"?>';f+=`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${e}" viewBox="0 0 ${e} ${e}">`,f+=`<rect width="${e}" height="${e}" fill="${t}"/>`,f+=`<g fill="${r}">`;for(let d=0;d<l;d++)for(let g=0;g<l;g++)if(!(a==="circle"&&this.isPartOfEye(g,d,l))&&this.hasModule(g,d)){let p=g*c,h=d*c,E=this.isPartOfEye(g,d,l),b=E&&i?i:r,B=E&&s?s*c:o*c;B>0?f+=`<rect x="${p}" y="${h}" width="${c}" height="${c}" rx="${B}" fill="${b}"/>`:f+=`<rect x="${p}" y="${h}" width="${c}" height="${c}" fill="${b}"/>`}return f+="</g>",a==="circle"&&(f+=this.generateCircularEyes(l,c)),f+="</svg>",f}generateCircularEyes(e,t){let{eyeColor:r,backgroundColor:o,foregroundColor:i}=this.options,s=r||i,a="";return[{row:3,col:3},{row:3,col:e-4},{row:e-4,col:3}].forEach(({row:l,col:c})=>{let f=c*t,d=l*t;a+=`<circle cx="${f}" cy="${d}" r="${t*3.5}" fill="${s}"/>`,a+=`<circle cx="${f}" cy="${d}" r="${t*2.5}" fill="${o}"/>`,a+=`<circle cx="${f}" cy="${d}" r="${t*1.5}" fill="${s}"/>`}),a}hasModule(e,t){let r=this.qrData.modules;return e<0||e>=r.size||t<0||t>=r.size?!1:r.data[t*r.size+e]===1}isPartOfEye(e,t,r){return e<7&&t<7||e>=r-7&&t<7||e<7&&t>=r-7}};var $e={type:"text",size:600,margin:4,padding:40,foregroundColor:"#000000",logo:"",logoSize:120,rounded:!0,moduleRadius:.35,logoPadding:10,logoShape:"circle",logoBackgroundColor:"#ffffff",logoRadius:20,gradient:!1,gradientColors:"#FEDA75,#FA7E1E,#D62976,#962FBF,#4F5BD5",gradientAngle:45,cornerRadius:60,backgroundColor:"#ffffff",errorCorrectionLevel:"H",eyeColor:"",eyeRadius:0,eyeShape:"square"},Ue=["circle","square"],Qe=["square","rounded","circle"],ke=["L","M","Q","H"];function Ve(n){if(!n.url&&!n.data)throw new Error("URL, text content, or structured data is required");if(n.type&&n.type!=="url"&&n.type!=="text"&&!n.data)throw new Error(`Structured data is required for type '${n.type}'`);if(n.size&&(n.size<100||n.size>5e3))throw new Error("Size must be between 100 and 5000 pixels");if(n.margin!==void 0&&(n.margin<0||n.margin>10))throw new Error("Margin must be between 0 and 10 modules");if(n.moduleRadius!==void 0&&(n.moduleRadius<0||n.moduleRadius>.5))throw new Error("Module radius must be between 0.0 and 0.5");if(n.eyeRadius!==void 0&&(n.eyeRadius<0||n.eyeRadius>.5))throw new Error("Eye radius must be between 0.0 and 0.5");if(n.eyeShape&&!Qe.includes(n.eyeShape))throw new Error(`Eye shape must be one of: ${Qe.join(", ")}`);if(n.gradientAngle&&(n.gradientAngle<0||n.gradientAngle>360))throw new Error("Gradient angle must be between 0 and 360 degrees");if(n.logoShape&&!Ue.includes(n.logoShape))throw new Error(`Logo shape must be one of: ${Ue.join(", ")}`);if(n.logoSize&&(n.logoSize<50||n.logoSize>500))throw new Error("Logo size must be between 50 and 500 pixels");if(n.errorCorrectionLevel&&!ke.includes(n.errorCorrectionLevel))throw new Error(`Error correction level must be one of: ${ke.join(", ")}`);let e=n.foregroundColor||n.color;if(e&&!/^#([0-9A-F]{3}){1,2}$/i.test(e))throw new Error("Color must be in hex format (e.g., #000000)");if(n.eyeColor&&!/^#([0-9A-F]{3}){1,2}$/i.test(n.eyeColor))throw new Error("Eye color must be in hex format (e.g., #000000)");if(n.backgroundColor&&!/^#([0-9A-F]{3}){1,2}$/i.test(n.backgroundColor))throw new Error("Background color must be in hex format (e.g., #ffffff)");if(n.logoBackgroundColor&&!/^#([0-9A-F]{3}){1,2}$/i.test(n.logoBackgroundColor))throw new Error("Logo background color must be in hex format (e.g., #ffffff)");if(n.gradientColors&&n.gradientColors.split(",").map(r=>r.trim()).forEach(r=>{if(!/^#([0-9A-F]{3}){1,2}$/i.test(r))throw new Error(`Invalid gradient color: ${r}. Must be in hex format`)}),n.data&&n.type)switch(n.type){case"vcard":{let t=n.data;if(!t.firstName&&!t.lastName)throw new Error("vCard requires at least a first name or last name")}break;case"wifi":if(!n.data.ssid)throw new Error("WiFi QR code requires SSID");break;case"email":if(!n.data.email)throw new Error("Email QR code requires email address");break;case"sms":if(!n.data.phone)throw new Error("SMS QR code requires phone number");break;case"geo":{let t=n.data;if(t.latitude===void 0||t.longitude===void 0)throw new Error("Geo QR code requires latitude and longitude")}break}}function He(n,e){return{...e,...n}}function jt(n){let e=["BEGIN:VCARD","VERSION:3.0"];if(n.firstName||n.lastName){let t=`${n.lastName||""};${n.firstName||""};;;`;e.push(`N:${t}`),e.push(`FN:${[n.firstName,n.lastName].filter(Boolean).join(" ")}`)}if(n.organization&&e.push(`ORG:${n.organization}`),n.title&&e.push(`TITLE:${n.title}`),n.phone&&e.push(`TEL:${n.phone}`),n.email&&e.push(`EMAIL:${n.email}`),n.url&&e.push(`URL:${n.url}`),n.address||n.city||n.state||n.zip||n.country){let t=`;;${n.address||""};${n.city||""};${n.state||""};${n.zip||""};${n.country||""}`;e.push(`ADR:${t}`)}return e.push("END:VCARD"),e.join(`
|
|
9
|
+
`)}function Yt(n){let{ssid:e,password:t="",encryption:r="WPA",hidden:o=!1}=n,i=a=>a.replace(/([\\;,:])/g,"\\$1"),s="WIFI:";return s+=`T:${r};`,s+=`S:${i(e)};`,t&&(s+=`P:${i(t)};`),o&&(s+="H:true;"),s+=";",s}function Kt(n){let e=`mailto:${n.email}`,t=[];return n.subject&&t.push(`subject=${encodeURIComponent(n.subject)}`),n.body&&t.push(`body=${encodeURIComponent(n.body)}`),t.length>0&&(e+="?"+t.join("&")),e}function Jt(n){let e=`sms:${n.phone}`;return n.message&&(e+=`?body=${encodeURIComponent(n.message)}`),e}function Wt(n){return`geo:${n.latitude},${n.longitude}`}function Xt(n,e,t){switch(n){case"url":return e||"";case"text":return e||"";case"vcard":return t?jt(t):"";case"wifi":return t?Yt(t):"";case"email":return t?Kt(t):"";case"sms":return t?Jt(t):"";case"geo":return t?Wt(t):"";default:return e||""}}var H=class{constructor(e){this.options=He(e,$e),e.color&&!e.foregroundColor&&(this.options.foregroundColor=e.color),Ve(this.options)}getQRContent(){let{type:e,url:t,data:r}=this.options;return Xt(e,t,r)}async generate(){let{errorCorrectionLevel:e,size:t,padding:r,foregroundColor:o}=this.options,i=t-r*2,s=this.getQRContent(),u=(await ze.default.create(s,{errorCorrectionLevel:e})).modules,l=u.size,c=i/l,f=document.createElement("canvas");f.width=t,f.height=t;let d=f.getContext("2d");if(!d)throw new Error("Failed to get 2D context from canvas. Canvas API may not be supported in this environment.");let g=new ce(d,this.options);g.render(),g.applyClipping();let h=new de(d,this.options).getFillStyle();return new fe(d,u,{...this.options,color:o,moduleCount:l,moduleSize:c}).render(h),g.restoreClipping(),this.options.logo&&await new ge(d,this.options).render(this.options.logo),f}async generateToDataURL(e="png"){let t=await this.generate();return e==="jpeg"?t.toDataURL("image/jpeg"):t.toDataURL("image/png")}async generateToBlob(e="png"){let t=await this.generate();return new Promise((r,o)=>{t.toBlob(i=>{i?r(i):o(new Error("Failed to generate blob"))},e==="jpeg"?"image/jpeg":"image/png")})}async download(e="qrcode.png"){let t=e.endsWith(".jpeg")||e.endsWith(".jpg")?"jpeg":"png",r=await this.generateToDataURL(t),o=document.createElement("a");o.href=r,o.download=e,o.click()}async generateToSVG(){let{errorCorrectionLevel:e,size:t}=this.options,r=this.getQRContent(),o=await ze.default.create(r,{errorCorrectionLevel:e});return new he(o,this.options,t).generate()}async downloadSVG(e="qrcode.svg"){let t=await this.generateToSVG(),r=new Blob([t],{type:"image/svg+xml"}),o=URL.createObjectURL(r),i=document.createElement("a");i.href=o,i.download=e,i.click(),URL.revokeObjectURL(o)}async appendTo(e){let t=await this.generate();return e.appendChild(t),t}updateOptions(e){this.options=He({...this.options,...e},$e),e.color&&!e.foregroundColor&&(this.options.foregroundColor=e.color),Ve(this.options)}};async function nr(n){return new H(n).generate()}async function rr(n,e){return new H(n).appendTo(e)}async function or(n,e){return new H(n).download(e)}export{H as QRGenerator,Kt as formatEmail,Wt as formatGeo,Jt as formatSMS,jt as formatVCard,Yt as formatWiFi,nr as generateQR,or as generateQRAndDownload,rr as generateQRToElement};
|
|
10
10
|
//# sourceMappingURL=bundle.js.map
|