@particle-academy/last-word-ui 0.4.1 → 0.5.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.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.5.0] - 2026-11-04
14
+
15
+ ### Added
16
+
17
+ - **Mixed page orientation.** A `pageBreak` carrying `page` changes the page from there on: each page is drawn at its own size and margins, with its own bands, and its text measured at its own width. `margins` merge side by side, every other key is replaced whole, `firstHeader` / `firstFooter` are never inherited and on a break mean the first page after it, and even bands follow the page number. `{section}` counts the stretches and `{sectionpages}` is the page count of the current one, as Word's `SECTION` and `SECTIONPAGES`. One scale serves every page, from the widest.
18
+ - `docStretches()`, `blockStretches()`, `packInput()`, `pageClassIn()`. `paginate()` takes a `stretch` on a break item and `firstEvenPageHeight`; `pageCapacity()` a stretch's first page index.
19
+ - `onLayout` reports `pageSizes` when the document's page changes partway. `pageWidth` and `pageHeight` stay the first page's.
20
+
21
+ ### Changed
22
+
23
+ - The notice no longer fires for a `page` on a top-level break, because that is drawn now. It still fires for what the writers refuse (a nested `page`, a background on a break, page keys straight on a break, a top-level `sections`), in new words. **Consumer action:** none, unless you compared `LAYOUT_NOTICE`'s text.
24
+ - `tests/fixtures/viewer-agreement.json` has a tenth case, recorded in headless Chromium; the first nine did not move.
25
+
13
26
  ## [0.4.1] - 2026-11-03
14
27
 
15
28
  **What you must do: nothing.** A document with a `colSpan` of 1000 or less draws
package/dist/index.cjs CHANGED
@@ -760,8 +760,12 @@ var VARIANT_KEY = {
760
760
  footer: { first: "firstFooter", even: "evenFooter" }
761
761
  };
762
762
  function pageClass(index) {
763
- if (index === 0) return "first";
764
- return index % 2 === 1 ? "even" : "odd";
763
+ return pageClassIn(index, 0);
764
+ }
765
+ function pageClassIn(index, start) {
766
+ const even = index % 2 === 1;
767
+ if (index === start) return even ? "firstEven" : "first";
768
+ return even ? "even" : "odd";
765
769
  }
766
770
  var isBandObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
