@particle-academy/last-word-ui 0.3.0 → 0.4.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/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
@@ -824,6 +824,40 @@ function numberFootnotes(doc) {
824
824
  return { marks, notes };
825
825
  }
826
826
 
827
+ // src/layout-notice.ts
828
+ 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.";
829
+ var NEAR_MISS_KEYS = ["size", "orientation", "margins", "header", "footer", "firstHeader", "firstFooter", "evenHeader", "evenFooter", "background", "border"];
830
+ var isObject = (v) => typeof v === "object" && v !== null;
831
+ function unshownLayout(doc) {
832
+ const found = [];
833
+ if (!isObject(doc)) return found;
834
+ if (doc.sections !== void 0) found.push("/sections");
835
+ const stack = [{ blocks: doc.blocks, at: "/blocks" }];
836
+ while (stack.length > 0) {
837
+ const { blocks, at } = stack.pop();
838
+ if (!Array.isArray(blocks)) continue;
839
+ blocks.forEach((block, i) => {
840
+ if (!isObject(block)) return;
841
+ const path = `${at}/${i}`;
842
+ if (block.type === "pageBreak") {
843
+ for (const key of ["page", ...NEAR_MISS_KEYS]) {
844
+ if (block[key] !== void 0) found.push(`${path}/${key}`);
845
+ }
846
+ } else if (block.type === "quote") {
847
+ stack.push({ blocks: block.blocks, at: `${path}/blocks` });
848
+ } else if (block.type === "table" && Array.isArray(block.rows)) {
849
+ block.rows.forEach((row, r) => {
850
+ if (!isObject(row) || !Array.isArray(row.cells)) return;
851
+ row.cells.forEach((cell, c) => {
852
+ if (isObject(cell)) stack.push({ blocks: cell.blocks, at: `${path}/rows/${r}/cells/${c}/blocks` });
853
+ });
854
+ });
855
+ }
856
+ });
857
+ }
858
+ return found;
859
+ }
860
+
827
861
  // src/measure.ts
828
862
  var SPLITTABLE = /* @__PURE__ */ new Set(["paragraph", "heading", "list", "quote", "code"]);
829
863
  var blockId = (index) => `b${index}`;
@@ -1323,12 +1357,20 @@ function DocViewer({
1323
1357
  }, []);
1324
1358
  const pageWpx = geometry.width * PX_PER_PT;
1325
1359
  const scale = typeof fixedScale === "number" && fixedScale > 0 ? fixedScale : fit === "none" || !width ? 1 : Math.min(maxScale, width / pageWpx);
1360
+ const notShown = useMemo(() => unshownLayout(doc), [doc]);
1326
1361
  const pageCount = layout?.pages.length ?? 0;
1327
1362
  useEffect(() => {
1328
1363
  if (layout && font !== "pending") {
1329
- onLayout?.({ pages: layout.pages.length, pageWidth: geometry.width, pageHeight: geometry.height, scale, font });
1364
+ onLayout?.({
1365
+ pages: layout.pages.length,
1366
+ pageWidth: geometry.width,
1367
+ pageHeight: geometry.height,
1368
+ scale,
1369
+ font,
1370
+ ...notShown.length > 0 ? { notShown } : {}
1371
+ });
1330
1372
  }
1331
- }, [layout, geometry, scale, onLayout, font]);
1373
+ }, [layout, geometry, scale, onLayout, font, notShown]);
1332
1374
  const typography2 = typography(doc?.defaultFont, ctx.size);
1333
1375
  const ready = layout !== null && font !== "pending";
1334
1376
  return /* @__PURE__ */ jsxs(
@@ -1344,6 +1386,7 @@ function DocViewer({
1344
1386
  children: [
1345
1387
  injectStyles && /* @__PURE__ */ jsx("style", { href: "particle-academy-last-word-ui", precedence: "default", children: VIEWER_CSS }),
1346
1388
  injectStyles && FONT_CSS && /* @__PURE__ */ jsx("style", { href: "particle-academy-last-word-ui-fonts", precedence: "default", children: FONT_CSS }),
1389
+ notShown.length > 0 && /* @__PURE__ */ jsx("div", { "data-lw-layout-notice": "", style: { marginBottom: gap }, children: /* @__PURE__ */ jsx(Callout, { color: "amber", children: LAYOUT_NOTICE }) }),
1347
1390
  /* @__PURE__ */ jsx(
1348
1391
  "div",
1349
1392
  {
@@ -1522,6 +1565,6 @@ function docFromReader(output) {
1522
1565
  return value;
1523
1566
  }
1524
1567
 
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 };
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 };
1526
1569
  //# sourceMappingURL=index.js.map
1527
1570
  //# sourceMappingURL=index.js.map