3 lines
18 KiB
JavaScript
3 lines
18 KiB
JavaScript
import{u as ct,B as et}from"./main-BIy8J6P1.js";import"./pwa-viewport-7HQOd5MC.js";import"./ScheduledAtField-B9b7q7O5.js";import"./ICONS-C5h6VnP9.js";const{best:j,bin:lt,drawTemplate:ft,fillArr:Y,info:D,interleave:dt,validateVersion:nt,zigzag:ut,popcnt:$}=ct,G=3,ht=8,yt=24,xt=2,mt=1.333,ot=2,wt=3,z=t=>t>>>0,L=(t,e)=>{const n=t.x-e.x,r=t.y-e.y;return n*n+r*r},N=(t,e)=>Math.sqrt(L(t,e)),B=t=>t.reduce((e,n)=>e+n),V=(t,e)=>{t.x+=e.x,t.y+=e.y},gt=t=>({x:-t.x,y:-t.y}),O=t=>({x:t.y,y:t.x}),W=t=>({x:t.x,y:t.y}),P=t=>({x:z(t.x),y:z(t.y)}),vt=(t,e)=>({x:t.x+e.x,y:t.y+e.y});function I(t,e,n){return Math.max(Math.min(t,n||t),e||t)}const rt=t=>{const e=t.data.length/(t.width*t.height);if(e===3||e===4)return e;throw new Error(`Unknown image format, bytes per pixel=${e}`)};function pt(t){const e=rt(t),n=new Uint8Array(t.height*t.width);for(let c=0,d=0,h=t.data;c<h.length;c+=e){const u=h[c],g=h[c+1],p=h[c+2];n[d++]=z((u+2*g+p)/4)&255}const r=ht;if(t.width<r*5||t.height<r*5)throw new Error("image too small");const o=Math.ceil(t.width/r),a=Math.ceil(t.height/r),s=t.height-r,i=t.width-r,l=new Uint8Array(o*a);for(let c=0;c<a;c++){const d=I(c*r,0,s);for(let h=0;h<o;h++){const u=I(h*r,0,i);let g=0,p=255,S=0;for(let x=0,v=d*t.width+u;x<r;x=x+1,v=v+t.width)for(let y=0;y<r;y++){const w=n[v+y];g+=w,p=Math.min(p,w),S=Math.max(S,w)}let A=Math.floor(g/r**2);if(S-p<=yt&&(A=p/2,c>0&&h>0)){const x=(y,w)=>w*o+y,v=(l[x(h,c-1)]+2*l[x(h-1,c)]+l[x(h-1,c-1)])/4;p<v&&(A=v)}l[o*c+h]=z(A)}}const f=new et({width:t.width,height:t.height});for(let c=0;c<a;c++){const d=I(c*r,0,s),h=I(c,2,a-3);for(let u=0;u<o;u++){const g=I(u*r,0,i),p=I(u,2,o-3);let S=0;for(let x=-2;x<=2;x++){const v=o*(h+x)+p;for(let y=-2;y<=2;y++)S+=l[v+y]}const A=S/25;for(let x=0,v=d*t.width+g;x<r;x+=1,v+=t.width)for(let y=0;y<r;y++)n[v+y]<=A&&f.set(g+y,d+x,!0)}}return f}function St(t,e){if(Math.abs(e.y-t.y)<=e.moduleSize&&Math.abs(e.x-t.x)<=e.moduleSize){const n=Math.abs(e.moduleSize-t.moduleSize);return n<=1||n<=t.moduleSize}return!1}function bt(t,e){const n=t.count+e.count;return{x:(t.count*t.x+e.count*e.x)/n,y:(t.count*t.y+e.count*e.y)/n,moduleSize:(t.count*t.moduleSize+e.count*e.moduleSize)/n,count:n}}const zt=t=>t.filter(e=>e.count>=ot);function it(t,e){const n=e||Y(t.length,1);if(t.length!==n.length)throw new Error("invalid pattern");if(!(t.length&1))throw new Error("invalid pattern, length should be odd");const r={center:Math.ceil(t.length/2)-1,length:t.length,pattern:t,size:n,runs:()=>Y(t.length,0),totalSize:B(n),total:o=>o.reduce((a,s)=>a+s),shift:(o,a)=>{for(let s=0;s<o.length-a;s++)o[s]=o[s+2];for(let s=o.length-a;s<o.length;s++)o[s]=0},checkSize(o,a,s=xt){const i=a/s;for(let l=0;l<o.length;l++)if(Math.abs(n[l]*a-o[l])>=n[l]*i)return!1;return!0},add(o,a,s,i){const l=i/k.totalSize,f={x:a,y:s,moduleSize:l,count:1};for(let c=0;c<o.length;c++){const d=o[c];if(St(d,f))return o[c]=bt(d,f)}o.push(f)},toCenter(o,a){for(let s=t.length-1;s>r.center;s--)a-=o[s];return a-=o[r.center]/2,a},check(o,a,s,i,l){let f=0,c=W(s);const d=gt(i),h=(u,g)=>{for(;o.isInside(c)&&!!o.point(c)===r.pattern[u];V(c,g))a[u]++,f++;if(a[u]===0)return!0;const p=u===r.center;return!!(l&&!p&&a[u]>r.size[u]*l)};for(let u=r.center;u>=0;u--)if(h(u,d))return!1;c=W(s),V(c,i),f=1;for(let u=r.center;u<r.length;u++)if(h(u,i))return!1;return f},scanLine(o,a,s,i,l){const f=r.runs();let c=0,d=s;if(s)for(;d<i&&!!o.get(d,a)===r.pattern[0];)d++;for(;d<i;d++){if(!!o.get(d,a)===r.pattern[c]){if(f[c]++,d!==o.width-1)continue;d++}if(c!==r.length-1){f[++c]++;continue}const h=l(f,d);if(h)c=0,f.fill(0);else{if(h===!1)break;r.shift(f,2),c=r.length-2,f[c]++}}}};return r}const k=it([!0,!1,!0,!1,!0],[1,1,3,1,1]),C=it([!1,!0,!1]);function H(t){let e=[];function n(y,w=2){const m=B(y);if(m<k.totalSize)return!1;const b=m/k.totalSize;return k.checkSize(y,b,w)}function r(y,w,m,b){const E=k.runs();let M=k.check(t,E,y,b,w);if(M===!1)return!1;const R=B(E);return 5*Math.abs(R-m)>=2*m?!1:n(E)?k.toCenter(E,M):!1}function o(y,w,m){if(!n(y))return!1;const b=B(y);let E=k.toCenter(y,m),M=r({x:z(E),y:w},y[2],b,{y:1,x:0});if(M===!1)return!1;M+=w;let R=r({x:z(E),y:z(M)},y[2],b,{y:0,x:1});if(R===!1)return!1;E=R+z(E);const T=k.runs();return!k.check(t,T,{x:z(E),y:z(M)},{x:1,y:1})||!n(T,mt)?!1:(k.add(e,E,M,b),!0)}let a=!1,s=I(z(3*t.height/388),wt),i=!1;for(let y=s-1;y<t.height&&!i;y+=s)k.scanLine(t,y,0,t.width,(w,m)=>{if(o(w,y,m)){if(s=2,a){let b=0,E=0;for(const T of e)T.count<ot||(b++,E+=T.moduleSize);if(b<3)return;const M=E/e.length;let R=0;for(const T of e)R+=Math.abs(T.moduleSize-M);if(R<=.05*E)return i=!0,!1}else if(e.length>1){const b=zt(e);if(b.length<2)return!0;a=!0;const E=z((Math.abs(b[0].x-b[1].x)-Math.abs(b[0].y-b[1].y))/2);return E<=w[2]+s?!0:(y+=E-w[2]-s,!1)}}});const l=e.length;if(l<3)throw new Error(`Finder: len(found) = ${l}`);e.sort((y,w)=>y.moduleSize-w.moduleSize);const f=j();for(let y=0;y<l-2;y++){const w=e[y];for(let m=y+1;m<l-1;m++){const b=e[m],E=L(w,b);for(let M=m+1;M<l;M++){const R=e[M];if(R.moduleSize>w.moduleSize*1.4)continue;const T=[E,L(b,R),L(w,R)].sort((st,at)=>st-at),Q=T[0],F=T[1],X=T[2];f.add(Math.abs(X-2*F)+Math.abs(X-2*Q),[w,b,R])}}}const c=f.get();if(!c)throw new Error("cannot find finder");const d=c[0],h=c[1],u=c[2],g=N(d,h),p=N(h,u),S=N(d,u);let A=u,x=d,v=h;if(p>=g&&p>=S?(A=d,x=h,v=u):S>=p&&S>=g&&(A=h,x=d,v=u),(v.x-A.x)*(x.y-A.y)-(v.y-A.y)*(x.x-A.x)<0){let y=x;x=v,v=y}return{bl:x,tl:A,tr:v}}function Et(t,e,n){const{moduleSize:r}=e,o=z(n*r),a=I(e.x-o,0),s=I(e.x+o,void 0,t.width-1),i=s-a,l=I(e.y-o,0),f=I(e.y+o,void 0,t.height-1),c=f-l;if(i<r*3||c<r*3)throw new Error(`x = ${i}, y=${c} moduleSize = ${r}`);const d=a,h=l,u=s-a,g=f-l,p=[],S=d+u,A=z(h+g/2);for(let x=0;x<g;x++){const v=z((x+1)/2),y=A+(x&1?-v:v);let w;if(C.scanLine(t,y,d,S,(m,b)=>{if(!C.checkSize(m,r))return;const E=B(m),M=C.toCenter(m,b),R=C.runs();let T=C.check(t,R,{x:z(M),y},{y:1,x:0},2*m[1]);if(T===!1)return;T+=y;const Q=B(R);if(5*Math.abs(Q-E)>=2*E||!C.checkSize(R,r))return;const F=C.toCenter(R,T);if(w=C.add(p,M,F,E),w)return!1}),w)return w}if(p.length>0)return p[0];throw new Error("Alignment pattern not found")}function K(t,e,n){let r=!1,o={x:Math.abs(n.x-e.x),y:Math.abs(n.y-e.y)};o.y>o.x&&(r=!0,e=O(e),n=O(n),o=O(o));let a=-o.x/2,s={x:e.x>=n.x?-1:1,y:e.y>=n.y?-1:1},i=0,l=n.x+s.x;for(let f=e.x,c=e.y;f!==l;f+=s.x){let d={x:f,y:c};if(r&&(d=O(d)),i===1==!!t.point(d)){if(i===2)return N({x:f,y:c},e);i++}if(a+=o.y,!(a<=0)){if(c===n.y)break;c+=s.y,a-=o.x}}return i===2?N({x:n.x+s.x,y:n.y},e):NaN}function Z(t,e,n){let r=K(t,e,n),o=1;const{x:a,y:s}=e;let i=a-(n.x-a);const l=t.width;i<0?(o=a/(a-i),i=0):i>=l&&(o=(l-1-a)/(i-a),i=l-1);let f=z(s-(n.y-s)*o),c=1;const d=t.height;return f<0?(c=s/(s-f),f=0):f>=d&&(c=(d-1-s)/(f-s),f=d-1),i=z(a+(i-a)*c),r+=K(t,e,{x:i,y:f}),r-1}function J(t,e,n){const r=Z(t,P(e),P(n)),o=Z(t,P(n),P(e));return Number.isNaN(r)?o/k.totalSize:Number.isNaN(o)?r/k.totalSize:(r+o)/(2*k.totalSize)}function At(t){let e,n,r;try{({bl:e,tl:n,tr:r}=H(t))}catch{try{t.negate(),{bl:e,tl:n,tr:r}=H(t)}catch(v){throw t.negate(),v}}const o=(J(t,n,r)+J(t,n,e))/2;if(o<1)throw new Error(`invalid moduleSize = ${o}`);const a=z(N(n,r)/o+.5),s=z(N(n,e)/o+.5);let i=z((a+s)/2+7);const l=i%4;l===0?i++:l===2?i--:l===3&&(i-=2);const f=D.size.decode(i);nt(f);let c;if(D.alignmentPatterns(f).length>0){const x={x:r.x-n.x+e.x,y:r.y-n.y+e.y},v=1-3/(D.size.encode(f)-7),y={x:z(n.x+v*(x.x-n.x)),y:z(n.y+v*(x.y-n.y)),moduleSize:o,count:1};for(let w=4;w<=16;w<<=1)try{c=Et(t,y,w);break}catch{}}const d={x:3.5,y:3.5},h={x:i-3.5,y:3.5},u={x:3.5,y:i-3.5};let g,p;c?(g=c,p={x:i-6.5,y:i-6.5}):(g={x:r.x-n.x+e.x,y:r.y-n.y+e.y},p={x:i-3.5,y:i-3.5});const S=[n,r,g,e];return{bits:Mt(t,i,S,[d,h,p,u]),points:S}}function tt(t){const e={x:t[0].x-t[1].x+t[2].x-t[3].x,y:t[0].y-t[1].y+t[2].y-t[3].y};if(e.x===0&&e.y===0)return[[t[1].x-t[0].x,t[2].x-t[1].x,t[0].x],[t[1].y-t[0].y,t[2].y-t[1].y,t[0].y],[0,0,1]];{const n={x:t[1].x-t[2].x,y:t[1].y-t[2].y},r={x:t[3].x-t[2].x,y:t[3].y-t[2].y},o=n.x*r.y-r.x*n.y,a=(e.x*r.y-r.x*e.y)/o,s=(n.x*e.y-e.x*n.y)/o;return[[t[1].x-t[0].x+a*t[1].x,t[3].x-t[0].x+s*t[3].x,t[0].x],[t[1].y-t[0].y+a*t[1].y,t[3].y-t[0].y+s*t[3].y,t[0].y],[a,s,1]]}}function Mt(t,e,n,r){const o=tt(r),a=[[o[1][1]*o[2][2]-o[2][1]*o[1][2],o[2][1]*o[0][2]-o[0][1]*o[2][2],o[0][1]*o[1][2]-o[1][1]*o[0][2]],[o[2][0]*o[1][2]-o[1][0]*o[2][2],o[0][0]*o[2][2]-o[2][0]*o[0][2],o[1][0]*o[0][2]-o[0][0]*o[1][2]],[o[1][0]*o[2][1]-o[2][0]*o[1][1],o[2][0]*o[0][1]-o[0][0]*o[2][1],o[0][0]*o[1][1]-o[1][0]*o[0][1]]],i=tt(n).map(d=>d.map((h,u)=>d.reduce((g,p,S)=>g+p*a[S][u],0))),l=new et(e),f=Y(2*e,0),c=f.length;for(let d=0;d<e;d++){const h=i;for(let u=0;u<c-1;u+=2){const g=u/2+.5,p=d+.5,S=h[2][0]*g+h[2][1]*p+h[2][2];f[u]=z((h[0][0]*g+h[0][1]*p+h[0][2])/S),f[u+1]=z((h[1][0]*g+h[1][1]*p+h[1][2])/S)}for(let u=0;u<c;u+=2){const g=I(f[u],0,t.width-1),p=I(f[u+1],0,t.height-1);t.get(g,p)&&l.set(u/2|0,d,!0)}}return l}function Rt(t){const e=(i,l,f)=>f<<1|(t.get(i,l)?1:0),n=t.height;let r=0;for(let i=5;i>=0;i--)for(let l=n-9;l>=n-11;l--)r=e(l,i,r);let o=0;for(let i=5;i>=0;i--)for(let l=n-9;l>=n-11;l--)o=e(i,l,o);let a=0;for(let i=0;i<6;i++)a=e(i,8,a);a=e(7,8,a),a=e(8,8,a),a=e(8,7,a);for(let i=5;i>=0;i--)a=e(8,i,a);let s=0;for(let i=n-1;i>=n-7;i--)s=e(8,i,s);for(let i=n-8;i<n;i++)s=e(i,8,s);return{version1:r,version2:o,format1:a,format2:s}}function Tt(t){const e=t.height,{version1:n,version2:r,format1:o,format2:a}=Rt(t);let s;const i=j();for(const f of["medium","low","high","quartile"])for(let c=0;c<8;c++){const d=D.formatBits(f,c),h={ecc:f,mask:c};if(d===o||d===a){s=h;break}i.add($(o^d),h),o!==a&&i.add($(a^d),h)}if(s===void 0&&i.score()<=G&&(s=i.get()),s===void 0)throw new Error("invalid format pattern");let l=D.size.decode(e);if(l<7)nt(l);else{l=void 0;const f=j();for(let c=7;c<=40;c++){const d=D.versionBits(c);if(d===n||d===r){l=c;break}f.add($(n^d),c),n!==r&&f.add($(r^d),c)}if(l===void 0&&f.score()<=G&&(l=f.get()),l===void 0)throw new Error("invalid version pattern");if(D.size.encode(l)!==e)throw new Error("invalid version size")}return{version:l,...s}}const kt={1:"iso-8859-1",2:"ibm437",3:"iso-8859-1",4:"iso-8859-2",5:"iso-8859-3",6:"iso-8859-4",7:"iso-8859-5",8:"iso-8859-6",9:"iso-8859-7",10:"iso-8859-8",11:"iso-8859-9",13:"iso-8859-11",15:"iso-8859-13",16:"iso-8859-14",17:"iso-8859-15",18:"iso-8859-16",20:"shift-jis",21:"windows-1250",22:"windows-1251",23:"windows-1252",24:"windows-1256",25:"utf-16be",26:"utf-8",28:"big5",29:"gbk",30:"euc-kr"};function It(t,e=26){const n=kt[e];if(!n)throw new Error(`Unsupported ECI: ${e}`);return new TextDecoder(n).decode(t)}function Dt(t,e=It){const n=t.height;if(n<21||(n&3)!==1||n!==t.width)throw new Error(`decode: invalid size=${n}`);const{version:r,mask:o,ecc:a}=Tt(t),s=ft(r,a,o),{total:i}=D.capacity(r,a),l=new Uint8Array(i);let f=0,c=0,d=0;if(ut(s,o,(x,v,y)=>{d++,c<<=1,c|=+(!!t.get(x,v)!==y),d===8&&(l[f++]=c,d=0,c=0)}),f!==i)throw new Error(`decode: pos=${f}, total=${i}`);let h=Array.from(dt(r,a).decode(l)).map(x=>lt(x,8)).join("");const u=x=>{if(x>h.length)throw new Error("Not enough bits");const v=h.slice(0,x);return h=h.slice(x),v},g=x=>+`0b${x}`,p={"0000":"terminator","0001":"numeric","0010":"alphanumeric","0100":"byte","0111":"eci",1e3:"kanji"};let S="",A=26;for(;!(h.length<4);){const x=u(4),v=p[x];if(v===void 0)throw new Error(`Unknown modeBits=${x} res="${S}"`);if(v==="terminator")break;const y=D.lengthBits(r,v);let w=g(u(y));if(v==="numeric"){for(;w>=3;){const m=g(u(10));if(m>=1e3)throw new Error(`numberic(3) = ${m}`);S+=m.toString().padStart(3,"0"),w-=3}if(w===2){const m=g(u(7));if(m>=100)throw new Error(`numeric(2) = ${m}`);S+=m.toString().padStart(2,"0")}else if(w===1){const m=g(u(4));if(m>=10)throw new Error(`Numeric(1) = ${m}`);S+=m.toString()}}else if(v==="alphanumeric"){for(;w>=2;){const m=g(u(11));S+=D.alphabet.alphanumerc.encode([Math.floor(m/45),m%45]).join(""),w-=2}w===1&&(S+=D.alphabet.alphanumerc.encode([g(u(6))]).join(""))}else if(v==="eci"){const m=g(u(8));(m&128)===0?A=m:(m&192)===128?A=(m&63)<<8|g(u(8)):A=(m&31)<<16|g(u(16));continue}else if(v==="byte"){const m=new Uint8Array(w);for(let b=0;b<w;b++)m[b]=g(u(8));S+=e(m,A)}else throw new Error(`Unknown mode=${v}`)}return S}function Ct(t){const e=Array.isArray(t.data)?new Uint8Array(t.data):t.data,{height:n,width:r}=t,o=Math.min(n,r),a={x:Math.floor((r-o)/2),y:Math.floor((n-o)/2)},s=rt(t),i=new Uint8Array(o*o*s);for(let l=0;l<o;l++){const f=((l+a.y)*r+a.x)*s,c=l*o*s,d=o*s;i.set(e.subarray(f,f+d),c)}return{offset:a,img:{height:o,width:o,data:i}}}function Nt(t,e={}){for(const i of["height","width"])if(!Number.isSafeInteger(t[i])||t[i]<=0)throw new Error(`invalid img.${i}=${t[i]} (${typeof t[i]})`);if(!Array.isArray(t.data)&&!(t.data instanceof Uint8Array)&&!(t.data instanceof Uint8ClampedArray))throw new Error(`invalid image.data=${t.data} (${typeof t.data})`);if(e.cropToSquare!==void 0&&typeof e.cropToSquare!="boolean")throw new Error(`invalid opts.cropToSquare=${e.cropToSquare}`);for(const i of["pointsOnDetect","imageOnBitmap","imageOnDetect","imageOnResult"])if(e[i]!==void 0&&typeof e[i]!="function")throw new Error(`invalid opts.${i}=${e[i]} (${typeof e[i]})`);let n={x:0,y:0};e.cropToSquare&&({img:t,offset:n}=Ct(t));const r=pt(t);e.imageOnBitmap&&e.imageOnBitmap(r.toImage());const{bits:o,points:a}=At(r);if(e.pointsOnDetect){const i=a.map(l=>({...l,...vt(l,n)}));e.pointsOnDetect(i)}e.imageOnDetect&&e.imageOnDetect(o.toImage());const s=Dt(o,e.textDecoder);return e.imageOnResult&&e.imageOnResult(o.toImage()),s}const Bt=t=>{const e=getComputedStyle(t),n=Math.floor(+e.width.split("px")[0]),r=Math.floor(+e.height.split("px")[0]);return{width:n,height:r}},q=(t,e,n)=>{t.height!==e&&(t.height=e),t.width!==n&&(t.width=n)},U=t=>{const e=t.getContext("2d");if(e===null)throw new Error("Cannot get canvas context");return{canvas:t,context:e}},_=({canvas:t,context:e})=>{e.clearRect(0,0,t.width,t.height)};class _t{opts;lastDetect=0;main;overlay;bitmap;resultQR;constructor({overlay:e,bitmap:n,resultQR:r}={},o={}){this.opts={resultBlockSize:8,overlayMainColor:"green",overlayFinderColor:"blue",overlaySideColor:"black",overlayTimeout:500,cropToSquare:!0,...o},this.main=U(document.createElement("canvas")),e&&(this.overlay=U(e)),n&&(this.bitmap=U(n)),r&&(this.resultQR=U(r),this.resultQR.context.imageSmoothingEnabled=!1)}setSize(e,n){q(this.main.canvas,e,n),this.overlay&&q(this.overlay.canvas,e,n),this.bitmap&&q(this.bitmap.canvas,e,n)}drawBitmap({data:e,height:n,width:r}){if(!this.bitmap)return;const o=new ImageData(Uint8ClampedArray.from(e),r,n);let a={x:0,y:0};this.opts.cropToSquare&&(a={x:Math.ceil((this.bitmap.canvas.width-r)/2),y:Math.ceil((this.bitmap.canvas.height-n)/2)}),this.bitmap.context.putImageData(o,a.x,a.y)}drawResultQr({data:e,height:n,width:r}){if(!this.resultQR)return;const o=this.opts.resultBlockSize;q(this.resultQR.canvas,n,r);const a=new ImageData(Uint8ClampedArray.from(e),r,n);this.resultQR.context.putImageData(a,0,0),this.resultQR.canvas.style=`image-rendering: pixelated; width: ${o*r}px; height: ${o*n}px`}drawOverlay(e){if(!this.overlay)return;const n=this.overlay.context,r=this.overlay.canvas.height,o=this.overlay.canvas.width;if(this.opts.cropToSquare&&r!==o){const a=Math.min(r,o),s={x:Math.floor((o-a)/2),y:Math.floor((r-a)/2)};n.clearRect(s.x,s.y,a,a),n.fillStyle=this.opts.overlaySideColor,o>r?(n.fillRect(0,0,s.x,r),n.fillRect(o-s.x,0,s.x,r)):r>o&&(n.fillRect(0,0,o,s.y),n.fillRect(0,r-s.y,o,s.y))}else n.clearRect(0,0,o,r);if(e){const[a,s,i,l]=e;n.fillStyle=this.opts.overlayMainColor,n.beginPath(),n.moveTo(a.x,a.y),n.lineTo(s.x,s.y),n.lineTo(i.x,i.y),n.lineTo(l.x,l.y),n.fill(),n.closePath(),n.fillStyle=this.opts.overlayFinderColor;for(const f of e){if(!("moduleSize"in f))continue;const c=f.x-3*f.moduleSize,d=f.y-3*f.moduleSize,h=7*f.moduleSize;n.fillRect(c,d,h,h)}}}drawImage(e,n,r){this.setSize(n,r);const{context:o}=this.main;o.drawImage(e,0,0,r,n);const a=o.getImageData(0,0,r,n),s={cropToSquare:this.opts.cropToSquare,textDecoder:this.opts.textDecoder};this.bitmap&&(s.imageOnBitmap=i=>this.drawBitmap(i)),this.overlay&&(s.pointsOnDetect=i=>this.drawOverlay(i)),this.resultQR&&(s.imageOnResult=i=>this.drawResultQr(i));try{const i=Nt(a,s);return this.lastDetect=Date.now(),i}catch{this.overlay&&Date.now()-this.lastDetect>this.opts.overlayTimeout&&this.drawOverlay()}}clear(){_(this.main),this.overlay&&_(this.overlay),this.bitmap&&_(this.bitmap),this.resultQR&&_(this.resultQR)}}class $t{stream;player;constructor(e,n){this.stream=e,this.player=n,this.setStream(e)}setStream(e){this.stream=e;const{player:n}=this;n.setAttribute("autoplay",""),n.setAttribute("muted",""),n.setAttribute("playsinline",""),n.srcObject=e}async listDevices(){if(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)throw new Error("Media Devices not supported");return(await navigator.mediaDevices.enumerateDevices()).filter(n=>n.kind==="videoinput").map(n=>({deviceId:n.deviceId,label:n.label||`Camera ${n.deviceId}`}))}async setDevice(e){this.stop();const n=await navigator.mediaDevices.getUserMedia({video:{deviceId:{exact:e}}});this.setStream(n)}readFrame(e,n=!1){const{player:r}=this;if(n)return e.drawImage(r,r.videoHeight,r.videoWidth);const o=Bt(r);return e.drawImage(r,o.height,o.width)}stop(){for(const e of this.stream.getTracks())e.stop()}}async function Lt(t){const e=await navigator.mediaDevices.getUserMedia({video:{height:{ideal:window.screen.height},width:{ideal:window.screen.width},facingMode:"environment"}});return new $t(e,t)}function Qt(t){let e;function n(r){t(r),e=requestAnimationFrame(n)}return e=requestAnimationFrame(n),()=>{e!==void 0&&(cancelAnimationFrame(e),e=void 0)}}function Ft(t,e,n){return new Promise((r,o)=>{if(!(Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&e>0&&n>0&&e<8192&&n<8192))return o(new Error("invalid width and height: "+e+" "+n));const s=new DOMParser().parseFromString(t,"image/svg+xml"),i=s.documentElement;i.setAttribute("width",String(e)),i.setAttribute("height",String(n));const l=s.createElementNS("http://www.w3.org/2000/svg","rect");l.setAttribute("width","100%"),l.setAttribute("height","100%"),l.setAttribute("fill","white"),i.insertBefore(l,i.firstChild);const c=new XMLSerializer().serializeToString(s),d=new Image;d.src="data:image/svg+xml,"+encodeURIComponent(c),d.onload=function(){const h=document.createElement("canvas");h.width=e,h.height=n;const u=h.getContext("2d");if(!u)return o(new Error("was not able to create 2d context"));u.drawImage(d,0,0,e,n);const g=h.toDataURL("image/png");r(g)},d.onerror=o})}export{_t as QRCanvas,Qt as frameLoop,Lt as frontalCamera,Bt as getSize,Ft as svgToPng};
|
|
//# sourceMappingURL=dom-BGTnaPi8.js.map
|