@pdfme/schemas 6.2.0 → 6.2.1-dev.18

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamicTemplate-BecnZ8Uf.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","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,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c,0BAA0B,MAAM,OAAO,MAAM,GAAG;IAC9D,WAAW;GACb;EACF;CACF;AACF"}
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { D as getBoxContentArea, E as createBoxDimension, L as CODE_BACKGROUND_COLOR, V as DEFAULT_FONT_COLOR, X as PLACEHOLDER_FONT_COLOR, Z as SYNTHETIC_BOLD_CSS_TEXT_SHADOW, a as createListItemSplitRange, c as getListItemRange, g as getFontKitFont, i as TEXT_LINE_SPLIT_UNIT, it as VERTICAL_ALIGN_MIDDLE, l as getTableBodyRange, n as LIST_ITEM_SPLIT_UNIT, o as createTableBodySplitRange, r as TABLE_BODY_SPLIT_UNIT, s as createTextLineSplitRange, t as BUILT_IN_DYNAMIC_LAYOUT_SPLIT_UNITS, u as getTextLineRange, z as DEFAULT_ALIGNMENT } from "./splitRange-B6311Noc.js";
2
2
  import { a as measureTextLines, f as resolveFontVariant, h as parseInlineMarkdown, u as isInlineMarkdownTextSchema } from "./measure-BarlRI1L.js";
3
- import { a as mapVerticalAlignToFlex, c as Formatter, d as embedAndGetFont, i as makeElementPlainTextContentEditable, l as getExtraFormatterSchema, n as textSchema, o as uiRender$4, r as buildStyledTextContainer, s as propPanel$3, t as builtInPlugins, u as pdfRender$4 } from "./builtins-C-2wyB_3.js";
4
- import { a as getCellPropPanelSchema, c as HEX_COLOR_PATTERN, i as getBodyWithSchemaRange, l as createSingleTable, n as getDynamicLayoutForTable, o as getColumnStylesPropPanelSchema, r as getBody, s as getDefaultCellStyles, t as getDynamicHeightsForTable } from "./dynamicTemplate-DkTVIMNr.js";
5
- import { c as isEditable, d as rotatePoint, f as countUniqueVariableNames, i as createSvgStr, l as readFile, m as visitVariables, n as convertForPdfLayoutProps, o as hex2PrintingColor, p as getVariableNames, r as createErrorElm, t as addAlphaToHex, u as rgbColorToCmykColor } from "./utils-CPYF2FY_.js";
3
+ import { a as mapVerticalAlignToFlex, c as Formatter, d as embedAndGetFont, i as makeElementPlainTextContentEditable, l as getExtraFormatterSchema, n as textSchema, o as uiRender$4, r as buildStyledTextContainer, s as propPanel$3, t as builtInPlugins, u as pdfRender$4 } from "./builtins-BID2DSHc.js";
4
+ import { a as getCellPropPanelSchema, c as HEX_COLOR_PATTERN, i as getBodyWithSchemaRange, l as OPAQUE_HEX_COLOR_PATTERN, n as getDynamicLayoutForTable, o as getColumnStylesPropPanelSchema, r as getBody, s as getDefaultCellStyles, t as getDynamicHeightsForTable, u as createSingleTable } from "./dynamicTemplate-BecnZ8Uf.js";
5
+ import { a as createSvgStr, d as rgbColorToCmykColor, f as rotatePoint, g as visitVariables, h as getVariableNames, i as createErrorElm, l as isEditable, m as countUniqueVariableNames, n as applyAlphaToOpacity, p as splitHexAlpha, r as convertForPdfLayoutProps, s as hex2PrintingColor, t as addAlphaToHex, u as readFile } from "./utils-DUdv_Vvk.js";
6
6
  import { a as normalizeListItems, c as LIST_STYLE_BULLET, i as normalizeListItemEntries, l as LIST_STYLE_ORDERED, n as calculateListLayout, o as serializeListItems, s as DEFAULT_LIST_STYLE, t as getDynamicLayoutForList } from "./dynamicTemplate-CcnCXHfM.js";
