abstract-document 20.1.6 → 20.2.1
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 +12 -0
- package/lib/abstract-document/atoms/text-run.d.ts.map +1 -1
- package/lib/abstract-document/atoms/text-run.js +1 -7
- package/lib/abstract-document/atoms/text-run.js.map +1 -1
- package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
- package/lib/abstract-document/markdown/markdown.js +58 -60
- package/lib/abstract-document/markdown/markdown.js.map +1 -1
- package/lib/abstract-document/resources.d.ts.map +1 -1
- package/lib/abstract-document/resources.js +1 -3
- package/lib/abstract-document/resources.js.map +1 -1
- package/lib/abstract-document/styles/table-style.js +2 -2
- package/lib/abstract-document/styles/table-style.js.map +1 -1
- package/lib/abstract-document/styles/text-style.js +6 -6
- package/lib/abstract-document/styles/text-style.js.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.js +14 -17
- package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.js +9 -11
- package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.js +2 -6
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.js +1 -2
- package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js +3 -3
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js +1 -0
- package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js +4 -6
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +2 -2
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +23 -26
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.js +21 -23
- package/lib/abstract-document-exporters/pdf/textRunRow.js.map +1 -1
- package/lib/abstract-document-jsx/index.d.ts.map +1 -1
- package/lib/abstract-document-jsx/index.js +5 -5
- package/lib/abstract-document-jsx/index.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +32 -29
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +29 -46
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +16 -5
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
- package/package.json +4 -4
- package/src/abstract-document/atoms/text-run.ts +1 -7
- package/src/abstract-document/markdown/markdown.ts +74 -76
- package/src/abstract-document/resources.ts +1 -3
- package/src/abstract-document/styles/table-style.ts +2 -2
- package/src/abstract-document/styles/text-style.ts +6 -6
- package/src/abstract-document-exporters/docx/xml-writer.ts +16 -19
- package/src/abstract-document-exporters/docx2/render-image.ts +11 -13
- package/src/abstract-document-exporters/docx2/render.ts +3 -7
- package/src/abstract-document-exporters/pdf/font.ts +1 -2
- package/src/abstract-document-exporters/pdf/measure.ts +9 -9
- package/src/abstract-document-exporters/pdf/paginate.ts +3 -2
- package/src/abstract-document-exporters/pdf/pre-process.ts +5 -7
- package/src/abstract-document-exporters/pdf/render-image.ts +9 -9
- package/src/abstract-document-exporters/pdf/render.ts +25 -28
- package/src/abstract-document-exporters/pdf/textRunRow.ts +32 -35
- package/src/abstract-document-jsx/index.ts +7 -7
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +30 -27
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +38 -51
- package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +22 -8
- package/src/custom_typings/pdf2json/index.d.ts +10 -1
- package/src/custom_typings/remark-parse/index.d.ts +4 -1
- package/src/custom_typings/remark-sub-super/index.d.ts +4 -1
- package/src/custom_typings/svg-to-pdfkit/index.d.ts +4 -1
- package/src/custom_typings/unified/index.d.ts +8 -1
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
TocSeparator,
|
|
18
18
|
ImageResource,
|
|
19
19
|
} from "../../abstract-document/index.js";
|
|
20
|
-
import type {
|
|
20
|
+
import type { ImageCellProps, ImageParagraphProps, ImageRowProps } from "./custom-elements.js";
|
|
21
21
|
import { TextRow, TextCell, TextParagraph, ImageCell, ImageParagraph, ImageRow } from "./custom-elements.js";
|
|
22
22
|
|
|
23
23
|
export type ADCreatorFn = (props?: Record<string, unknown>, children?: ReadonlyArray<unknown>) => unknown;
|
|
@@ -27,22 +27,23 @@ export const creators: (styleNames: Record<string, string>) => Record<string, AD
|
|
|
27
27
|
AbstractDoc: ((props, children: ReadonlyArray<Section.Section>) => AbstractDoc.create(props, children)) as ADCreatorFn,
|
|
28
28
|
Section: ((props, children: ReadonlyArray<SectionElement.SectionElement>) => Section.create(props, children)) as ADCreatorFn,
|
|
29
29
|
Paragraph: ((props, children: ReadonlyArray<Atom.Atom>) => Paragraph.create(props, children)) as ADCreatorFn,
|
|
30
|
-
TextRow: (
|
|
31
|
-
TextCell: (
|
|
32
|
-
TextParagraph: (
|
|
33
|
-
TextRun: (props) => TextRun.create(props
|
|
30
|
+
TextRow: (props) => TextRow({ ...props, text: requireText(props) }, styleNames),
|
|
31
|
+
TextCell: (props) => TextCell({ ...props, text: requireText(props) }, styleNames),
|
|
32
|
+
TextParagraph: (props) => TextParagraph({ ...props, text: requireText(props) }, styleNames),
|
|
33
|
+
TextRun: (props) => TextRun.create({ ...props, text: requireText(props) }),
|
|
34
34
|
ImageRow: ((props: Record<string, unknown>) => ImageRow(imageProps(props) as unknown as ImageRowProps, styleNames)) as ADCreatorFn,
|
|
35
35
|
ImageCell: ((props: Record<string, unknown>) => ImageCell(imageProps(props) as unknown as ImageCellProps, styleNames)) as ADCreatorFn,
|
|
36
36
|
ImageParagraph: ((props: Record<string, unknown>) =>
|
|
37
37
|
ImageParagraph(imageProps(props) as unknown as ImageParagraphProps, styleNames)) as ADCreatorFn,
|
|
38
38
|
Image: ((props: Record<string, unknown>) => Image.create(imageProps(props) as unknown as Image.ImageProps)) as ADCreatorFn,
|
|
39
|
-
Table: ((props, children: ReadonlyArray<TableRow.TableRow>) =>
|
|
39
|
+
Table: ((props, children: ReadonlyArray<TableRow.TableRow>) =>
|
|
40
|
+
Table.create({ ...props, columnWidths: props?.["columnWidths"] ?? [] } as unknown as Table.TableProps, children)) as ADCreatorFn,
|
|
40
41
|
TableRow: ((props, children: ReadonlyArray<TableCell.TableCell>) => TableRow.create(props, children)) as ADCreatorFn,
|
|
41
42
|
TableCell: ((props, children: ReadonlyArray<SectionElement.SectionElement>) => TableCell.create(props, children)) as ADCreatorFn,
|
|
42
|
-
TextField: (props) => TextField.create(props
|
|
43
|
-
Group: (props, children) => Group.create(props, children as ReadonlyArray<
|
|
43
|
+
TextField: (props) => TextField.create({ ...props, fieldType: requireFieldType(props) }),
|
|
44
|
+
Group: (props, children) => Group.create(props, children as ReadonlyArray<SectionElement.SectionElement>),
|
|
44
45
|
PageBreak: () => PageBreak.create(),
|
|
45
|
-
Markdown: (props) => Markdown.create(props
|
|
46
|
+
Markdown: (props) => Markdown.create({ ...props, text: requireText(props) }),
|
|
46
47
|
TocSeparator: (props) => TocSeparator.create(props as TocSeparator.TocSeparatorProps),
|
|
47
48
|
};
|
|
48
49
|
};
|
|
@@ -50,23 +51,17 @@ export const creators: (styleNames: Record<string, string>) => Record<string, AD
|
|
|
50
51
|
export const propsCreators: Record<string, ADCreatorFn> = {
|
|
51
52
|
styles: ((props: { readonly styles: Record<string, Record<string, string | number> & { readonly type: string }> }): unknown => {
|
|
52
53
|
const fixedStyles: Record<string, Record<string, string | number>> = {};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
}
|
|
54
|
+
Object.keys(props.styles).forEach((key: string) => {
|
|
55
|
+
fixedStyles[key] = { ...props.styles[key] };
|
|
56
|
+
});
|
|
58
57
|
|
|
59
58
|
return { ...fixedStyles, ...DefaultStyles.createStandardStyles() };
|
|
60
59
|
}) as ADCreatorFn,
|
|
61
60
|
columnWidths: ((props: { readonly columnWidths: string; readonly columnMultiplier: string }): unknown => {
|
|
62
|
-
const columnWidths =
|
|
63
|
-
|
|
64
|
-
.
|
|
65
|
-
|
|
66
|
-
.map((item: string) => {
|
|
67
|
-
const number = Number(item);
|
|
68
|
-
return number === 0 || Number.isNaN(number) ? Infinity : number;
|
|
69
|
-
});
|
|
61
|
+
const columnWidths = props.columnWidths.split(",").map((item: string) => {
|
|
62
|
+
const number = Number(item);
|
|
63
|
+
return number === 0 || Number.isNaN(number) ? Infinity : number;
|
|
64
|
+
});
|
|
70
65
|
if (props.columnMultiplier) {
|
|
71
66
|
return columnWidths.map((l) => l * Number(props.columnMultiplier));
|
|
72
67
|
}
|
|
@@ -83,11 +78,7 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
83
78
|
}) as ADCreatorFn,
|
|
84
79
|
borders: ((props: { readonly borders: string }): unknown => {
|
|
85
80
|
const borders: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
86
|
-
|
|
87
|
-
const propBorders = props.borders.toString().split(" ");
|
|
88
|
-
if (!propBorders) {
|
|
89
|
-
return borders;
|
|
90
|
-
}
|
|
81
|
+
const propBorders = props.borders.split(" ");
|
|
91
82
|
|
|
92
83
|
if (propBorders.length === 1) {
|
|
93
84
|
borders["top"] = Number(propBorders[0]);
|
|
@@ -150,11 +141,7 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
150
141
|
padding: ((props: { readonly padding: string }): unknown => {
|
|
151
142
|
const padding: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
152
143
|
|
|
153
|
-
|
|
154
|
-
const paddings = props.padding.toString().split(" ");
|
|
155
|
-
if (!paddings) {
|
|
156
|
-
return padding;
|
|
157
|
-
}
|
|
144
|
+
const paddings = props.padding.split(" ");
|
|
158
145
|
|
|
159
146
|
if (paddings.length === 1) {
|
|
160
147
|
padding["top"] = Number(paddings[0]);
|
|
@@ -216,11 +203,7 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
216
203
|
}) as ADCreatorFn,
|
|
217
204
|
margins: ((props: { readonly margins: string }): unknown => {
|
|
218
205
|
const margins: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
219
|
-
|
|
220
|
-
const propMargins = props.margins.toString().split(" ");
|
|
221
|
-
if (!propMargins) {
|
|
222
|
-
return margins;
|
|
223
|
-
}
|
|
206
|
+
const propMargins = props.margins.split(" ");
|
|
224
207
|
|
|
225
208
|
if (propMargins.length === 1) {
|
|
226
209
|
margins["top"] = Number(propMargins[0]);
|
|
@@ -358,6 +341,21 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
358
341
|
differentFirstPage: ((props: { readonly differentFirstPage: string }): unknown => strToBool(props.differentFirstPage)) as ADCreatorFn,
|
|
359
342
|
};
|
|
360
343
|
|
|
344
|
+
function requireText(props: Record<string, unknown> | undefined): string {
|
|
345
|
+
const text = props?.["text"];
|
|
346
|
+
return typeof text === "string" ? text : "";
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const validFieldTypes: ReadonlyArray<TextField.FieldType> = ["Date", "PageNumber", "TotalPages", "PageNumberOf"];
|
|
350
|
+
|
|
351
|
+
function requireFieldType(props: Record<string, unknown> | undefined): TextField.FieldType {
|
|
352
|
+
const fieldType = props?.["fieldType"];
|
|
353
|
+
if (validFieldTypes.includes(fieldType as TextField.FieldType)) {
|
|
354
|
+
return fieldType as TextField.FieldType;
|
|
355
|
+
}
|
|
356
|
+
throw new Error(`<TextField> requires a "fieldType" attribute of ${validFieldTypes.join(", ")}, got: ${String(fieldType)}`);
|
|
357
|
+
}
|
|
358
|
+
|
|
361
359
|
const zero = createPoint(0, 0);
|
|
362
360
|
const size = createSize(0, 0);
|
|
363
361
|
function imageProps(props: Record<string, unknown>): Record<string, unknown> {
|
|
@@ -373,21 +371,10 @@ function imageProps(props: Record<string, unknown>): Record<string, unknown> {
|
|
|
373
371
|
};
|
|
374
372
|
}
|
|
375
373
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
const validBools = {
|
|
381
|
-
"1": true,
|
|
382
|
-
true: true,
|
|
383
|
-
};
|
|
384
|
-
return str in validBools;
|
|
385
|
-
};
|
|
374
|
+
// bold/italic/etc. are declared `xs:boolean` in the XSD schema; XSD's boolean lexical space is {true, false, 1, 0}
|
|
375
|
+
const strToBool = (str: string | undefined): boolean => str === "true" || str === "1";
|
|
386
376
|
|
|
387
377
|
const strToNum = (str: string | undefined): number => {
|
|
388
378
|
const num = Number(str);
|
|
389
|
-
|
|
390
|
-
return 0;
|
|
391
|
-
}
|
|
392
|
-
return num;
|
|
379
|
+
return Number.isFinite(num) ? num : 0;
|
|
393
380
|
};
|
|
@@ -35,7 +35,9 @@ export function extractStyleNames(styleNames: string | undefined, styleNameTypes
|
|
|
35
35
|
return styleNameProps;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export type TextRowProps = Omit<TextCellProps, "style"> & {
|
|
38
|
+
export type TextRowProps = Omit<TextCellProps, "style"> & {
|
|
39
|
+
readonly cellStyle?: TableCellStyle.TableCellStyle;
|
|
40
|
+
};
|
|
39
41
|
|
|
40
42
|
export function TextRow(props: TextRowProps, styleNameTypes: Record<string, string>): TableRow.TableRow {
|
|
41
43
|
return TableRow.create({}, [TextCell({ ...props, style: props.cellStyle }, styleNameTypes)]);
|
|
@@ -85,7 +87,9 @@ export function TextParagraph(props: TextParagraphProps, styleNameTypes: Record<
|
|
|
85
87
|
return Paragraph.create({ style, styleName: styleNames.ParagraphStyle }, [textRun]);
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
export type ImageRowProps = Omit<ImageCellProps, "style"> & {
|
|
90
|
+
export type ImageRowProps = Omit<ImageCellProps, "style"> & {
|
|
91
|
+
readonly cellStyle?: TableCellStyle.TableCellStyle;
|
|
92
|
+
};
|
|
89
93
|
|
|
90
94
|
export function ImageRow(props: ImageRowProps, styleNameTypes: Record<string, string>): TableRow.TableRow {
|
|
91
95
|
return TableRow.create({}, [ImageCell({ ...props, style: props.cellStyle }, styleNameTypes)]);
|
|
@@ -101,12 +105,18 @@ export type ImageCellProps = Omit<ImageParagraphProps, "style"> & {
|
|
|
101
105
|
export function ImageCell(props: ImageCellProps, styleNameTypes: Record<string, string>): TableCell.TableCell {
|
|
102
106
|
const { imageResource, width, height, horizontalAlignment, verticalAlignment, paragraphStyle, style, columnSpan, rowSpan } = props;
|
|
103
107
|
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
|
|
104
|
-
const imageElement =
|
|
108
|
+
const imageElement = Image.create({
|
|
109
|
+
imageResource,
|
|
110
|
+
width,
|
|
111
|
+
height,
|
|
112
|
+
horizontalAlignment,
|
|
113
|
+
verticalAlignment,
|
|
114
|
+
});
|
|
105
115
|
const pararaphProps = {
|
|
106
116
|
style: paragraphStyle ? { ...paragraphStyle, type: "ParagraphStyle" } : undefined,
|
|
107
117
|
styleName: styleNames.ParagraphStyle,
|
|
108
118
|
} as ParagraphProps;
|
|
109
|
-
const paragraph =
|
|
119
|
+
const paragraph = Paragraph.create(pararaphProps, [imageElement]);
|
|
110
120
|
return TableCell.create({ columnSpan, rowSpan, style, styleName: styleNames.TableCellStyle }, [paragraph]);
|
|
111
121
|
}
|
|
112
122
|
|
|
@@ -118,9 +128,13 @@ export type ImageParagraphProps = ImageProps & {
|
|
|
118
128
|
export function ImageParagraph(props: ImageParagraphProps, styleNameTypes: Record<string, string>): Paragraph.Paragraph | undefined {
|
|
119
129
|
const { imageResource, width, height, style, horizontalAlignment, verticalAlignment } = props;
|
|
120
130
|
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
|
|
121
|
-
const imageElement =
|
|
131
|
+
const imageElement = Image.create({
|
|
132
|
+
imageResource,
|
|
133
|
+
width,
|
|
134
|
+
height,
|
|
135
|
+
horizontalAlignment,
|
|
136
|
+
verticalAlignment,
|
|
137
|
+
});
|
|
122
138
|
const pararaphProps = { style, styleName: styleNames.ParagraphStyle };
|
|
123
|
-
return
|
|
139
|
+
return Paragraph.create(pararaphProps, [imageElement]);
|
|
124
140
|
}
|
|
125
|
-
|
|
126
|
-
const ImageMissing = TextRun.create({ text: "Image missing" });
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
declare module "pdf2json"
|
|
1
|
+
declare module "pdf2json" {
|
|
2
|
+
// oxlint-disable-next-line no-redeclare -- value + type share a name, the standard pattern for typing a constructible class from an untyped module
|
|
3
|
+
interface PDFParser {
|
|
4
|
+
on: ((event: "pdfParser_dataError", callback: (data: { parserError: string }) => void) => void) &
|
|
5
|
+
((event: "pdfParser_dataReady", callback: (data: unknown) => void) => void);
|
|
6
|
+
parseBuffer: (buffer: Buffer) => void;
|
|
7
|
+
}
|
|
8
|
+
const PDFParser: new () => PDFParser;
|
|
9
|
+
export default PDFParser;
|
|
10
|
+
}
|