@poe-platform/safe-bash 0.1.748 → 0.1.750

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.
@@ -97628,6 +97628,9 @@ var lookupSpecialForms = {
97628
97628
  if (offsets[2] < 0 || offsets[2] >= areas.length) return error("#REF!");
97629
97629
  value3 = areas[offsets[2]];
97630
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]]] };
97631
97634
  } else if (offsets[2] !== 0) return error("#REF!");
97632
97635
  const row = offsets[0], column = offsets[1], dims = dimensions(value3);
97633
97636
  if (row < 0 || column < 0 || row >= dims.height || column >= dims.width) return error("#REF!");
@@ -105519,6 +105522,68 @@ function createZipCodec(runtime = defaults, profile = {}) {
105519
105522
  }
105520
105523
  return { readZipArchive, decodeZipEntry, makeZipEntry, writeZipArchive };
105521
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
+ }
105522
105587
  var xlsxNamespaceScanElements = /* @__PURE__ */ new Set([
105523
105588
  "worksheet",
105524
105589
  "extLst",
@@ -109393,7 +109458,7 @@ function createXlsxWriter(edition) {
109393
109458
  ...array ? { t: "array", ref: rangeText(array.range) } : {},
109394
109459
  ...formulaSemanticsAttributes(array?.arrayStringLiterals ?? cell.arrayStringLiterals, true, cell.formula)
109395
109460
  },
109396
- 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))
109397
109462
  );
109398
109463
  if (value3.kind === "string") {
109399
109464
  if ((stringCounts.get(stringKey) ?? 0) > 1) {
@@ -109437,7 +109502,7 @@ function createXlsxWriter(edition) {
109437
109502
  };
109438
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]])
109439
109504
  if (view2[gnm] !== void 0) viewAttrs[xlsx] = (invert ? !Number(view2[gnm]) : !!Number(view2[gnm])) ? 1 : 0;
109440
- 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);
109441
109506
  let cols = "", nextColumn = 0;
109442
109507
  for (const c4 of [...sheet.columns ?? []].sort((a3, b3) => a3.index - b3.index)) {
109443
109508
  const importedColumn = metadataNode(c4.style?.gnumeric, charge);
@@ -109518,7 +109583,7 @@ function createXlsxWriter(edition) {
109518
109583
  localSheetId: index2 < 0 ? void 0 : index2,
109519
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)
109520
109585
  },
109521
- 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))
109522
109587
  );
109523
109588
  }
109524
109589
  for (const [index2, sheet] of book.sheets.entries()) {
@@ -109595,17 +109660,24 @@ function createXlsxWriter(edition) {
109595
109660
  }
109596
109661
  };
109597
109662
  }
109598
- function exportXlsxFormula(source, sheet, row, column, context, arrayStringLiterals = false) {
109663
+ function exportXlsxFormula(book, source, sheet, row, column, context, arrayStringLiterals = false) {
109599
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
+ };
109600
109671
  const parsed = parseExpression(source.startsWith("=") || source.startsWith("of:=") ? source : "=" + source, {
109601
109672
  position,
109602
109673
  arrayStringLiterals,
109674
+ workbook: book,
109603
109675
  signal: context.signal,
109604
109676
  maximumLength: context.limits.workbookTextBytes ?? context.limits.outputBytes,
109605
109677
  maximumNodes: context.limits.workbookNodes ?? Infinity
109606
109678
  });
109607
109679
  if (!parsed.ok) throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: unparsed XLSX formula");
109608
- const result2 = serializeExpression(parsed.document, excelGrammar, false, true, { relativeSheets: "fixed" });
109680
+ const result2 = serializeExpression(expandIndexSheetAreas(parsed.document, onWork), excelGrammar, false, true, { relativeSheets: "fixed" });
109609
109681
  return result2.startsWith("=") ? result2.slice(1) : result2;
109610
109682
  }
