@pdfme/schemas 6.2.3-dev.5 → 6.2.3-dev.7
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/{builtins-Dtp1IM7M.js → builtins-Cj3XtvrX.js} +3 -3
- package/dist/{builtins-Dtp1IM7M.js.map → builtins-Cj3XtvrX.js.map} +1 -1
- package/dist/builtins.js +1 -1
- package/dist/dynamicLayout.js +1 -1
- package/dist/{dynamicTemplate-Zqt6kNsE.js → dynamicTemplate-BJxwjEWl.js} +489 -26
- package/dist/dynamicTemplate-BJxwjEWl.js.map +1 -0
- package/dist/graphics/imagehelper.d.ts +6 -1
- package/dist/index.js +71 -239
- package/dist/index.js.map +1 -1
- package/dist/tables/classes.d.ts +5 -3
- package/dist/tables/constants.d.ts +5 -0
- package/dist/tables/imageCell.d.ts +27 -0
- package/dist/tables/types.d.ts +23 -1
- package/dist/tables.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{utils-DvBaBoME.js → utils-DU1bG5sa.js} +2 -2
- package/dist/{utils-DvBaBoME.js.map → utils-DU1bG5sa.js.map} +1 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/dynamicTemplate-Zqt6kNsE.js.map +0 -1
package/dist/tables/classes.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Font } from '@pdfme/common';
|
|
2
|
-
import type { Font as FontKitFont } from 'fontkit';
|
|
1
|
+
import { Font, type BasePdf } from '@pdfme/common';
|
|
3
2
|
import type { Styles, TableInput, Settings, Section, StylesProps } from './types.js';
|
|
4
3
|
type ContentSettings = {
|
|
5
4
|
body: Row[];
|
|
@@ -16,11 +15,13 @@ export declare class Cell {
|
|
|
16
15
|
wrappedWidth: number;
|
|
17
16
|
minReadableWidth: number;
|
|
18
17
|
minWidth: number;
|
|
18
|
+
imageContentHeight: number;
|
|
19
19
|
width: number;
|
|
20
20
|
height: number;
|
|
21
21
|
x: number;
|
|
22
22
|
y: number;
|
|
23
23
|
constructor(raw: string, styles: Styles, section: Section);
|
|
24
|
+
isImage(): boolean;
|
|
24
25
|
getContentHeight(): number;
|
|
25
26
|
padding(name: 'top' | 'bottom' | 'left' | 'right'): number;
|
|
26
27
|
}
|
|
@@ -58,7 +59,8 @@ export declare class Table {
|
|
|
58
59
|
input: TableInput;
|
|
59
60
|
content: ContentSettings;
|
|
60
61
|
font: Font;
|
|
61
|
-
|
|
62
|
+
basePdf: BasePdf;
|
|
63
|
+
_cache: Map<string | number, unknown>;
|
|
62
64
|
}): Promise<Table>;
|
|
63
65
|
getHeadHeight(): number;
|
|
64
66
|
getBodyHeight(): number;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TableImageHeightMode } from './types.js';
|
|
2
|
+
export declare const DEFAULT_TABLE_IMAGE_HEIGHT = 20;
|
|
3
|
+
export declare const DEFAULT_TABLE_IMAGE_HEIGHT_MODE: TableImageHeightMode;
|
|
4
|
+
export declare const TABLE_IMAGE_DATA_URL_PATTERN: RegExp;
|
|
5
|
+
export declare const TABLE_IMAGE_AUTO_SAFETY_MARGIN = 1;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ImageObjectPosition } from '../graphics/image.js';
|
|
2
|
+
import type { ALIGNMENT, VERTICAL_ALIGNMENT } from '../text/types.js';
|
|
3
|
+
import { type TableCellType, type TableImageHeightMode } from './types.js';
|
|
4
|
+
export type TableImageDimension = {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const isTableImageDataUrl: (value: string) => boolean;
|
|
9
|
+
export declare const resolveImageDimension: (value: string, cache: Map<string | number, unknown>) => TableImageDimension | undefined;
|
|
10
|
+
export declare const warnInvalidTableImageOnce: (value: string | null | undefined, columnIndex: number, cache: Map<string | number, unknown>) => void;
|
|
11
|
+
export declare const normalizeTableCellType: (value: unknown, columnIndex: number, cache: Map<string | number, unknown>) => TableCellType | undefined;
|
|
12
|
+
export declare const normalizeTableImageHeightMode: (value: unknown) => TableImageHeightMode | undefined;
|
|
13
|
+
export declare const normalizeTableImageHeight: (value: unknown) => number | undefined;
|
|
14
|
+
export declare const getTableImageObjectPosition: (alignment: ALIGNMENT | undefined, verticalAlignment: VERTICAL_ALIGNMENT | undefined) => ImageObjectPosition;
|
|
15
|
+
export declare const resolveFixedTableImageHeight: (imageHeight: number | undefined) => number;
|
|
16
|
+
/**
|
|
17
|
+
* Fixed height is kept for empty and invalid values so rows in the column stay aligned.
|
|
18
|
+
* Auto height is 0 unless a PNG/JPEG data URL resolves.
|
|
19
|
+
*/
|
|
20
|
+
export declare const resolveTableImageContentHeight: (arg: {
|
|
21
|
+
value: string;
|
|
22
|
+
mode: TableImageHeightMode | undefined;
|
|
23
|
+
imageHeight: number | undefined;
|
|
24
|
+
contentWidth: number;
|
|
25
|
+
columnIndex: number;
|
|
26
|
+
cache: Map<string | number, unknown>;
|
|
27
|
+
}) => number;
|
package/dist/tables/types.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { ALIGNMENT, VERTICAL_ALIGNMENT } from '../text/types.js';
|
|
2
2
|
import type { BoxDimension } from '../box.js';
|
|
3
3
|
import type { Schema } from '@pdfme/common';
|
|
4
|
+
export declare const TABLE_CELL_TYPES: readonly ['text', 'image'];
|
|
5
|
+
export type TableCellType = (typeof TABLE_CELL_TYPES)[number];
|
|
6
|
+
export declare const TABLE_IMAGE_HEIGHT_MODES: readonly ['fixed', 'auto'];
|
|
7
|
+
export type TableImageHeightMode = (typeof TABLE_IMAGE_HEIGHT_MODES)[number];
|
|
4
8
|
export type Spacing = BoxDimension;
|
|
5
9
|
type BorderInsets = Spacing;
|
|
6
10
|
type BoxDimensions = Spacing;
|
|
@@ -17,7 +21,12 @@ export interface CellStyle {
|
|
|
17
21
|
borderWidth: BoxDimensions;
|
|
18
22
|
padding: BoxDimensions;
|
|
19
23
|
}
|
|
20
|
-
export type CellSchema = Schema & CellStyle
|
|
24
|
+
export type CellSchema = Schema & CellStyle & {
|
|
25
|
+
cellType?: TableCellType;
|
|
26
|
+
imageHeightMode?: TableImageHeightMode;
|
|
27
|
+
imageHeight?: number;
|
|
28
|
+
columnIndex?: number;
|
|
29
|
+
};
|
|
21
30
|
export type TableSchema = Schema & {
|
|
22
31
|
showHead: boolean;
|
|
23
32
|
head: string[];
|
|
@@ -35,6 +44,15 @@ export type TableSchema = Schema & {
|
|
|
35
44
|
alignment?: {
|
|
36
45
|
[colIndex: number]: ALIGNMENT;
|
|
37
46
|
};
|
|
47
|
+
cellType?: {
|
|
48
|
+
[colIndex: number]: TableCellType;
|
|
49
|
+
};
|
|
50
|
+
imageHeightMode?: {
|
|
51
|
+
[colIndex: number]: TableImageHeightMode;
|
|
52
|
+
};
|
|
53
|
+
imageHeight?: {
|
|
54
|
+
[colIndex: number]: number;
|
|
55
|
+
};
|
|
38
56
|
};
|
|
39
57
|
};
|
|
40
58
|
export interface Styles {
|
|
@@ -52,6 +70,9 @@ export interface Styles {
|
|
|
52
70
|
cellWidth: number;
|
|
53
71
|
minCellHeight: number;
|
|
54
72
|
minCellWidth: number;
|
|
73
|
+
cellType?: TableCellType;
|
|
74
|
+
imageHeightMode?: TableImageHeightMode;
|
|
75
|
+
imageHeight?: number;
|
|
55
76
|
}
|
|
56
77
|
export interface TableInput {
|
|
57
78
|
settings: Settings;
|
|
@@ -68,6 +89,7 @@ export interface Settings {
|
|
|
68
89
|
margin: Spacing;
|
|
69
90
|
tableWidth: number;
|
|
70
91
|
showHead: boolean;
|
|
92
|
+
templateShowHead: boolean;
|
|
71
93
|
tableLineWidth: number;
|
|
72
94
|
tableLineColor: string;
|
|
73
95
|
}
|
package/dist/tables.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { l as getTableBodyRange, o as createTableBodySplitRange, r as TABLE_BODY_SPLIT_UNIT } from "./splitRange-B6311Noc.js";
|
|
2
|
-
import { n as getDynamicLayoutForTable, t as getDynamicHeightsForTable } from "./dynamicTemplate-
|
|
2
|
+
import { n as getDynamicLayoutForTable, t as getDynamicHeightsForTable } from "./dynamicTemplate-BJxwjEWl.js";
|
|
3
3
|
export { TABLE_BODY_SPLIT_UNIT, createTableBodySplitRange, getDynamicHeightsForTable, getDynamicLayoutForTable, getTableBodyRange };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { ALIGNMENT, DYNAMIC_FONT_SIZE_FIT, FONT_VARIANT_FALLBACK, FontVariants, FontWidthCalcValues, RichTextRun, TEXT_FORMAT, TEXT_OVERFLOW, TextSchema, VERTICAL_ALIGNMENT, } from './text/types.js';
|
|
2
2
|
export type { MultiVariableTextSchema } from './multiVariableText/types.js';
|
|
3
3
|
export type { LIST_STYLE, ListItem, ListItemLayout, ListLayout, ListSchema } from './list/types.js';
|
|
4
|
-
export type { CellSchema, CellStyle, Section, Settings, Spacing, Styles, StylesProps, TableInput, TableSchema, } from './tables/types.js';
|
|
4
|
+
export type { CellSchema, CellStyle, Section, Settings, Spacing, Styles, StylesProps, TableCellType, TableImageHeightMode, TableInput, TableSchema, } from './tables/types.js';
|
|
5
5
|
export type { BoxDimension } from './box.js';
|
|
6
6
|
export type { BarcodeSchema, BarcodeTypes } from './barcodes/types.js';
|
|
7
7
|
export type { DateSchema } from './date/types.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as getDynamicHeightsForTable$1 } from "./dynamicTemplate-
|
|
1
|
+
import { t as getDynamicHeightsForTable$1 } from "./dynamicTemplate-BJxwjEWl.js";
|
|
2
2
|
import { isHexValid, mm2pt } from "@pdfme/common";
|
|
3
3
|
import { cmyk, degrees, degreesToRadians, rgb } from "@pdfme/pdf-lib";
|
|
4
4
|
//#region src/multiVariableText/variables.ts
|
|
@@ -263,4 +263,4 @@ var createSvgStr = (icon, attrs) => {
|
|
|
263
263
|
//#endregion
|
|
264
264
|
export { createSvgStr as a, hex2RgbColor as c, rgbColorToCmykColor as d, rotatePoint as f, visitVariables as g, getVariableNames as h, createErrorElm as i, isEditable as l, countUniqueVariableNames as m, applyAlphaToOpacity as n, getDynamicHeightsForTable as o, splitHexAlpha as p, convertForPdfLayoutProps as r, hex2PrintingColor as s, addAlphaToHex as t, readFile as u };
|
|
265
265
|
|
|
266
|
-
//# sourceMappingURL=utils-
|
|
266
|
+
//# sourceMappingURL=utils-DU1bG5sa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-DvBaBoME.js","names":["_getDynamicHeightsForTable"],"sources":["../src/multiVariableText/variables.ts","../src/utils.ts"],"sourcesContent":["export type VariableMatch = {\n name: string;\n startIndex: number;\n endIndex: number;\n};\n\nexport type VariableIndices = Map<number, string>;\n\nexport const visitVariables = (content: string, visitor: (match: VariableMatch) => void): void => {\n let startIndex = -1;\n\n for (let i = 0; i < content.length; i++) {\n const char = content[i];\n\n if (char === '{') {\n // Restart from the latest opener so malformed input behaves like /{([^{}]+)}/g\n // without requiring backtracking.\n startIndex = i;\n continue;\n }\n\n if (char === '}' && startIndex !== -1) {\n const name = content.slice(startIndex + 1, i);\n if (name.length > 0) {\n visitor({ name, startIndex, endIndex: i });\n }\n startIndex = -1;\n }\n }\n};\n\nexport const getVariableIndices = (content: string): VariableIndices => {\n const indices: VariableIndices = new Map();\n\n visitVariables(content, ({ name, startIndex }) => {\n indices.set(startIndex, name);\n });\n\n return indices;\n};\n\nexport const countUniqueVariableNames = (content: string): number => {\n const variableNames = new Set<string>();\n\n visitVariables(content, ({ name }) => {\n variableNames.add(name);\n });\n\n return variableNames.size;\n};\n\nexport const getVariableNames = (content: string): string[] => {\n const variableNames: string[] = [];\n\n visitVariables(content, ({ name }) => {\n variableNames.push(name);\n });\n\n return variableNames;\n};\n","import type * as CSS from 'csstype';\nimport { cmyk, degrees, degreesToRadians, rgb, type Color, type RGB } from '@pdfme/pdf-lib';\nimport { Schema, mm2pt, Mode, isHexValid, ColorType } from '@pdfme/common';\nimport { IconNode } from 'lucide';\nimport { getDynamicHeightsForTable as _getDynamicHeightsForTable } from './tables/dynamicTemplate.js';\nexport { measureTextHeight } from './text/measure.js';\nexport { escapeInlineMarkdown } from './text/inlineMarkdown.js';\nexport { getVariableNames, visitVariables } from './multiVariableText/variables.js';\nexport const convertForPdfLayoutProps = ({\n schema,\n pageHeight,\n applyRotateTranslate = true,\n}: {\n schema: Schema;\n pageHeight: number;\n applyRotateTranslate?: boolean;\n}) => {\n const { width: mmWidth, height: mmHeight, position, rotate, opacity } = schema;\n const { x: mmX, y: mmY } = position;\n\n const rotateDegrees = rotate ? -rotate : 0;\n const width = mm2pt(mmWidth);\n const height = mm2pt(mmHeight);\n let x = mm2pt(mmX);\n // PDF coordinate system is from bottom left, UI is top left, so we need to flip the y axis\n let y = pageHeight - mm2pt(mmY) - height;\n\n if (rotateDegrees && applyRotateTranslate) {\n // If rotating we must pivot around the same point as the UI performs its rotation.\n // The UI performs rotation around the objects center point (the pivot point below),\n // pdflib rotates around the bottom left corner of the object.\n // We must therefore adjust the X and Y by rotating the bottom left corner by this pivot point.\n const pivotPoint = { x: x + width / 2, y: pageHeight - mm2pt(mmY) - height / 2 };\n const rotatedPoint = rotatePoint({ x, y }, pivotPoint, rotateDegrees);\n x = rotatedPoint.x;\n y = rotatedPoint.y;\n }\n\n return {\n position: { x, y },\n height: height,\n width: width,\n rotate: degrees(rotateDegrees),\n opacity,\n };\n};\n\nexport const rotatePoint = (\n point: { x: number; y: number },\n pivot: { x: number; y: number },\n angleDegrees: number,\n): { x: number; y: number } => {\n const angleRadians = degreesToRadians(angleDegrees);\n\n const x =\n Math.cos(angleRadians) * (point.x - pivot.x) -\n Math.sin(angleRadians) * (point.y - pivot.y) +\n pivot.x;\n const y =\n Math.sin(angleRadians) * (point.x - pivot.x) +\n Math.cos(angleRadians) * (point.y - pivot.y) +\n pivot.y;\n\n return { x, y };\n};\n\nexport const getDynamicHeightsForTable = _getDynamicHeightsForTable;\n\n// ----------------------------------------\n\nexport const addAlphaToHex = (hex: string, alphaPercentage: number) => {\n if (!/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/i.test(hex)) {\n throw new Error('Invalid HEX color code');\n }\n const alphaValue = Math.round((alphaPercentage / 100) * 255);\n let alphaHex = alphaValue.toString(16);\n if (alphaHex.length === 1) alphaHex = '0' + alphaHex;\n return hex + alphaHex;\n};\n\nexport const isEditable = (mode: Mode, schema: Schema) =>\n mode === 'designer' || (mode === 'form' && schema.readOnly !== true);\n\n// Split a '#RGBA'/'#RRGGBBAA' hex into its opaque color and alpha channel, since\n// pdf-lib colors carry no alpha; alpha must be applied as draw opacity instead.\n// Colors without an alpha channel are passed through with alpha 1. Invalid hex is\n// also passed through untouched (never split) so that downstream color validation\n// still rejects the original string instead of a salvaged color plus a NaN alpha.\nexport const splitHexAlpha = (hexColor: string): { color: string; alpha: number } => {\n if (!hexColor.startsWith('#')) return { color: hexColor, alpha: 1 };\n const hex = hexColor.slice(1);\n if (!/^(?:[0-9a-f]{4}|[0-9a-f]{8})$/i.test(hex)) return { color: hexColor, alpha: 1 };\n const rgbLength = hex.length === 4 ? 3 : 6;\n const alphaHex = hex.slice(rgbLength);\n return {\n color: `#${hex.slice(0, rgbLength)}`,\n alpha: parseInt(alphaHex.length === 1 ? alphaHex.repeat(2) : alphaHex, 16) / 255,\n };\n};\n\n// Multiply a hex color's alpha channel into a draw opacity. An alpha of 1 returns\n// the opacity untouched (including undefined) so that PDFs rendered from colors\n// without an alpha channel stay byte-identical to previous releases: pdf-lib only\n// embeds an ExtGState when the opacity is defined.\nexport const applyAlphaToOpacity = (\n opacity: number | undefined,\n alpha: number,\n): number | undefined => (alpha === 1 ? opacity : (opacity ?? 1) * alpha);\n\nconst hex2rgb = (hex: string) => {\n // Drop any alpha channel; pdf-lib colors cannot represent it.\n hex = splitHexAlpha(hex).color;\n if (hex.slice(0, 1) === '#') hex = hex.slice(1);\n if (hex.length === 3)\n hex =\n hex.slice(0, 1) +\n hex.slice(0, 1) +\n hex.slice(1, 2) +\n hex.slice(1, 2) +\n hex.slice(2, 3) +\n hex.slice(2, 3);\n\n return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => parseInt(str, 16));\n};\n\nexport const rgbColorToCmykColor = ({ red, green, blue }: RGB) => {\n const key = 1 - Math.max(red, green, blue);\n const cyan = key === 1 ? 0 : (1 - red - key) / (1 - key);\n const magenta = key === 1 ? 0 : (1 - green - key) / (1 - key);\n const yellow = key === 1 ? 0 : (1 - blue - key) / (1 - key);\n\n return cmyk(cyan, magenta, yellow, key);\n};\n\nexport const hex2RgbColor = (hexString: string | undefined) => {\n if (hexString) {\n const isValid = isHexValid(hexString);\n\n if (!isValid) {\n throw new Error(`Invalid hex color value ${hexString}`);\n }\n\n const [r, g, b] = hex2rgb(hexString);\n\n return rgb(r / 255, g / 255, b / 255);\n }\n\n return undefined;\n};\n\nconst hex2CmykColor = (hexString: string | undefined) => {\n if (hexString) {\n const isValid = isHexValid(hexString);\n\n if (!isValid) {\n throw new Error(`Invalid hex color value ${hexString}`);\n }\n\n // Alpha is not flattened here; callers apply it as draw opacity via splitHexAlpha.\n const [r, g, b] = hex2rgb(hexString).map((value) => value / 255);\n\n return rgbColorToCmykColor(rgb(r, g, b));\n }\n\n return undefined;\n};\n\nexport const hex2PrintingColor = (color?: string | Color, colorType?: ColorType) => {\n // if color is already CMYK, RGB or Grayscale, does not required to convert\n if (typeof color === 'object') return color;\n return colorType?.toLowerCase() == 'cmyk' ? hex2CmykColor(color) : hex2RgbColor(color);\n};\n\nexport const readFile = (input: File | FileList | null): Promise<string | ArrayBuffer> =>\n new Promise((resolve, reject) => {\n const fileReader = new FileReader();\n\n fileReader.onload = (e) => {\n if (e.target?.result) {\n resolve(e.target.result);\n }\n };\n\n fileReader.onerror = () => {\n reject(new Error('[@pdfme/schemas] File reading failed'));\n };\n\n let file: File | null = null;\n if (input instanceof FileList && input.length > 0) {\n file = input[0];\n } else if (input instanceof File) {\n file = input;\n }\n\n if (file) {\n fileReader.readAsDataURL(file);\n } else {\n reject(new Error('[@pdfme/schemas] No files provided'));\n }\n });\n\nexport const createErrorElm = () => {\n const container = document.createElement('div');\n const containerStyle: CSS.Properties = {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: '100%',\n height: '100%',\n };\n Object.assign(container.style, containerStyle);\n\n const span = document.createElement('span');\n const spanStyle: CSS.Properties = {\n color: 'white',\n background: 'red',\n padding: '0.25rem',\n fontSize: '12pt',\n fontWeight: 'bold',\n borderRadius: '2px',\n fontFamily: \"'Open Sans', sans-serif\",\n };\n Object.assign(span.style, spanStyle);\n\n span.textContent = 'ERROR';\n container.appendChild(span);\n\n return container;\n};\n\nexport const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): string => {\n // In lucide 0.475.0, the icon is an array of elements, not a single SVG element\n // We need to create an SVG wrapper and add the elements as children\n\n const safeTagNames = new Set([\n 'svg',\n 'circle',\n 'ellipse',\n 'g',\n 'line',\n 'path',\n 'polygon',\n 'polyline',\n 'rect',\n ]);\n const safeAttributeNames = new Set([\n 'aria-hidden',\n 'aria-label',\n 'class',\n 'clip-rule',\n 'cx',\n 'cy',\n 'd',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'focusable',\n 'height',\n 'id',\n 'opacity',\n 'points',\n 'preserveAspectRatio',\n 'r',\n 'role',\n 'rx',\n 'ry',\n 'stroke',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke-width',\n 'transform',\n 'vector-effect',\n 'viewBox',\n 'width',\n 'x',\n 'x1',\n 'x2',\n 'xmlns',\n 'xmlns:xlink',\n 'y',\n 'y1',\n 'y2',\n ]);\n const escapeHtmlAttribute = (value: string): string =>\n value\n .replaceAll('&', '&')\n .replaceAll('\"', '"')\n .replaceAll(\"'\", ''')\n .replaceAll('<', '<')\n .replaceAll('>', '>');\n const escapeHtmlText = (value: string): string =>\n value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');\n const toSafeAttributeString = (attributes: Record<string, string>): string =>\n Object.entries(attributes)\n .filter(\n ([key, value]) =>\n safeAttributeNames.has(key) &&\n value !== undefined &&\n value !== null &&\n !key.toLowerCase().startsWith('on'),\n )\n .map(([key, value]) => `${key}=\"${escapeHtmlAttribute(String(value))}\"`)\n .join(' ');\n const toSafeTagName = (tag: unknown): string => {\n const tagName = String(tag);\n if (!safeTagNames.has(tagName)) {\n throw new Error(`Invalid SVG tag name: ${tagName}`);\n }\n return tagName;\n };\n\n // Handle non-array input\n if (!Array.isArray(icon)) {\n return escapeHtmlText(String(icon));\n }\n\n // Create default SVG attributes\n const svgAttrs = {\n xmlns: 'http://www.w3.org/2000/svg',\n width: '24',\n height: '24',\n viewBox: '0 0 24 24',\n fill: 'none',\n stroke: 'currentColor',\n 'stroke-width': '2',\n 'stroke-linecap': 'round',\n 'stroke-linejoin': 'round',\n ...attrs,\n };\n const svgAttrString = toSafeAttributeString(svgAttrs);\n\n // Helper function to process a single element\n const processElement = (element: unknown): string => {\n if (!Array.isArray(element)) {\n return escapeHtmlText(String(element));\n }\n\n const [tag, attributes = {}, children = []] = element as [\n unknown,\n Record<string, string>,\n unknown[],\n ];\n const tagName = toSafeTagName(tag);\n const attrString = toSafeAttributeString(attributes);\n\n // Process children recursively\n let childrenString = '';\n\n if (Array.isArray(children) && children.length > 0) {\n childrenString = children.map((child) => processElement(child)).join('');\n }\n\n // Return properly formatted element string\n if (childrenString) {\n return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}>${childrenString}</${String(tagName)}>`;\n } else {\n // Self-closing tag for empty children\n return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}/>`;\n }\n };\n\n // Process all elements and join them\n const elementsString = Array.isArray(icon)\n ? icon.map((element) => processElement(element)).join('')\n : processElement(icon);\n\n // Return the complete SVG string\n return `<svg ${svgAttrString}>${elementsString}</svg>`;\n};\n"],"mappings":";;;;AAQA,IAAa,kBAAkB,S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AAQ,OAAO,GACxB,OAAO,eAAe,OAAO,OAAO,CAAC;EAGvC,MAAM,CAAC,KAAK,aAAa,CAAC,GAAG,WAAW,CAAC,KAAK;EAK9C,MAAM,UAAU,cAAc,GAAG;EACjC,MAAM,aAAa,sBAAsB,UAAU;EAGnD,IAAI,iBAAiB;EAErB,IAAI,MAAM,QAAQ,QAAQ,KAAK,SAAS,SAAS,GAC/C,iBAAiB,SAAS,KAAK,UAAU,eAAe,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE;EAIzE,IAAI,gBACF,OAAO,IAAI,OAAO,OAAO,IAAI,aAAa,MAAM,OAAO,UAAU,IAAI,GAAG,GAAG,eAAe,IAAI,OAAO,OAAO,EAAE;OAG9G,OAAO,IAAI,OAAO,OAAO,IAAI,aAAa,MAAM,OAAO,UAAU,IAAI,GAAG;CAE5E;CAQA,OAAO,QAAQ,cAAc,GALN,MAAM,QAAQ,IAAI,IACrC,KAAK,KAAK,YAAY,eAAe,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,IACtD,eAAe,IAAI,EAGwB;AACjD"}
|
|
1
|
+
{"version":3,"file":"utils-DU1bG5sa.js","names":["_getDynamicHeightsForTable"],"sources":["../src/multiVariableText/variables.ts","../src/utils.ts"],"sourcesContent":["export type VariableMatch = {\n name: string;\n startIndex: number;\n endIndex: number;\n};\n\nexport type VariableIndices = Map<number, string>;\n\nexport const visitVariables = (content: string, visitor: (match: VariableMatch) => void): void => {\n let startIndex = -1;\n\n for (let i = 0; i < content.length; i++) {\n const char = content[i];\n\n if (char === '{') {\n // Restart from the latest opener so malformed input behaves like /{([^{}]+)}/g\n // without requiring backtracking.\n startIndex = i;\n continue;\n }\n\n if (char === '}' && startIndex !== -1) {\n const name = content.slice(startIndex + 1, i);\n if (name.length > 0) {\n visitor({ name, startIndex, endIndex: i });\n }\n startIndex = -1;\n }\n }\n};\n\nexport const getVariableIndices = (content: string): VariableIndices => {\n const indices: VariableIndices = new Map();\n\n visitVariables(content, ({ name, startIndex }) => {\n indices.set(startIndex, name);\n });\n\n return indices;\n};\n\nexport const countUniqueVariableNames = (content: string): number => {\n const variableNames = new Set<string>();\n\n visitVariables(content, ({ name }) => {\n variableNames.add(name);\n });\n\n return variableNames.size;\n};\n\nexport const getVariableNames = (content: string): string[] => {\n const variableNames: string[] = [];\n\n visitVariables(content, ({ name }) => {\n variableNames.push(name);\n });\n\n return variableNames;\n};\n","import type * as CSS from 'csstype';\nimport { cmyk, degrees, degreesToRadians, rgb, type Color, type RGB } from '@pdfme/pdf-lib';\nimport { Schema, mm2pt, Mode, isHexValid, ColorType } from '@pdfme/common';\nimport { IconNode } from 'lucide';\nimport { getDynamicHeightsForTable as _getDynamicHeightsForTable } from './tables/dynamicTemplate.js';\nexport { measureTextHeight } from './text/measure.js';\nexport { escapeInlineMarkdown } from './text/inlineMarkdown.js';\nexport { getVariableNames, visitVariables } from './multiVariableText/variables.js';\nexport const convertForPdfLayoutProps = ({\n schema,\n pageHeight,\n applyRotateTranslate = true,\n}: {\n schema: Schema;\n pageHeight: number;\n applyRotateTranslate?: boolean;\n}) => {\n const { width: mmWidth, height: mmHeight, position, rotate, opacity } = schema;\n const { x: mmX, y: mmY } = position;\n\n const rotateDegrees = rotate ? -rotate : 0;\n const width = mm2pt(mmWidth);\n const height = mm2pt(mmHeight);\n let x = mm2pt(mmX);\n // PDF coordinate system is from bottom left, UI is top left, so we need to flip the y axis\n let y = pageHeight - mm2pt(mmY) - height;\n\n if (rotateDegrees && applyRotateTranslate) {\n // If rotating we must pivot around the same point as the UI performs its rotation.\n // The UI performs rotation around the objects center point (the pivot point below),\n // pdflib rotates around the bottom left corner of the object.\n // We must therefore adjust the X and Y by rotating the bottom left corner by this pivot point.\n const pivotPoint = { x: x + width / 2, y: pageHeight - mm2pt(mmY) - height / 2 };\n const rotatedPoint = rotatePoint({ x, y }, pivotPoint, rotateDegrees);\n x = rotatedPoint.x;\n y = rotatedPoint.y;\n }\n\n return {\n position: { x, y },\n height: height,\n width: width,\n rotate: degrees(rotateDegrees),\n opacity,\n };\n};\n\nexport const rotatePoint = (\n point: { x: number; y: number },\n pivot: { x: number; y: number },\n angleDegrees: number,\n): { x: number; y: number } => {\n const angleRadians = degreesToRadians(angleDegrees);\n\n const x =\n Math.cos(angleRadians) * (point.x - pivot.x) -\n Math.sin(angleRadians) * (point.y - pivot.y) +\n pivot.x;\n const y =\n Math.sin(angleRadians) * (point.x - pivot.x) +\n Math.cos(angleRadians) * (point.y - pivot.y) +\n pivot.y;\n\n return { x, y };\n};\n\nexport const getDynamicHeightsForTable = _getDynamicHeightsForTable;\n\n// ----------------------------------------\n\nexport const addAlphaToHex = (hex: string, alphaPercentage: number) => {\n if (!/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/i.test(hex)) {\n throw new Error('Invalid HEX color code');\n }\n const alphaValue = Math.round((alphaPercentage / 100) * 255);\n let alphaHex = alphaValue.toString(16);\n if (alphaHex.length === 1) alphaHex = '0' + alphaHex;\n return hex + alphaHex;\n};\n\nexport const isEditable = (mode: Mode, schema: Schema) =>\n mode === 'designer' || (mode === 'form' && schema.readOnly !== true);\n\n// Split a '#RGBA'/'#RRGGBBAA' hex into its opaque color and alpha channel, since\n// pdf-lib colors carry no alpha; alpha must be applied as draw opacity instead.\n// Colors without an alpha channel are passed through with alpha 1. Invalid hex is\n// also passed through untouched (never split) so that downstream color validation\n// still rejects the original string instead of a salvaged color plus a NaN alpha.\nexport const splitHexAlpha = (hexColor: string): { color: string; alpha: number } => {\n if (!hexColor.startsWith('#')) return { color: hexColor, alpha: 1 };\n const hex = hexColor.slice(1);\n if (!/^(?:[0-9a-f]{4}|[0-9a-f]{8})$/i.test(hex)) return { color: hexColor, alpha: 1 };\n const rgbLength = hex.length === 4 ? 3 : 6;\n const alphaHex = hex.slice(rgbLength);\n return {\n color: `#${hex.slice(0, rgbLength)}`,\n alpha: parseInt(alphaHex.length === 1 ? alphaHex.repeat(2) : alphaHex, 16) / 255,\n };\n};\n\n// Multiply a hex color's alpha channel into a draw opacity. An alpha of 1 returns\n// the opacity untouched (including undefined) so that PDFs rendered from colors\n// without an alpha channel stay byte-identical to previous releases: pdf-lib only\n// embeds an ExtGState when the opacity is defined.\nexport const applyAlphaToOpacity = (\n opacity: number | undefined,\n alpha: number,\n): number | undefined => (alpha === 1 ? opacity : (opacity ?? 1) * alpha);\n\nconst hex2rgb = (hex: string) => {\n // Drop any alpha channel; pdf-lib colors cannot represent it.\n hex = splitHexAlpha(hex).color;\n if (hex.slice(0, 1) === '#') hex = hex.slice(1);\n if (hex.length === 3)\n hex =\n hex.slice(0, 1) +\n hex.slice(0, 1) +\n hex.slice(1, 2) +\n hex.slice(1, 2) +\n hex.slice(2, 3) +\n hex.slice(2, 3);\n\n return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => parseInt(str, 16));\n};\n\nexport const rgbColorToCmykColor = ({ red, green, blue }: RGB) => {\n const key = 1 - Math.max(red, green, blue);\n const cyan = key === 1 ? 0 : (1 - red - key) / (1 - key);\n const magenta = key === 1 ? 0 : (1 - green - key) / (1 - key);\n const yellow = key === 1 ? 0 : (1 - blue - key) / (1 - key);\n\n return cmyk(cyan, magenta, yellow, key);\n};\n\nexport const hex2RgbColor = (hexString: string | undefined) => {\n if (hexString) {\n const isValid = isHexValid(hexString);\n\n if (!isValid) {\n throw new Error(`Invalid hex color value ${hexString}`);\n }\n\n const [r, g, b] = hex2rgb(hexString);\n\n return rgb(r / 255, g / 255, b / 255);\n }\n\n return undefined;\n};\n\nconst hex2CmykColor = (hexString: string | undefined) => {\n if (hexString) {\n const isValid = isHexValid(hexString);\n\n if (!isValid) {\n throw new Error(`Invalid hex color value ${hexString}`);\n }\n\n // Alpha is not flattened here; callers apply it as draw opacity via splitHexAlpha.\n const [r, g, b] = hex2rgb(hexString).map((value) => value / 255);\n\n return rgbColorToCmykColor(rgb(r, g, b));\n }\n\n return undefined;\n};\n\nexport const hex2PrintingColor = (color?: string | Color, colorType?: ColorType) => {\n // if color is already CMYK, RGB or Grayscale, does not required to convert\n if (typeof color === 'object') return color;\n return colorType?.toLowerCase() == 'cmyk' ? hex2CmykColor(color) : hex2RgbColor(color);\n};\n\nexport const readFile = (input: File | FileList | null): Promise<string | ArrayBuffer> =>\n new Promise((resolve, reject) => {\n const fileReader = new FileReader();\n\n fileReader.onload = (e) => {\n if (e.target?.result) {\n resolve(e.target.result);\n }\n };\n\n fileReader.onerror = () => {\n reject(new Error('[@pdfme/schemas] File reading failed'));\n };\n\n let file: File | null = null;\n if (input instanceof FileList && input.length > 0) {\n file = input[0];\n } else if (input instanceof File) {\n file = input;\n }\n\n if (file) {\n fileReader.readAsDataURL(file);\n } else {\n reject(new Error('[@pdfme/schemas] No files provided'));\n }\n });\n\nexport const createErrorElm = () => {\n const container = document.createElement('div');\n const containerStyle: CSS.Properties = {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: '100%',\n height: '100%',\n };\n Object.assign(container.style, containerStyle);\n\n const span = document.createElement('span');\n const spanStyle: CSS.Properties = {\n color: 'white',\n background: 'red',\n padding: '0.25rem',\n fontSize: '12pt',\n fontWeight: 'bold',\n borderRadius: '2px',\n fontFamily: \"'Open Sans', sans-serif\",\n };\n Object.assign(span.style, spanStyle);\n\n span.textContent = 'ERROR';\n container.appendChild(span);\n\n return container;\n};\n\nexport const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): string => {\n // In lucide 0.475.0, the icon is an array of elements, not a single SVG element\n // We need to create an SVG wrapper and add the elements as children\n\n const safeTagNames = new Set([\n 'svg',\n 'circle',\n 'ellipse',\n 'g',\n 'line',\n 'path',\n 'polygon',\n 'polyline',\n 'rect',\n ]);\n const safeAttributeNames = new Set([\n 'aria-hidden',\n 'aria-label',\n 'class',\n 'clip-rule',\n 'cx',\n 'cy',\n 'd',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'focusable',\n 'height',\n 'id',\n 'opacity',\n 'points',\n 'preserveAspectRatio',\n 'r',\n 'role',\n 'rx',\n 'ry',\n 'stroke',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke-width',\n 'transform',\n 'vector-effect',\n 'viewBox',\n 'width',\n 'x',\n 'x1',\n 'x2',\n 'xmlns',\n 'xmlns:xlink',\n 'y',\n 'y1',\n 'y2',\n ]);\n const escapeHtmlAttribute = (value: string): string =>\n value\n .replaceAll('&', '&')\n .replaceAll('\"', '"')\n .replaceAll(\"'\", ''')\n .replaceAll('<', '<')\n .replaceAll('>', '>');\n const escapeHtmlText = (value: string): string =>\n value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');\n const toSafeAttributeString = (attributes: Record<string, string>): string =>\n Object.entries(attributes)\n .filter(\n ([key, value]) =>\n safeAttributeNames.has(key) &&\n value !== undefined &&\n value !== null &&\n !key.toLowerCase().startsWith('on'),\n )\n .map(([key, value]) => `${key}=\"${escapeHtmlAttribute(String(value))}\"`)\n .join(' ');\n const toSafeTagName = (tag: unknown): string => {\n const tagName = String(tag);\n if (!safeTagNames.has(tagName)) {\n throw new Error(`Invalid SVG tag name: ${tagName}`);\n }\n return tagName;\n };\n\n // Handle non-array input\n if (!Array.isArray(icon)) {\n return escapeHtmlText(String(icon));\n }\n\n // Create default SVG attributes\n const svgAttrs = {\n xmlns: 'http://www.w3.org/2000/svg',\n width: '24',\n height: '24',\n viewBox: '0 0 24 24',\n fill: 'none',\n stroke: 'currentColor',\n 'stroke-width': '2',\n 'stroke-linecap': 'round',\n 'stroke-linejoin': 'round',\n ...attrs,\n };\n const svgAttrString = toSafeAttributeString(svgAttrs);\n\n // Helper function to process a single element\n const processElement = (element: unknown): string => {\n if (!Array.isArray(element)) {\n return escapeHtmlText(String(element));\n }\n\n const [tag, attributes = {}, children = []] = element as [\n unknown,\n Record<string, string>,\n unknown[],\n ];\n const tagName = toSafeTagName(tag);\n const attrString = toSafeAttributeString(attributes);\n\n // Process children recursively\n let childrenString = '';\n\n if (Array.isArray(children) && children.length > 0) {\n childrenString = children.map((child) => processElement(child)).join('');\n }\n\n // Return properly formatted element string\n if (childrenString) {\n return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}>${childrenString}</${String(tagName)}>`;\n } else {\n // Self-closing tag for empty children\n return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}/>`;\n }\n };\n\n // Process all elements and join them\n const elementsString = Array.isArray(icon)\n ? icon.map((element) => processElement(element)).join('')\n : processElement(icon);\n\n // Return the complete SVG string\n return `<svg ${svgAttrString}>${elementsString}</svg>`;\n};\n"],"mappings":";;;;AAQA,IAAa,kBAAkB,SAAiB,YAAkD;CAChG,IAAI,aAAa;CAEjB,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;EACvC,MAAM,OAAO,QAAQ;EAErB,IAAI,SAAS,KAAK;GAGhB,aAAa;GACb;EACF;EAEA,IAAI,SAAS,OAAO,eAAe,IAAI;GACrC,MAAM,OAAO,QAAQ,MAAM,aAAa,GAAG,CAAC;GAC5C,IAAI,KAAK,SAAS,GAChB,QAAQ;IAAE;IAAM;IAAY,UAAU;GAAE,CAAC;GAE3C,aAAa;EACf;CACF;AACF;AAYA,IAAa,4BAA4B,YAA4B;CACnE,MAAM,gCAAgB,IAAI,IAAY;CAEtC,eAAe,UAAU,EAAE,WAAW;EACpC,cAAc,IAAI,IAAI;CACxB,CAAC;CAED,OAAO,cAAc;AACvB;AAEA,IAAa,oBAAoB,YAA8B;CAC7D,MAAM,gBAA0B,CAAC;CAEjC,eAAe,UAAU,EAAE,WAAW;EACpC,cAAc,KAAK,IAAI;CACzB,CAAC;CAED,OAAO;AACT;;;ACnDA,IAAa,4BAA4B,EACvC,QACA,YACA,uBAAuB,WAKnB;CACJ,MAAM,EAAE,OAAO,SAAS,QAAQ,UAAU,UAAU,QAAQ,YAAY;CACxE,MAAM,EAAE,GAAG,KAAK,GAAG,QAAQ;CAE3B,MAAM,gBAAgB,SAAS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bColorToCmykColor, f as rotatePoint, g as visitVariables, h as getVariableNames, i as createErrorElm, l as isEditable, n as applyAlphaToOpacity, o as getDynamicHeightsForTable, p as splitHexAlpha, r as convertForPdfLayoutProps, s as hex2PrintingColor, t as addAlphaToHex, u as readFile } from "./utils-
|
|
2
|
+
import { a as createSvgStr, c as hex2RgbColor, d as rgbColorToCmykColor, f as rotatePoint, g as visitVariables, h as getVariableNames, i as createErrorElm, l as isEditable, n as applyAlphaToOpacity, o as getDynamicHeightsForTable, p as splitHexAlpha, r as convertForPdfLayoutProps, s as hex2PrintingColor, t as addAlphaToHex, u as readFile } from "./utils-DU1bG5sa.js";
|
|
3
3
|
export { addAlphaToHex, applyAlphaToOpacity, convertForPdfLayoutProps, createErrorElm, createSvgStr, escapeInlineMarkdown, getDynamicHeightsForTable, getVariableNames, hex2PrintingColor, hex2RgbColor, isEditable, measureTextHeight, readFile, rgbColorToCmykColor, rotatePoint, splitHexAlpha, visitVariables };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdfme/schemas",
|
|
3
|
-
"version": "6.2.3-dev.
|
|
3
|
+
"version": "6.2.3-dev.7",
|
|
4
4
|
"description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pdf",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicTemplate-Zqt6kNsE.js","names":[],"sources":["../src/tables/classes.ts","../src/tables/tableHelper.ts","../src/constants.ts","../src/tables/helper.ts","../src/tables/dynamicTemplate.ts"],"sourcesContent":["import { Font, mm2pt, pt2mm } from '@pdfme/common';\nimport type { Font as FontKitFont } from 'fontkit';\nimport { getBoxContentArea, getBoxVerticalInset, type BoxStyleSchema } from '../box.js';\nimport { splitTextToSize, getFontKitFont, widthOfTextAtSize } from '../text/helper.js';\nimport type { Styles, TableInput, Settings, Section, StylesProps } from './types.js';\n\ntype ContentSettings = { body: Row[]; head: Row[]; columns: Column[] };\n\nexport class Cell {\n raw: string;\n text: string[];\n styles: Styles;\n section: Section;\n contentHeight = 0;\n contentWidth = 0;\n wrappedWidth = 0;\n minReadableWidth = 0;\n minWidth = 0;\n\n width = 0;\n height = 0;\n x = 0;\n y = 0;\n\n constructor(raw: string, styles: Styles, section: Section) {\n this.styles = styles;\n this.section = section;\n this.raw = raw;\n const splitRegex = /\\r\\n|\\r|\\n/g;\n this.text = raw.split(splitRegex);\n }\n\n getContentHeight() {\n const lineCount = Array.isArray(this.text) ? this.text.length : 1;\n const lineHeight = pt2mm(this.styles.fontSize) * this.styles.lineHeight;\n const height = lineCount * lineHeight + getBoxVerticalInset(getCellBoxStyle(this));\n return Math.max(height, this.styles.minCellHeight);\n }\n\n padding(name: 'top' | 'bottom' | 'left' | 'right') {\n return this.styles.cellPadding[name];\n }\n}\n\nconst getCellBoxStyle = (cell: Cell): BoxStyleSchema => ({\n padding: cell.styles.cellPadding,\n borderWidth: cell.styles.lineWidth,\n});\n\nexport class Column {\n index: number;\n wrappedWidth = 0;\n minReadableWidth = 0;\n minWidth = 0;\n width = 0;\n\n constructor(index: number) {\n this.index = index;\n }\n\n getMaxCustomCellWidth(table: Table) {\n let max = 0;\n for (const row of table.allRows()) {\n const cell: Cell = row.cells[this.index];\n max = Math.max(max, cell.styles.cellWidth);\n }\n return max;\n }\n}\n\nexport class Row {\n readonly raw: string[];\n readonly index: number;\n readonly section: Section;\n readonly cells: { [key: string]: Cell };\n\n height = 0;\n\n constructor(raw: string[], index: number, section: Section, cells: { [key: string]: Cell }) {\n this.raw = raw;\n this.index = index;\n this.section = section;\n this.cells = cells;\n }\n\n getMaxCellHeight(columns: Column[]) {\n return columns.reduce((acc, column) => Math.max(acc, this.cells[column.index]?.height || 0), 0);\n }\n\n getMinimumRowHeight(columns: Column[]) {\n return columns.reduce((acc: number, column: Column) => {\n const cell = this.cells[column.index];\n if (!cell) return 0;\n const vPadding = cell.padding('top') + cell.padding('bottom');\n const oneRowHeight = vPadding + cell.styles.lineHeight;\n return oneRowHeight > acc ? oneRowHeight : acc;\n }, 0);\n }\n}\n\nexport class Table {\n readonly settings: Settings;\n readonly styles: StylesProps;\n\n readonly columns: Column[];\n readonly head: Row[];\n readonly body: Row[];\n\n constructor(input: TableInput, content: ContentSettings) {\n this.settings = input.settings;\n this.styles = input.styles;\n\n this.columns = content.columns;\n this.head = content.head;\n this.body = content.body;\n }\n\n static async create(arg: {\n input: TableInput;\n content: ContentSettings;\n font: Font;\n _cache: Map<string | number, FontKitFont>;\n }) {\n const { input, content, font, _cache } = arg;\n const table = new Table(input, content);\n\n await calculateWidths({ table, font, _cache });\n\n return table;\n }\n\n getHeadHeight() {\n return this.head.reduce((acc, row) => acc + row.getMaxCellHeight(this.columns), 0);\n }\n\n getBodyHeight() {\n return this.body.reduce((acc, row) => acc + row.getMaxCellHeight(this.columns), 0);\n }\n\n allRows() {\n return this.head.concat(this.body);\n }\n\n getWidth() {\n return this.settings.tableWidth;\n }\n\n getHeight() {\n return (this.settings.showHead ? this.getHeadHeight() : 0) + this.getBodyHeight();\n }\n}\n\nasync function calculateWidths(arg: {\n table: Table;\n font: Font;\n _cache: Map<string | number, FontKitFont>;\n}) {\n const { table, font, _cache } = arg;\n\n const getFontKitFontByFontName = (fontName: string | undefined) =>\n getFontKitFont(fontName, font, _cache);\n\n await calculate(table, getFontKitFontByFontName);\n\n const resizableColumns: Column[] = [];\n let initialTableWidth = 0;\n\n table.columns.forEach((column) => {\n const customWidth = column.getMaxCustomCellWidth(table);\n if (customWidth) {\n // final column width\n column.width = customWidth;\n } else {\n // initial column width (will be resized)\n column.width = column.wrappedWidth;\n resizableColumns.push(column);\n }\n initialTableWidth += column.width;\n });\n\n // width difference that needs to be distributed\n let resizeWidth = table.getWidth() - initialTableWidth;\n\n // first resize attempt: with respect to minReadableWidth and minWidth\n if (resizeWidth) {\n resizeWidth = resizeColumns(resizableColumns, resizeWidth, (column) =>\n Math.max(column.minReadableWidth, column.minWidth),\n );\n }\n\n // second resize attempt: ignore minReadableWidth but respect minWidth\n if (resizeWidth) {\n resizeWidth = resizeColumns(resizableColumns, resizeWidth, (column) => column.minWidth);\n }\n\n resizeWidth = Math.abs(resizeWidth);\n\n applyColSpans(table);\n await fitContent(table, getFontKitFontByFontName);\n applyRowSpans(table);\n}\n\nfunction applyRowSpans(table: Table) {\n const rowSpanCells: {\n [key: string]: { cell: Cell; left: number; row: Row };\n } = {};\n let colRowSpansLeft = 1;\n const all = table.allRows();\n for (let rowIndex = 0; rowIndex < all.length; rowIndex++) {\n const row = all[rowIndex];\n for (const column of table.columns) {\n const data = rowSpanCells[column.index];\n if (colRowSpansLeft > 1) {\n colRowSpansLeft--;\n delete row.cells[column.index];\n } else if (data) {\n data.cell.height += row.height;\n colRowSpansLeft = 1;\n delete row.cells[column.index];\n data.left--;\n if (data.left <= 1) {\n delete rowSpanCells[column.index];\n }\n } else {\n const cell = row.cells[column.index];\n if (!cell) {\n continue;\n }\n cell.height = row.height;\n }\n }\n }\n}\n\nfunction applyColSpans(table: Table) {\n const all = table.allRows();\n for (let rowIndex = 0; rowIndex < all.length; rowIndex++) {\n const row = all[rowIndex];\n\n let colSpanCell = null;\n let combinedColSpanWidth = 0;\n let colSpansLeft = 0;\n for (let columnIndex = 0; columnIndex < table.columns.length; columnIndex++) {\n const column = table.columns[columnIndex];\n\n // Width and colspan\n colSpansLeft -= 1;\n if (colSpansLeft > 1 && table.columns[columnIndex + 1]) {\n combinedColSpanWidth += column.width;\n delete row.cells[column.index];\n } else if (colSpanCell) {\n const cell: Cell = colSpanCell;\n delete row.cells[column.index];\n colSpanCell = null;\n cell.width = column.width + combinedColSpanWidth;\n } else {\n const cell = row.cells[column.index];\n if (!cell) continue;\n colSpansLeft = 1;\n combinedColSpanWidth = 0;\n cell.width = column.width + combinedColSpanWidth;\n }\n }\n }\n}\n\nasync function fitContent(\n table: Table,\n getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>,\n) {\n const rowSpanHeight = { count: 0, height: 0 };\n for (const row of table.allRows()) {\n for (const column of table.columns) {\n const cell: Cell = row.cells[column.index];\n if (!cell) continue;\n\n const fontKitFont = await getFontKitFontByFontName(cell.styles.fontName);\n const contentArea = getBoxContentArea({\n position: { x: 0, y: 0 },\n width: cell.width,\n height: cell.height,\n ...getCellBoxStyle(cell),\n });\n cell.text = splitTextToSize({\n value: cell.raw,\n characterSpacing: cell.styles.characterSpacing,\n boxWidthInPt: mm2pt(contentArea.width),\n fontSize: cell.styles.fontSize,\n fontKitFont,\n });\n\n cell.contentHeight = cell.getContentHeight();\n\n let realContentHeight = cell.contentHeight;\n if (rowSpanHeight && rowSpanHeight.count > 0) {\n if (rowSpanHeight.height > realContentHeight) {\n realContentHeight = rowSpanHeight.height;\n }\n }\n if (realContentHeight > row.height) {\n row.height = realContentHeight;\n }\n }\n rowSpanHeight.count--;\n }\n}\n\nfunction resizeColumns(\n columns: Column[],\n resizeWidth: number,\n getMinWidth: (column: Column) => number,\n) {\n const initialResizeWidth = resizeWidth;\n const sumWrappedWidth = columns.reduce((acc, column) => acc + column.wrappedWidth, 0);\n\n for (let i = 0; i < columns.length; i++) {\n const column = columns[i];\n\n const ratio = column.wrappedWidth / sumWrappedWidth;\n const suggestedChange = initialResizeWidth * ratio;\n const suggestedWidth = column.width + suggestedChange;\n\n const minWidth = getMinWidth(column);\n const newWidth = suggestedWidth < minWidth ? minWidth : suggestedWidth;\n\n resizeWidth -= newWidth - column.width;\n column.width = newWidth;\n }\n\n resizeWidth = Math.round(resizeWidth * 1e10) / 1e10;\n\n // Run the resizer again if there's remaining width needs\n // to be distributed and there're columns that can be resized\n if (resizeWidth) {\n const resizableColumns = columns.filter((column) => {\n return resizeWidth < 0\n ? column.width > getMinWidth(column) // check if column can shrink\n : true; // check if column can grow\n });\n\n if (resizableColumns.length) {\n resizeWidth = resizeColumns(resizableColumns, resizeWidth, getMinWidth);\n }\n }\n\n return resizeWidth;\n}\n\nasync function calculate(\n table: Table,\n getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>,\n) {\n for (const row of table.allRows()) {\n for (const column of table.columns) {\n const cell = row.cells[column.index];\n if (!cell) continue;\n\n const hPadding = cell.padding('right') + cell.padding('left');\n const fontKitFont = await getFontKitFontByFontName(cell.styles.fontName);\n\n cell.contentWidth = getStringWidth(cell, fontKitFont) + hPadding;\n\n const longestWordWidth = getStringWidth(\n Object.assign(cell, { text: cell.text.join(' ').split(/\\s+/) }),\n fontKitFont,\n );\n cell.minReadableWidth = longestWordWidth + hPadding;\n\n cell.minWidth = cell.styles.cellWidth;\n cell.wrappedWidth = cell.styles.cellWidth;\n }\n }\n\n for (const row of table.allRows()) {\n for (const column of table.columns) {\n const cell = row.cells[column.index];\n\n // For now we ignore the minWidth and wrappedWidth of colspan cells when calculating colspan widths.\n // Could probably be improved upon however.\n if (cell) {\n column.wrappedWidth = Math.max(column.wrappedWidth, cell.wrappedWidth);\n column.minWidth = Math.max(column.minWidth, cell.minWidth);\n column.minReadableWidth = Math.max(column.minReadableWidth, cell.minReadableWidth);\n } else {\n // Respect cellWidth set in columnStyles even if there is no cells for this column\n // or if the column only have colspan cells. Since the width of colspan cells\n // does not affect the width of columns, setting columnStyles cellWidth enables the\n // user to at least do it manually.\n\n // Note that this is not perfect for now since for example row and table styles are\n // not accounted for\n const columnStyles = table.styles.columnStyles[column.index] || {};\n const cellWidth = columnStyles.cellWidth || columnStyles.minCellWidth;\n if (cellWidth) {\n column.minWidth = cellWidth;\n column.wrappedWidth = cellWidth;\n }\n }\n }\n }\n}\n\nfunction getStringWidth(cell: Cell, fontKitFont: FontKitFont) {\n const text = cell.text;\n const textArr: string[] = Array.isArray(text) ? text : [text];\n const fontSize = cell.styles.fontSize;\n const characterSpacing = cell.styles.characterSpacing;\n const widestLineWidth = textArr\n .map((text) => widthOfTextAtSize(text, fontKitFont, fontSize, characterSpacing))\n .reduce((a, b) => Math.max(a, b), 0);\n\n return widestLineWidth;\n}\n","import {\n Schema,\n isBlankPdf,\n BasePdf,\n CommonOptions,\n getDefaultFont,\n getFallbackFontName,\n cloneDeep,\n} from '@pdfme/common';\nimport type { Font as FontKitFont } from 'fontkit';\nimport type {\n TableSchema,\n CellStyle,\n Styles,\n Spacing,\n TableInput,\n StylesProps,\n Section,\n} from './types.js';\nimport { Cell, Column, Row, Table } from './classes.js';\nimport { createBoxDimension } from '../box.js';\nimport { getTableBodyRange } from '../splitRange.js';\n\ntype StyleProp = 'styles' | 'headStyles' | 'bodyStyles' | 'alternateRowStyles' | 'columnStyles';\n\ninterface CreateTableArgs {\n schema: Schema;\n basePdf: BasePdf;\n options: CommonOptions;\n _cache: Map<string | number, unknown>;\n}\n\ninterface UserOptions {\n startY: number;\n tableWidth: number;\n margin: Spacing;\n showHead: boolean;\n tableLineWidth?: number;\n tableLineColor?: string;\n head?: string[][];\n body?: string[][];\n\n styles?: Partial<Styles>;\n bodyStyles?: Partial<Styles>;\n headStyles?: Partial<Styles>;\n alternateRowStyles?: Partial<Styles>;\n columnStyles?: {\n [key: string]: Partial<Styles>;\n };\n}\n\nfunction parseSection(\n sectionName: Section,\n sectionRows: string[][],\n columns: Column[],\n styleProps: StylesProps,\n fallbackFontName: string,\n): Row[] {\n const rowSpansLeftForColumn: { [key: string]: { left: number; times: number } } = {};\n const result = sectionRows.map((rawRow, rowIndex) => {\n let skippedRowForRowSpans = 0;\n const cells: { [key: string]: Cell } = {};\n\n let colSpansAdded = 0;\n let columnSpansLeft = 0;\n for (const column of columns) {\n if (\n rowSpansLeftForColumn[column.index] == null ||\n rowSpansLeftForColumn[column.index].left === 0\n ) {\n if (columnSpansLeft === 0) {\n let rawCell;\n if (Array.isArray(rawRow)) {\n rawCell = rawRow[column.index - colSpansAdded - skippedRowForRowSpans];\n } else {\n rawCell = rawRow[column.index];\n }\n const styles = cellStyles(sectionName, column, rowIndex, styleProps, fallbackFontName);\n const cell = new Cell(rawCell, styles, sectionName);\n cells[column.index] = cell;\n\n columnSpansLeft = 0;\n rowSpansLeftForColumn[column.index] = {\n left: 0,\n times: columnSpansLeft,\n };\n } else {\n columnSpansLeft--;\n colSpansAdded++;\n }\n } else {\n rowSpansLeftForColumn[column.index].left--;\n columnSpansLeft = rowSpansLeftForColumn[column.index].times;\n skippedRowForRowSpans++;\n }\n }\n return new Row(rawRow, rowIndex, sectionName, cells);\n });\n return result;\n}\n\nfunction parseContent4Table(input: TableInput, fallbackFontName: string) {\n const content = input.content;\n const columns = content.columns.map((index) => new Column(index));\n const styles = input.styles;\n return {\n columns,\n head: parseSection('head', content.head, columns, styles, fallbackFontName),\n body: parseSection('body', content.body, columns, styles, fallbackFontName),\n };\n}\n\nfunction cellStyles(\n sectionName: Section,\n column: Column,\n rowIndex: number,\n styles: StylesProps,\n fallbackFontName: string,\n) {\n let sectionStyles;\n if (sectionName === 'head') {\n sectionStyles = styles.headStyles;\n } else if (sectionName === 'body') {\n sectionStyles = styles.bodyStyles;\n }\n const otherStyles = Object.assign({}, styles.styles, sectionStyles);\n\n const colStyles = styles.columnStyles[column.index] || {};\n\n const rowStyles =\n sectionName === 'body' && rowIndex % 2 === 0\n ? Object.assign({}, styles.alternateRowStyles)\n : {};\n\n const defaultStyle = {\n fontName: fallbackFontName,\n backgroundColor: '',\n textColor: '#000000',\n lineHeight: 1,\n characterSpacing: 0,\n alignment: 'left',\n verticalAlignment: 'middle',\n fontSize: 10,\n cellPadding: createBoxDimension(5),\n lineColor: '#000000',\n lineWidth: createBoxDimension(0),\n minCellHeight: 0,\n minCellWidth: 0,\n };\n return Object.assign(defaultStyle, otherStyles, rowStyles, colStyles) as Styles;\n}\n\nfunction mapCellStyle(style: CellStyle): Partial<Styles> {\n const mapping: Partial<Styles> = {\n fontName: style.fontName,\n alignment: style.alignment,\n verticalAlignment: style.verticalAlignment,\n fontSize: style.fontSize,\n lineHeight: style.lineHeight,\n characterSpacing: style.characterSpacing,\n backgroundColor: style.backgroundColor,\n // ---\n textColor: style.fontColor,\n lineColor: style.borderColor,\n lineWidth: style.borderWidth,\n cellPadding: style.padding,\n };\n return Object.fromEntries(\n Object.entries(mapping).filter(([, value]) => value !== undefined),\n ) as Partial<Styles>;\n}\n\nfunction getTableOptions(schema: TableSchema, body: string[][]): UserOptions {\n const columnStylesWidth = schema.headWidthPercentages.reduce(\n (acc, cur, i) => ({ ...acc, [i]: { cellWidth: schema.width * (cur / 100) } }),\n {} as Record<number, Partial<Styles>>,\n );\n\n const columnStylesAlignment = Object.entries(schema.columnStyles.alignment || {}).reduce(\n (acc, [key, value]) => ({ ...acc, [key]: { alignment: value } }),\n {} as Record<number, Partial<Styles>>,\n );\n\n const allKeys = new Set([\n ...Object.keys(columnStylesWidth).map(Number),\n ...Object.keys(columnStylesAlignment).map(Number),\n ]);\n const columnStyles = Array.from(allKeys).reduce(\n (acc, key) => {\n const widthStyle = columnStylesWidth[key] || {};\n const alignmentStyle = columnStylesAlignment[key] || {};\n return { ...acc, [key]: { ...widthStyle, ...alignmentStyle } };\n },\n {} as Record<number, Partial<Styles>>,\n );\n\n return {\n head: [schema.head],\n body,\n showHead: schema.showHead,\n startY: schema.position.y,\n tableWidth: schema.width,\n tableLineColor: schema.tableStyles.borderColor,\n tableLineWidth: schema.tableStyles.borderWidth,\n headStyles: mapCellStyle(schema.headStyles),\n bodyStyles: mapCellStyle(schema.bodyStyles),\n alternateRowStyles: { backgroundColor: schema.bodyStyles.alternateBackgroundColor },\n columnStyles,\n margin: { top: 0, right: 0, left: schema.position.x, bottom: 0 },\n };\n}\n\nfunction parseStyles(cInput: UserOptions) {\n const styleOptions: StylesProps = {\n styles: {},\n headStyles: {},\n bodyStyles: {},\n alternateRowStyles: {},\n columnStyles: {},\n };\n for (const prop of Object.keys(styleOptions) as StyleProp[]) {\n if (prop === 'columnStyles') {\n const current = cInput[prop];\n styleOptions.columnStyles = Object.assign({}, current);\n } else {\n const allOptions = [cInput];\n const styles = allOptions.map((opts) => opts[prop] || {});\n styleOptions[prop] = Object.assign({}, styles[0], styles[1], styles[2]);\n }\n }\n return styleOptions;\n}\n\nfunction parseContent4Input(options: UserOptions) {\n const head = options.head || [];\n const body = options.body || [];\n const columns = (head[0] || body[0] || []).map((_, index) => index);\n return { columns, head, body };\n}\n\nfunction parseInput(schema: TableSchema, body: string[][]): TableInput {\n const options = getTableOptions(schema, body);\n const styles = parseStyles(options);\n const settings = {\n startY: options.startY,\n margin: options.margin,\n tableWidth: options.tableWidth,\n showHead: options.showHead,\n tableLineWidth: options.tableLineWidth ?? 0,\n tableLineColor: options.tableLineColor ?? '',\n };\n\n const content = parseContent4Input(options);\n\n return { content, styles, settings };\n}\n\nexport function createSingleTable(body: string[][], args: CreateTableArgs) {\n const { options, _cache, basePdf } = args;\n if (!isBlankPdf(basePdf)) {\n console.warn(\n '[@pdfme/schema/table]' +\n 'When specifying a custom PDF for basePdf, ' +\n 'you cannot use features such as page breaks or re-layout of other elements.' +\n 'To utilize these features, please define basePdf as follows:\\n' +\n '{ width: number; height: number; padding: [number, number, number, number]; }',\n );\n }\n\n const schema = cloneDeep(args.schema) as TableSchema;\n const { start } = getTableBodyRange(schema) || { start: 0 };\n if (start % 2 === 1) {\n const alternateBackgroundColor = schema.bodyStyles.alternateBackgroundColor;\n schema.bodyStyles.alternateBackgroundColor = schema.bodyStyles.backgroundColor;\n schema.bodyStyles.backgroundColor = alternateBackgroundColor;\n }\n schema.showHead =\n schema.showHead === false ? false : !schema.__isSplit || schema.repeatHead === true;\n\n const input = parseInput(schema, body);\n\n const font = options.font || getDefaultFont();\n\n const fallbackFontName = getFallbackFontName(font);\n\n const content = parseContent4Table(input, fallbackFontName);\n\n return Table.create({\n input,\n content,\n font,\n _cache: _cache as unknown as Map<string | number, FontKitFont>,\n });\n}\n","export const DEFAULT_OPACITY = 1;\n// Matches isHexValid in @pdfme/common: 3/4/6/8-digit hex, where 4/8-digit carry alpha.\nexport const HEX_COLOR_PATTERN = '^#(?:[A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$';\n// Barcode bar/text colors are handed to bwip-js, which has no alpha support (it reads\n// 8-digit hex as CMYK and throws on 4-digit hex), so those fields stay 6-digit only.\nexport const OPAQUE_HEX_COLOR_PATTERN = '^#(?:[A-Fa-f0-9]{6})$';\n","import {\n DEFAULT_ALIGNMENT,\n DEFAULT_FONT_SIZE,\n DEFAULT_LINE_HEIGHT,\n DEFAULT_CHARACTER_SPACING,\n DEFAULT_FONT_COLOR,\n ALIGN_RIGHT,\n ALIGN_CENTER,\n ALIGN_LEFT,\n VERTICAL_ALIGN_TOP,\n VERTICAL_ALIGN_MIDDLE,\n VERTICAL_ALIGN_BOTTOM,\n} from '../text/constants.js';\nimport { HEX_COLOR_PATTERN } from '../constants.js';\nimport type { TableSchema } from './types.js';\nimport { getTableBodyRange } from '../splitRange.js';\nimport type { DynamicLayoutRange } from '@pdfme/common';\nimport { createBoxDimension, getBoxDimensionPropPanelSchema } from '../box.js';\n\nexport const getDefaultCellStyles = () => ({\n fontName: undefined,\n alignment: DEFAULT_ALIGNMENT,\n verticalAlignment: VERTICAL_ALIGN_MIDDLE,\n fontSize: DEFAULT_FONT_SIZE,\n lineHeight: DEFAULT_LINE_HEIGHT,\n characterSpacing: DEFAULT_CHARACTER_SPACING,\n fontColor: DEFAULT_FONT_COLOR,\n backgroundColor: '',\n borderColor: '#888888',\n borderWidth: createBoxDimension(0.1),\n padding: createBoxDimension(5),\n});\n\nexport const getCellPropPanelSchema = (arg: {\n i18n: (key: string) => string;\n fallbackFontName: string;\n fontNames: string[];\n isBody?: boolean;\n}) => {\n const { i18n, fallbackFontName, fontNames, isBody } = arg;\n\n return {\n fontName: {\n title: i18n('schemas.text.fontName'),\n type: 'string',\n widget: 'select',\n default: fallbackFontName,\n placeholder: fallbackFontName,\n props: { options: fontNames.map((name) => ({ label: name, value: name })) },\n span: 12,\n },\n fontSize: {\n title: i18n('schemas.text.size'),\n type: 'number',\n widget: 'inputNumber',\n props: { min: 0 },\n span: 6,\n },\n characterSpacing: {\n title: i18n('schemas.text.spacing'),\n type: 'number',\n widget: 'inputNumber',\n props: { min: 0 },\n span: 6,\n },\n alignment: {\n title: i18n('schemas.text.textAlign'),\n type: 'string',\n widget: 'select',\n props: {\n options: [\n { label: i18n('schemas.left'), value: ALIGN_LEFT },\n { label: i18n('schemas.center'), value: ALIGN_CENTER },\n { label: i18n('schemas.right'), value: ALIGN_RIGHT },\n ],\n },\n span: 8,\n },\n verticalAlignment: {\n title: i18n('schemas.text.verticalAlign'),\n type: 'string',\n widget: 'select',\n props: {\n options: [\n { label: i18n('schemas.top'), value: VERTICAL_ALIGN_TOP },\n { label: i18n('schemas.middle'), value: VERTICAL_ALIGN_MIDDLE },\n { label: i18n('schemas.bottom'), value: VERTICAL_ALIGN_BOTTOM },\n ],\n },\n span: 8,\n },\n lineHeight: {\n title: i18n('schemas.text.lineHeight'),\n type: 'number',\n widget: 'inputNumber',\n props: { step: 0.1, min: 0 },\n span: 8,\n },\n fontColor: {\n title: i18n('schemas.textColor'),\n type: 'string',\n widget: 'color',\n rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],\n },\n borderColor: {\n title: i18n('schemas.borderColor'),\n type: 'string',\n widget: 'color',\n rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],\n },\n backgroundColor: {\n title: i18n('schemas.backgroundColor'),\n type: 'string',\n widget: 'color',\n rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],\n },\n ...(isBody\n ? {\n alternateBackgroundColor: {\n title: i18n('schemas.table.alternateBackgroundColor'),\n type: 'string',\n widget: 'color',\n rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],\n },\n }\n : {}),\n '-': { type: 'void', widget: 'Divider' },\n borderWidth: {\n title: i18n('schemas.borderWidth'),\n type: 'object',\n widget: 'lineTitle',\n span: 24,\n properties: getBoxDimensionPropPanelSchema(0.1),\n },\n '--': { type: 'void', widget: 'Divider' },\n padding: {\n title: i18n('schemas.padding'),\n type: 'object',\n widget: 'lineTitle',\n span: 24,\n properties: getBoxDimensionPropPanelSchema(),\n },\n };\n};\n\nexport const getColumnStylesPropPanelSchema = ({\n head,\n i18n,\n}: {\n head: string[];\n i18n: (key: string) => string;\n}) => ({\n alignment: {\n type: 'object',\n widget: 'lineTitle',\n title: i18n('schemas.text.textAlign'),\n column: 3,\n properties: head.reduce(\n (acc, cur, i) =>\n Object.assign(acc, {\n [i]: {\n title: cur || 'Column ' + String(i + 1),\n type: 'string',\n widget: 'select',\n props: {\n options: [\n { label: i18n('schemas.left'), value: ALIGN_LEFT },\n { label: i18n('schemas.center'), value: ALIGN_CENTER },\n { label: i18n('schemas.right'), value: ALIGN_RIGHT },\n ],\n },\n },\n }),\n {},\n ),\n },\n});\n\nexport const getBody = (value: string | string[][]): string[][] => {\n if (typeof value === 'string') {\n return JSON.parse(value || '[]') as string[][];\n }\n return value || [];\n};\n\nexport const getBodyWithRange = (value: string | string[][], range?: DynamicLayoutRange) => {\n const body = getBody(value);\n if (!range) return body;\n return body.slice(range.start, range.end);\n};\n\nexport const getBodyWithSchemaRange = (\n value: string | string[][],\n schema: TableSchema,\n range = getTableBodyRange(schema),\n) => getBodyWithRange(value, range);\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n const prototype: unknown = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\n// Column indexes are canonical decimal keys (\"0\", \"1\", \"10\"), not \"01\" or \"1.5\".\nconst columnIndexFromKey = (key: string): number | undefined => {\n if (!/^(0|[1-9]\\d*)$/.test(key)) return undefined;\n const index = Number(key);\n return Number.isSafeInteger(index) ? index : undefined;\n};\n\n// Treat a value as a per-column map only when every key is a column index.\n// A map that mixes in any non-numeric key is left unchanged.\nconst isColumnIndexMap = (value: unknown): value is Record<string, unknown> => {\n if (!isPlainObject(value)) return false;\n return Object.keys(value).every((key) => columnIndexFromKey(key) !== undefined);\n};\n\nconst remapColumnIndexMap = (\n columnMap: Record<string, unknown>,\n removedIndex: number,\n): Record<string, unknown> => {\n const remapped: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(columnMap)) {\n const columnIndex = columnIndexFromKey(key);\n if (columnIndex === undefined || columnIndex === removedIndex) continue;\n const nextIndex = columnIndex > removedIndex ? columnIndex - 1 : columnIndex;\n remapped[nextIndex] = value;\n }\n return remapped;\n};\n\n// Per-column style maps are keyed by column index. Every map on columnStyles\n// — including keys this version does not define, such as fontName or image\n// cell settings — must drop the removed column and close the gap. Values that\n// are not column-index maps are preserved unchanged.\nexport const remapColumnStylesOnRemove = (\n columnStyles: TableSchema['columnStyles'] | null | undefined,\n removedIndex: number,\n): TableSchema['columnStyles'] => {\n if (columnStyles == null) return {};\n const source = columnStyles as Record<string, unknown>;\n const next: Record<string, unknown> = {};\n for (const [styleKey, styleValue] of Object.entries(source)) {\n next[styleKey] = isColumnIndexMap(styleValue)\n ? remapColumnIndexMap(styleValue, removedIndex)\n : styleValue;\n }\n return next as TableSchema['columnStyles'];\n};\n","import {\n Schema,\n BasePdf,\n BlankPdf,\n CommonOptions,\n DynamicLayoutArgs,\n DynamicLayoutResult,\n isBlankPdf,\n} from '@pdfme/common';\nimport { createSingleTable } from './tableHelper.js';\nimport { getBodyWithRange, getBody } from './helper.js';\nimport { TableSchema } from './types.js';\nimport { createTableBodySplitRange, getTableBodyRange } from '../splitRange.js';\n\nexport const getDynamicHeightsForTable = async (\n value: string,\n args: {\n schema: Schema;\n basePdf: BasePdf;\n options: CommonOptions;\n _cache: Map<string | number, unknown>;\n },\n): Promise<number[]> => {\n if (args.schema.type !== 'table') return Promise.resolve([args.schema.height]);\n const schema = args.schema as TableSchema;\n const bodyRange = getTableBodyRange(schema);\n const body = bodyRange?.start === 0 ? getBody(value) : getBodyWithRange(value, bodyRange);\n const table = await createSingleTable(body, args);\n\n const baseHeights = schema.showHead\n ? table.allRows().map((row) => row.height)\n : [0].concat(table.body.map((row) => row.height));\n\n const headerHeight = schema.showHead ? table.getHeadHeight() : 0;\n const shouldRepeatHeader = schema.repeatHead && isBlankPdf(args.basePdf) && headerHeight > 0;\n\n if (!shouldRepeatHeader) {\n return baseHeights;\n }\n\n const basePdf = args.basePdf as BlankPdf;\n const [paddingTop, , paddingBottom] = basePdf.padding;\n const pageContentHeight = basePdf.height - paddingTop - paddingBottom;\n const getPageStartY = (pageIndex: number) => pageIndex * pageContentHeight + paddingTop;\n\n const initialPageIndex = Math.max(\n 0,\n Math.floor((schema.position.y - paddingTop) / pageContentHeight),\n );\n const headRowCount = schema.showHead ? table.head.length : 0;\n const SAFETY_MARGIN = 0.5;\n\n let currentPageIndex = initialPageIndex;\n let currentPageY = schema.position.y;\n let rowsOnCurrentPage = 0;\n\n const result: number[] = [];\n\n for (let i = 0; i < baseHeights.length; i++) {\n const isBodyRow = i >= headRowCount;\n const rowHeight = baseHeights[i];\n\n while (true) {\n const currentPageStartY = getPageStartY(currentPageIndex);\n const remainingHeight = currentPageStartY + pageContentHeight - currentPageY;\n const needsHeader =\n isBodyRow && rowsOnCurrentPage === 0 && currentPageIndex > initialPageIndex;\n const totalRowHeight = rowHeight + (needsHeader ? headerHeight : 0);\n\n if (totalRowHeight > remainingHeight - SAFETY_MARGIN) {\n if (rowsOnCurrentPage === 0 && Math.abs(currentPageY - currentPageStartY) < SAFETY_MARGIN) {\n result.push(totalRowHeight);\n currentPageY += totalRowHeight;\n rowsOnCurrentPage++;\n break;\n }\n currentPageIndex++;\n currentPageY = getPageStartY(currentPageIndex);\n rowsOnCurrentPage = 0;\n continue;\n }\n\n result.push(totalRowHeight);\n currentPageY += totalRowHeight;\n rowsOnCurrentPage++;\n\n if (currentPageY >= currentPageStartY + pageContentHeight - SAFETY_MARGIN) {\n currentPageIndex++;\n currentPageY = getPageStartY(currentPageIndex);\n rowsOnCurrentPage = 0;\n }\n break;\n }\n }\n\n return result;\n};\n\nexport const getDynamicLayoutForTable = async (\n value: string,\n args: DynamicLayoutArgs,\n): Promise<DynamicLayoutResult> => {\n const heights = await getDynamicHeightsForTable(value, args);\n\n return {\n heights,\n avoidFirstUnitOnly: true,\n patchSplitSchema: ({ start, end, isSplit }) => {\n const range = {\n start: start === 0 ? 0 : start - 1,\n end: end - 1,\n };\n return {\n __splitRange: createTableBodySplitRange(range.start, range.end),\n __isSplit: isSplit,\n };\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAa,OAAb,MAAkB;CAgBhB,YAAY,KAAa,QAAgB,SAAkB;EAf3D,gBAAA,MAAA,OAAA,KAAA,CAAA;EACA,gBAAA,MAAA,QAAA,KAAA,CAAA;EACA,gBAAA,MAAA,UAAA,KAAA,CAAA;EACA,gBAAA,MAAA,WAAA,KAAA,CAAA;EACA,gBAAA,MAAA,iBAAgB,CAAA;EAChB,gBAAA,MAAA,gBAAe,CAAA;EACf,gBAAA,MAAA,gBAAe,CAAA;EACf,gBAAA,MAAA,oBAAmB,CAAA;EACnB,gBAAA,MAAA,YAAW,CAAA;EAEX,gBAAA,MAAA,SAAQ,CAAA;EACR,gBAAA,MAAA,UAAS,CAAA;EACT,gBAAA,MAAA,KAAI,CAAA;EACJ,gBAAA,MAAA,KAAI,CAAA;EAGF,KAAK,SAAS;EACd,KAAK,UAAU;EACf,KAAK,MAAM;EACX,MAAM,aAAa;EACnB,KAAK,OAAO,IAAI,MAAM,UAAU;CAClC;CAEA,mBAAmB;EAGjB,MAAM,UAFY,MAAM,QAAQ,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,MAC7C,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,OAAO,cACrB,oBAAoB,gBAAgB,IAAI,CAAC;EACjF,OAAO,KAAK,IAAI,QAAQ,KAAK,OAAO,aAAa;CACnD;CAEA,QAAQ,MAA2C;EACjD,OAAO,KAAK,OAAO,YAAY;CACjC;AACF;AAEA,IAAM,mBAAmB,UAAgC;CACvD,SAAS,KAAK,OAAO;CAC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