@evotecit/officeimo 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +1219 -2
- package/bundles/officeimo-canopyx.js +11286 -0
- package/bundles/officeimo-canopyx.mjs +11185 -0
- package/bundles/officeimo-csv.js +1254 -0
- package/bundles/officeimo-csv.mjs +1229 -0
- package/bundles/officeimo-datatables.js +11572 -0
- package/bundles/officeimo-datatables.mjs +11470 -0
- package/bundles/officeimo-execution.js +1503 -0
- package/bundles/officeimo-execution.mjs +1479 -0
- package/bundles/officeimo-pdf.js +6564 -0
- package/bundles/officeimo-pdf.mjs +6502 -0
- package/bundles/officeimo-xlsx.js +5333 -0
- package/bundles/officeimo-xlsx.mjs +5279 -0
- package/bundles/officeimo.js +11022 -0
- package/bundles/officeimo.mjs +10924 -0
- package/dist/core/dates.d.ts +1 -0
- package/dist/core/dates.js +16 -0
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/errors.js +31 -0
- package/dist/core/grouped-report.d.ts +87 -0
- package/dist/core/grouped-report.js +252 -0
- package/dist/core/index.d.ts +72 -0
- package/dist/core/index.js +37 -0
- package/dist/core/iteration.d.ts +7 -0
- package/dist/core/iteration.js +149 -0
- package/dist/core/limits.d.ts +7 -0
- package/dist/core/limits.js +56 -0
- package/dist/core/links.d.ts +5 -0
- package/dist/core/links.js +14 -0
- package/dist/core/presentation.d.ts +29 -0
- package/dist/core/presentation.js +59 -0
- package/dist/core/progress.d.ts +1 -0
- package/dist/core/progress.js +10 -0
- package/dist/core/sinks.d.ts +33 -0
- package/dist/core/sinks.js +101 -0
- package/dist/core/table.d.ts +8 -0
- package/dist/core/table.js +1 -0
- package/dist/core/value-text.d.ts +7 -0
- package/dist/core/value-text.js +13 -0
- package/dist/csv/index.d.ts +44 -0
- package/dist/csv/index.js +133 -0
- package/dist/csv/options.d.ts +1 -0
- package/dist/csv/options.js +8 -0
- package/dist/csv/structured-rows.d.ts +3 -0
- package/dist/csv/structured-rows.js +15 -0
- package/dist/execution/host.d.ts +5 -0
- package/dist/execution/host.js +164 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/protocol.d.ts +48 -0
- package/dist/execution/protocol.js +173 -0
- package/dist/execution/types.d.ts +42 -0
- package/dist/execution/types.js +1 -0
- package/dist/execution/worker.d.ts +3 -0
- package/dist/execution/worker.js +147 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -0
- package/dist/integrations/canopyx/dates.d.ts +1 -0
- package/dist/integrations/canopyx/dates.js +34 -0
- package/dist/integrations/canopyx/index.d.ts +10 -0
- package/dist/integrations/canopyx/index.js +45 -0
- package/dist/integrations/canopyx/source.d.ts +3 -0
- package/dist/integrations/canopyx/source.js +116 -0
- package/dist/integrations/canopyx/types.d.ts +83 -0
- package/dist/integrations/canopyx/types.js +1 -0
- package/dist/integrations/datatables/api.d.ts +1 -0
- package/dist/integrations/datatables/api.js +27 -0
- package/dist/integrations/datatables/headings.d.ts +1 -0
- package/dist/integrations/datatables/headings.js +65 -0
- package/dist/integrations/datatables/index.d.ts +12 -0
- package/dist/integrations/datatables/index.js +167 -0
- package/dist/integrations/datatables/snapshot.d.ts +3 -0
- package/dist/integrations/datatables/snapshot.js +206 -0
- package/dist/integrations/datatables/types.d.ts +98 -0
- package/dist/integrations/datatables/types.js +1 -0
- package/dist/integrations/options.d.ts +13 -0
- package/dist/integrations/options.js +34 -0
- package/dist/internal/capture.d.ts +4 -0
- package/dist/internal/capture.js +14 -0
- package/dist/internal/columns.d.ts +27 -0
- package/dist/internal/columns.js +1 -0
- package/dist/internal/crc32.d.ts +6 -0
- package/dist/internal/crc32.js +17 -0
- package/dist/internal/export-values.d.ts +3 -0
- package/dist/internal/export-values.js +14 -0
- package/dist/internal/rows.d.ts +6 -0
- package/dist/internal/rows.js +68 -0
- package/dist/internal/table-spans.d.ts +11 -0
- package/dist/internal/table-spans.js +58 -0
- package/dist/internal/totals.d.ts +15 -0
- package/dist/internal/totals.js +42 -0
- package/dist/opc/index.d.ts +67 -0
- package/dist/opc/index.js +233 -0
- package/dist/opc/properties.d.ts +15 -0
- package/dist/opc/properties.js +18 -0
- package/dist/opc/uri.d.ts +5 -0
- package/dist/opc/uri.js +41 -0
- package/dist/pdf/annotations.d.ts +1 -0
- package/dist/pdf/annotations.js +38 -0
- package/dist/pdf/binary.d.ts +6 -0
- package/dist/pdf/binary.js +24 -0
- package/dist/pdf/document-drawings.d.ts +15 -0
- package/dist/pdf/document-drawings.js +237 -0
- package/dist/pdf/document-grouped.d.ts +1 -0
- package/dist/pdf/document-grouped.js +194 -0
- package/dist/pdf/document-images.d.ts +19 -0
- package/dist/pdf/document-images.js +125 -0
- package/dist/pdf/document-types.d.ts +160 -0
- package/dist/pdf/document-types.js +1 -0
- package/dist/pdf/document-vectors.d.ts +11 -0
- package/dist/pdf/document-vectors.js +77 -0
- package/dist/pdf/document.d.ts +9 -0
- package/dist/pdf/document.js +270 -0
- package/dist/pdf/drawing-types.d.ts +53 -0
- package/dist/pdf/drawing-types.js +1 -0
- package/dist/pdf/font-resources.d.ts +43 -0
- package/dist/pdf/font-resources.js +201 -0
- package/dist/pdf/font-support.d.ts +1 -0
- package/dist/pdf/font-support.js +60 -0
- package/dist/pdf/font.d.ts +17 -0
- package/dist/pdf/font.js +56 -0
- package/dist/pdf/grouped-table.d.ts +6 -0
- package/dist/pdf/grouped-table.js +40 -0
- package/dist/pdf/grouped-types.d.ts +34 -0
- package/dist/pdf/grouped-types.js +1 -0
- package/dist/pdf/grouped.d.ts +10 -0
- package/dist/pdf/grouped.js +37 -0
- package/dist/pdf/index.d.ts +22 -0
- package/dist/pdf/index.js +8 -0
- package/dist/pdf/inline-text.d.ts +30 -0
- package/dist/pdf/inline-text.js +142 -0
- package/dist/pdf/inline-types.d.ts +15 -0
- package/dist/pdf/inline-types.js +1 -0
- package/dist/pdf/list-layout.d.ts +6 -0
- package/dist/pdf/list-layout.js +49 -0
- package/dist/pdf/objects.d.ts +2 -0
- package/dist/pdf/objects.js +143 -0
- package/dist/pdf/outlines.d.ts +1 -0
- package/dist/pdf/outlines.js +55 -0
- package/dist/pdf/page-context.d.ts +1 -0
- package/dist/pdf/page-context.js +12 -0
- package/dist/pdf/pages.d.ts +1 -0
- package/dist/pdf/pages.js +679 -0
- package/dist/pdf/paragraph-layout.d.ts +19 -0
- package/dist/pdf/paragraph-layout.js +66 -0
- package/dist/pdf/paragraph-styles.d.ts +1 -0
- package/dist/pdf/paragraph-styles.js +66 -0
- package/dist/pdf/png.d.ts +9 -0
- package/dist/pdf/png.js +259 -0
- package/dist/pdf/preflight.d.ts +7 -0
- package/dist/pdf/preflight.js +32 -0
- package/dist/pdf/presentation-settings.d.ts +5 -0
- package/dist/pdf/presentation-settings.js +28 -0
- package/dist/pdf/providers/harfbuzz.d.ts +60 -0
- package/dist/pdf/providers/harfbuzz.js +112 -0
- package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
- package/dist/pdf/providers/unicode13-profile.js +115 -0
- package/dist/pdf/section-types.d.ts +15 -0
- package/dist/pdf/section-types.js +40 -0
- package/dist/pdf/session.d.ts +25 -0
- package/dist/pdf/session.js +55 -0
- package/dist/pdf/settings.d.ts +15 -0
- package/dist/pdf/settings.js +171 -0
- package/dist/pdf/shaped-text.d.ts +5 -0
- package/dist/pdf/shaped-text.js +205 -0
- package/dist/pdf/standard-widths.d.ts +1 -0
- package/dist/pdf/standard-widths.js +317 -0
- package/dist/pdf/structure-parent-tree.d.ts +1 -0
- package/dist/pdf/structure-parent-tree.js +57 -0
- package/dist/pdf/structure.d.ts +6 -0
- package/dist/pdf/structure.js +250 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +114 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +85 -0
- package/dist/pdf/table-layout.d.ts +71 -0
- package/dist/pdf/table-layout.js +205 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +92 -0
- package/dist/pdf/text-shaping-types.d.ts +39 -0
- package/dist/pdf/text-shaping-types.js +1 -0
- package/dist/pdf/text.d.ts +13 -0
- package/dist/pdf/text.js +96 -0
- package/dist/pdf/truetype-subset.d.ts +5 -0
- package/dist/pdf/truetype-subset.js +217 -0
- package/dist/pdf/truetype.d.ts +1 -0
- package/dist/pdf/truetype.js +235 -0
- package/dist/pdf/types.d.ts +169 -0
- package/dist/pdf/types.js +1 -0
- package/dist/pdf/write.d.ts +6 -0
- package/dist/pdf/write.js +57 -0
- package/dist/xlsx/attachments.d.ts +30 -0
- package/dist/xlsx/attachments.js +67 -0
- package/dist/xlsx/chart-bindings.d.ts +1 -0
- package/dist/xlsx/chart-bindings.js +122 -0
- package/dist/xlsx/chart-types.d.ts +73 -0
- package/dist/xlsx/chart-types.js +1 -0
- package/dist/xlsx/chart-xml.d.ts +2 -0
- package/dist/xlsx/chart-xml.js +103 -0
- package/dist/xlsx/charts.d.ts +1 -0
- package/dist/xlsx/charts.js +159 -0
- package/dist/xlsx/conditional-formatting.d.ts +1 -0
- package/dist/xlsx/conditional-formatting.js +158 -0
- package/dist/xlsx/conditional-types.d.ts +64 -0
- package/dist/xlsx/conditional-types.js +1 -0
- package/dist/xlsx/data-row-ranges.d.ts +5 -0
- package/dist/xlsx/data-row-ranges.js +39 -0
- package/dist/xlsx/differential-styles.d.ts +1 -0
- package/dist/xlsx/differential-styles.js +102 -0
- package/dist/xlsx/formula.d.ts +8 -0
- package/dist/xlsx/formula.js +104 -0
- package/dist/xlsx/grouped-layout.d.ts +61 -0
- package/dist/xlsx/grouped-layout.js +79 -0
- package/dist/xlsx/grouped.d.ts +16 -0
- package/dist/xlsx/grouped.js +161 -0
- package/dist/xlsx/index.d.ts +24 -0
- package/dist/xlsx/index.js +10 -0
- package/dist/xlsx/layout.d.ts +1 -0
- package/dist/xlsx/layout.js +186 -0
- package/dist/xlsx/options.d.ts +1 -0
- package/dist/xlsx/options.js +16 -0
- package/dist/xlsx/portable.d.ts +27 -0
- package/dist/xlsx/portable.js +44 -0
- package/dist/xlsx/preservation.d.ts +1 -0
- package/dist/xlsx/preservation.js +60 -0
- package/dist/xlsx/ranges.d.ts +1 -0
- package/dist/xlsx/ranges.js +24 -0
- package/dist/xlsx/regions.d.ts +1 -0
- package/dist/xlsx/regions.js +97 -0
- package/dist/xlsx/structured-rows.d.ts +11 -0
- package/dist/xlsx/structured-rows.js +28 -0
- package/dist/xlsx/style-xml.d.ts +1 -0
- package/dist/xlsx/style-xml.js +6 -0
- package/dist/xlsx/styles.d.ts +70 -0
- package/dist/xlsx/styles.js +203 -0
- package/dist/xlsx/table.d.ts +12 -0
- package/dist/xlsx/table.js +35 -0
- package/dist/xlsx/types.d.ts +180 -0
- package/dist/xlsx/types.js +1 -0
- package/dist/xlsx/validation-types.d.ts +18 -0
- package/dist/xlsx/validation-types.js +1 -0
- package/dist/xlsx/validation.d.ts +1 -0
- package/dist/xlsx/validation.js +92 -0
- package/dist/xlsx/values.d.ts +13 -0
- package/dist/xlsx/values.js +86 -0
- package/dist/xlsx/workbook.d.ts +50 -0
- package/dist/xlsx/workbook.js +452 -0
- package/dist/xlsx/worksheet.d.ts +71 -0
- package/dist/xlsx/worksheet.js +700 -0
- package/dist/xlsx/write.d.ts +15 -0
- package/dist/xlsx/write.js +47 -0
- package/dist/xml/index.d.ts +24 -0
- package/dist/xml/index.js +74 -0
- package/dist/zip/entry.d.ts +39 -0
- package/dist/zip/entry.js +122 -0
- package/dist/zip/index.d.ts +44 -0
- package/dist/zip/index.js +248 -0
- package/package.json +104 -4
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { CellPresentation } from "../core/index.js";
|
|
2
|
+
import type { PdfOptions } from "./types.js";
|
|
3
|
+
import type { PdfDrawingBlock } from "./drawing-types.js";
|
|
4
|
+
import type { PdfText } from "./inline-types.js";
|
|
5
|
+
import type { PdfBookmark, PdfSectionBlock } from "./section-types.js";
|
|
6
|
+
import type { GroupedReportSource } from "../core/grouped-report.js";
|
|
7
|
+
import type { GroupedPdfTableOptions } from "./grouped-types.js";
|
|
8
|
+
/** Page geometry, fonts, decorations and resource policy shared by every document block. */
|
|
9
|
+
export interface PdfDocumentOptions extends Omit<PdfOptions<never>, "columns" | "includeHeader" | "headerRows" | "footer" | "headerPresentation" | "footerPresentation" | "alternateRowColor" | "columnWidths" | "wideTable" | "formatValue" | "formatRuns"> {
|
|
10
|
+
/** Named paragraph appearance and keep rules, copied before the block source is consumed. No style inheritance. */
|
|
11
|
+
readonly paragraphStyles?: Readonly<Record<string, PdfParagraphStyle>>;
|
|
12
|
+
}
|
|
13
|
+
/** A table's own columns, repeated headings, presentation and numeric totals. */
|
|
14
|
+
export type PdfTableOptions<T = never> = Pick<PdfOptions<T>, "columns" | "includeHeader" | "headerRows" | "footer" | "headerPresentation" | "footerPresentation" | "alternateRowColor" | "columnWidths" | "wideTable" | "formatValue" | "formatRuns">;
|
|
15
|
+
/** Construct through pdfTable so column keys and getters are checked against the row type. */
|
|
16
|
+
export interface PdfTableBlock {
|
|
17
|
+
readonly kind: "table";
|
|
18
|
+
readonly rows: Iterable<object> | AsyncIterable<object>;
|
|
19
|
+
readonly options: PdfTableOptions;
|
|
20
|
+
/** Visible caption before the table, kept with its first heading/data fragment. */
|
|
21
|
+
readonly caption?: PdfCaption;
|
|
22
|
+
/** Repeated visual context before continuation headings; an artifact in tagged output. */
|
|
23
|
+
readonly continuationCaption?: PdfCaption;
|
|
24
|
+
}
|
|
25
|
+
/** A single-use analytical source with repeated ancestor context and source-owned numeric aggregates.
|
|
26
|
+
* Construct through pdfGroupedTable to capture its options. Tagged output preserves the group hierarchy. */
|
|
27
|
+
export interface PdfGroupedTableBlock {
|
|
28
|
+
readonly kind: "groupedTable";
|
|
29
|
+
readonly report: GroupedReportSource;
|
|
30
|
+
readonly options: GroupedPdfTableOptions;
|
|
31
|
+
}
|
|
32
|
+
/** Reusable paragraph appearance, spacing and keep rules. Semantic roles remain on their content blocks. */
|
|
33
|
+
export interface PdfParagraphStyle {
|
|
34
|
+
readonly fontSize?: number;
|
|
35
|
+
readonly presentation?: Omit<Pick<CellPresentation, "bold" | "italic" | "color" | "alignment">, "alignment"> & {
|
|
36
|
+
readonly alignment?: "left" | "center" | "right";
|
|
37
|
+
};
|
|
38
|
+
/** Move this paragraph intact; reject when its complete layout exceeds a fresh page. */
|
|
39
|
+
readonly keepTogether?: boolean;
|
|
40
|
+
/** Keep this paragraph with the next paragraph line, table heading/data fragment or complete graphic. */
|
|
41
|
+
readonly keepWithNext?: boolean;
|
|
42
|
+
/** Space in points, before this paragraph; default zero. */
|
|
43
|
+
readonly spaceBefore?: number;
|
|
44
|
+
/** Space in points, after this paragraph; default eight. */
|
|
45
|
+
readonly spaceAfter?: number;
|
|
46
|
+
}
|
|
47
|
+
/** Flowing text and inline emphasis/links, using the document's fonts and supported-script contract. */
|
|
48
|
+
export interface PdfParagraphBlock extends PdfParagraphStyle {
|
|
49
|
+
readonly kind: "paragraph";
|
|
50
|
+
readonly text: PdfText;
|
|
51
|
+
/** Name from paragraphStyles. Explicit fields override it; presentation merges member by member. */
|
|
52
|
+
readonly style?: string;
|
|
53
|
+
/** Heading level in tagged output; omitted text is a paragraph. Appearance uses presentation. */
|
|
54
|
+
readonly headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
55
|
+
/** Native navigation destination at this paragraph's actual first painted line. */
|
|
56
|
+
readonly bookmark?: PdfBookmark;
|
|
57
|
+
}
|
|
58
|
+
/** Visible label kept before its table or figure; numbering is authored as part of text. */
|
|
59
|
+
export interface PdfCaption extends Omit<PdfParagraphStyle, "keepTogether" | "keepWithNext"> {
|
|
60
|
+
readonly text: PdfText;
|
|
61
|
+
readonly style?: string;
|
|
62
|
+
}
|
|
63
|
+
/** One rich paragraph body. Explicit line breaks may separate a finding's title, message and scope. */
|
|
64
|
+
export interface PdfListItem {
|
|
65
|
+
readonly text: PdfText;
|
|
66
|
+
readonly style?: string;
|
|
67
|
+
/** Move this whole item intact; reject when it exceeds a fresh page. */
|
|
68
|
+
readonly keepTogether?: boolean;
|
|
69
|
+
}
|
|
70
|
+
/** A streamed semantic list, with hanging body text and one marker per item. Nested blocks are unsupported. */
|
|
71
|
+
export interface PdfListBlock {
|
|
72
|
+
readonly kind: "list";
|
|
73
|
+
readonly items: Iterable<PdfListItem> | AsyncIterable<PdfListItem>;
|
|
74
|
+
/** Decimal numbering when true; otherwise a bullet. Default false. */
|
|
75
|
+
readonly ordered?: boolean;
|
|
76
|
+
/** First positive safe-integer number; valid only for ordered lists. Default one. */
|
|
77
|
+
readonly start?: number;
|
|
78
|
+
/** Default paragraph style for items; an item's style replaces this name. keepWithNext is unsupported. */
|
|
79
|
+
readonly itemStyle?: string;
|
|
80
|
+
/** Body offset in points; default reserves at least two ems and enough room for the marker and gap. */
|
|
81
|
+
readonly indent?: number;
|
|
82
|
+
/** Gap between marker and body in points; default half an em. */
|
|
83
|
+
readonly markerGap?: number;
|
|
84
|
+
}
|
|
85
|
+
/** An explicitly bounded group of paragraphs. Keeps stay within the group; other block kinds and nested groups are rejected. */
|
|
86
|
+
export interface PdfGroupBlock {
|
|
87
|
+
readonly kind: "group";
|
|
88
|
+
readonly blocks: readonly PdfParagraphBlock[];
|
|
89
|
+
/** Keep the complete paragraph group on one page; reject an oversized group. Default true. */
|
|
90
|
+
readonly keepTogether?: boolean;
|
|
91
|
+
}
|
|
92
|
+
/** Explicitly finish the current page; the next block starts on a new page. */
|
|
93
|
+
export interface PdfPageBreakBlock {
|
|
94
|
+
readonly kind: "pageBreak";
|
|
95
|
+
}
|
|
96
|
+
/** Already-decoded row-major 8-bit pixels, with no row padding or premultiplied alpha. */
|
|
97
|
+
export interface PdfRawImage {
|
|
98
|
+
readonly format: "rgb" | "rgba";
|
|
99
|
+
readonly width: number;
|
|
100
|
+
readonly height: number;
|
|
101
|
+
readonly data: Uint8Array;
|
|
102
|
+
}
|
|
103
|
+
/** An 8-bit grayscale/RGB JPEG. CMYK, ICC-profiled and nonstandard component layouts are rejected. */
|
|
104
|
+
export interface PdfJpegImage {
|
|
105
|
+
readonly format: "jpeg";
|
|
106
|
+
readonly data: Uint8Array;
|
|
107
|
+
}
|
|
108
|
+
/** A complete static unprofiled, noninterlaced 8-bit RGB/RGBA PNG, decoded with native DecompressionStream. */
|
|
109
|
+
export interface PdfPngImage {
|
|
110
|
+
readonly format: "png";
|
|
111
|
+
readonly data: Uint8Array;
|
|
112
|
+
}
|
|
113
|
+
/** An indivisible image. Oversized display dimensions scale down to the printable page. */
|
|
114
|
+
export interface PdfImageBlock {
|
|
115
|
+
readonly kind: "image";
|
|
116
|
+
readonly image: PdfRawImage | PdfJpegImage | PdfPngImage;
|
|
117
|
+
/** Display lengths in PDF points; omitted dimensions retain the intrinsic aspect ratio at 96 DPI. */
|
|
118
|
+
readonly width?: number;
|
|
119
|
+
readonly height?: number;
|
|
120
|
+
readonly alignment?: "left" | "center" | "right";
|
|
121
|
+
/** Required for meaningful figures in tagged output; cannot accompany decorative:true. */
|
|
122
|
+
readonly alternativeText?: string;
|
|
123
|
+
/** Explicitly exclude a purely decorative graphic from the logical reading order. */
|
|
124
|
+
readonly decorative?: boolean;
|
|
125
|
+
/** Visible caption before the complete image; distinct from alternativeText. */
|
|
126
|
+
readonly caption?: PdfCaption;
|
|
127
|
+
}
|
|
128
|
+
/** Coordinates use points from the vector block's top-left corner. */
|
|
129
|
+
export type PdfPathCommand = {
|
|
130
|
+
readonly op: "move" | "line";
|
|
131
|
+
readonly x: number;
|
|
132
|
+
readonly y: number;
|
|
133
|
+
} | {
|
|
134
|
+
readonly op: "cubic";
|
|
135
|
+
readonly x1: number;
|
|
136
|
+
readonly y1: number;
|
|
137
|
+
readonly x2: number;
|
|
138
|
+
readonly y2: number;
|
|
139
|
+
readonly x: number;
|
|
140
|
+
readonly y: number;
|
|
141
|
+
} | {
|
|
142
|
+
readonly op: "close";
|
|
143
|
+
};
|
|
144
|
+
/** A bounded path, painted once. No SVG, CSS, gradients, text or external resources are interpreted. */
|
|
145
|
+
export interface PdfVectorBlock {
|
|
146
|
+
readonly kind: "vector";
|
|
147
|
+
readonly width: number;
|
|
148
|
+
readonly height: number;
|
|
149
|
+
readonly commands: readonly PdfPathCommand[];
|
|
150
|
+
readonly fill?: string;
|
|
151
|
+
readonly stroke?: string;
|
|
152
|
+
readonly strokeWidth?: number;
|
|
153
|
+
readonly fillRule?: "nonzero" | "evenodd";
|
|
154
|
+
readonly alignment?: "left" | "center" | "right";
|
|
155
|
+
readonly alternativeText?: string;
|
|
156
|
+
readonly decorative?: boolean;
|
|
157
|
+
readonly caption?: PdfCaption;
|
|
158
|
+
}
|
|
159
|
+
/** Blocks are consumed once in order; each table owns its row source until that table completes. */
|
|
160
|
+
export type PdfDocumentBlock = PdfParagraphBlock | PdfGroupBlock | PdfTableBlock | PdfGroupedTableBlock | PdfPageBreakBlock | PdfImageBlock | PdfVectorBlock | PdfDrawingBlock | PdfListBlock | PdfSectionBlock;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PdfVectorBlock } from "./document-types.js";
|
|
2
|
+
import type { PdfSettings } from "./settings.js";
|
|
3
|
+
interface PreparedVector {
|
|
4
|
+
readonly width: number;
|
|
5
|
+
readonly height: number;
|
|
6
|
+
readonly count: number;
|
|
7
|
+
readonly content: string;
|
|
8
|
+
}
|
|
9
|
+
/** Capture and serialize one bounded display path, with no markup parser or resource loading. */
|
|
10
|
+
export declare function vectorCommands(block: PdfVectorBlock, settings: PdfSettings, used: number): Promise<PreparedVector>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { checkAbort, pause, taskYieldDue } from "../core/iteration.js";
|
|
3
|
+
import { color, positive } from "./settings.js";
|
|
4
|
+
import { pdfNumber as n } from "./objects.js";
|
|
5
|
+
/** Capture and serialize one bounded display path, with no markup parser or resource loading. */
|
|
6
|
+
export async function vectorCommands(block, settings, used) {
|
|
7
|
+
const width = positive(block.width, "Vector width"), height = positive(block.height, "Vector height");
|
|
8
|
+
const source = block.commands;
|
|
9
|
+
if (!Array.isArray(source))
|
|
10
|
+
throw new TypeError("Vector commands must be an array.");
|
|
11
|
+
if (used + source.length > settings.limits.maxVectorCommands)
|
|
12
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxVectorCommands exceeded.");
|
|
13
|
+
const input = source.map(c => {
|
|
14
|
+
if (!c || typeof c !== "object")
|
|
15
|
+
throw new TypeError("Invalid vector command.");
|
|
16
|
+
const op = c.op;
|
|
17
|
+
if (op === "move" || op === "line")
|
|
18
|
+
return { op, x: c.x, y: c.y };
|
|
19
|
+
if (op === "cubic")
|
|
20
|
+
return { op, x1: c.x1, y1: c.y1, x2: c.x2, y2: c.y2, x: c.x, y: c.y };
|
|
21
|
+
if (op === "close")
|
|
22
|
+
return { op };
|
|
23
|
+
throw new TypeError("Unsupported vector command.");
|
|
24
|
+
});
|
|
25
|
+
const fillValue = block.fill, strokeValue = block.stroke;
|
|
26
|
+
const fill = fillValue === undefined ? undefined : color(fillValue), stroke = strokeValue === undefined ? undefined : color(strokeValue);
|
|
27
|
+
if (fill === undefined && stroke === undefined)
|
|
28
|
+
throw new TypeError("A vector path requires fill or stroke.");
|
|
29
|
+
const strokeWidth = positive(block.strokeWidth ?? 1, "Vector stroke width", 144);
|
|
30
|
+
const fillRule = block.fillRule;
|
|
31
|
+
if (fillRule !== undefined && !["nonzero", "evenodd"].includes(fillRule))
|
|
32
|
+
throw new TypeError("Invalid vector fill rule.");
|
|
33
|
+
const commands = [];
|
|
34
|
+
let bytes = 0, started = false;
|
|
35
|
+
const coordinate = (value, bound) => {
|
|
36
|
+
if (!Number.isFinite(value) || value < 0 || value > bound)
|
|
37
|
+
throw new RangeError("Vector coordinates must stay inside their declared bounds.");
|
|
38
|
+
return n(value);
|
|
39
|
+
};
|
|
40
|
+
for (let i = 0; i < input.length; i++) {
|
|
41
|
+
const c = input[i];
|
|
42
|
+
let command;
|
|
43
|
+
if (!c || typeof c !== "object")
|
|
44
|
+
throw new TypeError("Invalid vector command.");
|
|
45
|
+
if (c.op === "move" || c.op === "line") {
|
|
46
|
+
if (c.op === "line" && !started)
|
|
47
|
+
throw new TypeError("A vector subpath must begin with move.");
|
|
48
|
+
command = coordinate(c.x, width) + " " + coordinate(c.y, height) + (c.op === "move" ? " m\n" : " l\n");
|
|
49
|
+
started = true;
|
|
50
|
+
}
|
|
51
|
+
else if (c.op === "cubic") {
|
|
52
|
+
if (!started)
|
|
53
|
+
throw new TypeError("A vector subpath must begin with move.");
|
|
54
|
+
command = [coordinate(c.x1, width), coordinate(c.y1, height), coordinate(c.x2, width), coordinate(c.y2, height), coordinate(c.x, width), coordinate(c.y, height)].join(" ") + " c\n";
|
|
55
|
+
}
|
|
56
|
+
else if (c.op === "close") {
|
|
57
|
+
if (!started)
|
|
58
|
+
throw new TypeError("Cannot close an empty vector path.");
|
|
59
|
+
command = "h\n";
|
|
60
|
+
}
|
|
61
|
+
else
|
|
62
|
+
throw new TypeError("Unsupported vector command.");
|
|
63
|
+
bytes += command.length;
|
|
64
|
+
if (bytes > settings.limits.maxPageBytes - 256)
|
|
65
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxPageBytes exceeded by vector commands.");
|
|
66
|
+
commands.push(command);
|
|
67
|
+
if ((i & 1023) === 1023) {
|
|
68
|
+
if (taskYieldDue())
|
|
69
|
+
await pause();
|
|
70
|
+
checkAbort(settings.options.signal);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!started)
|
|
74
|
+
throw new TypeError("A vector path needs at least one command.");
|
|
75
|
+
return { width, height, count: input.length, content: (fill === undefined ? "" : fill + " rg\n") + (stroke === undefined ? "" : stroke + " RG\n" + n(strokeWidth) + " w\n") +
|
|
76
|
+
commands.join("") + (fill !== undefined && stroke !== undefined ? "B" : fill !== undefined ? "f" : "S") + (fill !== undefined && fillRule === "evenodd" ? "*" : "") + "\n" };
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExportResult, OutputDestination } from "../core/index.js";
|
|
2
|
+
import type { PdfDocumentBlock, PdfDocumentOptions, PdfTableBlock, PdfTableOptions } from "./document-types.js";
|
|
3
|
+
/** Capture typed columns for a single-use table source in a composed document. */
|
|
4
|
+
export declare function pdfTable<T extends object>(rows: Iterable<T> | AsyncIterable<T>, options: PdfTableOptions<NoInfer<T>>): PdfTableBlock;
|
|
5
|
+
/** Write sequential report blocks to a PDF Blob, retaining finished output proportional to file size. */
|
|
6
|
+
export declare function writePdfDocument(blocks: Iterable<PdfDocumentBlock> | AsyncIterable<PdfDocumentBlock>, options?: PdfDocumentOptions): Promise<Blob>;
|
|
7
|
+
/** Stream composed pages with backpressure. Rows sum table source rows; columns reports the widest table.
|
|
8
|
+
* Analytical subtotals/grand totals also consume the cumulative maxRows output budget. */
|
|
9
|
+
export declare function writePdfDocumentTo(blocks: Iterable<PdfDocumentBlock> | AsyncIterable<PdfDocumentBlock>, destination: OutputDestination, configuration?: PdfDocumentOptions): Promise<ExportResult>;
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { BlobByteSink, withDestination } from "../core/sinks.js";
|
|
2
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
3
|
+
import { beginTask, checkAbort, consumeRows, pause, taskYieldDue } from "../core/iteration.js";
|
|
4
|
+
import { notifyProgress } from "../core/progress.js";
|
|
5
|
+
import { copyColumns, createRowProjector } from "../internal/rows.js";
|
|
6
|
+
import { captureFields } from "../internal/capture.js";
|
|
7
|
+
import { settings, captureWideTable } from "./settings.js";
|
|
8
|
+
import { pdfNumber as n } from "./objects.js";
|
|
9
|
+
import { PdfTableLayout } from "./table-layout.js";
|
|
10
|
+
import { PdfWriteSession } from "./session.js";
|
|
11
|
+
import { PdfDocumentImages } from "./document-images.js";
|
|
12
|
+
import { vectorCommands } from "./document-vectors.js";
|
|
13
|
+
import { graphicAlternative } from "./structure.js";
|
|
14
|
+
import { checkDrawingBlock, prepareDrawing } from "./document-drawings.js";
|
|
15
|
+
import { captureParagraph, captureCaption, prepareParagraph, checkParagraphBuffer, paragraphStartHeight } from "./paragraph-layout.js";
|
|
16
|
+
import { captureListOptions, prepareListItem } from "./list-layout.js";
|
|
17
|
+
import { captureSection } from "./section-types.js";
|
|
18
|
+
import { renderGroupedPdfTable } from "./document-grouped.js";
|
|
19
|
+
const tableOptionFields = ["columns", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "columnWidths", "wideTable", "formatValue", "formatRuns"];
|
|
20
|
+
/** Capture typed columns for a single-use table source in a composed document. */
|
|
21
|
+
export function pdfTable(rows, options) {
|
|
22
|
+
const captured = captureTableOptions(options);
|
|
23
|
+
return Object.freeze({ kind: "table", rows, options: Object.freeze({ ...captured, columns: Object.freeze(copyColumns(captured.columns)) }) });
|
|
24
|
+
}
|
|
25
|
+
/** Write sequential report blocks to a PDF Blob, retaining finished output proportional to file size. */
|
|
26
|
+
export async function writePdfDocument(blocks, options = {}) {
|
|
27
|
+
const sink = new BlobByteSink();
|
|
28
|
+
try {
|
|
29
|
+
await writePdfDocumentTo(blocks, sink, options);
|
|
30
|
+
return sink.toBlob("application/pdf");
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
sink.discard();
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Stream composed pages with backpressure. Rows sum table source rows; columns reports the widest table.
|
|
38
|
+
* Analytical subtotals/grand totals also consume the cumulative maxRows output budget. */
|
|
39
|
+
export async function writePdfDocumentTo(blocks, destination, configuration = {}) {
|
|
40
|
+
const captured = settings(configuration, true), controller = new AbortController();
|
|
41
|
+
const parentSignal = captured.options.signal, abort = () => controller.abort(parentSignal?.reason);
|
|
42
|
+
parentSignal?.addEventListener("abort", abort, { once: true });
|
|
43
|
+
if (parentSignal?.aborted)
|
|
44
|
+
abort();
|
|
45
|
+
const prepared = { ...captured, options: { ...captured.options, signal: controller.signal } }, { options, budget } = prepared;
|
|
46
|
+
try {
|
|
47
|
+
beginTask();
|
|
48
|
+
checkAbort(options.signal);
|
|
49
|
+
return await withDestination(destination, async (sink) => {
|
|
50
|
+
const session = new PdfWriteSession(sink, prepared), { objects, pages, fonts } = session, images = new PdfDocumentImages(objects, prepared);
|
|
51
|
+
let rows = 0, budgetRows = 0, columns = 0, commands = 0, drawingElements = 0, listItems = 0;
|
|
52
|
+
let pending = [];
|
|
53
|
+
const flushParagraphs = async (nextHeight = 0) => {
|
|
54
|
+
const paragraphs = [];
|
|
55
|
+
for (const paragraph of pending)
|
|
56
|
+
paragraphs.push(await prepareParagraph(paragraph, pages.settings, fonts));
|
|
57
|
+
pending = [];
|
|
58
|
+
await pages.paragraphs(paragraphs, nextHeight);
|
|
59
|
+
};
|
|
60
|
+
const enqueueParagraph = async (block) => {
|
|
61
|
+
const paragraph = captureParagraph(block, pages.settings, fonts);
|
|
62
|
+
if (!paragraph.text.text)
|
|
63
|
+
return;
|
|
64
|
+
if (pending.length || paragraph.keepWithNext) {
|
|
65
|
+
pending.push(paragraph);
|
|
66
|
+
checkParagraphBuffer(pending, pages.settings);
|
|
67
|
+
if (!paragraph.keepWithNext)
|
|
68
|
+
await flushParagraphs();
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
await pages.paragraphs([await prepareParagraph(paragraph, pages.settings, fonts)]);
|
|
72
|
+
};
|
|
73
|
+
const prepareCaption = async (captured) => captured === undefined ? undefined : prepareParagraph(captured, pages.settings, fonts);
|
|
74
|
+
const snapshotCaption = (caption) => caption === undefined ? undefined : captureCaption(caption, pages.settings, fonts);
|
|
75
|
+
await session.start();
|
|
76
|
+
await consumeRows(blocks, options.signal, async (block) => {
|
|
77
|
+
if (!block || typeof block !== "object")
|
|
78
|
+
throw new TypeError("PDF document blocks must be objects.");
|
|
79
|
+
switch (block.kind) {
|
|
80
|
+
case "section": {
|
|
81
|
+
const capturedSection = captureSection(block, prepared);
|
|
82
|
+
await flushParagraphs();
|
|
83
|
+
const section = await pages.beginSection(capturedSection);
|
|
84
|
+
if (section.includeHeading)
|
|
85
|
+
await enqueueParagraph({ kind: "paragraph", text: section.title,
|
|
86
|
+
headingLevel: section.level, ...(section.headingStyle === undefined ?
|
|
87
|
+
{ fontSize: pages.settings.fontSize * 1.5, presentation: { bold: true } } : { style: section.headingStyle }),
|
|
88
|
+
keepTogether: true, keepWithNext: true,
|
|
89
|
+
...(section.bookmark ? { bookmark: { title: section.title, level: section.level } } : {}) });
|
|
90
|
+
else if (section.bookmark)
|
|
91
|
+
pages.addBookmark({ title: section.title, level: section.level });
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "paragraph":
|
|
95
|
+
await enqueueParagraph(block);
|
|
96
|
+
break;
|
|
97
|
+
case "list": {
|
|
98
|
+
const captured = captureListOptions(block, pages.settings);
|
|
99
|
+
let count = 0, owner;
|
|
100
|
+
await consumeRows(captured.items, options.signal, async (item) => {
|
|
101
|
+
if (++listItems > prepared.limits.maxListItems)
|
|
102
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxListItems exceeded.");
|
|
103
|
+
const laidOut = await prepareListItem(item, count++, captured, pages.settings, fonts);
|
|
104
|
+
if (count === 1) {
|
|
105
|
+
await flushParagraphs(laidOut.paragraph.keepTogether ? laidOut.paragraph.height : laidOut.paragraph.firstHeight);
|
|
106
|
+
owner = session.structure?.element("L");
|
|
107
|
+
}
|
|
108
|
+
await pages.listItem(laidOut, owner);
|
|
109
|
+
if (taskYieldDue())
|
|
110
|
+
await pause();
|
|
111
|
+
checkAbort(options.signal);
|
|
112
|
+
});
|
|
113
|
+
await session.structure?.complete(owner);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case "group": {
|
|
117
|
+
const blocks = block.blocks, keepTogether = block.keepTogether;
|
|
118
|
+
if (!Array.isArray(blocks))
|
|
119
|
+
throw new TypeError("PDF paragraph group blocks must be an array.");
|
|
120
|
+
if (keepTogether !== undefined && typeof keepTogether !== "boolean")
|
|
121
|
+
throw new TypeError("PDF paragraph group keepTogether must be boolean.");
|
|
122
|
+
if (blocks.length > prepared.limits.maxGroupBlocks)
|
|
123
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxGroupBlocks exceeded.");
|
|
124
|
+
const captured = [];
|
|
125
|
+
for (const paragraph of blocks) {
|
|
126
|
+
captured.push(captureParagraph(paragraph, pages.settings, fonts));
|
|
127
|
+
checkParagraphBuffer(captured, prepared);
|
|
128
|
+
}
|
|
129
|
+
if (captured.filter(paragraph => paragraph.text.text).at(-1)?.keepWithNext)
|
|
130
|
+
throw new TypeError("The last paragraph in a group cannot keepWithNext beyond the group's boundary.");
|
|
131
|
+
const paragraphs = [];
|
|
132
|
+
for (const paragraph of captured)
|
|
133
|
+
paragraphs.push(await prepareParagraph(paragraph, pages.settings, fonts));
|
|
134
|
+
if (!paragraphs.some(paragraph => paragraph.lines.length > 0))
|
|
135
|
+
break;
|
|
136
|
+
await flushParagraphs(keepTogether !== false ? paragraphs.reduce((height, paragraph) => height + paragraph.height, 0) : paragraphStartHeight(paragraphs));
|
|
137
|
+
await pages.paragraphs(paragraphs, 0, keepTogether !== false);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case "pageBreak":
|
|
141
|
+
await flushParagraphs();
|
|
142
|
+
await pages.pageBreak();
|
|
143
|
+
break;
|
|
144
|
+
case "groupedTable":
|
|
145
|
+
await renderGroupedPdfTable(block, { prepared, pages, fonts, controller, flushParagraphs,
|
|
146
|
+
acceptColumns: count => { columns = Math.max(columns, count); },
|
|
147
|
+
acceptRow: source => {
|
|
148
|
+
budget.row(++budgetRows);
|
|
149
|
+
if (source && ++rows % 256 === 0)
|
|
150
|
+
notifyProgress(options.onProgress, { phase: "rows", rows, bytes: objects.bytes });
|
|
151
|
+
} });
|
|
152
|
+
break;
|
|
153
|
+
case "table": {
|
|
154
|
+
const { options: inputTableOptions, rows: source, caption: inputCaption, continuationCaption: inputContinuationCaption } = block;
|
|
155
|
+
const tableOptions = captureTableOptions(inputTableOptions);
|
|
156
|
+
const capturedCaption = snapshotCaption(inputCaption);
|
|
157
|
+
const capturedContinuationCaption = snapshotCaption(inputContinuationCaption);
|
|
158
|
+
const table = settings({ ...pages.settings.options, ...tableOptions, columns: tableOptions?.columns, includeHeader: tableOptions?.includeHeader ?? true }), layout = new PdfTableLayout({ ...table, budget }, fonts);
|
|
159
|
+
const caption = await prepareCaption(capturedCaption);
|
|
160
|
+
const continuationCaption = await prepareCaption(capturedContinuationCaption);
|
|
161
|
+
const project = createRowProjector(table.options.columns, undefined, options.signal);
|
|
162
|
+
let count = 0, started = false;
|
|
163
|
+
columns = Math.max(columns, table.options.columns.length);
|
|
164
|
+
const headings = await layout.headers(), headingHeight = await layout.blockHeight(headings);
|
|
165
|
+
await consumeRows(source, options.signal, async (row) => {
|
|
166
|
+
budget.row(++budgetRows);
|
|
167
|
+
const laidOut = await layout.data(project(row, count), count), keptHeading = !started && (pending.length > 0 || !!caption?.lines.length);
|
|
168
|
+
if (!started) {
|
|
169
|
+
const minimum = layout.minimumRowHeight(laidOut);
|
|
170
|
+
await flushParagraphs((caption?.height ?? 0) + headingHeight + minimum);
|
|
171
|
+
await pages.beginTable(layout, headings, minimum, caption, continuationCaption);
|
|
172
|
+
started = true;
|
|
173
|
+
}
|
|
174
|
+
await pages.row(laidOut, keptHeading);
|
|
175
|
+
count++;
|
|
176
|
+
rows++;
|
|
177
|
+
if (rows % 256 === 0)
|
|
178
|
+
notifyProgress(options.onProgress, { phase: "rows", rows, bytes: objects.bytes });
|
|
179
|
+
if (taskYieldDue())
|
|
180
|
+
await pause();
|
|
181
|
+
checkAbort(options.signal);
|
|
182
|
+
});
|
|
183
|
+
const footer = await layout.footer(count), keptFooterHeading = !started && (pending.length > 0 || !!caption?.lines.length);
|
|
184
|
+
if (!started) {
|
|
185
|
+
if (!headings.length && !footer?.length)
|
|
186
|
+
break;
|
|
187
|
+
const minimum = footer?.length ? table.options.footer?.rows ? await layout.blockHeight(footer) :
|
|
188
|
+
layout.minimumRowHeight(footer[0]) : 0;
|
|
189
|
+
await flushParagraphs((caption?.height ?? 0) + headingHeight + minimum);
|
|
190
|
+
await pages.beginTable(layout, headings, minimum, caption, continuationCaption);
|
|
191
|
+
}
|
|
192
|
+
if (footer) {
|
|
193
|
+
if (table.options.footer?.rows)
|
|
194
|
+
await pages.block(footer);
|
|
195
|
+
else
|
|
196
|
+
await pages.row(footer[0], keptFooterHeading);
|
|
197
|
+
}
|
|
198
|
+
await pages.endTable();
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case "image": {
|
|
202
|
+
const { width: displayWidth, height: displayHeight, image: inputImage, caption: inputCaption } = block;
|
|
203
|
+
const capturedCaption = snapshotCaption(inputCaption), alternative = graphicAlternative(block, pages.settings), alignment = graphicAlignment(block.alignment);
|
|
204
|
+
if (capturedCaption && alternative === undefined)
|
|
205
|
+
throw new TypeError("A captioned PDF graphic requires alternativeText and cannot be decorative.");
|
|
206
|
+
const image = await images.prepare(inputImage), caption = await prepareCaption(capturedCaption);
|
|
207
|
+
const width = displayWidth ?? (displayHeight === undefined ? image.width * .75 : displayHeight * image.width / image.height);
|
|
208
|
+
const height = displayHeight ?? width * image.height / image.width;
|
|
209
|
+
if (!Number.isFinite(width) || width <= 0 || !Number.isFinite(height) || height <= 0)
|
|
210
|
+
throw new RangeError("Image display dimensions must be finite and positive.");
|
|
211
|
+
await flushParagraphs((caption?.height ?? 0) + pages.graphicHeight(width, height));
|
|
212
|
+
pages.registerXObject(image.name, image.id);
|
|
213
|
+
await pages.graphic(width, height, alignment, (x, y, w, h) => "q " + [w, 0, 0, h, x, y].map(n).join(" ") + " cm /" + image.name + " Do Q\n", alternative, caption);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case "vector": {
|
|
217
|
+
const capturedCaption = snapshotCaption(block.caption), alternative = graphicAlternative(block, pages.settings), alignment = graphicAlignment(block.alignment);
|
|
218
|
+
if (capturedCaption && alternative === undefined)
|
|
219
|
+
throw new TypeError("A captioned PDF graphic requires alternativeText and cannot be decorative.");
|
|
220
|
+
const path = await vectorCommands(block, pages.settings, commands), caption = await prepareCaption(capturedCaption);
|
|
221
|
+
commands += path.count;
|
|
222
|
+
await flushParagraphs((caption?.height ?? 0) + pages.graphicHeight(path.width, path.height));
|
|
223
|
+
await pages.graphic(path.width, path.height, alignment, (x, y, w, h) => "q " + [w / path.width, 0, 0, -h / path.height, x, y + h].map(n).join(" ") +
|
|
224
|
+
" cm 0 0 " + n(path.width) + " " + n(path.height) + " re W n\n" + path.content + "Q\n", alternative, caption);
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
case "drawing": {
|
|
228
|
+
checkDrawingBlock(block);
|
|
229
|
+
const inputDrawing = block.drawing, capturedCaption = snapshotCaption(block.caption), alternative = graphicAlternative(block, pages.settings), alignment = graphicAlignment(block.alignment);
|
|
230
|
+
if (capturedCaption && alternative === undefined)
|
|
231
|
+
throw new TypeError("A captioned PDF graphic requires alternativeText and cannot be decorative.");
|
|
232
|
+
const drawing = await prepareDrawing(inputDrawing, pages.settings, fonts, { commands, elements: drawingElements }), caption = await prepareCaption(capturedCaption);
|
|
233
|
+
commands += drawing.commands;
|
|
234
|
+
drawingElements += drawing.elements;
|
|
235
|
+
await flushParagraphs((caption?.height ?? 0) + pages.graphicHeight(drawing.width, drawing.height));
|
|
236
|
+
await pages.graphic(drawing.width, drawing.height, alignment, (x, y, w, h) => "q " + [w / drawing.width, 0, 0, -h / drawing.height, x, y + h].map(n).join(" ") +
|
|
237
|
+
" cm 0 0 " + n(drawing.width) + " " + n(drawing.height) + " re W n\n" + drawing.content + "Q\n", alternative, caption);
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
default: throw new TypeError("Unsupported PDF document block.");
|
|
241
|
+
}
|
|
242
|
+
if (taskYieldDue())
|
|
243
|
+
await pause();
|
|
244
|
+
checkAbort(options.signal);
|
|
245
|
+
});
|
|
246
|
+
await flushParagraphs();
|
|
247
|
+
if (options.messageBottom)
|
|
248
|
+
await pages.paragraph(options.messageBottom);
|
|
249
|
+
await session.finish();
|
|
250
|
+
notifyProgress(options.onProgress, { phase: "complete", rows, bytes: objects.bytes });
|
|
251
|
+
checkAbort(options.signal);
|
|
252
|
+
return { rows, columns, bytes: objects.bytes };
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
parentSignal?.removeEventListener("abort", abort);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function graphicAlignment(value) {
|
|
260
|
+
if (value !== undefined && !["left", "center", "right"].includes(value))
|
|
261
|
+
throw new TypeError("Invalid graphic alignment.");
|
|
262
|
+
return value ?? "left";
|
|
263
|
+
}
|
|
264
|
+
/** Per-table overrides cannot change the document's shared fonts, geometry or resource policy. */
|
|
265
|
+
function captureTableOptions(options) {
|
|
266
|
+
if (!options || typeof options !== "object" || Object.keys(options).some(key => !tableOptionFields.includes(key)))
|
|
267
|
+
throw new TypeError("Table options support columns, headings, footers, widths and presentation; document settings belong on writePdfDocument.");
|
|
268
|
+
const captured = captureFields(options, tableOptionFields);
|
|
269
|
+
return { ...captured, ...(captured.wideTable === undefined ? {} : { wideTable: captureWideTable(captured.wideTable) }) };
|
|
270
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PdfCaption, PdfPathCommand } from "./document-types.js";
|
|
2
|
+
/** Versioned portable drawing. Lengths are points, with a top-left origin and downward y axis. */
|
|
3
|
+
export interface PdfDrawing {
|
|
4
|
+
readonly version: 1;
|
|
5
|
+
readonly width: number;
|
|
6
|
+
readonly height: number;
|
|
7
|
+
readonly elements: readonly PdfDrawingElement[];
|
|
8
|
+
}
|
|
9
|
+
/** One painted path; colors are six-digit RGB hex strings. */
|
|
10
|
+
export interface PdfDrawingPath {
|
|
11
|
+
readonly kind: "path";
|
|
12
|
+
readonly commands: readonly PdfPathCommand[];
|
|
13
|
+
readonly fill?: string;
|
|
14
|
+
readonly stroke?: string;
|
|
15
|
+
readonly strokeWidth?: number;
|
|
16
|
+
readonly fillRule?: "nonzero" | "evenodd";
|
|
17
|
+
readonly lineCap?: "butt" | "round" | "square";
|
|
18
|
+
readonly lineJoin?: "miter" | "round" | "bevel";
|
|
19
|
+
}
|
|
20
|
+
/** A face explicitly supplied in the PDF document's embedded static TrueType family. */
|
|
21
|
+
export type PdfDrawingFont = "regular" | "bold" | "italic" | "boldItalic";
|
|
22
|
+
/** Fixed baseline text. No wrapping, shaping, font lookup, synthetic emphasis or line breaks. */
|
|
23
|
+
export interface PdfDrawingText {
|
|
24
|
+
readonly kind: "text";
|
|
25
|
+
readonly text: string;
|
|
26
|
+
readonly x: number;
|
|
27
|
+
readonly y: number;
|
|
28
|
+
readonly font: PdfDrawingFont;
|
|
29
|
+
readonly fontSize: number;
|
|
30
|
+
readonly color: string;
|
|
31
|
+
}
|
|
32
|
+
export interface PdfDrawingClip {
|
|
33
|
+
readonly x: number;
|
|
34
|
+
readonly y: number;
|
|
35
|
+
readonly width: number;
|
|
36
|
+
readonly height: number;
|
|
37
|
+
}
|
|
38
|
+
/** Ordered children, optionally restricted by an axis-aligned rectangular clip. */
|
|
39
|
+
export interface PdfDrawingGroup {
|
|
40
|
+
readonly kind: "group";
|
|
41
|
+
readonly clip?: PdfDrawingClip;
|
|
42
|
+
readonly elements: readonly PdfDrawingElement[];
|
|
43
|
+
}
|
|
44
|
+
export type PdfDrawingElement = PdfDrawingPath | PdfDrawingText | PdfDrawingGroup;
|
|
45
|
+
/** An indivisible drawing, automatically scaled down to fit the printable page. */
|
|
46
|
+
export interface PdfDrawingBlock {
|
|
47
|
+
readonly kind: "drawing";
|
|
48
|
+
readonly drawing: PdfDrawing;
|
|
49
|
+
readonly alignment?: "left" | "center" | "right";
|
|
50
|
+
readonly alternativeText?: string;
|
|
51
|
+
readonly decorative?: boolean;
|
|
52
|
+
readonly caption?: PdfCaption;
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { PdfFont } from "./font.js";
|
|
2
|
+
import type { PdfObjects } from "./objects.js";
|
|
3
|
+
import type { PdfFonts } from "./types.js";
|
|
4
|
+
import type { TrueTypeFont } from "./truetype.js";
|
|
5
|
+
export declare class PdfFontResource {
|
|
6
|
+
readonly index: number;
|
|
7
|
+
readonly bold: boolean;
|
|
8
|
+
readonly italic: boolean;
|
|
9
|
+
readonly font: PdfFont | undefined;
|
|
10
|
+
private readonly shared?;
|
|
11
|
+
private readonly signal?;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly object: number;
|
|
14
|
+
readonly program: TrueTypeFont | undefined;
|
|
15
|
+
readonly syntheticBold: boolean;
|
|
16
|
+
readonly syntheticItalic: boolean;
|
|
17
|
+
private readonly mappings;
|
|
18
|
+
private readonly standardWidths;
|
|
19
|
+
constructor(index: number, bold: boolean, italic: boolean, font: PdfFont | undefined, objects: PdfObjects, syntheticBold: boolean, syntheticItalic: boolean, shared?: PdfFontResource | undefined, signal?: AbortSignal | undefined);
|
|
20
|
+
width(scalar: number): number;
|
|
21
|
+
lineHeight(size: number): number;
|
|
22
|
+
encode(text: string): string;
|
|
23
|
+
/** Register an already validated shaped glyph. A glyph may need distinct CIDs for different logical clusters. */
|
|
24
|
+
encodeGlyph(glyph: number, text: string): string;
|
|
25
|
+
write(objects: PdfObjects, compression: boolean): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare class PdfFontResources {
|
|
28
|
+
private readonly objects;
|
|
29
|
+
private readonly fonts?;
|
|
30
|
+
private readonly maxBytes;
|
|
31
|
+
private readonly signal?;
|
|
32
|
+
readonly resources: PdfFontResource[];
|
|
33
|
+
private readonly selections;
|
|
34
|
+
private readonly programs;
|
|
35
|
+
private readonly explicitSelections;
|
|
36
|
+
private readonly registered;
|
|
37
|
+
private fontBytes;
|
|
38
|
+
constructor(objects: PdfObjects, fonts?: PdfFonts | undefined, maxBytes?: number, signal?: AbortSignal | undefined);
|
|
39
|
+
/** The same operation budget covers unused declared faces and every explicit run face, once per identity. */
|
|
40
|
+
registerFont(font: PdfFont): void;
|
|
41
|
+
select(bold?: boolean, italic?: boolean, explicit?: PdfFont): PdfFontResource;
|
|
42
|
+
dictionary(): string;
|
|
43
|
+
}
|