UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

261 lines (260 loc) 13.4 kB
import { aa as le, am as S } 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. */ let v = null, R = null; const se = { compilerOptions: { target: "esnext" } }, ce = async () => ` interface FirstTest { isTrue?: boolean; } `, Y = /* @__PURE__ */ new Map([["IReferenceRange", "r"], ["IRange", "l"]]), Z = /* @__PURE__ */ new Map([["IWorkbook", "workbook"], ["ISheet", "sheet"], ["ICellRanges", "ranges"], ["ICellRange", "range"], ["IFormulaContext", "context"]]), q = (b, T) => { Array.from(T.keys()).forEach((C) => { const j = T.get(C); T.set(`${b}.${C}`, j); }); }, de = /* @__PURE__ */ new Map([["Scalar", "*"], ["FormulaError.Known", S.Error], ["Date", "Date"], ["JSON", "JSON"]]), ue = /* @__PURE__ */ new Map([]), U = "SheetXL"; q(U, Y), q(U, Z), q(U, ue); const pe = /* @__PURE__ */ new Map([["Promise", () => ({ async: !0 })], ["Observable", () => ({ stream: !0 })]]); let M = null; async function me() { if (M) return M; try { return await (await import("./CQaO6ZEvkHw2gfXL.mjs")).initialize(); } catch (b) { throw M = null, b; } finally { M = null; } } async function ye(b) { const T = b?.source ?? null; if (!T) return null; const C = (b.disableBundle || b.declarationsOnly) ?? !1, j = [ce(), me()], X = await Promise.all(j), ee = X[0], n = X[1]; let D = "", A = null; const I = [], te = { allowJs: !0, declaration: !1, sourceMap: !1, inlineSourceMap: !1, inlineSources: !1, isolatedModules: !0, preserveConstEnums: !1, module: 99, noResolve: !0, emitDeclarationOnly: !1, target: n.ScriptTarget.ES2020 }, O = "script", P = `${O}.ts`, _ = "lib.d.ts", H = "global.d.ts", F = { [P]: T, [_]: ` /** * 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>; } `, [H]: ee }, ne = { getSourceFile: (e, a, y, 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) => _, getNewLine: () => ` ` }, B = n.createProgram([P, H], te, ne), N = B.getTypeChecker(), re = B.getSourceFile(P), W = B.emit(); W.diagnostics.length > 0 && console.warn(W.diagnostics), D = F[`${O}.js`]; const L = (e, a, y, r) => { if (e) { if (e.kind === n.SyntaxKind.NumberKeyword) a.scalar = S.Number; else if (e.kind === n.SyntaxKind.StringKeyword) a.scalar = S.String; else if (e.kind === n.SyntaxKind.BooleanKeyword) a.scalar = S.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 = S.Null; } else if (e.kind === n.SyntaxKind.BigIntKeyword) a.scalar = S.Number; else if (e.kind === n.SyntaxKind.AnyKeyword) a.scalar = S.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, L(i, a, y, r); } else if (e.kind !== n.SyntaxKind.TupleType && e.kind === n.SyntaxKind.TypeReference) { const i = e.typeName?.getText?.() ?? null, f = Y.get(i); let m = !1; f && (a.range = f, m = !0); const x = de.get(i); if (x && (a.scalar = x), x !== void 0 && (m = !0), r) { const c = Z.get(i); if (c) return c; } else { const c = pe.get(i); if (c) { const l = { ...a, ...c() }; let t = 0; if (l.async && t++, l.stream && t++, t > 1) return void h(e, new Error(`'${i}' cannot have multiple modifiers: '${e?.parent?.name?.escapedText}'.`)); a = l, 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}'.`)); L(p[0], a, y, r); } } } else h(e, new Error(`Type is not defined for '${a?.name ?? "return"}'.`)); }, k = [], h = (e, a) => { k.push(a); }; if (n.forEachChild(re, (e) => { if (y = e, (n.getCombinedModifierFlags(y) & n.ModifierFlags.Export) !== 0 && n.isFunctionDeclaration(e)) { const r = {}, i = { parameters: {} }, f = e?.name?.getText(); try { r.name = f; const m = N.getSymbolAtLocation(e.name).getDocumentationComment(N); if (m && m.length > 0 && m[0].text) { let l = m[0].text; l = l.replace(/[\r\n]+/g, "\\n").trim(), i.summary = l; } const x = {}; L(e.type, x, r, !1), r.returnType = x; const p = {}; a = e, (n.getCombinedModifierFlags(a) & n.ModifierFlags.Default) !== 0 && (p.default = !0, A = f), Object.keys(p).length > 0 && (r.behavior = p), r.parameters = []; const c = /* @__PURE__ */ new Map(); for (let l = 0; l < e.parameters.length; l++) { const t = e.parameters[l], s = {}; s.name = t.name?.getText(); const E = L(t.type, s, r, !0); if (E) { if (r.parameters.length !== 0) { const K = e?.parent, u = K?.name?.getText(); return void h(e, new Error(`'${r.name}' contexts must be the first parameter: '${u}'.`)); } r.context = E; continue; } let g; if ((t.initializer !== void 0 && t.initializer !== null || t.questionToken !== void 0 && t.questionToken !== null) && (s.optional = !0, t.initializer)) try { g = 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 (K) { console.warn(`Couldn't extract default value for parameter '${s.name}'`, K); } t.dotDotDotToken && (s.rest = !0), r.parameters.push(s); const d = { description: "" }; i.parameters[s.name] = d; const o = N.getSymbolAtLocation(t.name).getDocumentationComment(N); o && o.length > 0 && o[0].text && (d.description = o[0].text), g !== void 0 && (d.defaultValue = g), c.set(s.name, s); } if (e.jsDoc && e.jsDoc.length > 0) { const l = e.jsDoc; for (let t = 0; t < l.length; t++) { const s = l[t]?.tags; if (s) for (let E = 0; E < s.length; E++) { const g = s[E]; let d = g?.tagName?.text; if (!d) continue; d = d.toLowerCase(); let o = g.comment; const K = d === "hidden"; if ((typeof o == "string" || K) && (typeof o == "string" && (o = o.replace(/[\r\n]+/g, "\\n").trim()), K || !o || (o = o.split(/\\n/)[0], o && o.length !== 0))) { if (o && typeof o == "string") { const u = /\{@link(code|plain)?\s+([^}|]+)(?:\s*\|\s*([^}]+))?\}/g; let w, $ = o, z = []; for (; (w = u.exec(o)) !== null; ) { const [J, V, ae, Q] = w, oe = [ae.trim()]; Q && oe.push(Q.trim()); } o = $, z.length > 0 && d === "see" && (i.links || (i.links = []), i.links.push(...z)); } if (d === "name") { const u = o; u !== f && (i.name = u); } else if (d !== "description") { if (d === "summary") { const u = o; u && (i.summary = u); } else if (d === "param") { const u = g.name?.text, w = c.get(u); if (!w) { k.push(new Error(`Parameter '${u}' not found in function '${f}'.`)); continue; } if (g.typeExpression && g.typeExpression.type) try { const $ = g.typeExpression.type; if ($.kind === n.SyntaxKind.UnionType) { const z = []; w.enums = z, $.types.forEach((J) => { if (J.kind === n.SyntaxKind.LiteralType) { const V = J.literal.text; V && z.push(V); } }); } } catch ($) { console.warn("Error parsing JSDoc type expression:", $); } } else if (d === "returns" || d === "return") r.returnType.description = o; else if (d === "category") i.category = o; else if (d === "hidden") { let u = !0; const w = o?.toLowerCase(); w === "false" ? u = !1 : w !== "true" && (u = o), u !== !1 && (i.hidden = u ?? !0); } } } } } } Object.keys(r.returnType).length === 0 && delete r.returnType, I.push([r, i]); } catch (m) { h(e, new Error(`'${f}': ${m.message}`)); } } var a, y; }), k.length > 0) throw console.warn(k), new Error("There were compilation errors.", { cause: k }); if (I.length === 0) throw new Error("No exported functions."); const ie = `${le.uuidV4()}-script`; try { C || k.length !== 0 || (D = await async function(e, a, y = "/script.js", r = "__SHEETXL") { try { const i = await async function() { if (v) return v; if (R) { if (await R, !v) throw new Error("ESBuild initialization promise resolved, but instance is not available."); return v; } let c, l; R = new Promise((t, s) => { c = t, l = s; }); try { const { initialize: t } = await import("./BM0APYFIQHTGxxYF.mjs"); return v = await t(), c(), v; } catch (t) { throw console.error("Failed to import or initialize esbuild:", t), R = null, l(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 l = "sheetxl-" + (/* @__PURE__ */ new Date()).getTime(); c.onResolve({ filter: new RegExp(`^(${y.replace("/", "\\/")}|${f})$`) }, (t) => ({ path: t.path, namespace: l })), c.onResolve({ filter: /.*/ }, (t) => { if (t.namespace !== l) return console.warn(`esbuild: Treating import "${t.path}" as external.`), { path: t.path, external: !0 }; }), c.onLoad({ filter: /.*/, namespace: l }, (t) => { let s; if (t.path === y) s = a; else { if (t.path !== f) return { errors: [{ text: `Cannot load unknown path in ${l}: ${t.path}` }] }; s = m; } return { contents: s, loader: "ts" }; }); } }, p = await i.build({ entryPoints: [y], bundle: !0, write: !1, format: "esm", plugins: [x], sourcemap: "inline", tsconfigRaw: se, 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, D, O)); } catch { console.warn("Error bundling script"); } const G = { functions: I, commitId: ie, source: T, name: "Script", language: "typescript", compiled: D }; return A && (G.autoRun = A), G; } export { ye as compileModule };