qrmake 1.0.0-test → 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/CHANGELOG.md +20 -0
- package/README.md +650 -4
- package/dist/cli.js +41 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +225 -0
- package/dist/index.d.ts +225 -0
- package/dist/index.js +4 -0
- package/package.json +59 -7
- package/index.d.ts +0 -2
- package/index.js +0 -8
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var x=class extends RangeError{constructor(t){super(t),this.name="QRError"}},X={L:0,M:1,Q:2,H:3},ve={L:1,M:0,Q:3,H:2},we=["L","M","Q","H"],Ae=[[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]],$e=[[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]],Ge={numeric:1,alphanumeric:2,byte:4,kanji:8},De={numeric:[10,12,14],alphanumeric:[9,11,13],byte:[8,16,16],kanji:[8,10,12]},P=["numeric","alphanumeric","byte","kanji"],Re="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",Me=e=>e<=9?0:e<=26?1:2,M=(e,t)=>De[e][Me(t)];function ke(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 O(e,t){let n=X[t];return(ke(e)>>3)-Ae[n][e]*$e[n][e]}function Be(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 Y(e,t="M"){N(e,"version"),Se(t);let n=O(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 T=new Uint8Array(512),W=new Uint8Array(256);{let e=1;for(let t=0;t<255;t++)T[t]=e,W[e]=t,e<<=1,e&256&&(e^=285);for(let t=255;t<512;t++)T[t]=T[t-255]}var q=(e,t)=>e===0||t===0?0:T[W[e]+W[t]],ge=new Map;function ze(e){let t=ge.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]=q(t[o],n)^(o+1<e?t[o+1]:0);n=q(n,2)}return ge.set(e,t),t}function Ve(e,t){let n=ze(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]^=q(n[s],i)}return r}function _e(e,t,n){let r=X[n],o=$e[r][t],i=Ae[r][t],s=ke(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(Ve(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 H=class{constructor(){this.bits=[]}put(t,n){for(let r=n-1;r>=0;r--)this.bits.push(t>>>r&1)}};function Fe(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 S;function We(){if(S!==void 0)return S;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)}S=t.size>0?t:null}catch{S=null}return S}function Ce(e,t){let n=t?We():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:Fe(i),numeric:i>=48&&i<=57,alnum:i<128?Re.indexOf(o):-1,sjis:n?.get(i)??-1})}return r}function Ue(e){return Array.from(e,t=>({bytes:[t],numeric:t>=48&&t<=57,alnum:t<128?Re.indexOf(String.fromCharCode(t)):-1,sjis:-1}))}var Z=(e,t)=>t==="byte"||(t==="numeric"?e.numeric:t==="alphanumeric"?e.alnum>=0:e.sjis>=0);function qe(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 ee=e=>e.mode==="byte"?e.units.reduce((t,n)=>t+n.bytes.length,0):e.units.length;function ye(e,t,n){let r=n?12:0;for(let o of e){let i=M(o.mode,t);if(ee(o)>=2**i)return 1/0;r+=4+i+qe(o)}return r}function He(e,t,n){if(e.length===0)return[{mode:"byte",units:[]}];let r=n?P:P.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(!Z(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 Je(e,t){for(let n of["numeric","alphanumeric",...t?["kanji"]:[]])if(e.length>0&&e.every(r=>Z(r,n)))return{mode:n,units:e};return{mode:"byte",units:e}}function Ee(e,t,n){let r=e.findIndex(o=>!Z(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 Ke(e){if(!e||!P.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"?Ce(n,t==="kanji"):Ue(n);return Ee(r,t,typeof n=="string"?n:"")}function Xe(e,t,n){e.put(Ge[t.mode],4),e.put(ee(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 Ye=21522;function xe(e,t){let n=ve[e]<<3|t,r=n;for(let o=0;o<10;o++)r=r<<1^(r>>>9)*1335;return(n<<10|r)^Ye}function Ze(e){let t=e;for(let n=0;n<12;n++)t=t<<1^(t>>>11)*7973;return e<<12|t}var et=[(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],J=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 tt(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=Be(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(K(e,0),t>=7){let i=Ze(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 K(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 nt(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 F(e,t){let{size:n,modules:r,reserved:o}=e,i=et[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 rt(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 N(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 Se(e){if(!we.includes(e))throw new x(`ecl must be 'L', 'M', 'Q' or 'H', got ${JSON.stringify(e)}`)}function E(e,t={}){let n=t.ecl??"M";Se(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 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&&!P.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"?Ce(e,s):Ue(e);if(u=h.some(w=>w.bytes.length>1||(w.bytes[0]??0)>127),t.mode){let w=Ee(h,t.mode,typeof e=="string"?e:"");a=()=>[w]}else if(t.optimize===!1){let w=Je(h,s);a=()=>[w]}else{let w=[];a=k=>{var he;return w[he=Me(k)]??(w[he]=He(h,k,s))}}}else if(Array.isArray(e)){let h=e.map(Ke);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=ye(d,m,f);for(;p>O(m,n)*8;){if(m>=o){let h=O(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=ye(d,m,f)}let c=n;if(t.boostEcl)for(let h of we.slice(X[n]+1))p<=O(m,h)*8&&(c=h);let g=O(m,c)*8,b=new H;f&&(b.put(7,4),b.put(26,8));for(let h of d)Xe(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=_e(l,m,c),A=m*4+17,$=new J(A);tt($,m),nt($,y);let j=i??0;if(i===void 0){let h=1/0;for(let w=0;w<8;w++){F($,w),K($,xe(c,w));let k=rt($.modules,A);k<h&&(h=k,j=w),F($,w)}}return F($,j),K($,xe(c,j)),ot(m,c,j,d.map(h=>({mode:h.mode,length:ee(h)})),$.modules)}function ot(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 I(e){return typeof e=="object"&&e!==null&&e.modules instanceof Uint8Array&&typeof e.size=="number"&&typeof e.get=="function"}var it=(()=>{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 st(e,t=0){t=~t;for(let n=0;n<e.length;n++)t=it[(t^e[n])&255]^t>>>8;return~t>>>0}function at(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 ne=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)}},Oe=[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],Ie=[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],Qe=[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],Le=[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 te(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 je(e,t){let n=e.length-1;for(;e[n]>t;)n--;return n}function ft(e,t){let n=new ne(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=je(Oe,s);te(n,257+u),Ie[u]&&n.bits(s-Oe[u],Ie[u]);let f=je(Qe,a);n.code(f,5),Le[f]&&n.bits(a-Qe[f],Le[f]),i+=s}else te(n,e[i]),i++}return te(n,256),n.finish()}function ut(e,t){let n=ft(e,t),r=new Uint8Array(n.length+6);r[0]=120,r[1]=1,r.set(n,2);let o=at(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 v=e=>[e>>>24,e>>>16&255,e>>>8&255,e&255];function Q(e,t){let n=new Uint8Array(12+t.length);n.set(v(t.length),0);for(let r=0;r<4;r++)n[4+r]=e.charCodeAt(r);return n.set(t,8),n.set(v(st(n.subarray(4,8+t.length))),8+t.length),n}function Te(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",[...v(e),...v(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",ut(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 D(e,t){return I(e)?e:E(e,t)}function C(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 ct(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 re=e=>e.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t]),L=e=>String(Math.round(e*1e3)/1e3);function B(e,t={}){let n=D(e,t),r=C(t.margin,"margin",4),o=ct(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=re(t.dark??"#000"),a=t.light??"#fff",u=n.size+r*2,f=t.size===void 0?u*o:C(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>${re(t.title)}</title>`:"",g=a==="transparent"?"":`<rect width="${u}" height="${u}" fill="${re(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 Ne(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 z(e,t={}){let n=D(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 x(`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 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 Te(s,s,f,[Ne(t.light??"#ffffff"),Ne(t.dark??"#000000")])}var G="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function lt(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+=G[r>>2]+G[(r&3)<<4|(o??0)>>4],t+=o===void 0?"=":G[(o&15)<<2|(i??0)>>6],t+=i===void 0?"=":G[i&63]}return t}function oe(e,t={}){let n=t.type??"png";if(n==="svg")return"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(B(e,t));if(n!=="png")throw new x(`type must be 'png' or 'svg', got ${JSON.stringify(n)}`);return"data:image/png;base64,"+lt(z(e,t))}function ie(e,t={}){let n=D(e,t),r=C(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 se(e,t={}){let n=D(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 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 fe(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 ae=e=>(Array.isArray(e)?e:[e]).map(t=>encodeURIComponent(t).replace(/%40/g,"@")).join(",");function ue(e,t={}){let n=[];return t.cc&&n.push("cc="+ae(t.cc)),t.bcc&&n.push("bcc="+ae(t.bcc)),t.subject&&n.push("subject="+encodeURIComponent(t.subject)),t.body&&n.push("body="+encodeURIComponent(t.body)),`mailto:${ae(e)}${n.length?"?"+n.join("&"):""}`}var _=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 ce(e){return"tel:"+_(e)}function le(e,t){return`SMSTO:${_(e)}${t?":"+t:""}`}function me(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 de(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 V=e=>e===void 0?[]:Array.isArray(e)?e:[e];function pe(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 V(e.phone))t.push(`TEL:${R(_(n))}`);for(let n of V(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 U=e=>e.replace(/([\\;,])/g,"\\$1").replace(/\r?\n/g,"\\n");function be(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:${U(n)};${U(t.join(" "))};;;`,`FN:${U(e.name)}`];e.org&&r.push(`ORG:${U(e.org)}`),e.title&&r.push(`TITLE:${U(e.title)}`);for(let o of V(e.phone))r.push(`TEL:${_(o)}`);for(let o of V(e.email))r.push(`EMAIL:${o}`);return e.url&&r.push(`URL:${e.url}`),e.address&&r.push(`ADR:;;${U(e.address)};;;;`),e.birthday&&r.push(`BDAY:${e.birthday}`),e.note&&r.push(`NOTE:${U(e.note)}`),r.push("END:VCARD"),r.join(`\r
|
|
4
|
+
`)}var Pe=((e,t)=>E(e,t));Object.assign(Pe,{encode:E,capacity:Y,isQRCode:I,toSVG:B,toPNG:z,toDataURL:oe,toTerminal:ie,toText:se,wifi:fe,email:ue,tel:ce,sms:le,geo:me,url:de,mecard:pe,vcard:be,QRError:x});var At=Pe;export{x as QRError,Y as capacity,At as default,ue as email,E as encode,me as geo,I as isQRCode,pe as mecard,Pe as qrmake,le as sms,ce as tel,oe as toDataURL,z as toPNG,B as toSVG,ie as toTerminal,se as toText,de as url,be as vcard,fe as wifi};
|
package/package.json
CHANGED
|
@@ -1,10 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qrmake",
|
|
3
|
-
"version": "1.0.0
|
|
4
|
-
"description": "Generate QR codes as SVG, PNG or terminal text,
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generate QR codes as SVG, PNG, data URLs or terminal text. From-scratch ISO/IEC 18004 encoder (versions 1-40, L/M/Q/H, numeric/alphanumeric/byte/kanji, optimal segments), sync pure-JS PNG, Wi-Fi/vCard/email helpers, CLI. ESM + CommonJS, zero dependencies.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"qr",
|
|
7
|
+
"qrcode",
|
|
8
|
+
"qr-code",
|
|
9
|
+
"qrcode-generator",
|
|
10
|
+
"qr-generator",
|
|
11
|
+
"qrcode-terminal",
|
|
12
|
+
"qr-image",
|
|
13
|
+
"barcode",
|
|
14
|
+
"2d-barcode",
|
|
15
|
+
"svg",
|
|
16
|
+
"png",
|
|
17
|
+
"data-url",
|
|
18
|
+
"terminal",
|
|
19
|
+
"cli",
|
|
20
|
+
"wifi",
|
|
21
|
+
"vcard",
|
|
22
|
+
"mecard",
|
|
23
|
+
"reed-solomon",
|
|
24
|
+
"iso-18004",
|
|
25
|
+
"zero-dependency"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"main": "./dist/index.cjs",
|
|
31
|
+
"module": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/index.d.cts",
|
|
41
|
+
"default": "./dist/index.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"bin": {
|
|
47
|
+
"qrmake": "./dist/cli.js"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist",
|
|
51
|
+
"CHANGELOG.md"
|
|
52
|
+
],
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"typecheck": "tsc -p .",
|
|
60
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
61
|
+
}
|
|
10
62
|
}
|
package/index.d.ts
DELETED