@particle-academy/last-word-ui 0.1.1 → 0.2.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 +38 -0
- package/README.md +20 -3
- package/dist/index.cjs +795 -563
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +145 -8
- package/dist/index.d.ts +145 -8
- package/dist/index.js +789 -564
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -189,11 +189,32 @@ interface Page {
|
|
|
189
189
|
size?: PageSize;
|
|
190
190
|
orientation?: Orientation;
|
|
191
191
|
margins?: PageMargins;
|
|
192
|
+
/** Every page, unless a variant below covers it. */
|
|
192
193
|
header?: Band | BlocksBand;
|
|
193
194
|
footer?: Band | BlocksBand;
|
|
195
|
+
/**
|
|
196
|
+
* Page 1 only, in place of `header` / `footer` (last-word 0.16.0, Word's
|
|
197
|
+
* "Different first page"). `{"blocks": []}` blanks page 1's band.
|
|
198
|
+
*/
|
|
199
|
+
firstHeader?: Band | BlocksBand;
|
|
200
|
+
firstFooter?: Band | BlocksBand;
|
|
201
|
+
/**
|
|
202
|
+
* Even pages (2, 4, ...), in place of `header` / `footer` (last-word 0.16.0,
|
|
203
|
+
* Word's "Different odd and even pages"). `{"blocks": []}` blanks them.
|
|
204
|
+
*/
|
|
205
|
+
evenHeader?: Band | BlocksBand;
|
|
206
|
+
evenFooter?: Band | BlocksBand;
|
|
207
|
+
}
|
|
208
|
+
/** Document properties (last-word 0.16.0). */
|
|
209
|
+
interface DocMeta {
|
|
210
|
+
/** Word's Author property: what an `{author}` field in a band shows. */
|
|
211
|
+
author?: string;
|
|
212
|
+
[key: string]: unknown;
|
|
194
213
|
}
|
|
195
214
|
interface Doc {
|
|
215
|
+
/** The document title: what a `{title}` field in a band shows. */
|
|
196
216
|
title?: string;
|
|
217
|
+
meta?: DocMeta;
|
|
197
218
|
blocks: Block[];
|
|
198
219
|
page?: Page;
|
|
199
220
|
defaultFont?: string;
|
|
@@ -225,6 +246,17 @@ interface DocViewerProps {
|
|
|
225
246
|
maxScale?: number;
|
|
226
247
|
/** Space between pages, in CSS px. Default 16. */
|
|
227
248
|
gap?: number;
|
|
249
|
+
/**
|
|
250
|
+
* What a `{filename}` field in a header or footer shows. The viewer cannot
|
|
251
|
+
* know the file's name, so it is empty unless given.
|
|
252
|
+
*/
|
|
253
|
+
filename?: string;
|
|
254
|
+
/**
|
|
255
|
+
* The moment `{date}` / `{time}` fields show: a Date or an ISO-8601 string
|
|
256
|
+
* (JSON-friendly). Default: the time of the first render. Pass it for
|
|
257
|
+
* deterministic output (tests, agents, a print preview "as of" a date).
|
|
258
|
+
*/
|
|
259
|
+
now?: Date | string;
|
|
228
260
|
/** Called after every layout with JSON-serializable facts about it. */
|
|
229
261
|
onLayout?: (layout: DocViewerLayout) => void;
|
|
230
262
|
/**
|
|
@@ -244,9 +276,15 @@ interface DocViewerProps {
|
|
|
244
276
|
*
|
|
245
277
|
* Stable handles: the root carries `data-lw-viewer`; each page `data-page`
|
|
246
278
|
* (1-based); each block or fragment of one `data-block` (`b0`, `b1`, ... in
|
|
247
|
-
* document order); each footnote `data-footnote`; bands `data-lw-band
|
|
279
|
+
* document order); each footnote `data-footnote`; bands `data-lw-band`, with
|
|
280
|
+
* `data-lw-band-variant` naming the one drawn (`default`, `first`, `even`).
|
|
281
|
+
*
|
|
282
|
+
* Header and footer text takes field tokens -- `{page}`, `{pages}`,
|
|
283
|
+
* `{section}`, `{sectionpages}`, `{author}`, `{title}`, `{filename}`, `{date}`,
|
|
284
|
+
* `{time}`, `{date:FORMAT}`, `{time:FORMAT}` -- drawn as plain text. In the
|
|
285
|
+
* body they stay literal.
|
|
248
286
|
*/
|
|
249
|
-
declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, onLayout, injectStyles, id, className, style, }: DocViewerProps): react.JSX.Element;
|
|
287
|
+
declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, filename, now, onLayout, injectStyles, id, className, style, }: DocViewerProps): react.JSX.Element;
|
|
250
288
|
|
|
251
289
|
/**
|
|
252
290
|
* A Doc from what a last-word reader returned -- `new DocxReader().read(bytes)`
|
|
@@ -318,8 +356,21 @@ interface BreakItem {
|
|
|
318
356
|
}
|
|
319
357
|
type PackItem = BlockItem | TableItem | BreakItem;
|
|
320
358
|
interface PackOptions {
|
|
321
|
-
/**
|
|
359
|
+
/**
|
|
360
|
+
* The body height available on a page no variant below covers: every page
|
|
361
|
+
* when neither is given, else the odd pages after the first.
|
|
362
|
+
*/
|
|
322
363
|
pageHeight: number;
|
|
364
|
+
/**
|
|
365
|
+
* The body height of page 1, when its header or footer differs from the
|
|
366
|
+
* rest (a first-page letterhead). `pageHeight` when absent.
|
|
367
|
+
*/
|
|
368
|
+
firstPageHeight?: number;
|
|
369
|
+
/**
|
|
370
|
+
* The body height of the even pages (2, 4, ...), when their bands differ.
|
|
371
|
+
* `pageHeight` when absent. Page 1 is odd, so it never takes this.
|
|
372
|
+
*/
|
|
373
|
+
evenPageHeight?: number;
|
|
323
374
|
/**
|
|
324
375
|
* Height of the separator rule above a page's footnotes, reserved once on
|
|
325
376
|
* any page that holds at least one note. 0 when absent.
|
|
@@ -357,7 +408,16 @@ interface PageLayout {
|
|
|
357
408
|
footnotes: number[];
|
|
358
409
|
/** Body height used, footnotes and separator included. */
|
|
359
410
|
used: number;
|
|
411
|
+
/** The body height this page had to fill (`pageCapacity()` for its index). */
|
|
412
|
+
capacity: number;
|
|
360
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* The body height of the page at 0-based `index`: page 1 takes
|
|
416
|
+
* `firstPageHeight`, even pages (odd indices) `evenPageHeight`, the rest
|
|
417
|
+
* `pageHeight`. A variant that is absent, non-finite or not positive falls
|
|
418
|
+
* back to `pageHeight`. At least 1, so a page always makes progress.
|
|
419
|
+
*/
|
|
420
|
+
declare function pageCapacity(options: PackOptions, index: number): number;
|
|
361
421
|
declare function paginate(items: PackItem[], options: PackOptions): PageLayout[];
|
|
362
422
|
|
|
363
423
|
/**
|
|
@@ -421,18 +481,95 @@ declare function pageGeometry(doc: Doc): PageGeometry;
|
|
|
421
481
|
*/
|
|
422
482
|
declare function bodyBox(g: PageGeometry, headerHeight: number, footerHeight: number): BodyBox;
|
|
423
483
|
|
|
424
|
-
/**
|
|
484
|
+
/**
|
|
485
|
+
* Which header and footer each page draws (last-word 0.16.0).
|
|
486
|
+
*
|
|
487
|
+
* `page.header` / `page.footer` are the defaults. Beside them:
|
|
488
|
+
* - `firstHeader` / `firstFooter`: page 1 only (Word's "Different first page");
|
|
489
|
+
* - `evenHeader` / `evenFooter`: pages 2, 4, ... (Word's "Different odd and
|
|
490
|
+
* even pages"), the default then being the odd pages'.
|
|
491
|
+
* A kind with no variant shows its default on those pages too. A variant of
|
|
492
|
+
* `{"blocks": []}` (or a one-line band with no text) is present but empty, so
|
|
493
|
+
* it BLANKS that page's band rather than falling back.
|
|
494
|
+
*
|
|
495
|
+
* So pages fall in three classes -- page 1, even pages, other odd pages --
|
|
496
|
+
* and every page of a class draws the same bands, at the same heights. The
|
|
497
|
+
* packer takes one body height per class (`PackOptions.firstPageHeight` /
|
|
498
|
+
* `evenPageHeight` / `pageHeight`) and `pageBodyBoxes` derives them.
|
|
499
|
+
*/
|
|
500
|
+
type BandKind = "header" | "footer";
|
|
501
|
+
/** Which of a kind's bands applies: the default, the first-page or the even-page one. */
|
|
502
|
+
type BandSlot = "default" | "first" | "even";
|
|
503
|
+
/** Page 1, an even page, or an odd page after the first. */
|
|
504
|
+
type PageClass = "first" | "even" | "odd";
|
|
505
|
+
/** Measured band heights per kind and slot, in any one unit; 0 when absent or blank. */
|
|
506
|
+
type BandHeights = Record<BandKind, Record<BandSlot, number>>;
|
|
507
|
+
/** The class of the page at 0-based `index`. */
|
|
508
|
+
declare function pageClass(index: number): PageClass;
|
|
509
|
+
/** The slot a page class draws for one kind: its variant when that is set, else the default. */
|
|
510
|
+
declare function bandSlot(page: Page | undefined, kind: BandKind, cls: PageClass): BandSlot;
|
|
511
|
+
/**
|
|
512
|
+
* The band the page at 0-based `index` draws for `kind`, or null when it
|
|
513
|
+
* draws none (no band, or a blank variant).
|
|
514
|
+
*/
|
|
515
|
+
declare function pageBand(page: Page | undefined, kind: BandKind, index: number): Band | BlocksBand | null;
|
|
516
|
+
/**
|
|
517
|
+
* The body box of each page class from the measured band heights (points):
|
|
518
|
+
* each class uses the header and footer it actually draws, so a tall
|
|
519
|
+
* first-page letterhead moves only page 1's body down.
|
|
520
|
+
*/
|
|
521
|
+
declare function pageBodyBoxes(g: PageGeometry, page: Page | undefined, heights: BandHeights): Record<PageClass, BodyBox>;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* The live values a header or footer's field tokens take on one page.
|
|
525
|
+
*
|
|
526
|
+
* Only `page` and `pages` are required, so a 0.1.x caller of
|
|
527
|
+
* `substituteFields(text, { page, pages })` is unchanged; every other value
|
|
528
|
+
* has a documented fallback.
|
|
529
|
+
*/
|
|
425
530
|
interface PageFields {
|
|
426
531
|
/** 1-based. */
|
|
427
532
|
page: number;
|
|
428
533
|
pages: number;
|
|
534
|
+
/**
|
|
535
|
+
* `{section}`. A last-word Doc is ONE section, so this is 1 unless a caller
|
|
536
|
+
* says otherwise.
|
|
537
|
+
*/
|
|
538
|
+
section?: number;
|
|
539
|
+
/** `{sectionpages}`. The Doc is one section, so the page total when absent. */
|
|
540
|
+
sectionPages?: number;
|
|
541
|
+
/** `{author}`: `doc.meta.author`. Empty when absent. */
|
|
542
|
+
author?: string;
|
|
543
|
+
/** `{title}`: the top-level `doc.title` (there is deliberately no `meta.title`). Empty when absent. */
|
|
544
|
+
title?: string;
|
|
545
|
+
/** `{filename}`: the viewer cannot know it, so it is a prop. Empty when absent. */
|
|
546
|
+
filename?: string;
|
|
547
|
+
/** `{date}` / `{time}` are "as of" this moment. The current time when absent. */
|
|
548
|
+
now?: Date;
|
|
429
549
|
}
|
|
430
550
|
/**
|
|
431
|
-
* Text with
|
|
432
|
-
*
|
|
433
|
-
*
|
|
551
|
+
* Text with its field tokens replaced by this page's values -- the PAGE,
|
|
552
|
+
* NUMPAGES, SECTION, SECTIONPAGES, AUTHOR, TITLE, FILENAME, DATE and TIME
|
|
553
|
+
* fields last-word writes into a band. Only in bands: in the body the same
|
|
554
|
+
* characters are literal text, as they are in the written file.
|
|
555
|
+
*
|
|
556
|
+
* Returns a plain string; the caller renders it as a React text node, so a
|
|
557
|
+
* value full of markup (an untrusted author) stays text.
|
|
434
558
|
*/
|
|
435
559
|
declare function substituteFields(text: string, fields: PageFields): string;
|
|
560
|
+
/**
|
|
561
|
+
* The `now` prop as a Date: a Date or an ISO-8601 string (JSON-friendly). A
|
|
562
|
+
* missing or unparseable value is the current time.
|
|
563
|
+
*/
|
|
564
|
+
declare function resolveNow(now: Date | string | undefined | null): Date;
|
|
565
|
+
/**
|
|
566
|
+
* A Word date-time picture, formatted in LOCAL time: d dd ddd dddd, M MM MMM
|
|
567
|
+
* MMMM, yy yyyy, h hh (12-hour), H HH (24-hour), m mm, s ss, am/pm, AM/PM.
|
|
568
|
+
* Text in single quotes is literal (an unterminated quote runs to the end);
|
|
569
|
+
* every other character is literal. Names are English, as Word writes them
|
|
570
|
+
* for an English document. Pure string work: no third-party code, no eval.
|
|
571
|
+
*/
|
|
572
|
+
declare function formatDatePicture(date: Date, picture: string): string;
|
|
436
573
|
|
|
437
574
|
interface FootnoteNumbering {
|
|
438
575
|
/** Run object -> its mark number. Keyed by identity, so the Doc must not be cloned between numbering and render. */
|
|
@@ -453,4 +590,4 @@ interface FootnoteNumbering {
|
|
|
453
590
|
*/
|
|
454
591
|
declare function numberFootnotes(doc: Doc): FootnoteNumbering;
|
|
455
592
|
|
|
456
|
-
export { type Align, type Band, 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, 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 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, bodyBox, docFromReader, numberFootnotes, pageGeometry, pageMargins, paginate, substituteFields };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -189,11 +189,32 @@ interface Page {
|
|
|
189
189
|
size?: PageSize;
|
|
190
190
|
orientation?: Orientation;
|
|
191
191
|
margins?: PageMargins;
|
|
192
|
+
/** Every page, unless a variant below covers it. */
|
|
192
193
|
header?: Band | BlocksBand;
|
|
193
194
|
footer?: Band | BlocksBand;
|
|
195
|
+
/**
|
|
196
|
+
* Page 1 only, in place of `header` / `footer` (last-word 0.16.0, Word's
|
|
197
|
+
* "Different first page"). `{"blocks": []}` blanks page 1's band.
|
|
198
|
+
*/
|
|
199
|
+
firstHeader?: Band | BlocksBand;
|
|
200
|
+
firstFooter?: Band | BlocksBand;
|
|
201
|
+
/**
|
|
202
|
+
* Even pages (2, 4, ...), in place of `header` / `footer` (last-word 0.16.0,
|
|
203
|
+
* Word's "Different odd and even pages"). `{"blocks": []}` blanks them.
|
|
204
|
+
*/
|
|
205
|
+
evenHeader?: Band | BlocksBand;
|
|
206
|
+
evenFooter?: Band | BlocksBand;
|
|
207
|
+
}
|
|
208
|
+
/** Document properties (last-word 0.16.0). */
|
|
209
|
+
interface DocMeta {
|
|
210
|
+
/** Word's Author property: what an `{author}` field in a band shows. */
|
|
211
|
+
author?: string;
|
|
212
|
+
[key: string]: unknown;
|
|
194
213
|
}
|
|
195
214
|
interface Doc {
|
|
215
|
+
/** The document title: what a `{title}` field in a band shows. */
|
|
196
216
|
title?: string;
|
|
217
|
+
meta?: DocMeta;
|
|
197
218
|
blocks: Block[];
|
|
198
219
|
page?: Page;
|
|
199
220
|
defaultFont?: string;
|
|
@@ -225,6 +246,17 @@ interface DocViewerProps {
|
|
|
225
246
|
maxScale?: number;
|
|
226
247
|
/** Space between pages, in CSS px. Default 16. */
|
|
227
248
|
gap?: number;
|
|
249
|
+
/**
|
|
250
|
+
* What a `{filename}` field in a header or footer shows. The viewer cannot
|
|
251
|
+
* know the file's name, so it is empty unless given.
|
|
252
|
+
*/
|
|
253
|
+
filename?: string;
|
|
254
|
+
/**
|
|
255
|
+
* The moment `{date}` / `{time}` fields show: a Date or an ISO-8601 string
|
|
256
|
+
* (JSON-friendly). Default: the time of the first render. Pass it for
|
|
257
|
+
* deterministic output (tests, agents, a print preview "as of" a date).
|
|
258
|
+
*/
|
|
259
|
+
now?: Date | string;
|
|
228
260
|
/** Called after every layout with JSON-serializable facts about it. */
|
|
229
261
|
onLayout?: (layout: DocViewerLayout) => void;
|
|
230
262
|
/**
|
|
@@ -244,9 +276,15 @@ interface DocViewerProps {
|
|
|
244
276
|
*
|
|
245
277
|
* Stable handles: the root carries `data-lw-viewer`; each page `data-page`
|
|
246
278
|
* (1-based); each block or fragment of one `data-block` (`b0`, `b1`, ... in
|
|
247
|
-
* document order); each footnote `data-footnote`; bands `data-lw-band
|
|
279
|
+
* document order); each footnote `data-footnote`; bands `data-lw-band`, with
|
|
280
|
+
* `data-lw-band-variant` naming the one drawn (`default`, `first`, `even`).
|
|
281
|
+
*
|
|
282
|
+
* Header and footer text takes field tokens -- `{page}`, `{pages}`,
|
|
283
|
+
* `{section}`, `{sectionpages}`, `{author}`, `{title}`, `{filename}`, `{date}`,
|
|
284
|
+
* `{time}`, `{date:FORMAT}`, `{time:FORMAT}` -- drawn as plain text. In the
|
|
285
|
+
* body they stay literal.
|
|
248
286
|
*/
|
|
249
|
-
declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, onLayout, injectStyles, id, className, style, }: DocViewerProps): react.JSX.Element;
|
|
287
|
+
declare function DocViewer({ doc, fit, scale: fixedScale, maxScale, gap, filename, now, onLayout, injectStyles, id, className, style, }: DocViewerProps): react.JSX.Element;
|
|
250
288
|
|
|
251
289
|
/**
|
|
252
290
|
* A Doc from what a last-word reader returned -- `new DocxReader().read(bytes)`
|
|
@@ -318,8 +356,21 @@ interface BreakItem {
|
|
|
318
356
|
}
|
|
319
357
|
type PackItem = BlockItem | TableItem | BreakItem;
|
|
320
358
|
interface PackOptions {
|
|
321
|
-
/**
|
|
359
|
+
/**
|
|
360
|
+
* The body height available on a page no variant below covers: every page
|
|
361
|
+
* when neither is given, else the odd pages after the first.
|
|
362
|
+
*/
|
|
322
363
|
pageHeight: number;
|
|
364
|
+
/**
|
|
365
|
+
* The body height of page 1, when its header or footer differs from the
|
|
366
|
+
* rest (a first-page letterhead). `pageHeight` when absent.
|
|
367
|
+
*/
|
|
368
|
+
firstPageHeight?: number;
|
|
369
|
+
/**
|
|
370
|
+
* The body height of the even pages (2, 4, ...), when their bands differ.
|
|
371
|
+
* `pageHeight` when absent. Page 1 is odd, so it never takes this.
|
|
372
|
+
*/
|
|
373
|
+
evenPageHeight?: number;
|
|
323
374
|
/**
|
|
324
375
|
* Height of the separator rule above a page's footnotes, reserved once on
|
|
325
376
|
* any page that holds at least one note. 0 when absent.
|
|
@@ -357,7 +408,16 @@ interface PageLayout {
|
|
|
357
408
|
footnotes: number[];
|
|
358
409
|
/** Body height used, footnotes and separator included. */
|
|
359
410
|
used: number;
|
|
411
|
+
/** The body height this page had to fill (`pageCapacity()` for its index). */
|
|
412
|
+
capacity: number;
|
|
360
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* The body height of the page at 0-based `index`: page 1 takes
|
|
416
|
+
* `firstPageHeight`, even pages (odd indices) `evenPageHeight`, the rest
|
|
417
|
+
* `pageHeight`. A variant that is absent, non-finite or not positive falls
|
|
418
|
+
* back to `pageHeight`. At least 1, so a page always makes progress.
|
|
419
|
+
*/
|
|
420
|
+
declare function pageCapacity(options: PackOptions, index: number): number;
|
|
361
421
|
declare function paginate(items: PackItem[], options: PackOptions): PageLayout[];
|
|
362
422
|
|
|
363
423
|
/**
|
|
@@ -421,18 +481,95 @@ declare function pageGeometry(doc: Doc): PageGeometry;
|
|
|
421
481
|
*/
|
|
422
482
|
declare function bodyBox(g: PageGeometry, headerHeight: number, footerHeight: number): BodyBox;
|
|
423
483
|
|
|
424
|
-
/**
|
|
484
|
+
/**
|
|
485
|
+
* Which header and footer each page draws (last-word 0.16.0).
|
|
486
|
+
*
|
|
487
|
+
* `page.header` / `page.footer` are the defaults. Beside them:
|
|
488
|
+
* - `firstHeader` / `firstFooter`: page 1 only (Word's "Different first page");
|
|
489
|
+
* - `evenHeader` / `evenFooter`: pages 2, 4, ... (Word's "Different odd and
|
|
490
|
+
* even pages"), the default then being the odd pages'.
|
|
491
|
+
* A kind with no variant shows its default on those pages too. A variant of
|
|
492
|
+
* `{"blocks": []}` (or a one-line band with no text) is present but empty, so
|
|
493
|
+
* it BLANKS that page's band rather than falling back.
|
|
494
|
+
*
|
|
495
|
+
* So pages fall in three classes -- page 1, even pages, other odd pages --
|
|
496
|
+
* and every page of a class draws the same bands, at the same heights. The
|
|
497
|
+
* packer takes one body height per class (`PackOptions.firstPageHeight` /
|
|
498
|
+
* `evenPageHeight` / `pageHeight`) and `pageBodyBoxes` derives them.
|
|
499
|
+
*/
|
|
500
|
+
type BandKind = "header" | "footer";
|
|
501
|
+
/** Which of a kind's bands applies: the default, the first-page or the even-page one. */
|
|
502
|
+
type BandSlot = "default" | "first" | "even";
|
|
503
|
+
/** Page 1, an even page, or an odd page after the first. */
|
|
504
|
+
type PageClass = "first" | "even" | "odd";
|
|
505
|
+
/** Measured band heights per kind and slot, in any one unit; 0 when absent or blank. */
|
|
506
|
+
type BandHeights = Record<BandKind, Record<BandSlot, number>>;
|
|
507
|
+
/** The class of the page at 0-based `index`. */
|
|
508
|
+
declare function pageClass(index: number): PageClass;
|
|
509
|
+
/** The slot a page class draws for one kind: its variant when that is set, else the default. */
|
|
510
|
+
declare function bandSlot(page: Page | undefined, kind: BandKind, cls: PageClass): BandSlot;
|
|
511
|
+
/**
|
|
512
|
+
* The band the page at 0-based `index` draws for `kind`, or null when it
|
|
513
|
+
* draws none (no band, or a blank variant).
|
|
514
|
+
*/
|
|
515
|
+
declare function pageBand(page: Page | undefined, kind: BandKind, index: number): Band | BlocksBand | null;
|
|
516
|
+
/**
|
|
517
|
+
* The body box of each page class from the measured band heights (points):
|
|
518
|
+
* each class uses the header and footer it actually draws, so a tall
|
|
519
|
+
* first-page letterhead moves only page 1's body down.
|
|
520
|
+
*/
|
|
521
|
+
declare function pageBodyBoxes(g: PageGeometry, page: Page | undefined, heights: BandHeights): Record<PageClass, BodyBox>;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* The live values a header or footer's field tokens take on one page.
|
|
525
|
+
*
|
|
526
|
+
* Only `page` and `pages` are required, so a 0.1.x caller of
|
|
527
|
+
* `substituteFields(text, { page, pages })` is unchanged; every other value
|
|
528
|
+
* has a documented fallback.
|
|
529
|
+
*/
|
|
425
530
|
interface PageFields {
|
|
426
531
|
/** 1-based. */
|
|
427
532
|
page: number;
|
|
428
533
|
pages: number;
|
|
534
|
+
/**
|
|
535
|
+
* `{section}`. A last-word Doc is ONE section, so this is 1 unless a caller
|
|
536
|
+
* says otherwise.
|
|
537
|
+
*/
|
|
538
|
+
section?: number;
|
|
539
|
+
/** `{sectionpages}`. The Doc is one section, so the page total when absent. */
|
|
540
|
+
sectionPages?: number;
|
|
541
|
+
/** `{author}`: `doc.meta.author`. Empty when absent. */
|
|
542
|
+
author?: string;
|
|
543
|
+
/** `{title}`: the top-level `doc.title` (there is deliberately no `meta.title`). Empty when absent. */
|
|
544
|
+
title?: string;
|
|
545
|
+
/** `{filename}`: the viewer cannot know it, so it is a prop. Empty when absent. */
|
|
546
|
+
filename?: string;
|
|
547
|
+
/** `{date}` / `{time}` are "as of" this moment. The current time when absent. */
|
|
548
|
+
now?: Date;
|
|
429
549
|
}
|
|
430
550
|
/**
|
|
431
|
-
* Text with
|
|
432
|
-
*
|
|
433
|
-
*
|
|
551
|
+
* Text with its field tokens replaced by this page's values -- the PAGE,
|
|
552
|
+
* NUMPAGES, SECTION, SECTIONPAGES, AUTHOR, TITLE, FILENAME, DATE and TIME
|
|
553
|
+
* fields last-word writes into a band. Only in bands: in the body the same
|
|
554
|
+
* characters are literal text, as they are in the written file.
|
|
555
|
+
*
|
|
556
|
+
* Returns a plain string; the caller renders it as a React text node, so a
|
|
557
|
+
* value full of markup (an untrusted author) stays text.
|
|
434
558
|
*/
|
|
435
559
|
declare function substituteFields(text: string, fields: PageFields): string;
|
|
560
|
+
/**
|
|
561
|
+
* The `now` prop as a Date: a Date or an ISO-8601 string (JSON-friendly). A
|
|
562
|
+
* missing or unparseable value is the current time.
|
|
563
|
+
*/
|
|
564
|
+
declare function resolveNow(now: Date | string | undefined | null): Date;
|
|
565
|
+
/**
|
|
566
|
+
* A Word date-time picture, formatted in LOCAL time: d dd ddd dddd, M MM MMM
|
|
567
|
+
* MMMM, yy yyyy, h hh (12-hour), H HH (24-hour), m mm, s ss, am/pm, AM/PM.
|
|
568
|
+
* Text in single quotes is literal (an unterminated quote runs to the end);
|
|
569
|
+
* every other character is literal. Names are English, as Word writes them
|
|
570
|
+
* for an English document. Pure string work: no third-party code, no eval.
|
|
571
|
+
*/
|
|
572
|
+
declare function formatDatePicture(date: Date, picture: string): string;
|
|
436
573
|
|
|
437
574
|
interface FootnoteNumbering {
|
|
438
575
|
/** Run object -> its mark number. Keyed by identity, so the Doc must not be cloned between numbering and render. */
|
|
@@ -453,4 +590,4 @@ interface FootnoteNumbering {
|
|
|
453
590
|
*/
|
|
454
591
|
declare function numberFootnotes(doc: Doc): FootnoteNumbering;
|
|
455
592
|
|
|
456
|
-
export { type Align, type Band, 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, 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 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, bodyBox, docFromReader, numberFootnotes, pageGeometry, pageMargins, paginate, substituteFields };
|
|
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 };
|