@campxdev/pdfme 1.2.2 → 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.
Files changed (46) hide show
  1. package/dist/cjs/chunks/{index-C8qZMUOU.js → fontSizePxWidget-Drk8HKGH.js} +138 -9
  2. package/dist/cjs/chunks/fontSizeTransform-CQQ_O42f.js +37 -0
  3. package/dist/cjs/chunks/{helper-BfoMn47R.js → helper-DGH62Z2s.js} +4 -0
  4. package/dist/cjs/chunks/{index-COKtXyPp.js → index-CoNR0xQU.js} +6 -2
  5. package/dist/cjs/chunks/{index-CVqJfcgy.js → index-CsEKt088.js} +697 -547
  6. package/dist/cjs/chunks/{pluginRegistry-C8bMreez.js → pluginRegistry-D2vr9MUy.js} +1 -1
  7. package/dist/cjs/common.js +7 -3
  8. package/dist/cjs/converter.js +1 -1
  9. package/dist/cjs/generator.js +3 -3
  10. package/dist/cjs/index.js +23 -16
  11. package/dist/cjs/print-designer-editor.js +3320 -3296
  12. package/dist/cjs/schemas.js +500 -38
  13. package/dist/cjs/ui.js +2007 -1868
  14. package/dist/esm/chunks/{index-C4F7EwBG.js → fontSizePxWidget-CbzQrSSM.js} +130 -5
  15. package/dist/esm/chunks/fontSizeTransform-CkTVJdRF.js +34 -0
  16. package/dist/esm/chunks/{helper-D5PPN6Bv.js → helper-DSxGxZ0j.js} +4 -1
  17. package/dist/esm/chunks/{index-CDhErAtE.js → index-DJkUkUo9.js} +4 -3
  18. package/dist/esm/chunks/{index-C7jr4GIK.js → index-D_-j4c4P.js} +691 -544
  19. package/dist/esm/chunks/{pluginRegistry-B-XSNgmK.js → pluginRegistry-Bgrz5qWG.js} +1 -1
  20. package/dist/esm/common.js +4 -3
  21. package/dist/esm/converter.js +1 -1
  22. package/dist/esm/generator.js +3 -3
  23. package/dist/esm/index.js +7 -6
  24. package/dist/esm/print-designer-editor.js +3307 -3286
  25. package/dist/esm/schemas.js +472 -13
  26. package/dist/esm/ui.js +2007 -1868
  27. package/dist/types/_vendors/common/fontSizeTransform.d.ts +5 -0
  28. package/dist/types/_vendors/common/helper.d.ts +1 -0
  29. package/dist/types/_vendors/common/index.d.ts +3 -2
  30. package/dist/types/_vendors/print-designer-editor/index.d.ts +2 -1
  31. package/dist/types/_vendors/print-designer-editor/types.d.ts +1 -1
  32. package/dist/types/_vendors/print-designer-editor/useDesigner.d.ts +1 -1
  33. package/dist/types/_vendors/schemas/index.d.ts +8 -2
  34. package/dist/types/_vendors/schemas/richText/helper.d.ts +3 -0
  35. package/dist/types/_vendors/schemas/richText/index.d.ts +4 -0
  36. package/dist/types/_vendors/schemas/richText/pdfRender.d.ts +3 -0
  37. package/dist/types/_vendors/schemas/richText/propPanel.d.ts +3 -0
  38. package/dist/types/_vendors/schemas/richText/types.d.ts +7 -0
  39. package/dist/types/_vendors/schemas/richText/uiRender.d.ts +3 -0
  40. package/dist/types/_vendors/schemas/singleVariableText/index.d.ts +4 -0
  41. package/dist/types/_vendors/schemas/singleVariableText/propPanel.d.ts +3 -0
  42. package/dist/types/_vendors/schemas/singleVariableText/types.d.ts +4 -0
  43. package/dist/types/_vendors/schemas/text/fontSizePxWidget.d.ts +9 -0
  44. package/dist/types/_vendors/ui/components/CtlBar.d.ts +1 -1
  45. package/dist/types/_vendors/ui/components/Paper.d.ts +1 -0
  46. package/package.json +1 -1
