@sheetxl/scripting 0.8.0-beta.1 → 0.8.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +5 -5
  2. package/browser/esm/4VkvY2rXOd49uHcQ.mjs +4 -0
  3. package/browser/esm/B73J41HhbJvswDz1.mjs +17 -0
  4. package/browser/esm/BPtHkO7z1Di3YIjV.mjs +162 -0
  5. package/browser/esm/B_2CC0NvNtPBw_ad.mjs +22 -0
  6. package/browser/esm/BxiAkxNyUQseLNBv.mjs +10 -0
  7. package/browser/esm/CV6NN6Ju5xBT1o6B.mjs +3955 -0
  8. package/browser/esm/Cg2-n5X_c3X8uPPp.mjs +581 -0
  9. package/browser/esm/D9jTpNifykCuQkTL.mjs +18 -0
  10. package/browser/esm/NpFv8YNKRgVPGXOq.mjs +9 -0
  11. package/browser/esm/_cUijEyyZifD_LZf.mjs +23 -0
  12. package/browser/esm/index.mjs +71 -41
  13. package/node/esm/4VkvY2rXOd49uHcQ.mjs +4 -0
  14. package/node/esm/ByvsA4Gi2N_jmjO4.mjs +161 -0
  15. package/node/esm/C8P-wHdBmweFS0Ex.mjs +20 -0
  16. package/node/esm/CLpM4kzEeZk_kWj4.mjs +23 -0
  17. package/node/esm/Cgbq_-KJhRYkRJw-.mjs +581 -0
  18. package/node/esm/ClxOMp6IdEZdW4Qd.mjs +8 -0
  19. package/node/esm/D0CDObJV23Rxk8-r.mjs +15 -0
  20. package/node/esm/index.mjs +83 -148
  21. package/node/esm/og3Pk2ReS3UiORbF.mjs +21 -0
  22. package/package.json +6 -7
  23. package/types/src/compiler/Bundler.d.ts +1 -1
  24. package/types/src/compiler/insertRunGuard.d.ts +11 -0
  25. package/types/src/lib/typescript/typescript.browser.d.ts +6 -0
  26. package/types/src/lib/typescript/typescript.node.d.ts +11 -0
  27. package/types/src/linter/Linter.d.ts +20 -0
  28. package/types/src/runtime/RunGuard.d.ts +31 -0
  29. package/types/src/runtime/index.d.ts +1 -0
  30. package/types/src/type/CompileOptions.d.ts +50 -0
  31. package/types/src/type/CompiledModule.d.ts +36 -6
  32. package/types/src/type/Diagnostic.d.ts +25 -3
  33. package/types/src/type/Types.d.ts +61 -5
  34. package/browser/cjs/BJpcKKDPQlQbi5O5.cjs +0 -7
  35. package/browser/cjs/Bu4cZ8iSZ3rij-oV.cjs +0 -1
  36. package/browser/cjs/BvG8N7G_8CXIAlT-.cjs +0 -1
  37. package/browser/cjs/CY8w1D0xPdaNysFJ.cjs +0 -1
  38. package/browser/cjs/C_7w8EJZpHw8ueuq.cjs +0 -1
  39. package/browser/cjs/C_IEgjM-hSJCv6Gm.cjs +0 -1
  40. package/browser/cjs/CctaCN_w3o34V9AR.cjs +0 -1
  41. package/browser/cjs/DIf4GvYEqb4ayb6a.cjs +0 -1
  42. package/browser/cjs/DcNeWEf5ZqALrCr4.cjs +0 -1
  43. package/browser/cjs/_PKWNtAymIZGtvCb.cjs +0 -21
  44. package/browser/cjs/index.cjs +0 -1
  45. package/browser/esm/1kUe1fPM50LHqYNI.mjs +0 -15
  46. package/browser/esm/3YV545IwjRqG3c1v.mjs +0 -27
  47. package/browser/esm/CFj5DZ16U361ltLj.mjs +0 -8
  48. package/browser/esm/CSXzDPdxAeONd9Br.mjs +0 -152
  49. package/browser/esm/DCIZplzRAR9pzoyD.mjs +0 -12
  50. package/browser/esm/DL0Hj5P777IybKK1.mjs +0 -25
  51. package/browser/esm/Dn3tZ47l4kfqm82M.mjs +0 -434
  52. package/browser/esm/Im_056DAe1M8tSZK.mjs +0 -23
  53. package/browser/esm/bJcM1PsEX9VZuqnT.mjs +0 -87
  54. package/browser/esm/v5FtHwExzUecgxho.mjs +0 -112
  55. package/node/esm/CFj5DZ16U361ltLj.mjs +0 -8
  56. package/node/esm/CL56uy8tfvhJRKYS.mjs +0 -434
  57. package/node/esm/CZgThiQ_9yYAaYaW.mjs +0 -152
  58. package/node/esm/DDDZ5Wv9-gK2v6Qt.mjs +0 -23
  59. package/node/esm/DEIcuGll5aCjPisP.mjs +0 -27
  60. package/node/esm/DOv0wuhb-kNvUT7-.mjs +0 -12
  61. package/node/esm/NgoqymNyfjBf3Vbn.mjs +0 -17
  62. package/node/esm/P5z0UPrc8__6uFCR.mjs +0 -14
