@pdfme/schemas 6.1.0-dev.2 → 6.1.1-dev.10
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/{builtins-CWHhKSVA.js → builtins-Clh58o_b.js} +313 -484
- package/dist/builtins-Clh58o_b.js.map +1 -0
- package/dist/builtins.d.ts +1 -1
- package/dist/builtins.js +1 -1
- package/dist/checkbox/index.d.ts +2 -2
- package/dist/dynamicLayout.d.ts +4 -0
- package/dist/dynamicLayout.js +20 -0
- package/dist/dynamicLayout.js.map +1 -0
- package/dist/dynamicTemplate-CB2Hj9cN.js +65 -0
- package/dist/dynamicTemplate-CB2Hj9cN.js.map +1 -0
- package/dist/{dynamicTemplate-DmuRoTw4.js → dynamicTemplate-CjbGepw4.js} +15 -10
- package/dist/dynamicTemplate-CjbGepw4.js.map +1 -0
- package/dist/{lists-B6dmgpkS.js → dynamicTemplate-Fn7mpUsu.js} +3 -6
- package/dist/dynamicTemplate-Fn7mpUsu.js.map +1 -0
- package/dist/graphics/image.d.ts +1 -1
- package/dist/graphics/signature.d.ts +1 -1
- package/dist/helper-BJzBqIT4.js +40 -0
- package/dist/helper-BJzBqIT4.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -51
- package/dist/index.js.map +1 -1
- package/dist/list/types.d.ts +0 -5
- package/dist/lists.d.ts +2 -1
- package/dist/lists.js +3 -2
- package/dist/measure-Bjmh9Ro3.js +585 -0
- package/dist/measure-Bjmh9Ro3.js.map +1 -0
- package/dist/multiVariableText/dynamicTemplate.d.ts +2 -0
- package/dist/radioGroup/index.d.ts +2 -2
- package/dist/select/index.d.ts +2 -2
- package/dist/shapes/line.d.ts +1 -1
- package/dist/shapes/rectAndEllipse.d.ts +1 -2
- package/dist/{helper-M_MmV_d5.js → splitRange-CpXivbmJ.js} +46 -5
- package/dist/splitRange-CpXivbmJ.js.map +1 -0
- package/dist/splitRange.d.ts +16 -0
- package/dist/tables/helper.d.ts +8 -8
- package/dist/tables.d.ts +1 -0
- package/dist/tables.js +3 -2
- package/dist/text/constants.d.ts +3 -0
- package/dist/text/dynamicTemplate.d.ts +2 -0
- package/dist/text/linkAnnotation.d.ts +14 -0
- package/dist/text/measure.d.ts +26 -0
- package/dist/text/overflow.d.ts +7 -0
- package/dist/text/richTextPdfRender.d.ts +2 -1
- package/dist/text/types.d.ts +3 -0
- package/dist/texts.d.ts +5 -0
- package/dist/texts.js +4 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +3 -2
- package/dist/utils.js.map +1 -1
- package/package.json +16 -1
- package/dist/builtins-CWHhKSVA.js.map +0 -1
- package/dist/dynamicTemplate-DmuRoTw4.js.map +0 -1
- package/dist/helper-M_MmV_d5.js.map +0 -1
- package/dist/lists-B6dmgpkS.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper-BJzBqIT4.js","names":[],"sources":["../src/multiVariableText/helper.ts"],"sourcesContent":["import { MultiVariableTextSchema } from './types.js';\nimport { escapeInlineMarkdown } from '../text/inlineMarkdown.js';\n\nexport const substituteVariables = (\n text: string,\n variablesIn: string | Record<string, string>,\n valueMapper: (value: string, variableName: string) => string = (value) => value,\n): string => {\n if (!text) {\n return '';\n }\n\n let substitutedText = text;\n\n if (variablesIn) {\n let variables: Record<string, string>;\n try {\n variables =\n typeof variablesIn === 'string'\n ? (JSON.parse(variablesIn || '{}') as Record<string, string>)\n : variablesIn;\n } catch {\n throw new SyntaxError(`[@pdfme/schemas] MVT: invalid JSON string '${variablesIn as string}'`);\n }\n\n Object.keys(variables).forEach((variableName) => {\n // handle special characters in variable name\n const variableForRegex = variableName.replace(/[/\\-\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n const regex = new RegExp('\\\\{' + variableForRegex + '\\\\}', 'g');\n substitutedText = substitutedText.replace(\n regex,\n valueMapper(variables[variableName], variableName),\n );\n });\n }\n\n // Remove any variables that were not substituted from inputs\n substitutedText = substitutedText.replace(/{[^{}]+}/g, '');\n\n return substitutedText;\n};\n\nexport const substituteVariablesAsInlineMarkdownLiterals = (\n text: string,\n variablesIn: string | Record<string, string>,\n): string => substituteVariables(text, variablesIn, escapeInlineMarkdown);\n\nexport const validateVariables = (value: string, schema: MultiVariableTextSchema): boolean => {\n if (schema.variables.length === 0) {\n return true;\n }\n\n let values;\n try {\n values = value ? (JSON.parse(value) as Record<string, string>) : {};\n } catch {\n throw new SyntaxError(\n `[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`,\n );\n }\n\n for (const variable of schema.variables) {\n if (!values[variable]) {\n if (schema.required) {\n throw new Error(\n `[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`,\n );\n }\n // If not required, then simply don't render this field if an input is missing\n return false;\n }\n }\n\n return true;\n};\n"],"mappings":";;AAGA,IAAa,uBACX,MACA,aACA,eAAgE,UAAU,UAC/D;AACX,KAAI,CAAC,KACH,QAAO;CAGT,IAAI,kBAAkB;AAEtB,KAAI,aAAa;EACf,IAAI;AACJ,MAAI;AACF,eACE,OAAO,gBAAgB,WAClB,KAAK,MAAM,eAAe,KAAK,GAChC;UACA;AACN,SAAM,IAAI,YAAY,8CAA8C,YAAsB,GAAG;;AAG/F,SAAO,KAAK,UAAU,CAAC,SAAS,iBAAiB;GAE/C,MAAM,mBAAmB,aAAa,QAAQ,0BAA0B,OAAO;GAC/E,MAAM,QAAQ,IAAI,OAAO,QAAQ,mBAAmB,OAAO,IAAI;AAC/D,qBAAkB,gBAAgB,QAChC,OACA,YAAY,UAAU,eAAe,aAAa,CACnD;IACD;;AAIJ,mBAAkB,gBAAgB,QAAQ,aAAa,GAAG;AAE1D,QAAO;;AAGT,IAAa,+CACX,MACA,gBACW,oBAAoB,MAAM,aAAa,qBAAqB;AAEzE,IAAa,qBAAqB,OAAe,WAA6C;AAC5F,KAAI,OAAO,UAAU,WAAW,EAC9B,QAAO;CAGT,IAAI;AACJ,KAAI;AACF,WAAS,QAAS,KAAK,MAAM,MAAM,GAA8B,EAAE;SAC7D;AACN,QAAM,IAAI,YACR,2CAA2C,MAAM,2BAA2B,OAAO,OACpF;;AAGH,MAAK,MAAM,YAAY,OAAO,UAC5B,KAAI,CAAC,OAAO,WAAW;AACrB,MAAI,OAAO,SACT,OAAM,IAAI,MACR,+BAA+B,SAAS,wBAAwB,OAAO,OACxE;AAGH,SAAO;;AAIX,QAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,3 +18,4 @@ export { builtInPlugins } from './builtins.js';
|
|
|
18
18
|
export { text, multiVariableText, list, image, signature, svg, table, barcodes, line, rectangle, ellipse, dateTime, date, time, select, radioGroup, checkbox, };
|
|
19
19
|
export { getDynamicHeightsForTable, getDynamicLayoutForTable } from './tables.js';
|
|
20
20
|
export { getDynamicLayoutForList } from './lists.js';
|
|
21
|
+
export { BUILT_IN_DYNAMIC_LAYOUT_SPLIT_UNITS, LIST_ITEM_SPLIT_UNIT, TABLE_BODY_SPLIT_UNIT, TEXT_LINE_SPLIT_UNIT, createListItemSplitRange, createTableBodySplitRange, createTextLineSplitRange, getListItemRange, getTableBodyRange, getTextLineRange, type BuiltInDynamicLayoutSplitUnit, } from './splitRange.js';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
1
|
+
import { E as DEFAULT_ALIGNMENT, K as VERTICAL_ALIGN_MIDDLE, O as DEFAULT_FONT_COLOR, R as PLACEHOLDER_FONT_COLOR, a as createListItemSplitRange, c as getListItemRange, h as getFontKitFont, i as TEXT_LINE_SPLIT_UNIT, 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, w as CODE_BACKGROUND_COLOR, z as SYNTHETIC_BOLD_CSS_TEXT_SHADOW } from "./splitRange-CpXivbmJ.js";
|
|
2
|
+
import { d as resolveFontVariant, l as isInlineMarkdownTextSchema, m as parseInlineMarkdown } from "./measure-Bjmh9Ro3.js";
|
|
3
|
+
import { a as mapVerticalAlignToFlex, c as Formatter, 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-Clh58o_b.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-CjbGepw4.js";
|
|
4
5
|
import { addAlphaToHex, convertForPdfLayoutProps, createErrorElm, createSvgStr, hex2PrintingColor, isEditable, readFile, rotatePoint } from "./utils.js";
|
|
5
|
-
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 "./
|
|
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-Fn7mpUsu.js";
|
|
7
|
+
import { n as substituteVariablesAsInlineMarkdownLiterals, r as validateVariables, t as substituteVariables } from "./helper-BJzBqIT4.js";
|
|
6
8
|
import "./tables.js";
|
|
9
|
+
import "./lists.js";
|
|
7
10
|
import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, mm2pt, px2mm } from "@pdfme/common";
|
|
8
11
|
import { Buffer as Buffer$1 } from "buffer";
|
|
9
12
|
import { toRadians } from "@pdfme/pdf-lib";
|
|
@@ -36,45 +39,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
39
|
enumerable: true
|
|
37
40
|
}) : target, mod));
|
|
38
41
|
//#endregion
|
|
39
|
-
//#region src/multiVariableText/helper.ts
|
|
40
|
-
var substituteVariables = (text, variablesIn, valueMapper = (value) => value) => {
|
|
41
|
-
if (!text) return "";
|
|
42
|
-
let substitutedText = text;
|
|
43
|
-
if (variablesIn) {
|
|
44
|
-
let variables;
|
|
45
|
-
try {
|
|
46
|
-
variables = typeof variablesIn === "string" ? JSON.parse(variablesIn || "{}") : variablesIn;
|
|
47
|
-
} catch {
|
|
48
|
-
throw new SyntaxError(`[@pdfme/schemas] MVT: invalid JSON string '${variablesIn}'`);
|
|
49
|
-
}
|
|
50
|
-
Object.keys(variables).forEach((variableName) => {
|
|
51
|
-
const variableForRegex = variableName.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
52
|
-
const regex = new RegExp("\\{" + variableForRegex + "\\}", "g");
|
|
53
|
-
substitutedText = substitutedText.replace(regex, valueMapper(variables[variableName], variableName));
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
substitutedText = substitutedText.replace(/{[^{}]+}/g, "");
|
|
57
|
-
return substitutedText;
|
|
58
|
-
};
|
|
59
|
-
var substituteVariablesAsInlineMarkdownLiterals = (text, variablesIn) => substituteVariables(text, variablesIn, escapeInlineMarkdown);
|
|
60
|
-
var validateVariables = (value, schema) => {
|
|
61
|
-
if (schema.variables.length === 0) return true;
|
|
62
|
-
let values;
|
|
63
|
-
try {
|
|
64
|
-
values = value ? JSON.parse(value) : {};
|
|
65
|
-
} catch {
|
|
66
|
-
throw new SyntaxError(`[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`);
|
|
67
|
-
}
|
|
68
|
-
for (const variable of schema.variables) if (!values[variable]) {
|
|
69
|
-
if (schema.required) throw new Error(`[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`);
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return true;
|
|
73
|
-
};
|
|
74
|
-
//#endregion
|
|
75
42
|
//#region src/multiVariableText/pdfRender.ts
|
|
76
43
|
var pdfRender$3 = async (arg) => {
|
|
77
44
|
const { value, schema, ...rest } = arg;
|
|
45
|
+
if (schema.readOnly) {
|
|
46
|
+
await pdfRender$4({
|
|
47
|
+
value,
|
|
48
|
+
schema,
|
|
49
|
+
...rest
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
78
53
|
if (!validateVariables(value, schema)) return;
|
|
79
54
|
await pdfRender$4({
|
|
80
55
|
value: isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(schema.text || "", value) : substituteVariables(schema.text || "", value),
|
|
@@ -268,11 +243,22 @@ var uiRender$3 = async (arg) => {
|
|
|
268
243
|
const { value, schema, rootElement, mode, onChange, ...rest } = arg;
|
|
269
244
|
let text = schema.text;
|
|
270
245
|
let numVariables = schema.variables.length;
|
|
271
|
-
|
|
246
|
+
const renderResolvedValue = schema.readOnly === true && mode !== "designer";
|
|
247
|
+
const renderValue = renderResolvedValue ? value : isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(text, value) : substituteVariables(text, value);
|
|
248
|
+
if (mode === "form" && numVariables > 0 && !renderResolvedValue) {
|
|
249
|
+
if (getTextLineRange(schema)) {
|
|
250
|
+
await uiRender$4({
|
|
251
|
+
value: renderValue,
|
|
252
|
+
schema,
|
|
253
|
+
mode: "viewer",
|
|
254
|
+
rootElement,
|
|
255
|
+
...rest
|
|
256
|
+
});
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
272
259
|
await formUiRender(arg);
|
|
273
260
|
return;
|
|
274
261
|
}
|
|
275
|
-
const renderValue = isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(text, value) : substituteVariables(text, value);
|
|
276
262
|
await uiRender$4({
|
|
277
263
|
value: isEditable(mode, schema) ? text : renderValue,
|
|
278
264
|
schema,
|
|
@@ -375,7 +361,9 @@ var applyInlineMarkdownStyle = (arg) => {
|
|
|
375
361
|
element.style.textShadow = SYNTHETIC_BOLD_CSS_TEXT_SHADOW;
|
|
376
362
|
}
|
|
377
363
|
if (resolvedFont.syntheticItalic) element.style.fontStyle = "italic";
|
|
378
|
-
|
|
364
|
+
const textDecorations = [];
|
|
365
|
+
if (run.strikethrough) textDecorations.push("line-through");
|
|
366
|
+
if (textDecorations.length > 0) element.style.textDecoration = textDecorations.join(" ");
|
|
379
367
|
if (run.code) {
|
|
380
368
|
element.style.backgroundColor = CODE_BACKGROUND_COLOR;
|
|
381
369
|
element.style.borderRadius = "2px";
|
|
@@ -622,7 +610,7 @@ var rectanglePdfRender$2 = rectangle.pdf;
|
|
|
622
610
|
var pdfRender$2 = async (arg) => {
|
|
623
611
|
const { schema, value } = arg;
|
|
624
612
|
const items = normalizeListItems(value);
|
|
625
|
-
const range = schema
|
|
613
|
+
const range = getListItemRange(schema) ?? {
|
|
626
614
|
start: 0,
|
|
627
615
|
end: items.length
|
|
628
616
|
};
|
|
@@ -887,7 +875,7 @@ var uiRender$2 = async (arg) => {
|
|
|
887
875
|
const usePlaceholder = editable && !value && Boolean(placeholder);
|
|
888
876
|
const items = normalizeListItems(usePlaceholder ? placeholder || "" : value);
|
|
889
877
|
const originalItems = normalizeListItemEntries(value);
|
|
890
|
-
const range = schema
|
|
878
|
+
const range = getListItemRange(schema) ?? {
|
|
891
879
|
start: 0,
|
|
892
880
|
end: items.length
|
|
893
881
|
};
|
|
@@ -2515,7 +2503,7 @@ async function drawTable(arg, table) {
|
|
|
2515
2503
|
}
|
|
2516
2504
|
var pdfRender = async (arg) => {
|
|
2517
2505
|
const { value, schema, basePdf, options, _cache } = arg;
|
|
2518
|
-
const body =
|
|
2506
|
+
const body = getBodyWithSchemaRange(typeof value !== "string" ? JSON.stringify(value || "[]") : value, schema);
|
|
2519
2507
|
const createTableArgs = {
|
|
2520
2508
|
schema,
|
|
2521
2509
|
basePdf,
|
|
@@ -2642,7 +2630,7 @@ var renderRowUi = (args) => {
|
|
|
2642
2630
|
if (!arg.onChange) return;
|
|
2643
2631
|
const newValue = Array.isArray(v) ? v[0].value : v.value;
|
|
2644
2632
|
if (section === "body") {
|
|
2645
|
-
const startRange = arg.schema
|
|
2633
|
+
const startRange = getTableBodyRange(arg.schema)?.start ?? 0;
|
|
2646
2634
|
value[rowIndex + startRange][colIndex] = newValue;
|
|
2647
2635
|
arg.onChange({
|
|
2648
2636
|
key: "content",
|
|
@@ -2695,7 +2683,8 @@ var resetEditingPosition = () => {
|
|
|
2695
2683
|
var uiRender = async (arg) => {
|
|
2696
2684
|
const { rootElement, onChange, schema, value, mode, scale } = arg;
|
|
2697
2685
|
const body = getBody(value);
|
|
2698
|
-
const
|
|
2686
|
+
const bodyRange = getTableBodyRange(schema);
|
|
2687
|
+
const bodyWidthRange = getBodyWithSchemaRange(value, schema, bodyRange);
|
|
2699
2688
|
const table = await createSingleTable(bodyWidthRange, arg);
|
|
2700
2689
|
const showHead = table.settings.showHead;
|
|
2701
2690
|
rootElement.innerHTML = "";
|
|
@@ -2748,7 +2737,7 @@ var uiRender = async (arg) => {
|
|
|
2748
2737
|
text: "-",
|
|
2749
2738
|
ariaLabel: "Remove row",
|
|
2750
2739
|
onClick: () => {
|
|
2751
|
-
const newTableBody = body.filter((_, j) => j !== i + (
|
|
2740
|
+
const newTableBody = body.filter((_, j) => j !== i + (bodyRange?.start ?? 0));
|
|
2752
2741
|
if (onChange) onChange({
|
|
2753
2742
|
key: "content",
|
|
2754
2743
|
value: JSON.stringify(newTableBody)
|
|
@@ -2758,7 +2747,7 @@ var uiRender = async (arg) => {
|
|
|
2758
2747
|
});
|
|
2759
2748
|
};
|
|
2760
2749
|
if (mode === "form" && onChange && !schema.readOnly) {
|
|
2761
|
-
if (
|
|
2750
|
+
if (bodyRange?.end === void 0 || bodyRange.end >= JSON.parse(value || "[]").length) rootElement.appendChild(createAddRowButton());
|
|
2762
2751
|
createRemoveRowButtons().forEach((button) => rootElement.appendChild(button));
|
|
2763
2752
|
}
|
|
2764
2753
|
if (mode === "designer" && onChange) {
|
|
@@ -6159,6 +6148,6 @@ var schema = {
|
|
|
6159
6148
|
icon: getCheckedIcon()
|
|
6160
6149
|
};
|
|
6161
6150
|
//#endregion
|
|
6162
|
-
export { barcodes, builtInPlugins, schema as checkbox, date_default as date, dateTime_default as dateTime, ellipse, getDynamicHeightsForTable, getDynamicLayoutForList, getDynamicLayoutForTable, imageSchema as image, lineSchema as line, listSchema as list, schema$1 as multiVariableText, schema$2 as radioGroup, rectangle, schema$3 as select, signature, svgSchema as svg, tableSchema as table, textSchema as text, time_default as time };
|
|
6151
|
+
export { BUILT_IN_DYNAMIC_LAYOUT_SPLIT_UNITS, LIST_ITEM_SPLIT_UNIT, TABLE_BODY_SPLIT_UNIT, TEXT_LINE_SPLIT_UNIT, barcodes, builtInPlugins, schema as checkbox, createListItemSplitRange, createTableBodySplitRange, createTextLineSplitRange, date_default as date, dateTime_default as dateTime, ellipse, getDynamicHeightsForTable, getDynamicLayoutForList, getDynamicLayoutForTable, getListItemRange, getTableBodyRange, getTextLineRange, imageSchema as image, lineSchema as line, listSchema as list, schema$1 as multiVariableText, schema$2 as radioGroup, rectangle, schema$3 as select, signature, svgSchema as svg, tableSchema as table, textSchema as text, time_default as time };
|
|
6163
6152
|
|
|
6164
6153
|
//# sourceMappingURL=index.js.map
|