ooxml-core 0.11.0 → 0.12.0

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 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/xlsx/formula/store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQ9C,OAAO,EAAO,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAEvD;;;GAGG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,GAChE,IAAI,CAkCN"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/xlsx/formula/store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQ9C,OAAO,EAAO,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAEvD;;;GAGG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,GAChE,IAAI,CAqCN"}
@@ -9913,8 +9913,9 @@ var AreaIndex = class {
9913
9913
  wide = /* @__PURE__ */ new Map();
9914
9914
  add(area, node) {
9915
9915
  const { start, end } = area.range;
9916
- if (start.row === end.row && start.col === end.col) {
9917
- push2(inner(this.cells, area.sheet), cellKey(start.row, start.col), node);
9916
+ if (start.row === end.row && end.col - start.col + 1 <= BUCKET_WIDTH) {
9917
+ const cells = inner(this.cells, area.sheet);
9918
+ for (let col = start.col; col <= end.col; col++) push2(cells, cellKey(start.row, col), node);
9918
9919
  return;
9919
9920
  }
9920
9921
  const entry = { range: area.range, node };
@@ -10141,7 +10142,8 @@ function writeFootprint(sheet, footprint, m) {
10141
10142
  }
10142
10143
  if (cell) {
10143
10144
  cell.value = value;
10144
- cell.spillAnchor = { row, col };
10145
+ if (!isSpilledCell(cell) || cell.spillAnchor.row !== row || cell.spillAnchor.col !== col)
10146
+ cell.spillAnchor = { row, col };
10145
10147
  } else {
10146
10148
  const spilled = { value, spillAnchor: { row, col } };
10147
10149
  putCell(sheet, r, c2, spilled);
@@ -10188,6 +10190,7 @@ var EngineHost = class {
10188
10190
  columnIndex;
10189
10191
  reverseIndex;
10190
10192
  footprintIndex;
10193
+ fullOrder;
10191
10194
  /** Range reads cached for one evaluation pass (see `readBlock`). */
10192
10195
  blockCache = /* @__PURE__ */ new Map();
10193
10196
  /** Counts reads that hit a formula still being evaluated (a circular reference). */
@@ -10360,6 +10363,7 @@ var EngineHost = class {
10360
10363
  if (this.footprints.delete(node)) this.footprintIndex = void 0;
10361
10364
  }
10362
10365
  graphChanged() {
10366
+ this.fullOrder = void 0;
10363
10367
  this.columnIndex = void 0;
10364
10368
  this.reverseIndex = void 0;
10365
10369
  this.footprintIndex = void 0;
@@ -10390,52 +10394,6 @@ var EngineHost = class {
10390
10394
  }
10391
10395
  };
10392
10396
 
10393
- // src/xlsx/formula/engine-types.ts
10394
- var CIRCULAR_REFERENCE_WARNING = "The workbook contains circular references; the cells involved show 0.";
10395
-
10396
- // src/xlsx/formula/engine-util.ts
10397
- function finalize(value, host) {
10398
- let result2;
10399
- if (value instanceof RefValue) {
10400
- if (value.areas.length !== 1) return ERR.VALUE;
10401
- if (value.isCell()) {
10402
- const area = value.areas[0];
10403
- result2 = host.readCell(area.sheet, area.range.start.row, area.range.start.col);
10404
- } else result2 = toMatrix(host, value);
10405
- } else if (value instanceof LambdaValue) return ERR.CALC;
10406
- else result2 = value;
10407
- if (result2 instanceof Matrix) {
10408
- if (result2.rows === 1 && result2.cols === 1) result2 = result2.get(0, 0);
10409
- else return result2.block().mapValues(clean);
10410
- }
10411
- return clean(result2);
10412
- }
10413
- function clean(value) {
10414
- if (value === null) return 0;
10415
- if (typeof value === "number") {
10416
- if (!Number.isFinite(value)) return ERR.NUM;
10417
- return value === 0 ? 0 : value;
10418
- }
10419
- return value;
10420
- }
10421
- var rangeHas = (range, row, col) => row >= range.start.row && row <= range.end.row && col >= range.start.col && col <= range.end.col;
10422
- function sameRange(a, b) {
10423
- if (!a || !b) return a === b || !a && !b;
10424
- return a.start.row === b.start.row && a.start.col === b.start.col && a.end.row === b.end.row && a.end.col === b.end.col;
10425
- }
10426
- function boundingBox(ranges) {
10427
- const first3 = ranges[0];
10428
- const start = { ...first3.start };
10429
- const end = { ...first3.end };
10430
- for (const r of ranges) {
10431
- start.row = Math.min(start.row, r.start.row);
10432
- start.col = Math.min(start.col, r.start.col);
10433
- end.row = Math.max(end.row, r.end.row);
10434
- end.col = Math.max(end.col, r.end.col);
10435
- }
10436
- return { start, end };
10437
- }
10438
-
10439
10397
  // src/xlsx/formula/scc.ts
10440
10398
  function stronglyConnected(nodes, successors) {
10441
10399
  const index2 = /* @__PURE__ */ new Map();
@@ -10488,6 +10446,63 @@ function stronglyConnected(nodes, successors) {
10488
10446
  return out;
10489
10447
  }
10490
10448
 
10449
+ // src/xlsx/formula/engine-order.ts
10450
+ function formulaOrder(nodes, successors) {
10451
+ const ranks = /* @__PURE__ */ new Map();
10452
+ const components = stronglyConnected(nodes, successors).map((members, rank4) => {
10453
+ for (const member of members) ranks.set(member, rank4);
10454
+ const first3 = members[0];
10455
+ return { nodes: members, cyclic: members.length > 1 || successors(first3).includes(first3) };
10456
+ });
10457
+ return { components, ranks };
10458
+ }
10459
+
10460
+ // src/xlsx/formula/engine-types.ts
10461
+ var CIRCULAR_REFERENCE_WARNING = "The workbook contains circular references; the cells involved show 0.";
10462
+
10463
+ // src/xlsx/formula/engine-util.ts
10464
+ function finalize(value, host) {
10465
+ let result2;
10466
+ if (value instanceof RefValue) {
10467
+ if (value.areas.length !== 1) return ERR.VALUE;
10468
+ if (value.isCell()) {
10469
+ const area = value.areas[0];
10470
+ result2 = host.readCell(area.sheet, area.range.start.row, area.range.start.col);
10471
+ } else result2 = toMatrix(host, value);
10472
+ } else if (value instanceof LambdaValue) return ERR.CALC;
10473
+ else result2 = value;
10474
+ if (result2 instanceof Matrix) {
10475
+ if (result2.rows === 1 && result2.cols === 1) result2 = result2.get(0, 0);
10476
+ else return result2.block().mapValues(clean);
10477
+ }
10478
+ return clean(result2);
10479
+ }
10480
+ function clean(value) {
10481
+ if (value === null) return 0;
10482
+ if (typeof value === "number") {
10483
+ if (!Number.isFinite(value)) return ERR.NUM;
10484
+ return value === 0 ? 0 : value;
10485
+ }
10486
+ return value;
10487
+ }
10488
+ var rangeHas = (range, row, col) => row >= range.start.row && row <= range.end.row && col >= range.start.col && col <= range.end.col;
10489
+ function sameRange(a, b) {
10490
+ if (!a || !b) return a === b || !a && !b;
10491
+ return a.start.row === b.start.row && a.start.col === b.start.col && a.end.row === b.end.row && a.end.col === b.end.col;
10492
+ }
10493
+ function boundingBox(ranges) {
10494
+ const first3 = ranges[0];
10495
+ const start = { ...first3.start };
10496
+ const end = { ...first3.end };
10497
+ for (const r of ranges) {
10498
+ start.row = Math.min(start.row, r.start.row);
10499
+ start.col = Math.min(start.col, r.start.col);
10500
+ end.row = Math.max(end.row, r.end.row);
10501
+ end.col = Math.max(end.col, r.end.col);
10502
+ }
10503
+ return { start, end };
10504
+ }
10505
+
10491
10506
  // src/xlsx/formula/store.ts
10492
10507
  function storeResult(sheet, node, cell, result2, claims) {
10493
10508
  const { row, col } = node;
@@ -10507,9 +10522,9 @@ function storeResult(sheet, node, cell, result2, claims) {
10507
10522
  return;
10508
10523
  }
10509
10524
  const footprint = footprintFor(row, col, result2);
10510
- if (node.spill) clearFootprint(sheet, node.spill, row, col);
10511
- delete node.spill;
10512
10525
  if (!footprint || !footprintFree(sheet, footprint, row, col, claims)) {
10526
+ if (node.spill) clearFootprint(sheet, node.spill, row, col);
10527
+ delete node.spill;
10513
10528
  node.blockedSpill = footprint ?? {
10514
10529
  start: { row, col },
10515
10530
  end: {
@@ -10520,6 +10535,7 @@ function storeResult(sheet, node, cell, result2, claims) {
10520
10535
  cell.value = ERR.SPILL;
10521
10536
  return;
10522
10537
  }
10538
+ if (node.spill && !sameRange(node.spill, footprint)) clearFootprint(sheet, node.spill, row, col);
10523
10539
  delete node.blockedSpill;
10524
10540
  writeFootprint(sheet, footprint, result2);
10525
10541
  node.spill = footprint;
@@ -10542,7 +10558,7 @@ var EngineCore = class extends EngineHost {
10542
10558
  const dirty = everything && round2 === 0 ? current : this.closure(current);
10543
10559
  this.footprintChanges = [];
10544
10560
  this.evaluatedAt = /* @__PURE__ */ new Map();
10545
- this.evaluateSet(dirty);
10561
+ this.evaluateSet(dirty, everything && round2 === 0);
10546
10562
  if (this.footprintChanges.length === 0) break;
10547
10563
  const next = /* @__PURE__ */ new Set();
10548
10564
  const reverse2 = this.reverse();
@@ -10584,7 +10600,7 @@ var EngineCore = class extends EngineHost {
10584
10600
  }
10585
10601
  return out;
10586
10602
  }
10587
- evaluateSet(dirty) {
10603
+ evaluateSet(dirty, full) {
10588
10604
  this.boundsCache.clear();
10589
10605
  this.blockCache.clear();
10590
10606
  const columns = this.columns();
@@ -10594,24 +10610,25 @@ var EngineCore = class extends EngineHost {
10594
10610
  let out = succCache.get(node);
10595
10611
  if (out) return out;
10596
10612
  const found = [];
10613
+ const anchors = /* @__PURE__ */ new Set();
10597
10614
  for (const dep of node.deps) {
10598
10615
  columns.nodesIn(dep, found);
10599
- const anchors = [];
10600
10616
  footprints.dependents(dep.sheet, dep.range, anchors);
10601
- for (const anchor of anchors) if (anchor.spill ?? anchor.arrayRange) found.push(anchor);
10602
10617
  }
10603
- out = [...new Set(found)].filter((n2) => dirty.has(n2));
10618
+ for (const anchor of anchors) if (anchor.spill ?? anchor.arrayRange) found.push(anchor);
10619
+ out = found.length ? [...new Set(found)].filter((n2) => dirty.has(n2)) : [];
10604
10620
  succCache.set(node, out);
10605
10621
  return out;
10606
10622
  };
10607
- const order = stronglyConnected(dirty, successors);
10623
+ const order = full && this.fullOrder || formulaOrder(dirty, successors);
10624
+ if (full) this.fullOrder = order;
10608
10625
  this.pending = new Set(dirty);
10609
10626
  this.dynamicCycleHits = /* @__PURE__ */ new Set();
10610
10627
  try {
10611
- for (const component of order) {
10612
- const first3 = component[0];
10613
- if (component.length > 1 || successors(first3).includes(first3)) {
10614
- for (const node of component) this.markCycle(node);
10628
+ for (const component of order.components) {
10629
+ const first3 = component.nodes[0];
10630
+ if (component.cyclic) {
10631
+ for (const node of component.nodes) this.markCycle(node);
10615
10632
  } else if (this.pending.has(first3)) {
10616
10633
  this.computeFrom(first3);
10617
10634
  }
@@ -10690,6 +10707,7 @@ var EngineCore = class extends EngineHost {
10690
10707
  return !!other && other !== node && !!other.spill && rangeHas(other.spill, r, c2);
10691
10708
  });
10692
10709
  if (!sameRange(before, node.spill) || !sameRange(blockedBefore, node.blockedSpill)) {
10710
+ this.updateOrder(node, before, blockedBefore);
10693
10711
  this.footprintIndex = void 0;
10694
10712
  this.blockCache.clear();
10695
10713
  }
@@ -10709,10 +10727,30 @@ var EngineCore = class extends EngineHost {
10709
10727
  }
10710
10728
  }
10711
10729
  }
10730
+ /** New spill edges may reuse the order only when every reader already follows its anchor. */
10731
+ updateOrder(node, before, blockedBefore) {
10732
+ const order = this.fullOrder;
10733
+ if (!order) return;
10734
+ if (before || blockedBefore || !node.spill || node.blockedSpill) {
10735
+ this.fullOrder = void 0;
10736
+ return;
10737
+ }
10738
+ const rank4 = order.ranks.get(node);
10739
+ if (rank4 === void 0) {
10740
+ this.fullOrder = void 0;
10741
+ return;
10742
+ }
10743
+ const readers = /* @__PURE__ */ new Set();
10744
+ this.reverse().dependents(node.sheet, node.spill, readers);
10745
+ for (const reader of readers) {
10746
+ if ((order.ranks.get(reader) ?? -1) <= rank4) {
10747
+ this.fullOrder = void 0;
10748
+ return;
10749
+ }
10750
+ }
10751
+ }
10712
10752
  frameFor(sheet, row, col, root, legacy = false) {
10713
- const frame = { host: this, sheet, row, col, scope: void 0, depth: 0 };
10714
- if (legacy) Object.assign(frame, { legacy: true });
10715
- return root ? { ...frame, root } : frame;
10753
+ return { host: this, sheet, row, col, scope: void 0, depth: 0, root, legacy };
10716
10754
  }
10717
10755
  evaluateFormula(node) {
10718
10756
  if (!node.ast) return node.parseError ?? ERR.NAME;
@@ -9907,8 +9907,9 @@ var AreaIndex = class {
9907
9907
  wide = /* @__PURE__ */ new Map();
9908
9908
  add(area, node) {
9909
9909
  const { start, end } = area.range;
9910
- if (start.row === end.row && start.col === end.col) {
9911
- push2(inner(this.cells, area.sheet), cellKey(start.row, start.col), node);
9910
+ if (start.row === end.row && end.col - start.col + 1 <= BUCKET_WIDTH) {
9911
+ const cells = inner(this.cells, area.sheet);
9912
+ for (let col = start.col; col <= end.col; col++) push2(cells, cellKey(start.row, col), node);
9912
9913
  return;
9913
9914
  }
9914
9915
  const entry = { range: area.range, node };
@@ -10135,7 +10136,8 @@ function writeFootprint(sheet, footprint, m) {
10135
10136
  }
10136
10137
  if (cell) {
10137
10138
  cell.value = value;
10138
- cell.spillAnchor = { row, col };
10139
+ if (!isSpilledCell(cell) || cell.spillAnchor.row !== row || cell.spillAnchor.col !== col)
10140
+ cell.spillAnchor = { row, col };
10139
10141
  } else {
10140
10142
  const spilled = { value, spillAnchor: { row, col } };
10141
10143
  putCell(sheet, r, c2, spilled);
@@ -10182,6 +10184,7 @@ var EngineHost = class {
10182
10184
  columnIndex;
10183
10185
  reverseIndex;
10184
10186
  footprintIndex;
10187
+ fullOrder;
10185
10188
  /** Range reads cached for one evaluation pass (see `readBlock`). */
10186
10189
  blockCache = /* @__PURE__ */ new Map();
10187
10190
  /** Counts reads that hit a formula still being evaluated (a circular reference). */
@@ -10354,6 +10357,7 @@ var EngineHost = class {
10354
10357
  if (this.footprints.delete(node)) this.footprintIndex = void 0;
10355
10358
  }
10356
10359
  graphChanged() {
10360
+ this.fullOrder = void 0;
10357
10361
  this.columnIndex = void 0;
10358
10362
  this.reverseIndex = void 0;
10359
10363
  this.footprintIndex = void 0;
@@ -10384,52 +10388,6 @@ var EngineHost = class {
10384
10388
  }
10385
10389
  };
10386
10390
 
10387
- // src/xlsx/formula/engine-types.ts
10388
- var CIRCULAR_REFERENCE_WARNING = "The workbook contains circular references; the cells involved show 0.";
10389
-
10390
- // src/xlsx/formula/engine-util.ts
10391
- function finalize(value, host) {
10392
- let result2;
10393
- if (value instanceof RefValue) {
10394
- if (value.areas.length !== 1) return ERR.VALUE;
10395
- if (value.isCell()) {
10396
- const area = value.areas[0];
10397
- result2 = host.readCell(area.sheet, area.range.start.row, area.range.start.col);
10398
- } else result2 = toMatrix(host, value);
10399
- } else if (value instanceof LambdaValue) return ERR.CALC;
10400
- else result2 = value;
10401
- if (result2 instanceof Matrix) {
10402
- if (result2.rows === 1 && result2.cols === 1) result2 = result2.get(0, 0);
10403
- else return result2.block().mapValues(clean);
10404
- }
10405
- return clean(result2);
10406
- }
10407
- function clean(value) {
10408
- if (value === null) return 0;
10409
- if (typeof value === "number") {
10410
- if (!Number.isFinite(value)) return ERR.NUM;
10411
- return value === 0 ? 0 : value;
10412
- }
10413
- return value;
10414
- }
10415
- var rangeHas = (range, row, col) => row >= range.start.row && row <= range.end.row && col >= range.start.col && col <= range.end.col;
10416
- function sameRange(a, b) {
10417
- if (!a || !b) return a === b || !a && !b;
10418
- return a.start.row === b.start.row && a.start.col === b.start.col && a.end.row === b.end.row && a.end.col === b.end.col;
10419
- }
10420
- function boundingBox(ranges) {
10421
- const first3 = ranges[0];
10422
- const start = { ...first3.start };
10423
- const end = { ...first3.end };
10424
- for (const r of ranges) {
10425
- start.row = Math.min(start.row, r.start.row);
10426
- start.col = Math.min(start.col, r.start.col);
10427
- end.row = Math.max(end.row, r.end.row);
10428
- end.col = Math.max(end.col, r.end.col);
10429
- }
10430
- return { start, end };
10431
- }
10432
-
10433
10391
  // src/xlsx/formula/scc.ts
10434
10392
  function stronglyConnected(nodes, successors) {
10435
10393
  const index2 = /* @__PURE__ */ new Map();
@@ -10482,6 +10440,63 @@ function stronglyConnected(nodes, successors) {
10482
10440
  return out;
10483
10441
  }
10484
10442
 
10443
+ // src/xlsx/formula/engine-order.ts
10444
+ function formulaOrder(nodes, successors) {
10445
+ const ranks = /* @__PURE__ */ new Map();
10446
+ const components = stronglyConnected(nodes, successors).map((members, rank4) => {
10447
+ for (const member of members) ranks.set(member, rank4);
10448
+ const first3 = members[0];
10449
+ return { nodes: members, cyclic: members.length > 1 || successors(first3).includes(first3) };
10450
+ });
10451
+ return { components, ranks };
10452
+ }
10453
+
10454
+ // src/xlsx/formula/engine-types.ts
10455
+ var CIRCULAR_REFERENCE_WARNING = "The workbook contains circular references; the cells involved show 0.";
10456
+
10457
+ // src/xlsx/formula/engine-util.ts
10458
+ function finalize(value, host) {
10459
+ let result2;
10460
+ if (value instanceof RefValue) {
10461
+ if (value.areas.length !== 1) return ERR.VALUE;
10462
+ if (value.isCell()) {
10463
+ const area = value.areas[0];
10464
+ result2 = host.readCell(area.sheet, area.range.start.row, area.range.start.col);
10465
+ } else result2 = toMatrix(host, value);
10466
+ } else if (value instanceof LambdaValue) return ERR.CALC;
10467
+ else result2 = value;
10468
+ if (result2 instanceof Matrix) {
10469
+ if (result2.rows === 1 && result2.cols === 1) result2 = result2.get(0, 0);
10470
+ else return result2.block().mapValues(clean);
10471
+ }
10472
+ return clean(result2);
10473
+ }
10474
+ function clean(value) {
10475
+ if (value === null) return 0;
10476
+ if (typeof value === "number") {
10477
+ if (!Number.isFinite(value)) return ERR.NUM;
10478
+ return value === 0 ? 0 : value;
10479
+ }
10480
+ return value;
10481
+ }
10482
+ var rangeHas = (range, row, col) => row >= range.start.row && row <= range.end.row && col >= range.start.col && col <= range.end.col;
10483
+ function sameRange(a, b) {
10484
+ if (!a || !b) return a === b || !a && !b;
10485
+ return a.start.row === b.start.row && a.start.col === b.start.col && a.end.row === b.end.row && a.end.col === b.end.col;
10486
+ }
10487
+ function boundingBox(ranges) {
10488
+ const first3 = ranges[0];
10489
+ const start = { ...first3.start };
10490
+ const end = { ...first3.end };
10491
+ for (const r of ranges) {
10492
+ start.row = Math.min(start.row, r.start.row);
10493
+ start.col = Math.min(start.col, r.start.col);
10494
+ end.row = Math.max(end.row, r.end.row);
10495
+ end.col = Math.max(end.col, r.end.col);
10496
+ }
10497
+ return { start, end };
10498
+ }
10499
+
10485
10500
  // src/xlsx/formula/store.ts
10486
10501
  function storeResult(sheet, node, cell, result2, claims) {
10487
10502
  const { row, col } = node;
@@ -10501,9 +10516,9 @@ function storeResult(sheet, node, cell, result2, claims) {
10501
10516
  return;
10502
10517
  }
10503
10518
  const footprint = footprintFor(row, col, result2);
10504
- if (node.spill) clearFootprint(sheet, node.spill, row, col);
10505
- delete node.spill;
10506
10519
  if (!footprint || !footprintFree(sheet, footprint, row, col, claims)) {
10520
+ if (node.spill) clearFootprint(sheet, node.spill, row, col);
10521
+ delete node.spill;
10507
10522
  node.blockedSpill = footprint ?? {
10508
10523
  start: { row, col },
10509
10524
  end: {
@@ -10514,6 +10529,7 @@ function storeResult(sheet, node, cell, result2, claims) {
10514
10529
  cell.value = ERR.SPILL;
10515
10530
  return;
10516
10531
  }
10532
+ if (node.spill && !sameRange(node.spill, footprint)) clearFootprint(sheet, node.spill, row, col);
10517
10533
  delete node.blockedSpill;
10518
10534
  writeFootprint(sheet, footprint, result2);
10519
10535
  node.spill = footprint;
@@ -10536,7 +10552,7 @@ var EngineCore = class extends EngineHost {
10536
10552
  const dirty = everything && round2 === 0 ? current : this.closure(current);
10537
10553
  this.footprintChanges = [];
10538
10554
  this.evaluatedAt = /* @__PURE__ */ new Map();
10539
- this.evaluateSet(dirty);
10555
+ this.evaluateSet(dirty, everything && round2 === 0);
10540
10556
  if (this.footprintChanges.length === 0) break;
10541
10557
  const next = /* @__PURE__ */ new Set();
10542
10558
  const reverse2 = this.reverse();
@@ -10578,7 +10594,7 @@ var EngineCore = class extends EngineHost {
10578
10594
  }
10579
10595
  return out;
10580
10596
  }
10581
- evaluateSet(dirty) {
10597
+ evaluateSet(dirty, full) {
10582
10598
  this.boundsCache.clear();
10583
10599
  this.blockCache.clear();
10584
10600
  const columns = this.columns();
@@ -10588,24 +10604,25 @@ var EngineCore = class extends EngineHost {
10588
10604
  let out = succCache.get(node);
10589
10605
  if (out) return out;
10590
10606
  const found = [];
10607
+ const anchors = /* @__PURE__ */ new Set();
10591
10608
  for (const dep of node.deps) {
10592
10609
  columns.nodesIn(dep, found);
10593
- const anchors = [];
10594
10610
  footprints.dependents(dep.sheet, dep.range, anchors);
10595
- for (const anchor of anchors) if (anchor.spill ?? anchor.arrayRange) found.push(anchor);
10596
10611
  }
10597
- out = [...new Set(found)].filter((n2) => dirty.has(n2));
10612
+ for (const anchor of anchors) if (anchor.spill ?? anchor.arrayRange) found.push(anchor);
10613
+ out = found.length ? [...new Set(found)].filter((n2) => dirty.has(n2)) : [];
10598
10614
  succCache.set(node, out);
10599
10615
  return out;
10600
10616
  };
10601
- const order = stronglyConnected(dirty, successors);
10617
+ const order = full && this.fullOrder || formulaOrder(dirty, successors);
10618
+ if (full) this.fullOrder = order;
10602
10619
  this.pending = new Set(dirty);
10603
10620
  this.dynamicCycleHits = /* @__PURE__ */ new Set();
10604
10621
  try {
10605
- for (const component of order) {
10606
- const first3 = component[0];
10607
- if (component.length > 1 || successors(first3).includes(first3)) {
10608
- for (const node of component) this.markCycle(node);
10622
+ for (const component of order.components) {
10623
+ const first3 = component.nodes[0];
10624
+ if (component.cyclic) {
10625
+ for (const node of component.nodes) this.markCycle(node);
10609
10626
  } else if (this.pending.has(first3)) {
10610
10627
  this.computeFrom(first3);
10611
10628
  }
@@ -10684,6 +10701,7 @@ var EngineCore = class extends EngineHost {
10684
10701
  return !!other && other !== node && !!other.spill && rangeHas(other.spill, r, c2);
10685
10702
  });
10686
10703
  if (!sameRange(before, node.spill) || !sameRange(blockedBefore, node.blockedSpill)) {
10704
+ this.updateOrder(node, before, blockedBefore);
10687
10705
  this.footprintIndex = void 0;
10688
10706
  this.blockCache.clear();
10689
10707
  }
@@ -10703,10 +10721,30 @@ var EngineCore = class extends EngineHost {
10703
10721
  }
10704
10722
  }
10705
10723
  }
10724
+ /** New spill edges may reuse the order only when every reader already follows its anchor. */
10725
+ updateOrder(node, before, blockedBefore) {
10726
+ const order = this.fullOrder;
10727
+ if (!order) return;
10728
+ if (before || blockedBefore || !node.spill || node.blockedSpill) {
10729
+ this.fullOrder = void 0;
10730
+ return;
10731
+ }
10732
+ const rank4 = order.ranks.get(node);
10733
+ if (rank4 === void 0) {
10734
+ this.fullOrder = void 0;
10735
+ return;
10736
+ }
10737
+ const readers = /* @__PURE__ */ new Set();
10738
+ this.reverse().dependents(node.sheet, node.spill, readers);
10739
+ for (const reader of readers) {
10740
+ if ((order.ranks.get(reader) ?? -1) <= rank4) {
10741
+ this.fullOrder = void 0;
10742
+ return;
10743
+ }
10744
+ }
10745
+ }
10706
10746
  frameFor(sheet, row, col, root, legacy = false) {
10707
- const frame = { host: this, sheet, row, col, scope: void 0, depth: 0 };
10708
- if (legacy) Object.assign(frame, { legacy: true });
10709
- return root ? { ...frame, root } : frame;
10747
+ return { host: this, sheet, row, col, scope: void 0, depth: 0, root, legacy };
10710
10748
  }
10711
10749
  evaluateFormula(node) {
10712
10750
  if (!node.ast) return node.parseError ?? ERR.NAME;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ooxml-core",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Shared OOXML logic for the Word, PowerPoint and Excel viewers: everything except the UI",
5
5
  "keywords": [
6
6
  "charts",