UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

263 lines (262 loc) 13.5 kB
import { t as ce, a4 as k } from "./Bf37sZn7h1jSr98w.mjs"; /** * @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. */ let v = null, M = null; const de = { compilerOptions: { target: "esnext" } }, ue = async () => ` interface FirstTest { isTrue?: boolean; } `, ee = /* @__PURE__ */ new Map([["IReferenceRange", "r"], ["IRange", "l"]]), te = /* @__PURE__ */ new Map([["IWorkbook", "workbook"], ["ISheet", "sheet"], ["ICellRanges", "ranges"], ["ICellRange", "range"], ["IFormulaContext", "context"]]), U = (b, T) => { Array.from(T.keys()).forEach((D) => { const A = T.get(D); T.set(`${b}.${D}`, A); }); }, pe = /* @__PURE__ */ new Map([["Scalar", "*"], ["FormulaError.Known", k.Error], ["Date", "Date"], ["JSON", "JSON"]]), me = /* @__PURE__ */ new Map([]), X = "SheetXL"; U(X, ee), U(X, te), U(X, me); const fe = /* @__PURE__ */ new Map([["Promise", () => ({ async: !0 })], ["Observable", () => ({ stream: !0 })]]); let j = null; async function ye() { if (j) return j; try { return await (await import("./BJCCAAJ6z2LxcOFd.mjs")).initialize(); } catch (b) { throw j = null, b; } finally { j = null; } } async function he(b) { const T = b?.source ?? null; if (!T) return null; const D = (b.disableBundle || b.declarationsOnly) ?? !1, A = [ue(), ye()], _ = await Promise.all(A), ne = _[0], n = _[1]; let N = "", I = null; const O = [], re = { allowJs: !0, declaration: !1, sourceMap: !1, inlineSourceMap: !1, inlineSources: !1, isolatedModules: !0, preserveConstEnums: !1, module: 99, noResolve: !0, emitDeclarationOnly: !1, target: n.ScriptTarget.ES2020 }, P = "script", B = `${P}.ts`, H = "lib.d.ts", W = "global.d.ts", F = { [B]: T, [H]: ` /** * Represents the completion of an asynchronous operation */ interface Promise<T> { /** * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The * resolved value cannot be modified from the callback. * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected). * @returns A Promise for the completion of the callback. */ finally(onfinally?: (() => void) | undefined | null): Promise<T>; } `, [W]: ne }, ie = { getSourceFile: (e, a, g, r) => n.createSourceFile(e, F[e], n.ScriptTarget.Latest, !0), fileExists: (e) => F[e] !== void 0, readFile: (e) => F[e], writeFile: (e, a) => { F[e] = a; }, getCurrentDirectory: () => "./", getCanonicalFileName: (e) => e, useCaseSensitiveFileNames: () => !0, getDefaultLibFileName: (e) => H, getNewLine: () => ` ` }, J = n.createProgram([B, W], re, ie), L = J.getTypeChecker(), ae = J.getSourceFile(B), G = J.emit(); G.diagnostics.length > 0 && console.warn(G.diagnostics), N = F[`${P}.js`]; const R = (e, a, g, r) => { if (e) { if (e.kind === n.SyntaxKind.NumberKeyword) a.scalar = k.Number; else if (e.kind === n.SyntaxKind.StringKeyword) a.scalar = k.String; else if (e.kind === n.SyntaxKind.BooleanKeyword) a.scalar = k.Boolean; else if (e.kind === n.SyntaxKind.UndefinedKeyword || e.kind === n.SyntaxKind.NullKeyword || e.kind === n.SyntaxKind.VoidKeyword) { if (r) return void h(e, new Error(`'undefined' is not a valid type for input: '${e?.parent?.name?.escapedText}'.`)); a.scalar = k.Null; } else if (e.kind === n.SyntaxKind.BigIntKeyword) a.scalar = k.Number; else if (e.kind === n.SyntaxKind.AnyKeyword) a.scalar = k.Null; else if (e.kind === n.SyntaxKind.ArrayType) { const i = e.elementType; if (!i) return void h(e, new Error(`'Array' must be typed: '${e?.parent?.name?.escapedText}'.`)); a.arrayDepth = (a.arrayDepth ?? 0) + 1, R(i, a, g, r); } else if (e.kind !== n.SyntaxKind.TupleType && e.kind === n.SyntaxKind.TypeReference) { const i = e.typeName?.getText?.() ?? null, f = ee.get(i); let m = !1; f && (a.range = f, m = !0); const x = pe.get(i); if (x && (a.scalar = x), x !== void 0 && (m = !0), r) { const c = te.get(i); if (c) return c; } else { const c = fe.get(i); if (c) { const o = { ...a, ...c() }; let t = 0; if (o.async && t++, o.stream && t++, t > 1) return void h(e, new Error(`'${i}' cannot have multiple modifiers: '${e?.parent?.name?.escapedText}'.`)); a = o, m = !0; } } if (!m) return void h("node", new Error(`'${i}' is not a valid type: '${e?.parent?.name?.escapedText}'.`)); const p = e.typeArguments; if (p) { if (p.length !== 1) return void h(e, new Error(`'${i}' must be typed with exactly 1 type: '${e?.parent?.name?.escapedText}'.`)); R(p[0], a, g, r); } } } else h(e, new Error(`Type is not defined for '${a?.name ?? "return"}'.`)); }, E = [], h = (e, a) => { E.push(a); }; if (n.forEachChild(ae, (e) => { if (g = e, (n.getCombinedModifierFlags(g) & n.ModifierFlags.Export) !== 0 && n.isFunctionDeclaration(e)) { const r = {}, i = { parameters: {} }, f = e?.name?.getText(); try { r.name = f; const m = L.getSymbolAtLocation(e.name).getDocumentationComment(L); if (m && m.length > 0 && m[0].text) { let o = m[0].text; o = o.replace(/[\r\n]+/g, "\\n").trim(), i.summary = o; } const x = {}; R(e.type, x, r, !1), r.returnType = x; const p = {}; a = e, (n.getCombinedModifierFlags(a) & n.ModifierFlags.Default) !== 0 && (p.default = !0, I = f), Object.keys(p).length > 0 && (r.behavior = p), r.parameters = []; const c = /* @__PURE__ */ new Map(); for (let o = 0; o < e.parameters.length; o++) { const t = e.parameters[o], s = {}; s.name = t.name?.getText(); const K = R(t.type, s, r, !0); if (K) { if (r.parameters.length !== 0) { const d = e?.parent, l = d?.name?.getText(); return void h(e, new Error(`'${r.name}' contexts must be the first parameter: '${l}'.`)); } r.context = K; continue; } let z; if ((t.initializer !== void 0 && t.initializer !== null || t.questionToken !== void 0 && t.questionToken !== null) && (s.optional = !0, t.initializer)) try { z = t.initializer.kind === n.SyntaxKind.StringLiteral ? t.initializer.text : t.initializer.kind === n.SyntaxKind.NumericLiteral ? parseFloat(t.initializer.text) : t.initializer.kind === n.SyntaxKind.TrueKeyword || t.initializer.kind === n.SyntaxKind.FalseKeyword ? t.initializer.kind === n.SyntaxKind.TrueKeyword : t.initializer.kind === n.SyntaxKind.NullKeyword ? null : t.initializer.kind === n.SyntaxKind.ObjectLiteralExpression || t.initializer.kind === n.SyntaxKind.ArrayLiteralExpression ? t.initializer.getText() : t.initializer.getText?.(); } catch (d) { console.warn(`Couldn't extract default value for parameter '${s.name}'`, d); } t.dotDotDotToken && (s.rest = !0), r.parameters.push(s); const S = { description: "" }; i.parameters[s.name] = S; const y = L.getSymbolAtLocation(t.name).getDocumentationComment(L); y && y.length > 0 && y[0].text && (S.description = y[0].text), z !== void 0 && (S.defaultValue = z), c.set(s.name, s); } if (e.jsDoc && e.jsDoc.length > 0) { const o = e.jsDoc, t = o.length; for (let s = 0; s < t; s++) { const K = o[s]?.tags; if (!K) continue; const z = K.length; for (let S = 0; S < z; S++) { const y = K[S]; let d = y?.tagName?.text; if (!d) continue; d = d.toLowerCase(); let l = y.comment; const Y = d === "hidden"; if ((typeof l == "string" || Y) && (typeof l == "string" && (l = l.replace(/[\r\n]+/g, "\\n").trim()), Y || !l || (l = l.split(/\\n/)[0], l && l.length !== 0))) { if (l && typeof l == "string") { const u = /\{@link(code|plain)?\s+([^}|]+)(?:\s*\|\s*([^}]+))?\}/g; let w, $ = l, C = []; for (; (w = u.exec(l)) !== null; ) { const [V, q, le, Z] = w, se = [le.trim()]; Z && se.push(Z.trim()); } l = $, C.length > 0 && d === "see" && (i.links || (i.links = []), i.links.push(...C)); } if (d === "name") { const u = l; u !== f && (i.name = u); } else if (d !== "description") { if (d === "summary") { const u = l; u && (i.summary = u); } else if (d === "param") { const u = y.name?.text, w = c.get(u); if (!w) { E.push(new Error(`Parameter '${u}' not found in function '${f}'.`)); continue; } if (y.typeExpression && y.typeExpression.type) try { const $ = y.typeExpression.type; if ($.kind === n.SyntaxKind.UnionType) { const C = []; w.enums = C, $.types.forEach((V) => { if (V.kind === n.SyntaxKind.LiteralType) { const q = V.literal.text; q && C.push(q); } }); } } catch ($) { console.warn("Error parsing JSDoc type expression:", $); } } else if (d === "returns" || d === "return") r.returnType.description = l; else if (d === "category") i.category = l; else if (d === "hidden") { let u = !0; const w = l?.toLowerCase(); w === "false" ? u = !1 : w !== "true" && (u = l), u !== !1 && (i.hidden = u ?? !0); } } } } } } Object.keys(r.returnType).length === 0 && delete r.returnType, O.push([r, i]); } catch (m) { h(e, new Error(`'${f}': ${m.message}`)); } } var a, g; }), E.length > 0) throw console.warn(E), new Error("There were compilation errors.", { cause: E }); if (O.length === 0) throw new Error("No exported functions."); const oe = `${ce.uuidV4()}-script`; try { D || E.length !== 0 || (N = await (async function(e, a, g = "/script.js", r = "__SHEETXL") { try { const i = await (async function() { if (v) return v; if (M) { if (await M, !v) throw new Error("ESBuild initialization promise resolved, but instance is not available."); return v; } let c, o; M = new Promise((t, s) => { c = t, o = s; }); try { const { initialize: t } = await import("./C_7bm0z3EAY_J-vT.mjs"); return v = await t(), c(), v; } catch (t) { throw console.error("Failed to import or initialize esbuild:", t), M = null, o(t), t; } })(), f = "@sheetxl/primitives", m = ` export const FormulaContext = globalThis.${r}?.FormulaContext; export const ScalarType = globalThis.${r}?.ScalarType; export const Observable = globalThis.${r}?.Observable; export const IRange = globalThis.${r}?.IRange; export const FormulaError = globalThis.${r}?.FormulaError; // Add more exports as needed `, x = { name: "sheetxl-esbuild-in-memory", setup(c) { const o = "sheetxl-" + (/* @__PURE__ */ new Date()).getTime(); c.onResolve({ filter: new RegExp(`^(${g.replace("/", "\\/")}|${f})$`) }, (t) => ({ path: t.path, namespace: o })), c.onResolve({ filter: /.*/ }, (t) => { if (t.namespace !== o) return console.warn(`esbuild: Treating import "${t.path}" as external.`), { path: t.path, external: !0 }; }), c.onLoad({ filter: /.*/, namespace: o }, (t) => { let s; if (t.path === g) s = a; else { if (t.path !== f) return { errors: [{ text: `Cannot load unknown path in ${o}: ${t.path}` }] }; s = m; } return { contents: s, loader: "ts" }; }); } }, p = await i.build({ entryPoints: [g], bundle: !0, write: !1, format: "esm", plugins: [x], sourcemap: "inline", tsconfigRaw: de, minify: !0, platform: "neutral" }); if (p.outputFiles && p.outputFiles.length > 0) return p.outputFiles[0].text; throw p.errors && p.errors.length > 0 ? new Error(`esbuild bundling failed: ${p.errors.map((c) => c.text).join(` `)}`) : new Error("esbuild did not produce an output file."); } catch (i) { throw console.error("esbuild bundling process failed:", i), i; } })(0, N, P)); } catch { console.warn("Error bundling script"); } const Q = { functions: O, commitId: oe, source: T, name: "Script", language: "typescript", compiled: N }; return I && (Q.autoRun = I), Q; } export { he as compileModule };