@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/dist/index.d.cts
CHANGED
|
@@ -238,6 +238,12 @@ interface DocViewerLayout {
|
|
|
238
238
|
* `"unused"`: the document has no such text.
|
|
239
239
|
*/
|
|
240
240
|
font: ViewerFont;
|
|
241
|
+
/**
|
|
242
|
+
* JSON Pointers to page layout the document asks for and this viewer does not
|
|
243
|
+
* show (`pageBreak.page`, page keys straight on a break, a top-level `sections`).
|
|
244
|
+
* Absent when there is none. The visible notice says the same thing.
|
|
245
|
+
*/
|
|
246
|
+
notShown?: string[];
|
|
241
247
|
}
|
|
242
248
|
type ViewerFont = "carlito" | "fallback" | "unused";
|
|
243
249
|
/** How long the viewer waits for the bundled font before laying out without it. */
|
|
@@ -288,7 +294,8 @@ interface DocViewerProps {
|
|
|
288
294
|
* Stable handles: the root carries `data-lw-viewer`; each page `data-page`
|
|
289
295
|
* (1-based); each block or fragment of one `data-block` (`b0`, `b1`, ... in
|
|
290
296
|
* document order); each footnote `data-footnote`; bands `data-lw-band`, with
|
|
291
|
-
* `data-lw-band-variant` naming the one drawn (`default`, `first`, `even`)
|
|
297
|
+
* `data-lw-band-variant` naming the one drawn (`default`, `first`, `even`);
|
|
298
|
+
* `data-lw-layout-notice` when the document asks for page layout it does not show.
|
|
292
299
|
*
|
|
293
300
|
* Header and footer text takes field tokens -- `{page}`, `{pages}`,
|
|
294
301
|
* `{section}`, `{sectionpages}`, `{author}`, `{title}`, `{filename}`, `{date}`,
|
|
@@ -330,6 +337,20 @@ declare function carlitoFaces(doc: Doc): string[];
|
|
|
330
337
|
*/
|
|
331
338
|
declare function docFromReader(output: unknown): Doc;
|
|
332
339
|
|
|
340
|
+
/**
|
|
341
|
+
* What the viewer says when a document asks for more than one page setup. It draws
|
|
342
|
+
* one until per-page geometry lands; drawing nothing, or drawing it wrong in
|
|
343
|
+
* silence, are the two worse answers. The same words as fancy-docs.
|
|
344
|
+
*/
|
|
345
|
+
declare const 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.";
|
|
346
|
+
/**
|
|
347
|
+
* JSON Pointers to what this viewer ignores about page layout: `pageBreak.page`,
|
|
348
|
+
* the near-miss keys on a break and a top-level `sections`, at any depth. Empty for
|
|
349
|
+
* a document with one page setup. The Doc arrives as JSON from any writer, so
|
|
350
|
+
* nothing here trusts its shape. A walk, not a recursion: the nesting is the file's.
|
|
351
|
+
*/
|
|
352
|
+
declare function unshownLayout(doc: Doc): string[];
|
|
353
|
+
|
|
333
354
|
/**
|
|
334
355
|
* The page packer: measured heights in, page assignments out.
|
|
335
356
|
*
|
|
@@ -621,4 +642,4 @@ interface FootnoteNumbering {
|
|
|
621
642
|
*/
|
|
622
643
|
declare function numberFootnotes(doc: Doc): FootnoteNumbering;
|
|
623
644
|
|
|
624
|
-
export { type Align, type Band, type BandHeights, type BandKind, type BandSlot, type Block, type BlockFragment, type BlockItem, type BlocksBand, type BodyBox, type Border, type BorderStyle, type BoxBorders, type BoxSides, type BreakItem, CARLITO_FACES, CARLITO_FAMILY, type ChartBlock, type CodeBlock, type Doc, type DocMeta, DocViewer, type DocViewerLayout, type DocViewerProps, FONT_LOAD_TIMEOUT_MS, type Footnote, type FootnoteMark, type FootnoteNumbering, type Fragment, type HeadingBlock, type HrBlock, type ImageBlock, type ListBlock, type ListItem, type Orientation, PAGE_BAND_DISTANCE_DEFAULT, PAGE_MARGIN_DEFAULT, PAGE_SIZES_PT, PX_PER_PT, type PackItem, type PackOptions, type Page, type PageBreakBlock, type PageClass, type PageFields, type PageGeometry, type PageLayout, type PageMargins, type PageSize, type ParagraphBlock, type ParagraphProps, type QuoteBlock, type ResolvedMargins, type Run, type TableBlock, type TableBorders, type TableCell, type TableFragment, type TableItem, type TableRow, type TableRowItem, type VAlign, type ViewerFont, bandSlot, bodyBox, carlitoFaces, docFromReader, fontFaceCss, formatDatePicture, numberFootnotes, pageBand, pageBodyBoxes, pageCapacity, pageClass, pageGeometry, pageMargins, paginate, resolveNow, substituteFields };
|
|
645
|
+
export { type Align, type Band, type BandHeights, type BandKind, type BandSlot, type Block, type BlockFragment, type BlockItem, type BlocksBand, type BodyBox, type Border, type BorderStyle, type BoxBorders, type BoxSides, type BreakItem, CARLITO_FACES, CARLITO_FAMILY, type ChartBlock, type CodeBlock, type Doc, type DocMeta, DocViewer, type DocViewerLayout, type DocViewerProps, FONT_LOAD_TIMEOUT_MS, type Footnote, type FootnoteMark, type FootnoteNumbering, type Fragment, type HeadingBlock, type HrBlock, type ImageBlock, LAYOUT_NOTICE, type ListBlock, type ListItem, type Orientation, PAGE_BAND_DISTANCE_DEFAULT, PAGE_MARGIN_DEFAULT, PAGE_SIZES_PT, PX_PER_PT, type PackItem, type PackOptions, type Page, type PageBreakBlock, type PageClass, type PageFields, type PageGeometry, type PageLayout, type PageMargins, type PageSize, type ParagraphBlock, type ParagraphProps, type QuoteBlock, type ResolvedMargins, type Run, type TableBlock, type TableBorders, type TableCell, type TableFragment, type TableItem, type TableRow, type TableRowItem, type VAlign, type ViewerFont, bandSlot, bodyBox, carlitoFaces, docFromReader, fontFaceCss, formatDatePicture, numberFootnotes, pageBand, pageBodyBoxes, pageCapacity, pageClass, pageGeometry, pageMargins, paginate, resolveNow, substituteFields, unshownLayout };
|
package/dist/index.d.ts
CHANGED
|
@@ -238,6 +238,12 @@ interface DocViewerLayout {
|
|
|
238
238
|
* `"unused"`: the document has no such text.
|
|
239
239
|
*/
|
|
240
240
|
font: ViewerFont;
|
|
241
|
+
/**
|
|
242
|
+
* JSON Pointers to page layout the document asks for and this viewer does not
|
|
243
|
+
* show (`pageBreak.page`, page keys straight on a break, a top-level `sections`).
|
|
244
|
+
* Absent when there is none. The visible notice says the same thing.
|
|
245
|
+
*/
|
|
246
|
+
notShown?: string[];
|
|
241
247
|
}
|
|
242
248
|
type ViewerFont = "carlito" | "fallback" | "unused";
|
|
243
249
|
/** How long the viewer waits for the bundled font before laying out without it. */
|
|
@@ -288,7 +294,8 @@ interface DocViewerProps {
|
|
|
288
294
|
* Stable handles: the root carries `data-lw-viewer`; each page `data-page`
|
|
289
295
|
* (1-based); each block or fragment of one `data-block` (`b0`, `b1`, ... in
|
|
290
296
|
* document order); each footnote `data-footnote`; bands `data-lw-band`, with
|
|
291
|
-
* `data-lw-band-variant` naming the one drawn (`default`, `first`, `even`)
|
|
297
|
+
* `data-lw-band-variant` naming the one drawn (`default`, `first`, `even`);
|
|
298
|
+
* `data-lw-layout-notice` when the document asks for page layout it does not show.
|
|
292
299
|
*
|
|
293
300
|
* Header and footer text takes field tokens -- `{page}`, `{pages}`,
|
|
294
301
|
* `{section}`, `{sectionpages}`, `{author}`, `{title}`, `{filename}`, `{date}`,
|
|
@@ -330,6 +337,20 @@ declare function carlitoFaces(doc: Doc): string[];
|
|
|
330
337
|
*/
|
|
331
338
|
declare function docFromReader(output: unknown): Doc;
|
|
332
339
|
|
|
340
|
+
/**
|
|
341
|
+
* What the viewer says when a document asks for more than one page setup. It draws
|
|
342
|
+
* one until per-page geometry lands; drawing nothing, or drawing it wrong in
|
|
343
|
+
* silence, are the two worse answers. The same words as fancy-docs.
|
|
344
|
+
*/
|
|
345
|
+
declare const 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.";
|
|
346
|
+
/**
|
|
347
|
+
* JSON Pointers to what this viewer ignores about page layout: `pageBreak.page`,
|
|
348
|
+
* the near-miss keys on a break and a top-level `sections`, at any depth. Empty for
|
|
349
|
+
* a document with one page setup. The Doc arrives as JSON from any writer, so
|
|
350
|
+
* nothing here trusts its shape. A walk, not a recursion: the nesting is the file's.
|
|
351
|
+
*/
|
|
352
|
+
declare function unshownLayout(doc: Doc): string[];
|
|
353
|
+
|
|
333
354
|
/**
|
|
334
355
|
* The page packer: measured heights in, page assignments out.
|
|
335
356
|
*
|
|
@@ -621,4 +642,4 @@ interface FootnoteNumbering {
|
|
|
621
642
|
*/
|
|
622
643
|
declare function numberFootnotes(doc: Doc): FootnoteNumbering;
|
|
623
644
|
|
|
624
|
-
export { type Align, type Band, type BandHeights, type BandKind, type BandSlot, type Block, type BlockFragment, type BlockItem, type BlocksBand, type BodyBox, type Border, type BorderStyle, type BoxBorders, type BoxSides, type BreakItem, CARLITO_FACES, CARLITO_FAMILY, type ChartBlock, type CodeBlock, type Doc, type DocMeta, DocViewer, type DocViewerLayout, type DocViewerProps, FONT_LOAD_TIMEOUT_MS, type Footnote, type FootnoteMark, type FootnoteNumbering, type Fragment, type HeadingBlock, type HrBlock, type ImageBlock, type ListBlock, type ListItem, type Orientation, PAGE_BAND_DISTANCE_DEFAULT, PAGE_MARGIN_DEFAULT, PAGE_SIZES_PT, PX_PER_PT, type PackItem, type PackOptions, type Page, type PageBreakBlock, type PageClass, type PageFields, type PageGeometry, type PageLayout, type PageMargins, type PageSize, type ParagraphBlock, type ParagraphProps, type QuoteBlock, type ResolvedMargins, type Run, type TableBlock, type TableBorders, type TableCell, type TableFragment, type TableItem, type TableRow, type TableRowItem, type VAlign, type ViewerFont, bandSlot, bodyBox, carlitoFaces, docFromReader, fontFaceCss, formatDatePicture, numberFootnotes, pageBand, pageBodyBoxes, pageCapacity, pageClass, pageGeometry, pageMargins, paginate, resolveNow, substituteFields };
|
|
645
|
+
export { type Align, type Band, type BandHeights, type BandKind, type BandSlot, type Block, type BlockFragment, type BlockItem, type BlocksBand, type BodyBox, type Border, type BorderStyle, type BoxBorders, type BoxSides, type BreakItem, CARLITO_FACES, CARLITO_FAMILY, type ChartBlock, type CodeBlock, type Doc, type DocMeta, DocViewer, type DocViewerLayout, type DocViewerProps, FONT_LOAD_TIMEOUT_MS, type Footnote, type FootnoteMark, type FootnoteNumbering, type Fragment, type HeadingBlock, type HrBlock, type ImageBlock, LAYOUT_NOTICE, type ListBlock, type ListItem, type Orientation, PAGE_BAND_DISTANCE_DEFAULT, PAGE_MARGIN_DEFAULT, PAGE_SIZES_PT, PX_PER_PT, type PackItem, type PackOptions, type Page, type PageBreakBlock, type PageClass, type PageFields, type PageGeometry, type PageLayout, type PageMargins, type PageSize, type ParagraphBlock, type ParagraphProps, type QuoteBlock, type ResolvedMargins, type Run, type TableBlock, type TableBorders, type TableCell, type TableFragment, type TableItem, type TableRow, type TableRowItem, type VAlign, type ViewerFont, bandSlot, bodyBox, carlitoFaces, docFromReader, fontFaceCss, formatDatePicture, numberFootnotes, pageBand, pageBodyBoxes, pageCapacity, pageClass, pageGeometry, pageMargins, paginate, resolveNow, substituteFields, unshownLayout };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useMemo, useRef, useState, useEffect, useLayoutEffect, useContext } from 'react';
|
|
2
|
-
import { Text, Separator, Heading, Table, ImageViewer } from '@particle-academy/react-fancy';
|
|
2
|
+
import { Callout, Text, Separator, Heading, Table, ImageViewer } from '@particle-academy/react-fancy';
|
|
3
3
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
// src/DocViewer.tsx
|
|
@@ -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 };
|
|
@@ -824,6 +833,40 @@ function numberFootnotes(doc) {
|
|
|
824
833
|
return { marks, notes };
|
|
825
834
|
}
|
|
826
835
|
|
|
836
|
+
// src/layout-notice.ts
|
|
837
|
+
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.";
|
|
838
|
+
var NEAR_MISS_KEYS = ["size", "orientation", "margins", "header", "footer", "firstHeader", "firstFooter", "evenHeader", "evenFooter", "background", "border"];
|
|
839
|
+
var isObject = (v) => typeof v === "object" && v !== null;
|
|
840
|
+
function unshownLayout(doc) {
|
|
841
|
+
const found = [];
|
|
842
|
+
if (!isObject(doc)) return found;
|
|
843
|
+
if (doc.sections !== void 0) found.push("/sections");
|
|
844
|
+
const stack = [{ blocks: doc.blocks, at: "/blocks" }];
|
|
845
|
+
while (stack.length > 0) {
|
|
846
|
+
const { blocks, at } = stack.pop();
|
|
847
|
+
if (!Array.isArray(blocks)) continue;
|
|
848
|
+
blocks.forEach((block, i) => {
|
|
849
|
+
if (!isObject(block)) return;
|
|
850
|
+
const path = `${at}/${i}`;
|
|
851
|
+
if (block.type === "pageBreak") {
|
|
852
|
+
for (const key of ["page", ...NEAR_MISS_KEYS]) {
|
|
853
|
+
if (block[key] !== void 0) found.push(`${path}/${key}`);
|
|
854
|
+
}
|
|
855
|
+
} else if (block.type === "quote") {
|
|
856
|
+
stack.push({ blocks: block.blocks, at: `${path}/blocks` });
|
|
857
|
+
} else if (block.type === "table" && Array.isArray(block.rows)) {
|
|
858
|
+
block.rows.forEach((row, r) => {
|
|
859
|
+
if (!isObject(row) || !Array.isArray(row.cells)) return;
|
|
860
|
+
row.cells.forEach((cell, c) => {
|
|
861
|
+
if (isObject(cell)) stack.push({ blocks: cell.blocks, at: `${path}/rows/${r}/cells/${c}/blocks` });
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
return found;
|
|
868
|
+
}
|
|
869
|
+
|
|
827
870
|
// src/measure.ts
|
|
828
871
|
var SPLITTABLE = /* @__PURE__ */ new Set(["paragraph", "heading", "list", "quote", "code"]);
|
|
829
872
|
var blockId = (index) => `b${index}`;
|
|
@@ -1323,12 +1366,20 @@ function DocViewer({
|
|
|
1323
1366
|
}, []);
|
|
1324
1367
|
const pageWpx = geometry.width * PX_PER_PT;
|
|
1325
1368
|
const scale = typeof fixedScale === "number" && fixedScale > 0 ? fixedScale : fit === "none" || !width ? 1 : Math.min(maxScale, width / pageWpx);
|
|
1369
|
+
const notShown = useMemo(() => unshownLayout(doc), [doc]);
|
|
1326
1370
|
const pageCount = layout?.pages.length ?? 0;
|
|
1327
1371
|
useEffect(() => {
|
|
1328
1372
|
if (layout && font !== "pending") {
|
|
1329
|
-
onLayout?.({
|
|
1373
|
+
onLayout?.({
|
|
1374
|
+
pages: layout.pages.length,
|
|
1375
|
+
pageWidth: geometry.width,
|
|
1376
|
+
pageHeight: geometry.height,
|
|
1377
|
+
scale,
|
|
1378
|
+
font,
|
|
1379
|
+
...notShown.length > 0 ? { notShown } : {}
|
|
1380
|
+
});
|
|
1330
1381
|
}
|
|
1331
|
-
}, [layout, geometry, scale, onLayout, font]);
|
|
1382
|
+
}, [layout, geometry, scale, onLayout, font, notShown]);
|
|
1332
1383
|
const typography2 = typography(doc?.defaultFont, ctx.size);
|
|
1333
1384
|
const ready = layout !== null && font !== "pending";
|
|
1334
1385
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1344,6 +1395,7 @@ function DocViewer({
|
|
|
1344
1395
|
children: [
|
|
1345
1396
|
injectStyles && /* @__PURE__ */ jsx("style", { href: "particle-academy-last-word-ui", precedence: "default", children: VIEWER_CSS }),
|
|
1346
1397
|
injectStyles && FONT_CSS && /* @__PURE__ */ jsx("style", { href: "particle-academy-last-word-ui-fonts", precedence: "default", children: FONT_CSS }),
|
|
1398
|
+
notShown.length > 0 && /* @__PURE__ */ jsx("div", { "data-lw-layout-notice": "", style: { marginBottom: gap }, children: /* @__PURE__ */ jsx(Callout, { color: "amber", children: LAYOUT_NOTICE }) }),
|
|
1347
1399
|
/* @__PURE__ */ jsx(
|
|
1348
1400
|
"div",
|
|
1349
1401
|
{
|
|
@@ -1522,6 +1574,6 @@ function docFromReader(output) {
|
|
|
1522
1574
|
return value;
|
|
1523
1575
|
}
|
|
1524
1576
|
|
|
1525
|
-
export { CARLITO_FACES, CARLITO_FAMILY, DocViewer, FONT_LOAD_TIMEOUT_MS, 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 };
|
|
1577
|
+
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 };
|
|
1526
1578
|
//# sourceMappingURL=index.js.map
|
|
1527
1579
|
//# sourceMappingURL=index.js.map
|