@particle-academy/last-word-ui 0.4.0 → 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 +27 -0
- package/dist/index.cjs +232 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -25
- package/dist/index.d.ts +87 -25
- package/dist/index.js +229 -88
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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 (
|
|
402
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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 };
|
|
@@ -748,8 +757,12 @@ var VARIANT_KEY = {
|
|
|
748
757
|
footer: { first: "firstFooter", even: "evenFooter" }
|
|
749
758
|
};
|
|
750
759
|
function pageClass(index) {
|
|
751
|
-
|
|
752
|
-
|
|
760
|
+
return pageClassIn(index, 0);
|
|
761
|
+
}
|
|
762
|
+
function pageClassIn(index, start) {
|
|
763
|
+
const even = index % 2 === 1;
|
|
764
|
+
if (index === start) return even ? "firstEven" : "first";
|
|
765
|
+
return even ? "even" : "odd";
|
|
753
766
|
}
|
|
754
767
|
var isBandObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
755
768
|
function slotBand(page, kind, slot) {
|
|
@@ -759,12 +772,12 @@ function slotBand(page, kind, slot) {
|
|
|
759
772
|
return isBandObject(v) ? v : void 0;
|
|
760
773
|
}
|
|
761
774
|
function bandSlot(page, kind, cls) {
|
|
762
|
-
if (cls === "first" && slotBand(page, kind, "first") !== void 0) return "first";
|
|
763
|
-
if (cls === "even" && slotBand(page, kind, "even") !== void 0) return "even";
|
|
775
|
+
if ((cls === "first" || cls === "firstEven") && slotBand(page, kind, "first") !== void 0) return "first";
|
|
776
|
+
if ((cls === "even" || cls === "firstEven") && slotBand(page, kind, "even") !== void 0) return "even";
|
|
764
777
|
return "default";
|
|
765
778
|
}
|
|
766
|
-
function pageBand(page, kind, index) {
|
|
767
|
-
const band = slotBand(page, kind, bandSlot(page, kind,
|
|
779
|
+
function pageBand(page, kind, index, start = 0) {
|
|
780
|
+
const band = slotBand(page, kind, bandSlot(page, kind, pageClassIn(index, start)));
|
|
768
781
|
return hasBand(band) ? band : null;
|
|
769
782
|
}
|
|
770
783
|
function pageBodyBoxes(g, page, heights) {
|
|
@@ -773,7 +786,7 @@ function pageBodyBoxes(g, page, heights) {
|
|
|
773
786
|
return hasBand(slotBand(page, kind, slot)) ? Math.max(0, heights[kind][slot] || 0) : 0;
|
|
774
787
|
};
|
|
775
788
|
const box = (cls) => bodyBox(g, height2("header", cls), height2("footer", cls));
|
|
776
|
-
return { first: box("first"), even: box("even"), odd: box("odd") };
|
|
789
|
+
return { first: box("first"), even: box("even"), odd: box("odd"), firstEven: box("firstEven") };
|
|
777
790
|
}
|
|
778
791
|
|
|
779
792
|
// src/footnotes.ts
|
|
@@ -824,32 +837,117 @@ function numberFootnotes(doc) {
|
|
|
824
837
|
return { marks, notes };
|
|
825
838
|
}
|
|
826
839
|
|
|
840
|
+
// src/stretches.ts
|
|
841
|
+
var isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
842
|
+
function isPageObject(page) {
|
|
843
|
+
return isObject(page) || Array.isArray(page) && page.length === 0;
|
|
844
|
+
}
|
|
845
|
+
function mergePage(page, change) {
|
|
846
|
+
const out = { ...page ?? {} };
|
|
847
|
+
delete out.firstHeader;
|
|
848
|
+
delete out.firstFooter;
|
|
849
|
+
for (const [key, value] of Object.entries(change)) {
|
|
850
|
+
if (value === void 0 || value === null || key === "background") continue;
|
|
851
|
+
if (key === "margins" && isObject(value) && isObject(out.margins)) {
|
|
852
|
+
const merged = { ...out.margins };
|
|
853
|
+
for (const [side, v] of Object.entries(value)) {
|
|
854
|
+
if (v !== void 0 && v !== null) merged[side] = v;
|
|
855
|
+
}
|
|
856
|
+
out.margins = merged;
|
|
857
|
+
} else {
|
|
858
|
+
out[key] = value;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return out;
|
|
862
|
+
}
|
|
863
|
+
function docStretches(doc) {
|
|
864
|
+
let page = doc?.page && typeof doc.page === "object" ? doc.page : void 0;
|
|
865
|
+
const make = (breakAt) => ({
|
|
866
|
+
page,
|
|
867
|
+
geometry: pageGeometry({ ...page ? { page } : {}}),
|
|
868
|
+
breakAt
|
|
869
|
+
});
|
|
870
|
+
const out = [make(null)];
|
|
871
|
+
(Array.isArray(doc?.blocks) ? doc.blocks : []).forEach((block, i) => {
|
|
872
|
+
const b = block;
|
|
873
|
+
if (!isObject(b) || b.type !== "pageBreak" || !isPageObject(b.page)) return;
|
|
874
|
+
page = mergePage(page, isObject(b.page) ? b.page : {});
|
|
875
|
+
out.push(make(i));
|
|
876
|
+
});
|
|
877
|
+
return out;
|
|
878
|
+
}
|
|
879
|
+
function blockStretches(stretches, count) {
|
|
880
|
+
const out = [];
|
|
881
|
+
let k = 0;
|
|
882
|
+
for (let i = 0; i < count; i++) {
|
|
883
|
+
while (k + 1 < stretches.length && stretches[k + 1].breakAt <= i) k++;
|
|
884
|
+
out.push(k);
|
|
885
|
+
}
|
|
886
|
+
return out;
|
|
887
|
+
}
|
|
888
|
+
var toPt = (h) => ({
|
|
889
|
+
default: h.default / PX_PER_PT,
|
|
890
|
+
first: h.first / PX_PER_PT,
|
|
891
|
+
even: h.even / PX_PER_PT
|
|
892
|
+
});
|
|
893
|
+
var heightsPt = (h) => ({ header: toPt(h.header), footer: toPt(h.footer) });
|
|
894
|
+
function packInput(stretches, measured) {
|
|
895
|
+
const boxes = stretches.map((s, k) => pageBodyBoxes(s.geometry, s.page, heightsPt(measured.stretchBands[k])));
|
|
896
|
+
const items = measured.items.map((item, i) => {
|
|
897
|
+
const k = stretches.findIndex((s) => s.breakAt === i);
|
|
898
|
+
if (k <= 0) return item;
|
|
899
|
+
const b = boxes[k];
|
|
900
|
+
const stretch = {
|
|
901
|
+
pageHeight: b.odd.height * PX_PER_PT,
|
|
902
|
+
firstPageHeight: b.first.height * PX_PER_PT,
|
|
903
|
+
firstEvenPageHeight: b.firstEven.height * PX_PER_PT,
|
|
904
|
+
evenPageHeight: b.even.height * PX_PER_PT
|
|
905
|
+
};
|
|
906
|
+
return { type: "break", stretch };
|
|
907
|
+
});
|
|
908
|
+
const first = boxes[0];
|
|
909
|
+
return {
|
|
910
|
+
items,
|
|
911
|
+
boxes,
|
|
912
|
+
options: {
|
|
913
|
+
pageHeight: first.odd.height * PX_PER_PT,
|
|
914
|
+
firstPageHeight: first.first.height * PX_PER_PT,
|
|
915
|
+
evenPageHeight: first.even.height * PX_PER_PT,
|
|
916
|
+
footnoteSeparator: measured.footnoteSeparator
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
|
|
827
921
|
// src/layout-notice.ts
|
|
828
|
-
var LAYOUT_NOTICE = "
|
|
922
|
+
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.";
|
|
829
923
|
var NEAR_MISS_KEYS = ["size", "orientation", "margins", "header", "footer", "firstHeader", "firstFooter", "evenHeader", "evenFooter", "background", "border"];
|
|
830
|
-
var
|
|
924
|
+
var isObject2 = (v) => typeof v === "object" && v !== null;
|
|
831
925
|
function unshownLayout(doc) {
|
|
832
926
|
const found = [];
|
|
833
|
-
if (!
|
|
927
|
+
if (!isObject2(doc)) return found;
|
|
834
928
|
if (doc.sections !== void 0) found.push("/sections");
|
|
835
929
|
const stack = [{ blocks: doc.blocks, at: "/blocks" }];
|
|
836
930
|
while (stack.length > 0) {
|
|
837
931
|
const { blocks, at } = stack.pop();
|
|
838
932
|
if (!Array.isArray(blocks)) continue;
|
|
839
933
|
blocks.forEach((block, i) => {
|
|
840
|
-
if (!
|
|
934
|
+
if (!isObject2(block)) return;
|
|
841
935
|
const path = `${at}/${i}`;
|
|
842
936
|
if (block.type === "pageBreak") {
|
|
843
|
-
for (const key of
|
|
937
|
+
for (const key of NEAR_MISS_KEYS) {
|
|
844
938
|
if (block[key] !== void 0) found.push(`${path}/${key}`);
|
|
845
939
|
}
|
|
940
|
+
if (block.page !== void 0) {
|
|
941
|
+
if (at !== "/blocks" || !isPageObject(block.page)) found.push(`${path}/page`);
|
|
942
|
+
else if (isObject2(block.page) && block.page.background !== void 0) found.push(`${path}/page/background`);
|
|
943
|
+
}
|
|
846
944
|
} else if (block.type === "quote") {
|
|
847
945
|
stack.push({ blocks: block.blocks, at: `${path}/blocks` });
|
|
848
946
|
} else if (block.type === "table" && Array.isArray(block.rows)) {
|
|
849
947
|
block.rows.forEach((row, r) => {
|
|
850
|
-
if (!
|
|
948
|
+
if (!isObject2(row) || !Array.isArray(row.cells)) return;
|
|
851
949
|
row.cells.forEach((cell, c) => {
|
|
852
|
-
if (
|
|
950
|
+
if (isObject2(cell)) stack.push({ blocks: cell.blocks, at: `${path}/rows/${r}/cells/${c}/blocks` });
|
|
853
951
|
});
|
|
854
952
|
});
|
|
855
953
|
}
|
|
@@ -888,7 +986,7 @@ function lineBreakpoints(el) {
|
|
|
888
986
|
}
|
|
889
987
|
return lines.slice(0, -1).map((l) => l[1]).filter((b) => b > 0 && b < total - 0.5);
|
|
890
988
|
}
|
|
891
|
-
function measure(root, blocks) {
|
|
989
|
+
function measure(root, blocks, stretchCount = 1) {
|
|
892
990
|
const noteHeights = /* @__PURE__ */ new Map();
|
|
893
991
|
root.querySelectorAll("[data-lw-measure-footnote]").forEach((el) => {
|
|
894
992
|
noteHeights.set(Number(el.dataset.lwMeasureFootnote), height(el));
|
|
@@ -932,17 +1030,23 @@ function measure(root, blocks) {
|
|
|
932
1030
|
...notes.length ? { footnotes: notes } : {}
|
|
933
1031
|
};
|
|
934
1032
|
});
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
for (const
|
|
938
|
-
|
|
1033
|
+
const stretchBands = Array.from({ length: Math.max(1, stretchCount) }, (_, k) => {
|
|
1034
|
+
const bands2 = { header: {}, footer: {} };
|
|
1035
|
+
for (const kind of ["header", "footer"]) {
|
|
1036
|
+
for (const slot of BAND_SLOTS) {
|
|
1037
|
+
const at = k === 0 ? `${kind}:${slot}` : `${k + 1}:${kind}:${slot}`;
|
|
1038
|
+
bands2[kind][slot] = height(root.querySelector(`[data-lw-measure-band="${at}"]`));
|
|
1039
|
+
}
|
|
939
1040
|
}
|
|
940
|
-
|
|
1041
|
+
return bands2;
|
|
1042
|
+
});
|
|
1043
|
+
const bands = stretchBands[0];
|
|
941
1044
|
return {
|
|
942
1045
|
items,
|
|
943
1046
|
headerHeight: bands.header.default,
|
|
944
1047
|
footerHeight: bands.footer.default,
|
|
945
1048
|
bands,
|
|
1049
|
+
stretchBands,
|
|
946
1050
|
footnoteSeparator: height(root.querySelector("[data-lw-measure-separator]"))
|
|
947
1051
|
};
|
|
948
1052
|
}
|
|
@@ -950,13 +1054,20 @@ function measure(root, blocks) {
|
|
|
950
1054
|
// src/paginate.ts
|
|
951
1055
|
var EPS = 1e-6;
|
|
952
1056
|
var positive = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
953
|
-
function pageCapacity(options, index) {
|
|
1057
|
+
function pageCapacity(options, index, start = 0) {
|
|
954
1058
|
const base = Math.max(1, positive(options.pageHeight) ? options.pageHeight : 1);
|
|
955
|
-
|
|
956
|
-
if (index
|
|
1059
|
+
const even = index % 2 === 1;
|
|
1060
|
+
if (index === start) {
|
|
1061
|
+
const first = even ? options.firstEvenPageHeight : options.firstPageHeight;
|
|
1062
|
+
if (positive(first)) return Math.max(1, first);
|
|
1063
|
+
}
|
|
1064
|
+
if (even) return positive(options.evenPageHeight) ? Math.max(1, options.evenPageHeight) : base;
|
|
957
1065
|
return base;
|
|
958
1066
|
}
|
|
959
|
-
function paginate(items,
|
|
1067
|
+
function paginate(items, initial) {
|
|
1068
|
+
let options = initial;
|
|
1069
|
+
let stretchStart = 0;
|
|
1070
|
+
let stretch = 0;
|
|
960
1071
|
let cap = pageCapacity(options, 0);
|
|
961
1072
|
const sep = Math.max(0, options.footnoteSeparator ?? 0);
|
|
962
1073
|
const pages = [];
|
|
@@ -964,8 +1075,8 @@ function paginate(items, options) {
|
|
|
964
1075
|
let content = 0;
|
|
965
1076
|
let noteHeights = 0;
|
|
966
1077
|
const newPage = () => {
|
|
967
|
-
cap = pageCapacity(options, pages.length);
|
|
968
|
-
page = { index: pages.length, fragments: [], footnotes: [], used: 0, capacity: cap };
|
|
1078
|
+
cap = pageCapacity(options, pages.length, stretchStart);
|
|
1079
|
+
page = { index: pages.length, fragments: [], footnotes: [], used: 0, capacity: cap, ...stretch > 0 ? { stretch } : {} };
|
|
969
1080
|
pages.push(page);
|
|
970
1081
|
content = 0;
|
|
971
1082
|
noteHeights = 0;
|
|
@@ -987,6 +1098,11 @@ function paginate(items, options) {
|
|
|
987
1098
|
newPage();
|
|
988
1099
|
items.forEach((item, index) => {
|
|
989
1100
|
if (item.type === "break") {
|
|
1101
|
+
if (item.stretch) {
|
|
1102
|
+
options = { footnoteSeparator: options.footnoteSeparator, ...item.stretch };
|
|
1103
|
+
stretchStart = pages.length;
|
|
1104
|
+
stretch++;
|
|
1105
|
+
}
|
|
990
1106
|
newPage();
|
|
991
1107
|
return;
|
|
992
1108
|
}
|
|
@@ -1035,7 +1151,7 @@ function paginate(items, options) {
|
|
|
1035
1151
|
const chain = keepChainHeight(index);
|
|
1036
1152
|
const next = items[index + 1];
|
|
1037
1153
|
const meaningful = next !== void 0 && next.type !== "break";
|
|
1038
|
-
const nextCap = pageCapacity(options, page.index + 1);
|
|
1154
|
+
const nextCap = pageCapacity(options, page.index + 1, stretchStart);
|
|
1039
1155
|
if (meaningful && chain <= nextCap + EPS && !fits(chain, notesIn(item, 0, height2, true))) newPage();
|
|
1040
1156
|
}
|
|
1041
1157
|
let start = 0;
|
|
@@ -1269,17 +1385,25 @@ function DocViewer({
|
|
|
1269
1385
|
className,
|
|
1270
1386
|
style
|
|
1271
1387
|
}) {
|
|
1272
|
-
const
|
|
1388
|
+
const stretches = useMemo(() => docStretches(doc), [doc]);
|
|
1389
|
+
const geometry = stretches[0].geometry;
|
|
1273
1390
|
const numbering = useMemo(() => numberFootnotes(doc), [doc]);
|
|
1274
1391
|
const blocks = useMemo(() => Array.isArray(doc?.blocks) ? doc.blocks : [], [doc]);
|
|
1275
|
-
const
|
|
1392
|
+
const blockStretch = useMemo(() => blockStretches(stretches, blocks.length), [stretches, blocks]);
|
|
1393
|
+
const noteStretch = useMemo(() => {
|
|
1394
|
+
const out = /* @__PURE__ */ new Map();
|
|
1395
|
+
let id2 = 0;
|
|
1396
|
+
blocks.forEach((block, i) => {
|
|
1397
|
+
for (let n = numberFootnotes({ blocks: [block] }).notes.length; n > 0; n--) out.set(++id2, blockStretch[i]);
|
|
1398
|
+
});
|
|
1399
|
+
return out;
|
|
1400
|
+
}, [blocks, blockStretch]);
|
|
1276
1401
|
const nowKey = now instanceof Date ? now.getTime() : now;
|
|
1277
1402
|
const nowDate = useMemo(() => resolveNow(nowKey === void 0 ? void 0 : typeof nowKey === "number" ? new Date(nowKey) : nowKey), [nowKey]);
|
|
1278
1403
|
const author = doc?.meta && typeof doc.meta === "object" ? doc.meta.author : void 0;
|
|
1279
1404
|
const title = doc?.title;
|
|
1280
1405
|
const docFields = useMemo(
|
|
1281
1406
|
() => ({
|
|
1282
|
-
section: 1,
|
|
1283
1407
|
...typeof author === "string" ? { author } : {},
|
|
1284
1408
|
...typeof title === "string" ? { title } : {},
|
|
1285
1409
|
...typeof filename === "string" ? { filename } : {},
|
|
@@ -1304,6 +1428,7 @@ function DocViewer({
|
|
|
1304
1428
|
}),
|
|
1305
1429
|
[numbering, doc, geometry]
|
|
1306
1430
|
);
|
|
1431
|
+
const ctxOf = (k) => ({ ...ctx, contentWidth: stretches[k].geometry.contentWidth });
|
|
1307
1432
|
useEffect(() => {
|
|
1308
1433
|
const state = initialFontState(faces);
|
|
1309
1434
|
setFont(state);
|
|
@@ -1319,22 +1444,12 @@ function DocViewer({
|
|
|
1319
1444
|
useLayoutEffect(() => {
|
|
1320
1445
|
const el = measureRef.current;
|
|
1321
1446
|
if (!el || font === "pending") return;
|
|
1322
|
-
const m = measure(el, blocks);
|
|
1323
|
-
const
|
|
1324
|
-
|
|
1325
|
-
first: h.first / PX_PER_PT,
|
|
1326
|
-
even: h.even / PX_PER_PT
|
|
1327
|
-
});
|
|
1328
|
-
const boxes = pageBodyBoxes(geometry, page, { header: toPt(m.bands.header), footer: toPt(m.bands.footer) });
|
|
1329
|
-
const pages = paginate(m.items, {
|
|
1330
|
-
pageHeight: boxes.odd.height * PX_PER_PT,
|
|
1331
|
-
firstPageHeight: boxes.first.height * PX_PER_PT,
|
|
1332
|
-
evenPageHeight: boxes.even.height * PX_PER_PT,
|
|
1333
|
-
footnoteSeparator: m.footnoteSeparator
|
|
1334
|
-
});
|
|
1447
|
+
const m = measure(el, blocks, stretches.length);
|
|
1448
|
+
const input = packInput(stretches, m);
|
|
1449
|
+
const pages = paginate(input.items, input.options);
|
|
1335
1450
|
const heights = m.items.map((it) => it.type === "block" ? it.height : 0);
|
|
1336
|
-
setLayout({ pages, boxes, heights });
|
|
1337
|
-
}, [blocks,
|
|
1451
|
+
setLayout({ pages, boxes: input.boxes, heights });
|
|
1452
|
+
}, [blocks, stretches, numbering, fontEpoch, docFields, font]);
|
|
1338
1453
|
useEffect(() => {
|
|
1339
1454
|
const fonts = typeof document !== "undefined" ? document.fonts : void 0;
|
|
1340
1455
|
let live = true;
|
|
@@ -1355,7 +1470,7 @@ function DocViewer({
|
|
|
1355
1470
|
ro.observe(el);
|
|
1356
1471
|
return () => ro.disconnect();
|
|
1357
1472
|
}, []);
|
|
1358
|
-
const pageWpx = geometry.width * PX_PER_PT;
|
|
1473
|
+
const pageWpx = Math.max(...stretches.map((s) => s.geometry.width)) * PX_PER_PT;
|
|
1359
1474
|
const scale = typeof fixedScale === "number" && fixedScale > 0 ? fixedScale : fit === "none" || !width ? 1 : Math.min(maxScale, width / pageWpx);
|
|
1360
1475
|
const notShown = useMemo(() => unshownLayout(doc), [doc]);
|
|
1361
1476
|
const pageCount = layout?.pages.length ?? 0;
|
|
@@ -1365,12 +1480,13 @@ function DocViewer({
|
|
|
1365
1480
|
pages: layout.pages.length,
|
|
1366
1481
|
pageWidth: geometry.width,
|
|
1367
1482
|
pageHeight: geometry.height,
|
|
1483
|
+
...stretches.length > 1 ? { pageSizes: layout.pages.map((p) => ({ width: stretches[p.stretch ?? 0].geometry.width, height: stretches[p.stretch ?? 0].geometry.height })) } : {},
|
|
1368
1484
|
scale,
|
|
1369
1485
|
font,
|
|
1370
1486
|
...notShown.length > 0 ? { notShown } : {}
|
|
1371
1487
|
});
|
|
1372
1488
|
}
|
|
1373
|
-
}, [layout, geometry, scale, onLayout, font, notShown]);
|
|
1489
|
+
}, [layout, geometry, stretches, scale, onLayout, font, notShown]);
|
|
1374
1490
|
const typography2 = typography(doc?.defaultFont, ctx.size);
|
|
1375
1491
|
const ready = layout !== null && font !== "pending";
|
|
1376
1492
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1403,49 +1519,74 @@ function DocViewer({
|
|
|
1403
1519
|
width: pt(geometry.contentWidth)
|
|
1404
1520
|
},
|
|
1405
1521
|
children: /* @__PURE__ */ jsxs(RenderCtx.Provider, { value: ctx, children: [
|
|
1406
|
-
|
|
1407
|
-
(
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1522
|
+
stretches.flatMap(
|
|
1523
|
+
(stretch, k) => ["header", "footer"].flatMap(
|
|
1524
|
+
(kind) => BAND_SLOTS.map((slot) => {
|
|
1525
|
+
const band = slotBand(stretch.page, kind, slot);
|
|
1526
|
+
if (!hasBand(band)) return null;
|
|
1527
|
+
const n = slot === "even" ? 2 : 1;
|
|
1528
|
+
const at = k === 0 ? `${kind}:${slot}` : `${k + 1}:${kind}:${slot}`;
|
|
1529
|
+
return /* @__PURE__ */ jsx("div", { "data-lw-measure-band": at, style: stretches.length > 1 ? { width: pt(stretch.geometry.contentWidth) } : void 0, children: /* @__PURE__ */ jsx(RenderCtx.Provider, { value: { ...ctxOf(k), fields: { ...docFields, section: k + 1, page: n, pages: n } }, children: /* @__PURE__ */ jsx(BandView, { band }) }) }, at);
|
|
1530
|
+
})
|
|
1531
|
+
)
|
|
1413
1532
|
),
|
|
1414
|
-
blocks.map((b, i) =>
|
|
1415
|
-
|
|
1533
|
+
blocks.map((b, i) => {
|
|
1534
|
+
const k = blockStretch[i];
|
|
1535
|
+
return /* @__PURE__ */ jsx(
|
|
1536
|
+
"div",
|
|
1537
|
+
{
|
|
1538
|
+
"data-lw-measure-block": i,
|
|
1539
|
+
style: { display: "flow-root", ...stretches.length > 1 ? { width: pt(stretches[k].geometry.contentWidth) } : {} },
|
|
1540
|
+
children: /* @__PURE__ */ jsx(RenderCtx.Provider, { value: ctxOf(k), children: /* @__PURE__ */ jsx(BlockView, { block: b }) })
|
|
1541
|
+
},
|
|
1542
|
+
i
|
|
1543
|
+
);
|
|
1544
|
+
}),
|
|
1545
|
+
numbering.notes.map((n) => {
|
|
1546
|
+
const k = noteStretch.get(n.id) ?? 0;
|
|
1547
|
+
return /* @__PURE__ */ jsx("div", { "data-lw-measure-footnote": n.id, style: stretches.length > 1 ? { width: pt(stretches[k].geometry.contentWidth) } : void 0, children: /* @__PURE__ */ jsx(RenderCtx.Provider, { value: ctxOf(k), children: /* @__PURE__ */ jsx(FootnoteView, { id: n.id, footnote: n.footnote }) }) }, n.id);
|
|
1548
|
+
}),
|
|
1416
1549
|
numbering.notes.length > 0 && /* @__PURE__ */ jsx("div", { "data-lw-measure-separator": "", children: /* @__PURE__ */ jsx(FootnoteSeparator, { height: pt(FOOTNOTE_SEPARATOR_PT) }) })
|
|
1417
1550
|
] })
|
|
1418
1551
|
}
|
|
1419
1552
|
),
|
|
1420
|
-
ready && layout && /* @__PURE__ */ jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) =>
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1553
|
+
ready && layout && /* @__PURE__ */ jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) => {
|
|
1554
|
+
const k = p.stretch ?? 0;
|
|
1555
|
+
const inStretch = layout.pages.filter((x) => (x.stretch ?? 0) === k);
|
|
1556
|
+
const start = inStretch[0].index;
|
|
1557
|
+
return /* @__PURE__ */ jsx(
|
|
1558
|
+
PageView,
|
|
1559
|
+
{
|
|
1560
|
+
page: p,
|
|
1561
|
+
pages: layout.pages.length,
|
|
1562
|
+
section: k + 1,
|
|
1563
|
+
sectionPages: inStretch.length,
|
|
1564
|
+
start,
|
|
1565
|
+
stretch: stretches[k],
|
|
1566
|
+
box: layout.boxes[k][pageClassIn(p.index, start)],
|
|
1567
|
+
scale,
|
|
1568
|
+
typography: typography2,
|
|
1569
|
+
ctx: ctxOf(k),
|
|
1570
|
+
docFields,
|
|
1571
|
+
numbering,
|
|
1572
|
+
blocks,
|
|
1573
|
+
heights: layout.heights
|
|
1574
|
+
},
|
|
1575
|
+
p.index
|
|
1576
|
+
);
|
|
1577
|
+
}) })
|
|
1438
1578
|
]
|
|
1439
1579
|
}
|
|
1440
1580
|
);
|
|
1441
1581
|
}
|
|
1442
|
-
function PageView({ page, pages,
|
|
1582
|
+
function PageView({ page, pages, section, sectionPages, start, stretch, box, scale, typography: typography2, ctx, docFields, numbering, blocks, heights }) {
|
|
1443
1583
|
const n = page.index + 1;
|
|
1444
|
-
const g = geometry;
|
|
1445
|
-
const
|
|
1446
|
-
const
|
|
1447
|
-
const
|
|
1448
|
-
const
|
|
1584
|
+
const g = stretch.geometry;
|
|
1585
|
+
const docPage = stretch.page;
|
|
1586
|
+
const bandCtx = { ...ctx, fields: { ...docFields, page: n, pages, section, sectionPages } };
|
|
1587
|
+
const cls = pageClassIn(page.index, start);
|
|
1588
|
+
const header = pageBand(docPage, "header", page.index, start);
|
|
1589
|
+
const footer = pageBand(docPage, "footer", page.index, start);
|
|
1449
1590
|
const variant = (kind) => bandSlot(docPage, kind, cls);
|
|
1450
1591
|
const notes = page.footnotes.map((fid) => numbering.notes.find((x) => x.id === fid)).filter((x) => !!x);
|
|
1451
1592
|
return /* @__PURE__ */ jsx(
|
|
@@ -1565,6 +1706,6 @@ function docFromReader(output) {
|
|
|
1565
1706
|
return value;
|
|
1566
1707
|
}
|
|
1567
1708
|
|
|
1568
|
-
export { CARLITO_FACES, CARLITO_FAMILY, DocViewer, FONT_LOAD_TIMEOUT_MS, LAYOUT_NOTICE, PAGE_BAND_DISTANCE_DEFAULT, PAGE_MARGIN_DEFAULT, PAGE_SIZES_PT, PX_PER_PT, bandSlot, bodyBox, carlitoFaces, docFromReader, fontFaceCss, formatDatePicture, numberFootnotes, pageBand, pageBodyBoxes, pageCapacity, pageClass, pageGeometry, pageMargins, paginate, resolveNow, substituteFields, unshownLayout };
|
|
1709
|
+
export { CARLITO_FACES, CARLITO_FAMILY, DocViewer, FONT_LOAD_TIMEOUT_MS, LAYOUT_NOTICE, PAGE_BAND_DISTANCE_DEFAULT, PAGE_MARGIN_DEFAULT, PAGE_SIZES_PT, PX_PER_PT, bandSlot, blockStretches, bodyBox, carlitoFaces, docFromReader, docStretches, fontFaceCss, formatDatePicture, numberFootnotes, packInput, pageBand, pageBodyBoxes, pageCapacity, pageClass, pageClassIn, pageGeometry, pageMargins, paginate, resolveNow, substituteFields, unshownLayout };
|
|
1569
1710
|
//# sourceMappingURL=index.js.map
|
|
1570
1711
|
//# sourceMappingURL=index.js.map
|