109611
109683
  function invalidBiff(message) {
@@ -116165,6 +116237,40 @@ var BiffOutput = class {
116165
116237
  this.length += bytes.length;
116166
116238
  return at;
116167
116239
  }
116240
+ /** Keep tokens/elements intact; oversized UTF-16 array strings carry width flags. */
116241
+ continuedRecord(opcode, payload, boundaries, strings = []) {
116242
+ const at = this.length;
116243
+ let offset = 0, next = 0, stringIndex = 0;
116244
+ do {
116245
+ while (strings[stringIndex] && strings[stringIndex].end <= offset) stringIndex++;
116246
+ const continuedString = strings[stringIndex] && strings[stringIndex].start < offset;
116247
+ const prefix = continuedString ? 1 : 0;
116248
+ const maximum = Math.min(payload.length, offset + this.maximumRecord - prefix);
116249
+ let end2 = maximum;
116250
+ if (boundaries && maximum < payload.length) {
116251
+ end2 = offset;
116252
+ while (next < boundaries.length && boundaries[next] <= maximum) end2 = boundaries[next++];
116253
+ let candidate = stringIndex;
116254
+ while (strings[candidate] && strings[candidate].end <= maximum) candidate++;
116255
+ const string = strings[candidate];
116256
+ if (string && string.end - string.start + 4 > this.maximumRecord && string.start < maximum && maximum < string.end) {
116257
+ const characterEnd = maximum - (maximum - string.start) % 2;
116258
+ if (characterEnd > string.start) end2 = Math.max(end2, characterEnd);
116259
+ }
116260
+ if (end2 <= offset) throw new SsconvertError("unsupported-feature", "Excel BIFF formula token is too large");
116261
+ }
116262
+ let part = payload.subarray(offset, end2);
116263
+ if (prefix) {
116264
+ const continued = new Uint8Array(part.length + 1);
116265
+ continued[0] = 1;
116266
+ continued.set(part, 1);
116267
+ part = continued;
116268
+ }
116269
+ this.record(offset === 0 ? opcode : 60, part);
116270
+ offset = end2;
116271
+ } while (offset < payload.length);
116272
+ return at;
116273
+ }
116168
116274
  finish() {
116169
116275
  this.context.signal.throwIfAborted();
116170
116276
  const bytes = new Uint8Array(this.length);
@@ -128230,8 +128336,8 @@ var operators = {
128230
128336
  ">=": 12,
128231
128337
  ">": 13,
128232
128338
  "<>": 14,
128233
- " ": 15,
128234
- ",": 16,
128339
+ intersection: 15,
128340
+ union: 16,
128235
128341
  ":": 17
128236
128342
  };
128237
128343
  var functions = new Map(Object.entries(biffFunctions).map(([id, spec]) => [spec[0], { id: Number(id), min: spec[1], max: spec[2] }]));
@@ -128264,7 +128370,6 @@ var BiffFormulaWriter = class {
128264
128370
  macroNames = [];
128265
128371
  workbookIndices = /* @__PURE__ */ new Map();
128266
128372
  linkIndices = /* @__PURE__ */ new Map();
128267
- uniqueNameId = 0;
128268
128373
  relocations = [];
128269
128374
  externalBook(workbook) {
128270
128375
  let index2 = this.workbookIndices.get(workbook);
@@ -128375,11 +128480,21 @@ var BiffFormulaWriter = class {
128375
128480
  maximumLength: this.context.limits.workbookTextBytes ?? this.context.limits.outputBytes
128376
128481
  });
128377
128482
  if (!parsed.ok) throw new SsconvertError("unsupported-feature", `Cannot export Excel formula: ${expression2}`);
128378
- return parsed.document.root;
128483
+ let work = 0;
128484
+ return expandIndexSheetAreas(parsed.document, () => {
128485
+ this.context.signal.throwIfAborted();
128486
+ if (++work > (this.context.limits.workbookNodes ?? this.context.limits.cells))
128487
+ throw new SsconvertError("resource-limit", "ssconvert BIFF formula node limit exceeded");
128488
+ }).root;
128379
128489
  };
128380
128490
  const relative = definition !== void 0;
128381
128491
  const root = definition ? parseNamedExpression(definition, this.book, parse2, () => this.context.signal.throwIfAborted()) : parse2(source, { sheet, row, column });
128382
128492
  const bytes = [], arrays = [], diagnostics = [];
128493
+ const tokenBoundaries = [], arrayBoundaries = [];
128494
+ const arrayStrings = [];
128495
+ const boundary = () => {
128496
+ if (bytes.length && tokenBoundaries.at(-1) !== bytes.length) tokenBoundaries.push(bytes.length);
128497
+ };
128383
128498
  let sheetLossReported = false;
128384
128499
  const relocations = [];
128385
128500
  const push = (part, target = bytes) => {
@@ -128422,12 +128537,14 @@ var BiffFormulaWriter = class {
128422
128537
  push([23]);
128423
128538
  push(biffString(text2, this.revision, this.context, 1));
128424
128539
  if (index2) push([8]);
128540
+ boundary();
128425
128541
  });
128426
128542
  if (chunks.length > 1) push([21]);
128427
128543
  }
128428
128544
  };
