@pdfme/common 6.1.13-dev.4 → 6.1.13-dev.46

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.
@@ -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.
@@ -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) => Uint8Array<ArrayBuffer>;
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
@@ -105,6 +105,7 @@ var Lang = z.enum([
105
105
  "ko",
106
106
  "ar",
107
107
  "th",
108
+ "tr",
108
109
  "pl",
109
110
  "it",
110
111
  "de",
@@ -941,6 +942,21 @@ var evaluatePlaceholders = (arg) => {
941
942
  }
942
943
  return resultContent;
943
944
  };
945
+ /**
946
+ * Resolve a read-only schema's render value.
947
+ * Text `content` is an expression template. MVT `content` is a variable JSON
948
+ * map and must not go through {@link replacePlaceholders}. Other types (table,
949
+ * image, …) keep the previous generate/UI behavior of evaluating expressions.
950
+ */
951
+ var resolveReadOnlyContent = (arg) => {
952
+ const content = arg.schema.content || "";
953
+ if (arg.schema.type === "multiVariableText") return content;
954
+ return replacePlaceholders({
955
+ content,
956
+ variables: arg.variables,
957
+ schemas: arg.schemas
958
+ });
959
+ };
944
960
  var replacePlaceholders = (arg) => {
945
961
  const { content, variables, schemas } = arg;
946
962
  if (!content || typeof content !== "string" || !content.includes("{") || !content.includes("}")) return content;
@@ -970,10 +986,23 @@ var replacePlaceholders = (arg) => {
970
986
  var EPSILON = .01;
971
987
  /** Calculate the content height of a page (drawable area excluding padding) */
972
988
  var getContentHeight = (basePdf) => basePdf.height - basePdf.padding[0] - basePdf.padding[2];
989
+ /**
990
+ * Resolve a readOnly table body.
991
+ * Uses input[schema.name] when present (array or JSON string) and never runs
992
+ * replacePlaceholders. Falls back to schema.content (Designer sample).
993
+ */
994
+ var getReadOnlyTableValue = (schema, input) => {
995
+ if (input && Object.prototype.hasOwnProperty.call(input, schema.name)) {
996
+ const value = input[schema.name];
997
+ if (value !== void 0 && value !== null) return typeof value === "string" ? value : JSON.stringify(value);
998
+ }
999
+ return schema.content || "";
1000
+ };
973
1001
  /** Get the input value for a schema */
974
1002
  var getSchemaValue = (schema, input, schemas) => {
975
1003
  if (!schema.readOnly) return input?.[schema.name] || "";
976
- if (schema.type !== "text" && schema.type !== "multiVariableText") return schema.content || "";
1004
+ if (schema.type === "table") return getReadOnlyTableValue(schema, input);
1005
+ if (schema.type !== "text") return schema.content || "";
977
1006
  return replacePlaceholders({
978
1007
  content: schema.content || "",
979
1008
  variables: input,
@@ -1212,6 +1241,6 @@ var pluginRegistry = (plugins) => {
1212
1241
  };
1213
1242
  };
1214
1243
  //#endregion
1215
- 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 };
1244
+ 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 };
1216
1245
 
1217
1246
  //# sourceMappingURL=index.js.map