1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9738],{19738:(e,t,r)=>{r.d(t,{WebContainer:()=>B});let n="__wc_api_tokens__";class i{_bus=new EventTarget;listen(e){function t(t){e(t.data)}return this._bus.addEventListener("message",t),()=>this._bus.removeEventListener("message",t)}fireEvent(e){this._bus.dispatchEvent(new MessageEvent("message",{data:e}))}}let s=Error();s.stack="";let o=new i;class a{origin;refresh;access;expires;_revoked=new AbortController;constructor(e,t,r,n){this.origin=e,this.refresh=t,this.access=r,this.expires=n}async activate(e){if(this._revoked.signal.aborted)throw Error("Token revoked");return(!(this.expires<Date.now())||!!await this._fetchNewAccessToken())&&(this._sync(),this._startRefreshTokensLoop(e),!0)}async revoke(e,t){this._revoked.abort();try{if(!(await fetch(`${this.origin}/oauth/revoke`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({token:this.refresh,token_type_hint:"refresh_token",client_id:e}),mode:"cors"})).ok)throw Error("Failed to logout")}catch(e){if(!t)throw e}l()}static fromStorage(){let e=function(){let e=localStorage.getItem(n);if(!e)return null;try{return JSON.parse(e)}catch{return null}}();return e?new a(e.origin,e.refresh,e.access,e.expires):null}static async fromAuthCode({editorOrigin:e,clientId:t,codeVerifier:r,authCode:n,redirectUri:i}){let s=await fetch(`${e}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:t,code:n,code_verifier:r,grant_type:"authorization_code",redirect_uri:i}),mode:"cors"});if(!s.ok)throw Error(`Failed to fetch token: ${s.status}`);let o=await s.json();c(o);let{access_token:l,refresh_token:h}=o;return new a(e,h,l,function({created_at:e,expires_in:t}){return(e+t)*1e3}(o))}async _fetchNewAccessToken(){try{let e=await fetch(`${this.origin}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:this.refresh}),mode:"cors",signal:this._revoked.signal});if(!e.ok)throw s;let t=await e.json();c(t);let{access_token:r,refresh_token:n}=t,i=function({created_at:e,expires_in:t}){return(e+t)*1e3}(t);return this.access=r,this.expires=i,this.refresh=n,!0}catch{return l(),!1}}_sync(){var e,t;e=this,localStorage.setItem(n,JSON.stringify(e)),t=this.access,o.fireEvent(t)}async _startRefreshTokensLoop(e){for(;;){let t=this.expires-Date.now()-1e3;if(await function(e){return new Promise(t=>setTimeout(t,e))}(Math.max(t,1e3)),this._revoked.signal.aborted)return;if(!this._fetchNewAccessToken())return void e();this._sync()}}}function l(){localStorage.removeItem(n)}function c(e){if("object"!=typeof e||!e||"string"!=typeof e.access_token||"string"!=typeof e.refresh_token||"number"!=typeof e.created_at||"number"!=typeof e.expires_in)throw Error("Invalid Token Response")}let h={},u=null,d={get editorOrigin(){return null==u&&(u=new URL(globalThis.WEBCONTAINER_API_IFRAME_URL??"https://stackblitz.com").origin),u},set editorOrigin(newOrigin){u=new URL(newOrigin).origin},setQueryParam(e,t){h[e]=t},get url(){let e=new URL(this.editorOrigin);for(let t in e.pathname="/headless",h)e.searchParams.set(t,h[t]);return e.searchParams.set("version","1.6.1"),e}},f={initialized:!1,bootCalled:!1,authComplete:function(){let e,t;function r(){t=new Promise(t=>e=t)}return r(),{get promise(){return t},resolve:t=>e(t),reset:r}}(),clientId:"",oauthScope:"",broadcastChannel:null,get editorOrigin(){return d.editorOrigin},tokens:null};new i,new i,(p=w||(w={})).UncaughtException="PREVIEW_UNCAUGHT_EXCEPTION",p.UnhandledRejection="PREVIEW_UNHANDLED_REJECTION",p.ConsoleError="PREVIEW_CONSOLE_ERROR";var p,w,_=Object.defineProperty,m={},y={createEndpoint:()=>k,expose:()=>C,proxy:()=>R,proxyMarker:()=>b,releaseProxy:()=>v,transfer:()=>N,transferHandlers:()=>x,windowEndpoint:()=>j,wrap:()=>S};for(var g in y)_(m,g,{get:y[g],enumerable:!0});var b=Symbol("Comlink.proxy"),k=Symbol("Comlink.endpoint"),v=Symbol("Comlink.releaseProxy"),E=Symbol("Comlink.thrown"),P=e=>"object"==typeof e&&null!==e||"function"==typeof e,x=new Map([["proxy",{canHandle:e=>P(e)&&e[b],serialize(e){let{port1:t,port2:r}=new MessageChannel;return C(e,t),[r,[r]]},deserialize:e=>(e.start(),S(e))}],["throw",{canHandle:e=>P(e)&&E in e,serialize:({value:e})=>[e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[]],deserialize(e){if(e.isError)throw Object.assign(Error(e.value.message),e.value);throw e.value}}]]);function C(e,t=self){t.addEventListener("message",function r(n){let i;if(!n||!n.data)return;let{id:s,type:o,path:a}=Object.assign({path:[]},n.data),l=(n.data.argumentList||[]).map(U);try{let t=a.slice(0,-1).reduce((e,t)=>
1e[t],e),r=a.reduce((e,t)=>e[t],e);switch(o){case 0:i=r;break;case 1:t[a.slice(-1)[0]]=U(n.data.value),i=!0;break;case 2:i=r.apply(t,l);break;case 3:{let e=new r(...l);i=R(e)}break;case 4:{let{port1:t,port2:r}=new MessageChannel;C(e,r),i=N(t,[t])}break;case 5:i=void 0}}catch(e){i={value:e,[E]:0}}Promise.resolve(i).catch(e=>({value:e,[E]:0})).then(e=>{let[n,i]=I(e);t.postMessage(Object.assign(Object.assign({},n),{id:s}),i),5===o&&(t.removeEventListener("message",r),O(t))})}),t.start&&t.start()}function O(e){"MessagePort"===e.constructor.name&&e.close()}function S(e,t){return function e(t,r=[],n=function(){}){let i=!1,s=new Proxy(n,{get(n,o){if(L(i),o===v)return()=>M(t,{type:5,path:r.map(e=>e.toString())}).then(()=>{O(t),i=!0});if("then"===o){if(0===r.length)return{then:()=>s};let e=M(t,{type:0,path:r.map(e=>e.toString())}).then(U);return e.then.bind(e)}return e(t,[...r,o])},set(e,n,s){L(i);let[o,a]=I(s);return M(t,{type:1,path:[...r,n].map(e=>e.toString()),value:o},a).then(U)},apply(n,s,o){L(i);let a=r[r.length-1];if(a===k)return M(t,{type:4}).then(U);if("bind"===a)return e(t,r.slice(0,-1));let[l,c]=T(o);return M(t,{type:2,path:r.map(e=>e.toString()),argumentList:l},c).then(U)},construct(e,n){L(i);let[s,o]=T(n);return M(t,{type:3,path:r.map(e=>e.toString()),argumentList:s},o).then(U)}});return s}(e,[],t)}function L(e){if(e)throw Error("Proxy has been released and is not useable")}function T(e){var t;let r=e.map(I);return[r.map(e=>e[0]),(t=r.map(e=>e[1]),Array.prototype.concat.apply([],t))]}var A=new WeakMap;function N(e,t){return A.set(e,t),e}function R(e){return Object.assign(e,{[b]:!0})}function j(e,t=self,r="*"){return{postMessage:(t,n)=>e.postMessage(t,r,n),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function I(e){for(let[t,r]of x)if(r.canHandle(e)){let[n,i]=r.serialize(e);return[{type:3,name:t,value:n},i]}return[{type:0,value:e},A.get(e)||[]]}function U(e){switch(e.type){case 3:return x.get(e.name).deserialize(e.value);case 0:return e.value}}function M(e,t,r){return new Promise(n=>{let i=[,,,,].fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-");e.addEventListener("message",function t(r){r.data&&r.data.id&&r.data.id===i&&(e.removeEventListener("message",t),n(r.data))}),e.start&&e.start(),e.postMessage(Object.assign({id:i},t),r)})}let F=[w.ConsoleError,w.UncaughtException,w.UnhandledRejection];function z(e){let t=Object.create(null);return e?Object.assign(t,e):t}let D=new TextDecoder("latin1"),W=null,H=null,J={},$=new TextDecoder,q=new TextEncoder;class B{_instance;_runtimeInfo;fs;static _instance=null;static _teardownPromise=null;_tornDown=!1;_unsubscribeFromTokenChangedListener=()=>{};constructor(e,t,r,n){if(this._instance=e,this._runtimeInfo=n,this.fs=new X(t),f.initialized){var i;this._unsubscribeFromTokenChangedListener=(i=e=>{this._instance.setCredentials({accessToken:e,editorOrigin:f.editorOrigin})},o.listen(i)),(async()=>{if(await f.authComplete.promise,!this._tornDown){if(!f.tokens)throw Error("Oops! Tokens is not defined when it always should be.");await this._instance.setCredentials({accessToken:f.tokens.access,editorOrigin:f.editorOrigin})}})().catch(e=>{console.error(e)})}}async spawn(e,t,r){let n,i,s,o=[];Array.isArray(t)?o=t:r=t;let a=new ReadableStream;if(r?.output!==!1){let e,t=(e=null,{stream:new ReadableStream({start(t){e=t}}),push:t=>{null!=t?e?.enqueue(t):(e?.close(),e=null)}});n=t.push,a=t.stream}let l=Z(Y(n)),c=Z(Y(void 0)),h=Z(Y(void 0));return new G(await this._instance.run({command:e,args:o,cwd:r?.cwd,env:r?.env,terminal:r?.terminal},c,h,l),a,i,s)}async export(e,t){let r={format:t?.format??"json",includes:t?.includes,excludes:t?.excludes,external:!0},n=await this._instance.serialize(e,r);return"json"===r.format?function e(t){let r=z();if("f"in t)throw Error("It is not possible to export a single file in the JSON format.");if("d"in t)for(let n of Object.keys(t.d)){let i=t.d[n];"d"in i?r[n]=z({directory:e(i)}):"f"in i&&("c"in i.f?r[n]=z({file:z({contents:i.f.b?function(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e[r].charCodeAt(0);return t}(i.f.c):i.f.c})}):"l"in i.f&&(r[n]=z({file:z({symlink:i.f.l})})))}return r}(JSON.parse($.decode(n))):n}on(e,t){var r;let n,i;if("preview-message"===e){let e=t;t=t=>{null!=t&&"object"==typeof t&&"type"in t&&F.includes(t.type)&&e(t)}}let{listener:s,subscribe:o}=(r=t,n=!1,i=()=>{},{subscribe:e=>(e.then(e=>{i=e,n&&i()}),()=>{n=!0,i()}),listener:(...e)=>{n||r(...e)}});return o(this._instance.on(e,m.proxy(s)))}mount(e,t){let r=e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):q.encode(JSON.stringify(function e(t){let r={d:{}};for(let n of Object.keys(t)){let i=t[n];if("file"in i){if("symlink"in i.file){r.d[n]={f:{l:i.file.symlink}};continue}let e=i.file.contents,t="string"==typeof e?e:D.decode(e),s="string"==typeof e?{}:{b:!0};r.d[n]={f:{c:t,...s}};continue}let s=e(i.directory);r.d[n]=s}return r}(e)));return this._instance.loadFiles(m.transfer(r,[r.buffer]),{mountPoints:t?.mountPoint})}setPreviewScript(e,t){return this._instance.setPreviewScript(e,t)}get path(){return this._runtimeInfo.path}get workdir(){return this._runtimeInfo.cwd}teardown(){if(this._tornDown)throw Error("WebContainer already torn down");this._tornDown=!0,this._unsubscribeFromTokenChangedListener();let e=async()=>{try{await this.fs._teardown(),await this._instance.teardown()}finally{this._instance[m.releaseProxy](),B._instance===this&&(B._instance=null)}};B._teardownPromise=e()}static async boot(e={}){await this._teardownPromise,B._teardownPromise=null;let{workdirName:t}=e;if(window.crossOriginIsolated&&"none"===e.coep&&console.warn(`A Cross-Origin-Embedder-Policy header is required in cross origin isolated environments. 2Set the 'coep' option to 'require-corp'.`),t?.includes("/")||".."===t||"."===t)throw Error("workdirName should be a valid folder name");for(f.bootCalled=!0;W;)await W;if(B._instance)throw Error("Only a single WebContainer instance can be booted");let r=K(e);W=r.catch(()=>{});try{let e=await r;return B._instance=e,e}finally{W=null}}}class Q{name;_type;constructor(e,t){this.name=e,this._type=t}isFile(){return 1===this._type}isDirectory(){return 2===this._type}}class V{_apiClient;_path;_options;_listener;_wrappedListener;_watcher;_closed=!1;constructor(e,t,r,n){this._apiClient=e,this._path=t,this._options=r,this._listener=n,this._apiClient._watchers.add(this),this._wrappedListener=(e,t)=>{this._listener&&!this._closed&&this._listener(e,t)},this._apiClient._fs.watch(this._path,this._options,Z(this._wrappedListener)).then(e=>{if(this._watcher=e,this._closed)return this._teardown()}).catch(console.error)}async close(){this._closed||(this._closed=!0,this._apiClient._watchers.delete(this),await this._teardown())}async _teardown(){await this._watcher?.close().finally(()=>{this._watcher?.[m.releaseProxy]()})}}class G{output;input;exit;_process;stdout;stderr;constructor(e,t,r,n){this.output=t,this._process=e,this.input=new WritableStream({write:e=>{this._getProcess()?.write(e).catch(()=>{})}}),this.exit=this._onExit(),this.stdout=r,this.stderr=n}kill(){this._process?.kill()}resize(e){this._getProcess()?.resize(e)}async _onExit(){try{return await this._process.onExit}finally{this._process?.[m.releaseProxy](),this._process=null}}_getProcess(){return null==this._process&&console.warn("This process already exited"),this._process}
2}class X{_fs;_watchers=new Set([]);constructor(e){this._fs=e}rm(...e){return this._fs.rm(...e)}async readFile(e,t){return await this._fs.readFile(e,t)}async rename(e,t){return await this._fs.rename(e,t)}async writeFile(e,t,r){if(t instanceof Uint8Array){let e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);t=m.transfer(new Uint8Array(e),[e])}await this._fs.writeFile(e,t,r)}async readdir(e,t){let r=await this._fs.readdir(e,t);return"string"==typeof r[0]||r[0]instanceof Uint8Array?r:r.map(e=>new Q(e.name,e["Symbol(type)"]))}async mkdir(e,t){return await this._fs.mkdir(e,t)}watch(e,t,r){return"function"==typeof t&&(r=t,t=null),new V(this,e,t,r)}async _teardown(){this._fs[m.releaseProxy](),await Promise.all([...this._watchers].map(e=>e.close()))}}async function K(e){let{serverPromise:t}=function(e){if(null!=H)return e.coep!==J.coep&&(console.warn(`Attempting to boot WebContainer with 'coep: ${e.coep}'`),console.warn(`First boot had 'coep: ${J.coep}', new settings will not take effect!`)),{serverPromise:H};e.coep&&d.setQueryParam("coep",e.coep),e.experimentalNode&&d.setQueryParam("experimental_node","1");let t=document.createElement("iframe");t.style.display="none",t.setAttribute("allow","cross-origin-isolated");let r=d.url;t.src=r.toString();let{origin:n}=r;return J={...e},H=new Promise(e=>{window.addEventListener("message",t=>{if(t.origin!==n)return;let{data:r}=t;"init"===r.type?e(m.wrap(t.ports[0])):"warning"===r.type&&console[r.level].call(console,r.message)})}),document.body.insertBefore(t,null),{serverPromise:H}}(e),r=await t,n=await r.build({host:window.location.host,version:"1.6.1",workdirName:e.workdirName,forwardPreviewErrors:e.forwardPreviewErrors}),[i,s,o]=await Promise.all([n.fs(),n.previewScript(),n.runtimeInfo()]);return new B(n,i,s,o)}function Y(e){if(null!=e)return t=>{t instanceof Uint8Array?e($.decode(t)):null==t&&e(null)}}function Z(e){if(null!=e)return m.proxy(e)}}}]); 3//# sourceMappingURL=9738.beffc877e8a43069.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.