@pdfme/common 6.1.13-dev.8 → 6.2.0-dev.13
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 +8 -0
- package/dist/expression.d.ts +12 -1
- package/dist/helper.d.ts +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.js +44 -3
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +39 -15
- package/dist/types.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +3 -2
|
@@ -11,6 +11,14 @@ interface ModifyTemplateForDynamicTableArg {
|
|
|
11
11
|
_cache: Map<string | number, unknown>;
|
|
12
12
|
}) => Promise<DynamicLayoutCallbackResult>;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve a readOnly table body.
|
|
16
|
+
* Uses input[schema.name] when present (array or JSON string) and never runs
|
|
17
|
+
* replacePlaceholders. Falls back to schema.content (Designer sample).
|
|
18
|
+
*/
|
|
19
|
+
export declare const getReadOnlyTableValue: (schema: Schema, input?: Record<string, unknown>) => string;
|
|
20
|
+
/** Get the input value for a schema */
|
|
21
|
+
export declare const getSchemaValue: (schema: Schema, input: Record<string, string>, schemas: Schema[][]) => string;
|
|
14
22
|
/**
|
|
15
23
|
* Process a template containing tables with dynamic heights
|
|
16
24
|
* and generate a new template with proper page breaks.
|
package/dist/expression.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import type { SchemaPageArray } from './types.js';
|
|
1
|
+
import type { Schema, SchemaPageArray } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a read-only schema's render value.
|
|
4
|
+
* Text `content` is an expression template. MVT `content` is a variable JSON
|
|
5
|
+
* map and must not go through {@link replacePlaceholders}. Other types (table,
|
|
6
|
+
* image, …) keep the previous generate/UI behavior of evaluating expressions.
|
|
7
|
+
*/
|
|
8
|
+
export declare const resolveReadOnlyContent: (arg: {
|
|
9
|
+
schema: Schema;
|
|
10
|
+
variables: Record<string, unknown>;
|
|
11
|
+
schemas: SchemaPageArray;
|
|
12
|
+
}) => string;
|
|
2
13
|
export declare const replacePlaceholders: (arg: {
|
|
3
14
|
content: string;
|
|
4
15
|
variables: Record<string, unknown>;
|
package/dist/helper.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PDFDocument, PDFPage } from '@pdfme/pdf-lib';
|
|
2
|
-
import { Template, Font, BasePdf, Plugins, BlankPdf } from './types.js';
|
|
2
|
+
import { Template, Font, BasePdf, Plugins, BlankPdf, PdfBytes } from './types.js';
|
|
3
3
|
export declare const cloneDeep: <T>(value: T) => T;
|
|
4
4
|
export declare const getFallbackFontName: (font: Font) => string;
|
|
5
5
|
export declare const getDefaultFont: () => Font;
|
|
@@ -48,7 +48,7 @@ export declare const applyInternalLinkAnnotations: (arg: {
|
|
|
48
48
|
}) => void;
|
|
49
49
|
export declare const getB64BasePdf: (customPdf: ArrayBuffer | Uint8Array | string) => Promise<string>;
|
|
50
50
|
export declare const isBlankPdf: (basePdf: BasePdf) => basePdf is BlankPdf;
|
|
51
|
-
export declare const b64toUint8Array: (base64: string) =>
|
|
51
|
+
export declare const b64toUint8Array: (base64: string) => PdfBytes;
|
|
52
52
|
export declare const checkFont: (arg: {
|
|
53
53
|
font: Font;
|
|
54
54
|
template: Template;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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, DynamicLayoutRange, DynamicLayoutSplitRange, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, DynamicLayoutArgs, DynamicLayoutCallbackResult, DynamicLayoutPatchArgs, DynamicLayoutResult, GetDynamicLayout } from './types.js';
|
|
3
|
+
import type { ChangeSchemaItem, ChangeSchemas, SchemaPageArray, PropPanel, PropPanelSchema, PropPanelWidgetProps, PDFRenderProps, Mode, UIRenderProps, Plugin, Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, DynamicLayoutRange, DynamicLayoutSplitRange, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, DynamicLayoutArgs, DynamicLayoutCallbackResult, DynamicLayoutPatchArgs, DynamicLayoutResult, GetDynamicLayout, PdfBytes } from './types.js';
|
|
4
4
|
import type { PdfLinkAnnotationRect } from './helper.js';
|
|
5
5
|
import type { PageOrientation, PageSize, PageSizePreset } from './pageSize.js';
|
|
6
6
|
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';
|
|
7
7
|
import { PAGE_SIZE_PRESETS, detectPaperSize, resolvePageSize } from './pageSize.js';
|
|
8
|
-
import { getDynamicTemplate } from './dynamicTemplate.js';
|
|
8
|
+
import { getDynamicTemplate, getReadOnlyTableValue, getSchemaValue } from './dynamicTemplate.js';
|
|
9
9
|
import { createDynamicLayoutSplitRange, getDynamicLayoutSplitRange } from './splitRange.js';
|
|
10
|
-
import { replacePlaceholders } from './expression.js';
|
|
10
|
+
import { replacePlaceholders, resolveReadOnlyContent } from './expression.js';
|
|
11
11
|
import { pluginRegistry } from './pluginRegistry.js';
|
|
12
|
-
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, PAGE_SIZE_PRESETS, detectPaperSize, resolvePageSize, createDynamicLayoutSplitRange, getDynamicLayoutSplitRange, };
|
|
13
|
-
export type { Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, DynamicLayoutRange, DynamicLayoutSplitRange, 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, PageOrientation, PageSize, PageSizePreset, };
|
|
12
|
+
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, getReadOnlyTableValue, getSchemaValue, replacePlaceholders, resolveReadOnlyContent, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, pluginRegistry, isUrlSafeToFetch, getInternalLinkTarget, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnchor, registerInternalLinkAnnotation, resetInternalLinkAnnotations, applyInternalLinkAnnotations, PAGE_SIZE_PRESETS, detectPaperSize, resolvePageSize, createDynamicLayoutSplitRange, getDynamicLayoutSplitRange, };
|
|
13
|
+
export type { Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, DynamicLayoutRange, DynamicLayoutSplitRange, 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, PageOrientation, PageSize, PageSizePreset, PdfBytes, };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Buffer } from "buffer";
|
|
|
3
3
|
import { PDFName } from "@pdfme/pdf-lib";
|
|
4
4
|
import * as acorn from "acorn";
|
|
5
5
|
//#region src/version.ts
|
|
6
|
-
var PDFME_VERSION = "6.
|
|
6
|
+
var PDFME_VERSION = "6.2.0";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/pageSize.ts
|
|
9
9
|
var PAGE_SIZE_PRESETS = {
|
|
@@ -164,6 +164,19 @@ z.object({
|
|
|
164
164
|
"schemas.middle": z.string(),
|
|
165
165
|
"schemas.bottom": z.string(),
|
|
166
166
|
"schemas.padding": z.string(),
|
|
167
|
+
"schemas.image.objectFit": z.string(),
|
|
168
|
+
"schemas.image.fit.contain": z.string(),
|
|
169
|
+
"schemas.image.fit.cover": z.string(),
|
|
170
|
+
"schemas.image.objectPosition": z.string(),
|
|
171
|
+
"schemas.image.position.left.top": z.string(),
|
|
172
|
+
"schemas.image.position.center.top": z.string(),
|
|
173
|
+
"schemas.image.position.right.top": z.string(),
|
|
174
|
+
"schemas.image.position.left.center": z.string(),
|
|
175
|
+
"schemas.image.position.center.center": z.string(),
|
|
176
|
+
"schemas.image.position.right.center": z.string(),
|
|
177
|
+
"schemas.image.position.left.bottom": z.string(),
|
|
178
|
+
"schemas.image.position.center.bottom": z.string(),
|
|
179
|
+
"schemas.image.position.right.bottom": z.string(),
|
|
167
180
|
"schemas.text.fontName": z.string(),
|
|
168
181
|
"schemas.text.size": z.string(),
|
|
169
182
|
"schemas.text.spacing": z.string(),
|
|
@@ -942,6 +955,21 @@ var evaluatePlaceholders = (arg) => {
|
|
|
942
955
|
}
|
|
943
956
|
return resultContent;
|
|
944
957
|
};
|
|
958
|
+
/**
|
|
959
|
+
* Resolve a read-only schema's render value.
|
|
960
|
+
* Text `content` is an expression template. MVT `content` is a variable JSON
|
|
961
|
+
* map and must not go through {@link replacePlaceholders}. Other types (table,
|
|
962
|
+
* image, …) keep the previous generate/UI behavior of evaluating expressions.
|
|
963
|
+
*/
|
|
964
|
+
var resolveReadOnlyContent = (arg) => {
|
|
965
|
+
const content = arg.schema.content || "";
|
|
966
|
+
if (arg.schema.type === "multiVariableText") return content;
|
|
967
|
+
return replacePlaceholders({
|
|
968
|
+
content,
|
|
969
|
+
variables: arg.variables,
|
|
970
|
+
schemas: arg.schemas
|
|
971
|
+
});
|
|
972
|
+
};
|
|
945
973
|
var replacePlaceholders = (arg) => {
|
|
946
974
|
const { content, variables, schemas } = arg;
|
|
947
975
|
if (!content || typeof content !== "string" || !content.includes("{") || !content.includes("}")) return content;
|
|
@@ -971,10 +999,23 @@ var replacePlaceholders = (arg) => {
|
|
|
971
999
|
var EPSILON = .01;
|
|
972
1000
|
/** Calculate the content height of a page (drawable area excluding padding) */
|
|
973
1001
|
var getContentHeight = (basePdf) => basePdf.height - basePdf.padding[0] - basePdf.padding[2];
|
|
1002
|
+
/**
|
|
1003
|
+
* Resolve a readOnly table body.
|
|
1004
|
+
* Uses input[schema.name] when present (array or JSON string) and never runs
|
|
1005
|
+
* replacePlaceholders. Falls back to schema.content (Designer sample).
|
|
1006
|
+
*/
|
|
1007
|
+
var getReadOnlyTableValue = (schema, input) => {
|
|
1008
|
+
if (input && Object.prototype.hasOwnProperty.call(input, schema.name)) {
|
|
1009
|
+
const value = input[schema.name];
|
|
1010
|
+
if (value !== void 0 && value !== null) return typeof value === "string" ? value : JSON.stringify(value);
|
|
1011
|
+
}
|
|
1012
|
+
return schema.content || "";
|
|
1013
|
+
};
|
|
974
1014
|
/** Get the input value for a schema */
|
|
975
1015
|
var getSchemaValue = (schema, input, schemas) => {
|
|
976
1016
|
if (!schema.readOnly) return input?.[schema.name] || "";
|
|
977
|
-
if (schema.type
|
|
1017
|
+
if (schema.type === "table") return getReadOnlyTableValue(schema, input);
|
|
1018
|
+
if (schema.type !== "text") return schema.content || "";
|
|
978
1019
|
return replacePlaceholders({
|
|
979
1020
|
content: schema.content || "",
|
|
980
1021
|
variables: input,
|
|
@@ -1213,6 +1254,6 @@ var pluginRegistry = (plugins) => {
|
|
|
1213
1254
|
};
|
|
1214
1255
|
};
|
|
1215
1256
|
//#endregion
|
|
1216
|
-
export { BLANK_A4_PDF, BLANK_PDF, CUSTOM_A4_PDF, DEFAULT_FONT_NAME, MM_TO_PT_RATIO, PAGE_SIZE_PRESETS, PDFME_VERSION, PT_TO_MM_RATIO, PT_TO_PX_RATIO, ZOOM, applyInternalLinkAnnotations, b64toUint8Array, checkDesignerProps, checkFont, checkGenerateProps, checkInputs, checkPreviewProps, checkTemplate, checkUIOptions, checkUIProps, cloneDeep, createDynamicLayoutSplitRange, detectPaperSize, getB64BasePdf, getDefaultFont, getDynamicLayoutSplitRange, getDynamicTemplate, getFallbackFontName, getInputFromTemplate, getInternalLinkTarget, isBlankPdf, isHexValid, isUrlSafeToFetch, mm2pt, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, pluginRegistry, pt2mm, pt2px, px2mm, registerInternalLinkAnchor, registerInternalLinkAnnotation, replacePlaceholders, resetInternalLinkAnnotations, resolvePageSize };
|
|
1257
|
+
export { BLANK_A4_PDF, BLANK_PDF, CUSTOM_A4_PDF, DEFAULT_FONT_NAME, MM_TO_PT_RATIO, PAGE_SIZE_PRESETS, PDFME_VERSION, PT_TO_MM_RATIO, PT_TO_PX_RATIO, ZOOM, applyInternalLinkAnnotations, b64toUint8Array, checkDesignerProps, checkFont, checkGenerateProps, checkInputs, checkPreviewProps, checkTemplate, checkUIOptions, checkUIProps, cloneDeep, createDynamicLayoutSplitRange, detectPaperSize, getB64BasePdf, getDefaultFont, getDynamicLayoutSplitRange, getDynamicTemplate, getFallbackFontName, getInputFromTemplate, getInternalLinkTarget, getReadOnlyTableValue, getSchemaValue, isBlankPdf, isHexValid, isUrlSafeToFetch, mm2pt, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, pluginRegistry, pt2mm, pt2px, px2mm, registerInternalLinkAnchor, registerInternalLinkAnnotation, replacePlaceholders, resetInternalLinkAnnotations, resolvePageSize, resolveReadOnlyContent };
|
|
1217
1258
|
|
|
1218
1259
|
//# sourceMappingURL=index.js.map
|