@@ -1,11 +1,103 @@
1
- import { E as px2mm, Z as ZOOM, c as b64toUint8Array, y as mm2pt, r as getFallbackFontName, D as DEFAULT_FONT_NAME } from './helper-D5PPN6Bv.js';
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, a as addAlphaToHex, r as readFile, d as convertForPdfLayoutProps, H as HEX_COLOR_PATTERN, h as hex2PrintingColor, e as rotatePoint, f as getDefaultCellStyles, u as uiRender$2, p as pdfRender$2, j as substituteVariables, k as createErrorElm, l as createInsertVariableWidget } from './index-C7jr4GIK.js';
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: 'https://pdfme.com/{id}',
7881
- code128: 'ORDER-{orderId}',
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
- export { BARCODE_TYPES as B, DEFAULT_BARCODE_COLOR as D, dynamicQrCode as a, dynamicTableSchema as b, validateBarcodeInput as c, dynamicBarcode as d, ellipse as e, createBarCode as f, DEFAULT_BARCODE_BG_COLOR as g, DEFAULT_BARCODE_INCLUDETEXT as h, imageSchema as i, cellSchema as j, lineSchema as l, rectangle as r, signature as s, variableBarcodes as v };
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 };
@@ -17262,6 +17262,9 @@ const pt2mm = (pt) => {
17262
17262
  const pt2px = (pt) => {
17263
17263
  return pt * PT_TO_PX_RATIO;
17264
17264
  };
17265
+ const px2pt = (px) => {
17266
+ return px / PT_TO_PX_RATIO;
17267
+ };
17265
17268
  const px2mm = (px) => {
17266
17269
  // http://www.endmemo.com/sconvert/millimeterpixel.php
17267
17270
  const ratio = 0.26458333333333;
@@ -17426,4 +17429,4 @@ const checkGenerateProps = (data) => {
17426
17429
  checkProps(data, GenerateProps);
17427
17430
  };
17428
17431
 
17429
- export { pt2px as A, BLANK_A4_PDF as B, CUSTOM_A4_PDF as C, DEFAULT_FONT_NAME as D, px2mm as E, MM_TO_PT_RATIO as M, PT_TO_MM_RATIO as P, ZOOM as Z, BLANK_PDF as a, PT_TO_PX_RATIO as b, b64toUint8Array as c, checkDesignerProps as d, checkFont as e, checkGenerateProps as f, checkInputs as g, checkPreviewProps as h, checkTemplate as i, checkUIOptions as j, checkUIProps as k, cloneDeep as l, getAllFonts as m, getAllFontsWithGoogle as n, getB64BasePdf as o, getBuiltinFontsData as p, getDefaultFont as q, getFallbackFontName as r, getGoogleFontsData as s, getInputFromTemplate as t, googleFonts as u, isBlankPdf as v, isGoogleFont as w, isHexValid as x, mm2pt as y, pt2mm as z };
17432
+ export { pt2px as A, BLANK_A4_PDF as B, CUSTOM_A4_PDF as C, DEFAULT_FONT_NAME as D, px2mm as E, px2pt as F, MM_TO_PT_RATIO as M, PT_TO_MM_RATIO as P, ZOOM as Z, BLANK_PDF as a, PT_TO_PX_RATIO as b, b64toUint8Array as c, checkDesignerProps as d, checkFont as e, checkGenerateProps as f, checkInputs as g, checkPreviewProps as h, checkTemplate as i, checkUIOptions as j, checkUIProps as k, cloneDeep as l, getAllFonts as m, getAllFontsWithGoogle as n, getB64BasePdf as o, getBuiltinFontsData as p, getDefaultFont as q, getFallbackFontName as r, getGoogleFontsData as s, getInputFromTemplate as t, googleFonts as u, isBlankPdf as v, isGoogleFont as w, isHexValid as x, mm2pt as y, pt2mm as z };
@@ -1,6 +1,7 @@
1
- import { o as getB64BasePdf } from './helper-D5PPN6Bv.js';
2
- export { B as BLANK_A4_PDF, a as BLANK_PDF, C as CUSTOM_A4_PDF, D as DEFAULT_FONT_NAME, M as MM_TO_PT_RATIO, P as PT_TO_MM_RATIO, b as PT_TO_PX_RATIO, Z as ZOOM, c as b64toUint8Array, d as checkDesignerProps, e as checkFont, f as checkGenerateProps, g as checkInputs, h as checkPreviewProps, i as checkTemplate, j as checkUIOptions, k as checkUIProps, l as cloneDeep, m as getAllFonts, n as getAllFontsWithGoogle, p as getBuiltinFontsData, q as getDefaultFont, r as getFallbackFontName, s as getGoogleFontsData, t as getInputFromTemplate, u as googleFonts, v as isBlankPdf, w as isGoogleFont, x as isHexValid, y as mm2pt, z as pt2mm, A as pt2px, E as px2mm } from './helper-D5PPN6Bv.js';
3
- export { g as getDynamicTemplate, p as pluginRegistry } from './pluginRegistry-B-XSNgmK.js';
1
+ import { o as getB64BasePdf } from './helper-DSxGxZ0j.js';
2
+ export { B as BLANK_A4_PDF, a as BLANK_PDF, C as CUSTOM_A4_PDF, D as DEFAULT_FONT_NAME, M as MM_TO_PT_RATIO, P as PT_TO_MM_RATIO, b as PT_TO_PX_RATIO, Z as ZOOM, c as b64toUint8Array, d as checkDesignerProps, e as checkFont, f as checkGenerateProps, g as checkInputs, h as checkPreviewProps, i as checkTemplate, j as checkUIOptions, k as checkUIProps, l as cloneDeep, m as getAllFonts, n as getAllFontsWithGoogle, p as getBuiltinFontsData, q as getDefaultFont, r as getFallbackFontName, s as getGoogleFontsData, t as getInputFromTemplate, u as googleFonts, v as isBlankPdf, w as isGoogleFont, x as isHexValid, y as mm2pt, z as pt2mm, A as pt2px, E as px2mm, F as px2pt } from './helper-DSxGxZ0j.js';
3
+ export { g as getDynamicTemplate, p as pluginRegistry } from './pluginRegistry-Bgrz5qWG.js';
4
+ export { t as templatePtToPx, a as templatePxToPt } from './fontSizeTransform-CkTVJdRF.js';
4
5
  export { r as replacePlaceholders } from './expression-B-F1KCfk.js';
5
6
  import 'zod';
6
7
  import 'buffer';