From 7e177a1a825ad8c1dab09fa3916350dd71eba76c Mon Sep 17 00:00:00 2001 From: SS <66886825+EarlMilktea@users.noreply.github.com> Date: Mon, 22 Jul 2024 09:13:33 +0900 Subject: [PATCH] :bug: Use relative URL --- assets/{index-dGJ3xUm8.js => index-CebxzHPN.js} | 2 +- index.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename assets/{index-dGJ3xUm8.js => index-CebxzHPN.js} (98%) diff --git a/assets/index-dGJ3xUm8.js b/assets/index-CebxzHPN.js similarity index 98% rename from assets/index-dGJ3xUm8.js rename to assets/index-CebxzHPN.js index 24f2d29..ba9626f 100644 --- a/assets/index-dGJ3xUm8.js +++ b/assets/index-CebxzHPN.js @@ -42,4 +42,4 @@ Error generating stack: `+i.message+` * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: Apache-2.0 - */const Qf=Symbol("Comlink.proxy"),Sm=Symbol("Comlink.endpoint"),xm=Symbol("Comlink.releaseProxy"),Ki=Symbol("Comlink.finalizer"),vl=Symbol("Comlink.thrown"),Kf=e=>typeof e=="object"&&e!==null||typeof e=="function",km={canHandle:e=>Kf(e)&&e[Qf],serialize(e){const{port1:t,port2:n}=new MessageChannel;return Gf(e,t),[n,[n]]},deserialize(e){return e.start(),Zf(e)}},Em={canHandle:e=>Kf(e)&&vl in e,serialize({value:e}){let t;return e instanceof Error?t={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:t={isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},Yf=new Map([["proxy",km],["throw",Em]]);function Cm(e,t){for(const n of e)if(t===n||n==="*"||n instanceof RegExp&&n.test(t))return!0;return!1}function Gf(e,t=globalThis,n=["*"]){t.addEventListener("message",function r(l){if(!l||!l.data)return;if(!Cm(n,l.origin)){console.warn(`Invalid origin '${l.origin}' for comlink proxy`);return}const{id:i,type:o,path:u}=Object.assign({path:[]},l.data),s=(l.data.argumentList||[]).map(Ht);let a;try{const h=u.slice(0,-1).reduce((p,w)=>p[w],e),m=u.reduce((p,w)=>p[w],e);switch(o){case"GET":a=m;break;case"SET":h[u.slice(-1)[0]]=Ht(l.data.value),a=!0;break;case"APPLY":a=m.apply(h,s);break;case"CONSTRUCT":{const p=new m(...s);a=Lm(p)}break;case"ENDPOINT":{const{port1:p,port2:w}=new MessageChannel;Gf(e,w),a=Tm(p,[p])}break;case"RELEASE":a=void 0;break;default:return}}catch(h){a={value:h,[vl]:0}}Promise.resolve(a).catch(h=>({value:h,[vl]:0})).then(h=>{const[m,p]=Yl(h);t.postMessage(Object.assign(Object.assign({},m),{id:i}),p),o==="RELEASE"&&(t.removeEventListener("message",r),Xf(t),Ki in e&&typeof e[Ki]=="function"&&e[Ki]())}).catch(h=>{const[m,p]=Yl({value:new TypeError("Unserializable return value"),[vl]:0});t.postMessage(Object.assign(Object.assign({},m),{id:i}),p)})}),t.start&&t.start()}function _m(e){return e.constructor.name==="MessagePort"}function Xf(e){_m(e)&&e.close()}function Zf(e,t){return Qo(e,[],t)}function rl(e){if(e)throw new Error("Proxy has been released and is not useable")}function Jf(e){return un(e,{type:"RELEASE"}).then(()=>{Xf(e)})}const Ql=new WeakMap,Kl="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(Ql.get(e)||0)-1;Ql.set(e,t),t===0&&Jf(e)});function Pm(e,t){const n=(Ql.get(t)||0)+1;Ql.set(t,n),Kl&&Kl.register(e,t,e)}function Nm(e){Kl&&Kl.unregister(e)}function Qo(e,t=[],n=function(){}){let r=!1;const l=new Proxy(n,{get(i,o){if(rl(r),o===xm)return()=>{Nm(l),Jf(e),r=!0};if(o==="then"){if(t.length===0)return{then:()=>l};const u=un(e,{type:"GET",path:t.map(s=>s.toString())}).then(Ht);return u.then.bind(u)}return Qo(e,[...t,o])},set(i,o,u){rl(r);const[s,a]=Yl(u);return un(e,{type:"SET",path:[...t,o].map(h=>h.toString()),value:s},a).then(Ht)},apply(i,o,u){rl(r);const s=t[t.length-1];if(s===Sm)return un(e,{type:"ENDPOINT"}).then(Ht);if(s==="bind")return Qo(e,t.slice(0,-1));const[a,h]=fa(u);return un(e,{type:"APPLY",path:t.map(m=>m.toString()),argumentList:a},h).then(Ht)},construct(i,o){rl(r);const[u,s]=fa(o);return un(e,{type:"CONSTRUCT",path:t.map(a=>a.toString()),argumentList:u},s).then(Ht)}});return Pm(l,e),l}function zm(e){return Array.prototype.concat.apply([],e)}function fa(e){const t=e.map(Yl);return[t.map(n=>n[0]),zm(t.map(n=>n[1]))]}const qf=new WeakMap;function Tm(e,t){return qf.set(e,t),e}function Lm(e){return Object.assign(e,{[Qf]:!0})}function Yl(e){for(const[t,n]of Yf)if(n.canHandle(e)){const[r,l]=n.serialize(e);return[{type:"HANDLER",name:t,value:r},l]}return[{type:"RAW",value:e},qf.get(e)||[]]}function Ht(e){switch(e.type){case"HANDLER":return Yf.get(e.name).deserialize(e.value);case"RAW":return e.value}}function un(e,t,n){return new Promise(r=>{const l=Om();e.addEventListener("message",function i(o){!o.data||!o.data.id||o.data.id!==l||(e.removeEventListener("message",i),r(o.data))}),e.start&&e.start(),e.postMessage(Object.assign({id:l},t),n)})}function Om(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}class Rm{#e;constructor(t){if(!Number.isInteger(t)||t<1)throw new Error;this.#e=Zf(new Worker(new URL("/assets/worker-q92aentc.js",import.meta.url),{type:"module",name:String(t)}))}async size(){return await this.#e.size()}async resize(t){await this.#e.resize(t)}async update(t){await this.#e.update(t)}async spin(){return await this.#e.spin()}async isReady(t=250){const n=new Promise(l=>{setTimeout(()=>{l("timeout")},t)});return await Promise.race([this.#e.size(),n])!=="timeout"}}const jm="#F97111",Fm="#439CFE",Ko=.05,da=1-2*Ko,pa=.15;function Mm({i:e,j:t,spin:n}){return I.jsx("rect",{width:da,height:da,x:e+Ko,y:t+Ko,rx:pa,ry:pa,style:{fill:n===1?jm:Fm}})}function $m({svgSize:e,spins:t}){const n=t.length,r=String(n),l=[];for(let i=0;iArray.from(t,()=>Math.random()<.5?1:-1))}const bf=12,Im=.44,Am=120,Um=new Rm(bf);function Wm({svgSize:e,size:t,k:n}){const r=kt.useRef(Um),[l,i]=kt.useState(()=>Dm(t));return kt.useEffect(()=>{const u=setInterval(async()=>{for(;!await r.current.isReady();)console.log("Waiting for Worker...");await r.current.size()!==t&&await r.current.resize(t),await r.current.update(n),i(await r.current.spin())},1e3/Am);return()=>{clearInterval(u)}},[t,n]),I.jsx($m,{svgSize:e,spins:l})}function Vm({size:e,hook:t}){return I.jsxs("div",{className:ue`flex`,children:[I.jsx("label",{htmlFor:"L",className:ue`w-1/12 block`,children:"L"}),I.jsx("input",{type:"range",min:"2",max:"128",step:"1",value:e,className:ue`w-9/12 bg-[#439CFE]`,id:"L",onChange:t}),I.jsx("div",{className:ue`w-2/12 text-right`,children:e})]})}function Hm({k:e,hook:t}){return I.jsxs("div",{className:ue`flex`,children:[I.jsx("label",{htmlFor:"k",className:ue`w-1/12 block`,children:"K"}),I.jsx("input",{type:"range",min:"-1",max:"1",step:"any",value:e,className:ue`w-9/12`,id:"k",onChange:t}),I.jsx("div",{className:ue`w-2/12 text-right`,children:e.toFixed(3)})]})}function Bm(){const[e,t]=kt.useState(bf),[n,r]=kt.useState(Im);return I.jsx("div",{className:ue`w-10/12 mx-auto relative top-1/2 -translate-y-2/4`,children:I.jsxs("div",{className:ue`flex justify-between`,children:[I.jsx("div",{className:ue`w-5/12`,children:I.jsx(Wm,{svgSize:"100%",size:e,k:n})}),I.jsxs("div",{className:ue`w-1/2 flex flex-col justify-between`,children:[I.jsx("h1",{className:ue`text-2xl font-bold`,children:"2D Ising Model: WebAssembly"}),I.jsxs("div",{children:[I.jsxs("div",{className:ue`flex justify-evenly`,children:[I.jsx("img",{src:"/wasm.svg",id:"wasm-logo",className:ue`w-3/12`}),I.jsx("img",{src:"/react.svg",id:"react-logo",className:ue`w-3/12`})]}),I.jsx("h2",{className:ue`text-center text-xl mt-2`,children:"WebAssembly + React"})]}),I.jsxs("div",{children:[I.jsx(Vm,{size:e,hook:l=>{const i=Number.parseInt(l.target.value);t(i)}}),I.jsx(Hm,{k:n,hook:l=>{const i=Number.parseFloat(l.target.value);r(i)}})]})]})]})})}wm({theme:{fontFamily:{sans:["Zen Maru Gothic","sans-serif"]},extend:{}}});const ed=document.getElementById("root");if(ed===null)throw new Error("Root element not found");Yi.createRoot(ed).render(I.jsx(yd.StrictMode,{children:I.jsx(Bm,{})})); + */const Qf=Symbol("Comlink.proxy"),Sm=Symbol("Comlink.endpoint"),xm=Symbol("Comlink.releaseProxy"),Ki=Symbol("Comlink.finalizer"),vl=Symbol("Comlink.thrown"),Kf=e=>typeof e=="object"&&e!==null||typeof e=="function",km={canHandle:e=>Kf(e)&&e[Qf],serialize(e){const{port1:t,port2:n}=new MessageChannel;return Gf(e,t),[n,[n]]},deserialize(e){return e.start(),Zf(e)}},Em={canHandle:e=>Kf(e)&&vl in e,serialize({value:e}){let t;return e instanceof Error?t={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:t={isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},Yf=new Map([["proxy",km],["throw",Em]]);function Cm(e,t){for(const n of e)if(t===n||n==="*"||n instanceof RegExp&&n.test(t))return!0;return!1}function Gf(e,t=globalThis,n=["*"]){t.addEventListener("message",function r(l){if(!l||!l.data)return;if(!Cm(n,l.origin)){console.warn(`Invalid origin '${l.origin}' for comlink proxy`);return}const{id:i,type:o,path:u}=Object.assign({path:[]},l.data),s=(l.data.argumentList||[]).map(Ht);let a;try{const h=u.slice(0,-1).reduce((p,w)=>p[w],e),m=u.reduce((p,w)=>p[w],e);switch(o){case"GET":a=m;break;case"SET":h[u.slice(-1)[0]]=Ht(l.data.value),a=!0;break;case"APPLY":a=m.apply(h,s);break;case"CONSTRUCT":{const p=new m(...s);a=Lm(p)}break;case"ENDPOINT":{const{port1:p,port2:w}=new MessageChannel;Gf(e,w),a=Tm(p,[p])}break;case"RELEASE":a=void 0;break;default:return}}catch(h){a={value:h,[vl]:0}}Promise.resolve(a).catch(h=>({value:h,[vl]:0})).then(h=>{const[m,p]=Yl(h);t.postMessage(Object.assign(Object.assign({},m),{id:i}),p),o==="RELEASE"&&(t.removeEventListener("message",r),Xf(t),Ki in e&&typeof e[Ki]=="function"&&e[Ki]())}).catch(h=>{const[m,p]=Yl({value:new TypeError("Unserializable return value"),[vl]:0});t.postMessage(Object.assign(Object.assign({},m),{id:i}),p)})}),t.start&&t.start()}function _m(e){return e.constructor.name==="MessagePort"}function Xf(e){_m(e)&&e.close()}function Zf(e,t){return Qo(e,[],t)}function rl(e){if(e)throw new Error("Proxy has been released and is not useable")}function Jf(e){return un(e,{type:"RELEASE"}).then(()=>{Xf(e)})}const Ql=new WeakMap,Kl="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(Ql.get(e)||0)-1;Ql.set(e,t),t===0&&Jf(e)});function Pm(e,t){const n=(Ql.get(t)||0)+1;Ql.set(t,n),Kl&&Kl.register(e,t,e)}function Nm(e){Kl&&Kl.unregister(e)}function Qo(e,t=[],n=function(){}){let r=!1;const l=new Proxy(n,{get(i,o){if(rl(r),o===xm)return()=>{Nm(l),Jf(e),r=!0};if(o==="then"){if(t.length===0)return{then:()=>l};const u=un(e,{type:"GET",path:t.map(s=>s.toString())}).then(Ht);return u.then.bind(u)}return Qo(e,[...t,o])},set(i,o,u){rl(r);const[s,a]=Yl(u);return un(e,{type:"SET",path:[...t,o].map(h=>h.toString()),value:s},a).then(Ht)},apply(i,o,u){rl(r);const s=t[t.length-1];if(s===Sm)return un(e,{type:"ENDPOINT"}).then(Ht);if(s==="bind")return Qo(e,t.slice(0,-1));const[a,h]=fa(u);return un(e,{type:"APPLY",path:t.map(m=>m.toString()),argumentList:a},h).then(Ht)},construct(i,o){rl(r);const[u,s]=fa(o);return un(e,{type:"CONSTRUCT",path:t.map(a=>a.toString()),argumentList:u},s).then(Ht)}});return Pm(l,e),l}function zm(e){return Array.prototype.concat.apply([],e)}function fa(e){const t=e.map(Yl);return[t.map(n=>n[0]),zm(t.map(n=>n[1]))]}const qf=new WeakMap;function Tm(e,t){return qf.set(e,t),e}function Lm(e){return Object.assign(e,{[Qf]:!0})}function Yl(e){for(const[t,n]of Yf)if(n.canHandle(e)){const[r,l]=n.serialize(e);return[{type:"HANDLER",name:t,value:r},l]}return[{type:"RAW",value:e},qf.get(e)||[]]}function Ht(e){switch(e.type){case"HANDLER":return Yf.get(e.name).deserialize(e.value);case"RAW":return e.value}}function un(e,t,n){return new Promise(r=>{const l=Om();e.addEventListener("message",function i(o){!o.data||!o.data.id||o.data.id!==l||(e.removeEventListener("message",i),r(o.data))}),e.start&&e.start(),e.postMessage(Object.assign({id:l},t),n)})}function Om(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}class Rm{#e;constructor(t){if(!Number.isInteger(t)||t<1)throw new Error;this.#e=Zf(new Worker(new URL(""+new URL("worker-q92aentc.js",import.meta.url).href,import.meta.url),{type:"module",name:String(t)}))}async size(){return await this.#e.size()}async resize(t){await this.#e.resize(t)}async update(t){await this.#e.update(t)}async spin(){return await this.#e.spin()}async isReady(t=250){const n=new Promise(l=>{setTimeout(()=>{l("timeout")},t)});return await Promise.race([this.#e.size(),n])!=="timeout"}}const jm="#F97111",Fm="#439CFE",Ko=.05,da=1-2*Ko,pa=.15;function Mm({i:e,j:t,spin:n}){return I.jsx("rect",{width:da,height:da,x:e+Ko,y:t+Ko,rx:pa,ry:pa,style:{fill:n===1?jm:Fm}})}function $m({svgSize:e,spins:t}){const n=t.length,r=String(n),l=[];for(let i=0;iArray.from(t,()=>Math.random()<.5?1:-1))}const bf=12,Im=.44,Am=120,Um=new Rm(bf);function Wm({svgSize:e,size:t,k:n}){const r=kt.useRef(Um),[l,i]=kt.useState(()=>Dm(t));return kt.useEffect(()=>{const u=setInterval(async()=>{for(;!await r.current.isReady();)console.log("Waiting for Worker...");await r.current.size()!==t&&await r.current.resize(t),await r.current.update(n),i(await r.current.spin())},1e3/Am);return()=>{clearInterval(u)}},[t,n]),I.jsx($m,{svgSize:e,spins:l})}function Vm({size:e,hook:t}){return I.jsxs("div",{className:ue`flex`,children:[I.jsx("label",{htmlFor:"L",className:ue`w-1/12 block`,children:"L"}),I.jsx("input",{type:"range",min:"2",max:"128",step:"1",value:e,className:ue`w-9/12 bg-[#439CFE]`,id:"L",onChange:t}),I.jsx("div",{className:ue`w-2/12 text-right`,children:e})]})}function Hm({k:e,hook:t}){return I.jsxs("div",{className:ue`flex`,children:[I.jsx("label",{htmlFor:"k",className:ue`w-1/12 block`,children:"K"}),I.jsx("input",{type:"range",min:"-1",max:"1",step:"any",value:e,className:ue`w-9/12`,id:"k",onChange:t}),I.jsx("div",{className:ue`w-2/12 text-right`,children:e.toFixed(3)})]})}function Bm(){const[e,t]=kt.useState(bf),[n,r]=kt.useState(Im);return I.jsx("div",{className:ue`w-10/12 mx-auto relative top-1/2 -translate-y-2/4`,children:I.jsxs("div",{className:ue`flex justify-between`,children:[I.jsx("div",{className:ue`w-5/12`,children:I.jsx(Wm,{svgSize:"100%",size:e,k:n})}),I.jsxs("div",{className:ue`w-1/2 flex flex-col justify-between`,children:[I.jsx("h1",{className:ue`text-2xl font-bold`,children:"2D Ising Model: WebAssembly"}),I.jsxs("div",{children:[I.jsxs("div",{className:ue`flex justify-evenly`,children:[I.jsx("img",{src:"/wasm.svg",id:"wasm-logo",className:ue`w-3/12`}),I.jsx("img",{src:"/react.svg",id:"react-logo",className:ue`w-3/12`})]}),I.jsx("h2",{className:ue`text-center text-xl mt-2`,children:"WebAssembly + React"})]}),I.jsxs("div",{children:[I.jsx(Vm,{size:e,hook:l=>{const i=Number.parseInt(l.target.value);t(i)}}),I.jsx(Hm,{k:n,hook:l=>{const i=Number.parseFloat(l.target.value);r(i)}})]})]})]})})}wm({theme:{fontFamily:{sans:["Zen Maru Gothic","sans-serif"]},extend:{}}});const ed=document.getElementById("root");if(ed===null)throw new Error("Root element not found");Yi.createRoot(ed).render(I.jsx(yd.StrictMode,{children:I.jsx(Bm,{})})); diff --git a/index.html b/index.html index 3d524f9..269ca15 100644 --- a/index.html +++ b/index.html @@ -15,8 +15,8 @@ rel="stylesheet" /> - - + +