767
771
  function slotBand(page, kind, slot) {
@@ -771,12 +775,12 @@ function slotBand(page, kind, slot) {
771
775
  return isBandObject(v) ? v : void 0;
772
776
  }
773
777
  function bandSlot(page, kind, cls) {
774
- if (cls === "first" && slotBand(page, kind, "first") !== void 0) return "first";
775
- if (cls === "even" && slotBand(page, kind, "even") !== void 0) return "even";
778
+ if ((cls === "first" || cls === "firstEven") && slotBand(page, kind, "first") !== void 0) return "first";
779
+ if ((cls === "even" || cls === "firstEven") && slotBand(page, kind, "even") !== void 0) return "even";
776
780
  return "default";
777
781
  }
778
- function pageBand(page, kind, index) {
779
- const band = slotBand(page, kind, bandSlot(page, kind, pageClass(index)));
782
+ function pageBand(page, kind, index, start = 0) {
783
+ const band = slotBand(page, kind, bandSlot(page, kind, pageClassIn(index, start)));
780
784
  return hasBand(band) ? band : null;
781
785
  }
782
786
  function pageBodyBoxes(g, page, heights) {
@@ -785,7 +789,7 @@ function pageBodyBoxes(g, page, heights) {
785
789
  return hasBand(slotBand(page, kind, slot)) ? Math.max(0, heights[kind][slot] || 0) : 0;
786
790
  };
787
791
  const box = (cls) => bodyBox(g, height2("header", cls), height2("footer", cls));
788
- return { first: box("first"), even: box("even"), odd: box("odd") };
792
+ return { first: box("first"), even: box("even"), odd: box("odd"), firstEven: box("firstEven") };
789
793
  }
790
794
 
791
795
  // src/footnotes.ts
@@ -836,32 +840,117 @@ function numberFootnotes(doc) {
836
840
  return { marks, notes };
837
841
  }
838
842
 
843
+ // src/stretches.ts
844
+ var isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
845
+ function isPageObject(page) {
846
+ return isObject(page) || Array.isArray(page) && page.length === 0;
847
+ }
848
+ function mergePage(page, change) {
849
+ const out = { ...page ?? {} };
850
+ delete out.firstHeader;
851
+ delete out.firstFooter;
852
+ for (const [key, value] of Object.entries(change)) {
853
+ if (value === void 0 || value === null || key === "background") continue;
854
+ if (key === "margins" && isObject(value) && isObject(out.margins)) {
855
+ const merged = { ...out.margins };
856
+ for (const [side, v] of Object.entries(value)) {
857
+ if (v !== void 0 && v !== null) merged[side] = v;
858
+ }
859
+ out.margins = merged;
860
+ } else {
861
+ out[key] = value;
862
+ }
863
+ }
864
+ return out;
865
+ }
866
+ function docStretches(doc) {
867
+ let page = doc?.page && typeof doc.page === "object" ? doc.page : void 0;
868
+ const make = (breakAt) => ({
869
+ page,
870
+ geometry: pageGeometry({ ...page ? { page } : {}}),
871
+ breakAt
872
+ });
873
+ const out = [make(null)];
874
+ (Array.isArray(doc?.blocks) ? doc.blocks : []).forEach((block, i) => {
875
+ const b = block;
876
+ if (!isObject(b) || b.type !== "pageBreak" || !isPageObject(b.page)) return;
877
+ page = mergePage(page, isObject(b.page) ? b.page : {});
878
+ out.push(make(i));
879
+ });
880
+ return out;
881
+ }
882
+ function blockStretches(stretches, count) {
883
+ const out = [];
884
+ let k = 0;
885
+ for (let i = 0; i < count; i++) {
886
+ while (k + 1 < stretches.length && stretches[k + 1].breakAt <= i) k++;
887
+ out.push(k);
888
+ }
889
+ return out;
890
+ }
891
+ var toPt = (h) => ({
892
+ default: h.default / PX_PER_PT,
893
+ first: h.first / PX_PER_PT,
894
+ even: h.even / PX_PER_PT
895
+ });
896
+ var heightsPt = (h) => ({ header: toPt(h.header), footer: toPt(h.footer) });
897
+ function packInput(stretches, measured) {
898
+ const boxes = stretches.map((s, k) => pageBodyBoxes(s.geometry, s.page, heightsPt(measured.stretchBands[k])));
899
+ const items = measured.items.map((item, i) => {
900
+ const k = stretches.findIndex((s) => s.breakAt === i);
901
+ if (k <= 0) return item;
902
+ const b = boxes[k];
903
+ const stretch = {
904
+ pageHeight: b.odd.height * PX_PER_PT,
905
+ firstPageHeight: b.first.height * PX_PER_PT,
906
+ firstEvenPageHeight: b.firstEven.height * PX_PER_PT,
907
+ evenPageHeight: b.even.height * PX_PER_PT
908
+ };
909
+ return { type: "break", stretch };
910
+ });
911
+ const first = boxes[0];
912
+ return {
913
+ items,
914
+ boxes,
915
+ options: {
916
+ pageHeight: first.odd.height * PX_PER_PT,
917
+ firstPageHeight: first.first.height * PX_PER_PT,
918
+ evenPageHeight: first.even.height * PX_PER_PT,
919
+ footnoteSeparator: measured.footnoteSeparator
920
+ }
921
+ };
922
+ }
923
+
839
924
  // src/layout-notice.ts
840
- var LAYOUT_NOTICE = "Mixed page orientation isn't shown yet. This document asks for different page settings partway through; every page here uses the document's one page setup.";
925
+ var LAYOUT_NOTICE = "Some page settings in this document aren't shown. It sets them somewhere they don't apply: on a page break directly, in a quote or a table cell, or under a sections key.";
841
926
  var NEAR_MISS_KEYS = ["size", "orientation", "margins", "header", "footer", "firstHeader", "firstFooter", "evenHeader", "evenFooter", "background", "border"];
842
- var isObject = (v) => typeof v === "object" && v !== null;
927
+ var isObject2 = (v) => typeof v === "object" && v !== null;
843
928
  function unshownLayout(doc) {
844
929
  const found = [];
845
- if (!isObject(doc)) return found;
930
+ if (!isObject2(doc)) return found;
846
931
  if (doc.sections !== void 0) found.push("/sections");
847
932
  const stack = [{ blocks: doc.blocks, at: "/blocks" }];
848
933
  while (stack.length > 0) {
849
934
  const { blocks, at } = stack.pop();
850
935
  if (!Array.isArray(blocks)) continue;
851
936
  blocks.forEach((block, i) => {
852
- if (!isObject(block)) return;
937
+ if (!isObject2(block)) return;
853
938
  const path = `${at}/${i}`;
854
939
  if (block.type === "pageBreak") {
855
- for (const key of ["page", ...NEAR_MISS_KEYS]) {
940
+ for (const key of NEAR_MISS_KEYS) {
856
941
  if (block[key] !== void 0) found.push(`${path}/${key}`);
857
942
  }
943
+ if (block.page !== void 0) {
944
+ if (at !== "/blocks" || !isPageObject(block.page)) found.push(`${path}/page`);
945
+ else if (isObject2(block.page) && block.page.background !== void 0) found.push(`${path}/page/background`);
946
+ }
858
947
  } else if (block.type === "quote") {
859
948
  stack.push({ blocks: block.blocks, at: `${path}/blocks` });
860
949
  } else if (block.type === "table" && Array.isArray(block.rows)) {
861
950
  block.rows.forEach((row, r) => {
862
- if (!isObject(row) || !Array.isArray(row.cells)) return;
951
+ if (!isObject2(row) || !Array.isArray(row.cells)) return;
863
952
  row.cells.forEach((cell, c) => {
864
- if (isObject(cell)) stack.push({ blocks: cell.blocks, at: `${path}/rows/${r}/cells/${c}/blocks` });
953
+ if (isObject2(cell)) stack.push({ blocks: cell.blocks, at: `${path}/rows/${r}/cells/${c}/blocks` });
865
954
  });
866
955
  });
867
956
  }
@@ -900,7 +989,7 @@ function lineBreakpoints(el) {
900
989
  }
901
990
  return lines.slice(0, -1).map((l) => l[1]).filter((b) => b > 0 && b < total - 0.5);
902
991
  }
903
- function measure(root, blocks) {
992
+ function measure(root, blocks, stretchCount = 1) {
904
993
  const noteHeights = /* @__PURE__ */ new Map();
905
994
  root.querySelectorAll("[data-lw-measure-footnote]").forEach((el) => {
906
995
  noteHeights.set(Number(el.dataset.lwMeasureFootnote), height(el));
@@ -944,17 +1033,23 @@ function measure(root, blocks) {
944
1033
  ...notes.length ? { footnotes: notes } : {}
945
1034
  };
946
1035
  });
947
- const bands = { header: {}, footer: {} };
948
- for (const kind of ["header", "footer"]) {
949
- for (const slot of BAND_SLOTS) {
950
- bands[kind][slot] = height(root.querySelector(`[data-lw-measure-band="${kind}:${slot}"]`));
1036
+ const stretchBands = Array.from({ length: Math.max(1, stretchCount) }, (_, k) => {
1037
+ const bands2 = { header: {}, footer: {} };
1038
+ for (const kind of ["header", "footer"]) {
1039
+ for (const slot of BAND_SLOTS) {
1040
+ const at = k === 0 ? `${kind}:${slot}` : `${k + 1}:${kind}:${slot}`;
1041
+ bands2[kind][slot] = height(root.querySelector(`[data-lw-measure-band="${at}"]`));
1042
+ }
951
1043
  }
952
- }
1044
+ return bands2;
1045
+ });
1046
+ const bands = stretchBands[0];
953
1047
  return {
954
1048
  items,
955
1049
  headerHeight: bands.header.default,
956
1050
  footerHeight: bands.footer.default,
957
1051
  bands,
1052
+ stretchBands,
958
1053
  footnoteSeparator: height(root.querySelector("[data-lw-measure-separator]"))
959
1054
  };
960
1055
  }
@@ -962,13 +1057,20 @@ function measure(root, blocks) {
962
1057
  // src/paginate.ts
963
1058
  var EPS = 1e-6;
964
1059
  var positive = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
965
- function pageCapacity(options, index) {
1060
+ function pageCapacity(options, index, start = 0) {
966
1061
  const base = Math.max(1, positive(options.pageHeight) ? options.pageHeight : 1);
967
- if (index === 0) return positive(options.firstPageHeight) ? Math.max(1, options.firstPageHeight) : base;
968
- if (index % 2 === 1) return positive(options.evenPageHeight) ? Math.max(1, options.evenPageHeight) : base;
1062
+ const even = index % 2 === 1;
1063
+ if (index === start) {
1064
+ const first = even ? options.firstEvenPageHeight : options.firstPageHeight;
1065
+ if (positive(first)) return Math.max(1, first);
1066
+ }
1067
+ if (even) return positive(options.evenPageHeight) ? Math.max(1, options.evenPageHeight) : base;
969
1068
  return base;
970
1069
  }
971
- function paginate(items, options) {
1070
+ function paginate(items, initial) {
1071
+ let options = initial;
1072
+ let stretchStart = 0;
1073
+ let stretch = 0;
972
1074
  let cap = pageCapacity(options, 0);
973
1075
  const sep = Math.max(0, options.footnoteSeparator ?? 0);
974
1076
  const pages = [];
@@ -976,8 +1078,8 @@ function paginate(items, options) {
976
1078
  let content = 0;
977
1079
  let noteHeights = 0;
978
1080
  const newPage = () => {
979
- cap = pageCapacity(options, pages.length);
980
- page = { index: pages.length, fragments: [], footnotes: [], used: 0, capacity: cap };
1081
+ cap = pageCapacity(options, pages.length, stretchStart);
1082
+ page = { index: pages.length, fragments: [], footnotes: [], used: 0, capacity: cap, ...stretch > 0 ? { stretch } : {} };
981
1083
  pages.push(page);
982
1084
  content = 0;
983
1085
  noteHeights = 0;
@@ -999,6 +1101,11 @@ function paginate(items, options) {
999
1101
  newPage();
1000
1102
  items.forEach((item, index) => {
1001
1103
  if (item.type === "break") {
1104
+ if (item.stretch) {
1105
+ options = { footnoteSeparator: options.footnoteSeparator, ...item.stretch };
1106
+ stretchStart = pages.length;
1107
+ stretch++;
1108
+ }
1002
1109
  newPage();
1003
1110
  return;
1004
1111
  }
@@ -1047,7 +1154,7 @@ function paginate(items, options) {
1047
1154
  const chain = keepChainHeight(index);
1048
1155
  const next = items[index + 1];
1049
1156
  const meaningful = next !== void 0 && next.type !== "break";
1050
- const nextCap = pageCapacity(options, page.index + 1);
1157
+ const nextCap = pageCapacity(options, page.index + 1, stretchStart);
1051
1158
  if (meaningful && chain <= nextCap + EPS && !fits(chain, notesIn(item, 0, height2, true))) newPage();
1052
1159
  }
1053
1160
  let start = 0;
@@ -1281,17 +1388,25 @@ function DocViewer({
1281
1388
  className,
1282
1389
  style
1283
1390
  }) {
1284
- const geometry = react.useMemo(() => pageGeometry(doc), [doc]);
1391
+ const stretches = react.useMemo(() => docStretches(doc), [doc]);
1392
+ const geometry = stretches[0].geometry;
1285
1393
  const numbering = react.useMemo(() => numberFootnotes(doc), [doc]);
1286
1394
  const blocks = react.useMemo(() => Array.isArray(doc?.blocks) ? doc.blocks : [], [doc]);
1287
- const page = doc?.page && typeof doc.page === "object" ? doc.page : void 0;
1395
+ const blockStretch = react.useMemo(() => blockStretches(stretches, blocks.length), [stretches, blocks]);
1396
+ const noteStretch = react.useMemo(() => {
1397
+ const out = /* @__PURE__ */ new Map();
1398
+ let id2 = 0;
1399
+ blocks.forEach((block, i) => {
1400
+ for (let n = numberFootnotes({ blocks: [block] }).notes.length; n > 0; n--) out.set(++id2, blockStretch[i]);
1401
+ });
1402
+ return out;
1403
+ }, [blocks, blockStretch]);
1288
1404
  const nowKey = now instanceof Date ? now.getTime() : now;
1289
1405
  const nowDate = react.useMemo(() => resolveNow(nowKey === void 0 ? void 0 : typeof nowKey === "number" ? new Date(nowKey) : nowKey), [nowKey]);
1290
1406
  const author = doc?.meta && typeof doc.meta === "object" ? doc.meta.author : void 0;
1291
1407
  const title = doc?.title;
1292
1408
  const docFields = react.useMemo(
1293
1409
  () => ({
1294
- section: 1,
1295
1410
  ...typeof author === "string" ? { author } : {},
1296
1411
  ...typeof title === "string" ? { title } : {},
1297
1412
  ...typeof filename === "string" ? { filename } : {},
@@ -1316,6 +1431,7 @@ function DocViewer({
1316
1431
  }),
1317
1432
  [numbering, doc, geometry]
1318
1433
  );
1434
+ const ctxOf = (k) => ({ ...ctx, contentWidth: stretches[k].geometry.contentWidth });
1319
1435
  react.useEffect(() => {
1320
1436
  const state = initialFontState(faces);
1321
1437
  setFont(state);
@@ -1331,22 +1447,12 @@ function DocViewer({
1331
1447
  react.useLayoutEffect(() => {
1332
1448
  const el = measureRef.current;
1333
1449
  if (!el || font === "pending") return;
1334
- const m = measure(el, blocks);
1335
- const toPt = (h) => ({
1336
- default: h.default / PX_PER_PT,
1337
- first: h.first / PX_PER_PT,
1338
- even: h.even / PX_PER_PT
1339
- });
1340
- const boxes = pageBodyBoxes(geometry, page, { header: toPt(m.bands.header), footer: toPt(m.bands.footer) });
1341
- const pages = paginate(m.items, {
1342
- pageHeight: boxes.odd.height * PX_PER_PT,
1343
- firstPageHeight: boxes.first.height * PX_PER_PT,
1344
- evenPageHeight: boxes.even.height * PX_PER_PT,
1345
- footnoteSeparator: m.footnoteSeparator
1346
- });
1450
+ const m = measure(el, blocks, stretches.length);
1451
+ const input = packInput(stretches, m);
1452
+ const pages = paginate(input.items, input.options);
1347
1453
  const heights = m.items.map((it) => it.type === "block" ? it.height : 0);
1348
- setLayout({ pages, boxes, heights });
1349
- }, [blocks, geometry, numbering, fontEpoch, page, docFields, font]);
1454
+ setLayout({ pages, boxes: input.boxes, heights });
1455
+ }, [blocks, stretches, numbering, fontEpoch, docFields, font]);
1350
1456
  react.useEffect(() => {
1351
1457
  const fonts = typeof document !== "undefined" ? document.fonts : void 0;
1352
1458
  let live = true;
@@ -1367,7 +1473,7 @@ function DocViewer({
1367
1473
  ro.observe(el);
1368
1474
  return () => ro.disconnect();
1369
1475
  }, []);
1370
- const pageWpx = geometry.width * PX_PER_PT;
1476
+ const pageWpx = Math.max(...stretches.map((s) => s.geometry.width)) * PX_PER_PT;
1371
1477
  const scale = typeof fixedScale === "number" && fixedScale > 0 ? fixedScale : fit === "none" || !width ? 1 : Math.min(maxScale, width / pageWpx);
1372
1478
  const notShown = react.useMemo(() => unshownLayout(doc), [doc]);
1373
1479
  const pageCount = layout?.pages.length ?? 0;
@@ -1377,12 +1483,13 @@ function DocViewer({
1377
1483
  pages: layout.pages.length,
1378
1484
  pageWidth: geometry.width,
1379
1485
  pageHeight: geometry.height,
1486
+ ...stretches.length > 1 ? { pageSizes: layout.pages.map((p) => ({ width: stretches[p.stretch ?? 0].geometry.width, height: stretches[p.stretch ?? 0].geometry.height })) } : {},
1380
1487
  scale,
1381
1488
  font,
1382
1489
  ...notShown.length > 0 ? { notShown } : {}
1383
1490
  });
1384
1491
  }
1385
- }, [layout, geometry, scale, onLayout, font, notShown]);
1492
+ }, [layout, geometry, stretches, scale, onLayout, font, notShown]);
1386
1493
  const typography2 = typography(doc?.defaultFont, ctx.size);
1387
1494
  const ready = layout !== null && font !== "pending";
1388
1495
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1415,49 +1522,74 @@ function DocViewer({
1415
1522
  width: pt(geometry.contentWidth)
1416
1523
  },
1417
1524
  children: /* @__PURE__ */ jsxRuntime.jsxs(RenderCtx.Provider, { value: ctx, children: [
1418
- ["header", "footer"].flatMap(
1419
- (kind) => BAND_SLOTS.map((slot) => {
1420
- const band = slotBand(page, kind, slot);
1421
- if (!hasBand(band)) return null;
1422
- const n = slot === "even" ? 2 : 1;
1423
- return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-measure-band": `${kind}:${slot}`, children: /* @__PURE__ */ jsxRuntime.jsx(RenderCtx.Provider, { value: { ...ctx, fields: { ...docFields, page: n, pages: n } }, children: /* @__PURE__ */ jsxRuntime.jsx(BandView, { band }) }) }, `${kind}:${slot}`);
1424
- })
1525
+ stretches.flatMap(
1526
+ (stretch, k) => ["header", "footer"].flatMap(
1527
+ (kind) => BAND_SLOTS.map((slot) => {
1528
+ const band = slotBand(stretch.page, kind, slot);
1529
+ if (!hasBand(band)) return null;
1530
+ const n = slot === "even" ? 2 : 1;
1531
+ const at = k === 0 ? `${kind}:${slot}` : `${k + 1}:${kind}:${slot}`;
1532
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-measure-band": at, style: stretches.length > 1 ? { width: pt(stretch.geometry.contentWidth) } : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(RenderCtx.Provider, { value: { ...ctxOf(k), fields: { ...docFields, section: k + 1, page: n, pages: n } }, children: /* @__PURE__ */ jsxRuntime.jsx(BandView, { band }) }) }, at);
1533
+ })
1534
+ )
1425
1535
  ),
1426
- blocks.map((b, i) => /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-measure-block": i, style: { display: "flow-root" }, children: /* @__PURE__ */ jsxRuntime.jsx(BlockView, { block: b }) }, i)),
1427
- numbering.notes.map((n) => /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-measure-footnote": n.id, children: /* @__PURE__ */ jsxRuntime.jsx(FootnoteView, { id: n.id, footnote: n.footnote }) }, n.id)),
1536
+ blocks.map((b, i) => {
1537
+ const k = blockStretch[i];
1538
+ return /* @__PURE__ */ jsxRuntime.jsx(
1539
+ "div",
1540
+ {
1541
+ "data-lw-measure-block": i,
1542
+ style: { display: "flow-root", ...stretches.length > 1 ? { width: pt(stretches[k].geometry.contentWidth) } : {} },
1543
+ children: /* @__PURE__ */ jsxRuntime.jsx(RenderCtx.Provider, { value: ctxOf(k), children: /* @__PURE__ */ jsxRuntime.jsx(BlockView, { block: b }) })
1544
+ },
1545
+ i
1546
+ );
1547
+ }),
1548
+ numbering.notes.map((n) => {
1549
+ const k = noteStretch.get(n.id) ?? 0;
1550
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-measure-footnote": n.id, style: stretches.length > 1 ? { width: pt(stretches[k].geometry.contentWidth) } : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(RenderCtx.Provider, { value: ctxOf(k), children: /* @__PURE__ */ jsxRuntime.jsx(FootnoteView, { id: n.id, footnote: n.footnote }) }) }, n.id);
1551
+ }),
1428
1552
  numbering.notes.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-measure-separator": "", children: /* @__PURE__ */ jsxRuntime.jsx(FootnoteSeparator, { height: pt(FOOTNOTE_SEPARATOR_PT) }) })
1429
1553
  ] })
1430
1554
  }
1431
1555
  ),
1432
- ready && layout && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) => /* @__PURE__ */ jsxRuntime.jsx(
1433
- PageView,
1434
- {
1435
- page: p,
1436
- pages: layout.pages.length,
1437
- geometry,
1438
- box: layout.boxes[pageClass(p.index)],
1439
- scale,
1440
- typography: typography2,
1441
- ctx,
1442
- docPage: page,
1443
- docFields,
1444
- numbering,
1445
- blocks,
1446
- heights: layout.heights
1447
- },
1448
- p.index
1449
- )) })
1556
+ ready && layout && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) => {
1557
+ const k = p.stretch ?? 0;
1558
+ const inStretch = layout.pages.filter((x) => (x.stretch ?? 0) === k);
1559
+ const start = inStretch[0].index;
1560
+ return /* @__PURE__ */ jsxRuntime.jsx(
1561
+ PageView,
1562
+ {
1563
+ page: p,
1564
+ pages: layout.pages.length,
1565
+ section: k + 1,
1566
+ sectionPages: inStretch.length,
1567
+ start,
1568
+ stretch: stretches[k],
1569
+ box: layout.boxes[k][pageClassIn(p.index, start)],
1570
+ scale,
1571
+ typography: typography2,
1572
+ ctx: ctxOf(k),
1573
+ docFields,
1574
+ numbering,
1575
+ blocks,
1576
+ heights: layout.heights
1577
+ },
1578
+ p.index
1579
+ );
1580
+ }) })
1450
1581
  ]
1451
1582
  }
1452
1583
  );
1453
1584
  }
1454
- function PageView({ page, pages, geometry, box, scale, typography: typography2, ctx, docPage, docFields, numbering, blocks, heights }) {
1585
+ function PageView({ page, pages, section, sectionPages, start, stretch, box, scale, typography: typography2, ctx, docFields, numbering, blocks, heights }) {
1455
1586
  const n = page.index + 1;
1456
- const g = geometry;
1457
- const bandCtx = { ...ctx, fields: { ...docFields, page: n, pages, sectionPages: pages } };
1458
- const cls = pageClass(page.index);
1459
- const header = pageBand(docPage, "header", page.index);
1460
- const footer = pageBand(docPage, "footer", page.index);
1587
+ const g = stretch.geometry;
1588
+ const docPage = stretch.page;
1589
+ const bandCtx = { ...ctx, fields: { ...docFields, page: n, pages, section, sectionPages } };
1590
+ const cls = pageClassIn(page.index, start);
1591
+ const header = pageBand(docPage, "header", page.index, start);
1592
+ const footer = pageBand(docPage, "footer", page.index, start);
1461
1593
  const variant = (kind) => bandSlot(docPage, kind, cls);
1462
1594
  const notes = page.footnotes.map((fid) => numbering.notes.find((x) => x.id === fid)).filter((x) => !!x);
1463
1595
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -1587,16 +1719,20 @@ exports.PAGE_MARGIN_DEFAULT = PAGE_MARGIN_DEFAULT;
1587
1719
  exports.PAGE_SIZES_PT = PAGE_SIZES_PT;
1588
1720
  exports.PX_PER_PT = PX_PER_PT;
1589
1721
  exports.bandSlot = bandSlot;
1722
+ exports.blockStretches = blockStretches;
1590
1723
  exports.bodyBox = bodyBox;
1591
1724
  exports.carlitoFaces = carlitoFaces;
1592
1725
  exports.docFromReader = docFromReader;
1726
+ exports.docStretches = docStretches;
1593
1727
  exports.fontFaceCss = fontFaceCss;
1594
1728
  exports.formatDatePicture = formatDatePicture;
1595
1729
  exports.numberFootnotes = numberFootnotes;
1730
+ exports.packInput = packInput;
1596
1731
  exports.pageBand = pageBand;
1597
1732
  exports.pageBodyBoxes = pageBodyBoxes;
1598
1733
  exports.pageCapacity = pageCapacity;
1599
1734
  exports.pageClass = pageClass;
1735
+ exports.pageClassIn = pageClassIn;
1600
1736
  exports.pageGeometry = pageGeometry;
1601
1737
  exports.pageMargins = pageMargins;
1602
1738
  exports.paginate = paginate;