@particle-academy/last-word-ui 0.3.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 +34 -0
- package/dist/index.cjs +63 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +63 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,40 @@ 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
|
+
|
|
27
|
+
## [0.4.0] - 2026-11-03
|
|
28
|
+
|
|
29
|
+
**What you must do: nothing.** A document with one page setup draws exactly as
|
|
30
|
+
before, with no new element and no new `onLayout` key. Under Tailwind, your build
|
|
31
|
+
needs react-fancy's classes as it already does.
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- **A visible notice when a document asks for mixed page layout** (mixed page
|
|
36
|
+
orientation, stage 1). `pageBreak.page`, page keys written straight on a break
|
|
37
|
+
(`pageBreak.orientation`, `.margins`, ...) and a top-level `sections` were silently
|
|
38
|
+
ignored, so a landscape section drew as portrait with nothing said. The document
|
|
39
|
+
still draws, one page setup as before, under a react-fancy `Callout`
|
|
40
|
+
(`data-lw-layout-notice`) in light and dark. `onLayout` gains `notShown`, JSON
|
|
41
|
+
Pointers to what it ignored, present only when there is something to report. New
|
|
42
|
+
exports: `LAYOUT_NOTICE`, `unshownLayout(doc)`. Per-page geometry comes in a later
|
|
43
|
+
release; **consumer action:** none. Those near-miss keys and `sections` do not
|
|
44
|
+
exist: `pageBreak.page` is the form, and `last-word` refuses all of them on write
|
|
45
|
+
until it can honour the first.
|
|
46
|
+
|
|
13
47
|
## [0.3.0] - 2026-11-01
|
|
14
48
|
|
|
15
49
|
**What you must do: probably nothing, but expect page breaks to move.** Calibri
|
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 (
|
|
405
|
-
|
|
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
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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 };
|
|
@@ -827,6 +836,40 @@ function numberFootnotes(doc) {
|
|
|
827
836
|
return { marks, notes };
|
|
828
837
|
}
|
|
829
838
|
|
|
839
|
+
// 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.";
|
|
841
|
+
var NEAR_MISS_KEYS = ["size", "orientation", "margins", "header", "footer", "firstHeader", "firstFooter", "evenHeader", "evenFooter", "background", "border"];
|
|
842
|
+
var isObject = (v) => typeof v === "object" && v !== null;
|
|
843
|
+
function unshownLayout(doc) {
|
|
844
|
+
const found = [];
|
|
845
|
+
if (!isObject(doc)) return found;
|
|
846
|
+
if (doc.sections !== void 0) found.push("/sections");
|
|
847
|
+
const stack = [{ blocks: doc.blocks, at: "/blocks" }];
|
|
848
|
+
while (stack.length > 0) {
|
|
849
|
+
const { blocks, at } = stack.pop();
|
|
850
|
+
if (!Array.isArray(blocks)) continue;
|
|
851
|
+
blocks.forEach((block, i) => {
|
|
852
|
+
if (!isObject(block)) return;
|
|
853
|
+
const path = `${at}/${i}`;
|
|
854
|
+
if (block.type === "pageBreak") {
|
|
855
|
+
for (const key of ["page", ...NEAR_MISS_KEYS]) {
|
|
856
|
+
if (block[key] !== void 0) found.push(`${path}/${key}`);
|
|
857
|
+
}
|
|
858
|
+
} else if (block.type === "quote") {
|
|
859
|
+
stack.push({ blocks: block.blocks, at: `${path}/blocks` });
|
|
860
|
+
} else if (block.type === "table" && Array.isArray(block.rows)) {
|
|
861
|
+
block.rows.forEach((row, r) => {
|
|
862
|
+
if (!isObject(row) || !Array.isArray(row.cells)) return;
|
|
863
|
+
row.cells.forEach((cell, c) => {
|
|
864
|
+
if (isObject(cell)) stack.push({ blocks: cell.blocks, at: `${path}/rows/${r}/cells/${c}/blocks` });
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
return found;
|
|
871
|
+
}
|
|
872
|
+
|
|
830
873
|
// src/measure.ts
|
|
831
874
|
var SPLITTABLE = /* @__PURE__ */ new Set(["paragraph", "heading", "list", "quote", "code"]);
|
|
832
875
|
var blockId = (index) => `b${index}`;
|
|
@@ -1326,12 +1369,20 @@ function DocViewer({
|
|
|
1326
1369
|
}, []);
|
|
1327
1370
|
const pageWpx = geometry.width * PX_PER_PT;
|
|
1328
1371
|
const scale = typeof fixedScale === "number" && fixedScale > 0 ? fixedScale : fit === "none" || !width ? 1 : Math.min(maxScale, width / pageWpx);
|
|
1372
|
+
const notShown = react.useMemo(() => unshownLayout(doc), [doc]);
|
|
1329
1373
|
const pageCount = layout?.pages.length ?? 0;
|
|
1330
1374
|
react.useEffect(() => {
|
|
1331
1375
|
if (layout && font !== "pending") {
|
|
1332
|
-
onLayout?.({
|
|
1376
|
+
onLayout?.({
|
|
1377
|
+
pages: layout.pages.length,
|
|
1378
|
+
pageWidth: geometry.width,
|
|
1379
|
+
pageHeight: geometry.height,
|
|
1380
|
+
scale,
|
|
1381
|
+
font,
|
|
1382
|
+
...notShown.length > 0 ? { notShown } : {}
|
|
1383
|
+
});
|
|
1333
1384
|
}
|
|
1334
|
-
}, [layout, geometry, scale, onLayout, font]);
|
|
1385
|
+
}, [layout, geometry, scale, onLayout, font, notShown]);
|
|
1335
1386
|
const typography2 = typography(doc?.defaultFont, ctx.size);
|
|
1336
1387
|
const ready = layout !== null && font !== "pending";
|
|
1337
1388
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1347,6 +1398,7 @@ function DocViewer({
|
|
|
1347
1398
|
children: [
|
|
1348
1399
|
injectStyles && /* @__PURE__ */ jsxRuntime.jsx("style", { href: "particle-academy-last-word-ui", precedence: "default", children: VIEWER_CSS }),
|
|
1349
1400
|
injectStyles && FONT_CSS && /* @__PURE__ */ jsxRuntime.jsx("style", { href: "particle-academy-last-word-ui-fonts", precedence: "default", children: FONT_CSS }),
|
|
1401
|
+
notShown.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-layout-notice": "", style: { marginBottom: gap }, children: /* @__PURE__ */ jsxRuntime.jsx(reactFancy.Callout, { color: "amber", children: LAYOUT_NOTICE }) }),
|
|
1350
1402
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1351
1403
|
"div",
|
|
1352
1404
|
{
|
|
@@ -1529,6 +1581,7 @@ exports.CARLITO_FACES = CARLITO_FACES;
|
|
|
1529
1581
|
exports.CARLITO_FAMILY = CARLITO_FAMILY;
|
|
1530
1582
|
exports.DocViewer = DocViewer;
|
|
1531
1583
|
exports.FONT_LOAD_TIMEOUT_MS = FONT_LOAD_TIMEOUT_MS;
|
|
1584
|
+
exports.LAYOUT_NOTICE = LAYOUT_NOTICE;
|
|
1532
1585
|
exports.PAGE_BAND_DISTANCE_DEFAULT = PAGE_BAND_DISTANCE_DEFAULT;
|
|
1533
1586
|
exports.PAGE_MARGIN_DEFAULT = PAGE_MARGIN_DEFAULT;
|
|
1534
1587
|
exports.PAGE_SIZES_PT = PAGE_SIZES_PT;
|
|
@@ -1549,5 +1602,6 @@ exports.pageMargins = pageMargins;
|
|
|
1549
1602
|
exports.paginate = paginate;
|
|
1550
1603
|
exports.resolveNow = resolveNow;
|
|
1551
1604
|
exports.substituteFields = substituteFields;
|
|
1605
|
+
exports.unshownLayout = unshownLayout;
|
|
1552
1606
|
//# sourceMappingURL=index.cjs.map
|
|
1553
1607
|
//# sourceMappingURL=index.cjs.map
|