@reportwright/viewer 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.
@@ -9,7 +9,7 @@ import {
9
9
  reportFetch,
10
10
  resolveParameters,
11
11
  reuseRefs
12
- } from "./chunk-WQOBRZAL.js";
12
+ } from "./chunk-M6GENFAH.js";
13
13
  import "./chunk-GJS242RR.js";
14
14
  import "./chunk-72S6DETS.js";
15
15
  import {
@@ -150,4 +150,4 @@ export {
150
150
  exportInteractiveHtml,
151
151
  reachableReportIds
152
152
  };
153
- //# sourceMappingURL=chunk-N5WHQ4DM.js.map
153
+ //# sourceMappingURL=chunk-FARG6X2U.js.map
@@ -9164,7 +9164,7 @@ register("table", {
9164
9164
  (item.groups || []).forEach((g, i) => {
9165
9165
  if (g.name) groupChains[g.name] = { rows, keys: item.groups.slice(0, i + 1).map((x) => x.expr) };
9166
9166
  });
9167
- const base = { ...tctx, aggRows: rows, aggIndex: void 0, fields: rows[0] || null, scopes, region: tableScope, group: void 0, groupChains: { ...tctx.groupChains || {}, ...groupChains } };
9167
+ const base = { ...tctx, aggRows: rows, aggIndex: void 0, fields: lc.win?.first || rows[0] || null, scopes, region: tableScope, group: void 0, groupChains: { ...tctx.groupChains || {}, ...groupChains } };
9168
9168
  const units = [];
9169
9169
  let y = 0;
9170
9170
  let repeatH = 0;
@@ -9402,7 +9402,8 @@ register("table", {
9402
9402
  openSpans = [];
9403
9403
  };
9404
9404
  const fl = base.bandRows === "first-last";
9405
- const headerUnits = (item.header || []).map((r) => layRow(r, fl && rows.length ? { ...base, pendingRows: [rows[0]] } : base, "header")).filter(Boolean);
9405
+ const first0 = lc.win?.first || rows[0];
9406
+ const headerUnits = (item.header || []).map((r) => layRow(r, fl && rows.length ? { ...base, pendingRows: [first0] } : base, "header")).filter(Boolean);
9406
9407
  endBand();
9407
9408
  const headerHeight = headerUnits.reduce((s, u) => s + u.height, 0);
9408
9409
  if (item.repeatHeader !== false) repeatH = headerHeight;
@@ -9416,7 +9417,7 @@ register("table", {
9416
9417
  y += tl.needed;
9417
9418
  }
9418
9419
  const groups = item.groups || [];
9419
- let rowNo = 0;
9420
+ let rowNo = lc.win?.rowOffset || 0;
9420
9421
  const groupTables = [];
9421
9422
  const tableKey = `${item.name}#${lc.nextId()}`;
9422
9423
  const emit = (level, grows, ctx, chain, keyPath) => {
@@ -9436,9 +9437,16 @@ register("table", {
9436
9437
  const dctx = { ...ctx, fields: grows[i], aggRows: grows, aggIndex: i, rowNumber: rowNo };
9437
9438
  const u0 = units.length;
9438
9439
  for (const r of item.detail || []) layRow(r, dctx, "detail", { level: groups.length });
9439
- if (groups.length && item.widowControl !== false) for (let k = u0; k < units.length; k++) units[k].grp = tableKey + keyPath;
9440
+ if (lc.win && units[u0]) {
9441
+ units[u0].rowHead = true;
9442
+ for (let k = u0; k < units.length; k++) units[k].dataRow = rowNo;
9443
+ }
9444
+ if (groups.length && item.widowControl !== false) for (let k = u0; k < units.length; k++) {
9445
+ units[k].grp = tableKey + keyPath;
9446
+ if (ctx.__before) units[k].grpBefore = ctx.__before;
9447
+ }
9440
9448
  const every = Math.trunc(Number(item.pageBreakEvery)) || 0;
9441
- if (every > 0 && rowNo > 1 && (rowNo - 1) % every === 0 && units[u0]) units[u0].breakBefore = true;
9449
+ if (every > 0 && rowNo > (lc.win?.rowOffset || 0) + 1 && (rowNo - 1) % every === 0 && units[u0]) units[u0].breakBefore = true;
9442
9450
  endBand();
9443
9451
  }
9444
9452
  return;
@@ -9495,11 +9503,11 @@ register("table", {
9495
9503
  }
9496
9504
  const shown = /* @__PURE__ */ new Set();
9497
9505
  const node = (bk, bi, sibs, depth, parentPath) => {
9498
- var _a;
9499
9506
  if (lc.rowBudget?.cut || shown.has(bk)) return;
9500
9507
  shown.add(bk);
9501
9508
  const sc = { rows: bk.rows, index: -1, run: [], number: bi + 1, prevRows: bi > 0 ? sibs[bi - 1].rows : null, siblings: sibRows(sibs), ...kids ? { level: depth, recRows: recOf.get(bk) } : {} };
9502
- const gctx = { ...ctx, fields: bk.rows[0], aggRows: bk.rows, aggIndex: void 0, scopes: { ...ctx.scopes, [gname]: sc }, groupKey: bk.key, group: sc };
9509
+ const cont = bi === 0 && (level === 0 || ctx.__cont) ? lc.win?.cont?.[level] : null;
9510
+ const gctx = { ...ctx, fields: cont ? cont.first : bk.rows[0], aggRows: bk.rows, aggIndex: void 0, scopes: { ...ctx.scopes, [gname]: sc }, groupKey: bk.key, group: sc, __cont: !!cont, __before: cont && level === groups.length - 1 ? cont.before : 0 };
9503
9511
  if (kids) {
9504
9512
  gctx.level = depth;
9505
9513
  if (g.indent) gctx.indent = (ctx.indent || 0) + depth * Number(g.indent);
@@ -9509,10 +9517,15 @@ register("table", {
9509
9517
  const dflt = kids && g.expandLevels != null ? depth < Number(g.expandLevels) : !g.initiallyCollapsed;
9510
9518
  const open = !g.collapsible ? true : lc.state?.toggles?.[tkey] ?? dflt;
9511
9519
  const start = units.length;
9512
- const hctx = g.header?.length ? { ...gctx, pendingRows: fl ? [bk.rows[0]] : recOf.get(bk) || bk.rows } : gctx;
9513
- const hu = (g.header || []).map((r, ri) => layRow(r, hctx, "groupHeader", { level, ...ri === 0 && g.collapsible ? { toggle: { key: tkey, open } } : {} })).filter(Boolean);
9520
+ const hctx = g.header?.length ? { ...gctx, pendingRows: fl ? [cont ? cont.first : bk.rows[0]] : recOf.get(bk) || bk.rows } : gctx;
9521
+ const hu = (cont && !g.repeatHeader ? [] : g.header || []).map((r, ri) => layRow(r, hctx, "groupHeader", { level, ...ri === 0 && g.collapsible ? { toggle: { key: tkey, open } } : {} })).filter(Boolean);
9514
9522
  endBand();
9515
9523
  const before = units.length;
9524
+ if (lc.win && !cont && before > start) {
9525
+ for (let k = start; k < before; k++) units[k].dataRow = rowNo + 1;
9526
+ units[start].rowHead = true;
9527
+ units[start].headLevel = level;
9528
+ }
9516
9529
  const rep = g.repeatHeader && before > start && !lc.fixed ? [...ctx.__rep || [], (() => {
9517
9530
  const hdr = units.slice(start, before), h0 = hdr[0].top, its = [];
9518
9531
  for (const u of hdr) for (const it of shiftLocal(u.items.filter((i) => i.t !== "link" && i.t !== "bookmark"), u.top - h0)) its.push(it);
@@ -9552,7 +9565,10 @@ register("table", {
9552
9565
  if (g.pageBreak === "after" && bi < sibs.length - 1) units[units.length - 1].breakAfter = true;
9553
9566
  if (g.keepTogether) {
9554
9567
  const id = `${item.name}:g${level}:${path}:${lc.nextId()}`;
9555
- for (let k = start; k < units.length; k++) (_a = units[k]).block || (_a.block = id);
9568
+ for (let k = start; k < units.length; k++) if (!units[k].block) {
9569
+ units[k].block = id;
9570
+ if (cont) units[k].blockOpen = true;
9571
+ }
9556
9572
  }
9557
9573
  }
9558
9574
  };
@@ -10478,7 +10494,8 @@ function paginate(units, tables, pageH, warn, stats) {
10478
10494
  if (b) {
10479
10495
  b.top = Math.min(b.top, u.top);
10480
10496
  b.bottom = Math.max(b.bottom, u.top + u.height);
10481
- } else blockMap.set(u.block, { top: u.top, bottom: u.top + u.height });
10497
+ if (u.blockOpen) b.open = true;
10498
+ } else blockMap.set(u.block, { top: u.top, bottom: u.top + u.height, open: !!u.blockOpen });
10482
10499
  }
10483
10500
  const blockUnits = /* @__PURE__ */ new Map();
10484
10501
  for (const u of units) if (u.block) {
@@ -10486,18 +10503,18 @@ function paginate(units, tables, pageH, warn, stats) {
10486
10503
  if (!l) blockUnits.set(u.block, l = []);
10487
10504
  l.push(u);
10488
10505
  }
10489
- const blocks = [...blockMap.values()].filter((b) => b.bottom - b.top <= pageH + EPS2);
10506
+ const blocks = [...blockMap.values()].filter((b) => !b.open && b.bottom - b.top <= pageH + EPS2);
10490
10507
  for (const b of blocks) cand.push(b.top, b.bottom);
10491
10508
  cand.sort((a, b) => a - b);
10492
10509
  const grpRows = /* @__PURE__ */ new Map();
10493
10510
  for (const u of units) if (u.grp) {
10494
10511
  let g = grpRows.get(u.grp);
10495
- if (!g) grpRows.set(u.grp, g = { tops: /* @__PURE__ */ new Set(), first: u.top, last: 0, block: u.block || null });
10512
+ if (!g) grpRows.set(u.grp, g = { tops: /* @__PURE__ */ new Set(), first: u.top, last: 0, block: u.block || null, before: u.grpBefore || 0 });
10496
10513
  g.tops.add(u.top);
10497
10514
  g.last = Math.max(g.last, u.top + u.height);
10498
10515
  if (g.block !== (u.block || null)) g.block = void 0;
10499
10516
  }
10500
- const widowGroups = [...grpRows.values()].map((g) => ({ first: g.first, last: g.last, tops: [...g.tops].sort((a, b) => a - b), block: g.block })).filter((g) => g.tops.length >= 4 || g.tops.length >= 2 && g.last - g.first <= pageH + EPS2).sort((a, b) => a.first - b.first);
10517
+ const widowGroups = [...grpRows.values()].map((g) => ({ first: g.first, last: g.last, tops: [...g.tops].sort((a, b) => a - b), block: g.block, before: g.before, n: g.tops.size + g.before })).filter((g) => g.n >= 4 || !g.before && g.n >= 2 && g.last - g.first <= pageH + EPS2).sort((a, b) => a.first - b.first);
10501
10518
  const wFirst = widowGroups.map((g) => g.first);
10502
10519
  const wMaxLast = [];
10503
10520
  widowGroups.forEach((g, i) => wMaxLast.push(Math.max(i ? wMaxLast[i - 1] : -Infinity, g.last)));
@@ -10524,9 +10541,9 @@ function paginate(units, tables, pageH, warn, stats) {
10524
10541
  tick(1);
10525
10542
  const g = widowGroups[i];
10526
10543
  if (g.last <= y + EPS2 || g.block && !withBlocks) continue;
10527
- if (g.tops.length < 4) return false;
10528
- const above = rowsAbove(g.tops, y);
10529
- if (above < 2 || g.tops.length - above < 2) return false;
10544
+ if (g.n < 4) return false;
10545
+ const above = g.before + rowsAbove(g.tops, y);
10546
+ if (above < 2 || g.n - above < 2) return false;
10530
10547
  }
10531
10548
  return true;
10532
10549
  };
@@ -10581,7 +10598,7 @@ function paginate(units, tables, pageH, warn, stats) {
10581
10598
  if (u.block) {
10582
10599
  const bl = blockMap.get(u.block);
10583
10600
  if (movedBlocks.has(bl)) continue;
10584
- if (!bl || bl.bottom - bl.top > room + EPS2 || bl.top <= top2 + EPS2) return null;
10601
+ if (!bl || bl.open || bl.bottom - bl.top > room + EPS2 || bl.top <= top2 + EPS2) return null;
10585
10602
  movedBlocks.add(bl);
10586
10603
  for (const m of blockUnits.get(u.block)) if (!placed.has(m)) moved.push(m);
10587
10604
  continue;
@@ -13770,14 +13787,16 @@ async function render(def0, opts = {}) {
13770
13787
  ctxFor: (item) => {
13771
13788
  const ds = item.dataSet || defaultDs;
13772
13789
  const rows = ds && dataSets[ds] || [];
13773
- return { ...baseCtx, globals, fields: rows[0] || null, aggRows: rows };
13790
+ return { ...baseCtx, globals, fields: (opts.pageWindow?.first && ds === defaultDs ? opts.pageWindow.first : rows[0]) || null, aggRows: rows };
13774
13791
  },
13775
13792
  subreports: null,
13776
13793
  bodyWidth: opts.bodyWidth ?? page.bodyWidth,
13777
13794
  images: def.images || {},
13778
13795
  imageBudget,
13779
- cellItems: { left: 1e5 }
13796
+ cellItems: { left: 1e5 },
13780
13797
  // rows of items inside table cells, for the whole render (items/index.js)
13798
+ win: opts.pageWindow || null
13799
+ // paged.js: units carry their row number (dataRow, rowHead), rows and groups continue
13781
13800
  };
13782
13801
  return lc;
13783
13802
  };
@@ -13916,12 +13935,14 @@ async function render(def0, opts = {}) {
13916
13935
  const bodyTop = mt + g.hH;
13917
13936
  const items = [];
13918
13937
  const cut = lc.rowBudget?.cut;
13919
- const globals = { ...baseCtx.globals, PageNumber: n - secStart[n] + 1, TotalPages: cut ? "…" : secLen.get(secStart[n]), OverallPageNumber: n + 1, OverallTotalPages: cut ? "…" : total };
13938
+ const win = opts.pageWindow, off = win ? win.offset : 0, all = win ? win.total ?? "…" : null;
13939
+ const globals = { ...baseCtx.globals, PageNumber: n - secStart[n] + 1 + (secStart[n] ? 0 : off), TotalPages: cut ? "…" : all ?? secLen.get(secStart[n]), OverallPageNumber: n + 1 + off, OverallTotalPages: cut ? "…" : all ?? total };
13940
+ const isFirst = n + off === 0, isLast = n === total - 1 && (!win || win.final);
13920
13941
  const plc = makeLc(globals, true);
13921
- const band = (section, y0, isFirst, isLast) => {
13942
+ const band = (section, y0, isFirst2, isLast2) => {
13922
13943
  if (!section) return;
13923
- if (isFirst && section.printOnFirstPage === false) return;
13924
- if (isLast && section.printOnLastPage === false) return;
13944
+ if (isFirst2 && section.printOnFirstPage === false) return;
13945
+ if (isLast2 && section.printOnLastPage === false) return;
13925
13946
  const capped2 = () => warn(`The page headers and footers would draw more than ${BAND_ITEMS.toLocaleString("en-US")} items in this report; they are left out of the later pages. Make them lighter, or the report shorter.`);
13926
13947
  if (bandWork.left <= 0) {
13927
13948
  capped2();
@@ -13942,7 +13963,7 @@ async function render(def0, opts = {}) {
13942
13963
  for (const u of r.units) if (c.paged) placeItems(u.items, ml, y0 + u.top, items);
13943
13964
  else for (const it of shiftItems(u.items, ml, y0 + u.top)) items.push(it);
13944
13965
  };
13945
- band(g.hdr, mt, g.own.h ? k === 0 : n === 0, g.own.h ? last : n === total - 1);
13966
+ band(g.hdr, mt, g.own.h ? k === 0 : isFirst, g.own.h ? last : isLast);
13946
13967
  const frozen = [];
13947
13968
  for (let c = 0; c < colCount; c++) {
13948
13969
  const p = slices[k * colCount + c];
@@ -13952,30 +13973,38 @@ async function render(def0, opts = {}) {
13952
13973
  for (const t of body.tables) {
13953
13974
  if (!(t.top < p.bottom - EPS4 && t.bottom > p.top + EPS4)) continue;
13954
13975
  const cont = p.repeat.includes(t);
13955
- let off = 0;
13976
+ let off2 = 0;
13956
13977
  if (!cont) {
13957
- for (const r of p.repeat) if (t.x0 < r.x1 - EPS4 && r.x0 < t.x1 - EPS4) off = Math.max(off, r.headerHeight);
13978
+ for (const r of p.repeat) if (t.x0 < r.x1 - EPS4 && r.x0 < t.x1 - EPS4) off2 = Math.max(off2, r.headerHeight);
13958
13979
  }
13959
- const y = cont ? bodyTop : bodyTop + off + t.top - p.top;
13960
- frozen.push({ x: cx + t.x0, y, w: t.x1 - t.x0, h: t.headerHeight, end: bodyTop + (cont ? t.headerHeight : off) + Math.min(t.bottom, p.bottom) - p.top });
13980
+ const y = cont ? bodyTop : bodyTop + off2 + t.top - p.top;
13981
+ frozen.push({ x: cx + t.x0, y, w: t.x1 - t.x0, h: t.headerHeight, end: bodyTop + (cont ? t.headerHeight : off2) + Math.min(t.bottom, p.bottom) - p.top });
13961
13982
  }
13962
13983
  for (const u of p.units) {
13963
- let off = 0;
13964
- for (const t of p.repeat) if (u.x0 < t.x1 - EPS4 && t.x0 < u.x1 - EPS4) off = Math.max(off, t.headerHeight);
13965
- if (u.atBottom) off += Math.max(0, cH - off - (p.bottom - p.top));
13966
- if (u.cont && u.top <= p.top + EPS4) placeItems(u.cont, cx, bodyTop + off, items);
13967
- placeItems(u.items, cx, bodyTop + off + (u.top - p.top), items);
13984
+ let off2 = 0;
13985
+ for (const t of p.repeat) if (u.x0 < t.x1 - EPS4 && t.x0 < u.x1 - EPS4) off2 = Math.max(off2, t.headerHeight);
13986
+ if (u.atBottom) off2 += Math.max(0, cH - off2 - (p.bottom - p.top));
13987
+ if (u.cont && u.top <= p.top + EPS4) placeItems(u.cont, cx, bodyTop + off2, items);
13988
+ placeItems(u.items, cx, bodyTop + off2 + (u.top - p.top), items);
13968
13989
  }
13969
13990
  }
13970
- band(g.ftr, ph - pg.margins.bottom - g.fH, g.own.f ? k === 0 : n === 0, g.own.f ? last : n === total - 1);
13991
+ band(g.ftr, ph - pg.margins.bottom - g.fH, g.own.f ? k === 0 : isFirst, g.own.f ? last : isLast);
13971
13992
  let j = 0;
13972
13993
  for (let i = 0; i < items.length; i++) {
13973
13994
  const it = items[i];
13974
- if (it.t === "bookmark") (it.heading ? headings : bookmarks2).push({ label: it.label, page: n + 1, y: it.y, level: it.level || 0, ...secStart[n] ? { shown: n - secStart[n] + 1 } : {} });
13995
+ if (it.t === "bookmark") (it.heading ? headings : bookmarks2).push({ label: it.label, page: n + 1 + off, y: it.y, level: it.level || 0, ...secStart[n] ? { shown: n - secStart[n] + 1 } : {} });
13975
13996
  else items[j++] = it;
13976
13997
  }
13977
13998
  items.length = j;
13978
13999
  const out = frozen.length ? { items, frozen } : { items };
14000
+ if (win) {
14001
+ const u = slices[k * colCount]?.units[0];
14002
+ if (u?.dataRow != null) {
14003
+ out.firstRow = u.dataRow;
14004
+ out.rowHead = !!u.rowHead;
14005
+ if (u.headLevel != null) out.headLevel = u.headLevel;
14006
+ }
14007
+ }
13979
14008
  if (pg.width !== first.width || ph !== pageH) {
13980
14009
  out.width = pg.width;
13981
14010
  out.height = ph;
@@ -14486,7 +14515,7 @@ async function pdfBlob(model, title, o = {}) {
14486
14515
  const store = fontStore();
14487
14516
  await customFonts();
14488
14517
  await store.load(fontKeysOf(model));
14489
- const { exportPdf } = await import("./chunk-66QZ3RDV.js");
14518
+ const { exportPdf } = await import("./chunk-5N6OFCHJ.js");
14490
14519
  const bytes = await exportPdf(model, store, {
14491
14520
  title,
14492
14521
  subset: subsetter,
@@ -14774,4 +14803,4 @@ export {
14774
14803
  serverPdfUrl,
14775
14804
  paramChoices
14776
14805
  };
14777
- //# sourceMappingURL=chunk-WQOBRZAL.js.map
14806
+ //# sourceMappingURL=chunk-M6GENFAH.js.map