UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

13 lines (12 loc) 2.36 kB
"use strict";/** * @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.6.4 * * (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("./Bd-US8M4eZh5SC26.cjs");exports.fromBufferJSON=async(w,l)=>{let u=w;(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 f=0;f<n.length;f++){const i=n[f],e=r[i];let a=!0;for(let s=0;s<e.length;s++)if(o[s]!==e[s]){a=!1;break}if(a)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(),f=new DecompressionStream(o),i=n.pipeThrough(f);return(await new Response(i).blob()).arrayBuffer()}(u));let b=new TextDecoder().decode(u);const g=JSON.parse(b),p={...l?.createWorkbookOptions??{},json:g};return new J.iy(p)},exports.toBufferJSON=async(w,l)=>{const u=await w.toJSON(),b=l?.whiteSpace??0;let g;l?.beforeWrite?.(w,u),g=b===0?JSON.stringify(u):function(o,r=2){const n=[];function f(i){const e=r*i;return n[e]===void 0&&(n[e]=" ".repeat(e)),n[e]}return function i(e,a,s,m){if(e==null||typeof e!="object")return JSON.stringify(e);const A=f(a),O=f(a+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+=O+i(e[h],a+1,s+1,!0),h<c-1&&(y+=`, `);return y+=` `+A+"]",y}const B=Object.keys(e),d=B.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=B[c];S+=O+JSON.stringify(y)+": "+i(e[y],a+1,s,!1),c<d-1&&(S+=`, `)}return S+=` `+A+"}",S}(o,0,0,!1)}(u,b);let p=new TextEncoder().encode(g).buffer;const t=l?.compress??!0;return t&&(p=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 f=new ReadableStream({start(a){a.enqueue(n),a.close()}}),i=new CompressionStream(r),e=f.pipeThrough(i);return(await new Response(e).blob()).arrayBuffer()}(p,typeof t=="string"?t:void 0)),p};