UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

85 lines (84 loc) 3.03 kB
import { az as J } from "./EFJ5klSL3OL5aq6z.mjs"; /** * @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. */ const z = 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(f, r = 2) { const n = []; function a(o) { const e = r * o; return n[e] === void 0 && (n[e] = " ".repeat(e)), n[e]; } return function o(e, i, s, m) { if (e == null || typeof e != "object") return JSON.stringify(e); const d = a(i), O = a(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 += O + o(e[h], i + 1, s + 1, !0), h < c - 1 && (y += `, `); return y += ` ` + d + "]", y; } const B = Object.keys(e), A = B.length; if (A === 0) return "{}"; if (!(s < 2)) return JSON.stringify(e); let S = `{ `; m || (s = 0); for (let c = 0; c < A; c++) { const y = B[c]; S += O + JSON.stringify(y) + ": " + o(e[y], i + 1, s, !1), c < A - 1 && (S += `, `); } return S += ` ` + d + "}", S; }(f, 0, 0, !1); }(u, b); let p = new TextEncoder().encode(g).buffer; const t = l?.compress ?? !0; return t && (p = await async function(f, r = "gzip") { let n; typeof SharedArrayBuffer < "u" && f instanceof SharedArrayBuffer ? (n = new ArrayBuffer(f.byteLength), new Uint8Array(n).set(new Uint8Array(f))) : n = f; const a = new ReadableStream({ start(i) { i.enqueue(n), i.close(); } }), o = new CompressionStream(r), e = a.pipeThrough(o); return (await new Response(e).blob()).arrayBuffer(); }(p, typeof t == "string" ? t : void 0)), p; }, k = async (w, l) => { let u = w; (function(t) { if (t.byteLength < 4) return !1; const f = 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 o = n[a], e = r[o]; let i = !0; for (let s = 0; s < e.length; s++) if (f[s] !== e[s]) { i = !1; break; } if (i) return o; } return !1; })(u) && (u = await async function(t, f = "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(f), o = n.pipeThrough(a); return (await new Response(o).blob()).arrayBuffer(); }(u)); let b = new TextDecoder().decode(u); const g = JSON.parse(b), p = { ...l?.createWorkbookOptions ?? {}, json: g }; return new J(p); }; export { k as fromBufferJSON, z as toBufferJSON };