UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

13 lines (12 loc) 2.38 kB
"use strict";/** * @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.7.27 * * (C) 2025-present SheetXL Inc. & Michael T. Ford * License: The license can be found at https://www.sheetxl.com/license. */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("./Bc1oKNEzl3Kcj4g5.cjs");exports.readBufferSXL=async(p,l)=>{let u=p;(function(t){if(t.byteLength<4)return!1;const o=new Uint8Array(t),r={gzip:[31,139],zip:[80,75,3,4],bz2:[66,90,104],br:[206,178,207,129]},n=Object.keys(r);for(let a=0;a<n.length;a++){const i=n[a],e=r[i];let f=!0;for(let s=0;s<e.length;s++)if(o[s]!==e[s]){f=!1;break}if(f)return i}return!1})(u)&&(u=await(async function(t,o="gzip"){let r;typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer?(r=new ArrayBuffer(t.byteLength),new Uint8Array(r).set(new Uint8Array(t))):r=t;const n=new Blob([r]).stream(),a=new DecompressionStream(o),i=n.pipeThrough(a);return(await new Response(i).blob()).arrayBuffer()})(u));let b=new TextDecoder().decode(u);const g=JSON.parse(b),w={name:l?.name,...l?.createWorkbookOptions??{},json:g};return new J.by(w)},exports.writeBufferSXL=async(p,l)=>{const u=await p.toJSON(),b=l?.whiteSpace??0;let g;l?.beforeWrite?.(p,u),g=b===0?JSON.stringify(u):(function(o,r=2){const n=[];function a(i){const e=r*i;return n[e]===void 0&&(n[e]=" ".repeat(e)),n[e]}return(function i(e,f,s,m){if(e==null||typeof e!="object")return JSON.stringify(e);const A=a(f),B=a(f+1);if(Array.isArray(e)){const c=e.length;if(c===0)return"[]";if(s!==0)return JSON.stringify(e);let y=`[ `;for(let h=0;h<c;h++)y+=B+i(e[h],f+1,s+1,!0),h<c-1&&(y+=`, `);return y+=` `+A+"]",y}const O=Object.keys(e),d=O.length;if(d===0)return"{}";if(!(s<2))return JSON.stringify(e);let S=`{ `;m||(s=0);for(let c=0;c<d;c++){const y=O[c];S+=B+JSON.stringify(y)+": "+i(e[y],f+1,s,!1),c<d-1&&(S+=`, `)}return S+=` `+A+"}",S})(o,0,0,!1)})(u,b);let w=new TextEncoder().encode(g).buffer;const t=l?.compress??!0;return t&&(w=await(async function(o,r="gzip"){let n;typeof SharedArrayBuffer<"u"&&o instanceof SharedArrayBuffer?(n=new ArrayBuffer(o.byteLength),new Uint8Array(n).set(new Uint8Array(o))):n=o;const a=new ReadableStream({start(f){f.enqueue(n),f.close()}}),i=new CompressionStream(r),e=a.pipeThrough(i);return(await new Response(e).blob()).arrayBuffer()})(w,typeof t=="string"?t:void 0)),w};