mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-20 08:52:59 +00:00
3 lines
3.2 KiB
JavaScript
3 lines
3.2 KiB
JavaScript
import{X as k,Y as U,Z as p,_ as v}from "./scheduler.f5cfe514.js";import{g as C,t as T,c as E,a as S}from "./index.c2fc59c9.js";import{h as x,j as F}from "./connection.5cd615cd.js";import{r as R,w as $}from "./index.c76aaf45.js";const O=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function P(t, e){const n=e.token={};function r(s, a, o, i){if(e.token!==n)return;e.resolved=i;let c=e.ctx;o!==void 0&&(c=c.slice(),c[o]=i);const l=s&&(e.current=s)(c);let u=!1;e.block&&(e.blocks?e.blocks.forEach((h, d)=>{d!==a&&h&&(C(),T(h,1,1,()=>{e.blocks[d]===h&&(e.blocks[d]=null)}),E())}):e.block.d(1),l.c(),S(l,1),l.m(e.mount(),e.anchor),u=!0),e.block=l,e.blocks&&(e.blocks[a]=l),u&&v()}if(k(t)){const s=U();if(t.then(a=>{p(s),r(e.then,1,e.value,a),p(null)}, a=>{if(p(s),r(e.catch,2,e.error,a),p(null),!e.hasCatch)throw a}),e.current!==e.pending)return r(e.pending,0),!0}else{if(e.current!==e.then)return r(e.then,1,e.value,t),!0;e.resolved=t}}function Y(t, e, n){const r=e.slice(),{resolved:s}=t;t.current===t.then&&(r[t.value]=s),t.current===t.catch&&(r[t.error]=s),t.block.p(r,n)}function g(t){let e=new Uint8Array(5);const n=new DataView(e.buffer);if(n.setUint32(0,t.length),t.length===0)return e;if(typeof t[0]=="number"){n.setUint8(4,m.indexOf("number"));const r=F(t);return n.setUint32(0,r.length),y(e,r)}else{if(Array.isArray(t[0]))return n.setUint8(4,m.indexOf("array")),y(e,...t.map(g));throw new Error("Not implemented")}}function _(t, e={pos:0}){const n=new DataView(t.buffer),r=n.getUint32(e.pos);e.pos+=4;const s=m[n.getUint8(e.pos)];if(e.pos++,console.log(e,t),s==="number"){const a=x(t.slice(e.pos,e.pos+r));return e.pos+=r,a}else if(s==="array"){const a=[];for(let o=0; o<r; o++)a.push(_(t,e));return a}else throw new Error("Not implemented")}function y(...t){const e=new Uint8Array(t.reduce((r, s)=>r+s.length,0));let n=0;for(const r of t)e.set(r,n),n+=r.length;return e}async function B(t){return new Promise(async e=>{const n=new FileReader;n.onloadend=function(){e(`${n.result.replace(/^data:application\/octet-stream;base64,/,"").replaceAll("+",".").replaceAll("/","_").replaceAll("=","-")}`)},n.readAsDataURL(t)})}async function D(t, e=window.fetch){return e(`data:application/octet-stream;base64,${t.replaceAll(".","+").replaceAll("_","/").replaceAll("-","=")}`).then(n=>n.blob())}const A={layout:[["layout","array"],["device","string"]],chords:[["chords","array"]],settings:[["settings","array"]]},m=["unknown","number","string","array"],f=`
|
|
`;async function j(t){let e=`${t.type}${f}${t.charaVersion}`;for(const[n,r]of A[t.type]){const s=t[n];if(e+=f,r==="string")e+=s;else if(r==="array"){const a=new Blob([g(s)]).stream().pipeThrough(new CompressionStream("deflate"));e+=await B(await new Response(a).blob())}else throw new Error("Not implemented")}return e}async function H(t,e=window.fetch){const[n,r,...s]=t.split(f),a={type:n,charaVersion:Number(r)};for(const[o,i]of A[n]){const c=s.shift();if(i==="string")a[o]=c;else if(i==="array"){const l=(await D(c,e)).stream().pipeThrough(new DecompressionStream("deflate")),u=new Uint8Array(await new Response(l).arrayBuffer());console.log(u),a[o]=_(u)}}return a}const w=$(!1),I=R(w);let b;function X(t){b?.(t)}const Z=(t,e)=>(w.set(!0),b=e,{destroy(){w.set(!1),b=void 0}});export{I as a,j as b,H as c,O as g,P as h,Z as s,X as t,Y as u};
|