@pdfme/schemas 6.1.13-dev.13 → 6.1.13-dev.22

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.
@@ -1,4 +1,12 @@
1
1
  import { MultiVariableTextSchema } from './types.js';
2
+ export declare const tryParseVariableMap: (variablesIn: string | Record<string, string> | undefined) => Record<string, string> | undefined;
2
3
  export declare const substituteVariables: (text: string, variablesIn: string | Record<string, string>, valueMapper?: (value: string, variableName: string) => string) => string;
3
4
  export declare const substituteVariablesAsInlineMarkdownLiterals: (text: string, variablesIn: string | Record<string, string>) => string;
5
+ /**
6
+ * Resolve a read-only MVT field to display text.
7
+ * jsx locked fields set `contentSnapshot` and store already-substituted text
8
+ * in `content`. Designer templates omit that flag and store variable JSON.
9
+ * Never treat `content` as an expression, and never infer a snapshot from keys.
10
+ */
11
+ export declare const resolveReadOnlyMultiVariableText: (schema: MultiVariableTextSchema, value?: string) => string;
4
12
  export declare const validateVariables: (value: string, schema: MultiVariableTextSchema) => boolean;
@@ -2,4 +2,6 @@ import type { TextSchema } from '../text/types.js';
2
2
  export type MultiVariableTextSchema = TextSchema & {
3
3
  text: string;
4
4
  variables: string[];
5
+ /** When true, `content` is already-substituted display text (jsx locked MVT). */
6
+ contentSnapshot?: boolean;
5
7
  };
package/dist/texts.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { X as TEXT_OVERFLOW_EXPAND, Z as TEXT_OVERFLOW_VISIBLE, i as TEXT_LINE_SPLIT_UNIT, s as createTextLineSplitRange, u as getTextLineRange } from "./splitRange-BHV0vb0Q.js";
2
2
  import { o as mergeTextLineRangeValue } from "./measure-BC7tjAtT.js";