128429
128545
  const visit = (node3) => {
128430
128546
  this.context.signal.throwIfAborted();
128547
+ boundary();
128431
128548
  if (node3.kind === "literal") literal2(node3.value);
128432
128549
  else if (node3.kind === "omitted") push([22]);
128433
128550
  else if (node3.kind === "parentheses") {
@@ -128580,24 +128697,15 @@ var BiffFormulaWriter = class {
128580
128697
  push([28, 29]);
128581
128698
  return;
128582
128699
  }
128583
- if (node3.sheet !== void 0 && scope !== void 0) {
128584
- const data3 = new Uint8Array(this.revision === 8 ? 7 : 25), view2 = new DataView(data3.buffer);
128700
+ if (node3.sheet !== void 0 && scope !== void 0 && this.revision === 8) {
128701
+ const data3 = new Uint8Array(7), view2 = new DataView(data3.buffer);
128585
128702
  data3[0] = 89;
128586
128703
  const scopeIndex = this.book.sheets.indexOf(scope);
128587
- if (this.revision === 8) {
128588
- const externalIndex = this.sheetLink(void 0, scopeIndex, scopeIndex);
128589
- relocations.push({ offset: bytes.length + 1, index: externalIndex, kind: "sheet" });
128590
- view2.setUint16(1, externalIndex, true);
128591
- view2.setUint16(3, index2 + 1, true);
128592
- } else {
128593
- const externalIndex = current === scope ? this.book.sheets.length + 1 : scopeIndex;
128594
- view2.setInt16(1, -(externalIndex + 1), true);
128595
- view2.setUint16(9, 1, true);
128596
- view2.setUint16(11, index2 + 1, true);
128597
- view2.setUint16(19, 15, true);
128598
- view2.setUint32(21, ++this.uniqueNameId, true);
128599
- }
128600
- relocations.push({ offset: bytes.length + (this.revision === 8 ? 3 : 11), index: index2, kind: "name" });
128704
+ const externalIndex = this.sheetLink(void 0, scopeIndex, scopeIndex);
128705
+ relocations.push({ offset: bytes.length + 1, index: externalIndex, kind: "sheet" });
128706
+ view2.setUint16(1, externalIndex, true);
128707
+ view2.setUint16(3, index2 + 1, true);
128708
+ relocations.push({ offset: bytes.length + 3, index: index2, kind: "name" });
128601
128709
  push(data3);
128602
128710
  } else {
128603
128711
  const data3 = new Uint8Array(this.revision === 8 ? 5 : 15);
@@ -128655,12 +128763,15 @@ var BiffFormulaWriter = class {
128655
128763
  if (!columns || columns > 256 || node3.rows.length > 65536) throw new SsconvertError("unsupported-feature", "Excel BIFF array dimensions exceed limits");
128656
128764
  push([64, ...new Uint8Array(7)]);
128657
128765
  push([this.revision === 8 ? columns - 1 : columns & 255, ...words(node3.rows.length - (this.revision === 8 ? 1 : 0))], arrays);
128766
+ arrayBoundaries.push(arrays.length);
128658
128767
  for (const arrayRow of node3.rows) for (const item of arrayRow) {
128659
128768
  if (item.kind !== "literal") throw new SsconvertError("unsupported-feature", "Excel BIFF array requires literals");
128660
128769
  const value3 = item.value;
128661
128770
  if (value3.kind === "string") {
128771
+ const start = arrays.length + 4;
128662
128772
  push([2], arrays);
128663
128773
  push(biffString(value3.value, this.revision, this.context, this.revision === 8 ? 2 : 1), arrays);
128774
+ if (this.revision === 8 && arrays.length > start) arrayStrings.push({ start, end: arrays.length });
128664
128775
  } else {
128665
128776
  const data3 = new Uint8Array(9), view2 = new DataView(data3.buffer);
128666
128777
  data3[0] = value3.kind === "number" ? 1 : value3.kind === "boolean" ? 4 : value3.kind === "error" ? 16 : 0;
@@ -128669,15 +128780,23 @@ var BiffFormulaWriter = class {
128669
128780
  else if (value3.kind === "error") data3[1] = biffError(value3.value);
128670
128781
  push(data3, arrays);
128671
128782
  }
128783
+ arrayBoundaries.push(arrays.length);
128672
128784
  }
128673
128785
  }
128786
+ boundary();
128674
128787
  };
128675
128788
  visit(root);
128789
+ boundary();
128790
+ if (bytes.length > 65535)
128791
+ throw new SsconvertError("unsupported-feature", "Excel BIFF formula token length exceeds version limits");
128676
128792
  const tokens3 = new Uint8Array(bytes);
128677
128793
  for (const relocation of relocations) this.relocations.push({ ...relocation, tokens: tokens3 });
128678
128794
  return {
128679
128795
  tokens: tokens3,
128796
+ tokenBoundaries,
128680
128797
  arrays: new Uint8Array(arrays),
128798
+ arrayBoundaries,
128799
+ arrayStrings,
128681
128800
  diagnostics,
128682
128801
  nameDependencies: relocations.filter((relocation) => relocation.kind === "name").map((relocation) => relocation.index)
128683
128802
  };
@@ -129262,7 +129381,10 @@ async function writeBiffStream(book, revision2, dual, context, filepass) {
129262
129381
  if (group) {
129263
129382
  formulas.set(cell, {
129264
129383
  tokens: new Uint8Array([dataTables.has(group) ? 2 : 1, ...words(group.range.startRow, group.range.startColumn)]),
129384
+ tokenBoundaries: [5],
129265
129385
  arrays: new Uint8Array(),
129386
+ arrayBoundaries: [],
129387
+ arrayStrings: [],
129266
129388
  diagnostics: [],
129267
129389
  nameDependencies: []
129268
129390
  });
@@ -129352,8 +129474,22 @@ async function writeBiffStream(book, revision2, dual, context, filepass) {
129352
129474
  header4[3] = text2[0];
129353
129475
  view3.setUint16(4, formula3.tokens.length, true);
129354
129476
  const scope = name.sheet === void 0 ? 0 : book.sheets.findIndex((sheet) => sheet.id === name.sheet) + 1;
129355
- view3.setUint16(revision2 === 8 ? 8 : 6, scope, true);
129356
- output2.record(24, join(join(header4, text2.subarray(1)), join(formula3.tokens, formula3.arrays)));
129477
+ if (revision2 === 7 && scope) view3.setUint16(6, scope - 1, true);
129478
+ view3.setUint16(8, scope, true);
129479
+ const start = header4.length + text2.length - 1;
129480
+ output2.continuedRecord(
129481
+ 24,
129482
+ join(join(header4, text2.subarray(1)), join(formula3.tokens, formula3.arrays)),
129483
+ [
129484
+ start,
129485
+ ...formula3.tokenBoundaries.map((offset) => offset + start),
129486
+ ...formula3.arrayBoundaries.map((offset) => offset + start + formula3.tokens.length)
129487
+ ],
129488
+ formula3.arrayStrings.map((span2) => ({
129489
+ start: start + formula3.tokens.length + span2.start,
129490
+ end: start + formula3.tokens.length + span2.end
129491
+ }))
129492
+ );
129357
129493
  }
129358
129494
  if (revision2 === 8) {
129359
129495
  metadata3.global(output2);
@@ -129407,7 +129543,19 @@ async function writeBiffStream(book, revision2, dual, context, filepass) {
129407
129543
  view3.setUint16(12, formula3.tokens.length, true);
129408
129544
  data3.set(formula3.tokens, 14);
129409
129545
  data3.set(formula3.arrays, 14 + formula3.tokens.length);
129410
- output2.record(545, data3);
129546
+ output2.continuedRecord(
129547
+ 545,
129548
+ data3,
129549
+ [
129550
+ 14,
129551
+ ...formula3.tokenBoundaries.map((offset) => offset + 14),
129552
+ ...formula3.arrayBoundaries.map((offset) => offset + 14 + formula3.tokens.length)
129553
+ ],
129554
+ formula3.arrayStrings.map((span2) => ({
129555
+ start: 14 + formula3.tokens.length + span2.start,
129556
+ end: 14 + formula3.tokens.length + span2.end
129557
+ }))
129558
+ );
129411
129559
  }
129412
129560
  }
129413
129561
  const cached = cell.cachedResult ?? cell.value;
@@ -129489,7 +129637,19 @@ async function writeCell(output2, cell, xf, revision2, strings, context, formula
129489
129637
  view2.setUint16(20, formula3.tokens.length, true);
129490
129638
  data3.set(formula3.tokens, 22);
129491
129639
  data3.set(formula3.arrays, 22 + formula3.tokens.length);
129492
- output2.record(6, data3);
129640
+ output2.continuedRecord(
129641
+ 6,
129642
+ data3,
129643
+ [
129644
+ 22,
129645
+ ...formula3.tokenBoundaries.map((offset) => offset + 22),
129646
+ ...formula3.arrayBoundaries.map((offset) => offset + 22 + formula3.tokens.length)
129647
+ ],
129648
+ formula3.arrayStrings.map((span2) => ({
129649
+ start: 22 + formula3.tokens.length + span2.start,
129650
+ end: 22 + formula3.tokens.length + span2.end
129651
+ }))
129652
+ );
129493
129653
  return;
129494
129654
  }
129495
129655
  if (value3.kind === "number") {
@@ -130410,6 +130570,33 @@ async function readBiff(borrowed, context, encoding) {
130410
130570
  while (records[index2 + 1]?.opcode === 60) parts.push(records[++index2].data);
130411
130571
  return { parts, next: index2 };
130412
130572
  };
130573
+ const formulaParts = (index2, offset, length) => {
130574
+ const first = records[index2].data;
130575
+ let tokens3;
130576
+ if (offset + length <= first.bytes.length) {
130577
+ tokens3 = first.slice(offset, length);
130578
+ offset += length;
130579
+ } else {
130580
+ accountFormulaWork(length);
130581
+ tokens3 = new Uint8Array(length);
130582
+ let written = 0;
130583
+ while (written < length) {
130584
+ context.signal.throwIfAborted();
130585
+ const part = records[index2].data;
130586
+ const count = Math.min(length - written, part.bytes.length - offset);
130587
+ tokens3.set(part.slice(offset, count), written);
130588
+ written += count;
130589
+ offset += count;
130590
+ if (written < length) {
130591
+ if (records[index2 + 1]?.opcode !== 60) invalidBiff("truncated formula tokens/CONTINUE");
130592
+ index2++;
130593
+ offset = 0;
130594
+ }
130595
+ }
130596
+ }
130597
+ const extra = stringParts(index2, offset);
130598
+ return { tokens: tokens3, arrays: extra.parts, next: extra.next };
130599
+ };
130413
130600
  for (let index2 = 0; index2 < records.length; index2++) {
130414
130601
  context.signal.throwIfAborted();
130415
130602
  const record7 = records[index2], data3 = record7.data, opcode = record7.opcode;
@@ -130608,13 +130795,12 @@ async function readBiff(borrowed, context, encoding) {
130608
130795
  const name = accountText(ver >= 8 ? cursor.unicode(length).text : cursor.legacy(length));
130609
130796
  const end2 = 7 + cursor.consumedBytes;
130610
130797
  const tokenLength = end2 + 2 <= data3.bytes.length ? data3.u16(end2) : 0;
130611
- const tokens3 = tokenLength ? data3.slice(end2 + 2, tokenLength) : new Uint8Array();
130798
+ const formula4 = tokenLength ? formulaParts(index2, end2 + 2, tokenLength) : { tokens: new Uint8Array(), arrays: [], next: index2 };
130612
130799
  const legacyLink = (sheet?.legacyExternalLinks ?? legacyExternalLinks).get((sheet?.legacyExternalSheets ?? legacyExternalSheets).length - 1);
130613
130800
  const table2 = ver >= 8 ? supbooks.at(-1)?.names : legacyLink?.names;
130614
130801
  if (!table2) invalidBiff("EXTERNNAME without workbook link");
130615
- const arrays = tokenLength ? stringParts(index2, end2 + 2 + tokenLength) : { parts: [], next: index2 };
130616
- index2 = arrays.next;
130617
- table2.push({ name, sheetIndex: data3.u16(2), tokens: tokens3, arrays: arrays.parts, revision: ver, codepage, supported: flags === 0, record: record7 });
130802
+ index2 = formula4.next;
130803
+ table2.push({ name, sheetIndex: data3.u16(2), tokens: formula4.tokens, arrays: formula4.arrays, revision: ver, codepage, supported: flags === 0, record: record7 });
130618
130804
  const addin = ver >= 8 ? supbooks.at(-1)?.kind === "addin" : legacyLink?.addin;
130619
130805
  const externalIdentity = (ver >= 8 ? supbooks.at(-1)?.workbook : legacyLink?.workbook) !== void 0 && flags === 0;
130620
130806
  if (!addin || flags !== 0) await retain(record7, sheet?.unsupportedRecords ?? unsupported9, !externalIdentity);
@@ -130644,7 +130830,9 @@ async function readBiff(borrowed, context, encoding) {
130644
130830
  }
130645
130831
  if (opcode === 24 || opcode === 536) {
130646
130832
  const flags = data3.u16(0), length = data3.u8(3), tokenLength = ver === 2 ? data3.u8(4) : data3.u16(4);
130647
- const start = ver >= 7 ? 14 : ver >= 3 ? 6 : 5, sheetIndex = ver >= 8 ? data3.u16(8) : ver >= 7 ? data3.u16(6) : 0;
130833
+ const start = ver >= 7 ? 14 : ver >= 3 ? 6 : 5;
130834
+ const scopeIsWorksheet = ver >= 8 || ver >= 7 && data3.u16(8) !== 0;
130835
+ const sheetIndex = scopeIsWorksheet ? data3.u16(8) : ver >= 7 ? data3.u16(6) : 0;
130648
130836
  const cursor = new BiffStrings([new Binary(data3.slice(start, data3.bytes.length - start))], context, codepage);
130649
130837
  let name;
130650
130838
  if (flags & 32 && length) {
@@ -130668,10 +130856,20 @@ async function readBiff(borrowed, context, encoding) {
130668
130856
  ][builtin];
130669
130857
  name = (base ?? `_BIFF_BUILTIN_${builtin}`) + text2.slice(1);
130670
130858
  } else name = ver >= 8 ? cursor.unicode(length).text : cursor.legacy(length);
130671
- const tokens3 = data3.slice(start + cursor.consumedBytes, tokenLength);
130672
- const arrays = stringParts(index2, start + cursor.consumedBytes + tokenLength);
130673
- index2 = arrays.next;
130674
- names2.push({ name: accountText(name), flags, tokens: tokens3, arrays: arrays.parts, sheetIndex, revision: ver, codepage, record: record7, ...sheet ? { owner: sheet } : {} });
130859
+ const formula4 = formulaParts(index2, start + cursor.consumedBytes, tokenLength);
130860
+ index2 = formula4.next;
130861
+ names2.push({
130862
+ name: accountText(name),
130863
+ flags,
130864
+ tokens: formula4.tokens,
130865
+ arrays: formula4.arrays,
130866
+ sheetIndex,
130867
+ scopeIsWorksheet,
130868
+ revision: ver,
130869
+ codepage,
130870
+ record: record7,
130871
+ ...sheet ? { owner: sheet } : {}
130872
+ });
130675
130873
  continue;
130676
130874
  }
130677
130875
  if (ignoredOpcodes.has(opcode)) continue;
@@ -130745,13 +130943,15 @@ async function readBiff(borrowed, context, encoding) {
130745
130943
  if (kind > 3) invalidBiff("invalid formula cache tag");
130746
130944
  }
130747
130945
  lastFormula = addCell(sheet, data3, value3, { cachedResult: value3, formulaDirty: !!(data3.u16(14) & 3) });
130748
- lastFormula.tokens = data3.slice(tokenStart, tokenLength);
130749
- const arrays = stringParts(index2, tokenStart + tokenLength);
130750
- index2 = arrays.next;
130751
- lastFormula.arrays = arrays.parts;
130946
+ const formula4 = formulaParts(index2, tokenStart, tokenLength);
130947
+ index2 = formula4.next;
130948
+ lastFormula.tokens = formula4.tokens;
130949
+ lastFormula.arrays = formula4.arrays;
130752
130950
  const nextOpcode = records[index2 + 1]?.opcode;
130753
130951
  const groupFollows = nextOpcode === 1212 || nextOpcode === 33 || nextOpcode === 545 || nextOpcode === 54 || nextOpcode === 55 || nextOpcode === 566;
130754
- const stringOpcode = records[index2 + (groupFollows ? 2 : 1)]?.opcode;
130952
+ let stringIndex = index2 + (groupFollows ? 2 : 1);
130953
+ if (groupFollows) while (records[stringIndex]?.opcode === 60) stringIndex++;
130954
+ const stringOpcode = records[stringIndex]?.opcode;
130755
130955
  if (stringCache2 && stringOpcode !== 7 && stringOpcode !== 519) {
130756
130956
  const error2 = { kind: "error", value: "MISSING STRING" };
130757
130957
  lastFormula.cell = { ...lastFormula.cell, value: error2, cachedResult: error2 };
@@ -130791,10 +130991,17 @@ async function readBiff(borrowed, context, encoding) {
130791
130991
  }
130792
130992
  const kind = opcode === 1212 ? "shared" : "array";
130793
130993
  const start = kind === "shared" ? 10 : ver === 2 ? 8 : ver <= 4 ? 10 : 14;
130794
- const tokens3 = data3.slice(start, ver === 2 && kind === "array" ? data3.u8(start - 1) : data3.u16(start - 2));
130795
- const arrays = stringParts(index2, start + tokens3.length);
130796
- index2 = arrays.next;
130797
- sheet.groups.push({ id: `biff-${sheet.offset}-${record7.offset}`, kind, range: range3, tokens: tokens3, arrays: arrays.parts, keyRow: lastFormula.cell.row, keyColumn: lastFormula.cell.column });
130994
+ const formula4 = formulaParts(index2, start, ver === 2 && kind === "array" ? data3.u8(start - 1) : data3.u16(start - 2));
130995
+ index2 = formula4.next;
130996
+ sheet.groups.push({
130997
+ id: `biff-${sheet.offset}-${record7.offset}`,
130998
+ kind,
130999
+ range: range3,
131000
+ tokens: formula4.tokens,
131001
+ arrays: formula4.arrays,
131002
+ keyRow: lastFormula.cell.row,
131003
+ keyColumn: lastFormula.cell.column
131004
+ });
130798
131005
  continue;
130799
131006
  }
130800
131007
  if (opcode === 7 || opcode === 519) {
@@ -130902,7 +131109,7 @@ async function readBiff(borrowed, context, encoding) {
130902
131109
  const localSheets = sheets.map((sheet) => sheet.name);
130903
131110
  const nameSheets = names2.map((name) => {
130904
131111
  if (!name.sheetIndex) return void 0;
130905
- return (name.revision >= 8 ? sheets[name.sheetIndex - 1]?.name : (name.owner?.legacyExternalSheets ?? legacyExternalSheets)[name.sheetIndex - 1]) ?? void 0;
131112
+ return (name.scopeIsWorksheet ? sheets[name.sheetIndex - 1]?.name : (name.owner?.legacyExternalSheets ?? legacyExternalSheets)[name.sheetIndex - 1]) ?? void 0;
130906
131113
  });
130907
131114
  const externalNameTables = /* @__PURE__ */ new Map();
130908
131115
  const formulaNames = names2.map((name) => name.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.748",
3
+ "version": "0.1.750",
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.748",
648
+ "@poe-platform/safe-fs": "0.1.750",
649
649
  "pdf-lib": "1.17.1",
650
650
  "@types/node": "^25.2.2",
651
651
  "pako": "3.0.1",