@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
85 lines (84 loc) • 3.06 kB
JavaScript
import { af as J } from "./elB9a338Kjeh3S89.js";
/**
* @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.
*/
const k = 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(a) {
const e = r * a;
return n[e] === void 0 && (n[e] = " ".repeat(e)), n[e];
}
return (function a(e, i, s, O) {
if (e == null || typeof e != "object") return JSON.stringify(e);
const A = f(i), m = f(i + 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 += m + a(e[h], i + 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 = `{
`;
O || (s = 0);
for (let c = 0; c < d; c++) {
const y = B[c];
S += m + JSON.stringify(y) + ": " + a(e[y], i + 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(i) {
i.enqueue(n), i.close();
} }), a = new CompressionStream(r), e = f.pipeThrough(a);
return (await new Response(e).blob()).arrayBuffer();
})(p, typeof t == "string" ? t : void 0)), p;
}, z = 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 a = n[f], e = r[a];
let i = !0;
for (let s = 0; s < e.length; s++) if (o[s] !== e[s]) {
i = !1;
break;
}
if (i) return a;
}
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), a = n.pipeThrough(f);
return (await new Response(a).blob()).arrayBuffer();
})(u));
let b = new TextDecoder().decode(u);
const g = JSON.parse(b), p = { name: l?.name, ...l?.createWorkbookOptions ?? {}, json: g };
return new J(p);
};
export {
z as readBufferSXL,
k as writeBufferSXL
};