3
- import { n as getDynamicLayoutForMultiVariableText, t as getDynamicLayoutForText } from "./dynamicTemplate-DFk_de1Y.js";
3
+ import { n as getDynamicLayoutForMultiVariableText, t as getDynamicLayoutForText } from "./dynamicTemplate-CCCmLMvQ.js";
4
4
  export { TEXT_LINE_SPLIT_UNIT, TEXT_OVERFLOW_EXPAND, TEXT_OVERFLOW_VISIBLE, createTextLineSplitRange, getDynamicLayoutForMultiVariableText, getDynamicLayoutForText, getTextLineRange, mergeTextLineRangeValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/schemas",
3
- "version": "6.1.13-dev.13",
3
+ "version": "6.1.13-dev.22",
4
4
  "description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
5
5
  "keywords": [
6
6
  "pdf",
@@ -1 +0,0 @@
1
- {"version":3,"file":"dynamicTemplate-DFk_de1Y.js","names":[],"sources":["../src/multiVariableText/dynamicTemplate.ts","../src/text/dynamicTemplate.ts"],"sourcesContent":["import type { DynamicLayoutArgs, DynamicLayoutResult } from '@pdfme/common';\nimport { TEXT_OVERFLOW_EXPAND } from '../text/constants.js';\nimport {\n getTextLineHeightsWithBox,\n getTextSplitBoxStyle,\n measureTextLines,\n sumLineHeights,\n} from '../text/measure.js';\nimport { isInlineMarkdownTextSchema } from '../text/richText.js';\nimport type { MultiVariableTextSchema } from './types.js';\nimport {\n substituteVariables,\n substituteVariablesAsInlineMarkdownLiterals,\n validateVariables,\n} from './helper.js';\nimport { createTextLineSplitRange } from '../splitRange.js';\n\nexport const getDynamicLayoutForMultiVariableText = async (\n value: string,\n args: DynamicLayoutArgs,\n): Promise<DynamicLayoutResult> => {\n if (args.schema.type !== 'multiVariableText') return { heights: [args.schema.height] };\n\n const schema = args.schema as MultiVariableTextSchema;\n if (schema.overflow !== TEXT_OVERFLOW_EXPAND) {\n return { heights: [schema.height] };\n }\n\n let renderValue = schema.readOnly && schema.variables.length === 0 ? schema.text || '' : value;\n if (!schema.readOnly) {\n if (!validateVariables(value, schema)) {\n return { heights: [schema.height] };\n }\n\n renderValue = isInlineMarkdownTextSchema(schema)\n ? substituteVariablesAsInlineMarkdownLiterals(schema.text || '', value)\n : substituteVariables(schema.text || '', value);\n }\n const { lineHeights } = await measureTextLines({\n value: renderValue,\n schema,\n font: args.options.font,\n _cache: args._cache,\n // `expand` owns the height decision, so measuring against a shrink-to-fit font size\n // would make the field keep its original box instead of growing.\n ignoreDynamicFontSize: true,\n });\n const heights = getTextLineHeightsWithBox(lineHeights, schema);\n const measuredHeight = sumLineHeights(heights);\n\n if (measuredHeight <= schema.height || lineHeights.length === 0) {\n return {\n heights: [schema.height],\n patchSplitSchema: () => ({ dynamicFontSize: undefined }),\n };\n }\n\n return {\n heights: lineHeights.length === 1 ? [Math.max(schema.height, measuredHeight)] : heights,\n patchSplitSchema: ({ start, end, isSplit }) => ({\n dynamicFontSize: undefined,\n __splitRange: lineHeights.length === 1 ? undefined : createTextLineSplitRange(start, end),\n __isSplit: isSplit,\n ...getTextSplitBoxStyle(schema, { start, end }, lineHeights.length),\n }),\n };\n};\n","import type { DynamicLayoutArgs, DynamicLayoutResult } from '@pdfme/common';\nimport { TEXT_OVERFLOW_EXPAND } from './constants.js';\nimport {\n getTextLineHeightsWithBox,\n getTextSplitBoxStyle,\n measureTextLines,\n sumLineHeights,\n} from './measure.js';\nimport type { TextSchema } from './types.js';\nimport { createTextLineSplitRange } from '../splitRange.js';\n\nexport const getDynamicLayoutForText = async (\n value: string,\n args: DynamicLayoutArgs,\n): Promise<DynamicLayoutResult> => {\n if (args.schema.type !== 'text') return { heights: [args.schema.height] };\n\n const schema = args.schema as TextSchema;\n if (schema.overflow !== TEXT_OVERFLOW_EXPAND) {\n return { heights: [schema.height] };\n }\n\n const { lineHeights } = await measureTextLines({\n value,\n schema,\n font: args.options.font,\n _cache: args._cache,\n // `expand` owns the height decision, so measuring against a shrink-to-fit font size\n // would make the field keep its original box instead of growing.\n ignoreDynamicFontSize: true,\n });\n const heights = getTextLineHeightsWithBox(lineHeights, schema);\n const measuredHeight = sumLineHeights(heights);\n\n if (measuredHeight <= schema.height || lineHeights.length === 0) {\n return {\n heights: [schema.height],\n patchSplitSchema: () => ({ dynamicFontSize: undefined }),\n };\n }\n\n return {\n heights: lineHeights.length === 1 ? [Math.max(schema.height, measuredHeight)] : heights,\n patchSplitSchema: ({ start, end, isSplit }) => ({\n dynamicFontSize: undefined,\n __splitRange: lineHeights.length === 1 ? undefined : createTextLineSplitRange(start, end),\n __isSplit: isSplit,\n ...getTextSplitBoxStyle(schema, { start, end }, lineHeights.length),\n }),\n };\n};\n"],"mappings":";;;;AAiBA,IAAa,uCAAuC,OAClD,OACA,SACiC;CACjC,IAAI,KAAK,OAAO,SAAS,qBAAqB,OAAO,EAAE,SAAS,CAAC,KAAK,OAAO,MAAM,EAAE;CAErF,MAAM,SAAS,KAAK;CACpB,IAAI,OAAO,aAAA,UACT,OAAO,EAAE,SAAS,CAAC,OAAO,MAAM,EAAE;CAGpC,IAAI,cAAc,OAAO,YAAY,OAAO,UAAU,WAAW,IAAI,OAAO,QAAQ,KAAK;CACzF,IAAI,CAAC,OAAO,UAAU;EACpB,IAAI,CAAC,kBAAkB,OAAO,MAAM,GAClC,OAAO,EAAE,SAAS,CAAC,OAAO,MAAM,EAAE;EAGpC,cAAc,2BAA2B,MAAM,IAC3C,4CAA4C,OAAO,QAAQ,IAAI,KAAK,IACpE,oBAAoB,OAAO,QAAQ,IAAI,KAAK;CAClD;CACA,MAAM,EAAE,gBAAgB,MAAM,iBAAiB;EAC7C,OAAO;EACP;EACA,MAAM,KAAK,QAAQ;EACnB,QAAQ,KAAK;EAGb,uBAAuB;CACzB,CAAC;CACD,MAAM,UAAU,0BAA0B,aAAa,MAAM;CAC7D,MAAM,iBAAiB,eAAe,OAAO;CAE7C,IAAI,kBAAkB,OAAO,UAAU,YAAY,WAAW,GAC5D,OAAO;EACL,SAAS,CAAC,OAAO,MAAM;EACvB,yBAAyB,EAAE,iBAAiB,KAAA,EAAU;CACxD;CAGF,OAAO;EACL,SAAS,YAAY,WAAW,IAAI,CAAC,KAAK,IAAI,OAAO,QAAQ,cAAc,CAAC,IAAI;EAChF,mBAAmB,EAAE,OAAO,KAAK,eAAe;GAC9C,iBAAiB,KAAA;GACjB,cAAc,YAAY,WAAW,IAAI,KAAA,IAAY,yBAAyB,OAAO,GAAG;GACxF,WAAW;GACX,GAAG,qBAAqB,QAAQ;IAAE;IAAO;GAAI,GAAG,YAAY,MAAM;EACpE;CACF;AACF;;;ACvDA,IAAa,0BAA0B,OACrC,OACA,SACiC;CACjC,IAAI,KAAK,OAAO,SAAS,QAAQ,OAAO,EAAE,SAAS,CAAC,KAAK,OAAO,MAAM,EAAE;CAExE,MAAM,SAAS,KAAK;CACpB,IAAI,OAAO,aAAA,UACT,OAAO,EAAE,SAAS,CAAC,OAAO,MAAM,EAAE;CAGpC,MAAM,EAAE,gBAAgB,MAAM,iBAAiB;EAC7C;EACA;EACA,MAAM,KAAK,QAAQ;EACnB,QAAQ,KAAK;EAGb,uBAAuB;CACzB,CAAC;CACD,MAAM,UAAU,0BAA0B,aAAa,MAAM;CAC7D,MAAM,iBAAiB,eAAe,OAAO;CAE7C,IAAI,kBAAkB,OAAO,UAAU,YAAY,WAAW,GAC5D,OAAO;EACL,SAAS,CAAC,OAAO,MAAM;EACvB,yBAAyB,EAAE,iBAAiB,KAAA,EAAU;CACxD;CAGF,OAAO;EACL,SAAS,YAAY,WAAW,IAAI,CAAC,KAAK,IAAI,OAAO,QAAQ,cAAc,CAAC,IAAI;EAChF,mBAAmB,EAAE,OAAO,KAAK,eAAe;GAC9C,iBAAiB,KAAA;GACjB,cAAc,YAAY,WAAW,IAAI,KAAA,IAAY,yBAAyB,OAAO,GAAG;GACxF,WAAW;GACX,GAAG,qBAAqB,QAAQ;IAAE;IAAO;GAAI,GAAG,YAAY,MAAM;EACpE;CACF;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"helper-VroN19Ci.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 (\n !Object.prototype.hasOwnProperty.call(values, variable) ||\n values[variable] === null ||\n values[variable] === undefined\n ) {\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;CACX,IAAI,CAAC,MACH,OAAO;CAGT,IAAI,kBAAkB;CAEtB,IAAI,aAAa;EACf,IAAI;EACJ,IAAI;GACF,YACE,OAAO,gBAAgB,WAClB,KAAK,MAAM,eAAe,IAAI,IAC/B;EACR,QAAQ;GACN,MAAM,IAAI,YAAY,8CAA8C,YAAsB,EAAE;EAC9F;EAEA,OAAO,KAAK,SAAS,CAAC,CAAC,SAAS,iBAAiB;GAE/C,MAAM,mBAAmB,aAAa,QAAQ,0BAA0B,MAAM;GAC9E,MAAM,QAAQ,IAAI,OAAO,QAAQ,mBAAmB,OAAO,GAAG;GAC9D,kBAAkB,gBAAgB,QAChC,OACA,YAAY,UAAU,eAAe,YAAY,CACnD;EACF,CAAC;CACH;CAGA,kBAAkB,gBAAgB,QAAQ,aAAa,EAAE;CAEzD,OAAO;AACT;AAEA,IAAa,+CACX,MACA,gBACW,oBAAoB,MAAM,aAAa,oBAAoB;AAExE,IAAa,qBAAqB,OAAe,WAA6C;CAC5F,IAAI,OAAO,UAAU,WAAW,GAC9B,OAAO;CAGT,IAAI;CACJ,IAAI;EACF,SAAS,QAAS,KAAK,MAAM,KAAK,IAA+B,CAAC;CACpE,QAAQ;EACN,MAAM,IAAI,YACR,2CAA2C,MAAM,2BAA2B,OAAO,MACrF;CACF;CAEA,KAAK,MAAM,YAAY,OAAO,WAC5B,IACE,CAAC,OAAO,UAAU,eAAe,KAAK,QAAQ,QAAQ,KACtD,OAAO,cAAc,QACrB,OAAO,cAAc,KAAA,GACrB;EACA,IAAI,OAAO,UACT,MAAM,IAAI,MACR,+BAA+B,SAAS,wBAAwB,OAAO,MACzE;EAGF,OAAO;CACT;CAGF,OAAO;AACT"}