UNPKG

custom-qrcode-browser

Version:

[![Continuous Integrations](https://github.com/CyrilDesch/custom-qrcode-browser/actions/workflows/continuous-integrations.yaml/badge.svg?branch=main)](https://github.com/CyrilDesch/custom-qrcode-browser/actions/workflows/continuous-integrations.yaml) [![L

8 lines (7 loc) 41.5 kB
/*! * custom-qrcode-browser * (c) Cyril Deschamps (https://cyrildeschamps.fr) * Released under the MIT License. */ var t;!function(t){t.DarkPixel="DarkPixel",t.Background="Background"}(t||(t={}));class e{constructor(e){this.origin=0,this.size=e,this.matrix=Array.from({length:e},(()=>Array(e).fill(t.Background)))}get(t,e){if(this.isOutOfBounds(t,e))throw new RangeError(`Index (${t}, ${e}) is out of bounds for a matrix of size ${this.size}.`);return this.matrix[t][e]}set(t,e,s){if(this.isOutOfBounds(t,e))throw new RangeError(`Index (${t}, ${e}) is out of bounds for a matrix of size ${this.size}.`);this.matrix[t][e]=s}isOutOfBounds(t,e){return t<0||t>=this.size||e<0||e>=this.size}static fromQrMatrix(s){const{size:i}=s,r=new e(i);for(let e=0;e<i;e++)for(let n=0;n<i;n++){const i=s.getModule(e,n);r.set(e,n,i?t.DarkPixel:t.Background)}return r}}class s{static encodeText(t,e){const i=o.makeSegments(t);return s.encodeSegments(i,e)}static encodeSegments(t,e,r=1,c=40,h=-1,l=!0){if(!(s.MIN_VERSION<=r&&r<=c&&c<=s.MAX_VERSION)||h<-1||h>7)throw new RangeError("Invalid value");let u,d;for(u=r;;u++){const i=8*s.getNumDataCodewords(u,e),r=o.getTotalBits(t,u);if(r<=i){d=r;break}if(u>=c)throw new RangeError("Data too long")}for(const t of[a.MEDIUM,a.QUARTILE,a.HIGH])l&&d<=8*s.getNumDataCodewords(u,t)&&(e=t);const m=[];for(const e of t){i(e.mode.modeBits,4,m),i(e.numChars,e.mode.numCharCountBits(u),m);for(const t of e.getData())m.push(t)}n(m.length==d);const p=8*s.getNumDataCodewords(u,e);n(m.length<=p),i(0,Math.min(4,p-m.length),m),i(0,(8-m.length%8)%8,m),n(m.length%8==0);for(let t=236;m.length<p;t^=253)i(t,8,m);const g=[];for(;8*g.length<m.length;)g.push(0);return m.forEach(((t,e)=>g[e>>>3]=(g[e>>>3]??0)|t<<7-(7&e))),new s(u,e,g,h)}constructor(t,e,i,r){if(this.version=t,this.errorCorrectionLevel=e,this.modules=[],this.isFunction=[],t<s.MIN_VERSION||t>s.MAX_VERSION)throw new RangeError("Version value out of range");if(r<-1||r>7)throw new RangeError("Mask value out of range");this.size=4*t+17;const o=[];for(let t=0;t<this.size;t++)o.push(!1);for(let t=0;t<this.size;t++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();const a=this.addEccAndInterleave(i);if(this.drawCodewords(a),-1==r){let t=1e9;for(let e=0;e<8;e++){this.applyMask(e),this.drawFormatBits(e);const s=this.getPenaltyScore();s<t&&(r=e,t=s),this.applyMask(e)}}n(0<=r&&r<=7),this.mask=r,this.applyMask(r),this.drawFormatBits(r),this.isFunction=[]}getModule(t,e){return 0<=t&&t<this.size&&0<=e&&e<this.size&&this.modules?.[e]?.[t]||!1}drawFunctionPatterns(){for(let t=0;t<this.size;t++)this.setFunctionModule(6,t,t%2==0),this.setFunctionModule(t,6,t%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const t=this.getAlignmentPatternPositions(),e=t.length;for(let s=0;s<e;s++)for(let i=0;i<e;i++)0==s&&0==i||0==s&&i==e-1||s==e-1&&0==i||this.drawAlignmentPattern(t[s],t[i]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){const e=this.errorCorrectionLevel.formatBits<<3|t;let s=e;for(let t=0;t<10;t++)s=s<<1^1335*(s>>>9);const i=21522^(e<<10|s);n(i>>>15==0);for(let t=0;t<=5;t++)this.setFunctionModule(8,t,r(i,t));this.setFunctionModule(8,7,r(i,6)),this.setFunctionModule(8,8,r(i,7)),this.setFunctionModule(7,8,r(i,8));for(let t=9;t<15;t++)this.setFunctionModule(14-t,8,r(i,t));for(let t=0;t<8;t++)this.setFunctionModule(this.size-1-t,8,r(i,t));for(let t=8;t<15;t++)this.setFunctionModule(8,this.size-15+t,r(i,t));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let t=this.version;for(let e=0;e<12;e++)t=t<<1^7973*(t>>>11);const e=this.version<<12|t;n(e>>>18==0);for(let t=0;t<18;t++){const s=r(e,t),i=this.size-11+t%3,n=Math.floor(t/3);this.setFunctionModule(i,n,s),this.setFunctionModule(n,i,s)}}drawFinderPattern(t,e){for(let s=-4;s<=4;s++)for(let i=-4;i<=4;i++){const r=Math.max(Math.abs(i),Math.abs(s)),n=t+i,o=e+s;0<=n&&n<this.size&&0<=o&&o<this.size&&this.setFunctionModule(n,o,2!=r&&4!=r)}}drawAlignmentPattern(t,e){for(let s=-2;s<=2;s++)for(let i=-2;i<=2;i++)this.setFunctionModule(t+i,e+s,1!=Math.max(Math.abs(i),Math.abs(s)))}setFunctionModule(t,e,s){this.modules[e][t]=s,this.isFunction[e][t]=!0}addEccAndInterleave(t){const e=this.version,i=this.errorCorrectionLevel;if(t.length!=s.getNumDataCodewords(e,i))throw new RangeError("Invalid argument");const r=s.NUM_ERROR_CORRECTION_BLOCKS[i.ordinal][e],o=s.ECC_CODEWORDS_PER_BLOCK[i.ordinal][e],a=Math.floor(s.getNumRawDataModules(e)/8),c=r-a%r,h=Math.floor(a/r),l=[],u=s.reedSolomonComputeDivisor(o);for(let e=0,i=0;e<r;e++){const r=t.slice(i,i+h-o+(e<c?0:1));i+=r.length;const n=s.reedSolomonComputeRemainder(r,u);e<c&&r.push(0),l.push(r.concat(n))}const d=[];for(let t=0;t<l[0].length;t++)l.forEach(((e,s)=>{(t!=h-o||s>=c)&&d.push(e[t])}));return n(d.length==a),d}drawCodewords(t){if(t.length!=Math.floor(s.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let e=0;for(let s=this.size-1;s>=1;s-=2){6==s&&(s=5);for(let i=0;i<this.size;i++)for(let n=0;n<2;n++){const o=s-n,a=!(s+1&2)?this.size-1-i:i;!this.isFunction[a][o]&&e<8*t.length&&(this.modules[a][o]=r(t[e>>>3],7-(7&e)),e++)}}n(e==8*t.length)}applyMask(t){if(t<0||t>7)throw new RangeError("Mask value out of range");for(let e=0;e<this.size;e++)for(let s=0;s<this.size;s++){let i;switch(t){case 0:i=(s+e)%2==0;break;case 1:i=e%2==0;break;case 2:i=s%3==0;break;case 3:i=(s+e)%3==0;break;case 4:i=(Math.floor(s/3)+Math.floor(e/2))%2==0;break;case 5:i=s*e%2+s*e%3==0;break;case 6:i=(s*e%2+s*e%3)%2==0;break;case 7:i=((s+e)%2+s*e%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[e][s]&&i&&(this.modules[e][s]=!this.modules[e][s])}}getPenaltyScore(){let t=0;for(let e=0;e<this.size;e++){let i=!1,r=0;const n=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[e][o]==i?(r++,5==r?t+=s.PENALTY_N1:r>5&&t++):(this.finderPenaltyAddHistory(r,n),i||(t+=this.finderPenaltyCountPatterns(n)*s.PENALTY_N3),i=this.modules[e][o],r=1);t+=this.finderPenaltyTerminateAndCount(i,r,n)*s.PENALTY_N3}for(let e=0;e<this.size;e++){let i=!1,r=0;const n=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][e]==i?(r++,5==r?t+=s.PENALTY_N1:r>5&&t++):(this.finderPenaltyAddHistory(r,n),i||(t+=this.finderPenaltyCountPatterns(n)*s.PENALTY_N3),i=this.modules[o][e],r=1);t+=this.finderPenaltyTerminateAndCount(i,r,n)*s.PENALTY_N3}for(let e=0;e<this.size-1;e++)for(let i=0;i<this.size-1;i++){const r=this.modules[e][i];r==this.modules[e][i+1]&&r==this.modules[e+1][i]&&r==this.modules[e+1][i+1]&&(t+=s.PENALTY_N2)}let e=0;for(const t of this.modules)e=t.reduce(((t,e)=>t+(e?1:0)),e);const i=this.size*this.size,r=Math.ceil(Math.abs(20*e-10*i)/i)-1;return n(0<=r&&r<=9),t+=r*s.PENALTY_N4,n(0<=t&&t<=2568888),t}getAlignmentPatternPositions(){if(1==this.version)return[];{const t=Math.floor(this.version/7)+2,e=2*Math.floor((8*this.version+3*t+5)/(4*t-4)),s=[6];for(let i=this.size-7;s.length<t;i-=e)s.splice(1,0,i);return s}}static getNumRawDataModules(t){if(t<s.MIN_VERSION||t>s.MAX_VERSION)throw new RangeError("Version number out of range");let e=(16*t+128)*t+64;if(t>=2){const s=Math.floor(t/7)+2;e-=(25*s-10)*s-55,t>=7&&(e-=36)}return n(208<=e&&e<=29648),e}static getNumDataCodewords(t,e){return Math.floor(s.getNumRawDataModules(t)/8)-s.ECC_CODEWORDS_PER_BLOCK[e.ordinal][t]*s.NUM_ERROR_CORRECTION_BLOCKS[e.ordinal][t]}static reedSolomonComputeDivisor(t){if(t<1||t>255)throw new RangeError("Degree out of range");const e=[];for(let s=0;s<t-1;s++)e.push(0);e.push(1);let i=1;for(let r=0;r<t;r++){for(let t=0;t<e.length;t++)e[t]=s.reedSolomonMultiply(e[t],i),t+1<e.length&&(e[t]^=e[t+1]);i=s.reedSolomonMultiply(i,2)}return e}static reedSolomonComputeRemainder(t,e){const i=e.map((t=>0));for(const r of t){const t=r^i.shift();i.push(0),e.forEach(((e,r)=>i[r]^=s.reedSolomonMultiply(e,t)))}return i}static reedSolomonMultiply(t,e){if(t>>>8!=0||e>>>8!=0)throw new RangeError("Byte out of range");let s=0;for(let i=7;i>=0;i--)s=s<<1^285*(s>>>7),s^=(e>>>i&1)*t;return n(s>>>8==0),s}finderPenaltyCountPatterns(t){const e=t[1];n(e<=3*this.size);const s=e>0&&t[2]==e&&t[3]==3*e&&t[4]==e&&t[5]==e;return(s&&t[0]>=4*e&&t[6]>=e?1:0)+(s&&t[6]>=4*e&&t[0]>=e?1:0)}finderPenaltyTerminateAndCount(t,e,s){return t&&(this.finderPenaltyAddHistory(e,s),e=0),e+=this.size,this.finderPenaltyAddHistory(e,s),this.finderPenaltyCountPatterns(s)}finderPenaltyAddHistory(t,e){0==e[0]&&(t+=this.size),e.pop(),e.unshift(t)}}function i(t,e,s){if(e<0||e>31||t>>>e!=0)throw new RangeError("Value out of range");for(let i=e-1;i>=0;i--)s.push(t>>>i&1)}function r(t,e){return!!(t>>>e&1)}function n(t){if(!t)throw new Error("Assertion error")}s.MIN_VERSION=1,s.MAX_VERSION=40,s.PENALTY_N1=3,s.PENALTY_N2=3,s.PENALTY_N3=40,s.PENALTY_N4=10,s.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],s.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]];class o{static makeBytes(t){const e=[];for(const s of t)i(s,8,e);return new o(c.BYTE,t.length,e)}static makeNumeric(t){if(!o.isNumeric(t))throw new RangeError("String contains non-numeric characters");const e=[];for(let s=0;s<t.length;){const r=Math.min(t.length-s,3);i(parseInt(t.substring(s,s+r),10),3*r+1,e),s+=r}return new o(c.NUMERIC,t.length,e)}static makeAlphanumeric(t){if(!o.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");const e=[];let s;for(s=0;s+2<=t.length;s+=2){let r=45*o.ALPHANUMERIC_CHARSET.indexOf(t.charAt(s));r+=o.ALPHANUMERIC_CHARSET.indexOf(t.charAt(s+1)),i(r,11,e)}return s<t.length&&i(o.ALPHANUMERIC_CHARSET.indexOf(t.charAt(s)),6,e),new o(c.ALPHANUMERIC,t.length,e)}static makeSegments(t){return""==t?[]:o.isNumeric(t)?[o.makeNumeric(t)]:o.isAlphanumeric(t)?[o.makeAlphanumeric(t)]:[o.makeBytes(o.toUtf8ByteArray(t))]}static makeEci(t){const e=[];if(t<0)throw new RangeError("ECI assignment value out of range");if(t<128)i(t,8,e);else if(t<16384)i(2,2,e),i(t,14,e);else{if(!(t<1e6))throw new RangeError("ECI assignment value out of range");i(6,3,e),i(t,21,e)}return new o(c.ECI,0,e)}static isNumeric(t){return o.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return o.ALPHANUMERIC_REGEX.test(t)}constructor(t,e,s){if(this.mode=t,this.numChars=e,this.bitData=s,e<0)throw new RangeError("Invalid argument");this.bitData=s.slice()}getData(){return this.bitData.slice()}static getTotalBits(t,e){let s=0;for(const i of t){const t=i.mode.numCharCountBits(e);if(i.numChars>=1<<t)return 1/0;s+=4+t+i.bitData.length}return s}static toUtf8ByteArray(t){t=encodeURI(t);const e=[];for(let s=0;s<t.length;s++)"%"!=t.charAt(s)?e.push(t.charCodeAt(s)):(e.push(parseInt(t.substring(s+1,s+3),16)),s+=2);return e}}o.NUMERIC_REGEX=/^[0-9]*$/,o.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+./:-]*$/,o.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";class a{constructor(t,e){this.ordinal=t,this.formatBits=e}static fromString(t){switch(t){case"LOW":return a.LOW;case"MEDIUM":return a.MEDIUM;case"QUARTILE":return a.QUARTILE;case"HIGH":return a.HIGH}}}a.LOW=new a(0,1),a.MEDIUM=new a(1,0),a.QUARTILE=new a(2,3),a.HIGH=new a(3,2);class c{constructor(t,e){this.modeBits=t,this.numBitsCharCount=e}numCharCountBits(t){return this.numBitsCharCount[Math.floor((t+7)/17)]}}c.NUMERIC=new c(1,[10,12,14]),c.ALPHANUMERIC=new c(2,[9,11,13]),c.BYTE=new c(4,[8,16,16]),c.KANJI=new c(8,[8,10,12]),c.ECI=new c(7,[0,0,0]);const h="http://www.w3.org/2000/svg";function l(t){const e=document.createElementNS(h,"path");return e.setAttribute("d",t),e}function u(t){const e=document.createElementNS(h,"g");for(const s of t)e.appendChild(s);return e}function d(t){let e=t.querySelector("defs");return null===e&&(e=document.createElementNS(h,"defs"),t.insertBefore(e,t.firstChild)),e}function m(t,e){return t*((1-e)/e)}class p{constructor(t,e){this.start=t,this.end=e}static fromString(t){switch(t){case"Vertical":return p.Vertical;case"Horizontal":return p.Horizontal;case"LeftDiagonal":return p.LeftDiagonal;case"RightDiagonal":return p.RightDiagonal}}}p.Vertical=new p(["50%","0%"],["50%","100%"]),p.Horizontal=new p(["0%","50%"],["100%","50%"]),p.LeftDiagonal=new p(["0%","0%"],["100%","100%"]),p.RightDiagonal=new p(["100%","0%"],["0%","100%"]);const g=class{constructor(t){this.color=t}applyToElement(t){t.setAttribute("fill",this.color)}},S=class{constructor(t,e){this.colors=t,this.orientation=e,this.gradientId=`gradient-linear-${Math.random().toString(36).slice(2,11)}`}applyToElement(t,e){const s=d(e);if(!s.querySelector(`#${this.gradientId}`)){const t=this.createGradientElement();this.colors.forEach((([e,s])=>this.appendStopElement(t,e,s))),s.appendChild(t)}t.setAttribute("fill",`url(#${this.gradientId})`)}createGradientElement(){const{start:t,end:e}=this.orientation,s=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");return s.setAttribute("id",this.gradientId),s.setAttribute("gradientUnits","userSpaceOnUse"),s.setAttribute("x1",t[0].toString()),s.setAttribute("y1",t[1].toString()),s.setAttribute("x2",e[0].toString()),s.setAttribute("y2",e[1].toString()),s}appendStopElement(t,e,s){const i=document.createElementNS("http://www.w3.org/2000/svg","stop");i.setAttribute("offset",100*e+"%"),i.setAttribute("stop-color",s),t.appendChild(i)}},f=class{constructor(t,e=Math.sqrt(2)){this.colors=t,this.radius=e,this.gradientId=`gradient-radial-${Math.random().toString(36).slice(2,11)}`}applyToElement(t,e){const s=d(e),i=this.createGradientElement();this.colors.forEach((([t,e])=>this.appendStopElement(i,t,e))),s.appendChild(i),t.setAttribute("fill",`url(#${this.gradientId})`)}createGradientElement(){const t=document.createElementNS("http://www.w3.org/2000/svg","radialGradient");return t.setAttribute("id",this.gradientId),t.setAttribute("cx","0.5"),t.setAttribute("cy","0.5"),t.setAttribute("r",50*this.radius+"%"),t}appendStopElement(t,e,s){const i=document.createElementNS("http://www.w3.org/2000/svg","stop");i.setAttribute("offset",100*e+"%"),i.setAttribute("stop-color",s),t.appendChild(i)}},E=class{constructor(t){this.colors=t,this.gradientId=`gradient-sweep-${Math.random().toString(36).slice(2,11)}`}applyToElement(t,e){const s=d(e),i=this.createGradientElement();this.colors.forEach((([t,e])=>this.appendStopElement(i,t,e))),s.appendChild(i),t.setAttribute("fill",`url(#${this.gradientId})`)}createGradientElement(){const t=document.createElementNS("http://www.w3.org/2000/svg","radialGradient");return t.setAttribute("id",this.gradientId),t.setAttribute("cx","0.5"),t.setAttribute("cy","0.5"),t.setAttribute("r","0.5"),t}appendStopElement(t,e,s){const i=document.createElementNS("http://www.w3.org/2000/svg","stop");i.setAttribute("offset",100*e+"%"),i.setAttribute("stop-color",s),t.appendChild(i)}};class ${constructor(t=null,e=1,s=0,i=new g("black")){this.imageData=t,this.sizeRatio=e,this.padding=s,this.color=i}createSvgElement(t){const e=this.createBaseRect(),s=d(t);return this.imageData?(this.createPattern(this.imageData,s,t),e.setAttribute("fill",`url(#${this.imageData})`)):this.color.applyToElement(e,t),e}createBaseRect(){const t=document.createElementNS(h,"rect");return t.setAttribute("x","0"),t.setAttribute("y","0"),t.setAttribute("width","100%"),t.setAttribute("height","100%"),t}createPattern(t,e,s){const i=document.createElementNS(h,"pattern");i.setAttribute("id",t),i.setAttribute("patternUnits","userSpaceOnUse"),i.setAttribute("width","100%"),i.setAttribute("height","100%");const r=this.createBaseRect();this.color.applyToElement(r,s);const n=this.createImageElement(t);i.appendChild(r),i.appendChild(n),e.appendChild(i)}createImageElement(t){const e=document.createElementNS(h,"image");return e.setAttribute("href",t),e.setAttribute("x","0"),e.setAttribute("y","0"),e.setAttribute("width","100%"),e.setAttribute("height","100%"),e.setAttribute("preserveAspectRatio","xMidYMid slice"),e}}class w{constructor(t=1){this.sizeRatio=t}}const A={Square:class extends w{createSvgElement(t,e,s){const i=s*this.sizeRatio,r=(s-i)/2;return`M${t+r},${e+r} H${t+r+i} V${e+r+i} H${t+r} Z`}},Circle:class extends w{createSvgElement(t,e,s){const i=s/2*this.sizeRatio;return`M${t+s/2},${e+s/2} m-${i},0 a${i},${i} 0 1,0 ${2*i},0 a${i},${i} 0 1,0 -${2*i},0`}},RoundCorners:class extends w{constructor(t=1,e=0){super(t),this.cornerRadius=e}createSvgElement(t,e,s){const i=s*this.sizeRatio,r=(s-i)/2,n=i*this.cornerRadius;return`M${t+r+n},${e+r}\n H${t+r+i-n}\n A${n},${n} 0 0 1 ${t+r+i},${e+r+n}\n V${e+r+i-n}\n A${n},${n} 0 0 1 ${t+r+i-n},${e+r+i}\n H${t+r+n}\n A${n},${n} 0 0 1 ${t+r},${e+r+i-n}\n V${e+r+n}\n A${n},${n} 0 0 1 ${t+r+n},${e+r} Z`}},Rhombus:class extends w{createSvgElement(t,e,s){const i=s*this.sizeRatio,r=(s-i)/2,n=i/2;return`M ${t+r+n},${e+r}\n L ${t+r+i},${e+r+n}\n L ${t+r+n},${e+r+i}\n L ${t+r},${e+r+n} Z`}},Star:class extends w{createSvgElement(t,e,s){const i=s*this.sizeRatio,r=(s-i)/2,n=t+r+i/2,o=e+r+i/2;return`M ${Array.from({length:5},((t,e)=>{const s=(72*e-90)*Math.PI/180;return`${n+i/2*Math.cos(s)},${o+i/2*Math.sin(s)}`})).join(" L ")} Z`}},RoundCornersVertical:class extends w{constructor(t=1,e=0){super(t),this.cornerRadius=e}createSvgElement(t,e,s){const i=s*this.sizeRatio,r=(s-i)/2,n=i*this.cornerRadius;return`M ${t+r+n},${e+r}\n H ${t+r+i-n}\n V ${e+r+i}\n H ${t+r+n} Z`}},RoundCornersHorizontal:class extends w{constructor(t=1,e=0){super(t),this.cornerRadius=e}createSvgElement(t,e,s){const i=s*this.sizeRatio,r=(s-i)/2,n=i*this.cornerRadius;return`M ${t+r},${e+r+n}\n H ${t+r+i}\n V ${e+r+i-n}\n H ${t+r} Z`}},StickyCorners:class extends w{constructor(t=1,e=0){super(t),this.cornerRadius=e}createSvgElement(t,e,s,i){const r=s*this.sizeRatio,n=(s-r)/2,o=r*this.cornerRadius;let a=`M${t+n+r/2},${e+n}`;return i.top||i.right?a+=` H${t+n+r}`:a+=` H${t+n+r-o}\n A${o},${o} 0 0 1 ${t+n+r},${e+n+o}`,i.right||i.bottom?a+=` V${e+n+r}`:a+=` V${e+n+r-o}\n A${o},${o} 0 0 1 ${t+n+r-o},${e+n+r}`,i.bottom||i.left?a+=` H${t+n}`:a+=` H${t+n+o}\n A${o},${o} 0 0 1 ${t+n},${e+n+r-o}`,i.left||i.top?a+=` V${e+n}`:a+=` V${e+n+o}\n A${o},${o} 0 0 1 ${t+n+o},${e+n}`,a+" Z"}},Hexagon:class extends w{createSvgElement(t,e,s){const i=s*this.sizeRatio,r=(s-i)/2,n=i/2,o=i/4;return`M ${t+r+o},${e+r}\n L ${t+r+i-o},${e+r}\n L ${t+r+i},${e+r+n}\n L ${t+r+i-o},${e+r+i}\n L ${t+r+o},${e+r+i}\n L ${t+r},${e+r+n} Z`}},Octagon:class extends w{createSvgElement(t,e,s){const i=s*this.sizeRatio,r=(s-i)/2,n=i/3;return`M ${t+r+n},${e+r}\n L ${t+r+i-n},${e+r}\n L ${t+r+i},${e+r+n}\n L ${t+r+i},${e+r+i-n}\n L ${t+r+i-n},${e+r+i}\n L ${t+r+n},${e+r+i}\n L ${t+r},${e+r+i-n}\n L ${t+r},${e+r+n} Z`}}};class R{constructor(t=3,e=new g("black")){this.size=t,this.color=e}addEyeCoordinates(t,e,s){for(let i=t;i<t+this.size;i++)for(let t=e;t<e+this.size;t++)s.addUsedCoordinate(i,t)}setAttributes(t,e){Object.entries(e).forEach((([e,s])=>t.setAttribute(e,s)))}}const C={Square:class extends R{constructor(t=0,e=3,s){super(e,s),this.cornerRadius=t}createSvgElement(t,e,s){this.addEyeCoordinates(t,e,s);const i=document.createElementNS(h,"rect"),r=this.size,n=Math.min(Math.max(this.cornerRadius,0),.5)*r;return this.setAttributes(i,{x:t.toString(),y:e.toString(),width:r.toString(),height:r.toString(),rx:n.toString(),ry:n.toString()}),this.color.applyToElement(i,s.mainSvg),i}},Circle:class extends R{createSvgElement(t,e,s){this.addEyeCoordinates(t,e,s);const i=document.createElementNS(h,"circle"),r=this.size/2;return this.setAttributes(i,{cx:(t+1.5).toString(),cy:(e+1.5).toString(),r:r.toString()}),this.color.applyToElement(i,s.mainSvg),i}},Rhombus:class extends R{createSvgElement(t,e,s){this.addEyeCoordinates(t,e,s);const i=document.createElementNS(h,"polygon"),r=this.size/2,n=[`${r},0`,`${this.size},${r}`,`${r},${this.size}`,`0,${r}`].map((s=>{const[i,r]=s.split(",").map(Number);return`${i+t},${r+e}`}));return i.setAttribute("points",n.join(" ")),this.color.applyToElement(i,s.mainSvg),i}}};class b{constructor(t=!1,e=!1,s=!1,i=!1,r=!1,n=!1,o=!1,a=!1){this.topLeft=a,this.topRight=r,this.left=i,this.top=t,this.right=e,this.bottomLeft=o,this.bottom=s,this.bottomRight=n}static get empty(){return null===this.emptyInstance&&(this.emptyInstance=new b),this.emptyInstance}}function M(t,e,s){const i=(i,r)=>!t.isOutOfBounds(i,r)&&t.get(i,r)===t.get(e,s);return new b(i(e,s-1),i(e+1,s),i(e,s+1),i(e-1,s),i(e+1,s-1),i(e+1,s+1),i(e-1,s+1),i(e-1,s-1))}b.emptyInstance=null;class x{constructor(t,e=new g("black")){this.pixelShape=t,this.color=e}addEyeFrameCoordinates(t,e,s){for(let i=e;i<e+7;i++)for(let r=s;r<s+7;r++)i!==e&&r!==s&&i!==e+7-1&&r!==s+7-1||t.addUsedCoordinate(i,r)}}const y=class extends x{createSvgElement(t,e,s){if(this.addEyeFrameCoordinates(s,t,e),this.pixelShape instanceof A.StickyCorners){return u([new C.Square(this.pixelShape.cornerRadius,7,this.color).createSvgElement(t,e,s),new C.Square(this.pixelShape.cornerRadius-.05*this.pixelShape.sizeRatio,7-2*this.pixelShape.sizeRatio,s.options.shapes.background?.color??new g("white")).createSvgElement(t+this.pixelShape.sizeRatio,e+this.pixelShape.sizeRatio,s)])}{let i="";for(let r=t;r<t+7;r++)for(let n=e;n<e+7;n++)r!==t&&n!==e&&r!==t+7-1&&n!==e+7-1||(i+=this.pixelShape.createSvgElement(r,n,1,M(s.qrMatrix,r,n)));const r=l(i);return this.color.applyToElement(r,s.mainSvg),r}}},N=class extends x{createSvgElement(t,e,s){this.addEyeFrameCoordinates(s,t,e);const i=t+3.5,r=e+3.5,n=3.5;let o="";if(this.pixelShape instanceof A.StickyCorners){const t=2.5;o=`\n M ${i+n}, ${r}\n A 3.5,3.5 0 1,0 ${i-n},${r}\n A 3.5,3.5 0 1,0 ${i+n},${r}\n M ${i+t}, ${r}\n A ${t},${t} 0 1,1 ${i-t},${r}\n A ${t},${t} 0 1,1 ${i+t},${r}\n `;const e=l(o);return e.setAttribute("fill-rule","evenodd"),this.color.applyToElement(e,s.mainSvg),e}{const a=.5;for(let c=t;c<t+7;c++)for(let t=e;t<e+7;t++){const e=c-i+.5,h=t-r+.5,l=Math.sqrt(e*e+h*h);l>=n-a&&l<=n+a&&(o+=this.pixelShape.createSvgElement(c,t,1,M(s.qrMatrix,c,t)))}const c=l(o);return this.color.applyToElement(c,s.mainSvg),c}}},P="http://www.w3.org/2000/svg";class v{constructor(t=null,e=.2,s=1,i=new g("black")){this.imageData=t,this.sizeRatio=e,this.padding=s,this.color=i}addLogoCoordinates(t,e,s,i,r){for(let n=t;n<t+s;n++)for(let t=e;t<e+i;t++)r.addUsedCoordinate(n,t)}createImageElement(t,e,s,i,r){if(!this.imageData)throw new Error("Image data is not provided.");if(this.imageData.includes("<svg")){const n=(new DOMParser).parseFromString(this.imageData,"image/svg+xml"),o=document.importNode(n.documentElement,!0);o.setAttribute("width",s.toString()),o.setAttribute("height",i.toString()),o.setAttribute("x",t.toString()),o.setAttribute("y",e.toString());const a=document.createElementNS(P,"g");return r&&a.setAttribute("clip-path",`url(#${r})`),a.appendChild(o),a}{const n=document.createElementNS(P,"image");return n.setAttributeNS("http://www.w3.org/1999/xlink","href",this.imageData||""),n.setAttribute("x",t.toString()),n.setAttribute("y",e.toString()),n.setAttribute("width",s.toString()),n.setAttribute("height",i.toString()),r&&n.setAttribute("clip-path",`url(#${r})`),n}}}const z={Square:class extends v{constructor(t,e,s,i,r=0){super(t,e,s,i),this.cornerRadius=r}createSvgElement(t,e){const s=e.qrMatrix.size*this.sizeRatio,i=(e.qrMatrix.size-s)/2,r=(e.qrMatrix.size-s)/2,n=[];this.addLogoCoordinates(Math.round(i),Math.round(r),s,s,e);const o=document.createElementNS(P,"rect");if(o.setAttribute("x",i.toString()),o.setAttribute("y",r.toString()),o.setAttribute("width",s.toString()),o.setAttribute("height",s.toString()),this.cornerRadius>0&&(o.setAttribute("rx",this.cornerRadius.toString()),o.setAttribute("ry",this.cornerRadius.toString())),this.color.applyToElement(o,t),n.push(o),this.imageData){const e=`clipSquare${Math.random().toString(36).substr(2,9)}`;this.createClipPath(t,i,r,s,e);const o=s-2*this.padding,a=this.createImageElement(i+this.padding,r+this.padding,o,o,e);n.push(a)}return u(n)}createClipPath(t,e,s,i,r){const n=d(t),o=document.createElementNS(P,"clipPath");o.setAttribute("id",r);const a=document.createElementNS(P,"rect");a.setAttribute("x",(e+this.padding).toString()),a.setAttribute("y",(s+this.padding).toString()),a.setAttribute("width",(i-2*this.padding).toString()),a.setAttribute("height",(i-2*this.padding).toString()),this.cornerRadius>0&&(a.setAttribute("rx",this.cornerRadius.toString()),a.setAttribute("ry",this.cornerRadius.toString())),o.appendChild(a),n.appendChild(o)}},Circle:class extends v{createSvgElement(t,e){const s=e.qrMatrix.size,i=e.qrMatrix.size,r=s/2,n=i/2,o=Math.min(s,i)*this.sizeRatio/2,a=[];this.addCircleCoordinates(r-.5,n-.5,o,e);const c=document.createElementNS(P,"circle");if(c.setAttribute("cx",r.toString()),c.setAttribute("cy",n.toString()),c.setAttribute("r",o.toString()),this.color.applyToElement(c,t),a.push(c),this.imageData){const e=`clipCircle${Math.random().toString(36).substr(2,9)}`;this.createClipPath(t,r,n,o,e);const s=2*(o-this.padding),i=this.createImageElement(r-(o-this.padding),n-(o-this.padding),s,s,e);a.push(i)}return u(a)}createClipPath(t,e,s,i,r){const n=d(t),o=document.createElementNS(P,"clipPath");o.setAttribute("id",r);const a=document.createElementNS(P,"circle");a.setAttribute("cx",e.toString()),a.setAttribute("cy",s.toString()),a.setAttribute("r",(i-this.padding).toString()),o.appendChild(a),n.appendChild(o)}addCircleCoordinates(t,e,s,i){const r=Math.floor(t-s),n=Math.ceil(t+s),o=Math.floor(e-s),a=Math.ceil(e+s);for(let c=r;c<n;c++)for(let r=o;r<a;r++){Math.sqrt((c-t)**2+(r-e)**2)<=s&&i.addUsedCoordinate(c,r)}}},Rhombus:class extends v{createSvgElement(t,e){const s=e.qrMatrix.size*this.sizeRatio,i=e.qrMatrix.size/2,r=e.qrMatrix.size/2,n=s/2,o=[];this.addRhombusLogoCoordinates(i-.5,r-.5,n,e);const a=[`${i},${r-n}`,`${i+n},${r}`,`${i},${r+n}`,`${i-n},${r}`].join(" "),c=document.createElementNS(P,"polygon");if(c.setAttribute("points",a),this.color.applyToElement(c,t),o.push(c),this.imageData){const e=`clipRhombus${Math.random().toString(36).substr(2,9)}`;this.createClipPath(t,i,r,n,e);const s=2*(n-this.padding),a=this.createImageElement(i-(n-this.padding),r-(n-this.padding),s,s,e);o.push(a)}return u(o)}createClipPath(t,e,s,i,r){const n=d(t),o=document.createElementNS(P,"clipPath");o.setAttribute("id",r);const a=i-this.padding,c=[`${e},${s-a}`,`${e+a},${s}`,`${e},${s+a}`,`${e-a},${s}`].join(" "),h=document.createElementNS(P,"polygon");h.setAttribute("points",c),o.appendChild(h),n.appendChild(o)}addRhombusLogoCoordinates(t,e,s,i){const r=Math.floor(t-s),n=Math.ceil(t+s),o=Math.floor(e-s),a=Math.ceil(e+s);for(let c=r;c<=n;c++)for(let r=o;r<=a;r++){Math.abs(c-t)/s+Math.abs(r-e)/s<=1&&i.addUsedCoordinate(c,r)}}}};class I{constructor(t=new A.Square,e=new g("black")){this.pixelShape=t,this.color=e}createSvgElement(t,e,s){let i="";const r=s.qrMatrix.size;for(let n=t;n<r;n++)for(let t=e;t<r;t++)if(this.isDarkPixel(n,t,s)){s.addUsedCoordinate(n,t);const e=M(s.qrMatrix,n,t);i+=this.pixelShape.createSvgElement(n,t,1,e)}const n=l(i);return this.color.applyToElement(n,s.mainSvg),n}isDarkPixel(e,s,i){return i.qrMatrix.get(e,s)===t.DarkPixel&&!i.isUsedCoordinate(e,s)}}class L{constructor(t){this.seed=t}nextBoolean(){const t=1e4*Math.sin(this.seed++);return t-Math.floor(t)>.5}}const T=class{constructor(){this.qrOriginStart=[0,0]}apply(t){return t}pixelInShape(){return!0}},q=class{constructor(t=233){this.random=new L(t),this.addedPoints=new Set,this.qrOriginStart=[0,0]}apply(t){const s=Math.round((t.size*Math.sqrt(2)-t.size)/2),i=t.size+2*s,r=new e(i),n=i/2;return this.qrOriginStart=[n-t.size/2,n-t.size/2],this.fillCircularPixels(r,t,s,n,i),this.copyOriginalMatrix(t,r,s),r}pixelInShape(t,e){return this.addedPoints.has(`${t},${e}`)}fillCircularPixels(e,s,i,r,n){for(let o=0;o<n;o++)for(let a=0;a<n;a++)if(this.isInCircularArea(o,a,r,s.size,i)&&!this.isAdjacentToEyeFrame(o,a,7,n,this.qrOriginStart)){const s=this.random.nextBoolean();e.set(o,a,s?t.DarkPixel:t.Background),s&&this.addedPoints.add(`${o},${a}`)}}copyOriginalMatrix(t,e,s){for(let i=0;i<t.size;i++)for(let r=0;r<t.size;r++)e.set(s+i,s+r,t.get(i,r))}isInCircularArea(t,e,s,i,r){return(t<=r-1||e<=r-1||t>=r+i||e>=r+i)&&Math.sqrt((s-t)*(s-t-.5)+(s-e)*(s-e-.5))<=s}isAdjacentToEyeFrame(t,e,s,i,r){return[{x:r[0],y:r[1],sides:["top","left"]},{x:r[0],y:i-r[1]-s,sides:["bottom","left"]},{x:i-r[0]-s,y:r[1],sides:["top","right"]}].some((({x:i,y:r,sides:n})=>this.isPixelAdjacentToEyeFrame(t,e,i,r,n,s)))}isPixelAdjacentToEyeFrame(t,e,s,i,r,n){return r.includes("left")&&t===s-1&&e>=i&&e<i+n||r.includes("right")&&t===s+n&&e>=i&&e<i+n||r.includes("top")&&e===i-1&&t>=s&&t<s+n||r.includes("bottom")&&e===i+n&&t>=s&&t<s+n}};class k{constructor(t,e=new g("black")){this.pixelShape=t,this.color=e}createSvgElement(t,e,s){let i="";const r=s.qrXEnd-7;for(let n=t+1;n<r;n++)i+=this.processPixel(t,n,s),i+=this.processPixel(n,e,s);const n=l(i);return this.color.applyToElement(n,s.mainSvg),n}processPixel(e,s,i){return i.qrMatrix.get(e,s)===t.DarkPixel?(i.addUsedCoordinate(e,s),this.pixelShape.createSvgElement(e,s,1,M(i.qrMatrix,e,s))):""}}class D{constructor(t=null,e=null,s=null,i=null,r=null,n,o,a=null){this.alignmentPattern=t,this.background=e,this.eyeFrame=s,this.eye=i,this.logo=r,this.timingLine=a,this.matrixPixel=n??new I(new A.Square),this.qrCode=o??new T}}class O{constructor(t,e=new g("black")){this.pixelShape=t,this.color=e}addAlignmentPatternCoordinates(t,e,s){for(let i=e;i<e+5;i++)for(let e=s;e<s+5;e++)t.addUsedCoordinate(i,e)}}const B={Square:class extends O{createSvgElement(t,e,s){if(this.addAlignmentPatternCoordinates(s,t,e),this.pixelShape instanceof A.StickyCorners){return u([new C.Square(this.pixelShape.cornerRadius,5,this.color).createSvgElement(t,e,s),new C.Square(this.pixelShape.cornerRadius-.05*this.pixelShape.sizeRatio,5-2*this.pixelShape.sizeRatio,s.options.shapes.background?.color??new g("white")).createSvgElement(t+this.pixelShape.sizeRatio,e+this.pixelShape.sizeRatio,s),this.createPixelPath(t,e,s)])}return this.createSimpleSquarePath(t,e,s)}createPixelPath(t,e,s){const i=l(this.pixelShape.createSvgElement(t+2,e+2,1,M(s.qrMatrix,t+2,e+2)));return this.color.applyToElement(i,s.mainSvg),i}createSimpleSquarePath(t,e,s){let i="";for(let r=t;r<t+5;r++)for(let n=e;n<e+5;n++)r!==t&&n!==e&&r!==t+5-1&&n!==e+5-1||(i+=this.pixelShape.createSvgElement(r,n,1,M(s.qrMatrix,r,n)));i+=this.pixelShape.createSvgElement(t+2,e+2,1,M(s.qrMatrix,t+2,e+2));const r=l(i);return this.color.applyToElement(r,s.mainSvg),r}},Circle:class extends O{createSvgElement(t,e,s){this.addAlignmentPatternCoordinates(s,t,e);const i=t+2.5,r=e+2.5,n=l(`${this.createCirclePathData(i,r,2.5)}${this.pixelShape.createSvgElement(t+2,e+2,1,M(s.qrMatrix,t+2,e+2))}`);return n.setAttribute("fill-rule","evenodd"),this.color.applyToElement(n,s.mainSvg),n}createCirclePathData(t,e,s){const i=s-1;return`\n M ${t+s}, ${e}\n A ${s},${s} 0 1,0 ${t-s},${e}\n A ${s},${s} 0 1,0 ${t+s},${e}\n M ${t+i}, ${e}\n A ${i},${i} 0 1,1 ${t-i},${e}\n A ${i},${i} 0 1,1 ${t+i},${e}\n `}}};function H(t){return new D(t.alignmentPattern?function(t){return new B.Square(U(t.pixelShape),t.color?V(t.color):void 0)}(t.alignmentPattern):null,t.background?function(t){const e=t.color?V(t.color):void 0;return new $(t.image,1,0,e)}(t.background):null,t.eyeFrame?function(t){return"Circle"===t.type?new N(U(t.pixelShape),t.color?V(t.color):void 0):new y(U(t.pixelShape),t.color?V(t.color):void 0)}(t.eyeFrame):null,t.eye?function(t){const e=t.color?V(t.color):void 0;switch(t.type){case"Circle":return new C.Circle(3,e);case"Rhombus":return new C.Rhombus(3,e);default:return new C.Square(t.cornerRadius??0,3,e)}}(t.eye):null,t.logo?function(t){const e=t.color?V(t.color):void 0;switch(t.type){case"Circle":return new z.Circle(t.image,t.sizeRatio,t.padding,e);case"Rhombus":return new z.Rhombus(t.image,t.sizeRatio,t.padding,e);default:return new z.Square(t.image,t.sizeRatio,t.padding,e)}}(t.logo):null,t.matrixPixel?function(t){return new I(t.pixelShape?U(t.pixelShape):void 0,t.color?V(t.color):void 0)}(t.matrixPixel):null,t.qrCode?F(t.qrCode):null,t.timingLine?_(t.timingLine):null)}function U(t){switch(t.type){case"Circle":return new A.Circle(t.sizeRatio);case"RoundCorners":return new A.RoundCorners(t.sizeRatio,t.cornerRadius);case"StickyCorners":return new A.StickyCorners(t.sizeRatio,t.cornerRadius);case"Square":return new A.Square(t.sizeRatio);case"Rhombus":return new A.Rhombus(t.sizeRatio);case"Star":return new A.Star(t.sizeRatio);case"RoundCornersVertical":return new A.RoundCornersVertical(t.sizeRatio,t.cornerRadius);case"RoundCornersHorizontal":return new A.RoundCornersHorizontal(t.sizeRatio,t.cornerRadius);case"Hexagon":return new A.Hexagon(t.sizeRatio);case"Octagon":return new A.Octagon(t.sizeRatio)}}function F(t){return"Circle"===t.type?new q(t.seed):new T}function _(t){return new k(U(t.pixelShape),t.color?V(t.color):void 0)}function V(t){switch(t.type){case"LinearGradient":return new S(t.colors,p.fromString(t.orientation));case"RadialGradient":return new f(t.colors,t.radius);case"SweepGradient":return new E(t.colors);default:return new g(t.value)}}class G{constructor(t){this.sizeRatio=t.sizeRatio??1,this.shapes=t.shapes?H(t.shapes):new D(null,null,null,null,null,null,null,null),this.errorCorrectionLevel=t.errorCorrectionLevel?a.fromString(t.errorCorrectionLevel):a.HIGH}}class Y{constructor(t,e,s){this.qrMatrix=t,this.options=e,this.mainSvg=s,this.usedCoordinates=new Set}get qrXOrigin(){return this.shapes.qrCode.qrOriginStart[0]}get qrYOrigin(){return this.shapes.qrCode.qrOriginStart[1]}get qrXEnd(){return this.qrMatrix.size-this.qrXOrigin}get qrYEnd(){return this.qrMatrix.size-this.qrYOrigin}get shapes(){return this.options.shapes}addUsedCoordinate(t,e){this.usedCoordinates.add(`${t},${e}`)}isUsedCoordinate(t,e){return this.usedCoordinates.has(`${t},${e}`)}get qrCodeElementStartCoordinate(){const{qrXOrigin:t,qrYOrigin:e,qrXEnd:s,qrYEnd:i}=this,r=[{x:t,y:e},{x:s-7,y:e},{x:t,y:i-7}];return{timingLinePosition:{x:t+7-1,y:e+7-1},eyesFramesPositions:r,eyesPositions:r.map((({x:t,y:e})=>({x:t+2,y:e+2}))),alignmentPatternPosition:{x:s-9,y:i-9}}}drawSvg(){if(!this.qrMatrix)throw new Error("No QR matrix set");const{shapes:t,mainSvg:e,qrCodeElementStartCoordinate:s}=this,i=[];t.background&&e.appendChild(t.background.createSvgElement(e)),t.timingLine&&i.push(t.timingLine.createSvgElement(s.timingLinePosition.x,s.timingLinePosition.y,this)),t.eyeFrame&&s.eyesFramesPositions.forEach((({x:e,y:s})=>{i.push(t.eyeFrame.createSvgElement(e,s,this))})),t.eye&&s.eyesPositions.forEach((({x:e,y:s})=>{i.push(t.eye.createSvgElement(e,s,this))})),t.logo&&i.push(t.logo.createSvgElement(e,this)),t.alignmentPattern&&i.push(t.alignmentPattern.createSvgElement(s.alignmentPatternPosition.x,s.alignmentPatternPosition.y,this)),i.push(t.matrixPixel.createSvgElement(0,0,this));const r=u(i),n=m(this.qrMatrix.size,this.options.sizeRatio)/2;r.setAttribute("transform",`translate(${n}, ${n})`),e.appendChild(r)}}class j{constructor(t){this.value=t}encode(){return this.value}}class X{constructor(t){this.url=t}encode(){return this.url}}class W{constructor(t,e,s,i){this.email=t,this.copyTo=e,this.subject=s,this.body=i}encode(){const t=[];this.copyTo&&t.push(`cc=${this.copyTo}`),this.subject&&t.push(`subject=${this.escape(this.subject)}`),this.body&&t.push(`body=${this.escape(this.body)}`);const e=t.length>0?`?${t.join("&")}`:"";return`mailto:${this.email}${e}`}escape(t){return encodeURIComponent(t).replace(/\+/g," ")}}class Z{constructor(t,e){this.lat=t,this.lon=e}encode(){return`GEO:${this.lat},${this.lon}`}}class K{constructor(t,e){this.url=t,this.title=e}encode(){return`MEBKM:URL:${this.url};TITLE:${this.title};`}}var Q;!function(t){t.WEP="WEP",t.WPA="WPA",t.OPEN="nopass"}(Q||(Q={}));class J{constructor(t,e,s,i=!1){this.authentication=t,this.ssid=e,this.psk=s,this.hidden=i}encode(){return"WIFI:"+(this.ssid?`S:${J.escape(this.ssid)};`:"")+(this.authentication?`T:${this.authentication};`:"")+(this.psk?`P:${J.escape(this.psk)};`:"")+`H:${this.hidden};`}static escape(t){return t.replace(/[\\,;."']/g,(t=>`\\${t}`))}}class tt{constructor(t,e,s=!1,i,r,n){this.ssid=t,this.psk=e,this.hidden=s,this.user=i,this.eap=r,this.phase=n}encode(){return"WIFI:"+(this.ssid?`S:${J.escape(this.ssid)};`:"")+(this.user?`U:${J.escape(this.user)};`:"")+(this.psk?`P:${J.escape(this.psk)};`:"")+(this.eap?`E:${J.escape(this.eap)};`:"")+(this.phase?`PH:${J.escape(this.phase)};`:"")+`H:${this.hidden};`}}class et{constructor(t){this.phoneNumber=t}encode(){return`TEL:${this.phoneNumber}`}}class st{constructor(t,e,s=!1){this.phoneNumber=t,this.subject=e,this.isMMS=s}encode(){return`${this.isMMS?"MMS":"SMS"}:${this.phoneNumber}${this.subject?`:${this.subject}`:""}`}}class it{constructor(t,e,s,i,r,n,o){this.firstName=t,this.secondName=e,this.job=s,this.company=i,this.address=r,this.phone=n,this.email=o}encode(){return"BIZCARD:"+(this.firstName?`N:${this.firstName};`:"")+(this.secondName?`X:${this.secondName};`:"")+(this.job?`T:${this.job};`:"")+(this.company?`C:${this.company};`:"")+(this.address?`A:${this.address};`:"")+(this.phone?`B:${this.phone};`:"")+(this.email?`E:${this.email};`:"")+";"}}class rt{constructor(t,e,s,i,r,n,o,a){this.name=t,this.company=e,this.title=s,this.phoneNumber=i,this.email=r,this.address=n,this.website=o,this.note=a}encode(){return"BEGIN:VCARD\nVERSION:3.0\n"+(this.name?`N:${this.name}\n`:"")+(this.company?`ORG:${this.company}\n`:"")+(this.title?`TITLE:${this.title}\n`:"")+(this.phoneNumber?`TEL:${this.phoneNumber}\n`:"")+(this.website?`URL:${this.website}\n`:"")+(this.email?`EMAIL:${this.email}\n`:"")+(this.address?`ADR:${this.address}\n`:"")+(this.note?`NOTE:${this.note}\n`:"")+"END:VCARD"}}class nt{constructor(t,e,s,i){this.name=t,this.address=e,this.phoneNumber=s,this.email=i}encode(){return"MECARD:"+(this.name?`N:${this.name};`:"")+(this.address?`ADR:${this.address};`:"")+(this.phoneNumber?`TEL:${this.phoneNumber};`:"")+(this.email?`EMAIL:${this.email};`:"")+";"}}class ot{constructor(t){this.videoId=t}encode(){return`YOUTUBE:${this.videoId}`}}class at{constructor(t,e,s,i,r,n){this.uid=t,this.stamp=e,this.organizer=s,this.start=i,this.end=r,this.summary=n}encode(){return"BEGIN:VEVENT\n"+(this.uid?`UID:${this.uid}\n`:"")+(this.stamp?`DTSTAMP:${this.stamp}\n`:"")+(this.organizer?`ORGANIZER:${this.organizer}\n`:"")+(this.start?`DTSTART:${this.start}\n`:"")+(this.end?`DTEND:${this.end}\n`:"")+(this.summary?`SUMMARY:${this.summary}\n`:"")+"END:VEVENT"}}class ct{constructor(t){this.appPackage=t}encode(){return`market://details?id=${this.appPackage}`}}function ht(t){switch(t.type){case"Text":return new j(t.data.value);case"Url":return new X(t.data.url);case"Email":return new W(t.data.email,t.data.copyTo,t.data.subject,t.data.body);case"GeoPos":return new Z(t.data.lat,t.data.lon);case"Bookmark":return new K(t.data.url,t.data.title);case"Wifi":return new J(t.data.authentication,t.data.ssid,t.data.psk,t.data.hidden??!1);case"EnterpriseWifi":return new tt(t.data.ssid,t.data.psk,t.data.hidden??!1,t.data.user,t.data.eap,t.data.phase);case"Phone":return new et(t.data.phoneNumber);case"SMS":return new st(t.data.phoneNumber,t.data.subject,t.data.isMMS);case"BizCard":return new it(t.data.firstName,t.data.secondName,t.data.job,t.data.company,t.data.address,t.data.phone,t.data.email);case"VCard":return new rt(t.data.name,t.data.company,t.data.title,t.data.phoneNumber,t.data.email,t.data.address,t.data.website,t.data.note);case"MeCard":return new nt(t.data.name,t.data.address,t.data.phoneNumber,t.data.email);case"YouTube":return new ot(t.data.videoId);case"Event":return new at(t.data.uid,t.data.stamp,t.data.organizer,t.data.start,t.data.end,t.data.summary);case"GooglePlay":return new ct(t.data.appPackage)}}function lt(t,e){return new ut(t,ht(e.data),new G(e.options??{}))}class ut{constructor(t,i,r){this.svg=t,this.options=r;const n=s.encodeText(i.encode(),r.errorCorrectionLevel);this.codeMatrix=r.shapes.qrCode.apply(e.fromQrMatrix(n))}generateSvg(){let t;this.svg.innerHTML="",t=0!==this.options.sizeRatio?this.codeMatrix.size+m(this.codeMatrix.size,this.options.sizeRatio):0,this.svg.setAttribute("viewBox",`0 0 ${t} ${t}`),this.svg.setAttribute("xmlns","http://www.w3.org/2000/svg"),new Y(this.codeMatrix,this.options,this.svg).drawSvg()}}export{lt as QrCodeGenerator,ht as createQrDataFromConfig,F as createQrShape,H as createQrShapesFromConfig,_ as createQrTimingLineShape}; //# sourceMappingURL=index.mjs.map