@legalplace/prerenderx 3.8.24-staging.0 → 3.8.24

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 (44) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/libs/DocumentRender.d.ts +2 -3
  3. package/dist/libs/DocumentRender.js +4 -13
  4. package/dist/libs/FillPdfForm.d.ts +1 -1
  5. package/dist/libs/FillPdfForm.js +15 -25
  6. package/dist/libs/OptionRender.d.ts +0 -4
  7. package/dist/libs/OptionRender.js +29 -125
  8. package/dist/libs/OutputParser.d.ts +1 -1
  9. package/dist/libs/OutputParser.js +6 -18
  10. package/dist/libs/Prerender.d.ts +2 -5
  11. package/dist/libs/Prerender.js +27 -100
  12. package/dist/libs/SectionRender.d.ts +0 -3
  13. package/dist/libs/SectionRender.js +22 -64
  14. package/dist/libs/misc/FillPdfFormBase.d.ts +1 -1
  15. package/dist/libs/misc/FillPdfFormBase.js +37 -11
  16. package/dist/types/types.d.ts +0 -13
  17. package/package.json +10 -9
  18. package/src/libs/DocumentRender.ts +5 -33
  19. package/src/libs/FillPdfForm.ts +22 -39
  20. package/src/libs/OptionRender.ts +63 -218
  21. package/src/libs/OutputParser.ts +9 -40
  22. package/src/libs/Prerender.ts +38 -157
  23. package/src/libs/SectionRender.ts +28 -111
  24. package/src/libs/misc/FillPdfFormBase.ts +67 -34
  25. package/src/types/types.ts +0 -27
  26. package/.yalc/@legalplace/models-v3-types/.eslintrc +0 -3
  27. package/.yalc/@legalplace/models-v3-types/.gitlab-ci.yml +0 -30
  28. package/.yalc/@legalplace/models-v3-types/CHANGELOG.md +0 -1503
  29. package/.yalc/@legalplace/models-v3-types/README +0 -6
  30. package/.yalc/@legalplace/models-v3-types/index.ts +0 -915
  31. package/.yalc/@legalplace/models-v3-types/package.json +0 -16
  32. package/.yalc/@legalplace/models-v3-types/schema.json +0 -2918
  33. package/.yalc/@legalplace/models-v3-types/tsconfig.json +0 -22
  34. package/.yalc/@legalplace/models-v3-types/yalc.sig +0 -1
  35. package/dist/libs/outputTableRendering.d.ts +0 -16
  36. package/dist/libs/outputTableRendering.js +0 -130
  37. package/dist/libs/regionHelpers.d.ts +0 -5
  38. package/dist/libs/regionHelpers.js +0 -22
  39. package/dist/libs/tableOutputExpansion.d.ts +0 -20
  40. package/dist/libs/tableOutputExpansion.js +0 -68
  41. package/src/libs/tableOutputExpansion.ts +0 -145
  42. package/tests/Prerender.documentMultiple.test.ts +0 -276
  43. package/tests/Prerender.repeated.test.ts +0 -115
  44. package/yalc.lock +0 -10
