mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-21 01:12:59 +00:00
4 lines
3.1 KiB
JavaScript
4 lines
3.1 KiB
JavaScript
import{M as A,N as _,O as p,P as k}from"./scheduler.CXEVs2ap.js";import{g as U,t as v,c as T,a as E}from"./index.CTdcniaS.js";import{d as x,c as C}from"./connection.wgaIHNYB.js";const D=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((d,h)=>{h!==a&&d&&(U(),v(d,1,1,()=>{e.blocks[h]===d&&(e.blocks[h]=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(A(t)){const s=_();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 O(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=C(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=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(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 F(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 N(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 P(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 F(await new Response(a).blob())}else throw new Error("Not implemented")}return e}async function S(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 N(c,e)).stream().pipeThrough(new DecompressionStream("deflate")),u=new Uint8Array(await new Response(l).arrayBuffer());a[o]=b(u)}}return a}export{S as a,P as c,D as g,V as h,O as u};
|
|
//# sourceMappingURL=share-url.D1X9O966.js.map
|