@particle-academy/last-word-ui 0.2.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
@@ -230,7 +230,24 @@ interface DocViewerLayout {
230
230
  pageHeight: number;
231
231
  /** The scale the pages are drawn at. */
232
232
  scale: number;
233
+ /**
234
+ * What Calibri and unspecified text was measured in. `"carlito"`: the
235
+ * bundled font, so the page count is the same on every machine (and agrees
236
+ * with last-word's `layout()`). `"fallback"`: it could not load (or the
237
+ * runtime has no FontFaceSet), so the count depends on this machine's fonts.
238
+ * `"unused"`: the document has no such text.
239
+ */
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[];
233
247
  }
248
+ type ViewerFont = "carlito" | "fallback" | "unused";
249
+ /** How long the viewer waits for the bundled font before laying out without it. */
250
+ declare const FONT_LOAD_TIMEOUT_MS = 3000;
234
251
  interface DocViewerProps {
235
252
  /** The document: last-word JSON, e.g. `new DocxReader().read(bytes)`. */
236
253
  doc: Doc;
@@ -277,7 +294,8 @@ interface DocViewerProps {
277
294
  * Stable handles: the root carries `data-lw-viewer`; each page `data-page`
278
295
  * (1-based); each block or fragment of one `data-block` (`b0`, `b1`, ... in
279
296
  * document order); each footnote `data-footnote`; bands `data-lw-band`, with
280
- * `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.
281
299
  *
282
300
  * Header and footer text takes field tokens -- `{page}`, `{pages}`,
283
301
  * `{section}`, `{sectionpages}`, `{author}`, `{title}`, `{filename}`, `{date}`,
@@ -286,6 +304,26 @@ interface DocViewerProps {
286
304
  */
287
305
  declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, filename, now, onLayout, injectStyles, id, className, style, }: DocViewerProps): react.JSX.Element;
288
306
 
307
+ /** The package-unique family the bundled Carlito is declared under (`fonts.ts`). */
308
+ declare const CARLITO_FAMILY = "LW Carlito";
309
+
310
+ interface CarlitoFace {
311
+ file: string;
312
+ weight: 400 | 700;
313
+ style: "normal" | "italic";
314
+ /** sha256 of the upstream file; a test pins the shipped bytes to it. */
315
+ sha256: string;
316
+ }
317
+ declare const CARLITO_FACES: readonly CarlitoFace[];
318
+ /** The four `@font-face` rules, each face at the URL `url(file)` returns. */
319
+ declare function fontFaceCss(url: (file: string) => string): string;
320
+ /**
321
+ * The faces a document draws in the bundled Carlito, as `FontFaceSet.load()`
322
+ * descriptors, in a fixed order. Only those are fetched: a plain memo never
323
+ * downloads the italic faces.
324
+ */
325
+ declare function carlitoFaces(doc: Doc): string[];
326
+
289
327
  /**
290
328
  * A Doc from what a last-word reader returned -- `new DocxReader().read(bytes)`
291
329
  * in `@particle-academy/last-word`, or the same JSON from PHP or Python over
@@ -299,6 +337,20 @@ declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, filenam
299
337
  */
300
338
  declare function docFromReader(output: unknown): Doc;
301
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
+
302
354
  /**
303
355
  * The page packer: measured heights in, page assignments out.
304
356
  *
@@ -590,4 +642,4 @@ interface FootnoteNumbering {
590
642
  */
591
643
  declare function numberFootnotes(doc: Doc): FootnoteNumbering;
592
644
 
593
- 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, type ChartBlock, type CodeBlock, type Doc, type DocMeta, DocViewer, type DocViewerLayout, type DocViewerProps, 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, bandSlot, bodyBox, docFromReader, 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
@@ -230,7 +230,24 @@ interface DocViewerLayout {
230
230
  pageHeight: number;
231
231
  /** The scale the pages are drawn at. */
232
232
  scale: number;
233
+ /**
234
+ * What Calibri and unspecified text was measured in. `"carlito"`: the
235
+ * bundled font, so the page count is the same on every machine (and agrees
236
+ * with last-word's `layout()`). `"fallback"`: it could not load (or the
237
+ * runtime has no FontFaceSet), so the count depends on this machine's fonts.
238
+ * `"unused"`: the document has no such text.
239
+ */
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[];
233
247
  }
248
+ type ViewerFont = "carlito" | "fallback" | "unused";
249
+ /** How long the viewer waits for the bundled font before laying out without it. */
250
+ declare const FONT_LOAD_TIMEOUT_MS = 3000;
234
251
  interface DocViewerProps {
235
252
  /** The document: last-word JSON, e.g. `new DocxReader().read(bytes)`. */
236
253
  doc: Doc;
@@ -277,7 +294,8 @@ interface DocViewerProps {
277
294
  * Stable handles: the root carries `data-lw-viewer`; each page `data-page`
278
295
  * (1-based); each block or fragment of one `data-block` (`b0`, `b1`, ... in
279
296
  * document order); each footnote `data-footnote`; bands `data-lw-band`, with
280
- * `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.
281
299
  *
282
300
  * Header and footer text takes field tokens -- `{page}`, `{pages}`,
283
301
  * `{section}`, `{sectionpages}`, `{author}`, `{title}`, `{filename}`, `{date}`,
@@ -286,6 +304,26 @@ interface DocViewerProps {
286
304
  */
287
305
  declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, filename, now, onLayout, injectStyles, id, className, style, }: DocViewerProps): react.JSX.Element;
288
306
 
307
+ /** The package-unique family the bundled Carlito is declared under (`fonts.ts`). */
308
+ declare const CARLITO_FAMILY = "LW Carlito";
309
+
310
+ interface CarlitoFace {
311
+ file: string;
312
+ weight: 400 | 700;
313
+ style: "normal" | "italic";
314
+ /** sha256 of the upstream file; a test pins the shipped bytes to it. */
315
+ sha256: string;
316
+ }
317
+ declare const CARLITO_FACES: readonly CarlitoFace[];
318
+ /** The four `@font-face` rules, each face at the URL `url(file)` returns. */
319
+ declare function fontFaceCss(url: (file: string) => string): string;
320
+ /**
321
+ * The faces a document draws in the bundled Carlito, as `FontFaceSet.load()`
322
+ * descriptors, in a fixed order. Only those are fetched: a plain memo never
323
+ * downloads the italic faces.
324
+ */
325
+ declare function carlitoFaces(doc: Doc): string[];
326
+
289
327
  /**
290
328
  * A Doc from what a last-word reader returned -- `new DocxReader().read(bytes)`
291
329
  * in `@particle-academy/last-word`, or the same JSON from PHP or Python over
@@ -299,6 +337,20 @@ declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, filenam
299
337
  */
300
338
  declare function docFromReader(output: unknown): Doc;
301
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
+
302
354
  /**
303
355
  * The page packer: measured heights in, page assignments out.
304
356
  *
@@ -590,4 +642,4 @@ interface FootnoteNumbering {
590
642
  */
591
643
  declare function numberFootnotes(doc: Doc): FootnoteNumbering;
592
644
 
593
- 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, type ChartBlock, type CodeBlock, type Doc, type DocMeta, DocViewer, type DocViewerLayout, type DocViewerProps, 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, bandSlot, bodyBox, docFromReader, 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
- import { createContext, useMemo, useRef, useState, useLayoutEffect, useEffect, useContext } from 'react';
2
- import { Text, Separator, Heading, Table, ImageViewer } from '@particle-academy/react-fancy';
1
+ import { createContext, useMemo, useRef, useState, useEffect, useLayoutEffect, useContext } from 'react';
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
@@ -303,11 +303,25 @@ var FALLBACKS = {
303
303
  "courier new": '"Liberation Mono", Cousine, monospace',
304
304
  consolas: '"Liberation Mono", Menlo, monospace'
305
305
  };
306
+ var CARLITO_FAMILY = "LW Carlito";
306
307
  function fontStack(name) {
307
- const clean = typeof name === "string" ? name.replace(/[^A-Za-z0-9 _-]/g, "").trim() : "";
308
- const font = clean === "" ? DEFAULT_FONT : clean;
308
+ const clean2 = typeof name === "string" ? name.replace(/[^A-Za-z0-9 _-]/g, "").trim() : "";
309
+ const font = clean2 === "" ? DEFAULT_FONT : clean2;
309
310
  const fallback = FALLBACKS[font.toLowerCase()] ?? 'Carlito, "Segoe UI", Arial, sans-serif';
310
- return `"${font}", ${fallback}`;
311
+ const first = font.toLowerCase() === "calibri" ? `"${CARLITO_FAMILY}", ` : "";
312
+ return `${first}"${font}", ${fallback}`;
313
+ }
314
+ function typography(defaultFont, size) {
315
+ return {
316
+ fontFamily: fontStack(defaultFont),
317
+ fontSize: pt(size),
318
+ lineHeight: SINGLE_LINE,
319
+ color: "#000000",
320
+ textAlign: "left",
321
+ fontKerning: "none",
322
+ fontVariantLigatures: "none",
323
+ textRendering: "geometricPrecision"
324
+ };
311
325
  }
312
326
  var MONO = fontStack("Consolas");
313
327
  var CSS_STYLE = {
@@ -810,6 +824,40 @@ function numberFootnotes(doc) {
810
824
  return { marks, notes };
811
825
  }
812
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
+
813
861
  // src/measure.ts
814
862
  var SPLITTABLE = /* @__PURE__ */ new Set(["paragraph", "heading", "list", "quote", "code"]);
815
863
  var blockId = (index) => `b${index}`;
@@ -1099,6 +1147,96 @@ function sum(notes) {
1099
1147
  return notes.reduce((a, n) => a + n.height, 0);
1100
1148
  }
1101
1149
 
1150
+ // src/font-urls.ts
1151
+ function carlitoUrls() {
1152
+ try {
1153
+ return {
1154
+ "Carlito-Regular.ttf": new URL("../fonts/Carlito-Regular.ttf", import.meta.url).href,
1155
+ "Carlito-Bold.ttf": new URL("../fonts/Carlito-Bold.ttf", import.meta.url).href,
1156
+ "Carlito-Italic.ttf": new URL("../fonts/Carlito-Italic.ttf", import.meta.url).href,
1157
+ "Carlito-BoldItalic.ttf": new URL("../fonts/Carlito-BoldItalic.ttf", import.meta.url).href
1158
+ };
1159
+ } catch {
1160
+ return null;
1161
+ }
1162
+ }
1163
+
1164
+ // src/fonts.ts
1165
+ var CARLITO_FACES = [
1166
+ { file: "Carlito-Regular.ttf", weight: 400, style: "normal", sha256: "f6418f708baede9789daef5d458c0f53d2a888af9820e8062934e504fedc6595" },
1167
+ { file: "Carlito-Bold.ttf", weight: 700, style: "normal", sha256: "bb5d20f79b82599ec72983597437373a80f2d2085fa91fc144fd74e876a594db" },
1168
+ { file: "Carlito-Italic.ttf", weight: 400, style: "italic", sha256: "0b019225e58d702bfedcbd35c21696769f8ee115cb6343f84c2f240312450d1c" },
1169
+ { file: "Carlito-BoldItalic.ttf", weight: 700, style: "italic", sha256: "b32928186c119599e03ca6a1ffc680fdcb7fac95772f4b95d989cf6cd3861517" }
1170
+ ];
1171
+ function fontFaceCss(url) {
1172
+ return CARLITO_FACES.map(
1173
+ (f) => `@font-face { font-family: "${CARLITO_FAMILY}"; font-weight: ${f.weight}; font-style: ${f.style}; font-display: swap; src: url("${url(f.file)}") format("truetype"); }`
1174
+ ).join("\n");
1175
+ }
1176
+ var clean = (name) => typeof name === "string" ? name.replace(/[^A-Za-z0-9 _-]/g, "").trim() : "";
1177
+ function usesCarlito(name) {
1178
+ const n = clean(name);
1179
+ return (n === "" ? DEFAULT_FONT : n).toLowerCase() === "calibri";
1180
+ }
1181
+ function carlitoFaces(doc) {
1182
+ const used = /* @__PURE__ */ new Set();
1183
+ const docCarlito = usesCarlito(doc?.defaultFont);
1184
+ const runs = (list, bold, italic) => {
1185
+ if (!Array.isArray(list)) return;
1186
+ for (const r of list) {
1187
+ if (!r || typeof r !== "object") continue;
1188
+ if (r.footnote && typeof r.footnote === "object") blocks(r.footnote.blocks, false, false);
1189
+ const hasFont = typeof r.font === "string" && r.font !== "";
1190
+ if (r.code || !(hasFont ? usesCarlito(r.font) : docCarlito)) continue;
1191
+ used.add(`${bold || r.bold ? 700 : 400}:${italic || r.italic ? "italic" : "normal"}`);
1192
+ }
1193
+ };
1194
+ const blocks = (list, bold, italic) => {
1195
+ if (!Array.isArray(list)) return;
1196
+ for (const b of list) {
1197
+ if (!b || typeof b !== "object") continue;
1198
+ switch (b.type) {
1199
+ case "paragraph":
1200
+ runs(b.runs, bold, italic);
1201
+ break;
1202
+ case "heading":
1203
+ runs(b.runs, true, italic);
1204
+ break;
1205
+ case "list": {
1206
+ const items = (xs) => {
1207
+ if (!Array.isArray(xs)) return;
1208
+ for (const it of xs) {
1209
+ runs(it?.runs, bold, italic);
1210
+ items(it?.children);
1211
+ }
1212
+ };
1213
+ items(b.items);
1214
+ break;
1215
+ }
1216
+ case "quote":
1217
+ blocks(b.blocks, bold, true);
1218
+ break;
1219
+ case "table":
1220
+ for (const row of Array.isArray(b.rows) ? b.rows : []) {
1221
+ for (const cell of Array.isArray(row?.cells) ? row.cells : []) blocks(cell?.blocks, bold || row.header === true, italic);
1222
+ }
1223
+ break;
1224
+ }
1225
+ }
1226
+ };
1227
+ blocks(doc?.blocks, false, false);
1228
+ const page = doc?.page && typeof doc.page === "object" ? doc.page : {};
1229
+ for (const key of ["header", "footer", "firstHeader", "firstFooter", "evenHeader", "evenFooter"]) {
1230
+ const band = page[key];
1231
+ if (!band || typeof band !== "object") continue;
1232
+ if (Array.isArray(band.blocks)) blocks(band.blocks, false, false);
1233
+ else if (docCarlito && [band.left, band.center, band.right].some((s) => typeof s === "string" && s !== "")) used.add("400:normal");
1234
+ }
1235
+ return CARLITO_FACES.filter((f) => used.has(`${f.weight}:${f.style}`)).map(
1236
+ (f) => `${f.weight} ${f.style} 16px "${CARLITO_FAMILY}"`
1237
+ );
1238
+ }
1239
+
1102
1240
  // src/viewer-css.ts
1103
1241
  var VIEWER_CSS = `
1104
1242
  :where([data-lw-viewer]) [data-lw-table] > table { width: 100%; border-collapse: collapse; table-layout: fixed; }
@@ -1107,6 +1245,16 @@ var VIEWER_CSS = `
1107
1245
  :where([data-lw-viewer]) hr[data-react-fancy-separator] { margin: 0; width: 100%; border: 0; border-top: 0.75pt solid #000000; }
1108
1246
  :where([data-lw-viewer]) [data-lw-sheet] p, :where([data-lw-viewer]) [data-lw-measure] p { margin-top: 0; margin-bottom: 0; }
1109
1247
  `.trim();
1248
+ var FONT_LOAD_TIMEOUT_MS = 3e3;
1249
+ var FONT_CSS = (() => {
1250
+ const urls = carlitoUrls();
1251
+ return urls ? fontFaceCss((file) => urls[file]) : null;
1252
+ })();
1253
+ function initialFontState(faces) {
1254
+ if (faces.length === 0) return "unused";
1255
+ const fonts = typeof document !== "undefined" ? document.fonts : void 0;
1256
+ return fonts && typeof fonts.load === "function" ? "pending" : "fallback";
1257
+ }
1110
1258
  function DocViewer({
1111
1259
  doc,
1112
1260
  fit = "width",
@@ -1143,6 +1291,9 @@ function DocViewer({
1143
1291
  const measureRef = useRef(null);
1144
1292
  const [layout, setLayout] = useState(null);
1145
1293
  const [fontEpoch, setFontEpoch] = useState(0);
1294
+ const faces = useMemo(() => carlitoFaces(doc), [doc]);
1295
+ const facesKey = faces.join("|");
1296
+ const [font, setFont] = useState(() => initialFontState(faces));
1146
1297
  const [width, setWidth] = useState(null);
1147
1298
  const ctx = useMemo(
1148
1299
  () => ({
@@ -1153,9 +1304,21 @@ function DocViewer({
1153
1304
  }),
1154
1305
  [numbering, doc, geometry]
1155
1306
  );
1307
+ useEffect(() => {
1308
+ const state = initialFontState(faces);
1309
+ setFont(state);
1310
+ if (state !== "pending") return;
1311
+ let live = true;
1312
+ const timer = setTimeout(() => live && setFont((f) => f === "pending" ? "fallback" : f), FONT_LOAD_TIMEOUT_MS);
1313
+ Promise.all(faces.map((f) => document.fonts.load(f))).then((loaded) => live && setFont(loaded.every((l) => l.length > 0) ? "carlito" : "fallback")).catch(() => live && setFont("fallback"));
1314
+ return () => {
1315
+ live = false;
1316
+ clearTimeout(timer);
1317
+ };
1318
+ }, [facesKey]);
1156
1319
  useLayoutEffect(() => {
1157
1320
  const el = measureRef.current;
1158
- if (!el) return;
1321
+ if (!el || font === "pending") return;
1159
1322
  const m = measure(el, blocks);
1160
1323
  const toPt = (h) => ({
1161
1324
  default: h.default / PX_PER_PT,
@@ -1171,7 +1334,7 @@ function DocViewer({
1171
1334
  });
1172
1335
  const heights = m.items.map((it) => it.type === "block" ? it.height : 0);
1173
1336
  setLayout({ pages, boxes, heights });
1174
- }, [blocks, geometry, numbering, fontEpoch, page, docFields]);
1337
+ }, [blocks, geometry, numbering, fontEpoch, page, docFields, font]);
1175
1338
  useEffect(() => {
1176
1339
  const fonts = typeof document !== "undefined" ? document.fonts : void 0;
1177
1340
  let live = true;
@@ -1194,28 +1357,36 @@ function DocViewer({
1194
1357
  }, []);
1195
1358
  const pageWpx = geometry.width * PX_PER_PT;
1196
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]);
1197
1361
  const pageCount = layout?.pages.length ?? 0;
1198
1362
  useEffect(() => {
1199
- if (layout) onLayout?.({ pages: layout.pages.length, pageWidth: geometry.width, pageHeight: geometry.height, scale });
1200
- }, [layout, geometry, scale, onLayout]);
1201
- const typography = {
1202
- fontFamily: fontStack(doc?.defaultFont),
1203
- fontSize: pt(ctx.size),
1204
- lineHeight: SINGLE_LINE,
1205
- color: "#000000",
1206
- textAlign: "left"
1207
- };
1363
+ if (layout && font !== "pending") {
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
+ });
1372
+ }
1373
+ }, [layout, geometry, scale, onLayout, font, notShown]);
1374
+ const typography2 = typography(doc?.defaultFont, ctx.size);
1375
+ const ready = layout !== null && font !== "pending";
1208
1376
  return /* @__PURE__ */ jsxs(
1209
1377
  "div",
1210
1378
  {
1211
1379
  ref: rootRef,
1212
1380
  id,
1213
1381
  "data-lw-viewer": "",
1214
- "data-lw-pages": pageCount || void 0,
1382
+ "data-lw-pages": ready && pageCount || void 0,
1383
+ "data-lw-font": ready ? font : void 0,
1215
1384
  className,
1216
1385
  style: { position: "relative", ...style },
1217
1386
  children: [
1218
1387
  injectStyles && /* @__PURE__ */ jsx("style", { href: "particle-academy-last-word-ui", precedence: "default", children: VIEWER_CSS }),
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 }) }),
1219
1390
  /* @__PURE__ */ jsx(
1220
1391
  "div",
1221
1392
  {
@@ -1223,7 +1394,7 @@ function DocViewer({
1223
1394
  "aria-hidden": "true",
1224
1395
  "data-lw-measure": "",
1225
1396
  style: {
1226
- ...typography,
1397
+ ...typography2,
1227
1398
  position: "absolute",
1228
1399
  visibility: "hidden",
1229
1400
  pointerEvents: "none",
@@ -1246,7 +1417,7 @@ function DocViewer({
1246
1417
  ] })
1247
1418
  }
1248
1419
  ),
1249
- layout && /* @__PURE__ */ jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) => /* @__PURE__ */ jsx(
1420
+ ready && layout && /* @__PURE__ */ jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) => /* @__PURE__ */ jsx(
1250
1421
  PageView,
1251
1422
  {
1252
1423
  page: p,
@@ -1254,7 +1425,7 @@ function DocViewer({
1254
1425
  geometry,
1255
1426
  box: layout.boxes[pageClass(p.index)],
1256
1427
  scale,
1257
- typography,
1428
+ typography: typography2,
1258
1429
  ctx,
1259
1430
  docPage: page,
1260
1431
  docFields,
@@ -1268,7 +1439,7 @@ function DocViewer({
1268
1439
  }
1269
1440
  );
1270
1441
  }
1271
- function PageView({ page, pages, geometry, box, scale, typography, ctx, docPage, docFields, numbering, blocks, heights }) {
1442
+ function PageView({ page, pages, geometry, box, scale, typography: typography2, ctx, docPage, docFields, numbering, blocks, heights }) {
1272
1443
  const n = page.index + 1;
1273
1444
  const g = geometry;
1274
1445
  const bandCtx = { ...ctx, fields: { ...docFields, page: n, pages, sectionPages: pages } };
@@ -1288,7 +1459,7 @@ function PageView({ page, pages, geometry, box, scale, typography, ctx, docPage,
1288
1459
  {
1289
1460
  "data-lw-sheet": "",
1290
1461
  style: {
1291
- ...typography,
1462
+ ...typography2,
1292
1463
  position: "relative",
1293
1464
  width: pt(g.width),
1294
1465
  height: pt(g.height),
@@ -1394,6 +1565,6 @@ function docFromReader(output) {
1394
1565
  return value;
1395
1566
  }
1396
1567
 
1397
- export { DocViewer, PAGE_BAND_DISTANCE_DEFAULT, PAGE_MARGIN_DEFAULT, PAGE_SIZES_PT, PX_PER_PT, bandSlot, bodyBox, docFromReader, 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 };
1398
1569
  //# sourceMappingURL=index.js.map
1399
1570
  //# sourceMappingURL=index.js.map