@@ -1,22 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "lib": [
5
- "es6"
6
- ],
7
- "noImplicitAny": true,
8
- "noImplicitThis": true,
9
- "strictFunctionTypes": true,
10
- "strictNullChecks": true,
11
- "baseUrl": "../",
12
- "typeRoots": [
13
- "../"
14
- ],
15
- "types": [],
16
- "noEmit": true,
17
- "forceConsistentCasingInFileNames": true
18
- },
19
- "files": [
20
- "index.ts"
21
- ]
22
- }
@@ -1 +0,0 @@
1
- 8dafcafb8397571e5cb7e2f8266c3326
@@ -1,16 +0,0 @@
1
- import type { OptionV3 } from "@legalplace/models-v3-types";
2
- export type OutputTableCellStyle = Record<string, string>;
3
- export type OutputTableStyle = {
4
- columnWidths?: number[];
5
- width?: number;
6
- borderStyle?: string;
7
- borderColor?: string;
8
- borderWidth?: number;
9
- };
10
- export declare const expandOutputTableCellStyle: (styles: OutputTableCellStyle) => OutputTableCellStyle;
11
- export declare const serializeInlineStyle: (styles: OutputTableCellStyle) => string;
12
- export declare const buildOutputTableStyleAttr: (tableStyle?: OutputTableStyle) => string;
13
- export declare const buildOutputTableCellStyleAttr: (cellStyle?: OutputTableCellStyle | null) => string;
14
- export declare const getOutputTableCellStyle: (option: OptionV3) => OutputTableCellStyle | undefined;
15
- export declare const replaceOutputTableMarkers: (html: string, renderTable: (tableId: number) => string) => string;
16
- export declare const stripOutputTableMarkers: (html: string) => string;
@@ -1,130 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.stripOutputTableMarkers = exports.replaceOutputTableMarkers = exports.getOutputTableCellStyle = exports.buildOutputTableCellStyleAttr = exports.buildOutputTableStyleAttr = exports.serializeInlineStyle = exports.expandOutputTableCellStyle = void 0;
15
- var DEFAULT_OUTPUT_TABLE_CELL_STYLE = {
16
- paddingTop: "4px",
17
- paddingRight: "4px",
18
- paddingBottom: "4px",
19
- paddingLeft: "4px",
20
- borderTopWidth: "1px",
21
- borderTopStyle: "solid",
22
- borderTopColor: "#000000",
23
- borderRightWidth: "1px",
24
- borderRightStyle: "solid",
25
- borderRightColor: "#000000",
26
- borderBottomWidth: "1px",
27
- borderBottomStyle: "solid",
28
- borderBottomColor: "#000000",
29
- borderLeftWidth: "1px",
30
- borderLeftStyle: "solid",
31
- borderLeftColor: "#000000",
32
- };
33
- var BORDER_SIDES = ["Top", "Right", "Bottom", "Left"];
34
- var parseBoxShorthand = function (parts) {
35
- var first = parts[0], second = parts[1], third = parts[2], fourth = parts[3];
36
- if (parts.length === 1) {
37
- return [first, first, first, first];
38
- }
39
- if (parts.length === 2) {
40
- return [first, second, first, second];
41
- }
42
- if (parts.length === 3) {
43
- return [first, second, third, second];
44
- }
45
- return [first, second, third, fourth];
46
- };
47
- var parseBorderShorthand = function (border) {
48
- var parts = border.trim().split(/\s+/);
49
- var width = parts.find(function (part) { return /^[0-9.]+(px|pt|em|rem|%)?$/i.test(part); }) || "1px";
50
- var style = parts.find(function (part) {
51
- return ["solid", "dashed", "dotted", "double", "none"].includes(part.toLowerCase());
52
- }) || "solid";
53
- var color = parts.find(function (part) { return part.startsWith("#") || part.startsWith("rgb"); }) ||
54
- "#000000";
55
- return { width: width, style: style, color: color };
56
- };
57
- var expandOutputTableCellStyle = function (styles) {
58
- var expanded = __assign({}, styles);
59
- if (expanded.padding) {
60
- var _a = parseBoxShorthand(expanded.padding.trim().split(/\s+/)), top_1 = _a[0], right = _a[1], bottom = _a[2], left = _a[3];
61
- delete expanded.padding;
62
- expanded.paddingTop = expanded.paddingTop || top_1;
63
- expanded.paddingRight = expanded.paddingRight || right;
64
- expanded.paddingBottom = expanded.paddingBottom || bottom;
65
- expanded.paddingLeft = expanded.paddingLeft || left;
66
- }
67
- if (expanded.border) {
68
- var _b = parseBorderShorthand(expanded.border), width_1 = _b.width, style_1 = _b.style, color_1 = _b.color;
69
- delete expanded.border;
70
- BORDER_SIDES.forEach(function (side) {
71
- var widthKey = "border".concat(side, "Width");
72
- var styleKey = "border".concat(side, "Style");
73
- var colorKey = "border".concat(side, "Color");
74
- expanded[widthKey] = expanded[widthKey] || width_1;
75
- expanded[styleKey] = expanded[styleKey] || style_1;
76
- expanded[colorKey] = expanded[colorKey] || color_1;
77
- });
78
- }
79
- return expanded;
80
- };
81
- exports.expandOutputTableCellStyle = expandOutputTableCellStyle;
82
- var camelToKebab = function (property) {
83
- return property.replace(/[A-Z]/g, function (match) { return "-".concat(match.toLowerCase()); });
84
- };
85
- var serializeInlineStyle = function (styles) {
86
- return Object.entries(styles)
87
- .filter(function (_a) {
88
- var value = _a[1];
89
- return value !== undefined && value !== "";
90
- })
91
- .map(function (_a) {
92
- var property = _a[0], value = _a[1];
93
- return "".concat(camelToKebab(property), ":").concat(value);
94
- })
95
- .join(";");
96
- };
97
- exports.serializeInlineStyle = serializeInlineStyle;
98
- var buildOutputTableStyleAttr = function (tableStyle) {
99
- var styles = [
100
- "table-layout:fixed",
101
- "border-spacing:0",
102
- "border-collapse:collapse",
103
- ];
104
- if (typeof (tableStyle === null || tableStyle === void 0 ? void 0 : tableStyle.width) === "number") {
105
- styles.push("width:".concat(tableStyle.width, "%"));
106
- }
107
- return " style=\"".concat(styles.join(";"), "\"");
108
- };
109
- exports.buildOutputTableStyleAttr = buildOutputTableStyleAttr;
110
- var buildOutputTableCellStyleAttr = function (cellStyle) {
111
- var styles = (0, exports.expandOutputTableCellStyle)(__assign(__assign({}, DEFAULT_OUTPUT_TABLE_CELL_STYLE), (cellStyle || {})));
112
- var serialized = (0, exports.serializeInlineStyle)(styles);
113
- return serialized.length > 0 ? " style=\"".concat(serialized, "\"") : "";
114
- };
115
- exports.buildOutputTableCellStyleAttr = buildOutputTableCellStyleAttr;
116
- var getOutputTableCellStyle = function (option) {
117
- return option.meta.cellStyle;
118
- };
119
- exports.getOutputTableCellStyle = getOutputTableCellStyle;
120
- var OUTPUT_TABLE_MARKER_REGEX = /<output-table\s+data-id="(\d+)"\s*><\/output-table>/gi;
121
- var replaceOutputTableMarkers = function (html, renderTable) {
122
- return html.replace(OUTPUT_TABLE_MARKER_REGEX, function (_match, tableId) {
123
- return renderTable(parseInt(tableId, 10));
124
- });
125
- };
126
- exports.replaceOutputTableMarkers = replaceOutputTableMarkers;
127
- var stripOutputTableMarkers = function (html) {
128
- return html.replace(OUTPUT_TABLE_MARKER_REGEX, "");
129
- };
130
- exports.stripOutputTableMarkers = stripOutputTableMarkers;
@@ -1,5 +0,0 @@
1
- import type { SectionRoleV3, SectionV3 } from "@legalplace/models-v3-types";
2
- export type OutputRegionRole = SectionRoleV3;
3
- export declare const isBodySection: (section: SectionV3) => boolean;
4
- export declare const isRegionSection: (section: SectionV3, role: OutputRegionRole) => boolean;
5
- export declare const getSectionIdsForRole: (sections: Record<string, SectionV3>, role: OutputRegionRole) => number[];
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSectionIdsForRole = exports.isRegionSection = exports.isBodySection = void 0;
4
- var isBodySection = function (section) {
5
- return !section.role || section.role === "body";
6
- };
7
- exports.isBodySection = isBodySection;
8
- var isRegionSection = function (section, role) {
9
- if (role === "body")
10
- return (0, exports.isBodySection)(section);
11
- return section.role === role;
12
- };
13
- exports.isRegionSection = isRegionSection;
14
- var getSectionIdsForRole = function (sections, role) {
15
- return Object.keys(sections)
16
- .map(function (sectionId) { return parseInt(sectionId, 10); })
17
- .filter(function (sectionId) {
18
- var section = sections[sectionId];
19
- return section && (0, exports.isRegionSection)(section, role);
20
- });
21
- };
22
- exports.getSectionIdsForRole = getSectionIdsForRole;
@@ -1,20 +0,0 @@
1
- import type { ConditionV3 } from "@legalplace/models-v3-types";
2
- import type ConditionsRunner from "@legalplace/conditions-runner";
3
- import type { Types } from "@legalplace/referencesparser";
4
- import { type ExpandTableMarkupContext } from "@legalplace/referencesparser";
5
- import type InputsType from "@legalplace/types/dist/inputs";
6
- export declare const evaluateInlineTableCondition: (condition: ConditionV3, contextOptionId: number, occurrenceIndex: number, conditionsRunner: ConditionsRunner, references: Types.ReferencesType, ovc: InputsType) => boolean;
7
- type CreateTableMarkupContextParams = {
8
- references: Types.ReferencesType;
9
- ovc: InputsType;
10
- conditions: ConditionsRunner;
11
- contextOptionId: number;
12
- defaultOccurrenceIndex: number;
13
- };
14
- export declare const createTableMarkupContext: ({ references, ovc, conditions, contextOptionId, defaultOccurrenceIndex, }: CreateTableMarkupContextParams) => ExpandTableMarkupContext;
15
- type ExpandOutputTableMarkupParams = CreateTableMarkupContextParams & {
16
- output: string;
17
- };
18
- export declare const expandOutputTableMarkup: ({ output, references, ovc, conditions, contextOptionId, defaultOccurrenceIndex, }: ExpandOutputTableMarkupParams) => string;
19
- export declare const cleanupRenderedOutputHtml: (output: string) => string;
20
- export {};
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cleanupRenderedOutputHtml = exports.expandOutputTableMarkup = exports.createTableMarkupContext = exports.evaluateInlineTableCondition = void 0;
7
- var lplogic_1 = __importDefault(require("@legalplace/lplogic"));
8
- var DataPopulator_1 = __importDefault(require("@legalplace/conditions-runner/dist/DataPopulator"));
9
- var referencesparser_1 = require("@legalplace/referencesparser");
10
- var OutputParser_1 = require("./OutputParser");
11
- var extractVariableIds = function (html) {
12
- var matches = html.match(/\[var:([0-9]+)\]/gi);
13
- if (matches === null)
14
- return [];
15
- return Array.from(new Set(matches.map(function (tag) {
16
- var idMatch = tag.match(/([0-9]+)/);
17
- return idMatch ? parseInt(idMatch[1], 10) : 0;
18
- }))).filter(function (id) { return id > 0; });
19
- };
20
- var evaluateInlineTableCondition = function (condition, contextOptionId, occurrenceIndex, conditionsRunner, references, ovc) {
21
- var dataMap = (0, referencesparser_1.extractConditionDataMap)(condition);
22
- var currentData = new DataPopulator_1.default(conditionsRunner, references, ovc, dataMap, contextOptionId, occurrenceIndex).getData();
23
- var result = (0, lplogic_1.default)((0, referencesparser_1.stripConditionUiMetadata)(condition), currentData);
24
- return result !== false;
25
- };
26
- exports.evaluateInlineTableCondition = evaluateInlineTableCondition;
27
- var createTableMarkupContext = function (_a) {
28
- var references = _a.references, ovc = _a.ovc, conditions = _a.conditions, contextOptionId = _a.contextOptionId, defaultOccurrenceIndex = _a.defaultOccurrenceIndex;
29
- return ({
30
- defaultContextOptionId: contextOptionId,
31
- defaultOccurrenceIndex: defaultOccurrenceIndex,
32
- getOccurrenceInputs: function (multipleOptionId) {
33
- return ovc.options[String(multipleOptionId)] || [];
34
- },
35
- evaluateCondition: function (condition, multipleOptionId, occurrenceIndex) {
36
- return (0, exports.evaluateInlineTableCondition)(condition, multipleOptionId, occurrenceIndex, conditions, references, ovc);
37
- },
38
- substituteVariables: function (html, multipleOptionId, occurrenceIndex) {
39
- var variableIds = extractVariableIds(html);
40
- var variables = (0, OutputParser_1.getRelatedVariablesValues)(multipleOptionId, occurrenceIndex, variableIds, ovc, references);
41
- return (0, OutputParser_1.parseOutputWithVariables)(html, occurrenceIndex, variables, []);
42
- },
43
- });
44
- };
45
- exports.createTableMarkupContext = createTableMarkupContext;
46
- var expandOutputTableMarkup = function (_a) {
47
- var output = _a.output, references = _a.references, ovc = _a.ovc, conditions = _a.conditions, contextOptionId = _a.contextOptionId, defaultOccurrenceIndex = _a.defaultOccurrenceIndex;
48
- if (!(0, referencesparser_1.hasTableDynamicMarkup)(output))
49
- return output;
50
- return (0, referencesparser_1.expandTableMarkup)(output, (0, exports.createTableMarkupContext)({
51
- references: references,
52
- ovc: ovc,
53
- conditions: conditions,
54
- contextOptionId: contextOptionId,
55
- defaultOccurrenceIndex: defaultOccurrenceIndex,
56
- }));
57
- };
58
- exports.expandOutputTableMarkup = expandOutputTableMarkup;
59
- var cleanupRenderedOutputHtml = function (output) {
60
- if (output.includes("<table")) {
61
- return output.replace(/\xA0/g, " ");
62
- }
63
- return output
64
- .replace(/<\/([a-z]+)>([\n\s]+)</gi, "</$1><")
65
- .replace(/\n/g, "<br />")
66
- .replace(/\xA0/g, " ");
67
- };
68
- exports.cleanupRenderedOutputHtml = cleanupRenderedOutputHtml;
@@ -1,145 +0,0 @@
1
- import LpLogic from "@legalplace/lplogic";
2
- import type { ConditionV3 } from "@legalplace/models-v3-types";
3
- import type ConditionsRunner from "@legalplace/conditions-runner";
4
- import DataPopulator from "@legalplace/conditions-runner/dist/DataPopulator";
5
- import type { Types } from "@legalplace/referencesparser";
6
- import {
7
- expandTableMarkup,
8
- extractConditionDataMap,
9
- hasTableDynamicMarkup,
10
- stripConditionUiMetadata,
11
- type ExpandTableMarkupContext,
12
- } from "@legalplace/referencesparser";
13
- import type InputsType from "@legalplace/types/dist/inputs";
14
- import {
15
- getRelatedVariablesValues,
16
- parseOutputWithVariables,
17
- } from "./OutputParser";
18
-
19
- /**
20
- * Extracts variable ids referenced as `[var:N]` tags in an HTML fragment.
21
- */
22
- const extractVariableIds = (html: string): number[] => {
23
- const matches = html.match(/\[var:([0-9]+)\]/gi);
24
- if (matches === null) return [];
25
-
26
- return Array.from(
27
- new Set(
28
- matches.map((tag) => {
29
- const idMatch = tag.match(/([0-9]+)/);
30
- return idMatch ? parseInt(idMatch[1], 10) : 0;
31
- })
32
- )
33
- ).filter((id) => id > 0);
34
- };
35
-
36
- /**
37
- * Evaluates an inline table condition at a given occurrence index.
38
- */
39
- export const evaluateInlineTableCondition = (
40
- condition: ConditionV3,
41
- contextOptionId: number,
42
- occurrenceIndex: number,
43
- conditionsRunner: ConditionsRunner,
44
- references: Types.ReferencesType,
45
- ovc: InputsType
46
- ): boolean => {
47
- const dataMap = extractConditionDataMap(condition);
48
- const currentData = new DataPopulator(
49
- conditionsRunner,
50
- references,
51
- ovc,
52
- dataMap,
53
- contextOptionId,
54
- occurrenceIndex
55
- ).getData();
56
- const result = LpLogic(stripConditionUiMetadata(condition), currentData);
57
- return result !== false;
58
- };
59
-
60
- type CreateTableMarkupContextParams = {
61
- references: Types.ReferencesType;
62
- ovc: InputsType;
63
- conditions: ConditionsRunner;
64
- contextOptionId: number;
65
- defaultOccurrenceIndex: number;
66
- };
67
-
68
- /**
69
- * Builds the expandTableMarkup context for prerenderx output rendering.
70
- */
71
- export const createTableMarkupContext = ({
72
- references,
73
- ovc,
74
- conditions,
75
- contextOptionId,
76
- defaultOccurrenceIndex,
77
- }: CreateTableMarkupContextParams): ExpandTableMarkupContext => ({
78
- defaultContextOptionId: contextOptionId,
79
- defaultOccurrenceIndex,
80
- getOccurrenceInputs: (multipleOptionId: number) =>
81
- ovc.options[String(multipleOptionId)] || [],
82
- evaluateCondition: (condition, multipleOptionId, occurrenceIndex) =>
83
- evaluateInlineTableCondition(
84
- condition,
85
- multipleOptionId,
86
- occurrenceIndex,
87
- conditions,
88
- references,
89
- ovc
90
- ),
91
- substituteVariables: (html, multipleOptionId, occurrenceIndex) => {
92
- const variableIds = extractVariableIds(html);
93
- const variables = getRelatedVariablesValues(
94
- multipleOptionId,
95
- occurrenceIndex,
96
- variableIds,
97
- ovc,
98
- references
99
- );
100
- return parseOutputWithVariables(html, occurrenceIndex, variables, []);
101
- },
102
- });
103
-
104
- type ExpandOutputTableMarkupParams = CreateTableMarkupContextParams & {
105
- output: string;
106
- };
107
-
108
- /**
109
- * Expands dynamic table markup in an output HTML string when needed.
110
- */
111
- export const expandOutputTableMarkup = ({
112
- output,
113
- references,
114
- ovc,
115
- conditions,
116
- contextOptionId,
117
- defaultOccurrenceIndex,
118
- }: ExpandOutputTableMarkupParams): string => {
119
- if (!hasTableDynamicMarkup(output)) return output;
120
-
121
- return expandTableMarkup(
122
- output,
123
- createTableMarkupContext({
124
- references,
125
- ovc,
126
- conditions,
127
- contextOptionId,
128
- defaultOccurrenceIndex,
129
- })
130
- );
131
- };
132
-
133
- /**
134
- * Applies post-processing cleanup to rendered output HTML.
135
- */
136
- export const cleanupRenderedOutputHtml = (output: string): string => {
137
- if (output.includes("<table")) {
138
- return output.replace(/\xA0/g, " ");
139
- }
140
-
141
- return output
142
- .replace(/<\/([a-z]+)>([\n\s]+)</gi, "</$1><")
143
- .replace(/\n/g, "<br />")
144
- .replace(/\xA0/g, " ");
145
- };