@particle-academy/last-word-ui 0.4.0 → 0.4.1

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.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.4.1] - 2026-11-03
14
+
15
+ **What you must do: nothing.** A document with a `colSpan` of 1000 or less draws
16
+ exactly as it did.
17
+
18
+ ### Security
19
+
20
+ - A table cell's column span had no upper limit here either, so a very small
21
+ document could cost a browser tab far more than its size. `tableGrid()` clamps a
22
+ `colSpan` to 1000 (`MAX_COL_SPAN`, last-word's limit) and no longer spends memory
23
+ on each slot a span covers. The viewer still never refuses a document.
24
+ **Consumer action:** upgrade. If you vendored `doc-viewer` with `fancy-cli`,
25
+ add it again to take the fix: a vendored copy does not update itself.
26
+
13
27
  ## [0.4.0] - 2026-11-03
14
28
 
15
29
  **What you must do: nothing.** A document with one page setup draws exactly as
package/dist/index.cjs CHANGED
@@ -392,28 +392,37 @@ function spacingStyle(p, defaultAfter, defaultBefore = 0) {
392
392
  }
393
393
 
394
394
  // src/table-grid.ts
395
+ var MAX_COL_SPAN = 1e3;
395
396
  var span = (v) => typeof v === "number" && Number.isInteger(v) && v > 1 ? v : 1;
396
397
  function tableGrid(rows) {
397
- const occupied = rows.map(() => /* @__PURE__ */ new Set());
398
398
  const joinPrevious = rows.map(() => false);
399
399
  let colCount = 0;
400
+ let active = [];
401
+ let reach = -1;
400
402
  const out = rows.map((row, r) => {
403
+ joinPrevious[r] = r <= reach;
404
+ active = active.filter((s) => s[0] >= r).sort((a, b) => a[1] - b[1]);
405
+ const above = active.length;
406
+ let j = 0;
401
407
  const placed = [];
402
408
  let col = 0;
403
409
  (Array.isArray(row?.cells) ? row.cells : []).forEach((cell, c) => {
404
- while (occupied[r].has(col)) col++;
405
- const colSpan = span(cell?.colSpan);
410
+ while (j < above && active[j][1] <= col) {
411
+ col = Math.max(col, active[j][2]);
412
+ j++;
413
+ }
414
+ const colSpan = Math.min(MAX_COL_SPAN, span(cell?.colSpan));
406
415
  const rowSpan = Math.min(span(cell?.rowSpan), rows.length - r);
407
- for (let dr = 0; dr < rowSpan; dr++) {
408
- for (let dc = 0; dc < colSpan; dc++) occupied[r + dr].add(col + dc);
409
- if (dr > 0) joinPrevious[r + dr] = true;
416
+ if (rowSpan > 1) {
417
+ active.push([r + rowSpan - 1, col, col + colSpan]);
418
+ reach = Math.max(reach, r + rowSpan - 1);
410
419
  }
411
420
  placed.push({ row: r, cell: c, col, colSpan, rowSpan });
412
421
  col += colSpan;
422
+ colCount = Math.max(colCount, col);
413
423
  });
414
424
  return placed;
415
425
  });
416
- for (const set of occupied) for (const c of set) colCount = Math.max(colCount, c + 1);
417
426
  let headerRows = 0;
418
427
  while (headerRows < rows.length && rows[headerRows]?.header === true) headerRows++;
419
428
  return { colCount: Math.max(1, colCount), rows: out, joinPrevious, headerRows };