dingtalk-qr-code 1.0.0 → 1.0.1
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/index.js +1 -22
- package/package.json +3 -2
- package/types/index.d.ts +4 -0
package/dist/index.js
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import qr from "./qr";
|
|
3
|
-
export function generate(ctx, text, params) {
|
|
4
|
-
const {
|
|
5
|
-
logo,
|
|
6
|
-
ecc = 2,
|
|
7
|
-
size = 512,
|
|
8
|
-
shape = "square",
|
|
9
|
-
background = "#FFFFFF"
|
|
10
|
-
} = params || {};
|
|
11
|
-
ctx.canvas.width = size;
|
|
12
|
-
ctx.canvas.height = size;
|
|
13
|
-
ctx.save();
|
|
14
|
-
ctx.fillStyle = background;
|
|
15
|
-
ctx.fillRect(0, 0, size, size);
|
|
16
|
-
ctx.restore();
|
|
17
|
-
qr.draw(text, ctx, size, Number(ecc), {
|
|
18
|
-
imageUrl: logo,
|
|
19
|
-
shape,
|
|
20
|
-
background
|
|
21
|
-
});
|
|
22
|
-
}
|
|
1
|
+
var o0=[0,11,15,19,23,27,31,16,18,20,22,24,26,28,20,22,24,24,26,28,28,22,24,24,26,26,28,28,24,24,26,26,26,28,28,24,26,26,26,28,28],d0=[3220,1468,2713,1235,3062,1890,2119,1549,2344,2936,1117,2583,1330,2470,1667,2249,2028,3780,481,4011,142,3098,831,3445,592,2517,1776,2234,1951,2827,1070,2660,1345,3177],i0=[30660,29427,32170,30877,26159,25368,27713,26998,21522,20773,24188,23371,17913,16590,20375,19104,13663,12392,16177,14854,9396,8579,11994,11245,5769,5054,7399,6608,1890,597,3340,2107],H=[1,0,19,7,1,0,16,10,1,0,13,13,1,0,9,17,1,0,34,10,1,0,28,16,1,0,22,22,1,0,16,28,1,0,55,15,1,0,44,26,2,0,17,18,2,0,13,22,1,0,80,20,2,0,32,18,2,0,24,26,4,0,9,16,1,0,108,26,2,0,43,24,2,2,15,18,2,2,11,22,2,0,68,18,4,0,27,16,4,0,19,24,4,0,15,28,2,0,78,20,4,0,31,18,2,4,14,18,4,1,13,26,2,0,97,24,2,2,38,22,4,2,18,22,4,2,14,26,2,0,116,30,3,2,36,22,4,4,16,20,4,4,12,24,2,2,68,18,4,1,43,26,6,2,19,24,6,2,15,28,4,0,81,20,1,4,50,30,4,4,22,28,3,8,12,24,2,2,92,24,6,2,36,22,4,6,20,26,7,4,14,28,4,0,107,26,8,1,37,22,8,4,20,24,12,4,11,22,3,1,115,30,4,5,40,24,11,5,16,20,11,5,12,24,5,1,87,22,5,5,41,24,5,7,24,30,11,7,12,24,5,1,98,24,7,3,45,28,15,2,19,24,3,13,15,30,1,5,107,28,10,1,46,28,1,15,22,28,2,17,14,28,5,1,120,30,9,4,43,26,17,1,22,28,2,19,14,28,3,4,113,28,3,11,44,26,17,4,21,26,9,16,13,26,3,5,107,28,3,13,41,26,15,5,24,30,15,10,15,28,4,4,116,28,17,0,42,26,17,6,22,28,19,6,16,30,2,7,111,28,17,0,46,28,7,16,24,30,34,0,13,24,4,5,121,30,4,14,47,28,11,14,24,30,16,14,15,30,6,4,117,30,6,14,45,28,11,16,24,30,30,2,16,30,8,4,106,26,8,13,47,28,7,22,24,30,22,13,15,30,10,2,114,28,19,4,46,28,28,6,22,28,33,4,16,30,8,4,122,30,22,3,45,28,8,26,23,30,12,28,15,30,3,10,117,30,3,23,45,28,4,31,24,30,11,31,15,30,7,7,116,30,21,7,45,28,1,37,23,30,19,26,15,30,5,10,115,30,19,10,47,28,15,25,24,30,23,25,15,30,13,3,115,30,2,29,46,28,42,1,24,30,23,28,15,30,17,0,115,30,10,23,46,28,10,35,24,30,19,35,15,30,17,1,115,30,14,21,46,28,29,19,24,30,11,46,15,30,13,6,115,30,14,23,46,28,44,7,24,30,59,1,16,30,12,7,121,30,12,26,47,28,39,14,24,30,22,41,15,30,6,14,121,30,6,34,47,28,46,10,24,30,2,64,15,30,17,4,122,30,29,14,46,28,49,10,24,30,24,46,15,30,4,18,122,30,13,32,46,28,48,14,24,30,42,32,15,30,20,4,117,30,40,7,47,28,43,22,24,30,10,67,15,30,19,6,118,30,18,31,47,28,34,34,24,30,20,61,15,30],V=[255,0,1,25,2,50,26,198,3,223,51,238,27,104,199,75,4,100,224,14,52,141,239,129,28,193,105,248,200,8,76,113,5,138,101,47,225,36,15,33,53,147,142,218,240,18,130,69,29,181,194,125,106,39,249,185,201,154,9,120,77,228,114,166,6,191,139,98,102,221,48,253,226,152,37,179,16,145,34,136,54,208,148,206,143,150,219,189,241,210,19,92,131,56,70,64,30,66,182,163,195,72,126,110,107,58,40,84,250,133,186,61,202,94,155,159,10,21,121,43,78,212,229,172,115,243,167,87,7,112,192,247,140,128,99,13,103,74,222,237,49,197,254,24,227,165,153,119,38,184,180,124,17,68,146,217,35,32,137,46,55,63,209,91,149,188,207,205,144,135,151,178,220,252,190,97,242,86,211,171,20,42,93,158,132,60,57,83,71,109,65,162,31,45,67,216,183,123,164,118,196,23,73,236,127,12,111,246,108,161,59,82,41,157,85,170,251,96,134,177,187,204,62,90,203,89,95,176,156,169,160,81,11,245,22,235,122,117,44,215,79,174,213,233,230,231,173,232,116,214,244,234,168,80,88,175],y=[1,2,4,8,16,32,64,128,29,58,116,232,205,135,19,38,76,152,45,90,180,117,234,201,143,3,6,12,24,48,96,192,157,39,78,156,37,74,148,53,106,212,181,119,238,193,159,35,70,140,5,10,20,40,80,160,93,186,105,210,185,111,222,161,95,190,97,194,153,47,94,188,101,202,137,15,30,60,120,240,253,231,211,187,107,214,177,127,254,225,223,163,91,182,113,226,217,175,67,134,17,34,68,136,13,26,52,104,208,189,103,206,129,31,62,124,248,237,199,147,59,118,236,197,151,51,102,204,133,23,46,92,184,109,218,169,79,158,33,66,132,21,42,84,168,77,154,41,82,164,85,170,73,146,57,114,228,213,183,115,230,209,191,99,198,145,63,126,252,229,215,179,123,246,241,255,227,219,171,75,150,49,98,196,149,55,110,220,165,87,174,65,130,25,50,100,200,141,7,14,28,56,112,224,221,167,83,166,81,162,89,178,121,242,249,239,195,155,43,86,172,69,138,9,18,36,72,144,61,122,244,245,247,243,251,235,203,139,11,22,44,88,176,125,250,233,207,131,27,54,108,216,173,71,142,0],s=[],N=[],l=[],K=[],w=[],k,e,F,M,m,R,W=2;function P(o,x){var a;o>x&&(a=o,o=x,x=a),a=x,a*=x,a+=x,a>>=1,a+=o,K[a]=1}function _(o,x){var a;for(l[o+e*x]=1,a=-2;a<2;a++)l[o+a+e*(x-2)]=1,l[o-2+e*(x+a+1)]=1,l[o+2+e*(x+a)]=1,l[o+a+1+e*(x+2)]=1;for(a=0;a<2;a++)P(o-1,x+a),P(o+1,x-a),P(o-a,x-1),P(o+a,x+1)}function G(o){for(;o>=255;)o-=255,o=(o>>8)+(o&255);return o}var p=[];function Z(o,x,a,f){var r,i,d;for(r=0;r<f;r++)s[a+r]=0;for(r=0;r<x;r++){if(d=V[s[o+r]^s[a]],d!=255)for(i=1;i<f;i++)s[a+i-1]=s[a+i]^y[G(d+p[f-i])];else for(i=a;i<a+f;i++)s[i]=s[i+1];s[a+f-1]=d==255?0:y[G(d+p[0])]}}function C(o,x){var a;return o>x&&(a=o,o=x,x=a),a=x,a+=x*x,a>>=1,a+=o,K[a]}function $(o){var x,a,f,r;switch(o){case 0:for(a=0;a<e;a++)for(x=0;x<e;x++)!(x+a&1)&&!C(x,a)&&(l[x+a*e]^=1);break;case 1:for(a=0;a<e;a++)for(x=0;x<e;x++)!(a&1)&&!C(x,a)&&(l[x+a*e]^=1);break;case 2:for(a=0;a<e;a++)for(f=0,x=0;x<e;x++,f++)f==3&&(f=0),!f&&!C(x,a)&&(l[x+a*e]^=1);break;case 3:for(r=0,a=0;a<e;a++,r++)for(r==3&&(r=0),f=r,x=0;x<e;x++,f++)f==3&&(f=0),!f&&!C(x,a)&&(l[x+a*e]^=1);break;case 4:for(a=0;a<e;a++)for(f=0,r=a>>1&1,x=0;x<e;x++,f++)f==3&&(f=0,r=!r),!r&&!C(x,a)&&(l[x+a*e]^=1);break;case 5:for(r=0,a=0;a<e;a++,r++)for(r==3&&(r=0),f=0,x=0;x<e;x++,f++)f==3&&(f=0),!((x&a&1)+!(!f|!r))&&!C(x,a)&&(l[x+a*e]^=1);break;case 6:for(r=0,a=0;a<e;a++,r++)for(r==3&&(r=0),f=0,x=0;x<e;x++,f++)f==3&&(f=0),!((x&a&1)+(f&&f==r)&1)&&!C(x,a)&&(l[x+a*e]^=1);break;case 7:for(r=0,a=0;a<e;a++,r++)for(r==3&&(r=0),f=0,x=0;x<e;x++,f++)f==3&&(f=0),!((f&&f==r)+(x+a&1)&1)&&!C(x,a)&&(l[x+a*e]^=1);break}}var c0=3,n0=3,b0=40,l0=10;function S(o){var x,a=0;for(x=0;x<=o;x++)w[x]>=5&&(a+=c0+w[x]-5);for(x=3;x<o-1;x+=2)w[x-2]==w[x+2]&&w[x+2]==w[x-1]&&w[x-1]==w[x+1]&&w[x-1]*3==w[x]&&(w[x-3]==0||x+3>o||w[x-3]*3>=w[x]*4||w[x+3]*3>=w[x]*4)&&(a+=b0);return a}function h0(){var o,x,a,f,r,i=0,d=0;for(x=0;x<e-1;x++)for(o=0;o<e-1;o++)(l[o+e*x]&&l[o+1+e*x]&&l[o+e*(x+1)]&&l[o+1+e*(x+1)]||!(l[o+e*x]||l[o+1+e*x]||l[o+e*(x+1)]||l[o+1+e*(x+1)]))&&(i+=n0);for(x=0;x<e;x++){for(w[0]=0,a=f=o=0;o<e;o++)(r=l[o+e*x])==f?w[a]++:w[++a]=1,f=r,d+=f?1:-1;i+=S(a)}d<0&&(d=-d);var h=d,T=0;for(h+=h<<2,h<<=1;h>e*e;)h-=e*e,T++;for(i+=T*l0,o=0;o<e;o++){for(w[0]=0,a=f=x=0;x<e;x++)(r=l[o+e*x])==f?w[a]++:w[++a]=1,f=r;i+=S(a)}return i}function X(o){var x,a,f,r,i,d,h,T;r=o.length,k=0;do if(k++,f=(W-1)*4+(k-1)*16,F=H[f++],M=H[f++],m=H[f++],R=H[f],f=m*(F+M)+M-3+(k<=9),r<=f)break;while(k<40);for(e=17+4*k,i=m+(m+R)*(F+M)+M,r=0;r<i;r++)N[r]=0;for(s=o.slice(0),r=0;r<e*e;r++)l[r]=0;for(r=0;r<(e*(e+1)+1)/2;r++)K[r]=0;for(r=0;r<3;r++){for(f=0,a=0,r==1&&(f=e-7),r==2&&(a=e-7),l[a+3+e*(f+3)]=1,x=0;x<6;x++)l[a+x+e*f]=1,l[a+e*(f+x+1)]=1,l[a+6+e*(f+x)]=1,l[a+x+1+e*(f+6)]=1;for(x=1;x<5;x++)P(a+x,f+1),P(a+1,f+x+1),P(a+5,f+x),P(a+x+1,f+5);for(x=2;x<4;x++)l[a+x+e*(f+2)]=1,l[a+2+e*(f+x+1)]=1,l[a+4+e*(f+x)]=1,l[a+x+1+e*(f+4)]=1}if(k>1)for(r=o0[k],a=e-7;;){for(x=e-7;x>r-3&&(_(x,a),!(x<r));)x-=r;if(a<=r+9)break;a-=r,_(6,a),_(a,6)}for(l[8+e*(e-8)]=1,a=0;a<7;a++)P(7,a),P(e-8,a),P(7,a+e-7);for(x=0;x<8;x++)P(x,7),P(x+e-8,7),P(x,e-8);for(x=0;x<9;x++)P(x,8);for(x=0;x<8;x++)P(x+e-8,8),P(8,x);for(a=0;a<7;a++)P(8,a+e-7);for(x=0;x<e-14;x++)x&1?(P(8+x,6),P(6,8+x)):(l[8+x+e*6]=1,l[6+e*(8+x)]=1);if(k>6)for(r=d0[k-7],f=17,x=0;x<6;x++)for(a=0;a<3;a++,f--)1&(f>11?k>>f-12:r>>f)?(l[5-x+e*(2-a+e-11)]=1,l[2-a+e-11+e*(5-x)]=1):(P(5-x,2-a+e-11),P(2-a+e-11,5-x));for(a=0;a<e;a++)for(x=0;x<=a;x++)l[x+e*a]&&P(x,a);for(i=s.length,d=0;d<i;d++)N[d]=s.charCodeAt(d);if(s=N.slice(0),x=m*(F+M)+M,i>=x-2&&(i=x-2,k>9&&i--),d=i,k>9){for(s[d+2]=0,s[d+3]=0;d--;)r=s[d],s[d+3]|=255&r<<4,s[d+2]=r>>4;s[2]|=255&i<<4,s[1]=i>>4,s[0]=64|i>>12}else{for(s[d+1]=0,s[d+2]=0;d--;)r=s[d],s[d+2]|=255&r<<4,s[d+1]=r>>4;s[1]|=255&i<<4,s[0]=64|i>>4}for(d=i+3-(k<10);d<x;)s[d++]=236,s[d++]=17;for(p[0]=1,d=0;d<R;d++){for(p[d+1]=1,h=d;h>0;h--)p[h]=p[h]?p[h-1]^y[G(V[p[h]]+d)]:p[h-1];p[0]=y[G(V[p[0]]+d)]}for(d=0;d<=R;d++)p[d]=V[p[d]];for(f=x,a=0,d=0;d<F;d++)Z(a,m,f,R),a+=m,f+=R;for(d=0;d<M;d++)Z(a,m+1,f,R),a+=m+1,f+=R;for(a=0,d=0;d<m;d++){for(h=0;h<F;h++)N[a++]=s[d+h*m];for(h=0;h<M;h++)N[a++]=s[F*m+d+h*(m+1)]}for(h=0;h<M;h++)N[a++]=s[F*m+d+h*(m+1)];for(d=0;d<R;d++)for(h=0;h<F+M;h++)N[a++]=s[x+d+h*R];for(s=N,x=a=e-1,f=i=1,T=(m+R)*(F+M)+M,d=0;d<T;d++)for(r=s[d],h=0;h<8;h++,r<<=1){128&r&&(l[x+e*a]=1);do i?x--:(x++,f?a!=0?a--:(x-=2,f=!f,x==6&&(x--,a=9)):a!=e-1?a++:(x-=2,f=!f,x==6&&(x--,a-=8))),i=!i;while(C(x,a))}for(s=l.slice(0),r=0,a=3e4,f=0;f<8&&($(f),x=h0(),x<a&&(a=x,r=f),r!=7);f++)l=s.slice(0);for(r!=f&&$(r),a=i0[r+(W-1<<3)],f=0;f<8;f++,a>>=1)a&1&&(l[e-1-f+e*8]=1,f<6?l[8+e*f]=1:l[8+e*(f+1)]=1);for(f=0;f<7;f++,a>>=1)a&1&&(l[8+e*(e-7+f)]=1,f?l[6-f+e*8]=1:l[7+e*8]=1);return l}var J=null,O=null,B={get ecclevel(){return W},set ecclevel(o){W=o},get size(){return O},set size(o){O=o},get canvas(){return J},set canvas(o){J=o},getFrame:function(x){return X(x)},draw:function(x,a,f,r,i){var d=i.imageUrl,h=i.shape,T=i.background,Q={get width(){return f},get height(){return f},getContext:function(){return a}};B._draw(x,Q,f,r,{imageUrl:d,shape:h,background:T})},_draw:function(x,a,f,r,i){var d=i.imageUrl,h=i.shape,T=i.background;if(W=r||W,a=a||J,!a){console.warn("No canvas provided to draw QR code in!");return}f=f||O||Math.min(a.width,a.height);var Q=X(x),c=a.getContext("2d"),t=.9*f/e,v=0,E=1,j=.8;c.fillStyle="black";for(var Y=function(u,g){return u>=0&&u<=6&&g>=0&&g<=6||u>=0&&u<=6&&g>=e-7&&g<e||u>=e-7&&u<e&&g>=0&&g<=6},x0=function(){n===3&&b===3&&(c.beginPath(),c.arc(t*n+.05*f+v+.5*t,t*b+.05*f+v+.5*t,1.5*t*E,0,2*Math.PI),c.fill(),c.beginPath(),c.arc(t*n+.05*f+v+.5*t,t*b+.05*f+v+.5*t,3*t*E,.5*Math.PI,1.5*Math.PI,!0),c.lineWidth=t,c.stroke(),c.closePath())},a0=function(){n==3&&b===e-4&&(c.beginPath(),c.arc(t*n+.05*f+v+.5*t,t*b+.05*f+v+.5*t,1.5*t*E,0,2*Math.PI),c.fill(),c.beginPath(),c.arc(t*n+.05*f+v+.5*t,t*b+.05*f+v+.5*t,3*t*E,.5*Math.PI,1.5*Math.PI,!0),c.lineWidth=t,c.stroke(),c.closePath())},f0=function(){b==3&&n===e-4&&(c.beginPath(),c.arc(t*n+.05*f+v+.5*t,t*b+.05*f+v+.5*t,1.5*t*E,0,2*Math.PI),c.fill(),c.beginPath(),c.arc(t*n+.05*f+v+.5*t,t*b+.05*f+v+.5*t,3*t*E,.5*Math.PI,1.5*Math.PI,!0),c.lineWidth=t,c.stroke(),c.closePath())},e0=function(){return n>=e-3&&b==0||n===e-1&&b>=0&&b<=6||b===6&&n>=e-3||n>=4&&b===e-7||n>=4&&b===e-1||n===6&&b>=e-7||n<=7&&n>=4&&b===0||n===6&&b>=0&&b<=6||b===6&&n>=4&&n<6?!0:n>=2&&n<=5&&b>=2&&b<=5||n>=e-5&&n<=e-2&&b>=2&&b<=5||b>=e-5&&b<=e-2&&n>=2&&n<=5},r0=function(){n===0&&b===0||n===e-7&&b===0||n===0&&b===e-7?(c.beginPath(),c.moveTo(t*n+.05*f+v+t,t*b+.05*f+v+t),c.arc(t*n+.05*f+v+t,t*b+.05*f+v+t,t,Math.PI,1.5*Math.PI),c.fill(),c.closePath()):n===0&&b===6||n===0&&b===e-1||n===e-7&&b===6?(c.beginPath(),c.moveTo(t*n+.05*f+v+t,t*b+.05*f+v),c.arc(t*n+.05*f+v+t,t*b+.05*f+v,t,.5*Math.PI,Math.PI),c.fill(),c.closePath()):Y(n,b)&&!e0()&&c.fillRect(t*n+.05*f+v,t*b+.05*f+v,t,t)},t0=function(u,g,U){U.moveTo(u.x+g,u.y),U.lineTo(u.x+u.width-g,u.y),U.arc(u.x+u.width-g,u.y+g,g,Math.PI/180*270,0,!1),U.lineTo(u.x+u.width,u.y+u.height-g),U.arc(u.x+u.width-g,u.y+u.height-g,g,0,Math.PI/180*90,0,!1),U.lineTo(u.x+g,u.y+u.height),U.arc(u.x+g,u.y+u.height-g,g,Math.PI/180*90,Math.PI/180*180,!1),U.lineTo(u.x,u.y+g),U.arc(u.x+g,u.y+g,g,Math.PI/180*180,Math.PI/180*270,!1),U.clip()},n=0;n<e;n++)for(var b=0;b<e;b++)Q[b*e+n]&&(x0(),a0(),f0(),r0(),Y(n,b)||(c.beginPath(),c.arc(t*n+.05*f+v+.5*t,t*b+.05*f+v+.5*t,.5*t*j,0,2*Math.PI),c.fill()));if(d){var D=Math.floor(11*e/45);D%2===0&&D--;for(var I=D-2,n=0;n<e;n++)for(var b=0;b<e;b++){var A=e/2+I/2;A-n>=0&&A-n<=I+1&&A-b>=0&&A-b<=I+1&&c.clearRect(t*n+.05*f+v,t*b+.05*f+v,t,t)}var L=t*(e/2)+.05*f+v;c.fillStyle=T==="transparant"?"rgba(255, 255, 255, 0)":T,c.fillRect(L-D/2*t,L-D/2*t,D*t,D*t),c.save(),h==="circle"?(c.arc(L,L,I/2*t,0,2*Math.PI),c.clip()):t0({x:L-I/2*t,y:L-I/2*t,width:I*t,height:I*t},I*t*1/6,c),c.drawImage(d,L-I/2*t,L-I/2*t,I*t,I*t),c.restore()}},toDataURL:function(x,a,f){var r=document.createElement("canvas");return r.width=a||O||240,r.height=r.width,B.draw(x,r,r.width,f),r.toDataURL()},makeImage:function(x,a,f){var r=new Image;return r.src=B.toDataURL(x,a,f),r}},z=B;function s0(o,x,a){let{logo:f,ecc:r=2,size:i=512,shape:d="square",background:h="#FFFFFF"}=a||{};o.canvas.width=i,o.canvas.height=i,o.save(),o.fillStyle=h,o.fillRect(0,0,i,i),o.restore(),z.draw(x,o,i,Number(r),{imageUrl:f,shape:d,background:h})}var g0={generate:s0};export{g0 as default,s0 as generate};
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dingtalk-qr-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"test": "bun run ./test/basic.ts",
|
|
7
8
|
"clean": "rimraf dist types",
|
|
8
|
-
"build": "npm run clean && esbuild ./src/index.ts --outfile=./dist/index.js && tsc"
|
|
9
|
+
"build": "npm run clean && esbuild ./src/index.ts --outfile=./dist/index.js --bundle --minify --target=es2015 --format=esm && tsc"
|
|
9
10
|
},
|
|
10
11
|
"types": "./types",
|
|
11
12
|
"files": [
|