@campxdev/pdfme 1.2.1 → 1.3.0
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/chunks/{index-dHRmLCnu.js → fontSizePxWidget-Drk8HKGH.js} +138 -9
- package/dist/cjs/chunks/fontSizeTransform-CQQ_O42f.js +37 -0
- package/dist/cjs/chunks/{helper-C2o2tpNj.js → helper-DGH62Z2s.js} +16959 -4
- package/dist/cjs/chunks/{index-qB7eb2BC.js → index-CoNR0xQU.js} +10 -2
- package/dist/cjs/chunks/{index-CXm3doOM.js → index-CsEKt088.js} +750 -535
- package/dist/cjs/chunks/{pluginRegistry-Ba3ANzzx.js → pluginRegistry-D2vr9MUy.js} +1 -1
- package/dist/cjs/common.js +11 -3
- package/dist/cjs/converter.js +1 -1
- package/dist/cjs/generator.js +3 -3
- package/dist/cjs/index.js +27 -16
- package/dist/cjs/print-designer-editor.js +3389 -3383
- package/dist/cjs/schemas.js +500 -38
- package/dist/cjs/ui.js +83339 -72691
- package/dist/esm/chunks/{index-pDt5vVVj.js → fontSizePxWidget-CbzQrSSM.js} +130 -5
- package/dist/esm/chunks/fontSizeTransform-CkTVJdRF.js +34 -0
- package/dist/esm/chunks/{helper-D7XF1bxK.js → helper-DSxGxZ0j.js} +16955 -5
- package/dist/esm/chunks/{index-D1FuD_XZ.js → index-DJkUkUo9.js} +4 -3
- package/dist/esm/chunks/{index-qTsnfbi7.js → index-D_-j4c4P.js} +744 -532
- package/dist/esm/chunks/{pluginRegistry-DEA2P0ud.js → pluginRegistry-Bgrz5qWG.js} +1 -1
- package/dist/esm/common.js +4 -3
- package/dist/esm/converter.js +1 -1
- package/dist/esm/generator.js +3 -3
- package/dist/esm/index.js +7 -6
- package/dist/esm/print-designer-editor.js +3374 -3374
- package/dist/esm/schemas.js +472 -13
- package/dist/esm/ui.js +83339 -72691
- package/dist/types/_vendors/common/constants.d.ts +1 -2
- package/dist/types/_vendors/common/fontSizeTransform.d.ts +5 -0
- package/dist/types/_vendors/common/googleFontUrls.d.ts +9 -0
- package/dist/types/_vendors/common/googleFonts.d.ts +7 -0
- package/dist/types/_vendors/common/helper.d.ts +2 -0
- package/dist/types/_vendors/common/index.d.ts +4 -2
- package/dist/types/_vendors/print-designer-editor/index.d.ts +2 -1
- package/dist/types/_vendors/print-designer-editor/types.d.ts +1 -1
- package/dist/types/_vendors/print-designer-editor/useDesigner.d.ts +1 -1
- package/dist/types/_vendors/schemas/index.d.ts +8 -2
- package/dist/types/_vendors/schemas/richText/helper.d.ts +3 -0
- package/dist/types/_vendors/schemas/richText/index.d.ts +4 -0
- package/dist/types/_vendors/schemas/richText/pdfRender.d.ts +3 -0
- package/dist/types/_vendors/schemas/richText/propPanel.d.ts +3 -0
- package/dist/types/_vendors/schemas/richText/types.d.ts +7 -0
- package/dist/types/_vendors/schemas/richText/uiRender.d.ts +3 -0
- package/dist/types/_vendors/schemas/singleVariableText/index.d.ts +4 -0
- package/dist/types/_vendors/schemas/singleVariableText/propPanel.d.ts +3 -0
- package/dist/types/_vendors/schemas/singleVariableText/types.d.ts +4 -0
- package/dist/types/_vendors/schemas/text/fontCache.d.ts +10 -0
- package/dist/types/_vendors/schemas/text/fontSizePxWidget.d.ts +9 -0
- package/dist/types/_vendors/ui/components/CtlBar.d.ts +1 -1
- package/dist/types/_vendors/ui/components/Paper.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,11 +1,103 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as px2mm, Z as ZOOM, c as b64toUint8Array, y as mm2pt, r as getFallbackFontName, D as DEFAULT_FONT_NAME, F as px2pt, A as pt2px } from './helper-DSxGxZ0j.js';
|
|
2
2
|
import SignaturePad from 'signature_pad';
|
|
3
3
|
import { Image, PenTool, Minus, Square, Circle, Table as Table$1, QrCode, Barcode } from 'lucide';
|
|
4
|
-
import { D as DEFAULT_OPACITY, c as createSvgStr, i as isEditable,
|
|
4
|
+
import { D as DEFAULT_OPACITY, c as createSvgStr, i as isEditable, d as addAlphaToHex, r as readFile, e as convertForPdfLayoutProps, H as HEX_COLOR_PATTERN, h as hex2PrintingColor, f as rotatePoint, j as getDefaultCellStyles, u as uiRender$2, p as pdfRender$2, k as createErrorElm } from './index-D_-j4c4P.js';
|
|
5
5
|
import { Buffer } from 'buffer';
|
|
6
6
|
import { t as toRadians } from './colors-jzbEzNi4.js';
|
|
7
7
|
import { v1 } from 'uuid';
|
|
8
8
|
import bwipjs from 'bwip-js';
|
|
9
|
+
import { r as replacePlaceholders } from './expression-B-F1KCfk.js';
|
|
10
|
+
|
|
11
|
+
const substituteVariables = (text, variablesIn, extraContext) => {
|
|
12
|
+
if (!text) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
let variables;
|
|
16
|
+
try {
|
|
17
|
+
variables =
|
|
18
|
+
typeof variablesIn === 'string'
|
|
19
|
+
? JSON.parse(variablesIn || '{}')
|
|
20
|
+
: variablesIn;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new SyntaxError(`[@campxdev/schemas] MVT: invalid JSON string '${variablesIn}'`);
|
|
24
|
+
}
|
|
25
|
+
// Merge extra context (e.g. currentPage, totalPages) with user variables
|
|
26
|
+
// System context takes precedence over user variables
|
|
27
|
+
const merged = extraContext ? { ...variables, ...extraContext } : variables;
|
|
28
|
+
// Use the full JS expression evaluator — supports {varName}, {expr * 2}, {str.toUpperCase()}, etc.
|
|
29
|
+
const result = replacePlaceholders({ content: text, variables: merged, schemas: [] });
|
|
30
|
+
// Strip any remaining unresolved {placeholders} for clean output
|
|
31
|
+
return result.replace(/\{[^{}]+\}/g, '');
|
|
32
|
+
};
|
|
33
|
+
const validateVariables = (value, schema) => {
|
|
34
|
+
if (!schema.variables || schema.variables.length === 0) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
let values;
|
|
38
|
+
try {
|
|
39
|
+
values = value ? JSON.parse(value) : {};
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw new SyntaxError(`[@campxdev/generator] invalid JSON string '${value}' for variables in field ${schema.name}`);
|
|
43
|
+
}
|
|
44
|
+
for (const variable of schema.variables) {
|
|
45
|
+
if (!values[variable]) {
|
|
46
|
+
if (schema.required) {
|
|
47
|
+
throw new Error(`[@campxdev/generator] variable ${variable} is missing for field ${schema.name}`);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Factory function that creates an "Insert Variable" widget for a specific schema field.
|
|
57
|
+
* The widget renders a dropdown of available variables and appends {varName} to the field value.
|
|
58
|
+
*
|
|
59
|
+
* @param targetKey - The schema field key to insert variables into (e.g., 'text', 'content')
|
|
60
|
+
* @returns A PropPanelWidgetProps function that renders the variable picker
|
|
61
|
+
*/
|
|
62
|
+
const createInsertVariableWidget = (targetKey) => {
|
|
63
|
+
return (props) => {
|
|
64
|
+
const { rootElement, changeSchemas, activeSchema, options } = props;
|
|
65
|
+
const variables = options.variables?.textVariables ?? [];
|
|
66
|
+
if (variables.length === 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const container = document.createElement('div');
|
|
70
|
+
container.style.cssText =
|
|
71
|
+
'display:flex; gap:6px; align-items:center; margin-bottom:10px; z-index:9999; position:relative;';
|
|
72
|
+
const label = document.createElement('span');
|
|
73
|
+
label.textContent = 'Insert Variable:';
|
|
74
|
+
label.style.cssText = 'font-size:12px; color:#666; white-space:nowrap;';
|
|
75
|
+
const select = document.createElement('select');
|
|
76
|
+
select.style.cssText =
|
|
77
|
+
'flex:1; height:30px; border:1px solid #E0E0E0; border-radius:4px; padding:0 8px; font-size:13px; background:#fff; cursor:pointer; z-index:9999;';
|
|
78
|
+
const blank = document.createElement('option');
|
|
79
|
+
blank.value = '';
|
|
80
|
+
blank.textContent = '— pick variable —';
|
|
81
|
+
select.appendChild(blank);
|
|
82
|
+
for (const v of variables) {
|
|
83
|
+
const opt = document.createElement('option');
|
|
84
|
+
opt.value = v.value;
|
|
85
|
+
opt.textContent = v.label;
|
|
86
|
+
select.appendChild(opt);
|
|
87
|
+
}
|
|
88
|
+
select.onchange = (e) => {
|
|
89
|
+
const varName = e.target.value;
|
|
90
|
+
if (!varName)
|
|
91
|
+
return;
|
|
92
|
+
const current = String(activeSchema[targetKey] ?? '');
|
|
93
|
+
changeSchemas([{ key: targetKey, value: current + `{${varName}}`, schemaId: activeSchema.id }]);
|
|
94
|
+
select.value = '';
|
|
95
|
+
};
|
|
96
|
+
container.appendChild(label);
|
|
97
|
+
container.appendChild(select);
|
|
98
|
+
rootElement.appendChild(container);
|
|
99
|
+
};
|
|
100
|
+
};
|
|
9
101
|
|
|
10
102
|
// ref: https://github.com/image-size/image-size ----------------------------
|
|
11
103
|
// The following code is adapted from the image-size code. Unnecessary formats and dependencies on Node have been removed.
|
|
@@ -7877,8 +7969,8 @@ const uiRender = async (arg) => {
|
|
|
7877
7969
|
|
|
7878
7970
|
/** Default sample text per barcode type */
|
|
7879
7971
|
const defaultTextByType = {
|
|
7880
|
-
qrcode: '
|
|
7881
|
-
code128: '
|
|
7972
|
+
qrcode: '',
|
|
7973
|
+
code128: '',
|
|
7882
7974
|
code39: 'CODE-{id}',
|
|
7883
7975
|
ean13: '212345678900{check}',
|
|
7884
7976
|
ean8: '0234567{check}',
|
|
@@ -8010,4 +8102,37 @@ const variableBarcodes = BARCODE_TYPES.reduce((acc, type) => Object.assign(acc,
|
|
|
8010
8102
|
const dynamicQrCode = variableBarcodes['qrcode'];
|
|
8011
8103
|
const dynamicBarcode = variableBarcodes['code128'];
|
|
8012
8104
|
|
|
8013
|
-
|
|
8105
|
+
/**
|
|
8106
|
+
* A custom propPanel widget that displays fontSize in pixels (px) while
|
|
8107
|
+
* storing the value internally in points (pt) as pdfme requires.
|
|
8108
|
+
*
|
|
8109
|
+
* Register as `widgets: { fontSizePxWidget }` in Designer options, then
|
|
8110
|
+
* swap the fontSize field's widget to 'fontSizePxWidget' in your propPanel schema.
|
|
8111
|
+
*/
|
|
8112
|
+
const fontSizePxWidget = (props) => {
|
|
8113
|
+
const { rootElement, changeSchemas, activeSchema } = props;
|
|
8114
|
+
const currentPt = activeSchema.fontSize ?? 13;
|
|
8115
|
+
const currentPx = pt2px(currentPt);
|
|
8116
|
+
const wrapper = document.createElement('div');
|
|
8117
|
+
wrapper.style.cssText = 'display:flex;align-items:center;gap:4px;';
|
|
8118
|
+
const input = document.createElement('input');
|
|
8119
|
+
input.type = 'number';
|
|
8120
|
+
input.min = '1';
|
|
8121
|
+
input.value = String(currentPx);
|
|
8122
|
+
input.style.cssText =
|
|
8123
|
+
'width:60px;height:24px;border:1px solid #d9d9d9;border-radius:4px;padding:0 6px;font-size:13px;box-sizing:border-box;';
|
|
8124
|
+
const suffix = document.createElement('span');
|
|
8125
|
+
suffix.textContent = 'px';
|
|
8126
|
+
suffix.style.cssText = 'font-size:12px;color:#888;';
|
|
8127
|
+
input.addEventListener('change', () => {
|
|
8128
|
+
const px = Number(input.value);
|
|
8129
|
+
if (!isNaN(px) && px > 0) {
|
|
8130
|
+
changeSchemas([{ key: 'fontSize', value: px2pt(px), schemaId: activeSchema.id }]);
|
|
8131
|
+
}
|
|
8132
|
+
});
|
|
8133
|
+
wrapper.appendChild(input);
|
|
8134
|
+
wrapper.appendChild(suffix);
|
|
8135
|
+
rootElement.appendChild(wrapper);
|
|
8136
|
+
};
|
|
8137
|
+
|
|
8138
|
+
export { BARCODE_TYPES as B, DEFAULT_BARCODE_COLOR as D, dynamicQrCode as a, dynamicTableSchema as b, validateVariables as c, dynamicBarcode as d, ellipse as e, fontSizePxWidget as f, substituteVariables as g, createInsertVariableWidget as h, imageSchema as i, validateBarcodeInput as j, createBarCode as k, lineSchema as l, DEFAULT_BARCODE_BG_COLOR as m, DEFAULT_BARCODE_INCLUDETEXT as n, cellSchema as o, rectangle as r, signature as s, variableBarcodes as v };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { A as pt2px, F as px2pt } from './helper-DSxGxZ0j.js';
|
|
2
|
+
|
|
3
|
+
const convertSchemaFontSize = (schema, convert) => {
|
|
4
|
+
const result = { ...schema };
|
|
5
|
+
if (result.fontSize != null) {
|
|
6
|
+
result.fontSize = convert(result.fontSize);
|
|
7
|
+
}
|
|
8
|
+
if (result.dynamicFontSize) {
|
|
9
|
+
result.dynamicFontSize = {
|
|
10
|
+
...result.dynamicFontSize,
|
|
11
|
+
min: convert(result.dynamicFontSize.min),
|
|
12
|
+
max: convert(result.dynamicFontSize.max),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
const applyFontSizeConversion = (template, convert) => {
|
|
18
|
+
const result = { ...template };
|
|
19
|
+
result.schemas = template.schemas.map((page) => page.map((schema) => convertSchemaFontSize(schema, convert)));
|
|
20
|
+
const basePdf = template.basePdf;
|
|
21
|
+
if (Array.isArray(basePdf?.staticSchema)) {
|
|
22
|
+
result.basePdf = {
|
|
23
|
+
...basePdf,
|
|
24
|
+
staticSchema: basePdf.staticSchema.map((s) => convertSchemaFontSize(s, convert)),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
/** Convert all fontSize fields in a template from pt (pdfme internal) → px (user-facing). */
|
|
30
|
+
const templatePtToPx = (template) => applyFontSizeConversion(template, pt2px);
|
|
31
|
+
/** Convert all fontSize fields in a template from px (user-facing) → pt (pdfme internal). */
|
|
32
|
+
const templatePxToPt = (template) => applyFontSizeConversion(template, px2pt);
|
|
33
|
+
|
|
34
|
+
export { templatePxToPt as a, templatePtToPx as t };
|