qrmake 0.0.0-stage → 1.0.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/cli.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import{readFileSync as Ye,writeFileSync as Ze}from"fs";var k=class extends RangeError{constructor(t){super(t),this.name="QRError"}},V={L:0,M:1,Q:2,H:3},Me={L:1,M:0,Q:3,H:2},Z=["L","M","Q","H"],ee=[[0,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],[0,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],[0,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],[0,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]],te=[[0,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],[0,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],[0,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],[0,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]],$e={numeric:1,alphanumeric:2,byte:4,kanji:8},Ce={numeric:[10,12,14],alphanumeric:[9,11,13],byte:[8,16,16],kanji:[8,10,12]},O=["numeric","alphanumeric","byte","kanji"],ne="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",re=e=>e<=9?0:e<=26?1:2,D=(e,t)=>Ce[e][re(t)];function oe(e){let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}function I(e,t){let n=V[t];return(oe(e)>>3)-ee[n][e]*te[n][e]}function Ue(e){if(e===1)return[];let t=Math.floor(e/7)+2,n=Math.floor((e*8+t*3+5)/(t*4-4))*2,r=[6];for(let o=e*4+10;r.length<t;o-=n)r.splice(1,0,o);return r}var L=new Uint8Array(512),T=new Uint8Array(256);{let e=1;for(let t=0;t<255;t++)L[t]=e,T[e]=t,e<<=1,e&256&&(e^=285);for(let t=255;t<512;t++)L[t]=L[t-255]}var z=(e,t)=>e===0||t===0?0:L[T[e]+T[t]],W=new Map;function ve(e){let t=W.get(e);if(t)return t;t=new Uint8Array(e),t[e-1]=1;let n=1;for(let r=0;r<e;r++){for(let o=0;o<e;o++)t[o]=z(t[o],n)^(o+1<e?t[o+1]:0);n=z(n,2)}return W.set(e,t),t}function Se(e,t){let n=ve(t),r=new Uint8Array(t);for(let o=0;o<e.length;o++){let i=e[o]^r[0];if(r.copyWithin(0,1),r[t-1]=0,i!==0)for(let s=0;s<t;s++)r[s]^=z(n[s],i)}return r}function Re(e,t,n){let r=V[n],o=te[r][t],i=ee[r][t],s=oe(t)>>3;if(e.length!==s-i*o)throw new k("Invalid data length");let a=o-s%o,l=Math.floor(s/o)-i,c=[],u=[];for(let f=0,g=0;f<o;f++){let h=l+(f<a?0:1),d=e.subarray(g,g+h);g+=h,c.push(d),u.push(Se(d,i))}let m=new Uint8Array(s),b=0;for(let f=0;f<=l;f++)for(let g of c)f<g.length&&(m[b++]=g[f]);for(let f=0;f<i;f++)for(let g of u)m[b++]=g[f];return m}var G=class{constructor(){this.bits=[]}put(t,n){for(let r=n-1;r>=0;r--)this.bits.push(t>>>r&1)}};function Ee(e){return e<128?[e]:e<2048?[192|e>>6,128|e&63]:(e>=55296&&e<=57343&&(e=65533),e<65536?[224|e>>12,128|e>>6&63,128|e&63]:[240|e>>18,128|e>>12&63,128|e>>6&63,128|e&63])}var v;function Ie(){if(v!==void 0)return v;try{let e=new TextDecoder("shift_jis",{fatal:!0}),t=new Map,n=new Uint8Array(2);for(let r=129;r<=235;r++)if(!(r>159&&r<224))for(let o=64;o<=252;o++){if(o===127||r===235&&o>191)continue;n[0]=r,n[1]=o;let i;try{i=e.decode(n)}catch{continue}let s=i.codePointAt(0);i.length===1&&!t.has(s)&&t.set(s,r<<8|o)}v=t.size>0?t:null}catch{v=null}return v}function ie(e,t){let n=t?Ie():null;if(t&&!n)throw new k("Kanji mode needs TextDecoder with Shift JIS support, which this runtime lacks");let r=[];for(let o of e){let i=o.codePointAt(0);r.push({bytes:Ee(i),numeric:i>=48&&i<=57,alnum:i<128?ne.indexOf(o):-1,sjis:n?.get(i)??-1})}return r}function se(e){return Array.from(e,t=>({bytes:[t],numeric:t>=48&&t<=57,alnum:t<128?ne.indexOf(String.fromCharCode(t)):-1,sjis:-1}))}var _=(e,t)=>t==="byte"||(t==="numeric"?e.numeric:t==="alphanumeric"?e.alnum>=0:e.sjis>=0);function Le(e){let t=e.units.length;switch(e.mode){case"numeric":return Math.floor(t/3)*10+[0,4,7][t%3];case"alphanumeric":return Math.floor(t/2)*11+t%2*6;case"kanji":return t*13;default:return e.units.reduce((n,r)=>n+r.bytes.length*8,0)}}var H=e=>e.mode==="byte"?e.units.reduce((t,n)=>t+n.bytes.length,0):e.units.length;function X(e,t,n){let r=n?12:0;for(let o of e){let i=D(o.mode,t);if(H(o)>=2**i)return 1/0;r+=4+i+Le(o)}return r}function Oe(e,t,n){if(e.length===0)return[{mode:"byte",units:[]}];let r=n?O:O.slice(0,3),o=r.length,i=r.map(m=>(4+D(m,t))*6),s=i.slice(),a=[];for(let m of e){let b=new Array(o).fill(1/0),f=new Int8Array(o).fill(-1);for(let d=0;d<o;d++){let y=r[d];if(!_(m,y))continue;let w=y==="byte"?m.bytes.length*48:y==="numeric"?20:y==="alphanumeric"?33:78;b[d]=s[d]+w,f[d]=d}let g=b.slice(),h=f.slice();for(let d=0;d<o;d++)for(let y=0;y<o;y++){if(h[y]!==y)continue;let w=Math.ceil(g[y]/6)*6+i[d];w<b[d]&&(b[d]=w,f[d]=y)}a.push(f),s=b}let l=0;for(let m=1;m<o;m++)s[m]<s[l]&&(l=m);let c=new Array(e.length);for(let m=e.length-1;m>=0;m--)l=a[m][l],c[m]=l;let u=[];for(let m=0;m<e.length;m++){let b=r[c[m]],f=u[u.length-1];f&&f.mode===b?f.units.push(e[m]):u.push({mode:b,units:[e[m]]})}return u}function je(e,t){for(let n of["numeric","alphanumeric",...t?["kanji"]:[]])if(e.length>0&&e.every(r=>_(r,n)))return{mode:n,units:e};return{mode:"byte",units:e}}function ae(e,t,n){let r=e.findIndex(o=>!_(o,t));if(r>=0){let o=String.fromCodePoint(...n?[Array.from(n)[r].codePointAt(0)]:e[r].bytes);throw new k(`Cannot encode ${JSON.stringify(o)} in ${t} mode`)}return{mode:t,units:e}}function Pe(e){if(!e||!O.includes(e.mode))throw new k(`Invalid segment mode: ${String(e?.mode)}`);let{mode:t,data:n}=e;if(typeof n!="string"&&!(n instanceof Uint8Array))throw new TypeError("Segment data must be a string or Uint8Array");if(t==="kanji"&&n instanceof Uint8Array){if(n.length%2)throw new k("Kanji segment bytes must be Shift JIS pairs");let o=[];for(let i=0;i<n.length;i+=2){let s=n[i]<<8|n[i+1];if(!(s>=33088&&s<=40956||s>=57408&&s<=60351))throw new k(`Shift JIS code 0x${s.toString(16)} is outside the kanji mode ranges`);o.push({bytes:[],numeric:!1,alnum:-1,sjis:s})}return{mode:t,units:o}}let r=typeof n=="string"?ie(n,t==="kanji"):se(n);return ae(r,t,typeof n=="string"?n:"")}function Qe(e,t,n){e.put($e[t.mode],4),e.put(H(t),D(t.mode,n));let{units:r}=t;switch(t.mode){case"numeric":for(let o=0;o<r.length;o+=3){let i=r.slice(o,o+3),s=Number(i.map(a=>String.fromCharCode(a.bytes[0])).join(""));e.put(s,i.length*3+1)}break;case"alphanumeric":for(let o=0;o<r.length;o+=2)o+1<r.length?e.put(r[o].alnum*45+r[o+1].alnum,11):e.put(r[o].alnum,6);break;case"kanji":for(let o of r){let i=o.sjis-(o.sjis<=40956?33088:49472);e.put((i>>8)*192+(i&255),13)}break;default:for(let o of r)for(let i of o.bytes)e.put(i,8)}}var Ne=21522;function Y(e,t){let n=Me[e]<<3|t,r=n;for(let o=0;o<10;o++)r=r<<1^(r>>>9)*1335;return(n<<10|r)^Ne}function Te(e){let t=e;for(let n=0;n<12;n++)t=t<<1^(t>>>11)*7973;return e<<12|t}var ze=[(e,t)=>(e+t)%2===0,(e,t)=>t%2===0,e=>e%3===0,(e,t)=>(e+t)%3===0,(e,t)=>(Math.floor(e/3)+Math.floor(t/2))%2===0,(e,t)=>e*t%2+e*t%3===0,(e,t)=>(e*t%2+e*t%3)%2===0,(e,t)=>((e+t)%2+e*t%3)%2===0],B=class{constructor(t){this.size=t;this.modules=new Uint8Array(t*t),this.reserved=new Uint8Array(t*t)}fn(t,n,r){let o=n*this.size+t;this.modules[o]=r?1:0,this.reserved[o]=1}};function Ge(e,t){let{size:n}=e;for(let i=0;i<n;i++)e.fn(6,i,i%2===0),e.fn(i,6,i%2===0);for(let[i,s]of[[3,3],[n-4,3],[3,n-4]])for(let a=-4;a<=4;a++)for(let l=-4;l<=4;l++){let c=i+l,u=s+a;if(c<0||u<0||c>=n||u>=n)continue;let m=Math.max(Math.abs(l),Math.abs(a));e.fn(c,u,m!==2&&m!==4)}let r=Ue(t),o=r.length-1;for(let i=0;i<=o;i++)for(let s=0;s<=o;s++)if(!(i===0&&s===0||i===0&&s===o||i===o&&s===0))for(let a=-2;a<=2;a++)for(let l=-2;l<=2;l++)e.fn(r[i]+l,r[s]+a,Math.max(Math.abs(l),Math.abs(a))!==1);if(q(e,0),t>=7){let i=Te(t);for(let s=0;s<18;s++){let a=(i>>>s&1)===1,l=n-11+s%3,c=Math.floor(s/3);e.fn(l,c,a),e.fn(c,l,a)}}}function q(e,t){let{size:n}=e,r=o=>(t>>>o&1)===1;for(let o=0;o<=5;o++)e.fn(8,o,r(o));e.fn(8,7,r(6)),e.fn(8,8,r(7)),e.fn(7,8,r(8));for(let o=9;o<15;o++)e.fn(14-o,8,r(o));for(let o=0;o<8;o++)e.fn(n-1-o,8,r(o));for(let o=8;o<15;o++)e.fn(8,n-15+o,r(o));e.fn(8,n-8,!0)}function Be(e,t){let{size:n,modules:r,reserved:o}=e,i=t.length*8,s=0;for(let a=n-1;a>=1;a-=2){a===6&&(a=5);let l=(a+1&2)===0;for(let c=0;c<n;c++){let u=l?n-1-c:c;for(let m=0;m<2;m++){let b=u*n+a-m;o[b]||(s<i&&(r[b]=t[s>>>3]>>>7-(s&7)&1),s++)}}}}function Q(e,t){let{size:n,modules:r,reserved:o}=e,i=ze[t];for(let s=0;s<n;s++)for(let a=0;a<n;a++){let l=s*n+a;!o[l]&&i(a,s)&&(r[l]^=1)}}function qe(e,t){let n=0,r=0,o=(i,s)=>e[s*t+i];for(let i=0;i<2;i++){let s=i===0?(a,l)=>o(l,a):o;for(let a=0;a<t;a++){let l=1;for(let c=1;c<=t;c++)c<t&&s(a,c)===s(a,c-1)?l++:(l>=5&&(n+=l-2),l=1);for(let c=0;c+6<t;c++)if(s(a,c)&&!s(a,c+1)&&s(a,c+2)&&s(a,c+3)&&s(a,c+4)&&!s(a,c+5)&&s(a,c+6)){let u=c>=4&&!s(a,c-1)&&!s(a,c-2)&&!s(a,c-3)&&!s(a,c-4),m=c+10<t&&!s(a,c+7)&&!s(a,c+8)&&!s(a,c+9)&&!s(a,c+10);u&&(n+=40),m&&(n+=40)}}}for(let i=0;i<t-1;i++)for(let s=0;s<t-1;s++){let a=o(s,i);a===o(s+1,i)&&a===o(s,i+1)&&a===o(s+1,i+1)&&(n+=3)}for(let i=0;i<e.length;i++)r+=e[i];return n+=Math.floor(Math.abs(r*100/e.length-50)/5)*10,n}function N(e,t){if(typeof e!="number"||!Number.isInteger(e)||e<1||e>40)throw new k(`${t} must be an integer from 1 to 40, got ${String(e)}`)}function Ve(e){if(!Z.includes(e))throw new k(`ecl must be 'L', 'M', 'Q' or 'H', got ${JSON.stringify(e)}`)}function ce(e,t={}){let n=t.ecl??"M";Ve(n);let r=t.minVersion??1,o=t.maxVersion??40;if(t.version!==void 0&&(N(t.version,"version"),r=o=t.version),N(r,"minVersion"),N(o,"maxVersion"),r>o)throw new k(`minVersion (${r}) is greater than maxVersion (${o})`);let i=t.mask;if(i!==void 0&&!(Number.isInteger(i)&&i>=0&&i<=7))throw new k(`mask must be an integer from 0 to 7, got ${String(i)}`);if(t.mode!==void 0&&!O.includes(t.mode))throw new k(`Invalid mode: ${String(t.mode)}`);let s=t.kanji===!0||t.mode==="kanji",a,l=!1;if(typeof e=="string"||e instanceof Uint8Array){let p=typeof e=="string"?ie(e,s):se(e);if(l=p.some(x=>x.bytes.length>1||(x.bytes[0]??0)>127),t.mode){let x=ae(p,t.mode,typeof e=="string"?e:"");a=()=>[x]}else if(t.optimize===!1){let x=je(p,s);a=()=>[x]}else{let x=[];a=$=>x[re($)]??=Oe(p,$,s)}}else if(Array.isArray(e)){let p=e.map(Pe);l=p.some(x=>x.mode==="byte"&&x.units.some($=>$.bytes[0]>127)),a=()=>p}else throw new TypeError(`qrmake: expected a string, Uint8Array or array of segments, got ${e===null?"null":typeof e}`);let c=t.eci===!0&&l,u=r,m=a(u),b=X(m,u,c);for(;b>I(u,n)*8;){if(u>=o){let p=I(o,n)*8;throw new k(Number.isFinite(b)?`Data too long: needs ${b} bits, but version ${o}-${n} holds ${p}`:`Data too long for version ${o}-${n}`)}u++,m=a(u),b=X(m,u,c)}let f=n;if(t.boostEcl)for(let p of Z.slice(V[n]+1))b<=I(u,p)*8&&(f=p);let g=I(u,f)*8,h=new G;c&&(h.put(7,4),h.put(26,8));for(let p of m)Qe(h,p,u);h.put(0,Math.min(4,g-h.bits.length)),h.put(0,(8-h.bits.length%8)%8);let d=new Uint8Array(g/8);for(let p=0;p<h.bits.length;p++)d[p>>>3]|=h.bits[p]<<7-(p&7);for(let p=h.bits.length/8,x=236;p<d.length;p++,x^=253)d[p]=x;let y=Re(d,u,f),w=u*4+17,M=new B(w);Ge(M,u),Be(M,y);let E=i??0;if(i===void 0){let p=1/0;for(let x=0;x<8;x++){Q(M,x),q(M,Y(f,x));let $=qe(M.modules,w);$<p&&(p=$,E=x),Q(M,x)}}return Q(M,E),q(M,Y(f,E)),De(u,f,E,m.map(p=>({mode:p.mode,length:H(p)})),M.modules)}function De(e,t,n,r,o){let i=e*4+17;return{version:e,size:i,ecl:t,mask:n,segments:r,modules:o,get(s,a){return s>=0&&a>=0&&s<i&&a<i&&o[a*i+s]===1},toArray(){return Array.from({length:i},(s,a)=>Array.from(o.subarray(a*i,(a+1)*i),l=>l===1))}}}function ue(e){return typeof e=="object"&&e!==null&&e.modules instanceof Uint8Array&&typeof e.size=="number"&&typeof e.get=="function"}var _e=(()=>{let e=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;e[t]=n>>>0}return e})();function He(e,t=0){t=~t;for(let n=0;n<e.length;n++)t=_e[(t^e[n])&255]^t>>>8;return~t>>>0}function Fe(e){let t=1,n=0;for(let r=0;r<e.length;){let o=Math.min(r+5552,e.length);for(;r<o;r++)t+=e[r],n+=t;t%=65521,n%=65521}return(n<<16|t)>>>0}var J=class{constructor(t){this.pos=0;this.acc=0;this.n=0;this.buf=new Uint8Array(Math.max(64,t))}bits(t,n){for(this.acc|=t<<this.n,this.n+=n;this.n>=8;)this.byte(this.acc&255),this.acc>>>=8,this.n-=8}code(t,n){let r=0;for(let o=0;o<n;o++)r|=(t>>>o&1)<<n-1-o;this.bits(r,n)}byte(t){if(this.pos===this.buf.length){let n=new Uint8Array(this.buf.length*2);n.set(this.buf),this.buf=n}this.buf[this.pos++]=t}finish(){return this.n>0&&this.byte(this.acc&255),this.acc=this.n=0,this.buf.subarray(0,this.pos)}},le=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],fe=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],me=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],de=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];function F(e,t){t<144?e.code(48+t,8):t<256?e.code(400+t-144,9):t<280?e.code(t-256,7):e.code(192+t-280,8)}function be(e,t){let n=e.length-1;for(;e[n]>t;)n--;return n}function Je(e,t){let n=new J(e.length/4+64);n.bits(1,1),n.bits(1,2);let r=e.length,o=t>1&&t<=32768?[t,1]:[1];for(let i=0;i<r;){let s=0,a=0;for(let l of o){if(l>i)continue;let c=0,u=Math.min(258,r-i);for(;c<u&&e[i+c]===e[i+c-l];)c++;c>s&&(s=c,a=l)}if(s>=3){let l=be(le,s);F(n,257+l),fe[l]&&n.bits(s-le[l],fe[l]);let c=be(me,a);n.code(c,5),de[c]&&n.bits(a-me[c],de[c]),i+=s}else F(n,e[i]),i++}return F(n,256),n.finish()}function Ke(e,t){let n=Je(e,t),r=new Uint8Array(n.length+6);r[0]=120,r[1]=1,r.set(n,2);let o=Fe(e);return r[r.length-4]=o>>>24,r[r.length-3]=o>>>16&255,r[r.length-2]=o>>>8&255,r[r.length-1]=o&255,r}var j=e=>[e>>>24,e>>>16&255,e>>>8&255,e&255];function S(e,t){let n=new Uint8Array(12+t.length);n.set(j(t.length),0);for(let r=0;r<4;r++)n[4+r]=e.charCodeAt(r);return n.set(t,8),n.set(j(He(n.subarray(4,8+t.length))),8+t.length),n}function he(e,t,n,r){let o=Math.ceil(e/8),i=new Uint8Array((o+1)*t);for(let c=0;c<t;c++)i.set(n.subarray(c*o,(c+1)*o),c*(o+1)+1);let s=[new Uint8Array([137,80,78,71,13,10,26,10]),S("IHDR",[...j(e),...j(t),1,3,0,0,0]),S("PLTE",[...r[0].slice(0,3),...r[1].slice(0,3)])];(r[0][3]<255||r[1][3]<255)&&s.push(S("tRNS",[r[0][3],r[1][3]])),s.push(S("IDAT",Ke(i,o+1)),S("IEND",[]));let a=new Uint8Array(s.reduce((c,u)=>c+u.length,0)),l=0;for(let c of s)a.set(c,l),l+=c.length;return a}function P(e,t){return ue(e)?e:ce(e,t)}function C(e,t,n){if(e===void 0)return n;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new k(`${t} must be a non-negative integer, got ${String(e)}`);return e}function We(e,t,n){if(e===void 0)return n;if(typeof e!="number"||!Number.isFinite(e)||e<=0)throw new k(`${t} must be a positive number, got ${String(e)}`);return e}var K=e=>e.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]),R=e=>String(Math.round(e*1e3)/1e3);function pe(e,t={}){let n=P(e,t),r=C(t.margin,"margin",4),o=We(t.scale,"scale",4),i=t.radius??0;if(typeof i!="number"||!(i>=0&&i<=.5))throw new k(`radius must be from 0 to 0.5, got ${String(i)}`);let s=K(t.dark??"#000"),a=t.light??"#fff",l=n.size+r*2,c=t.size===void 0?l*o:C(t.size,"size",0),u="";for(let h=0;h<n.size;h++)if(i===0)for(let d=0;d<n.size;){if(!n.get(d,h)){d++;continue}let y=d;for(;n.get(d,h);)d++;u+=`M${y+r} ${h+r}h${d-y}v1H${y+r}z`}else{let d=R(i),y=R(1-2*i);for(let w=0;w<n.size;w++)n.get(w,h)&&(u+=`M${R(w+r+i)} ${h+r}h${y}a${d} ${d} 0 0 1 ${d} ${d}v${y}a${d} ${d} 0 0 1 -${d} ${d}h-${y}a${d} ${d} 0 0 1 -${d} -${d}v-${y}a${d} ${d} 0 0 1 ${d} -${d}z`)}let m=c>0?` width="${R(c)}" height="${R(c)}"`:"",b=i===0?' shape-rendering="crispEdges"':"",f=t.title?`<title>${K(t.title)}</title>`:"",g=a==="transparent"?"":`<rect width="${l}" height="${l}" fill="${K(a)}"/>`;return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${l} ${l}"${m}${b}>${f}${g}<path fill="${s}" d="${u}"/></svg>`}function ge(e){if(e==="transparent")return[255,255,255,0];let t=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e);if(!t)throw new k(`Unsupported colour ${JSON.stringify(e)}: use #rgb, #rgba, #rrggbb, #rrggbbaa or 'transparent'`);let n=t[1];n.length<=4&&(n=n.replace(/./g,"$&$&")),n.length===6&&(n+="ff");let r=o=>parseInt(n.slice(o*2,o*2+2),16);return[r(0),r(1),r(2),r(3)]}function ye(e,t={}){let n=P(e,t),r=C(t.margin,"margin",4),o=n.size+r*2,i,s,a;if(t.size!==void 0){if(s=C(t.size,"size",0),i=Math.floor(s/o),i<1)throw new k(`size ${s} is too small: this code needs at least ${o} px`);a=Math.floor((s-o*i)/2)}else{if(i=C(t.scale,"scale",4),i<1)throw new k("scale must be at least 1");s=o*i,a=0}r=r*i+a;let l=Math.ceil(s/8),c=new Uint8Array(l*s);for(let u=0;u<n.size;u++){let m=new Uint8Array(l);for(let b=0;b<n.size;b++)if(n.get(b,u))for(let f=r+b*i,g=f+i;f<g;f++)m[f>>3]|=128>>(f&7);for(let b=r+u*i,f=b+i;b<f;b++)c.set(m,b*l)}return he(s,s,c,[ge(t.light??"#ffffff"),ge(t.dark??"#000000")])}function xe(e,t={}){let n=P(e,t),r=C(t.margin,"margin",2),o=t.invert===!0,i=t.ansi===!0,s=t.small!==!1,a=-r,l=n.size+r,c=(f,g)=>g>=l?!1:n.get(f,g)!==(i?o:!o),u=[],[m,b]=i?[o?"\x1B[97;40m":"\x1B[30;107m","\x1B[0m"]:["",""];if(s)for(let f=a;f<l;f+=2){let g=m;for(let h=a;h<l;h++){let d=c(h,f),y=f+1<l?c(h,f+1):i?!1:null;g+=y===null?d?"\u2580":" ":d?y?"\u2588":"\u2580":y?"\u2584":" "}u.push(g+b)}else for(let f=a;f<l;f++){let g=m;for(let h=a;h<l;h++)g+=c(h,f)?"\u2588\u2588":" ";u.push(g+b)}return u.join(`
3
+ `)}function ke(e,t={}){let n=P(e,t),r=C(t.margin,"margin",4),o=t.dark??"##",i=t.light??" ",s=[];for(let a=-r;a<n.size+r;a++){let l="";for(let c=-r;c<n.size+r;c++)l+=n.get(c,a)?o:i;s.push(l)}return s.join(t.newline??`
4
+ `)}var Xe=`Usage: qrmake [options] <text>
5
+ echo <text> | qrmake [options]
6
+
7
+ Print a QR code in the terminal, or save it as SVG or PNG.
8
+
9
+ Options:
10
+ -o, --output <file> Write to a file; the format comes from the extension
11
+ (.svg, .png, .txt)
12
+ -t, --type <type> Output on stdout: terminal (default), svg, png, text
13
+ -e, --ecl <level> Error correction: L, M (default), Q, H
14
+ --qr-version <n> Force QR version 1-40 (default: smallest that fits)
15
+ -m, --margin <n> Quiet zone in modules (default 2 in the terminal, else 4)
16
+ -s, --scale <n> Pixels per module for SVG/PNG (default 4)
17
+ --size <px> Image width and height in pixels for SVG/PNG
18
+ --dark <color> Dark module colour for SVG/PNG (default #000)
19
+ --light <color> Background colour for SVG/PNG, or "transparent"
20
+ -i, --invert Terminal: draw dark modules (for light backgrounds)
21
+ -l, --large Terminal: two characters per module instead of half blocks
22
+ -a, --ansi Terminal: paint black on white with ANSI colours
23
+ -h, --help Show this help
24
+ -v, --version Show the qrmake version
25
+
26
+ Examples:
27
+ qrmake "https://example.com"
28
+ qrmake -o code.svg -e H "Hello, world"
29
+ qrmake -o code.png --size 512 "WIFI:T:WPA;S:MyNet;P:secret;;"
30
+ git remote get-url origin | qrmake
31
+ `,U=e=>({exit:{code:2,stdout:"",stderr:`qrmake: ${e}
32
+ Run qrmake --help for usage.
33
+ `}});function we(e,t){let n={type:"terminal",invert:!1,large:!1,ansi:!1},r=[],o=!1;for(let i=0;i<e.length;i++){let s=e[i],a;if(s==="--"){r.push(...e.slice(i+1));break}s.startsWith("--")&&s.includes("=")&&(a=s.slice(s.indexOf("=")+1),s=s.slice(0,s.indexOf("=")));let l=()=>{if(a!==void 0)return a;let u=e[i+1];if(u!==void 0)return i++,u},c=(u,m,b)=>{let f=l(),g=Number(f);return f===void 0||!Number.isInteger(g)||g<m||g>b?U(`${u} needs a whole number from ${m} to ${b}`):g};switch(s){case"-h":case"--help":return{exit:{code:0,stdout:Xe,stderr:""}};case"-v":case"--version":return{exit:{code:0,stdout:t+`
34
+ `,stderr:""}};case"-o":case"--output":{let u=l();if(!u)return U(`${s} needs a file name`);n.output=u;break}case"-t":case"--type":{let u=l();if(u!=="terminal"&&u!=="svg"&&u!=="png"&&u!=="text")return U(`${s} must be terminal, svg, png or text`);n.type=u,o=!0;break}case"-e":case"--ecl":{let u=l()?.toUpperCase();if(u!=="L"&&u!=="M"&&u!=="Q"&&u!=="H")return U(`${s} must be L, M, Q or H`);n.ecl=u;break}case"--qr-version":{let u=c(s,1,40);if(typeof u!="number")return u;n.version=u;break}case"-m":case"--margin":{let u=c(s,0,1e3);if(typeof u!="number")return u;n.margin=u;break}case"-s":case"--scale":{let u=c(s,1,1e3);if(typeof u!="number")return u;n.scale=u;break}case"--size":{let u=c(s,1,1e5);if(typeof u!="number")return u;n.size=u;break}case"--dark":case"--light":{let u=l();if(!u)return U(`${s} needs a colour`);n[s==="--dark"?"dark":"light"]=u;break}case"-i":case"--invert":n.invert=!0;break;case"-l":case"--large":n.large=!0;break;case"-a":case"--ansi":n.ansi=!0;break;default:if(s.startsWith("-")&&s.length>1)return U(`unknown option ${s}`);r.push(s)}}if(r.length&&(n.text=r.join(" ")),n.output&&!o){let i=/\.([a-z]+)$/i.exec(n.output)?.[1]?.toLowerCase();if(i==="svg"||i==="png")n.type=i;else if(i==="txt")n.type="text";else return U(`cannot tell the format of ${n.output}; use .svg, .png or .txt, or pass --type`)}return n}function Ae(e,t){let n={ecl:e.ecl,version:e.version,margin:e.margin},r={...n,scale:e.scale,size:e.size,dark:e.dark,light:e.light};switch(e.type){case"svg":return pe(t,r)+`
35
+ `;case"png":return ye(t,r);case"text":return ke(t,n)+`
36
+ `;default:return xe(t,{...n,invert:e.invert,small:!e.large,ansi:e.ansi})+`
37
+ `}}function et(){try{return JSON.parse(Ye(new URL("../package.json",import.meta.url),"utf8")).version}catch{return"unknown"}}async function tt(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf8").replace(/\r?\n$/,"")}var A=we(process.argv.slice(2),et());"exit"in A&&(process.stdout.write(A.exit.stdout),process.stderr.write(A.exit.stderr),process.exit(A.exit.code));try{A.text===void 0&&process.stdin.isTTY&&(process.stderr.write(`qrmake: no text. Pass it as an argument or pipe it in. Run qrmake --help for usage.
38
+ `),process.exit(2));let e=A.text??await tt();A.text===void 0&&e===""&&(process.stderr.write(`qrmake: no text on stdin. Run qrmake --help for usage.
39
+ `),process.exit(2));let t=Ae(A,e);A.output?(Ze(A.output,t),process.stderr.write(`qrmake: wrote ${A.output}
40
+ `)):process.stdout.write(t)}catch(e){process.stderr.write(`qrmake: ${e instanceof Error?e.message:String(e)}
41
+ `),process.exit(1)}
package/dist/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";var re=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Be=Object.prototype.hasOwnProperty;var ze=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},Ve=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of De(t))!Be.call(e,o)&&o!==n&&re(e,o,{get:()=>t[o],enumerable:!(r=Ge(t,o))||r.enumerable});return e};var _e=e=>Ve(re({},"__esModule",{value:!0}),e);var wt={};ze(wt,{QRError:()=>x,capacity:()=>D,default:()=>xt,email:()=>J,encode:()=>C,geo:()=>Z,isQRCode:()=>S,mecard:()=>te,qrmake:()=>ge,sms:()=>Y,tel:()=>X,toDataURL:()=>_,toPNG:()=>T,toSVG:()=>j,toTerminal:()=>F,toText:()=>W,url:()=>ee,vcard:()=>ne,wifi:()=>H});module.exports=_e(wt);var x=class extends RangeError{constructor(t){super(t),this.name="QRError"}},ce={L:0,M:1,Q:2,H:3},Fe={L:1,M:0,Q:3,H:2},$e=["L","M","Q","H"],Re=[[0,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],[0,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],[0,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],[0,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]],Me=[[0,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],[0,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],[0,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],[0,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]],We={numeric:1,alphanumeric:2,byte:4,kanji:8},qe={numeric:[10,12,14],alphanumeric:[9,11,13],byte:[8,16,16],kanji:[8,10,12]},G=["numeric","alphanumeric","byte","kanji"],ke="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",Ce=e=>e<=9?0:e<=26?1:2,M=(e,t)=>qe[e][Ce(t)];function Ue(e){let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}function I(e,t){let n=ce[t];return(Ue(e)>>3)-Re[n][e]*Me[n][e]}function He(e){if(e===1)return[];let t=Math.floor(e/7)+2,n=Math.floor((e*8+t*3+5)/(t*4-4))*2,r=[6];for(let o=e*4+10;r.length<t;o-=n)r.splice(1,0,o);return r}function D(e,t="M"){v(e,"version"),Ie(t);let n=I(e,t)*8,r=a=>Math.max(0,n-4-M(a,e)),o=r("numeric"),i=r("alphanumeric"),s=o%10;return{bits:n,numeric:Math.min(Math.floor(o/10)*3+(s>=7?2:s>=4?1:0),2**M("numeric",e)-1),alphanumeric:Math.min(Math.floor(i/11)*2+(i%11>=6?1:0),2**M("alphanumeric",e)-1),byte:Math.min(Math.floor(r("byte")/8),2**M("byte",e)-1),kanji:Math.min(Math.floor(r("kanji")/13),2**M("kanji",e)-1)}}var P=new Uint8Array(512),ie=new Uint8Array(256);{let e=1;for(let t=0;t<255;t++)P[t]=e,ie[e]=t,e<<=1,e&256&&(e^=285);for(let t=255;t<512;t++)P[t]=P[t-255]}var se=(e,t)=>e===0||t===0?0:P[ie[e]+ie[t]],xe=new Map;function Je(e){let t=xe.get(e);if(t)return t;t=new Uint8Array(e),t[e-1]=1;let n=1;for(let r=0;r<e;r++){for(let o=0;o<e;o++)t[o]=se(t[o],n)^(o+1<e?t[o+1]:0);n=se(n,2)}return xe.set(e,t),t}function Ke(e,t){let n=Je(t),r=new Uint8Array(t);for(let o=0;o<e.length;o++){let i=e[o]^r[0];if(r.copyWithin(0,1),r[t-1]=0,i!==0)for(let s=0;s<t;s++)r[s]^=se(n[s],i)}return r}function Xe(e,t,n){let r=ce[n],o=Me[r][t],i=Re[r][t],s=Ue(t)>>3;if(e.length!==s-i*o)throw new x("Invalid data length");let a=o-s%o,u=Math.floor(s/o)-i,f=[],m=[];for(let c=0,g=0;c<o;c++){let b=u+(c<a?0:1),l=e.subarray(g,g+b);g+=b,f.push(l),m.push(Ke(l,i))}let d=new Uint8Array(s),p=0;for(let c=0;c<=u;c++)for(let g of f)c<g.length&&(d[p++]=g[c]);for(let c=0;c<i;c++)for(let g of m)d[p++]=g[c];return d}var ae=class{constructor(){this.bits=[]}put(t,n){for(let r=n-1;r>=0;r--)this.bits.push(t>>>r&1)}};function Ye(e){return e<128?[e]:e<2048?[192|e>>6,128|e&63]:(e>=55296&&e<=57343&&(e=65533),e<65536?[224|e>>12,128|e>>6&63,128|e&63]:[240|e>>18,128|e>>12&63,128|e>>6&63,128|e&63])}var O;function Ze(){if(O!==void 0)return O;try{let e=new TextDecoder("shift_jis",{fatal:!0}),t=new Map,n=new Uint8Array(2);for(let r=129;r<=235;r++)if(!(r>159&&r<224))for(let o=64;o<=252;o++){if(o===127||r===235&&o>191)continue;n[0]=r,n[1]=o;let i;try{i=e.decode(n)}catch{continue}let s=i.codePointAt(0);i.length===1&&!t.has(s)&&t.set(s,r<<8|o)}O=t.size>0?t:null}catch{O=null}return O}function Ee(e,t){let n=t?Ze():null;if(t&&!n)throw new x("Kanji mode needs TextDecoder with Shift JIS support, which this runtime lacks");let r=[];for(let o of e){let i=o.codePointAt(0);r.push({bytes:Ye(i),numeric:i>=48&&i<=57,alnum:i<128?ke.indexOf(o):-1,sjis:n?.get(i)??-1})}return r}function Se(e){return Array.from(e,t=>({bytes:[t],numeric:t>=48&&t<=57,alnum:t<128?ke.indexOf(String.fromCharCode(t)):-1,sjis:-1}))}var le=(e,t)=>t==="byte"||(t==="numeric"?e.numeric:t==="alphanumeric"?e.alnum>=0:e.sjis>=0);function et(e){let t=e.units.length;switch(e.mode){case"numeric":return Math.floor(t/3)*10+[0,4,7][t%3];case"alphanumeric":return Math.floor(t/2)*11+t%2*6;case"kanji":return t*13;default:return e.units.reduce((n,r)=>n+r.bytes.length*8,0)}}var me=e=>e.mode==="byte"?e.units.reduce((t,n)=>t+n.bytes.length,0):e.units.length;function we(e,t,n){let r=n?12:0;for(let o of e){let i=M(o.mode,t);if(me(o)>=2**i)return 1/0;r+=4+i+et(o)}return r}function tt(e,t,n){if(e.length===0)return[{mode:"byte",units:[]}];let r=n?G:G.slice(0,3),o=r.length,i=r.map(d=>(4+M(d,t))*6),s=i.slice(),a=[];for(let d of e){let p=new Array(o).fill(1/0),c=new Int8Array(o).fill(-1);for(let l=0;l<o;l++){let y=r[l];if(!le(d,y))continue;let A=y==="byte"?d.bytes.length*48:y==="numeric"?20:y==="alphanumeric"?33:78;p[l]=s[l]+A,c[l]=l}let g=p.slice(),b=c.slice();for(let l=0;l<o;l++)for(let y=0;y<o;y++){if(b[y]!==y)continue;let A=Math.ceil(g[y]/6)*6+i[l];A<p[l]&&(p[l]=A,c[l]=y)}a.push(c),s=p}let u=0;for(let d=1;d<o;d++)s[d]<s[u]&&(u=d);let f=new Array(e.length);for(let d=e.length-1;d>=0;d--)u=a[d][u],f[d]=u;let m=[];for(let d=0;d<e.length;d++){let p=r[f[d]],c=m[m.length-1];c&&c.mode===p?c.units.push(e[d]):m.push({mode:p,units:[e[d]]})}return m}function nt(e,t){for(let n of["numeric","alphanumeric",...t?["kanji"]:[]])if(e.length>0&&e.every(r=>le(r,n)))return{mode:n,units:e};return{mode:"byte",units:e}}function Oe(e,t,n){let r=e.findIndex(o=>!le(o,t));if(r>=0){let o=String.fromCodePoint(...n?[Array.from(n)[r].codePointAt(0)]:e[r].bytes);throw new x(`Cannot encode ${JSON.stringify(o)} in ${t} mode`)}return{mode:t,units:e}}function rt(e){if(!e||!G.includes(e.mode))throw new x(`Invalid segment mode: ${String(e?.mode)}`);let{mode:t,data:n}=e;if(typeof n!="string"&&!(n instanceof Uint8Array))throw new TypeError("Segment data must be a string or Uint8Array");if(t==="kanji"&&n instanceof Uint8Array){if(n.length%2)throw new x("Kanji segment bytes must be Shift JIS pairs");let o=[];for(let i=0;i<n.length;i+=2){let s=n[i]<<8|n[i+1];if(!(s>=33088&&s<=40956||s>=57408&&s<=60351))throw new x(`Shift JIS code 0x${s.toString(16)} is outside the kanji mode ranges`);o.push({bytes:[],numeric:!1,alnum:-1,sjis:s})}return{mode:t,units:o}}let r=typeof n=="string"?Ee(n,t==="kanji"):Se(n);return Oe(r,t,typeof n=="string"?n:"")}function ot(e,t,n){e.put(We[t.mode],4),e.put(me(t),M(t.mode,n));let{units:r}=t;switch(t.mode){case"numeric":for(let o=0;o<r.length;o+=3){let i=r.slice(o,o+3),s=Number(i.map(a=>String.fromCharCode(a.bytes[0])).join(""));e.put(s,i.length*3+1)}break;case"alphanumeric":for(let o=0;o<r.length;o+=2)o+1<r.length?e.put(r[o].alnum*45+r[o+1].alnum,11):e.put(r[o].alnum,6);break;case"kanji":for(let o of r){let i=o.sjis-(o.sjis<=40956?33088:49472);e.put((i>>8)*192+(i&255),13)}break;default:for(let o of r)for(let i of o.bytes)e.put(i,8)}}var it=21522;function Ae(e,t){let n=Fe[e]<<3|t,r=n;for(let o=0;o<10;o++)r=r<<1^(r>>>9)*1335;return(n<<10|r)^it}function st(e){let t=e;for(let n=0;n<12;n++)t=t<<1^(t>>>11)*7973;return e<<12|t}var at=[(e,t)=>(e+t)%2===0,(e,t)=>t%2===0,e=>e%3===0,(e,t)=>(e+t)%3===0,(e,t)=>(Math.floor(e/3)+Math.floor(t/2))%2===0,(e,t)=>e*t%2+e*t%3===0,(e,t)=>(e*t%2+e*t%3)%2===0,(e,t)=>((e+t)%2+e*t%3)%2===0],fe=class{constructor(t){this.size=t;this.modules=new Uint8Array(t*t),this.reserved=new Uint8Array(t*t)}fn(t,n,r){let o=n*this.size+t;this.modules[o]=r?1:0,this.reserved[o]=1}};function ft(e,t){let{size:n}=e;for(let i=0;i<n;i++)e.fn(6,i,i%2===0),e.fn(i,6,i%2===0);for(let[i,s]of[[3,3],[n-4,3],[3,n-4]])for(let a=-4;a<=4;a++)for(let u=-4;u<=4;u++){let f=i+u,m=s+a;if(f<0||m<0||f>=n||m>=n)continue;let d=Math.max(Math.abs(u),Math.abs(a));e.fn(f,m,d!==2&&d!==4)}let r=He(t),o=r.length-1;for(let i=0;i<=o;i++)for(let s=0;s<=o;s++)if(!(i===0&&s===0||i===0&&s===o||i===o&&s===0))for(let a=-2;a<=2;a++)for(let u=-2;u<=2;u++)e.fn(r[i]+u,r[s]+a,Math.max(Math.abs(u),Math.abs(a))!==1);if(ue(e,0),t>=7){let i=st(t);for(let s=0;s<18;s++){let a=(i>>>s&1)===1,u=n-11+s%3,f=Math.floor(s/3);e.fn(u,f,a),e.fn(f,u,a)}}}function ue(e,t){let{size:n}=e,r=o=>(t>>>o&1)===1;for(let o=0;o<=5;o++)e.fn(8,o,r(o));e.fn(8,7,r(6)),e.fn(8,8,r(7)),e.fn(7,8,r(8));for(let o=9;o<15;o++)e.fn(14-o,8,r(o));for(let o=0;o<8;o++)e.fn(n-1-o,8,r(o));for(let o=8;o<15;o++)e.fn(8,n-15+o,r(o));e.fn(8,n-8,!0)}function ut(e,t){let{size:n,modules:r,reserved:o}=e,i=t.length*8,s=0;for(let a=n-1;a>=1;a-=2){a===6&&(a=5);let u=(a+1&2)===0;for(let f=0;f<n;f++){let m=u?n-1-f:f;for(let d=0;d<2;d++){let p=m*n+a-d;o[p]||(s<i&&(r[p]=t[s>>>3]>>>7-(s&7)&1),s++)}}}}function oe(e,t){let{size:n,modules:r,reserved:o}=e,i=at[t];for(let s=0;s<n;s++)for(let a=0;a<n;a++){let u=s*n+a;!o[u]&&i(a,s)&&(r[u]^=1)}}function ct(e,t){let n=0,r=0,o=(i,s)=>e[s*t+i];for(let i=0;i<2;i++){let s=i===0?(a,u)=>o(u,a):o;for(let a=0;a<t;a++){let u=1;for(let f=1;f<=t;f++)f<t&&s(a,f)===s(a,f-1)?u++:(u>=5&&(n+=u-2),u=1);for(let f=0;f+6<t;f++)if(s(a,f)&&!s(a,f+1)&&s(a,f+2)&&s(a,f+3)&&s(a,f+4)&&!s(a,f+5)&&s(a,f+6)){let m=f>=4&&!s(a,f-1)&&!s(a,f-2)&&!s(a,f-3)&&!s(a,f-4),d=f+10<t&&!s(a,f+7)&&!s(a,f+8)&&!s(a,f+9)&&!s(a,f+10);m&&(n+=40),d&&(n+=40)}}}for(let i=0;i<t-1;i++)for(let s=0;s<t-1;s++){let a=o(s,i);a===o(s+1,i)&&a===o(s,i+1)&&a===o(s+1,i+1)&&(n+=3)}for(let i=0;i<e.length;i++)r+=e[i];return n+=Math.floor(Math.abs(r*100/e.length-50)/5)*10,n}function v(e,t){if(typeof e!="number"||!Number.isInteger(e)||e<1||e>40)throw new x(`${t} must be an integer from 1 to 40, got ${String(e)}`)}function Ie(e){if(!$e.includes(e))throw new x(`ecl must be 'L', 'M', 'Q' or 'H', got ${JSON.stringify(e)}`)}function C(e,t={}){let n=t.ecl??"M";Ie(n);let r=t.minVersion??1,o=t.maxVersion??40;if(t.version!==void 0&&(v(t.version,"version"),r=o=t.version),v(r,"minVersion"),v(o,"maxVersion"),r>o)throw new x(`minVersion (${r}) is greater than maxVersion (${o})`);let i=t.mask;if(i!==void 0&&!(Number.isInteger(i)&&i>=0&&i<=7))throw new x(`mask must be an integer from 0 to 7, got ${String(i)}`);if(t.mode!==void 0&&!G.includes(t.mode))throw new x(`Invalid mode: ${String(t.mode)}`);let s=t.kanji===!0||t.mode==="kanji",a,u=!1;if(typeof e=="string"||e instanceof Uint8Array){let h=typeof e=="string"?Ee(e,s):Se(e);if(u=h.some(w=>w.bytes.length>1||(w.bytes[0]??0)>127),t.mode){let w=Oe(h,t.mode,typeof e=="string"?e:"");a=()=>[w]}else if(t.optimize===!1){let w=nt(h,s);a=()=>[w]}else{let w=[];a=k=>{var ye;return w[ye=Ce(k)]??(w[ye]=tt(h,k,s))}}}else if(Array.isArray(e)){let h=e.map(rt);u=h.some(w=>w.mode==="byte"&&w.units.some(k=>k.bytes[0]>127)),a=()=>h}else throw new TypeError(`qrmake: expected a string, Uint8Array or array of segments, got ${e===null?"null":typeof e}`);let f=t.eci===!0&&u,m=r,d=a(m),p=we(d,m,f);for(;p>I(m,n)*8;){if(m>=o){let h=I(o,n)*8;throw new x(Number.isFinite(p)?`Data too long: needs ${p} bits, but version ${o}-${n} holds ${h}`:`Data too long for version ${o}-${n}`)}m++,d=a(m),p=we(d,m,f)}let c=n;if(t.boostEcl)for(let h of $e.slice(ce[n]+1))p<=I(m,h)*8&&(c=h);let g=I(m,c)*8,b=new ae;f&&(b.put(7,4),b.put(26,8));for(let h of d)ot(b,h,m);b.put(0,Math.min(4,g-b.bits.length)),b.put(0,(8-b.bits.length%8)%8);let l=new Uint8Array(g/8);for(let h=0;h<b.bits.length;h++)l[h>>>3]|=b.bits[h]<<7-(h&7);for(let h=b.bits.length/8,w=236;h<l.length;h++,w^=253)l[h]=w;let y=Xe(l,m,c),A=m*4+17,$=new fe(A);ft($,m),ut($,y);let N=i??0;if(i===void 0){let h=1/0;for(let w=0;w<8;w++){oe($,w),ue($,Ae(c,w));let k=ct($.modules,A);k<h&&(h=k,N=w),oe($,w)}}return oe($,N),ue($,Ae(c,N)),lt(m,c,N,d.map(h=>({mode:h.mode,length:me(h)})),$.modules)}function lt(e,t,n,r,o){let i=e*4+17;return{version:e,size:i,ecl:t,mask:n,segments:r,modules:o,get(s,a){return s>=0&&a>=0&&s<i&&a<i&&o[a*i+s]===1},toArray(){return Array.from({length:i},(s,a)=>Array.from(o.subarray(a*i,(a+1)*i),u=>u===1))}}}function S(e){return typeof e=="object"&&e!==null&&e.modules instanceof Uint8Array&&typeof e.size=="number"&&typeof e.get=="function"}var mt=(()=>{let e=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;e[t]=n>>>0}return e})();function dt(e,t=0){t=~t;for(let n=0;n<e.length;n++)t=mt[(t^e[n])&255]^t>>>8;return~t>>>0}function pt(e){let t=1,n=0;for(let r=0;r<e.length;){let o=Math.min(r+5552,e.length);for(;r<o;r++)t+=e[r],n+=t;t%=65521,n%=65521}return(n<<16|t)>>>0}var pe=class{constructor(t){this.pos=0;this.acc=0;this.n=0;this.buf=new Uint8Array(Math.max(64,t))}bits(t,n){for(this.acc|=t<<this.n,this.n+=n;this.n>=8;)this.byte(this.acc&255),this.acc>>>=8,this.n-=8}code(t,n){let r=0;for(let o=0;o<n;o++)r|=(t>>>o&1)<<n-1-o;this.bits(r,n)}byte(t){if(this.pos===this.buf.length){let n=new Uint8Array(this.buf.length*2);n.set(this.buf),this.buf=n}this.buf[this.pos++]=t}finish(){return this.n>0&&this.byte(this.acc&255),this.acc=this.n=0,this.buf.subarray(0,this.pos)}},Qe=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],Le=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],je=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],Te=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];function de(e,t){t<144?e.code(48+t,8):t<256?e.code(400+t-144,9):t<280?e.code(t-256,7):e.code(192+t-280,8)}function Ne(e,t){let n=e.length-1;for(;e[n]>t;)n--;return n}function bt(e,t){let n=new pe(e.length/4+64);n.bits(1,1),n.bits(1,2);let r=e.length,o=t>1&&t<=32768?[t,1]:[1];for(let i=0;i<r;){let s=0,a=0;for(let u of o){if(u>i)continue;let f=0,m=Math.min(258,r-i);for(;f<m&&e[i+f]===e[i+f-u];)f++;f>s&&(s=f,a=u)}if(s>=3){let u=Ne(Qe,s);de(n,257+u),Le[u]&&n.bits(s-Qe[u],Le[u]);let f=Ne(je,a);n.code(f,5),Te[f]&&n.bits(a-je[f],Te[f]),i+=s}else de(n,e[i]),i++}return de(n,256),n.finish()}function ht(e,t){let n=bt(e,t),r=new Uint8Array(n.length+6);r[0]=120,r[1]=1,r.set(n,2);let o=pt(e);return r[r.length-4]=o>>>24,r[r.length-3]=o>>>16&255,r[r.length-2]=o>>>8&255,r[r.length-1]=o&255,r}var B=e=>[e>>>24,e>>>16&255,e>>>8&255,e&255];function Q(e,t){let n=new Uint8Array(12+t.length);n.set(B(t.length),0);for(let r=0;r<4;r++)n[4+r]=e.charCodeAt(r);return n.set(t,8),n.set(B(dt(n.subarray(4,8+t.length))),8+t.length),n}function Pe(e,t,n,r){let o=Math.ceil(e/8),i=new Uint8Array((o+1)*t);for(let f=0;f<t;f++)i.set(n.subarray(f*o,(f+1)*o),f*(o+1)+1);let s=[new Uint8Array([137,80,78,71,13,10,26,10]),Q("IHDR",[...B(e),...B(t),1,3,0,0,0]),Q("PLTE",[...r[0].slice(0,3),...r[1].slice(0,3)])];(r[0][3]<255||r[1][3]<255)&&s.push(Q("tRNS",[r[0][3],r[1][3]])),s.push(Q("IDAT",ht(i,o+1)),Q("IEND",[]));let a=new Uint8Array(s.reduce((f,m)=>f+m.length,0)),u=0;for(let f of s)a.set(f,u),u+=f.length;return a}function V(e,t){return S(e)?e:C(e,t)}function U(e,t,n){if(e===void 0)return n;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new x(`${t} must be a non-negative integer, got ${String(e)}`);return e}function gt(e,t,n){if(e===void 0)return n;if(typeof e!="number"||!Number.isFinite(e)||e<=0)throw new x(`${t} must be a positive number, got ${String(e)}`);return e}var be=e=>e.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]),L=e=>String(Math.round(e*1e3)/1e3);function j(e,t={}){let n=V(e,t),r=U(t.margin,"margin",4),o=gt(t.scale,"scale",4),i=t.radius??0;if(typeof i!="number"||!(i>=0&&i<=.5))throw new x(`radius must be from 0 to 0.5, got ${String(i)}`);let s=be(t.dark??"#000"),a=t.light??"#fff",u=n.size+r*2,f=t.size===void 0?u*o:U(t.size,"size",0),m="";for(let b=0;b<n.size;b++)if(i===0)for(let l=0;l<n.size;){if(!n.get(l,b)){l++;continue}let y=l;for(;n.get(l,b);)l++;m+=`M${y+r} ${b+r}h${l-y}v1H${y+r}z`}else{let l=L(i),y=L(1-2*i);for(let A=0;A<n.size;A++)n.get(A,b)&&(m+=`M${L(A+r+i)} ${b+r}h${y}a${l} ${l} 0 0 1 ${l} ${l}v${y}a${l} ${l} 0 0 1 -${l} ${l}h-${y}a${l} ${l} 0 0 1 -${l} -${l}v-${y}a${l} ${l} 0 0 1 ${l} -${l}z`)}let d=f>0?` width="${L(f)}" height="${L(f)}"`:"",p=i===0?' shape-rendering="crispEdges"':"",c=t.title?`<title>${be(t.title)}</title>`:"",g=a==="transparent"?"":`<rect width="${u}" height="${u}" fill="${be(a)}"/>`;return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${u} ${u}"${d}${p}>${c}${g}<path fill="${s}" d="${m}"/></svg>`}function ve(e){if(e==="transparent")return[255,255,255,0];let t=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e);if(!t)throw new x(`Unsupported colour ${JSON.stringify(e)}: use #rgb, #rgba, #rrggbb, #rrggbbaa or 'transparent'`);let n=t[1];n.length<=4&&(n=n.replace(/./g,"$&$&")),n.length===6&&(n+="ff");let r=o=>parseInt(n.slice(o*2,o*2+2),16);return[r(0),r(1),r(2),r(3)]}function T(e,t={}){let n=V(e,t),r=U(t.margin,"margin",4),o=n.size+r*2,i,s,a;if(t.size!==void 0){if(s=U(t.size,"size",0),i=Math.floor(s/o),i<1)throw new x(`size ${s} is too small: this code needs at least ${o} px`);a=Math.floor((s-o*i)/2)}else{if(i=U(t.scale,"scale",4),i<1)throw new x("scale must be at least 1");s=o*i,a=0}r=r*i+a;let u=Math.ceil(s/8),f=new Uint8Array(u*s);for(let m=0;m<n.size;m++){let d=new Uint8Array(u);for(let p=0;p<n.size;p++)if(n.get(p,m))for(let c=r+p*i,g=c+i;c<g;c++)d[c>>3]|=128>>(c&7);for(let p=r+m*i,c=p+i;p<c;p++)f.set(d,p*u)}return Pe(s,s,f,[ve(t.light??"#ffffff"),ve(t.dark??"#000000")])}var z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function yt(e){let t="";for(let n=0;n<e.length;n+=3){let r=e[n],o=e[n+1],i=e[n+2];t+=z[r>>2]+z[(r&3)<<4|(o??0)>>4],t+=o===void 0?"=":z[(o&15)<<2|(i??0)>>6],t+=i===void 0?"=":z[i&63]}return t}function _(e,t={}){let n=t.type??"png";if(n==="svg")return"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(j(e,t));if(n!=="png")throw new x(`type must be 'png' or 'svg', got ${JSON.stringify(n)}`);return"data:image/png;base64,"+yt(T(e,t))}function F(e,t={}){let n=V(e,t),r=U(t.margin,"margin",2),o=t.invert===!0,i=t.ansi===!0,s=t.small!==!1,a=-r,u=n.size+r,f=(c,g)=>g>=u?!1:n.get(c,g)!==(i?o:!o),m=[],[d,p]=i?[o?"\x1B[97;40m":"\x1B[30;107m","\x1B[0m"]:["",""];if(s)for(let c=a;c<u;c+=2){let g=d;for(let b=a;b<u;b++){let l=f(b,c),y=c+1<u?f(b,c+1):i?!1:null;g+=y===null?l?"\u2580":" ":l?y?"\u2588":"\u2580":y?"\u2584":" "}m.push(g+p)}else for(let c=a;c<u;c++){let g=d;for(let b=a;b<u;b++)g+=f(b,c)?"\u2588\u2588":" ";m.push(g+p)}return m.join(`
2
+ `)}function W(e,t={}){let n=V(e,t),r=U(t.margin,"margin",4),o=t.dark??"##",i=t.light??" ",s=[];for(let a=-r;a<n.size+r;a++){let u="";for(let f=-r;f<n.size+r;f++)u+=n.get(f,a)?o:i;s.push(u)}return s.join(t.newline??`
3
+ `)}var R=e=>e.replace(/([\\;,:"])/g,"\\$1");function H(e){let{ssid:t,password:n,hidden:r}=e;if(typeof t!="string"||t==="")throw new TypeError("wifi: ssid must be a non-empty string");let o=e.security??(n?"WPA":"nopass");if(o!=="nopass"&&!n)throw new TypeError(`wifi: a password is required for ${o}`);let i=`WIFI:T:${o};S:${R(t)};`;return o!=="nopass"&&(i+=`P:${R(n)};`),r&&(i+="H:true;"),i+";"}var he=e=>(Array.isArray(e)?e:[e]).map(t=>encodeURIComponent(t).replace(/%40/g,"@")).join(",");function J(e,t={}){let n=[];return t.cc&&n.push("cc="+he(t.cc)),t.bcc&&n.push("bcc="+he(t.bcc)),t.subject&&n.push("subject="+encodeURIComponent(t.subject)),t.body&&n.push("body="+encodeURIComponent(t.body)),`mailto:${he(e)}${n.length?"?"+n.join("&"):""}`}var K=e=>{let t=String(e).replace(/[\s().-]/g,"");if(!/^\+?[0-9*#,;pw]+$/i.test(t))throw new TypeError(`Invalid phone number: ${JSON.stringify(e)}`);return t};function X(e){return"tel:"+K(e)}function Y(e,t){return`SMSTO:${K(e)}${t?":"+t:""}`}function Z(e,t,n){let r=(i,s,a)=>{if(typeof i!="number"||!Number.isFinite(i)||Math.abs(i)>s)throw new RangeError(`geo: invalid ${a} ${String(i)}`);return String(i)},o=`geo:${r(e,90,"latitude")},${r(t,180,"longitude")}`;return n!==void 0&&(o+=","+r(n,1/0,"altitude")),o}function ee(e){let t=String(e).trim();if(!t)throw new TypeError("url: link must be a non-empty string");return/^[a-z][a-z0-9+.-]*:/i.test(t)?t:"https://"+t}var q=e=>e===void 0?[]:Array.isArray(e)?e:[e];function te(e){if(!e?.name)throw new TypeError("mecard: name is required");let t=[`N:${R(e.name)}`];e.org&&t.push(`ORG:${R(e.org)}`);for(let n of q(e.phone))t.push(`TEL:${R(K(n))}`);for(let n of q(e.email))t.push(`EMAIL:${R(n)}`);return e.url&&t.push(`URL:${R(e.url)}`),e.address&&t.push(`ADR:${R(e.address)}`),e.birthday&&t.push(`BDAY:${e.birthday.replace(/-/g,"")}`),e.note&&t.push(`NOTE:${R(e.note)}`),`MECARD:${t.join(";")};;`}var E=e=>e.replace(/([\\;,])/g,"\\$1").replace(/\r?\n/g,"\\n");function ne(e){if(!e?.name)throw new TypeError("vcard: name is required");let t=e.name.trim().split(/\s+/),n=t.length>1?t.pop():"",r=["BEGIN:VCARD","VERSION:3.0",`N:${E(n)};${E(t.join(" "))};;;`,`FN:${E(e.name)}`];e.org&&r.push(`ORG:${E(e.org)}`),e.title&&r.push(`TITLE:${E(e.title)}`);for(let o of q(e.phone))r.push(`TEL:${K(o)}`);for(let o of q(e.email))r.push(`EMAIL:${o}`);return e.url&&r.push(`URL:${e.url}`),e.address&&r.push(`ADR:;;${E(e.address)};;;;`),e.birthday&&r.push(`BDAY:${e.birthday}`),e.note&&r.push(`NOTE:${E(e.note)}`),r.push("END:VCARD"),r.join(`\r
4
+ `)}var ge=((e,t)=>C(e,t));Object.assign(ge,{encode:C,capacity:D,isQRCode:S,toSVG:j,toPNG:T,toDataURL:_,toTerminal:F,toText:W,wifi:H,email:J,tel:X,sms:Y,geo:Z,url:ee,mecard:te,vcard:ne,QRError:x});var xt=ge;0&&(module.exports={QRError,capacity,email,encode,geo,isQRCode,mecard,qrmake,sms,tel,toDataURL,toPNG,toSVG,toTerminal,toText,url,vcard,wifi});
5
+ var __d=module.exports.default;for(var __k in module.exports)if(!(__k in __d))__d[__k]=module.exports[__k];__d.default=__d;module.exports=__d;
@@ -0,0 +1,225 @@
1
+ type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
2
+ type Mode = 'numeric' | 'alphanumeric' | 'byte' | 'kanji';
3
+ type MaskPattern = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
4
+ /** A piece of data encoded in one mode. Pass an array of these to choose the modes yourself. */
5
+ interface Segment {
6
+ mode: Mode;
7
+ /**
8
+ * `numeric` / `alphanumeric`: the characters. `byte`: a string (encoded as UTF-8) or raw bytes.
9
+ * `kanji`: a string of Shift JIS double-byte characters, or the Shift JIS bytes themselves.
10
+ */
11
+ data: string | Uint8Array;
12
+ }
13
+ /** What `qrmake()` accepts: text, raw bytes, or explicit segments. */
14
+ type QRInput = string | Uint8Array | readonly Segment[];
15
+ interface QROptions {
16
+ /** Error correction level: L ~7%, M ~15% (default), Q ~25%, H ~30% of the symbol can be damaged. */
17
+ ecl?: ErrorCorrectionLevel;
18
+ /** Use a higher error correction level when the data still fits in the same version. Default `false`. */
19
+ boostEcl?: boolean;
20
+ /** Force this exact version (1-40). Throws if the data does not fit. */
21
+ version?: number;
22
+ /** Smallest version to consider. Default 1. */
23
+ minVersion?: number;
24
+ /** Largest version to consider. Default 40. */
25
+ maxVersion?: number;
26
+ /** Force this mask pattern (0-7) instead of picking the one with the lowest penalty. */
27
+ mask?: MaskPattern;
28
+ /** Encode all text in this one mode instead of choosing automatically. */
29
+ mode?: Mode;
30
+ /**
31
+ * Split text into numeric/alphanumeric/byte runs to make the smallest code. Default `true`.
32
+ * With `false`, a single segment in the most compact mode that fits all the text is used.
33
+ */
34
+ optimize?: boolean;
35
+ /** Allow kanji mode for Japanese text (needs `TextDecoder` with Shift JIS support). Default `false`. */
36
+ kanji?: boolean;
37
+ /** Add a UTF-8 ECI header (designator 26) when byte-mode text is not plain ASCII. Default `false`. */
38
+ eci?: boolean;
39
+ }
40
+ interface SegmentInfo {
41
+ mode: Mode;
42
+ /** Number of characters (bytes for byte mode). */
43
+ length: number;
44
+ }
45
+ /** An encoded QR code. */
46
+ interface QRCode {
47
+ /** Version, 1-40. */
48
+ readonly version: number;
49
+ /** Width and height in modules (`version * 4 + 17`), without the quiet zone. */
50
+ readonly size: number;
51
+ /** Error correction level actually used. */
52
+ readonly ecl: ErrorCorrectionLevel;
53
+ /** Mask pattern actually used. */
54
+ readonly mask: MaskPattern;
55
+ /** How the data was split into modes. */
56
+ readonly segments: readonly SegmentInfo[];
57
+ /** Row-major modules, `1` = dark. Index with `y * size + x`. */
58
+ readonly modules: Uint8Array;
59
+ /** `true` if the module at column `x`, row `y` is dark. Outside the symbol (the quiet zone) is light. */
60
+ get(x: number, y: number): boolean;
61
+ /** The modules as rows of booleans (`true` = dark). */
62
+ toArray(): boolean[][];
63
+ }
64
+ declare class QRError extends RangeError {
65
+ constructor(message: string);
66
+ }
67
+ interface Capacity {
68
+ /** Data bits available, including mode and length headers. */
69
+ bits: number;
70
+ numeric: number;
71
+ alphanumeric: number;
72
+ /** Bytes (UTF-8 bytes for text). */
73
+ byte: number;
74
+ kanji: number;
75
+ }
76
+ /** How many characters fit in one segment of each mode at this version and level. */
77
+ declare function capacity(version: number, ecl?: ErrorCorrectionLevel): Capacity;
78
+ /** Encode text, bytes or segments as a QR code. */
79
+ declare function encode(input: QRInput, options?: QROptions): QRCode;
80
+ /** `true` if `value` looks like a QR code returned by `qrmake()`. */
81
+ declare function isQRCode(value: unknown): value is QRCode;
82
+
83
+ /** Text/bytes/segments to encode, or a code already made with `qrmake()`. */
84
+ type RenderInput = QRInput | QRCode;
85
+ interface SVGOptions extends QROptions {
86
+ /** Quiet zone width in modules. Default 4 (the minimum the standard asks for). */
87
+ margin?: number;
88
+ /** Pixels per module for the `width`/`height` attributes. Default 4. Ignored when `size` is set. */
89
+ scale?: number;
90
+ /** Width and height attributes in pixels. Set to `0` to leave them out (the SVG fills its container). */
91
+ size?: number;
92
+ /** Colour of dark modules (any CSS colour). Default `'#000'`. */
93
+ dark?: string;
94
+ /** Background colour (any CSS colour), or `'transparent'` for none. Default `'#fff'`. */
95
+ light?: string;
96
+ /** Corner radius of each module, from 0 (square, default) to 0.5 (dots). */
97
+ radius?: number;
98
+ /** Accessible title, added as a `<title>` element. */
99
+ title?: string;
100
+ }
101
+ interface PNGOptions extends QROptions {
102
+ /** Quiet zone width in modules. Default 4. */
103
+ margin?: number;
104
+ /** Pixels per module. Default 4. Ignored when `size` is set. */
105
+ scale?: number;
106
+ /**
107
+ * Exact image width and height in pixels. Modules are scaled by a whole number of pixels and
108
+ * any leftover pixels are added to the quiet zone. Throws if `size` is too small for 1 px modules.
109
+ */
110
+ size?: number;
111
+ /** Dark module colour: `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`. Default `'#000000'`. */
112
+ dark?: string;
113
+ /** Background colour in the same formats, or `'transparent'`. Default `'#ffffff'`. */
114
+ light?: string;
115
+ }
116
+ interface DataURLOptions extends SVGOptions, PNGOptions {
117
+ /** Image format. Default `'png'`. */
118
+ type?: 'png' | 'svg';
119
+ }
120
+ interface TerminalOptions extends QROptions {
121
+ /** Quiet zone width in modules. Default 2. */
122
+ margin?: number;
123
+ /**
124
+ * Draw dark modules with block characters, for terminals with a light background.
125
+ * By default the light modules are drawn, which suits the usual light-on-dark terminal.
126
+ */
127
+ invert?: boolean;
128
+ /** Pack two rows into one line with half blocks (`▀ ▄ █`). Default `true`; `false` uses two `█` per module. */
129
+ small?: boolean;
130
+ /** Paint with ANSI black-on-white colours so the code scans on any terminal theme. Default `false`. */
131
+ ansi?: boolean;
132
+ }
133
+ interface TextOptions extends QROptions {
134
+ /** Quiet zone width in modules. Default 4. */
135
+ margin?: number;
136
+ /** String for a dark module. Default `'##'`. */
137
+ dark?: string;
138
+ /** String for a light module. Default `' '`. */
139
+ light?: string;
140
+ /** Line separator. Default `'\n'`. */
141
+ newline?: string;
142
+ }
143
+ /** Render as an SVG string with all dark modules in one `<path>`. */
144
+ declare function toSVG(input: RenderInput, options?: SVGOptions): string;
145
+ /** Render as PNG file bytes. Synchronous, and works in any JavaScript runtime. */
146
+ declare function toPNG(input: RenderInput, options?: PNGOptions): Uint8Array;
147
+ /** Render as a `data:` URL, for `<img src>`. PNG by default; `{ type: 'svg' }` for SVG. */
148
+ declare function toDataURL(input: RenderInput, options?: DataURLOptions): string;
149
+ /** Render with Unicode block characters for printing in a terminal. */
150
+ declare function toTerminal(input: RenderInput, options?: TerminalOptions): string;
151
+ /** Render as plain text, one line per row of modules. */
152
+ declare function toText(input: RenderInput, options?: TextOptions): string;
153
+
154
+ type WifiSecurity = 'WPA' | 'WEP' | 'SAE' | 'nopass';
155
+ interface WifiOptions {
156
+ ssid: string;
157
+ /** Leave out for an open network. */
158
+ password?: string;
159
+ /** `'WPA'` covers WPA/WPA2 personal; `'SAE'` is WPA3-only. Default `'WPA'` with a password, `'nopass'` without. */
160
+ security?: WifiSecurity;
161
+ /** The network does not broadcast its SSID. */
162
+ hidden?: boolean;
163
+ }
164
+ /** Join a Wi-Fi network: `WIFI:T:WPA;S:MyNet;P:secret;;`. */
165
+ declare function wifi(options: WifiOptions): string;
166
+ interface EmailOptions {
167
+ subject?: string;
168
+ body?: string;
169
+ cc?: string | string[];
170
+ bcc?: string | string[];
171
+ }
172
+ /** Compose an email: `mailto:` URL with optional subject, body, cc and bcc. */
173
+ declare function email(to: string | string[], options?: EmailOptions): string;
174
+ /** Call a number: `tel:+15551234567`. Spaces, dashes, dots and brackets are removed. */
175
+ declare function tel(number: string): string;
176
+ /** Send a text message: `SMSTO:+15551234567:Hello`. */
177
+ declare function sms(number: string, message?: string): string;
178
+ /** A map location: `geo:48.8584,2.2945`. */
179
+ declare function geo(latitude: number, longitude: number, altitude?: number): string;
180
+ /** A link. Adds `https://` when there is no scheme. */
181
+ declare function url(link: string): string;
182
+ interface ContactOptions {
183
+ /** Full name, e.g. `'Jane Doe'`. */
184
+ name: string;
185
+ phone?: string | string[];
186
+ email?: string | string[];
187
+ url?: string;
188
+ org?: string;
189
+ title?: string;
190
+ /** Postal address as one line. */
191
+ address?: string;
192
+ note?: string;
193
+ /** `YYYY-MM-DD`. */
194
+ birthday?: string;
195
+ }
196
+ /** A contact card in MECARD format (compact; read by iOS and Android cameras). */
197
+ declare function mecard(contact: ContactOptions): string;
198
+ /** A contact card in vCard 3.0 format (more fields than MECARD, slightly larger). */
199
+ declare function vcard(contact: ContactOptions): string;
200
+
201
+ interface QRMake {
202
+ /** Encode text, bytes or segments as a QR code matrix. */
203
+ (input: QRInput, options?: QROptions): QRCode;
204
+ encode: typeof encode;
205
+ capacity: typeof capacity;
206
+ isQRCode: typeof isQRCode;
207
+ toSVG: typeof toSVG;
208
+ toPNG: typeof toPNG;
209
+ toDataURL: typeof toDataURL;
210
+ toTerminal: typeof toTerminal;
211
+ toText: typeof toText;
212
+ wifi: typeof wifi;
213
+ email: typeof email;
214
+ tel: typeof tel;
215
+ sms: typeof sms;
216
+ geo: typeof geo;
217
+ url: typeof url;
218
+ mecard: typeof mecard;
219
+ vcard: typeof vcard;
220
+ QRError: typeof QRError;
221
+ }
222
+ /** Encode text, bytes or segments as a QR code. Same as `encode`, with every other export attached. */
223
+ declare const qrmake: QRMake;
224
+
225
+ export { type Capacity, type ContactOptions, type DataURLOptions, type EmailOptions, type ErrorCorrectionLevel, type MaskPattern, type Mode, type PNGOptions, type QRCode, QRError, type QRInput, type QRMake, type QROptions, type RenderInput, type SVGOptions, type Segment, type SegmentInfo, type TerminalOptions, type TextOptions, type WifiOptions, type WifiSecurity, capacity, qrmake as default, email, encode, geo, isQRCode, mecard, qrmake, sms, tel, toDataURL, toPNG, toSVG, toTerminal, toText, url, vcard, wifi };
@@ -0,0 +1,225 @@
1
+ type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
2
+ type Mode = 'numeric' | 'alphanumeric' | 'byte' | 'kanji';
3
+ type MaskPattern = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
4
+ /** A piece of data encoded in one mode. Pass an array of these to choose the modes yourself. */
5
+ interface Segment {
6
+ mode: Mode;
7
+ /**
8
+ * `numeric` / `alphanumeric`: the characters. `byte`: a string (encoded as UTF-8) or raw bytes.
9
+ * `kanji`: a string of Shift JIS double-byte characters, or the Shift JIS bytes themselves.
10
+ */
11
+ data: string | Uint8Array;
12
+ }
13
+ /** What `qrmake()` accepts: text, raw bytes, or explicit segments. */
14
+ type QRInput = string | Uint8Array | readonly Segment[];
15
+ interface QROptions {
16
+ /** Error correction level: L ~7%, M ~15% (default), Q ~25%, H ~30% of the symbol can be damaged. */
17
+ ecl?: ErrorCorrectionLevel;
18
+ /** Use a higher error correction level when the data still fits in the same version. Default `false`. */
19
+ boostEcl?: boolean;
20
+ /** Force this exact version (1-40). Throws if the data does not fit. */
21
+ version?: number;
22
+ /** Smallest version to consider. Default 1. */
23
+ minVersion?: number;
24
+ /** Largest version to consider. Default 40. */
25
+ maxVersion?: number;
26
+ /** Force this mask pattern (0-7) instead of picking the one with the lowest penalty. */
27
+ mask?: MaskPattern;
28
+ /** Encode all text in this one mode instead of choosing automatically. */
29
+ mode?: Mode;
30
+ /**
31
+ * Split text into numeric/alphanumeric/byte runs to make the smallest code. Default `true`.
32
+ * With `false`, a single segment in the most compact mode that fits all the text is used.
33
+ */
34
+ optimize?: boolean;
35
+ /** Allow kanji mode for Japanese text (needs `TextDecoder` with Shift JIS support). Default `false`. */
36
+ kanji?: boolean;
37
+ /** Add a UTF-8 ECI header (designator 26) when byte-mode text is not plain ASCII. Default `false`. */
38
+ eci?: boolean;
39
+ }
40
+ interface SegmentInfo {
41
+ mode: Mode;
42
+ /** Number of characters (bytes for byte mode). */
43
+ length: number;
44
+ }
45
+ /** An encoded QR code. */
46
+ interface QRCode {
47
+ /** Version, 1-40. */
48
+ readonly version: number;
49
+ /** Width and height in modules (`version * 4 + 17`), without the quiet zone. */
50
+ readonly size: number;
51
+ /** Error correction level actually used. */
52
+ readonly ecl: ErrorCorrectionLevel;
53
+ /** Mask pattern actually used. */
54
+ readonly mask: MaskPattern;
55
+ /** How the data was split into modes. */
56
+ readonly segments: readonly SegmentInfo[];
57
+ /** Row-major modules, `1` = dark. Index with `y * size + x`. */
58
+ readonly modules: Uint8Array;
59
+ /** `true` if the module at column `x`, row `y` is dark. Outside the symbol (the quiet zone) is light. */
60
+ get(x: number, y: number): boolean;
61
+ /** The modules as rows of booleans (`true` = dark). */
62
+ toArray(): boolean[][];
63
+ }
64
+ declare class QRError extends RangeError {
65
+ constructor(message: string);
66
+ }
67
+ interface Capacity {
68
+ /** Data bits available, including mode and length headers. */
69
+ bits: number;
70
+ numeric: number;
71
+ alphanumeric: number;
72
+ /** Bytes (UTF-8 bytes for text). */
73
+ byte: number;
74
+ kanji: number;
75
+ }
76
+ /** How many characters fit in one segment of each mode at this version and level. */
77
+ declare function capacity(version: number, ecl?: ErrorCorrectionLevel): Capacity;
78
+ /** Encode text, bytes or segments as a QR code. */
79
+ declare function encode(input: QRInput, options?: QROptions): QRCode;
80
+ /** `true` if `value` looks like a QR code returned by `qrmake()`. */
81
+ declare function isQRCode(value: unknown): value is QRCode;
82
+
83
+ /** Text/bytes/segments to encode, or a code already made with `qrmake()`. */
84
+ type RenderInput = QRInput | QRCode;
85
+ interface SVGOptions extends QROptions {
86
+ /** Quiet zone width in modules. Default 4 (the minimum the standard asks for). */
87
+ margin?: number;
88
+ /** Pixels per module for the `width`/`height` attributes. Default 4. Ignored when `size` is set. */
89
+ scale?: number;
90
+ /** Width and height attributes in pixels. Set to `0` to leave them out (the SVG fills its container). */
91
+ size?: number;
92
+ /** Colour of dark modules (any CSS colour). Default `'#000'`. */
93
+ dark?: string;
94
+ /** Background colour (any CSS colour), or `'transparent'` for none. Default `'#fff'`. */
95
+ light?: string;
96
+ /** Corner radius of each module, from 0 (square, default) to 0.5 (dots). */
97
+ radius?: number;
98
+ /** Accessible title, added as a `<title>` element. */
99
+ title?: string;
100
+ }
101
+ interface PNGOptions extends QROptions {
102
+ /** Quiet zone width in modules. Default 4. */
103
+ margin?: number;
104
+ /** Pixels per module. Default 4. Ignored when `size` is set. */
105
+ scale?: number;
106
+ /**
107
+ * Exact image width and height in pixels. Modules are scaled by a whole number of pixels and
108
+ * any leftover pixels are added to the quiet zone. Throws if `size` is too small for 1 px modules.
109
+ */
110
+ size?: number;
111
+ /** Dark module colour: `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`. Default `'#000000'`. */
112
+ dark?: string;
113
+ /** Background colour in the same formats, or `'transparent'`. Default `'#ffffff'`. */
114
+ light?: string;
115
+ }
116
+ interface DataURLOptions extends SVGOptions, PNGOptions {
117
+ /** Image format. Default `'png'`. */
118
+ type?: 'png' | 'svg';
119
+ }
120
+ interface TerminalOptions extends QROptions {
121
+ /** Quiet zone width in modules. Default 2. */
122
+ margin?: number;
123
+ /**
124
+ * Draw dark modules with block characters, for terminals with a light background.
125
+ * By default the light modules are drawn, which suits the usual light-on-dark terminal.
126
+ */
127
+ invert?: boolean;
128
+ /** Pack two rows into one line with half blocks (`▀ ▄ █`). Default `true`; `false` uses two `█` per module. */
129
+ small?: boolean;
130
+ /** Paint with ANSI black-on-white colours so the code scans on any terminal theme. Default `false`. */
131
+ ansi?: boolean;
132
+ }
133
+ interface TextOptions extends QROptions {
134
+ /** Quiet zone width in modules. Default 4. */
135
+ margin?: number;
136
+ /** String for a dark module. Default `'##'`. */
137
+ dark?: string;
138
+ /** String for a light module. Default `' '`. */
139
+ light?: string;
140
+ /** Line separator. Default `'\n'`. */
141
+ newline?: string;
142
+ }
143
+ /** Render as an SVG string with all dark modules in one `<path>`. */
144
+ declare function toSVG(input: RenderInput, options?: SVGOptions): string;
145
+ /** Render as PNG file bytes. Synchronous, and works in any JavaScript runtime. */
146
+ declare function toPNG(input: RenderInput, options?: PNGOptions): Uint8Array;
147
+ /** Render as a `data:` URL, for `<img src>`. PNG by default; `{ type: 'svg' }` for SVG. */
148
+ declare function toDataURL(input: RenderInput, options?: DataURLOptions): string;
149
+ /** Render with Unicode block characters for printing in a terminal. */
150
+ declare function toTerminal(input: RenderInput, options?: TerminalOptions): string;
151
+ /** Render as plain text, one line per row of modules. */
152
+ declare function toText(input: RenderInput, options?: TextOptions): string;
153
+
154
+ type WifiSecurity = 'WPA' | 'WEP' | 'SAE' | 'nopass';
155
+ interface WifiOptions {
156
+ ssid: string;
157
+ /** Leave out for an open network. */
158
+ password?: string;
159
+ /** `'WPA'` covers WPA/WPA2 personal; `'SAE'` is WPA3-only. Default `'WPA'` with a password, `'nopass'` without. */
160
+ security?: WifiSecurity;
161
+ /** The network does not broadcast its SSID. */
162
+ hidden?: boolean;
163
+ }
164
+ /** Join a Wi-Fi network: `WIFI:T:WPA;S:MyNet;P:secret;;`. */
165
+ declare function wifi(options: WifiOptions): string;
166
+ interface EmailOptions {
167
+ subject?: string;
168
+ body?: string;
169
+ cc?: string | string[];
170
+ bcc?: string | string[];
171
+ }
172
+ /** Compose an email: `mailto:` URL with optional subject, body, cc and bcc. */
173
+ declare function email(to: string | string[], options?: EmailOptions): string;
174
+ /** Call a number: `tel:+15551234567`. Spaces, dashes, dots and brackets are removed. */
175
+ declare function tel(number: string): string;
176
+ /** Send a text message: `SMSTO:+15551234567:Hello`. */
177
+ declare function sms(number: string, message?: string): string;
178
+ /** A map location: `geo:48.8584,2.2945`. */
179
+ declare function geo(latitude: number, longitude: number, altitude?: number): string;
180
+ /** A link. Adds `https://` when there is no scheme. */
181
+ declare function url(link: string): string;
182
+ interface ContactOptions {
183
+ /** Full name, e.g. `'Jane Doe'`. */
184
+ name: string;
185
+ phone?: string | string[];
186
+ email?: string | string[];
187
+ url?: string;
188
+ org?: string;
189
+ title?: string;
190
+ /** Postal address as one line. */
191
+ address?: string;
192
+ note?: string;
193
+ /** `YYYY-MM-DD`. */
194
+ birthday?: string;
195
+ }
196
+ /** A contact card in MECARD format (compact; read by iOS and Android cameras). */
197
+ declare function mecard(contact: ContactOptions): string;
198
+ /** A contact card in vCard 3.0 format (more fields than MECARD, slightly larger). */
199
+ declare function vcard(contact: ContactOptions): string;
200
+
201
+ interface QRMake {
202
+ /** Encode text, bytes or segments as a QR code matrix. */
203
+ (input: QRInput, options?: QROptions): QRCode;
204
+ encode: typeof encode;
205
+ capacity: typeof capacity;
206
+ isQRCode: typeof isQRCode;
207
+ toSVG: typeof toSVG;
208
+ toPNG: typeof toPNG;
209
+ toDataURL: typeof toDataURL;
210
+ toTerminal: typeof toTerminal;
211
+ toText: typeof toText;
212
+ wifi: typeof wifi;
213
+ email: typeof email;
214
+ tel: typeof tel;
215
+ sms: typeof sms;
216
+ geo: typeof geo;
217
+ url: typeof url;
218
+ mecard: typeof mecard;
219
+ vcard: typeof vcard;
220
+ QRError: typeof QRError;
221
+ }
222
+ /** Encode text, bytes or segments as a QR code. Same as `encode`, with every other export attached. */
223
+ declare const qrmake: QRMake;
224
+
225
+ export { type Capacity, type ContactOptions, type DataURLOptions, type EmailOptions, type ErrorCorrectionLevel, type MaskPattern, type Mode, type PNGOptions, type QRCode, QRError, type QRInput, type QRMake, type QROptions, type RenderInput, type SVGOptions, type Segment, type SegmentInfo, type TerminalOptions, type TextOptions, type WifiOptions, type WifiSecurity, capacity, qrmake as default, email, encode, geo, isQRCode, mecard, qrmake, sms, tel, toDataURL, toPNG, toSVG, toTerminal, toText, url, vcard, wifi };