@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/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,53 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [0.3.0] - 2026-11-01
|
|
14
|
+
|
|
15
|
+
**What you must do: probably nothing, but expect page breaks to move.** Calibri
|
|
16
|
+
and default text now draws in a bundled font with kerning off, so a document
|
|
17
|
+
can break differently from 0.2.0, on every machine, including ones that had
|
|
18
|
+
real Calibri or only Arial. That is the point: the count is now the same
|
|
19
|
+
everywhere and matches last-word's `Agent::layout()`. Under a strict CSP you
|
|
20
|
+
already import `styles.css`; allow its font files in `font-src`. On the
|
|
21
|
+
CommonJS build, import `styles.css` too, or the viewer reports
|
|
22
|
+
`font: "fallback"`.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- **A bundled Carlito** (1.104, from googlefonts/carlito, unmodified, SIL OFL
|
|
27
|
+
1.1 with a NOTICE in `fonts/`), declared as `"LW Carlito"` in regular, bold,
|
|
28
|
+
italic and bold italic. Metric-compatible with Calibri: every printable
|
|
29
|
+
ASCII and Latin-1 advance is equal in all four styles. The package now
|
|
30
|
+
publishes `fonts/` (about 2.7 MB of TTF; Carlito is not published as woff2
|
|
31
|
+
upstream, and these are the files as published). A browser fetches only the
|
|
32
|
+
faces a document uses.
|
|
33
|
+
- `styles.css` declares the same `@font-face` rules, with URLs relative to the
|
|
34
|
+
stylesheet, for the strict-CSP route.
|
|
35
|
+
- `DocViewerLayout.font`: `"carlito"`, `"fallback"` or `"unused"`, and
|
|
36
|
+
`data-lw-font` on the root, so a caller can tell a deterministic page count
|
|
37
|
+
from one that depends on the machine.
|
|
38
|
+
- `FONT_LOAD_TIMEOUT_MS` (3000) and the `ViewerFont` type.
|
|
39
|
+
- `demo/agreement.html`: the harness that renders documents in the viewer and
|
|
40
|
+
records the page layout last-word's `layout()` is held to. The fixtures it
|
|
41
|
+
produced are in `tests/fixtures/viewer-agreement.json` (the same bytes as in
|
|
42
|
+
last-word; both pin the sha256).
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- **Calibri and unspecified text draws in the bundled Carlito, first in the
|
|
47
|
+
stack**, ahead of `Calibri`, `Carlito`, `Segoe UI` and `Arial`. Pages may
|
|
48
|
+
break differently from 0.2.0 on any machine: where real Calibri was
|
|
49
|
+
installed, because kerning is now off; where it was not, because the text is
|
|
50
|
+
no longer in Segoe UI or Arial. Every other explicit font keeps its stack,
|
|
51
|
+
and its breaks still depend on the machine.
|
|
52
|
+
- **Kerning and ligatures are off** (`font-kerning: none`,
|
|
53
|
+
`font-variant-ligatures: none`), as in Word by default, and
|
|
54
|
+
`text-rendering: geometricPrecision`.
|
|
55
|
+
- **The viewer waits for the font before it measures.** No pages and no
|
|
56
|
+
`onLayout` until the faces the document draws have loaded (or 3 s pass).
|
|
57
|
+
0.2.0 drew pages in the fallback first and re-laid them out when web fonts
|
|
58
|
+
arrived, so `onLayout` could report a count that changed a moment later.
|
|
59
|
+
|
|
13
60
|
## [0.2.0] - 2026-11-01
|
|
14
61
|
|
|
15
62
|
Renders last-word 0.16.0's band variants and field tokens. **Consumer action:
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ so a deep clone between numbering and render would lose the marks.
|
|
|
51
51
|
| `gap` | `number` | `16` | px between pages |
|
|
52
52
|
| `filename` | `string` | `""` | what a `{filename}` band field shows |
|
|
53
53
|
| `now` | `Date \| string` | first render | the moment `{date}` / `{time}` show; an ISO string is fine |
|
|
54
|
-
| `onLayout` | `(l) => void` | | `{ pages, pageWidth, pageHeight, scale }`, JSON |
|
|
54
|
+
| `onLayout` | `(l) => void` | | `{ pages, pageWidth, pageHeight, scale, font }`, JSON; see *Fonts* |
|
|
55
55
|
| `injectStyles` | `boolean` | `true` | see *Styles* |
|
|
56
56
|
| `id`, `className`, `style` | | | on the root |
|
|
57
57
|
|
|
@@ -75,6 +75,41 @@ rules instead:
|
|
|
75
75
|
import "@particle-academy/last-word-ui/styles.css";
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
`styles.css` also declares the bundled font (below) with URLs relative to
|
|
79
|
+
itself (`../fonts/*.ttf`), so the bundler that imports it emits the font files.
|
|
80
|
+
Allow them in `font-src` (`'self'` covers it when you serve them from your own
|
|
81
|
+
origin).
|
|
82
|
+
|
|
83
|
+
### Fonts: the same page count on every machine
|
|
84
|
+
|
|
85
|
+
Calibri, and text with no font named, draws in a **bundled Carlito** (family
|
|
86
|
+
`"LW Carlito"`, first in the stack). Carlito is metric-compatible with Calibri:
|
|
87
|
+
every printable ASCII and Latin-1 advance is identical in all four styles, so
|
|
88
|
+
lines break where Calibri's would. Because the font ships with the package, a
|
|
89
|
+
document paginates the same on a machine with Calibri, with Arial, or with
|
|
90
|
+
neither, and the count agrees with last-word's `Agent::layout()` (PHP, 0.17.0),
|
|
91
|
+
which measures with the same font's metrics.
|
|
92
|
+
|
|
93
|
+
- Kerning and ligatures are off, as they are in Word by default, so a line is
|
|
94
|
+
exactly the sum of its advances.
|
|
95
|
+
- The viewer **waits for the font** before it measures: no pages are drawn and
|
|
96
|
+
`onLayout` is not called until the faces the document uses have loaded (only
|
|
97
|
+
those are fetched; a plain memo never downloads the italics). After
|
|
98
|
+
`FONT_LOAD_TIMEOUT_MS` (3 s) it lays out without it.
|
|
99
|
+
- `onLayout` reports `font`: `"carlito"` (deterministic), `"fallback"` (the
|
|
100
|
+
font could not load, so the count depends on this machine) or `"unused"` (no
|
|
101
|
+
Calibri text). The root carries the same value as `data-lw-font`.
|
|
102
|
+
- Only Calibri and default text is deterministic. Any other font in the
|
|
103
|
+
document draws in that font as installed, as before.
|
|
104
|
+
- With `injectStyles` (the default) the `@font-face` rules point at the files
|
|
105
|
+
through `new URL("../fonts/...", import.meta.url)`, which Vite, webpack 5,
|
|
106
|
+
Rollup and Parcel resolve to emitted assets. The CommonJS build has no
|
|
107
|
+
`import.meta`, so there it reports `"fallback"`: import `styles.css` instead.
|
|
108
|
+
|
|
109
|
+
The four TTFs are Carlito 1.104 from
|
|
110
|
+
[googlefonts/carlito](https://github.com/googlefonts/carlito), shipped
|
|
111
|
+
unmodified under the SIL Open Font License 1.1 (`fonts/OFL.txt`, `fonts/NOTICE`).
|
|
112
|
+
|
|
78
113
|
## What it renders
|
|
79
114
|
|
|
80
115
|
- **Pages:** letter, legal and a4, portrait or landscape, with margins as the
|
|
@@ -150,4 +185,5 @@ npm run demo # vite demo: a multi-page memo, wide and narrow
|
|
|
150
185
|
|
|
151
186
|
## License
|
|
152
187
|
|
|
153
|
-
MIT
|
|
188
|
+
MIT, except the fonts in `fonts/`: Carlito, SIL Open Font License 1.1, see
|
|
189
|
+
`fonts/OFL.txt` and `fonts/NOTICE`.
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var react = require('react');
|
|
|
4
4
|
var reactFancy = require('@particle-academy/react-fancy');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
|
|
7
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
8
|
// src/DocViewer.tsx
|
|
8
9
|
|
|
9
10
|
// src/geometry.ts
|
|
@@ -305,11 +306,25 @@ var FALLBACKS = {
|
|
|
305
306
|
"courier new": '"Liberation Mono", Cousine, monospace',
|
|
306
307
|
consolas: '"Liberation Mono", Menlo, monospace'
|
|
307
308
|
};
|
|
309
|
+
var CARLITO_FAMILY = "LW Carlito";
|
|
308
310
|
function fontStack(name) {
|
|
309
|
-
const
|
|
310
|
-
const font =
|
|
311
|
+
const clean2 = typeof name === "string" ? name.replace(/[^A-Za-z0-9 _-]/g, "").trim() : "";
|
|
312
|
+
const font = clean2 === "" ? DEFAULT_FONT : clean2;
|
|
311
313
|
const fallback = FALLBACKS[font.toLowerCase()] ?? 'Carlito, "Segoe UI", Arial, sans-serif';
|
|
312
|
-
|
|
314
|
+
const first = font.toLowerCase() === "calibri" ? `"${CARLITO_FAMILY}", ` : "";
|
|
315
|
+
return `${first}"${font}", ${fallback}`;
|
|
316
|
+
}
|
|
317
|
+
function typography(defaultFont, size) {
|
|
318
|
+
return {
|
|
319
|
+
fontFamily: fontStack(defaultFont),
|
|
320
|
+
fontSize: pt(size),
|
|
321
|
+
lineHeight: SINGLE_LINE,
|
|
322
|
+
color: "#000000",
|
|
323
|
+
textAlign: "left",
|
|
324
|
+
fontKerning: "none",
|
|
325
|
+
fontVariantLigatures: "none",
|
|
326
|
+
textRendering: "geometricPrecision"
|
|
327
|
+
};
|
|
313
328
|
}
|
|
314
329
|
var MONO = fontStack("Consolas");
|
|
315
330
|
var CSS_STYLE = {
|
|
@@ -1101,6 +1116,96 @@ function sum(notes) {
|
|
|
1101
1116
|
return notes.reduce((a, n) => a + n.height, 0);
|
|
1102
1117
|
}
|
|
1103
1118
|
|
|
1119
|
+
// src/font-urls.ts
|
|
1120
|
+
function carlitoUrls() {
|
|
1121
|
+
try {
|
|
1122
|
+
return {
|
|
1123
|
+
"Carlito-Regular.ttf": new URL("../fonts/Carlito-Regular.ttf", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href,
|
|
1124
|
+
"Carlito-Bold.ttf": new URL("../fonts/Carlito-Bold.ttf", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href,
|
|
1125
|
+
"Carlito-Italic.ttf": new URL("../fonts/Carlito-Italic.ttf", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href,
|
|
1126
|
+
"Carlito-BoldItalic.ttf": new URL("../fonts/Carlito-BoldItalic.ttf", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href
|
|
1127
|
+
};
|
|
1128
|
+
} catch {
|
|
1129
|
+
return null;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
// src/fonts.ts
|
|
1134
|
+
var CARLITO_FACES = [
|
|
1135
|
+
{ file: "Carlito-Regular.ttf", weight: 400, style: "normal", sha256: "f6418f708baede9789daef5d458c0f53d2a888af9820e8062934e504fedc6595" },
|
|
1136
|
+
{ file: "Carlito-Bold.ttf", weight: 700, style: "normal", sha256: "bb5d20f79b82599ec72983597437373a80f2d2085fa91fc144fd74e876a594db" },
|
|
1137
|
+
{ file: "Carlito-Italic.ttf", weight: 400, style: "italic", sha256: "0b019225e58d702bfedcbd35c21696769f8ee115cb6343f84c2f240312450d1c" },
|
|
1138
|
+
{ file: "Carlito-BoldItalic.ttf", weight: 700, style: "italic", sha256: "b32928186c119599e03ca6a1ffc680fdcb7fac95772f4b95d989cf6cd3861517" }
|
|
1139
|
+
];
|
|
1140
|
+
function fontFaceCss(url) {
|
|
1141
|
+
return CARLITO_FACES.map(
|
|
1142
|
+
(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"); }`
|
|
1143
|
+
).join("\n");
|
|
1144
|
+
}
|
|
1145
|
+
var clean = (name) => typeof name === "string" ? name.replace(/[^A-Za-z0-9 _-]/g, "").trim() : "";
|
|
1146
|
+
function usesCarlito(name) {
|
|
1147
|
+
const n = clean(name);
|
|
1148
|
+
return (n === "" ? DEFAULT_FONT : n).toLowerCase() === "calibri";
|
|
1149
|
+
}
|
|
1150
|
+
function carlitoFaces(doc) {
|
|
1151
|
+
const used = /* @__PURE__ */ new Set();
|
|
1152
|
+
const docCarlito = usesCarlito(doc?.defaultFont);
|
|
1153
|
+
const runs = (list, bold, italic) => {
|
|
1154
|
+
if (!Array.isArray(list)) return;
|
|
1155
|
+
for (const r of list) {
|
|
1156
|
+
if (!r || typeof r !== "object") continue;
|
|
1157
|
+
if (r.footnote && typeof r.footnote === "object") blocks(r.footnote.blocks, false, false);
|
|
1158
|
+
const hasFont = typeof r.font === "string" && r.font !== "";
|
|
1159
|
+
if (r.code || !(hasFont ? usesCarlito(r.font) : docCarlito)) continue;
|
|
1160
|
+
used.add(`${bold || r.bold ? 700 : 400}:${italic || r.italic ? "italic" : "normal"}`);
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
const blocks = (list, bold, italic) => {
|
|
1164
|
+
if (!Array.isArray(list)) return;
|
|
1165
|
+
for (const b of list) {
|
|
1166
|
+
if (!b || typeof b !== "object") continue;
|
|
1167
|
+
switch (b.type) {
|
|
1168
|
+
case "paragraph":
|
|
1169
|
+
runs(b.runs, bold, italic);
|
|
1170
|
+
break;
|
|
1171
|
+
case "heading":
|
|
1172
|
+
runs(b.runs, true, italic);
|
|
1173
|
+
break;
|
|
1174
|
+
case "list": {
|
|
1175
|
+
const items = (xs) => {
|
|
1176
|
+
if (!Array.isArray(xs)) return;
|
|
1177
|
+
for (const it of xs) {
|
|
1178
|
+
runs(it?.runs, bold, italic);
|
|
1179
|
+
items(it?.children);
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
items(b.items);
|
|
1183
|
+
break;
|
|
1184
|
+
}
|
|
1185
|
+
case "quote":
|
|
1186
|
+
blocks(b.blocks, bold, true);
|
|
1187
|
+
break;
|
|
1188
|
+
case "table":
|
|
1189
|
+
for (const row of Array.isArray(b.rows) ? b.rows : []) {
|
|
1190
|
+
for (const cell of Array.isArray(row?.cells) ? row.cells : []) blocks(cell?.blocks, bold || row.header === true, italic);
|
|
1191
|
+
}
|
|
1192
|
+
break;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
blocks(doc?.blocks, false, false);
|
|
1197
|
+
const page = doc?.page && typeof doc.page === "object" ? doc.page : {};
|
|
1198
|
+
for (const key of ["header", "footer", "firstHeader", "firstFooter", "evenHeader", "evenFooter"]) {
|
|
1199
|
+
const band = page[key];
|
|
1200
|
+
if (!band || typeof band !== "object") continue;
|
|
1201
|
+
if (Array.isArray(band.blocks)) blocks(band.blocks, false, false);
|
|
1202
|
+
else if (docCarlito && [band.left, band.center, band.right].some((s) => typeof s === "string" && s !== "")) used.add("400:normal");
|
|
1203
|
+
}
|
|
1204
|
+
return CARLITO_FACES.filter((f) => used.has(`${f.weight}:${f.style}`)).map(
|
|
1205
|
+
(f) => `${f.weight} ${f.style} 16px "${CARLITO_FAMILY}"`
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1104
1209
|
// src/viewer-css.ts
|
|
1105
1210
|
var VIEWER_CSS = `
|
|
1106
1211
|
:where([data-lw-viewer]) [data-lw-table] > table { width: 100%; border-collapse: collapse; table-layout: fixed; }
|
|
@@ -1109,6 +1214,16 @@ var VIEWER_CSS = `
|
|
|
1109
1214
|
:where([data-lw-viewer]) hr[data-react-fancy-separator] { margin: 0; width: 100%; border: 0; border-top: 0.75pt solid #000000; }
|
|
1110
1215
|
:where([data-lw-viewer]) [data-lw-sheet] p, :where([data-lw-viewer]) [data-lw-measure] p { margin-top: 0; margin-bottom: 0; }
|
|
1111
1216
|
`.trim();
|
|
1217
|
+
var FONT_LOAD_TIMEOUT_MS = 3e3;
|
|
1218
|
+
var FONT_CSS = (() => {
|
|
1219
|
+
const urls = carlitoUrls();
|
|
1220
|
+
return urls ? fontFaceCss((file) => urls[file]) : null;
|
|
1221
|
+
})();
|
|
1222
|
+
function initialFontState(faces) {
|
|
1223
|
+
if (faces.length === 0) return "unused";
|
|
1224
|
+
const fonts = typeof document !== "undefined" ? document.fonts : void 0;
|
|
1225
|
+
return fonts && typeof fonts.load === "function" ? "pending" : "fallback";
|
|
1226
|
+
}
|
|
1112
1227
|
function DocViewer({
|
|
1113
1228
|
doc,
|
|
1114
1229
|
fit = "width",
|
|
@@ -1145,6 +1260,9 @@ function DocViewer({
|
|
|
1145
1260
|
const measureRef = react.useRef(null);
|
|
1146
1261
|
const [layout, setLayout] = react.useState(null);
|
|
1147
1262
|
const [fontEpoch, setFontEpoch] = react.useState(0);
|
|
1263
|
+
const faces = react.useMemo(() => carlitoFaces(doc), [doc]);
|
|
1264
|
+
const facesKey = faces.join("|");
|
|
1265
|
+
const [font, setFont] = react.useState(() => initialFontState(faces));
|
|
1148
1266
|
const [width, setWidth] = react.useState(null);
|
|
1149
1267
|
const ctx = react.useMemo(
|
|
1150
1268
|
() => ({
|
|
@@ -1155,9 +1273,21 @@ function DocViewer({
|
|
|
1155
1273
|
}),
|
|
1156
1274
|
[numbering, doc, geometry]
|
|
1157
1275
|
);
|
|
1276
|
+
react.useEffect(() => {
|
|
1277
|
+
const state = initialFontState(faces);
|
|
1278
|
+
setFont(state);
|
|
1279
|
+
if (state !== "pending") return;
|
|
1280
|
+
let live = true;
|
|
1281
|
+
const timer = setTimeout(() => live && setFont((f) => f === "pending" ? "fallback" : f), FONT_LOAD_TIMEOUT_MS);
|
|
1282
|
+
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"));
|
|
1283
|
+
return () => {
|
|
1284
|
+
live = false;
|
|
1285
|
+
clearTimeout(timer);
|
|
1286
|
+
};
|
|
1287
|
+
}, [facesKey]);
|
|
1158
1288
|
react.useLayoutEffect(() => {
|
|
1159
1289
|
const el = measureRef.current;
|
|
1160
|
-
if (!el) return;
|
|
1290
|
+
if (!el || font === "pending") return;
|
|
1161
1291
|
const m = measure(el, blocks);
|
|
1162
1292
|
const toPt = (h) => ({
|
|
1163
1293
|
default: h.default / PX_PER_PT,
|
|
@@ -1173,7 +1303,7 @@ function DocViewer({
|
|
|
1173
1303
|
});
|
|
1174
1304
|
const heights = m.items.map((it) => it.type === "block" ? it.height : 0);
|
|
1175
1305
|
setLayout({ pages, boxes, heights });
|
|
1176
|
-
}, [blocks, geometry, numbering, fontEpoch, page, docFields]);
|
|
1306
|
+
}, [blocks, geometry, numbering, fontEpoch, page, docFields, font]);
|
|
1177
1307
|
react.useEffect(() => {
|
|
1178
1308
|
const fonts = typeof document !== "undefined" ? document.fonts : void 0;
|
|
1179
1309
|
let live = true;
|
|
@@ -1198,26 +1328,25 @@ function DocViewer({
|
|
|
1198
1328
|
const scale = typeof fixedScale === "number" && fixedScale > 0 ? fixedScale : fit === "none" || !width ? 1 : Math.min(maxScale, width / pageWpx);
|
|
1199
1329
|
const pageCount = layout?.pages.length ?? 0;
|
|
1200
1330
|
react.useEffect(() => {
|
|
1201
|
-
if (layout
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
color: "#000000",
|
|
1208
|
-
textAlign: "left"
|
|
1209
|
-
};
|
|
1331
|
+
if (layout && font !== "pending") {
|
|
1332
|
+
onLayout?.({ pages: layout.pages.length, pageWidth: geometry.width, pageHeight: geometry.height, scale, font });
|
|
1333
|
+
}
|
|
1334
|
+
}, [layout, geometry, scale, onLayout, font]);
|
|
1335
|
+
const typography2 = typography(doc?.defaultFont, ctx.size);
|
|
1336
|
+
const ready = layout !== null && font !== "pending";
|
|
1210
1337
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1211
1338
|
"div",
|
|
1212
1339
|
{
|
|
1213
1340
|
ref: rootRef,
|
|
1214
1341
|
id,
|
|
1215
1342
|
"data-lw-viewer": "",
|
|
1216
|
-
"data-lw-pages": pageCount || void 0,
|
|
1343
|
+
"data-lw-pages": ready && pageCount || void 0,
|
|
1344
|
+
"data-lw-font": ready ? font : void 0,
|
|
1217
1345
|
className,
|
|
1218
1346
|
style: { position: "relative", ...style },
|
|
1219
1347
|
children: [
|
|
1220
1348
|
injectStyles && /* @__PURE__ */ jsxRuntime.jsx("style", { href: "particle-academy-last-word-ui", precedence: "default", children: VIEWER_CSS }),
|
|
1349
|
+
injectStyles && FONT_CSS && /* @__PURE__ */ jsxRuntime.jsx("style", { href: "particle-academy-last-word-ui-fonts", precedence: "default", children: FONT_CSS }),
|
|
1221
1350
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1222
1351
|
"div",
|
|
1223
1352
|
{
|
|
@@ -1225,7 +1354,7 @@ function DocViewer({
|
|
|
1225
1354
|
"aria-hidden": "true",
|
|
1226
1355
|
"data-lw-measure": "",
|
|
1227
1356
|
style: {
|
|
1228
|
-
...
|
|
1357
|
+
...typography2,
|
|
1229
1358
|
position: "absolute",
|
|
1230
1359
|
visibility: "hidden",
|
|
1231
1360
|
pointerEvents: "none",
|
|
@@ -1248,7 +1377,7 @@ function DocViewer({
|
|
|
1248
1377
|
] })
|
|
1249
1378
|
}
|
|
1250
1379
|
),
|
|
1251
|
-
layout && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1380
|
+
ready && layout && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-lw-page-stack": "", style: { display: "flex", flexDirection: "column", alignItems: "center", gap }, children: layout.pages.map((p) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1252
1381
|
PageView,
|
|
1253
1382
|
{
|
|
1254
1383
|
page: p,
|
|
@@ -1256,7 +1385,7 @@ function DocViewer({
|
|
|
1256
1385
|
geometry,
|
|
1257
1386
|
box: layout.boxes[pageClass(p.index)],
|
|
1258
1387
|
scale,
|
|
1259
|
-
typography,
|
|
1388
|
+
typography: typography2,
|
|
1260
1389
|
ctx,
|
|
1261
1390
|
docPage: page,
|
|
1262
1391
|
docFields,
|
|
@@ -1270,7 +1399,7 @@ function DocViewer({
|
|
|
1270
1399
|
}
|
|
1271
1400
|
);
|
|
1272
1401
|
}
|
|
1273
|
-
function PageView({ page, pages, geometry, box, scale, typography, ctx, docPage, docFields, numbering, blocks, heights }) {
|
|
1402
|
+
function PageView({ page, pages, geometry, box, scale, typography: typography2, ctx, docPage, docFields, numbering, blocks, heights }) {
|
|
1274
1403
|
const n = page.index + 1;
|
|
1275
1404
|
const g = geometry;
|
|
1276
1405
|
const bandCtx = { ...ctx, fields: { ...docFields, page: n, pages, sectionPages: pages } };
|
|
@@ -1290,7 +1419,7 @@ function PageView({ page, pages, geometry, box, scale, typography, ctx, docPage,
|
|
|
1290
1419
|
{
|
|
1291
1420
|
"data-lw-sheet": "",
|
|
1292
1421
|
style: {
|
|
1293
|
-
...
|
|
1422
|
+
...typography2,
|
|
1294
1423
|
position: "relative",
|
|
1295
1424
|
width: pt(g.width),
|
|
1296
1425
|
height: pt(g.height),
|
|
@@ -1396,14 +1525,19 @@ function docFromReader(output) {
|
|
|
1396
1525
|
return value;
|
|
1397
1526
|
}
|
|
1398
1527
|
|
|
1528
|
+
exports.CARLITO_FACES = CARLITO_FACES;
|
|
1529
|
+
exports.CARLITO_FAMILY = CARLITO_FAMILY;
|
|
1399
1530
|
exports.DocViewer = DocViewer;
|
|
1531
|
+
exports.FONT_LOAD_TIMEOUT_MS = FONT_LOAD_TIMEOUT_MS;
|
|
1400
1532
|
exports.PAGE_BAND_DISTANCE_DEFAULT = PAGE_BAND_DISTANCE_DEFAULT;
|
|
1401
1533
|
exports.PAGE_MARGIN_DEFAULT = PAGE_MARGIN_DEFAULT;
|
|
1402
1534
|
exports.PAGE_SIZES_PT = PAGE_SIZES_PT;
|
|
1403
1535
|
exports.PX_PER_PT = PX_PER_PT;
|
|
1404
1536
|
exports.bandSlot = bandSlot;
|
|
1405
1537
|
exports.bodyBox = bodyBox;
|
|
1538
|
+
exports.carlitoFaces = carlitoFaces;
|
|
1406
1539
|
exports.docFromReader = docFromReader;
|
|
1540
|
+
exports.fontFaceCss = fontFaceCss;
|
|
1407
1541
|
exports.formatDatePicture = formatDatePicture;
|
|
1408
1542
|
exports.numberFootnotes = numberFootnotes;
|
|
1409
1543
|
exports.pageBand = pageBand;
|