@pdfme/common 6.1.0 → 6.1.1-dev.5
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/dist/dynamicTemplate.d.ts +2 -2
- package/dist/helper.d.ts +30 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +177 -28
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +95 -0
- package/dist/types.d.ts +20 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema, Template, BasePdf, CommonOptions } from './types.js';
|
|
1
|
+
import { Schema, Template, BasePdf, CommonOptions, DynamicLayoutCallbackResult } from './types.js';
|
|
2
2
|
interface ModifyTemplateForDynamicTableArg {
|
|
3
3
|
template: Template;
|
|
4
4
|
input: Record<string, string>;
|
|
@@ -9,7 +9,7 @@ interface ModifyTemplateForDynamicTableArg {
|
|
|
9
9
|
basePdf: BasePdf;
|
|
10
10
|
options: CommonOptions;
|
|
11
11
|
_cache: Map<string | number, unknown>;
|
|
12
|
-
}) => Promise<
|
|
12
|
+
}) => Promise<DynamicLayoutCallbackResult>;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Process a template containing tables with dynamic heights
|
package/dist/helper.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PDFDocument, PDFPage } from '@pdfme/pdf-lib';
|
|
1
2
|
import { Template, Font, BasePdf, Plugins, BlankPdf } from './types.js';
|
|
2
3
|
export declare const cloneDeep: typeof structuredClone;
|
|
3
4
|
export declare const getFallbackFontName: (font: Font) => string;
|
|
@@ -16,6 +17,35 @@ export declare const getInputFromTemplate: (template: Template) => {
|
|
|
16
17
|
[key: string]: string;
|
|
17
18
|
}[];
|
|
18
19
|
export declare const isUrlSafeToFetch: (urlString: string) => boolean;
|
|
20
|
+
export type PdfLinkAnnotationRect = {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
};
|
|
26
|
+
export declare const normalizeSafeLinkUri: (uri: string) => string | undefined;
|
|
27
|
+
export declare const getInternalLinkTarget: (href: string) => string | undefined;
|
|
28
|
+
export declare const normalizeInternalLinkHref: (href: string) => string | undefined;
|
|
29
|
+
export declare const normalizeLinkHref: (href: string) => string | undefined;
|
|
30
|
+
export declare const resetInternalLinkAnnotations: (_cache: Map<string | number, unknown>) => void;
|
|
31
|
+
export declare const registerInternalLinkAnchor: (arg: {
|
|
32
|
+
_cache: Map<string | number, unknown>;
|
|
33
|
+
name: string;
|
|
34
|
+
page: PDFPage;
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
}) => void;
|
|
38
|
+
export declare const registerInternalLinkAnnotation: (arg: {
|
|
39
|
+
_cache: Map<string | number, unknown>;
|
|
40
|
+
page: PDFPage;
|
|
41
|
+
targetName: string;
|
|
42
|
+
rect: PdfLinkAnnotationRect;
|
|
43
|
+
borderWidth?: number;
|
|
44
|
+
}) => void;
|
|
45
|
+
export declare const applyInternalLinkAnnotations: (arg: {
|
|
46
|
+
_cache: Map<string | number, unknown>;
|
|
47
|
+
pdfDoc: PDFDocument;
|
|
48
|
+
}) => void;
|
|
19
49
|
export declare const getB64BasePdf: (customPdf: ArrayBuffer | Uint8Array | string) => Promise<string>;
|
|
20
50
|
export declare const isBlankPdf: (basePdf: BasePdf) => basePdf is BlankPdf;
|
|
21
51
|
export declare const b64toUint8Array: (base64: string) => Uint8Array<ArrayBuffer>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { PDFME_VERSION } from './version.js';
|
|
2
2
|
import { MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, BLANK_A4_PDF, CUSTOM_A4_PDF, ZOOM, DEFAULT_FONT_NAME } from './constants.js';
|
|
3
|
-
import type { ChangeSchemaItem, ChangeSchemas, SchemaPageArray, PropPanel, PropPanelSchema, PropPanelWidgetProps, PDFRenderProps, Mode, UIRenderProps, Plugin, Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps } from './types.js';
|
|
4
|
-
import {
|
|
3
|
+
import type { ChangeSchemaItem, ChangeSchemas, SchemaPageArray, PropPanel, PropPanelSchema, PropPanelWidgetProps, PDFRenderProps, Mode, UIRenderProps, Plugin, Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, DynamicLayoutArgs, DynamicLayoutCallbackResult, DynamicLayoutPatchArgs, DynamicLayoutResult, GetDynamicLayout } from './types.js';
|
|
4
|
+
import type { PdfLinkAnnotationRect } from './helper.js';
|
|
5
|
+
import { cloneDeep, getFallbackFontName, getDefaultFont, getB64BasePdf, b64toUint8Array, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, mm2pt, pt2mm, pt2px, px2mm, isHexValid, getInputFromTemplate, isBlankPdf, isUrlSafeToFetch, getInternalLinkTarget, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnchor, registerInternalLinkAnnotation, resetInternalLinkAnnotations, applyInternalLinkAnnotations } from './helper.js';
|
|
5
6
|
import { getDynamicTemplate } from './dynamicTemplate.js';
|
|
6
7
|
import { replacePlaceholders } from './expression.js';
|
|
7
8
|
import { pluginRegistry } from './pluginRegistry.js';
|
|
8
|
-
export { PDFME_VERSION, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, BLANK_A4_PDF, CUSTOM_A4_PDF, ZOOM, DEFAULT_FONT_NAME, cloneDeep, getFallbackFontName, getDefaultFont, getB64BasePdf, b64toUint8Array, mm2pt, pt2mm, pt2px, px2mm, isHexValid, getInputFromTemplate, isBlankPdf, getDynamicTemplate, replacePlaceholders, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, pluginRegistry, isUrlSafeToFetch, };
|
|
9
|
-
export type { Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugin, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ChangeSchemaItem, ChangeSchemas, SchemaPageArray, PropPanel, PropPanelSchema, PropPanelWidgetProps, PDFRenderProps, UIRenderProps, Mode, };
|
|
9
|
+
export { PDFME_VERSION, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, BLANK_A4_PDF, CUSTOM_A4_PDF, ZOOM, DEFAULT_FONT_NAME, cloneDeep, getFallbackFontName, getDefaultFont, getB64BasePdf, b64toUint8Array, mm2pt, pt2mm, pt2px, px2mm, isHexValid, getInputFromTemplate, isBlankPdf, getDynamicTemplate, replacePlaceholders, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, pluginRegistry, isUrlSafeToFetch, getInternalLinkTarget, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnchor, registerInternalLinkAnnotation, resetInternalLinkAnnotations, applyInternalLinkAnnotations, };
|
|
10
|
+
export type { Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugin, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ChangeSchemaItem, ChangeSchemas, SchemaPageArray, PropPanel, PropPanelSchema, PropPanelWidgetProps, PDFRenderProps, UIRenderProps, Mode, DynamicLayoutArgs, DynamicLayoutCallbackResult, DynamicLayoutPatchArgs, DynamicLayoutResult, GetDynamicLayout, PdfLinkAnnotationRect, };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
|
+
import { PDFName } from "@pdfme/pdf-lib";
|
|
3
4
|
import * as acorn from "acorn";
|
|
4
5
|
//#region src/version.ts
|
|
5
|
-
var PDFME_VERSION = "6.1.
|
|
6
|
+
var PDFME_VERSION = "6.1.1";
|
|
6
7
|
//#endregion
|
|
7
8
|
//#region src/constants.ts
|
|
8
9
|
var PT_TO_PX_RATIO = 1.333;
|
|
@@ -133,7 +134,18 @@ z.object({
|
|
|
133
134
|
"schemas.date.locale": z.string(),
|
|
134
135
|
"schemas.select.options": z.string(),
|
|
135
136
|
"schemas.select.optionPlaceholder": z.string(),
|
|
136
|
-
"schemas.radioGroup.groupName": z.string()
|
|
137
|
+
"schemas.radioGroup.groupName": z.string(),
|
|
138
|
+
"schemas.list.listStyle": z.string(),
|
|
139
|
+
"schemas.list.bullet": z.string(),
|
|
140
|
+
"schemas.list.ordered": z.string(),
|
|
141
|
+
"schemas.list.markerWidth": z.string(),
|
|
142
|
+
"schemas.list.markerGap": z.string(),
|
|
143
|
+
"schemas.list.indentSize": z.string(),
|
|
144
|
+
"schemas.list.itemSpacing": z.string(),
|
|
145
|
+
"schemas.list.addItem": z.string(),
|
|
146
|
+
"schemas.list.removeItem": z.string(),
|
|
147
|
+
"schemas.list.indentItem": z.string(),
|
|
148
|
+
"schemas.list.outdentItem": z.string()
|
|
137
149
|
});
|
|
138
150
|
z.enum([
|
|
139
151
|
"viewer",
|
|
@@ -163,6 +175,10 @@ var Schema = z.object({
|
|
|
163
175
|
start: z.number(),
|
|
164
176
|
end: z.number().optional()
|
|
165
177
|
}).optional(),
|
|
178
|
+
__itemRange: z.object({
|
|
179
|
+
start: z.number(),
|
|
180
|
+
end: z.number().optional()
|
|
181
|
+
}).optional(),
|
|
166
182
|
__isSplit: z.boolean().optional()
|
|
167
183
|
}).passthrough();
|
|
168
184
|
var SchemaForUIAdditionalInfo = z.object({ id: z.string() });
|
|
@@ -350,6 +366,130 @@ var isUrlSafeToFetch = (urlString) => {
|
|
|
350
366
|
}
|
|
351
367
|
return true;
|
|
352
368
|
};
|
|
369
|
+
var SAFE_LINK_URI_PROTOCOLS = new Set([
|
|
370
|
+
"http:",
|
|
371
|
+
"https:",
|
|
372
|
+
"mailto:"
|
|
373
|
+
]);
|
|
374
|
+
var INTERNAL_LINK_CACHE_KEY = "pdfme-internal-link-cache";
|
|
375
|
+
var normalizeSafeLinkUri = (uri) => {
|
|
376
|
+
const trimmed = uri.trim();
|
|
377
|
+
if (!trimmed) return void 0;
|
|
378
|
+
let parsed;
|
|
379
|
+
try {
|
|
380
|
+
parsed = new URL(trimmed);
|
|
381
|
+
} catch {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
return SAFE_LINK_URI_PROTOCOLS.has(parsed.protocol.toLowerCase()) ? trimmed : void 0;
|
|
385
|
+
};
|
|
386
|
+
var getInternalLinkTarget = (href) => {
|
|
387
|
+
const trimmed = href.trim();
|
|
388
|
+
if (!trimmed.startsWith("#") || trimmed.length === 1) return void 0;
|
|
389
|
+
let target = trimmed.slice(1);
|
|
390
|
+
try {
|
|
391
|
+
target = decodeURIComponent(target);
|
|
392
|
+
} catch {}
|
|
393
|
+
target = target.trim();
|
|
394
|
+
if (!target || Array.from(target).some((char) => {
|
|
395
|
+
const code = char.charCodeAt(0);
|
|
396
|
+
return code < 32 || code === 127;
|
|
397
|
+
})) return;
|
|
398
|
+
return target;
|
|
399
|
+
};
|
|
400
|
+
var normalizeInternalLinkHref = (href) => {
|
|
401
|
+
const target = getInternalLinkTarget(href);
|
|
402
|
+
return target ? `#${target}` : void 0;
|
|
403
|
+
};
|
|
404
|
+
var normalizeLinkHref = (href) => normalizeSafeLinkUri(href) ?? normalizeInternalLinkHref(href);
|
|
405
|
+
var getInternalLinkCache = (_cache) => {
|
|
406
|
+
let cache = _cache.get(INTERNAL_LINK_CACHE_KEY);
|
|
407
|
+
if (!cache) {
|
|
408
|
+
cache = {
|
|
409
|
+
anchors: /* @__PURE__ */ new Map(),
|
|
410
|
+
annotations: []
|
|
411
|
+
};
|
|
412
|
+
_cache.set(INTERNAL_LINK_CACHE_KEY, cache);
|
|
413
|
+
}
|
|
414
|
+
return cache;
|
|
415
|
+
};
|
|
416
|
+
var resetInternalLinkAnnotations = (_cache) => {
|
|
417
|
+
_cache.set(INTERNAL_LINK_CACHE_KEY, {
|
|
418
|
+
anchors: /* @__PURE__ */ new Map(),
|
|
419
|
+
annotations: []
|
|
420
|
+
});
|
|
421
|
+
};
|
|
422
|
+
var registerInternalLinkAnchor = (arg) => {
|
|
423
|
+
const { _cache, name, page, x, y } = arg;
|
|
424
|
+
if (!name) return;
|
|
425
|
+
const cache = getInternalLinkCache(_cache);
|
|
426
|
+
const anchors = cache.anchors.get(name) ?? [];
|
|
427
|
+
anchors.push({
|
|
428
|
+
name,
|
|
429
|
+
page,
|
|
430
|
+
x,
|
|
431
|
+
y
|
|
432
|
+
});
|
|
433
|
+
cache.anchors.set(name, anchors);
|
|
434
|
+
};
|
|
435
|
+
var registerInternalLinkAnnotation = (arg) => {
|
|
436
|
+
const { _cache, page, targetName, rect, borderWidth } = arg;
|
|
437
|
+
if (!targetName || rect.width <= 0 || rect.height <= 0) return;
|
|
438
|
+
getInternalLinkCache(_cache).annotations.push({
|
|
439
|
+
page,
|
|
440
|
+
targetName,
|
|
441
|
+
rect,
|
|
442
|
+
borderWidth
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
var addGoToLinkAnnotation = (arg) => {
|
|
446
|
+
const { pdfDoc, page, target, rect, borderWidth = 0 } = arg;
|
|
447
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
448
|
+
const annotationRef = pdfDoc.context.register(pdfDoc.context.obj({
|
|
449
|
+
Type: PDFName.of("Annot"),
|
|
450
|
+
Subtype: PDFName.of("Link"),
|
|
451
|
+
Rect: [
|
|
452
|
+
rect.x,
|
|
453
|
+
rect.y,
|
|
454
|
+
rect.x + rect.width,
|
|
455
|
+
rect.y + rect.height
|
|
456
|
+
],
|
|
457
|
+
Border: [
|
|
458
|
+
0,
|
|
459
|
+
0,
|
|
460
|
+
borderWidth
|
|
461
|
+
],
|
|
462
|
+
A: {
|
|
463
|
+
Type: PDFName.of("Action"),
|
|
464
|
+
S: PDFName.of("GoTo"),
|
|
465
|
+
D: [
|
|
466
|
+
target.page.ref,
|
|
467
|
+
PDFName.of("XYZ"),
|
|
468
|
+
target.x,
|
|
469
|
+
target.y,
|
|
470
|
+
null
|
|
471
|
+
]
|
|
472
|
+
}
|
|
473
|
+
}));
|
|
474
|
+
page.node.addAnnot(annotationRef);
|
|
475
|
+
};
|
|
476
|
+
var applyInternalLinkAnnotations = (arg) => {
|
|
477
|
+
const { _cache, pdfDoc } = arg;
|
|
478
|
+
const cache = getInternalLinkCache(_cache);
|
|
479
|
+
cache.annotations.forEach((annotation) => {
|
|
480
|
+
const anchors = cache.anchors.get(annotation.targetName) ?? [];
|
|
481
|
+
if (anchors.length === 0) throw new Error(`[@pdfme/generator] Internal link target "#${annotation.targetName}" was not found.`);
|
|
482
|
+
if (anchors.length > 1) throw new Error(`[@pdfme/generator] Internal link target "#${annotation.targetName}" is ambiguous because multiple schemas use that name.`);
|
|
483
|
+
addGoToLinkAnnotation({
|
|
484
|
+
pdfDoc,
|
|
485
|
+
page: annotation.page,
|
|
486
|
+
target: anchors[0],
|
|
487
|
+
rect: annotation.rect,
|
|
488
|
+
borderWidth: annotation.borderWidth
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
resetInternalLinkAnnotations(_cache);
|
|
492
|
+
};
|
|
353
493
|
var getB64BasePdf = async (customPdf) => {
|
|
354
494
|
if (typeof customPdf === "string" && !customPdf.startsWith("data:application/pdf;") && typeof window !== "undefined") {
|
|
355
495
|
if (!isUrlSafeToFetch(customPdf)) throw Error("[@pdfme/common] Invalid or unsafe URL for basePdf. Only http: and https: URLs pointing to public hosts are allowed.");
|
|
@@ -451,7 +591,7 @@ function normalizePageSchemas(pageSchemas, paddingTop) {
|
|
|
451
591
|
schema: cloneDeep(schema),
|
|
452
592
|
baseY: localY,
|
|
453
593
|
height: schema.height,
|
|
454
|
-
|
|
594
|
+
dynamicLayout: { heights: [schema.height] }
|
|
455
595
|
});
|
|
456
596
|
orderMap.set(schema.name, index);
|
|
457
597
|
});
|
|
@@ -465,20 +605,21 @@ function normalizePageSchemas(pageSchemas, paddingTop) {
|
|
|
465
605
|
};
|
|
466
606
|
}
|
|
467
607
|
/**
|
|
468
|
-
* Place
|
|
608
|
+
* Place height units on pages, splitting across pages as needed.
|
|
469
609
|
* @returns The final global Y coordinate after placement
|
|
470
610
|
*/
|
|
471
|
-
function
|
|
472
|
-
|
|
611
|
+
function placeUnitsOnPages(schema, dynamicLayout, startGlobalY, contentHeight, paddingTop, pages) {
|
|
612
|
+
const dynamicHeights = dynamicLayout.heights;
|
|
613
|
+
let currentUnitIndex = 0;
|
|
473
614
|
let currentPageIndex = Math.floor(startGlobalY / contentHeight);
|
|
474
615
|
let currentYInPage = startGlobalY % contentHeight;
|
|
475
616
|
if (currentYInPage < 0) currentYInPage = 0;
|
|
476
617
|
let actualGlobalEndY = 0;
|
|
477
618
|
const isSplittable = dynamicHeights.length > 1;
|
|
478
|
-
while (
|
|
619
|
+
while (currentUnitIndex < dynamicHeights.length) {
|
|
479
620
|
while (pages.length <= currentPageIndex) pages.push([]);
|
|
480
621
|
const spaceLeft = contentHeight - currentYInPage;
|
|
481
|
-
if (dynamicHeights[
|
|
622
|
+
if (dynamicHeights[currentUnitIndex] > spaceLeft + EPSILON) {
|
|
482
623
|
if (!(Math.abs(spaceLeft - contentHeight) <= EPSILON)) {
|
|
483
624
|
currentPageIndex++;
|
|
484
625
|
currentYInPage = 0;
|
|
@@ -486,40 +627,41 @@ function placeRowsOnPages(schema, dynamicHeights, startGlobalY, contentHeight, p
|
|
|
486
627
|
}
|
|
487
628
|
}
|
|
488
629
|
let chunkHeight = 0;
|
|
489
|
-
const
|
|
490
|
-
while (
|
|
491
|
-
const h = dynamicHeights[
|
|
630
|
+
const startUnitIndex = currentUnitIndex;
|
|
631
|
+
while (currentUnitIndex < dynamicHeights.length) {
|
|
632
|
+
const h = dynamicHeights[currentUnitIndex];
|
|
492
633
|
if (currentYInPage + chunkHeight + h <= contentHeight + EPSILON) {
|
|
493
634
|
chunkHeight += h;
|
|
494
|
-
|
|
635
|
+
currentUnitIndex++;
|
|
495
636
|
} else break;
|
|
496
637
|
}
|
|
497
638
|
const isAtPageTop = currentYInPage <= EPSILON;
|
|
498
|
-
if (isSplittable &&
|
|
499
|
-
|
|
639
|
+
if (dynamicLayout.avoidFirstUnitOnly && isSplittable && startUnitIndex === 0 && currentUnitIndex === 1 && dynamicHeights.length > 1 && !isAtPageTop) {
|
|
640
|
+
currentUnitIndex = 0;
|
|
500
641
|
currentPageIndex++;
|
|
501
642
|
currentYInPage = 0;
|
|
502
643
|
continue;
|
|
503
644
|
}
|
|
504
|
-
if (
|
|
505
|
-
chunkHeight += dynamicHeights[
|
|
506
|
-
|
|
645
|
+
if (currentUnitIndex === startUnitIndex) {
|
|
646
|
+
chunkHeight += dynamicHeights[currentUnitIndex];
|
|
647
|
+
currentUnitIndex++;
|
|
507
648
|
}
|
|
649
|
+
const patch = dynamicLayout.patchSplitSchema?.({
|
|
650
|
+
schema,
|
|
651
|
+
start: startUnitIndex,
|
|
652
|
+
end: currentUnitIndex,
|
|
653
|
+
isSplit: startUnitIndex > 0,
|
|
654
|
+
chunkHeight
|
|
655
|
+
}) ?? {};
|
|
508
656
|
const newSchema = {
|
|
509
657
|
...schema,
|
|
658
|
+
...patch,
|
|
510
659
|
height: chunkHeight,
|
|
511
660
|
position: {
|
|
512
661
|
...schema.position,
|
|
513
662
|
y: currentYInPage + paddingTop
|
|
514
663
|
}
|
|
515
664
|
};
|
|
516
|
-
if (isSplittable) {
|
|
517
|
-
newSchema.__bodyRange = {
|
|
518
|
-
start: startRowIndex === 0 ? 0 : startRowIndex - 1,
|
|
519
|
-
end: currentRowIndex - 1
|
|
520
|
-
};
|
|
521
|
-
newSchema.__isSplit = startRowIndex > 0;
|
|
522
|
-
}
|
|
523
665
|
pages[currentPageIndex].push(newSchema);
|
|
524
666
|
currentYInPage += chunkHeight;
|
|
525
667
|
if (currentYInPage >= contentHeight - EPSILON) {
|
|
@@ -550,12 +692,19 @@ function processDynamicPage(items, orderMap, contentHeight, paddingTop) {
|
|
|
550
692
|
let totalYOffset = 0;
|
|
551
693
|
for (const item of items) {
|
|
552
694
|
const currentGlobalStartY = item.baseY + totalYOffset;
|
|
553
|
-
totalYOffset =
|
|
695
|
+
totalYOffset = placeUnitsOnPages(item.schema, item.dynamicLayout, currentGlobalStartY, contentHeight, paddingTop, pages) - (item.baseY + item.height);
|
|
554
696
|
}
|
|
555
697
|
sortPagesByOrder(pages, orderMap);
|
|
556
698
|
removeTrailingEmptyPages(pages);
|
|
557
699
|
return pages;
|
|
558
700
|
}
|
|
701
|
+
var normalizeDynamicLayoutResult = (result) => {
|
|
702
|
+
const dynamicLayout = Array.isArray(result) ? { heights: result } : result;
|
|
703
|
+
return {
|
|
704
|
+
...dynamicLayout,
|
|
705
|
+
heights: dynamicLayout.heights.length === 0 ? [0] : dynamicLayout.heights
|
|
706
|
+
};
|
|
707
|
+
};
|
|
559
708
|
/**
|
|
560
709
|
* Process a template containing tables with dynamic heights
|
|
561
710
|
* and generate a new template with proper page breaks.
|
|
@@ -587,9 +736,9 @@ var getDynamicTemplate = async (arg) => {
|
|
|
587
736
|
basePdf,
|
|
588
737
|
options,
|
|
589
738
|
_cache
|
|
590
|
-
}).then(
|
|
739
|
+
}).then(normalizeDynamicLayoutResult);
|
|
591
740
|
}));
|
|
592
|
-
for (let j = 0; j < chunkResults.length; j++) items[i + j].
|
|
741
|
+
for (let j = 0; j < chunkResults.length; j++) items[i + j].dynamicLayout = chunkResults[j];
|
|
593
742
|
}
|
|
594
743
|
const processedPages = processDynamicPage(items, orderMap, contentHeight, paddingTop);
|
|
595
744
|
resultPages.push(...processedPages);
|
|
@@ -961,6 +1110,6 @@ var pluginRegistry = (plugins) => {
|
|
|
961
1110
|
};
|
|
962
1111
|
};
|
|
963
1112
|
//#endregion
|
|
964
|
-
export { BLANK_A4_PDF, BLANK_PDF, CUSTOM_A4_PDF, DEFAULT_FONT_NAME, MM_TO_PT_RATIO, PDFME_VERSION, PT_TO_MM_RATIO, PT_TO_PX_RATIO, ZOOM, b64toUint8Array, checkDesignerProps, checkFont, checkGenerateProps, checkInputs, checkPreviewProps, checkTemplate, checkUIOptions, checkUIProps, cloneDeep, getB64BasePdf, getDefaultFont, getDynamicTemplate, getFallbackFontName, getInputFromTemplate, isBlankPdf, isHexValid, isUrlSafeToFetch, mm2pt, pluginRegistry, pt2mm, pt2px, px2mm, replacePlaceholders };
|
|
1113
|
+
export { BLANK_A4_PDF, BLANK_PDF, CUSTOM_A4_PDF, DEFAULT_FONT_NAME, MM_TO_PT_RATIO, PDFME_VERSION, PT_TO_MM_RATIO, PT_TO_PX_RATIO, ZOOM, applyInternalLinkAnnotations, b64toUint8Array, checkDesignerProps, checkFont, checkGenerateProps, checkInputs, checkPreviewProps, checkTemplate, checkUIOptions, checkUIProps, cloneDeep, getB64BasePdf, getDefaultFont, getDynamicTemplate, getFallbackFontName, getInputFromTemplate, getInternalLinkTarget, isBlankPdf, isHexValid, isUrlSafeToFetch, mm2pt, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, pluginRegistry, pt2mm, pt2px, px2mm, registerInternalLinkAnchor, registerInternalLinkAnnotation, replacePlaceholders, resetInternalLinkAnnotations };
|
|
965
1114
|
|
|
966
1115
|
//# sourceMappingURL=index.js.map
|