@particle-academy/last-word-ui 0.2.0 → 0.3.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 +47 -0
- package/README.md +38 -2
- package/dist/index.cjs +154 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +150 -22
- package/dist/index.js.map +1 -1
- package/dist/styles.css +28 -0
- package/dist/styles.css.map +1 -1
- package/fonts/Carlito-Bold.ttf +0 -0
- package/fonts/Carlito-BoldItalic.ttf +0 -0
- package/fonts/Carlito-Italic.ttf +0 -0
- package/fonts/Carlito-Regular.ttf +0 -0
- package/fonts/NOTICE +24 -0
- package/fonts/OFL.txt +94 -0
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -230,7 +230,18 @@ 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;
|
|
233
241
|
}
|
|
242
|
+
type ViewerFont = "carlito" | "fallback" | "unused";
|
|
243
|
+
/** How long the viewer waits for the bundled font before laying out without it. */
|
|
244
|
+
declare const FONT_LOAD_TIMEOUT_MS = 3000;
|
|
234
245
|
interface DocViewerProps {
|
|
235
246
|
/** The document: last-word JSON, e.g. `new DocxReader().read(bytes)`. */
|
|
236
247
|
doc: Doc;
|
|
@@ -286,6 +297,26 @@ interface DocViewerProps {
|
|
|
286
297
|
*/
|
|
287
298
|
declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, filename, now, onLayout, injectStyles, id, className, style, }: DocViewerProps): react.JSX.Element;
|
|
288
299
|
|
|
300
|
+
/** The package-unique family the bundled Carlito is declared under (`fonts.ts`). */
|
|
301
|
+
declare const CARLITO_FAMILY = "LW Carlito";
|
|
302
|
+
|
|
303
|
+
interface CarlitoFace {
|
|
304
|
+
file: string;
|
|
305
|
+
weight: 400 | 700;
|
|
306
|
+
style: "normal" | "italic";
|
|
307
|
+
/** sha256 of the upstream file; a test pins the shipped bytes to it. */
|
|
308
|
+
sha256: string;
|
|
309
|
+
}
|
|
310
|
+
declare const CARLITO_FACES: readonly CarlitoFace[];
|
|
311
|
+
/** The four `@font-face` rules, each face at the URL `url(file)` returns. */
|
|
312
|
+
declare function fontFaceCss(url: (file: string) => string): string;
|
|
313
|
+
/**
|
|
314
|
+
* The faces a document draws in the bundled Carlito, as `FontFaceSet.load()`
|
|
315
|
+
* descriptors, in a fixed order. Only those are fetched: a plain memo never
|
|
316
|
+
* downloads the italic faces.
|
|
317
|
+
*/
|
|
318
|
+
declare function carlitoFaces(doc: Doc): string[];
|
|
319
|
+
|
|
289
320
|
/**
|
|
290
321
|
* A Doc from what a last-word reader returned -- `new DocxReader().read(bytes)`
|
|
291
322
|
* in `@particle-academy/last-word`, or the same JSON from PHP or Python over
|
|
@@ -590,4 +621,4 @@ interface FootnoteNumbering {
|
|
|
590
621
|
*/
|
|
591
622
|
declare function numberFootnotes(doc: Doc): FootnoteNumbering;
|
|
592
623
|
|
|
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -230,7 +230,18 @@ 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;
|
|
233
241
|
}
|
|
242
|
+
type ViewerFont = "carlito" | "fallback" | "unused";
|
|
243
|
+
/** How long the viewer waits for the bundled font before laying out without it. */
|
|
244
|
+
declare const FONT_LOAD_TIMEOUT_MS = 3000;
|
|
234
245
|
interface DocViewerProps {
|
|
235
246
|
/** The document: last-word JSON, e.g. `new DocxReader().read(bytes)`. */
|
|
236
247
|
doc: Doc;
|
|
@@ -286,6 +297,26 @@ interface DocViewerProps {
|
|
|
286
297
|
*/
|
|
287
298
|
declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, filename, now, onLayout, injectStyles, id, className, style, }: DocViewerProps): react.JSX.Element;
|
|
288
299
|
|
|
300
|
+
/** The package-unique family the bundled Carlito is declared under (`fonts.ts`). */
|
|
301
|
+
declare const CARLITO_FAMILY = "LW Carlito";
|
|
302
|
+
|
|
303
|
+
interface CarlitoFace {
|
|
304
|
+
file: string;
|
|
305
|
+
weight: 400 | 700;
|
|
306
|
+
style: "normal" | "italic";
|
|
307
|
+
/** sha256 of the upstream file; a test pins the shipped bytes to it. */
|
|
308
|
+
sha256: string;
|
|
309
|
+
}
|
|
310
|
+
declare const CARLITO_FACES: readonly CarlitoFace[];
|
|
311
|
+
/** The four `@font-face` rules, each face at the URL `url(file)` returns. */
|
|
312
|
+
declare function fontFaceCss(url: (file: string) => string): string;
|
|
313
|
+
/**
|
|
314
|
+
* The faces a document draws in the bundled Carlito, as `FontFaceSet.load()`
|
|
315
|
+
* descriptors, in a fixed order. Only those are fetched: a plain memo never
|
|
316
|
+
* downloads the italic faces.
|
|
317
|
+
*/
|
|
318
|
+
declare function carlitoFaces(doc: Doc): string[];
|
|
319
|
+
|
|
289
320
|
/**
|
|
290
321
|
* A Doc from what a last-word reader returned -- `new DocxReader().read(bytes)`
|
|
291
322
|
* in `@particle-academy/last-word`, or the same JSON from PHP or Python over
|
|
@@ -590,4 +621,4 @@ interface FootnoteNumbering {
|
|
|
590
621
|
*/
|
|
591
622
|
declare function numberFootnotes(doc: Doc): FootnoteNumbering;
|
|
592
623
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useMemo, useRef, useState,
|
|
1
|
+
import { createContext, useMemo, useRef, useState, useEffect, useLayoutEffect, useContext } from 'react';
|
|
2
2
|
import { Text, Separator, Heading, Table, ImageViewer } from '@particle-academy/react-fancy';
|
|
3
3
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
|
|
@@ -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
|
|
308
|
-
const font =
|
|
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
|
-
|
|
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 = {
|
|
@@ -1099,6 +1113,96 @@ function sum(notes) {
|
|
|
1099
1113
|
return notes.reduce((a, n) => a + n.height, 0);
|
|
1100
1114
|
}
|
|
1101
1115
|
|
|
1116
|
+
// src/font-urls.ts
|
|
1117
|
+
function carlitoUrls() {
|
|
1118
|
+
try {
|
|
1119
|
+
return {
|
|
1120
|
+
"Carlito-Regular.ttf": new URL("../fonts/Carlito-Regular.ttf", import.meta.url).href,
|
|
1121
|
+
"Carlito-Bold.ttf": new URL("../fonts/Carlito-Bold.ttf", import.meta.url).href,
|
|
1122
|
+
"Carlito-Italic.ttf": new URL("../fonts/Carlito-Italic.ttf", import.meta.url).href,
|
|
1123
|
+
"Carlito-BoldItalic.ttf": new URL("../fonts/Carlito-BoldItalic.ttf", import.meta.url).href
|
|
1124
|
+
};
|
|
1125
|
+
} catch {
|
|
1126
|
+
return null;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// src/fonts.ts
|
|
1131
|
+
var CARLITO_FACES = [
|
|
1132
|
+
{ file: "Carlito-Regular.ttf", weight: 400, style: "normal", sha256: "f6418f708baede9789daef5d458c0f53d2a888af9820e8062934e504fedc6595" },
|
|
1133
|
+
{ file: "Carlito-Bold.ttf", weight: 700, style: "normal", sha256: "bb5d20f79b82599ec72983597437373a80f2d2085fa91fc144fd74e876a594db" },
|
|
1134
|
+
{ file: "Carlito-Italic.ttf", weight: 400, style: "italic", sha256: "0b019225e58d702bfedcbd35c21696769f8ee115cb6343f84c2f240312450d1c" },
|
|
1135
|
+
{ file: "Carlito-BoldItalic.ttf", weight: 700, style: "italic", sha256: "b32928186c119599e03ca6a1ffc680fdcb7fac95772f4b95d989cf6cd3861517" }
|
|
1136
|
+
];
|
|
1137
|
+
function fontFaceCss(url) {
|
|
1138
|
+
return CARLITO_FACES.map(
|
|
1139
|
+
(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"); }`
|
|
1140
|
+
).join("\n");
|
|
1141
|
+
}
|
|
1142
|
+
var clean = (name) => typeof name === "string" ? name.replace(/[^A-Za-z0-9 _-]/g, "").trim() : "";
|
|
1143
|
+
function usesCarlito(name) {
|
|
1144
|
+
const n = clean(name);
|
|
1145
|
+
return (n === "" ? DEFAULT_FONT : n).toLowerCase() === "calibri";
|
|
1146
|
+
}
|
|
1147
|
+
function carlitoFaces(doc) {
|
|
1148
|
+
const used = /* @__PURE__ */ new Set();
|
|
1149
|
+
const docCarlito = usesCarlito(doc?.defaultFont);
|
|
1150
|
+
const runs = (list, bold, italic) => {
|
|
1151
|
+
if (!Array.isArray(list)) return;
|
|
1152
|
+
for (const r of list) {
|
|
1153
|
+
if (!r || typeof r !== "object") continue;
|
|
1154
|
+
if (r.footnote && typeof r.footnote === "object") blocks(r.footnote.blocks, false, false);
|
|
1155
|
+
const hasFont = typeof r.font === "string" && r.font !== "";
|
|
1156
|
+
if (r.code || !(hasFont ? usesCarlito(r.font) : docCarlito)) continue;
|
|
1157
|
+
used.add(`${bold || r.bold ? 700 : 400}:${italic || r.italic ? "italic" : "normal"}`);
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
const blocks = (list, bold, italic) => {
|
|
1161
|
+
if (!Array.isArray(list)) return;
|
|
1162
|
+
for (const b of list) {
|
|
1163
|
+
if (!b || typeof b !== "object") continue;
|
|
1164
|
+
switch (b.type) {
|
|
1165
|
+
case "paragraph":
|
|
1166
|
+
runs(b.runs, bold, italic);
|
|
1167
|
+
break;
|
|
1168
|
+
case "heading":
|
|
1169
|
+
runs(b.runs, true, italic);
|
|
1170
|
+
break;
|
|
1171
|
+
case "list": {
|
|
1172
|
+
const items = (xs) => {
|
|
1173
|
+
if (!Array.isArray(xs)) return;
|
|
1174
|
+
for (const it of xs) {
|
|
1175
|
+
runs(it?.runs, bold, italic);
|
|
1176
|
+
items(it?.children);
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
items(b.items);
|
|
1180
|
+
break;
|
|
1181
|
+
}
|
|
1182
|
+
case "quote":
|
|
1183
|
+
blocks(b.blocks, bold, true);
|
|
1184
|
+
break;
|
|
1185
|
+
case "table":
|
|
1186
|
+
for (const row of Array.isArray(b.rows) ? b.rows : []) {
|
|
1187
|
+
for (const cell of Array.isArray(row?.cells) ? row.cells : []) blocks(cell?.blocks, bold || row.header === true, italic);
|
|
1188
|
+
}
|
|
1189
|
+
break;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
blocks(doc?.blocks, false, false);
|
|
1194
|
+
const page = doc?.page && typeof doc.page === "object" ? doc.page : {};
|
|
1195
|
+
for (const key of ["header", "footer", "firstHeader", "firstFooter", "evenHeader", "evenFooter"]) {
|
|
1196
|
+
const band = page[key];
|
|
1197
|
+
if (!band || typeof band !== "object") continue;
|
|
1198
|
+
if (Array.isArray(band.blocks)) blocks(band.blocks, false, false);
|
|
1199
|
+
else if (docCarlito && [band.left, band.center, band.right].some((s) => typeof s === "string" && s !== "")) used.add("400:normal");
|
|
1200
|
+
}
|
|
1201
|
+
return CARLITO_FACES.filter((f) => used.has(`${f.weight}:${f.style}`)).map(
|
|
1202
|
+
(f) => `${f.weight} ${f.style} 16px "${CARLITO_FAMILY}"`
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1102
1206
|
// src/viewer-css.ts
|
|
1103
1207
|
var VIEWER_CSS = `
|
|
1104
1208
|
:where([data-lw-viewer]) [data-lw-table] > table { width: 100%; border-collapse: collapse; table-layout: fixed; }
|
|
@@ -1107,6 +1211,16 @@ var VIEWER_CSS = `
|
|
|
1107
1211
|
:where([data-lw-viewer]) hr[data-react-fancy-separator] { margin: 0; width: 100%; border: 0; border-top: 0.75pt solid #000000; }
|
|
1108
1212
|
:where([data-lw-viewer]) [data-lw-sheet] p, :where([data-lw-viewer]) [data-lw-measure] p { margin-top: 0; margin-bottom: 0; }
|
|
1109
1213
|
`.trim();
|
|
1214
|
+
var FONT_LOAD_TIMEOUT_MS = 3e3;
|
|
1215
|
+
var FONT_CSS = (() => {
|
|
1216
|
+
const urls = carlitoUrls();
|
|
1217
|
+
return urls ? fontFaceCss((file) => urls[file]) : null;
|
|
1218
|
+
})();
|
|
1219
|
+
function initialFontState(faces) {
|
|
1220
|
+
if (faces.length === 0) return "unused";
|
|
1221
|
+
const fonts = typeof document !== "undefined" ? document.fonts : void 0;
|
|
1222
|
+
return fonts && typeof fonts.load === "function" ? "pending" : "fallback";
|
|
1223
|
+
}
|
|
1110
1224
|
function DocViewer({
|
|
1111
1225
|
doc,
|
|
1112
1226
|
fit = "width",
|
|
@@ -1143,6 +1257,9 @@ function DocViewer({
|
|
|
1143
1257
|
const measureRef = useRef(null);
|
|
1144
1258
|
const [layout, setLayout] = useState(null);
|
|
1145
1259
|
const [fontEpoch, setFontEpoch] = useState(0);
|
|
1260
|
+
const faces = useMemo(() => carlitoFaces(doc), [doc]);
|
|
1261
|
+
const facesKey = faces.join("|");
|
|
1262
|
+
const [font, setFont] = useState(() => initialFontState(faces));
|
|
1146
1263
|
const [width, setWidth] = useState(null);
|
|
1147
1264
|
const ctx = useMemo(
|
|
1148
1265
|
() => ({
|
|
@@ -1153,9 +1270,21 @@ function DocViewer({
|
|
|
1153
1270
|
}),
|
|
1154
1271
|
[numbering, doc, geometry]
|
|
1155
1272
|
);
|
|
1273
|
+
useEffect(() => {
|
|
1274
|
+
const state = initialFontState(faces);
|
|
1275
|
+
setFont(state);
|
|
1276
|
+
if (state !== "pending") return;
|
|
1277
|
+
let live = true;
|
|
1278
|
+
const timer = setTimeout(() => live && setFont((f) => f === "pending" ? "fallback" : f), FONT_LOAD_TIMEOUT_MS);
|
|
1279
|
+
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"));
|
|
1280
|
+
return () => {
|
|
1281
|
+
live = false;
|
|
1282
|
+
clearTimeout(timer);
|
|
1283
|
+
};
|
|
1284
|
+
}, [facesKey]);
|
|
1156
1285
|
useLayoutEffect(() => {
|
|
1157
1286
|
const el = measureRef.current;
|
|
1158
|
-
if (!el) return;
|
|
1287
|
+
if (!el || font === "pending") return;
|
|
1159
1288
|
const m = measure(el, blocks);
|
|
1160
1289
|
const toPt = (h) => ({
|
|
1161
1290
|
default: h.default / PX_PER_PT,
|
|
@@ -1171,7 +1300,7 @@ function DocViewer({
|
|
|
1171
1300
|
});
|
|
1172
1301
|
const heights = m.items.map((it) => it.type === "block" ? it.height : 0);
|
|
1173
1302
|
setLayout({ pages, boxes, heights });
|
|
1174
|
-
}, [blocks, geometry, numbering, fontEpoch, page, docFields]);
|
|
1303
|
+
}, [blocks, geometry, numbering, fontEpoch, page, docFields, font]);
|
|
1175
1304
|
useEffect(() => {
|
|
1176
1305
|
const fonts = typeof document !== "undefined" ? document.fonts : void 0;
|
|
1177
1306
|
let live = true;
|
|
@@ -1196,26 +1325,25 @@ function DocViewer({
|
|
|
1196
1325
|
const scale = typeof fixedScale === "number" && fixedScale > 0 ? fixedScale : fit === "none" || !width ? 1 : Math.min(maxScale, width / pageWpx);
|
|
1197
1326
|
const pageCount = layout?.pages.length ?? 0;
|
|
1198
1327
|
useEffect(() => {
|
|
1199
|
-
if (layout
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
color: "#000000",
|
|
1206
|
-
textAlign: "left"
|
|
1207
|
-
};
|
|
1328
|
+
if (layout && font !== "pending") {
|
|
1329
|
+
onLayout?.({ pages: layout.pages.length, pageWidth: geometry.width, pageHeight: geometry.height, scale, font });
|
|
1330
|
+
}
|
|
1331
|
+
}, [layout, geometry, scale, onLayout, font]);
|
|
1332
|
+
const typography2 = typography(doc?.defaultFont, ctx.size);
|
|
1333
|
+
const ready = layout !== null && font !== "pending";
|
|
1208
1334
|
return /* @__PURE__ */ jsxs(
|
|
1209
1335
|
"div",
|
|
1210
1336
|
{
|
|
1211
1337
|
ref: rootRef,
|
|
1212
1338
|
id,
|
|
1213
1339
|
"data-lw-viewer": "",
|
|
1214
|
-
"data-lw-pages": pageCount || void 0,
|
|
1340
|
+
"data-lw-pages": ready && pageCount || void 0,
|
|
1341
|
+
"data-lw-font": ready ? font : void 0,
|
|
1215
1342
|
className,
|
|
1216
1343
|
style: { position: "relative", ...style },
|
|
1217
1344
|
children: [
|
|
1218
1345
|
injectStyles && /* @__PURE__ */ jsx("style", { href: "particle-academy-last-word-ui", precedence: "default", children: VIEWER_CSS }),
|
|
1346
|
+
injectStyles && FONT_CSS && /* @__PURE__ */ jsx("style", { href: "particle-academy-last-word-ui-fonts", precedence: "default", children: FONT_CSS }),
|
|
1219
1347
|
/* @__PURE__ */ jsx(
|
|
1220
1348
|
"div",
|
|
1221
1349
|
{
|
|
@@ -1223,7 +1351,7 @@ function DocViewer({
|
|
|
1223
1351
|
"aria-hidden": "true",
|
|
1224
1352
|
"data-lw-measure": "",
|
|
1225
1353
|
style: {
|
|
1226
|
-
...
|
|
1354
|
+
...typography2,
|
|
1227
1355
|
position: "absolute",
|
|
1228
1356
|
visibility: "hidden",
|
|
1229
1357
|
pointerEvents: "none",
|
|
@@ -1246,7 +1374,7 @@ function DocViewer({
|
|
|
1246
1374
|
] })
|
|
1247
1375
|
}
|
|
1248
1376
|
),
|
|
1249
|
-
layout && /* @__PURE__ */ jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) => /* @__PURE__ */ jsx(
|
|
1377
|
+
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
1378
|
PageView,
|
|
1251
1379
|
{
|
|
1252
1380
|
page: p,
|
|
@@ -1254,7 +1382,7 @@ function DocViewer({
|
|
|
1254
1382
|
geometry,
|
|
1255
1383
|
box: layout.boxes[pageClass(p.index)],
|
|
1256
1384
|
scale,
|
|
1257
|
-
typography,
|
|
1385
|
+
typography: typography2,
|
|
1258
1386
|
ctx,
|
|
1259
1387
|
docPage: page,
|
|
1260
1388
|
docFields,
|
|
@@ -1268,7 +1396,7 @@ function DocViewer({
|
|
|
1268
1396
|
}
|
|
1269
1397
|
);
|
|
1270
1398
|
}
|
|
1271
|
-
function PageView({ page, pages, geometry, box, scale, typography, ctx, docPage, docFields, numbering, blocks, heights }) {
|
|
1399
|
+
function PageView({ page, pages, geometry, box, scale, typography: typography2, ctx, docPage, docFields, numbering, blocks, heights }) {
|
|
1272
1400
|
const n = page.index + 1;
|
|
1273
1401
|
const g = geometry;
|
|
1274
1402
|
const bandCtx = { ...ctx, fields: { ...docFields, page: n, pages, sectionPages: pages } };
|
|
@@ -1288,7 +1416,7 @@ function PageView({ page, pages, geometry, box, scale, typography, ctx, docPage,
|
|
|
1288
1416
|
{
|
|
1289
1417
|
"data-lw-sheet": "",
|
|
1290
1418
|
style: {
|
|
1291
|
-
...
|
|
1419
|
+
...typography2,
|
|
1292
1420
|
position: "relative",
|
|
1293
1421
|
width: pt(g.width),
|
|
1294
1422
|
height: pt(g.height),
|
|
@@ -1394,6 +1522,6 @@ function docFromReader(output) {
|
|
|
1394
1522
|
return value;
|
|
1395
1523
|
}
|
|
1396
1524
|
|
|
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 };
|
|
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 };
|
|
1398
1526
|
//# sourceMappingURL=index.js.map
|
|
1399
1527
|
//# sourceMappingURL=index.js.map
|