package/README.md CHANGED
@@ -37,7 +37,7 @@ import { ScriptCompiler } from '@sheetxl/scripting';
37
37
  const { module, diagnostics } = await ScriptCompiler.compile({
38
38
  source: `
39
39
  /**
40
- * @summary Calculate compound interest
40
+ * Calculate compound interest
41
41
  */
42
42
  export function compoundInterest(
43
43
  principal: number,
@@ -71,14 +71,14 @@ const scripts = workbook.getScripts();
71
71
  const module = await scripts.createModule({
72
72
  source: `
73
73
  /**
74
- * @summary Double the value
74
+ * Double the value
75
75
  */
76
76
  export function DOUBLE(value: number): number {
77
77
  return value * 2;
78
78
  }
79
79
 
80
80
  /**
81
- * @summary Set active cell value
81
+ * Set active cell value
82
82
  */
83
83
  export function setCellValue(cell: ICell, value: any): void {
84
84
  cell.setValue(value);
@@ -126,7 +126,7 @@ Custom functions usable in spreadsheet formulas:
126
126
 
127
127
  Imperative operations that modify spreadsheet state:
128
128
 
129
- - Accept: `ICell`, `ICellRange`, `ISheet`, `IWorkbook`, scalars (via UI prompt)
129
+ - Accept: `ICell`, `ICellRange`, `IWorksheet`, `IWorkbook`, scalars (via UI prompt)
130
130
  - Return: `void`, `Promise<void>`, or cleanup function `() => void`
131
131
  - Invoked: Via UI menu, buttons, or as autorun on workbook load
132
132
  - Example: `export function formatHeader(range: ICellRange): void`
@@ -214,7 +214,7 @@ Platform detection is automatic via conditional exports.
214
214
  ## Examples & Templates
215
215
 
216
216
  Explore ready-to-use scripting templates at:
217
- **[github.com/sheetxl/scripting-templates](https://github.com/sheetxl/scripting-templates)**
217
+ **[github.com/sheetxl/templates-scripting](https://github.com/sheetxl/templates-scripting)**
218
218
 
219
219
  Templates include:
220
220
 
@@ -0,0 +1,4 @@
1
+ var a = "//# sourceMappingURL";
2
+ export {
3
+ a as t
4
+ };
@@ -0,0 +1,17 @@
1
+ var i = Object.freeze({ NoBody: "SXL1001", Anonymous: "SXL1002", ParseError: "SXL1003", InvalidParamType: "SXL2001", InvalidReturnType: "SXL2002", UndefinedInput: "SXL2003", MissingType: "SXL2004", UntypedArray: "SXL2005", GenericArity: "SXL2006", MultipleModifiers: "SXL2007", ContextNotFirst: "SXL2010", MultipleLambda: "SXL2020", LambdaNotLast: "SXL2021", LambdaScalarMismatch: "SXL2022", LambdaReturn: "SXL2023", FunctionReturn: "SXL2024", LambdaArity: "SXL2025", ArrayDepth: "SXL2030", RepeatingPosition: "SXL2040", MultipleRepeating: "SXL2041", RepeatingSlots: "SXL2042", RepeatingOptional: "SXL2043", RepeatingMax: "SXL2044", EnumMixed: "SXL2050", EnumMemberNotConstant: "SXL2051", EnumNotLocal: "SXL2052", EnumMissingAlias: "SXL2053", EnumPosition: "SXL2054", EnumOmittedValue: "SXL2055", NoExports: "SXL3001", UnknownParam: "SXL3002", BuiltInName: "SXL3003", UnknownReturnKind: "SXL3005", InvalidName: "SXL3006", DuplicateName: "SXL3007", MissingSummary: "SXL9001", MissingParamDescription: "SXL9002", MissingReturns: "SXL9003", EnumDuplicateValue: "SXL9004", EnumMemberUndocumented: "SXL9005" }), a = [{ name: "param", group: "jsdoc", description: "Document a parameter. A string union type becomes a dropdown of allowed options.", snippet: "param ${1:name} ${2:description}" }, { name: "returns", aliases: ["return"], group: "jsdoc", description: "Describe the return value." }, { name: "category", group: "sheetxl", description: "Group the function under a category in the function list.", snippet: "category ${1:name}" }, { name: "name", group: "sheetxl", description: "A name an identifier cannot spell: the name formulas call a function by (MY.FUNC), or an enum member's label.", snippet: "name ${1:NAME}" }, { name: "description", group: "sheetxl", description: "A longer description of the function." }, { name: "deprecated", group: "sheetxl", standalone: !0, description: "Mark the function as deprecated (optionally with a reason)." }, { name: "hidden", group: "sheetxl", standalone: !0, description: "Hide the function from the function list." }, { name: "returnkind", group: "sheetxl", description: "Declare the value kind of the return (a ValueKind word, e.g. `number`, `array`, `reference`) where the type spelling cannot say it (a union return collapses to any).", snippet: "returnKind ${1:number}" }, { name: "example", group: "jsdoc", description: "Provide a usage example." }, { name: "see", group: "jsdoc", description: "Reference a related function or link." }], r = (() => {
2
+ const n = /* @__PURE__ */ new Map();
3
+ for (const e of a) if (n.set(e.name, e), e.aliases) for (const t of e.aliases) n.set(t, e);
4
+ return n;
5
+ })();
6
+ function o(n) {
7
+ return (function(e) {
8
+ if (!e) return;
9
+ const t = (e.startsWith("@") ? e.slice(1) : e).toLowerCase();
10
+ return r.get(t);
11
+ })(n)?.standalone === !0;
12
+ }
13
+ export {
14
+ o as n,
15
+ i as r,
16
+ a as t
17
+ };
@@ -0,0 +1,162 @@
1
+ import { n as x } from "./BxiAkxNyUQseLNBv.mjs";
2
+ import { r as U } from "./B73J41HhbJvswDz1.mjs";
3
+ import { analyzeModule as V } from "./Cg2-n5X_c3X8uPPp.mjs";
4
+ import { t as I } from "./4VkvY2rXOd49uHcQ.mjs";
5
+ import { CommonUtils as X } from "@sheetxl/utils";
6
+ var f = null, w = null, q = { compilerOptions: { target: "esnext" } };
7
+ async function H(t, m, p = "/script.js", u = x, n = !1) {
8
+ try {
9
+ const d = await (async function() {
10
+ if (f) return f;
11
+ if (w) {
12
+ if (await w, !f) throw new Error("ESBuild initialization promise resolved, but instance is not available.");
13
+ return f;
14
+ }
15
+ let i, o;
16
+ w = new Promise((r, l) => {
17
+ i = r, o = l;
18
+ });
19
+ try {
20
+ const { initialize: r } = await import("./D9jTpNifykCuQkTL.mjs");
21
+ return f = await r(), i(), f;
22
+ } catch (r) {
23
+ throw console.error("Failed to import or initialize esbuild:", r), w = null, o(r), r;
24
+ }
25
+ })(), c = "@sheetxl/primitives", s = `
26
+ export const FormulaContext = globalThis.${u}?.FormulaContext;
27
+ export const ScalarType = globalThis.${u}?.ScalarType;
28
+ export const Observable = globalThis.${u}?.Observable;
29
+ export const IRange = globalThis.${u}?.IRange;
30
+ export const FormulaError = globalThis.${u}?.FormulaError;
31
+ // Add more exports as needed
32
+ `, a = await d.build({ entryPoints: [p], bundle: !0, write: !1, format: "esm", plugins: [{ name: "sheetxl-esbuild-in-memory", setup(i) {
33
+ const o = "sheetxl-" + (/* @__PURE__ */ new Date()).getTime();
34
+ i.onResolve({ filter: new RegExp(`^(${p.replace("/", "\\/")}|${c})$`) }, (r) => ({ path: r.path, namespace: o })), i.onResolve({ filter: /.*/ }, (r) => {
35
+ if (r.namespace !== o) return console.warn(`esbuild: Treating import "${r.path}" as external.`), { path: r.path, external: !0 };
36
+ }), i.onLoad({ filter: /.*/, namespace: o }, (r) => {
37
+ let l;
38
+ if (r.path === p) l = m;
39
+ else {
40
+ if (r.path !== c) return { errors: [{ text: `Cannot load unknown path in ${o}: ${r.path}` }] };
41
+ l = s;
42
+ }
43
+ return { contents: l, loader: "ts" };
44
+ });
45
+ } }], sourcemap: "inline", tsconfigRaw: q, minify: n, platform: "neutral" });
46
+ if (a.outputFiles && a.outputFiles.length > 0) return a.outputFiles[0].text;
47
+ throw a.errors && a.errors.length > 0 ? new Error(`esbuild bundling failed: ${a.errors.map((i) => i.text).join(`
48
+ `)}`) : new Error("esbuild did not produce an output file.");
49
+ } catch (d) {
50
+ throw console.error("esbuild bundling process failed:", d), d;
51
+ }
52
+ }
53
+ function Y(t, m, p) {
54
+ return (u) => {
55
+ const n = u.factory, d = () => n.createExpressionStatement(n.createCallChain(n.createPropertyAccessExpression(n.createIdentifier(x), "checkRun"), n.createToken(t.SyntaxKind.QuestionDotToken), void 0, [n.createStringLiteral(m), n.createNumericLiteral(p)])), c = (a) => {
56
+ const i = a.statements;
57
+ let o = 0;
58
+ for (; o < i.length && t.isExpressionStatement(i[o]) && t.isStringLiteral(i[o].expression); ) o++;
59
+ return n.updateBlock(a, [...i.slice(0, o), d(), ...i.slice(o)]);
60
+ }, s = (a) => {
61
+ if (((i) => t.isForStatement(i) || t.isForInStatement(i) || t.isForOfStatement(i) || t.isWhileStatement(i) || t.isDoStatement(i))(a)) {
62
+ const i = a.statement;
63
+ return t.visitEachChild(a, (o) => {
64
+ const r = s(o);
65
+ return o === i ? (l = r, t.isBlock(l) ? c(l) : n.createBlock([d(), l], !0)) : r;
66
+ var l;
67
+ }, u);
68
+ }
69
+ if (t.isFunctionLike(a) && a.body) {
70
+ const i = a.body;
71
+ return t.visitEachChild(a, (o) => {
72
+ const r = s(o);
73
+ return o === i ? (l = r, t.isBlock(l) ? c(l) : n.createBlock([d(), n.createReturnStatement(l)], !0)) : r;
74
+ var l;
75
+ }, u);
76
+ }
77
+ return t.visitEachChild(a, s, u);
78
+ };
79
+ return (a) => t.visitNode(a, s);
80
+ };
81
+ }
82
+ var Z = async () => `
83
+ interface FirstTest {
84
+ isTrue?: boolean;
85
+ }
86
+ `, v = null, L = "sheetxl.d.ts", N = "sheetxl-modules.d.ts", _ = ["lib.webworker.d.ts", "lib.es2020.d.ts", "lib.esnext.asynciterable.d.ts"], O = /* @__PURE__ */ new Map(), D = null, R = null;
87
+ async function ee() {
88
+ return R || (R = import("./B_2CC0NvNtPBw_ad.mjs").then(async (t) => {
89
+ const m = await j();
90
+ return t.readLibFile(m, "lib.es5.d.ts") !== void 0 ? t.readLibFile : null;
91
+ })), R;
92
+ }
93
+ async function j() {
94
+ if (v) return v;
95
+ try {
96
+ const t = await (await import("./B_2CC0NvNtPBw_ad.mjs")).initialize();
97
+ if (!t) throw new Error("TypeScript could not be loaded. Check your connection and try again.");
98
+ return t;
99
+ } catch (t) {
100
+ throw v = null, t;
101
+ } finally {
102
+ v = null;
103
+ }
104
+ }
105
+ async function le(t) {
106
+ const m = t?.source ?? null;
107
+ if (!m) return { module: null, diagnostics: [] };
108
+ const p = (t.disableBundle || t.declarationsOnly) ?? !1, [u, n, d] = await Promise.all([Z(), j(), t.ambientTypes ? ee() : null]), c = d ? t.ambientTypes ?? null : null;
109
+ let s = "";
110
+ const a = { allowJs: !0, declaration: !1, sourceMap: !1, inlineSourceMap: !1, inlineSources: !1, isolatedModules: !0, preserveConstEnums: !1, module: 99, noResolve: !0, emitDeclarationOnly: !1, target: n.ScriptTarget.ES2020, ...c ? { lib: _, skipLibCheck: !0, strict: !0 } : {} }, i = "script", o = `${i}.ts`, r = "lib.d.ts", l = "global.d.ts", g = { [o]: m, [r]: `
111
+ /**
112
+ * Represents the completion of an asynchronous operation
113
+ */
114
+ interface Promise<T> {
115
+ /**
116
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
117
+ * resolved value cannot be modified from the callback.
118
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
119
+ * @returns A Promise for the completion of the callback.
120
+ */
121
+ finally(onfinally?: (() => void) | undefined | null): Promise<T>;
122
+ }
123
+ `, [l]: u, ...c ? { [L]: c, [N]: `declare module '@sheetxl/primitives' { export = SheetXL; }
124
+ ` } : {} }, S = (e) => g[e] ?? (d && e.startsWith("lib.") ? d(n, e) : void 0), z = { getSourceFile: (e, $, te, ne) => {
125
+ if (e === L) return D?.text !== c && (D = { text: c, file: n.createSourceFile(e, c, n.ScriptTarget.Latest, !1) }), D.file;
126
+ if (g[e] === void 0) {
127
+ let y = O.get(e);
128
+ if (!y) {
129
+ const B = S(e);
130
+ if (B === void 0) return;
131
+ y = n.createSourceFile(e, B, n.ScriptTarget.Latest, !1), O.set(e, y);
132
+ }
133
+ return y;
134
+ }
135
+ return n.createSourceFile(e, g[e], n.ScriptTarget.Latest, !0);
136
+ }, fileExists: (e) => S(e) !== void 0, readFile: S, writeFile: (e, $) => {
137
+ g[e] = $;
138
+ }, getCurrentDirectory: () => "./", getCanonicalFileName: (e) => e, useCaseSensitiveFileNames: () => !0, getDefaultLibFileName: (e) => r, getNewLine: () => `
139
+ ` }, h = n.createProgram([o, l, ...c ? [L, N] : []], a, z), A = h.getTypeChecker(), T = h.getSourceFile(o), F = t.runGuard;
140
+ h.emit(void 0, void 0, void 0, void 0, F ? { before: [Y(n, F.key, F.timeoutMs)] } : void 0), s = g[`${i}.js`] ?? "";
141
+ const M = (e) => ({ start: e.start ?? 0, length: e.length ?? 0, severity: e.category === n.DiagnosticCategory.Warning ? "warning" : "error", code: `TS${e.code}`, message: n.flattenDiagnosticMessageText(e.messageText, `
142
+ `) }), W = h.getSyntacticDiagnostics(T).map(M), G = c ? h.getSemanticDiagnostics(T).filter((e) => e.category === n.DiagnosticCategory.Error || e.category === n.DiagnosticCategory.Warning).map(M) : [], k = V(n, T, A, { builtInNames: t.builtInNames, isBuiltIn: t.isBuiltIn, lenient: t.lenient });
143
+ let b = [...W, ...G, ...k.diagnostics];
144
+ t.lenient && (b = b.filter((e) => e.code !== U.MissingType));
145
+ const J = k.functions, P = k.autoRun, K = b.some((e) => e.severity === "error"), Q = `${X.uuidV4()}-script`;
146
+ let C = null;
147
+ if (K) s = "";
148
+ else {
149
+ try {
150
+ p || (s = await H(0, s, i, void 0, t.minify ?? !1));
151
+ } catch {
152
+ console.warn("Error bundling script");
153
+ }
154
+ const e = s.indexOf(I);
155
+ e > -1 && (C = s.substring(e + I.length + 1, s.length), s = s.substring(0, e), s = s.replaceAll("globalThis." + x, x));
156
+ }
157
+ const E = { functions: J, commitId: Q, source: m, language: "typescript", compiled: s };
158
+ return C && (E.sourceMap = C), P && (E.autoRun = P), { module: E, diagnostics: b };
159
+ }
160
+ export {
161
+ le as compileModule
162
+ };
@@ -0,0 +1,22 @@
1
+ var i = null;
2
+ async function t() {
3
+ return i || (i = new Promise(async (n, e) => {
4
+ let r = null;
5
+ try {
6
+ r = await import(
7
+ /* webpackIgnore: true */
8
+ /* @vite-ignore */
9
+ "https://esm.sh/typescript@5.7.2"
10
+ );
11
+ } catch (l) {
12
+ console.error("Error initializing Browser TypeScript module:", l);
13
+ }
14
+ r || (console.log("use script fallback"), i = null), n(r);
15
+ }));
16
+ }
17
+ function o(n, e) {
18
+ }
19
+ export {
20
+ t as initialize,
21
+ o as readLibFile
22
+ };
@@ -0,0 +1,10 @@
1
+ var a = Object.defineProperty, l = (r, o) => {
2
+ let e = {};
3
+ for (var t in r) a(e, t, { get: r[t], enumerable: !0 });
4
+ return o || a(e, Symbol.toStringTag, { value: "Module" }), e;
5
+ }, u = l({ GLOBAL_CONTEXT_VARIABLE: () => n }), n = "__SHEETXL";
6
+ export {
7
+ n,
8
+ l as r,
9
+ u as t
10
+ };