@poe-platform/safe-bash 0.1.747 → 0.1.749

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.
@@ -97606,7 +97606,8 @@ var lookupSpecialForms = {
97606
97606
  if (!args.length || args.length > 4) return error("#VALUE!");
97607
97607
  let source = args[0];
97608
97608
  while (source.kind === "parentheses") source = source.child;
97609
- let value3 = host.evaluate(source, false);
97609
+ const areaSet = source.kind === "binary" && source.op === "union";
97610
+ let value3 = host.evaluate(source, areaSet);
97610
97611
  if (value3.kind === "error") return value3;
97611
97612
  const offsets = [0, 0, 0];
97612
97613
  for (let index2 = 1; index2 < args.length; index2++) {
@@ -97616,11 +97617,20 @@ var lookupSpecialForms = {
97616
97617
  if (n === void 0) return error("#VALUE!");
97617
97618
  offsets[index2 - 1] = Math.trunc(n) - 1;
97618
97619
  }
97619
- if (source.kind === "binary" && source.op === "union") {
97620
- if (value3.kind === "matrix") {
97621
- if (offsets[2] < 0 || offsets[2] >= value3.rows.length) return error("#REF!");
97622
- value3 = value3.rows[offsets[2]][0];
97623
- } else return error("#REF!");
97620
+ if (areaSet) {
97621
+ const areas = [], pending = [value3];
97622
+ while (pending.length) {
97623
+ host.tick();
97624
+ const area = pending.pop();
97625
+ if (area.kind === "set") for (let index2 = area.values.length - 1; index2 >= 0; index2--) pending.push(area.values[index2]);
97626
+ else areas.push(area);
97627
+ }
97628
+ if (offsets[2] < 0 || offsets[2] >= areas.length) return error("#REF!");
97629
+ value3 = areas[offsets[2]];
97630
+ if (value3.kind === "error") return value3;
97631
+ } else if (value3.kind === "range" && value3.sheets.length > 1) {
97632
+ if (offsets[2] < 0 || offsets[2] >= value3.sheets.length) return error("#REF!");
97633
+ value3 = { ...value3, sheets: [value3.sheets[offsets[2]]] };
97624
97634
  } else if (offsets[2] !== 0) return error("#REF!");
97625
97635
  const row = offsets[0], column = offsets[1], dims = dimensions(value3);
97626
97636
  if (row < 0 || column < 0 || row >= dims.height || column >= dims.width) return error("#REF!");
@@ -105512,6 +105522,68 @@ function createZipCodec(runtime = defaults, profile = {}) {
105512
105522
  }
105513
105523
  return { readZipArchive, decodeZipEntry, makeZipEntry, writeZipArchive };
105514
105524
  }
105525
+ function expandIndexSheetAreas(document6, onWork) {
105526
+ const order = document6.sheetOrder;
105527
+ if (!order) return document6;
105528
+ let ids, names2;
105529
+ const sheetIndex = (endpoint) => {
105530
+ if (!ids || !names2) {
105531
+ ids = /* @__PURE__ */ new Map();
105532
+ names2 = /* @__PURE__ */ new Map();
105533
+ for (let index2 = 0; index2 < order.length; index2++) {
105534
+ onWork();
105535
+ const id = order[index2];
105536
+ ids.set(id, index2);
105537
+ names2.set(foldSheetName(document6.sheetNames?.[id] ?? id), index2);
105538
+ }
105539
+ }
105540
+ const name = endpoint.sheet ?? document6.position.sheet;
105541
+ return ids.get(name) ?? names2.get(foldSheetName(name)) ?? -1;
105542
+ };
105543
+ const visit = (node3) => {
105544
+ onWork();
105545
+ if (node3.kind === "parentheses" || node3.kind === "unary") return { ...node3, child: visit(node3.child) };
105546
+ if (node3.kind === "binary") return { ...node3, left: visit(node3.left), right: visit(node3.right) };
105547
+ if (node3.kind === "array") return { ...node3, rows: node3.rows.map((row) => row.map(visit)) };
105548
+ if (node3.kind !== "call") return node3;
105549
+ const args = node3.args.map(visit);
105550
+ let source = args[0];
105551
+ while (source?.kind === "parentheses") source = source.child;
105552
+ if (node3.name === "INDEX" && args.length >= 1 && args.length <= 4 && source?.kind === "reference" && source.last && source.first.workbook === void 0 && source.last.workbook === void 0 && !source.label) {
105553
+ const first = sheetIndex(source.first), last = sheetIndex(source.last);
105554
+ if (first >= 0 && last >= 0 && first !== last) {
105555
+ let areas = [];
105556
+ for (let index2 = Math.min(first, last); index2 <= Math.max(first, last); index2++) {
105557
+ onWork();
105558
+ const sheet = document6.sheetNames?.[order[index2]] ?? order[index2];
105559
+ const first2 = { ...source.first, sheet };
105560
+ const last2 = { ...source.last, sheet };
105561
+ delete first2.sheetOffset;
105562
+ delete last2.sheetOffset;
105563
+ areas.push({ ...source, first: first2, last: last2 });
105564
+ }
105565
+ while (areas.length > 1) {
105566
+ const next = [];
105567
+ for (let index2 = 0; index2 < areas.length; index2 += 2) {
105568
+ onWork();
105569
+ next.push(areas[index2 + 1] ? {
105570
+ kind: "binary",
105571
+ op: "union",
105572
+ start: source.start,
105573
+ end: source.end,
105574
+ left: areas[index2],
105575
+ right: areas[index2 + 1]
105576
+ } : areas[index2]);
105577
+ }
105578
+ areas = next;
105579
+ }
105580
+ args[0] = { kind: "parentheses", start: source.start, end: source.end, child: areas[0] };
105581
+ }
105582
+ }
105583
+ return { ...node3, args };
105584
+ };
105585
+ return { ...document6, root: visit(document6.root) };
105586
+ }
105515
105587
  var xlsxNamespaceScanElements = /* @__PURE__ */ new Set([
105516
105588
  "worksheet",
105517
105589
  "extLst",
@@ -109386,7 +109458,7 @@ function createXlsxWriter(edition) {
109386
109458
  ...array ? { t: "array", ref: rangeText(array.range) } : {},
109387
109459
  ...formulaSemanticsAttributes(array?.arrayStringLiterals ?? cell.arrayStringLiterals, true, cell.formula)
109388
109460
  },
109389
- escapeXlsx(exportXlsxFormula(cell.formula, sheet, cell.row, cell.column, context, array?.arrayStringLiterals ?? cell.arrayStringLiterals))
109461
+ escapeXlsx(exportXlsxFormula(book, cell.formula, sheet, cell.row, cell.column, context, array?.arrayStringLiterals ?? cell.arrayStringLiterals))
109390
109462
  );
109391
109463
  if (value3.kind === "string") {
109392
109464
  if ((stringCounts.get(stringKey) ?? 0) > 1) {
@@ -109430,7 +109502,7 @@ function createXlsxWriter(edition) {
109430
109502
  };
109431
109503
  for (const [gnm, xlsx, invert] of [["DisplayFormulas", "showFormulas", false], ["HideZero", "showZeros", true], ["HideGrid", "showGridLines", true], ["HideColHeader", "showRowColHeaders", true], ["DisplayOutlines", "showOutlineSymbols", false], ["RTL_Layout", "rightToLeft", false]])
109432
109504
  if (view2[gnm] !== void 0) viewAttrs[xlsx] = (invert ? !Number(view2[gnm]) : !!Number(view2[gnm])) ? 1 : 0;
109433
- const metadata3 = await writeXlsxSheetMetadata(sheet, index2 + 1, xml2, context, namespace5, exportXlsxFormula, styles, charge);
109505
+ const metadata3 = await writeXlsxSheetMetadata(sheet, index2 + 1, xml2, context, namespace5, exportXlsxFormula.bind(null, book), styles, charge);
109434
109506
  let cols = "", nextColumn = 0;
109435
109507
  for (const c4 of [...sheet.columns ?? []].sort((a3, b3) => a3.index - b3.index)) {
109436
109508
  const importedColumn = metadataNode(c4.style?.gnumeric, charge);
@@ -109511,7 +109583,7 @@ function createXlsxWriter(edition) {
109511
109583
  localSheetId: index2 < 0 ? void 0 : index2,
109512
109584
  ...formulaSemanticsAttributes(name.arrayStringLiterals, true, name.expression, name.position ? { ...name.position, sheet: book.sheets.find((s) => s.id === name.position.sheet)?.name ?? name.position.sheet } : void 0)
109513
109585
  },
109514
- escapeXlsx(exportXlsxFormula(name.expression, sheet, name.position?.row ?? 0, name.position?.column ?? 0, context, name.arrayStringLiterals))
109586
+ escapeXlsx(exportXlsxFormula(book, name.expression, sheet, name.position?.row ?? 0, name.position?.column ?? 0, context, name.arrayStringLiterals))
109515
109587
  );
109516
109588
  }
109517
109589
  for (const [index2, sheet] of book.sheets.entries()) {
@@ -109588,17 +109660,24 @@ function createXlsxWriter(edition) {
109588
109660
  }
109589
109661
  };
109590
109662
  }
109591
- function exportXlsxFormula(source, sheet, row, column, context, arrayStringLiterals = false) {
109663
+ function exportXlsxFormula(book, source, sheet, row, column, context, arrayStringLiterals = false) {
109592
109664
  const position = { sheet: sheet.id, row, column };
109665
+ let work = 0;
109666
+ const onWork = () => {
109667
+ context.signal.throwIfAborted();
109668
+ if (++work > (context.limits.workbookNodes ?? Infinity))
109669
+ throw new SsconvertError("resource-limit", "ssconvert XLSX formula node limit exceeded");
109670
+ };
109593
109671
  const parsed = parseExpression(source.startsWith("=") || source.startsWith("of:=") ? source : "=" + source, {
109594
109672
  position,
109595
109673
  arrayStringLiterals,
109674
+ workbook: book,
109596
109675
  signal: context.signal,
109597
109676
  maximumLength: context.limits.workbookTextBytes ?? context.limits.outputBytes,
109598
109677
  maximumNodes: context.limits.workbookNodes ?? Infinity
109599
109678
  });
109600
109679
  if (!parsed.ok) throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: unparsed XLSX formula");
109601
- const result2 = serializeExpression(parsed.document, excelGrammar, false, true, { relativeSheets: "fixed" });
109680
+ const result2 = serializeExpression(expandIndexSheetAreas(parsed.document, onWork), excelGrammar, false, true, { relativeSheets: "fixed" });
109602
109681
  return result2.startsWith("=") ? result2.slice(1) : result2;
109603
109682
  }
109604
109683
  function invalidBiff(message) {
@@ -128223,8 +128302,8 @@ var operators = {
128223
128302
  ">=": 12,
128224
128303
  ">": 13,
128225
128304
  "<>": 14,
128226
- " ": 15,
128227
- ",": 16,
128305
+ intersection: 15,
128306
+ union: 16,
128228
128307
  ":": 17
128229
128308
  };
128230
128309
  var functions = new Map(Object.entries(biffFunctions).map(([id, spec]) => [spec[0], { id: Number(id), min: spec[1], max: spec[2] }]));
@@ -128368,7 +128447,12 @@ var BiffFormulaWriter = class {
128368
128447
  maximumLength: this.context.limits.workbookTextBytes ?? this.context.limits.outputBytes
128369
128448
  });
128370
128449
  if (!parsed.ok) throw new SsconvertError("unsupported-feature", `Cannot export Excel formula: ${expression2}`);
128371
- return parsed.document.root;
128450
+ let work = 0;
128451
+ return expandIndexSheetAreas(parsed.document, () => {
128452
+ this.context.signal.throwIfAborted();
128453
+ if (++work > (this.context.limits.workbookNodes ?? this.context.limits.cells))
128454
+ throw new SsconvertError("resource-limit", "ssconvert BIFF formula node limit exceeded");
128455
+ }).root;
128372
128456
  };
128373
128457
  const relative = definition !== void 0;
128374
128458
  const root = definition ? parseNamedExpression(definition, this.book, parse2, () => this.context.signal.throwIfAborted()) : parse2(source, { sheet, row, column });
@@ -140035,6 +140119,7 @@ function lotusExternalVariable(name) {
140035
140119
  async function lotusFormula(bytes, format2, group, row, column, sheetIndex, sheetName2, context, consumeOperation, functions2 = lotusFunctions, names2, legacyReferenceLayout) {
140036
140120
  const b3 = new Binary(bytes), stack = [], modern = format2 !== "wk1";
140037
140121
  const relativeReferences = /* @__PURE__ */ new Map();
140122
+ const indexRanges = /* @__PURE__ */ new Map();
140038
140123
  let at = 0;
140039
140124
  const pop = async () => {
140040
140125
  if (stack.length) return stack.pop();
@@ -140042,7 +140127,8 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
140042
140127
  return "#REF!";
140043
140128
  };
140044
140129
  const ref = (r, c4, rr, cr) => {
140045
- if (r < 0 || c4 < 0) return "#REF!";
140130
+ const rows = modern || legacyReferenceLayout === void 0 ? 65536 : legacyReferenceLayout === "wk1" ? 2048 : 16384;
140131
+ if (r < 0 || r >= rows || c4 < 0 || c4 >= 256) return "#REF!";
140046
140132
  const a3 = formatA1(r, c4);
140047
140133
  let i = 0;
140048
140134
  while (a3[i] >= "A" && a3[i] <= "Z") i++;
@@ -140052,13 +140138,13 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
140052
140138
  const c4 = b3.u16(p2), r = b3.u16(p2 + 2), cr = !!(c4 & 32768), rr = !!(r & 32768);
140053
140139
  if (legacyReferenceLayout === "works3" || legacyReferenceLayout === "symphony") {
140054
140140
  const axis = (raw, origin, bits) => {
140055
- if (!(raw & 32768)) return raw;
140141
+ if (!(raw & 32768)) return raw & (1 << bits) - 1;
140056
140142
  const shift = 32 - bits, boundary = 2 ** (bits - 1);
140057
140143
  let delta = raw << shift >> shift;
140058
140144
  if (delta + origin >= boundary) delta -= boundary;
140059
140145
  return origin + delta;
140060
140146
  };
140061
- let targetColumn = c4;
140147
+ let targetColumn = c4 & 255;
140062
140148
  if (legacyReferenceLayout === "symphony" && cr) {
140063
140149
  let delta = c4 & 255;
140064
140150
  if (delta & 128 && delta + column >= 256) delta -= 256;
@@ -140086,6 +140172,10 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
140086
140172
  const target = b3.u8(p2 + 2), name = sheetName2(target);
140087
140173
  return (target === sheetIndex && !qualifySheet ? "" : quoteFormulaString(name, "'", gnumericGrammar) + "!") + ref(b3.u16(p2), b3.u8(p2 + 3), !!(flags & 2), !!(flags & 1));
140088
140174
  };
140175
+ const rangeReference = (first, last) => {
140176
+ if (first.endsWith("#REF!") || last?.endsWith("#REF!")) return "#REF!";
140177
+ return first + (last === void 0 ? "" : ":" + last);
140178
+ };
140089
140179
  while (at < bytes.length) {
140090
140180
  context.signal.throwIfAborted();
140091
140181
  const op = b3.u8(at++);
@@ -140119,8 +140209,17 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
140119
140209
  const name = `LOTUS_SHEET_REFERENCE_${relativeReferences.size}`;
140120
140210
  relativeReferences.set(name, { kind: "reference", start: 0, end: 0, first, ...last ? { last } : {} });
140121
140211
  stack.push(name);
140122
- } else stack.push(newRef(at + 1, flags & 7, crossSheet) + (op === 2 ? `:${newRef(at + 5, flags >> 3 & 7, crossSheet)}` : ""));
140123
- } else stack.push(oldRef(at) + (op === 2 ? `:${oldRef(at + 4)}` : ""));
140212
+ } else {
140213
+ const source = rangeReference(newRef(at + 1, flags & 7, crossSheet), op === 2 ? newRef(at + 5, flags >> 3 & 7, crossSheet) : void 0);
140214
+ stack.push(source);
140215
+ if (crossSheet) indexRanges.set(source, {
140216
+ firstSheet: b3.u8(at + 3),
140217
+ lastSheet: b3.u8(at + 7),
140218
+ first: ref(b3.u16(at + 1), b3.u8(at + 4), !!(flags & 2), !!(flags & 1)),
140219
+ last: ref(b3.u16(at + 5), b3.u8(at + 8), !!(flags & 16), !!(flags & 8))
140220
+ });
140221
+ }
140222
+ } else stack.push(rangeReference(oldRef(at), op === 2 ? oldRef(at + 4) : void 0));
140124
140223
  at += length;
140125
140224
  } else if (op === 5) {
140126
140225
  const length = format2 === "123" ? 4 : 2;
@@ -140159,7 +140258,14 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
140159
140258
  const crossSheet = range3.first.sheet !== range3.last.sheet;
140160
140259
  const endpoint = (point) => (point.sheet === sheetIndex && !crossSheet ? "" : quoteFormulaString(sheetName2(point.sheet), "'", gnumericGrammar) + "!") + ref(point.row, point.column, op === 7, op === 7);
140161
140260
  const single = range3.first.row === range3.last.row && range3.first.column === range3.last.column && range3.first.sheet === range3.last.sheet;
140162
- stack.push(endpoint(range3.first) + (single ? "" : ":" + endpoint(range3.last)));
140261
+ const source = endpoint(range3.first) + (single ? "" : ":" + endpoint(range3.last));
140262
+ stack.push(source);
140263
+ if (crossSheet) indexRanges.set(source, {
140264
+ firstSheet: range3.first.sheet,
140265
+ lastSheet: range3.last.sheet,
140266
+ first: ref(range3.first.row, range3.first.column, op === 7, op === 7),
140267
+ last: ref(range3.last.row, range3.last.column, op === 7, op === 7)
140268
+ });
140163
140269
  }
140164
140270
  } else if (modern && op >= 9 && op <= 11) {
140165
140271
  const length = op === 9 ? 4 : op === 10 ? 5 : 11;
@@ -140203,7 +140309,7 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
140203
140309
  }
140204
140310
  const operands = [];
140205
140311
  for (let i = 0; i < args; i++) operands.unshift(await pop());
140206
- let subtract3 = 0;
140312
+ let subtract3 = info?.[3] === "wk1_year_func" ? 1900 : 0;
140207
140313
  if (functions2 === lotusFunctions) {
140208
140314
  switch (info?.[1]) {
140209
140315
  case "CHOOSE":
@@ -140221,19 +140327,36 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
140221
140327
  case "HLOOKUP":
140222
140328
  if (operands.length === 3) operands[2] = `(${operands[2]}+1)`;
140223
140329
  break;
140330
+ case "DSUM":
140331
+ case "DAVG":
140332
+ case "DCNT":
140333
+ case "DMIN":
140334
+ case "DMAX":
140335
+ case "DVAR":
140336
+ case "DSTD":
140337
+ case "DPURECOUNT":
140338
+ if (operands.length > 1) operands[1] = `(${operands[1]}+1)`;
140339
+ break;
140224
140340
  case "INDEX":
140225
- if (operands.length === 3) {
140341
+ if (operands.length === 3 || operands.length === 4) {
140226
140342
  const [, column2, row2] = operands;
140227
140343
  operands[1] = `(${row2}+1)`;
140228
140344
  operands[2] = `(${column2}+1)`;
140345
+ if (operands.length === 4) operands[3] = `(${operands[3]}+1)`;
140346
+ const span2 = indexRanges.get(operands[0]);
140347
+ if (span2) {
140348
+ const choices = [];
140349
+ for (let index2 = Math.min(span2.firstSheet, span2.lastSheet); index2 <= Math.max(span2.firstSheet, span2.lastSheet); index2++) {
140350
+ consumeOperation();
140351
+ choices.push(quoteFormulaString(sheetName2(index2), "'", gnumericGrammar) + "!" + span2.first + ":" + span2.last);
140352
+ }
140353
+ operands[0] = `(${choices.join(",")})`;
140354
+ }
140229
140355
  }
140230
140356
  break;
140231
140357
  case "STRING":
140232
140358
  operands.push("TRUE()");
140233
140359
  break;
140234
- case "YEAR":
140235
- subtract3 = 1900;
140236
- break;
140237
140360
  case "ROUNDUP":
140238
140361
  case "ROUNDDOWN":
140239
140362
  if (operands.length === 3) operands.pop();
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  YqValueFailure,
3
3
  createYqQuerySession
4
- } from "../safe-bash/command-chunks/chunk-6QU5OLPJ.js";
4
+ } from "../safe-bash/command-chunks/chunk-4AWKMIU3.js";
5
5
  import "../safe-bash/command-chunks/chunk-S3BO2NJT.js";
6
- import "../safe-bash/command-chunks/chunk-6742OVAC.js";
6
+ import "../safe-bash/command-chunks/chunk-WX5IUIQK.js";
7
7
  import "../safe-bash/command-chunks/chunk-TPDKSK66.js";
8
8
  import "../safe-bash/command-chunks/chunk-A7SJ2FC6.js";
9
9
  import "../safe-bash/command-chunks/chunk-XZ7QGZMG.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Interpreter
3
- } from "../safe-bash/command-chunks/chunk-6742OVAC.js";
3
+ } from "../safe-bash/command-chunks/chunk-WX5IUIQK.js";
4
4
  import "../safe-bash/command-chunks/chunk-TPDKSK66.js";
5
5
  import "../safe-bash/command-chunks/chunk-A7SJ2FC6.js";
6
6
  import "../safe-bash/command-chunks/chunk-XZ7QGZMG.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  YqValueFailure,
3
3
  createYqQuerySession
4
- } from "../safe-bash/command-chunks/chunk-6QU5OLPJ.js";
4
+ } from "../safe-bash/command-chunks/chunk-4AWKMIU3.js";
5
5
  import "../safe-bash/command-chunks/chunk-S3BO2NJT.js";
6
- import "../safe-bash/command-chunks/chunk-6742OVAC.js";
6
+ import "../safe-bash/command-chunks/chunk-WX5IUIQK.js";
7
7
  import "../safe-bash/command-chunks/chunk-TPDKSK66.js";
8
8
  import "../safe-bash/command-chunks/chunk-A7SJ2FC6.js";
9
9
  import "../safe-bash/command-chunks/chunk-XZ7QGZMG.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.747",
3
+ "version": "0.1.749",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -645,7 +645,7 @@
645
645
  "access": "public"
646
646
  },
647
647
  "dependencies": {
648
- "@poe-platform/safe-fs": "0.1.747",
648
+ "@poe-platform/safe-fs": "0.1.749",
649
649
  "pdf-lib": "1.17.1",
650
650
  "@types/node": "^25.2.2",
651
651
  "pako": "3.0.1",