mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-04-29 01:28:56 +00:00
4 lines
3.1 KiB
JavaScript
4 lines
3.1 KiB
JavaScript
import{_,$ as A,a0 as p,a1 as k}from"./scheduler.0b1efdfb.js";import{g as U,t as v,c as T,a as E}from"./index.432346bf.js";import{h as $,j as x}from"./connection.af08a73b.js";const N=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function V(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&&(U(),v(h,1,1,()=>{e.blocks[d]===h&&(e.blocks[d]=null)}),T())}):e.block.d(1),l.c(),E(l,1),l.m(e.mount(),e.anchor),u=!0),e.block=l,e.blocks&&(e.blocks[a]=l),u&&k()}if(_(t)){const s=A();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 S(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 y(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=x(t);return n.setUint32(0,r.length),w(e,r)}else{if(Array.isArray(t[0]))return n.setUint8(4,m.indexOf("array")),w(e,...t.map(y));throw new Error("Not implemented")}}function b(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++,s==="number"){const a=$(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(b(t,e));return a}else throw new Error("Not implemented")}function w(...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 C(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 F(t,e=window.fetch){return e(`data:application/octet-stream;base64,${t.replaceAll(".","+").replaceAll("_","/").replaceAll("-","=")}`).then(n=>n.blob())}const g={layout:[["layout","array"],["device","string"]],chords:[["chords","array"]],settings:[["settings","array"]]},m=["unknown","number","string","array"],f=`
|
|
`;async function z(t){let e=`${t.type}${f}${t.charaVersion}`;for(const[n,r]of g[t.type]){const s=t[n];if(e+=f,r==="string")e+=s;else if(r==="array"){const a=new Blob([y(s)]).stream().pipeThrough(new CompressionStream("deflate"));e+=await C(await new Response(a).blob())}else throw new Error("Not implemented")}return e}async function L(t,e=window.fetch){const[n,r,...s]=t.split(f),a={type:n,charaVersion:Number(r)};for(const[o,i]of g[n]){const c=s.shift();if(i==="string")a[o]=c;else if(i==="array"){const l=(await F(c,e)).stream().pipeThrough(new DecompressionStream("deflate")),u=new Uint8Array(await new Response(l).arrayBuffer());console.log(u),a[o]=b(u)}}return a}export{z as a,L as c,N as g,V as h,S as u};
|
|
//# sourceMappingURL=share-url.93504801.js.map
|