@linkshell/gateway 0.6.36 → 0.6.38
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/gateway/src/relay.d.ts +2 -0
- package/dist/gateway/src/relay.js +13 -0
- package/dist/gateway/src/relay.js.map +1 -1
- package/dist/gateway/tsconfig.tsbuildinfo +1 -1
- package/dist/wire/src/model.d.ts +4 -0
- package/dist/wire/src/model.js +2 -0
- package/dist/wire/src/model.js.map +1 -1
- package/dist/wire/src/relay-client.d.ts +2 -0
- package/dist/wire/src/relay-client.js +1 -0
- package/dist/wire/src/relay-client.js.map +1 -1
- package/dist/wire/src/relay.d.ts +8 -0
- package/dist/wire/src/relay.js +4 -0
- package/dist/wire/src/relay.js.map +1 -1
- package/dist/wire/src/rpc.d.ts +59 -1
- package/dist/wire/src/rpc.js +19 -0
- package/dist/wire/src/rpc.js.map +1 -1
- package/package.json +2 -2
- package/src/relay.ts +9 -0
- package/web-client/assets/{index-DucA84b9.css → index-Byw7jIME.css} +1 -1
- package/web-client/assets/{index-CpP6sHsL.js → index-CI0n455B.js} +2 -2
- package/web-client/assets/{qr-scanner.min-BeTv0k1C.js → qr-scanner.min-D-mj1Slb.js} +1 -1
- package/web-client/assets/render-DbAsu5wu.js +642 -0
- package/web-client/assets/render-thZKmerw.css +1 -0
- package/web-client/index.html +2 -2
- package/web-client/assets/render-1p4GgyhN.js +0 -629
- package/web-client/assets/render-Bb86geFz.css +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/render-
|
|
2
|
-
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const r of n)if(r.type==="childList")for(const i of r.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&s(i)}).observe(document,{childList:!0,subtree:!0});function o(n){const r={};return n.integrity&&(r.integrity=n.integrity),n.referrerPolicy&&(r.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?r.credentials="include":n.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function s(n){if(n.ep)return;n.ep=!0;const r=o(n);fetch(n.href,r)}})();const A="modulepreload",R=function(e){return"/"+e},L={},F=function(t,o,s){let n=Promise.resolve();if(o&&o.length>0){let i=function(a){return Promise.all(a.map(f=>Promise.resolve(f).then(m=>({status:"fulfilled",value:m}),m=>({status:"rejected",reason:m}))))};document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),_=c?.nonce||c?.getAttribute("nonce");n=i(o.map(a=>{if(a=R(a),a in L)return;L[a]=!0;const f=a.endsWith(".css"),m=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${a}"]${m}`))return;const l=document.createElement("link");if(l.rel=f?"stylesheet":A,f||(l.as="script"),l.crossOrigin="",l.href=a,_&&l.setAttribute("nonce",_),document.head.appendChild(l),f)return new Promise((N,I)=>{l.addEventListener("load",N),l.addEventListener("error",()=>I(new Error(`Unable to preload CSS for ${a}`)))})}))}function r(i){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=i,window.dispatchEvent(c),!c.defaultPrevented)throw i}return n.then(i=>{for(const c of i||[])c.status==="rejected"&&r(c.reason);return t().catch(r)})},S=typeof window<"u"&&window.__LINKSHELL_CONFIG__?.desktop===!0,K=S&&window.__LINKSHELL_CONFIG__?.desktopPlatform==="win32",M="desktop:local",V="linkshell-desktop-visibility",U="linkshell-desktop-account",q="linkshell-desktop-error";let g,u,h,k=Promise.resolve(),b;const p=new Map;let w={},d,y=0;function O(e){window.dispatchEvent(new CustomEvent(q,{detail:e instanceof Error?e.message:String(e)}))}async function E(e,t={}){if(!S||!g)throw new Error("桌面工作台尚未连接,请重新打开窗口");if(!/^\/desktop\/[a-z]+$/.test(e))throw new Error("无效的桌面请求");const o=new Headers(t.headers);o.set("Authorization",`Bearer ${g}`),t.body&&o.set("Content-Type","application/json");const s=await fetch(e,{...t,headers:o,credentials:"omit",cache:"no-store",redirect:"error",signal:t.signal??AbortSignal.timeout(15e3)}),n=await s.json();if(!s.ok)throw new Error(n.error||"桌面服务暂时不可用,请重试");return n}async function x(){if(!(!S||u))return h||(h=(async()=>{const e=new URLSearchParams(location.hash.slice(1)),t=e.get("desktop");g=t||sessionStorage.getItem("linkshell.desktop.capability")||void 0,t&&(sessionStorage.setItem("linkshell.desktop.capability",t),e.delete("desktop"),history.replaceState(null,"",location.pathname+location.search+(e.size?`#${e}`:""))),u=await E("/desktop/bootstrap"),document.documentElement.dataset.desktop="true",window.__LINKSHELL_DESKTOP_FLUSH__=$})().finally(()=>{h=void 0}),h)}function j(){if(!u)throw new Error("桌面设备身份尚未载入");return u.identity}function W(){return u?.localComputer}function B(e,t){return u?.storage[e]??t}function D(e,t){k=k.then(async()=>{try{await E("/desktop/storage",{method:"PUT",body:JSON.stringify({key:e,value:t.value})}),p.get(e)===t&&p.delete(e)}catch(o){O(new Error(`工作台设置尚未保存:${o instanceof Error?o.message:String(o)}。请重试连接。`))}})}function G(e,t){if(!u)throw new Error("桌面工作台尚未初始化");const o=t===void 0?null:JSON.parse(JSON.stringify(t));u.storage[e]=o;const s={value:o};p.set(e,s),D(e,s)}function H(){for(const[e,t]of p)D(e,t);return k}async function P(){let e;do e=k,await e;while(e!==k)}function $(){return b??=(async()=>(await P(),p.size&&await H(),await P(),{saved:p.size===0,pending:p.size}))().finally(()=>{b=void 0})}function T(e){const t=e.userId!==w.userId||e.email!==w.email||e.accessToken!==w.accessToken;return w=e,t&&window.dispatchEvent(new CustomEvent(U,{detail:e})),e}function z(){if(d)return d;const e=y,t=E("/desktop/account").then(o=>e===y?T(o):w).finally(()=>{d===t&&(d=void 0)});return d=t,t}async function J(){await E("/desktop/login",{method:"POST",signal:AbortSignal.timeout(36e4)}),y++,d=void 0,await z()}async function Y(){await E("/desktop/logout",{method:"POST"}),y++,d=void 0,T({})}function Q(){if(!g)throw new Error("桌面连接已失效,请重新打开窗口");const e=new URL("/desktop/host",location.origin);return e.protocol=location.protocol==="https:"?"wss:":"ws:",e.searchParams.set("token",g),new WebSocket(e)}function v(e){if(K){const o=window.chrome?.webview;return o?(o.postMessage(e),!0):!1}const t=window.webkit?.messageHandlers?.linkshellDesktop;return!S||!t?!1:(t.postMessage(e),!0)}function X(e){return v({action:"screenFullScreen",enabled:e})}const Z="linkshell-desktop-fullscreen";function ee(){v({action:"manage"})||O("请通过 LinkShell 菜单打开本机服务")}function te(e){v({action:"appearance",value:e})}function oe(e){v({action:"contentFocus",focused:e})}async function C(){try{await x(),await F(()=>import("./render-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/render-DbAsu5wu.js","assets/markdown-SZOrMO_3.js","assets/account-R7yD1rZE.js","assets/terminal-DWFexEE4.js","assets/terminal-DOrYoP_4.css","assets/render-thZKmerw.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const r of n)if(r.type==="childList")for(const i of r.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&s(i)}).observe(document,{childList:!0,subtree:!0});function o(n){const r={};return n.integrity&&(r.integrity=n.integrity),n.referrerPolicy&&(r.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?r.credentials="include":n.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function s(n){if(n.ep)return;n.ep=!0;const r=o(n);fetch(n.href,r)}})();const A="modulepreload",R=function(e){return"/"+e},L={},F=function(t,o,s){let n=Promise.resolve();if(o&&o.length>0){let i=function(a){return Promise.all(a.map(f=>Promise.resolve(f).then(m=>({status:"fulfilled",value:m}),m=>({status:"rejected",reason:m}))))};document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),_=c?.nonce||c?.getAttribute("nonce");n=i(o.map(a=>{if(a=R(a),a in L)return;L[a]=!0;const f=a.endsWith(".css"),m=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${a}"]${m}`))return;const l=document.createElement("link");if(l.rel=f?"stylesheet":A,f||(l.as="script"),l.crossOrigin="",l.href=a,_&&l.setAttribute("nonce",_),document.head.appendChild(l),f)return new Promise((N,I)=>{l.addEventListener("load",N),l.addEventListener("error",()=>I(new Error(`Unable to preload CSS for ${a}`)))})}))}function r(i){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=i,window.dispatchEvent(c),!c.defaultPrevented)throw i}return n.then(i=>{for(const c of i||[])c.status==="rejected"&&r(c.reason);return t().catch(r)})},S=typeof window<"u"&&window.__LINKSHELL_CONFIG__?.desktop===!0,K=S&&window.__LINKSHELL_CONFIG__?.desktopPlatform==="win32",M="desktop:local",V="linkshell-desktop-visibility",U="linkshell-desktop-account",q="linkshell-desktop-error";let g,u,h,k=Promise.resolve(),b;const p=new Map;let w={},d,y=0;function O(e){window.dispatchEvent(new CustomEvent(q,{detail:e instanceof Error?e.message:String(e)}))}async function E(e,t={}){if(!S||!g)throw new Error("桌面工作台尚未连接,请重新打开窗口");if(!/^\/desktop\/[a-z]+$/.test(e))throw new Error("无效的桌面请求");const o=new Headers(t.headers);o.set("Authorization",`Bearer ${g}`),t.body&&o.set("Content-Type","application/json");const s=await fetch(e,{...t,headers:o,credentials:"omit",cache:"no-store",redirect:"error",signal:t.signal??AbortSignal.timeout(15e3)}),n=await s.json();if(!s.ok)throw new Error(n.error||"桌面服务暂时不可用,请重试");return n}async function x(){if(!(!S||u))return h||(h=(async()=>{const e=new URLSearchParams(location.hash.slice(1)),t=e.get("desktop");g=t||sessionStorage.getItem("linkshell.desktop.capability")||void 0,t&&(sessionStorage.setItem("linkshell.desktop.capability",t),e.delete("desktop"),history.replaceState(null,"",location.pathname+location.search+(e.size?`#${e}`:""))),u=await E("/desktop/bootstrap"),document.documentElement.dataset.desktop="true",window.__LINKSHELL_DESKTOP_FLUSH__=$})().finally(()=>{h=void 0}),h)}function j(){if(!u)throw new Error("桌面设备身份尚未载入");return u.identity}function W(){return u?.localComputer}function B(e,t){return u?.storage[e]??t}function D(e,t){k=k.then(async()=>{try{await E("/desktop/storage",{method:"PUT",body:JSON.stringify({key:e,value:t.value})}),p.get(e)===t&&p.delete(e)}catch(o){O(new Error(`工作台设置尚未保存:${o instanceof Error?o.message:String(o)}。请重试连接。`))}})}function G(e,t){if(!u)throw new Error("桌面工作台尚未初始化");const o=t===void 0?null:JSON.parse(JSON.stringify(t));u.storage[e]=o;const s={value:o};p.set(e,s),D(e,s)}function H(){for(const[e,t]of p)D(e,t);return k}async function P(){let e;do e=k,await e;while(e!==k)}function $(){return b??=(async()=>(await P(),p.size&&await H(),await P(),{saved:p.size===0,pending:p.size}))().finally(()=>{b=void 0})}function T(e){const t=e.userId!==w.userId||e.email!==w.email||e.accessToken!==w.accessToken;return w=e,t&&window.dispatchEvent(new CustomEvent(U,{detail:e})),e}function z(){if(d)return d;const e=y,t=E("/desktop/account").then(o=>e===y?T(o):w).finally(()=>{d===t&&(d=void 0)});return d=t,t}async function J(){await E("/desktop/login",{method:"POST",signal:AbortSignal.timeout(36e4)}),y++,d=void 0,await z()}async function Y(){await E("/desktop/logout",{method:"POST"}),y++,d=void 0,T({})}function Q(){if(!g)throw new Error("桌面连接已失效,请重新打开窗口");const e=new URL("/desktop/host",location.origin);return e.protocol=location.protocol==="https:"?"wss:":"ws:",e.searchParams.set("token",g),new WebSocket(e)}function v(e){if(K){const o=window.chrome?.webview;return o?(o.postMessage(e),!0):!1}const t=window.webkit?.messageHandlers?.linkshellDesktop;return!S||!t?!1:(t.postMessage(e),!0)}function X(e){return v({action:"screenFullScreen",enabled:e})}const Z="linkshell-desktop-fullscreen";function ee(){v({action:"manage"})||O("请通过 LinkShell 菜单打开本机服务")}function te(e){v({action:"appearance",value:e})}function oe(e){v({action:"contentFocus",focused:e})}async function C(){try{await x(),await F(()=>import("./render-DbAsu5wu.js"),__vite__mapDeps([0,1,2,3,4,5]))}catch(e){const t=document.getElementById("root");t.replaceChildren();const o=document.createElement("main");o.style.cssText="max-width:440px;margin:18vh auto;padding:32px;font:15px system-ui;line-height:1.65";const s=document.createElement("h1");s.textContent="工作台暂时无法打开";const n=document.createElement("p");n.textContent=e instanceof Error?e.message:String(e);const r=document.createElement("button");r.textContent="重试",r.style.cssText="padding:8px 18px;border-radius:9px;cursor:pointer",r.onclick=()=>{r.disabled=!0,C()},o.append(s,n,r),t.append(o)}}C();export{q as D,F as _,j as a,U as b,V as c,z as d,W as e,M as f,E as g,K as h,S as i,Q as j,H as k,Y as l,J as m,X as n,ee as o,Z as p,oe as q,B as r,G as s,te as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as S}from"./index-CpP6sHsL.js";class s{constructor(e,t,i,a,n){this._legacyCanvasSize=s.DEFAULT_CANVAS_SIZE,this._preferredCamera="environment",this._maxScansPerSecond=25,this._lastScanTimestamp=-1,this._destroyed=this._flashOn=this._paused=this._active=!1,this.$video=e,this.$canvas=document.createElement("canvas"),i&&typeof i=="object"?this._onDecode=t:(console.warn(i||a||n?"You're using a deprecated version of the QrScanner constructor which will be removed in the future":"Note that the type of the scan result passed to onDecode will change in the future. To already switch to the new api today, you can pass returnDetailedScanResult: true."),this._legacyOnDecode=t),t=typeof i=="object"?i:{},this._onDecodeError=t.onDecodeError||(typeof i=="function"?i:this._onDecodeError),this._calculateScanRegion=t.calculateScanRegion||(typeof a=="function"?a:this._calculateScanRegion),this._preferredCamera=t.preferredCamera||n||this._preferredCamera,this._legacyCanvasSize=typeof i=="number"?i:typeof a=="number"?a:this._legacyCanvasSize,this._maxScansPerSecond=t.maxScansPerSecond||this._maxScansPerSecond,this._onPlay=this._onPlay.bind(this),this._onLoadedMetaData=this._onLoadedMetaData.bind(this),this._onVisibilityChange=this._onVisibilityChange.bind(this),this._updateOverlay=this._updateOverlay.bind(this),e.disablePictureInPicture=!0,e.playsInline=!0,e.muted=!0;let o=!1;if(e.hidden&&(e.hidden=!1,o=!0),document.body.contains(e)||(document.body.appendChild(e),o=!0),i=e.parentElement,t.highlightScanRegion||t.highlightCodeOutline){if(a=!!t.overlay,this.$overlay=t.overlay||document.createElement("div"),n=this.$overlay.style,n.position="absolute",n.display="none",n.pointerEvents="none",this.$overlay.classList.add("scan-region-highlight"),!a&&t.highlightScanRegion){this.$overlay.innerHTML='<svg class="scan-region-highlight-svg" viewBox="0 0 238 238" preserveAspectRatio="none" style="position:absolute;width:100%;height:100%;left:0;top:0;fill:none;stroke:#e9b213;stroke-width:4;stroke-linecap:round;stroke-linejoin:round"><path d="M31 2H10a8 8 0 0 0-8 8v21M207 2h21a8 8 0 0 1 8 8v21m0 176v21a8 8 0 0 1-8 8h-21m-176 0H10a8 8 0 0 1-8-8v-21"/></svg>';try{this.$overlay.firstElementChild.animate({transform:["scale(.98)","scale(1.01)"]},{duration:400,iterations:1/0,direction:"alternate",easing:"ease-in-out"})}catch{}i.insertBefore(this.$overlay,this.$video.nextSibling)}t.highlightCodeOutline&&(this.$overlay.insertAdjacentHTML("beforeend",'<svg class="code-outline-highlight" preserveAspectRatio="none" style="display:none;width:100%;height:100%;fill:none;stroke:#e9b213;stroke-width:5;stroke-dasharray:25;stroke-linecap:round;stroke-linejoin:round"><polygon/></svg>'),this.$codeOutlineHighlight=this.$overlay.lastElementChild)}this._scanRegion=this._calculateScanRegion(e),requestAnimationFrame(()=>{let d=window.getComputedStyle(e);d.display==="none"&&(e.style.setProperty("display","block","important"),o=!0),d.visibility!=="visible"&&(e.style.setProperty("visibility","visible","important"),o=!0),o&&(console.warn("QrScanner has overwritten the video hiding style to avoid Safari stopping the playback."),e.style.opacity="0",e.style.width="0",e.style.height="0",this.$overlay&&this.$overlay.parentElement&&this.$overlay.parentElement.removeChild(this.$overlay),delete this.$overlay,delete this.$codeOutlineHighlight),this.$overlay&&this._updateOverlay()}),e.addEventListener("play",this._onPlay),e.addEventListener("loadedmetadata",this._onLoadedMetaData),document.addEventListener("visibilitychange",this._onVisibilityChange),window.addEventListener("resize",this._updateOverlay),this._qrEnginePromise=s.createQrEngine()}static set WORKER_PATH(e){console.warn("Setting QrScanner.WORKER_PATH is not required and not supported anymore. Have a look at the README for new setup instructions.")}static async hasCamera(){try{return!!(await s.listCameras(!1)).length}catch{return!1}}static async listCameras(e=!1){if(!navigator.mediaDevices)return[];let t=async()=>(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind==="videoinput"),i;try{e&&(await t()).every(a=>!a.label)&&(i=await navigator.mediaDevices.getUserMedia({audio:!1,video:!0}))}catch{}try{return(await t()).map((a,n)=>({id:a.deviceId,label:a.label||(n===0?"Default Camera":`Camera ${n+1}`)}))}finally{i&&(console.warn("Call listCameras after successfully starting a QR scanner to avoid creating a temporary video stream"),s._stopVideoStream(i))}}async hasFlash(){let e;try{if(this.$video.srcObject){if(!(this.$video.srcObject instanceof MediaStream))return!1;e=this.$video.srcObject}else e=(await this._getCameraStream()).stream;return"torch"in e.getVideoTracks()[0].getSettings()}catch{return!1}finally{e&&e!==this.$video.srcObject&&(console.warn("Call hasFlash after successfully starting the scanner to avoid creating a temporary video stream"),s._stopVideoStream(e))}}isFlashOn(){return this._flashOn}async toggleFlash(){this._flashOn?await this.turnFlashOff():await this.turnFlashOn()}async turnFlashOn(){if(!this._flashOn&&!this._destroyed&&(this._flashOn=!0,this._active&&!this._paused))try{if(!await this.hasFlash())throw"No flash available";await this.$video.srcObject.getVideoTracks()[0].applyConstraints({advanced:[{torch:!0}]})}catch(e){throw this._flashOn=!1,e}}async turnFlashOff(){this._flashOn&&(this._flashOn=!1,await this._restartVideoStream())}destroy(){this.$video.removeEventListener("loadedmetadata",this._onLoadedMetaData),this.$video.removeEventListener("play",this._onPlay),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("resize",this._updateOverlay),this._destroyed=!0,this._flashOn=!1,this.stop(),s._postWorkerMessage(this._qrEnginePromise,"close")}async start(){if(this._destroyed)throw Error("The QR scanner can not be started as it had been destroyed.");if((!this._active||this._paused)&&(window.location.protocol!=="https:"&&console.warn("The camera stream is only accessible if the page is transferred via https."),this._active=!0,!document.hidden))if(this._paused=!1,this.$video.srcObject)await this.$video.play();else try{let{stream:e,facingMode:t}=await this._getCameraStream();!this._active||this._paused?s._stopVideoStream(e):(this._setVideoMirror(t),this.$video.srcObject=e,await this.$video.play(),this._flashOn&&(this._flashOn=!1,this.turnFlashOn().catch(()=>{})))}catch(e){if(!this._paused)throw this._active=!1,e}}stop(){this.pause(),this._active=!1}async pause(e=!1){if(this._paused=!0,!this._active)return!0;this.$video.pause(),this.$overlay&&(this.$overlay.style.display="none");let t=()=>{this.$video.srcObject instanceof MediaStream&&(s._stopVideoStream(this.$video.srcObject),this.$video.srcObject=null)};return e?(t(),!0):(await new Promise(i=>setTimeout(i,300)),this._paused?(t(),!0):!1)}async setCamera(e){e!==this._preferredCamera&&(this._preferredCamera=e,await this._restartVideoStream())}static async scanImage(e,t,i,a,n=!1,o=!1){let d,c=!1;t&&("scanRegion"in t||"qrEngine"in t||"canvas"in t||"disallowCanvasResizing"in t||"alsoTryWithoutScanRegion"in t||"returnDetailedScanResult"in t)?(d=t.scanRegion,i=t.qrEngine,a=t.canvas,n=t.disallowCanvasResizing||!1,o=t.alsoTryWithoutScanRegion||!1,c=!0):console.warn(t||i||a||n||o?"You're using a deprecated api for scanImage which will be removed in the future.":"Note that the return type of scanImage will change in the future. To already switch to the new api today, you can pass returnDetailedScanResult: true."),t=!!i;try{let m,h;[i,m]=await Promise.all([i||s.createQrEngine(),s._loadImage(e)]),[a,h]=s._drawToCanvas(m,d,a,n);let u;if(i instanceof Worker){let r=i;t||s._postWorkerMessageSync(r,"inversionMode","both"),u=await new Promise((l,f)=>{let p,y,g,w=-1;y=v=>{v.data.id===w&&(r.removeEventListener("message",y),r.removeEventListener("error",g),clearTimeout(p),v.data.data!==null?l({data:v.data.data,cornerPoints:s._convertPoints(v.data.cornerPoints,d)}):f(s.NO_QR_CODE_FOUND))},g=v=>{r.removeEventListener("message",y),r.removeEventListener("error",g),clearTimeout(p),f("Scanner error: "+(v?v.message||v:"Unknown Error"))},r.addEventListener("message",y),r.addEventListener("error",g),p=setTimeout(()=>g("timeout"),1e4);let _=h.getImageData(0,0,a.width,a.height);w=s._postWorkerMessageSync(r,"decode",_,[_.data.buffer])})}else u=await Promise.race([new Promise((r,l)=>window.setTimeout(()=>l("Scanner error: timeout"),1e4)),(async()=>{try{var[r]=await i.detect(a);if(!r)throw s.NO_QR_CODE_FOUND;return{data:r.rawValue,cornerPoints:s._convertPoints(r.cornerPoints,d)}}catch(l){if(r=l.message||l,/not implemented|service unavailable/.test(r))return s._disableBarcodeDetector=!0,s.scanImage(e,{scanRegion:d,canvas:a,disallowCanvasResizing:n,alsoTryWithoutScanRegion:o});throw`Scanner error: ${r}`}})()]);return c?u:u.data}catch(m){if(!d||!o)throw m;let h=await s.scanImage(e,{qrEngine:i,canvas:a,disallowCanvasResizing:n});return c?h:h.data}finally{t||s._postWorkerMessage(i,"close")}}setGrayscaleWeights(e,t,i,a=!0){s._postWorkerMessage(this._qrEnginePromise,"grayscaleWeights",{red:e,green:t,blue:i,useIntegerApproximation:a})}setInversionMode(e){s._postWorkerMessage(this._qrEnginePromise,"inversionMode",e)}static async createQrEngine(e){if(e&&console.warn("Specifying a worker path is not required and not supported anymore."),e=()=>S(()=>import("./qr-scanner-worker.min-D85Z9gVD.js"),[]).then(i=>i.createWorker()),!(!s._disableBarcodeDetector&&"BarcodeDetector"in window&&BarcodeDetector.getSupportedFormats&&(await BarcodeDetector.getSupportedFormats()).includes("qr_code")))return e();let t=navigator.userAgentData;return t&&t.brands.some(({brand:i})=>/Chromium/i.test(i))&&/mac ?OS/i.test(t.platform)&&await t.getHighEntropyValues(["architecture","platformVersion"]).then(({architecture:i,platformVersion:a})=>/arm/i.test(i||"arm")&&13<=parseInt(a||"13")).catch(()=>!0)?e():new BarcodeDetector({formats:["qr_code"]})}_onPlay(){this._scanRegion=this._calculateScanRegion(this.$video),this._updateOverlay(),this.$overlay&&(this.$overlay.style.display=""),this._scanFrame()}_onLoadedMetaData(){this._scanRegion=this._calculateScanRegion(this.$video),this._updateOverlay()}_onVisibilityChange(){document.hidden?this.pause():this._active&&this.start()}_calculateScanRegion(e){let t=Math.round(.6666666666666666*Math.min(e.videoWidth,e.videoHeight));return{x:Math.round((e.videoWidth-t)/2),y:Math.round((e.videoHeight-t)/2),width:t,height:t,downScaledWidth:this._legacyCanvasSize,downScaledHeight:this._legacyCanvasSize}}_updateOverlay(){requestAnimationFrame(()=>{if(this.$overlay){var e=this.$video,t=e.videoWidth,i=e.videoHeight,a=e.offsetWidth,n=e.offsetHeight,o=e.offsetLeft,d=e.offsetTop,c=window.getComputedStyle(e),m=c.objectFit,h=t/i,u=a/n;switch(m){case"none":var r=t,l=i;break;case"fill":r=a,l=n;break;default:(m==="cover"?h>u:h<u)?(l=n,r=l*h):(r=a,l=r/h),m==="scale-down"&&(r=Math.min(r,t),l=Math.min(l,i))}var[f,p]=c.objectPosition.split(" ").map((g,w)=>{const _=parseFloat(g);return g.endsWith("%")?(w?n-l:a-r)*_/100:_});c=this._scanRegion.width||t,u=this._scanRegion.height||i,m=this._scanRegion.x||0;var y=this._scanRegion.y||0;h=this.$overlay.style,h.width=`${c/t*r}px`,h.height=`${u/i*l}px`,h.top=`${d+p+y/i*l}px`,i=/scaleX\(-1\)/.test(e.style.transform),h.left=`${o+(i?a-f-r:f)+(i?t-m-c:m)/t*r}px`,h.transform=e.style.transform}})}static _convertPoints(e,t){if(!t)return e;let i=t.x||0,a=t.y||0,n=t.width&&t.downScaledWidth?t.width/t.downScaledWidth:1;t=t.height&&t.downScaledHeight?t.height/t.downScaledHeight:1;for(let o of e)o.x=o.x*n+i,o.y=o.y*t+a;return e}_scanFrame(){!this._active||this.$video.paused||this.$video.ended||("requestVideoFrameCallback"in this.$video?this.$video.requestVideoFrameCallback.bind(this.$video):requestAnimationFrame)(async()=>{if(!(1>=this.$video.readyState)){var e=Date.now()-this._lastScanTimestamp,t=1e3/this._maxScansPerSecond;e<t&&await new Promise(a=>setTimeout(a,t-e)),this._lastScanTimestamp=Date.now();try{var i=await s.scanImage(this.$video,{scanRegion:this._scanRegion,qrEngine:this._qrEnginePromise,canvas:this.$canvas})}catch(a){if(!this._active)return;this._onDecodeError(a)}!s._disableBarcodeDetector||await this._qrEnginePromise instanceof Worker||(this._qrEnginePromise=s.createQrEngine()),i?(this._onDecode?this._onDecode(i):this._legacyOnDecode&&this._legacyOnDecode(i.data),this.$codeOutlineHighlight&&(clearTimeout(this._codeOutlineHighlightRemovalTimeout),this._codeOutlineHighlightRemovalTimeout=void 0,this.$codeOutlineHighlight.setAttribute("viewBox",`${this._scanRegion.x||0} ${this._scanRegion.y||0} ${this._scanRegion.width||this.$video.videoWidth} ${this._scanRegion.height||this.$video.videoHeight}`),this.$codeOutlineHighlight.firstElementChild.setAttribute("points",i.cornerPoints.map(({x:a,y:n})=>`${a},${n}`).join(" ")),this.$codeOutlineHighlight.style.display="")):this.$codeOutlineHighlight&&!this._codeOutlineHighlightRemovalTimeout&&(this._codeOutlineHighlightRemovalTimeout=setTimeout(()=>this.$codeOutlineHighlight.style.display="none",100))}this._scanFrame()})}_onDecodeError(e){e!==s.NO_QR_CODE_FOUND&&console.log(e)}async _getCameraStream(){if(!navigator.mediaDevices)throw"Camera not found.";let e=/^(environment|user)$/.test(this._preferredCamera)?"facingMode":"deviceId",t=[{width:{min:1024}},{width:{min:768}},{}],i=t.map(a=>Object.assign({},a,{[e]:{exact:this._preferredCamera}}));for(let a of[...i,...t])try{let n=await navigator.mediaDevices.getUserMedia({video:a,audio:!1}),o=this._getFacingMode(n)||(a.facingMode?this._preferredCamera:this._preferredCamera==="environment"?"user":"environment");return{stream:n,facingMode:o}}catch{}throw"Camera not found."}async _restartVideoStream(){let e=this._paused;await this.pause(!0)&&!e&&this._active&&await this.start()}static _stopVideoStream(e){for(let t of e.getTracks())t.stop(),e.removeTrack(t)}_setVideoMirror(e){this.$video.style.transform="scaleX("+(e==="user"?-1:1)+")"}_getFacingMode(e){return(e=e.getVideoTracks()[0])?/rear|back|environment/i.test(e.label)?"environment":/front|user|face/i.test(e.label)?"user":null:null}static _drawToCanvas(e,t,i,a=!1){i=i||document.createElement("canvas");let n=t&&t.x?t.x:0,o=t&&t.y?t.y:0,d=t&&t.width?t.width:e.videoWidth||e.width,c=t&&t.height?t.height:e.videoHeight||e.height;return a||(a=t&&t.downScaledWidth?t.downScaledWidth:d,t=t&&t.downScaledHeight?t.downScaledHeight:c,i.width!==a&&(i.width=a),i.height!==t&&(i.height=t)),t=i.getContext("2d",{alpha:!1}),t.imageSmoothingEnabled=!1,t.drawImage(e,n,o,d,c,0,0,i.width,i.height),[i,t]}static async _loadImage(e){if(e instanceof Image)return await s._awaitImageLoad(e),e;if(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement||e instanceof SVGImageElement||"OffscreenCanvas"in window&&e instanceof OffscreenCanvas||"ImageBitmap"in window&&e instanceof ImageBitmap)return e;if(e instanceof File||e instanceof Blob||e instanceof URL||typeof e=="string"){let t=new Image;t.src=e instanceof File||e instanceof Blob?URL.createObjectURL(e):e.toString();try{return await s._awaitImageLoad(t),t}finally{(e instanceof File||e instanceof Blob)&&URL.revokeObjectURL(t.src)}}else throw"Unsupported image type."}static async _awaitImageLoad(e){e.complete&&e.naturalWidth!==0||await new Promise((t,i)=>{let a=n=>{e.removeEventListener("load",a),e.removeEventListener("error",a),n instanceof ErrorEvent?i("Image load error"):t()};e.addEventListener("load",a),e.addEventListener("error",a)})}static async _postWorkerMessage(e,t,i,a){return s._postWorkerMessageSync(await e,t,i,a)}static _postWorkerMessageSync(e,t,i,a){if(!(e instanceof Worker))return-1;let n=s._workerMessageId++;return e.postMessage({id:n,type:t,data:i},a),n}}s.DEFAULT_CANVAS_SIZE=400;s.NO_QR_CODE_FOUND="No QR code found";s._disableBarcodeDetector=!1;s._workerMessageId=0;export{s as default};
|
|
1
|
+
import{_ as S}from"./index-CI0n455B.js";class s{constructor(e,t,i,a,n){this._legacyCanvasSize=s.DEFAULT_CANVAS_SIZE,this._preferredCamera="environment",this._maxScansPerSecond=25,this._lastScanTimestamp=-1,this._destroyed=this._flashOn=this._paused=this._active=!1,this.$video=e,this.$canvas=document.createElement("canvas"),i&&typeof i=="object"?this._onDecode=t:(console.warn(i||a||n?"You're using a deprecated version of the QrScanner constructor which will be removed in the future":"Note that the type of the scan result passed to onDecode will change in the future. To already switch to the new api today, you can pass returnDetailedScanResult: true."),this._legacyOnDecode=t),t=typeof i=="object"?i:{},this._onDecodeError=t.onDecodeError||(typeof i=="function"?i:this._onDecodeError),this._calculateScanRegion=t.calculateScanRegion||(typeof a=="function"?a:this._calculateScanRegion),this._preferredCamera=t.preferredCamera||n||this._preferredCamera,this._legacyCanvasSize=typeof i=="number"?i:typeof a=="number"?a:this._legacyCanvasSize,this._maxScansPerSecond=t.maxScansPerSecond||this._maxScansPerSecond,this._onPlay=this._onPlay.bind(this),this._onLoadedMetaData=this._onLoadedMetaData.bind(this),this._onVisibilityChange=this._onVisibilityChange.bind(this),this._updateOverlay=this._updateOverlay.bind(this),e.disablePictureInPicture=!0,e.playsInline=!0,e.muted=!0;let o=!1;if(e.hidden&&(e.hidden=!1,o=!0),document.body.contains(e)||(document.body.appendChild(e),o=!0),i=e.parentElement,t.highlightScanRegion||t.highlightCodeOutline){if(a=!!t.overlay,this.$overlay=t.overlay||document.createElement("div"),n=this.$overlay.style,n.position="absolute",n.display="none",n.pointerEvents="none",this.$overlay.classList.add("scan-region-highlight"),!a&&t.highlightScanRegion){this.$overlay.innerHTML='<svg class="scan-region-highlight-svg" viewBox="0 0 238 238" preserveAspectRatio="none" style="position:absolute;width:100%;height:100%;left:0;top:0;fill:none;stroke:#e9b213;stroke-width:4;stroke-linecap:round;stroke-linejoin:round"><path d="M31 2H10a8 8 0 0 0-8 8v21M207 2h21a8 8 0 0 1 8 8v21m0 176v21a8 8 0 0 1-8 8h-21m-176 0H10a8 8 0 0 1-8-8v-21"/></svg>';try{this.$overlay.firstElementChild.animate({transform:["scale(.98)","scale(1.01)"]},{duration:400,iterations:1/0,direction:"alternate",easing:"ease-in-out"})}catch{}i.insertBefore(this.$overlay,this.$video.nextSibling)}t.highlightCodeOutline&&(this.$overlay.insertAdjacentHTML("beforeend",'<svg class="code-outline-highlight" preserveAspectRatio="none" style="display:none;width:100%;height:100%;fill:none;stroke:#e9b213;stroke-width:5;stroke-dasharray:25;stroke-linecap:round;stroke-linejoin:round"><polygon/></svg>'),this.$codeOutlineHighlight=this.$overlay.lastElementChild)}this._scanRegion=this._calculateScanRegion(e),requestAnimationFrame(()=>{let d=window.getComputedStyle(e);d.display==="none"&&(e.style.setProperty("display","block","important"),o=!0),d.visibility!=="visible"&&(e.style.setProperty("visibility","visible","important"),o=!0),o&&(console.warn("QrScanner has overwritten the video hiding style to avoid Safari stopping the playback."),e.style.opacity="0",e.style.width="0",e.style.height="0",this.$overlay&&this.$overlay.parentElement&&this.$overlay.parentElement.removeChild(this.$overlay),delete this.$overlay,delete this.$codeOutlineHighlight),this.$overlay&&this._updateOverlay()}),e.addEventListener("play",this._onPlay),e.addEventListener("loadedmetadata",this._onLoadedMetaData),document.addEventListener("visibilitychange",this._onVisibilityChange),window.addEventListener("resize",this._updateOverlay),this._qrEnginePromise=s.createQrEngine()}static set WORKER_PATH(e){console.warn("Setting QrScanner.WORKER_PATH is not required and not supported anymore. Have a look at the README for new setup instructions.")}static async hasCamera(){try{return!!(await s.listCameras(!1)).length}catch{return!1}}static async listCameras(e=!1){if(!navigator.mediaDevices)return[];let t=async()=>(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind==="videoinput"),i;try{e&&(await t()).every(a=>!a.label)&&(i=await navigator.mediaDevices.getUserMedia({audio:!1,video:!0}))}catch{}try{return(await t()).map((a,n)=>({id:a.deviceId,label:a.label||(n===0?"Default Camera":`Camera ${n+1}`)}))}finally{i&&(console.warn("Call listCameras after successfully starting a QR scanner to avoid creating a temporary video stream"),s._stopVideoStream(i))}}async hasFlash(){let e;try{if(this.$video.srcObject){if(!(this.$video.srcObject instanceof MediaStream))return!1;e=this.$video.srcObject}else e=(await this._getCameraStream()).stream;return"torch"in e.getVideoTracks()[0].getSettings()}catch{return!1}finally{e&&e!==this.$video.srcObject&&(console.warn("Call hasFlash after successfully starting the scanner to avoid creating a temporary video stream"),s._stopVideoStream(e))}}isFlashOn(){return this._flashOn}async toggleFlash(){this._flashOn?await this.turnFlashOff():await this.turnFlashOn()}async turnFlashOn(){if(!this._flashOn&&!this._destroyed&&(this._flashOn=!0,this._active&&!this._paused))try{if(!await this.hasFlash())throw"No flash available";await this.$video.srcObject.getVideoTracks()[0].applyConstraints({advanced:[{torch:!0}]})}catch(e){throw this._flashOn=!1,e}}async turnFlashOff(){this._flashOn&&(this._flashOn=!1,await this._restartVideoStream())}destroy(){this.$video.removeEventListener("loadedmetadata",this._onLoadedMetaData),this.$video.removeEventListener("play",this._onPlay),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("resize",this._updateOverlay),this._destroyed=!0,this._flashOn=!1,this.stop(),s._postWorkerMessage(this._qrEnginePromise,"close")}async start(){if(this._destroyed)throw Error("The QR scanner can not be started as it had been destroyed.");if((!this._active||this._paused)&&(window.location.protocol!=="https:"&&console.warn("The camera stream is only accessible if the page is transferred via https."),this._active=!0,!document.hidden))if(this._paused=!1,this.$video.srcObject)await this.$video.play();else try{let{stream:e,facingMode:t}=await this._getCameraStream();!this._active||this._paused?s._stopVideoStream(e):(this._setVideoMirror(t),this.$video.srcObject=e,await this.$video.play(),this._flashOn&&(this._flashOn=!1,this.turnFlashOn().catch(()=>{})))}catch(e){if(!this._paused)throw this._active=!1,e}}stop(){this.pause(),this._active=!1}async pause(e=!1){if(this._paused=!0,!this._active)return!0;this.$video.pause(),this.$overlay&&(this.$overlay.style.display="none");let t=()=>{this.$video.srcObject instanceof MediaStream&&(s._stopVideoStream(this.$video.srcObject),this.$video.srcObject=null)};return e?(t(),!0):(await new Promise(i=>setTimeout(i,300)),this._paused?(t(),!0):!1)}async setCamera(e){e!==this._preferredCamera&&(this._preferredCamera=e,await this._restartVideoStream())}static async scanImage(e,t,i,a,n=!1,o=!1){let d,c=!1;t&&("scanRegion"in t||"qrEngine"in t||"canvas"in t||"disallowCanvasResizing"in t||"alsoTryWithoutScanRegion"in t||"returnDetailedScanResult"in t)?(d=t.scanRegion,i=t.qrEngine,a=t.canvas,n=t.disallowCanvasResizing||!1,o=t.alsoTryWithoutScanRegion||!1,c=!0):console.warn(t||i||a||n||o?"You're using a deprecated api for scanImage which will be removed in the future.":"Note that the return type of scanImage will change in the future. To already switch to the new api today, you can pass returnDetailedScanResult: true."),t=!!i;try{let m,h;[i,m]=await Promise.all([i||s.createQrEngine(),s._loadImage(e)]),[a,h]=s._drawToCanvas(m,d,a,n);let u;if(i instanceof Worker){let r=i;t||s._postWorkerMessageSync(r,"inversionMode","both"),u=await new Promise((l,f)=>{let p,y,g,w=-1;y=v=>{v.data.id===w&&(r.removeEventListener("message",y),r.removeEventListener("error",g),clearTimeout(p),v.data.data!==null?l({data:v.data.data,cornerPoints:s._convertPoints(v.data.cornerPoints,d)}):f(s.NO_QR_CODE_FOUND))},g=v=>{r.removeEventListener("message",y),r.removeEventListener("error",g),clearTimeout(p),f("Scanner error: "+(v?v.message||v:"Unknown Error"))},r.addEventListener("message",y),r.addEventListener("error",g),p=setTimeout(()=>g("timeout"),1e4);let _=h.getImageData(0,0,a.width,a.height);w=s._postWorkerMessageSync(r,"decode",_,[_.data.buffer])})}else u=await Promise.race([new Promise((r,l)=>window.setTimeout(()=>l("Scanner error: timeout"),1e4)),(async()=>{try{var[r]=await i.detect(a);if(!r)throw s.NO_QR_CODE_FOUND;return{data:r.rawValue,cornerPoints:s._convertPoints(r.cornerPoints,d)}}catch(l){if(r=l.message||l,/not implemented|service unavailable/.test(r))return s._disableBarcodeDetector=!0,s.scanImage(e,{scanRegion:d,canvas:a,disallowCanvasResizing:n,alsoTryWithoutScanRegion:o});throw`Scanner error: ${r}`}})()]);return c?u:u.data}catch(m){if(!d||!o)throw m;let h=await s.scanImage(e,{qrEngine:i,canvas:a,disallowCanvasResizing:n});return c?h:h.data}finally{t||s._postWorkerMessage(i,"close")}}setGrayscaleWeights(e,t,i,a=!0){s._postWorkerMessage(this._qrEnginePromise,"grayscaleWeights",{red:e,green:t,blue:i,useIntegerApproximation:a})}setInversionMode(e){s._postWorkerMessage(this._qrEnginePromise,"inversionMode",e)}static async createQrEngine(e){if(e&&console.warn("Specifying a worker path is not required and not supported anymore."),e=()=>S(()=>import("./qr-scanner-worker.min-D85Z9gVD.js"),[]).then(i=>i.createWorker()),!(!s._disableBarcodeDetector&&"BarcodeDetector"in window&&BarcodeDetector.getSupportedFormats&&(await BarcodeDetector.getSupportedFormats()).includes("qr_code")))return e();let t=navigator.userAgentData;return t&&t.brands.some(({brand:i})=>/Chromium/i.test(i))&&/mac ?OS/i.test(t.platform)&&await t.getHighEntropyValues(["architecture","platformVersion"]).then(({architecture:i,platformVersion:a})=>/arm/i.test(i||"arm")&&13<=parseInt(a||"13")).catch(()=>!0)?e():new BarcodeDetector({formats:["qr_code"]})}_onPlay(){this._scanRegion=this._calculateScanRegion(this.$video),this._updateOverlay(),this.$overlay&&(this.$overlay.style.display=""),this._scanFrame()}_onLoadedMetaData(){this._scanRegion=this._calculateScanRegion(this.$video),this._updateOverlay()}_onVisibilityChange(){document.hidden?this.pause():this._active&&this.start()}_calculateScanRegion(e){let t=Math.round(.6666666666666666*Math.min(e.videoWidth,e.videoHeight));return{x:Math.round((e.videoWidth-t)/2),y:Math.round((e.videoHeight-t)/2),width:t,height:t,downScaledWidth:this._legacyCanvasSize,downScaledHeight:this._legacyCanvasSize}}_updateOverlay(){requestAnimationFrame(()=>{if(this.$overlay){var e=this.$video,t=e.videoWidth,i=e.videoHeight,a=e.offsetWidth,n=e.offsetHeight,o=e.offsetLeft,d=e.offsetTop,c=window.getComputedStyle(e),m=c.objectFit,h=t/i,u=a/n;switch(m){case"none":var r=t,l=i;break;case"fill":r=a,l=n;break;default:(m==="cover"?h>u:h<u)?(l=n,r=l*h):(r=a,l=r/h),m==="scale-down"&&(r=Math.min(r,t),l=Math.min(l,i))}var[f,p]=c.objectPosition.split(" ").map((g,w)=>{const _=parseFloat(g);return g.endsWith("%")?(w?n-l:a-r)*_/100:_});c=this._scanRegion.width||t,u=this._scanRegion.height||i,m=this._scanRegion.x||0;var y=this._scanRegion.y||0;h=this.$overlay.style,h.width=`${c/t*r}px`,h.height=`${u/i*l}px`,h.top=`${d+p+y/i*l}px`,i=/scaleX\(-1\)/.test(e.style.transform),h.left=`${o+(i?a-f-r:f)+(i?t-m-c:m)/t*r}px`,h.transform=e.style.transform}})}static _convertPoints(e,t){if(!t)return e;let i=t.x||0,a=t.y||0,n=t.width&&t.downScaledWidth?t.width/t.downScaledWidth:1;t=t.height&&t.downScaledHeight?t.height/t.downScaledHeight:1;for(let o of e)o.x=o.x*n+i,o.y=o.y*t+a;return e}_scanFrame(){!this._active||this.$video.paused||this.$video.ended||("requestVideoFrameCallback"in this.$video?this.$video.requestVideoFrameCallback.bind(this.$video):requestAnimationFrame)(async()=>{if(!(1>=this.$video.readyState)){var e=Date.now()-this._lastScanTimestamp,t=1e3/this._maxScansPerSecond;e<t&&await new Promise(a=>setTimeout(a,t-e)),this._lastScanTimestamp=Date.now();try{var i=await s.scanImage(this.$video,{scanRegion:this._scanRegion,qrEngine:this._qrEnginePromise,canvas:this.$canvas})}catch(a){if(!this._active)return;this._onDecodeError(a)}!s._disableBarcodeDetector||await this._qrEnginePromise instanceof Worker||(this._qrEnginePromise=s.createQrEngine()),i?(this._onDecode?this._onDecode(i):this._legacyOnDecode&&this._legacyOnDecode(i.data),this.$codeOutlineHighlight&&(clearTimeout(this._codeOutlineHighlightRemovalTimeout),this._codeOutlineHighlightRemovalTimeout=void 0,this.$codeOutlineHighlight.setAttribute("viewBox",`${this._scanRegion.x||0} ${this._scanRegion.y||0} ${this._scanRegion.width||this.$video.videoWidth} ${this._scanRegion.height||this.$video.videoHeight}`),this.$codeOutlineHighlight.firstElementChild.setAttribute("points",i.cornerPoints.map(({x:a,y:n})=>`${a},${n}`).join(" ")),this.$codeOutlineHighlight.style.display="")):this.$codeOutlineHighlight&&!this._codeOutlineHighlightRemovalTimeout&&(this._codeOutlineHighlightRemovalTimeout=setTimeout(()=>this.$codeOutlineHighlight.style.display="none",100))}this._scanFrame()})}_onDecodeError(e){e!==s.NO_QR_CODE_FOUND&&console.log(e)}async _getCameraStream(){if(!navigator.mediaDevices)throw"Camera not found.";let e=/^(environment|user)$/.test(this._preferredCamera)?"facingMode":"deviceId",t=[{width:{min:1024}},{width:{min:768}},{}],i=t.map(a=>Object.assign({},a,{[e]:{exact:this._preferredCamera}}));for(let a of[...i,...t])try{let n=await navigator.mediaDevices.getUserMedia({video:a,audio:!1}),o=this._getFacingMode(n)||(a.facingMode?this._preferredCamera:this._preferredCamera==="environment"?"user":"environment");return{stream:n,facingMode:o}}catch{}throw"Camera not found."}async _restartVideoStream(){let e=this._paused;await this.pause(!0)&&!e&&this._active&&await this.start()}static _stopVideoStream(e){for(let t of e.getTracks())t.stop(),e.removeTrack(t)}_setVideoMirror(e){this.$video.style.transform="scaleX("+(e==="user"?-1:1)+")"}_getFacingMode(e){return(e=e.getVideoTracks()[0])?/rear|back|environment/i.test(e.label)?"environment":/front|user|face/i.test(e.label)?"user":null:null}static _drawToCanvas(e,t,i,a=!1){i=i||document.createElement("canvas");let n=t&&t.x?t.x:0,o=t&&t.y?t.y:0,d=t&&t.width?t.width:e.videoWidth||e.width,c=t&&t.height?t.height:e.videoHeight||e.height;return a||(a=t&&t.downScaledWidth?t.downScaledWidth:d,t=t&&t.downScaledHeight?t.downScaledHeight:c,i.width!==a&&(i.width=a),i.height!==t&&(i.height=t)),t=i.getContext("2d",{alpha:!1}),t.imageSmoothingEnabled=!1,t.drawImage(e,n,o,d,c,0,0,i.width,i.height),[i,t]}static async _loadImage(e){if(e instanceof Image)return await s._awaitImageLoad(e),e;if(e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement||e instanceof SVGImageElement||"OffscreenCanvas"in window&&e instanceof OffscreenCanvas||"ImageBitmap"in window&&e instanceof ImageBitmap)return e;if(e instanceof File||e instanceof Blob||e instanceof URL||typeof e=="string"){let t=new Image;t.src=e instanceof File||e instanceof Blob?URL.createObjectURL(e):e.toString();try{return await s._awaitImageLoad(t),t}finally{(e instanceof File||e instanceof Blob)&&URL.revokeObjectURL(t.src)}}else throw"Unsupported image type."}static async _awaitImageLoad(e){e.complete&&e.naturalWidth!==0||await new Promise((t,i)=>{let a=n=>{e.removeEventListener("load",a),e.removeEventListener("error",a),n instanceof ErrorEvent?i("Image load error"):t()};e.addEventListener("load",a),e.addEventListener("error",a)})}static async _postWorkerMessage(e,t,i,a){return s._postWorkerMessageSync(await e,t,i,a)}static _postWorkerMessageSync(e,t,i,a){if(!(e instanceof Worker))return-1;let n=s._workerMessageId++;return e.postMessage({id:n,type:t,data:i},a),n}}s.DEFAULT_CANVAS_SIZE=400;s.NO_QR_CODE_FOUND="No QR code found";s._disableBarcodeDetector=!1;s._workerMessageId=0;export{s as default};
|