7
7
  import { i as validateVariables, n as substituteVariables, r as substituteVariablesAsInlineMarkdownLiterals, t as resolveReadOnlyMultiVariableText } from "./helper-BR4_UZA5.js";
8
8
  import "./tables.js";
9
9
  import "./lists.js";
10
- import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, getInternalLinkTarget, mm2pt, normalizeLinkHref, px2mm } from "@pdfme/common";
10
+ import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, getInternalLinkTarget, isHexValid, mm2pt, normalizeLinkHref, px2mm } from "@pdfme/common";
11
11
  import { Buffer as Buffer$1 } from "buffer";
12
12
  import { popGraphicsState, pushGraphicsState, rotateDegrees, translate } from "@pdfme/pdf-lib";
13
13
  import { Barcode, Calendar, CalendarClock, ChevronDown, Circle, CircleDot, Clock, Image, List, Minus, QrCode, Route, Square, SquareCheck, Table, Type } from "lucide";
@@ -674,13 +674,15 @@ var shape = {
674
674
  applyRotateTranslate: false
675
675
  });
676
676
  const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
677
+ const { color: fillHex, alpha: fillAlpha } = splitHexAlpha(schema.color ?? "");
678
+ const { color: borderHex, alpha: borderAlpha } = splitHexAlpha(schema.borderColor ?? "");
677
679
  const drawOptions = {
678
680
  rotate,
679
681
  borderWidth,
680
- borderColor: hex2PrintingColor(schema.borderColor, colorType),
681
- color: hex2PrintingColor(schema.color, colorType),
682
- opacity,
683
- borderOpacity: opacity
682
+ borderColor: hex2PrintingColor(borderHex, colorType),
683
+ color: hex2PrintingColor(fillHex, colorType),
684
+ opacity: applyAlphaToOpacity(opacity, fillAlpha),
685
+ borderOpacity: applyAlphaToOpacity(opacity, borderAlpha)
684
686
  };
