@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/dist/index.js CHANGED
@@ -389,28 +389,37 @@ function spacingStyle(p, defaultAfter, defaultBefore = 0) {
389
389
  }
390
390
 
391
391
  // src/table-grid.ts
392
+ var MAX_COL_SPAN = 1e3;
392
393
  var span = (v) => typeof v === "number" && Number.isInteger(v) && v > 1 ? v : 1;
393
394
  function tableGrid(rows) {
394
- const occupied = rows.map(() => /* @__PURE__ */ new Set());
395
395
  const joinPrevious = rows.map(() => false);
396
396
  let colCount = 0;
397
+ let active = [];
398
+ let reach = -1;
397
399
  const out = rows.map((row, r) => {
400
+ joinPrevious[r] = r <= reach;
401
+ active = active.filter((s) => s[0] >= r).sort((a, b) => a[1] - b[1]);
402
+ const above = active.length;
403
+ let j = 0;
398
404
  const placed = [];
399
405
  let col = 0;
400
406
  (Array.isArray(row?.cells) ? row.cells : []).forEach((cell, c) => {
401
- while (occupied[r].has(col)) col++;
402
- const colSpan = span(cell?.colSpan);
407
+ while (j < above && active[j][1] <= col) {
408
+ col = Math.max(col, active[j][2]);
409
+ j++;
410
+ }
411
+ const colSpan = Math.min(MAX_COL_SPAN, span(cell?.colSpan));
403
412
  const rowSpan = Math.min(span(cell?.rowSpan), rows.length - r);
404
- for (let dr = 0; dr < rowSpan; dr++) {
405
- for (let dc = 0; dc < colSpan; dc++) occupied[r + dr].add(col + dc);
406
- if (dr > 0) joinPrevious[r + dr] = true;
413
+ if (rowSpan > 1) {
414
+ active.push([r + rowSpan - 1, col, col + colSpan]);
415
+ reach = Math.max(reach, r + rowSpan - 1);
407
416
  }
408
417
  placed.push({ row: r, cell: c, col, colSpan, rowSpan });
409
418
  col += colSpan;
419
+ colCount = Math.max(colCount, col);
410
420
  });
411
421
  return placed;
412
422
  });
413
- for (const set of occupied) for (const c of set) colCount = Math.max(colCount, c + 1);
414
423
  let headerRows = 0;
415
424
  while (headerRows < rows.length && rows[headerRows]?.header === true) headerRows++;
416
425
  return { colCount: Math.max(1, colCount), rows: out, joinPrevious, headerRows };