abstract-document 16.0.32 → 16.0.34
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/lib/abstract-document/page/master-page.d.ts +4 -0
- package/lib/abstract-document/page/master-page.d.ts.map +1 -1
- package/lib/abstract-document/page/master-page.js +3 -1
- package/lib/abstract-document/page/master-page.js.map +1 -1
- package/lib/abstract-document/styles/page-style.d.ts +4 -0
- package/lib/abstract-document/styles/page-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/page-style.js +3 -1
- package/lib/abstract-document/styles/page-style.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js +13 -1
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.d.ts +6 -0
- package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js +43 -10
- package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js +3 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +7 -6
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +12 -2
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/elements.d.ts +4 -3
- package/lib/abstract-document-xml/xsd-template/elements.d.ts.map +1 -1
- package/lib/abstract-document-xml/xsd-template/elements.js +20 -13
- package/lib/abstract-document-xml/xsd-template/elements.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/styles.d.ts +1 -1
- package/lib/abstract-document-xml/xsd-template/styles.d.ts.map +1 -1
- package/lib/abstract-document-xml/xsd-template/styles.js +2 -0
- package/lib/abstract-document-xml/xsd-template/styles.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts +2 -2
- package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts.map +1 -1
- package/lib/abstract-document-xml/xsd-template/xsd-template.js +1 -0
- package/lib/abstract-document-xml/xsd-template/xsd-template.js.map +1 -1
- package/package.json +2 -2
- package/src/abstract-document/page/master-page.ts +7 -1
- package/src/abstract-document/styles/page-style.ts +8 -0
- package/src/abstract-document-exporters/pdf/measure.ts +15 -3
- package/src/abstract-document-exporters/pdf/paginate.ts +52 -15
- package/src/abstract-document-exporters/pdf/pre-process.ts +3 -1
- package/src/abstract-document-exporters/pdf/render.ts +8 -7
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +10 -2
- package/src/abstract-document-xml/xsd-template/elements.ts +21 -12
- package/src/abstract-document-xml/xsd-template/styles.ts +2 -0
- package/src/abstract-document-xml/xsd-template/xsd-template.ts +1 -0
- package/lib/abstract-document-exporters/shared/to-base-64.d.ts +0 -3
- package/lib/abstract-document-exporters/shared/to-base-64.d.ts.map +0 -1
- package/lib/abstract-document-exporters/shared/to-base-64.js +0 -19
- package/lib/abstract-document-exporters/shared/to-base-64.js.map +0 -1
|
@@ -42,13 +42,13 @@ function splitSection(
|
|
|
42
42
|
): Array<Page> {
|
|
43
43
|
const resources = AD.Resources.mergeResources([parentResources, section]);
|
|
44
44
|
const pages = new Array<Page>();
|
|
45
|
-
const contentRect = getPageContentRect(desiredSizes, section);
|
|
46
45
|
|
|
47
46
|
let children = section.children;
|
|
48
47
|
let elements = new Array<AD.SectionElement.SectionElement>();
|
|
49
48
|
let elementsHeight = 0;
|
|
50
49
|
let currentPage = previousPage;
|
|
51
50
|
for (let i = 0; i < children.length; ++i) {
|
|
51
|
+
const contentRect = getPageContentRect(desiredSizes, section, pages.length + 1);
|
|
52
52
|
const element = children[i];
|
|
53
53
|
if (element.type === "PageBreak") {
|
|
54
54
|
currentPage = createPage(resources, desiredSizes, currentPage, section, elements, pages.length === 0);
|
|
@@ -218,10 +218,12 @@ function createPage(
|
|
|
218
218
|
const namedDestionations = [...sectionName, ...targetNames];
|
|
219
219
|
|
|
220
220
|
// Ignore leading space by expanding the content rect upwards
|
|
221
|
-
const rect = getPageContentRect(desiredSizes, section);
|
|
221
|
+
const rect = getPageContentRect(desiredSizes, section, pageNo);
|
|
222
222
|
const [leadingSpace] = getLeadingAndTrailingSpace(resources, section, elements);
|
|
223
223
|
const contentRect = AD.Rect.create(rect.x, rect.y - leadingSpace, rect.width, rect.height + leadingSpace);
|
|
224
224
|
|
|
225
|
+
const frontHeader = (section.page.frontHeader === undefined || section.page.frontHeader.length === 0) ? section.page.header : section.page.frontHeader;
|
|
226
|
+
const frontFooter = (section.page.frontFooter === undefined || section.page.frontFooter.length === 0) ? section.page.footer : section.page.frontFooter;
|
|
225
227
|
return {
|
|
226
228
|
pageNo: pageNo,
|
|
227
229
|
namedDestionations: namedDestionations,
|
|
@@ -229,37 +231,72 @@ function createPage(
|
|
|
229
231
|
section: section,
|
|
230
232
|
contentRect: contentRect,
|
|
231
233
|
elements: elements,
|
|
232
|
-
header: section.page.header,
|
|
233
|
-
footer: section.page.footer,
|
|
234
|
+
header: isFirst ? frontHeader : section.page.header,
|
|
235
|
+
footer: isFirst ? frontFooter : section.page.footer,
|
|
234
236
|
};
|
|
235
237
|
}
|
|
236
238
|
|
|
237
|
-
function
|
|
239
|
+
export function getHeaderAndFooter(section: AD.Section.Section, pageNo: number): {
|
|
240
|
+
readonly header: Array<AD.SectionElement.SectionElement>;
|
|
241
|
+
readonly footer: Array<AD.SectionElement.SectionElement>;
|
|
242
|
+
readonly headerMargins: AD.LayoutFoundation.LayoutFoundation;
|
|
243
|
+
readonly footerMargins: AD.LayoutFoundation.LayoutFoundation;
|
|
244
|
+
} {
|
|
245
|
+
const FIRST_PAGE = 1;
|
|
246
|
+
const EVEN_PAGE = 0;
|
|
247
|
+
const ODD_PAGE = 1;
|
|
248
|
+
switch(true) {
|
|
249
|
+
//first page
|
|
250
|
+
case pageNo === FIRST_PAGE: {
|
|
251
|
+
const normalHeader = section.page.frontHeader === undefined || section.page.frontHeader.length === 0;
|
|
252
|
+
const normalFooter = section.page.frontFooter === undefined || section.page.frontFooter.length === 0;
|
|
253
|
+
return {
|
|
254
|
+
footer: normalFooter ? section.page.footer : section.page.frontFooter,
|
|
255
|
+
header: normalHeader ? section.page.header : section.page.frontHeader,
|
|
256
|
+
headerMargins: normalHeader ? section.page.style.headerMargins : (section.page.style.firstPageHeaderMargins ?? section.page.style.headerMargins),
|
|
257
|
+
footerMargins: normalFooter ? section.page.style.footerMargins : (section.page.style.firstPageFooterMargins ?? section.page.style.footerMargins),
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
case pageNo === 0:
|
|
261
|
+
case pageNo % 2 === EVEN_PAGE:
|
|
262
|
+
case pageNo % 2 === ODD_PAGE:
|
|
263
|
+
default: {
|
|
264
|
+
return {
|
|
265
|
+
header: section.page.header,
|
|
266
|
+
footer: section.page.footer,
|
|
267
|
+
headerMargins: section.page.style.headerMargins,
|
|
268
|
+
footerMargins: section.page.style.footerMargins,
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function getPageContentRect(desiredSizes: Map<{}, AD.Size.Size>, section: AD.Section.Section, pageNo: number): AD.Rect.Rect {
|
|
238
275
|
const style = section.page.style;
|
|
239
276
|
const pageWidth = AD.PageStyle.getWidth(style);
|
|
240
277
|
const pageHeight = AD.PageStyle.getHeight(style);
|
|
241
278
|
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
279
|
+
const { header, footer, headerMargins, footerMargins } = getHeaderAndFooter(section, pageNo);
|
|
280
|
+
const headerHeight = header.reduce(
|
|
281
|
+
(prev, curr) => prev + getDesiredSize(curr, desiredSizes).height,
|
|
282
|
+
headerMargins.top + headerMargins.bottom
|
|
245
283
|
);
|
|
246
|
-
const footerHeight =
|
|
247
|
-
(
|
|
248
|
-
|
|
284
|
+
const footerHeight = footer.reduce(
|
|
285
|
+
(prev, curr) => prev + getDesiredSize(curr, desiredSizes).height,
|
|
286
|
+
footerMargins.top + footerMargins.bottom
|
|
249
287
|
);
|
|
250
288
|
|
|
251
|
-
let headerY =
|
|
252
|
-
for (let element of
|
|
289
|
+
let headerY = headerMargins.top;
|
|
290
|
+
for (let element of header) {
|
|
253
291
|
const elementSize = getDesiredSize(element, desiredSizes);
|
|
254
292
|
headerY += elementSize.height;
|
|
255
293
|
}
|
|
256
|
-
headerY +=
|
|
294
|
+
headerY += headerMargins.bottom;
|
|
257
295
|
|
|
258
296
|
const rectX = style.contentMargins.left;
|
|
259
297
|
const rectY = headerY + style.contentMargins.top;
|
|
260
298
|
const rectWidth = pageWidth - (style.contentMargins.left + style.contentMargins.right);
|
|
261
299
|
const rectHeight = pageHeight - headerHeight - footerHeight - style.contentMargins.top - style.contentMargins.bottom;
|
|
262
|
-
|
|
263
300
|
return AD.Rect.create(rectX, rectY, rectWidth, rectHeight);
|
|
264
301
|
}
|
|
265
302
|
|
|
@@ -52,7 +52,9 @@ function preProcessSection(s: AD.Section.Section, parentResources: AD.Resources.
|
|
|
52
52
|
const resources = AD.Resources.mergeResources([parentResources, s]);
|
|
53
53
|
const header = s.page.header.flatMap((e) => preProcessSectionElement(e, resources));
|
|
54
54
|
const footer = s.page.footer.flatMap((e) => preProcessSectionElement(e, resources));
|
|
55
|
-
const
|
|
55
|
+
const frontHeader = (s.page.frontHeader ?? []).flatMap((e) => preProcessSectionElement(e, resources));
|
|
56
|
+
const frontFooter = (s.page.frontFooter ?? []).flatMap((e) => preProcessSectionElement(e, resources));
|
|
57
|
+
const page = AD.MasterPage.create({ style: s.page.style, header: header, footer: footer, frontHeader: frontHeader, frontFooter: frontFooter });
|
|
56
58
|
const children = s.children.flatMap((e) => preProcessSectionElement(e, resources));
|
|
57
59
|
return AD.Section.create({ page: page, id: s.id }, children);
|
|
58
60
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
2
|
import { preProcess } from "./pre-process.js";
|
|
3
3
|
import { measure, measurePages } from "./measure.js";
|
|
4
|
-
import { paginate, Page } from "./paginate.js";
|
|
4
|
+
import { paginate, Page, getHeaderAndFooter } from "./paginate.js";
|
|
5
5
|
import { updatePageRefs } from "./update-refs.js";
|
|
6
6
|
import { renderImage } from "./render-image.js";
|
|
7
7
|
import { registerFonts, getFontNameStyle } from "./font.js";
|
|
@@ -80,8 +80,9 @@ function renderPage(
|
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
const
|
|
84
|
-
const
|
|
83
|
+
const { headerMargins, footerMargins } = getHeaderAndFooter(section, page.pageNo);
|
|
84
|
+
const headerX = headerMargins.left;
|
|
85
|
+
const headerStart = headerMargins.top;
|
|
85
86
|
let headerY = headerStart;
|
|
86
87
|
for (let element of page.header) {
|
|
87
88
|
const elementSize = getDesiredSize(element, desiredSizes);
|
|
@@ -97,14 +98,14 @@ function renderPage(
|
|
|
97
98
|
headerY += elementSize.height;
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
headerY +=
|
|
101
|
+
headerY += headerMargins.bottom;
|
|
101
102
|
|
|
102
103
|
const footerHeight = page.footer.reduce(
|
|
103
104
|
(a, b) => a + (AD.Position.isPositionAbsolute(b) ? 0 : getDesiredSize(b, desiredSizes).height),
|
|
104
|
-
|
|
105
|
+
footerMargins.top + footerMargins.bottom
|
|
105
106
|
);
|
|
106
|
-
const footerX =
|
|
107
|
-
const footerStart = pageHeight - (footerHeight -
|
|
107
|
+
const footerX = footerMargins.left;
|
|
108
|
+
const footerStart = pageHeight - (footerHeight - footerMargins.top);
|
|
108
109
|
let footerY = footerStart;
|
|
109
110
|
for (let element of page.footer) {
|
|
110
111
|
const elementSize = getDesiredSize(element, desiredSizes);
|
|
@@ -36,8 +36,16 @@ function abstractDocXmlRecursive(
|
|
|
36
36
|
} else {
|
|
37
37
|
// For lowercase elements we add them as keys using their name
|
|
38
38
|
// Some special keys should directly have an array of children as value instead of an object with children key
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const arrayedElements = ["header", "footer", "headerRows"];
|
|
40
|
+
const childrenOnly = arrayedElements.findIndex((e) => e === childName) !== -1;
|
|
41
|
+
const differentFirstPage = childElement.attributes.differentFirstPage;
|
|
42
|
+
if(differentFirstPage === "true" && childName === "header") {
|
|
43
|
+
props.frontHeader = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
44
|
+
} else if (differentFirstPage === "true" && childName === "footer") {
|
|
45
|
+
props.frontFooter = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
46
|
+
} else {
|
|
47
|
+
props[childName] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
48
|
+
}
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as Custom from "./custom-elements.js";
|
|
2
2
|
|
|
3
3
|
export const abstractDoc = `<xs:element name="AbstractDoc">
|
|
4
|
-
|
|
4
|
+
<xs:complexType>
|
|
5
5
|
<xs:sequence>
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
<xs:element name="StyleNames" type="StyleNames" minOccurs="0"></xs:element>
|
|
7
|
+
<xs:element name="Section" type="Section"></xs:element>
|
|
8
8
|
</xs:sequence>
|
|
9
9
|
</xs:complexType>
|
|
10
10
|
</xs:element>`;
|
|
@@ -28,21 +28,30 @@ export const page = `<xs:complexType name="page">
|
|
|
28
28
|
</xs:annotation>
|
|
29
29
|
<xs:all>
|
|
30
30
|
<xs:element name="style" type="MasterPageStyle" />
|
|
31
|
-
<xs:element name="header" type="
|
|
32
|
-
<xs:element name="footer" type="
|
|
31
|
+
<xs:element name="header" type="HeaderFooter" minOccurs="0" />
|
|
32
|
+
<xs:element name="footer" type="HeaderFooter" minOccurs="0" />
|
|
33
33
|
</xs:all>
|
|
34
34
|
</xs:complexType>`;
|
|
35
35
|
|
|
36
|
+
const sectionElementBody = `<xs:element name="Table" type="Table" minOccurs="0" />
|
|
37
|
+
<xs:element name="Group" type="Group" minOccurs="0" />
|
|
38
|
+
<xs:element name="PageBreak" type="PageBreak" minOccurs="0" />
|
|
39
|
+
<xs:element name="Paragraph" type="Paragraph" minOccurs="0" />
|
|
40
|
+
${Custom.textParagraphElement}
|
|
41
|
+
${Custom.imageParagraphElement}
|
|
42
|
+
<xs:element name="Markdown" type="Markdown" minOccurs="0" />`;
|
|
43
|
+
|
|
36
44
|
export const sectionElement = `<xs:complexType name="SectionElement">
|
|
37
45
|
<xs:choice maxOccurs="unbounded">
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
${sectionElementBody}
|
|
47
|
+
</xs:choice>
|
|
48
|
+
</xs:complexType>`;
|
|
49
|
+
|
|
50
|
+
export const headerFooter = `<xs:complexType name="HeaderFooter">
|
|
51
|
+
<xs:choice maxOccurs="unbounded">
|
|
52
|
+
${sectionElementBody}
|
|
45
53
|
</xs:choice>
|
|
54
|
+
<xs:attribute name="differentFirstPage" type="xs:boolean" use="optional"/>
|
|
46
55
|
</xs:complexType>`;
|
|
47
56
|
|
|
48
57
|
export const group = `<xs:complexType name="Group">
|
|
@@ -244,6 +244,8 @@ export const masterPageStyle = `<xs:complexType name="MasterPageStyle">
|
|
|
244
244
|
<xs:all>
|
|
245
245
|
<xs:element name="headerMargins" type="LayoutFoundation" />
|
|
246
246
|
<xs:element name="footerMargins" type="LayoutFoundation" />
|
|
247
|
+
<xs:element name="firstPageHeaderMargins" type="LayoutFoundation" minOccurs="0" />
|
|
248
|
+
<xs:element name="firstPageFooterMargins" type="LayoutFoundation" minOccurs="0" />
|
|
247
249
|
<xs:element name="contentMargins" type="LayoutFoundation" />
|
|
248
250
|
</xs:all>
|
|
249
251
|
<xs:attribute name="paperSize" use="required">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-base-64.d.ts","sourceRoot":"","sources":["../../../src/abstract-document-exporters/shared/to-base-64.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,CAarD;AAED,eAAO,MAAM,YAAY,wBAAwB,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rawSvgPrefix = void 0;
|
|
4
|
-
exports.toBase64String = toBase64String;
|
|
5
|
-
function toBase64String(u8) {
|
|
6
|
-
const imageFormat = u8[0] === 0xff && u8[1] === 0xd8 ? "image/jpeg" : "image/png";
|
|
7
|
-
// Node
|
|
8
|
-
if (typeof Buffer !== "undefined") {
|
|
9
|
-
return `data:${imageFormat};base64,${Buffer.from(u8).toString("base64")}`;
|
|
10
|
-
}
|
|
11
|
-
// Browser
|
|
12
|
-
let bin = "";
|
|
13
|
-
for (const e of u8) {
|
|
14
|
-
bin += String.fromCharCode(e);
|
|
15
|
-
}
|
|
16
|
-
return `data:${imageFormat};base64,${btoa(bin)}`;
|
|
17
|
-
}
|
|
18
|
-
exports.rawSvgPrefix = "data:image/svg+xml,";
|
|
19
|
-
//# sourceMappingURL=to-base-64.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-base-64.js","sourceRoot":"","sources":["../../../src/abstract-document-exporters/shared/to-base-64.ts"],"names":[],"mappings":";;;AAAA,wCAaC;AAbD,SAAgB,cAAc,CAAC,EAAc;IAC3C,MAAM,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC;IAClF,OAAO;IACP,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,QAAQ,WAAW,WAAW,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC5E,CAAC;IACD,UAAU;IACV,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACnB,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,QAAQ,WAAW,WAAW,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACnD,CAAC;AAEY,QAAA,YAAY,GAAG,qBAAqB,CAAC"}
|