3 lines
18 KiB
JavaScript
3 lines
18 KiB
JavaScript
import{u as st,B as J}from"./main-0n0W_4XT.js";import"./pwa-viewport-CJ-1bFP1.js";import"./ScheduledAtField-C2dSuh6f.js";import"./ICONS-DaAGffIM.js";const{best:F,bin:at,drawTemplate:ct,fillArr:Y,info:I,interleave:lt,validateVersion:tt,zigzag:ft}=st,X=3,ut=8,dt=24,ht=2,yt=1.333,et=2,xt=3,b=t=>t>>>0,_=(t,e)=>{const n=t.x-e.x,r=t.y-e.y;return n*n+r*r},N=(t,e)=>Math.sqrt(_(t,e)),B=t=>t.reduce((e,n)=>e+n),G=(t,e)=>{t.x+=e.x,t.y+=e.y},mt=t=>({x:-t.x,y:-t.y}),$=t=>({x:t.y,y:t.x}),V=t=>({x:t.x,y:t.y}),O=t=>({x:b(t.x),y:b(t.y)}),wt=(t,e)=>({x:t.x+e.x,y:t.y+e.y});function D(t,e,n){return Math.max(Math.min(t,n||t),e||t)}const nt=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 gt(t){const e=nt(t),n=new Uint8Array(t.height*t.width);for(let c=0,l=0,d=t.data;c<d.length;c+=e){const h=d[c],w=d[c+1],g=d[c+2];n[l++]=b((h+2*w+g)/4)&255}const r=ut;if(t.width<r*5||t.height<r*5)throw new Error("image too small");const o=Math.ceil(t.width/r),s=Math.ceil(t.height/r),a=t.height-r,i=t.width-r,f=new Uint8Array(o*s);for(let c=0;c<s;c++){const l=D(c*r,0,a);for(let d=0;d<o;d++){const h=D(d*r,0,i);let w=0,g=255,v=0;for(let m=0,S=l*t.width+h;m<r;m=m+1,S=S+t.width)for(let y=0;y<r;y++){const x=n[S+y];w+=x,g=Math.min(g,x),v=Math.max(v,x)}let p=Math.floor(w/r**2);if(v-g<=dt&&(p=g/2,c>0&&d>0)){const m=(y,x)=>x*o+y,S=(f[m(d,c-1)]+2*f[m(d-1,c)]+f[m(d-1,c-1)])/4;g<S&&(p=S)}f[o*c+d]=b(p)}}const u=new J({width:t.width,height:t.height});for(let c=0;c<s;c++){const l=D(c*r,0,a),d=D(c,2,s-3);for(let h=0;h<o;h++){const w=D(h*r,0,i),g=D(h,2,o-3);let v=0;for(let m=-2;m<=2;m++){const S=o*(d+m)+g;for(let y=-2;y<=2;y++)v+=f[S+y]}const p=v/25;for(let m=0,S=l*t.width+w;m<r;m+=1,S+=t.width)for(let y=0;y<r;y++)n[S+y]<=p&&(u.data[l+m][w+y]=!0)}}return u}function vt(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 pt(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 St=t=>t.filter(e=>e.count>=et);function ot(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((s,a)=>s+a),shift:(o,s)=>{for(let a=0;a<o.length-s;a++)o[a]=o[a+2];for(let a=o.length-s;a<o.length;a++)o[a]=0},checkSize(o,s,a=ht){const i=s/a;for(let f=0;f<o.length;f++)if(Math.abs(n[f]*s-o[f])>=n[f]*i)return!1;return!0},add(o,s,a,i){const f=i/k.totalSize,u={x:s,y:a,moduleSize:f,count:1};for(let c=0;c<o.length;c++){const l=o[c];if(vt(l,u))return o[c]=pt(l,u)}o.push(u)},toCenter(o,s){for(let a=t.length-1;a>r.center;a--)s-=o[a];return s-=o[r.center]/2,s},check(o,s,a,i,f){let u=0,c=V(a);const l=mt(i),d=(h,w)=>{for(;o.isInside(c)&&!!o.point(c)===r.pattern[h];G(c,w))s[h]++,u++;if(s[h]===0)return!0;const g=h===r.center;return!!(f&&!g&&s[h]>r.size[h]*f)};for(let h=r.center;h>=0;h--)if(d(h,l))return!1;c=V(a),G(c,i),u=1;for(let h=r.center;h<r.length;h++)if(d(h,i))return!1;return u},scanLine(o,s,a,i,f){const u=r.runs();let c=0,l=a;if(a)for(;l<i&&!!o.data[s][l]===r.pattern[0];)l++;for(;l<i;l++){if(!!o.data[s][l]===r.pattern[c]){if(u[c]++,l!==o.width-1)continue;l++}if(c!==r.length-1){u[++c]++;continue}const d=f(u,l);if(d)c=0,u.fill(0);else{if(d===!1)break;r.shift(u,2),c=r.length-2,u[c]++}}}};return r}const k=ot([!0,!1,!0,!1,!0],[1,1,3,1,1]),C=ot([!1,!0,!1]);function bt(t){let e=[];function n(y,x=2){const A=B(y);if(A<k.totalSize)return!1;const E=A/k.totalSize;return k.checkSize(y,E,x)}function r(y,x,A,E){const z=k.runs();let M=k.check(t,z,y,E,x);if(M===!1)return!1;const R=B(z);return 5*Math.abs(R-A)>=2*A?!1:n(z)?k.toCenter(z,M):!1}function o(y,x,A){if(!n(y))return!1;const E=B(y);let z=k.toCenter(y,A),M=r({x:b(z),y:x},y[2],E,{y:1,x:0});if(M===!1)return!1;M+=x;let R=r({x:b(z),y:b(M)},y[2],E,{y:0,x:1});if(R===!1)return!1;z=R+b(z);const T=k.runs();return!k.check(t,T,{x:b(z),y:b(M)},{x:1,y:1})||!n(T,yt)?!1:(k.add(e,z,M,E),!0)}let s=!1,a=D(b(3*t.height/388),xt),i=!1;for(let y=a-1;y<t.height&&!i;y+=a)k.scanLine(t,y,0,t.width,(x,A)=>{if(o(x,y,A)){if(a=2,s){let E=0,z=0;for(const T of e)T.count<et||(E++,z+=T.moduleSize);if(E<3)return;const M=z/e.length;let R=0;for(const T of e)R+=Math.abs(T.moduleSize-M);if(R<=.05*z)return i=!0,!1}else if(e.length>1){const E=St(e);if(E.length<2)return!0;s=!0;const z=b((Math.abs(E[0].x-E[1].x)-Math.abs(E[0].y-E[1].y))/2);return z<=x[2]+a?!0:(y+=z-x[2]-a,!1)}}});const f=e.length;if(f<3)throw new Error(`Finder: len(found) = ${f}`);e.sort((y,x)=>y.moduleSize-x.moduleSize);const u=F();for(let y=0;y<f-2;y++){const x=e[y];for(let A=y+1;A<f-1;A++){const E=e[A],z=_(x,E);for(let M=A+1;M<f;M++){const R=e[M];if(R.moduleSize>x.moduleSize*1.4)continue;const T=[z,_(E,R),_(x,R)].sort((rt,it)=>rt-it),L=T[0],Q=T[1],j=T[2];u.add(Math.abs(j-2*Q)+Math.abs(j-2*L),[x,E,R])}}}const c=u.get();if(!c)throw new Error("cannot find finder");const l=c[0],d=c[1],h=c[2],w=N(l,d),g=N(d,h),v=N(l,h);let p=h,m=l,S=d;if(g>=w&&g>=v?(p=l,m=d,S=h):v>=g&&v>=w&&(p=d,m=l,S=h),(S.x-p.x)*(m.y-p.y)-(S.y-p.y)*(m.x-p.x)<0){let y=m;m=S,S=y}return{bl:m,tl:p,tr:S}}function zt(t,e,n){const{moduleSize:r}=e,o=b(n*r),s=D(e.x-o,0),a=D(e.x+o,void 0,t.width-1),i=a-s,f=D(e.y-o,0),u=D(e.y+o,void 0,t.height-1),c=u-f;if(i<r*3||c<r*3)throw new Error(`x = ${i}, y=${c} moduleSize = ${r}`);const l=s,d=f,h=a-s,w=u-f,g=[],v=l+h,p=b(d+w/2);for(let m=0;m<w;m++){const S=b((m+1)/2),y=p+(m&1?-S:S);let x;if(C.scanLine(t,y,l,v,(A,E)=>{if(!C.checkSize(A,r))return;const z=B(A),M=C.toCenter(A,E),R=C.runs();let T=C.check(t,R,{x:b(M),y},{y:1,x:0},2*A[1]);if(T===!1)return;T+=y;const L=B(R);if(5*Math.abs(L-z)>=2*z||!C.checkSize(R,r))return;const Q=C.toCenter(R,T);if(x=C.add(g,M,Q,z),x)return!1}),x)return x}if(g.length>0)return g[0];throw new Error("Alignment pattern not found")}function W(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=$(e),n=$(n),o=$(o));let s=-o.x/2,a={x:e.x>=n.x?-1:1,y:e.y>=n.y?-1:1},i=0,f=n.x+a.x;for(let u=e.x,c=e.y;u!==f;u+=a.x){let l={x:u,y:c};if(r&&(l=$(l)),i===1==!!t.point(l)){if(i===2)return N({x:u,y:c},e);i++}if(s+=o.y,!(s<=0)){if(c===n.y)break;c+=a.y,s-=o.x}}return i===2?N({x:n.x+a.x,y:n.y},e):NaN}function H(t,e,n){let r=W(t,e,n),o=1;const{x:s,y:a}=e;let i=s-(n.x-s);const f=t.width;i<0?(o=s/(s-i),i=0):i>=f&&(o=(f-1-s)/(i-s),i=f-1);let u=b(a-(n.y-a)*o),c=1;const l=t.height;return u<0?(c=a/(a-u),u=0):u>=l&&(c=(l-1-a)/(u-a),u=l-1),i=b(s+(i-s)*c),r+=W(t,e,{x:i,y:u}),r-1}function K(t,e,n){const r=H(t,O(e),O(n)),o=H(t,O(n),O(e));return Number.isNaN(r)?o/k.totalSize:Number.isNaN(o)?r/k.totalSize:(r+o)/(2*k.totalSize)}function At(t){const{bl:e,tl:n,tr:r}=bt(t),o=(K(t,n,r)+K(t,n,e))/2;if(o<1)throw new Error(`invalid moduleSize = ${o}`);const s=b(N(n,r)/o+.5),a=b(N(n,e)/o+.5);let i=b((s+a)/2+7);const f=i%4;f===0?i++:f===2?i--:f===3&&(i-=2);const u=I.size.decode(i);tt(u);let c;if(I.alignmentPatterns(u).length>0){const m={x:r.x-n.x+e.x,y:r.y-n.y+e.y},S=1-3/(I.size.encode(u)-7),y={x:b(n.x+S*(m.x-n.x)),y:b(n.y+S*(m.y-n.y)),moduleSize:o,count:1};for(let x=4;x<=16;x<<=1)try{c=zt(t,y,x);break}catch{}}const l={x:3.5,y:3.5},d={x:i-3.5,y:3.5},h={x:3.5,y:i-3.5};let w,g;c?(w=c,g={x:i-6.5,y:i-6.5}):(w={x:r.x-n.x+e.x,y:r.y-n.y+e.y},g={x:i-3.5,y:i-3.5});const v=[n,r,w,e];return{bits:Et(t,i,v,[l,d,g,h]),points:v}}function Z(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,s=(e.x*r.y-r.x*e.y)/o,a=(n.x*e.y-e.x*n.y)/o;return[[t[1].x-t[0].x+s*t[1].x,t[3].x-t[0].x+a*t[3].x,t[0].x],[t[1].y-t[0].y+s*t[1].y,t[3].y-t[0].y+a*t[3].y,t[0].y],[s,a,1]]}}function Et(t,e,n,r){const o=Z(r),s=[[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=Z(n).map(l=>l.map((d,h)=>l.reduce((w,g,v)=>w+g*s[v][h],0))),f=new J(e),u=Y(2*e,0),c=u.length;for(let l=0;l<e;l++){const d=i;for(let h=0;h<c-1;h+=2){const w=h/2+.5,g=l+.5,v=d[2][0]*w+d[2][1]*g+d[2][2];u[h]=b((d[0][0]*w+d[0][1]*g+d[0][2])/v),u[h+1]=b((d[1][0]*w+d[1][1]*g+d[1][2])/v)}for(let h=0;h<c;h+=2){const w=D(u[h],0,t.width-1),g=D(u[h+1],0,t.height-1);t.data[g][w]&&(f.data[l][h/2]=!0)}}return f}function Mt(t){const e=(i,f,u)=>u<<1|(t.data[f][i]?1:0),n=t.height;let r=0;for(let i=5;i>=0;i--)for(let f=n-9;f>=n-11;f--)r=e(f,i,r);let o=0;for(let i=5;i>=0;i--)for(let f=n-9;f>=n-11;f--)o=e(i,f,o);let s=0;for(let i=0;i<6;i++)s=e(i,8,s);s=e(7,8,s),s=e(8,8,s),s=e(8,7,s);for(let i=5;i>=0;i--)s=e(8,i,s);let a=0;for(let i=n-1;i>=n-7;i--)a=e(8,i,a);for(let i=n-8;i<n;i++)a=e(i,8,a);return{version1:r,version2:o,format1:s,format2:a}}function Rt(t){const e=c=>{let l=0;for(;c;)c&1&&l++,c>>=1;return l},n=t.height,{version1:r,version2:o,format1:s,format2:a}=Mt(t);let i;const f=F();for(const c of["medium","low","high","quartile"])for(let l=0;l<8;l++){const d=I.formatBits(c,l),h={ecc:c,mask:l};if(d===s||d===a){i=h;break}f.add(e(s^d),h),s!==a&&f.add(e(a^d),h)}if(i===void 0&&f.score()<=X&&(i=f.get()),i===void 0)throw new Error("invalid format pattern");let u=I.size.decode(n);if(u<7)tt(u);else{u=void 0;const c=F();for(let l=7;l<=40;l++){const d=I.versionBits(l);if(d===r||d===o){u=l;break}c.add(e(r^d),l),r!==o&&c.add(e(o^d),l)}if(u===void 0&&c.score()<=X&&(u=c.get()),u===void 0)throw new Error("invalid version pattern");if(I.size.encode(u)!==n)throw new Error("invalid version size")}return{version:u,...i}}function Tt(t){return new TextDecoder().decode(new Uint8Array(t))}function kt(t,e=Tt){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:s}=Rt(t),a=ct(r,s,o),{total:i}=I.capacity(r,s),f=new Uint8Array(i);let u=0,c=0,l=0;if(ft(a,o,(p,m,S)=>{l++,c<<=1,c|=+(!!t.data[m][p]!==S),l===8&&(f[u++]=c,l=0,c=0)}),u!==i)throw new Error(`decode: pos=${u}, total=${i}`);let d=Array.from(lt(r,s).decode(f)).map(p=>at(p,8)).join("");const h=p=>{if(p>d.length)throw new Error("Not enough bits");const m=d.slice(0,p);return d=d.slice(p),m},w=p=>+`0b${p}`,g={"0000":"terminator","0001":"numeric","0010":"alphanumeric","0100":"byte","0111":"eci",1e3:"kanji"};let v="";for(;!(d.length<4);){const p=h(4),m=g[p];if(m===void 0)throw new Error(`Unknown modeBits=${p} res="${v}"`);if(m==="terminator")break;const S=I.lengthBits(r,m);let y=w(h(S));if(m==="numeric"){for(;y>=3;){const x=w(h(10));if(x>=1e3)throw new Error(`numberic(3) = ${x}`);v+=x.toString().padStart(3,"0"),y-=3}if(y===2){const x=w(h(7));if(x>=100)throw new Error(`numeric(2) = ${x}`);v+=x.toString().padStart(2,"0")}else if(y===1){const x=w(h(4));if(x>=10)throw new Error(`Numeric(1) = ${x}`);v+=x.toString()}}else if(m==="alphanumeric"){for(;y>=2;){const x=w(h(11));v+=I.alphabet.alphanumerc.encode([Math.floor(x/45),x%45]).join(""),y-=2}y===1&&(v+=I.alphabet.alphanumerc.encode([w(h(6))]).join(""))}else if(m==="byte"){let x=[];for(let A=0;A<y;A++)x.push(+`0b${h(8)}`);v+=e(new Uint8Array(x))}else throw new Error(`Unknown mode=${m}`)}return v}function Dt(t){const e=Array.isArray(t.data)?new Uint8Array(t.data):t.data,{height:n,width:r}=t,o=Math.min(n,r),s={x:Math.floor((r-o)/2),y:Math.floor((n-o)/2)},a=nt(t),i=new Uint8Array(o*o*a);for(let f=0;f<o;f++){const u=((f+s.y)*r+s.x)*a,c=f*o*a,l=o*a;i.set(e.subarray(u,u+l),c)}return{offset:s,img:{height:o,width:o,data:i}}}function It(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}=Dt(t));const r=gt(t);e.imageOnBitmap&&e.imageOnBitmap(r.toImage());const{bits:o,points:s}=At(r);if(e.pointsOnDetect){const i=s.map(f=>({...f,...wt(f,n)}));e.pointsOnDetect(i)}e.imageOnDetect&&e.imageOnDetect(o.toImage());const a=kt(o,e.textDecoder);return e.imageOnResult&&e.imageOnResult(o.toImage()),a}const Ct=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}},P=(t,e,n)=>{t.height!==e&&(t.height=e),t.width!==n&&(t.width=n)},q=t=>{const e=t.getContext("2d");if(e===null)throw new Error("Cannot get canvas context");return{canvas:t,context:e}},U=({canvas:t,context:e})=>{e.clearRect(0,0,t.width,t.height)};class qt{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=q(document.createElement("canvas")),e&&(this.overlay=q(e)),n&&(this.bitmap=q(n)),r&&(this.resultQR=q(r),this.resultQR.context.imageSmoothingEnabled=!1)}setSize(e,n){P(this.main.canvas,e,n),this.overlay&&P(this.overlay.canvas,e,n),this.bitmap&&P(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 s={x:0,y:0};this.opts.cropToSquare&&(s={x:Math.ceil((this.bitmap.canvas.width-r)/2),y:Math.ceil((this.bitmap.canvas.height-n)/2)}),this.bitmap.context.putImageData(o,s.x,s.y)}drawResultQr({data:e,height:n,width:r}){if(!this.resultQR)return;const o=this.opts.resultBlockSize;P(this.resultQR.canvas,n,r);const s=new ImageData(Uint8ClampedArray.from(e),r,n);this.resultQR.context.putImageData(s,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 s=Math.min(r,o),a={x:Math.floor((o-s)/2),y:Math.floor((r-s)/2)};n.clearRect(a.x,a.y,s,s),n.fillStyle=this.opts.overlaySideColor,o>r?(n.fillRect(0,0,a.x,r),n.fillRect(o-a.x,0,a.x,r)):r>o&&(n.fillRect(0,0,o,a.y),n.fillRect(0,r-a.y,o,a.y))}else n.clearRect(0,0,o,r);if(e){const[s,a,i,f]=e;n.fillStyle=this.opts.overlayMainColor,n.beginPath(),n.moveTo(s.x,s.y),n.lineTo(a.x,a.y),n.lineTo(i.x,i.y),n.lineTo(f.x,f.y),n.fill(),n.closePath(),n.fillStyle=this.opts.overlayFinderColor;for(const u of e){if(!("moduleSize"in u))continue;const c=u.x-3*u.moduleSize,l=u.y-3*u.moduleSize,d=7*u.moduleSize;n.fillRect(c,l,d,d)}}}drawImage(e,n,r){this.setSize(n,r);const{context:o}=this.main;o.drawImage(e,0,0,r,n);const s=o.getImageData(0,0,r,n),a={cropToSquare:this.opts.cropToSquare,textDecoder:this.opts.textDecoder};this.bitmap&&(a.imageOnBitmap=i=>this.drawBitmap(i)),this.overlay&&(a.pointsOnDetect=i=>this.drawOverlay(i)),this.resultQR&&(a.imageOnResult=i=>this.drawResultQr(i));try{const i=It(s,a);return this.lastDetect=Date.now(),i}catch{this.overlay&&Date.now()-this.lastDetect>this.opts.overlayTimeout&&this.drawOverlay()}}clear(){U(this.main),this.overlay&&U(this.overlay),this.bitmap&&U(this.bitmap),this.resultQR&&U(this.resultQR)}}class Nt{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=Ct(r);return e.drawImage(r,o.height,o.width)}stop(){for(const e of this.stream.getTracks())e.stop()}}async function Ut(t){const e=await navigator.mediaDevices.getUserMedia({video:{height:{ideal:window.screen.height},width:{ideal:window.screen.width},facingMode:"environment"}});return new Nt(e,t)}function _t(t){let e;function n(r){t(r),e=requestAnimationFrame(n)}return e=requestAnimationFrame(n),()=>{e!==void 0&&(cancelAnimationFrame(e),e=void 0)}}function Lt(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 a=new DOMParser().parseFromString(t,"image/svg+xml"),i=a.documentElement;i.setAttribute("width",String(e)),i.setAttribute("height",String(n));const f=a.createElementNS("http://www.w3.org/2000/svg","rect");f.setAttribute("width","100%"),f.setAttribute("height","100%"),f.setAttribute("fill","white"),i.insertBefore(f,i.firstChild);const c=new XMLSerializer().serializeToString(a),l=new Image;l.src="data:image/svg+xml,"+encodeURIComponent(c),l.onload=function(){const d=document.createElement("canvas");d.width=e,d.height=n;const h=d.getContext("2d");if(!h)return o(new Error("was not able to create 2d context"));h.drawImage(l,0,0,e,n);const w=d.toDataURL("image/png");r(w)},l.onerror=o})}export{qt as QRCanvas,_t as frameLoop,Ut as frontalCamera,Ct as getSize,Lt as svgToPng};
|
|
//# sourceMappingURL=dom-BT9_JKk_.js.map
|