685
687
  if (schema.type === "ellipse") page.drawEllipse({
686
688
  x: x4Ellipse + width / 2,
@@ -721,7 +723,6 @@ var shape = {
721
723
  title: i18n("schemas.borderColor"),
722
724
  type: "string",
723
725
  widget: "color",
724
- props: { disabledAlpha: true },
725
726
  rules: [{
726
727
  pattern: HEX_COLOR_PATTERN,
727
728
  message: i18n("validation.hexColor")
@@ -732,7 +733,6 @@ var shape = {
732
733
  title: i18n("schemas.color"),
733
734
  type: "string",
734
735
  widget: "color",
735
- props: { disabledAlpha: true },
736
736
  rules: [{
737
737
  pattern: HEX_COLOR_PATTERN,
738
738
  message: i18n("validation.hexColor")
@@ -2455,9 +2455,21 @@ var validateBarcodeInput = (type, input) => {
2455
2455
  */
2456
2456
  var barCodeType2Bcid = (type) => type === "nw7" ? "rationalizedCodabar" : type;
2457
2457
  /**
2458
- * Strip hash from the beginning of HTML hex color codes for the bwip.js lib
2458
+ * Strip hash from the beginning of HTML hex color codes for the bwip.js lib.
2459
+ * Any '#RGBA'/'#RRGGBBAA' alpha channel is dropped first (rendered opaque, like
2460
+ * AcroForm colors): bwip-js has no alpha support — it reads 8-digit hex as CMYK
2461
+ * and throws on 4-digit hex. Hash-less colors pass through untouched because
2462
+ * bwip-js natively treats those as RRGGBB/CCMMYYKK.
2463
+ */
2464
+ var mapHexColorForBwipJsLib = (color, fallback) => {
2465
+ const hex = color || fallback;
2466
+ return hex ? splitHexAlpha(hex).color.replace("#", "") : "000000";
2467
+ };
2468
+ /**
2469
+ * Barcode colors historically accept bwip-js style hex without a leading '#';
2470
+ * CSS and pdfme's color utils require the '#', so add it when missing.
2459
2471
  */
2460
- var mapHexColorForBwipJsLib = (color, fallback) => color ? color.replace("#", "") : fallback ? fallback.replace("#", "") : "000000";
2472
+ var ensureHexColorHash = (color) => color && !color.startsWith("#") && isHexValid(`#${color}`) ? `#${color}` : color;
2461
2473
  var getBwipJsRenderer = () => bwipjs;
2462
2474
  var getDocument = () => globalThis.document;
2463
2475
  var getOffscreenCanvasCtor = () => globalThis.OffscreenCanvas;
@@ -2532,7 +2544,7 @@ var createBarCode = async (arg) => {
2532
2544
  //#endregion
2533
2545
  //#region src/barcodes/pdfRender.ts
2534
2546
  var getBarcodeCacheKey = (schema, value) => {
2535
- return `svg:${schema.type}:${schema.width}:${schema.height}:${schema.backgroundColor}:${schema.barColor}:${schema.textColor}:${schema.includetext}:${value}`;
2547
+ return `svg:${schema.type}:${schema.width}:${schema.height}:${schema.barColor}:${schema.textColor}:${schema.includetext}:${value}`;
2536
2548
  };
2537
2549
  var addSvgOpacity = (svg, opacity) => {
2538
2550
  return opacity === void 0 ? svg : svg.replace(/<svg\b/, `<svg opacity="${opacity}"`);
@@ -2551,9 +2563,11 @@ var pdfRender$1 = async (arg) => {
2551
2563
  if (!svg) {
2552
2564
  svg = createBarCodeSvg({
2553
2565
  ...schema,
2566
+ backgroundColor: void 0,
2554
2567
  type: schema.type,
2555
2568
  input: value
2556
2569
  });
2570
+ svg = svg.replace(/<svg\b/, "<svg preserveAspectRatio=\"none\"");
2557
2571
  _cache.set(inputBarcodeCacheKey, svg);
2558
2572
  }
2559
2573
  const pageHeight = page.getHeight();
@@ -2569,6 +2583,19 @@ var pdfRender$1 = async (arg) => {
2569
2583
  const rotate = schema.rotate ? -schema.rotate : 0;
2570
2584
  if (rotate) page.pushOperators(pushGraphicsState(), translate(pivot.x, pivot.y), rotateDegrees(rotate), translate(-pivot.x, -pivot.y));
2571
2585
  try {
2586
+ const backgroundHex = ensureHexColorHash(schema.backgroundColor);
2587
+ if (backgroundHex) {
2588
+ const { color: backgroundColorHex, alpha } = splitHexAlpha(backgroundHex);
2589
+ const backgroundColor = alpha > 0 ? hex2PrintingColor(backgroundColorHex, options.colorType) : void 0;
2590
+ if (backgroundColor) page.drawRectangle({
2591
+ x,
2592
+ y,
2593
+ width,
2594
+ height,
2595
+ color: backgroundColor,
2596
+ opacity: applyAlphaToOpacity(opacity, alpha)
2597
+ });
2598
+ }
2572
2599
  await page.drawSvg(addSvgOpacity(svg, opacity), {
2573
2600
  x,
2574
2601
  y: y + height,
@@ -2754,7 +2781,7 @@ var getPropPanelByBarcodeType = (barcodeType) => {
2754
2781
  widget: "color",
2755
2782
  props: { disabledAlpha: true },
2756
2783
  rules: [{
2757
- pattern: HEX_COLOR_PATTERN,
2784
+ pattern: OPAQUE_HEX_COLOR_PATTERN,
2758
2785
  message: i18n("validation.hexColor")
2759
2786
  }]
2760
2787
  },
@@ -2762,7 +2789,6 @@ var getPropPanelByBarcodeType = (barcodeType) => {
2762
2789
  title: i18n("schemas.bgColor"),
2763
2790
  type: "string",
2764
2791
  widget: "color",
2765
- props: { disabledAlpha: true },
2766
2792
  rules: [{
2767
2793
  pattern: HEX_COLOR_PATTERN,
2768
2794
  message: i18n("validation.hexColor")
@@ -2773,7 +2799,11 @@ var getPropPanelByBarcodeType = (barcodeType) => {
2773
2799
  title: i18n("schemas.textColor"),
2774
2800
  type: "string",
2775
2801
  widget: "color",
2776
- props: { disabledAlpha: true }
2802
+ props: { disabledAlpha: true },
2803
+ rules: [{
2804
+ pattern: OPAQUE_HEX_COLOR_PATTERN,
2805
+ message: i18n("validation.hexColor")
2806
+ }]
2777
2807
  },
2778
2808
  includetext: {
2779
2809
  title: i18n("schemas.barcodes.includetext"),
@@ -2800,6 +2830,7 @@ var blobToDataURL = (blob) => new Promise((resolve, reject) => {
2800
2830
  var createBarcodeImage = async (schema, value) => {
2801
2831
  const imageBuf = await createBarCode({
2802
2832
  ...schema,
2833
+ backgroundColor: void 0,
2803
2834
  input: value
2804
2835
  });
2805
2836
  return await blobToDataURL(new Blob([new Uint8Array(imageBuf)], { type: "image/png" }));
@@ -2823,7 +2854,8 @@ var uiRender$1 = async (arg) => {
2823
2854
  display: "flex",
2824
2855
  alignItems: "center",
2825
2856
  justifyContent: "center",
2826
- fontFamily: "'Open Sans', sans-serif"
2857
+ fontFamily: "'Open Sans', sans-serif",
2858
+ backgroundColor: ensureHexColorHash(schema.backgroundColor) || "transparent"
2827
2859
  };
2828
2860
  Object.assign(container.style, containerStyle);
2829
2861
  rootElement.appendChild(container);
@@ -2898,6 +2930,7 @@ var lineSchema = {
2898
2930
  x: x + width / 2,
2899
2931
  y: y + height / 2
2900
2932
  };
2933
+ const { color: lineHex, alpha } = splitHexAlpha(schema.color ?? DEFAULT_LINE_COLOR);
2901
2934
  page.drawLine({
2902
2935
  start: rotatePoint({
2903
2936
  x,
@@ -2908,8 +2941,8 @@ var lineSchema = {
2908
2941
  y: y + height / 2
2909
2942
  }, pivot, rotate.angle),
2910
2943
  thickness: height,
2911
- color: hex2PrintingColor(schema.color ?? DEFAULT_LINE_COLOR, colorType),
2912
- opacity
2944
+ color: hex2PrintingColor(lineHex, colorType),
2945
+ opacity: applyAlphaToOpacity(opacity, alpha)
2913
2946
  });
2914
2947
  },
2915
2948
  ui: (arg) => {
@@ -2943,7 +2976,6 @@ var lineSchema = {
2943
2976
  title: i18n("schemas.color"),
2944
2977
  type: "string",
2945
2978
  widget: "color",
2946
- props: { disabledAlpha: true },
2947
2979
  required: true,
2948
2980
  rules: [{
2949
2981
  pattern: HEX_COLOR_PATTERN,
@@ -3624,7 +3656,6 @@ var tableSchema = {
3624
3656
  title: i18n("schemas.borderColor"),
3625
3657
  type: "string",
3626
3658
  widget: "color",
3627
- props: { disabledAlpha: true },
3628
3659
  rules: [{
3629
3660
  pattern: HEX_COLOR_PATTERN,
3630
3661
  message: i18n("validation.hexColor")
@@ -6440,7 +6471,6 @@ var getPlugin = ({ type, icon }) => {
6440
6471
  title: i18n("schemas.textColor"),
6441
6472
  type: "string",
6442
6473
  widget: "color",
6443
- props: { disabledAlpha: true },
6444
6474
  rules: [{
6445
6475
  pattern: HEX_COLOR_PATTERN,
6446
6476
  message: i18n("validation.hexColor")
@@ -6450,7 +6480,6 @@ var getPlugin = ({ type, icon }) => {
6450
6480
  title: i18n("schemas.bgColor"),
6451
6481
  type: "string",
6452
6482
  widget: "color",
6453
- props: { disabledAlpha: true },
6454
6483
  rules: [{
6455
6484
  pattern: HEX_COLOR_PATTERN,
6456
6485
  message: i18n("validation.hexColor")
@@ -6754,7 +6783,6 @@ var schema$2 = {
6754
6783
  title: i18n("schemas.color"),
6755
6784
  type: "string",
6756
6785
  widget: "color",
6757
- props: { disabledAlpha: true },
6758
6786
  required: true,
6759
6787
  rules: [{
6760
6788
  pattern: HEX_COLOR_PATTERN,
@@ -6820,7 +6848,6 @@ var schema = {
6820
6848
  title: i18n("schemas.color"),
6821
6849
  type: "string",
6822
6850
  widget: "color",
6823
- props: { disabledAlpha: true },
6824
6851
  required: true,
6825
6852
  rules: [{
6826
6853
  pattern: HEX_COLOR_PATTERN,
@@ -6844,9 +6871,8 @@ var schema = {
6844
6871
  };
6845
6872
  //#endregion
6846
6873
  //#region src/circleMark/index.ts
6847
- var HEX_COLOR_REGEXP = new RegExp(HEX_COLOR_PATTERN);
6848
6874
  var isSelected = (value) => value === "true";
6849
- var hasRenderableStyle = (schema) => schema.width > 0 && schema.height > 0 && schema.borderWidth > 0 && typeof schema.color === "string" && HEX_COLOR_REGEXP.test(schema.color);
6875
+ var hasRenderableStyle = (schema) => schema.width > 0 && schema.height > 0 && schema.borderWidth > 0 && typeof schema.color === "string" && isHexValid(schema.color);
6850
6876
  var circleMark = {
6851
6877
  ui: (arg) => {
6852
6878
  const { schema, value, onChange, rootElement, mode } = arg;
@@ -6897,6 +6923,7 @@ var circleMark = {
6897
6923
  const xScale = width / 2 - borderWidth / 2;
6898
6924
  const yScale = height / 2 - borderWidth / 2;
6899
6925
  if (xScale <= 0 || yScale <= 0) return;
6926
+ const { color: borderColorHex, alpha: borderAlpha } = splitHexAlpha(schema.color);
6900
6927
  page.drawEllipse({
6901
6928
  x: x + width / 2,
6902
6929
  y: y + height / 2,
@@ -6904,8 +6931,8 @@ var circleMark = {
6904
6931
  yScale,
6905
6932
  rotate,
6906
6933
  borderWidth,
6907
- borderColor: hex2PrintingColor(schema.color, options.colorType),
6908
- borderOpacity: opacity
6934
+ borderColor: hex2PrintingColor(borderColorHex, options.colorType),
6935
+ borderOpacity: applyAlphaToOpacity(opacity, borderAlpha)
6909
6936
  });
6910
6937
  },
6911
6938
  propPanel: {
@@ -6914,7 +6941,6 @@ var circleMark = {
6914
6941
  title: i18n("schemas.color"),
6915
6942
  type: "string",
6916
6943
  widget: "color",
6917
- props: { disabledAlpha: true },
6918
6944
  required: true,
6919
6945
  rules: [{
6920
6946
  pattern: HEX_COLOR_PATTERN,