@sheetxl/scripting 0.4.20 → 0.4.21

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.
@@ -1,476 +0,0 @@
1
- import { e as he } from "./index.mjs";
2
- /**
3
- * @license @sheetxl/scripting - Scripting - Scripting engine for Macros and formulas; includes TypeScript and EsBuild. - v0.4.20
4
- *
5
- * (C) 2025-present SheetXL Inc. & Michael T. Ford
6
- * License: The license can be found at https://www.sheetxl.com/license.
7
- */
8
- const ie = "n", ge = "s", we = "b", Ce = "e", ae = "z";
9
- var se, q, r;
10
- (q = se || (se = {})).Orientation = { Column: "column", Row: "row" }, q.Orientations = { ...q.Orientation, Both: "both" }, q.Direction = { Up: "up", Down: "down", Left: "left", Right: "right" }, ((e) => {
11
- e.Code = { Parse: 0, Null: 1, Div0: 2, Value: 3, Ref: 4, Name: 5, Num: 6, NA: 7, GettingData: 8, Spill: 9, Connect: 10, Blocked: 11, Unknown: 12, Field: 13, Calc: 14, Busy: 16, Python: 19, Timeout: 20 }, e.Label = { Parse: "#PARSE!", Null: "#NULL!", Div0: "#DIV/0!", Value: "#VALUE!", Ref: "#REF!", Name: "#NAME?", Num: "#NUM!", NA: "#N/A", GettingData: "#GETTING_DATA", Spill: "#SPILL!", Connect: "#CONNECT!", Blocked: "#BLOCKED!", Unknown: "#UNKNOWN!", Field: "#FIELD!", Calc: "#CALC!", Busy: "#BUSY!", Python: "#PYTHON!", Timeout: "#TIMEOUT!" };
12
- class a extends Error {
13
- constructor(n, o, L, J) {
14
- super(L, J), this._label = o, this._code = n, this.details = J;
15
- }
16
- static {
17
- this.code = e.Code.Unknown;
18
- }
19
- get isFormulaError() {
20
- return !0;
21
- }
22
- getLabel() {
23
- return this._label;
24
- }
25
- getCode() {
26
- return this._code;
27
- }
28
- equals(n) {
29
- return !!n && (this._code === n._code || this._code === n.code);
30
- }
31
- get [Symbol.toStringTag]() {
32
- return "[FormulaError]";
33
- }
34
- toString() {
35
- return this.message || this._label;
36
- }
37
- }
38
- e.Known = a;
39
- class C extends a {
40
- constructor(n, o) {
41
- super(e.Code.Parse, e.Label.Parse, n, o);
42
- }
43
- static {
44
- this.code = e.Code.Parse;
45
- }
46
- getDetails() {
47
- const n = this.details;
48
- return { line: n?.line ?? 1, column: n?.column ?? 1, offset: n?.offset ?? 0, length: n?.length ?? 0 };
49
- }
50
- }
51
- e.Parse = C;
52
- class p extends a {
53
- constructor(n, o) {
54
- super(e.Code.Null, e.Label.Null, n, o);
55
- }
56
- static {
57
- this.code = e.Code.Null;
58
- }
59
- }
60
- e.Null = p;
61
- class F extends a {
62
- constructor(n, o) {
63
- super(e.Code.Div0, e.Label.Div0, n, o);
64
- }
65
- static {
66
- this.code = e.Code.Div0;
67
- }
68
- }
69
- e.Div0 = F;
70
- class R extends a {
71
- constructor(n, o) {
72
- super(e.Code.Value, e.Label.Value, n, o);
73
- }
74
- static {
75
- this.code = e.Code.Value;
76
- }
77
- }
78
- e.Value = R;
79
- class s extends a {
80
- constructor(n, o) {
81
- super(e.Code.Ref, e.Label.Ref, n, o);
82
- }
83
- static {
84
- this.code = e.Code.Ref;
85
- }
86
- }
87
- e.Ref = s;
88
- class K extends a {
89
- constructor(n, o) {
90
- super(e.Code.Name, e.Label.Name, n, o);
91
- }
92
- static {
93
- this.code = e.Code.Name;
94
- }
95
- }
96
- e.Name = K;
97
- class k extends a {
98
- constructor(n, o) {
99
- super(e.Code.Num, e.Label.Num, n, o);
100
- }
101
- static {
102
- this.code = e.Code.Num;
103
- }
104
- }
105
- e.Num = k;
106
- class b extends a {
107
- constructor(n, o) {
108
- super(e.Code.NA, e.Label.NA, n, o);
109
- }
110
- static {
111
- this.code = e.Code.NA;
112
- }
113
- }
114
- e.NA = b;
115
- class N extends a {
116
- constructor(n, o) {
117
- super(e.Code.GettingData, e.Label.GettingData, n, o);
118
- }
119
- static {
120
- this.code = e.Code.GettingData;
121
- }
122
- }
123
- e.GettingData = N;
124
- class d extends a {
125
- constructor(n, o) {
126
- super(e.Code.Spill, e.Label.Spill, n, o);
127
- }
128
- static {
129
- this.code = e.Code.Spill;
130
- }
131
- }
132
- e.Spill = d;
133
- class S extends a {
134
- constructor(n, o) {
135
- super(e.Code.Connect, e.Label.Connect, n, o);
136
- }
137
- static {
138
- this.code = e.Code.Connect;
139
- }
140
- }
141
- e.Connect = S;
142
- class G extends a {
143
- constructor(n, o) {
144
- super(e.Code.Blocked, e.Label.Blocked, n, o);
145
- }
146
- static {
147
- this.code = e.Code.Blocked;
148
- }
149
- }
150
- e.Blocked = G;
151
- class _ extends a {
152
- constructor(n, o) {
153
- super(e.Code.Unknown, e.Label.Unknown, n, o);
154
- }
155
- static {
156
- this.code = e.Code.Unknown;
157
- }
158
- }
159
- e.Unknown = _;
160
- class B extends a {
161
- constructor(n, o) {
162
- super(e.Code.Field, e.Label.Field, n, o);
163
- }
164
- static {
165
- this.code = e.Code.Field;
166
- }
167
- }
168
- e.Field = B;
169
- class X extends a {
170
- constructor(n, o) {
171
- super(e.Code.Calc, e.Label.Calc, n, o);
172
- }
173
- static {
174
- this.code = e.Code.Calc;
175
- }
176
- }
177
- e.Calc = X;
178
- class O extends a {
179
- constructor(n, o) {
180
- super(e.Code.Busy, e.Label.Busy, n, o);
181
- }
182
- static {
183
- this.code = e.Code.Busy;
184
- }
185
- }
186
- e.Busy = O;
187
- class A extends a {
188
- constructor(n, o) {
189
- super(e.Code.Python, e.Label.Python, n, o);
190
- }
191
- static {
192
- this.code = e.Code.Python;
193
- }
194
- }
195
- e.Python = A;
196
- class Y extends a {
197
- constructor(n, o) {
198
- super(e.Code.Timeout, e.Label.Timeout, n, o);
199
- }
200
- static {
201
- this.code = e.Code.Timeout;
202
- }
203
- }
204
- e.Timeout = Y;
205
- })(r || (r = {}));
206
- const f = {};
207
- f[r.Code.Parse] = r.Parse, f[r.Code.Null] = r.Null, f[r.Code.Div0] = r.Div0, f[r.Code.Value] = r.Value, f[r.Code.Ref] = r.Ref, f[r.Code.Name] = r.Name, f[r.Code.Num] = r.Num, f[r.Code.NA] = r.NA, f[r.Code.GettingData] = r.GettingData, f[r.Code.Spill] = r.Spill, f[r.Code.Connect] = r.Connect, f[r.Code.Blocked] = r.Blocked, f[r.Code.Unknown] = r.Unknown, f[r.Code.Field] = r.Field, f[r.Code.Calc] = r.Calc, f[r.Code.Busy] = r.Busy, f[r.Code.Python] = r.Python, f[r.Code.Timeout] = r.Timeout;
208
- const ce = /* @__PURE__ */ new Map(), ne = /* @__PURE__ */ new Map(), de = /* @__PURE__ */ new Map(), ue = /* @__PURE__ */ new Map(), le = Object.keys(f);
209
- for (let e = 0; e < le.length; e++) {
210
- const a = le[e], C = f[a];
211
- de.set(r.Label[a], C), ue.set(r.Code[a], C);
212
- const p = new C();
213
- ce.set(p.getLabel(), p), ne.set(p.getCode(), p);
214
- }
215
- const xe = ne.get(r.Code.Unknown);
216
- var u;
217
- (u = r || (r = {})).BuiltIn = { Parse: new u.Parse(), Null: new u.Null(), Div0: new u.Div0(), Value: new u.Value(), Ref: new u.Ref(), Name: new u.Name(), Num: new u.Num(), NA: new u.NA(), GettingData: new u.GettingData(), Spill: new u.Spill(), Connect: new u.Connect(), Blocked: new u.Blocked(), Unknown: new u.Unknown(), Field: new u.Field(), Calc: new u.Calc(), Busy: new u.Busy(), Python: new u.Python(), Timeout: new u.Timeout() }, u.getBuiltInByLabel = (e) => ce.get(e), u.newTypedError = (e, a, C) => {
218
- let p;
219
- return p = typeof e == "string" ? de.get(e) : ue.get(e), p || (p = u.Unknown), new p(a, C);
220
- }, u.getBuiltInById = (e) => ne.get(e) || xe;
221
- let I = null, H = null;
222
- const be = { compilerOptions: { target: "esnext" } };
223
- async function Te(e, a, C = "/script.js", p = "__SHEETXL") {
224
- try {
225
- const F = await async function() {
226
- if (I) return I;
227
- if (H) {
228
- if (await H, !I) throw new Error("ESBuild initialization promise resolved, but instance is not available.");
229
- return I;
230
- }
231
- let b, N;
232
- H = new Promise((d, S) => {
233
- b = d, N = S;
234
- });
235
- try {
236
- const { initialize: d } = await import("./B1020q1KSEfMetOp.mjs");
237
- return I = await d(), b(), I;
238
- } catch (d) {
239
- throw console.error("Failed to import or initialize esbuild:", d), H = null, N(d), d;
240
- }
241
- }(), R = "@sheetxl/primitives", s = `
242
- export const FormulaContext = globalThis.${p}?.FormulaContext;
243
- export const ScalarType = globalThis.${p}?.ScalarType;
244
- export const Observable = globalThis.${p}?.Observable;
245
- export const IRange = globalThis.${p}?.IRange;
246
- export const FormulaError = globalThis.${p}?.FormulaError;
247
- // Add more exports as needed
248
- `, K = { name: "sheetxl-esbuild-in-memory", setup(b) {
249
- const N = "sheetxl-" + (/* @__PURE__ */ new Date()).getTime();
250
- b.onResolve({ filter: new RegExp(`^(${C.replace("/", "\\/")}|${R})$`) }, (d) => ({ path: d.path, namespace: N })), b.onResolve({ filter: /.*/ }, (d) => {
251
- if (d.namespace !== N) return console.warn(`esbuild: Treating import "${d.path}" as external.`), { path: d.path, external: !0 };
252
- }), b.onLoad({ filter: /.*/, namespace: N }, (d) => {
253
- let S;
254
- if (d.path === C) S = a;
255
- else {
256
- if (d.path !== R) return { errors: [{ text: `Cannot load unknown path in ${N}: ${d.path}` }] };
257
- S = s;
258
- }
259
- return { contents: S, loader: "ts" };
260
- });
261
- } }, k = await F.build({ entryPoints: [C], bundle: !0, write: !1, format: "esm", plugins: [K], sourcemap: "inline", tsconfigRaw: be, minify: !0, platform: "neutral" });
262
- if (k.outputFiles && k.outputFiles.length > 0) return k.outputFiles[0].text;
263
- throw k.errors && k.errors.length > 0 ? new Error(`esbuild bundling failed: ${k.errors.map((b) => b.text).join(`
264
- `)}`) : new Error("esbuild did not produce an output file.");
265
- } catch (F) {
266
- throw console.error("esbuild bundling process failed:", F), F;
267
- }
268
- }
269
- const ke = async () => `
270
- interface FirstTest {
271
- isTrue?: boolean;
272
- }
273
- `, pe = /* @__PURE__ */ new Map([["IReferenceRange", "r"], ["IRange", "l"]]), me = /* @__PURE__ */ new Map([["IWorkbook", "workbook"], ["ISheet", "sheet"], ["ICellRanges", "ranges"], ["ICellRange", "range"], ["IFormulaContext", "context"]]), ee = (e, a) => {
274
- Array.from(a.keys()).forEach((C) => {
275
- const p = a.get(C);
276
- a.set(`${e}.${C}`, p);
277
- });
278
- }, Ne = /* @__PURE__ */ new Map([["Scalar", "*"], ["FormulaError.Known", Ce], ["Date", "Date"], ["JSON", "JSON"]]), Se = /* @__PURE__ */ new Map([]), te = "SheetXL";
279
- ee(te, pe), ee(te, me), ee(te, Se);
280
- const Ee = /* @__PURE__ */ new Map([["Promise", () => ({ async: !0 })], ["Observable", () => ({ stream: !0 })]]);
281
- let W = null;
282
- async function Le() {
283
- if (W) return W;
284
- try {
285
- return await (await import("./DmKkzjlUwfDMAhOe.mjs")).initialize();
286
- } catch (e) {
287
- throw W = null, e;
288
- } finally {
289
- W = null;
290
- }
291
- }
292
- async function ve(e) {
293
- const a = e?.source ?? null;
294
- if (!a) return null;
295
- const C = (e.disableBundle || e.declarationsOnly) ?? !1, p = [ke(), Le()], F = await Promise.all(p), R = F[0], s = F[1];
296
- let K = "", k = null;
297
- const b = [], N = { allowJs: !0, declaration: !1, sourceMap: !1, inlineSourceMap: !1, inlineSources: !1, isolatedModules: !0, preserveConstEnums: !1, module: 99, noResolve: !0, emitDeclarationOnly: !1, target: s.ScriptTarget.ES2020 }, d = "script", S = `${d}.ts`, G = "lib.d.ts", _ = "global.d.ts", B = { [S]: a, [G]: `
298
- /**
299
- * Represents the completion of an asynchronous operation
300
- */
301
- interface Promise<T> {
302
- /**
303
- * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
304
- * resolved value cannot be modified from the callback.
305
- * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
306
- * @returns A Promise for the completion of the callback.
307
- */
308
- finally(onfinally?: (() => void) | undefined | null): Promise<T>;
309
- }
310
- `, [_]: R }, X = { getSourceFile: (t, i, T, E) => s.createSourceFile(t, B[t], s.ScriptTarget.Latest, !0), fileExists: (t) => B[t] !== void 0, readFile: (t) => B[t], writeFile: (t, i) => {
311
- B[t] = i;
312
- }, getCurrentDirectory: () => "./", getCanonicalFileName: (t) => t, useCaseSensitiveFileNames: () => !0, getDefaultLibFileName: (t) => G, getNewLine: () => `
313
- ` }, O = s.createProgram([S, _], N, X), A = O.getTypeChecker(), Y = O.getSourceFile(S), m = O.emit();
314
- m.diagnostics.length > 0 && console.warn(m.diagnostics), K = B[`${d}.js`];
315
- const n = (t, i, T, E) => {
316
- if (t) {
317
- if (t.kind === s.SyntaxKind.NumberKeyword) i.scalar = ie;
318
- else if (t.kind === s.SyntaxKind.StringKeyword) i.scalar = ge;
319
- else if (t.kind === s.SyntaxKind.BooleanKeyword) i.scalar = we;
320
- else if (t.kind === s.SyntaxKind.UndefinedKeyword || t.kind === s.SyntaxKind.NullKeyword || t.kind === s.SyntaxKind.VoidKeyword) {
321
- if (E) return void L(t, new Error(`'undefined' is not a valid type for input: '${t?.parent?.name?.escapedText}'.`));
322
- i.scalar = ae;
323
- } else if (t.kind === s.SyntaxKind.BigIntKeyword) i.scalar = ie;
324
- else if (t.kind === s.SyntaxKind.AnyKeyword) i.scalar = ae;
325
- else if (t.kind === s.SyntaxKind.ArrayType) {
326
- const y = t.elementType;
327
- if (!y) return void L(t, new Error(`'Array' must be typed: '${t?.parent?.name?.escapedText}'.`));
328
- i.arrayDepth = (i.arrayDepth ?? 0) + 1, n(y, i, T, E);
329
- } else if (t.kind !== s.SyntaxKind.TupleType) {
330
- if (t.kind === s.SyntaxKind.TypeReference) {
331
- const y = t.typeName?.getText?.() ?? null, V = pe.get(y);
332
- let P = !1;
333
- V && (i.range = V, P = !0);
334
- const U = Ne.get(y);
335
- if (U && (i.scalar = U), U !== void 0 && (P = !0), E) {
336
- const l = me.get(y);
337
- if (l) return l;
338
- } else {
339
- const l = Ee.get(y);
340
- if (l) {
341
- const h = { ...i, ...l() };
342
- let D = 0;
343
- if (h.async && D++, h.stream && D++, D > 1) return void L(t, new Error(`'${y}' cannot have multiple modifiers: '${t?.parent?.name?.escapedText}'.`));
344
- i = h, P = !0;
345
- }
346
- }
347
- if (!P) return void L("node", new Error(`'${y}' is not a valid type: '${t?.parent?.name?.escapedText}'.`));
348
- const x = t.typeArguments;
349
- if (x) {
350
- if (x.length !== 1) return void L(t, new Error(`'${y}' must be typed with exactly 1 type: '${t?.parent?.name?.escapedText}'.`));
351
- n(x[0], i, T, E);
352
- }
353
- }
354
- }
355
- } else L(t, new Error(`Type is not defined for '${i?.name ?? "return"}'.`));
356
- }, o = [], L = (t, i) => {
357
- o.push(i);
358
- };
359
- if (s.forEachChild(Y, (t) => {
360
- if (((i) => (s.getCombinedModifierFlags(i) & s.ModifierFlags.Export) !== 0)(t) && s.isFunctionDeclaration(t)) {
361
- const i = {}, T = { parameters: {} }, E = t?.name?.getText();
362
- try {
363
- i.name = E;
364
- const y = A.getSymbolAtLocation(t.name).getDocumentationComment(A);
365
- if (y && y.length > 0 && y[0].text) {
366
- let x = y[0].text;
367
- x = x.replace(/[\r\n]+/g, "\\n").trim(), T.summary = x;
368
- }
369
- const V = {};
370
- n(t.type, V, i, !1), i.returnType = V;
371
- const P = {};
372
- ((x) => (s.getCombinedModifierFlags(x) & s.ModifierFlags.Default) !== 0)(t) && (P.default = !0, k = E), Object.keys(P).length > 0 && (i.behavior = P), i.parameters = [];
373
- const U = /* @__PURE__ */ new Map();
374
- for (let x = 0; x < t.parameters.length; x++) {
375
- const l = t.parameters[x], h = {};
376
- h.name = l.name?.getText();
377
- const D = n(l.type, h, i, !0);
378
- if (D) {
379
- if (i.parameters.length !== 0) {
380
- const M = t?.parent, w = M?.name?.getText();
381
- return void L(t, new Error(`'${i.name}' contexts must be the first parameter: '${w}'.`));
382
- }
383
- i.context = D;
384
- continue;
385
- }
386
- let v;
387
- if ((l.initializer !== void 0 && l.initializer !== null || l.questionToken !== void 0 && l.questionToken !== null) && (h.optional = !0, l.initializer)) try {
388
- v = l.initializer.kind === s.SyntaxKind.StringLiteral ? l.initializer.text : l.initializer.kind === s.SyntaxKind.NumericLiteral ? parseFloat(l.initializer.text) : l.initializer.kind === s.SyntaxKind.TrueKeyword || l.initializer.kind === s.SyntaxKind.FalseKeyword ? l.initializer.kind === s.SyntaxKind.TrueKeyword : l.initializer.kind === s.SyntaxKind.NullKeyword ? null : l.initializer.kind === s.SyntaxKind.ObjectLiteralExpression || l.initializer.kind === s.SyntaxKind.ArrayLiteralExpression ? l.initializer.getText() : l.initializer.getText?.();
389
- } catch (M) {
390
- console.warn(`Couldn't extract default value for parameter '${h.name}'`, M);
391
- }
392
- l.dotDotDotToken && (h.rest = !0), i.parameters.push(h);
393
- const g = { description: "" };
394
- T.parameters[h.name] = g;
395
- const c = A.getSymbolAtLocation(l.name).getDocumentationComment(A);
396
- c && c.length > 0 && c[0].text && (g.description = c[0].text), v !== void 0 && (g.defaultValue = v), U.set(h.name, h);
397
- }
398
- if (t.jsDoc && t.jsDoc.length > 0) {
399
- const x = t.jsDoc;
400
- for (let l = 0; l < x.length; l++) {
401
- const h = x[l]?.tags;
402
- if (h) for (let D = 0; D < h.length; D++) {
403
- const v = h[D];
404
- let g = v?.tagName?.text;
405
- if (!g) continue;
406
- g = g.toLowerCase();
407
- let c = v.comment;
408
- const M = g === "hidden";
409
- if ((typeof c == "string" || M) && (typeof c == "string" && (c = c.replace(/[\r\n]+/g, "\\n").trim()), M || !c || (c = c.split(/\\n/)[0], c && c.length !== 0))) {
410
- if (c && typeof c == "string") {
411
- const w = /\{@link(code|plain)?\s+([^}|]+)(?:\s*\|\s*([^}]+))?\}/g;
412
- let $, z = c, j = [];
413
- for (; ($ = w.exec(c)) !== null; ) {
414
- const [Q, Z, fe, re] = $, ye = [fe.trim()];
415
- re && ye.push(re.trim());
416
- }
417
- c = z, j.length > 0 && g === "see" && (T.links || (T.links = []), T.links.push(...j));
418
- }
419
- if (g === "name") {
420
- const w = c;
421
- w !== E && (T.name = w);
422
- } else if (g !== "description") {
423
- if (g === "summary") {
424
- const w = c;
425
- w && (T.summary = w);
426
- } else if (g === "param") {
427
- const w = v.name?.text, $ = U.get(w);
428
- if (!$) {
429
- o.push(new Error(`Parameter '${w}' not found in function '${E}'.`));
430
- continue;
431
- }
432
- if (v.typeExpression && v.typeExpression.type) try {
433
- const z = v.typeExpression.type;
434
- if (z.kind === s.SyntaxKind.UnionType) {
435
- const j = [];
436
- $.enums = j, z.types.forEach((Q) => {
437
- if (Q.kind === s.SyntaxKind.LiteralType) {
438
- const Z = Q.literal.text;
439
- Z && j.push(Z);
440
- }
441
- });
442
- }
443
- } catch (z) {
444
- console.warn("Error parsing JSDoc type expression:", z);
445
- }
446
- } else if (g === "returns" || g === "return") i.returnType.description = c;
447
- else if (g === "category") T.category = c;
448
- else if (g === "hidden") {
449
- let w = !0;
450
- const $ = c?.toLowerCase();
451
- $ === "false" ? w = !1 : $ !== "true" && (w = c), w !== !1 && (T.hidden = w ?? !0);
452
- }
453
- }
454
- }
455
- }
456
- }
457
- }
458
- Object.keys(i.returnType).length === 0 && delete i.returnType, b.push([i, T]);
459
- } catch (y) {
460
- L(t, new Error(`'${E}': ${y.message}`));
461
- }
462
- }
463
- }), o.length > 0) throw console.warn(o), new Error("There were compilation errors.", { cause: o });
464
- if (b.length === 0) throw new Error("No exported functions.");
465
- const J = `${he.uuidV4()}-script`;
466
- try {
467
- C || o.length !== 0 || (K = await Te(0, K, d));
468
- } catch {
469
- console.warn("Error bundling script");
470
- }
471
- const oe = { functions: b, commitId: J, source: a, name: "Script", language: "typescript", compiled: K };
472
- return k && (oe.autoRun = k), oe;
473
- }
474
- export {
475
- ve as compileModule
476
- };