@pdfme/schemas 5.3.8-dev.9 → 5.3.9-dev.1
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/cjs/__tests__/barcode.test.js +119 -120
- package/dist/cjs/__tests__/barcode.test.js.map +1 -1
- package/dist/cjs/__tests__/multiVariableText.test.js +15 -15
- package/dist/cjs/__tests__/multiVariableText.test.js.map +1 -1
- package/dist/cjs/__tests__/text.test.js +88 -78
- package/dist/cjs/__tests__/text.test.js.map +1 -1
- package/dist/cjs/__tests__/utils.test.js +76 -15
- package/dist/cjs/__tests__/utils.test.js.map +1 -1
- package/dist/cjs/src/barcodes/helper.js +2 -1
- package/dist/cjs/src/barcodes/helper.js.map +1 -1
- package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
- package/dist/cjs/src/barcodes/propPanel.js +3 -3
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
- package/dist/cjs/src/checkbox/index.js +4 -4
- package/dist/cjs/src/checkbox/index.js.map +1 -1
- package/dist/cjs/src/date/date.js +2 -2
- package/dist/cjs/src/date/date.js.map +1 -1
- package/dist/cjs/src/date/dateTime.js +2 -2
- package/dist/cjs/src/date/dateTime.js.map +1 -1
- package/dist/cjs/src/date/helper.js +28 -18
- package/dist/cjs/src/date/helper.js.map +1 -1
- package/dist/cjs/src/date/time.js +2 -2
- package/dist/cjs/src/date/time.js.map +1 -1
- package/dist/cjs/src/graphics/image.js.map +1 -1
- package/dist/cjs/src/graphics/imagehelper.js.map +1 -1
- package/dist/cjs/src/graphics/svg.js +25 -2
- package/dist/cjs/src/graphics/svg.js.map +1 -1
- package/dist/cjs/src/index.js +34 -31
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/multiVariableText/helper.js +2 -2
- package/dist/cjs/src/multiVariableText/helper.js.map +1 -1
- package/dist/cjs/src/multiVariableText/pdfRender.js +5 -5
- package/dist/cjs/src/multiVariableText/pdfRender.js.map +1 -1
- package/dist/cjs/src/multiVariableText/propPanel.js +19 -14
- package/dist/cjs/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/cjs/src/multiVariableText/uiRender.js +25 -15
- package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/cjs/src/radioGroup/index.js +4 -4
- package/dist/cjs/src/radioGroup/index.js.map +1 -1
- package/dist/cjs/src/select/index.js +9 -9
- package/dist/cjs/src/select/index.js.map +1 -1
- package/dist/cjs/src/shapes/line.js +1 -1
- package/dist/cjs/src/shapes/rectAndEllipse.js +8 -4
- package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/cjs/src/tables/classes.js +4 -4
- package/dist/cjs/src/tables/classes.js.map +1 -1
- package/dist/cjs/src/tables/dynamicTemplate.js +2 -2
- package/dist/cjs/src/tables/dynamicTemplate.js.map +1 -1
- package/dist/cjs/src/tables/helper.js +25 -25
- package/dist/cjs/src/tables/helper.js.map +1 -1
- package/dist/cjs/src/tables/pdfRender.js +8 -8
- package/dist/cjs/src/tables/pdfRender.js.map +1 -1
- package/dist/cjs/src/tables/tableHelper.js +6 -7
- package/dist/cjs/src/tables/tableHelper.js.map +1 -1
- package/dist/cjs/src/tables/uiRender.js.map +1 -1
- package/dist/cjs/src/text/extraFormatter.js +17 -17
- package/dist/cjs/src/text/extraFormatter.js.map +1 -1
- package/dist/cjs/src/text/helper.js +17 -7
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +1 -1
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js +2 -2
- package/dist/cjs/src/text/propPanel.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/cjs/src/utils.js +52 -12
- package/dist/cjs/src/utils.js.map +1 -1
- package/dist/esm/__tests__/barcode.test.js +14 -15
- package/dist/esm/__tests__/barcode.test.js.map +1 -1
- package/dist/esm/__tests__/multiVariableText.test.js +1 -1
- package/dist/esm/__tests__/multiVariableText.test.js.map +1 -1
- package/dist/esm/__tests__/text.test.js +2 -2
- package/dist/esm/__tests__/text.test.js.map +1 -1
- package/dist/esm/__tests__/utils.test.js +65 -4
- package/dist/esm/__tests__/utils.test.js.map +1 -1
- package/dist/esm/src/barcodes/helper.js +2 -1
- package/dist/esm/src/barcodes/helper.js.map +1 -1
- package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +3 -3
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/barcodes/uiRender.js.map +1 -1
- package/dist/esm/src/checkbox/index.js +2 -2
- package/dist/esm/src/checkbox/index.js.map +1 -1
- package/dist/esm/src/date/date.js +1 -1
- package/dist/esm/src/date/date.js.map +1 -1
- package/dist/esm/src/date/dateTime.js +1 -1
- package/dist/esm/src/date/dateTime.js.map +1 -1
- package/dist/esm/src/date/helper.js +4 -4
- package/dist/esm/src/date/helper.js.map +1 -1
- package/dist/esm/src/date/time.js +1 -1
- package/dist/esm/src/date/time.js.map +1 -1
- package/dist/esm/src/graphics/image.js.map +1 -1
- package/dist/esm/src/graphics/imagehelper.js.map +1 -1
- package/dist/esm/src/graphics/svg.js +25 -2
- package/dist/esm/src/graphics/svg.js.map +1 -1
- package/dist/esm/src/index.js +16 -14
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/multiVariableText/helper.js +2 -2
- package/dist/esm/src/multiVariableText/helper.js.map +1 -1
- package/dist/esm/src/multiVariableText/pdfRender.js +2 -2
- package/dist/esm/src/multiVariableText/pdfRender.js.map +1 -1
- package/dist/esm/src/multiVariableText/propPanel.js +15 -10
- package/dist/esm/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/esm/src/multiVariableText/uiRender.js +19 -9
- package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/esm/src/radioGroup/index.js +2 -2
- package/dist/esm/src/radioGroup/index.js.map +1 -1
- package/dist/esm/src/select/index.js +2 -2
- package/dist/esm/src/select/index.js.map +1 -1
- package/dist/esm/src/shapes/line.js +1 -1
- package/dist/esm/src/shapes/rectAndEllipse.js +8 -4
- package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/esm/src/tables/classes.js +1 -1
- package/dist/esm/src/tables/classes.js.map +1 -1
- package/dist/esm/src/tables/dynamicTemplate.js +1 -1
- package/dist/esm/src/tables/dynamicTemplate.js.map +1 -1
- package/dist/esm/src/tables/helper.js +5 -5
- package/dist/esm/src/tables/helper.js.map +1 -1
- package/dist/esm/src/tables/pdfRender.js +4 -4
- package/dist/esm/src/tables/pdfRender.js.map +1 -1
- package/dist/esm/src/tables/tableHelper.js +1 -1
- package/dist/esm/src/tables/tableHelper.js.map +1 -1
- package/dist/esm/src/tables/uiRender.js.map +1 -1
- package/dist/esm/src/text/extraFormatter.js +2 -2
- package/dist/esm/src/text/extraFormatter.js.map +1 -1
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +1 -1
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js +1 -1
- package/dist/esm/src/text/propPanel.js.map +1 -1
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/esm/src/utils.js +52 -12
- package/dist/esm/src/utils.js.map +1 -1
- package/dist/node/__tests__/barcode.test.js +119 -120
- package/dist/node/__tests__/barcode.test.js.map +1 -1
- package/dist/node/__tests__/multiVariableText.test.js +15 -15
- package/dist/node/__tests__/multiVariableText.test.js.map +1 -1
- package/dist/node/__tests__/text.test.js +88 -78
- package/dist/node/__tests__/text.test.js.map +1 -1
- package/dist/node/__tests__/utils.test.js +76 -15
- package/dist/node/__tests__/utils.test.js.map +1 -1
- package/dist/node/src/barcodes/helper.js +2 -1
- package/dist/node/src/barcodes/helper.js.map +1 -1
- package/dist/node/src/barcodes/pdfRender.js.map +1 -1
- package/dist/node/src/barcodes/propPanel.js +3 -3
- package/dist/node/src/barcodes/propPanel.js.map +1 -1
- package/dist/node/src/barcodes/uiRender.js.map +1 -1
- package/dist/node/src/checkbox/index.js +4 -4
- package/dist/node/src/checkbox/index.js.map +1 -1
- package/dist/node/src/date/date.js +2 -2
- package/dist/node/src/date/date.js.map +1 -1
- package/dist/node/src/date/dateTime.js +2 -2
- package/dist/node/src/date/dateTime.js.map +1 -1
- package/dist/node/src/date/helper.js +28 -18
- package/dist/node/src/date/helper.js.map +1 -1
- package/dist/node/src/date/time.js +2 -2
- package/dist/node/src/date/time.js.map +1 -1
- package/dist/node/src/graphics/image.js.map +1 -1
- package/dist/node/src/graphics/imagehelper.js.map +1 -1
- package/dist/node/src/graphics/svg.js +25 -2
- package/dist/node/src/graphics/svg.js.map +1 -1
- package/dist/node/src/index.js +34 -31
- package/dist/node/src/index.js.map +1 -1
- package/dist/node/src/multiVariableText/helper.js +2 -2
- package/dist/node/src/multiVariableText/helper.js.map +1 -1
- package/dist/node/src/multiVariableText/pdfRender.js +5 -5
- package/dist/node/src/multiVariableText/pdfRender.js.map +1 -1
- package/dist/node/src/multiVariableText/propPanel.js +19 -14
- package/dist/node/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/node/src/multiVariableText/uiRender.js +25 -15
- package/dist/node/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/node/src/radioGroup/index.js +4 -4
- package/dist/node/src/radioGroup/index.js.map +1 -1
- package/dist/node/src/select/index.js +9 -9
- package/dist/node/src/select/index.js.map +1 -1
- package/dist/node/src/shapes/line.js +1 -1
- package/dist/node/src/shapes/rectAndEllipse.js +8 -4
- package/dist/node/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/node/src/tables/classes.js +4 -4
- package/dist/node/src/tables/classes.js.map +1 -1
- package/dist/node/src/tables/dynamicTemplate.js +2 -2
- package/dist/node/src/tables/dynamicTemplate.js.map +1 -1
- package/dist/node/src/tables/helper.js +25 -25
- package/dist/node/src/tables/helper.js.map +1 -1
- package/dist/node/src/tables/pdfRender.js +8 -8
- package/dist/node/src/tables/pdfRender.js.map +1 -1
- package/dist/node/src/tables/tableHelper.js +6 -7
- package/dist/node/src/tables/tableHelper.js.map +1 -1
- package/dist/node/src/tables/uiRender.js.map +1 -1
- package/dist/node/src/text/extraFormatter.js +17 -17
- package/dist/node/src/text/extraFormatter.js.map +1 -1
- package/dist/node/src/text/helper.js +17 -7
- package/dist/node/src/text/helper.js.map +1 -1
- package/dist/node/src/text/pdfRender.js +1 -1
- package/dist/node/src/text/pdfRender.js.map +1 -1
- package/dist/node/src/text/propPanel.js +2 -2
- package/dist/node/src/text/propPanel.js.map +1 -1
- package/dist/node/src/text/uiRender.js.map +1 -1
- package/dist/node/src/utils.js +52 -12
- package/dist/node/src/utils.js.map +1 -1
- package/dist/types/src/barcodes/helper.d.ts +1 -1
- package/dist/types/src/barcodes/index.d.ts +1 -1
- package/dist/types/src/barcodes/pdfRender.d.ts +1 -1
- package/dist/types/src/barcodes/propPanel.d.ts +1 -1
- package/dist/types/src/barcodes/uiRender.d.ts +1 -1
- package/dist/types/src/date/date.d.ts +1 -1
- package/dist/types/src/date/dateTime.d.ts +1 -1
- package/dist/types/src/date/helper.d.ts +1 -1
- package/dist/types/src/date/time.d.ts +1 -1
- package/dist/types/src/date/types.d.ts +6 -1
- package/dist/types/src/index.d.ts +16 -15
- package/dist/types/src/multiVariableText/helper.d.ts +1 -1
- package/dist/types/src/multiVariableText/index.d.ts +1 -1
- package/dist/types/src/multiVariableText/pdfRender.d.ts +1 -1
- package/dist/types/src/multiVariableText/propPanel.d.ts +1 -1
- package/dist/types/src/multiVariableText/types.d.ts +1 -1
- package/dist/types/src/multiVariableText/uiRender.d.ts +1 -1
- package/dist/types/src/select/index.d.ts +1 -1
- package/dist/types/src/shapes/rectAndEllipse.d.ts +16 -96
- package/dist/types/src/tables/cell.d.ts +1 -1
- package/dist/types/src/tables/classes.d.ts +1 -1
- package/dist/types/src/tables/helper.d.ts +5 -5
- package/dist/types/src/tables/pdfRender.d.ts +1 -1
- package/dist/types/src/tables/propPanel.d.ts +1 -1
- package/dist/types/src/tables/tableHelper.d.ts +1 -1
- package/dist/types/src/tables/types.d.ts +1 -1
- package/dist/types/src/text/constants.d.ts +1 -1
- package/dist/types/src/text/helper.d.ts +1 -1
- package/dist/types/src/text/index.d.ts +1 -1
- package/dist/types/src/text/pdfRender.d.ts +1 -1
- package/dist/types/src/text/propPanel.d.ts +1 -1
- package/dist/types/src/text/uiRender.d.ts +1 -1
- package/dist/types/src/utils.d.ts +4 -85
- package/eslint.config.mjs +22 -0
- package/package.json +3 -4
- package/src/barcodes/helper.ts +3 -4
- package/src/barcodes/index.ts +2 -2
- package/src/barcodes/pdfRender.ts +2 -2
- package/src/barcodes/propPanel.ts +4 -5
- package/src/barcodes/uiRender.ts +1 -1
- package/src/checkbox/index.ts +2 -2
- package/src/date/date.ts +1 -1
- package/src/date/dateTime.ts +1 -1
- package/src/date/helper.ts +20 -13
- package/src/date/time.ts +1 -1
- package/src/date/types.ts +7 -1
- package/src/graphics/imagehelper.ts +1 -1
- package/src/graphics/svg.ts +27 -2
- package/src/index.ts +17 -14
- package/src/multiVariableText/helper.ts +15 -7
- package/src/multiVariableText/index.ts +1 -1
- package/src/multiVariableText/pdfRender.ts +3 -3
- package/src/multiVariableText/propPanel.ts +19 -16
- package/src/multiVariableText/types.ts +1 -1
- package/src/multiVariableText/uiRender.ts +26 -23
- package/src/radioGroup/index.ts +3 -3
- package/src/select/index.ts +4 -4
- package/src/shapes/line.ts +1 -1
- package/src/shapes/rectAndEllipse.ts +10 -4
- package/src/tables/cell.ts +5 -5
- package/src/tables/classes.ts +7 -7
- package/src/tables/dynamicTemplate.ts +3 -3
- package/src/tables/helper.ts +7 -7
- package/src/tables/pdfRender.ts +9 -9
- package/src/tables/propPanel.ts +1 -1
- package/src/tables/tableHelper.ts +15 -12
- package/src/tables/types.ts +1 -1
- package/src/tables/uiRender.ts +6 -6
- package/src/text/constants.ts +1 -1
- package/src/text/extraFormatter.ts +2 -2
- package/src/text/helper.ts +6 -6
- package/src/text/index.ts +1 -1
- package/src/text/pdfRender.ts +4 -4
- package/src/text/propPanel.ts +2 -2
- package/src/text/uiRender.ts +14 -6
- package/src/utils.ts +60 -15
- package/tsconfig.cjs.json +1 -1
- package/tsconfig.esm.json +2 -1
- package/tsconfig.node.json +2 -1
- package/.eslintrc.cjs +0 -3
package/src/tables/classes.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Font, mm2pt, pt2mm } from '@pdfme/common';
|
2
2
|
import type { Font as FontKitFont } from 'fontkit';
|
3
|
-
import { splitTextToSize, getFontKitFont, widthOfTextAtSize } from '../text/helper';
|
4
|
-
import type { Styles, TableInput, Settings, Section, StylesProps } from './types';
|
3
|
+
import { splitTextToSize, getFontKitFont, widthOfTextAtSize } from '../text/helper.js';
|
4
|
+
import type { Styles, TableInput, Settings, Section, StylesProps } from './types.js';
|
5
5
|
|
6
6
|
type ContentSettings = { body: Row[]; head: Row[]; columns: Column[] };
|
7
7
|
|
@@ -175,7 +175,7 @@ async function calculateWidths(arg: { table: Table; font: Font; _cache: Map<any,
|
|
175
175
|
// first resize attempt: with respect to minReadableWidth and minWidth
|
176
176
|
if (resizeWidth) {
|
177
177
|
resizeWidth = resizeColumns(resizableColumns, resizeWidth, (column) =>
|
178
|
-
Math.max(column.minReadableWidth, column.minWidth)
|
178
|
+
Math.max(column.minReadableWidth, column.minWidth),
|
179
179
|
);
|
180
180
|
}
|
181
181
|
|
@@ -257,7 +257,7 @@ function applyColSpans(table: Table) {
|
|
257
257
|
|
258
258
|
async function fitContent(
|
259
259
|
table: Table,
|
260
|
-
getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont
|
260
|
+
getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>,
|
261
261
|
) {
|
262
262
|
const rowSpanHeight = { count: 0, height: 0 };
|
263
263
|
for (const row of table.allRows()) {
|
@@ -293,7 +293,7 @@ async function fitContent(
|
|
293
293
|
function resizeColumns(
|
294
294
|
columns: Column[],
|
295
295
|
resizeWidth: number,
|
296
|
-
getMinWidth: (column: Column) => number
|
296
|
+
getMinWidth: (column: Column) => number,
|
297
297
|
) {
|
298
298
|
const initialResizeWidth = resizeWidth;
|
299
299
|
const sumWrappedWidth = columns.reduce((acc, column) => acc + column.wrappedWidth, 0);
|
@@ -333,7 +333,7 @@ function resizeColumns(
|
|
333
333
|
|
334
334
|
async function calculate(
|
335
335
|
table: Table,
|
336
|
-
getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont
|
336
|
+
getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>,
|
337
337
|
) {
|
338
338
|
for (const row of table.allRows()) {
|
339
339
|
for (const column of table.columns) {
|
@@ -347,7 +347,7 @@ async function calculate(
|
|
347
347
|
|
348
348
|
const longestWordWidth = getStringWidth(
|
349
349
|
Object.assign(cell, { text: cell.text.join(' ').split(/\s+/) }),
|
350
|
-
fontKitFont
|
350
|
+
fontKitFont,
|
351
351
|
);
|
352
352
|
cell.minReadableWidth = longestWordWidth + hPadding;
|
353
353
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Schema, BasePdf, CommonOptions } from '@pdfme/common';
|
2
|
-
import { createSingleTable } from './tableHelper';
|
2
|
+
import { createSingleTable } from './tableHelper.js';
|
3
3
|
import { getBodyWithRange, getBody } from './helper.js';
|
4
|
-
import { TableSchema } from './types';
|
4
|
+
import { TableSchema } from './types.js';
|
5
5
|
|
6
6
|
export const getDynamicHeightsForTable = async (
|
7
7
|
value: string,
|
@@ -10,7 +10,7 @@ export const getDynamicHeightsForTable = async (
|
|
10
10
|
basePdf: BasePdf;
|
11
11
|
options: CommonOptions;
|
12
12
|
_cache: Map<any, any>;
|
13
|
-
}
|
13
|
+
},
|
14
14
|
): Promise<number[]> => {
|
15
15
|
if (args.schema.type !== 'table') return Promise.resolve([args.schema.height]);
|
16
16
|
const schema = args.schema as TableSchema;
|
package/src/tables/helper.ts
CHANGED
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
VERTICAL_ALIGN_TOP,
|
11
11
|
VERTICAL_ALIGN_MIDDLE,
|
12
12
|
VERTICAL_ALIGN_BOTTOM,
|
13
|
-
} from '../text/constants';
|
13
|
+
} from '../text/constants.js';
|
14
14
|
import { HEX_COLOR_PATTERN } from '../constants.js';
|
15
15
|
|
16
16
|
export const getDefaultCellStyles = () => ({
|
@@ -112,7 +112,7 @@ export const getCellPropPanelSchema = (arg: {
|
|
112
112
|
type: 'string',
|
113
113
|
widget: 'color',
|
114
114
|
props: {
|
115
|
-
disabledAlpha: true
|
115
|
+
disabledAlpha: true,
|
116
116
|
},
|
117
117
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
118
118
|
},
|
@@ -121,7 +121,7 @@ export const getCellPropPanelSchema = (arg: {
|
|
121
121
|
type: 'string',
|
122
122
|
widget: 'color',
|
123
123
|
props: {
|
124
|
-
disabledAlpha: true
|
124
|
+
disabledAlpha: true,
|
125
125
|
},
|
126
126
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
127
127
|
},
|
@@ -130,7 +130,7 @@ export const getCellPropPanelSchema = (arg: {
|
|
130
130
|
type: 'string',
|
131
131
|
widget: 'color',
|
132
132
|
props: {
|
133
|
-
disabledAlpha: true
|
133
|
+
disabledAlpha: true,
|
134
134
|
},
|
135
135
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
136
136
|
},
|
@@ -141,7 +141,7 @@ export const getCellPropPanelSchema = (arg: {
|
|
141
141
|
type: 'string',
|
142
142
|
widget: 'color',
|
143
143
|
props: {
|
144
|
-
disabledAlpha: true
|
144
|
+
disabledAlpha: true,
|
145
145
|
},
|
146
146
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
147
147
|
},
|
@@ -194,7 +194,7 @@ export const getColumnStylesPropPanelSchema = ({
|
|
194
194
|
},
|
195
195
|
},
|
196
196
|
}),
|
197
|
-
{}
|
197
|
+
{},
|
198
198
|
),
|
199
199
|
},
|
200
200
|
});
|
@@ -208,7 +208,7 @@ export const getBody = (value: string | string[][]): string[][] => {
|
|
208
208
|
|
209
209
|
export const getBodyWithRange = (
|
210
210
|
value: string | string[][],
|
211
|
-
range?: { start: number; end?: number | undefined }
|
211
|
+
range?: { start: number; end?: number | undefined },
|
212
212
|
) => {
|
213
213
|
const body = getBody(value);
|
214
214
|
if (!range) return body;
|
package/src/tables/pdfRender.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import type { TableSchema } from './types';
|
1
|
+
import type { TableSchema } from './types.js';
|
2
2
|
import type { PDFRenderProps } from '@pdfme/common';
|
3
|
-
import { Cell, Table, Row, Column } from './classes';
|
4
|
-
import { rectangle } from '../shapes/rectAndEllipse';
|
5
|
-
import cell from './cell';
|
6
|
-
import { getBodyWithRange } from './helper';
|
7
|
-
import { createSingleTable } from './tableHelper';
|
3
|
+
import { Cell, Table, Row, Column } from './classes.js';
|
4
|
+
import { rectangle } from '../shapes/rectAndEllipse.js';
|
5
|
+
import cell from './cell.js';
|
6
|
+
import { getBodyWithRange } from './helper.js';
|
7
|
+
import { createSingleTable } from './tableHelper.js';
|
8
8
|
|
9
9
|
type Pos = { x: number; y: number };
|
10
10
|
|
@@ -41,7 +41,7 @@ async function drawRow(
|
|
41
41
|
table: Table,
|
42
42
|
row: Row,
|
43
43
|
cursor: Pos,
|
44
|
-
columns: Column[]
|
44
|
+
columns: Column[],
|
45
45
|
) {
|
46
46
|
cursor.x = table.settings.margin.left;
|
47
47
|
for (const column of columns) {
|
@@ -65,7 +65,7 @@ async function drawTableBorder(
|
|
65
65
|
arg: PDFRenderProps<TableSchema>,
|
66
66
|
table: Table,
|
67
67
|
startPos: Pos,
|
68
|
-
cursor: Pos
|
68
|
+
cursor: Pos,
|
69
69
|
) {
|
70
70
|
const lineWidth = table.settings.tableLineWidth;
|
71
71
|
const lineColor = table.settings.tableLineColor;
|
@@ -112,7 +112,7 @@ export const pdfRender = async (arg: PDFRenderProps<TableSchema>) => {
|
|
112
112
|
|
113
113
|
const body = getBodyWithRange(
|
114
114
|
typeof value !== 'string' ? JSON.stringify(value || '[]') : value,
|
115
|
-
schema.__bodyRange
|
115
|
+
schema.__bodyRange,
|
116
116
|
);
|
117
117
|
const table = await createSingleTable(body, arg);
|
118
118
|
await drawTable(arg, table);
|
package/src/tables/propPanel.ts
CHANGED
@@ -15,8 +15,8 @@ import type {
|
|
15
15
|
TableInput,
|
16
16
|
StylesProps,
|
17
17
|
Section,
|
18
|
-
} from './types';
|
19
|
-
import { Cell, Column, Row, Table } from './classes';
|
18
|
+
} from './types.js';
|
19
|
+
import { Cell, Column, Row, Table } from './classes.js';
|
20
20
|
|
21
21
|
type StyleProp = 'styles' | 'headStyles' | 'bodyStyles' | 'alternateRowStyles' | 'columnStyles';
|
22
22
|
|
@@ -51,7 +51,7 @@ function parseSection(
|
|
51
51
|
sectionRows: string[][],
|
52
52
|
columns: Column[],
|
53
53
|
styleProps: StylesProps,
|
54
|
-
fallbackFontName: string
|
54
|
+
fallbackFontName: string,
|
55
55
|
): Row[] {
|
56
56
|
const rowSpansLeftForColumn: { [key: string]: { left: number; times: number } } = {};
|
57
57
|
const result = sectionRows.map((rawRow, rowIndex) => {
|
@@ -112,7 +112,7 @@ function cellStyles(
|
|
112
112
|
column: Column,
|
113
113
|
rowIndex: number,
|
114
114
|
styles: StylesProps,
|
115
|
-
fallbackFontName: string
|
115
|
+
fallbackFontName: string,
|
116
116
|
) {
|
117
117
|
let sectionStyles;
|
118
118
|
if (sectionName === 'head') {
|
@@ -167,23 +167,26 @@ function mapCellStyle(style: CellStyle): Partial<Styles> {
|
|
167
167
|
function getTableOptions(schema: TableSchema, body: string[][]): UserOptions {
|
168
168
|
const columnStylesWidth = schema.headWidthPercentages.reduce(
|
169
169
|
(acc, cur, i) => ({ ...acc, [i]: { cellWidth: schema.width * (cur / 100) } }),
|
170
|
-
{} as Record<number, Partial<Styles
|
170
|
+
{} as Record<number, Partial<Styles>>,
|
171
171
|
);
|
172
172
|
|
173
173
|
const columnStylesAlignment = Object.entries(schema.columnStyles.alignment || {}).reduce(
|
174
174
|
(acc, [key, value]) => ({ ...acc, [key]: { alignment: value } }),
|
175
|
-
{} as Record<number, Partial<Styles
|
175
|
+
{} as Record<number, Partial<Styles>>,
|
176
176
|
);
|
177
177
|
|
178
178
|
const allKeys = new Set([
|
179
179
|
...Object.keys(columnStylesWidth).map(Number),
|
180
180
|
...Object.keys(columnStylesAlignment).map(Number),
|
181
181
|
]);
|
182
|
-
const columnStyles = Array.from(allKeys).reduce(
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
182
|
+
const columnStyles = Array.from(allKeys).reduce(
|
183
|
+
(acc, key) => {
|
184
|
+
const widthStyle = columnStylesWidth[key] || {};
|
185
|
+
const alignmentStyle = columnStylesAlignment[key] || {};
|
186
|
+
return { ...acc, [key]: { ...widthStyle, ...alignmentStyle } };
|
187
|
+
},
|
188
|
+
{} as Record<number, Partial<Styles>>,
|
189
|
+
);
|
187
190
|
|
188
191
|
return {
|
189
192
|
head: [schema.head],
|
@@ -254,7 +257,7 @@ export function createSingleTable(body: string[][], args: CreateTableArgs) {
|
|
254
257
|
'When specifying a custom PDF for basePdf, ' +
|
255
258
|
'you cannot use features such as page breaks or re-layout of other elements.' +
|
256
259
|
'To utilize these features, please define basePdf as follows:\n' +
|
257
|
-
'{ width: number; height: number; padding: [number, number, number, number]; }'
|
260
|
+
'{ width: number; height: number; padding: [number, number, number, number]; }',
|
258
261
|
);
|
259
262
|
}
|
260
263
|
|
package/src/tables/types.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { ALIGNMENT, VERTICAL_ALIGNMENT } from '../text/types';
|
1
|
+
import type { ALIGNMENT, VERTICAL_ALIGNMENT } from '../text/types.js';
|
2
2
|
import type { Schema } from '@pdfme/common';
|
3
3
|
|
4
4
|
export type Spacing = { top: number; right: number; bottom: number; left: number };
|
package/src/tables/uiRender.ts
CHANGED
@@ -4,7 +4,7 @@ import { px2mm } from '@pdfme/common';
|
|
4
4
|
import { createSingleTable } from './tableHelper.js';
|
5
5
|
import { getBody, getBodyWithRange } from './helper.js';
|
6
6
|
import cell from './cell.js';
|
7
|
-
import { Row } from './classes';
|
7
|
+
import { Row } from './classes.js';
|
8
8
|
|
9
9
|
const buttonSize = 30;
|
10
10
|
|
@@ -75,7 +75,7 @@ const calcResizedHeadWidthPercentages = (arg: {
|
|
75
75
|
const setBorder = (
|
76
76
|
div: HTMLDivElement,
|
77
77
|
borderPosition: 'Top' | 'Left' | 'Right' | 'Bottom',
|
78
|
-
arg: UIRenderProps<TableSchema
|
78
|
+
arg: UIRenderProps<TableSchema>,
|
79
79
|
) => {
|
80
80
|
div.style[`border${borderPosition}`] = `${String(arg.schema.tableStyles.borderWidth)}mm solid ${
|
81
81
|
arg.schema.tableStyles.borderColor
|
@@ -88,7 +88,7 @@ const drawBorder = (
|
|
88
88
|
colIndex: number,
|
89
89
|
rowIndex: number,
|
90
90
|
rowsLength: number,
|
91
|
-
arg: UIRenderProps<TableSchema
|
91
|
+
arg: UIRenderProps<TableSchema>,
|
92
92
|
) => {
|
93
93
|
const isFirstColumn = colIndex === 0;
|
94
94
|
const isLastColumn = colIndex === Object.values(row.cells).length - 1;
|
@@ -213,7 +213,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
213
213
|
|
214
214
|
const handleChangeEditingPosition = (
|
215
215
|
newPosition: { rowIndex: number; colIndex: number },
|
216
|
-
editingPosition: { rowIndex: number; colIndex: number }
|
216
|
+
editingPosition: { rowIndex: number; colIndex: number },
|
217
217
|
) => {
|
218
218
|
resetEditingPosition();
|
219
219
|
editingPosition.rowIndex = newPosition.rowIndex;
|
@@ -296,7 +296,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
296
296
|
const newColumnWidthPercentage = 25;
|
297
297
|
const totalCurrentWidth = schema.headWidthPercentages.reduce(
|
298
298
|
(acc, width) => acc + width,
|
299
|
-
0
|
299
|
+
0,
|
300
300
|
);
|
301
301
|
const scalingRatio = (100 - newColumnWidthPercentage) / totalCurrentWidth;
|
302
302
|
const scaledWidths = schema.headWidthPercentages.map((width) => width * scalingRatio);
|
@@ -329,7 +329,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
329
329
|
onClick: () => {
|
330
330
|
const totalWidthMinusRemoved = schema.headWidthPercentages.reduce(
|
331
331
|
(sum, width, j) => (j !== i ? sum + width : sum),
|
332
|
-
0
|
332
|
+
0,
|
333
333
|
);
|
334
334
|
|
335
335
|
// TODO Should also remove the deleted columnStyles when deleting
|
package/src/text/constants.ts
CHANGED
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
TextVerticalAlignBottomIcon,
|
10
10
|
TextVerticalAlignMiddleIcon,
|
11
11
|
TextVerticalAlignTopIcon,
|
12
|
-
} from './icons';
|
12
|
+
} from './icons/index.js';
|
13
13
|
import {
|
14
14
|
ALIGN_CENTER,
|
15
15
|
ALIGN_RIGHT,
|
@@ -18,7 +18,7 @@ import {
|
|
18
18
|
VERTICAL_ALIGN_BOTTOM,
|
19
19
|
VERTICAL_ALIGN_MIDDLE,
|
20
20
|
ALIGN_JUSTIFY,
|
21
|
-
} from './constants';
|
21
|
+
} from './constants.js';
|
22
22
|
|
23
23
|
export enum Formatter {
|
24
24
|
STRIKETHROUGH = 'strikethrough',
|
package/src/text/helper.ts
CHANGED
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
DEFAULT_FONT_NAME,
|
12
12
|
} from '@pdfme/common';
|
13
13
|
import { Buffer } from 'buffer';
|
14
|
-
import type { TextSchema, FontWidthCalcValues } from './types';
|
14
|
+
import type { TextSchema, FontWidthCalcValues } from './types.js';
|
15
15
|
import {
|
16
16
|
DEFAULT_FONT_SIZE,
|
17
17
|
DEFAULT_CHARACTER_SPACING,
|
@@ -29,7 +29,7 @@ export const getBrowserVerticalFontAdjustments = (
|
|
29
29
|
fontKitFont: FontKitFont,
|
30
30
|
fontSize: number,
|
31
31
|
lineHeight: number,
|
32
|
-
verticalAlignment: string
|
32
|
+
verticalAlignment: string,
|
33
33
|
) => {
|
34
34
|
const { ascent, descent, unitsPerEm } = fontKitFont;
|
35
35
|
|
@@ -92,7 +92,7 @@ export const widthOfTextAtSize = (
|
|
92
92
|
text: string,
|
93
93
|
fontKitFont: FontKitFont,
|
94
94
|
fontSize: number,
|
95
|
-
characterSpacing: number
|
95
|
+
characterSpacing: number,
|
96
96
|
) => {
|
97
97
|
const { glyphs } = fontKitFont.layout(text);
|
98
98
|
const scale = 1000 / fontKitFont.unitsPerEm;
|
@@ -112,7 +112,7 @@ const getCacheKey = (fontName: string) => `getFontKitFont-${fontName}`;
|
|
112
112
|
export const getFontKitFont = async (
|
113
113
|
fontName: string | undefined,
|
114
114
|
font: Font,
|
115
|
-
_cache: Map<any, any
|
115
|
+
_cache: Map<any, any>,
|
116
116
|
) => {
|
117
117
|
const fntNm = fontName || getFallbackFontName(font);
|
118
118
|
const cacheKey = getCacheKey(fntNm);
|
@@ -129,7 +129,7 @@ export const getFontKitFont = async (
|
|
129
129
|
}
|
130
130
|
|
131
131
|
const fontKitFont = fontkit.create(
|
132
|
-
fontData instanceof Buffer ? fontData : Buffer.from(fontData as ArrayBuffer)
|
132
|
+
fontData instanceof Buffer ? fontData : Buffer.from(fontData as ArrayBuffer),
|
133
133
|
) as fontkit.Font;
|
134
134
|
_cache.set(cacheKey, fontKitFont);
|
135
135
|
|
@@ -281,7 +281,7 @@ export const calculateDynamicFontSize = ({
|
|
281
281
|
line.replace('\n', ''),
|
282
282
|
fontKitFont,
|
283
283
|
size,
|
284
|
-
characterSpacing
|
284
|
+
characterSpacing,
|
285
285
|
);
|
286
286
|
const textWidthInMm = pt2mm(textWidth);
|
287
287
|
totalWidthInMm = Math.max(totalWidthInMm, textWidthInMm);
|
package/src/text/index.ts
CHANGED
@@ -2,7 +2,7 @@ import type { Plugin } from '@pdfme/common';
|
|
2
2
|
import { pdfRender } from './pdfRender.js';
|
3
3
|
import { propPanel } from './propPanel.js';
|
4
4
|
import { uiRender } from './uiRender.js';
|
5
|
-
import type { TextSchema } from './types';
|
5
|
+
import type { TextSchema } from './types.js';
|
6
6
|
import { TextCursorInput } from 'lucide';
|
7
7
|
import { createSvgStr } from '../utils.js';
|
8
8
|
|
package/src/text/pdfRender.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { PDFFont, PDFDocument } from '@pdfme/pdf-lib';
|
2
2
|
import type { Font as FontKitFont } from 'fontkit';
|
3
|
-
import type { TextSchema } from './types';
|
3
|
+
import type { TextSchema } from './types.js';
|
4
4
|
import {
|
5
5
|
PDFRenderProps,
|
6
6
|
ColorType,
|
@@ -49,12 +49,12 @@ const embedAndGetFontObj = async (arg: {
|
|
49
49
|
return pdfDoc.embedFont(fontData, {
|
50
50
|
subset: typeof v.subset === 'undefined' ? true : v.subset,
|
51
51
|
});
|
52
|
-
})
|
52
|
+
}),
|
53
53
|
);
|
54
54
|
|
55
55
|
const fontObj = Object.keys(font).reduce(
|
56
56
|
(acc, cur, i) => Object.assign(acc, { [cur]: fontValues[i] }),
|
57
|
-
{} as { [key: string]: PDFFont }
|
57
|
+
{} as { [key: string]: PDFFont },
|
58
58
|
);
|
59
59
|
|
60
60
|
_cache.set(pdfDoc, fontObj);
|
@@ -74,7 +74,7 @@ const getFontProp = ({
|
|
74
74
|
}) => {
|
75
75
|
const fontSize = schema.dynamicFontSize
|
76
76
|
? calculateDynamicFontSize({ textSchema: schema, fontKitFont, value })
|
77
|
-
: schema.fontSize ?? DEFAULT_FONT_SIZE;
|
77
|
+
: (schema.fontSize ?? DEFAULT_FONT_SIZE);
|
78
78
|
const color = hex2PrintingColor(schema.fontColor || DEFAULT_FONT_COLOR, colorType);
|
79
79
|
|
80
80
|
return {
|
package/src/text/propPanel.ts
CHANGED
@@ -5,7 +5,7 @@ import {
|
|
5
5
|
PropPanelSchema,
|
6
6
|
getFallbackFontName,
|
7
7
|
} from '@pdfme/common';
|
8
|
-
import type { TextSchema } from './types';
|
8
|
+
import type { TextSchema } from './types.js';
|
9
9
|
import {
|
10
10
|
DEFAULT_FONT_SIZE,
|
11
11
|
DEFAULT_ALIGNMENT,
|
@@ -20,7 +20,7 @@ import {
|
|
20
20
|
DEFAULT_DYNAMIC_MAX_FONT_SIZE,
|
21
21
|
} from './constants.js';
|
22
22
|
import { DEFAULT_OPACITY, HEX_COLOR_PATTERN } from '../constants.js';
|
23
|
-
import { getExtraFormatterSchema } from './extraFormatter';
|
23
|
+
import { getExtraFormatterSchema } from './extraFormatter.js';
|
24
24
|
|
25
25
|
const UseDynamicFontSize = (props: PropPanelWidgetProps) => {
|
26
26
|
const { rootElement, changeSchemas, activeSchema, i18n } = props;
|
package/src/text/uiRender.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type * as CSS from 'csstype';
|
2
2
|
import type { Font as FontKitFont } from 'fontkit';
|
3
3
|
import { UIRenderProps, getDefaultFont } from '@pdfme/common';
|
4
|
-
import type { TextSchema } from './types';
|
4
|
+
import type { TextSchema } from './types.js';
|
5
5
|
import {
|
6
6
|
DEFAULT_FONT_SIZE,
|
7
7
|
DEFAULT_ALIGNMENT,
|
@@ -70,7 +70,11 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
70
70
|
};
|
71
71
|
const font = options?.font || getDefaultFont();
|
72
72
|
const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
|
73
|
-
const textBlock = buildStyledTextContainer(
|
73
|
+
const textBlock = buildStyledTextContainer(
|
74
|
+
arg,
|
75
|
+
fontKitFont,
|
76
|
+
usePlaceholder ? placeholder : value,
|
77
|
+
);
|
74
78
|
|
75
79
|
const processedText = replaceUnsupportedChars(value, fontKitFont);
|
76
80
|
|
@@ -82,7 +86,7 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
82
86
|
(l, i) =>
|
83
87
|
`<span style="letter-spacing:${
|
84
88
|
String(value).length === i + 1 ? 0 : 'inherit'
|
85
|
-
};">${l}</span
|
89
|
+
};">${l}</span>`,
|
86
90
|
)
|
87
91
|
.join('');
|
88
92
|
return;
|
@@ -115,7 +119,7 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
115
119
|
fontKitFont,
|
116
120
|
dynamicFontSize ?? schema.fontSize ?? DEFAULT_FONT_SIZE,
|
117
121
|
schema.lineHeight ?? DEFAULT_LINE_HEIGHT,
|
118
|
-
schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT
|
122
|
+
schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT,
|
119
123
|
);
|
120
124
|
textBlock.style.paddingTop = `${newTopAdj}px`;
|
121
125
|
textBlock.style.marginBottom = `${newBottomAdj}px`;
|
@@ -150,7 +154,11 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
150
154
|
}
|
151
155
|
};
|
152
156
|
|
153
|
-
export const buildStyledTextContainer = (
|
157
|
+
export const buildStyledTextContainer = (
|
158
|
+
arg: UIRenderProps<TextSchema>,
|
159
|
+
fontKitFont: FontKitFont,
|
160
|
+
value: string,
|
161
|
+
) => {
|
154
162
|
const { schema, rootElement, mode, options, _cache } = arg;
|
155
163
|
const font = options?.font || getDefaultFont();
|
156
164
|
|
@@ -171,7 +179,7 @@ export const buildStyledTextContainer = (arg: UIRenderProps<TextSchema>, fontKit
|
|
171
179
|
fontKitFont,
|
172
180
|
dynamicFontSize ?? schema.fontSize ?? DEFAULT_FONT_SIZE,
|
173
181
|
schema.lineHeight ?? DEFAULT_LINE_HEIGHT,
|
174
|
-
schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT
|
182
|
+
schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT,
|
175
183
|
);
|
176
184
|
|
177
185
|
const topAdjustment = topAdj.toString();
|
package/src/utils.ts
CHANGED
@@ -45,7 +45,7 @@ export const convertForPdfLayoutProps = ({
|
|
45
45
|
export const rotatePoint = (
|
46
46
|
point: { x: number; y: number },
|
47
47
|
pivot: { x: number; y: number },
|
48
|
-
angleDegrees: number
|
48
|
+
angleDegrees: number,
|
49
49
|
): { x: number; y: number } => {
|
50
50
|
const angleRadians = degreesToRadians(angleDegrees);
|
51
51
|
|
@@ -148,10 +148,8 @@ const hex2CmykColor = (hexString: string | undefined) => {
|
|
148
148
|
|
149
149
|
export const hex2PrintingColor = (color?: string | Color, colorType?: ColorType) => {
|
150
150
|
// if color is already CMYK, RGB or Grayscale, does not required to convert
|
151
|
-
if (typeof color === 'object') return color
|
152
|
-
return colorType?.toLowerCase() == 'cmyk'
|
153
|
-
? hex2CmykColor(color)
|
154
|
-
: hex2RgbColor(color);
|
151
|
+
if (typeof color === 'object') return color;
|
152
|
+
return colorType?.toLowerCase() == 'cmyk' ? hex2CmykColor(color) : hex2RgbColor(color);
|
155
153
|
};
|
156
154
|
|
157
155
|
export const readFile = (input: File | FileList | null): Promise<string | ArrayBuffer> =>
|
@@ -212,21 +210,68 @@ export const createErrorElm = () => {
|
|
212
210
|
};
|
213
211
|
|
214
212
|
export const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): string => {
|
215
|
-
|
216
|
-
|
213
|
+
// In lucide 0.475.0, the icon is an array of elements, not a single SVG element
|
214
|
+
// We need to create an SVG wrapper and add the elements as children
|
217
215
|
|
218
|
-
|
216
|
+
// Handle non-array input
|
217
|
+
if (!Array.isArray(icon)) {
|
218
|
+
return String(icon);
|
219
|
+
}
|
220
|
+
|
221
|
+
// Create default SVG attributes
|
222
|
+
const svgAttrs = {
|
223
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
224
|
+
width: '24',
|
225
|
+
height: '24',
|
226
|
+
viewBox: '0 0 24 24',
|
227
|
+
fill: 'none',
|
228
|
+
stroke: 'currentColor',
|
229
|
+
'stroke-width': '2',
|
230
|
+
'stroke-linecap': 'round',
|
231
|
+
'stroke-linejoin': 'round',
|
232
|
+
...(attrs || {}),
|
233
|
+
};
|
234
|
+
|
235
|
+
// Format SVG attributes string
|
236
|
+
const svgAttrString = Object.entries(svgAttrs)
|
237
|
+
.map(([key, value]) => `${key}="${value}"`)
|
238
|
+
.join(' ');
|
239
|
+
|
240
|
+
// Helper function to process a single element
|
241
|
+
const processElement = (element: any): string => {
|
242
|
+
if (!Array.isArray(element)) {
|
243
|
+
return String(element);
|
244
|
+
}
|
245
|
+
|
246
|
+
const [tag, attributes = {}, children = []] = element;
|
247
|
+
const tagName = String(tag);
|
219
248
|
|
220
|
-
|
249
|
+
// Format attributes string
|
250
|
+
const attrString = Object.entries(attributes)
|
221
251
|
.map(([key, value]) => `${key}="${value}"`)
|
222
252
|
.join(' ');
|
223
253
|
|
224
|
-
|
225
|
-
|
226
|
-
.join('');
|
254
|
+
// Process children recursively
|
255
|
+
let childrenString = '';
|
227
256
|
|
228
|
-
|
257
|
+
if (Array.isArray(children) && children.length > 0) {
|
258
|
+
childrenString = children.map((child) => processElement(child)).join('');
|
259
|
+
}
|
260
|
+
|
261
|
+
// Return properly formatted element string
|
262
|
+
if (childrenString) {
|
263
|
+
return `<${tagName}${attrString ? ' ' + attrString : ''}>${childrenString}</${tagName}>`;
|
264
|
+
} else {
|
265
|
+
// Self-closing tag for empty children
|
266
|
+
return `<${tagName}${attrString ? ' ' + attrString : ''}/>`;
|
267
|
+
}
|
229
268
|
};
|
230
269
|
|
231
|
-
|
232
|
-
|
270
|
+
// Process all elements and join them
|
271
|
+
const elementsString = Array.isArray(icon)
|
272
|
+
? icon.map((element) => processElement(element)).join('')
|
273
|
+
: processElement(icon);
|
274
|
+
|
275
|
+
// Return the complete SVG string
|
276
|
+
return `<svg ${svgAttrString}>${elementsString}</svg>`;
|
277
|
+
};
|
package/tsconfig.cjs.json
CHANGED
package/tsconfig.esm.json
CHANGED
package/tsconfig.node.json
CHANGED
package/.eslintrc.cjs
DELETED