@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,19 +1,111 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var helper = require('./helper-
|
|
3
|
+
var helper = require('./helper-DGH62Z2s.js');
|
|
4
4
|
var SignaturePad = require('signature_pad');
|
|
5
5
|
var lucide = require('lucide');
|
|
6
|
-
var index = require('./index-
|
|
6
|
+
var index = require('./index-CsEKt088.js');
|
|
7
7
|
var buffer = require('buffer');
|
|
8
8
|
var colors = require('./colors-BeBcxfhb.js');
|
|
9
9
|
var uuid = require('uuid');
|
|
10
10
|
var bwipjs = require('bwip-js');
|
|
11
|
+
var expression = require('./expression-CoTzcL7v.js');
|
|
11
12
|
|
|
12
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
|
|
14
15
|
var SignaturePad__default = /*#__PURE__*/_interopDefault(SignaturePad);
|
|
15
16
|
var bwipjs__default = /*#__PURE__*/_interopDefault(bwipjs);
|
|
16
17
|
|
|
18
|
+
const substituteVariables = (text, variablesIn, extraContext) => {
|
|
19
|
+
if (!text) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
let variables;
|
|
23
|
+
try {
|
|
24
|
+
variables =
|
|
25
|
+
typeof variablesIn === 'string'
|
|
26
|
+
? JSON.parse(variablesIn || '{}')
|
|
27
|
+
: variablesIn;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new SyntaxError(`[@campxdev/schemas] MVT: invalid JSON string '${variablesIn}'`);
|
|
31
|
+
}
|
|
32
|
+
// Merge extra context (e.g. currentPage, totalPages) with user variables
|
|
33
|
+
// System context takes precedence over user variables
|
|
34
|
+
const merged = extraContext ? { ...variables, ...extraContext } : variables;
|
|
35
|
+
// Use the full JS expression evaluator — supports {varName}, {expr * 2}, {str.toUpperCase()}, etc.
|
|
36
|
+
const result = expression.replacePlaceholders({ content: text, variables: merged, schemas: [] });
|
|
37
|
+
// Strip any remaining unresolved {placeholders} for clean output
|
|
38
|
+
return result.replace(/\{[^{}]+\}/g, '');
|
|
39
|
+
};
|
|
40
|
+
const validateVariables = (value, schema) => {
|
|
41
|
+
if (!schema.variables || schema.variables.length === 0) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
let values;
|
|
45
|
+
try {
|
|
46
|
+
values = value ? JSON.parse(value) : {};
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw new SyntaxError(`[@campxdev/generator] invalid JSON string '${value}' for variables in field ${schema.name}`);
|
|
50
|
+
}
|
|
51
|
+
for (const variable of schema.variables) {
|
|
52
|
+
if (!values[variable]) {
|
|
53
|
+
if (schema.required) {
|
|
54
|
+
throw new Error(`[@campxdev/generator] variable ${variable} is missing for field ${schema.name}`);
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Factory function that creates an "Insert Variable" widget for a specific schema field.
|
|
64
|
+
* The widget renders a dropdown of available variables and appends {varName} to the field value.
|
|
65
|
+
*
|
|
66
|
+
* @param targetKey - The schema field key to insert variables into (e.g., 'text', 'content')
|
|
67
|
+
* @returns A PropPanelWidgetProps function that renders the variable picker
|
|
68
|
+
*/
|
|
69
|
+
const createInsertVariableWidget = (targetKey) => {
|
|
70
|
+
return (props) => {
|
|
71
|
+
const { rootElement, changeSchemas, activeSchema, options } = props;
|
|
72
|
+
const variables = options.variables?.textVariables ?? [];
|
|
73
|
+
if (variables.length === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const container = document.createElement('div');
|
|
77
|
+
container.style.cssText =
|
|
78
|
+
'display:flex; gap:6px; align-items:center; margin-bottom:10px; z-index:9999; position:relative;';
|
|
79
|
+
const label = document.createElement('span');
|
|
80
|
+
label.textContent = 'Insert Variable:';
|
|
81
|
+
label.style.cssText = 'font-size:12px; color:#666; white-space:nowrap;';
|
|
82
|
+
const select = document.createElement('select');
|
|
83
|
+
select.style.cssText =
|
|
84
|
+
'flex:1; height:30px; border:1px solid #E0E0E0; border-radius:4px; padding:0 8px; font-size:13px; background:#fff; cursor:pointer; z-index:9999;';
|
|
85
|
+
const blank = document.createElement('option');
|
|
86
|
+
blank.value = '';
|
|
87
|
+
blank.textContent = '— pick variable —';
|
|
88
|
+
select.appendChild(blank);
|
|
89
|
+
for (const v of variables) {
|
|
90
|
+
const opt = document.createElement('option');
|
|
91
|
+
opt.value = v.value;
|
|
92
|
+
opt.textContent = v.label;
|
|
93
|
+
select.appendChild(opt);
|
|
94
|
+
}
|
|
95
|
+
select.onchange = (e) => {
|
|
96
|
+
const varName = e.target.value;
|
|
97
|
+
if (!varName)
|
|
98
|
+
return;
|
|
99
|
+
const current = String(activeSchema[targetKey] ?? '');
|
|
100
|
+
changeSchemas([{ key: targetKey, value: current + `{${varName}}`, schemaId: activeSchema.id }]);
|
|
101
|
+
select.value = '';
|
|
102
|
+
};
|
|
103
|
+
container.appendChild(label);
|
|
104
|
+
container.appendChild(select);
|
|
105
|
+
rootElement.appendChild(container);
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
17
109
|
// ref: https://github.com/image-size/image-size ----------------------------
|
|
18
110
|
// The following code is adapted from the image-size code. Unnecessary formats and dependencies on Node have been removed.
|
|
19
111
|
const decoder = new TextDecoder();
|
|
@@ -7510,7 +7602,7 @@ const pdfRender = async (arg) => {
|
|
|
7510
7602
|
// Dynamic mode: schema.text has a template → resolve with variables from value
|
|
7511
7603
|
// Static mode: no schema.text → use value directly as barcode input
|
|
7512
7604
|
const resolved = schema.text
|
|
7513
|
-
? (schema.readOnly ? value :
|
|
7605
|
+
? (schema.readOnly ? value : substituteVariables(schema.text, value || '{}', pageContext))
|
|
7514
7606
|
: value || '';
|
|
7515
7607
|
if (!resolved || !validateBarcodeInput(schema.type, resolved))
|
|
7516
7608
|
return;
|
|
@@ -7772,7 +7864,7 @@ const uiRender = async (arg) => {
|
|
|
7772
7864
|
return {};
|
|
7773
7865
|
}
|
|
7774
7866
|
})();
|
|
7775
|
-
const resolved =
|
|
7867
|
+
const resolved = substituteVariables(schema.text || '', variables, pageContext);
|
|
7776
7868
|
if (mode === 'designer') {
|
|
7777
7869
|
// Designer: show a semi-transparent text input for the template string + barcode preview
|
|
7778
7870
|
const input = document.createElement('input');
|
|
@@ -7811,7 +7903,7 @@ const uiRender = async (arg) => {
|
|
|
7811
7903
|
}
|
|
7812
7904
|
if (onChange)
|
|
7813
7905
|
onChange(changes);
|
|
7814
|
-
const r =
|
|
7906
|
+
const r = substituteVariables(newText, vars, pageContext);
|
|
7815
7907
|
void renderBarcodePreview(schema, r, previewWrap);
|
|
7816
7908
|
}, 300);
|
|
7817
7909
|
});
|
|
@@ -7842,7 +7934,7 @@ const uiRender = async (arg) => {
|
|
|
7842
7934
|
minHeight: '40px',
|
|
7843
7935
|
});
|
|
7844
7936
|
const refreshPreview = () => {
|
|
7845
|
-
const r =
|
|
7937
|
+
const r = substituteVariables(schema.text || '', variables, pageContext);
|
|
7846
7938
|
void renderBarcodePreview(schema, r, previewWrap);
|
|
7847
7939
|
};
|
|
7848
7940
|
for (const varName of schema.variables) {
|
|
@@ -7884,8 +7976,8 @@ const uiRender = async (arg) => {
|
|
|
7884
7976
|
|
|
7885
7977
|
/** Default sample text per barcode type */
|
|
7886
7978
|
const defaultTextByType = {
|
|
7887
|
-
qrcode: '
|
|
7888
|
-
code128: '
|
|
7979
|
+
qrcode: '',
|
|
7980
|
+
code128: '',
|
|
7889
7981
|
code39: 'CODE-{id}',
|
|
7890
7982
|
ean13: '212345678900{check}',
|
|
7891
7983
|
ean8: '0234567{check}',
|
|
@@ -7937,7 +8029,7 @@ const getPropPanelByType = (type) => {
|
|
|
7937
8029
|
const defaultVars = {};
|
|
7938
8030
|
updateVariablesFromText(defaultText, defaultVars);
|
|
7939
8031
|
const { width, height } = defaultSizeByType[type] ?? { width: 40, height: 20 };
|
|
7940
|
-
const insertVariableWidget =
|
|
8032
|
+
const insertVariableWidget = createInsertVariableWidget('text');
|
|
7941
8033
|
return {
|
|
7942
8034
|
schema: ({ i18n }) => ({
|
|
7943
8035
|
insertVariablePicker: {
|
|
@@ -8017,19 +8109,56 @@ const variableBarcodes = BARCODE_TYPES.reduce((acc, type) => Object.assign(acc,
|
|
|
8017
8109
|
const dynamicQrCode = variableBarcodes['qrcode'];
|
|
8018
8110
|
const dynamicBarcode = variableBarcodes['code128'];
|
|
8019
8111
|
|
|
8112
|
+
/**
|
|
8113
|
+
* A custom propPanel widget that displays fontSize in pixels (px) while
|
|
8114
|
+
* storing the value internally in points (pt) as pdfme requires.
|
|
8115
|
+
*
|
|
8116
|
+
* Register as `widgets: { fontSizePxWidget }` in Designer options, then
|
|
8117
|
+
* swap the fontSize field's widget to 'fontSizePxWidget' in your propPanel schema.
|
|
8118
|
+
*/
|
|
8119
|
+
const fontSizePxWidget = (props) => {
|
|
8120
|
+
const { rootElement, changeSchemas, activeSchema } = props;
|
|
8121
|
+
const currentPt = activeSchema.fontSize ?? 13;
|
|
8122
|
+
const currentPx = helper.pt2px(currentPt);
|
|
8123
|
+
const wrapper = document.createElement('div');
|
|
8124
|
+
wrapper.style.cssText = 'display:flex;align-items:center;gap:4px;';
|
|
8125
|
+
const input = document.createElement('input');
|
|
8126
|
+
input.type = 'number';
|
|
8127
|
+
input.min = '1';
|
|
8128
|
+
input.value = String(currentPx);
|
|
8129
|
+
input.style.cssText =
|
|
8130
|
+
'width:60px;height:24px;border:1px solid #d9d9d9;border-radius:4px;padding:0 6px;font-size:13px;box-sizing:border-box;';
|
|
8131
|
+
const suffix = document.createElement('span');
|
|
8132
|
+
suffix.textContent = 'px';
|
|
8133
|
+
suffix.style.cssText = 'font-size:12px;color:#888;';
|
|
8134
|
+
input.addEventListener('change', () => {
|
|
8135
|
+
const px = Number(input.value);
|
|
8136
|
+
if (!isNaN(px) && px > 0) {
|
|
8137
|
+
changeSchemas([{ key: 'fontSize', value: helper.px2pt(px), schemaId: activeSchema.id }]);
|
|
8138
|
+
}
|
|
8139
|
+
});
|
|
8140
|
+
wrapper.appendChild(input);
|
|
8141
|
+
wrapper.appendChild(suffix);
|
|
8142
|
+
rootElement.appendChild(wrapper);
|
|
8143
|
+
};
|
|
8144
|
+
|
|
8020
8145
|
exports.BARCODE_TYPES = BARCODE_TYPES;
|
|
8021
8146
|
exports.DEFAULT_BARCODE_BG_COLOR = DEFAULT_BARCODE_BG_COLOR;
|
|
8022
8147
|
exports.DEFAULT_BARCODE_COLOR = DEFAULT_BARCODE_COLOR;
|
|
8023
8148
|
exports.DEFAULT_BARCODE_INCLUDETEXT = DEFAULT_BARCODE_INCLUDETEXT;
|
|
8024
8149
|
exports.cellSchema = cellSchema;
|
|
8025
8150
|
exports.createBarCode = createBarCode;
|
|
8151
|
+
exports.createInsertVariableWidget = createInsertVariableWidget;
|
|
8026
8152
|
exports.dynamicBarcode = dynamicBarcode;
|
|
8027
8153
|
exports.dynamicQrCode = dynamicQrCode;
|
|
8028
8154
|
exports.dynamicTableSchema = dynamicTableSchema;
|
|
8029
8155
|
exports.ellipse = ellipse;
|
|
8156
|
+
exports.fontSizePxWidget = fontSizePxWidget;
|
|
8030
8157
|
exports.imageSchema = imageSchema;
|
|
8031
8158
|
exports.lineSchema = lineSchema;
|
|
8032
8159
|
exports.rectangle = rectangle;
|
|
8033
8160
|
exports.signature = signature;
|
|
8161
|
+
exports.substituteVariables = substituteVariables;
|
|
8034
8162
|
exports.validateBarcodeInput = validateBarcodeInput;
|
|
8163
|
+
exports.validateVariables = validateVariables;
|
|
8035
8164
|
exports.variableBarcodes = variableBarcodes;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var helper = require('./helper-DGH62Z2s.js');
|
|
4
|
+
|
|
5
|
+
const convertSchemaFontSize = (schema, convert) => {
|
|
6
|
+
const result = { ...schema };
|
|
7
|
+
if (result.fontSize != null) {
|
|
8
|
+
result.fontSize = convert(result.fontSize);
|
|
9
|
+
}
|
|
10
|
+
if (result.dynamicFontSize) {
|
|
11
|
+
result.dynamicFontSize = {
|
|
12
|
+
...result.dynamicFontSize,
|
|
13
|
+
min: convert(result.dynamicFontSize.min),
|
|
14
|
+
max: convert(result.dynamicFontSize.max),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
const applyFontSizeConversion = (template, convert) => {
|
|
20
|
+
const result = { ...template };
|
|
21
|
+
result.schemas = template.schemas.map((page) => page.map((schema) => convertSchemaFontSize(schema, convert)));
|
|
22
|
+
const basePdf = template.basePdf;
|
|
23
|
+
if (Array.isArray(basePdf?.staticSchema)) {
|
|
24
|
+
result.basePdf = {
|
|
25
|
+
...basePdf,
|
|
26
|
+
staticSchema: basePdf.staticSchema.map((s) => convertSchemaFontSize(s, convert)),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
/** Convert all fontSize fields in a template from pt (pdfme internal) → px (user-facing). */
|
|
32
|
+
const templatePtToPx = (template) => applyFontSizeConversion(template, helper.pt2px);
|
|
33
|
+
/** Convert all fontSize fields in a template from px (user-facing) → pt (pdfme internal). */
|
|
34
|
+
const templatePxToPt = (template) => applyFontSizeConversion(template, helper.px2pt);
|
|
35
|
+
|
|
36
|
+
exports.templatePtToPx = templatePtToPx;
|
|
37
|
+
exports.templatePxToPt = templatePxToPt;
|